[commit: ghc] ghc-8.0: DriverPipeline: Fix 'unused arguments' warnings from Clang (6babb89)

git at git.haskell.org git at git.haskell.org
Wed Mar 23 16:37:58 UTC 2016


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

On branch  : ghc-8.0
Link       : http://ghc.haskell.org/trac/ghc/changeset/6babb89baac43058bcb4a86edbba0560f01f4670/ghc

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

commit 6babb89baac43058bcb4a86edbba0560f01f4670
Author: Erik de Castro Lopo <erikd at mega-nerd.com>
Date:   Sun Mar 13 15:28:11 2016 +1100

    DriverPipeline: Fix 'unused arguments' warnings from Clang
    
    When using Clang as the C compiler, over 100 tests were failing
    due to Clang reporting that some command line arguments were not
    being used. These warnings only occur when Clang is compiling
    assembler files which happens in two places, one of which already
    conditionally adding `-Qunused-arguments` to the command line when
    the compiler was Clang. This fixes the other.
    
    Test Plan: validate with clang as the C compiler
    
    Reviewers: bgamari, hvr, austin, rwbarton
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D1998
    
    GHC Trac Issues: #11684
    
    (cherry picked from commit 46f9a476e17714e27d893b491cc0dcf68c745249)


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

6babb89baac43058bcb4a86edbba0560f01f4670
 compiler/main/DriverPipeline.hs | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs
index 455f613..c9174f4 100644
--- a/compiler/main/DriverPipeline.hs
+++ b/compiler/main/DriverPipeline.hs
@@ -1576,16 +1576,32 @@ mkExtraObj dflags extn xs
  = do cFile <- newTempName dflags extn
       oFile <- newTempName dflags "o"
       writeFile cFile xs
-      let rtsDetails = getPackageDetails dflags rtsUnitId
-          pic_c_flags = picCCOpts dflags
+      ccInfo <- liftIO $ getCompilerInfo dflags
       SysTools.runCc dflags
-                     ([Option        "-c",
-                       FileOption "" cFile,
-                       Option        "-o",
-                       FileOption "" oFile]
-                      ++ map (FileOption "-I") (includeDirs rtsDetails)
-                      ++ map Option pic_c_flags)
+                ([Option        "-c",
+                  FileOption "" cFile,
+                  Option        "-o",
+                  FileOption "" oFile]
+                 ++ if extn /= "s"
+                        then cOpts
+                        else asmOpts ccInfo)
       return oFile
+    where
+      -- Pass a different set of options to the C compiler depending one whether
+      -- we're compiling C or assembler. When compiling C, we pass the usual
+      -- set of include directories and PIC flags.
+      cOpts = map Option (picCCOpts dflags)
+                    ++ map (FileOption "-I")
+                            (includeDirs $ getPackageDetails dflags rtsUnitId)
+
+      -- When compiling assembler code, we drop the usual C options, and if the
+      -- compiler is Clang, we add an extra argument to tell Clang to ignore
+      -- unused command line options. See trac #11684.
+      asmOpts ccInfo =
+            if any (ccInfo ==) [Clang, AppleClang, AppleClang51]
+                then [Option "-Qunused-arguments"]
+                else []
+
 
 -- When linking a binary, we need to create a C main() function that
 -- starts everything off.  This used to be compiled statically as part



More information about the ghc-commits mailing list