Skip to content

Commit de6fd1c

Browse files
committed
Rely on inline functions even if that causes warnings in older compilers.
So far we have worked around the fact that some very old compilers do not support 'inline' functions by only using inline functions conditionally (or not at all). Since such compilers are very rare by now, we have decided to rely on inline functions from 9.6 onwards. To avoid breaking these old compilers inline is defined away when not supported. That'll cause "function x defined but not used" type of warnings, but since nobody develops on such compilers anymore that's ok. This change in policy will allow us to more easily employ inline functions. I chose to remove code previously conditional on PG_USE_INLINE as it seemed confusing to have code dependent on a define that's always defined. Blacklisting of compilers, like in c53f738, now has to be done differently. A platform template can define PG_FORCE_DISABLE_INLINE to force inline to be defined empty. Discussion: [email protected]
1 parent a855118 commit de6fd1c

29 files changed

+92
-415
lines changed

config/c-compiler.m4

-34
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,6 @@ fi])# PGAC_C_SIGNED
1717

1818

1919

20-
# PGAC_C_INLINE
21-
# -------------
22-
# Check if the C compiler understands inline functions without being
23-
# noisy about unused static inline functions. Some older compilers
24-
# understand inline functions (as tested by AC_C_INLINE) but warn about
25-
# them if they aren't used in a translation unit.
26-
#
27-
# This test used to just define an inline function, but some compilers
28-
# (notably clang) got too smart and now warn about unused static
29-
# inline functions when defined inside a .c file, but not when defined
30-
# in an included header. Since the latter is what we want to use, test
31-
# to see if the warning appears when the function is in a header file.
32-
# Not pretty, but it works.
33-
#
34-
# Defines: inline, PG_USE_INLINE
35-
AC_DEFUN([PGAC_C_INLINE],
36-
[AC_C_INLINE
37-
AC_CACHE_CHECK([for quiet inline (no complaint if unreferenced)], pgac_cv_c_inline_quietly,
38-
[pgac_cv_c_inline_quietly=no
39-
if test "$ac_cv_c_inline" != no; then
40-
pgac_c_inline_save_werror=$ac_c_werror_flag
41-
ac_c_werror_flag=yes
42-
AC_LINK_IFELSE([AC_LANG_PROGRAM([#include "$srcdir/config/test_quiet_include.h"],[])],
43-
[pgac_cv_c_inline_quietly=yes])
44-
ac_c_werror_flag=$pgac_c_inline_save_werror
45-
fi])
46-
if test "$pgac_cv_c_inline_quietly" != no; then
47-
AC_DEFINE_UNQUOTED([PG_USE_INLINE], 1,
48-
[Define to 1 if "static inline" works without unwanted warnings from ]
49-
[compilations where static inline functions are defined but not called.])
50-
fi
51-
])# PGAC_C_INLINE
52-
53-
5420
# PGAC_C_PRINTF_ARCHETYPE
5521
# -----------------------
5622
# Set the format archetype used by gcc to check printf type functions. We

config/test_quiet_include.h

-18
This file was deleted.

configure

-38
Original file line numberDiff line numberDiff line change
@@ -11006,44 +11006,6 @@ _ACEOF
1100611006
;;
1100711007
esac
1100811008

11009-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for quiet inline (no complaint if unreferenced)" >&5
11010-
$as_echo_n "checking for quiet inline (no complaint if unreferenced)... " >&6; }
11011-
if ${pgac_cv_c_inline_quietly+:} false; then :
11012-
$as_echo_n "(cached) " >&6
11013-
else
11014-
pgac_cv_c_inline_quietly=no
11015-
if test "$ac_cv_c_inline" != no; then
11016-
pgac_c_inline_save_werror=$ac_c_werror_flag
11017-
ac_c_werror_flag=yes
11018-
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
11019-
/* end confdefs.h. */
11020-
#include "$srcdir/config/test_quiet_include.h"
11021-
int
11022-
main ()
11023-
{
11024-
11025-
;
11026-
return 0;
11027-
}
11028-
_ACEOF
11029-
if ac_fn_c_try_link "$LINENO"; then :
11030-
pgac_cv_c_inline_quietly=yes
11031-
fi
11032-
rm -f core conftest.err conftest.$ac_objext \
11033-
conftest$ac_exeext conftest.$ac_ext
11034-
ac_c_werror_flag=$pgac_c_inline_save_werror
11035-
fi
11036-
fi
11037-
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_c_inline_quietly" >&5
11038-
$as_echo "$pgac_cv_c_inline_quietly" >&6; }
11039-
if test "$pgac_cv_c_inline_quietly" != no; then
11040-
11041-
cat >>confdefs.h <<_ACEOF
11042-
#define PG_USE_INLINE 1
11043-
_ACEOF
11044-
11045-
fi
11046-
1104711009
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for printf format archetype" >&5
1104811010
$as_echo_n "checking for printf format archetype... " >&6; }
1104911011
if ${pgac_cv_printf_archetype+:} false; then :

configure.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ fi
13091309

13101310
m4_defun([AC_PROG_CC_STDC], []) dnl We don't want that.
13111311
AC_C_BIGENDIAN
1312-
PGAC_C_INLINE
1312+
AC_C_INLINE
13131313
PGAC_PRINTF_ARCHETYPE
13141314
AC_C_FLEXIBLE_ARRAY_MEMBER
13151315
PGAC_C_SIGNED

