Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Proposed workaround for long double compiler bug on OpenBSD/sparc64.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | long-double-bug
Files: files | file ages | folders
SHA1:c11d1444e660280c6fc4f0b4d1519b44219ed54f
User & Date: edward 2013-05-02 07:01:35
Context
2013-06-08
01:34
Merge updates from trunk. Leaf check-in: 7872db85 user: edward tags: long-double-bug
2013-05-02
07:01
Proposed workaround for long double compiler bug on OpenBSD/sparc64. check-in: c11d1444 user: edward tags: long-double-bug
00:15
Keep the entry boxes filled in on the hash-color-test webpage. check-in: 8d3ff5a7 user: drh tags: trunk
Changes

Changes to auto.def.

1
2
3
4
5
6
7
8
9
10
...
230
231
232
233
234
235
236
237


























238
239
# System autoconfiguration. Try: ./configure --help

use cc cc-lib

options {
    with-openssl:path|auto|none
                         => {Look for openssl in the given path, or auto or none}
    with-zlib:path       => {Look for zlib in the given path}
    with-tcl:path        => {Enable Tcl integration, with Tcl in the specified path}
    with-tcl-stubs=0     => {Enable Tcl integration via stubs mechanism}
................................................................................

# Check for getpassphrase() for Solaris 10 where getpass() truncates to 10 chars
if {![cc-check-functions getpassphrase]} {
    # Haiku needs this
    cc-check-function-in-lib getpass bsd
}
cc-check-function-in-lib dlopen dl



























make-template Makefile.in
make-config-header autoconfig.h -auto {USE_* FOSSIL_*}


|







 








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


1
2
3
4
5
6
7
8
9
10
...
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# System autoconfiguration. Try: ./configure --help

use cc cc-lib cc-run

options {
    with-openssl:path|auto|none
                         => {Look for openssl in the given path, or auto or none}
    with-zlib:path       => {Look for zlib in the given path}
    with-tcl:path        => {Enable Tcl integration, with Tcl in the specified path}
    with-tcl-stubs=0     => {Enable Tcl integration via stubs mechanism}
................................................................................

# Check for getpassphrase() for Solaris 10 where getpass() truncates to 10 chars
if {![cc-check-functions getpassphrase]} {
    # Haiku needs this
    cc-check-function-in-lib getpass bsd
}
cc-check-function-in-lib dlopen dl

# Check for long double bug
# See test/long-double.test for more information.
set code {
    volatile long long n; volatile long double ld;
    n = 2147483648L; ld = n;
    if (ld < 0) return 1;
}
switch -glob -- [get-define host] {
    sparc64-*-openbsd* {
        msg-checking "Checking for long double bug..."
        # If we're cross compiling we won't be able to run
        # binaries at all, so first check and see if a trivial
        # program runs okay.
        if {[cc-run -code {return 0;}]} {
            if {[cc-run -code $code]} {
                msg-result "not found"
            } else {
                msg-result "found"
                define-append EXTRA_CFLAGS -DLONGDOUBLE_TYPE=double
            }
        } else {
            msg-result "Unable to test, assuming bug not present"
        }
    }
}

make-template Makefile.in
make-config-header autoconfig.h -auto {USE_* FOSSIL_*}

Added autosetup/cc-run.tcl.











































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# @synopsis:
#
# The 'cc-run' module provides a way to compile and run a bit of
# code.  This is not cross compilation friendly and is therefore
# against autosetup's general philosophy, but is sometimes the only
# way to perform a test.
#

use cc

module-options {}

# cc-run is based on cctest in cc.tcl.

# @cc-run ?settings?
# 
# Low level C/C++ program checker. Compiles, links, and runs a small
# C/C++ program according to the arguments and returns 1 if OK, or 0
# if not.
#
# Supported settings are:
#
## -cflags cflags      A list of flags to pass to the compiler
## -includes list      A list of includes, e.g. {stdlib.h stdio.h}
## -declare code       Code to declare before main()
## -lang c|c++         Use the C (default) or C++ compiler
## -libs liblist       List of libraries to link, e.g. {-ldl -lm}
## -code code          Code to compile in the body of main()
## -source code        Compile a complete program. Ignore -includes, -declare and -code
## -sourcefile file    Shorthand for -source [readfile [get-define srcdir]/$file]
#
# Unless -source or -sourcefile is specified, the C program looks like:
#
## #include <firstinclude>   /* same for remaining includes in the list */
##
## declare-code              /* any code in -declare, verbatim */
##
## int main(void) {
##   code                    /* any code in -code, verbatim */
##   return 0;
## }
#
# Any failures are recorded in 'config.log'
#
proc cc-run {args} {
	set src conftest__.c
	set tmp conftest__

	# Easiest way to merge in the settings
	cc-with $args {
		array set opts [cc-get-settings]
	}

	if {[info exists opts(-sourcefile)]} {
		set opts(-source) [readfile [get-define srcdir]/$opts(-sourcefile) "#error can't find $opts(-sourcefile)"]
	}
	if {[info exists opts(-source)]} {
		set lines $opts(-source)
	} else {
		foreach i $opts(-includes) {
			if {$opts(-code) ne "" && ![feature-checked $i]} {
				# Compiling real code with an unchecked header file
				# Quickly (and silently) check for it now

				# Remove all -includes from settings before checking
				set saveopts [cc-update-settings -includes {}]
				msg-quiet cc-check-includes $i
				cc-store-settings $saveopts
			}
			if {$opts(-code) eq "" || [have-feature $i]} {
				lappend source "#include <$i>"
			}
		}
		lappend source {*}$opts(-declare)
		lappend source "int main(void) {"
		lappend source $opts(-code)
		lappend source "return 0;"
		lappend source "}"

		set lines [join $source \n]
	}

	# Build the command line
	set cmdline {}
	lappend cmdline {*}[get-define CCACHE]
	switch -exact -- $opts(-lang) {
		c++ {
			lappend cmdline {*}[get-define CXX] {*}[get-define CXXFLAGS]
		}
		c {
			lappend cmdline {*}[get-define CC] {*}[get-define CFLAGS]
		}
		default {
			autosetup-error "cc-run called with unknown language: $opts(-lang)"
		}
	}

	lappend cmdline {*}$opts(-cflags)

	switch -glob -- [get-define host] {
		*-*-darwin* {
			# Don't generate .dSYM directories
			lappend cmdline -gstabs
		}
	}
	lappend cmdline $src -o $tmp {*}$opts(-libs)

	# At this point we have the complete command line and the
	# complete source to be compiled. Get the result from cache if
	# we can
	if {[info exists ::cc_cache($cmdline,$lines)]} {
		msg-checking "(cached) "
		set ok $::cc_cache($cmdline,$lines)
		if {$::autosetup(debug)} {
			configlog "From cache (ok=$ok): [join $cmdline]"
			configlog "============"
			configlog $lines
			configlog "============"
		}
		return $ok
	}

	writefile $src $lines\n

	set ok 1
	if {[catch {exec-with-stderr {*}$cmdline} result errinfo]} {
		configlog "Failed: [join $cmdline]"
		configlog $result
		configlog "============"
		configlog "The failed code was:"
		configlog $lines
		configlog "============"
		set ok 0
	} else {
		if {$::autosetup(debug)} {
			configlog "Compiled OK: [join $cmdline]"
			configlog "============"
			configlog $lines
			configlog "============"
		}
		if {[catch {exec-with-stderr ./$tmp} result errinfo]} {
			configlog "Failed: $tmp"
			configlog $result
			configlog "============"
			configlog "The failed code was:"
			configlog $lines
			configlog "============"
			set ok 0
		} else {
			if {$::autosetup(debug)} {
				configlog "Ran OK: $tmp"
				configlog "============"
				configlog $lines
				configlog "============"
			}
		}
	}
	file delete $src
	file delete $tmp

	# cache it
	set ::cc_cache($cmdline,$lines) $ok

	return $ok
}

Added test/long-double.test.















































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#
# OpenBSD on 64 bit SPARC has what appears to be a complier bug involving
# the "long double" type.  This has been observed on OpenBSD 5.1 and 5.2
# using the bundled gcc compiler (gcc (GCC) 4.2.1 20070719).
#
# The following progam demonstrates the problem:
#
#     #include <stdio.h>
#
#     int
#     main (int argc, char *argv[])
#     {
#             volatile long long n;
#             volatile long double ld;
#
#             n = 2147483648L;
#             ld = n;
#             printf (" n = %lld\n", n);
#             printf ("ld = %0.17Lg\n", ld);
#
#             return 0;
#     }
#
# Example output, on an x86 system without the bug:
#      n = 2147483648
#     ld = 2147483648
#
# Example output, on an OpenBSD/sparc64 system with the bug:
#      n = 2147483648
#     ld = -2147483648
#
# The bug manifests itself in Fossil by way of a long double in
# SQLite's internal sqlite3AtoF() function.
#
# An example demonstrating the bug using Fossil:
#
#     $ ./fossil new x.fossil
#     $ ./fossil sqlite3 -R x.fossil
#     sqlite> select 2456247.35094206;
#     -2456247.35094206
#     sqlite> .quit
#
# See also:
# 
# [fossil-users] System problem leads to Fossil problem on OpenBSD/sparc64
# http://www.mail-archive.com/fossil-users@lists.fossil-scm.org/msg11144.html
#

# Fossil will write data on $HOME, running 'fossil new' here.
# We need not to clutter the $HOME of the test caller.
set env(HOME) [pwd]

fossil new rep.fossil

proc long-double {testname args} {
  set i 1
  foreach {sql result} $args {
    set out [open test.sql w]
    puts $out $sql
    close $out
    fossil sqlite3 -R rep.fossil < test.sql
    test long-double-$testname.$i {$::RESULT eq $result}
    incr i
  }
}

# Returns "-2456247.35094206" on systems with the long double compiler bug.
long-double 100 "select 2456247.35094206;" "2456247.35094206"

file delete rep.fossil
file delete test.sql