Skip to content

Commit

Permalink
Merge branch 'sycl' of https://github.com/intel/llvm into deps_uplift
Browse files Browse the repository at this point in the history
  • Loading branch information
yinyangsx committed Jul 31, 2020
2 parents 7997313 + 4c57d4d commit aa4a181
Show file tree
Hide file tree
Showing 2,436 changed files with 123,763 additions and 24,860 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ sycl/source/stream.cpp @againull

# Specialization constant
sycl/include/CL/sycl/detail/sycl_fe_intrins.hpp @kbobrovs
sycl/include/CL/sycl/detail/spec_constant_impl.hpp @kbobrovs
sycl/include/CL/sycl/experimental/spec_constant.hpp @kbobrovs
sycl/source/detail/spec_constant_impl.hpp @kbobrovs

# Program manager
sycl/source/detail/program_manager @kbobrovs
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:
fetch-depth: 2

- name: Get clang-format first
run: sudo apt-get install -yqq clang-format-9
run: sudo apt-get install -yqq clang-format-10

- name: Run clang-format for the patch
run: |
git diff -U0 --no-color ${GITHUB_SHA}^1 ${GITHUB_SHA} -- | ./clang/tools/clang-format/clang-format-diff.py -p1 -binary clang-format-9 > ./clang-format.patch
git diff -U0 --no-color ${GITHUB_SHA}^1 ${GITHUB_SHA} -- | ./clang/tools/clang-format/clang-format-diff.py -p1 -binary clang-format-10 > ./clang-format.patch
# Add patch with formatting fixes to CI job artifacts
- uses: actions/upload-artifact@v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ static QualType getUnqualifiedType(const Expr &E) {
}

