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 | |
---|---|---|
410 ms | linux > HWAddressSanitizer-x86_64.TestCases::sizes.cpp |
Event Timeline
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | ||
---|---|---|
3129–3133 | 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 | ||
---|---|---|
3129–3133 | 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 | ||
---|---|---|
3129–3133 | 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. | |
3181 | Removed the phrase. |
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | ||
---|---|---|
3178 | 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 | ||
---|---|---|
3178 | 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?