[clang] [llvm] [Clang]: Enable speculative devirtualization (PR #159685)

Teresa Johnson via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 25 07:35:29 PST 2025


================
@@ -0,0 +1,77 @@
+// Test that Clang emits vtable metadata when speculative devirtualization is enabled.
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fdevirtualize-speculatively -emit-llvm -o - %s | FileCheck --check-prefix=VTABLE-OPT --check-prefix=TT-ITANIUM-DEFAULT-NOLTO-SPECULATIVE-DEVIRT  %s
+
+struct A {
+  A();
+  virtual void f();
+};
+
+struct B : virtual A {
+  B();
+  virtual void g();
+  virtual void h();
+};
+
+namespace {
+
+struct D : B {
+  D();
+  virtual void f();
+  virtual void h();
+};
+
+}
+
+A::A() {}
+B::B() {}
+D::D() {}
+
+void A::f() {
+}
+
+void B::g() {
+}
+
+void D::f() {
+}
+
+void D::h() {
+}
+
+void af(A *a) {
+  // TT-ITANIUM-DEFAULT-NOLTO-SPECULATIVE-DEVIRT: [[P:%[^ ]*]] = call i1 @llvm.public.type.test(ptr [[VT:%[^ ]*]], metadata !"_ZTS1A")
----------------
teresajohnson wrote:

Nit: does this check label need to be so long? Does it even need to be distinct from VTABLE-OPT since they must be used together? They could both simply be CHECK without any loss of clarity I think. Actually that would probably be clearer.

https://github.com/llvm/llvm-project/pull/159685


More information about the cfe-commits mailing list