diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2013-09-04 17:35:07 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2013-09-04 17:35:07 +0000 |
commit | d9063c46f59f4bec47bcbeddca8ca2f789348c03 (patch) | |
tree | 76505542df7a05016dc71ffe44ed3ba264fb54be /clang-tools-extra/test/clang-modernize/LoopConvert/naming-alias.cpp | |
parent | 6a23d212897d5402035cfaea82260f6dae1c8f2a (diff) | |
download | bcm5719-llvm-d9063c46f59f4bec47bcbeddca8ca2f789348c03.tar.gz bcm5719-llvm-d9063c46f59f4bec47bcbeddca8ca2f789348c03.zip |
Rename cpp11-migrate to clang-modernize.
There is no reason to expect this tool to be limited to C++11, it seems
very likely to be of on-going interest. It seems likely to be useful for
modernizing even as new libraries come out in TSes and other formats
than a complete standard. Fundamentally, we need something a bit more
general. After some discussion on the list, going with
'clang-modernize'.
I've tried to do a reasonably comprehensive job of fixing up the names,
but I may still have missed some. Feel free to poke me if you spot any
fallout here. Things I've tried reasonably hard to find and fix:
- cpp11-migrate -> clang-modernize
- Migrator -> Modernizer
- Clean up the introductory documentation that was C++11 specific.
I'll also point out that this tool continues to delight me. =] Also,
a huge thanks to those who have so carefully, thoroughly documented the
tool. The docs here are simply phenomenal. Every tool should be this
well documented. I hope I have updated the documentation reasonably
well, but I'm not very good at documentation, so review much
appreciated.
llvm-svn: 189960
Diffstat (limited to 'clang-tools-extra/test/clang-modernize/LoopConvert/naming-alias.cpp')
-rw-r--r-- | clang-tools-extra/test/clang-modernize/LoopConvert/naming-alias.cpp | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-modernize/LoopConvert/naming-alias.cpp b/clang-tools-extra/test/clang-modernize/LoopConvert/naming-alias.cpp new file mode 100644 index 00000000000..343dd0cc650 --- /dev/null +++ b/clang-tools-extra/test/clang-modernize/LoopConvert/naming-alias.cpp @@ -0,0 +1,139 @@ +// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp +// RUN: clang-modernize -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 sideEffect(int); + +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; + + int IntArr[N]; + for (unsigned i = 0; i < N; ++i) { + if (int alias = IntArr[i]) { + sideEffect(alias); + } + } + // CHECK: for (auto alias : IntArr) + // CHECK-NEXT: if (alias) { + + for (unsigned i = 0; i < N; ++i) { + while (int alias = IntArr[i]) { + sideEffect(alias); + } + } + // CHECK: for (auto alias : IntArr) + // CHECK-NEXT: while (alias) { + + for (unsigned i = 0; i < N; ++i) { + switch (int alias = IntArr[i]) { + default: + sideEffect(alias); + } + } + // CHECK: for (auto alias : IntArr) + // CHECK-NEXT: switch (alias) { + + for (unsigned i = 0; i < N; ++i) { + for (int alias = IntArr[i]; alias < N; ++alias) { + sideEffect(alias); + } + } + // CHECK: for (auto alias : IntArr) + // CHECK-NEXT: for (; alias < N; ++alias) { + + for (unsigned i = 0; i < N; ++i) { + for (unsigned j = 0; int alias = IntArr[i]; ++j) { + sideEffect(alias); + } + } + // CHECK: for (auto alias : IntArr) + // CHECK-NEXT: for (unsigned j = 0; alias; ++j) { +} + +void refs_and_vals() { + // The following tests check that the transform correctly preserves the + // reference or value qualifiers of the aliased variable. That is, if the + // variable was declared as a value, the loop variable will be declared as a + // value and vice versa for references. + + S s; + const S s_const = s; + + for (S::const_iterator it = s_const.begin(); it != s_const.end(); ++it) { + MutableVal alias = *it; { } + alias.x = 0; + } + // CHECK: for (auto alias : s_const) + // CHECK-NOT: MutableVal {{[a-z_]+}} = + // CHECK-NEXT: { } + // CHECK-NEXT: alias.x = 0; + + for (S::iterator it = s.begin(), e = s.end(); it != e; ++it) { + MutableVal alias = *it; { } + alias.x = 0; + } + // CHECK: for (auto alias : s) + // CHECK-NOT: MutableVal {{[a-z_]+}} = + // CHECK-NEXT: { } + // CHECK-NEXT: alias.x = 0; + + for (S::iterator it = s.begin(), e = s.end(); it != e; ++it) { + MutableVal &alias = *it; { } + alias.x = 0; + } + // CHECK: for (auto & alias : s) + // CHECK-NOT: MutableVal &{{[a-z_]+}} = + // CHECK-NEXT: { } + // CHECK-NEXT: alias.x = 0; +} |