h-joo updated this revision to Diff 259326. h-joo added a comment. In D78643#1997103 <https://reviews.llvm.org/D78643#1997103>, @jdoerfert wrote:
> Can we create a test case that shows even if it is a dependent type we will > eventuall issue an error if it is not an addressable lvalue or array item? > If this is the part that needs refactoring to work, we should add the test > with a TODO. Added a test to check the test triggers in presence of lvalue expression. Although the test does not trigger line 15912, but rather line 15905. I tried some examples and it seems like after during the template instantiation, while an ArraySubscriptExpr is being constructed, it already checks whether it's a pointer type or an array type, thus, I am thinking this check in line 15912 might actually be redundant? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D78643/new/ https://reviews.llvm.org/D78643 Files: clang/lib/Sema/SemaOpenMP.cpp clang/test/OpenMP/depend_template_subscription.cpp Index: clang/test/OpenMP/depend_template_subscription.cpp =================================================================== --- /dev/null +++ clang/test/OpenMP/depend_template_subscription.cpp @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -verify -fopenmp -std=c++11 %s -Wuninitialized + +#ifndef HEADER +#define HEADER + +template<typename IndexT> +void test(double *A, IndexT k) +{ + + #pragma omp task depend(out: A[k]) // Should not print error Bug #45383 + { + ; + } +} + +struct lValueVector { + int operator [] (int index) { + return index + 42; + } +}; +template<typename BaseTypeT, typename IndexT> +void test2(BaseTypeT A, IndexT k) +{ + #pragma omp task depend(out: A[k]) // expected-error {{expected addressable lvalue expression, array element or array section}} + { + ; + } +} +int driver(double *A) +{ + int k = 42; + test(A, k); + test2(lValueVector(), k); // expected-note {{in instantiation of function template specialization 'test2<lValueVector, int>' requested here}} + return 0; +} + +#endif \ No newline at end of file Index: clang/lib/Sema/SemaOpenMP.cpp =================================================================== --- clang/lib/Sema/SemaOpenMP.cpp +++ clang/lib/Sema/SemaOpenMP.cpp @@ -15902,20 +15902,25 @@ continue; } - auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); - if (!RefExpr->IgnoreParenImpCasts()->isLValue() || - (ASE && - !ASE->getBase() - ->getType() - .getNonReferenceType() - ->isPointerType() && - !ASE->getBase()->getType().getNonReferenceType()->isArrayType())) { + if (!RefExpr->IgnoreParenImpCasts()->isLValue()) { Diag(ELoc, diag::err_omp_expected_addressable_lvalue_or_array_item) << (LangOpts.OpenMP >= 50 ? 1 : 0) << (LangOpts.OpenMP >= 50 ? 1 : 0) << RefExpr->getSourceRange(); continue; } + if (auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr)) { + QualType BaseType = ASE->getBase()->getType(); + if (!BaseType->isDependentType() && + !BaseType.getNonReferenceType()->isPointerType() && + !BaseType.getNonReferenceType()->isArrayType()) { + Diag(ELoc, diag::err_omp_expected_addressable_lvalue_or_array_item) + << (LangOpts.OpenMP >= 50 ? 1 : 0) + << (LangOpts.OpenMP >= 50 ? 1 : 0) << RefExpr->getSourceRange(); + continue; + } + } + ExprResult Res; { Sema::TentativeAnalysisScope Trap(*this);
Index: clang/test/OpenMP/depend_template_subscription.cpp =================================================================== --- /dev/null +++ clang/test/OpenMP/depend_template_subscription.cpp @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -verify -fopenmp -std=c++11 %s -Wuninitialized + +#ifndef HEADER +#define HEADER + +template<typename IndexT> +void test(double *A, IndexT k) +{ + + #pragma omp task depend(out: A[k]) // Should not print error Bug #45383 + { + ; + } +} + +struct lValueVector { + int operator [] (int index) { + return index + 42; + } +}; +template<typename BaseTypeT, typename IndexT> +void test2(BaseTypeT A, IndexT k) +{ + #pragma omp task depend(out: A[k]) // expected-error {{expected addressable lvalue expression, array element or array section}} + { + ; + } +} +int driver(double *A) +{ + int k = 42; + test(A, k); + test2(lValueVector(), k); // expected-note {{in instantiation of function template specialization 'test2<lValueVector, int>' requested here}} + return 0; +} + +#endif \ No newline at end of file Index: clang/lib/Sema/SemaOpenMP.cpp =================================================================== --- clang/lib/Sema/SemaOpenMP.cpp +++ clang/lib/Sema/SemaOpenMP.cpp @@ -15902,20 +15902,25 @@ continue; } - auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); - if (!RefExpr->IgnoreParenImpCasts()->isLValue() || - (ASE && - !ASE->getBase() - ->getType() - .getNonReferenceType() - ->isPointerType() && - !ASE->getBase()->getType().getNonReferenceType()->isArrayType())) { + if (!RefExpr->IgnoreParenImpCasts()->isLValue()) { Diag(ELoc, diag::err_omp_expected_addressable_lvalue_or_array_item) << (LangOpts.OpenMP >= 50 ? 1 : 0) << (LangOpts.OpenMP >= 50 ? 1 : 0) << RefExpr->getSourceRange(); continue; } + if (auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr)) { + QualType BaseType = ASE->getBase()->getType(); + if (!BaseType->isDependentType() && + !BaseType.getNonReferenceType()->isPointerType() && + !BaseType.getNonReferenceType()->isArrayType()) { + Diag(ELoc, diag::err_omp_expected_addressable_lvalue_or_array_item) + << (LangOpts.OpenMP >= 50 ? 1 : 0) + << (LangOpts.OpenMP >= 50 ? 1 : 0) << RefExpr->getSourceRange(); + continue; + } + } + ExprResult Res; { Sema::TentativeAnalysisScope Trap(*this);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits