[all-commits] [llvm/llvm-project] 3d349e: [CodeGen][ObjC] Fix broken IR generated when there...

Akira Hatanaka via All-commits all-commits at lists.llvm.org
Thu Jan 21 17:39:09 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 3d349ed7e1108686271a09314dafaa356df4006d
      https://github.com/llvm/llvm-project/commit/3d349ed7e1108686271a09314dafaa356df4006d
  Author: Akira Hatanaka <ahatanaka at apple.com>
  Date:   2021-01-21 (Thu, 21 Jan 2021)

  Changed paths:
    M clang/lib/CodeGen/CGObjC.cpp
    M clang/test/CodeGenObjC/ns_consume_null_check.m

  Log Message:
  -----------
  [CodeGen][ObjC] Fix broken IR generated when there is a nil receiver
check

This patch fixes a bug in emitARCOperationAfterCall where it inserts the
fall-back call after a bitcast instruction and then replaces the
bitcast's operand with the result of the fall-back call. The generated
IR without this patch looks like this:

msgSend.call:                                     ; preds = %entry
  %call = call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend
  br label %msgSend.cont

msgSend.null-receiver:                            ; preds = %entry
  call void @llvm.objc.release(i8* %4)
  br label %msgSend.cont

msgSend.cont:
  %8 = phi i8* [ %call, %msgSend.call ], [ null, %msgSend.null-receiver ]
  %9 = bitcast i8* %10 to %0*
  %10 = call i8* @llvm.objc.retain(i8* %8)

Notice that `%9 = bitcast i8* %10` to %0* is taking operand %10 which is
defined after it.

To fix the bug, this patch modifies the insert point to point to the
bitcast instruction so that the fall-back call is inserted before the
bitcast. In addition, it teaches the function to look at phi
instructions that are generated when there is a check for a null
receiver and insert the retainRV/claimRV instruction right after the
call instead of inserting a fall-back call right after the phi
instruction.

rdar://73360225

Differential Revision: https://reviews.llvm.org/D95181




More information about the All-commits mailing list