Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: test declarations in C...



details:   https://anonhg.NetBSD.org/src/rev/989ac1344fce
branches:  trunk
changeset: 378267:989ac1344fce
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jul 28 22:05:44 2023 +0000

description:
tests/lint: test declarations in C11 and C23

diffstat:

 tests/usr.bin/xlint/lint1/c11.c |  107 +++++++++++++++++++++++++++++++++++++++-
 tests/usr.bin/xlint/lint1/c23.c |    8 ++-
 2 files changed, 112 insertions(+), 3 deletions(-)

diffs (156 lines):

diff -r 02f3429d8b63 -r 989ac1344fce tests/usr.bin/xlint/lint1/c11.c
--- a/tests/usr.bin/xlint/lint1/c11.c   Fri Jul 28 21:50:03 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/c11.c   Fri Jul 28 22:05:44 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: c11.c,v 1.3 2023/07/13 20:30:21 rillig Exp $   */
+/*     $NetBSD: c11.c,v 1.4 2023/07/28 22:05:44 rillig Exp $   */
 # 3 "c11.c"
 
 /*
@@ -6,7 +6,7 @@
  * functions, anonymous struct/union members, and several more.
  */
 
-/* lint1-flags: -Ac11 -w -X 236 -X 351 */
+/* lint1-flags: -Ac11 -w -X 192,231,236,351 */
 
 _Noreturn void exit(int);
 void _Noreturn exit(int);
@@ -42,6 +42,109 @@ three_times(void)
        exit(0);
 }
 
+
+_Static_assert(1 > 0, "string");
+/* XXX: requires C23 or later */
+_Static_assert(1 > 0);
+
+
+// C11 6.7.6.1p3
+const int *ptr_to_constant;
+int *const constant_ptr;
+
+// C11 6.7.6.1p4
+typedef int *int_ptr;
+const int_ptr constant_ptr;
+
+// C11 6.7.6.2p7
+float fa[11], *afp[17];
+
+// C11 6.7.6.2p8
+extern int *x;
+extern int y[];
+
+// C11 6.7.6.2p9
+extern int n;
+extern int m;
+void fcompat(void)
+{
+       int a[n][6][m];
+       int (*p)[4][n+1];
+       int c[n][n][6][m];
+       int (*r)[n][n][n+1];
+       /* expect+2: warning: 'p' set but not used in function 'fcompat' [191] */
+       /* expect+1: warning: illegal combination of 'pointer to array[4] of array[1] of int' and 'pointer to array[6] of array[1] of int', op '=' [124] */
+       p = a;
+       /* expect+2: warning: 'r' set but not used in function 'fcompat' [191] */
+       /* expect+1: warning: illegal combination of 'pointer to array[1] of array[1] of array[1] of int' and 'pointer to array[1] of array[6] of array[1] of int', op '=' [124] */
+       r = c;
+}
+
+// C11 6.7.6.2p10
+extern int n;
+int A[n];
+extern int (*p2)[n];
+int B[100];
+void fvla(int m, int C[m][m]);
+void fvla(int m, int C[m][m])
+{
+       typedef int VLA[m][m];
+       struct tag {
+               int (*y)[n];
+               int z[n];
+       };
+       int D[m];
+       static int E[m];
+       /* expect+1: warning: nested 'extern' declaration of 'F' [352] */
+       extern int F[m];
+       int (*s)[m];
+       /* expect+1: warning: nested 'extern' declaration of 'r' [352] */
+       extern int (*r)[m];
+       /* expect+2: warning: illegal combination of 'pointer to array[1] of int' and 'pointer to int', op 'init' [124] */
+       /* expect+1: warning: 'q' set but not used in function 'fvla' [191] */
+       static int (*q)[m] = &B;
+}
+
+// C11 6.7.6.3p15
+int f(void), *fip(), (*pfi)();
+
+// C11 6.7.6.3p17
+int (*apfi[3])(int *x, int *y);
+
+// C11 6.7.6.3p18
+int (*fpfi(int (*)(long), int))(int, ...);
+
+// C11 6.7.6.3p19
+void addscalar(int n, int m, double a[n][n*m+300], double x);
+int main(void)
+{
+       double b[4][308];
+       /* expect+1: warning: converting 'pointer to array[308] of double' to incompatible 'pointer to array[1] of double' for argument 3 [153] */
+       addscalar(4, 2, b, 2.17);
+       return 0;
+}
+void addscalar(int n, int m, double a[n][n*m+300], double x)
+{
+       for (int i = 0; i < n; i++)
+               for (int j = 0, k = n*m+300; j < k; j++)
+                       a[i][j] += x;
+}
+
+// C11 6.7.6.3p20
+double maximum(int n, int m, double a[n][m]);
+/* expect+1: error: null dimension [17] */
+double maximum(int n, int m, double a[*][*]);
+/* expect+1: error: null dimension [17] */
+double maximum(int n, int m, double a[ ][*]);
+double maximum(int n, int m, double a[ ][m]);
+
+void f1(double (* restrict a)[5]);
+void f2(double a[restrict][5]);
+/* expect+1: error: syntax error '3' [249] */
+void f3(double a[restrict 3][5]);
+void f4(double a[restrict static 3][5]);
+
+
 // In C11 mode, 'thread_local' is not yet known, but '_Thread_local' is.
 /* expect+2: error: old-style declaration; add 'int' [1] */
 /* expect+1: error: syntax error 'int' [249] */
diff -r 02f3429d8b63 -r 989ac1344fce tests/usr.bin/xlint/lint1/c23.c
--- a/tests/usr.bin/xlint/lint1/c23.c   Fri Jul 28 21:50:03 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/c23.c   Fri Jul 28 22:05:44 2023 +0000
@@ -1,10 +1,11 @@
-/*     $NetBSD: c23.c,v 1.6 2023/07/25 16:56:35 rillig Exp $   */
+/*     $NetBSD: c23.c,v 1.7 2023/07/28 22:05:44 rillig Exp $   */
 # 3 "c23.c"
 
 // Tests for the option -Ac23, which allows features from C23 and all earlier
 // ISO standards, but none of the GNU extensions.
 //
 // See also:
+//     c11.c
 //     msg_353.c               for empty initializer braces
 
 /* lint1-flags: -Ac23 -w -X 351 */
@@ -22,6 +23,11 @@ empty_initializer_braces(void)
        return s.member;
 }
 
+
+_Static_assert(1 > 0, "string");
+_Static_assert(1 > 0);
+
+
 // The keyword 'thread_local' was introduced in C23.
 thread_local int globally_visible;
 



Home | Main Index | Thread Index | Old Index