[clang] [clang][bytecode] Reject invalid CXXNewExprs (PR #179629)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 4 01:21:40 PST 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/179629
If they contain errors, we can't rely on any of their API returning sane values.
>From c1aa1bfb55d02b8d004871a233d086c2981a1f3c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Wed, 4 Feb 2026 10:20:36 +0100
Subject: [PATCH] [clang][bytecode] Reject invalid CXXNewExprs
If they contain errors, we can't rely on any of their API returning sane
values.
---
clang/lib/AST/ByteCode/Compiler.cpp | 3 +++
clang/test/AST/ByteCode/placement-new.cpp | 2 ++
2 files changed, 5 insertions(+)
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}}
More information about the cfe-commits
mailing list