<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 - clang9 -Oz generates incorrect symbols for msvc i386 target"
   href="https://bugs.llvm.org/show_bug.cgi?id=42711">42711</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang9 -Oz generates incorrect symbols for msvc i386 target
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>9.0
          </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>-New Bugs
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Code to Reproduce(from ffmpeg):

#include <stdint.h>
#include <math.h>
#ifndef ff_ctzll
#define ff_ctzll(v) __builtin_ctzll(v)
#endif
#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)

int64_t av_gcd(int64_t a, int64_t b) {
    int za, zb, k;
    int64_t u, v;
    if (a == 0)
        return b;
    if (b == 0)
        return a;
    za = ff_ctzll(a);
    zb = ff_ctzll(b);
    k  = FFMIN(za, zb);
    u = llabs(a >> za);
    v = llabs(b >> zb);
    while (u != v) {
        if (u > v)
            FFSWAP(int64_t, v, u);
        v -= u;
        v >>= ff_ctzll(v);
    }
    return (uint64_t)u << k;
}

int main()
{
    int v = av_gcd(123, 345);
}

Build Command:

gnu style: clang-9 -Oz -fuse-ld=lld-link-9 --target=i386-pc-windows-msvc
-std=c11 -MD -Wl,-nodefaultlib:libcmt -Wl,-defaultlib:msvcrt clangcl32OzBug.c

vc style: clang-cl -Xclang -Oz --target=i386-pc-windows-msvc -MD
clangcl32OzBug.c

Actual Results:

lld-link-9: error: undefined symbol: ___ashrdi3
<span class="quote">>>> referenced by /tmp/clangcl32OzBug-b06f63.o:(_av_gcd)
>>> referenced by /tmp/clangcl32OzBug-b06f63.o:(_av_gcd)
>>> referenced by /tmp/clangcl32OzBug-b06f63.o:(_av_gcd)</span >

lld-link-9: error: undefined symbol: ___ashldi3
<span class="quote">>>> referenced by /tmp/clangcl32OzBug-b06f63.o:(_av_gcd)</span >
clang: error: linker command failed with exit code 1 (use -v to see invocation)


Expected Results:
no error

Additional Information:
x64 target, clang-8, -Os -O2 no error.
__ashrdi3 exists in libgcc and compiler-rt.</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>