2024-11-22 00:07 AEDT

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000240mercuryBugpublic2011-12-09 10:26
Reportermaclarty 
Assigned Towangp 
PrioritynormalSeveritymajorReproducibilityalways
StatusresolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0000240: float unboxing issue on MinGW
DescriptionThe attached program produces incorrect output when compiled on MinGW with rotd-2011-11-29 in grade hlc.gc at -O1 or lower:

$ mmc bug.m -O1 --grade hlc.gc
$ ./bug
0.0
123.0
$ mmc bug.m -O2 --grade hlc.gc
$ ./bug
123.0
123.0

$ uname -a
MINGW32_NT-6.1 TTT 1.0.17(0.48/3/2) 2011-04-24 23:39 i686 Msys

$ gcc --version
gcc.exe (GCC) 4.6.1

11.07-beta-2011-11-30 works.
TagsNo tags attached.
Attached Files
  • ? file icon bug.m (474 bytes) 2011-12-02 20:08

-Relationships
+Relationships

-Notes

~0000422

juliensf (administrator)

Hi,

Does the same also occur with the asm_fast.gc grade on MinGW? Does the same occur on other
non-Windows 32-bit machines.
(If the problem is not restricted to MinGW then it's probably an issue to related to Peter's changes
for unboxed doubles, since that didn't go onto the 11.07 branch.)

~0000423

maclarty (developer)

The problem does not occur with asm_fast.gc or 32bit Linux. I also compared the c file generated on Linux and Windows and there are no differences. Note that I used a different version of gcc on Linux (4.4.3).

~0000424

juliensf (administrator)

I have MinGW gcc 4.5.0 on my laptop so I will give that a try. We should try 4.6.1 on Linux or Mac OS X.

~0000425

juliensf (administrator)

It also occurs with gcc 4.5.0 on MinGW.

~0000427

juliensf (administrator)

-O[01] --common-struct works

-O1 --inline-simple causes both values to be printed incorrectly.

~0000428

maclarty (developer)

I believe the cause of the problem is some incorrect assumptions about how struct fields are aligned. Consider the following C program:

#include <stdio.h>
struct t {
    void *f1;
    double f2;
};
int main() {
    printf("%p\n", &((struct t*)0)->f2);
}

On MinGW this produces 8, but on 32 bit Linux it produces 4.

In the C code generated for bug.m there is the following struct:

struct bug_scalar_cell_group_1 {
  MR_Box f1;
  MR_Float f2;
};

Later on we use MR_hl_field to extract the float field. However MR_hl_field casts the struct to an array of pointers and then looks up element 1. That would look at offset 4, but on MinGW, the float field is at offset 8.

~0000429

wangp (developer)

That'd be it, thanks.

See also bug 0000211

~0000435

wangp (developer)

Fix committed.
+Notes

-Issue History
Date Modified Username Field Change
2011-12-02 20:08 maclarty New Issue
2011-12-02 20:08 maclarty File Added: bug.m
2011-12-02 20:53 juliensf Note Added: 0000422
2011-12-02 20:53 juliensf Status new => feedback
2011-12-02 21:40 maclarty Note Added: 0000423
2011-12-02 21:49 juliensf Note Added: 0000424
2011-12-03 04:58 juliensf Note Added: 0000425
2011-12-03 05:03 juliensf Note Added: 0000427
2011-12-03 11:59 maclarty Note Added: 0000428
2011-12-03 12:36 wangp Note Added: 0000429
2011-12-05 11:00 wangp Status feedback => assigned
2011-12-05 11:00 wangp Assigned To => wangp
2011-12-09 10:25 wangp Note Added: 0000435
2011-12-09 10:26 wangp Status assigned => resolved
2011-12-09 10:26 wangp Resolution open => fixed
+Issue History