Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions clang/lib/AST/ByteCode/Interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -3096,7 +3096,8 @@ inline bool ArrayElemPtr(InterpState &S, CodePtr OpPC) {
}

if (Offset.isZero()) {
if (Ptr.getFieldDesc()->isArray() && Ptr.getIndex() == 0) {
if (const Descriptor *Desc = Ptr.getFieldDesc();
Desc && Desc->isArray() && Ptr.getIndex() == 0) {
S.Stk.push<Pointer>(Ptr.atIndex(0).narrow());
return true;
}
Expand Down Expand Up @@ -3126,7 +3127,8 @@ inline bool ArrayElemPtrPop(InterpState &S, CodePtr OpPC) {
}

if (Offset.isZero()) {
if (Ptr.getFieldDesc()->isArray() && Ptr.getIndex() == 0) {
if (const Descriptor *Desc = Ptr.getFieldDesc();
Desc && Desc->isArray() && Ptr.getIndex() == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to do the same change in ArrayElemPtr above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added with dae76b1

Do you think we need this kind of check for each use of getFieldDesc? Or the other uses are not supposed to be null
If so, I think we need some assertions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it's fine.

S.Stk.push<Pointer>(Ptr.atIndex(0).narrow());
return true;
}
Expand Down
10 changes: 10 additions & 0 deletions clang/test/AST/ByteCode/typeid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,13 @@ namespace TypeidPtrInEvaluationResult {
consteval const std::type_info *ftype_info() { return &typeid(c); }
const std::type_info *T1 = ftype_info();
}

// Regression test for crash in ArrayElemPtrPop with typeid pointers. GH-163127
namespace TypeidPtrRegression {
void dontcrash() {
// this should just be an error and not an ICE
constexpr auto res = ((void**)&typeid(int))[0]; // both-error {{must be initialized by a constant expression}} \
// both-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}}
}
}