[PATCH] D22526: AMDGPU: Fix bug causing crash due to invalid opencl version metadata.
Yaxun Liu via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 19 12:18:17 PDT 2016
yaxunl created this revision.
yaxunl added reviewers: arsenm, nhaustov.
yaxunl added a subscriber: llvm-commits.
Herald added a reviewer: tstellarAMD.
Herald added subscribers: kzhuravl, arsenm.
https://reviews.llvm.org/D22526
Files:
lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
test/CodeGen/AMDGPU/invalid-opencl-version-metadata1.ll
test/CodeGen/AMDGPU/invalid-opencl-version-metadata2.ll
test/CodeGen/AMDGPU/invalid-opencl-version-metadata3.ll
Index: test/CodeGen/AMDGPU/invalid-opencl-version-metadata3.ll
===================================================================
--- /dev/null
+++ 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}
Index: test/CodeGen/AMDGPU/invalid-opencl-version-metadata2.ll
===================================================================
--- /dev/null
+++ 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 = !{}
Index: test/CodeGen/AMDGPU/invalid-opencl-version-metadata1.ll
===================================================================
--- /dev/null
+++ 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 = !{}
Index: lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
===================================================================
--- lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
+++ lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
@@ -783,15 +783,19 @@
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);
+ 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);
+ }
+ }
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22526.64540.patch
Type: text/x-patch
Size: 3069 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160719/0101305f/attachment.bin>
More information about the llvm-commits
mailing list