commit 91d6c4c2e9cf507de205fab129a65be40fb1c6b3
parent 9e85b6a1ad15b70aefd3436ca605aea2f523f335
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Tue, 10 Feb 2026 11:26:43 +0100
cc2: Keep label position in commas
When a comma 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, 16 insertions(+), 0 deletions(-)
diff --git a/src/cmd/scc-cc/cc2/sethi.c b/src/cmd/scc-cc/cc2/sethi.c
@@ -184,6 +184,7 @@ sethi(Node *np)
np->u.sym->refcnt--;
return NULL;
case OCOMMA:
+ keeplabel();
r = np->right;
comma(np->left);
return replace(np, r);
diff --git a/tests/cc/execute/0245-comma.c b/tests/cc/execute/0245-comma.c
@@ -0,0 +1,14 @@
+int but, aclick;
+
+int
+main(void)
+{
+ int r;
+
+ aclick = 1;
+ but = 1;
+ r = 1;
+ if (aclick == 1 && but == 1)
+ r = ((aclick = 0) + 1 , aclick);
+ return r;
+}
diff --git a/tests/cc/execute/scc-tests.lst b/tests/cc/execute/scc-tests.lst
@@ -235,3 +235,4 @@
0242-ternary.c
0243-ternary.c
0244-logic.c
+0245-comma.c