[PATCH 0/2] incpath, Fortran: Fix memory leak in gfc_add_include_path

Bernhard Reutner-Fischer rep.dot.nop@gmail.com
Fri Nov 5 22:59:02 GMT 2021


On Fri,  5 Nov 2021 22:17:16 +0100
Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> wrote:

> Hi!
> 
> In order to fix this very minor leak, we need a knob to free all
> cpp_dirs that were added.
> This adds a free_cpp_dirs() to gcc/incpath and needs review from some
> global maintainer or maybe libcpp maintainer for this hunk.

One thing that i want to note is that it sounds a tiny bit odd that we
(the fortran FE) pull in the usual C paths, but maybe that's
deliberate and agreed on? We have in incpath.c:

> /* Exported function to handle include chain merging, duplicate
>    removal, and registration with cpplib.  */
> void
> register_include_chains (cpp_reader *pfile, const char *sysroot,
> 			 const char *iprefix, const char *imultilib,
> 			 int stdinc, int cxx_stdinc, int verbose)
> {
>   static const char *const lang_env_vars[] =
>     { "C_INCLUDE_PATH", "CPLUS_INCLUDE_PATH",
>       "OBJC_INCLUDE_PATH", "OBJCPLUS_INCLUDE_PATH" };
>   cpp_options *cpp_opts = cpp_get_options (pfile);
>   size_t idx = (cpp_opts->objc ? 2: 0);
> 
>   if (cpp_opts->cplusplus)
>     idx++;
>   else
>     cxx_stdinc = false;
> 
>   /* CPATH and language-dependent environment variables may add to the
>      include chain.  */
>   add_env_var_paths ("CPATH", INC_BRACKET);
>   add_env_var_paths (lang_env_vars[idx], INC_SYSTEM);
> 
>   target_c_incpath.extra_pre_includes (sysroot, iprefix, stdinc);

where we pass cxx_stdinc=0 and cpp_pts->cplusplus==0 (and nobody
complains anout that chatty cxx_stdinc=false and not =0 but so be it)
I.e. we do honor both CPATH as well as C_INCLUDE_PATH from the env for
fortran preprocessing. Maybe we should document this fact somehow as i
do not think we want to change it?

[ in gcc/doc/cppenv.texi:
@itemx OBJC_INCLUDE_PATH
@c Commented out until ObjC++ is part of GCC:
@c @itemx OBJCPLUS_INCLUDE_PATH
where i think objc++ is currently (still) in the tree so maybe someone
may want to tweak the docs here. But i digress..
]

gcc/ada/gnat_ugn.texi documents caveats for globally set C_INCLUDE_PATH
when using more than one compiler. [It's the only user of :envvar:`` in
the tree, everybody else seems to use @env{} btw.] I cannot judge if
ada is aware of pulling in CPATH or if maybe they somehow prevent this,
didn't look.

Thoughts on the env vars for fortran preprocessing?
thanks,
> 
> Bootstrapped and regtested on x86_64-unknown-linux without regressions.
> Ok for tunk?
> 
> Bernhard Reutner-Fischer (2):
>   Add free_cpp_dirs()
>   Fortran: Fix memory leak in gfc_add_include_path [PR68800]
> 
>  gcc/fortran/cpp.c      | 13 +++++++++++--
>  gcc/fortran/cpp.h      |  1 +
>  gcc/fortran/f95-lang.c |  2 +-
>  gcc/fortran/scanner.c  |  7 ++++---
>  gcc/incpath.c          | 13 +++++++++++++
>  gcc/incpath.h          |  1 +
>  6 files changed, 31 insertions(+), 6 deletions(-)
> 



More information about the Gcc-patches mailing list