<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;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
        {font-family:"Lucida Console";
        panose-1:2 11 6 9 4 5 4 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;
        color:black;}
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
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;
        color:black;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;
        color:black;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.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 bgcolor=white lang=EN-GB link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US'>Hi,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US'>This is a (tested!) patch to add checks that both pre-increment and pre-decrement don’t overflow, for both char and short integer types (since they’re both narrower than int), as per the problem fixed in PR9350.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US'>Thanks, Andrew R<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:windowtext'>From:</span></b><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:windowtext'> Friedman, Eli [mailto:efriedma@codeaurora.org] <br><b>Sent:</b> 4 January 2017 6:42 pm<br><b>To:</b> andrew.rogers@cantab.net; cfe-dev@lists.llvm.org<br><b>Subject:</b> Re: [cfe-dev] Testcase for LLVM PR9350<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>On 1/3/2017 2:28 PM, via cfe-dev wrote:<o:p></o:p></p></div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><p class=MsoNormal style='background:white'><span style='font-size:10.0pt;font-family:"Lucida Console"'>Hi clang devs, <o:p></o:p></span></p><div id="yui_3_16_0_ym19_1_1483447542855_7226"><p class=MsoNormal style='background:white'><span style='font-size:10.0pt;font-family:"Lucida Console"'><o:p> </o:p></span></p></div><div id="yui_3_16_0_ym19_1_1483447542855_7228"><p class=MsoNormal style='background:white'><span style='font-size:10.0pt;font-family:"Lucida Console"'>I was looking at PR9350 and saw that Eli added a test to check LLVM doesn't overflow on [signed] char increment:<o:p></o:p></span></p></div><div id="yui_3_16_0_ym19_1_1483447542855_7229"><p class=MsoNormal style='background:white'><span style='font-size:10.0pt;font-family:"Lucida Console"'><o:p> </o:p></span></p></div><div id="yui_3_16_0_ym19_1_1483447542855_7231"><p class=MsoNormal style='background:white'><span style='font-size:10.0pt;font-family:"Lucida Console"'>--- cfe/trunk/test/CodeGen/integer-overflow.c 2011/03/02 01:43:30 126815<br id="yui_3_16_0_ym19_1_1483447542855_7232">+++ cfe/trunk/test/CodeGen/integer-overflow.c 2011/03/02 01:49:12 126816<br id="yui_3_16_0_ym19_1_1483447542855_7233">@@ -50,11 +50,17 @@<br id="yui_3_16_0_ym19_1_1483447542855_7234">   // TRAPV_HANDLER: foo(<br id="yui_3_16_0_ym19_1_1483447542855_7235">   --a;<br id="yui_3_16_0_ym19_1_1483447542855_7236">   <br id="yui_3_16_0_ym19_1_1483447542855_7237">-  <br id="yui_3_16_0_ym19_1_1483447542855_7238">   // -fwrapv should turn off inbounds for GEP's, PR9256<br id="yui_3_16_0_ym19_1_1483447542855_7239">   extern int* P;<br id="yui_3_16_0_ym19_1_1483447542855_7240">   ++P;<br id="yui_3_16_0_ym19_1_1483447542855_7241">   // DEFAULT: getelementptr inbounds i32*<br id="yui_3_16_0_ym19_1_1483447542855_7242">   // WRAPV: getelementptr i32*<br id="yui_3_16_0_ym19_1_1483447542855_7243">   // TRAPV: getelementptr inbounds i32*<br id="yui_3_16_0_ym19_1_1483447542855_7244">+<br id="yui_3_16_0_ym19_1_1483447542855_7245">+  // PR9350: char increment never overflows.<br id="yui_3_16_0_ym19_1_1483447542855_7246">+  extern volatile signed char PR9350;<br id="yui_3_16_0_ym19_1_1483447542855_7247">+  // DEFAULT: add i8 {{.*}}, 1<br id="yui_3_16_0_ym19_1_1483447542855_7248">+  // WRAPV: add i8 {{.*}}, 1<br id="yui_3_16_0_ym19_1_1483447542855_7249">+  // TRAPV: add i8 {{.*}}, 1<br id="yui_3_16_0_ym19_1_1483447542855_7250">+  ++PR9350;<br id="yui_3_16_0_ym19_1_1483447542855_7251">}<o:p></o:p></span></p></div><div id="yui_3_16_0_ym19_1_1483447542855_7252"><p class=MsoNormal style='background:white'><span style='font-size:10.0pt;font-family:"Lucida Console"'><o:p> </o:p></span></p></div><div id="yui_3_16_0_ym19_1_1483447542855_7798"><p class=MsoNormal style='background:white'><span style='font-size:10.0pt;font-family:"Lucida Console"'><a href="http://llvm.org/viewvc/llvm-project?view=revision&revision=126816">http://llvm.org/viewvc/llvm-project?view=revision&revision=126816</a><o:p></o:p></span></p></div><div id="yui_3_16_0_ym19_1_1483447542855_8228"><p class=MsoNormal style='background:white'><span style='font-size:10.0pt;font-family:"Lucida Console"'><o:p> </o:p></span></p></div><div id="yui_3_16_0_ym19_1_1483447542855_7254"><p class=MsoNormal style='background:white'><span style='font-size:10.0pt;font-family:"Lucida Console"'>Presumably the logic about promotion to int applies the same as in the argument John gave in PR9350 since 6.5.3.1 §3 says "the prefix -- operator is analogous to the prefix ++ operator, except that the value of the operand is decremented".<o:p></o:p></span></p></div><div id="yui_3_16_0_ym19_1_1483447542855_7255"><p class=MsoNormal style='background:white'><span style='font-size:10.0pt;font-family:"Lucida Console"'><o:p> </o:p></span></p></div><div id="yui_3_16_0_ym19_1_1483447542855_7257"><p class=MsoNormal style='background:white'><span style='font-size:10.0pt;font-family:"Lucida Console"'>Would it therefore make sense to add the equivalent test to integer-overflow.c that decrement of a [signed] char didn't ever cause underflow:<o:p></o:p></span></p></div><div id="yui_3_16_0_ym19_1_1483447542855_7258"><p class=MsoNormal style='background:white'><span style='font-size:10.0pt;font-family:"Lucida Console"'><o:p> </o:p></span></p></div><div id="yui_3_16_0_ym19_1_1483447542855_7260"><p class=MsoNormal style='background:white'><span style='font-size:10.0pt;font-family:"Lucida Console"'>  // DEFAULT: sub i8 {{.*}}, 1<br id="yui_3_16_0_ym19_1_1483447542855_7261">  // WRAPV: sub i8 {{.*}}, 1<br id="yui_3_16_0_ym19_1_1483447542855_7262">  // TRAPV: sub i8 {{.*}}, 1<br id="yui_3_16_0_ym19_1_1483447542855_7263">  --PR9350;<o:p></o:p></span></p></div><p class=MsoNormal style='background:white'><span style='font-size:10.0pt;font-family:"Lucida Console"'><o:p> </o:p></span></p></div></blockquote><p class=MsoNormal><br>Yes, it probably makes sense to add a testcase like that.  Patch welcome.<o:p></o:p></p><p>-Eli<o:p></o:p></p><pre>-- <o:p></o:p></pre><pre>Employee of Qualcomm Innovation Center, Inc.<o:p></o:p></pre><pre>Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project<o:p></o:p></pre></div></body></html>