Calling gcc: Pass optc flags as last options (#14452)
authorRoland Senn <rsx@bluewin.ch>
Thu, 22 Nov 2018 16:52:33 +0000 (11:52 -0500)
committerBen Gamari <ben@smart-cactus.org>
Thu, 22 Nov 2018 18:14:02 +0000 (13:14 -0500)
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

compiler/main/SysTools/Tasks.hs
testsuite/tests/driver/Makefile
testsuite/tests/driver/T14452.hs [new file with mode: 0644]
testsuite/tests/driver/T14452.stdout [new file with mode: 0644]
testsuite/tests/driver/all.T

index 66cc1ec..a986db2 100644 (file)
@@ -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
index 540f158..e60df7a 100644 (file)
@@ -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 (file)
index 0000000..2fb3cfc
--- /dev/null
@@ -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 (file)
index 0000000..d15a710
--- /dev/null
@@ -0,0 +1 @@
+-O3
index be91a26..a33dba1 100644 (file)
@@ -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'])