-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[[clang::lifetimebound]] is ignored without warning if the function parameter doesn't have a name. #96034
Comments
@llvm/issue-subscribers-clang-frontend Author: Haojian Wu (hokein) See the example:
The AST looks like:
|
It looks like the attribute is just ignored without warning at that position: https://godbolt.org/z/nM56PbTbe int* good(const int& abc[[clang::lifetimebound]]);
int* bad(const int& [[clang::lifetimebound]]);
int* good2([[clang::lifetimebound]] const int&);
int* good3([[clang::lifetimebound]] const int& abc);
int* bad2(const int& [[clang::lifetimebound]] abc);
int main() {
int* a = good(0);
int* b = bad(0); // no -Wdangling
int* c = good2(0);
int* d = good3(0);
int* e = bad2(0); // no -Wdangling
} The fact that it doesn't work makes sense as Compare that to the similar int* good(const int* abc[[gnu::nonnull]]);
int* bad(const int* [[gnu::nonnull]]); // warning: attribute ignored
int* good2([[gnu::nonnull]] const int*);
int* good3([[gnu::nonnull]] const int* abc);
int* bad2(const int* [[gnu::nonnull]] abc); // warning: attribute ignored
int main() {
int* a = good(0);
int* b = bad(0); // no warning
int* c = good2(0);
int* d = good3(0);
int* e = bad2(0); // no warning
}
llvm-project/clang/include/clang/Basic/Attr.td Line 1793 in f991ebb
llvm-project/clang/include/clang/Basic/Attr.td Line 2190 in f991ebb
|
Thanks for the clarification.
Yeah, this makes sense. For the |
I think we're not diagnosing this as a non-type attribute applied to a type because it is a type attribute -- specifically, when applied to ah implicit object parameter, what it actually appertains to is a function type. We'll need some better checking for the |
I've published #118281 which adds warnings to diagnose this and similar cases of a silent |
Emit the "cannot be applied to types" warning instead of silently ignoring the attribute when it's attempted to be used on a type (instead of a function argument or the function definition). Before this commit, the warning has been printed when the attribute was (mis)used on a decl-specifier, but not in other places in a declarator. Examples where the warning starts being emitted with this commit: ``` int * [[clang::lifetimebound]] x; void f(int * [[clang::lifetimebound]] x); void g(int * [[clang::lifetimebound]]); ``` Note that the last example is the case of an unnamed function parameter. While in theory Clang could've supported the `[[clang::lifetimebound]]` analysis for unnamed parameters, it doesn't currently, so the commit at least makes the situation better by highlighting this as a warning instead of a silent ignore - which was reported at #96034.
…18501) This relands #118281 as-is, after it got reverted in commit 356df2d. The reland can go in after we fixed some downstream codebases that had incorrectly placed attributes. Original commit description: > Emit the "cannot be applied to types" warning instead of silently ignoring the attribute when it's attempted to be used on a type (instead of a function argument or the function definition). > > Before this commit, the warning has been printed when the attribute was (mis)used on a decl-specifier, but not in other places in a declarator. > > Examples where the warning starts being emitted with this commit: > > ``` > int * [[clang::lifetimebound]] x; > > void f(int * [[clang::lifetimebound]] x); > > void g(int * [[clang::lifetimebound]]); > ``` > > Note that the last example is the case of an unnamed function parameter. While in theory Clang could've supported the `[[clang::lifetimebound]]` analysis for unnamed parameters, it doesn't currently, so the commit at least makes the situation better by highlighting this as a warning instead of a silent ignore - which was reported at #96034.
…vm#118501) This relands llvm#118281 as-is, after it got reverted in commit 356df2d. The reland can go in after we fixed some downstream codebases that had incorrectly placed attributes. Original commit description: > Emit the "cannot be applied to types" warning instead of silently ignoring the attribute when it's attempted to be used on a type (instead of a function argument or the function definition). > > Before this commit, the warning has been printed when the attribute was (mis)used on a decl-specifier, but not in other places in a declarator. > > Examples where the warning starts being emitted with this commit: > > ``` > int * [[clang::lifetimebound]] x; > > void f(int * [[clang::lifetimebound]] x); > > void g(int * [[clang::lifetimebound]]); > ``` > > Note that the last example is the case of an unnamed function parameter. While in theory Clang could've supported the `[[clang::lifetimebound]]` analysis for unnamed parameters, it doesn't currently, so the commit at least makes the situation better by highlighting this as a warning instead of a silent ignore - which was reported at llvm#96034.
See the example:
The AST looks like:
The text was updated successfully, but these errors were encountered: