[PATCH] D72786: [clang] Set function attributes on SEH filter functions correctly.

Sanne Wouda via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 15 10:03:15 PST 2020


sanwou01 created this revision.
sanwou01 added a reviewer: rnk.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72786

Files:
  clang/lib/CodeGen/CGException.cpp
  clang/test/CodeGen/exceptions-seh-finally.c
  clang/test/CodeGenCXX/exceptions-seh-filter-uwtable.cpp


Index: clang/test/CodeGenCXX/exceptions-seh-filter-uwtable.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeGenCXX/exceptions-seh-filter-uwtable.cpp
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 "-triple" "arm64-windowsj" "-munwind-tables" "-fms-compatibility" -emit-llvm %s -o - | FileCheck %s
+
+# 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: define internal i32 @"?filt$0 at 0@at@@"(i8* %exception_pointers, i8* %frame_pointer) #[[MD:[0-9]+]]
+// CHECK: attributes #[[MD]] = { noinline nounwind uwtable 
+
+void at() {
+  i ar;
+
+  __try {
+    ar->ad();
+  } __except (aq(*ar, _exception_code(), 0, 0)) {
+  }
+
+}
Index: clang/test/CodeGen/exceptions-seh-finally.c
===================================================================
--- clang/test/CodeGen/exceptions-seh-finally.c
+++ clang/test/CodeGen/exceptions-seh-finally.c
@@ -281,7 +281,5 @@
 // CHECK-LABEL: define internal void @"?fin$0 at 0@finally_with_func@@"({{[^)]*}})
 // CHECK: call void @cleanup_with_func(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @"??_C at _0BC@COAGBPGM at 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]] = { "{{.*}}" }
+// noinline and nounwind are now added anyway
+// CHECK: attributes [[finally_attrs]] = { noinline nounwind "{{.*}}" }
Index: clang/lib/CodeGen/CGException.cpp
===================================================================
--- clang/lib/CodeGen/CGException.cpp
+++ clang/lib/CodeGen/CGException.cpp
@@ -1885,7 +1885,7 @@
                 OutlinedStmt->getBeginLoc(), OutlinedStmt->getBeginLoc());
   CurSEHParent = ParentCGF.CurSEHParent;
 
-  CGM.SetLLVMFunctionAttributes(GlobalDecl(), FnInfo, CurFn);
+  CGM.SetInternalFunctionAttributes(GlobalDecl(), CurFn, FnInfo);
   EmitCapturedLocals(ParentCGF, OutlinedStmt, IsFilter);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72786.238306.patch
Type: text/x-patch
Size: 2335 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200115/24420ccd/attachment.bin>


More information about the cfe-commits mailing list