[PATCH] D41311: [CodeGen] Fix crash when a function taking transparent union is redeclared.

Volodymyr Sapsai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 15 15:23:47 PST 2017


vsapsai created this revision.
vsapsai added reviewers: rjmccall, rafael.
Herald added subscribers: kristof.beyls, aemerson.

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 we would be able to cast
to 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.
Added them because when trying different fix I regressed on those cases
but there were no tests to catch it.

rdar://problem/34949329


https://reviews.llvm.org/D41311

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/transparent-union-redecl.c
  clang/test/Sema/transparent-union.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41311.127199.patch
Type: text/x-patch
Size: 4399 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171215/6c4afad0/attachment-0001.bin>


More information about the cfe-commits mailing list