Skip to content

Commit f375299

Browse files
committed
Require and limit features to C11
Error out if the compiler does not support C11 and limit the standard to C11 if the compiler accepts a standard flag. This limit prevents us from using features of newer standard versions. Also removes support for `__thread` since we now rely on C11 `_Thread_local`. Signed-off-by: Joseph Schuchart <[email protected]>
1 parent b4bf0f8 commit f375299

File tree

2 files changed

+17
-39
lines changed

2 files changed

+17
-39
lines changed

config/opal_setup_cc.m4

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ AC_DEFUN([OPAL_SETUP_CC],[
170170
AC_REQUIRE([_OPAL_PROG_CC])
171171
AC_REQUIRE([AM_PROG_CC_C_O])
172172

173-
OPAL_VAR_SCOPE_PUSH([opal_prog_cc_c11_helper__Thread_local_available opal_prog_cc_c11_helper_atomic_var_available opal_prog_cc_c11_helper__Atomic_available opal_prog_cc_c11_helper__static_assert_available opal_prog_cc_c11_helper__Generic_available opal_prog_cc__thread_available opal_prog_cc_c11_helper_atomic_fetch_xor_explicit_available opal_prog_cc_c11_helper_proper__Atomic_support_in_atomics])
173+
OPAL_VAR_SCOPE_PUSH([opal_prog_cc_c11_helper__Thread_local_available opal_prog_cc_c11_helper_atomic_var_available opal_prog_cc_c11_helper__Atomic_available opal_prog_cc_c11_helper__static_assert_available opal_prog_cc_c11_helper__Generic_available opal_prog_cc_c11_helper_atomic_fetch_xor_explicit_available opal_prog_cc_c11_helper_proper__Atomic_support_in_atomics])
174174

175175
OPAL_PROG_CC_C11
176176

@@ -179,33 +179,24 @@ AC_DEFUN([OPAL_SETUP_CC],[
179179
OPAL_C_COMPILER_VENDOR([opal_c_vendor])
180180

181181
if test $opal_cv_c11_supported = no ; then
182-
# It is not currently an error if C11 support is not available. Uncomment the
183-
# following lines and update the warning when we require a C11 compiler.
184-
# AC_MSG_WARNING([Open MPI requires a C11 (or newer) compiler])
185-
# AC_MSG_ERROR([Aborting.])
186-
# From Open MPI 1.7 on we require a C99 compliant compiler
187-
dnl with autoconf 2.70 AC_PROG_CC makes AC_PROG_CC_C99 obsolete
188-
m4_version_prereq([2.70],
189-
[],
190-
[AC_PROG_CC_C99])
191-
# The result of AC_PROG_CC_C99 is stored in ac_cv_prog_cc_c99
192-
if test "x$ac_cv_prog_cc_c99" = xno ; then
193-
AC_MSG_WARN([Open MPI requires a C99 (or newer) compiler. C11 is recommended.])
194-
AC_MSG_ERROR([Aborting.])
195-
fi
196-
197-
# Get the correct result for C11 support flags now that the compiler flags have
198-
# changed
199-
OPAL_PROG_CC_C11_HELPER([], [], [])
182+
# C11 is required
183+
AC_MSG_WARN([Open MPI requires a C11 (or newer) compiler. C11 is required.])
184+
AC_MSG_ERROR([Aborting.])
185+
elif test $opal_cv_c11_flag_required = no ; then
186+
# Check if the compiler accepts -std=c11
187+
# this helps avoid accidentally using newer features
188+
opal_prog_cc_c11_flags="-std=c11 -c11"
189+
AC_MSG_NOTICE([checking if $CC supports C11 standard flag])
190+
for flag in $(echo $opal_prog_cc_c11_flags | tr ' ' '\n') ; do
191+
_OPAL_CHECK_SPECIFIC_CFLAGS($flag, std_c11)
192+
if test "x$opal_cv_cc_std_c11" == "x1" ; then
193+
OPAL_FLAGS_APPEND_UNIQ([CFLAGS], ["$flag"])
194+
AC_MSG_NOTICE([using $flag to ensure C11 support])
195+
break
196+
fi
197+
done
200198
fi
201199

202-
# Check if compiler support __thread
203-
OPAL_CC_HELPER([if $CC $1 supports __thread], [opal_prog_cc__thread_available],
204-
[],[[static __thread int foo = 1;++foo;]])
205-
206-
OPAL_CC_HELPER([if $CC $1 supports C11 _Thread_local], [opal_prog_cc_c11_helper__Thread_local_available],
207-
[],[[static _Thread_local int foo = 1;++foo;]])
208-
209200
dnl At this time Open MPI only needs thread local and the atomic convenience types for C11 support. These
210201
dnl will likely be required in the future.
211202
AC_DEFINE_UNQUOTED([OPAL_C_HAVE__THREAD_LOCAL], [$opal_prog_cc_c11_helper__Thread_local_available],
@@ -223,9 +214,6 @@ AC_DEFUN([OPAL_SETUP_CC],[
223214
AC_DEFINE_UNQUOTED([OPAL_C_HAVE__STATIC_ASSERT], [$opal_prog_cc_c11_helper__static_assert_available],
224215
[Whether C compiler support _Static_assert keyword])
225216

226-
AC_DEFINE_UNQUOTED([OPAL_C_HAVE___THREAD], [$opal_prog_cc__thread_available],
227-
[Whether C compiler supports __thread])
228-
229217
# Check for standard headers, needed here because needed before
230218
# the types checks. This is only necessary for Autoconf < v2.70.
231219
m4_version_prereq([2.70],

opal/mca/threads/thread_usage.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -250,17 +250,7 @@ OPAL_THREAD_DEFINE_ATOMIC_SWAP(int64_t, int64_t, 64)
250250
# define OPAL_ATOMIC_SWAP_64 opal_thread_swap_64
251251

252252
/* thread local storage */
253-
#if OPAL_C_HAVE__THREAD_LOCAL
254253
# define opal_thread_local _Thread_local
255254
# define OPAL_HAVE_THREAD_LOCAL 1
256255

257-
#elif OPAL_C_HAVE___THREAD /* OPAL_C_HAVE__THREAD_LOCAL */
258-
# define opal_thread_local __thread
259-
# define OPAL_HAVE_THREAD_LOCAL 1
260-
#endif /* OPAL_C_HAVE___THREAD */
261-
262-
#if !defined(OPAL_HAVE_THREAD_LOCAL)
263-
# define OPAL_HAVE_THREAD_LOCAL 0
264-
#endif /* !defined(OPAL_HAVE_THREAD_LOCAL) */
265-
266256
#endif /* OPAL_MCA_THREADS_THREAD_USAGE_H */

0 commit comments

Comments
 (0)