[flang-commits] [clang] [flang] [flang][driver] Add options -fdefault-integer-4 and -fdefault-real-4 (PR #172323)

Tarun Prabhu via flang-commits flang-commits at lists.llvm.org
Tue Dec 16 07:42:20 PST 2025


================
@@ -1086,15 +1086,35 @@ static bool parseDialectArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
   }
 
   // -fdefault* family
-  if (args.hasArg(clang::options::OPT_fdefault_real_8)) {
-    res.getDefaultKinds().set_defaultRealKind(8);
-    res.getDefaultKinds().set_doublePrecisionKind(16);
+  if (const llvm::opt::Arg *arg =
+          args.getLastArg(clang::options::OPT_fdefault_real_8,
+                          clang::options::OPT_fdefault_real_4)) {
+    const llvm::opt::Option &opt = arg->getOption();
+    if (opt.matches(clang::options::OPT_fdefault_real_8)) {
+      res.getDefaultKinds().set_defaultRealKind(8);
+      res.getDefaultKinds().set_doublePrecisionKind(16);
----------------
tarunprabhu wrote:

There PR does not change the behavior of `-fdefault-real-8`, so `flang` will continue to behave as it would have before.

```
program test
  implicit none
  double precision :: n

  write(*,*) acos(n)
end program test
```

If I compile the code above on a machine without support for `real(16)`, I get this:

```
flang -fdefault-real-8 -o /tmp/a.out -O2 /tmp/test.f90 && /tmp/a.out
/usr/bin/ld: /tmp/double-0c6305.o: in function `_QQmain':
FIRModule:(.text+0x1f): undefined reference to `_FortranAAcosF128'
/usr/bin/ld: /tmp/double-0c6305.o: in function `main':
FIRModule:(.text+0x96): undefined reference to `_FortranAAcosF128'
```

It may be a better user experience to emit a  warning - or even an error - `-fdefault-real-8` is used on a target that does not support `real(16)`. IMO, that is an unrelated change that should be deferred to a different PR.

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


More information about the flang-commits mailing list