cparser does not understand _Pragma
ibara opened this issue · 3 comments
Hi --
I am an OpenBSD developer, making a package of libfirm and cparser for our package repository. I noticed during testing cparser that it doesn't understand the C99 _Pragma preprocessor operator. This is important, because in OpenBSD sys/cdefs.h
, the _Pragma operator is used if the compiler identifies itself as gcc-4.0.0 or newer, which cparser does.
Here is a simple test case to demonstrate the behavior:
_Pragma("GCC warning \"hello\"") int main(void){ return 7; }
Here is the output for some other compilers:
The default OpenBSD compiler: clang-5.0.0:
pragma.c:1:1: warning: hello [-W#pragma-messages]
_Pragma("GCC warning \"hello\"") int main(void){ return 7; }
^
<scratch space>:2:6: note: expanded from here
GCC warning "hello"
^
1 warning generated.
gcc-4.9.4:
pragma.c:1:13: warning: hello
_Pragma("GCC warning \"hello\"") int main(void){ return 7; }
^
pcc-1.2.0DEVEL-20171102:
pragma.c, line 2: warning: gcc pragma unsupported
All three compilers go on to successfully compile the program correctly.
This is the output from cparser:
pragma.c:1:1: warning: type specifier missing; assuming 'int' [-Wimplicit-int]
pragma.c:1:9: error: expected ')', got string literal "GCC warning "hello""
pragma.c:1:34: error: expected '{' while parsing function definition, got 'int'
2 error(s), 1 warning(s)
And it does not go on to finish compiling.
As a result, I have had to change cparser's identification from gcc-4.6.0 to gcc-3.4.6 but this is not the best thing to do, as other software that looks for gcc compatibility that cparser does have will be forced to ignore it. I will say that with this change of identification, cparser is able to build the vast majority of OpenBSD software on both i386 and amd64 (I am using a checkout from after 1.22.0 that has the amd64 PIC code so that libfirm+cparser works on OpenBSD/amd64).
I am perfectly OK if cparser chooses to go the pcc route and just ignore the _Pragma. However, unlike #pragma, you cannot simply skip to the end of the line; you must ignore just that token.
this issue was addressed in #16 . OP @nilput and @MatzeB both spent a lot of effort to get the PR into the right shape, but then after a while OP suddenly closed the PR. imo we should remove the unnecessary addition here #16 (comment) and reopen the PR (or file a new one with OPs commits squashed into one and the nitpick issue removed), to get this finally in.
Thank you! _Pragma support is now merged.