Opened 6 months ago

Closed 5 months ago

#8493 closed bug (fixed)

Can't compile happy + ghc with clang's CPP

Reported by: maxs Owned by:
Priority: highest Milestone: 7.8.1
Component: libraries (other) Version: 7.7
Keywords: happy clang Cc: lukexi@…, kazu@…
Operating System: MacOS X Architecture: Unknown/Multiple
Type of failure: Building GHC failed Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

On OS X MtnLion? with Xcode 5:

Compiling GHC fails early on because the GenericTemate? outputted by happy is syntactically invalid. It is invalid because of tabs inserted into the template that cause the functions to have syntax / indenting errors. I attempted to install happy to patch it, but happy will not compile either because of the tabs.

I think clang's CPP is inserting tabs into lines with > 8 spaces of indentation.

Also the comment lines in the template of this form are invalid for clang and cause it to fail.

# 5 comment

Change History (16)

comment:1 Changed 6 months ago by lukexi

  • Cc lukexi@… added

comment:2 follow-up: Changed 6 months ago by hvr

Do I understand you right, that Clang's CPP converts spaces into tabs? :-/

comment:3 in reply to: ↑ 2 Changed 6 months ago by maxs

Replying to hvr:

Do I understand you right, that Clang's CPP converts spaces into tabs? :-/

So this is what I thought 3 hours ago, I'm not so certain anymore.

I'm trying to build happy (from git, 2cfc3b70cd from https://github.com/simonmar/happy)

If I run:

ghc-7.6.3 -E -cpp templates/GenericTemplate.hs -DHAPPY_ARRAY

Then it has no tabs.

But when I use cabal install instead, the file:

dist/build/happy/happy-tmp/AttrGrammerParser.hs

contains tabs.

cabal builds it with:

'/usr/local/bin/clang-xcode5-wrapper' '-E' '-undef' '-traditional' '-m64' '-fno-stack-protector' '-m64' '-I' 'dist/build/happy/happy-tmp' '-I' 'dist/build/happy/happy-tmp' '-I' 'dist/build/autogen' '-I' 'dist/build/happy/happy-tmp' '-I' '/usr/local/Cellar/ghc/7.6.3/lib/ghc-7.6.3/base-4.6.0.1/include' '-I' '/usr/local/Cellar/ghc/7.6.3/lib/ghc-7.6.3/include' '-D__GLASGOW_HASKELL__=706' '-Ddarwin_BUILD_OS=1' '-Dx86_64_BUILD_ARCH=1' '-Ddarwin_HOST_OS=1' '-Dx86_64_HOST_ARCH=1' '-U __PIC__' '-D__PIC__' '-include' 'dist/build/autogen/cabal_macros.h' '-x' 'c' 'dist/build/happy/happy-tmp/AttrGrammarParser.hs' '-o' '/var/folders/4q/5j7w6x5x3c1bc427tcgvg4sc0000gn/T/ghc10733_0/ghc10733_6.hscpp'

where the wrapper is: https://github.com/ghc-ios/ghc-ios-scripts/blob/master/clang-xcode5-wrapper.hs

comment:4 Changed 6 months ago by hvr

  • Keywords clang added

comment:5 Changed 6 months ago by maxs

I don't think we have a problem with indentation if you use happy 1.18.10 or happy HEAD (2cfc3b70cd). If you use happy 1.19 to compile happy, you may have indentation problems with clang. But HEAD fixed that.

We do however have a problem with some lines with preprocessor "comments".

Happy Version 1.18.10 can compile happy HEAD (with clang).
But if you then try to compile a happy program (like GHC or happy HEAD) with happy HEAD, it will error on:

