[Bug modula2/108182] gm2 driver mishandles target and multilib options

cvs-commit at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Jan 25 15:24:25 GMT 2023


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108182

--- Comment #19 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Iain D Sandoe <iains@gcc.gnu.org>:

https://gcc.gnu.org/g:80cf2c5e8f496bed9c6facf55f9ae31d0d90fd28

commit r13-5373-g80cf2c5e8f496bed9c6facf55f9ae31d0d90fd28
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Mon Jan 16 14:07:20 2023 +0000

    modula-2: Fixes for preprocessing [PR102343, PR108182].

    Modula-2 uses the C preprocessor to implement handling for conditional
    code and macros.  However, this is not done directly, because the process
    is applied recursively to imported definitions and modules.

    The cc1gm2 executable records the parameters as a template command line
    needed to create a composite 'cc1 -E' for each file to be preprocessed
    starting with the main file from the original command line.

    This patch fixes the capture of the C preprocessor template to include
    the target information needed for correct multilib operation.

    In order to match the existing semantics of '-E, -M and -MM' these have
    to be handled as a 'pre-processor only' job (i.e. the recursion is omitted
    and only the main file is processed).

    Whereas C-family front ends always pre-process, Modula-2 only does so
    when specifically requested (via the -fcpp option).

    '-MD, -MMD and -MQ' also require special handling, since (in principle)
    these options can be applied to any command line (with -fcpp) providing
    dependency information as a by-product.

    TODO: the preprocessor is not able to determine def and mod dependencies
    for Modula-2 and so the output of this only shows the object to module
    dep.  We should be able to append the .def and .mod dependencies.

    The patch amends save-temps handling to cater for the preprocessor
    recursion and to avoid writing saved files into the source directories.

    The patch changes the extension for Modula-2 preprocessed source to .m2i
    to avoid clashes with .i.

    The main driver code is amended to add default handlers for .mod and .m2i
    so that a useful error message will be emitted if the Modula-2 compiler
    is not built-in.

    The compiler will now also handle code generation from a .m2i preprocessed
    source.

    TODO: We should not need to pass the '-c' option to the compiler to alter
    the processing of init code.

    Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>

            PR modula2/102343
            PR modula2/108182

    gcc/ChangeLog:

            * gcc.cc: Provide default specs for Modula-2 so that when the
            language is not built-in better diagnostics are emitted for
            attempts to use .mod or .m2i file extensions.

    gcc/m2/ChangeLog:

            * gm2-compiler/M2Comp.mod: Early exit for pre-processor-only jobs.
            * gm2-compiler/M2Options.def (SetPPOnly, GetPPOnly, SetMD, GetMD,
            SetMMD, GetMMD, SetMQ, GetMQ, SetObj, GetObj, SetDumpDir,
            GetDumpDir):New.
            * gm2-compiler/M2Options.mod:(SetPPOnly, GetPPOnly, SetMD, GetMD,
            SetMMD, GetMMD, SetMQ, GetMQ, SetObj, GetObj, SetDumpDir,
            GetDumpDir):New.
            * gm2-compiler/M2Preprocess.def (PreprocessModule): Add flag to
            indicate the main file.
            * gm2-compiler/M2Preprocess.mod: Handle Preprocess-only jobs,
            handle MD, MMD and MQ options.
            * gm2-gcc/m2options.h (M2Options_SetPPOnly, M2Options_GetPPOnly,
            M2Options_SetDumpDir, M2Options_SetMD, M2Options_GetMD,
            M2Options_SetMMD, M2Options_GetMMD, M2Options_SetMQ,
M2Options_GetMQ,
            M2Options_SetObj, M2Options_GetObj): New.
            * gm2-gcc/m2type.cc (m2type_InitBaseTypes): Early exit for pre-
            processor-only jobs.
            * gm2-lang.cc (gm2_langhook_init): Handle preprocess-only commands.
            (gm2_langhook_option_lang_mask): Claim C and Driver options so that
            we can intercept them for building pre-processor commands.
            (gm2_langhook_init_options): Collect the preprocessor line here.
            Save options that have different actions for preprocessor and
compile
            commands.
            (gm2_langhook_handle_option): Only handle the modula-2 options
here.
            (gm2_langhook_post_options): Do not create a back-end for pre-
            processor-only jobs.
            * gm2spec.cc (lang_specific_driver): Ignore PCH options, append a
            scaffold-main for cases where we are building a main module with
            -c.
            * lang-specs.h: Revise to handle preprocessor-only jobs and to
            consume pre-processed files.
            * lang.opt: Remove Driver and C options copies (we claim these
            separately).


More information about the Gcc-bugs mailing list