KhronosGroup / KhronosGroup/SPIRV-LLVM-Translator

Infinite loop when translating llvm global variable to SPRIV

Open
#1,393 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
LLVM
Stars
625
Forks
279
Avg merge
3d 5h
Merged PRs (30d)
34

Description

Encountered an infinite loop when coverting the following OpenCL kernel to SPIRV binary. The source code is:

`typedef struct {`
` int first;`
` constant int* firstPtr;`
`} ConstantPool;`

`constant ConstantPool constants = { 1, &constants.first };`

`kernel void constant_struct_with_pointer_to_own_field(void)`
`{ ... }`

This struct is a little bit weird, but llvm creates the following globalvariable:

`%struct.ConstantPool = type { i32, i32 addrspace(2)* }`

`@constants = dso_local addrspace(2) constant %struct.ConstantPool { i32 1, i32 addrspace(2)* getelementptr inbounds (%struct.ConstantPool, %struct.ConstantPool addrspace(2)* @constants, i32 0, i32 0) }, align 4
`

The problem is that `transConstant` have the following code:
![image](https://user-images.githubusercontent.com/77853593/152268843-b8915f6d-b128-4069-8cf4-3270864ad816.png)

As a struct, the transCosntant pushes all operands and call tranValue again. In my case, one operand finally reaches the value itself, which causes an infinite loop.

How to avoid this infinit loop? IMO, even we don't implement the global variable containing a llvm::ConstantExpr of itself (which seems hard to represent in spirv?), we should assert a scenario like this?

Contributor guide

Open the contributing guide

Research direction

Start by tracing transConstant and transValue using the self-referential LLVM global shown in the issue, reproducing the OpenCL kernel translation to confirm the recursion. Determine how this case should terminate, then verify that translation no longer loops and that the resulting diagnostic or handling matches the chosen behavior.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.