[PATCH] D124878: [Bitcode] Include indirect users of BlockAddresses in bitcode

Wende Tan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 3 14:19:43 PDT 2022


twd2 created this revision.
twd2 added reviewers: nickdesaulniers, dexonsmith, tejohnson, MaskRay, void, pcc, rickyz.
twd2 added a project: LLVM.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
twd2 requested review of this revision.
Herald added a subscriber: llvm-commits.

The original fix (commit 23ec5782c3cc <https://reviews.llvm.org/rG23ec5782c3cc0d77b5e44285e5124cd4a3ffeeef>) of https://github.com/llvm/llvm-project/issues/52787 only adds `Function`s that have `Instruction`s that directly use `BlockAddress`es into the bitcode (`FUNC_CODE_BLOCKADDR_USERS`).

However, in either @rickyz's original reproducing code:

  void f(long);
  
  __attribute__((noinline)) static void fun(long x) {
    f(x + 1);
  }
  
  void repro(void) {
    fun(({
      label:
        (long)&&label;
    }));
  }



  ...
  define dso_local void @repro() #0 {
  entry:
    br label %label
  
  label:                                            ; preds = %entry
    tail call fastcc void @fun()
    ret void
  }
  
  define internal fastcc void @fun() unnamed_addr #1 {
  entry:
    tail call void @f(i64 add (i64 ptrtoint (i8* blockaddress(@repro, %label) to i64), i64 1)) #3
    ret void
  }
  ...

or the xfs and overlayfs in the Linux kernel, `BlockAddress`es (e.g., `i8* blockaddress(@repro, %label)`) may first compose `ConstantExpr`s (e.g., `i64 ptrtoint (i8* blockaddress(@repro, %label) to i64)`) and then used by `Instruction`s. This case is not handled by the original fix.

This patch adds *indirect* users of `BlockAddress`es, i.e., the `Instruction`s using some `Constant`s which further use the `BlockAddress`es, into the bitcode as well, by doing breadth-first searches.

Fixes: https://github.com/llvm/llvm-project/issues/52787
Fixes: 23ec5782c3cc <https://reviews.llvm.org/rG23ec5782c3cc0d77b5e44285e5124cd4a3ffeeef> ("[Bitcode] materialize Functions early when BlockAddress taken")


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124878

Files:
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/test/Bitcode/blockaddress-indirect-users.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124878.426817.patch
Type: text/x-patch
Size: 3367 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220503/ed0c505a/attachment.bin>


More information about the llvm-commits mailing list