2019-07-08 23:45:24 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -fopenmp -verify %s -Wuninitialized
|
2014-06-25 19:44:49 +08:00
|
|
|
|
2019-07-08 23:45:24 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -fopenmp-simd -verify %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 sections
|
|
|
|
{
|
|
|
|
argc = x; // expected-warning {{variable 'x' is uninitialized when used here}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-25 19:44:49 +08:00
|
|
|
void foo();
|
|
|
|
|
|
|
|
// expected-error@+1 {{unexpected OpenMP directive '#pragma omp sections'}}
|
|
|
|
#pragma omp sections
|
|
|
|
|
|
|
|
// expected-error@+1 {{unexpected OpenMP directive '#pragma omp sections'}}
|
|
|
|
#pragma omp sections foo
|
|
|
|
|
|
|
|
void test_no_clause() {
|
|
|
|
int i;
|
|
|
|
#pragma omp sections
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
|
|
|
|
// expected-error@+2 {{the statement for '#pragma omp sections' must be a compound statement}}
|
|
|
|
#pragma omp sections
|
|
|
|
++i;
|
2014-06-26 16:21:58 +08:00
|
|
|
|
|
|
|
#pragma omp sections
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
foo(); // expected-error {{statement in 'omp sections' directive must be enclosed into a section region}}
|
|
|
|
}
|
2014-06-25 19:44:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_branch_protected_scope() {
|
|
|
|
int i = 0;
|
|
|
|
L1:
|
|
|
|
++i;
|
|
|
|
|
|
|
|
int x[24];
|
|
|
|
|
|
|
|
#pragma omp parallel
|
|
|
|
#pragma omp sections
|
|
|
|
{
|
|
|
|
if (i == 5)
|
|
|
|
goto L1; // expected-error {{use of undeclared label 'L1'}}
|
|
|
|
else if (i == 6)
|
|
|
|
return; // expected-error {{cannot return from OpenMP region}}
|
|
|
|
else if (i == 7)
|
|
|
|
goto L2;
|
|
|
|
else if (i == 8) {
|
|
|
|
L2:
|
|
|
|
x[i]++;
|
|
|
|
}
|
2014-06-26 16:21:58 +08:00
|
|
|
#pragma omp section
|
|
|
|
if (i == 5)
|
|
|
|
goto L1; // expected-error {{use of undeclared label 'L1'}}
|
|
|
|
else if (i == 6)
|
|
|
|
return; // expected-error {{cannot return from OpenMP region}}
|
|
|
|
else if (i == 7)
|
|
|
|
goto L3;
|
|
|
|
else if (i == 8) {
|
|
|
|
L3:
|
|
|
|
x[i]++;
|
|
|
|
}
|
2014-06-25 19:44:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (x[0] == 0)
|
|
|
|
goto L2; // expected-error {{use of undeclared label 'L2'}}
|
|
|
|
else if (x[1] == 1)
|
|
|
|
goto L1;
|
2014-06-26 16:21:58 +08:00
|
|
|
goto L3; // expected-error {{use of undeclared label 'L3'}}
|
2014-06-25 19:44:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_invalid_clause() {
|
|
|
|
int i;
|
|
|
|
#pragma omp parallel
|
|
|
|
// expected-warning@+1 {{extra tokens at the end of '#pragma omp sections' are ignored}}
|
|
|
|
#pragma omp sections foo bar
|
|
|
|
{
|
|
|
|
foo();
|
2014-06-26 16:21:58 +08:00
|
|
|
// expected-error@+1 {{unexpected OpenMP clause 'nowait' in directive '#pragma omp section'}}
|
|
|
|
#pragma omp section nowait
|
|
|
|
;
|
2014-06-25 19:44:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_non_identifiers() {
|
|
|
|
int i, x;
|
|
|
|
|
|
|
|
#pragma omp parallel
|
|
|
|
// expected-warning@+1 {{extra tokens at the end of '#pragma omp sections' are ignored}}
|
|
|
|
#pragma omp sections;
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
#pragma omp parallel
|
|
|
|
// expected-error@+2 {{unexpected OpenMP clause 'linear' in directive '#pragma omp sections'}}
|
|
|
|
// expected-warning@+1 {{extra tokens at the end of '#pragma omp sections' are ignored}}
|
|
|
|
#pragma omp sections linear(x);
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma omp parallel
|
|
|
|
// expected-warning@+1 {{extra tokens at the end of '#pragma omp sections' are ignored}}
|
|
|
|
#pragma omp sections private(x);
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma omp parallel
|
|
|
|
// expected-warning@+1 {{extra tokens at the end of '#pragma omp sections' are ignored}}
|
|
|
|
#pragma omp sections, private(x);
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_private() {
|
|
|
|
int i;
|
|
|
|
#pragma omp parallel
|
|
|
|
// expected-error@+2 {{expected expression}}
|
|
|
|
// expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
|
|
|
|
#pragma omp sections private(
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
#pragma omp parallel
|
|
|
|
// expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
|
2016-04-01 16:43:42 +08:00
|
|
|
// expected-error@+1 2 {{expected expression}}
|
2014-06-25 19:44:49 +08:00
|
|
|
#pragma omp sections private(,
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
#pragma omp parallel
|
2016-04-01 16:43:42 +08:00
|
|
|
// expected-error@+1 2 {{expected expression}}
|
2014-06-25 19:44:49 +08:00
|
|
|
#pragma omp sections private(, )
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
#pragma omp parallel
|
|
|
|
// expected-error@+1 {{expected expression}}
|
|
|
|
#pragma omp sections private()
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
#pragma omp parallel
|
|
|
|
// expected-error@+1 {{expected expression}}
|
|
|
|
#pragma omp sections private(int)
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
#pragma omp parallel
|
|
|
|
// expected-error@+1 {{expected variable name}}
|
|
|
|
#pragma omp sections private(0)
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
|
|
|
|
int x, y, z;
|
|
|
|
#pragma omp parallel
|
|
|
|
#pragma omp sections private(x)
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
#pragma omp parallel
|
|
|
|
#pragma omp sections private(x, y)
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
#pragma omp parallel
|
|
|
|
#pragma omp sections private(x, y, z)
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_lastprivate() {
|
|
|
|
int i;
|
|
|
|
#pragma omp parallel
|
|
|
|
// expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
|
|
|
|
// expected-error@+1 {{expected expression}}
|
|
|
|
#pragma omp sections lastprivate(
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma omp parallel
|
|
|
|
// expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
|
2016-04-01 16:43:42 +08:00
|
|
|
// expected-error@+1 2 {{expected expression}}
|
2014-06-25 19:44:49 +08:00
|
|
|
#pragma omp sections lastprivate(,
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
#pragma omp parallel
|
2016-04-01 16:43:42 +08:00
|
|
|
// expected-error@+1 2 {{expected expression}}
|
2014-06-25 19:44:49 +08:00
|
|
|
#pragma omp sections lastprivate(, )
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
#pragma omp parallel
|
|
|
|
// expected-error@+1 {{expected expression}}
|
|
|
|
#pragma omp sections lastprivate()
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
#pragma omp parallel
|
|
|
|
// expected-error@+1 {{expected expression}}
|
|
|
|
#pragma omp sections lastprivate(int)
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
#pragma omp parallel
|
|
|
|
// expected-error@+1 {{expected variable name}}
|
|
|
|
#pragma omp sections lastprivate(0)
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
|
|
|
|
int x, y, z;
|
|
|
|
#pragma omp parallel
|
|
|
|
#pragma omp sections lastprivate(x)
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
#pragma omp parallel
|
|
|
|
#pragma omp sections lastprivate(x, y)
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
#pragma omp parallel
|
|
|
|
#pragma omp sections lastprivate(x, y, z)
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_firstprivate() {
|
|
|
|
int i;
|
|
|
|
#pragma omp parallel
|
|
|
|
// expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
|
|
|
|
// expected-error@+1 {{expected expression}}
|
|
|
|
#pragma omp sections firstprivate(
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma omp parallel
|
|
|
|
// expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
|
2016-04-01 16:43:42 +08:00
|
|
|
// expected-error@+1 2 {{expected expression}}
|
2014-06-25 19:44:49 +08:00
|
|
|
#pragma omp sections firstprivate(,
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
#pragma omp parallel
|
2016-04-01 16:43:42 +08:00
|
|
|
// expected-error@+1 2 {{expected expression}}
|
2014-06-25 19:44:49 +08:00
|
|
|
#pragma omp sections firstprivate(, )
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
#pragma omp parallel
|
|
|
|
// expected-error@+1 {{expected expression}}
|
|
|
|
#pragma omp sections firstprivate()
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
#pragma omp parallel
|
|
|
|
// expected-error@+1 {{expected expression}}
|
|
|
|
#pragma omp sections firstprivate(int)
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
#pragma omp parallel
|
|
|
|
// expected-error@+1 {{expected variable name}}
|
|
|
|
#pragma omp sections firstprivate(0)
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
|
|
|
|
int x, y, z;
|
|
|
|
#pragma omp parallel
|
|
|
|
#pragma omp sections lastprivate(x) firstprivate(x)
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
#pragma omp parallel
|
|
|
|
#pragma omp sections lastprivate(x, y) firstprivate(x, y)
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
#pragma omp parallel
|
|
|
|
#pragma omp sections lastprivate(x, y, z) firstprivate(x, y, z)
|
|
|
|
{
|
|
|
|
foo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-21 10:45:36 +08:00
|
|
|
void test_nowait() {
|
|
|
|
#pragma omp parallel
|
|
|
|
#pragma omp sections nowait nowait // expected-error {{directive '#pragma omp sections' cannot contain more than one 'nowait' clause}}
|
|
|
|
{
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|