[commit: ghc] master: Use assembler-with-cpp mode when running CPP. (7b0695a)

Austin Seipp mad.one at gmail.com
Wed Jun 19 04:33:14 CEST 2013


Repository : http://darcs.haskell.org/ghc.git/

On branch  : master

https://github.com/ghc/ghc/commit/7b0695a887c13a431f898d89938e127faa3f4585

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

commit 7b0695a887c13a431f898d89938e127faa3f4585
Author: Austin Seipp <aseipp at pobox.com>
Date:   Mon Jun 17 06:12:08 2013 -0500

    Use assembler-with-cpp mode when running CPP.
    
    This is needed because Clang is very strict about C99 macro rules, which
    dictate that '#' in a body must have a token immediately following it for
    string-ification. In practice we break this all the time, because we do
    very weird stuff like:
    
        #define FOOBAR(xyz) \
        {-# SOME PRAGMA #-} \
        baz :: (xyz) \
        baz = ...
    
    where the leading '#' in in the macro body clearly breaks this rule.
    
    Signed-off-by: Austin Seipp <aseipp at pobox.com>

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

 compiler/main/DriverPipeline.hs | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs
index 7df823c..958bc9b 100644
--- a/compiler/main/DriverPipeline.hs
+++ b/compiler/main/DriverPipeline.hs
@@ -1140,10 +1140,10 @@ runPhase (RealPhase cc_phase) input_fn dflags
                 -- very weakly typed, being derived from C--.
                 ["-fno-strict-aliasing"]
 
-        let gcc_lang_opt | cc_phase `eqPhase` Ccpp  = "c++"
-                         | cc_phase `eqPhase` Cobjc = "objective-c"
+        let gcc_lang_opt | cc_phase `eqPhase` Ccpp    = "c++"
+                         | cc_phase `eqPhase` Cobjc   = "objective-c"
                          | cc_phase `eqPhase` Cobjcpp = "objective-c++"
-                         | otherwise                = "c"
+                         | otherwise                  = "c"
         liftIO $ SysTools.runCc dflags (
                 -- force the C compiler to interpret this file as C when
                 -- compiling .hc files, by adding the -x c option.
@@ -2042,8 +2042,12 @@ doCpp dflags raw input_fn output_fn = do
                     ++ map SysTools.Option backend_defs
                     ++ map SysTools.Option hscpp_opts
                     ++ map SysTools.Option sse_defs
+        -- Set the language mode to assembler-with-cpp when preprocessing. This
+        -- alleviates some of the C99 macro rules relating to whitespace and the hash
+        -- operator, which we tend to abuse. Clang in particular is not very happy
+        -- about this.
                     ++ [ SysTools.Option     "-x"
-                       , SysTools.Option     "c"
+                       , SysTools.Option     "assembler-with-cpp"
                        , SysTools.Option     input_fn
         -- We hackily use Option instead of FileOption here, so that the file
         -- name is not back-slashed on Windows.  cpp is capable of





More information about the ghc-commits mailing list