The following (reduced) code: typedef enum { TYPE_NON_IDR, TYPE_IDR, } NAL_UNIT_TYPE; typedef struct recordTag { } Record; typedef struct { unsigned int ActualSize; unsigned short *Slice; }Info;
typedef struct { } Params; typedef struct { NAL_UNIT_TYPE unit_type; } NAL_UNIT; unsigned int foo( Info *Decode, unsigned int nal_len) { NAL_UNIT nal_unit; unsigned short *Backend; unsigned char complete; int *BufLen = (int *)&Decode->ActualSize; do{ *BufLen = *BufLen - nal_len; if (((nal_unit.unit_type) == TYPE_NON_IDR)) { Decode->Slice = Backend; } }while (*BufLen >0); Finish( &complete); } Produces infinite loop with this options: -O2 >gcc -v Using built-in specs. Target: x86_64-unknown-linux-gnu Configured with: ../configure --enable-threads=posix --prefix=/x/x86_gcc_4.4/bin --enable-languages=c,c++ --disable-checking Thread model: posix gcc version 4.4.0 (GCC) The issue first appears in tree PRE (from reduced2.c.084t.pre): ... <bb 2>: D.1896_2 = &Decode_1(D)->ActualSize; BufLen_3 = (int *) D.1896_2; pretmp.16_34 = Decode_1(D)->ActualSize; <bb 3>: # prephitmp.17_35 = PHI <pretmp.16_34(2), D.1905_12(8)> D.1907_14 = prephitmp.17_35; D.1899_7 = D.1907_14 - nal_len_6(D); D.1900_8 = (int) D.1899_7; *BufLen_3 = D.1900_8; if (nal_unit$unit_type_16(D) == 0) goto <bb 4>; else goto <bb 7>; <bb 7>: goto <bb 5>; <bb 4>: Decode_1(D)->Slice = Backend_10(D); pretmp.16_36 = Decode_1(D)->ActualSize; <bb 5>: # prephitmp.17_37 = PHI <prephitmp.17_35(7), pretmp.16_36(4)> D.1905_12 = prephitmp.17_37; D.1906_13 = (int) D.1905_12; if (D.1906_13 > 0) goto <bb 8>; else goto <bb 6>; The first "argument" of this PHI: # prephitmp.17_37 = PHI <prephitmp.17_35(7), pretmp.16_36(4)> is wrong - instead of decremented value it uses original one. PRE only makes an earlier DF analysis issue evident. The problem is elsewhere. Any suggestions are highly appreciated. -- Summary: PRE produces illegal PHI node Product: gcc Version: 4.4.0 Status: UNCONFIRMED Severity: major Priority: P3 Component: middle-end AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: sergei_lus at yahoo dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42794