Skip to content

Commit

Permalink
Test and document some C99 DRs
Browse files Browse the repository at this point in the history
This captures the first 15 or so DRs in C99
  • Loading branch information
AaronBallman committed Jun 30, 2022
1 parent e961e05 commit cce06da
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 9 deletions.
23 changes: 23 additions & 0 deletions clang/test/C/drs/dr206.c
@@ -0,0 +1,23 @@
/* RUN: %clang_cc1 -std=c89 -Wno-deprecated-non-prototype -ast-dump -o - %s | FileCheck %s
RUN: %clang_cc1 -std=c99 -Wno-deprecated-non-prototype -ast-dump -o - %s | FileCheck %s
RUN: %clang_cc1 -std=c11 -Wno-deprecated-non-prototype -ast-dump -o - %s | FileCheck %s
RUN: %clang_cc1 -std=c17 -Wno-deprecated-non-prototype -ast-dump -o - %s | FileCheck %s
*/

/* WG14 DR206: yes
* Default argument conversion of float _Complex
*/
void dr206_unprototyped();
void dr206(void) {
/* Ensure that _Complex float is not promoted to _Complex double but is
* instead passed directly without a type conversion.
*/
_Complex float f = 1.2f;
dr206_unprototyped(f);
// CHECK: CallExpr 0x{{.*}} <line:16:3, col:23> 'void'
// CHECK-NEXT: ImplicitCastExpr 0x{{.*}} <col:3> 'void (*)()' <FunctionToPointerDecay>
// CHECK-NEXT: DeclRefExpr 0x{{.*}} <col:3> 'void ()' Function 0x{{.*}} 'dr206_unprototyped' 'void ()'
// CHECK-NEXT: ImplicitCastExpr 0x{{.*}} <col:22> '_Complex float' <LValueToRValue>
// CHECK-NEXT: DeclRefExpr 0x{{.*}} <col:22> '_Complex float' lvalue Var 0x{{.*}} 'f' '_Complex float'
}

24 changes: 24 additions & 0 deletions clang/test/C/drs/dr208.c
@@ -0,0 +1,24 @@
/* RUN: %clang_cc1 -std=c99 -verify -emit-llvm -o - %s | FileCheck %s
RUN: %clang_cc1 -std=c11 -verify -emit-llvm -o - %s | FileCheck %s
RUN: %clang_cc1 -std=c17 -verify -emit-llvm -o - %s | FileCheck %s
RUN: %clang_cc1 -std=c2x -verify -emit-llvm -o - %s | FileCheck %s
*/

/* WG14 DR208: yes
* Ambiguity in initialization
*/
int dr208_init(int);
void dr208(void) {
int a[2] = {
dr208_init(0), /* expected-note {{previous initialization with side effects is here (side effects will not occur at run time)}} */
dr208_init(1),
[0] = dr208_init(2) /* expected-warning {{initializer overrides prior initialization of this subobject}} */
};

/* CHECK-NOT: call i32 @dr208_init(i32 noundef 0)
CHECK-DAG: call i32 @dr208_init(i32 noundef 1)
CHECK-DAG: call i32 @dr208_init(i32 noundef 2)
CHECK-NOT: call i32 @dr208_init(i32 noundef 0)
*/
}

61 changes: 61 additions & 0 deletions clang/test/C/drs/dr209.c
@@ -0,0 +1,61 @@
/* RUN: %clang_cc1 -std=c99 -ffreestanding -triple x86_64-unknown-linux -fsyntax-only -verify -pedantic -Wno-c11-extensions %s
RUN: %clang_cc1 -std=c99 -ffreestanding -triple x86_64-unknown-win32 -fms-compatibility -fsyntax-only -verify -pedantic -Wno-c11-extensions %s
RUN: %clang_cc1 -std=c11 -ffreestanding -fsyntax-only -verify -pedantic %s
RUN: %clang_cc1 -std=c17 -ffreestanding -fsyntax-only -verify -pedantic %s
RUN: %clang_cc1 -std=c2x -ffreestanding -fsyntax-only -verify -pedantic %s
*/

