-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang][bytecode] Fix a crash with typeid pointers #154692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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 llvm#153712
|
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesThat 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 Full diff: https://github.com/llvm/llvm-project/pull/154692.diff 2 Files Affected:
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 149ce3b1042db..ee756492f6694 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -1788,6 +1788,8 @@ inline bool GetPtrBase(InterpState &S, CodePtr OpPC, uint32_t Off) {
return false;
if (!Ptr.isBlockPointer()) {
+ if (!Ptr.isIntegralPointer())
+ return false;
S.Stk.push<Pointer>(Ptr.asIntPointer().baseCast(S.getASTContext(), Off));
return true;
}
@@ -1809,6 +1811,8 @@ inline bool GetPtrBasePop(InterpState &S, CodePtr OpPC, uint32_t Off,
return false;
if (!Ptr.isBlockPointer()) {
+ if (!Ptr.isIntegralPointer())
+ return false;
S.Stk.push<Pointer>(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 5be5604016db5..179a66fd7fd0a 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<const std::__pointer_type_info&>(
+ typeid(int)
+ );
+ return pti.__flags == 0 ? 1 : 0;
+}
|
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/65/builds/21561 Here is the relevant piece of the build log for the reference |
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