commit 9e85b6a1ad15b70aefd3436ca605aea2f523f335
parent 8be6d9e4cd588fd6110a4252e36848214ad04b28
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Tue, 10 Feb 2026 11:26:43 +0100
cc2: Keep label position in logic expressions
When a logic is transformed into a set of jumps new statements are
inserted before the current statement, displacing the relative position
of the label of the current statement in case of having one. For that
reason in this case we have to create a label statment and place there
the label.
Diffstat:
3 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/src/cmd/scc-cc/cc2/sethi.c b/src/cmd/scc-cc/cc2/sethi.c
@@ -193,6 +193,7 @@ sethi(Node *np)
case ONEG:
case OAND:
case OOR:
+ keeplabel();
return replace(np, logicexpr(np));
default:
np = tsethi(np);
diff --git a/tests/cc/execute/0244-logic.c b/tests/cc/execute/0244-logic.c
@@ -0,0 +1,16 @@
+int but, aclick;
+
+int
+main(void)
+{
+ int r;
+
+ r = 0;
+ if (aclick == 1 && but)
+ r = but == 1 && aclick == 0;
+ if (aclick == 0 && but)
+ r = but == 1 || aclick == 0;
+ if (aclick == 1 && but == 0)
+ r = !but;
+ return r;
+}
diff --git a/tests/cc/execute/scc-tests.lst b/tests/cc/execute/scc-tests.lst
@@ -234,3 +234,4 @@
0241-init.c
0242-ternary.c
0243-ternary.c
+0244-logic.c