[clang] [clang][bytecode] Handle missing DynamicDecl in CallVirt (PR #187980)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 22 23:31:37 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
Don't return true from getDynamicDecl() if the returned DynamicDecl is null.
---
Full diff: https://github.com/llvm/llvm-project/pull/187980.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Interp.cpp (+3-3)
- (modified) clang/test/AST/ByteCode/records.cpp (+8)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 360291ef4e9da..1b6b785b58757 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1771,7 +1771,7 @@ bool Call(InterpState &S, CodePtr OpPC, const Function *Func,
return true;
}
-static bool GetDynamicDecl(InterpState &S, CodePtr OpPC, Pointer TypePtr,
+static bool getDynamicDecl(InterpState &S, CodePtr OpPC, Pointer TypePtr,
const CXXRecordDecl *&DynamicDecl) {
TypePtr = TypePtr.stripBaseCasts();
@@ -1797,7 +1797,7 @@ static bool GetDynamicDecl(InterpState &S, CodePtr OpPC, Pointer TypePtr,
} else {
DynamicDecl = DynamicType->getAsCXXRecordDecl();
}
- return true;
+ return DynamicDecl != nullptr;
}
bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func,
@@ -1810,7 +1810,7 @@ bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func,
const FunctionDecl *Callee = Func->getDecl();
const CXXRecordDecl *DynamicDecl = nullptr;
- if (!GetDynamicDecl(S, OpPC, ThisPtr, DynamicDecl))
+ if (!getDynamicDecl(S, OpPC, ThisPtr, DynamicDecl))
return false;
assert(DynamicDecl);
diff --git a/clang/test/AST/ByteCode/records.cpp b/clang/test/AST/ByteCode/records.cpp
index 804b4c6ea466a..a6aea0458e4ed 100644
--- a/clang/test/AST/ByteCode/records.cpp
+++ b/clang/test/AST/ByteCode/records.cpp
@@ -1902,3 +1902,11 @@ namespace StaticRedecl {
constexpr T t;
static_assert(t.p == &T::tt, "");
}
+
+namespace VirtCallNoRecord {
+ struct S {
+ virtual int foo();
+ };
+ int bar(int{((S *const)0)->foo()});
+}
+
``````````
</details>
https://github.com/llvm/llvm-project/pull/187980
More information about the cfe-commits
mailing list