This is an archive of the discontinued LLVM Phabricator instance.

Add begin source location for the attributed statement created from PragmaLoopHint decorated loop
ClosedPublic

Authored by ychen on Jun 1 2020, 11:53 AM.

Details

Summary

Right now it is a '<invalid sloc>' for cases like this.
CounterCoverageMappingBuilder relies on the information to decide the
region for a attributed loop.

Fix PR40971

Diff Detail

Event Timeline

ychen created this revision.Jun 1 2020, 11:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 1 2020, 11:53 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
jdenny added a comment.Jun 5 2020, 9:11 AM

This looks like a continuation of the work started in D61643 (which makes the loc of #pragma available to pragma handlers) and D61509 (which changes the start loc for OpenMP pragmas from omp to #pragma).

clang/lib/Parse/ParsePragma.cpp
3102

When I remove this change, the new test still passes. Please make sure this case is covered.

clang/lib/Parse/ParseStmt.cpp
2176

I think the call to getExpansionLoc shouldn't be here. If the ast dumper or other clients want to convert to that form, they can do so.

ychen updated this revision to Diff 268958.Jun 5 2020, 4:22 PM
  • Address feedback
ychen marked 4 inline comments as done.Jun 5 2020, 4:25 PM
ychen added inline comments.
clang/lib/Parse/ParsePragma.cpp
3102

Added a test case for this.

clang/lib/Parse/ParseStmt.cpp
2176

Indeed. Removing this helps code coverage shows the coverage for the macro spelling location. Thanks.

jdenny accepted this revision.Jun 8 2020, 7:52 AM

LGTM except for the nit I put in a comment.

However, I have little experience with these particular pragmas. Before pushing, please give others a few more days in case they want to review.

clang/test/AST/sourceranges.cpp
116

Is there any reason not to check for LoopHintAttr here and on the _Pragma case below? If so, I suggest a comment to explain why these cases are different.

This revision is now accepted and ready to land.Jun 8 2020, 7:52 AM
ychen updated this revision to Diff 269282.Jun 8 2020, 10:05 AM
ychen marked 3 inline comments as done.
  • add comment
clang/test/AST/sourceranges.cpp
116

Comment added.

The existing checking of LoopHintAttr already covered the code changes in ParsePragma.cpp. In the other two cases LoopHintAttr have its location in <scratch space> which I felt unrelated to this change so I skipped them to avoid confusion.

jdenny marked an inline comment as done.Jun 8 2020, 10:47 AM
jdenny added inline comments.
clang/test/AST/sourceranges.cpp
116

Thanks.

ychen updated this revision to Diff 269380.Jun 8 2020, 4:44 PM
  • update
aaron.ballman accepted this revision.Jun 9 2020, 6:23 AM

LGTM aside from a minor nit.

clang/lib/Parse/ParseStmt.cpp
2198

You can use isInvalid() here rather than !isValid(). Also, I'd appreciate an assertion message like && "start of attribute range already set" or something.

ychen updated this revision to Diff 269586.Jun 9 2020, 10:05 AM
  • address comments
ychen marked an inline comment as done.Jun 9 2020, 10:05 AM
This revision was automatically updated to reflect the committed changes.

Note that this causes a regression (reported here) https://bugs.llvm.org/show_bug.cgi?id=46336

The assert added here breaks in the case where a pragma loop attribute is combined with a C++ attribute.

ychen added a comment.Jun 16 2020, 3:09 PM

Note that this causes a regression (reported here) https://bugs.llvm.org/show_bug.cgi?id=46336

The assert added here breaks in the case where a pragma loop attribute is combined with a C++ attribute.

Resolved with
4676cf444ea2678660ee48279be99efde4bf60e9
8c6c606cdc72c3ddd55f382d91ef1afc3cb9f2a8