[clang] 0d9decc - [clang][Interp] Handle invalid CXXCtorInitializer expressions
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 9 00:20:53 PST 2024
Author: Timm Bäder
Date: 2024-02-09T09:20:41+01:00
New Revision: 0d9decc6694c188e2f7fa17d140ba9bd7cc98b6b
URL: https://github.com/llvm/llvm-project/commit/0d9decc6694c188e2f7fa17d140ba9bd7cc98b6b
DIFF: https://github.com/llvm/llvm-project/commit/0d9decc6694c188e2f7fa17d140ba9bd7cc98b6b.diff
LOG: [clang][Interp] Handle invalid CXXCtorInitializer expressions
Their type might be a null type, in which case we need to abort here.
Added:
Modified:
clang/lib/AST/Interp/ByteCodeStmtGen.cpp
clang/test/AST/Interp/records.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index b0ec90a1f2851c..bedcc78dc23555 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -144,6 +144,10 @@ bool ByteCodeStmtGen<Emitter>::visitFunc(const FunctionDecl *F) {
auto emitFieldInitializer = [&](const Record::Field *F, unsigned FieldOffset,
const Expr *InitExpr) -> bool {
+ // We don't know what to do with these, so just return false.
+ if (InitExpr->getType().isNull())
+ return false;
+
if (std::optional<PrimType> T = this->classify(InitExpr)) {
if (!this->visit(InitExpr))
return false;
diff --git a/clang/test/AST/Interp/records.cpp b/clang/test/AST/Interp/records.cpp
index fb50d1c6c5833a..93da831f3bda0a 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -1228,3 +1228,14 @@ namespace InheritedConstructor {
constexpr S s(1);
}
}
+
+namespace InvalidCtorInitializer {
+ struct X {
+ int Y;
+ constexpr X() // expected-note {{declared here}}
+ : Y(fo_o_()) {} // both-error {{use of undeclared identifier 'fo_o_'}}
+ };
+ // no crash on evaluating the constexpr ctor.
+ constexpr int Z = X().Y; // both-error {{constexpr variable 'Z' must be initialized by a constant expression}} \
+ // expected-note {{undefined constructor 'X'}}
+}
More information about the cfe-commits
mailing list