[llvm-commits] [llvm] r91843 - in /llvm/trunk: test/TableGen/subst2.td utils/TableGen/Record.cpp

David Greene greened at obbligato.org
Mon Dec 21 13:21:35 PST 2009


Author: greened
Date: Mon Dec 21 15:21:34 2009
New Revision: 91843

URL: http://llvm.org/viewvc/llvm-project?rev=91843&view=rev
Log:

Fix a bug in !subst where TableGen would go and resubstitute text it had
just substituted.  This could cause infinite looping in certain
pathological cases.

Added:
    llvm/trunk/test/TableGen/subst2.td
Modified:
    llvm/trunk/utils/TableGen/Record.cpp

Added: llvm/trunk/test/TableGen/subst2.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/subst2.td?rev=91843&view=auto

==============================================================================
--- llvm/trunk/test/TableGen/subst2.td (added)
+++ llvm/trunk/test/TableGen/subst2.td Mon Dec 21 15:21:34 2009
@@ -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">;

Modified: llvm/trunk/utils/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/Record.cpp?rev=91843&r1=91842&r2=91843&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/Record.cpp (original)
+++ llvm/trunk/utils/TableGen/Record.cpp Mon Dec 21 15:21:34 2009
@@ -945,11 +945,13 @@
         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);





More information about the llvm-commits mailing list