<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/56293>56293</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            difference due to atoi folding on Darwin
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          msebor
      </td>
    </tr>
</table>

<pre>
    As discussed in [D128364](https://reviews.llvm.org/D128364#3618130), by relying on nonportable `strtol` behavior on the host, the `atoi` (and `strtol`) folders can introduce an observable difference between different targets or when cross-compiling.  The following test case passes successfully on Linux but will likely abort when cross-compiling for Darwin on Linux due to the first `atoi` call having been folded to zero (with no change to `errno`) while the second call having resulted in the Darwin implementation of the function setting `errno` to `EINVAL` as POSIX allows but doesn't require.  (I don't have access to Darwin to verify this is what happens but the test failures reported in [D128364](https://reviews.llvm.org/D128364#3618130) suggest this is the case,
```
#include <errno.h>
#include <stdlib.h>

char s[] = "";

int main(void)
{
  errno = 0;
  int i0 = atoi("");
  int e0 = errno;

  errno = 0;
  int i1 = atoi(s);
  int e1 = errno;

  if (i0 != i1 || e0 != e1)
    abort();
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVE1v4zgM_TX2hWhgy3E-Dj50mhYoMJhZYBaLvcoWbWtHkTKinGzm1y8lu206KOa0gZJYIvX4-Ei6dera3BMoTd1EhAq0haz-dCjFrtqss_qQid0Ywomy6j4TT7w8njVeaGXM-bhyfuCjF29RVZtyV1ZFJvaZeID2Ch7NVdsBnAXr7Mn5IFuDkG0KCj44ww_Q4ijP2vnoFEaE0VGI1-Mz22VwOroxE2nVu6scB3pnFHqCTlomH7xTU4fAG9cS-nMKp3Tfo0fLhhbDBdG-HgUI0g8YCJjAZWRL5x3RXeeOJ22Y-grgTybCYYy7xFQCUuBohHCSLBkBTV2HRP1kzDXm8Fnb6V9opwAXb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