Index: lib/CodeGen/CGDebugInfo.cpp =================================================================== --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -2376,9 +2376,11 @@ // FIXME: Generalize this for even non-member global variables where the // declaration and definition may have different lexical decl contexts, once // we have support for emitting declarations of (non-member) global variables. - VDContext = getContextDescriptor( - dyn_cast(VD->isStaticDataMember() ? VD->getLexicalDeclContext() - : VD->getDeclContext())); + const DeclContext *DC = VD->isStaticDataMember() ? VD->getLexicalDeclContext() + : VD->getDeclContext(); + while (DC->isRecord()) + DC = DC->getParent(); + VDContext = getContextDescriptor(dyn_cast(DC)); } llvm::DISubprogram @@ -3171,6 +3173,7 @@ CGDebugInfo::getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D) { if (!D->isStaticDataMember()) return llvm::DIDerivedType(); + auto MI = StaticDataMemberCache.find(D->getCanonicalDecl()); if (MI != StaticDataMemberCache.end()) { assert(MI->second && "Static data member declaration should still exist"); Index: test/CodeGenCXX/inline-dllexport-member.cpp =================================================================== --- /dev/null +++ test/CodeGenCXX/inline-dllexport-member.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -triple i686-windows-gnu -fms-compatibility -g -emit-llvm %s -o - \ +// RUN: | FileCheck %s + +struct __declspec(dllexport) s { + static const unsigned int ui = 0; +}; + +// CHECK: ; [ DW_TAG_variable ] [ui] [line 5] [def] +// CHECK: ; [ DW_TAG_const_type ] [line 0, size 0, align 0, offset 0] [from unsigned int] +// CHECK: ; [ DW_TAG_base_type ] [unsigned int] [line 0, size 32, align 32, offset 0, enc DW_ATE_unsigned] +// CHECH: ; [ DW_TAG_member ] [ui] [line 5, size 0, align 0, offset 0] [static] [from ] +