GCC warns on these cases, but we currently just silently ignore the attribute.
Details
- Reviewers
rjmccall • espindola aaron.ballman - Commits
- rGdaa3c5b1325e: [Sema] Emit warning for visibility attribute on internal-linkage declaration
rC359814: [Sema] Emit warning for visibility attribute on internal-linkage declaration
rL359814: [Sema] Emit warning for visibility attribute on internal-linkage declaration
Diff Detail
- Repository
- rL LLVM
Event Timeline
lib/Sema/SemaDeclAttr.cpp | ||
---|---|---|
2619 ↗ | (On Diff #196528) | const auto *ND please. |
2621 ↗ | (On Diff #196528) | I think it would be more helpful for users if we introduced a new diagnostic here that explained why the attribute is being ignored, otherwise the diagnostic is somewhat indecipherable. |
2622 ↗ | (On Diff #196528) | We shouldn't early return here (it's not an error, just a warning), so that the other diagnostics can also trigger if needed. |
lib/Sema/SemaDeclAttr.cpp | ||
---|---|---|
2621 ↗ | (On Diff #196528) | Sure, I am amenable to anything here. GCC uses the same short message, but it does seem to indicate e.g. that the keyword static played some role by using additional source ranges. I don't know how we would go about that with the Sema/AST split? We could just go with a more explicit message. Do you have any thoughts on the wording? warning: 'visibility' attribute ignored on non-external symbol |
2622 ↗ | (On Diff #196528) | Should I also fix the other early-return-on-warning's in the same function, e.g. the function begins with: // Visibility attributes don't mean anything on a typedef. if (isa<TypedefNameDecl>(D)) { S.Diag(AL.getRange().getBegin(), diag::warn_attribute_ignored) << AL; return; } I suppose the difference is that the attribute "can" be placed on the symbol in this case, but it is ignored just the same. |
lib/Sema/SemaDeclAttr.cpp | ||
---|---|---|
2621 ↗ | (On Diff #196528) | Your suggested diagnostic text seems pretty close to me, but how about: 'visibility' attribute is ignore on a non-external symbol in the IgnoredAttributes group. |
2622 ↗ | (On Diff #196528) | That might be worth fixing as well, but as a separate patch because it's also kind of unrelated to the functionality in this patch. Good catch! |
Use distinct sema diagnostic and do not return early.
I am going to bump DIAG_SIZE_SEMA in another patch, as it seems like we have hit the current limit.
Richard Smith on cfe-dev pointed out some cases where this patch is incorrect, stemming from trying to calculate the linkage too early; the warning will either have to work without the use of isExternallyVisible or will have to be emitted later. This was reverted in r359858 for now.