Skip to content

Commit a81d3f8

Browse files
PawelJurekpszymich
authored andcommitted
StackOverflowDetection: fix for cases where stack pointer is 32 bit
When private pointer size is 32 bit, stack pointer is also set to be 32 bit in InitializeStackVariables. GetStackPointer intrinsic assumed 64 bit size. (cherry picked from commit 08a6ee8)
1 parent ba4178f commit a81d3f8

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

IGC/BiFModule/Implementation/assert.cl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void __devicelib_assert_fail(char *expr, char *file, int line, char *func, long
4646
__builtin_IB_software_exception();
4747
}
4848

49-
long __builtin_IB_get_stack_pointer();
49+
ulong __builtin_IB_get_stack_pointer();
5050
int __builtin_IB_get_stack_size_per_thread();
5151

5252
// This function needs to be inserted in entry points.
@@ -62,7 +62,7 @@ void __stackoverflow_init() {
6262
buf += 3;
6363
*buf = __builtin_IB_get_stack_size_per_thread();
6464
buf = buf + 1;
65-
global long* stackBase = ((global long*)(buf));
65+
global ulong* stackBase = ((global ulong*)(buf));
6666
stackBase[HWTID] = __builtin_IB_get_stack_pointer();
6767
}
6868

@@ -74,7 +74,7 @@ void __stackoverflow_detection() {
7474
buf += 3;
7575
int stackSizePerThread = *buf;
7676
buf += 1;
77-
long stackBase = ((global long*)(buf))[HWTID];
77+
ulong stackBase = ((global ulong*)(buf))[HWTID];
7878

7979
if (__builtin_IB_get_stack_pointer() - stackBase > stackSizePerThread) {
8080
global volatile AssertBufferHeader* header = (global volatile AssertBufferHeader*) __builtin_IB_get_assert_buffer();

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8355,7 +8355,11 @@ void EmitPass::EmitGenIntrinsicMessage(llvm::GenIntrinsicInst* inst)
83558355
break;
83568356
}
83578357
case GenISAIntrinsic::GenISA_getStackPointer: {
8358-
m_encoder->Copy(m_destination, m_currShader->GetSP());
8358+
IGC_ASSERT(m_destination->GetType() == ISA_TYPE_Q);
8359+
IGC_ASSERT(m_currShader->GetSP() &&
8360+
(m_currShader->GetSP()->GetType() == ISA_TYPE_UQ ||
8361+
m_currShader->GetSP()->GetType() == ISA_TYPE_UD));
8362+
m_encoder->Cast(m_destination, m_currShader->GetSP());
83598363
m_encoder->Push();
83608364
break;
83618365
}

0 commit comments

Comments
 (0)