[PATCH] D27388: [bugpoint] Clean up type names at the very end

Keno Fischer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 3 20:24:46 PST 2016


loladiro created this revision.
loladiro added a reviewer: majnemer.
loladiro added a subscriber: llvm-commits.

When we roundtrip through bitcode, type names end up duplicated, so
types get renamed, causing very long chains of numbers at the end.
We could fix this by using a separate context for each step, but that
is a decently large change, and would also be slower. Instead, just
insert a post process step to try to rename types to something shorter.


https://reviews.llvm.org/D27388

Files:
  tools/bugpoint/CrashDebugger.cpp


Index: tools/bugpoint/CrashDebugger.cpp
===================================================================
--- tools/bugpoint/CrashDebugger.cpp
+++ tools/bugpoint/CrashDebugger.cpp
@@ -1043,6 +1043,24 @@
   return Error::success();
 }
 
+static void DoTypeNameCleanup(Module *M) {
+  // When we roundtrip types through bitcode, those end up being not unique,
+  // so they get renamed, causing really long chains of type.123.234.342.etc.
+  // Instead of this, find the part of the name that is not just numbers and use
+  // that as the type name.
+  std::vector<StructType *> Types = M->getIdentifiedStructTypes();
+  for (StructType *T : Types) {
+    StringRef Name = T->getName();
+    // Count the number of characters that are either dots or numbers from the
+    // end.
+    const uint8_t *cur, *end;
+    cur = end = Name.bytes_end() - 1;
+    while (cur > Name.bytes_begin() && (*cur == '.' || isdigit(*cur)))
+      --cur;
+    T->setName(Name.drop_back(end - cur));
+  }
+}
+
 /// DebugACrash - Given a predicate that determines whether a component crashes
 /// on a program, try to destructively reduce the program while still keeping
 /// the predicate true.
@@ -1184,6 +1202,15 @@
     // Find out if the pass still crashes on the cleaned up program...
     if (TestFn(BD, M)) {
       BD.setNewProgram(M); // Yup, it does, keep the reduced version...
+
+      // Bugpoints makes a mess of type names. Try to clean them up.
+      DoTypeNameCleanup(M);
+
+      // In principle something could depend on names, I suppose
+      if (!TestFn(BD, M)) {
+        return make_error<StringError>("Cleaning up type names hides bug",
+                                       inconvertibleErrorCode());
+      }
     } else {
       delete M;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27388.80196.patch
Type: text/x-patch
Size: 1757 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161204/8551672f/attachment.bin>


More information about the llvm-commits mailing list