[libc-commits] [libc] [libc] add `LLVM_LIBC_CAST` macro. (PR #127319)

via libc-commits libc-commits at lists.llvm.org
Sat Feb 15 04:59:54 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: None (c8ef)

<details>
<summary>Changes</summary>

related: #<!-- -->127238

This patch adds a macro called `LLVM_LIBC_CAST`, similar to `__BIONIC_CAST`, for type conversion in `endian.h`.

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


1 Files Affected:

- (modified) libc/include/__llvm-libc-common.h (+6) 


``````````diff
diff --git a/libc/include/__llvm-libc-common.h b/libc/include/__llvm-libc-common.h
index a0fa506c01ab8..83682e0a440d8 100644
--- a/libc/include/__llvm-libc-common.h
+++ b/libc/include/__llvm-libc-common.h
@@ -47,6 +47,9 @@
 #define __NOEXCEPT throw()
 #endif
 
+#undef LLVM_LIBC_CAST
+#define LLVM_LIBC_CAST(cast, type, value) (cast<type>(value))
+
 #else // not __cplusplus
 
 #undef __BEGIN_C_DECLS
@@ -85,6 +88,9 @@
 #undef _Returns_twice
 #define _Returns_twice __attribute__((returns_twice))
 
+#undef LLVM_LIBC_CAST
+#define LLVM_LIBC_CAST(cast, type, value) ((type)(value))
+
 #endif // __cplusplus
 
 #endif // LLVM_LIBC_COMMON_H

``````````

</details>


https://github.com/llvm/llvm-project/pull/127319


More information about the libc-commits mailing list