src/backend/lib/ilist.c

-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
*/
1919
#include "postgres.h"
2020

21-
/* See ilist.h */
22-
#define ILIST_INCLUDE_DEFINITIONS
23-
2421
#include "lib/ilist.h"
2522

2623
/*

src/backend/nodes/list.c

-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
*/
1616
#include "postgres.h"
1717

18-
/* see pg_list.h */
19-
#define PG_LIST_INCLUDE_DEFINITIONS
20-
2118
#include "nodes/pg_list.h"
2219

2320

src/backend/port/atomics.c

-7
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313
*/
1414
#include "postgres.h"
1515

16-
/*
17-
* We want the functions below to be inline; but if the compiler doesn't
18-
* support that, fall back on providing them as regular functions. See
19-
* STATIC_IF_INLINE in c.h.
20-
*/
21-
#define ATOMICS_INCLUDE_DEFINITIONS
22-
2316
#include "miscadmin.h"
2417
#include "port/atomics.h"
2518
#include "storage/spin.h"

src/backend/utils/adt/arrayfuncs.c

-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
#endif
2121
#include <math.h>
2222

23-
/* See arrayaccess.h */
24-
#define ARRAYACCESS_INCLUDE_DEFINITIONS
25-
2623
#include "access/htup_details.h"
2724
#include "catalog/pg_type.h"
2825
#include "funcapi.h"

src/backend/utils/mmgr/mcxt.c

-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
*-------------------------------------------------------------------------
2020
*/
2121

22-
/* see palloc.h. Must be before postgres.h */
23-
#define MCXT_INCLUDE_DEFINITIONS
24-
2522
#include "postgres.h"
2623

2724
#include "miscadmin.h"

src/backend/utils/sort/sortsupport.c

-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515

1616
#include "postgres.h"
1717

18-
/* See sortsupport.h */
19-
#define SORTSUPPORT_INCLUDE_DEFINITIONS
20-
2118
#include "access/nbtree.h"
2219
#include "fmgr.h"
2320
#include "utils/lsyscache.h"

src/include/access/gin_private.h

+1-7
Original file line numberDiff line numberDiff line change
@@ -952,11 +952,8 @@ extern ItemPointer ginMergeItemPointers(ItemPointerData *a, uint32 na,
952952

953953
/*
954954
* Merging the results of several gin scans compares item pointers a lot,
955-
* so we want this to be inlined. But if the compiler doesn't support that,
956-
* fall back on the non-inline version from itemptr.c. See STATIC_IF_INLINE in
957-
* c.h.
955+
* so we want this to be inlined.
958956
*/
959-
#ifdef PG_USE_INLINE
960957
static inline int
961958
ginCompareItemPointers(ItemPointer a, ItemPointer b)
962959
{
@@ -970,8 +967,5 @@ ginCompareItemPointers(ItemPointer a, ItemPointer b)
970967
else
971968
return -1;
972969
}
973-
#else
974-
#define ginCompareItemPointers(a, b) ItemPointerCompare(a, b)
975-
#endif /* PG_USE_INLINE */
976970

977971
#endif /* GIN_PRIVATE_H */

src/include/c.h

+14-28
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,20 @@
5353
#include "pg_config.h"
5454
#include "pg_config_manual.h" /* must be after pg_config.h */
5555

56+
/*
57+
* Force disable inlining if PG_FORCE_DISABLE_INLINE is defined. This is used
58+
* to work around compiler bugs and might also be useful for investigatory
59+
* purposes.
60+
*
61+
* This is done early (in slightly the wrong section) for two reasons: a) we
62+
* don't want to include headers with different settings of this b)
63+
* functionality later in this file might want to rely on inline functions.
64+
*/
65+
#ifdef PG_FORCE_DISABLE_INLINE
66+
#undef inline
67+
#define inline
68+
#endif
69+
5670
/*
5771
* We always rely on the WIN32 macro being set by our build system,
5872
* but _WIN32 is the compiler pre-defined macro. So make sure we define
@@ -920,34 +934,6 @@ typedef NameData *Name;
920934
#endif
921935

922936

923-
/*
924-
* Function inlining support -- Allow modules to define functions that may be
925-
* inlined, if the compiler supports it.
926-
*
927-
* The function bodies must be defined in the module header prefixed by
928-
* STATIC_IF_INLINE, protected by a cpp symbol that the module's .c file must
929-
* define. If the compiler doesn't support inline functions, the function
930-
* definitions are pulled in by the .c file as regular (not inline) symbols.
931-
*
932-
* The header must also declare the functions' prototypes, protected by
933-
* !PG_USE_INLINE.
934-
*/
935-
936-
/* declarations which are only visible when not inlining and in the .c file */
937-
#ifdef PG_USE_INLINE
938-
#define STATIC_IF_INLINE static inline
939-
#else
940-
#define STATIC_IF_INLINE
941-
#endif /* PG_USE_INLINE */
942-
943-
/* declarations which are marked inline when inlining, extern otherwise */
944-
#ifdef PG_USE_INLINE
945-
#define STATIC_IF_INLINE_DECLARE static inline
946-
#else
947-
#define STATIC_IF_INLINE_DECLARE extern
948-
#endif /* PG_USE_INLINE */
949-
950-
951937
/* ----------------------------------------------------------------
952938
* Section 8: random stuff
953939
* ----------------------------------------------------------------

0 commit comments

Comments
 (0)