[clang] 5dcda94 - [clang][bytecode] Handle missing DynamicDecl in CallVirt (#187980)

via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 23 01:15:39 PDT 2026


Author: Timm Baeder
Date: 2026-03-23T09:15:33+01:00
New Revision: 5dcda94b163eab26a75a27529ff3894dc41dc235

URL: https://github.com/llvm/llvm-project/commit/5dcda94b163eab26a75a27529ff3894dc41dc235
DIFF: https://github.com/llvm/llvm-project/commit/5dcda94b163eab26a75a27529ff3894dc41dc235.diff

LOG: [clang][bytecode] Handle missing DynamicDecl in CallVirt (#187980)

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

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Interp.cpp
    clang/test/AST/ByteCode/records.cpp

Removed: 
    


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


        


More information about the cfe-commits mailing list