[LLVMdev] What happened to "malloc" in LLVM 3.0 IR?

Duncan Sands baldrick at free.fr
Thu Jan 19 08:25:29 PST 2012


Hi Jacques,

> I have a compiler written with LLVM 2.6 by a student that produces .ll files, It behaved fine at the time.
>
> Trying to take the work over using version 3.0, I run into the problem that "malloc" in the IR is no longer valid:
>
> semac1 menu>  llvm-as Carre.ll
> llvm-as: Carre.ll:68:14: error: expected instruction opcode
>    %_malloc = malloc i8, i32 %2                    ;<i8*>  [#uses=1]
>               ^
>
> Couldn't find any hint on the web about how to modify the code generation in this compiler to go ahead.

the malloc instruction was removed because it no longer offered any advantages
over recognizing the standard library call "malloc".  So the frontend should
just be modified to generate a call to the "malloc" function.
You can auto-upgrade any existing IR by using tools from 2.7, 2.8, ..., 3.0
along the lines of:
   "opt-2.7 old_bitcode -o - | opt-2.8 -o - | opt-2.9 -o - | opt-3.0 -o new_bitcode"
You can probably omit most of those versions if you are lucky.

Ciao, Duncan.

>
> Thanks for your help!
>
> Regards,
>
> --
>
> Faulty line above is part of the following function:
>
> define i8* @lista_sprintf_double(double %number, i32 %taille, i32 %decimales) {
> entry:
>    %_castInttoDbl = sitofp i32 %decimales to double ;<double>  [#uses=1]
>    %0 = call i8* @lista_sprintf(i8* getelementptr inbounds ([5 x i8]* @_stringexpr1, i32 0, i32 0), double %_castInttoDbl) ;<i8*>  [#uses=2]
>    %_castInttoDbl4 = sitofp i32 %taille to double  ;<double>  [#uses=1]
>    %1 = call i8* @lista_sprintf(i8* getelementptr inbounds ([5 x i8]* @_stringexpr3, i32 0, i32 0), double %_castInttoDbl4) ;<i8*>  [#uses=2]
>    %_lenL = call i32 @strlen(i8* getelementptr inbounds ([2 x i8]* @_stringexpr4, i32 0, i32 0)) ;<i32>  [#uses=1]
>    %_lenR = call i32 @strlen(i8* %1)               ;<i32>  [#uses=1]
>    %_totallen = add i32 %_lenL, 1                  ;<i32>  [#uses=1]
>    %2 = add i32 %_totallen, %_lenR                 ;<i32>  [#uses=1]
>    %_malloc = malloc i8, i32 %2                    ;<i8*>  [#uses=1]
>    %_strcpy = call i8* @strcpy(i8* %_malloc, i8* getelementptr inbounds ([2 x i8]* @_stringexpr4, i32 0, i32 0)) ;<i8*>  [#uses=1]
>    %_strcat = call i8* @strcat(i8* %_strcpy, i8* %1) ;<i8*>  [#uses=2]
>    %_lenL5 = call i32 @strlen(i8* %_strcat)        ;<i32>  [#uses=1]
>    %_lenR6 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8]* @_stringexpr2, i32 0, i32 0)) ;<i32>  [#uses=1]
>    %_totallen7 = add i32 %_lenL5, 1                ;<i32>  [#uses=1]
>    %3 = add i32 %_totallen7, %_lenR6               ;<i32>  [#uses=1]
>    %_malloc8 = malloc i8, i32 %3                   ;<i8*>  [#uses=1]
>    %_strcpy9 = call i8* @strcpy(i8* %_malloc8, i8* %_strcat) ;<i8*>  [#uses=1]
>    %_strcat10 = call i8* @strcat(i8* %_strcpy9, i8* getelementptr inbounds ([2 x i8]* @_stringexpr2, i32 0, i32 0)) ;<i8*>  [#uses=2]
>    %_lenL11 = call i32 @strlen(i8* %_strcat10)     ;<i32>  [#uses=1]
>    %_lenR12 = call i32 @strlen(i8* %0)             ;<i32>  [#uses=1]
>    %_totallen13 = add i32 %_lenL11, 1              ;<i32>  [#uses=1]
>    %4 = add i32 %_totallen13, %_lenR12             ;<i32>  [#uses=1]
>    %_malloc14 = malloc i8, i32 %4                  ;<i8*>  [#uses=1]
>    %_strcpy15 = call i8* @strcpy(i8* %_malloc14, i8* %_strcat10) ;<i8*>  [#uses=1]
>    %_strcat16 = call i8* @strcat(i8* %_strcpy15, i8* %0) ;<i8*>  [#uses=2]
>    %_lenL17 = call i32 @strlen(i8* %_strcat16)     ;<i32>  [#uses=1]
>    %_lenR18 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8]* @_stringexpr, i32 0, i32 0)) ;<i32>  [#uses=1]
>    %_totallen19 = add i32 %_lenL17, 1              ;<i32>  [#uses=1]
>    %5 = add i32 %_totallen19, %_lenR18             ;<i32>  [#uses=1]
>    %_malloc20 = malloc i8, i32 %5                  ;<i8*>  [#uses=1]
>    %_strcpy21 = call i8* @strcpy(i8* %_malloc20, i8* %_strcat16) ;<i8*>  [#uses=1]
>    %_strcat22 = call i8* @strcat(i8* %_strcpy21, i8* getelementptr inbounds ([2 x i8]* @_stringexpr, i32 0, i32 0)) ;<i8*>  [#uses=1]
>    %6 = call i8* @lista_sprintf(i8* %_strcat22, double %number) ;<i8*>  [#uses=1]
>    ret i8* %6
> }
>
>
> --
>
> Dr Jacques MENU
> Chargé de cours
> Centre Universitaire d'Informatique
> Université de Genève
> mailto://Jacques.Menu@unige.ch
> http://cui.unige.ch/~menu
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list