Skip to content

Commit c9bb3bd

Browse files
authored
[clang][bytecode] Fix a crash with typeid pointers (#154692)
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 f306e0a commit c9bb3bd

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
@@ -1806,6 +1806,8 @@ inline bool GetPtrBase(InterpState &S, CodePtr OpPC, uint32_t Off) {
18061806
return false;
18071807

18081808
if (!Ptr.isBlockPointer()) {
1809+
if (!Ptr.isIntegralPointer())
1810+
return false;
18091811
S.Stk.push<Pointer>(Ptr.asIntPointer().baseCast(S.getASTContext(), Off));
18101812
return true;
18111813
}
@@ -1827,6 +1829,8 @@ inline bool GetPtrBasePop(InterpState &S, CodePtr OpPC, uint32_t Off,
18271829
return false;
18281830

18291831
if (!Ptr.isBlockPointer()) {
1832+
if (!Ptr.isIntegralPointer())
1833+
return false;
18301834
S.Stk.push<Pointer>(Ptr.asIntPointer().baseCast(S.getASTContext(), Off));
18311835
return true;
18321836
}

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)