g++ 12.0.0 20220109 snapshot (g:90045c5df5b3c8853e7740fb72a11aead1c489bb) fails -fcompare-debug check when compiling the following testcase, reduced from gcc/testsuite/gcc.dg/torture/pr89223.c, w/ -O1: int a[5]; void c () { unsigned int b; for (b = 3; ; b--) a[b] = ({ a[b + 1]; }); } % g++-12.0.0 -O1 -fcompare-debug -c lluhupiv.c g++-12.0.0: error: lluhupiv.c: '-fcompare-debug' failure (length) --- lluhupiv.c.gkd 2022-01-22 15:27:16.168639041 +0700 +++ lluhupiv.gk.c.gkd 2022-01-22 15:27:16.239634334 +0700 @@ -33,7 +33,7 @@ (nil)) (insn # 0 0 3 (set (mem:SI (plus:DI (mult:DI (reg:DI 2 cx [orig:87 b ] [87]) (const_int 4 [0x4])) - (reg/f:DI 5 di [86])) [ a[b_3]+0 S4 A32]) + (reg/f:DI 5 di [86])) [ MEM <int[5]> [(int *)&a][b_3]+0 S4 A32]) (reg:SI 4 si [orig:82 _2 ] [82])) "lluhupiv.c":9:10# {*movsi_internal} (expr_list:REG_DEAD (reg:SI 4 si [orig:82 _2 ] [82]) (expr_list:REG_DEAD (reg:DI 2 cx [orig:87 b ] [87])
Started with r11-963-g80d6f89e78fc3b772701988cc73aa8e8006283be which has been backported to 10.x in r10-8355-g7d919c33fbd29
[apinski@xeond2 src]$ diff -up t.cc.*original t.gk.cc.*original |less --- t.cc.005t.original 2022-01-22 03:44:26.901343652 -0800 +++ t.gk.cc.005t.original 2022-01-22 03:44:27.005343663 -0800 @@ -6,13 +6,19 @@ { unsigned int b; + # DEBUG BEGIN STMT; unsigned int b; + # DEBUG BEGIN STMT; <<cleanup_point <<< Unknown tree: expr_stmt (void) (b = 3) >>>>>; <D.2374>:; + # DEBUG BEGIN STMT; <<cleanup_point <<< Unknown tree: expr_stmt - (void) (a[b] = a[b + 1]) >>>>>; + (void) (a[b] = # DEBUG BEGIN STMT; + a[b + 1];) >>>>>; + # DEBUG BEGIN STMT; <<cleanup_point (void) b-- >>; + # DEBUG BEGIN STMT; goto <D.2374>; } And then we gimplify: + # DEBUG BEGIN_STMT + # DEBUG BEGIN_STMT b = 3; <D.2374>: - _1 = b + 1; - _2 = a[_1]; - a[b] = _2; + # DEBUG BEGIN_STMT + _1 = &a[b]; + # DEBUG BEGIN_STMT + _2 = b + 1; + _3 = a[_2]; + *_1 = _3; + # DEBUG BEGIN_STMT b = b + 4294967295; + # DEBUG BEGIN_STMT goto <D.2374>;
Similar in nature to PR 100733 and PR 103788.
If it is because of -gstatement-frontiers, I've ran out of ideas how to fix them. So unless Alexandre is willing to look at it, I'd suggest to at least turn -gstatement-frontiers off by default.
I think it's reasonable to turn them off (OTOH we then probably lose all test coverage). IIRC gdb doensn't handle any of the advanced debug stuff GCC emits (like views)?
Meanwhile, I've finally added -gno-statement-frontiers to my testing scripts.
I've recommended before that, without any plan to implement consumers for this debug information, keeping it in place is mostly wasteful. AFAICT other debug stmts issued by front-ends could hit the same issue, but those are only theoretical IIRC. On the one hand, disabling the feature would hide the known problem that codegen is sensitive to such debug stmts, but on the other, we can cross that bridge if we get to it again.
GCC 10.4 is being released, retargeting bugs to GCC 10.5.
GCC 10 branch is being closed.