[clang-doc] fix ASan complaints from passing RepositoryURL as reference#148923
Merged
[clang-doc] fix ASan complaints from passing RepositoryURL as reference#148923
Conversation
Passing RepositoryURL around as an optional reference triggered stack-use-after-return complaints.
Member
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
Member
|
@llvm/pr-subscribers-clang-tools-extra Author: Erick Velez (evelez7) ChangesPassing RepositoryURL around as an optional reference triggered Full diff: https://github.com/llvm/llvm-project/pull/148923.diff 1 Files Affected:
diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp
index 6fdc7196e9095..cc4c68346ec53 100644
--- a/clang-tools-extra/clang-doc/JSONGenerator.cpp
+++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp
@@ -45,7 +45,7 @@ static auto SerializeReferenceLambda = [](const auto &Ref, Object &Object) {
static json::Object
serializeLocation(const Location &Loc,
- const std::optional<StringRef> &RepositoryUrl) {
+ const std::optional<StringRef> RepositoryUrl) {
Object LocationObj = Object();
LocationObj["LineNumber"] = Loc.StartLineNumber;
LocationObj["Filename"] = Loc.Filename;
@@ -169,7 +169,7 @@ static json::Value serializeComment(const CommentInfo &I) {
static void
serializeCommonAttributes(const Info &I, json::Object &Obj,
- const std::optional<StringRef> &RepositoryUrl) {
+ const std::optional<StringRef> RepositoryUrl) {
Obj["Name"] = I.Name;
Obj["USR"] = toHex(toStringRef(I.USR));
@@ -211,9 +211,9 @@ static void serializeReference(const Reference &Ref, Object &ReferenceObj) {
// differently. Only enums, records, and typedefs are handled here.
static void
serializeCommonChildren(const ScopeChildren &Children, json::Object &Obj,
- const std::optional<StringRef> &RepositoryUrl) {
- static auto SerializeInfo = [&RepositoryUrl](const auto &Info,
- Object &Object) {
+ const std::optional<StringRef> RepositoryUrl) {
+ static auto SerializeInfo = [RepositoryUrl](const auto &Info,
+ Object &Object) {
serializeInfo(Info, Object, RepositoryUrl);
};
@@ -304,7 +304,7 @@ static void serializeInfo(const FieldTypeInfo &I, Object &Obj) {
}
static void serializeInfo(const FunctionInfo &F, json::Object &Obj,
- const std::optional<StringRef> &RepositoryURL) {
+ const std::optional<StringRef> RepositoryURL) {
serializeCommonAttributes(F, Obj, RepositoryURL);
Obj["IsStatic"] = F.IsStatic;
@@ -459,7 +459,7 @@ static void serializeInfo(const RecordInfo &I, json::Object &Obj,
}
static void serializeInfo(const VarInfo &I, json::Object &Obj,
- const std::optional<StringRef> &RepositoryUrl) {
+ const std::optional<StringRef> RepositoryUrl) {
serializeCommonAttributes(I, Obj, RepositoryUrl);
Obj["IsStatic"] = I.IsStatic;
auto TypeObj = Object();
@@ -468,15 +468,15 @@ static void serializeInfo(const VarInfo &I, json::Object &Obj,
}
static void serializeInfo(const NamespaceInfo &I, json::Object &Obj,
- const std::optional<StringRef> &RepositoryUrl) {
+ const std::optional<StringRef> RepositoryUrl) {
serializeCommonAttributes(I, Obj, RepositoryUrl);
if (!I.Children.Namespaces.empty())
serializeArray(I.Children.Namespaces, Obj, "Namespaces",
SerializeReferenceLambda);
- static auto SerializeInfo = [&RepositoryUrl](const auto &Info,
- Object &Object) {
+ static auto SerializeInfo = [RepositoryUrl](const auto &Info,
+ Object &Object) {
serializeInfo(Info, Object, RepositoryUrl);
};
|
ilovepi
approved these changes
Jul 15, 2025
Contributor
ilovepi
left a comment
There was a problem hiding this comment.
LGTM, assuming the complaint is from the optional and not the StringRef.
Member
Author
Yeah the complaint was from the optional's bool operator being checked. |
Member
Author
This was referenced Jul 18, 2025
This was referenced Jul 23, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Passing RepositoryURL around as an optional reference triggered
stack-use-after-return complaints.