diff --git a/lib/Analysis/AssumeBundleQueries.cpp b/lib/Analysis/AssumeBundleQueries.cpp index 273b38a9567..9cb5b10570b 100644 --- a/lib/Analysis/AssumeBundleQueries.cpp +++ b/lib/Analysis/AssumeBundleQueries.cpp @@ -88,9 +88,11 @@ void llvm::fillMapFromAssume(CallInst &AssumeCI, RetainedKnowledgeMap &Result) { Result[Key][&Assume] = {0, 0}; continue; } - unsigned Val = cast( - getValueFromBundleOpInfo(Assume, Bundles, ABA_Argument)) - ->getZExtValue(); + auto *CI = dyn_cast( + getValueFromBundleOpInfo(Assume, Bundles, ABA_Argument)); + if (!CI) + continue; + unsigned Val = CI->getZExtValue(); auto Lookup = Result.find(Key); if (Lookup == Result.end() || !Lookup->second.count(&Assume)) { Result[Key][&Assume] = {Val, Val}; diff --git a/unittests/Analysis/AssumeBundleQueriesTest.cpp b/unittests/Analysis/AssumeBundleQueriesTest.cpp index 946368e1cb9..a66e365f237 100644 --- a/unittests/Analysis/AssumeBundleQueriesTest.cpp +++ b/unittests/Analysis/AssumeBundleQueriesTest.cpp @@ -383,6 +383,15 @@ TEST(AssumeQueryAPI, fillMapFromAssume) { "(nonnull|align|dereferenceable)")); ASSERT_TRUE(FindExactlyAttributes(Map, Old, "")); })); + Tests.push_back(std::make_pair( + "call void @llvm.assume(i1 true) [\"align\"(i8* undef, i32 undef)]", + [](Instruction *I) { + // Don't crash but don't learn from undef. + RetainedKnowledgeMap Map; + fillMapFromAssume(*cast(I), Map); + + ASSERT_TRUE(Map.empty()); + })); RunTest(Head, Tail, Tests); }