Skip to content

Commit 6c8ded0

Browse files
committed
[TableGen] Don't dereference from dyn_cast<> - use cast<> instead. NFCI.
dyn_cast<> can return null if the cast fails, resulting in null dereferences and static analyzer warnings. We should use cast<> instead.
1 parent 5a02bf4 commit 6c8ded0

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

llvm/lib/TableGen/Record.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -856,12 +856,12 @@ static StringInit *interleaveStringList(const ListInit *List,
856856
const StringInit *Delim) {
857857
if (List->size() == 0)
858858
return StringInit::get("");
859-
SmallString<80> Result(dyn_cast<StringInit>(List->getElement(0))->getValue());
859+
SmallString<80> Result(cast<StringInit>(List->getElement(0))->getValue());
860860
StringInit::StringFormat Fmt = StringInit::SF_String;
861-
861+
862862
for (unsigned I = 1, E = List->size(); I < E; ++I) {
863863
Result.append(Delim->getValue());
864-
auto *StrInit = dyn_cast<StringInit>(List->getElement(I));
864+
auto *StrInit = cast<StringInit>(List->getElement(I));
865865
Result.append(StrInit->getValue());
866866
Fmt = StringInit::determineFormat(Fmt, StrInit->getFormat());
867867
}
@@ -872,13 +872,14 @@ static StringInit *interleaveIntList(const ListInit *List,
872872
const StringInit *Delim) {
873873
if (List->size() == 0)
874874
return StringInit::get("");
875-
SmallString<80> Result(dyn_cast<IntInit>(List->getElement(0)->
876-
getCastTo(IntRecTy::get()))->getAsString());
877-
875+
SmallString<80> Result(
876+
cast<IntInit>(List->getElement(0)->getCastTo(IntRecTy::get()))
877+
->getAsString());
878+
878879
for (unsigned I = 1, E = List->size(); I < E; ++I) {
879880
Result.append(Delim->getValue());
880-
Result.append(dyn_cast<IntInit>(List->getElement(I)->
881-
getCastTo(IntRecTy::get()))->getAsString());
881+
Result.append(cast<IntInit>(List->getElement(I)->getCastTo(IntRecTy::get()))
882+
->getAsString());
882883
}
883884
return StringInit::get(Result);
884885
}

0 commit comments

Comments
 (0)