[llvm] r228818 - Verifier: Check for null operands in !llvm.module.flags
David Majnemer
david.majnemer at gmail.com
Wed Feb 11 01:13:06 PST 2015
Author: majnemer
Date: Wed Feb 11 03:13:06 2015
New Revision: 228818
URL: http://llvm.org/viewvc/llvm-project?rev=228818&view=rev
Log:
Verifier: Check for null operands in !llvm.module.flags
Added:
llvm/trunk/test/Verifier/module-flags-2.ll
Modified:
llvm/trunk/lib/IR/Module.cpp
llvm/trunk/lib/IR/Verifier.cpp
Modified: llvm/trunk/lib/IR/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Module.cpp?rev=228818&r1=228817&r2=228818&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Module.cpp (original)
+++ llvm/trunk/lib/IR/Module.cpp Wed Feb 11 03:13:06 2015
@@ -278,7 +278,7 @@ void Module::eraseNamedMetadata(NamedMDN
}
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<M
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));
Modified: llvm/trunk/lib/IR/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Verifier.cpp?rev=228818&r1=228817&r2=228818&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Verifier.cpp (original)
+++ llvm/trunk/lib/IR/Verifier.cpp Wed Feb 11 03:13:06 2015
@@ -869,7 +869,7 @@ Verifier::visitModuleFlag(const MDNode *
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,
Added: llvm/trunk/test/Verifier/module-flags-2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Verifier/module-flags-2.ll?rev=228818&view=auto
==============================================================================
--- llvm/trunk/test/Verifier/module-flags-2.ll (added)
+++ llvm/trunk/test/Verifier/module-flags-2.ll Wed Feb 11 03:13:06 2015
@@ -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)
More information about the llvm-commits
mailing list