Bug 21944 – importC: Support parsing # line marker directive extensions

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-05-21T09:19:46Z
Last change time
2021-06-06T20:55:59Z
Keywords
ImportC, pull, rejects-valid
Assigned to
No Owner
Creator
Iain Buclaw

Comments

Comment #0 by ibuclaw — 2021-05-21T09:19:46Z
The gcc preprocessor (gcc -E) spits out code like this: --- # 1 "test.c" # 1 "<built-in>" # 1 "<command-line>" # 31 "<command-line>" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 32 "<command-line>" 2 # 1 "test.c" --- The CParser seems to successfully ignore these directives, though it does so using the `panic()` function. However if a line marker appears in the middle of a declaration, e.g: --- struct Foo { int var; #1 "foo.c" 3 4 }; --- An error occurs.
Comment #1 by dlang-bot — 2021-05-25T21:08:59Z
@ibuclaw created dlang/dmd pull request #12585 "fix Issue 21944 - importC: Add `-P` to C preprocessor invocation example" fixing this issue: - fix Issue 21944 - importC: Add `-P` to C preprocessor invocation example The recommendation for using a preprocessor does not generate compilable code due to the `#line` directive not being supported by importC. https://github.com/dlang/dmd/pull/12585
Comment #2 by ibuclaw — 2021-05-25T21:10:14Z
Patch sent that recommends users to use `-P` to turn off the generation of linemarkers in the output from the preprocessor. This saves us having to support the extension.
Comment #3 by ibuclaw — 2021-05-26T12:46:00Z
Comment #4 by bugzilla — 2021-06-05T23:39:20Z
Not implementing this would be a nuisance, and there'd be no way to get the line numbers correct for debugging.
Comment #5 by bugzilla — 2021-06-05T23:40:06Z
The Digital Mars preprocessor, as well as the Warp preprocessor, emit linemarker directives.
Comment #6 by dlang-bot — 2021-06-05T23:44:15Z
@WalterBright created dlang/dmd pull request #12637 "fix Issue 21944 - ImportC: Support parsing # line marker directive ex…" fixing this issue: - fix Issue 21944 - importC: Support parsing # line marker directive extensions https://github.com/dlang/dmd/pull/12637
Comment #7 by dlang-bot — 2021-06-06T20:55:59Z
dlang/dmd pull request #12637 "fix Issue 21944 - ImportC: Support parsing # line marker directive ex…" was merged into master: - 4423156fdd66cdd5bbc4233bd85add1b8ea68d78 by Walter Bright: fix Issue 21944 - importC: Support parsing # line marker directive extensions https://github.com/dlang/dmd/pull/12637