* obstack.h __PTR_ALIGN vs. ubsan
@ 2021-09-02 4:03 Alan Modra
2021-09-19 17:01 ` Jeff Law
0 siblings, 1 reply; 2+ messages in thread
From: Alan Modra @ 2021-09-02 4:03 UTC (permalink / raw)
To: binutils, gcc-patches
Current ubsan complains on every use of __PTR_ALIGN (when ptrdiff_t is
as large as a pointer), due to making calculations relative to a NULL
pointer. This patch avoids the problem by extracting out and
simplifying __BPTR_ALIGN for the usual case. I've continued to use
ptrdiff_t here, where it might be better to throw away __BPTR_ALIGN
entirely and just assume uintptr_t exists.
OK to apply for gcc?
* obstack.h (__PTR_ALIGN): Expand and simplify __BPTR_ALIGN
rather than calculating relative to a NULL pointer.
diff --git a/include/obstack.h b/include/obstack.h
index a6eb6c95587..0d8746f835b 100644
--- a/include/obstack.h
+++ b/include/obstack.h
@@ -137,9 +137,9 @@
relative to B. Otherwise, use the faster strategy of computing the
alignment relative to 0. */
-#define __PTR_ALIGN(B, P, A) \
- __BPTR_ALIGN (sizeof (ptrdiff_t) < sizeof (void *) ? (B) : (char *) 0, \
- P, A)
+#define __PTR_ALIGN(B, P, A) \
+ (sizeof (ptrdiff_t) < sizeof (void *) ? __BPTR_ALIGN (B, P, A) \
+ : (char *) (((ptrdiff_t) (P) + (A)) & ~(A)))
#ifndef __attribute_pure__
# if defined __GNUC_MINOR__ && __GNUC__ * 1000 + __GNUC_MINOR__ >= 2096
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: obstack.h __PTR_ALIGN vs. ubsan
2021-09-02 4:03 obstack.h __PTR_ALIGN vs. ubsan Alan Modra
@ 2021-09-19 17:01 ` Jeff Law
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2021-09-19 17:01 UTC (permalink / raw)
To: Alan Modra, binutils, gcc-patches
On 9/1/2021 10:03 PM, Alan Modra via Binutils wrote:
> Current ubsan complains on every use of __PTR_ALIGN (when ptrdiff_t is
> as large as a pointer), due to making calculations relative to a NULL
> pointer. This patch avoids the problem by extracting out and
> simplifying __BPTR_ALIGN for the usual case. I've continued to use
> ptrdiff_t here, where it might be better to throw away __BPTR_ALIGN
> entirely and just assume uintptr_t exists.
>
> OK to apply for gcc?
>
> * obstack.h (__PTR_ALIGN): Expand and simplify __BPTR_ALIGN
> rather than calculating relative to a NULL pointer.
OK
jeff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-09-19 17:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-02 4:03 obstack.h __PTR_ALIGN vs. ubsan Alan Modra
2021-09-19 17:01 ` Jeff Law
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).