Bug 88966 - Indirect stringification of "linux" produces "1"
Summary: Indirect stringification of "linux" produces "1"
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: preprocessor (show other bugs)
Version: 5.4.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-01-22 04:27 UTC by Bin Meng
Modified: 2019-01-22 10:05 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 7.3.0, 8.1.0
Last reconfirmed: 2019-01-22 00:00:00


Attachments
test case (157 bytes, text/plain)
2019-01-22 04:27 UTC, Bin Meng
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bin Meng 2019-01-22 04:27:30 UTC
Created attachment 45487 [details]
test case

This issue is seen with GCC 5.4.0 shipped by Ubuntu 16.04, but is also reproducible with GCC 7.3.0 and 8.1.0.

Use attached test case (test.c) to reproduce.

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.10' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.10) 

$ gcc test.c -o test
$ ./test
case 1: 1
case 2: vmlinux
case 3: linux4.20
case 4: weird 1 ?
case 5: linux

It looks the indirect stringification (two levels) has special handling of "linux". Doing just one level (see case 5) works fine.
Comment 1 Dimitar Dimitrov 2019-01-22 05:16:53 UTC
The "linux" is a predefined macro:

$ $ gcc -E -dM - </dev/null|grep -w linux
#define linux 1

Looks like by-design to me.
Comment 2 Bin Meng 2019-01-22 05:25:08 UTC
(In reply to Dimitar Dimitrov from comment #1)
> The "linux" is a predefined macro:
> 
> $ $ gcc -E -dM - </dev/null|grep -w linux
> #define linux 1
> 
> Looks like by-design to me.

Indeed "linux" is a predefined macro. But why does str(linux) and stringify(linux) give different results?
Comment 3 Martin Liška 2019-01-22 08:11:25 UTC
Confirmed, happens will all releases I have (4.8.0+).
Comment 4 Andrew Pinski 2019-01-22 08:41:12 UTC
The same reason why:
#define mymacro 1

str(mymacro)
stringify(mymacro)

Gives different results.
Comment 5 Jonathan Wakely 2019-01-22 10:05:33 UTC
This is not a bug, "linux" is a predefined macro and the preprocessor is doing exactly what it's supposed to. See https://gcc.gnu.org/onlinedocs/cpp/System-specific-Predefined-Macros.html