Skip to content

Commit 3196d3c

Browse files
committed
Merge from 'main' to 'sycl-web' (187 commits)
CONFLICT (content): Merge conflict in clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
2 parents 1842fa3 + 0f6cbde commit 3196d3c

File tree

639 files changed

+38423
-9658
lines changed

Some content is hidden

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

639 files changed

+38423
-9658
lines changed

clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp

Lines changed: 74 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -201,30 +201,42 @@ void PreferMemberInitializerCheck::check(
201201
diag(S->getBeginLoc(), "%0 should be initialized in an in-class"
202202
" default member initializer")
203203
<< Field;
204-
if (!InvalidFix) {
205-
CharSourceRange StmtRange =
206-
CharSourceRange::getCharRange(S->getBeginLoc(), SemiColonEnd);
207-
208-
SmallString<128> Insertion(
209-
{UseAssignment ? " = " : "{",
210-
Lexer::getSourceText(
211-
CharSourceRange(InitValue->getSourceRange(), true),
212-
*Result.SourceManager, getLangOpts()),
213-
UseAssignment ? "" : "}"});
214-
215-
Diag << FixItHint::CreateInsertion(FieldEnd, Insertion)
216-
<< FixItHint::CreateRemoval(StmtRange);
217-
}
204+
if (InvalidFix)
205+
continue;
206+
CharSourceRange StmtRange =
207+
CharSourceRange::getCharRange(S->getBeginLoc(), SemiColonEnd);
208+
209+
SmallString<128> Insertion(
210+
{UseAssignment ? " = " : "{",
211+
Lexer::getSourceText(
212+
CharSourceRange(InitValue->getSourceRange(), true),
213+
*Result.SourceManager, getLangOpts()),
214+
UseAssignment ? "" : "}"});
215+
216+
Diag << FixItHint::CreateInsertion(FieldEnd, Insertion)
217+
<< FixItHint::CreateRemoval(StmtRange);
218+
218219
} else {
219220
StringRef InsertPrefix = "";
221+
bool HasInitAlready = false;
220222
SourceLocation InsertPos;
223+
SourceRange ReplaceRange;
221224
bool AddComma = false;
222225
bool InvalidFix = false;
223226
unsigned Index = Field->getFieldIndex();
224227
const CXXCtorInitializer *LastInListInit = nullptr;
225228
for (const CXXCtorInitializer *Init : Ctor->inits()) {
226-
if (!Init->isWritten())
229+
if (!Init->isWritten() || Init->isInClassMemberInitializer())
227230
continue;
231+
if (Init->getMember() == Field) {
232+
HasInitAlready = true;
233+
if (isa<ImplicitValueInitExpr>(Init->getInit()))
234+
InsertPos = Init->getRParenLoc();
235+
else {
236+
ReplaceRange = Init->getInit()->getSourceRange();
237+
}
238+
break;
239+
}
228240
if (Init->isMemberInitializer() &&
229241
Index < Init->getMember()->getFieldIndex()) {
230242
InsertPos = Init->getSourceLocation();
@@ -235,30 +247,38 @@ void PreferMemberInitializerCheck::check(
235247
}
236248
LastInListInit = Init;
237249
}
238-
if (InsertPos.isInvalid()) {
239-
if (LastInListInit) {
240-
InsertPos = Lexer::getLocForEndOfToken(
241-
LastInListInit->getRParenLoc(), 0, *Result.SourceManager,
242-
getLangOpts());
243-
// Inserting after the last constructor initializer, so we need a
244-
// comma.
245-
InsertPrefix = ", ";
246-
} else {
247-
InsertPos = Lexer::getLocForEndOfToken(
248-
Ctor->getTypeSourceInfo()
249-
->getTypeLoc()
250-
.getAs<clang::FunctionTypeLoc>()
251-
.getLocalRangeEnd(),
252-
0, *Result.SourceManager, getLangOpts());
253-
254-
// If this is first time in the loop, there are no initializers so
255-
// `:` declares member initialization list. If this is a subsequent
256-
// pass then we have already inserted a `:` so continue with a
257-
// comma.
258-
InsertPrefix = FirstToCtorInits ? " : " : ", ";
250+
if (HasInitAlready) {
251+
if (InsertPos.isValid())
252+
InvalidFix |= InsertPos.isMacroID();
253+
else
254+
InvalidFix |= ReplaceRange.getBegin().isMacroID() ||
255+
ReplaceRange.getEnd().isMacroID();
256+
} else {
257+
if (InsertPos.isInvalid()) {
258+
if (LastInListInit) {
259+
InsertPos = Lexer::getLocForEndOfToken(
260+
LastInListInit->getRParenLoc(), 0, *Result.SourceManager,
261+
getLangOpts());
262+
// Inserting after the last constructor initializer, so we need a
263+
// comma.
264+
InsertPrefix = ", ";
265+
} else {
266+
InsertPos = Lexer::getLocForEndOfToken(
267+
Ctor->getTypeSourceInfo()
268+
->getTypeLoc()
269+
.getAs<clang::FunctionTypeLoc>()
270+
.getLocalRangeEnd(),
271+
0, *Result.SourceManager, getLangOpts());
272+
273+
// If this is first time in the loop, there are no initializers so
274+
// `:` declares member initialization list. If this is a
275+
// subsequent pass then we have already inserted a `:` so continue
276+
// with a comma.
277+
InsertPrefix = FirstToCtorInits ? " : " : ", ";
278+
}
259279
}
280+
InvalidFix |= InsertPos.isMacroID();
260281
}
261-
InvalidFix |= InsertPos.isMacroID();
262282

263283
SourceLocation SemiColonEnd;
264284
if (auto NextToken = Lexer::findNextToken(
@@ -271,21 +291,25 @@ void PreferMemberInitializerCheck::check(
271291
diag(S->getBeginLoc(), "%0 should be initialized in a member"
272292
" initializer of the constructor")
273293
<< Field;
274-
if (!InvalidFix) {
275-
276-
CharSourceRange StmtRange =
277-
CharSourceRange::getCharRange(S->getBeginLoc(), SemiColonEnd);
278-
SmallString<128> Insertion(
279-
{InsertPrefix, Field->getName(), "(",
280-
Lexer::getSourceText(
281-
CharSourceRange(InitValue->getSourceRange(), true),
282-
*Result.SourceManager, getLangOpts()),
283-
AddComma ? "), " : ")"});
294+
if (InvalidFix)
295+
continue;
296+
StringRef NewInit = Lexer::getSourceText(
297+
CharSourceRange(InitValue->getSourceRange(), true),
298+
*Result.SourceManager, getLangOpts());
299+
if (HasInitAlready) {
300+
if (InsertPos.isValid())
301+
Diag << FixItHint::CreateInsertion(InsertPos, NewInit);
302+
else
303+
Diag << FixItHint::CreateReplacement(ReplaceRange, NewInit);
304+
} else {
305+
SmallString<128> Insertion({InsertPrefix, Field->getName(), "(",
306+
NewInit, AddComma ? "), " : ")"});
284307
Diag << FixItHint::CreateInsertion(InsertPos, Insertion,
285-
FirstToCtorInits)
286-
<< FixItHint::CreateRemoval(StmtRange);
287-
FirstToCtorInits = false;
308+
FirstToCtorInits);
288309
}
310+
Diag << FixItHint::CreateRemoval(
311+
CharSourceRange::getCharRange(S->getBeginLoc(), SemiColonEnd));
312+
FirstToCtorInits = false;
289313
}
290314
}
291315
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ ast_matchers::internal::Matcher<Expr> supportedContainerTypesMatcher() {
6868
"::std::unordered_map", "::std::array", "::std::deque")));
6969
}
7070

71+
AST_MATCHER(Expr, hasSideEffects) {
72+
return Node.HasSideEffects(Finder->getASTContext());
73+
}
74+
7175
} // namespace
7276

7377
InefficientVectorOperationCheck::InefficientVectorOperationCheck(
@@ -145,7 +149,10 @@ void InefficientVectorOperationCheck::addMatcher(
145149
// FIXME: Support more complex range-expressions.
146150
Finder->addMatcher(
147151
cxxForRangeStmt(
148-
hasRangeInit(declRefExpr(supportedContainerTypesMatcher())),
152+
hasRangeInit(
153+
anyOf(declRefExpr(supportedContainerTypesMatcher()),
154+
memberExpr(hasObjectExpression(unless(hasSideEffects())),
155+
supportedContainerTypesMatcher()))),
149156
HasInterestingLoopBody, InInterestingCompoundStmt)
150157
.bind(RangeLoopName),
151158
this);

clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ std::string NewFunction::renderDeclaration(FunctionDeclKind K,
479479
llvm::formatv("{0} {\n{1}\n}\n", Declaration, getFuncBody(SM)));
480480
break;
481481
}
482+
llvm_unreachable("Unsupported FunctionDeclKind enum");
482483
}
483484

484485
std::string NewFunction::getFuncBody(const SourceManager &SM) const {

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ New check aliases
127127
Changes in existing checks
128128
^^^^^^^^^^^^^^^^^^^^^^^^^^
129129

130+
- Improved :doc:`performance-inefficient-vector-operation
131+
<clang-tidy/checks/performance-inefficient-vector-operation>` to work when
132+
the vector is a member of a structure.
133+
130134
- Fixed a false positive in :doc:`readability-non-const-parameter
131135
<clang-tidy/checks/readability-non-const-parameter>` when the parameter is referenced by an lvalue
132136

@@ -139,6 +143,12 @@ Changes in existing checks
139143

140144
- Fixed a crash in :doc:`bugprone-sizeof-expression <clang-tidy/checks/bugprone-sizeof-expression>` when
141145
`sizeof(...)` is compared agains a `__int128_t`.
146+
147+
- Improved :doc:`cppcoreguidelines-prefer-member-initializer
148+
<clang-tidy/checks/cppcoreguidelines-prefer-member-initializer>` check.
149+
150+
Fixed an issue when there was already an initializer in the constructor and
151+
the check would try to create another initializer for the same member.
142152

143153
Removed checks
144154
^^^^^^^^^^^^^^

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,14 +526,32 @@ struct InitFromVarDecl {
526526
}
527527
};
528528

529-
struct AlreadyHasInit {
529+
struct HasInClassInit {
530530
int m = 4;
531-
AlreadyHasInit() {
531+
HasInClassInit() {
532532
m = 3;
533533
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'm' should be initialized in a member initializer of the constructor
534534
}
535535
};
536536

537+
struct HasInitListInit {
538+
int M;
539+
// CHECK-MESSAGES: :[[@LINE+5]]:5: warning: 'M' should be initialized in a member initializer of the constructor
540+
// CHECK-FIXES: HasInitListInit(const HasInitListInit &Other) : M(Other.M) {
541+
// CHECK-FIXES-NEXT: {{^ $}}
542+
// CHECK-FIXES-NEXT: }
543+
HasInitListInit(const HasInitListInit &Other) : M(4) {
544+
M = Other.M;
545+
}
546+
// CHECK-MESSAGES: :[[@LINE+5]]:5: warning: 'M' should be initialized in a member initializer of the constructor
547+
// CHECK-FIXES: HasInitListInit(HasInitListInit &&Other) : M(Other.M) {
548+
// CHECK-FIXES-NEXT: {{^ $}}
549+
// CHECK-FIXES-NEXT: }
550+
HasInitListInit(HasInitListInit &&Other) : M() {
551+
M = Other.M;
552+
}
553+
};
554+
537555
#define ASSIGN_IN_MACRO(FIELD, VALUE) FIELD = (VALUE);
538556

539557
struct MacroCantFix {

clang-tools-extra/test/clang-tidy/checkers/performance-inefficient-vector-operation.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class vector {
4444
void reserve(size_t n);
4545
void resize(size_t n);
4646

47-
size_t size();
47+
size_t size() const;
4848
const_reference operator[] (size_type) const;
4949
reference operator[] (size_type);
5050

@@ -359,3 +359,31 @@ void f(std::vector<int>& t) {
359359
}
360360
}
361361
}
362+
363+
struct StructWithFieldContainer {
364+
std::vector<int> Numbers;
365+
std::vector<int> getNumbers() const {
366+
std::vector<int> Result;
367+
// CHECK-FIXES: Result.reserve(Numbers.size());
368+
for (auto Number : Numbers) {
369+
Result.push_back(Number);
370+
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'push_back' is called
371+
}
372+
return Result;
373+
}
374+
};
375+
376+
StructWithFieldContainer getStructWithField();
377+
378+
void foo(const StructWithFieldContainer &Src) {
379+
std::vector<int> A;
380+
// CHECK-FIXES: A.reserve(Src.Numbers.size());
381+
for (auto Number : Src.Numbers) {
382+
A.push_back(Number);
383+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'push_back' is called
384+
}
385+
std::vector<int> B;
386+
for (auto Number : getStructWithField().Numbers) {
387+
B.push_back(Number);
388+
}
389+
}

clang/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ set(PPC_LINUX_DEFAULT_IEEELONGDOUBLE OFF CACHE BOOL
245245
set(CLANG_SPAWN_CC1 OFF CACHE BOOL
246246
"Whether clang should use a new process for the CC1 invocation")
247247

248-
option(CLANG_DEFAULT_PIE_ON_LINUX "Default to -fPIE and -pie on linux-gnu" ON)
248+
option(CLANG_DEFAULT_PIE_ON_LINUX "Default to -fPIE and -pie on Linux" OFF)
249249

250250
# Manually handle default so we can change the meaning of a cached default.
251251
set(CLANG_ENABLE_OPAQUE_POINTERS "DEFAULT" CACHE STRING

clang/docs/ClangCommandLineReference.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,10 +2093,6 @@ Emit OpenMP code only for SIMD-based constructs.
20932093

20942094
Enable debugging in the OpenMP offloading device RTL
20952095

2096-
.. option:: -fopenmp-target-new-runtime, -fno-openmp-target-new-runtime
2097-
2098-
Use the new bitcode library for OpenMP offloading
2099-
21002096
.. option:: -fopenmp-offload-mandatory
21012097

21022098
Indicate that offloading to the device is mandatory and do not generate host-fallback code.

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,6 @@ Internal API Changes
298298
Build System Changes
299299
--------------------
300300

301-
* CMake ``-DCLANG_DEFAULT_PIE_ON_LINUX=ON`` is now the default. This is used by
302-
linux-gnu systems to decide whether ``-fPIE -pie`` is the default (instead of
303-
``-fno-pic -no-pie``). This matches GCC installations on many Linux distros.
304-
Note: linux-android and linux-musl always default to ``-fPIE -pie``, ignoring
305-
this variable. ``-DCLANG_DEFAULT_PIE_ON_LINUX`` may be removed in the future.
306-
307301
AST Matchers
308302
------------
309303

clang/include/clang/AST/DeclarationName.h

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "clang/Basic/SourceLocation.h"
2222
#include "llvm/ADT/DenseMapInfo.h"
2323
#include "llvm/ADT/FoldingSet.h"
24+
#include "llvm/ADT/STLExtras.h"
2425
#include "llvm/Support/Compiler.h"
2526
#include "llvm/Support/type_traits.h"
2627
#include <cassert>
@@ -192,6 +193,13 @@ class DeclarationName {
192193
"The various classes that DeclarationName::Ptr can point to"
193194
" must be at least aligned to 8 bytes!");
194195

196+
static_assert(
197+
std::is_same<std::underlying_type_t<StoredNameKind>,
198+
std::underlying_type_t<
199+
detail::DeclarationNameExtra::ExtraKind>>::value,
200+
"The various enums used to compute values for NameKind should "
201+
"all have the same underlying type");
202+
195203
public:
196204
/// The kind of the name stored in this DeclarationName.
197205
/// The first 7 enumeration values are stored inline and correspond
@@ -205,15 +213,18 @@ class DeclarationName {
205213
CXXDestructorName = StoredCXXDestructorName,
206214
CXXConversionFunctionName = StoredCXXConversionFunctionName,
207215
CXXOperatorName = StoredCXXOperatorName,
208-
CXXDeductionGuideName = UncommonNameKindOffset +
209-
detail::DeclarationNameExtra::CXXDeductionGuideName,
210-
CXXLiteralOperatorName =
211-
UncommonNameKindOffset +
212-
detail::DeclarationNameExtra::CXXLiteralOperatorName,
213-
CXXUsingDirective = UncommonNameKindOffset +
214-
detail::DeclarationNameExtra::CXXUsingDirective,
215-
ObjCMultiArgSelector = UncommonNameKindOffset +
216-
detail::DeclarationNameExtra::ObjCMultiArgSelector
216+
CXXDeductionGuideName = llvm::addEnumValues(
217+
UncommonNameKindOffset,
218+
detail::DeclarationNameExtra::CXXDeductionGuideName),
219+
CXXLiteralOperatorName = llvm::addEnumValues(
220+
UncommonNameKindOffset,
221+
detail::DeclarationNameExtra::CXXLiteralOperatorName),
222+
CXXUsingDirective =
223+
llvm::addEnumValues(UncommonNameKindOffset,
224+
detail::DeclarationNameExtra::CXXUsingDirective),
225+
ObjCMultiArgSelector =
226+
llvm::addEnumValues(UncommonNameKindOffset,
227+
detail::DeclarationNameExtra::ObjCMultiArgSelector),
217228
};
218229

219230
private:

0 commit comments

Comments
 (0)