|
编译的时候,开启相关检查选项
譬如
https://gcc.gnu.org/onlinedocs/g ... ml#Code-Gen-Options
-fcheck=<keyword> Enable the generation of run-time checks; the argument shall be a comma-delimited list of the following keywords. Prefixing a check with no- disables it if it was activated by a previous specification. ‘all’Enable all run-time test of -fcheck.
‘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.
Note: The warning is only printed once per location.
‘bounds’Enable generation of run-time checks for array subscripts and against the declared minimum and maximum values. It also checks array indices for assumed and deferred shape arrays against the actual allocated bounds and ensures that all string lengths are equal for character array constructors without an explicit typespec.
Some checks require that -fcheck=bounds is set for the compilation of the main program.
Note: In the future this may also include other forms of checking, e.g., checking substring references.
‘do’Enable generation of run-time checks for invalid modification of loop iteration variables.
‘mem’Enable generation of run-time checks for memory allocation. Note: This option does not affect explicit allocations using the ALLOCATE statement, which will be always checked.
‘pointer’Enable generation of run-time checks for pointers and allocatables.
‘recursion’Enable generation of run-time checks for recursively called subroutines and functions which are not marked as recursive. See also -frecursive. Note: This check does not work for OpenMP programs and is disabled if used together with -frecursive and -fopenmp.
Example: Assuming you have a file foo.f90, the command
gfortran -fcheck=all,no-array-temps foo.f90
will compile the file with all checks enabled as specified above except warnings for generated array temporaries.
|
|