/* WG14 DR209: partial
* Problem implementing INTN_C macros
*/
#include <stdint.h>

#if INT8_C(0) != 0
#error "uh oh"
#elif INT16_C(0) != 0
#error "uh oh"
#elif INT32_C(0) != 0
#error "uh oh"
#elif INT64_C(0) != 0LL
#error "uh oh"
#elif UINT8_C(0) != 0U
#error "uh oh"
#elif UINT16_C(0) != 0U
#error "uh oh"
#elif UINT32_C(0) != 0U
#error "uh oh"
#elif UINT64_C(0) != 0ULL
#error "uh oh"
#endif

void dr209(void) {
(void)_Generic(INT8_C(0), __typeof__(+(int_least8_t){0}) : 1);
(void)_Generic(INT16_C(0), __typeof__(+(int_least16_t){0}) : 1);
(void)_Generic(INT32_C(0), __typeof__(+(int_least32_t){0}) : 1);
(void)_Generic(INT64_C(0), __typeof__(+(int_least64_t){0}) : 1);
(void)_Generic(UINT8_C(0), __typeof__(+(uint_least8_t){0}) : 1);
(void)_Generic(UINT16_C(0), __typeof__(+(uint_least16_t){0}) : 1);
// FIXME: This is not the expected behavior; the type of the expanded value
// in both of these cases should be 'int',
//
// C99 7.18.4p3: The type of the expression shall have the same type as would
// an expression of the corresponding type converted according to the integer
// promotions.
//
// C99 7.18.4.1p1: The macro UINTN_C(value) shall expand to an integer
// constant expression corresponding to the type uint_leastN_t.
//
// C99 7.18.1.2p2: The typedef name uint_leastN_t designates an unsigned
// integer type with a width of at least N, ...
//
// So the value's type is the same underlying type as uint_leastN_t, which is
// unsigned char for uint_least8_t, and unsigned short for uint_least16_t,
// but then the value undergoes integer promotions which would convert both
// of those types to int.
//
// expected-error@-2 {{controlling expression type 'unsigned int' not compatible with any generic association type}}
// expected-error@-2 {{controlling expression type 'unsigned int' not compatible with any generic association type}}
(void)_Generic(UINT32_C(0), __typeof__(+(uint_least32_t){0}) : 1);
(void)_Generic(UINT64_C(0), __typeof__(+(uint_least64_t){0}) : 1);
}

82 changes: 82 additions & 0 deletions clang/test/C/drs/dr2xx.c
@@ -0,0 +1,82 @@
/* RUN: %clang_cc1 -std=c89 -fsyntax-only -verify=expected,c89only -pedantic -Wno-c11-extensions %s
RUN: %clang_cc1 -std=c99 -triple x86_64-unknown-linux -fsyntax-only -verify=expected,c99untilc2x -pedantic -Wno-c11-extensions %s
RUN: %clang_cc1 -std=c99 -triple x86_64-unknown-win32 -fms-compatibility -fsyntax-only -verify=expected,c99untilc2x -pedantic -Wno-c11-extensions %s
RUN: %clang_cc1 -std=c11 -fsyntax-only -verify=expected,c99untilc2x -pedantic %s
RUN: %clang_cc1 -std=c17 -fsyntax-only -verify=expected,c99untilc2x -pedantic %s
RUN: %clang_cc1 -std=c2x -fsyntax-only -verify=expected,c2xandup -pedantic %s
*/

/* The following are DRs which do not require tests to demonstrate
* conformance or nonconformance.
*
* WG14 DR201: yes
* Integer types longer than long
*
* WG14 DR211: yes
* Accuracy of decimal string to/from "binary" (non-decimal) floating-point conversions
*
* WG14 DR215: yes
* Equality operators
*/


