[PATCH] D110668: [clang-cl] Accept `#pragma warning(disable : N)` for some N

Nico Weber via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 28 16:46:03 PDT 2021


thakis created this revision.
thakis added a reviewer: hans.
thakis added a project: clang.
Herald added subscribers: dexonsmith, dang, mgorny.
thakis requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

clang-cl maps /wdNNNN to -Wno-flags for a few warnings that map
cleanly from cl.exe concepts to clang concepts.

This patch adds support for the same numbers to
`#pragma warning(disable : NNNN)`. It also lets
`#pragma warning(push)` and `#pragma warning(pop)` have an effect,
since these are used together with `warning(disable)`.

The optional numeric argument to `warning(push)` is ignored,
as are the other non-`disable` `pragma warning()` arguments.
(Supporting `error` would be easy, but we also don't support
`/we`, and those should probably be added together.)

The motivating example is that a bunch of code (including in LLVM)
uses this idiom to locally disable warnings about calls to deprecated
functions in Windows-only code, and 4996 maps nicely to
-Wno-deprecated-declarations:

  #pragma warning(push)
  #pragma warning(disable: 4996)
    f();
  #pragma warning(pop)

Implementation-wise:

- Move `/wd` flag handling from Options.td to actual Driver-level code
- Extract the function mapping cl.exe IDs to warning groups to the new file clang/lib/Basic/CLWarnings.cpp
- Call that new function from the PragmaWarning handler


https://reviews.llvm.org/D110668

Files:
  clang/include/clang/Basic/CLWarnings.h
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/CLWarnings.cpp
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Lex/Pragma.cpp
  clang/test/Driver/cl-options.c
  clang/test/Sema/pragma-warning.cpp
  llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110668.375737.patch
Type: text/x-patch
Size: 8413 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210928/c4da56b5/attachment.bin>


More information about the cfe-commits mailing list