-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
326 changed files
with
5,827 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <stdlib.h> | ||
#include <stdbool.h> | ||
typedef int (*myfunc)(int); | ||
int a(int arg) { return arg + 1;} | ||
int b(int arg) { return arg + 2;} | ||
int caller(myfunc fn, int arg) { | ||
return fn(arg); | ||
} | ||
int main() { | ||
myfunc arr[3] = {&a, &b, a}; | ||
myfunc foo = a; | ||
myfunc bar = &(a); | ||
if (foo != bar) abort(); | ||
if (arr[0] == arr[1]) abort(); | ||
if (arr[0] != arr[2]) abort(); | ||
if (caller(b, 40) != 42) abort(); | ||
if (caller(&b, 40) != 42) abort(); | ||
return 0; | ||
} | ||
|
||
// run | ||
// expect=fail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <stdlib.h> | ||
int func(char *x) { return x[0]; } | ||
struct S { char *member; }; | ||
struct S global_struct = { .member = "global" }; | ||
char *g = "global"; | ||
int main(void) { | ||
if (g[0] != 'g') abort(); | ||
if (global_struct.member[0] != 'g') abort(); | ||
char *string = "hello"; | ||
if (string[0] != 'h') abort(); | ||
struct S s = {.member = "hello"}; | ||
if (s.member[0] != 'h') abort(); | ||
if (func("foo") != 'f') abort(); | ||
return 0; | ||
} | ||
|
||
// run | ||
// expect=fail |
36 changes: 36 additions & 0 deletions
36
test/cases/run/Array_initializers_(string_literals,_incomplete_arrays).c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <stdlib.h> | ||
#include <string.h> | ||
extern int foo[]; | ||
int global_arr[] = {1, 2, 3}; | ||
char global_string[] = "hello"; | ||
int main(int argc, char *argv[]) { | ||
if (global_arr[2] != 3) abort(); | ||
if (strlen(global_string) != 5) abort(); | ||
const char *const_str = "hello"; | ||
if (strcmp(const_str, "hello") != 0) abort(); | ||
char empty_str[] = ""; | ||
if (strlen(empty_str) != 0) abort(); | ||
char hello[] = "hello"; | ||
if (strlen(hello) != 5 || sizeof(hello) != 6) abort(); | ||
int empty[] = {}; | ||
if (sizeof(empty) != 0) abort(); | ||
int bar[] = {42}; | ||
if (bar[0] != 42) abort(); | ||
bar[0] = 43; | ||
if (bar[0] != 43) abort(); | ||
int baz[] = {1, [42] = 123, 456}; | ||
if (baz[42] != 123 || baz[43] != 456) abort(); | ||
if (sizeof(baz) != sizeof(int) * 44) abort(); | ||
const char *const names[] = {"first", "second", "third"}; | ||
if (strcmp(names[2], "third") != 0) abort(); | ||
char catted_str[] = "abc" "def"; | ||
if (strlen(catted_str) != 6 || sizeof(catted_str) != 7) abort(); | ||
char catted_trunc_str[2] = "abc" "def"; | ||
if (sizeof(catted_trunc_str) != 2 || catted_trunc_str[0] != 'a' || catted_trunc_str[1] != 'b') abort(); | ||
char big_array_utf8lit[10] = "💯"; | ||
if (strcmp(big_array_utf8lit, "💯") != 0 || big_array_utf8lit[9] != 0) abort(); | ||
return 0; | ||
} | ||
|
||
// run | ||
// expect=fail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <stdlib.h> | ||
int sign(int v) { | ||
return -(v < 0); | ||
} | ||
int main(void) { | ||
if (sign(-5) != -1) abort(); | ||
if (sign(5) != 0) abort(); | ||
if (sign(0) != 0) abort(); | ||
return 0; | ||
} | ||
|
||
// run | ||
// expect=fail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#include <stdlib.h> | ||
#include <limits.h> | ||
#include <stdbool.h> | ||
#define M_E 2.71828182845904523536 | ||
#define M_PI_2 1.57079632679489661923 | ||
bool check_clz(unsigned int pos) { | ||
return (__builtin_clz(1 << pos) == (8 * sizeof(unsigned int) - pos - 1)); | ||
} | ||
int main(void) { | ||
if (__builtin_bswap16(0x0102) != 0x0201) abort(); | ||
if (__builtin_bswap32(0x01020304) != 0x04030201) abort(); | ||
if (__builtin_bswap64(0x0102030405060708) != 0x0807060504030201) abort(); | ||
|
||
if (__builtin_signbit(0.0) != 0) abort(); | ||
if (__builtin_signbitf(0.0f) != 0) abort(); | ||
if (__builtin_signbit(1.0) != 0) abort(); | ||
if (__builtin_signbitf(1.0f) != 0) abort(); | ||
if (__builtin_signbit(-1.0) != 1) abort(); | ||
if (__builtin_signbitf(-1.0f) != 1) abort(); | ||
|
||
if (__builtin_popcount(0) != 0) abort(); | ||
if (__builtin_popcount(0b1) != 1) abort(); | ||
if (__builtin_popcount(0b11) != 2) abort(); | ||
if (__builtin_popcount(0b1111) != 4) abort(); | ||
if (__builtin_popcount(0b11111111) != 8) abort(); | ||
|
||
if (__builtin_ctz(0b1) != 0) abort(); | ||
if (__builtin_ctz(0b10) != 1) abort(); | ||
if (__builtin_ctz(0b100) != 2) abort(); | ||
if (__builtin_ctz(0b10000) != 4) abort(); | ||
if (__builtin_ctz(0b100000000) != 8) abort(); | ||
|
||
if (!check_clz(0)) abort(); | ||
if (!check_clz(1)) abort(); | ||
if (!check_clz(2)) abort(); | ||
if (!check_clz(4)) abort(); | ||
if (!check_clz(8)) abort(); | ||
|
||
if (__builtin_sqrt(__builtin_sqrt(__builtin_sqrt(256))) != 2.0) abort(); | ||
if (__builtin_sqrt(__builtin_sqrt(__builtin_sqrt(256.0))) != 2.0) abort(); | ||
if (__builtin_sqrt(__builtin_sqrt(__builtin_sqrt(256.0f))) != 2.0) abort(); | ||
if (__builtin_sqrtf(__builtin_sqrtf(__builtin_sqrtf(256.0f))) != 2.0f) abort(); | ||
|
||
if (__builtin_sin(1.0) != -__builtin_sin(-1.0)) abort(); | ||
if (__builtin_sinf(1.0f) != -__builtin_sinf(-1.0f)) abort(); | ||
if (__builtin_sin(M_PI_2) != 1.0) abort(); | ||
if (__builtin_sinf(M_PI_2) != 1.0f) abort(); | ||
|
||
if (__builtin_cos(1.0) != __builtin_cos(-1.0)) abort(); | ||
if (__builtin_cosf(1.0f) != __builtin_cosf(-1.0f)) abort(); | ||
if (__builtin_cos(0.0) != 1.0) abort(); | ||
if (__builtin_cosf(0.0f) != 1.0f) abort(); | ||
|
||
if (__builtin_exp(0) != 1.0) abort(); | ||
if (__builtin_fabs(__builtin_exp(1.0) - M_E) > 0.00000001) abort(); | ||
if (__builtin_exp(0.0f) != 1.0f) abort(); | ||
|
||
if (__builtin_exp2(0) != 1.0) abort(); | ||
if (__builtin_exp2(4.0) != 16.0) abort(); | ||
if (__builtin_exp2f(0.0f) != 1.0f) abort(); | ||
if (__builtin_exp2f(4.0f) != 16.0f) abort(); | ||
|
||
if (__builtin_log(M_E) != 1.0) abort(); | ||
if (__builtin_log(1.0) != 0.0) abort(); | ||
if (__builtin_logf(1.0f) != 0.0f) abort(); | ||
|
||
if (__builtin_log2(8.0) != 3.0) abort(); | ||
if (__builtin_log2(1.0) != 0.0) abort(); | ||
if (__builtin_log2f(8.0f) != 3.0f) abort(); | ||
if (__builtin_log2f(1.0f) != 0.0f) abort(); | ||
|
||
if (__builtin_log10(1000.0) != 3.0) abort(); | ||
if (__builtin_log10(1.0) != 0.0) abort(); | ||
if (__builtin_log10f(1000.0f) != 3.0f) abort(); | ||
if (__builtin_log10f(1.0f) != 0.0f) abort(); | ||
|
||
if (__builtin_fabs(-42.0f) != 42.0) abort(); | ||
if (__builtin_fabs(-42.0) != 42.0) abort(); | ||
if (__builtin_fabs(-42) != 42.0) abort(); | ||
if (__builtin_fabsf(-42.0f) != 42.0f) abort(); | ||
|
||
if (__builtin_fabs(-42.0f) != 42.0) abort(); | ||
if (__builtin_fabs(-42.0) != 42.0) abort(); | ||
if (__builtin_fabs(-42) != 42.0) abort(); | ||
if (__builtin_fabsf(-42.0f) != 42.0f) abort(); | ||
|
||
if (__builtin_abs(42) != 42) abort(); | ||
if (__builtin_abs(-42) != 42) abort(); | ||
if (__builtin_abs(INT_MIN) != INT_MIN) abort(); | ||
|
||
if (__builtin_floor(42.9) != 42.0) abort(); | ||
if (__builtin_floor(-42.9) != -43.0) abort(); | ||
if (__builtin_floorf(42.9f) != 42.0f) abort(); | ||
if (__builtin_floorf(-42.9f) != -43.0f) abort(); | ||
|
||
if (__builtin_ceil(42.9) != 43.0) abort(); | ||
if (__builtin_ceil(-42.9) != -42) abort(); | ||
if (__builtin_ceilf(42.9f) != 43.0f) abort(); | ||
if (__builtin_ceilf(-42.9f) != -42.0f) abort(); | ||
|
||
if (__builtin_trunc(42.9) != 42.0) abort(); | ||
if (__builtin_truncf(42.9f) != 42.0f) abort(); | ||
if (__builtin_trunc(-42.9) != -42.0) abort(); | ||
if (__builtin_truncf(-42.9f) != -42.0f) abort(); | ||
|
||
if (__builtin_round(0.5) != 1.0) abort(); | ||
if (__builtin_round(-0.5) != -1.0) abort(); | ||
if (__builtin_roundf(0.5f) != 1.0f) abort(); | ||
if (__builtin_roundf(-0.5f) != -1.0f) abort(); | ||
|
||
if (__builtin_strcmp("abc", "abc") != 0) abort(); | ||
if (__builtin_strcmp("abc", "def") >= 0 ) abort(); | ||
if (__builtin_strcmp("def", "abc") <= 0) abort(); | ||
|
||
if (__builtin_strlen("this is a string") != 16) abort(); | ||
|
||
char *s = malloc(6); | ||
__builtin_memcpy(s, "hello", 5); | ||
s[5] = '\0'; | ||
if (__builtin_strlen(s) != 5) abort(); | ||
|
||
__builtin_memset(s, 42, __builtin_strlen(s)); | ||
if (s[0] != 42 || s[1] != 42 || s[2] != 42 || s[3] != 42 || s[4] != 42) abort(); | ||
|
||
free(s); | ||
|
||
return 0; | ||
} | ||
|
||
// run | ||
// expect=fail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <stdlib.h> | ||
struct S { int x; }; | ||
union U { | ||
long l; | ||
double d; | ||
struct S s; | ||
}; | ||
union U bar(union U u) { return u; } | ||
int main(void) { | ||
union U u = (union U) 42L; | ||
if (u.l != 42L) abort(); | ||
u = (union U) 2.0; | ||
if (u.d != 2.0) abort(); | ||
u = bar((union U)4.0); | ||
if (u.d != 4.0) abort(); | ||
u = (union U)(struct S){ .x = 5 }; | ||
if (u.s.x != 5) abort(); | ||
return 0; | ||
} | ||
|
||
// run | ||
// expect=fail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <stdlib.h> | ||
char foo(char c) { return c; } | ||
int bar(int i) { return i; } | ||
long baz(long l) { return l; } | ||
int main() { | ||
if (foo(1 == 2)) abort(); | ||
if (!foo(1 == 1)) abort(); | ||
if (bar(1 == 2)) abort(); | ||
if (!bar(1 == 1)) abort(); | ||
if (baz(1 == 2)) abort(); | ||
if (!baz(1 == 1)) abort(); | ||
return 0; | ||
} | ||
|
||
// run | ||
// expect=fail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
enum Foo { A, B, C }; | ||
static inline enum Foo do_stuff(void) { | ||
int64_t i = 1; | ||
return (enum Foo)i; | ||
} | ||
int main(void) { | ||
if (do_stuff() != B) abort(); | ||
return 0; | ||
} | ||
|
||
// run | ||
// expect=fail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <stdlib.h> | ||
int main(void) { | ||
int x = 123; | ||
union { typeof(x) val; } u = { x }; | ||
if (u.val != 123) abort(); | ||
return 0; | ||
} | ||
|
||
// run | ||
// expect=fail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
int main(void) { | ||
if (1 || (abort(), 1)) {} | ||
if (0 && (1, printf("do not print\n"))) {} | ||
int x = 0; | ||
x = (x = 3, 4, x + 1); | ||
if (x != 4) abort(); | ||
return 0; | ||
} | ||
|
||
// run | ||
// expect=fail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <stdlib.h> | ||
struct Foo { | ||
int a; | ||
char b[2]; | ||
float c; | ||
}; | ||
int main() { | ||
struct Foo foo; | ||
int x = 1, y = 2; | ||
foo = (struct Foo) {x + y, {'a', 'b'}, 42.0f}; | ||
if (foo.a != x + y || foo.b[0] != 'a' || foo.b[1] != 'b' || foo.c != 42.0f) abort(); | ||
return 0; | ||
} | ||
|
||
// run | ||
// expect=fail |
16 changes: 16 additions & 0 deletions
16
test/cases/run/Ensure_side-effects_only_evaluated_once_for_signed_array_indices.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <stdlib.h> | ||
int main(void) { | ||
int foo[] = {1, 2, 3, 4}; | ||
int *p = foo; | ||
int idx = 1; | ||
if ((++p)[--idx] != 2) abort(); | ||
if (p != foo + 1) abort(); | ||
if (idx != 0) abort(); | ||
if ((p++)[idx++] != 2) abort(); | ||
if (p != foo + 2) abort(); | ||
if (idx != 1) abort(); | ||
return 0; | ||
} | ||
|
||
// run | ||
// expect=fail |
17 changes: 17 additions & 0 deletions
17
test/cases/run/Ensure_while_loop_under_an_if_doesn't_steal_the_else.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <stdio.h> | ||
void doWork(int id) { } | ||
int reallyDelete(int id) { printf("deleted %d\n", id); return 1; } | ||
int process(int id, int n, int delete) { | ||
if(!delete) | ||
while(n-- > 0) doWork(id); | ||
else | ||
return reallyDelete(id); | ||
return 0; | ||
} | ||
int main(void) { | ||
process(99, 3, 0); | ||
return 0; | ||
} | ||
|
||
// run | ||
// expect=fail |
15 changes: 15 additions & 0 deletions
15
test/cases/run/Enum_constant_matches_enum_name,_multiple_enumerations_with_same_value.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <stdlib.h> | ||
enum FOO { | ||
FOO = 1, | ||
BAR = 2, | ||
BAZ = 1, | ||
}; | ||
int main(void) { | ||
enum FOO x = BAZ; | ||
if (x != 1) abort(); | ||
if (x != BAZ) abort(); | ||
if (x != FOO) abort(); | ||
} | ||
|
||
// run | ||
// expect=fail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
enum A { A0, A1=0xFFFFFFFF }; | ||
enum B { B0=-1, B1=0xFFFFFFFF }; | ||
enum C { C0=-1, C1=0 }; | ||
enum D { D0, D1=0xFFFFFFFFFFL }; | ||
enum E { E0=-1, E1=0xFFFFFFFFFFL }; | ||
int main(void) { | ||
signed char a0 = A0, a1 = A1; | ||
signed char b0 = B0, b1 = B1; | ||
signed char c0 = C0, c1 = C1; | ||
signed char d0 = D0, d1 = D1; | ||
signed char e0 = E0, e1 = E1; | ||
return 0; | ||
} | ||
|
||
// run | ||
// expect=fail |
Oops, something went wrong.