Skip to content

Commit f6a90f0

Browse files
authored
[C++17] Force C++17 when build DXC (microsoft#5520)
This is for enable clang-cl build on windows. The gtest fix is merging from google/googletest@f66ab00 to work around 'operator <<' is ambiguous on DefaultPrintNonContainerTo.
1 parent c2233c6 commit f6a90f0

File tree

10 files changed

+31
-46
lines changed

10 files changed

+31
-46
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# See docs/CMake.html for instructions about how to build LLVM with CMake.
22
cmake_minimum_required(VERSION 3.17.2) # HLSL Change - Require CMake 3.17.2.
33

4+
set(CMAKE_CXX_STANDARD 17)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
47
if (NOT "${DXC_CMAKE_BEGINS_INCLUDE}" STREQUAL "")
58
include(${DXC_CMAKE_BEGINS_INCLUDE})
69
endif()

lib/Support/MSFileSystemBasic.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ static
4545
DWORD WIN32_FROM_HRESULT(HRESULT hr)
4646
{
4747
if (SUCCEEDED(hr)) return ERROR_SUCCESS;
48-
if ((hr & 0xFFFF0000) == MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, 0))
48+
if ((HRESULT)(hr & 0xFFFF0000) ==
49+
MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, 0))
4950
{
5051
// Could have come from many values, but we choose this one
5152
return HRESULT_CODE(hr);
@@ -88,11 +89,6 @@ void ClearStatStg(_Inout_ STATSTG* statStg)
8889
///////////////////////////////////////////////////////////////////////////////////////////////////
8990
// IDxcSystemAccess-based MSFileSystem implementation.
9091

91-
static const int FirstAllocFD = 10;
92-
static const int LastAllocFD = 8 * 1024;
93-
static const HANDLE FirstAllocHandle = (HANDLE)(uintptr_t)FirstAllocFD;
94-
static const HANDLE LastAllocHandle = (HANDLE)(uintptr_t)LastAllocFD;
95-
9692
struct MSFileSystemHandle
9793
{
9894
enum MSFileSystemHandleKind
@@ -109,27 +105,28 @@ struct MSFileSystemHandle
109105
int fd; // For a file handle, its file descriptor.
110106

111107
MSFileSystemHandle(int knownFD)
112-
: fd(knownFD)
113-
, kind(MSFileSystemHandleKind_FileHandle)
108+
: kind(MSFileSystemHandleKind_FileHandle),
109+
fd(knownFD)
114110
{
115111
}
116112

117113
MSFileSystemHandle(IUnknown* pMapping)
118-
: storage(pMapping)
119-
, kind(MSFileSystemHandleKind_FileMappingHandle)
114+
: kind(MSFileSystemHandleKind_FileMappingHandle)
115+
, storage(pMapping)
120116
, fd(0)
121117
{
122118
}
123119

124120
MSFileSystemHandle(IUnknown* pStorage, IStream* pStream)
125-
: storage(pStorage)
121+
: kind(MSFileSystemHandleKind_FileHandle) ,
122+
storage(pStorage)
126123
, stream(pStream)
127-
, kind(MSFileSystemHandleKind_FileHandle)
128124
, fd(0)
129125
{
130126
}
131127

132-
MSFileSystemHandle(IEnumSTATSTG* pEnumSTATG) : storage(pEnumSTATG), kind(MSFileSystemHandleKind_FindHandle)
128+
MSFileSystemHandle(IEnumSTATSTG *pEnumSTATG)
129+
: kind(MSFileSystemHandleKind_FindHandle) ,storage(pEnumSTATG)
133130
{
134131
}
135132

@@ -445,7 +442,6 @@ BOOL MSFileSystemForIface::FindNextFileW(HANDLE hFindFile, LPWIN32_FIND_DATAW lp
445442
{
446443
HRESULT hr = S_OK;
447444
CComPtr<IEnumSTATSTG> enumStatStg;
448-
BOOL resultValue = FALSE;
449445
STATSTG elt;
450446
ULONG fetched;
451447

@@ -462,7 +458,6 @@ BOOL MSFileSystemForIface::FindNextFileW(HANDLE hFindFile, LPWIN32_FIND_DATAW lp
462458
else
463459
{
464460
IFC(CopyStatStg(&elt, lpFindFileData));
465-
resultValue = TRUE;
466461
}
467462

468463
Cleanup:

lib/Support/Process.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Optional<std::string> Process::FindInEnvPath(const std::string& EnvName,
6868
COLOR(FGBG, "7", BOLD)\
6969
}
7070

71+
[[maybe_unused]]
7172
static const char colorcodes[2][2][8][10] = {
7273
{ ALLCOLORS("3",""), ALLCOLORS("3","1;") },
7374
{ ALLCOLORS("4",""), ALLCOLORS("4","1;") }

lib/Support/Windows/MSFileSystem.inc.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -236,24 +236,6 @@ static bool is_separator(const wchar_t value) {
236236
}
237237
}
238238

239-
// TODO: consider erasing this
240-
namespace {
241-
error_code TempDir(_In_ MSFileSystemRef fsr, SmallVectorImpl<wchar_t> &result) {
242-
retry_temp_dir:
243-
DWORD len = fsr->GetTempPathW(result.capacity(), result.begin());
244-
245-
if (len == 0)
246-
return mapWindowsError(::GetLastError());
247-
248-
if (len > result.capacity()) {
249-
result.reserve(len);
250-
goto retry_temp_dir;
251-
}
252-
253-
result.set_size(len);
254-
return error_code();
255-
}
256-
}
257239

258240
namespace llvm {
259241
namespace sys {

lib/Support/Windows/Mutex.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ using namespace sys;
2424

2525
MutexImpl::MutexImpl(bool /*recursive*/)
2626
{
27-
C_ASSERT(sizeof(data_) == sizeof(CRITICAL_SECTION));
27+
static_assert(sizeof(data_) == sizeof(CRITICAL_SECTION),
28+
"CRITICAL_SECTION size mismatch");
2829
// data_ = new CRITICAL_SECTION; // HLSL Change
2930
InitializeCriticalSection((LPCRITICAL_SECTION)data_);
3031
}

lib/Support/Windows/Process.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ ConvertAndPushArg(const wchar_t *Arg, SmallVectorImpl<const char *> &Args,
176176
return std::error_code();
177177
}
178178

179+
#if 0 // HLSL Change - comment out unused function.
179180
/// \brief Perform wildcard expansion of Arg, or just push it into Args if it
180181
/// doesn't have wildcards or doesn't match any files.
181182
static std::error_code
@@ -222,6 +223,7 @@ WildcardExpand(const wchar_t *Arg, SmallVectorImpl<const char *> &Args,
222223
FindClose(FindHandle);
223224
return ec;
224225
}
226+
#endif
225227

226228
std::error_code
227229
Process::GetArgumentVector(SmallVectorImpl<const char *> &Args,

projects/dxilconv/lib/DxilConvPasses/DxilCleanup.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ class DxilCleanup : public ModulePass {
127127
// I cannot delete these constructors, because vector depends on them, even if I never trigger them.
128128
// So assert if they are hit instead.
129129
LiveRange(const LiveRange &other)
130-
: id(other.id), numI(other.numI), numF(other.numF), numU(other.numU), pNewType(other.pNewType),
131-
defs(other.defs), bitcastMap(other.bitcastMap)
130+
: id(other.id), defs(other.defs),
131+
bitcastMap(other.bitcastMap) ,numI(other.numI), numF(other.numF),
132+
numU(other.numU), pNewType(other.pNewType)
132133
{ DXASSERT_NOMSG(false); }
133134
LiveRange(LiveRange &&other)
134135
: id(other.id), numI(other.numI), numF(other.numF), numU(other.numU), pNewType(other.pNewType),
@@ -1226,7 +1227,7 @@ Value *DxilCleanup::CastValue(Value *pValue, Type *pToType, Instruction *pOrigIn
12261227

12271228
const unsigned kNumTypeArgs = 3;
12281229
Type *ArgTypes[kNumTypeArgs];
1229-
DXIL::OpCode OpCode;
1230+
DXIL::OpCode OpCode = DXIL::OpCode::NumOpCodes;
12301231
if (pType == Type::getFloatTy(*m_pCtx)) {
12311232
IFTBOOL(pToType == Type::getInt32Ty(*m_pCtx), DXC_E_OPTIMIZATION_FAILED);
12321233
OpCode = DXIL::OpCode::BitcastF32toI32;
@@ -1307,6 +1308,8 @@ bool DxilCleanup::IsDxilBitcast(Value *pValue) {
13071308
case OP::OpCode::BitcastI32toF32:
13081309
case OP::OpCode::BitcastI64toF64:
13091310
return true;
1311+
default:
1312+
return false;
13101313
}
13111314
}
13121315
}

tools/clang/lib/Parse/ParseStmt.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ Parser::ParseStatementOrDeclarationAfterAttributes(StmtVector &Stmts,
189189
// punctuator, then we are using them as identifers. Need to change
190190
// the token type to tok::identifier and fall through to the next case.
191191
// E.g., center = <RHS>.
192-
if (tok::isPunctuator(NextToken().getKind())) {
192+
if (!tok::isPunctuator(NextToken().getKind())) {
193+
goto tok_default_case;
194+
} else {
193195
Tok.setKind(tok::identifier);
194196
LLVM_FALLTHROUGH;
195-
} else {
196-
goto tok_default_case;
197197
}
198198
}
199199
// HLSL Change Ends

tools/clang/unittests/HLSLHost/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,10 @@ add_clang_executable(HLSLHost
1111
HLSLHost.cpp
1212
)
1313

14-
target_link_libraries(HLSLHost
15-
ClangHLSLTests
16-
)
17-
1814
set_target_properties(HLSLHost PROPERTIES VERSION ${CLANG_EXECUTABLE_VERSION})
1915

2016
include_directories(AFTER ${DIASDK_INCLUDE_DIRS})
2117

22-
add_dependencies(HLSLHost ClangHLSLTests)
23-
2418
if(UNIX)
2519
set(CLANGXX_LINK_OR_COPY create_symlink)
2620
# Create a relative symlink

utils/unittest/googletest/include/gtest/gtest-printers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,10 @@ void PrintTo(const ::std::pair<T1, T2>& value, ::std::ostream* os) {
683683
*os << ')';
684684
}
685685

686+
#if GTEST_LANG_CXX11
687+
inline void PrintTo(std::nullptr_t, ::std::ostream* os) { *os << "(nullptr)"; }
688+
#endif // GTEST_LANG_CXX11
689+
686690
// Implements printing a non-reference type T by letting the compiler
687691
// pick the right overload of PrintTo() for T.
688692
template <typename T>

0 commit comments

Comments
 (0)