[clang] [clang] Improve diagnostic if intrin.h used in incompatible environments (PR #234114)

via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 21 01:50:22 PDT 2026


https://github.com/gallopruss-sie created https://github.com/llvm/llvm-project/pull/234114

Attempting to include intrin.h in environments (such as PS5) where it isn't supported results in a confusing file not found error from the include_next

...\intrin.h(12,15): fatal error: 'intrin.h' file not found
   12 | #include_next <intrin.h>
      |               ^~~~~~~~~~

This can occur when porting codebases from Windows.

This change provides an earlier, clearer error in these environments.

Claude Code helped write this, and produced the test.

>From 7c2d6cb791f6de48a25c14ca0f70ebd7b5aab362 Mon Sep 17 00:00:00 2001
From: Russell Gallop <russell.gallop at sony.com>
Date: Wed, 21 Oct 2026 09:28:52 +0100
Subject: [PATCH] [clang] Improve diagnostic if intrin.h used in incompatible
 environments

Attempting to include intrin.h in environments (such as PS5) where it isn't
supported results in a confusing file not found error from the include_next

...\intrin.h(12,15): fatal error: 'intrin.h' file not found
   12 | #include_next <intrin.h>
      |               ^~~~~~~~~~

This can occur when porting codebases from Windows.

This change provides an earlier, clearer error in these environments.
---
 clang/lib/Headers/intrin.h                |  4 +++-
 clang/test/Headers/intrin-non-windows.cpp | 14 ++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Headers/intrin-non-windows.cpp

diff --git a/clang/lib/Headers/intrin.h b/clang/lib/Headers/intrin.h
index 7dcb5a526afb2a..7396e476dd9915 100644
--- a/clang/lib/Headers/intrin.h
+++ b/clang/lib/Headers/intrin.h
@@ -8,7 +8,9 @@
  */
 
 /* Only include this if we're compiling for the windows platform. */
-#ifndef _MSC_VER
+#if !defined(_WIN32)
+#error "<intrin.h> is a Windows-only header and is not available on this platform"
+#elif !defined(_MSC_VER)
 #include_next <intrin.h>
 #else
 
diff --git a/clang/test/Headers/intrin-non-windows.cpp b/clang/test/Headers/intrin-non-windows.cpp
new file mode 100644
index 00000000000000..36bb2bcc704db4
--- /dev/null
+++ b/clang/test/Headers/intrin-non-windows.cpp
@@ -0,0 +1,14 @@
+// Verify that <intrin.h> produces a clear diagnostic on non-Windows targets
+// rather than silently failing via #include_next to a missing system header.
+
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -ffreestanding -fsyntax-only \
+// RUN:     -Wsystem-headers -verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -ffreestanding -fsyntax-only \
+// RUN:     -Wsystem-headers -verify %s
+// RUN: %clang_cc1 -triple aarch64-linux-gnu -ffreestanding -fsyntax-only \
+// RUN:     -Wsystem-headers -verify %s
+// RUN: %clang_cc1 -triple x86_64-sie-ps5 -ffreestanding -fsyntax-only \
+// RUN:     -Wsystem-headers -verify %s
+
+// expected-error at intrin.h:* {{<intrin.h> is a Windows-only header and is not available on this platform}}
+#include <intrin.h>



More information about the cfe-commits mailing list