[PATCH] D45418: [SimplifyLibcalls] Atoi, strtol replacements

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 12 13:04:44 PDT 2018


xbolva00 added inline comments.


================
Comment at: lib/Transforms/Utils/SimplifyLibCalls.cpp:1716
+  if (DL.getTypeAllocSize(CI->getType()) != sizeof(long int))
+    return nullptr;
+
----------------
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.


https://reviews.llvm.org/D45418





More information about the llvm-commits mailing list