<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [compiler-rt][lli][halfType] lli segfaults while executing half type."
   href="https://bugs.llvm.org/show_bug.cgi?id=48213">48213</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[compiler-rt][lli][halfType] lli segfaults while executing half type.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>compiler-rt
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>11.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>builtins
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>vikram.tarikere@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=24180" name="attach_24180" title="IR containing half type - fails to JIT-execute.">attachment 24180</a> <a href="attachment.cgi?id=24180&action=edit" title="IR containing half type - fails to JIT-execute.">[details]</a></span>
IR containing half type - fails to JIT-execute.

The attached bitcode file (addHalf.ll) contains half types (adds 1.0 and 2.0 to
return 3.0) and it segfaults while executing with lli. I think lli fails to
find the right rtlibs because if I compile with llc and link with compiler-rt,
then it executes successfully.

$llc addHalf.ll
$clang addHalf.s --rtlib=compiler-rt    // I need to link with compiler-rt due
to references for __gnu_h2f_ieee from half type conversions.
$./a.out
3.000000

Now, if I try to JIT-execute:
$lli addHalf.ll
PLEASE submit a bug report to <a href="https://bugs.llvm.org/">https://bugs.llvm.org/</a> and include the crash
backtrace.
Stack dump:
0.      Program arguments: lli addHalf.ll
#0 0x00007f7e210929f0 llvm::sys::PrintStackTrace(llvm::raw_ostream&)
/local-ssd/vtariker/llvm/llvm-project/llvm/lib/Support/Unix/Signals.inc:564:0
#1 0x00007f7e21092a83 PrintStackTraceSignalHandler(void*)
/local-ssd/vtariker/llvm/llvm-project/llvm/lib/Support/Unix/Signals.inc:625:0
#2 0x00007f7e21090b2e llvm::sys::RunSignalHandlers()
/local-ssd/vtariker/llvm/llvm-project/llvm/lib/Support/Signals.cpp:68:0
#3 0x00007f7e21092433 SignalHandler(int)
/local-ssd/vtariker/llvm/llvm-project/llvm/lib/Support/Unix/Signals.inc:406:0
#4 0x00007f7e1e56c0c0 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x110c0)
Segmentation fault
$

I have built the compiler-rt library. Maybe I need to tell lli to pick the
compiler-rt libs (just like in the llc case). If so, how do I do that?
A quick debug revealed that it segfaults at
lib/ExecutionEngine/MCJIT/MCJIT.cpp::runFunction() at line 583.



I used the below C-code to generate .ll and then edited it to convert single to
half type:
$cat addHalf.c
#include <stdio.h>

__attribute__((noinline)) float addHalf(float a, float b) {
    return a + b;
}


int main() {

    float a, b;
    float ans;

    a = 1.0;
    b = 2.0;
    ans = addHalf(a, b);
    printf("%f\n", ans);
    return 0;
}

$clang -emit-llvm addHalf.c -O0 -S -o addHalfO0.ll
$opt -mem2reg -instnamer addHalfO0.ll -S -o addHalf_single.ll        // Edited
addHalf_single.ll to get the attached addHalf.ll.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>