[clang] 7010a4f - [clang][Interp] Don't assume throw stmts have a subexpr
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 28 03:45:20 PDT 2023
Author: Timm Bäder
Date: 2023-07-28T12:44:53+02:00
New Revision: 7010a4f14e0bb397773915910fbcf557f6ad6816
URL: https://github.com/llvm/llvm-project/commit/7010a4f14e0bb397773915910fbcf557f6ad6816
DIFF: https://github.com/llvm/llvm-project/commit/7010a4f14e0bb397773915910fbcf557f6ad6816.diff
LOG: [clang][Interp] Don't assume throw stmts have a subexpr
Differential Revision: https://reviews.llvm.org/D156503
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/invalid.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 9f17ba1d7aa05f..70ce1c3750bbf1 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1000,7 +1000,7 @@ bool ByteCodeExprGen<Emitter>::VisitPredefinedExpr(const PredefinedExpr *E) {
template <class Emitter>
bool ByteCodeExprGen<Emitter>::VisitCXXThrowExpr(const CXXThrowExpr *E) {
- if (!this->discard(E->getSubExpr()))
+ if (E->getSubExpr() && !this->discard(E->getSubExpr()))
return false;
return this->emitInvalid(E);
diff --git a/clang/test/AST/Interp/invalid.cpp b/clang/test/AST/Interp/invalid.cpp
index 9f3477e397eb5c..522ad02f71ce07 100644
--- a/clang/test/AST/Interp/invalid.cpp
+++ b/clang/test/AST/Interp/invalid.cpp
@@ -23,6 +23,17 @@ namespace Throw {
// ref-note {{subexpression not valid in a constant expression}}
return 0;
}
+
+ constexpr int NoSubExpr() { // ref-error {{never produces a constant expression}} \
+ // expected-error {{never produces a constant expression}}
+ throw; // ref-note 2{{subexpression not valid}} \
+ // expected-note 2{{subexpression not valid}}
+ return 0;
+ }
+ static_assert(NoSubExpr() == 0, ""); // ref-error {{not an integral constant expression}} \
+ // ref-note {{in call to}} \
+ // expected-error {{not an integral constant expression}} \
+ // expected-note {{in call to}}
}
namespace Asm {
More information about the cfe-commits
mailing list