r237839 - Evaluate union cast subexpressions when the cast value is unused
Reid Kleckner
reid at kleckner.net
Wed May 20 14:59:25 PDT 2015
Author: rnk
Date: Wed May 20 16:59:25 2015
New Revision: 237839
URL: http://llvm.org/viewvc/llvm-project?rev=237839&view=rev
Log:
Evaluate union cast subexpressions when the cast value is unused
Fixes PR23597.
Modified:
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/test/CodeGen/exprs.c
Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=237839&r1=237838&r2=237839&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Wed May 20 16:59:25 2015
@@ -584,7 +584,12 @@ void AggExprEmitter::VisitCastExpr(CastE
}
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();
Modified: cfe/trunk/test/CodeGen/exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/exprs.c?rev=237839&r1=237838&r2=237839&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/exprs.c (original)
+++ cfe/trunk/test/CodeGen/exprs.c Wed May 20 16:59:25 2015
@@ -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()
More information about the cfe-commits
mailing list