LLVM 3.0 oddity

Hi all,

In the LLVM backend for the DDC compiler, since version 2.7 I have
been doing the following:

  declare external ccc i32 @some_fn(%struct.Obj* ) align 8

  ; bunch more declarations and code.

  define external ccc i32 @some_fn(%struct.Obj* %_p_vn)
  {
  entry:

but now I'm getting an error at the function definition saying:

    error: invalid redefinition of function 'some_fn'

So my questions are:

a) Is this a bug? Should llvm be allowing this?

b) Is there a good reason why I should not be allowed both declare
    and a defined a function in the same module?

c) Am I doing something else wrong.

Cheers,
Erik

Erik de Castro Lopo <mle+cl@mega-nerd.com> writes:

[snip]

  declare external ccc i32 @some_fn(%struct.Obj* ) align 8

  ; bunch more declarations and code.

  define external ccc i32 @some_fn(%struct.Obj* %_p_vn)

[snip]

c) Am I doing something else wrong.

I guess that the problem is with the missing `align 8' on the `define'.

Óscar Fuentes wrote:

Erik de Castro Lopo <mle+cl@mega-nerd.com> writes:

[snip]

> declare external ccc i32 @some_fn(%struct.Obj* ) align 8
>
> ; bunch more declarations and code.
>
> define external ccc i32 @some_fn(%struct.Obj* %_p_vn)
[snip]
> c) Am I doing something else wrong.

I guess that the problem is with the missing `align 8' on the `define'.

Nope, if I add an 'align 8' to the definition, I still get the
same error.

Here is a minimal test case:

    declare i32 @plus_two(i32)

    define i32 @plus_two(i32 %x) {
      %1 = add nsw i32 %x, 2
      ret i32 %1
    }

for which llc gives the error:

    llc: a.ll:4:12: error: invalid redefinition of function 'plus_two'
    define i32 @plus_two(i32 %x) {

Erik

I don’t know the reason, but I do remember that LLVM does not allow you to declare a function and define it.

Reid

Reid Kleckner wrote: