Skip to content

Commit 8f21027

Browse files
authored
Fix C++23 build errors (microsoft#7818)
See context in the linked bug. Bug: crbug.com/388068055
1 parent ea7e910 commit 8f21027

File tree

7 files changed

+178
-125
lines changed

7 files changed

+178
-125
lines changed

include/llvm/IR/CFG.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ namespace llvm {
2929
template <class Ptr, class USE_iterator> // Predecessor Iterator
3030
class PredIterator {
3131
public:
32+
// HLSL Change start: The iterator wasn't satisfying the std::forward_iterator
33+
// concept, which caused std::vector::insert calls to fail in C++23.
3234
using iterator_category = std::forward_iterator_tag;
33-
using value_type = Ptr;
35+
using value_type = Ptr *;
3436
using difference_type = std::ptrdiff_t;
35-
using pointer = Ptr *;
37+
using pointer = Ptr **;
38+
// HLSL Change end
3639
using reference = Ptr *;
3740

3841
private:
@@ -119,8 +122,11 @@ class SuccIterator {
119122

120123
public:
121124
using iterator_category = std::random_access_iterator_tag;
122-
using value_type = BB_;
123-
using difference_type = int;
125+
// HLSL Change start: The iterator wasn't satisfying the std::forward_iterator
126+
// concept, which caused std::vector::insert calls to fail in C++23.
127+
using value_type = BB_ *;
128+
using difference_type = std::ptrdiff_t;
129+
// HLSL Change end
124130
using pointer = BB_ *;
125131
using reference = BB_ *;
126132

include/llvm/IR/Instruction.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ struct ilist_traits<Instruction>
5050
public:
5151
// Saves and takes ownership of the sentinel.
5252
// Must be called before the other accessors above.
53-
void setSentinel(std::unique_ptr<Instruction> &&s) {
54-
Sentinel = std::move(s);
55-
}
53+
// HLSL Change start: definition moved out-of-line because Instruction must be
54+
// a complete type when ~unique_ptr<Instruction> is instantiated in C++23.
55+
inline void setSentinel(std::unique_ptr<Instruction> &&s);
56+
// HLSL Change Ends
5657

5758
private:
5859
std::unique_ptr<Instruction> Sentinel;
@@ -526,6 +527,13 @@ class Instruction : public User, public ilist_node<Instruction> {
526527
Instruction *cloneImpl() const;
527528
};
528529

530+
// HLSL Change start: definition moved out-of-line because Instruction must be
531+
// a complete type when ~unique_ptr<Instruction> is instantiated in C++23.
532+
void ilist_traits<Instruction>::setSentinel(std::unique_ptr<Instruction> &&s) {
533+
Sentinel = std::move(s);
534+
}
535+
// HLSL Change end
536+
529537
// HLSL Change Starts
530538
// Temporarily disable "downcast of address" UBSAN runtime error
531539
// https://github.com/microsoft/DirectXShaderCompiler/issues/6446

include/llvm/TableGen/Record.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ class RecTy {
5757
public:
5858
RecTyKind getRecTyKind() const { return Kind; }
5959

60-
RecTy(RecTyKind K) : Kind(K) {}
61-
virtual ~RecTy() {}
60+
// HLSL Change start: definitions moved out-of-line because ListRecTy must be
61+
// be a complete type when ~unique_ptr<ListRecTy> is instantiated in C++23
62+
// (see ListTy member).
63+
inline RecTy(RecTyKind K);
64+
inline virtual ~RecTy();
65+
// HLSL Change end
6266

6367
virtual std::string getAsString() const = 0;
6468
void print(raw_ostream &OS) const { OS << getAsString(); }
@@ -170,6 +174,14 @@ class ListRecTy : public RecTy {
170174
bool typeIsConvertibleTo(const RecTy *RHS) const override;
171175
};
172176

177+
// HLSL Change start: definitions moved out-of-line because ListRecTy must be
178+
// be a complete type when ~unique_ptr<ListRecTy> is instantiated in C++23 (see
179+
// ListTy member).
180+
RecTy::RecTy(RecTyKind K) : Kind(K) {}
181+
182+
RecTy::~RecTy() {}
183+
// HLSL Change end
184+
173185
/// DagRecTy - 'dag' - Represent a dag fragment
174186
///
175187
class DagRecTy : public RecTy {

lib/HLSL/DxilContainerReflection.cpp

Lines changed: 108 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,114 @@ enum class PublicAPI { D3D12 = 0, D3D11_47 = 1, D3D11_43 = 2, Invalid };
120120
((D3D_SHADER_VARIABLE_CLASS)(D3D_SVC_INTERFACE_POINTER + 1))
121121
#endif
122122

123+
class CShaderReflectionType;
124+
class CShaderReflectionVariable;
125+
class CShaderReflectionConstantBuffer;
126+
class CShaderReflection;
127+
struct D3D11_INTERNALSHADER_RESOURCE_DEF;
128+
class CShaderReflectionType final : public ID3D12ShaderReflectionType {
129+
friend class CShaderReflectionConstantBuffer;
130+
131+
protected:
132+
D3D12_SHADER_TYPE_DESC m_Desc;
133+
UINT m_SizeInCBuffer;
134+
std::string m_Name;
135+
std::vector<StringRef> m_MemberNames;
136+
std::vector<CShaderReflectionType *> m_MemberTypes;
137+
CShaderReflectionType *m_pSubType;
138+
CShaderReflectionType *m_pBaseClass;
139+
std::vector<CShaderReflectionType *> m_Interfaces;
140+
ULONG_PTR m_Identity;
141+
142+
public:
143+
// Internal
144+
HRESULT InitializeEmpty();
145+
HRESULT
146+
Initialize(DxilModule &M, llvm::Type *type,
147+
DxilFieldAnnotation &typeAnnotation, unsigned int baseOffset,
148+
std::vector<std::unique_ptr<CShaderReflectionType>> &allTypes,
149+
bool isCBuffer);
150+
151+
// ID3D12ShaderReflectionType
152+
STDMETHOD(GetDesc)(D3D12_SHADER_TYPE_DESC *pDesc);
153+
154+
STDMETHOD_(ID3D12ShaderReflectionType *, GetMemberTypeByIndex)(UINT Index);
155+
STDMETHOD_(ID3D12ShaderReflectionType *, GetMemberTypeByName)(LPCSTR Name);
156+
STDMETHOD_(LPCSTR, GetMemberTypeName)(UINT Index);
157+
158+
STDMETHOD(IsEqual)(ID3D12ShaderReflectionType *pType);
159+
STDMETHOD_(ID3D12ShaderReflectionType *, GetSubType)();
160+
STDMETHOD_(ID3D12ShaderReflectionType *, GetBaseClass)();
161+
STDMETHOD_(UINT, GetNumInterfaces)();
162+
STDMETHOD_(ID3D12ShaderReflectionType *, GetInterfaceByIndex)(UINT uIndex);
163+
STDMETHOD(IsOfType)(ID3D12ShaderReflectionType *pType);
164+
STDMETHOD(ImplementsInterface)(ID3D12ShaderReflectionType *pBase);
165+
166+
bool CheckEqual(CShaderReflectionType *pOther) {
167+
return m_Identity == pOther->m_Identity;
168+
}
169+
170+
UINT GetCBufferSize() { return m_SizeInCBuffer; }
171+
};
172+
173+
class CShaderReflectionVariable final : public ID3D12ShaderReflectionVariable {
174+
protected:
175+
D3D12_SHADER_VARIABLE_DESC m_Desc;
176+
CShaderReflectionType *m_pType;
177+
CShaderReflectionConstantBuffer *m_pBuffer;
178+
BYTE *m_pDefaultValue;
179+
180+
public:
181+
void Initialize(CShaderReflectionConstantBuffer *pBuffer,
182+
D3D12_SHADER_VARIABLE_DESC *pDesc,
183+
CShaderReflectionType *pType, BYTE *pDefaultValue);
184+
185+
LPCSTR GetName() { return m_Desc.Name; }
186+
187+
// ID3D12ShaderReflectionVariable
188+
STDMETHOD(GetDesc)(D3D12_SHADER_VARIABLE_DESC *pDesc);
189+
190+
STDMETHOD_(ID3D12ShaderReflectionType *, GetType)();
191+
STDMETHOD_(ID3D12ShaderReflectionConstantBuffer *, GetBuffer)();
192+
193+
STDMETHOD_(UINT, GetInterfaceSlot)(UINT uArrayIndex);
194+
};
195+
196+
class CShaderReflectionConstantBuffer final
197+
: public ID3D12ShaderReflectionConstantBuffer {
198+
protected:
199+
D3D12_SHADER_BUFFER_DESC m_Desc;
200+
std::vector<CShaderReflectionVariable> m_Variables;
201+
// For StructuredBuffer arrays, Name will have [0] appended for each dimension
202+
// to match fxc behavior.
203+
std::string m_ReflectionName;
204+
205+
public:
206+
CShaderReflectionConstantBuffer() = default;
207+
CShaderReflectionConstantBuffer(CShaderReflectionConstantBuffer &&other) {
208+
m_Desc = other.m_Desc;
209+
std::swap(m_Variables, other.m_Variables);
210+
}
211+
212+
void Initialize(DxilModule &M, DxilCBuffer &CB,
213+
std::vector<std::unique_ptr<CShaderReflectionType>> &allTypes,
214+
bool bUsageInMetadata);
215+
void InitializeStructuredBuffer(
216+
DxilModule &M, DxilResource &R,
217+
std::vector<std::unique_ptr<CShaderReflectionType>> &allTypes);
218+
void InitializeTBuffer(
219+
DxilModule &M, DxilResource &R,
220+
std::vector<std::unique_ptr<CShaderReflectionType>> &allTypes,
221+
bool bUsageInMetadata);
222+
LPCSTR GetName() { return m_Desc.Name; }
223+
224+
// ID3D12ShaderReflectionConstantBuffer
225+
STDMETHOD(GetDesc)(D3D12_SHADER_BUFFER_DESC *pDesc);
226+
227+
STDMETHOD_(ID3D12ShaderReflectionVariable *, GetVariableByIndex)(UINT Index);
228+
STDMETHOD_(ID3D12ShaderReflectionVariable *, GetVariableByName)(LPCSTR Name);
229+
};
230+
123231
class DxilModuleReflection {
124232
public:
125233
hlsl::RDAT::DxilRuntimeData m_RDAT;
@@ -541,114 +649,6 @@ void hlsl::CreateDxcContainerReflection(IDxcContainerReflection **ppResult) {
541649
///////////////////////////////////////////////////////////////////////////////
542650
// DxilShaderReflection implementation - helper objects. //
543651

544-
class CShaderReflectionType;
545-
class CShaderReflectionVariable;
546-
class CShaderReflectionConstantBuffer;
547-
class CShaderReflection;
548-
struct D3D11_INTERNALSHADER_RESOURCE_DEF;
549-
class CShaderReflectionType final : public ID3D12ShaderReflectionType {
550-
friend class CShaderReflectionConstantBuffer;
551-
552-
protected:
553-
D3D12_SHADER_TYPE_DESC m_Desc;
554-
UINT m_SizeInCBuffer;
555-
std::string m_Name;
556-
std::vector<StringRef> m_MemberNames;
557-
std::vector<CShaderReflectionType *> m_MemberTypes;
558-
CShaderReflectionType *m_pSubType;
559-
CShaderReflectionType *m_pBaseClass;
560-
std::vector<CShaderReflectionType *> m_Interfaces;
561-
ULONG_PTR m_Identity;
562-
563-
public:
564-
// Internal
565-
HRESULT InitializeEmpty();
566-
HRESULT
567-
Initialize(DxilModule &M, llvm::Type *type,
568-
DxilFieldAnnotation &typeAnnotation, unsigned int baseOffset,
569-
std::vector<std::unique_ptr<CShaderReflectionType>> &allTypes,
570-
bool isCBuffer);
571-
572-
// ID3D12ShaderReflectionType
573-
STDMETHOD(GetDesc)(D3D12_SHADER_TYPE_DESC *pDesc);
574-
575-
STDMETHOD_(ID3D12ShaderReflectionType *, GetMemberTypeByIndex)(UINT Index);
576-
STDMETHOD_(ID3D12ShaderReflectionType *, GetMemberTypeByName)(LPCSTR Name);
577-
STDMETHOD_(LPCSTR, GetMemberTypeName)(UINT Index);
578-
579-
STDMETHOD(IsEqual)(ID3D12ShaderReflectionType *pType);
580-
STDMETHOD_(ID3D12ShaderReflectionType *, GetSubType)();
581-
STDMETHOD_(ID3D12ShaderReflectionType *, GetBaseClass)();
582-
STDMETHOD_(UINT, GetNumInterfaces)();
583-
STDMETHOD_(ID3D12ShaderReflectionType *, GetInterfaceByIndex)(UINT uIndex);
584-
STDMETHOD(IsOfType)(ID3D12ShaderReflectionType *pType);
585-
STDMETHOD(ImplementsInterface)(ID3D12ShaderReflectionType *pBase);
586-
587-
bool CheckEqual(CShaderReflectionType *pOther) {
588-
return m_Identity == pOther->m_Identity;
589-
}
590-
591-
UINT GetCBufferSize() { return m_SizeInCBuffer; }
592-
};
593-
594-
class CShaderReflectionVariable final : public ID3D12ShaderReflectionVariable {
595-
protected:
596-
D3D12_SHADER_VARIABLE_DESC m_Desc;
597-
CShaderReflectionType *m_pType;
598-
CShaderReflectionConstantBuffer *m_pBuffer;
599-
BYTE *m_pDefaultValue;
600-
601-
public:
602-
void Initialize(CShaderReflectionConstantBuffer *pBuffer,
603-
D3D12_SHADER_VARIABLE_DESC *pDesc,
604-
CShaderReflectionType *pType, BYTE *pDefaultValue);
605-
606-
LPCSTR GetName() { return m_Desc.Name; }
607-
608-
// ID3D12ShaderReflectionVariable
609-
STDMETHOD(GetDesc)(D3D12_SHADER_VARIABLE_DESC *pDesc);
610-
611-
STDMETHOD_(ID3D12ShaderReflectionType *, GetType)();
612-
STDMETHOD_(ID3D12ShaderReflectionConstantBuffer *, GetBuffer)();
613-
614-
STDMETHOD_(UINT, GetInterfaceSlot)(UINT uArrayIndex);
615-
};
616-
617-
class CShaderReflectionConstantBuffer final
618-
: public ID3D12ShaderReflectionConstantBuffer {
619-
protected:
620-
D3D12_SHADER_BUFFER_DESC m_Desc;
621-
std::vector<CShaderReflectionVariable> m_Variables;
622-
// For StructuredBuffer arrays, Name will have [0] appended for each dimension
623-
// to match fxc behavior.
624-
std::string m_ReflectionName;
625-
626-
public:
627-
CShaderReflectionConstantBuffer() = default;
628-
CShaderReflectionConstantBuffer(CShaderReflectionConstantBuffer &&other) {
629-
m_Desc = other.m_Desc;
630-
std::swap(m_Variables, other.m_Variables);
631-
}
632-
633-
void Initialize(DxilModule &M, DxilCBuffer &CB,
634-
std::vector<std::unique_ptr<CShaderReflectionType>> &allTypes,
635-
bool bUsageInMetadata);
636-
void InitializeStructuredBuffer(
637-
DxilModule &M, DxilResource &R,
638-
std::vector<std::unique_ptr<CShaderReflectionType>> &allTypes);
639-
void InitializeTBuffer(
640-
DxilModule &M, DxilResource &R,
641-
std::vector<std::unique_ptr<CShaderReflectionType>> &allTypes,
642-
bool bUsageInMetadata);
643-
LPCSTR GetName() { return m_Desc.Name; }
644-
645-
// ID3D12ShaderReflectionConstantBuffer
646-
STDMETHOD(GetDesc)(D3D12_SHADER_BUFFER_DESC *pDesc);
647-
648-
STDMETHOD_(ID3D12ShaderReflectionVariable *, GetVariableByIndex)(UINT Index);
649-
STDMETHOD_(ID3D12ShaderReflectionVariable *, GetVariableByName)(LPCSTR Name);
650-
};
651-
652652
// Invalid type sentinel definitions
653653
class CInvalidSRType;
654654
class CInvalidSRVariable;

tools/clang/lib/Driver/Tools.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,12 @@ SmallString<128> getCompilerRT(const ToolChain &TC, StringRef Component,
9494
mutable std::unique_ptr<visualstudio::Compiler> CLFallback;
9595

9696
public:
97-
// CAUTION! The first constructor argument ("clang") is not arbitrary,
98-
// as it is for other tools. Some operations on a Tool actually test
99-
// whether that tool is Clang based on the Tool's Name as a string.
100-
Clang(const ToolChain &TC) : Tool("clang", "clang frontend", TC, RF_Full) {}
97+
// HLSL Change start: definition moved out-of-line since
98+
// visualstudio::Compiler must be a complete type when
99+
// ~unique_ptr<visualstudio::Compiler> is instantiated in C++23 (see
100+
// CLFallback member).
101+
inline Clang(const ToolChain &TC);
102+
// HLSL Change end
101103

102104
bool hasGoodDiagnostics() const override { return true; }
103105
bool hasIntegratedAssembler() const override { return true; }
@@ -675,6 +677,16 @@ class LLVM_LIBRARY_VISIBILITY Compiler : public Tool {
675677
};
676678
} // end namespace visualstudio
677679

680+
// HLSL Change start: definition moved out-of-line since visualstudio::Compiler
681+
// must be a complete type when ~unique_ptr<visualstudio::Compiler> is
682+
// instantiated in C++23 (see CLFallback member).
683+
// CAUTION! The first constructor argument ("clang") is not arbitrary,
684+
// as it is for other tools. Some operations on a Tool actually test
685+
// whether that tool is Clang based on the Tool's Name as a string.
686+
Clang::Clang(const ToolChain &TC)
687+
: Tool("clang", "clang frontend", TC, RF_Full) {}
688+
// HLSL Change end
689+
678690
/// MinGW -- Directly call GNU Binutils assembler and linker
679691
namespace MinGW {
680692
class LLVM_LIBRARY_VISIBILITY Assembler : public Tool {

tools/clang/lib/Format/FormatToken.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,12 @@ class AnnotatedLine;
110110
/// \brief A wrapper around a \c Token storing information about the
111111
/// whitespace characters preceding it.
112112
struct FormatToken {
113-
FormatToken() {}
113+
// HLSL Change start: in C++23, TokenRole must be a complete type when
114+
// ~unique_ptr<TokenRole> is instantiated. Explicitly defaulting the
115+
// constructor allows the compiler to generate its code later, when TokenRule
116+
// is complete.
117+
FormatToken() = default;
118+
// HLSL Change end
114119

115120
/// \brief The \c Token.
116121
Token Tok;

tools/clang/tools/libclang/CIndexDiagnostic.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ class CXDiagnosticSetImpl {
2929
std::vector<std::unique_ptr<CXDiagnosticImpl>> Diagnostics;
3030
const bool IsExternallyManaged;
3131
public:
32-
CXDiagnosticSetImpl(bool isManaged = false)
33-
: IsExternallyManaged(isManaged) {}
32+
// HLSL Change start: definition moved out-of-line because CXDiagnosticImpl
33+
// must be a complete type when ~unique_ptr<CXDiagnosticImpl> is instantiated
34+
// in C++23 (Diagnostics member).
35+
inline CXDiagnosticSetImpl(bool isManaged = false);
36+
// HLSL Change end
3437

3538
virtual ~CXDiagnosticSetImpl();
3639

@@ -107,7 +110,14 @@ class CXDiagnosticImpl {
107110
private:
108111
Kind K;
109112
};
110-
113+
114+
// HLSL Change start: definition moved out-of-line because CXDiagnosticImpl must
115+
// be a complete type when ~unique_ptr<CXDiagnosticImpl> is instantiated in
116+
// C++23 (Diagnostics member).
117+
CXDiagnosticSetImpl::CXDiagnosticSetImpl(bool isManaged)
118+
: IsExternallyManaged(isManaged) {}
119+
// HLSL Change end
120+
111121
/// \brief The storage behind a CXDiagnostic
112122
struct CXStoredDiagnostic : public CXDiagnosticImpl {
113123
const StoredDiagnostic &Diag;

0 commit comments

Comments
 (0)