From 2a187521f3c7bde806f322da3acf905afb2b82a8 Mon Sep 17 00:00:00 2001
From: Richard Smith <richard-llvm@metafoo.co.uk>
Date: Fri, 13 Nov 2015 05:14:45 +0000
Subject: [PATCH] [modules] When a declaration has non-trivial visibility,
 check whether it's actually hidden before we check its linkage. This avoids
 computing the linkage "too early" for an anonymous struct with a typedef name
 for linkage.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253012 91177308-0d34-0410-b5e6-96231b3b80d8
---
 include/clang/Sema/Lookup.h           | 3 +--
 test/Modules/submodule-visibility.cpp | 7 +++++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/include/clang/Sema/Lookup.h b/include/clang/Sema/Lookup.h
index f291a8aef05..87c40f0cf20 100644
--- a/include/clang/Sema/Lookup.h
+++ b/include/clang/Sema/Lookup.h
@@ -303,8 +303,7 @@ public:
     if (!D->isInIdentifierNamespace(IDNS))
       return nullptr;
 
-    if (!D->isHidden() || isHiddenDeclarationVisible(D) ||
-        isVisibleSlow(getSema(), D))
+    if (isVisible(getSema(), D) || isHiddenDeclarationVisible(D))
       return D;
 
     return getAcceptableDeclSlow(D);
diff --git a/test/Modules/submodule-visibility.cpp b/test/Modules/submodule-visibility.cpp
index b2c5fc7ba19..345ae155bb3 100644
--- a/test/Modules/submodule-visibility.cpp
+++ b/test/Modules/submodule-visibility.cpp
@@ -28,3 +28,10 @@ int k = n + m; // OK, a and b are visible here.
 #ifndef B
 #error B is not defined
 #endif
+
+// Ensure we don't compute the linkage of this struct before we find it has a
+// typedef name for linkage purposes.
+typedef struct {
+  int p;                 
+  void (*f)(int p);                                                                       
+} name_for_linkage;
-- 
GitLab