Verifier: Check for null operands in !llvm.module.flags
authorDavid Majnemer <david.majnemer@gmail.com>
Wed, 11 Feb 2015 09:13:06 +0000 (09:13 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Wed, 11 Feb 2015 09:13:06 +0000 (09:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228818 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/Module.cpp
lib/IR/Verifier.cpp
test/Verifier/module-flags-2.ll [new file with mode: 0644]

index d32ffcdac33704f8f5ae622b6a1721d63a2b0dc4..b0abe8cbe110f6789aee52cb53c3c46e7a278aba 100644 (file)
@@ -278,7 +278,7 @@ void Module::eraseNamedMetadata(NamedMDNode *NMD) {
 }
 
 bool Module::isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB) {
-  if (ConstantInt *Behavior = mdconst::dyn_extract<ConstantInt>(MD)) {
+  if (ConstantInt *Behavior = mdconst::dyn_extract_or_null<ConstantInt>(MD)) {
     uint64_t Val = Behavior->getLimitedValue();
     if (Val >= ModFlagBehaviorFirstVal && Val <= ModFlagBehaviorLastVal) {
       MFB = static_cast<ModFlagBehavior>(Val);
@@ -298,7 +298,7 @@ getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const {
     ModFlagBehavior MFB;
     if (Flag->getNumOperands() >= 3 &&
         isValidModFlagBehavior(Flag->getOperand(0), MFB) &&
-        isa<MDString>(Flag->getOperand(1))) {
+        dyn_cast_or_null<MDString>(Flag->getOperand(1))) {
       // Check the operands of the MDNode before accessing the operands.
       // The verifier will actually catch these failures.
       MDString *Key = cast<MDString>(Flag->getOperand(1));
index 37816a374cbaa75c31b2a1782d95ef0110adcfb1..5d4de30e44013a01d94ae723efdfc5ae27b1b42a 100644 (file)
@@ -869,7 +869,7 @@ Verifier::visitModuleFlag(const MDNode *Op,
   Module::ModFlagBehavior MFB;
   if (!Module::isValidModFlagBehavior(Op->getOperand(0), MFB)) {
     Assert1(
-        mdconst::dyn_extract<ConstantInt>(Op->getOperand(0)),
+        mdconst::dyn_extract_or_null<ConstantInt>(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 (file)
index 0000000..8582162
--- /dev/null
@@ -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)