[PATCH] D124534: [clang] Add a diagnostic for line directive of a gnu extension

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 4 04:16:29 PDT 2022


aaron.ballman added a comment.

In D124534#3490098 <https://reviews.llvm.org/D124534#3490098>, @ken-matsui wrote:

> @aaron.ballman
>
>> If so, I think putting Diag after the call of this function would be better.
>
> With the above change, I tried to add comments to failed tests, but there were over 300 files.
>
> During my investigation, I found most tests printed warnings without file information strangely.
>
>   error: 'warning' diagnostics seen but not expected: 
>     Line 0: this style of line directive is a GNU extension
>     Line 0: this style of line directive is a GNU extension
>   2 errors generated.

That is rather unexpected.

> If warnings have file information, it should be like:
>
>   error: 'warning' diagnostics seen but not expected: 
>     File /tmp/llvm-project/clang/test/Preprocessor/line-directive.c Line 9: this style of line directive is a GNU extension
>   1 error generated.
>
> Even tests that completely do not use preprocessor directives, such as `clang/test/SemaCXX/matrix-type.cpp`, failed with the above strange warnings.
>
> Thus, I suspect that the warnings without file paths have come from internally included SDK (I'm using macOS that includes `/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk`) or something that is not related to target test files.
>
> What do you think?

The tests run in -cc1 mode and don't #include anything, so I don't think the issue is an internally included SDK. I think the issue could be from this: https://github.com/llvm/llvm-project/blob/main/clang/lib/Frontend/InitPreprocessor.cpp#L1355 and https://github.com/llvm/llvm-project/blob/main/clang/lib/Frontend/InitPreprocessor.cpp#L1368. You may have to hook up to a debugger to see why we're issuing those surprising warnings. If it turns out that it's these inserted directives, you may have to look at the source location of the digit token to see if `isWrittenInBuiltinFile()` is true or not (and we may need to also check `isWrittenInScratchSpace()` as well, perhaps).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124534/new/

https://reviews.llvm.org/D124534



More information about the cfe-commits mailing list