[Tinycc-devel] bug #50847: #line vs. #include "foo.h"
tinycc community - I found and submitted tinycc bug #50847: #line directive corrupts #include search path https://savannah.nongnu.org/bugs/index.php?50847 Three comments: 1. The submission wraps the test case in a tidy (485 byte) tarball. For lazyweb members who don't want to unpack that, there's really not much to it. The bug is triggered by bad.c: #line 10 "mythical.c" #include "simple.h" int foo(bar *b) { return b->x == b->y; } where simple.h provides a typedef for bar, and the bug shows up when bad.c is in a different directory from where you run the compile. The command line in demo.sh is "tcc -c dir/bad.c". 2. The c99 standard is mute on where C compilers are supposed to find their include files, but the gcc documentation is clear: https://gcc.gnu.org/onlinedocs/gcc-3.0.2/cpp_2.html GCC looks for headers requested with #include "file" first in the directory containing the current file, then in the same places it would have looked for a header requested with angle brackets. For example, if `/usr/include/sys/stat.h' contains #include "types.h", GCC looks for `types.h' first in `/usr/include/sys', then in its usual search path. `#line' (see section 6. Line Control) does not change GCC's idea of the directory containing the current file. This is also the behavior of clang. 3. I put together a brain-dead patch to tinycc mob HEAD, that touches three lines total and seems to do the job. It is arguably somewhat wasteful of scratch memory. Here it is, sorry if the mail pipeline mangles it: diff --git a/libtcc.c b/libtcc.c index 99bf783..302ce39 100644 --- a/libtcc.c +++ b/libtcc.c @@ -581,6 +581,7 @@ ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen) bf->buf_end = bf->buffer + initlen; bf->buf_end[0] = CH_EOB; /* put eob symbol */ pstrcpy(bf->filename, sizeof(bf->filename), filename); +pstrcpy(bf->filename2, sizeof(bf->filename2), filename); #ifdef _WIN32 normalize_slashes(bf->filename); #endif diff --git a/tcc.h b/tcc.h index 5b9d4a3..92b9060 100644 --- a/tcc.h +++ b/tcc.h @@ -546,6 +546,7 @@ typedef struct BufferedFile { int *ifdef_stack_ptr; /* ifdef_stack value at the start of the file */ int include_next_index; /* next search path */ char filename[1024];/* filename */ +char filename2[1024];/* filename not modified by # line directive */ unsigned char unget[4]; unsigned char buffer[1]; /* extra size for CH_EOB char */ } BufferedFile; diff --git a/tccpp.c b/tccpp.c index 7e5cdcf..4495752 100644 --- a/tccpp.c +++ b/tccpp.c @@ -1791,7 +1791,8 @@ ST_FUNC void preprocess(int is_bof) /* search in file's dir if "header.h" */ if (c != '\"') continue; -path = file->filename; +/* https://savannah.nongnu.org/bugs/index.php?50847 */ +path = file->filename2; pstrncpy(buf1, path, tcc_basename(path) - path); } else { ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Re: [Tinycc-devel] configure file permission
Larry Doolittle wrote: Friends - commit 7acf9aa8 from earlier today took away the x (execute) permission bits on configure. Sorry, it was by accident. Don't know why or when but sometimes my git and/or msys or something does that. -- gr ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel
[Tinycc-devel] configure file permission
Friends - commit 7acf9aa8 from earlier today took away the x (execute) permission bits on configure. That means the instructions in README ./configure make make test make install don't work any more. Just FYI, maybe you want to put those bits back, or update the README to say "sh configure". - Larry ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Re: [Tinycc-devel] bug #50847: #line vs. #include "foo.h"
grischka - On Tue, Apr 25, 2017 at 09:20:53PM +0200, grischka wrote: > Larry Doolittle wrote: > >3. I put together a brain-dead patch to tinycc mob HEAD, > >that touches three lines total and seems to do the job. > >It is arguably somewhat wasteful of scratch memory. > Push to mob if you want it in the release. > (After all, if it works, and, what else could we do. I think I had > a quite similar patch somewhere, some (long) time ago.) OK, I seem to have followed the directions at http://repo.or.cz/tinycc.git successfully. I imagine a test case should be added to the source tree, but I haven't looked into that. - Larry ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Re: [Tinycc-devel] bug #50847: #line vs. #include "foo.h"
Larry Doolittle wrote: 3. I put together a brain-dead patch to tinycc mob HEAD, that touches three lines total and seems to do the job. It is arguably somewhat wasteful of scratch memory. Here it is, sorry if the mail pipeline mangles it: Push to mob if you want it in the release. (After all, if it works, and, what else could we do. I think I had a quite similar patch somewhere, some (long) time ago.) -- gr diff --git a/libtcc.c b/libtcc.c index 99bf783..302ce39 100644 --- a/libtcc.c +++ b/libtcc.c @@ -581,6 +581,7 @@ ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen) bf->buf_end = bf->buffer + initlen; bf->buf_end[0] = CH_EOB; /* put eob symbol */ pstrcpy(bf->filename, sizeof(bf->filename), filename); +pstrcpy(bf->filename2, sizeof(bf->filename2), filename); #ifdef _WIN32 normalize_slashes(bf->filename); #endif diff --git a/tcc.h b/tcc.h index 5b9d4a3..92b9060 100644 --- a/tcc.h +++ b/tcc.h @@ -546,6 +546,7 @@ typedef struct BufferedFile { int *ifdef_stack_ptr; /* ifdef_stack value at the start of the file */ int include_next_index; /* next search path */ char filename[1024];/* filename */ +char filename2[1024];/* filename not modified by # line directive */ unsigned char unget[4]; unsigned char buffer[1]; /* extra size for CH_EOB char */ } BufferedFile; diff --git a/tccpp.c b/tccpp.c index 7e5cdcf..4495752 100644 --- a/tccpp.c +++ b/tccpp.c @@ -1791,7 +1791,8 @@ ST_FUNC void preprocess(int is_bof) /* search in file's dir if "header.h" */ if (c != '\"') continue; -path = file->filename; +/* https://savannah.nongnu.org/bugs/index.php?50847 */ +path = file->filename2; pstrncpy(buf1, path, tcc_basename(path) - path); } else { ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel
[Tinycc-devel] bug #50847: #line vs. #include "foo.h"
tinycc community - I found and submitted tinycc bug #50847: #line directive corrupts #include search path https://savannah.nongnu.org/bugs/index.php?50847 Three comments: 1. The submission wraps the test case in a tidy (485 byte) tarball. For lazyweb members who don't want to unpack that, there's really not much to it. The bug is triggered by bad.c: #line 10 "mythical.c" #include "simple.h" int foo(bar *b) { return b->x == b->y; } where simple.h provides a typedef for bar, and the bug shows up when bad.c is in a different directory from where you run the compile. The command line in demo.sh is "tcc -c dir/bad.c". 2. The c99 standard is mute on where C compilers are supposed to find their include files, but the gcc documentation is clear: https://gcc.gnu.org/onlinedocs/gcc-3.0.2/cpp_2.html GCC looks for headers requested with #include "file" first in the directory containing the current file, then in the same places it would have looked for a header requested with angle brackets. For example, if `/usr/include/sys/stat.h' contains #include "types.h", GCC looks for `types.h' first in `/usr/include/sys', then in its usual search path. `#line' (see section 6. Line Control) does not change GCC's idea of the directory containing the current file. This is also the behavior of clang. 3. I put together a brain-dead patch to tinycc mob HEAD, that touches three lines total and seems to do the job. It is arguably somewhat wasteful of scratch memory. Here it is, sorry if the mail pipeline mangles it: diff --git a/libtcc.c b/libtcc.c index 99bf783..302ce39 100644 --- a/libtcc.c +++ b/libtcc.c @@ -581,6 +581,7 @@ ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen) bf->buf_end = bf->buffer + initlen; bf->buf_end[0] = CH_EOB; /* put eob symbol */ pstrcpy(bf->filename, sizeof(bf->filename), filename); +pstrcpy(bf->filename2, sizeof(bf->filename2), filename); #ifdef _WIN32 normalize_slashes(bf->filename); #endif diff --git a/tcc.h b/tcc.h index 5b9d4a3..92b9060 100644 --- a/tcc.h +++ b/tcc.h @@ -546,6 +546,7 @@ typedef struct BufferedFile { int *ifdef_stack_ptr; /* ifdef_stack value at the start of the file */ int include_next_index; /* next search path */ char filename[1024];/* filename */ +char filename2[1024];/* filename not modified by # line directive */ unsigned char unget[4]; unsigned char buffer[1]; /* extra size for CH_EOB char */ } BufferedFile; diff --git a/tccpp.c b/tccpp.c index 7e5cdcf..4495752 100644 --- a/tccpp.c +++ b/tccpp.c @@ -1791,7 +1791,8 @@ ST_FUNC void preprocess(int is_bof) /* search in file's dir if "header.h" */ if (c != '\"') continue; -path = file->filename; +/* https://savannah.nongnu.org/bugs/index.php?50847 */ +path = file->filename2; pstrncpy(buf1, path, tcc_basename(path) - path); } else { ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel
Re: [Tinycc-devel] TinyCC in macOS
Thank you. I followed the directions on the http://repo.or.cz/tinycc.git website. The three patches have been pushed. A On Sat, Apr 15, 2017 at 8:42 PM, Michael Matz wrote: > Hello, > > On Thu, 13 Apr 2017, Andrei E. Warkentin wrote: > > How does the merge process work for tinycc? Anything you want from my end? >> > > I used imprecise language. When I said "merge" I meant "push to mob". See > http://repo.or.cz/tinycc.git, in particular the section "mob" of the > repository readme. (Please rebase your work to current mob before pushing; > I'm not sure if non-fast-forwards are even accepted, but just in case to > not uglify history too much). > > > > Ciao, > Michael. > > ___ > Tinycc-devel mailing list > Tinycc-devel@nongnu.org > https://lists.nongnu.org/mailman/listinfo/tinycc-devel > -- A ___ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel