<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Helvetica;
        panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
        {font-family:Helvetica;
        panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Menlo-Regular;
        panose-1:0 0 0 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.apple-converted-space
        {mso-style-name:apple-converted-space;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">It is my understand that debuggers don’t require it.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Dave, could you elaborate?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Thanks,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">  Michael<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></a></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> friss@apple.com [mailto:friss@apple.com]
<br>
<b>Sent:</b> Thursday, October 08, 2015 09:28<br>
<b>To:</b> Kuperstein, Michael M<br>
<b>Cc:</b> llvm-commits@lists.llvm.org<br>
<b>Subject:</b> Re: [llvm] r249522 - [X86] Emit .cfi_escape GNU_ARGS_SIZE when adjusting the stack before calls<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">On Oct 7, 2015, at 9:17 PM, Kuperstein, Michael M <<a href="mailto:michael.m.kuperstein@intel.com">michael.m.kuperstein@intel.com</a>> wrote:<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal" style="mso-line-height-alt:9.75pt"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Yes, we won’t emit GNU_ARGS_SIZE CFI if there are no landing pads in the function (it’s not necessary in that case – in fact
 it is only necessary just before an invoke), so disabling based on that should be fine.<span class="apple-converted-space"> </span></span><o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I sent a patch to do that. I’m wondering though: EH isn’t the only consumer of unwinding info. Debuggers and symbolizers will try to unwind the stack. If you don’t have a frame pointer, won’t you break these use cases if you have no CFI
 annotations for these pushes?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Fred<o:p></o:p></p>
</div>
<p class="MsoNormal"><br>
<br>
<o:p></o:p></p>
<div>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<div>
<p class="MsoNormal" style="mso-line-height-alt:9.75pt"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span class="apple-converted-space"><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> </span></span><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""><a href="mailto:friss@apple.com">friss@apple.com</a>
 [<a href="mailto:friss@apple.com">mailto:friss@apple.com</a>]<span class="apple-converted-space"> </span><br>
<b>Sent:</b><span class="apple-converted-space"> </span>Thursday, October 08, 2015 01:00<br>
<b>To:</b><span class="apple-converted-space"> </span>Kuperstein, Michael M<br>
<b>Cc:</b><span class="apple-converted-space"> </span><a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<b>Subject:</b><span class="apple-converted-space"> </span>Re: [llvm] r249522 - [X86] Emit .cfi_escape GNU_ARGS_SIZE when adjusting the stack before calls</span><o:p></o:p></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal" style="mso-line-height-alt:9.75pt"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-line-height-alt:9.75pt"> <o:p></o:p></p>
</div>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal" style="mso-line-height-alt:9.75pt">On Oct 7, 2015, at 2:41 PM, Kuperstein, Michael M <<a href="mailto:michael.m.kuperstein@intel.com"><span style="color:purple">michael.m.kuperstein@intel.com</span></a>> wrote:<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal" style="mso-line-height-alt:9.75pt"> <o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:9.75pt"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">Hi Fred,<br>
<br>
Sorry for the breakage, I realize how annoying this sort of thing is to debug. :-\</span><o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<div>
<p class="MsoNormal" style="mso-line-height-alt:9.75pt"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="mso-line-height-alt:9.75pt">No worries, it wasn’t the most bizarre thing I had to debug lately :-)<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal" style="mso-line-height-alt:9.75pt"><br>
<br>
<br>
<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:9.75pt"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">I'll try to figure out what to do about the assert. My first thought is that it may be overly conservative, and we should just be skipping CFI
 directives, regardless of whether they're marked FrameSetup.<br>
Do you happen to have a testcase handy?</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="mso-line-height-alt:9.75pt"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="mso-line-height-alt:9.75pt">Not a reduced one that I could send out, sorry. And I don’t have much time right now to work on that. I would expect that if the first thing in the function is call, this should trigger quite easily. I
 should be able to work on a test case tomorrow. <o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal" style="mso-line-height-alt:9.75pt"><br>
<br>
<br>
<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:9.75pt"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">To disable it on Darwin (are there other platforms that use compact_unwind?), the best place would be in X86CallFrameOptimization::isLegal().<br>
In any case, even for Darwin, you only need to disable it if !MF.getMMI().getLandingPads().empty(), right?</span><o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="mso-line-height-alt:9.75pt"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="mso-line-height-alt:9.75pt">As soon as you emit a GNU_ARGS_size CFI, it confuses the compact unwind emission, so I think we need to avoid getting into that case completely (if the compiler can’t synthesize compact unwind desc, the
 linker will give strange warnings). Does the above condition cover all these cases?<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="mso-line-height-alt:9.75pt"> <o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal" style="mso-line-height-alt:9.75pt">Fred <o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal" style="mso-line-height-alt:9.75pt"><br>
<br>
<br>
<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal" style="line-height:9.75pt"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">Michael<br>
<br>
-----Original Message-----<br>
From:<span class="apple-converted-space"> </span></span><a href="mailto:friss@apple.com"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif";color:purple">friss@apple.com</span></a><span class="apple-converted-space"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""> </span></span><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">[</span><a href="mailto:friss@apple.com"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif";color:purple">mailto:friss@apple.com</span></a><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">]<span class="apple-converted-space"> </span><br>
Sent: Thursday, October 08, 2015 00:10<br>
To: Kuperstein, Michael M<br>
Cc:<span class="apple-converted-space"> </span></span><a href="mailto:llvm-commits@lists.llvm.org"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif";color:purple">llvm-commits@lists.llvm.org</span></a><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><br>
Subject: Re: [llvm] r249522 - [X86] Emit .cfi_escape GNU_ARGS_SIZE when adjusting the stack before calls<br>
<br>
Hi Michael,<br>
<br>
I just spent quite some time debugging an issue that should be fixed by that patch, unfortunately there are 2 issues with it:<br>
<br>
- You can end up generating an args size directive right after the prologue, which means the assert in that function of DwarfDebug.cpp will sometimes fire:<br>
<br>
static DebugLoc findPrologueEndLoc(const MachineFunction *MF) {<br>
 // First known non-DBG_VALUE and non-frame setup location marks<br>
 // the beginning of the function body.<br>
 for (const auto &MBB : *MF)<br>
   for (const auto &MI : MBB)<br>
     if (!MI.isDebugValue() && !MI.getFlag(MachineInstr::FrameSetup) &&<br>
         MI.getDebugLoc()) {<br>
       // Did the target forget to set the FrameSetup flag for CFI insns?<br>
       assert(!MI.isCFIInstruction() &&<br>
              "First non-frame-setup instruction is a CFI instruction.");<br>
       return MI.getDebugLoc();<br>
     }<br>
 return DebugLoc();<br>
}<br>
<br>
- Darwin uses compact_unwind, and a dynamic SP during the function can’t really be described by that (because if you look at the code, we currently emit one compact unwind entry per function. Not sure if the runtime depends on that or if we could emit multiple
 ones). So the exception handling is still totally broken on Darwin.<br>
