Skip to content

Commit 3b41e3b

Browse files
committed
Merge from 'main' to 'sycl-web' (#27)
CONFLICT (content): Merge conflict in clang/lib/Driver/Driver.cpp
2 parents 3ecf343 + 4f14b80 commit 3b41e3b

File tree

111 files changed

+1601
-1391
lines changed

Some content is hidden

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

111 files changed

+1601
-1391
lines changed

clang-tools-extra/test/clang-tidy/checkers/readability-container-size-empty.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ std::string s_func() {
100100
return std::string();
101101
}
102102

103-
int main() {
103+
void takesBool(bool)
104+
{
105+
106+
}
107+
108+
bool returnsBool() {
104109
std::set<int> intSet;
105110
std::string str;
106111
std::string str2;
@@ -397,6 +402,42 @@ int main() {
397402
;
398403
// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: the 'empty' method should be used
399404
// CHECK-FIXES: {{^ }}if (derived.empty()){{$}}
405+
406+
takesBool(derived.size());
407+
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: the 'empty' method should be used
408+
// CHECK-FIXES: {{^ }}takesBool(!derived.empty());
409+
410+
takesBool(derived.size() == 0);
411+
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: the 'empty' method should be used
412+
// CHECK-FIXES: {{^ }}takesBool(derived.empty());
413+
414+
takesBool(derived.size() != 0);
415+
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: the 'empty' method should be used
416+
// CHECK-FIXES: {{^ }}takesBool(!derived.empty());
417+
418+
bool b1 = derived.size();
419+
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: the 'empty' method should be used
420+
// CHECK-FIXES: {{^ }}bool b1 = !derived.empty();
421+
422+
bool b2(derived.size());
423+
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: the 'empty' method should be used
424+
// CHECK-FIXES: {{^ }}bool b2(!derived.empty());
425+
426+
auto b3 = static_cast<bool>(derived.size());
427+
// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: the 'empty' method should be used
428+
// CHECK-FIXES: {{^ }}auto b3 = static_cast<bool>(!derived.empty());
429+
430+
auto b4 = (bool)derived.size();
431+
// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: the 'empty' method should be used
432+
// CHECK-FIXES: {{^ }}auto b4 = (bool)!derived.empty();
433+
434+
auto b5 = bool(derived.size());
435+
// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: the 'empty' method should be used
436+
// CHECK-FIXES: {{^ }}auto b5 = bool(!derived.empty());
437+
438+
return derived.size();
439+
// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: the 'empty' method should be used
440+
// CHECK-FIXES: {{^ }}return !derived.empty();
400441
}
401442

402443
#define CHECKSIZE(x) if (x.size()) {}

clang/include/clang/AST/ComputeDependence.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class ObjCMessageExpr;
107107
ExprDependence computeDependence(FullExpr *E);
108108
ExprDependence computeDependence(OpaqueValueExpr *E);
109109
ExprDependence computeDependence(ParenExpr *E);
110-
ExprDependence computeDependence(UnaryOperator *E);
110+
ExprDependence computeDependence(UnaryOperator *E, const ASTContext &Ctx);
111111
ExprDependence computeDependence(UnaryExprOrTypeTraitExpr *E);
112112
ExprDependence computeDependence(ArraySubscriptExpr *E);
113113
ExprDependence computeDependence(MatrixSubscriptExpr *E);

clang/include/clang/AST/Decl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,9 @@ class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
12631263
/// constant expression, according to the relevant language standard.
12641264
/// This only checks properties of the declaration, and does not check
12651265
/// whether the initializer is in fact a constant expression.
1266+
///
1267+
/// This corresponds to C++20 [expr.const]p3's notion of a
1268+
/// "potentially-constant" variable.
12661269
bool mightBeUsableInConstantExpressions(const ASTContext &C) const;
12671270

12681271
/// Determine whether this variable's value can be used in a

clang/include/clang/ASTMatchers/ASTMatchersInternal.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,10 +1064,11 @@ class HasDeclarationMatcher : public MatcherInterface<T> {
10641064
/// is \c NULL.
10651065
bool matchesDecl(const Decl *Node, ASTMatchFinder *Finder,
10661066
BoundNodesTreeBuilder *Builder) const {
1067-
if (Finder->isTraversalIgnoringImplicitNodes() && Node->isImplicit())
1068-
return false;
1069-
return Node != nullptr && this->InnerMatcher.matches(
1070-
DynTypedNode::create(*Node), Finder, Builder);
1067+
return Node != nullptr &&
1068+
!(Finder->isTraversalIgnoringImplicitNodes() &&
1069+
Node->isImplicit()) &&
1070+
this->InnerMatcher.matches(DynTypedNode::create(*Node), Finder,
1071+
Builder);
10711072
}
10721073
};
10731074

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,16 +1291,6 @@ def err_expected_end_declare_target_or_variant : Error<
12911291
def err_expected_begin_declare_variant
12921292
: Error<"'#pragma omp end declare variant' with no matching '#pragma omp "
12931293
"begin declare variant'">;
1294-
def err_expected_begin_assumes
1295-
: Error<"'#pragma omp end assumes' with no matching '#pragma omp begin assumes'">;
1296-
def warn_omp_unknown_assumption_clause_missing_id
1297-
: Warning<"valid %0 clauses start with %1; %select{token|tokens}2 will be ignored">,
1298-
InGroup<OpenMPClauses>;
1299-
def warn_omp_unknown_assumption_clause_without_args
1300-
: Warning<"%0 clause should not be followed by arguments; tokens will be ignored">,
1301-
InGroup<OpenMPClauses>;
1302-
def note_omp_assumption_clause_continue_here
1303-
: Note<"the ignored tokens spans until here">;
13041294
def err_omp_declare_target_unexpected_clause: Error<
13051295
"unexpected '%0' clause, only %select{'to' or 'link'|'to', 'link' or 'device_type'}1 clauses expected">;
13061296
def err_omp_expected_clause: Error<

clang/include/clang/Parse/Parser.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3113,13 +3113,6 @@ class Parser : public CodeCompletionHandler {
31133113
void ParseOMPDeclareVariantClauses(DeclGroupPtrTy Ptr, CachedTokens &Toks,
31143114
SourceLocation Loc);
31153115

3116-
/// Parse 'omp [begin] assume[s]' directive.
3117-
void ParseOpenMPAssumesDirective(OpenMPDirectiveKind DKind,
3118-
SourceLocation Loc);
3119-
3120-
/// Parse 'omp end assumes' directive.
3121-
void ParseOpenMPEndAssumesDirective(SourceLocation Loc);
3122-
31233116
/// Parse clauses for '#pragma omp declare target'.
31243117
DeclGroupPtrTy ParseOMPDeclareTargetClauses();
31253118
/// Parse '#pragma omp end declare target'.

clang/include/clang/Sema/Sema.h

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10295,13 +10295,6 @@ class Sema final {
1029510295
/// The current `omp begin/end declare variant` scopes.
1029610296
SmallVector<OMPDeclareVariantScope, 4> OMPDeclareVariantScopes;
1029710297

10298-
/// The current `omp begin/end assumes` scopes.
10299-
SmallVector<AssumptionAttr *, 4> OMPAssumeScoped;
10300-
10301-
/// All `omp assumes` we encountered so far.
10302-
SmallVector<AssumptionAttr *, 4> OMPAssumeGlobal;
10303-
10304-
public:
1030510298
/// The declarator \p D defines a function in the scope \p S which is nested
1030610299
/// in an `omp begin/end declare variant` scope. In this method we create a
1030710300
/// declaration for \p D and rename \p D according to the OpenMP context
@@ -10315,11 +10308,10 @@ class Sema final {
1031510308
void ActOnFinishedFunctionDefinitionInOpenMPDeclareVariantScope(
1031610309
Decl *D, SmallVectorImpl<FunctionDecl *> &Bases);
1031710310

10318-
/// Act on \p D, a function definition inside of an `omp [begin/end] assumes`.
10319-
void ActOnFinishedFunctionDefinitionInOpenMPAssumeScope(Decl *D);
10311+
public:
1032010312

10321-
/// Can we exit an OpenMP declare variant scope at the moment.
10322-
bool isInOpenMPDeclareVariantScope() const {
10313+
/// Can we exit a scope at the moment.
10314+
bool isInOpenMPDeclareVariantScope() {
1032310315
return !OMPDeclareVariantScopes.empty();
1032410316
}
1032510317

@@ -10435,22 +10427,6 @@ class Sema final {
1043510427
ArrayRef<Expr *> VarList,
1043610428
ArrayRef<OMPClause *> Clauses,
1043710429
DeclContext *Owner = nullptr);
10438-
10439-
/// Called on well-formed '#pragma omp [begin] assume[s]'.
10440-
void ActOnOpenMPAssumesDirective(SourceLocation Loc,
10441-
OpenMPDirectiveKind DKind,
10442-
ArrayRef<StringRef> Assumptions,
10443-
bool SkippedClauses);
10444-
10445-
/// Check if there is an active global `omp begin assumes` directive.
10446-
bool isInOpenMPAssumeScope() const { return !OMPAssumeScoped.empty(); }
10447-
10448-
/// Check if there is an active global `omp assumes` directive.
10449-
bool hasGlobalOpenMPAssumes() const { return !OMPAssumeGlobal.empty(); }
10450-
10451-
/// Called on well-formed '#pragma omp end assumes'.
10452-
void ActOnOpenMPEndAssumesDirective();
10453-
1045410430
/// Called on well-formed '#pragma omp requires'.
1045510431
DeclGroupPtrTy ActOnOpenMPRequiresDirective(SourceLocation Loc,
1045610432
ArrayRef<OMPClause *> ClauseList);

clang/lib/AST/ComputeDependence.cpp

Lines changed: 83 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,39 @@ ExprDependence clang::computeDependence(ParenExpr *E) {
3737
return E->getSubExpr()->getDependence();
3838
}
3939

40-
ExprDependence clang::computeDependence(UnaryOperator *E) {
41-
return toExprDependence(E->getType()->getDependence()) |
42-
E->getSubExpr()->getDependence();
40+
ExprDependence clang::computeDependence(UnaryOperator *E,
41+
const ASTContext &Ctx) {
42+
ExprDependence Dep = toExprDependence(E->getType()->getDependence()) |
43+
E->getSubExpr()->getDependence();
44+
45+
// C++ [temp.dep.constexpr]p5:
46+
// An expression of the form & qualified-id where the qualified-id names a
47+
// dependent member of the current instantiation is value-dependent. An
48+
// expression of the form & cast-expression is also value-dependent if
49+
// evaluating cast-expression as a core constant expression succeeds and
50+
// the result of the evaluation refers to a templated entity that is an
51+
// object with static or thread storage duration or a member function.
52+
//
53+
// What this amounts to is: constant-evaluate the operand and check whether it
54+
// refers to a templated entity other than a variable with local storage.
55+
if (Ctx.getLangOpts().CPlusPlus && E->getOpcode() == UO_AddrOf &&
56+
!(Dep & ExprDependence::Value)) {
57+
Expr::EvalResult Result;
58+
SmallVector<PartialDiagnosticAt, 8> Diag;
59+
Result.Diag = &Diag;
60+
// FIXME: This doesn't enforce the C++98 constant expression rules.
61+
if (E->getSubExpr()->EvaluateAsConstantExpr(Result, Ctx) && Diag.empty() &&
62+
Result.Val.isLValue()) {
63+
auto *VD = Result.Val.getLValueBase().dyn_cast<const ValueDecl *>();
64+
if (VD && VD->isTemplated()) {
65+
auto *VarD = dyn_cast<VarDecl>(VD);
66+
if (!VarD || !VarD->hasLocalStorage())
67+
Dep |= ExprDependence::Value;
68+
}
69+
}
70+
}
71+
72+
return Dep;
4373
}
4474

4575
ExprDependence clang::computeDependence(UnaryExprOrTypeTraitExpr *E) {
@@ -423,22 +453,21 @@ ExprDependence clang::computeDependence(DeclRefExpr *E, const ASTContext &Ctx) {
423453
Deps |= ExprDependence::UnexpandedPack;
424454
Deps |= toExprDependence(Type->getDependence()) & ExprDependence::Error;
425455

426-
// (TD) C++ [temp.dep.expr]p3:
456+
// C++ [temp.dep.expr]p3:
427457
// An id-expression is type-dependent if it contains:
428-
//
429-
// and
430-
//
431-
// (VD) C++ [temp.dep.constexpr]p2:
432-
// An identifier is value-dependent if it is:
433458

434-
// (TD) - an identifier that was declared with dependent type
435-
// (VD) - a name declared with a dependent type,
459+
// - an identifier associated by name lookup with one or more declarations
460+
// declared with a dependent type
461+
//
462+
// [The "or more" case is not modeled as a DeclRefExpr. There are a bunch
463+
// more bullets here that we handle by treating the declaration as having a
464+
// dependent type if they involve a placeholder type that can't be deduced.]
436465
if (Type->isDependentType())
437466
return Deps | ExprDependence::TypeValueInstantiation;
438467
else if (Type->isInstantiationDependentType())
439468
Deps |= ExprDependence::Instantiation;
440469

441-
// (TD) - a conversion-function-id that specifies a dependent type
470+
// - a conversion-function-id that specifies a dependent type
442471
if (Decl->getDeclName().getNameKind() ==
443472
DeclarationName::CXXConversionFunctionName) {
444473
QualType T = Decl->getDeclName().getCXXNameType();
@@ -449,23 +478,28 @@ ExprDependence clang::computeDependence(DeclRefExpr *E, const ASTContext &Ctx) {
449478
Deps |= ExprDependence::Instantiation;
450479
}
451480

452-
// (VD) - the name of a non-type template parameter,
481+
// - a template-id that is dependent,
482+
// - a nested-name-specifier or a qualified-id that names a member of an
483+
// unknown specialization
484+
// [These are not modeled as DeclRefExprs.]
485+
486+
// or if it names a dependent member of the current instantiation that is a
487+
// static data member of type "array of unknown bound of T" for some T
488+
// [handled below].
489+
490+
// C++ [temp.dep.constexpr]p2:
491+
// An id-expression is value-dependent if:
492+
493+
// - it is type-dependent [handled above]
494+
495+
// - it is the name of a non-type template parameter,
453496
if (isa<NonTypeTemplateParmDecl>(Decl))
454497
return Deps | ExprDependence::ValueInstantiation;
455498

456-
// (VD) - a constant with integral or enumeration type and is
457-
// initialized with an expression that is value-dependent.
458-
// (VD) - a constant with literal type and is initialized with an
459-
// expression that is value-dependent [C++11].
460-
// (VD) - FIXME: Missing from the standard:
461-
// - an entity with reference type and is initialized with an
462-
// expression that is value-dependent [C++11]
463-
if (VarDecl *Var = dyn_cast<VarDecl>(Decl)) {
464-
if ((Ctx.getLangOpts().CPlusPlus11
465-
? Var->getType()->isLiteralType(Ctx)
466-
: Var->getType()->isIntegralOrEnumerationType()) &&
467-
(Var->getType().isConstQualified() ||
468-
Var->getType()->isReferenceType())) {
499+
// - it names a potentially-constant variable that is initialized with an
500+
// expression that is value-dependent
501+
if (const auto *Var = dyn_cast<VarDecl>(Decl)) {
502+
if (Var->mightBeUsableInConstantExpressions(Ctx)) {
469503
if (const Expr *Init = Var->getAnyInitializer()) {
470504
if (Init->isValueDependent())
471505
Deps |= ExprDependence::ValueInstantiation;
@@ -474,25 +508,35 @@ ExprDependence clang::computeDependence(DeclRefExpr *E, const ASTContext &Ctx) {
474508
}
475509
}
476510

477-
// (VD) - FIXME: Missing from the standard:
478-
// - a member function or a static data member of the current
479-
// instantiation
511+
// - it names a static data member that is a dependent member of the
512+
// current instantiation and is not initialized in a member-declarator,
480513
if (Var->isStaticDataMember() &&
481-
Var->getDeclContext()->isDependentContext()) {
482-
Deps |= ExprDependence::ValueInstantiation;
483-
TypeSourceInfo *TInfo = Var->getFirstDecl()->getTypeSourceInfo();
484-
if (TInfo->getType()->isIncompleteArrayType())
485-
Deps |= ExprDependence::Type;
514+
Var->getDeclContext()->isDependentContext() &&
515+
!Var->getFirstDecl()->hasInit()) {
516+
const VarDecl *First = Var->getFirstDecl();
517+
TypeSourceInfo *TInfo = First->getTypeSourceInfo();
518+
if (TInfo->getType()->isIncompleteArrayType()) {
519+
Deps |= ExprDependence::TypeValueInstantiation;
520+
} else if (!First->hasInit()) {
521+
Deps |= ExprDependence::ValueInstantiation;
522+
}
486523
}
487524

488525
return Deps;
489526
}
490527

491-
// (VD) - FIXME: Missing from the standard:
492-
// - a member function or a static data member of the current
493-
// instantiation
494-
if (isa<CXXMethodDecl>(Decl) && Decl->getDeclContext()->isDependentContext())
495-
Deps |= ExprDependence::ValueInstantiation;
528+
// - it names a static member function that is a dependent member of the
529+
// current instantiation
530+
//
531+
// FIXME: It's unclear that the restriction to static members here has any
532+
// effect: any use of a non-static member function name requires either
533+
// forming a pointer-to-member or providing an object parameter, either of
534+
// which makes the overall expression value-dependent.
535+
if (auto *MD = dyn_cast<CXXMethodDecl>(Decl)) {
536+
if (MD->isStatic() && Decl->getDeclContext()->isDependentContext())
537+
Deps |= ExprDependence::ValueInstantiation;
538+
}
539+
496540
return Deps;
497541
}
498542

clang/lib/AST/Expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4495,7 +4495,7 @@ UnaryOperator::UnaryOperator(const ASTContext &Ctx, Expr *input, Opcode opc,
44954495
UnaryOperatorBits.HasFPFeatures = FPFeatures.requiresTrailingStorage();
44964496
if (hasStoredFPFeatures())
44974497
setStoredFPFeatures(FPFeatures);
4498-
setDependence(computeDependence(this));
4498+
setDependence(computeDependence(this, Ctx));
44994499
}
45004500

45014501
UnaryOperator *UnaryOperator::Create(const ASTContext &C, Expr *input,

clang/lib/ASTMatchers/Dynamic/Marshallers.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,10 @@ template <> struct ArgTypeTraits<unsigned> {
161161
template <> struct ArgTypeTraits<attr::Kind> {
162162
private:
163163
static Optional<attr::Kind> getAttrKind(llvm::StringRef AttrKind) {
164+
if (!AttrKind.consume_front("attr::"))
165+
return llvm::None;
164166
return llvm::StringSwitch<Optional<attr::Kind>>(AttrKind)
165-
#define ATTR(X) .Case("attr::" #X, attr:: X)
167+
#define ATTR(X) .Case(#X, attr::X)
166168
#include "clang/Basic/AttrList.inc"
167169
.Default(llvm::None);
168170
}
@@ -189,8 +191,10 @@ template <> struct ArgTypeTraits<attr::Kind> {
189191
template <> struct ArgTypeTraits<CastKind> {
190192
private:
191193
static Optional<CastKind> getCastKind(llvm::StringRef AttrKind) {
194+
if (!AttrKind.consume_front("CK_"))
195+
return llvm::None;
192196
return llvm::StringSwitch<Optional<CastKind>>(AttrKind)
193-
#define CAST_OPERATION(Name) .Case("CK_" #Name, CK_##Name)
197+
#define CAST_OPERATION(Name) .Case(#Name, CK_##Name)
194198
#include "clang/AST/OperationKinds.def"
195199
.Default(llvm::None);
196200
}
@@ -265,11 +269,12 @@ template <> struct ArgTypeTraits<UnaryExprOrTypeTrait> {
265269
private:
266270
static Optional<UnaryExprOrTypeTrait>
267271
getUnaryOrTypeTraitKind(llvm::StringRef ClauseKind) {
272+
if (!ClauseKind.consume_front("UETT_"))
273+
return llvm::None;
268274
return llvm::StringSwitch<Optional<UnaryExprOrTypeTrait>>(ClauseKind)
269-
#define UNARY_EXPR_OR_TYPE_TRAIT(Spelling, Name, Key) \
270-
.Case("UETT_" #Name, UETT_##Name)
275+
#define UNARY_EXPR_OR_TYPE_TRAIT(Spelling, Name, Key) .Case(#Name, UETT_##Name)
271276
#define CXX11_UNARY_EXPR_OR_TYPE_TRAIT(Spelling, Name, Key) \
272-
.Case("UETT_" #Name, UETT_##Name)
277+
.Case(#Name, UETT_##Name)
273278
#include "clang/Basic/TokenKinds.def"
274279
.Default(llvm::None);
275280
}

0 commit comments

Comments
 (0)