[clang] 70248bf - [Clang] Implement function attribute nouwtable
Yuanfang Chen via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 29 12:13:08 PDT 2022
Author: Yuanfang Chen
Date: 2022-08-29T12:12:19-07:00
New Revision: 70248bfdea6c70008ca42bf03bb28ebdee252744
URL: https://github.com/llvm/llvm-project/commit/70248bfdea6c70008ca42bf03bb28ebdee252744
DIFF: https://github.com/llvm/llvm-project/commit/70248bfdea6c70008ca42bf03bb28ebdee252744.diff
LOG: [Clang] Implement function attribute nouwtable
To have finer control of IR uwtable attribute generation. For target code generation,
IR nounwind and uwtable may have some interaction. However, for frontend, there are
no semantic interactions so the this new `nouwtable` is marked "SimpleHandler = 1".
Differential Revision: https://reviews.llvm.org/D132592
Added:
clang/test/CodeGen/attr-nouwtable.c
Modified:
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/Misc/pragma-attribute-supported-attributes-list.test
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ef3950501f963..92b52b8998b4f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -149,6 +149,9 @@ Attribute Changes in Clang
using the MinGW environment. This attribute is only available for Windows
targets.
+- Introduced a new function attribute ``__attribute__((nouwtable))`` to suppress
+ LLVM IR ``uwtable`` function attribute.
+
Windows Support
---------------
diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index 3b0e3e2971803..0ad59b2c153ae 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2092,6 +2092,13 @@ def NoThrow : InheritableAttr {
let Documentation = [NoThrowDocs];
}
+def NoUwtable : InheritableAttr {
+ let Spellings = [Clang<"nouwtable">];
+ let Subjects = SubjectList<[FunctionLike]>;
+ let Documentation = [NoUwtableDocs];
+ let SimpleHandler = 1;
+}
+
def NvWeak : IgnoredAttr {
// No Declspec spelling of this attribute; the CUDA headers use
// __attribute__((nv_weak)) unconditionally. Does not receive an [[]]
diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td
index 32084bf512bc1..68f1268ed7da9 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4537,6 +4537,16 @@ guaranteed to not throw an exception.
}];
}
+def NoUwtableDocs : Documentation {
+ let Category = DocCatFunction;
+ let Content = [{
+Clang supports the ``nouwtable`` attribute which skips emitting
+the unwind table entry for the specified function. This attribute is useful for
+selectively emitting the unwind table entry on some functions when building with
+``-funwind-tables`` compiler option.
+ }];
+}
+
def InternalLinkageDocs : Documentation {
let Category = DocCatFunction;
let Content = [{
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 6294fe9e87d32..62e906a87af48 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1963,7 +1963,7 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
llvm::Function *F) {
llvm::AttrBuilder B(F->getContext());
- if (CodeGenOpts.UnwindTables)
+ if ((!D || !D->hasAttr<NoUwtableAttr>()) && CodeGenOpts.UnwindTables)
B.addUWTableAttr(llvm::UWTableKind(CodeGenOpts.UnwindTables));
if (CodeGenOpts.StackClashProtector)
diff --git a/clang/test/CodeGen/attr-nouwtable.c b/clang/test/CodeGen/attr-nouwtable.c
new file mode 100644
index 0000000000000..a0c6d9232ef30
--- /dev/null
+++ b/clang/test/CodeGen/attr-nouwtable.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -funwind-tables=2 -S -emit-llvm %s -o - | FileCheck %s
+
+__attribute__((nouwtable))
+int test1(void) { return 0; }
+
+// CHECK: @test1{{.*}}[[ATTR1:#[0-9]+]]
+// CHECK: attributes [[ATTR1]] = {
+// CHECK-NOT: uwtable
+// CHECK: }
diff --git a/clang/test/Misc/pragma-attribute-supported-attributes-list.test b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
index bde9505009934..b6a52832dadde 100644
--- a/clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -115,6 +115,7 @@
// CHECK-NEXT: NoStackProtector (SubjectMatchRule_function)
// CHECK-NEXT: NoThreadSafetyAnalysis (SubjectMatchRule_function)
// CHECK-NEXT: NoThrow (SubjectMatchRule_hasType_functionType)
+// CHECK-NEXT: NoUwtable (SubjectMatchRule_hasType_functionType)
// CHECK-NEXT: NotTailCalled (SubjectMatchRule_function)
// CHECK-NEXT: OSConsumed (SubjectMatchRule_variable_is_parameter)
// CHECK-NEXT: OSReturnsNotRetained (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_objc_property, SubjectMatchRule_variable_is_parameter)
More information about the cfe-commits
mailing list