Skip to content

Commit

Permalink
Require and limit features to C11
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
devreal committed Jul 9, 2024
1 parent b4bf0f8 commit f375299
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 39 deletions.
46 changes: 17 additions & 29 deletions config/opal_setup_cc.m4
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ AC_DEFUN([OPAL_SETUP_CC],[
AC_REQUIRE([_OPAL_PROG_CC])
AC_REQUIRE([AM_PROG_CC_C_O])

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])
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])

OPAL_PROG_CC_C11

Expand All @@ -179,33 +179,24 @@ AC_DEFUN([OPAL_SETUP_CC],[
OPAL_C_COMPILER_VENDOR([opal_c_vendor])

if test $opal_cv_c11_supported = no ; then
# It is not currently an error if C11 support is not available. Uncomment the
# following lines and update the warning when we require a C11 compiler.
# AC_MSG_WARNING([Open MPI requires a C11 (or newer) compiler])
# AC_MSG_ERROR([Aborting.])
# From Open MPI 1.7 on we require a C99 compliant compiler
dnl with autoconf 2.70 AC_PROG_CC makes AC_PROG_CC_C99 obsolete
m4_version_prereq([2.70],
[],
[AC_PROG_CC_C99])
# The result of AC_PROG_CC_C99 is stored in ac_cv_prog_cc_c99
if test "x$ac_cv_prog_cc_c99" = xno ; then
AC_MSG_WARN([Open MPI requires a C99 (or newer) compiler. C11 is recommended.])
AC_MSG_ERROR([Aborting.])
fi

# Get the correct result for C11 support flags now that the compiler flags have
# changed
OPAL_PROG_CC_C11_HELPER([], [], [])
# C11 is required
AC_MSG_WARN([Open MPI requires a C11 (or newer) compiler. C11 is required.])
AC_MSG_ERROR([Aborting.])
elif test $opal_cv_c11_flag_required = no ; then
# Check if the compiler accepts -std=c11
# this helps avoid accidentally using newer features
opal_prog_cc_c11_flags="-std=c11 -c11"
AC_MSG_NOTICE([checking if $CC supports C11 standard flag])
for flag in $(echo $opal_prog_cc_c11_flags | tr ' ' '\n') ; do
_OPAL_CHECK_SPECIFIC_CFLAGS($flag, std_c11)
if test "x$opal_cv_cc_std_c11" == "x1" ; then
OPAL_FLAGS_APPEND_UNIQ([CFLAGS], ["$flag"])
AC_MSG_NOTICE([using $flag to ensure C11 support])
break
fi
done
fi

# Check if compiler support __thread
OPAL_CC_HELPER([if $CC $1 supports __thread], [opal_prog_cc__thread_available],
[],[[static __thread int foo = 1;++foo;]])

OPAL_CC_HELPER([if $CC $1 supports C11 _Thread_local], [opal_prog_cc_c11_helper__Thread_local_available],
[],[[static _Thread_local int foo = 1;++foo;]])

dnl At this time Open MPI only needs thread local and the atomic convenience types for C11 support. These
dnl will likely be required in the future.
AC_DEFINE_UNQUOTED([OPAL_C_HAVE__THREAD_LOCAL], [$opal_prog_cc_c11_helper__Thread_local_available],
Expand All @@ -223,9 +214,6 @@ AC_DEFUN([OPAL_SETUP_CC],[
AC_DEFINE_UNQUOTED([OPAL_C_HAVE__STATIC_ASSERT], [$opal_prog_cc_c11_helper__static_assert_available],
[Whether C compiler support _Static_assert keyword])

AC_DEFINE_UNQUOTED([OPAL_C_HAVE___THREAD], [$opal_prog_cc__thread_available],
[Whether C compiler supports __thread])

# Check for standard headers, needed here because needed before
# the types checks. This is only necessary for Autoconf < v2.70.
m4_version_prereq([2.70],
Expand Down
10 changes: 0 additions & 10 deletions opal/mca/threads/thread_usage.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,7 @@ OPAL_THREAD_DEFINE_ATOMIC_SWAP(int64_t, int64_t, 64)
# define OPAL_ATOMIC_SWAP_64 opal_thread_swap_64

/* thread local storage */
#if OPAL_C_HAVE__THREAD_LOCAL
# define opal_thread_local _Thread_local
# define OPAL_HAVE_THREAD_LOCAL 1

#elif OPAL_C_HAVE___THREAD /* OPAL_C_HAVE__THREAD_LOCAL */
# define opal_thread_local __thread
# define OPAL_HAVE_THREAD_LOCAL 1
#endif /* OPAL_C_HAVE___THREAD */

#if !defined(OPAL_HAVE_THREAD_LOCAL)
# define OPAL_HAVE_THREAD_LOCAL 0
#endif /* !defined(OPAL_HAVE_THREAD_LOCAL) */

#endif /* OPAL_MCA_THREADS_THREAD_USAGE_H */

0 comments on commit f375299

Please sign in to comment.