Skip to content

Commit

Permalink
LLVM and SPIRV-LLVM-Translator pulldown (WW01)
Browse files Browse the repository at this point in the history
  • Loading branch information
bb-sycl committed Jan 5, 2024
2 parents b9854a1 + d28865a commit fbbae18
Show file tree
Hide file tree
Showing 1,495 changed files with 73,951 additions and 31,035 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Github action workflows should be stored in this directrory.
Github action workflows should be stored in this directory.
1 change: 0 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,3 @@ jobs:
run: |
cmake -B flang-build -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;mlir;flang" -DLLVM_ENABLE_SPHINX=ON -DSPHINX_WARNINGS_AS_ERRORS=OFF ./llvm
TZ=UTC ninja -C flang-build docs-flang-html docs-flang-man
1 change: 0 additions & 1 deletion .github/workflows/libcxx-build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,3 @@ jobs:
**/CMakeError.log
**/CMakeOutput.log
**/crash_diagnostics/*
4 changes: 2 additions & 2 deletions clang-tools-extra/clangd/Hover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ void maybeAddSymbolProviders(ParsedAST &AST, HoverInfo &HI,

const SourceManager &SM = AST.getSourceManager();
llvm::SmallVector<include_cleaner::Header> RankedProviders =
include_cleaner::headersForSymbol(Sym, SM, AST.getPragmaIncludes().get());
include_cleaner::headersForSymbol(Sym, SM, &AST.getPragmaIncludes());
if (RankedProviders.empty())
return;

Expand Down Expand Up @@ -1254,7 +1254,7 @@ void maybeAddUsedSymbols(ParsedAST &AST, HoverInfo &HI, const Inclusion &Inc) {
llvm::DenseSet<include_cleaner::Symbol> UsedSymbols;
include_cleaner::walkUsed(
AST.getLocalTopLevelDecls(), collectMacroReferences(AST),
AST.getPragmaIncludes().get(), AST.getPreprocessor(),
&AST.getPragmaIncludes(), AST.getPreprocessor(),
[&](const include_cleaner::SymbolReference &Ref,
llvm::ArrayRef<include_cleaner::Header> Providers) {
if (Ref.RT != include_cleaner::RefType::Explicit ||
Expand Down
36 changes: 3 additions & 33 deletions clang-tools-extra/clangd/IncludeCleaner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#include <cassert>
#include <iterator>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <utility>
Expand Down Expand Up @@ -237,18 +236,6 @@ removeAllUnusedIncludes(llvm::ArrayRef<Diag> UnusedIncludes) {
Diag.Fixes.front().Edits.begin(),
Diag.Fixes.front().Edits.end());
}

// TODO(hokein): emit a suitable text for the label.
ChangeAnnotation Annotation = {/*label=*/"",
/*needsConfirmation=*/true,
/*description=*/""};
static const ChangeAnnotationIdentifier RemoveAllUnusedID =
"RemoveAllUnusedIncludes";
for (unsigned I = 0; I < RemoveAll.Edits.size(); ++I) {
ChangeAnnotationIdentifier ID = RemoveAllUnusedID + std::to_string(I);
RemoveAll.Edits[I].annotationId = ID;
RemoveAll.Annotations.push_back({ID, Annotation});
}
return RemoveAll;
}

Expand All @@ -268,20 +255,8 @@ addAllMissingIncludes(llvm::ArrayRef<Diag> MissingIncludeDiags) {
Edits.try_emplace(Edit.newText, Edit);
}
}
// FIXME(hokein): emit used symbol reference in the annotation.
ChangeAnnotation Annotation = {/*label=*/"",
/*needsConfirmation=*/true,
/*description=*/""};
static const ChangeAnnotationIdentifier AddAllMissingID =
"AddAllMissingIncludes";
unsigned I = 0;
for (auto &It : Edits) {
ChangeAnnotationIdentifier ID = AddAllMissingID + std::to_string(I++);
for (auto &It : Edits)
AddAllMissing.Edits.push_back(std::move(It.second));
AddAllMissing.Edits.back().annotationId = ID;

AddAllMissing.Annotations.push_back({ID, Annotation});
}
return AddAllMissing;
}
Fix fixAll(const Fix &RemoveAllUnused, const Fix &AddAllMissing) {
Expand All @@ -292,11 +267,6 @@ Fix fixAll(const Fix &RemoveAllUnused, const Fix &AddAllMissing) {
FixAll.Edits.push_back(F);
for (const auto &F : AddAllMissing.Edits)
FixAll.Edits.push_back(F);

for (const auto &A : RemoveAllUnused.Annotations)
FixAll.Annotations.push_back(A);
for (const auto &A : AddAllMissing.Annotations)
FixAll.Annotations.push_back(A);
return FixAll;
}

Expand All @@ -311,7 +281,7 @@ getUnused(ParsedAST &AST,
auto IncludeID = static_cast<IncludeStructure::HeaderID>(*MFI.HeaderID);
if (ReferencedFiles.contains(IncludeID))
continue;
if (!mayConsiderUnused(MFI, AST, AST.getPragmaIncludes().get())) {
if (!mayConsiderUnused(MFI, AST, &AST.getPragmaIncludes())) {
dlog("{0} was not used, but is not eligible to be diagnosed as unused",
MFI.Written);
continue;
Expand Down Expand Up @@ -403,7 +373,7 @@ IncludeCleanerFindings computeIncludeCleanerFindings(ParsedAST &AST) {
.getBuiltinDir();
include_cleaner::walkUsed(
AST.getLocalTopLevelDecls(), /*MacroRefs=*/Macros,
AST.getPragmaIncludes().get(), AST.getPreprocessor(),
&AST.getPragmaIncludes(), AST.getPreprocessor(),
[&](const include_cleaner::SymbolReference &Ref,
llvm::ArrayRef<include_cleaner::Header> Providers) {
bool Satisfied = false;
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/InlayHints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ std::string summarizeExpr(const Expr *E) {
// Step through implicit nodes that clang doesn't classify as such.
std::string VisitCXXMemberCallExpr(const CXXMemberCallExpr *E) {
// Call to operator bool() inside if (X): dispatch to X.
if (E->getNumArgs() == 0 &&
if (E->getNumArgs() == 0 && E->getMethodDecl() &&
E->getMethodDecl()->getDeclName().getNameKind() ==
DeclarationName::CXXConversionFunctionName &&
E->getSourceRange() ==
Expand Down
21 changes: 12 additions & 9 deletions clang-tools-extra/clangd/ParsedAST.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,18 +653,23 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
}

IncludeStructure Includes;
include_cleaner::PragmaIncludes PI;
// If we are using a preamble, copy existing includes.
if (Preamble) {
Includes = Preamble->Includes;
Includes.MainFileIncludes = Patch->preambleIncludes();
// Replay the preamble includes so that clang-tidy checks can see them.
ReplayPreamble::attach(Patch->preambleIncludes(), *Clang,
Patch->modifiedBounds());
PI = *Preamble->Pragmas;
}
// Important: collectIncludeStructure is registered *after* ReplayPreamble!
// Otherwise we would collect the replayed includes again...
// (We can't *just* use the replayed includes, they don't have Resolved path).
Includes.collect(*Clang);
// Same for pragma-includes, we're already inheriting preamble includes, so we
// should only receive callbacks for non-preamble mainfile includes.
PI.record(*Clang);
// Copy over the macros in the preamble region of the main file, and combine
// with non-preamble macros below.
MainFileMacros Macros;
Expand Down Expand Up @@ -735,7 +740,7 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
ParsedAST Result(Filename, Inputs.Version, std::move(Preamble),
std::move(Clang), std::move(Action), std::move(Tokens),
std::move(Macros), std::move(Marks), std::move(ParsedDecls),
std::move(Diags), std::move(Includes));
std::move(Diags), std::move(Includes), std::move(PI));
llvm::move(getIncludeCleanerDiags(Result, Inputs.Contents),
std::back_inserter(Result.Diags));
return std::move(Result);
Expand Down Expand Up @@ -828,23 +833,21 @@ ParsedAST::ParsedAST(PathRef TUPath, llvm::StringRef Version,
syntax::TokenBuffer Tokens, MainFileMacros Macros,
std::vector<PragmaMark> Marks,
std::vector<Decl *> LocalTopLevelDecls,
std::vector<Diag> Diags, IncludeStructure Includes)
std::vector<Diag> Diags, IncludeStructure Includes,
include_cleaner::PragmaIncludes PI)
: TUPath(TUPath), Version(Version), Preamble(std::move(Preamble)),
Clang(std::move(Clang)), Action(std::move(Action)),
Tokens(std::move(Tokens)), Macros(std::move(Macros)),
Marks(std::move(Marks)), Diags(std::move(Diags)),
LocalTopLevelDecls(std::move(LocalTopLevelDecls)),
Includes(std::move(Includes)) {
Resolver = std::make_unique<HeuristicResolver>(getASTContext());
Includes(std::move(Includes)), PI(std::move(PI)),
Resolver(std::make_unique<HeuristicResolver>(getASTContext())) {
assert(this->Clang);
assert(this->Action);
}

std::shared_ptr<const include_cleaner::PragmaIncludes>
ParsedAST::getPragmaIncludes() const {
if (!Preamble)
return nullptr;
return Preamble->Pragmas;
const include_cleaner::PragmaIncludes &ParsedAST::getPragmaIncludes() const {
return PI;
}

std::optional<llvm::StringRef> ParsedAST::preambleVersion() const {
Expand Down
9 changes: 4 additions & 5 deletions clang-tools-extra/clangd/ParsedAST.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,8 @@ class ParsedAST {
/// Tokens recorded while parsing the main file.
/// (!) does not have tokens from the preamble.
const syntax::TokenBuffer &getTokens() const { return Tokens; }
/// Returns the PramaIncludes from the preamble.
/// Might be null if AST is built without a preamble.
std::shared_ptr<const include_cleaner::PragmaIncludes>
getPragmaIncludes() const;
/// Returns the PramaIncludes for preamble + main file includes.
const include_cleaner::PragmaIncludes &getPragmaIncludes() const;

/// Returns the version of the ParseInputs this AST was built from.
llvm::StringRef version() const { return Version; }
Expand All @@ -129,7 +127,7 @@ class ParsedAST {
std::unique_ptr<FrontendAction> Action, syntax::TokenBuffer Tokens,
MainFileMacros Macros, std::vector<PragmaMark> Marks,
std::vector<Decl *> LocalTopLevelDecls, std::vector<Diag> Diags,
IncludeStructure Includes);
IncludeStructure Includes, include_cleaner::PragmaIncludes PI);
Path TUPath;
std::string Version;
// In-memory preambles must outlive the AST, it is important that this member
Expand Down Expand Up @@ -159,6 +157,7 @@ class ParsedAST {
// top-level decls from the preamble.
std::vector<Decl *> LocalTopLevelDecls;
IncludeStructure Includes;
include_cleaner::PragmaIncludes PI;
std::unique_ptr<HeuristicResolver> Resolver;
};

Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/XRefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,7 @@ maybeFindIncludeReferences(ParsedAST &AST, Position Pos,
auto Converted = convertIncludes(AST);
include_cleaner::walkUsed(
AST.getLocalTopLevelDecls(), collectMacroReferences(AST),
AST.getPragmaIncludes().get(), AST.getPreprocessor(),
&AST.getPragmaIncludes(), AST.getPreprocessor(),
[&](const include_cleaner::SymbolReference &Ref,
llvm::ArrayRef<include_cleaner::Header> Providers) {
if (Ref.RT != include_cleaner::RefType::Explicit ||
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clangd/index/FileIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ FileShardedIndex::getShard(llvm::StringRef Uri) const {
SlabTuple indexMainDecls(ParsedAST &AST) {
return indexSymbols(
AST.getASTContext(), AST.getPreprocessor(), AST.getLocalTopLevelDecls(),
&AST.getMacros(), *AST.getPragmaIncludes(),
&AST.getMacros(), AST.getPragmaIncludes(),
/*IsIndexMainAST=*/true, AST.version(), /*CollectMainFileRefs=*/true);
}

Expand Down
8 changes: 4 additions & 4 deletions clang-tools-extra/clangd/index/SymbolCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,8 @@ void SymbolCollector::setIncludeLocation(const Symbol &S, SourceLocation DefLoc,

// Use the expansion location to get the #include header since this is
// where the symbol is exposed.
IncludeFiles[S.ID] = SM.getDecomposedExpansionLoc(DefLoc).first;
if (FileID FID = SM.getDecomposedExpansionLoc(DefLoc).first; FID.isValid())
IncludeFiles[S.ID] = FID;

// We update providers for a symbol with each occurence, as SymbolCollector
// might run while parsing, rather than at the end of a translation unit.
Expand Down Expand Up @@ -879,16 +880,15 @@ void SymbolCollector::finish() {
const Symbol *S = Symbols.find(SID);
if (!S)
continue;
assert(IncludeFiles.contains(SID));

const auto FID = IncludeFiles.at(SID);
FileID FID = IncludeFiles.lookup(SID);
// Determine if the FID is #include'd or #import'ed.
Symbol::IncludeDirective Directives = Symbol::Invalid;
auto CollectDirectives = shouldCollectIncludePath(S->SymInfo.Kind);
if ((CollectDirectives & Symbol::Include) != 0)
Directives |= Symbol::Include;
// Only allow #import for symbols from ObjC-like files.
if ((CollectDirectives & Symbol::Import) != 0) {
if ((CollectDirectives & Symbol::Import) != 0 && FID.isValid()) {
auto [It, Inserted] = FileToContainsImportsOrObjC.try_emplace(FID);
if (Inserted)
It->second = FilesWithObjCConstructs.contains(FID) ||
Expand Down
15 changes: 15 additions & 0 deletions clang-tools-extra/clangd/test/GH75115.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: rm -rf %t.dir && mkdir -p %t.dir
// RUN: echo '[{"directory": "%/t.dir", "command": "clang --target=x86_64-pc-windows-msvc -x c GH75115.test", "file": "GH75115.test"}]' > %t.dir/compile_commands.json
// RUN: clangd -enable-config=0 --compile-commands-dir=%t.dir -check=%s 2>&1 | FileCheck -strict-whitespace %s

// CHECK: Building preamble...
// CHECK-NEXT: Built preamble
// CHECK-NEXT: Indexing headers...
// CHECK-NEXT: Building AST...
// CHECK-NEXT: Indexing AST...
// CHECK-NEXT: Building inlay hints
// CHECK-NEXT: semantic highlighting
// CHECK-NEXT: Testing features at each token
// CHECK-NEXT: All checks completed, 0 errors

#define assert
Loading

0 comments on commit fbbae18

Please sign in to comment.