This is an archive of the discontinued LLVM Phabricator instance.

[Clang][Comments] Parse `<img src=""/>` in doc comments correctly
ClosedPublic

Authored by egorzhdan on Aug 30 2022, 5:03 AM.

Details

Summary

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

Diff Detail

Event Timeline

egorzhdan created this revision.Aug 30 2022, 5:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 30 2022, 5:03 AM
egorzhdan requested review of this revision.Aug 30 2022, 5:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 30 2022, 5:03 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
gribozavr2 added inline comments.
clang/test/Sema/warn-documentation.cpp
78

Could you also add these tests to clang/test/Index/comment-to-html-xml-conversion.cpp to show that the whole tag is captured correctly? (for example, the ">" is correctly captured as a part of the tag, not as plain text)

egorzhdan updated this revision to Diff 456674.EditedAug 30 2022, 7:56 AM
  • Add tests for conversion of doc comments to HTML/XML
  • Fix a bug in StringRef -> CXString conversion logic for an empty string
egorzhdan marked an inline comment as done.Aug 30 2022, 7:57 AM
egorzhdan added inline comments.
clang/test/Sema/warn-documentation.cpp
78

Thanks, added a few tests there.

gribozavr2 added inline comments.Aug 30 2022, 8:38 AM
clang/tools/libclang/CXString.cpp
85 ↗(On Diff #456674)

Please split this change into a separate patch and add a unit test.

egorzhdan marked an inline comment as done.Aug 30 2022, 10:02 AM
egorzhdan added inline comments.
clang/tools/libclang/CXString.cpp
85 ↗(On Diff #456674)

Do you know a good way to add a unit-test for this? This function only gets called from within libclang, it isn't exposed to clients of libclang, including libclangTest. So I think a unit test would probably need to invoke the same CXComment API that c-index-test invokes while running comment-to-html-xml-conversion.cpp. Would that be worth it?

gribozavr2 accepted this revision.Aug 30 2022, 1:06 PM
gribozavr2 added inline comments.
clang/tools/libclang/CXString.cpp
85 ↗(On Diff #456674)

It is unfortunate that the headers for CXString are not visible to llvm-project/clang/unittests/libclang/LibclangTest.cpp.

It wouldn't make sense to use the CXComment API because that's exactly what comment-to-html-xml-conversion.cpp does. A benefit of the unit test would be clear, direct testing of CXString.

Anyhow, please split the CXString change to a separate patch (without tests, unfortunately).

This revision is now accepted and ready to land.Aug 30 2022, 1:06 PM
egorzhdan updated this revision to Diff 456989.Aug 31 2022, 9:42 AM

Rebase to apply fixes to string conversion

gribozavr2 accepted this revision.Aug 31 2022, 9:49 AM
This revision was landed with ongoing or failed builds.Sep 1 2022, 5:17 AM
This revision was automatically updated to reflect the committed changes.