Skip to content

Commit

Permalink
Merged master:4d90ff59ac45 into amd-gfx:8832016e5a77
Browse files Browse the repository at this point in the history
Local branch amd-gfx 8832016 Merged master:4dec8ec33d68 into amd-gfx:029ad24856bc
Remote branch master 4d90ff5 [clangd] When inserting "using", add "::" in front if that's the style.
  • Loading branch information
Sw authored and Sw committed Aug 25, 2020
2 parents 8832016 + 4d90ff5 commit 43b9ac8
Show file tree
Hide file tree
Showing 148 changed files with 5,568 additions and 2,623 deletions.
20 changes: 20 additions & 0 deletions clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ class UsingFinder : public RecursiveASTVisitor<UsingFinder> {
const SourceManager &SM;
};

bool isFullyQualified(const NestedNameSpecifier *NNS) {
if (!NNS)
return false;
return NNS->getKind() == NestedNameSpecifier::Global ||
isFullyQualified(NNS->getPrefix());
}

struct InsertionPointData {
// Location to insert the "using" statement. If invalid then the statement
// should not be inserted at all (it already exists).
Expand All @@ -94,6 +101,9 @@ struct InsertionPointData {
// insertion point is anchored to, we may need one or more \n to ensure
// proper formatting.
std::string Suffix;
// Whether using should be fully qualified, even if what the user typed was
// not. This is based on our detection of the local style.
bool AlwaysFullyQualify = false;
};

// Finds the best place to insert the "using" statement. Returns invalid
Expand All @@ -118,7 +128,13 @@ findInsertionPoint(const Tweak::Selection &Inputs,
SM)
.TraverseAST(Inputs.AST->getASTContext());

bool AlwaysFullyQualify = true;
for (auto &U : Usings) {
// Only "upgrade" to fully qualified is all relevant using decls are fully
// qualified. Otherwise trust what the user typed.
if (!isFullyQualified(U->getQualifier()))
AlwaysFullyQualify = false;

if (SM.isBeforeInTranslationUnit(Inputs.Cursor, U->getUsingLoc()))
// "Usings" is sorted, so we're done.
break;
Expand All @@ -137,6 +153,7 @@ findInsertionPoint(const Tweak::Selection &Inputs,
if (LastUsingLoc.isValid()) {
InsertionPointData Out;
Out.Loc = LastUsingLoc;
Out.AlwaysFullyQualify = AlwaysFullyQualify;
return Out;
}

Expand Down Expand Up @@ -278,6 +295,9 @@ Expected<Tweak::Effect> AddUsing::apply(const Selection &Inputs) {
std::string UsingText;
llvm::raw_string_ostream UsingTextStream(UsingText);
UsingTextStream << "using ";
if (InsertionPoint->AlwaysFullyQualify &&
!isFullyQualified(QualifierToRemove.getNestedNameSpecifier()))
UsingTextStream << "::";
QualifierToRemove.getNestedNameSpecifier()->print(
UsingTextStream, Inputs.AST->getASTContext().getPrintingPolicy());
UsingTextStream << Name << ";" << InsertionPoint->Suffix;
Expand Down
57 changes: 57 additions & 0 deletions clang-tools-extra/clangd/unittests/TweakTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2723,6 +2723,63 @@ namespace foo { void fun(); }
void foo::fun() {
ff();
})cpp"},
// If all other using are fully qualified, add ::
{R"cpp(
#include "test.hpp"
using ::one::two::cc;
using ::one::two::ee;
void fun() {
one::two::f^f();
})cpp",
R"cpp(
#include "test.hpp"
using ::one::two::cc;
using ::one::two::ff;using ::one::two::ee;
void fun() {
ff();
})cpp"},
// Make sure we don't add :: if it's already there
{R"cpp(
#include "test.hpp"
using ::one::two::cc;
using ::one::two::ee;
void fun() {
::one::two::f^f();
})cpp",
R"cpp(
#include "test.hpp"
using ::one::two::cc;
using ::one::two::ff;using ::one::two::ee;
void fun() {
ff();
})cpp"},
// If even one using doesn't start with ::, do not add it
{R"cpp(
#include "test.hpp"
using ::one::two::cc;
using one::two::ee;
void fun() {
one::two::f^f();
})cpp",
R"cpp(
#include "test.hpp"
using ::one::two::cc;
using one::two::ff;using one::two::ee;
void fun() {
ff();
})cpp"}};
llvm::StringMap<std::string> EditedFiles;
for (const auto &Case : Cases) {
Expand Down
4 changes: 2 additions & 2 deletions clang/include/clang/Tooling/Syntax/Tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ class Node {
Node *nextSibling() { return NextSibling; }

/// Dumps the structure of a subtree. For debugging and testing purposes.
std::string dump(const Arena &A) const;
std::string dump(const SourceManager &SM) const;
/// Dumps the tokens forming this subtree.
std::string dumpTokens(const Arena &A) const;
std::string dumpTokens(const SourceManager &SM) const;

/// Asserts invariants on this node of the tree and its immediate children.
/// Will not recurse into the subtree. No-op if NDEBUG is set.
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Basic/Targets/X86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
case CK_IcelakeClient:
case CK_IcelakeServer:
case CK_Tigerlake:
case CK_SapphireRapids:
// FIXME: Historically, we defined this legacy name, it would be nice to
// remove it at some point. We've never exposed fine-grained names for
// recent primary x86 CPUs, and we should keep it that way.
Expand Down Expand Up @@ -1269,6 +1270,7 @@ Optional<unsigned> X86TargetInfo::getCPUCacheLineSize() const {
case CK_Cooperlake:
case CK_Cannonlake:
case CK_Tigerlake:
case CK_SapphireRapids:
case CK_IcelakeClient:
case CK_IcelakeServer:
case CK_KNL:
Expand Down
5 changes: 3 additions & 2 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5584,7 +5584,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
LanguageStandard = llvm::StringSwitch<StringRef>(StdArg->getValue())
.Case("c++14", "-std=c++14")
.Case("c++17", "-std=c++17")
.Case("c++latest", "-std=c++2a")
.Case("c++latest", "-std=c++20")
.Default("");
if (LanguageStandard.empty())
D.Diag(clang::diag::warn_drv_unused_argument)
Expand Down Expand Up @@ -5647,7 +5647,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// FIXME: Find a better way to determine whether the language has modules
// support by default, or just assume that all languages do.
bool HaveModules =
Std && (Std->containsValue("c++2a") || Std->containsValue("c++latest"));
Std && (Std->containsValue("c++2a") || Std->containsValue("c++20") ||
Std->containsValue("c++latest"));
RenderModulesOptions(C, D, Args, Input, Output, CmdArgs, HaveModules);

if (Args.hasFlag(options::OPT_fpch_validate_input_files_content,
Expand Down
7 changes: 7 additions & 0 deletions clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2053,6 +2053,13 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(
// typedef (C++ [dcl.typedef]p4).
if (Previous.isSingleTagDecl())
Previous.clear();

// Filter out previous declarations that don't match the scope. The only
// effect this has is to remove declarations found in inline namespaces
// for friend declarations with unqualified names.
SemaRef.FilterLookupForScope(Previous, DC, /*Scope*/ nullptr,
/*ConsiderLinkage*/ true,
QualifierLoc.hasQualifier());
}

SemaRef.CheckFunctionDeclaration(/*Scope*/ nullptr, Function, Previous,
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Tooling/Syntax/BuildTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ class syntax::TreeBuilder {
R += std::string(
formatv("- '{0}' covers '{1}'+{2} tokens\n", It->second->kind(),
It->first->text(A.sourceManager()), CoveredTokens));
R += It->second->dump(A);
R += It->second->dump(A.sourceManager());
}
return R;
}
Expand Down
82 changes: 40 additions & 42 deletions clang/lib/Tooling/Syntax/Tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,46 +133,45 @@ void syntax::Tree::replaceChildRangeLowLevel(Node *BeforeBegin, Node *End,
}

namespace {
static void dumpTokens(raw_ostream &OS, ArrayRef<syntax::Token> Tokens,
const SourceManager &SM) {
assert(!Tokens.empty());
bool First = true;
for (const auto &T : Tokens) {
if (!First)
OS << " ";
else
First = false;
// Handle 'eof' separately, calling text() on it produces an empty string.
if (T.kind() == tok::eof) {
OS << "<eof>";
continue;
}
OS << T.text(SM);
}
static void dumpLeaf(raw_ostream &OS, const syntax::Leaf *L,
const SourceManager &SM) {
assert(L);
const auto *Token = L->token();
assert(Token);
// Handle 'eof' separately, calling text() on it produces an empty string.
if (Token->kind() == tok::eof)
OS << "<eof>";
else
OS << Token->text(SM);
}

static void dumpTree(raw_ostream &OS, const syntax::Node *N,
const syntax::Arena &A, std::vector<bool> IndentMask) {
std::string Marks;
if (!N->isOriginal())
Marks += "M";
if (N->role() == syntax::NodeRole::Detached)
Marks += "*"; // FIXME: find a nice way to print other roles.
if (!N->canModify())
Marks += "I";
if (!Marks.empty())
OS << Marks << ": ";

if (auto *L = dyn_cast<syntax::Leaf>(N)) {
dumpTokens(OS, *L->token(), A.sourceManager());
static void dumpNode(raw_ostream &OS, const syntax::Node *N,
const SourceManager &SM, std::vector<bool> IndentMask) {
auto dumpExtraInfo = [&OS](const syntax::Node *N) {
if (N->role() != syntax::NodeRole::Unknown)
OS << " " << N->role();
if (!N->isOriginal())
OS << " synthesized";
if (!N->canModify())
OS << " unmodifiable";
};

assert(N);
if (const auto *L = dyn_cast<syntax::Leaf>(N)) {
OS << "'";
dumpLeaf(OS, L, SM);
OS << "'";
dumpExtraInfo(N);
OS << "\n";
return;
}

auto *T = cast<syntax::Tree>(N);
OS << T->kind() << "\n";
const auto *T = cast<syntax::Tree>(N);
OS << T->kind();
dumpExtraInfo(N);
OS << "\n";

for (auto It = T->firstChild(); It != nullptr; It = It->nextSibling()) {
for (const auto *It = T->firstChild(); It; It = It->nextSibling()) {
for (bool Filled : IndentMask) {
if (Filled)
OS << "| ";
Expand All @@ -186,28 +185,27 @@ static void dumpTree(raw_ostream &OS, const syntax::Node *N,
OS << "|-";
IndentMask.push_back(true);
}
dumpTree(OS, It, A, IndentMask);
dumpNode(OS, It, SM, IndentMask);
IndentMask.pop_back();
}
}
} // namespace

std::string syntax::Node::dump(const Arena &A) const {
std::string syntax::Node::dump(const SourceManager &SM) const {
std::string Str;
llvm::raw_string_ostream OS(Str);
dumpTree(OS, this, A, /*IndentMask=*/{});
dumpNode(OS, this, SM, /*IndentMask=*/{});
return std::move(OS.str());
}

std::string syntax::Node::dumpTokens(const Arena &A) const {
std::string syntax::Node::dumpTokens(const SourceManager &SM) const {
std::string Storage;
llvm::raw_string_ostream OS(Storage);
traverse(this, [&](const syntax::Node *N) {
auto *L = dyn_cast<syntax::Leaf>(N);
if (!L)
return;
::dumpTokens(OS, *L->token(), A.sourceManager());
OS << " ";
if (const auto *L = dyn_cast<syntax::Leaf>(N)) {
dumpLeaf(OS, L, SM);
OS << " ";
}
});
return OS.str();
}
Expand Down
3 changes: 3 additions & 0 deletions clang/test/CodeGen/attr-target-mv.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ int __attribute__((target("arch=icelake-client"))) foo(void) {return 6;}
int __attribute__((target("arch=icelake-server"))) foo(void) {return 7;}
int __attribute__((target("arch=cooperlake"))) foo(void) {return 8;}
int __attribute__((target("arch=tigerlake"))) foo(void) {return 9;}
int __attribute__((target("arch=sapphirerapids"))) foo(void) {return 10;}
int __attribute__((target("default"))) foo(void) { return 2; }

int bar() {
Expand Down Expand Up @@ -91,6 +92,8 @@ __attribute__((target("avx,sse4.2"), used)) inline void foo_used2(int i, double
// LINUX: ret i32 8
// LINUX: define i32 @foo.arch_tigerlake()
// LINUX: ret i32 9
// LINUX: define i32 @foo.arch_sapphirerapids()
// LINUX: ret i32 10
// LINUX: define i32 @foo()
// LINUX: ret i32 2
// LINUX: define i32 @bar()
Expand Down
1 change: 1 addition & 0 deletions clang/test/CodeGen/target-builtin-noerror.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ void verifycpustrings() {
(void)__builtin_cpu_is("skylake-avx512");
(void)__builtin_cpu_is("slm");
(void)__builtin_cpu_is("tigerlake");
(void)__builtin_cpu_is("sapphirerapids");
(void)__builtin_cpu_is("tremont");
(void)__builtin_cpu_is("westmere");
(void)__builtin_cpu_is("znver1");
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/cl-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@
// STDCXX17: -std=c++17

// RUN: %clang_cl -fmsc-version=1900 -TP -std:c++latest -### -- %s 2>&1 | FileCheck -check-prefix=STDCXXLATEST %s
// STDCXXLATEST: -std=c++2a
// STDCXXLATEST: -std=c++20

// RUN: env CL="/Gy" %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=ENV-CL %s
// ENV-CL: "-ffunction-sections"
Expand Down
1 change: 1 addition & 0 deletions clang/test/Driver/modules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
// Check use of a .pcm file in another compilation.
//
// RUN: %clang -std=c++2a -fmodule-file=%t/module.pcm -Dexport= %s -S -o %t/module.o -v 2>&1 | FileCheck %s --check-prefix=CHECK-USE
// RUN: %clang -std=c++20 -fmodule-file=%t/module.pcm -Dexport= %s -S -o %t/module.o -v 2>&1 | FileCheck %s --check-prefix=CHECK-USE
//
// CHECK-USE: -cc1
// CHECK-USE-SAME: {{-emit-obj|-S}}
Expand Down
4 changes: 4 additions & 0 deletions clang/test/Driver/x86-march.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@
// RUN: | FileCheck %s -check-prefix=tremont
// tremont: "-target-cpu" "tremont"
//
// RUN: %clang -target x86_64-unknown-unknown -c -### %s -march=sapphirerapids 2>&1 \
// RUN: | FileCheck %s -check-prefix=sapphirerapids
// sapphirerapids: "-target-cpu" "sapphirerapids"
//
// RUN: %clang -target x86_64-unknown-unknown -c -### %s -march=k8 2>&1 \
// RUN: | FileCheck %s -check-prefix=k8
// k8: "-target-cpu" "k8"
Expand Down
8 changes: 4 additions & 4 deletions clang/test/Misc/target-invalid-cpu-note.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// X86-SAME: nocona, core2, penryn, bonnell, atom, silvermont, slm, goldmont, goldmont-plus, tremont,
// X86-SAME: nehalem, corei7, westmere, sandybridge, corei7-avx, ivybridge,
// X86-SAME: core-avx-i, haswell, core-avx2, broadwell, skylake, skylake-avx512,
// X86-SAME: skx, cascadelake, cooperlake, cannonlake, icelake-client, icelake-server, tigerlake, knl, knm, lakemont, k6, k6-2, k6-3,
// X86-SAME: skx, cascadelake, cooperlake, cannonlake, icelake-client, icelake-server, tigerlake, sapphirerapids, knl, knm, lakemont, k6, k6-2, k6-3,
// X86-SAME: athlon, athlon-tbird, athlon-xp, athlon-mp, athlon-4, k8, athlon64,
// X86-SAME: athlon-fx, opteron, k8-sse3, athlon64-sse3, opteron-sse3, amdfam10,
// X86-SAME: barcelona, btver1, btver2, bdver1, bdver2, bdver3, bdver4, znver1, znver2,
Expand All @@ -33,7 +33,7 @@
// X86_64-SAME: atom, silvermont, slm, goldmont, goldmont-plus, tremont, nehalem, corei7, westmere,
// X86_64-SAME: sandybridge, corei7-avx, ivybridge, core-avx-i, haswell,
// X86_64-SAME: core-avx2, broadwell, skylake, skylake-avx512, skx, cascadelake, cooperlake, cannonlake,
// X86_64-SAME: icelake-client, icelake-server, tigerlake, knl, knm, k8, athlon64, athlon-fx, opteron, k8-sse3,
// X86_64-SAME: icelake-client, icelake-server, tigerlake, sapphirerapids, knl, knm, k8, athlon64, athlon-fx, opteron, k8-sse3,
// X86_64-SAME: athlon64-sse3, opteron-sse3, amdfam10, barcelona, btver1,
// X86_64-SAME: btver2, bdver1, bdver2, bdver3, bdver4, znver1, znver2, x86-64

Expand All @@ -45,7 +45,7 @@
// TUNE_X86-SAME: nocona, core2, penryn, bonnell, atom, silvermont, slm, goldmont, goldmont-plus, tremont,
// TUNE_X86-SAME: nehalem, corei7, westmere, sandybridge, corei7-avx, ivybridge,
// TUNE_X86-SAME: core-avx-i, haswell, core-avx2, broadwell, skylake, skylake-avx512,
// TUNE_X86-SAME: skx, cascadelake, cooperlake, cannonlake, icelake-client, icelake-server, tigerlake, knl, knm, lakemont, k6, k6-2, k6-3,
// TUNE_X86-SAME: skx, cascadelake, cooperlake, cannonlake, icelake-client, icelake-server, tigerlake, sapphirerapids, knl, knm, lakemont, k6, k6-2, k6-3,
// TUNE_X86-SAME: athlon, athlon-tbird, athlon-xp, athlon-mp, athlon-4, k8, athlon64,
// TUNE_X86-SAME: athlon-fx, opteron, k8-sse3, athlon64-sse3, opteron-sse3, amdfam10,
// TUNE_X86-SAME: barcelona, btver1, btver2, bdver1, bdver2, bdver3, bdver4, znver1, znver2,
Expand All @@ -59,7 +59,7 @@
// TUNE_X86_64-SAME: nocona, core2, penryn, bonnell, atom, silvermont, slm, goldmont, goldmont-plus, tremont,
// TUNE_X86_64-SAME: nehalem, corei7, westmere, sandybridge, corei7-avx, ivybridge,
// TUNE_X86_64-SAME: core-avx-i, haswell, core-avx2, broadwell, skylake, skylake-avx512,
// TUNE_X86_64-SAME: skx, cascadelake, cooperlake, cannonlake, icelake-client, icelake-server, tigerlake, knl, knm, lakemont, k6, k6-2, k6-3,
// TUNE_X86_64-SAME: skx, cascadelake, cooperlake, cannonlake, icelake-client, icelake-server, tigerlake, sapphirerapids, knl, knm, lakemont, k6, k6-2, k6-3,
// TUNE_X86_64-SAME: athlon, athlon-tbird, athlon-xp, athlon-mp, athlon-4, k8, athlon64,
// TUNE_X86_64-SAME: athlon-fx, opteron, k8-sse3, athlon64-sse3, opteron-sse3, amdfam10,
// TUNE_X86_64-SAME: barcelona, btver1, btver2, bdver1, bdver2, bdver3, bdver4, znver1, znver2,
Expand Down
Loading

0 comments on commit 43b9ac8

Please sign in to comment.