[PATCH] D140474: [YAML IO] Check that mapping doesn't contain duplicating keys
Anton Sidorenko via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 16 06:46:46 PST 2023
asi-sc updated this revision to Diff 489542.
asi-sc added a comment.
Move test changes to a separate review D141848 <https://reviews.llvm.org/D141848>
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D140474/new/
https://reviews.llvm.org/D140474
Files:
llvm/lib/Support/YAMLTraits.cpp
llvm/test/tools/yaml2obj/map_duplicate_key.test
llvm/test/tools/yaml2obj/map_duplicate_key_2.test
Index: llvm/test/tools/yaml2obj/map_duplicate_key_2.test
===================================================================
--- /dev/null
+++ llvm/test/tools/yaml2obj/map_duplicate_key_2.test
@@ -0,0 +1,15 @@
+# RUN: not yaml2obj %s 2>&1 | FileCheck %s
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ ABIVersion: 0x05
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ ABIVersion: 0x05
+
+# CHECK: error: duplicated mapping key 'FileHeader
Index: llvm/test/tools/yaml2obj/map_duplicate_key.test
===================================================================
--- /dev/null
+++ llvm/test/tools/yaml2obj/map_duplicate_key.test
@@ -0,0 +1,11 @@
+# RUN: not yaml2obj %s 2>&1 | FileCheck %s
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Type: ET_REL
+ ABIVersion: 0x05
+
+# CHECK: error: duplicated mapping key 'Type
Index: llvm/lib/Support/YAMLTraits.cpp
===================================================================
--- llvm/lib/Support/YAMLTraits.cpp
+++ llvm/lib/Support/YAMLTraits.cpp
@@ -435,6 +435,11 @@
// Copy string to permanent storage
KeyStr = StringStorage.str().copy(StringAllocator);
}
+ if (mapHNode->Mapping.count(KeyStr))
+ // From YAML spec: "The content of a mapping node is an unordered set of
+ // key/value node pairs, with the restriction that each of the keys is
+ // unique."
+ setError(KeyNode, Twine("duplicated mapping key '") + KeyStr);
auto ValueHNode = createHNodes(Value);
if (EC)
break;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140474.489542.patch
Type: text/x-patch
Size: 1667 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230116/a817c49f/attachment.bin>
More information about the llvm-commits
mailing list