• [^] # Re: LLVM IR n'est pas portable

    Posté par . En réponse au journal LLVM dans un gestionnaire de paquets ?. Évalué à 3.

    Un exemple tout bête (et valide !) :
    cat ir.c

    int take_ptr(long ptr) {
    return *(int*)ptr;
    }


    clang ir.c -emit-llvm -o - | llvm-as | opt -O3 | llvm-dis

    ; ModuleID = ''
    target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
    target triple = "i386-pc-linux-gnu"
    %struct.__block_descriptor = type { i32, i32 }
    %struct.__block_literal_generic = type { i8*, i32, i32, i8*, %struct.__block_descriptor* }

    define i32 @take_ptr(i32 %ptr) nounwind {
    entry:
    %conv = inttoptr i32 %ptr to i32* ; <i32*> [#uses=1]
    %tmp1 = load i32* %conv ; [#uses=1]
    ret i32 %tmp1
    }


    Note le "long -> i32" qui ne sera pas valide sur une architecture 64 bits. :(