Skip to content

Commit 9969219

Browse files
authored
merge main into amd-staging (llvm#3045)
2 parents 0d909bc + d166aff commit 9969219

File tree

514 files changed

+18598
-10353
lines changed

Some content is hidden

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

514 files changed

+18598
-10353
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,10 @@ Improvements to Clang's diagnostics
678678
#GH142457, #GH139913, #GH138850, #GH137867, #GH137860, #GH107840, #GH93308,
679679
#GH69470, #GH59391, #GH58172, #GH46215, #GH45915, #GH45891, #GH44490,
680680
#GH36703, #GH32903, #GH23312, #GH69874.
681+
682+
- Clang no longer emits a spurious -Wdangling-gsl warning in C++23 when
683+
iterating over an element of a temporary container in a range-based
684+
for loop.(#GH109793, #GH145164)
681685

682686
- Fixed false positives in ``-Wformat-truncation`` and ``-Wformat-overflow``
683687
diagnostics when floating-point numbers had both width field and plus or space
@@ -1251,6 +1255,7 @@ OpenMP Support
12511255
- Fixed mapping of arrays of structs containing nested structs with user defined
12521256
mappers, by using compiler-generated default mappers for the outer structs for
12531257
such maps.
1258+
- Deprecation warning has been emitted for deprecated delimited form of ``declare target``.
12541259

12551260
Improvements
12561261
^^^^^^^^^^^^

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/DiagnosticParseKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,9 @@ def err_omp_declare_target_multiple : Error<
15741574
"%0 appears multiple times in clauses on the same declare target directive">;
15751575
def err_omp_declare_target_indirect_device_type: Error<
15761576
"only 'device_type(any)' clause is allowed with indirect clause">;
1577+
def warn_omp_deprecated_declare_target_delimited_form :
1578+
Warning<"the delimited form of '#pragma omp declare target' without clauses is deprecated; use '#pragma omp begin declare target' instead">,
1579+
InGroup<Deprecated>;
15771580
def err_omp_expected_clause: Error<
15781581
"expected at least one clause on '#pragma omp %0' directive">;
15791582
def err_omp_mapper_illegal_identifier : Error<

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/include/clang/Lex/TokenLexer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class TokenLexer {
6565

6666
/// The offset of the macro expansion in the
6767
/// "source location address space".
68-
unsigned MacroStartSLocOffset;
68+
SourceLocation::UIntTy MacroStartSLocOffset;
6969

7070
/// Location of the macro definition.
7171
SourceLocation MacroDefStart;

clang/include/clang/Sema/Sema.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13318,18 +13318,6 @@ class Sema final : public SemaBase {
1331813318
/// \param ForDefaultArgumentSubstitution indicates we should continue looking
1331913319
/// when encountering a specialized member function template, rather than
1332013320
/// returning immediately.
13321-
void getTemplateInstantiationArgs(
13322-
MultiLevelTemplateArgumentList &Result, const NamedDecl *D,
13323-
const DeclContext *DC = nullptr, bool Final = false,
13324-
std::optional<ArrayRef<TemplateArgument>> Innermost = std::nullopt,
13325-
bool RelativeToPrimary = false, const FunctionDecl *Pattern = nullptr,
13326-
bool ForConstraintInstantiation = false,
13327-
bool SkipForSpecialization = false,
13328-
bool ForDefaultArgumentSubstitution = false);
13329-
13330-
/// This creates a new \p MultiLevelTemplateArgumentList and invokes the other
13331-
/// overload with it as the first parameter. Prefer this overload in most
13332-
/// situations.
1333313321
MultiLevelTemplateArgumentList getTemplateInstantiationArgs(
1333413322
const NamedDecl *D, const DeclContext *DC = nullptr, bool Final = false,
1333513323
std::optional<ArrayRef<TemplateArgument>> Innermost = std::nullopt,

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,8 @@ bool Free(InterpState &S, CodePtr OpPC, bool DeleteIsArrayForm,
11961196
if (!CheckDynamicMemoryAllocation(S, OpPC))
11971197
return false;
11981198

1199+
DynamicAllocator &Allocator = S.getAllocator();
1200+
11991201
const Expr *Source = nullptr;
12001202
const Block *BlockToDelete = nullptr;
12011203
{
@@ -1212,6 +1214,21 @@ bool Free(InterpState &S, CodePtr OpPC, bool DeleteIsArrayForm,
12121214
while (Ptr.isBaseClass())
12131215
Ptr = Ptr.getBase();
12141216

1217+
Source = Ptr.getDeclDesc()->asExpr();
1218+
BlockToDelete = Ptr.block();
1219+
1220+
// Check that new[]/delete[] or new/delete were used, not a mixture.
1221+
const Descriptor *BlockDesc = BlockToDelete->getDescriptor();
1222+
if (std::optional<DynamicAllocator::Form> AllocForm =
1223+
Allocator.getAllocationForm(Source)) {
1224+
DynamicAllocator::Form DeleteForm =
1225+
DeleteIsArrayForm ? DynamicAllocator::Form::Array
1226+
: DynamicAllocator::Form::NonArray;
1227+
if (!CheckNewDeleteForms(S, OpPC, *AllocForm, DeleteForm, BlockDesc,
1228+
Source))
1229+
return false;
1230+
}
1231+
12151232
// For the non-array case, the types must match if the static type
12161233
// does not have a virtual destructor.
12171234
if (!DeleteIsArrayForm && Ptr.getType() != InitialType &&
@@ -1230,9 +1247,6 @@ bool Free(InterpState &S, CodePtr OpPC, bool DeleteIsArrayForm,
12301247
return false;
12311248
}
12321249

1233-
Source = Ptr.getDeclDesc()->asExpr();
1234-
BlockToDelete = Ptr.block();
1235-
12361250
if (!CheckDeleteSource(S, OpPC, Source, Ptr))
12371251
return false;
12381252

@@ -1266,24 +1280,14 @@ bool Free(InterpState &S, CodePtr OpPC, bool DeleteIsArrayForm,
12661280
if (!RunDestructors(S, OpPC, BlockToDelete))
12671281
return false;
12681282

1269-
DynamicAllocator &Allocator = S.getAllocator();
1270-
const Descriptor *BlockDesc = BlockToDelete->getDescriptor();
1271-
std::optional<DynamicAllocator::Form> AllocForm =
1272-
Allocator.getAllocationForm(Source);
1273-
12741283
if (!Allocator.deallocate(Source, BlockToDelete, S)) {
12751284
// Nothing has been deallocated, this must be a double-delete.
12761285
const SourceInfo &Loc = S.Current->getSource(OpPC);
12771286
S.FFDiag(Loc, diag::note_constexpr_double_delete);
12781287
return false;
12791288
}
12801289

1281-
assert(AllocForm);
1282-
DynamicAllocator::Form DeleteForm = DeleteIsArrayForm
1283-
? DynamicAllocator::Form::Array
1284-
: DynamicAllocator::Form::NonArray;
1285-
return CheckNewDeleteForms(S, OpPC, *AllocForm, DeleteForm, BlockDesc,
1286-
Source);
1290+
return true;
12871291
}
12881292

12891293
void diagnoseEnumValue(InterpState &S, CodePtr OpPC, const EnumDecl *ED,

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 103 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "clang/Basic/TargetBuiltins.h"
1919
#include "clang/Basic/TargetInfo.h"
2020
#include "llvm/ADT/StringExtras.h"
21+
#include "llvm/Support/ErrorHandling.h"
2122
#include "llvm/Support/SipHash.h"
2223

2324
namespace clang {
@@ -1673,6 +1674,12 @@ static bool interp__builtin_vector_reduce(InterpState &S, CodePtr OpPC,
16731674
(void)T::bitOr(Result, Elem, BitWidth, &Result);
16741675
} else if (ID == Builtin::BI__builtin_reduce_xor) {
16751676
(void)T::bitXor(Result, Elem, BitWidth, &Result);
1677+
} else if (ID == Builtin::BI__builtin_reduce_min) {
1678+
if (Elem < Result)
1679+
Result = Elem;
1680+
} else if (ID == Builtin::BI__builtin_reduce_max) {
1681+
if (Elem > Result)
1682+
Result = Elem;
16761683
} else {
16771684
llvm_unreachable("Unhandled vector reduce builtin");
16781685
}
@@ -1686,12 +1693,18 @@ static bool interp__builtin_vector_reduce(InterpState &S, CodePtr OpPC,
16861693
/// Can be called with an integer or vector as the first and only parameter.
16871694
static bool interp__builtin_elementwise_popcount(InterpState &S, CodePtr OpPC,
16881695
const InterpFrame *Frame,
1689-
const CallExpr *Call) {
1696+
const CallExpr *Call,
1697+
unsigned BuiltinID) {
16901698
assert(Call->getNumArgs() == 1);
16911699
if (Call->getArg(0)->getType()->isIntegerType()) {
16921700
PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
16931701
APSInt Val = popToAPSInt(S.Stk, ArgT);
1694-
pushInteger(S, Val.popcount(), Call->getType());
1702+
1703+
if (BuiltinID == Builtin::BI__builtin_elementwise_popcount) {
1704+
pushInteger(S, Val.popcount(), Call->getType());
1705+
} else {
1706+
pushInteger(S, Val.reverseBits(), Call->getType());
1707+
}
16951708
return true;
16961709
}
16971710
// Otherwise, the argument must be a vector.
@@ -1710,8 +1723,13 @@ static bool interp__builtin_elementwise_popcount(InterpState &S, CodePtr OpPC,
17101723
// FIXME: Reading from uninitialized vector elements?
17111724
for (unsigned I = 0; I != NumElems; ++I) {
17121725
INT_TYPE_SWITCH_NO_BOOL(ElemT, {
1713-
Dst.atIndex(I).deref<T>() =
1714-
T::from(Arg.atIndex(I).deref<T>().toAPSInt().popcount());
1726+
if (BuiltinID == Builtin::BI__builtin_elementwise_popcount) {
1727+
Dst.atIndex(I).deref<T>() =
1728+
T::from(Arg.atIndex(I).deref<T>().toAPSInt().popcount());
1729+
} else {
1730+
Dst.atIndex(I).deref<T>() = T::from(
1731+
Arg.atIndex(I).deref<T>().toAPSInt().reverseBits().getZExtValue());
1732+
}
17151733
Dst.atIndex(I).initialize();
17161734
});
17171735
}
@@ -2234,6 +2252,78 @@ static bool interp__builtin_is_within_lifetime(InterpState &S, CodePtr OpPC,
22342252
return true;
22352253
}
22362254

2255+
static bool interp__builtin_elementwise_sat(InterpState &S, CodePtr OpPC,
2256+
const CallExpr *Call,
2257+
unsigned BuiltinID) {
2258+
Call->dumpColor();
2259+
assert(Call->getNumArgs() == 2);
2260+
2261+
// Single integer case.
2262+
if (!Call->getArg(0)->getType()->isVectorType()) {
2263+
assert(!Call->getArg(1)->getType()->isVectorType());
2264+
APSInt RHS = popToAPSInt(
2265+
S.Stk, *S.getContext().classify(Call->getArg(1)->getType()));
2266+
APSInt LHS = popToAPSInt(
2267+
S.Stk, *S.getContext().classify(Call->getArg(0)->getType()));
2268+
APInt Result;
2269+
if (BuiltinID == Builtin::BI__builtin_elementwise_add_sat) {
2270+
Result = LHS.isSigned() ? LHS.sadd_sat(RHS) : LHS.uadd_sat(RHS);
2271+
} else if (BuiltinID == Builtin::BI__builtin_elementwise_sub_sat) {
2272+
Result = LHS.isSigned() ? LHS.ssub_sat(RHS) : LHS.usub_sat(RHS);
2273+
} else {
2274+
llvm_unreachable("Wrong builtin ID");
2275+
}
2276+
2277+
pushInteger(S, APSInt(Result, !LHS.isSigned()), Call->getType());
2278+
return true;
2279+
}
2280+
2281+
// Vector case.
2282+
assert(Call->getArg(0)->getType()->isVectorType() &&
2283+
Call->getArg(1)->getType()->isVectorType());
2284+
const auto *VT = Call->getArg(0)->getType()->castAs<VectorType>();
2285+
assert(VT->getElementType() ==
2286+
Call->getArg(1)->getType()->castAs<VectorType>()->getElementType());
2287+
assert(VT->getNumElements() ==
2288+
Call->getArg(1)->getType()->castAs<VectorType>()->getNumElements());
2289+
assert(VT->getElementType()->isIntegralOrEnumerationType());
2290+
2291+
const Pointer &RHS = S.Stk.pop<Pointer>();
2292+
const Pointer &LHS = S.Stk.pop<Pointer>();
2293+
const Pointer &Dst = S.Stk.peek<Pointer>();
2294+
PrimType ElemT = *S.getContext().classify(VT->getElementType());
2295+
unsigned NumElems = VT->getNumElements();
2296+
for (unsigned I = 0; I != NumElems; ++I) {
2297+
APSInt Elem1;
2298+
APSInt Elem2;
2299+
INT_TYPE_SWITCH_NO_BOOL(ElemT, {
2300+
Elem1 = LHS.atIndex(I).deref<T>().toAPSInt();
2301+
Elem2 = RHS.atIndex(I).deref<T>().toAPSInt();
2302+
});
2303+
2304+
APSInt Result;
2305+
if (BuiltinID == Builtin::BI__builtin_elementwise_add_sat) {
2306+
Result = APSInt(Elem1.isSigned() ? Elem1.sadd_sat(Elem2)
2307+
: Elem1.uadd_sat(Elem2),
2308+
Call->getType()->isUnsignedIntegerOrEnumerationType());
2309+
} else if (BuiltinID == Builtin::BI__builtin_elementwise_sub_sat) {
2310+
Result = APSInt(Elem1.isSigned() ? Elem1.ssub_sat(Elem2)
2311+
: Elem1.usub_sat(Elem2),
2312+
Call->getType()->isUnsignedIntegerOrEnumerationType());
2313+
} else {
2314+
llvm_unreachable("Wrong builtin ID");
2315+
}
2316+
2317+
INT_TYPE_SWITCH_NO_BOOL(ElemT, {
2318+
const Pointer &E = Dst.atIndex(I);
2319+
E.deref<T>() = static_cast<T>(Result);
2320+
E.initialize();
2321+
});
2322+
}
2323+
2324+
return true;
2325+
}
2326+
22372327
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
22382328
uint32_t BuiltinID) {
22392329
if (!S.getASTContext().BuiltinInfo.isConstantEvaluated(BuiltinID))
@@ -2592,10 +2682,14 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
25922682
case Builtin::BI__builtin_reduce_and:
25932683
case Builtin::BI__builtin_reduce_or:
25942684
case Builtin::BI__builtin_reduce_xor:
2685+
case Builtin::BI__builtin_reduce_min:
2686+
case Builtin::BI__builtin_reduce_max:
25952687
return interp__builtin_vector_reduce(S, OpPC, Call, BuiltinID);
25962688

25972689
case Builtin::BI__builtin_elementwise_popcount:
2598-
return interp__builtin_elementwise_popcount(S, OpPC, Frame, Call);
2690+
case Builtin::BI__builtin_elementwise_bitreverse:
2691+
return interp__builtin_elementwise_popcount(S, OpPC, Frame, Call,
2692+
BuiltinID);
25992693

26002694
case Builtin::BI__builtin_memcpy:
26012695
case Builtin::BImemcpy:
@@ -2633,6 +2727,10 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
26332727
case Builtin::BI__builtin_is_within_lifetime:
26342728
return interp__builtin_is_within_lifetime(S, OpPC, Call);
26352729

2730+
case Builtin::BI__builtin_elementwise_add_sat:
2731+
case Builtin::BI__builtin_elementwise_sub_sat:
2732+
return interp__builtin_elementwise_sat(S, OpPC, Call, BuiltinID);
2733+
26362734
default:
26372735
S.FFDiag(S.Current->getLocation(OpPC),
26382736
diag::note_invalid_subexpr_in_const_expr)

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,6 +2190,9 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
21902190
SourceLocation DTLoc = ConsumeAnyToken();
21912191
bool HasClauses = Tok.isNot(tok::annot_pragma_openmp_end);
21922192
SemaOpenMP::DeclareTargetContextInfo DTCI(DKind, DTLoc);
2193+
if (DKind == OMPD_declare_target && !HasClauses &&
2194+
getLangOpts().OpenMP >= 52)
2195+
Diag(DTLoc, diag::warn_omp_deprecated_declare_target_delimited_form);
21932196
if (HasClauses)
21942197
ParseOMPDeclareTargetClauses(DTCI);
21952198
bool HasImplicitMappings = DKind == OMPD_begin_declare_target ||

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.

0 commit comments

Comments
 (0)