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