[clang] [clang-repl] Test explicit emission of dtors in runtime interface builder (NFC) (PR #89734)

Stefan Gränitz via cfe-commits cfe-commits at lists.llvm.org
Thu May 30 05:38:22 PDT 2024


https://github.com/weliveindetail updated https://github.com/llvm/llvm-project/pull/89734

>From 3aef8a0b009b54c4839a323b21cb5b09aa50d035 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Date: Tue, 23 Apr 2024 12:23:11 +0200
Subject: [PATCH 1/3] [clang-repl] Add test for explicit emission of dtors in
 the runtime interface builder

---
 clang/test/Interpreter/force-codegen-dtor.cpp | 13 +++++++++++++
 1 file changed, 13 insertions(+)
 create mode 100644 clang/test/Interpreter/force-codegen-dtor.cpp

diff --git a/clang/test/Interpreter/force-codegen-dtor.cpp b/clang/test/Interpreter/force-codegen-dtor.cpp
new file mode 100644
index 0000000000000..a299ea46d5eac
--- /dev/null
+++ b/clang/test/Interpreter/force-codegen-dtor.cpp
@@ -0,0 +1,13 @@
+// UNSUPPORTED: system-aix
+
+// RUN: cat %s | clang-repl | FileCheck %s
+int *x = new int();
+template <class T> struct GuardX { T *&x; GuardX(T *&x) : x(x) {}; ~GuardX(); };
+template <class T> GuardX<T>::~GuardX() { delete x; x = nullptr; }
+
+// clang would normally defer codegen for ~GuardX()
+// Make sure that RuntimeInterfaceBuilder requests it explicitly
+(GuardX(x))
+
+// CHECK-NOT: Symbols not found
+// CHECK-NOT: _ZN6GuardXIiED2Ev

>From 398373fb353ece01899c988570fddfb42e535fe4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Date: Tue, 23 Apr 2024 14:06:57 +0200
Subject: [PATCH 2/3] Add printf in dtor

---
 clang/test/Interpreter/force-codegen-dtor.cpp | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/clang/test/Interpreter/force-codegen-dtor.cpp b/clang/test/Interpreter/force-codegen-dtor.cpp
index a299ea46d5eac..07758bb3fa099 100644
--- a/clang/test/Interpreter/force-codegen-dtor.cpp
+++ b/clang/test/Interpreter/force-codegen-dtor.cpp
@@ -1,13 +1,17 @@
+// REQUIRES: host-supports-jit
 // UNSUPPORTED: system-aix
 
 // RUN: cat %s | clang-repl | FileCheck %s
 int *x = new int();
 template <class T> struct GuardX { T *&x; GuardX(T *&x) : x(x) {}; ~GuardX(); };
-template <class T> GuardX<T>::~GuardX() { delete x; x = nullptr; }
 
-// clang would normally defer codegen for ~GuardX()
-// Make sure that RuntimeInterfaceBuilder requests it explicitly
+// clang normally defers codegen for this out-of-line ~GuardX(), which would
+// cause the JIT to report Symbols not found: [ _ZN6GuardXIiED2Ev ]
+extern "C" int printf(const char *, ...);
+template <class T> GuardX<T>::~GuardX() { delete x; printf("Running dtor\n"); }
+
+// Let's make sure that the RuntimeInterfaceBuilder requests it explicitly:
 (GuardX(x))
 
 // CHECK-NOT: Symbols not found
-// CHECK-NOT: _ZN6GuardXIiED2Ev
+// CHECK: Running dtor

>From 9e8dd768a5256b4b54d54780328a3853762f1088 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= <stefan.graenitz at gmail.com>
Date: Wed, 24 Apr 2024 10:04:53 +0200
Subject: [PATCH 3/3] Fix: GuardX ctor invocation requires explicit template
 param

---
 clang/test/Interpreter/force-codegen-dtor.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Interpreter/force-codegen-dtor.cpp b/clang/test/Interpreter/force-codegen-dtor.cpp
index 07758bb3fa099..783a8b73426c7 100644
--- a/clang/test/Interpreter/force-codegen-dtor.cpp
+++ b/clang/test/Interpreter/force-codegen-dtor.cpp
@@ -11,7 +11,7 @@ extern "C" int printf(const char *, ...);
 template <class T> GuardX<T>::~GuardX() { delete x; printf("Running dtor\n"); }
 
 // Let's make sure that the RuntimeInterfaceBuilder requests it explicitly:
-(GuardX(x))
+(GuardX<int>(x))
 
 // CHECK-NOT: Symbols not found
 // CHECK: Running dtor



More information about the cfe-commits mailing list