[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
This commit is contained in:
Yuanfang Chen 2022-08-24 12:24:54 -07:00
parent ce6989fd8a
commit 70248bfdea
6 changed files with 31 additions and 1 deletions

View File

@ -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
---------------

View File

@ -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 [[]]

View File

@ -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 = [{

View File

@ -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)

View File

@ -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: }

View File

@ -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)