Skip to content

Commit 568ad77

Browse files
authored
[Sanitizer] Fix sanitizer fails in msvc (microsoft#5851)
1. Add -sanitizer to hctbuild. 2. Detach pCompileSource in recompile to avoid release freeed memory. 3. Fix Execution test issue about Init size. This is for microsoft#5876
1 parent b1b8acd commit 568ad77

File tree

4 files changed

+32
-21
lines changed

4 files changed

+32
-21
lines changed

cmake/modules/HandleLLVMOptions.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,11 @@ if(LLVM_USE_SANITIZER)
533533
message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}")
534534
endif()
535535
else()
536-
message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.")
536+
if (LLVM_USE_SANITIZER STREQUAL "Address")
537+
append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
538+
else()
539+
message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}")
540+
endif()
537541
endif()
538542
if (LLVM_USE_SANITIZE_COVERAGE)
539543
append("-fsanitize-coverage=edge,indirect-calls,8bit-counters,trace-cmp" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)

tools/clang/tools/dxclib/dxc.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,8 @@ void DxcContext::Recompile(IDxcBlob *pSource, IDxcLibrary *pLibrary,
778778
IFT(pPdbUtils->GetSourceName(i, &pFileName));
779779
IFT(pIncludeHandler->insertIncludeFile(pFileName, pSourceFile, 0));
780780
if (pMainFileName == pFileName) {
781-
pCompileSource.Attach(pSourceFile);
781+
// Transfer pSourceFile to avoid pPdbUtils release it again.
782+
pCompileSource.Attach(pSourceFile.Detach());
782783
}
783784
}
784785

@@ -803,11 +804,6 @@ void DxcContext::Recompile(IDxcBlob *pSource, IDxcLibrary *pLibrary,
803804
pIncludeHandler, &pResult));
804805
}
805806

806-
#ifndef _WIN32
807-
// FIXME: fix crash on linux when not detach pCompileSource.
808-
pCompileSource.Detach();
809-
#endif
810-
811807
*ppCompileResult = pResult.Detach();
812808
}
813809

tools/clang/unittests/HLSLExec/ShaderOpArith.xml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,12 @@
10851085
-1.0f 1.0f 0, 1.0f 1.0f 0.0f, -1.0f -1.0f 0,
10861086
</Resource>
10871087
<Resource Name='CB0' Dimension='BUFFER' Width="256" InitialResourceState='COPY_DEST' Init='FromBytes'>
1088-
-inf, -1.5f, -denorm, -0, 0, denorm, 1.5f, inf, nan
1088+
-inf, -1.5f, -denorm, -0, 0, denorm, 1.5f, inf, nan,
1089+
0,0,0,0,0,0,0,0,0,0,0,
1090+
0,0,0,0,0,0,0,0,0,0,0,
1091+
0,0,0,0,0,0,0,0,0,0,0,
1092+
0,0,0,0,0,0,0,0,0,0,0,
1093+
0,0,0,0,0,0,0,0,0,0,0
10891094
</Resource>
10901095
<Resource Name="U0" Dimension="BUFFER" Width="1280"
10911096
Flags="ALLOW_UNORDERED_ACCESS" InitialResourceState="COPY_DEST"
@@ -1348,7 +1353,7 @@
13481353
<ShaderOp Name="Triangle" PS="PS" VS="VS">
13491354
<RootSignature>RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT)</RootSignature>
13501355

1351-
<Resource Name="VBuffer" Dimension="BUFFER" Width="1024" Flags="ALLOW_UNORDERED_ACCESS" InitialResourceState="COPY_DEST" Init="FromBytes">
1356+
<Resource Name="VBuffer" Dimension="BUFFER" Width="84" Flags="ALLOW_UNORDERED_ACCESS" InitialResourceState="COPY_DEST" Init="FromBytes">
13521357
{ { 0.0f, 0.25f , 0.0f }, { 1.0f, 0.0f, 0.0f, 1.0f } },
13531358
{ { 0.25f, -0.25f , 0.0f }, { 0.0f, 1.0f, 0.0f, 1.0f } },
13541359
{ { -0.25f, -0.25f , 0.0f }, { 0.0f, 0.0f, 1.0f, 1.0f } }
@@ -1397,7 +1402,7 @@
13971402

