Evaluate union cast subexpressions when the cast value is unused

Fixes PR23597.

llvm-svn: 237839
This commit is contained in:
Reid Kleckner 2015-05-20 21:59:25 +00:00
parent 0c28fd7fda
commit 892bb0cace
2 changed files with 17 additions and 1 deletions

View File

@ -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();

View File

@ -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()