Passing -g3 to GHC causes Cmm lexer errors
Summary
On a GCC system, if building a Cmm file with -optc-g3
, the build fails with a lexer error on defines emitted by cc -E
due to having a debug level higher than two. A related issue was reported as #18996 (closed)
Some triage was already done on IRC and we concluded that cc -E
emits defines when the debug-level is greater than two, which trips up the Cmm compiler. The purpose of this is to generate debug info. As this is unnecessary when simply preprocessing Cmm files we've concluded that we could just pass -g0
(and indeed adding -optc-g0
suppresses the error) whenever this kind of preprocessing is needed. This'd require a configure
-time check for the availability of -g0
.
We've also noticed that -optp
flags appear not to be passed to the Cmm preprocessing step, and we concluded that this happens because cppUseCc
is set to True
in the CmmCpp
phase. To address this, @alt-romes was considering passing preprocessor flags to CC when it is used as the preprocessor, but was worried that this might be dangerous (if cpp and cc differ in supported flags). If GHC was to do that, then adding -g0
if supported to preprocessor flags would cover both cases.
All things considered, it seems reasonable to me to pass -g0
if supported individually to both cpp
and cc -E
(so, configure-testing both and passing both).
Steps to reproduce
- Create an empty Test.cmm
- Run
ghc
with-optc-g3
~$ >Test.cmm
~$ ghc -c -odir f/ Test.cmm -optc-g3
<built-in>:0:2: error: Cmm lexical error
~ 1 $
Expected behavior
Produce a Test.o
without error
Environment
- GHC version used: The Glorious Glasgow Haskell Compilation System, version 9.2.8
Optional:
- Operating System: Gentoo GNU/Linux
- System Architecture: x86_64-pc-linux-gnu