[Git][ghc/ghc][wip/andreask/9.10-backports] Add the cmm_cpp_is_gcc predicate to the testsuite

Andreas Klebinger (@AndreasK) gitlab at gitlab.haskell.org
Wed Dec 18 15:14:22 UTC 2024



Andreas Klebinger pushed to branch wip/andreask/9.10-backports at Glasgow Haskell Compiler / GHC


Commits:
5080053a by Arsen Arsenović at 2024-12-18T15:48:32+01:00
Add the cmm_cpp_is_gcc predicate to the testsuite

A future C-- test called T24474-cmm-override-g0 relies on the
GCC-specific behaviour of -g3 implying -dD, which, in turn, leads to it
emitting #defines past the preprocessing stage.  Clang, at least, does
not do this, so the test would fail if ran on Clang.

As the behaviour here being tested is ``-optCmmP-g3'' undoing effects of
the workaround we apply as a fix for bug #24474, and the workaround was
for GCC-specific behaviour, the test needs to be marked as fragile on
other compilers.

(cherry picked from commit 4d59abf295cd371448f22c1724b955dce4974302)

- - - - -


3 changed files:

- testsuite/config/ghc
- testsuite/driver/testglobals.py
- testsuite/driver/testlib.py


Changes:

=====================================
testsuite/config/ghc
=====================================
@@ -224,7 +224,7 @@ def get_compiler_info():
     # See Note [Replacing backward slashes in config.libdir].
     config.libdir = config.libdir.replace('\\', '/')
 
-    def test_compile(flags):
+    def test_compile(flags, test_filename='test.hs', test_src=None):
         """
         Check whether GHC can compile in the given way. This is used as a
         proxy to determine, e.g., whether profiled libraries were built, or
@@ -235,12 +235,15 @@ def get_compiler_info():
 
         res = False
 
-        with tempfile.TemporaryDirectory() as d:
-            src = Path(d) / 'test.hs'
-            src.write_text(textwrap.dedent('''
+        if test_src is None:
+            test_src = '''
                 module Main where
                 main = putStrLn "Hello World!"
-            '''))
+            '''
+
+        with tempfile.TemporaryDirectory() as d:
+            src = Path(d) / test_filename
+            src.write_text(textwrap.dedent(test_src))
             try:
                 p = subprocess.run(
                     '{} -v0 {} -o test '.format(config.compiler, src) + ' '.join(flags),
@@ -296,6 +299,16 @@ def get_compiler_info():
         config.plugin_way_flags = "-static"
         config.ghc_th_way       = "normal"
 
+    config.cmm_cpp_is_gcc = test_compile(
+        ['-c'],
+        test_filename='test.cmm',
+        test_src='''
+        #if defined(__clang__) || !defined(__GNUC__)
+        # error "not gcc"
+        #endif
+        '''
+    )
+
 # Note [Replacing backward slashes in config.libdir]
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 #


=====================================
testsuite/driver/testglobals.py
=====================================
@@ -234,6 +234,9 @@ class TestConfig:
         # The path specifies the file in which to write the dependencies
         self.only_report_hadrian_deps = None # type: Optional[Path]
 
+        # Are we using GCC to preprocess C--?
+        self.cmm_cpp_is_gcc = False
+
     def validate(self) -> None:
         """ Check the TestConfig for self-consistency """
         def assert_implies(a: bool, b: bool):


=====================================
testsuite/driver/testlib.py
=====================================
@@ -991,6 +991,10 @@ def llvm_build ( ) -> bool:
 def have_thread_sanitizer( ) -> bool:
     return config.have_thread_sanitizer
 
+
+def gcc_as_cmmp() -> bool:
+    return config.cmm_cpp_is_gcc
+
 # ---
 
 # Note [Measuring residency]



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5080053a75b0a25eed2ff2cdd7a45b74d04cff3f

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5080053a75b0a25eed2ff2cdd7a45b74d04cff3f
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/20241218/e70932e4/attachment-0001.html>


More information about the ghc-commits mailing list