[PATCH] D78643: [OpenMP] Fix false error report of array subscription for templated indexes.
Hana Joo via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 22 11:58:21 PDT 2020
h-joo updated this revision to Diff 259343.
h-joo added a comment.
In D78643#1997405 <https://reviews.llvm.org/D78643#1997405>, @ABataev wrote:
> In D78643#1997344 <https://reviews.llvm.org/D78643#1997344>, @jdoerfert wrote:
>
> > This looks reasonable to me. @ABataev WDYT?
>
>
> I would add a positive test with -ast-print
1. Changed into a positive test with -ast-print
2. Just `QualType BaseType = ASE->getBase()->getType().getNonReferenceType();` and dropped all the call for getNonReferenceType() in later checks.
Thank you for your time for the review! I do have one more question to ask. I don't understand the log of the build failure, would you be able to give me a bit of a hint?
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,49 @@
+// RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s
+
+#ifndef HEADER
+#define HEADER
+
+template<typename IndexT>
+void test(double *A, IndexT k)
+{
+ #pragma omp task depend(out: A[k])
+ {
+ ;
+ }
+}
+// CHECK: template <typename IndexT> void test(double *A, IndexT k) {
+// CHECK: #pragma omp task depend(out : A[k])
+// CHECK: {
+// CHECK: ;
+// CHECK: }
+// CHECK: }
+// CHECK: template<> void test<int>(double *A, int k) {
+// CHECK: #pragma omp task depend(out : A[k])
+// CHECK: {
+// CHECK: ;
+// CHECK: }
+// CHECK: }
+
+
+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,24 @@
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().getNonReferenceType();
+ if (!BaseType->isDependentType() && !BaseType->isPointerType() &&
+ !BaseType->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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78643.259343.patch
Type: text/x-patch
Size: 2937 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200422/ea85f3a0/attachment-0001.bin>
More information about the cfe-commits
mailing list