-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[RemoveDIs] Fix SIGSEGV caused by splitBasicBlock #90312
Conversation
@llvm/pr-subscribers-llvm-ir Author: Franklin Zhang (FLZ101) ChangesFull diff: https://github.com/llvm/llvm-project/pull/90312.diff 2 Files Affected:
diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp
index 6e62767c99e2a2..49d0e245c58676 100644
--- a/llvm/lib/IR/BasicBlock.cpp
+++ b/llvm/lib/IR/BasicBlock.cpp
@@ -1009,7 +1009,7 @@ void BasicBlock::spliceDebugInfoImpl(BasicBlock::iterator Dest, BasicBlock *Src,
// generate the iterator with begin() / getFirstInsertionPt(), it means
// any trailing debug-info at the end of the block would "normally" have
// been pushed in front of "First". Move it there now.
- DbgMarker *FirstMarker = getMarker(First);
+ DbgMarker *FirstMarker = createMarker(First);
DbgMarker *TrailingDbgRecords = getTrailingDbgRecords();
if (TrailingDbgRecords) {
FirstMarker->absorbDebugValues(*TrailingDbgRecords, true);
diff --git a/llvm/unittests/IR/BasicBlockDbgInfoTest.cpp b/llvm/unittests/IR/BasicBlockDbgInfoTest.cpp
index 905928819dda80..f873bbd4293af5 100644
--- a/llvm/unittests/IR/BasicBlockDbgInfoTest.cpp
+++ b/llvm/unittests/IR/BasicBlockDbgInfoTest.cpp
@@ -109,6 +109,62 @@ TEST(BasicBlockDbgInfoTest, InsertAfterSelf) {
UseNewDbgInfoFormat = false;
}
+TEST(BasicBlockDbgInfoTest, SplitBasicBlockBefore) {
+ LLVMContext C;
+ UseNewDbgInfoFormat = true;
+
+ std::unique_ptr<Module> M = parseIR(C, R"---(
+ define dso_local void @func() #0 !dbg !10 {
+ %1 = alloca i32, align 4
+ tail call void @llvm.dbg.declare(metadata ptr %1, metadata !14, metadata !DIExpression()), !dbg !16
+ store i32 2, ptr %1, align 4, !dbg !16
+ ret void, !dbg !17
+ }
+
+ declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
+
+ attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
+
+ !llvm.dbg.cu = !{!0}
+ !llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8}
+ !llvm.ident = !{!9}
+
+ !0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "dummy", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+ !1 = !DIFile(filename: "dummy", directory: "dummy")
+ !2 = !{i32 7, !"Dwarf Version", i32 5}
+ !3 = !{i32 2, !"Debug Info Version", i32 3}
+ !4 = !{i32 1, !"wchar_size", i32 4}
+ !5 = !{i32 8, !"PIC Level", i32 2}
+ !6 = !{i32 7, !"PIE Level", i32 2}
+ !7 = !{i32 7, !"uwtable", i32 2}
+ !8 = !{i32 7, !"frame-pointer", i32 2}
+ !9 = !{!"dummy"}
+ !10 = distinct !DISubprogram(name: "func", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !13)
+ !11 = !DISubroutineType(types: !12)
+ !12 = !{null}
+ !13 = !{}
+ !14 = !DILocalVariable(name: "a", scope: !10, file: !1, line: 2, type: !15)
+ !15 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+ !16 = !DILocation(line: 2, column: 6, scope: !10)
+ !17 = !DILocation(line: 3, column: 2, scope: !10)
+ )---");
+ ASSERT_TRUE(M);
+
+ M->convertToNewDbgValues();
+
+ Function *F = M->getFunction("func");
+
+ BasicBlock &BB = F->getEntryBlock();
+ auto I = std::prev(BB.end(), 2);
+ BB.splitBasicBlockBefore(I, "before");
+
+ BasicBlock &BBBefore = F->getEntryBlock();
+ auto I2 = std::prev(BBBefore.end(), 2);
+ ASSERT_TRUE(I2->hasDbgRecords());
+
+ UseNewDbgInfoFormat = false;
+}
+
TEST(BasicBlockDbgInfoTest, MarkerOperations) {
LLVMContext C;
UseNewDbgInfoFormat = true;
|
ad846a4
to
656482d
Compare
Looks correct at a surface level; I'm out-of-office for a while though, Stephen/Orlando should be able to confirm this is a good fix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to ask if the unittest could be changed to use the new textual format, but this (intrinsics) matches the other tests so that's ok for now, that can be updated with the others when we get to that.
Code change makes sense. LGTM once the inline comment is addressed. Thank you!
llvm/lib/IR/BasicBlock.cpp
Outdated
@@ -1009,7 +1009,7 @@ void BasicBlock::spliceDebugInfoImpl(BasicBlock::iterator Dest, BasicBlock *Src, | |||
// generate the iterator with begin() / getFirstInsertionPt(), it means | |||
// any trailing debug-info at the end of the block would "normally" have | |||
// been pushed in front of "First". Move it there now. | |||
DbgMarker *FirstMarker = getMarker(First); | |||
DbgMarker *FirstMarker = createMarker(First); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you drop this into the if (TrailingDbgRecords)
body? We don't want to create a marker if we're not going to use it when TrailingDbgRecords
is false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
656482d
to
93c83c1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Still LGTM, thanks)
See
llvm/unittests/IR/BasicBlockDbgInfoTest.cpp
for a test case.The SIGSEGV is like below: