[llvm] r340518 - TableGen/SearchableTables: Cast enums to unsigned in generated code
Nicolai Haehnle via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 23 01:02:03 PDT 2018
Author: nha
Date: Thu Aug 23 01:02:02 2018
New Revision: 340518
URL: http://llvm.org/viewvc/llvm-project?rev=340518&view=rev
Log:
TableGen/SearchableTables: Cast enums to unsigned in generated code
Summary:
This should fix signedness warnings when compiling with MSVC.
Change-Id: I4664cce0ba91e9b42d21a86fd4a7e82f2320c451
Reviewers: RKSimon
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D51097
Modified:
llvm/trunk/utils/TableGen/SearchableTableEmitter.cpp
Modified: llvm/trunk/utils/TableGen/SearchableTableEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/SearchableTableEmitter.cpp?rev=340518&r1=340517&r2=340518&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/SearchableTableEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/SearchableTableEmitter.cpp Thu Aug 23 01:02:02 2018
@@ -430,6 +430,15 @@ void SearchableTableEmitter::emitLookupF
<< ").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";
More information about the llvm-commits
mailing list