[llvm] [Remarks] Escape control characters in YAML remark arguments and decode them when parsing (PR #227654)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 1 04:59:49 PDT 2026
================
@@ -265,22 +265,21 @@ Expected<StringRef> YAMLRemarkParser::parseKey(yaml::KeyValueNode &Node) {
}
Expected<StringRef> YAMLRemarkParser::parseStr(yaml::KeyValueNode &Node) {
- auto *Value = dyn_cast_if_present<yaml::ScalarNode>(Node.getValue());
- yaml::BlockScalarNode *ValueBlock;
- StringRef Result;
- if (!Value) {
- // Try to parse the value as a block node.
- ValueBlock = dyn_cast_if_present<yaml::BlockScalarNode>(Node.getValue());
- if (!ValueBlock)
- return error("expected a value of scalar type.", Node);
- Result = ValueBlock->getValue();
- } else
- Result = Value->getRawValue();
-
- Result.consume_front("\'");
- Result.consume_back("\'");
-
- return Result;
+ yaml::Node *Value = Node.getValue();
+ // A block value lives in the YAML document, which next() frees before
+ // returning the remark.
+ if (auto *Block = dyn_cast_if_present<yaml::BlockScalarNode>(Value))
+ return Block->getValue().copy(Alloc);
+
+ auto *Scalar = dyn_cast_if_present<yaml::ScalarNode>(Value);
+ if (!Scalar)
+ return error("expected a value of scalar type.", Node);
+ SmallString<32> Storage;
+ StringRef Result = Scalar->getValue(Storage);
----------------
fhahn wrote:
I think this will now write `\0` unescaped if it is contained in the remark string. Could you add a test where we round-trip through bitcode format for a remark string containing `\0`. I think currently it will cut things off.
Perhaps we should just forbid it
https://github.com/llvm/llvm-project/pull/227654
More information about the llvm-commits
mailing list