diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp --- a/llvm/lib/MC/MCStreamer.cpp +++ b/llvm/lib/MC/MCStreamer.cpp @@ -124,9 +124,12 @@ void MCStreamer::emitExplicitComments() {} void MCStreamer::generateCompactUnwindEncodings(MCAsmBackend *MAB) { - for (auto &FI : DwarfFrameInfos) + for (auto &FI : DwarfFrameInfos) { + if (!MAB || FI.Instructions.empty() && !FI.Personality && !FI.Lsda) + continue; FI.CompactUnwindEncoding = - (MAB ? MAB->generateCompactUnwindEncoding(FI.Instructions) : 0); + MAB->generateCompactUnwindEncoding(FI.Instructions); + } } /// EmitIntValue - Special case of EmitValue that avoids the client having to diff --git a/llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_compact_unwind.s b/llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_compact_unwind.s --- a/llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_compact_unwind.s +++ b/llvm/test/ExecutionEngine/JITLink/AArch64/MachO_arm64_compact_unwind.s @@ -13,6 +13,7 @@ .p2align 2 _main: .cfi_startproc + .cfi_def_cfa_offset 16 ret .cfi_endproc diff --git a/llvm/test/MC/AArch64/arm64-leaf-compact-unwind.s b/llvm/test/MC/AArch64/arm64-leaf-compact-unwind.s --- a/llvm/test/MC/AArch64/arm64-leaf-compact-unwind.s +++ b/llvm/test/MC/AArch64/arm64-leaf-compact-unwind.s @@ -6,18 +6,14 @@ # CHECK: Contents of __compact_unwind section: # CHECK-NEXT: Entry at offset 0x0: -# CHECK-NEXT: start: 0x0 ltmp0 -# CHECK-NEXT: length: 0x8 -# CHECK-NEXT: compact encoding: 0x02000000 -# CHECK-NEXT: Entry at offset 0x20: # CHECK-NEXT: start: 0x8 _foo2 # CHECK-NEXT: length: 0x40 # CHECK-NEXT: compact encoding: 0x02009000 -# CHECK-NEXT: Entry at offset 0x40: +# CHECK-NEXT: Entry at offset 0x20: # CHECK-NEXT: start: 0x48 _foo3 # CHECK-NEXT: length: 0xd4 # CHECK-NEXT: compact encoding: 0x0200400f -# CHECK-NEXT: Entry at offset 0x60: +# CHECK-NEXT: Entry at offset 0x40: # CHECK-NEXT: start: 0x11c _foo4 # CHECK-NEXT: length: 0x54 # CHECK-NEXT: compact encoding: 0x02021010 diff --git a/llvm/test/MC/AArch64/arm64_32-compact-unwind.s b/llvm/test/MC/AArch64/arm64_32-compact-unwind.s --- a/llvm/test/MC/AArch64/arm64_32-compact-unwind.s +++ b/llvm/test/MC/AArch64/arm64_32-compact-unwind.s @@ -5,11 +5,12 @@ ; references to addresses (function, personality, LSDA) are pointer-sized. ; CHECK: Contents of section __LD,__compact_unwind: -; CHECK-NEXT: 0004 00000000 04000000 00000002 00000000 +; CHECK-NEXT: 0004 00000000 04000000 00100002 00000000 ; CHECK-NEXT: 0014 00000000 .globl _test_compact_unwind .align 2 _test_compact_unwind: .cfi_startproc + .cfi_def_cfa_offset 16 ret .cfi_endproc