Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,866
    • Issues 4,866
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 457
    • Merge requests 457
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #2961
Closed
Open
Created Jan 16, 2009 by sjanssen@cse.unl.edu@trac-sjanssen

Incorrect FFI code generated with -O

GHC 6.10.1 seems to generate incorrect code for createWindow in X11-1.4.3 on x86_64 when optimizations are on.

    $ ghc-6.10.1 -fforce-recomp --make simple.hs -O0 -o simple
    $ ghc-6.10.1 -fforce-recomp --make simple.hs -O -o simple_optimized

When built with no optimizations, the program succeeds:

    $ ./simple
    (33554433,Display 0x0000000001192dd0,Screen 0x0000000001193a40,194)

When built with optimizations, the X server sends an error about an invalid parameter to a XCreateWindow call:

    $ ./simple_optimized 
    (33554433,Display 0x0000000000b91dd0,Screen 0x0000000000b92a40,194)
    X Error of failed request:  BadMatch (invalid parameter attributes)
      Major opcode of failed request:  1 (X_CreateWindow)
      Serial number of failed request:  7
      Current serial number in output stream:  8

We set a breakpoint at XCreateWindow to check the arguments passed, note that depth takes the correct value in the non-optimized version:

    $ gdb simple
    (gdb) break XCreateWindow
    (gdb) run
    ...
    Breakpoint 1, XCreateWindow (dpy=0x172bde0, parent=194, x=0, y=0, width=100, height=100, 
        borderWidth=0, depth=24, class=1, visual=0x17333d0, valuemask=512, 
        attributes=0x7f920a77e040) at ../../src/Window.c:115
    115     ../../src/Window.c: No such file or directory.
        in ../../src/Window.c

The optimized version has "depth=38044640", which is total nonsense. The value seems to change from run to run.

    $ gdb simple_optimized
    (gdb) break XCreateWindow
    (gdb) run
    ...
    Breakpoint 1, XCreateWindow (dpy=0x2440df0, parent=194, x=0, y=0, width=100, height=100, 
        borderWidth=0, depth=38044640, class=1, visual=0x24483e0, valuemask=512, 
        attributes=0x7f84f577e040) at ../../src/Window.c:115
    115     ../../src/Window.c: No such file or directory.
        in ../../src/Window.c

We discovered this bug in xmonad (http://xmonad.org/bugs/226), and have temporarily worked around it by using Cabal's --disable-optimization flag.

Trac metadata
Trac field Value
Version 6.10.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (FFI)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking