[PATCH] D129224: [InstCombine] Fold strtoul and strtoull and avoid PR #56293

Alexander Kornienko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 1 04:17:30 PDT 2022


alexfh added a subscriber: tstellar.
alexfh added a comment.

In D129224#3690667 <https://reviews.llvm.org/D129224#3690667>, @alexfh wrote:

> There's a problem after this commit: the endptr pointer is not set correctly in some cases. https://gcc.godbolt.org/z/dvcPWcz1T

Apologies, hit "enter" too early. Here's an example:

  #include <stdlib.h>
  #include <stdio.h>
  
  int main(int, char**) {
     char *endptr = nullptr;
     const char *src = "-9223372036854775808";
     long long result = strtoll(src, &endptr, 0);
     printf("source: <%s>, result: %lld, endptr: <%s>\n", src, result, endptr);
  }

When compiled with -O1 or higher optimization level, it now outputs `source: <-9223372036854775808>, result: -9223372036854775808, endptr: <8>`. For -O0 the output is correct: `source: <-9223372036854775808>, result: -9223372036854775808, endptr: <>`.

Do you see an obvious fix?

(and btw, the fix will need to be cherrypicked to the release: @tstellar, fyi)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129224/new/

https://reviews.llvm.org/D129224



More information about the llvm-commits mailing list