ispc / ispc

Intel® Implicit SPMD Program Compiler
BSD 3-Clause "New" or "Revised" License
2.53k stars 317 forks source link

Enum field in struct causes crash #2285

Open qcoh opened 2 years ago

qcoh commented 2 years ago

Steps to reproduce

Compile the following code (enum.ispc):

enum material_type {
  DIFFUSE = 0,
};

struct sphere {
  material_type type;
};

export uniform float render(uniform sphere spheres[]) {
  sphere current_sphere = spheres[0]; // this the offensive line. If I add "uniform" to the type of current_sphere, compilation succeeds.
  return 0.0f;
}

with

ispc enum.ispc --target=avx2

Current behaviour

The compilation fails with the error:

/usr/local/src/ispc/src/expr.cpp:6536: Assertion failed: "CastType<PointerType>(type) != NULL".
***
*** Please file a bug report at https://github.com/ispc/ispc/issues
*** (Including as much information as you can about how to reproduce this error).
*** You have apparently encountered a bug in the compiler that we'd like to fix!
***
/usr/local/src/ispc/src/main.cpp(396): FATAL ERROR: Unhandled signal sent to process; terminating.
Aborted (core dumped)

Expected behaviour

Compilation succeeds.

Other comment

In the above example it may seem that I could make spheres uniform but in my actual code, I get different indices depending on the gang's previous computation.

FWIW, I'm working around the issue by using int instead of an enum, i.e.

#define  DIFFUSE 0

struct sphere {
  int type;
};

Environment

Ubuntu 20.04 with ispc 1.17.0:

$ ispc --version
Intel(r) Implicit SPMD Program Compiler (Intel(r) ISPC), 1.17.0 (build commit 7ad8429369a4d5ce @ 20220128, LLVM 12.0.1)
dbabokin commented 2 years ago

Thanks for reporting this bug and thanks for detailed description!