[OPENMP] Fixed codegen for parameters privatization.

For parameters we shall take a derived type of parameters, not the original one.

llvm-svn: 237882
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index c7d0c14..ee6bdb2 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -505,9 +505,6 @@
   }
 
   QualType Type = D->getType().getNonReferenceType().getCanonicalType();
-  if (auto *PVD = dyn_cast<ParmVarDecl>(D)) {
-    Type = PVD->getOriginalType().getNonReferenceType().getCanonicalType();
-  }
   bool IsConstant = Type.isConstant(SemaRef.getASTContext());
   Type = SemaRef.getASTContext().getBaseElementType(Type);
   // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
@@ -664,9 +661,6 @@
           }
           auto *VD = cast<VarDecl>(cast<DeclRefExpr>(DE)->getDecl());
           QualType Type = VD->getType();
-          if (auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
-            Type = PVD->getOriginalType();
-          }
           auto DVar = DSAStack->getTopDSA(VD, false);
           if (DVar.CKind == OMPC_lastprivate) {
             // Generate helper private variable and initialize it with the
@@ -4761,9 +4755,6 @@
     VarDecl *VD = cast<VarDecl>(D);
 
     QualType Type = VD->getType();
-    if (auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
-      Type = PVD->getOriginalType();
-    }
     if (Type->isDependentType() || Type->isInstantiationDependentType()) {
       // It will be analyzed later.
       Vars.push_back(DE);
@@ -4805,7 +4796,7 @@
     }
 
     // Variably modified types are not supported for tasks.
-    if (Type->isVariablyModifiedType() &&
+    if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() &&
         DSAStack->getCurrentDirective() == OMPD_task) {
       Diag(ELoc, diag::err_omp_variably_modified_type_not_supported)
           << getOpenMPClauseName(OMPC_private) << Type
@@ -4907,9 +4898,6 @@
     VarDecl *VD = cast<VarDecl>(D);
 
     QualType Type = VD->getType();
-    if (auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
-      Type = PVD->getOriginalType();
-    }
     if (Type->isDependentType() || Type->isInstantiationDependentType()) {
       // It will be analyzed later.
       Vars.push_back(DE);
@@ -5036,7 +5024,7 @@
     }
 
     // Variably modified types are not supported for tasks.
-    if (Type->isVariablyModifiedType() &&
+    if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() &&
         DSAStack->getCurrentDirective() == OMPD_task) {
       Diag(ELoc, diag::err_omp_variably_modified_type_not_supported)
           << getOpenMPClauseName(OMPC_firstprivate) << Type
@@ -5143,9 +5131,6 @@
     VarDecl *VD = cast<VarDecl>(D);
 
     QualType Type = VD->getType();
-    if (auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
-      Type = PVD->getOriginalType();
-    }
     if (Type->isDependentType() || Type->isInstantiationDependentType()) {
       // It will be analyzed later.
       Vars.push_back(DE);
@@ -5280,9 +5265,6 @@
     VarDecl *VD = cast<VarDecl>(D);
 
     QualType Type = VD->getType();
-    if (auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
-      Type = PVD->getOriginalType();
-    }
     if (Type->isDependentType() || Type->isInstantiationDependentType()) {
       // It will be analyzed later.
       Vars.push_back(DE);
@@ -5492,9 +5474,6 @@
     auto D = DE->getDecl();
     auto VD = cast<VarDecl>(D);
     auto Type = VD->getType();
-    if (auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
-      Type = PVD->getOriginalType();
-    }
     // OpenMP [2.9.3.3, Restrictions, C/C++, p.3]
     //  A variable that appears in a private clause must not have an incomplete
     //  type or a reference type.
@@ -5825,9 +5804,6 @@
     }
 
     QualType QType = VD->getType();
-    if (auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
-      QType = PVD->getOriginalType();
-    }
     if (QType->isDependentType() || QType->isInstantiationDependentType()) {
       // It will be analyzed later.
       Vars.push_back(DE);
@@ -6008,9 +5984,6 @@
     // The type of list items appearing in the aligned clause must be
     // array, pointer, reference to array, or reference to pointer.
     QualType QType = VD->getType();
-    if (auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
-      QType = PVD->getOriginalType();
-    }
     QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType();
     const Type *Ty = QType.getTypePtrOrNull();
     if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() &&
@@ -6090,9 +6063,6 @@
     VarDecl *VD = cast<VarDecl>(D);
 
     QualType Type = VD->getType();
-    if (auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
-      Type = PVD->getOriginalType();
-    }
     if (Type->isDependentType() || Type->isInstantiationDependentType()) {
       // It will be analyzed later.
       Vars.push_back(DE);
@@ -6183,9 +6153,6 @@
     VarDecl *VD = cast<VarDecl>(D);
 
     QualType Type = VD->getType();
-    if (auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
-      Type = PVD->getOriginalType();
-    }
     if (Type->isDependentType() || Type->isInstantiationDependentType()) {
       // It will be analyzed later.
       Vars.push_back(DE);
@@ -6225,7 +6192,7 @@
     }
 
     // Variably modified types are not supported.
-    if (Type->isVariablyModifiedType()) {
+    if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) {
       Diag(ELoc, diag::err_omp_variably_modified_type_not_supported)
           << getOpenMPClauseName(OMPC_copyprivate) << Type
           << getOpenMPDirectiveName(DSAStack->getCurrentDirective());