Iterate only through reachable blocks. This finetunes r330706 and
resolves build issue reported by Craig Topper.
Details
- Reviewers
craig.topper thegameg violetav
Diff Detail
- Repository
- rL LLVM
Event Timeline
This fix fixes the original case, but its easy to break it again
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
; Function Attrs: noinline nounwind optnone uwtable
define hidden void @foo() #0 {
bb:
br label %bb1
bb1: ; preds = %bb3, %bb
%tmp = icmp ne i32 0, 0
br i1 %tmp, label %bb2, label %bb3
bb2: ; preds = %bb1
br label %bb4
bb4: ; preds = %bb2
br label %bb3
bb3: ; preds = %bb4, %bb1
br label %bb1
}
attributes #0 = { noinline nounwind optnone uwtable "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" }Does this example come from a real test case? The issue here is that bb2 will not have predecessors after X86 DAG->DAG Instruction Selection, and this way we reach bb3 from either:
bb0->bb1->bb3 or
bb2->bb4->bb3.
What should be a correct offset for bb3 in this case?
It's not real. But bb4 is only reachable from bb2. I just wedged an empty block in the path from bb2 to bb3 in my previous case. So neither bb2 or bb4 are actually reachable from the start of the function.
I made a typo (bb3 vs bb4). I wanted to say:
and this way we reach bb3 from either:
bb0->bb1->bb3 or
bb2->bb4->bb3.
What should be a correct offset for bb3 in this case?
Here is a C program rather than hacked IR that still crashes with this patch. I don't know anything about CFI so I don't know what the right answer is.
int __attribute((__always_inline__)) bar() {
return 0;
}
void foo() {
if (bar() != 0) {
if (bar() != 0) {
}
}
}Thanks Craig for the test example. The issues were related to unreachable blocks that exist with -O0, this patch now skips all of them and hopefully it will resolve issues you are seeing.
| lib/CodeGen/CFIInstrInserter.cpp | ||
|---|---|---|
| 298 | How about range for on depth_first(&MF)? | |
| lib/CodeGen/CFIInstrInserter.cpp | ||
|---|---|---|
| 297 | Do you need an external set? You aren't accessing it are you? | |
Update the patch per comments.
| lib/CodeGen/CFIInstrInserter.cpp | ||
|---|---|---|
| 297 | No, in this version of the patch I do not need it. I had some asserts in local copy. | |
pred_empty()?