2019-07-08 23:45:24 +08:00
// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s -Wuninitialized
// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -std=c++98 -o - %s -Wuninitialized
// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -std=c++11 -o - %s -Wuninitialized
2014-07-22 14:45:04 +08:00
2019-07-08 23:45:24 +08:00
// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -o - %s -Wuninitialized
// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -std=c++98 -o - %s -Wuninitialized
// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 -std=c++11 -o - %s -Wuninitialized
2017-12-30 02:07:07 +08:00
[OPENMP]Initial fix PR42392: Improve -Wuninitialized warnings for OpenMP programs.
Summary:
Some OpenMP clauses rely on the values of the variables. If the variable
is not initialized and used in OpenMP clauses that depend on the
variables values, it should be reported that the uninitialized variable
is used in the OpenMP clause expression.
This patch adds initial processing for uninitialized variables in OpenMP
constructs. Currently, it checks for use of the uninitialized variables
in the structured blocks.
Reviewers: NoQ, Szelethus, dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet
Subscribers: rnkovacs, guansong, jfb, jdoerfert, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64356
llvm-svn: 365786
2019-07-11 22:54:17 +08:00
void xxx ( int argc ) {
int x ; // expected-note {{initialize the variable 'x' to silence this warning}}
# pragma omp for ordered
for ( int i = 0 ; i < 10 ; + + i ) {
# pragma omp ordered
argc = x ; // expected-warning {{variable 'x' is uninitialized when used here}}
}
}
2014-07-22 14:45:04 +08:00
int foo ( ) ;
template < class T >
T foo ( ) {
2015-12-23 18:27:45 +08:00
T k ;
2014-07-22 14:45:04 +08:00
# pragma omp for ordered
for ( int i = 0 ; i < 10 ; + + i ) {
L1 :
foo ( ) ;
# pragma omp ordered
{
foo ( ) ;
goto L1 ; // expected-error {{use of undeclared label 'L1'}}
}
}
# pragma omp for ordered
for ( int i = 0 ; i < 10 ; + + i ) {
foo ( ) ;
goto L2 ; // expected-error {{use of undeclared label 'L2'}}
# pragma omp ordered
{
L2 :
foo ( ) ;
}
}
2015-09-25 18:37:12 +08:00
# pragma omp for ordered
for ( int i = 0 ; i < 10 ; + + i ) {
# pragma omp ordered threads threads // expected-error {{directive '#pragma omp ordered' cannot contain more than one 'threads' clause}}
{
foo ( ) ;
}
}
# pragma omp for ordered(1) // expected-note {{'ordered' clause with specified parameter}}
for ( int i = 0 ; i < 10 ; + + i ) {
# pragma omp ordered // expected-error {{'ordered' directive without any clauses cannot be closely nested inside ordered region with specified parameter}}
{
foo ( ) ;
}
}
# pragma omp for ordered(1) // expected-note {{'ordered' clause with specified parameter}}
for ( int i = 0 ; i < 10 ; + + i ) {
# pragma omp ordered threads // expected-error {{'ordered' directive with 'threads' clause cannot be closely nested inside ordered region with specified parameter}}
{
foo ( ) ;
}
}
2020-06-17 01:16:08 +08:00
# pragma omp for ordered
for ( int i = 0 ; i < 10 ; + + i ) {
# pragma omp ordered // expected-note {{previous 'ordered' directive used here}}
{
foo ( ) ;
}
# pragma omp ordered // expected-error {{exactly one 'ordered' directive must appear in the loop body of an enclosing directive}}
{
foo ( ) ;
}
}
2015-09-28 14:39:35 +08:00
# pragma omp ordered simd simd // expected-error {{directive '#pragma omp ordered' cannot contain more than one 'simd' clause}}
{
foo ( ) ;
}
# pragma omp simd
for ( int i = 0 ; i < 10 ; + + i ) {
# pragma omp ordered // expected-error {{OpenMP constructs may not be nested inside a simd region}}
{
foo ( ) ;
}
}
# pragma omp simd
for ( int i = 0 ; i < 10 ; + + i ) {
# pragma omp ordered threads // expected-error {{OpenMP constructs may not be nested inside a simd region}}
{
foo ( ) ;
}
}
2020-06-17 01:16:08 +08:00
# pragma omp simd
for ( int i = 0 ; i < 10 ; + + i ) {
# pragma omp ordered simd // expected-note {{previous 'ordered' directive used here}}
{
foo ( ) ;
}
# pragma omp ordered simd // expected-error {{exactly one 'ordered' directive must appear in the loop body of an enclosing directive}}
{
foo ( ) ;
}
}
# pragma omp for simd
2015-09-28 14:39:35 +08:00
for ( int i = 0 ; i < 10 ; + + i ) {
# pragma omp ordered // expected-error {{OpenMP constructs may not be nested inside a simd region}}
{
foo ( ) ;
}
}
# pragma omp for simd
for ( int i = 0 ; i < 10 ; + + i ) {
# pragma omp ordered threads // expected-error {{OpenMP constructs may not be nested inside a simd region}}
{
foo ( ) ;
}
}
# pragma omp parallel for simd
for ( int i = 0 ; i < 10 ; + + i ) {
# pragma omp ordered // expected-error {{OpenMP constructs may not be nested inside a simd region}}
{
foo ( ) ;
}
}
# pragma omp parallel for simd
for ( int i = 0 ; i < 10 ; + + i ) {
# pragma omp ordered threads // expected-error {{OpenMP constructs may not be nested inside a simd region}}
{
foo ( ) ;
}
2015-12-18 13:05:56 +08:00
# pragma omp ordered depend(source) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
}
# pragma omp parallel for ordered
for ( int i = 0 ; i < 10 ; + + i ) {
# pragma omp ordered depend(source) // expected-error {{'ordered' directive with 'depend' clause cannot be closely nested inside ordered region without specified parameter}}
2015-12-23 18:27:45 +08:00
# pragma omp ordered depend(sink : i) // expected-error {{'ordered' directive with 'depend' clause cannot be closely nested inside ordered region without specified parameter}}
2015-12-18 13:05:56 +08:00
}
2020-03-07 00:09:55 +08:00
# pragma omp parallel for ordered(2) // expected-note 3 {{'ordered' clause with specified parameter}}
2015-12-18 13:05:56 +08:00
for ( int i = 0 ; i < 10 ; + + i ) {
for ( int j = 0 ; j < 10 ; + + j ) {
# pragma omp ordered depend // expected-error {{expected '(' after 'depend'}} expected-error {{'ordered' directive without any clauses cannot be closely nested inside ordered region with specified parameter}}
2015-12-23 18:27:45 +08:00
# pragma omp ordered depend( // expected-error {{expected ')'}} expected-error {{expected 'source' or 'sink' in OpenMP clause 'depend'}} expected-error {{'ordered' directive without any clauses cannot be closely nested inside ordered region with specified parameter}} expected-warning {{missing ':' or ')' after dependency type - ignoring}} expected-note {{to match this '('}}
2015-12-18 13:05:56 +08:00
# pragma omp ordered depend(source // expected-error {{expected ')'}} expected-note {{to match this '('}}
2020-03-07 00:09:55 +08:00
# pragma omp ordered depend(sink // expected-error {{expected expression}} expected-warning {{missing ':' or ')' after dependency type - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected 'i' loop iteration variable}}
# pragma omp ordered depend(sink : // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected expression}} expected-error {{expected 'i' loop iteration variable}}
2015-12-23 18:27:45 +08:00
# pragma omp ordered depend(sink : i // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected 'j' loop iteration variable}}
# pragma omp ordered depend(sink : i) // expected-error {{expected 'j' loop iteration variable}}
2015-12-18 13:05:56 +08:00
# pragma omp ordered depend(source)
if ( i = = j )
# pragma omp ordered depend(source) // expected-error {{'#pragma omp ordered' with 'depend' clause cannot be an immediate substatement}}
;
2015-12-23 18:27:45 +08:00
if ( i = = j )
# pragma omp ordered depend(sink : i, j) // expected-error {{'#pragma omp ordered' with 'depend' clause cannot be an immediate substatement}}
;
2015-12-18 13:05:56 +08:00
# pragma omp ordered depend(source) threads // expected-error {{'depend' clauses cannot be mixed with 'threads' clause}}
# pragma omp ordered simd depend(source) // expected-error {{'depend' clauses cannot be mixed with 'simd' clause}}
# pragma omp ordered depend(source) depend(source) // expected-error {{directive '#pragma omp ordered' cannot contain more than one 'depend' clause with 'source' dependence}}
2015-12-23 18:27:45 +08:00
# pragma omp ordered depend(in : i) // expected-error {{expected 'source' or 'sink' in OpenMP clause 'depend'}} expected-error {{'ordered' directive without any clauses cannot be closely nested inside ordered region with specified parameter}}
# pragma omp ordered depend(sink : i, j)
# pragma omp ordered depend(sink : j, i) // expected-error {{expected 'i' loop iteration variable}} expected-error {{expected 'j' loop iteration variable}}
# pragma omp ordered depend(sink : i, j, k) // expected-error {{unexpected expression: number of expressions is larger than the number of associated loops}}
2020-08-20 03:46:22 +08:00
# pragma omp ordered depend(sink : i+foo(), j / 4) // expected-error {{integral constant expression}} expected-error {{expected '+' or '-' operation}}
2017-02-04 02:58:34 +08:00
# if __cplusplus >= 201103L
// expected-note@-2 {{non-constexpr function 'foo' cannot be used in a constant expression}}
# endif
2015-12-23 18:27:45 +08:00
# pragma omp ordered depend(sink : i*0, j-4) // expected-error {{expected '+' or '-' operation}}
# pragma omp ordered depend(sink : i-0, j+sizeof(T)) depend(sink : i-0, j+sizeof(T))
# pragma omp ordered depend(sink : i-0, j+sizeof(T)) depend(source) // expected-error {{'depend(source)' clause cannot be mixed with 'depend(sink:vec)' clauses}}
# pragma omp ordered depend(source) depend(sink : i-0, j+sizeof(T)) // expected-error {{'depend(sink:vec)' clauses cannot be mixed with 'depend(source)' clause}}
2015-12-18 13:05:56 +08:00
}
2015-09-28 14:39:35 +08:00
}
2018-02-16 06:42:57 +08:00
# pragma omp ordered depend(source) // expected-error {{'ordered' directive with 'depend' clause cannot be closely nested inside ordered region without specified parameter}}
# pragma omp ordered depend(sink:k) // expected-error {{'ordered' directive with 'depend' clause cannot be closely nested inside ordered region without specified parameter}}
2014-07-22 14:45:04 +08:00
return T ( ) ;
}
int foo ( ) {
2017-02-04 02:58:34 +08:00
# if __cplusplus >= 201103L
2020-09-04 22:13:28 +08:00
// expected-note@-2 2 {{declared here}}
2017-02-04 02:58:34 +08:00
# endif
2015-12-23 18:27:45 +08:00
int k ;
2014-07-22 14:45:04 +08:00
# pragma omp for ordered
for ( int i = 0 ; i < 10 ; + + i ) {
L1 :
foo ( ) ;
# pragma omp ordered
{
foo ( ) ;
goto L1 ; // expected-error {{use of undeclared label 'L1'}}
}
}
# pragma omp for ordered
for ( int i = 0 ; i < 10 ; + + i ) {
foo ( ) ;
goto L2 ; // expected-error {{use of undeclared label 'L2'}}
# pragma omp ordered
{
L2 :
foo ( ) ;
}
}
2015-09-25 18:37:12 +08:00
# pragma omp for ordered
for ( int i = 0 ; i < 10 ; + + i ) {
# pragma omp ordered threads threads // expected-error {{directive '#pragma omp ordered' cannot contain more than one 'threads' clause}}
{
foo ( ) ;
}
}
# pragma omp for ordered(1) // expected-note {{'ordered' clause with specified parameter}}
for ( int i = 0 ; i < 10 ; + + i ) {
# pragma omp ordered // expected-error {{'ordered' directive without any clauses cannot be closely nested inside ordered region with specified parameter}}
{
foo ( ) ;
}
}
# pragma omp for ordered(1) // expected-note {{'ordered' clause with specified parameter}}
for ( int i = 0 ; i < 10 ; + + i ) {
# pragma omp ordered threads // expected-error {{'ordered' directive with 'threads' clause cannot be closely nested inside ordered region with specified parameter}}
{
foo ( ) ;
}
}
2015-09-28 14:39:35 +08:00
# pragma omp ordered simd simd // expected-error {{directive '#pragma omp ordered' cannot contain more than one 'simd' clause}}
{
foo ( ) ;
}
# pragma omp simd
for ( int i = 0 ; i < 10 ; + + i ) {
# pragma omp ordered // expected-error {{OpenMP constructs may not be nested inside a simd region}}
{
foo ( ) ;
}
}
# pragma omp simd
for ( int i = 0 ; i < 10 ; + + i ) {
# pragma omp ordered threads // expected-error {{OpenMP constructs may not be nested inside a simd region}}
{
foo ( ) ;
}
}
# pragma omp for simd
for ( int i = 0 ; i < 10 ; + + i ) {
# pragma omp ordered // expected-error {{OpenMP constructs may not be nested inside a simd region}}
{
foo ( ) ;
}
}
# pragma omp for simd
for ( int i = 0 ; i < 10 ; + + i ) {
# pragma omp ordered threads // expected-error {{OpenMP constructs may not be nested inside a simd region}}
{
foo ( ) ;
}
}
# pragma omp parallel for simd
for ( int i = 0 ; i < 10 ; + + i ) {
# pragma omp ordered // expected-error {{OpenMP constructs may not be nested inside a simd region}}
{
foo ( ) ;
}
}
# pragma omp parallel for simd
for ( int i = 0 ; i < 10 ; + + i ) {
# pragma omp ordered threads // expected-error {{OpenMP constructs may not be nested inside a simd region}}
{
foo ( ) ;
}
2015-12-18 13:05:56 +08:00
# pragma omp ordered depend(source) // expected-error {{OpenMP constructs may not be nested inside a simd region}}
}
# pragma omp parallel for ordered
for ( int i = 0 ; i < 10 ; + + i ) {
# pragma omp ordered depend(source) // expected-error {{'ordered' directive with 'depend' clause cannot be closely nested inside ordered region without specified parameter}}
2015-12-23 18:27:45 +08:00
# pragma omp ordered depend(sink : i) // expected-error {{'ordered' directive with 'depend' clause cannot be closely nested inside ordered region without specified parameter}}
2015-12-18 13:05:56 +08:00
}
2020-03-07 00:09:55 +08:00
# pragma omp parallel for ordered(2) // expected-note 3 {{'ordered' clause with specified parameter}}
2015-12-18 13:05:56 +08:00
for ( int i = 0 ; i < 10 ; + + i ) {
for ( int j = 0 ; j < 10 ; + + j ) {
# pragma omp ordered depend // expected-error {{expected '(' after 'depend'}} expected-error {{'ordered' directive without any clauses cannot be closely nested inside ordered region with specified parameter}}
2015-12-23 18:27:45 +08:00
# pragma omp ordered depend( // expected-error {{expected ')'}} expected-error {{expected 'source' or 'sink' in OpenMP clause 'depend'}} expected-error {{'ordered' directive without any clauses cannot be closely nested inside ordered region with specified parameter}} expected-warning {{missing ':' or ')' after dependency type - ignoring}} expected-note {{to match this '('}}
2015-12-18 13:05:56 +08:00
# pragma omp ordered depend(source // expected-error {{expected ')'}} expected-note {{to match this '('}}
2020-03-07 00:09:55 +08:00
# pragma omp ordered depend(sink // expected-error {{expected expression}} expected-warning {{missing ':' or ')' after dependency type - ignoring}} expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected 'i' loop iteration variable}}
# pragma omp ordered depend(sink : // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected expression}} expected-error {{expected 'i' loop iteration variable}}
2015-12-23 18:27:45 +08:00
# pragma omp ordered depend(sink : i // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected 'j' loop iteration variable}}
# pragma omp ordered depend(sink : i) // expected-error {{expected 'j' loop iteration variable}}
2015-12-18 13:05:56 +08:00
# pragma omp ordered depend(source)
if ( i = = j )
# pragma omp ordered depend(source) // expected-error {{'#pragma omp ordered' with 'depend' clause cannot be an immediate substatement}}
;
2015-12-23 18:27:45 +08:00
if ( i = = j )
# pragma omp ordered depend(sink : i, j) // expected-error {{'#pragma omp ordered' with 'depend' clause cannot be an immediate substatement}}
;
2015-12-18 13:05:56 +08:00
# pragma omp ordered depend(source) threads // expected-error {{'depend' clauses cannot be mixed with 'threads' clause}}
# pragma omp ordered simd depend(source) // expected-error {{'depend' clauses cannot be mixed with 'simd' clause}}
# pragma omp ordered depend(source) depend(source) // expected-error {{directive '#pragma omp ordered' cannot contain more than one 'depend' clause with 'source' dependence}}
2015-12-23 18:27:45 +08:00
# pragma omp ordered depend(in : i) // expected-error {{expected 'source' or 'sink' in OpenMP clause 'depend'}} expected-error {{'ordered' directive without any clauses cannot be closely nested inside ordered region with specified parameter}}
2019-03-27 22:14:31 +08:00
# pragma omp ordered depend(sink : i, j) allocate(i) // expected-error {{unexpected OpenMP clause 'allocate' in directive '#pragma omp ordered'}}
2015-12-23 18:27:45 +08:00
# pragma omp ordered depend(sink : j, i) // expected-error {{expected 'i' loop iteration variable}} expected-error {{expected 'j' loop iteration variable}}
# pragma omp ordered depend(sink : i, j, k) // expected-error {{unexpected expression: number of expressions is larger than the number of associated loops}}
2020-08-20 03:46:22 +08:00
# pragma omp ordered depend(sink : i+foo(), j / 4) // expected-error {{integral constant expression}} expected-error {{expected '+' or '-' operation}}
2017-02-04 02:58:34 +08:00
# if __cplusplus >= 201103L
// expected-note@-2 {{non-constexpr function 'foo' cannot be used in a constant expression}}
# endif
2015-12-23 18:27:45 +08:00
# pragma omp ordered depend(sink : i*0, j-4) // expected-error {{expected '+' or '-' operation}}
# pragma omp ordered depend(sink : i-0, j+sizeof(int)) depend(sink : i-0, j+sizeof(int))
# pragma omp ordered depend(sink : i-0, j+sizeof(int)) depend(source) // expected-error {{'depend(source)' clause cannot be mixed with 'depend(sink:vec)' clauses}}
# pragma omp ordered depend(source) depend(sink : i-0, j+sizeof(int)) // expected-error {{'depend(sink:vec)' clauses cannot be mixed with 'depend(source)' clause}}
2015-12-18 13:05:56 +08:00
}
2015-09-28 14:39:35 +08:00
}
2014-07-22 14:45:04 +08:00
2017-09-20 05:04:23 +08:00
# pragma omp for ordered(2) // expected-note {{as specified in 'ordered' clause}}
for ( int i = 0 ; i < 10 ; + + i ) { // expected-error {{expected 2 for loops after '#pragma omp for', but found only 1}}
# pragma omp ordered depend(sink : i)
int j ;
# pragma omp ordered depend(sink : i, j) // expected-error {{expected loop iteration variable}}
foo ( ) ;
}
2015-12-23 18:27:45 +08:00
return foo < int > ( ) ; // expected-note {{in instantiation of function template specialization 'foo<int>' requested here}}
2014-07-22 14:45:04 +08:00
}