[flang-commits] [flang] [flang] Accept C-style comments in label fields (PR #207012)

Eugene Epshteyn via flang-commits flang-commits at lists.llvm.org
Thu Sep 17 15:46:01 PDT 2026


================
@@ -83,13 +83,21 @@ bool FrontendAction::beginSourceFile(CompilerInstance &ci,
   //  * `-cpp/-nocpp`, or
   //  * 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) ||
+  bool includeMacros =
+      (invoc.getPreprocessorOpts().macrosFlag == PPMacrosFlag::Include) ||
       (invoc.getPreprocessorOpts().showMacros) ||
       (invoc.getPreprocessorOpts().macrosFlag == PPMacrosFlag::Unknown &&
-       getCurrentInput().getMustBePreprocessed())) {
+       getCurrentInput().getMustBePreprocessed());
+  if (includeMacros) {
     invoc.setDefaultPredefinitions();
     invoc.collectMacroDefinitions();
   }
+  // Preprocessing is enabled if macros are included or if `-E` is specified
+  // and `-nocpp` is not.
+  invoc.getFortranOpts().preprocessingEnabled =
----------------
eugeneepshteyn wrote:

(Question from AI agent)

Since plain `-E` now also sets `preprocessingEnabled`, the driver's `-save-temps` pipeline (which runs a separate `-E` stage) accepts fixed-form input that a direct compile rejects:

```console
$ printf '/*c*/ print *, /* comment */ "hello"\n/*d*/+, "world"\n      end\n' > w.f
$ flang -S w.f
error: Could not scan w.f
w.f:1:1: error: Character in fixed-form label field must be a digit
$ flang -save-temps -S w.f && echo accepted
accepted
$ flang -save-temps -nocpp -S w.f
...
error: Could not parse w.i
w.f:2:7: error: expected an executable statement
```

Is that divergence intended? The `-E` stage could inherit the compilation's preprocessing decision instead of unconditionally counting as `PrintPreprocessedInput`, or the asymmetry could be documented/tested as the chosen contract. Either way seems fine — the divergence errs toward acceptance and only affects the extension shapes — but it's worth deciding explicitly.


https://github.com/llvm/llvm-project/pull/207012


More information about the flang-commits mailing list