h-joo created this revision. h-joo added a reviewer: ABataev. h-joo added projects: clang, OpenMP. Herald added subscribers: cfe-commits, arphaman, guansong, yaxunl. Herald added a reviewer: jdoerfert.
This is a fix for Bug 45383 <https://bugs.llvm.org/show_bug.cgi?id=45383>. This revision fixes the error reported for array subscription for the cases where the array index is a template parameter. Note that the `ArraySubscriptExpr::getBase()` might return something which might not be a base in the cases where either LHS or RHS of the `ArraySubscriptExpr` is a template declaration - I think the fundemental fix would include more changes with `ArraySubscriptExpr::getBase()` in the presence of template dependent types, but I thought it would involve a bigger scope of refactoring since many of the code is touching it. Please also keep in mind this is my first patch, so I would be very glad for any kind of comment if I did something wrong. Repository: rG LLVM Github Monorepo 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,22 @@ +// 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]) // expected-no-diagnostics + { + ; + } +} + +int driver(double *A) +{ + int k = 0; + test(A, k); + 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,22 @@ +// 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]) // expected-no-diagnostics + { + ; + } +} + +int driver(double *A) +{ + int k = 0; + test(A, k); + 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