Skip to content

Commit fc05f49

Browse files
authored
More conforming to C++ standards (microsoft#4521)
1. Can't mix char* and const char* 2. Remove redundant const and std::move 3. Use standard types and macros to replace platform dependent ones
1 parent 1a4a01b commit fc05f49

File tree

8 files changed

+21
-22
lines changed

8 files changed

+21
-22
lines changed

lib/DxilDia/DxilDiaSession.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void dxil_dia::Session::Init(std::shared_ptr<llvm::LLVMContext> context,
9898
try {
9999
m_symsMgr.Init(this);
100100
} catch (const hlsl::Exception &) {
101-
m_symsMgr = std::move(dxil_dia::SymbolManager());
101+
m_symsMgr = dxil_dia::SymbolManager();
102102
}
103103
}
104104

projects/dxilconv/include/DxilConvPasses/ScopeNest.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct ScopeNestEvent {
7676
return ScopeNestEvent(nullptr, Type::Invalid);
7777
}
7878

79-
const bool IsBeginScope() const {
79+
bool IsBeginScope() const {
8080
switch (ElementType) {
8181
case Type::TopLevel_Begin:
8282
return "TopLevel_Begin";
@@ -91,7 +91,7 @@ struct ScopeNestEvent {
9191
return false;
9292
}
9393

94-
const bool IsEndScope() const {
94+
bool IsEndScope() const {
9595
switch (ElementType) {
9696
case Type::If_End:
9797
case Type::Switch_End:

projects/dxilconv/lib/DxbcConverter/DxbcConverter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -567,11 +567,11 @@ void DxbcConverter::ExtractSignatureFromDXBC(
567567
memcpy(&P, pParamBase + iElement * uElemSize, uElemSize);
568568
break;
569569
case sizeof(D3D10_INTERNALSHADER_PARAMETER):
570-
static_assert(sizeof(D3D11_INTERNALSHADER_PARAMETER_FOR_GS) ==
571-
sizeof(D3D10_INTERNALSHADER_PARAMETER) +
572-
FIELD_OFFSET(D3D11_INTERNALSHADER_PARAMETER_FOR_GS,
573-
SemanticName),
574-
"Incorrect assumptions about field offset");
570+
static_assert(
571+
sizeof(D3D11_INTERNALSHADER_PARAMETER_FOR_GS) ==
572+
sizeof(D3D10_INTERNALSHADER_PARAMETER) +
573+
offsetof(D3D11_INTERNALSHADER_PARAMETER_FOR_GS, SemanticName),
574+
"Incorrect assumptions about field offset");
575575
memcpy(&P.SemanticName, pParamBase + iElement * uElemSize, uElemSize);
576576
break;
577577
default:

projects/dxilconv/unittests/DxilConvTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class DxilConvTest {
140140
return false;
141141
}
142142
std::string str = std::string(buffer, size);
143-
DWORD pos;
143+
size_t pos;
144144
if ((pos = str.find_last_of("\\")) != std::string::npos) {
145145
str = str.substr(0, pos + 1);
146146
}

tools/clang/unittests/HLSLExec/ExecutionTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5477,7 +5477,7 @@ void ExecutionTest::RunBasicShaderModelTest(D3D_SHADER_MODEL shaderModel) {
54775477
return;
54785478
}
54795479

5480-
char *pShaderModelStr;
5480+
const char *pShaderModelStr;
54815481
if (shaderModel == D3D_SHADER_MODEL_6_1) {
54825482
pShaderModelStr = "cs_6_1";
54835483
} else if (shaderModel == D3D_SHADER_MODEL_6_3) {
@@ -5499,7 +5499,7 @@ void ExecutionTest::RunBasicShaderModelTest(D3D_SHADER_MODEL shaderModel) {
54995499
char shader[sizeof(shaderTemplate) + 50];
55005500

55015501
// Run simple shader with float data types
5502-
char *sTy = "float";
5502+
const char *sTy = "float";
55035503
float inputFloatPairs[] = {1.5f, -2.8f, 3.23e-5f, 6.0f, 181.621f, 14.978f};
55045504
VERIFY_IS_TRUE(sprintf(shader, shaderTemplate, sTy, sTy, sTy) > 0);
55055505
WEX::Logging::Log::Comment(L"BasicShaderModel float");

tools/clang/unittests/HLSLHost/HLSLHost.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ struct HhResultReply {
172172
};
173173

174174
// Logging and tracing.
175-
static void HhTrace(LPWSTR pMessage) { wprintf(L"%s\n", pMessage); }
175+
static void HhTrace(LPCWSTR pMessage) { wprintf(L"%s\n", pMessage); }
176176

177177
template <typename TInterface, typename TObject>
178178
HRESULT DoBasicQueryInterfaceWithRemote(TObject *self, REFIID iid,

tools/clang/unittests/dxc_batch/dxc_batch.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -767,9 +767,6 @@ class DxcBatchContext {
767767

768768
int DxcBatchContext::BatchCompile(bool bMultiThread, bool bLibLink) {
769769
int retVal = 0;
770-
DxcOpts tmp_Opts;
771-
// tmp_Opts = m_Opts;
772-
m_Opts.InputFile;
773770
SmallString<128> path(m_Opts.InputFile.begin(), m_Opts.InputFile.end());
774771
llvm::sys::path::remove_filename(path);
775772

tools/dxexp/dxexp.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ static const char *ShaderModelToStr(D3D_SHADER_MODEL SM) {
187187
}
188188
}
189189

190-
static char *ViewInstancingTierToStr(D3D12_VIEW_INSTANCING_TIER Tier) {
190+
static const char *ViewInstancingTierToStr(D3D12_VIEW_INSTANCING_TIER Tier) {
191191
switch (Tier) {
192192
case D3D12_VIEW_INSTANCING_TIER_NOT_SUPPORTED:
193193
return "NO";
@@ -202,7 +202,7 @@ static char *ViewInstancingTierToStr(D3D12_VIEW_INSTANCING_TIER Tier) {
202202
}
203203
}
204204

205-
static char *RaytracingTierToStr(D3D12_RAYTRACING_TIER Tier) {
205+
static const char *RaytracingTierToStr(D3D12_RAYTRACING_TIER Tier) {
206206
switch (Tier) {
207207
case D3D12_RAYTRACING_TIER_NOT_SUPPORTED:
208208
return "NO";
@@ -296,7 +296,7 @@ static HRESULT PrintAdapters() {
296296
hr = e.m_hr;
297297
json_printf("%c { \"err\": \"unable to print information for adapters - "
298298
"0x%08x\" }\n",
299-
comma, hr);
299+
comma, (unsigned int)hr);
300300
text_printf("%s", "Unable to print information for adapters.\n");
301301
}
302302
json_printf(" ] }\n");
@@ -336,7 +336,8 @@ int main(int argc, const char *argv[]) {
336336
hRuntime = LoadLibraryW(L"d3d12.dll");
337337
if (hRuntime == NULL) {
338338
err = GetLastError();
339-
printf("Failed to load library d3d12.dll - Win32 error %u\n", err);
339+
printf("Failed to load library d3d12.dll - Win32 error %u\n",
340+
(unsigned int)err);
340341
return 1;
341342
}
342343

@@ -356,7 +357,8 @@ int main(int argc, const char *argv[]) {
356357
hRuntime = LoadLibraryW(L"d3d12.dll");
357358
if (hRuntime == NULL) {
358359
err = GetLastError();
359-
printf("Failed to load library d3d12.dll - Win32 error %u\n", err);
360+
printf("Failed to load library d3d12.dll - Win32 error %u\n",
361+
(unsigned int)err);
360362
return 1;
361363
}
362364

@@ -367,7 +369,7 @@ int main(int argc, const char *argv[]) {
367369
err = GetLastError();
368370
printf("Failed to find export 'D3D12EnableExperimentalFeatures' in "
369371
"d3d12.dll - Win32 error %u%s\n",
370-
err,
372+
(unsigned int)err,
371373
err == ERROR_PROC_NOT_FOUND
372374
? " (The specified procedure could not be found.)"
373375
: "");
@@ -411,7 +413,7 @@ int main(int argc, const char *argv[]) {
411413
} else {
412414
text_printf("Experimental shader model feature failed with unexpected "
413415
"HRESULT 0x%08x.\n",
414-
hr);
416+
(unsigned int)hr);
415417
json_printf("{ \"err\": \"0x%08x\" }", hr);
416418
json_printf("\n}\n");
417419
return 4;

0 commit comments

Comments
 (0)