[clang] a1bcc8f - [clang][bytecode] Diagnose heap-allocated array elem pointers... (#137523)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 27 09:01:23 PDT 2025
Author: Timm Baeder
Date: 2025-04-27T18:01:19+02:00
New Revision: a1bcc8f757ff70e3504c7cca1219a474c55325d1
URL: https://github.com/llvm/llvm-project/commit/a1bcc8f757ff70e3504c7cca1219a474c55325d1
DIFF: https://github.com/llvm/llvm-project/commit/a1bcc8f757ff70e3504c7cca1219a474c55325d1.diff
LOG: [clang][bytecode] Diagnose heap-allocated array elem pointers... (#137523)
... as "pointer to subobject".
Added:
Modified:
clang/lib/AST/ByteCode/EvaluationResult.cpp
clang/test/AST/ByteCode/new-delete.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/EvaluationResult.cpp b/clang/lib/AST/ByteCode/EvaluationResult.cpp
index d603e08c7bb4d..f59612bf00015 100644
--- a/clang/lib/AST/ByteCode/EvaluationResult.cpp
+++ b/clang/lib/AST/ByteCode/EvaluationResult.cpp
@@ -230,8 +230,9 @@ bool EvaluationResult::checkReturnValue(InterpState &S, const Context &Ctx,
assert(B->getDescriptor());
assert(B->getDescriptor()->asExpr());
+ bool IsSubobj = !Ptr.isRoot() || Ptr.isArrayElement();
S.FFDiag(Info, diag::note_constexpr_dynamic_alloc)
- << Ptr.getType()->isReferenceType() << !Ptr.isRoot();
+ << Ptr.getType()->isReferenceType() << IsSubobj;
S.Note(B->getDescriptor()->asExpr()->getExprLoc(),
diag::note_constexpr_dynamic_alloc_here);
return false;
diff --git a/clang/test/AST/ByteCode/new-delete.cpp b/clang/test/AST/ByteCode/new-delete.cpp
index 21d65461c79c7..6726659d49e71 100644
--- a/clang/test/AST/ByteCode/new-delete.cpp
+++ b/clang/test/AST/ByteCode/new-delete.cpp
@@ -620,6 +620,10 @@ namespace std {
}
}
+constexpr int *escape = std::allocator<int>().allocate(3); // both-error {{constant expression}} \
+ // both-note {{pointer to subobject of heap-allocated}} \
+ // both-note {{heap allocation performed here}}
+
/// Specialization for float, using operator new/delete.
namespace std {
using size_t = decltype(sizeof(0));
More information about the cfe-commits
mailing list