[llvm] b877c35 - [YAMLIO] Correctly diagnose empty alias/anchor

Scott Linder via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 16 10:45:39 PST 2020


Author: Scott Linder
Date: 2020-11-16T18:45:05Z
New Revision: b877c35d4b2cc67f7c3d96698fcd3845683ce5e2

URL: https://github.com/llvm/llvm-project/commit/b877c35d4b2cc67f7c3d96698fcd3845683ce5e2
DIFF: https://github.com/llvm/llvm-project/commit/b877c35d4b2cc67f7c3d96698fcd3845683ce5e2.diff

LOG: [YAMLIO] Correctly diagnose empty alias/anchor

The `Range` of an alias/anchor token includes the leading `&` or `*`,
but it is skipped while parsing the name. The check for an empty name
fails to account for the skipped leading character and so the error is
never hit.

Fix the off-by-one and add a couple regression tests.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D91462

Added: 
    

Modified: 
    llvm/lib/Support/YAMLParser.cpp
    llvm/unittests/Support/YAMLIOTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/YAMLParser.cpp b/llvm/lib/Support/YAMLParser.cpp
index b9bbdc33a433..06c3120bca02 100644
--- a/llvm/lib/Support/YAMLParser.cpp
+++ b/llvm/lib/Support/YAMLParser.cpp
@@ -1423,7 +1423,7 @@ bool Scanner::scanAliasOrAnchor(bool IsAlias) {
     ++Column;
   }
 
-  if (Start == Current) {
+  if (Start + 1 == Current) {
     setError("Got empty alias or anchor", Start);
     return false;
   }

diff  --git a/llvm/unittests/Support/YAMLIOTest.cpp b/llvm/unittests/Support/YAMLIOTest.cpp
index c7df4b919a27..e4e3fe09d14c 100644
--- a/llvm/unittests/Support/YAMLIOTest.cpp
+++ b/llvm/unittests/Support/YAMLIOTest.cpp
@@ -3101,3 +3101,15 @@ TEST(YAMLIO, TestUnknownDirective) {
   EXPECT_FALSE(yin2.setCurrentDocument());
   EXPECT_TRUE(yin2.error());
 }
+
+TEST(YAMLIO, TestEmptyAlias) {
+  Input yin("&");
+  EXPECT_FALSE(yin.setCurrentDocument());
+  EXPECT_TRUE(yin.error());
+}
+
+TEST(YAMLIO, TestEmptyAnchor) {
+  Input yin("*");
+  EXPECT_FALSE(yin.setCurrentDocument());
+  EXPECT_TRUE(yin.error());
+}


        


More information about the llvm-commits mailing list