Index: include/clang/Parse/Parser.h =================================================================== --- include/clang/Parse/Parser.h +++ include/clang/Parse/Parser.h @@ -2335,8 +2335,8 @@ void DiagnoseUnexpectedNamespace(NamedDecl *Context); - Decl *ParseNamespace(unsigned Context, SourceLocation &DeclEnd, - SourceLocation InlineLoc = SourceLocation()); + DeclGroupPtrTy ParseNamespace(unsigned Context, SourceLocation &DeclEnd, + SourceLocation InlineLoc = SourceLocation()); void ParseInnerNamespace(std::vector& IdentLoc, std::vector& Ident, std::vector& NamespaceLoc, Index: include/clang/Sema/Sema.h =================================================================== --- include/clang/Sema/Sema.h +++ include/clang/Sema/Sema.h @@ -4054,7 +4054,8 @@ SourceLocation IdentLoc, IdentifierInfo *Ident, SourceLocation LBrace, - AttributeList *AttrList); + AttributeList *AttrList, + UsingDirectiveDecl * &UsingDecl); void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace); NamespaceDecl *getStdNamespace() const; Index: lib/CodeGen/CGDebugInfo.cpp =================================================================== --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -3259,10 +3259,14 @@ void CGDebugInfo::EmitUsingDirective(const UsingDirectiveDecl &UD) { if (CGM.getCodeGenOpts().getDebugInfo() < CodeGenOptions::LimitedDebugInfo) return; - DBuilder.createImportedModule( - getCurrentContextDescriptor(cast(UD.getDeclContext())), - getOrCreateNameSpace(UD.getNominatedNamespace()), - getLineNumber(UD.getLocation())); + const NamespaceDecl *NSDecl = UD.getNominatedNamespace(); + if (!NSDecl->isAnonymousNamespace() || + CGM.getTarget().getTriple().isPS4CPU()) { + DBuilder.createImportedModule( + getCurrentContextDescriptor(cast(UD.getDeclContext())), + getOrCreateNameSpace(NSDecl), + getLineNumber(UD.getLocation())); + } } void CGDebugInfo::EmitUsingDecl(const UsingDecl &UD) { Index: lib/Parse/ParseDecl.cpp =================================================================== --- lib/Parse/ParseDecl.cpp +++ lib/Parse/ParseDecl.cpp @@ -1468,15 +1468,13 @@ if (getLangOpts().CPlusPlus && NextToken().is(tok::kw_namespace)) { ProhibitAttributes(attrs); SourceLocation InlineLoc = ConsumeToken(); - SingleDecl = ParseNamespace(Context, DeclEnd, InlineLoc); - break; + return ParseNamespace(Context, DeclEnd, InlineLoc); } return ParseSimpleDeclaration(Context, DeclEnd, attrs, true); case tok::kw_namespace: ProhibitAttributes(attrs); - SingleDecl = ParseNamespace(Context, DeclEnd); - break; + return ParseNamespace(Context, DeclEnd); case tok::kw_using: SingleDecl = ParseUsingDirectiveOrDeclaration(Context, ParsedTemplateInfo(), DeclEnd, attrs, &OwnedType); Index: lib/Parse/ParseDeclCXX.cpp =================================================================== --- lib/Parse/ParseDeclCXX.cpp +++ lib/Parse/ParseDeclCXX.cpp @@ -54,9 +54,9 @@ /// namespace-alias-definition: [C++ 7.3.2: namespace.alias] /// 'namespace' identifier '=' qualified-namespace-specifier ';' /// -Decl *Parser::ParseNamespace(unsigned Context, - SourceLocation &DeclEnd, - SourceLocation InlineLoc) { +Parser::DeclGroupPtrTy Parser::ParseNamespace(unsigned Context, + SourceLocation &DeclEnd, + SourceLocation InlineLoc) { assert(Tok.is(tok::kw_namespace) && "Not a namespace!"); SourceLocation NamespaceLoc = ConsumeToken(); // eat the 'namespace'. ObjCDeclContextSwitch ObjCDC(*this); @@ -64,7 +64,7 @@ if (Tok.is(tok::code_completion)) { Actions.CodeCompleteNamespaceDecl(getCurScope()); cutOffParsing(); - return nullptr; + return DeclGroupPtrTy();; } SourceLocation IdentLoc; @@ -108,7 +108,7 @@ Diag(Tok, diag::err_expected) << tok::identifier; // Skip to end of the definition and eat the ';'. SkipUntil(tok::semi); - return nullptr; + return DeclGroupPtrTy(); } if (attrLoc.isValid()) Diag(attrLoc, diag::err_unexpected_namespace_attributes_alias); @@ -115,8 +115,9 @@ if (InlineLoc.isValid()) Diag(InlineLoc, diag::err_inline_namespace_alias) << FixItHint::CreateRemoval(InlineLoc); - return ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd); - } + Decl *NSAlias = ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd); + return Actions.ConvertDeclToDeclGroup(NSAlias); +} BalancedDelimiterTracker T(*this, tok::l_brace); @@ -125,7 +126,7 @@ Diag(Tok, diag::err_expected) << tok::l_brace; else Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace; - return nullptr; + return DeclGroupPtrTy(); } if (getCurScope()->isClassScope() || getCurScope()->isTemplateParamScope() || @@ -133,7 +134,7 @@ getCurScope()->getFnParent()) { Diag(T.getOpenLocation(), diag::err_namespace_nonnamespace_scope); SkipUntil(tok::r_brace); - return nullptr; + return DeclGroupPtrTy(); } if (ExtraIdent.empty()) { @@ -180,10 +181,11 @@ // Enter a scope for the namespace. ParseScope NamespaceScope(this, Scope::DeclScope); + UsingDirectiveDecl *ImplicitUsingDirectiveDecl = nullptr; Decl *NamespcDecl = Actions.ActOnStartNamespaceDef(getCurScope(), InlineLoc, NamespaceLoc, IdentLoc, Ident, T.getOpenLocation(), - attrs.getList()); + attrs.getList(), ImplicitUsingDirectiveDecl); PrettyDeclStackTraceEntry CrashInfo(Actions, NamespcDecl, NamespaceLoc, "parsing namespace"); @@ -198,8 +200,10 @@ DeclEnd = T.getCloseLocation(); Actions.ActOnFinishNamespaceDef(NamespcDecl, DeclEnd); - - return NamespcDecl; + + // Return NamespaceDecl + ImportDecl here. + return Actions.ConvertDeclToDeclGroup(NamespcDecl, + ImplicitUsingDirectiveDecl); } /// ParseInnerNamespace - Parse the contents of a namespace. @@ -228,17 +232,17 @@ // FIXME: Preserve the source information through to the AST rather than // desugaring it here. ParseScope NamespaceScope(this, Scope::DeclScope); + UsingDirectiveDecl *ImplicitUsingDirectiveDecl = NULL; Decl *NamespcDecl = Actions.ActOnStartNamespaceDef(getCurScope(), SourceLocation(), NamespaceLoc[index], IdentLoc[index], Ident[index], Tracker.getOpenLocation(), - attrs.getList()); + attrs.getList(), ImplicitUsingDirectiveDecl); ParseInnerNamespace(IdentLoc, Ident, NamespaceLoc, ++index, InlineLoc, attrs, Tracker); NamespaceScope.Exit(); - Actions.ActOnFinishNamespaceDef(NamespcDecl, Tracker.getCloseLocation()); } Index: lib/Sema/SemaDeclCXX.cpp =================================================================== --- lib/Sema/SemaDeclCXX.cpp +++ lib/Sema/SemaDeclCXX.cpp @@ -7185,7 +7185,8 @@ SourceLocation IdentLoc, IdentifierInfo *II, SourceLocation LBrace, - AttributeList *AttrList) { + AttributeList *AttrList, + UsingDirectiveDecl *& UD) { SourceLocation StartLoc = InlineLoc.isValid() ? InlineLoc : NamespaceLoc; // For anonymous namespace, take the location of the left brace. SourceLocation Loc = II ? IdentLoc : LBrace; @@ -7309,14 +7310,13 @@ // namespace internal linkage. if (!PrevNS) { - UsingDirectiveDecl* UD - = UsingDirectiveDecl::Create(Context, Parent, - /* 'using' */ LBrace, - /* 'namespace' */ SourceLocation(), - /* qualifier */ NestedNameSpecifierLoc(), - /* identifier */ SourceLocation(), - Namespc, - /* Ancestor */ Parent); + UD = UsingDirectiveDecl::Create(Context, Parent, + /* 'using' */ LBrace, + /* 'namespace' */ SourceLocation(), + /* qualifier */ NestedNameSpecifierLoc(), + /* identifier */ SourceLocation(), + Namespc, + /* Ancestor */ Parent); UD->setImplicit(); Parent->addDecl(UD); } Index: test/CodeGenCXX/debug-info-anon-namespace.cpp =================================================================== --- test/CodeGenCXX/debug-info-anon-namespace.cpp +++ test/CodeGenCXX/debug-info-anon-namespace.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -emit-llvm -g -triple x86_64-scei-ps4 -O0 %s -o - | FileCheck --check-prefix=PS4 %s +// RUN: %clang_cc1 -emit-llvm -g -triple x86_64-unknown-linux-gnu -O0 %s -o - | FileCheck --check-prefix=NON-PS4 %s + +namespace +{ + int a = 5; +} +int *b = &a; + +namespace +{ + namespace { + int a1 = 5; + } + int a2 = 7; +} +int *b1 = &a1; +int *b2 = &a2; + + +// PS4: [[NS:![0-9]+]] = !DINamespace +// PS4: [[NS2:![0-9]+]] = !DINamespace +// PS4: !DIImportedEntity(tag: DW_TAG_imported_module, scope: !0, entity: [[NS]]) +// PS4: !DIImportedEntity(tag: DW_TAG_imported_module, scope: [[NS]], entity: [[NS2]], line: {{[0-9]+}}) +// NON-PS4-NOT: !DIImportedEntity +