diff options
author | Zejun Wu <watashi@fb.com> | 2019-06-04 15:25:10 -0700 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-06-07 10:27:34 -0400 |
commit | cfd3e0f1cfd16c8f35cae139d2a871a32eb4d2e1 (patch) | |
tree | c77e9244a3d894d72277f7d0c65f85b861b2390a /testsuite/tests/driver | |
parent | 13b3d45d308108da2d92b3c06b5489f41703e623 (diff) | |
download | haskell-cfd3e0f1cfd16c8f35cae139d2a871a32eb4d2e1.tar.gz |
Pass preprocessor options to C compiler when building foreign C files (#16737)
Diffstat (limited to 'testsuite/tests/driver')
-rw-r--r-- | testsuite/tests/driver/T16737.hs | 32 | ||||
-rw-r--r-- | testsuite/tests/driver/T16737.stdout | 2 | ||||
-rw-r--r-- | testsuite/tests/driver/T16737include/T16737.h | 7 | ||||
-rw-r--r-- | testsuite/tests/driver/all.T | 1 |
4 files changed, 42 insertions, 0 deletions
diff --git a/testsuite/tests/driver/T16737.hs b/testsuite/tests/driver/T16737.hs new file mode 100644 index 0000000000..daf830693b --- /dev/null +++ b/testsuite/tests/driver/T16737.hs @@ -0,0 +1,32 @@ +{-# LANGUAGE TemplateHaskell #-} +{-# OPTIONS_GHC -DFOO=2 -optP=-DBAR=3 -optc=-DBAZ=5 -optcxx=-DBAZ=7 #-} + +import Language.Haskell.TH.Syntax + +do + let code = unlines + [ "#if defined(__cplusplus)" + , "extern \"C\" {" + , "#endif" + , "#include <T16737.h>" + , "int FUN(void) {" + , " return FOO * BAR * BAZ;" + , "}" + , "#if defined(__cplusplus)" + , "}" + , "#endif" + ] + addForeignSource LangC code + addForeignSource LangCxx code + pure [] + +foreign import ccall unsafe "c_value" + c_value :: IO Int + +foreign import ccall unsafe "cxx_value" + cxx_value :: IO Int + +main :: IO () +main = do + print =<< c_value + print =<< cxx_value diff --git a/testsuite/tests/driver/T16737.stdout b/testsuite/tests/driver/T16737.stdout new file mode 100644 index 0000000000..8a3609b7ca --- /dev/null +++ b/testsuite/tests/driver/T16737.stdout @@ -0,0 +1,2 @@ +30 +42 diff --git a/testsuite/tests/driver/T16737include/T16737.h b/testsuite/tests/driver/T16737include/T16737.h new file mode 100644 index 0000000000..08c7ca8729 --- /dev/null +++ b/testsuite/tests/driver/T16737include/T16737.h @@ -0,0 +1,7 @@ +#pragma once + +#if defined(__cplusplus) +#define FUN cxx_value +#else +#define FUN c_value +#endif diff --git a/testsuite/tests/driver/all.T b/testsuite/tests/driver/all.T index 3cb0f95ce4..173ce3bf0a 100644 --- a/testsuite/tests/driver/all.T +++ b/testsuite/tests/driver/all.T @@ -270,3 +270,4 @@ test('inline-check', omit_ways(['hpc', 'profasm']) test('T14452', [], makefile_test, []) test('T15396', normal, compile_and_run, ['-package ghc']) +test('T16737', [extra_files(['T16737include/'])], compile_and_run, ['-optP=-isystem -optP=T16737include']) |