Introduce UNSAFE_BUFFERS() macro to PDFium.
Introduce the macro but do not use it yet as we continue to discuss
how to document safe usage.
Split from https://pdfium-review.googlesource.com/c/pdfium/+/116070
Derived from https://crrev.com/1255055
Change-Id: Iddfe732072f27b0c4e97781a25b52ec5f05664c4
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/116170
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Thomas Sepez <tsepez@google.com>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/BUILD.gn b/BUILD.gn
index b4815b7..7be7cc9 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -343,6 +343,13 @@
]
}
+config("pdfium_nounsafe_buffer_usage_config") {
+ cflags = []
+ if (is_clang) {
+ cflags += [ "-Wunsafe-buffer-usage" ]
+ }
+}
+
config("pdfium_noshorten_config") {
cflags = []
if (is_clang) {
diff --git a/third_party/base/compiler_specific.h b/third_party/base/compiler_specific.h
index e11deb6..b3ee6d0 100644
--- a/third_party/base/compiler_specific.h
+++ b/third_party/base/compiler_specific.h
@@ -77,4 +77,18 @@
#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
+
#endif // THIRD_PARTY_BASE_COMPILER_SPECIFIC_H_