[M3devel] thouhts on -Wall with C backend output

Jay K jay.krell at cornell.edu
Wed Jan 9 07:46:00 CET 2013


I'm going with "gcc -Wno-return-type " for now. Alas.

I put in "default:assert(!"case_jump hit default") for case_jumps, but of coursethat doesn't help.

If/when I make the C backend even more sophisticated, I'll detectlabel:;} // end of non-void function
and change it to:label:assert(!"control reaches end of non-void function");} // end of non-void function

This level of sophistication is basically to run the last pass multiple times, suppressing some/most logic/code, esp. the prints on all but the last pass.
The other passes, so far, have been useful in that they run over a subset of operations, and leavefewer for the last pass to deal with.
Hm. I do have "op_index", so at end of function, I might be able to just look back one operation for the set_label.
But that wouldn't detect:label: a = b;} // end of function
maybe that never occurs.
I also can't likely just put the assert at the end of every non-void function. 1) it bloats the code a bit 2) it would be usually unreachable.
I'm not even sure gcc wouldn't complain here about reachability...except..I already omit unused labels, so I know this label is branched to... anyway..later...

 - Jay


> To: jay.krell at cornell.edu
> Date: Sun, 16 Dec 2012 23:49:35 -0800
> From: mika at async.caltech.edu
> CC: m3devel at elegosoft.com
> Subject: Re: [M3devel] thouhts on -Wall with C backend output
> 
> Yeah it sounds like the frontend knows something that it's not telling
> the backend about... if I am reading your emails right.
> 
> Jay K writes:
> >--_ad389312-f922-410e-bb8f-e7106388428f_
> >Content-Type: text/plain; charset="Windows-1252"
> >Content-Transfer-Encoding: quoted-printable
> >
> >
> >drat=2C these are worse:
> >
> >"../src/Macro.m3"=2C line 949: warning: unreachable ELSE in TYPECASE
> >
> >
> >=3D=3D package /Users/jay/dev2/cm3/m3-ui/formsvbt =3D=3D
> >
> > +++ /cm3/bin/cm3    -build -DROOT=3D/Users/jay/dev2/cm3 +++
> >--- building in AMD64_DARWIN ---
> >
> >ignoring ../src/m3overrides
> >
> >new source -> compiling Macro.m3
> >cc1plus: warnings being treated as errors
> >Macro.mc.c: In function =91char* Macro__EvalLength(char*=2C char*)=92:
> >Macro.mc.c:5271: warning: control reaches end of non-void function
> >Macro.mc.c: In function =91char* Macro__EvalPlus(char*=2C char*)=92:
> >Macro.mc.c:9004: warning: control reaches end of non-void function
> >Macro.mc.c: In function =91char* Macro__EvalMinus(char*=2C char*)=92:
> >Macro.mc.c:9468: warning: control reaches end of non-void function
> >
> >
> >If I put in the somewhat obvious:
> >
> >
> >    ELSE <* ASSERT FALSE *>
> >
> >
> >then:
> >
> >new source -> compiling Macro.m3
> >"../src/Macro.m3"=2C line 949: warning: unreachable ELSE in TYPECASE
> >1 warning encountered
> >cc1plus: warnings being treated as errors
> >Macro.mc.c: In function =91char* Macro__EvalLength(char*=2C char*)=92:
> >Macro.mc.c:5271: warning: control reaches end of non-void function
> >Macro.mc.c: In function =91char* Macro__EvalPlus(char*=2C char*)=92:
> >Macro.mc.c:9004: warning: control reaches end of non-void function
> >
> >
> >
> >For stablegen=2C I am inclined to put in that ELSE <* ASSERT FALSE *>.
> >
> >
> >I might might might be able to put in C assert(false) in these places.
> >
> > - Jay
> >
> >
> >> To: hendrik at topoi.pooq.com
> >> Date: Sun=2C 16 Dec 2012 10:55:29 -0800
> >> From: mika at async.caltech.edu
> >> CC: m3devel at elegosoft.com
> >> Subject: Re: [M3devel] thouhts on -Wall with C backend output
> >>=20
> >> Can you have an option to add an assertion in the output for these cases?
> >>=20
> >> Here either
> >>=20
> >> 1. gcc has found a bug in the C code generator and/or front end=2C in tha=
> >t
> >>    there's no default (abortion) case
> >>=20
> >> or
> >>=20
> >> 2. the front end has deduced there is no need for abortion because it can
> >>    see that the missing ELSE is never going to be exercised=2C based on t=
> >he
> >>    already existing type information
> >>=20
> >> What I'm proposing is two modes for the compiler:
> >>=20
> >> -- ignore the errors
> >>=20
> >> or
> >>=20
> >> -- add proper assertions to the C code=2C e.g.=2C=20
> >>=20
> >>     assert(false=2C "front-end deduced this cant happen by inspecting typ=
> >e information")
> >>=20
> >>    which=2C when enabled=2C should make gcc shut up=2C and instead turn i=
> >nto
> >>    runtime checks on the compiler
> >>=20
> >>       Mika
> >>=20
> >> Hendrik Boom writes:
> >> >On Sun=2C Dec 16=2C 2012 at 09:58:10AM +0000=2C Jay K wrote:
> >> >>=20
> >> >> I've tried to generate "very good C".
> >> >> I've fixed some of what gcc -Wall complains about.
> >> >> For default gcc on my old MacBook -- old enough that it can still emul=
> >ate PowerPC=2C gcc is 4.0.1.
> >> >> (at least one of what I deal with=2C I think anything newer won't comp=
> >lain..)
> >> >>=20
> >> >>=20
> >> >>=20
> >> >> do-cm3-all with -Wall -Werror gets very far=2C to:
> >> >>=20
> >> >> =3D=3D package /Users/jay/dev2/cm3/m3-db/stablegen =3D=3D
> >> >>=20
> >> >>  +++ /cm3/bin/cm3    -build -DROOT=3D/Users/jay/dev2/cm3 +++
> >> >> --- building in AMD64_DARWIN ---
> >> >>=20
> >> >> ignoring ../src/m3overrides
> >> >>=20
> >> >> w source -> compiling GenCode.m3
> >> >> cc1: warnings being treated as errors
> >> >> GenCode.mc.c: In function =91GenCode__BuildMethods__Search=92:
> >> >> GenCode.mc.c:3505: warning: control reaches end of non-void function
> >> >>   m3_backend =3D> 1
> >> >>=20
> >> >>   PROCEDURE Search (    type    : Type.Reference=3B
> >> >>                     VAR count   : INTEGER=3B
> >> >>                     VAR top     : CARDINAL=3B
> >> >>                         umethods: AtomList.T   ):
> >> >>     ImportList.MethodList RAISES {StablegenError.E} =3D
> >> >>     VAR methods: ImportList.MethodList=3B
> >> >>     BEGIN
> >> >>       IF (type =3D Type.root) OR (type =3D NIL) THEN (* base of
> >> >>                                                     recursion *)
> >> >>         RETURN NEW(ImportList.MethodList=2C ABS(count))
> >> >>       ELSE
> >> >>     TYPECASE type OF
> >> >>           Type.Object (ob) =3D>=20
> >> >>           IF count <=3D 0 THEN
> >> >>             count:=3D count - NUMBER(ob.methods^)
> >> >>           END=3B
> >> >>           methods :=3D Search(ob.super=2C count=2C top=2C umethods)=3B
> >> >>           FOR i :=3D 0 TO LAST(ob.methods^) DO
> >> >>             IF umethods =3D NIL
> >> >>               OR AtomList.Member(
> >> >>                      umethods=2C ob.methods[i].name) THEN
> >> >>               IF AtomList.Member(reserved=2C ob.methods[i].name) THEN
> >> >>                 RAISE StablegenError.E(Atom.ToText(ob.methods[i].name)
> >> >>                 &" is a reserved method name in stable objects. "
> >> >>                 &"Must not be an update method.")
> >> >>               END=3B
> >> >>               methods[top].name :=3D ob.methods[i].name=3B
> >> >>               methods[top].sig :=3D ob.methods[i].sig=3B
> >> >>               INC(top)
> >> >>             END
> >> >>           END=3B
> >> >>           RETURN methods
> >> >>         | Type.Opaque (op) =3D>
> >> >>           RETURN Search(op.revealedSuperType=2C count=2C top=2C umetho=
> >ds)
> >> >>         | Type.Reference =3D> <*ASSERT FALSE*>
> >> >>         END
> >> >>       END
> >> >>     END Search=3B
> >> >>=20
> >> >> I think we can't expect gcc -Wall -Werror to pass.
> >> >> I really wanted it to=2C and I tried=2C and I fixed stuff.
> >> >> But I don't think it is viable.
> >> >> Ok?
> >> >
> >> >Could  it be that the TYPECASE doesn't have an ELSE clause=2C possibly
> >> >translated to a switch withouy a default: label?  This would give the
> >> >C code an apparent path to the end of the function.  M3 may know that
> >> >the TYPECASE exhausts all the possibilities=2C but C will not.
> >> >
> >> >-- hendrik
> > 		 	   		  =
> >
> >--_ad389312-f922-410e-bb8f-e7106388428f_
> >Content-Type: text/html; charset="Windows-1252"
> >Content-Transfer-Encoding: quoted-printable
> >
> ><html>
> ><head>
> ><style><!--
> >.hmmessage P
> >{
> >margin:0px=3B
> >padding:0px
> >}
> >body.hmmessage
> >{
> >font-size: 10pt=3B
> >font-family:Tahoma
> >}
> >--></style></head>
> ><body class=3D'hmmessage'><div dir=3D'ltr'>
> >drat=2C these are worse:<br><br>"../src/Macro.m3"=2C line 949: warning: unr=
> >eachable ELSE in TYPECASE<br><br><br>=3D=3D package /Users/jay/dev2/cm3/m3-=
> >ui/formsvbt =3D=3D<br><br>&nbsp=3B+++ /cm3/bin/cm3&nbsp=3B&nbsp=3B&nbsp=3B =
> >-build -DROOT=3D/Users/jay/dev2/cm3 +++<br>--- building in AMD64_DARWIN ---=
> ><br><br>ignoring ../src/m3overrides<br><br>new source -&gt=3B compiling Mac=
> >ro.m3<br>cc1plus: warnings being treated as errors<br>Macro.mc.c: In functi=
> >on =91char* Macro__EvalLength(char*=2C char*)=92:<br>Macro.mc.c:5271: warni=
> >ng: control reaches end of non-void function<br>Macro.mc.c: In function =91=
> >char* Macro__EvalPlus(char*=2C char*)=92:<br>Macro.mc.c:9004: warning: cont=
> >rol reaches end of non-void function<br>Macro.mc.c: In function =91char* Ma=
> >cro__EvalMinus(char*=2C char*)=92:<br>Macro.mc.c:9468: warning: control rea=
> >ches end of non-void function<br><br><br>If I put in the somewhat obvious:<=
> >br><br><br>&nbsp=3B&nbsp=3B&nbsp=3B ELSE &lt=3B* ASSERT FALSE *&gt=3B<br><b=
> >r><br>then:<br><br>new source -&gt=3B compiling Macro.m3<br>"../src/Macro.m=
> >3"=2C line 949: warning: unreachable ELSE in TYPECASE<br>1 warning encounte=
> >red<br>cc1plus: warnings being treated as errors<br>Macro.mc.c: In function=
> > =91char* Macro__EvalLength(char*=2C char*)=92:<br>Macro.mc.c:5271: warning=
> >: control reaches end of non-void function<br>Macro.mc.c: In function =91ch=
> >ar* Macro__EvalPlus(char*=2C char*)=92:<br>Macro.mc.c:9004: warning: contro=
> >l reaches end of non-void function<br><br><br><br>For stablegen=2C I am inc=
> >lined to put in that ELSE &lt=3B* ASSERT FALSE *&gt=3B.<br><br><br>I might =
> >might might be able to put in C assert(false) in these places.<br><br>&nbsp=
> >=3B- Jay<br><br><br><div><div id=3D"SkyDrivePlaceholder"></div>&gt=3B To: h=
> >endrik at topoi.pooq.com<br>&gt=3B Date: Sun=2C 16 Dec 2012 10:55:29 -0800<br>=
> >&gt=3B From: mika at async.caltech.edu<br>&gt=3B CC: m3devel at elegosoft.com<br>=
> >&gt=3B Subject: Re: [M3devel] thouhts on -Wall with C backend output<br>&gt=
> >=3B <br>&gt=3B Can you have an option to add an assertion in the output for=
> > these cases?<br>&gt=3B <br>&gt=3B Here either<br>&gt=3B <br>&gt=3B 1. gcc =
> >has found a bug in the C code generator and/or front end=2C in that<br>&gt=
> >=3B    there's no default (abortion) case<br>&gt=3B <br>&gt=3B or<br>&gt=3B=
> > <br>&gt=3B 2. the front end has deduced there is no need for abortion beca=
> >use it can<br>&gt=3B    see that the missing ELSE is never going to be exer=
> >cised=2C based on the<br>&gt=3B    already existing type information<br>&gt=
> >=3B <br>&gt=3B What I'm proposing is two modes for the compiler:<br>&gt=3B =
> ><br>&gt=3B -- ignore the errors<br>&gt=3B <br>&gt=3B or<br>&gt=3B <br>&gt=
> >=3B -- add proper assertions to the C code=2C e.g.=2C <br>&gt=3B <br>&gt=3B=
> >     assert(false=2C "front-end deduced this cant happen by inspecting type=
> > information")<br>&gt=3B <br>&gt=3B    which=2C when enabled=2C should make=
> > gcc shut up=2C and instead turn into<br>&gt=3B    runtime checks on the co=
> >mpiler<br>&gt=3B <br>&gt=3B       Mika<br>&gt=3B <br>&gt=3B Hendrik Boom wr=
> >ites:<br>&gt=3B &gt=3BOn Sun=2C Dec 16=2C 2012 at 09:58:10AM +0000=2C Jay K=
> > wrote:<br>&gt=3B &gt=3B&gt=3B <br>&gt=3B &gt=3B&gt=3B I've tried to genera=
> >te "very good C".<br>&gt=3B &gt=3B&gt=3B I've fixed some of what gcc -Wall =
> >complains about.<br>&gt=3B &gt=3B&gt=3B For default gcc on my old MacBook -=
> >- old enough that it can still emulate PowerPC=2C gcc is 4.0.1.<br>&gt=3B &=
> >gt=3B&gt=3B (at least one of what I deal with=2C I think anything newer won=
> >'t complain..)<br>&gt=3B &gt=3B&gt=3B <br>&gt=3B &gt=3B&gt=3B <br>&gt=3B &g=
> >t=3B&gt=3B <br>&gt=3B &gt=3B&gt=3B do-cm3-all with -Wall -Werror gets very =
> >far=2C to:<br>&gt=3B &gt=3B&gt=3B <br>&gt=3B &gt=3B&gt=3B =3D=3D package /U=
> >sers/jay/dev2/cm3/m3-db/stablegen =3D=3D<br>&gt=3B &gt=3B&gt=3B <br>&gt=3B =
> >&gt=3B&gt=3B  +++ /cm3/bin/cm3    -build -DROOT=3D/Users/jay/dev2/cm3 +++<b=
> >r>&gt=3B &gt=3B&gt=3B --- building in AMD64_DARWIN ---<br>&gt=3B &gt=3B&gt=
> >=3B <br>&gt=3B &gt=3B&gt=3B ignoring ../src/m3overrides<br>&gt=3B &gt=3B&gt=
> >=3B <br>&gt=3B &gt=3B&gt=3B w source -&gt=3B compiling GenCode.m3<br>&gt=3B=
> > &gt=3B&gt=3B cc1: warnings being treated as errors<br>&gt=3B &gt=3B&gt=3B =
> >GenCode.mc.c: In function =91GenCode__BuildMethods__Search=92:<br>&gt=3B &g=
> >t=3B&gt=3B GenCode.mc.c:3505: warning: control reaches end of non-void func=
> >tion<br>&gt=3B &gt=3B&gt=3B   m3_backend =3D&gt=3B 1<br>&gt=3B &gt=3B&gt=3B=
> > <br>&gt=3B &gt=3B&gt=3B   PROCEDURE Search (    type    : Type.Reference=
> >=3B<br>&gt=3B &gt=3B&gt=3B                     VAR count   : INTEGER=3B<br>=
> >&gt=3B &gt=3B&gt=3B                     VAR top     : CARDINAL=3B<br>&gt=3B=
> > &gt=3B&gt=3B                         umethods: AtomList.T   ):<br>&gt=3B &=
> >gt=3B&gt=3B     ImportList.MethodList RAISES {StablegenError.E} =3D<br>&gt=
> >=3B &gt=3B&gt=3B     VAR methods: ImportList.MethodList=3B<br>&gt=3B &gt=3B=
> >&gt=3B     BEGIN<br>&gt=3B &gt=3B&gt=3B       IF (type =3D Type.root) OR (t=
> >ype =3D NIL) THEN (* base of<br>&gt=3B &gt=3B&gt=3B                        =
> >                             recursion *)<br>&gt=3B &gt=3B&gt=3B         RE=
> >TURN NEW(ImportList.MethodList=2C ABS(count))<br>&gt=3B &gt=3B&gt=3B       =
> >ELSE<br>&gt=3B &gt=3B&gt=3B     TYPECASE type OF<br>&gt=3B &gt=3B&gt=3B    =
> >       Type.Object (ob) =3D&gt=3B <br>&gt=3B &gt=3B&gt=3B           IF coun=
> >t &lt=3B=3D 0 THEN<br>&gt=3B &gt=3B&gt=3B             count:=3D count - NUM=
> >BER(ob.methods^)<br>&gt=3B &gt=3B&gt=3B           END=3B<br>&gt=3B &gt=3B&g=
> >t=3B           methods :=3D Search(ob.super=2C count=2C top=2C umethods)=3B=
> ><br>&gt=3B &gt=3B&gt=3B           FOR i :=3D 0 TO LAST(ob.methods^) DO<br>&=
> >gt=3B &gt=3B&gt=3B             IF umethods =3D NIL<br>&gt=3B &gt=3B&gt=3B  =
> >             OR AtomList.Member(<br>&gt=3B &gt=3B&gt=3B                    =
> >  umethods=2C ob.methods[i].name) THEN<br>&gt=3B &gt=3B&gt=3B              =
> > IF AtomList.Member(reserved=2C ob.methods[i].name) THEN<br>&gt=3B &gt=3B&g=
> >t=3B                 RAISE StablegenError.E(Atom.ToText(ob.methods[i].name)=
> ><br>&gt=3B &gt=3B&gt=3B                 &amp=3B" is a reserved method name =
> >in stable objects. "<br>&gt=3B &gt=3B&gt=3B                 &amp=3B"Must no=
> >t be an update method.")<br>&gt=3B &gt=3B&gt=3B               END=3B<br>&gt=
> >=3B &gt=3B&gt=3B               methods[top].name :=3D ob.methods[i].name=3B=
> ><br>&gt=3B &gt=3B&gt=3B               methods[top].sig :=3D ob.methods[i].s=
> >ig=3B<br>&gt=3B &gt=3B&gt=3B               INC(top)<br>&gt=3B &gt=3B&gt=3B =
> >            END<br>&gt=3B &gt=3B&gt=3B           END=3B<br>&gt=3B &gt=3B&gt=
> >=3B           RETURN methods<br>&gt=3B &gt=3B&gt=3B         | Type.Opaque (=
> >op) =3D&gt=3B<br>&gt=3B &gt=3B&gt=3B           RETURN Search(op.revealedSup=
> >erType=2C count=2C top=2C umethods)<br>&gt=3B &gt=3B&gt=3B         | Type.R=
> >eference =3D&gt=3B &lt=3B*ASSERT FALSE*&gt=3B<br>&gt=3B &gt=3B&gt=3B       =
> >  END<br>&gt=3B &gt=3B&gt=3B       END<br>&gt=3B &gt=3B&gt=3B     END Searc=
> >h=3B<br>&gt=3B &gt=3B&gt=3B <br>&gt=3B &gt=3B&gt=3B I think we can't expect=
> > gcc -Wall -Werror to pass.<br>&gt=3B &gt=3B&gt=3B I really wanted it to=2C=
> > and I tried=2C and I fixed stuff.<br>&gt=3B &gt=3B&gt=3B But I don't think=
> > it is viable.<br>&gt=3B &gt=3B&gt=3B Ok?<br>&gt=3B &gt=3B<br>&gt=3B &gt=3B=
> >Could  it be that the TYPECASE doesn't have an ELSE clause=2C possibly<br>&=
> >gt=3B &gt=3Btranslated to a switch withouy a default: label?  This would gi=
> >ve the<br>&gt=3B &gt=3BC code an apparent path to the end of the function. =
> > M3 may know that<br>&gt=3B &gt=3Bthe TYPECASE exhausts all the possibiliti=
> >es=2C but C will not.<br>&gt=3B &gt=3B<br>&gt=3B &gt=3B-- hendrik<br></div>=
> > 		 	   		  </div></body>
> ></html>=
> >
> >--_ad389312-f922-410e-bb8f-e7106388428f_--
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://m3lists.elegosoft.com/pipermail/m3devel/attachments/20130109/73a6cdec/attachment-0001.html>


More information about the M3devel mailing list