Skip to content

Commit 500e7ab

Browse files
authored
merge main into amd-staging (llvm#3079)
2 parents 9c32abb + 5076930 commit 500e7ab

File tree

20 files changed

+412
-130
lines changed

20 files changed

+412
-130
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,7 @@ Bug Fixes to C++ Support
971971
consistently treat the initializer as manifestly constant-evaluated.
972972
(#GH135281)
973973
- Fix a crash in the presence of invalid base classes. (#GH147186)
974+
- Fix a crash with NTTP when instantiating local class.
974975

975976
Bug Fixes to AST Handling
976977
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4412,8 +4412,12 @@ Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation,
44124412
// No need to instantiate in-class initializers during explicit
44134413
// instantiation.
44144414
if (Field->hasInClassInitializer() && TSK == TSK_ImplicitInstantiation) {
4415+
// Handle local classes which could have substituted template params.
44154416
CXXRecordDecl *ClassPattern =
4416-
Instantiation->getTemplateInstantiationPattern();
4417+
Instantiation->isLocalClass()
4418+
? Instantiation->getInstantiatedFromMemberClass()
4419+
: Instantiation->getTemplateInstantiationPattern();
4420+
44174421
DeclContext::lookup_result Lookup =
44184422
ClassPattern->lookup(Field->getDeclName());
44194423
FieldDecl *Pattern = Lookup.find_first<FieldDecl>();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %clang_cc1 -fsyntax-only %s -verify
2+
// expected-no-diagnostics
3+
4+
template <int i>
5+
int g() {
6+
return [] (auto) -> int {
7+
struct L {
8+
int m = i;
9+
};
10+
return 0;
11+
} (42);
12+
}
13+
14+
int v = g<1>();

libcxx/include/unordered_map

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -967,9 +967,8 @@ private:
967967
typedef __hash_value_type<key_type, mapped_type> __value_type;
968968
typedef __unordered_map_hasher<key_type, value_type, hasher, key_equal> __hasher;
969969
typedef __unordered_map_equal<key_type, value_type, key_equal, hasher> __key_equal;
970-
typedef __rebind_alloc<allocator_traits<allocator_type>, __value_type> __allocator_type;
971970

972-
typedef __hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table;
971+
typedef __hash_table<__value_type, __hasher, __key_equal, allocator_type> __table;
973972

974973
__table __table_;
975974

@@ -1777,9 +1776,8 @@ private:
17771776
typedef __hash_value_type<key_type, mapped_type> __value_type;
17781777
typedef __unordered_map_hasher<key_type, value_type, hasher, key_equal> __hasher;
17791778
typedef __unordered_map_equal<key_type, value_type, key_equal, hasher> __key_equal;
1780-
typedef __rebind_alloc<allocator_traits<allocator_type>, __value_type> __allocator_type;
17811779

1782-
typedef __hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table;
1780+
typedef __hash_table<__value_type, __hasher, __key_equal, allocator_type> __table;
17831781

17841782
__table __table_;
17851783

libcxx/test/std/containers/associative/multimap/incomplete_type.pass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include <map>
1515

16+
#include "min_allocator.h"
1617
#include "test_macros.h"
1718

1819
struct A {
@@ -28,5 +29,8 @@ inline bool operator<(A const& L, A const& R) { return L.data < R.data; }
2829
int main(int, char**) {
2930
A a;
3031

32+
// Make sure that the allocator isn't rebound to and incomplete type
33+
std::multimap<int, int, std::less<int>, complete_type_allocator<std::pair<const int, int> > > m;
34+
3135
return 0;
3236
}

libcxx/test/std/containers/unord/unord.map/incomplete_type.pass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <unordered_map>
1616

17+
#include "min_allocator.h"
1718
#include "test_macros.h"
1819

1920
template <class Tp>
@@ -36,5 +37,9 @@ inline bool operator==(A const& L, A const& R) { return &L == &R; }
3637
int main(int, char**) {
3738
A a;
3839

40+
// Make sure that the allocator isn't rebound to an incomplete type
41+
std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, complete_type_allocator<std::pair<const int, int> > >
42+
m;
43+
3944
return 0;
4045
}

libcxx/test/std/containers/unord/unord.multimap/incomplete.pass.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <unordered_map>
1616

17+
#include "min_allocator.h"
1718
#include "test_macros.h"
1819

1920
template <class Tp>
@@ -36,5 +37,13 @@ inline bool operator==(A const& L, A const& R) { return &L == &R; }
3637
int main(int, char**) {
3738
A a;
3839

40+
// Make sure that the allocator isn't rebound to an incomplete type
41+
std::unordered_multimap<int,
42+
int,
43+
std::hash<int>,
44+
std::equal_to<int>,
45+
complete_type_allocator<std::pair<const int, int> > >
46+
m;
47+
3948
return 0;
4049
}

llvm/cmake/config-ix.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ set(USE_NO_UNINITIALIZED 0)
510510
# false positives.
511511
if (CMAKE_COMPILER_IS_GNUCXX)
512512
# Disable all -Wuninitialized warning for old GCC versions.
513-
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.0)
513+
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15.0)
514514
set(USE_NO_UNINITIALIZED 1)
515515
else()
516516
set(USE_NO_MAYBE_UNINITIALIZED 1)

llvm/include/llvm/MC/MCSection.h

Lines changed: 94 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -31,101 +31,21 @@ class MCAsmInfo;
3131
class MCAssembler;
3232
class MCContext;
3333
class MCExpr;
34+
class MCFragment;
3435
class MCObjectStreamer;
3536
class MCSymbol;
3637
class MCSection;
3738
class MCSubtargetInfo;
3839
class raw_ostream;
3940
class Triple;
4041

41-
// Represents a contiguous piece of code or data within a section. Its size is
42-
// determined by MCAssembler::layout. All subclasses must have trivial
43-
// destructors.
44-
//
45-
// Declaration order: MCFragment, MCSection, then MCFragment's derived classes.
46-
// This allows MCSection's inline functions to access MCFragment members and
47-
// allows MCFragment's derived classes to access MCSection.
48-
class MCFragment {
49-
friend class MCAssembler;
50-
friend class MCObjectStreamer;
51-
friend class MCSection;
52-
53-
public:
54-
enum FragmentType : uint8_t {
55-
FT_Data,
56-
FT_Relaxable,
57-
FT_Align,
58-
FT_Fill,
59-
FT_LEB,
60-
FT_Nops,
61-
FT_Org,
62-
FT_Dwarf,
63-
FT_DwarfFrame,
64-
FT_BoundaryAlign,
65-
FT_SymbolId,
66-
FT_CVInlineLines,
67-
FT_CVDefRange,
68-
FT_PseudoProbe,
69-
};
70-
71-
private:
72-
// The next fragment within the section.
73-
MCFragment *Next = nullptr;
74-
75-
/// The data for the section this fragment is in.
76-
MCSection *Parent = nullptr;
77-
78-
/// The offset of this fragment in its section.
79-
uint64_t Offset = 0;
80-
81-
/// The layout order of this fragment.
82-
unsigned LayoutOrder = 0;
83-
84-
FragmentType Kind;
85-
86-
protected:
87-
/// Used by subclasses for better packing.
88-
///
89-
/// MCEncodedFragment
90-
bool HasInstructions : 1;
91-
bool AlignToBundleEnd : 1;
92-
/// MCDataFragment
93-
bool LinkerRelaxable : 1;
94-
/// MCRelaxableFragment: x86-specific
95-
bool AllowAutoPadding : 1;
96-
97-
LLVM_ABI MCFragment(FragmentType Kind, bool HasInstructions);
98-
99-
public:
100-
MCFragment() = delete;
101-
MCFragment(const MCFragment &) = delete;
102-
MCFragment &operator=(const MCFragment &) = delete;
103-
104-
MCFragment *getNext() const { return Next; }
105-
106-
FragmentType getKind() const { return Kind; }
107-
108-
MCSection *getParent() const { return Parent; }
109-
void setParent(MCSection *Value) { Parent = Value; }
110-
111-
LLVM_ABI const MCSymbol *getAtom() const;
112-
113-
unsigned getLayoutOrder() const { return LayoutOrder; }
114-
void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
115-
116-
/// Does this fragment have instructions emitted into it? By default
117-
/// this is false, but specific fragment types may set it to true.
118-
bool hasInstructions() const { return HasInstructions; }
119-
120-
LLVM_ABI void dump() const;
121-
};
122-
12342
/// Instances of this class represent a uniqued identifier for a section in the
12443
/// current translation unit. The MCContext class uniques and creates these.
12544
class LLVM_ABI MCSection {
12645
public:
12746
friend MCAssembler;
12847
friend MCObjectStreamer;
48+
friend class MCFragment;
12949
friend class MCEncodedFragment;
13050
friend class MCRelaxableFragment;
13151
static constexpr unsigned NonUniqueID = ~0U;
@@ -155,10 +75,7 @@ class LLVM_ABI MCSection {
15575
MCFragment &operator*() const { return *F; }
15676
bool operator==(const iterator &O) const { return F == O.F; }
15777
bool operator!=(const iterator &O) const { return F != O.F; }
158-
iterator &operator++() {
159-
F = F->Next;
160-
return *this;
161-
}
78+
iterator &operator++();
16279
};
16380

16481
struct FragList {
@@ -296,6 +213,87 @@ class LLVM_ABI MCSection {
296213
virtual StringRef getVirtualSectionKind() const;
297214
};
298215

216+
// Represents a contiguous piece of code or data within a section. Its size is
217+
// determined by MCAssembler::layout. All subclasses must have trivial
218+
// destructors.
219+
class MCFragment {
220+
friend class MCAssembler;
221+
friend class MCObjectStreamer;
222+
friend class MCSection;
223+
224+
public:
225+
enum FragmentType : uint8_t {
226+
FT_Data,
227+
FT_Relaxable,
228+
FT_Align,
229+
FT_Fill,
230+
FT_LEB,
231+
FT_Nops,
232+
FT_Org,
233+
FT_Dwarf,
234+
FT_DwarfFrame,
235+
FT_BoundaryAlign,
236+
FT_SymbolId,
237+
FT_CVInlineLines,
238+
FT_CVDefRange,
239+
FT_PseudoProbe,
240+
};
241+
242+
private:
243+
// The next fragment within the section.
244+
MCFragment *Next = nullptr;
245+
246+
/// The data for the section this fragment is in.
247+
MCSection *Parent = nullptr;
248+
249+
/// The offset of this fragment in its section.
250+
uint64_t Offset = 0;
251+
252+
/// The layout order of this fragment.
253+
unsigned LayoutOrder = 0;
254+
255+
FragmentType Kind;
256+
257+
protected:
258+
/// Used by subclasses for better packing.
259+
///
260+
/// MCEncodedFragment
261+
bool HasInstructions : 1;
262+
bool AlignToBundleEnd : 1;
263+
/// MCDataFragment
264+
bool LinkerRelaxable : 1;
265+
/// MCRelaxableFragment: x86-specific
266+
bool AllowAutoPadding : 1;
267+
268+
LLVM_ABI MCFragment(FragmentType Kind, bool HasInstructions);
269+
270+
public:
271+
MCFragment() = delete;
272+
MCFragment(const MCFragment &) = delete;
273+
MCFragment &operator=(const MCFragment &) = delete;
274+
275+
MCFragment *getNext() const { return Next; }
276+
277+
FragmentType getKind() const { return Kind; }
278+
279+
MCSection *getParent() const { return Parent; }
280+
void setParent(MCSection *Value) { Parent = Value; }
281+
282+
LLVM_ABI const MCSymbol *getAtom() const;
283+
284+
unsigned getLayoutOrder() const { return LayoutOrder; }
285+
void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
286+
287+
/// Does this fragment have instructions emitted into it? By default
288+
/// this is false, but specific fragment types may set it to true.
289+
bool hasInstructions() const { return HasInstructions; }
290+
291+
bool isLinkerRelaxable() const { return LinkerRelaxable; }
292+
void setLinkerRelaxable() { LinkerRelaxable = true; }
293+
294+
LLVM_ABI void dump() const;
295+
};
296+
299297
/// Interface implemented by fragments that contain encoded instructions and/or
300298
/// data.
301299
class MCEncodedFragment : public MCFragment {
@@ -357,6 +355,9 @@ class MCEncodedFragment : public MCFragment {
357355
this->STI = &STI;
358356
}
359357

358+
bool getAllowAutoPadding() const { return AllowAutoPadding; }
359+
void setAllowAutoPadding(bool V) { AllowAutoPadding = V; }
360+
360361
// Content-related functions manage parent's storage using ContentStart and
361362
// ContentSize.
362363
void clearContents() { ContentEnd = ContentStart; }
@@ -407,6 +408,8 @@ class MCEncodedFragment : public MCFragment {
407408
return ArrayRef(getParent()->FixupStorage)
408409
.slice(FixupStart, FixupEnd - FixupStart);
409410
}
411+
412+
size_t getSize() const { return ContentEnd - ContentStart; }
410413
};
411414

412415
/// Fragment for data and encoded instructions.
@@ -418,9 +421,6 @@ class MCDataFragment : public MCEncodedFragment {
418421
static bool classof(const MCFragment *F) {
419422
return F->getKind() == MCFragment::FT_Data;
420423
}
421-
422-
bool isLinkerRelaxable() const { return LinkerRelaxable; }
423-
void setLinkerRelaxable() { LinkerRelaxable = true; }
424424
};
425425

426426
/// A relaxable fragment holds on to its MCInst, since it may need to be
@@ -463,9 +463,6 @@ class MCRelaxableFragment : public MCEncodedFragment {
463463
llvm::copy(Inst, S.begin() + OperandStart);
464464
}
465465

466-
bool getAllowAutoPadding() const { return AllowAutoPadding; }
467-
void setAllowAutoPadding(bool V) { AllowAutoPadding = V; }
468-
469466
static bool classof(const MCFragment *F) {
470467
return F->getKind() == MCFragment::FT_Relaxable;
471468
}
@@ -794,6 +791,11 @@ class MCPseudoProbeAddrFragment : public MCEncodedFragment {
794791
}
795792
};
796793

794+
inline MCSection::iterator &MCSection::iterator::operator++() {
795+
F = F->Next;
796+
return *this;
797+
}
798+
797799
} // end namespace llvm
798800

799801
#endif // LLVM_MC_MCSECTION_H

0 commit comments

Comments
 (0)