From: Quentin Colombet Date: Mon, 29 Oct 2012 17:56:23 +0000 (+0000) Subject: Make forcesizeopt attribute available to the end user X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0d6b5e5fdedb097aa0446ce42694f21278b8ec1d;p=platform%2Fupstream%2Fllvm.git Make forcesizeopt attribute available to the end user llvm-svn: 166946 --- diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 738b460..4a5f1e72 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -341,6 +341,11 @@ def Final : InheritableAttr { let SemaHandler = 0; } +def ForceSizeOpt : InheritableAttr { + let Spellings = [GNU<"forcesizeopt">]; + let Subjects = [Function]; +} + def Format : InheritableAttr { let Spellings = [GNU<"format">]; let Args = [StringArgument<"Type">, IntArgument<"FormatIdx">, diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 9617de8..523e2d2 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -583,6 +583,9 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, if (D->hasAttr()) F->addFnAttr(llvm::Attributes::OptimizeForSize); + if (D->hasAttr()) + F->addFnAttr(llvm::Attributes::ForceSizeOpt); + if (isa(D) || isa(D)) F->setUnnamedAddr(true); diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index df4757e..992cafc 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -1523,6 +1523,20 @@ static void handleAliasAttr(Sema &S, Decl *D, const AttributeList &Attr) { Str->getString())); } +static void handleForceSizeOptAttr(Sema &S, Decl *D, const AttributeList &Attr) { + // Check the attribute arguments. + if (!checkAttributeNumArgs(S, Attr, 0)) + return; + + if (!isa(D)) { + S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type) + << Attr.getName() << ExpectedFunction; + return; + } + + D->addAttr(::new (S.Context) ForceSizeOptAttr(Attr.getRange(), S.Context)); +} + static void handleColdAttr(Sema &S, Decl *D, const AttributeList &Attr) { // Check the attribute arguments. if (!checkAttributeNumArgs(S, Attr, 0)) @@ -4285,6 +4299,9 @@ static void ProcessInheritableDeclAttr(Sema &S, Scope *scope, Decl *D, case AttributeList::AT_ExtVectorType: handleExtVectorTypeAttr(S, scope, D, Attr); break; + case AttributeList::AT_ForceSizeOpt: + handleForceSizeOptAttr(S, D, Attr); + break; case AttributeList::AT_Format: handleFormatAttr (S, D, Attr); break; case AttributeList::AT_FormatArg: handleFormatArgAttr (S, D, Attr); break; case AttributeList::AT_CUDAGlobal: handleGlobalAttr (S, D, Attr); break; diff --git a/clang/test/CodeGen/attr-forcesizeopt.c b/clang/test/CodeGen/attr-forcesizeopt.c index c4e6c4a..693e7cc 100644 --- a/clang/test/CodeGen/attr-forcesizeopt.c +++ b/clang/test/CodeGen/attr-forcesizeopt.c @@ -24,3 +24,8 @@ int test2() { // OTHER-NOT: forcesizeopt // OTHER: ret } + +int test3() __attribute__((forcesizeopt)) { +// Oz: @test3{{.*}}forcesizeopt +// OTHER: @test3{{.*}}forcesizeopt +}