157 changes: 155 additions & 2 deletions clang/test/SemaCXX/warn-range-loop-analysis.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wall -Wno-unused -verify %s
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wloop-analysis -verify %s
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wrange-loop-analysis -verify %s
// RUN: %clang_cc1 -fsyntax-only -std=c++11 -Wloop-analysis -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s

template <typename return_type>
struct Iterator {
Expand Down Expand Up @@ -67,44 +69,62 @@ void test0() {
for (const int &x : int_non_ref_container) {}
// expected-warning@-1 {{loop variable 'x' is always a copy because the range of type 'Container<int>' does not return a reference}}
// expected-note@-2 {{use non-reference type 'int'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""

for (const double &x : int_container) {}
// expected-warning@-1 {{loop variable 'x' has type 'const double &' but is initialized with type 'int' resulting in a copy}}
// expected-note@-2 {{use non-reference type 'double' to keep the copy or type 'const int &' to prevent copying}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:21-[[@LINE-3]]:22}:""

for (const Bar x : bar_container) {}
// expected-warning@-1 {{loop variable 'x' of type 'const Bar' creates a copy from type 'const Bar'}}
// expected-note@-2 {{use reference type 'const Bar &' to prevent copying}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:18}:"&"
}

void test1() {
Container<int> A;

for (const int &&x : A) {}
// No warning, rvalue-reference to the temporary
for (const int &x : A) {}
// expected-warning@-1 {{always a copy}}
// expected-note@-2 {{'int'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
for (const int x : A) {}
// No warning, non-reference type indicates copy is made
for (int&& x : A) {}
// No warning, rvalue-reference to the temporary
//for (int &x : A) {}
// Binding error
for (int x : A) {}
// No warning, non-reference type indicates copy is made

for (const double &&x : A) {}
// No warning, rvalue-reference to the temporary
for (const double &x : A) {}
// expected-warning@-1 {{always a copy}}
// expected-note@-2 {{'double'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:21-[[@LINE-3]]:22}:""
for (const double x : A) {}
// No warning, non-reference type indicates copy is made
for (double &&x : A) {}
// No warning, rvalue-reference to the temporary
//for (double &x : A) {}
// Binding error
for (double x : A) {}
// No warning, non-reference type indicates copy is made

for (const Bar &&x : A) {}
// No warning, rvalue-reference to the temporary
for (const Bar &x : A) {}
// expected-warning@-1 {{always a copy}}
// expected-note@-2 {{'Bar'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
for (const Bar x : A) {}
// No warning, non-reference type indicates copy is made
for (Bar &&x : A) {}
// No warning, rvalue-reference to the temporary
//for (Bar &x : A) {}
// Binding error
for (Bar x : A) {}
Expand All @@ -114,28 +134,50 @@ void test1() {
void test2() {
Container<int&> B;

//for (const int &&x : B) {}
// Binding error
for (const int &x : B) {}
// No warning, this reference is not a temporary
for (const int x : B) {}
// No warning on POD copy
//for (int &x : B) {}
// Binding error
for (int &x : B) {}
// No warning
for (int x : B) {}
// No warning

for (const double &&x : B) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note-re@-2 {{'double'{{.*}}'const int &'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:21-[[@LINE-3]]:23}:""
for (const double &x : B) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note-re@-2 {{'double'{{.*}}'const int &'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:21-[[@LINE-3]]:22}:""
for (const double x : B) {}
for (double &&x : B) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note-re@-2 {{'double'{{.*}}'const int &'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:15-[[@LINE-3]]:17}:""
//for (double &x : B) {}
// Binding error
for (double x : B) {}
// No warning

for (const Bar &&x : B) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note@-2 {{'Bar'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:20}:""
for (const Bar &x : B) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note@-2 {{'Bar'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
for (const Bar x : B) {}
for (Bar &&x : B) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note@-2 {{'Bar'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:""
//for (Bar &x : B) {}
// Binding error
for (Bar x : B) {}
Expand All @@ -145,21 +187,31 @@ void test2() {
void test3() {
Container<Bar> C;

for (const Bar &&x : C) {}
// No warning, rvalue-reference to the temporary
for (const Bar &x : C) {}
// expected-warning@-1 {{always a copy}}
// expected-note@-2 {{'Bar'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
for (const Bar x : C) {}
// No warning, non-reference type indicates copy is made
for (Bar &&x : C) {}
// No warning, rvalue-reference to the temporary
//for (Bar &x : C) {}
// Binding error
for (Bar x : C) {}
// No warning, non-reference type indicates copy is made

for (const int &&x : C) {}
// No warning, rvalue-reference to the temporary
for (const int &x : C) {}
// expected-warning@-1 {{always a copy}}
// expected-note@-2 {{'int'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
for (const int x : C) {}
// No warning, copy made
for (int &&x : C) {}
// No warning, rvalue-reference to the temporary
//for (int &x : C) {}
// Binding error
for (int x : C) {}
Expand All @@ -169,21 +221,35 @@ void test3() {
void test4() {
Container<Bar&> D;

//for (const Bar &&x : D) {}
// Binding error
for (const Bar &x : D) {}
// No warning, this reference is not a temporary
for (const Bar x : D) {}
// expected-warning@-1 {{creates a copy}}
// expected-note@-2 {{'const Bar &'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:18}:"&"
//for (Bar &&x : D) {}
// Binding error
for (Bar &x : D) {}
// No warning
for (Bar x : D) {}
// No warning

for (const int &&x : D) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note-re@-2 {{'int'{{.*}}'const Bar &'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:20}:""
for (const int &x : D) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note-re@-2 {{'int'{{.*}}'const Bar &'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
for (const int x : D) {}
// No warning
for (int &&x : D) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note-re@-2 {{'int'{{.*}}'const Bar &'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:""
//for (int &x : D) {}
// Binding error
for (int x : D) {}
Expand All @@ -193,11 +259,16 @@ void test4() {
void test5() {
Container<Foo> E;

for (const Bar &&x : E) {}
// No warning, rvalue-reference to the temporary
for (const Bar &x : E) {}
// expected-warning@-1 {{always a copy}}
// expected-note@-2 {{'Bar'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
for (const Bar x : E) {}
// No warning, non-reference type indicates copy is made
for (Bar &&x : E) {}
// No warning, rvalue-reference to the temporary
//for (Bar &x : E) {}
// Binding error
for (Bar x : E) {}
Expand All @@ -207,11 +278,20 @@ void test5() {
void test6() {
Container<Foo&> F;

for (const Bar &&x : F) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note-re@-2 {{'Bar'{{.*}}'const Foo &'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:20}:""
for (const Bar &x : F) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note-re@-2 {{'Bar'{{.*}}'const Foo &'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
for (const Bar x : F) {}
// No warning.
for (Bar &&x : F) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note-re@-2 {{'Bar'{{.*}}'const Foo &'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:""
//for (Bar &x : F) {}
// Binding error
for (Bar x : F) {}
Expand All @@ -221,53 +301,88 @@ void test6() {
void test7() {
double G[2];

//for (const double &&x : G) {}
// Binding error
for (const double &x : G) {}
// No warning
for (const double x : G) {}
// No warning on POD copy
//for (double &&x : G) {}
// Binding error
for (double &x : G) {}
// No warning
for (double x : G) {}
// No warning

for (const int &&x : G) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note-re@-2 {{'int'{{.*}}'const double &'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:20}:""
for (const int &x : G) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note-re@-2 {{'int'{{.*}}'const double &'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
for (const int x : G) {}
// No warning
for (int &&x : G) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note-re@-2 {{'int'{{.*}}'const double &'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:""
//for (int &x : G) {}
// Binding error
for (int x : G) {}
// No warning

for (const Bar &&x : G) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note-re@-2 {{'Bar'{{.*}}'const double &'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:20}:""
for (const Bar &x : G) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note-re@-2 {{'Bar'{{.*}}'const double &'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
for (const Bar x : G) {}
// No warning
//for (int &Bar : G) {}
for (Bar &&x : G) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note-re@-2 {{'Bar'{{.*}}'const double &'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:""
//for (Bar &x : G) {}
// Binding error
for (int Bar : G) {}
for (Bar x : G) {}
// No warning
}

void test8() {
Foo H[2];

//for (const Foo &&x : H) {}
// Binding error
for (const Foo &x : H) {}
// No warning
for (const Foo x : H) {}
// No warning on POD copy
//for (Foo &&x : H) {}
// Binding error
for (Foo &x : H) {}
// No warning
for (Foo x : H) {}
// No warning

for (const Bar &&x : H) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note-re@-2 {{'Bar'{{.*}}'const Foo &'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:20}:""
for (const Bar &x : H) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note-re@-2 {{'Bar'{{.*}}'const Foo &'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
for (const Bar x : H) {}
// No warning
for (Bar &&x: H) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note-re@-2 {{'Bar'{{.*}}'const Foo &'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:""
//for (Bar &x: H) {}
// Binding error
for (Bar x: H) {}
Expand All @@ -277,23 +392,61 @@ void test8() {
void test9() {
Bar I[2] = {1,2};

//for (const Bar &&x : I) {}
// Binding error
for (const Bar &x : I) {}
// No warning
for (const Bar x : I) {}
// expected-warning@-1 {{creates a copy}}
// expected-note@-2 {{'const Bar &'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:18}:"&"
//for (Bar &&x : I) {}
// Binding error
for (Bar &x : I) {}
// No warning
for (Bar x : I) {}
// No warning

for (const int &&x : I) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note-re@-2 {{'int'{{.*}}'const Bar &'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:20}:""
for (const int &x : I) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note-re@-2 {{'int'{{.*}}'const Bar &'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""
for (const int x : I) {}
// No warning
for (int &&x : I) {}
// expected-warning@-1 {{resulting in a copy}}
// expected-note-re@-2 {{'int'{{.*}}'const Bar &'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:""
//for (int &x : I) {}
// Binding error
for (int x : I) {}
// No warning
}

void test10() {
Container<Bar> C;

for (const Bar &x : C) {}
// expected-warning@-1 {{always a copy}}
// expected-note@-2 {{'Bar'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:19}:""

for (const Bar& x : C) {}
// expected-warning@-1 {{always a copy}}
// expected-note@-2 {{'Bar'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:17-[[@LINE-3]]:18}:""

for (const Bar & x : C) {}
// expected-warning@-1 {{always a copy}}
// expected-note@-2 {{'Bar'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:18-[[@LINE-3]]:20}:""

for (const Bar&x : C) {}
// expected-warning@-1 {{always a copy}}
// expected-note@-2 {{'Bar'}}
// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:17-[[@LINE-3]]:18}:" "
}
2 changes: 1 addition & 1 deletion clang/tools/clang-refactor/TestSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bool areChangesSame(const tooling::AtomicChanges &LHS,
const tooling::AtomicChanges &RHS) {
if (LHS.size() != RHS.size())
return false;
for (const auto &I : llvm::zip(LHS, RHS)) {
for (auto I : llvm::zip(LHS, RHS)) {
if (!(std::get<0>(I) == std::get<1>(I)))
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ bool isRSAllocationTyCallSite(llvm::Module &module, llvm::CallInst *call_inst) {
(void)module;
if (!call_inst->hasByValArgument())
return false;
for (const auto &param : call_inst->operand_values())
for (const auto *param : call_inst->operand_values())
if (isRSAllocationPtrTy(param->getType()))
return true;
return false;
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/Platform/Android/AdbClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ Status AdbClient::GetDevices(DeviceIDList &device_list) {
llvm::SmallVector<llvm::StringRef, 4> devices;
response.split(devices, "\n", -1, false);

for (const auto device : devices)
for (const auto &device : devices)
device_list.push_back(device.split('\t').first);

// Force disconnect since ADB closes connection after host:devices response
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Target/StackFrameRecognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ScriptedStackFrameRecognizer::RecognizeFrame(lldb::StackFrameSP frame) {
ValueObjectListSP args =
m_interpreter->GetRecognizedArguments(m_python_object_sp, frame);
auto args_synthesized = ValueObjectListSP(new ValueObjectList());
for (const auto o : args->GetObjects()) {
for (const auto &o : args->GetObjects()) {
args_synthesized->Append(ValueObjectRecognizerSynthesizedValue::Create(
*o, eValueTypeVariableArgument));
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Analysis/LoopInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ template <class BlockT, class LoopT> class LoopBase {
bool isLoopExiting(const BlockT *BB) const {
assert(!isInvalid() && "Loop not in a valid state!");
assert(contains(BB) && "Exiting block must be part of the loop");
for (const auto &Succ : children<const BlockT *>(BB)) {
for (const auto *Succ : children<const BlockT *>(BB)) {
if (!contains(Succ))
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions llvm/include/llvm/Analysis/LoopInfoImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void LoopBase<BlockT, LoopT>::getExitingBlocks(
SmallVectorImpl<BlockT *> &ExitingBlocks) const {
assert(!isInvalid() && "Loop not in a valid state!");
for (const auto BB : blocks())
for (const auto &Succ : children<BlockT *>(BB))
for (auto *Succ : children<BlockT *>(BB))
if (!contains(Succ)) {
// Not in current loop? It must be an exit block.
ExitingBlocks.push_back(BB);
Expand Down Expand Up @@ -63,7 +63,7 @@ void LoopBase<BlockT, LoopT>::getExitBlocks(
SmallVectorImpl<BlockT *> &ExitBlocks) const {
assert(!isInvalid() && "Loop not in a valid state!");
for (const auto BB : blocks())
for (const auto &Succ : children<BlockT *>(BB))
for (auto *Succ : children<BlockT *>(BB))
if (!contains(Succ))
// Not in current loop? It must be an exit block.
ExitBlocks.push_back(Succ);
Expand Down Expand Up @@ -142,7 +142,7 @@ void LoopBase<BlockT, LoopT>::getExitEdges(
SmallVectorImpl<Edge> &ExitEdges) const {
assert(!isInvalid() && "Loop not in a valid state!");
for (const auto BB : blocks())
for (const auto &Succ : children<BlockT *>(BB))
for (auto *Succ : children<BlockT *>(BB))
if (!contains(Succ))
// Not in current loop? It must be an exit block.
ExitEdges.emplace_back(BB, Succ);
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Support/GenericDomTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -778,13 +778,13 @@ class DominatorTreeBase {
NodeRef NewBBSucc = *GraphT::child_begin(NewBB);

std::vector<NodeRef> PredBlocks;
for (const auto &Pred : children<Inverse<N>>(NewBB))
for (auto Pred : children<Inverse<N>>(NewBB))
PredBlocks.push_back(Pred);

assert(!PredBlocks.empty() && "No predblocks?");

bool NewBBDominatesNewBBSucc = true;
for (const auto &Pred : children<Inverse<N>>(NewBBSucc)) {
for (auto Pred : children<Inverse<N>>(NewBBSucc)) {
if (Pred != NewBB && !dominates(NewBBSucc, Pred) &&
isReachableFromEntry(Pred)) {
NewBBDominatesNewBBSucc = false;
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/DomTreeUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void DomTreeUpdater::applyUpdates(ArrayRef<DominatorTree::UpdateType> Updates) {
return;

if (Strategy == UpdateStrategy::Lazy) {
for (const auto U : Updates)
for (const auto &U : Updates)
if (!isSelfDominance(U))
PendUpdates.push_back(U);

Expand All @@ -253,7 +253,7 @@ void DomTreeUpdater::applyUpdatesPermissive(

SmallSet<std::pair<BasicBlock *, BasicBlock *>, 8> Seen;
SmallVector<DominatorTree::UpdateType, 8> DeduplicatedUpdates;
for (const auto U : Updates) {
for (const auto &U : Updates) {
auto Edge = std::make_pair(U.getFrom(), U.getTo());
// Because it is illegal to submit updates that have already been applied
// and updates to an edge need to be strictly ordered,
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/MemoryDependenceAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,7 @@ void MemoryDependenceResults::RemoveCachedNonLocalPointerDependencies(
if (auto *I = dyn_cast<Instruction>(P.getPointer())) {
auto toRemoveIt = ReverseNonLocalDefsCache.find(I);
if (toRemoveIt != ReverseNonLocalDefsCache.end()) {
for (const auto &entry : toRemoveIt->second)
for (const auto *entry : toRemoveIt->second)
NonLocalDefsCache.erase(entry);
ReverseNonLocalDefsCache.erase(toRemoveIt);
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/ScalarEvolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12527,7 +12527,7 @@ PredicatedScalarEvolution::PredicatedScalarEvolution(
const PredicatedScalarEvolution &Init)
: RewriteMap(Init.RewriteMap), SE(Init.SE), L(Init.L), Preds(Init.Preds),
Generation(Init.Generation), BackedgeCount(Init.BackedgeCount) {
for (const auto &I : Init.FlagsMap)
for (auto I : Init.FlagsMap)
FlagsMap.insert(I);
}

Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/CodeGen/InlineSpiller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,7 @@ void HoistSpillHelper::runHoistSpills(
}
// For spills in SpillsToKeep with LiveReg set (i.e., not original spill),
// save them to SpillsToIns.
for (const auto Ent : SpillsToKeep) {
for (const auto &Ent : SpillsToKeep) {
if (Ent.second)
SpillsToIns[Ent.first->getBlock()] = Ent.second;
}
Expand Down Expand Up @@ -1486,7 +1486,7 @@ void HoistSpillHelper::hoistAllSpills() {

LLVM_DEBUG({
dbgs() << "Finally inserted spills in BB: ";
for (const auto Ispill : SpillsToIns)
for (const auto &Ispill : SpillsToIns)
dbgs() << Ispill.first->getNumber() << " ";
dbgs() << "\nFinally removed spills in BB: ";
for (const auto Rspill : SpillsToRm)
Expand All @@ -1501,7 +1501,7 @@ void HoistSpillHelper::hoistAllSpills() {
StackIntvl.getValNumInfo(0));

// Insert hoisted spills.
for (auto const Insert : SpillsToIns) {
for (auto const &Insert : SpillsToIns) {
MachineBasicBlock *BB = Insert.first;
unsigned LiveReg = Insert.second;
MachineBasicBlock::iterator MI = IPA.getLastInsertPointIter(OrigLI, *BB);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/InterleavedLoadCombinePass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ bool InterleavedLoadCombineImpl::combine(std::list<VectorInfo> &InterleavedLoad,

// If there are users outside the set to be eliminated, we abort the
// transformation. No gain can be expected.
for (const auto &U : I->users()) {
for (auto *U : I->users()) {
if (Is.find(dyn_cast<Instruction>(U)) == Is.end())
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/RegAllocFast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ void RegAllocFast::allocateBasicBlock(MachineBasicBlock &MBB) {
MachineBasicBlock::iterator MII = MBB.begin();

// Add live-in registers as live.
for (const MachineBasicBlock::RegisterMaskPair LI : MBB.liveins())
for (const MachineBasicBlock::RegisterMaskPair &LI : MBB.liveins())
if (MRI->isAllocatable(LI.PhysReg))
definePhysReg(MII, LI.PhysReg, regReserved);

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3038,7 +3038,7 @@ static bool isVectorReductionOp(const User *I) {
if (!Visited.insert(User).second)
continue;

for (const auto &U : User->users()) {
for (const auto *U : User->users()) {
auto Inst = dyn_cast<Instruction>(U);
if (!Inst)
return false;
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ void TargetLoweringObjectFileELF::emitModuleMetadata(MCStreamer &Streamer,

Streamer.SwitchSection(S);

for (const auto &Operand : LinkerOptions->operands()) {
for (const auto *Operand : LinkerOptions->operands()) {
if (cast<MDNode>(Operand)->getNumOperands() != 2)
report_fatal_error("invalid llvm.linker.options");
for (const auto &Option : cast<MDNode>(Operand)->operands()) {
Expand All @@ -289,7 +289,7 @@ void TargetLoweringObjectFileELF::emitModuleMetadata(MCStreamer &Streamer,

Streamer.SwitchSection(S);

for (const auto &Operand : DependentLibraries->operands()) {
for (const auto *Operand : DependentLibraries->operands()) {
Streamer.EmitBytes(
cast<MDString>(cast<MDNode>(Operand)->getOperand(0))->getString());
Streamer.EmitIntValue(0, 1);
Expand Down Expand Up @@ -885,7 +885,7 @@ void TargetLoweringObjectFileMachO::emitModuleMetadata(MCStreamer &Streamer,
Module &M) const {
// Emit the linker options if present.
if (auto *LinkerOptions = M.getNamedMetadata("llvm.linker.options")) {
for (const auto &Option : LinkerOptions->operands()) {
for (const auto *Option : LinkerOptions->operands()) {
SmallVector<std::string, 4> StrOptions;
for (const auto &Piece : cast<MDNode>(Option)->operands())
StrOptions.push_back(cast<MDString>(Piece)->getString());
Expand Down Expand Up @@ -1449,7 +1449,7 @@ void TargetLoweringObjectFileCOFF::emitModuleMetadata(MCStreamer &Streamer,
// linker.
MCSection *Sec = getDrectveSection();
Streamer.SwitchSection(Sec);
for (const auto &Option : LinkerOptions->operands()) {
for (const auto *Option : LinkerOptions->operands()) {
for (const auto &Piece : cast<MDNode>(Option)->operands()) {
// Lead with a space for consistency with our dllexport implementation.
std::string Directive(" ");
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ Optional<DWARFFormValue>
AppleAcceleratorTable::Entry::lookup(HeaderData::AtomType Atom) const {
assert(HdrData && "Dereferencing end iterator?");
assert(HdrData->Atoms.size() == Values.size());
for (const auto &Tuple : zip_first(HdrData->Atoms, Values)) {
for (auto Tuple : zip_first(HdrData->Atoms, Values)) {
if (std::get<0>(Tuple).first == Atom)
return std::get<1>(Tuple);
}
Expand Down Expand Up @@ -531,7 +531,7 @@ DWARFDebugNames::Entry::Entry(const NameIndex &NameIdx, const Abbrev &Abbr)
Optional<DWARFFormValue>
DWARFDebugNames::Entry::lookup(dwarf::Index Index) const {
assert(Abbr->Attributes.size() == Values.size());
for (const auto &Tuple : zip_first(Abbr->Attributes, Values)) {
for (auto Tuple : zip_first(Abbr->Attributes, Values)) {
if (std::get<0>(Tuple).Index == Index)
return std::get<1>(Tuple);
}
Expand Down Expand Up @@ -565,7 +565,7 @@ void DWARFDebugNames::Entry::dump(ScopedPrinter &W) const {
W.printHex("Abbrev", Abbr->Code);
W.startLine() << formatv("Tag: {0}\n", Abbr->Tag);
assert(Abbr->Attributes.size() == Values.size());
for (const auto &Tuple : zip_first(Abbr->Attributes, Values)) {
for (auto Tuple : zip_first(Abbr->Attributes, Values)) {
W.startLine() << formatv("{0}: ", std::get<0>(Tuple).Index);
std::get<1>(Tuple).dump(W.getOStream());
W.getOStream() << '\n';
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ unsigned DWARFVerifier::verifyDebugInfoReferences() {
// getting the DIE by offset and emitting an error
OS << "Verifying .debug_info references...\n";
unsigned NumErrors = 0;
for (const std::pair<uint64_t, std::set<uint64_t>> &Pair :
for (const std::pair<const uint64_t, std::set<uint64_t>> &Pair :
ReferenceToDIEOffsets) {
if (DCtx.getDIEForOffset(Pair.first))
continue;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/Symbolize/Symbolize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ Optional<ArrayRef<uint8_t>> getBuildID(const ELFFile<ELFT> *Obj) {
if (P.p_type != ELF::PT_NOTE)
continue;
Error Err = Error::success();
for (const auto &N : Obj->notes(P, Err))
for (auto N : Obj->notes(P, Err))
if (N.getType() == ELF::NT_GNU_BUILD_ID && N.getName() == ELF::ELF_NOTE_GNU)
return N.getDesc();
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void CtorDtorRunner::add(iterator_range<CtorDtorIterator> CtorDtors) {
JD.getExecutionSession(),
(*CtorDtors.begin()).Func->getParent()->getDataLayout());

for (const auto &CtorDtor : CtorDtors) {
for (auto CtorDtor : CtorDtors) {
assert(CtorDtor.Func && CtorDtor.Func->hasName() &&
"Ctor/Dtor function must be named to be runnable under the JIT");

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/IR/TypeFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void TypeFinder::run(const Module &M, bool onlyNamed) {
}

for (const auto &NMD : M.named_metadata())
for (const auto &MDOp : NMD.operands())
for (const auto *MDOp : NMD.operands())
incorporateMDNode(MDOp);
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Linker/IRMover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ Error IRLinker::linkGlobalValueBody(GlobalValue &Dst, GlobalValue &Src) {
}

void IRLinker::flushRAUWWorklist() {
for (const auto Elem : RAUWWorklist) {
for (const auto &Elem : RAUWWorklist) {
GlobalValue *Old;
Value *New;
std::tie(Old, New) = Elem;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/MC/XCOFFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ void XCOFFObjectWriter::writeSymbolTable(const MCAsmLayout &Layout) {
writeSymbolTableEntryForControlSection(
Csect, SectionIndex, Csect.MCCsect->getStorageClass());

for (const auto Sym : Csect.Syms)
for (const auto &Sym : Csect.Syms)
writeSymbolTableEntryForCsectMemberLabel(
Sym, Csect, SectionIndex, Layout.getSymbolOffset(*(Sym.MCSym)));
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/MCA/HardwareUnits/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void ResourceManager::releaseBuffers(uint64_t ConsumedBuffers) {

uint64_t ResourceManager::checkAvailability(const InstrDesc &Desc) const {
uint64_t BusyResourceMask = 0;
for (const std::pair<uint64_t, const ResourceUsage> &E : Desc.Resources) {
for (const std::pair<uint64_t, ResourceUsage> &E : Desc.Resources) {
unsigned NumUnits = E.second.isReserved() ? 0U : E.second.NumUnits;
unsigned Index = getResourceStateIndex(E.first);
if (!Resources[Index]->isReady(NumUnits))
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/MCA/Stages/InstructionTables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Error InstructionTables::execute(InstRef &IR) {
UsedResources.clear();

// Identify the resources consumed by this instruction.
for (const std::pair<uint64_t, ResourceUsage> Resource : Desc.Resources) {
for (const std::pair<const uint64_t, ResourceUsage> Resource :
Desc.Resources) {
// Skip zero-cycle resources (i.e., unused resources).
if (!Resource.second.size())
continue;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ObjectYAML/CodeViewYAMLDebugSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ std::shared_ptr<DebugSubsection> YAMLLinesSubsection::toCodeViewSubsection(
for (const auto &LC : Lines.Blocks) {
Result->createBlock(LC.FileName);
if (Result->hasColumnInfo()) {
for (const auto &Item : zip(LC.Lines, LC.Columns)) {
for (auto Item : zip(LC.Lines, LC.Columns)) {
auto &L = std::get<0>(Item);
auto &C = std::get<1>(Item);
uint32_t LE = L.LineStart + L.EndDelta;
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Support/CommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class CommandLineParser {
// If we're adding this to all sub-commands, add it to the ones that have
// already been registered.
if (SC == &*AllSubCommands) {
for (const auto &Sub : RegisteredSubCommands) {
for (auto *Sub : RegisteredSubCommands) {
if (SC == Sub)
continue;
addLiteralOption(Opt, Sub, Name);
Expand Down Expand Up @@ -243,7 +243,7 @@ class CommandLineParser {
// If we're adding this to all sub-commands, add it to the ones that have
// already been registered.
if (SC == &*AllSubCommands) {
for (const auto &Sub : RegisteredSubCommands) {
for (auto *Sub : RegisteredSubCommands) {
if (SC == Sub)
continue;
addOption(O, Sub);
Expand Down Expand Up @@ -318,7 +318,7 @@ class CommandLineParser {
}

bool hasOptions() const {
for (const auto &S : RegisteredSubCommands) {
for (const auto *S : RegisteredSubCommands) {
if (hasOptions(*S))
return true;
}
Expand Down Expand Up @@ -2112,7 +2112,7 @@ static void sortOpts(StringMap<Option *> &OptMap,
static void
sortSubCommands(const SmallPtrSetImpl<SubCommand *> &SubMap,
SmallVectorImpl<std::pair<const char *, SubCommand *>> &Subs) {
for (const auto &S : SubMap) {
for (auto *S : SubMap) {
if (S->getName().empty())
continue;
Subs.push_back(std::make_pair(S->getName().data(), S));
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/Support/TargetParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ StringRef llvm::AMDGPU::getArchNameR600(GPUKind AK) {
}

AMDGPU::GPUKind llvm::AMDGPU::parseArchAMDGCN(StringRef CPU) {
for (const auto C : AMDGCNGPUs) {
for (const auto &C : AMDGCNGPUs) {
if (CPU == C.Name)
return C.Kind;
}
Expand All @@ -141,7 +141,7 @@ AMDGPU::GPUKind llvm::AMDGPU::parseArchAMDGCN(StringRef CPU) {
}

AMDGPU::GPUKind llvm::AMDGPU::parseArchR600(StringRef CPU) {
for (const auto C : R600GPUs) {
for (const auto &C : R600GPUs) {
if (CPU == C.Name)
return C.Kind;
}
Expand All @@ -163,12 +163,12 @@ unsigned AMDGPU::getArchAttrR600(GPUKind AK) {

void AMDGPU::fillValidArchListAMDGCN(SmallVectorImpl<StringRef> &Values) {
// XXX: Should this only report unique canonical names?
for (const auto C : AMDGCNGPUs)
for (const auto &C : AMDGCNGPUs)
Values.push_back(C.Name);
}

void AMDGPU::fillValidArchListR600(SmallVectorImpl<StringRef> &Values) {
for (const auto C : R600GPUs)
for (const auto &C : R600GPUs)
Values.push_back(C.Name);
}

Expand Down