Skip to content

Commit 5f87237

Browse files
nikicllvmbot
authored andcommitted
[DwarfEhPrepare] Assign dummy debug location for inserted _Unwind_Resume calls (PR57469)
DwarfEhPrepare inserts calls to _Unwind_Resume into landing pads. If _Unwind_Resume happens to be defined in the same module and debug info is used, then this leads to a verifier error: inlinable function call in a function with debug info must have a !dbg location call void @_Unwind_Resume(ptr %exn.obj) #0 Fix this by assigning a dummy location to the call. (As this happens in the backend, inlining is not actually relevant here.) Fixes llvm/llvm-project#57469. Differential Revision: https://reviews.llvm.org/D133095 (cherry picked from commit 5134bd4)
1 parent 80b4a25 commit 5f87237

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

llvm/lib/CodeGen/DwarfEHPrepare.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/CodeGen/TargetSubtargetInfo.h"
2626
#include "llvm/IR/BasicBlock.h"
2727
#include "llvm/IR/Constants.h"
28+
#include "llvm/IR/DebugInfoMetadata.h"
2829
#include "llvm/IR/DerivedTypes.h"
2930
#include "llvm/IR/Dominators.h"
3031
#include "llvm/IR/Function.h"
@@ -247,6 +248,13 @@ bool DwarfEHPrepare::InsertUnwindResumeCalls() {
247248
// Call the rewind function.
248249
CallInst *CI =
249250
CallInst::Create(RewindFunction, RewindFunctionArgs, "", UnwindBB);
251+
// The verifier requires that all calls of debug-info-bearing functions
252+
// from debug-info-bearing functions have a debug location (for inlining
253+
// purposes). Assign a dummy location to satisfy the constraint.
254+
Function *RewindFn = dyn_cast<Function>(RewindFunction.getCallee());
255+
if (RewindFn && RewindFn->getSubprogram())
256+
if (DISubprogram *SP = F.getSubprogram())
257+
CI->setDebugLoc(DILocation::get(SP->getContext(), 0, 0, SP));
250258
CI->setCallingConv(RewindFunctionCallingConv);
251259

252260
// We never expect _Unwind_Resume to return.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -S -mtriple=x86_64-linux-gnu -dwarfehprepare < %s | FileCheck %s
3+
4+
; PR57469: If _Unwind_Resume is defined in the same module and we have debug
5+
; info, then the inserted _Unwind_Resume calls also need to have a dummy debug
6+
; location to satisfy inlining requirements.
7+
8+
define void @_Unwind_Resume(ptr %ptr) !dbg !4 {
9+
; CHECK-LABEL: @_Unwind_Resume(
10+
; CHECK-NEXT: ret void, !dbg [[DBG11:![0-9]+]]
11+
;
12+
ret void, !dbg !11
13+
}
14+
15+
declare i32 @__gxx_personality_v0(...)
16+
declare void @might_throw()
17+
18+
define void @simple_cleanup_catch() personality ptr @__gxx_personality_v0 !dbg !12 {
19+
; CHECK-LABEL: @simple_cleanup_catch(
20+
; CHECK-NEXT: invoke void @might_throw()
21+
; CHECK-NEXT: to label [[EXIT:%.*]] unwind label [[LANDINGPAD:%.*]], !dbg [[DBG15:![0-9]+]]
22+
; CHECK: exit:
23+
; CHECK-NEXT: ret void
24+
; CHECK: landingpad:
25+
; CHECK-NEXT: [[EX:%.*]] = landingpad { ptr, i32 }
26+
; CHECK-NEXT: cleanup
27+
; CHECK-NEXT: [[EXN_OBJ:%.*]] = extractvalue { ptr, i32 } [[EX]], 0
28+
; CHECK-NEXT: call void @_Unwind_Resume(ptr [[EXN_OBJ]]) #[[ATTR0:[0-9]+]], !dbg [[DBG16:![0-9]+]]
29+
; CHECK-NEXT: unreachable
30+
;
31+
invoke void @might_throw()
32+
to label %exit unwind label %landingpad, !dbg !15
33+
34+
exit:
35+
ret void
36+
37+
landingpad:
38+
%ex = landingpad { ptr, i32 }
39+
cleanup
40+
resume { ptr, i32 } %ex
41+
}
42+
43+
!llvm.dbg.cu = !{!0}
44+
!llvm.module.flags = !{!2, !3}
45+
46+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 16.0.0 (https://github.com/llvm/llvm-project.git a4c8fb9d1f46f30c66a9ca0dd07c7933f338bb34)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
47+
!1 = !DIFile(filename: "/app/example.c", directory: "/app")
48+
!2 = !{i32 7, !"Dwarf Version", i32 4}
49+
!3 = !{i32 2, !"Debug Info Version", i32 3}
50+
!4 = distinct !DISubprogram(name: "_Unwind_Resume", scope: !5, file: !5, line: 1, type: !6, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !9)
51+
!5 = !DIFile(filename: "example.c", directory: "/app")
52+
!6 = !DISubroutineType(types: !7)
53+
!7 = !{null, !8}
54+
!8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
55+
!9 = !{!10}
56+
!10 = !DILocalVariable(name: "exception", arg: 1, scope: !4, file: !5, line: 1, type: !8)
57+
!11 = !DILocation(line: 2, column: 1, scope: !4)
58+
!12 = distinct !DISubprogram(name: "test", scope: !5, file: !5, line: 4, type: !13, scopeLine: 4, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
59+
!13 = !DISubroutineType(types: !14)
60+
!14 = !{null}
61+
!15 = !DILocation(line: 6, column: 1, scope: !12)
62+
63+
; CHECK: [[DBG_SCOPE:![0-9]+]] = distinct !DISubprogram(name: "test"
64+
; CHECK: [[DBG16]] = !DILocation(line: 0, scope: [[DBG_SCOPE]])

0 commit comments

Comments
 (0)