From f937622ecee4e0f6aa4de7b9a68d8fbfb6d6acab Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Wed, 11 Feb 2015 09:13:06 +0000 Subject: [PATCH] Verifier: Check for null operands in !llvm.module.flags git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228818 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/Module.cpp | 4 ++-- lib/IR/Verifier.cpp | 2 +- test/Verifier/module-flags-2.ll | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 test/Verifier/module-flags-2.ll diff --git a/lib/IR/Module.cpp b/lib/IR/Module.cpp index d32ffcdac33..b0abe8cbe11 100644 --- a/lib/IR/Module.cpp +++ b/lib/IR/Module.cpp @@ -278,7 +278,7 @@ void Module::eraseNamedMetadata(NamedMDNode *NMD) { } bool Module::isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB) { - if (ConstantInt *Behavior = mdconst::dyn_extract(MD)) { + if (ConstantInt *Behavior = mdconst::dyn_extract_or_null(MD)) { uint64_t Val = Behavior->getLimitedValue(); if (Val >= ModFlagBehaviorFirstVal && Val <= ModFlagBehaviorLastVal) { MFB = static_cast(Val); @@ -298,7 +298,7 @@ getModuleFlagsMetadata(SmallVectorImpl &Flags) const { ModFlagBehavior MFB; if (Flag->getNumOperands() >= 3 && isValidModFlagBehavior(Flag->getOperand(0), MFB) && - isa(Flag->getOperand(1))) { + dyn_cast_or_null(Flag->getOperand(1))) { // Check the operands of the MDNode before accessing the operands. // The verifier will actually catch these failures. MDString *Key = cast(Flag->getOperand(1)); diff --git a/lib/IR/Verifier.cpp b/lib/IR/Verifier.cpp index 37816a374cb..5d4de30e440 100644 --- a/lib/IR/Verifier.cpp +++ b/lib/IR/Verifier.cpp @@ -869,7 +869,7 @@ Verifier::visitModuleFlag(const MDNode *Op, Module::ModFlagBehavior MFB; if (!Module::isValidModFlagBehavior(Op->getOperand(0), MFB)) { Assert1( - mdconst::dyn_extract(Op->getOperand(0)), + mdconst::dyn_extract_or_null(Op->getOperand(0)), "invalid behavior operand in module flag (expected constant integer)", Op->getOperand(0)); Assert1(false, diff --git a/test/Verifier/module-flags-2.ll b/test/Verifier/module-flags-2.ll new file mode 100644 index 00000000000..8582162eaf8 --- /dev/null +++ b/test/Verifier/module-flags-2.ll @@ -0,0 +1,6 @@ +; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s + +!llvm.module.flags = !{!0} +!0 = !{null, null, null} + +; CHECK: invalid behavior operand in module flag (expected constant integer) -- 2.34.1