Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 Dec 2012 12:17:53 -0500 (EST)
From:      Keith White <kwhite@uottawa.ca>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/174240: bin/clang i386 generates incorrect code for ports/devel/dev86
Message-ID:  <201212061717.qB6HHrNW004277@localhost.my.domain>
Resent-Message-ID: <201212061750.qB6Ho0Nl055096@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         174240
>Category:       bin
>Synopsis:       bin/clang i386 generates incorrect code for ports/devel/dev86
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Dec 06 17:50:00 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator:     Keith White
>Release:        FreeBSD 10.0-CURRENT amd64
>Organization:
SITE, University of Ottawa
>Environment:
System: FreeBSD freebsd10 10.0-CURRENT FreeBSD 10.0-CURRENT #10 r243890M: Wed Dec 5 11:39:25 EST 2012 root@freebsd10:/usr/obj/usr/src/sys/GENERIC amd64


	
>Description:
clang (i386) compiles ports/devel/dev86/.../as/genlist.c:build_number()
to an infinite loop when optimization -O2 is turned on.

	
>How-To-Repeat:

Extract build_number() from ports/devel/dev86/.../as/genlist.c

=== bn.c ===
PUBLIC char *build_number(num, width, where)
unsigned num;
unsigned width;
register char *where;
{
    static unsigned powers_of_10[] = {1, 10, 100, 1000, 10000,};
    unsigned char digit;
    unsigned char power;
    register unsigned power_of_10;

    power = 5;                  /* actually 1 more than power */
    do
    {
        for (digit = '0', power_of_10 = (powers_of_10 - 1)[power];
             num >= power_of_10; num -= power_of_10)
            ++digit;
        if (power <= width)
            *where++ = digit;
    }
    while (--power != 0);
    return where;
}
============
clang -m32 --version
	FreeBSD clang version 3.2 (branches/release_32 168974) 20121130
	Target: i386-unknown-freebsd10.0
	Thread model: posix

clang -O2 -DPUBLIC="" -m32 -c -save-temps bn.c
cat bn.s
	...
	build_number:                           # @build_number
	# BB#0:                                 # %for.body.lr.ph
		.align	16, 0x90
	.LBB0_1:                                # %for.body
                                        # =>This Inner Loop Header: Depth=1
		jmp	.LBB0_1
	...

>Fix:

Fix to clang unknown.

clang generates correct code when "power" is made volatile.

==== devel/dev86 port patch ====
--- dev86-0.16.18/as/genlist.c.orig     2001-06-23 16:13:19.000000000 -0400
+++ dev86-0.16.18/as/genlist.c  2012-12-06 12:11:26.000000000 -0500
@@ -113,7 +113,7 @@
 {
     static unsigned powers_of_10[] = {1, 10, 100, 1000, 10000,};
     unsigned char digit;
-    unsigned char power;
+    volatile unsigned char power;
     register unsigned power_of_10;
 
     power = 5;                 /* actually 1 more than power */
====

...keith
>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201212061717.qB6HHrNW004277>