[GSoC] Fortran – run-time argument checking

2025-03-20 Thread Gwen Fu
I'm very sorry that I've only just gotten in touch with the Gfortran
community! I've been trying to fix a bug in the GCC community for some time
(although I'm still working on it) and trying to understand the internal
components of GCC and its operation process.
I'm very sorry that I just got in touch with the Gfortran community now! I
have been trying to fix a bug in the GCC community for some time (although
I'm still working on it), and trying to understand the internal components
of GCC and the running process.
I have some superficial doubts about this project:
1. Which version of fortran does the "older Fortran code" refer to?
2. "A pointer to the called function is stored alongside to permit calls
from uninstrumented code to instrumented code." Why do we need to call the
detected function? Is the purpose of our project just to check whether the
function parameters match the passed parameters?
3. Is Fortran a strongly typed language like C++?


GSoC[Fortran Runtime argument check ] Draft of Proposal and some doubts about the needs

2025-04-05 Thread Gwen Fu
My doubt :
1.Does the compilation option only need to support fortran versions above
9, o5r does it also need to support fortran 77?
2.Regarding parameter checking, *my idea is that after the user creates an
array of a specified size, it is passed into the function as a parameter*.
However, the array size required by the function does not match the size
specified by the user. However, this idea seems to be impossible to
implement in fortran77. *In addition, in addition to implicit and explicit
size arrays, are there other data structures that require parameter type
checking?*
3.
I found out that "-fcheck=*" is an option for runtime checking, but the
relevant options are commented out.
  OPT_fcheck_ = 1070,/* -fcheck= */
  /* OPT_fcheck_assert = 1071, *//* -fcheck=assert */
  /* OPT_fcheck_bounds = 1072, *//* -fcheck=bounds */
  /* OPT_fcheck_in = 1073, *//* -fcheck=in */
  /* OPT_fcheck_invariant = 1074, */ /* -fcheck=invariant */
  /* OPT_fcheck_out = 1075, */   /* -fcheck=out */
  /* OPT_fcheck_switch = 1076, *//* -fcheck=switch */
  OPT_fcheckaction_ = 1077,  /* -fcheckaction= */
  OPT_fchecking = 1078,  /* -fchecking */

And I tried :
$ gfortran -o fibonacci fabonaqi.f90 -fcheck=in
f951: Warning: command-line option ‘-fpreconditions’ is valid for D but not
for Fortran
$ gfortran --help=check
cc1: warning: unrecognized argument to ‘--help=’ option: ‘check’
So Is this related  to the project ?

Here is my proposal draft (importran part )
Parameter Mismatch Implicit Declaration Features of Fortran 77

I think this is the reason why parameter mismatch may occur

In *Fortran 77*, *Implicit Typing* is a variable type automatic inference
mechanism, that is, *the compiler automatically determines its data type
based on the first letter of the variable name* without explicit
declaration.
Variable first characterDefault data type
A-H O-Z AH OZ REAL (single-precision floating point number)
I-N INTEGER (integer)

*This will lead*

   -

   *Error-prone*: If you make a typo (e.g., TOTAL is mistakenly written as
   TOAL), the compiler will not report an error, but the variable type may
   change.
   -

   *Poor code readability*: Implicit rules are not intuitive, increasing
   maintenance difficulty.


Parameter mismatch of implicit-size or explicit-size array

*1. Assumed-size Array*

*Syntax example:*

SUBROUTINE SUB(A)
  DIMENSION A(*)  ! Assumed-size array
  INTEGER A
  ! ...
END

*Potential issues:*

   -

   *No bounds checking*: The compiler does not know the actual size of the
   array passed in, and relies entirely on the programmer to ensure correct
   access.
   -

   *Out-of-bounds risk*: If A(i) is accessed inside the function but i
   exceeds the actual array range, undefined behavior (such as memory
   corruption, program crash) will occur.
   -

   *No shape checking*: Even if the dimensions of the array passed in do
   not match (such as A(10) but the actual passed in A(5)), the compiler
   will not report an error.

*2. Explicit-size Array *

*Syntax example:*

SUBROUTINE SUB(A, N)
  DIMENSION A(N)  ! Explicit-size Array
  INTEGER A, N
  ! ...
END

*Potential Issues:*

   -

   *Manual Size Passing*: The array size N must be passed additionally,
   which is prone to errors (e.g. passing the wrong N).
   -

   *Mismatch Risk*: If N is larger than the actual array size, the function
   may access illegal memory.
   -

   *No Dimension Check*: The compiler will not warn even if the array
   dimensions passed in are different (e.g. A(10) vs A(5,2)).

Technology stack mastered

   -

   Familiar with C++/C language
   -

   Familiar with Linux environment programming, proficient in three IO
   multiplexing technologies: epoll, select, and poll, and their underlying
   principles
   -

   Proficient in debugging tools such as gdb valgrind
   -

   Understand Fortran language


Projects participated in

   -

   Personal project Lightweight HTTP server based on Reactor mode
   

This project is developed in C++, including log output module, connection
management module, business module, and I/O processing connection request
processing module

   -

   OSPP-2024 Kytunig-Client data output function module development
   

This project is developed in Python, and its core functions include
deserialization of JSON data and conversion of JSON data into Excel files.


Re: GSoC[Fortran Runtime argument check ] Draft of Proposal and some doubts about the needs

2025-04-06 Thread Gwen Fu
Thanks for your reply !
>The word "parameter" has very a specific meaning in Fortran. The
>entity that is passed into a function or subroutine is an "actual
>argument". The entity within the functions associated with the
>"actual argument" is a "dummy argument".

Can I understand "dummy parameters" as temporary variables in a function
similar to C/C++, which copy the value of the passed parameter?
Or this is pass by value in C++.

>It is not clear to me what you're trying to accomplish. gfortran
>already has an -fimplicit-none option that enforces no implicit
>typing. This option will catch the "typo" type error. Gfortran
>also has the -fallow-argument-mismatch. If the code is within
>a single file, gfortran will build an explicit interface when
>it encounters an external procedure, and then it uses that interface
>to check any additional references.
I looked up the meaning of these two compilation options.
Both of them are compile time options .
But this project  needs to provide an option run-time test .
I am currently trying to understand the concept of runtime options and
what can happen.


[GSoC]Fortran – run-time argument checking

2025-03-26 Thread Gwen Fu
Gwen Fu  于 2025年3月25日周二 下午8:34写道:

> I found out that "-fcheck=*" is an option for runtime checking, but the
> relevant options are commented out.
>   OPT_fcheck_ = 1070,/* -fcheck= */
>   /* OPT_fcheck_assert = 1071, *//* -fcheck=assert */
>   /* OPT_fcheck_bounds = 1072, *//* -fcheck=bounds */
>   /* OPT_fcheck_in = 1073, *//* -fcheck=in */
>   /* OPT_fcheck_invariant = 1074, */ /* -fcheck=invariant */
>   /* OPT_fcheck_out = 1075, */   /* -fcheck=out */
>   /* OPT_fcheck_switch = 1076, *//* -fcheck=switch */
>   OPT_fcheckaction_ = 1077,  /* -fcheckaction= */
>   OPT_fchecking = 1078,  /* -fchecking */
>
> And I tried :
> $ gfortran -o fibonacci fabonaqi.f90 -fcheck=in
> f951: Warning: command-line option ‘-fpreconditions’ is valid for D but
> not for Fortran
> $ gfortran --help=check
> cc1: warning: unrecognized argument to ‘--help=’ option: ‘check’
> So what's wrong with these ?
>


Re: GSoC[Fortran Runtime argument check ] Draft of Proposal and some doubts about the needs

2025-04-10 Thread Gwen Fu
Thank you for your detailed explanation of  "dummy parameter"  !

>It is still unclear to me what you are trying to accomplish.
>Implicit typying and implicit interfaces are a compile-time
>thing.
...
>An -fcheck=implicit-type option that generates a runtime
>error that does not make sense to me unless the aim is
>to slow down the compile code.  The above code would be
>transformed into something like (ignoring passing convention).
>float
>foo(float x)
>{
>  if (runtime_option & fcheck_implicit_type)
 >runtime_error("'foo' has an implicit type");

>  if (runtime_option & fcheck_implicit_type)
>runtime_error("'x' has an implicit type");

>  return (x * x);
>}

Here  is the description of the GSoC project :
*Fortran – run-time argument checking.* – In particular older Fortran code,
which does not use modules, but also code which uses implicit-size or
explicit-size arrays is prone to argument mismatches. The goal of this item
is to *add an optional run-time test* which works by storing the
argument-type/size data before the call in a global variable – and check
against it in the callee. (A pointer to the called function is stored
alongside to permit calls from uninstrumented code to instrumented code.)
This project would/could be mentored by Tobias Burnus. Required skills
include C/C++; some knowledge of Fortran helps, but is not needed. *Difficulty
medium, size: 175 hours (medium)*.

"older Fortran code "may indicate the version Fortran 77
I try to regard "an optional run-time test" as a compile option like what
you said "-fcheck=implicit-type" . Is there any other understanding?
(Maybe , the test is "check_implicit_type" , the code you showed to me
above))

Although the optimized code will reduce the code running efficiency, I feel
that this project should have its place!😄😄


[GSoC]Fortran – run-time argument checking

2025-03-25 Thread Gwen Fu
I found out that "-fcheck=*" is an option for runtime checking, but the
relevant options are commented out.
  OPT_fcheck_ = 1070,/* -fcheck= */
  /* OPT_fcheck_assert = 1071, *//* -fcheck=assert */
  /* OPT_fcheck_bounds = 1072, *//* -fcheck=bounds */
  /* OPT_fcheck_in = 1073, *//* -fcheck=in */
  /* OPT_fcheck_invariant = 1074, */ /* -fcheck=invariant */
  /* OPT_fcheck_out = 1075, */   /* -fcheck=out */
  /* OPT_fcheck_switch = 1076, *//* -fcheck=switch */
  OPT_fcheckaction_ = 1077,  /* -fcheckaction= */
  OPT_fchecking = 1078,  /* -fchecking */

And I tried :
$ gfortran -o fibonacci fabonaqi.f90 -fcheck=in
f951: Warning: command-line option ‘-fpreconditions’ is valid for D but not
for Fortran
$ gfortran --help=check
cc1: warning: unrecognized argument to ‘--help=’ option: ‘check’
So what's wrong with these ?