Repository: apple/swift
File: test/SILGen/foreach_borrowing.swift (Swift)

Code before:

  // _nextSpan() function_ref should be at "for" keyword location (170:3)
  // CHECK: [[NEXT_SPAN:%.*]] = function_ref @$ss4SpanVsRi_zrlE05_nextA012maximumCountAByxGSi_tF {{.*}}, loc "{{.*}}":170:3
  // CHECK: apply [[NEXT_SPAN]]{{.*}}, loc "{{.*}}":170:3

  // $span debug_value should be at "for" keyword location (170:3)
  // CHECK: debug_value {{.*}}, let, name "$span", loc "{{.*}}":170:3

  // Outer loop condition (!$span.isEmpty)
  // CHECK: [[NOT_IS_EMPTY:%.*]] = function_ref @$sSb1nopyS2bFZ {{.*}}, loc "{{.*}}":170:3
  // CHECK: apply [[NOT_IS_EMPTY]]{{.*}}, loc "{{.*}}":170:3

  // Inner loop condition ($i < $count)
  // CHECK: function_ref @$sSi1loiySbSi_SitFZ  {{.*}}, loc "{{.*}}":170:3

  // Pattern variable "x" should be at its declaration location (170:7)
  // CHECK: debug_value {{.*}}, let, name "x", loc "{{.*}}":170:7

  // Where clause "==" operator function_ref
  // CHECK: [[EQUALS:%.*]] = function_ref @$sSi2eeoiySbSi_SitFZ {{.*}}, loc "{{.*}}":170:24
  // Where clause "==" operator apply
  // CHECK: apply [[EQUALS]]{{.*}}, loc "{{.*}}":170:24
  // Where clause condition extraction
  // CHECK: struct_extract {{.*}} : $Bool, #Bool._value, loc "{{.*}}":170:22
  // Where clause conditional branch
  // CHECK: cond_br {{.*}}, loc "{{.*}}":170:22

  for x in seq where x == val{
  }
}


Review comment (bug):
Can you also add checks for the other loop conditions? IIRC those were the ones that were important for debug info

Code after:
  // _nextSpan() function_ref should be at "for" keyword location
  // CHECK: [[NEXT_SPAN:%.*]] = function_ref @$ss4SpanVsRi_zrlE05_nextA012maximumCountAByxGSi_tF {{.*}}, loc "{{.*}}":[[@LINE+27]]:3
  // CHECK: apply [[NEXT_SPAN]]{{.*}}, loc "{{.*}}":[[@LINE+26]]:3

  // $span debug_value should be at "for" keyword location
  // CHECK: debug_value {{.*}}, let, name "$span", loc "{{.*}}":[[@LINE+23]]:3

  // Outer loop condition (!$span.isEmpty)
  // CHECK: [[NOT_IS_EMPTY:%.*]] = function_ref @$sSb1nopyS2bFZ {{.*}}, loc "{{.*}}":[[@LINE+20]]:3
  // CHECK: apply [[NOT_IS_EMPTY]]{{.*}}, loc "{{.*}}":[[@LINE+19]]:3
  // CHECK: cond_br {{.*}}, loc "{{.*}}":[[@LINE+18]]:3

  // Inner loop condition ($i < $count)
  // CHECK: function_ref @$sSi1loiySbSi_SitFZ  {{.*}}, loc "{{.*}}":[[@LINE+15]]:3
  // CHECK: cond_br {{.*}}, loc "{{.*}}":[[@LINE+14]]:3

  // Pattern variable "x" should be at its declaration location
  // CHECK: debug_value {{.*}}, let, name "element", loc "{{.*}}":[[@LINE+11]]:7

  // Where clause "==" operator function_ref
  // CHECK: [[EQUALS:%.*]] = function_ref @$sSi2eeoiySbSi_SitFZ {{.*}}, loc "{{.*}}":[[@LINE+8]]:36
  // Where clause "==" operator apply
  // CHECK: apply [[EQUALS]]{{.*}}, loc "{{.*}}":[[@LINE+6]]:36
  // Where clause condition extraction
  // CHECK: struct_extract {{.*}} : $Bool, #Bool._value, loc "{{.*}}":[[@LINE+4]]:28
  // Where clause conditional branch
  // CHECK: cond_br {{.*}}, loc "{{.*}}":[[@LINE+2]]:28

  for element in seq where element == val{
  }
}

// CHECK-LABEL: sil hidden [ossa] @$s17foreach_borrowing34testForEachNonCopyableSILDebugInfo3seqys4SpanVyAA14NoncopyableIntVG_tF : $@convention(thin) (@guaranteed Span<NoncopyableInt>) -> () {
func testForEachNonCopyableSILDebugInfo(seq: borrowing Span<NoncopyableInt>){
  // CHECK: debug_value {{.*}} : $*NoncopyableInt, let, name "element", expr op_deref, loc "{{.*}}":[[@LINE+1]]:7 isImplicit: false
  for element in seq {
      if (element.value == 0){
          continue
      }
  }
}