[Patch] Fix for incorrect ABI in case we have an unused union argument passed by value
Karthik Bhat
blitz.opensource at gmail.com
Tue Aug 20 06:11:31 PDT 2013
Hi,
Please find the patch for incorrect ABI in case we have a union argument
passed by value.
Index: test/CodeGen/transparent-union.c
===================================================================
--- test/CodeGen/transparent-union.c (revision 188794)
+++ test/CodeGen/transparent-union.c (working copy)
@@ -1,9 +1,7 @@
// RUN: %clang_cc1 -Werror -triple i386-unknown-unknown -emit-llvm -o %t %s
// RUN: FileCheck < %t %s
-//
-// FIXME: Note that we don't currently get the ABI right here. f0() should
be
-// f0(i8*).
+
typedef union {
void *f0;
} transp_t0 __attribute__((transparent_union));
@@ -11,7 +9,7 @@
void f0(transp_t0 obj);
// CHECK-LABEL: define void @f1_0(i32* %a0)
-// CHECK: call void @f0(%union.transp_t0* byval align 4 %{{.*}})
+// CHECK: call void @f0(i8* %{{.*}})
// CHECK: call void %{{.*}}(i8* %{{[a-z0-9]*}})
// CHECK: }
void f1_0(int *a0) {
Index: lib/CodeGen/TargetInfo.cpp
===================================================================
--- lib/CodeGen/TargetInfo.cpp (revision 188794)
+++ lib/CodeGen/TargetInfo.cpp (working copy)
@@ -325,10 +325,11 @@
//
// FIXME: This needs to be generalized to handle classes as well.
const RecordDecl *RD = RT->getDecl();
- if (!RD->isStruct() || isa<CXXRecordDecl>(RD))
+ if (!(RD->isStruct() || RD->isUnion()) || isa<CXXRecordDecl>(RD))
return false;
uint64_t Size = 0;
+ uint64_t CurrentElmtSize = 0;
for (RecordDecl::field_iterator i = RD->field_begin(), e =
RD->field_end();
i != e; ++i) {
@@ -343,7 +344,14 @@
if (FD->isBitField())
return false;
+ if (!RD->isUnion())
Size += Context.getTypeSize(FD->getType());
+ else {
+ //Size of union is size of it's largest element.
+ CurrentElmtSize = Context.getTypeSize(FD->getType());
+ if (CurrentElmtSize > Size)
+ Size = CurrentElmtSize;
+ }
}
// Make sure there are not any holes in the struct.
Regards
Karthik Bhat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130820/58b1e295/attachment.html>
More information about the cfe-commits
mailing list