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

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 9 13:05:39 PDT 2018


xbolva00 abandoned this revision.
xbolva00 added a comment.

Abandoned.



================
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()));
----------------
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.


================
Comment at: test/Transforms/InstCombine/str-int-2.ll:4
+
+ at .str = private unnamed_addr constant [11 x i8] c"2147483648\00", align 1
+
----------------
lebedev.ri wrote:
> But this is just `1<<31`, it fits into `i32` as-is.
> Maybe `4294967296` (`1<<32`) ?
Updated.


https://reviews.llvm.org/D45418





More information about the llvm-commits mailing list