This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Diagnose annotating `if constexpr` with a likelihood attribute
ClosedPublic

Authored by Mordante on Oct 28 2020, 12:28 PM.

Details

Summary

Adds a diagnostic when the user annotates an if constexpr with a likelihood attribute. The if constexpr statement is evaluated at compile time so the attribute has no effect. Annotating the accompanied else with a likelihood attribute has the same effect as annotating a generic statement. Since the attribute there is most likely not intended, a diagnostic will be issued. Since the attributes can't conflict, the "conflict" won't be diagnosed for an if constexpr.

It extends diagnostics on a patch in review.
Depends on D89899

Diff Detail

Event Timeline

Mordante requested review of this revision.Oct 28 2020, 12:28 PM
Mordante created this revision.

Patch generally looks good. Minor complaint about how you're using notes.

clang/include/clang/Basic/DiagnosticSemaKinds.td
3163

This isn't a useful form of re-use. The problem is that the original note is pretending to be generic when it really isn't; please rename it to something like note_annotating_infinite_loop_here (maybe in a different patch). This patch should just add a new note.

aaron.ballman accepted this revision.Oct 30 2020, 9:36 AM

LGTM aside from the point @rjmccall made about the note.

This revision is now accepted and ready to land.Oct 30 2020, 9:36 AM
Mordante marked an inline comment as done.Oct 30 2020, 11:09 AM

Thanks for the review!

clang/include/clang/Basic/DiagnosticSemaKinds.td
3163

I'll fix it. I'll also change the warn at line 3158, since that uses the same select.

This revision was landed with ongoing or failed builds.Oct 31 2020, 9:52 AM
This revision was automatically updated to reflect the committed changes.
Mordante marked an inline comment as done.