Skip to content

Commit f4078bf

Browse files
authored
Merge branch 'main' into hgh/libcxx/P2255R2-A_type_trait_to_detect_reference_binding_to_temporary
2 parents 8be8079 + 4277c21 commit f4078bf

File tree

429 files changed

+9916
-10204
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

429 files changed

+9916
-10204
lines changed

clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "UnnecessaryValueParamCheck.h"
10-
1110
#include "../utils/DeclRefExprUtils.h"
1211
#include "../utils/FixItHintUtils.h"
1312
#include "../utils/Matchers.h"
@@ -30,14 +29,6 @@ std::string paramNameOrIndex(StringRef Name, size_t Index) {
3029
.str();
3130
}
3231

33-
bool isReferencedOutsideOfCallExpr(const FunctionDecl &Function,
34-
ASTContext &Context) {
35-
auto Matches = match(declRefExpr(to(functionDecl(equalsNode(&Function))),
36-
unless(hasAncestor(callExpr()))),
37-
Context);
38-
return !Matches.empty();
39-
}
40-
4132
bool hasLoopStmtAncestor(const DeclRefExpr &DeclRef, const Decl &Decl,
4233
ASTContext &Context) {
4334
auto Matches = match(
@@ -155,12 +146,9 @@ void UnnecessaryValueParamCheck::handleConstRefFix(const FunctionDecl &Function,
155146
// Do not propose fixes when:
156147
// 1. the ParmVarDecl is in a macro, since we cannot place them correctly
157148
// 2. the function is virtual as it might break overrides
158-
// 3. the function is referenced outside of a call expression within the
159-
// compilation unit as the signature change could introduce build errors.
160-
// 4. the function is an explicit template/ specialization.
149+
// 3. the function is an explicit template/ specialization.
161150
const auto *Method = llvm::dyn_cast<CXXMethodDecl>(&Function);
162151
if (Param.getBeginLoc().isMacroID() || (Method && Method->isVirtual()) ||
163-
isReferencedOutsideOfCallExpr(Function, Context) ||
164152
Function.getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
165153
return;
166154
for (const auto *FunctionDecl = &Function; FunctionDecl != nullptr;

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ Changes in existing checks
115115
<clang-tidy/checks/misc/redundant-expression>` check by providing additional
116116
examples and fixing some macro related false positives.
117117

118+
- Improved :doc:`performance/unnecessary-value-param
119+
<clang-tidy/checks/performance/unnecessary-value-param>` check performance by
120+
tolerating fix-it breaking compilation when functions is used as pointers
121+
to avoid matching usage of functions within the current compilation unit.
122+
118123
Removed checks
119124
^^^^^^^^^^^^^^
120125

clang-tools-extra/docs/clang-tidy/checks/performance/unnecessary-value-param.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ Will become:
5454
Field = std::move(Value);
5555
}
5656

57+
Because the fix-it needs to change the signature of the function, it may break
58+
builds if the function is used in multiple translation units or some codes
59+
depends on funcion signatures.
60+
5761
Options
5862
-------
5963

clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-value-param.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,7 @@ void PositiveNonConstDeclaration(const ExpensiveToCopyType A) {
332332

333333
void PositiveOnlyMessageAsReferencedInCompilationUnit(ExpensiveToCopyType A) {
334334
// CHECK-MESSAGES: [[@LINE-1]]:75: warning: the parameter 'A' is copied
335-
// CHECK-FIXES: void PositiveOnlyMessageAsReferencedInCompilationUnit(ExpensiveToCopyType A) {
336-
}
337-
338-
void ReferenceFunctionOutsideOfCallExpr() {
339-
void (*ptr)(ExpensiveToCopyType) = &PositiveOnlyMessageAsReferencedInCompilationUnit;
335+
// CHECK-FIXES: void PositiveOnlyMessageAsReferencedInCompilationUnit(const ExpensiveToCopyType& A) {
340336
}
341337

342338
void PositiveMessageAndFixAsFunctionIsCalled(ExpensiveToCopyType A) {

clang/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ using namespace ento;
2323
namespace {
2424
class UndefinedAssignmentChecker
2525
: public Checker<check::Bind> {
26-
const BugType BT{this, "Assigned value is garbage or undefined"};
26+
const BugType BT{this, "Assigned value is uninitialized"};
2727

2828
public:
2929
void checkBind(SVal location, SVal val, const Stmt *S,
@@ -57,8 +57,7 @@ void UndefinedAssignmentChecker::checkBind(SVal location, SVal val,
5757

5858
while (StoreE) {
5959
if (const UnaryOperator *U = dyn_cast<UnaryOperator>(StoreE)) {
60-
OS << "The expression is an uninitialized value. "
61-
"The computed value will also be garbage";
60+
OS << "The expression uses uninitialized memory";
6261

6362
ex = U->getSubExpr();
6463
break;
@@ -67,8 +66,8 @@ void UndefinedAssignmentChecker::checkBind(SVal location, SVal val,
6766
if (const BinaryOperator *B = dyn_cast<BinaryOperator>(StoreE)) {
6867
if (B->isCompoundAssignmentOp()) {
6968
if (C.getSVal(B->getLHS()).isUndef()) {
70-
OS << "The left expression of the compound assignment is an "
71-
"uninitialized value. The computed value will also be garbage";
69+
OS << "The left expression of the compound assignment uses "
70+
<< "uninitialized memory";
7271
ex = B->getLHS();
7372
break;
7473
}
@@ -89,7 +88,7 @@ void UndefinedAssignmentChecker::checkBind(SVal location, SVal val,
8988
for (auto *I : CD->inits()) {
9089
if (I->getInit()->IgnoreImpCasts() == StoreE) {
9190
OS << "Value assigned to field '" << I->getMember()->getName()
92-
<< "' in implicit constructor is garbage or undefined";
91+
<< "' in implicit constructor is uninitialized";
9392
break;
9493
}
9594
}

clang/test/Analysis/Inputs/expected-plists/edges-new.mm.plist

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,17 +2578,17 @@
25782578
</array>
25792579
<key>depth</key><integer>0</integer>
25802580
<key>extended_message</key>
2581-
<string>The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage</string>
2581+
<string>The left expression of the compound assignment uses uninitialized memory</string>
25822582
<key>message</key>
2583-
<string>The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage</string>
2583+
<string>The left expression of the compound assignment uses uninitialized memory</string>
25842584
</dict>
25852585
</array>
2586-
<key>description</key><string>The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage</string>
2586+
<key>description</key><string>The left expression of the compound assignment uses uninitialized memory</string>
25872587
<key>category</key><string>Logic error</string>
2588-
<key>type</key><string>Assigned value is garbage or undefined</string>
2588+
<key>type</key><string>Assigned value is uninitialized</string>
25892589
<key>check_name</key><string>core.uninitialized.Assign</string>
25902590
<!-- This hash is experimental and going to change! -->
2591-
<key>issue_hash_content_of_line_in_context</key><string>025372576cd3ba6716044f93a51c978c</string>
2591+
<key>issue_hash_content_of_line_in_context</key><string>324827600c298776167cd9562f71bda6</string>
25922592
<key>issue_context_kind</key><string>function</string>
25932593
<key>issue_context</key><string>test_objc_fast_enumeration_2</string>
25942594
<key>issue_hash_function_offset</key><string>5</string>

clang/test/Analysis/Inputs/expected-plists/plist-output.m.plist

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5864,17 +5864,17 @@
58645864
</array>
58655865
<key>depth</key><integer>0</integer>
58665866
<key>extended_message</key>
5867-
<string>The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage</string>
5867+
<string>The left expression of the compound assignment uses uninitialized memory</string>
58685868
<key>message</key>
5869-
<string>The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage</string>
5869+
<string>The left expression of the compound assignment uses uninitialized memory</string>
58705870
</dict>
58715871
</array>
5872-
<key>description</key><string>The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage</string>
5872+
<key>description</key><string>The left expression of the compound assignment uses uninitialized memory</string>
58735873
<key>category</key><string>Logic error</string>
5874-
<key>type</key><string>Assigned value is garbage or undefined</string>
5874+
<key>type</key><string>Assigned value is uninitialized</string>
58755875
<key>check_name</key><string>core.uninitialized.Assign</string>
58765876
<!-- This hash is experimental and going to change! -->
5877-
<key>issue_hash_content_of_line_in_context</key><string>21c774309bdfd487c3d09a61a671bbcc</string>
5877+
<key>issue_hash_content_of_line_in_context</key><string>faa8858031ed123ff98cc23cf14d462f</string>
58785878
<key>issue_context_kind</key><string>function</string>
58795879
<key>issue_context</key><string>test_loop_fast_enumeration</string>
58805880
<key>issue_hash_function_offset</key><string>5</string>

clang/test/Analysis/a_flaky_crash.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ bool bar(S);
1414
void foo() {
1515
int x;
1616
if (true && bar(S()))
17-
++x; // expected-warning{{The expression is an uninitialized value. The computed value will also be garbage}}
17+
++x; // expected-warning{{The expression uses uninitialized memory}}
1818
}
1919

2020
// 256 copies of the same run-line to make it crash more often when it breaks.

clang/test/Analysis/analysis-after-multiple-dtors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ int main() {
2323

2424
int x;
2525
int y = x;
26-
// expected-warning@-1{{Assigned value is garbage or undefined}}
26+
// expected-warning@-1{{Assigned value is uninitialized}}
2727
(void)y;
2828
}

clang/test/Analysis/array-init-loop.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void array_uninit() {
1919

2020
auto [a, b, c, d, e] = arr;
2121

22-
int x = e; // expected-warning{{Assigned value is garbage or undefined}}
22+
int x = e; // expected-warning{{Assigned value is uninitialized}}
2323
}
2424

2525
void lambda_init() {
@@ -168,7 +168,7 @@ struct S3_duplicate {
168168
void array_uninit_non_pod() {
169169
S3 arr[1];
170170

171-
auto [a] = arr; // expected-warning@159{{ in implicit constructor is garbage or undefined }}
171+
auto [a] = arr; // expected-warning@159{{ in implicit constructor is uninitialized}}
172172
}
173173

174174
void lambda_init_non_pod() {
@@ -191,7 +191,7 @@ void lambda_init_non_pod() {
191191
void lambda_uninit_non_pod() {
192192
S3_duplicate arr[4];
193193

194-
int l = [arr] { return arr[3].i; }(); // expected-warning@164{{ in implicit constructor is garbage or undefined }}
194+
int l = [arr] { return arr[3].i; }(); // expected-warning@164{{ in implicit constructor is uninitialized }}
195195
}
196196

197197
// If this struct is being copy/move constructed by the implicit ctors, ArrayInitLoopExpr

0 commit comments

Comments
 (0)