summaryrefslogtreecommitdiffstats
path: root/clang/test/CodeGen/arm-pnaclcall.c
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@google.com>2012-10-16 22:30:41 +0000
committerDerek Schuff <dschuff@google.com>2012-10-16 22:30:41 +0000
commita202096dc0d3bf62e88d194e126f2bef9c54fcec (patch)
tree9941a7eda7b9254de7bbbdacab60a8adbe169c21 /clang/test/CodeGen/arm-pnaclcall.c
parent0e8bf254b5fb6ddb2505836361edb44f5df55f25 (diff)
downloadbcm5719-llvm-a202096dc0d3bf62e88d194e126f2bef9c54fcec.tar.gz
bcm5719-llvm-a202096dc0d3bf62e88d194e126f2bef9c54fcec.zip
Add pnaclcall convention to Native Client targets.
Because PNaCl bitcode must be target-independent, it uses some different bitcode representations from other targets (e.g. byval and sret for structures). This means that without additional type information, it cannot meet some native ABI requirements for some targets (e.g. passing structures containing unions by value on x86-64). To allow generation of code which uses the correct native ABIs, we also support triples such as x86_64-nacl, which uses target-dependent IR (as opposed to le32-nacl, which uses byval and sret). To allow interoperation between the two types of code, this patch adds a calling convention attribute to be used in code compiled with the target-dependent triple, which will generate code using the le32-style bitcode. This calling convention does not need to be explicitly supported in the backend because it determines bitcode representation rather than native conventions (the backend just needs to undersand how to handle byval and sret for the Native Client OS). This patch implements __attribute__((pnaclcall)) to generate calls in bitcode according to the le32 bitcode conventions, an attribute which is accepted by any Native Client target, but issues a warning otherwise. llvm-svn: 166065
Diffstat (limited to 'clang/test/CodeGen/arm-pnaclcall.c')
-rw-r--r--clang/test/CodeGen/arm-pnaclcall.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/clang/test/CodeGen/arm-pnaclcall.c b/clang/test/CodeGen/arm-pnaclcall.c
new file mode 100644
index 00000000000..50259957eb1
--- /dev/null
+++ b/clang/test/CodeGen/arm-pnaclcall.c
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -triple armv7-unknown-nacl-gnueabi \
+// RUN: -ffreestanding -mfloat-abi hard -target-cpu cortex-a8 \
+// RUN: -emit-llvm -w -o - %s | FileCheck %s
+
+// Test that functions with pnaclcall attribute generate portable bitcode
+// like the le32 arch target
+
+typedef struct {
+ int a;
+ int b;
+} s1;
+// CHECK: define i32 @f48(%struct.s1* byval %s)
+int __attribute__((pnaclcall)) f48(s1 s) { return s.a; }
+
+// CHECK: define void @f49(%struct.s1* noalias sret %agg.result)
+s1 __attribute__((pnaclcall)) f49() { s1 s; s.a = s.b = 1; return s; }
+
+union simple_union {
+ int a;
+ char b;
+};
+// Unions should be passed as byval structs
+// CHECK: define void @f50(%union.simple_union* byval %s)
+void __attribute__((pnaclcall)) f50(union simple_union s) {}
+
+typedef struct {
+ int b4 : 4;
+ int b3 : 3;
+ int b8 : 8;
+} bitfield1;
+// Bitfields should be passed as byval structs
+// CHECK: define void @f51(%struct.bitfield1* byval %bf1)
+void __attribute__((pnaclcall)) f51(bitfield1 bf1) {}
OpenPOWER on IntegriCloud