From 5224fe7e3e06ed43b5f3d86bedf1983e48c6a47a Mon Sep 17 00:00:00 2001 From: Virgile Prevosto <virgile.prevosto@m4x.org> Date: Wed, 19 Jun 2024 15:38:34 +0200 Subject: [PATCH] [tests] test that we don't accept Generics on a VLA type --- tests/syntax/generic.c | 6 ++++ tests/syntax/oracle/generic.1.res.oracle | 14 ++++---- tests/syntax/oracle/generic.10.res.oracle | 32 ++++++++++++++++++ tests/syntax/oracle/generic.2.res.oracle | 12 +++---- tests/syntax/oracle/generic.3.res.oracle | 12 +++---- tests/syntax/oracle/generic.4.res.oracle | 16 ++++----- tests/syntax/oracle/generic.5.res.oracle | 16 ++++----- tests/syntax/oracle/generic.6.res.oracle | 12 +++---- tests/syntax/oracle/generic.7.res.oracle | 12 +++---- tests/syntax/oracle/generic.8.res.oracle | 14 ++++---- tests/syntax/oracle/generic.9.res.oracle | 40 +++++------------------ 11 files changed, 101 insertions(+), 85 deletions(-) create mode 100644 tests/syntax/oracle/generic.10.res.oracle diff --git a/tests/syntax/generic.c b/tests/syntax/generic.c index 17726aab534..15a9d6aa05f 100644 --- a/tests/syntax/generic.c +++ b/tests/syntax/generic.c @@ -9,6 +9,7 @@ STDOPT: #"-cpp-extra-args=-DINCOMPLETE_TYPE" STDOPT: #"-cpp-extra-args=-DINCOMPATIBLE_QUALIFIED_TYPE" STDOPT: #"-cpp-extra-args=-DFUNCTION_TYPE" + STDOPT: #"-cpp-extra-args=-DVLA" EXIT: 0 STDOPT: */ @@ -63,6 +64,11 @@ int main() { #endif #ifdef INCOMPATIBLE_QUALIFIED_TYPE int a = _Generic("abc", char const *: 0); +#endif +#ifdef VLA + int x = 42; + int y[x]; + int a = _Generic(y, int[x]: 0, default: 1); #endif int ok1 = _Generic("abc", char*: 0); int ok2 = _Generic(1.0, float: 1, double: 0); diff --git a/tests/syntax/oracle/generic.1.res.oracle b/tests/syntax/oracle/generic.1.res.oracle index c8f6605be6d..525bed32e1e 100644 --- a/tests/syntax/oracle/generic.1.res.oracle +++ b/tests/syntax/oracle/generic.1.res.oracle @@ -1,11 +1,11 @@ [kernel] Parsing generic.c (with preprocessing) -[kernel] generic.c:36: +[kernel] generic.c:37: _Generic requires at least one generic association: - Location: line 36, between columns 10 and 25, before or at token: ; - 34 int main() { - 35 #ifdef NONE - 36 int a = _Generic("abc"); + Location: line 37, between columns 10 and 25, before or at token: ; + 35 int main() { + 36 #ifdef NONE + 37 int a = _Generic("abc"); ^^^^^^^^^^^^^^^ - 37 #endif - 38 #ifdef TOO_MANY_DEFAULTS + 38 #endif + 39 #ifdef TOO_MANY_DEFAULTS [kernel] Frama-C aborted: invalid user input. diff --git a/tests/syntax/oracle/generic.10.res.oracle b/tests/syntax/oracle/generic.10.res.oracle new file mode 100644 index 00000000000..70bdefa20fd --- /dev/null +++ b/tests/syntax/oracle/generic.10.res.oracle @@ -0,0 +1,32 @@ +[kernel] Parsing generic.c (with preprocessing) +/* Generated by Frama-C */ +int foo(int i) +{ + int __retres; + __retres = 0; + return __retres; +} + +void void_foo(int i) +{ + return; +} + +float cbrtf(float x); + +int main(void) +{ + int __retres; + float tmp; + int ok1 = 0; + int ok2 = 0; + int ok3 = 0; + int ok4 = 0; + tmp = cbrtf(0.0f); + double c = (double)tmp; + int ok5 = 0; + __retres = 0; + return __retres; +} + + diff --git a/tests/syntax/oracle/generic.2.res.oracle b/tests/syntax/oracle/generic.2.res.oracle index 0edc5626dfd..592f81d34ca 100644 --- a/tests/syntax/oracle/generic.2.res.oracle +++ b/tests/syntax/oracle/generic.2.res.oracle @@ -1,10 +1,10 @@ [kernel] Parsing generic.c (with preprocessing) -[kernel] generic.c:39: User Error: +[kernel] generic.c:40: User Error: multiple default clauses in _Generic selection - 37 #endif - 38 #ifdef TOO_MANY_DEFAULTS - 39 int a = _Generic("abc", default: 1, default: 1); + 38 #endif + 39 #ifdef TOO_MANY_DEFAULTS + 40 int a = _Generic("abc", default: 1, default: 1); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 40 #endif - 41 #ifdef TOO_MANY_COMPATIBLE + 41 #endif + 42 #ifdef TOO_MANY_COMPATIBLE [kernel] Frama-C aborted: invalid user input. diff --git a/tests/syntax/oracle/generic.3.res.oracle b/tests/syntax/oracle/generic.3.res.oracle index af00e69e6f9..89f860800fa 100644 --- a/tests/syntax/oracle/generic.3.res.oracle +++ b/tests/syntax/oracle/generic.3.res.oracle @@ -1,11 +1,11 @@ [kernel] Parsing generic.c (with preprocessing) -[kernel] generic.c:43: User Error: +[kernel] generic.c:44: User Error: multiple compatible types in _Generic selection: 'my_uint' and 'unsigned int' - 41 #ifdef TOO_MANY_COMPATIBLE - 42 // compatibility via typedef - 43 int a = _Generic(42, my_uint: 1, unsigned int: 2); + 42 #ifdef TOO_MANY_COMPATIBLE + 43 // compatibility via typedef + 44 int a = _Generic(42, my_uint: 1, unsigned int: 2); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 44 #endif - 45 #ifdef TOO_MANY_COMPATIBLE2 + 45 #endif + 46 #ifdef TOO_MANY_COMPATIBLE2 [kernel] Frama-C aborted: invalid user input. diff --git a/tests/syntax/oracle/generic.4.res.oracle b/tests/syntax/oracle/generic.4.res.oracle index 4dea267e9f5..3b8bc64668e 100644 --- a/tests/syntax/oracle/generic.4.res.oracle +++ b/tests/syntax/oracle/generic.4.res.oracle @@ -1,14 +1,14 @@ [kernel] Parsing generic.c (with preprocessing) -[kernel] generic.c:47: User Error: +[kernel] generic.c:48: User Error: multiple compatible types in _Generic selection: 'void (*)()' and 'void (*)(void)' - 45 #ifdef TOO_MANY_COMPATIBLE2 - 46 // compatibility modulo implicit arguments + 46 #ifdef TOO_MANY_COMPATIBLE2 + 47 // compatibility modulo implicit arguments - 47 int a = _Generic(0, - 48 void (*)(): 0, - 49 void (*)(void): 0); + 48 int a = _Generic(0, + 49 void (*)(): 0, + 50 void (*)(void): 0); - 50 #endif - 51 #ifdef TOO_MANY_COMPATIBLE3 + 51 #endif + 52 #ifdef TOO_MANY_COMPATIBLE3 [kernel] Frama-C aborted: invalid user input. diff --git a/tests/syntax/oracle/generic.5.res.oracle b/tests/syntax/oracle/generic.5.res.oracle index 579b9dde795..5c1e7279049 100644 --- a/tests/syntax/oracle/generic.5.res.oracle +++ b/tests/syntax/oracle/generic.5.res.oracle @@ -1,15 +1,15 @@ [kernel] Parsing generic.c (with preprocessing) -[kernel] generic.c:54: User Error: +[kernel] generic.c:55: User Error: controlling expression compatible with more than one association type in _Generic selection: controlling expression: '(void (*)())0' (type: void (*)()); compatible types: void (*)(void), void (*)(int ) - 52 // implicit arguments compatible between first and second selector, - 53 // but the selectors themselves are not compatible between them + 53 // implicit arguments compatible between first and second selector, + 54 // but the selectors themselves are not compatible between them - 54 int a = _Generic((void (*)()) 0, - 55 void (*)(int): 0, - 56 void (*)(void): 0); + 55 int a = _Generic((void (*)()) 0, + 56 void (*)(int): 0, + 57 void (*)(void): 0); - 57 #endif - 58 #ifdef INCOMPLETE_TYPE + 58 #endif + 59 #ifdef INCOMPLETE_TYPE [kernel] Frama-C aborted: invalid user input. diff --git a/tests/syntax/oracle/generic.6.res.oracle b/tests/syntax/oracle/generic.6.res.oracle index fbfffc1be28..c53dd9c2738 100644 --- a/tests/syntax/oracle/generic.6.res.oracle +++ b/tests/syntax/oracle/generic.6.res.oracle @@ -1,10 +1,10 @@ [kernel] Parsing generic.c (with preprocessing) -[kernel] generic.c:59: User Error: +[kernel] generic.c:60: User Error: generic association with incomplete type 'void' - 57 #endif - 58 #ifdef INCOMPLETE_TYPE - 59 int a = _Generic(42, void: 1, default: 2); + 58 #endif + 59 #ifdef INCOMPLETE_TYPE + 60 int a = _Generic(42, void: 1, default: 2); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 60 #endif - 61 #ifdef FUNCTION_TYPE + 61 #endif + 62 #ifdef FUNCTION_TYPE [kernel] Frama-C aborted: invalid user input. diff --git a/tests/syntax/oracle/generic.7.res.oracle b/tests/syntax/oracle/generic.7.res.oracle index c232c3c417e..03f063c8583 100644 --- a/tests/syntax/oracle/generic.7.res.oracle +++ b/tests/syntax/oracle/generic.7.res.oracle @@ -1,12 +1,12 @@ [kernel] Parsing generic.c (with preprocessing) -[kernel] generic.c:65: User Error: +[kernel] generic.c:66: User Error: no compatible types and no default type in _Generic selection: controlling expression: '"abc"' (type: char *); candidate types: char const * - 63 #endif - 64 #ifdef INCOMPATIBLE_QUALIFIED_TYPE - 65 int a = _Generic("abc", char const *: 0); + 64 #endif + 65 #ifdef INCOMPATIBLE_QUALIFIED_TYPE + 66 int a = _Generic("abc", char const *: 0); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - 66 #endif - 67 int ok1 = _Generic("abc", char*: 0); + 67 #endif + 68 #ifdef VLA [kernel] Frama-C aborted: invalid user input. diff --git a/tests/syntax/oracle/generic.8.res.oracle b/tests/syntax/oracle/generic.8.res.oracle index fe357172812..78569285df2 100644 --- a/tests/syntax/oracle/generic.8.res.oracle +++ b/tests/syntax/oracle/generic.8.res.oracle @@ -1,11 +1,11 @@ [kernel] Parsing generic.c (with preprocessing) -[kernel] generic.c:62: +[kernel] generic.c:63: syntax error: - Location: line 62, column 27, before or at token: int - 60 #endif - 61 #ifdef FUNCTION_TYPE - 62 int a = _Generic(1, void(int): 1); + Location: line 63, column 27, before or at token: int + 61 #endif + 62 #ifdef FUNCTION_TYPE + 63 int a = _Generic(1, void(int): 1); ^ - 63 #endif - 64 #ifdef INCOMPATIBLE_QUALIFIED_TYPE + 64 #endif + 65 #ifdef INCOMPATIBLE_QUALIFIED_TYPE [kernel] Frama-C aborted: invalid user input. diff --git a/tests/syntax/oracle/generic.9.res.oracle b/tests/syntax/oracle/generic.9.res.oracle index 70bdefa20fd..ef373d91c17 100644 --- a/tests/syntax/oracle/generic.9.res.oracle +++ b/tests/syntax/oracle/generic.9.res.oracle @@ -1,32 +1,10 @@ [kernel] Parsing generic.c (with preprocessing) -/* Generated by Frama-C */ -int foo(int i) -{ - int __retres; - __retres = 0; - return __retres; -} - -void void_foo(int i) -{ - return; -} - -float cbrtf(float x); - -int main(void) -{ - int __retres; - float tmp; - int ok1 = 0; - int ok2 = 0; - int ok3 = 0; - int ok4 = 0; - tmp = cbrtf(0.0f); - double c = (double)tmp; - int ok5 = 0; - __retres = 0; - return __retres; -} - - +[kernel] generic.c:71: User Error: + generic association with variably modified type 'int [x]' + 69 int x = 42; + 70 int y[x]; + 71 int a = _Generic(y, int[x]: 0, default: 1); + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + 72 #endif + 73 int ok1 = _Generic("abc", char*: 0); +[kernel] Frama-C aborted: invalid user input. -- GitLab