From 36cafe1fb01864e13e9e4eca383482fcde461a39 Mon Sep 17 00:00:00 2001 From: guenther Date: Sun, 25 Jul 2010 23:00:05 +0000 Subject: [PATCH] basic regress tests (based on test-19.c) for _Bool and _Complex support --- regress/usr.bin/xlint/Makefile | 4 +- regress/usr.bin/xlint/test-24.c | 124 +++++++++++++ regress/usr.bin/xlint/test-24.c.exp | 22 +++ regress/usr.bin/xlint/test-25.c | 266 ++++++++++++++++++++++++++++ regress/usr.bin/xlint/test-25.c.exp | 38 ++++ 5 files changed, 452 insertions(+), 2 deletions(-) create mode 100644 regress/usr.bin/xlint/test-24.c create mode 100644 regress/usr.bin/xlint/test-24.c.exp create mode 100644 regress/usr.bin/xlint/test-25.c create mode 100644 regress/usr.bin/xlint/test-25.c.exp diff --git a/regress/usr.bin/xlint/Makefile b/regress/usr.bin/xlint/Makefile index 386228b8f48..9a7767091a6 100644 --- a/regress/usr.bin/xlint/Makefile +++ b/regress/usr.bin/xlint/Makefile @@ -1,7 +1,7 @@ -# $OpenBSD: Makefile,v 1.27 2006/05/28 23:55:42 cloder Exp $ +# $OpenBSD: Makefile,v 1.28 2010/07/25 23:00:05 guenther Exp $ TEST_MODULES= 1 2 3 4 5 6 7 8 9 10 12 13 14 15 16 17 18 19 20 21 22 \ - 23 + 23 24 25 LINT= lint .for i in ${TEST_MODULES} diff --git a/regress/usr.bin/xlint/test-24.c b/regress/usr.bin/xlint/test-24.c new file mode 100644 index 00000000000..037de233432 --- /dev/null +++ b/regress/usr.bin/xlint/test-24.c @@ -0,0 +1,124 @@ +/* $OpenBSD: test-24.c,v 1.1 2010/07/25 23:00:05 guenther Exp $ */ + +/* + * Placed in the public domain by Philip Guenther . + * + * Test _Bool handling. + * Based in part on test-19.c, by Chad Loder . + */ + +void +f(void) +{ + _Bool b1; + const _Bool b2 = 1; + _Bool const b3 = 0; + float fl = 4.3f; + + _Bool *bp = &b1; + + *bp = 3; + if (b1 > 1 || + b2 < 0 || + *bp > 1 || + *bp < 0) + { + *bp = 0; + } + + b1 = fl; +} + +void b1 (_Bool b){ b++; } +void c1 (signed char c){ c++; } +void uc1 (unsigned char uc) { uc++; } +void s1 (short s) { s++; } +void us1 (unsigned short us) { us++; } +void i1 (int i) { i++; } +void ui1 (unsigned int ui) { ui++; } +void f1 (float f) { f++; } +void l1 (long l) { l++; } +void ul1 (unsigned long ul) { ul++; } +void d1 (double d) { d++; } +void ll1 (long long ll) { ll++; } +void ull1 (unsigned long long ull) { ull++; } +void ld1 (long double ld) { ld++; } + +/* ARGSUSED */ +int +main(int argc, char* argv[]) +{ + _Bool B = 1; + signed char C = 1; + unsigned char UC = 1; + short S = 1; + unsigned short US = 1; + int I = 1; + unsigned int UI = 1; + long L = 1; + unsigned long UL = 1; + long long LL = 1; + unsigned long long ULL = 1; + float F = 1.0f; + double D = 1.0; + long double LD = 1.0L; + + f(); + + /* test with variables */ + b1(B); + b1(C); + b1(UC); + b1(S); + b1(US); + b1(I); + b1(UI); + b1(L); + b1(UL); + b1(LL); + b1(ULL); + b1(F); + b1(D); + b1(LD); + + c1(B); + uc1(B); + s1(B); + us1(B); + i1(B); + ui1(B); + f1(B); + l1(B); + ul1(B); + d1(B); + ll1(B); + ull1(B); + ld1(B); + + /* now test with int constants */ + b1(-1); + b1(0); + b1(1); + + /* now test with long constants */ + b1(-1L); + b1(0L); + b1(1L); + + /* now test with float constants */ + b1(-1.0f); + b1(0.0f); + b1(1.0f); + + /* now test with double constants */ + b1(-1.0); + b1(0.0); + b1(1.0); + + /* now test with long double constants */ + b1(-1.0L); + b1(0.0L); + b1(1.0L); + + return 0; +} diff --git a/regress/usr.bin/xlint/test-24.c.exp b/regress/usr.bin/xlint/test-24.c.exp new file mode 100644 index 00000000000..5877999487d --- /dev/null +++ b/regress/usr.bin/xlint/test-24.c.exp @@ -0,0 +1,22 @@ +test-24.c:22: warning: comparison of _Bool with 0, op < +test-24.c:24: warning: comparison of _Bool with 0, op < +test-24.c:29: warning: converted from 'float' to '_Bool' +test-24.c:15: warning: b3 set but not used in function f +test-24.c:70: warning: b1() arg #1: converted from 'signed char' to '_Bool' +test-24.c:71: warning: b1() arg #1: converted from 'unsigned char' to '_Bool' +test-24.c:72: warning: b1() arg #1: converted from 'short' to '_Bool' +test-24.c:73: warning: b1() arg #1: converted from 'unsigned short' to '_Bool' +test-24.c:75: warning: b1() arg #1: converted from 'unsigned int' to '_Bool' +test-24.c:76: warning: b1() arg #1: converted from 'long' to '_Bool' +test-24.c:77: warning: b1() arg #1: converted from 'unsigned long' to '_Bool' +test-24.c:78: warning: b1() arg #1: converted from 'long long' to '_Bool' +test-24.c:79: warning: b1() arg #1: converted from 'unsigned long long' to '_Bool' +test-24.c:80: warning: b1() arg #1: converted from 'float' to '_Bool' +test-24.c:81: warning: b1() arg #1: converted from 'double' to '_Bool' +test-24.c:82: warning: b1() arg #1: converted from 'long double' to '_Bool' +test-24.c:99: warning: b1() arg #1: conversion of negative constant to unsigned type +test-24.c:104: warning: b1() arg #1: conversion of negative constant to unsigned type +test-24.c:109: warning: b1() arg #1: conversion of 'float' to '_Bool' is out of range +test-24.c:114: warning: b1() arg #1: conversion of 'double' to '_Bool' is out of range +test-24.c:119: warning: b1() arg #1: conversion of 'long double' to '_Bool' is out of range +Lint pass2: diff --git a/regress/usr.bin/xlint/test-25.c b/regress/usr.bin/xlint/test-25.c new file mode 100644 index 00000000000..9a68fee9f6e --- /dev/null +++ b/regress/usr.bin/xlint/test-25.c @@ -0,0 +1,266 @@ +/* $OpenBSD: test-25.c,v 1.1 2010/07/25 23:00:05 guenther Exp $ */ + +/* + * Placed in the public domain by Philip Guenther . + * + * Test _Complex handling, based on test-19.c + */ + +#include +#include + +int +f(void) +{ + float f1; + double d1; + long double l1; + + float _Complex fc1; + _Complex float fc2; + + double _Complex dc1; + _Complex double dc2; + + long double _Complex lc1; + double long _Complex lc2; + double _Complex long lc3; + long _Complex double lc4; + _Complex long double lc5; + _Complex double long lc6; + + /* test type compatibility by mixing pointers */ + if (&fc1 == &fc2) + return 0; + if (&dc1 == &dc2) + return 0; + if (&fc1 == &dc1 || &dc1 == &lc1 || &lc1 == &fc1) + return 1; + if (&__real__ fc1 == &f1 || &__imag__ fc1 == &f1 || + &__real__ dc1 == &d1 || &__imag__ dc1 == &d1 || + &__real__ lc1 == &l1 || &__imag__ lc1 == &l1) + return 1; + return (&lc1 != &lc2 && &lc1 != &lc3 && &lc1 != &lc4 && + &lc1 != &lc5 && &lc1 != &lc6); +} + +void b1 (_Bool b){ b++; } +void c1 (signed char c){ c++; } +void uc1 (unsigned char uc) { uc++; } +void s1 (short s) { s++; } +void us1 (unsigned short us) { us++; } +void i1 (int i) { i++; } +void ui1 (unsigned int ui) { ui++; } +void f1 (float f) { f++; } +void l1 (long l) { l++; } +void ul1 (unsigned long ul) { ul++; } +void d1 (double d) { d++; } +void ll1 (long long ll) { ll++; } +void ull1 (unsigned long long ull) { ull++; } +void ld1 (long double ld) { ld++; } +void fc1 (float _Complex f) { f++; } +void dc1 (double _Complex d) { d++; } +void ldc1 (long double _Complex ld) { ld++; } + +/* ARGSUSED */ +int +main(int argc, char* argv[]) +{ + _Bool B = 1; + signed char C = 1; + unsigned char UC = 1; + short S = 1; + unsigned short US = 1; + int II = 1; + unsigned int UI = 1; + long L = 1; + unsigned long UL = 1; + long long LL = 1; + unsigned long long ULL = 1; + float F = 1.0f; + double D = 1.0; + long double LD = 1.0L; + float _Complex FC = 1.0f + I; + double _Complex DC = 1.0 + I; + long double _Complex LDC = 1.0L + I; + + f(); + + /* test with variables */ + b1(FC); + b1(DC); + b1(LDC); + + c1(FC); + c1(DC); + c1(LDC); + + uc1(FC); + uc1(DC); + uc1(LDC); + + s1(FC); + s1(DC); + s1(LDC); + + us1(FC); + us1(DC); + us1(LDC); + + i1(FC); + i1(DC); + i1(LDC); + + ui1(FC); + ui1(DC); + ui1(LDC); + + f1(FC); + f1(DC); + f1(LDC); + + l1(FC); + l1(DC); + l1(LDC); + + ul1(FC); + ul1(DC); + ul1(LDC); + + d1(FC); + d1(DC); + d1(LDC); + + ll1(FC); + ll1(DC); + ll1(LDC); + + ull1(FC); + ull1(DC); + ull1(LDC); + + ld1(FC); + ld1(DC); + ld1(LDC); + + fc1(B); + fc1(C); + fc1(UC); + fc1(S); + fc1(US); + fc1(II); + fc1(UI); + fc1(L); + fc1(UL); + fc1(LL); + fc1(ULL); + fc1(F); + fc1(D); + fc1(LD); + fc1(FC); + fc1(DC); + fc1(LDC); + + dc1(B); + dc1(C); + dc1(UC); + dc1(S); + dc1(US); + dc1(II); + dc1(UI); + dc1(L); + dc1(UL); + dc1(LL); + dc1(ULL); + dc1(F); + dc1(D); + dc1(LD); + dc1(FC); + dc1(DC); + dc1(LDC); + + ldc1(B); + ldc1(C); + ldc1(UC); + ldc1(S); + ldc1(US); + ldc1(II); + ldc1(UI); + ldc1(L); + ldc1(UL); + ldc1(LL); + ldc1(ULL); + ldc1(F); + ldc1(D); + ldc1(LD); + ldc1(FC); + ldc1(DC); + ldc1(LDC); + + /* now test with int constants */ + fc1(-1); + fc1(0); + fc1(1); + + dc1(-1); + dc1(0); + dc1(1); + + ldc1(-1); + ldc1(0); + ldc1(1); + + /* now test with long constants */ + fc1(-1L); + fc1(0L); + fc1(1L); + + dc1(-1L); + dc1(0L); + dc1(1L); + + ldc1(-1L); + ldc1(0L); + ldc1(1L); + + /* now test with float constants */ + fc1(-1.0f); + fc1(0.0f); + fc1(1.0f); + + dc1(-1.0f); + dc1(0.0f); + dc1(1.0f); + + ldc1(-1.0f); + ldc1(0.0f); + ldc1(1.0f); + + /* now test with double constants */ + fc1(-1.0); + fc1(0.0); + fc1(1.0); + + dc1(-1.0); + dc1(0.0); + dc1(1.0); + + ldc1(-1.0); + ldc1(0.0); + ldc1(1.0); + + /* now test with long double constants */ + fc1(-1.0L); + fc1(0.0L); + fc1(1.0L); + + dc1(-1.0L); + dc1(0.0L); + dc1(1.0L); + + ldc1(-1.0L); + ldc1(0.0L); + ldc1(1.0L); + + return 0; +} diff --git a/regress/usr.bin/xlint/test-25.c.exp b/regress/usr.bin/xlint/test-25.c.exp new file mode 100644 index 00000000000..fb9d33c2857 --- /dev/null +++ b/regress/usr.bin/xlint/test-25.c.exp @@ -0,0 +1,38 @@ +test-25.c:37: warning: illegal pointer combination, op == +test-25.c:37: warning: illegal pointer combination, op == +test-25.c:37: warning: illegal pointer combination, op == +test-25.c:90: warning: b1() arg #1: converted from 'float _Complex' to '_Bool' +test-25.c:91: warning: b1() arg #1: converted from 'double _Complex' to '_Bool' +test-25.c:92: warning: b1() arg #1: converted from 'long double _Complex' to '_Bool' +test-25.c:94: warning: c1() arg #1: converted from 'float _Complex' to 'signed char' +test-25.c:95: warning: c1() arg #1: converted from 'double _Complex' to 'signed char' +test-25.c:96: warning: c1() arg #1: converted from 'long double _Complex' to 'signed char' +test-25.c:98: warning: uc1() arg #1: converted from 'float _Complex' to 'unsigned char' +test-25.c:99: warning: uc1() arg #1: converted from 'double _Complex' to 'unsigned char' +test-25.c:100: warning: uc1() arg #1: converted from 'long double _Complex' to 'unsigned char' +test-25.c:102: warning: s1() arg #1: converted from 'float _Complex' to 'short' +test-25.c:103: warning: s1() arg #1: converted from 'double _Complex' to 'short' +test-25.c:104: warning: s1() arg #1: converted from 'long double _Complex' to 'short' +test-25.c:106: warning: us1() arg #1: converted from 'float _Complex' to 'unsigned short' +test-25.c:107: warning: us1() arg #1: converted from 'double _Complex' to 'unsigned short' +test-25.c:108: warning: us1() arg #1: converted from 'long double _Complex' to 'unsigned short' +test-25.c:110: warning: i1() arg #1: converted from 'float _Complex' to 'int' +test-25.c:111: warning: i1() arg #1: converted from 'double _Complex' to 'int' +test-25.c:112: warning: i1() arg #1: converted from 'long double _Complex' to 'int' +test-25.c:114: warning: ui1() arg #1: converted from 'float _Complex' to 'unsigned int' +test-25.c:115: warning: ui1() arg #1: converted from 'double _Complex' to 'unsigned int' +test-25.c:116: warning: ui1() arg #1: converted from 'long double _Complex' to 'unsigned int' +test-25.c:122: warning: l1() arg #1: converted from 'float _Complex' to 'long' +test-25.c:123: warning: l1() arg #1: converted from 'double _Complex' to 'long' +test-25.c:124: warning: l1() arg #1: converted from 'long double _Complex' to 'long' +test-25.c:126: warning: ul1() arg #1: converted from 'float _Complex' to 'unsigned long' +test-25.c:127: warning: ul1() arg #1: converted from 'double _Complex' to 'unsigned long' +test-25.c:128: warning: ul1() arg #1: converted from 'long double _Complex' to 'unsigned long' +test-25.c:134: warning: ll1() arg #1: converted from 'float _Complex' to 'long long' +test-25.c:135: warning: ll1() arg #1: converted from 'double _Complex' to 'long long' +test-25.c:136: warning: ll1() arg #1: converted from 'long double _Complex' to 'long long' +test-25.c:138: warning: ull1() arg #1: converted from 'float _Complex' to 'unsigned long long' +test-25.c:139: warning: ull1() arg #1: converted from 'double _Complex' to 'unsigned long long' +test-25.c:140: warning: ull1() arg #1: converted from 'long double _Complex' to 'unsigned long long' +Lint pass2: +f returns value which is always ignored -- 2.20.1