Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit ca333d7

Browse files
[Exception Handling] Unwind tables are required for all functions that have an EH personality.
This patch is for defect: https://bugs.llvm.org/show_bug.cgi?id=32611 Functions may require unwind tables even if they are marked with the attribute nounwind. Any function with an EH personality may require an unwind table. Differential Revision: https://reviews.llvm.org/D50987 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@340614 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d73e0d8 commit ca333d7

File tree

4 files changed

+96
-1
lines changed

4 files changed

+96
-1
lines changed

include/llvm/IR/Function.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ class Function : public GlobalObject, public ilist_node<Function> {
571571

572572
/// True if this function needs an unwind table.
573573
bool needsUnwindTableEntry() const {
574-
return hasUWTable() || !doesNotThrow();
574+
return hasUWTable() || !doesNotThrow() || hasPersonalityFn();
575575
}
576576

577577
/// Determine if the function returns a structure through first

test/CodeGen/PowerPC/uwtables.ll

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
; RUN: llc -mcpu=pwr9 -mtriple=powerpc64le-unknown-unknown \
2+
; RUN: -verify-machineinstrs -ppc-asm-full-reg-names \
3+
; RUN: -ppc-vsr-nums-as-vr < %s | FileCheck %s
4+
; RUN: llc -mcpu=pwr8 -mtriple=powerpc64le-unknown-unknown \
5+
; RUN: -verify-machineinstrs -ppc-asm-full-reg-names \
6+
; RUN: -ppc-vsr-nums-as-vr < %s | FileCheck %s
7+
; RUN: llc -mtriple=powerpc64-unknown-unknown \
8+
; RUN: -verify-machineinstrs -ppc-asm-full-reg-names \
9+
; RUN: -ppc-vsr-nums-as-vr < %s | FileCheck %s
10+
11+
12+
@_ZTIi = external constant i8*
13+
14+
; Function is marked as nounwind but it still throws with __cxa_throw and
15+
; calls __cxa_call_unexpected.
16+
; Need to make sure that we do not only have a debug frame.
17+
; Function Attrs: noreturn nounwind
18+
define void @_Z4funcv() local_unnamed_addr #0 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
19+
entry:
20+
%exception = tail call i8* @__cxa_allocate_exception(i64 4)
21+
%0 = bitcast i8* %exception to i32*
22+
store i32 100, i32* %0, align 16
23+
invoke void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null)
24+
to label %unreachable unwind label %lpad
25+
26+
lpad: ; preds = %entry
27+
%1 = landingpad { i8*, i32 }
28+
filter [0 x i8*] zeroinitializer
29+
%2 = extractvalue { i8*, i32 } %1, 0
30+
tail call void @__cxa_call_unexpected(i8* %2)
31+
unreachable
32+
33+
unreachable: ; preds = %entry
34+
unreachable
35+
; CHECK-LABEL: _Z4funcv
36+
; CHECK-NOT: .debug_frame
37+
; CHECK: .cfi_personality
38+
; CHECK: .cfi_endproc
39+
}
40+
41+
declare i8* @__cxa_allocate_exception(i64) local_unnamed_addr
42+
43+
declare void @__cxa_throw(i8*, i8*, i8*) local_unnamed_addr
44+
45+
declare i32 @__gxx_personality_v0(...)
46+
47+
declare void @__cxa_call_unexpected(i8*) local_unnamed_addr
48+
49+
50+
attributes #0 = { noreturn nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="ppc64le" "target-features"="+altivec,+bpermd,+crypto,+direct-move,+extdiv,+htm,+power8-vector,+vsx,-power9-vector,-qpx" "unsafe-fp-math"="false" "use-soft-float"="false" }
51+

test/CodeGen/X86/uwtables.ll

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
; RUN: llc -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
2+
3+
4+
@_ZTIi = external constant i8*
5+
6+
; Function is marked as nounwind but it still throws with __cxa_throw and
7+
; calls __cxa_call_unexpected.
8+
; Need to make sure that we do not only have a debug frame.
9+
; Function Attrs: noreturn nounwind
10+
define void @_Z4funcv() local_unnamed_addr #0 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
11+
entry:
12+
%exception = tail call i8* @__cxa_allocate_exception(i64 4)
13+
%0 = bitcast i8* %exception to i32*
14+
store i32 100, i32* %0, align 16
15+
invoke void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null)
16+
to label %unreachable unwind label %lpad
17+
18+
lpad: ; preds = %entry
19+
%1 = landingpad { i8*, i32 }
20+
filter [0 x i8*] zeroinitializer
21+
%2 = extractvalue { i8*, i32 } %1, 0
22+
tail call void @__cxa_call_unexpected(i8* %2)
23+
unreachable
24+
25+
unreachable: ; preds = %entry
26+
unreachable
27+
; CHECK-LABEL: _Z4funcv
28+
; CHECK-NOT: .debug_frame
29+
; CHECK: .cfi_personality
30+
; CHECK: .cfi_endproc
31+
}
32+
33+
declare i8* @__cxa_allocate_exception(i64) local_unnamed_addr
34+
35+
declare void @__cxa_throw(i8*, i8*, i8*) local_unnamed_addr
36+
37+
declare i32 @__gxx_personality_v0(...)
38+
39+
declare void @__cxa_call_unexpected(i8*) local_unnamed_addr
40+
41+
42+
attributes #0 = { noreturn nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="ppc64le" "target-features"="+altivec,+bpermd,+crypto,+direct-move,+extdiv,+htm,+power8-vector,+vsx,-power9-vector,-qpx" "unsafe-fp-math"="false" "use-soft-float"="false" }
43+

test/CodeGen/X86/x86-shrink-wrap-unwind.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ attributes #5 = { nounwind readonly ssp uwtable "split-stack" }
237237
; CHECK: push
238238
;
239239
; Jump to throw_exception:
240+
; CHECK-NEXT: .cfi_def_cfa_offset
240241
; CHECK-NEXT: testb $1, %dil
241242
; CHECK-NEXT: jne [[THROW_LABEL:LBB[0-9_]+]]
242243
; Else return exit

0 commit comments

Comments
 (0)