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,865
    • Issues 4,865
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 459
    • Merge requests 459
  • 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
  • #16737
Closed
Open
Created Jun 03, 2019 by Zejun Wu@watashiReporter

cpp is not run when building .c or .cpp files

Summary

C pre-processor is not run and -D or -optP flags are not respected when building .c or .cpp files.

Steps to reproduce

$ cat test.c
#ifndef TEST
#define TEST 0
#endif
#include <stdio.h>
int main(void) {
  printf("%d\n", TEST);
  return 0;
}
$ ghc -DTEST=9 test.c -no-hs-main && ./a.out
0

or

$ mkdir -p x && touch x/x.h 
$ echo '#include "x.h"' > y.c
$ ghc -Ix -c y.c
$ ghc -optP=-Ix -c y.c

y.c:1:10: error:
     fatal error: x.h: No such file or directory
     #include "x.h"
              ^~~~~
  |
1 | #include "x.h"
  |          ^
compilation terminated.
`gcc' failed in phase `C Compiler'. (Exit code: 1)

Expected behavior

Output 9 for the first example. Both ghc -Ix -c y.c and ghc -optP=-Ix -c y.c work in the second example.

This is because we don't run cpp for Cc, Ccxx, Cobjc and Cobjcxx phase and we probably should do so. For HCc phase, we usually run cpp in previous phase and probably don't want to run it again.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking