summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2019-06-03 18:51:17 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-06-13 23:34:41 -0400
commit7bc5d6c6578ab9d60a83b81c7cc14819afef32ba (patch)
tree63c2e2e2669a48965c5508a3787b62b14837889a /compiler
parent5ce63d52fed05371edb34b4f330c33bc85a45127 (diff)
downloadhaskell-7bc5d6c6578ab9d60a83b81c7cc14819afef32ba.tar.gz
Maintain separate flags for C++ compiler invocations
Previously we would pass flags intended for the C compiler to the C++ compiler (see #16738). This would cause, for instance, `-std=gnu99` to be passed to the C++ compiler, causing spurious test failures. Fix this by maintaining a separate set of flags for C++ compilation invocations.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/ghci/Linker.hs2
-rw-r--r--compiler/main/DynFlags.hs4
-rw-r--r--compiler/main/Settings.hs2
-rw-r--r--compiler/main/SysTools.hs33
-rw-r--r--compiler/main/SysTools/Info.hs2
-rw-r--r--compiler/main/SysTools/Tasks.hs28
-rw-r--r--compiler/main/ToolSettings.hs2
7 files changed, 39 insertions, 34 deletions
diff --git a/compiler/ghci/Linker.hs b/compiler/ghci/Linker.hs
index 4f938a9a5f..e26dcce1ee 100644
--- a/compiler/ghci/Linker.hs
+++ b/compiler/ghci/Linker.hs
@@ -343,7 +343,7 @@ linkCmdLineLibs' hsc_env pls =
-- Add directories to library search paths, this only has an effect
-- on Windows. On Unix OSes this function is a NOP.
- let all_paths = let paths = takeDirectory (fst $ pgm_c dflags)
+ let all_paths = let paths = takeDirectory (pgm_c dflags)
: framework_paths
++ lib_paths_base
++ [ takeDirectory dll | DLLPath dll <- libspecs ]
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index 0b2b32d5bb..1d026f6c99 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -1421,7 +1421,7 @@ pgm_P :: DynFlags -> (String,[Option])
pgm_P dflags = toolSettings_pgm_P $ toolSettings dflags
pgm_F :: DynFlags -> String
pgm_F dflags = toolSettings_pgm_F $ toolSettings dflags
-pgm_c :: DynFlags -> (String,[Option])
+pgm_c :: DynFlags -> String
pgm_c dflags = toolSettings_pgm_c $ toolSettings dflags
pgm_a :: DynFlags -> (String,[Option])
pgm_a dflags = toolSettings_pgm_a $ toolSettings dflags
@@ -3049,7 +3049,7 @@ dynamic_flags_deps = [
$ hasArg $ \f -> alterToolSettings $ \s -> s { toolSettings_pgm_F = f }
, make_ord_flag defFlag "pgmc"
$ hasArg $ \f -> alterToolSettings $ \s -> s
- { toolSettings_pgm_c = (f,[])
+ { toolSettings_pgm_c = f
, -- Don't pass -no-pie with -pgmc
-- (see #15319)
toolSettings_ccSupportsNoPie = False
diff --git a/compiler/main/Settings.hs b/compiler/main/Settings.hs
index 5a5f5ca3c9..b8285340cf 100644
--- a/compiler/main/Settings.hs
+++ b/compiler/main/Settings.hs
@@ -119,7 +119,7 @@ sPgm_P :: Settings -> (String, [Option])
sPgm_P = toolSettings_pgm_P . sToolSettings
sPgm_F :: Settings -> String
sPgm_F = toolSettings_pgm_F . sToolSettings
-sPgm_c :: Settings -> (String, [Option])
+sPgm_c :: Settings -> String
sPgm_c = toolSettings_pgm_c . sToolSettings
sPgm_a :: Settings -> (String, [Option])
sPgm_a = toolSettings_pgm_a . sToolSettings
diff --git a/compiler/main/SysTools.hs b/compiler/main/SysTools.hs
index 2899ba383d..6db3f3243d 100644
--- a/compiler/main/SysTools.hs
+++ b/compiler/main/SysTools.hs
@@ -194,17 +194,18 @@ initSysTools top_dir
-- It would perhaps be nice to be able to override this
-- with the settings file, but it would be a little fiddly
-- to make that possible, so for now you can't.
- gcc_prog <- getToolSetting "C compiler command"
- gcc_args_str <- getSetting "C compiler flags"
+ cc_prog <- getToolSetting "C compiler command"
+ cc_args_str <- getSetting "C compiler flags"
+ cxx_args_str <- getSetting "C++ compiler flags"
gccSupportsNoPie <- getBooleanSetting "C compiler supports -no-pie"
cpp_prog <- getToolSetting "Haskell CPP command"
cpp_args_str <- getSetting "Haskell CPP flags"
- let unreg_gcc_args = if targetUnregisterised
- then ["-DNO_REGS", "-DUSE_MINIINTERPRETER"]
- else []
- cpp_args= map Option (words cpp_args_str)
- gcc_args = map Option (words gcc_args_str
- ++ unreg_gcc_args)
+ let unreg_cc_args = if targetUnregisterised
+ then ["-DNO_REGS", "-DUSE_MINIINTERPRETER"]
+ else []
+ cpp_args = map Option (words cpp_args_str)
+ cc_args = words cc_args_str ++ unreg_cc_args
+ cxx_args = words cxx_args_str
ldSupportsCompactUnwind <- getBooleanSetting "ld supports compact unwind"
ldSupportsBuildId <- getBooleanSetting "ld supports build-id"
ldSupportsFilelist <- getBooleanSetting "ld supports filelist"
@@ -236,11 +237,11 @@ initSysTools top_dir
-- Other things being equal, as and ld are simply gcc
- gcc_link_args_str <- getSetting "C compiler link flags"
- let as_prog = gcc_prog
- as_args = gcc_args
- ld_prog = gcc_prog
- ld_args = gcc_args ++ map Option (words gcc_link_args_str)
+ cc_link_args_str <- getSetting "C compiler link flags"
+ let as_prog = cc_prog
+ as_args = map Option cc_args
+ ld_prog = cc_prog
+ ld_args = map Option (cc_args ++ words cc_link_args_str)
-- We just assume on command line
lc_prog <- getSetting "LLVM llc command"
@@ -308,7 +309,7 @@ initSysTools top_dir
, toolSettings_pgm_L = unlit_path
, toolSettings_pgm_P = (cpp_prog, cpp_args)
, toolSettings_pgm_F = ""
- , toolSettings_pgm_c = (gcc_prog, gcc_args)
+ , toolSettings_pgm_c = cc_prog
, toolSettings_pgm_a = (as_prog, as_args)
, toolSettings_pgm_l = (ld_prog, ld_args)
, toolSettings_pgm_dll = (mkdll_prog,mkdll_args)
@@ -325,8 +326,8 @@ initSysTools top_dir
, toolSettings_opt_P = []
, toolSettings_opt_P_fingerprint = fingerprint0
, toolSettings_opt_F = []
- , toolSettings_opt_c = []
- , toolSettings_opt_cxx = []
+ , toolSettings_opt_c = cc_args
+ , toolSettings_opt_cxx = cxx_args
, toolSettings_opt_a = []
, toolSettings_opt_l = []
, toolSettings_opt_windres = []
diff --git a/compiler/main/SysTools/Info.hs b/compiler/main/SysTools/Info.hs
index 2dcd39549f..9aa9002c23 100644
--- a/compiler/main/SysTools/Info.hs
+++ b/compiler/main/SysTools/Info.hs
@@ -219,7 +219,7 @@ getCompilerInfo dflags = do
-- See Note [Run-time linker info].
getCompilerInfo' :: DynFlags -> IO CompilerInfo
getCompilerInfo' dflags = do
- let (pgm,_) = pgm_c dflags
+ let pgm = pgm_c dflags
-- Try to grab the info from the process output.
parseCompilerInfo _stdo stde _exitc
-- Regular GCC
diff --git a/compiler/main/SysTools/Tasks.hs b/compiler/main/SysTools/Tasks.hs
index a3d312e30e..1747d50be1 100644
--- a/compiler/main/SysTools/Tasks.hs
+++ b/compiler/main/SysTools/Tasks.hs
@@ -62,9 +62,9 @@ runPp dflags args = do
-- | Run compiler of C-like languages and raw objects (such as gcc or clang).
runCc :: Maybe ForeignSrcLang -> DynFlags -> [Option] -> IO ()
runCc mLanguage dflags args = do
- let (p,args0) = pgm_c dflags
+ let p = pgm_c dflags
args1 = map Option userOpts
- args2 = args0 ++ languageOptions ++ args ++ args1
+ args2 = languageOptions ++ args ++ args1
-- We take care to pass -optc flags in args1 last to ensure that the
-- user can override flags passed by GHC. See #14452.
mb_env <- getGccEnv args2
@@ -126,12 +126,16 @@ runCc mLanguage dflags args = do
-- -x c option.
(languageOptions, userOpts) = case mLanguage of
Nothing -> ([], userOpts_c)
- Just language -> ([Option "-x", Option languageName], opts) where
- (languageName, opts) = case language of
- LangCxx -> ("c++", userOpts_cxx)
- LangObjc -> ("objective-c", userOpts_c)
- LangObjcxx -> ("objective-c++", userOpts_cxx)
- _ -> ("c", userOpts_c)
+ Just language -> ([Option "-x", Option languageName], opts)
+ where
+ s = settings dflags
+ (languageName, opts) = case language of
+ LangC -> ("c", sOpt_c s ++ userOpts_c)
+ LangCxx -> ("c++", sOpt_cxx s ++ userOpts_cxx)
+ LangObjc -> ("objective-c", userOpts_c)
+ LangObjcxx -> ("objective-c++", userOpts_cxx)
+ LangAsm -> ("assembler", [])
+ RawObject -> ("c", []) -- claim C for lack of a better idea
userOpts_c = getOpts dflags opt_c
userOpts_cxx = getOpts dflags opt_cxx
@@ -333,7 +337,8 @@ runMkDLL dflags args = do
runWindres :: DynFlags -> [Option] -> IO ()
runWindres dflags args = do
- let (gcc, gcc_args) = pgm_c dflags
+ let cc = pgm_c dflags
+ cc_args = map Option (sOpt_c (settings dflags))
windres = pgm_windres dflags
opts = map Option (getOpts dflags opt_windres)
quote x = "\"" ++ x ++ "\""
@@ -341,8 +346,7 @@ runWindres dflags args = do
-- spaces then windres fails to run gcc. We therefore need
-- to tell it what command to use...
Option ("--preprocessor=" ++
- unwords (map quote (gcc :
- map showOpt gcc_args ++
+ unwords (map quote (cc :
map showOpt opts ++
["-E", "-xc", "-DRC_INVOKED"])))
-- ...but if we do that then if windres calls popen then
@@ -351,7 +355,7 @@ runWindres dflags args = do
-- See #1828.
: Option "--use-temp-file"
: args
- mb_env <- getGccEnv gcc_args
+ mb_env <- getGccEnv cc_args
runSomethingFiltered dflags id "Windres" windres args' Nothing mb_env
touch :: DynFlags -> String -> String -> IO ()
diff --git a/compiler/main/ToolSettings.hs b/compiler/main/ToolSettings.hs
index e15c6923e2..952e5869fc 100644
--- a/compiler/main/ToolSettings.hs
+++ b/compiler/main/ToolSettings.hs
@@ -22,7 +22,7 @@ data ToolSettings = ToolSettings
, toolSettings_pgm_L :: String
, toolSettings_pgm_P :: (String, [Option])
, toolSettings_pgm_F :: String
- , toolSettings_pgm_c :: (String, [Option])
+ , toolSettings_pgm_c :: String
, toolSettings_pgm_a :: (String, [Option])
, toolSettings_pgm_l :: (String, [Option])
, toolSettings_pgm_dll :: (String, [Option])