Skip to content

Commit 755d111

Browse files
authored
Fix several bugs in code (microsoft#4516)
1. Wrong usage of memset 2. Member initializer list in order of declaration 3. Add explicit to MSFileSystemHandle's single parameter constructors
1 parent cb6a654 commit 755d111

File tree

10 files changed

+23
-24
lines changed

10 files changed

+23
-24
lines changed

lib/DxilDia/DxcPixCompilationInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct CompilationInfo : public IDxcPixCompilationInfo {
7676
};
7777

7878
CompilationInfo::CompilationInfo(IMalloc *pMalloc, dxil_dia::Session *pSession)
79-
: m_pSession(pSession), m_pMalloc(pMalloc) {
79+
: m_pMalloc(pMalloc), m_pSession(pSession) {
8080
auto *Module = m_pSession->DxilModuleRef().GetModule();
8181
m_contents =
8282
Module->getNamedMetadata(hlsl::DxilMDHelper::kDxilSourceContentsMDName);

lib/DxilDia/DxilDiaEnumTables.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class EnumTables : public IDiaEnumTables {
4242
}
4343

4444
EnumTables(IMalloc *pMalloc, Session *pSession)
45-
: m_pMalloc(pMalloc), m_pSession(pSession), m_dwRef(0), m_next(0) {
45+
: m_dwRef(0), m_pMalloc(pMalloc), m_pSession(pSession), m_next(0) {
4646
m_tables.fill(nullptr);
4747
}
4848

lib/Support/MSFileSystemBasic.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,18 @@ struct MSFileSystemHandle {
107107
stream; // For a file or console file handle, the stream interface.
108108
int fd; // For a file handle, its file descriptor.
109109

110-
MSFileSystemHandle(int knownFD)
110+
explicit MSFileSystemHandle(int knownFD)
111111
: kind(MSFileSystemHandleKind_FileHandle), fd(knownFD) {}
112112

113-
MSFileSystemHandle(IUnknown *pMapping)
113+
explicit MSFileSystemHandle(IUnknown *pMapping)
114114
: kind(MSFileSystemHandleKind_FileMappingHandle), storage(pMapping),
115115
fd(0) {}
116116

117117
MSFileSystemHandle(IUnknown *pStorage, IStream *pStream)
118118
: kind(MSFileSystemHandleKind_FileHandle), storage(pStorage),
119119
stream(pStream), fd(0) {}
120120

121-
MSFileSystemHandle(IEnumSTATSTG *pEnumSTATG)
121+
explicit MSFileSystemHandle(IEnumSTATSTG *pEnumSTATG)
122122
: kind(MSFileSystemHandleKind_FindHandle), storage(pEnumSTATG) {}
123123

124124
MSFileSystemHandle(MSFileSystemHandle &&other) {

projects/dxilconv/include/DxilConvPasses/ScopeNest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct ScopeNestEvent {
7171
Type ElementType;
7272
BlockTy *Block;
7373

74-
ScopeNestEvent(BlockTy *B, Type T) : Block(B), ElementType(T) {}
74+
ScopeNestEvent(BlockTy *B, Type T) : ElementType(T), Block(B) {}
7575
static ScopeNestEvent Invalid() {
7676
return ScopeNestEvent(nullptr, Type::Invalid);
7777
}

projects/dxilconv/include/DxilConvPasses/ScopeNestIterator.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,8 @@ class ScopeNestIterator {
264264

265265
public:
266266
Scope(Type scopeType, Block *startBlock, BranchKind annotation)
267-
: m_type(scopeType), m_startBlock(startBlock),
268-
m_startAnnotation(annotation), m_endBlock(nullptr),
269-
m_backedge(nullptr)
267+
: m_type(scopeType), m_startAnnotation(annotation),
268+
m_startBlock(startBlock), m_endBlock(nullptr), m_backedge(nullptr)
270269

271270
{
272271
if (m_type == Type::If) {

projects/dxilconv/lib/DxbcConverter/DxbcConverter.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ __override HRESULT STDMETHODCALLTYPE DxbcConverter::ConvertInDriver(
104104

105105
DxbcConverter::DxbcConverter()
106106
: m_dwRef(0), m_pPR(nullptr), m_pOP(nullptr), m_pSM(nullptr),
107-
m_DxbcMajor(0), m_DxbcMinor(0), m_pUnusedF32(nullptr),
108-
m_pUnusedI32(nullptr), m_NumTempRegs(0), m_pIcbGV(nullptr),
109-
m_bDisableHashCheck(false), m_bRunDxilCleanup(true),
110-
m_bLegacyCBufferLoad(true), m_TGSMCount(0),
107+
m_DxbcMajor(0), m_DxbcMinor(0), m_bDisableHashCheck(false),
108+
m_bRunDxilCleanup(true), m_bLegacyCBufferLoad(true),
111109
m_DepthRegType(D3D10_SB_OPERAND_TYPE_NULL), m_bHasStencilRef(false),
112-
m_bHasCoverageOut(false), m_bControlPointPhase(false),
113-
m_bPatchConstantPhase(false), m_pInterfaceDataBuffer(nullptr),
114-
m_pClassInstanceCBuffers(nullptr), m_pClassInstanceSamplers(nullptr),
110+
m_bHasCoverageOut(false), m_pUnusedF32(nullptr), m_pUnusedI32(nullptr),
111+
m_NumTempRegs(0), m_pIcbGV(nullptr), m_TGSMCount(0),
112+
m_bControlPointPhase(false), m_bPatchConstantPhase(false),
113+
m_pInterfaceDataBuffer(nullptr), m_pClassInstanceCBuffers(nullptr),
114+
m_pClassInstanceSamplers(nullptr),
115115
m_pClassInstanceComparisonSamplers(nullptr), m_NumIfaces(0),
116116
m_FcallCount(0) {
117117
DXASSERT(OP::CheckOpCodeTable(), "incorrect entry in OpCode property table");

projects/dxilconv/lib/DxilConvPasses/DxilCleanup.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ class DxilCleanup : public ModulePass {
133133
DXASSERT_NOMSG(false);
134134
}
135135
LiveRange(LiveRange &&other)
136-
: id(other.id), numI(other.numI), numF(other.numF), numU(other.numU),
137-
pNewType(other.pNewType), defs(std::move(other.defs)),
138-
bitcastMap(std::move(other.bitcastMap)) {
136+
: id(other.id), defs(std::move(other.defs)),
137+
bitcastMap(std::move(other.bitcastMap)), numI(other.numI),
138+
numF(other.numF), numU(other.numU), pNewType(other.pNewType) {
139139
DXASSERT_NOMSG(false);
140140
}
141141

tools/clang/unittests/HLSL/MSFileSysTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class MockDxcSystemAccess : public IDxcSystemAccess {
133133

134134
public:
135135
unsigned findCount;
136-
MockDxcSystemAccess() : findCount(1), m_dwRef(0) {}
136+
MockDxcSystemAccess() : m_dwRef(0), findCount(1) {}
137137

138138
static HRESULT Create(MockDxcSystemAccess **pResult) {
139139
*pResult = new (std::nothrow) MockDxcSystemAccess();

tools/clang/unittests/HLSLExec/ExecutionTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3445,9 +3445,9 @@ TEST_F(ExecutionTest, WaveIntrinsicsInPSTest) {
34453445
bool isTop[4];
34463446
bool isLeft[4];
34473447
PerPixelData helperData;
3448-
memset(&helperData, sizeof(helperData), 0);
3448+
memset(&helperData, 0, sizeof(helperData));
34493449
PerPixelData *layout[4]; // tl,tr,bl,br
3450-
memset(layout, sizeof(layout), 0);
3450+
memset(layout, 0, sizeof(layout));
34513451
auto fnToLayout = [&](bool top, bool left) -> PerPixelData ** {
34523452
int idx = top ? 0 : 2;
34533453
idx += left ? 0 : 1;
@@ -10948,7 +10948,7 @@ void ExecutionTest::WaveSizeTest() {
1094810948
VERIFY_IS_TRUE(sizeof(WaveSizeTestData) * MAX_WAVESIZE <=
1094910949
Data.size());
1095010950
WaveSizeTestData *pInData = (WaveSizeTestData *)Data.data();
10951-
memset(&pInData, sizeof(WaveSizeTestData) * MAX_WAVESIZE, 0);
10951+
memset(pInData, 0, sizeof(WaveSizeTestData) * MAX_WAVESIZE);
1095210952
},
1095310953
ShaderOpSet);
1095410954

tools/clang/unittests/HLSLExec/ShaderOpTest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,4 +342,4 @@ void ParseShaderOpSetFromXml(IXmlReader *pReader, ShaderOpSet *pShaderOpSet);
342342

343343
} // namespace st
344344

345-
#endif __SHADEROPTEST_H__
345+
#endif // __SHADEROPTEST_H__

0 commit comments

Comments
 (0)