https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93306
Bug ID: 93306 Summary: Unnecessary file I/O done for #if 0 && __has_include(...) Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: minor Priority: P3 Component: preprocessor Assignee: nathan at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- Given: #if 0 && __has_include("foo.h") #endif strace shows a lot of redundant I/O: stat("foo.h.gch", 0x7ffdc491f760) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "foo.h", O_RDONLY|O_NOCTTY) = -1 ENOENT (No such file or directory) lstat("/home", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/home/jwakely", {st_mode=S_IFDIR|0700, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib/gcc", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.0.1", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/include", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/include/c++", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/include/c++/10.0.1", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/include/c++/10.0.1/foo.h", 0x7ffdc491e620) = -1 ENOENT (No such file or directory) stat("/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.0.1/../../../../include/c++/10.0.1/foo.h.gch", 0x7ffdc491f760) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.0.1/../../../../include/c++/10.0.1/foo.h", O_RDONLY|O_NOCTTY) = -1 ENOENT (No such file or directory) lstat("/home", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/home/jwakely", {st_mode=S_IFDIR|0700, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib/gcc", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.0.1", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/include", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/include/c++", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/include/c++/10.0.1", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/include/c++/10.0.1/x86_64-pc-linux-gnu", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/include/c++/10.0.1/x86_64-pc-linux-gnu/foo.h", 0x7ffdc491e620) = -1 ENOENT (No such file or directory) stat("/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.0.1/../../../../include/c++/10.0.1/x86_64-pc-linux-gnu/foo.h.gch", 0x7ffdc491f760) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.0.1/../../../../include/c++/10.0.1/x86_64-pc-linux-gnu/foo.h", O_RDONLY|O_NOCTTY) = -1 ENOENT (No such file or directory) lstat("/home", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/home/jwakely", {st_mode=S_IFDIR|0700, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib/gcc", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.0.1", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/include", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/include/c++", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/include/c++/10.0.1", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/include/c++/10.0.1/backward", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/include/c++/10.0.1/backward/foo.h", 0x7ffdc491e620) = -1 ENOENT (No such file or directory) stat("/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.0.1/../../../../include/c++/10.0.1/backward/foo.h.gch", 0x7ffdc491f760) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.0.1/../../../../include/c++/10.0.1/backward/foo.h", O_RDONLY|O_NOCTTY) = -1 ENOENT (No such file or directory) lstat("/home", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/home/jwakely", {st_mode=S_IFDIR|0700, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib/gcc", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.0.1", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.0.1/include", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.0.1/include/foo.h", 0x7ffdc491e620) = -1 ENOENT (No such file or directory) stat("/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.0.1/include/foo.h.gch", 0x7ffdc491f760) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.0.1/include/foo.h", O_RDONLY|O_NOCTTY) = -1 ENOENT (No such file or directory) lstat("/usr", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/usr/local", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/usr/local/include", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/usr/local/include/foo.h", 0x7ffdc491e620) = -1 ENOENT (No such file or directory) stat("/usr/local/include/foo.h.gch", 0x7ffdc491f760) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/local/include/foo.h", O_RDONLY|O_NOCTTY) = -1 ENOENT (No such file or directory) lstat("/home", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/home/jwakely", {st_mode=S_IFDIR|0700, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/include", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/include/foo.h", 0x7ffdc491e620) = -1 ENOENT (No such file or directory) stat("/home/jwakely/gcc/10/include/foo.h.gch", 0x7ffdc491f760) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/home/jwakely/gcc/10/include/foo.h", O_RDONLY|O_NOCTTY) = -1 ENOENT (No such file or directory) lstat("/home", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/home/jwakely", {st_mode=S_IFDIR|0700, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib/gcc", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.0.1", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.0.1/include-fixed", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0 lstat("/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.0.1/include-fixed/foo.h", 0x7ffdc491e620) = -1 ENOENT (No such file or directory) stat("/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.0.1/include-fixed/foo.h.gch", 0x7ffdc491f760) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/home/jwakely/gcc/10/lib/gcc/x86_64-pc-linux-gnu/10.0.1/include-fixed/foo.h", O_RDONLY|O_NOCTTY) = -1 ENOENT (No such file or directory) lstat("/usr", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/usr/include", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/usr/include/foo.h", 0x7ffdc491e620) = -1 ENOENT (No such file or directory) stat("/usr/include/foo.h.gch", 0x7ffdc491f760) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/include/foo.h", O_RDONLY|O_NOCTTY) = -1 ENOENT (No such file or directory) This affects uses like: #if __cplusplus >= 201703L && __has_include(<optional>) On IRC Nathan said "I see what's happening the __has_include evaluator is ignoring the skip_eval counter"