jyn514 / saltwater

A C compiler written in Rust, with a focus on good error messages.
BSD 3-Clause "New" or "Revised" License
294 stars 27 forks source link

## is not implemented #506

Open jyn514 opened 4 years ago

jyn514 commented 4 years ago

Expected behavior

cargo run tests/runner-tests/hello_world.c works on linux platforms.

Code

#include<stdio.h>

int main() {
    puts("Hello, world!");
}
bits/libc-header-start.h:56:4 error: invalid macro: trailing tokens in `#if` expression
#if __GLIBC_USE (IEC_60559_BFP_EXT) || __GLIBC_USE (ISOC2X)
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
jyn514 commented 4 years ago

This was broken in b7a16c258d0db41ee67e7a7b8daf9295ca44e7cf, cc @hdamron17

jyn514 commented 4 years ago
$ rg '#define __GLIBC_USE' /usr/include/
/usr/include/features.h
179:#define __GLIBC_USE(F)  __GLIBC_USE_ ## F
jyn514 commented 4 years ago

Minimal reproduction:

#define __GLIBC_USE(F)  __GLIBC_USE_ ## F
# define __GLIBC_USE_IEC_60559_TYPES_EXT 1 
# define __GLIBC_USE_ISOC2X 1
#if __GLIBC_USE (IEC_60559_BFP_EXT) || __GLIBC_USE (ISOC2X)
    int main() {}
#endif
<stdin>:4:4 error: invalid macro: trailing tokens in `#if` expression
#if __GLIBC_USE (IEC_60559_BFP_EXT) || __GLIBC_USE (ISOC2X)
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
<stdin>:6:2 error: invalid macro: #endif without #if
#endif
 ^^^^^
jyn514 commented 4 years ago

I think this is just that ## isn't implemented and the error is slightly different than before: http://port70.net/~nsz/c/c11/n1570.html#6.10.3.3

hdamron17 commented 4 years ago

It passed the tests..? I'm confused how if it depended on ##

jyn514 commented 4 years ago

Well, hello_world.c is platform dependent. So glibc on my machine is probably different from glibc on travis. I just haven't tried to run the tests since you merged that fix.

hdamron17 commented 4 years ago

Hmm. I thought I ran it on my Ubuntu machine but maybe not. Or it could be different there too.

hdamron17 commented 4 years ago

I don't think ## will be too hard to implement. But maybe that's a problem for after you finish separating out the preprocessor.

jyn514 commented 4 years ago

I don't think ## will be too hard to implement. But maybe that's a problem for after you finish separating out the preprocessor.

Let's not wait for me to separate the preprocessor 😅 we'll be here a while. I don't expect ## to make it any harder to separate than it already is.

hdamron17 commented 4 years ago

This is going to be a lot harder than I originally thought because we're dealing with tokens not plain strings and the token type can change in concatenation. E.g. 5 ## e5 (int, id) -> 5e5 (float).