Fix a bug in !subst where TableGen would go and resubstitute text it had
authorDavid Greene <greened@obbligato.org>
Mon, 21 Dec 2009 21:21:34 +0000 (21:21 +0000)
committerDavid Greene <greened@obbligato.org>
Mon, 21 Dec 2009 21:21:34 +0000 (21:21 +0000)
just substituted.  This could cause infinite looping in certain
pathological cases.

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

test/TableGen/subst2.td [new file with mode: 0644]
utils/TableGen/Record.cpp

diff --git a/test/TableGen/subst2.td b/test/TableGen/subst2.td
new file mode 100644 (file)
index 0000000..3366c9d
--- /dev/null
@@ -0,0 +1,15 @@
+// RUN: tblgen %s | FileCheck %s
+// CHECK: No subst
+// CHECK: No foo
+// CHECK: RECURSE foo
+
+class Recurse<string t> {
+  string Text = t;
+}
+
+class Text<string text> : 
+  Recurse<!subst("RECURSE", "RECURSE", !subst("NORECURSE", "foo", text))>;
+
+def Ok1 : Text<"No subst">;
+def Ok2 : Text<"No NORECURSE">;
+def Trouble : Text<"RECURSE NORECURSE">;
index 53f90146a75a239da9ff4535743bbe71cb3cd38b..542735e88b48aaa7b8dd94154a90ad609de0eaa5 100644 (file)
@@ -945,11 +945,13 @@ Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) {
         std::string Val = RHSs->getValue();
 
         std::string::size_type found;
+        std::string::size_type idx = 0;
         do {
-          found = Val.find(LHSs->getValue());
+          found = Val.find(LHSs->getValue(), idx);
           if (found != std::string::npos) {
             Val.replace(found, LHSs->getValue().size(), MHSs->getValue());
           }
+          idx = found +  MHSs->getValue().size();
         } while (found != std::string::npos);
 
         return new StringInit(Val);