[TableGen] Rewrite an assert to not do a bunch unsigned math and then try to ensure...
authorCraig Topper <craig.topper@gmail.com>
Tue, 26 May 2015 08:07:49 +0000 (08:07 +0000)
committerCraig Topper <craig.topper@gmail.com>
Tue, 26 May 2015 08:07:49 +0000 (08:07 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238186 91177308-0d34-0410-b5e6-96231b3b80d8

lib/TableGen/TableGenBackend.cpp

index 9763f85c79348770d0633bb4d3be262dea77893d..43f8cb089ec62ad091141b40fe96b2c41db096e3 100644 (file)
@@ -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';
 }