Skip to content

Commit 8039af2

Browse files
svenvhsys-ce-bb
authored andcommitted
Report disallowed extensions in metadata (#2125)
When translating the `spirv.Extension` metadata of an LLVM Module, report an error when encountering an extension that has been explicitly disabled. Original commit: KhronosGroup/SPIRV-LLVM-Translator@2e917c9
1 parent 76b5d11 commit 8039af2

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5461,6 +5461,10 @@ bool LLVMToSPIRVBase::transExtension() {
54615461
std::string S;
54625462
N.nextOp().get(S);
54635463
assert(!S.empty() && "Invalid extension");
5464+
ExtensionID ExtID = SPIRVMap<ExtensionID, std::string>::rmap(S);
5465+
if (!BM->getErrorLog().checkError(BM->isAllowedToUseExtension(ExtID),
5466+
SPIRVEC_RequiresExtension, S))
5467+
return false;
54645468
BM->getExtension().insert(S);
54655469
}
54665470
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; Check whether the translator reports an error for a module with !spirv.Extension
2+
; metadata containing an extension that is disabled by --spirv-ext
3+
4+
; RUN: llvm-as < %s -o %t.bc
5+
; RUN: not llvm-spirv --spirv-ext=-SPV_KHR_bit_instructions %t.bc 2>&1 | FileCheck %s
6+
7+
; CHECK: RequiresExtension: Feature requires the following SPIR-V extension:
8+
; CHECK-NEXT: SPV_KHR_bit_instructions
9+
10+
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"
11+
target triple = "spir-unknown-unknown"
12+
13+
; Function Attrs: nounwind
14+
define spir_kernel void @foo() #0 {
15+
entry:
16+
ret void
17+
}
18+
19+
attributes #0 = { nounwind }
20+
21+
!spirv.MemoryModel = !{!0}
22+
!spirv.Source = !{!1}
23+
!spirv.Extension = !{!3}
24+
!opencl.spir.version = !{!0}
25+
!opencl.ocl.version = !{!0}
26+
!opencl.used.extensions = !{!2}
27+
!opencl.used.optional.core.features = !{!2}
28+
29+
!0 = !{i32 1, i32 2}
30+
!1 = !{i32 3, i32 102000}
31+
!2 = !{}
32+
!3 = !{!"SPV_KHR_bit_instructions"}

0 commit comments

Comments
 (0)