Bug 62226 - Encode CPP options in lang.opt
Summary: Encode CPP options in lang.opt
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: 44054 55534 56659 64273
  Show dependency treegraph
 
Reported: 2014-08-22 10:39 UTC by Manuel López-Ibáñez
Modified: 2021-09-25 16:11 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-08-22 00:00:00


Attachments
patch to handle CPP() per language (1.78 KB, patch)
2014-08-22 10:39 UTC, Manuel López-Ibáñez
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Manuel López-Ibáñez 2014-08-22 10:39:53 UTC
Created attachment 33378 [details]
patch to handle CPP() per language

I recently added a new feature to .opt files to encode CPP options and handle them transparently. Unfortunately, it does not work with Fortran because Fortran does not use the common options machinery.

Steps to fix:

* Fortran should use the common options machinery (at least for those options that are CPP options).

* Apply the attached patch.

* Add a call to Fortran_cpp_handle_option_auto and init_global_opts_from_cpp somewhere appropriate in the Fortran FE.

Features like #pragma diagnostics and -fdiagnostics-show-option rely on this, so it is a prerequisite for fixing PR44054.
Comment 1 Tobias Burnus 2021-09-24 07:57:08 UTC
I am not sure whether the original issue still exists.

Fortran now uses a lot of the common machinery and also seems to handle CPP() well.

Thus, is this now fixed/superseded by the recent and not so recent developments or is something still needed?
Comment 2 Manuel López-Ibáñez 2021-09-25 16:11:42 UTC
(In reply to Tobias Burnus from comment #1)
> I am not sure whether the original issue still exists.
> 
> Fortran now uses a lot of the common machinery and also seems to handle
> CPP() well.
> 
> Thus, is this now fixed/superseded by the recent and not so recent
> developments or is something still needed?

If Fortran will always use a subset of the CPP options used by the C FE and defined by c-family/c.opt, then I guess it may not be needed. 

But be aware that this code:

https://github.com/gcc-mirror/gcc/blob/8bafc9640f353ff11c0535a03096fb4db9a5bb95/gcc/fortran/cpp.c#L1062

only works because this file:

https://github.com/gcc-mirror/gcc/blob/master/gcc/c-family/c.opt#L390

encodes the CppReason and it is not possible without the patch in this PR to have a CPP option that only works for Fortran only encoded in fortran/lang.opt

I haven't tested whether diagnostics from CPP show the appropriate option in Fortran and behave correctly with #pragma GCC diagnostics.

Another minor thing: You added recently another copy of:

https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/gcc/c-family/c-common.c#L6293

I may have added that function there, but it should be added in common code. In fact, it could be actually generated as "static inline" together with the table of codes:

https://github.com/gcc-mirror/gcc/blob/master/gcc/opth-gen.awk

so that it is available by including opts.h (in fact, that function is the only user of cpp_reason_option_codes, so the table could be inside the function rather than being yet another global).