[llvm] 2544283 - [Core][FIX] Do not assume instruction users in DetermineUseCaptureKind
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 1 17:18:02 PDT 2023
Author: Johannes Doerfert
Date: 2023-09-01T17:17:51-07:00
New Revision: 2544283597e0f12f523cc4d32a599809152e793d
URL: https://github.com/llvm/llvm-project/commit/2544283597e0f12f523cc4d32a599809152e793d
DIFF: https://github.com/llvm/llvm-project/commit/2544283597e0f12f523cc4d32a599809152e793d.diff
LOG: [Core][FIX] Do not assume instruction users in DetermineUseCaptureKind
Added:
Modified:
llvm/lib/Analysis/CaptureTracking.cpp
llvm/test/Transforms/Attributor/callgraph.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/CaptureTracking.cpp b/llvm/lib/Analysis/CaptureTracking.cpp
index 00e096af3110b96..2827eb705ac58c7 100644
--- a/llvm/lib/Analysis/CaptureTracking.cpp
+++ b/llvm/lib/Analysis/CaptureTracking.cpp
@@ -304,7 +304,11 @@ llvm::FindEarliestCapture(const Value *V, Function &F, bool ReturnCaptures,
UseCaptureKind llvm::DetermineUseCaptureKind(
const Use &U,
function_ref<bool(Value *, const DataLayout &)> IsDereferenceableOrNull) {
- Instruction *I = cast<Instruction>(U.getUser());
+ Instruction *I = dyn_cast<Instruction>(U.getUser());
+
+ // TODO: Investigate non-instruction uses.
+ if (!I)
+ return UseCaptureKind::MAY_CAPTURE;
switch (I->getOpcode()) {
case Instruction::Call:
diff --git a/llvm/test/Transforms/Attributor/callgraph.ll b/llvm/test/Transforms/Attributor/callgraph.ll
index 08a294318f8bcc9..e91236b661e0785 100644
--- a/llvm/test/Transforms/Attributor/callgraph.ll
+++ b/llvm/test/Transforms/Attributor/callgraph.ll
@@ -5,6 +5,9 @@
; RUN: opt -passes=attributor --attributor-max-specializations-per-call-base=0 -S < %s | FileCheck %s --check-prefixes=CHECK,OWRDL,LIMI0
; RUN: opt -passes=attributor --attributor-assume-closed-world -S < %s | FileCheck %s --check-prefixes=CHECK,UPTO2,UNLIM,CWRLD
+;.
+; CHECK: @[[G:[a-zA-Z0-9_$"\\.-]+]] = global ptr @usedByGlobal
+;.
define dso_local void @func1() {
; CHECK-LABEL: @func1(
; CHECK-NEXT: br label [[TMP2:%.*]]
@@ -472,6 +475,14 @@ define void @usedOnlyInCastedDirectCallCaller() {
ret void
}
+define internal void @usedByGlobal() {
+; CHECK-LABEL: @usedByGlobal(
+; CHECK-NEXT: ret void
+;
+ ret void
+}
+ at G = global ptr @usedByGlobal
+
define void @broker(ptr %unknown) !callback !0 {
; OWRDL-LABEL: @broker(
; OWRDL-NEXT: call void [[UNKNOWN:%.*]]()
@@ -618,6 +629,8 @@ cond.end.i:
; UTC_ARGS: --enable
+;.
+; CHECK: attributes #[[ATTR0:[0-9]+]] = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) }
;.
; UNLIM: [[META0:![0-9]+]] = !{!1}
; UNLIM: [[META1:![0-9]+]] = !{i64 0, i1 false}
More information about the llvm-commits
mailing list