[nasm:nasm-2.15.xx] BR 3392687: clang miscompiles offsetin() for uninitialized pointer

nasm-bot for H. Peter Anvin (Intel) hpa at zytor.com
Tue Jun 30 17:03:08 PDT 2020


Commit-ID:  f21b2ba8f3772eb7d1207c214a181516b9d1f4e4
Gitweb:     http://repo.or.cz/w/nasm.git?a=commitdiff;h=f21b2ba8f3772eb7d1207c214a181516b9d1f4e4
Author:     H. Peter Anvin (Intel) <hpa at zytor.com>
AuthorDate: Tue, 30 Jun 2020 09:54:01 -0700
Committer:  H. Peter Anvin (Intel) <hpa at zytor.com>
CommitDate: Tue, 30 Jun 2020 09:54:01 -0700

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 at jasper.la>
Reported-by: David Bohman <debohman at gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa at zytor.com>


---
 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)


More information about the Nasm-commits mailing list