Skip to content

Commit

Permalink
Use GCC's builtin offset_of as the first option
Browse files Browse the repository at this point in the history
Other than C++ code, the GCC offsetof builtin was never getting used.
The version that did get expanded could not be used for array
declarations on GCC 4.5 and later because it wasn't considered a
constant expression by those later GCC compilers.

The first symptom was seen when building world with GCC 4.6, but the
the offsetof expansion was finally identified as the cause of the
problem while discussion PostgreSQL 9.1 build failures on DragonFly.
Since DragonFly was the only platform exibiting the behavior, the
problem was narrowed down to the offsetof macro or the compiler itself.
Fixing the macro allowed the unpatched pgsql to compile.

Thanks-to: Tom Lane
  • Loading branch information
John Marino authored and François Tigeot committed Oct 7, 2012
1 parent 7b33812 commit 262e0d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 6 additions & 5 deletions sys/cpu/i386/include/stdint.h
Expand Up @@ -36,7 +36,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* $FreeBSD: src/sys/i386/include/_stdint.h,v 1.1 2002/07/29 17:41:07 mike Exp $
* $DragonFly: src/sys/cpu/i386/include/stdint.h,v 1.8 2007/07/29 22:20:10 pavalos Exp $
*/

#ifndef _CPU_STDINT_H_
Expand Down Expand Up @@ -117,16 +116,18 @@ typedef volatile int __atomic_intr_t;
/*
* Its convenient to put these here rather then create another header file.
*/
#if __GNUC_PREREQ__(4, 1)
#define __offsetof(type, field) __builtin_offsetof(type, field)
#else
#ifndef __cplusplus
#define __offsetof(type, field) ((__size_t)(&((type *)0)->field))
#elif (__GNUC__ >= 4)
#define __offsetof(type, field) __builtin_offsetof(type, field)
#else
#else
#define __offsetof(type, field) \
(__offsetof__ (reinterpret_cast <__size_t> \
(&reinterpret_cast <const volatile char &> \
(static_cast<type *> (0)->field))))
#endif
#endif
#endif

#define __arysize(ary) (sizeof(ary)/sizeof((ary)[0]))

Expand Down
6 changes: 4 additions & 2 deletions sys/cpu/x86_64/include/stdint.h
Expand Up @@ -132,16 +132,18 @@ typedef volatile int __atomic_intr_t;
/*
* Its convenient to put these here rather then create another header file.
*/
#if __GNUC_PREREQ__(4, 1)
#define __offsetof(type, field) __builtin_offsetof(type, field)
#else
#ifndef __cplusplus
#define __offsetof(type, field) ((__size_t)(&((type *)0)->field))
#elif (__GNUC__ >= 4)
#define __offsetof(type, field) __builtin_offsetof(type, field)
#else
#define __offsetof(type, field) \
(__offsetof__ (reinterpret_cast <__size_t> \
(&reinterpret_cast <const volatile char &> \
(static_cast<type *> (0)->field))))
#endif
#endif

#define __arysize(ary) (sizeof(ary)/sizeof((ary)[0]))

Expand Down

0 comments on commit 262e0d7

Please sign in to comment.