[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:48 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);
+
----------------
fhahn wrote:

I think the use-after-free could be fixed independently?


https://github.com/llvm/llvm-project/pull/227654


More information about the llvm-commits mailing list