[clang] eabb1f0 - [AST] Avoid single-trip loop in ClangAttrEmitter
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 19 23:50:12 PDT 2021
Author: Sam McCall
Date: 2021-08-20T08:49:57+02:00
New Revision: eabb1f0732ac5e20d2e169024befaf2e9f166a8d
URL: https://github.com/llvm/llvm-project/commit/eabb1f0732ac5e20d2e169024befaf2e9f166a8d
DIFF: https://github.com/llvm/llvm-project/commit/eabb1f0732ac5e20d2e169024befaf2e9f166a8d.diff
LOG: [AST] Avoid single-trip loop in ClangAttrEmitter
This triggers coverity warnings, see https://reviews.llvm.org/D107703
Added:
Modified:
clang/utils/TableGen/ClangAttrEmitter.cpp
Removed:
################################################################################
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 342bbb39395f8..5d0fd8b9f6b8e 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -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";
}
}
More information about the cfe-commits
mailing list