]> granicus.if.org Git - clang/commitdiff
Evaluate union cast subexpressions when the cast value is unused
authorReid Kleckner <reid@kleckner.net>
Wed, 20 May 2015 21:59:25 +0000 (21:59 +0000)
committerReid Kleckner <reid@kleckner.net>
Wed, 20 May 2015 21:59:25 +0000 (21:59 +0000)
Fixes PR23597.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237839 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprAgg.cpp
test/CodeGen/exprs.c

index 77e4464ee8c6df1fb53cda150eafd37eaf4f8f5a..6fedf0efda9d8f87f60bd716706b281177dff3a2 100644 (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();
index f7b6ab87b20e8bf3a9e329c8d44b180308a4c80f..59afa802b18385fe74e0f0a21ec5e3bbf2b250cc 100644 (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()