[llvm-dev] LLVM behavior different depending on function symbol name

Andrew Kelley via llvm-dev llvm-dev at lists.llvm.org
Mon Jun 19 08:45:54 PDT 2017


Greetings,

I have a Zig implementation of ceil which is emitted into LLVM IR like this:

; Function Attrs: nobuiltin nounwind
define internal fastcc float @ceil(float) unnamed_addr #3 !dbg !644 {
Entry:
  %x = alloca float, align 4
  store float %0, float* %x
  call void @llvm.dbg.declare(metadata float* %x, metadata !649, metadata
!494), !dbg !651
  %1 = load float, float* %x, !dbg !652
  %2 = call fastcc float @ceil32(float %1) #8, !dbg !656
  ret float %2, !dbg !657
}

Test case:

test "math.ceil" {
    assert(ceil(f32(0.0)) == ceil32(0.0));
    assert(ceil(f64(0.0)) == ceil64(0.0));
}


When I compile with optimizations on, this test case fails. The optimized
code for the test case ends up being a call to panic (assertion failure),
which means that LLVM determined the test failed at compile-time.

What's strange about this is that if I change the function name from @ceil
to @ceil_asdf (and change the callers) then the test passes.

So I think LLVM is doing some kind of string comparison on the symbol name
and detecting that it is "ceil" and then having different, undesired
behavior.

I tried putting `nobuiltin` in the function attributes and at the callsite,
but that did not change anything.

Any ideas what's going on?

Downstream issue: https://github.com/zig-lang/zig/issues/393

Regards,
Andrew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170619/fb44b9f3/attachment.html>


More information about the llvm-dev mailing list