Commit b5792d90 authored by Hans Wennborg's avatar Hans Wennborg
Browse files

Merging r276119:

------------------------------------------------------------------------
r276119 | yaxunl | 2016-07-20 07:38:06 -0700 (Wed, 20 Jul 2016) | 3 lines

AMDGPU: Fix bug causing crash due to invalid opencl version metadata.

Differential Revision: https://reviews.llvm.org/D22526
------------------------------------------------------------------------

llvm-svn: 277079
parent 454777f7
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -783,17 +783,21 @@ void AMDGPUAsmPrinter::emitStartOfRuntimeMetadata(const Module &M) {
  emitRuntimeMDIntValue(OutStreamer, RuntimeMD::KeyMDVersion,
                        RuntimeMD::MDVersion << 8 | RuntimeMD::MDRevision, 2);
  if (auto MD = M.getNamedMetadata("opencl.ocl.version")) {
    if (MD->getNumOperands()) {
      auto Node = MD->getOperand(0);
      if (Node->getNumOperands() > 1) {
        emitRuntimeMDIntValue(OutStreamer, RuntimeMD::KeyLanguage,
                              RuntimeMD::OpenCL_C, 1);
    auto Node = MD->getOperand(0);
    unsigned short Major = mdconst::extract<ConstantInt>(Node->getOperand(0))
        uint16_t Major = mdconst::extract<ConstantInt>(Node->getOperand(0))
                         ->getZExtValue();
    unsigned short Minor = mdconst::extract<ConstantInt>(Node->getOperand(1))
        uint16_t Minor = mdconst::extract<ConstantInt>(Node->getOperand(1))
                         ->getZExtValue();
        emitRuntimeMDIntValue(OutStreamer, RuntimeMD::KeyLanguageVersion,
                              Major * 100 + Minor * 10, 2);
      }
    }
  }
}

static std::string getOCLTypeName(Type *Ty, bool isSigned) {
  if (VectorType* VecTy = dyn_cast<VectorType>(Ty)) {
+8 −0
Original line number Diff line number Diff line
; RUN: llc -mtriple=amdgcn--amdhsa < %s | FileCheck %s
; check llc does not crash for invalid opencl version metadata

; CHECK: .section        .AMDGPU.runtime_metadata
; CHECK-NEXT: .byte	1
; CHECK-NEXT: .short	256

!opencl.ocl.version = !{}
+9 −0
Original line number Diff line number Diff line
; RUN: llc -mtriple=amdgcn--amdhsa < %s | FileCheck %s
; check llc does not crash for invalid opencl version metadata

; CHECK: .section        .AMDGPU.runtime_metadata
; CHECK-NEXT: .byte	1
; CHECK-NEXT: .short	256

!opencl.ocl.version = !{!0}
!0 = !{}
+9 −0
Original line number Diff line number Diff line
; RUN: llc -mtriple=amdgcn--amdhsa < %s | FileCheck %s
; check llc does not crash for invalid opencl version metadata

; CHECK: .section        .AMDGPU.runtime_metadata
; CHECK-NEXT: .byte	1
; CHECK-NEXT: .short	256

!opencl.ocl.version = !{!0}
!0 = !{i32 1}