more warning testcases
authorMatthias Braun <matze@braunis.de>
Sun, 26 Oct 2008 12:02:46 +0000 (12:02 +0000)
committerMatthias Braun <matze@braunis.de>
Sun, 26 Oct 2008 12:02:46 +0000 (12:02 +0000)
[r23204]

16 files changed:
parsetest/nowarn/write_only.c [new file with mode: 0644]
parsetest/nowarn/write_only1.c [new file with mode: 0644]
parsetest/nowarn/write_only10.c [new file with mode: 0644]
parsetest/nowarn/write_only5.c [new file with mode: 0644]
parsetest/nowarn/write_only7.c [new file with mode: 0644]
parsetest/nowarn/write_only9.c [new file with mode: 0644]
parsetest/should_warn/README [new file with mode: 0644]
parsetest/should_warn/never_read1.c [new file with mode: 0644]
parsetest/should_warn/write_only.c [new file with mode: 0644]
parsetest/should_warn/write_only11.c [new file with mode: 0644]
parsetest/should_warn/write_only12.c [new file with mode: 0644]
parsetest/should_warn/write_only2.c [new file with mode: 0644]
parsetest/should_warn/write_only3.c [new file with mode: 0644]
parsetest/should_warn/write_only4.c [new file with mode: 0644]
parsetest/should_warn/write_only6.c [new file with mode: 0644]
parsetest/should_warn/write_only8.c [new file with mode: 0644]

