Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port gcc-dg tests from GCC #49

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions SingleSource/Regression/C/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ if(ARCH MATCHES "x86" OR ARCH MATCHES "riscv" OR
ARCH MATCHES "AArch64" OR ARCH MATCHES "ARM" OR
ARCH MATCHES "LoongArch")
add_subdirectory(gcc-c-torture)
add_subdirectory(gcc-dg)
endif()

list(APPEND LDFLAGS -lm)
Expand Down
63 changes: 2 additions & 61 deletions SingleSource/Regression/C/gcc-c-torture/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,64 +1,5 @@
# The following cause errors if they are passed to clang via CFLAGS
set(CLANG_ERRORING_CFLAGS
"-fno-early-inlining"
"-fno-ira-share-spill-slots"
"-ftree-loop-distribution"
"-fno-tree-bit-ccp"
"-fno-tree-coalesce-vars"
)

# This pulls out options in dg-options into `${Variable}`
function(gcc_torture_dg_options_cflags Variable File)
# Some files have dg-options which we need to pick up. These should be in
# the first line but often aren't.
#
# We also need to be careful not to pick up target-specific dg-options.
set(DG_CFLAGS)

file(STRINGS ${File} FileLines)
foreach(FileLine ${FileLines})
# Looking for `dg-options "..."` or `dg-additional-options "..."` without
# `{ target` afterwards (ignoring spaces).
if(FileLine MATCHES "dg-(additional-)?options ({ )?\"([^\"]*)\"( })?(.*)")
# This is needed to turn the string into a list of CFLAGS
separate_arguments(FILE_CFLAGS UNIX_COMMAND ${CMAKE_MATCH_3})
# This does the negative lookahead for `{ target` anywhere in the rest of
# the line
if(NOT ${CMAKE_MATCH_5} MATCHES "{ +target")
list(APPEND DG_CFLAGS ${FILE_CFLAGS})
endif()
endif()
endforeach()

# Remove any flags that will make clang error
if (DG_CFLAGS)
list(REMOVE_ITEM DG_CFLAGS ${CLANG_ERRORING_CFLAGS})
endif()

# Set the parent scope variable
set(${Variable} ${DG_CFLAGS} PARENT_SCOPE)
endfunction()

function(gcc_torture_execute_test File)
cmake_parse_arguments(_TORTURE "" "PREFIX" "CFLAGS;LDFLAGS" ${ARGN})
# There are a few tests with duplicate filenames, and CMake wants all target
# names to be unique, so we add a disambiguator to the target name. The
# disambiguator is based upon the directory structure, swapping `/` for `-`.
get_filename_component(Name ${File} NAME_WE)
set(_target "${_TORTURE_PREFIX}-${Name}")

gcc_torture_dg_options_cflags(DG_CFLAGS ${File})

# Add any flags that were requested
list(APPEND CFLAGS ${DG_CFLAGS} ${_TORTURE_CFLAGS})
list(APPEND LDFLAGS ${_TORTURE_LDFLAGS})

llvm_test_executable_no_test(${_target} ${File})
llvm_test_run()

llvm_add_test_for_target(${_target})
endfunction()
include(${CMAKE_CURRENT_SOURCE_DIR}/../../DgOptions.txt)

