http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55424
Bug #: 55424 Summary: [4.8 Regression]gcc.dg/uninit-pred-8_b.c bogus warning line 23 on ARM/Cortex-M0/-Os Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: minor Priority: P3 Component: tree-optimization AssignedTo: unassig...@gcc.gnu.org ReportedBy: amker.ch...@gmail.com The test case require optimization level "-O2" and it passes on ARM/cortex-m0 with "-O2", but the failure with "-Os" does reveal potential bug in tree-ssa-uninit.c Test command line: arm-none-eabi-gcc ./uninit-pred-8_b.c -fno-diagnostics-show-caret -Wuninitialized -fno-tree-dominator-opts -S -mthumb -mcpu=cortex-m0 -Os -o uninit-pred-8_b.s The warning info: .../trunk-orig/gcc/gcc/testsuite/gcc.dg/uninit-pred-8_b.c: In function 'foo': .../trunk-orig/gcc/gcc/testsuite/gcc.dg/uninit-pred-8_b.c:23:11: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized] .../trunk-orig/gcc/gcc/testsuite/gcc.dg/uninit-pred-8_b.c: In function 'foo_2': .../trunk-orig/gcc/gcc/testsuite/gcc.dg/uninit-pred-8_b.c:42:11: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized] This failure occurs after checking in r193687. The patch prefers to generate branches on ARM/cortex-m0. After investigating tree dump of tree-ssa-uninit.c, I think: tree-ssa-uninit.c computes control dependent chain for uses/def of variable and checks whether each use is guarded by def. It has a upper bound on the number of control dependent chains(MAX_NUM_CHAINS==8) and just retreat to false warning if the number of chains exceeds MAX_NUM_CHAINS. In our scenario, the number of chains exceeds MAX_NUM_CHAINS because we prefer short circuit now, resulting in false warning information. These false warning cannot be fully removed if the MAX_NUM_CHAINS exists, but we can improve it in following way: There are lots of invalid control dependent chains computed in tree-ssa-uninit.c now and should be pruned. I have already implemented a quick fix and it works for our scenario. I am not sure it should be fixed in this way, so please comments if you have any opinions. Thanks Dump of tree-ssa-uninit.c: ;; Function foo (foo, funcdef_no=0, decl_uid=4065, cgraph_uid=0) Use in stmt v_24 = PHI <v_25(8), v_1(9)> is guarded by : (.NOT.) if (m_6(D) != 0) Operand defs of phi v_1 = PHI <v_9(D)(6), r_7(D)(4), r_7(D)(2), r_7(D)(5)> is guarded by : (.NOT.) if (n_5(D) <= 9) (.AND.) (.NOT.) if (m_6(D) > 100) (.AND.) if (r_7(D) <= 19) (.OR.) if (n_5(D) <= 9) (.OR.) (.NOT.) if (n_5(D) <= 9) (.AND.) (.NOT.) if (m_6(D) > 100) (.AND.) (.NOT.) if (r_7(D) <= 19) (.AND.) if (l_8(D) != 0) foo (int n, int l, int m, int r) { int v; int g.1; int g.0; <bb 2>: if (n_5(D) <= 9) goto <bb 7>; else goto <bb 3>; <bb 3>: if (m_6(D) > 100) goto <bb 18>; else goto <bb 4>; <bb 4>: if (r_7(D) <= 19) goto <bb 7>; else goto <bb 5>; <bb 5>: if (l_8(D) != 0) goto <bb 7>; else goto <bb 6>; <bb 6>: <bb 7>: # v_1 = PHI <v_9(D)(6), r_7(D)(4), r_7(D)(2), r_7(D)(5)> if (m_6(D) != 0) goto <bb 8>; else goto <bb 9>; <bb 8>: # v_25 = PHI <v_1(7), v_22(18)> g.0_11 = g; g.1_12 = g.0_11 + 1; g = g.1_12; goto <bb 10>; <bb 9>: bar (); <bb 10>: # v_24 = PHI <v_25(8), v_1(9)> if (n_5(D) <= 9) goto <bb 14>; else goto <bb 11>; <bb 11>: if (m_6(D) > 100) goto <bb 14>; else goto <bb 12>; <bb 12>: if (r_7(D) <= 19) goto <bb 14>; else goto <bb 16>; <bb 13>: if (m_6(D) > 100) goto <bb 15>; else goto <bb 16>; <bb 14>: blah (v_24); if (n_5(D) <= 9) goto <bb 15>; else goto <bb 13>; <bb 15>: blah (v_24); goto <bb 17>; <bb 16>: if (r_7(D) <= 9) goto <bb 15>; else goto <bb 17>; <bb 17>: return 0; <bb 18>: # v_22 = PHI <r_7(D)(3)> goto <bb 8>; }