[PATCH] D157452: [RFC][Clang][Codegen] `std::type_info` needs special care with explicit address spaces

Alex Voicu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 8 16:17:28 PDT 2023


AlexVlx created this revision.
AlexVlx added reviewers: rjmccall, efriedma, yaxunl, arsenm.
AlexVlx added a project: clang.
Herald added a project: All.
AlexVlx requested review of this revision.
Herald added subscribers: cfe-commits, wdng.

After https://reviews.llvm.org/D153092, for targets that use a non-default AS for globals, an "interesting" situation arises around `typeid` and its paired type, `type_info`:

- on the AST level, the `type_info` interface is defined with default / generic addresses, be it for function arguments, or for `this`;
- in IR, `type_info` values are globals, and thus pointers to `type_info` values are pointers to global

This leads to a mismatch between the function signature / formal type of the argument, and its actual type. Currently we try to handle such mismatches via bitcast, but that is wrong in this case, since an ascast is required. **However**, I'm not convinced this is the right way to address it, I've just not found a better / less noisy one (yet?); the other alternative would be to special case codegen for typeinfo itself, and adjust the IR function signatures there. That's less centralised and doesn't actually seem correct, since `type_info` has a C++(mangled) interface, and we'd be basically lying about the type. Hopefully I'm missing some obvious and significantly more tidy solution - hence the RFC.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157452

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/typeid-cxx11-with-address-space.cpp
  clang/test/CodeGenCXX/typeid-with-address-space.cpp
  clang/test/CodeGenCXX/typeinfo
  clang/test/CodeGenCXX/typeinfo-with-address-space.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157452.548380.patch
Type: text/x-patch
Size: 10132 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230808/f3bf3bff/attachment-0001.bin>


More information about the cfe-commits mailing list