Add tests for recently-implemented language features.

This commit is contained in:
Stephen Heumann 2021-12-05 13:55:09 -06:00
parent c767848ec9
commit 98529a9342
6 changed files with 211 additions and 4 deletions

View File

@ -12,8 +12,12 @@
{1} c99stdint.c
{1} c99stdio.c
{1} c99llong.c
{1} c99hexflt.c
{1} c99arraytp.c
{1} c99complit.c
{1} c11generic.c
{1} c11align.c
{1} c11noret.c
{1} c11quickex.c
{1} c11sassert.c
{1} c11unicode.c

View File

@ -0,0 +1,69 @@
/*
* Test Unicode characters and strings (C11).
*/
#include <stdio.h>
#include <uchar.h>
#if !__STDC_UTF_16__ || !__STDC_UTF_32__
#error "Compiler does not use UTF-16/UTF-32 encodings"
#endif
int main(void) {
char16_t c16 = u'a';
char32_t c32 = U'A';
if (c16 != 0x61)
goto Fail;
if (c32 != 0x41)
goto Fail;
c16 = u'\u283C';
c32 = U'\uFB76';
if (c16 != 0x283C)
goto Fail;
if (c32 != 0xFB76)
goto Fail;
c32 = U'\U0002B820';
if (c32 != 0x2B820)
goto Fail;
char s8[] = u8"a\u042D\uF910\U00010085";
unsigned char *s8u = (unsigned char*)s8;
if (sizeof s8 != 11)
goto Fail;
if (s8u[0] != 0x61 || s8u[1] != 0xd0 || s8u[2] != 0xad ||
s8u[3] != 0xef || s8u[4] != 0xa4 || s8u[5] != 0x90 ||
s8u[6] != 0xf0 || s8u[7] != 0x90 || s8u[8] != 0x82 ||
s8u[9] != 0x85 || s8u[10] != 0x00)
goto Fail;
char16_t s16[] = u"a\u042D\uF910\U00010085";
if (sizeof s16 != 6 * sizeof(char16_t))
goto Fail;
if (s16[0] != 0x0061 || s16[1] != 0x042d || s16[2] != 0xf910 ||
s16[3] != 0xd800 || s16[4] != 0xdc85 || s16[5] != 0x0000)
goto Fail;
char32_t s32[] = U"a\u042D\uF910\U00010085";
if (sizeof s32 != 5 * sizeof(char32_t))
goto Fail;
if (s32[0] != 0x000061 || s32[1] != 0x00042d || s32[2] != 0x00f910 ||
s32[3] != 0x010085 || s32[4] != 0x000000)
goto Fail;
printf ("Passed Conformance Test c99unicode\n");
return 0;
Fail:
printf ("Failed Conformance Test c99unicode\n");
}

View File

@ -0,0 +1,24 @@
/*
* Test of qualifiers and/or 'static' in array parameter types (C99).
*/
#include <stdio.h>
int f(long x[const static 20], short y[static volatile 1], int z[const]) {
return x[0] + y[0] + z[0];
}
int main(void) {
long X[20] = {5};
short Y[15] = {60};
int Z = 700;
if (f(X,Y,&Z) != 765)
goto Fail;
printf ("Passed Conformance Test c99arraytp\n");
return 0;
Fail:
printf ("Failed Conformance Test c99arraytp\n");
}

View File

@ -0,0 +1,33 @@
/*
* Test of compound literals (C99).
*
* This currently only tests compound literals outside of functions,
* since that is the only place where ORCA/C currently supports them.
*/
#include <stdio.h>
int *p = (int[]){1,2,3};
int *q = &(int[100]){4,5,6}[1];
struct S *s = &(struct S {int i; double d; void *p;}){100,200.5,&p};
int main(void) {
if (p[2] != 3)
goto Fail;
if (*q != 5)
goto Fail;
if (q[80] != 0)
goto Fail;
p[2] = s->i;
if (p[2] != 100)
goto Fail;
printf ("Passed Conformance Test c99complit\n");
return 0;
Fail:
printf ("Failed Conformance Test c99complit\n");
}

View File

@ -0,0 +1,81 @@
/*
* Test hexadecimal floating-point constants (C99).
*/
#include <math.h>
#include <stdio.h>
int main(void) {
double d;
long double ld;
/* Parts of this assume 80-bit long double format. */
d = 0xF.8p-1;
if (d != 7.75)
goto Fail;
d = 0XAB4fp2;
if (d != 175420.0)
goto Fail;
d = 0X.23423p-1;
if (d != (double)0.06886434555053710938)
goto Fail;
d = 0x4353.p+7;
if (d != (double)2206080.0)
goto Fail;
ld = 0xabcdef0012345678ffffffffffffp123L;
if (ld != 3.7054705751091077761e+70L)
goto Fail;
ld = 0xabcdef0012345678000000000000p123L;
if (ld != 3.7054705751091077758e+70L)
goto Fail;
ld = 0x0.0000000000000000000000012345aP50L;
if (ld != 1.61688425235478883124e-14L)
goto Fail;
ld = 0x1324124.abcd23p-3000L;
if (ld != 1.63145601325652579262e-896L)
goto Fail;
ld = 0x0000000000.000000p1234567890123456789012345678901234567890L;
if (ld != 0.0)
goto Fail;
ld = 0X1p17000L;
if (ld != INFINITY)
goto Fail;
ld = 0x1.fffffffffffffffep16383L;
if (ld != 1.18973149535723176502e+4932L)
goto Fail;
ld = 0x1.ffffffffffffffffp16383L;
if (ld != INFINITY)
goto Fail;
ld = 0X1p-16400L;
if (ld != 1.28254056667789211512e-4937L)
goto Fail;
if (ld == 0)
goto Fail;
ld = 0x3abd.232323p-16390L;
if (ld != 1.97485962609712244075e-4930L)
goto Fail;
ld = 0x7.7p-17000L;
if (ld != 0.0)
goto Fail;
printf ("Passed Conformance Test c99hexflt\n");
return 0;
Fail:
printf ("Failed Conformance Test c99hexflt\n");
}

View File

@ -88,10 +88,6 @@ Fail:
printf ("Failed Conformance Test c99stdio\n");
}
#ifdef __ORCAC__
#pragma optimize 8
#endif
int mysscanf(const char *restrict str, const char *restrict fmt, ...) {
va_list va;
int ret;