GithubHelp home page GithubHelp logo

Comments (4)

squeek502 avatar squeek502 commented on July 20, 2024 1

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

// line_no is 0 indexed
try w.print(" {d} \"", .{line_no + 1});

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 include_start tokens. So, I think that's the bug here--the line number is not actually 0-indexed, and the start tokens are incorrectly being added with 0-indexed line numbers instead of 1-indexed like all the rest of the tokens.

from arocc.

squeek502 avatar squeek502 commented on July 20, 2024

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 next in this code is?

arocc/src/aro/Preprocessor.zig

Lines 2962 to 2969 in e382265

var next = first;
while (true) {
var tmp = tokenizer.*;
next = tmp.nextNoWS();
if (next.id != .nl) break;
tokenizer.* = tmp;
}
try pp.addIncludeResume(next.source, next.end, next.line);

from arocc.

squeek502 avatar squeek502 commented on July 20, 2024

Another manifestation of this problem without #include:

test.c:

this is line 1








this is line 10
$ 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 #line 11 "test.c" should be #line 10 "test.c")

from arocc.

ehaas avatar ehaas commented on July 20, 2024

I'm not totally sure what next is doing there - seems like all the tests still pass if that is removed (and just use first for everything in the addIncludeResume call), and it fixes the .rc test you provided.

from arocc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.