[flang-commits] [flang] [flang] Fix -E -dM macro dumping for stdin and .f90 inputs (PR #200144)
via flang-commits
flang-commits at lists.llvm.org
Thu May 28 02:38:18 PDT 2026
https://github.com/ejose02 created https://github.com/llvm/llvm-project/pull/200144
Issue:
flang -E -dM does not consistently print predefined macros for stdin and .f90 inputs, unlike expected behavior.
Root cause:
Flang only initialized predefined macros when preprocessing was implied by -cpp or suffix-based inference (mustBePreprocessed), but not when -dM alone requested macro dumping.
Fix:
Treat -dM as an explicit trigger to initialize macro predefinitions in, and add a stdin regression test for flang -E -dM - < /dev/null.
Fixes #198234
>From c1b99069463ad66150e29707c0bcc82a08f71f44 Mon Sep 17 00:00:00 2001
From: ejose02 <ejose at amd.com>
Date: Thu, 28 May 2026 14:46:30 +0530
Subject: [PATCH] [flang] Fix -E -dM macro dumping for stdin and .f90 inputs
Issue:
flang -E -dM does not consistently print predefined macros for stdin and .f90 inputs, unlike expected behavior.
Root cause:
Flang only initialized predefined macros when preprocessing was implied by -cpp or suffix-based inference (mustBePreprocessed), but not when -dM alone requested macro dumping.
Fix:
Treat -dM as an explicit trigger to initialize macro predefinitions in, and add a stdin regression test for flang -E -dM - < /dev/null.
---
flang/lib/Frontend/FrontendAction.cpp | 1 +
flang/test/Preprocessing/show-macros-stdin.f90 | 10 ++++++++++
2 files changed, 11 insertions(+)
create mode 100644 flang/test/Preprocessing/show-macros-stdin.f90
diff --git a/flang/lib/Frontend/FrontendAction.cpp b/flang/lib/Frontend/FrontendAction.cpp
index 58901c6000380..7d201881cbba7 100644
--- a/flang/lib/Frontend/FrontendAction.cpp
+++ b/flang/lib/Frontend/FrontendAction.cpp
@@ -81,6 +81,7 @@ bool FrontendAction::beginSourceFile(CompilerInstance &ci,
// * the file extension (if the user didn't express any preference)
// to decide whether to include them or not.
if ((invoc.getPreprocessorOpts().macrosFlag == PPMacrosFlag::Include) ||
+ (invoc.getPreprocessorOpts().showMacros) ||
(invoc.getPreprocessorOpts().macrosFlag == PPMacrosFlag::Unknown &&
getCurrentInput().getMustBePreprocessed())) {
invoc.setDefaultPredefinitions();
diff --git a/flang/test/Preprocessing/show-macros-stdin.f90 b/flang/test/Preprocessing/show-macros-stdin.f90
new file mode 100644
index 0000000000000..b14bd88a4630e
--- /dev/null
+++ b/flang/test/Preprocessing/show-macros-stdin.f90
@@ -0,0 +1,10 @@
+! RUN: %flang -E -dM - < /dev/null | FileCheck %s
+
+! Check that dumping macros from stdin still emits default definitions.
+
+! CHECK: #define __DATE__
+! CHECK: #define __TIME__
+! CHECK: #define __flang__
+! CHECK: #define __flang_major__
+! CHECK: #define __flang_minor__
+! CHECK: #define __flang_patchlevel__
More information about the flang-commits
mailing list