jy7.yang added you to the CC list for the revision "Replace loop variable 
naming logic".

Hi klimek,

Instead of naming the new loop variable based on the container name, we
now simply reuse the original loop variable.

The previous way was causing problems when, for example, the container
name is 'ints'. The naming logic checks for plurality, then names the
new loop variable as 'int' which is a reserved keyword.

Changes for loop convert tests are also made; all variable name pattern
matchers are replaced with the actual expected name.

http://llvm-reviews.chandlerc.com/D484

Files:
  cpp11-migrate/LoopConvert/LoopActions.cpp
  cpp11-migrate/LoopConvert/VariableNaming.cpp
  cpp11-migrate/LoopConvert/VariableNaming.h
  docs/cpp11-migrate.rst
  test/cpp11-migrate/Combined/combined.cpp
  test/cpp11-migrate/LoopConvert/array.cpp
  test/cpp11-migrate/LoopConvert/confidence.cpp
  test/cpp11-migrate/LoopConvert/dependency.cpp
  test/cpp11-migrate/LoopConvert/iterator.cpp
  test/cpp11-migrate/LoopConvert/naming.cpp
  test/cpp11-migrate/LoopConvert/nesting.cpp
  test/cpp11-migrate/LoopConvert/pseudoarray.cpp
  test/cpp11-migrate/LoopConvert/single-iterator.cpp
Index: cpp11-migrate/LoopConvert/LoopActions.cpp
===================================================================
--- cpp11-migrate/LoopConvert/LoopActions.cpp
+++ cpp11-migrate/LoopConvert/LoopActions.cpp
@@ -14,7 +14,6 @@
 //===----------------------------------------------------------------------===//
 #include "LoopActions.h"
 #include "LoopMatchers.h"
-#include "VariableNaming.h"
 #include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
@@ -748,9 +747,8 @@
     // No further replacements are made to the loop, since the iterator or index
     // was used exactly once - in the initialization of AliasVar.
   } else {
-    VariableNamer Namer(GeneratedDecls, &ParentFinder->getStmtToParentStmtMap(),
-                        TheLoop, IndexVar, MaybeContainer);
-    VarName = Namer.createIndexName();
+    // We keep the original variable as the new loop variable.
+    VarName = IndexVar->getName().str();
     // First, replace all usages of the array subscript expression with our new
     // variable.
     for (UsageResult::const_iterator I = Usages.begin(), E = Usages.end();
Index: cpp11-migrate/LoopConvert/VariableNaming.cpp
===================================================================
--- cpp11-migrate/LoopConvert/VariableNaming.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-//===-- LoopConvert/VariableNaming.h - Gererate variable names --*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file
-/// \brief This file contains the definitino of the VariableNamer class, which
-/// is responsible for generating new variable names and ensuring that they do
-/// not conflict with existing ones.
-///
-//===----------------------------------------------------------------------===//
-#include "VariableNaming.h"
-
-using namespace llvm;
-using namespace clang;
-
-std::string VariableNamer::createIndexName() {
-  // FIXME: Add in naming conventions to handle:
-  //  - Uppercase/lowercase indices
-  //  - How to handle conflicts
-  //  - An interactive process for naming
-  std::string IteratorName;
-  std::string ContainerName;
-  if (TheContainer)
-    ContainerName = TheContainer->getName().str();
-
-  size_t Len = ContainerName.length();
-  if (Len > 1 && ContainerName[Len - 1] == 's')
-    IteratorName = ContainerName.substr(0, Len - 1);
-  else
-    IteratorName = "elem";
-
-  if (!declarationExists(IteratorName))
-    return IteratorName;
-
-  IteratorName = ContainerName + "_" + OldIndex->getName().str();
-  if (!declarationExists(IteratorName))
-    return IteratorName;
-
-  IteratorName = ContainerName + "_elem";
-  if (!declarationExists(IteratorName))
-    return IteratorName;
-
-  IteratorName += "_elem";
-  if (!declarationExists(IteratorName))
-    return IteratorName;
-
-  IteratorName = "_elem_";
-
-  // Someone defeated my naming scheme...
-  while (declarationExists(IteratorName))
-    IteratorName += "i";
-  return IteratorName;
-}
-
-/// \brief Determines whether or not the the name Symbol exists in LoopContext,
-/// any of its parent contexts, or any of its child statements.
-///
-/// We also check to see if the same identifier was generated by this loop
-/// converter in a loop nested within SourceStmt.
-bool VariableNamer::declarationExists(const StringRef Symbol) {
-  // Determine if the symbol was generated in a parent context.
-  for (const Stmt *S = SourceStmt; S != NULL; S = ReverseAST->lookup(S)) {
-    StmtGeneratedVarNameMap::const_iterator I = GeneratedDecls->find(S);
-    if (I != GeneratedDecls->end() && I->second == Symbol)
-      return true;
-  }
-
-  // FIXME: Rather than detecting conflicts at their usages, we should check the
-  // parent context.
-  // For some reason, lookup() always returns the pair (NULL, NULL) because its
-  // StoredDeclsMap is not initialized (i.e. LookupPtr.getInt() is false inside
-  // of DeclContext::lookup()). Why is this?
-
-  // Finally, determine if the symbol was used in the loop or a child context.
-  DeclFinderASTVisitor DeclFinder(Symbol, GeneratedDecls);
-  return DeclFinder.findUsages(SourceStmt);
-}
Index: cpp11-migrate/LoopConvert/VariableNaming.h
===================================================================
--- cpp11-migrate/LoopConvert/VariableNaming.h
+++ /dev/null
@@ -1,56 +0,0 @@
-//===-- LoopConvert/VariableNaming.h - Gererate variable names --*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file
-/// \brief This file contains the declaration of the VariableNamer class, which
-/// is responsible for generating new variable names and ensuring that they do
-/// not conflict with existing ones.
-//
-//===----------------------------------------------------------------------===//
-#ifndef LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_VARIABLE_NAMING_H
-#define LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_VARIABLE_NAMING_H
-
-#include "StmtAncestor.h"
-#include "clang/AST/ASTContext.h"
-
-/// \brief Create names for generated variables within a particular statement.
-///
-/// VariableNamer uses a DeclContext as a reference point, checking for any
-/// conflicting declarations higher up in the context or within SourceStmt.
-/// It creates a variable name using hints from a source container and the old
-/// index, if they exist.
-class VariableNamer {
- public:
-  VariableNamer(StmtGeneratedVarNameMap *GeneratedDecls,
-                const StmtParentMap *ReverseAST, const clang::Stmt *SourceStmt,
-                const clang::VarDecl *OldIndex,
-                const clang::VarDecl *TheContainer) :
-  GeneratedDecls(GeneratedDecls), ReverseAST(ReverseAST),
-  SourceStmt(SourceStmt), OldIndex(OldIndex), TheContainer(TheContainer) { }
-
-  /// \brief Generate a new index name.
-  ///
-  /// Generates the name to be used for an inserted iterator. It relies on
-  /// declarationExists() to determine that there are no naming conflicts, and
-  /// tries to use some hints from the container name and the old index name.
-  std::string createIndexName();
-
- private:
-  StmtGeneratedVarNameMap *GeneratedDecls;
-  const StmtParentMap *ReverseAST;
-  const clang::Stmt *SourceStmt;
-  const clang::VarDecl *OldIndex;
-  const clang::VarDecl *TheContainer;
-
-  // Determine whether or not a declaration that would conflict with Symbol
-  // exists in an outer context or in any statement contained in SourceStmt.
-  bool declarationExists(const llvm::StringRef Symbol);
-};
-
-#endif // LLVM_TOOLS_CLANG_TOOLS_EXTRA_CPP11_MIGRATE_VARIABLE_NAMING_H
Index: docs/cpp11-migrate.rst
===================================================================
--- docs/cpp11-migrate.rst
+++ docs/cpp11-migrate.rst
@@ -185,16 +185,16 @@
   v.push_back(3);
 
   // safe transform
-  for (auto & elem : arr)
-    cout << elem;
+  for (auto & i : arr)
+    cout << i;
 
   // reasonable transform
-  for (auto & elem : v)
-    cout << elem;
+  for (auto & it : v)
+    cout << it;
 
   // reasonable transform
-  for (auto & elem : v)
-    cout << elem;
+  for (auto & i : v)
+    cout << i;
 
 .. _nullptr-convert-transformation:
 
Index: test/cpp11-migrate/Combined/combined.cpp
===================================================================
--- test/cpp11-migrate/Combined/combined.cpp
+++ test/cpp11-migrate/Combined/combined.cpp
@@ -28,8 +28,8 @@
     *it = NULL;
   }
 
-  // CHECK: for ({{[a-zA-Z_ ]+&? ?}}[[VAR:[a-z_]+]] : t)
-  // CHECK-NEXT: [[VAR]] = nullptr;
+  // CHECK: for (auto & it : t)
+  // CHECK-NEXT: it = nullptr;
 }
 
 void test_loopconvert_and_nullptr_risky() {
@@ -40,6 +40,6 @@
     (*pArr)[i] = NULL;
   }
 
-  // RISKY: for (auto & [[VAR:[a-z_]+]] : *pArr)
-  // RISKY-NEXT: [[VAR:[a-z_]+]] = nullptr;
+  // RISKY: for (auto & i : *pArr)
+  // RISKY-NEXT: i = nullptr;
 }
Index: test/cpp11-migrate/LoopConvert/array.cpp
===================================================================
--- test/cpp11-migrate/LoopConvert/array.cpp
+++ test/cpp11-migrate/LoopConvert/array.cpp
@@ -25,77 +25,77 @@
     sum += arr[i];
     int k;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : arr) {
-  // CHECK-NEXT: sum += [[VAR]];
+  // CHECK: for (auto & i : arr) {
+  // CHECK-NEXT: sum += i;
   // CHECK-NEXT: int k;
   // CHECK-NEXT: }
 
   for (int i = 0; i < N; ++i) {
     printf("Fibonacci number is %d\n", arr[i]);
     sum += arr[i] + 2;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : arr)
-  // CHECK-NEXT: printf("Fibonacci number is %d\n", [[VAR]]);
-  // CHECK-NEXT: sum += [[VAR]] + 2;
+  // CHECK: for (auto & i : arr)
+  // CHECK-NEXT: printf("Fibonacci number is %d\n", i);
+  // CHECK-NEXT: sum += i + 2;
 
   for (int i = 0; i < N; ++i) {
     int x = arr[i];
     int y = arr[i] + 2;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : arr)
-  // CHECK-NEXT: int x = [[VAR]];
-  // CHECK-NEXT: int y = [[VAR]] + 2;
+  // CHECK: for (auto & i : arr)
+  // CHECK-NEXT: int x = i;
+  // CHECK-NEXT: int y = i + 2;
 
   for (int i = 0; i < N; ++i) {
     int x = N;
     x = arr[i];
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : arr)
+  // CHECK: for (auto & i : arr)
   // CHECK-NEXT: int x = N;
-  // CHECK-NEXT: x = [[VAR]];
+  // CHECK-NEXT: x = i;
 
   for (int i = 0; i < N; ++i) {
     arr[i] += 1;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : arr) {
-  // CHECK-NEXT: [[VAR]] += 1;
+  // CHECK: for (auto & i : arr) {
+  // CHECK-NEXT: i += 1;
   // CHECK-NEXT: }
 
   for (int i = 0; i < N; ++i) {
     int x = arr[i] + 2;
     arr[i] ++;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : arr)
-  // CHECK-NEXT: int x = [[VAR]] + 2;
-  // CHECK-NEXT: [[VAR]] ++;
+  // CHECK: for (auto & i : arr)
+  // CHECK-NEXT: int x = i + 2;
+  // CHECK-NEXT: i ++;
 
   for (int i = 0; i < N; ++i) {
     arr[i] = 4 + arr[i];
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : arr)
-  // CHECK-NEXT: [[VAR]] = 4 + [[VAR]];
+  // CHECK: for (auto & i : arr)
+  // CHECK-NEXT: i = 4 + i;
 
   for (int i = 0; i < NMinusOne + 1; ++i) {
     sum += arr[i];
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : arr) {
-  // CHECK-NEXT: sum += [[VAR]];
+  // CHECK: for (auto & i : arr) {
+  // CHECK-NEXT: sum += i;
   // CHECK-NEXT: }
 
   for (int i = 0; i < N; ++i) {
     printf("Fibonacci number %d has address %p\n", arr[i], &arr[i]);
     sum += arr[i] + 2;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : arr)
-  // CHECK-NEXT: printf("Fibonacci number %d has address %p\n", [[VAR]], &[[VAR]]);
-  // CHECK-NEXT: sum += [[VAR]] + 2;
+  // CHECK: for (auto & i : arr)
+  // CHECK-NEXT: printf("Fibonacci number %d has address %p\n", i, &i);
+  // CHECK-NEXT: sum += i + 2;
 
   Val teas[N];
   for (int i = 0; i < N; ++i) {
     teas[i].g();
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : teas) {
-  // CHECK-NEXT: [[VAR]].g();
+  // CHECK: for (auto & i : teas) {
+  // CHECK-NEXT: i.g();
   // CHECK-NEXT: }
 }
 
@@ -106,36 +106,36 @@
     for (int i = 0; i < N; ++i) {
       printf("%d", Arr[i]);
     }
-    // CHECK: for (auto & [[VAR:[a-z_]+]] : Arr) {
-    // CHECK-NEXT: printf("%d", [[VAR]]);
+    // CHECK: for (auto & i : Arr) {
+    // CHECK-NEXT: printf("%d", i);
     // CHECK-NEXT: }
 
     for (int i = 0; i < N; ++i) {
       printf("%d", ValArr[i].x);
     }
-    // CHECK: for (auto & [[VAR:[a-z_]+]] : ValArr) {
-    // CHECK-NEXT: printf("%d", [[VAR]].x);
+    // CHECK: for (auto & i : ValArr) {
+    // CHECK-NEXT: printf("%d", i.x);
     // CHECK-NEXT: }
   }
 
   void explicitThis() {
     for (int i = 0; i < N; ++i) {
       printf("%d", this->Arr[i]);
     }
-    // CHECK: for (auto & [[VAR:[a-z_]+]] : this->Arr) {
-    // CHECK-NEXT: printf("%d", [[VAR]]);
+    // CHECK: for (auto & i : this->Arr) {
+    // CHECK-NEXT: printf("%d", i);
     // CHECK-NEXT: }
 
     for (int i = 0; i < N; ++i) {
       printf("%d", this->ValArr[i].x);
     }
-    // CHECK: for (auto & [[VAR:[a-z_]+]] : this->ValArr) {
-    // CHECK-NEXT: printf("%d", [[VAR]].x);
+    // CHECK: for (auto & i : this->ValArr) {
+    // CHECK-NEXT: printf("%d", i.x);
     // CHECK-NEXT: }
   }
 };
 
-// Loops whose bounds are value-dependent shold not be converted.
+// Loops whose bounds are value-dependent should not be converted.
 template<int N>
 void dependentExprBound() {
   for (int i = 0; i < N; ++i)
@@ -150,6 +150,6 @@
   void (Val::*mfpArr[N])(void) = { &Val::g };
   for (int i = 0; i < N; ++i)
     (v.*mfpArr[i])();
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : mfpArr)
-  // CHECK-NEXT: (v.*[[VAR]])();
+  // CHECK: for (auto & i : mfpArr)
+  // CHECK-NEXT: (v.*i)();
 }
Index: test/cpp11-migrate/LoopConvert/confidence.cpp
===================================================================
--- test/cpp11-migrate/LoopConvert/confidence.cpp
+++ test/cpp11-migrate/LoopConvert/confidence.cpp
@@ -19,15 +19,15 @@
   // CHECK: for (int i = 0; i < M; ++i) {
   // CHECK-NEXT: sum += Arr[0][i];
   // CHECK-NEXT: }
-  // RISKY: for (auto & [[VAR:[a-z_]+]] : Arr[0]) {
-  // RISKY-NEXT: sum += [[VAR]];
+  // RISKY: for (auto & i : Arr[0]) {
+  // RISKY-NEXT: sum += i;
   // RISKY-NEXT: }
 
   for (int i = 0; i < N; ++i) {
     sum += (*pArr)[i];
   }
-  // RISKY: for (auto & [[VAR:[a-z_]+]] : *pArr) {
-  // RISKY-NEXT: sum += [[VAR]];
+  // RISKY: for (auto & i : *pArr) {
+  // RISKY-NEXT: sum += i;
   // RISKY-NEXT: }
   // CHECK: for (int i = 0; i < N; ++i) {
   // CHECK-NEXT: sum += (*pArr)[i];
Index: test/cpp11-migrate/LoopConvert/dependency.cpp
===================================================================
--- test/cpp11-migrate/LoopConvert/dependency.cpp
+++ test/cpp11-migrate/LoopConvert/dependency.cpp
@@ -10,9 +10,9 @@
     int a = 0;
     int b = arr[i][a];
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : arr) {
+  // CHECK: for (auto & i : arr) {
   // CHECK-NEXT: int a = 0;
-  // CHECK-NEXT: int b = [[VAR]][a];
+  // CHECK-NEXT: int b = i[a];
   // CHECK-NEXT: }
 
   for (int j = 0; j < M; ++j) {
Index: test/cpp11-migrate/LoopConvert/iterator.cpp
===================================================================
--- test/cpp11-migrate/LoopConvert/iterator.cpp
+++ test/cpp11-migrate/LoopConvert/iterator.cpp
@@ -10,94 +10,94 @@
   for (T::iterator it = t.begin(), e = t.end(); it != e; ++it) {
     printf("I found %d\n", *it);
   }
-  // CHECK: for ({{[a-zA-Z_ ]+&? ?}}[[VAR:[a-z_]+]] : t)
-  // CHECK-NEXT: printf("I found %d\n", [[VAR]]);
+  // CHECK: for (auto & it : t)
+  // CHECK-NEXT: printf("I found %d\n", it);
 
   T *pt;
   for (T::iterator it = pt->begin(), e = pt->end(); it != e; ++it) {
     printf("I found %d\n", *it);
   }
-  // CHECK: for ({{[a-zA-Z_ ]+&? ?}}[[VAR:[a-z_]+]] : *pt)
-  // CHECK-NEXT: printf("I found %d\n", [[VAR]]);
+  // CHECK: for (auto & it : *pt)
+  // CHECK-NEXT: printf("I found %d\n", it);
 
   S s;
   for (S::const_iterator it = s.begin(), e = s.end(); it != e; ++it) {
     printf("s has value %d\n", (*it).x);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : s)
-  // CHECK-NEXT: printf("s has value %d\n", ([[VAR]]).x);
+  // CHECK: for (auto & it : s)
+  // CHECK-NEXT: printf("s has value %d\n", (it).x);
 
   S *ps;
   for (S::const_iterator it = ps->begin(), e = ps->end(); it != e; ++it) {
     printf("s has value %d\n", (*it).x);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : *ps)
-  // CHECK-NEXT: printf("s has value %d\n", ([[VAR]]).x);
+  // CHECK: for (auto & it : *ps)
+  // CHECK-NEXT: printf("s has value %d\n", (it).x);
 
   for (S::const_iterator it = s.begin(), e = s.end(); it != e; ++it) {
     printf("s has value %d\n", it->x);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : s)
-  // CHECK-NEXT: printf("s has value %d\n", [[VAR]].x);
+  // CHECK: for (auto & it : s)
+  // CHECK-NEXT: printf("s has value %d\n", it.x);
 
   for (S::iterator it = s.begin(), e = s.end(); it != e; ++it) {
     it->x = 3;
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : s)
-  // CHECK-NEXT: [[VAR]].x = 3;
+  // CHECK: for (auto & it : s)
+  // CHECK-NEXT: it.x = 3;
 
   for (S::iterator it = s.begin(), e = s.end(); it != e; ++it) {
     (*it).x = 3;
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : s)
-  // CHECK-NEXT: ([[VAR]]).x = 3;
+  // CHECK: for (auto & it : s)
+  // CHECK-NEXT: (it).x = 3;
 
   for (S::iterator it = s.begin(), e = s.end(); it != e; ++it) {
     it->nonConstFun(4, 5);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : s)
-  // CHECK-NEXT: [[VAR]].nonConstFun(4, 5);
+  // CHECK: for (auto & it : s)
+  // CHECK-NEXT: it.nonConstFun(4, 5);
 
   U u;
   for (U::iterator it = u.begin(), e = u.end(); it != e; ++it) {
     printf("s has value %d\n", it->x);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : u)
-  // CHECK-NEXT: printf("s has value %d\n", [[VAR]].x);
+  // CHECK: for (auto & it : u)
+  // CHECK-NEXT: printf("s has value %d\n", it.x);
 
   for (U::iterator it = u.begin(), e = u.end(); it != e; ++it) {
     printf("s has value %d\n", (*it).x);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : u)
-  // CHECK-NEXT: printf("s has value %d\n", ([[VAR]]).x);
+  // CHECK: for (auto & it : u)
+  // CHECK-NEXT: printf("s has value %d\n", (it).x);
 
   U::iterator A;
   for (U::iterator i = u.begin(), e = u.end(); i != e; ++i)
     int k = A->x + i->x;
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : u)
-  // CHECK-NEXT: int k = A->x + [[VAR]].x;
+  // CHECK: for (auto & i : u)
+  // CHECK-NEXT: int k = A->x + i.x;
 
   dependent<int> v;
   for (dependent<int>::const_iterator it = v.begin(), e = v.end();
        it != e; ++it) {
     printf("Fibonacci number is %d\n", *it);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : v)
-  // CHECK-NEXT: printf("Fibonacci number is %d\n", [[VAR]]);
+  // CHECK: for (auto & it : v)
+  // CHECK-NEXT: printf("Fibonacci number is %d\n", it);
 
   for (dependent<int>::const_iterator it(v.begin()), e = v.end();
        it != e; ++it) {
     printf("Fibonacci number is %d\n", *it);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : v)
-  // CHECK-NEXT: printf("Fibonacci number is %d\n", [[VAR]]);
+  // CHECK: for (auto & it : v)
+  // CHECK-NEXT: printf("Fibonacci number is %d\n", it);
 
   doublyDependent<int,int> intmap;
   for (doublyDependent<int,int>::iterator it = intmap.begin(), e = intmap.end();
        it != e; ++it) {
     printf("intmap[%d] = %d", it->first, it->second);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : intmap)
-  // CHECK-NEXT: printf("intmap[%d] = %d", [[VAR]].first, [[VAR]].second);
+  // CHECK: for (auto & it : intmap)
+  // CHECK-NEXT: printf("intmap[%d] = %d", it.first, it.second);
 
 }
Index: test/cpp11-migrate/LoopConvert/naming.cpp
===================================================================
--- test/cpp11-migrate/LoopConvert/naming.cpp
+++ test/cpp11-migrate/LoopConvert/naming.cpp
@@ -27,27 +27,27 @@
     int y = t.x;
     int z = Arr[i].x + t.x;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : Arr)
-  // CHECK-NEXT: Val &t = [[VAR]];
+  // CHECK: for (auto & i : Arr)
+  // CHECK-NEXT: Val &t = i;
   // CHECK-NEXT: int y = t.x;
-  // CHECK-NEXT: int z = [[VAR]].x + t.x;
+  // CHECK-NEXT: int z = i.x + t.x;
 
   for (int i = 0; i < N; ++i) {
     Val t = Arr[i];
     int y = t.x;
     int z = Arr[i].x + t.x;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : Arr)
-  // CHECK-NEXT: Val t = [[VAR]];
+  // CHECK: for (auto & i : Arr)
+  // CHECK-NEXT: Val t = i;
   // CHECK-NEXT: int y = t.x;
-  // CHECK-NEXT: int z = [[VAR]].x + t.x;
+  // CHECK-NEXT: int z = i.x + t.x;
 
   for (int i = 0; i < N; ++i) {
     Val &t = func(Arr[i]);
     int y = t.x;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : Arr)
