[PATCH] D96032: [flang][driver] Add support for -fopenmp and -fopenacc

2021-02-04 Thread Faris via Phabricator via cfe-commits
FarisRehman created this revision.
Herald added subscribers: dang, guansong, yaxunl.
Herald added a reviewer: sscalpone.
Herald added a reviewer: awarzynski.
Herald added a reviewer: jansvoboda11.
FarisRehman requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Add support for the following Fortran dialect options:

- -fopenmp
- -fopenacc

Update OpenMP and OpenACC semantics tests to use the new driver if it is built, 
otherwise use f18.
OpenMP tests that include `use omp_lib` or run `test_symbols.sh` have not been 
updated as they require options `-intrinsic-module-directory` and 
`-funparse-with-symbols` which are currently not implemented in the new driver.
Similarly OpenACC tests that run `test_symbols.sh` have not been updated.

This patch also moves semanticsContext to CompilerInvocation and created in 
CompilerInvocation#setSemanticsOpts so that the semantics context can use 
Fortran::parser::Options#features.

Summary of changes:

- Move semanticsContext to CompilerInvocation.h
- Update OpenMP and OpenACC semantics tests that do not rely on 
`-intrinsic-module-directory` and `-funparse-with-symbols` to use %flang


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96032

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInstance.h
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CompilerInstance.cpp
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Semantics/OpenACC/acc-atomic-validity.f90
  flang/test/Semantics/OpenACC/acc-branch.f90
  flang/test/Semantics/OpenACC/acc-cache-validity.f90
  flang/test/Semantics/OpenACC/acc-canonicalization-validity.f90
  flang/test/Semantics/OpenACC/acc-data.f90
  flang/test/Semantics/OpenACC/acc-declare-validity.f90
  flang/test/Semantics/OpenACC/acc-host-data.f90
  flang/test/Semantics/OpenACC/acc-init-validity.f90
  flang/test/Semantics/OpenACC/acc-kernels-loop.f90
  flang/test/Semantics/OpenACC/acc-kernels.f90
  flang/test/Semantics/OpenACC/acc-loop.f90
  flang/test/Semantics/OpenACC/acc-parallel-loop-validity.f90
  flang/test/Semantics/OpenACC/acc-parallel.f90
  flang/test/Semantics/OpenACC/acc-resolve01.f90
  flang/test/Semantics/OpenACC/acc-resolve02.f90
  flang/test/Semantics/OpenACC/acc-routine-validity.f90
  flang/test/Semantics/OpenACC/acc-serial-loop.f90
  flang/test/Semantics/OpenACC/acc-serial.f90
  flang/test/Semantics/OpenACC/acc-set-validity.f90
  flang/test/Semantics/OpenACC/acc-shutdown-validity.f90
  flang/test/Semantics/OpenACC/acc-update-validity.f90
  flang/test/Semantics/OpenACC/acc-wait-validity.f90
  flang/test/Semantics/omp-atomic.f90
  flang/test/Semantics/omp-combined-constructs.f90
  flang/test/Semantics/omp-copyin01.f90
  flang/test/Semantics/omp-copyin02.f90
  flang/test/Semantics/omp-copyin03.f90
  flang/test/Semantics/omp-copyin04.f90
  flang/test/Semantics/omp-copyin05.f90
  flang/test/Semantics/omp-declarative-directive.f90
  flang/test/Semantics/omp-default.f90
  flang/test/Semantics/omp-default02.f90
  flang/test/Semantics/omp-depend01.f90
  flang/test/Semantics/omp-depend02.f90
  flang/test/Semantics/omp-depend03.f90
  flang/test/Semantics/omp-device-constructs.f90
  flang/test/Semantics/omp-do-collapse-positivecases.f90
  flang/test/Semantics/omp-do-collapse.f90
  flang/test/Semantics/omp-do-cycle.f90
  flang/test/Semantics/omp-do-ordered-positivecases.f90
  flang/test/Semantics/omp-do-ordered.f90
  flang/test/Semantics/omp-do-schedule01.f90
  flang/test/Semantics/omp-do-schedule02.f90
  flang/test/Semantics/omp-do01.f90
  flang/test/Semantics/omp-do02.f90
  flang/test/Semantics/omp-do03.f90
  flang/test/Semantics/omp-do04.f90
  flang/test/Semantics/omp-do05.f90
  flang/test/Semantics/omp-do06.f90
  flang/test/Semantics/omp-do07.f90
  flang/test/Semantics/omp-do08.f90
  flang/test/Semantics/omp-do09.f90
  flang/test/Semantics/omp-do10.f90
  flang/test/Semantics/omp-flush01.f90
  flang/test/Semantics/omp-invalid-branch.f90
  flang/test/Semantics/omp-loop-association.f90
  flang/test/Semantics/omp-loop-simd01.f90
  flang/test/Semantics/omp-nested01.f90
  flang/test/Semantics/omp-no-dowhile-in-parallel.f90
  flang/test/Semantics/omp-parallel-private01.f90
  flang/test/Semantics/omp-parallel-private02.f90
  flang/test/Semantics/omp-parallel-private03.f90
  flang/test/Semantics/omp-parallel-private04.f90
  flang/test/Semantics/omp-parallel-shared01.f90
  flang/test/Semantics/omp-parallel-shared02.f90
  flang/test/Semantics/omp-parallel-shared03.f90
  flang/test/Semantics/omp-parallel-shared04.f90
  flang/test/Semantics/omp-parallel01.f90
  flang/test/Semantics/omp-parallel02.f90
  flang/test/Semantics/omp-private01.f90
  

[PATCH] D95460: [flang][driver] Add forced form flags and -ffixed-line-length

2021-02-04 Thread Faris via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3a1513c142f4: [flang][driver] Add forced form flags and 
-ffixed-line-length (authored by FarisRehman).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95460/new/

https://reviews.llvm.org/D95460

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/lib/Driver/ToolChains/Flang.h
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CompilerInstance.cpp
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/Inputs/fixed-form-test.f
  flang/test/Flang-Driver/Inputs/fixed-line-length-test.f
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/fixed-free-flag.f90
  flang/test/Flang-Driver/fixed-line-length.f90

Index: flang/test/Flang-Driver/fixed-line-length.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/fixed-line-length.f90
@@ -0,0 +1,56 @@
+! Ensure argument -ffixed-line-length=n works as expected.
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -E %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=DEFAULTLENGTH
+! RUN: not %flang-new -E -ffixed-line-length=-2 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=NEGATIVELENGTH
+! RUN: not %flang-new -E -ffixed-line-length=3 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
+! RUN: %flang-new -E -ffixed-line-length=none %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang-new -E -ffixed-line-length=0 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang-new -E -ffixed-line-length=13 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=LENGTH13
+
+!
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!
+! RUN: %flang-new -fc1 -E %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=DEFAULTLENGTH
+! RUN: not %flang-new -fc1 -E -ffixed-line-length=-2 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=NEGATIVELENGTH
+! RUN: not %flang-new -fc1 -E -ffixed-line-length=3 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
+! RUN: %flang-new -fc1 -E -ffixed-line-length=none %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang-new -fc1 -E -ffixed-line-length=0 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang-new -fc1 -E -ffixed-line-length=13 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=LENGTH13
+
+!-
+! COMMAND ALIAS -ffixed-line-length-n
+!-
+! RUN: %flang-new -E -ffixed-line-length-13 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=LENGTH13
+! RUN: %flang-new -fc1 -E -ffixed-line-length-13 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=LENGTH13
+
+!-
+! EXPECTED OUTPUT WITH DEFAULT LENGTH
+!-
+! The line should be trimmed to 72 characters when reading based on the default value of fixed line length.
+! DEFAULTLENGTH: program{{(a{58})}}
+
+!-
+! EXPECTED OUTPUT WITH A NEGATIVE LENGTH
+!-
+! NEGATIVELENGTH: invalid value '-2' in 'ffixed-line-length=','value must be 'none' or a non-negative integer'
+
+!-
+! EXPECTED OUTPUT WITH LENGTH LESS THAN 7
+!-
+! INVALIDLENGTH: invalid value '3' in 'ffixed-line-length=','value must be at least seven'
+
+!---
+! EXPECTED OUTPUT WITH UNLIMITED LENGTH
+!---
+! The line should not be trimmed and so 73 characters (including spaces) should be read.
+! UNLIMITEDLENGTH: program{{(a{59})}}
+
+!
+! EXPECTED OUTPUT WITH LENGTH 13
+!
+! LENGTH13: program
Index: flang/test/Flang-Driver/fixed-free-flag.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/fixed-free-flag.f90
@@ -0,0 +1,25 @@
+! Ensure arguments -ffree-form and -ffixed-form work as expected.
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: not %flang-new -fsyntax-only -ffree-form %S/Inputs/fixed-form-test.f  2>&1 | FileCheck %s 

[PATCH] D95460: [flang][driver] Add forced form flags and -ffixed-line-length

2021-02-02 Thread Faris via Phabricator via cfe-commits
FarisRehman updated this revision to Diff 320811.
FarisRehman marked an inline comment as done.
FarisRehman added a comment.

Address review comment

This revision addresses a review comment by @tskeith

Summary of changes:

- Add a new option, ffixed_line_length_EQ, that defines `-ffixed-line-length=`
- Make option ffixed_line_length_VALUE (`-ffixed-line-length-`) an alias of 
ffixed_line_length_EQ, to be consistent with gfortran
- Add flag FlangOnlyOption to ffixed-form, ffree-form and ffixed-line-length


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95460/new/

https://reviews.llvm.org/D95460

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/lib/Driver/ToolChains/Flang.h
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CompilerInstance.cpp
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/Inputs/fixed-form-test.f
  flang/test/Flang-Driver/Inputs/fixed-line-length-test.f
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/fixed-free-flag.f90
  flang/test/Flang-Driver/fixed-line-length.f90

