-fdiagnostics-format= I have a quesiton about -fshow-column

I updated the -fdiagnostics-format implementation based on the feedback, and added a test case. When adding support for columns for msvc I ran into the issue that -fshow-column was not supported, as implied by the documentation, so I had to also fix that in the patch. I added -fshow-column to the test case, since it was obviously missing.

The default behavior for -fms-extensions folks is the same as before.

**-fdiagnostics-format=clang/msvc/vi**: Changes diagnostic output format to better match IDEs and command line tools.
This option controls the output format of the filename, line number, and column printed in diagnostic messages. The default for this option is clang. If ifms-extensions is set then the default is changed to msvc and -fno-show-column is also set.

For example, a format string warning will produce these three renditions based on the setting of this option, the fourth rendition shows default output when -fms-extensions is set:

  t.c:3:11: warning: conversion specifies type 'char *' but the argument has type 'int'
  t.c(3,11) : warning: conversion specifies type 'char *' but the argument has type 'int'  
  t.c +3:11: warning: conversion specifies type 'char *' but the argument has type 'int' 
  t.c(3) : warning: conversion specifies type 'char *' but the argument has type 'int'  

In this code from ParseDiagnosticArgs():

if (Args.hasArg(OPT_fms_extensions)) {
Opts.Format = DiagnosticOptions::Msvc;
Opts.ShowColumn = Args.hasArg(OPT_fshow_column);
} else
Opts.Format = DiagnosticOptions::Clang;

The call to Args.hasArg(OPT_fshow_column) always seems to return 0? Does this mean I did not add -fshow-column correctly?

This works as expected:

/Users/fish/work/Clang2/build/Release/bin/clang -fsyntax-only -ccc-host-triple x86_64-pc-win32 diag-format.c
diag-format.c(28) : warning: extra tokens at end of #endif directive [-Wextra-tokens]
#endif bad // extension!
^
//
1 warning generated.

This works:

/Users/fish/work/Clang2/build/Release/bin/clang -fsyntax-only -fdiagnostics-format=msvc -ccc-host-triple x86_64-pc-win32 diag-format.c
diag-format.c(28,7) : warning: extra tokens at end of #endif directive [-Wextra-tokens]
#endif bad // extension!
^
//
1 warning generated.

This one does not:

/Users/fish/work/Clang2/build/Release/bin/clang -fsyntax-only -ccc-host-triple x86_64-pc-win32 -fshow-column diag-format.c
diag-format.c(28) : warning: extra tokens at end of #endif directive [-Wextra-tokens]
#endif bad // extension!
^
//
1 warning generated.

So what am I missing?

Andrew Fish

fdiagnostics-formant.patch (10.2 KB)

hasFlag() is far better than hasArg() for what you’re doing, since it handles both the positive (-fshow-column) and negative (-fno-show-column) arguments in one command. For example, I switched the ShowColumn computation to this:

Opts.ShowColumn = Args.hasFlag(OPT_fshow_column,
OPT_fno_show_column,
/Default=/true);

I committed a slightly-tweaked version of your patch as Clang r131794, where I also got rid of the dependence on -fms-extensions. Thanks so much for working on this!

  • Doug