DebugInfo: Don't crash if 'Debug Info Version' has a strange value
authorDavid Majnemer <david.majnemer@gmail.com>
Mon, 16 Feb 2015 06:04:53 +0000 (06:04 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Mon, 16 Feb 2015 06:04:53 +0000 (06:04 +0000)
llvm-svn: 229356

llvm/lib/IR/DebugInfo.cpp
llvm/test/Assembler/invalid-debug-info-version.ll [new file with mode: 0644]

index 31f1e19..deeaae7 100644 (file)
@@ -1537,7 +1537,7 @@ bool llvm::StripDebugInfo(Module &M) {
 }
 
 unsigned llvm::getDebugMetadataVersionFromModule(const Module &M) {
-  if (auto *Val = mdconst::extract_or_null<ConstantInt>(
+  if (auto *Val = mdconst::dyn_extract_or_null<ConstantInt>(
           M.getModuleFlag("Debug Info Version")))
     return Val->getZExtValue();
   return 0;
diff --git a/llvm/test/Assembler/invalid-debug-info-version.ll b/llvm/test/Assembler/invalid-debug-info-version.ll
new file mode 100644 (file)
index 0000000..94a8153
--- /dev/null
@@ -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", !""}