Migrate and FileCheck-ize some of:

2003-09-18-BitfieldTests.c 2007-04-11-PR1321.c 2003-11-13-TypeSafety.c 2003-08-29-StructLayoutBug.c 2010-05-14-Optimized-VarType.c 2003-10-06-NegateExprType.c 2007-06-05-NoInlineAttribute.c 2011-03-31-ArrayRefFolding.c 2010-07-14-ref-off-end.c Atomics-no64bit.c 2007-05-11-str-const.c 2004-11-27-InvalidConstantExpr.c 2007-04-05-UnPackedStruct.c 2004-03-15-SimpleIndirectGoto.c 2004-01-08-ExternInlineRedefine.c sret2.c 2007-02-07-AddrLabel.c 2002-09-19-StarInLabel.c 2003-11-16-StaticArrayInit.c 2003-08-18-SigSetJmp.c 2007-04-24-VolatileStructCopy.c 2002-07-29-Casts.c 2005-06-15-ExpandGotoInternalProblem.c 2007-09-17-WeakRef.c 2007-04-24-str-const.c 2003-08-30-LargeIntegerBitfieldMember.c inline-asm-mrv.c

from llvm/test/FrontendC.

llvm-svn: 136035
This commit is contained in:
Eric Christopher 2011-07-26 00:57:50 +00:00
parent 5387bd340b
commit e6051006ba
27 changed files with 585 additions and 0 deletions

View File

@ -0,0 +1,86 @@
// RUN: %clang_cc1 -emit-llvm %s -o /dev/null
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
int
main(int argc, char** argv)
{
char c1;
short s1, ssf1, ssd1;
unsigned char ubs0;
signed char bs0;
unsigned char ubc0, uc2;
unsigned short us2, usf1, usd1;
int ic3, is3, sif1, sid1;
unsigned int uic4, uis4, uif1, uid1;
long slf1, sld1;
unsigned long ulf1, uld1;
float f1;
double d1;
/* Test integer to integer conversions */
c1 = (char) (argc >= 2)? atoi(argv[1]) : 0xff64; /* 100 = 'd' */
s1 = (short) (argc >= 3)? atoi(argv[2]) : -769; /* 0xf7ff = -769 */
ubc0 = (unsigned char) c1; /* 100 = 'd' */
ubs0 = (unsigned char) s1; /* 0xff = 255 */
bs0 = (signed char) s1; /* 0xff = -1 */
uc2 = (unsigned char) c1; /* 100 = 'd' */
us2 = (unsigned short) s1; /* 0xf7ff = 64767 */
ic3 = (int) c1; /* 100 = 'd' */
is3 = (int) s1; /* 0xfffff7ff = -769 */
uic4 = (unsigned int) c1; /* 100 = 'd' */
uis4 = (unsigned int) s1; /* 0xfffff7ff = 4294966527 */
printf("ubc0 = '%c'\n", ubc0);
printf("ubs0 = %u\n", ubs0);
printf("bs0 = %d\n", bs0);
printf("c1 = '%c'\n", c1);
printf("s1 = %d\n", s1);
printf("uc2 = '%c'\n", uc2);
printf("us2 = %u\n", us2);
printf("ic3 = '%c'\n", ic3);
printf("is3 = %d\n", is3);
printf("uic4 = '%c'\n", uic4);
printf("uis4 = %u\n", uis4);
/* Test floating-point to integer conversions */
f1 = (float) (argc >= 4)? atof(argv[3]) : 1.0;
d1 = (argc >= 5)? atof(argv[4]) : 2.0;
usf1 = (unsigned short) f1;
usd1 = (unsigned short) d1;
uif1 = (unsigned int) f1;
uid1 = (unsigned int) d1;
ulf1 = (unsigned long) f1;
uld1 = (unsigned long) d1;
ssf1 = (short) f1;
ssd1 = (short) d1;
sif1 = (int) f1;
sid1 = (int) d1;
slf1 = (long) f1;
sld1 = (long) d1;
printf("usf1 = %u\n", usf1);
printf("usd1 = %u\n", usd1);
printf("uif1 = %u\n", uif1);
printf("uid1 = %u\n", uid1);
printf("ulf1 = %u\n", ulf1);
printf("uld1 = %u\n", uld1);
printf("ssf1 = %d\n", ssf1);
printf("ssd1 = %d\n", ssd1);
printf("sif1 = %d\n", sif1);
printf("sid1 = %d\n", sid1);
printf("slf1 = %d\n", slf1);
printf("sld1 = %d\n", sld1);
return 0;
}

View File

@ -0,0 +1,9 @@
// RUN: %clang_cc1 -emit-llvm %s -o /dev/null
extern void start() __asm__("start");
extern void _start() __asm__("_start");
extern void __start() __asm__("__start");
void start() {}
void _start() {}
void __start() {}

View File

@ -0,0 +1,10 @@
// RUN: %clang_cc1 -emit-llvm %s -o /dev/null
#include <setjmp.h>
sigjmp_buf B;
int foo() {
sigsetjmp(B, 1);
bar();
}

View File

@ -0,0 +1,10 @@
// RUN: %clang_cc1 -emit-llvm %s -o /dev/null
struct foo {
unsigned int I:1;
unsigned char J[1];
unsigned int K:1;
};
void test(struct foo *X) {}

View File

@ -0,0 +1,9 @@
// RUN: %clang_cc1 -emit-llvm %s -o /dev/null
struct foo {
unsigned int I:1;
unsigned char J[1][123];
unsigned int K:1;
};
struct foo F;

View File

@ -0,0 +1,30 @@
// RUN: %clang_cc1 -w -emit-llvm %s -o /dev/null
typedef struct BF {
int A : 1;
char B;
int C : 13;
} BF;
char *test1(BF *b) {
return &b->B; // Must be able to address non-bitfield
}
void test2(BF *b) { // Increment and decrement operators
b->A++;
--b->C;
}
void test3(BF *b) {
b->C = 12345; // Store
}
int test4(BF *b) {
return b->C; // Load
}
void test5(BF *b, int i) { // array ref
b[i].C = 12345;
}

View File

@ -0,0 +1,8 @@
// RUN: %clang_cc1 -emit-llvm %s -o /dev/null
extern int A[10];
void Func(int *B) {
B - &A[5];
}

View File

@ -0,0 +1,5 @@
// RUN: %clang_cc1 %s -emit-llvm -o - | grep getelementptr
int *test(int *X, int Y) {
return X + Y;
}

View File

@ -0,0 +1,8 @@
// RUN: %clang_cc1 -emit-llvm %s -o /dev/null
void bar () {
static char x[10];
static char *xend = x + 10;
}

View File

@ -0,0 +1,14 @@
// RUN: %clang_cc1 -std=gnu89 -emit-llvm %s -o /dev/null
extern __inline long int
__strtol_l (int a)
{
return 0;
}
long int
__strtol_l (int a)
{
return 0;
}

View File

@ -0,0 +1,23 @@
// RUN: %clang_cc1 -emit-llvm %s -o /dev/null
int code[]={0,0,0,0,1};
void foo(int x) {
volatile int b;
b = 0xffffffff;
}
void bar(int *pc) {
static const void *l[] = {&&lab0, &&end};
foo(0);
goto *l[*pc];
lab0:
foo(0);
pc++;
goto *l[*pc];
end:
return;
}
int main() {
bar(code);
return 0;
}

View File

@ -0,0 +1,10 @@
// RUN: %clang_cc1 %s -emit-llvm -o - | not grep {foo\\* sub}
// This should not produce a subtrace constantexpr of a pointer
struct foo {
int Y;
char X[100];
} F;
int test(char *Y) {
return Y - F.X;
}

View File

@ -0,0 +1,14 @@
// RUN: %clang_cc1 -std=c99 %s -emit-llvm -o - | \
// RUN: opt -std-compile-opts -disable-output
// PR580
int X, Y;
int foo() {
int i;
for (i=0; i<100; i++ )
{
break;
i = ( X || Y ) ;
}
}

View File

@ -0,0 +1,10 @@
// PR947
// RUN: %clang_cc1 %s -emit-llvm -o -
void foo() {
void *ptr;
label:
ptr = &&label;
goto *ptr;
}

View File

@ -0,0 +1,16 @@
// RUN: %clang_cc1 %s -emit-llvm -o -
enum {
tA = 0,
tB = 1
};
struct MyStruct {
unsigned long A;
void * B;
};
void bar(){
struct MyStruct MS = { tB, 0 };
}

View File

@ -0,0 +1,12 @@
// RUN: %clang_cc1 %s -emit-llvm -o /dev/null
struct X {
unsigned int e0 : 17;
unsigned int e1 : 17;
unsigned int e2 : 17;
unsigned int e3 : 17;
unsigned int e4 : 17;
unsigned int e5 : 17;
unsigned int e6 : 17;
unsigned int e7 : 17;
} __attribute__((packed)) x;

View File

@ -0,0 +1,11 @@
// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
// PR1352
struct foo {
int x;
};
void copy(volatile struct foo *p, struct foo *q) {
// CHECK: call void @llvm.memcpy
*p = *q;
}

View File

@ -0,0 +1,17 @@
// RUN: %clang_cc1 -emit-llvm %s -o /dev/null
static char *str;
static const struct {
const char *name;
unsigned type;
} scan_special[] = {
{"shift", 1},
{0, 0}
};
static void
sb(void)
{
while (*str == ' ' || *str == '\t')
str++;
}

View File

@ -0,0 +1,5 @@
// RUN: %clang_cc1 -emit-llvm -g %s -o /dev/null
static unsigned char out[]={0,1};
static const unsigned char str1[]="1";

View File

@ -0,0 +1,13 @@
// RUN: %clang_cc1 -O2 -emit-llvm %s -o - | grep call
static int bar(int x, int y) __attribute__((noinline));
static int bar(int x, int y)
{
return x + y;
}
int foo(int a, int b) {
return bar(b, a);
}

View File

@ -0,0 +1,10 @@
// RUN: %clang_cc1 -O1 -emit-llvm %s -o - | grep icmp
// PR1678
extern void B (void);
static __typeof(B) A __attribute__ ((__weakref__("B")));
int active (void)
{
static void *const p = __extension__ (void *) &A;
return p != 0;
}

View File

@ -0,0 +1,23 @@
// RUN: %clang_cc1 %s -Os -emit-llvm -g -o - | grep DW_TAG_structure_type | count 1
// Variable 'a' is optimized but the debug info should preserve its type info.
#include <stdlib.h>
struct foo {
int Attribute;
};
void *getfoo(void) __attribute__((noinline));
void *getfoo(void)
{
int *x = malloc(sizeof(int));
*x = 42;
return (void *)x;
}
int main(int argc, char *argv[]) {
struct foo *a = (struct foo *)getfoo();
return a->Attribute;
}

View File

@ -0,0 +1,24 @@
// RUN: %clang_cc1 %s -emit-llvm -triple i386-apple-darwin -o - | FileCheck %s
extern void abort();
extern void exit(int);
struct T
{
unsigned i:8;
unsigned c:24;
};
f(struct T t)
{
struct T s[1];
s[0]=t;
return(char)s->c;
}
main()
{
// CHECK: getelementptr inbounds [1 x %struct.T]* %s, i32 0, i32 0
// CHECK: getelementptr inbounds [1 x %struct.T]* %s, i32 0, i32 0
struct T t;
t.i=0xff;
t.c=0xffff11;
if(f(t)!=0x11)abort();
exit(0);
}

View File

@ -0,0 +1,15 @@
// RUN: %clang_cc1 -emit-llvm -o - -triple i386-apple-darwin -Os %s | FileCheck %s
// PR9571
struct t {
int x;
};
extern struct t *cfun;
int f(void) {
if (!(cfun + 0))
// CHECK: icmp eq %struct.t* %tmp, null
return 0;
return cfun->x;
}

View File

@ -0,0 +1,172 @@
// Test frontend handling of __sync builtins.
// Modified from a gcc testcase.
// RUN: %clang_cc1 -emit-llvm %s -o - | grep atomic | count 129
// RUN: %clang_cc1 -emit-llvm %s -o - | grep p0i8 | count 43
// RUN: %clang_cc1 -emit-llvm %s -o - | grep p0i16 | count 43
// RUN: %clang_cc1 -emit-llvm %s -o - | grep p0i32 | count 43
// RUN: %clang_cc1 -emit-llvm %s -o - | grep volatile | count 6
// Currently this is implemented only for Alpha, X86, PowerPC.
// Add your target here if it doesn't work.
// This version of the test does not include long long.
// XFAIL: sparc,arm
signed char sc;
unsigned char uc;
signed short ss;
unsigned short us;
signed int si;
unsigned int ui;
void test_op_ignore (void)
{
(void) __sync_fetch_and_add (&sc, 1);
(void) __sync_fetch_and_add (&uc, 1);
(void) __sync_fetch_and_add (&ss, 1);
(void) __sync_fetch_and_add (&us, 1);
(void) __sync_fetch_and_add (&si, 1);
(void) __sync_fetch_and_add (&ui, 1);
(void) __sync_fetch_and_sub (&sc, 1);
(void) __sync_fetch_and_sub (&uc, 1);
(void) __sync_fetch_and_sub (&ss, 1);
(void) __sync_fetch_and_sub (&us, 1);
(void) __sync_fetch_and_sub (&si, 1);
(void) __sync_fetch_and_sub (&ui, 1);
(void) __sync_fetch_and_or (&sc, 1);
(void) __sync_fetch_and_or (&uc, 1);
(void) __sync_fetch_and_or (&ss, 1);
(void) __sync_fetch_and_or (&us, 1);
(void) __sync_fetch_and_or (&si, 1);
(void) __sync_fetch_and_or (&ui, 1);
(void) __sync_fetch_and_xor (&sc, 1);
(void) __sync_fetch_and_xor (&uc, 1);
(void) __sync_fetch_and_xor (&ss, 1);
(void) __sync_fetch_and_xor (&us, 1);
(void) __sync_fetch_and_xor (&si, 1);
(void) __sync_fetch_and_xor (&ui, 1);
(void) __sync_fetch_and_and (&sc, 1);
(void) __sync_fetch_and_and (&uc, 1);
(void) __sync_fetch_and_and (&ss, 1);
(void) __sync_fetch_and_and (&us, 1);
(void) __sync_fetch_and_and (&si, 1);
(void) __sync_fetch_and_and (&ui, 1);
}
void test_fetch_and_op (void)
{
sc = __sync_fetch_and_add (&sc, 11);
uc = __sync_fetch_and_add (&uc, 11);
ss = __sync_fetch_and_add (&ss, 11);
us = __sync_fetch_and_add (&us, 11);
si = __sync_fetch_and_add (&si, 11);
ui = __sync_fetch_and_add (&ui, 11);
sc = __sync_fetch_and_sub (&sc, 11);
uc = __sync_fetch_and_sub (&uc, 11);
ss = __sync_fetch_and_sub (&ss, 11);
us = __sync_fetch_and_sub (&us, 11);
si = __sync_fetch_and_sub (&si, 11);
ui = __sync_fetch_and_sub (&ui, 11);
sc = __sync_fetch_and_or (&sc, 11);
uc = __sync_fetch_and_or (&uc, 11);
ss = __sync_fetch_and_or (&ss, 11);
us = __sync_fetch_and_or (&us, 11);
si = __sync_fetch_and_or (&si, 11);
ui = __sync_fetch_and_or (&ui, 11);
sc = __sync_fetch_and_xor (&sc, 11);
uc = __sync_fetch_and_xor (&uc, 11);
ss = __sync_fetch_and_xor (&ss, 11);
us = __sync_fetch_and_xor (&us, 11);
si = __sync_fetch_and_xor (&si, 11);
ui = __sync_fetch_and_xor (&ui, 11);
sc = __sync_fetch_and_and (&sc, 11);
uc = __sync_fetch_and_and (&uc, 11);
ss = __sync_fetch_and_and (&ss, 11);
us = __sync_fetch_and_and (&us, 11);
si = __sync_fetch_and_and (&si, 11);
ui = __sync_fetch_and_and (&ui, 11);
}
void test_op_and_fetch (void)
{
sc = __sync_add_and_fetch (&sc, uc);
uc = __sync_add_and_fetch (&uc, uc);
ss = __sync_add_and_fetch (&ss, uc);
us = __sync_add_and_fetch (&us, uc);
si = __sync_add_and_fetch (&si, uc);
ui = __sync_add_and_fetch (&ui, uc);
sc = __sync_sub_and_fetch (&sc, uc);
uc = __sync_sub_and_fetch (&uc, uc);
ss = __sync_sub_and_fetch (&ss, uc);
us = __sync_sub_and_fetch (&us, uc);
si = __sync_sub_and_fetch (&si, uc);
ui = __sync_sub_and_fetch (&ui, uc);
sc = __sync_or_and_fetch (&sc, uc);
uc = __sync_or_and_fetch (&uc, uc);
ss = __sync_or_and_fetch (&ss, uc);
us = __sync_or_and_fetch (&us, uc);
si = __sync_or_and_fetch (&si, uc);
ui = __sync_or_and_fetch (&ui, uc);
sc = __sync_xor_and_fetch (&sc, uc);
uc = __sync_xor_and_fetch (&uc, uc);
ss = __sync_xor_and_fetch (&ss, uc);
us = __sync_xor_and_fetch (&us, uc);
si = __sync_xor_and_fetch (&si, uc);
ui = __sync_xor_and_fetch (&ui, uc);
sc = __sync_and_and_fetch (&sc, uc);
uc = __sync_and_and_fetch (&uc, uc);
ss = __sync_and_and_fetch (&ss, uc);
us = __sync_and_and_fetch (&us, uc);
si = __sync_and_and_fetch (&si, uc);
ui = __sync_and_and_fetch (&ui, uc);
}
void test_compare_and_swap (void)
{
sc = __sync_val_compare_and_swap (&sc, uc, sc);
uc = __sync_val_compare_and_swap (&uc, uc, sc);
ss = __sync_val_compare_and_swap (&ss, uc, sc);
us = __sync_val_compare_and_swap (&us, uc, sc);
si = __sync_val_compare_and_swap (&si, uc, sc);
ui = __sync_val_compare_and_swap (&ui, uc, sc);
ui = __sync_bool_compare_and_swap (&sc, uc, sc);
ui = __sync_bool_compare_and_swap (&uc, uc, sc);
ui = __sync_bool_compare_and_swap (&ss, uc, sc);
ui = __sync_bool_compare_and_swap (&us, uc, sc);
ui = __sync_bool_compare_and_swap (&si, uc, sc);
ui = __sync_bool_compare_and_swap (&ui, uc, sc);
}
void test_lock (void)
{
sc = __sync_lock_test_and_set (&sc, 1);
uc = __sync_lock_test_and_set (&uc, 1);
ss = __sync_lock_test_and_set (&ss, 1);
us = __sync_lock_test_and_set (&us, 1);
si = __sync_lock_test_and_set (&si, 1);
ui = __sync_lock_test_and_set (&ui, 1);
__sync_synchronize ();
__sync_lock_release (&sc);
__sync_lock_release (&uc);
__sync_lock_release (&ss);
__sync_lock_release (&us);
__sync_lock_release (&si);
__sync_lock_release (&ui);
}

View File

@ -0,0 +1,12 @@
// RUN: %clang_cc1 -emit-llvm %s -o - -O | not grep alloca
// PR2094
int sad16_sse2(void *v, unsigned char *blk2, unsigned char *blk1,
int stride, int h) {
int ret;
asm volatile( "%0 %1 %2 %3"
: "+r" (h), "+r" (blk1), "+r" (blk2)
: "r" ((long)stride));
asm volatile("set %0 %1" : "=r"(ret) : "r"(blk1));
return ret;
}

View File

@ -0,0 +1,9 @@
// RUN: %clang_cc1 %s -emit-llvm -O0 -o - | grep sret | count 2
struct abc {
long a;
long b;
long c;
};
struct abc foo2(){}