Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d9a14f6

Browse files
committed
Test for sparc int128 alignmend bug by Tom Lane
1 parent ac653af commit d9a14f6

File tree

2 files changed

+101
-15
lines changed

2 files changed

+101
-15
lines changed

config/c-compiler.m4

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,29 +108,59 @@ AC_DEFUN([PGAC_TYPE_128BIT_INT],
108108
[AC_CACHE_CHECK([for __int128], [pgac_cv__128bit_int],
109109
[AC_LINK_IFELSE([AC_LANG_PROGRAM([
110110
/*
111+
* We don't actually run this test, just link it to verify that any support
112+
* functions needed for __int128 are present.
113+
*
111114
* These are globals to discourage the compiler from folding all the
112115
* arithmetic tests down to compile-time constants. We do not have
113-
* convenient support for 64bit literals at this point...
116+
* convenient support for 128bit literals at this point...
114117
*/
115118
__int128 a = 48828125;
116-
__int128 b = 97656255;
119+
__int128 b = 97656250;
117120
],[
118121
__int128 c,d;
119122
a = (a << 12) + 1; /* 200000000001 */
120123
b = (b << 12) + 5; /* 400000000005 */
121-
/* use the most relevant arithmetic ops */
124+
/* try the most relevant arithmetic ops */
122125
c = a * b;
123126
d = (c + b) / b;
124-
/* return different values, to prevent optimizations */
127+
/* must use the results, else compiler may optimize arithmetic away */
125128
if (d != a+1)
126-
return 0;
127-
return 1;
129+
return 1;
128130
])],
129131
[pgac_cv__128bit_int=yes],
130132
[pgac_cv__128bit_int=no])])
131133
if test x"$pgac_cv__128bit_int" = xyes ; then
132-
AC_DEFINE(PG_INT128_TYPE, __int128, [Define to the name of a signed 128-bit integer type.])
133-
AC_CHECK_ALIGNOF(PG_INT128_TYPE)
134+
# Some versions of gcc have problems passing __int128 function arguments
135+
# when using non-default alignment. Test that, if not cross-compiling.
136+
AC_CACHE_CHECK([for __int128 alignment bug], [pgac_cv__128bit_int_bug],
137+
[AC_RUN_IFELSE([AC_LANG_PROGRAM([
138+
/* This must match the corresponding code in c.h: */
139+
#if defined(__GNUC__) || defined(__SUNPRO_C) || defined(__IBMC__)
140+
#define pg_attribute_aligned(a) __attribute__((aligned(a)))
141+
#endif
142+
typedef __int128 int128a
143+
#if defined(pg_attribute_aligned)
144+
pg_attribute_aligned(8)
145+
#endif
146+
;
147+
int128a holder;
148+
void pass_by_val(void *buffer, int128a par) { holder = par; }
149+
],[
150+
long int i64 = 97656225L << 12;
151+
int128a q;
152+
pass_by_val(main, (int128a) i64);
153+
q = (int128a) i64;
154+
if (q != holder)
155+
return 1;
156+
])],
157+
[pgac_cv__128bit_int_bug=ok],
158+
[pgac_cv__128bit_int_bug=broken],
159+
[pgac_cv__128bit_int_bug=assuming-ok])])
160+
if test x"$pgac_cv__128bit_int_bug" != xbroken ; then
161+
AC_DEFINE(PG_INT128_TYPE, __int128, [Define to the name of a signed 128-bit integer type.])
162+
AC_CHECK_ALIGNOF(PG_INT128_TYPE)
163+
fi
134164
fi])# PGAC_TYPE_128BIT_INT
135165

136166

configure

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15057,12 +15057,15 @@ else
1505715057
/* end confdefs.h. */
1505815058
1505915059
/*
15060+
* We don't actually run this test, just link it to verify that any support
15061+
* functions needed for __int128 are present.
15062+
*
1506015063
* These are globals to discourage the compiler from folding all the
1506115064
* arithmetic tests down to compile-time constants. We do not have
15062-
* convenient support for 64bit literals at this point...
15065+
* convenient support for 128bit literals at this point...
1506315066
*/
1506415067
__int128 a = 48828125;
15065-
__int128 b = 97656255;
15068+
__int128 b = 97656250;
1506615069
1506715070
int
1506815071
main ()
@@ -15071,13 +15074,12 @@ main ()
1507115074
__int128 c,d;
1507215075
a = (a << 12) + 1; /* 200000000001 */
1507315076
b = (b << 12) + 5; /* 400000000005 */
15074-
/* use the most relevant arithmetic ops */
15077+
/* try the most relevant arithmetic ops */
1507515078
c = a * b;
1507615079
d = (c + b) / b;
15077-
/* return different values, to prevent optimizations */
15080+
/* must use the results, else compiler may optimize arithmetic away */
1507815081
if (d != a+1)
15079-
return 0;
15080-
return 1;
15082+
return 1;
1508115083
1508215084
;
1508315085
return 0;
@@ -15094,10 +15096,63 @@ fi
1509415096
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv__128bit_int" >&5
1509515097
$as_echo "$pgac_cv__128bit_int" >&6; }
1509615098
if test x"$pgac_cv__128bit_int" = xyes ; then
15099+
# Some versions of gcc have problems passing __int128 function arguments
15100+
# when using non-default alignment. Test that, if not cross-compiling.
15101+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __int128 alignment bug" >&5
15102+
$as_echo_n "checking for __int128 alignment bug... " >&6; }
15103+
if ${pgac_cv__128bit_int_bug+:} false; then :
15104+
$as_echo_n "(cached) " >&6
15105+
else
15106+
if test "$cross_compiling" = yes; then :
15107+
pgac_cv__128bit_int_bug=assuming-ok
15108+
else
15109+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
15110+
/* end confdefs.h. */
15111+
15112+
/* This must match the corresponding code in c.h: */
15113+
#if defined(__GNUC__) || defined(__SUNPRO_C) || defined(__IBMC__)
15114+
#define pg_attribute_aligned(a) __attribute__((aligned(a)))
15115+
#endif
15116+
typedef __int128 int128a
15117+
#if defined(pg_attribute_aligned)
15118+
pg_attribute_aligned(8)
15119+
#endif
15120+
;
15121+
int128a holder;
15122+
void pass_by_val(void *buffer, int128a par) { holder = par; }
15123+
15124+
int
15125+
main ()
15126+
{
15127+
15128+
long int i64 = 97656225L << 12;
15129+
int128a q;
15130+
pass_by_val(main, (int128a) i64);
15131+
q = (int128a) i64;
15132+
if (q != holder)
15133+
return 1;
15134+
15135+
;
15136+
return 0;
15137+
}
15138+
_ACEOF
15139+
if ac_fn_c_try_run "$LINENO"; then :
15140+
pgac_cv__128bit_int_bug=ok
15141+
else
15142+
pgac_cv__128bit_int_bug=broken
15143+
fi
15144+
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
15145+
conftest.$ac_objext conftest.beam conftest.$ac_ext
15146+
fi
15147+
15148+
fi
15149+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv__128bit_int_bug" >&5
15150+
$as_echo "$pgac_cv__128bit_int_bug" >&6; }
15151+
if test x"$pgac_cv__128bit_int_bug" != xbroken ; then
1509715152

1509815153
$as_echo "#define PG_INT128_TYPE __int128" >>confdefs.h
1509915154

15100-
# The cast to long int works around a bug in the HP C Compiler,
15155+
# The cast to long int works around a bug in the HP C Compiler,
1510115156
# see AC_CHECK_SIZEOF for more information.
1510215157
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking alignment of PG_INT128_TYPE" >&5
1510315158
$as_echo_n "checking alignment of PG_INT128_TYPE... " >&6; }
@@ -15132,6 +15187,7 @@ cat >>confdefs.h <<_ACEOF
1513215187
_ACEOF
1513315188

1513415189

15190+
fi
1513515191
fi
1513615192

1513715193
# Check for various atomic operations now that we have checked how to declare

0 commit comments

Comments
 (0)