Stop emit incomplete type error for a variable in a map clause

where should not.

Currently we are using QTy->isIncompleteType(&ND) to check incomplete
type.  But before doing that, need to instantiate for a class template
specialization or a class member of a class template specialization,
or an array with known size of such..., so that we know it is really
incomplete type.

To fix this using RequireCompleteType instead.

The new test is added into "test/OpenMP/target_update_messages.cpp"

The different of using RequireCompleteType is when emit incomplete type,
an additional note is also emitted to point to where incomplete type
is declared.  Because this change, many tests are needed to be fixed
by adding additional note.

This is to fix https://bugs.llvm.org/show_bug.cgi?id=50508

Differential Revision: https://reviews.llvm.org/D107200
This commit is contained in:
Jennifer Yu 2021-08-03 10:35:04 -07:00
parent 033ca45d4f
commit 656d022331
53 changed files with 76 additions and 56 deletions

View File

@ -18443,11 +18443,8 @@ OMPClause *Sema::ActOnOpenMPDeviceClause(OpenMPDeviceClauseModifier Modifier,
static bool checkTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef,
DSAStackTy *Stack, QualType QTy,
bool FullCheck = true) {
NamedDecl *ND;
if (QTy->isIncompleteType(&ND)) {
SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR;
if (SemaRef.RequireCompleteType(SL, QTy, diag::err_incomplete_type))
return false;
}
if (FullCheck && !SemaRef.CurContext->isDependentContext() &&
!QTy.isTriviallyCopyableType(SemaRef.Context))
SemaRef.Diag(SL, diag::warn_omp_non_trivial_type_mapped) << QTy << SR;

View File

@ -9,7 +9,7 @@ bool foobool(int argc) {
return argc;
}
struct S1; // expected-note {{declared here}} expected-note{{forward declaration of 'S1'}}
struct S1; // expected-note {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -18,7 +18,7 @@ void xxx(int argc) {
extern int omp_default_mem_alloc;
struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
struct S1; // expected-note 2 {{declared here}} expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -11,7 +11,7 @@ bool foobool(int argc) {
return argc;
}
extern int omp_default_mem_alloc;
struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
struct S1; // expected-note 2 {{declared here}} expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -36,7 +36,7 @@ void foobar(int &ref) {
foo();
}
struct S1; // expected-note {{declared here}} expected-note 4 {{forward declaration of 'S1'}}
struct S1; // expected-note {{declared here}} expected-note 6 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -3,7 +3,7 @@
// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 %s -Wno-openmp-mapping -Wuninitialized
struct S1; // expected-note 2 {{declared here}}
struct S1; // expected-note 2 {{declared here}} // expected-note 2 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -102,7 +102,7 @@ template<int LEN> int test_warn() {
return 0;
}
struct S1; // expected-note 2 {{declared here}}
struct S1; // expected-note 2 {{declared here}} // expected-note {{forward declaration of 'S1'}}
extern S1 a; // expected-note {{'a' declared here}}
class S2 {
mutable int a;

View File

@ -17,7 +17,7 @@ void xxx(int argc) {
;
}
struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
struct S1; // expected-note 2 {{declared here}} expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -12,7 +12,7 @@ bool foobool(int argc) {
return argc;
}
struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
struct S1; // expected-note 2 {{declared here}} expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -116,7 +116,7 @@ template<int LEN> int test_warn() {
return ind2;
}
struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
struct S1; // expected-note 2 {{declared here}} expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -35,7 +35,7 @@ void foobar(int &ref) {
foo();
}
struct S1; // expected-note {{declared here}} expected-note 4 {{forward declaration of 'S1'}}
struct S1; // expected-note {{declared here}} expected-note 6 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -3,7 +3,7 @@
// RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 %s -Wuninitialized
struct S1; // expected-note 2 {{declared here}}
struct S1; // expected-note 2 {{declared here}} // expected-note 2 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -102,7 +102,7 @@ template<int LEN> int test_warn() {
return 0;
}
struct S1; // expected-note 2 {{declared here}}
struct S1; // expected-note 2 {{declared here}} // expected-note {{forward declaration of 'S1'}}
extern S1 a; // expected-note {{'a' declared here}}
class S2 {
mutable int a;

View File

@ -10,7 +10,7 @@ bool foobool(int argc) {
return argc;
}
struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
struct S1; // expected-note 2 {{declared here}} expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -12,7 +12,7 @@ bool foobool(int argc) {
return argc;
}
struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
struct S1; // expected-note 2 {{declared here}} expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -116,7 +116,7 @@ template<int LEN> int test_warn() {
return ind2;
}
struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
struct S1; // expected-note 2 {{declared here}} expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -35,7 +35,7 @@ void foobar(int &ref) {
foo();
}
struct S1; // expected-note {{declared here}} expected-note 4 {{forward declaration of 'S1'}}
struct S1; // expected-note {{declared here}} expected-note 6 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -448,7 +448,7 @@ bool foobool(int argc) {
return argc;
}
struct S1; // expected-note 2 {{declared here}}
struct S1; // expected-note 2 {{declared here}} // expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -20,7 +20,7 @@ void xxx(int argc) {
;
}
struct S1; // expected-note 2 {{declared here}}
struct S1; // expected-note 2 {{declared here}} // expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -20,7 +20,7 @@ void xxx(int argc) {
;
}
struct S1; // expected-note 2 {{declared here}}
struct S1; // expected-note 2 {{declared here}} // expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -20,7 +20,7 @@ void xxx(int argc) {
;
}
struct S1; // expected-note 2 {{declared here}}
struct S1; // expected-note 2 {{declared here}} // expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -20,7 +20,7 @@ void xxx(int argc) {
;
}
struct S1; // expected-note 2 {{declared here}}
struct S1; // expected-note 2 {{declared here}} // expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -20,7 +20,7 @@ void xxx(int argc) {
;
}
struct S1; // expected-note 2 {{declared here}}
struct S1; // expected-note 2 {{declared here}} // expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -18,7 +18,7 @@ void xxx(int argc) {
;
}
struct S1; // expected-note 2 {{declared here}}
struct S1; // expected-note 2 {{declared here}} // expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -20,7 +20,7 @@ void xxx(int argc) {
;
}
struct S1; // expected-note 2 {{declared here}}
struct S1; // expected-note 2 {{declared here}} // expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -20,7 +20,7 @@ void xxx(int argc) {
;
}
struct S1; // expected-note 2 {{declared here}}
struct S1; // expected-note 2 {{declared here}} // expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -335,7 +335,7 @@ bool foobool(int argc) {
return argc;
}
struct S1; // expected-note 2 {{declared here}}
struct S1; // expected-note 2 {{declared here}} // expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -12,7 +12,7 @@ bool foobool(int argc) {
return argc;
}
struct S1; // expected-note 2 {{declared here}}
struct S1; // expected-note 2 {{declared here}} // expected-note 2 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -185,3 +185,27 @@ int main(int argc, char **argv) {
return tmain(argc, argv);
}
template<typename _Tp, int _Nm> struct array {
_Tp & operator[](int __n) noexcept;
};
#pragma omp declare target
extern array<double, 4> arr;
#pragma omp end declare target
void copy_host_to_device()
{
#pragma omp target update from(arr) // expected-no-error
arr[0] = 0;
}
struct FOO; // expected-note {{forward declaration of 'FOO'}}
extern FOO a;
template <typename T, int I>
struct bar {
void func() {
#pragma omp target map(to: a) // expected-error {{incomplete type 'FOO' where a complete type is required}}
foo();
}
};