/* WG14 DR204: yes
* size_t and ptrdiff_t as a long long type
*/
void dr204(void) {
__typeof__(sizeof(0)) s;
__typeof__((int *)0 - (int *)0) p;
signed long sl;
#if __LLONG_WIDTH__ > __LONG_WIDTH__
/* If the implementation supports a standard integer type larger than signed
* long, it's okay for size_t and ptrdiff_t to have a greater integer
* conversion rank than signed long.
*/
(void)_Generic(s + sl, __typeof__(s) : 1);
(void)_Generic(p + sl, __typeof__(p) : 1);
#elif __LLONG_WIDTH__ == __LONG_WIDTH__
/* But if the implementation doesn't support a larger standard integer type
* than signed long, the conversion rank should prefer signed long if the type
* is signed (ptrdiff_t) or unsigned long if the type is unsigned (size_t).
*/
(void)_Generic(s + sl, unsigned long : 1);
(void)_Generic(p + sl, signed long : 1);
#else
#error "Something has gone off the rails"
#endif
}

/* WG14 DR207: partial
* Handling of imaginary types
*
* FIXME: Clang recognizes the _Imaginary keyword but does not support the data
* type.
*/
void dr207(void) {
_Imaginary float f; /* expected-error {{imaginary types are not supported}}
c89only-warning {{'_Imaginary' is a C99 extension}}
*/
}

/* WG14 DR216: yes
* Source character encodings
*/
void dr216(void) {
#define A(x) _Static_assert((char)x >= 0, "no")
A('A'); A('B'); A('C'); A('D'); A('E'); A('F'); A('G'); A('H'); A('I');
A('J'); A('K'); A('L'); A('M'); A('N'); A('O'); A('P'); A('Q'); A('R');
A('S'); A('T'); A('U'); A('V'); A('W'); A('X'); A('Y'); A('Z');

A('a'); A('b'); A('c'); A('d'); A('e'); A('f'); A('g'); A('h'); A('i');
A('j'); A('k'); A('l'); A('m'); A('n'); A('o'); A('p'); A('q'); A('r');
A('s'); A('t'); A('u'); A('v'); A('w'); A('x'); A('y'); A('z');

A('0'); A('1'); A('2'); A('3'); A('4');
A('5'); A('6'); A('7'); A('8'); A('9');

A('!'); A('"'); A('#'); A('%'); A('&'); A('\''); A('('); A(')'); A('*');
A('+'); A(','); A('-'); A('.'); A('/'); A(':'); A(';'); A('<'); A('=');
A('>'); A('?'); A('['); A('\\'); A(']'); A('^'); A('_'); A('{'); A('|');
A('}'); A('~');
#undef A
}
29 changes: 20 additions & 9 deletions clang/www/c_dr_status.html
Expand Up @@ -1129,7 +1129,7 @@ <h2 id="cdr">C defect report implementation status</h2>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_201.htm">201</a></td>
<td>NAD</td>
<td>Integer types longer than long</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="202">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_202.htm">202</a></td>
Expand All @@ -1147,7 +1147,7 @@ <h2 id="cdr">C defect report implementation status</h2>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_204.htm">204</a></td>
<td>C99</td>
<td>size_t and ptrdiff_t as a long long type</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="205">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_205.htm">205</a></td>
Expand All @@ -1159,25 +1159,36 @@ <h2 id="cdr">C defect report implementation status</h2>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_206.htm">206</a></td>
<td>NAD</td>
<td>Default argument conversion of float _Complex</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="207">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_207.htm">207</a></td>
<td>C99</td>
<td>Handling of imaginary types</td>
<td class="unknown" align="center">Unknown</td>
<td class="partial" align="center">
<details><summary>Partial</summary>
Clang detects use of the _Imaginary keyword but does not otherwise
support the type yet.
</details>
</td>
</tr>
<tr id="208">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_208.htm">208</a></td>
<td>C99</td>
<td>Ambiguity in initialization</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="209">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_209.htm">209</a></td>
<td>C99</td>
<td>Problem implementing INTN_C macros</td>
<td class="na" align="center">N/A</td>
<td class="partial" align="center">
<details><summary>Partial</summary>
Clang provides these definitions in a freestanding compilation, but the
type of the value produced by <code>UINT8_C</code> and <code>UINT16_C</code>
is not the type after integer promotion per C99 7.18.4p3.
</details>
</td>
</tr>
<tr id="210">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_210.htm">210</a></td>
Expand All @@ -1189,7 +1200,7 @@ <h2 id="cdr">C defect report implementation status</h2>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_211.htm">211</a></td>
<td>C99</td>
<td>Accuracy of decimal string to/from "binary" (non-decimal) floating-point conversions</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="212">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_212.htm">212</a></td>
Expand All @@ -1213,13 +1224,13 @@ <h2 id="cdr">C defect report implementation status</h2>
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_215.htm">215</a></td>
<td>C99</td>
<td>Equality operators</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="216">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_216.htm">216</a></td>
<td>C99</td>
<td>Source character encodings</td>
<td class="unknown" align="center">Unknown</td>
<td class="full" align="center">Yes</td>
</tr>
<tr id="217">
<td><a href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_217.htm">217</a></td>
Expand Down

