Put plugin-specific logic in pdfium_common_config.

Define a symbol indicating it is present, and then use it to
condition plugin-specific definitions so as to avoid breaking
(future) builds against off-the-shelf clang compilers, as
plugin-only #pragma syntax may be added.

Change-Id: Ia485f9ed56705f2bf9506c9ba868b6b4515aca52
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/118273
Reviewed-by: Thomas Sepez <tsepez@google.com>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/BUILD.gn b/BUILD.gn
index 72a6944..5ac06bf 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -228,6 +228,58 @@
       "-Wno-return-type",
     ]
   }
+
+  if (clang_use_chrome_plugins) {
+    defines += [ "PDF_USE_CHROME_PLUGINS" ]
+
+    # Catch misuse of C-style pointers.
+    # TODO(crbug.com/1320670): enable for non-debug builds once this stops
+    # interfering with code generation.
+    # TODO(tsepez): enable for windows, too.
+    if (is_debug && !is_win) {
+      cflags += [
+        "-Xclang",
+        "-plugin-arg-find-bad-constructs",
+        "-Xclang",
+        "check-raw-ptr-fields",
+
+        "-Xclang",
+        "-plugin-arg-find-bad-constructs",
+        "-Xclang",
+        "raw-ptr-exclude-path=public",
+
+        "-Xclang",
+        "-plugin-arg-find-bad-constructs",
+        "-Xclang",
+        "raw-ptr-exclude-path=test",
+
+        # TODO(tsepez): enforce raw_ref<> as well.
+        # "-Xclang",
+        # "-plugin-arg-find-bad-constructs",
+        # "-Xclang",
+        # "check-raw-ref-fields",
+      ]
+      defines += [ "PDF_ENABLE_UNOWNED_PTR_EXCLUSION" ]
+    }
+
+    # Catch misuse of cppgc in XFA.
+    if (pdf_enable_xfa) {
+      cflags += [
+        "-Xclang",
+        "-add-plugin",
+        "-Xclang",
+        "blink-gc-plugin",
+      ]
+
+      # Disable GC plugin forbidding off-heap collections of GCed:
+      cflags += [
+        "-Xclang",
+        "-plugin-arg-blink-gc-plugin",
+        "-Xclang",
+        "disable-off-heap-collections-of-gced-check",
+      ]
+    }
+  }
 }
 
 config("pdfium_implementation_config") {
@@ -282,64 +334,9 @@
   }
 }
 
-config("pdfium_plugin_config") {
-  cflags = []
-  defines = []
-  if (clang_use_chrome_plugins) {
-    # Catch misuse of C-style pointers.
-    # TODO(crbug.com/1320670): enable for non-debug builds once this stops
-    # interfering with code generation.
-    # TODO(tsepez): enable for windows, too.
-    if (is_debug && !is_win) {
-      cflags += [
-        "-Xclang",
-        "-plugin-arg-find-bad-constructs",
-        "-Xclang",
-        "check-raw-ptr-fields",
-
-        "-Xclang",
-        "-plugin-arg-find-bad-constructs",
-        "-Xclang",
-        "raw-ptr-exclude-path=public",
-
-        "-Xclang",
-        "-plugin-arg-find-bad-constructs",
-        "-Xclang",
-        "raw-ptr-exclude-path=test",
-
-        # TODO(tsepez): enforce raw_ref<> as well.
-        # "-Xclang",
-        # "-plugin-arg-find-bad-constructs",
-        # "-Xclang",
-        # "check-raw-ref-fields",
-      ]
-      defines += [ "PDF_ENABLE_UNOWNED_PTR_EXCLUSION" ]
-    }
-
-    # Catch misuse of cppgc in XFA.
-    if (pdf_enable_xfa) {
-      cflags += [
-        "-Xclang",
-        "-add-plugin",
-        "-Xclang",
-        "blink-gc-plugin",
-      ]
-
-      # Disable GC plugin forbidding off-heap collections of GCed:
-      cflags += [
-        "-Xclang",
-        "-plugin-arg-blink-gc-plugin",
-        "-Xclang",
-        "disable-off-heap-collections-of-gced-check",
-      ]
-    }
-  }
-}
-
 config("pdfium_strict_config") {
   configs = [
     ":pdfium_core_config",
-    ":pdfium_plugin_config",
     "//build/config/compiler:wexit_time_destructors",
     "//build/config/compiler:wglobal_constructors",
   ]
diff --git a/core/fxcrt/compiler_specific.h b/core/fxcrt/compiler_specific.h
index a2d0b68..eac87b0 100644
--- a/core/fxcrt/compiler_specific.h
+++ b/core/fxcrt/compiler_specific.h
@@ -86,7 +86,7 @@
 // clang-format off
 // Formatting is off so that we can put each _Pragma on its own line, as
 // recommended by the gcc docs.
-#if defined(__clang__)
+#if defined(PDF_USE_CHROME_PLUGINS)
 #define UNSAFE_BUFFERS(...)                  \
   _Pragma("clang unsafe_buffer_usage begin") \
   __VA_ARGS__                                \