Skip to content

Commit f44f83a

Browse files
authored
[clang][bytecode] Reject typeid pointers from OffsetHelper (#163793)
1 parent 0cefd5c commit f44f83a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

clang/lib/AST/ByteCode/Interp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2258,6 +2258,8 @@ std::optional<Pointer> OffsetHelper(InterpState &S, CodePtr OpPC,
22582258
S.CCEDiag(S.Current->getSource(OpPC), diag::note_constexpr_array_index)
22592259
<< N << /*non-array*/ true << 0;
22602260
return Pointer(Ptr.asFunctionPointer().getFunction(), N);
2261+
} else if (!Ptr.isBlockPointer()) {
2262+
return std::nullopt;
22612263
}
22622264

22632265
assert(Ptr.isBlockPointer());

clang/test/AST/ByteCode/typeid.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ namespace TypeidPtrInEvaluationResult {
6363
// Regression test for crash in ArrayElemPtrPop with typeid pointers. GH-163127
6464
namespace TypeidPtrRegression {
6565
void dontcrash() {
66-
// this should just be an error and not an ICE
6766
constexpr auto res = ((void**)&typeid(int))[0]; // both-error {{must be initialized by a constant expression}} \
68-
// both-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}}
67+
// both-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}}
68+
}
69+
void dontcrash2() {
70+
constexpr auto res = ((void**)&typeid(int))[1]; // both-error {{must be initialized by a constant expression}} \
71+
// both-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}}
6972
}
7073
}
7174

0 commit comments

Comments
 (0)