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

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 9 13:41:54 PDT 2018


efriedma added inline comments.


================
Comment at: lib/Transforms/Utils/SimplifyLibCalls.cpp:1697
+  if (ConstantInt *CInt = dyn_cast<ConstantInt>(CI->getArgOperand(2)))
+    return ConstantInt::get(CI->getType(), strtol(Str.str().c_str(), nullptr,
+                                                  CInt->getSExtValue()));
----------------
xbolva00 wrote:
> xbolva00 wrote:
> > efriedma wrote:
> > > lebedev.ri wrote:
> > > > lebedev.ri wrote:
> > > > > `base` is `i32`, but `strtol` returns `long int` (`i64`?), so i don't think using `CI->getType()` is correct.
> > > > > 
> > > > Oh, `CI` is `CallInst`, not `ConstantInt`, never mind then.
> > > This is missing some checks.  In particular, what happens if the host's "long" is a different width from the target's "long"? What happens if strtol sets errno?  What happens if the target program is using a locale where isspace() doesn't match the C locale's isspace()?
> > Ah yes. So I will have to close this patch since we cant optimize this calls.
> I dont know about that thing with locale. I dont think we have to care about this weirdness.
isspace() in all locales should return true for all the characters where it returns true in the C locale; it's just a question of whether there are some additional characters which also count as spaces.  So I think you'll get the right behavior if you refuse to fold in cases where strtol would fail in the C locale.


https://reviews.llvm.org/D45418





More information about the llvm-commits mailing list