<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 18, 2021 at 7:51 AM Ryan Santhirarajan <<a href="mailto:rsanthir@quicinc.com">rsanthir@quicinc.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">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" rel="noreferrer" 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" rel="noreferrer" target="_blank">https://reviews.llvm.org/D100509</a> , it actually reports very similar results albeit in different forms.</blockquote><div><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> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <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" rel="noreferrer" 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" rel="noreferrer" 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" rel="noreferrer" 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" rel="noreferrer" 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" rel="noreferrer" 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" rel="noreferrer" 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" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>