[PATCH] D43108: Support for the mno-stack-arg-probe flag

2018-03-01 Thread Ruslan Nikolaev via Phabricator via cfe-commits
nruslan added a comment.

@aemerson : yes, it is just part of MS ABI


Repository:
  rC Clang

https://reviews.llvm.org/D43108



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43108: Support for the mno-stack-arg-probe flag

2018-03-01 Thread Amara Emerson via Phabricator via cfe-commits
aemerson added a comment.

In https://reviews.llvm.org/D43108#1023300, @nruslan wrote:

> By default, stack probes are enabled (i.e., -mstack-arg-probe is the default 
> behavior) and have the size of 4K in x86.


This part what I wanted to clarify, `-mstack-probe-arg` is enabling stack 
probes if the ABI requires it only, not for other reasons like security.


Repository:
  rC Clang

https://reviews.llvm.org/D43108



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43108: Support for the mno-stack-arg-probe flag

2018-02-28 Thread Ruslan Nikolaev via Phabricator via cfe-commits
nruslan added a comment.

@aemerson : I am not 100% sure, but I think you are talking about different 
flag. This commit is for supporting a flag to disable stack probes (identical 
flag can be found in MinGW), it basically only applies to PE/COFF (Windows) 
targets. It can be useful to compile UEFI code. By default, Windows will use 
check probes of 4K in x86. A related stack-probe-size allows to vary the size 
of stack probes. This one completely disables them.

By default, stack probes are enabled (i.e., -mstack-arg-probe is the default 
behavior) and have the size of 4K in x86.


Repository:
  rC Clang

https://reviews.llvm.org/D43108



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43108: Support for the mno-stack-arg-probe flag

2018-02-28 Thread Amara Emerson via Phabricator via cfe-commits
aemerson added a comment.

Can we clarify the meaning of this option a bit. The doc you've added here is 
saying that `-mno-stack-arg-probe` disables stack probes. Then what does 
`-mstack-arg-probe` mean specifically? Does it mean that only stack probes for 
ABI required reasons are enabled, or probes are done even in cases where the 
ABI doesn't require them? Either way, the doc needs to be clearer on the exact 
purpose.

I'm currently working on enabling stack probes for reasons other than ABI, and 
so if the answer is that this option is only concerned with ABI, we will need 
another option like `-fstack-check`.


Repository:
  rC Clang

https://reviews.llvm.org/D43108



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43108: Support for the mno-stack-arg-probe flag

2018-02-23 Thread Hans Wennborg via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC325901: Support for the mno-stack-arg-probe flag (authored 
by hans, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43108?vs=134377=135631#toc

Repository:
  rC Clang

https://reviews.llvm.org/D43108

Files:
  docs/ClangCommandLineReference.rst
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/TargetInfo.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/stack-arg-probe.c
  test/Driver/stack-arg-probe.c

Index: docs/ClangCommandLineReference.rst
===
--- docs/ClangCommandLineReference.rst
+++ docs/ClangCommandLineReference.rst
@@ -2192,6 +2192,10 @@
 
 Set the stack probe size
 
+.. option:: -mstack-arg-probe, -mno-stack-arg-probe
+
+Disable stack probes
+
 .. option:: -mstackrealign, -mno-stackrealign
 
 Force realign the stack at entry to every function
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1842,6 +1842,10 @@
   HelpText<"Set the stack alignment">;
 def mstack_probe_size : Joined<["-"], "mstack-probe-size=">, Group, Flags<[CC1Option]>,
   HelpText<"Set the stack probe size">;
+def mstack_arg_probe : Flag<["-"], "mstack-arg-probe">, Group,
+  HelpText<"Enable stack probes">;
+def mno_stack_arg_probe : Flag<["-"], "mno-stack-arg-probe">, Group, Flags<[CC1Option]>,
+  HelpText<"Disable stack probes which are enabled by default">;
 def mthread_model : Separate<["-"], "mthread-model">, Group, Flags<[CC1Option]>,
   HelpText<"The thread model to use, e.g. posix, single (posix by default)">, Values<"posix,single">;
 def meabi : Separate<["-"], "meabi">, Group, Flags<[CC1Option]>,
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -227,6 +227,7 @@
 ///< alignment, if not 0.
 VALUE_CODEGENOPT(StackProbeSize, 32, 4096) ///< Overrides default stack
///< probe size, even if 0.
+CODEGENOPT(NoStackArgProbe, 1, 0) ///< Set when -mno-stack-arg-probe is used
 CODEGENOPT(DebugColumnInfo, 1, 0) ///< Whether or not to use column information
   ///< in debug info.
 
Index: test/CodeGen/stack-arg-probe.c
===
--- test/CodeGen/stack-arg-probe.c
+++ test/CodeGen/stack-arg-probe.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -triple=i686-windows-msvc -emit-llvm -o - -mno-stack-arg-probe | FileCheck %s -check-prefix=NO-STACKPROBE
+// RUN: %clang_cc1 %s -triple=i686-windows-msvc -emit-llvm -o - | FileCheck %s -check-prefix=STACKPROBE
+
+// NO-STACKPROBE: attributes #{{[0-9]+}} = {{{.*}} "no-stack-arg-probe"
+// STACKPROBE-NOT: attributes #{{[0-9]+}} = {{{.*}} "no-stack-arg-probe"
+
+void test1() {
+}
Index: test/Driver/stack-arg-probe.c
===
--- test/Driver/stack-arg-probe.c
+++ test/Driver/stack-arg-probe.c
@@ -0,0 +1,7 @@
+// RUN: %clang -### %s 2>&1 | FileCheck %s -check-prefix=STACKPROBE
+// RUN: %clang -### -mno-stack-arg-probe -mstack-arg-probe %s 2>&1 | FileCheck %s -check-prefix=STACKPROBE
+// RUN: %clang -### -mstack-arg-probe -mno-stack-arg-probe %s 2>&1 | FileCheck %s -check-prefix=NO-STACKPROBE
+// REQUIRES: clang-driver
+
+// NO-STACKPROBE: -mno-stack-arg-probe
+// STACKPROBE-NOT: -mno-stack-arg-probe
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -4047,6 +4047,10 @@
   CmdArgs.push_back("-mstack-probe-size=0");
   }
 
