csmith-project / creduce

C-Reduce, a C and C++ program reducer
Other
1.3k stars 123 forks source link

Infinite loop trying to reduce simple snippet #205

Closed ghost closed 4 years ago

ghost commented 4 years ago

Version

Bug

Consider this simple snippet:

#define UINT16BIT unsigned short int
#define UINT32BIT unsigned int
#define FRAME_DIM_X 2048
#define FRAME_DIM_Y 2048
#define STRIPES_PER_FRAME 32
#define PIXEL_PER_STRIPE 0
#define BS 1024
#define DIM_X 0
#define DIM_Y 0
#define STRIPES_PER_BS 0
void detectSaturation(UINT16BIT frame[DIM_Y][DIM_X][BS][BS],
                      UINT16BIT saturationLimit,
                      UINT32BIT saturationFrame[DIM_Y][DIM_X][BS][BS / 32],
                      int i, int j) {
  UINT32BIT x, y, stripe;
  UINT16BIT saturationLimitValue;
  UINT32BIT stripe_lb = j * STRIPES_PER_BS;
  for (stripe = stripe_lb; stripe < stripe_lb + STRIPES_PER_BS; stripe++) {
    for (y = 0; y < BS; y++) {
      for (x = stripe * PIXEL_PER_STRIPE - j * BS; x < 0 - j * BS; x++) {
        if (frame[i][j][y][x] > saturationLimitValue) {
          saturationFrame[i][j][y][0] =
              saturationFrame[i][j][y][0] | (0 << (x & 0));
        }
      }
    }
  }
}

When I try to reduce it there is a point where creduce seems to enter an infinite loop, something like:

 creduce ./reduce.sh preProcessingFixedPoint_allin_v1.c
===< 10737 >===
running 1 interestingness test in parallel
===< pass_unifdef :: 0 >===
===< pass_comments :: 0 >===
===< pass_ifs :: 0 >===
===< pass_includes :: 0 >===
===< pass_line_markers :: 0 >===
===< pass_blank :: 0 >===
===< pass_clang_binsrch :: replace-function-def-with-decl >===
===< pass_clang_binsrch :: remove-unused-function >===
===< pass_lines :: 0 >===
(0.0 %, 942 bytes)
(5.7 %, 888 bytes)
(8.4 %, 863 bytes)
===< pass_lines :: 1 >===
(7.6 %, 870 bytes)
===< pass_lines :: 2 >===
(6.5 %, 881 bytes)
===< pass_lines :: 3 >===
(4.9 %, 896 bytes)
===< pass_lines :: 4 >===
(3.1 %, 913 bytes)
===< pass_lines :: 6 >===
(1.1 %, 932 bytes)
===< pass_lines :: 8 >===
(-1.0 %, 951 bytes)
===< pass_lines :: 10 >===
(-3.0 %, 970 bytes)
===< pass_clang_binsrch :: replace-function-def-with-decl >===
===< pass_clang_binsrch :: remove-unused-function >===
===< pass_clang :: remove-unused-function >===
===< pass_balanced :: curly >===
===< pass_balanced :: curly2 >===
===< pass_balanced :: curly3 >===
===< pass_balanced :: parens-to-zero >===
===< pass_clang :: callexpr-to-value >===
===< pass_clang :: replace-callexpr >===
===< pass_clang :: simplify-callexpr >===
===< pass_clang :: remove-unused-enum-member >===
===< pass_clang :: remove-enum-member-value >===
===< pass_clang_binsrch :: remove-unused-var >===
===< pass_special :: a >===
===< pass_special :: b >===
===< pass_special :: c >===
===< pass_include_includes :: 0 >===
===< pass_ternary :: b >===
===< pass_ternary :: c >===
===< pass_balanced :: curly >===
(cache hit for /home/brupelo/appentra/pwa-test/crashes/crash_preprocessing_fixedpoint_allin_v1/preProcessingFixedPoint_allin_v1.c)
===< pass_balanced :: curly2 >===
(cache hit for /home/brupelo/appentra/pwa-test/crashes/crash_preprocessing_fixedpoint_allin_v1/preProcessingFixedPoint_allin_v1.c)
===< pass_balanced :: curly3 >===
(cache hit for /home/brupelo/appentra/pwa-test/crashes/crash_preprocessing_fixedpoint_allin_v1/preProcessingFixedPoint_allin_v1.c)
===< pass_balanced :: parens >===
===< pass_balanced :: angles >===
===< pass_balanced :: square >===
===< pass_balanced :: curly-inside >===
===< pass_balanced :: parens-inside >===
===< pass_balanced :: angles-inside >===
===< pass_balanced :: square-inside >===
(-2.4 %, 965 bytes)
(-1.9 %, 960 bytes)
===< pass_balanced :: curly-only >===
(-1.7 %, 958 bytes)
(-1.5 %, 956 bytes)
(-1.3 %, 954 bytes)
===< pass_balanced :: angles-only >===
===< pass_balanced :: square-only >===
===< pass_clang :: remove-namespace >===
===< pass_clang :: aggregate-to-scalar >===
===< pass_clang :: param-to-global >===
(-6.5 %, 1003 bytes)
(-11.7 %, 1052 bytes)
(-16.9 %, 1101 bytes)
(-22.1 %, 1150 bytes)
(-27.3 %, 1199 bytes)
(-32.5 %, 1248 bytes)
(-37.7 %, 1297 bytes)
(-42.9 %, 1346 bytes)
(-48.1 %, 1395 bytes)
(-53.3 %, 1444 bytes)
(-58.5 %, 1493 bytes)
(-63.7 %, 1542 bytes)
(-68.9 %, 1591 bytes)
(-74.1 %, 1640 bytes)
(-79.3 %, 1689 bytes)
(-84.5 %, 1738 bytes)
(-89.7 %, 1787 bytes)
(-94.9 %, 1836 bytes)
(-100.1 %, 1885 bytes)
(-105.3 %, 1934 bytes)
(-110.5 %, 1983 bytes)
(-115.7 %, 2032 bytes)
(-120.9 %, 2081 bytes)
(-126.1 %, 2130 bytes)
(-131.3 %, 2179 bytes)
(-136.5 %, 2228 bytes)
(-141.7 %, 2277 bytes)
(-146.9 %, 2326 bytes)
(-152.1 %, 2375 bytes)
(-157.3 %, 2424 bytes)
(-162.5 %, 2473 bytes)
(-167.7 %, 2522 bytes)
(-172.9 %, 2571 bytes)
(-178.1 %, 2620 bytes)
(-183.3 %, 2669 bytes)
(-188.5 %, 2718 bytes)
(-193.7 %, 2767 bytes)
(-198.9 %, 2816 bytes)
(-204.1 %, 2865 bytes)
(-209.3 %, 2914 bytes)
(-214.5 %, 2963 bytes)
(-219.7 %, 3012 bytes)
(-224.9 %, 3061 bytes)
(-230.1 %, 3110 bytes)
(-235.4 %, 3159 bytes)
(-240.6 %, 3208 bytes)
(-245.8 %, 3257 bytes)
(-251.0 %, 3306 bytes)
(-256.2 %, 3355 bytes)
(-261.4 %, 3404 bytes)
(-266.6 %, 3453 bytes)
(-271.8 %, 3502 bytes)
(-277.0 %, 3551 bytes)
(-282.2 %, 3600 bytes)
(-287.4 %, 3649 bytes)
(-292.6 %, 3698 bytes)
(-297.8 %, 3747 bytes)
(-303.0 %, 3796 bytes)
(-308.2 %, 3845 bytes)
(-313.4 %, 3894 bytes)
(-318.6 %, 3943 bytes)
(-323.8 %, 3992 bytes)
(-329.0 %, 4041 bytes)
(-334.2 %, 4090 bytes)
(-339.4 %, 4139 bytes)
(-344.6 %, 4188 bytes)
(-349.8 %, 4237 bytes)
(-355.0 %, 4286 bytes)
(-360.2 %, 4335 bytes)
(-365.4 %, 4384 bytes)
(-370.6 %, 4433 bytes)
(-375.8 %, 4482 bytes)
(-381.0 %, 4531 bytes)
(-386.2 %, 4580 bytes)
(-391.4 %, 4629 bytes)
(-396.6 %, 4678 bytes)
(-401.8 %, 4727 bytes)
(-407.0 %, 4776 bytes)
(-412.2 %, 4825 bytes)
(-417.4 %, 4874 bytes)
(-422.6 %, 4923 bytes)
(-427.8 %, 4972 bytes)
(-433.0 %, 5021 bytes)
(-438.2 %, 5070 bytes)
(-443.4 %, 5119 bytes)
(-448.6 %, 5168 bytes)
(-453.8 %, 5217 bytes)
(-459.0 %, 5266 bytes)
(-464.2 %, 5315 bytes)
(-469.4 %, 5364 bytes)
(-474.6 %, 5413 bytes)
(-479.8 %, 5462 bytes)
(-485.0 %, 5511 bytes)
(-490.2 %, 5560 bytes)
(-495.4 %, 5609 bytes)
(-500.6 %, 5658 bytes)
(-505.8 %, 5707 bytes)
(-511.0 %, 5756 bytes)
(-516.2 %, 5805 bytes)
(-521.4 %, 5854 bytes)
^Z
[4]+  Detenido                creduce ./reduce.sh preProcessingFixedPoint_allin_v1.c

It happens at certain point the file will look like this:

#define UINT16BIT unsigned short int
#define UINT32BIT unsigned int
#define PIXEL_PER_STRIPE 0
#define BS 1024
#define DIM_X 0
#define DIM_Y 0
#define STRIPES_PER_BS 0
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
unsigned short detectSaturation_saturationLimit;
void detectSaturation(UINT16BIT frame[][DIM_X][BS][BS],                       UINT16BIT saturationLimit,                       UINT32BIT saturationFrame[][DIM_X][BS][BS / 32],                       int i, int j) {
         UINT32BIT x, y, stripe;
         UINT16BIT saturationLimitValue;
         UINT32BIT stripe_lb = j * STRIPES_PER_BS;
         for (stripe = stripe_lb;
       stripe < stripe_lb + STRIPES_PER_BS;
       stripe++) 
          for (y = 0;
      y < BS;
      y++) {
           for (x = stripe * PIXEL_PER_STRIPE - j * BS;
     x < 0 - j * BS;
     x++) 
            if (frame[i][j][y][x] > saturationLimitValue) 
             saturationFrame[i][j][y][0] =               saturationFrame[i][j][y][0] | (0 << (x & 0));

         }

       }

If I continued running the number of statements unsigned short detectSaturation_saturationLimit; will continue growing ad infinitum (I assume :))... is this the expected behaviour or a bug?

Ps. Used creduce few times but this software seems pretty awesome so thank you very much to the authors for creating it!

chenyang78 commented 4 years ago

Fixed.

Thanks for reporting the issue!