<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 10, 2015 at 10:52 AM, Ekaterina Romanova via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: kromanova<br>
Date: Thu Dec 10 12:52:50 2015<br>
New Revision: 255281<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=255281&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=255281&view=rev</a><br>
Log:<br>
Do not generate DW_TAG_imported_module for anonymous namespaces (even nested) for all the platforms except PS4.<br>
For PS4, generate explicit import for anonymous namespaces and mark it by DW_AT_artificial attribute.<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D12624" rel="noreferrer" target="_blank">http://reviews.llvm.org/D12624</a><br>
<br>
<br>
Added:<br>
cfe/trunk/test/CodeGenCXX/debug-info-anon-namespace.cpp<br>
Modified:<br>
cfe/trunk/include/clang/Frontend/CodeGenOptions.def<br>
cfe/trunk/include/clang/Parse/Parser.h<br>
cfe/trunk/include/clang/Sema/Sema.h<br>
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
cfe/trunk/lib/Frontend/CompilerInvocation.cpp<br>
cfe/trunk/lib/Parse/ParseDecl.cpp<br>
cfe/trunk/lib/Parse/ParseDeclCXX.cpp<br>
cfe/trunk/lib/Sema/SemaDeclCXX.cpp<br>
<br>
Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=255281&r1=255280&r2=255281&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=255281&r1=255280&r2=255281&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)<br>
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Thu Dec 10 12:52:50 2015<br>
@@ -166,6 +166,10 @@ CODEGENOPT(DebugColumnInfo, 1, 0) ///< W<br>
CODEGENOPT(DebugTypeExtRefs, 1, 0) ///< Whether or not debug info should contain<br>
///< external references to a PCH or module.<br>
<br>
+CODEGENOPT(DebugExplicitImport, 1, 0) ///< Whether or not debug info should<br>
+ ///< contain explicit imports for<br>
+ ///< anonymous namespaces<br>
+<br>
CODEGENOPT(EmitLLVMUseLists, 1, 0) ///< Control whether to serialize use-lists.<br>
<br>
/// The user specified number of registers to be used for integral arguments,<br>
<br>
Modified: cfe/trunk/include/clang/Parse/Parser.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=255281&r1=255280&r2=255281&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=255281&r1=255280&r2=255281&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Parse/Parser.h (original)<br>
+++ cfe/trunk/include/clang/Parse/Parser.h Thu Dec 10 12:52:50 2015<br>
@@ -2337,8 +2337,8 @@ private:<br>
<br>
void DiagnoseUnexpectedNamespace(NamedDecl *Context);<br>
<br>
- Decl *ParseNamespace(unsigned Context, SourceLocation &DeclEnd,<br>
- SourceLocation InlineLoc = SourceLocation());<br>
+ DeclGroupPtrTy ParseNamespace(unsigned Context, SourceLocation &DeclEnd,<br>
+ SourceLocation InlineLoc = SourceLocation());<br>
void ParseInnerNamespace(std::vector<SourceLocation>& IdentLoc,<br>
std::vector<IdentifierInfo*>& Ident,<br>
std::vector<SourceLocation>& NamespaceLoc,<br>
<br>
Modified: cfe/trunk/include/clang/Sema/Sema.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=255281&r1=255280&r2=255281&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=255281&r1=255280&r2=255281&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Sema/Sema.h (original)<br>
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Dec 10 12:52:50 2015<br>
@@ -4093,7 +4093,8 @@ public:<br>
SourceLocation IdentLoc,<br>
IdentifierInfo *Ident,<br>
SourceLocation LBrace,<br>
- AttributeList *AttrList);<br>
+ AttributeList *AttrList,<br>
+ UsingDirectiveDecl * &UsingDecl);<br>
void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace);<br>
<br>
NamespaceDecl *getStdNamespace() const;<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=255281&r1=255280&r2=255281&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=255281&r1=255280&r2=255281&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Dec 10 12:52:50 2015<br>
@@ -3408,10 +3408,14 @@ llvm::DIScope *CGDebugInfo::getCurrentCo<br>
void CGDebugInfo::EmitUsingDirective(const UsingDirectiveDecl &UD) {<br>
if (CGM.getCodeGenOpts().getDebugInfo() < CodeGenOptions::LimitedDebugInfo)<br>
return;<br>
- DBuilder.createImportedModule(<br>
- getCurrentContextDescriptor(cast<Decl>(UD.getDeclContext())),<br>
- getOrCreateNameSpace(UD.getNominatedNamespace()),<br>
- getLineNumber(UD.getLocation()));<br>
+ const NamespaceDecl *NSDecl = UD.getNominatedNamespace();<br>
+ if (!NSDecl->isAnonymousNamespace() ||<br>
+ CGM.getCodeGenOpts().DebugExplicitImport) {<br>
+ DBuilder.createImportedModule(<br>
+ getCurrentContextDescriptor(cast<Decl>(UD.getDeclContext())),<br>
+ getOrCreateNameSpace(NSDecl),<br>
+ getLineNumber(UD.getLocation()));<br>
+ }<br>
}<br>
<br>
void CGDebugInfo::EmitUsingDecl(const UsingDecl &UD) {<br>
<br>
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=255281&r1=255280&r2=255281&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=255281&r1=255280&r2=255281&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)<br>
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu Dec 10 12:52:50 2015<br>
@@ -365,6 +365,7 @@ static bool ParseCodeGenArgs(CodeGenOpti<br>
const TargetOptions &TargetOpts) {<br>
using namespace options;<br>
bool Success = true;<br>
+ llvm::Triple Triple = llvm::Triple(TargetOpts.Triple);<br>
<br>
unsigned OptimizationLevel = getOptimizationLevel(Args, IK, Diags);<br>
// TODO: This could be done in Driver<br>
@@ -409,6 +410,8 @@ static bool ParseCodeGenArgs(CodeGenOpti<br>
Opts.EmitCodeView = Args.hasArg(OPT_gcodeview);<br>
Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file);<br>
Opts.DebugTypeExtRefs = Args.hasArg(OPT_dwarf_ext_refs);<br>
+ if (Triple.isPS4CPU())<br>
+ Opts.DebugExplicitImport = true;<br></blockquote><div><br></div><div>Could/should this ^ just be: Opts.DebugExplicitImport = Triple.isPS4CPU(); ?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
for (const auto &Arg : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ))<br>
Opts.DebugPrefixMap.insert(StringRef(Arg).split('='));<br>
<br>
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=255281&r1=255280&r2=255281&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=255281&r1=255280&r2=255281&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)<br>
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Thu Dec 10 12:52:50 2015<br>
@@ -1465,15 +1465,13 @@ Parser::DeclGroupPtrTy Parser::ParseDecl<br>
if (getLangOpts().CPlusPlus && NextToken().is(tok::kw_namespace)) {<br>
ProhibitAttributes(attrs);<br>
SourceLocation InlineLoc = ConsumeToken();<br>
- SingleDecl = ParseNamespace(Context, DeclEnd, InlineLoc);<br>
- break;<br>
+ return ParseNamespace(Context, DeclEnd, InlineLoc);<br>
}<br>
return ParseSimpleDeclaration(Context, DeclEnd, attrs,<br>
true);<br>
case tok::kw_namespace:<br>
ProhibitAttributes(attrs);<br>
- SingleDecl = ParseNamespace(Context, DeclEnd);<br>
- break;<br>
+ return ParseNamespace(Context, DeclEnd);<br>
case tok::kw_using:<br>
SingleDecl = ParseUsingDirectiveOrDeclaration(Context, ParsedTemplateInfo(),<br>
DeclEnd, attrs, &OwnedType);<br>
<br>
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=255281&r1=255280&r2=255281&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=255281&r1=255280&r2=255281&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)<br>
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Thu Dec 10 12:52:50 2015<br>
@@ -55,9 +55,9 @@ using namespace clang;<br>
/// namespace-alias-definition: [C++ 7.3.2: namespace.alias]<br>
/// 'namespace' identifier '=' qualified-namespace-specifier ';'<br>
///<br>
-Decl *Parser::ParseNamespace(unsigned Context,<br>
- SourceLocation &DeclEnd,<br>
- SourceLocation InlineLoc) {<br>
+Parser::DeclGroupPtrTy Parser::ParseNamespace(unsigned Context,<br>
+ SourceLocation &DeclEnd,<br>
+ SourceLocation InlineLoc) {<br>
assert(Tok.is(tok::kw_namespace) && "Not a namespace!");<br>
SourceLocation NamespaceLoc = ConsumeToken(); // eat the 'namespace'.<br>
ObjCDeclContextSwitch ObjCDC(*this);<br>
@@ -65,7 +65,7 @@ Decl *Parser::ParseNamespace(unsigned Co<br>
if (Tok.is(tok::code_completion)) {<br>
Actions.CodeCompleteNamespaceDecl(getCurScope());<br>
cutOffParsing();<br>
- return nullptr;<br>
+ return DeclGroupPtrTy();;<br></blockquote><div><br></div><div>Extra semicolon here ^<br><br>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?)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
}<br>
<br>
SourceLocation IdentLoc;<br>
@@ -109,15 +109,16 @@ Decl *Parser::ParseNamespace(unsigned Co<br>
Diag(Tok, diag::err_expected) << tok::identifier;<br>
// Skip to end of the definition and eat the ';'.<br>
SkipUntil(tok::semi);<br>
- return nullptr;<br>
+ return DeclGroupPtrTy();<br>
}<br>
if (attrLoc.isValid())<br>
Diag(attrLoc, diag::err_unexpected_namespace_attributes_alias);<br>
if (InlineLoc.isValid())<br>
Diag(InlineLoc, diag::err_inline_namespace_alias)<br>
<< FixItHint::CreateRemoval(InlineLoc);<br>
- return ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd);<br>
- }<br>
+ Decl *NSAlias = ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd);<br>
+ return Actions.ConvertDeclToDeclGroup(NSAlias);<br>
+}<br>
<br>
BalancedDelimiterTracker T(*this, tok::l_brace);<br>
if (T.consumeOpen()) {<br>
@@ -125,7 +126,7 @@ Decl *Parser::ParseNamespace(unsigned Co<br>
Diag(Tok, diag::err_expected) << tok::l_brace;<br>
else<br>
Diag(Tok, diag::err_expected_either) << tok::identifier << tok::l_brace;<br>
- return nullptr;<br>
+ return DeclGroupPtrTy();<br>
}<br>
<br>
if (getCurScope()->isClassScope() || getCurScope()->isTemplateParamScope() ||<br>
@@ -133,7 +134,7 @@ Decl *Parser::ParseNamespace(unsigned Co<br>
getCurScope()->getFnParent()) {<br>
Diag(T.getOpenLocation(), diag::err_namespace_nonnamespace_scope);<br>
SkipUntil(tok::r_brace);<br>
- return nullptr;<br>
+ return DeclGroupPtrTy();<br>
}<br>
<br>
if (ExtraIdent.empty()) {<br>
@@ -180,10 +181,11 @@ Decl *Parser::ParseNamespace(unsigned Co<br>
// Enter a scope for the namespace.<br>
ParseScope NamespaceScope(this, Scope::DeclScope);<br>
<br>
+ UsingDirectiveDecl *ImplicitUsingDirectiveDecl = nullptr;<br>
Decl *NamespcDecl =<br>
Actions.ActOnStartNamespaceDef(getCurScope(), InlineLoc, NamespaceLoc,<br>
IdentLoc, Ident, T.getOpenLocation(),<br>
- attrs.getList());<br>
+ attrs.getList(), ImplicitUsingDirectiveDecl);<br>
<br>
PrettyDeclStackTraceEntry CrashInfo(Actions, NamespcDecl, NamespaceLoc,<br>
"parsing namespace");<br>
@@ -198,8 +200,9 @@ Decl *Parser::ParseNamespace(unsigned Co<br>
<br>
DeclEnd = T.getCloseLocation();<br>
Actions.ActOnFinishNamespaceDef(NamespcDecl, DeclEnd);<br>
-<br>
- return NamespcDecl;<br>
+<br>
+ return Actions.ConvertDeclToDeclGroup(NamespcDecl,<br>
+ ImplicitUsingDirectiveDecl);<br>
}<br>
<br>
/// ParseInnerNamespace - Parse the contents of a namespace.<br>
@@ -229,17 +232,19 @@ void Parser::ParseInnerNamespace(std::ve<br>
// FIXME: Preserve the source information through to the AST rather than<br>
// desugaring it here.<br>
ParseScope NamespaceScope(this, Scope::DeclScope);<br>
+ UsingDirectiveDecl *ImplicitUsingDirectiveDecl = nullptr;<br>
Decl *NamespcDecl =<br>
Actions.ActOnStartNamespaceDef(getCurScope(), SourceLocation(),<br>
NamespaceLoc[index], IdentLoc[index],<br>
Ident[index], Tracker.getOpenLocation(),<br>
- attrs.getList());<br>
+ attrs.getList(), ImplicitUsingDirectiveDecl);<br>
+ assert(!ImplicitUsingDirectiveDecl &&<br>
+ "nested namespace definition cannot define anonymous namespace");<br>
<br>
ParseInnerNamespace(IdentLoc, Ident, NamespaceLoc, ++index, InlineLoc,<br>
attrs, Tracker);<br>
<br>
NamespaceScope.Exit();<br>
-<br>
Actions.ActOnFinishNamespaceDef(NamespcDecl, Tracker.getCloseLocation());<br>
}<br>
<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=255281&r1=255280&r2=255281&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=255281&r1=255280&r2=255281&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Dec 10 12:52:50 2015<br>
@@ -7185,7 +7185,8 @@ Decl *Sema::ActOnStartNamespaceDef(Scope<br>
SourceLocation IdentLoc,<br>
IdentifierInfo *II,<br>
SourceLocation LBrace,<br>
- AttributeList *AttrList) {<br>
+ AttributeList *AttrList,<br>
+ UsingDirectiveDecl *&UD) {<br>
SourceLocation StartLoc = InlineLoc.isValid() ? InlineLoc : NamespaceLoc;<br>
// For anonymous namespace, take the location of the left brace.<br>
SourceLocation Loc = II ? IdentLoc : LBrace;<br>
@@ -7299,14 +7300,13 @@ Decl *Sema::ActOnStartNamespaceDef(Scope<br>
// namespace internal linkage.<br>
<br>
if (!PrevNS) {<br>
- UsingDirectiveDecl* UD<br>
- = UsingDirectiveDecl::Create(Context, Parent,<br>
- /* 'using' */ LBrace,<br>
- /* 'namespace' */ SourceLocation(),<br>
- /* qualifier */ NestedNameSpecifierLoc(),<br>
- /* identifier */ SourceLocation(),<br>
- Namespc,<br>
- /* Ancestor */ Parent);<br>
+ UD = UsingDirectiveDecl::Create(Context, Parent,<br>
+ /* 'using' */ LBrace,<br>
+ /* 'namespace' */ SourceLocation(),<br>
+ /* qualifier */ NestedNameSpecifierLoc(),<br>
+ /* identifier */ SourceLocation(),<br>
+ Namespc,<br>
+ /* Ancestor */ Parent);<br>
UD->setImplicit();<br>
Parent->addDecl(UD);<br>
}<br>
<br>
Added: cfe/trunk/test/CodeGenCXX/debug-info-anon-namespace.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-anon-namespace.cpp?rev=255281&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-anon-namespace.cpp?rev=255281&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/debug-info-anon-namespace.cpp (added)<br>
+++ cfe/trunk/test/CodeGenCXX/debug-info-anon-namespace.cpp Thu Dec 10 12:52:50 2015<br>
@@ -0,0 +1,26 @@<br>
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple x86_64-scei-ps4 -O0 %s -o - | FileCheck --check-prefix=PS4 %s<br>
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -triple x86_64-unknown-linux-gnu -O0 %s -o - | FileCheck --check-prefix=NON-PS4 %s<br>
+<br>
+namespace<br>
+{<br>
+ int a = 5;<br>
+}<br>
+int *b = &a;<br>
+<br>
+namespace<br>
+{<br>
+ namespace {<br>
+ int a1 = 5;<br>
+ }<br>
+ int a2 = 7;<br>
+}<br>
+int *b1 = &a1;<br>
+int *b2 = &a2;<br>
+<br>
+<br>
+// PS4: [[NS:![0-9]+]] = !DINamespace<br>
+// PS4: [[NS2:![0-9]+]] = !DINamespace<br>
+// PS4: !DIImportedEntity(tag: DW_TAG_imported_module, scope: !0, entity: [[NS]])<br>
+// PS4: !DIImportedEntity(tag: DW_TAG_imported_module, scope: [[NS]], entity: [[NS2]], line: {{[0-9]+}})<br>
+// NON-PS4-NOT: !DIImportedEntity<br>
+<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>