[commit: ghc] master: Calling gcc: Pass optc flags as last options (#14452) (f2d9fb0)

git at git.haskell.org git at git.haskell.org
Thu Nov 22 18:47:13 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/f2d9fb0c288788abeb796a13d600295a526290cd/ghc

>---------------------------------------------------------------

commit f2d9fb0c288788abeb796a13d600295a526290cd
Author: Roland Senn <rsx at bluewin.ch>
Date:   Thu Nov 22 11:52:33 2018 -0500

    Calling gcc: Pass optc flags as last options (#14452)
    
    Test Plan: make test TEST=T14452
    
    Reviewers: hvr, bgamari, monoidal, thomie, osa1
    
    Reviewed By: osa1
    
    Subscribers: rwbarton, carter
    
    GHC Trac Issues: #14452
    
    Differential Revision: https://phabricator.haskell.org/D5318


>---------------------------------------------------------------

f2d9fb0c288788abeb796a13d600295a526290cd
 compiler/main/SysTools/Tasks.hs      | 4 +++-
 testsuite/tests/driver/Makefile      | 5 +++++
 testsuite/tests/driver/T14452.hs     | 5 +++++
 testsuite/tests/driver/T14452.stdout | 1 +
 testsuite/tests/driver/all.T         | 1 +
 5 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/compiler/main/SysTools/Tasks.hs b/compiler/main/SysTools/Tasks.hs
index 66cc1ec..a986db2 100644
--- a/compiler/main/SysTools/Tasks.hs
+++ b/compiler/main/SysTools/Tasks.hs
@@ -62,7 +62,9 @@ runCc :: DynFlags -> [Option] -> IO ()
 runCc dflags args =   do
   let (p,args0) = pgm_c dflags
       args1 = map Option (getOpts dflags opt_c)
-      args2 = args0 ++ args1 ++ args
+      args2 = args0 ++ 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
   runSomethingResponseFile dflags cc_filter "C Compiler" p args2 mb_env
  where
diff --git a/testsuite/tests/driver/Makefile b/testsuite/tests/driver/Makefile
index 540f158..e60df7a 100644
--- a/testsuite/tests/driver/Makefile
+++ b/testsuite/tests/driver/Makefile
@@ -668,3 +668,8 @@ T12955:
 T12971:
 	mkdir -p ä
 	TMP=ä "$(TEST_HC)" $(TEST_HC_OPTS) --make T12971
+
+.PHONY: T14452
+T14452:
+	"$(TEST_HC)" $(TEST_HC_OPTS) -v -c -O2 T14452.hs 2>&1 | grep 'O3' \
+	| awk 'NF{print $$NF; exit}'  # awk: extract last word of line
diff --git a/testsuite/tests/driver/T14452.hs b/testsuite/tests/driver/T14452.hs
new file mode 100644
index 0000000..2fb3cfc
--- /dev/null
+++ b/testsuite/tests/driver/T14452.hs
@@ -0,0 +1,5 @@
+{-# LANGUAGE CApiFFI #-}
+{-# OPTIONS_GHC -optc-O3 #-}
+
+module T14452 where
+foreign import capi unsafe "stdlib.h exit" c_exit :: Int -> IO ()
diff --git a/testsuite/tests/driver/T14452.stdout b/testsuite/tests/driver/T14452.stdout
new file mode 100644
index 0000000..d15a710
--- /dev/null
+++ b/testsuite/tests/driver/T14452.stdout
@@ -0,0 +1 @@
+-O3
diff --git a/testsuite/tests/driver/all.T b/testsuite/tests/driver/all.T
index be91a26..a33dba1 100644
--- a/testsuite/tests/driver/all.T
+++ b/testsuite/tests/driver/all.T
@@ -283,4 +283,5 @@ test('inline-check', omit_ways(['hpc', 'profasm'])
                    , compile
 		   , ['-dinline-check foo -O -ddebug-output'])
 
+test('T14452', [], run_command, ['$MAKE -s --no-print-directory T14452'])
 test('T15396', normal, compile_and_run, ['-package ghc'])



More information about the ghc-commits mailing list