From 18ad179208246dd1c80545125f86c2ae3f93e340 Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Thu, 16 Jul 2015 04:19:43 +0000 Subject: [PATCH] [OPENMP] Fixed detection of canonical loops with random access iterators. Add handling of iterators with copy/move constructors with default arguments + converting template constructors. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242382 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaOpenMP.cpp | 10 ++++++---- test/OpenMP/for_codegen.cpp | 5 +++-- test/OpenMP/for_loop_messages.cpp | 2 +- test/OpenMP/for_simd_loop_messages.cpp | 2 +- test/OpenMP/parallel_for_loop_messages.cpp | 2 +- test/OpenMP/parallel_for_simd_loop_messages.cpp | 2 +- test/OpenMP/simd_loop_messages.cpp | 2 +- 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index 239ede5bb6..e11ab82f88 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -2290,8 +2290,9 @@ bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, VarRef = NewVarRefExpr; if (auto *CE = dyn_cast_or_null(NewLB)) if (const CXXConstructorDecl *Ctor = CE->getConstructor()) - if (Ctor->isCopyConstructor() && CE->getNumArgs() == 1 && - CE->getArg(0) != nullptr) + if ((Ctor->isCopyOrMoveConstructor() || + Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && + CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) NewLB = CE->getArg(0)->IgnoreParenImpCasts(); LB = NewLB; return false; @@ -2426,8 +2427,9 @@ static const VarDecl *GetInitVarDecl(const Expr *E) { E = getExprAsWritten(E); if (auto *CE = dyn_cast_or_null(E)) if (const CXXConstructorDecl *Ctor = CE->getConstructor()) - if (Ctor->isCopyConstructor() && CE->getNumArgs() == 1 && - CE->getArg(0) != nullptr) + if ((Ctor->isCopyOrMoveConstructor() || + Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && + CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) E = CE->getArg(0)->IgnoreParenImpCasts(); auto DRE = dyn_cast_or_null(E); if (!DRE) diff --git a/test/OpenMP/for_codegen.cpp b/test/OpenMP/for_codegen.cpp index 539fb7bf02..7f7e9ba9d2 100644 --- a/test/OpenMP/for_codegen.cpp +++ b/test/OpenMP/for_codegen.cpp @@ -420,8 +420,9 @@ struct Bool { template struct It { It() : p(0) {} - It(const It &) ; - It(It &) ; + It(const It &, int = 0) ; + template + It(U &, int = 0) ; It &operator=(const It &); It &operator=(It &); ~It() {} diff --git a/test/OpenMP/for_loop_messages.cpp b/test/OpenMP/for_loop_messages.cpp index f425defdf3..ba27934b11 100644 --- a/test/OpenMP/for_loop_messages.cpp +++ b/test/OpenMP/for_loop_messages.cpp @@ -562,7 +562,7 @@ int test_with_random_access_iterator() { for (Iter1 I = begin1; I >= end1; ++I) ++I; #pragma omp parallel -// expected-error@+5 {{invalid operands to binary expression ('Iter1' and 'Iter1')}} +// expected-error@+5 {{invalid operands to binary expression ('Iter1' and 'float')}} // expected-error@+4 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}} // Initializer is constructor with all default params. // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} diff --git a/test/OpenMP/for_simd_loop_messages.cpp b/test/OpenMP/for_simd_loop_messages.cpp index 6e68eb8a08..99b8339840 100644 --- a/test/OpenMP/for_simd_loop_messages.cpp +++ b/test/OpenMP/for_simd_loop_messages.cpp @@ -544,7 +544,7 @@ int test_with_random_access_iterator() { for (Iter1 I = begin1; I >= end1; ++I) ++I; #pragma omp parallel -// expected-error@+5 {{invalid operands to binary expression ('Iter1' and 'Iter1')}} +// expected-error@+5 {{invalid operands to binary expression ('Iter1' and 'float')}} // expected-error@+4 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}} // Initializer is constructor with all default params. // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} diff --git a/test/OpenMP/parallel_for_loop_messages.cpp b/test/OpenMP/parallel_for_loop_messages.cpp index 09a15e2dc3..8c0cdf8e9e 100644 --- a/test/OpenMP/parallel_for_loop_messages.cpp +++ b/test/OpenMP/parallel_for_loop_messages.cpp @@ -467,7 +467,7 @@ int test_with_random_access_iterator() { #pragma omp parallel for for (Iter1 I = begin1; I >= end1; ++I) ++I; -// expected-error@+5 {{invalid operands to binary expression ('Iter1' and 'Iter1')}} +// expected-error@+5 {{invalid operands to binary expression ('Iter1' and 'float')}} // expected-error@+4 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}} // Initializer is constructor with all default params. // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} diff --git a/test/OpenMP/parallel_for_simd_loop_messages.cpp b/test/OpenMP/parallel_for_simd_loop_messages.cpp index 0473b248a6..94bd37c596 100644 --- a/test/OpenMP/parallel_for_simd_loop_messages.cpp +++ b/test/OpenMP/parallel_for_simd_loop_messages.cpp @@ -467,7 +467,7 @@ int test_with_random_access_iterator() { #pragma omp parallel for simd for (Iter1 I = begin1; I >= end1; ++I) ++I; -// expected-error@+5 {{invalid operands to binary expression ('Iter1' and 'Iter1')}} +// expected-error@+5 {{invalid operands to binary expression ('Iter1' and 'float')}} // expected-error@+4 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}} // Initializer is constructor with all default params. // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} diff --git a/test/OpenMP/simd_loop_messages.cpp b/test/OpenMP/simd_loop_messages.cpp index fe8e70a9b8..bd7dd5bf52 100644 --- a/test/OpenMP/simd_loop_messages.cpp +++ b/test/OpenMP/simd_loop_messages.cpp @@ -456,7 +456,7 @@ int test_with_random_access_iterator() { ++I; // Initializer is constructor with all default params. - // expected-error@+4 {{invalid operands to binary expression ('Iter1' and 'Iter1')}} + // expected-error@+4 {{invalid operands to binary expression ('Iter1' and 'float')}} // expected-error@+3 {{could not calculate number of iterations calling 'operator-' with upper and lower loop bounds}} // expected-warning@+2 {{initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')}} #pragma omp simd -- 2.40.0