Skip to content

[clang-format] Misannotation of annotated function names #70603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
HazardyKnusperkeks opened this issue Oct 29, 2023 · 5 comments
Closed

[clang-format] Misannotation of annotated function names #70603

HazardyKnusperkeks opened this issue Oct 29, 2023 · 5 comments
Labels
clang-format question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

Comments

@HazardyKnusperkeks
Copy link
Contributor

Taken from #69325:
ANNOTATE() void foo(); will be annotated as:

AnnotatedTokens(L=0, P=0, T=5, C=0):
 M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=identifier L=8 PPK=2 FakeLParens= FakeRParens=0 II=0x561bf7af7110 Text='ANNOTATE'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=23 Name=l_paren L=9 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
 M=0 C=0 T=FunctionAnnotationRParen S=0 F=0 B=0 BK=0 P=140 Name=r_paren L=10 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'
 M=0 C=1 T=Unknown S=1 F=0 B=0 BK=0 P=23 Name=void L=15 PPK=2 FakeLParens= FakeRParens=0 II=0x561bf7abb610 Text='void'
 M=0 C=0 T=TrailingAnnotation S=1 F=0 B=0 BK=0 P=23 Name=identifier L=19 PPK=2 FakeLParens= FakeRParens=0 II=0x561bf7af7140 Text='foo'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=23 Name=l_paren L=20 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=140 Name=r_paren L=21 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=23 Name=semi L=22 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=';'

Obviously it shouldn't be TrailingAnnotation, but FunctionDeclarationName, if ANNOTATE is declared as AttributeMacros the annotation is:

AnnotatedTokens(L=0, P=0, T=5, C=0):
 M=0 C=0 T=AttributeMacro S=1 F=0 B=0 BK=0 P=0 Name=identifier L=8 PPK=2 FakeLParens= FakeRParens=0 II=0x564eba5a7f40 Text='ANNOTATE'
 M=0 C=0 T=AttributeLParen S=0 F=0 B=0 BK=0 P=23 Name=l_paren L=9 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
 M=0 C=0 T=AttributeRParen S=0 F=0 B=0 BK=0 P=140 Name=r_paren L=10 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'
 M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=23 Name=void L=15 PPK=2 FakeLParens= FakeRParens=0 II=0x564eba56bd80 Text='void'
 M=0 C=1 T=FunctionDeclarationName S=1 F=0 B=0 BK=0 P=80 Name=identifier L=19 PPK=2 FakeLParens= FakeRParens=0 II=0x564eba5a8138 Text='foo'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=23 Name=l_paren L=20 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=140 Name=r_paren L=21 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=23 Name=semi L=22 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=';'

Which gets that one right.
There are multiple questions here for me:

  1. What is the difference between an attribute and a function declaration? Just reducing it to one breaks 4 tests.
  2. Do we want to work an that, or wait until someone has a real issue with it?
  3. Should we allow (or even force?) a break between the AttributeRParen and the return type? The code from [clang-format] Incorrect formatting for annotated constrained functions #69325 is not nicely formatted with the AttributeMacros set.

@mydeveloperday @owenca @rymiel

@llvmbot
Copy link
Member

llvmbot commented Oct 29, 2023

@llvm/issue-subscribers-clang-format

Author: Björn Schäpers (HazardyKnusperkeks)

Taken from #69325: `ANNOTATE() void foo();` will be annotated as: ``` AnnotatedTokens(L=0, P=0, T=5, C=0): M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=identifier L=8 PPK=2 FakeLParens= FakeRParens=0 II=0x561bf7af7110 Text='ANNOTATE' M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=23 Name=l_paren L=9 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='(' M=0 C=0 T=FunctionAnnotationRParen S=0 F=0 B=0 BK=0 P=140 Name=r_paren L=10 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')' M=0 C=1 T=Unknown S=1 F=0 B=0 BK=0 P=23 Name=void L=15 PPK=2 FakeLParens= FakeRParens=0 II=0x561bf7abb610 Text='void' M=0 C=0 T=TrailingAnnotation S=1 F=0 B=0 BK=0 P=23 Name=identifier L=19 PPK=2 FakeLParens= FakeRParens=0 II=0x561bf7af7140 Text='foo' M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=23 Name=l_paren L=20 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='(' M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=140 Name=r_paren L=21 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')' M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=23 Name=semi L=22 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=';' ``` Obviously it shouldn't be `TrailingAnnotation`, but `FunctionDeclarationName`, if `ANNOTATE` is declared as `AttributeMacros` the annotation is: ``` AnnotatedTokens(L=0, P=0, T=5, C=0): M=0 C=0 T=AttributeMacro S=1 F=0 B=0 BK=0 P=0 Name=identifier L=8 PPK=2 FakeLParens= FakeRParens=0 II=0x564eba5a7f40 Text='ANNOTATE' M=0 C=0 T=AttributeLParen S=0 F=0 B=0 BK=0 P=23 Name=l_paren L=9 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='(' M=0 C=0 T=AttributeRParen S=0 F=0 B=0 BK=0 P=140 Name=r_paren L=10 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')' M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=23 Name=void L=15 PPK=2 FakeLParens= FakeRParens=0 II=0x564eba56bd80 Text='void' M=0 C=1 T=FunctionDeclarationName S=1 F=0 B=0 BK=0 P=80 Name=identifier L=19 PPK=2 FakeLParens= FakeRParens=0 II=0x564eba5a8138 Text='foo' M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=23 Name=l_paren L=20 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='(' M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=140 Name=r_paren L=21 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')' M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=23 Name=semi L=22 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=';' ``` Which gets that one right. There are multiple questions here for me:
  1. What is the difference between an attribute and a function declaration? Just reducing it to one breaks 4 tests.
  2. Do we want to work an that, or wait until someone has a real issue with it?
  3. Should we allow (or even force?) a break between the AttributeRParen and the return type? The code from #69325 is not nicely formatted with the AttributeMacros set.

@mydeveloperday @owenca @rymiel

@rymiel
Copy link
Member

rymiel commented Oct 30, 2023

What is the difference between an attribute and a function declaration?

Did you mean function annotation? The first case has a FunctionAnnotationRParen, I assume that's what you're referring to.

@HazardyKnusperkeks
Copy link
Contributor Author

What is the difference between an attribute and a function declaration?

Did you mean function annotation? The first case has a FunctionAnnotationRParen, I assume that's what you're referring to.

And the attributes have AttributeRParen. I raise the question what is the difference in

  1. C++ code generally.
  2. In clang-format annotations.

The examples for the function annotations in out tests and in #69325 the macros which get FunctionAnnotationRParens they are always macros which are in fact attributes. One difference is that the arguments to the attribute is not given within [[ ]], but in the following parenthesis.

Are there any function annotations, which are not attributes in reality? Should BreakAfterAttributes affect the annotations?

@owenca
Copy link
Contributor

owenca commented Nov 1, 2023

  1. What is the difference between an attribute and a function declaration annotation? Just reducing it to one breaks 4 tests.

I think function annotations are one type of attributes.

  1. Do we want to work an that, or wait until someone has a real issue with it?

I would wait.

  1. Should we allow (or even force?) a break between the AttributeRParen and the return type? The code from [clang-format] Incorrect formatting for annotated constrained functions #69325 is not nicely formatted with the AttributeMacros set.

We should leave it alone for now and let the user use Macros and BreakAfterAttributes as I suggested in #69325.

@HazardyKnusperkeks
Copy link
Contributor Author

Then we are done here. :)

@HazardyKnusperkeks HazardyKnusperkeks closed this as not planned Won't fix, can't repro, duplicate, stale Nov 10, 2023
@EugeneZelenko EugeneZelenko added the question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! label Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-format question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!
Projects
None yet
Development

No branches or pull requests

5 participants