file(COPY lit.local.cfg DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")

add_subdirectory(execute)
add_subdirectory(execute)
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
add_subdirectory(ieee)

# GCC C Torture Suite is conventionally run without warnings
list(APPEND CFLAGS -Wno-implicit-int -Wno-int-conversion -Wno-implicit-function-declaration -w)

set(TestsToSkip)

##
Expand Down
20 changes: 20 additions & 0 deletions SingleSource/Regression/C/gcc-dg/20000108-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Copyright (C) 2000 Free Software Foundation.

by Alexandre Oliva <oliva@lsd.ic.unicamp.br> */

/* { dg-do run } */
/* { dg-options "-O3" } */

extern void abort (void);

void foo () {} /* unused, but essential to trigger the bug */

int main () {
int i;
/* use asms to prevent optimizations */
/* i = -1; */ asm ("" : "=r" (i) : "0" (-1));
/* i = 1; */ asm ("" : "=r" (i) : "0" (i ? 1 : 2));
if (i != 1)
abort();
return 0;
}
17 changes: 17 additions & 0 deletions SingleSource/Regression/C/gcc-dg/20000111-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Copyright (C) 2000 Free Software Foundation.

by Alexandre Oliva <oliva@lsd.ic.unicamp.br> */

/* { dg-do compile } */

__inline int
foo (int **q) {
return *q && **q;
}

void
bar () {
int **p;
if (foo (p))
do_something ();
}
20 changes: 20 additions & 0 deletions SingleSource/Regression/C/gcc-dg/20000623-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* { dg-do run } */
/* { dg-options "-O3 -fno-strict-aliasing" } */

extern void exit (int);
extern void abort (void);

struct foos { int l; };
int foo;
static struct foos *getfoo(void);
int main (void)
{
struct foos *f = getfoo();
f->l = 1;
foo = 2;
if (f->l == 1)
abort();
exit(0);
}
static struct foos *getfoo(void)
{ return (struct foos *)&foo; }
13 changes: 13 additions & 0 deletions SingleSource/Regression/C/gcc-dg/20000629-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* { dg-do compile } */
/* { dg-options "-O2 -g" } */

void foo(register char *p)
{
char c, *q, *sp;
while (1) {
*p++=0;
sp=p+1;
c=*sp;
*p++=0;
}
}
17 changes: 17 additions & 0 deletions SingleSource/Regression/C/gcc-dg/20000707-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* { dg-do compile } */
/* { dg-options "-O2 -Wall" } */
/* { dg-require-effective-target label_values } */

extern void foo(void *here);
extern inline void bar(void)
{
__label__ here;
foo(&&here);
here:
;
}

void baz(void)
{
bar();
}
78 changes: 78 additions & 0 deletions SingleSource/Regression/C/gcc-dg/20000906-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* { dg-do run } */

/* Testcase distilled from glibc's nss_parse_service_list in nss/nsswitch.c
It can't be distilled further. Fails with `-O2' for i[3456]86. */

/* this simulates a bounded-pointer type. */
struct ucharp { unsigned char *v, *l, *h; };

/* this simulates bounded-pointer check prior to pointer dereference. */
#define AREF(var, idx) ((((((((var).v+(idx)) < (var).l) \
|| (((var).v+(idx)+1) > (var).h))) \
&& (__builtin_trap (), 0)), \
(var).v)[(idx)])

struct list
{
struct list *next;
};

struct list *
alloc_list (void)
{
static struct list l;
return &l;
}

int one = 1;

void
foo (struct ucharp cp, struct ucharp lp, struct list **nextp)
{
while (1)
{
struct list *list;
while (AREF (lp, 0) && AREF (cp, AREF (lp, 0)))
++lp.v;
list = alloc_list ();
while (AREF (cp, AREF (lp, 0)))
++lp.v;
if (AREF (lp, 0) == one)
do
++lp.v;
while (AREF (lp, 0) && AREF (cp, AREF (lp, 0)));
/* The above AREF (cp, ...) fails because the pseudo created to
hold cp.v holds garbage, having never been set.
The easiest way to see the problem is to compile wiht `-O2 -da'
then look at *.09.loop. Search for something like this:

Hoisted regno 183 r/o from (mem/s:SI (reg:SI 16 argp) 10)
Replaced reg 91, deleting init_insn (213).

Now, look for the use of reg 91, which has no set. */

*nextp = list;
nextp = &list->next;
if (!*lp.v)
break;
}
}

extern void exit (int);

int
main (void)
{
static unsigned char cp0[] = "\0\0\0\0";
struct ucharp cp = { cp0, cp0, cp0 + sizeof (cp0) };

static unsigned char lp0[] = "\1\1\0\0";
struct ucharp lp = { lp0, lp0, lp0 + sizeof (lp0) };

struct list list;
struct list *nextp = &list;

foo (cp, lp, &nextp);

exit (0);
}
27 changes: 27 additions & 0 deletions SingleSource/Regression/C/gcc-dg/20000926-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Copyright (C) 2000 Free Software Foundation.
by William Cohen <wcohen@redhat.com> */

/* { dg-do compile } */
/* { dg-options "" } */
#include <limits.h>

struct PDATA
{
unsigned int Dummy:(sizeof(int)*CHAR_BIT);
const char* PName;
};

typedef struct PDATA P_DATA;

struct PLAYBOOK {
const char * BookName;
P_DATA Play[0];
};

struct PLAYBOOK playbook =
{
"BookName",
{
{ 1, "PName0" }, /* { dg-warning "(excess elements)|(near initialization)" } */
}
};
48 changes: 48 additions & 0 deletions SingleSource/Regression/C/gcc-dg/20001009-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* { dg-do compile { target fpic } } */
/* { dg-options "-O2 -fpic" } */
/* { dg-skip-if "too many arguments in function call" { bpf-*-* } } */

extern void foo (void *a, double x, double y);
void
bar (void *a, double b, double c, double d, double e, double f, double g, double h, double i, double j, double k[6])
{
double l, m, n, o, p;
double q, r, s, t, u;
double x, y, v, w;
double z = 0.5 * j;
double aa;
l = b - 3 * d;
m = 4 * f;
n = f - h;
q = c + 3 * g - i;
r = 2 * (e - 2 * g + i);
s = g - i;
if (l != 0.0)
{
aa = 0.0;
o = (- m + aa);
p = (- m - aa);
if (o > 0.0)
{
x = ((b-h)*o + 3*(d+h)*o + 3*(f-h)*o);
y = ((c-i)*o + 3*(e+i)*o + 3*(g-i)*o);
foo (a, z, w);
foo (a, -z, w);
}
if (p > 0.0)
{
x = ((b+3*f-h)*p + 3*(d-2*f+h)*p + 3*p);
y = ((c+3*g-i)*p + 3*(e-2*g+i)*p + 3*p);
v = x * k[0] + y * k[2];
w = x * k[1] + y * k[3];
foo (a, z, w);
foo (a, - z, w);
}
}
if (q != 0.0)
{
aa = 0.0;
t = (- r + aa) / (2 * q);
u = (- r - aa) / (2 * q);
}
}
19 changes: 19 additions & 0 deletions SingleSource/Regression/C/gcc-dg/20001012-1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* { dg-do run { target fpic } } */
/* { dg-options "-O2 -fpic" } */

extern void abort (void);
extern void exit (int);

double
foo (void)
{
return (__extension__ ((union { unsigned __l __attribute__((__mode__(__SI__))); float __d; }) { __l: 0x3f800000UL }).__d);
}

int
main ()
{
if (foo() != 1.0)
abort ();
exit (0);
}
38 changes: 38 additions & 0 deletions SingleSource/Regression/C/gcc-dg/20001012-2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* { dg-do run { target fpic } } */
/* { dg-options "-O2 -fpic" } */
/* { dg-require-effective-target alloca } */

extern void abort (void);
extern void exit (int);

void foo (char *x, const char *y, ...)
{
}

double bar (const char *x, long y)
{
return 0.0;
}

typedef __SIZE_TYPE__ size_t;
extern size_t strlen (const char *);

double baz (const char *x)
{
if (x[0] != '\0')
{
char y[6 + strlen (x)];
foo (y, "FOO", x);
return bar (y, 0);
}

return (__extension__ ((union { unsigned __l __attribute__((__mode__(__SI__))); float __d; }) { __l: 0x3f800000UL }).__d);
}

int
main ()
{
if (baz("") != 1.0)
abort ();
exit (0);
}
Loading