Skip to content

Commit 03f2776

Browse files
committed
[clang][bytecode] Fix a crash with typeid pointers
That code is from a time when typeid pointers didn't exist. We can get there for non-block, non-integral pointers, but we can't meaningfully handle that case. Just return false. Fixes #153712
1 parent e16ced3 commit 03f2776

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

clang/lib/AST/ByteCode/Interp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,6 +1788,8 @@ inline bool GetPtrBase(InterpState &S, CodePtr OpPC, uint32_t Off) {
17881788
return false;
17891789

17901790
if (!Ptr.isBlockPointer()) {
1791+
if (!Ptr.isIntegralPointer())
1792+
return false;
17911793
S.Stk.push<Pointer>(Ptr.asIntPointer().baseCast(S.getASTContext(), Off));
17921794
return true;
17931795
}
@@ -1809,6 +1811,8 @@ inline bool GetPtrBasePop(InterpState &S, CodePtr OpPC, uint32_t Off,
18091811
return false;
18101812

18111813
if (!Ptr.isBlockPointer()) {
1814+
if (!Ptr.isIntegralPointer())
1815+
return false;
18121816
S.Stk.push<Pointer>(Ptr.asIntPointer().baseCast(S.getASTContext(), Off));
18131817
return true;
18141818
}

clang/test/AST/ByteCode/typeid.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ struct __type_info_implementations {
1313
typedef __unique_impl __impl;
1414
};
1515

16-
class type_info {
16+
class __pointer_type_info {
17+
public:
18+
int __flags = 0;
19+
};
20+
21+
class type_info : public __pointer_type_info {
1722
protected:
1823
typedef __type_info_implementations::__impl __impl;
1924
__impl::__type_name_t __type_name;
@@ -40,3 +45,10 @@ constexpr bool test() {
4045
return true;
4146
}
4247
static_assert(test());
48+
49+
int dontcrash() {
50+
auto& pti = static_cast<const std::__pointer_type_info&>(
51+
typeid(int)
52+
);
53+
return pti.__flags == 0 ? 1 : 0;
54+
}

0 commit comments

Comments
 (0)