move mini test set to dsource.org/projects/dstress

This commit is contained in:
Moritz Warning
2011-01-10 19:49:05 +01:00
parent f48f98c474
commit 6d7fe4d1c3
396 changed files with 0 additions and 8829 deletions

View File

@@ -1,22 +0,0 @@
import ldc.llvmasm;
void main() {
version(X86)
{
int i;
__asm("movl $1, $0", "=*m,i", &i, 42);
assert(i == 42);
int j = __asm!(int)("movl $1, %eax", "={ax},i", 42);
assert(j == 42);
auto k = __asmtuple!(int,int)("mov $2, %eax ; mov $3, %edx", "={ax},={dx},i,i", 10, 20);
assert(k.v[0] == 10);
assert(k.v[1] == 20);
}
else version(PPC)
{
int j = 42;
int i = __asm!(int)("li $1, $0", "=r,*m", &j);
assert(i == 42);
}
}

View File

@@ -1,23 +0,0 @@
module a;
extern(C) int printf(char*, ...);
int i = 42;
void main()
{
int j;
j = i;
int* p;
p = &j;
int k = *p;
assert(k == 42);
byte b = -1;
int i = b;
assert(i == -1);
int* p2 = p;
printf("Done\n");
}

View File

@@ -1,34 +0,0 @@
class Foo
{
this(int j)
{
i = pi = j;
}
int i;
private:
int pi;
}
class Bar : Foo
{
this(int j)
{
super(j);
baz = 42;
}
int baz;
}
void func()
{
auto bar = new Bar(12);
}
void main()
{
func();
}

View File

@@ -1,15 +0,0 @@
module aa1;
void main()
{
int[int] aai;
assert(aai is null);
aai[0] = 52;
assert(aai !is null);
int i = aai[0];
assert(i == 52);
aai[32] = 123;
int j = aai[32];
assert(i == 52);
assert(j == 123);
}

View File

@@ -1,21 +0,0 @@
module tangotests.aa1_1;
extern(C) int printf(char*,...);
void main()
{
int[int] map;
map[1] = 1;
map[10] = 1;
map[11] = 11;
map[14] = 41;
map[21] = 12;
map[23] = 32;
map[32] = 23;
map[201] = 102;
foreach(k,v; map)
{
printf("%d:%d ", k,v);
}
printf("\n");
}

View File

@@ -1,12 +0,0 @@
module aa2;
void main()
{
long[float] aa;
long* p = 2.0f in aa;
assert(!p);
aa[4f] = 23;
p = 4f in aa;
assert(p);
assert(*p == 23);
}

View File

@@ -1,12 +0,0 @@
module tangotests.aa2_1;
int main()
{
int[cdouble] x;
cdouble d=22.0+0.0i;
x[d] = 44;
if(44 != x[d]){
assert(0);
}
return 0;
}

View File

@@ -1,27 +0,0 @@
module aa3;
extern(C) int printf(char*, ...);
alias char[] string;
void main()
{
int[string] aa;
{aa["hello"] = 1;}
{int* p = "" in aa;}
aa[" worl"] = 2;
aa["d"] = 3;
aa["thisisgreat"] = 10;
int sum;
string cat;
{
foreach(k,v;aa)
{
printf("int[%.*s] = %d\n", k.length, k.ptr, v);
sum += v;
cat ~= k;
}
}
assert(sum == 16);
printf("cat = %.*s\n", cat.length, cat.ptr);
assert(cat.length == 22);
}

View File

@@ -1,20 +0,0 @@
module aa4;
void main()
{
int[int] aa;
aa = addkey(aa,42,12);
int* p = haskey(aa,42);
assert(p && *p == 12);
}
int[int] addkey(int[int] aa, int key, int val)
{
aa[key] = val;
return aa;
}
int* haskey(int[int] aa, int key)
{
return key in aa;
}

View File

@@ -1,9 +0,0 @@
module aa5;
void main()
{
int[int] aa;
aa[42] = 1;
int i = aa[42];
assert(i == 1);
}

View File

@@ -1,27 +0,0 @@
module aa6;
extern(C) int printf(char*, ...);
void main()
{
int[int] aa;
aa = [1:1, 2:4, 3:9, 4:16];
printf("---\n");
foreach(int k, int v; aa)
printf("aa[%d] = %d\n", k, v);
aa.rehash;
printf("---\n");
foreach(int k, int v; aa)
printf("aa[%d] = %d\n", k, v);
size_t n = aa.length;
assert(n == 4);
int[] keys = aa.keys;
assert(keys[] == [1,2,3,4][]);
int[] vals = aa.values;
assert(vals[] == [1,4,9,16][]);
aa.remove(3);
printf("---\n");
foreach(int k, int v; aa)
printf("aa[%d] = %d\n", k, v);
assert(aa.length == 3);
}

View File

@@ -1,20 +0,0 @@
// adapted from dstress.run.a.associative_array_19_<n> to catch regressions early
module mini.aa7;
extern (C) int printf(char*, ...);
extern (C) void gc_collect();
int main(){
char*[char] aa;
char key = 'a';
aa[key] = &key;
gc_collect();
assert(aa[key] == &key);
assert(key in aa);
return 0;
}

View File

@@ -1,48 +0,0 @@
void test(K,V)(K k1, V v1, K k2, V v2, K k3, V v3)
{
V[K] a, b;
a[k1] = v1;
a[k2] = v2;
assert(a != b);
assert(b != a);
assert(a == a);
assert(b == b);
b[k1] = v1;
assert(a != b);
assert(b != a);
b[k2] = v2;
assert(a == b);
assert(b == a);
b[k1] = v2;
assert(a != b);
assert(b != a);
b[k1] = v1;
b[k2] = v3;
assert(a != b);
assert(b != a);
b[k2] = v2;
b[k3] = v3;
assert(a != b);
assert(b != a);
}
void main()
{
test!(int,int)(1, 2, 3, 4, 5, 6);
test!(char[],int)("abc", 2, "def", 4, "geh", 6);
test!(int,char[])(1, "abc", 2, "def", 3, "geh");
test!(char[],char[])("123", "abc", "456", "def", "789", "geh");
Object a = new Object, b = new Object, c = new Object;
test!(Object, Object)(a, a, b, b, c, c);
int[int] a2 = [1:2, 2:3, 3:4];
int[int] b2 = [1:2, 2:5, 3:4];
int[int] c2 = [1:2, 2:3];
test!(int,int[int])(1,a2, 2,b2, 3,c2);
}

View File

@@ -1,19 +0,0 @@
module tangotests.align1;
extern(C) int printf(char*, ...);
struct TLA
{
char[3] tla;
char[] toString() { return tla; }
void dump()
{
printf("%.*s\n", 3, tla.ptr);
}
}
void main()
{
TLA fbi = TLA("FBI");
fbi.dump();
}

View File

@@ -1,21 +0,0 @@
module alignment;
align(1) struct S
{
ubyte b;
int i;
ubyte[2] b2;
long l;
real r;
}
void main()
{
byte b;
short s;
int i;
long l;
float f;
double d;
real r;
}

View File

@@ -1,16 +0,0 @@
module alloca1;
pragma(alloca) void* alloca(uint);
extern(C) int printf(char*, ...);
void main()
{
int n = 16;
int* p = cast(int*)alloca(n*int.sizeof);
int[] a = p[0..n];
a[] = 0;
foreach(i,v; a) {
printf("a[%2d] = %d\n", i, v);
}
}

View File

@@ -1,3 +0,0 @@
bool ok = false;
void f(){ ok = true; } void main() { bool b=true; b && f(); assert(ok); }

View File

@@ -1,10 +0,0 @@
module arrayinit;
float[4] ftable = [1,2,3,4];
int[8] itable = [3:42,6:123];
private uint[7] crc32_table = [0x00000000,0x77073096,0xee0e612c,0x990951ba,0x076dc419,0x706af48f,0xe963a535];
void main()
{
assert(crc32_table[3] == 0x990951ba);
}

View File

@@ -1,8 +0,0 @@
void main()
{
float m[4][4];
float* fp = &m[0][0];
for (int i=0; i<16; i++,fp++)
assert(*fp !<>= 0);
}

View File

@@ -1,10 +0,0 @@
// bug #191
int[3] a = [0: 0, 2: 42, 1: 1];
void main()
{
assert(a[0] == 0);
assert(a[1] == 1); // fails!
assert(a[2] == 42);
}

View File

@@ -1,17 +0,0 @@
extern(C) int printf(char*, ...);
void main()
{
int[3] a = [1, 2, 3];
int[3] b = [4, 5, 6];
int[3] c;
c[] = a[] + b[];
printf("c.ptr = %p\n", c.ptr);
printf("c.length = %lu\n", c.length);
assert(c[0] == 5);
assert(c[1] == 7);
assert(c[2] == 9);
}

View File

@@ -1,10 +0,0 @@
void main()
{
int[4] a = [1,2,3,4];
int[4] b = [5,6,7,8];
a[] += b[];
assert(a[0] == 6);
assert(a[1] == 8);
assert(a[2] == 10);
assert(a[3] == 12);
}

View File

@@ -1,10 +0,0 @@
void main()
{
int[4] a = [1,2,3,4];
int[4] b = [5,6,7,8];
a[] += b[] / 2;
assert(a[0] == 3);
assert(a[1] == 5);
assert(a[2] == 6);
assert(a[3] == 8);
}

View File

@@ -1,29 +0,0 @@
void main()
{
auto a = new float[1024];
auto b = new float[1024];
auto c = new float[1024];
for (auto i=0; i<1024; i++)
{
a[i] = i;
b[i] = i*2;
c[i] = i*4;
}
a[] = b[] + c[] / 2;
foreach(i,v; a)
{
assert(eq(v, b[i] + c[i] / 2));
}
}
float abs(float x)
{
return x<0?-x:x;
}
bool eq(float a, float b)
{
return abs(a-b) <= float.epsilon;
}

View File

@@ -1,43 +0,0 @@
module arrays1;
extern(C) int printf(char*, ...);
void integer()
{
auto arr = new int[16];
arr[1] = 42;
arr[6] = 555;
print_int(arr);
delete arr;
}
void floating()
{
auto arr = new float[6];
arr[1] = 3.14159265;
arr[3] = 1.61803399;
print_float(arr);
delete arr;
}
void print_int(int[] arr)
{
printf("arr[%lu] = [", arr.length);
for (auto i=0; i<arr.length; i++)
printf("%d,", arr[i]);
printf("\b]\n");
}
void print_float(float[] arr)
{
printf("arr[%lu] = [", arr.length);
for (auto i=0; i<arr.length; i++)
printf("%f,", arr[i]);
printf("\b]\n");
}
void main()
{
integer();
floating();
}

View File

@@ -1,7 +0,0 @@
module arrays10;
void main()
{
int[] a = new int[10];
a[] = 3;
}

View File

@@ -1,51 +0,0 @@
module arrays11;
void ints()
{
int[] a = [1,2,3,4,5,6];
{assert(a == a);}
int[] b = [4,5,6,7,8,9];
{assert(a != b);}
{assert(a[3..$] == b[0..3]);}
}
void floats()
{
float[] a = [1.0f, 2.0f, 3.0f, 4.0f];
{assert(a == a);}
float[] b = [2.0f, 3.0f, 5.0f];
{assert(a != b);}
{assert(a[1..3] == b[0..2]);}
}
struct S
{
int i;
int j;
int opEquals(S s)
{
return (i == s.i) && (j == s.j);
}
}
void structs()
{
S[] a = [S(0,0), S(1,0), S(2,0), S(3,0)];
{assert(a == a);}
S[] b = [S(0,1), S(1,0), S(2,0), S(3,1)];
{assert(a != b);}
{assert(a[1..3] == b[1..3]);}
S[2] c = [S(2,0), S(3,1)];
{assert(c == b[2..$]);}
}
void main()
{
ints();
floats();
structs();
}

View File

@@ -1,19 +0,0 @@
module arrays12;
void ints()
{
int[3] a = [1,2,3];
int[3] b = [2,3,4];
int[3] c = [2,5,0];
{assert(a < b);}
{assert(b > a);}
{assert(a < c);}
{assert(c > a);}
{assert(b < c);}
{assert(c > b);}
}
void main()
{
ints();
}

View File

@@ -1,18 +0,0 @@
module arrays13;
extern(C) int printf(char*, ...);
void main()
{
char[] a = "hello";
assert(a > "hel");
assert(a >= "hel");
assert(a < "helloo");
assert(a <= "helloo");
assert(a > "betty");
assert(a >= "betty");
assert(a == "hello");
assert(a <= "hello");
assert(a >= "hello");
}

View File

@@ -1,7 +0,0 @@
module arrays14;
void main()
{
auto s = "hello world";
auto d = s.dup;
}

View File

@@ -1,30 +0,0 @@
module mini.arrays16;
void main()
{
intarrays!(byte)();
intarrays!(ubyte)();
intarrays!(short)();
intarrays!(ushort)();
intarrays!(int)();
intarrays!(uint)();
intarrays!(long)();
intarrays!(ulong)();
}
void intarrays(T)()
{
T[] ia = [cast(T)1,2,3,4];
T[] ib = [cast(T)1,2,3,4];
T[] ic = [cast(T)1,2,3];
T[] id = [cast(T)1,2,3,4,5];
assert(ia == ia);
assert(ia == ib);
assert(ia != ic);
assert(ia != id);
assert(ia > ic);
assert(ia !< ic);
assert(ia < id);
assert(ia !> id);
}

View File

@@ -1,6 +0,0 @@
module mini.arrays17;
void main()
{
const char[2][2] id = [1: "ab"];
}

View File

@@ -1,27 +0,0 @@
module mini.arrays18;
struct Str { int a,b; }
void main() {
Str[] arr = new Str[64];
auto tmp = Str(1,2);
arr[] = tmp;
assert(arr[0].a == 1);
assert(arr[0].b == 2);
assert(arr[13].a == 1);
assert(arr[13].b == 2);
assert(arr[42].a == 1);
assert(arr[42].b == 2);
assert(arr[63].a == 1);
assert(arr[63].b == 2);
arr[] = Str(3,4);
assert(arr[0].a == 3);
assert(arr[0].b == 4);
assert(arr[13].a == 3);
assert(arr[13].b == 4);
assert(arr[42].a == 3);
assert(arr[42].b == 4);
assert(arr[63].a == 3);
assert(arr[63].b == 4);
}

View File

@@ -1,9 +0,0 @@
module mini.arrays19;
extern(C) int printf(char*, ...);
void main()
{
bool var = ([] is null);
assert(var);
}

View File

@@ -1,19 +0,0 @@
char[] get()
{
return "hello";
}
void param(char[] s)
{
}
void refparam(ref char[] s)
{
}
void main()
{
char[] dstr = get();
param(dstr);
refparam(dstr);
}

View File

@@ -1,23 +0,0 @@
module mini.arrays20;
int[] foo()
{
return [2,4,6];
}
int[] bar()
{
return [1,3,5];
}
void main()
{
auto a = foo();
auto b = bar();
assert(b[0] == 1);
assert(a[0] == 2);
assert(b[1] == 3);
assert(a[1] == 4);
assert(b[2] == 5);
assert(a[2] == 6);
}

View File

@@ -1,10 +0,0 @@
module arrays3;
void main()
{
int[] arr;
{arr = new int[25];}
{assert(arr.length == 25);}
{arr.length = arr.length + 5;}
{assert(arr.length == 30);}
}

View File

@@ -1,13 +0,0 @@
module arrays4;
void main()
{
int[] arr;
arr ~= 3;
assert(arr.length == 1);
assert(arr[0] == 3);
arr ~= 5;
assert(arr.length == 2);
assert(arr[0] == 3);
assert(arr[1] == 5);
}

View File

@@ -1,11 +0,0 @@
module arrays5;
void main()
{
auto arr = new float[5];
{arr[4] = 1f;}
{assert(arr[0] !<>= 0f);}
{assert(arr[1] !<>= 0f);}
{assert(arr[2] !<>= 0f);}
{assert(arr[3] !<>= 0f);}
{assert(arr[4] == 1f);}
}

View File

@@ -1,6 +0,0 @@
module arrays6;
void main()
{
int[4] a = [1,2,3,4];
}

View File

@@ -1,31 +0,0 @@
module arrays7;
extern(C) int printf(char*, ...);
struct S
{
int i;
float f;
long l;
void print()
{
printf("%d %f %lx\n", i, f, l);
}
}
void main()
{
S[] arr;
S s;
assert(arr.length == 0);
arr ~= s;
assert(arr.length == 1);
arr ~= S(1,2.64,0xFFFF_FFFF_FFFF);
assert(arr.length == 2);
arr[0].print();
arr[1].print();
assert(arr[1].i == 1);
assert(arr[1].f > 2.63 && arr[1].f < 2.65);
assert(arr[1].l == 0xFFFF_FFFF_FFFF);
}

View File

@@ -1,19 +0,0 @@
module arrays8;
extern(C) int printf(char*, ...);
void main()
{
char[] a = "hello ";
printf(" \"%s\".length = %u\n", a.ptr, a.length);
char[] b = "world";
printf(" \"%s\".length = %u\n", b.ptr, b.length);
char[] c = a ~ b;
printf("After 'a ~ b':\n");
printf(" \"%.*s\".length = %u\n", a.length, a.ptr, a.length);
printf(" \"%.*s\".length = %u\n", b.length, b.ptr, b.length);
printf(" \"%.*s\".length = %u\n", c.length, c.ptr, c.length);
assert(c.length == a.length + b.length);
assert(c !is a);
assert(c !is b);
}

View File

@@ -1,8 +0,0 @@
module arrays9;
const int[] g = [1,2,3,4];
void main()
{
}

View File

@@ -1,31 +0,0 @@
module asm1;
extern(C) int printf(char*, ...);
void main()
{
version(D_InlineAsm_X86)
{
int x;
asm
{
mov EAX, 42;
mov x, EAX;
}
printf("x = %d\n", x);
}
else version(D_InlineAsm_X86_64)
{
long x;
asm
{
movq RAX, 42L;
movq x, RAX;
}
printf("x = %ld\n", x);
}
else
{
static assert(0, "no inline asm for this platform yet");
}
}

View File

@@ -1,31 +0,0 @@
module asm10;
struct S {
ushort first;
ushort second;
int unaccessed;
}
void main() {
auto s = S(512, 42, -1);
ushort x = 0;
version(D_InlineAsm_X86) {
asm {
lea EAX, s;
mov CX, S.second[EAX];
mov x, CX;
mov S.first[EAX], 640;
}
} else version(D_InlineAsm_X86_64) {
asm {
lea RAX, s;
mov CX, S.second[RAX];
mov x, CX;
mov S.first[RAX], 640;
}
}
assert(x == 42);
assert(s.first == 640);
assert(s.second == 42);
assert(s.unaccessed == -1);
}

View File

@@ -1,35 +0,0 @@
module tangotests.asm1_1;
extern(C) int printf(char*, ...);
int main()
{
int i = 12;
int* ip = &i;
printf("%d\n", i);
version (D_InlineAsm_X86)
{
asm
{
mov ECX, ip;
mov EAX, [ECX];
add EAX, 8;
mul EAX, EAX;
mov [ECX], EAX;
}
}
else version (D_InlineAsm_X86_64)
{
asm
{
movq RCX, ip;
mov EAX, [RCX];
add EAX, 8;
imul EAX, EAX;
mov [RCX], EAX;
}
}
printf("%d\n", i);
assert(i == 400);
return 0;
}

View File

@@ -1,32 +0,0 @@
module tangotests.asm2;
extern(C) int printf(char*, ...);
int main()
{
int i = 40;
int j = 2;
version(D_InlineAsm_X86)
{
asm
{
mov EAX, i;
mov EBX, j;
add EAX, EBX;
mov i, EAX;
}
}
else version(D_InlineAsm_X86_64)
{
asm
{
mov EAX, i;
mov EBX, j;
add EAX, EBX;
mov i, EAX;
}
}
printf("42 = %d\n", i);
assert(i == 42);
return 0;
}

View File

@@ -1,27 +0,0 @@
module tangotests.asm3;
extern(C) int printf(char*, ...);
void main()
{
char* fmt = "Hello D World\n";
printf(fmt);
version (D_InlineAsm_X86)
{
asm
{
push fmt;
call printf;
pop EAX;
}
}
else version(D_InlineAsm_X86_64)
{
asm
{
movq RDI, fmt;
xor AL, AL;
call printf;
}
}
}

View File

@@ -1,41 +0,0 @@
module tangotests.asm4;
extern(C) int printf(char*,...);
void main()
{
char* stmt = "yay!\n";
char* fmt = "%s";
version (D_InlineAsm_X86)
{
asm
{
jmp L2;
L1:;
jmp L3;
L2:;
jmp L1;
L3:;
push stmt;
call printf;
pop EAX;
}
}
else version(D_InlineAsm_X86_64)
{
asm
{
jmp L2;
L1:;
jmp L3;
L2:;
jmp L1;
L3:;
movq RDI, fmt;
movq RSI, stmt;
xor AL, AL;
call printf;
}
}
printf(fmt,stmt);
}

View File

@@ -1,33 +0,0 @@
int foo()
{
version(X86)
{
asm { mov EAX, 42; }
} else version(X86_64)
{
asm { movq RAX, 42; }
}
else static assert(0, "todo");
}
ulong bar()
{
version(X86)
{
asm { mov EAX, 0xFF; mov EDX, 0xAA; }
} else version(X86_64)
{
asm { movq RAX, 0xAA000000FF; }
}
else static assert(0, "todo");
}
void main()
{
long l = 1;
l = 2;
l = 4;
l = 8;
assert(foo() == 42);
assert(bar() == 0xAA000000FF);
}

View File

@@ -1,33 +0,0 @@
extern(C) int printf(char*, ...);
version (D_InlineAsm_X86)
version = InlineAsm_X86_Any;
version (D_InlineAsm_X86_64)
version = InlineAsm_X86_Any;
void main()
{
int a,b,c;
a = int.max-1;
b = 5;
version (InlineAsm_X86_Any)
{
asm
{
mov EAX, a;
mov ECX, b;
add EAX, ECX;
jo Loverflow;
mov c, EAX;
}
}
printf("a == %d\n", a);
printf("b == %d\n", b);
printf("c == %d\n", c);
assert(c == c);
return;
Loverflow:
int y=0;
//assert(0, "overflow");
}

View File

@@ -1,71 +0,0 @@
module tangotests.asm7;
// test massive label collisions (runtime uses Loverflow too)
extern(C) int printf(char*, ...);
void main()
{
int a = add(1,2);
int s = sub(1,2);
assert(a == 3);
assert(s == -1);
}
int add(int a, int b)
{
int res;
version (D_InlineAsm_X86)
{
asm
{
mov EAX, a;
add EAX, b;
jo Loverflow;
mov res, EAX;
}
}
else version (D_InlineAsm_X86_64)
{
asm
{
mov EAX, a;
add EAX, b;
jo Loverflow;
mov res, EAX;
}
}
printf("%d\n",res);
return res;
Loverflow:
assert(0, "add overflow");
}
int sub(int a, int b)
{
int res;
version (D_InlineAsm_X86)
{
asm
{
mov EAX, a;
sub EAX, b;
jo Loverflow;
mov res, EAX;
}
}
else version (D_InlineAsm_X86_64)
{
asm
{
mov EAX, a;
sub EAX, b;
jo Loverflow;
mov res, EAX;
}
}
printf("%d\n",res);
return res;
Loverflow:
assert(0, "sub overflow");
int x;
}

View File

@@ -1,401 +0,0 @@
const float one_f = 1;
const double one_d = 1;
const real one_r = 1;
int foo()
{
version(X86)
{
asm { mov EAX, 42; }
}
else version (X86_64)
{
asm { mov EAX, 42; }
}
else static assert(0, "todo");
}
ulong bar()
{
version(X86)
{
asm { mov EDX, 0xAA; mov EAX, 0xFF; }
}
else version (X86_64)
{
asm { movq RAX, 0xAA000000FF; }
}
else static assert(0, "todo");
}
float onef()
{
version(X86)
{
asm { fld1; }
}
else version (X86_64)
{
asm { movss XMM0, [one_f]; }
}
else static assert(0, "todo");
}
double oned()
{
version(X86)
{
asm { fld1; }
}
else version (X86_64)
{
asm { movsd XMM0, [one_d]; }
}
else static assert(0, "todo");
}
real oner()
{
version(X86)
{
asm { fld1; }
}
else version (X86_64)
{
asm { fld1; }
}
else static assert(0, "todo");
}
ifloat oneif()
{
version(X86)
{
asm { fld1; }
}
else version (X86_64)
{
asm { movss XMM0, [one_f]; }
}
else static assert(0, "todo");
}
idouble oneid()
{
version(X86)
{
asm { fld1; }
}
else version (X86_64)
{
asm { movsd XMM0, [one_d]; }
}
else static assert(0, "todo");
}
ireal oneir()
{
version(X86)
{
asm { fld1; }
}
else version (X86_64)
{
asm { fld1; }
}
else static assert(0, "todo");
}
const float two_f = 2;
cfloat cf()
{
version(X86)
{
asm { fld1; fld two_f; }
}
else version (X86_64)
{
asm
{
movss XMM0, [one_f];
movss XMM1, [two_f];
}
}
else static assert(0, "todo");
}
extern(C) cfloat cf_C()
{
version(X86)
{
asm {
mov EAX, [one_f];
mov EDX, [two_f];
}
}
else version (X86_64)
{
asm {
mov EAX, [one_f];
mov ECX, [two_f];
shl RCX, 32;
or RAX, RCX;
movd XMM0, RAX;
}
}
else static assert(0, "todo");
}
cfloat cf2()
{
version(X86)
{
asm
{
naked;
fld1;
fld two_f;
ret;
}
}
else version (X86_64)
{
asm
{
naked;
movss XMM0, [one_f];
movss XMM1, [two_f];
ret;
}
}
else static assert(0, "todo");
}
extern(C) cfloat cf2_C()
{
version(X86)
{
asm
{
naked;
mov EAX, [one_f];
mov EDX, [two_f];
ret;
}
}
else version (X86_64)
{
asm {
naked;
mov EAX, [one_f];
mov ECX, [two_f];
shl RCX, 32;
or RAX, RCX;
movd XMM0, RAX;
ret;
}
}
else static assert(0, "todo");
}
const double two_d = 2;
cdouble cd()
{
version(X86)
{
asm { fld1; fld two_d; }
}
else version (X86_64)
{
asm
{
leaq RAX, [one_d];
leaq RCX, [two_d];
movsd XMM0, [RAX];
movsd XMM1, [RCX];
}
}
else static assert(0, "todo");
}
cdouble cd2()
{
version(X86)
{
asm
{
naked;
fld1;
fld two_d;
ret;
}
}
else version (X86_64)
{
asm
{
naked;
movsd XMM0, [one_d];
movsd XMM1, [two_d];
}
}
else static assert(0, "todo");
}
const real two_r = 2.0;
creal cr()
{
version(X86)
{
asm { fld1; fld two_r; }
}
else version (X86_64)
{
asm { fld two_r; fld1; }
}
else static assert(0, "todo");
}
creal cr2()
{
version(X86)
{
asm
{
naked;
fld1;
fld two_r;
ret;
}
}
else version (X86_64)
{
asm
{
naked;
fld two_r;
fld1;
ret;
}
}
else static assert(0, "todo");
}
void* vp()
{
version(X86)
{
asm { mov EAX, 0x80; }
}
else version (X86_64)
{
asm { movq RAX, 0x80; }
}
else static assert(0, "todo");
}
int[int] gaa;
int[int] aa()
{
version(X86)
{
asm { mov EAX, gaa; }
}
else version (X86_64)
{
asm { movq RAX, gaa; }
}
else static assert(0, "todo");
}
Object gobj;
Object ob()
{
version(X86)
{
asm { mov EAX, gobj; }
}
else version (X86_64)
{
asm { movq RAX, gobj; }
}
else static assert(0, "todo");
}
char[] ghello = "hello world";
char[] str()
{
version(X86)
{
asm { lea ECX, ghello; mov EAX, [ECX]; mov EDX, [ECX+4]; }
}
else version (X86_64)
{
asm { movq RAX, [ghello]; movq RDX, [ghello]+8; }
}
else static assert(0, "todo");
}
char[] delegate() dg()
{
version(X86)
{
asm { mov EAX, gobj; lea EDX, Object.toString; }
}
else version (X86_64)
{
asm { movq RAX, [gobj]; leaq RDX, Object.toString; }
}
else static assert(0, "todo");
}
void main()
{
gaa[4] = 5;
gobj = new Object;
auto adg = &gobj.toString;
assert(foo() == 42);
assert(bar() == 0xAA000000FF);
assert(onef() == 1);
assert(oned() == 1);
assert(oner() == 1);
assert(oneif() == 1i);
assert(oneid() == 1i);
assert(oneir() == 1i);
assert(cf() == 1+2i);
assert(cf2() == 1+2i);
assert(cf_C() == 1+2i);
assert(cf2_C() == 1+2i);
assert(cd() == 1+2i);
assert(cd2() == 1+2i);
assert(cr() == 1+2i);
assert(cr2() == 1+2i);
assert(vp() == cast(void*)0x80);
assert(aa() is gaa);
assert(ob() is gobj);
assert(str() == "hello world");
assert(dg()() == "object.Object");
}
extern(C) int printf(char*, ...);

View File

@@ -1,28 +0,0 @@
module asm9;
version(X86) version = DoSome;
else version(X86_64) version = DoSome;
T add(T, T t)(T a) {
asm {
add a, t;
}
return a;
}
void main() {
version (DoSome) {
assert(add!(ubyte, 20)(10) == 30);
assert(add!(ushort, 20_000)(10_000) == 30_000);
assert(add!(uint, 2_000_000)(1_000_000) == 3_000_000);
}
version(X86_64) {
// 64-bit immediates aren't allowed on "ADD", nor are
// unsigned 32-bit ones, so make the template parameter
// fit in a 32-bit signed int.
// These values were chosen so that the lower 32-bits overflow
// and we can see the upper half of the 64-bit input increment.
auto result = add!(long, 2_000_000_000)(21_000_000_000);
assert(result == 23_000_000_000);
}
}

View File

@@ -1,23 +0,0 @@
module assign;
// this is taken from std.intrinsic from gdc
int mybtc(uint *p, uint bitnum)
{
uint * q = p + (bitnum / (uint.sizeof*8));
uint mask = 1 << (bitnum & ((uint.sizeof*8) - 1));
int result = *q & mask;
*q ^= mask;
return result ? -1 : 0;
}
void main()
{
uint i = 0xFFFF_FFFF;
int r = mybtc(&i, 31);
assert(r);
assert(i == 0x7FFF_FFFF);
r = mybtc(&i, 31);
assert(!r);
assert(i == 0xFFFF_FFFF);
}

View File

@@ -1,17 +0,0 @@
module mini.assign1;
extern(C) int printf(char*, ...);
struct X
{
int a;
alias a b;
}
void main()
{
X e = void;
e.a = e.b = 5;
printf("%d - %d\n", e.a, e.b);
assert(e.a == 5);
assert(e.a == e.b);
}

View File

@@ -1,12 +0,0 @@
module mini.atomic1;
pragma(intrinsic, "llvm.atomic.swap.i#.p0i#")
T atomic_swap(T)(T* ptr, T val);
void main()
{
int i = 42;
int j = atomic_swap(&i, 43);
assert(j == 42);
assert(i == 43);
}

View File

@@ -1,25 +0,0 @@
module b;
extern(C) int printf(char*, ...);
struct S
{
int i;
float[4] f;
}
void main()
{
S s;
int i = s.i;
int* p = &s.i;
*p = 42;
printf("%d == %d\n", *p, s.i);
float* f = &s.f[0];
printf("%f == %f\n", *f, s.f[0]);
*f = 3.1415;
printf("%f == %f\n", *f, s.f[0]);
s.f[0] = 123.456;
printf("%f == %f\n", *f, s.f[0]);
}

View File

@@ -1,78 +0,0 @@
extern(C) int printf(char*, ...);
void main()
{
printf("Bitwise operations test\n");
{ ushort a = 0xFFF0;
ushort b = 0x0FFF;
assert((a&b) == 0x0FF0);
assert((a|b) == 0xFFFF);
assert((a^b) == 0xF00F);
}
{ ubyte a = 0xFF;
ulong b = 0xFFFF_FFFF_FFFF_FFF0;
assert((a&b) == 0xF0);
}
{ ushort s = 0xFF;
assert((s<<1) == s*2);
assert((s>>>1) == s/2);
}
{ int s = -10;
assert((s>>1) == -5);
assert((s>>>1) != -5);
}
{ ushort a = 0xFFF0;
ushort b = 0x0FFF;
auto t = a;
t &= b;
assert(t == 0x0FF0);
t = a;
t |= b;
assert(t == 0xFFFF);
t = a;
t ^= b;
assert(t == 0xF00F);
}
{ ubyte a = 0xFF;
ulong b = 0xFFFF_FFFF_FFFF_FFF0;
a &= b;
assert(a == 0xF0);
}
{ ushort s = 0xFF;
auto t = s;
t <<= 1;
assert(t == (s*2));
t = s;
t >>>= 1;
assert(t == s/2);
}
{ int s = -10;
auto t = s;
t >>= 1;
assert(t == -5);
t = s;
t >>>= 1;
assert(t != -5);
}
{ struct S
{
uint i;
ulong l;
};
S s = S(1,4);
auto a = s.i | s.l;
assert(a == 5);
s.i = 0xFFFF_00FF;
s.l = 0xFFFF_FFFF_0000_FF00;
s.l ^= s.i;
assert(s.l == ulong.max);
s.i = 0x__FFFF_FF00;
s.l = 0xFF00FF_FF00;
s.i &= s.l;
assert(s.i == 0x00FF_FF00);
}
printf(" SUCCESS\n");
}

View File

@@ -1,7 +0,0 @@
bool got() { return true; }
extern(C) int printf(char*, ...);
void main()
{
bool b = true && got();
printf("%d\n", b ? 1 : 0);
}

View File

@@ -1,5 +0,0 @@
module bug1;
struct Foo { Foo opSub(ref Foo b) { return Foo(); } }
struct Bar { Foo whee; }
void test(ref Bar moo) { Foo nngh; auto plonk = nngh - moo.whee; }
void main() { Bar bar; test(bar); }

View File

@@ -1,24 +0,0 @@
module bug10;
extern(C) int printf(char*, ...);
class C
{
char[] msg;
this()
{
}
this(char[] msg)
{
this.msg = msg;
}
}
void main()
{
auto c = new C();
c.msg = "world";
auto b = new C("hello");
printf("%.*s\n", b.msg.length, b.msg.ptr);
printf("%.*s\n", c.msg.length, c.msg.ptr);
}

View File

@@ -1,12 +0,0 @@
module bug11;
struct S
{
int[4] arr;
}
S s=S([1,2,3,4]);
void main()
{
}

View File

@@ -1,6 +0,0 @@
module bug12;
void main()
{
const char[] name="y";
}

View File

@@ -1,18 +0,0 @@
module bug13;
void func1(ubyte[4]* arr)
{
ubyte* b = &(*arr)[0];
func2(&(*arr)[1]);
}
void func2(ubyte* ptr)
{
assert(*ptr == 2);
}
void main()
{
ubyte[4] arr = [cast(ubyte)1,2,3,4];
func1(&arr);
}

View File

@@ -1,7 +0,0 @@
module bug14;
void main()
{
int[] arr = new int[12];
int i = arr[0];
}

View File

@@ -1,17 +0,0 @@
module bug15;
bool bool1(bool b) {
if (b) return true;
else return false;
}
bool bool2(bool b) {
if (b) {return true;}
else {return false;}
}
void main()
{
assert(bool1(true));
assert(!bool2(false));
}

View File

@@ -1,11 +0,0 @@
module bug16;
void func(long val)
{
val >>= 32;
}
void main()
{
func(64L);
}

View File

@@ -1,18 +0,0 @@
static foocalled = false;
static barcalled = false;
void foo() { foocalled = true; }
void bar() { barcalled = true; }
void f(bool b)
{
return b ? foo() : bar();
}
void main()
{
f(true);
assert(foocalled && !barcalled);
f(false);
assert(foocalled && barcalled);
}

View File

@@ -1,13 +0,0 @@
module bug17;
struct Vec
{
Vec opAdd(ref Vec b) { return Vec(); }
Vec opMul(double a) { return Vec(); }
}
void main()
{
Vec foo;
Vec bar;
auto whee=foo+bar*1f;
}

View File

@@ -1,11 +0,0 @@
module bug18;
struct S {
int[9] i;
}
void main()
{
int[9] i;
auto s = S(i);
}

View File

@@ -1,11 +0,0 @@
interface I {}
class A : I {}
class B : A {}
void main () {
A a = new A;
I i = a;
assert(!cast(B)a);
assert(!cast(B)i);
}

View File

@@ -1,7 +0,0 @@
module bug19;
void main()
{
auto dg = (int i) { return i*2; };
assert(dg(2) == 4);
}

View File

@@ -1,12 +0,0 @@
struct Color {
uint c;
static Color opCall(uint _c) { Color ret; ret.c = _c; return ret; }
}
// run at compile time
static const Color white = Color(0xffffffff);
void main()
{
assert(white.c == 0xffffffff);
}

View File

@@ -1,25 +0,0 @@
struct Color {
uint c;
}
struct Vertex {
double x, y;
Color c;
static Vertex opCall(double x, double y, Color c) {
Vertex ret;
ret.x = x;
ret.y = y;
ret.c = c;
return ret;
}
}
void main() {
Color c = {0xffffffff};
auto v = Vertex(1, 5, c);
assert(v.x == 1 && v.y == 5); // passes
assert(v.c.c == 0xffffffff); // fails in LDC
}

View File

@@ -1,4 +0,0 @@
module bug2;
struct Vec { Vec barf() { return Vec(); } }
class test { this(Vec whee) { } }
void main() { Vec whee; new test(whee.barf()); }

View File

@@ -1,19 +0,0 @@
module bug20;
extern(C) int printf(char*, ...);
void func(void delegate() dg)
{
dg();
}
void main()
{
int i = 42;
void delegate() dg = {
i++;
};
printf("i = %d\n",i);
func(dg);
printf("i = %d\n",i);
assert(i == 43);
}

View File

@@ -1,17 +0,0 @@
module bug21;
extern(C) int printf(char*, ...);
void main()
{
int i = 42;
auto a = {
int j = i*2;
auto b = {
return j;
};
return b();
};
int i2 = a();
printf("%d\n", i2);
assert(i2 == i*2);
}

View File

@@ -1,12 +0,0 @@
module bug22;
extern(C) int printf(char*, ...);
void main()
{
int i;
delegate {
i = 42;
}();
printf("%d\n", i);
assert(i == 42);
}

View File

@@ -1,15 +0,0 @@
module bug23;
extern(C) int printf(char*, ...);
void main()
{
int i;
delegate {
i++;
delegate {
i++;
}();
}();
printf("%d\n", i);
assert(i == 2);
}

View File

@@ -1,22 +0,0 @@
module bug24;
extern(C) int printf(char*, ...);
struct S
{
long l;
float f;
}
void main()
{
S s = S(3L,2f);
delegate {
S t = S(4L, 1f);
delegate {
s.l += t.l;
s.f += t.f;
}();
}();
printf("%lu %f\n", s.l, s.f);
assert(s.l == 7 && s.f == 3);
}

View File

@@ -1,13 +0,0 @@
module bug25;
extern(C) int printf(char*, ...);
void main()
{
int i = 2;
delegate {
i = i*i;
i += i*i;
}();
printf("%d\n", i);
assert(i == 20);
}

View File

@@ -1,17 +0,0 @@
module bug27;
int func(int a, int b)
{
if (a == b)
return 0;
else if (a < b)
return -1;
else
return 1;
}
void main()
{
int i = func(3,4);
assert(i == -1);
}

View File

@@ -1,17 +0,0 @@
module bug28;
void main()
{
char[] a = "hello";
char[] b = "hello";
char[] c = "world";
char[] d = "somethingelse";
assert(a == a);
assert(a == b);
assert(a != c);
assert(b != c);
assert(a != d);
assert(b != d);
assert(c != d);
assert(d == d);
}

View File

@@ -1,16 +0,0 @@
module bug29;
extern(C) int printf(char*, ...);
void main()
{
int[] arr16 = new int[4];
{
void[] arr = arr16;
{
printf("%lu\n", arr.length);
{
assert(arr.length == 16);
}
}
}
}

View File

@@ -1,24 +0,0 @@
module bug3;
struct S
{
int[] arr;
char[5] ch;
}
class C
{
int[] arr;
char[4] crs;
}
void main()
{
S s;
s.arr = new int[5];
s.arr[1] = 32;
int i;
i = s.arr[0];
//assert(s.arr[0] == 0);
//assert(s.arr[1] == 32);
}

View File

@@ -1,22 +0,0 @@
module bug30;
void main()
{
int[] a = new int[4];
{a[0] = 1;
a[1] = 2;
a[2] = 3;
a[3] = 4;}
int[] b = new int[4];
{b[0] = 1;
b[1] = 2;
b[2] = 3;
b[3] = 4;}
int[] c = new int[4];
{c[0] = 1;
c[1] = 2;
c[2] = 4;
c[3] = 3;}
{assert(a == b);}
{assert(a != c);}
}

View File

@@ -1,20 +0,0 @@
extern(C) int printf(char*, ...);
long foo(ref int p) {
try { return 0; }
finally {
p++;
throw new Object;
}
}
void main() {
int p = 0;
try {
foo(p);
assert(0);
} catch {
}
printf("Number of types scope(exit) was executed : %d\n", p);
assert(p == 1);
}

View File

@@ -1,15 +0,0 @@
module bug32;
extern(C) int printf(char*, ...);
struct S
{
char[] getName() { return name; }
char[] name;
}
void main()
{
S s = S("Kyle");
char[] name = s.name;
printf("%.*s\n", name.length, name.ptr);
}

View File

@@ -1,33 +0,0 @@
module bug33;
extern(C) int memcmp(void*,void*,size_t);
private int string_cmp(char[] s1, char[] s2)
{
auto len = s1.length;
if (s2.length < len)
len = s2.length;
int result = memcmp(s1.ptr, s2.ptr, len);
if (result == 0)
result = cast(int)(cast(ptrdiff_t)s1.length - cast(ptrdiff_t)s2.length);
return result;
}
struct S
{
char[] toString()
{
return "S";
}
}
int func()
{
S a,b;
return string_cmp(a.toString(),b.toString());
}
void main()
{
assert(func() == 0);
}

View File

@@ -1,55 +0,0 @@
module bug34;
class MyTypeInfo_Pointer
{
char[] toString() { return m_next.toString() ~ "*"; }
int opEquals(Object o)
{ TypeInfo_Pointer c;
return this is o ||
((c = cast(TypeInfo_Pointer)o) !is null &&
this.m_next == c.m_next);
}
hash_t getHash(void *p)
{
return cast(uint)*cast(void* *)p;
}
int equals(void *p1, void *p2)
{
return cast(int)(*cast(void* *)p1 == *cast(void* *)p2);
}
int compare(void *p1, void *p2)
{
if (*cast(void* *)p1 < *cast(void* *)p2)
return -1;
else if (*cast(void* *)p1 > *cast(void* *)p2)
return 1;
else
return 0;
}
size_t tsize()
{
return (void*).sizeof;
}
void swap(void *p1, void *p2)
{ void* tmp;
tmp = *cast(void**)p1;
*cast(void**)p1 = *cast(void**)p2;
*cast(void**)p2 = tmp;
}
TypeInfo next() { return m_next; }
uint flags() { return 1; }
TypeInfo m_next;
}
void main()
{
}

View File

@@ -1,7 +0,0 @@
module bug35;
private const char[10] digits = "0123456789"; /// 0..9
void main()
{
}

View File

@@ -1,8 +0,0 @@
module bug36;
void main()
{
int[] a;
void* cp = cast(void*)a;
}

View File

@@ -1,7 +0,0 @@
module bug37;
void main()
{
char[] a = "hello";
assert(a !is null);
}

View File

@@ -1,14 +0,0 @@
class A {
class B {
}
}
class C : A {
void test () {
B foo = new B();
}
}
int main () {
return 0;
}

View File

@@ -1,12 +0,0 @@
module bug38;
void func(int* p)
{
p++;
}
void main()
{
int i;
func(&i);
}

View File

@@ -1,13 +0,0 @@
module bug39;
struct S
{
long l;
}
void main()
{
S s;
s.l = 23;
void* p = &s;
}

View File

@@ -1,13 +0,0 @@
module bug4;
int func(int i)
{
i += 2;
i -= 3;
return i;
}
void main()
{
assert(func(4) == 3);
}

View File

@@ -1,12 +0,0 @@
module bug40;
char[] func(void* p)
{
return null;
}
void main()
{
char[] function(void*) fp = &func;
assert(fp(null) is null);
}

View File

@@ -1,10 +0,0 @@
module bug41;
void main()
{
char[] a = "hello world";
char* ap = a.ptr;
size_t i = 5;
char[] b = ap[0..i];
assert(b == "hello");
}

Some files were not shown because too many files have changed in this diff Show More