[PATCH] D126781: [CodeGen] Correctly handle weak symbols in the codegen

Vassil Vassilev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 2 14:43:05 PDT 2022


v.g.vassilev added a comment.

Thanks for the prompt reply.

We have seen that when there is an inline/weak symbol with no use CodeGen decides not to emit that symbol and moves it into a map. Upon a use it would lazily emit it. However, in cling/clang-repl the use might come on the next line, which means that we called `CodeGeneratorImpl::StartModule` which has called `CodeGeneratorImpl::Initialize` and reset `Builder`. By that time we have lost the information if we emitted the symbol or not.

The intent of this patch is to selectively carry some state over to the `Builder` so that we can keep track of the lazy decisions the previous builder took. If we eagerly emit declarations we have no problems `clang-repl -Xcc -Xclang -Xcc -femit-all-decls  "inline int f() { return 1; }" "int i = f();"` makes it work. However it seems an overkill.

A second goal of this patch is to start a discussion if/how we could do it better as carrying state is error-prone...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D126781/new/

https://reviews.llvm.org/D126781



More information about the cfe-commits mailing list