[clang] [clang][bytecode] Reject invalid CXXNewExprs (PR #179629)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 4 01:22:17 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
If they contain errors, we can't rely on any of their API returning sane values.
---
Full diff: https://github.com/llvm/llvm-project/pull/179629.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+3)
- (modified) clang/test/AST/ByteCode/placement-new.cpp (+2)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index af076f90733df..7401eccb4dbdd 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -3598,6 +3598,9 @@ bool Compiler<Emitter>::VisitCXXNewExpr(const CXXNewExpr *E) {
const Expr *PlacementDest = nullptr;
bool IsNoThrow = false;
+ if (E->containsErrors())
+ return false;
+
if (PlacementArgs != 0) {
// FIXME: There is no restriction on this, but it's not clear that any
// other form makes any sense. We get here for cases such as:
diff --git a/clang/test/AST/ByteCode/placement-new.cpp b/clang/test/AST/ByteCode/placement-new.cpp
index f458ea17b6cc6..503e456565f5d 100644
--- a/clang/test/AST/ByteCode/placement-new.cpp
+++ b/clang/test/AST/ByteCode/placement-new.cpp
@@ -522,3 +522,5 @@ constexpr int intDestArray() {
static_assert(intDestArray() == 0); // both-error {{not an integral constant expression}} \
// both-note {{in call to}}
+constexpr void invalidDest() { new (undefinedfunction()) int; } // both-error {{use of undeclared identifier 'undefinedfunction'}}
+static_assert((invalidDest(), true)); // both-error {{not an integral constant expression}}
``````````
</details>
https://github.com/llvm/llvm-project/pull/179629
More information about the cfe-commits
mailing list