Index: lib/CodeGen/CGDebugInfo.cpp =================================================================== --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -2969,8 +2969,13 @@ if (DC->isRecord()) DC = CGM.getContext().getTranslationUnitDecl(); - llvm::DIScope *Mod = getParentModuleOrNull(VD); - VDContext = getContextDescriptor(cast(DC), Mod ? Mod : TheCU); + // If we are in a lexical block use it as the context. + if (!LexicalBlockStack.empty()) + VDContext = cast(LexicalBlockStack.back()); + else { + llvm::DIScope *Mod = getParentModuleOrNull(VD); + VDContext = getContextDescriptor(cast(DC), Mod ? Mod : TheCU); + } } llvm::DISubprogram *CGDebugInfo::getFunctionFwdDeclOrStub(GlobalDecl GD,