summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYaxun Liu <Yaxun.Liu@amd.com>2016-07-20 14:38:06 +0000
committerYaxun Liu <Yaxun.Liu@amd.com>2016-07-20 14:38:06 +0000
commit4b1d9f7f1887a3ff21a9c17fa53927ea69d96697 (patch)
tree55a4307e9229fadb247323334086f3a146dda3f0
parentb084125dbfa389e5cc0ce9d691b990d1b86a676a (diff)
downloadbcm5719-llvm-4b1d9f7f1887a3ff21a9c17fa53927ea69d96697.tar.gz
bcm5719-llvm-4b1d9f7f1887a3ff21a9c17fa53927ea69d96697.zip
AMDGPU: Fix bug causing crash due to invalid opencl version metadata.
Differential Revision: https://reviews.llvm.org/D22526 llvm-svn: 276119
-rw-r--r--llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp22
-rw-r--r--llvm/test/CodeGen/AMDGPU/invalid-opencl-version-metadata1.ll8
-rw-r--r--llvm/test/CodeGen/AMDGPU/invalid-opencl-version-metadata2.ll9
-rw-r--r--llvm/test/CodeGen/AMDGPU/invalid-opencl-version-metadata3.ll9
4 files changed, 39 insertions, 9 deletions
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
index cfe6346fb6b..c9c95c796a6 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
@@ -783,15 +783,19 @@ void AMDGPUAsmPrinter::emitStartOfRuntimeMetadata(const Module &M) {
emitRuntimeMDIntValue(OutStreamer, RuntimeMD::KeyMDVersion,
RuntimeMD::MDVersion << 8 | RuntimeMD::MDRevision, 2);
if (auto MD = M.getNamedMetadata("opencl.ocl.version")) {
- emitRuntimeMDIntValue(OutStreamer, RuntimeMD::KeyLanguage,
- RuntimeMD::OpenCL_C, 1);
- auto Node = MD->getOperand(0);
- unsigned short Major = mdconst::extract<ConstantInt>(Node->getOperand(0))
- ->getZExtValue();
- unsigned short Minor = mdconst::extract<ConstantInt>(Node->getOperand(1))
- ->getZExtValue();
- emitRuntimeMDIntValue(OutStreamer, RuntimeMD::KeyLanguageVersion,
- Major * 100 + Minor * 10, 2);
+ if (MD->getNumOperands()) {
+ auto Node = MD->getOperand(0);
+ if (Node->getNumOperands() > 1) {
+ emitRuntimeMDIntValue(OutStreamer, RuntimeMD::KeyLanguage,
+ RuntimeMD::OpenCL_C, 1);
+ uint16_t Major = mdconst::extract<ConstantInt>(Node->getOperand(0))
+ ->getZExtValue();
+ uint16_t Minor = mdconst::extract<ConstantInt>(Node->getOperand(1))
+ ->getZExtValue();
+ emitRuntimeMDIntValue(OutStreamer, RuntimeMD::KeyLanguageVersion,
+ Major * 100 + Minor * 10, 2);
+ }
+ }
}
}
diff --git a/llvm/test/CodeGen/AMDGPU/invalid-opencl-version-metadata1.ll b/llvm/test/CodeGen/AMDGPU/invalid-opencl-version-metadata1.ll
new file mode 100644
index 00000000000..4e17a921d91
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/invalid-opencl-version-metadata1.ll
@@ -0,0 +1,8 @@
+; 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 = !{}
diff --git a/llvm/test/CodeGen/AMDGPU/invalid-opencl-version-metadata2.ll b/llvm/test/CodeGen/AMDGPU/invalid-opencl-version-metadata2.ll
new file mode 100644
index 00000000000..35b7d70596c
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/invalid-opencl-version-metadata2.ll
@@ -0,0 +1,9 @@
+; 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 = !{}
diff --git a/llvm/test/CodeGen/AMDGPU/invalid-opencl-version-metadata3.ll b/llvm/test/CodeGen/AMDGPU/invalid-opencl-version-metadata3.ll
new file mode 100644
index 00000000000..e1693551b62
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/invalid-opencl-version-metadata3.ll
@@ -0,0 +1,9 @@
+; 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}
OpenPOWER on IntegriCloud