https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121361

            Bug ID: 121361
           Summary: Some C++ diagnostic information only appears in text
                    sinks, not in SARIF
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: diagnostic, SARIF
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dmalcolm at gcc dot gnu.org
            Blocks: 116253
  Target Milestone: ---

Consider:

./xgcc -B. -S ../../src/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C
-std=c++20 -fdiagnostics-set-output=text:experimental-nesting=yes
-fdiagnostics-add-output=sarif -fconcepts-diagnostics-depth=3
../../src/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C: In function
‘int main()’:
../../src/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C:20:6: error: no
matching function for call to ‘pet(donkey)’
   20 |   pet(donkey{}); // { dg-error "no matching function for call to
'pet\\\(donkey\\\)'" }
      |   ~~~^~~~~~~~~~
  • there are 3 candidates
    • candidate 1: ‘template<class T>  requires  pettable<T> void pet(T)’
      ../../src/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C:15:6:
         15 | void pet(T);
            |      ^~~
      • template argument deduction/substitution failed:
        • constraints not satisfied
          • ../../src/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C: In
substitution of ‘template<class T>  requires  pettable<T> void pet(T) [with T =
donkey]’:
          • required from here
           
../../src/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C:20:6:   
               20 |   pet(donkey{}); // { dg-error "no matching function for
call to 'pet\\\(donkey\\\)'" }
                  |   ~~~^~~~~~~~~~
          • required for the satisfaction of ‘pettable<T>’ [with T = donkey]
           
../../src/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C:12:9:   
               12 | concept pettable = requires(T t) { t.pet(); };
                  |         ^~~~~~~~
          • in requirements with ‘T t’ [with T = donkey]
           
../../src/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C:12:20:   
               12 | concept pettable = requires(T t) { t.pet(); };
                  |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~
          • the required expression ‘t.pet()’ is invalid, because
           
../../src/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C:12:41:
               12 | concept pettable = requires(T t) { t.pet(); };
                  |                                    ~~~~~^~
            • error: ‘struct donkey’ has no member named ‘pet’
             
../../src/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C:12:38:
                 12 | concept pettable = requires(T t) { t.pet(); };
                    |                                    ~~^~~
    • candidate 2: ‘void pet(dog)’
      ../../src/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C:8:6:
          8 | void pet(dog);
            |      ^~~
      • no known conversion for argument 1 from ‘donkey’ to ‘dog’
        ../../src/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C:8:10:
            8 | void pet(dog);
              |          ^~~
    • candidate 3: ‘void pet(cat)’
      ../../src/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C:9:6:
          9 | void pet(cat);
            |      ^~~
      • no known conversion for argument 1 from ‘donkey’ to ‘cat’
        ../../src/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C:9:10:
            9 | void pet(cat);
              |          ^~~

versus saving the output as .sarif and then using sarif-replay (or viewing the
sarif output in an IDE).

I'm working on a patch to support nesting levels in sarif-replay, but in the
meantime, various parts of the output are entirely missing.  In the above
example, the following is missing from the text output when round-tripping
through sarif:

../../src/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C: In substitution
of ‘template<class T>  requires  pettable<T> void pet(T) [with T = donkey]’:
../../src/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C:20:6:   required
from here
   20 |   pet(donkey{}); // { dg-error "no matching function for call to
'pet\\\(donkey\\\)'" }
      |   ~~~^~~~~~~~~~
../../src/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C:12:9:   required
for the satisfaction of ‘pettable<T>’ [with T = donkey]
../../src/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C:12:20:   in
requirements with ‘T t’ [with T = donkey]


The issue is that in various information in the C++ frontend is emitted only
via the text starter:  cp_diagnostic_text_starter calls the following:

  maybe_print_instantiation_context (text_output);
  maybe_print_constexpr_context (text_output);
  maybe_print_constraint_context (text_output);

and the "const diagnostics::text_sink &text_output" is passed around in various
places.

We should somehow capture this information in the SARIF output (I'm not yet
sure how to best represent it there).  Perhaps the diagnostics subsystem needs
to provide additional hooks for the C++ FE to use, rather than tightly binding
this with text output.   (though, again, I'm not yet sure how)

Filing against c++ component, but really affects both c++ FE *and* the shared
diagnostics subsystem.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116253
[Bug 116253] RFE: support for nested diagnostics

Reply via email to