<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </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/lib/builtins/muldi3.c: Infinite loop/stack overflow in __muldi3"
   href="http://llvm.org/bugs/show_bug.cgi?id=21514">21514</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>compiler-rt/lib/builtins/muldi3.c:  Infinite loop/stack overflow in __muldi3
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>compiler-rt
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>troshkovdanil@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>__muldi3(di_int a, di_int b)
{
    dwords x;
    x.all = a;
    dwords y;
    y.all = b;
    dwords r;
    r.all = __muldsi3(x.s.low, y.s.low);
    r.s.high += x.s.high * y.s.low + x.s.low * y.s.high;
    return r.all;
}

Function recursively uses itself (r.s.high += x.s.high * y.s.low + x.s.low *
y.s.high).
It occurs quite legally...
Dumps (-mllvm -print-after-all):

; Function Attrs: nounwind
define i64 @__muldi3(i64 %a, i64 %b) #0 {
entry:
  %x.sroa.0.0.extract.trunc = trunc i64 %a to i32
  %x.sroa.3.0.extract.shift = lshr i64 %a, 32
  %x.sroa.3.0.extract.trunc = trunc i64 %x.sroa.3.0.extract.shift to i32
  %y.sroa.0.0.extract.trunc = trunc i64 %b to i32
  %y.sroa.3.0.extract.shift = lshr i64 %b, 32
  %y.sroa.3.0.extract.trunc = trunc i64 %y.sroa.3.0.extract.shift to i32
  %call = call fastcc i64 @__muldsi3(i32 %x.sroa.0.0.extract.trunc, i32
%y.sroa.0.0.extract.trunc)
  %r.sroa.0.0.extract.trunc = trunc i64 %call to i32
  %r.sroa.2.0.extract.shift = lshr i64 %call, 32
  %r.sroa.2.0.extract.trunc = trunc i64 %r.sroa.2.0.extract.shift to i32
  %mul = mul i32 %x.sroa.3.0.extract.trunc, %y.sroa.0.0.extract.trunc
  %mul12 = mul i32 %x.sroa.0.0.extract.trunc, %y.sroa.3.0.extract.trunc
  %add = add i32 %mul, %mul12
  %add15 = add i32 %r.sroa.2.0.extract.trunc, %add
  %r.sroa.2.0.insert.ext = zext i32 %add15 to i64
  %r.sroa.2.0.insert.shift = shl i64 %r.sroa.2.0.insert.ext, 32
  %r.sroa.0.0.insert.ext = zext i32 %r.sroa.0.0.extract.trunc to i64
  %r.sroa.0.0.insert.mask = and i64 %r.sroa.2.0.insert.shift, -4294967296
  %r.sroa.0.0.insert.insert = or i64 %r.sroa.0.0.insert.mask,
%r.sroa.0.0.insert.ext
  ret i64 %r.sroa.0.0.insert.insert
}
.....
*** IR Dump After Combine redundant instructions ***
; Function Attrs: nounwind
define i64 @__muldi3(i64 %a, i64 %b) #0 {
entry:
  %x.sroa.0.0.extract.trunc = trunc i64 %a to i32
  %x.sroa.3.0.extract.shift = lshr i64 %a, 32
  %y.sroa.0.0.extract.trunc = trunc i64 %b to i32
  %y.sroa.3.0.extract.shift = lshr i64 %b, 32
  %call = call fastcc i64 @__muldsi3(i32 %x.sroa.0.0.extract.trunc, i32
%y.sroa.0.0.extract.trunc)
  %mul = mul i64 %x.sroa.3.0.extract.shift, %b
  %mul12 = mul i64 %y.sroa.3.0.extract.shift, %a
  %add = add i64 %mul, %mul12
  %add1519 = shl i64 %add, 32
  %r.sroa.2.0.extract.shift20 = add i64 %call, %add1519
  ret i64 %r.sroa.2.0.extract.shift20
}

And (mul i64) is __muldi3...

I've looked for similar problems in the Internet and found something like this:

<a href="https://groups.google.com/forum/#!topic/llvm-dev/c-i8S5tOSYg">https://groups.google.com/forum/#!topic/llvm-dev/c-i8S5tOSYg</a>

So it looks like the solution is to explicitly use builtins:

     r.all = __muldsi3(x.s.low, y.s.low);
-    r.s.high += x.s.high * y.s.low + x.s.low * y.s.high;
+    r.s.high += __mulsi3(x.s.high, y.s.low) + __mulsi3(x.s.low, y.s.high);
     return r.all;

But we have no __mulsi3...

Any ideas?</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>