view tests/mini/asm7.d @ 812:6c2ff06c4201

Fixed a nasty bug with how interface vtables for class initializers were output, causing some class fields to be skipped. Fixed a problem in definition of ClassInfos where an invalid constant was potentially used. This needs to be looked into proper as it might happen again in the future.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Mon, 01 Dec 2008 04:37:54 +0100
parents 4ac97ec7c18e
children 12b423e17860
line wrap: on
line source

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 (LLVM_InlineAsm_X86)
    {
	asm
    	{
		mov EAX, a;
        	add EAX, b;
        	jo Loverflow;
        	mov res, EAX;
    	}
    }
    else version (LLVM_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 (LLVM_InlineAsm_X86)
    {
    	asm
    	{
		mov EAX, a;
        	sub EAX, b;
        	jo Loverflow;
        	mov res, EAX;
    	}
    }
    else version (LLVM_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;
}