Skip to content

Commit

Permalink
Use assembler-with-cpp mode when running CPP.
Browse files Browse the repository at this point in the history
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@pobox.com>
  • Loading branch information
thoughtpolice committed Jun 19, 2013
1 parent 73991d6 commit 7b0695a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions compiler/main/DriverPipeline.hs
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7b0695a

Please sign in to comment.