-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[flang] Correctly handle -mframe-pointer=reserved #146937
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
@llvm/pr-subscribers-flang-driver @llvm/pr-subscribers-flang-fir-hlfir Author: Daniel Paoliello (dpaoliello) ChangesFixes #146582 started using the This change adds support for Full diff: https://github.com/llvm/llvm-project/pull/146937.diff 3 Files Affected:
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp
index 30d81f3daa969..c4d334c4b6de9 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -291,13 +291,14 @@ static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts,
opts.AliasAnalysis = opts.OptimizationLevel > 0;
- // -mframe-pointer=none/non-leaf/all option.
+ // -mframe-pointer=none/non-leaf/reserved/all option.
if (const llvm::opt::Arg *a =
args.getLastArg(clang::driver::options::OPT_mframe_pointer_EQ)) {
std::optional<llvm::FramePointerKind> val =
llvm::StringSwitch<std::optional<llvm::FramePointerKind>>(a->getValue())
.Case("none", llvm::FramePointerKind::None)
.Case("non-leaf", llvm::FramePointerKind::NonLeaf)
+ .Case("reserved", llvm::FramePointerKind::Reserved)
.Case("all", llvm::FramePointerKind::All)
.Default(std::nullopt);
diff --git a/flang/lib/Optimizer/Passes/Pipelines.cpp b/flang/lib/Optimizer/Passes/Pipelines.cpp
index 42d9e7ba2418f..dca176abe5ec5 100644
--- a/flang/lib/Optimizer/Passes/Pipelines.cpp
+++ b/flang/lib/Optimizer/Passes/Pipelines.cpp
@@ -358,6 +358,8 @@ void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm,
framePointerKind = mlir::LLVM::framePointerKind::FramePointerKind::NonLeaf;
else if (config.FramePointerKind == llvm::FramePointerKind::All)
framePointerKind = mlir::LLVM::framePointerKind::FramePointerKind::All;
+ else if (config.FramePointerKind == llvm::FramePointerKind::Reserved)
+ framePointerKind = mlir::LLVM::framePointerKind::FramePointerKind::Reserved;
else
framePointerKind = mlir::LLVM::framePointerKind::FramePointerKind::None;
diff --git a/flang/test/Driver/func-attr.f90 b/flang/test/Driver/func-attr.f90
index 7442ac54dcaa5..e8cab4fca2226 100644
--- a/flang/test/Driver/func-attr.f90
+++ b/flang/test/Driver/func-attr.f90
@@ -4,6 +4,7 @@
! RUN: %flang_fc1 -triple aarch64-none-none -mframe-pointer=none -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefix=CHECK-NONEFP
! RUN: %flang_fc1 -triple aarch64-none-none -mframe-pointer=non-leaf -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefix=CHECK-NONLEAFFP
+! RUN: %flang_fc1 -triple aarch64-none-none -mframe-pointer=reserved -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefix=CHECK-RESERVEDFP
! RUN: %flang_fc1 -triple aarch64-none-none -mframe-pointer=all -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefix=CHECK-ALLFP
! RUN: not %flang_fc1 -triple aarch64-none-none -mframe-pointer=wrongval -emit-llvm -o - %s 2>&1| FileCheck %s --check-prefix=CHECK-WRONGVALUEFP
@@ -20,6 +21,7 @@ end subroutine func
! CHECK-NONEFP-NOT: attributes #0 = { "frame-pointer"="{{.*}}" }
! CHECK-NONLEAFFP: attributes #0 = { "frame-pointer"="non-leaf" }
+! CHECK-RESERVEDFP: attributes #0 = { "frame-pointer"="reserved" }
! CHECK-ALLFP: attributes #0 = { "frame-pointer"="all" }
! CHECK-WRONGVALUEFP:error: invalid value 'wrongval' in '-mframe-pointer=wrongval'
|
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.
Thanks for this. This LGTM, but please wait for @DavidTruby
Fixes
#146802
#146582 started using the
Reserved
Frame Pointer kind for Arm64 Windows, but this revealed a bug in Flang where it copied the-mframe-pointer=reserved
flag from Clang, but didn't correctly handle it in its own command line parser and subsequent compilation pipeline.This change adds support for
-mframe-pointer=reserved
and adds a test to make sure that functions are correctly marked when the flag is set.