<br>
At least as a short-term thing, what’s the right place to just disable the push optimizations on Darwin (or maybe any platform that uses compact_unwind) when the function needs an EH description?<br>
<br>
Fred<br>
<br>
<br>
<br>
</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="line-height:9.75pt"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif"">On Oct 7, 2015, at 12:01 AM, Michael Kuperstein via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org"><span style="color:purple">llvm-commits@lists.llvm.org</span></a>>
 wrote:<br>
<br>
Author: mkuper<br>
Date: Wed Oct  7 02:01:31 2015<br>
New Revision: 249522<br>
<br>
URL:<span class="apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project?rev=249522&view=rev"><span style="color:purple">http://llvm.org/viewvc/llvm-project?rev=249522&view=rev</span></a><br>
Log:<br>
[X86] Emit .cfi_escape GNU_ARGS_SIZE when adjusting the stack before<span class="apple-converted-space"> </span><br>
calls<br>
<br>
When outgoing function arguments are passed using push instructions,<span class="apple-converted-space"> </span><br>
and EH is enabled, we may need to indicate to the stack unwinder that<span class="apple-converted-space"> </span><br>
the stack pointer was adjusted before the call.<br>
<br>
This should fix the exception handling issues in PR24792.<br>
<br>
Differential Revision:<span class="apple-converted-space"> </span><a href="http://reviews.llvm.org/D13132"><span style="color:purple">http://reviews.llvm.org/D13132</span></a><br>
<br>
Added:<br>
  llvm/trunk/test/CodeGen/X86/push-cfi-obj.ll<br>
  llvm/trunk/test/CodeGen/X86/push-cfi.ll<br>
Modified:<br>
  llvm/trunk/include/llvm/MC/MCDwarf.h<br>
  llvm/trunk/include/llvm/MC/MCStreamer.h<br>
  llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp<br>
  llvm/trunk/lib/MC/MCAsmStreamer.cpp<br>
  llvm/trunk/lib/MC/MCDwarf.cpp<br>
  llvm/trunk/lib/MC/MCStreamer.cpp<br>
  llvm/trunk/lib/Target/X86/X86FrameLowering.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/MC/MCDwarf.h<br>
URL:<span class="apple-converted-space"> </span><br>
<a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCDwarf"><span style="color:purple">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCDwarf</span></a><br>
.h?rev=249522&r1=249521&r2=249522&view=diff<br>
======================================================================<br>
========<br>
--- llvm/trunk/include/llvm/MC/MCDwarf.h (original)<br>
+++ llvm/trunk/include/llvm/MC/MCDwarf.h Wed Oct  7 02:01:31 2015<br>
@@ -340,7 +340,8 @@ public:<br>
   OpRestore,<br>
   OpUndefined,<br>
   OpRegister,<br>
-    OpWindowSave<br>
+    OpWindowSave,<br>
+    OpGnuArgsSize<br>
 };<br>
<br>
private:<br>
@@ -454,6 +455,11 @@ public:<br>
   return MCCFIInstruction(OpEscape, L, 0, 0, Vals);<br>
 }<br>
<br>
+  /// \brief A special wrapper for .cfi_escape that indicates<span class="apple-converted-space"> </span><br>
+ GNU_ARGS_SIZE  static MCCFIInstruction createGnuArgsSize(MCSymbol *L, int Size) {<br>
+    return MCCFIInstruction(OpGnuArgsSize, L, 0, Size, "");  }<br>
+<br>
 OpType getOperation() const { return Operation; }<br>
 MCSymbol *getLabel() const { return Label; }<br>
<br>
@@ -473,7 +479,7 @@ public:<br>
 int getOffset() const {<br>
   assert(Operation == OpDefCfa || Operation == OpOffset ||<br>
          Operation == OpRelOffset || Operation == OpDefCfaOffset ||<br>
-           Operation == OpAdjustCfaOffset);<br>
+           Operation == OpAdjustCfaOffset || Operation ==<span class="apple-converted-space"> </span><br>
+ OpGnuArgsSize);<br>
   return Offset;<br>
 }<br>
<br>
<br>
Modified: llvm/trunk/include/llvm/MC/MCStreamer.h<br>
URL:<span class="apple-converted-space"> </span><br>
<a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStrea"><span style="color:purple">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStrea</span></a><br>
mer.h?rev=249522&r1=249521&r2=249522&view=diff<br>
======================================================================<br>
========<br>
--- llvm/trunk/include/llvm/MC/MCStreamer.h (original)<br>
+++ llvm/trunk/include/llvm/MC/MCStreamer.h Wed Oct  7 02:01:31 2015<br>
@@ -661,6 +661,7 @@ public:<br>
 virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);<br>
 virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);<br>
 virtual void EmitCFIEscape(StringRef Values);<br>
+  virtual void EmitCFIGnuArgsSize(int64_t Size);<br>
 virtual void EmitCFISignalFrame();<br>
 virtual void EmitCFIUndefined(int64_t Register);<br>
 virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);<br>
<br>
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp<br>
URL:<span class="apple-converted-space"> </span><br>
<a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/"><span style="color:purple">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/</span></a><br>
AsmPrinterDwarf.cpp?rev=249522&r1=249521&r2=249522&view=diff<br>
======================================================================<br>
========<br>
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp (original)<br>
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp Wed Oct  7<span class="apple-converted-space"> </span><br>
+++ 02:01:31 2015<br>
@@ -246,6 +246,12 @@ void AsmPrinter::emitCFIInstruction(cons<br>
 case MCCFIInstruction::OpSameValue:<br>
   OutStreamer->EmitCFISameValue(Inst.getRegister());<br>
   break;<br>
+  case MCCFIInstruction::OpGnuArgsSize:<br>
+    OutStreamer->EmitCFIGnuArgsSize(Inst.getOffset());<br>
+    break;<br>
+  case MCCFIInstruction::OpEscape:<br>
+    OutStreamer->EmitCFIEscape(Inst.getValues());<br>
+    break;<br>
 }<br>
}<br>
<br>
<br>
Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp<br>
URL:<span class="apple-converted-space"> </span><br>
<a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cp"><span style="color:purple">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cp</span></a><br>
p?rev=249522&r1=249521&r2=249522&view=diff<br>
======================================================================<br>
========<br>
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)<br>
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Wed Oct  7 02:01:31 2015<br>
@@ -29,6 +29,7 @@<br>
#include "llvm/Support/ErrorHandling.h"<br>
#include "llvm/Support/Format.h"<br>
#include "llvm/Support/FormattedStream.h"<br>
+#include "llvm/Support/LEB128.h"<br>
#include "llvm/Support/MathExtras.h"<br>
#include "llvm/Support/Path.h"<br>
#include <cctype><br>
@@ -210,6 +211,8 @@ public:<br>
 void EmitCFISameValue(int64_t Register) override;<br>
 void EmitCFIRelOffset(int64_t Register, int64_t Offset) override;<br>
 void EmitCFIAdjustCfaOffset(int64_t Adjustment) override;<br>
+  void EmitCFIEscape(StringRef Values) override;  void<span class="apple-converted-space"> </span><br>
+ EmitCFIGnuArgsSize(int64_t Size) override;<br>
 void EmitCFISignalFrame() override;<br>
 void EmitCFIUndefined(int64_t Register) override;<br>
 void EmitCFIRegister(int64_t Register1, int64_t Register2) override;<span class="apple-converted-space"> </span><br>
@@ -1010,6 +1013,32 @@ void MCAsmStreamer::EmitCFIDefCfaOffset(<br>
 EmitEOL();<br>
}<br>
<br>
+static void PrintCFIEscape(llvm::formatted_raw_ostream &OS, StringRef<span class="apple-converted-space"> </span><br>
+Values) {<br>
+  OS << "\t.cfi_escape ";<br>
+  if (!Values.empty()) {<br>
+    size_t e = Values.size() - 1;<br>
+    for (size_t i = 0; i < e; ++i)<br>
+      OS << format("0x%02x", uint8_t(Values[i])) << ", ";<br>
+    OS << format("0x%02x", uint8_t(Values[e]));<br>
+  }<br>
+}<br>
+<br>
+void MCAsmStreamer::EmitCFIEscape(StringRef Values) {<br>
+  MCStreamer::EmitCFIEscape(Values);<br>
+  PrintCFIEscape(OS, Values);<br>
+  EmitEOL();<br>
+}<br>
+<br>
+void MCAsmStreamer::EmitCFIGnuArgsSize(int64_t Size) {<br>
+  MCStreamer::EmitCFIGnuArgsSize(Size);<br>
+  <br>
+  uint8_t Buffer[16] = { dwarf::DW_CFA_GNU_args_size };  unsigned Len<span class="apple-converted-space"> </span><br>
+ = encodeULEB128(Size, Buffer + 1) + 1;<br>
+  <br>
+  PrintCFIEscape(OS, StringRef((const char *)&Buffer[0], Len));<br>
+  EmitEOL();<br>
+}<br>
+<br>
void MCAsmStreamer::EmitCFIDefCfaRegister(int64_t Register) {<br>
 MCStreamer::EmitCFIDefCfaRegister(Register);<br>
 OS << "\t.cfi_def_cfa_register ";<br>
<br>
Modified: llvm/trunk/lib/MC/MCDwarf.cpp<br>
URL:<span class="apple-converted-space"> </span><br>
<a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev"><span style="color:purple">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDwarf.cpp?rev</span></a>=<br>
249522&r1=249521&r2=249522&view=diff<br>
======================================================================<br>
========<br>
--- llvm/trunk/lib/MC/MCDwarf.cpp (original)<br>
+++ llvm/trunk/lib/MC/MCDwarf.cpp Wed Oct  7 02:01:31 2015<br>
@@ -1147,6 +1147,11 @@ void FrameEmitterImpl::EmitCFIInstructio<br>
   Streamer.EmitIntValue(dwarf::DW_CFA_restore | Reg, 1);<br>
   return;<br>
 }<br>
+  case MCCFIInstruction::OpGnuArgsSize: {<br>
+    Streamer.EmitIntValue(dwarf::DW_CFA_GNU_args_size, 1);<br>
+    Streamer.EmitULEB128IntValue(Instr.getOffset());<br>
+    return;<br>
+  }<br>
 case MCCFIInstruction::OpEscape:<br>
   Streamer.EmitBytes(Instr.getValues());<br>
   return;<br>
<br>
Modified: llvm/trunk/lib/MC/MCStreamer.cpp<br>
URL:<span class="apple-converted-space"> </span><br>
<a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?r"><span style="color:purple">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?r</span></a><br>
ev=249522&r1=249521&r2=249522&view=diff<br>
======================================================================<br>
========<br>
--- llvm/trunk/lib/MC/MCStreamer.cpp (original)<br>
+++ llvm/trunk/lib/MC/MCStreamer.cpp Wed Oct  7 02:01:31 2015<br>
@@ -359,6 +359,14 @@ void MCStreamer::EmitCFIEscape(StringRef<br>
 CurFrame->Instructions.push_back(Instruction);<br>
}<br>
<br>
+void MCStreamer::EmitCFIGnuArgsSize(int64_t Size) {<br>
+  MCSymbol *Label = EmitCFICommon();<br>
+  MCCFIInstruction Instruction =<span class="apple-converted-space"> </span><br>
+    MCCFIInstruction::createGnuArgsSize(Label, Size);<br>
+  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();<br>
+  CurFrame->Instructions.push_back(Instruction);<br>
+}<br>
+<br>
void MCStreamer::EmitCFISignalFrame() {<br>
 EnsureValidDwarfFrame();<br>
 MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();<br>
<br>
Modified: llvm/trunk/lib/Target/X86/X86FrameLowering.cpp<br>
URL:<span class="apple-converted-space"> </span><br>
<a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86Frame"><span style="color:purple">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86Frame</span></a><br>
Lowering.cpp?rev=249522&r1=249521&r2=249522&view=diff<br>
======================================================================<br>
========<br>
--- llvm/trunk/lib/Target/X86/X86FrameLowering.cpp (original)<br>
+++ llvm/trunk/lib/Target/X86/X86FrameLowering.cpp Wed Oct  7 02:01:31<span class="apple-converted-space"> </span><br>
+++ 2015<br>
@@ -2073,8 +2073,6 @@ eliminateCallFramePseudoInstr(MachineFun<br>
   // If the stack pointer can be changed after prologue, turn the<br>
   // adjcallstackup instruction into a 'sub ESP, <amt>' and the<br>
   // adjcallstackdown instruction into 'add ESP, <amt>'<br>
-    if (Amount == 0)<br>
-      return;<br>
<br>
   // We need to keep the stack aligned properly.  To do this, we round the<br>
   // amount of space needed for the outgoing arguments up to the<span class="apple-converted-space"> </span><br>
next @@ -2082,6 +2080,25 @@ eliminateCallFramePseudoInstr(MachineFun<br>
   unsigned StackAlign = getStackAlignment();<br>
   Amount = RoundUpToAlignment(Amount, StackAlign);<br>
<br>
+    // If we have any exception handlers in this function, and we adjust<br>
+    // the SP before calls, we may need to indicate this to the unwinder,<br>
+    // using GNU_ARGS_SIZE. Note that this may be necessary<br>
+    // even when Amount == 0, because the preceding function may have<br>
+    // set a non-0 GNU_ARGS_SIZE.<br>
+    // TODO: We don't need to reset this between subsequent functions,<br>
+    // if it didn't change.<br>
+    bool HasDwarfEHHandlers =<br>
+      !MF.getTarget().getMCAsmInfo()->usesWindowsCFI() &&<br>
+      !MF.getMMI().getLandingPads().empty();<br>
+<br>
+    if (HasDwarfEHHandlers && !isDestroy &&<span class="apple-converted-space"> </span><br>
+        MF.getInfo<X86MachineFunctionInfo>()->getHasPushSequences())<br>
+      BuildCFI(MBB, I, DL,<br>
+               MCCFIInstruction::createGnuArgsSize(nullptr, Amount));<br>
+<br>
+    if (Amount == 0)<br>
+      return;<br>
+<br>
   // Factor out the amount that gets handled inside the sequence<br>
   // (Pushes of argument for frame setup, callee pops for frame destroy)<br>
   Amount -= InternalAmt;<br>
<br>
Added: llvm/trunk/test/CodeGen/X86/push-cfi-obj.ll<br>
URL:<span class="apple-converted-space"> </span><br>
<a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/push-c"><span style="color:purple">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/push-c</span></a><br>
fi-obj.ll?rev=249522&view=auto<span class="apple-converted-space"> </span><br>
======================================================================<br>
========<br>
--- llvm/trunk/test/CodeGen/X86/push-cfi-obj.ll (added)<br>
+++ llvm/trunk/test/CodeGen/X86/push-cfi-obj.ll Wed Oct  7 02:01:31<span class="apple-converted-space"> </span><br>
+++ 2015<br>
@@ -0,0 +1,38 @@<br>
+; RUN: llc < %s -mtriple=i686-pc-linux -filetype=obj | llvm-readobj<span class="apple-converted-space"> </span><br>
+-s -sr -sd | FileCheck %s<br>
+<br>
+; CHECK:         Index: 8<br>
+; CHECK-NEXT:    Name: .eh_frame (41)<br>
+; CHECK-NEXT:    Type: SHT_PROGBITS (0x1)<br>
+; CHECK-NEXT:    Flags [ (0x2)<br>
+; CHECK-NEXT:      SHF_ALLOC (0x2)<br>
+; CHECK-NEXT:    ]<br>
+; CHECK-NEXT:    Address: 0x0<br>
+; CHECK-NEXT:    Offset: 0x64<br>
+; CHECK-NEXT:    Size: 60<br>
+; CHECK-NEXT:    Link: 0<br>
+; CHECK-NEXT:    Info: 0<br>
+; CHECK-NEXT:    AddressAlignment: 4<br>
+; CHECK-NEXT:    EntrySize: 0<br>
+; CHECK-NEXT:    Relocations [<br>
+; CHECK-NEXT:    ]<br>
+; CHECK-NEXT:    SectionData (<br>
+; CHECK-NEXT:      0000: 1C000000 00000000 017A504C 5200017C  |.........zPLR..||<br>
+; CHECK-NEXT:      0010: 08070000 00000000 1B0C0404 88010000  |................|<br>
+; CHECK-NEXT:      0020: 18000000 24000000 00000000 19000000  |....$...........|<br>
+; CHECK-NEXT:      0030: 04000000 00430E10 2E100000           |.....C......|<br>
+; CHECK-NEXT:    )<br>
+<br>
+declare i32 @__gxx_personality_v0(...) declare void @good(i32 %a, i32<span class="apple-converted-space"> </span><br>
+%b, i32 %c, i32 %d)<br>
+<br>
+define void @test() optsize personality i8* bitcast (i32 (...)*<span class="apple-converted-space"> </span><br>
+@__gxx_personality_v0 to i8*) {<br>
+entry:<br>
+  invoke void @good(i32 1, i32 2, i32 3, i32 4)<br>
+          to label %continue unwind label %cleanup<br>
+continue:<br>
+  ret void<br>
+cleanup:  <br>
+  landingpad { i8*, i32 }<br>
+     cleanup<br>
+  ret void<br>
+}<br>
<br>
Added: llvm/trunk/test/CodeGen/X86/push-cfi.ll<br>
URL:<span class="apple-converted-space"> </span><br>
<a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/push-c"><span style="color:purple">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/push-c</span></a><br>
fi.ll?rev=249522&view=auto<span class="apple-converted-space"> </span><br>
======================================================================<br>
========<br>
--- llvm/trunk/test/CodeGen/X86/push-cfi.ll (added)<br>
+++ llvm/trunk/test/CodeGen/X86/push-cfi.ll Wed Oct  7 02:01:31 2015<br>
@@ -0,0 +1,143 @@<br>
+; RUN: llc < %s -mtriple=i686-pc-linux | FileCheck %s<br>
+<br>
+declare i32 @__gxx_personality_v0(...) declare void @good(i32 %a, i32<span class="apple-converted-space"> </span><br>
+%b, i32 %c, i32 %d) declare void @large(i32 %a, i32 %b, i32 %c, i32<span class="apple-converted-space"> </span><br>
+%d, i32 %e, i32 %f) declare void @empty()<br>
+<br>
+; We use an invoke, and expect a .cfi_escape GNU_ARGS_SIZE with size<span class="apple-converted-space"> </span><br>
+16 ; before the invocation ; CHECK-LABEL: test1:<br>
+; CHECK: .cfi_escape 0x2e, 0x10<br>
+; CHECK-NEXT: pushl   $4<br>
+; CHECK-NEXT: pushl   $3<br>
+; CHECK-NEXT: pushl   $2<br>
+; CHECK-NEXT: pushl   $1<br>
+; CHECK-NEXT: call<br>
+; CHECK-NEXT: addl $16, %esp<br>
+define void @test1() optsize personality i8* bitcast (i32 (...)*<span class="apple-converted-space"> </span><br>
+@__gxx_personality_v0 to i8*) {<br>
+entry:<br>
+  invoke void @good(i32 1, i32 2, i32 3, i32 4)<br>
+          to label %continue unwind label %cleanup<br>
+continue:<br>
+  ret void<br>
+cleanup:  <br>
+  landingpad { i8*, i32 }<br>
+     cleanup<br>
+  ret void<br>
+}<br>
+<br>
+; If the function has no handlers, we don't need to generate<span class="apple-converted-space"> </span><br>
+GNU_ARGS_SIZE, ; even if it has an unwind table.<br>
+; CHECK-LABEL: test2:<br>
+; CHECK-NOT: .cfi_escape<br>
+; CHECK: pushl   $4<br>
+; CHECK-NEXT: pushl   $3<br>
+; CHECK-NEXT: pushl   $2<br>
+; CHECK-NEXT: pushl   $1<br>
+; CHECK-NEXT: call<br>
+; CHECK-NEXT: addl $16, %esp<br>
+define void @test2() optsize personality i8* bitcast (i32 (...)*<span class="apple-converted-space"> </span><br>
+@__gxx_personality_v0 to i8*) {<br>
+entry:<br>
+  call void @good(i32 1, i32 2, i32 3, i32 4)<br>
+  ret void<br>
+}<br>
+<br>
+; If we did not end up using any pushes, no need for GNU_ARGS_SIZE<span class="apple-converted-space"> </span><br>
+anywhere ; CHECK-LABEL: test3:<br>
+; CHECK-NOT: .cfi_escape<br>
+; CHECK-NOT: pushl<br>
+; CHECK: retl<br>
+define void @test3() optsize personality i8* bitcast (i32 (...)*<span class="apple-converted-space"> </span><br>
+@__gxx_personality_v0 to i8*) {<br>
+entry:<br>
+  invoke void @empty()<br>
+          to label %continue unwind label %cleanup<br>
+continue:<br>
+  ret void<br>
+cleanup:  <br>
+  landingpad { i8*, i32 }<br>
+     cleanup<br>
+  ret void<br>
+}<br>
+<br>
+; Different sized stacks need different GNU_ARGS_SIZEs ; CHECK-LABEL:<span class="apple-converted-space"> </span><br>
+test4:<br>
+; CHECK: .cfi_escape 0x2e, 0x10<br>
+; CHECK-NEXT: pushl   $4<br>
+; CHECK-NEXT: pushl   $3<br>
+; CHECK-NEXT: pushl   $2<br>
+; CHECK-NEXT: pushl   $1<br>
+; CHECK-NEXT: call<br>
+; CHECK-NEXT: addl $16, %esp<br>
+; CHECK: .cfi_escape 0x2e, 0x20<br>
+; CHECK-NEXT: subl    $8, %esp<br>
+; CHECK-NEXT: pushl   $11<br>
+; CHECK-NEXT: pushl   $10<br>
+; CHECK-NEXT: pushl   $9<br>
+; CHECK-NEXT: pushl   $8<br>
+; CHECK-NEXT: pushl   $7<br>
+; CHECK-NEXT: pushl   $6<br>
+; CHECK-NEXT: calll   large<br>
+; CHECK-NEXT: addl $32, %esp<br>
+define void @test4() optsize personality i8* bitcast (i32 (...)*<span class="apple-converted-space"> </span><br>
+@__gxx_personality_v0 to i8*) {<br>
+entry:<br>
+  invoke void @good(i32 1, i32 2, i32 3, i32 4)<br>
+          to label %continue1 unwind label %cleanup<br>
+continue1:<br>
+  invoke void @large(i32 6, i32 7, i32 8, i32 9, i32 10, i32 11)<br>
+          to label %continue2 unwind label %cleanup<br>
+continue2:<br>
+  ret void          <br>
+cleanup:  <br>
+  landingpad { i8*, i32 }<br>
+     cleanup<br>
+  ret void<br>
+}<br>
+<br>
+; If we did use pushes, we need to reset GNU_ARGS_SIZE before a call<span class="apple-converted-space"> </span><br>
+; without parameters ; CHECK-LABEL: test5:<br>
+; CHECK: .cfi_escape 0x2e, 0x10<br>
+; CHECK-NEXT: pushl   $4<br>
+; CHECK-NEXT: pushl   $3<br>
+; CHECK-NEXT: pushl   $2<br>
+; CHECK-NEXT: pushl   $1<br>
+; CHECK-NEXT: call<br>
+; CHECK-NEXT: addl $16, %esp<br>
+; CHECK: .cfi_escape 0x2e, 0x00<br>
+; CHECK-NEXT: call<br>
+define void @test5() optsize personality i8* bitcast (i32 (...)*<span class="apple-converted-space"> </span><br>
+@__gxx_personality_v0 to i8*) {<br>
+entry:<br>
+  invoke void @good(i32 1, i32 2, i32 3, i32 4)<br>
+          to label %continue1 unwind label %cleanup<br>
+continue1:<br>
+  invoke void @empty()<br>
+          to label %continue2 unwind label %cleanup<br>
+continue2:<br>
+  ret void          <br>
+cleanup:  <br>
+  landingpad { i8*, i32 }<br>
+     cleanup<br>
+  ret void<br>
+}<br>
+<br>
+; This is actually inefficient - we don't need to repeat the .cfi_escape twice.<br>
+; CHECK-LABEL: test6:<br>
+; CHECK: .cfi_escape 0x2e, 0x10<br>
+; CHECK: call<br>
+; CHECK: .cfi_escape 0x2e, 0x10<br>
+; CHECK: call<br>
+define void @test6() optsize personality i8* bitcast (i32 (...)*<span class="apple-converted-space"> </span><br>
+@__gxx_personality_v0 to i8*) {<br>
+entry:<br>
+  invoke void @good(i32 1, i32 2, i32 3, i32 4)<br>
+          to label %continue1 unwind label %cleanup<br>
+continue1:<br>
+  invoke void @good(i32 5, i32 6, i32 7, i32 8)<br>
+          to label %continue2 unwind label %cleanup<br>
+continue2:<br>
+  ret void          <br>
+cleanup:  <br>
+  landingpad { i8*, i32 }<br>
+     cleanup<br>
+  ret void<br>
+}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org"><span style="color:purple">llvm-commits@lists.llvm.org</span></a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits"><span style="color:purple">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</span></a></span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="line-height:9.75pt"><span style="font-size:9.0pt;font-family:"Helvetica","sans-serif""><br>
---------------------------------------------------------------------<br>
Intel Israel (74) Limited<br>
<br>
This e-mail and any attachments may contain confidential material for<br>
the sole use of the intended recipient(s). Any review or distribution<br>
by others is strictly prohibited. If you are not the intended<br>
recipient, please contact the sender and delete all copies.</span><o:p></o:p></p>
</div>
</div>
</div>
<div>
<p class="MsoNormal" style="mso-line-height-alt:9.75pt"> <o:p></o:p></p>
</div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;line-height:9.75pt;orphans: auto;text-align:start;widows: auto;-webkit-text-stroke-width: 0px;word-spacing:0px">
<span style="font-size:8.5pt;font-family:"Menlo-Regular","serif"">---------------------------------------------------------------------<br>
Intel Israel (74) Limited<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;line-height:9.75pt;orphans: auto;text-align:start;widows: auto;-webkit-text-stroke-width: 0px;word-spacing:0px">
<span style="font-size:8.5pt;font-family:"Menlo-Regular","serif"">This e-mail and any attachments may contain confidential material for<br>
the sole use of the intended recipient(s). Any review or distribution<br>
by others is strictly prohibited. If you are not the intended<br>
recipient, please contact the sender and delete all copies.<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p>---------------------------------------------------------------------<br>
Intel Israel (74) Limited</p>

<p>This e-mail and any attachments may contain confidential material for<br>
the sole use of the intended recipient(s). Any review or distribution<br>
by others is strictly prohibited. If you are not the intended<br>
recipient, please contact the sender and delete all copies.</p></body>
</html>