[PATCH] D96344: [flang][driver] Add options for -fdefault* and -flarge-sizes

Tim Keith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 17 10:11:24 PST 2021


tskeith added inline comments.


================
Comment at: flang/lib/Frontend/CompilerInvocation.cpp:254
+  if (args.hasArg(clang::driver::options::OPT_fdefault_real_8))
+    res.defaultKinds().set_defaultRealKind(8);
+  if (args.hasArg(clang::driver::options::OPT_fdefault_integer_8)) {
----------------
awarzynski wrote:
> arnamoy10 wrote:
> > awarzynski wrote:
> > > From `gfortran` [[ https://gcc.gnu.org/onlinedocs/gfortran/Fortran-Dialect-Options.html | documentation ]]:
> > > 
> > > ```
> > > This option promotes the default width of DOUBLE PRECISION and double real constants like 1.d0 to 16 bytes if possible.
> > > ```
> > > 
> > > So I believe that you are missing:
> > > ```
> > > res.defaultKinds().set_doublePrecisionKind(16);
> > > ```
> > I thought it is not necessary because `doublePrecisionKind` is automatically initialized to double the size of `defaultRealKind_` in [[ https://github.com/llvm/llvm-project/blob/adfd3c7083f9808d145239153c10f72eece485d8/flang/include/flang/Common/default-kinds.h#L51-L58 | here ]]--> `int doublePrecisionKind_{2 * defaultRealKind_};`. 
> > 
> > 
> Yes, but the default value for `defaultRealKind_` is 4 and here you are setting it to 8. So, correct me if I'm wrong, but when the driver is here, the following has happened:
> ```
> int defaultIntegerKind_{4};
> int defaultRealKind_{defaultIntegerKind_};
> int doublePrecisionKind_{2 * defaultRealKind_};
> ```
> So `dublePrecisionKind_` is 8 rather than 16.
You can test these are working correctly by compiling a module like this:
```
module m
  implicit none
  real :: x
  double precision :: y
  integer, parameter :: real_kind = kind(x)
  integer, parameter :: double_kind = kind(y)
end
```
Then check for `double_kind=8_4` (or whatever) in the generated `.mod` file.

For `-flarge-sizes`:
```
  real :: z(10)
  integer, parameter :: size_kind = kind(ubound(z, 1))
```


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

https://reviews.llvm.org/D96344



More information about the cfe-commits mailing list