[PATCH] D39859: [OpenMP] diagnose assign to firstprivate const

Alexey Bataev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 10 07:40:07 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL317891: [OpenMP] diagnose assign to firstprivate const, patch by Joel E. Denny (authored by ABataev).

Changed prior to commit:
  https://reviews.llvm.org/D39859?vs=122329&id=122434#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39859

Files:
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/test/OpenMP/parallel_firstprivate_messages.cpp


Index: cfe/trunk/test/OpenMP/parallel_firstprivate_messages.cpp
===================================================================
--- cfe/trunk/test/OpenMP/parallel_firstprivate_messages.cpp
+++ cfe/trunk/test/OpenMP/parallel_firstprivate_messages.cpp
@@ -56,7 +56,7 @@
 }
 
 int main(int argc, char **argv) {
-  const int d = 5;
+  const int d = 5; // expected-note {{variable 'd' declared const here}}
   const int da[5] = { 0 };
   S4 e(4);
   S5 g(5);
@@ -72,6 +72,8 @@
   #pragma omp parallel firstprivate (argc)
   #pragma omp parallel firstprivate (S1) // expected-error {{'S1' does not refer to a value}}
   #pragma omp parallel firstprivate (a, b, c, d, f) // expected-error {{firstprivate variable with incomplete type 'S1'}}
+  #pragma omp parallel firstprivate (d)
+    d = 5; // expected-error {{cannot assign to variable 'd' with const-qualified type}}
   #pragma omp parallel firstprivate (argv[1]) // expected-error {{expected variable name}}
   #pragma omp parallel firstprivate(ba)
   #pragma omp parallel firstprivate(ca)
Index: cfe/trunk/lib/Sema/SemaExpr.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp
+++ cfe/trunk/lib/Sema/SemaExpr.cpp
@@ -14352,8 +14352,13 @@
   bool ByRef = true;
   // Using an LValue reference type is consistent with Lambdas (see below).
   if (S.getLangOpts().OpenMP && RSI->CapRegionKind == CR_OpenMP) {
-    if (S.IsOpenMPCapturedDecl(Var))
+    if (S.IsOpenMPCapturedDecl(Var)) {
+      bool HasConst = DeclRefType.isConstQualified();
       DeclRefType = DeclRefType.getUnqualifiedType();
+      // Don't lose diagnostics about assignments to const.
+      if (HasConst)
+        DeclRefType.addConst();
+    }
     ByRef = S.IsOpenMPCapturedByRef(Var, RSI->OpenMPLevel);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39859.122434.patch
Type: text/x-patch
Size: 1792 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171110/655da764/attachment.bin>


More information about the cfe-commits mailing list