[Git][ghc/ghc][wip/24286] 2 commits: driver: Set -DPROFILING when compiling C++ sources with profiling
Zubin (@wz1000)
gitlab at gitlab.haskell.org
Mon Jan 8 11:04:11 UTC 2024
Zubin pushed to branch wip/24286 at Glasgow Haskell Compiler / GHC
Commits:
197b58c8 by Zubin Duggal at 2024-01-08T16:30:00+05:30
driver: Set -DPROFILING when compiling C++ sources with profiling
Earlier, we used to pass all preprocessor flags to the c++ compiler.
This meant that -DPROFILING was passed to the c++ compiler because
it was a part of C++ flags
However, this was incorrect and the behaviour was changed in
8ff3134ed4aa323b0199ad683f72165e51a59ab6. See #21291.
But that commit exposed this bug where -DPROFILING was no longer being passed
when compiling c++ sources.
The fix is to explicitly include -DPROFILING in `opt_cxx` when profiling is
enabled to ensure we pass the correct options for the way to both C and C++
compilers
Fixes #24286
- - - - -
3bd05d74 by Zubin Duggal at 2024-01-08T16:34:00+05:30
testsuite: rename objcpp -> objcxx
To avoid confusion with C Pre Processsor
- - - - -
8 changed files:
- compiler/GHC/Driver/Session.hs
- compiler/GHC/Platform/Ways.hs
- testsuite/driver/testglobals.py
- testsuite/driver/testlib.py
- testsuite/tests/driver/Makefile
- + testsuite/tests/driver/T24286.cpp
- testsuite/tests/driver/all.T
- testsuite/tests/driver/objc/all.T
Changes:
=====================================
compiler/GHC/Driver/Session.hs
=====================================
@@ -438,7 +438,8 @@ opt_c :: DynFlags -> [String]
opt_c dflags = concatMap (wayOptc (targetPlatform dflags)) (ways dflags)
++ toolSettings_opt_c (toolSettings dflags)
opt_cxx :: DynFlags -> [String]
-opt_cxx dflags= toolSettings_opt_cxx $ toolSettings dflags
+opt_cxx dflags = concatMap (wayOptcxx (targetPlatform dflags)) (ways dflags)
+ ++ toolSettings_opt_cxx (toolSettings dflags)
opt_a :: DynFlags -> [String]
opt_a dflags= toolSettings_opt_a $ toolSettings dflags
opt_l :: DynFlags -> [String]
=====================================
compiler/GHC/Platform/Ways.hs
=====================================
@@ -31,6 +31,7 @@ module GHC.Platform.Ways
, wayGeneralFlags
, wayUnsetGeneralFlags
, wayOptc
+ , wayOptcxx
, wayOptl
, wayOptP
, wayDesc
@@ -177,6 +178,9 @@ wayOptc _ WayDebug = []
wayOptc _ WayDyn = []
wayOptc _ WayProf = ["-DPROFILING"]
+wayOptcxx :: Platform -> Way -> [String]
+wayOptcxx = wayOptc -- Use the same flags as C
+
-- | Pass these options to linker when enabling this way
wayOptl :: Platform -> Way -> [String]
wayOptl _ (WayCustom {}) = []
=====================================
testsuite/driver/testglobals.py
=====================================
@@ -403,7 +403,7 @@ class TestOptions:
self.c_src = False
self.cxx_src = False
self.objc_src = False
- self.objcpp_src = False
+ self.objcxx_src = False
# Does this test use a .cmm file?
self.cmm_src = False
=====================================
testsuite/driver/testlib.py
=====================================
@@ -967,8 +967,8 @@ def cxx_src( name, opts ):
def objc_src( name, opts ):
opts.objc_src = True
-def objcpp_src( name, opts ):
- opts.objcpp_src = True
+def objcxx_src( name, opts ):
+ opts.objcxx_src = True
def cmm_src( name, opts ):
opts.cmm_src = True
@@ -1961,7 +1961,7 @@ async def simple_build(name: Union[TestName, str],
if (getTestOpts().c_src or
getTestOpts().cxx_src or
getTestOpts().objc_src or
- getTestOpts().objcpp_src):
+ getTestOpts().objcxx_src):
extra_hc_opts += ' -no-hs-main '
if getTestOpts().compile_cmd_prefix == '':
@@ -2938,7 +2938,7 @@ def add_hs_lhs_suffix(name: str) -> Path:
return add_suffix(name, 'cpp')
elif getTestOpts().objc_src:
return add_suffix(name, 'm')
- elif getTestOpts().objcpp_src:
+ elif getTestOpts().objcxx_src:
return add_suffix(name, 'mm')
elif getTestOpts().literate:
return add_suffix(name, 'lhs')
=====================================
testsuite/tests/driver/Makefile
=====================================
@@ -808,5 +808,3 @@ T23339B:
"$(TEST_HC)" -tmpdir "$(PWD)/tmp" $(TEST_HC_OPTS) -v0 T23339B.hs -finfo-table-map
# Check that the file is kept and is the right one
find . -name "*.c" -exec cat {} \; | grep "init__ip_init"
-
-
=====================================
testsuite/tests/driver/T24286.cpp
=====================================
@@ -0,0 +1,7 @@
+#if !defined(PROFILING)
+#error PROFILING flag not set for C++ files, see #24286
+#endif
+
+int main() {
+ return 0;
+}
=====================================
testsuite/tests/driver/all.T
=====================================
@@ -326,3 +326,4 @@ test('T23339', req_c, makefile_test, [])
test('T23339B', [extra_files(['T23339.hs']), req_c], makefile_test, [])
test('T23613', normal, compile_and_run, ['-this-unit-id=foo'])
test('T23944', [unless(have_dynamic(), skip), extra_files(['T23944A.hs'])], multimod_compile, ['T23944 T23944A', '-fprefer-byte-code -fbyte-code -fno-code -dynamic-too -fwrite-interface'])
+test('T24286', [cxx_src, unless(have_profiling(), skip), extra_files(['T24286.cpp'])], compile, ['-prof -no-hs-main'])
=====================================
testsuite/tests/driver/objc/all.T
=====================================
@@ -12,8 +12,8 @@ test('objc-hi',
expect_fail_for(['ghci']) ],
compile_and_run, ['-framework Foundation'])
-test('objcpp-hi',
+test('objcxx-hi',
[ skip_if_not_osx,
- objcpp_src,
+ objcxx_src,
expect_fail_for(['ghci']) ],
compile_and_run, ['-framework Foundation -lc++'])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2853e8b480787041df4635ebf7ae6c203132272e...3bd05d744f7dc0aeb284202715f87dc52956ba2f
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2853e8b480787041df4635ebf7ae6c203132272e...3bd05d744f7dc0aeb284202715f87dc52956ba2f
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240108/9d5fa4b8/attachment-0001.html>
More information about the ghc-commits
mailing list