Skip to content

Commit

Permalink
Merge from 'master' to 'sycl-web' (triSYCL#3)
Browse files Browse the repository at this point in the history
  CONFLICT (content): Merge conflict in clang/include/clang/Basic/DiagnosticSemaKinds.td
  • Loading branch information
Erich Keane committed Jun 5, 2020
2 parents 72dc69e + 931fcd3 commit 030a52d
Show file tree
Hide file tree
Showing 1,011 changed files with 30,656 additions and 11,397 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "ProTypeVarargCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"

using namespace clang::ast_matchers;

Expand All @@ -18,11 +19,72 @@ namespace cppcoreguidelines {

const internal::VariadicDynCastAllOfMatcher<Stmt, VAArgExpr> vAArgExpr;

static constexpr StringRef AllowedVariadics[] = {
// clang-format off
"__builtin_isgreater",
"__builtin_isgreaterequal",
"__builtin_isless",
"__builtin_islessequal",
"__builtin_islessgreater",
"__builtin_isunordered",
"__builtin_fpclassify",
"__builtin_isfinite",
"__builtin_isinf",
"__builtin_isinf_sign",
"__builtin_isnan",
"__builtin_isnormal",
"__builtin_signbit",
"__builtin_constant_p",
"__builtin_classify_type",
"__builtin_va_start",
"__builtin_assume_aligned", // Documented as variadic to support default
// parameters.
"__builtin_prefetch", // Documented as variadic to support default
// parameters.
"__builtin_shufflevector", // Documented as variadic but with a defined
// number of args based on vector size.
"__builtin_convertvector",
"__builtin_call_with_static_chain",
"__builtin_annotation",
"__builtin_add_overflow",
"__builtin_sub_overflow",
"__builtin_mul_overflow",
"__builtin_preserve_access_index",
"__builtin_nontemporal_store",
"__builtin_nontemporal_load",
"__builtin_ms_va_start",
// clang-format on
};

namespace {
AST_MATCHER(QualType, isVAList) {
ASTContext &Context = Finder->getASTContext();
QualType Desugar = Node.getDesugaredType(Context);
return Context.getBuiltinVaListType().getDesugaredType(Context) == Desugar ||
Context.getBuiltinMSVaListType().getDesugaredType(Context) == Desugar;
}

AST_MATCHER_P(AdjustedType, hasOriginalType,
ast_matchers::internal::Matcher<QualType>, InnerType) {
return InnerType.matches(Node.getOriginalType(), Finder, Builder);
}
} // namespace

void ProTypeVarargCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(vAArgExpr().bind("va_use"), this);

Finder->addMatcher(
callExpr(callee(functionDecl(isVariadic()))).bind("callvararg"), this);
callExpr(callee(functionDecl(isVariadic(),
unless(hasAnyName(AllowedVariadics)))))
.bind("callvararg"),
this);

Finder->addMatcher(
varDecl(unless(parmVarDecl()),
hasType(qualType(
anyOf(isVAList(), decayedType(hasOriginalType(isVAList()))))))
.bind("va_list"),
this);
}

