diff options
Diffstat (limited to 'contrib/netbsd-tests/usr.bin/xlint/lint1')
53 files changed, 739 insertions, 0 deletions
diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_alignof.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_alignof.c new file mode 100644 index 000000000000..4a661346305b --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_alignof.c @@ -0,0 +1,6 @@ +/* __alignof__ */ +int +main(void) +{ + return __alignof__(short); +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_anon_struct.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_anon_struct.c new file mode 100644 index 000000000000..367b56fa1a85 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_anon_struct.c @@ -0,0 +1,26 @@ +/* Anonymous struct test */ + +typedef int type; + +struct point { + int x; + int y; +}; + +struct bar { + struct { + struct point top_left; + struct point bottom_right; + }; + type z; +}; + + +int +main(void) +{ + struct bar b; + b.top_left.x = 1; + return 0; +} + diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_anon_union.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_anon_union.c new file mode 100644 index 000000000000..508bcc9bdf43 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_anon_union.c @@ -0,0 +1,16 @@ +/* struct with only anonymous members */ + +struct foo { + union { + long loo; + double doo; + }; +}; + +int +main(void) { + + struct foo *f = 0; + printf("%p\n", &f[1]); + return 0; +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_complex_num.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_complex_num.c new file mode 100644 index 000000000000..c3c952e7b722 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_complex_num.c @@ -0,0 +1,7 @@ +double cabs(double _Complex); + +double cabs(double _Complex foo) +{ + double d = __real__ foo; + return d + 0.1fi; +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_complex_split.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_complex_split.c new file mode 100644 index 000000000000..7b3d1a1d501e --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_complex_split.c @@ -0,0 +1,8 @@ +int b(double a) { + return a == 0; +} +void a(void) { + double _Complex z = 0; + if (b(__real__ z) && b(__imag__ z)) + return; +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_compound_literal_comma.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_compound_literal_comma.c new file mode 100644 index 000000000000..ca70694b4270 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_compound_literal_comma.c @@ -0,0 +1,14 @@ +struct bintime { + unsigned long long sec; + unsigned long long frac; +}; + +struct bintime +us2bintime(unsigned long long us) +{ + + return (struct bintime) { + .sec = us / 1000000U, + .frac = (((us % 1000000U) >> 32)/1000000U) >> 32, + }; +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_decls_after_stmt.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_decls_after_stmt.c new file mode 100644 index 000000000000..f32a963c76b0 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_decls_after_stmt.c @@ -0,0 +1,5 @@ +void sample(void) +{ + int i = 0; i += 1; + int j = 0; j += 1; +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_decls_after_stmt2.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_decls_after_stmt2.c new file mode 100644 index 000000000000..960d392350ca --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_decls_after_stmt2.c @@ -0,0 +1,6 @@ +typedef int int_t; +int main(void) { +int i = 0; i += 1; +int_t j = 0; j += 1; +return 0; +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_decls_after_stmt3.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_decls_after_stmt3.c new file mode 100644 index 000000000000..278fe1bb713c --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_decls_after_stmt3.c @@ -0,0 +1,5 @@ +void sample(int i) +{ + i += 1; + int j = 0; j += 1; +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_flex_array_packed.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_flex_array_packed.c new file mode 100644 index 000000000000..e7b875617131 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_flex_array_packed.c @@ -0,0 +1,6 @@ +/* Allow packed c99 flexible arrays */ +struct { + int x; + char y[0]; +} __packed foo; + diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_for_loops.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_for_loops.c new file mode 100644 index 000000000000..48e380cb3600 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_for_loops.c @@ -0,0 +1,15 @@ +/* c99 for loops */ +extern void foo(int); + +int +main(void) +{ + // Test the basic functionality + for (int i = 0; i < 10; i++) + foo(i); + + // Test that the scope of the iterator is correct + for (int i = 0; i < 10; i++) + continue; + return 0; +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_func.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_func.c new file mode 100644 index 000000000000..b827bfa9f6bc --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_func.c @@ -0,0 +1,7 @@ +/* C99 __func__ */ + +void +foo(const char *p) { + p = __func__; + foo(p); +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_nested_struct.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_nested_struct.c new file mode 100644 index 000000000000..15410c899739 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_nested_struct.c @@ -0,0 +1,25 @@ +/* C99 nested struct init with named and non-named initializers */ +typedef struct pthread_mutex_t { + unsigned int ptm_magic; + char ptm_errorcheck; + + char ptm_pad1[3]; + + char ptm_interlock; + + char ptm_pad2[3]; + + volatile void * ptm_owner; + void * volatile ptm_waiters; + unsigned int ptm_recursed; + void *ptm_spare2; +} pthread_mutex_t; + + +struct arc4random_global { + + pthread_mutex_t lock; +} arc4random_global = { + + .lock = { 0x33330003, 0, { 0, 0, 0 }, 0, { 0, 0, 0 }, ((void *)0), ((void *)0), 0, ((void *)0) }, +}; diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_recursive_init.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_recursive_init.c new file mode 100644 index 000000000000..347644ffe107 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_recursive_init.c @@ -0,0 +1,13 @@ +/* C99 recursive struct/union initialization */ +struct top { + int i; + char c; + union onion { + short us; + char uc; + } u; + char *s; +} c[] = { + { .s = "foo", .c = 'b', .u = { .uc = 'c' } }, + { .i = 1, .c = 'a', .u = { .us = 2 } }, +}; diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_struct_init.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_struct_init.c new file mode 100644 index 000000000000..a94cbd163897 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_struct_init.c @@ -0,0 +1,10 @@ +/* C99 struct initialization */ +struct { + int i; + char *s; +} c[] = { + { .i = 2, }, + { .s = "foo" }, + { .i = 1, .s = "bar" }, + { .s = "foo", .i = -1 }, +}; diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_union_cast.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_union_cast.c new file mode 100644 index 000000000000..31628b456288 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_union_cast.c @@ -0,0 +1,18 @@ +/* union cast */ + +struct bar { + int a; + int b; +}; + +union foo { + struct bar *a; + int b; +}; + +void +foo(void) { + struct bar *a; + + ((union foo)a).a; +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_union_init1.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_union_init1.c new file mode 100644 index 000000000000..0e1a1a8323d9 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_union_init1.c @@ -0,0 +1,8 @@ +/* C99 union initialization */ +union { + int i; + char *s; +} c[] = { + { i: 1 }, + { s: "foo" } +}; diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_union_init2.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_union_init2.c new file mode 100644 index 000000000000..51d34d450f21 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_union_init2.c @@ -0,0 +1,8 @@ +/* C99 union initialization */ +union { + int i[10]; + short s; +} c[] = { + { s: 2 }, + { i: { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } }, +}; diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_union_init3.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_union_init3.c new file mode 100644 index 000000000000..f5e8b59f4621 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_union_init3.c @@ -0,0 +1,8 @@ +/* C99 union initialization */ +struct { + int i[10]; + char *s; +} c[] = { + { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, + "foo" }, +}; diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_union_init4.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_union_init4.c new file mode 100644 index 000000000000..f73b1134f7db --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c99_union_init4.c @@ -0,0 +1,15 @@ +/* test .data.l[x] */ +typedef struct { + int type; + union { + char b[20]; + short s[10]; + long l[5]; + } data; +} foo; + + +foo bar = { + .type = 3, + .data.l[0] = 4 +}; diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c9x_array_init.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c9x_array_init.c new file mode 100644 index 000000000000..66f0e9ec158e --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c9x_array_init.c @@ -0,0 +1,6 @@ +/* C9X array initializers */ +int foo[256] = { + [2] = 1, + [3] = 2, + [4 ... 5] = 3 +}; diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c9x_recursive_init.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c9x_recursive_init.c new file mode 100644 index 000000000000..df907cd7a3cd --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_c9x_recursive_init.c @@ -0,0 +1,16 @@ +/* C9X struct/union member init, with nested union and trailing member */ +union node { + void *next; + char *data; +}; +struct foo { + int b; + union node n; + int c; +}; + +struct foo f = { + .b = 1, + .n = { .next = 0, }, + .c = 1 +}; diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_cast_fun_array_param.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_cast_fun_array_param.c new file mode 100644 index 000000000000..345c7835d3bf --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_cast_fun_array_param.c @@ -0,0 +1,9 @@ + +static void f(void *b[4]) { + (void)&b; +} + +void * +foo(void *fn) { + return fn == 0 ? f : (void (*)(void *[4])) fn; +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_cast_init.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_cast_init.c new file mode 100644 index 000000000000..36986e800ac4 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_cast_init.c @@ -0,0 +1,27 @@ +/* cast initialization */ +typedef unsigned char u_char; +typedef unsigned int size_t; +struct sockaddr_x25 { + u_char x25_len; + u_char x25_family; + short x25_net; + char x25_addr[16]; + struct x25opts { + char op_flags; + char op_psize; + char op_wsize; + char op_speed; + } x25_opts; + short x25_udlen; + char x25_udata[16]; +}; + +struct sockaddr_x25 x25_dgmask = { + (unsigned char)(unsigned char)(unsigned int)(unsigned long)(&((( struct sockaddr_x25 *)0)->x25_udata[1])) , + 0, + 0, + {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, + {0, 0, 0, 0}, + -1, + {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, +}; diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_cast_init2.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_cast_init2.c new file mode 100644 index 000000000000..9597d3580397 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_cast_init2.c @@ -0,0 +1,7 @@ +/* cast initialization as the rhs of a - operand */ +struct sockaddr_dl { + char sdl_data[2]; +}; + +int npdl_datasize = sizeof(struct sockaddr_dl) - +((int) ((unsigned long)&((struct sockaddr_dl *) 0)->sdl_data[0])); diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_cast_lhs.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_cast_lhs.c new file mode 100644 index 000000000000..eb865695535f --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_cast_lhs.c @@ -0,0 +1,7 @@ +/* pointer casts are valid lhs lvalues */ +struct sockaddr { }; +void +foo() { + unsigned long p = 6; + ((struct sockaddr *)p) = 0; +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_compound_literals1.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_compound_literals1.c new file mode 100644 index 000000000000..cd1987ae17de --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_compound_literals1.c @@ -0,0 +1,11 @@ +/* compound literals */ + +struct p { + short a, b, c, d; +}; + +foo() +{ + struct p me = (struct p) {1, 2, 3, 4}; + me.a = me.b; +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_compound_literals2.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_compound_literals2.c new file mode 100644 index 000000000000..e4ffb929873f --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_compound_literals2.c @@ -0,0 +1,18 @@ +/* compound literals */ + +struct p { + short a, b, c, d; +} zz = { + 1, 2, 3, 4 +}; + +struct p *bar(int i) +{ + static struct p q[10]; + return &q[i]; +} + +foo() +{ + *bar(1) = (struct p) { 1, 2, 3, 4 }; +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_constant_conv1.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_constant_conv1.c new file mode 100644 index 000000000000..53795c5fe858 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_constant_conv1.c @@ -0,0 +1,9 @@ +/* Flag information-losing constant conversion in argument lists */ + +int f(unsigned int); + +void +should_fail() +{ + f(-1); +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_constant_conv2.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_constant_conv2.c new file mode 100644 index 000000000000..87066c96b5a8 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_constant_conv2.c @@ -0,0 +1,9 @@ +/* Flag information-losing constant conversion in argument lists */ + +int f(unsigned int); + +void +should_fail() +{ + f(2.1); +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_cvt_constant.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_cvt_constant.c new file mode 100644 index 000000000000..aa74509fa42e --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_cvt_constant.c @@ -0,0 +1,8 @@ +/* the second assignment assumes failed before */ +int +main(void) { + double x = 1; + int foo = 0; + if (foo) + x = 1; +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_cvt_in_ternary.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_cvt_in_ternary.c new file mode 100644 index 000000000000..4a6149c67224 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_cvt_in_ternary.c @@ -0,0 +1,13 @@ +/* CVT node handling in ?: operator */ +typedef unsigned long int size_t; +struct filecore_direntry { + unsigned len:32; +}; +int +main(void) +{ + struct filecore_direntry dirent = { 0 }; + size_t uio_resid = 0; + size_t bytelen = (((dirent.len)<(uio_resid))?(dirent.len):(uio_resid)); + return bytelen; +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_ellipsis_in_switch.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_ellipsis_in_switch.c new file mode 100644 index 000000000000..ba4a338d29ae --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_ellipsis_in_switch.c @@ -0,0 +1,11 @@ +int x(void) +{ + int i = 33; + switch (i) { + case 1 ... 40: + break; + default: + break; + } + return 0; +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.c new file mode 100644 index 000000000000..d970be182648 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_gcc_compound_statements1.c @@ -0,0 +1,7 @@ +/* GCC compound statements */ + +foo(unsigned long z) +{ + z = ({ unsigned long tmp; tmp = 1; tmp; }); + foo(z); +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_gcc_compound_statements2.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_gcc_compound_statements2.c new file mode 100644 index 000000000000..fa1ee67302c5 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_gcc_compound_statements2.c @@ -0,0 +1,14 @@ +/* GCC compound statements with non-expressions */ +struct cpu_info { + int bar; +}; + +int +main(void) +{ + return ({ + struct cpu_info *__ci; + __asm__ volatile("movl %%fs:4,%0":"=r" (__ci)); + __ci; + })->bar; +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_gcc_compound_statements3.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_gcc_compound_statements3.c new file mode 100644 index 000000000000..29e9063dcf4a --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_gcc_compound_statements3.c @@ -0,0 +1,10 @@ +/* GCC compound statements with void type */ + +void +main(void) +{ + ({ + void *v; + __asm__ volatile("noop"); + }); +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_gcc_extension.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_gcc_extension.c new file mode 100644 index 000000000000..d8bd8f5fe944 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_gcc_extension.c @@ -0,0 +1,6 @@ +/* extension */ +void a(void) { + double __logbw = 1; + if (__extension__(({ __typeof((__logbw)) x_ = (__logbw); !__builtin_isinf((x_)) && !__builtin_isnan((x_)); }))) + __logbw = 1; +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_gcc_func.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_gcc_func.c new file mode 100644 index 000000000000..459919de2955 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_gcc_func.c @@ -0,0 +1,7 @@ +/* gcc __FUNCTION__ */ + +void +foo(const char *p) { + p = __FUNCTION__; + foo(p); +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_gcc_variable_array_init.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_gcc_variable_array_init.c new file mode 100644 index 000000000000..d5b01ad0c2d2 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_gcc_variable_array_init.c @@ -0,0 +1,7 @@ +/* gcc: variable array initializer */ +void foo(int i) +{ + int array[i]; + while (i--) + foo(array[i] = 0); +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_incorrect_array_size.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_incorrect_array_size.c new file mode 100644 index 000000000000..c86c0d6b3b70 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_incorrect_array_size.c @@ -0,0 +1,3 @@ +struct foo { + int a[-1]; +}; diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_long_double_int.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_long_double_int.c new file mode 100644 index 000000000000..a5a644e3e3d4 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_long_double_int.c @@ -0,0 +1,7 @@ +/* PR 39639: writing "long double" gave "long int" */ + +int +fail(long double *a, long int *b) +{ + return a == b; +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_nested_structs.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_nested_structs.c new file mode 100644 index 000000000000..edd3396bd224 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_nested_structs.c @@ -0,0 +1,21 @@ +/* Nested struct */ +typedef void *EditLine; +typedef void *History; + +typedef struct { + EditLine *el; + History *hist; +} el_mode_t; + +struct el_modes_s { + el_mode_t command; + el_mode_t string; + el_mode_t filec; + el_mode_t mime_enc; +}; + +struct el_modes_s elm = { + .command = { .el = 0, .hist = 0, }, + .string = { .el = 0, .hist = 0, }, + .filec = { .el = 0, .hist = 0, }, +}; diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_nolimit_init.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_nolimit_init.c new file mode 100644 index 000000000000..68e71b4df050 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_nolimit_init.c @@ -0,0 +1,4 @@ +/* no limit initializers */ +char foo[][4] = { + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" +}; diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_packed_structs.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_packed_structs.c new file mode 100644 index 000000000000..71b438496f92 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_packed_structs.c @@ -0,0 +1,35 @@ +/* packed tests */ + +struct in_addr { + int x; +}; +struct ip_timestamp { + char ipt_code; + char ipt_len; + char ipt_ptr; + unsigned int ipt_flg:4, + ipt_oflw:4; + union ipt_timestamp { + int ipt_time[1]; + struct ipt_ta { + struct in_addr ipt_addr; + int ipt_time; + } ipt_ta[1] __packed; + } ipt_timestamp __packed; +} __packed; + +typedef struct __packed { + int x; +} t; + +struct x { + char c; + long l; +} __packed; + +struct y { + char c; + long l; +}; + +int a[sizeof(struct y) - sizeof(struct x) - 1]; diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_shift_to_narrower_type.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_shift_to_narrower_type.c new file mode 100644 index 000000000000..0208944a2d12 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_shift_to_narrower_type.c @@ -0,0 +1,24 @@ +// Test that type shifts that result to narrower types don't produce warnings. + +void +foo(void) { + unsigned long l = 100; + unsigned long long ll = 100; + unsigned int i = 100; + unsigned short s = 100; + unsigned char c = 1; + + l = ll >> 32; +// i = ll >> 31; + i = ll >> 32; + s = ll >> 48; + c = ll >> 56; + s = i >> 16; + c = i >> 24; + c = s >> 8; + (void)≪ + (void)&l; + (void)&i; + (void)&s; + (void)&c; +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_type_conv1.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_type_conv1.c new file mode 100644 index 000000000000..d9e470e941b9 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_type_conv1.c @@ -0,0 +1,11 @@ +/* Flag information-losing type conversion in argument lists */ + +int f(unsigned int); + +void +should_fail() +{ + long long x = 20; + + f(x); +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_type_conv2.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_type_conv2.c new file mode 100644 index 000000000000..7c2e1f478ecd --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_type_conv2.c @@ -0,0 +1,11 @@ +/* Flag information-losing type conversion in argument lists */ + +int f(float); + +void +should_fail() +{ + double x = 2.0; + + f(x); +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_type_conv3.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_type_conv3.c new file mode 100644 index 000000000000..bc6a8e695ada --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_type_conv3.c @@ -0,0 +1,10 @@ +/* Flag information-losing type conversion in argument lists */ + +int f(unsigned int); + +void +should_fail() +{ + + f(0x7fffffffffffffffLL); +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_type_question_colon.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_type_question_colon.c new file mode 100644 index 000000000000..00f69cde6bcc --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_type_question_colon.c @@ -0,0 +1,14 @@ +/* the type of the ?: expression should be the more specific type */ + +struct foo { + int bar; +}; + +void +test(void) { + int i; + struct foo *ptr = 0; + + for (i = (ptr ? ptr : (void *)0)->bar; i < 10; i++) + test(); +} diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_typefun.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_typefun.c new file mode 100644 index 000000000000..ad69c514ece5 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_typefun.c @@ -0,0 +1,22 @@ +/* typedef of function parameter */ + +typedef void (*free_func) (void * opaque, void* address); +typedef struct stack_st +{ + int num; + char **data; + int sorted; + + int num_alloc; + int (*comp)(const void *, const void *); +} _STACK; /* Use STACK_OF(...) instead */ + +typedef void *OPENSSL_BLOCK; +struct stack_st_OPENSSL_BLOCK { _STACK stack; }; +typedef void *d2i_of_void(void **,const unsigned char **,long); typedef int i2d_of_void(void *,unsigned char **); + +struct stack_st_OPENSSL_BLOCK *d2i_ASN1_SET(struct stack_st_OPENSSL_BLOCK **a, + const unsigned char **pp, + long length, d2i_of_void *d2i, + void (*free_func)(OPENSSL_BLOCK), int ex_tag, + int ex_class); diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_typename_as_var.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_typename_as_var.c new file mode 100644 index 000000000000..248dc7558b52 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_typename_as_var.c @@ -0,0 +1,14 @@ +typedef char h[10]; + +typedef struct { + int i; + char *c; +} fh; + +struct foo { + fh h; + struct { + int x; + int y; + } fl; +}; diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/d_zero_sized_arrays.c b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_zero_sized_arrays.c new file mode 100644 index 000000000000..9c06c6b5e413 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/d_zero_sized_arrays.c @@ -0,0 +1,3 @@ +struct foo { +int a[0]; +}; diff --git a/contrib/netbsd-tests/usr.bin/xlint/lint1/t_integration.sh b/contrib/netbsd-tests/usr.bin/xlint/lint1/t_integration.sh new file mode 100755 index 000000000000..9575f9664d3b --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/xlint/lint1/t_integration.sh @@ -0,0 +1,132 @@ +# $NetBSD: t_integration.sh,v 1.4 2014/04/21 19:10:41 christos Exp $ +# +# Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +LINT1=/usr/libexec/lint1 + +Names= + +check_valid() +{ + atf_check -s exit:0 ${LINT1} -g -S "$(atf_get_srcdir)/$1" /dev/null +} + +check_invalid() +{ + atf_check -s not-exit:0 -o ignore -e ignore ${LINT1} -g -S -w \ + "$(atf_get_srcdir)/$1" /dev/null +} + +test_case() +{ + local result="${1}"; shift + local name="${1}"; shift + local descr="${*}" + + atf_test_case ${name} + eval "${name}_head() { + atf_set \"descr\" \"${descr}\"; + atf_set \"require.progs\" \"${LINT1}\"; + }" + eval "${name}_body() { + ${result} d_${name}.c; + }" + + Names="${Names} ${name}" +} + +test_case check_valid c99_struct_init "Checks C99 struct initialization" +test_case check_valid c99_union_init1 "Checks C99 union initialization" +test_case check_valid c99_union_init2 "Checks C99 union initialization" +test_case check_valid c99_union_init3 "Checks C99 union initialization" +test_case check_valid c99_recursive_init "Checks C99 recursive struct/union" \ + "initialization" +test_case check_valid c9x_recursive_init "Checks C9X struct/union member" \ + "init, with nested union and trailing member" +test_case check_valid nested_structs "Checks nested structs" +test_case check_valid packed_structs "Checks packed structs" + +test_case check_valid cast_init "Checks cast initialization" +test_case check_valid cast_init2 "Checks cast initialization as the rhs of a" \ + "- operand" +test_case check_valid cast_lhs "Checks whether pointer casts are valid lhs" \ + "lvalues" + +test_case check_valid gcc_func "Checks GCC __FUNCTION__" +test_case check_valid c99_func "Checks C99 __func__" + +test_case check_valid gcc_variable_array_init "Checks GCC variable array" \ + "initializers" +test_case check_valid c9x_array_init "Checks C9X array initializers" +test_case check_valid c99_decls_after_stmt "Checks C99 decls after statements" +test_case check_valid c99_decls_after_stmt3 "Checks C99 decls after statements" +test_case check_valid nolimit_init "Checks no limit initializers" +test_case check_valid zero_sized_arrays "Checks zero sized arrays" + +test_case check_valid compound_literals1 "Checks compound literals" +test_case check_valid compound_literals2 "Checks compound literals" +test_case check_valid gcc_compound_statements1 "Checks GCC compound statements" +test_case check_valid gcc_compound_statements2 "Checks GCC compound" \ + "statements with non-expressions" +test_case check_valid gcc_compound_statements3 "Checks GCC compound" \ + "statements with void type" +# XXX: Because of polymorphic __builtin_isnan and expression has null effect +# test_case check_valid gcc_extension "Checks GCC __extension__ and __typeof__" + +test_case check_valid cvt_in_ternary "Checks CVT nodes handling in ?" \ +test_case check_valid cvt_constant "Checks constant conversion" +test_case check_valid ellipsis_in_switch "Checks ellipsis in switch()" +test_case check_valid c99_complex_num "Checks C99 complex numbers" +test_case check_valid c99_complex_split "Checks C99 complex access" +test_case check_valid c99_for_loops "Checks C99 for loops" +test_case check_valid alignof "Checks __alignof__" +test_case check_valid shift_to_narrower_type "Checks that type shifts that" \ + "result in narrower types do not produce warnings" + +test_case check_invalid constant_conv1 "Checks failing on information-losing" \ + "constant conversion in argument lists" +test_case check_invalid constant_conv2 "Checks failing on information-losing" \ + "constant conversion in argument lists" + +test_case check_invalid type_conv1 "Checks failing on information-losing" \ + "type conversion in argument lists" +test_case check_invalid type_conv2 "Checks failing on information-losing" \ + "type conversion in argument lists" +test_case check_invalid type_conv3 "Checks failing on information-losing" \ + "type conversion in argument lists" + +test_case check_invalid incorrect_array_size "Checks failing on incorrect" \ + "array sizes" + +test_case check_invalid long_double_int "Checks for confusion of 'long" \ + "double' with 'long int'; PR 39639" + +atf_init_test_cases() +{ + for name in ${Names}; do + atf_add_test_case ${name} + done +} |