Skip to content

Fix -include header when known modules are used#298

Open
davispuh wants to merge 1 commit into
jacob-carlborg:masterfrom
davispuh:include
Open

Fix -include header when known modules are used#298
davispuh wants to merge 1 commit into
jacob-carlborg:masterfrom
davispuh:include

Conversation

@davispuh

Copy link
Copy Markdown

Currently if you have
a.h with:

#include <errno.h>

And empty b.h.
Then -include fails:

$ dstep -includeb.h a.h
dstep: an unknown error occurred: core.exception.RangeError@dstep/translator/HeaderIndex.d(100): Range violation
----------------
??:? onRangeError [0x55ba460de15a]
??:? _d_arraybounds [0x55ba460c4d15]
dstep/translator/HeaderIndex.d:100 bool dstep.translator.HeaderIndex.IncludeGraph.isReachableBy(immutable(char)[], immutable(char)[]) [0x55ba4606bf29]
dstep/translator/HeaderIndex.d:382 immutable(char)[][immutable(char)[]] dstep.translator.HeaderIndex.HeaderIndex.resolveKnownModules!(std.algorithm.iteration.FilterResult!(dstep.translator.HeaderIndex.HeaderIndex.__ctor(clang.TranslationUnit.TranslationUnit, const(immutable(char)[][immutable(char)[]])).__lambda_L308_C9, clang.Cursor.Cursor[]).FilterResult).resolveKnownModules(std.algorithm.iteration.FilterResult!(dstep.translator.HeaderIndex.HeaderIndex.__ctor(clang.TranslationUnit.TranslationUnit, const(immutable(char)[][immutable(char)[]])).__lambda_L308_C9, clang.Cursor.Cursor[]).FilterResult, dstep.translator.HeaderIndex.HeaderIndex.KnownModule[]) [0x55ba4606f0b7]
dstep/translator/HeaderIndex.d:323 dstep.translator.HeaderIndex.HeaderIndex dstep.translator.HeaderIndex.HeaderIndex.__ctor!(std.algorithm.iteration.FilterResult!(dstep.translator.HeaderIndex.HeaderIndex.__ctor(clang.TranslationUnit.TranslationUnit, const(immutable(char)[][immutable(char)[]])).__lambda_L308_C9, clang.Cursor.Cursor[]).FilterResult).__ctor(std.algorithm.iteration.FilterResult!(dstep.translator.HeaderIndex.HeaderIndex.__ctor(clang.TranslationUnit.TranslationUnit, const(immutable(char)[][immutable(char)[]])).__lambda_L308_C9, clang.Cursor.Cursor[]).FilterResult, const(immutable(char)[][immutable(char)[]])) [0x55ba4606ee48]
dstep/translator/HeaderIndex.d:316 dstep.translator.HeaderIndex.HeaderIndex dstep.translator.HeaderIndex.HeaderIndex.__ctor(clang.TranslationUnit.TranslationUnit, const(immutable(char)[][immutable(char)[]])) [0x55ba4606da89]
dstep/translator/HeaderIndex.d:293 dstep.translator.HeaderIndex.HeaderIndex dstep.translator.HeaderIndex.HeaderIndex.__ctor(clang.TranslationUnit.TranslationUnit) [0x55ba4606d95d]
dstep/translator/Context.d:158 dstep.translator.HeaderIndex.HeaderIndex dstep.translator.Context.Context.headerIndex() [0x55ba4606724a]
dstep/translator/Context.d:51 dstep.translator.Context.Context dstep.translator.Context.Context.__ctor(clang.TranslationUnit.TranslationUnit, dstep.translator.Options.Options, dstep.translator.Translator.Translator) [0x55ba46066c67]
dstep/translator/Translator.d:70 dstep.translator.Translator.Translator dstep.translator.Translator.Translator.__ctor(clang.TranslationUnit.TranslationUnit, dstep.translator.Options.Options) [0x55ba460ab587]
dstep/driver/Application.d:65 void dstep.driver.Application.Application.run() [0x55ba46052147]
dstep/driver/CommandLine.d:181 int dstep.driver.CommandLine.run(immutable(char)[][]) [0x55ba46062a61]
dstep/main.d:18 _Dmain [0x55ba46065977]
core.exception.RangeError@dstep/translator/HeaderIndex.d(100): Range violation
----------------
??:? onRangeError [0x55ba460de15a]
??:? _d_arraybounds [0x55ba460c4d15]
dstep/translator/HeaderIndex.d:100 bool dstep.translator.HeaderIndex.IncludeGraph.isReachableBy(immutable(char)[], immutable(char)[]) [0x55ba4606bf29]
dstep/translator/HeaderIndex.d:382 immutable(char)[][immutable(char)[]] dstep.translator.HeaderIndex.HeaderIndex.resolveKnownModules!(std.algorithm.iteration.FilterResult!(dstep.translator.HeaderIndex.HeaderIndex.__ctor(clang.TranslationUnit.TranslationUnit, const(immutable(char)[][immutable(char)[]])).__lambda_L308_C9, clang.Cursor.Cursor[]).FilterResult).resolveKnownModules(std.algorithm.iteration.FilterResult!(dstep.translator.HeaderIndex.HeaderIndex.__ctor(clang.TranslationUnit.TranslationUnit, const(immutable(char)[][immutable(char)[]])).__lambda_L308_C9, clang.Cursor.Cursor[]).FilterResult, dstep.translator.HeaderIndex.HeaderIndex.KnownModule[]) [0x55ba4606f0b7]
dstep/translator/HeaderIndex.d:323 dstep.translator.HeaderIndex.HeaderIndex dstep.translator.HeaderIndex.HeaderIndex.__ctor!(std.algorithm.iteration.FilterResult!(dstep.translator.HeaderIndex.HeaderIndex.__ctor(clang.TranslationUnit.TranslationUnit, const(immutable(char)[][immutable(char)[]])).__lambda_L308_C9, clang.Cursor.Cursor[]).FilterResult).__ctor(std.algorithm.iteration.FilterResult!(dstep.translator.HeaderIndex.HeaderIndex.__ctor(clang.TranslationUnit.TranslationUnit, const(immutable(char)[][immutable(char)[]])).__lambda_L308_C9, clang.Cursor.Cursor[]).FilterResult, const(immutable(char)[][immutable(char)[]])) [0x55ba4606ee48]
dstep/translator/HeaderIndex.d:316 dstep.translator.HeaderIndex.HeaderIndex dstep.translator.HeaderIndex.HeaderIndex.__ctor(clang.TranslationUnit.TranslationUnit, const(immutable(char)[][immutable(char)[]])) [0x55ba4606da89]
dstep/translator/HeaderIndex.d:293 dstep.translator.HeaderIndex.HeaderIndex dstep.translator.HeaderIndex.HeaderIndex.__ctor(clang.TranslationUnit.TranslationUnit) [0x55ba4606d95d]
dstep/translator/Context.d:158 dstep.translator.HeaderIndex.HeaderIndex dstep.translator.Context.Context.headerIndex() [0x55ba4606724a]
dstep/translator/Context.d:51 dstep.translator.Context.Context dstep.translator.Context.Context.__ctor(clang.TranslationUnit.TranslationUnit, dstep.translator.Options.Options, dstep.translator.Translator.Translator) [0x55ba46066c67]
dstep/translator/Translator.d:70 dstep.translator.Translator.Translator dstep.translator.Translator.Translator.__ctor(clang.TranslationUnit.TranslationUnit, dstep.translator.Options.Options) [0x55ba460ab587]
dstep/driver/Application.d:65 void dstep.driver.Application.Application.run() [0x55ba46052147]
dstep/driver/CommandLine.d:181 int dstep.driver.CommandLine.run(immutable(char)[][]) [0x55ba46062a61]
dstep/main.d:18 _Dmain [0x55ba46065977]

This PR fixes it so that it works.

Copilot AI review requested due to automatic review settings March 18, 2026 22:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a crash in dstep when compiling with -include and using known-module resolution, by ensuring headers introduced via directives with an empty including-file path are still indexed in the include graph.

Changes:

  • Extend IncludeGraph construction to register includedPath even when directive.file.absolutePath is empty (e.g., -include-injected headers).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread dstep/translator/HeaderIndex.d

@jacob-carlborg jacob-carlborg left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test case as suggested.

Currently if you have a.h with:
```
 #include <errno.h>
```

And empty `b.h` then `-include` fails:
```
$ dstep -includeb.h a.h
dstep: an unknown error occurred: core.exception.RangeError@dstep/translator/HeaderIndex.d(100): Range violation
```

This commit fixes this issue.
@davispuh

Copy link
Copy Markdown
Author

Added test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants