diff options
| author | Timm Baeder <tbaeder@redhat.com> | 2025-10-17 14:51:16 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-17 14:51:16 +0200 |
| commit | f44f83a35d0faa2393e63d7e3a0343277366a695 (patch) | |
| tree | 2f8e0bda3644c64905881c6493ad115165c2f250 | |
| parent | 0cefd5c3c2277f24d195aa6d6a730e41515e6495 (diff) | |
| download | llvm-f44f83a35d0faa2393e63d7e3a0343277366a695.zip llvm-f44f83a35d0faa2393e63d7e3a0343277366a695.tar.gz llvm-f44f83a35d0faa2393e63d7e3a0343277366a695.tar.bz2 | |
[clang][bytecode] Reject typeid pointers from OffsetHelper (#163793)
| -rw-r--r-- | clang/lib/AST/ByteCode/Interp.h | 2 | ||||
| -rw-r--r-- | clang/test/AST/ByteCode/typeid.cpp | 7 |
2 files changed, 7 insertions, 2 deletions
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index 812d25f..2f7e2d9 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -2258,6 +2258,8 @@ std::optional<Pointer> OffsetHelper(InterpState &S, CodePtr OpPC, S.CCEDiag(S.Current->getSource(OpPC), diag::note_constexpr_array_index) << N << /*non-array*/ true << 0; return Pointer(Ptr.asFunctionPointer().getFunction(), N); + } else if (!Ptr.isBlockPointer()) { + return std::nullopt; } assert(Ptr.isBlockPointer()); diff --git a/clang/test/AST/ByteCode/typeid.cpp b/clang/test/AST/ByteCode/typeid.cpp index 090309d1..aca18d4 100644 --- a/clang/test/AST/ByteCode/typeid.cpp +++ b/clang/test/AST/ByteCode/typeid.cpp @@ -63,9 +63,12 @@ namespace TypeidPtrInEvaluationResult { // 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}} + // both-note {{cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression}} + } + void dontcrash2() { + constexpr auto res = ((void**)&typeid(int))[1]; // 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}} } } |
