public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Olivier Hainque <hainque@adacore.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>
Cc: Olivier Hainque <hainque@adacore.com>
Subject: [PATCH] undef offsetof before defining it in stddef.h
Date: Fri, 30 Sep 2022 18:35:14 +0200	[thread overview]
Message-ID: <3AFBDBC2-8140-4068-A595-8B1ED5C3CE4A@adacore.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 780 bytes --]

Hello,

The attached patch is a proposal to #undef offsetof before
the #define we do in ginclude/stddef.h, which prevents redefinition
warnings from dg tests passing -Wsystem-headers on systems which
provide a definition in system headers, such as VxWorks.

We have been using this for a while with gcc-11 based toolchains
for a wide range of configurations (linux and windows hosts, native
and cross, bare board or VxWorks for a range of CPUs).

This also passes build + sanity test with gcc-12 for
powerpc64-vxworks7r2, then full bootstrap + regression testing
for mainline on x86_64-linux.

Ok to commit?

Thanks in advance!

With Kind Regards,

Olivier

2022-09-30  Olivier Hainque  <hainque@adacore.com>
    
gcc/
       * ginclude/stddef.h: #undef offsetof before #define.


[-- Attachment #2: 0003-undef-offsetof-before-defining-it-in-stddef.h.patch --]
[-- Type: application/octet-stream, Size: 1072 bytes --]

From 365b8343d8f882926d817b81243990ff66945d7c Mon Sep 17 00:00:00 2001
From: Olivier Hainque <hainque@adacore.com>
Date: Fri, 28 Jan 2022 16:34:50 +0000
Subject: [PATCH 03/18] undef offsetof before defining it in stddef.h

This prevents redefinition warnings by -Wsystem-headers on
OSses where system headers happen to provide a definition of
their own, such as VxWorks.

2022-02-15  Olivier Hainque  <hainque@adacore.com>

gcc/
	* ginclude/stddef.h: #undef offsetof before #define.
---
 gcc/ginclude/stddef.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gcc/ginclude/stddef.h b/gcc/ginclude/stddef.h
index 3d29213e8f1..2767edf51de 100644
--- a/gcc/ginclude/stddef.h
+++ b/gcc/ginclude/stddef.h
@@ -412,6 +412,7 @@ typedef __WINT_TYPE__ wint_t;
 #ifdef _STDDEF_H
 
 /* Offset of member MEMBER in a struct of type TYPE. */
+#undef offsetof		/* in case a system header has defined it. */
 #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
 
 #if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) \
-- 
2.25.1


[-- Attachment #3: Type: text/plain, Size: 3 bytes --]





             reply	other threads:[~2022-09-30 16:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-30 16:35 Olivier Hainque [this message]
2022-10-06 12:17 ` Richard Biener
2022-10-06 16:49   ` Olivier Hainque

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3AFBDBC2-8140-4068-A595-8B1ED5C3CE4A@adacore.com \
    --to=hainque@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).