[LLVMdev] Structure Alignment
Manoel Teixeira
manoel at fonetica.com.br
Thu Jun 4 12:49:11 PDT 2009
struct xfirstStru
{
int var1;
double var2;
int var3;
char *var4;
};
%FIRSTSTRU_PLUSPLUS_TOTVS. = type { i32, double, i32, i8* }
Hi,
I had not applied the layout at run time, only during the emission of the .bc.
Now it's running ok when I allocate the structure point at LLVM side, but, when I allocate the structure pointer in the C side, the LLVM function does not acquire the double value correctly.
Manoel Teixeira
> Message: 1
> Date: Thu, 4 Jun 2009 10:39:24 -0300
> From: " Manoel Teixeira " <manoel at fonetica.com.br>
> Subject: [LLVMdev] Structure Alignment
> To: llvmdev at cs.uiuc.edu
> Message-ID: <20090604133924.4200.qmail at hm885.locaweb.com.br>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi,
> I have a problem using structs, when calling a function written in C from
> a LLVM function or calling a LLVM function from a C one.
> I noticed that the LLVM align double with 4 bytes and our run time routines
> use 8, in MS Windows.
> If a use #pragma pack(4) in my C programs, the routines run fine, but
> I must ensure that all external call should use the #pragma directive.
>
> If I change the llvm layout f64:64:64, the LLVM calls C functions and
> the struct is OK, in the C side, but the getelemntptr fails in LLVM side.
> Is there on way to ensure that the LLVM reads the correct memory position
> in this case?
>
> //#pragma pack(4)
> struct xfirstStru
> {
> int var1;
> double var2;
> int var3;
> char *var4;
> };
> typedef struct xfirstStru osX ;
> typedef struct xfirstStru* PosX ;
> //#pragma pack()
> //
> extern "C" int testOSX( PosX osx )
> {
> printf("\nChamada C %d %f %d %s",++osx->var1,++osx->var2,++osx->var3,osx->var4);
> return 999;
> }
>
> it was
> ... f64:32:64 ...
> and I changed it to
> ... f64:64:64 ...
>
> %struct.VAR1. = getelementptr %FIRSTSTRU.* %OUTRASTRU., i32 0, i32 0 ; <i32*> [#uses=2] %loadX = load i32* %struct.el.VAR1., align 4 ; <i32> [#uses=1]
> here the first element is OK
> ...
> %struct.el.VAR2. = getelementptr %FIRSTSTRU.* %OUTRASTRU., i32 0, i32 1 ; <i32*> [#uses=2] %loadX = load double* %struct.el.VAR2., align 8 ; <double> [#uses=1]
> here, the second is wrong
> ...
>
>
> Thanks,
> Manoel Teixeira
>
More information about the llvm-dev
mailing list