Index: flang/test/Flang-Driver/fixed-line-length.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/fixed-line-length.f90
@@ -0,0 +1,56 @@
+! Ensure argument -ffixed-line-length=n works as expected.
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -E %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=DEFAULTLENGTH
+! RUN: not %flang-new -E -ffixed-line-length=-2 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=NEGATIVELENGTH
+! RUN: not %flang-new -E -ffixed-line-length=3 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
+! RUN: %flang-new -E -ffixed-line-length=none %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang-new -E -ffixed-line-length=0 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang-new -E -ffixed-line-length=13 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=LENGTH13
+
+!
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!
+! RUN: %flang-new -fc1 -E %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=DEFAULTLENGTH
+! RUN: not %flang-new -fc1 -E -ffixed-line-length=-2 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=NEGATIVELENGTH
+! RUN: not %flang-new -fc1 -E -ffixed-line-length=3 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
+! RUN: %flang-new -fc1 -E -ffixed-line-length=none %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang-new -fc1 -E -ffixed-line-length=0 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang-new -fc1 -E -ffixed-line-length=13 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=LENGTH13
+
+!-
+! COMMAND ALIAS -ffixed-line-length-n
+!-
+! RUN: %flang-new -E -ffixed-line-length-13 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=LENGTH13
+! RUN: %flang-new -fc1 -E -ffixed-line-length-13 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=LENGTH13
+
+!-
+! EXPECTED OUTPUT WITH DEFAULT LENGTH
+!-
+! The line should be trimmed to 72 characters when reading based on the default value of fixed line length.
+! DEFAULTLENGTH: program{{(a{58})}}
+
+!-
+! EXPECTED OUTPUT WITH A NEGATIVE LENGTH
+!-
+! NEGATIVELENGTH: invalid value '-2' in 'ffixed-line-length=','value must be 'none' or a non-negative integer'
+
+!-
+! EXPECTED OUTPUT WITH LENGTH LESS THAN 7
+!-
+! INVALIDLENGTH: invalid value '3' in 'ffixed-line-length=','value must be at least seven'
+
+!---
+! EXPECTED OUTPUT WITH UNLIMITED LENGTH
+!---
+! The line should not be trimmed and so 73 characters (including spaces) should be read.
+! UNLIMITEDLENGTH: program{{(a{59})}}
+
+!
+! EXPECTED OUTPUT WITH LENGTH 13
+!
+! LENGTH13: program
Index: flang/test/Flang-Driver/fixed-free-flag.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/fixed-free-flag.f90
@@ -0,0 +1,25 @@
+! Ensure arguments 

[PATCH] D95460: [flang][driver] Add forced form flags and -ffixed-line-length

2021-01-29 Thread Faris via Phabricator via cfe-commits
FarisRehman updated this revision to Diff 320145.
FarisRehman added a comment.

Remove -fno-fixed-form and -fno-free-form

Remove options `-fno-fixed-form` and `-fno-free-form` allowing for help 
messages to be added to `-ffixed-form` and `-ffree-form`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95460/new/

https://reviews.llvm.org/D95460

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/lib/Driver/ToolChains/Flang.h
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CompilerInstance.cpp
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/Inputs/fixed-form-test.f
  flang/test/Flang-Driver/Inputs/fixed-line-length-test.f
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/fixed-free-flag.f90
  flang/test/Flang-Driver/fixed-line-length.f90

Index: flang/test/Flang-Driver/fixed-line-length.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/fixed-line-length.f90
@@ -0,0 +1,50 @@
+! Ensure argument -ffixed-line-length-n works as expected.
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -E %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=DEFAULTLENGTH
+! RUN: not %flang-new -E -ffixed-line-length--2 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=NEGATIVELENGTH
+! RUN: not %flang-new -E -ffixed-line-length-3 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
+! RUN: %flang-new -E -ffixed-line-length-none %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang-new -E -ffixed-line-length-0 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang-new -E -ffixed-line-length-13 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=LENGTH13
+
+!
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!
+! RUN: %flang-new -fc1 -E %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=DEFAULTLENGTH
+! RUN: not %flang-new -fc1 -E -ffixed-line-length--2 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=NEGATIVELENGTH
+! RUN: not %flang-new -fc1 -E -ffixed-line-length-3 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
+! RUN: %flang-new -fc1 -E -ffixed-line-length-none %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang-new -fc1 -E -ffixed-line-length-0 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang-new -fc1 -E -ffixed-line-length-13 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=LENGTH13
+
+!-
+! EXPECTED OUTPUT WITH DEFAULT LENGTH
+!-
+! The line should be trimmed to 72 characters when reading based on the default value of fixed line length.
+! DEFAULTLENGTH: program{{(a{58})}}
+
+!-
+! EXPECTED OUTPUT WITH A NEGATIVE LENGTH
+!-
+! NEGATIVELENGTH: invalid value '-2' in 'ffixed-line-length-','value must be 'none' or a non-negative integer'
+
+!-
+! EXPECTED OUTPUT WITH LENGTH LESS THAN 7
+!-
+! INVALIDLENGTH: invalid value '3' in 'ffixed-line-length-','value must be at least seven'
+
+!---
+! EXPECTED OUTPUT WITH UNLIMITED LENGTH
+!---
+! The line should not be trimmed and so 73 characters (including spaces) should be read.
+! UNLIMITEDLENGTH: program{{(a{59})}}
+
+!
+! EXPECTED OUTPUT WITH LENGTH 13
+!
+! LENGTH13: program
Index: flang/test/Flang-Driver/fixed-free-flag.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/fixed-free-flag.f90
@@ -0,0 +1,25 @@
+! Ensure arguments -ffree-form and -ffixed-form work as expected.
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: not %flang-new -fsyntax-only -ffree-form %S/Inputs/fixed-form-test.f  2>&1 | FileCheck %s --check-prefix=FREEFORM
+! RUN: %flang-new -fsyntax-only -ffixed-form %S/Inputs/free-form-test.f90 2>&1 | FileCheck %s --check-prefix=FIXEDFORM
+
+!
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!
+! RUN: not %flang-new -fc1 -fsyntax-only -ffree-form %S/Inputs/fixed-form-test.f  2>&1 | FileCheck 

[PATCH] D95460: [flang][driver] Add forced form flags and -ffixed-line-length

2021-01-28 Thread Faris via Phabricator via cfe-commits
FarisRehman marked an inline comment as done.
FarisRehman added inline comments.



Comment at: flang/lib/Frontend/CompilerInstance.cpp:151-158
+  if (invoc.frontendOpts().fortranForm_ == FortranForm::Unknown) {
+// Switch between fixed and free form format based on the input file
+// extension. Ideally we should have all Fortran options set before
+// entering this loop (i.e. processing any input files). However, we
+// can't decide between fixed and free form based on the file extension
+// earlier than this.
+invoc.fortranOpts().isFixedForm = fif.IsFixedForm();

awarzynski wrote:
> Hm, unwanted TABs? 
> 
> Also, please keep note of: https://reviews.llvm.org/D95464 (there should be 
> no conflicts from what I can tell).
I believe this is just Phabricator showing the comments have been indented


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95460/new/

https://reviews.llvm.org/D95460

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95460: [flang][driver] Add forced form flags and -ffixed-line-length

2021-01-28 Thread Faris via Phabricator via cfe-commits
FarisRehman updated this revision to Diff 319842.
FarisRehman marked 12 inline comments as done.
FarisRehman added a comment.

Address review comment

Address the review comment by @awarzynski

Summary of changes:

- Shorten help text
- Add method AddFortranDialectOptions to Flang.cpp
- Change style of code to use quaternary operator
- Update regression tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95460/new/

https://reviews.llvm.org/D95460

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/lib/Driver/ToolChains/Flang.h
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CompilerInstance.cpp
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/Inputs/fixed-form-test.f
  flang/test/Flang-Driver/Inputs/fixed-line-length-test.f
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/fixed-free-flag.f90
  flang/test/Flang-Driver/fixed-line-length.f90

Index: flang/test/Flang-Driver/fixed-line-length.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/fixed-line-length.f90
@@ -0,0 +1,50 @@
+! Ensure argument -ffixed-line-length-n works as expected.
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -E %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=DEFAULTLENGTH
+! RUN: not %flang-new -E -ffixed-line-length--2 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=NEGATIVELENGTH
+! RUN: not %flang-new -E -ffixed-line-length-3 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
+! RUN: %flang-new -E -ffixed-line-length-none %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang-new -E -ffixed-line-length-0 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang-new -E -ffixed-line-length-13 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=LENGTH13
+
+!
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!
+! RUN: %flang-new -fc1 -E %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=DEFAULTLENGTH
+! RUN: not %flang-new -fc1 -E -ffixed-line-length--2 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=NEGATIVELENGTH
+! RUN: not %flang-new -fc1 -E -ffixed-line-length-3 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
+! RUN: %flang-new -fc1 -E -ffixed-line-length-none %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang-new -fc1 -E -ffixed-line-length-0 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang-new -fc1 -E -ffixed-line-length-13 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=LENGTH13
+
+!-
+! EXPECTED OUTPUT WITH DEFAULT LENGTH
+!-
+! The line should be trimmed to 72 characters when reading based on the default value of fixed line length.
+! DEFAULTLENGTH: program{{(a{58})}}
+
+!-
+! EXPECTED OUTPUT WITH A NEGATIVE LENGTH
+!-
+! NEGATIVELENGTH: invalid value '-2' in 'ffixed-line-length-','value must be 'none' or a non-negative integer'
+
+!-
+! EXPECTED OUTPUT WITH LENGTH LESS THAN 7
+!-
+! INVALIDLENGTH: invalid value '3' in 'ffixed-line-length-','value must be at least seven'
+
+!---
+! EXPECTED OUTPUT WITH UNLIMITED LENGTH
+!---
+! The line should not be trimmed and so 73 characters (including spaces) should be read.
+! UNLIMITEDLENGTH: program{{(a{59})}}
+
+!
+! EXPECTED OUTPUT WITH LENGTH 13
+!
+! LENGTH13: program
Index: flang/test/Flang-Driver/fixed-free-flag.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/fixed-free-flag.f90
@@ -0,0 +1,25 @@
+! Ensure arguments -ffree-form and -ffixed-form work as expected.
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: not %flang-new -fsyntax-only -ffree-form %S/Inputs/fixed-form-test.f  2>&1 | FileCheck %s --check-prefix=FREEFORM
+! RUN: %flang-new -fsyntax-only -ffixed-form %S/Inputs/free-form-test.f90 2>&1 | FileCheck %s --check-prefix=FIXEDFORM
+
+!
+! FRONTEND FLANG DRIVER (flang-new -fc1)

