Fortran: Silence -Wmaybe-uninitialized warning

Message ID 20211031162558.3254777-1-rep.dot.nop@gmail.com
State Committed
Commit a16010a3eed9d5a3e49098351cf5ba18483cdc02
Headers
Series Fortran: Silence -Wmaybe-uninitialized warning |

Commit Message

Bernhard Reutner-Fischer Oct. 31, 2021, 4:25 p.m. UTC
  From: Bernhard Reutner-Fischer <aldot@gcc.gnu.org>

gcc/fortran/ChangeLog:

	* resolve.c (resolve_fl_procedure): Initialize
	allocatable_or_pointer.

---
fortran/resolve.c: In function 'bool resolve_fl_procedure(gfc_symbol*, int)':
fortran/resolve.c:13391:7: warning: 'allocatable_or_pointer' may be used uninitialized in this function [-Wmaybe-uninitialized]
13390 |   if (sym->attr.elemental && sym->result
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13391 |       && allocatable_or_pointer)
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~
.../fortran/resolve.c:13197:8: note: 'allocatable_or_pointer' was declared here
13197 |   bool allocatable_or_pointer;
      |        ^~~~~~~~~~~~~~~~~~~~~~

Bootstrapped and regtested without regressions.
Ok for trunk?
---
 gcc/fortran/resolve.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Thomas Koenig Oct. 31, 2021, 5:05 p.m. UTC | #1
Hi Bernhard,

> gcc/fortran/ChangeLog:
> 
> 	* resolve.c (resolve_fl_procedure): Initialize
> 	allocatable_or_pointer.



Looking at the code, it is clear that this is a false
positive, or a false maybe, but the semantics of C/C++
may well indicate that sym->result could change, although
it clearly does not.

So, OK.

Thanks for the patch!

Best regards

	Thomas
  
Bernhard Reutner-Fischer Oct. 31, 2021, 5:31 p.m. UTC | #2
On Sun, 31 Oct 2021 18:05:36 +0100
Thomas Koenig <tkoenig@netcologne.de> wrote:

> Hi Bernhard,
> 
> > gcc/fortran/ChangeLog:
> > 
> > 	* resolve.c (resolve_fl_procedure): Initialize
> > 	allocatable_or_pointer.  
> 
> Looking at the code, it is clear that this is a false
> positive, or a false maybe, but the semantics of C/C++
> may well indicate that sym->result could change, although
> it clearly does not.

Agree wholeheartedly
> 
> So, OK.

pushed as r12-4811
> 
> Thanks for the patch!

I have to thank you for the quick review!
cheers,
  

Patch

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 8da396b32ec..21126cba262 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -13179,7 +13179,7 @@  static bool
 resolve_fl_procedure (gfc_symbol *sym, int mp_flag)
 {
   gfc_formal_arglist *arg;
-  bool allocatable_or_pointer;
+  bool allocatable_or_pointer = false;
 
   if (sym->attr.function
       && !resolve_fl_var_and_proc (sym, mp_flag))