Skip to content

Incorrectly inferred captures(none) when a pointer is captured by a call to readonly nonunwind function without return value #129090

@tmiasko

Description

@tmiasko

FunctionAttrs assumes that readonly (or readnone) and nounwind function that
don't return a value can't capture arguments. That is incorrect, since such a
function can vary its behavior by terminating or not terminating.

An example demonstrating the issue:

$ cat a.ll 
define void @f(ptr %a, ptr %b) {
start:
  call void @g(ptr %a, ptr %b)
  ret void
}

define void @g(ptr %a, ptr %b) {
start:
  %0 = icmp eq ptr %a, %b
  br i1 %0, label %bb2, label %bb1

bb1:
  br label %bb1

bb2:
  ret void
}
$ opt-21 -S --passes=function-attrs a.ll
; ModuleID = 'a.ll'
source_filename = "a.ll"

; Function Attrs: nofree norecurse nosync nounwind memory(none)
define void @f(ptr readnone captures(none) %a, ptr readnone captures(none) %b) #0 {
start:
  call void @g(ptr %a, ptr %b)
  ret void
}

; Function Attrs: nofree norecurse nosync nounwind memory(none)
define void @g(ptr readnone %a, ptr readnone %b) #0 {
start:
  %0 = icmp eq ptr %a, %b
  br i1 %0, label %bb2, label %bb1

bb1:                                              ; preds = %bb1, %start
  br label %bb1

bb2:                                              ; preds = %start
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(none) }

Metadata

Metadata

Assignees

Labels

ipoInterprocedural optimizationsllvm:analysisIncludes value tracking, cost tables and constant foldingmiscompilation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions