diff --git a/llvm/lib/Support/YAMLParser.cpp b/llvm/lib/Support/YAMLParser.cpp index b9bbdc33a4333..06c3120bca026 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 c7df4b919a274..e4e3fe09d14c8 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()); +}