diff --git a/parsetest/nowarn/write_only.c b/parsetest/nowarn/write_only.c
new file mode 100644 (file)
index 0000000..0ef48b7
--- /dev/null
@@ -0,0 +1,34 @@
+struct X { int i[10]; int j; struct X* next; };
+
+void f(int parm)
+{{
+#if 0
+       parm++;
+       int x = 0;
+       int y = 1;
+       x = x + y;
+       for (int z = 0;; ++z) {
+               z;
+       }
+       int* a = 0;
+       a = &a[*a];
+       int* b = 0;
+       b = b[*b] = 0;
+       for (struct X* px = 0;; px = px->next) {}
+       struct X* x2 = 0;
+       x2->next = 0;
+       int c;
+       c = *&c = 0;
+       int d = 23;
+       int e = 42;
+       asm("" : "+r" (e) : "r" (d));
+       struct X* x3 = 0;
+       x3->i[2] = 0;
+       int i[10];
+       i[0] = 1;
+       int j[10];
+       j[j[j[0]]] = 23;
+#endif
+       struct X* x4 = 0;
+       x4->j++;
+}}
diff --git a/parsetest/nowarn/write_only1.c b/parsetest/nowarn/write_only1.c
new file mode 100644 (file)
index 0000000..2f4c6d8
--- /dev/null
@@ -0,0 +1,8 @@
+struct X { int i[10]; int j; struct X* next; } gX;
+
+int main(void)
+{
+       struct X* x4 = &gX;
+       x4->j++;
+       return 0;
+}
diff --git a/parsetest/nowarn/write_only10.c b/parsetest/nowarn/write_only10.c
new file mode 100644 (file)
index 0000000..7cacb7a
--- /dev/null
@@ -0,0 +1,8 @@
+struct X { int i[10]; int j; struct X* next; } gX;
+
+int main(void)
+{
+       struct X* x3 = &gX;
+       x3->i[2] = 0;
+       return 0;
+}
diff --git a/parsetest/nowarn/write_only5.c b/parsetest/nowarn/write_only5.c
new file mode 100644 (file)
index 0000000..447e458
--- /dev/null
@@ -0,0 +1,9 @@
+int A;
+
+int main(void)
+{
+       int *a = &A;
+       a[*a] = 0;
+
+       return 0;
+}
diff --git a/parsetest/nowarn/write_only7.c b/parsetest/nowarn/write_only7.c
new file mode 100644 (file)
index 0000000..a34452f
--- /dev/null
@@ -0,0 +1,8 @@
+struct X { int i[10]; int j; struct X* next; } gX;
+
+int main(void)
+{
+       struct X* x2 = &gX;
+       x2->next = 0;
+       return 0;
+}
diff --git a/parsetest/nowarn/write_only9.c b/parsetest/nowarn/write_only9.c
new file mode 100644 (file)
index 0000000..661aba9
--- /dev/null
@@ -0,0 +1,7 @@
+int main(void)
+{
+       int d = 23;
+       int e = 42;
+       asm("" : "+r" (e) : "r" (d));
+       return 0;
+}
diff --git a/parsetest/should_warn/README b/parsetest/should_warn/README
new file mode 100644 (file)
index 0000000..345bb61
--- /dev/null
@@ -0,0 +1,2 @@
+This directory contains testcases that should produces a certain warning
+(but no syntax errors)
diff --git a/parsetest/should_warn/never_read1.c b/parsetest/should_warn/never_read1.c
new file mode 100644 (file)
index 0000000..360070f
--- /dev/null
@@ -0,0 +1,9 @@
+/* -w -Wunused-variable */
+extern int rand(void);
+
+int main(void)
+{
+       int x = 23;
+       x = rand();
+       return 0;
+}
diff --git a/parsetest/should_warn/write_only.c b/parsetest/should_warn/write_only.c
new file mode 100644 (file)
index 0000000..0ef48b7
--- /dev/null
@@ -0,0 +1,34 @@
+struct X { int i[10]; int j; struct X* next; };
+
+void f(int parm)
+{{
+#if 0
+       parm++;
+       int x = 0;
+       int y = 1;
+       x = x + y;
+       for (int z = 0;; ++z) {
+               z;
+       }
+       int* a = 0;
+       a = &a[*a];
+       int* b = 0;
+       b = b[*b] = 0;
+       for (struct X* px = 0;; px = px->next) {}
+       struct X* x2 = 0;
+       x2->next = 0;
+       int c;
+       c = *&c = 0;
+       int d = 23;
+       int e = 42;
+       asm("" : "+r" (e) : "r" (d));
+       struct X* x3 = 0;
+       x3->i[2] = 0;
+       int i[10];
+       i[0] = 1;
+       int j[10];
+       j[j[j[0]]] = 23;
+#endif
+       struct X* x4 = 0;
+       x4->j++;
+}}
diff --git a/parsetest/should_warn/write_only11.c b/parsetest/should_warn/write_only11.c
new file mode 100644 (file)
index 0000000..d677b4a
--- /dev/null
@@ -0,0 +1,6 @@
+int main(void)
+{
+       int i[10];
+       i[0] = 1;
+       return 0;
+}
diff --git a/parsetest/should_warn/write_only12.c b/parsetest/should_warn/write_only12.c
new file mode 100644 (file)
index 0000000..8bad87a
--- /dev/null
@@ -0,0 +1,6 @@
+int main(void)
+{
+       int j[10];
+       j[j[j[0]]] = 23;
+       return 0;
+}
diff --git a/parsetest/should_warn/write_only2.c b/parsetest/should_warn/write_only2.c
new file mode 100644 (file)
index 0000000..595fd7d
--- /dev/null
@@ -0,0 +1,9 @@
+struct X { int i[10]; int j; struct X* next; } gX;
+
+int main(void)
+{
+       int x = 0;
+       int y = 1;
+       x = x + y;
+       return 0;
+}
diff --git a/parsetest/should_warn/write_only3.c b/parsetest/should_warn/write_only3.c
new file mode 100644 (file)
index 0000000..c361562
--- /dev/null
@@ -0,0 +1,8 @@
+extern int rand(void);
+
+int main(void)
+{
+       for(int z = 0; rand() % 2 != 0; ++z)
+               z;
+       return 0;
+}
diff --git a/parsetest/should_warn/write_only4.c b/parsetest/should_warn/write_only4.c
new file mode 100644 (file)
index 0000000..2f413d3
--- /dev/null
@@ -0,0 +1,9 @@
+int A;
+
+int main(void)
+{
+       int *a = &A;
+       a = &a[*a];
+
+       return 0;
+}
diff --git a/parsetest/should_warn/write_only6.c b/parsetest/should_warn/write_only6.c
new file mode 100644 (file)
index 0000000..6346e60
--- /dev/null
@@ -0,0 +1,11 @@
+struct X { int i[10]; int j; struct X* next; } gX;
+
+extern int rand(void);
+
+int main(void)
+{
+       for (struct X* px = &gX; rand() % 2 == 0; px = px->next)
+       {}
+
+       return 0;
+}
diff --git a/parsetest/should_warn/write_only8.c b/parsetest/should_warn/write_only8.c
new file mode 100644 (file)
index 0000000..69627b2
--- /dev/null
@@ -0,0 +1,6 @@
+int main(void)
+{
+       int c;
+       c = *&c = 0;
+       return 0;
+}