Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

weliveindetail
Copy link
Contributor

This patch adds test coverage for an edge case that is supported already.

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Apr 23, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 23, 2024

@llvm/pr-subscribers-clang

Author: Stefan Gränitz (weliveindetail)

Changes

This patch adds test coverage for an edge case that is supported already.


Full diff: https://github.com/llvm/llvm-project/pull/89734.diff

1 Files Affected:

  • (added) clang/test/Interpreter/force-codegen-dtor.cpp (+13)
diff --git a/clang/test/Interpreter/force-codegen-dtor.cpp b/clang/test/Interpreter/force-codegen-dtor.cpp
new file mode 100644
index 00000000000000..a299ea46d5eac0
--- /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

(GuardX(x))

// CHECK-NOT: Symbols not found
// CHECK-NOT: _ZN6GuardXIiED2Ev
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer a check like below that is more explicit, but we recognize expressions for value printing (the thing we parse as "semi-missing") only in trailing statements. If we added the code below, then (GuardX(x)) is not considered trailing anymore, because we pipe he whole file into clang-repl.

#include <cstdint>
auto x_addr = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(x));

extern "C" int printf(const char *, ...);
printf("0x%016" PRIx64 "\n", x_addr);

// CHECK: 0x00000000000000000

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a printf in the dtor?

Copy link
Contributor

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@weliveindetail weliveindetail force-pushed the clang-repl-test-coverage-force-codegen-dtor branch from 3ae15ad to 9e8dd76 Compare May 30, 2024 12:38
@weliveindetail
Copy link
Contributor Author

Oh interesting, the Windows test actually fails at this assertion:

DC->getLexicalParent() == CurContext && "The next DeclContext should be lexically contained in the current one.", file C:\ws\src\clang\lib\Sema\SemaDecl.cpp, line 1332

@vgvassilev Any ideas?

@vgvassilev
Copy link
Contributor

We generally have to put a switch for the late parsed templates. We have it in some other tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants