diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -1641,7 +1641,9 @@ if (!FuncMDO) return; auto F = dyn_cast(FuncMDO); - Assert(F && isa(F->getValue()->stripPointerCasts()), + Assert(F, "expected a Value", FuncMDO); + auto VF = F->getValue()->stripPointerCasts(); + Assert(isa(VF) || isa(VF), "expected a Function or null", FuncMDO); }; auto Node = dyn_cast_or_null(MDO); diff --git a/llvm/lib/Target/TargetLoweringObjectFile.cpp b/llvm/lib/Target/TargetLoweringObjectFile.cpp --- a/llvm/lib/Target/TargetLoweringObjectFile.cpp +++ b/llvm/lib/Target/TargetLoweringObjectFile.cpp @@ -171,8 +171,8 @@ if (!MDO) return nullptr; auto *V = cast(MDO); - const Function *F = cast(V->getValue()->stripPointerCasts()); - if (F->hasDLLImportStorageClass()) + const Function *F = dyn_cast(V->getValue()->stripPointerCasts()); + if (!F || F->hasDLLImportStorageClass()) return nullptr; return TM->getSymbol(F); }; diff --git a/llvm/test/Verifier/module-flags-cgprofile.ll b/llvm/test/Verifier/module-flags-cgprofile.ll --- a/llvm/test/Verifier/module-flags-cgprofile.ll +++ b/llvm/test/Verifier/module-flags-cgprofile.ll @@ -6,7 +6,7 @@ !llvm.module.flags = !{!0} !0 = !{i32 5, !"CG Profile", !1} -!1 = !{!2, !"", !3, !4, !5, !6, !7, !8} +!1 = !{!2, !"", !3, !4, !5, !6, !7, !8, !9} !2 = !{void ()* @a, void ()* @b, i64 32} !3 = !{void ()* @a, void ()* @b} !4 = !{void ()* @a, void ()* @b, i64 32, i64 32} @@ -14,6 +14,7 @@ !6 = !{void ()* @a, !"b", i64 32} !7 = !{void ()* @a, void ()* @b, !""} !8 = !{void ()* @a, void ()* @b, null} +!9 = !{void ()* @a, void ()* undef, i64 32} ; CHECK: expected a MDNode triple ; CHECK: !"" @@ -21,9 +22,9 @@ ; CHECK: !3 = !{void ()* @a, void ()* @b} ; CHECK: expected a MDNode triple ; CHECK: !4 = !{void ()* @a, void ()* @b, i64 32, i64 32} -; CHECK: expected a Function or null +; CHECK: expected a Value ; CHECK: !"a" -; CHECK: expected a Function or null +; CHECK: expected a Value ; CHECK: !"b" ; CHECK: expected an integer constant ; CHECK: !""