egorzhdan updated this revision to Diff 456674.
egorzhdan added a comment.

- Add tests for conversion of doc comments to HTML/XML
- Fix a bug in `StringRef` -> `CXString` conversion logic for an empty

string


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132932/new/

https://reviews.llvm.org/D132932

Files:
  clang/lib/AST/CommentLexer.cpp
  clang/test/Index/comment-to-html-xml-conversion.cpp
  clang/test/Sema/warn-documentation.cpp
  clang/tools/libclang/CXString.cpp

Index: clang/tools/libclang/CXString.cpp
===================================================================
--- clang/tools/libclang/CXString.cpp
+++ clang/tools/libclang/CXString.cpp
@@ -78,13 +78,19 @@
 }
 
 CXString createRef(StringRef String) {
+  // If the string is empty, it might point to a position in another string
+  // while having zero length. Make sure we don't create a reference to the
+  // larger string.
+  if (String.empty())
+    return createEmpty();
+
   // If the string is not nul-terminated, we have to make a copy.
 
   // FIXME: This is doing a one past end read, and should be removed! For memory
   // we don't manage, the API string can become unterminated at any time outside
   // our control.
 
-  if (!String.empty() && String.data()[String.size()] != 0)
+  if (String.data()[String.size()] != 0)
     return createDup(String);
 
   CXString Result;
Index: clang/test/Sema/warn-documentation.cpp
===================================================================
--- clang/test/Sema/warn-documentation.cpp
+++ clang/test/Sema/warn-documentation.cpp
@@ -62,6 +62,21 @@
 /// <br></br>
 int test_html11(int);
 
+/// Aaa bbb<img/>
+int test_html12(int);
+
+/// Aaa bbb<img />
+int test_html13(int);
+
+/// Aaa bbb<img src="">
+int test_html14(int);
+
+/// Aaa bbb<img src=""/>
+int test_html15(int);
+
+/// Aaa bbb<img src="" />
+int test_html16(int);
+
 /// <blockquote>Meow</blockquote>
 int test_html_nesting1(int);
 
Index: clang/test/Index/comment-to-html-xml-conversion.cpp
===================================================================
--- clang/test/Index/comment-to-html-xml-conversion.cpp
+++ clang/test/Index/comment-to-html-xml-conversion.cpp
@@ -744,6 +744,65 @@
 // CHECK-NEXT:         (CXComment_Text Text=[ ] IsWhitespace)
 // CHECK-NEXT:         (CXComment_InlineCommand CommandName=[anchor] RenderAnchor Arg[0]=A)))]
 
+/// Aaa bbb<img/>
+void comment_to_html_conversion_38();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_38:{{.*}} FullCommentAsHTML=[<p class="para-brief"> Aaa bbb<img/></p>] FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-2]]" column="6"><Name>comment_to_html_conversion_38</Name><USR>c:@F@comment_to_html_conversion_38#</USR><Declaration>void comment_to_html_conversion_38()</Declaration><Abstract><Para> Aaa bbb<rawHTML><![CDATA[<img/>]]></rawHTML></Para></Abstract></Function>]
+// 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<img />
+void comment_to_html_conversion_39();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_39:{{.*}} FullCommentAsHTML=[<p class="para-brief"> Aaa ccc<img/></p>] FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-2]]" column="6"><Name>comment_to_html_conversion_39</Name><USR>c:@F@comment_to_html_conversion_39#</USR><Declaration>void comment_to_html_conversion_39()</Declaration><Abstract><Para> Aaa ccc<rawHTML><![CDATA[<img/>]]></rawHTML></Para></Abstract></Function>]
+// 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<img src="">
+void comment_to_html_conversion_40();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_40:{{.*}} FullCommentAsHTML=[<p class="para-brief"> Aaa ccc<img src></p>] FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-2]]" column="6"><Name>comment_to_html_conversion_40</Name><USR>c:@F@comment_to_html_conversion_40#</USR><Declaration>void comment_to_html_conversion_40()</Declaration><Abstract><Para> Aaa ccc<rawHTML><![CDATA[<img src>]]></rawHTML></Para></Abstract></Function>]
+// 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=)
+
+/// Aaa ccc<img src="path">
+void comment_to_html_conversion_41();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_41:{{.*}} FullCommentAsHTML=[<p class="para-brief"> Aaa ccc<img src="path"></p>] FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-2]]" column="6"><Name>comment_to_html_conversion_41</Name><USR>c:@F@comment_to_html_conversion_41#</USR><Declaration>void comment_to_html_conversion_41()</Declaration><Abstract><Para> Aaa ccc<rawHTML><![CDATA[<img src="path">]]></rawHTML></Para></Abstract></Function>]
+// 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<img src="path"/>
+void comment_to_html_conversion_42();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_42:{{.*}} FullCommentAsHTML=[<p class="para-brief"> Aaa ccc<img src="path"/></p>] FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-2]]" column="6"><Name>comment_to_html_conversion_42</Name><USR>c:@F@comment_to_html_conversion_42#</USR><Declaration>void comment_to_html_conversion_42()</Declaration><Abstract><Para> Aaa ccc<rawHTML><![CDATA[<img src="path"/>]]></rawHTML></Para></Abstract></Function>]
+// 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<img src=""/>
+void comment_to_html_conversion_43();
+
+// CHECK: comment-to-html-xml-conversion.cpp:[[@LINE-2]]:6: FunctionDecl=comment_to_html_conversion_43:{{.*}} FullCommentAsHTML=[<p class="para-brief"> Aaa ddd<img src/></p>] FullCommentAsXML=[<Function file="{{[^"]+}}comment-to-html-xml-conversion.cpp" line="[[@LINE-2]]" column="6"><Name>comment_to_html_conversion_43</Name><USR>c:@F@comment_to_html_conversion_43#</USR><Declaration>void comment_to_html_conversion_43()</Declaration><Abstract><Para> Aaa ddd<rawHTML><![CDATA[<img src/>]]></rawHTML></Para></Abstract></Function>]
+// 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 {
Index: clang/lib/AST/CommentLexer.cpp
===================================================================
--- clang/lib/AST/CommentLexer.cpp
+++ clang/lib/AST/CommentLexer.cpp
@@ -701,7 +701,7 @@
 
   C = *BufferPtr;
   if (!isHTMLIdentifierStartingCharacter(C) &&
-      C != '=' && C != '\"' && C != '\'' && C != '>') {
+      C != '=' && C != '\"' && C != '\'' && C != '>' && C != '/') {
     State = LS_Normal;
     return;
   }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to