Skip to content

Commit b252dd4

Browse files
authored
Merge branch 'main' into 120590-fileinterface
2 parents 7a1a0c9 + a27da0a commit b252dd4

Some content is hidden

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

51 files changed

+437
-291
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6976,7 +6976,7 @@ def err_illegal_decl_mempointer_to_reference : Error<
69766976
def err_illegal_decl_mempointer_to_void : Error<
69776977
"'%0' declared as a member pointer to void">;
69786978
def err_illegal_decl_mempointer_in_nonclass
6979-
: Error<"'%0' does not point into a class">;
6979+
: Error<"%0 does not point into a class">;
69806980
def err_reference_to_void : Error<"cannot form a reference to 'void'">;
69816981
def err_nonfunction_block_type : Error<
69826982
"block pointer to non-function type is invalid">;

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14885,7 +14885,7 @@ class Sema final : public SemaBase {
1488514885
///
1488614886
/// \returns a member pointer type, if successful, or a NULL type if there was
1488714887
/// an error.
14888-
QualType BuildMemberPointerType(QualType T, NestedNameSpecifier *Qualifier,
14888+
QualType BuildMemberPointerType(QualType T, const CXXScopeSpec &SS,
1488914889
CXXRecordDecl *Cls, SourceLocation Loc,
1489014890
DeclarationName Entity);
1489114891

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,9 @@ static bool interp__builtin_ptrauth_string_discriminator(
14771477
const auto &Ptr = S.Stk.peek<Pointer>();
14781478
assert(Ptr.getFieldDesc()->isPrimitiveArray());
14791479

1480+
// This should be created for a StringLiteral, so should alway shold at least
1481+
// one array element.
1482+
assert(Ptr.getFieldDesc()->getNumElems() >= 1);
14801483
StringRef R(&Ptr.deref<char>(), Ptr.getFieldDesc()->getNumElems() - 1);
14811484
uint64_t Result = getPointerAuthStableSipHash(R);
14821485
pushInteger(S, Result, Call->getType());

clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "clang/AST/RecordLayout.h"
2020
#include "clang/Basic/TargetInfo.h"
2121

22+
#include <variant>
23+
2224
using namespace clang;
2325
using namespace clang::interp;
2426

@@ -450,33 +452,48 @@ bool clang::interp::DoBitCastPtr(InterpState &S, CodePtr OpPC,
450452
return Success;
451453
}
452454

455+
using PrimTypeVariant =
456+
std::variant<Pointer, FunctionPointer, MemberPointer, FixedPoint,
457+
Integral<8, false>, Integral<8, true>, Integral<16, false>,
458+
Integral<16, true>, Integral<32, false>, Integral<32, true>,
459+
Integral<64, false>, Integral<64, true>, IntegralAP<true>,
460+
IntegralAP<false>, Boolean, Floating>;
461+
462+
// NB: This implementation isn't exactly ideal, but:
463+
// 1) We can't just do a bitcast here since we need to be able to
464+
// copy pointers.
465+
// 2) This also needs to handle overlapping regions.
466+
// 3) We currently have no way of iterating over the fields of a pointer
467+
// backwards.
453468
bool clang::interp::DoMemcpy(InterpState &S, CodePtr OpPC,
454469
const Pointer &SrcPtr, const Pointer &DestPtr,
455470
Bits Size) {
456471
assert(SrcPtr.isBlockPointer());
457472
assert(DestPtr.isBlockPointer());
458473

459-
unsigned SrcStartOffset = SrcPtr.getByteOffset();
460-
unsigned DestStartOffset = DestPtr.getByteOffset();
461-
474+
llvm::SmallVector<PrimTypeVariant> Values;
462475
enumeratePointerFields(SrcPtr, S.getContext(), Size,
463476
[&](const Pointer &P, PrimType T, Bits BitOffset,
464477
Bits FullBitWidth, bool PackedBools) -> bool {
465-
unsigned SrcOffsetDiff =
466-
P.getByteOffset() - SrcStartOffset;
467-
468-
Pointer DestP =
469-
Pointer(DestPtr.asBlockPointer().Pointee,
470-
DestPtr.asBlockPointer().Base,
471-
DestStartOffset + SrcOffsetDiff);
478+
TYPE_SWITCH(T, { Values.push_back(P.deref<T>()); });
479+
return true;
480+
});
472481

482+
unsigned ValueIndex = 0;
483+
enumeratePointerFields(DestPtr, S.getContext(), Size,
484+
[&](const Pointer &P, PrimType T, Bits BitOffset,
485+
Bits FullBitWidth, bool PackedBools) -> bool {
473486
TYPE_SWITCH(T, {
474-
DestP.deref<T>() = P.deref<T>();
475-
DestP.initialize();
487+
P.deref<T>() = std::get<T>(Values[ValueIndex]);
488+
P.initialize();
476489
});
477490

491+
++ValueIndex;
478492
return true;
479493
});
480494

495+
// We should've read all the values into DestPtr.
496+
assert(ValueIndex == Values.size());
497+
481498
return true;
482499
}

clang/lib/CodeGen/Targets/AVR.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class AVRABIInfo : public DefaultABIInfo {
5959
unsigned TySize = getContext().getTypeSize(Ty);
6060

6161
// An int8 type argument always costs two registers like an int16.
62-
if (TySize == 8 && NumRegs >= 2) {
62+
if (TySize == 8 && NumRegs >= 2 && Ty->isIntegralOrEnumerationType()) {
6363
NumRegs -= 2;
6464
return ABIArgInfo::getExtend(Ty);
6565
}

clang/lib/Sema/SemaType.cpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2685,10 +2685,23 @@ QualType Sema::BuildFunctionType(QualType T,
26852685
return Context.getFunctionType(T, ParamTypes, EPI);
26862686
}
26872687

2688-
QualType Sema::BuildMemberPointerType(QualType T,
2689-
NestedNameSpecifier *Qualifier,
2688+
QualType Sema::BuildMemberPointerType(QualType T, const CXXScopeSpec &SS,
26902689
CXXRecordDecl *Cls, SourceLocation Loc,
26912690
DeclarationName Entity) {
2691+
if (!Cls && !isDependentScopeSpecifier(SS)) {
2692+
Cls = dyn_cast_or_null<CXXRecordDecl>(computeDeclContext(SS));
2693+
if (!Cls) {
2694+
auto D =
2695+
Diag(SS.getBeginLoc(), diag::err_illegal_decl_mempointer_in_nonclass)
2696+
<< SS.getRange();
2697+
if (const IdentifierInfo *II = Entity.getAsIdentifierInfo())
2698+
D << II;
2699+
else
2700+
D << "member pointer";
2701+
return QualType();
2702+
}
2703+
}
2704+
26922705
// Verify that we're not building a pointer to pointer to function with
26932706
// exception specification.
26942707
if (CheckDistantExceptionSpec(T)) {
@@ -2730,7 +2743,7 @@ QualType Sema::BuildMemberPointerType(QualType T,
27302743
if (T->isFunctionType())
27312744
adjustMemberFunctionCC(T, /*HasThisPointer=*/true, IsCtorOrDtor, Loc);
27322745

2733-
return Context.getMemberPointerType(T, Qualifier, Cls);
2746+
return Context.getMemberPointerType(T, SS.getScopeRep(), Cls);
27342747
}
27352748

27362749
QualType Sema::BuildBlockPointerType(QualType T,
@@ -5344,20 +5357,9 @@ static TypeSourceInfo *GetFullTypeForDeclarator(TypeProcessingState &state,
53445357
// Avoid emitting extra errors if we already errored on the scope.
53455358
D.setInvalidType(true);
53465359
AreDeclaratorChunksValid = false;
5347-
} else if (auto *RD =
5348-
dyn_cast_or_null<CXXRecordDecl>(S.computeDeclContext(SS));
5349-
RD || S.isDependentScopeSpecifier(SS)) {
5350-
T = S.BuildMemberPointerType(T, SS.getScopeRep(), RD, DeclType.Loc,
5351-
D.getIdentifier());
53525360
} else {
5353-
S.Diag(DeclType.Mem.Scope().getBeginLoc(),
5354-
diag::err_illegal_decl_mempointer_in_nonclass)
5355-
<< (D.getIdentifier() ? D.getIdentifier()->getName() : "type name")
5356-
<< DeclType.Mem.Scope().getRange();
5357-
D.setInvalidType(true);
5358-
AreDeclaratorChunksValid = false;
5359-
// FIXME: Maybe we could model these as as a MemberPointerType with a
5360-
// non-dependent, non-class qualifier anyway.
5361+
T = S.BuildMemberPointerType(T, SS, /*Cls=*/nullptr, DeclType.Loc,
5362+
D.getIdentifier());
53615363
}
53625364

53635365
if (T.isNull()) {
@@ -9255,10 +9257,10 @@ bool Sema::RequireCompleteTypeImpl(SourceLocation Loc, QualType T,
92559257
// "Can't ask whether a dependent type is complete");
92569258

92579259
if (const MemberPointerType *MPTy = T->getAs<MemberPointerType>()) {
9258-
if (!MPTy->getQualifier()->isDependent()) {
9259-
QualType T = Context.getTypeDeclType(MPTy->getMostRecentCXXRecordDecl());
9260-
if (getLangOpts().CompleteMemberPointers &&
9261-
!MPTy->getMostRecentCXXRecordDecl()->isBeingDefined() &&
9260+
if (CXXRecordDecl *RD = MPTy->getMostRecentCXXRecordDecl();
9261+
RD && !RD->isDependentType()) {
9262+
QualType T = Context.getTypeDeclType(RD);
9263+
if (getLangOpts().CompleteMemberPointers && !RD->isBeingDefined() &&
92629264
RequireCompleteType(Loc, T, Kind, diag::err_memptr_incomplete))
92639265
return true;
92649266

clang/lib/Sema/TreeTransform.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -864,8 +864,8 @@ class TreeTransform {
864864
/// By default, performs semantic analysis when building the member pointer
865865
/// type. Subclasses may override this routine to provide different behavior.
866866
QualType RebuildMemberPointerType(QualType PointeeType,
867-
NestedNameSpecifier *Qualifier,
868-
CXXRecordDecl *Cls, SourceLocation Sigil);
867+
const CXXScopeSpec &SS, CXXRecordDecl *Cls,
868+
SourceLocation Sigil);
869869

870870
QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl,
871871
SourceLocation ProtocolLAngleLoc,
@@ -5631,9 +5631,10 @@ TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
56315631
NewQualifierLoc.getNestedNameSpecifier() !=
56325632
OldQualifierLoc.getNestedNameSpecifier() ||
56335633
NewCls != OldCls) {
5634-
Result = getDerived().RebuildMemberPointerType(
5635-
PointeeType, NewQualifierLoc.getNestedNameSpecifier(), NewCls,
5636-
TL.getStarLoc());
5634+
CXXScopeSpec SS;
5635+
SS.Adopt(NewQualifierLoc);
5636+
Result = getDerived().RebuildMemberPointerType(PointeeType, SS, NewCls,
5637+
TL.getStarLoc());
56375638
if (Result.isNull())
56385639
return QualType();
56395640
}
@@ -17044,9 +17045,9 @@ TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
1704417045

1704517046
template <typename Derived>
1704617047
QualType TreeTransform<Derived>::RebuildMemberPointerType(
17047-
QualType PointeeType, NestedNameSpecifier *Qualifier, CXXRecordDecl *Cls,
17048+
QualType PointeeType, const CXXScopeSpec &SS, CXXRecordDecl *Cls,
1704817049
SourceLocation Sigil) {
17049-
return SemaRef.BuildMemberPointerType(PointeeType, Qualifier, Cls, Sigil,
17050+
return SemaRef.BuildMemberPointerType(PointeeType, SS, Cls, Sigil,
1705017051
getDerived().getBaseEntity());
1705117052
}
1705217053

clang/test/AST/ByteCode/builtin-functions.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,6 @@ namespace BuiltinMemcpy {
12761276
static_assert(test_incomplete_array_type() == 1234); // both-error {{constant}} both-note {{in call}}
12771277

12781278

1279-
/// FIXME: memmove needs to support overlapping memory regions.
12801279
constexpr bool memmoveOverlapping() {
12811280
char s1[] {1, 2, 3};
12821281
__builtin_memmove(s1, s1 + 1, 2 * sizeof(char));
@@ -1289,7 +1288,7 @@ namespace BuiltinMemcpy {
12891288

12901289
return Result1 && Result2;
12911290
}
1292-
static_assert(memmoveOverlapping()); // expected-error {{failed}}
1291+
static_assert(memmoveOverlapping());
12931292
}
12941293

12951294
namespace Memcmp {

clang/test/CodeGen/RISCV/riscv-func-attr-target.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ int test_vsetvlmax_e64m1() {
8585
// CHECK: attributes #2 = { {{.*}}"target-features"="+64bit,+a,+m,+save-restore,+zaamo,+zalrsc,+zbb,+zifencei,+zmmul,-relax,-zfa" }
8686
// CHECK: attributes #3 = { {{.*}}"target-features"="+64bit,+a,+d,+f,+m,+save-restore,+v,+zaamo,+zalrsc,+zbb,+zicond,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-relax,-zfa" }
8787
// Make sure we append negative features if we override the arch
88-
// CHECK: attributes #4 = { {{.*}}"target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zaamo,+zalrsc,+zbb,+zicsr,+zifencei,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}" }
88+
// CHECK: attributes #4 = { {{.*}}"target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zaamo,+zalrsc,+zbb,+zca,+zcd,+zicsr,+zifencei,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}" }
8989
// CHECK: attributes #5 = { {{.*}}"target-features"="+64bit,+m,+save-restore,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}" }
9090
// CHECK: attributes #6 = { {{.*}}"target-cpu"="sifive-u54" "target-features"="+64bit,+a,+m,+save-restore,+zaamo,+zalrsc,+zbb,+zifencei,+zmmul,-relax,-zfa" }
9191
// CHECK: attributes #7 = { {{.*}}"target-cpu"="sifive-u54" "target-features"="+64bit,+m,+save-restore,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}" }
92-
// CHECK: attributes #8 = { {{.*}}"target-cpu"="sifive-u54" "target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zaamo,+zalrsc,+zicsr,+zifencei,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}" }
92+
// CHECK: attributes #8 = { {{.*}}"target-cpu"="sifive-u54" "target-features"="+64bit,+a,+c,+d,+f,+m,+save-restore,+zaamo,+zalrsc,+zca,+zcd,+zicsr,+zifencei,+zmmul,{{(-[[:alnum:]-]+)(,-[[:alnum:]-]+)*}}" }
9393
// CHECK: attributes #9 = { {{.*}}"target-features"="+64bit,+a,+m,+save-restore,+zaamo,+zalrsc,+zicsr,+zifencei,+zmmul,+zve32x,+zvl32b,-relax,-zbb,-zfa" }
9494
// CHECK: attributes #11 = { {{.*}}"target-features"="+64bit,+a,+f,+m,+save-restore,+zaamo,+zalrsc,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zvl32b,-relax,-zbb,-zfa" }
9595
// CHECK: attributes #12 = { {{.*}}"target-features"="+64bit,+a,+d,+f,+m,+save-restore,+zaamo,+zalrsc,+zicsr,+zifencei,+zmmul,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl32b,+zvl64b,-relax,-zbb,-zfa" }

clang/test/CodeGen/attr-target-clones-riscv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ int bar() { return foo1() + foo2() + foo3() + foo4() + foo5() + foo6() + foo7()
370370
// CHECK: attributes #[[ATTR0]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+i" }
371371
// CHECK: attributes #[[ATTR1]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+i,+m,+zmmul" }
372372
// CHECK: attributes #[[ATTR2]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+i,+zbb" }
373-
// CHECK: attributes #[[ATTR3]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+c,+i,+zbb" }
373+
// CHECK: attributes #[[ATTR3]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+c,+i,+zbb,+zca" }
374374
// CHECK: attributes #[[ATTR4]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+d,+f,+i,+v,+zbb,+zicsr,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b" }
375375
// CHECK: attributes #[[ATTR5]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+i,+zvkt" }
376376
// CHECK: attributes #[[ATTR6]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+i,+zba" }

0 commit comments

Comments
 (0)