Add a set of new tests for C95/C99/C11 features that we now support.

These are currently only run by the new DOIT3 test-running script.

Note that these tests are designed to be applicable to most implementations of C95/C99/C11, not just ORCA/C. They do make certain assumptions not guaranteed by the standards (e.g. power of 2 types and some properties of IEEE-like FP), but in general those assumptions should be true for most 'normal' systems.
This commit is contained in:
Stephen Heumann 2021-08-22 15:03:54 -05:00
parent 40f560039d
commit 6ead1d4caf
20 changed files with 1303 additions and 0 deletions

19
Tests/Conformance/DOIT3 Normal file
View File

@ -0,0 +1,19 @@
{1} c95digraph.c
{1} c95iso646.c
{1} c99fam.c
{1} c99intdiv.c
{1} c99func.c
{1} c99macros.c
{1} c99ucn.c
{1} c99misc.c
{1} c99bool.c
{1} c99fpclass.c
{1} c99fenv.c
{1} c99stdint.c
{1} c99stdio.c
{1} c99llong.c
{1} c11generic.c
{1} c11align.c
{1} c11noret.c
{1} c11quickex.c
{1} c11sassert.c

View File

@ -0,0 +1,44 @@
/*
* Test alignment functionality (C11/C17).
*/
#include <stdio.h>
#include <stdalign.h>
#include <stddef.h>
#include <stdlib.h>
int main(void) {
char _Alignas(short) a;
alignas(_Alignof(max_align_t)) char b;
a = 'a';
b = 'b';
if (a != 'a' || b != 'b')
goto Fail;
if (!(alignof(char) <= _Alignof(int)))
goto Fail;
if (!(alignof(long double) <= _Alignof(max_align_t)))
goto Fail;
long *lp = aligned_alloc(alignof(long), sizeof(long)*2);
if (lp == NULL)
goto Fail;
*(lp+1) = 123456789;
if (lp[1] != 123456789)
goto Fail;
free(lp);
// aligned_alloc with invalid alignment must return NULL (C17).
lp = aligned_alloc(123, 123);
if (lp)
goto Fail;
printf ("Passed Conformance Test c11align\n");
return 0;
Fail:
printf ("Failed Conformance Test c11align\n");
}

View File

@ -0,0 +1,46 @@
/*
* Test use of generic selection expressions (C11).
*/
#include <stdio.h>
#define g(x) _Generic((x), \
int: (x)+1, \
long: (x)+2, \
double: (x)+3, \
long double: (x)+4, \
unsigned char *: 100, \
int *: 101, \
default: 200 \
)
int main(void) {
int i;
if (g(12345) != 12346)
goto Fail;
if (g(1000000L) != 1000002)
goto Fail;
if (g(123.0) != 126.0)
goto Fail;
if (g(123.0L) != 127.0L)
goto Fail;
if (g((unsigned char*)&i) != 100)
goto Fail;
if (g(&i) != 101)
goto Fail;
if (g(123u) != 200)
goto Fail;
printf ("Passed Conformance Test c11generic\n");
return 0;
Fail:
printf ("Failed Conformance Test c11generic\n");
}

View File

@ -0,0 +1,21 @@
/*
* Test _Noreturn function specifier (C11).
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdnoreturn.h>
noreturn int f2(void) {
printf ("Passed Conformance Test c11noret\n");
exit(0);
}
_Noreturn void f1(void) {
f2();
}
int main(void) {
f1();
printf ("Failed Conformance Test c11noret\n");
}

View File

@ -0,0 +1,21 @@
/*
* Test quick_exit and at_quick_exit (C11).
*/
#include <stdio.h>
#include <stdlib.h>
void f1(void) {
printf ("Passed Conformance Test c11quickex\n");
fflush(stdout);
}
void f2(void) {
printf ("Failed Conformance Test c11quickex\n");
}
int main(void) {
atexit(f2);
at_quick_exit(f1);
quick_exit(0);
}

View File

