Skip to content

Commit ec3c9cc

Browse files
committed
Add definition pg_attribute_aligned() for MSVC
Visual Studio 2015+ has support for a macro to control the alignement of structures as of __declspec(align(#)), and this commit adds a definition of pg_attribute_aligned() based on that. It happens that this was already used in the implementation of atomics for MSVC. Note that there is still no definition fo pg_attribute_packed(), so this does not impact itemptr.h. Author: James Coleman Discussion: https://postgr.es/m/CAAaqYe-HbtZvR3msoMtk+hYW2S0e0OapzMW8icSMYTMA+mN8Aw@mail.gmail.com
1 parent 1c27d16 commit ec3c9cc

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

config/c-compiler.m4

+2
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ if test x"$pgac_cv__128bit_int" = xyes ; then
139139
/* This must match the corresponding code in c.h: */
140140
#if defined(__GNUC__) || defined(__SUNPRO_C) || defined(__IBMC__)
141141
#define pg_attribute_aligned(a) __attribute__((aligned(a)))
142+
#elif defined(_MSC_VER)
143+
#define pg_attribute_aligned(a) __declspec(align(a))
142144
#endif
143145
typedef __int128 int128a
144146
#if defined(pg_attribute_aligned)

configure

+2
Original file line numberDiff line numberDiff line change
@@ -17462,6 +17462,8 @@ else
1746217462
/* This must match the corresponding code in c.h: */
1746317463
#if defined(__GNUC__) || defined(__SUNPRO_C) || defined(__IBMC__)
1746417464
#define pg_attribute_aligned(a) __attribute__((aligned(a)))
17465+
#elif defined(_MSC_VER)
17466+
#define pg_attribute_aligned(a) __declspec(align(a))
1746517467
#endif
1746617468
typedef __int128 int128a
1746717469
#if defined(pg_attribute_aligned)

src/include/c.h

+11
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,17 @@
181181
#define pg_attribute_noreturn() __attribute__((noreturn))
182182
#define pg_attribute_packed() __attribute__((packed))
183183
#define HAVE_PG_ATTRIBUTE_NORETURN 1
184+
#elif defined(_MSC_VER)
185+
/*
186+
* MSVC supports aligned. noreturn is also possible but in MSVC it is
187+
* declared before the definition while pg_attribute_noreturn() macro
188+
* is currently used after the definition.
189+
*
190+
* Packing is also possible but only by wrapping the entire struct definition
191+
* which doesn't fit into our current macro declarations.
192+
*/
193+
#define pg_attribute_aligned(a) __declspec(align(a))
194+
#define pg_attribute_noreturn()
184195
#else
185196
/*
186197
* NB: aligned and packed are not given default definitions because they

src/include/port/atomics/generic-msvc.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ typedef struct pg_atomic_uint32
3939
} pg_atomic_uint32;
4040

4141
#define PG_HAVE_ATOMIC_U64_SUPPORT
42-
typedef struct __declspec(align(8)) pg_atomic_uint64
42+
typedef struct pg_attribute_aligned(8) pg_atomic_uint64
4343
{
4444
volatile uint64 value;
4545
} pg_atomic_uint64;

0 commit comments

Comments
 (0)