This is an archive of the discontinued LLVM Phabricator instance.

Mark memrchr as unavailable on Windows
ClosedPublic

Authored by mati865 on Sep 18 2022, 5:52 AM.

Details

Summary

Otherwise LLVM will optimise strrchr into memrchr on Windows resulting in linker error:

$ cat memrchr_test.c
#include <string.h>
int main(int argc, char **argv) {
    return (long)strrchr("KkMm", argv[argc-1][0]);
}

$ clang memrchr_test.c -O
memrchr_test.c:3:12: warning: cast to smaller integer type 'long' from 'char *' [-Wpointer-to-int-cast]
    return (long)strrchr("KkMm", argv[argc-1][0]);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
ld.lld: error: undefined symbol: memrchr
>>> referenced by D:/msys64/tmp/memrchr_test-e7aabd.o:(main)
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Example taken from MSYS2 Discord and tested with windows-gnu target.

Diff Detail

Event Timeline

mati865 created this revision.Sep 18 2022, 5:52 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 18 2022, 5:52 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
mati865 requested review of this revision.Sep 18 2022, 5:52 AM
mati865 added a subscriber: mstorsjo.
aeubanks accepted this revision.Sep 19 2022, 7:29 PM
aeubanks added a subscriber: aeubanks.

lg

I was going to ask for a test but it looks like we don't really test per-target available libcalls and that does seem tedious and probably not worth it

This revision is now accepted and ready to land.Sep 19 2022, 7:29 PM
This revision was automatically updated to reflect the committed changes.