+  if (!Args.hasFlag(options::OPT_mstack_arg_probe,
+options::OPT_mno_stack_arg_probe, true))
+CmdArgs.push_back(Args.MakeArgString("-mno-stack-arg-probe"));
+
   if (Arg *A = Args.getLastArg(options::OPT_mrestrict_it,
options::OPT_mno_restrict_it)) {
 if (A->getOption().matches(options::OPT_mrestrict_it)) {
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -923,6 +923,8 @@
 Opts.StackProbeSize = StackProbeSize;
   }
 
+  Opts.NoStackArgProbe = Args.hasArg(OPT_mno_stack_arg_probe);
+
   if (Arg *A = Args.getLastArg(OPT_fobjc_dispatch_method_EQ)) {
 StringRef Name = A->getValue();
 unsigned Method = llvm::StringSwitch(Name)
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp

[PATCH] D43108: Support for the mno-stack-arg-probe flag

2018-02-22 Thread Ruslan Nikolaev via Phabricator via cfe-commits
nruslan added a comment.

@hans, @craig.topper, @MatzeB: Can someone commit 
https://reviews.llvm.org/D43108 (this) and https://reviews.llvm.org/D43107 on 
my behalf? I do not think, I have commit access.


https://reviews.llvm.org/D43108



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43108: Support for the mno-stack-arg-probe flag

2018-02-16 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

This looks good to me.


https://reviews.llvm.org/D43108



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43108: Support for the mno-stack-arg-probe flag

2018-02-14 Thread Ruslan Nikolaev via Phabricator via cfe-commits
nruslan added a comment.

@hans: I responded to the comments and also updated diff for clang with new 
changes.


https://reviews.llvm.org/D43108



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43108: Support for the mno-stack-arg-probe flag

2018-02-14 Thread Ruslan Nikolaev via Phabricator via cfe-commits
nruslan added inline comments.



Comment at: lib/Driver/ToolChains/Clang.cpp:4038
+  if (Args.hasArg(options::OPT_mno_stack_arg_probe))
+CmdArgs.push_back("-mno-stack-arg-probe");
+

hans wrote:
> I think you can just do
> 
> ```
> Args.AddLastArg(CmdArgs, options::OPT_mno_stack_arg_probe)
> ```
> 
> which avoids the if-statement and having to spell out the flag.
I added mstack_arg_probe also, and this check now contains two options. I am 
not sure how AddLastArg behaves in this case (especially because only one 
attribute needs to be defined: mno-stack-arg-probe, and a positive case is the 
default). I found some other examples similar to this one, and they used hasArg 
with two options.


https://reviews.llvm.org/D43108



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43108: Support for the mno-stack-arg-probe flag

2018-02-14 Thread Ruslan Nikolaev via Phabricator via cfe-commits
nruslan updated this revision to Diff 134377.
nruslan marked 3 inline comments as done.
nruslan added a comment.

Added mstack-arg-probe, tests, and changes related to other comments of the 
reviewers


https://reviews.llvm.org/D43108

Files:
  docs/ClangCommandLineReference.rst
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/TargetInfo.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/stack-arg-probe.c
  test/Driver/stack-arg-probe.c

Index: test/Driver/stack-arg-probe.c
===
--- /dev/null
+++ test/Driver/stack-arg-probe.c
@@ -0,0 +1,7 @@
+// RUN: %clang -### %s 2>&1 | FileCheck %s -check-prefix=STACKPROBE
+// RUN: %clang -### -mno-stack-arg-probe -mstack-arg-probe %s 2>&1 | FileCheck %s -check-prefix=STACKPROBE
+// RUN: %clang -### -mstack-arg-probe -mno-stack-arg-probe %s 2>&1 | FileCheck %s -check-prefix=NO-STACKPROBE
+// REQUIRES: clang-driver
+
+// NO-STACKPROBE: -mno-stack-arg-probe
+// STACKPROBE-NOT: -mno-stack-arg-probe
Index: test/CodeGen/stack-arg-probe.c
===
--- /dev/null
+++ test/CodeGen/stack-arg-probe.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -triple=i686-windows-msvc -emit-llvm -o - -mno-stack-arg-probe | FileCheck %s -check-prefix=NO-STACKPROBE
+// RUN: %clang_cc1 %s -triple=i686-windows-msvc -emit-llvm -o - | FileCheck %s -check-prefix=STACKPROBE
+
+// NO-STACKPROBE: attributes #{{[0-9]+}} = {{{.*}} "no-stack-arg-probe"
+// STACKPROBE-NOT: attributes #{{[0-9]+}} = {{{.*}} "no-stack-arg-probe"
+
+void test1() {
+}
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -914,6 +914,8 @@
 Opts.StackProbeSize = StackProbeSize;
   }
 
+  Opts.NoStackArgProbe = Args.hasArg(OPT_mno_stack_arg_probe);
+
   if (Arg *A = Args.getLastArg(OPT_fobjc_dispatch_method_EQ)) {
 StringRef Name = A->getValue();
 unsigned Method = llvm::StringSwitch(Name)
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -4034,6 +4034,10 @@
   CmdArgs.push_back("-mstack-probe-size=0");
   }
 
+  if (!Args.hasFlag(options::OPT_mstack_arg_probe,
+options::OPT_mno_stack_arg_probe, true))
+CmdArgs.push_back(Args.MakeArgString("-mno-stack-arg-probe"));
+
   if (Arg *A = Args.getLastArg(options::OPT_mrestrict_it,
options::OPT_mno_restrict_it)) {
 if (A->getOption().matches(options::OPT_mrestrict_it)) {
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -2355,16 +2355,15 @@
   }
 };
 
-static void addStackProbeSizeTargetAttribute(const Decl *D,
- llvm::GlobalValue *GV,
- CodeGen::CodeGenModule ) {
-  if (D && isa(D)) {
-if (CGM.getCodeGenOpts().StackProbeSize != 4096) {
-  llvm::Function *Fn = cast(GV);
+static void addStackProbeTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
+  CodeGen::CodeGenModule ) {
+  if (llvm::Function *Fn = dyn_cast_or_null(GV)) {
 
+if (CGM.getCodeGenOpts().StackProbeSize != 4096)
   Fn->addFnAttr("stack-probe-size",
 llvm::utostr(CGM.getCodeGenOpts().StackProbeSize));
-}
+if (CGM.getCodeGenOpts().NoStackArgProbe)
+  Fn->addFnAttr("no-stack-arg-probe");
   }
 }
 
@@ -2374,7 +2373,7 @@
   X86_32TargetCodeGenInfo::setTargetAttributes(D, GV, CGM, IsForDefinition);
   if (!IsForDefinition)
 return;
-  addStackProbeSizeTargetAttribute(D, GV, CGM);
+  addStackProbeTargetAttributes(D, GV, CGM);
 }
 
 class WinX86_64TargetCodeGenInfo : public TargetCodeGenInfo {
@@ -2436,7 +2435,7 @@
 }
   }
 
