[clang] [clang][bytecode] Check for errors in CXXDeleteExprs (PR #185189)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Mar 7 05:22:51 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
e.g. `getOperatorDelete()` may return null for those.
---
Full diff: https://github.com/llvm/llvm-project/pull/185189.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+3-3)
- (modified) clang/test/AST/ByteCode/new-delete.cpp (+9)
``````````diff
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}}
``````````
</details>
https://github.com/llvm/llvm-project/pull/185189
More information about the cfe-commits
mailing list