<built-in>:2:2: Not in scope: `#'

Which is from the happy processed files. They look like:

{-# LINE 1 "templates/GenericTemplate.hs" #-}
# 1 "templates/GenericTemplate.hs"
# 1 "<built-in>" 1
# 1 "templates/GenericTemplate.hs" 2
-- $Id: GenericTemplate.hs,v 1.26 2005/01/14 14:47:22 simonmar Exp $
...

comment:6 Changed 6 months ago by kazu-yamamoto

  • Cc kazu@… added

comment:7 Changed 6 months ago by kazu-yamamoto

I'm using GHC 7.6.3 with the wrapper on Mavericks.

I can compile happy 1.19.0 in this environment.
I can even build GHC head in this environment, too.

If there is something I can verify, please tell me.

P.S.

I got the following warning when configuring happy 1.19.0:

% cabal configure
Resolving dependencies...
[1 of 1] Compiling Main             ( Setup.lhs, dist/setup/Main.o )
Linking ./dist/setup/setup ...
Configuring happy-1.19.0...

/var/folders/k0/548g5xg90jjfbrj5j09nvwv80000gq/T/4321.c:1:12:
     warning: control reaches end of non-void function [-Wreturn-type]
int foo() {}
           ^
1 warning generated.

comment:8 Changed 6 months ago by maxs

is your wrapper set to use '/usr/bin/clang' or '/usr/local/bin/gcc-4.2' ?

comment:9 Changed 6 months ago by kazu-yamamoto

clang. For more information, please read: http://d.hatena.ne.jp/kazu-yamamoto/20131028/1382921924

The name of "gcc" is really important. If the name of your wrapper is not "gcc", you get some troubles.

comment:10 Changed 6 months ago by maxs

I tried replacing gcc with the wrapper, but it does not change the outcome.

I am using Mountain Lion, not Mavericks, though that shouldn't matter.

lukexi was having the same problem, I have messaged him to ask if this fixes the problem for him.

Thanks!

comment:11 follow-up: Changed 6 months ago by carter

did you try having a wrapper like the following be "gcc" in your path?

carter Desktop/repoScratcher » cat ~/bin/gcc 
#!/bin/sh
gcc-4.8 $@% 

thats how i've solved most of my problems, by making sure the "gcc" in my path is actually gcc.

just doing the clang wrapper *wont* resolve that, unless you've got it masquerading as "gcc" too.

comment:12 in reply to: ↑ 11 Changed 6 months ago by maxs

Replying to carter:

thats how i've solved most of my problems, by making sure the "gcc" in my path is actually gcc.

Yeah I could install gcc, but we should be able to build it without gcc (EDIT I'm not sure if this ever worked).

Last edited 6 months ago by maxs (previous) (diff)

comment:13 Changed 6 months ago by carter

have you tried putting the "clang wrapper" in your path as "gcc" ?

comment:14 Changed 6 months ago by maxs

Yeah it currently is.

maxs$ gcc -v
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
clang: warning: argument unused during compilation: '-Wno-invalid-pp-token'
clang: warning: argument unused during compilation: '-Wno-unicode'
clang: warning: argument unused during compilation: '-Wno-trigraphs'

comment:15 Changed 5 months ago by George

Not sure if this helps, but with Xcode 5, Mavericks, the latest Haskell platform after running Mark Lentczner script (emailed Oct. 31 to haskell-platform@…,haskell-cafe@…, and ghc-devs@…) I am able to compile happy 1.19.1:

cabal install happy
Resolving dependencies...
Downloading happy-1.19.1...
[1 of 1] Compiling Main ( /var/folders/9b/rh4y2gy92hgdb6ktv4df1jv00000gn/T/happy-1.19.1-26867/happy-1.19.1/Setup.lhs, /var/folders/9b/rh4y2gy92hgdb6ktv4df1jv00000gn/T/happy-1.19.1-26867/happy-1.19.1/dist/setup/Main.o )
Linking /var/folders/9b/rh4y2gy92hgdb6ktv4df1jv00000gn/T/happy-1.19.1-26867/happy-1.19.1/dist/setup/setup ...
Configuring happy-1.19.1...
Building happy-1.19.1...
Preprocessing executable 'happy' for happy-1.19.1...
...
Linking dist/build/happy/happy ...
Warning: No documentation was generated as this package does not contain a
library. Perhaps you want to use the --executables, --tests or --benchmarks
flags.
Installing executable(s) in
/Users/gcolpitts/Library/Haskell/ghc-7.6.3/lib/happy-1.19.1/bin
Warning: The directory
/Users/gcolpitts/Library/Haskell/ghc-7.6.3/lib/happy-1.19.1/bin is not in the
system search path.
Installed happy-1.19.1
Updating documentation index /Users/gcolpitts/Library/Haskell/doc/index.html
Warning: could not create a symlink in /Users/gcolpitts/Library/Haskell/bin
for happy because the file exists there already but is not managed by cabal.
You can create a symlink for this executable manually if you wish. The
executable file has been installed at
/Users/gcolpitts/Library/Haskell/ghc-7.6.3/lib/happy-1.19.1/bin/happy
bash-3.2$ gcc -v
Configured with: --prefix=/Applications/Xcode?.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode?.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
bash-3.2$ ghc -v
Glasgow Haskell Compiler, Version 7.6.3, stage 2 booted by GHC version 7.4.2
Using binary package database: /Library/Frameworks?/GHC.framework/Versions/7.6.3-x86_64/usr/lib/ghc-7.6.3/package.conf.d/package.cache
Using binary package database: /Users/gcolpitts/.ghc/x86_64-darwin-7.6.3/package.conf.d/package.cache
hiding package vector-0.10.0.1 to avoid conflict with later version vector-0.10.9.1
hiding package unordered-containers-0.2.3.0 to avoid conflict with later version unordered-containers-0.2.3.3
hiding package hashable-1.1.2.5 to avoid conflict with later version hashable-1.2.1.0
hiding package binary-0.5.1.1 to avoid conflict with later version binary-0.6.4.0
hiding package Cabal-1.16.0 to avoid conflict with later version Cabal-1.18.1.2
hiding package containers-0.5.0.0 to avoid conflict with later version containers-0.5.3.1
hiding package bytestring-0.10.0.2 to avoid conflict with later version bytestring-0.10.4.0
hiding package Cabal-1.18.1.1 to avoid conflict with later version Cabal-1.18.1.2
hiding package blaze-builder-0.3.1.1 to avoid conflict with later version blaze-builder-0.3.2.0
wired-in package ghc-prim mapped to ghc-prim-0.3.0.0-d5221a8c8a269b66ab9a07bdc23317dd
wired-in package integer-gmp mapped to integer-gmp-0.5.0.0-2f15426f5b53fe4c6490832f9b20d8d7
wired-in package base mapped to base-4.6.0.1-6c351d70a24d3e96f315cba68f3acf57
wired-in package rts mapped to builtin_rts
wired-in package template-haskell mapped to template-haskell-2.8.0.0-c2c1b21dbbb37ace4b7dc26c966ec664
wired-in package dph-seq not found.
wired-in package dph-par not found.
Hsc static flags: -static
* Deleting temp files:
Deleting:
* Deleting temp dirs:
Deleting:
ghc: no input files
Usage: For basic information, try the `--help' option.

comment:16 Changed 5 months ago by carter

  • Resolution set to fixed
  • Status changed from new to closed

I think this issue *should be resolved now*

make sure you're using the newest version of HAPPY and ALEX on hackage

please open a new ticket with more information if you're still having problems

Note: See TracTickets for help on using tickets.