https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/187980

Don't return true from getDynamicDecl() if the returned DynamicDecl is null.

>From 6c3a058fd52d82b6996da47c09f57f80505b0546 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Mon, 23 Mar 2026 07:25:10 +0100
Subject: [PATCH] [clang][bytecode] Handle missing DynamicDecl in CallVirt

Don't return true from getDynamicDecl() if the returned DynamicDecl is
null.
---
 clang/lib/AST/ByteCode/Interp.cpp   | 6 +++---
 clang/test/AST/ByteCode/records.cpp | 8 ++++++++
 2 files changed, 11 insertions(+), 3 deletions(-)

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()});
+}
+

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to