llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: gallopruss-sie

<details>
<summary>Changes</summary>

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 &lt;intrin.h&gt;
      |               ^~~~~~~~~~

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/234114.diff


2 Files Affected:

- (modified) clang/lib/Headers/intrin.h (+3-1) 
- (added) clang/test/Headers/intrin-non-windows.cpp (+14) 


``````````diff
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
+
+// [email protected]:* {{<intrin.h> is a Windows-only header and is not 
available on this platform}}
+#include <intrin.h>

``````````

</details>


https://github.com/llvm/llvm-project/pull/234114
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to