llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

-fdiagnostics-show-line-numbers are off in -Wformat warnings

Open zmodem opened this issue 2 years ago • 0 comments

Consider:

$ cat -n /tmp/a.c
     1  #include <stdio.h>
     2
     3  void f(int x) {
     4    printf("%f",
     5           x);
     6  }

$ build/bin/clang -c /tmp/a.c
/tmp/a.c:5:10: warning: format specifies type 'double' but the argument has type 'int' [-Wformat]
    5 |   printf("%f",
      |           ~~
      |           %d
    6 |          x);
      |          ^
1 warning generated.

The diag location of a.c:5:10 is correct: it points to the x which is the argument in question.

However, the printed line numbers make it look like the printf starts on line 5 and the x is on line 6, which is not the case.

With -fno-diagnostics-show-line-numbers it looks correct:

$ build/bin/clang -c /tmp/a.c -fno-diagnostics-show-line-numbers
/tmp/a.c:5:10: warning: format specifies type 'double' but the argument has type 'int' [-Wformat]
  printf("%f",
          ~~
          %d
         x);
         ^
1 warning generated.

zmodem avatar Jun 26 '23 12:06 zmodem