[llvm-bugs] [Bug 42711] New: clang9 -Oz generates incorrect symbols for msvc i386 target

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jul 22 07:11:57 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=42711

            Bug ID: 42711
           Summary: clang9 -Oz generates incorrect symbols for msvc i386
                    target
           Product: clang
           Version: 9.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: wbsecg1 at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

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
>>> referenced by /tmp/clangcl32OzBug-b06f63.o:(_av_gcd)
>>> referenced by /tmp/clangcl32OzBug-b06f63.o:(_av_gcd)
>>> referenced by /tmp/clangcl32OzBug-b06f63.o:(_av_gcd)

lld-link-9: error: undefined symbol: ___ashldi3
>>> referenced by /tmp/clangcl32OzBug-b06f63.o:(_av_gcd)
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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190722/ed5ca24c/attachment.html>


More information about the llvm-bugs mailing list