[clang] 3e0d6c8 - [clang][bytecode] Check for errors in CXXDeleteExprs (#185189)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Mar 7 22:17:11 PST 2026
Author: Timm Baeder
Date: 2026-03-08T07:17:06+01:00
New Revision: 3e0d6c81f22edaa8f13a54a1094ebacff1dbc7a2
URL: https://github.com/llvm/llvm-project/commit/3e0d6c81f22edaa8f13a54a1094ebacff1dbc7a2
DIFF: https://github.com/llvm/llvm-project/commit/3e0d6c81f22edaa8f13a54a1094ebacff1dbc7a2.diff
LOG: [clang][bytecode] Check for errors in CXXDeleteExprs (#185189)
e.g. `getOperatorDelete()` may return null for those.
Added:
Modified:
clang/lib/AST/ByteCode/Compiler.cpp
clang/test/AST/ByteCode/new-delete.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 93ad8eb26f29e..6d8b84a83a4ad 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4136,15 +4136,15 @@ bool Compiler<Emitter>::VisitCXXNewExpr(const CXXNewExpr *E) {
template <class Emitter>
bool Compiler<Emitter>::VisitCXXDeleteExpr(const CXXDeleteExpr *E) {
- const Expr *Arg = E->getArgument();
-
+ if (E->containsErrors())
+ return false;
const FunctionDecl *OperatorDelete = E->getOperatorDelete();
if (!OperatorDelete->isUsableAsGlobalAllocationFunctionInConstantEvaluation())
return this->emitInvalidNewDeleteExpr(E, E);
// Arg must be an lvalue.
- if (!this->visit(Arg))
+ if (!this->visit(E->getArgument()))
return false;
return this->emitFree(E->isArrayForm(), E->isGlobalDelete(), E);
diff --git a/clang/test/AST/ByteCode/new-delete.cpp b/clang/test/AST/ByteCode/new-delete.cpp
index 4e2af79a24811..bf892e79a67ac 100644
--- a/clang/test/AST/ByteCode/new-delete.cpp
+++ b/clang/test/AST/ByteCode/new-delete.cpp
@@ -1135,6 +1135,15 @@ namespace NonLiteralType {
}
}
+namespace BrokenDelete {
+ constexpr void foo() {
+ F *f = /* missing */; // both-error {{unknown type name 'F'}} \
+ // both-error {{expected expression}}
+
+ delete f;
+ }
+}
+
#else
/// Make sure we reject this prior to C++20
constexpr int a() { // both-error {{never produces a constant expression}}
More information about the cfe-commits
mailing list