Skip to content

Commit 517e702

Browse files
authored
[ClangCL] fix warning for clang unit test. (microsoft#5708)
1. remove unused variable. 2. use 1u instead 1 to avoid signed unsigned mismatch. 3. use std::size to replace _countof. 4. Use LPCWSTR/LPCSTR instead of LPWSTR/LPSTR.
1 parent 1dac9d8 commit 517e702

File tree

6 files changed

+26
-30
lines changed

6 files changed

+26
-30
lines changed

tools/clang/unittests/HLSL/CompilerTest.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,15 +1524,15 @@ static void VerifyPdbUtil(
15241524
D3D12_SHADER_DESC desc = {};
15251525
VERIFY_SUCCEEDED(pRefl->GetDesc(&desc));
15261526

1527-
VERIFY_ARE_EQUAL(desc.ConstantBuffers, 1);
1527+
VERIFY_ARE_EQUAL(desc.ConstantBuffers, 1u);
15281528
ID3D12ShaderReflectionConstantBuffer *pCB =
15291529
pRefl->GetConstantBufferByIndex(0);
15301530

15311531
D3D12_SHADER_BUFFER_DESC cbDesc = {};
15321532
VERIFY_SUCCEEDED(pCB->GetDesc(&cbDesc));
15331533

15341534
VERIFY_IS_TRUE(0 == strcmp(cbDesc.Name, "MyCbuffer"));
1535-
VERIFY_ARE_EQUAL(cbDesc.Variables, 1);
1535+
VERIFY_ARE_EQUAL(cbDesc.Variables, 1u);
15361536

15371537
ID3D12ShaderReflectionVariable *pVar = pCB->GetVariableByIndex(0);
15381538
D3D12_SHADER_VARIABLE_DESC varDesc = {};
@@ -1655,7 +1655,7 @@ TEST_F(CompilerTest, CompileThenTestPdbUtilsStripped) {
16551655
VERIFY_IS_FALSE(pPdbUtils->IsFullPDB());
16561656
UINT32 uSourceCount = 0;
16571657
VERIFY_SUCCEEDED(pPdbUtils->GetSourceCount(&uSourceCount));
1658-
VERIFY_ARE_EQUAL(uSourceCount, 0);
1658+
VERIFY_ARE_EQUAL(uSourceCount, 0u);
16591659
}
16601660
}
16611661

@@ -1806,21 +1806,21 @@ void CompilerTest::TestPdbUtils(bool bSlim, bool bSourceInDebugModule,
18061806
VERIFY_SUCCEEDED(pPdbUtils_Again.QueryInterface(&pPdbUtils2_Again));
18071807
VERIFY_ARE_EQUAL(pPdbUtils2_Again, pPdbUtils2);
18081808

1809-
VERIFY_ARE_EQUAL(pPdbUtils2.p->AddRef(), 5);
1810-
VERIFY_ARE_EQUAL(pPdbUtils2.p->Release(), 4);
1809+
VERIFY_ARE_EQUAL(pPdbUtils2.p->AddRef(), 5u);
1810+
VERIFY_ARE_EQUAL(pPdbUtils2.p->Release(), 4u);
18111811
}
18121812
VERIFY_ARE_EQUAL(pPdbUtils_Again, pPdbUtils);
18131813

1814-
VERIFY_ARE_EQUAL(pPdbUtils2.p->AddRef(), 4);
1815-
VERIFY_ARE_EQUAL(pPdbUtils2.p->Release(), 3);
1814+
VERIFY_ARE_EQUAL(pPdbUtils2.p->AddRef(), 4u);
1815+
VERIFY_ARE_EQUAL(pPdbUtils2.p->Release(), 3u);
18161816
}
18171817

1818-
VERIFY_ARE_EQUAL(pPdbUtils2.p->AddRef(), 3);
1819-
VERIFY_ARE_EQUAL(pPdbUtils2.p->Release(), 2);
1818+
VERIFY_ARE_EQUAL(pPdbUtils2.p->AddRef(), 3u);
1819+
VERIFY_ARE_EQUAL(pPdbUtils2.p->Release(), 2u);
18201820
}
18211821

