Re: [PATCH] D19689: Add Subjects to NoDebugAttr [NFC]
This revision was automatically updated to reflect the committed changes. Closed by commit rL268065: Add a Subjects line to NoDebugAttr [NFC]. (authored by probinson). Changed prior to commit: http://reviews.llvm.org/D19689?vs=55482&id=55618#toc Repository: rL LLVM http://reviews.llvm.org/D19689 Files: cfe/trunk/include/clang/Basic/Attr.td cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/lib/Sema/SemaDeclAttr.cpp cfe/trunk/test/Sema/attr-nodebug.c cfe/trunk/test/SemaObjC/attr-nodebug.m Index: cfe/trunk/lib/Sema/SemaDeclAttr.cpp === --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp @@ -3572,18 +3572,6 @@ } static void handleNoDebugAttr(Sema &S, Decl *D, const AttributeList &Attr) { - if (const VarDecl *VD = dyn_cast(D)) { -if (!VD->hasGlobalStorage()) - S.Diag(Attr.getLoc(), - diag::warn_attribute_requires_functions_or_static_globals) -<< Attr.getName(); - } else if (!isFunctionOrMethod(D)) { -S.Diag(Attr.getLoc(), - diag::warn_attribute_requires_functions_or_static_globals) - << Attr.getName(); -return; - } - D->addAttr(::new (S.Context) NoDebugAttr(Attr.getRange(), S.Context, Attr.getAttributeSpellingListIndex())); Index: cfe/trunk/include/clang/Basic/Attr.td === --- cfe/trunk/include/clang/Basic/Attr.td +++ cfe/trunk/include/clang/Basic/Attr.td @@ -973,6 +973,8 @@ def NoDebug : InheritableAttr { let Spellings = [GCC<"nodebug">]; + let Subjects = SubjectList<[FunctionLike, ObjCMethod, GlobalVar], WarnDiag, + "ExpectedFunctionGlobalVarMethodOrProperty">; let Documentation = [NoDebugDocs]; } Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td === --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td @@ -2512,9 +2512,6 @@ def warn_incomplete_encoded_type : Warning< "encoding of %0 type is incomplete because %1 component has unknown encoding">, InGroup>; -def warn_attribute_requires_functions_or_static_globals : Warning< - "%0 only applies to variables with static storage duration and functions">, - InGroup; def warn_gnu_inline_attribute_requires_inline : Warning< "'gnu_inline' attribute requires function to be marked 'inline'," " attribute ignored">, Index: cfe/trunk/test/Sema/attr-nodebug.c === --- cfe/trunk/test/Sema/attr-nodebug.c +++ cfe/trunk/test/Sema/attr-nodebug.c @@ -3,7 +3,7 @@ int a __attribute__((nodebug)); void b() { - int b __attribute__((nodebug)); // expected-warning {{'nodebug' only applies to variables with static storage duration and functions}} + int b __attribute__((nodebug)); // expected-warning {{'nodebug' attribute only applies to functions and global variables}} } void t1() __attribute__((nodebug)); Index: cfe/trunk/test/SemaObjC/attr-nodebug.m === --- cfe/trunk/test/SemaObjC/attr-nodebug.m +++ cfe/trunk/test/SemaObjC/attr-nodebug.m @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics +@interface NSObject +- (void)doSomething __attribute__((nodebug)); +@end Index: cfe/trunk/lib/Sema/SemaDeclAttr.cpp === --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp @@ -3572,18 +3572,6 @@ } static void handleNoDebugAttr(Sema &S, Decl *D, const AttributeList &Attr) { - if (const VarDecl *VD = dyn_cast(D)) { -if (!VD->hasGlobalStorage()) - S.Diag(Attr.getLoc(), - diag::warn_attribute_requires_functions_or_static_globals) -<< Attr.getName(); - } else if (!isFunctionOrMethod(D)) { -S.Diag(Attr.getLoc(), - diag::warn_attribute_requires_functions_or_static_globals) - << Attr.getName(); -return; - } - D->addAttr(::new (S.Context) NoDebugAttr(Attr.getRange(), S.Context, Attr.getAttributeSpellingListIndex())); Index: cfe/trunk/include/clang/Basic/Attr.td === --- cfe/trunk/include/clang/Basic/Attr.td +++ cfe/trunk/include/clang/Basic/Attr.td @@ -973,6 +973,8 @@ def NoDebug : InheritableAttr { let Spellings = [GCC<"nodebug">]; + let Subjects = SubjectList<[FunctionLike, ObjCMethod, GlobalVar], WarnDiag, + "ExpectedFunctionGlobalVarMethodOrProperty">; let Documentation = [NoDebugDocs]; } Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td === --- cfe/trunk/include/clang/Basic/DiagnosticSemaKi
Re: [PATCH] D19689: Add Subjects to NoDebugAttr [NFC]
On Fri, Apr 29, 2016 at 12:24 PM, Paul Robinson wrote: > probinson added a comment. > > I'll proceed from here without doing anything about the inconsistencies, > because this particular one should go away and you're already doing something > about the rest of it. I think that's a good idea. :-) ~Aaron > > > > Comment at: include/clang/Basic/Attr.td:977 > @@ -976,1 +976,3 @@ > + let Subjects = SubjectList<[FunctionLike, ObjCMethod, GlobalVar], WarnDiag, > + "ExpectedFunctionGlobalVarMethodOrProperty">; >let Documentation = [NoDebugDocs]; > > aaron.ballman wrote: >> It's really strange that the diagnostic kind is >> `ExpectedFunctionGlobalVarMethodOrProperty` but the subject list does not >> have objective-c properties. It's even more strange that this diagnostic >> kind corresponds to the diagnostic text "functions and global variables" >> without mention of objective-c methods or properties. I see that the Alias >> attribute suffers from this same discombobulation. > I agree, but I didn't want to do anything about it because my next step is to > replace GlobalVar with Var in the SubjectList, and therefore change the > diagnostic enum to something else, making the inconsistency moot (at least > for this attribute). > > > > http://reviews.llvm.org/D19689 > > > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19689: Add Subjects to NoDebugAttr [NFC]
probinson added a comment. I'll proceed from here without doing anything about the inconsistencies, because this particular one should go away and you're already doing something about the rest of it. Comment at: include/clang/Basic/Attr.td:977 @@ -976,1 +976,3 @@ + let Subjects = SubjectList<[FunctionLike, ObjCMethod, GlobalVar], WarnDiag, + "ExpectedFunctionGlobalVarMethodOrProperty">; let Documentation = [NoDebugDocs]; aaron.ballman wrote: > It's really strange that the diagnostic kind is > `ExpectedFunctionGlobalVarMethodOrProperty` but the subject list does not > have objective-c properties. It's even more strange that this diagnostic kind > corresponds to the diagnostic text "functions and global variables" without > mention of objective-c methods or properties. I see that the Alias attribute > suffers from this same discombobulation. I agree, but I didn't want to do anything about it because my next step is to replace GlobalVar with Var in the SubjectList, and therefore change the diagnostic enum to something else, making the inconsistency moot (at least for this attribute). http://reviews.llvm.org/D19689 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19689: Add Subjects to NoDebugAttr [NFC]
On Thu, Apr 28, 2016 at 4:46 PM, Robinson, Paul wrote: > Generally tests test something other than "this program doesn't crash" - > should it test that we apply the attribute correctly? (either via ast dump, > or checking the resulting DWARF doesn't have debug info on the relevant > entity) > > Or is this not actually a new/separate codepath? In which case do we > really need the test? > > > > It's a –verify test which is about diagnostics, rather than not-crashing. > It parallels line 3 of Sema/attr-nodebug.c, which verifies the attribute > can be applied to a function. Without this test, you could remove > "ObjCMethod" from the Subjects line and no test would fail. I put > "ObjCMethod" on the Subjects line because the hand-coded condition used > "isFunctionOrMethod" which permits Objective-C methods. The new test > passes with old and new compilers, demonstrating the NFC claim. > Ah, OK - thanks for the context :) > > > Now, if we decide the 'nodebug' attribute should not apply to Objective-C, > that's fine with me, in which case the new test should verify that a > diagnostic *is* produced. > > > > I am admittedly clueless about Objective-C, are they handled differently > from other functions by the time we get to CGDebugInfo? If there's another > path I should tweak, I'd like to know about it. > > Thanks, > > --paulr > > > > *From:* David Blaikie [mailto:dblai...@gmail.com] > *Sent:* Thursday, April 28, 2016 4:26 PM > *To:* reviews+d19689+public+514682b5314c5...@reviews.llvm.org; Robinson, > Paul > *Cc:* Aaron Ballman; cfe-commits > *Subject:* Re: [PATCH] D19689: Add Subjects to NoDebugAttr [NFC] > > > > LGTM > > > > On Thu, Apr 28, 2016 at 2:10 PM, Paul Robinson via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > > probinson created this revision. > probinson added a reviewer: aaron.ballman. > probinson added a subscriber: cfe-commits. > > The 'nodebug' attribute had hand-coded constraints; replace those with a > Subjects line in Attr.td. > Also add a missing test to verify the attribute is okay on an Objective-C > method. > > http://reviews.llvm.org/D19689 > > Files: > include/clang/Basic/Attr.td > include/clang/Basic/DiagnosticSemaKinds.td > lib/Sema/SemaDeclAttr.cpp > test/Sema/attr-nodebug.c > test/SemaObjC/attr-nodebug.m > > Index: test/SemaObjC/attr-nodebug.m > === > --- test/SemaObjC/attr-nodebug.m > +++ test/SemaObjC/attr-nodebug.m > @@ -0,0 +1,5 @@ > +// RUN: %clang_cc1 -fsyntax-only -verify %s > +// expected-no-diagnostics > +@interface NSObject > +- (void)doSomething __attribute__((nodebug)); > +@end > > > > Generally tests test something other than "this program doesn't crash" - > should it test that we apply the attribute correctly? (either via ast dump, > or checking the resulting DWARF doesn't have debug info on the relevant > entity) > > Or is this not actually a new/separate codepath? In which case do we > really need the test? > > > > Index: test/Sema/attr-nodebug.c > === > --- test/Sema/attr-nodebug.c > +++ test/Sema/attr-nodebug.c > @@ -3,7 +3,7 @@ > int a __attribute__((nodebug)); > > void b() { > - int b __attribute__((nodebug)); // expected-warning {{'nodebug' only > applies to variables with static storage duration and functions}} > + int b __attribute__((nodebug)); // expected-warning {{'nodebug' > attribute only applies to functions and global variables}} > } > > void t1() __attribute__((nodebug)); > Index: lib/Sema/SemaDeclAttr.cpp > === > --- lib/Sema/SemaDeclAttr.cpp > +++ lib/Sema/SemaDeclAttr.cpp > @@ -3572,18 +3572,6 @@ > } > > static void handleNoDebugAttr(Sema &S, Decl *D, const AttributeList > &Attr) { > - if (const VarDecl *VD = dyn_cast(D)) { > -if (!VD->hasGlobalStorage()) > - S.Diag(Attr.getLoc(), > - diag::warn_attribute_requires_functions_or_static_globals) > -<< Attr.getName(); > - } else if (!isFunctionOrMethod(D)) { > -S.Diag(Attr.getLoc(), > - diag::warn_attribute_requires_functions_or_static_globals) > - << Attr.getName(); > -return; > - } > - >D->addAttr(::new (S.Context) > NoDebugAttr(Attr.getRange(), S.Context, > Attr.getAttributeSpellingListIndex())); > Ind
Re: [PATCH] D19689: Add Subjects to NoDebugAttr [NFC]
aaron.ballman accepted this revision. aaron.ballman added a comment. This revision is now accepted and ready to land. This turns out to be a bit of a mess: Alias and NoDebug use the same diagnostic kind text, neither of which match the actual subject list. Alias doesn't appertain to an obj-c method or property. NoDebug doesn't appertain to an obj-c property. The diagnostic text for that diagnostic kind doesn't match the subject list it is describing in either case. And the diagnostic text talks about "global variables" when what it really means are "variables that have global *storage*" and so static storage duration is a bit more accurate than "global variable" which implies that the following should diagnose: void f() { static int i __attribute__((nodebug)); } I have a WIP patch (http://reviews.llvm.org/D18768) that will hopefully make this situation better. Your current changes will add a bit of overhead to my refactoring, but it's a drop in the bucket compared to the other diagnostic wording changes, so I'm not overly concerned. I think the patch LGTM despite my comments. Comment at: include/clang/Basic/Attr.td:977 @@ -976,1 +976,3 @@ + let Subjects = SubjectList<[FunctionLike, ObjCMethod, GlobalVar], WarnDiag, + "ExpectedFunctionGlobalVarMethodOrProperty">; let Documentation = [NoDebugDocs]; It's really strange that the diagnostic kind is `ExpectedFunctionGlobalVarMethodOrProperty` but the subject list does not have objective-c properties. It's even more strange that this diagnostic kind corresponds to the diagnostic text "functions and global variables" without mention of objective-c methods or properties. I see that the Alias attribute suffers from this same discombobulation. Comment at: test/Sema/attr-nodebug.c:6 @@ -5,3 +5,3 @@ void b() { - int b __attribute__((nodebug)); // expected-warning {{'nodebug' only applies to variables with static storage duration and functions}} + int b __attribute__((nodebug)); // expected-warning {{'nodebug' attribute only applies to functions and global variables}} } Global variables is a misnomer though since this really applies to variables with static storage duration (including local variables). http://reviews.llvm.org/D19689 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
RE: [PATCH] D19689: Add Subjects to NoDebugAttr [NFC]
Generally tests test something other than "this program doesn't crash" - should it test that we apply the attribute correctly? (either via ast dump, or checking the resulting DWARF doesn't have debug info on the relevant entity) Or is this not actually a new/separate codepath? In which case do we really need the test? It's a –verify test which is about diagnostics, rather than not-crashing. It parallels line 3 of Sema/attr-nodebug.c, which verifies the attribute can be applied to a function. Without this test, you could remove "ObjCMethod" from the Subjects line and no test would fail. I put "ObjCMethod" on the Subjects line because the hand-coded condition used "isFunctionOrMethod" which permits Objective-C methods. The new test passes with old and new compilers, demonstrating the NFC claim. Now, if we decide the 'nodebug' attribute should not apply to Objective-C, that's fine with me, in which case the new test should verify that a diagnostic *is* produced. I am admittedly clueless about Objective-C, are they handled differently from other functions by the time we get to CGDebugInfo? If there's another path I should tweak, I'd like to know about it. Thanks, --paulr From: David Blaikie [mailto:dblai...@gmail.com] Sent: Thursday, April 28, 2016 4:26 PM To: reviews+d19689+public+514682b5314c5...@reviews.llvm.org; Robinson, Paul Cc: Aaron Ballman; cfe-commits Subject: Re: [PATCH] D19689: Add Subjects to NoDebugAttr [NFC] LGTM On Thu, Apr 28, 2016 at 2:10 PM, Paul Robinson via cfe-commits mailto:cfe-commits@lists.llvm.org>> wrote: probinson created this revision. probinson added a reviewer: aaron.ballman. probinson added a subscriber: cfe-commits. The 'nodebug' attribute had hand-coded constraints; replace those with a Subjects line in Attr.td. Also add a missing test to verify the attribute is okay on an Objective-C method. http://reviews.llvm.org/D19689 Files: include/clang/Basic/Attr.td include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclAttr.cpp test/Sema/attr-nodebug.c test/SemaObjC/attr-nodebug.m Index: test/SemaObjC/attr-nodebug.m === --- test/SemaObjC/attr-nodebug.m +++ test/SemaObjC/attr-nodebug.m @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// expected-no-diagnostics +@interface NSObject +- (void)doSomething __attribute__((nodebug)); +@end Generally tests test something other than "this program doesn't crash" - should it test that we apply the attribute correctly? (either via ast dump, or checking the resulting DWARF doesn't have debug info on the relevant entity) Or is this not actually a new/separate codepath? In which case do we really need the test? Index: test/Sema/attr-nodebug.c === --- test/Sema/attr-nodebug.c +++ test/Sema/attr-nodebug.c @@ -3,7 +3,7 @@ int a __attribute__((nodebug)); void b() { - int b __attribute__((nodebug)); // expected-warning {{'nodebug' only applies to variables with static storage duration and functions}} + int b __attribute__((nodebug)); // expected-warning {{'nodebug' attribute only applies to functions and global variables}} } void t1() __attribute__((nodebug)); Index: lib/Sema/SemaDeclAttr.cpp === --- lib/Sema/SemaDeclAttr.cpp +++ lib/Sema/SemaDeclAttr.cpp @@ -3572,18 +3572,6 @@ } static void handleNoDebugAttr(Sema &S, Decl *D, const AttributeList &Attr) { - if (const VarDecl *VD = dyn_cast(D)) { -if (!VD->hasGlobalStorage()) - S.Diag(Attr.getLoc(), - diag::warn_attribute_requires_functions_or_static_globals) -<< Attr.getName(); - } else if (!isFunctionOrMethod(D)) { -S.Diag(Attr.getLoc(), - diag::warn_attribute_requires_functions_or_static_globals) - << Attr.getName(); -return; - } - D->addAttr(::new (S.Context) NoDebugAttr(Attr.getRange(), S.Context, Attr.getAttributeSpellingListIndex())); Index: include/clang/Basic/DiagnosticSemaKinds.td === --- include/clang/Basic/DiagnosticSemaKinds.td +++ include/clang/Basic/DiagnosticSemaKinds.td @@ -2504,9 +2504,6 @@ def warn_incomplete_encoded_type : Warning< "encoding of %0 type is incomplete because %1 component has unknown encoding">, InGroup>; -def warn_attribute_requires_functions_or_static_globals : Warning< - "%0 only applies to variables with static storage duration and functions">, - InGroup; def warn_gnu_inline_attribute_requires_inline : Warning< "'gnu_inline' attribute requires function to be marked 'inline'," " attribute ign
Re: [PATCH] D19689: Add Subjects to NoDebugAttr [NFC]
LGTM On Thu, Apr 28, 2016 at 2:10 PM, Paul Robinson via cfe-commits < cfe-commits@lists.llvm.org> wrote: > probinson created this revision. > probinson added a reviewer: aaron.ballman. > probinson added a subscriber: cfe-commits. > > The 'nodebug' attribute had hand-coded constraints; replace those with a > Subjects line in Attr.td. > Also add a missing test to verify the attribute is okay on an Objective-C > method. > > http://reviews.llvm.org/D19689 > > Files: > include/clang/Basic/Attr.td > include/clang/Basic/DiagnosticSemaKinds.td > lib/Sema/SemaDeclAttr.cpp > test/Sema/attr-nodebug.c > test/SemaObjC/attr-nodebug.m > > Index: test/SemaObjC/attr-nodebug.m > === > --- test/SemaObjC/attr-nodebug.m > +++ test/SemaObjC/attr-nodebug.m > @@ -0,0 +1,5 @@ > +// RUN: %clang_cc1 -fsyntax-only -verify %s > +// expected-no-diagnostics > +@interface NSObject > +- (void)doSomething __attribute__((nodebug)); > +@end > Generally tests test something other than "this program doesn't crash" - should it test that we apply the attribute correctly? (either via ast dump, or checking the resulting DWARF doesn't have debug info on the relevant entity) Or is this not actually a new/separate codepath? In which case do we really need the test? > Index: test/Sema/attr-nodebug.c > === > --- test/Sema/attr-nodebug.c > +++ test/Sema/attr-nodebug.c > @@ -3,7 +3,7 @@ > int a __attribute__((nodebug)); > > void b() { > - int b __attribute__((nodebug)); // expected-warning {{'nodebug' only > applies to variables with static storage duration and functions}} > + int b __attribute__((nodebug)); // expected-warning {{'nodebug' > attribute only applies to functions and global variables}} > } > > void t1() __attribute__((nodebug)); > Index: lib/Sema/SemaDeclAttr.cpp > === > --- lib/Sema/SemaDeclAttr.cpp > +++ lib/Sema/SemaDeclAttr.cpp > @@ -3572,18 +3572,6 @@ > } > > static void handleNoDebugAttr(Sema &S, Decl *D, const AttributeList > &Attr) { > - if (const VarDecl *VD = dyn_cast(D)) { > -if (!VD->hasGlobalStorage()) > - S.Diag(Attr.getLoc(), > - diag::warn_attribute_requires_functions_or_static_globals) > -<< Attr.getName(); > - } else if (!isFunctionOrMethod(D)) { > -S.Diag(Attr.getLoc(), > - diag::warn_attribute_requires_functions_or_static_globals) > - << Attr.getName(); > -return; > - } > - >D->addAttr(::new (S.Context) > NoDebugAttr(Attr.getRange(), S.Context, > Attr.getAttributeSpellingListIndex())); > Index: include/clang/Basic/DiagnosticSemaKinds.td > === > --- include/clang/Basic/DiagnosticSemaKinds.td > +++ include/clang/Basic/DiagnosticSemaKinds.td > @@ -2504,9 +2504,6 @@ > def warn_incomplete_encoded_type : Warning< >"encoding of %0 type is incomplete because %1 component has unknown > encoding">, >InGroup>; > -def warn_attribute_requires_functions_or_static_globals : Warning< > - "%0 only applies to variables with static storage duration and > functions">, > - InGroup; > def warn_gnu_inline_attribute_requires_inline : Warning< >"'gnu_inline' attribute requires function to be marked 'inline'," >" attribute ignored">, > Index: include/clang/Basic/Attr.td > === > --- include/clang/Basic/Attr.td > +++ include/clang/Basic/Attr.td > @@ -973,6 +973,8 @@ > > def NoDebug : InheritableAttr { >let Spellings = [GCC<"nodebug">]; > + let Subjects = SubjectList<[FunctionLike, ObjCMethod, GlobalVar], > WarnDiag, > + > "ExpectedFunctionGlobalVarMethodOrProperty">; >let Documentation = [NoDebugDocs]; > } > > > > > ___ > cfe-commits mailing list > cfe-commits@lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits > > ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits