View previous topic :: View next topic |
Author |
Message |
Sebastian
Joined: 20 Feb 2008 Posts: 177
|
Posted: Tue Dec 02, 2008 12:22 pm Post subject: checkmate fails to point out zero ref |
|
|
Hello,
checkmate seems to overlook full-array assignments to not-allocated arrays. There's no problem with assigning only a single element (or a range) which is correctly claimed as invalid operation when using checkmate.
Sample:
Code: | program alloc
integer, allocatable, dimension(:) :: array
array = 0
print*, "Should not reach this."
end program alloc |
Compile with Quote: | ftn95 /checkmate alloc.f90 /link | and it just runs (which is wrong).
Compile it with Quote: | ftn95 alloc.f90 /link | and it will throw an access violation when running the app (this is basically correct as the unallocated array is a zero reference).
Is this expected to behave like that (why)?
Thanks. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7927 Location: Salford, UK
|
Posted: Tue Dec 02, 2008 1:11 pm Post subject: |
|
|
We will take a look at this to see if the error can be trapped. |
|
Back to top |
|
|
Sebastian
Joined: 20 Feb 2008 Posts: 177
|
Posted: Thu Dec 04, 2008 11:22 am Post subject: |
|
|
Thanks.
Do you happen to know if it is actually an error (coding bug) or should a
full-array assignment just be ignored by the compiler if the array is not
allocated yet? The latter would make sense if the full-array alloc is something
like "initialize all elements" where elements==0 for unallocated arrays. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7927 Location: Salford, UK
|
Posted: Thu Dec 04, 2008 1:18 pm Post subject: |
|
|
It is a programming error but it would be nice if checkmate was clever enough to flag it. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7927 Location: Salford, UK
|
Posted: Fri Dec 12, 2008 5:19 pm Post subject: |
|
|
We have investigated this matter to see if checkmate can be extended to check for this programming error. Unfortunately this is not possible without endangering other parts of the compiler. In other words the undef check works for individual elements but not for block assignment and we cannot see a way to improve on this.
What happens is the compiler expands the block assignment into a loop but the loop is never entered because the default size is negative. As a result the built-in test on individual elements is never applied.
In practice the fault will become apparent when you try to access the array values. |
|
Back to top |
|
|
Sebastian
Joined: 20 Feb 2008 Posts: 177
|
Posted: Mon Dec 15, 2008 9:35 am Post subject: |
|
|
Quote: | In practice the fault will become apparent when you try to access the array values. |
Actually the faulting instruction when compiling in release mode is the full-array assignment and not a following read or write access to an array element. Means if the array is (for whatever reason) never used, the checkmate compile works without error, but the releasemode executable crashes.
Quote: | but the loop is never entered because the default size is negative |
What is the default value for that loop in release mode? Or is it undefined?
Thanks. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7927 Location: Salford, UK
|
Posted: Mon Dec 15, 2008 12:25 pm Post subject: |
|
|
I do understand where the fault occurs but, as you pointed out, the impact of the programming error may occur later.
In theory the default value of the size (of an unallocated array) is undefined.
You cannot rely on its value either from one compiler to another or even within FTN95 from one release to another. |
|
Back to top |
|
|
Sebastian
Joined: 20 Feb 2008 Posts: 177
|
Posted: Tue Dec 16, 2008 9:02 am Post subject: |
|
|
Quote: | You cannot rely on its value either from one compiler to another or even within FTN95 from one release to another. |
But using additional checks/preinitializations (fieldsize negative for checkmate) it would be possible, right? But that's the "without endangering other parts of the compiler" part you talked about I guess.
Thanks anyways for looking into it. |
|
Back to top |
|
|
|