-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang-doc][fix] crashes when generating HTML without --repository
#131698
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang-tools-extra Author: Mohamed Emad (hulxv) ChangesFix #131697 Full diff: https://github.com/llvm/llvm-project/pull/131698.diff 1 Files Affected:
diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index 18a0de826630c..37d94ace17477 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -494,7 +494,7 @@ genReferencesBlock(const std::vector<Reference> &References,
static std::unique_ptr<TagNode>
writeFileDefinition(const Location &L,
std::optional<StringRef> RepositoryUrl = std::nullopt) {
- if (!L.IsFileInRootDir && !RepositoryUrl)
+ if (!L.IsFileInRootDir || !RepositoryUrl)
return std::make_unique<TagNode>(
HTMLTag::TAG_P, "Defined at line " + std::to_string(L.LineNumber) +
" of file " + L.Filename);
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, but I don't think this is logic is quite right as it stands. There should also be some accompanying test changes to reflect what's being fixed. As this patch stands it removes basic functionality.
@@ -494,7 +494,7 @@ genReferencesBlock(const std::vector<Reference> &References, | |||
static std::unique_ptr<TagNode> | |||
writeFileDefinition(const Location &L, | |||
std::optional<StringRef> RepositoryUrl = std::nullopt) { | |||
if (!L.IsFileInRootDir && !RepositoryUrl) | |||
if (!L.IsFileInRootDir || !RepositoryUrl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic isn't correct, and happens to prevent us from effectively using the --repository=
string anywhere, as evidenced by our tests.
I have some additional test changes that I'm in the process of adding that will hopefully cover this case.
An alternative would be to change the deref of the option to use .value_or("")
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#131894 adds more complete testing logic around the --repository
flag. see if the behavior you're trying to fix reproduces in the tests w/ that PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#131894 adds more complete testing logic around the
--repository
flag. see if the behavior you're trying to fix reproduces in the tests w/ that PR?
yup, it's correct but I think we need to add some tests for single files also
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic isn't correct, and happens to prevent us from effectively using the --repository= string anywhere, as evidenced by our tests.
The whole next logic depends on RepositoryUrl
. how can we continue using it if it's not passed?
An alternative would be to change the deref of the option to use .value_or("") instead.
If RepositoryUrl
is not passed, shouldn't we use file://
protocol as I think? In this case, the FileUrl
should be something like file:///path/to/file
, not just an empty string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whole next logic depends on
RepositoryUrl
. how can we continue using it if it's not passed?
What I mean is that often !L.IsFileInRootDir || !RepositoryUrl
is true when we want to use the --repository
flag, meaning we never use the URL in situations where we should.
If RepositoryUrl is not passed, shouldn't we use file:// protocol as I think? In this case, the FileUrl should be something like file:///path/to/file, not just an empty string
Maybe. I think we're still generating a valid path in the HTML, but different generation methods are welcome. Some of this may be obsoleted after @PeterChou1 finishes landing #108653 and the prerequisite Mustache support in LLVM support.
hey, sorry, I ended up landing #131939. There are two reasons: 1) I really wanted to fix that crash ASAP. 2) I made the mistake of stacking other patches on top of it with graphite, and it turns out it isn't easy to reorder them. As a result I couldn't fix the basic functionality of HTML links without reuploading the entire rest of the stack. Normally, I'd much prefer to just mentor you through the process, but I really needed to fix those links. If you're still interested in working on this though, I think the test could be improved , and I wouldn't mid seeing that code cleaned up. In particular, I'm wondering how great of an idea it is to use those optionals, when we end up w/ a |
Fix #131697