Files
clang-p2996/clang/test/OpenMP/flush_messages.cpp
Richard Smith a6e8d5e554 PR40642: Fix determination of whether the final statement of a statement
expression is a discarded-value expression.

Summary:
We used to get this wrong in three ways:

1) During parsing, an expression-statement followed by the }) ending a
   statement expression was always treated as producing the value of the
   statement expression. That's wrong for ({ if (1) expr; })
2) During template instantiation, various kinds of statement (most
   statements not appearing directly in a compound-statement) were not
   treated as discarded-value expressions, resulting in missing volatile
   loads (etc).
3) In all contexts, an expression-statement with attributes was not
   treated as producing the value of the statement expression, eg
   ({ [[attr]] expr; }).

Also fix incorrect enforcement of OpenMP rule that directives can "only
be placed in the program at a position where ignoring or deleting the
directive would result in a program with correct syntax". In particular,
a label (be it goto, case, or default) should not affect whether
directives are permitted.

Reviewers: aaron.ballman, rjmccall

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D57984

llvm-svn: 354090
2019-02-15 00:27:53 +00:00

137 lines
4.6 KiB
C++

// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s
// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 %s
struct S1 { // expected-note 2 {{declared here}}
int a;
};
template <class T>
T tmain(T argc) {
#pragma omp flush
;
#pragma omp flush untied // expected-error {{unexpected OpenMP clause 'untied' in directive '#pragma omp flush'}}
#pragma omp flush unknown // expected-warning {{extra tokens at the end of '#pragma omp flush' are ignored}}
if (argc)
#pragma omp flush // expected-error {{'#pragma omp flush' cannot be an immediate substatement}}
if (argc) {
#pragma omp flush
}
while (argc)
#pragma omp flush // expected-error {{'#pragma omp flush' cannot be an immediate substatement}}
while (argc) {
#pragma omp flush
}
do
#pragma omp flush // expected-error {{'#pragma omp flush' cannot be an immediate substatement}}
while (argc)
;
do {
#pragma omp flush
} while (argc);
switch (argc)
#pragma omp flush // expected-error {{'#pragma omp flush' cannot be an immediate substatement}}
switch (argc)
case 1:
#pragma omp flush // expected-error {{'#pragma omp flush' cannot be an immediate substatement}}
switch (argc)
case 1: {
#pragma omp flush
}
switch (argc) {
#pragma omp flush
case 1:
#pragma omp flush
break;
default: {
#pragma omp flush
} break;
}
for (;;)
#pragma omp flush // expected-error {{'#pragma omp flush' cannot be an immediate substatement}}
for (;;) {
#pragma omp flush
}
label:
#pragma omp flush
label1 : {
#pragma omp flush
}
#pragma omp flush
#pragma omp flush( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
#pragma omp flush() // expected-error {{expected expression}}
#pragma omp flush(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
#pragma omp flush(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
#pragma omp flush(argc)
#pragma omp flush(S1) // expected-error {{'S1' does not refer to a value}}
#pragma omp flush(argc) flush(argc) // expected-warning {{extra tokens at the end of '#pragma omp flush' are ignored}}
#pragma omp parallel flush(argc) // expected-warning {{extra tokens at the end of '#pragma omp parallel' are ignored}}
;
return T();
}
int main(int argc, char **argv) {
#pragma omp flush
;
#pragma omp flush untied // expected-error {{unexpected OpenMP clause 'untied' in directive '#pragma omp flush'}}
#pragma omp flush unknown // expected-warning {{extra tokens at the end of '#pragma omp flush' are ignored}}
if (argc)
#pragma omp flush // expected-error {{'#pragma omp flush' cannot be an immediate substatement}}
if (argc) {
#pragma omp flush
}
while (argc)
#pragma omp flush // expected-error {{'#pragma omp flush' cannot be an immediate substatement}}
while (argc) {
#pragma omp flush
}
do
#pragma omp flush // expected-error {{'#pragma omp flush' cannot be an immediate substatement}}
while (argc)
;
do {
#pragma omp flush
} while (argc);
switch (argc)
#pragma omp flush // expected-error {{'#pragma omp flush' cannot be an immediate substatement}}
switch (argc)
case 1:
#pragma omp flush // expected-error {{'#pragma omp flush' cannot be an immediate substatement}}
switch (argc)
case 1: {
#pragma omp flush
}
switch (argc) {
#pragma omp flush
case 1:
#pragma omp flush
break;
default: {
#pragma omp flush
} break;
}
for (;;)
#pragma omp flush // expected-error {{'#pragma omp flush' cannot be an immediate substatement}}
for (;;) {
#pragma omp flush
}
label:
#pragma omp flush
label1 : {
#pragma omp flush
}
#pragma omp flush
#pragma omp flush( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
#pragma omp flush() // expected-error {{expected expression}}
#pragma omp flush(argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
#pragma omp flush(argc, // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
#pragma omp flush(argc)
#pragma omp flush(S1) // expected-error {{'S1' does not refer to a value}}
#pragma omp flush(argc) flush(argc) // expected-warning {{extra tokens at the end of '#pragma omp flush' are ignored}}
#pragma omp parallel flush(argc) // expected-warning {{extra tokens at the end of '#pragma omp parallel' are ignored}}
;
return tmain(argc);
}