Author: Sanne Wouda Date: 2020-01-17T18:09:42Z New Revision: ecfd6d3e84185127fb836d6fe62564456be3a9cd
URL: https://github.com/llvm/llvm-project/commit/ecfd6d3e84185127fb836d6fe62564456be3a9cd DIFF: https://github.com/llvm/llvm-project/commit/ecfd6d3e84185127fb836d6fe62564456be3a9cd.diff LOG: [clang] Set function attributes on SEH filter functions correctly. Summary: When compiling with -munwind-tables, the SEH filter funclet needs the uwtable function attribute, which gets automatically added if we use SetInternalFunctionAttributes. The filter funclet is internal so this seems appropriate. Reviewers: rnk Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D72786 Added: clang/test/CodeGenCXX/exceptions-seh-filter-uwtable.cpp Modified: clang/lib/CodeGen/CGException.cpp clang/test/CodeGen/exceptions-seh-finally.c Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp index 53fafab3e0e6..fffd9897270e 100644 --- a/clang/lib/CodeGen/CGException.cpp +++ b/clang/lib/CodeGen/CGException.cpp @@ -1885,7 +1885,7 @@ void CodeGenFunction::startOutlinedSEHHelper(CodeGenFunction &ParentCGF, OutlinedStmt->getBeginLoc(), OutlinedStmt->getBeginLoc()); CurSEHParent = ParentCGF.CurSEHParent; - CGM.SetLLVMFunctionAttributes(GlobalDecl(), FnInfo, CurFn); + CGM.SetInternalFunctionAttributes(GlobalDecl(), CurFn, FnInfo); EmitCapturedLocals(ParentCGF, OutlinedStmt, IsFilter); } diff --git a/clang/test/CodeGen/exceptions-seh-finally.c b/clang/test/CodeGen/exceptions-seh-finally.c index 3e10d15debcc..8aafeb23090d 100644 --- a/clang/test/CodeGen/exceptions-seh-finally.c +++ b/clang/test/CodeGen/exceptions-seh-finally.c @@ -1,6 +1,7 @@ -// RUN: %clang_cc1 %s -triple x86_64-pc-win32 -fms-extensions -emit-llvm -o - | FileCheck %s -// RUN: %clang_cc1 %s -triple i686-pc-win32 -fms-extensions -emit-llvm -o - | FileCheck %s -// RUN: %clang_cc1 %s -triple aarch64-windows -fms-extensions -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 %s -triple x86_64-pc-win32 -fms-extensions -emit-llvm -O1 -disable-llvm-passes -o - | FileCheck %s +// RUN: %clang_cc1 %s -triple i686-pc-win32 -fms-extensions -emit-llvm -O1 -disable-llvm-passes -o - | FileCheck %s +// RUN: %clang_cc1 %s -triple aarch64-windows -fms-extensions -emit-llvm -O1 -disable-llvm-passes -o - | FileCheck %s +// NOTE: we're passing "-O1 -disable-llvm-passes" to avoid adding optnone and noinline everywhere. void abort(void) __attribute__((noreturn)); void might_crash(void); @@ -281,7 +282,6 @@ void finally_with_func() { // CHECK-LABEL: define internal void @"?fin$0@0@finally_with_func@@"({{[^)]*}}) // CHECK: call void @cleanup_with_func(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @"??_C@_0BC@COAGBPGM@finally_with_func?$AA@", i{{32|64}} 0, i{{32|64}} 0)) -// Look for the absence of noinline. Enum attributes come first, so check that -// a string attribute is the first to verify that no enum attributes are -// present. -// CHECK: attributes [[finally_attrs]] = { "{{.*}}" } +// Look for the absence of noinline. nounwind is expected; any further +// attributes should be string attributes. +// CHECK: attributes [[finally_attrs]] = { nounwind "{{.*}}" } diff --git a/clang/test/CodeGenCXX/exceptions-seh-filter-uwtable.cpp b/clang/test/CodeGenCXX/exceptions-seh-filter-uwtable.cpp new file mode 100644 index 000000000000..f09c6a39c7f5 --- /dev/null +++ b/clang/test/CodeGenCXX/exceptions-seh-filter-uwtable.cpp @@ -0,0 +1,48 @@ +// RUN: %clang_cc1 "-triple" "arm64-windows" "-munwind-tables" "-fms-compatibility" -emit-llvm -O1 -disable-llvm-passes %s -o - | FileCheck %s +// NOTE: we're passing "-O1 -disable-llvm-passes" to avoid adding optnone and noinline everywhere. + +# 0 "" 3 +#define a(b, c) d() & b +#define f(c) a(e(0, 0, #c).b(), ) + +struct e { + e(int, int, char *); + int b(); +}; + +struct d { + void operator&(int); +}; + +struct h; + +struct i { + h *operator->(); + h &operator*() { f(); } +}; + +typedef int g; + +struct h { + void ad(); +}; + +g aq(h j, g k, int, int) { + if (k) + return; + j.ad(); +} + +// Check for the uwtable attribute on the filter funclet. +// CHECK: define internal i32 @"?filt$0@0@at@@"(i8* %exception_pointers, i8* %frame_pointer) #[[MD:[0-9]+]] +// CHECK: attributes #[[MD]] = { nounwind uwtable + +void at() { + i ar; + + __try { + ar->ad(); + } __except (aq(*ar, _exception_code(), 0, 0)) { + } + +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits