From 548f3f906148c821cd30d61921b6aa2e2c866f1c Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Wed, 6 Jul 2022 14:33:37 -0400 Subject: [PATCH] Update the status & add tests for some more C99 DRs --- clang/test/C/drs/dr253.c | 27 ++++++++++ clang/test/C/drs/dr2xx.c | 108 +++++++++++++++++++++++++++++++++++++ clang/www/c_dr_status.html | 28 +++++----- 3 files changed, 149 insertions(+), 14 deletions(-) create mode 100644 clang/test/C/drs/dr253.c diff --git a/clang/test/C/drs/dr253.c b/clang/test/C/drs/dr253.c new file mode 100644 index 000000000000..3eae0a01586a --- /dev/null +++ b/clang/test/C/drs/dr253.c @@ -0,0 +1,27 @@ +/* RUN: %clang_cc1 -std=c89 -ast-dump -o - %s | FileCheck %s + RUN: %clang_cc1 -std=c99 -ast-dump -o - %s | FileCheck %s + RUN: %clang_cc1 -std=c11 -ast-dump -o - %s | FileCheck %s + RUN: %clang_cc1 -std=c17 -ast-dump -o - %s | FileCheck %s + RUN: %clang_cc1 -std=c2x -ast-dump -o - %s | FileCheck %s + */ + +/* WG14 DR253: yes + * "overriding" in designated initializers + */ +struct fred { + char s [6]; + int n; +}; + +struct fred y [] = { { { "abc" }, 1 }, [0] = { .s[0] = 'q' } }; + +/* Ensure that y[0] is initialized as if by the initializer { 'q' }. */ + +// CHECK: VarDecl 0x{{.*}} col:13 y 'struct fred[1]' cinit +// CHECK-NEXT: InitListExpr 0x{{.*}} 'struct fred[1]' +// CHECK-NEXT: InitListExpr 0x{{.*}} 'struct fred':'struct fred' +// CHECK-NEXT: InitListExpr 0x{{.*}} 'char[6]' +// CHECK-NEXT: array_filler +// CHECK-NEXT: ImplicitCastExpr +// CHECK-NEXT: CharacterLiteral 0x{{.*}} 'int' 113 +// CHECK-NEXT: ImplicitValueInitExpr 0x{{.*}} <> 'int' diff --git a/clang/test/C/drs/dr2xx.c b/clang/test/C/drs/dr2xx.c index b34b7ef2cce7..0d5a564ba101 100644 --- a/clang/test/C/drs/dr2xx.c +++ b/clang/test/C/drs/dr2xx.c @@ -32,6 +32,18 @@ * * WG14 DR234: yes * Miscellaneous Typos + * + * WG14 DR245: yes + * Missing paragraph numbers + * + * WG14 DR247: yes + * Are values a form of behaviour? + * + * WG14 DR248: yes + * Limits are required for optional types + * + * WG14 DR255: yes + * Non-prototyped function calls and argument mismatches */ @@ -144,3 +156,99 @@ void dr230(void) { /* expected-error@-1 {{invalid preprocessing directive}} \ expected-warning@-1 {{missing terminating ' character}} */ + +/* WG14 DR237: no + * Declarations using [static] + */ +void dr237_f(int array[static 10]); /* c89only-warning {{static array size is a C99 feature}} + expected-note {{callee declares array parameter as static here}} + */ +void dr237_1(void) { + int array[4]; + dr237_f(array); /* expected-warning {{array argument is too small; contains 4 elements, callee requires at least 10}} */ +} + +/* FIXME: the composite type for this declaration should retain the static + * array extent instead of losing it. + */ +void dr237_f(int array[]); + +void dr237_2(void) { + int array[4]; + /* FIXME: this should diagnose the same as above. */ + dr237_f(array); +} + +/* WG14 DR246: yes + * Completion of declarators + */ +void dr246(void) { + int i[i]; /* expected-error {{use of undeclared identifier 'i'}} */ +} + +/* WG14 DR250: yes + * Non-directives within macro arguments + */ +void dr250(void) { +#define dr250_nothing(x) + + /* FIXME: See DR231 regarding the error about an invalid preprocessing + * directive. + */ + + dr250_nothing( +#nondirective /* expected-error {{invalid preprocessing directive}} + expected-warning {{embedding a directive within macro arguments has undefined behavior}} + */ + ) + +#undef dr250_nothing +} + +/* WG14 DR251: yes + * Are struct fred and union fred the same type? + */ +union dr251_fred { int a; }; /* expected-note {{previous use is here}} */ +void dr251(void) { + struct dr251_fred *ptr; /* expected-error {{use of 'dr251_fred' with tag type that does not match previous declaration}} */ +} + +#if __STDC_VERSION__ < 202000L +/* WG14 DR252: yes + * Incomplete argument types when calling non-prototyped functions + */ +void dr252_no_proto(); /* expected-warning {{a function declaration without a prototype is deprecated in all versions of C}} */ +void dr252_proto(void); /* expected-note {{'dr252_proto' declared here}} */ +void dr252(void) { + /* It's a constraint violation to pass an argument to a function with a + * prototype that specifies a void parameter. + */ + dr252_proto(dr252_no_proto()); /* expected-error {{too many arguments to function call, expected 0, have 1}} */ + + /* It's technically UB to pass an incomplete type to a function without a + * prototype, but Clang treats it as an error. + */ + dr252_no_proto(dr252_proto()); /* expected-error {{argument type 'void' is incomplete}} + expected-warning {{passing arguments to 'dr252_no_proto' without a prototype is deprecated in all versions of C and is not supported in C2x}} + */ +} +#endif /* __STDC_VERSION__ < 202000L */ + +/* WG14 DR258: yes + * Ordering of "defined" and macro replacement + */ +void dr258(void) { + /* We get the diagnostic twice because the argument is used twice in the + * expansion. */ +#define repeat(x) x && x +#if repeat(defined fred) /* expected-warning 2 {{macro expansion producing 'defined' has undefined behavior}} */ +#endif + + /* We get no diagnostic because the argument is unused. */ +#define forget(x) 0 +#if forget(defined fred) +#endif + +#undef repeat +#undef forget +} diff --git a/clang/www/c_dr_status.html b/clang/www/c_dr_status.html index 239e8e8140ba..132eadd6d6f6 100644 --- a/clang/www/c_dr_status.html +++ b/clang/www/c_dr_status.html @@ -1356,7 +1356,7 @@ conformance.

237 NAD Declarations using [static] - Unknown + No 238 @@ -1385,7 +1385,7 @@ conformance.

242 C99 - + Make the base standard and Annex F consistent for logb(0) N/A @@ -1410,49 +1410,49 @@ conformance.

246 NAD Completion of declarators - Unknown + Yes 247 C99 Are values a form of behaviour? - Unknown + Yes 248 C99 - limits are required for optional types - Unknown + Limits are required for optional types + Yes 249 - C99 + Dup Lacuna applying C89:TC1 to C99 - Unknown + Duplicate of 9 250 C99 Non-directives within macro arguments - Unknown + Yes 251 C99 Are struct fred and union fred the same type? - Unknown + Yes 252 NAD Incomplete argument types when calling non-prototyped functions - Unknown + Yes 253 NAD "overriding" in designated initializers - Unknown + Yes 254 @@ -1464,7 +1464,7 @@ conformance.

255 NAD Non-prototyped function calls and argument mismatches - Unknown + Yes 256 @@ -1482,7 +1482,7 @@ conformance.

258 NAD Ordering of "defined" and macro replacement - Unknown + Yes 259