-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[NFC] Fixes proposed by code sanitizer. #134138
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
Conversation
@llvm/pr-subscribers-clang-tools-extra Author: Zahira Ammarguellat (zahiraam) ChangesFull diff: https://github.com/llvm/llvm-project/pull/134138.diff 3 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
index bafcd402ca851..7650d9e8a592f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
@@ -260,7 +260,7 @@ static IntegerRange createFromType(const ASTContext &Context,
llvm::APSInt LowerValue(PrecisionBits + 2, /*isUnsigned*/ false);
LowerValue.setBit(PrecisionBits);
LowerValue.setSignBit();
- return {LowerValue, UpperValue};
+ return {std::move(LowerValue), UpperValue};
}
assert(T.isInteger() && "Unexpected builtin type");
uint64_t TypeSize = Context.getTypeSize(&T);
diff --git a/clang-tools-extra/clangd/ConfigCompile.cpp b/clang-tools-extra/clangd/ConfigCompile.cpp
index 3d7f792aa136b..13c2405e76df7 100644
--- a/clang-tools-extra/clangd/ConfigCompile.cpp
+++ b/clang-tools-extra/clangd/ConfigCompile.cpp
@@ -535,7 +535,7 @@ struct FragmentCompiler {
}
if (Filters->empty())
return std::nullopt;
- auto Filter = [Filters](llvm::StringRef Path) {
+ auto Filter = [Filters = std::move(Filters)](llvm::StringRef Path) {
for (auto &Regex : *Filters)
if (Regex.match(Path))
return true;
diff --git a/clang-tools-extra/clangd/Headers.cpp b/clang-tools-extra/clangd/Headers.cpp
index 0ffd9ee4d2751..0d43ada87d359 100644
--- a/clang-tools-extra/clangd/Headers.cpp
+++ b/clang-tools-extra/clangd/Headers.cpp
@@ -305,7 +305,7 @@ IncludeInserter::calculateIncludePath(const HeaderFile &InsertedHeader,
if (llvm::sys::path::is_absolute(Suggested))
return std::nullopt;
bool IsAngled = false;
- for (auto Filter : AngledHeaders) {
+ for (auto &Filter : AngledHeaders) {
if (Filter(Suggested)) {
IsAngled = true;
break;
|
@llvm/pr-subscribers-clang-tidy Author: Zahira Ammarguellat (zahiraam) ChangesFull diff: https://github.com/llvm/llvm-project/pull/134138.diff 3 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
index bafcd402ca851..7650d9e8a592f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
@@ -260,7 +260,7 @@ static IntegerRange createFromType(const ASTContext &Context,
llvm::APSInt LowerValue(PrecisionBits + 2, /*isUnsigned*/ false);
LowerValue.setBit(PrecisionBits);
LowerValue.setSignBit();
- return {LowerValue, UpperValue};
+ return {std::move(LowerValue), UpperValue};
}
assert(T.isInteger() && "Unexpected builtin type");
uint64_t TypeSize = Context.getTypeSize(&T);
diff --git a/clang-tools-extra/clangd/ConfigCompile.cpp b/clang-tools-extra/clangd/ConfigCompile.cpp
index 3d7f792aa136b..13c2405e76df7 100644
--- a/clang-tools-extra/clangd/ConfigCompile.cpp
+++ b/clang-tools-extra/clangd/ConfigCompile.cpp
@@ -535,7 +535,7 @@ struct FragmentCompiler {
}
if (Filters->empty())
return std::nullopt;
- auto Filter = [Filters](llvm::StringRef Path) {
+ auto Filter = [Filters = std::move(Filters)](llvm::StringRef Path) {
for (auto &Regex : *Filters)
if (Regex.match(Path))
return true;
diff --git a/clang-tools-extra/clangd/Headers.cpp b/clang-tools-extra/clangd/Headers.cpp
index 0ffd9ee4d2751..0d43ada87d359 100644
--- a/clang-tools-extra/clangd/Headers.cpp
+++ b/clang-tools-extra/clangd/Headers.cpp
@@ -305,7 +305,7 @@ IncludeInserter::calculateIncludePath(const HeaderFile &InsertedHeader,
if (llvm::sys::path::is_absolute(Suggested))
return std::nullopt;
bool IsAngled = false;
- for (auto Filter : AngledHeaders) {
+ for (auto &Filter : AngledHeaders) {
if (Filter(Suggested)) {
IsAngled = true;
break;
|
@llvm/pr-subscribers-clangd Author: Zahira Ammarguellat (zahiraam) ChangesFull diff: https://github.com/llvm/llvm-project/pull/134138.diff 3 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
index bafcd402ca851..7650d9e8a592f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
@@ -260,7 +260,7 @@ static IntegerRange createFromType(const ASTContext &Context,
llvm::APSInt LowerValue(PrecisionBits + 2, /*isUnsigned*/ false);
LowerValue.setBit(PrecisionBits);
LowerValue.setSignBit();
- return {LowerValue, UpperValue};
+ return {std::move(LowerValue), UpperValue};
}
assert(T.isInteger() && "Unexpected builtin type");
uint64_t TypeSize = Context.getTypeSize(&T);
diff --git a/clang-tools-extra/clangd/ConfigCompile.cpp b/clang-tools-extra/clangd/ConfigCompile.cpp
index 3d7f792aa136b..13c2405e76df7 100644
--- a/clang-tools-extra/clangd/ConfigCompile.cpp
+++ b/clang-tools-extra/clangd/ConfigCompile.cpp
@@ -535,7 +535,7 @@ struct FragmentCompiler {
}
if (Filters->empty())
return std::nullopt;
- auto Filter = [Filters](llvm::StringRef Path) {
+ auto Filter = [Filters = std::move(Filters)](llvm::StringRef Path) {
for (auto &Regex : *Filters)
if (Regex.match(Path))
return true;
diff --git a/clang-tools-extra/clangd/Headers.cpp b/clang-tools-extra/clangd/Headers.cpp
index 0ffd9ee4d2751..0d43ada87d359 100644
--- a/clang-tools-extra/clangd/Headers.cpp
+++ b/clang-tools-extra/clangd/Headers.cpp
@@ -305,7 +305,7 @@ IncludeInserter::calculateIncludePath(const HeaderFile &InsertedHeader,
if (llvm::sys::path::is_absolute(Suggested))
return std::nullopt;
bool IsAngled = false;
- for (auto Filter : AngledHeaders) {
+ for (auto &Filter : AngledHeaders) {
if (Filter(Suggested)) {
IsAngled = true;
break;
|
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.
LGTM
@@ -260,7 +260,7 @@ static IntegerRange createFromType(const ASTContext &Context, | |||
llvm::APSInt LowerValue(PrecisionBits + 2, /*isUnsigned*/ false); | |||
LowerValue.setBit(PrecisionBits); | |||
LowerValue.setSignBit(); | |||
return {LowerValue, UpperValue}; | |||
return {std::move(LowerValue), UpperValue}; |
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 doesn't have any impact.
And if using move, why not for a second too
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.
Isn't this actually an antipattern? What exactly do you mean by "code sanitizer", can you show the actual error message?
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 is the error message:
" LowerValue is passed-by-value as parameter to llvm::APSInt::APSInt(llvm::APSInt const &) /implicit =default/, when it could be moved instead"
"Use std::move(LowerValue) instead of LowerValue."
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.
Do you think this should be reverted?
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 doesn't have any impact. And if using move, why not for a second too
Good point. I was only addressing the issues that the sanitizer identified.
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.
What tool did you use to get that error message?
I do not see the point of this change, please revert. We must not blindly do what tools tell us, we must critically think if they make sense or not.
@@ -305,7 +305,7 @@ IncludeInserter::calculateIncludePath(const HeaderFile &InsertedHeader, | |||
if (llvm::sys::path::is_absolute(Suggested)) | |||
return std::nullopt; | |||
bool IsAngled = false; | |||
for (auto Filter : AngledHeaders) { | |||
for (auto &Filter : AngledHeaders) { |
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.
same thing in line 315
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 changes to the clang-tidy check should be reverted IMO.
Also, please provide more information. What do you mean by "code sanitizer", what is the exact error message, etc.
Please see above the error message from sanitizer. I can revert the change if you think the don't make sense. |
@@ -535,7 +535,7 @@ struct FragmentCompiler { | |||
} | |||
if (Filters->empty()) | |||
return std::nullopt; | |||
auto Filter = [Filters](llvm::StringRef Path) { | |||
auto Filter = [Filters = std::move(Filters)](llvm::StringRef Path) { |
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.
Line 520: this can now be a make_unique
.
@@ -535,7 +535,7 @@ struct FragmentCompiler { | |||
} | |||
if (Filters->empty()) | |||
return std::nullopt; | |||
auto Filter = [Filters](llvm::StringRef Path) { | |||
auto Filter = [Filters = std::move(Filters)](llvm::StringRef Path) { | |||
for (auto &Regex : *Filters) |
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.
for (auto &Regex : *Filters) | |
for (const auto &Regex : *Filters) |
Same for both cases in other file.
In general, I don't fully understand the scope of this patch. Surely, there's thousands of things that could be improved in the codebase. Which of those belong to this patch? Reviewers can always point out things that could be improved ad infinitum, leading to a patch with lots of unrelated changes. When do we decide that we are done? |
I totally agree. Our code sanitizer points us to many edits that are most of the time false positive. I have proposed in this PR fixes that I have judged might be real issues (I might be wrong). |
No description provided.