Bug 71974 - Warning: uninitialized variable with OpenMP nested loops
Summary: Warning: uninitialized variable with OpenMP nested loops
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.4
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic, openmp
Depends on:
Blocks: Wuninitialized
  Show dependency treegraph
 
Reported: 2016-07-22 17:25 UTC by Rafael Guglielmetti
Modified: 2017-08-27 21:54 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-08-24 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rafael Guglielmetti 2016-07-22 17:25:13 UTC
I used the collapse clause of OpenMP to work with a doubly nested loop as follows:
unsigned int iMax(10);
#pragma omp parallel for schedule(dynamic,1) shared(iMax) private(i, j) collapse(2)
for( i = 1; i < 4; i++ )
{
	for( j = 0; j <= iMax - i; j++ )
	{
	}
}

The above code, which seems to work, create the following warning:
warning: ‘i’ is used uninitialized in this function [-Wuninitialized]

Is it normal?
Comment 1 Rafael Guglielmetti 2016-07-25 12:30:19 UTC
With gcc 6.1.1, the above code gives rise to the error:
error: condition expression refers to iteration variable ‘i’

So I suppose my syntax was incorrect. It is annoying tough.
Comment 2 Eric Gallager 2017-08-24 21:54:15 UTC
(In reply to Rafael Guglielmetti from comment #1)
> With gcc 6.1.1, the above code gives rise to the error:
> error: condition expression refers to iteration variable ‘i’
> 
> So I suppose my syntax was incorrect. It is annoying tough.

Do you have a version of your code that avoids that error? I get it, too, and so I can't reproduce the warning with that error there... WAITING on a valid testcase.
Comment 3 Rafael Guglielmetti 2017-08-27 16:57:26 UTC
(In reply to Eric Gallager from comment #2)
> (In reply to Rafael Guglielmetti from comment #1)
> > With gcc 6.1.1, the above code gives rise to the error:
> > error: condition expression refers to iteration variable ‘i’
> > 
> > So I suppose my syntax was incorrect. It is annoying tough.
> 
> Do you have a version of your code that avoids that error? I get it, too,
> and so I can't reproduce the warning with that error there... WAITING on a
> valid testcase.

I think I did something else but I don't remember how I avoid this problem, sorry.
Comment 4 Eric Gallager 2017-08-27 21:54:09 UTC
(In reply to Rafael Guglielmetti from comment #3)
> (In reply to Eric Gallager from comment #2)
> > (In reply to Rafael Guglielmetti from comment #1)
> > > With gcc 6.1.1, the above code gives rise to the error:
> > > error: condition expression refers to iteration variable ‘i’
> > > 
> > > So I suppose my syntax was incorrect. It is annoying tough.
> > 
> > Do you have a version of your code that avoids that error? I get it, too,
> > and so I can't reproduce the warning with that error there... WAITING on a
> > valid testcase.
> 
> I think I did something else but I don't remember how I avoid this problem,
> sorry.

Okay, I'm closing this then, feel free to reopen if you ever do remember