diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2016-11-24 18:09:46 +0100 |
|---|---|---|
| committer | Christopher Li <sparse@chrisli.org> | 2017-02-13 09:34:44 +0800 |
| commit | 548e90093d336d28f4bb00b3267417d145a6b601 (patch) | |
| tree | a05b9f2d6e226ba3d481ef56af086028c5d599e9 /validation | |
| parent | 8c5fa9ab6b0f92a0f1dc91859fba4075371b4eac (diff) | |
| download | sparse-dev-548e90093d336d28f4bb00b3267417d145a6b601.tar.gz | |
testsuite: test modifiers preserved by 'typeof()'
Note: address space, 'safe' & 'noderef' have their own test file
because they have others issues or need to be handled differently.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Signed-off-by: Christopher Li <sparse@chrisli.org>
Diffstat (limited to 'validation')
| -rw-r--r-- | validation/typeof-addresspace.c | 20 | ||||
| -rw-r--r-- | validation/typeof-mods.c | 109 | ||||
| -rw-r--r-- | validation/typeof-noderef.c | 19 | ||||
| -rw-r--r-- | validation/typeof-safe.c | 23 |
4 files changed, 171 insertions, 0 deletions
diff --git a/validation/typeof-addresspace.c b/validation/typeof-addresspace.c new file mode 100644 index 00000000..a94f77a3 --- /dev/null +++ b/validation/typeof-addresspace.c @@ -0,0 +1,20 @@ +#define __as __attribute__((address_space(1))) + +static void test_as(void) +{ + int __as obj, *ptr; + typeof(obj) var = obj; + typeof(ptr) ptr2 = ptr; + typeof(*ptr) var2 = obj; + typeof(*ptr) *ptr3 = ptr; /* check-should-pass */ + typeof(obj) *ptr4 = ptr; /* check-should-pass */ + obj = obj; + ptr = ptr; + ptr = &obj; + obj = *ptr; +} + +/* + * check-name: typeof-addresspace.c + * check-known-to-fail + */ diff --git a/validation/typeof-mods.c b/validation/typeof-mods.c new file mode 100644 index 00000000..8c98ab8c --- /dev/null +++ b/validation/typeof-mods.c @@ -0,0 +1,109 @@ +#define __noderef __attribute__((noderef)) +#define __bitwise __attribute__((bitwise)) +#define __nocast __attribute__((nocast)) +#define __safe __attribute__((safe)) + +static void test_spec(void) +{ + unsigned int obj, *ptr; + typeof(obj) var = obj; + typeof(ptr) ptr2 = ptr; + typeof(*ptr) var2 = obj; + typeof(*ptr) *ptr3 = ptr; + typeof(obj) *ptr4 = ptr; + obj = obj; + ptr = ptr; + ptr = &obj; + obj = *ptr; +} + +static void test_const(void) +{ + const int obj, *ptr; + typeof(obj) var = obj; + typeof(ptr) ptr2 = ptr; + typeof(*ptr) var2 = obj; + typeof(*ptr) *ptr3 = ptr; + typeof(obj) *ptr4 = ptr; + ptr = ptr; + ptr = &obj; +} + +static void test_volatile(void) +{ + volatile int obj, *ptr; + typeof(obj) var = obj; + typeof(ptr) ptr2 = ptr; + typeof(*ptr) var2 = obj; + typeof(*ptr) *ptr3 = ptr; + typeof(obj) *ptr4 = ptr; + obj = obj; + ptr = ptr; + ptr = &obj; + obj = *ptr; +} + +static void test_bitwise(void) +{ + typedef int __bitwise type_t; + type_t obj, *ptr; + typeof(obj) var = obj; + typeof(ptr) ptr2 = ptr; + typeof(*ptr) var2 = obj; + typeof(*ptr) *ptr3 = ptr; + typeof(obj) *ptr4 = ptr; + obj = obj; + ptr = ptr; + ptr = &obj; + obj = *ptr; +} + +static void test_static(void) +{ + static int obj, *ptr; + typeof(obj) var = obj; + typeof(ptr) ptr2 = ptr; + typeof(*ptr) var2 = obj; + typeof(*ptr) *ptr3 = ptr; + typeof(obj) *ptr4 = ptr; + obj = obj; + ptr = ptr; + ptr = &obj; + obj = *ptr; +} + +static void test_tls(void) +{ + __thread int obj, *ptr; + typeof(obj) var = obj; + typeof(ptr) ptr2 = ptr; + typeof(*ptr) var2 = obj; + typeof(*ptr) *ptr3 = ptr; + typeof(obj) *ptr4 = ptr; + obj = obj; + ptr = ptr; + ptr = &obj; + obj = *ptr; +} + +static void test_nocast(void) +{ + int __nocast obj, *ptr; + typeof(obj) var = obj; + typeof(ptr) ptr2 = ptr; + typeof(*ptr) var2 = obj; + typeof(*ptr) *ptr3 = ptr; + typeof(obj) *ptr4 = ptr; + obj = obj; + ptr = ptr; + ptr = &obj; + obj = *ptr; +} + +/* + * check-name: typeof-mods + * check-known-to-fail + * + * check-error-start + * check-error-end + */ diff --git a/validation/typeof-noderef.c b/validation/typeof-noderef.c new file mode 100644 index 00000000..e95a53ad --- /dev/null +++ b/validation/typeof-noderef.c @@ -0,0 +1,19 @@ +#define __noderef __attribute__((noderef)) + +static void test_noderef(void) +{ + int __noderef obj, *ptr; + typeof(ptr) ptr2 = ptr; + typeof(*ptr) *ptr3 = ptr; + typeof(obj) *ptr4 = ptr; + ptr = ptr; + ptr = &obj; +} + +/* + * check-name: typeof-noderef + * check-known-to-fail + * + * check-error-start + * check-error-end + */ diff --git a/validation/typeof-safe.c b/validation/typeof-safe.c new file mode 100644 index 00000000..614863fb --- /dev/null +++ b/validation/typeof-safe.c @@ -0,0 +1,23 @@ +#define __safe __attribute__((safe)) + +static void test_safe(void) +{ + int __safe obj, *ptr; + typeof(obj) var = obj; + typeof(ptr) ptr2 = ptr; + typeof(*ptr) var2 = obj; + typeof(*ptr) *ptr3 = ptr; + typeof(obj) *ptr4 = ptr; + obj = obj; + ptr = ptr; + ptr = &obj; + obj = *ptr; +} + +/* + * check-name: typeof-safe + * check-known-to-fail + * + * check-error-start + * check-error-end + */ |
