[clang] d093401 - [NFC] Remove string parameter of annotation attribute from AST childs.
via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 9 07:40:30 PST 2020
Author: Tyker
Date: 2020-11-09T16:39:59+01:00
New Revision: d093401a2617d3c46aaed9eeaecf877e3ae1a9f1
URL: https://github.com/llvm/llvm-project/commit/d093401a2617d3c46aaed9eeaecf877e3ae1a9f1
DIFF: https://github.com/llvm/llvm-project/commit/d093401a2617d3c46aaed9eeaecf877e3ae1a9f1.diff
LOG: [NFC] Remove string parameter of annotation attribute from AST childs.
this simplifies using annotation attributes when using clang as library
Added:
Modified:
clang/include/clang/Basic/Attr.td
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/AST/ast-dump-attr.cpp
clang/test/Misc/pragma-attribute-cxx.cpp
clang/test/Misc/pragma-attribute-objc.m
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index 687c03f55841..7ae5803f1c30 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -740,6 +740,16 @@ def Annotate : InheritableParamAttr {
let Args = [StringArgument<"Annotation">, VariadicExprArgument<"Args">];
// Ensure that the annotate attribute can be used with
// '#pragma clang attribute' even though it has no subject list.
+ let AdditionalMembers = [{
+ static AnnotateAttr *Create(ASTContext &Ctx, llvm::StringRef Annotation, \
+ const AttributeCommonInfo &CommonInfo = {SourceRange{}}) {
+ return AnnotateAttr::Create(Ctx, Annotation, nullptr, 0, CommonInfo);
+ }
+ static AnnotateAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Annotation, \
+ const AttributeCommonInfo &CommonInfo = {SourceRange{}}) {
+ return AnnotateAttr::CreateImplicit(Ctx, Annotation, nullptr, 0, CommonInfo);
+ }
+ }];
let PragmaAttributeSupport = 1;
let Documentation = [Undocumented];
}
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index d8b819cf5bee..92b2b5c0dc43 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2391,7 +2391,6 @@ llvm::Constant *CodeGenModule::EmitAnnotationLineNo(SourceLocation L) {
llvm::Constant *CodeGenModule::EmitAnnotationArgs(const AnnotateAttr *Attr) {
ArrayRef<Expr *> Exprs = {Attr->args_begin(), Attr->args_size()};
- Exprs = Exprs.drop_front();
if (Exprs.empty())
return llvm::ConstantPointerNull::get(Int8PtrTy);
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 71fccc4c68e7..ec3ea9ebd85e 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -3686,7 +3686,7 @@ void Sema::AddAnnotationAttr(Decl *D, const AttributeCommonInfo &CI,
StringRef Str, MutableArrayRef<Expr *> Args) {
auto *Attr = AnnotateAttr::Create(Context, Str, Args.data(), Args.size(), CI);
llvm::SmallVector<PartialDiagnosticAt, 8> Notes;
- for (unsigned Idx = 1; Idx < Attr->args_size(); Idx++) {
+ for (unsigned Idx = 0; Idx < Attr->args_size(); Idx++) {
Expr *&E = Attr->args_begin()[Idx];
assert(E && "error are handled before");
if (E->isValueDependent() || E->isTypeDependent())
@@ -3718,7 +3718,7 @@ void Sema::AddAnnotationAttr(Decl *D, const AttributeCommonInfo &CI,
/// current language mode.
if (!Result || !Notes.empty()) {
Diag(E->getBeginLoc(), diag::err_attribute_argument_n_type)
- << CI << Idx << AANT_ArgumentConstantExpr;
+ << CI << (Idx + 1) << AANT_ArgumentConstantExpr;
for (auto &Note : Notes)
Diag(Note.first, Note.second);
return;
@@ -3737,8 +3737,8 @@ static void handleAnnotateAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
return;
llvm::SmallVector<Expr *, 4> Args;
- Args.reserve(AL.getNumArgs());
- for (unsigned Idx = 0; Idx < AL.getNumArgs(); Idx++) {
+ Args.reserve(AL.getNumArgs() - 1);
+ for (unsigned Idx = 1; Idx < AL.getNumArgs(); Idx++) {
assert(!AL.isArgIdent(Idx));
Args.push_back(AL.getArgAsExpr(Idx));
}
diff --git a/clang/test/AST/ast-dump-attr.cpp b/clang/test/AST/ast-dump-attr.cpp
index 3207f692fc23..c2bd768dc2ad 100644
--- a/clang/test/AST/ast-dump-attr.cpp
+++ b/clang/test/AST/ast-dump-attr.cpp
@@ -252,12 +252,10 @@ int mergeAttrTest() __attribute__((unused,no_thread_safety_analysis));
// CHECK-NEXT: DeprecatedAttr{{.*}} Inherited
// CHECK-NEXT: WarnUnusedResultAttr{{.*}} Inherited
// CHECK-NEXT: AnnotateAttr{{.*}}
-// CHECK-NEXT: StringLiteral
// CHECK: FunctionDecl{{.*}} mergeAttrTest
// CHECK-NEXT: DeprecatedAttr{{.*}} Inherited
// CHECK-NEXT: WarnUnusedResultAttr{{.*}} Inherited
// CHECK-NEXT: AnnotateAttr{{.*}} Inherited
-// CHECK-NEXT: StringLiteral
// CHECK-NEXT: UnusedAttr
// CHECK-NEXT: NoThreadSafetyAnalysisAttr
diff --git a/clang/test/Misc/pragma-attribute-cxx.cpp b/clang/test/Misc/pragma-attribute-cxx.cpp
index fc80127dfbec..38b025e47691 100644
--- a/clang/test/Misc/pragma-attribute-cxx.cpp
+++ b/clang/test/Misc/pragma-attribute-cxx.cpp
@@ -21,15 +21,11 @@ class testClass2 {
// CHECK: CXXMethodDecl{{.*}} testMethod1
// CHECK-NEXT: ParmVarDecl{{.*}} param
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
-// CHECK-NEXT: StringLiteral
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
-// CHECK-NEXT: StringLiteral
// CHECK-NEXT: CXXConstructorDecl
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
-// CHECK-NEXT: StringLiteral
// CHECK-NEXT: CXXMethodDecl{{.*}} operator->
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
-// CHECK-NEXT: StringLiteral
#pragma clang attribute push (__attribute__((annotate("method"))), apply_to=any(record, field, variable, function, namespace, type_alias))
@@ -40,25 +36,19 @@ void testClass2::testMethod1(int param) {
// CHECK-LABEL: CXXMethodDecl{{.*}}prev{{.*}} testMethod1
// CHECK-NEXT: ParmVarDecl{{.*}} param
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
-// CHECK-NEXT: StringLiteral
// CHECK-NEXT: AnnotateAttr{{.*}} "method"
-// CHECK-NEXT: StringLiteral
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
-// CHECK-NEXT: StringLiteral
// CHECK-NEXT: AnnotateAttr{{.*}} "method"
-// CHECK-NEXT: StringLiteral
namespace testNamespace {
}
// CHECK-LABEL: NamespaceDecl{{.*}} testNamespace
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
-// CHECK-NEXT: StringLiteral
class testClassForward;
// CHECK-LABEL: CXXRecordDecl{{.*}} testClassForward
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
-// CHECK-NEXT: StringLiteral
namespace testNamespaceAlias = testNamespace;
// CHECK-LABEL: NamespaceAliasDecl{{.*}} testNamespaceAlias
@@ -78,7 +68,6 @@ void testCatchVariable() {
// CHECK: CXXCatchStmt
// CHECK-NEXT: VarDecl{{.*}} testCatch
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
-// CHECK-NEXT: StringLiteral
void testLambdaMethod() {
auto l = [] () { };
@@ -90,7 +79,6 @@ void testLambdaMethod() {
// CHECK: CXXMethodDecl{{.*}} operator()
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
-// CHECK-NEXT: StringLiteral
#pragma clang attribute pop
diff --git a/clang/test/Misc/pragma-attribute-objc.m b/clang/test/Misc/pragma-attribute-objc.m
index 15cd946d93b3..541cfa9ad3bc 100644
--- a/clang/test/Misc/pragma-attribute-objc.m
+++ b/clang/test/Misc/pragma-attribute-objc.m
@@ -8,7 +8,6 @@ @interface testInterface1
// CHECK-LABEL: ObjCInterfaceDecl{{.*}}testInterface1
// CHECK-NEXT: ObjCImplementation
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
-// CHECK-NEXT: StringLiteral
// CHECK-NEXT: ObjCSubclassingRestrictedAttr{{.*}}
// CHECK-NOT: AnnotateAttr
@@ -18,29 +17,24 @@ @interface testInterface1
int testIvar1;
// CHECK-LABEL: ObjCIvarDecl{{.*}} testIvar1
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
- // CHECK-NEXT: StringLiteral
// CHECK-NOT: ObjCSubclassingRestrictedAttr
}
@property int testProp1;
// CHECK-LABEL: ObjCPropertyDecl{{.*}} testProp1
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
-// CHECK-NEXT: StringLiteral
// CHECK-NOT: ObjCSubclassingRestrictedAttr
- (void)testIm:(int) x;
// CHECK-LABEL: ObjCMethodDecl{{.*}}testIm
// CHECK-NEXT: ParmVarDecl{{.*}} x
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
-// CHECK-NEXT: StringLiteral
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
-// CHECK-NEXT: StringLiteral
// CHECK-NOT: ObjCSubclassingRestrictedAttr
+ (void)testCm;
// CHECK-LABEL: ObjCMethodDecl{{.*}}testCm
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
-// CHECK-NEXT: StringLiteral
// CHECK-NOT: ObjCSubclassingRestrictedAttr
// Implicit getters/setters shouldn't receive the attributes.
@@ -62,7 +56,6 @@ @implementation testInterface1
int testIvar2;
// CHECK-LABEL: ObjCIvarDecl{{.*}} testIvar2
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
- // CHECK-NEXT: StringLiteral
// CHECK-NOT: ObjCSubclassingRestrictedAttr
}
@@ -73,10 +66,8 @@ - (void)testIm:(int) x {
// CHECK-NEXT: ImplicitParamDecl
// CHECK-NEXT: ParmVarDecl{{.*}} x
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
-// CHECK-NEXT: StringLiteral
// CHECK-NEXT: CompoundStmt
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
-// CHECK-NEXT: StringLiteral
// CHECK-NOT: ObjCSubclassingRestrictedAttr
}
@@ -98,10 +89,8 @@ @implementation testImplWithoutInterface // expected-warning {{cannot find inter
// CHECK-LABEL: ObjCInterfaceDecl{{.*}}testImplWithoutInterface
// CHECK-NEXT: ObjCImplementation
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
-// CHECK-NEXT: StringLiteral
// CHECK-NEXT: ObjCSubclassingRestrictedAttr
// CHECK-NEXT: AnnotateAttr{{.*}} "applied at container start"
-// CHECK-NEXT: StringLiteral
// CHECK-LABEL: ObjCImplementationDecl{{.*}}testImplWithoutInterface
// CHECK-NOT: AnnotateAttr
@@ -114,14 +103,12 @@ @implementation testImplWithoutInterface // expected-warning {{cannot find inter
@protocol testProtocol
// CHECK-LABEL: ObjCProtocolDecl{{.*}}testProtocol
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
-// CHECK-NEXT: StringLiteral
// CHECK-NOT: ObjCSubclassingRestrictedAttr
// CHECK-NOT: AnnotateAttr
- (void)testProtIm;
// CHECK-LABEL: ObjCMethodDecl{{.*}}testProtIm
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
-// CHECK-NEXT: StringLiteral
// CHECK-NOT: ObjCSubclassingRestrictedAttr
@end
@@ -129,7 +116,6 @@ - (void)testProtIm;
@protocol testForwardProtocol;
// CHECK-LABEL: ObjCProtocolDecl{{.*}}testForwardProtocol
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
-// CHECK-NEXT: StringLiteral
// CHECK-NOT: ObjCSubclassingRestrictedAttr
@@ -166,7 +152,6 @@ @implementation testInterface1(testCat)
@interface testInterface3
// CHECK-LABEL: ObjCInterfaceDecl{{.*}}testInterface3
// CHECK-NEXT: AnnotateAttr{{.*}} "test"
-// CHECK-NEXT: StringLiteral
// CHECK-NOT: ObjCSubclassingRestrictedAttr
@end
More information about the cfe-commits
mailing list