1822-
VERIFY_ARE_EQUAL(pPdbUtils.p->AddRef(), 2);
1823-
VERIFY_ARE_EQUAL(pPdbUtils.p->Release(), 1);
1822+
VERIFY_ARE_EQUAL(pPdbUtils.p->AddRef(), 2u);
1823+
VERIFY_ARE_EQUAL(pPdbUtils.p->Release(), 1u);
18241824
}
18251825

18261826
TEST_F(CompilerTest, CompileThenTestPdbUtils) {

tools/clang/unittests/HLSL/DxilContainerTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ class DxilContainerTest : public ::testing::Test {
327327
D3D12_SHADER_VARIABLE_DESC testConst;
328328
pTestConst = pTestCB->GetVariableByIndex(vi);
329329
VERIFY_SUCCEEDED(pTestConst->GetDesc(&testConst));
330-
VERIFY_ARE_EQUAL(variableMap.count(testConst.Name), 1);
330+
VERIFY_ARE_EQUAL(variableMap.count(testConst.Name), 1u);
331331
D3D12_SHADER_VARIABLE_DESC baseConst = variableMap[testConst.Name];
332332
VERIFY_ARE_EQUAL(testConst.uFlags, baseConst.uFlags);
333333
VERIFY_ARE_EQUAL(testConst.StartOffset, baseConst.StartOffset);
@@ -336,7 +336,7 @@ class DxilContainerTest : public ::testing::Test {
336336

337337
ID3D12ShaderReflectionType *pTestType = pTestConst->GetType();
338338
VERIFY_IS_NOT_NULL(pTestType);
339-
VERIFY_ARE_EQUAL(variableTypeMap.count(testConst.Name), 1);
339+
VERIFY_ARE_EQUAL(variableTypeMap.count(testConst.Name), 1u);
340340
ID3D12ShaderReflectionType *pBaseType =
341341
variableTypeMap[testConst.Name];
342342

tools/clang/unittests/HLSL/RewriterTest.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,6 @@ TEST_F(RewriterTest, RunPredefines) {
465465
L"rewriter\\correct_rewrites\\predefines_gold.hlsl");
466466
}
467467

468-
static const UINT32 CP_UTF16 = 1200;
469-
470468
TEST_F(RewriterTest, RunWideOneByte) {
471469
CComPtr<IDxcRewriter> pRewriter;
472470
VERIFY_SUCCEEDED(CreateRewriter(&pRewriter));

tools/clang/unittests/HLSLErrors/HLSLErrors.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "dxc/dxcapi.h" // Be sure to link with dxcompiler.lib.
55
#include <d3d12shader.h> // Shader reflection.
66
// clang-format on
7+
#include <array> // for std::size.
78

89
// Code from
910
// https://github.com/microsoft/DirectXShaderCompiler/wiki/Using-dxc.exe-and-dxcompiler.dll
@@ -184,7 +185,7 @@ int main() {
184185
pHash != nullptr) {
185186
wprintf(L"Hash: ");
186187
DxcShaderHash *pHashBuf = (DxcShaderHash *)pHash->GetBufferPointer();
187-
for (int i = 0; i < _countof(pHashBuf->HashDigest); i++)
188+
for (unsigned i = 0; i < std::size(pHashBuf->HashDigest); i++)
188189
wprintf(L"%x", pHashBuf->HashDigest[i]);
189190
wprintf(L"\n");
190191
}

tools/clang/unittests/HLSLHost/HLSLHost.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ class CoInit {
121121
};
122122

123123
// Globals.
124-
static DWORD g_ProcessLocks;
125124
static const GUID
126125
CLSID_HLSLHostServer = // {7FD7A859-6C6B-4352-8F1E-C67BB62E774B}
127126
{0x7fd7a859,
@@ -139,12 +138,7 @@ static const DWORD ReadLogMsgId = 6;
139138
static const DWORD SetSizeMsgId = 7;
140139
static const DWORD SetParentWndMsgId = 8;
141140
static const DWORD GetPidMsgReplyId = 100 + GetPidMsgId;
142-
static const DWORD StartRendererMsgReplyId = 100 + StartRendererMsgId;
143-
static const DWORD StopRendererMsgReplyId = 100 + StopRendererMsgId;
144-
static const DWORD SetPayloadMsgReplyId = 100 + SetPayloadMsgId;
145141
static const DWORD ReadLogMsgReplyId = 100 + ReadLogMsgId;
146-
static const DWORD SetSizeMsgReplyId = 100 + SetSizeMsgId;
147-
static const DWORD SetParentWndMsgReplyId = 100 + SetParentWndMsgId;
148142

149143
struct HhMessageHeader {
150144
DWORD Length;
@@ -502,7 +496,7 @@ class Renderer {
502496
g_ShutdownServerEvent.SetEvent();
503497
}
504498
}
505-
void SetPayload(LPSTR pText) {
499+
void SetPayload(LPCSTR pText) {
506500
LPSTR textCopy = strdup(pText);
507501
LPSTR oldText =
508502
(LPSTR)InterlockedExchangePointer(&m_ShaderOpText, textCopy);
@@ -643,7 +637,8 @@ class ServerObj : public IStream {
643637
DXC_MICROCOM_ADDREF_RELEASE_IMPL(m_dwRef)
644638
ServerObj() : m_dwRef(0) {}
645639
~ServerObj() {}
646-
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppvObject) {
640+
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid,
641+
void **ppvObject) override {
647642
return DoBasicQueryInterfaceWithRemote<IStream>(this, iid, ppvObject);
648643
}
649644

@@ -705,9 +700,9 @@ class ServerObj : public IStream {
705700
WriteRequestResultReply(MsgKind, S_OK);
706701
break;
707702
case SetPayloadMsgId:
708-
LPSTR pText;
703+
LPCSTR pText;
709704
HhTrace(L"SetPayload message received");
710-
pText = (LPSTR)(pHeader + 1);
705+
pText = (LPCSTR)(pHeader + 1);
711706
m_renderer.SetPayload(pText);
712707
WriteRequestResultReply(MsgKind, S_OK);
713708
break;
@@ -856,19 +851,20 @@ class ServerFactory : public IClassFactory {
856851
public:
857852
DXC_MICROCOM_ADDREF_RELEASE_IMPL(m_dwRef)
858853
ServerFactory() : m_dwRef(0) {}
859-
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppvObject) {
854+
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid,
855+
void **ppvObject) override {
860856
return DoBasicQueryInterfaceWithRemote<IClassFactory>(this, iid, ppvObject);
861857
}
862858
HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown *pUnk, REFIID riid,
863-
void **ppvObj) {
859+
void **ppvObj) override {
864860
if (pUnk)
865861
return CLASS_E_NOAGGREGATION;
866862
CComPtr<ServerObj> obj = new (std::nothrow) ServerObj();
867863
if (obj.p == nullptr)
868864
return E_OUTOFMEMORY;
869865
return obj.p->QueryInterface(riid, ppvObj);
870866
}
871-
HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock) {
867+
HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock) override {
872868
// TODO: implement
873869
return S_OK;
874870
}

tools/clang/unittests/dxc_batch/dxc_batch.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,8 @@ class DxcIncludeHandlerForInjectedSources : public IDxcIncludeHandler {
537537
DxcIncludeHandlerForInjectedSources() : m_dwRef(0){};
538538
std::unordered_map<std::wstring, CComPtr<IDxcBlob>> includeFiles;
539539

540-
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppvObject) {
540+
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid,
541+
void **ppvObject) override {
541542
return DoBasicQueryInterface<IDxcIncludeHandler>(this, iid, ppvObject);
542543
}
543544

0 commit comments

Comments
 (0)