Skip to content

Commit

Permalink
LLVM and SPIRV-LLVM-Translator pulldown (WW48)
Browse files Browse the repository at this point in the history
  • Loading branch information
bb-sycl committed Nov 26, 2021
2 parents 6266820 + 2843e15 commit 3b80fcc
Show file tree
Hide file tree
Showing 1,631 changed files with 69,548 additions and 31,973 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,19 @@ AST_MATCHER_FUNCTION_P(StatementMatcher, isConstRefReturningMethodCall,
// variable being declared. The assumption is that the const reference being
// returned either points to a global static variable or to a member of the
// called object.
return cxxMemberCallExpr(
callee(cxxMethodDecl(
returns(hasCanonicalType(matchers::isReferenceToConst())))
.bind(MethodDeclId)),
on(declRefExpr(to(
varDecl(
unless(hasType(qualType(hasCanonicalType(hasDeclaration(namedDecl(
matchers::matchesAnyListedName(ExcludedContainerTypes))))))))
.bind(ObjectArgId)))));
const auto MethodDecl =
cxxMethodDecl(returns(hasCanonicalType(matchers::isReferenceToConst())))
.bind(MethodDeclId);
const auto ReceiverExpr = declRefExpr(to(varDecl().bind(ObjectArgId)));
const auto ReceiverType =
hasCanonicalType(recordType(hasDeclaration(namedDecl(
unless(matchers::matchesAnyListedName(ExcludedContainerTypes))))));

return expr(anyOf(
cxxMemberCallExpr(callee(MethodDecl), on(ReceiverExpr),
thisPointerType(ReceiverType)),
cxxOperatorCallExpr(callee(MethodDecl), hasArgument(0, ReceiverExpr),
hasArgument(0, hasType(ReceiverType)))));
}

AST_MATCHER_FUNCTION(StatementMatcher, isConstRefReturningFunctionCall) {
Expand Down
5 changes: 4 additions & 1 deletion clang-tools-extra/clangd/ClangdLSPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,6 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
Server.emplace(*CDB, TFS, Opts,
static_cast<ClangdServer::Callbacks *>(this));
}
applyConfiguration(Params.initializationOptions.ConfigSettings);

Opts.CodeComplete.EnableSnippets = Params.capabilities.CompletionSnippets;
Opts.CodeComplete.IncludeFixIts = Params.capabilities.CompletionFixes;
Expand Down Expand Up @@ -627,6 +626,10 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
if (Opts.Encoding)
Result["offsetEncoding"] = *Opts.Encoding;
Reply(std::move(Result));

// Apply settings after we're fully initialized.
// This can start background indexing and in turn trigger LSP notifications.
applyConfiguration(Params.initializationOptions.ConfigSettings);
}

void ClangdLSPServer::onInitialized(const InitializedParams &Params) {}
Expand Down
8 changes: 8 additions & 0 deletions clang-tools-extra/clangd/IncludeCleaner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "SourceCode.h"
#include "support/Logger.h"
#include "support/Trace.h"
#include "clang/AST/ExprCXX.h"
#include "clang/AST/RecursiveASTVisitor.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Lex/HeaderSearch.h"
Expand Down Expand Up @@ -104,6 +105,13 @@ class ReferencedLocationCrawler
return true;
}

// When the overload is not resolved yet, mark all candidates as used.
bool VisitOverloadExpr(OverloadExpr *E) {
for (const auto *ResolutionDecl : E->decls())
add(ResolutionDecl);
return true;
}

private:
using Base = RecursiveASTVisitor<ReferencedLocationCrawler>;

Expand Down
4 changes: 4 additions & 0 deletions clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ TEST(IncludeCleaner, ReferencedLocations) {
"inline void ^foo() {}",
"void bar() { foo(); }",
},
{
"int ^foo(char); int ^foo(float);",
"template<class T> int x = foo(T{});",
},
// Static function
{
"struct ^X { static bool ^foo(); }; bool X::^foo() {}",
Expand Down
40 changes: 26 additions & 14 deletions clang-tools-extra/docs/clang-tidy/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ Using clang-tidy

:program:`clang-tidy` is a `LibTooling`_-based tool, and it's easier to work
with if you set up a compile command database for your project (for an example
of how to do this see `How To Setup Tooling For LLVM`_). You can also specify
of how to do this, see `How To Setup Tooling For LLVM`_). You can also specify
compilation options on the command line after ``--``:

.. code-block:: console
$ clang-tidy test.cpp -- -Imy_project/include -DMY_DEFINES ...
:program:`clang-tidy` has its own checks and can also run Clang static analyzer
:program:`clang-tidy` has its own checks and can also run Clang Static Analyzer
checks. Each check has a name and the checks to run can be chosen using the
``-checks=`` option, which specifies a comma-separated list of positive and
negative (prefixed with ``-``) globs. Positive globs add subsets of checks,
negative (prefixed with ``-``) globs. Positive globs add subsets of checks, and
negative globs remove them. For example,

.. code-block:: console
Expand All @@ -61,7 +61,7 @@ Name prefix Description
``altera-`` Checks related to OpenCL programming for FPGAs.
``android-`` Checks related to Android.
``boost-`` Checks related to Boost library.
``bugprone-`` Checks that target bugprone code constructs.
``bugprone-`` Checks that target bug-prone code constructs.
``cert-`` Checks related to CERT Secure Coding Guidelines.
``clang-analyzer-`` Clang Static Analyzer checks.
``concurrency-`` Checks related to concurrent programming (including
Expand Down Expand Up @@ -90,11 +90,11 @@ Name prefix Description

Clang diagnostics are treated in a similar way as check diagnostics. Clang
diagnostics are displayed by :program:`clang-tidy` and can be filtered out using
``-checks=`` option. However, the ``-checks=`` option does not affect
the ``-checks=`` option. However, the ``-checks=`` option does not affect
compilation arguments, so it cannot turn on Clang warnings which are not
already turned on in build configuration. The ``-warnings-as-errors=`` option
upgrades any warnings emitted under the ``-checks=`` flag to errors (but it
does not enable any checks itself).
already turned on in the build configuration. The ``-warnings-as-errors=``
option upgrades any warnings emitted under the ``-checks=`` flag to errors (but
it does not enable any checks itself).

Clang diagnostics have check names starting with ``clang-diagnostic-``.
Diagnostics which have a corresponding warning option, are named
Expand Down Expand Up @@ -140,6 +140,12 @@ An overview of all the command-line options:
When the value is empty, clang-tidy will
attempt to find a file named .clang-tidy for
each source file in its parent directories.
--config-file=<string> -
Specify the path of .clang-tidy or custom config file:
e.g. --config-file=/some/path/myTidyConfigFile
This option internally works exactly the same way as
--config option after reading specified config file.
Use either --config-file or --config, not both.
--dump-config -
Dumps configuration in the YAML format to
stdout. This option can be used along with a
Expand All @@ -160,9 +166,9 @@ An overview of all the command-line options:
YAML file to store suggested fixes in. The
stored fixes can be applied to the input source
code with clang-apply-replacements.
--extra-arg=<string> - Additional argument to append to the compiler command line
--extra-arg=<string> - Additional argument to append to the compiler command line.
Can be used several times.
--extra-arg-before=<string> - Additional argument to prepend to the compiler command line
--extra-arg-before=<string> - Additional argument to prepend to the compiler command line.
Can be used several times.
--fix -
Apply suggested fixes. Without -fix-errors
Expand Down Expand Up @@ -223,6 +229,12 @@ An overview of all the command-line options:
format to stderr. When this option is passed,
these per-TU profiles are instead stored as JSON.
--system-headers - Display the errors from system headers.
--use-color -
Use colors in diagnostics. If not set, colors
will be used if the terminal connected to
standard output supports colors.
This option overrides the 'UseColor' option in
.clang-tidy file, if any.
--vfsoverlay=<filename> -
Overlay the virtual filesystem described by file
over the real file system.
Expand Down Expand Up @@ -301,8 +313,8 @@ mechanism to suppress diagnostics using ``NOLINT``, ``NOLINTNEXTLINE``, and
The ``NOLINT`` comment instructs :program:`clang-tidy` to ignore warnings on the
*same line* (it doesn't apply to a function, a block of code or any other
language construct; it applies to the line of code it is on). If introducing the
comment in the same line would change the formatting in an undesired way, the
``NOLINTNEXTLINE`` comment allows to suppress clang-tidy warnings on the *next
comment on the same line would change the formatting in an undesired way, the
``NOLINTNEXTLINE`` comment allows suppressing clang-tidy warnings on the *next
line*. The ``NOLINTBEGIN`` and ``NOLINTEND`` comments allow suppressing
clang-tidy warnings on *multiple lines* (affecting all lines between the two
comments).
Expand All @@ -320,8 +332,8 @@ For example:
// Suppress all the diagnostics for the line
Foo(int param); // NOLINT

// Consider explaining the motivation to suppress the warning.
Foo(char param); // NOLINT: Allow implicit conversion from `char`, because <some valid reason>.
// Consider explaining the motivation to suppress the warning
Foo(char param); // NOLINT: Allow implicit conversion from `char`, because <some valid reason>

// Silence only the specified checks for the line
Foo(double param); // NOLINT(google-explicit-constructor, google-runtime-int)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct ExpensiveToCopy {

struct ConstInCorrectType {
const ExpensiveToCopy &secretlyMutates() const;
const ExpensiveToCopy &operator[](int) const;
};

using NSVTE = ns::ViewType<ExpensiveToCopy>;
Expand Down Expand Up @@ -58,3 +59,29 @@ void excludedConstIncorrectType() {
const auto E = C.secretlyMutates();
E.constMethod();
}

void excludedConstIncorrectTypeOperator() {
ConstInCorrectType C;
const auto E = C[42];
E.constMethod();
}

void excludedConstIncorrectTypeAsPointer(ConstInCorrectType *C) {
const auto E = C->secretlyMutates();
E.constMethod();
}

void excludedConstIncorrectTypeAsPointerOperator(ConstInCorrectType *C) {
const auto E = (*C)[42];
E.constMethod();
}

void excludedConstIncorrectTypeAsReference(const ConstInCorrectType &C) {
const auto E = C.secretlyMutates();
E.constMethod();
}

void excludedConstIncorrectTypeAsReferenceOperator(const ConstInCorrectType &C) {
const auto E = C[42];
E.constMethod();
}
Loading

0 comments on commit 3b80fcc

Please sign in to comment.