[PATCH] D139974: [llvm][ADT] Fix Any with msvc and lto

Sebastian Neubauer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 19 08:15:44 PST 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG95b27b2a1e0e: [llvm][ADT] Fix Any with msvc and lto (authored by sebastian-ne).

Changed prior to commit:
  https://reviews.llvm.org/D139974?vs=482933&id=483974#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139974

Files:
  llvm/include/llvm/ADT/Any.h


Index: llvm/include/llvm/ADT/Any.h
===================================================================
--- llvm/include/llvm/ADT/Any.h
+++ llvm/include/llvm/ADT/Any.h
@@ -31,9 +31,9 @@
   // identifier for the type `T`. It is explicitly marked with default
   // visibility so that when `-fvisibility=hidden` is used, the loader still
   // merges duplicate definitions across DSO boundaries.
-  template <typename T> struct TypeId {
-    static const char Id;
-  };
+  // We also cannot mark it as `const`, otherwise msvc merges all definitions
+  // when lto is enabled, making any comparison return true.
+  template <typename T> struct TypeId { static char Id; };
 
   struct StorageBase {
     virtual ~StorageBase() = default;
@@ -117,7 +117,7 @@
   std::unique_ptr<StorageBase> Storage;
 };
 
-template <typename T> const char Any::TypeId<T>::Id = 0;
+template <typename T> char Any::TypeId<T>::Id = 0;
 
 template <typename T> bool any_isa(const Any &Value) {
   if (!Value.Storage)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139974.483974.patch
Type: text/x-patch
Size: 991 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221219/8180032e/attachment.bin>


More information about the llvm-commits mailing list