[PATCH] D77502: [clang][CodeGen] Handle throw expression in conditional operator constant folding
Richard Smith - zygoloid via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 8 13:03:17 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG878d96011acc: [clang][CodeGen] Handle throw expression in conditional operator constant… (authored by tambre, committed by rsmith).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D77502/new/
https://reviews.llvm.org/D77502
Files:
clang/lib/CodeGen/CGExpr.cpp
clang/test/CodeGenCXX/throw-expressions.cpp
Index: clang/test/CodeGenCXX/throw-expressions.cpp
===================================================================
--- clang/test/CodeGenCXX/throw-expressions.cpp
+++ clang/test/CodeGenCXX/throw-expressions.cpp
@@ -79,6 +79,12 @@
// CHECK-NOT: call {{.*}}@_ZN6DR15601AD1Ev
// CHECK: call {{.*}} @__cxa_atexit({{.*}} @_ZN6DR15601AD1Ev {{.*}} @_ZGRN6DR15601rE
// CHECK-NOT: call {{.*}}@_ZN6DR15601AD1Ev
+
+ // PR28184
+ void conditional_throw() {
+ int a;
+ (true ? throw 0 : a) = 0; // CHECK: call void @__cxa_throw({{.*}})
+ }
}
// CHECK-LABEL: define void @_Z5test7b(
Index: clang/lib/CodeGen/CGExpr.cpp
===================================================================
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -4331,6 +4331,16 @@
// If the true case is live, we need to track its region.
if (CondExprBool)
incrementProfileCounter(expr);
+ // If a throw expression we emit it and return an undefined lvalue
+ // because it can't be used.
+ if (auto *ThrowExpr = dyn_cast<CXXThrowExpr>(live->IgnoreParens())) {
+ EmitCXXThrowExpr(ThrowExpr);
+ llvm::Type *Ty =
+ llvm::PointerType::getUnqual(ConvertType(dead->getType()));
+ return MakeAddrLValue(
+ Address(llvm::UndefValue::get(Ty), CharUnits::One()),
+ dead->getType());
+ }
return EmitLValue(live);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77502.256099.patch
Type: text/x-patch
Size: 1425 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200408/a730306c/attachment.bin>
More information about the cfe-commits
mailing list