-  addStackProbeSizeTargetAttribute(D, GV, CGM);
+  addStackProbeTargetAttributes(D, GV, CGM);
 }
 }
 
@@ -5622,7 +5621,7 @@
   ARMTargetCodeGenInfo::setTargetAttributes(D, GV, CGM, IsForDefinition);
   if (!IsForDefinition)
 return;
-  addStackProbeSizeTargetAttribute(D, GV, CGM);
+  addStackProbeTargetAttributes(D, GV, CGM);
 }
 }
 
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -223,6 +223,7 @@
 ///< alignment, if not 0.
 VALUE_CODEGENOPT(StackProbeSize, 32, 4096) ///< Overrides default stack
///< probe size, even if 0.
+CODEGENOPT(NoStackArgProbe, 1, 0) ///< Set when -mno-stack-arg-probe is used
 

[PATCH] D43108: Support for the mno-stack-arg-probe flag

2018-02-13 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In https://reviews.llvm.org/D43108#1005904, @nruslan wrote:

> @hans: One real-world example is when it is used to compile UEFI code using 
> PE/COFF targets natively. Obviously, UEFI uses ABI which is basically almost 
> the same as MS ABI, except that chkstk is not used. It mostly works (I 
> actually was able to get it running) except the cases when the code contains 
> variable-sized arrays allocated on stacks. Unfortunately, stack-probe-size 
> will only help with fixed sized array but will not help to solve the problem 
> described in the bug description since stack usage is unknown at compile 
> time. MinGW does not have this problem because it provides this flag.


I see, interesting. Might be worth mentioning in the commit message for others 
wondering what the flag is useful for.

> @MatzeB : there is a test on LLVM side (related review). Do you think the 
> test is needed for clang side? If so, please let me know, what kind of test 
> it is supposed to be.

Yes please, I think think there should be on in test/Driver/ to check that 
forwarding the flag to cc1 (and if we have a -mno-foo, there should maybe be a 
-mfoo variant too?), and a test in test/CodeGen/ to check that the attribute 
gets put on the functions correctly. Perhaps r321992 is a good example to look 
at.


Repository:
  rC Clang

https://reviews.llvm.org/D43108



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43108: Support for the mno-stack-arg-probe flag

2018-02-12 Thread Ruslan Nikolaev via Phabricator via cfe-commits
nruslan added a comment.

