]> git.ipfire.org Git - thirdparty/gcc.git/commit
c: c++: Add target_[version/clones] to decl diagnostics formatting.
authorAlfie Richards <alfie.richards@arm.com>
Wed, 28 May 2025 15:42:07 +0000 (15:42 +0000)
committerAlfie Richards <alfie.richards@arm.com>
Tue, 23 Sep 2025 09:47:43 +0000 (09:47 +0000)
commitc2c7fd312c243cca58395508a8b6f708410bbfed
treefd493322b7393df337de1e2381ee6f06d941a0fb
parentaeb9a43bbb2e92d5e4b93250785701d0e37355d9
c: c++: Add target_[version/clones] to decl diagnostics formatting.

Adds the target_version and target_clones attributes to diagnostic messages
for target_version semantics.

This is because the target_version/target_clones attributes affect the identity
of the decls, so need to be represented in diagnostics for them.

This also requires making maybe_print_whitespace available to c++ code so
we can control if whitespace is needed cosistantly between c and c++
diagnostics.

After this change diagnostics look like:

c:
```
test.c:6:8: error: redefinition of ‘foo [[target_version("sve")]]’
    6 | float  foo  () {return 1;}
      |        ^~~
test.c:3:8: note: previous definition of ‘foo [[target_version("sve")]]’ with type ‘float(void)’
    3 | float  foo  () {return 2;}
      |        ^~~
test.c:12:8: error: redefinition of ‘bar [[target_clones("sve")]]’
   12 | float  bar () {return 1;}
      |        ^~~
test.c:9:8: note: previous definition of ‘bar [[target_clones("sve")]]’ with type ‘float(void)’
    9 | float  bar () {return 2;}
      |        ^~~
```

c++:
```
test.cpp:6:8: error: redefinition of ‘float foo [[target_version("sve")]] ()’
    6 | float  foo  () {return 1;}
      |        ^~~
test.cpp:3:8: note: ‘float foo [[target_version("sve")]] ()’ previously defined here
    3 | float  foo  () {return 2;}
      |        ^~~
test.cpp:12:8: error: redefinition of ‘float bar [[target_clones("sve")]] ()’
   12 | float  bar () {return 1;}
      |        ^~~
test.cpp:9:8: note: ‘float bar [[target_clones("sve")]] ()’ previously defined here
    9 | float  bar () {return 2;}
      |        ^~~
```

This only affects targets which use target_version (aarch64 and riscv).

gcc/c-family/ChangeLog:

* c-pretty-print.cc (pp_c_function_target_version): New function.
(pp_c_function_target_clones): New function.
(pp_c_maybe_whitespace): Move to c-pretty-print.h.
* c-pretty-print.h (pp_c_function_target_version): New function.
(pp_c_function_target_clones): New function.
(pp_c_maybe_whitespace): Moved here from c-pretty-print.cc.

gcc/c/ChangeLog:

* c-objc-common.cc (c_tree_printer): Add printing of target_clone and
target_version in decl diagnostics.

gcc/cp/ChangeLog:

* cxx-pretty-print.h (pp_cxx_function_target_version): New macro.
(pp_cxx_function_target_clones): Ditto.
(pp_cxx_maybe_whitespace): Ditto.
* error.cc (dump_function_decl): Add printing of target_clone and
target_version in decl diagnostics.
gcc/c-family/c-pretty-print.cc
gcc/c-family/c-pretty-print.h
gcc/c/c-objc-common.cc
gcc/cp/cxx-pretty-print.h
gcc/cp/error.cc