[PATCH] D95460: [flang][driver] Add forced form flags and -ffixed-line-length

2021-01-26 Thread Faris via Phabricator via cfe-commits
FarisRehman created this revision.
Herald added a reviewer: sscalpone.
Herald added a subscriber: dang.
Herald added a reviewer: awarzynski.
Herald added a reviewer: jansvoboda11.
FarisRehman requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add support for the following layout options:

- -ffree-form
- -ffixed-form
- -ffixed-line-length-n

The default fixed line length is 72, based off the current default.

This patch does not add `-ffree-line-length-n` as Fortran::parser::Options does 
not have a variable for free form columns.
Whilst `fixedFormColumns` variable is used in f18 for `-ffree-line-length-n`, 
f18 only allows `-ffree-line-length-none`/`-ffree-line-length-0` and not a 
user-specified value. `fixedFormcolumns` cannot be used in the new driver as it 
is ignored in the frontend when dealing with free form files.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95460

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CompilerInstance.cpp
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/Inputs/fixed-form-test.f
  flang/test/Flang-Driver/Inputs/fixed-line-length-test.f
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/fixed-free-flag.f90
  flang/test/Flang-Driver/fixed-line-length.f90

Index: flang/test/Flang-Driver/fixed-line-length.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/fixed-line-length.f90
@@ -0,0 +1,43 @@
+! Ensure argument -ffixed-line-length-n works as expected.
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -E %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=DEFAULTLENGTH
+! RUN: not %flang-new -E -ffixed-line-length-3 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
+! RUN: %flang-new -E -ffixed-line-length-none %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang-new -E -ffixed-line-length-0 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang-new -E -ffixed-line-length-13 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=LENGTH13
+
+!
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!
+! RUN: %flang-new -fc1 -E %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=DEFAULTLENGTH
+! RUN: not %flang-new -fc1 -E -ffixed-line-length-3 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=INVALIDLENGTH
+! RUN: %flang-new -fc1 -E -ffixed-line-length-none %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang-new -fc1 -E -ffixed-line-length-0 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=UNLIMITEDLENGTH
+! RUN: %flang-new -fc1 -E -ffixed-line-length-13 %S/Inputs/fixed-line-length-test.f  2>&1 | FileCheck %s --check-prefix=LENGTH13
+
+!-
+! EXPECTED OUTPUT WITH DEFAULT LENGTH
+!-
+! The line should be trimmed to 72 characters when reading based on the default value of fixed line length.
+! DEFAULTLENGTH: programaa
+
+!-
+! EXPECTED OUTPUT WITH LENGTH LESS THAN 7
+!-
+! INVALIDLENGTH: invalid value '{{(-)?[0-9]+}}'
+
+!---
+! EXPECTED OUTPUT WITH UNLIMITED LENGTH
+!---
+! The line should not be trimmed and so 73 characters (including spaces) should be read.
+! UNLIMITEDLENGTH: programaaa
+
+!
+! EXPECTED OUTPUT WITH LENGTH 13
+!
+! LENGTH13: program
Index: flang/test/Flang-Driver/fixed-free-flag.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/fixed-free-flag.f90
@@ -0,0 +1,25 @@
+! Ensure arguments -ffree-form and -ffixed-form work as expected.
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: not %flang-new -fsyntax-only -ffree-form %S/Inputs/fixed-form-test.f %S/Inputs/free-form-test.f90  2>&1 | FileCheck %s --check-prefix=FREEFORM
+! RUN: %flang-new -fsyntax-only -ffixed-form %S/Inputs/free-form-test.f90 %S/Inputs/fixed-form-test.f  2>&1 | FileCheck %s --check-prefix=FIXEDFORM
+
+!
+! FRONTEND FLANG DRIVER (flang-new -fc1)

[PATCH] D93453: [flang][driver] Add support for `-I`

2021-01-15 Thread Faris via Phabricator via cfe-commits
FarisRehman updated this revision to Diff 316908.
FarisRehman marked 2 inline comments as done.
FarisRehman added a comment.

Add include-module test

Update the regression test to check the behaviour of -I with an INCLUDE line in 
the source code.
Also add a regression test to check the behaviour of -I with module files.

Summary of changes:

- Update include-header.f90 to check INCLUDE
- Add include-module.f90 to check the behaviour with module files
- Rename SecondaryInputs directory to header-dir and create a module-dir 
directory


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93453/new/

https://reviews.llvm.org/D93453

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/Inputs/basic-header-one.h
  flang/test/Flang-Driver/Inputs/basic-header-two.h
  flang/test/Flang-Driver/Inputs/basictestmoduleone.mod
  flang/test/Flang-Driver/Inputs/header-dir/basic-header-one.h
  flang/test/Flang-Driver/Inputs/header-dir/basic-header-two.h
  flang/test/Flang-Driver/Inputs/module-dir/basictestmoduletwo.mod
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/include-header.f90
  flang/test/Flang-Driver/include-module.f90

Index: flang/test/Flang-Driver/include-module.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/include-module.f90
@@ -0,0 +1,32 @@
+! Ensure argument -I works as expected with module files.
+! The module files for this test are not real module files.
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: not %flang-new -fsyntax-only -I %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fsyntax-only -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: not %flang-new -fc1 -fsyntax-only -I %S/Inputs -I %S/Inputs/module-dir %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: not %flang-new -fc1 -fsyntax-only -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+
+!-
+! EXPECTED OUTPUT FOR MISSING MODULE FILE
+!-
+! SINGLEINCLUDE:No such file or directory
+! SINGLEINCLUDE-NOT:Error reading module file for module 'basictestmoduletwo'
+
+!---
+! EXPECTED OUTPUT FOR ALL MODULES FOUND
+!---
+! INCLUDED-NOT:No such file or directory
+
+program test_dash_I_with_mod_files
+USE basictestmoduleone
+USE basictestmoduletwo
+end
\ No newline at end of file
Index: flang/test/Flang-Driver/include-header.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/include-header.f90
@@ -0,0 +1,77 @@
+! Ensure argument -I works as expected with an included header.
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: not %flang-new -E %s  2>&1 | FileCheck %s --check-prefix=UNINCLUDED
+! RUN: %flang-new -E -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: %flang-new -E -I %S/Inputs -I %S/Inputs/header-dir %s  2>&1 | FileCheck %s --check-prefix=MAINDIRECTORY
+! RUN: %flang-new -E -I %S/Inputs/header-dir -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SUBDIRECTORY
+
+!
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!
+! RUN: not %flang-new -fc1 -E %s  2>&1 | FileCheck %s --check-prefix=UNINCLUDED
+! RUN: %flang-new -fc1 -E -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: %flang-new -fc1 -E -I %S/Inputs -I %S/Inputs/header-dir %s  2>&1 | FileCheck %s --check-prefix=MAINDIRECTORY
+! RUN: %flang-new -fc1 -E -I %S/Inputs/header-dir -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SUBDIRECTORY
+
+!
+! EXPECTED OUTPUT FOR MISSING INCLUDED FILE
+!
+! UNINCLUDED:No such file or directory
+! UNINCLUDED-NOT:program b
+! UNINCLUDED-NOT:program c
+
+!-
+! EXPECTED OUTPUT FOR A SINGLE INCLUDED FOLDER
+!
+! SINGLEINCLUDE:program maindirectoryone
+! SINGLEINCLUDE-NOT:program x
+! SINGLEINCLUDE-NOT:program b
+! SINGLEINCLUDE-NEXT:end
+! SINGLEINCLUDE-NEXT:program maindirectorytwo
+! SINGLEINCLUDE-NOT:program y
+! SINGLEINCLUDE-NOT:program c
+
+!---
+! EXPECTED OUTPUT FOR Inputs/ 

[PATCH] D93453: [flang][driver] Add support for `-I`

2021-01-15 Thread Faris via Phabricator via cfe-commits
FarisRehman marked 2 inline comments as done.
FarisRehman added inline comments.



Comment at: flang/test/Flang-Driver/include-header.f90:38
+!-
+! EXPECTED OUTPUT FOR /Inputs/ FOLDER SPECIFIED FIRST
+!-

sameeranjoshi wrote:
> Nit - Shouldn't this be `Inputs/` starting with a `/` changes the meaning(at 
> least on Linux systems) ?
I've fixed this, thanks.



Comment at: flang/test/Flang-Driver/include-header.f90:59
+#endif
+end

tskeith wrote:
> `-I` also is supposed to affect INCLUDE lines so it would be good to have a 
> test for that too. They are handled during preprocessing and so can be tested 
> the same way.
> 
> It also affects searching for .mod files but I think to test that requires 
> semantics (i.e. to report an error if the module can't be found). It would be 
> good to test that somewhere too.
Thanks, I've updated the test to check INCLUDE lines and added a new test for 
module files.
I've added some `.mod` files to the Inputs directory, however these files are 
not real module files and are just there for the test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93453/new/

https://reviews.llvm.org/D93453

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D93401: [flang][driver] Add support for `-D`, `-U`

2021-01-15 Thread Faris via Phabricator via cfe-commits
FarisRehman marked an inline comment as done.
FarisRehman added inline comments.



Comment at: flang/test/Flang-Driver/driver-help.f90:22
 ! HELP-NEXT: -###   Print (but do not run) the commands to run 
for this compilation
+! HELP-NEXT: -D = Define  to  (or 1 if  
omitted)
 ! HELP-NEXT: -E Only run the preprocessor

FarisRehman wrote:
> sameeranjoshi wrote:
> > I see below crash report, when omitting the  but not omitting the 
> > `=` symbol.
> > Not sure if that's correct way of running hence instead of filing bug 
> > reporting here.
> > 
> > ```
> > ./bin/flang-new -E -DX= test.f90
> > ```
> > 
> > ```
> > PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash 
> > backtrace.
> > Stack dump:
> > 0.  Program arguments: 
> > /home/amd/f18_git/final_test/driver_build/bin/flang-new -fc1 -E -D X= -o - 
> > test.f90
> >  #0 0x7f26185d0bc1 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
> > (/home/amd/f18_git/final_test/driver_build/bin/../lib/libLLVMSupport.so.12git+0x1a4bc1)
> >  #1 0x7f26185ce9a4 llvm::sys::RunSignalHandlers() 
> > (/home/amd/f18_git/final_test/driver_build/bin/../lib/libLLVMSupport.so.12git+0x1a29a4)
> >  #2 0x7f26185ceb10 SignalHandler(int) 
> > (/home/amd/f18_git/final_test/driver_build/bin/../lib/libLLVMSupport.so.12git+0x1a2b10)
> >  #3 0x7f2617749470 (/lib/x86_64-linux-gnu/libc.so.6+0x46470)
> >  #4 0x7f2617443498 
> > Fortran::parser::OffsetToProvenanceMappings::Map(unsigned long) const 
> > (/home/amd/f18_git/final_test/driver_build/bin/../lib/../lib/libFortranParser.so.12git+0x571498)
> >  #5 0x7f261744adf2 Fortran::parser::TokenSequence::GetProvenanceRange() 
> > const 
> > (/home/amd/f18_git/final_test/driver_build/bin/../lib/../lib/libFortranParser.so.12git+0x578df2)
> >  #6 0x7f26173dd334 
> > Fortran::parser::Preprocessor::MacroReplacement(Fortran::parser::TokenSequence
> >  const&, Fortran::parser::Prescanner&) (.localalias) 
> > (/home/amd/f18_git/final_test/driver_build/bin/../lib/../lib/libFortranParser.so.12git+0x50b334)
> >  #7 0x7f26173e9dc1 Fortran::parser::Prescanner::Statement() 
> > (.localalias) 
> > (/home/amd/f18_git/final_test/driver_build/bin/../lib/../lib/libFortranParser.so.12git+0x517dc1)
> >  #8 0x7f26173ea888 
> > Fortran::parser::Prescanner::Prescan(Fortran::common::Interval)
> >  (.localalias) 
> > (/home/amd/f18_git/final_test/driver_build/bin/../lib/../lib/libFortranParser.so.12git+0x51)
> >  #9 0x7f26173d480b 
> > Fortran::parser::Parsing::Prescan(std::__cxx11::basic_string > std::char_traits, std::allocator > const&, 
> > Fortran::parser::Options) 
> > (/home/amd/f18_git/final_test/driver_build/bin/../lib/../lib/libFortranParser.so.12git+0x50280b)
> > #10 0x7f2618424ddd Fortran::frontend::FrontendAction::Execute() 
> > (/home/amd/f18_git/final_test/driver_build/bin/../lib/libflangFrontend.so.12git+0x)
> > #11 0x7f261841fa5e 
> > Fortran::frontend::CompilerInstance::ExecuteAction(Fortran::frontend::FrontendAction&)
> >  
> > (/home/amd/f18_git/final_test/driver_build/bin/../lib/libflangFrontend.so.12git+0x8a5e)
> > #12 0x7f26184132fc 
> > Fortran::frontend::ExecuteCompilerInvocation(Fortran::frontend::CompilerInstance*)
> >  
> > (/home/amd/f18_git/final_test/driver_build/bin/../lib/libflangFrontendTool.so.12git+0x12fc)
> > #13 0x55bad4081c20 fc1_main(llvm::ArrayRef, char const*) 
> > (/home/amd/f18_git/final_test/driver_build/bin/flang-new+0x3c20)
> > #14 0x55bad4080e59 main 
> > (/home/amd/f18_git/final_test/driver_build/bin/flang-new+0x2e59)
> > #15 0x7f261772a1e3 __libc_start_main 
> > /build/glibc-5mDdLG/glibc-2.30/csu/../csu/libc-start.c:342:3
> > #16 0x55bad4080eae _start 
> > (/home/amd/f18_git/final_test/driver_build/bin/flang-new+0x2eae)
> > flang-new: error: unable to execute command: Segmentation fault (core 
> > dumped)
> > flang-new: error: flang frontend command failed due to signal (use -v to 
> > see invocation)
> > flang-new version 12.0.0 (https://github.com/llvm/llvm-project.git 
> > 2f9cb090cc6db1be5bf524eb0a32537503b3e786)
> > Target: x86_64-unknown-linux-gnu
> > Thread model: posix
> > InstalledDir: /home/amd/f18_git/final_test/driver_build/bin
> > flang-new: note: diagnostic msg: Error generating preprocessed source(s) - 
> > no preprocessable inputs.
> > 
> > ```
> > 
> Thanks for reporting this!
> I was able to reproduce this error running:
>   - flang-new -DX= file.f
>   - flang-new -E -DX= file.f
>   - flang-new -fc1 -E -DX= file.f
>   - f18 -E -DX= file.f
> However I did not receive an error when running: `flang-new -fc1 -DX= file.f`
> I suspect this may be an issue in the frontend and I will look into this 
> further.
The bug seems to occur in the frontend and a bug report has been filed: 
https://bugs.llvm.org/show_bug.cgi?id=48747


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93401/new/


[PATCH] D93453: [flang][driver] Add support for `-I`

2021-01-13 Thread Faris via Phabricator via cfe-commits
FarisRehman updated this revision to Diff 316423.
FarisRehman added a comment.

Add a new test

Update the regression test to check the behaviour of multiple `-I`'s specified.

Summary of changes:

- Update regression test with new checks
- Fix regression tests that broke when patch D93712 
 was implemented


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93453/new/

https://reviews.llvm.org/D93453

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/Inputs/SecondaryInputs/basic-test-header.h
  flang/test/Flang-Driver/Inputs/basic-test-header.h
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/include-header.f90

Index: flang/test/Flang-Driver/include-header.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/include-header.f90
@@ -0,0 +1,59 @@
+! Ensure argument -I works as expected.
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: not %flang-new -E %s  2>&1 | FileCheck %s --check-prefix=UNINCLUDED
+! RUN: %flang-new -E -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: %flang-new -E -I %S/Inputs -I %S/Inputs/SecondaryInputs %s  2>&1 | FileCheck %s --check-prefix=PRIMARYINCLUDE
+! RUN: %flang-new -E -I %S/Inputs/SecondaryInputs -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SECONDARYINCLUDE
+! RUN: not %flang-new -E -I %S/InvalidFolder %s  2>&1 | FileCheck %s --check-prefix=UNINCLUDED
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: not %flang-new -fc1 -E %s  2>&1 | FileCheck %s --check-prefix=UNINCLUDED
+! RUN: %flang-new -fc1 -E -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SINGLEINCLUDE
+! RUN: %flang-new -E -I %S/Inputs -I %S/Inputs/SecondaryInputs %s  2>&1 | FileCheck %s --check-prefix=PRIMARYINCLUDE
+! RUN: %flang-new -E -I %S/Inputs/SecondaryInputs -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=SECONDARYINCLUDE
+! RUN: not %flang-new -fc1 -E -I %S/InvalidFolder %s  2>&1 | FileCheck %s --check-prefix=UNINCLUDED
+
+!
+! EXPECTED OUTPUT FOR MISSING INCLUDED FILE
+!
+! UNINCLUDED:No such file or directory
+! UNINCLUDED-NOT:program a
+
+!--
+! EXPECTED OUTPUT FOR A SINGLE INCLUDE
+!--
+! SINGLEINCLUDE:program firstdirectory
+! SINGLEINCLUDE-NOT:program x
+! SINGLEINCLUDE-NOT:program b
+! SINGLEINCLUDE-NEXT:end
+
+!-
+! EXPECTED OUTPUT FOR /Inputs/ FOLDER SPECIFIED FIRST
+!-
+! PRIMARYINCLUDE:program firstdirectory
+! PRIMARYINCLUDE-NOT:program seconddirectory
+! PRIMARYINCLUDE-NOT:program b
+! PRIMARYINCLUDE-NEXT:end
+
+!-
+! EXPECTED OUTPUT FOR /Inputs/SecondaryInputs/ FOLDER SPECIFIED FIRST
+!-
+! SECONDARYINCLUDE:program seconddirectory
+! SECONDARYINCLUDE-NOT:program firstdirectory
+! SECONDARYINCLUDE-NOT:program b
+! SECONDARYINCLUDE-NEXT:end
+
+#include 
+#ifdef X
+program X
+#else
+program B
+#endif
+end
\ No newline at end of file
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -25,6 +25,7 @@
 ! HELP-NEXT: -fcolor-diagnosticsEnable colors in diagnostics
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! HELP-NEXT: -help  Display available options
+! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -o   Write output to 
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
@@ -39,6 +40,7 @@
 ! HELP-FC1-NEXT: -emit-obj Emit native object files
 ! HELP-FC1-NEXT: -E Only run the preprocessor
 ! HELP-FC1-NEXT: -help  Display available options
+! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -o   Write output to 
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
Index: flang/test/Flang-Driver/driver-help-hidden.f90
===
--- flang/test/Flang-Driver/driver-help-hidden.f90
+++ 

[PATCH] D93401: [flang][driver] Add support for `-D`, `-U`

2021-01-11 Thread Faris via Phabricator via cfe-commits
FarisRehman added inline comments.



Comment at: flang/test/Flang-Driver/driver-help.f90:22
 ! HELP-NEXT: -###   Print (but do not run) the commands to run 
for this compilation
+! HELP-NEXT: -D = Define  to  (or 1 if  
omitted)
 ! HELP-NEXT: -E Only run the preprocessor

sameeranjoshi wrote:
> I see below crash report, when omitting the  but not omitting the `=` 
> symbol.
> Not sure if that's correct way of running hence instead of filing bug 
> reporting here.
> 
> ```
> ./bin/flang-new -E -DX= test.f90
> ```
> 
> ```
> PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash 
> backtrace.
> Stack dump:
> 0.  Program arguments: 
> /home/amd/f18_git/final_test/driver_build/bin/flang-new -fc1 -E -D X= -o - 
> test.f90
>  #0 0x7f26185d0bc1 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
> (/home/amd/f18_git/final_test/driver_build/bin/../lib/libLLVMSupport.so.12git+0x1a4bc1)
>  #1 0x7f26185ce9a4 llvm::sys::RunSignalHandlers() 
> (/home/amd/f18_git/final_test/driver_build/bin/../lib/libLLVMSupport.so.12git+0x1a29a4)
>  #2 0x7f26185ceb10 SignalHandler(int) 
> (/home/amd/f18_git/final_test/driver_build/bin/../lib/libLLVMSupport.so.12git+0x1a2b10)
>  #3 0x7f2617749470 (/lib/x86_64-linux-gnu/libc.so.6+0x46470)
>  #4 0x7f2617443498 
> Fortran::parser::OffsetToProvenanceMappings::Map(unsigned long) const 
> (/home/amd/f18_git/final_test/driver_build/bin/../lib/../lib/libFortranParser.so.12git+0x571498)
>  #5 0x7f261744adf2 Fortran::parser::TokenSequence::GetProvenanceRange() 
> const 
> (/home/amd/f18_git/final_test/driver_build/bin/../lib/../lib/libFortranParser.so.12git+0x578df2)
>  #6 0x7f26173dd334 
> Fortran::parser::Preprocessor::MacroReplacement(Fortran::parser::TokenSequence
>  const&, Fortran::parser::Prescanner&) (.localalias) 
> (/home/amd/f18_git/final_test/driver_build/bin/../lib/../lib/libFortranParser.so.12git+0x50b334)
>  #7 0x7f26173e9dc1 Fortran::parser::Prescanner::Statement() (.localalias) 
> (/home/amd/f18_git/final_test/driver_build/bin/../lib/../lib/libFortranParser.so.12git+0x517dc1)
>  #8 0x7f26173ea888 
> Fortran::parser::Prescanner::Prescan(Fortran::common::Interval)
>  (.localalias) 
> (/home/amd/f18_git/final_test/driver_build/bin/../lib/../lib/libFortranParser.so.12git+0x51)
>  #9 0x7f26173d480b 
> Fortran::parser::Parsing::Prescan(std::__cxx11::basic_string std::char_traits, std::allocator > const&, 
> Fortran::parser::Options) 
> (/home/amd/f18_git/final_test/driver_build/bin/../lib/../lib/libFortranParser.so.12git+0x50280b)
> #10 0x7f2618424ddd Fortran::frontend::FrontendAction::Execute() 
> (/home/amd/f18_git/final_test/driver_build/bin/../lib/libflangFrontend.so.12git+0x)
> #11 0x7f261841fa5e 
> Fortran::frontend::CompilerInstance::ExecuteAction(Fortran::frontend::FrontendAction&)
>  
> (/home/amd/f18_git/final_test/driver_build/bin/../lib/libflangFrontend.so.12git+0x8a5e)
> #12 0x7f26184132fc 
> Fortran::frontend::ExecuteCompilerInvocation(Fortran::frontend::CompilerInstance*)
>  
> (/home/amd/f18_git/final_test/driver_build/bin/../lib/libflangFrontendTool.so.12git+0x12fc)
> #13 0x55bad4081c20 fc1_main(llvm::ArrayRef, char const*) 
> (/home/amd/f18_git/final_test/driver_build/bin/flang-new+0x3c20)
> #14 0x55bad4080e59 main 
> (/home/amd/f18_git/final_test/driver_build/bin/flang-new+0x2e59)
> #15 0x7f261772a1e3 __libc_start_main 
> /build/glibc-5mDdLG/glibc-2.30/csu/../csu/libc-start.c:342:3
> #16 0x55bad4080eae _start 
> (/home/amd/f18_git/final_test/driver_build/bin/flang-new+0x2eae)
> flang-new: error: unable to execute command: Segmentation fault (core dumped)
> flang-new: error: flang frontend command failed due to signal (use -v to see 
> invocation)
> flang-new version 12.0.0 (https://github.com/llvm/llvm-project.git 
> 2f9cb090cc6db1be5bf524eb0a32537503b3e786)
> Target: x86_64-unknown-linux-gnu
> Thread model: posix
> InstalledDir: /home/amd/f18_git/final_test/driver_build/bin
> flang-new: note: diagnostic msg: Error generating preprocessed source(s) - no 
> preprocessable inputs.
> 
> ```
> 
Thanks for reporting this!
I was able to reproduce this error running:
  - flang-new -DX= file.f
  - flang-new -E -DX= file.f
  - flang-new -fc1 -E -DX= file.f
  - f18 -E -DX= file.f
However I did not receive an error when running: `flang-new -fc1 -DX= file.f`
I suspect this may be an issue in the frontend and I will look into this 
further.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93401/new/

https://reviews.llvm.org/D93401

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D93453: [flang][driver] Add support for `-I`

2021-01-07 Thread Faris via Phabricator via cfe-commits
FarisRehman updated this revision to Diff 315090.
FarisRehman added a comment.

Rename test files

Rename test files to use dashes instead of underscores, as other test files do.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93453/new/

https://reviews.llvm.org/D93453

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/Inputs/basic-test-header.h
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/include-header.f90

Index: flang/test/Flang-Driver/include-header.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/include-header.f90
@@ -0,0 +1,39 @@
+! Ensure argument -I works as expected.
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -E %s  2>&1 | FileCheck %s --check-prefix=UNINCLUDED
+! RUN: %flang-new -E -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: %flang-new -E -I %S/InvalidFolder %s  2>&1 | FileCheck %s --check-prefix=UNINCLUDED
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang-new -fc1 -E %s  2>&1 | FileCheck %s --check-prefix=UNINCLUDED
+! RUN: %flang-new -fc1 -E -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: %flang-new -fc1 -E -I %S/InvalidFolder %s  2>&1 | FileCheck %s --check-prefix=UNINCLUDED
+
+!
+! EXPECTED OUTPUT FOR MISSING INCLUDED FILE
+!
+! UNINCLUDED:program b
+! UNINCLUDED-NOT:program a
+! UNINCLUDED-NEXT:end
+
+!--
+! EXPECTED OUTPUT FOR INCLUDE
+!--
+! INCLUDED:program a
+! INCLUDED-NOT:program b
+! INCLUDED-NEXT:end
+
+#include 
+#ifdef X
+program A
+#else
+program B
+#endif
+end
\ No newline at end of file
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -24,6 +24,7 @@
 ! HELP-NEXT: -fcolor-diagnosticsEnable colors in diagnostics
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! HELP-NEXT: -help  Display available options
+! HELP-NEXT: -IAdd directory to include search path
 ! HELP-NEXT: -o   Write output to 
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
@@ -37,6 +38,7 @@
 ! HELP-FC1-NEXT: -D = Define  to  (or 1 if  omitted)
 ! HELP-FC1-NEXT: -E Only run the preprocessor
 ! HELP-FC1-NEXT: -help  Display available options
+! HELP-FC1-NEXT: -IAdd directory to include search path
 ! HELP-FC1-NEXT: -o   Write output to 
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
Index: flang/test/Flang-Driver/driver-help-hidden.f90
===
--- flang/test/Flang-Driver/driver-help-hidden.f90
+++ flang/test/Flang-Driver/driver-help-hidden.f90
@@ -24,6 +24,7 @@
 ! CHECK-NEXT: -fcolor-diagnosticsEnable colors in diagnostics
 ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! CHECK-NEXT: -help Display available options
+! CHECK-NEXT: -IAdd directory to include search path
 ! CHECK-NEXT: -o  Write output to 
 ! CHECK-NEXT: -test-io  Run the InputOuputTest action. Use for development and testing only.
 ! CHECK-NEXT: -U  Undefine macro 
Index: flang/test/Flang-Driver/Inputs/basic-test-header.h
===
--- /dev/null
+++ flang/test/Flang-Driver/Inputs/basic-test-header.h
@@ -0,0 +1 @@
+#define X
\ No newline at end of file
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -171,6 +171,10 @@
   opts.addMacroUndef(currentArg->getValue());
 }
   }
+
+  // Add the ordered list of -I's.
+  for (const auto *currentArg : args.filtered(clang::driver::options::OPT_I))
+opts.searchDirectoriesFromDashI.emplace_back(currentArg->getValue());
 }
 
 bool CompilerInvocation::CreateFromArgs(CompilerInvocation ,
@@ -256,4 +260,9 @@
   const auto  = preprocessorOpts();
 
   collectMacroDefinitions(preprocessorOptions, fortranOptions);
-}
\ No newline at end of file
+
+  fortranOptions.searchDirectories.insert(
+  fortranOptions.searchDirectories.end(),
+  

[PATCH] D93453: [flang][driver] Add support for `-I`

2021-01-06 Thread Faris via Phabricator via cfe-commits
FarisRehman updated this revision to Diff 314905.
FarisRehman added a comment.

Address minor changes in review comments

Summary of changes

- Add a TODO for future search-path related options
- Change the text which the driver-help tests look for, which matches the help 
message in #D94169
- Rename the test header


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93453/new/

https://reviews.llvm.org/D93453

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/Inputs/basic_test_header.h
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/include_header.f90

Index: flang/test/Flang-Driver/include_header.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/include_header.f90
@@ -0,0 +1,39 @@
+! Ensure argument -I works as expected.
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -E %s  2>&1 | FileCheck %s --check-prefix=UNINCLUDED
+! RUN: %flang-new -E -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: %flang-new -E -I %S/InvalidFolder %s  2>&1 | FileCheck %s --check-prefix=UNINCLUDED
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang-new -fc1 -E %s  2>&1 | FileCheck %s --check-prefix=UNINCLUDED
+! RUN: %flang-new -fc1 -E -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: %flang-new -fc1 -E -I %S/InvalidFolder %s  2>&1 | FileCheck %s --check-prefix=UNINCLUDED
+
+!
+! EXPECTED OUTPUT FOR MISSING INCLUDED FILE
+!
+! UNINCLUDED:program b
+! UNINCLUDED-NOT:program a
+! UNINCLUDED-NEXT:end
+
+!--
+! EXPECTED OUTPUT FOR INCLUDE
+!--
+! INCLUDED:program a
+! INCLUDED-NOT:program b
+! INCLUDED-NEXT:end
+
+#include 
+#ifdef X
+program A
+#else
+program B
+#endif
+end
\ No newline at end of file
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -24,6 +24,7 @@
 ! HELP-NEXT: -fcolor-diagnosticsEnable colors in diagnostics
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! HELP-NEXT: -help  Display available options
+! HELP-NEXT: -IAdd directory to include search path
 ! HELP-NEXT: -o   Write output to 
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
@@ -37,6 +38,7 @@
 ! HELP-FC1-NEXT: -D = Define  to  (or 1 if  omitted)
 ! HELP-FC1-NEXT: -E Only run the preprocessor
 ! HELP-FC1-NEXT: -help  Display available options
+! HELP-FC1-NEXT: -IAdd directory to include search path
 ! HELP-FC1-NEXT: -o   Write output to 
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
Index: flang/test/Flang-Driver/driver-help-hidden.f90
===
--- flang/test/Flang-Driver/driver-help-hidden.f90
+++ flang/test/Flang-Driver/driver-help-hidden.f90
@@ -24,6 +24,7 @@
 ! CHECK-NEXT: -fcolor-diagnosticsEnable colors in diagnostics
 ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! CHECK-NEXT: -help Display available options
+! CHECK-NEXT: -IAdd directory to include search path
 ! CHECK-NEXT: -o  Write output to 
 ! CHECK-NEXT: -test-io  Run the InputOuputTest action. Use for development and testing only.
 ! CHECK-NEXT: -U  Undefine macro 
Index: flang/test/Flang-Driver/Inputs/basic_test_header.h
===
--- /dev/null
+++ flang/test/Flang-Driver/Inputs/basic_test_header.h
@@ -0,0 +1 @@
+#define X
\ No newline at end of file
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -171,6 +171,10 @@
   opts.addMacroUndef(currentArg->getValue());
 }
   }
+
+  // Add the ordered list of -I's.
+  for (const auto *currentArg : args.filtered(clang::driver::options::OPT_I))
+opts.searchDirectoriesFromDashI.emplace_back(currentArg->getValue());
 }
 
 bool CompilerInvocation::CreateFromArgs(CompilerInvocation ,
@@ -256,4 +260,9 @@
   const auto  = preprocessorOpts();
 
   collectMacroDefinitions(preprocessorOptions, 

[PATCH] D93453: [flang][driver] Add support for `-I`

2020-12-23 Thread Faris via Phabricator via cfe-commits
FarisRehman updated this revision to Diff 313536.
FarisRehman added a comment.

Clean up test

Summary of changes:

- Clean up test include_header.f90
- Rename SearchDirectoriesFromDashI to searchDirectoriesFromDashI


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93453/new/

https://reviews.llvm.org/D93453

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/Inputs/included.h
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/include_header.f90

Index: flang/test/Flang-Driver/include_header.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/include_header.f90
@@ -0,0 +1,39 @@
+! Ensure argument -I works as expected.
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -E %s  2>&1 | FileCheck %s --check-prefix=UNINCLUDED
+! RUN: %flang-new -E -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: %flang-new -E -I %S/InvalidFolder %s  2>&1 | FileCheck %s --check-prefix=UNINCLUDED
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang-new -fc1 -E %s  2>&1 | FileCheck %s --check-prefix=UNINCLUDED
+! RUN: %flang-new -fc1 -E -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: %flang-new -fc1 -E -I %S/InvalidFolder %s  2>&1 | FileCheck %s --check-prefix=UNINCLUDED
+
+!
+! EXPECTED OUTPUT FOR MISSING INCLUDED FILE
+!
+! UNINCLUDED:program b
+! UNINCLUDED-NOT:program a
+! UNINCLUDED-NEXT:end
+
+!--
+! EXPECTED OUTPUT FOR INCLUDE
+!--
+! INCLUDED:program a
+! INCLUDED-NOT:program b
+! INCLUDED-NEXT:end
+
+#include 
+#ifdef X
+program A
+#else
+program B
+#endif
+end
\ No newline at end of file
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -24,6 +24,7 @@
 ! HELP-NEXT: -fcolor-diagnosticsEnable colors in diagnostics
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! HELP-NEXT: -help  Display available options
+! HELP-NEXT: -IAdd directory to include search path. If there are multiple -I options, these directories are searched in the order they are given before the standard system directories are searched. If the same directory is in the SYSTEM include search paths, for example if also specified with -isystem, the -I option will be ignored
 ! HELP-NEXT: -o   Write output to 
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
@@ -37,6 +38,7 @@
 ! HELP-FC1-NEXT: -D = Define  to  (or 1 if  omitted)
 ! HELP-FC1-NEXT: -E Only run the preprocessor
 ! HELP-FC1-NEXT: -help  Display available options
+! HELP-FC1-NEXT: -IAdd directory to include search path. If there are multiple -I options, these directories are searched in the order they are given before the standard system directories are searched. If the same directory is in the SYSTEM include search paths, for example if also specified with -isystem, the -I option will be ignored
 ! HELP-FC1-NEXT: -o   Write output to 
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
Index: flang/test/Flang-Driver/driver-help-hidden.f90
===
--- flang/test/Flang-Driver/driver-help-hidden.f90
+++ flang/test/Flang-Driver/driver-help-hidden.f90
@@ -24,6 +24,7 @@
 ! CHECK-NEXT: -fcolor-diagnosticsEnable colors in diagnostics
 ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! CHECK-NEXT: -help Display available options
+! CHECK-NEXT: -IAdd directory to include search path. If there are multiple -I options, these directories are searched in the order they are given before the standard system directories are searched. If the same directory is in the SYSTEM include search paths, for example if also specified with -isystem, the -I option will be ignored
 ! CHECK-NEXT: -o  Write output to 
 ! CHECK-NEXT: -test-io  Run the InputOuputTest action. Use for development and testing only.
 ! CHECK-NEXT: -U  Undefine macro 
Index: flang/test/Flang-Driver/Inputs/included.h
===
--- /dev/null
+++ flang/test/Flang-Driver/Inputs/included.h
@@ 

[PATCH] D93401: [flang][driver] Add support for `-D`, `-U`

2020-12-23 Thread Faris via Phabricator via cfe-commits
FarisRehman updated this revision to Diff 313532.
FarisRehman marked 5 inline comments as done.
FarisRehman added a comment.

Address review comments

This revision addresses comments by @awarzynski

Summary of changes:

- Update commit summary
- Use Doxygen style for input/output parameters
- Make method and variable names lowercase where required
- Remove unnecessary lines in added tests
- Update multiline macro test to have a stronger test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93401/new/

https://reviews.llvm.org/D93401

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/lib/Driver/ToolChains/Flang.h
  flang/include/flang/Frontend/CompilerInstance.h
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInstance.cpp
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/macro_def_undef.f90
  flang/test/Flang-Driver/macro_multiline.f90

Index: flang/test/Flang-Driver/macro_multiline.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/macro_multiline.f90
@@ -0,0 +1,22 @@
+! Ensure the end-of-line character and anything that follows after in a macro definition (-D) is ignored.
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: printf -- "-DX=A\nTHIS_SHOULD_NOT_EXIST_IN_THE_OUTPUT\n" | xargs %flang-new -E %s  2>&1 | FileCheck --strict-whitespace --match-full-lines %s
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: printf -- "-DX=A\nTHIS_SHOULD_NOT_EXIST_IN_THE_OUTPUT\n" | xargs %flang-new -fc1 -E %s  2>&1 | FileCheck --strict-whitespace --match-full-lines %s
+
+!---
+! EXPECTED OUTPUT FOR MACRO 'X'
+!---
+! CHECK:start a end
+! CHECK-NOT:THIS_SHOULD_NOT_EXIST_IN_THE_OUTPUT
+! CHECK-NOT:this_should_not_exist_in_the_output
+
+START X END
\ No newline at end of file
Index: flang/test/Flang-Driver/macro_def_undef.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/macro_def_undef.f90
@@ -0,0 +1,38 @@
+! Ensure arguments -D and -U work as expected.
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -E %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
+! RUN: %flang-new -E -DX=A %s  2>&1 | FileCheck %s --check-prefix=DEFINED
+! RUN: %flang-new -E -DX=A -UX %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang-new -fc1 -E %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
+! RUN: %flang-new -fc1 -E -DX=A %s  2>&1 | FileCheck %s --check-prefix=DEFINED
+! RUN: %flang-new -fc1 -E -DX -UX %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
+
+!
+! EXPECTED OUTPUT FOR AN UNDEFINED MACRO
+!
+! UNDEFINED:program b
+! UNDEFINED-NOT:program x
+! UNDEFINED-NEXT:end
+
+!
+! EXPECTED OUTPUT FOR MACRO 'X' DEFINED AS A
+!
+! DEFINED:program a
+! DEFINED-NOT:program b
+! DEFINED-NEXT:end
+
+#ifdef X
+program X
+#else
+program B
+#endif
+end
\ No newline at end of file
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -19,11 +19,13 @@
 ! HELP-EMPTY:
 ! HELP-NEXT:OPTIONS:
 ! HELP-NEXT: -###   Print (but do not run) the commands to run for this compilation
+! HELP-NEXT: -D = Define  to  (or 1 if  omitted)
 ! HELP-NEXT: -E Only run the preprocessor
 ! HELP-NEXT: -fcolor-diagnosticsEnable colors in diagnostics
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! HELP-NEXT: -help  Display available options
 ! HELP-NEXT: -o   Write output to 
+! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
 
 !-
@@ -32,10 +34,12 @@
 ! HELP-FC1:USAGE: flang-new
 ! HELP-FC1-EMPTY:
 ! HELP-FC1-NEXT:OPTIONS:
-! HELP-FC1-NEXT: -EOnly run the preprocessor
-! HELP-FC1-NEXT: -help Display available options
-! HELP-FC1-NEXT: -o  Write output to 
-! HELP-FC1-NEXT: --version Print version information
+! HELP-FC1-NEXT: -D = Define  to  (or 1 if  omitted)
+! 

[PATCH] D93453: [flang][driver] Add support for `-I`

2020-12-22 Thread Faris via Phabricator via cfe-commits
FarisRehman updated this revision to Diff 313319.
FarisRehman added a comment.

Address review comments

Summary of changes:

- Add a regression test for -I
- Move claiming of -I option to the dedicated parsing preprocessing options 
method
- Rename SearchDirectoriesFromI to SearchDirectoriesFromDashI
- Undo unrelated changes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93453/new/

https://reviews.llvm.org/D93453

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/Inputs/included.h
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/include_header.f90

Index: flang/test/Flang-Driver/include_header.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/include_header.f90
@@ -0,0 +1,41 @@
+! Ensure argument -I works as expected.
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -E %s  2>&1 | FileCheck %s --check-prefix=UNINCLUDED
+! RUN: %flang-new -E -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: %flang-new -E -I %S/InvalidFolder %s  2>&1 | FileCheck %s --check-prefix=UNINCLUDED
+
+!-
+! FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang-new -fc1 -E %s  2>&1 | FileCheck %s --check-prefix=UNINCLUDED
+! RUN: %flang-new -fc1 -E -I %S/Inputs %s  2>&1 | FileCheck %s --check-prefix=INCLUDED
+! RUN: %flang-new -fc1 -E -I %S/InvalidFolder %s  2>&1 | FileCheck %s --check-prefix=UNINCLUDED
+
+
+!
+! EXPECTED OUTPUT FOR MISSING INCLUDE
+!
+! UNINCLUDED:program b
+! UNINCLUDED-NOT:program a
+! UNINCLUDED-NEXT:end
+
+!
+! EXPECTED OUTPUT FOR INCLUDE
+!
+! INCLUDED:program a
+! INCLUDED-NOT:program b
+! INCLUDED-NEXT:end
+
+! Include.F:
+#include 
+#ifdef X
+program A
+#else
+program B
+#endif
+end
\ No newline at end of file
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -24,6 +24,7 @@
 ! HELP-NEXT: -fcolor-diagnosticsEnable colors in diagnostics
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! HELP-NEXT: -help  Display available options
+! HELP-NEXT: -IAdd directory to include search path. If there are multiple -I options, these directories are searched in the order they are given before the standard system directories are searched. If the same directory is in the SYSTEM include search paths, for example if also specified with -isystem, the -I option will be ignored
 ! HELP-NEXT: -o   Write output to 
 ! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
@@ -37,6 +38,7 @@
 ! HELP-FC1-NEXT: -D = Define  to  (or 1 if  omitted)
 ! HELP-FC1-NEXT: -E Only run the preprocessor
 ! HELP-FC1-NEXT: -help  Display available options
+! HELP-FC1-NEXT: -IAdd directory to include search path. If there are multiple -I options, these directories are searched in the order they are given before the standard system directories are searched. If the same directory is in the SYSTEM include search paths, for example if also specified with -isystem, the -I option will be ignored
 ! HELP-FC1-NEXT: -o   Write output to 
 ! HELP-FC1-NEXT: -U  Undefine macro 
 ! HELP-FC1-NEXT: --version  Print version information
Index: flang/test/Flang-Driver/driver-help-hidden.f90
===
--- flang/test/Flang-Driver/driver-help-hidden.f90
+++ flang/test/Flang-Driver/driver-help-hidden.f90
@@ -24,6 +24,7 @@
 ! CHECK-NEXT: -fcolor-diagnosticsEnable colors in diagnostics
 ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! CHECK-NEXT: -help Display available options
+! CHECK-NEXT: -IAdd directory to include search path. If there are multiple -I options, these directories are searched in the order they are given before the standard system directories are searched. If the same directory is in the SYSTEM include search paths, for example if also specified with -isystem, the -I option will be ignored
 ! CHECK-NEXT: -o  Write output to 
 ! CHECK-NEXT: -test-io  Run the InputOuputTest action. Use for development and testing only.
 ! CHECK-NEXT: -U  Undefine macro 
Index: 

[PATCH] D93401: [flang][driver] Add support for `-D`, `-U`

2020-12-21 Thread Faris via Phabricator via cfe-commits
FarisRehman marked 2 inline comments as done.
FarisRehman added inline comments.



Comment at: flang/lib/Frontend/CompilerInvocation.cpp:205
+/// Collect the macro definitions provided by the given preprocessor
+/// options into the parser options.
+void collectMacroDefinitions(

awarzynski wrote:
> This is not quite true, because you're collecting them into preprocessor 
> options :)
Added a comment to clarify the input and output arguments in the latest 
revision  


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93401/new/

https://reviews.llvm.org/D93401

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D93401: [flang][driver] Add support for `-D`, `-U`

2020-12-21 Thread Faris via Phabricator via cfe-commits
FarisRehman marked an inline comment as done.
FarisRehman added inline comments.



Comment at: flang/lib/Frontend/CompilerInvocation.cpp:228
+  // Note: GCC drops anything following an end-of-line character.
+  llvm::StringRef::size_type End = MacroBody.find_first_of("\n\r");
+  MacroBody = MacroBody.substr(0, End);

tskeith wrote:
> This is a change in behavior from f18, right? If so, the commit message 
> should mention it and why it's changing.
Updated the summary to address this, thanks


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93401/new/

https://reviews.llvm.org/D93401

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D93401: [flang][driver] Add support for `-D`, `-U`

2020-12-21 Thread Faris via Phabricator via cfe-commits
FarisRehman updated this revision to Diff 313108.
FarisRehman edited the summary of this revision.
FarisRehman added a comment.

Address review comments

Address comments with the following changes:

- Add a dedicated method to adding preprocessing options in Flang.cpp
- Change preprocessorOpts to use std::shared_ptr
- Separate SetDefaultFortranOpts from SetFortranOpts in CompilerInvocation
- Fix method and variable naming in CompilerInvocation.cpp
- Add comments to new methods and fields
- Add missing file header to PreprocessorOptions.h
- Remove unnecessary changes and method calls
- Add a regression test to check end-of-line character behaviour in a macro 
definition


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93401/new/

https://reviews.llvm.org/D93401

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/lib/Driver/ToolChains/Flang.h
  flang/include/flang/Frontend/CompilerInstance.h
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInstance.cpp
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/macro_def_undef.f90
  flang/test/Flang-Driver/macro_multiline.f90

Index: flang/test/Flang-Driver/macro_multiline.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/macro_multiline.f90
@@ -0,0 +1,26 @@
+! Ensure \n and anything that follows after in a macro definition (-D) is ignored.
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: printf -- "-DX=A\nTHIS_SHOULD_NOT_EXIST_IN_THE_OUTPUT\n" | xargs %flang-new -E %s  2>&1 | FileCheck -strict-whitespace %s
+
+!-
+!   FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: printf -- "-DX=A\nTHIS_SHOULD_NOT_EXIST_IN_THE_OUTPUT\n" | xargs %flang-new -fc1 -E %s  2>&1 | FileCheck -strict-whitespace %s
+
+
+!---
+! EXPECTED OUTPUT FOR MACRO 'X'
+!---
+! printf -- "-DX=A\nTHIS_SHOULD_NOT_EXIST_IN_THE_OUTPUT\n" | xargs flang-new -E %s
+! CHECK:program a
+! CHECK-NOT:program x
+! CHECK-NEXT:end
+
+! Macro.F:
+program X
+end
\ No newline at end of file
Index: flang/test/Flang-Driver/macro_def_undef.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/macro_def_undef.f90
@@ -0,0 +1,43 @@
+! Ensure arguments -D and -U work as expected.
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -E %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
+! RUN: %flang-new -E -DX=A %s  2>&1 | FileCheck %s --check-prefix=DEFINED
+! RUN: %flang-new -E -DX=A -UX %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
+
+!-
+!   FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang-new -fc1 -E %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
+! RUN: %flang-new -fc1 -E -DX=A %s  2>&1 | FileCheck %s --check-prefix=DEFINED
+! RUN: %flang-new -fc1 -E -DX -UX %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
+
+
+!
+! EXPECTED OUTPUT FOR AN UNDEFINED MACRO
+!
+! flang-new -E %s
+! flang-new -E -DX=A -UX %s
+! UNDEFINED:program b
+! UNDEFINED-NOT:program x
+! UNDEFINED-NEXT:end
+
+!
+! EXPECTED OUTPUT FOR MACRO 'X' DEFINED AS A
+!
+! flang-new -E -DX=A %s
+! DEFINED:program a
+! DEFINED-NOT:program b
+! DEFINED-NEXT:end
+
+! Macro.F:
+#ifdef X
+program X
+#else
+program B
+#endif
+end
\ No newline at end of file
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -19,11 +19,13 @@
 ! HELP-EMPTY:
 ! HELP-NEXT:OPTIONS:
 ! HELP-NEXT: -###   Print (but do not run) the commands to run for this compilation
+! HELP-NEXT: -D = Define  to  (or 1 if  omitted)
 ! HELP-NEXT: -E Only run the preprocessor
 ! HELP-NEXT: -fcolor-diagnosticsEnable colors in diagnostics
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! HELP-NEXT: -help  Display available options
 ! HELP-NEXT: -o   Write output to 
+! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
 
 !-
@@ -32,10 +34,12 @@
 ! HELP-FC1:USAGE: flang-new
 ! 

[PATCH] D93453: [flang][driver] Add support for `-I`

2020-12-17 Thread Faris via Phabricator via cfe-commits
FarisRehman created this revision.
Herald added a reviewer: sscalpone.
Herald added a subscriber: dang.
FarisRehman requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add support for option -I in the Flang driver.
This will allow for included headers in other directories, as the default 
search path is currently the working folder.
The behaviour of this is consistent with the current F18 
 driver.

Summary of changes:

- Add SearchDirectoriesFromI to PreprocessorOptions, to be forwarded into the 
parser's searchDirectories


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93453

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp


Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -165,6 +165,10 @@
   opts.addMacroUndef(A->getValue());
 }
   }
