-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect line directives after #include
line
#604
Comments
This patch fixes this particular case: diff --git a/src/aro/Preprocessor.zig b/src/aro/Preprocessor.zig
index a70c739..e850c62 100644
--- a/src/aro/Preprocessor.zig
+++ b/src/aro/Preprocessor.zig
@@ -2966,7 +2966,7 @@ fn include(pp: *Preprocessor, tokenizer: *Tokenizer, which: Compilation.WhichInc
if (next.id != .nl) break;
tokenizer.* = tmp;
}
- try pp.addIncludeResume(next.source, next.end, next.line);
+ try pp.addIncludeResume(next.source, next.end, first.line);
}
/// tokens that are part of a pragma directive can happen in 3 ways: but it's pretty clearly a hack. @ehaas could you provide some insight on what the intention of arocc/src/aro/Preprocessor.zig Lines 2962 to 2969 in e382265
|
Another manifestation of this problem without
$ arocc -E -fuse-line-directives test.c
#line 1 "test.c"
#line 1 "<builtin>"
#line 294 "<builtin>"
#line 1 "<command line>"
#line 1 "test.c"
this is line 1
#line 11 "test.c"
this is line 10 (the |
I'm not totally sure what |
I believe it's skipping past newlines after an include, so e.g. #include "foo.h"
foo would end up as #line 1 "foo.h"
#line 4 "root.c"
foo instead of #line 1 "foo.h"
#line 2 "root.c"
foo In looking into this more, though, I'm confused about whether or not this is actually true: arocc/src/aro/Preprocessor.zig Lines 3133 to 3134 in e382265
In printing out the tokens, the line numbers all seem to actually be 1-indexed. The only 0-based tokens I see are the inserted |
Line numbers are 1-indexed, not 0-indexed. Before this commit, include_start/include_resume tokens were being added with a mix of 1-indexed and 0-indexed line numbers. After this commit, all line numbers are 1-indexed. Closes Vexu#604
Line numbers are 1-indexed, not 0-indexed. Before this commit, include_start/include_resume tokens were being added with a mix of 1-indexed and 0-indexed line numbers. After this commit, all line numbers are 1-indexed. Closes #604
Minimal test case, unsure exactly what else this affects (if anything):
test.rc
:a.h
is an empty fileproduces
There is no line 3 of
test.rc
, so that last line directive should be for line 2. Note that adding more#include
lines does not seem to compound the effect (it's still off-by-one).Clang output for comparison (
clang -E -fuse-line-directives -xc test.rc
):The text was updated successfully, but these errors were encountered: