The loop convert tests for conflicting names have been extended to check for macro names, types, and language keywords including language extensions. Tests have also been added. Fixes PR15322 Author: Jack Yang <jack.yang@intel.com> Reviewer: gribozavr, klimek, revane llvm-svn: 176690
60 lines
1.7 KiB
C++
60 lines
1.7 KiB
C++
// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
|
|
// RUN: cpp11-migrate -loop-convert %t.cpp -- -I %S/Inputs
|
|
// RUN: FileCheck -input-file=%t.cpp %s
|
|
|
|
#include "structures.h"
|
|
|
|
const int N = 10;
|
|
|
|
Val Arr[N];
|
|
Val &func(Val &);
|
|
|
|
void aliasing() {
|
|
// If the loop container is only used for a declaration of a temporary
|
|
// variable to hold each element, we can name the new variable for the
|
|
// converted range-based loop as the temporary variable's name.
|
|
|
|
// In the following case, "t" is used as a temporary variable to hold each
|
|
// element, and thus we consider the name "t" aliased to the loop.
|
|
// The extra blank braces are left as a placeholder for after the variable
|
|
// declaration is deleted.
|
|
for (int i = 0; i < N; ++i) {
|
|
Val &t = Arr[i]; { }
|
|
int y = t.x;
|
|
}
|
|
// CHECK: for (auto & t : Arr)
|
|
// CHECK-NOT: Val &{{[a-z_]+}} =
|
|
// CHECK-NEXT: { }
|
|
// CHECK-NEXT: int y = t.x;
|
|
|
|
// The container was not only used to initialize a temporary loop variable for
|
|
// the container's elements, so we do not alias the new loop variable.
|
|
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 & elem : Arr)
|
|
// CHECK-NEXT: Val &t = elem;
|
|
// CHECK-NEXT: int y = t.x;
|
|
// CHECK-NEXT: int z = elem.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 & elem : Arr)
|
|
// CHECK-NEXT: Val t = elem;
|
|
// CHECK-NEXT: int y = t.x;
|
|
// CHECK-NEXT: int z = elem.x + t.x;
|
|
|
|
for (int i = 0; i < N; ++i) {
|
|
Val &t = func(Arr[i]);
|
|
int y = t.x;
|
|
}
|
|
// CHECK: for (auto & elem : Arr)
|
|
// CHECK-NEXT: Val &t = func(elem);
|
|
// CHECK-NEXT: int y = t.x;
|
|
}
|