diff options
author | Volodymyr Sapsai <vsapsai@apple.com> | 2017-12-21 19:42:37 +0000 |
---|---|---|
committer | Volodymyr Sapsai <vsapsai@apple.com> | 2017-12-21 19:42:37 +0000 |
commit | 50739c04c36d228f7e79227d2ae69b75174bb660 (patch) | |
tree | a2e5ea9a7a39c762fe4f62907415126e449ec783 /test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp | |
parent | 749de2d465e3b5185ce6d8e24e84deebfdadc662 (diff) |
[CodeGen] Fix crash when a function taking transparent union is redeclared.
When a function taking transparent union is declared as taking one of
union members earlier in the translation unit, clang would hit an
"Invalid cast" assertion during EmitFunctionProlog. This case
corresponds to function f1 in test/CodeGen/transparent-union-redecl.c.
We decided to cast i32 to union because after merging function
declarations function parameter type becomes int,
CGFunctionInfo::ArgInfo type matches with ABIArgInfo type, so we decide
it is a trivial case. But these types should also be castable to
parameter declaration type which is not the case here.
The fix is in checking for the trivial case if ABIArgInfo type matches with
parameter declaration type. It exposed inconsistency that we check
hasScalarEvaluationKind for different types in EmitParmDecl and
EmitFunctionProlog, and comment says they should match.
Additional tests in Sema/transparent-union.c capture current behavior and make
sure there are no regressions.
rdar://problem/34949329
Reviewers: rjmccall, rafael
Reviewed By: rjmccall
Subscribers: aemerson, cfe-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D41311
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@321296 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp')
-rw-r--r-- | test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp b/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp index c9dd1dd7d8..2eca906d00 100644 --- a/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp +++ b/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp @@ -115,9 +115,15 @@ void B::foo() { // B::foo gets 'this' cast to VBase* in ECX (i.e. this+8) so we // need to adjust 'this' before use. // -// Store initial this: +// Coerce this to correct type: +// CHECK: %[[THIS_STORE:.*]] = alloca %struct.B* // CHECK: %[[THIS_ADDR:.*]] = alloca %struct.B* -// CHECK: store %struct.B* %{{.*}}, %struct.B** %[[THIS_ADDR]], align 4 +// CHECK: %[[COERCE_VAL:.*]] = bitcast i8* %{{.*}} to %struct.B* +// CHECK: store %struct.B* %[[COERCE_VAL]], %struct.B** %[[THIS_STORE]], align 4 +// +// Store initial this: +// CHECK: %[[THIS_INIT:.*]] = load %struct.B*, %struct.B** %[[THIS_STORE]] +// CHECK: store %struct.B* %[[THIS_INIT]], %struct.B** %[[THIS_ADDR]], align 4 // // Reload and adjust the this parameter: // CHECK: %[[THIS_RELOAD:.*]] = load %struct.B*, %struct.B** %[[THIS_ADDR]] |