2020-07-30 00:18:45 +08:00
// RUN: %clang_cc1 -verify=expected,lt50,lt51 -fopenmp -fopenmp-version=45 -ferror-limit 100 -o - -std=c++11 %s -Wuninitialized
// RUN: %clang_cc1 -verify=expected,ge50,lt51 -fopenmp -fopenmp-version=50 -ferror-limit 100 -o - -std=c++11 %s -Wuninitialized
// RUN: %clang_cc1 -verify=expected,ge50,ge51 -fopenmp -fopenmp-version=51 -ferror-limit 100 -o - -std=c++11 %s -Wuninitialized
2016-05-27 01:30:50 +08:00
2020-07-30 00:18:45 +08:00
// RUN: %clang_cc1 -verify=expected,lt50,lt51 -fopenmp-simd -fopenmp-version=45 -ferror-limit 100 -o - -std=c++11 %s -Wuninitialized
// RUN: %clang_cc1 -verify=expected,ge50,lt51 -fopenmp-simd -fopenmp-version=50 -ferror-limit 100 -o - -std=c++11 %s -Wuninitialized
// RUN: %clang_cc1 -verify=expected,ge50,ge51 -fopenmp-simd -fopenmp-version=51 -ferror-limit 100 -o - -std=c++11 %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 target update to(x)
argc = x ; // expected-warning {{variable 'x' is uninitialized when used here}}
}
2016-05-27 01:30:50 +08:00
void foo ( ) {
}
bool foobool ( int argc ) {
return argc ;
}
struct S1 ; // Aexpected-note {{declared here}}
template < class T , class S > // Aexpected-note {{declared here}}
int tmain ( T argc , S * * argv ) {
int n ;
return 0 ;
}
2020-07-30 00:18:45 +08:00
struct S {
int i ;
} ;
2016-05-27 01:30:50 +08:00
int main ( int argc , char * * argv ) {
int m ;
# pragma omp target update // expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
2016-05-27 01:39:58 +08:00
# pragma omp target update to(m) { // expected-warning {{extra tokens at the end of '#pragma omp target update' are ignored}}
# pragma omp target update to(m) ( // expected-warning {{extra tokens at the end of '#pragma omp target update' are ignored}}
# pragma omp target update to(m) [ // expected-warning {{extra tokens at the end of '#pragma omp target update' are ignored}}
# pragma omp target update to(m) ] // expected-warning {{extra tokens at the end of '#pragma omp target update' are ignored}}
# pragma omp target update to(m) ) // expected-warning {{extra tokens at the end of '#pragma omp target update' are ignored}}
2016-05-27 01:30:50 +08:00
2020-07-30 00:18:45 +08:00
# pragma omp declare mapper(id: S s) map(s.i)
S s ;
// Check parsing with no modifiers.
// lt51-error@+2 {{expected expression}}
// lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
# pragma omp target update to(: s)
// expected-error@+2 {{expected expression}}
// expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
# pragma omp target update to(:)
// expected-error@+2 2 {{expected expression}}
// expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
# pragma omp target update to(,:)
// Check parsing with one modifier.
// expected-error@+2 {{use of undeclared identifier 'foobar'}}
// expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
# pragma omp target update to(foobar: s)
// expected-error@+3 {{expected ',' or ')' in 'to' clause}}
// expected-error@+2 {{expected ')'}}
// expected-note@+1 {{to match this '('}}
# pragma omp target update to(m: s)
# pragma omp target update to(mapper(id): s)
// lt51-error@+2 {{use of undeclared identifier 'present'}}
// lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
# pragma omp target update to(present: s)
// ge51-warning@+4 {{missing ':' after motion modifier - ignoring}}
// lt51-warning@+3 {{missing ':' after ) - ignoring}}
// expected-error@+2 {{expected expression}}
// expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
# pragma omp target update to(mapper(id) s)
// ge51-warning@+4 {{missing ':' after motion modifier - ignoring}}
// ge51-error@+3 {{expected expression}}
// lt51-error@+2 {{use of undeclared identifier 'present'}}
// expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
# pragma omp target update to(present s)
// ge51-warning@+4 {{missing ':' after motion modifier - ignoring}}
// lt51-warning@+3 {{missing ':' after ) - ignoring}}
// expected-error@+2 {{expected expression}}
// expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
# pragma omp target update to(mapper(id))
// ge51-warning@+4 {{missing ':' after motion modifier - ignoring}}
// ge51-error@+3 {{expected expression}}
// lt51-error@+2 {{use of undeclared identifier 'present'}}
// expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
# pragma omp target update to(present)
// expected-error@+2 {{expected expression}}
// expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
# pragma omp target update to(mapper(id):)
// ge51-error@+3 {{expected expression}}
// lt51-error@+2 {{use of undeclared identifier 'present'}}
// expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
# pragma omp target update to(present:)
// Check parsing with two modifiers.
// lt51-warning@+1 {{missing ':' after ) - ignoring}}
# pragma omp target update to(mapper(id), present: s)
// lt51-error@+3 {{use of undeclared identifier 'present'}}
// lt51-error@+2 {{use of undeclared identifier 'id'}}
// lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
# pragma omp target update to(present, mapper(id): s)
// lt51-warning@+1 {{missing ':' after ) - ignoring}}
# pragma omp target update to(mapper(id) present: s)
// lt51-error@+2 {{use of undeclared identifier 'present'}}
// lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
# pragma omp target update to(present mapper(id): s)
// Check parsing with unnecessary commas.
// lt51-warning@+1 {{missing ':' after ) - ignoring}}
# pragma omp target update to(mapper(id),: s)
// lt51-error@+3 {{use of undeclared identifier 'present'}}
// lt51-error@+2 {{expected expression}}
// lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
# pragma omp target update to(present , : s)
// ge51-warning@+2 {{missing ':' after motion modifier - ignoring}}
// lt51-warning@+1 {{missing ':' after ) - ignoring}}
# pragma omp target update to(mapper(id),,: s)
// ge51-warning@+5 {{missing ':' after motion modifier - ignoring}}
// lt51-error@+4 {{use of undeclared identifier 'present'}}
// lt51-error@+3 {{expected expression}}
// lt51-error@+2 {{expected expression}}
// lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
# pragma omp target update to(present,,: s)
// lt51-warning@+1 {{missing ':' after ) - ignoring}}
# pragma omp target update to(mapper(id), present,: s)
// lt51-error@+4 {{use of undeclared identifier 'present'}}
// lt51-error@+3 {{use of undeclared identifier 'id'}}
// lt51-error@+2 {{expected expression}}
// lt51-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
# pragma omp target update to(present, mapper(id),: s)
2019-03-27 22:14:31 +08:00
# pragma omp target update from(m) allocate(m) // expected-error {{unexpected OpenMP clause 'allocate' in directive '#pragma omp target update'}}
2016-05-27 01:30:50 +08:00
{
foo ( ) ;
}
2020-07-10 02:27:32 +08:00
[OpenMP5.0] map item can be non-contiguous for target update
In order not to modify the `tgt_target_data_update` information but still be
able to pass the extra information for non-contiguous map item (offset,
count, and stride for each dimension), this patch overload `arg` when
the maptype is set as `OMP_MAP_DESCRIPTOR`. The origin `arg` is for
passing the pointer information, however, the overloaded `arg` is an
array of descriptor_dim:
struct descriptor_dim {
int64_t offset;
int64_t count;
int64_t stride
};
and the array size is the same as dimension size. In addition, since we
have count and stride information in descriptor_dim, we can replace/overload the
`arg_size` parameter by using dimension size.
For supporting `stride` in array section, we use a dummy dimension in
descriptor to store the unit size. The formula for counting the stride
in dimension D_n: `unit size * (D_0 * D_1 ... * D_n-1) * D_n.stride`.
Demonstrate how it works:
```
double arr[3][4][5];
D0: { offset = 0, count = 1, stride = 8 } // offset, count, dimension size always be 0, 1, 1 for this extra dimension, stride is the unit size
D1: { offset = 0, count = 2, stride = 8 * 1 * 2 = 16 } // stride = unit size * (product of dimension size of D0) * D1.stride = 4 * 1 * 2 = 8
D2: { offset = 2, count = 2, stride = 8 * (1 * 5) * 1 = 40 } // stride = unit size * (product of dimension size of D0, D1) * D2.stride = 4 * 5 * 1 = 20
D3: { offset = 0, count = 2, stride = 8 * (1 * 5 * 4) * 2 = 320 } // stride = unit size * (product of dimension size of D0, D1, D2) * D3.stride = 4 * 25 * 2 = 200
// X here means we need to offload this data, therefore, runtime will transfer
// data from offset 80, 96, 120, 136, 400, 416, 440, 456
// Runtime patch: https://reviews.llvm.org/D82245
// OOOOO OOOOO OOOOO
// OOOOO OOOOO OOOOO
// XOXOO OOOOO XOXOO
// XOXOO OOOOO XOXOO
```
Reviewed By: ABataev
Differential Revision: https://reviews.llvm.org/D84192
2020-11-07 11:03:55 +08:00
double marr [ 10 ] [ 5 ] [ 10 ] ;
# pragma omp target update to(marr[0:2][2:4][1:2]) // lt50-error {{array section does not specify contiguous storage}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
{ }
# pragma omp target update from(marr[0:2][2:4][1:2]) // lt50-error {{array section does not specify contiguous storage}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
# pragma omp target update to(marr[0:][1:2:2][1:2]) // ge50-error {{array section does not specify length for outermost dimension}} lt50-error {{expected ']'}} lt50-note {{to match this '['}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
{ }
# pragma omp target update from(marr[0:][1:2:2][1:2]) // ge50-error {{array section does not specify length for outermost dimension}} lt50-error {{expected ']'}} lt50-note {{to match this '['}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
int arr [ 4 ] [ 3 ] [ 2 ] [ 1 ] ;
# pragma omp target update to(arr[0:2][2:4][:2][1]) // lt50-error {{array section does not specify contiguous storage}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
{ }
# pragma omp target update from(arr[0:2][2:4][:2][1]) // lt50-error {{array section does not specify contiguous storage}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
double * * * dptr ;
# pragma omp target update to(dptr[0:2][2:4][1:2]) // lt50-error {{array section does not specify contiguous storage}} ge50-error 2 {{section length is unspecified and cannot be inferred because subscripted value is an array of unknown bound}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
{ }
# pragma omp target update from(dptr[0:2][2:4][1:2]) // lt50-error {{array section does not specify contiguous storage}} ge50-error 2 {{section length is unspecified and cannot be inferred because subscripted value is an array of unknown bound}} lt50-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
2020-07-10 02:27:32 +08:00
int iarr [ 5 ] [ 5 ] ;
2020-07-30 00:18:45 +08:00
// ge50-error@+4 {{section stride is evaluated to a non-positive value -1}}
// lt50-error@+3 {{expected ']'}}
// lt50-note@+2 {{to match this '['}}
// expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
# pragma omp target update to(iarr[0:][1:2:-1])
2020-07-10 02:27:32 +08:00
{ }
2020-07-30 00:18:45 +08:00
// ge50-error@+4 {{section stride is evaluated to a non-positive value -1}}
// lt50-error@+3 {{expected ']'}}
// lt50-note@+2 {{to match this '['}}
// expected-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
# pragma omp target update from(iarr[0:][1:2:-1])
[OpenMP5.0] map item can be non-contiguous for target update
In order not to modify the `tgt_target_data_update` information but still be
able to pass the extra information for non-contiguous map item (offset,
count, and stride for each dimension), this patch overload `arg` when
the maptype is set as `OMP_MAP_DESCRIPTOR`. The origin `arg` is for
passing the pointer information, however, the overloaded `arg` is an
array of descriptor_dim:
struct descriptor_dim {
int64_t offset;
int64_t count;
int64_t stride
};
and the array size is the same as dimension size. In addition, since we
have count and stride information in descriptor_dim, we can replace/overload the
`arg_size` parameter by using dimension size.
For supporting `stride` in array section, we use a dummy dimension in
descriptor to store the unit size. The formula for counting the stride
in dimension D_n: `unit size * (D_0 * D_1 ... * D_n-1) * D_n.stride`.
Demonstrate how it works:
```
double arr[3][4][5];
D0: { offset = 0, count = 1, stride = 8 } // offset, count, dimension size always be 0, 1, 1 for this extra dimension, stride is the unit size
D1: { offset = 0, count = 2, stride = 8 * 1 * 2 = 16 } // stride = unit size * (product of dimension size of D0) * D1.stride = 4 * 1 * 2 = 8
D2: { offset = 2, count = 2, stride = 8 * (1 * 5) * 1 = 40 } // stride = unit size * (product of dimension size of D0, D1) * D2.stride = 4 * 5 * 1 = 20
D3: { offset = 0, count = 2, stride = 8 * (1 * 5 * 4) * 2 = 320 } // stride = unit size * (product of dimension size of D0, D1, D2) * D3.stride = 4 * 25 * 2 = 200
// X here means we need to offload this data, therefore, runtime will transfer
// data from offset 80, 96, 120, 136, 400, 416, 440, 456
// Runtime patch: https://reviews.llvm.org/D82245
// OOOOO OOOOO OOOOO
// OOOOO OOOOO OOOOO
// XOXOO OOOOO XOXOO
// XOXOO OOOOO XOXOO
```
Reviewed By: ABataev
Differential Revision: https://reviews.llvm.org/D84192
2020-11-07 11:03:55 +08:00
{ }
// lt50-error@+5 {{expected expression}}
// ge50-error@+4 {{array section does not specify length for outermost dimension}}
// lt50-error@+3 {{expected ']'}}
// lt50-note@+2 {{to match this '['}}
// lt50-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
# pragma omp target update to(iarr[0: :2][1:2])
{ }
// lt50-error@+5 {{expected expression}}
// ge50-error@+4 {{array section does not specify length for outermost dimension}}
// lt50-error@+3 {{expected ']'}}
// lt50-note@+2 {{to match this '['}}
// lt50-error@+1 {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}}
# pragma omp target update from(iarr[0: :2][1:2])
{ }
2020-07-10 02:27:32 +08:00
2016-05-27 01:30:50 +08:00
return tmain ( argc , argv ) ;
}