Skip to content

Commit ad67b8d

Browse files
authored
Merge branch 'main' into change-VPReductionRecipe-inherit-from-VPRecipeWithIRFlags
2 parents 6c6ccb2 + 584f8cc commit ad67b8d

File tree

314 files changed

+69014
-3205
lines changed

Some content is hidden

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

314 files changed

+69014
-3205
lines changed

clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
namespace clang::tidy::bugprone {
2020
using ast_matchers::MatchFinder;
2121
using dataflow::UncheckedOptionalAccessDiagnoser;
22+
using dataflow::UncheckedOptionalAccessDiagnostic;
2223
using dataflow::UncheckedOptionalAccessModel;
2324

2425
static constexpr llvm::StringLiteral FuncID("fun");
@@ -52,14 +53,16 @@ void UncheckedOptionalAccessCheck::check(
5253
UncheckedOptionalAccessDiagnoser Diagnoser(ModelOptions);
5354
// FIXME: Allow user to set the (defaulted) SAT iterations max for
5455
// `diagnoseFunction` with config options.
55-
if (llvm::Expected<llvm::SmallVector<SourceLocation>> Locs =
56-
dataflow::diagnoseFunction<UncheckedOptionalAccessModel,
57-
SourceLocation>(*FuncDecl, *Result.Context,
58-
Diagnoser))
59-
for (const SourceLocation &Loc : *Locs)
60-
diag(Loc, "unchecked access to optional value");
56+
if (llvm::Expected<llvm::SmallVector<UncheckedOptionalAccessDiagnostic>>
57+
Diags = dataflow::diagnoseFunction<UncheckedOptionalAccessModel,
58+
UncheckedOptionalAccessDiagnostic>(
59+
*FuncDecl, *Result.Context, Diagnoser))
60+
for (const UncheckedOptionalAccessDiagnostic &Diag : *Diags) {
61+
diag(Diag.Range.getBegin(), "unchecked access to optional value")
62+
<< Diag.Range;
63+
}
6164
else
62-
llvm::consumeError(Locs.takeError());
65+
llvm::consumeError(Diags.takeError());
6366
}
6467

6568
} // namespace clang::tidy::bugprone

clang/docs/LanguageExtensions.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,6 +1959,32 @@ references can be used instead of numeric references.
19591959
return -1;
19601960
}
19611961

1962+
1963+
Constexpr strings in GNU ASM statememts
1964+
=======================================
1965+
1966+
In C++11 mode (and greater), Clang supports specifying the template,
1967+
constraints, and clobber strings with a parenthesized constant expression
1968+
producing an object with the following member functions
1969+
1970+
.. code-block:: c++
1971+
1972+
constexpr const char* data() const;
1973+
constexpr size_t size() const;
1974+
1975+
such as ``std::string``, ``std::string_view``, ``std::vector<char>``.
1976+
This mechanism follow the same rules as ``static_assert`` messages in
1977+
C++26, see ``[dcl.pre]/p12``.
1978+
1979+
Query for this feature with ``__has_extension(gnu_asm_constexpr_strings)``.
1980+
1981+
.. code-block:: c++
1982+
1983+
int foo() {
1984+
asm((std::string_view("nop")) ::: (std::string_view("memory")));
1985+
}
1986+
1987+
19621988
Objective-C Features
19631989
====================
19641990

clang/docs/ReleaseNotes.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ What's New in Clang |release|?
7474
C++ Language Changes
7575
--------------------
7676

77+
- Similarly to GCC, Clang now supports constant expressions in
78+
the strings of a GNU ``asm`` statement.
79+
80+
.. code-block:: c++
81+
82+
int foo() {
83+
asm((std::string_view("nop")) ::: (std::string_view("memory")));
84+
}
85+
7786
C++2c Feature Support
7887
^^^^^^^^^^^^^^^^^^^^^
7988

