Sometimes in unoptimized code, we have dangling unreachable basic blocks with no predecessors. Basic block sections should be emitted for those as well. Without this patch, the included test fails with a fatal error in AsmPrinter::emitBasicBlockEnd.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Time | Test | |
---|---|---|
490 ms | windows > lld.ELF/invalid::symtab-sh-info.s |
Event Timeline
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | ||
---|---|---|
3093–3097 | I think this would require a lot more comments. I see that you have flipped the if-else here, is there any reason you did that. Plus, there are a lot more checks than earlier. Could you add more comments that explain what is going on here? Thanks. | |
llvm/lib/CodeGen/MachineBasicBlock.cpp | ||
270 | Is this the same as getParent()->front() == this? |
- Add a private member function shouldEmitLabelForBasicBlock and call it to decide if basic blocks require symbols.
Thank you for your helpful comments @tmsriram and @snehasish
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | ||
---|---|---|
3093–3097 | I refactored this into a private member function. The reason is that isBlockOnlyReachableByFallthrough is a virtual member function. | |
llvm/lib/CodeGen/MachineBasicBlock.cpp | ||
270 | Yes, except with a &: | |
llvm/test/CodeGen/X86/basic-block-sections-unreachable.ll | ||
18 | I intentionally want to limit the test to checking labels and sections only. The reason is that the CFI directive of this block may be removed since it has no real instructions. However, I think that may be a later follow-up with a separate test. Please let me know if you have a good reason. |
Thanks again for the comments @tmsriram
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | ||
---|---|---|
3093–3097 | Thanks for the comment. I think initially the condition was reversed due to the simpler logic of the "false" direction. Since we now use a helper function to extract the condition, we can do it the natural way. I can change this to if (!shouldEmitLabelForBasicBlock(MBB)) and reverse the two directions, but don't see the value in that. | |
3145 | Removed the phrase. |
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | ||
---|---|---|
3142 | The coding standard does not replicate the function name for a comment. Some old code uses does not conform to the standard |
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | ||
---|---|---|
3142 | Removed the comment. |
This is the only place that EmitMBBlabel is checked. I don't see why you can't put that condition just directly after the if?