[PATCH] D109732: Attributor: Fix crash on undef in !callees

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 13 18:44:27 PDT 2021


arsenm created this revision.
arsenm added reviewers: jdoerfert, kuter.
Herald added subscribers: ormris, okura, uenoku, hiraditya.
Herald added a reviewer: uenoku.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a reviewer: sstefan1.
Herald added a reviewer: baziotis.
Herald added a project: LLVM.

https://reviews.llvm.org/D109732

Files:
  llvm/lib/Transforms/IPO/AttributorAttributes.cpp
  llvm/test/Transforms/Attributor/callgraph.ll


Index: llvm/test/Transforms/Attributor/callgraph.ll
===================================================================
--- llvm/test/Transforms/Attributor/callgraph.ll
+++ llvm/test/Transforms/Attributor/callgraph.ll
@@ -76,9 +76,22 @@
   ret void
 }
 
+; Check there's no crash if something that isn't a function appears in !callees
+define void @undef_in_callees() {
+; CHECK-LABEL: @undef_in_callees(
+; CHECK-NEXT:  cond.end.i:
+; CHECK-NEXT:    call void undef(i8* undef, i32 undef, i8* undef), !callees !3
+; CHECK-NEXT:    ret void
+;
+cond.end.i:
+  call void undef(i8* undef, i32 undef, i8* undef), !callees !3
+  ret void
+}
+
 !0 = !{!1}
 !1 = !{i64 0, i1 false}
 !2 = !{void ()* @func3, void ()* @func4}
+!3 = distinct !{void (i8*, i32, i8*)* undef, void (i8*, i32, i8*)* null}
 
 ; UTC_ARGS: --disable
 
Index: llvm/lib/Transforms/IPO/AttributorAttributes.cpp
===================================================================
--- llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -9438,7 +9438,7 @@
     // Process callee metadata if available.
     if (auto *MD = getCtxI()->getMetadata(LLVMContext::MD_callees)) {
       for (auto &Op : MD->operands()) {
-        Function *Callee = mdconst::extract_or_null<Function>(Op);
+        Function *Callee = mdconst::dyn_extract_or_null<Function>(Op);
         if (Callee)
           addCalledFunction(Callee, Change);
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109732.372381.patch
Type: text/x-patch
Size: 1444 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210914/1775661d/attachment.bin>


More information about the llvm-commits mailing list