@hans: One real-world example is when it is used to compile UEFI code using 
PE/COFF targets natively. Obviously, UEFI uses ABI which is basically almost 
the same as MS ABI, except that chkstk is not used. It mostly works (I actually 
was able to get it running) except the cases when the code contains 
variable-sized arrays allocated on stacks. Unfortunately, stack-probe-size will 
only help with fixed sized array but will not help to solve the problem 
described in the bug description since stack usage is unknown at compile time. 
MinGW does not have this problem because it provides this flag.

@MatzeB : there is a test on LLVM side (related review). Do you think the test 
is needed for clang side? If so, please let me know, what kind of test it is 
supposed to be.


Repository:
  rC Clang

https://reviews.llvm.org/D43108



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43108: Support for the mno-stack-arg-probe flag

2018-02-12 Thread Matthias Braun via Phabricator via cfe-commits
MatzeB added a comment.

- No test.
- What about `-mstack-arg-probe`, shouldn't we have that for consistency?
- I'd prefer not to review clang changes myself as I don't know that part of 
the code too well.


Repository:
  rC Clang

https://reviews.llvm.org/D43108



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43108: Support for the mno-stack-arg-probe flag

2018-02-12 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

I see in the PR that matches a MinGW flag, but I'm curious to the motivation 
here. In what scenario would the user want to use this, i.e. how do they know 
it's safe to drop the probes?




Comment at: lib/CodeGen/TargetInfo.cpp:2358
 
-static void addStackProbeSizeTargetAttribute(const Decl *D,
- llvm::GlobalValue *GV,
- CodeGen::CodeGenModule ) {
+static void addStackProbeParamsTargetAttribute(const Decl *D,
+   llvm::GlobalValue *GV,

I'd suggest perhaps "addStackProbeTargetAttributes" as a name instead, since 
I'm not sure what Params is for.



Comment at: lib/CodeGen/TargetInfo.cpp:2361
+   CodeGen::CodeGenModule ) {
   if (D && isa(D)) {
+llvm::Function *Fn = cast(GV);

This could be written as

```
if (llvm::Function *Fn = dyn_cast_or_null(GV)) {
```



Comment at: lib/Driver/ToolChains/Clang.cpp:4038
+  if (Args.hasArg(options::OPT_mno_stack_arg_probe))
+CmdArgs.push_back("-mno-stack-arg-probe");
+

I think you can just do

```
Args.AddLastArg(CmdArgs, options::OPT_mno_stack_arg_probe)
```

which avoids the if-statement and having to spell out the flag.


Repository:
  rC Clang

https://reviews.llvm.org/D43108



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43108: Support for the mno-stack-arg-probe flag

2018-02-11 Thread Ruslan Nikolaev via Phabricator via cfe-commits
nruslan added a comment.

@craig.topper, @MatzeB, @hans: Can someone take a look at this change?


Repository:
  rC Clang

https://reviews.llvm.org/D43108



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43108: Support for the mno-stack-arg-probe flag

2018-02-08 Thread Ruslan Nikolaev via Phabricator via cfe-commits
nruslan created this revision.
nruslan added a reviewer: clang.
Herald added a subscriber: cfe-commits.

Adds support for this flag. There is also another piece for llvm (separate 
review). More info: https://bugs.llvm.org/show_bug.cgi?id=36221


Repository:
  rC Clang

https://reviews.llvm.org/D43108

Files:
  docs/ClangCommandLineReference.rst
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/TargetInfo.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp

Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -914,6 +914,8 @@
 Opts.StackProbeSize = StackProbeSize;
   }
 
+  Opts.NoStackArgProbe = Args.hasArg(OPT_mno_stack_arg_probe);
+
   if (Arg *A = Args.getLastArg(OPT_fobjc_dispatch_method_EQ)) {
 StringRef Name = A->getValue();
 unsigned Method = llvm::StringSwitch(Name)
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -4034,6 +4034,9 @@
   CmdArgs.push_back("-mstack-probe-size=0");
   }
 
+  if (Args.hasArg(options::OPT_mno_stack_arg_probe))
+CmdArgs.push_back("-mno-stack-arg-probe");
+
   if (Arg *A = Args.getLastArg(options::OPT_mrestrict_it,
options::OPT_mno_restrict_it)) {
 if (A->getOption().matches(options::OPT_mrestrict_it)) {
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -2355,16 +2355,17 @@
   }
 };
 
-static void addStackProbeSizeTargetAttribute(const Decl *D,
- llvm::GlobalValue *GV,
- CodeGen::CodeGenModule ) {
+static void addStackProbeParamsTargetAttribute(const Decl *D,
+   llvm::GlobalValue *GV,
+   CodeGen::CodeGenModule ) {
   if (D && isa(D)) {
-if (CGM.getCodeGenOpts().StackProbeSize != 4096) {
-  llvm::Function *Fn = cast(GV);
+llvm::Function *Fn = cast(GV);
 
+if (CGM.getCodeGenOpts().StackProbeSize != 4096)
   Fn->addFnAttr("stack-probe-size",
 llvm::utostr(CGM.getCodeGenOpts().StackProbeSize));
-}
+if (CGM.getCodeGenOpts().NoStackArgProbe)
+  Fn->addFnAttr("no-stack-arg-probe");
   }
 }
 
@@ -2374,7 +2375,7 @@
   X86_32TargetCodeGenInfo::setTargetAttributes(D, GV, CGM, IsForDefinition);
   if (!IsForDefinition)
 return;
-  addStackProbeSizeTargetAttribute(D, GV, CGM);
+  addStackProbeParamsTargetAttribute(D, GV, CGM);
 }
 
 class WinX86_64TargetCodeGenInfo : public TargetCodeGenInfo {
@@ -2436,7 +2437,7 @@
 }
   }
 
-  addStackProbeSizeTargetAttribute(D, GV, CGM);
+  addStackProbeParamsTargetAttribute(D, GV, CGM);
 }
 }
 
@@ -5622,7 +5623,7 @@
   ARMTargetCodeGenInfo::setTargetAttributes(D, GV, CGM, IsForDefinition);
   if (!IsForDefinition)
 return;
-  addStackProbeSizeTargetAttribute(D, GV, CGM);
+  addStackProbeParamsTargetAttribute(D, GV, CGM);
 }
 }
 
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -223,6 +223,7 @@
 ///< alignment, if not 0.
 VALUE_CODEGENOPT(StackProbeSize, 32, 4096) ///< Overrides default stack
///< probe size, even if 0.
+CODEGENOPT(NoStackArgProbe, 1, 0) ///< Set when -mno-stack-arg-probe is used
 CODEGENOPT(DebugColumnInfo, 1, 0) ///< Whether or not to use column information
   ///< in debug info.
 
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1822,6 +1822,8 @@
   HelpText<"Set the stack alignment">;
 def mstack_probe_size : Joined<["-"], "mstack-probe-size=">, Group, Flags<[CC1Option]>,
   HelpText<"Set the stack probe size">;
+def mno_stack_arg_probe : Flag<["-"], "mno-stack-arg-probe">, Group, Flags<[CC1Option]>,
+  HelpText<"Disable stack probes">;
 def mthread_model : Separate<["-"], "mthread-model">, Group, Flags<[CC1Option]>,
   HelpText<"The thread model to use, e.g. posix, single (posix by default)">, Values<"posix,single">;
 def meabi : Separate<["-"], "meabi">, Group, Flags<[CC1Option]>,
Index: docs/ClangCommandLineReference.rst
===
--- docs/ClangCommandLineReference.rst
+++ docs/ClangCommandLineReference.rst
@@ -2180,6 +2180,10 @@
 
 Set the stack probe size
 
+.. option:: -mno-stack-arg-probe
+
+Disable stack