<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;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-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.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
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">
<div class="WordSection1">
<p class="MsoNormal">               if (width == 0)<o:p></o:p></p>
<p class="MsoNormal">became<o:p></o:p></p>
<p class="MsoNormal">               %1 = icmp eq i32 %width, 0<o:p></o:p></p>
<p class="MsoNormal">which is straightforward; and<o:p></o:p></p>
<p class="MsoNormal">               else if (width > PNG_UINT_31_MAX)<o:p></o:p></p>
<p class="MsoNormal">became (assuming the constant is 0x7fffffff)<o:p></o:p></p>
<p class="MsoNormal">               %3 icmp slt i32 %width, 0<o:p></o:p></p>
<p class="MsoNormal">(note this is a signed comparison with 0, which is equivalent to the comparison in the source)<o:p></o:p></p>
<p class="MsoNormal">and finally<o:p></o:p></p>
<p class="MsoNormal">               if (width > png_ptr->user_width_max)<o:p></o:p></p>
<p class="MsoNormal">became<o:p></o:p></p>
<p class="MsoNormal">               %8 = icmp ult i32 %7, %width<o:p></o:p></p>
<p class="MsoNormal">after loading the png_ptr field into %7 in the previous instruction.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Does that help?<o:p></o:p></p>
<p class="MsoNormal">--paulr   <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> llvm-dev <llvm-dev-bounces@lists.llvm.org> <b>On Behalf Of
</b>David Blaikie via llvm-dev<br>
<b>Sent:</b> Wednesday, December 18, 2019 5:30 PM<br>
<b>To:</b> Alberto Barbaro <barbaro.alberto@gmail.com><br>
<b>Cc:</b> llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Subject:</b> Re: [llvm-dev] Missing code depending on a #ifdef within the .ll file<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">I'm sorry, I don't understand the question - the source code shows 3 calls to png_warning (one of them from the if block you're interested in), and the IR shows 3 calls to png_warning - so it looks like the body of the if block is included
 in the IR you've shown?<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Wed, Dec 18, 2019 at 2:24 PM Alberto Barbaro <<a href="mailto:barbaro.alberto@gmail.com">barbaro.alberto@gmail.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">
<div>
<div>
<p class="MsoNormal">Hi David,<o:p></o:p></p>
<div>
<p class="MsoNormal">My question is: why both #ifdef and #else branches are missing? I think at least one of the two should be present... In fact there is a case where the width could be greater then <o:p></o:p></p>
</div>
<p class="MsoNormal">PNG_USER_WIDTH_MAX but not greater then PNG_UINT_31_MAX. That's why I was expecting at least one of the two...<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Thanks<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Alberto<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Wed, Dec 18, 2019, 22:12 David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.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">
<div>
<p class="MsoNormal">Not sure I understand the question - but usually a compiler would, on one compilation, only compile one versoin of the code with one set of defines. <br>
<br>
There could be invalid code (it could literally be junk - or it could be code that's only valid when the define is true/false, etc) in an unreachable ifdef, so it doesn't make sense to compile it.<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Wed, Dec 18, 2019 at 2:09 PM Alberto Barbaro via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</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">
<div>
<div>
<p class="MsoNormal">Hi all,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">I have managed to compile libpng using wllvm and obtain the IR of pngpixel ( small tool which is part of libpng ).<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">libpng has a function called png_check_IHDR:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">void /* PRIVATE */<br>
png_check_IHDR(png_const_structrp png_ptr,<br>
   png_uint_32 width, png_uint_32 height, int bit_depth,<br>
   int color_type, int interlace_type, int compression_type,<br>
   int filter_type)<br>
{<br>
   int error = 0;<br>
<br>
   /* Check for width and height valid values */<br>
   if (width == 0)<br>
   {<br>
      png_warning(png_ptr, "Image width is zero in IHDR");<br>
      error = 1;<br>
   }<br>
   else if (width > PNG_UINT_31_MAX)<br>
   {<br>
      png_warning(png_ptr, "Invalid image width in IHDR");<br>
      error = 1;<br>
   }<br>
  <b> else<br>
   {<br>
#     ifdef PNG_SET_USER_LIMITS_SUPPORTED<br>
      if (width > png_ptr->user_width_max)<br>
#     else<br>
      if (width > PNG_USER_WIDTH_MAX)<br>
#     endif<br>
      {<br>
         png_warning(png_ptr, "Image width exceeds user limit in IHDR");<br>
         error = 1;<br>
      }<br>
   }</b><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">...<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">}<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Unfortunately the relative IR does not seem to have the branch highlighted in bold:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">; Function Attrs: nounwind uwtable<br>
define void @png_check_IHDR(%struct.png_struct_def* noalias %png_ptr, i32 %width, i32 %height, i32 %bit_depth, i32 %color_type, i32 %interlace_type, i32 %compression_type, i32 %filter_type) #5 {<br>
  <b>%1 = icmp eq i32 %width, 0</b><br>
  br i1 %1, label %.thread, label %2<br>
<br>
.thread:                                          ; preds = %0<br>
  tail call void @png_warning(%struct.png_struct_def* %png_ptr, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str50, i64 0, i64 0)) #15<br>
  br label %5<br>
<br>
; <label>:2:                                      ; preds = %0<br>
  <b>%3 = icmp slt i32 %width, 0</b><br>
  br i1 %3, label %4, label %5<br>
<br>
; <label>:4:                                      ; preds = %2<br>
  tail call void @png_warning(%struct.png_struct_def* %png_ptr, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str51, i64 0, i64 0)) #15<br>
  br label %5<br>
<br>
; <label>:5:                                      ; preds = %4, %2, %.thread<br>
  %error.1 = phi i32 [ 1, %4 ], [ 0, %2 ], [ 1, %.thread ]<br>
  %6 = getelementptr inbounds %struct.png_struct_def, %struct.png_struct_def* %png_ptr, i64 0, i32 132<br>
  %7 = load i32, i32* %6, align 4, !tbaa !22<br>
  <b>%8 = icmp ult i32 %7, %width ; if (width > PNG_UINT_31_MAX)</b><br>
  br i1 %8, label %9, label %10<br>
<br>
; <label>:9:                                      ; preds = %5<br>
  tail call void @png_warning(%struct.png_struct_def* %png_ptr, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str53, i64 0, i64 0)) #15<br>
  br label %10<br>
<br>
; <label>:10:                                     ; preds = %9, %5<br>
  %error.3 = phi i32 [ 1, %9 ], [ %error.1, %5 ]<br>
  <b>%11 = icmp eq i32 %height, 0 ; first check on the height</b><br>
  br i1 %11, label %.thread27, label %12<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Does anybody know why the else branch is completely missing?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Alberto<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
<p class="MsoNormal">_______________________________________________<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>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</body>
</html>