Files
clang-p2996/clang-tools-extra/test/loop-convert/naming.cpp
David Blaikie efae14e96c Fix tests to be more robust (to older versions of grep, lesser lit-like test runners, etc)
Seems I had a problem with my version of grep, when run by lit, not supporting
the \s escape. This seems to fix it for me & I'll be getting the buildbots to
run these tests too to keep an eye on them (actually loop-convert tests still
fail when run via a make build, so that'll be addressed in a future commit). I
could use [[:space:]] to generalize over other whitespace but that seemed
unnecessarily verbose when the flexibility wasn't actually required by the
current text of the tests.

Also I just simplified a lot of the loop-convert tests (removing the
unecessary temp file deletion at the start, removing the unnecessary && for
FileCheck, etc).

The remove-cstr-calls/basic.cpp changes were necessitated by an out of tree
lit-like test runner that's a bit less fantastic about escaping. They were
modeled on existing tooling test cases in Clang, with thanks to Manuel Klimek
for the pointers.

llvm-svn: 163009
2012-08-31 17:49:33 +00:00

68 lines
1.6 KiB
C++

// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
// RUN: loop-convert . %t.cpp -- -I %S/Inputs
// RUN: FileCheck -input-file=%t.cpp %s
#include "structures.h"
const int N = 10;
int nums[N];
int sum = 0;
Val Arr[N];
Val &func(Val &);
void aliasing() {
// 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-NEXT: { }
// CHECK-NEXT: int y = 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-NEXT: int y = t.x;
// CHECK-NEXT: int z = [[VAR]].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-NEXT: int y = t.x;
// CHECK-NEXT: int z = [[VAR]].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-NEXT: int y = t.x;
}
void sameNames() {
int num = 0;
for (int i = 0; i < N; ++i) {
printf("Fibonacci number is %d\n", nums[i]);
sum += nums[i] + 2 + num;
(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-NOT: (void) num;
// CHECK: }
}