Skip to content

Commit

Permalink
[AST] Avoid single-trip loop in ClangAttrEmitter
Browse files Browse the repository at this point in the history
This triggers coverity warnings, see https://reviews.llvm.org/D107703
  • Loading branch information
sam-mccall committed Aug 20, 2021
1 parent fd21d1e commit eabb1f0
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions clang/utils/TableGen/ClangAttrEmitter.cpp
Expand Up @@ -4235,15 +4235,13 @@ void EmitClangAttrDocTable(RecordKeeper &Records, raw_ostream &OS) {
if (!A->getValueAsBit("ASTNode"))
continue;
std::vector<Record *> Docs = A->getValueAsListOfDefs("Documentation");
for (const auto *D : Docs) {
OS << "\nstatic const char AttrDoc_" << A->getName() << "[] = "
<< "R\"reST("
<< D->getValueAsOptionalString("Content").getValueOr("").trim()
<< ")reST\";\n";
// Only look at the first documentation if there are several.
// (Currently there's only one such attr, revisit if this becomes common).
break;
}
assert(!Docs.empty());
// Only look at the first documentation if there are several.
// (Currently there's only one such attr, revisit if this becomes common).
StringRef Text =
Docs.front()->getValueAsOptionalString("Content").getValueOr("");
OS << "\nstatic const char AttrDoc_" << A->getName() << "[] = "
<< "R\"reST(" << Text.trim() << ")reST\";\n";
}
}

Expand Down

0 comments on commit eabb1f0

Please sign in to comment.