[Mlir-commits] [mlir] 95935e8 - Make genAttributeVerifier escape the summary.
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Oct 21 14:41:35 PDT 2021
Author: Matthias Kramm
Date: 2021-10-21T21:41:31Z
New Revision: 95935e8285ad0e2872b83190669c9f70f2fd2112
URL: https://github.com/llvm/llvm-project/commit/95935e8285ad0e2872b83190669c9f70f2fd2112
DIFF: https://github.com/llvm/llvm-project/commit/95935e8285ad0e2872b83190669c9f70f2fd2112.diff
LOG: Make genAttributeVerifier escape the summary.
The summary can contain references to e.g. attribute defaults, which
can contain special characters. So these strings need to be C++
escaped.
Reviewed By: Mogball
Differential Revision: https://reviews.llvm.org/D112249
Added:
Modified:
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
Removed:
################################################################################
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index e5d243952a53..12cb505d2a65 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -151,6 +151,14 @@ static std::string replaceAllSubstrs(std::string str, const std::string &match,
return str;
}
+// Escape a string using LLVM/MLIR encoding. E.g. foo"bar -> foo\22bar.
+static std::string escapeString(StringRef value) {
+ std::string ret;
+ llvm::raw_string_ostream os(ret);
+ llvm::printEscapedString(value, os);
+ return os.str();
+}
+
// Returns whether the record has a value of the given name that can be returned
// via getValueAsString.
static inline bool hasStringAttribute(const Record &record,
@@ -359,6 +367,7 @@ class OpEmitter {
// The emitter containing all of the locally emitted verification functions.
const StaticVerifierFunctionEmitter &staticVerifierEmitter;
};
+
} // end anonymous namespace
// Populate the format context `ctx` with substitutions of attributes, operands
@@ -464,7 +473,7 @@ static void genAttributeVerifier(const Operator &op, const char *attrGet,
body << tgfmt(" if (!($0)) return $1\"attribute '$2' "
"failed to satisfy constraint: $3\");\n",
/*ctx=*/nullptr, tgfmt(condition, &ctx.withSelf(varName)),
- emitErrorPrefix, attrName, attr.getSummary());
+ emitErrorPrefix, attrName, escapeString(attr.getSummary()));
if (allowMissingAttr)
body << " }\n";
body << " }\n";
More information about the Mlir-commits
mailing list