[clang] [clang][bytecode] Fix assert when calling static functions via CallVirt (PR #224253)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 17 03:01:17 PDT 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/224253
This only happens in error cases.
>From 8a62aa1d6c49e40a0ebfe7a6e88d00a5222b3035 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Thu, 17 Sep 2026 12:00:05 +0200
Subject: [PATCH] [clang][bytecode] Fix assert when calling static functions
via CallVirt
This only happens in error cases.
---
clang/lib/AST/ByteCode/Interp.cpp | 6 ++++++
clang/test/AST/ByteCode/cxx20.cpp | 13 +++++++++++++
2 files changed, 19 insertions(+)
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