From 128f39da932be50cb49646084820119e6e0d1e22 Mon Sep 17 00:00:00 2001 From: Alexey Bader Date: Sat, 28 Dec 2019 16:13:33 +0300 Subject: [PATCH] Fix crash in getFullyQualifiedName for inline namespace Summary: The ICE happens when the most outer namespace is an inline namespace. Reviewers: bkramer, ilya-biryukov Reviewed By: ilya-biryukov Subscribers: ebevhan, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71962 --- clang/lib/AST/QualTypeNames.cpp | 2 +- clang/unittests/Tooling/QualTypeNamesTest.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/QualTypeNames.cpp b/clang/lib/AST/QualTypeNames.cpp index f28f001..73a33a2 100644 --- a/clang/lib/AST/QualTypeNames.cpp +++ b/clang/lib/AST/QualTypeNames.cpp @@ -192,7 +192,7 @@ static NestedNameSpecifier *createOuterNNS(const ASTContext &Ctx, const Decl *D, // Ignore inline namespace; NS = dyn_cast(NS->getDeclContext()); } - if (NS->getDeclName()) { + if (NS && NS->getDeclName()) { return createNestedNameSpecifier(Ctx, NS, WithGlobalNsPrefix); } return nullptr; // no starting '::', no anonymous diff --git a/clang/unittests/Tooling/QualTypeNamesTest.cpp b/clang/unittests/Tooling/QualTypeNamesTest.cpp index b6c3029..ff6b78c 100644 --- a/clang/unittests/Tooling/QualTypeNamesTest.cpp +++ b/clang/unittests/Tooling/QualTypeNamesTest.cpp @@ -223,6 +223,17 @@ TEST(QualTypeNameTest, getFullyQualifiedName) { "}\n" ); + TypeNameVisitor InlineNamespace; + InlineNamespace.ExpectedQualTypeNames["c"] = "B::C"; + InlineNamespace.runOver("inline namespace A {\n" + " namespace B {\n" + " class C {};\n" + " }\n" + "}\n" + "using namespace A::B;\n" + "C c;\n", + TypeNameVisitor::Lang_CXX11); + TypeNameVisitor AnonStrucs; AnonStrucs.ExpectedQualTypeNames["a"] = "short"; AnonStrucs.ExpectedQualTypeNames["un_in_st_1"] = -- 2.7.4