[llvm-dev] Missing code depending on a #ifdef within the .ll file

Alberto Barbaro via llvm-dev llvm-dev at lists.llvm.org
Wed Dec 18 14:08:42 PST 2019


Hi all,
I have managed to compile libpng using wllvm and obtain the IR of pngpixel
( small tool which is part of libpng ).

libpng has a function called png_check_IHDR:

void /* PRIVATE */
png_check_IHDR(png_const_structrp png_ptr,
   png_uint_32 width, png_uint_32 height, int bit_depth,
   int color_type, int interlace_type, int compression_type,
   int filter_type)
{
   int error = 0;

   /* Check for width and height valid values */
   if (width == 0)
   {
      png_warning(png_ptr, "Image width is zero in IHDR");
      error = 1;
   }
   else if (width > PNG_UINT_31_MAX)
   {
      png_warning(png_ptr, "Invalid image width in IHDR");
      error = 1;
   }











* else   {#     ifdef PNG_SET_USER_LIMITS_SUPPORTED      if (width >
png_ptr->user_width_max)#     else      if (width > PNG_USER_WIDTH_MAX)#
  endif      {         png_warning(png_ptr, "Image width exceeds user limit
in IHDR");         error = 1;      }   }*
...
}

Unfortunately the relative IR does not seem to have the branch highlighted
in bold:

; Function Attrs: nounwind uwtable
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 {
  *%1 = icmp eq i32 %width, 0*
  br i1 %1, label %.thread, label %2

.thread:                                          ; preds = %0
  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 label %5

; <label>:2:                                      ; preds = %0
  *%3 = icmp slt i32 %width, 0*
  br i1 %3, label %4, label %5

; <label>:4:                                      ; preds = %2
  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 label %5

; <label>:5:                                      ; preds = %4, %2, %.thread
  %error.1 = phi i32 [ 1, %4 ], [ 0, %2 ], [ 1, %.thread ]
  %6 = getelementptr inbounds %struct.png_struct_def,
%struct.png_struct_def* %png_ptr, i64 0, i32 132
  %7 = load i32, i32* %6, align 4, !tbaa !22
  *%8 = icmp ult i32 %7, %width ; if (width > PNG_UINT_31_MAX)*
  br i1 %8, label %9, label %10

; <label>:9:                                      ; preds = %5
  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 label %10

; <label>:10:                                     ; preds = %9, %5
  %error.3 = phi i32 [ 1, %9 ], [ %error.1, %5 ]
  *%11 = icmp eq i32 %height, 0 ; first check on the height*
  br i1 %11, label %.thread27, label %12

Does anybody know why the else branch is completely missing?

Thanks,
Alberto
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191218/9181b3a8/attachment.html>


More information about the llvm-dev mailing list