Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 4444fc4

Browse files
committed
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 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_39@277079 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 83c76e2 commit 4444fc4

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -783,15 +783,19 @@ void AMDGPUAsmPrinter::emitStartOfRuntimeMetadata(const Module &M) {
783783
emitRuntimeMDIntValue(OutStreamer, RuntimeMD::KeyMDVersion,
784784
RuntimeMD::MDVersion << 8 | RuntimeMD::MDRevision, 2);
785785
if (auto MD = M.getNamedMetadata("opencl.ocl.version")) {
786-
emitRuntimeMDIntValue(OutStreamer, RuntimeMD::KeyLanguage,
787-
RuntimeMD::OpenCL_C, 1);
788-
auto Node = MD->getOperand(0);
789-
unsigned short Major = mdconst::extract<ConstantInt>(Node->getOperand(0))
790-
->getZExtValue();
791-
unsigned short Minor = mdconst::extract<ConstantInt>(Node->getOperand(1))
792-
->getZExtValue();
793-
emitRuntimeMDIntValue(OutStreamer, RuntimeMD::KeyLanguageVersion,
794-
Major * 100 + Minor * 10, 2);
786+
if (MD->getNumOperands()) {
787+
auto Node = MD->getOperand(0);
788+
if (Node->getNumOperands() > 1) {
789+
emitRuntimeMDIntValue(OutStreamer, RuntimeMD::KeyLanguage,
790+
RuntimeMD::OpenCL_C, 1);
791+
uint16_t Major = mdconst::extract<ConstantInt>(Node->getOperand(0))
792+
->getZExtValue();
793+
uint16_t Minor = mdconst::extract<ConstantInt>(Node->getOperand(1))
794+
->getZExtValue();
795+
emitRuntimeMDIntValue(OutStreamer, RuntimeMD::KeyLanguageVersion,
796+
Major * 100 + Minor * 10, 2);
797+
}
798+
}
795799
}
796800
}
797801

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
; RUN: llc -mtriple=amdgcn--amdhsa < %s | FileCheck %s
2+
; check llc does not crash for invalid opencl version metadata
3+
4+
; CHECK: .section .AMDGPU.runtime_metadata
5+
; CHECK-NEXT: .byte 1
6+
; CHECK-NEXT: .short 256
7+
8+
!opencl.ocl.version = !{}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
; RUN: llc -mtriple=amdgcn--amdhsa < %s | FileCheck %s
2+
; check llc does not crash for invalid opencl version metadata
3+
4+
; CHECK: .section .AMDGPU.runtime_metadata
5+
; CHECK-NEXT: .byte 1
6+
; CHECK-NEXT: .short 256
7+
8+
!opencl.ocl.version = !{!0}
9+
!0 = !{}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
; RUN: llc -mtriple=amdgcn--amdhsa < %s | FileCheck %s
2+
; check llc does not crash for invalid opencl version metadata
3+
4+
; CHECK: .section .AMDGPU.runtime_metadata
5+
; CHECK-NEXT: .byte 1
6+
; CHECK-NEXT: .short 256
7+
8+
!opencl.ocl.version = !{!0}
9+
!0 = !{i32 1}

0 commit comments

Comments
 (0)