From mboxrd@z Thu Jan 1 00:00:00 1970 From: tlaronde@polynum.com Date: Thu, 22 Apr 2010 17:29:53 +0200 To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Message-ID: <20100422152953.GA616@polynum.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.3i Subject: [9fans] BUG!!! in Plan9 compiler! Topicbox-Message-UUID: 0b9b10d8-ead6-11e9-9d60-3106f5b1d025 So I have finally narrow down and compare the calculus under NetBSD/i386/gcc and Plan9/i386/ken-cc. And this has nothing to do with div versus shift... ken-cc is at fault here and it seems deep; it has apparently to deal with registerization. Data: Under NetBSD/gcc, I have the following values: before: x1:=5440, x2:=-5843, x3:=78909 after: x1:=5440, x2:=-201, x3:=18166, r:=6827 t:=30232 Under Plan9/gcc, I have the following values: before: x1:=5440, x2:=-5843, x3:=78909 after: x1:=5440, x2:=2147483447, x3:=1073759990, r:=6827 t:=-1073711592 Uhm... seems to have a `slight' divergence... In fact, all wrong values depend upon x2, that has the "correct" value... with 2^31 complement. A positive when it should be negative, since the offending code is the following: x2 = half ( x1 + x2 + xicorr ) ; that is : x2 = (5440 - 5843 + 1) / 2; Not exactly pushing things to the limit! And yes, the expected result is indeed -201. In fact, if you just extract this kind of expression, and compile a test, there is no problem. But the calling function is teratologic: it has 10 parameters and 18 automatic variables. Since the problem arises in this context, but not if you just add this isolated in a test program, and call it with these very 3 values (5440, -5843, 1), it is clear that's the way the computation is handled with huge number of parameters and auto variables that wreaks havoc. If I declare all the auto volatile, this does nothing: same result. If I do the addition, and afterwards take the half, that works: x2 += x1 + xicorr; x2 = half(x2); /* works! */ Problem: this is not a solution, but a hack, since this kind of 3 variables handling is common. This one fails. And the others? Is there a limit about the number of parameters? -- Thierry Laronde http://www.kergis.com/ Key fingerprint = 0FF7 E906 FBAF FE95 FD89 250D 52B1 AE95 6006 F40C