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

    <tr>
        <th>Summary</th>
        <td>
            UndefinedBehaviorSanitizer should no longer report an error about adding a NULL pointer and a 0 integer
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    According to https://sourceware.org/pipermail/libc-alpha/2024-October/160375.html, N3322 has been accepted for inclusion in ISO C.

In particular, adding a NULL pointer and a 0 integer is no longer undefined behaviour. clang's UBSAN should therefore no longer report a "runtime error" about it.

How to reproduce:
1. Save this file as `n3322-1.c`:
```
/* This program exercises functionality allowed by
 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3322.pdf */

#include <stddef.h>

int main ()
{
  char *volatile p1 = NULL;
  char *volatile p2 = NULL;
  ptrdiff_t n = p1 - p2;
  char *q = p1 + n;
 (void) q;
}
```
2. Compile it:
```
$ clang -fsanitize=undefined,address -O0 -fno-omit-frame-pointer -ggdb n3322-1.c
```
3. Run it:
```
$ ASAN_OPTIONS="detect_leaks=0 abort_on_error=0 allocator_may_return_null=1" ./a.out
n3322-1.c:11:16: runtime error: applying zero offset to null pointer
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior n3322-1.c:11:16 
```

This runtime error, seen with clang 19, should go away.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVUFv2zgT_TX0ZSBBHCV2dNDBiT_jK9Ami7o57MmgyJHELk2qJGVv-usXlOyk6bq7Cxi0SM6MZt7MexIh6M4S1ez2nt1uFmKMvfN10wvdGFo0Tr3UaymdV9p2EB30MQ6BlWuGW4bb4EYv6SQ85c53DLeDHsgfhDYMt0Y3MhNm6AXDLRZ4kz3J6BryDLd8WZSr27yPB8PwAR7LEhF6E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