Skip to content

Commit

Permalink
[ClangCL] Cleanup rest clang-cl warnings (microsoft#5847)
Browse files Browse the repository at this point in the history
1. printf format mismatch.
2. avoid cast from CComPtr<IncludeHandlerVFSOverlayForTest> to
CComPtr<IDxcIncludeHandler>.
3. fix signed unsigned mismatch.
4. fix order of fields in constructor.
5. add override for override methods.
6. port
llvm/llvm-project@01f4209
7. add copy assignment operator to avoid
-Wdeprecated-copy-with-user-provided-copy
8. disable -Wignored-qualifiers for taef header WexTestClass.h.
9. remove unused fields.
10. add -clang-cl for hctbuild.
  • Loading branch information
python3kgae authored Oct 16, 2023
1 parent 1306b0c commit 956fa34
Show file tree
Hide file tree
Showing 18 changed files with 110 additions and 103 deletions.
6 changes: 4 additions & 2 deletions include/dxc/Support/microcom.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ template <typename T> void DxcCallDestructor(T *obj) { obj->T::~T(); }
#define DXC_MICROCOM_REF_FIELD(m_dwRef) \
volatile std::atomic<llvm::sys::cas_flag> m_dwRef = {0};
#define DXC_MICROCOM_ADDREF_IMPL(m_dwRef) \
ULONG STDMETHODCALLTYPE AddRef() override { return (ULONG)++m_dwRef; }
ULONG STDMETHODCALLTYPE AddRef() noexcept override { \
return (ULONG)++m_dwRef; \
}
#define DXC_MICROCOM_ADDREF_RELEASE_IMPL(m_dwRef) \
DXC_MICROCOM_ADDREF_IMPL(m_dwRef) \
ULONG STDMETHODCALLTYPE Release() override { \
Expand Down Expand Up @@ -107,7 +109,7 @@ inline T *CreateOnMalloc(IMalloc *pMalloc, Args &&...args) {

#define DXC_MICROCOM_TM_ADDREF_RELEASE_IMPL() \
DXC_MICROCOM_ADDREF_IMPL(m_dwRef) \
ULONG STDMETHODCALLTYPE Release() override { \
ULONG STDMETHODCALLTYPE Release() noexcept override { \
ULONG result = (ULONG)--m_dwRef; \
if (result == 0) { \
CComPtr<IMalloc> pTmp(m_pMalloc); \
Expand Down
11 changes: 11 additions & 0 deletions include/dxc/Test/HlslTestUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,18 @@
#include <string>
#include <vector>
#ifdef _WIN32

// Disable -Wignored-qualifiers for WexTestClass.h.
// For const size_t GetSize() const; in TestData.h.
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wignored-qualifiers"
#endif
#include "WexTestClass.h"
#ifdef __clang__
#pragma clang diagnostic pop
#endif

#include <dxgiformat.h>
#else
#include "WEXAdapter.h"
Expand Down
5 changes: 5 additions & 0 deletions projects/dxilconv/include/ShaderBinary/ShaderBinary.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ class COperandBase {
public:
COperandBase() { Clear(); }
COperandBase(const COperandBase &Op) { memcpy(this, &Op, sizeof(*this)); }
COperandBase &operator=(const COperandBase &Op) {
if (this != &Op)
memcpy(this, &Op, sizeof(*this));
return *this;
}
D3D10_SB_OPERAND_TYPE OperandType() const { return m_Type; }
const COperandIndex *OperandIndex(UINT Index) const {
return &m_Index[Index];
Expand Down
9 changes: 4 additions & 5 deletions tools/clang/lib/CodeGen/CGBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,19 @@ class CodeGenFunction;
/// instructions.
template <bool PreserveNames>
class CGBuilderInserter
: protected llvm::IRBuilderDefaultInserter<PreserveNames> {
: protected llvm::IRBuilderDefaultInserter<PreserveNames> {
public:
CGBuilderInserter() : CGF(nullptr) {}
CGBuilderInserter() = default;
explicit CGBuilderInserter(CodeGenFunction *CGF) : CGF(CGF) {}

protected:
/// \brief This forwards to CodeGenFunction::InsertHelper.
void InsertHelper(llvm::Instruction *I, const llvm::Twine &Name,
llvm::BasicBlock *BB,
llvm::BasicBlock::iterator InsertPt) const;
private:
void operator=(const CGBuilderInserter &) = delete;

CodeGenFunction *CGF;
private:
CodeGenFunction *CGF = nullptr;
};

// Don't preserve names on values in an optimized build.
Expand Down
4 changes: 1 addition & 3 deletions tools/clang/unittests/HLSL/AllocatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
///////////////////////////////////////////////////////////////////////////////

#include "dxc/Support/WinIncludes.h"
#ifdef _WIN32
#include "WexTestClass.h"
#endif
#include "dxc/Test/HlslTestUtils.h"

#include "dxc/HLSL/DxilSpanAllocator.h"
Expand Down Expand Up @@ -104,6 +101,7 @@ bool Align(unsigned &pos, unsigned end, unsigned align) {
struct Element {
Element() = default;
Element(const Element &) = default;
Element &operator=(const Element &) = default;
Element(unsigned id, unsigned start, unsigned end)
: id(id), start(start), end(end) {}
bool operator<(const Element &other) { return id < other.id; }
Expand Down
3 changes: 0 additions & 3 deletions tools/clang/unittests/HLSL/DXIsenseTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
#include "dxc/Test/HLSLTestData.h"
#include <stdint.h>

#ifdef _WIN32
#include "WexTestClass.h"
#endif
#include "dxc/Support/microcom.h"
#include "dxc/Test/HlslTestUtils.h"

Expand Down
3 changes: 0 additions & 3 deletions tools/clang/unittests/HLSL/LinkerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

#include <fstream>

#ifdef _WIN32
#include "WexTestClass.h"
#endif
#include "dxc/DxilContainer/DxilContainer.h"
#include "dxc/Support/Global.h" // for IFT macro
#include "dxc/Test/DxcTestUtils.h"
Expand Down
120 changes: 60 additions & 60 deletions tools/clang/unittests/HLSL/MSFileSysTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// Includes on Windows are highly order dependent.
#include <stdint.h>
#include "dxc/Support/WinIncludes.h"
#include "WexTestClass.h"
#include "dxc/Test/HlslTestUtils.h"

#include "llvm/Support/MSFileSystem.h"
Expand All @@ -38,14 +37,15 @@ private: \
volatile std::atomic<llvm::sys::cas_flag> m_dwRef; \
\
public: \
ULONG STDMETHODCALLTYPE AddRef() { return (ULONG)++m_dwRef; } \
ULONG STDMETHODCALLTYPE Release() { \
ULONG STDMETHODCALLTYPE AddRef() override { return (ULONG)++m_dwRef; } \
ULONG STDMETHODCALLTYPE Release() override { \
ULONG result = (ULONG)--m_dwRef; \
if (result == 0) \
delete this; \
return result; \
} \
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppvObject) { \
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void **ppvObject) \
override { \
if (ppvObject == nullptr) \
return E_POINTER; \
if (IsEqualIID(iid, __uuidof(IUnknown)) || \
Expand Down Expand Up @@ -100,12 +100,12 @@ class FixedEnumSTATSTG : public IEnumSTATSTG {
m_items[i].pwcsName = CoTaskMemDup(m_items[i].pwcsName);
}
}
~FixedEnumSTATSTG() {
virtual ~FixedEnumSTATSTG() {
for (auto &item : m_items)
CoTaskMemFree(item.pwcsName);
}
virtual HRESULT STDMETHODCALLTYPE Next(ULONG celt, STATSTG *rgelt,
ULONG *pceltFetched) {
HRESULT STDMETHODCALLTYPE Next(ULONG celt, STATSTG *rgelt,
ULONG *pceltFetched) override {
if (celt != 1 || pceltFetched == nullptr)
return E_NOTIMPL;
if (m_index >= m_items.size()) {
Expand All @@ -119,22 +119,20 @@ class FixedEnumSTATSTG : public IEnumSTATSTG {
++m_index;
return S_OK;
}
virtual HRESULT STDMETHODCALLTYPE Skip(ULONG celt) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE Reset(void) { return E_NOTIMPL; }
virtual HRESULT STDMETHODCALLTYPE Clone(IEnumSTATSTG **) { return E_NOTIMPL; }
HRESULT STDMETHODCALLTYPE Skip(ULONG celt) override { return E_NOTIMPL; }
HRESULT STDMETHODCALLTYPE Reset(void) override { return E_NOTIMPL; }
HRESULT STDMETHODCALLTYPE Clone(IEnumSTATSTG **) override {
return E_NOTIMPL;
}
};

class MockDxcSystemAccess : public IDxcSystemAccess {
SIMPLE_IUNKNOWN_IMPL1(IDxcSystemAccess)
private:
LPCSTR m_fileName;
LPCSTR m_contents;
unsigned m_length;

public:
unsigned findCount;
MockDxcSystemAccess() : m_dwRef(0), findCount(1) {}

virtual ~MockDxcSystemAccess() {}
static HRESULT Create(MockDxcSystemAccess **pResult) {
*pResult = new (std::nothrow) MockDxcSystemAccess();
if (*pResult == nullptr)
Expand All @@ -143,8 +141,8 @@ class MockDxcSystemAccess : public IDxcSystemAccess {
return S_OK;
}

virtual HRESULT STDMETHODCALLTYPE EnumFiles(LPCWSTR fileName,
IEnumSTATSTG **pResult) override {
HRESULT STDMETHODCALLTYPE EnumFiles(LPCWSTR fileName,
IEnumSTATSTG **pResult) override {
wchar_t hlslName[] = L"filename.hlsl";
wchar_t fxName[] = L"filename2.fx";
STATSTG items[] = {{hlslName,
Expand Down Expand Up @@ -180,94 +178,96 @@ class MockDxcSystemAccess : public IDxcSystemAccess {
*pResult = resultEnum;
return S_OK;
}
virtual HRESULT STDMETHODCALLTYPE OpenStorage(LPCWSTR lpFileName,
DWORD dwDesiredAccess,
DWORD dwShareMode,
DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes,
IUnknown **pResult) override {
HRESULT STDMETHODCALLTYPE OpenStorage(LPCWSTR lpFileName,
DWORD dwDesiredAccess,
DWORD dwShareMode,
DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes,
IUnknown **pResult) override {
*pResult = SHCreateMemStream(nullptr, 0);
return (*pResult == nullptr) ? E_OUTOFMEMORY : S_OK;
}
virtual HRESULT STDMETHODCALLTYPE
HRESULT STDMETHODCALLTYPE
SetStorageTime(IUnknown *storage, const FILETIME *lpCreationTime,
const FILETIME *lpLastAccessTime,
const FILETIME *lpLastWriteTime) override {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE GetFileInformationForStorage(
HRESULT STDMETHODCALLTYPE GetFileInformationForStorage(
IUnknown *storage,
LPBY_HANDLE_FILE_INFORMATION lpFileInformation) override {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE
GetFileTypeForStorage(IUnknown *storage, DWORD *fileType) override {
HRESULT STDMETHODCALLTYPE GetFileTypeForStorage(IUnknown *storage,
DWORD *fileType) override {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE CreateHardLinkInStorage(
HRESULT STDMETHODCALLTYPE CreateHardLinkInStorage(
LPCWSTR lpFileName, LPCWSTR lpExistingFileName) override {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE MoveStorage(LPCWSTR lpExistingFileName,
LPCWSTR lpNewFileName,
DWORD dwFlags) override {
HRESULT STDMETHODCALLTYPE MoveStorage(LPCWSTR lpExistingFileName,
LPCWSTR lpNewFileName,
DWORD dwFlags) override {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE
HRESULT STDMETHODCALLTYPE
GetFileAttributesForStorage(LPCWSTR lpFileName, DWORD *pResult) override {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE DeleteStorage(LPCWSTR lpFileName) override {
HRESULT STDMETHODCALLTYPE DeleteStorage(LPCWSTR lpFileName) override {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE
HRESULT STDMETHODCALLTYPE
RemoveDirectoryStorage(LPCWSTR lpFileName) override {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE
HRESULT STDMETHODCALLTYPE
CreateDirectoryStorage(LPCWSTR lpPathName) override {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE GetCurrentDirectoryForStorage(
DWORD nBufferLength, LPWSTR lpBuffer, DWORD *len) override {
HRESULT STDMETHODCALLTYPE GetCurrentDirectoryForStorage(DWORD nBufferLength,
LPWSTR lpBuffer,
DWORD *len) override {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE GetMainModuleFileNameW(
DWORD nBufferLength, LPWSTR lpBuffer, DWORD *len) override {
HRESULT STDMETHODCALLTYPE GetMainModuleFileNameW(DWORD nBufferLength,
LPWSTR lpBuffer,
DWORD *len) override {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE GetTempStoragePath(DWORD nBufferLength,
LPWSTR lpBuffer,
DWORD *len) override {
HRESULT STDMETHODCALLTYPE GetTempStoragePath(DWORD nBufferLength,
LPWSTR lpBuffer,
DWORD *len) override {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE
SupportsCreateSymbolicLink(BOOL *pResult) override {
HRESULT STDMETHODCALLTYPE SupportsCreateSymbolicLink(BOOL *pResult) override {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE CreateSymbolicLinkInStorage(
HRESULT STDMETHODCALLTYPE CreateSymbolicLinkInStorage(
LPCWSTR lpSymlinkFileName, LPCWSTR lpTargetFileName,
DWORD dwFlags) override {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE CreateStorageMapping(
IUnknown *hFile, DWORD flProtect, DWORD dwMaximumSizeHigh,
DWORD dwMaximumSizeLow, IUnknown **pResult) override {
HRESULT STDMETHODCALLTYPE CreateStorageMapping(IUnknown *hFile,
DWORD flProtect,
DWORD dwMaximumSizeHigh,
DWORD dwMaximumSizeLow,
IUnknown **pResult) override {
return E_NOTIMPL;
}
virtual HRESULT MapViewOfFile(IUnknown *hFileMappingObject,
DWORD dwDesiredAccess, DWORD dwFileOffsetHigh,
DWORD dwFileOffsetLow,
SIZE_T dwNumberOfBytesToMap,
ID3D10Blob **pResult) override {
HRESULT MapViewOfFile(IUnknown *hFileMappingObject, DWORD dwDesiredAccess,
DWORD dwFileOffsetHigh, DWORD dwFileOffsetLow,
SIZE_T dwNumberOfBytesToMap,
ID3D10Blob **pResult) override {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE
OpenStdStorage(int standardFD, IUnknown **pResult) override {
HRESULT STDMETHODCALLTYPE OpenStdStorage(int standardFD,
IUnknown **pResult) override {
return E_NOTIMPL;
}
virtual HRESULT STDMETHODCALLTYPE
GetStreamDisplay(ITextFont **textFont, unsigned *columnCount) override {
HRESULT STDMETHODCALLTYPE GetStreamDisplay(ITextFont **textFont,
unsigned *columnCount) override {
return E_NOTIMPL;
}
};
Expand Down Expand Up @@ -306,7 +306,7 @@ void MSFileSysTest::FindFirstWhenInvokedThenFailsIfNoMatch() {
CreateMSFileSystemForIface(access, &fileSystem);
WIN32_FIND_DATAW findData;
HANDLE h = fileSystem->FindFirstFileW(L"foobar", &findData);
VERIFY_ARE_EQUAL(ERROR_FILE_NOT_FOUND, GetLastError());
VERIFY_ARE_EQUAL(ERROR_FILE_NOT_FOUND, (long)GetLastError());
VERIFY_ARE_EQUAL(INVALID_HANDLE_VALUE, h);
VERIFY_ARE_EQUAL_WSTR(L"", findData.cFileName);
delete fileSystem;
Expand All @@ -323,7 +323,7 @@ void MSFileSysTest::FindNextWhenLastThenNoMatch() {
VERIFY_ARE_NOT_EQUAL(INVALID_HANDLE_VALUE, h);
BOOL findNext = fileSystem->FindNextFileW(h, &findData);
VERIFY_IS_FALSE(findNext);
VERIFY_ARE_EQUAL(ERROR_FILE_NOT_FOUND, GetLastError());
VERIFY_ARE_EQUAL(ERROR_FILE_NOT_FOUND, (long)GetLastError());
fileSystem->FindClose(h);
delete fileSystem;
}
Expand Down Expand Up @@ -357,7 +357,7 @@ void MSFileSysTest::OpenWhenNewThenZeroSize() {
char buf[4];
DWORD bytesRead;
VERIFY_IS_TRUE(fileSystem->ReadFile(h, buf, _countof(buf), &bytesRead));
VERIFY_ARE_EQUAL(0, bytesRead);
VERIFY_ARE_EQUAL(0u, bytesRead);
fileSystem->CloseHandle(h);
delete fileSystem;
}
3 changes: 0 additions & 3 deletions tools/clang/unittests/HLSL/Objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
#include "dxc/Test/HLSLTestData.h"
#include <stdint.h>

#ifdef _WIN32
#include "WexTestClass.h"
#endif
#include "dxc/Test/HlslTestUtils.h"

#include <exception>
Expand Down
3 changes: 0 additions & 3 deletions tools/clang/unittests/HLSL/OptionsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
#include <vector>

#include "dxc/Test/HLSLTestData.h"
#ifdef _WIN32
#include "WexTestClass.h"
#endif
#include "dxc/Test/HlslTestUtils.h"

#include "dxc/DxilContainer/DxilContainer.h"
Expand Down
Loading

0 comments on commit 956fa34

Please sign in to comment.