p4lang / p4c

P4_16 reference compiler
https://p4.org/
Apache License 2.0
683 stars 446 forks source link

p4c "-DT=1 + 1" is broken #3772

Open apinski-cavium opened 1 year ago

apinski-cavium commented 1 year ago
apinski@xeond:~/src/p4/octeontxkpu$ ../p4c/build/p4c t6.p4 -D"T=1 + 1"   -v
running cc -E -DT=1 + 1 -C -undef -nostdinc -x assembler-with-cpp -I /bajas/pinskia/src/p4/p4c/build/p4include -o './t6.p4i' 't6.p4'
cc: error: +: No such file or directory
cc: error: 1: No such file or directory

Looks like quoting is missed ...

davidbolvansky commented 1 year ago

https://github.com/p4lang/p4c/blob/main/tools/driver/p4c_src/driver.py#L120

mihaibudiu commented 1 year ago

This is a Python bug. Anyone wants to tackle it?

apinski-cavium commented 1 year ago

No this is not a bug in the python code but rather it is a bug in common/parser_options.cpp dealing with spaces. The way cpp/cc is invoked is using popen and you just pass the string directly without re-encoding the spaces and such. The same will happen if you have an include directory with a space in it. Or with use -MF with a file with a space. Most likely you should use posix_spawnp (https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_spawn.html) instead of popen. And have an array of arguments instead of popen doing the tokenizing.