Skip to content

Commit ec3ac93

Browse files
Merge branch 'main' into add-dwarfexprentry-api
2 parents c01a747 + c86c815 commit ec3ac93

File tree

168 files changed

+5661
-4829
lines changed

Some content is hidden

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

168 files changed

+5661
-4829
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,10 @@ Improvements to Clang's diagnostics
662662
#GH142457, #GH139913, #GH138850, #GH137867, #GH137860, #GH107840, #GH93308,
663663
#GH69470, #GH59391, #GH58172, #GH46215, #GH45915, #GH45891, #GH44490,
664664
#GH36703, #GH32903, #GH23312, #GH69874.
665+
666+
- Clang no longer emits a spurious -Wdangling-gsl warning in C++23 when
667+
iterating over an element of a temporary container in a range-based
668+
for loop.(#GH109793, #GH145164)
665669

666670
- Fixed false positives in ``-Wformat-truncation`` and ``-Wformat-overflow``
667671
diagnostics when floating-point numbers had both width field and plus or space

clang/include/clang/AST/Decl.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,11 @@ class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
10901090

10911091
LLVM_PREFERRED_TYPE(bool)
10921092
unsigned IsCXXCondDecl : 1;
1093+
1094+
/// Whether this variable is the implicit __range variable in a for-range
1095+
/// loop.
1096+
LLVM_PREFERRED_TYPE(bool)
1097+
unsigned IsCXXForRangeImplicitVar : 1;
10931098
};
10941099

10951100
union {
@@ -1591,6 +1596,19 @@ class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
15911596
NonParmVarDeclBits.IsCXXCondDecl = true;
15921597
}
15931598

1599+
/// Whether this variable is the implicit '__range' variable in C++
1600+
/// range-based for loops.
1601+
bool isCXXForRangeImplicitVar() const {
1602+
return isa<ParmVarDecl>(this) ? false
1603+
: NonParmVarDeclBits.IsCXXForRangeImplicitVar;
1604+
}
1605+
1606+
void setCXXForRangeImplicitVar(bool FRV) {
1607+
assert(!isa<ParmVarDecl>(this) &&
1608+
"Cannot set IsCXXForRangeImplicitVar on ParmVarDecl");
1609+
NonParmVarDeclBits.IsCXXForRangeImplicitVar = FRV;
1610+
}
1611+
15941612
/// Determines if this variable's alignment is dependent.
15951613
bool hasDependentAlignment() const;
15961614

clang/include/clang/Basic/riscv_andes_vector.td

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,35 @@ let RequiredFeatures = ["xandesvbfhcvt"],
6464
}
6565
}
6666

67+
// Andes Vector INT4 Load Extension (XAndesVSIntLoad)
68+
69+
let SupportOverloading = false,
70+
UnMaskedPolicyScheme = HasPassthruOperand in {
71+
multiclass RVVVLN8Builtin {
72+
let Name = NAME # "_v",
73+
IRName = "nds_vln",
74+
MaskedIRName = "nds_vln_mask",
75+
OverloadedName = NAME in
76+
def : RVVOutOp0Builtin<"v", "vPC0", "c">;
77+
}
78+
}
79+
80+
let SupportOverloading = false,
81+
UnMaskedPolicyScheme = HasPassthruOperand in {
82+
multiclass RVVVLNU8Builtin {
83+
let Name = NAME # "_v",
84+
IRName = "nds_vlnu",
85+
MaskedIRName = "nds_vlnu_mask",
86+
OverloadedName = NAME in
87+
def : RVVOutOp0Builtin<"Uv", "UvPC0", "c">;
88+
}
89+
}
90+
91+
let RequiredFeatures = ["xandesvsintload"] in {
92+
defm nds_vln8 : RVVVLN8Builtin;
93+
defm nds_vlnu8 : RVVVLNU8Builtin;
94+
}
95+
6796
// Andes Vector Packed FP16 Extension (XAndesVPackFPH)
6897

6998
multiclass RVVFPMAD {

clang/lib/AST/ExprConstant.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,11 +1428,11 @@ namespace {
14281428
}
14291429
bool destroy(bool RunDestructors = true) {
14301430
bool OK = cleanup(Info, RunDestructors, OldStackSize);
1431-
OldStackSize = -1U;
1431+
OldStackSize = std::numeric_limits<unsigned>::max();
14321432
return OK;
14331433
}
14341434
~ScopeRAII() {
1435-
if (OldStackSize != -1U)
1435+
if (OldStackSize != std::numeric_limits<unsigned>::max())
14361436
destroy(false);
14371437
// Body moved to a static method to encourage the compiler to inline away
14381438
// instances of this class.

clang/lib/Format/Format.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
#include "UnwrappedLineFormatter.h"
2323
#include "UsingDeclarationsSorter.h"
2424
#include "clang/Tooling/Inclusions/HeaderIncludes.h"
25+
2526
#include "llvm/ADT/Sequence.h"
27+
#include <limits>
2628

2729
#define DEBUG_TYPE "format-formatter"
2830

@@ -777,7 +779,7 @@ template <> struct MappingTraits<FormatStyle::SpacesInLineComment> {
777779
IO.mapOptional("Maximum", signedMaximum);
778780
Space.Maximum = static_cast<unsigned>(signedMaximum);
779781

780-
if (Space.Maximum != -1u)
782+
if (Space.Maximum < std::numeric_limits<unsigned>::max())
781783
Space.Minimum = std::min(Space.Minimum, Space.Maximum);
782784
}
783785
};
@@ -1672,7 +1674,8 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
16721674
LLVMStyle.SpacesBeforeTrailingComments = 1;
16731675
LLVMStyle.SpacesInAngles = FormatStyle::SIAS_Never;
16741676
LLVMStyle.SpacesInContainerLiterals = true;
1675-
LLVMStyle.SpacesInLineCommentPrefix = {/*Minimum=*/1, /*Maximum=*/-1u};
1677+
LLVMStyle.SpacesInLineCommentPrefix = {
1678+
/*Minimum=*/1, /*Maximum=*/std::numeric_limits<unsigned>::max()};
16761679
LLVMStyle.SpacesInParens = FormatStyle::SIPO_Never;
16771680
LLVMStyle.SpacesInSquareBrackets = false;
16781681
LLVMStyle.Standard = FormatStyle::LS_Latest;
@@ -3168,11 +3171,12 @@ static bool affectsRange(ArrayRef<tooling::Range> Ranges, unsigned Start,
31683171
// the index of the first of the duplicates as the others are going to be
31693172
// removed. OffsetToEOL describes the cursor's position relative to the end of
31703173
// its current line.
3171-
// If `Cursor` is not on any #include, `Index` will be UINT_MAX.
3174+
// If `Cursor` is not on any #include, `Index` will be
3175+
// std::numeric_limits<unsigned>::max().
31723176
static std::pair<unsigned, unsigned>
31733177
FindCursorIndex(const ArrayRef<IncludeDirective> &Includes,
31743178
const ArrayRef<unsigned> &Indices, unsigned Cursor) {
3175-
unsigned CursorIndex = UINT_MAX;
3179+
unsigned CursorIndex = std::numeric_limits<unsigned>::max();
31763180
unsigned OffsetToEOL = 0;
31773181
for (int i = 0, e = Includes.size(); i != e; ++i) {
31783182
unsigned Start = Includes[Indices[i]].Offset;
@@ -3440,11 +3444,12 @@ tooling::Replacements sortCppIncludes(const FormatStyle &Style, StringRef Code,
34403444
return Replaces;
34413445
}
34423446

3443-
// Returns group number to use as a first order sort on imports. Gives UINT_MAX
3444-
// if the import does not match any given groups.
3447+
// Returns group number to use as a first order sort on imports. Gives
3448+
// std::numeric_limits<unsigned>::max() if the import does not match any given
3449+
// groups.
34453450
static unsigned findJavaImportGroup(const FormatStyle &Style,
34463451
StringRef ImportIdentifier) {
3447-
unsigned LongestMatchIndex = UINT_MAX;
3452+
unsigned LongestMatchIndex = std::numeric_limits<unsigned>::max();
34483453
unsigned LongestMatchLength = 0;
34493454
for (unsigned I = 0; I < Style.JavaImportGroups.size(); I++) {
34503455
const std::string &GroupPrefix = Style.JavaImportGroups[I];
@@ -3673,13 +3678,15 @@ formatReplacements(StringRef Code, const tooling::Replacements &Replaces,
36733678
namespace {
36743679

36753680
inline bool isHeaderInsertion(const tooling::Replacement &Replace) {
3676-
return Replace.getOffset() == UINT_MAX && Replace.getLength() == 0 &&
3681+
return Replace.getOffset() == std::numeric_limits<unsigned>::max() &&
3682+
Replace.getLength() == 0 &&
36773683
tooling::HeaderIncludes::IncludeRegex.match(
36783684
Replace.getReplacementText());
36793685
}
36803686

36813687
inline bool isHeaderDeletion(const tooling::Replacement &Replace) {
3682-
return Replace.getOffset() == UINT_MAX && Replace.getLength() == 1;
3688+
return Replace.getOffset() == std::numeric_limits<unsigned>::max() &&
3689+
Replace.getLength() == 1;
36833690
}
36843691

36853692
// FIXME: insert empty lines between newly created blocks.
@@ -3699,7 +3706,7 @@ fixCppIncludeInsertions(StringRef Code, const tooling::Replacements &Replaces,
36993706
consumeError(HeaderInsertions.add(R));
37003707
} else if (isHeaderDeletion(R)) {
37013708
HeadersToDelete.insert(R.getReplacementText());
3702-
} else if (R.getOffset() == UINT_MAX) {
3709+
} else if (R.getOffset() == std::numeric_limits<unsigned>::max()) {
37033710
llvm::errs() << "Insertions other than header #include insertion are "
37043711
"not supported! "
37053712
<< R.getReplacementText() << "\n";

clang/lib/Lex/Lexer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include <cstddef>
4242
#include <cstdint>
4343
#include <cstring>
44+
#include <limits>
4445
#include <optional>
4546
#include <string>
4647
#include <tuple>
@@ -3456,7 +3457,7 @@ std::optional<uint32_t> Lexer::tryReadNumericUCN(const char *&StartPtr,
34563457
}
34573458

34583459
unsigned Value = llvm::hexDigitValue(C);
3459-
if (Value == -1U) {
3460+
if (Value == std::numeric_limits<unsigned>::max()) {
34603461
if (!Delimited)
34613462
break;
34623463
if (Diagnose)

clang/lib/Sema/CheckExprLifetime.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,12 +1340,6 @@ checkExprLifetimeImpl(Sema &SemaRef, const InitializedEntity *InitEntity,
13401340
return false;
13411341
}
13421342

1343-
if (IsGslPtrValueFromGslTempOwner && DiagLoc.isValid()) {
1344-
SemaRef.Diag(DiagLoc, diag::warn_dangling_lifetime_pointer)
1345-
<< DiagRange;
1346-
return false;
1347-
}
1348-
13491343
switch (shouldLifetimeExtendThroughPath(Path)) {
13501344
case PathLifetimeKind::Extend:
13511345
// Update the storage duration of the materialized temporary.
@@ -1356,6 +1350,20 @@ checkExprLifetimeImpl(Sema &SemaRef, const InitializedEntity *InitEntity,
13561350
return true;
13571351

13581352
case PathLifetimeKind::NoExtend:
1353+
if (SemaRef.getLangOpts().CPlusPlus23 && InitEntity) {
1354+
if (const VarDecl *VD =
1355+
dyn_cast_if_present<VarDecl>(InitEntity->getDecl());
1356+
VD && VD->isCXXForRangeImplicitVar()) {
1357+
return false;
1358+
}
1359+
}
1360+
1361+
if (IsGslPtrValueFromGslTempOwner && DiagLoc.isValid()) {
1362+
SemaRef.Diag(DiagLoc, diag::warn_dangling_lifetime_pointer)
1363+
<< DiagRange;
1364+
return false;
1365+
}
1366+
13591367
// If the path goes through the initialization of a variable or field,
13601368
// it can't possibly reach a temporary created in this full-expression.
13611369
// We will have already diagnosed any problems with the initializer.

clang/lib/Sema/SemaExpr.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include "llvm/Support/SaveAndRestore.h"
6666
#include "llvm/Support/TimeProfiler.h"
6767
#include "llvm/Support/TypeSize.h"
68+
#include <limits>
6869
#include <optional>
6970

7071
using namespace clang;
@@ -1906,7 +1907,7 @@ ExprResult Sema::CreateGenericSelectionExpr(
19061907
}
19071908

19081909
SmallVector<unsigned, 1> CompatIndices;
1909-
unsigned DefaultIndex = -1U;
1910+
unsigned DefaultIndex = std::numeric_limits<unsigned>::max();
19101911
// Look at the canonical type of the controlling expression in case it was a
19111912
// deduced type like __auto_type. However, when issuing diagnostics, use the
19121913
// type the user wrote in source rather than the canonical one.
@@ -1961,7 +1962,8 @@ ExprResult Sema::CreateGenericSelectionExpr(
19611962
// C11 6.5.1.1p2 "If a generic selection has no default generic association,
19621963
// its controlling expression shall have type compatible with exactly one of
19631964
// the types named in its generic association list."
1964-
if (DefaultIndex == -1U && CompatIndices.size() == 0) {
1965+
if (DefaultIndex == std::numeric_limits<unsigned>::max() &&
1966+
CompatIndices.size() == 0) {
19651967
auto P = GetControllingRangeAndType(ControllingExpr, ControllingType);
19661968
SourceRange SR = P.first;
19671969
Diag(SR.getBegin(), diag::err_generic_sel_no_match) << SR << P.second;

clang/lib/Sema/SemaStmt.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,6 +2423,7 @@ VarDecl *BuildForRangeVarDecl(Sema &SemaRef, SourceLocation Loc,
24232423
VarDecl *Decl = VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type,
24242424
TInfo, SC_None);
24252425
Decl->setImplicit();
2426+
Decl->setCXXForRangeImplicitVar(true);
24262427
return Decl;
24272428
}
24282429

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,7 @@ RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) {
16341634
VarDeclBits.getNextBits(/*Width*/ 3);
16351635

16361636
VD->NonParmVarDeclBits.ObjCForDecl = VarDeclBits.getNextBit();
1637+
VD->NonParmVarDeclBits.IsCXXForRangeImplicitVar = VarDeclBits.getNextBit();
16371638
}
16381639

16391640
// If this variable has a deduced type, defer reading that type until we are

0 commit comments

Comments
 (0)