-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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] Improve _Alignas
on a struct
declaration diagnostic
#65638
Conversation
Generally looks good, thanks for working on this I'd like to see more tests in |
There is similar effort on Phab, we should pick one of them https://reviews.llvm.org/D141177 |
@AaronBallman you have a preference as to which PR we pursue? |
No strong preference, but the author of D141177 seems to have gone silent again so if @jerinphilip is actively working on this patch, I'd say let's go with this one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo nitpick.
Maybe @AaronBallman will want to look at it too.
Do we want a release notes for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this! I think the changes should come with a release note so users know about the fix. I did have a question on the design, but overall the direction seems sensible to me.
74b62ef
to
919be6b
Compare
I have rebased the PR with main (which appears to fix the formatting workflow). For the time being, I have left the C23 test using I've altered the state of this PR to be close to D141177, using the existing attribute warning for reduced complexity (happy to provide attribution). Key difference The following routes were also considered:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from some nits, I think this looks reasonable to me. I'll leave the final sign-off to @erichkeane but if he doesn't approve in the next few days (WG21 meetings are upcoming so he may be busy), I'll come back to approve.
Thank you for all the help on this one! It turns out good first issue
is really hard to determine accurately. ;-)
clang/docs/ReleaseNotes.rst
Outdated
declaration specifiers. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
declaration specifiers. | |
declaration specifiers. | |
(#58637 <https://github.com/llvm/llvm-project/issues/58637>`_) |
clang/lib/Sema/SemaDecl.cpp
Outdated
unsigned DiagnosticId; | ||
if (AL.isAlignas() && !getLangOpts().CPlusPlus) { | ||
DiagnosticId = diag::warn_attribute_ignored; | ||
} else if (AL.isRegularKeywordAttribute()) { | ||
DiagnosticId = diag::err_declspec_keyword_has_no_effect; | ||
} else { | ||
DiagnosticId = diag::warn_declspec_attribute_ignored; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsigned DiagnosticId; | |
if (AL.isAlignas() && !getLangOpts().CPlusPlus) { | |
DiagnosticId = diag::warn_attribute_ignored; | |
} else if (AL.isRegularKeywordAttribute()) { | |
DiagnosticId = diag::err_declspec_keyword_has_no_effect; | |
} else { | |
DiagnosticId = diag::warn_declspec_attribute_ignored; | |
} | |
unsigned DiagnosticId = diag::warn_declspec_attribute_ignored; | |
if (AL.isAlignas() && !getLangOpts().CPlusPlus) | |
DiagnosticId = diag::warn_attribute_ignored; | |
else if (AL.isRegularKeywordAttribute()) | |
DiagnosticId = diag::err_declspec_keyword_has_no_effect; |
Changes for our odd choice coding style and to be slightly more succinct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments Aaron made should be fixed, plus 1 more from me, else LGTM.
@@ -192,6 +192,13 @@ class AttributeCommonInfo { | |||
|
|||
bool isC23Attribute() const { return SyntaxUsed == AS_C23; } | |||
|
|||
bool isAlignas() const { | |||
// In the current state of code, IsAlignas is only configured to return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is immediately stale once we commit this, right? Also, it refers to IsAlignas
, but the function name is isAlignas
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This refers to the variable IsAlignAs
(not the parent function isAlignas
), and the sentence holds for the current state of code. I believe I'm trying to explain why I cannot use IsAlignas
's current behaviour here (as it is more invasive). Normally I'd expect this function to be a const
accessor to a private member per programming conventions, which is not the case here, hence a comment.
I'm sensing the review comment confusion indicates I need to communicate this better in source comments. Suggestions welcome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about:
// FIXME: In the current state, the IsAlignas member variable is only true with the C++
// `alignas` keyword but not `_Alignas`. The following expression works around the
// otherwise lost information so it will return true for `alignas` or `_Alignas` while still
// returning false for things like `__attribute__((aligned))`.
919be6b
to
323e569
Compare
Adds `isAlignas()` method on `AttributeCommonInfo` which accounts for C++ `alignas` as well as C11 `_Alignas`. The method is used to improve diagnostic in C when `_Alignas` is used in C at the wrong location. This corrects the previously suggested move of `_Alignas` past the declaration specifier, now warns attribute `_Alignas` is ignored.
323e569
to
947d4b4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you for the fix!
Fixes #58637.
Adds
isAlignas()
method onAttributeCommonInfo
which accounts forC++
alignas
as well as C11_Alignas
.The method is used to improve diagnostic in C when
_Alignas
is used inC at the wrong location. This corrects the previously suggested move
of
_Alignas
past the declaration specifier, now warns attribute_Alignas
is ignored.Based on https://reviews.llvm.org/D141177.