diff options
author | Quentin Colombet <qcolombet@apple.com> | 2012-10-29 17:56:23 +0000 |
---|---|---|
committer | Quentin Colombet <qcolombet@apple.com> | 2012-10-29 17:56:23 +0000 |
commit | ba927d9b26ead2ad535c7761b8862d8e82c41b13 (patch) | |
tree | e947f1b128568fe31775441d4eba9519071916e5 | |
parent | c0e44454bd78b8b4f3d70f08cf1edd5466b0c798 (diff) |
Make forcesizeopt attribute available to the end user
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166946 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/Attr.td | 5 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 3 | ||||
-rw-r--r-- | lib/Sema/SemaDeclAttr.cpp | 17 | ||||
-rw-r--r-- | test/CodeGen/attr-forcesizeopt.c | 5 |
4 files changed, 30 insertions, 0 deletions
diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td index 738b460b5a..4a5f1e727f 100644 --- a/include/clang/Basic/Attr.td +++ b/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/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 9617de8eb7..523e2d2624 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -583,6 +583,9 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, if (D->hasAttr<ColdAttr>()) F->addFnAttr(llvm::Attributes::OptimizeForSize); + if (D->hasAttr<ForceSizeOptAttr>()) + F->addFnAttr(llvm::Attributes::ForceSizeOpt); + if (isa<CXXConstructorDecl>(D) || isa<CXXDestructorDecl>(D)) F->setUnnamedAddr(true); diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index df4757e4d2..992cafce74 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/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<FunctionDecl>(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/test/CodeGen/attr-forcesizeopt.c b/test/CodeGen/attr-forcesizeopt.c index c4e6c4ad81..693e7ccbad 100644 --- a/test/CodeGen/attr-forcesizeopt.c +++ b/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 +} |