From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sat, 26 Feb 2022 19:39:32 +0000 (-0800)
Subject: Document clang -fsanitize=undefined glitch
X-Git-Tag: v1.0~2345
X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=532b4c9f21473559657e273ef9f8f6fc8c7c2ab1;p=gnulib.git

Document clang -fsanitize=undefined glitch

* doc/gnulib-intro.texi (Unsupported Platforms):
Document incompatibility of ‘clang -fsanitize=undefined’
with Gnulib, and how to work around it by also using
‘-fno-sanitize=pointer-overflow’.
---

diff --git a/ChangeLog b/ChangeLog
index 6daf85da3e..430f81fd39 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2022-02-26  Paul Eggert  <eggert@cs.ucla.edu>
+
+	Document clang -fsanitize=undefined glitch
+	* doc/gnulib-intro.texi (Unsupported Platforms):
+	Document incompatibility of ‘clang -fsanitize=undefined’
+	with Gnulib, and how to work around it by also using
+	‘-fno-sanitize=pointer-overflow’.
+
 2022-02-25  Darshit Shah  <darnir@gnu.org>
 
 	modules/unicase/special-casing: Fix compilation error
diff --git a/doc/gnulib-intro.texi b/doc/gnulib-intro.texi
index a80c0995f5..0bc9701561 100644
--- a/doc/gnulib-intro.texi
+++ b/doc/gnulib-intro.texi
@@ -235,6 +235,17 @@ and Gnulib-using code would have if it were intended to be portable to
 all practical POSIX or C platforms.
 
 @itemize @bullet
+@item
+Clang's @option{-fsanitize=undefined} option causes the program to
+crash if it adds zero to a null pointer -- behavior that is undefined
+in strict C, but which yields a null pointer on all practical porting
+targets and which the Gnulib portability guidelines allow.
+
+If you use Clang with @option{-fsanitize=undefined}, you can work
+around the problem by also using @samp{-fno-sanitize=pointer-overflow},
+although this may also disable some unrelated and useful pointer checks.
+Perhaps someday the Clang developers will fix the infelicity.
+
 @item
 The IBM i's pointers are 128 bits wide and it lacks the two types
 @code{intptr_t} and @code{uintptr_t}, which are optional in the C and