From f21b2ba8f3772eb7d1207c214a181516b9d1f4e4 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin (Intel)" Date: Tue, 30 Jun 2020 09:54:01 -0700 Subject: 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 Reported-by: David Bohman Signed-off-by: H. Peter Anvin (Intel) --- nasmlib/strlist.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nasmlib/strlist.c b/nasmlib/strlist.c index db5a09ab..449304b7 100644 --- a/nasmlib/strlist.c +++ b/nasmlib/strlist.c @@ -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) -- cgit v1.2.1