https://github.com/gedare updated https://github.com/llvm/llvm-project/pull/92617
>From b4a8c06b79ec10ed2f53a7410bd847ecfa9e8450 Mon Sep 17 00:00:00 2001 From: Gedare Bloom <ged...@rtems.org> Date: Fri, 17 May 2024 17:18:59 -0600 Subject: [PATCH 1/5] [clang-format]: Annotate colons found in inline assembly Short-circuit the parsing of tok::colon to label colons found within lines starting with asm as InlineASMColon. Fixes #92616. --- clang/lib/Format/TokenAnnotator.cpp | 2 ++ clang/unittests/Format/TokenAnnotatorTest.cpp | 20 ++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 7c4c76a91f2c5..a83f937336565 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1358,6 +1358,8 @@ class AnnotatingParser { Line.First->startsSequence(tok::kw_export, Keywords.kw_module) || Line.First->startsSequence(tok::kw_export, Keywords.kw_import)) { Tok->setType(TT_ModulePartitionColon); + } else if (Line.First->is(tok::kw_asm)) { + Tok->setType(TT_InlineASMColon); } else if (Contexts.back().ColonIsDictLiteral || Style.isProto()) { Tok->setType(TT_DictLiteral); if (Style.Language == FormatStyle::LK_TextProto) { diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index aadfa6dc0165c..0f5f3936e0181 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -1489,11 +1489,25 @@ TEST_F(TokenAnnotatorTest, RequiresDoesNotChangeParsingOfTheRest) { TEST_F(TokenAnnotatorTest, UnderstandsAsm) { auto Tokens = annotate("__asm{\n" "a:\n" - "};"); - ASSERT_EQ(Tokens.size(), 7u) << Tokens; + ": x\n" + ":};"); + ASSERT_EQ(Tokens.size(), 10u) << Tokens; EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); EXPECT_TOKEN(Tokens[1], tok::l_brace, TT_InlineASMBrace); - EXPECT_TOKEN(Tokens[4], tok::r_brace, TT_InlineASMBrace); + EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[7], tok::r_brace, TT_InlineASMBrace); + + Tokens = annotate("__asm__ volatile (\n" + "a:\n" + ": x\n" + ":);"); + ASSERT_EQ(Tokens.size(), 11u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[7], tok::colon, TT_InlineASMColon); } TEST_F(TokenAnnotatorTest, UnderstandsObjCBlock) { >From 835425caa996d63f726bf89599b49ac2ad7fa3fb Mon Sep 17 00:00:00 2001 From: Gedare Bloom <ged...@rtems.org> Date: Thu, 23 May 2024 08:37:50 -0600 Subject: [PATCH 2/5] TokenAnnotator: remove redundant TT_InlineASMColon and add more tests --- clang/lib/Format/TokenAnnotator.cpp | 9 +-- clang/unittests/Format/TokenAnnotatorTest.cpp | 69 ++++++++++++++++++- 2 files changed, 70 insertions(+), 8 deletions(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index a83f937336565..bbf791c44d775 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1428,12 +1428,9 @@ class AnnotatingParser { // the colon are passed as macro arguments. Tok->setType(TT_ObjCMethodExpr); } else if (Contexts.back().ContextKind == tok::l_paren && - !Line.InPragmaDirective) { - if (Style.isTableGen() && Contexts.back().IsTableGenDAGArg) { - Tok->setType(TT_TableGenDAGArgListColon); - break; - } - Tok->setType(TT_InlineASMColon); + !Line.InPragmaDirective && Style.isTableGen() && + Contexts.back().IsTableGenDAGArg) { + Tok->setType(TT_TableGenDAGArgListColon); } break; case tok::pipe: diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 0f5f3936e0181..f5e819f8719a6 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -1488,7 +1488,7 @@ TEST_F(TokenAnnotatorTest, RequiresDoesNotChangeParsingOfTheRest) { TEST_F(TokenAnnotatorTest, UnderstandsAsm) { auto Tokens = annotate("__asm{\n" - "a:\n" + "\"a\":\n" ": x\n" ":};"); ASSERT_EQ(Tokens.size(), 10u) << Tokens; @@ -1500,7 +1500,7 @@ TEST_F(TokenAnnotatorTest, UnderstandsAsm) { EXPECT_TOKEN(Tokens[7], tok::r_brace, TT_InlineASMBrace); Tokens = annotate("__asm__ volatile (\n" - "a:\n" + "\"a\":\n" ": x\n" ":);"); ASSERT_EQ(Tokens.size(), 11u) << Tokens; @@ -1508,6 +1508,71 @@ TEST_F(TokenAnnotatorTest, UnderstandsAsm) { EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); EXPECT_TOKEN(Tokens[7], tok::colon, TT_InlineASMColon); + + Tokens = annotate("asm volatile (\n" + "\"a\":\n" + ": x\n" + ":);"); + ASSERT_EQ(Tokens.size(), 11u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[7], tok::colon, TT_InlineASMColon); + + Tokens = annotate("__asm__ volatile (\n" + "\"a_label:\"\n" + ":\n" + ": x\n" + ":);"); + ASSERT_EQ(Tokens.size(), 11u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[7], tok::colon, TT_InlineASMColon); + + Tokens = annotate("asm volatile (\n" + "\"a_label:\"\n" + ":\n" + ": x\n" + ":);"); + ASSERT_EQ(Tokens.size(), 11u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[7], tok::colon, TT_InlineASMColon); + + Tokens = annotate("__asm__ volatile (\n" + "\"a_label:\"\n" + "\"a b c(%%x)\"\n" + ":\n" + ": x\n" + ":);"); + ASSERT_EQ(Tokens.size(), 12u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[8], tok::colon, TT_InlineASMColon); + + Tokens = annotate("__asm__ volatile (\n" + "\"insn\"\n" + ": \"=r\" (var1), \"=&r\" (value)\n" + ":\n" + ": \"memory\");"); + ASSERT_EQ(Tokens.size(), 20u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[14], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[15], tok::colon, TT_InlineASMColon); + + Tokens = annotate("__asm__ volatile (\n" + "\"ldr r1, [r0, %%[sym]]\"\n" + ":\n" + ": [sym] \"J\" (aaaaa(aaaa, aaaa))\n" + ");"); + ASSERT_EQ(Tokens.size(), 21u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); } TEST_F(TokenAnnotatorTest, UnderstandsObjCBlock) { >From 84882016f666fe736fec55815e88ac297b59452f Mon Sep 17 00:00:00 2001 From: Gedare Bloom <ged...@rtems.org> Date: Fri, 24 May 2024 09:46:41 -0600 Subject: [PATCH 3/5] TokenAnnotator: remove last block in consumeToken colon --- clang/lib/Format/TokenAnnotator.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index bbf791c44d775..6378c224d847c 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1427,10 +1427,6 @@ class AnnotatingParser { // This handles a special macro in ObjC code where selectors including // the colon are passed as macro arguments. Tok->setType(TT_ObjCMethodExpr); - } else if (Contexts.back().ContextKind == tok::l_paren && - !Line.InPragmaDirective && Style.isTableGen() && - Contexts.back().IsTableGenDAGArg) { - Tok->setType(TT_TableGenDAGArgListColon); } break; case tok::pipe: >From 556ef68cc8f8fd8add03b3053f02067cc79f5d73 Mon Sep 17 00:00:00 2001 From: Gedare Bloom <ged...@rtems.org> Date: Fri, 24 May 2024 11:55:22 -0600 Subject: [PATCH 4/5] TokenAnnotatorTest: improve UnderstandsAsm tests --- clang/unittests/Format/TokenAnnotatorTest.cpp | 174 +++++++++++++++++- 1 file changed, 165 insertions(+), 9 deletions(-) diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index f5e819f8719a6..1e310495d081a 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -1499,10 +1499,65 @@ TEST_F(TokenAnnotatorTest, UnderstandsAsm) { EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); EXPECT_TOKEN(Tokens[7], tok::r_brace, TT_InlineASMBrace); - Tokens = annotate("__asm__ volatile (\n" + Tokens = annotate("asm{\n" + "\"a\":\n" + ": x\n" + ":};"); + ASSERT_EQ(Tokens.size(), 10u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[1], tok::l_brace, TT_InlineASMBrace); + EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[7], tok::r_brace, TT_InlineASMBrace); + + Tokens = annotate("__asm__{\n" + "\"a\":\n" + ": x\n" + ":};"); + ASSERT_EQ(Tokens.size(), 10u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[1], tok::l_brace, TT_InlineASMBrace); + EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[7], tok::r_brace, TT_InlineASMBrace); + + Tokens = annotate("__asm (\n" "\"a\":\n" ": x\n" ":);"); + ASSERT_EQ(Tokens.size(), 10u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); + + Tokens = annotate("asm (\n" + "\"a\":\n" + ": x\n" + ":);"); + ASSERT_EQ(Tokens.size(), 10u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); + + Tokens = annotate("__asm__ (\n" + "\"a\":\n" + ": x\n" + ":);"); + ASSERT_EQ(Tokens.size(), 10u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); + + Tokens = annotate("__asm volatile (\n" + "\"a_label:\"\n" + ":\n" + ": x\n" + ":);"); ASSERT_EQ(Tokens.size(), 11u) << Tokens; EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); @@ -1510,7 +1565,8 @@ TEST_F(TokenAnnotatorTest, UnderstandsAsm) { EXPECT_TOKEN(Tokens[7], tok::colon, TT_InlineASMColon); Tokens = annotate("asm volatile (\n" - "\"a\":\n" + "\"a_label:\"\n" + ":\n" ": x\n" ":);"); ASSERT_EQ(Tokens.size(), 11u) << Tokens; @@ -1530,16 +1586,74 @@ TEST_F(TokenAnnotatorTest, UnderstandsAsm) { EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); EXPECT_TOKEN(Tokens[7], tok::colon, TT_InlineASMColon); + Tokens = annotate("__asm (\n" + "\"a_label:\"\n" + ": x\n" + ":\n" + ": y);"); + ASSERT_EQ(Tokens.size(), 11u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); + + Tokens = annotate("asm (\n" + "\"a_label:\"\n" + ": x\n" + ":\n" + ": y);"); + ASSERT_EQ(Tokens.size(), 11u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); + + Tokens = annotate("__asm__ (\n" + "\"a_label:\"\n" + ": x\n" + ":\n" + ": y);"); + ASSERT_EQ(Tokens.size(), 11u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); + + Tokens = annotate("__asm volatile (\n" + "\"a_label:\"\n" + "\"a b c(%%x)\"\n" + ":\n" + ": x\n" + ":);"); + ASSERT_EQ(Tokens.size(), 12u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[8], tok::colon, TT_InlineASMColon); + + Tokens = annotate("__asm volatile (\n" + "\"a_label:\"\n" + "\"a b c(%%x)\"\n" + ":\n" + ": x\n" + ":);"); + ASSERT_EQ(Tokens.size(), 12u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[8], tok::colon, TT_InlineASMColon); + Tokens = annotate("asm volatile (\n" "\"a_label:\"\n" + "\"a b c(%%x)\"\n" ":\n" ": x\n" ":);"); - ASSERT_EQ(Tokens.size(), 11u) << Tokens; + ASSERT_EQ(Tokens.size(), 12u) << Tokens; EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); - EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[7], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[8], tok::colon, TT_InlineASMColon); Tokens = annotate("__asm__ volatile (\n" "\"a_label:\"\n" @@ -1553,16 +1667,58 @@ TEST_F(TokenAnnotatorTest, UnderstandsAsm) { EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); EXPECT_TOKEN(Tokens[8], tok::colon, TT_InlineASMColon); - Tokens = annotate("__asm__ volatile (\n" + Tokens = annotate("__asm (\n" "\"insn\"\n" ": \"=r\" (var1), \"=&r\" (value)\n" ":\n" ": \"memory\");"); - ASSERT_EQ(Tokens.size(), 20u) << Tokens; + ASSERT_EQ(Tokens.size(), 19u) << Tokens; EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); - EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[13], tok::colon, TT_InlineASMColon); EXPECT_TOKEN(Tokens[14], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[15], tok::colon, TT_InlineASMColon); + + Tokens = annotate("asm (\n" + "\"insn\"\n" + ": \"=r\" (var1), \"=&r\" (value)\n" + ":\n" + ": \"memory\");"); + ASSERT_EQ(Tokens.size(), 19u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[13], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[14], tok::colon, TT_InlineASMColon); + + Tokens = annotate("__asm__ (\n" + "\"insn\"\n" + ": \"=r\" (var1), \"=&r\" (value)\n" + ":\n" + ": \"memory\");"); + ASSERT_EQ(Tokens.size(), 19u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[13], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[14], tok::colon, TT_InlineASMColon); + + Tokens = annotate("__asm volatile (\n" + "\"ldr r1, [r0, %%[sym]]\"\n" + ":\n" + ": [sym] \"J\" (aaaaa(aaaa, aaaa))\n" + ");"); + ASSERT_EQ(Tokens.size(), 21u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); + + Tokens = annotate("asm volatile (\n" + "\"ldr r1, [r0, %%[sym]]\"\n" + ":\n" + ": [sym] \"J\" (aaaaa(aaaa, aaaa))\n" + ");"); + ASSERT_EQ(Tokens.size(), 21u) << Tokens; + EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); + EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); + EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); Tokens = annotate("__asm__ volatile (\n" "\"ldr r1, [r0, %%[sym]]\"\n" >From 41320dc6cc16d66d1e5cb9f8790c0a00e37a7197 Mon Sep 17 00:00:00 2001 From: Gedare Bloom <ged...@rtems.org> Date: Fri, 24 May 2024 23:17:39 -0600 Subject: [PATCH 5/5] TokenAnnotaterTest: remove repetitive snippets --- clang/unittests/Format/TokenAnnotatorTest.cpp | 172 +----------------- 1 file changed, 3 insertions(+), 169 deletions(-) diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 1e310495d081a..ad9513b4c52e3 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -1499,31 +1499,7 @@ TEST_F(TokenAnnotatorTest, UnderstandsAsm) { EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); EXPECT_TOKEN(Tokens[7], tok::r_brace, TT_InlineASMBrace); - Tokens = annotate("asm{\n" - "\"a\":\n" - ": x\n" - ":};"); - ASSERT_EQ(Tokens.size(), 10u) << Tokens; - EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); - EXPECT_TOKEN(Tokens[1], tok::l_brace, TT_InlineASMBrace); - EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[7], tok::r_brace, TT_InlineASMBrace); - - Tokens = annotate("__asm__{\n" - "\"a\":\n" - ": x\n" - ":};"); - ASSERT_EQ(Tokens.size(), 10u) << Tokens; - EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); - EXPECT_TOKEN(Tokens[1], tok::l_brace, TT_InlineASMBrace); - EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[7], tok::r_brace, TT_InlineASMBrace); - - Tokens = annotate("__asm (\n" + Tokens = annotate("__asm(\n" "\"a\":\n" ": x\n" ":);"); @@ -1533,37 +1509,6 @@ TEST_F(TokenAnnotatorTest, UnderstandsAsm) { EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); - Tokens = annotate("asm (\n" - "\"a\":\n" - ": x\n" - ":);"); - ASSERT_EQ(Tokens.size(), 10u) << Tokens; - EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); - EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); - - Tokens = annotate("__asm__ (\n" - "\"a\":\n" - ": x\n" - ":);"); - ASSERT_EQ(Tokens.size(), 10u) << Tokens; - EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); - EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); - - Tokens = annotate("__asm volatile (\n" - "\"a_label:\"\n" - ":\n" - ": x\n" - ":);"); - ASSERT_EQ(Tokens.size(), 11u) << Tokens; - EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); - EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[7], tok::colon, TT_InlineASMColon); - Tokens = annotate("asm volatile (\n" "\"a_label:\"\n" ":\n" @@ -1575,40 +1520,7 @@ TEST_F(TokenAnnotatorTest, UnderstandsAsm) { EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); EXPECT_TOKEN(Tokens[7], tok::colon, TT_InlineASMColon); - Tokens = annotate("__asm__ volatile (\n" - "\"a_label:\"\n" - ":\n" - ": x\n" - ":);"); - ASSERT_EQ(Tokens.size(), 11u) << Tokens; - EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); - EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[7], tok::colon, TT_InlineASMColon); - - Tokens = annotate("__asm (\n" - "\"a_label:\"\n" - ": x\n" - ":\n" - ": y);"); - ASSERT_EQ(Tokens.size(), 11u) << Tokens; - EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); - EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); - - Tokens = annotate("asm (\n" - "\"a_label:\"\n" - ": x\n" - ":\n" - ": y);"); - ASSERT_EQ(Tokens.size(), 11u) << Tokens; - EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); - EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); - - Tokens = annotate("__asm__ (\n" + Tokens = annotate("__asm__(\n" "\"a_label:\"\n" ": x\n" ":\n" @@ -1631,65 +1543,7 @@ TEST_F(TokenAnnotatorTest, UnderstandsAsm) { EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); EXPECT_TOKEN(Tokens[8], tok::colon, TT_InlineASMColon); - Tokens = annotate("__asm volatile (\n" - "\"a_label:\"\n" - "\"a b c(%%x)\"\n" - ":\n" - ": x\n" - ":);"); - ASSERT_EQ(Tokens.size(), 12u) << Tokens; - EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); - EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[8], tok::colon, TT_InlineASMColon); - - Tokens = annotate("asm volatile (\n" - "\"a_label:\"\n" - "\"a b c(%%x)\"\n" - ":\n" - ": x\n" - ":);"); - ASSERT_EQ(Tokens.size(), 12u) << Tokens; - EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); - EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[8], tok::colon, TT_InlineASMColon); - - Tokens = annotate("__asm__ volatile (\n" - "\"a_label:\"\n" - "\"a b c(%%x)\"\n" - ":\n" - ": x\n" - ":);"); - ASSERT_EQ(Tokens.size(), 12u) << Tokens; - EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); - EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[6], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[8], tok::colon, TT_InlineASMColon); - - Tokens = annotate("__asm (\n" - "\"insn\"\n" - ": \"=r\" (var1), \"=&r\" (value)\n" - ":\n" - ": \"memory\");"); - ASSERT_EQ(Tokens.size(), 19u) << Tokens; - EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); - EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[13], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[14], tok::colon, TT_InlineASMColon); - - Tokens = annotate("asm (\n" - "\"insn\"\n" - ": \"=r\" (var1), \"=&r\" (value)\n" - ":\n" - ": \"memory\");"); - ASSERT_EQ(Tokens.size(), 19u) << Tokens; - EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); - EXPECT_TOKEN(Tokens[3], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[13], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[14], tok::colon, TT_InlineASMColon); - - Tokens = annotate("__asm__ (\n" + Tokens = annotate("asm(\n" "\"insn\"\n" ": \"=r\" (var1), \"=&r\" (value)\n" ":\n" @@ -1700,26 +1554,6 @@ TEST_F(TokenAnnotatorTest, UnderstandsAsm) { EXPECT_TOKEN(Tokens[13], tok::colon, TT_InlineASMColon); EXPECT_TOKEN(Tokens[14], tok::colon, TT_InlineASMColon); - Tokens = annotate("__asm volatile (\n" - "\"ldr r1, [r0, %%[sym]]\"\n" - ":\n" - ": [sym] \"J\" (aaaaa(aaaa, aaaa))\n" - ");"); - ASSERT_EQ(Tokens.size(), 21u) << Tokens; - EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); - EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); - - Tokens = annotate("asm volatile (\n" - "\"ldr r1, [r0, %%[sym]]\"\n" - ":\n" - ": [sym] \"J\" (aaaaa(aaaa, aaaa))\n" - ");"); - ASSERT_EQ(Tokens.size(), 21u) << Tokens; - EXPECT_TOKEN(Tokens[0], tok::kw_asm, TT_Unknown); - EXPECT_TOKEN(Tokens[4], tok::colon, TT_InlineASMColon); - EXPECT_TOKEN(Tokens[5], tok::colon, TT_InlineASMColon); - Tokens = annotate("__asm__ volatile (\n" "\"ldr r1, [r0, %%[sym]]\"\n" ":\n" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits