summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Sanders <daniel.sanders@imgtec.com>2015-01-14 12:00:12 +0000
committerDaniel Sanders <daniel.sanders@imgtec.com>2015-01-14 12:00:12 +0000
commite90c8e8c4e4da7583df49a267d3dfe96cfc400d7 (patch)
treedfd0119e0c5a40e9481566b9bff3a2f1649b10f4
parent6c1b9266748d8eac3fb196b0b96fb10f0168b2f6 (diff)
[mips] Handle transparent unions correctly.
Summary: This fixes MultiSource/Applications/lemon on big-endian N32 by correcting the handling of the argument to wait(). glibc defines it as a transparent union of void* and int*. Such unions are passed according to the rules of the first member so the argument must be passed as if it were a void* (sign extended from i32 to i64) and not as a union (shifted to the upper bits of an i64). wait() already behaves correctly on big-endian O32 and N64 since the union is already the same size as an argument slot. Reviewers: atanasyan Reviewed By: atanasyan Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D6963 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225981 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/TargetInfo.cpp2
-rw-r--r--test/CodeGen/mips-transparent-union.c27
2 files changed, 29 insertions, 0 deletions
diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp
index aafe05aab6..6ad3495157 100644
--- a/lib/CodeGen/TargetInfo.cpp
+++ b/lib/CodeGen/TargetInfo.cpp
@@ -5693,6 +5693,8 @@ llvm::Type *MipsABIInfo::getPaddingType(uint64_t OrigOffset,
ABIArgInfo
MipsABIInfo::classifyArgumentType(QualType Ty, uint64_t &Offset) const {
+ Ty = useFirstFieldIfTransparentUnion(Ty);
+
uint64_t OrigOffset = Offset;
uint64_t TySize = getContext().getTypeSize(Ty);
uint64_t Align = getContext().getTypeAlign(Ty) / 8;
diff --git a/test/CodeGen/mips-transparent-union.c b/test/CodeGen/mips-transparent-union.c
new file mode 100644
index 0000000000..ad417dd9f5
--- /dev/null
+++ b/test/CodeGen/mips-transparent-union.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple mips64-linux-gnu -S -o - -emit-llvm %s | FileCheck %s
+//
+// Transparent unions are passed according to the calling convention rules of
+// the first member. In this case, it is as if it were a void pointer so we
+// do not have the inreg attribute we would normally have for unions.
+//
+// This comes up in glibc's wait() function and matters for the big-endian N32
+// case where pointers are promoted to i64 and a non-transparent union would be
+// passed in the upper 32-bits of an i64.
+
+union either_pointer {
+ void *void_ptr;
+ int *int_ptr;
+} __attribute__((transparent_union));
+
+extern void foo(union either_pointer p);
+
+int data;
+
+void bar(void) {
+ return foo(&data);
+}
+
+// CHECK-LABEL: define void @bar()
+// CHECK: call void @foo(i8* %{{[0-9]+}})
+
+// CHECK: declare void @foo(i8*)