-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[flang] Support -funsafe-cray-pointers #172252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
If -funsafe-cray-pointers is passed to flang driver, pass '-mmlir -funsafe-cray-pointers' to the compiler.
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
|
@llvm/pr-subscribers-flang-driver @llvm/pr-subscribers-clang-driver Author: Eugene Epshteyn (eugeneepshteyn) ChangesIf -funsafe-cray-pointers is passed to flang driver, pass '-mmlir -funsafe-cray-pointers' to the compiler. Full diff: https://github.com/llvm/llvm-project/pull/172252.diff 3 Files Affected:
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
index c38bdd06057a2..9c3b284c4967c 100644
--- a/clang/include/clang/Options/Options.td
+++ b/clang/include/clang/Options/Options.td
@@ -7457,6 +7457,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..4e7ab2cf6edc3 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -201,6 +201,13 @@ 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");
+ CmdArgs.push_back("-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..bd8cafc1602f3
--- /dev/null
+++ b/flang/test/Driver/unsafe-cray-pointers.f90
@@ -0,0 +1,5 @@
+! RUN: %flang -funsafe-cray-pointers -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-ON
+! RUN: %flang -fno-unsafe-cray-pointers -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-OFF
+
+! CHECK-ON: "-mmlir" "-funsafe-cray-pointers"
+! CHECK-OFF-NOT: "-mmlir" "-funsafe-cray-pointers"
|
vzakhari
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
If
-funsafe-cray-pointersis passed to flang driver, pass-mmlir -funsafe-cray-pointersto the compiler. This should make it easier to work with the code that relies on behavior before #170908