static bool hasSingleVariadicArgumentWithValue(const CallExpr *C, uint64_t I) {
Expand Down Expand Up @@ -54,7 +116,7 @@ void ProTypeVarargCheck::check(const MatchFinder::MatchResult &Result) {

if (const auto *Matched = Result.Nodes.getNodeAs<Expr>("va_use")) {
diag(Matched->getExprLoc(),
"do not use va_start/va_arg to define c-style vararg functions; "
"do not use va_arg to define c-style vararg functions; "
"use variadic templates instead");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ static bool areEquivalentExpr(const Expr *Left, const Expr *Right) {
Expr::const_child_iterator LeftIter = Left->child_begin();
Expr::const_child_iterator RightIter = Right->child_begin();
while (LeftIter != Left->child_end() && RightIter != Right->child_end()) {
if (!areEquivalentExpr(dyn_cast<Expr>(*LeftIter),
dyn_cast<Expr>(*RightIter)))
if (!areEquivalentExpr(dyn_cast_or_null<Expr>(*LeftIter),
dyn_cast_or_null<Expr>(*RightIter)))
return false;
++LeftIter;
++RightIter;
Expand Down Expand Up @@ -117,6 +117,9 @@ static bool areEquivalentExpr(const Expr *Left, const Expr *Right) {
case Stmt::MemberExprClass:
return cast<MemberExpr>(Left)->getMemberDecl() ==
cast<MemberExpr>(Right)->getMemberDecl();
case Stmt::CXXFoldExprClass:
return cast<CXXFoldExpr>(Left)->getOperator() ==
cast<CXXFoldExpr>(Right)->getOperator();
case Stmt::CXXFunctionalCastExprClass:
case Stmt::CStyleCastExprClass:
return cast<ExplicitCastExpr>(Left)->getTypeAsWritten() ==
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ add_clang_library(clangTidyModernizeModule
RawStringLiteralCheck.cpp
RedundantVoidArgCheck.cpp
ReplaceAutoPtrCheck.cpp
ReplaceDisallowCopyAndAssignMacroCheck.cpp
ReplaceRandomShuffleCheck.cpp
ReturnBracedInitListCheck.cpp
ShrinkToFitCheck.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ void LoopConvertCheck::doConversion(
QualType Type = Context->getAutoDeductType();
if (!Descriptor.ElemType.isNull() && Descriptor.ElemType->isFundamentalType())
Type = Descriptor.ElemType.getUnqualifiedType();
Type = Type.getDesugaredType(*Context);

// If the new variable name is from the aliased variable, then the reference
// type for the new variable should only be used if the aliased variable was
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "RawStringLiteralCheck.h"
#include "RedundantVoidArgCheck.h"
#include "ReplaceAutoPtrCheck.h"
#include "ReplaceDisallowCopyAndAssignMacroCheck.h"
#include "ReplaceRandomShuffleCheck.h"
#include "ReturnBracedInitListCheck.h"
#include "ShrinkToFitCheck.h"
Expand Down Expand Up @@ -67,6 +68,8 @@ class ModernizeModule : public ClangTidyModule {
"modernize-redundant-void-arg");
CheckFactories.registerCheck<ReplaceAutoPtrCheck>(
"modernize-replace-auto-ptr");
CheckFactories.registerCheck<ReplaceDisallowCopyAndAssignMacroCheck>(
"modernize-replace-disallow-copy-and-assign-macro");
CheckFactories.registerCheck<ReplaceRandomShuffleCheck>(
"modernize-replace-random-shuffle");
CheckFactories.registerCheck<ReturnBracedInitListCheck>(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//===--- ReplaceDisallowCopyAndAssignMacroCheck.cpp - clang-tidy ----------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "ReplaceDisallowCopyAndAssignMacroCheck.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/MacroArgs.h"
#include "llvm/Support/FormatVariadic.h"

namespace clang {
namespace tidy {
namespace modernize {

namespace {

class ReplaceDisallowCopyAndAssignMacroCallbacks : public PPCallbacks {
public:
explicit ReplaceDisallowCopyAndAssignMacroCallbacks(
ReplaceDisallowCopyAndAssignMacroCheck &Check, Preprocessor &PP)
: Check(Check), PP(PP) {}

void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD,
SourceRange Range, const MacroArgs *Args) override {
IdentifierInfo *Info = MacroNameTok.getIdentifierInfo();
if (!Info || !Args || Args->getNumMacroArguments() != 1)
return;
if (Info->getName() != Check.getMacroName())
return;
// The first argument to the DISALLOW_COPY_AND_ASSIGN macro is exptected to
// be the class name.
const Token *ClassNameTok = Args->getUnexpArgument(0);
if (Args->ArgNeedsPreexpansion(ClassNameTok, PP))
// For now we only support simple argument that don't need to be
// pre-expanded.
return;
clang::IdentifierInfo *ClassIdent = ClassNameTok->getIdentifierInfo();
if (!ClassIdent)
return;

std::string Replacement = llvm::formatv(
R"cpp({0}(const {0} &) = delete;
const {0} &operator=(const {0} &) = delete{1})cpp",
ClassIdent->getName(), shouldAppendSemi(Range) ? ";" : "");

Check.diag(MacroNameTok.getLocation(),
"prefer deleting copy constructor and assignment operator over "
"using macro '%0'")
<< Check.getMacroName()
<< FixItHint::CreateReplacement(
PP.getSourceManager().getExpansionRange(Range), Replacement);
}

private:
/// \returns \c true if the next token after the given \p MacroLoc is \b not a
/// semicolon.
bool shouldAppendSemi(SourceRange MacroLoc) {
llvm::Optional<Token> Next = Lexer::findNextToken(
MacroLoc.getEnd(), PP.getSourceManager(), PP.getLangOpts());
return !(Next && Next->is(tok::semi));
}

ReplaceDisallowCopyAndAssignMacroCheck &Check;
Preprocessor &PP;
};
} // namespace

ReplaceDisallowCopyAndAssignMacroCheck::ReplaceDisallowCopyAndAssignMacroCheck(
StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
MacroName(Options.get("MacroName", "DISALLOW_COPY_AND_ASSIGN")) {}

void ReplaceDisallowCopyAndAssignMacroCheck::registerPPCallbacks(
const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
PP->addPPCallbacks(
::std::make_unique<ReplaceDisallowCopyAndAssignMacroCallbacks>(
*this, *ModuleExpanderPP));
}

void ReplaceDisallowCopyAndAssignMacroCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "MacroName", MacroName);
}

} // namespace modernize
} // namespace tidy
} // namespace clang
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//===--- ReplaceDisallowCopyAndAssignMacroCheck.h - clang-tidy --*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACEDISALLOWCOPYANDASSIGNMACROCHECK_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACEDISALLOWCOPYANDASSIGNMACROCHECK_H

#include "../ClangTidyCheck.h"

namespace clang {
namespace tidy {
namespace modernize {

/// This check finds macro expansions of ``DISALLOW_COPY_AND_ASSIGN(Type)`` and
/// replaces them with a deleted copy constructor and a deleted assignment
/// operator.
///
/// Before:
/// ~~~{.cpp}
/// class Foo {
/// private:
/// DISALLOW_COPY_AND_ASSIGN(Foo);
/// };
/// ~~~
///
/// After:
/// ~~~{.cpp}
/// class Foo {
/// private:
/// Foo(const Foo &) = delete;
/// const Foo &operator=(const Foo &) = delete;
/// };
/// ~~~
///
/// For the user-facing documentation see:
/// http://clang.llvm.org/extra/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.html
class ReplaceDisallowCopyAndAssignMacroCheck : public ClangTidyCheck {
public:
ReplaceDisallowCopyAndAssignMacroCheck(StringRef Name,
ClangTidyContext *Context);
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus11;
}
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override;
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;

const std::string &getMacroName() const { return MacroName; }

private:
const std::string MacroName;
};

} // namespace modernize
} // namespace tidy
} // namespace clang

#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACEDISALLOWCOPYANDASSIGNMACROCHECK_H
16 changes: 12 additions & 4 deletions clang-tools-extra/clangd/ClangdServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,16 @@ void ClangdServer::codeComplete(PathRef File, Position Pos,
}
}
}
ParseInputs ParseInput{IP->Command, FS, IP->Contents.str()};
ParseInput.Index = Index;
ParseInput.Opts.BuildRecoveryAST = BuildRecoveryAST;
ParseInput.Opts.PreserveRecoveryASTType = PreserveRecoveryASTType;

// FIXME(ibiryukov): even if Preamble is non-null, we may want to check
// both the old and the new version in case only one of them matches.
CodeCompleteResult Result = clangd::codeComplete(
File, IP->Command, IP->Preamble, IP->Contents, Pos, FS,
CodeCompleteOpts, SpecFuzzyFind ? SpecFuzzyFind.getPointer() : nullptr);
File, Pos, IP->Preamble, ParseInput, CodeCompleteOpts,
SpecFuzzyFind ? SpecFuzzyFind.getPointer() : nullptr);
{
clang::clangd::trace::Span Tracer("Completion results callback");
CB(std::move(Result));
Expand Down Expand Up @@ -281,8 +286,11 @@ void ClangdServer::signatureHelp(PathRef File, Position Pos,
return CB(llvm::createStringError(llvm::inconvertibleErrorCode(),
"Failed to parse includes"));

CB(clangd::signatureHelp(File, IP->Command, *PreambleData, IP->Contents,
Pos, FS, Index));
ParseInputs ParseInput{IP->Command, FS, IP->Contents.str()};
ParseInput.Index = Index;
ParseInput.Opts.BuildRecoveryAST = BuildRecoveryAST;
ParseInput.Opts.PreserveRecoveryASTType = PreserveRecoveryASTType;
CB(clangd::signatureHelp(File, Pos, *PreambleData, ParseInput));
};

// Unlike code completion, we wait for a preamble here.
Expand Down
Loading

0 comments on commit 030a52d

Please sign in to comment.