[llvm] 4f30c58 - [TargetLibraryInfo] Mark memrchr as unavailable on Windows
Martin Storsjö via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 20 01:03:24 PDT 2022
Author: Mateusz Mikuła
Date: 2022-09-20T10:50:31+03:00
New Revision: 4f30c5808a49ba85b052cb65bbe7b34109187bad
URL: https://github.com/llvm/llvm-project/commit/4f30c5808a49ba85b052cb65bbe7b34109187bad
DIFF: https://github.com/llvm/llvm-project/commit/4f30c5808a49ba85b052cb65bbe7b34109187bad.diff
LOG: [TargetLibraryInfo] Mark memrchr as unavailable on Windows
Otherwise LLVM will optimise strrchr into memrchr on Windows resulting in linker error:
```
$ cat memrchr_test.c
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.
Reviewed By: aeubanks
Differential Revision: https://reviews.llvm.org/D134134
Added:
Modified:
llvm/lib/Analysis/TargetLibraryInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index 75b57e75fdd0..40f0cf39d7d6 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -439,6 +439,7 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
TLI.setUnavailable(LibFunc_htons);
TLI.setUnavailable(LibFunc_lchown);
TLI.setUnavailable(LibFunc_lstat);
+ TLI.setUnavailable(LibFunc_memrchr);
TLI.setUnavailable(LibFunc_ntohl);
TLI.setUnavailable(LibFunc_ntohs);
TLI.setUnavailable(LibFunc_pread);
More information about the llvm-commits
mailing list