This is an archive of the discontinued LLVM Phabricator instance.

[clang-cl][MSVC] Map /external:Wn n=1-4 to -Wsystem-headers
ClosedPublic

Authored by steplong on Jun 9 2022, 3:36 PM.

Diff Detail

Event Timeline

steplong created this revision.Jun 9 2022, 3:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 9 2022, 3:36 PM
steplong requested review of this revision.Jun 9 2022, 3:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 9 2022, 3:36 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

I don't think /external:Wn behaves exactly like -Wsystem-headers. /external:Wn applies /Wn to the system headers, while -Wsystem-headers applies whatever is on the command line to the system headers. I think /external:Wn behaves more like:

// foo.c
#pragma clang diagnostic push
#pragma clang diagnostic warning "-Wall"
#include <foo.h>
#pragma clang diagnostic pop


void foo() {
  int i = 10;
}
// foo.h
void bar() {
   int i = 11;
}

Passing -Wno-unused-variables only suppresses the warnings for the rest of foo.c. It looks like the pragma is calling setSeverityForGroup(diag::Flavor::WarningOrError, "-Wall", diag::Serverity::Warning, Loc), but I'm not sure where we can detect that we are including a system header.

hans added a comment.Jun 10 2022, 6:03 AM

Right, this is not the same, but I suppose it's better than ignoring the flag.

clang/include/clang/Driver/Options.td
6480

should we map it to -Wno-system-headers?

clang/test/Driver/cl-zc.cpp
106 ↗(On Diff #435710)

This is not the right test file, cl-zc.cpp is for testing /Zc flags.
I don't think we have a special file for clang-cl warning flags, so clang/test/Driver/cl-options.c would be the file to use.

steplong added inline comments.Jun 10 2022, 6:38 AM
clang/test/Driver/cl-zc.cpp
106 ↗(On Diff #435710)

Oh whoops, I think I added some /kernel tests here too for D126719

steplong updated this revision to Diff 435901.Jun 10 2022, 6:55 AM
  • Move tests to cl-options.c
  • Map /external:W0 to -Wno-system-headers
steplong edited the summary of this revision. (Show Details)Jun 10 2022, 6:55 AM
hans accepted this revision.Jun 10 2022, 7:17 AM

lgtm

clang/include/clang/Driver/Options.td
6480

For the help text, the "with -Wno-system-headers" part seems redundant.
How about:

Ignore warnings from system headers (default)

This revision is now accepted and ready to land.Jun 10 2022, 7:17 AM
steplong updated this revision to Diff 435910.Jun 10 2022, 7:31 AM
  • Change helptext for /external:W0

Hmm do you know how I can restart the pre-merge checks? It looks like the x64 debian openmp tests failed. I don't think this patch is related, but I want to make sure

hans added a comment.Jun 13 2022, 7:09 AM

Hmm do you know how I can restart the pre-merge checks? It looks like the x64 debian openmp tests failed. I don't think this patch is related, but I want to make sure

You can rebase and upload the patch again. But those bots are pretty flaky, I don't think it's related to this patch either.

steplong updated this revision to Diff 436394.Jun 13 2022, 7:53 AM
  • Rebase patch
This revision was landed with ongoing or failed builds.Jun 13 2022, 11:26 AM
This revision was automatically updated to reflect the committed changes.