@@ -149,6 +149,75 @@ TEST(BasicBlockDbgInfoTest, SplitBasicBlockBefore) {
149
149
ASSERT_TRUE (I2->hasDbgRecords ());
150
150
}
151
151
152
+ TEST (BasicBlockDbgInfoTest, DropSourceAtomOnSplit) {
153
+ LLVMContext C;
154
+ std::unique_ptr<Module> M = parseIR (C, R"---(
155
+ define dso_local void @func() !dbg !10 {
156
+ %1 = alloca i32, align 4
157
+ ret void, !dbg !DILocation(line: 3, column: 2, scope: !10, atomGroup: 1, atomRank: 1)
158
+ }
159
+
160
+ !llvm.dbg.cu = !{!0}
161
+ !llvm.module.flags = !{!2, !3}
162
+
163
+ !0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "dummy", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
164
+ !1 = !DIFile(filename: "dummy", directory: "dummy")
165
+ !2 = !{i32 7, !"Dwarf Version", i32 5}
166
+ !3 = !{i32 2, !"Debug Info Version", i32 3}
167
+ !10 = distinct !DISubprogram(name: "func", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !13)
168
+ !11 = !DISubroutineType(types: !12)
169
+ !12 = !{null}
170
+ !13 = !{}
171
+ !14 = !DILocalVariable(name: "a", scope: !10, file: !1, line: 2, type: !15)
172
+ !15 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
173
+ )---" );
174
+ ASSERT_TRUE (M);
175
+
176
+ Function *F = M->getFunction (" func" );
177
+
178
+ // Test splitBasicBlockBefore.
179
+ {
180
+ BasicBlock &BB = F->back ();
181
+ // Split at `ret void`.
182
+ BasicBlock *Before =
183
+ BB.splitBasicBlockBefore (std::prev (BB.end (), 1 ), " before" );
184
+ const DebugLoc &BrToAfterDL = Before->getTerminator ()->getDebugLoc ();
185
+ ASSERT_TRUE (BrToAfterDL);
186
+ EXPECT_EQ (BrToAfterDL->getAtomGroup (), 0u );
187
+
188
+ BasicBlock *After = Before->getSingleSuccessor ();
189
+ ASSERT_TRUE (After);
190
+ const DebugLoc &OrigTerminatorDL = After->getTerminator ()->getDebugLoc ();
191
+ ASSERT_TRUE (OrigTerminatorDL);
192
+ #ifdef EXPERIMENTAL_KEY_INSTRUCTIONS
193
+ EXPECT_EQ (OrigTerminatorDL->getAtomGroup (), 1u );
194
+ #else
195
+ EXPECT_EQ (OrigTerminatorDL->getAtomGroup (), 0u );
196
+ #endif
197
+ }
198
+
199
+ // Test splitBasicBlock.
200
+ {
201
+ BasicBlock &BB = F->back ();
202
+ // Split at `ret void`.
203
+ BasicBlock *After = BB.splitBasicBlock (std::prev (BB.end (), 1 ), " before" );
204
+
205
+ const DebugLoc &OrigTerminatorDL = After->getTerminator ()->getDebugLoc ();
206
+ ASSERT_TRUE (OrigTerminatorDL);
207
+ #ifdef EXPERIMENTAL_KEY_INSTRUCTIONS
208
+ EXPECT_EQ (OrigTerminatorDL->getAtomGroup (), 1u );
209
+ #else
210
+ EXPECT_EQ (OrigTerminatorDL->getAtomGroup (), 0u );
211
+ #endif
212
+
213
+ BasicBlock *Before = After->getSinglePredecessor ();
214
+ ASSERT_TRUE (Before);
215
+ const DebugLoc &BrToAfterDL = Before->getTerminator ()->getDebugLoc ();
216
+ ASSERT_TRUE (BrToAfterDL);
217
+ EXPECT_EQ (BrToAfterDL->getAtomGroup (), 0u );
218
+ }
219
+ }
220
+
152
221
TEST (BasicBlockDbgInfoTest, MarkerOperations) {
153
222
LLVMContext C;
154
223
std::unique_ptr<Module> M = parseIR (C, R"(
0 commit comments