From 3f58e9b36a351eb9ea446fc2d43108a237a3f79f Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Mon, 16 Feb 2015 06:04:53 +0000 Subject: [PATCH] DebugInfo: Don't crash if 'Debug Info Version' has a strange value git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229356 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/DebugInfo.cpp | 2 +- test/Assembler/invalid-debug-info-version.ll | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 test/Assembler/invalid-debug-info-version.ll diff --git a/lib/IR/DebugInfo.cpp b/lib/IR/DebugInfo.cpp index 31f1e19a945..deeaae7d5de 100644 --- a/lib/IR/DebugInfo.cpp +++ b/lib/IR/DebugInfo.cpp @@ -1537,7 +1537,7 @@ bool llvm::StripDebugInfo(Module &M) { } unsigned llvm::getDebugMetadataVersionFromModule(const Module &M) { - if (auto *Val = mdconst::extract_or_null( + if (auto *Val = mdconst::dyn_extract_or_null( M.getModuleFlag("Debug Info Version"))) return Val->getZExtValue(); return 0; diff --git a/test/Assembler/invalid-debug-info-version.ll b/test/Assembler/invalid-debug-info-version.ll new file mode 100644 index 00000000000..94a81538562 --- /dev/null +++ b/test/Assembler/invalid-debug-info-version.ll @@ -0,0 +1,5 @@ +; RUN: opt < %s -S | FileCheck %s + +!llvm.module.flags = !{!0} +!0 = !{i32 1, !"Debug Info Version", !""} +; CHECK: !{i32 1, !"Debug Info Version", !""}