diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/c_files/c11.c | 69 | ||||
-rw-r--r-- | tests/test_c_generator.py | 22 | ||||
-rwxr-xr-x | tests/test_c_parser.py | 14 |
3 files changed, 74 insertions, 31 deletions
diff --git a/tests/c_files/c11.c b/tests/c_files/c11.c index 854feba..3c57f55 100644 --- a/tests/c_files/c11.c +++ b/tests/c_files/c11.c @@ -1,31 +1,38 @@ -#include <stdio.h>
-#include <stdlib.h>
-#include <stdnoreturn.h>
-#include <threads.h>
-#include <assert.h>
-
-/* C11 thread locals */
-_Thread_local int flag;
-thread_local int flag2;
-
-static_assert(sizeof(flag) == sizeof(flag2), "Really unexpected size difference");
-
-noreturn void func2(void)
-{
- abort();
-}
-
-_Noreturn void func(void)
-{
- func2();
-}
-
-int main()
-{
- _Static_assert(sizeof(flag) == sizeof(flag2), "Unexpected size difference");
- static_assert(sizeof(flag) == sizeof(flag2), "Unexpected size difference");
-
- printf("Flag: %d\n", flag);
- printf("Flag2: %d\n", flag2);
- func();
-}
+#include <stdio.h> +#include <stdlib.h> +#include <stdnoreturn.h> +#include <threads.h> +#include <assert.h> +#include <stdatomic.h> + +/* C11 thread locals */ +_Thread_local int flag; +thread_local int flag2; +_Atomic int flag3; +_Atomic(int) flag4; +_Atomic(_Atomic(int) *) flag5; +atomic_bool flag6; + +static_assert(sizeof(flag) == sizeof(flag2), "Really unexpected size difference"); + +noreturn void func2(void) +{ + abort(); +} + +_Noreturn void func(void) +{ + func2(); +} + +int main() +{ + _Static_assert(sizeof(flag) == sizeof(flag2), "Unexpected size difference"); + static_assert(sizeof(flag) == sizeof(flag2), "Unexpected size difference"); + static_assert(sizeof(flag) == sizeof(flag3), "Unexpected size difference"); + static_assert(sizeof(flag) == sizeof(flag4), "Unexpected size difference"); + + printf("Flag: %d\n", flag); + printf("Flag2: %d\n", flag2); + func(); +} diff --git a/tests/test_c_generator.py b/tests/test_c_generator.py index 0926b15..bcbdfcc 100644 --- a/tests/test_c_generator.py +++ b/tests/test_c_generator.py @@ -392,6 +392,28 @@ class TestCtoC(unittest.TestCase): self.assertEqual(c3, '_Atomic int * _Atomic x;\n') self._assert_ctoc_correct(s3) + # FIXME: Regeneration with multiple qualifiers is not fully supported. + # REF: https://github.com/eliben/pycparser/issues/433 + # self._assert_ctoc_correct('auto const _Atomic(int *) a;') + + s4 = 'typedef _Atomic(int) atomic_int;' + c4 = self._run_c_to_c(s4) + self.assertEqual(c4, 'typedef _Atomic int atomic_int;\n') + self._assert_ctoc_correct(s4) + + s5 = 'typedef _Atomic(_Atomic(_Atomic(int (*)(void)) *) *) t;' + c5 = self._run_c_to_c(s5) + self.assertEqual(c5, 'typedef int (* _Atomic * _Atomic * _Atomic t)(void);\n') + self._assert_ctoc_correct(s5) + + self._assert_ctoc_correct(r''' + typedef struct node_t { + _Atomic(void*) a; + _Atomic(void) *b; + _Atomic void *c; + } node; + ''') + def test_nested_sizeof(self): src = '1' for _ in range(30): diff --git a/tests/test_c_parser.py b/tests/test_c_parser.py index 40b53af..7e6a648 100755 --- a/tests/test_c_parser.py +++ b/tests/test_c_parser.py @@ -572,6 +572,20 @@ class TestCParser_fundamentals(TestCParser_base): 'bar', ['TypeDecl', ['IdentifierType', ['int']]]]) + # typedefs with _Atomic specifiers. + s = 'typedef _Atomic(int) atomic_int;' + self.assertEqual(self.get_decl(s, 0), + ['Typedef', 'atomic_int', ['TypeDecl', ['IdentifierType', ['int']]]]) + + s = 'typedef _Atomic(_Atomic(_Atomic(int (*)(void)) *) *) t;' + self.assertEqual(self.get_decl(s, 0), + ['Typedef', 't', + ['PtrDecl', ['_Atomic'], + ['PtrDecl', ['_Atomic'], + ['PtrDecl', ['_Atomic'], + ['FuncDecl', [['Typename', ['TypeDecl', ['IdentifierType', ['void']]]]], + ['TypeDecl', ['IdentifierType', ['int']]]]]]]]) + def test_sizeof(self): e = """ void foo() |