Closed
Description
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:
- 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;
}
- Compile it:
$ clang -fsanitize=undefined,address -O0 -fno-omit-frame-pointer -ggdb n3322-1.c
- 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.