[PATCH] D103885: [clang] Suppress warnings for tautological comparison in generated macro code

Joachim Protze via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 8 04:05:34 PDT 2021


protze.joachim created this revision.
protze.joachim added reviewers: jdoerfert, aaron.ballman, hokein.
protze.joachim added projects: clang, clang-tools-extra.
Herald added subscribers: usaxena95, kadircet, arphaman, hiraditya.
protze.joachim requested review of this revision.
Herald added subscribers: cfe-commits, llvm-commits.
Herald added a project: LLVM.

The warnings for some of the generated and included files can quickly fill pages and might hide serious issues. The macro purposely performs tautological comparison to filter those cases. Filtering the warning for the respective code regions seems a reasonable approach.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103885

Files:
  clang-tools-extra/clangd/CompileCommands.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  llvm/lib/Frontend/OpenMP/OMPContext.cpp


Index: llvm/lib/Frontend/OpenMP/OMPContext.cpp
===================================================================
--- llvm/lib/Frontend/OpenMP/OMPContext.cpp
+++ llvm/lib/Frontend/OpenMP/OMPContext.cpp
@@ -58,6 +58,10 @@
     break;
   }
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wtautological-compare"
+  // The generated code is expected to generate tautological comparison
+
   // Add the appropriate device architecture trait based on the triple.
 #define OMP_TRAIT_PROPERTY(Enum, TraitSetEnum, TraitSelectorEnum, Str)         \
   if (TraitSelector::TraitSelectorEnum == TraitSelector::device_arch) {        \
@@ -68,6 +72,7 @@
       ActiveTraits.set(unsigned(TraitProperty::Enum));                         \
   }
 #include "llvm/Frontend/OpenMP/OMPKinds.def"
+#pragma clang diagnostic pop
 
   // TODO: What exactly do we want to see as device ISA trait?
   //       The discussion on the list did not seem to have come to an agreed
Index: clang/lib/Sema/SemaCodeComplete.cpp
===================================================================
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -6227,12 +6227,17 @@
                         &ResultBuilder::IsType);
   Results.EnterNewScope();
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wtautological-compare"
+  // The generated code is expected to generate tautological comparison
+
   // Add the names of overloadable operators. Note that OO_Conditional is not
   // actually overloadable.
 #define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly)  \
   if (OO_##Name != OO_Conditional)                                             \
     Results.AddResult(Result(Spelling));
 #include "clang/Basic/OperatorKinds.def"
+#pragma clang diagnostic pop
 
   // Add any type names visible from the current scope
   Results.allowNestedNameSpecifiers();
Index: clang-tools-extra/clangd/CompileCommands.cpp
===================================================================
--- clang-tools-extra/clangd/CompileCommands.cpp
+++ clang-tools-extra/clangd/CompileCommands.cpp
@@ -352,6 +352,10 @@
     };
     // Also grab prefixes for each option, these are not fully exposed.
     const char *const *Prefixes[DriverID::LastOption] = {nullptr};
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wtautological-compare"
+    // the generated code is expected to generate tautological comparison
 #define PREFIX(NAME, VALUE) static const char *const NAME[] = VALUE;
 #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM,  \
                HELP, METAVAR, VALUES)                                          \
@@ -361,6 +365,7 @@
 #include "clang/Driver/Options.inc"
 #undef OPTION
 #undef PREFIX
+#pragma clang diagnostic pop
 
     auto Result = std::make_unique<TableTy>();
     // Iterate over distinct options (represented by the canonical alias).


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103885.350569.patch
Type: text/x-patch
Size: 2944 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210608/faf0242d/attachment.bin>


More information about the cfe-commits mailing list