2019-07-08 23:45:24 +08:00
// RUN: %clang_cc1 -verify -fopenmp %s -Wuninitialized
2014-07-21 17:42:05 +08:00
2019-07-08 23:45:24 +08:00
// RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
2017-12-30 02:07:07 +08:00
2014-07-21 17:42:05 +08:00
int foo ( ) ;
[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 critical
argc = x ; // expected-warning {{variable 'x' is uninitialized when used here}}
}
2015-12-15 16:19:24 +08:00
template < typename T , int N >
int tmain ( int argc , char * * argv ) { // expected-note {{declared here}}
2014-07-21 17:42:05 +08:00
# pragma omp critical
;
2019-03-27 22:14:31 +08:00
# pragma omp critical untied allocate(argc) // expected-error {{unexpected OpenMP clause 'untied' in directive '#pragma omp critical'}} expected-error {{unexpected OpenMP clause 'allocate' in directive '#pragma omp critical'}}
2014-07-21 17:42:05 +08:00
# pragma omp critical unknown // expected-warning {{extra tokens at the end of '#pragma omp critical' are ignored}}
# pragma omp critical ( // expected-error {{expected identifier}} expected-error {{expected ')'}} expected-note {{to match this '('}}
# pragma omp critical ( + // expected-error {{expected identifier}} expected-error {{expected ')'}} expected-note {{to match this '('}}
2015-12-15 16:19:24 +08:00
# pragma omp critical (name2 // expected-error {{expected ')'}} expected-note {{to match this '('}}
2014-07-21 17:42:05 +08:00
# pragma omp critical (name1)
foo ( ) ;
{
# pragma omp critical
} // expected-error {{expected statement}}
2015-12-15 16:19:24 +08:00
# pragma omp critical (name2) // expected-note {{previous 'critical' region starts here}}
2014-07-21 17:42:05 +08:00
# pragma omp critical
for ( int i = 0 ; i < 10 ; + + i ) {
foo ( ) ;
# pragma omp parallel
# pragma omp for
for ( int j = 0 ; j < 10 ; j + + ) {
foo ( ) ;
2015-12-15 16:19:24 +08:00
# pragma omp critical(name2) // expected-error {{cannot nest 'critical' regions having the same name 'name2'}}
2014-07-21 17:42:05 +08:00
foo ( ) ;
}
}
2015-12-15 16:19:24 +08:00
# pragma omp critical (name2)
2014-07-21 17:42:05 +08:00
# pragma omp critical
for ( int i = 0 ; i < 10 ; + + i ) {
foo ( ) ;
# pragma omp parallel
# pragma omp for
for ( int j = 0 ; j < 10 ; j + + ) {
# pragma omp critical
foo ( ) ;
}
}
2015-12-15 16:19:24 +08:00
# pragma omp critical (name2)
2014-07-21 17:42:05 +08:00
# pragma omp critical
for ( int i = 0 ; i < 10 ; + + i ) {
foo ( ) ;
# pragma omp parallel
# pragma omp for
for ( int j = 0 ; j < 10 ; j + + ) {
# pragma omp critical (nam)
foo ( ) ;
}
}
2015-12-15 16:19:24 +08:00
# pragma omp critical (name2) hint // expected-error {{expected '(' after 'hint'}}
foo ( ) ;
# pragma omp critical (name2) hint( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
foo ( ) ;
# pragma omp critical (name2) hint(+ // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
foo ( ) ;
2020-10-14 01:03:02 +08:00
# pragma omp critical (name2) hint(argc) // expected-error {{integral constant expression}} expected-note 0+{{constant expression}}
2015-12-15 16:19:24 +08:00
foo ( ) ;
# pragma omp critical (name) hint(N) // expected-error {{argument to 'hint' clause must be a strictly positive integer value}} expected-error {{constructs with the same name must have a 'hint' clause with the same value}} expected-note {{'hint' clause with value '4'}}
foo ( ) ;
# pragma omp critical hint(N) // expected-error {{the name of the construct must be specified in presence of 'hint' clause}}
foo ( ) ;
2014-07-21 17:42:05 +08:00
return 0 ;
}
2015-12-15 16:19:24 +08:00
int main ( int argc , char * * argv ) { // expected-note {{declared here}}
# pragma omp critical
;
# pragma omp critical untied // expected-error {{unexpected OpenMP clause 'untied' in directive '#pragma omp critical'}}
# pragma omp critical unknown // expected-warning {{extra tokens at the end of '#pragma omp critical' are ignored}}
# pragma omp critical ( // expected-error {{expected identifier}} expected-error {{expected ')'}} expected-note {{to match this '('}}
# pragma omp critical ( + // expected-error {{expected identifier}} expected-error {{expected ')'}} expected-note {{to match this '('}}
# pragma omp critical (name2 // expected-error {{expected ')'}} expected-note {{to match this '('}}
# pragma omp critical (name1)
foo ( ) ;
{
# pragma omp critical
} // expected-error {{expected statement}}
# pragma omp critical (name2) // expected-note {{previous 'critical' region starts here}}
# pragma omp critical
for ( int i = 0 ; i < 10 ; + + i ) {
foo ( ) ;
# pragma omp parallel
# pragma omp for
for ( int j = 0 ; j < 10 ; j + + ) {
foo ( ) ;
# pragma omp critical(name2) // expected-error {{cannot nest 'critical' regions having the same name 'name2'}}
foo ( ) ;
}
}
# pragma omp critical (name2)
# pragma omp critical
for ( int i = 0 ; i < 10 ; + + i ) {
foo ( ) ;
# pragma omp parallel
# pragma omp for
for ( int j = 0 ; j < 10 ; j + + ) {
# pragma omp critical
foo ( ) ;
}
}
# pragma omp critical (name2)
# pragma omp critical
for ( int i = 0 ; i < 10 ; + + i ) {
foo ( ) ;
# pragma omp parallel
# pragma omp for
for ( int j = 0 ; j < 10 ; j + + ) {
# pragma omp critical (nam)
foo ( ) ;
}
}
# pragma omp critical (name2) hint // expected-error {{expected '(' after 'hint'}}
foo ( ) ;
# pragma omp critical (name2) hint( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
foo ( ) ;
# pragma omp critical (name2) hint(+ // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
foo ( ) ;
2020-10-14 01:03:02 +08:00
# pragma omp critical (name2) hint(argc) // expected-error {{integral constant expression}} expected-note 0+{{constant expression}}
2015-12-15 16:19:24 +08:00
foo ( ) ;
# pragma omp critical (name) hint(23) // expected-note {{previous 'hint' clause with value '23'}}
foo ( ) ;
# pragma omp critical hint(-5) // expected-error {{argument to 'hint' clause must be a strictly positive integer value}}
foo ( ) ;
# pragma omp critical hint(1) // expected-error {{the name of the construct must be specified in presence of 'hint' clause}}
foo ( ) ;
return tmain < int , 4 > ( argc , argv ) + tmain < float , - 5 > ( argc , argv ) ; // expected-note {{in instantiation of function template specialization 'tmain<float, -5>' requested here}} expected-note {{in instantiation of function template specialization 'tmain<int, 4>' requested here}}
}
2014-07-21 17:42:05 +08:00
int foo ( ) {
2020-07-07 01:32:11 +08:00
L1 : // expected-note {{jump exits scope of OpenMP structured block}}
2014-07-21 17:42:05 +08:00
foo ( ) ;
# pragma omp critical
{
foo ( ) ;
2020-07-07 01:32:11 +08:00
goto L1 ; // expected-error {{cannot jump from this goto statement to its label}}
2014-07-21 17:42:05 +08:00
}
2020-07-07 01:32:11 +08:00
goto L2 ; // expected-error {{cannot jump from this goto statement to its label}}
2014-07-21 17:42:05 +08:00
# pragma omp critical
2020-07-07 01:32:11 +08:00
{ // expected-note {{jump bypasses OpenMP structured block}}
2014-07-21 17:42:05 +08:00
L2 :
foo ( ) ;
}
return 0 ;
2015-12-15 16:19:24 +08:00
}