Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc] fix build errors #95600

Merged
merged 2 commits into from
Jun 14, 2024
Merged

[libc] fix build errors #95600

merged 2 commits into from
Jun 14, 2024

Conversation

SchrodingerZhu
Copy link
Contributor

@SchrodingerZhu SchrodingerZhu commented Jun 14, 2024

Bitfield conversion problem tested at: https://godbolt.org/z/dxjhs5Ghr

@SchrodingerZhu SchrodingerZhu self-assigned this Jun 14, 2024
@llvmbot llvmbot added the libc label Jun 14, 2024
@SchrodingerZhu SchrodingerZhu marked this pull request as draft June 14, 2024 21:04
@llvmbot
Copy link
Collaborator

llvmbot commented Jun 14, 2024

@llvm/pr-subscribers-libc

Author: Schrodinger ZHU Yifan (SchrodingerZhu)

Changes

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

2 Files Affected:

  • (modified) libc/src/__support/macros/attributes.h (+1-1)
  • (modified) libc/src/__support/threads/linux/rwlock.h (+3-2)
diff --git a/libc/src/__support/macros/attributes.h b/libc/src/__support/macros/attributes.h
index 7e8e2ddfac9b1..c6474673de85a 100644
--- a/libc/src/__support/macros/attributes.h
+++ b/libc/src/__support/macros/attributes.h
@@ -42,7 +42,7 @@
 #define LIBC_CONSTINIT
 #endif
 
-#ifdef __clang__
+#if defined(__clang__) && __has_attribute(preferred_type)
 #define LIBC_PREFERED_TYPE(TYPE) [[clang::preferred_type(TYPE)]]
 #else
 #define LIBC_PREFERED_TYPE(TYPE)
diff --git a/libc/src/__support/threads/linux/rwlock.h b/libc/src/__support/threads/linux/rwlock.h
index 5db0590fd6aa0..1778995cf3766 100644
--- a/libc/src/__support/threads/linux/rwlock.h
+++ b/libc/src/__support/threads/linux/rwlock.h
@@ -370,8 +370,9 @@ class RwLock {
 public:
   LIBC_INLINE constexpr RwLock(Role preference = Role::Reader,
                                bool is_pshared = false)
-      : is_pshared(is_pshared), preference(static_cast<unsigned>(preference)),
-        state(0), writer_tid(0), queue() {}
+      : is_pshared(is_pshared),
+        preference(static_cast<unsigned>(preference) & 1u), state(0),
+        writer_tid(0), queue() {}
 
   [[nodiscard]]
   LIBC_INLINE LockResult try_read_lock() {

@SchrodingerZhu SchrodingerZhu changed the title Libc/gcc bug [libc] workaround gcc bitfield assignment warning Jun 14, 2024
@SchrodingerZhu SchrodingerZhu marked this pull request as ready for review June 14, 2024 21:05
@SchrodingerZhu SchrodingerZhu marked this pull request as draft June 14, 2024 21:09
@SchrodingerZhu SchrodingerZhu changed the title [libc] workaround gcc bitfield assignment warning [libc] fix build errors Jun 14, 2024
@SchrodingerZhu SchrodingerZhu marked this pull request as ready for review June 14, 2024 21:13
@SchrodingerZhu
Copy link
Contributor Author

Should be good now. Sorry for the noise.

@SchrodingerZhu
Copy link
Contributor Author

I am now merging this without waiting for ARM/RISCV build, since RwLock are not enabled on ARM(32) and RISC-V anyway.

@SchrodingerZhu SchrodingerZhu merged commit f00f11b into llvm:main Jun 14, 2024
6 of 7 checks passed
@SchrodingerZhu SchrodingerZhu deleted the libc/gcc-bug branch June 14, 2024 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants