Index: clang/lib/CodeGen/CGCall.cpp =================================================================== --- clang/lib/CodeGen/CGCall.cpp +++ clang/lib/CodeGen/CGCall.cpp @@ -2317,6 +2317,7 @@ // If we have the trivial case, handle it with no muss and fuss. if (!isa(ArgI.getCoerceToType()) && + !isa(ConvertType(Arg->getType())) && ArgI.getCoerceToType() == ConvertType(Ty) && ArgI.getDirectOffset() == 0) { assert(NumIRArgs == 1); @@ -2414,8 +2415,8 @@ break; } - Address Alloca = CreateMemTemp(Ty, getContext().getDeclAlign(Arg), - Arg->getName()); + Address Alloca = CreateMemTemp( + Arg->getType(), getContext().getDeclAlign(Arg), Arg->getName()); // Pointer to store into. Address Ptr = emitAddressAtOffset(*this, Alloca, ArgI); @@ -2461,9 +2462,9 @@ } // Match to what EmitParmDecl is expecting for this type. - if (CodeGenFunction::hasScalarEvaluationKind(Ty)) { + if (CodeGenFunction::hasScalarEvaluationKind(Arg->getType())) { llvm::Value *V = - EmitLoadOfScalar(Alloca, false, Ty, Arg->getLocStart()); + EmitLoadOfScalar(Alloca, false, Arg->getType(), Arg->getLocStart()); if (isPromoted) V = emitArgumentDemotion(*this, Arg, V); ArgVals.push_back(ParamValue::forDirect(V)); Index: clang/test/CodeGen/transparent-union-redecl.c =================================================================== --- /dev/null +++ clang/test/CodeGen/transparent-union-redecl.c @@ -0,0 +1,36 @@ +// RUN: %clang_cc1 -Werror -triple i386-linux -emit-llvm -o - %s | FileCheck %s + +// Test that different order of declarations is acceptable and that +// implementing different redeclarations is acceptable. +// rdar://problem/34949329 + +typedef union { + int i; + float f; +} TU __attribute__((transparent_union)); + +// CHECK-LABEL: define void @f0(i32 %tu.coerce) +// CHECK: %tu = alloca %union.TU, align 4 +// CHECK: %coerce.dive = getelementptr inbounds %union.TU, %union.TU* %tu, i32 0, i32 0 +// CHECK: store i32 %tu.coerce, i32* %coerce.dive, align 4 +void f0(TU tu) {} +void f0(int i); + +// CHECK-LABEL: define void @f1(i32 %tu.coerce) +// CHECK: %tu = alloca %union.TU, align 4 +// CHECK: %coerce.dive = getelementptr inbounds %union.TU, %union.TU* %tu, i32 0, i32 0 +// CHECK: store i32 %tu.coerce, i32* %coerce.dive, align 4 +void f1(int i); +void f1(TU tu) {} + +// CHECK-LABEL: define void @f2(i32 %i) +// CHECK: %i.addr = alloca i32, align 4 +// CHECK: store i32 %i, i32* %i.addr, align 4 +void f2(TU tu); +void f2(int i) {} + +// CHECK-LABEL: define void @f3(i32 %i) +// CHECK: %i.addr = alloca i32, align 4 +// CHECK: store i32 %i, i32* %i.addr, align 4 +void f3(int i) {} +void f3(TU tu); Index: clang/test/Sema/transparent-union.c =================================================================== --- clang/test/Sema/transparent-union.c +++ clang/test/Sema/transparent-union.c @@ -43,6 +43,35 @@ void fvpp(TU); // expected-note{{previous declaration is here}} void fvpp(void **v) {} // expected-error{{conflicting types}} +/* Test redeclaring a function taking a transparent_union arg more than twice. + Merging different declarations depends on their order, vary order too. */ + +void f_triple0(TU tu) {} +void f_triple0(int *); // expected-note{{previous declaration is here}} +void f_triple0(float *f); // expected-error{{conflicting types}} + +void f_triple1(int *); +void f_triple1(TU tu) {} // expected-note{{previous definition is here}} +void f_triple1(float *f); // expected-error{{conflicting types}} + +void f_triple2(int *); // expected-note{{previous declaration is here}} +void f_triple2(float *f); // expected-error{{conflicting types}} +void f_triple2(TU tu) {} + +/* Test calling redeclared function taking a transparent_union arg. */ + +void f_callee(TU); +void f_callee(int *i) {} // expected-note{{passing argument to parameter 'i' here}} + +void caller(void) { + TU tu; + f_callee(tu); // expected-error{{passing 'TU' to parameter of incompatible type 'int *'}} + + int *i; + f_callee(i); +} + + /* FIXME: we'd like to just use an "int" here and align it differently from the normal "int", but if we do so we lose the alignment information from the typedef within the compiler. */