[PATCH] D159490: Fix warning in MSVC

Giuliano Belinassi via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 8 15:58:29 PDT 2023


giulianobelinassi created this revision.
giulianobelinassi added reviewers: aaron.ballman, erichkeane.
Herald added a project: All.
giulianobelinassi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Currently there is no `PrintOnLeft` attribute set, which results in an
empty switch-case. When compiling this, MSVC issues a warning saying
that the switch-case is empty. Fix this by using a macro and checking
if this macro is defined or not.

Links to D157394 <https://reviews.llvm.org/D157394>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D159490

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/utils/TableGen/ClangAttrEmitter.cpp


Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===================================================================
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3217,6 +3217,8 @@
 
   std::vector<Record *> Attrs = Records.getAllDerivedDefinitions("Attr");
   std::vector<Record *> PragmaAttrs;
+  bool first = false;
+
   for (auto *Attr : Attrs) {
     if (!Attr->getValueAsBit("ASTNode"))
       continue;
@@ -3224,8 +3226,15 @@
     if (!Attr->getValueAsBit(FieldName))
       continue;
 
-    OS << "case attr::" << Attr->getName() << ":\n";
+    if (!first) {
+      first = true;
+      OS << "#define CLANG_ATTR_LIST_" << FieldName;
+    }
+
+    OS << " \\\n case attr::" << Attr->getName() << ":";
   }
+
+  OS << '\n';
 }
 
 // Emits the enumeration list for attributes.
Index: clang/lib/AST/DeclPrinter.cpp
===================================================================
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -250,13 +250,23 @@
   return Out;
 }
 
+// For CLANG_ATTR_LIST_CanPrintOnLeft macro.
+#include "clang/Basic/AttrLeftSideCanPrintList.inc"
+
+// For CLANG_ATTR_LIST_PrintOnLeft macro.
+#include "clang/Basic/AttrLeftSideMustPrintList.inc"
+
 static bool canPrintOnLeftSide(attr::Kind kind) {
+#ifdef CLANG_ATTR_LIST_CanPrintOnLeft
   switch (kind) {
-#include "clang/Basic/AttrLeftSideCanPrintList.inc"
+  CLANG_ATTR_LIST_CanPrintOnLeft
     return true;
   default:
     return false;
   }
+#else
+  return false;
+#endif
 }
 
 static bool canPrintOnLeftSide(const Attr *A) {
@@ -268,11 +278,16 @@
 
 static bool mustPrintOnLeftSide(attr::Kind kind) {
   switch (kind) {
-#include "clang/Basic/AttrLeftSideMustPrintList.inc"
+#ifdef CLANG_ATTR_LIST_PrintOnLeft
+  switch (kind) {
+  CLANG_ATTR_LIST_PrintOnLeft
     return true;
   default:
     return false;
   }
+#else
+  return false;
+#endif
 }
 
 static bool mustPrintOnLeftSide(const Attr *A) {
@@ -314,7 +329,6 @@
                    VD->getInitStyle() == VarDecl::CallInit)
           AttrLoc = AttrPrintLoc::Left;
       }
-
       // Only print the side matches the user requested.
       if ((Loc & AttrLoc) != AttrPrintLoc::None)
         A->printPretty(Out, Policy);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159490.556321.patch
Type: text/x-patch
Size: 2239 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230908/795a1e03/attachment.bin>


More information about the cfe-commits mailing list