ychen created this revision. ychen added reviewers: aaron.ballman, rnk, rsmith. Herald added a project: All. ychen requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
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". Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D132592 Files: clang/include/clang/Basic/Attr.td clang/include/clang/Basic/AttrDocs.td clang/lib/CodeGen/CodeGenModule.cpp clang/test/CodeGen/attr-nouwtable.c Index: clang/test/CodeGen/attr-nouwtable.c =================================================================== --- /dev/null +++ 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: } Index: clang/lib/CodeGen/CodeGenModule.cpp =================================================================== --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -1942,7 +1942,7 @@ 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) Index: clang/include/clang/Basic/AttrDocs.td =================================================================== --- clang/include/clang/Basic/AttrDocs.td +++ clang/include/clang/Basic/AttrDocs.td @@ -4537,6 +4537,16 @@ }]; } +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 = [{ Index: clang/include/clang/Basic/Attr.td =================================================================== --- clang/include/clang/Basic/Attr.td +++ clang/include/clang/Basic/Attr.td @@ -2086,6 +2086,13 @@ 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 [[]]
Index: clang/test/CodeGen/attr-nouwtable.c =================================================================== --- /dev/null +++ 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: } Index: clang/lib/CodeGen/CodeGenModule.cpp =================================================================== --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -1942,7 +1942,7 @@ 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) Index: clang/include/clang/Basic/AttrDocs.td =================================================================== --- clang/include/clang/Basic/AttrDocs.td +++ clang/include/clang/Basic/AttrDocs.td @@ -4537,6 +4537,16 @@ }]; } +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 = [{ Index: clang/include/clang/Basic/Attr.td =================================================================== --- clang/include/clang/Basic/Attr.td +++ clang/include/clang/Basic/Attr.td @@ -2086,6 +2086,13 @@ 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 [[]]
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits