Skip to content

Commit

Permalink
LLVM and SPIRV-LLVM-Translator pulldown (WW45)
Browse files Browse the repository at this point in the history
  • Loading branch information
bb-sycl committed Nov 2, 2021
2 parents 53ea8b9 + 4281da1 commit 1d8ceba
Show file tree
Hide file tree
Showing 2,382 changed files with 102,149 additions and 58,109 deletions.
1 change: 1 addition & 0 deletions .github/workflows/repo-lockdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ permissions:
jobs:
action:
runs-on: ubuntu-latest
if: github.repository == 'llvm/llvm-project'
steps:
- uses: dessant/repo-lockdown@v2
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static const std::string DefaultIgnoredParameterTypeSuffixes =
"inputit",
"InputIt",
"forwardit",
"FowardIt",
"ForwardIt",
"bidirit",
"BidirIt",
"constiterator",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void ForwardDeclarationNamespaceCheck::onEndOfTranslationUnit() {
if (CurDecl->hasDefinition() || CurDecl->isReferenced()) {
continue; // Skip forward declarations that are used/referenced.
}
if (FriendTypes.count(CurDecl->getTypeForDecl()) != 0) {
if (FriendTypes.contains(CurDecl->getTypeForDecl())) {
continue; // Skip forward declarations referenced as friend.
}
if (CurDecl->getLocation().isMacroID() ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ computeInsertions(const CXXConstructorDecl::init_const_range &Inits,
// Add all fields between current field up until the next initializer.
for (; Decl != std::end(OrderedDecls) && *Decl != InitDecl; ++Decl) {
if (const auto *D = dyn_cast<T>(*Decl)) {
if (DeclsToInit.count(D) > 0)
if (DeclsToInit.contains(D))
Insertions.back().Initializers.emplace_back(getName(D));
}
}
Expand All @@ -221,7 +221,7 @@ computeInsertions(const CXXConstructorDecl::init_const_range &Inits,
// Add remaining decls that require initialization.
for (; Decl != std::end(OrderedDecls); ++Decl) {
if (const auto *D = dyn_cast<T>(*Decl)) {
if (DeclsToInit.count(D) > 0)
if (DeclsToInit.contains(D))
Insertions.back().Initializers.emplace_back(getName(D));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void UnusedUsingDeclsCheck::removeFromFoundDecls(const Decl *D) {
//
// FIXME: Use a more efficient way to find a matching context.
for (auto &Context : Contexts) {
if (Context.UsingTargetDecls.count(D->getCanonicalDecl()) > 0)
if (Context.UsingTargetDecls.contains(D->getCanonicalDecl()))
Context.IsUsed = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ AST_MATCHER_FUNCTION_P(StatementMatcher, isConstRefReturningMethodCall,
// returned either points to a global static variable or to a member of the
// called object.
return cxxMemberCallExpr(
callee(cxxMethodDecl(returns(matchers::isReferenceToConst()))
callee(cxxMethodDecl(
returns(hasCanonicalType(matchers::isReferenceToConst())))
.bind(MethodDeclId)),
on(declRefExpr(to(
varDecl(
Expand All @@ -97,7 +98,8 @@ AST_MATCHER_FUNCTION(StatementMatcher, isConstRefReturningFunctionCall) {
// Only allow initialization of a const reference from a free function if it
// has no arguments. Otherwise it could return an alias to one of its
// arguments and the arguments need to be checked for const use as well.
return callExpr(callee(functionDecl(returns(matchers::isReferenceToConst()))
return callExpr(callee(functionDecl(returns(hasCanonicalType(
matchers::isReferenceToConst())))
.bind(FunctionDeclId)),
argumentCountIs(0), unless(callee(cxxMethodDecl())))
.bind(InitFunctionCallId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ void InconsistentDeclarationParameterNameCheck::check(
const auto *OriginalDeclaration =
Result.Nodes.getNodeAs<FunctionDecl>("functionDecl");

if (VisitedDeclarations.count(OriginalDeclaration) > 0)
if (VisitedDeclarations.contains(OriginalDeclaration))
return; // Avoid multiple warnings.

const FunctionDecl *ParameterSourceDeclaration =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "StaticAccessedThroughInstanceCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "llvm/ADT/StringRef.h"

using namespace clang::ast_matchers;

Expand Down Expand Up @@ -54,7 +55,7 @@ void StaticAccessedThroughInstanceCheck::check(

const Expr *BaseExpr = MemberExpression->getBase();

// Do not warn for overlaoded -> operators.
// Do not warn for overloaded -> operators.
if (isa<CXXOperatorCallExpr>(BaseExpr))
return;

Expand All @@ -70,6 +71,10 @@ void StaticAccessedThroughInstanceCheck::check(
std::string BaseTypeName =
BaseType.getAsString(PrintingPolicyWithSupressedTag);

// Do not warn for CUDA built-in variables.
if (StringRef(BaseTypeName).startswith("__cuda_builtin_"))
return;

SourceLocation MemberExprStartLoc = MemberExpression->getBeginLoc();
auto Diag =
diag(MemberExprStartLoc, "static member accessed through instance");
Expand Down
6 changes: 5 additions & 1 deletion clang-tools-extra/clangd/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ void IgnoreDiagnostics::HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
IgnoreDiagnostics::log(DiagLevel, Info);
}

static bool AllowCrashPragmasForTest = false;
void allowCrashPragmasForTest() { AllowCrashPragmasForTest = true; }

void disableUnsupportedOptions(CompilerInvocation &CI) {
// Disable "clang -verify" diagnostics, they are rarely useful in clangd, and
// our compiler invocation set-up doesn't seem to work with it (leading
Expand All @@ -66,7 +69,8 @@ void disableUnsupportedOptions(CompilerInvocation &CI) {
CI.getPreprocessorOpts().PCHWithHdrStop = false;
CI.getPreprocessorOpts().PCHWithHdrStopCreate = false;
// Don't crash on `#pragma clang __debug parser_crash`
CI.getPreprocessorOpts().DisablePragmaDebugCrash = true;
if (!AllowCrashPragmasForTest)
CI.getPreprocessorOpts().DisablePragmaDebugCrash = true;

// Always default to raw container format as clangd doesn't registry any other
// and clang dies when faced with unknown formats.
Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/clangd/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ std::unique_ptr<CompilerInstance> prepareCompilerInstance(
std::unique_ptr<llvm::MemoryBuffer> MainFile,
IntrusiveRefCntPtr<llvm::vfs::FileSystem>, DiagnosticConsumer &);

/// Respect `#pragma clang __debug crash` etc, which are usually disabled.
/// This may only be called before threads are spawned.
void allowCrashPragmasForTest();

} // namespace clangd
} // namespace clang

Expand Down
3 changes: 3 additions & 0 deletions clang-tools-extra/clangd/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ struct Config {
ExternalIndexSpec External;
} Index;

enum UnusedIncludesPolicy { Strict, None };
/// Controls warnings and errors when parsing code.
struct {
bool SuppressAll = false;
Expand All @@ -97,6 +98,8 @@ struct Config {
std::string Checks;
llvm::StringMap<std::string> CheckOptions;
} ClangTidy;

UnusedIncludesPolicy UnusedIncludes = None;
} Diagnostics;

/// Style of the codebase.
Expand Down
10 changes: 10 additions & 0 deletions clang-tools-extra/clangd/ConfigCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,16 @@ struct FragmentCompiler {
C.Diagnostics.Suppress.insert(N);
});

if (F.UnusedIncludes)
if (auto Val = compileEnum<Config::UnusedIncludesPolicy>(
"UnusedIncludes", **F.UnusedIncludes)
.map("Strict", Config::UnusedIncludesPolicy::Strict)
.map("None", Config::UnusedIncludesPolicy::None)
.value())
Out.Apply.push_back([Val](const Params &, Config &C) {
C.Diagnostics.UnusedIncludes = *Val;
});

compile(std::move(F.ClangTidy));
}

Expand Down
14 changes: 14 additions & 0 deletions clang-tools-extra/clangd/ConfigFragment.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,20 @@ struct Fragment {
/// This often has other advantages, such as skipping some analysis.
std::vector<Located<std::string>> Suppress;

/// Controls how clangd will correct "unnecessary #include directives.
/// clangd can warn if a header is `#include`d but not used, and suggest
/// removing it.
//
/// Strict means a header is unused if it does not *directly* provide any
/// symbol used in the file. Removing it may still break compilation if it
/// transitively includes headers that are used. This should be fixed by
/// including those headers directly.
///
/// Valid values are:
/// - Strict
/// - None
llvm::Optional<Located<std::string>> UnusedIncludes;

/// Controls how clang-tidy will run over the code base.
///
/// The settings are merged with any settings found in .clang-tidy
Expand Down
3 changes: 3 additions & 0 deletions clang-tools-extra/clangd/ConfigYAML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ class Parser {
if (auto Values = scalarValues(N))
F.Suppress = std::move(*Values);
});
Dict.handle("UnusedIncludes", [&](Node &N) {
F.UnusedIncludes = scalarValue(N, "UnusedIncludes");
});
Dict.handle("ClangTidy", [&](Node &N) { parse(F.ClangTidy, N); });
Dict.parse(N);
}
Expand Down
3 changes: 3 additions & 0 deletions clang-tools-extra/clangd/Diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,9 @@ void toLSPDiags(
case Diag::ClangTidy:
Main.source = "clang-tidy";
break;
case Diag::Clangd:
Main.source = "clangd";
break;
case Diag::ClangdConfig:
Main.source = "clangd-config";
break;
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clangd/Diagnostics.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ struct Diag : DiagBase {
Unknown,
Clang,
ClangTidy,
Clangd,
ClangdConfig,
} Source = Unknown;
/// Elaborate on the problem, usually pointing to a related piece of code.
Expand Down
30 changes: 18 additions & 12 deletions clang-tools-extra/clangd/Hover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,24 +262,30 @@ const FunctionDecl *getUnderlyingFunction(const Decl *D) {
// Returns the decl that should be used for querying comments, either from index
// or AST.
const NamedDecl *getDeclForComment(const NamedDecl *D) {
const NamedDecl *DeclForComment = D;
if (const auto *TSD = llvm::dyn_cast<ClassTemplateSpecializationDecl>(D)) {
// Template may not be instantiated e.g. if the type didn't need to be
// complete; fallback to primary template.
if (TSD->getTemplateSpecializationKind() == TSK_Undeclared)
return TSD->getSpecializedTemplate();
if (const auto *TIP = TSD->getTemplateInstantiationPattern())
return TIP;
}
if (const auto *TSD = llvm::dyn_cast<VarTemplateSpecializationDecl>(D)) {
DeclForComment = TSD->getSpecializedTemplate();
else if (const auto *TIP = TSD->getTemplateInstantiationPattern())
DeclForComment = TIP;
} else if (const auto *TSD =
llvm::dyn_cast<VarTemplateSpecializationDecl>(D)) {
if (TSD->getTemplateSpecializationKind() == TSK_Undeclared)
return TSD->getSpecializedTemplate();
if (const auto *TIP = TSD->getTemplateInstantiationPattern())
return TIP;
}
if (const auto *FD = D->getAsFunction())
DeclForComment = TSD->getSpecializedTemplate();
else if (const auto *TIP = TSD->getTemplateInstantiationPattern())
DeclForComment = TIP;
} else if (const auto *FD = D->getAsFunction())
if (const auto *TIP = FD->getTemplateInstantiationPattern())
return TIP;
return D;
DeclForComment = TIP;
// Ensure that getDeclForComment(getDeclForComment(X)) = getDeclForComment(X).
// This is usually not needed, but in strange cases of comparision operators
// being instantiated from spasceship operater, which itself is a template
// instantiation the recursrive call is necessary.
if (D != DeclForComment)
DeclForComment = getDeclForComment(DeclForComment);
return DeclForComment;
}

// Look up information about D from the index, and add it to Hover.
Expand Down
Loading

0 comments on commit 1d8ceba

Please sign in to comment.