13981403
<ShaderOp Name="TriangleHalf" PS="PS" VS="VS">
13991404
<RootSignature>RootFlags(ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT)</RootSignature>
1400-
<Resource Name="VBuffer" Dimension="BUFFER" Width="1024" Flags="ALLOW_UNORDERED_ACCESS" InitialResourceState="COPY_DEST" Init="FromBytes">
1405+
<Resource Name="VBuffer" Dimension="BUFFER" Width="48" Flags="ALLOW_UNORDERED_ACCESS" InitialResourceState="COPY_DEST" Init="FromBytes">
14011406
{ { 0.0h, 0.25h , 0.0h, 1.0h }, { 1.0h, 1.0h, 1.0h, 1.0h } },
14021407
{ { 0.25h, -0.25h , 0.0h, 1.0h }, { 1.0h, 1.0h, 1.0h, 1.0h } },
14031408
{ { -0.25h, -0.25h , 0.0h, 1.0h }, { 1.0h, 1.0h, 1.0h, 1.0h } }
@@ -2229,7 +2234,7 @@
22292234
<Resource Name="U1" Dimension="BUFFER" Width="9216"
22302235
Flags="ALLOW_UNORDERED_ACCESS" InitialResourceState="COPY_DEST"
22312236
Init="Zero" ReadBack="true" TransitionTo="UNORDERED_ACCESS" />
2232-
<Resource Name="U2" Dimension="BUFFER" Width="256" Format="R32_TYPELESS"
2237+
<Resource Name="U2" Dimension="BUFFER" Width="64" Format="R32_TYPELESS"
22332238
Flags="ALLOW_UNORDERED_ACCESS" InitialResourceState="COPY_DEST"
22342239
Init="FromBytes" ReadBack="true" TransitionTo="UNORDERED_ACCESS" >
22352240
{ 0I, 0I, 99999999I, 99999999I, 0I, 0I, -1I, -1I, 0I, 0I, 0I, 0I, 42I, 42I, 42I, 42I }
@@ -2245,12 +2250,12 @@
22452250
Flags="ALLOW_UNORDERED_ACCESS" InitialResourceState="COPY_DEST"
22462251
Init="Zero" ReadBack="true" TransitionTo="UNORDERED_ACCESS" />
22472252
<!-- 32-bit typed resources -->
2248-
<Resource Name="U6" Dimension="BUFFER" Width="256" Format="R32_UINT"
2253+
<Resource Name="U6" Dimension="BUFFER" Width="64" Format="R32_UINT"
22492254
Flags="ALLOW_UNORDERED_ACCESS" InitialResourceState="COPY_DEST"
22502255
Init="FromBytes" ReadBack="true" TransitionTo="UNORDERED_ACCESS" >
22512256
{ 0I, 0I, 99999999I, 99999999I, 0I, 0I, -1I, -1I, 0I, 0I, 0I, 0I, 42I, 42I, 42I, 42I }
22522257
</Resource>
2253-
<Resource Name="U7" Dimension="BUFFER" Width="256" Format="R32_SINT"
2258+
<Resource Name="U7" Dimension="BUFFER" Width="64" Format="R32_SINT"
22542259
Flags="ALLOW_UNORDERED_ACCESS" InitialResourceState="COPY_DEST"
22552260
Init="FromBytes" ReadBack="true" TransitionTo="UNORDERED_ACCESS" >
22562261
{ 0I, 0I, 99999999I, 99999999I, 0I, 0I, -1I, -1I, 0I, 0I, 0I, 0I, 42I, 42I, 42I, 42I }
@@ -2272,25 +2277,25 @@
22722277
Flags="ALLOW_UNORDERED_ACCESS" InitialResourceState="COPY_DEST"
22732278
Init="Zero" ReadBack="true" TransitionTo="UNORDERED_ACCESS" />
22742279
<!-- 64-bit typed resources -->
2275-
<Resource Name="U12" Dimension="BUFFER" Width="256" Format="R32G32_UINT"
2280+
<Resource Name="U12" Dimension="BUFFER" Width="64" Format="R32G32_UINT"
22762281
Flags="ALLOW_UNORDERED_ACCESS" InitialResourceState="COPY_DEST"
22772282
Init="FromBytes" ReadBack="true" TransitionTo="UNORDERED_ACCESS" >
22782283
{ 0I, 0I, 99999999I, 99999999I, 0I, 0I, -1I, -1I, 0I, 0I, 0I, 0I, 42I, 42I, 42I, 42I }
22792284
</Resource>
2280-
<Resource Name="U13" Dimension="BUFFER" Width="256" Format="R32G32_SINT"
2285+
<Resource Name="U13" Dimension="BUFFER" Width="64" Format="R32G32_SINT"
22812286
Flags="ALLOW_UNORDERED_ACCESS" InitialResourceState="COPY_DEST"
22822287
Init="FromBytes" ReadBack="true" TransitionTo="UNORDERED_ACCESS" >
22832288
{ 0I, 0I, 99999999I, 99999999I, 0I, 0I, -1I, -1I, 0I, 0I, 0I, 0I, 42I, 42I, 42I, 42I }
22842289
</Resource>
22852290
<Resource Name="U14" Dimension="BUFFER" Width="1024" Format="R32G32_UINT"
22862291
Flags="ALLOW_UNORDERED_ACCESS" InitialResourceState="COPY_DEST"
22872292
Init="Zero" ReadBack="true" TransitionTo="UNORDERED_ACCESS" />
2288-
<Resource Name="U15" Dimension="TEXTURE1D" Width="16" Format="R32G32_UINT"
2293+
<Resource Name="U15" Dimension="TEXTURE1D" Width="8" Format="R32G32_UINT"
22892294
Flags="ALLOW_UNORDERED_ACCESS" InitialResourceState="COPY_DEST"
22902295
Init="FromBytes" ReadBack="true" TransitionTo="UNORDERED_ACCESS" >
22912296
{ 0I, 0I, 99999999I, 99999999I, 0I, 0I, -1I, -1I, 0I, 0I, 0I, 0I, 42I, 42I, 42I, 42I }
22922297
</Resource>
2293-
<Resource Name="U16" Dimension="TEXTURE1D" Width="16" Format="R32G32_SINT"
2298+
<Resource Name="U16" Dimension="TEXTURE1D" Width="8" Format="R32G32_SINT"
22942299
Flags="ALLOW_UNORDERED_ACCESS" InitialResourceState="COPY_DEST"
22952300
Init="FromBytes" ReadBack="true" TransitionTo="UNORDERED_ACCESS" >
22962301
{ 0I, 0I, 99999999I, 99999999I, 0I, 0I, -1I, -1I, 0I, 0I, 0I, 0I, 42I, 42I, 42I, 42I }
@@ -2331,15 +2336,15 @@
23312336
NumElements="128" Format="R32_UINT" />
23322337
<!-- 64-bit typed resources -->
23332338
<Descriptor Name="U12" Kind="UAV" ResName="U12" Dimension="BUFFER"
2334-
NumElements="16" Format="R32G32_UINT" />
2339+
NumElements="8" Format="R32G32_UINT" />
23352340
<Descriptor Name="U13" Kind="UAV" ResName="U13" Dimension="BUFFER"
2336-
NumElements="16" Format="R32G32_UINT" />
2341+
NumElements="8" Format="R32G32_UINT" />
23372342
<Descriptor Name="U14" Kind="UAV" ResName="U14" Dimension="BUFFER"
23382343
NumElements="128" Format="R32G32_UINT" />
23392344
<Descriptor Name="U15" Kind="UAV" ResName="U15" Dimension="TEXTURE1D"
2340-
NumElements="16" Format="R32G32_UINT" />
2345+
NumElements="8" Format="R32G32_UINT" />
23412346
<Descriptor Name="U16" Kind="UAV" ResName="U16" Dimension="TEXTURE1D"
2342-
NumElements="16" Format="R32G32_UINT" />
2347+
NumElements="8" Format="R32G32_UINT" />
23432348
<Descriptor Name="U17" Kind="UAV" ResName="U17" Dimension="TEXTURE1D"
23442349
NumElements="128" Format="R32G32_UINT" />
23452350
</DescriptorHeap>

utils/hct/hctbuild.cmd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ if "%1"=="-default-adapter" (
204204
shift /1
205205
shift /1 & goto :parse_args
206206
)
207+
if "%1"=="-sanitizer" (
208+
set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_USE_SANITIZER:STRING=Address
209+
shift /1 & goto :parse_args
210+
)
211+
212+
207213
rem Begin SPIRV change
208214
if "%1"=="-spirv" (
209215
echo SPIR-V codegen is enabled.

0 commit comments

Comments
 (0)