gulfem updated this revision to Diff 302369. gulfem added a comment. Update the attribute documentation
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D90275/new/ https://reviews.llvm.org/D90275 Files: clang/include/clang/Basic/Attr.td clang/include/clang/Basic/AttrDocs.td clang/lib/CodeGen/CGCall.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/test/CodeGen/attr-leaf.c clang/test/Misc/pragma-attribute-supported-attributes-list.test clang/test/Sema/attr-leaf.c llvm/include/llvm/Bitcode/LLVMBitCodes.h llvm/include/llvm/IR/Attributes.td llvm/lib/AsmParser/LLLexer.cpp llvm/lib/AsmParser/LLParser.cpp llvm/lib/AsmParser/LLToken.h llvm/lib/Bitcode/Reader/BitcodeReader.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp llvm/lib/IR/Attributes.cpp llvm/lib/IR/Verifier.cpp llvm/lib/Transforms/Utils/CodeExtractor.cpp llvm/test/Bitcode/attributes.ll
Index: llvm/test/Bitcode/attributes.ll =================================================================== --- llvm/test/Bitcode/attributes.ll +++ llvm/test/Bitcode/attributes.ll @@ -410,6 +410,12 @@ ret void } +; CHECK; define void @f70() #43 +define void @f70() nocallback +{ + ret void +} + ; CHECK: attributes #0 = { noreturn } ; CHECK: attributes #1 = { nounwind } ; CHECK: attributes #2 = { readnone } @@ -453,4 +459,5 @@ ; CHECK: attributes #40 = { null_pointer_is_valid } ; CHECK: attributes #41 = { mustprogress } ; CHECK: attributes #42 = { nossp } +; CHECK: attributes #43 = { nocallback } ; CHECK: attributes #[[NOBUILTIN]] = { nobuiltin } Index: llvm/lib/Transforms/Utils/CodeExtractor.cpp =================================================================== --- llvm/lib/Transforms/Utils/CodeExtractor.cpp +++ llvm/lib/Transforms/Utils/CodeExtractor.cpp @@ -906,6 +906,7 @@ case Attribute::NoRecurse: case Attribute::InlineHint: case Attribute::MinSize: + case Attribute::NoCallback: case Attribute::NoDuplicate: case Attribute::NoFree: case Attribute::NoImplicitFloat: Index: llvm/lib/IR/Verifier.cpp =================================================================== --- llvm/lib/IR/Verifier.cpp +++ llvm/lib/IR/Verifier.cpp @@ -1572,6 +1572,7 @@ case Attribute::NoReturn: case Attribute::NoSync: case Attribute::WillReturn: + case Attribute::NoCallback: case Attribute::NoCfCheck: case Attribute::NoUnwind: case Attribute::NoInline: Index: llvm/lib/IR/Attributes.cpp =================================================================== --- llvm/lib/IR/Attributes.cpp +++ llvm/lib/IR/Attributes.cpp @@ -371,6 +371,8 @@ return "noalias"; if (hasAttribute(Attribute::NoBuiltin)) return "nobuiltin"; + if (hasAttribute(Attribute::NoCallback)) + return "nocallback"; if (hasAttribute(Attribute::NoCapture)) return "nocapture"; if (hasAttribute(Attribute::NoDuplicate)) Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp =================================================================== --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -643,6 +643,8 @@ return bitc::ATTR_KIND_NO_ALIAS; case Attribute::NoBuiltin: return bitc::ATTR_KIND_NO_BUILTIN; + case Attribute::NoCallback: + return bitc::ATTR_KIND_NO_CALLBACK; case Attribute::NoCapture: return bitc::ATTR_KIND_NO_CAPTURE; case Attribute::NoDuplicate: Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp =================================================================== --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -1433,6 +1433,8 @@ return Attribute::NoAlias; case bitc::ATTR_KIND_NO_BUILTIN: return Attribute::NoBuiltin; + case bitc::ATTR_KIND_NO_CALLBACK: + return Attribute::NoCallback; case bitc::ATTR_KIND_NO_CAPTURE: return Attribute::NoCapture; case bitc::ATTR_KIND_NO_DUPLICATE: Index: llvm/lib/AsmParser/LLToken.h =================================================================== --- llvm/lib/AsmParser/LLToken.h +++ llvm/lib/AsmParser/LLToken.h @@ -198,6 +198,7 @@ kw_noalias, kw_noundef, kw_nobuiltin, + kw_nocallback, kw_nocapture, kw_noduplicate, kw_nofree, Index: llvm/lib/AsmParser/LLParser.cpp =================================================================== --- llvm/lib/AsmParser/LLParser.cpp +++ llvm/lib/AsmParser/LLParser.cpp @@ -1314,6 +1314,9 @@ break; case lltok::kw_naked: B.addAttribute(Attribute::Naked); break; case lltok::kw_nobuiltin: B.addAttribute(Attribute::NoBuiltin); break; + case lltok::kw_nocallback: + B.addAttribute(Attribute::NoCallback); + break; case lltok::kw_noduplicate: B.addAttribute(Attribute::NoDuplicate); break; case lltok::kw_nofree: B.addAttribute(Attribute::NoFree); break; case lltok::kw_noimplicitfloat: Index: llvm/lib/AsmParser/LLLexer.cpp =================================================================== --- llvm/lib/AsmParser/LLLexer.cpp +++ llvm/lib/AsmParser/LLLexer.cpp @@ -651,6 +651,7 @@ KEYWORD(nest); KEYWORD(noalias); KEYWORD(nobuiltin); + KEYWORD(nocallback); KEYWORD(nocapture); KEYWORD(noduplicate); KEYWORD(nofree); Index: llvm/include/llvm/IR/Attributes.td =================================================================== --- llvm/include/llvm/IR/Attributes.td +++ llvm/include/llvm/IR/Attributes.td @@ -91,6 +91,9 @@ /// Callee isn't recognized as a builtin. def NoBuiltin : EnumAttr<"nobuiltin">; +/// Function cannot enter into caller's translation unit. +def NoCallback : EnumAttr<"nocallback">; + /// Function creates no aliases of pointer. def NoCapture : EnumAttr<"nocapture">; Index: llvm/include/llvm/Bitcode/LLVMBitCodes.h =================================================================== --- llvm/include/llvm/Bitcode/LLVMBitCodes.h +++ llvm/include/llvm/Bitcode/LLVMBitCodes.h @@ -652,6 +652,7 @@ ATTR_KIND_BYREF = 69, ATTR_KIND_MUSTPROGRESS = 70, ATTR_KIND_NO_STACK_PROTECT = 71, + ATTR_KIND_NO_CALLBACK = 72, }; enum ComdatSelectionKindCodes { Index: clang/test/Sema/attr-leaf.c =================================================================== --- /dev/null +++ clang/test/Sema/attr-leaf.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -verify -fsyntax-only %s +// expected-no-diagnostics + +void f(void) __attribute__((leaf)); Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test =================================================================== --- clang/test/Misc/pragma-attribute-supported-attributes-list.test +++ clang/test/Misc/pragma-attribute-supported-attributes-list.test @@ -68,6 +68,7 @@ // CHECK-NEXT: InitPriority (SubjectMatchRule_variable) // CHECK-NEXT: InternalLinkage (SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_record) // CHECK-NEXT: LTOVisibilityPublic (SubjectMatchRule_record) +// CHECK-NEXT: Leaf (SubjectMatchRule_function) // CHECK-NEXT: LoaderUninitialized (SubjectMatchRule_variable_is_global) // CHECK-NEXT: Lockable (SubjectMatchRule_record) // CHECK-NEXT: MIGServerRoutine (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_block) Index: clang/test/CodeGen/attr-leaf.c =================================================================== --- /dev/null +++ clang/test/CodeGen/attr-leaf.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -emit-llvm -Oz -o - %s | FileCheck %s + +// CHECK: define void @f() local_unnamed_addr [[ATTRS:#[0-9]+]] { +void f() __attribute__((leaf)); + +void f() +{ +} + +// CHECK: attributes [[ATTRS]] = { {{.*}}nocallback{{.*}} } Index: clang/lib/Sema/SemaDeclAttr.cpp =================================================================== --- clang/lib/Sema/SemaDeclAttr.cpp +++ clang/lib/Sema/SemaDeclAttr.cpp @@ -7590,6 +7590,9 @@ case ParsedAttr::AT_AnyX86NoCfCheck: handleNoCfCheckAttr(S, D, AL); break; + case ParsedAttr::AT_Leaf: + handleSimpleAttribute<LeafAttr>(S, D, AL); + break; case ParsedAttr::AT_NoThrow: if (!AL.isUsedAsTypeAttr()) handleSimpleAttribute<NoThrowAttr>(S, D, AL); Index: clang/lib/CodeGen/CGCall.cpp =================================================================== --- clang/lib/CodeGen/CGCall.cpp +++ clang/lib/CodeGen/CGCall.cpp @@ -1988,6 +1988,8 @@ FuncAttrs.addAttribute("no_caller_saved_registers"); if (TargetDecl->hasAttr<AnyX86NoCfCheckAttr>()) FuncAttrs.addAttribute(llvm::Attribute::NoCfCheck); + if (TargetDecl->hasAttr<LeafAttr>()) + FuncAttrs.addAttribute(llvm::Attribute::NoCallback); HasOptnone = TargetDecl->hasAttr<OptimizeNoneAttr>(); if (auto *AllocSize = TargetDecl->getAttr<AllocSizeAttr>()) { Index: clang/include/clang/Basic/AttrDocs.td =================================================================== --- clang/include/clang/Basic/AttrDocs.td +++ clang/include/clang/Basic/AttrDocs.td @@ -3901,6 +3901,22 @@ }]; } +def LeafDocs : Documentation { + let Category = DocCatVariable; + let Content = [{ + +The ``leaf`` attribute is used as a compiler hint to improve dataflow analysis +in library functions. Functions marked with the ``leaf`` attribute are not allowed +to jump back into the caller's translation unit, whether through invoking a +callback function, a direct external function call, use of ``longjmp``, or other means. +Therefore, they cannot use or modify any data that does not escape the caller function's +compilation unit. + +For more information see +`gcc documentation <https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html>` +}]; +} + def NoStackProtectorDocs : 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 @@ -1430,6 +1430,13 @@ let Documentation = [LayoutVersionDocs]; } +def Leaf : InheritableAttr { + let Spellings = [GCC<"leaf">]; + let Subjects = SubjectList<[Function]>; + let Documentation = [LeafDocs]; + let SimpleHandler = 1; +} + def LifetimeBound : DeclOrTypeAttr { let Spellings = [Clang<"lifetimebound", 0>]; let Subjects = SubjectList<[ParmVar, ImplicitObjectParameter], ErrorDiag>;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits