[PATCH] D45418: [SimplifyLibcalls] Atoi, strtol replacements
Eli Friedman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 13 14:09:23 PDT 2018
efriedma added inline comments.
================
Comment at: lib/Transforms/Utils/SimplifyLibCalls.cpp:1716
+ if (DL.getTypeAllocSize(CI->getType()) != sizeof(long int))
+ return nullptr;
+
----------------
xbolva00 wrote:
> efriedma wrote:
> > xbolva00 wrote:
> > > efriedma wrote:
> > > > `DL.getTypeAllocSize(CI->getType()) != sizeof(long int)` will cause your testcase to fail on 32-bit hosts (because we'll refuse the fold the call).
> > > >
> > > > Can you use strtoll plus a range check, instead?
> > > But problem is ..
> > >
> > > errs() << std::numeric_limits<long int>::max() << "\n";
> > > errs() << std::numeric_limits<long long int>::max() << "\n";
> > >
> > > 9223372036854775807
> > > 9223372036854775807
> > >
> > > So we need to rely on errno, I think
> > By "range check", I mean in addition to the errno check, if CI->getType() is a 32-bit integer, check that the result of strtoll fits into a 32-bit integer.
> Oh :D ok. Will fix.
The range check is still wrong. You can try building 32-bit LLVM yourself by setting the CMake option LLVM_BUILD_32_BITS.
https://reviews.llvm.org/D45418
More information about the llvm-commits
mailing list