[libcxx-commits] [PATCH] D115334: [libc++] Change workaround for init_priority((101)) outside of system headers

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Dec 13 11:38:04 PST 2021


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG515afe8b13a6: [libc++] Change workaround for init_priority((100)) outside of system headers (authored by ldionne).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115334

Files:
  libcxx/src/chrono.cpp
  libcxx/src/chrono_system_time_init.h
  libcxx/src/experimental/memory_resource.cpp
  libcxx/src/experimental/memory_resource_init_helper.h
  libcxx/src/iostream.cpp
  libcxx/src/iostream_init.h


Index: libcxx/src/iostream_init.h
===================================================================
--- /dev/null
+++ libcxx/src/iostream_init.h
@@ -0,0 +1,2 @@
+#pragma GCC system_header
+_LIBCPP_HIDDEN ios_base::Init __start_std_streams _LIBCPP_INIT_PRIORITY_MAX;
\ No newline at end of file
Index: libcxx/src/iostream.cpp
===================================================================
--- libcxx/src/iostream.cpp
+++ libcxx/src/iostream.cpp
@@ -85,12 +85,9 @@
 ;
 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
 
-// Hacky way to make the compiler believe that we're inside a system header so
-// it doesn't flag the use of the init_priority attribute with a value that's
-// reserved for the implementation (we're the implementation).
-# 80 "iostream.cpp" 1 3
-_LIBCPP_HIDDEN ios_base::Init __start_std_streams _LIBCPP_INIT_PRIORITY_MAX;
-# 82 "iostream.cpp" 2
+// Pretend we're inside a system header so the compiler doesn't flag the use of the init_priority
+// attribute with a value that's reserved for the implementation (we're the implementation).
+#include "iostream_init.h"
 
 // On Windows the TLS storage for locales needs to be initialized before we create
 // the standard streams, otherwise it may not be alive during program termination
Index: libcxx/src/experimental/memory_resource_init_helper.h
===================================================================
--- /dev/null
+++ libcxx/src/experimental/memory_resource_init_helper.h
@@ -0,0 +1,2 @@
+#pragma GCC system_header
+_LIBCPP_SAFE_STATIC ResourceInitHelper res_init _LIBCPP_INIT_PRIORITY_MAX;
\ No newline at end of file
Index: libcxx/src/experimental/memory_resource.cpp
===================================================================
--- libcxx/src/experimental/memory_resource.cpp
+++ libcxx/src/experimental/memory_resource.cpp
@@ -76,9 +76,9 @@
   ~ResourceInitHelper() {}
 };
 
-# 79 "memory_resource.cpp" 1 3
-_LIBCPP_SAFE_STATIC ResourceInitHelper res_init _LIBCPP_INIT_PRIORITY_MAX;
-# 81 "memory_resource.cpp" 2
+// Pretend we're inside a system header so the compiler doesn't flag the use of the init_priority
+// attribute with a value that's reserved for the implementation (we're the implementation).
+#include "memory_resource_init_helper.h"
 
 } // end namespace
 
Index: libcxx/src/chrono_system_time_init.h
===================================================================
--- /dev/null
+++ libcxx/src/chrono_system_time_init.h
@@ -0,0 +1,2 @@
+#pragma GCC system_header
+GetSystemTimeInit GetSystemTimeAsFileTimeFunc _LIBCPP_INIT_PRIORITY_MAX;
\ No newline at end of file
Index: libcxx/src/chrono.cpp
===================================================================
--- libcxx/src/chrono.cpp
+++ libcxx/src/chrono.cpp
@@ -80,9 +80,9 @@
   GetSystemTimeAsFileTimePtr fp;
 };
 
-# 83 "chrono.cpp" 1 3
-GetSystemTimeInit GetSystemTimeAsFileTimeFunc _LIBCPP_INIT_PRIORITY_MAX;
-# 85 "chrono.cpp" 2
+// Pretend we're inside a system header so the compiler doesn't flag the use of the init_priority
+// attribute with a value that's reserved for the implementation (we're the implementation).
+#include "chrono_system_time_init.h"
 } // namespace
 
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115334.393977.patch
Type: text/x-patch
Size: 3162 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211213/28ce272f/attachment-0001.bin>


More information about the libcxx-commits mailing list