Skip to content

Commit df2213f

Browse files
committed
[EHStreamer] Omit @lpstart when function has no landing pads
When no landing pads exist for a function, `@LPStart` is undefined and must be omitted. EH table is generally not emitted for functions without landing pads, except when the personality function is uknown (`!isNoOpWithoutInvoke(classifyEHPersonality(Per))`). In that case, we must omit `@LPStart` even when machine function splitting is enabled. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D131626
1 parent 65c022a commit df2213f

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,9 +663,10 @@ MCSymbol *EHStreamer::emitExceptionTable() {
663663
Asm->OutStreamer->emitLabel(CSRange.ExceptionLabel);
664664

665665
// Emit the LSDA header.
666-
// If only one call-site range exists, LPStart is omitted as it is the
667-
// same as the function entry.
668-
if (CallSiteRanges.size() == 1) {
666+
// LPStart is omitted if either we have a single call-site range (in which
667+
// case the function entry is treated as @LPStart) or if this function has
668+
// no landing pads (in which case @LPStart is undefined).
669+
if (CallSiteRanges.size() == 1 || LandingPadRange == nullptr) {
669670
Asm->emitEncodingByte(dwarf::DW_EH_PE_omit, "@LPStart");
670671
} else if (!Asm->isPositionIndependent()) {
671672
// For more than one call-site ranges, LPStart must be explicitly
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
;; Verify that @LPStart is omitted when there are no landing pads. This test
2+
;; uses an unkown personality to force emitting the exception table.
3+
4+
; RUN: llc -basic-block-sections=all -mtriple=x86_64 < %s | FileCheck %s
5+
6+
declare void @throwit()
7+
declare i32 @__unknown_ehpersonality(...)
8+
9+
define void @foo(i1 %cond) uwtable personality ptr @__unknown_ehpersonality {
10+
entry:
11+
br i1 %cond, label %cond.true, label %cond.false
12+
13+
cond.true: ; preds = %entry
14+
call void @throwit()
15+
unreachable
16+
17+
cond.false: ; preds = %entry
18+
ret void
19+
}
20+
21+
; CHECK: GCC_except_table0:
22+
; CHECK-NEXT: .Lexception0:
23+
; CHECK-NEXT: .byte 255 # @LPStart Encoding = omit
24+
; CHECK-NEXT: .byte 255 # @TType Encoding = omit
25+
; CHECK-NEXT: .byte 1 # Call site Encoding = uleb128
26+
; CHECK-NEXT: .uleb128 .Laction_table_base0-.Lcst_begin0
27+
; CHECK-NEXT: .Lcst_begin0:
28+
; CHECK-NEXT: .Lexception1:
29+
; CHECK-NEXT: .byte 255 # @LPStart Encoding = omit
30+
; CHECK-NEXT: .byte 255 # @TType Encoding = omit
31+
; CHECK-NEXT: .byte 1 # Call site Encoding = uleb128
32+
; CHECK-NEXT: .uleb128 .Laction_table_base0-.Lcst_begin1
33+
; CHECK-NEXT: .Lcst_begin1:
34+
; CHECK-NEXT: .Lexception2:
35+
; CHECK-NEXT: .byte 255 # @LPStart Encoding = omit
36+
; CHECK-NEXT: .byte 255 # @TType Encoding = omit
37+
; CHECK-NEXT: .byte 1 # Call site Encoding = uleb128
38+
; CHECK-NEXT: .uleb128 .Laction_table_base0-.Lcst_begin2
39+
; CHECK-NEXT: .Lcst_begin2:
40+
; CHECK-NEXT: .uleb128 foo.__part.2-foo.__part.2 # >> Call Site 1 <<
41+
; CHECK-NEXT: .uleb128 .LBB_END0_2-foo.__part.2 # Call between foo.__part.2 and .LBB_END0_2
42+
; CHECK-NEXT: .byte 0 # has no landing pad
43+
; CHECK-NEXT: .byte 0 # On action: cleanup
44+
; CHECK-NEXT: .Laction_table_base0:

0 commit comments

Comments
 (0)