Update UNSAFE_BUFFER macros to match chromium/src/base

Now that these have stabilized, use the base definitions instead of
our own.

Change-Id: I3c990b79c6c089bc95677735c13e8201a1d34f02
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/117151
Reviewed-by: Thomas Sepez <tsepez@google.com>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/compiler_specific.h b/core/fxcrt/compiler_specific.h
index 8452524..00b84af 100644
--- a/core/fxcrt/compiler_specific.h
+++ b/core/fxcrt/compiler_specific.h
@@ -77,18 +77,27 @@
 #define GSL_POINTER
 #endif
 
-// TODO(tsepez): Replace with actual code from base/.
 #if defined(__clang__) && HAS_ATTRIBUTE(unsafe_buffer_usage)
 #define UNSAFE_BUFFER_USAGE [[clang::unsafe_buffer_usage]]
-#define UNSAFE_PRAGMA_BEGIN _Pragma("clang unsafe_buffer_usage begin")
-#define UNSAFE_PRAGMA_END _Pragma("clang unsafe_buffer_usage end")
 #else
 #define UNSAFE_BUFFER_USAGE
-#define UNSAFE_PRAGMA_BEGIN
-#define UNSAFE_PRAGMA_END
 #endif
-#define UNSAFE_BUFFERS(...) UNSAFE_PRAGMA_BEGIN __VA_ARGS__ UNSAFE_PRAGMA_END
-#define UNSAFE_HEADERS_BEGIN() UNSAFE_PRAGMA_BEGIN
-#define UNSAFE_HEADERS_END() UNSAFE_PRAGMA_END
+
+#if defined(__clang__)
+// clang-format off
+// Formatting is off so that we can put each _Pragma on its own line, as
+// recommended by the gcc docs.
+#define UNSAFE_BUFFERS(...)                  \
+  _Pragma("clang unsafe_buffer_usage begin") \
+  __VA_ARGS__                                \
+  _Pragma("clang unsafe_buffer_usage end")
+// clang-format on
+#define UNSAFE_BUFFERS_INCLUDE_BEGIN _Pragma("clang unsafe_buffer_usage begin")
+#define UNSAFE_BUFFERS_INCLUDE_END _Pragma("clang unsafe_buffer_usage end")
+#else
+#define UNSAFE_BUFFERS(...) __VA_ARGS__
+#define UNSAFE_BUFFERS_INCLUDE_BEGIN
+#define UNSAFE_BUFFERS_INCLUDE_END
+#endif
 
 #endif  // CORE_FXCRT_COMPILER_SPECIFIC_H_
diff --git a/core/fxcrt/fx_memory_pa.cpp b/core/fxcrt/fx_memory_pa.cpp
index 82df893..6241f83 100644
--- a/core/fxcrt/fx_memory_pa.cpp
+++ b/core/fxcrt/fx_memory_pa.cpp
@@ -10,9 +10,9 @@
 #include "core/fxcrt/fx_safe_types.h"
 
 #if defined(PDF_USE_PARTITION_ALLOC)
-UNSAFE_HEADERS_BEGIN()
+UNSAFE_BUFFERS_INCLUDE_BEGIN
 #include "partition_alloc/partition_alloc.h"
-UNSAFE_HEADERS_END()
+UNSAFE_BUFFERS_INCLUDE_END
 #else
 #error "File compiled under wrong build option."
 #endif
diff --git a/core/fxcrt/span.h b/core/fxcrt/span.h
index 2e51cd2..130af03 100644
--- a/core/fxcrt/span.h
+++ b/core/fxcrt/span.h
@@ -21,9 +21,9 @@
 // with the fully annotated one that is being prepared in base/.
 
 #if defined(PDF_USE_PARTITION_ALLOC)
-UNSAFE_HEADERS_BEGIN()
+UNSAFE_BUFFERS_INCLUDE_BEGIN
 #include "partition_alloc/pointers/raw_ptr.h"
-UNSAFE_HEADERS_END()
+UNSAFE_BUFFERS_INCLUDE_END
 #else
 #include "core/fxcrt/unowned_ptr_exclusion.h"
 #endif
diff --git a/core/fxcrt/unowned_ptr.h b/core/fxcrt/unowned_ptr.h
index fba0e25..4e77c5f 100644
--- a/core/fxcrt/unowned_ptr.h
+++ b/core/fxcrt/unowned_ptr.h
@@ -42,10 +42,10 @@
 #include "core/fxcrt/compiler_specific.h"
 
 #if defined(PDF_USE_PARTITION_ALLOC)
-UNSAFE_HEADERS_BEGIN()
+UNSAFE_BUFFERS_INCLUDE_BEGIN
 #include "partition_alloc/partition_alloc_buildflags.h"
 #include "partition_alloc/pointers/raw_ptr.h"
-UNSAFE_HEADERS_END()
+UNSAFE_BUFFERS_INCLUDE_END
 
 #if !BUILDFLAG(USE_PARTITION_ALLOC)
 #error "pdf_use_partition_alloc=true requires use_partition_alloc=true"