This is an archive of the discontinued LLVM Phabricator instance.

inline stmt attribute diagnosing in templates
ClosedPublic

Authored by erichkeane on Mar 17 2023, 12:10 PM.

Details

Reviewers
aaron.ballman
Group Reviewers
Restricted Project
Commits
rG514e4359a543: inline stmt attribute diagnosing in templates
Summary

D146089's author discovered that our diagnostics for always/no inline
would null-dereference when used in a template. He fixed that by
skipping in the dependent case.

This patch makes sure we diagnose these after a template instantiation.
It also adds infrastructure for other statement attributes to add
checking/transformation.

Diff Detail

Event Timeline

erichkeane created this revision.Mar 17 2023, 12:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2023, 12:10 PM
erichkeane requested review of this revision.Mar 17 2023, 12:10 PM
aaron.ballman added inline comments.
clang/docs/ReleaseNotes.rst
184
clang/lib/Sema/SemaStmtAttr.cpp
225–231

Minor cleanup; NFC

241

Range-based for loop using llvm::enumerate() so you can keep the index?

clang/lib/Sema/TreeTransform.h
411–412

So we don't get unused parameter warnings.

7617–7618

Hmmm, this seems a bit inconsistent -- why do we pass the AttributedStmt as the first argument and not S->getSubStmt()? It may be totally reasonable, but should we make the first parameter of TransformStmtAttr() be const AttributedStmt * instead of const Stmt * so it's clear to callers that what they're getting for the original is already wrapped as opposed to unwrapped like the second argument?

erichkeane marked 5 inline comments as done.

Changes aaron suggested. Chose zip_longest instead of enumerate.

aaron.ballman added inline comments.Mar 20 2023, 12:37 PM
clang/test/Sema/attr-alwaysinline.cpp
48

Why is this not included in the 3 for: // expected-warning@+4 3{{statement attribute 'always_inline' has higher precedence than function attribute 'noinline'}}

It's pretty unfortunate just how often this diagnostic triggers for the same line of code. This seems rather chatty, can you help me understand what's going on?

erichkeane added inline comments.Mar 20 2023, 12:45 PM
clang/test/Sema/attr-alwaysinline.cpp
48

I split them because they are diagnosing different 'things'. See the associated 'note' on it.

THIS warning is the one that happens while forming the primary template (the non-dependent call to non_dependent), and is later suppressed in the individual instantiations (which is the logic with the 'old' statement in SemaStmtAttr.cpp).

The set on line 50 is for baz, which we emit 3x, because we're instantiating this function 3x. Suppressing these isn't particularly possible without putting some sort of state in the AST of 'have we diagnosed this' as far as I can tell.

The variadic case below defeats our suppression entirely, which is why it diagnoses so often. The non-dependent case can no longer be suppressed, because we don't have a good hold of which pre-instantiation call-exprs are associated with the post-instantiated call-exprs.

erichkeane added inline comments.Mar 21 2023, 6:09 AM
clang/test/Sema/attr-alwaysinline.cpp
48

As far as the 'chattiness', I suspect using these attributes on a statement with multiple call expressions is likely pretty rare. Using it on a dependent call is probably less likely.

That said, this attribute is a ergonomic nightmare if there are any call expressions in an argument list... I'm hoping whoever uses this is aware of that!

aaron.ballman accepted this revision.Mar 21 2023, 7:58 AM

LGTM, thank you!

This revision is now accepted and ready to land.Mar 21 2023, 7:58 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 21 2023, 8:17 AM