static APValue getConstantExprValue(const ASTContext &Ctx, const Expr &E) {
llvm::APSInt IntegerConstant;
if (E.isIntegerConstantExpr(IntegerConstant, Ctx))
return APValue(IntegerConstant);
if (auto IntegerConstant = E.getIntegerConstantExpr(Ctx))
return APValue(*IntegerConstant);
APValue Constant;
if (Ctx.getLangOpts().CPlusPlus && E.isCXX11ConstantExpr(Ctx, &Constant))
return Constant;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ void ProBoundsConstantArrayIndexCheck::check(
if (IndexExpr->isValueDependent())
return; // We check in the specialization.

llvm::APSInt Index;
if (!IndexExpr->isIntegerConstantExpr(Index, *Result.Context, nullptr,
/*isEvaluated=*/true)) {
Optional<llvm::APSInt> Index =
IndexExpr->getIntegerConstantExpr(*Result.Context);
if (!Index) {
SourceRange BaseRange;
if (const auto *ArraySubscriptE = dyn_cast<ArraySubscriptExpr>(Matched))
BaseRange = ArraySubscriptE->getBase()->getSourceRange();
Expand Down Expand Up @@ -101,9 +101,9 @@ void ProBoundsConstantArrayIndexCheck::check(
if (!StdArrayDecl)
return;

if (Index.isSigned() && Index.isNegative()) {
if (Index->isSigned() && Index->isNegative()) {
diag(Matched->getExprLoc(), "std::array<> index %0 is negative")
<< Index.toString(10);
<< Index->toString(10);
return;
}

Expand All @@ -118,11 +118,11 @@ void ProBoundsConstantArrayIndexCheck::check(

// Get uint64_t values, because different bitwidths would lead to an assertion
// in APInt::uge.
if (Index.getZExtValue() >= ArraySize.getZExtValue()) {
if (Index->getZExtValue() >= ArraySize.getZExtValue()) {
diag(Matched->getExprLoc(),
"std::array<> index %0 is past the end of the array "
"(which contains %1 elements)")
<< Index.toString(10) << ArraySize.toString(10, false);
<< Index->toString(10) << ArraySize.toString(10, false);
}
}

Expand Down
22 changes: 15 additions & 7 deletions clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,13 @@ static bool retrieveIntegerConstantExpr(const MatchFinder::MatchResult &Result,
const Expr *&ConstExpr) {
std::string CstId = (Id + "-const").str();
ConstExpr = Result.Nodes.getNodeAs<Expr>(CstId);
return ConstExpr && ConstExpr->isIntegerConstantExpr(Value, *Result.Context);
if (!ConstExpr)
return false;
Optional<llvm::APSInt> R = ConstExpr->getIntegerConstantExpr(*Result.Context);
if (!R)
return false;
Value = *R;
return true;
}

// Overloaded `retrieveIntegerConstantExpr` for compatibility.
Expand Down Expand Up @@ -673,7 +679,7 @@ static bool retrieveRelationalIntegerConstantExpr(

if (const auto *Arg = OverloadedOperatorExpr->getArg(1)) {
if (!Arg->isValueDependent() &&
!Arg->isIntegerConstantExpr(Value, *Result.Context))
!Arg->isIntegerConstantExpr(*Result.Context))
return false;
}
Symbol = OverloadedOperatorExpr->getArg(0);
Expand Down Expand Up @@ -1265,21 +1271,23 @@ void RedundantExpressionCheck::check(const MatchFinder::MatchResult &Result) {
"left-right-shift-confusion")) {
const auto *ShiftingConst = Result.Nodes.getNodeAs<Expr>("shift-const");
assert(ShiftingConst && "Expr* 'ShiftingConst' is nullptr!");
APSInt ShiftingValue;
Optional<llvm::APSInt> ShiftingValue =
ShiftingConst->getIntegerConstantExpr(*Result.Context);

if (!ShiftingConst->isIntegerConstantExpr(ShiftingValue, *Result.Context))
if (!ShiftingValue)
return;

const auto *AndConst = Result.Nodes.getNodeAs<Expr>("and-const");
assert(AndConst && "Expr* 'AndCont' is nullptr!");
APSInt AndValue;
if (!AndConst->isIntegerConstantExpr(AndValue, *Result.Context))
Optional<llvm::APSInt> AndValue =
AndConst->getIntegerConstantExpr(*Result.Context);
if (!AndValue)
return;

// If ShiftingConst is shifted left with more bits than the position of the
// leftmost 1 in the bit representation of AndValue, AndConstant is
// ineffective.
if (AndValue.getActiveBits() > ShiftingValue)
if (AndValue->getActiveBits() > *ShiftingValue)
return;

auto Diag = diag(BinaryAndExpr->getOperatorLoc(),
Expand Down
7 changes: 4 additions & 3 deletions clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,12 @@ static bool arrayMatchesBoundExpr(ASTContext *Context,
Context->getAsConstantArrayType(ArrayType);
if (!ConstType)
return false;
llvm::APSInt ConditionSize;
if (!ConditionExpr->isIntegerConstantExpr(ConditionSize, *Context))
Optional<llvm::APSInt> ConditionSize =
ConditionExpr->getIntegerConstantExpr(*Context);
if (!ConditionSize)
return false;
llvm::APSInt ArraySize(ConstType->getSize());
return llvm::APSInt::isSameValue(ConditionSize, ArraySize);
return llvm::APSInt::isSameValue(*ConditionSize, ArraySize);
}

ForLoopIndexUseVisitor::ForLoopIndexUseVisitor(ASTContext *Context,
Expand Down
76 changes: 69 additions & 7 deletions clang-tools-extra/clangd/FindTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,32 @@ nodeToString(const ast_type_traits::DynTypedNode &N) {
}

// Helper function for getMembersReferencedViaDependentName()
// which takes a dependent type `T` and heuristically
// which takes a possibly-dependent type `T` and heuristically
// resolves it to a CXXRecordDecl in which we can try name lookup.
CXXRecordDecl *resolveTypeToRecordDecl(const Type *T) {
assert(T);
if (const auto *ICNT = T->getAs<InjectedClassNameType>()) {

if (const auto *RT = T->getAs<RecordType>())
return dyn_cast<CXXRecordDecl>(RT->getDecl());

if (const auto *ICNT = T->getAs<InjectedClassNameType>())
T = ICNT->getInjectedSpecializationType().getTypePtrOrNull();
}
if (!T)
return nullptr;

const auto *TST = T->getAs<TemplateSpecializationType>();
if (!TST)
return nullptr;

const ClassTemplateDecl *TD = dyn_cast_or_null<ClassTemplateDecl>(
TST->getTemplateName().getAsTemplateDecl());
if (!TD)
return nullptr;

return TD->getTemplatedDecl();
}

// Given a dependent type and a member name, heuristically resolve the
// Given a tag-decl type and a member name, heuristically resolve the
// name to one or more declarations.
// The current heuristic is simply to look up the name in the primary
// template. This is a heuristic because the template could potentially
Expand Down Expand Up @@ -154,6 +162,10 @@ const Type *getPointeeType(const Type *T) {
return FirstArg.getAsType().getTypePtrOrNull();
}

// Forward declaration, needed as this function is mutually recursive
// with resolveDependentExprToDecls.
const Type *resolveDependentExprToType(const Expr *E);

// Try to heuristically resolve a dependent expression `E` to one
// or more declarations that it likely references.
std::vector<const NamedDecl *> resolveDependentExprToDecls(const Expr *E) {
Expand All @@ -163,6 +175,17 @@ std::vector<const NamedDecl *> resolveDependentExprToDecls(const Expr *E) {
if (ME->isArrow()) {
BaseType = getPointeeType(BaseType);
}
if (!BaseType)
return {};
if (const auto *BT = BaseType->getAs<BuiltinType>()) {
// If BaseType is the type of a dependent expression, it's just
// represented as BultinType::Dependent which gives us no information. We
// can get further by analyzing the depedent expression.
Expr *Base = ME->isImplicitAccess() ? nullptr : ME->getBase();
if (Base && BT->getKind() == BuiltinType::Dependent) {
BaseType = resolveDependentExprToType(Base);
}
}
return getMembersReferencedViaDependentName(
BaseType, [ME](ASTContext &) { return ME->getMember(); },
/*IsNonstaticMember=*/true);
Expand All @@ -173,9 +196,38 @@ std::vector<const NamedDecl *> resolveDependentExprToDecls(const Expr *E) {
[RE](ASTContext &) { return RE->getDeclName(); },
/*IsNonstaticMember=*/false);
}
if (const auto *CE = dyn_cast<CallExpr>(E)) {
const auto *CalleeType = resolveDependentExprToType(CE->getCallee());
if (!CalleeType)
return {};
if (const auto *FnTypePtr = CalleeType->getAs<PointerType>())
CalleeType = FnTypePtr->getPointeeType().getTypePtr();
if (const FunctionType *FnType = CalleeType->getAs<FunctionType>()) {
if (const auto *D =
resolveTypeToRecordDecl(FnType->getReturnType().getTypePtr())) {
return {D};
}
}
}
if (const auto *ME = dyn_cast<MemberExpr>(E)) {
return {ME->getMemberDecl()};
}
return {};
}

// Try to heuristically resolve the type of a dependent expression `E`.
const Type *resolveDependentExprToType(const Expr *E) {
std::vector<const NamedDecl *> Decls = resolveDependentExprToDecls(E);
if (Decls.size() != 1) // Names an overload set -- just bail.
return nullptr;
if (const auto *TD = dyn_cast<TypeDecl>(Decls[0])) {
return TD->getTypeForDecl();
} else if (const auto *VD = dyn_cast<ValueDecl>(Decls[0])) {
return VD->getType().getTypePtrOrNull();
}
return nullptr;
}

const NamedDecl *getTemplatePattern(const NamedDecl *D) {
if (const CXXRecordDecl *CRD = dyn_cast<CXXRecordDecl>(D)) {
if (const auto *Result = CRD->getTemplateInstantiationPattern())
Expand Down Expand Up @@ -235,9 +287,8 @@ const NamedDecl *getTemplatePattern(const NamedDecl *D) {
// and both are lossy. We must know upfront what the caller ultimately wants.
//
// FIXME: improve common dependent scope using name lookup in primary templates.
// e.g. template<typename T> int foo() { return std::vector<T>().size(); }
// formally size() is unresolved, but the primary template is a good guess.
// This affects:
// We currently handle DependentScopeDeclRefExpr and
// CXXDependentScopeMemberExpr, but some other constructs remain to be handled:
// - DependentTemplateSpecializationType,
// - DependentNameType
// - UnresolvedUsingValueDecl
Expand Down Expand Up @@ -302,6 +353,8 @@ struct TargetFinder {
// Record the underlying decl instead, if allowed.
D = USD->getTargetDecl();
Flags |= Rel::Underlying; // continue with the underlying decl.
} else if (const auto *DG = dyn_cast<CXXDeductionGuideDecl>(D)) {
D = DG->getDeducedTemplate();
}

if (const Decl *Pat = getTemplatePattern(D)) {
Expand Down Expand Up @@ -659,6 +712,15 @@ llvm::SmallVector<ReferenceLoc, 2> refInDecl(const Decl *D) {
/*IsDecl=*/true,
{ND}});
}

void VisitCXXDeductionGuideDecl(const CXXDeductionGuideDecl *DG) {
// The class template name in a deduction guide targets the class
// template.
Refs.push_back(ReferenceLoc{DG->getQualifierLoc(),
DG->getNameInfo().getLoc(),
/*IsDecl=*/false,
{DG->getDeducedTemplate()}});
}
};

Visitor V;
Expand Down
20 changes: 16 additions & 4 deletions clang-tools-extra/clangd/Selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,26 @@ class SelectionTester {
SelFirst, AllSpelledTokens.end(), [&](const syntax::Token &Tok) {
return SM.getFileOffset(Tok.location()) < SelEnd;
});
auto Sel = llvm::makeArrayRef(SelFirst, SelLimit);
// Find which of these are preprocessed to nothing and should be ignored.
std::vector<bool> PPIgnored(Sel.size(), false);
for (const syntax::TokenBuffer::Expansion &X :
Buf.expansionsOverlapping(Sel)) {
if (X.Expanded.empty()) {
for (const syntax::Token &Tok : X.Spelled) {
if (&Tok >= SelFirst && &Tok < SelLimit)
PPIgnored[&Tok - SelFirst] = true;
}
}
}
// Precompute selectedness and offset for selected spelled tokens.
for (const syntax::Token *T = SelFirst; T < SelLimit; ++T) {
if (shouldIgnore(*T))
for (unsigned I = 0; I < Sel.size(); ++I) {
if (shouldIgnore(Sel[I]) || PPIgnored[I])
continue;
SpelledTokens.emplace_back();
Tok &S = SpelledTokens.back();
S.Offset = SM.getFileOffset(T->location());
if (S.Offset >= SelBegin && S.Offset + T->length() <= SelEnd)
S.Offset = SM.getFileOffset(Sel[I].location());
if (S.Offset >= SelBegin && S.Offset + Sel[I].length() <= SelEnd)
S.Selected = SelectionTree::Complete;
else
S.Selected = SelectionTree::Partial;
Expand Down
45 changes: 33 additions & 12 deletions clang-tools-extra/clangd/URI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,56 @@ inline llvm::Error make_string_error(const llvm::Twine &Message) {
llvm::inconvertibleErrorCode());
}

bool isWindowsPath(llvm::StringRef Path) {
return Path.size() > 1 && llvm::isAlpha(Path[0]) && Path[1] == ':';
}

bool isNetworkPath(llvm::StringRef Path) {
return Path.size() > 2 && Path[0] == Path[1] &&
llvm::sys::path::is_separator(Path[0]);
}

/// This manages file paths in the file system. All paths in the scheme
/// are absolute (with leading '/').
/// Note that this scheme is hardcoded into the library and not registered in
/// registry.
class FileSystemScheme : public URIScheme {
public:
llvm::Expected<std::string>
getAbsolutePath(llvm::StringRef /*Authority*/, llvm::StringRef Body,
getAbsolutePath(llvm::StringRef Authority, llvm::StringRef Body,
llvm::StringRef /*HintPath*/) const override {
if (!Body.startswith("/"))
return make_string_error("File scheme: expect body to be an absolute "
"path starting with '/': " +
Body);
// For Windows paths e.g. /X:
if (Body.size() > 2 && Body[0] == '/' && Body[2] == ':')
llvm::SmallString<128> Path;
if (!Authority.empty()) {
// Windows UNC paths e.g. file://server/share => \\server\share
("//" + Authority).toVector(Path);
} else if (isWindowsPath(Body.substr(1))) {
// Windows paths e.g. file:///X:/path => X:\path
Body.consume_front("/");
llvm::SmallVector<char, 16> Path(Body.begin(), Body.end());
}
Path.append(Body);
llvm::sys::path::native(Path);
return std::string(Path.begin(), Path.end());
return std::string(Path);
}

llvm::Expected<URI>
uriFromAbsolutePath(llvm::StringRef AbsolutePath) const override {
std::string Body;
// For Windows paths e.g. X:
if (AbsolutePath.size() > 1 && AbsolutePath[1] == ':')
llvm::StringRef Authority;
llvm::StringRef Root = llvm::sys::path::root_name(AbsolutePath);
if (isNetworkPath(Root)) {
// Windows UNC paths e.g. \\server\share => file://server/share
Authority = Root.drop_front(2);
AbsolutePath.consume_front(Root);
} else if (isWindowsPath(Root)) {
// Windows paths e.g. X:\path => file:///X:/path
Body = "/";
}
Body += llvm::sys::path::convert_to_slash(AbsolutePath);
return URI("file", /*Authority=*/"", Body);
return URI("file", Authority, Body);
}
};

Expand Down Expand Up @@ -96,13 +117,13 @@ bool shouldEscape(unsigned char C) {
void percentEncode(llvm::StringRef Content, std::string &Out) {
std::string Result;
for (unsigned char C : Content)
if (shouldEscape(C))
{
if (shouldEscape(C)) {
Out.push_back('%');
Out.push_back(llvm::hexdigit(C / 16));
Out.push_back(llvm::hexdigit(C % 16));
} else
{ Out.push_back(C); }
} else {
Out.push_back(C);
}
}

/// Decodes a string according to percent-encoding.
Expand Down
Loading

0 comments on commit aa4a181

Please sign in to comment.