On Thu, Dec 10, 2015 at 10:52 AM, Ekaterina Romanova via cfe-commits < cfe-commits@lists.llvm.org> wrote:
> Author: kromanova > Date: Thu Dec 10 12:52:50 2015 > New Revision: 255281 > > URL: http://llvm.org/viewvc/llvm-project?rev=255281&view=rev > Log: > Do not generate DW_TAG_imported_module for anonymous namespaces (even > nested) for all the platforms except PS4. > For PS4, generate explicit import for anonymous namespaces and mark it by > DW_AT_artificial attribute. > > Differential Revision: http://reviews.llvm.org/D12624 > > > Added: > cfe/trunk/test/CodeGenCXX/debug-info-anon-namespace.cpp > Modified: > cfe/trunk/include/clang/Frontend/CodeGenOptions.def > cfe/trunk/include/clang/Parse/Parser.h > cfe/trunk/include/clang/Sema/Sema.h > cfe/trunk/lib/CodeGen/CGDebugInfo.cpp > cfe/trunk/lib/Frontend/CompilerInvocation.cpp > cfe/trunk/lib/Parse/ParseDecl.cpp > cfe/trunk/lib/Parse/ParseDeclCXX.cpp > cfe/trunk/lib/Sema/SemaDeclCXX.cpp > > Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=255281&r1=255280&r2=255281&view=diff > > ============================================================================== > --- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original) > +++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Thu Dec 10 > 12:52:50 2015 > @@ -166,6 +166,10 @@ CODEGENOPT(DebugColumnInfo, 1, 0) ///< W > CODEGENOPT(DebugTypeExtRefs, 1, 0) ///< Whether or not debug info should > contain > ///< external references to a PCH or > module. > > +CODEGENOPT(DebugExplicitImport, 1, 0) ///< Whether or not debug info > should > + ///< contain explicit imports for > + ///< anonymous namespaces > + > CODEGENOPT(EmitLLVMUseLists, 1, 0) ///< Control whether to serialize > use-lists. > > /// The user specified number of registers to be used for integral > arguments, > > Modified: cfe/trunk/include/clang/Parse/Parser.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=255281&r1=255280&r2=255281&view=diff > > ============================================================================== > --- cfe/trunk/include/clang/Parse/Parser.h (original) > +++ cfe/trunk/include/clang/Parse/Parser.h Thu Dec 10 12:52:50 2015 > @@ -2337,8 +2337,8 @@ private: > > 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<SourceLocation>& IdentLoc, > std::vector<IdentifierInfo*>& Ident, > std::vector<SourceLocation>& NamespaceLoc, > > Modified: cfe/trunk/include/clang/Sema/Sema.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=255281&r1=255280&r2=255281&view=diff > > ============================================================================== > --- cfe/trunk/include/clang/Sema/Sema.h (original) > +++ cfe/trunk/include/clang/Sema/Sema.h Thu Dec 10 12:52:50 2015 > @@ -4093,7 +4093,8 @@ public: > SourceLocation IdentLoc, > IdentifierInfo *Ident, > SourceLocation LBrace, > - AttributeList *AttrList); > + AttributeList *AttrList, > + UsingDirectiveDecl * &UsingDecl); > void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace); > > NamespaceDecl *getStdNamespace() const; > > Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=255281&r1=255280&r2=255281&view=diff > > ============================================================================== > --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original) > +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Dec 10 12:52:50 2015 > @@ -3408,10 +3408,14 @@ llvm::DIScope *CGDebugInfo::getCurrentCo > void CGDebugInfo::EmitUsingDirective(const UsingDirectiveDecl &UD) { > if (CGM.getCodeGenOpts().getDebugInfo() < > CodeGenOptions::LimitedDebugInfo) > return; > - DBuilder.createImportedModule( > - getCurrentContextDescriptor(cast<Decl>(UD.getDeclContext())), > - getOrCreateNameSpace(UD.getNominatedNamespace()), > - getLineNumber(UD.getLocation())); > + const NamespaceDecl *NSDecl = UD.getNominatedNamespace(); > + if (!NSDecl->isAnonymousNamespace() || > + CGM.getCodeGenOpts().DebugExplicitImport) { > + DBuilder.createImportedModule( > + getCurrentContextDescriptor(cast<Decl>(UD.getDeclContext())), > + getOrCreateNameSpace(NSDecl), > + getLineNumber(UD.getLocation())); > + } > } > > void CGDebugInfo::EmitUsingDecl(const UsingDecl &UD) { > > Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=255281&r1=255280&r2=255281&view=diff > > ============================================================================== > --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original) > +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu Dec 10 12:52:50 2015 > @@ -365,6 +365,7 @@ static bool ParseCodeGenArgs(CodeGenOpti > const TargetOptions &TargetOpts) { > using namespace options; > bool Success = true; > + llvm::Triple Triple = llvm::Triple(TargetOpts.Triple); > > unsigned OptimizationLevel = getOptimizationLevel(Args, IK, Diags); > // TODO: This could be done in Driver > @@ -409,6 +410,8 @@ static bool ParseCodeGenArgs(CodeGenOpti > Opts.EmitCodeView = Args.hasArg(OPT_gcodeview); > Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file); > Opts.DebugTypeExtRefs = Args.hasArg(OPT_dwarf_ext_refs); > + if (Triple.isPS4CPU()) > + Opts.DebugExplicitImport = true; > Could/should this ^ just be: Opts.DebugExplicitImport = Triple.isPS4CPU(); ? > > for (const auto &Arg : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ)) > Opts.DebugPrefixMap.insert(StringRef(Arg).split('=')); > > Modified: cfe/trunk/lib/Parse/ParseDecl.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=255281&r1=255280&r2=255281&view=diff > > ============================================================================== > --- cfe/trunk/lib/Parse/ParseDecl.cpp (original) > +++ cfe/trunk/lib/Parse/ParseDecl.cpp Thu Dec 10 12:52:50 2015 > @@ -1465,15 +1465,13 @@ Parser::DeclGroupPtrTy Parser::ParseDecl > 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); > > Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=255281&r1=255280&r2=255281&view=diff > > ============================================================================== > --- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original) > +++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Thu Dec 10 12:52:50 2015 > @@ -55,9 +55,9 @@ using namespace clang; > /// 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); > @@ -65,7 +65,7 @@ Decl *Parser::ParseNamespace(unsigned Co > if (Tok.is(tok::code_completion)) { > Actions.CodeCompleteNamespaceDecl(getCurScope()); > cutOffParsing(); > - return nullptr; > + return DeclGroupPtrTy();; > Extra semicolon here ^ And is there any reason not to just use nullptr here and elsewhere? Anything with the substring "PtrTy" in the name seems like it should be pointer-like and be convertible from nullptr_t, no? (what is DeclGroupPtrTy?) > } > > SourceLocation IdentLoc; > @@ -109,15 +109,16 @@ Decl *Parser::ParseNamespace(unsigned Co > 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); > 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); > if (T.consumeOpen()) { > @@ -125,7 +126,7 @@ Decl *Parser::ParseNamespace(unsigned Co > 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 @@ Decl *Parser::ParseNamespace(unsigned Co > 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 @@ Decl *Parser::ParseNamespace(unsigned Co > // 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,9 @@ Decl *Parser::ParseNamespace(unsigned Co > > DeclEnd = T.getCloseLocation(); > Actions.ActOnFinishNamespaceDef(NamespcDecl, DeclEnd); > - > - return NamespcDecl; > + > + return Actions.ConvertDeclToDeclGroup(NamespcDecl, > + ImplicitUsingDirectiveDecl); > } > > /// ParseInnerNamespace - Parse the contents of a namespace. > @@ -229,17 +232,19 @@ void Parser::ParseInnerNamespace(std::ve > // FIXME: Preserve the source information through to the AST rather than > // desugaring it here. > ParseScope NamespaceScope(this, Scope::DeclScope); > + UsingDirectiveDecl *ImplicitUsingDirectiveDecl = nullptr; > Decl *NamespcDecl = > Actions.ActOnStartNamespaceDef(getCurScope(), SourceLocation(), > NamespaceLoc[index], IdentLoc[index], > Ident[index], > Tracker.getOpenLocation(), > - attrs.getList()); > + attrs.getList(), > ImplicitUsingDirectiveDecl); > + assert(!ImplicitUsingDirectiveDecl && > + "nested namespace definition cannot define anonymous namespace"); > > ParseInnerNamespace(IdentLoc, Ident, NamespaceLoc, ++index, InlineLoc, > attrs, Tracker); > > NamespaceScope.Exit(); > - > Actions.ActOnFinishNamespaceDef(NamespcDecl, > Tracker.getCloseLocation()); > } > > > Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=255281&r1=255280&r2=255281&view=diff > > ============================================================================== > --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original) > +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Dec 10 12:52:50 2015 > @@ -7185,7 +7185,8 @@ Decl *Sema::ActOnStartNamespaceDef(Scope > 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; > @@ -7299,14 +7300,13 @@ Decl *Sema::ActOnStartNamespaceDef(Scope > // 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); > } > > Added: cfe/trunk/test/CodeGenCXX/debug-info-anon-namespace.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-anon-namespace.cpp?rev=255281&view=auto > > ============================================================================== > --- cfe/trunk/test/CodeGenCXX/debug-info-anon-namespace.cpp (added) > +++ cfe/trunk/test/CodeGenCXX/debug-info-anon-namespace.cpp Thu Dec 10 > 12:52:50 2015 > @@ -0,0 +1,26 @@ > +// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple > x86_64-scei-ps4 -O0 %s -o - | FileCheck --check-prefix=PS4 %s > +// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -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 > + > > > _______________________________________________ > cfe-commits mailing list > cfe-commits@lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits >
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits