# Compiler options to report implicit creation of temporary variables

**URL:** <https://fortran-lang.discourse.group/t/compiler-options-to-report-implicit-creation-of-temporary-variables/8874>\
**Category:** Uncategorized\
**Created:** [November 24, 2024, 8:43am UTC](https://fortran-lang.discourse.group/t/compiler-options-to-report-implicit-creation-of-temporary-variables/8874 "2024-11-24T08:43:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![septc](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/septc/32/77_2.png) [@septc](https://fortran-lang.discourse.group/u/septc)\
**Post date:** [November 24, 2024, 8:43am UTC](https://fortran-lang.discourse.group/t/compiler-options-to-report-implicit-creation-of-temporary-variables/8874/1 "2024-11-24T08:43:17Z")

</div>

Hello,

Gfortran has an option to report implicit creation of temporary arrays (or array temporaries):

[-fcheck=array-temps (Code Gen Options)](https://gcc.gnu.org/onlinedocs/gfortran/Code-Gen-Options.html#index-fcheck)

> `-fcheck=<keyword>`  
> Enable the generation of run-time checks (…)
> 
> keyword = ‘all’  
> Enable all run-time test of -fcheck.
> 
> keyword = ‘array-temps’  
> Warns at run time when for passing an actual argument a temporary array had to be generated. The information generated by this warning is sometimes useful in optimization, in order to avoid such temporaries.

Here, I mean by “implicit creation” that compilers create temporary arrays internally for some reason (contiguity of memory, optimization, etc). I am wondering if other Fortran compilers also have similar options? Also, are there possibly some options to report implicit creation of _scalar_ temporary variables, particularly for derived-type objects? (I checked the manual for Gfortran-12, but could not find related ones.)

If you might know similar options in other languages (either for scalar derived types or array temporaries), I would appreciate it if you share the information. I think it would be possible to implement such a feature somehow (e.g., by user-defined automatic constructors if it is supported by the language), but here I am wondering whether compiler options or pragmas or tools (?) are available for making a report of temporary objects (particularly large ones).

Thanks very much!

---

<div class="post-metadata">

**Author:** ![septc](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/septc/32/77_2.png) [@septc](https://fortran-lang.discourse.group/u/septc)\
**Post date:** [November 24, 2024, 9:28am UTC](https://fortran-lang.discourse.group/t/compiler-options-to-report-implicit-creation-of-temporary-variables/8874/2 "2024-11-24T09:28:11Z")

</div>

The info from [Perplexity](https://www.perplexity.ai/search/gfortran-has-an-option-to-repo-KmDb7_HfSFuBVlbMggCCJA) was something like this, which suggests that similar options are available for arrays, though no specific options for scalar variables. (FWIW, the last paragraph mentions a challenge for determining “unnecessary” temporary objects, but I am more interested in knowing whether implicit copies of (possibly large) objects occur in a given routine, for example. According to the info below, it might be useful to check general optimization reports also.)

> Gfortran’s -fcheck=array-temps option is indeed useful for reporting implicit creation of temporary arrays. Some other Fortran compilers offer similar options:
> 
> 1. Intel Fortran Compiler (ifort):
> 
> - -check arg\_temp\_created: Reports when temporary arrays are created for array \>arguments.
> 
> 1. NAG Fortran Compiler:
> 
> - -C=array: Checks array bounds and reports temporary array creation.
> 
> For scalar temporary variables, especially derived-type objects, there are no widely available compiler options specifically for reporting their creation. However, some compilers provide general optimization reports that may include information about temporary object creation:
> 
> 1. Intel Fortran Compiler:
> 
> - -qopt-report: Generates optimization reports that may include information about temporary objects.
> 
> 1. PGI/NVIDIA HPC Compiler:
> 
> - -Minfo=all: Provides detailed optimization information.
> 
> It’s worth noting that implementing such features for scalar derived types or more complex objects is challenging due to the difficulty in determining what constitutes an “unnecessary” temporary object in all cases. Compiler developers often focus on optimizing these cases rather than reporting them.

> **(more details on other languages)**
>
> In other programming languages:
> 
> 1. C++:
> 
> 2. Rust:
> 
> 3. Java:
