BR 3392687: clang miscompiles offsetin() for uninitialized pointer

The actual pointer value in offsetin() cancels out, but clang still
miscompiles offsetin() for an uninitialized pointer, considering the
value to be completely undefined. Initialize pointer being passed to
offsetin() to make clang happy; both the gcc and clang optimizers
discover later in the code that the initialization is unused and
removes it from the code.

Although technically undefined behavior, this is in my opinion a
severe quality of implementation bug in clang, and I will file a bug
report accordingly.

Reported-by: Jasper Lievisse Adriaanse <r+nasm@jasper.la>
Reported-by: David Bohman <debohman@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin (Intel) 2020-06-30 09:54:01 -07:00
parent 14f41b2319
commit f21b2ba8f3

View File

@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------- *
*
* Copyright 1996-2018 The NASM Authors - All Rights Reserved
* Copyright 1996-2020 The NASM Authors - All Rights Reserved
* See the file AUTHORS included with the NASM distribution for
* the specific copyright holders.
*
@ -102,7 +102,8 @@ strlist_add(struct strlist *list, const char *str)
const struct strlist_entry *
strlist_vprintf(struct strlist *list, const char *fmt, va_list ap)
{
struct strlist_entry *e;
/* clang miscompiles offsetin() unless e is initialized here */
struct strlist_entry *e = NULL;
struct hash_insert hi;
if (!list)