diff options
-rw-r--r-- | clang/lib/CodeGen/CGExprAgg.cpp | 7 | ||||
-rw-r--r-- | clang/test/CodeGen/exprs.c | 11 |
2 files changed, 17 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index 77e4464ee8c..6fedf0efda9 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/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/clang/test/CodeGen/exprs.c b/clang/test/CodeGen/exprs.c index f7b6ab87b20..59afa802b18 100644 --- a/clang/test/CodeGen/exprs.c +++ b/clang/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() |