forked from OSchip/llvm-project
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. llvm-svn: 91843
This commit is contained in:
parent
131420c5d7
commit
dbf7074296
|
@ -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">;
|
|
@ -945,11 +945,13 @@ Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) {
|
||||||
std::string Val = RHSs->getValue();
|
std::string Val = RHSs->getValue();
|
||||||
|
|
||||||
std::string::size_type found;
|
std::string::size_type found;
|
||||||
|
std::string::size_type idx = 0;
|
||||||
do {
|
do {
|
||||||
found = Val.find(LHSs->getValue());
|
found = Val.find(LHSs->getValue(), idx);
|
||||||
if (found != std::string::npos) {
|
if (found != std::string::npos) {
|
||||||
Val.replace(found, LHSs->getValue().size(), MHSs->getValue());
|
Val.replace(found, LHSs->getValue().size(), MHSs->getValue());
|
||||||
}
|
}
|
||||||
|
idx = found + MHSs->getValue().size();
|
||||||
} while (found != std::string::npos);
|
} while (found != std::string::npos);
|
||||||
|
|
||||||
return new StringInit(Val);
|
return new StringInit(Val);
|
||||||
|
|
Loading…
Reference in New Issue