[llvm] Add unit test for CloneModule and #dbg_label (PR #91463)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 8 05:08:27 PDT 2024
https://github.com/PietroGhg created https://github.com/llvm/llvm-project/pull/91463
This PR adds a unit test for `llvm::CloneModule`, to make sure that `#dbg_label` and relative metadata nodes are cloned correctly.
>From 09040f8e598ebee9dcab9ba4bc3234aa9c46e7ec Mon Sep 17 00:00:00 2001
From: PietroGhg <pietro.ghiglio at codeplay.com>
Date: Wed, 8 May 2024 11:37:02 +0100
Subject: [PATCH] Add unittest for CloneModule and #dbg_label
---
.../Transforms/Utils/CloningTest.cpp | 38 +++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/llvm/unittests/Transforms/Utils/CloningTest.cpp b/llvm/unittests/Transforms/Utils/CloningTest.cpp
index 6f4e860d60468..ded1841ef7d21 100644
--- a/llvm/unittests/Transforms/Utils/CloningTest.cpp
+++ b/llvm/unittests/Transforms/Utils/CloningTest.cpp
@@ -1122,4 +1122,42 @@ TEST_F(CloneModule, IFunc) {
EXPECT_EQ("resolver", Resolver->getName());
EXPECT_EQ(GlobalValue::PrivateLinkage, Resolver->getLinkage());
}
+
+TEST_F(CloneModule, CloneDbgLabel) {
+ LLVMContext Context;
+
+ std::unique_ptr<Module> M = parseIR(
+ Context,
+ R"M(
+define void @noop(ptr nocapture noundef writeonly align 4 %dst) local_unnamed_addr !dbg !3 {
+entry:
+ %call = tail call spir_func i64 @foo(i32 noundef 0)
+ #dbg_label(!11, !12)
+ store i64 %call, ptr %dst, align 4
+ ret void
+}
+
+declare i64 @foo(i32 noundef) local_unnamed_addr
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 19.0.0git", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
+!1 = !DIFile(filename: "<stdin>", directory: "foo")
+!2 = !{i32 2, !"Debug Info Version", i32 3}
+!3 = distinct !DISubprogram(name: "noop", scope: !4, file: !4, line: 17, type: !5, scopeLine: 17, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !9)
+!4 = !DIFile(filename: "file", directory: "foo")
+!5 = !DISubroutineType(types: !6)
+!6 = !{null, !7}
+!7 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)
+!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!9 = !{}
+!11 = !DILabel(scope: !3, name: "foo", file: !4, line: 23)
+!12 = !DILocation(line: 23, scope: !3)
+)M");
+
+ ASSERT_FALSE(verifyModule(*M, &errs()));
+ auto NewM = llvm::CloneModule(*M);
+ EXPECT_FALSE(verifyModule(*NewM, &errs()));
+}
}
More information about the llvm-commits
mailing list