+
+  // Add the ordered list of -I's.
+  for (const auto *A : args.filtered(clang::driver::options::OPT_I))
+opts.SearchDirectoriesFromI.emplace_back(A->getValue());
 }
 
 bool CompilerInvocation::CreateFromArgs(CompilerInvocation ,
@@ -237,10 +241,15 @@
   auto  = fortranOpts();
   const auto  = preprocessorOpts();
 
-  // These defaults are based on the defaults in f18/f18.cpp.
-  std::vector searchDirectories{"."s};
-  fortranOptions.searchDirectories = searchDirectories;
   fortranOptions.isFixedForm = false;
 
   collectMacroDefinitions(fortranOptions, preprocessorOptions);
+
+  // These defaults are based on the defaults in f18/f18.cpp.
+  std::vector searchDirectories{"."s};
+  for (const auto  :
+  preprocessorOptions.SearchDirectoriesFromI) {
+searchDirectories.emplace_back(searchDirectoryFromI);
+  }
+  fortranOptions.searchDirectories = searchDirectories;
 }
Index: flang/include/flang/Frontend/PreprocessorOptions.h
===
--- flang/include/flang/Frontend/PreprocessorOptions.h
+++ flang/include/flang/Frontend/PreprocessorOptions.h
@@ -10,6 +10,7 @@
 class PreprocessorOptions {
 public:
   std::vector> Macros;
+  std::vector SearchDirectoriesFromI;
 
 public:
   PreprocessorOptions() {}
Index: clang/lib/Driver/ToolChains/Flang.cpp
===
--- clang/lib/Driver/ToolChains/Flang.cpp
+++ clang/lib/Driver/ToolChains/Flang.cpp
@@ -72,6 +72,8 @@
   }
   Args.ClaimAllArgs(options::OPT_D);
 
+  Args.AddAllArgs(CmdArgs, options::OPT_I);
+
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
 CmdArgs.push_back(Output.getFilename());
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -661,7 +661,7 @@
 HelpText<"Restrict all prior -I flags to double-quoted inclusion and "
  "remove current directory from include path">;
 def I : JoinedOrSeparate<["-"], "I">, Group,
-Flags<[CC1Option,CC1AsOption]>, MetaVarName<"">,
+Flags<[CC1Option,CC1AsOption,FlangOption,FC1Option]>, MetaVarName<"">,
 HelpText<"Add directory to include search path. If there are multiple -I "
  "options, these directories are searched in the order they are "
  "given before the standard system directories are searched. "


Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -165,6 +165,10 @@
   opts.addMacroUndef(A->getValue());
 }
   }
+
+  // Add the ordered list of -I's.
+  for (const auto *A : args.filtered(clang::driver::options::OPT_I))
+opts.SearchDirectoriesFromI.emplace_back(A->getValue());
 }
 
 bool CompilerInvocation::CreateFromArgs(CompilerInvocation ,
@@ -237,10 +241,15 @@
   auto  = fortranOpts();
   const auto  = preprocessorOpts();
 
-  // These defaults are based on the defaults in f18/f18.cpp.
-  std::vector searchDirectories{"."s};
-  fortranOptions.searchDirectories = searchDirectories;
   fortranOptions.isFixedForm = false;
 
   collectMacroDefinitions(fortranOptions, preprocessorOptions);
+
+  // These defaults are based on the defaults in f18/f18.cpp.
+  std::vector searchDirectories{"."s};
+  for (const auto  :
+  preprocessorOptions.SearchDirectoriesFromI) {
+searchDirectories.emplace_back(searchDirectoryFromI);
+  }
+  fortranOptions.searchDirectories = searchDirectories;
 }
Index: flang/include/flang/Frontend/PreprocessorOptions.h
===
--- flang/include/flang/Frontend/PreprocessorOptions.h
+++ 

[PATCH] D93401: [flang][driver] Add support for `-D`, `-U`

2020-12-16 Thread Faris via Phabricator via cfe-commits
FarisRehman created this revision.
Herald added a reviewer: sscalpone.
Herald added a subscriber: dang.
FarisRehman requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add support for options -D and -U in the Flang driver along with a regression 
test for them.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93401

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInstance.h
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/include/flang/Frontend/PreprocessorOptions.h
  flang/lib/Frontend/CompilerInstance.cpp
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/test/Flang-Driver/driver-help-hidden.f90
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/macro.f90

Index: flang/test/Flang-Driver/macro.f90
===
--- /dev/null
+++ flang/test/Flang-Driver/macro.f90
@@ -0,0 +1,49 @@
+! Ensure arguments -D and -U work as expected.
+
+! REQUIRES: new-flang-driver
+
+!--
+! FLANG DRIVER (flang-new)
+!--
+! RUN: %flang-new -E %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
+! RUN: %flang-new -E -DNEW %s  2>&1 | FileCheck %s --check-prefix=DEFINED
+! RUN: %flang-new -E -DNEW -UNEW %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
+
+!-
+!   FRONTEND FLANG DRIVER (flang-new -fc1)
+!-
+! RUN: %flang-new -fc1 -E %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
+! RUN: %flang-new -fc1 -E -DNEW %s  2>&1 | FileCheck %s --check-prefix=DEFINED
+! RUN: %flang-new -fc1 -E -DNEW -UNEW %s  2>&1 | FileCheck %s --check-prefix=UNDEFINED
+
+
+!
+! EXPECTED OUTPUT FOR MACRO 'NEW' UNDEFINED
+!
+! flang-new -E %s
+! flang-new -E -DNEW -UNEW %s
+! UNDEFINED:program b
+! UNDEFINED-NOT:program a
+! UNDEFINED-NEXT:x = 1
+! UNDEFINED-NEXT:write(*,*) x
+! UNDEFINED-NEXT:end
+
+!
+! EXPECTED OUTPUT FOR MACRO 'NEW' DEFINED
+!
+! flang-new -E -DNEW %s
+! DEFINED:program a
+! DEFINED-NOT:program b
+! DEFINED-NEXT:x = 1
+! DEFINED-NEXT:write(*,*) x
+! DEFINED-NEXT:end
+
+! Macro.F:
+#ifdef NEW
+program A
+#else
+program B
+#endif
+  x = 1
+  write(*,*) x
+end
\ No newline at end of file
Index: flang/test/Flang-Driver/driver-help.f90
===
--- flang/test/Flang-Driver/driver-help.f90
+++ flang/test/Flang-Driver/driver-help.f90
@@ -19,11 +19,13 @@
 ! HELP-EMPTY:
 ! HELP-NEXT:OPTIONS:
 ! HELP-NEXT: -###   Print (but do not run) the commands to run for this compilation
+! HELP-NEXT: -D = Define  to  (or 1 if  omitted)
 ! HELP-NEXT: -E Only run the preprocessor
 ! HELP-NEXT: -fcolor-diagnosticsEnable colors in diagnostics
 ! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! HELP-NEXT: -help  Display available options
 ! HELP-NEXT: -o   Write output to 
+! HELP-NEXT: -U  Undefine macro 
 ! HELP-NEXT: --version  Print version information
 
 !-
@@ -32,10 +34,12 @@
 ! HELP-FC1:USAGE: flang-new
 ! HELP-FC1-EMPTY:
 ! HELP-FC1-NEXT:OPTIONS:
-! HELP-FC1-NEXT: -EOnly run the preprocessor
-! HELP-FC1-NEXT: -help Display available options
-! HELP-FC1-NEXT: -o  Write output to 
-! HELP-FC1-NEXT: --version Print version information
+! HELP-FC1-NEXT: -D = Define  to  (or 1 if  omitted)
+! HELP-FC1-NEXT: -E Only run the preprocessor
+! HELP-FC1-NEXT: -help  Display available options
+! HELP-FC1-NEXT: -o   Write output to 
+! HELP-FC1-NEXT: -U  Undefine macro 
+! HELP-FC1-NEXT: --version  Print version information
 
 !---
 ! EXPECTED ERROR
Index: flang/test/Flang-Driver/driver-help-hidden.f90
===
--- flang/test/Flang-Driver/driver-help-hidden.f90
+++ flang/test/Flang-Driver/driver-help-hidden.f90
@@ -19,12 +19,14 @@
 ! CHECK-EMPTY:
 ! CHECK-NEXT:OPTIONS:
 ! CHECK-NEXT: -###  Print (but do not run) the commands to run for this compilation
+! CHECK-NEXT: -D = Define  to  (or 1 if  omitted)
 ! CHECK-NEXT: -EOnly run the preprocessor
 ! CHECK-NEXT: -fcolor-diagnosticsEnable colors in diagnostics
 ! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
 ! CHECK-NEXT: -help Display available options
 ! CHECK-NEXT: -o  Write output to 
 ! CHECK-NEXT: -test-io  Run the InputOuputTest action. Use for development and testing only.
+! CHECK-NEXT: -U  Undefine macro 
 ! CHECK-NEXT: --version Print version