[PATCH] D139973: [llvm] Make llvm::Any similar to std::any

Sebastian Neubauer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 19 08:33:20 PST 2022


sebastian-ne updated this revision to Diff 483975.
sebastian-ne marked 2 inline comments as done.
sebastian-ne added a comment.

> It is surprising to me that std::any can work without RTTI. Never thought it could be implemented.

It seems like libstdc++ and libc++ both implement it the way llvm::Any is implemented when RTTI is not available (actually, I think llvm::Any was copied from libstdc++ at some point).

> This "compare function pointer" trick is awesome, but it might not always work as explained in this commit.
> This question however, suggest that any_cast doesn't always work with RTTI either, which is weird.
> I don't know of any other potential issues. std::visitor can't be used with std::any in absense of std::any::type, but that's minor, I think.

As you noticed, it is very difficult to implement Any correctly on every platform under any circumstances and compiler flags.
That is exactly what this patch aims at: Moving the responsibility to implement Any correctly to the standard library.

Unfortunatly, we can’t replace llvm::Any with std::any just yet, because of bugs in msvc that were only fixed recently.

> llvm::any_isa<> is kind of convenient and is aligned with llvm::isa<>. Same for llvm::any_cast.

It is, however, there is no std::any_isa or std::any_cast_or_null, so the question gets wether we want to keep llvm::Any around as a wrapper of std::any once we can use it (in this case this patch would be obsolete)
or if we we want to remove llvm::Any and use std::any only.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139973

Files:
  clang/unittests/Tooling/RefactoringTest.cpp
  clang/unittests/Tooling/TransformerTest.cpp
  lldb/include/lldb/Core/RichManglingContext.h
  llvm/include/llvm/ADT/Any.h
  llvm/lib/CodeGen/MachinePassManager.cpp
  llvm/lib/IR/LLVMContextImpl.h
  llvm/lib/Passes/StandardInstrumentations.cpp
  llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
  llvm/lib/Transforms/Scalar/LoopPassManager.cpp
  llvm/lib/Transforms/Utils/Debugify.cpp
  llvm/unittests/ADT/AnyTest.cpp
  llvm/unittests/IR/PassBuilderCallbacksTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139973.483975.patch
Type: text/x-patch
Size: 26181 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221219/cc5116bc/attachment-0001.bin>


More information about the cfe-commits mailing list