Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
-
9e58b8a1
by Cheng Shao at 2026-02-11T16:08:10-05:00
7 changed files:
- configure.ac
- distrib/configure.ac.in
- m4/fp_cmm_cpp_cmd_with_args.m4
- rts/include/Stg.h
- testsuite/tests/ffi/should_run/all.T
- utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cc.hs
- utils/ghc-toolchain/src/GHC/Toolchain/Tools/Cpp.hs
Changes:
| ... | ... | @@ -671,8 +671,8 @@ FP_CC_IGNORE_UNUSED_ARGS([$CC], [CONF_CC_OPTS_STAGE2]) |
| 671 | 671 | |
| 672 | 672 | # CPP, CPPFLAGS
|
| 673 | 673 | # --with-cpp/-with-cpp-flags
|
| 674 | -dnl Note that we must do this after setting and using the C99 CPPFLAGS, or
|
|
| 675 | -dnl otherwise risk trying to configure the C99 and LD flags using -E as a CPPFLAG
|
|
| 674 | +dnl Note that we must do this after setting and using the C11 CPPFLAGS, or
|
|
| 675 | +dnl otherwise risk trying to configure the C11 and LD flags using -E as a CPPFLAG
|
|
| 676 | 676 | FP_CPP_CMD_WITH_ARGS([$CC_STAGE0],[CPPCmd_STAGE0],[CONF_CPP_OPTS_STAGE0])
|
| 677 | 677 | FP_CPP_CMD_WITH_ARGS([$CC],[CPPCmd],[CONF_CPP_OPTS_STAGE1])
|
| 678 | 678 | FP_CPP_CMD_WITH_ARGS([$CC],[CPPCmd],[CONF_CPP_OPTS_STAGE2])
|
| ... | ... | @@ -313,8 +313,8 @@ FP_CC_IGNORE_UNUSED_ARGS([$CC], [CONF_CC_OPTS_STAGE2]) |
| 313 | 313 | |
| 314 | 314 | # CPP, CPPFLAGS
|
| 315 | 315 | # --with-cpp/-with-cpp-flags
|
| 316 | -dnl Note that we must do this after setting and using the C99 CPPFLAGS, or
|
|
| 317 | -dnl otherwise risk trying to configure the C99 and LD flags using -E as a CPPFLAG
|
|
| 316 | +dnl Note that we must do this after setting and using the C11 CPPFLAGS, or
|
|
| 317 | +dnl otherwise risk trying to configure the C11 and LD flags using -E as a CPPFLAG
|
|
| 318 | 318 | FP_CPP_CMD_WITH_ARGS([$CC_STAGE0],[CPPCmd_STAGE0],[CONF_CPP_OPTS_STAGE0])
|
| 319 | 319 | FP_CPP_CMD_WITH_ARGS([$CC],[CPPCmd],[CONF_CPP_OPTS_STAGE1])
|
| 320 | 320 | FP_CPP_CMD_WITH_ARGS([$CC],[CPPCmd],[CONF_CPP_OPTS_STAGE2])
|
| ... | ... | @@ -56,6 +56,27 @@ else |
| 56 | 56 | AC_MSG_RESULT([no])
|
| 57 | 57 | fi
|
| 58 | 58 | |
| 59 | +AC_MSG_CHECKING([the C-- preprocessor for C11 support])
|
|
| 60 | +cat > conftest.c <<EOF
|
|
| 61 | +#include <stdio.h>
|
|
| 62 | +#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L
|
|
| 63 | +# error "Compiler does not advertise C11 conformance"
|
|
| 64 | +#endif
|
|
| 65 | +EOF
|
|
| 66 | +if "$CMM_CPP_CMD" $CMM_CPP_ARGS conftest.c -o conftest -g0 >/dev/null 2>&1; then
|
|
| 67 | + AC_MSG_RESULT([yes])
|
|
| 68 | +else
|
|
| 69 | + # Try -std=gnu11
|
|
| 70 | + if "$CMM_CPP_CMD" -std=gnu11 $CMM_CPP_ARGS conftest.c -o conftest -g0 >/dev/null 2>&1; then
|
|
| 71 | + $3="-std=gnu11 $$3"
|
|
| 72 | + AC_MSG_RESULT([needs -std=gnu11])
|
|
| 73 | + else
|
|
| 74 | + AC_MSG_ERROR([C11-compatible compiler needed])
|
|
| 75 | + fi
|
|
| 76 | +fi
|
|
| 77 | +rm -f conftest.c conftest.o conftest
|
|
| 78 | + |
|
| 79 | + |
|
| 59 | 80 | $2="$CMM_CPP_CMD"
|
| 60 | 81 | $3="$$3 $CMM_CPP_ARGS"
|
| 61 | 82 |
| ... | ... | @@ -31,8 +31,8 @@ |
| 31 | 31 | #define __STDC_VERSION__ 0
|
| 32 | 32 | #endif
|
| 33 | 33 | |
| 34 | -#if !(__STDC_VERSION__ >= 199901L) && !(__cplusplus >= 201103L)
|
|
| 35 | -# error __STDC_VERSION__ does not advertise C99, C++11 or later
|
|
| 34 | +#if !(__STDC_VERSION__ >= 201112L) && !(__cplusplus >= 201103L)
|
|
| 35 | +# error __STDC_VERSION__ does not advertise C11, C++11 or later
|
|
| 36 | 36 | #endif
|
| 37 | 37 | |
| 38 | 38 | /*
|
| ... | ... | @@ -49,10 +49,6 @@ |
| 49 | 49 | #if !defined(IN_STG_CODE)
|
| 50 | 50 | # define IN_STG_CODE 1
|
| 51 | 51 | |
| 52 | -// Turn on C99 for .hc code. This gives us the INFINITY and NAN
|
|
| 53 | -// constants from math.h, which we occasionally need to use in .hc (#1861)
|
|
| 54 | -# define _ISOC99_SOURCE
|
|
| 55 | - |
|
| 56 | 52 | // We need _BSD_SOURCE so that math.h defines things like gamma
|
| 57 | 53 | // on Linux
|
| 58 | 54 | # define _BSD_SOURCE
|
| ... | ... | @@ -103,7 +103,7 @@ test('T2276_ghci', [ only_ghci, |
| 103 | 103 | pre_cmd('$MAKE -s --no-print-directory T2276_ghci_setup ghciWayFlags=' + config.ghci_way_flags) ],
|
| 104 | 104 | compile_and_run, ['-fobject-code T2276_ghci_c.o'])
|
| 105 | 105 | |
| 106 | -test('T2469', normal, compile_and_run, ['-optc-std=gnu99'])
|
|
| 106 | +test('T2469', normal, compile_and_run, ['-optc-std=gnu11'])
|
|
| 107 | 107 | |
| 108 | 108 | test('T2594', [req_c], compile_and_run, ['T2594_c.c'])
|
| 109 | 109 |
| ... | ... | @@ -11,6 +11,7 @@ module GHC.Toolchain.Tools.Cc |
| 11 | 11 | , compileC
|
| 12 | 12 | , compileAsm
|
| 13 | 13 | , addPlatformDepCcFlags
|
| 14 | + , checkC11Support
|
|
| 14 | 15 | ) where
|
| 15 | 16 | |
| 16 | 17 | import Control.Monad
|
| ... | ... | @@ -50,8 +51,12 @@ findCc archOs llvmTarget progOpt = do |
| 50 | 51 | cc1 <- ignoreUnusedArgs cc0
|
| 51 | 52 | cc2 <- ccSupportsTarget archOs llvmTarget cc1
|
| 52 | 53 | checking "whether Cc works" $ checkCcWorks cc2
|
| 53 | - checkCcSupportsExtraViaCFlags cc2
|
|
| 54 | - return cc2
|
|
| 54 | + cc3 <- oneOf "cc doesn't support C11" $ map checkC11Support
|
|
| 55 | + [ cc2
|
|
| 56 | + , cc2 & _ccFlags %++ "-std=gnu11"
|
|
| 57 | + ]
|
|
| 58 | + checkCcSupportsExtraViaCFlags cc3
|
|
| 59 | + return cc3
|
|
| 55 | 60 | |
| 56 | 61 | checkCcWorks :: Cc -> M ()
|
| 57 | 62 | checkCcWorks cc = withTempDir $ \dir -> do
|
| ... | ... | @@ -83,6 +88,17 @@ ccSupportsTarget archOs target cc = |
| 83 | 88 | checking "whether Cc supports --target" $
|
| 84 | 89 | supportsTarget archOs _ccProgram checkCcWorks target cc
|
| 85 | 90 | |
| 91 | +checkC11Support :: Cc -> M Cc
|
|
| 92 | +checkC11Support cc = checking "for C11 support" $ withTempDir $ \dir -> do
|
|
| 93 | + let test_o = dir </> "test.o"
|
|
| 94 | + compileC cc test_o $ unlines
|
|
| 95 | + [ "#include <stdio.h>"
|
|
| 96 | + , "#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 201112L"
|
|
| 97 | + , "# error \"Compiler does not advertise C11 conformance\""
|
|
| 98 | + , "#endif"
|
|
| 99 | + ]
|
|
| 100 | + return cc
|
|
| 101 | + |
|
| 86 | 102 | checkCcSupportsExtraViaCFlags :: Cc -> M ()
|
| 87 | 103 | checkCcSupportsExtraViaCFlags cc = checking "whether cc supports extra via-c flags" $ withTempDir $ \dir -> do
|
| 88 | 104 | let test_o = dir </> "test.o"
|
| ... | ... | @@ -19,7 +19,7 @@ import GHC.Toolchain.Prelude |
| 19 | 19 | import GHC.Toolchain.Program
|
| 20 | 20 | |
| 21 | 21 | import GHC.Toolchain.Tools.Cc
|
| 22 | -import GHC.Toolchain.Utils (withTempDir, expectFileExists)
|
|
| 22 | +import GHC.Toolchain.Utils (withTempDir, oneOf, expectFileExists)
|
|
| 23 | 23 | |
| 24 | 24 | newtype Cpp = Cpp { cppProgram :: Program
|
| 25 | 25 | }
|
| ... | ... | @@ -160,7 +160,13 @@ findJsCpp progOpt cc = checking "for JavaScript C preprocessor" $ do |
| 160 | 160 | findCmmCpp :: ProgOpt -> Cc -> M CmmCpp
|
| 161 | 161 | findCmmCpp progOpt cc = checking "for a Cmm preprocessor" $ do
|
| 162 | 162 | -- Use the specified CPP or try to use the c compiler
|
| 163 | - cpp <- findProgram "Cmm preprocessor" progOpt [] <|> pure (programFromOpt progOpt (prgPath $ ccProgram cc) [])
|
|
| 163 | + foundCppProg <- findProgram "Cmm preprocessor" progOpt [] <|> pure (programFromOpt progOpt (prgPath $ ccProgram cc) [])
|
|
| 164 | + -- Check whether the C preprocessor needs -std=gnu11 (only very old toolchains need this)
|
|
| 165 | + Cc cpp <- oneOf "cc doesn't support C11" $ map checkC11Support
|
|
| 166 | + [ Cc foundCppProg
|
|
| 167 | + , Cc (foundCppProg & _prgFlags %++ "-std=gnu11")
|
|
| 168 | + ]
|
|
| 169 | + |
|
| 164 | 170 | cmmCppSupportsG0 <- withTempDir $ \dir -> do
|
| 165 | 171 | let conftest = dir </> "conftest.c"
|
| 166 | 172 | writeFile conftest "int main(void) {}"
|
| ... | ... | @@ -175,9 +181,14 @@ findCmmCpp progOpt cc = checking "for a Cmm preprocessor" $ do |
| 175 | 181 | findCpp :: ProgOpt -> Cc -> M Cpp
|
| 176 | 182 | findCpp progOpt cc = checking "for C preprocessor" $ do
|
| 177 | 183 | -- Use the specified CPP or try to use the c compiler
|
| 178 | - cpp <- findProgram "C preprocessor" progOpt [] <|> pure (programFromOpt progOpt (prgPath $ ccProgram cc) [])
|
|
| 184 | + foundCppProg <- findProgram "C preprocessor" progOpt [] <|> pure (programFromOpt progOpt (prgPath $ ccProgram cc) [])
|
|
| 185 | + -- Check whether the C preprocessor needs -std=gnu11 (only very old toolchains need this)
|
|
| 186 | + Cc cpp2 <- oneOf "cc doesn't support C11" $ map checkC11Support
|
|
| 187 | + [ Cc foundCppProg
|
|
| 188 | + , Cc (foundCppProg & _prgFlags %++ "-std=gnu11")
|
|
| 189 | + ]
|
|
| 179 | 190 | -- Always add the -E flag to the CPP, regardless of the user options
|
| 180 | - let cppProgram = addFlagIfNew "-E" cpp
|
|
| 191 | + let cppProgram = addFlagIfNew "-E" cpp2
|
|
| 181 | 192 | return Cpp{cppProgram}
|
| 182 | 193 | |
| 183 | 194 | --------------------------------------------------------------------------------
|