[flang-commits] [flang] b81c507 - [flang] add -flang-experimental-polymorphism flag to flang-new

David Truby via flang-commits flang-commits at lists.llvm.org
Thu Jun 22 08:21:39 PDT 2023


Author: David Truby
Date: 2023-06-22T16:21:09+01:00
New Revision: b81c5070d5451af127b2c9c2ae362ba1b0a96c01

URL: https://github.com/llvm/llvm-project/commit/b81c5070d5451af127b2c9c2ae362ba1b0a96c01
DIFF: https://github.com/llvm/llvm-project/commit/b81c5070d5451af127b2c9c2ae362ba1b0a96c01.diff

LOG: [flang] add -flang-experimental-polymorphism flag to flang-new

This flag enables Fortran 2003 polymorphism. It is marked experimental
and not included in --help.

Reviewed By: tblah, awarzynski

Differential Revision: https://reviews.llvm.org/D153281

Added: 
    flang/test/Driver/flang-experimental-polymorphism-flag.f90

Modified: 
    clang/include/clang/Driver/Options.td
    clang/lib/Driver/ToolChains/Flang.cpp
    flang/lib/Frontend/CompilerInvocation.cpp
    flang/test/Driver/driver-help-hidden.f90
    flang/test/Driver/frontend-forwarding.f90

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 69239e6cf296d..53c107b0f0fb0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5283,6 +5283,11 @@ def flang_experimental_hlfir : Flag<["-"], "flang-experimental-hlfir">,
   Flags<[FlangOption, FC1Option, FlangOnlyOption, NoXarchOption, HelpHidden]>,
   HelpText<"Use HLFIR lowering (experimental)">;
 
+def flang_experimental_polymorphism : Flag<["-"], "flang-experimental-polymorphism">,
+  Flags<[FlangOption, FC1Option, FlangOnlyOption, NoXarchOption, HelpHidden]>,
+  HelpText<"Enable Fortran 2003 polymorphism (experimental)">;
+  
+
 //===----------------------------------------------------------------------===//
 // FLangOption + CoreOption + NoXarchOption
 //===----------------------------------------------------------------------===//

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 9a2ddf777cd7f..75b9524a0c72e 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -140,6 +140,8 @@ void Flang::addCodegenOptions(const ArgList &Args,
 
   if (Args.hasArg(options::OPT_flang_experimental_hlfir))
     CmdArgs.push_back("-flang-experimental-hlfir");
+  if (Args.hasArg(options::OPT_flang_experimental_polymorphism))
+    CmdArgs.push_back("-flang-experimental-polymorphism");
   if (shouldLoopVersion(Args))
     CmdArgs.push_back("-fversion-loops-for-stride");
 }

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 610f60c5899bb..f8a075ce5f949 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -920,6 +920,10 @@ bool CompilerInvocation::createFromArgs(
     res.loweringOpts.setLowerToHighLevelFIR(true);
   }
 
+  if (args.hasArg(clang::driver::options::OPT_flang_experimental_polymorphism)) {
+    res.loweringOpts.setPolymorphicTypeImpl(true);
+  }
+
   success &= parseFrontendArgs(res.getFrontendOpts(), args, diags);
   parseTargetArgs(res.getTargetOpts(), args);
   parsePreprocessorArgs(res.getPreprocessorOpts(), args);

diff  --git a/flang/test/Driver/driver-help-hidden.f90 b/flang/test/Driver/driver-help-hidden.f90
index d8b1a03d4c0d9..a3fe2f09c0703 100644
--- a/flang/test/Driver/driver-help-hidden.f90
+++ b/flang/test/Driver/driver-help-hidden.f90
@@ -41,6 +41,8 @@
 ! CHECK-NEXT:                        Specify where to find the compiled intrinsic modules
 ! CHECK-NEXT: -flang-experimental-hlfir
 ! CHECK-NEXT:                        Use HLFIR lowering (experimental)
+! CHECK-NEXT: -flang-experimental-polymorphism
+! CHECK-NEXT:                        Enable Fortran 2003 polymorphism (experimental)
 ! CHECK-NEXT: -flarge-sizes          Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! CHECK-NEXT: -flto=<value> Set LTO mode

diff  --git a/flang/test/Driver/flang-experimental-polymorphism-flag.f90 b/flang/test/Driver/flang-experimental-polymorphism-flag.f90
new file mode 100644
index 0000000000000..106e898149a18
--- /dev/null
+++ b/flang/test/Driver/flang-experimental-polymorphism-flag.f90
@@ -0,0 +1,10 @@
+! Test -flang-experimental-hlfir flag
+! RUN: %flang_fc1 -flang-experimental-polymorphism -emit-fir -o - %s | FileCheck %s
+! RUN: not %flang_fc1 -emit-fir -o - %s 2>&1 | FileCheck %s --check-prefix NO-POLYMORPHISM
+
+! CHECK: func.func @_QPtest(%{{.*}}: !fir.class<none> {fir.bindc_name = "poly"})
+subroutine test(poly)
+  class(*) :: poly
+end subroutine test
+
+! NO-POLYMORPHISM: not yet implemented: support for polymorphic types

diff  --git a/flang/test/Driver/frontend-forwarding.f90 b/flang/test/Driver/frontend-forwarding.f90
index ddee84bac106c..e953c957d2d00 100644
--- a/flang/test/Driver/frontend-forwarding.f90
+++ b/flang/test/Driver/frontend-forwarding.f90
@@ -16,7 +16,7 @@
 ! RUN:     -freciprocal-math \
 ! RUN:     -fpass-plugin=Bye%pluginext \
 ! RUN:     -fversion-loops-for-stride \
-! RUN:     -mllvm -print-before-all\
+! RUN:     -flang-experimental-polymorphism \
 ! RUN:     -mllvm -print-before-all \
 ! RUN:     -save-temps=obj \
 ! RUN:     -P \
@@ -36,6 +36,7 @@
 ! CHECK: "-freciprocal-math"
 ! CHECK: "-fconvert=little-endian"
 ! CHECK: "-fpass-plugin=Bye
-! CHECK: "-fversion-loops-for-stride"  
+! CHECK: "-flang-experimental-polymorphism"
+! CHECK: "-fversion-loops-for-stride"
 ! CHECK: "-mllvm" "-print-before-all"
 ! CHECK: "-save-temps=obj"


        


More information about the flang-commits mailing list