<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=us-ascii">
<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:"Noto Sans Devanagari";}
@font-face
        {font-family:"Liberation Serif";}
@font-face
        {font-family:"Noto Sans CJK SC Regular";}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
p.Standard, li.Standard, div.Standard
        {mso-style-name:Standard;
        margin:0cm;
        margin-bottom:.0001pt;
        text-autospace:ideograph-other;
        font-size:12.0pt;
        font-family:"Liberation Serif",serif;
        mso-fareast-language:ZH-CN;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
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="PL" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="Standard"><span lang="EN-US">To Whom It May Concern,<o:p></o:p></span></p>
<p class="Standard"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="Standard"><span lang="EN-US">I am writing in reference to a patch I created in response to the bug I have decided to work on.<o:p></o:p></span></p>
<p class="Standard"><span lang="EN-US">Bug comes from the official site:<o:p></o:p></span></p>
<p class="Standard"><span lang="EN-US"><a href="https://bugs.llvm.org/show_bug.cgi?id=34001">https://bugs.llvm.org/show_bug.cgi?id=34001</a><o:p></o:p></span></p>
<p class="Standard"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="Standard"><b><u><span lang="EN-US">Short overview:<o:p></o:p></span></u></b></p>
<p class="Standard"><b><u><span lang="EN-US"><o:p><span style="text-decoration:none"> </span></o:p></span></u></b></p>
<p class="Standard"><span lang="EN-US">Clang-format bug resulting in a strange behavior of control statements short blocks. Different flags combinations do not guarantee expected result. Turned on option
<b>AllowShortBlocksOnASingleLine</b> does not work as intended.<o:p></o:p></span></p>
<p class="Standard"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="Standard"><b><u><span lang="EN-US">Description of the problem:<o:p></o:p></span></u></b></p>
<p class="Standard"><b><u><span lang="EN-US"><o:p><span style="text-decoration:none"> </span></o:p></span></u></b></p>
<p class="Standard"><span lang="EN-US">Cpp source file <i>UnwrappedLineFormatter</i> does not handle
<b>AllowShortBlocksOnASingleLine</b> flag as it should. Putting a single-line control statement without any braces, clang-format works as expected (depending on
<b>AllowShortIfStatementOnASingleLine</b> or <b>AllowShortLoopsOnASingleLine</b> value). Putting a single-line control statement in braces, we can observe strange and incorrect behavior.<o:p></o:p></span></p>
<p class="Standard"><span lang="EN-US">Our short block is intercepted by <b>tryFitMultipleLinesInOne
</b>function. The function returns a number of lines to be merged. Unfortunately, our control statement block is not covered properly. There are several if-return statements, but none of them handles our block. A block is identified by the line first token
 and by left and right braces. A function block works as expected, there is such an if-return statement doing proper job. A control statement block, from the other hand, falls into strange conditional construct, which depends on
<b>BraceWrapping.AfterFunction</b> flag (with condition that the line’s last token is left brace, what is possible in our case) or goes even further. That should definitely not happen.<o:p></o:p></span></p>
<p class="Standard"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="Standard"><b><u><span lang="EN-US">Description of the patch:<o:p></o:p></span></u></b></p>
<p class="Standard"><b><u><span lang="EN-US"><o:p><span style="text-decoration:none"> </span></o:p></span></u></b></p>
<p class="Standard"><span lang="EN-US">By adding three different if statements, we guarantee that our short control statement block, however it looks like (different brace wrapping flags may be turned on), is handled properly and does not fall into wrong conditional
 construct. Depending on appropriate options we return either 0 (when something disturbs our merging attempt) or let another function (<b>tryMergeSimpleBlock)
</b>take the responsibility of returned result (number of merged lines). Nevertheless, one more correction is required in mentioned
<b>tryMergeSimpleBlock</b> function. The function, previously, returned either 0 or 2. The problem was that this did not handle the case when our block had the left brace in a separate line, not the header one. After change, after adding condition, we return
 the result compatible with block’s structure. In case of left brace in the header’s line we do everything as before the patch. In case of left brace in a separate line we do the job similar to the one we do in case of a “non-header left brace” function short
 block. To be precise, we <u>try</u> to merge the block ignoring the header line. Then, if success, we increment our returned result.<o:p></o:p></span></p>
<p class="Standard"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="Standard"><span lang="EN-US">Please find the attached diff files. There are two. One created by simple svn diff command and one with postscript “NoWhitespaces” which ignores every whitespace while creating patch file. Has been done for more readable
 format. <o:p></o:p></span></p>
<p class="Standard"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="Standard"><span lang="EN-US">I would be very grateful if that could go under review. Thank you.<o:p></o:p></span></p>
<p class="Standard"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="Standard"><span lang="EN-US">Best regards,<o:p></o:p></span></p>
<p class="Standard"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="Standard"><span lang="EN-US">Pawel Maciocha<o:p></o:p></span></p>
</div>
</body>
</html>