[clang][OpenCL] Use of CLK_NULL_QUEUE trips assert during CodeGen
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
The following kernel compiled with `-finclude-default-header -fdeclare-opencl-builtins -triple spir64-unknown-unknown -cl-std=CL2.0` triggers an assert:
```opencl
kernel void foo(global int *x)
{
queue_t q = get_default_queue();
if (q != CLK_NULL_QUEUE) {
*x = 1;
}
}
```
```
...
#11 0x0000000004a328b8 (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) CGExprScalar.cpp:0:0
#12 0x0000000004a2a896 clang::StmtVisitorBase::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#13 0x0000000004a3a64d clang::CodeGen::CodeGenFunction::EmitPromotedScalarExpr(clang::Expr const*, clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4a3a64d)
#14 0x0000000004a3b2cc (anonymous namespace)::ScalarExprEmitter::EmitBinOps(clang::BinaryOperator const*, clang::QualType) CGExprScalar.cpp:0:0
#15 0x0000000004a3b960 (anonymous namespace)::ScalarExprEmitter::EmitCompare(clang::BinaryOperator const*, llvm::CmpInst::Predicate, llvm::CmpInst::Predicate, llvm::CmpInst::Predicate, bool) CGExprScalar.cpp:0:0
#16 0x0000000004a2bb16 clang::StmtVisitorBase::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#17 0x0000000004a3029c clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4a3029c)
#18 0x000000000498dabd clang::CodeGen::CodeGenFunction::EvaluateExprAsBool(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x498dabd)
#19 0x0000000004bcdacc clang::CodeGen::CodeGenFunction::EmitBranchOnBoolExpr(clang::Expr const*, llvm::BasicBlock*, llvm::BasicBlock*, unsigned long, clang::Stmt::Likelihood, clang::Expr const*, clang::VarDecl const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4bcdacc)
#20 0x0000000004b5dac4 clang::CodeGen::CodeGenFunction::EmitIfStmt(clang::IfStmt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4b5dac4)
...
Assertion `isa(Val) && "cast() argument of incompatible type!"' failed.
```
This might be a design flaw: the use of a target extension type for OpenCL's `queue_t` type might make it impossible for Clang codegen to emit IR that does any operations on such a type, due to restrictions of target extension types. This may affect other OpenCL types too.
Contributor guide
Assessment
This issue has not been assessed yet.