Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29277 Discussions

Bounds check and character length for 11.1.056

hdankowski
Beginner
873 Views
Hi,

I issued another problem with the (new?) bounds check for the version 11.1 and newer:

For Fortran 77, the compiler notices a problem if the given character length is different than the expected and throws a runtime error (with activated -check bounds).

Example:
SUBROUTINE BU_PRLIESCONF(umfeld,confile)
...
character*80 inpuffer
character*40 umfeld(0:50,2)
...
call bu_prumwand(inpuffer(glzeichen+1:end-1),umfeld(k,1),
* fehler)
...
end

SUBROUTINE BU_PRUMWAND(inpuffer,outpuffer,fehler)
...
implicit none
character*30 inpuffer,outpuffer
...
end

This was not noticed before, which in fact is an improvement. We now have the problem, that the system worked ok before and we quickly need to fix this.

One idea as a quick solution is to turn the bounds check runtime error into a warning with the compiler option "-WB". What is the correct usage for that? I tried to compile the library with "-check all -WB", but this still gives a runtime error. Do I have to specify this option for the executable as well or as a linking option?

Is it possible to deactivate this character length check, but still use the bounds check for "normal" arrays? If this is not possible, can this be a new option for upcoming releases?

Regards,
Hendrik D.
0 Kudos
1 Solution
Steven_L_Intel1
Employee
873 Views

The best solution is to use CHARACTER(*) in the subroutine. No, there is not an option to separate character and array bounds checking, and we have no plans for such an option.

View solution in original post

0 Kudos
7 Replies
Steven_L_Intel1
Employee
874 Views

The best solution is to use CHARACTER(*) in the subroutine. No, there is not an option to separate character and array bounds checking, and we have no plans for such an option.
0 Kudos
hdankowski
Beginner
873 Views

The best solution is to use CHARACTER(*) in the subroutine. No, there is not an option to separate character and array bounds checking, and we have no plans for such an option.

Hi,

thanks for the quick reply, great! That's probably the best solution here.

But again, how is the correct usage for this -WB option that the bounds check only produces warnings but not runtime errors?

Thanks,
Hendrik D.
0 Kudos
Steven_L_Intel1
Employee
873 Views
-WB affects places where the compiler, at compile time, can detect a bounds error. That's not the case here, though I think that if you had also added "-warn interface" you would have received a compile-time diagnostic.
0 Kudos
hdankowski
Beginner
873 Views
-WB affects places where the compiler, at compile time, can detect a bounds error. That's not the case here, though I think that if you had also added "-warn interface" you would have received a compile-time diagnostic.

Thanks again.

I tried that and also generated a small testcase, which is attached. I compiled it with:

ifort -c -check all dummy.f
ifort dummy.o main.f90

./a.out produces the expected runtime error:
forrtl: severe (408): fort: (18): Dummy character variable 'INPUFFER' has length 30 which is greater then actual variable length 1

Image PC Routine Line Source
a.out 08095C8D Unknown Unknown Unknown
a.out 08094A85 Unknown Unknown Unknown
a.out 08061958 Unknown Unknown Unknown
a.out 0804B707 Unknown Unknown Unknown
a.out 0804B9D8 Unknown Unknown Unknown
a.out 0804A36E bu_prumwand 102 dummy.f
a.out 0804A171 bu_prliesconf 74 dummy.f
a.out 0804A8D2 MAIN__ 3 main.f90
a.out 08049E91 Unknown Unknown Unknown
libc.so.6 B7DA8FE0 Unknown Unknown Unknown
a.out 08049DD1 Unknown Unknown Unknown


Now I added the -warn interface option, but this did not have any effect, it compiled without any warning.

But very interesting that f90 code for the interfaces is generated, didn't know that before, might be useful for old f77 code.


Any other options I can try?

Regards,
Hendrik D.



0 Kudos
Steven_L_Intel1
Employee
873 Views
Your new code uses character(*) so -warn interface doesn't see a problem.
0 Kudos
hdankowski
Beginner
873 Views
Your new code uses character(*) so -warn interface doesn't see a problem.

No it does not:
SUBROUTINE BU_PRUMWAND(inpuffer,outpuffer,fehler)

implicit none

character*30 inpuffer,outpuffer

...

thats just the old f77 style of char length declaration. the bounds check still throws an error!

hendrik
0 Kudos
Steven_L_Intel1
Employee
873 Views
Yes, it does:

SUBROUTINE BU_PRLIESCONF(confile)
...
character*(*) confile

So, for the call from the main program to BU_PRILESCONF, the compiler sees no problem. You later call BU_PRUMWAND with a run-time substring of inpbuffer - the compiler does not see a constant length here and therefore doesn't give a compile-time error for that call.
0 Kudos
Reply