Skip to content

Commit 3b7e3d7

Browse files
Merge branch 'sycl' of https://github.com/srividya-sundaram/llvm into unused-args-elimination
2 parents 0b6a546 + fe7885c commit 3b7e3d7

File tree

2,427 files changed

+117672
-23914
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,427 files changed

+117672
-23914
lines changed

.github/workflows/clang-format.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ jobs:
1414
fetch-depth: 2
1515

1616
- name: Get clang-format first
17-
run: sudo apt-get install -yqq clang-format-9
17+
run: sudo apt-get install -yqq clang-format-10
1818

1919
- name: Run clang-format for the patch
2020
run: |
21-
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
21+
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
2222
2323
# Add patch with formatting fixes to CI job artifacts
2424
- uses: actions/upload-artifact@v1

clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ static QualType getUnqualifiedType(const Expr &E) {
7979
}
8080

8181
static APValue getConstantExprValue(const ASTContext &Ctx, const Expr &E) {
82-
llvm::APSInt IntegerConstant;
83-
if (E.isIntegerConstantExpr(IntegerConstant, Ctx))
84-
return APValue(IntegerConstant);
82+
if (auto IntegerConstant = E.getIntegerConstantExpr(Ctx))
83+
return APValue(*IntegerConstant);
8584
APValue Constant;
8685
if (Ctx.getLangOpts().CPlusPlus && E.isCXX11ConstantExpr(Ctx, &Constant))
8786
return Constant;

clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ void ProBoundsConstantArrayIndexCheck::check(
6565
if (IndexExpr->isValueDependent())
6666
return; // We check in the specialization.
6767

68-
llvm::APSInt Index;
69-
if (!IndexExpr->isIntegerConstantExpr(Index, *Result.Context, nullptr,
70-
/*isEvaluated=*/true)) {
68+
Optional<llvm::APSInt> Index =
69+
IndexExpr->getIntegerConstantExpr(*Result.Context);
70+
if (!Index) {
7171
SourceRange BaseRange;
7272
if (const auto *ArraySubscriptE = dyn_cast<ArraySubscriptExpr>(Matched))
7373
BaseRange = ArraySubscriptE->getBase()->getSourceRange();
@@ -101,9 +101,9 @@ void ProBoundsConstantArrayIndexCheck::check(
101101
if (!StdArrayDecl)
102102
return;
103103

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

@@ -118,11 +118,11 @@ void ProBoundsConstantArrayIndexCheck::check(
118118

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

clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,13 @@ static bool retrieveIntegerConstantExpr(const MatchFinder::MatchResult &Result,
500500
const Expr *&ConstExpr) {
501501
std::string CstId = (Id + "-const").str();
502502
ConstExpr = Result.Nodes.getNodeAs<Expr>(CstId);
503-
return ConstExpr && ConstExpr->isIntegerConstantExpr(Value, *Result.Context);
503+
if (!ConstExpr)
504+
return false;
505+
Optional<llvm::APSInt> R = ConstExpr->getIntegerConstantExpr(*Result.Context);
506+
if (!R)
507+
return false;
508+
Value = *R;
509+
return true;
504510
}
505511

506512
// Overloaded `retrieveIntegerConstantExpr` for compatibility.
@@ -673,7 +679,7 @@ static bool retrieveRelationalIntegerConstantExpr(
673679

674680
if (const auto *Arg = OverloadedOperatorExpr->getArg(1)) {
675681
if (!Arg->isValueDependent() &&
676-
!Arg->isIntegerConstantExpr(Value, *Result.Context))
682+
!Arg->isIntegerConstantExpr(*Result.Context))
677683
return false;
678684
}
679685
Symbol = OverloadedOperatorExpr->getArg(0);
@@ -1265,21 +1271,23 @@ void RedundantExpressionCheck::check(const MatchFinder::MatchResult &Result) {
12651271
"left-right-shift-confusion")) {
12661272
const auto *ShiftingConst = Result.Nodes.getNodeAs<Expr>("shift-const");
12671273
assert(ShiftingConst && "Expr* 'ShiftingConst' is nullptr!");
1268-
APSInt ShiftingValue;
1274+
Optional<llvm::APSInt> ShiftingValue =
1275+
ShiftingConst->getIntegerConstantExpr(*Result.Context);
12691276

1270-
if (!ShiftingConst->isIntegerConstantExpr(ShiftingValue, *Result.Context))
1277+
if (!ShiftingValue)
12711278
return;
12721279

12731280
const auto *AndConst = Result.Nodes.getNodeAs<Expr>("and-const");
12741281
assert(AndConst && "Expr* 'AndCont' is nullptr!");
1275-
APSInt AndValue;
1276-
if (!AndConst->isIntegerConstantExpr(AndValue, *Result.Context))
1282+
Optional<llvm::APSInt> AndValue =
1283+
AndConst->getIntegerConstantExpr(*Result.Context);
1284+
if (!AndValue)
12771285
return;
12781286

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

12851293
auto Diag = diag(BinaryAndExpr->getOperatorLoc(),

clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,12 @@ static bool arrayMatchesBoundExpr(ASTContext *Context,
438438
Context->getAsConstantArrayType(ArrayType);
439439
if (!ConstType)
440440
return false;
441-
llvm::APSInt ConditionSize;
442-
if (!ConditionExpr->isIntegerConstantExpr(ConditionSize, *Context))
441+
Optional<llvm::APSInt> ConditionSize =
442+
ConditionExpr->getIntegerConstantExpr(*Context);
443+
if (!ConditionSize)
443444
return false;
444445
llvm::APSInt ArraySize(ConstType->getSize());
445-
return llvm::APSInt::isSameValue(ConditionSize, ArraySize);
446+
return llvm::APSInt::isSameValue(*ConditionSize, ArraySize);
446447
}
447448

448449
ForLoopIndexUseVisitor::ForLoopIndexUseVisitor(ASTContext *Context,

clang-tools-extra/clangd/FindTarget.cpp

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,32 @@ nodeToString(const ast_type_traits::DynTypedNode &N) {
5959
}
6060

6161
// Helper function for getMembersReferencedViaDependentName()
62-
// which takes a dependent type `T` and heuristically
62+
// which takes a possibly-dependent type `T` and heuristically
6363
// resolves it to a CXXRecordDecl in which we can try name lookup.
6464
CXXRecordDecl *resolveTypeToRecordDecl(const Type *T) {
6565
assert(T);
66-
if (const auto *ICNT = T->getAs<InjectedClassNameType>()) {
66+
67+
if (const auto *RT = T->getAs<RecordType>())
68+
return dyn_cast<CXXRecordDecl>(RT->getDecl());
69+
70+
if (const auto *ICNT = T->getAs<InjectedClassNameType>())
6771
T = ICNT->getInjectedSpecializationType().getTypePtrOrNull();
68-
}
72+
if (!T)
73+
return nullptr;
74+
6975
const auto *TST = T->getAs<TemplateSpecializationType>();
7076
if (!TST)
7177
return nullptr;
78+
7279
const ClassTemplateDecl *TD = dyn_cast_or_null<ClassTemplateDecl>(
7380
TST->getTemplateName().getAsTemplateDecl());
7481
if (!TD)
7582
return nullptr;
83+
7684
return TD->getTemplatedDecl();
7785
}
7886

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

165+
// Forward declaration, needed as this function is mutually recursive
166+
// with resolveDependentExprToDecls.
167+
const Type *resolveDependentExprToType(const Expr *E);
168+
157169
// Try to heuristically resolve a dependent expression `E` to one
158170
// or more declarations that it likely references.
159171
std::vector<const NamedDecl *> resolveDependentExprToDecls(const Expr *E) {
@@ -163,6 +175,17 @@ std::vector<const NamedDecl *> resolveDependentExprToDecls(const Expr *E) {
163175
if (ME->isArrow()) {
164176
BaseType = getPointeeType(BaseType);
165177
}
178+
if (!BaseType)
179+
return {};
180+
if (const auto *BT = BaseType->getAs<BuiltinType>()) {
181+
// If BaseType is the type of a dependent expression, it's just
182+
// represented as BultinType::Dependent which gives us no information. We
183+
// can get further by analyzing the depedent expression.
184+
Expr *Base = ME->isImplicitAccess() ? nullptr : ME->getBase();
185+
if (Base && BT->getKind() == BuiltinType::Dependent) {
186+
BaseType = resolveDependentExprToType(Base);
187+
}
188+
}
166189
return getMembersReferencedViaDependentName(
167190
BaseType, [ME](ASTContext &) { return ME->getMember(); },
168191
/*IsNonstaticMember=*/true);
@@ -173,9 +196,38 @@ std::vector<const NamedDecl *> resolveDependentExprToDecls(const Expr *E) {
173196
[RE](ASTContext &) { return RE->getDeclName(); },
174197
/*IsNonstaticMember=*/false);
175198
}
199+
if (const auto *CE = dyn_cast<CallExpr>(E)) {
200+
const auto *CalleeType = resolveDependentExprToType(CE->getCallee());
201+
if (!CalleeType)
202+
return {};
203+
if (const auto *FnTypePtr = CalleeType->getAs<PointerType>())
204+
CalleeType = FnTypePtr->getPointeeType().getTypePtr();
205+
if (const FunctionType *FnType = CalleeType->getAs<FunctionType>()) {
206+
if (const auto *D =
207+
resolveTypeToRecordDecl(FnType->getReturnType().getTypePtr())) {
208+
return {D};
209+
}
210+
}
211+
}
212+
if (const auto *ME = dyn_cast<MemberExpr>(E)) {
213+
return {ME->getMemberDecl()};
214+
}
176215
return {};
177216
}
178217

218+
// Try to heuristically resolve the type of a dependent expression `E`.
219+
const Type *resolveDependentExprToType(const Expr *E) {
220+
std::vector<const NamedDecl *> Decls = resolveDependentExprToDecls(E);
221+
if (Decls.size() != 1) // Names an overload set -- just bail.
222+
return nullptr;
223+
if (const auto *TD = dyn_cast<TypeDecl>(Decls[0])) {
224+
return TD->getTypeForDecl();
225+
} else if (const auto *VD = dyn_cast<ValueDecl>(Decls[0])) {
226+
return VD->getType().getTypePtrOrNull();
227+
}
228+
return nullptr;
229+
}
230+
179231
const NamedDecl *getTemplatePattern(const NamedDecl *D) {
180232
if (const CXXRecordDecl *CRD = dyn_cast<CXXRecordDecl>(D)) {
181233
if (const auto *Result = CRD->getTemplateInstantiationPattern())
@@ -235,9 +287,8 @@ const NamedDecl *getTemplatePattern(const NamedDecl *D) {
235287
// and both are lossy. We must know upfront what the caller ultimately wants.
236288
//
237289
// FIXME: improve common dependent scope using name lookup in primary templates.
238-
// e.g. template<typename T> int foo() { return std::vector<T>().size(); }
239-
// formally size() is unresolved, but the primary template is a good guess.
240-
// This affects:
290+
// We currently handle DependentScopeDeclRefExpr and
291+
// CXXDependentScopeMemberExpr, but some other constructs remain to be handled:
241292
// - DependentTemplateSpecializationType,
242293
// - DependentNameType
243294
// - UnresolvedUsingValueDecl
@@ -302,6 +353,8 @@ struct TargetFinder {
302353
// Record the underlying decl instead, if allowed.
303354
D = USD->getTargetDecl();
304355
Flags |= Rel::Underlying; // continue with the underlying decl.
356+
} else if (const auto *DG = dyn_cast<CXXDeductionGuideDecl>(D)) {
357+
D = DG->getDeducedTemplate();
305358
}
306359

307360
if (const Decl *Pat = getTemplatePattern(D)) {
@@ -659,6 +712,15 @@ llvm::SmallVector<ReferenceLoc, 2> refInDecl(const Decl *D) {
659712
/*IsDecl=*/true,
660713
{ND}});
661714
}
715+
716+
void VisitCXXDeductionGuideDecl(const CXXDeductionGuideDecl *DG) {
717+
// The class template name in a deduction guide targets the class
718+
// template.
719+
Refs.push_back(ReferenceLoc{DG->getQualifierLoc(),
720+
DG->getNameInfo().getLoc(),
721+
/*IsDecl=*/false,
722+
{DG->getDeducedTemplate()}});
723+
}
662724
};
663725

664726
Visitor V;

clang-tools-extra/clangd/Selection.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,26 @@ class SelectionTester {
220220
SelFirst, AllSpelledTokens.end(), [&](const syntax::Token &Tok) {
221221
return SM.getFileOffset(Tok.location()) < SelEnd;
222222
});
223+
auto Sel = llvm::makeArrayRef(SelFirst, SelLimit);
224+
// Find which of these are preprocessed to nothing and should be ignored.
225+
std::vector<bool> PPIgnored(Sel.size(), false);
226+
for (const syntax::TokenBuffer::Expansion &X :
227+
Buf.expansionsOverlapping(Sel)) {
228+
if (X.Expanded.empty()) {
229+
for (const syntax::Token &Tok : X.Spelled) {
230+
if (&Tok >= SelFirst && &Tok < SelLimit)
231+
PPIgnored[&Tok - SelFirst] = true;
232+
}
233+
}
234+
}
223235
// Precompute selectedness and offset for selected spelled tokens.
224-
for (const syntax::Token *T = SelFirst; T < SelLimit; ++T) {
225-
if (shouldIgnore(*T))
236+
for (unsigned I = 0; I < Sel.size(); ++I) {
237+
if (shouldIgnore(Sel[I]) || PPIgnored[I])
226238
continue;
227239
SpelledTokens.emplace_back();
228240
Tok &S = SpelledTokens.back();
229-
S.Offset = SM.getFileOffset(T->location());
230-
if (S.Offset >= SelBegin && S.Offset + T->length() <= SelEnd)
241+
S.Offset = SM.getFileOffset(Sel[I].location());
242+
if (S.Offset >= SelBegin && S.Offset + Sel[I].length() <= SelEnd)
231243
S.Selected = SelectionTree::Complete;
232244
else
233245
S.Selected = SelectionTree::Partial;

clang-tools-extra/clangd/URI.cpp

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,35 +26,56 @@ inline llvm::Error make_string_error(const llvm::Twine &Message) {
2626
llvm::inconvertibleErrorCode());
2727
}
2828

29+
bool isWindowsPath(llvm::StringRef Path) {
30+
return Path.size() > 1 && llvm::isAlpha(Path[0]) && Path[1] == ':';
31+
}
32+
33+
bool isNetworkPath(llvm::StringRef Path) {
34+
return Path.size() > 2 && Path[0] == Path[1] &&
35+
llvm::sys::path::is_separator(Path[0]);
36+
}
37+
2938
/// This manages file paths in the file system. All paths in the scheme
3039
/// are absolute (with leading '/').
3140
/// Note that this scheme is hardcoded into the library and not registered in
3241
/// registry.
3342
class FileSystemScheme : public URIScheme {
3443
public:
3544
llvm::Expected<std::string>
36-
getAbsolutePath(llvm::StringRef /*Authority*/, llvm::StringRef Body,
45+
getAbsolutePath(llvm::StringRef Authority, llvm::StringRef Body,
3746
llvm::StringRef /*HintPath*/) const override {
3847
if (!Body.startswith("/"))
3948
return make_string_error("File scheme: expect body to be an absolute "
4049
"path starting with '/': " +
4150
Body);
42-
// For Windows paths e.g. /X:
43-
if (Body.size() > 2 && Body[0] == '/' && Body[2] == ':')
51+
llvm::SmallString<128> Path;
52+
if (!Authority.empty()) {
53+
// Windows UNC paths e.g. file://server/share => \\server\share
54+
("//" + Authority).toVector(Path);
55+
} else if (isWindowsPath(Body.substr(1))) {
56+
// Windows paths e.g. file:///X:/path => X:\path
4457
Body.consume_front("/");
45-
llvm::SmallVector<char, 16> Path(Body.begin(), Body.end());
58+
}
59+
Path.append(Body);
4660
llvm::sys::path::native(Path);
47-
return std::string(Path.begin(), Path.end());
61+
return std::string(Path);
4862
}
4963

5064
llvm::Expected<URI>
5165
uriFromAbsolutePath(llvm::StringRef AbsolutePath) const override {
5266
std::string Body;
53-
// For Windows paths e.g. X:
54-
if (AbsolutePath.size() > 1 && AbsolutePath[1] == ':')
67+
llvm::StringRef Authority;
68+
llvm::StringRef Root = llvm::sys::path::root_name(AbsolutePath);
69+
if (isNetworkPath(Root)) {
70+
// Windows UNC paths e.g. \\server\share => file://server/share
71+
Authority = Root.drop_front(2);
72+
AbsolutePath.consume_front(Root);
73+
} else if (isWindowsPath(Root)) {
74+
// Windows paths e.g. X:\path => file:///X:/path
5575
Body = "/";
76+
}
5677
Body += llvm::sys::path::convert_to_slash(AbsolutePath);
57-
return URI("file", /*Authority=*/"", Body);
78+
return URI("file", Authority, Body);
5879
}
5980
};
6081

@@ -96,13 +117,13 @@ bool shouldEscape(unsigned char C) {
96117
void percentEncode(llvm::StringRef Content, std::string &Out) {
97118
std::string Result;
98119
for (unsigned char C : Content)
99-
if (shouldEscape(C))
100-
{
120+
if (shouldEscape(C)) {
101121
Out.push_back('%');
102122
Out.push_back(llvm::hexdigit(C / 16));
103123
Out.push_back(llvm::hexdigit(C % 16));
104-
} else
105-
{ Out.push_back(C); }
124+
} else {
125+
Out.push_back(C);
126+
}
106127
}
107128

108129
/// Decodes a string according to percent-encoding.

0 commit comments

Comments
 (0)