-  // CHECK-NEXT: Val &t = func([[VAR]]);
+  // CHECK: for (auto & i : Arr)
+  // CHECK-NEXT: Val &t = func(i);
   // CHECK-NEXT: int y = t.x;
 }
 
@@ -59,9 +59,19 @@
     (void) nums[i];
   }
   // CHECK: int num = 0;
-  // CHECK-NEXT: for (auto & [[VAR:[a-z_]+]] : nums)
-  // CHECK-NEXT: printf("Fibonacci number is %d\n", [[VAR]]);
-  // CHECK-NEXT: sum += [[VAR]] + 2 + num;
+  // CHECK-NEXT: for (auto & i : nums)
+  // CHECK-NEXT: printf("Fibonacci number is %d\n", i);
+  // CHECK-NEXT: sum += i + 2 + num;
   // CHECK-NOT: (void) num;
   // CHECK: }
 }
+
+void reservedKeywords() {
+  int ints[N];
+  for (int i = 0; i < N; ++i) {
+    sum += ints[i];
+  }
+  // CHECK: int ints[N];
+  // CHECK-NEXT: for (auto & i : ints)
+  // CHECK-NEXT: sum += i;
+}
Index: test/cpp11-migrate/LoopConvert/nesting.cpp
===================================================================
--- test/cpp11-migrate/LoopConvert/nesting.cpp
+++ test/cpp11-migrate/LoopConvert/nesting.cpp
@@ -16,10 +16,10 @@
       int l = Arr[i].x + Arr[j].x;
     }
   }
-  // CHECK: for (auto & [[VAR:[a-zA-Z_]+]] : Arr)
-  // CHECK-NEXT: for (auto & [[INNERVAR:[a-zA-Z_]+]] : Arr)
-  // CHECK-NEXT: int k = [[VAR]].x + [[INNERVAR]].x;
-  // CHECK-NOT: int l = [[VAR]].x + [[VAR]].x;
+  // CHECK: for (auto & i : Arr)
+  // CHECK-NEXT: for (auto & j : Arr)
+  // CHECK-NEXT: int k = i.x + j.x;
+  // CHECK-NOT: int l = i.x + i.x;
 
   Val Nest[N][M];
   for (int i = 0; i < N; ++i) {
@@ -29,9 +29,9 @@
   }
   // The inner loop is also convertible, but doesn't need to be converted
   // immediately. Update this test when that changes!
-  // CHECK: for (auto & [[VAR:[a-zA-Z_]+]] : Nest)
+  // CHECK: for (auto & i : Nest)
   // CHECK-NEXT: for (int j = 0; j < M; ++j)
-  // CHECK-NEXT: printf("Got item %d", [[VAR]][j].x);
+  // CHECK-NEXT: printf("Got item %d", i[j].x);
 
   // Note that the order of M and N are switched for this test.
   for (int j = 0; j < M; ++j) {
@@ -41,17 +41,17 @@
   }
   // CHECK-NOT: for (auto & {{[a-zA-Z_]+}} : Nest[i])
   // CHECK: for (int j = 0; j < M; ++j)
-  // CHECK-NEXT: for (auto & [[VAR:[a-zA-Z_]+]] : Nest)
-  // CHECK-NEXT: printf("Got item %d", [[VAR]][j].x);
+  // CHECK-NEXT: for (auto & i : Nest)
+  // CHECK-NEXT: printf("Got item %d", i[j].x);
   Nested<T> NestT;
   for (Nested<T>::iterator I = NestT.begin(), E = NestT.end(); I != E; ++I) {
     for (T::iterator TI = (*I).begin(), TE = (*I).end(); TI != TE; ++TI) {
       printf("%d", *TI);
     }
   }
   // The inner loop is also convertible, but doesn't need to be converted
   // immediately. Update this test when that changes!
-  // CHECK: for (auto & [[VAR:[a-zA-Z_]+]] : NestT) {
-  // CHECK-NEXT: for (T::iterator TI = ([[VAR]]).begin(), TE = ([[VAR]]).end(); TI != TE; ++TI) {
+  // CHECK: for (auto & I : NestT) {
+  // CHECK-NEXT: for (T::iterator TI = (I).begin(), TE = (I).end(); TI != TE; ++TI) {
   // CHECK-NEXT: printf("%d", *TI);
 }
Index: test/cpp11-migrate/LoopConvert/pseudoarray.cpp
===================================================================
--- test/cpp11-migrate/LoopConvert/pseudoarray.cpp
+++ test/cpp11-migrate/LoopConvert/pseudoarray.cpp
@@ -15,25 +15,25 @@
     printf("Fibonacci number is %d\n", v[i]);
     sum += v[i] + 2;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : v)
-  // CHECK-NEXT: printf("Fibonacci number is %d\n", [[VAR]]);
-  // CHECK-NEXT: sum += [[VAR]] + 2;
+  // CHECK: for (auto & i : v)
+  // CHECK-NEXT: printf("Fibonacci number is %d\n", i);
+  // CHECK-NEXT: sum += i + 2;
 
   for (int i = 0, e = v.size(); i < e; ++i) {
     printf("Fibonacci number is %d\n", v.at(i));
     sum += v.at(i) + 2;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : v)
-  // CHECK-NEXT: printf("Fibonacci number is %d\n", [[VAR]]);
-  // CHECK-NEXT: sum += [[VAR]] + 2;
+  // CHECK: for (auto & i : v)
+  // CHECK-NEXT: printf("Fibonacci number is %d\n", i);
+  // CHECK-NEXT: sum += i + 2;
 
   for (int i = 0, e = pv->size(); i < e; ++i) {
     printf("Fibonacci number is %d\n", pv->at(i));
     sum += pv->at(i) + 2;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : *pv)
-  // CHECK-NEXT: printf("Fibonacci number is %d\n", [[VAR]]);
-  // CHECK-NEXT: sum += [[VAR]] + 2;
+  // CHECK: for (auto & i : *pv)
+  // CHECK-NEXT: printf("Fibonacci number is %d\n", i);
+  // CHECK-NEXT: sum += i + 2;
 
   // This test will fail if size() isn't called repeatedly, since it
   // returns unsigned int, and 0 is deduced to be signed int.
@@ -43,24 +43,24 @@
     printf("Fibonacci number is %d\n", (*pv).at(i));
     sum += (*pv)[i] + 2;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : *pv)
-  // CHECK-NEXT: printf("Fibonacci number is %d\n", [[VAR]]);
-  // CHECK-NEXT: sum += [[VAR]] + 2;
+  // CHECK: for (auto & i : *pv)
+  // CHECK-NEXT: printf("Fibonacci number is %d\n", i);
+  // CHECK-NEXT: sum += i + 2;
 
   for (int i = 0; i < cv->size(); ++i) {
     printf("Fibonacci number is %d\n", cv->at(i));
     sum += cv->at(i) + 2;
   }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : *cv)
-  // CHECK-NEXT: printf("Fibonacci number is %d\n", [[VAR]]);
-  // CHECK-NEXT: sum += [[VAR]] + 2;
+  // CHECK: for (auto & i : *cv)
+  // CHECK-NEXT: printf("Fibonacci number is %d\n", i);
+  // CHECK-NEXT: sum += i + 2;
 }
 
 // Check for loops that don't mention containers
 void noContainer() {
   for (auto i = 0; i < v.size(); ++i) { }
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : v) { }
+  // CHECK: for (auto & i : v) { }
 
   for (auto i = 0; i < v.size(); ++i) ;
-  // CHECK: for (auto & [[VAR:[a-z_]+]] : v) ;
+  // CHECK: for (auto & i : v) ;
 }
Index: test/cpp11-migrate/LoopConvert/single-iterator.cpp
===================================================================
--- test/cpp11-migrate/LoopConvert/single-iterator.cpp
+++ test/cpp11-migrate/LoopConvert/single-iterator.cpp
@@ -12,104 +12,104 @@
     MutableVal k = *i;
     MutableVal j = *i;
   }