View File

@ -15,7 +15,7 @@ bool foobool(int argc) {
return argc;
}
struct S1; // expected-note 2 {{declared here}}
struct S1; // expected-note 2 {{declared here}} // expected-note 2 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -18,7 +18,7 @@ void xxx(int argc) {
;
}
struct S1; // expected-note {{declared here}} expected-note{{forward declaration of 'S1'}}
struct S1; // expected-note {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -12,7 +12,7 @@ bool foobool(int argc) {
return argc;
}
struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
struct S1; // expected-note 2 {{declared here}} expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -18,7 +18,7 @@ void xxx(int argc) {
;
}
struct S1; // expected-note {{declared here}} expected-note{{forward declaration of 'S1'}}
struct S1; // expected-note {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -12,7 +12,7 @@ bool foobool(int argc) {
return argc;
}
struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
struct S1; // expected-note 2 {{declared here}} expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -28,7 +28,7 @@ bool foobool(int argc) {
return argc;
}
struct S1; // expected-note {{declared here}} expected-note 4 {{forward declaration of 'S1'}}
struct S1; // expected-note {{declared here}} expected-note 6 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -9,7 +9,7 @@ bool foobool(int argc) {
return argc;
}
struct S1; // expected-note {{declared here}}
struct S1; // expected-note {{declared here}} // expected-note {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -91,7 +91,7 @@ template<int LEN> int test_warn() {
return 0;
}
struct S1; // expected-note 2 {{declared here}}
struct S1; // expected-note 2 {{declared here}} // expected-note {{forward declaration of 'S1'}}
extern S1 a; // expected-note {{'a' declared here}}
class S2 {
mutable int a;

View File

@ -19,7 +19,7 @@ void xxx(int argc) {
;
}
struct S1; // expected-note {{declared here}} expected-note{{forward declaration of 'S1'}}
struct S1; // expected-note {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -12,7 +12,7 @@ bool foobool(int argc) {
return argc;
}
struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
struct S1; // expected-note 2 {{declared here}} expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -105,7 +105,7 @@ template<int LEN> int test_warn() {
return ind2;
}
struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
struct S1; // expected-note 2 {{declared here}} expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -28,7 +28,7 @@ bool foobool(int argc) {
return argc;
}
struct S1; // expected-note {{declared here}} expected-note 4 {{forward declaration of 'S1'}}
struct S1; // expected-note {{declared here}} expected-note 6 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -9,7 +9,7 @@ bool foobool(int argc) {
return argc;
}
struct S1; // expected-note {{declared here}}
struct S1; // expected-note {{declared here}} expected-note {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -34,7 +34,7 @@ void foobar(int &ref) {
for (int j=0; j<100; j++) foo();
}
struct S1; // expected-note {{declared here}} expected-note 4 {{forward declaration of 'S1'}}
struct S1; // expected-note {{declared here}} expected-note 6 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -9,7 +9,7 @@ bool foobool(int argc) {
return argc;
}
struct S1; // expected-note {{declared here}}
struct S1; // expected-note {{declared here}} // expected-note {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -91,7 +91,7 @@ template<int LEN> int test_warn() {
return 0;
}
struct S1; // expected-note 2 {{declared here}}
struct S1; // expected-note 2 {{declared here}} // expected-note {{forward declaration of 'S1'}}
extern S1 a; // expected-note {{'a' declared here}}
class S2 {
mutable int a;

View File

@ -20,7 +20,7 @@ void xxx(int argc) {
;
}
struct S1; // expected-note {{declared here}} expected-note{{forward declaration of 'S1'}}
struct S1; // expected-note {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -12,7 +12,7 @@ bool foobool(int argc) {
return argc;
}
struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
struct S1; // expected-note 2 {{declared here}} expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -105,7 +105,7 @@ template<int LEN> int test_warn() {
return ind2;
}
struct S1; // expected-note 2 {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
struct S1; // expected-note 2 {{declared here}} expected-note 3 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -28,7 +28,7 @@ bool foobool(int argc) {
return argc;
}
struct S1; // expected-note {{declared here}} expected-note 4 {{forward declaration of 'S1'}}
struct S1; // expected-note {{declared here}} expected-note 6 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -9,7 +9,7 @@ bool foobool(int argc) {
return argc;
}
struct S1; // expected-note {{declared here}}
struct S1; // expected-note {{declared here}} // expected-note {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -18,7 +18,7 @@ void xxx(int argc) {
;
}
struct S1; // expected-note {{declared here}} expected-note{{forward declaration of 'S1'}}
struct S1; // expected-note {{declared here}} expected-note 2 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -34,7 +34,7 @@ void foobar(int &ref) {
foo();
}
struct S1; // expected-note {{declared here}} expected-note 4 {{forward declaration of 'S1'}}
struct S1; // expected-note {{declared here}} expected-note 6 {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;

View File

@ -8,8 +8,7 @@ void foo() {
bool foobool(int argc) {
return argc;
}
struct S1; // expected-note {{declared here}}
struct S1; // expected-note {{declared here}} // expected-note {{forward declaration of 'S1'}}
extern S1 a;
class S2 {
mutable int a;