@@ -251,6 +260,9 @@ Improvements to Clang's diagnostics
251260
- The ``-Wsign-compare`` warning now treats expressions with bitwise not(~) and minus(-) as signed integers
252261
except for the case where the operand is an unsigned integer
253262
and throws warning if they are compared with unsigned integers (##18878).
263+
- The ``-Wunnecessary-virtual-specifier`` warning has been added to warn about
264+
methods which are marked as virtual inside a ``final`` class, and hence can
265+
never be overridden.
254266

255267
- Improve the diagnostics for chained comparisons to report actual expressions and operators (#GH129069).
256268

clang/include/clang/AST/Expr.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,10 @@ class Expr : public ValueStmt {
787787
const Expr *PtrExpression, ASTContext &Ctx,
788788
EvalResult &Status) const;
789789

790+
bool EvaluateCharRangeAsString(APValue &Result, const Expr *SizeExpression,
791+
const Expr *PtrExpression, ASTContext &Ctx,
792+
EvalResult &Status) const;
793+
790794
/// If the current Expr can be evaluated to a pointer to a null-terminated
791795
/// constant string, return the constant string (without the terminating
792796
/// null).

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,15 +2410,15 @@ DEF_TRAVERSE_DECL(ImplicitConceptSpecializationDecl, {
24102410
}
24112411

24122412
DEF_TRAVERSE_STMT(GCCAsmStmt, {
2413-
TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getAsmString());
2413+
TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getAsmStringExpr());
24142414
for (unsigned I = 0, E = S->getNumInputs(); I < E; ++I) {
2415-
TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getInputConstraintLiteral(I));
2415+
TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getInputConstraintExpr(I));
24162416
}
24172417
for (unsigned I = 0, E = S->getNumOutputs(); I < E; ++I) {
2418-
TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOutputConstraintLiteral(I));
2418+
TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getOutputConstraintExpr(I));
24192419
}
24202420
for (unsigned I = 0, E = S->getNumClobbers(); I < E; ++I) {
2421-
TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getClobberStringLiteral(I));
2421+
TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(S->getClobberExpr(I));
24222422
}
24232423
// children() iterates over inputExpr and outputExpr.
24242424
})

clang/include/clang/AST/Stmt.h

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3193,7 +3193,7 @@ class AsmStmt : public Stmt {
31933193
/// getOutputConstraint - Return the constraint string for the specified
31943194
/// output operand. All output constraints are known to be non-empty (either
31953195
/// '=' or '+').
3196-
StringRef getOutputConstraint(unsigned i) const;
3196+
std::string getOutputConstraint(unsigned i) const;
31973197

31983198
/// isOutputPlusConstraint - Return true if the specified output constraint
31993199
/// is a "+" constraint (which is both an input and an output) or false if it
@@ -3214,14 +3214,14 @@ class AsmStmt : public Stmt {
32143214

32153215
/// getInputConstraint - Return the specified input constraint. Unlike output
32163216
/// constraints, these can be empty.
3217-
StringRef getInputConstraint(unsigned i) const;
3217+
std::string getInputConstraint(unsigned i) const;
32183218

32193219
const Expr *getInputExpr(unsigned i) const;
32203220

32213221
//===--- Other ---===//
32223222

32233223
unsigned getNumClobbers() const { return NumClobbers; }
3224-
StringRef getClobber(unsigned i) const;
3224+
std::string getClobber(unsigned i) const;
32253225

32263226
static bool classof(const Stmt *T) {
32273227
return T->getStmtClass() == GCCAsmStmtClass ||
@@ -3302,21 +3302,20 @@ class GCCAsmStmt : public AsmStmt {
33023302
friend class ASTStmtReader;
33033303

33043304
SourceLocation RParenLoc;
3305-
StringLiteral *AsmStr;
3305+
Expr *AsmStr;
33063306

33073307
// FIXME: If we wanted to, we could allocate all of these in one big array.
3308-
StringLiteral **Constraints = nullptr;
3309-
StringLiteral **Clobbers = nullptr;
3308+
Expr **Constraints = nullptr;
3309+
Expr **Clobbers = nullptr;
33103310
IdentifierInfo **Names = nullptr;
33113311
unsigned NumLabels = 0;
33123312

33133313
public:
33143314
GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, bool issimple,
33153315
bool isvolatile, unsigned numoutputs, unsigned numinputs,
3316-
IdentifierInfo **names, StringLiteral **constraints, Expr **exprs,
3317-
StringLiteral *asmstr, unsigned numclobbers,
3318-
StringLiteral **clobbers, unsigned numlabels,
3319-
SourceLocation rparenloc);
3316+
IdentifierInfo **names, Expr **constraints, Expr **exprs,
3317+
Expr *asmstr, unsigned numclobbers, Expr **clobbers,
3318+
unsigned numlabels, SourceLocation rparenloc);
33203319

33213320
/// Build an empty inline-assembly statement.
33223321
explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty) {}
@@ -3326,9 +3325,11 @@ class GCCAsmStmt : public AsmStmt {
33263325

33273326
//===--- Asm String Analysis ---===//
33283327

3329-
const StringLiteral *getAsmString() const { return AsmStr; }
3330-
StringLiteral *getAsmString() { return AsmStr; }
3331-
void setAsmString(StringLiteral *E) { AsmStr = E; }
3328+
const Expr *getAsmStringExpr() const { return AsmStr; }
3329+
Expr *getAsmStringExpr() { return AsmStr; }
3330+
void setAsmStringExpr(Expr *E) { AsmStr = E; }
3331+
3332+
std::string getAsmString() const;
33323333

33333334
/// AsmStringPiece - this is part of a decomposed asm string specification
33343335
/// (for use with the AnalyzeAsmString function below). An asm string is
@@ -3397,14 +3398,12 @@ class GCCAsmStmt : public AsmStmt {
33973398
return {};
33983399
}
33993400

3400-
StringRef getOutputConstraint(unsigned i) const;
3401+
std::string getOutputConstraint(unsigned i) const;
34013402

3402-
const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
3403-
return Constraints[i];
3404-
}
3405-
StringLiteral *getOutputConstraintLiteral(unsigned i) {
3403+
const Expr *getOutputConstraintExpr(unsigned i) const {
34063404
return Constraints[i];
34073405
}
3406+
Expr *getOutputConstraintExpr(unsigned i) { return Constraints[i]; }
34083407

34093408
Expr *getOutputExpr(unsigned i);
34103409

@@ -3425,12 +3424,12 @@ class GCCAsmStmt : public AsmStmt {
34253424
return {};
34263425
}
34273426

3428-
StringRef getInputConstraint(unsigned i) const;
3427+
std::string getInputConstraint(unsigned i) const;
34293428

3430-
const StringLiteral *getInputConstraintLiteral(unsigned i) const {
3429+
const Expr *getInputConstraintExpr(unsigned i) const {
34313430
return Constraints[i + NumOutputs];
34323431
}
3433-
StringLiteral *getInputConstraintLiteral(unsigned i) {
3432+
Expr *getInputConstraintExpr(unsigned i) {
34343433
return Constraints[i + NumOutputs];
34353434
}
34363435

@@ -3441,6 +3440,8 @@ class GCCAsmStmt : public AsmStmt {
34413440
return const_cast<GCCAsmStmt*>(this)->getInputExpr(i);
34423441
}
34433442

3443+
static std::string ExtractStringFromGCCAsmStmtComponent(const Expr *E);
3444+
34443445
//===--- Labels ---===//
34453446

34463447
bool isAsmGoto() const {
@@ -3489,12 +3490,9 @@ class GCCAsmStmt : public AsmStmt {
34893490
private:
34903491
void setOutputsAndInputsAndClobbers(const ASTContext &C,
34913492
IdentifierInfo **Names,
3492-
StringLiteral **Constraints,
3493-
Stmt **Exprs,
3494-
unsigned NumOutputs,
3495-
unsigned NumInputs,
3496-
unsigned NumLabels,
3497-
StringLiteral **Clobbers,
3493+
Expr **Constraints, Stmt **Exprs,
3494+
unsigned NumOutputs, unsigned NumInputs,
3495+
unsigned NumLabels, Expr **Clobbers,
34983496
unsigned NumClobbers);
34993497

35003498
public:
@@ -3505,12 +3503,10 @@ class GCCAsmStmt : public AsmStmt {
35053503
/// This returns -1 if the operand name is invalid.
35063504
int getNamedOperand(StringRef SymbolicName) const;
35073505

3508-
StringRef getClobber(unsigned i) const;
3506+
std::string getClobber(unsigned i) const;
35093507

3510-
StringLiteral *getClobberStringLiteral(unsigned i) { return Clobbers[i]; }
3511-
const StringLiteral *getClobberStringLiteral(unsigned i) const {
3512-
return Clobbers[i];
3513-
}
3508+
Expr *getClobberExpr(unsigned i) { return Clobbers[i]; }
3509+
const Expr *getClobberExpr(unsigned i) const { return Clobbers[i]; }
35143510

35153511
SourceLocation getBeginLoc() const LLVM_READONLY { return AsmLoc; }
35163512
SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }

clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h"
2121
#include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
2222
#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
23+
#include "clang/Analysis/FlowSensitive/MatchSwitch.h"
2324
#include "clang/Analysis/FlowSensitive/NoopLattice.h"
2425
#include "clang/Basic/SourceLocation.h"
2526
#include "llvm/ADT/SmallVector.h"
@@ -71,20 +72,26 @@ class UncheckedOptionalAccessModel
7172
TransferMatchSwitch;
7273
};
7374

75+
/// Diagnostic information for an unchecked optional access.
76+
struct UncheckedOptionalAccessDiagnostic {
77+
CharSourceRange Range;
78+
};
79+
7480
class UncheckedOptionalAccessDiagnoser {
7581
public:
7682
UncheckedOptionalAccessDiagnoser(
7783
UncheckedOptionalAccessModelOptions Options = {});
7884

79-
llvm::SmallVector<SourceLocation>
85+
llvm::SmallVector<UncheckedOptionalAccessDiagnostic>
8086
operator()(const CFGElement &Elt, ASTContext &Ctx,
8187
const TransferStateForDiagnostics<UncheckedOptionalAccessLattice>
8288
&State) {
8389
return DiagnoseMatchSwitch(Elt, Ctx, State.Env);
8490
}
8591

8692
private:
87-
CFGMatchSwitch<const Environment, llvm::SmallVector<SourceLocation>>
93+
CFGMatchSwitch<const Environment,
94+
llvm::SmallVector<UncheckedOptionalAccessDiagnostic>>
8895
DiagnoseMatchSwitch;
8996
};
9097

clang/include/clang/Basic/Attr.td

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4812,33 +4812,6 @@ def HLSLShader : InheritableAttr {
48124812
}];
48134813
}
48144814

4815-
def HLSLResource : InheritableAttr {
4816-
let Spellings = [];
4817-
let Subjects = SubjectList<[Struct]>;
4818-
let LangOpts = [HLSL];
4819-
let Args = [
4820-
EnumArgument<
4821-
"ResourceKind", "llvm::hlsl::ResourceKind",
4822-
/*is_string=*/0,
4823-
[
4824-
"Texture1D", "Texture2D", "Texture2DMS", "Texture3D", "TextureCube",
4825-
"Texture1DArray", "Texture2DArray", "Texture2DMSArray",
4826-
"TextureCubeArray", "TypedBuffer", "RawBuffer", "StructuredBuffer",
4827-
"CBuffer", "Sampler", "TBuffer", "RTAccelerationStructure",
4828-
"FeedbackTexture2D", "FeedbackTexture2DArray"
4829-
],
4830-
[
4831-
"Texture1D", "Texture2D", "Texture2DMS", "Texture3D", "TextureCube",
4832-
"Texture1DArray", "Texture2DArray", "Texture2DMSArray",
4833-
"TextureCubeArray", "TypedBuffer", "RawBuffer", "StructuredBuffer",
4834-
"CBuffer", "Sampler", "TBuffer", "RTAccelerationStructure",
4835-
"FeedbackTexture2D", "FeedbackTexture2DArray"
4836-
],
4837-
/*opt=*/0, /*fake=*/0, /*isExternalType=*/1, /*isCovered=*/0>
4838-
];
4839-
let Documentation = [InternalOnly];
4840-
}
4841-
48424815
def HLSLROV : TypeAttr {
48434816
let Spellings = [CXX11<"hlsl", "is_rov">];
48444817
let LangOpts = [HLSL];

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,19 @@ def CXX11WarnInconsistentOverrideMethod :
372372
def CXX11WarnSuggestOverrideDestructor : DiagGroup<"suggest-destructor-override">;
373373
def CXX11WarnSuggestOverride : DiagGroup<"suggest-override">;
374374

375+
def WarnUnnecessaryVirtualSpecifier : DiagGroup<"unnecessary-virtual-specifier"> {
376+
code Documentation = [{
377+
Warns when a ``final`` class contains a virtual method (including virtual
378+
destructors). Since ``final`` classes cannot be subclassed, their methods
379+
cannot be overridden, and hence the ``virtual`` specifier is useless.
380+
381+
The warning also detects virtual methods in classes whose destructor is
382+
``final``, for the same reason.
383+
384+
The warning does not fire on virtual methods which are also marked ``override``.
385+
}];
386+
}
387+
375388
// Original name of this warning in Clang
376389
def : DiagGroup<"c++0x-narrowing", [CXX11Narrowing]>;
377390

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,10 @@ def warn_cxx20_compat_label_end_of_compound_statement : Warning<
336336
def err_address_of_label_outside_fn : Error<
337337
"use of address-of-label extension outside of a function body">;
338338
def err_asm_operand_wide_string_literal : Error<
339-
"cannot use %select{unicode|wide|an empty}0 string literal in 'asm'">;
339+
"cannot use %select{unicode|wide}0 string literal in 'asm'">;
340+
341+
def err_asm_expected_string : Error<
342+
"expected string literal %select{or parenthesized constant expression |}0in 'asm'">;
340343
def err_expected_selector_for_method : Error<
341344
"expected selector for Objective-C method">;
342345
def err_expected_property_name : Error<"expected property name">;

0 commit comments

Comments
 (0)