From c9bb3bdbcae1381dc1e08e33a7935c14a99aa0e4 Mon Sep 17 00:00:00 2001 From: Timm Baeder Date: Thu, 21 Aug 2025 13:13:02 +0200 Subject: [PATCH] [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 --- clang/lib/AST/ByteCode/Interp.h | 4 ++++ clang/test/AST/ByteCode/typeid.cpp | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h index 86fca7f652a4..4eaaa018824b 100644 --- a/clang/lib/AST/ByteCode/Interp.h +++ b/clang/lib/AST/ByteCode/Interp.h @@ -1806,6 +1806,8 @@ inline bool GetPtrBase(InterpState &S, CodePtr OpPC, uint32_t Off) { return false; if (!Ptr.isBlockPointer()) { + if (!Ptr.isIntegralPointer()) + return false; S.Stk.push(Ptr.asIntPointer().baseCast(S.getASTContext(), Off)); return true; } @@ -1827,6 +1829,8 @@ inline bool GetPtrBasePop(InterpState &S, CodePtr OpPC, uint32_t Off, return false; if (!Ptr.isBlockPointer()) { + if (!Ptr.isIntegralPointer()) + return false; S.Stk.push(Ptr.asIntPointer().baseCast(S.getASTContext(), Off)); return true; } diff --git a/clang/test/AST/ByteCode/typeid.cpp b/clang/test/AST/ByteCode/typeid.cpp index 5be5604016db..179a66fd7fd0 100644 --- a/clang/test/AST/ByteCode/typeid.cpp +++ b/clang/test/AST/ByteCode/typeid.cpp @@ -13,7 +13,12 @@ struct __type_info_implementations { typedef __unique_impl __impl; }; -class type_info { +class __pointer_type_info { +public: + int __flags = 0; +}; + +class type_info : public __pointer_type_info { protected: typedef __type_info_implementations::__impl __impl; __impl::__type_name_t __type_name; @@ -40,3 +45,10 @@ constexpr bool test() { return true; } static_assert(test()); + +int dontcrash() { + auto& pti = static_cast( + typeid(int) + ); + return pti.__flags == 0 ? 1 : 0; +}