[Git][ghc/ghc][wip/romes/configure-qunused-args] Configure -Qunused-arguments instead of hardcoding it

Rodrigo Mesquita (@alt-romes) gitlab at gitlab.haskell.org
Tue Jun 6 09:39:16 UTC 2023



Rodrigo Mesquita pushed to branch wip/romes/configure-qunused-args at Glasgow Haskell Compiler / GHC


Commits:
0f7a00cb by Rodrigo Mesquita at 2023-06-06T10:39:08+01:00
Configure -Qunused-arguments instead of hardcoding it

When GHC invokes clang, it currently passes -Qunused-arguments to
discard warnings resulting from GHC using multiple options that aren't
used.

In this commit, we configure -Qunused-arguments into the Cc options
instead of checking if the compiler is clang at runtime and hardcoding
the flag into GHC.

This is part of the effort to centralise toolchain information in
toolchain target files at configure time with the end goal of a runtime
retargetable GHC.

- - - - -


4 changed files:

- compiler/GHC/Driver/Pipeline/Execute.hs
- configure.ac
- distrib/configure.ac.in
- + m4/fp_cc_ignore_unused_args.m4


Changes:

=====================================
compiler/GHC/Driver/Pipeline/Execute.hs
=====================================
@@ -292,11 +292,7 @@ runAsPhase with_cpp pipe_env hsc_env location input_fn = do
 
         -- LLVM from version 3.0 onwards doesn't support the OS X system
         -- assembler, so we use clang as the assembler instead. (#5636)
-        let (as_prog, get_asm_info) =
-                ( applyAssemblerProg $ backendAssemblerProg (backend dflags)
-                , applyAssemblerInfoGetter $ backendAssemblerInfoGetter (backend dflags)
-                )
-        asmInfo <- get_asm_info logger dflags platform
+        let as_prog = applyAssemblerProg $ backendAssemblerProg (backend dflags)
 
         let cmdline_include_paths = includePaths dflags
         let pic_c_flags = picCCOpts dflags
@@ -330,9 +326,6 @@ runAsPhase with_cpp pipe_env hsc_env location input_fn = do
                        ++ [ GHC.SysTools.Option "-Wa,--no-type-check"
                           | platformArch (targetPlatform dflags) == ArchWasm32]
 
-                       ++ (if any (asmInfo ==) [Clang, AppleClang, AppleClang51]
-                            then [GHC.SysTools.Option "-Qunused-arguments"]
-                            else [])
                        ++ [ GHC.SysTools.Option "-x"
                           , if with_cpp
                               then GHC.SysTools.Option "assembler-with-cpp"
@@ -400,19 +393,6 @@ runForeignJsPhase pipe_env hsc_env _location input_fn = do
   return output_fn
 
 
-applyAssemblerInfoGetter
-    :: DefunctionalizedAssemblerInfoGetter
-    -> Logger -> DynFlags -> Platform -> IO CompilerInfo
-applyAssemblerInfoGetter StandardAssemblerInfoGetter logger dflags _platform =
-    getAssemblerInfo logger dflags
-applyAssemblerInfoGetter JSAssemblerInfoGetter _ _ _ =
-    pure Emscripten
-applyAssemblerInfoGetter DarwinClangAssemblerInfoGetter logger dflags platform =
-    if platformOS platform == OSDarwin then
-        pure Clang
-    else
-        getAssemblerInfo logger dflags
-
 applyAssemblerProg
     :: DefunctionalizedAssemblerProg
     -> Logger -> DynFlags -> Platform -> [Option] -> IO ()


=====================================
configure.ac
=====================================
@@ -663,6 +663,12 @@ FP_CC_SUPPORTS_TARGET([$CC_STAGE0], [CONF_CC_OPTS_STAGE0], [CONF_CXX_OPTS_STAGE0
 FP_CC_SUPPORTS_TARGET([$CC], [CONF_CC_OPTS_STAGE1], [CONF_CXX_OPTS_STAGE1], [CONF_GCC_LINKER_OPTS_STAGE1])
 FP_CC_SUPPORTS_TARGET([$CC], [CONF_CC_OPTS_STAGE2], [CONF_CXX_OPTS_STAGE2], [CONF_GCC_LINKER_OPTS_STAGE2])
 
+dnl Pass -Qunused-arguments or otherwise GHC will have very noisy invocations of Clang
+dnl TODO: Do we need -Qunused-arguments in CXX and GCC linker too?
+FP_CC_IGNORE_UNUSED_ARGS([$CC_STAGE0], [CONF_CC_OPTS_STAGE0])
+FP_CC_IGNORE_UNUSED_ARGS([$CC], [CONF_CC_OPTS_STAGE1])
+FP_CC_IGNORE_UNUSED_ARGS([$CC], [CONF_CC_OPTS_STAGE2])
+
 # See rules/distdir-way-opts.mk for details.
 # Flags passed to the C compiler
 AC_SUBST(CONF_CC_OPTS_STAGE0)


=====================================
distrib/configure.ac.in
=====================================
@@ -223,6 +223,10 @@ dnl CONF_CC_OPTS_STAGE[12] accordingly.
 FP_CC_SUPPORTS_TARGET([$CC], [CONF_CC_OPTS_STAGE1], [CONF_CXX_OPTS_STAGE1], [CONF_GCC_LINK_OPTS_STAGE1])
 FP_CC_SUPPORTS_TARGET([$CC], [CONF_CC_OPTS_STAGE2], [CONF_CXX_OPTS_STAGE2], [CONF_GCC_LINK_OPTS_STAGE2])
 
+dnl Pass -Qunused-arguments or otherwise GHC will have very noisy invocations of Clang
+FP_CC_IGNORE_UNUSED_ARGS([$CC], [CONF_CC_OPTS_STAGE1])
+FP_CC_IGNORE_UNUSED_ARGS([$CC], [CONF_CC_OPTS_STAGE2])
+
 dnl TargetWordSize for settings file
 AC_CHECK_SIZEOF(void *, 4)
 if test "x$ac_cv_sizeof_void_p" = "x0"; then


=====================================
m4/fp_cc_ignore_unused_args.m4
=====================================
@@ -0,0 +1,31 @@
+# FP_CC_IGNORE_UNUSED_ARGS
+# ------------------------
+# GHC tends to produce command-lines with unused arguments that elicit
+# warnings from Clang. Clang offers the @-Qunused-arguments@ flag to silence
+# these. See #11684.
+#
+# The primary effect of this is updating CONF_CC_OPTS_STAGE[12] to explicitly
+# pass -Qunused-arguments to Clang, since otherwise Cc invocations by GHC will
+# be very noisy
+#
+# $1 = CC
+# $2 = CC_OPTS variable
+AC_DEFUN([FP_CC_IGNORE_UNUSED_ARGS],
+[
+   AC_MSG_CHECKING([whether $1 supports -Qunused-arguments])
+   echo 'int main() { return 0; }' > conftest.c
+   if $1 -Qunused-arguments -Werror conftest.c > /dev/null 2>&1 ; then
+       CONF_CC_SUPPORTS_TARGET=YES
+       AC_MSG_RESULT([yes])
+   else
+       CONF_CC_SUPPORTS_TARGET=NO
+       AC_MSG_RESULT([no])
+   fi
+   rm -f conftest.c conftest
+
+   if test $CONF_CC_SUPPORTS_TARGET = YES ; then
+       $2="$$2 -Qunused-arguments"
+   fi
+])
+
+



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0f7a00cbb1915dc9e4f7a7cf62a87b90c8837210

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0f7a00cbb1915dc9e4f7a7cf62a87b90c8837210
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/20230606/1db64be4/attachment-0001.html>


More information about the ghc-commits mailing list