Skip to content

Commit 434e6e1

Browse files
committed
Improve implementation of pg_attribute_always_inline.
Avoid compiler warnings on MSVC (which doesn't want to see both __forceinline and inline) and ancient GCC (which doesn't have __attribute__((always_inline))). Don't force inline-ing when building at -O0, as the programmer is probably hoping for exact source-to-object-line correspondence in that case. (For the moment this only works for GCC; maybe we can extend it later.) Make pg_attribute_always_inline be syntactically a drop-in replacement for inline, rather than an additional wart. And improve the comments. Thomas Munro and Michail Nikolaev, small tweaks by me Discussion: https://postgr.es/m/32278.1514863068@sss.pgh.pa.us Discussion: https://postgr.es/m/CANtu0oiYp74brgntKOxgg1FK5+t8uQ05guSiFU6FYz_5KUhr6Q@mail.gmail.com
1 parent e0a0dec commit 434e6e1

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/backend/executor/nodeHashjoin.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ static void ExecParallelHashJoinPartitionOuter(HashJoinState *node);
161161
* the other one is "outer".
162162
* ----------------------------------------------------------------
163163
*/
164-
pg_attribute_always_inline
165-
static inline TupleTableSlot *
164+
static pg_attribute_always_inline TupleTableSlot *
166165
ExecHashJoinImpl(PlanState *pstate, bool parallel)
167166
{
168167
HashJoinState *node = castNode(HashJoinState, pstate);

src/include/c.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,21 @@
146146
#define pg_attribute_noreturn()
147147
#endif
148148

149-
/* GCC, Sunpro and XLC support always_inline via __attribute__ */
150-
#if defined(__GNUC__)
151-
#define pg_attribute_always_inline __attribute__((always_inline))
152-
/* msvc via a special keyword */
149+
/*
150+
* Use "pg_attribute_always_inline" in place of "inline" for functions that
151+
* we wish to force inlining of, even when the compiler's heuristics would
152+
* choose not to. But, if possible, don't force inlining in unoptimized
153+
* debug builds.
154+
*/
155+
#if (defined(__GNUC__) && __GNUC__ > 3 && defined(__OPTIMIZE__)) || defined(__SUNPRO_C) || defined(__IBMC__)
156+
/* GCC > 3, Sunpro and XLC support always_inline via __attribute__ */
157+
#define pg_attribute_always_inline __attribute__((always_inline)) inline
153158
#elif defined(_MSC_VER)
159+
/* MSVC has a special keyword for this */
154160
#define pg_attribute_always_inline __forceinline
155161
#else
156-
#define pg_attribute_always_inline
162+
/* Otherwise, the best we can do is to say "inline" */
163+
#define pg_attribute_always_inline inline
157164
#endif
158165

159166
/*

0 commit comments

Comments
 (0)