steplong created this revision. Herald added a reviewer: aaron.ballman. Herald added a project: All. steplong requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Add the ability to put __attribute__((frame_pointer(arg))) on functions. arg is only allowed to be none, non_leaf, or all. Depends on D125719 <https://reviews.llvm.org/D125719>. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D125720 Files: clang/include/clang/Basic/Attr.td clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/CodeGen/CodeGenModule.cpp clang/lib/Sema/SemaDeclAttr.cpp
Index: clang/lib/Sema/SemaDeclAttr.cpp =================================================================== --- clang/lib/Sema/SemaDeclAttr.cpp +++ clang/lib/Sema/SemaDeclAttr.cpp @@ -6763,6 +6763,24 @@ checkSwiftAsyncErrorBlock(S, D, ErrorAttr, AsyncAttr); } +static void handleFramePointer(Sema &S, Decl *D, const ParsedAttr &AL) { + if (!AL.isArgIdent(0)) { + S.Diag(AL.getLoc(), diag::err_attribute_argument_n_type) + << AL << 1 << AANT_ArgumentIdentifier; + return; + } + + FramePointerAttr::Kind Kind; + IdentifierInfo *II = AL.getArgAsIdent(0)->Ident; + if (!FramePointerAttr::ConvertStrToKind(II->getName(), Kind)) { + S.Diag(AL.getLoc(), diag::warn_frame_pointer_type_not_supported) << AL + << II; + return; + } + + D->addAttr(::new (S.Context) FramePointerAttr(S.Context, AL, Kind)); +} + //===----------------------------------------------------------------------===// // Microsoft specific attribute handlers. //===----------------------------------------------------------------------===// @@ -9031,6 +9049,10 @@ case ParsedAttr::AT_UsingIfExists: handleSimpleAttribute<UsingIfExistsAttr>(S, D, AL); break; + + case ParsedAttr::AT_FramePointer: + handleFramePointer(S, D, AL); + break; } } Index: clang/lib/CodeGen/CodeGenModule.cpp =================================================================== --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -1650,6 +1650,24 @@ /*AttrOnCallSite=*/false, IsThunk); F->setAttributes(PAL); F->setCallingConv(static_cast<llvm::CallingConv::ID>(CallingConv)); + if (!GD.getDecl()) + return; + + if (GD.getDecl()->hasAttr<FramePointerAttr>()) { + F->removeFnAttr("frame-pointer"); + FramePointerAttr *Attr = GD.getDecl()->getAttr<FramePointerAttr>(); + switch (Attr->getKind()) { + case FramePointerAttr::None: + F->addFnAttr("frame-pointer", "none"); + break; + case FramePointerAttr::NonLeaf: + F->addFnAttr("frame-pointer", "non-leaf"); + break; + case FramePointerAttr::All: + F->addFnAttr("frame-pointer", "all"); + break; + } + } } static void removeImageAccessQualifier(std::string& TyName) { Index: clang/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticSemaKinds.td +++ clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -11633,4 +11633,8 @@ "a randomized struct can only be initialized with a designated initializer">; def err_cast_from_randomized_struct : Error< "casting from randomized structure pointer type %0 to %1">; + +def warn_frame_pointer_type_not_supported : Warning< + "%0 frame_pointer argument not supported: %1">, + InGroup<IgnoredAttributes>; } // end of sema component. Index: clang/include/clang/Basic/Attr.td =================================================================== --- clang/include/clang/Basic/Attr.td +++ clang/include/clang/Basic/Attr.td @@ -1441,6 +1441,16 @@ let Documentation = [Undocumented]; } +def FramePointer : InheritableAttr { + // This attribute has no spellings as it is only ever created implicitly. + let Spellings = []; + let Subjects = SubjectList<[Function]>; + let Args = [EnumArgument<"Kind", "Kind", + ["none", "non_leaf", "all"], + ["None", "NonLeaf", "All"]>]; + let Documentation = [Undocumented]; +} + def FlagEnum : InheritableAttr { let Spellings = [Clang<"flag_enum">]; let Subjects = SubjectList<[Enum]>;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits