[LLVMdev] IR type safety

me22 me22.ca at gmail.com
Tue Sep 21 14:55:35 PDT 2010


On Tue, Sep 21, 2010 at 14:20, Renato Golin <rengolin at systemcall.org> wrote:
> On 21 September 2010 18:39, Andrew Lenharth <andrewl at lenharth.org> wrote:
>> Type names don't have meaning.  If you want this not to happen, you
>> can generate a different opaque type for each type in your language to
>> prevent merging.
>
> Why create opaque types to avoid something that should be taken from
> granted (in a said "type-safe" representation)?
>
> [...]
>
> Am I being too picky?
>

I think you're just trying to do something that by design doesn't
work.  Your complaint seems to be that LLVM's type system doesn't give
you nominal type safety with transparent types, and you're right, it
doesn't, because transparent types work structurally.

If you want nominal type safety, then you need something else.  Two
possible options are name mangling the functions (as you mentioned C++
does), or use LLVM's opaque types, which work nominally.

LLVM's transparent types do, however, give you far more than C does.
Try linking these together:

    -- a.c --
    int foo(int);
    int bar(int a) { return a * foo(a); }

    -- b.c --
    int foo(char *p) { return puts(p); }

HTH,
~ Scott

P.S.  I don't think "transparent types" is an official LLVM term, but
it seemed a reasonable opposite for "opaque types".




More information about the llvm-dev mailing list