[clang] 2980a76 - [clang][bytecode] Fix assert when calling static functions via CallVirt (#224253)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 17 04:38:06 PDT 2026
Author: Timm Baeder
Date: 2026-09-17T13:38:00+02:00
New Revision: 2980a76d91fa43c8d4ad21dbf9346efc0ef05d3d
URL: https://github.com/llvm/llvm-project/commit/2980a76d91fa43c8d4ad21dbf9346efc0ef05d3d
DIFF: https://github.com/llvm/llvm-project/commit/2980a76d91fa43c8d4ad21dbf9346efc0ef05d3d.diff
LOG: [clang][bytecode] Fix assert when calling static functions via CallVirt (#224253)
This only happens in error cases.
Added:
Modified:
clang/lib/AST/ByteCode/Interp.cpp
clang/test/AST/ByteCode/cxx20.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 5b0422d9ae9bd..de7d8ce188f97 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -2427,6 +2427,12 @@ bool DynamicCast(InterpState &S, CodePtr OpPC, const Type *DestTypePtr,
bool CallVirt(InterpState &S, CodePtr OpPC, const Function *Func,
uint32_t VarArgSize) {
+ // This happens in error cases.
+ if (!Func->hasThisPointer()) {
+ assert(!Func->isValid());
+ return diagnoseCallableDecl(S, OpPC, Func->getDecl());
+ }
+
assert(Func->hasThisPointer());
assert(Func->isVirtual());
size_t ArgSize = Func->getArgSize() + VarArgSize;
diff --git a/clang/test/AST/ByteCode/cxx20.cpp b/clang/test/AST/ByteCode/cxx20.cpp
index b06a3ed9149cb..c5ade52a66b40 100644
--- a/clang/test/AST/ByteCode/cxx20.cpp
+++ b/clang/test/AST/ByteCode/cxx20.cpp
@@ -1531,3 +1531,16 @@ namespace SubPtr {
}
static_assert(dynAlloc() == 1);
}
+
+namespace InvalidVirtualCall {
+ struct A {
+ virtual void foo(); // both-note {{overridden virtual function is here}}
+ };
+
+ struct B : A {
+ constexpr void bar() { foo(); } // both-error {{never produces a constant expression}} \
+ // both-note {{non-constexpr function 'foo' cannot be used in a constant expression}}
+ static void foo(); // both-error {{'static' member function 'foo' overrides a virtual function in a base class}} \
+ // both-note {{declared here}}
+ };
+}
More information about the cfe-commits
mailing list