[PATCH] D135483: [llvm][LLParser] Fix issue with forward-referenced dso_local_equivalent globals

Leonard Chan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 7 12:51:09 PDT 2022


leonardchan created this revision.
leonardchan added reviewers: phosek, MaskRay.
leonardchan added a project: LLVM.
Herald added subscribers: StephenFan, pengfei, hiraditya.
Herald added a project: All.
leonardchan requested review of this revision.

llc would fail with this IR:

  ; RUN:llc -mtriple=x86_64-linux-gnu -o - %s
  @_ZTV1B_rv = constant i32 trunc (i64 sub (i64 ptrtoint (void ()* dso_local_equivalent @_ZN1B1fEi to i64), i64 ptrtoint (i32* getelementptr inbounds (i32, i32* @_ZTV1B_rv, i32 0) to i64)) to i32)
  
  define void @_ZN1B1fEi() {
     ret void
  }
  
  bin/llc: error: bin/llc: /usr/local/google/home/leonardchan/llvm-monorepo/llvm-project-2/llvm/test/ThinLTO/X86/dso_local_equivalent.ll:6:66: error: constant expression type mismatch: got type 'i8*' but expected 'void ()*'

The issue is that the forward referenced placeholder globalvariable is being type-checked with _ZN1B1fEi once we finish parsing its name and type. This patch ensures the placeholder will only be established if we know what type it should be. In globals, this is straightforward where the expected type is given before `dso_local_equivalent`. For calls where we may not know the type of the forward-referenced callee, we can lazily create the placeholder until the type is known.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135483

Files:
  llvm/include/llvm/AsmParser/LLParser.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/test/CodeGen/X86/dso_local_equivalent.ll
  llvm/test/CodeGen/X86/dso_local_equivalent_errors.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135483.466158.patch
Type: text/x-patch
Size: 9100 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221007/0404f7e1/attachment.bin>


More information about the llvm-commits mailing list