; RUN: llvm-as %s -o %t.bc
; RUN: not llvm-spirv %t.bc -o %t.spv 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR

; Check that everything is fine if SPV_INTEL_long_composites is enabled
; RUN: llvm-spirv --spirv-ext=+SPV_INTEL_long_composites %t.bc -o %t.spv
; RUN: llvm-spirv %t.spv --to-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM
; TODO: run validator once it supports the extension
; RUNx: spirv-val %t.spv

; CHECK-SPIRV: Capability LongCompositesINTEL
; CHECK-SPIRV: Extension "SPV_INTEL_long_composites"
; CHECK-SPIRV: TypeInt [[TInt:[0-9]+]] 8
; CHECK-SPIRV: Constant {{[0-9]+}} [[ArrSize:[0-9]+]] 78000
; CHECK-SPIRV: TypeArray [[TArr:[0-9]+]] [[TInt]] [[ArrSize]]
; CHECK-SPIRV: 65535 ConstantComposite [[TArr]]
; CHECK-SPIRV-NEXT: 12469 ConstantCompositeContinuedINTEL

; CHECK-LLVM: @big_array = unnamed_addr addrspace(2) constant [78000 x i8] c"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz

; CHECK-ERROR: InvalidWordCount: Can't encode instruction with word count greater than 65535:
; CHECK-ERROR-NEXT: Global variable has a constant array initializer with a number of elements greater than OpConstantComposite can have (65532). Should the array be split?
; CHECK-ERROR-NEXT: Original LLVM value:
; CHECK-ERROR-NEXT: @big_array = local_unnamed_addr addrspace(2) constant [78000 x i8] c"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz

; ModuleID = 'llvm-spirv/test/word_count_limit.cl'
source_filename = "llvm-spirv/test/word_count_limit.cl"
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"
target triple = "spir"

@big_array = local_unnamed_addr addrspace(2) constant [78000 x i8] c"[encoded data, 78000 characters]", align 1

!llvm.module.flags = !{!0}
!opencl.ocl.version = !{!1}
!opencl.spir.version = !{!2}
!llvm.ident = !{!3}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 1, i32 0}
!2 = !{i32 1, i32 2}
!3 = !{!"clang version 11.0.0 (https://github.com/llvm/llvm-project eb8edd852601270eff090dc7d42acde7cd7a2573)"}
