[llvm] r238186 - [TableGen] Rewrite an assert to not do a bunch unsigned math and then try to ensure the result is a positive number.

Craig Topper craig.topper at gmail.com
Tue May 26 01:07:50 PDT 2015


Author: ctopper
Date: Tue May 26 03:07:49 2015
New Revision: 238186

URL: http://llvm.org/viewvc/llvm-project?rev=238186&view=rev
Log:
[TableGen] Rewrite an assert to not do a bunch unsigned math and then try to ensure the result is a positive number.

I think the fact that it was explicitly excluding 0 kept this from being a tautology. The exclusion of 0 for the old math was also a bug that's easily hit if the description gets split into multiple lines.

Modified:
    llvm/trunk/lib/TableGen/TableGenBackend.cpp

Modified: llvm/trunk/lib/TableGen/TableGenBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/TableGenBackend.cpp?rev=238186&r1=238185&r2=238186&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/TableGenBackend.cpp (original)
+++ llvm/trunk/lib/TableGen/TableGenBackend.cpp Tue May 26 03:07:49 2015
@@ -22,11 +22,11 @@ const size_t MAX_LINE_LEN = 80U;
 static void printLine(raw_ostream &OS, const Twine &Prefix, char Fill,
                       StringRef Suffix) {
   size_t Pos = (size_t)OS.tell();
-  assert((MAX_LINE_LEN - Prefix.str().size() - Suffix.size() > 0) &&
+  assert((Prefix.str().size() + Suffix.size() <= MAX_LINE_LEN) &&
          "header line exceeds max limit");
   OS << Prefix;
-  const size_t e = MAX_LINE_LEN - Suffix.size();
-  for (size_t i = (size_t)OS.tell() - Pos; i < e; ++i)
+  for (size_t i = (size_t)OS.tell() - Pos, e = MAX_LINE_LEN - Suffix.size();
+         i < e; ++i)
     OS << Fill;
   OS << Suffix << '\n';
 }





More information about the llvm-commits mailing list