-  // CHECK: for ({{[a-zA-Z_ ]+&? ?}}[[VAR:[a-z_]+]] : exes[index].getS())
-  // CHECK-NEXT: MutableVal k = [[VAR]];
-  // CHECK-NEXT: MutableVal j = [[VAR]];
+  // CHECK: for (auto & i : exes[index].getS())
+  // CHECK-NEXT: MutableVal k = i;
+  // CHECK-NEXT: MutableVal j = i;
 }
 
 void f() {
   /// begin()/end() - based for loops here:
   T t;
   for (T::iterator it = t.begin(); it != t.end(); ++it) {
     printf("I found %d\n", *it);
   }
-  // CHECK: for ({{[a-zA-Z_ ]+&? ?}}[[VAR:[a-z_]+]] : t)
-  // CHECK-NEXT: printf("I found %d\n", [[VAR]]);
+  // CHECK: for (auto & it : t)
+  // CHECK-NEXT: printf("I found %d\n", it);
 
   T *pt;
   for (T::iterator it = pt->begin(); it != pt->end(); ++it) {
     printf("I found %d\n", *it);
   }
-  // CHECK: for ({{[a-zA-Z_ ]+&? ?}}[[VAR:[a-z_]+]] : *pt)
-  // CHECK-NEXT: printf("I found %d\n", [[VAR]]);
+  // CHECK: for (auto & it : *pt)
+  // CHECK-NEXT: printf("I found %d\n", it);
 
   S s;
   for (S::const_iterator it = s.begin(); it != s.end(); ++it) {
     printf("s has value %d\n", (*it).x);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : s)
-  // CHECK-NEXT: printf("s has value %d\n", ([[VAR]]).x);
+  // CHECK: for (auto & it : s)
+  // CHECK-NEXT: printf("s has value %d\n", (it).x);
 
   S *ps;
   for (S::const_iterator it = ps->begin(); it != ps->end(); ++it) {
     printf("s has value %d\n", (*it).x);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : *ps)
-  // CHECK-NEXT: printf("s has value %d\n", ([[VAR]]).x);
+  // CHECK: for (auto & it : *ps)
+  // CHECK-NEXT: printf("s has value %d\n", (it).x);
 
   for (S::const_iterator it = s.begin(); it != s.end(); ++it) {
     printf("s has value %d\n", it->x);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : s)
-  // CHECK-NEXT: printf("s has value %d\n", [[VAR]].x);
+  // CHECK: for (auto & it : s)
+  // CHECK-NEXT: printf("s has value %d\n", it.x);
 
   for (S::iterator it = s.begin(); it != s.end(); ++it) {
     it->x = 3;
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : s)
-  // CHECK-NEXT: [[VAR]].x = 3;
+  // CHECK: for (auto & it : s)
+  // CHECK-NEXT: it.x = 3;
 
   for (S::iterator it = s.begin(); it != s.end(); ++it) {
     (*it).x = 3;
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : s)
-  // CHECK-NEXT: ([[VAR]]).x = 3;
+  // CHECK: for (auto & it : s)
+  // CHECK-NEXT: (it).x = 3;
 
   for (S::iterator it = s.begin(); it != s.end(); ++it) {
     it->nonConstFun(4, 5);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : s)
-  // CHECK-NEXT: [[VAR]].nonConstFun(4, 5);
+  // CHECK: for (auto & it : s)
+  // CHECK-NEXT: it.nonConstFun(4, 5);
 
   U u;
   for (U::iterator it = u.begin(); it != u.end(); ++it) {
     printf("s has value %d\n", it->x);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : u)
-  // CHECK-NEXT: printf("s has value %d\n", [[VAR]].x);
+  // CHECK: for (auto & it : u)
+  // CHECK-NEXT: printf("s has value %d\n", it.x);
 
   for (U::iterator it = u.begin(); it != u.end(); ++it) {
     printf("s has value %d\n", (*it).x);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : u)
-  // CHECK-NEXT: printf("s has value %d\n", ([[VAR]]).x);
+  // CHECK: for (auto & it : u)
+  // CHECK-NEXT: printf("s has value %d\n", (it).x);
 
   U::iterator A;
   for (U::iterator i = u.begin(); i != u.end(); ++i)
     int k = A->x + i->x;
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : u)
-  // CHECK-NEXT: int k = A->x + [[VAR]].x;
+  // CHECK: for (auto & i : u)
+  // CHECK-NEXT: int k = A->x + i.x;
 
   dependent<int> v;
   for (dependent<int>::const_iterator it = v.begin();
        it != v.end(); ++it) {
     printf("Fibonacci number is %d\n", *it);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : v)
-  // CHECK-NEXT: printf("Fibonacci number is %d\n", [[VAR]]);
+  // CHECK: for (auto & it : v)
+  // CHECK-NEXT: printf("Fibonacci number is %d\n", it);
 
   for (dependent<int>::const_iterator it(v.begin());
        it != v.end(); ++it) {
     printf("Fibonacci number is %d\n", *it);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : v)
-  // CHECK-NEXT: printf("Fibonacci number is %d\n", [[VAR]]);
+  // CHECK: for (auto & it : v)
+  // CHECK-NEXT: printf("Fibonacci number is %d\n", it);
 
   doublyDependent<int,int> intmap;
   for (doublyDependent<int,int>::iterator it = intmap.begin();
        it != intmap.end(); ++it) {
     printf("intmap[%d] = %d", it->first, it->second);
   }
-  // CHECK: for ({{[a-zA-Z_ ]*&? ?}}[[VAR:[a-z_]+]] : intmap)
-  // CHECK-NEXT: printf("intmap[%d] = %d", [[VAR]].first, [[VAR]].second);
+  // CHECK: for (auto & it : intmap)
+  // CHECK-NEXT: printf("intmap[%d] = %d", it.first, it.second);
 }
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to