From: Reid Kleckner Date: Wed, 20 May 2015 21:59:25 +0000 (+0000) Subject: Evaluate union cast subexpressions when the cast value is unused X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4574f723bd33d25e6209fe7514ac116b8ed27d0f;p=clang Evaluate union cast subexpressions when the cast value is unused Fixes PR23597. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237839 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp index 77e4464ee8..6fedf0efda 100644 --- a/lib/CodeGen/CGExprAgg.cpp +++ b/lib/CodeGen/CGExprAgg.cpp @@ -584,7 +584,12 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) { } case CK_ToUnion: { - if (Dest.isIgnored()) break; + // Evaluate even if the destination is ignored. + if (Dest.isIgnored()) { + CGF.EmitAnyExpr(E->getSubExpr(), AggValueSlot::ignored(), + /*ignoreResult=*/true); + break; + } // GCC union extension QualType Ty = E->getSubExpr()->getType(); diff --git a/test/CodeGen/exprs.c b/test/CodeGen/exprs.c index f7b6ab87b2..59afa802b1 100644 --- a/test/CodeGen/exprs.c +++ b/test/CodeGen/exprs.c @@ -184,3 +184,14 @@ void f17() { extfunc(x); // CHECK: add nsw i128 %{{.}}, -1 } + +// PR23597: We should evaluate union cast operands even if the cast is unused. +typedef union u { + int i; +} strct; +int returns_int(void); +void f18() { + (strct)returns_int(); +} +// CHECK-LABEL: define void @f18() +// CHECK: call i32 @returns_int()