[PATCH] D51097: TableGen/SearchableTables: Cast enums to unsigned in generated code
Nicolai Hähnle via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 22 04:28:45 PDT 2018
nhaehnle created this revision.
nhaehnle added a reviewer: RKSimon.
This should fix signedness warnings when compiling with MSVC.
Change-Id: I4664cce0ba91e9b42d21a86fd4a7e82f2320c451
Repository:
rL LLVM
https://reviews.llvm.org/D51097
Files:
utils/TableGen/SearchableTableEmitter.cpp
Index: utils/TableGen/SearchableTableEmitter.cpp
===================================================================
--- utils/TableGen/SearchableTableEmitter.cpp
+++ utils/TableGen/SearchableTableEmitter.cpp
@@ -430,6 +430,15 @@
<< ").compare(RHS." << Field.Name << ");\n";
OS << " if (Cmp" << Field.Name << " < 0) return true;\n";
OS << " if (Cmp" << Field.Name << " > 0) return false;\n";
+ } else if (Field.Enum) {
+ // Explicitly cast to unsigned, because the signedness of enums is
+ // compiler-dependent.
+ OS << " if ((unsigned)LHS." << Field.Name
+ << " < (unsigned)RHS." << Field.Name << ")\n";
+ OS << " return true;\n";
+ OS << " if ((unsigned)LHS." << Field.Name
+ << " > (unsigned)RHS." << Field.Name << ")\n";
+ OS << " return false;\n";
} else {
OS << " if (LHS." << Field.Name << " < RHS." << Field.Name << ")\n";
OS << " return true;\n";
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51097.161918.patch
Type: text/x-patch
Size: 995 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180822/68b1c65b/attachment.bin>
More information about the llvm-commits
mailing list