Skip to content

Commit a1bcc8f

Browse files
authored
[clang][bytecode] Diagnose heap-allocated array elem pointers... (llvm#137523)
... as "pointer to subobject".
1 parent 95b2e23 commit a1bcc8f

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

clang/lib/AST/ByteCode/EvaluationResult.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,9 @@ bool EvaluationResult::checkReturnValue(InterpState &S, const Context &Ctx,
230230
assert(B->getDescriptor());
231231
assert(B->getDescriptor()->asExpr());
232232

233+
bool IsSubobj = !Ptr.isRoot() || Ptr.isArrayElement();
233234
S.FFDiag(Info, diag::note_constexpr_dynamic_alloc)
234-
<< Ptr.getType()->isReferenceType() << !Ptr.isRoot();
235+
<< Ptr.getType()->isReferenceType() << IsSubobj;
235236
S.Note(B->getDescriptor()->asExpr()->getExprLoc(),
236237
diag::note_constexpr_dynamic_alloc_here);
237238
return false;

clang/test/AST/ByteCode/new-delete.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,10 @@ namespace std {
620620
}
621621
}
622622

623+
constexpr int *escape = std::allocator<int>().allocate(3); // both-error {{constant expression}} \
624+
// both-note {{pointer to subobject of heap-allocated}} \
625+
// both-note {{heap allocation performed here}}
626+
623627
/// Specialization for float, using operator new/delete.
624628
namespace std {
625629
using size_t = decltype(sizeof(0));

0 commit comments

Comments
 (0)