From 0cb08093365478224f2a58cece42527fb8e1199e Mon Sep 17 00:00:00 2001 From: Egor Zhdan Date: Tue, 30 Aug 2022 12:55:43 +0100 Subject: [PATCH] [Clang][Comments] Parse `` in doc comments correctly This is a valid HTML5 tag. Previously it triggered a Clang error (`HTML start tag prematurely ended, expected attribute name or '>'`) since Clang was treating `/>` as a text token. This was happening because after lexing the closing quote (`"`) the lexer state was reset to "Normal" while the tag was not actually closed yet: `>` was not yet parsed at that point. rdar://91464292 Differential Revision: https://reviews.llvm.org/D132932 --- clang/lib/AST/CommentLexer.cpp | 2 +- .../test/Index/comment-to-html-xml-conversion.cpp | 50 ++++++++++++++++++++++ clang/test/Sema/warn-documentation.cpp | 15 +++++++ 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/CommentLexer.cpp b/clang/lib/AST/CommentLexer.cpp index 61ce897..f0250fc 100644 --- a/clang/lib/AST/CommentLexer.cpp +++ b/clang/lib/AST/CommentLexer.cpp @@ -701,7 +701,7 @@ void Lexer::lexHTMLStartTag(Token &T) { C = *BufferPtr; if (!isHTMLIdentifierStartingCharacter(C) && - C != '=' && C != '\"' && C != '\'' && C != '>') { + C != '=' && C != '\"' && C != '\'' && C != '>' && C != '/') { State = LS_Normal; return; } diff --git a/clang/test/Index/comment-to-html-xml-conversion.cpp b/clang/test/Index/comment-to-html-xml-conversion.cpp index 1fedd38..ec49e5a 100644 --- a/clang/test/Index/comment-to-html-xml-conversion.cpp +++ b/clang/test/Index/comment-to-html-xml-conversion.cpp @@ -744,6 +744,26 @@ void comment_to_html_conversion_37(); // CHECK-NEXT: (CXComment_Text Text=[ ] IsWhitespace) // CHECK-NEXT: (CXComment_InlineCommand CommandName=[anchor] RenderAnchor Arg[0]=A)))] +/// Aaa bbb +void comment_to_html_conversion_38(); + +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_38:{{.*}} FullCommentAsHTML=[

Aaa bbb

] FullCommentAsXML=[comment_to_html_conversion_38c:@F@comment_to_html_conversion_38#void comment_to_html_conversion_38() Aaa bbb]]>] +// CHECK-NEXT: CommentAST=[ +// CHECK-NEXT: (CXComment_FullComment +// CHECK-NEXT: (CXComment_Paragraph +// CHECK-NEXT: (CXComment_Text Text=[ Aaa bbb]) +// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] SelfClosing) + +/// Aaa ccc +void comment_to_html_conversion_39(); + +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_39:{{.*}} FullCommentAsHTML=[

Aaa ccc

] FullCommentAsXML=[comment_to_html_conversion_39c:@F@comment_to_html_conversion_39#void comment_to_html_conversion_39() Aaa ccc]]>] +// CHECK-NEXT: CommentAST=[ +// CHECK-NEXT: (CXComment_FullComment +// CHECK-NEXT: (CXComment_Paragraph +// CHECK-NEXT: (CXComment_Text Text=[ Aaa ccc]) +// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] SelfClosing) + /// Aaa ccc void comment_to_html_conversion_40(); @@ -754,6 +774,36 @@ void comment_to_html_conversion_40(); // CHECK-NEXT: (CXComment_Text Text=[ Aaa ccc]) // CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] Attrs: src=) +/// Aaa ccc +void comment_to_html_conversion_41(); + +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_41:{{.*}} FullCommentAsHTML=[

Aaa ccc

] FullCommentAsXML=[comment_to_html_conversion_41c:@F@comment_to_html_conversion_41#void comment_to_html_conversion_41() Aaa ccc]]>] +// CHECK-NEXT: CommentAST=[ +// CHECK-NEXT: (CXComment_FullComment +// CHECK-NEXT: (CXComment_Paragraph +// CHECK-NEXT: (CXComment_Text Text=[ Aaa ccc]) +// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] Attrs: src=path) + +/// Aaa ccc +void comment_to_html_conversion_42(); + +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_42:{{.*}} FullCommentAsHTML=[

Aaa ccc

] FullCommentAsXML=[comment_to_html_conversion_42c:@F@comment_to_html_conversion_42#void comment_to_html_conversion_42() Aaa ccc]]>] +// CHECK-NEXT: CommentAST=[ +// CHECK-NEXT: (CXComment_FullComment +// CHECK-NEXT: (CXComment_Paragraph +// CHECK-NEXT: (CXComment_Text Text=[ Aaa ccc]) +// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] Attrs: src=path SelfClosing) + +/// Aaa ddd +void comment_to_html_conversion_43(); + +// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_43:{{.*}} FullCommentAsHTML=[

Aaa ddd

] FullCommentAsXML=[comment_to_html_conversion_43c:@F@comment_to_html_conversion_43#void comment_to_html_conversion_43() Aaa ddd]]>] +// CHECK-NEXT: CommentAST=[ +// CHECK-NEXT: (CXComment_FullComment +// CHECK-NEXT: (CXComment_Paragraph +// CHECK-NEXT: (CXComment_Text Text=[ Aaa ddd]) +// CHECK-NEXT: (CXComment_HTMLStartTag Name=[img] Attrs: src= SelfClosing) + /// Aaa. class comment_to_xml_conversion_01 { // CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-1]]:7: ClassDecl=comment_to_xml_conversion_01:{{.*}} FullCommentAsXML=[comment_to_xml_conversion_01c:@S@comment_to_xml_conversion_01class comment_to_xml_conversion_01 {} Aaa.] diff --git a/clang/test/Sema/warn-documentation.cpp b/clang/test/Sema/warn-documentation.cpp index 431c0e0..284ae97 100644 --- a/clang/test/Sema/warn-documentation.cpp +++ b/clang/test/Sema/warn-documentation.cpp @@ -62,6 +62,21 @@ int test_html10(int); ///

int test_html11(int); +/// Aaa bbb +int test_html12(int); + +/// Aaa bbb +int test_html13(int); + +/// Aaa bbb +int test_html14(int); + +/// Aaa bbb +int test_html15(int); + +/// Aaa bbb +int test_html16(int); + ///
Meow
int test_html_nesting1(int); -- 2.7.4