scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit f3c4d6c3e0822ccf373935eb8851660bbd298931
parent 46588de4ca1b0a4c47591d61c5947dc1a3238ce5
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date:   Tue, 10 Feb 2026 11:00:03 +0100

cc2: Preserve labels in replace()

The intention of replace is replacing a node with other, but in
case the original node had a label it was lost in the replace
process.

Diffstat:
Msrc/cmd/scc-cc/cc2/sethi.c | 4++++
Atests/cc/execute/0242-ternary.c | 9+++++++++
Mtests/cc/execute/scc-tests.lst | 1+
3 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/src/cmd/scc-cc/cc2/sethi.c b/src/cmd/scc-cc/cc2/sethi.c @@ -140,11 +140,15 @@ static Node * replace(Node *what, Node *with) { Node *prev, *next; + Symbol *label; + label = what->label; next = what->next, prev = what->prev; + *what = *with; delnode(with); what->next = next, what->prev = prev; + what->label = label; return sethi(what); } diff --git a/tests/cc/execute/0242-ternary.c b/tests/cc/execute/0242-ternary.c @@ -0,0 +1,9 @@ +int but, aclick; + +int +main(void) +{ + if (aclick == 1 && but) + (but == 1) ? 0 : 1; + return 0; +} diff --git a/tests/cc/execute/scc-tests.lst b/tests/cc/execute/scc-tests.lst @@ -232,3 +232,4 @@ 0239-fcasts.c 0240-init.c 0241-init.c +0242-ternary.c