[OPENMP] Codegen for declare target with link clause.

If the link clause is used on the declare target directive, the object
should be linked on target or target data directives, not during the
codegen. Patch adds support for this clause.

llvm-svn: 328544
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 619af9a..1c3495a 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -9494,10 +9494,13 @@
           return true;
 
   // If the decl is marked as `declare target`, it should be emitted.
-  for (const auto *Decl = D->getMostRecentDecl(); Decl;
-       Decl = Decl->getPreviousDecl())
-    if (Decl->hasAttr<OMPDeclareTargetDeclAttr>())
-      return true;
+  for (const auto *Decl : D->redecls()) {
+    if (!Decl->hasAttrs())
+      continue;
+    if (const auto *Attr = Decl->getAttr<OMPDeclareTargetDeclAttr>())
+      if (Attr->getMapType() != OMPDeclareTargetDeclAttr::MT_Link)
+        return true;
+  }
 
   return false;
 }