Fix unroller crash in library targets (#4604)

Fixed when there are multiple functions with loops that can't be unrolled at
the point of doing [unroll], the unroll pass crashes because it didn't clean up
memory between runs.
This commit is contained in:
Adam Yang 2022-08-19 11:37:19 -07:00 коммит произвёл GitHub
Родитель fc8c775ea6
Коммит 1e0de6211c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 42 добавлений и 1 удалений

Просмотреть файл

@ -108,7 +108,6 @@ public:
static char ID;
std::set<Loop *> LoopsThatFailed;
std::unordered_set<Function *> CleanedUpAlloca;
unsigned MaxIterationAttempt = 0;
bool OnlyWarnOnFail = false;
bool StructurizeLoopExits = false;
@ -1212,7 +1211,11 @@ bool DxilLoopUnroll::doFinalization() {
Twine(Msg) + Twine(" Use '-HV 2016' to treat this as warning."));
}
}
// This pass instance can be reused. Clear this so it doesn't blow up on the subsequent runs.
LoopsThatFailed.clear();
}
return false;
}

Просмотреть файл

@ -0,0 +1,38 @@
// RUN: %dxc -Od -E main -T lib_6_x %s | FileCheck %s
// Regression test for when there are multiple functions with loops that can't
// be unrolled at the point of doing [unroll], the unroll pass crashes because
// it didn't clean up memory between runs.
// CHECK: pass_reuse_regression.hlsl:{{[0-9]+}}:{{[0-9]+}}: error: Could not unroll loop
// CHECK: pass_reuse_regression.hlsl:{{[0-9]+}}:{{[0-9]+}}: error: Could not unroll loop
AppendStructuredBuffer<float4> buf0;
uint g_cond;
struct Params {
int foo;
};
float f(Params p) {
[unroll]
for (uint j = 0; j < p.foo; j++) {
buf0.Append(1);
}
return 0;
}
float g(Params p) {
[unroll]
for (uint j = 0; j < p.foo; j++) {
buf0.Append(1);
}
return 0;
}
float main() : SV_Target {
Params p;
p.foo = g_cond;
return f(p) + g(p);
}