This is an archive of the discontinued LLVM Phabricator instance.

[libclang] Expose arguments of clang::annotate
ClosedPublic

Authored by fridtjof on May 24 2023, 1:48 PM.

Details

Summary

This enables easy consumption of arbitrary data added
to this annotation in addition to the annotation category,
which was already exposed.

Diff Detail

Event Timeline

fridtjof created this revision.May 24 2023, 1:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2023, 1:48 PM
Herald added a subscriber: arphaman. · View Herald Transcript
fridtjof requested review of this revision.May 24 2023, 1:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 24 2023, 1:48 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Thank you for the additions! This should have test coverage in clang/unitttests/libclang/LibclangTest.cpp and a release note.

clang/tools/libclang/CIndex.cpp
2752

We could use a template type and enable_if (for some type safety), then it shares the implementation.

fridtjof updated this revision to Diff 530219.EditedJun 10 2023, 9:12 AM
  • Deduplicated code by using templates (looks a bit ridiculous though)
  • Release notes entry added
  • Unit test added

I think precommit CI may have found a relevant failure:

******************** TEST 'Clang :: Index/IBOutletCollection.m' FAILED ********************
Script:
--
: 'RUN: at line 8';   c:\ws\w5\llvm-project\premerge-checks\build\bin\c-index-test.exe -cursor-at=C:\ws\w5\llvm-project\premerge-checks\clang\test\Index\IBOutletCollection.m:4:24 C:\ws\w5\llvm-project\premerge-checks\clang\test\Index\IBOutletCollection.m | c:\ws\w5\llvm-project\premerge-checks\build\bin\filecheck.exe -check-prefix=CHECK-CURSOR C:\ws\w5\llvm-project\premerge-checks\clang\test\Index\IBOutletCollection.m
: 'RUN: at line 11';   c:\ws\w5\llvm-project\premerge-checks\build\bin\c-index-test.exe -test-annotate-tokens=C:\ws\w5\llvm-project\premerge-checks\clang\test\Index\IBOutletCollection.m:4:1:5:1 C:\ws\w5\llvm-project\premerge-checks\clang\test\Index\IBOutletCollection.m | c:\ws\w5\llvm-project\premerge-checks\build\bin\filecheck.exe -check-prefix=CHECK-TOK C:\ws\w5\llvm-project\premerge-checks\clang\test\Index\IBOutletCollection.m
--
Exit Code: 1
 
Command Output (stdout):
--
$ ":" "RUN: at line 8"
$ "c:\ws\w5\llvm-project\premerge-checks\build\bin\c-index-test.exe" "-cursor-at=C:\ws\w5\llvm-project\premerge-checks\clang\test\Index\IBOutletCollection.m:4:24" "C:\ws\w5\llvm-project\premerge-checks\clang\test\Index\IBOutletCollection.m"
$ "c:\ws\w5\llvm-project\premerge-checks\build\bin\filecheck.exe" "-check-prefix=CHECK-CURSOR" "C:\ws\w5\llvm-project\premerge-checks\clang\test\Index\IBOutletCollection.m"
# command stderr:
C:\ws\w5\llvm-project\premerge-checks\clang\test\Index\IBOutletCollection.m:9:18: error: CHECK-CURSOR: expected string not found in input
// CHECK-CURSOR: ObjCClassRef=Test:3:12
                 ^
<stdin>:1:1: note: scanning from here
4:3 attribute(iboutletcollection)= [IBOutletCollection=ObjCInterface] Extent=[4:3 - 4:27]
^
<stdin>:1:54: note: possible intended match here
4:3 attribute(iboutletcollection)= [IBOutletCollection=ObjCInterface] Extent=[4:3 - 4:27]
                                                     ^
 
Input file: <stdin>
Check file: C:\ws\w5\llvm-project\premerge-checks\clang\test\Index\IBOutletCollection.m
 
-dump-input=help explains the following input dump.
 
Input was:
<<<<<<
           1: 4:3 attribute(iboutletcollection)= [IBOutletCollection=ObjCInterface] Extent=[4:3 - 4:27]
check:9'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
check:9'1                                                          ?                                     possible intended match
>>>>>>
 
error: command failed with exit status: 1
 
--
 
********************
clang/unittests/libclang/LibclangTest.cpp
1176

Spurious comment?

1178

We don't seem to be testing this?

fridtjof updated this revision to Diff 544142.Jul 25 2023, 4:29 PM

I fixed the failing IBOutletCollection.m test - there was code to do special handling for the respective attribute type, which my patch accidentally skipped previously. I reordered the generic attribute handling to come after the special cases in VisitChildren.

I cleaned up my unit test. After trying a bit to fix it for testing annotate_type as well, I found out that for some unknown reason it is not exposed like usual attributes (maybe because it's a type attribute?).
Therefore, I decided to drop it from the test altogether.

I fixed the failing IBOutletCollection.m test - there was code to do special handling for the respective attribute type, which my patch accidentally skipped previously. I reordered the generic attribute handling to come after the special cases in VisitChildren.

Nice!

I cleaned up my unit test. After trying a bit to fix it for testing annotate_type as well, I found out that for some unknown reason it is not exposed like usual attributes (maybe because it's a type attribute?).
Therefore, I decided to drop it from the test altogether.

I think we should drop the annotate_type functionality from the patch entirely rather than add it without any test coverage knowing it doesn't seem to work as expected.

fridtjof updated this revision to Diff 545305.Jul 28 2023, 4:27 PM
fridtjof retitled this revision from [libclang] Expose arguments of clang::annotate{_type} to [libclang] Expose arguments of clang::annotate.
fridtjof edited the summary of this revision. (Show Details)
fridtjof edited the summary of this revision. (Show Details)

I think we should drop the annotate_type functionality from the patch entirely rather than add it without any test coverage knowing it doesn't seem to work as expected.

Agreed - I removed the superfluous code and also cleaned up the summary accordingly.

fridtjof updated this revision to Diff 545388.Jul 29 2023, 5:23 PM

Whoops, forgot to run clang-format on the last diff. Also took the opportunity to just get rid of the template mess now that we're only dealing with AnnotateAttr anyway.

aaron.ballman accepted this revision.Jul 31 2023, 6:23 AM

LGTM! Do you need me to commit this on your behalf? If so, what name and email address would you like me to use for patch attribution?

This revision is now accepted and ready to land.Jul 31 2023, 6:23 AM

(Whoops, somehow never got a mail for that reply)

Yes, please. You can attribute the commit to "fridtjof <fridtjof@das-labor.org>"

This revision was automatically updated to reflect the committed changes.
vitalybuka added inline comments.
clang/tools/libclang/CIndex.cpp
3656
vitalybuka reopened this revision.Aug 10 2023, 3:21 PM
This revision is now accepted and ready to land.Aug 10 2023, 3:21 PM

Not sure why the similar code above does not leak, so I will revert and leave to author to investigate

vitalybuka added inline comments.Aug 10 2023, 3:31 PM
clang/tools/libclang/CIndex.cpp
3656

Please ignore the location of this comment.
I don't know which part of the patch is responsible for the leak
Another trace here https://lab.llvm.org/buildbot/#/builders/236/builds/5562/steps/13/logs/stdio

fridtjof updated this revision to Diff 549197.Aug 10 2023, 4:34 PM

It was the unit test I added - I forgot to properly dispose of the EvalResult there

This revision was automatically updated to reflect the committed changes.

It was the unit test I added - I forgot to properly dispose of the EvalResult there

I've re-landed the changes in 177ec17944af5fb87445017c3ac9028bbc1d710f, thank you!