get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/2224046/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2224046,
    "url": "http://patchwork.ozlabs.org/api/patches/2224046/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/gcc/patch/20260416171656.2901675-1-albert@tugraz.at/",
    "project": {
        "id": 17,
        "url": "http://patchwork.ozlabs.org/api/projects/17/?format=api",
        "name": "GNU Compiler Collection",
        "link_name": "gcc",
        "list_id": "gcc-patches.gcc.gnu.org",
        "list_email": "gcc-patches@gcc.gnu.org",
        "web_url": null,
        "scm_url": null,
        "webscm_url": null,
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<20260416171656.2901675-1-albert@tugraz.at>",
    "list_archive_url": null,
    "date": "2026-04-16T17:16:56",
    "name": "fortran: Enable target preprocessor macros with -cpp [PR42954]",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "86f63fb1415cda7ed7bc0cadc650bc822aa86595",
    "submitter": {
        "id": 92019,
        "url": "http://patchwork.ozlabs.org/api/people/92019/?format=api",
        "name": "Albert, Christopher",
        "email": "albert@tugraz.at"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/gcc/patch/20260416171656.2901675-1-albert@tugraz.at/mbox/",
    "series": [
        {
            "id": 500187,
            "url": "http://patchwork.ozlabs.org/api/series/500187/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/gcc/list/?series=500187",
            "date": "2026-04-16T17:16:56",
            "name": "fortran: Enable target preprocessor macros with -cpp [PR42954]",
            "version": 1,
            "mbox": "http://patchwork.ozlabs.org/series/500187/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/2224046/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2224046/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>",
        "X-Original-To": [
            "incoming@patchwork.ozlabs.org",
            "gcc-patches@gcc.gnu.org"
        ],
        "Delivered-To": [
            "patchwork-incoming@legolas.ozlabs.org",
            "gcc-patches@gcc.gnu.org"
        ],
        "Authentication-Results": [
            "legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=tugraz.at header.i=@tugraz.at header.a=rsa-sha256\n header.s=mailrelay header.b=BUoSFdcc;\n\tdkim-atps=neutral",
            "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=38.145.34.32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)",
            "sourceware.org;\n\tdkim=pass (1024-bit key,\n unprotected) header.d=tugraz.at header.i=@tugraz.at header.a=rsa-sha256\n header.s=mailrelay header.b=BUoSFdcc",
            "sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=tugraz.at",
            "sourceware.org; spf=pass smtp.mailfrom=tugraz.at",
            "server2.sourceware.org;\n arc=none smtp.remote-ip=129.27.2.202"
        ],
        "Received": [
            "from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fxPpd4K8Rz1yD3\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 17 Apr 2026 03:17:44 +1000 (AEST)",
            "from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 4AE414C900C3\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 16 Apr 2026 17:17:42 +0000 (GMT)",
            "from mailrelay.tugraz.at (mailrelay.tugraz.at [129.27.2.202])\n by sourceware.org (Postfix) with ESMTPS id 38D894BA902B;\n Thu, 16 Apr 2026 17:17:12 +0000 (GMT)",
            "from mailuefterl.fritz.box (unknown [185.68.250.147])\n by mailrelay.tugraz.at (Postfix) with ESMTPSA id 4fxPnj25ZVz9rx6;\n Thu, 16 Apr 2026 19:16:56 +0200 (CEST)"
        ],
        "DKIM-Filter": [
            "OpenDKIM Filter v2.11.0 sourceware.org 4AE414C900C3",
            "OpenDKIM Filter v2.11.0 sourceware.org 38D894BA902B"
        ],
        "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org 38D894BA902B",
        "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org 38D894BA902B",
        "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776359832; cv=none;\n b=pA/hibbR8SGpes+PnNjr0ceIsFLfZSAny+ldoJNaDAJFoIX0h/t2YWoCW9x+hJtZzEExIzahJHnsGtttO6LYRAJjOfQjLwlxF2zqHER2eIBKuRtb0muD1UNdGHmR/b8NypqQDeOAvLW+wrJwnc61dxfrvatMcpFf3wdvkjLMTLw=",
        "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776359832; c=relaxed/simple;\n bh=JvpIg+X4kXKqx2p2wH69sCTNaYkslxzgw4dd72ks2tg=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=DcfOuNTlFtUIY2HvktRUiWuv9msCLWLYKVCKo94L53ZpjqcwRPceydnX+YvSrLWZvdVeEif8MHZQU3JTCC/Qr5Se0MHesmJKasNL2pSUaaLiEKd/46o0YsTdBkGqjNvVKG5R5H988VKrsgGRXIJEILncjuKx8YPuIRvFfJ33Nww=",
        "ARC-Authentication-Results": "i=1; server2.sourceware.org",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=tugraz.at;\n s=mailrelay; t=1776359817;\n bh=8p36ZTUL2be/G1KBmJTm7ThuSsmNxVjlfb865EFGqiQ=;\n h=From:To:Cc:Subject:Date;\n b=BUoSFdcck3WohXCAVWK8ZBi2XxUl8WtNxaI7ywgL9V8LERJs51kFcECeMR+dkhQjw\n seD2LgOqil7Lr9hUFAc2HtMfAh78qjqI72pgx8G8/uO0i1MJpZuAgasyO1dlVmdnx5\n sgKgQXPsii9lCXq9wKolrSWkmqV17LHaJ/MjGFFc=",
        "From": "Christopher Albert <albert@tugraz.at>",
        "To": "gcc-patches@gcc.gnu.org",
        "Cc": "fortran@gcc.gnu.org, Christopher Albert <albert@tugraz.at>,\n Kai Tietz <ktietz@gcc.gnu.org>",
        "Subject": "[PATCH] fortran: Enable target preprocessor macros with -cpp\n [PR42954]",
        "Date": "Thu, 16 Apr 2026 19:16:56 +0200",
        "Message-ID": "<20260416171656.2901675-1-albert@tugraz.at>",
        "X-Mailer": "git-send-email 2.53.0",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-TUG-Backscatter-control": "M8C9d6vb7ybI0LFLVdluXg",
        "X-Scanned-By": "MIMEDefang 2.74 on 129.27.10.117",
        "X-BeenThere": "gcc-patches@gcc.gnu.org",
        "X-Mailman-Version": "2.1.30",
        "Precedence": "list",
        "List-Id": "Gcc-patches mailing list <gcc-patches.gcc.gnu.org>",
        "List-Unsubscribe": "<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>",
        "List-Archive": "<https://gcc.gnu.org/pipermail/gcc-patches/>",
        "List-Post": "<mailto:gcc-patches@gcc.gnu.org>",
        "List-Help": "<mailto:gcc-patches-request@gcc.gnu.org?subject=help>",
        "List-Subscribe": "<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>",
        "Errors-To": "gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"
    },
    "content": "The Fortran preprocessor has never defined target-specific macros such as\n__linux__, __unix__, __ELF__, __x86_64__, or __amd64__ that the C\npreprocessor provides.  This was caused by the TARGET_OS_CPP_BUILTINS,\nTARGET_OBJFMT_CPP_BUILTINS, and TARGET_CPU_CPP_BUILTINS hooks being\ndisabled since 2008 (marked as \"Pandora's Box\") because several target\nconfig headers use C-family-only functions.\n\nFix by providing Fortran-compatible local helpers for\nbuiltin_define_std, builtin_define_with_value, and\nbuiltin_define_with_int_value (which in the C frontend live in\nc-family/c-cppbuiltin.cc and use the C-family-only globals parse_in\nand flag_iso), plus wrapper macros for c_dialect_cxx, flag_iso, and\nother C-family identifiers referenced by target config headers.  This\nallows TARGET_OS_CPP_BUILTINS and TARGET_OBJFMT_CPP_BUILTINS to\nexecute in the Fortran frontend.\n\nUnlike the C frontend default (flag_iso=0, GNU extensions mode), the\nFortran wrapper sets flag_iso=1 to suppress user-namespace macros like\nbare \"unix\" and \"linux\" that would conflict with Fortran identifiers.\nOnly the reserved-namespace forms (__unix__, __linux__, etc.) are\ndefined.  Fortran has no -std=cNN equivalent to control this, so the\nconservative choice avoids silent identifier replacement.\n\nFor TARGET_CPU_CPP_BUILTINS, which on most architectures expands to a\nfunction in a C-family-only object file (e.g., ix86_target_macros in\ni386-c.cc), provide an x86 implementation directly in fortran/cpp.cc\nthat covers architecture identification and float-size macros.\nISA feature macros (__SSE__, __AVX__, etc.) are not included; if\nneeded, they could be factored out of i386-c.cc into a shared object.\n\nRemove the dead __attribute__((target(...))) block from\ngfortran.dg/gomp/declare-variant-10.f90: it was guarded by\n#if defined(__x86_64__) which was previously always false because\ngfortran never defined these macros, and gfortran does not support\nC-style __attribute__ syntax.\n\nCo-authored-by: Kai Tietz <ktietz@gcc.gnu.org>\n\n\tPR fortran/42954\n\ngcc/fortran/ChangeLog:\n\n\t* cpp.cc (gfc_builtin_define_std): New helper mirroring\n\tbuiltin_define_std from c-family/c-cppbuiltin.cc.\n\t(gfc_builtin_define_with_value): New helper mirroring\n\tbuiltin_define_with_value from c-family/c-cppbuiltin.cc.\n\t(gfc_define_ix86_target_macros): New function providing x86 CPU\n\tidentification macros for the Fortran preprocessor.\n\t(gfc_darwin_cpp_builtins): New function providing Darwin platform\n\tmacros.\n\t(cpp_define_builtins): Remove Pandora's Box FIXME.  Add wrapper\n\tmacros for C-family functions and variables used in target config\n\theaders.  Set flag_iso=1 to suppress bare-name macros.  Enable\n\tTARGET_OS_CPP_BUILTINS and TARGET_OBJFMT_CPP_BUILTINS.  Call\n\tgfc_define_ix86_target_macros on x86 targets.\n\ngcc/testsuite/ChangeLog:\n\n\t* gfortran.dg/gomp/declare-variant-10.f90: Remove dead\n\t__attribute__((target)) block that is now exposed by newly\n\tdefined target macros.\n\t* gfortran.dg/pr42954-linux.f90: New test.\n\t* gfortran.dg/pr42954-x86.f90: New test.\n\nSigned-off-by: Christopher Albert <albert@tugraz.at>\n---\n gcc/fortran/cpp.cc                            | 178 ++++++++++++++++--\n .../gfortran.dg/gomp/declare-variant-10.f90   |   3 -\n gcc/testsuite/gfortran.dg/pr42954-linux.f90   |  24 +++\n gcc/testsuite/gfortran.dg/pr42954-x86.f90     |  10 +\n 4 files changed, 194 insertions(+), 21 deletions(-)\n create mode 100644 gcc/testsuite/gfortran.dg/pr42954-linux.f90\n create mode 100644 gcc/testsuite/gfortran.dg/pr42954-x86.f90",
    "diff": "diff --git a/gcc/fortran/cpp.cc b/gcc/fortran/cpp.cc\nindex 6b5f136e4f3..ada1bc1a211 100644\n--- a/gcc/fortran/cpp.cc\n+++ b/gcc/fortran/cpp.cc\n@@ -157,6 +157,126 @@ void pp_dir_change (cpp_reader *, const char *);\n static int dump_macro (cpp_reader *, cpp_hashnode *, void *);\n static void dump_queued_macros (cpp_reader *);\n \n+/* Fortran-local helpers that mirror builtin_define_std,\n+   builtin_define_with_value, and builtin_define_with_int_value from\n+   c-family/c-cppbuiltin.cc.  Those functions use the C-family-only\n+   globals parse_in and flag_iso, so they cannot be called directly\n+   from the Fortran frontend.  */\n+\n+/* Given \"unix\", define __unix, __unix__, and (if DEFINE_USER) unix.  */\n+\n+static void\n+gfc_builtin_define_std (cpp_reader *pfile, const char *macro,\n+\t\t\tbool define_user)\n+{\n+  size_t len = strlen (macro);\n+  char *buff = (char *) alloca (len + 5);\n+  char *p = buff + 2;\n+  char *q = p + len;\n+\n+  memcpy (p, macro, len + 1);\n+  if (!(*p == '_' && (p[1] == '_' || ISUPPER (p[1]))))\n+    {\n+      if (*p != '_')\n+\t*--p = '_';\n+      if (p[1] != '_')\n+\t*--p = '_';\n+    }\n+  cpp_define (pfile, p);\n+\n+  if (p != buff + 2)\n+    {\n+      if (q[-1] != '_')\n+\t*q++ = '_';\n+      if (q[-2] != '_')\n+\t*q++ = '_';\n+      *q = '\\0';\n+      cpp_define (pfile, p);\n+      if (define_user)\n+\tcpp_define (pfile, macro);\n+    }\n+}\n+\n+/* Define MACRO to EXPANSION; if IS_STR, quote the expansion.  */\n+\n+static void\n+gfc_builtin_define_with_value (cpp_reader *pfile, const char *macro,\n+\t\t\t       const char *expansion, int is_str)\n+{\n+  size_t mlen = strlen (macro);\n+  size_t elen = strlen (expansion);\n+  char *buf = (char *) alloca (mlen + elen + 4);\n+  if (is_str)\n+    sprintf (buf, \"%s=\\\"%s\\\"\", macro, expansion);\n+  else\n+    sprintf (buf, \"%s=%s\", macro, expansion);\n+  cpp_define (pfile, buf);\n+}\n+\n+/* Provide x86 CPU identification macros for the Fortran preprocessor.\n+   TARGET_CPU_CPP_BUILTINS() cannot be called directly because it expands\n+   to ix86_target_macros() in i386-c.cc, which is only linked into\n+   C-family frontends.  This covers architecture identification and\n+   float-size macros.  ISA feature macros (__SSE__, __AVX__, etc.) and\n+   arch/tune macros (__znver4__, __skylake__, etc.) from\n+   ix86_target_macros_internal() are not included; if needed, they could\n+   be factored out of i386-c.cc into a shared object.  */\n+\n+#ifdef TARGET_80387\n+static void\n+gfc_define_ix86_target_macros (cpp_reader *pfile)\n+{\n+  if (TARGET_64BIT)\n+    {\n+      cpp_assert (pfile, \"cpu=x86_64\");\n+      cpp_assert (pfile, \"machine=x86_64\");\n+      cpp_define (pfile, \"__amd64\");\n+      cpp_define (pfile, \"__amd64__\");\n+      cpp_define (pfile, \"__x86_64\");\n+      cpp_define (pfile, \"__x86_64__\");\n+      if (TARGET_X32)\n+\t{\n+\t  cpp_define (pfile, \"_ILP32\");\n+\t  cpp_define (pfile, \"__ILP32__\");\n+\t}\n+    }\n+  else\n+    {\n+      cpp_assert (pfile, \"cpu=i386\");\n+      cpp_assert (pfile, \"machine=i386\");\n+      gfc_builtin_define_std (pfile, \"i386\", false);\n+      cpp_define (pfile, \"_ILP32\");\n+      cpp_define (pfile, \"__ILP32__\");\n+    }\n+\n+  if (!TARGET_80387)\n+    cpp_define (pfile, \"_SOFT_FLOAT\");\n+\n+  if (TARGET_LONG_DOUBLE_64)\n+    cpp_define (pfile, \"__LONG_DOUBLE_64__\");\n+\n+  if (TARGET_LONG_DOUBLE_128)\n+    cpp_define (pfile, \"__LONG_DOUBLE_128__\");\n+\n+  cpp_define_formatted (pfile, \"__SIZEOF_FLOAT80__=%d\",\n+\t\t\tGET_MODE_SIZE (XFmode));\n+  cpp_define (pfile, \"__SIZEOF_FLOAT128__=16\");\n+}\n+#endif\n+\n+/* Provide essential Darwin platform macros for the Fortran preprocessor.\n+   The full darwin_cpp_builtins() in darwin-c.cc also defines\n+   __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ and\n+   __CONSTANT_CFSTRINGS__, but those depend on functions only linked\n+   into C-family frontends.  */\n+\n+static void ATTRIBUTE_UNUSED\n+gfc_darwin_cpp_builtins (cpp_reader *pfile)\n+{\n+  cpp_define (pfile, \"__MACH__\");\n+  cpp_define (pfile, \"__APPLE__\");\n+  gfc_builtin_define_with_value (pfile, \"__APPLE_CC__\", \"1\", false);\n+}\n \n static void\n cpp_define_builtins (cpp_reader *pfile)\n@@ -177,33 +297,55 @@ cpp_define_builtins (cpp_reader *pfile)\n   if (flag_openmp)\n     cpp_define (pfile, \"_OPENMP=202111\");\n \n-  /* The defines below are necessary for the TARGET_* macros.\n-\n-     FIXME:  Note that builtin_define_std() actually is a function\n-     in c-cppbuiltin.cc which uses flags undefined for Fortran.\n-     Let's skip this for now. If needed, one needs to look into it\n-     once more.  */\n+  /* Wrapper macros for C-family identifiers used in target config\n+     headers.  These allow TARGET_OS_CPP_BUILTINS and\n+     TARGET_OBJFMT_CPP_BUILTINS to compile in the Fortran frontend.  */\n \n # define builtin_define(TXT) cpp_define (pfile, TXT)\n-# define builtin_define_std(TXT)\n+# define builtin_define_std(TXT) gfc_builtin_define_std (pfile, TXT, !flag_iso)\n+# define builtin_define_with_value(MACRO, EXPANSION, IS_STR) \\\n+  gfc_builtin_define_with_value (pfile, MACRO, EXPANSION, IS_STR)\n+# define builtin_define_with_int_value(MACRO, VALUE) \\\n+  cpp_define_formatted (pfile, \"%s=\" HOST_WIDE_INT_PRINT_DEC, \\\n+\t\t\tMACRO, (HOST_WIDE_INT) (VALUE))\n # define builtin_assert(TXT) cpp_assert (pfile, TXT)\n+# define c_dialect_cxx() 0\n+# define c_dialect_objc() 0\n+# define preprocessing_asm_p() 0\n+# define preprocessing_trad_p() 0\n+  /* Fortran has no -std=cNN flag to control this.  Set to 1 (ISO mode)\n+     so that builtin_define_std() only defines reserved-namespace macros\n+     like __unix__ and __linux__, not bare \"unix\" or \"linux\" which are\n+     valid Fortran identifiers and would cause silent replacement.  */\n+# define flag_iso 1\n+# define flag_isoc94 0\n+# define flag_isoc99 0\n+# define flag_isoc11 0\n+# define flag_isoc23 0\n+# define darwin_cpp_builtins(PFILE) gfc_darwin_cpp_builtins (PFILE)\n \n-  /* FIXME: Pandora's Box\n-    Using the macros below results in multiple breakages:\n-     - mingw will fail to compile this file as dependent macros\n-       assume to be used in c-cppbuiltin.cc only. Further, they use\n-       flags only valid/defined in C (same as noted above).\n-       [config/i386/mingw32.h, config/i386/cygming.h]\n-     - other platforms (not as popular) break similarly\n-       [grep for 'builtin_define_with_int_value' in gcc/config/]\n-\n-  TARGET_CPU_CPP_BUILTINS ();\n   TARGET_OS_CPP_BUILTINS ();\n-  TARGET_OBJFMT_CPP_BUILTINS (); */\n+  TARGET_OBJFMT_CPP_BUILTINS ();\n+\n+#ifdef TARGET_80387\n+  gfc_define_ix86_target_macros (pfile);\n+#endif\n \n #undef builtin_define\n #undef builtin_define_std\n+#undef builtin_define_with_value\n+#undef builtin_define_with_int_value\n #undef builtin_assert\n+#undef c_dialect_cxx\n+#undef c_dialect_objc\n+#undef preprocessing_asm_p\n+#undef preprocessing_trad_p\n+#undef flag_iso\n+#undef flag_isoc94\n+#undef flag_isoc99\n+#undef flag_isoc11\n+#undef flag_isoc23\n+#undef darwin_cpp_builtins\n }\n \n bool\ndiff --git a/gcc/testsuite/gfortran.dg/gomp/declare-variant-10.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-variant-10.f90\nindex 0e0ab518010..115195e1194 100644\n--- a/gcc/testsuite/gfortran.dg/gomp/declare-variant-10.f90\n+++ b/gcc/testsuite/gfortran.dg/gomp/declare-variant-10.f90\n@@ -64,9 +64,6 @@ contains\n     call f18 ()\t  ! { dg-final { scan-tree-dump-times \"f18 \\\\\\(\\\\\\);\" 1 \"gimple\" } } */\n   end subroutine\n \n-#if defined(__i386__) || defined(__x86_64__)\n-  __attribute__((target (\"avx512f,avx512bw\")))\n-#endif\n   subroutine test2 ()\n     !$omp target\n       call f04 () ! { dg-final { scan-tree-dump-times \"f03 \\\\\\(\\\\\\);\" 1 \"gimple\" { target { { i?86-*-* x86_64-*-* } && { ! ilp32 } } } } }\ndiff --git a/gcc/testsuite/gfortran.dg/pr42954-linux.f90 b/gcc/testsuite/gfortran.dg/pr42954-linux.f90\nnew file mode 100644\nindex 00000000000..bd5efe7a237\n--- /dev/null\n+++ b/gcc/testsuite/gfortran.dg/pr42954-linux.f90\n@@ -0,0 +1,24 @@\n+! { dg-do preprocess { target *-*-linux* } }\n+! { dg-options \"-cpp\" }\n+!\n+! PR fortran/42954 - target macros missing in gfortran -cpp\n+\n+#ifndef __linux__\n+# error __linux__ not defined\n+#endif\n+\n+#ifndef __linux\n+# error __linux not defined\n+#endif\n+\n+#ifndef __unix__\n+# error __unix__ not defined\n+#endif\n+\n+#ifndef __unix\n+# error __unix not defined\n+#endif\n+\n+#ifndef __ELF__\n+# error __ELF__ not defined\n+#endif\ndiff --git a/gcc/testsuite/gfortran.dg/pr42954-x86.f90 b/gcc/testsuite/gfortran.dg/pr42954-x86.f90\nnew file mode 100644\nindex 00000000000..0a3b7eac8a2\n--- /dev/null\n+++ b/gcc/testsuite/gfortran.dg/pr42954-x86.f90\n@@ -0,0 +1,10 @@\n+! { dg-do preprocess { target { i?86-*-* x86_64-*-* } } }\n+! { dg-options \"-cpp\" }\n+!\n+! PR fortran/42954 - target macros missing in gfortran -cpp\n+\n+#if !defined(__i386__) && !defined(__i386) \\\n+    && !defined(__x86_64__) && !defined(__x86_64) \\\n+    && !defined(__amd64__) && !defined(__amd64)\n+# error x86 target macros not defined\n+#endif\n",
    "prefixes": []
}