Skip to content

Commit 31ed43e

Browse files
NuullllAlexeySachkov
authored andcommitted
Fix getSPIRVBuiltin assertion failure
It's possible that the underscore-delimited postfix is not empty when we do this check in `SPIRVToOCLBase::visitCallInst`. Should return false instead of returning an assertion failure. Signed-off-by: Yilong Guo <yilong.guo@intel.com>
1 parent 85a9394 commit 31ed43e

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/SPIRV/SPIRVUtil.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,8 @@ bool getSPIRVBuiltin(const std::string &OrigName, spv::BuiltIn &B) {
478478
SmallVector<StringRef, 2> Postfix;
479479
StringRef R(OrigName);
480480
R = dePrefixSPIRVName(R, Postfix);
481-
assert(Postfix.empty() && "Invalid SPIR-V builtin Name");
481+
if (!Postfix.empty())
482+
return false;
482483
return getByName(R.str(), B);
483484
}
484485

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: llvm-as %s -o - | llvm-spirv -o %t.spv
2+
; RUN: llvm-spirv -r %t.spv -o - | llvm-dis -o - | FileCheck %s
3+
4+
target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
5+
target triple = "spir-unknown-unknown"
6+
7+
; Function Attrs: nounwind readnone
8+
define spir_kernel void @f() #0 !kernel_arg_addr_space !0 !kernel_arg_access_qual !0 !kernel_arg_type !0 !kernel_arg_base_type !0 !kernel_arg_type_qual !0 {
9+
entry:
10+
%0 = call spir_func i32 @_Z32__spirv_somefunc_with_underscorev()
11+
; CHECK: call spir_func i32 @_Z32__spirv_somefunc_with_underscorev()
12+
%1 = call spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()
13+
; CHECK: call spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()
14+
ret void
15+
}
16+
17+
declare spir_func i32 @_Z32__spirv_somefunc_with_underscorev()
18+
declare spir_func i64 @_Z28__spirv_GlobalInvocationId_xv()
19+
20+
attributes #0 = { nounwind readnone }
21+
22+
!0 = !{}

0 commit comments

Comments
 (0)