[clang] [clang][Lex] Do not look up files for __has_include in unevaluated operands (PR #247849)
Chen Miao via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 2 07:49:11 PST 2026
================
@@ -0,0 +1,62 @@
+// Check that __has_include, __has_include_next and __has_embed do not look up
+// the file in an operand whose value is not used, like GCC, so the file does
+// not end up in the dependency output.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: %clang -std=c23 -fsyntax-only -MD -MF %t/deps -MT out \
+// RUN: -I %t/inc -I %t/next --embed-dir=%t/embed %t/main.c
+// RUN: FileCheck --input-file=%t/deps --implicit-check-not=skipped %s
+
+// CHECK: out:
+// CHECK: main.c
+// CHECK: inc{{[/\\]}}live-or.h
+// CHECK: inc{{[/\\]}}live-cond.h
+// CHECK: embed{{[/\\]}}live-embed.bin
+// CHECK: inc{{[/\\]}}next.h
+// CHECK: next{{[/\\]}}live-next.h
+
+//--- main.c
+#if 0 && __has_include("skipped-and.h")
+#endif
+#if 1 || __has_include("skipped-or.h")
+#endif
+#if 0 ? __has_include("skipped-true.h") : 0
+#endif
+#if 1 ? 0 : __has_include("skipped-false.h")
+#endif
+#if 0 && (1 + !__has_include("skipped-nested.h"))
+#endif
+#if 0 && __has_embed(<skipped-embed.bin>)
+#endif
+
+#if !(0 && 1 || __has_include("live-or.h"))
+#error live-or.h not found
+#endif
----------------
ChenMiaoi wrote:
``` cc
#define OR(x) 1 || (x)
#if !(0 && OR(__has_include("live-or.h")))
#error live-or.h not found
#endif
```
Could you test this? Looks like will enter error?
https://github.com/llvm/llvm-project/pull/247849
More information about the cfe-commits
mailing list