[clang] cf55dfb - [clang][bytecode] Fix null Descriptor dereference in ArrayElemPtrPop (#163386)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 16 00:47:46 PDT 2025
Author: term-est
Date: 2025-10-16T09:47:42+02:00
New Revision: cf55dfbc5a73d584bab468229a96c63fa7de1f6e
URL: https://github.com/llvm/llvm-project/commit/cf55dfbc5a73d584bab468229a96c63fa7de1f6e
DIFF: https://github.com/llvm/llvm-project/commit/cf55dfbc5a73d584bab468229a96c63fa7de1f6e.diff
LOG: [clang][bytecode] Fix null Descriptor dereference in ArrayElemPtrPop (#163386)
Fixes #163127
Added:
Modified:
clang/lib/AST/ByteCode/Interp.h
clang/test/AST/ByteCode/typeid.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 57cc705282d1b..812d25fc79490 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -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;
}
@@ -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) {
S.Stk.push<Pointer>(Ptr.atIndex(0).narrow());
return true;
}
diff --git a/clang/test/AST/ByteCode/typeid.cpp b/clang/test/AST/ByteCode/typeid.cpp
index 00b01c8e40682..090309d16e737 100644
--- a/clang/test/AST/ByteCode/typeid.cpp
+++ b/clang/test/AST/ByteCode/typeid.cpp
@@ -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}}
+ }
+}
+
More information about the cfe-commits
mailing list