flang icon indicating copy to clipboard operation
flang copied to clipboard

Q: Compiler message structure for VS Code integration

Open gnikit opened this issue 3 years ago • 0 comments

Hi all,

We are finally getting around to adding linting support for flang in VS Code Modern Fortran . How we achieve that is through a syntax only compilation of the files with -fsyntax-only and then using regex we extract the relevant parts from stdout/stderr. For that we need to have a good understanding of the structure of the compiler messages, e.g. warnings, errors, fatal errors,etc. .

Hence, I was wondering if you could point me to a resource or provide an outline for flang's compiler output. Here is an example of what I am looking for from Intel's (ifort) compiler. Similarly, for gfortran most compiler messages fit this pattern:

filename:line:column:
      
  line |  failing line of code
       |
severity: message

Using the following MWE as a testbed

program main

  call say_hello(1, 1)

contains

  subroutine say_hello(a,b)
    integer :: a,b

    print *, "Hello, World!"
  end subroutine say_hello

end program main

and compiling with flang -Wall -fsyntax-only sample.f90 I would expect some warnings to be raised for the unused variables a and b but only a warning is thrown for -Wall being unused. Am I missing something?

Replacing call say_hello(1,1) in the above MWE with call say_hello() to raise a compile time error yields the message:

F90-S-0186-Argument missing for formal argument a (sample.f90: 3)
  0 inform,   0 warnings,   1 severes, 0 fatal for main

This message we can work with, but is there a way to also get the column number where the error occurred?

On a related note, I understand that there are effectively 2 flang compilers this one and formerly known f18 which is now a part of the llvm-project. Do you know if the compiler output from f18 is different from this repos flang output and if so, how? Again, any links to docs would be greatly appreciated.

Additional information

flang --version

output:

clang version 7.0.1 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

gnikit avatar Nov 22 '21 12:11 gnikit