8 comments on commit cce06da

@nunoplopes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the tests is failing on the buildbots, see here: https://lab.llvm.org/buildbot/#/builders/109/builds/41718

@AaronBallman
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the tests is failing on the buildbots, see here: https://lab.llvm.org/buildbot/#/builders/109/builds/41718

It was fixed in 56dc4db.

@nunoplopes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! It's green indeed.

@vitalybuka
Copy link
Collaborator

@vitalybuka vitalybuka commented on cce06da Jul 1, 2022 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hubert-reinterpretcast
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is still broken https://lab.llvm.org/buildbot/#/builders/105

On Thu, 30 Jun 2022 at 14:20, Nuno Lopes @.***> wrote: Thank you! It's green indeed. — Reply to this email directly, view it on GitHub <cce06da#commitcomment-77407036>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALV4F7IDYW2OZWAWOZOYZTVRYFR7ANCNFSM52KVSE3Q . You are receiving this because you are subscribed to this thread.Message ID: <llvm/llvm-project/commit/cce06da1ecf789658551ca5f3b255c361f063abf/77407036 @github.com>

Thanks. That's fixed in 6bd53df.

@dyung
Copy link
Collaborator

@dyung dyung commented on cce06da Jul 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test dr2xx.c is still failing on arm bots:
https://lab.llvm.org/buildbot/#/builders/171/builds/16815

******************** TEST 'Clang :: C/drs/dr2xx.c' FAILED ********************
Script:
--
: 'RUN: at line 1';   /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/lib/clang/15.0.0/include -nostdsysteminc -std=c89 -fsyntax-only -verify=expected,c89only -pedantic -Wno-c11-extensions /home/tcwg-buildbot/worker/clang-armv7-quick/llvm/clang/test/C/drs/dr2xx.c
: 'RUN: at line 2';   /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/lib/clang/15.0.0/include -nostdsysteminc -std=c99 -triple x86_64-unknown-linux -fsyntax-only -verify=expected,c99untilc2x -pedantic -Wno-c11-extensions /home/tcwg-buildbot/worker/clang-armv7-quick/llvm/clang/test/C/drs/dr2xx.c
: 'RUN: at line 3';   /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/lib/clang/15.0.0/include -nostdsysteminc -std=c99 -triple x86_64-unknown-win32 -fms-compatibility -fsyntax-only -verify=expected,c99untilc2x -pedantic -Wno-c11-extensions /home/tcwg-buildbot/worker/clang-armv7-quick/llvm/clang/test/C/drs/dr2xx.c
: 'RUN: at line 4';   /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/lib/clang/15.0.0/include -nostdsysteminc -std=c11 -fsyntax-only -verify=expected,c99untilc2x -pedantic /home/tcwg-buildbot/worker/clang-armv7-quick/llvm/clang/test/C/drs/dr2xx.c
: 'RUN: at line 5';   /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/lib/clang/15.0.0/include -nostdsysteminc -std=c17 -fsyntax-only -verify=expected,c99untilc2x -pedantic /home/tcwg-buildbot/worker/clang-armv7-quick/llvm/clang/test/C/drs/dr2xx.c
: 'RUN: at line 6';   /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/lib/clang/15.0.0/include -nostdsysteminc -std=c2x -fsyntax-only -verify=expected,c2xandup -pedantic /home/tcwg-buildbot/worker/clang-armv7-quick/llvm/clang/test/C/drs/dr2xx.c
--
Exit Code: 1
Command Output (stderr):
--
error: 'error' diagnostics seen but not expected: 
  File /home/tcwg-buildbot/worker/clang-armv7-quick/llvm/clang/test/C/drs/dr2xx.c Line 35: controlling expression type 'unsigned long' not compatible with any generic association type
  File /home/tcwg-buildbot/worker/clang-armv7-quick/llvm/clang/test/C/drs/dr2xx.c Line 36: controlling expression type 'long' not compatible with any generic association type
2 errors generated.
--
********************

@AaronBallman
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm looking into the ARM failure now, sorry for that!

@AaronBallman
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test dr2xx.c is still failing on arm bots: https://lab.llvm.org/buildbot/#/builders/171/builds/16815

******************** TEST 'Clang :: C/drs/dr2xx.c' FAILED ********************
Script:
--
: 'RUN: at line 1';   /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/lib/clang/15.0.0/include -nostdsysteminc -std=c89 -fsyntax-only -verify=expected,c89only -pedantic -Wno-c11-extensions /home/tcwg-buildbot/worker/clang-armv7-quick/llvm/clang/test/C/drs/dr2xx.c
: 'RUN: at line 2';   /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/lib/clang/15.0.0/include -nostdsysteminc -std=c99 -triple x86_64-unknown-linux -fsyntax-only -verify=expected,c99untilc2x -pedantic -Wno-c11-extensions /home/tcwg-buildbot/worker/clang-armv7-quick/llvm/clang/test/C/drs/dr2xx.c
: 'RUN: at line 3';   /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/lib/clang/15.0.0/include -nostdsysteminc -std=c99 -triple x86_64-unknown-win32 -fms-compatibility -fsyntax-only -verify=expected,c99untilc2x -pedantic -Wno-c11-extensions /home/tcwg-buildbot/worker/clang-armv7-quick/llvm/clang/test/C/drs/dr2xx.c
: 'RUN: at line 4';   /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/lib/clang/15.0.0/include -nostdsysteminc -std=c11 -fsyntax-only -verify=expected,c99untilc2x -pedantic /home/tcwg-buildbot/worker/clang-armv7-quick/llvm/clang/test/C/drs/dr2xx.c
: 'RUN: at line 5';   /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/lib/clang/15.0.0/include -nostdsysteminc -std=c17 -fsyntax-only -verify=expected,c99untilc2x -pedantic /home/tcwg-buildbot/worker/clang-armv7-quick/llvm/clang/test/C/drs/dr2xx.c
: 'RUN: at line 6';   /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/bin/clang -cc1 -internal-isystem /home/tcwg-buildbot/worker/clang-armv7-quick/stage1/lib/clang/15.0.0/include -nostdsysteminc -std=c2x -fsyntax-only -verify=expected,c2xandup -pedantic /home/tcwg-buildbot/worker/clang-armv7-quick/llvm/clang/test/C/drs/dr2xx.c
--
Exit Code: 1
Command Output (stderr):
--
error: 'error' diagnostics seen but not expected: 
  File /home/tcwg-buildbot/worker/clang-armv7-quick/llvm/clang/test/C/drs/dr2xx.c Line 35: controlling expression type 'unsigned long' not compatible with any generic association type
  File /home/tcwg-buildbot/worker/clang-armv7-quick/llvm/clang/test/C/drs/dr2xx.c Line 36: controlling expression type 'long' not compatible with any generic association type
2 errors generated.
--
********************

This should now be fixed by 14035d5, 83fdf0c, and ac8dab8. Sorry about the churn while I tried to get that test correct. :-)

Please sign in to comment.