aboutsummaryrefslogtreecommitdiff
path: root/test/Analysis/copypaste/labels.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/Analysis/copypaste/labels.cpp')
-rw-r--r--test/Analysis/copypaste/labels.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/Analysis/copypaste/labels.cpp b/test/Analysis/copypaste/labels.cpp
new file mode 100644
index 000000000000..26318ac40510
--- /dev/null
+++ b/test/Analysis/copypaste/labels.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -analyze -std=gnu++11 -analyzer-checker=alpha.clone.CloneChecker -verify %s
+
+// expected-no-diagnostics
+
+
+bool foo1(int x) {
+ start:
+ if (x != 3) {
+ ++x;
+ void *ptr = &&start;
+ goto start;
+ }
+ end:
+ return false;
+}
+
+// Targeting a different label with the address-of-label operator.
+bool foo2(int x) {
+ start:
+ if (x != 3) {
+ ++x;
+ void *ptr = &&end;
+ goto start;
+ }
+ end:
+ return false;
+}
+
+// Different target label in goto
+bool foo3(int x) {
+ start:
+ if (x != 3) {
+ ++x;
+ void *ptr = &&start;
+ goto end;
+ }
+ end:
+ return false;
+}
+
+// FIXME: Can't detect same algorithm as in foo1 but with different label names.
+bool foo4(int x) {
+ foo:
+ if (x != 3) {
+ ++x;
+ void *ptr = &&foo;
+ goto foo;
+ }
+ end:
+ return false;
+}