Skip to content

Commit 09ac879

Browse files
ronliebskganesan008
authored andcommitted
merge main into amd-staging
2 parents b343c3e + 461be1d commit 09ac879

File tree

15 files changed

+229
-36
lines changed

15 files changed

+229
-36
lines changed

clang/include/clang/AST/Redeclarable.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ class Redeclarable {
114114

115115
bool isFirst() const {
116116
return isa<KnownLatest>(Link) ||
117-
// FIXME: 'template' is required on the next line due to an
118-
// apparent clang bug.
119117
isa<UninitializedLatest>(cast<NotKnownLatest>(Link));
120118
}
121119

clang/lib/AST/ByteCode/Descriptor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ struct Descriptor final {
274274

275275
void dump() const;
276276
void dump(llvm::raw_ostream &OS) const;
277+
void dumpFull(unsigned Offset = 0, unsigned Indent = 0) const;
277278
};
278279

279280
/// Bitfield tracking the initialisation status of elements of primitive arrays.

clang/lib/AST/ByteCode/Disasm.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,38 @@ LLVM_DUMP_METHOD void Descriptor::dump(llvm::raw_ostream &OS) const {
251251
OS << " dummy";
252252
}
253253

254+
/// Dump descriptor, including all valid offsets.
255+
LLVM_DUMP_METHOD void Descriptor::dumpFull(unsigned Offset,
256+
unsigned Indent) const {
257+
unsigned Spaces = Indent * 2;
258+
llvm::raw_ostream &OS = llvm::errs();
259+
OS.indent(Spaces);
260+
dump(OS);
261+
OS << '\n';
262+
OS.indent(Spaces) << "Metadata: " << getMetadataSize() << " bytes\n";
263+
OS.indent(Spaces) << "Size: " << getSize() << " bytes\n";
264+
OS.indent(Spaces) << "AllocSize: " << getAllocSize() << " bytes\n";
265+
Offset += getMetadataSize();
266+
if (isCompositeArray()) {
267+
OS.indent(Spaces) << "Elements: " << getNumElems() << '\n';
268+
unsigned FO = Offset;
269+
for (unsigned I = 0; I != getNumElems(); ++I) {
270+
FO += sizeof(InlineDescriptor);
271+
assert(ElemDesc->getMetadataSize() == 0);
272+
OS.indent(Spaces) << "Element " << I << " offset: " << FO << '\n';
273+
ElemDesc->dumpFull(FO, Indent + 1);
274+
275+
FO += ElemDesc->getAllocSize();
276+
}
277+
} else if (isRecord()) {
278+
ElemRecord->dump(OS, Indent + 1, Offset);
279+
} else if (isPrimitive()) {
280+
} else {
281+
}
282+
283+
OS << '\n';
284+
}
285+
254286
LLVM_DUMP_METHOD void InlineDescriptor::dump(llvm::raw_ostream &OS) const {
255287
{
256288
ColorScope SC(OS, true, {llvm::raw_ostream::BLUE, true});

clang/lib/AST/ByteCode/DynamicAllocator.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Block *DynamicAllocator::allocate(const Expr *Source, PrimType T,
5454
Block *DynamicAllocator::allocate(const Descriptor *ElementDesc,
5555
size_t NumElements, unsigned EvalID,
5656
Form AllocForm) {
57+
assert(ElementDesc->getMetadataSize() == 0);
5758
// Create a new descriptor for an array of the specified size and
5859
// element type.
5960
const Descriptor *D = allocateDescriptor(
@@ -72,6 +73,7 @@ Block *DynamicAllocator::allocate(const Descriptor *D, unsigned EvalID,
7273
auto *B = new (Memory.get()) Block(EvalID, D, /*isStatic=*/false);
7374
B->invokeCtor();
7475

76+
assert(D->getMetadataSize() == sizeof(InlineDescriptor));
7577
InlineDescriptor *ID = reinterpret_cast<InlineDescriptor *>(B->rawData());
7678
ID->Desc = D;
7779
ID->IsActive = true;

clang/lib/AST/ByteCode/Interp.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2896,9 +2896,7 @@ inline bool Alloc(InterpState &S, CodePtr OpPC, const Descriptor *Desc) {
28962896
Block *B = Allocator.allocate(Desc, S.Ctx.getEvalID(),
28972897
DynamicAllocator::Form::NonArray);
28982898
assert(B);
2899-
29002899
S.Stk.push<Pointer>(B);
2901-
29022900
return true;
29032901
}
29042902

@@ -2923,8 +2921,7 @@ inline bool AllocN(InterpState &S, CodePtr OpPC, PrimType T, const Expr *Source,
29232921
Allocator.allocate(Source, T, static_cast<size_t>(NumElements),
29242922
S.Ctx.getEvalID(), DynamicAllocator::Form::Array);
29252923
assert(B);
2926-
S.Stk.push<Pointer>(B, sizeof(InlineDescriptor));
2927-
2924+
S.Stk.push<Pointer>(B);
29282925
return true;
29292926
}
29302927

@@ -2950,9 +2947,7 @@ inline bool AllocCN(InterpState &S, CodePtr OpPC, const Descriptor *ElementDesc,
29502947
Allocator.allocate(ElementDesc, static_cast<size_t>(NumElements),
29512948
S.Ctx.getEvalID(), DynamicAllocator::Form::Array);
29522949
assert(B);
2953-
2954-
S.Stk.push<Pointer>(B, sizeof(InlineDescriptor));
2955-
2950+
S.Stk.push<Pointer>(B);
29562951
return true;
29572952
}
29582953

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,49 +1655,50 @@ static bool interp__builtin_operator_new(InterpState &S, CodePtr OpPC,
16551655
return false;
16561656
}
16571657

1658+
bool IsArray = NumElems.ugt(1);
16581659
std::optional<PrimType> ElemT = S.getContext().classify(ElemType);
16591660
DynamicAllocator &Allocator = S.getAllocator();
16601661
if (ElemT) {
1661-
if (NumElems.ule(1)) {
1662-
const Descriptor *Desc =
1663-
S.P.createDescriptor(NewCall, *ElemT, Descriptor::InlineDescMD,
1664-
/*IsConst=*/false, /*IsTemporary=*/false,
1665-
/*IsMutable=*/false);
1666-
Block *B = Allocator.allocate(Desc, S.getContext().getEvalID(),
1662+
if (IsArray) {
1663+
Block *B = Allocator.allocate(NewCall, *ElemT, NumElems.getZExtValue(),
1664+
S.Ctx.getEvalID(),
16671665
DynamicAllocator::Form::Operator);
16681666
assert(B);
1669-
1670-
S.Stk.push<Pointer>(B);
1667+
S.Stk.push<Pointer>(Pointer(B).atIndex(0));
16711668
return true;
16721669
}
1673-
assert(NumElems.ugt(1));
16741670

1675-
Block *B =
1676-
Allocator.allocate(NewCall, *ElemT, NumElems.getZExtValue(),
1677-
S.Ctx.getEvalID(), DynamicAllocator::Form::Operator);
1671+
const Descriptor *Desc =
1672+
S.P.createDescriptor(NewCall, *ElemT, Descriptor::InlineDescMD,
1673+
/*IsConst=*/false, /*IsTemporary=*/false,
1674+
/*IsMutable=*/false);
1675+
Block *B = Allocator.allocate(Desc, S.getContext().getEvalID(),
1676+
DynamicAllocator::Form::Operator);
16781677
assert(B);
1678+
16791679
S.Stk.push<Pointer>(B);
16801680
return true;
16811681
}
16821682

16831683
assert(!ElemT);
16841684
// Structs etc.
16851685
const Descriptor *Desc = S.P.createDescriptor(
1686-
NewCall, ElemType.getTypePtr(), Descriptor::InlineDescMD,
1686+
NewCall, ElemType.getTypePtr(),
1687+
IsArray ? std::nullopt : Descriptor::InlineDescMD,
16871688
/*IsConst=*/false, /*IsTemporary=*/false, /*IsMutable=*/false,
16881689
/*Init=*/nullptr);
16891690

1690-
if (NumElems.ule(1)) {
1691-
Block *B = Allocator.allocate(Desc, S.getContext().getEvalID(),
1692-
DynamicAllocator::Form::Operator);
1691+
if (IsArray) {
1692+
Block *B =
1693+
Allocator.allocate(Desc, NumElems.getZExtValue(), S.Ctx.getEvalID(),
1694+
DynamicAllocator::Form::Operator);
16931695
assert(B);
1694-
S.Stk.push<Pointer>(B);
1696+
S.Stk.push<Pointer>(Pointer(B).atIndex(0));
16951697
return true;
16961698
}
16971699

1698-
Block *B =
1699-
Allocator.allocate(Desc, NumElems.getZExtValue(), S.Ctx.getEvalID(),
1700-
DynamicAllocator::Form::Operator);
1700+
Block *B = Allocator.allocate(Desc, S.getContext().getEvalID(),
1701+
DynamicAllocator::Form::Operator);
17011702
assert(B);
17021703
S.Stk.push<Pointer>(B);
17031704
return true;

clang/lib/AST/ByteCode/Program.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,8 @@ Descriptor *Program::createDescriptor(const DeclTy &D, const Type *Ty,
432432
return allocateDescriptor(D, *T, MDSize, IsTemporary,
433433
Descriptor::UnknownSize{});
434434
} else {
435-
const Descriptor *Desc = createDescriptor(D, ElemTy.getTypePtr(),
436-
MDSize, IsConst, IsTemporary);
435+
const Descriptor *Desc = createDescriptor(
436+
D, ElemTy.getTypePtr(), std::nullopt, IsConst, IsTemporary);
437437
if (!Desc)
438438
return nullptr;
439439
return allocateDescriptor(D, Desc, MDSize, IsTemporary,

clang/lib/Headers/amxavx512intrin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
/// dst.byte[i] := a.row[row_index].byte[row_chunk+i]
229229
/// ENDFOR
230230
/// \endcode
231-
#define _tile_movrow(a, b) __builtin_ia32_tilemovrow(a, b)
231+
#define _tile_movrow(a, b) ((__m512i)__builtin_ia32_tilemovrow(a, b))
232232

233233
/// This is internal intrinsic. C/C++ user should avoid calling it directly.
234234

clang/lib/Headers/shaintrin.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@
4747
/// An immediate value where bits [1:0] select among four possible
4848
/// combining functions and rounding constants (not specified here).
4949
/// \returns A 128-bit vector of [4 x i32] containing the updated SHA-1 state.
50-
#define _mm_sha1rnds4_epu32(V1, V2, M) \
51-
__builtin_ia32_sha1rnds4((__v4si)(__m128i)(V1), (__v4si)(__m128i)(V2), (M))
50+
#define _mm_sha1rnds4_epu32(V1, V2, M) \
51+
((__m128i)__builtin_ia32_sha1rnds4((__v4si)(__m128i)(V1), \
52+
(__v4si)(__m128i)(V2), (M)))
5253

5354
/// Calculates the SHA-1 state variable E from the SHA-1 state variables in
5455
/// the 128-bit vector of [4 x i32] in \a __X, adds that to the next set of
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// RUN: %clang_cc1 -std=c++2c -fexperimental-new-constant-interpreter -verify=expected,both %s
2+
// RUN: %clang_cc1 -std=c++2c -verify=ref,both %s
3+
4+
5+
/// This example used to cause an invalid read because allocating
6+
/// an array needs to return a pointer to the first element,
7+
/// not to the array.
8+
9+
namespace std {
10+
using size_t = decltype(sizeof(0));
11+
12+
template <class _Tp>
13+
class allocator {
14+
public:
15+
typedef size_t size_type;
16+
typedef _Tp value_type;
17+
constexpr _Tp *allocate(size_t __n) {
18+
return static_cast<_Tp *>(::operator new(__n * sizeof(_Tp)));
19+
}
20+
};
21+
}
22+
23+
void *operator new(std::size_t, void *p) { return p; }
24+
void* operator new[] (std::size_t, void* p) {return p;}
25+
26+
namespace std {
27+
template <class _Ep>
28+
class initializer_list {
29+
const _Ep *__begin_;
30+
__SIZE_TYPE__ __size_;
31+
32+
public:
33+
typedef _Ep value_type;
34+
typedef const _Ep &reference;
35+
constexpr __SIZE_TYPE__ size() const noexcept { return __size_; }
36+
constexpr const _Ep *begin() const noexcept { return __begin_; }
37+
constexpr const _Ep *end() const noexcept { return __begin_ + __size_; }
38+
};
39+
}
40+
41+
template<typename T>
42+
class vector {
43+
public:
44+
constexpr vector(std::initializer_list<T> Ts) {
45+
A = B = std::allocator<T>{}.allocate(Ts.size()); // both-note {{heap allocation performed here}}
46+
47+
new (A) T(*Ts.begin());
48+
}
49+
private:
50+
T *A = nullptr;
51+
T *B = nullptr;
52+
};
53+
54+
constexpr vector<vector<int>> ints = {{3}, {4}}; // both-error {{must be initialized by a constant expression}} \
55+
// both-note {{pointer to}}

0 commit comments

Comments
 (0)