[PR #393] [MERGED] Fix strict aliasing violations in Address #408

Closed
opened 2026-10-26 09:50:00 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/deepseek-ai/3FS/pull/393
Author: @qieqieplus
Created: 1/24/2026
Status: ✅ Merged
Merged: 1/24/2026
Merged by: @SF-Zhou

Base: main ← Head: main


📝 Commits (1)

  • 8934f9b Fix strict aliasing violations in Address

📊 Changes

1 file changed (+18 additions, -20 deletions)

View changed files

📝 src/common/utils/Address.h (+18 -20)

📄 Description

Replaced reinterpret_cast with std::bit_cast.

The previous implementation used reinterpret_cast to treat the Address struct as a uint64_t or an array of bytes.
Which could effectively work but violate C++ strict aliasing rules.
With C++20, these low-level bitwise reinterpretations could be safely performed via std::bit_cast.

While std::bit_cast is conceptually std::memcpy underhood, but it could be optimzed by compilers in many cases.
The compiler generates identical assembly code for simple cases:
https://godbolt.org/z/d7j5YYKcj


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/deepseek-ai/3FS/pull/393 **Author:** [@qieqieplus](https://github.com/qieqieplus) **Created:** 1/24/2026 **Status:** ✅ Merged **Merged:** 1/24/2026 **Merged by:** [@SF-Zhou](https://github.com/SF-Zhou) **Base:** `main` ← **Head:** `main` --- ### 📝 Commits (1) - [`8934f9b`](https://github.com/deepseek-ai/3FS/commit/8934f9b05655994037060a885f199cbb3cb6274d) Fix strict aliasing violations in Address ### 📊 Changes **1 file changed** (+18 additions, -20 deletions) <details> <summary>View changed files</summary> 📝 `src/common/utils/Address.h` (+18 -20) </details> ### 📄 Description Replaced reinterpret_cast with std::bit_cast. The previous implementation used reinterpret_cast to treat the Address struct as a uint64_t or an array of bytes. Which could effectively work but violate C++ strict aliasing rules. With C++20, these low-level bitwise reinterpretations could be safely performed via std::bit_cast. While std::bit_cast is conceptually std::memcpy underhood, but it could be optimzed by compilers in many cases. The compiler generates identical assembly code for simple cases: https://godbolt.org/z/d7j5YYKcj --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-26 09:50:00 +00:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
deepseek-ai/3FS#408
No description provided.