Commit 15f1dc33 authored by Ryan Scott's avatar Ryan Scott Committed by Marge Bot

Prevent -optc arguments from being duplicated in reverse order (#17471)

This reverts a part of commit
7bc5d6c6 that causes all arguments
to `-optc` (and `-optcxx`) to be passed twice to the C/C++ compiler,
once in reverse order and then again in the correct order. While
passing duplicate arguments is usually harmless it can cause breakage
in this pattern, which is employed by Hackage libraries in the wild:

ghc Foo.hs foo.c -optc-D -optcFOO

As `FOO -D -D FOO` will cause compilers to error.

Fixes #17471.
parent 4a1e7e47
Pipeline #13133 passed with stages
in 471 minutes and 34 seconds
......@@ -127,10 +127,9 @@ runCc mLanguage dflags args = traceToolCommand dflags "cc" $ do
Nothing -> ([], userOpts_c)
Just language -> ([Option "-x", Option languageName], opts)
s = settings dflags
(languageName, opts) = case language of
LangC -> ("c", sOpt_c s ++ userOpts_c)
LangCxx -> ("c++", sOpt_cxx s ++ userOpts_cxx)
LangC -> ("c", userOpts_c)
LangCxx -> ("c++", userOpts_cxx)
LangObjc -> ("objective-c", userOpts_c)
LangObjcxx -> ("objective-c++", userOpts_cxx)
LangAsm -> ("assembler", [])
{-# LANGUAGE ForeignFunctionInterface #-}
module Main where
import Foreign.C.Types
foreign import ccall "foo" foo :: IO CInt
main :: IO ()
main = foo >>= print
int foo() {
#if defined(FOO)
return 1;
return 0;
......@@ -213,3 +213,6 @@ test('PrimFFIWord16', [omit_ways(['ghci'])], compile_and_run, ['PrimFFIWord16_c.
test('T493', [omit_ways(['ghci'])], compile_and_run, ['T493_c.c'])
test('UnliftedNewtypesByteArrayOffset', [omit_ways(['ghci'])], compile_and_run, ['UnliftedNewtypesByteArrayOffset_c.c'])
test('T17471', [omit_ways(['ghci'])], compile_and_run,
['T17471_c.c -optc-D -optcFOO'])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment