[clang] 0323938 - Fix warning in MSVC
via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 11 06:51:44 PDT 2023
Author: Giuliano Belinassi
Date: 2023-09-11T06:51:11-07:00
New Revision: 0323938d3c7a1a48b60a7dea8ec7300e98b4a931
URL: https://github.com/llvm/llvm-project/commit/0323938d3c7a1a48b60a7dea8ec7300e98b4a931
DIFF: https://github.com/llvm/llvm-project/commit/0323938d3c7a1a48b60a7dea8ec7300e98b4a931.diff
LOG: Fix warning in MSVC
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
Added:
Modified:
clang/lib/AST/DeclPrinter.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index 834449ff1b999a0..397911894cc5d0d 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -250,13 +250,23 @@ raw_ostream& DeclPrinter::Indent(unsigned Indentation) {
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 canPrintOnLeftSide(const Attr *A) {
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 @@ void DeclPrinter::prettyPrintAttributes(Decl *D, llvm::raw_ostream &Out,
VD->getInitStyle() == VarDecl::CallInit)
AttrLoc = AttrPrintLoc::Left;
}
-
// Only print the side matches the user requested.
if ((Loc & AttrLoc) != AttrPrintLoc::None)
A->printPretty(Out, Policy);
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp
index ff6ffe16b4ccda9..7ea09058c3d39f2 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -3217,6 +3217,8 @@ void EmitClangAttrPrintList(const std::string &FieldName, RecordKeeper &Records,
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 @@ void EmitClangAttrPrintList(const std::string &FieldName, RecordKeeper &Records,
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.
More information about the cfe-commits
mailing list