https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/204063
This was missing. >From 105f3fe45bcb194a5827bdb250b8fa429a0b8df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]> Date: Tue, 16 Jun 2026 08:18:21 +0200 Subject: [PATCH] [clang][bytecode] Check record bases for dynamic allocations This was missing. --- clang/lib/AST/ByteCode/EvaluationResult.cpp | 7 +++++++ clang/test/AST/ByteCode/new-delete.cpp | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/ByteCode/EvaluationResult.cpp b/clang/lib/AST/ByteCode/EvaluationResult.cpp index 24f242758324e..10c83942fbde1 100644 --- a/clang/lib/AST/ByteCode/EvaluationResult.cpp +++ b/clang/lib/AST/ByteCode/EvaluationResult.cpp @@ -173,6 +173,13 @@ static void collectBlocks(PtrView Ptr, llvm::SetVector<const Block *> &Blocks) { if (const Record *R = Desc->ElemRecord; R && R->hasPtrField()) { + for (const Record::Base &B : R->bases()) { + if (!B.R->hasPtrField()) + continue; + PtrView BasePtr = Ptr.atField(B.Offset); + collectBlocks(BasePtr, Blocks); + } + for (const Record::Field &F : R->fields()) { if (!isOrHasPtr(F.Desc)) continue; diff --git a/clang/test/AST/ByteCode/new-delete.cpp b/clang/test/AST/ByteCode/new-delete.cpp index 7481eccd2c03a..dd61accc898cd 100644 --- a/clang/test/AST/ByteCode/new-delete.cpp +++ b/clang/test/AST/ByteCode/new-delete.cpp @@ -1226,7 +1226,7 @@ namespace ArrayDestSize { static_assert(dynarray<char>(3, 2) == 'x'); // both-error {{constant expression}} both-note {{in call}} } -namespace OpertorArrayDelete { +namespace OperatorArrayDelete { struct S {}; using State = S[2]; constexpr unsigned run(const State *s) { @@ -1241,6 +1241,19 @@ namespace OpertorArrayDelete { // both-note {{in call to}} } +namespace AllocInBase { + struct A { + int *p; + constexpr A() : p(new int) {} // both-note {{heap allocation performed here}} + }; + struct B : A { + int *m; + constexpr B() : m(new int) {} + }; + constexpr B b{}; // both-error {{must be initialized by a constant expression}} \ + // both-note {{pointer to heap-allocated object is not a constant expression}} +} + #else /// Make sure we reject this prior to C++20 constexpr int a() { // both-error {{never produces a constant expression}} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
