<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: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 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
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" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Hi David,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">You raise a good point, I think for now we can have a simple alias, and if need be change it in the future. Here’s a change that does that:<br>
<a href="https://reviews.llvm.org/D102782">https://reviews.llvm.org/D102782</a><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Regards,<o:p></o:p></p>
<p class="MsoNormal">Ryan<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> David Blaikie <dblaikie@gmail.com> <br>
<b>Sent:</b> Tuesday, May 18, 2021 11:14 AM<br>
<b>To:</b> Ryan Santhirarajan <rsanthir@quicinc.com><br>
<b>Cc:</b> Roman Lebedev <lebedev.ri@gmail.com>; llvm-dev@lists.llvm.org; Chris Jenneisch <chrisj@quicinc.com>; Pengxuan Zheng <pzheng@quicinc.com><br>
<b>Subject:</b> [EXT] Re: [llvm-dev] Implementing "-Wstack-usage=" warning flag<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Tue, May 18, 2021 at 7:51 AM Ryan Santhirarajan <<a href="mailto:rsanthir@quicinc.com">rsanthir@quicinc.com</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">Hi Roman,<br>
<br>
It seems that there isn't really a consensus on what the most "correct" approach is as there already exists a discrepancy between LLVM and GCC behaviour. I suggest that we proceeed with the less invasive of the two approaches,
<a href="https://reviews.llvm.org/D101965" target="_blank">https://reviews.llvm.org/D101965</a>, and if we decide to update "-Wframe-larger-than=" and "-Wstack-usage=" that can be addressed later. As it stands now the two flags will report similar information.<br>
<br>
My change cooperates well with the change you pointed out, <a href="https://reviews.llvm.org/D100509" target="_blank">
https://reviews.llvm.org/D100509</a> , it actually reports very similar results albeit in different forms.<o:p></o:p></p>
</blockquote>
<div>
<p class="MsoNormal"><br>
Is there any particular benefit to them being in different forms, rather than having the stack-usage be an alias for frame-larger-than for now?<br>
 <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal"><br>
<br>
Regards,<br>
Ryan<br>
<br>
<br>
-----Original Message-----<br>
From: Roman Lebedev <<a href="mailto:lebedev.ri@gmail.com" target="_blank">lebedev.ri@gmail.com</a>>
<br>
Sent: Thursday, May 6, 2021 12:35 AM<br>
To: David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>><br>
Cc: Ryan Santhirarajan <<a href="mailto:rsanthir@quicinc.com" target="_blank">rsanthir@quicinc.com</a>>;
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>; Chris Jenneisch <<a href="mailto:chrisj@quicinc.com" target="_blank">chrisj@quicinc.com</a>>; Pengxuan Zheng <<a href="mailto:pzheng@quicinc.com" target="_blank">pzheng@quicinc.com</a>><br>
Subject: [EXT] Re: [llvm-dev] Implementing "-Wstack-usage=" warning flag<br>
<br>
Thank you for looking into it!<br>
<br>
I think while these diagnostics may be niche, they may be quite important, especially given that clang static analyzer does not implement a proper check for maximal stack usage of a program.<br>
<br>
How will this cooperate with parallel implementation in<br>
<a href="https://reviews.llvm.org/D100509" target="_blank">https://reviews.llvm.org/D100509</a> ?<br>
<br>
I think current clang's -Wframe-larger-than= does not match either one of the GCC options:
<a href="https://godbolt.org/z/ehTaEMjW5" target="_blank">https://godbolt.org/z/ehTaEMjW5</a> I guess it only counts the allocas within the function?<br>
<br>
There, it is visible that the stack usage is the cumulative size of all the allocas within the function's body, while frame-size also includes arguments into that computation.<br>
<br>
Which, i think is consistent with<br>
<a href="https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html" target="_blank">https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html</a><br>
* -Wstack-usage=byte-size<br>
  Warn if the stack usage of a function might exceed byte-size.<br>
  The computation done to determine the stack usage is conservative.<br>
  Any space allocated via alloca, variable-length arrays, or related<br>
  constructs is included by the compiler when determining whether or not<br>
  to issue a warning.<br>
* -Wframe-larger-than=byte-size<br>
  Warn if the size of a function frame exceeds byte-size. The<br>
  computation done to determine the stack frame size is approximate and<br>
  not conservative. The actual requirements may be somewhat greater<br>
  than byte-size even if you do not get a warning. In addition,<br>
  any space allocated via alloca, variable-length arrays,<br>
  or related constructs is not included by the compiler when<br>
  determining whether or not to issue a warning<br>
  -Wframe-larger-than=‘PTRDIFF_MAX’ is enabled by default.<br>
  Warnings controlled by the option can be disabled either by<br>
  specifying byte-size of ‘SIZE_MAX’ or more or by<br>
  -Wno-frame-larger-than.<br>
<br>
Roman<br>
<br>
On Thu, May 6, 2021 at 4:55 AM David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:<br>
><br>
> +Roman Lebedev<br>
><br>
> Roman - what was your particular motivation for filing the bug? Is <br>
> there a use case that -Wframe-larger-than doesn't cover? Would <br>
> -Wstack-usage as an alias for -Wframe-larger-than be adequate for your <br>
> use case (if directly using the existing flag is not sufficient for <br>
> some reason)?<br>
><br>
> On Wed, May 5, 2021 at 6:32 PM Ryan Santhirarajan via llvm-dev <br>
> <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
> ><br>
> > Hello everyone,<br>
> ><br>
> ><br>
> ><br>
> > I am trying to address the following bug:<br>
> > <a href="https://bugs.llvm.org/show_bug.cgi?id=44418" target="_blank">https://bugs.llvm.org/show_bug.cgi?id=44418</a><br>
> ><br>
> > Which asks for the implementation of the missing “-Wstack-usage=” which will report, on a per-function basis, if the stack usage exceeds the user input.<br>
> ><br>
> ><br>
> ><br>
> > My first approach at implementing “-Wstack-usage” is the following:<br>
> ><br>
> > <a href="https://reviews.llvm.org/D101965" target="_blank">https://reviews.llvm.org/D101965</a><br>
> ><br>
> > This is virtually identical to the output of “-Wframe-larger-than” on clang. However when observing the behaviour of GCC I noticed that GCC outputs different values for “-Wstack-usage” and “-Wframe-larger-than”.<br>
> ><br>
> ><br>
> ><br>
> > This led me to my second approach which changes the way clang reports “-Wframe-larger-than”. This can be found here:<br>
> > <a href="https://reviews.llvm.org/D101964" target="_blank">https://reviews.llvm.org/D101964</a><br>
> ><br>
> > With this second approach, “-Wframe-larger-than” now reports the stack size minus any space allocated on the stack for the parameters of called functions. This more closely resembles GCC’s behaviour.<br>
> ><br>
> ><br>
> ><br>
> > I am unsure which implementation is preferred/correct and I am wondering if anyone can comment or provide some information on what a better approach would be, and what exactly the two flags should be reporting.<br>
> ><br>
> ><br>
> ><br>
> > Thanks,<br>
> ><br>
> > Ryan Santhirarajan<br>
> ><br>
> > _______________________________________________<br>
> > LLVM Developers mailing list<br>
> > <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
> > <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
</body>
</html>