OSDN Git Service

Merging r340641:
authorHans Wennborg <hans@hanshq.net>
Mon, 27 Aug 2018 10:05:36 +0000 (10:05 +0000)
committerHans Wennborg <hans@hanshq.net>
Mon, 27 Aug 2018 10:05:36 +0000 (10:05 +0000)
------------------------------------------------------------------------
r340641 | stefanp | 2018-08-24 21:38:29 +0200 (Fri, 24 Aug 2018) | 9 lines

[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/branches/release_70@340731 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/Function.h
test/CodeGen/PowerPC/uwtables.ll [new file with mode: 0644]
test/CodeGen/X86/uwtables.ll [new file with mode: 0644]
test/CodeGen/X86/x86-shrink-wrap-unwind.ll

index c8d6b07..02e3ecc 100644 (file)
@@ -557,7 +557,7 @@ public:
 
   /// True if this function needs an unwind table.
   bool needsUnwindTableEntry() const {
-    return hasUWTable() || !doesNotThrow();
+    return hasUWTable() || !doesNotThrow() || hasPersonalityFn();
   }
 
   /// Determine if the function returns a structure through first
diff --git a/test/CodeGen/PowerPC/uwtables.ll b/test/CodeGen/PowerPC/uwtables.ll
new file mode 100644 (file)
index 0000000..1968b71
--- /dev/null
@@ -0,0 +1,51 @@
+; RUN: llc -mcpu=pwr9 -mtriple=powerpc64le-unknown-unknown \
+; RUN:   -verify-machineinstrs -ppc-asm-full-reg-names \
+; RUN:   -ppc-vsr-nums-as-vr < %s | FileCheck %s
+; RUN: llc -mcpu=pwr8 -mtriple=powerpc64le-unknown-unknown \
+; RUN:   -verify-machineinstrs -ppc-asm-full-reg-names \
+; RUN:   -ppc-vsr-nums-as-vr < %s | FileCheck %s
+; RUN: llc -mtriple=powerpc64-unknown-unknown \
+; RUN:   -verify-machineinstrs -ppc-asm-full-reg-names \
+; RUN:   -ppc-vsr-nums-as-vr < %s | FileCheck %s
+
+
+@_ZTIi = external constant i8*
+
+; Function is marked as nounwind but it still throws with __cxa_throw and
+; calls __cxa_call_unexpected.
+; Need to make sure that we do not only have a debug frame.
+; Function Attrs: noreturn nounwind
+define void @_Z4funcv() local_unnamed_addr #0 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
+entry:
+  %exception = tail call i8* @__cxa_allocate_exception(i64 4)
+  %0 = bitcast i8* %exception to i32*
+  store i32 100, i32* %0, align 16
+  invoke void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null)
+          to label %unreachable unwind label %lpad
+
+lpad:                                             ; preds = %entry
+  %1 = landingpad { i8*, i32 }
+          filter [0 x i8*] zeroinitializer
+  %2 = extractvalue { i8*, i32 } %1, 0
+  tail call void @__cxa_call_unexpected(i8* %2)
+  unreachable
+
+unreachable:                                      ; preds = %entry
+  unreachable
+; CHECK-LABEL: _Z4funcv
+; CHECK-NOT: .debug_frame
+; CHECK: .cfi_personality
+; CHECK: .cfi_endproc
+}
+
+declare i8* @__cxa_allocate_exception(i64) local_unnamed_addr
+
+declare void @__cxa_throw(i8*, i8*, i8*) local_unnamed_addr
+
+declare i32 @__gxx_personality_v0(...)
+
+declare void @__cxa_call_unexpected(i8*) local_unnamed_addr
+
+
+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" }
+
diff --git a/test/CodeGen/X86/uwtables.ll b/test/CodeGen/X86/uwtables.ll
new file mode 100644 (file)
index 0000000..d25492d
--- /dev/null
@@ -0,0 +1,43 @@
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
+
+
+@_ZTIi = external constant i8*
+
+; Function is marked as nounwind but it still throws with __cxa_throw and
+; calls __cxa_call_unexpected.
+; Need to make sure that we do not only have a debug frame.
+; Function Attrs: noreturn nounwind
+define void @_Z4funcv() local_unnamed_addr #0 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
+entry:
+  %exception = tail call i8* @__cxa_allocate_exception(i64 4)
+  %0 = bitcast i8* %exception to i32*
+  store i32 100, i32* %0, align 16
+  invoke void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null)
+          to label %unreachable unwind label %lpad
+
+lpad:                                             ; preds = %entry
+  %1 = landingpad { i8*, i32 }
+          filter [0 x i8*] zeroinitializer
+  %2 = extractvalue { i8*, i32 } %1, 0
+  tail call void @__cxa_call_unexpected(i8* %2)
+  unreachable
+
+unreachable:                                      ; preds = %entry
+  unreachable
+; CHECK-LABEL: _Z4funcv
+; CHECK-NOT: .debug_frame
+; CHECK: .cfi_personality
+; CHECK: .cfi_endproc
+}
+
+declare i8* @__cxa_allocate_exception(i64) local_unnamed_addr
+
+declare void @__cxa_throw(i8*, i8*, i8*) local_unnamed_addr
+
+declare i32 @__gxx_personality_v0(...)
+
+declare void @__cxa_call_unexpected(i8*) local_unnamed_addr
+
+
+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" }
+
index bac8393..f1f81da 100644 (file)
@@ -237,6 +237,7 @@ attributes #5 = { nounwind readonly ssp uwtable "split-stack" }
 ; CHECK: push
 ;
 ; Jump to throw_exception:
+; CHECK-NEXT: .cfi_def_cfa_offset
 ; CHECK-NEXT: testb $1, %dil
 ; CHECK-NEXT: jne [[THROW_LABEL:LBB[0-9_]+]]
 ; Else return exit