diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp --- a/llvm/lib/TableGen/Record.cpp +++ b/llvm/lib/TableGen/Record.cpp @@ -856,14 +856,19 @@ const StringInit *Delim) { if (List->size() == 0) return StringInit::get(""); - SmallString<80> Result(cast(List->getElement(0))->getValue()); + StringInit *Element = dyn_cast(List->getElement(0)); + if (!Element) + return nullptr; + SmallString<80> Result(Element->getValue()); StringInit::StringFormat Fmt = StringInit::SF_String; for (unsigned I = 1, E = List->size(); I < E; ++I) { Result.append(Delim->getValue()); - auto *StrInit = cast(List->getElement(I)); - Result.append(StrInit->getValue()); - Fmt = StringInit::determineFormat(Fmt, StrInit->getFormat()); + StringInit *Element = dyn_cast(List->getElement(I)); + if (!Element) + return nullptr; + Result.append(Element->getValue()); + Fmt = StringInit::determineFormat(Fmt, Element->getFormat()); } return StringInit::get(Result, Fmt); } @@ -872,14 +877,21 @@ const StringInit *Delim) { if (List->size() == 0) return StringInit::get(""); - SmallString<80> Result( - cast(List->getElement(0)->getCastTo(IntRecTy::get())) - ->getAsString()); + IntInit *Element = + dyn_cast_or_null(List->getElement(0) + ->convertInitializerTo(IntRecTy::get())); + if (!Element) + return nullptr; + SmallString<80> Result(Element->getAsString()); for (unsigned I = 1, E = List->size(); I < E; ++I) { Result.append(Delim->getValue()); - Result.append(cast(List->getElement(I)->getCastTo(IntRecTy::get())) - ->getAsString()); + IntInit *Element = + dyn_cast_or_null(List->getElement(I) + ->convertInitializerTo(IntRecTy::get())); + if (!Element) + return nullptr; + Result.append(Element->getAsString()); } return StringInit::get(Result); } @@ -975,10 +987,13 @@ ListInit *List = dyn_cast(LHS); StringInit *Delim = dyn_cast(RHS); if (List && Delim) { + StringInit *Result; if (isa(List->getElementType())) - return interleaveStringList(List, Delim); + Result = interleaveStringList(List, Delim); else - return interleaveIntList(List, Delim); + Result = interleaveIntList(List, Delim); + if (Result) + return Result; } break; } diff --git a/llvm/test/TableGen/interleave.td b/llvm/test/TableGen/interleave.td --- a/llvm/test/TableGen/interleave.td +++ b/llvm/test/TableGen/interleave.td @@ -77,6 +77,15 @@ code OperatorList = !interleave(!listconcat(Operators, [[{;}]]), ", "); } +// CHECK: def Rec7 +// CHECK: str = "foo/bar/zoo"; + +def Rec7 { + string foo = "foo"; + string zoo = "oops, not zoo"; + string str = !interleave([foo, "bar", zoo], "/"); + let zoo = "zoo"; +} #ifdef ERROR1 def op;