[PATCH] D157191: Improve dumps of attributes
Giuliano Belinassi via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 8 15:53:13 PDT 2023
giulianobelinassi updated this revision to Diff 556319.
giulianobelinassi added a comment.
Fix warning in MSVC
Summary:
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 D141714 <https://reviews.llvm.org/D141714>
Reviewers: aaron.ballman, erichkeane
Differential Revision: https://reviews.llvm.org/D157191
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D157191/new/
https://reviews.llvm.org/D157191
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: D157191.556319.patch
Type: text/x-patch
Size: 2239 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230908/b16a9c85/attachment-0001.bin>
More information about the cfe-commits
mailing list