9front - general discussion about 9front
 help / color / mirror / Atom feed
* Re: [9front] Ape: Fix assert warnings.
@ 2019-06-18 14:35 cinap_lenrek
  2019-06-18 16:36 ` Ori Bernstein
  0 siblings, 1 reply; 7+ messages in thread
From: cinap_lenrek @ 2019-06-18 14:35 UTC (permalink / raw)
  To: 9front

this is not full fix tho. it still warns for non-constant case...

--
cinap


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9front] Ape: Fix assert warnings.
  2019-06-18 14:35 [9front] Ape: Fix assert warnings cinap_lenrek
@ 2019-06-18 16:36 ` Ori Bernstein
  0 siblings, 0 replies; 7+ messages in thread
From: Ori Bernstein @ 2019-06-18 16:36 UTC (permalink / raw)
  To: 9front

On Tue, 18 Jun 2019 16:35:07 +0200, cinap_lenrek@felloff.net wrote:

> this is not full fix tho. it still warns for non-constant case...

stdio putc has a similar issue to this, but it *needs* to 
return an int, so a void cast isn't quite enough anyways.

I'd thought of making USED() an expression, so we could do:

	x = USED(a?b:c)

Thinking about it more, a better solution may be to say that
if one of the ternary branches has side effects, the other is
implicitly USED(), which will solve this warning.

	0 ? 0 : 1

should warn, but

	1 ? 0 : printf("nope");

should be silent, because printf has a side effect.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9front] Ape: Fix assert warnings.
  2019-06-18 16:46 cinap_lenrek
@ 2019-06-18 20:37 ` Ori Bernstein
  0 siblings, 0 replies; 7+ messages in thread
From: Ori Bernstein @ 2019-06-18 20:37 UTC (permalink / raw)
  To: 9front; +Cc: cinap_lenrek

I'll look more at the compiler, instead of committing workarounds.

On Tue, 18 Jun 2019 18:46:19 +0200
cinap_lenrek@felloff.net wrote:

> no, stdio putc() macro has a different problem.
> 
> the null warning comes from trailing int cast
> after the character assignment:
> 
> CAST INT (1) /tmp/b.c:6[stdin:231]
>    AS CHAR (1) /tmp/b.c:6[stdin:231]
>       IND CHAR (1) /tmp/b.c:6[stdin:231]
>          POSTINC IND CHAR (1) /tmp/b.c:6[stdin:231]
>             NAME "_IO_stream" 48 <10> IND CHAR /tmp/b.c:6[stdin:231]
>             Z
>          Z
>       CONST "33" <20> CHAR /tmp/b.c:6[stdin:231]
>    Z
> 
> the compiler could statically know if the COND has a
> result and not insert the cast.
> 
> --
> cinap
> 


-- 
Ori Bernstein <ori@eigenstate.org>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9front] Ape: Fix assert warnings.
@ 2019-06-18 16:46 cinap_lenrek
  2019-06-18 20:37 ` Ori Bernstein
  0 siblings, 1 reply; 7+ messages in thread
From: cinap_lenrek @ 2019-06-18 16:46 UTC (permalink / raw)
  To: 9front

no, stdio putc() macro has a different problem.

the null warning comes from trailing int cast
after the character assignment:

CAST INT (1) /tmp/b.c:6[stdin:231]
   AS CHAR (1) /tmp/b.c:6[stdin:231]
      IND CHAR (1) /tmp/b.c:6[stdin:231]
         POSTINC IND CHAR (1) /tmp/b.c:6[stdin:231]
            NAME "_IO_stream" 48 <10> IND CHAR /tmp/b.c:6[stdin:231]
            Z
         Z
      CONST "33" <20> CHAR /tmp/b.c:6[stdin:231]
   Z

the compiler could statically know if the COND has a
result and not insert the cast.

--
cinap


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9front] Ape: Fix assert warnings.
@ 2019-06-18 14:37 cinap_lenrek
  0 siblings, 0 replies; 7+ messages in thread
From: cinap_lenrek @ 2019-06-18 14:37 UTC (permalink / raw)
  To: 9front

oh wait. no i'm confused... carry on :)

--
cinap


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9front] Ape: Fix assert warnings.
@ 2019-06-18 14:26 cinap_lenrek
  0 siblings, 0 replies; 7+ messages in thread
From: cinap_lenrek @ 2019-06-18 14:26 UTC (permalink / raw)
  To: 9front

potential fix that makes constant (void) casts non-ops. this
works as cgen() ignores nodes with nil type.

--- a/sys/src/cmd/cc/scon.c	Tue Jun 18 13:29:29 2019 +0200
+++ b/sys/src/cmd/cc/scon.c	Tue Jun 18 16:15:00 2019 +0200
@@ -49,8 +49,11 @@
 		break;
 
 	case OCAST:
-		if(et == TVOID)
+		if(et == TVOID){
+			n->left = Z;
+			n->type = T;
 			return;
+		}
 		et = l->type->etype;
 		if(isf) {
 			if(typefd[et])

--
cinap


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [9front] Ape: Fix assert warnings.
@ 2019-06-18 11:57 cinap_lenrek
  0 siblings, 0 replies; 7+ messages in thread
From: cinap_lenrek @ 2019-06-18 11:57 UTC (permalink / raw)
  To: 9front

i remember assert was changed because there was some
usecase where assert() was used in a expression.

changeset:   6435:c4a6eb67bc9a
user:        mischief <mischief@offblast.org>
date:        Mon Apr 02 21:44:21 2018 -0700
summary:     ape: improve assert macro

maybe mischief can clear up the detalis.

maybe the warning should be fixed in the compiler?

--
cinap


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-06-18 20:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-18 14:35 [9front] Ape: Fix assert warnings cinap_lenrek
2019-06-18 16:36 ` Ori Bernstein
  -- strict thread matches above, loose matches on Subject: below --
2019-06-18 16:46 cinap_lenrek
2019-06-18 20:37 ` Ori Bernstein
2019-06-18 14:37 cinap_lenrek
2019-06-18 14:26 cinap_lenrek
2019-06-18 11:57 cinap_lenrek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).