@ -0,0 +1,26 @@
/*
* Test static assertions (C11).
*/
#include <stdio.h>
#include <assert.h>
typedef struct {
int a;
static_assert(1+1==2, "bad math");
int b;
} S1;
typedef struct {
int a;
int b;
} S2;
_Static_assert(sizeof(S1)==sizeof(S2), "strange struct sizes");
int main(void) {
static_assert(sizeof(char)==1, "bad char size");
printf ("Passed Conformance Test c11sassert\n");
return 0;
}

View File

@ -0,0 +1,20 @@
/*
* Test support for digraphs (C95).
*/
%:include <stdio.h>
#define merge(a,b) a%:%:b
int main(void) <%
merge(in,t) a<:1] = {123%>;
if (a[0:> != 123)
goto Fail;
printf ("Passed Conformance Test c95digraph\n");
return 0;
Fail:
printf ("Failed Conformance Test c95digraph\n");
}

View File

@ -0,0 +1,32 @@
/*
* Test support for <iso646.h> (C95).
*/
#include <stdio.h>
#include <iso646.h>
int main(void) {
unsigned int u = 0x000F;
if (not ((0 or 1) and 1))
goto Fail;
u = compl u;
u and_eq 0x056E;
u or_eq 0x4000;
u xor_eq 0x000C;
if (u not_eq 0x456C)
goto Fail;
u = ((0x3000 bitand 0x1400) bitor 0x0020) xor 0x0320;
if (u not_eq 0x1300)
goto Fail;
printf ("Passed Conformance Test c95iso646\n");
return 0;
Fail:
printf ("Failed Conformance Test c95iso646\n");
}

View File

@ -0,0 +1,94 @@
/*
* Test of _Bool type and <stdbool.h> header (C99).
*/
#include <stdio.h>
#include <stdbool.h>
int main(void) {
_Bool a = true;
bool b = false;
if (true != 1 || false != 0)
goto Fail;
if (!a || b)
goto Fail;
if (!++a)
goto Fail;
if (!a)
goto Fail;
if (--a)
goto Fail;
if (--a != true)
goto Fail;
b = 0x80000000;
if (!b)
goto Fail;
b = 2 + 4 == 5;
if (b)
goto Fail;
a = 0.0001;
b = 0.0;
if (b || !a)
goto Fail;
a = (void*)0;
b = &a;
if (a || !b)
goto Fail;
struct {
bool a : 1;
_Bool b : 1;
} s;
s.a = true;
s.b = false;
if (!s.a || s.b)
goto Fail;
if (!++s.a)
goto Fail;
if (!s.a)
goto Fail;
if (--s.a)
goto Fail;
if (--s.a != true)
goto Fail;
s.b = 0x80000000;
if (!s.b)
goto Fail;
s.b = 2 + 4 == 5;
if (s.b)
goto Fail;
s.a = 0.0001;
s.b = 0.0;
if (s.b || !s.a)
goto Fail;
s.a = (void*)0;
s.b = &a;
if (s.a || !s.b)
goto Fail;
printf ("Passed Conformance Test c99bool\n");
return 0;
Fail:
printf ("Failed Conformance Test c99bool\n");
}

View File

@ -0,0 +1,49 @@
/*
* Test use of flexible array member (C99).
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TEST_STRING "123456789"
struct S {
int i;
char s[];
};
int main(void) {
struct S s1, *sp;
s1.i = 123;
sp = &s1;
if (sp->i != 123)
goto Fail;
sp = malloc(sizeof(struct S) + sizeof(TEST_STRING));
if (!sp)
goto Fail;
*sp = s1; // only guaranteed to copy i
if (sp->i != 123)
goto Fail;
strcpy(sp->s, TEST_STRING);
if (strcmp (sp->s, TEST_STRING) != 0) {
free(sp);
goto Fail;
}
free(sp);
printf ("Passed Conformance Test c99fam\n");
return 0;
Fail:
printf ("Failed Conformance Test c99fam\n");
}

107
Tests/Conformance/c99fenv.c Normal file
View File

@ -0,0 +1,107 @@
/*
* Test floating-point environment access with <fenv.h> (C99).
*/
#pragma STDC FENV_ACCESS ON
#include <fenv.h>
#include <float.h>
#include <stdio.h>
int main(void) {
double d;
int i;
fexcept_t excepts, excepts2 = {0};
fenv_t env, env2;
feholdexcept(&env);
i = feclearexcept(0);
if (i != 0) goto Fail;
i = feclearexcept(FE_INEXACT);
if (i != 0) goto Fail;
i = feclearexcept(FE_ALL_EXCEPT);
if (i != 0) goto Fail;
d = 1.0;
d /= 0.0;
if (fetestexcept(FE_DIVBYZERO) != FE_DIVBYZERO)
goto Fail;
i = fegetexceptflag(&excepts, FE_ALL_EXCEPT);
if (i != 0) goto Fail;
excepts2 = excepts;
i = feclearexcept(FE_ALL_EXCEPT);
if (i != 0) goto Fail;
if (fetestexcept(FE_ALL_EXCEPT) != 0)
goto Fail;
i = feraiseexcept(FE_INVALID | FE_UNDERFLOW);
if (i != 0) goto Fail;
i = fegetexceptflag(&excepts, FE_ALL_EXCEPT);
if (i != 0) goto Fail;
if (fetestexcept(FE_ALL_EXCEPT - FE_INEXACT)
!= (FE_INVALID | FE_UNDERFLOW))
goto Fail;
i = fesetexceptflag(&excepts2, FE_DIVBYZERO);
if (fetestexcept(FE_ALL_EXCEPT - FE_INEXACT)
!= (FE_INVALID | FE_UNDERFLOW | FE_DIVBYZERO))
goto Fail;
i = fesetexceptflag(&excepts2, FE_ALL_EXCEPT);
if (fetestexcept(FE_ALL_EXCEPT) != FE_DIVBYZERO)
goto Fail;
i = fetestexcept(0);
if (i != 0) goto Fail;
i = fesetround(FE_UPWARD);
if (i != 0) goto Fail;
i = fegetround();
if (i != FE_UPWARD) goto Fail;
if (FLT_ROUNDS != 2) goto Fail;
i = fegetenv(&env);
if (i != 0) goto Fail;
i = fesetround(FE_DOWNWARD);
if (i != 0) goto Fail;
i = fegetround();
if (i != FE_DOWNWARD) goto Fail;
if (FLT_ROUNDS != 3) goto Fail;
i = feclearexcept(FE_ALL_EXCEPT);
if (i != 0) goto Fail;
i = feholdexcept(&env2);
if (i != 0) goto Fail;
fesetenv(&env);
if (i != 0) goto Fail;
if (fegetround() != FE_UPWARD) goto Fail;
if (fetestexcept(FE_ALL_EXCEPT) != FE_DIVBYZERO)
goto Fail;
fesetenv(&env2);
if (i != 0) goto Fail;
if (fegetround() != FE_DOWNWARD) goto Fail;
i = feraiseexcept(FE_INVALID | FE_INEXACT);
if (i != 0) goto Fail;
feupdateenv(&env2);
if (i != 0) goto Fail;
if (fegetround() != FE_DOWNWARD) goto Fail;
if (fetestexcept(FE_ALL_EXCEPT) != (FE_INVALID | FE_INEXACT))
goto Fail;
fesetenv(FE_DFL_ENV);
if (i != 0) goto Fail;
printf ("Passed Conformance Test c99fenv\n");
return 0;
Fail:
printf ("Failed Conformance Test c99fenv\n");
}

View File

@ -0,0 +1,216 @@
/*
* Test floating-point classification macros (C99).
*/
#include <float.h>
#include <math.h>
#include <stdio.h>
int main(void) {
float f;
double d;
long double ld;
// These tests assume IEEE-like floating-point behavior.
/* float tests */
f = INFINITY;
if (fpclassify(f) != FP_INFINITE)
goto Fail;
if (!isinf(f) || isfinite(f) || isnan(f) || isnormal(f))
goto Fail;
if (signbit(f) != 0)
goto Fail;
f = NAN;
if (fpclassify(f) != FP_NAN)
goto Fail;
if (isinf(f) || isfinite(f) || !isnan(f) || isnormal(f))
goto Fail;
f = 1.0;
if (fpclassify(f) != FP_NORMAL)
goto Fail;
if (isinf(f) || !isfinite(f) || isnan(f) || !isnormal(f))
goto Fail;
if (signbit(f) != 0)
goto Fail;
f = FLT_MIN;
if (fpclassify(f) != FP_NORMAL)
goto Fail;
if (isinf(f) || !isfinite(f) || isnan(f) || !isnormal(f))
goto Fail;
if (signbit(f) != 0)
goto Fail;
f = FLT_MAX;
if (fpclassify(f) != FP_NORMAL)
goto Fail;
if (isinf(f) || !isfinite(f) || isnan(f) || !isnormal(f))
goto Fail;
if (signbit(f) != 0)
goto Fail;
f = 0.0;
if (fpclassify(f) != FP_ZERO)
goto Fail;
if (isinf(f) || !isfinite(f) || isnan(f) || isnormal(f))
goto Fail;
if (signbit(f) != 0)
goto Fail;
f = FLT_MIN / 2.0;
if (fpclassify(f) != FP_SUBNORMAL)
goto Fail;
if (isinf(f) || !isfinite(f) || isnan(f) || isnormal(f))
goto Fail;
if (signbit(f) != 0)
goto Fail;
f = -INFINITY;
if (signbit(f) == 0)
goto Fail;
f = -1.0;
if (signbit(f) == 0)
goto Fail;
/* double tests */
d = INFINITY;
if (fpclassify(d) != FP_INFINITE)
goto Fail;
if (!isinf(d) || isfinite(d) || isnan(d) || isnormal(d))
goto Fail;
if (signbit(d) != 0)
goto Fail;
d = NAN;
if (fpclassify(d) != FP_NAN)
goto Fail;
if (isinf(d) || isfinite(d) || !isnan(d) || isnormal(d))
goto Fail;
d = 1.0;
if (fpclassify(d) != FP_NORMAL)
goto Fail;
if (isinf(d) || !isfinite(d) || isnan(d) || !isnormal(d))
goto Fail;
if (signbit(d) != 0)
goto Fail;
d = DBL_MIN;
if (fpclassify(d) != FP_NORMAL)
goto Fail;
if (isinf(d) || !isfinite(d) || isnan(d) || !isnormal(d))
goto Fail;
if (signbit(d) != 0)
goto Fail;
d = DBL_MAX;
if (fpclassify(d) != FP_NORMAL)
goto Fail;
if (isinf(d) || !isfinite(d) || isnan(d) || !isnormal(d))
goto Fail;
if (signbit(d) != 0)
goto Fail;
d = 0.0;
if (fpclassify(d) != FP_ZERO)
goto Fail;
if (isinf(d) || !isfinite(d) || isnan(d) || isnormal(d))
goto Fail;
if (signbit(d) != 0)
goto Fail;
d = DBL_MIN / 2.0;
if (fpclassify(d) != FP_SUBNORMAL)
goto Fail;
if (isinf(d) || !isfinite(d) || isnan(d) || isnormal(d))
goto Fail;
if (signbit(d) != 0)
goto Fail;
d = -INFINITY;
if (signbit(d) == 0)
goto Fail;
d = -1.0;
if (signbit(d) == 0)
goto Fail;
/* long double tests */
ld = INFINITY;
if (fpclassify(ld) != FP_INFINITE)
goto Fail;
if (!isinf(ld) || isfinite(ld) || isnan(ld) || isnormal(ld))
goto Fail;
if (signbit(ld) != 0)
goto Fail;
ld = NAN;
if (fpclassify(ld) != FP_NAN)
goto Fail;
if (isinf(ld) || isfinite(ld) || !isnan(ld) || isnormal(ld))
goto Fail;
ld = 1.0;
if (fpclassify(ld) != FP_NORMAL)
goto Fail;
if (isinf(ld) || !isfinite(ld) || isnan(ld) || !isnormal(ld))
goto Fail;
if (signbit(ld) != 0)
goto Fail;
ld = LDBL_MIN;
if (fpclassify(ld) != FP_NORMAL)
goto Fail;
if (isinf(ld) || !isfinite(ld) || isnan(ld) || !isnormal(ld))
goto Fail;
if (signbit(ld) != 0)
goto Fail;
ld = LDBL_MAX;
if (fpclassify(ld) != FP_NORMAL)
goto Fail;
if (isinf(ld) || !isfinite(ld) || isnan(ld) || !isnormal(ld))
goto Fail;
if (signbit(ld) != 0)
goto Fail;
ld = 0.0;
if (fpclassify(ld) != FP_ZERO)
goto Fail;
if (isinf(ld) || !isfinite(ld) || isnan(ld) || isnormal(ld))
goto Fail;
if (signbit(ld) != 0)
goto Fail;
ld = LDBL_MIN / 2.0;
if (fpclassify(ld) != FP_SUBNORMAL)
goto Fail;
if (isinf(ld) || !isfinite(ld) || isnan(ld) || isnormal(ld))
goto Fail;
if (signbit(ld) != 0)
goto Fail;
ld = -INFINITY;
if (signbit(ld) == 0)
goto Fail;
ld = -1.0;
if (signbit(ld) == 0)
goto Fail;
printf ("Passed Conformance Test c99fpclass\n");
return 0;
Fail:
printf ("Failed Conformance Test c99fpclass\n");
}

View File

@ -0,0 +1,27 @@
/*
* Test __func__ (C99).
*/
#include <stdio.h>
#include <string.h>
int main(void) {
const char *p = __func__;
if (strcmp(__func__, "main") != 0)
goto Fail;
if (sizeof __func__ != 5)
goto Fail;
{
if (p != __func__)
goto Fail;
}
printf ("Passed Conformance Test c99func\n");
return 0;
Fail:
printf ("Failed Conformance Test c99func\n");
}

View File

@ -0,0 +1,25 @@
/*
* Test that integer division involving negative numbers follows C99 rules.
*/
#include <stdio.h>
int main(void) {
if ((-7) / 3 != -2)
goto Fail;
if ((-7) % 3 != -1)
goto Fail;
if (7 / -3 != -2)
goto Fail;
if (7 % -3 != 1)
goto Fail;
printf ("Passed Conformance Test c99intdiv\n");
return 0;
Fail:
printf ("Failed Conformance Test c99intdiv\n");
}

View File

@ -0,0 +1,219 @@
/*
* Test the long long type and operations on it (C99).
*/
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <limits.h>
// Preprocessor arithmetic should use (u)intmax_t, which is at least long long
#if 0x1234567800000000 + 0x3333000000000000 != 0x4567567800000000
#error "Preprocessor arithmetic uses a smaller type than is required by C99+"
#endif
long long ll1, ll2, *llp;
static unsigned long long f(long long x, unsigned long long y) {
return x + y;
}
int main(void) {
unsigned long long ull1, ull2, *ullp;
ll1 = 0x2142134abc342132;
ll2 = 0424622122152311057372;
ull1 = ll1;
ull2 = ll2;
// C language operations on long long types
if (ll1 + ll2 != 7382622918894190636)
goto Fail;
if (ll1 - ll2 != -2589624592053059016)
goto Fail;
if (ll1 / ll2 != 0)
goto Fail;
if (ll1 % ll2 != 2396499163420565810)
goto Fail;
if (-ll1 != -0x2142134abc342132)
goto Fail;
if (+ll2 != 0424622122152311057372)
goto Fail;
if (ull1 + ull2 != 7382622918894190636)
goto Fail;
if (ll1 - ll2 != 15857119481656492600u)
goto Fail;
if (ull1 / ull2 != 0)
goto Fail;
if (ull1 % ull2 != 2396499163420565810)
goto Fail;
if (ull1 * ull2 != 7852775837922281172)
goto Fail;
if (-ull1 != 16050244910288985806u)
goto Fail;
if ((uint8_t)ull1 != 0x32)
goto Fail;
if ((uint16_t)ull1 != 0x2132)
goto Fail;
if ((uint32_t)ull1 != 0xbc342132)
goto Fail;
if (sizeof(ll1) < 8)
goto Fail;
if (sizeof(unsigned long long) < 8)
goto Fail;
ullp = &ull1;
if ((*ullp)++ != 0x2142134abc342132)
goto Fail;
if (ull1 != 0x2142134abc342133)
goto Fail;
if (ull1-- != 0x2142134abc342133)
goto Fail;
if (ullp[0] != 0x2142134abc342132)
goto Fail;
llp = &ll1;
if (--*llp != 0x2142134abc342131)
goto Fail;
if (ll1 != 0x2142134abc342131)
goto Fail;
if (++ll1 != 0x2142134abc342132)
goto Fail;
if (*llp != 0x2142134abc342132)
goto Fail;
if (ll1 > ll2)
goto Fail;
if (ull1 >= ll2)
goto Fail;
if (ull2 <= ll1)
goto Fail;
if (ll1 < ull1)
goto Fail;
if (ll1 != ull1)
goto Fail;
if (ull2 == ll1)
goto Fail;
if ((ll1 && ull2) != 1)
goto Fail;
if ((ll2 || 0) != 1)
goto Fail;
if ((ll1 & ull2) != 0x102010210240032)
goto Fail;
if ((ull1 | ll2) != 0x6572576bff347ffa)
goto Fail;
if ((ll1 ^ ll2) != 0x64705669ef107fc8)
goto Fail;
if (~ull1 != 0xdebdecb543cbdecd)
goto Fail;
if (ull1 << 4 != 0x142134abc3421320)
goto Fail;
if ((ll1 >>= 40) != 0x214213)
goto Fail;
ll1 = 0xabcd12345678;
if ((double)ll1 != 188897262065272.0)
goto Fail;
ull1 = (double)ll1;
if (ull1 != 0xabcd12345678)
goto Fail;
if ((double)ull1 != 188897262065272.0)
goto Fail;
ll1 = (double)ull1 * 4096.0;
if (ll1 != 0xabcd12345678000)
goto Fail;
ull2 = f(ll2, 4);
if (ull2 != 0424622122152311057376)
goto Fail;
unsigned long long (*g)(long long x, unsigned long long y) = f;
ull2 = g(1, ull2);
if (ull2 != 0424622122152311057377)
goto Fail;
// Library functions on (unsigned) long long or (u)intmax_t
if (llabs(-2143242134213423424) != 2143242134213423424)
goto Fail;
if (llabs(534253245325325) != 534253245325325)
goto Fail;
if (imaxabs(-34523523456235354) != 34523523456235354)
goto Fail;
if (imaxabs(34135353245345) != 34135353245345)
goto Fail;
lldiv_t d1;
d1 = lldiv(34532523534523245, 213);
if (d1.quot != 162124523636259)
goto Fail;
if (d1.rem != 78)
goto Fail;
d1 = lldiv(-34532523534523245, 213);
if (d1.quot != -162124523636259)
goto Fail;
if (d1.rem != -78)
goto Fail;
d1 = lldiv(-34532523534523245, -213);
if (d1.quot != 162124523636259)
goto Fail;
if (d1.rem != -78)
goto Fail;
d1 = lldiv(34532523534523245, -213);
if (d1.quot != -162124523636259)
goto Fail;
if (d1.rem != 78)
goto Fail;
imaxdiv_t d2;
d2 = imaxdiv(34532523534523245, 213);
if (d2.quot != 162124523636259)
goto Fail;
if (d2.rem != 78)
goto Fail;
if (atoll("214214215134634264") != 214214215134634264)
goto Fail;
if (strtoll("-sdfsdfsa2142", 0, 30) != -504001881733555022)
goto Fail;
if (strtoll("-asfsdfasfsfsfsfasfssdfasfsdfsafff", 0, 35) != LLONG_MIN)
goto Fail;
if (strtoull("0xfa24252315abcdef", 0, 0) != 0xfa24252315abcdef)
goto Fail;
if (strtoimax("-sdfsdfsa2142", 0, 30) != -504001881733555022)
goto Fail;
if (strtoumax("0xfa24252315abcdef", 0, 0) != 0xfa24252315abcdef)
goto Fail;
// Constant expressions
static long long sll1 =
-(321512542135123451 / 3241241234 * 2353423223)
+ 34547547645634 - 341242134234124;
if (sll1 != -233752781426004585)
goto Fail;
static unsigned long long sll2 =
(0xc345324532452345 & 0xad4312341234abcd) >> 4
| (0x2453245abcd34534 ^ 0x234213412342134a) << 3;
if (sll2 != 0x389db9fcfdaaf3f4)
goto Fail;
static long long sll3 = (long long)10000000000.1;
if (sll3 != 10000000000)
goto Fail;
static double sd1 = (double)-0x12345678abcd;
if (sd1 != -0x12345678abcd)
goto Fail;
printf ("Passed Conformance Test c99llong\n");
return 0;
Fail:
printf ("Failed Conformance Test c99llong\n");
}

View File

@ -0,0 +1,32 @@
/*
* Test macros with variable arguments and empty macro arguments (C99).
*/
#include <stdio.h>
#include <string.h>
#define a(x) (x + 5)
#define print(fmt, ...) sprintf(str, fmt, __VA_ARGS__)
char str[100];
int main(void) {
if (a() != a(0))
goto Fail;
print("%i %s", 123, "hi");
if (strcmp(str, "123 hi") != 0)
goto Fail;
print("%u %s %x", 123, "hi", 0xA8);
if (strcmp(str, "123 hi a8") != 0)
goto Fail;
printf ("Passed Conformance Test c99macros\n");
return 0;
Fail:
printf ("Failed Conformance Test c99macros\n");
}

View File

@ -0,0 +1,58 @@
/*
* Test miscellaneous C99 features.
*/
#include <stdio.h>
#include <ctype.h>
/* __STDC_HOSTED__ predefined macro */
#if !defined(__STDC_HOSTED__) || __STDC_HOSTED__ != 1
#error "Not a hosted implementation of C99+"
#endif
/* Trailing comma in enums */
enum {A,B,C,};
/* static inline functions */
inline static int f(void) {
return C;
}
/* restricted pointers and idempotent type qualifiers */
void g(char *restrict c1, char * const restrict const c2) {
*c1 = *c2;
}
int main(void) {
/* // comments */ char s[] =
// This is a comment
"But this is not";
if (sizeof s != 16)
goto Fail;
if (f() != 2)
goto Fail;
/* Mixed declarations and statements */
char c = 'x';
/* Declarations in for loops */
for (int i = 0; i < 256; i++) {
/* isblank() macro/function */
if ((_Bool)isblank(i) != (i == ' ' || i == '\t'))
goto Fail;
if ((_Bool)(isblank)(i) != (i == ' ' || i == '\t'))
goto Fail;
}
g(&c,s);
if (c != 'B')
goto Fail;
printf ("Passed Conformance Test c99misc\n");
return 0;
Fail:
printf ("Failed Conformance Test c99misc\n");
}

View File

@ -0,0 +1,89 @@
/*
* Test <stdint.h> and <inttypes.h> (C99).
*/
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
int main(void) {
// This assumes properties true for ORCA/C
// and most other typical C implementations.
int8_t i8 = 0x12;
uint_least16_t uil16 = 0x1234;
uint_fast32_t uif32 = 0x12345678;
uintmax_t uim = 0x1234567890abcdef;
uintptr_t uip;
void *p = &i8;
uip = (uintptr_t)p;
if ((void*)uip != p)
goto Fail;
if (INT32_MAX != 0x7fffffff)
goto Fail;
if (INT_LEAST16_MIN != -32768L)
goto Fail;
if (UINT_FAST64_MAX != 0xffffffffffffffff)
goto Fail;
if (PTRDIFF_MIN > -65535L)
goto Fail;
if (SIZE_MAX < 65535)
goto Fail;
if (INT32_C(0x123) != 0x123)
goto Fail;
if (sizeof(INT32_C(0x123)) != 4)
goto Fail;
if (INT64_C(42) != 42)
goto Fail;
if (sizeof(INT64_C(42)) != 8)
goto Fail;
if (INTMAX_C(0x1234567890abcdef) != 0x1234567890abcdef)
goto Fail;
if (sizeof(INTMAX_C(0x1234567890abcdef)) < 8)
goto Fail;
char s[100];
sprintf(s, "%" PRId8 " %" PRIuLEAST16 " %#" PRIxFAST32 " %" PRIXMAX,
i8, uil16, uif32, uim);
if (strcmp(s, "18 4660 0x12345678 1234567890ABCDEF") != 0)
goto Fail;
i8 = 0;
uil16 = 0;
uif32 = 0;
uim = 0;
sscanf(s, "%" SCNd8 " %" SCNuLEAST16 " %" SCNxFAST32 " %" SCNxMAX,
&i8, &uil16, &uif32, &uim);
if (i8 != 0x12)
goto Fail;
if (uil16 != 0x1234)
goto Fail;
if (uif32 != 0x12345678)
goto Fail;
if (uim != 0x1234567890abcdef)
goto Fail;
printf ("Passed Conformance Test c99stdint\n");
return 0;
Fail:
printf ("Failed Conformance Test c99stdint\n");
}

View File

@ -0,0 +1,117 @@
/*
* Test <stdio.h> features from C99.
*/
#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include <stdint.h>
#include <stdarg.h>
int mysscanf(const char *restrict str, const char *restrict fmt, ...);
int mysnprintf(char *restrict str, size_t n, const char *restrict fmt, ...);
int main(void) {
char s[100] = "abcdef";
// snprintf tests
if (snprintf(0, 0, "123") != 3)
goto Fail;
if (snprintf(s, 0, "123") != 3)
goto Fail;
if (memcmp(s, "abcdef", 6) != 0)
goto Fail;
if (snprintf(s, 1, "123") != 3)
goto Fail;
if (memcmp(s, "\0bcdef", 6) != 0)
goto Fail;
if (snprintf(s, 3, "123") != 3)
goto Fail;
if (memcmp(s, "12\0def", 6) != 0)
goto Fail;
if (snprintf(s, 4, "123") != 3)
goto Fail;
if (memcmp(s, "123\0ef", 6) != 0)
goto Fail;
s[0] = 'x';
if (snprintf(s, 0x10000, "123") != 3)
goto Fail;
if (memcmp(s, "123\0ef", 6) != 0)
goto Fail;
// new length modifiers for printf
signed char sc[2] = {-123, 42};
unsigned long long ull = 0x2134123412341234;
uintmax_t uim = 12345678901234567890u;
size_t sz = 012345;
ptrdiff_t pd = -12345;
double d = 123.456;
mysnprintf(s, 100, "%hhi %#llx %ju %zo %td %lf",
sc[0], ull, uim, sz, pd, d);
if (strcmp(s, "-123 0x2134123412341234 12345678901234567890 12345 -12345 123.456000") != 0)
goto Fail;
sc[0] = 0;
ull = 0;
uim = 0;
sz = 0;
pd = 0;
d = 0;
// new length modifiers for scanf
if (mysscanf(s, "%hhi %llx %ju %zo %td %lf",
&sc[0], &ull, &uim, &sz, &pd, &d) != 6)
goto Fail;
if (sc[0] != -123)
goto Fail;
if (ull != 0x2134123412341234)
goto Fail;
if (uim != 12345678901234567890u)
goto Fail;
if (sz != 012345)
goto Fail;
if (pd != -12345)
goto Fail;
if (d != (double)123.456)
goto Fail;
if (sc[1] != 42)
goto Fail;
printf ("Passed Conformance Test c99stdio\n");
return 0;
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;
// vsscanf function
va_start(va, fmt);
ret = vsscanf(str, fmt, va);
va_end(va);
return ret;
}
int mysnprintf(char *restrict str, size_t n, const char *restrict fmt, ...) {
va_list va;
int ret;
// vsnprintf function
va_start(va, fmt);
ret = vsnprintf(str, n, fmt, va);
va_end(va);
return ret;
}

View File

@ -0,0 +1,41 @@
/*
* Test universal character names (C99).
*/
#include <stdio.h>
#include <string.h>
int \u00c0\u0300\U0000aBcDaaa123\U000100aB\U000afffd = 38;
int abc\u2465\U00021a34xyz(void) {
return '\U00000060';
}
int main(void) {
int a;
a = \u00c0\u0300\uAbCdaaa123\U000100aB\U000a\
fffD;
if (a != 38)
goto Fail;
char c = abc\U00002465\U00021a34xyz();
if (c != '`')
goto Fail;
char s[] = "\U00000060\u0040\u0024";
if (sizeof s != 4)
goto Fail;
if (strcmp(s, "`@$") != 0)
goto Fail;
printf ("Passed Conformance Test c99ucn\n");
return 0;
Fail:
printf ("Failed Conformance Test c99ucn\n");
}