scc

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

commit a76a140d9965d255ecb952c8d9522c3f2036c280
parent 8c478f26e5b418f2ac6039c25ab3ac67554f5e63
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed,  1 Jan 2025 21:51:03 +0100

cc1: Avoid cast node in pointer conversions

When a pointer is converted to any other pointer no changes
happen in the expression, only the type changes. But adding
a new cast node hides some flags that the original node had,
like for example constant addresses were missing the constant
attribute.

Diffstat:
Msrc/cmd/scc-cc/cc1/expr.c | 10+++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/cmd/scc-cc/cc1/expr.c b/src/cmd/scc-cc/cc1/expr.c @@ -324,16 +324,20 @@ convert(Node *np, Type *newtp, int iscast) goto good_conv; } else if (op == PTR) { if (eqtype(newtp, oldtp, EQUIV)) - goto good_conv; + goto good_ptr_conv; if (iscast) - goto good_conv; + goto good_ptr_conv; if (newtp == pvoidtype || oldtp == pvoidtype) - goto good_conv; + goto good_ptr_conv; } default: return NULL; } +good_ptr_conv: + np->type = newtp; + return np; + good_conv: return node(OCAST, newtp, np, NULL); }