[flang-commits] [clang] [flang] [flang] Support -funsafe-cray-pointers (PR #172252)

Eugene Epshteyn via flang-commits flang-commits at lists.llvm.org
Sun Dec 14 21:57:54 PST 2025


https://github.com/eugeneepshteyn created https://github.com/llvm/llvm-project/pull/172252

If -funsafe-cray-pointers is passed to flang driver, pass '-mmlir -funsafe-cray-pointers' to the compiler.

>From 509af02a62af56d688d2325bfffc73272933652c Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Mon, 15 Dec 2025 00:56:23 -0500
Subject: [PATCH] [flang] Support -funsafe-cray-pointers

If -funsafe-cray-pointers is passed to flang driver, pass
'-mmlir -funsafe-cray-pointers' to the compiler.
---
 clang/include/clang/Options/Options.td     | 4 ++++
 clang/lib/Driver/ToolChains/Flang.cpp      | 5 +++++
 flang/test/Driver/unsafe-cray-pointers.f90 | 4 ++++
 3 files changed, 13 insertions(+)
 create mode 100644 flang/test/Driver/unsafe-cray-pointers.f90

diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index 45c5322351a17..10feb01752e90 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -7453,6 +7453,10 @@ By default, the heap is used. Allocations of polymorphic types
 are always done on the heap, though this may change in future releases.
   }]>;
 
+defm unsafe_cray_pointers : BoolOptionWithoutMarshalling<"f", "unsafe-cray-pointers",
+  PosFlag<SetTrue, [], [FlangOption, FC1Option], "Optimizations allow for unsafe Cray pointer usages">,
+  NegFlag<SetFalse, [], [FlangOption, FC1Option], "Optimizations don't allow for unsafe Cray pointer usages (default)">>;
+
 def fhermetic_module_files : Flag<["-"], "fhermetic-module-files">, Group<f_Group>,
   HelpText<"Emit hermetic module files (no nested USE association)">;
 
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp
index 2f5e93d139858..5470cc6c9bf86 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -201,6 +201,11 @@ void Flang::addCodegenOptions(const ArgList &Args,
       !stackArrays->getOption().matches(options::OPT_fno_stack_arrays))
     CmdArgs.push_back("-fstack-arrays");
 
+  if (Args.hasFlag(options::OPT_funsafe_cray_pointers,
+                   options::OPT_fno_unsafe_cray_pointers, false))
+    // TODO: currently passed as MLIR option
+    CmdArgs.push_back("-mmlir -funsafe-cray-pointers"); 
+
   Args.addOptInFlag(CmdArgs, options::OPT_fexperimental_loop_fusion,
                     options::OPT_fno_experimental_loop_fusion);
 
diff --git a/flang/test/Driver/unsafe-cray-pointers.f90 b/flang/test/Driver/unsafe-cray-pointers.f90
new file mode 100644
index 0000000000000..b67dfc6da0fe2
--- /dev/null
+++ b/flang/test/Driver/unsafe-cray-pointers.f90
@@ -0,0 +1,4 @@
+! RUN: %flang -funsafe-cray-pointers -### %s 2>&1 | FileCheck %s
+
+! CHECK: "-mmlir -funsafe-cray-pointers"
+! CHECK-NOT: "-mmlir -funsafe-cray-pointers"



More information about the flang-commits mailing list