[clang] [clang] Drop unaligned from calls to readNext (NFC) (PR #88842)

2024-04-16 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata closed 
https://github.com/llvm/llvm-project/pull/88842
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Drop unaligned from calls to readNext (NFC) (PR #88842)

2024-04-15 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 approved this pull request.


https://github.com/llvm/llvm-project/pull/88842
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Drop unaligned from calls to readNext (NFC) (PR #88842)

2024-04-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes

Now readNext defaults to unaligned accesses.  This patch drops
unaligned to improve readability.


---

Patch is 30.09 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/88842.diff


4 Files Affected:

- (modified) clang/lib/APINotes/APINotesReader.cpp (+55-82) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+37-50) 
- (modified) clang/lib/Serialization/GlobalModuleIndex.cpp (+4-8) 
- (modified) clang/lib/Serialization/MultiOnDiskHashTable.h (+2-2) 


``diff
diff --git a/clang/lib/APINotes/APINotesReader.cpp 
b/clang/lib/APINotes/APINotesReader.cpp
index fbbe9c32ce1258..dfc3beb6fa13ee 100644
--- a/clang/lib/APINotes/APINotesReader.cpp
+++ b/clang/lib/APINotes/APINotesReader.cpp
@@ -30,23 +30,20 @@ namespace {
 llvm::VersionTuple ReadVersionTuple(const uint8_t *) {
   uint8_t NumVersions = (*Data++) & 0x03;
 
-  unsigned Major =
-  endian::readNext(Data);
+  unsigned Major = endian::readNext(Data);
   if (NumVersions == 0)
 return llvm::VersionTuple(Major);
 
-  unsigned Minor =
-  endian::readNext(Data);
+  unsigned Minor = endian::readNext(Data);
   if (NumVersions == 1)
 return llvm::VersionTuple(Major, Minor);
 
   unsigned Subminor =
-  endian::readNext(Data);
+  endian::readNext(Data);
   if (NumVersions == 2)
 return llvm::VersionTuple(Major, Minor, Subminor);
 
-  unsigned Build =
-  endian::readNext(Data);
+  unsigned Build = endian::readNext(Data);
   return llvm::VersionTuple(Major, Minor, Subminor, Build);
 }
 
@@ -71,16 +68,16 @@ class VersionedTableInfo {
 
   static std::pair ReadKeyDataLength(const uint8_t *) 
{
 unsigned KeyLength =
-endian::readNext(Data);
+endian::readNext(Data);
 unsigned DataLength =
-endian::readNext(Data);
+endian::readNext(Data);
 return {KeyLength, DataLength};
   }
 
   static data_type ReadData(internal_key_type Key, const uint8_t *Data,
 unsigned Length) {
 unsigned NumElements =
-endian::readNext(Data);
+endian::readNext(Data);
 data_type Result;
 Result.reserve(NumElements);
 for (unsigned i = 0; i != NumElements; ++i) {
@@ -105,14 +102,14 @@ void ReadCommonEntityInfo(const uint8_t *, 
CommonEntityInfo ) {
 Info.setSwiftPrivate(static_cast((UnavailableBits >> 3) & 0x01));
 
   unsigned MsgLength =
-  endian::readNext(Data);
+  endian::readNext(Data);
   Info.UnavailableMsg =
   std::string(reinterpret_cast(Data),
   reinterpret_cast(Data) + MsgLength);
   Data += MsgLength;
 
   unsigned SwiftNameLength =
-  endian::readNext(Data);
+  endian::readNext(Data);
   Info.SwiftName =
   std::string(reinterpret_cast(Data),
   reinterpret_cast(Data) + SwiftNameLength);
@@ -124,7 +121,7 @@ void ReadCommonTypeInfo(const uint8_t *, 
CommonTypeInfo ) {
   ReadCommonEntityInfo(Data, Info);
 
   unsigned SwiftBridgeLength =
-  endian::readNext(Data);
+  endian::readNext(Data);
   if (SwiftBridgeLength > 0) {
 Info.setSwiftBridge(std::string(reinterpret_cast(Data),
 SwiftBridgeLength - 1));
@@ -132,7 +129,7 @@ void ReadCommonTypeInfo(const uint8_t *, 
CommonTypeInfo ) {
   }
 
   unsigned ErrorDomainLength =
-  endian::readNext(Data);
+  endian::readNext(Data);
   if (ErrorDomainLength > 0) {
 Info.setNSErrorDomain(std::optional(std::string(
 reinterpret_cast(Data), ErrorDomainLength - 1)));
@@ -163,9 +160,9 @@ class IdentifierTableInfo {
 
   static std::pair ReadKeyDataLength(const uint8_t *) 
{
 unsigned KeyLength =
-endian::readNext(Data);
+endian::readNext(Data);
 unsigned DataLength =
-endian::readNext(Data);
+endian::readNext(Data);
 return {KeyLength, DataLength};
   }
 
@@ -175,8 +172,7 @@ class IdentifierTableInfo {
 
   static data_type ReadData(internal_key_type key, const uint8_t *Data,
 unsigned Length) {
-return endian::readNext(
-Data);
+return endian::readNext(Data);
   }
 };
 
@@ -203,26 +199,24 @@ class ObjCContextIDTableInfo {
 
   static std::pair ReadKeyDataLength(const uint8_t *) 
{
 unsigned KeyLength =
-endian::readNext(Data);
+endian::readNext(Data);
 unsigned DataLength =
-endian::readNext(Data);
+endian::readNext(Data);
 return {KeyLength, DataLength};
   }
 
   static internal_key_type ReadKey(const uint8_t *Data, unsigned Length) {
 auto ParentCtxID =
-endian::readNext(Data);
+endian::readNext(Data);
 auto ContextKind =
-endian::readNext(Data);
-auto NameID =
-endian::readNext(Data);
+endian::readNext(Data);
+auto NameID = endian::readNext(Data);
 return {ParentCtxID, ContextKind, NameID};
   }
 
   static data_type ReadData(internal_key_type Key, 

[clang] [clang] Drop unaligned from calls to readNext (NFC) (PR #88842)

2024-04-15 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Kazu Hirata (kazutakahirata)


Changes

Now readNext defaults to unaligned accesses.  This patch drops
unaligned to improve readability.


---

Patch is 30.09 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/88842.diff


4 Files Affected:

- (modified) clang/lib/APINotes/APINotesReader.cpp (+55-82) 
- (modified) clang/lib/Serialization/ASTReader.cpp (+37-50) 
- (modified) clang/lib/Serialization/GlobalModuleIndex.cpp (+4-8) 
- (modified) clang/lib/Serialization/MultiOnDiskHashTable.h (+2-2) 


``diff
diff --git a/clang/lib/APINotes/APINotesReader.cpp 
b/clang/lib/APINotes/APINotesReader.cpp
index fbbe9c32ce1258..dfc3beb6fa13ee 100644
--- a/clang/lib/APINotes/APINotesReader.cpp
+++ b/clang/lib/APINotes/APINotesReader.cpp
@@ -30,23 +30,20 @@ namespace {
 llvm::VersionTuple ReadVersionTuple(const uint8_t *) {
   uint8_t NumVersions = (*Data++) & 0x03;
 
-  unsigned Major =
-  endian::readNext(Data);
+  unsigned Major = endian::readNext(Data);
   if (NumVersions == 0)
 return llvm::VersionTuple(Major);
 
-  unsigned Minor =
-  endian::readNext(Data);
+  unsigned Minor = endian::readNext(Data);
   if (NumVersions == 1)
 return llvm::VersionTuple(Major, Minor);
 
   unsigned Subminor =
-  endian::readNext(Data);
+  endian::readNext(Data);
   if (NumVersions == 2)
 return llvm::VersionTuple(Major, Minor, Subminor);
 
-  unsigned Build =
-  endian::readNext(Data);
+  unsigned Build = endian::readNext(Data);
   return llvm::VersionTuple(Major, Minor, Subminor, Build);
 }
 
@@ -71,16 +68,16 @@ class VersionedTableInfo {
 
   static std::pair ReadKeyDataLength(const uint8_t *) 
{
 unsigned KeyLength =
-endian::readNext(Data);
+endian::readNext(Data);
 unsigned DataLength =
-endian::readNext(Data);
+endian::readNext(Data);
 return {KeyLength, DataLength};
   }
 
   static data_type ReadData(internal_key_type Key, const uint8_t *Data,
 unsigned Length) {
 unsigned NumElements =
-endian::readNext(Data);
+endian::readNext(Data);
 data_type Result;
 Result.reserve(NumElements);
 for (unsigned i = 0; i != NumElements; ++i) {
@@ -105,14 +102,14 @@ void ReadCommonEntityInfo(const uint8_t *, 
CommonEntityInfo ) {
 Info.setSwiftPrivate(static_cast((UnavailableBits >> 3) & 0x01));
 
   unsigned MsgLength =
-  endian::readNext(Data);
+  endian::readNext(Data);
   Info.UnavailableMsg =
   std::string(reinterpret_cast(Data),
   reinterpret_cast(Data) + MsgLength);
   Data += MsgLength;
 
   unsigned SwiftNameLength =
-  endian::readNext(Data);
+  endian::readNext(Data);
   Info.SwiftName =
   std::string(reinterpret_cast(Data),
   reinterpret_cast(Data) + SwiftNameLength);
@@ -124,7 +121,7 @@ void ReadCommonTypeInfo(const uint8_t *, 
CommonTypeInfo ) {
   ReadCommonEntityInfo(Data, Info);
 
   unsigned SwiftBridgeLength =
-  endian::readNext(Data);
+  endian::readNext(Data);
   if (SwiftBridgeLength > 0) {
 Info.setSwiftBridge(std::string(reinterpret_cast(Data),
 SwiftBridgeLength - 1));
@@ -132,7 +129,7 @@ void ReadCommonTypeInfo(const uint8_t *, 
CommonTypeInfo ) {
   }
 
   unsigned ErrorDomainLength =
-  endian::readNext(Data);
+  endian::readNext(Data);
   if (ErrorDomainLength > 0) {
 Info.setNSErrorDomain(std::optional(std::string(
 reinterpret_cast(Data), ErrorDomainLength - 1)));
@@ -163,9 +160,9 @@ class IdentifierTableInfo {
 
   static std::pair ReadKeyDataLength(const uint8_t *) 
{
 unsigned KeyLength =
-endian::readNext(Data);
+endian::readNext(Data);
 unsigned DataLength =
-endian::readNext(Data);
+endian::readNext(Data);
 return {KeyLength, DataLength};
   }
 
@@ -175,8 +172,7 @@ class IdentifierTableInfo {
 
   static data_type ReadData(internal_key_type key, const uint8_t *Data,
 unsigned Length) {
-return endian::readNext(
-Data);
+return endian::readNext(Data);
   }
 };
 
@@ -203,26 +199,24 @@ class ObjCContextIDTableInfo {
 
   static std::pair ReadKeyDataLength(const uint8_t *) 
{
 unsigned KeyLength =
-endian::readNext(Data);
+endian::readNext(Data);
 unsigned DataLength =
-endian::readNext(Data);
+endian::readNext(Data);
 return {KeyLength, DataLength};
   }
 
   static internal_key_type ReadKey(const uint8_t *Data, unsigned Length) {
 auto ParentCtxID =
-endian::readNext(Data);
+endian::readNext(Data);
 auto ContextKind =
-endian::readNext(Data);
-auto NameID =
-endian::readNext(Data);
+endian::readNext(Data);
+auto NameID = endian::readNext(Data);
 return {ParentCtxID, ContextKind, NameID};
   }
 
   static data_type ReadData(internal_key_type 

[clang] [clang] Drop unaligned from calls to readNext (NFC) (PR #88842)

2024-04-15 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/88842

Now readNext defaults to unaligned accesses.  This patch drops
unaligned to improve readability.


>From 9a07aaf809d8cb2e4b22aa7c4bd5eb274abbfe8a Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Mon, 15 Apr 2024 09:41:29 -0700
Subject: [PATCH] [clang] Drop unaligned from calls to readNext (NFC)

Now readNext defaults to unaligned accesses.  This patch drops
unaligned to improve readability.
---
 clang/lib/APINotes/APINotesReader.cpp | 137 +++---
 clang/lib/Serialization/ASTReader.cpp |  87 +--
 clang/lib/Serialization/GlobalModuleIndex.cpp |  12 +-
 .../lib/Serialization/MultiOnDiskHashTable.h  |   4 +-
 4 files changed, 98 insertions(+), 142 deletions(-)

diff --git a/clang/lib/APINotes/APINotesReader.cpp 
b/clang/lib/APINotes/APINotesReader.cpp
index fbbe9c32ce1258..dfc3beb6fa13ee 100644
--- a/clang/lib/APINotes/APINotesReader.cpp
+++ b/clang/lib/APINotes/APINotesReader.cpp
@@ -30,23 +30,20 @@ namespace {
 llvm::VersionTuple ReadVersionTuple(const uint8_t *) {
   uint8_t NumVersions = (*Data++) & 0x03;
 
-  unsigned Major =
-  endian::readNext(Data);
+  unsigned Major = endian::readNext(Data);
   if (NumVersions == 0)
 return llvm::VersionTuple(Major);
 
-  unsigned Minor =
-  endian::readNext(Data);
+  unsigned Minor = endian::readNext(Data);
   if (NumVersions == 1)
 return llvm::VersionTuple(Major, Minor);
 
   unsigned Subminor =
-  endian::readNext(Data);
+  endian::readNext(Data);
   if (NumVersions == 2)
 return llvm::VersionTuple(Major, Minor, Subminor);
 
-  unsigned Build =
-  endian::readNext(Data);
+  unsigned Build = endian::readNext(Data);
   return llvm::VersionTuple(Major, Minor, Subminor, Build);
 }
 
@@ -71,16 +68,16 @@ class VersionedTableInfo {
 
   static std::pair ReadKeyDataLength(const uint8_t *) 
{
 unsigned KeyLength =
-endian::readNext(Data);
+endian::readNext(Data);
 unsigned DataLength =
-endian::readNext(Data);
+endian::readNext(Data);
 return {KeyLength, DataLength};
   }
 
   static data_type ReadData(internal_key_type Key, const uint8_t *Data,
 unsigned Length) {
 unsigned NumElements =
-endian::readNext(Data);
+endian::readNext(Data);
 data_type Result;
 Result.reserve(NumElements);
 for (unsigned i = 0; i != NumElements; ++i) {
@@ -105,14 +102,14 @@ void ReadCommonEntityInfo(const uint8_t *, 
CommonEntityInfo ) {
 Info.setSwiftPrivate(static_cast((UnavailableBits >> 3) & 0x01));
 
   unsigned MsgLength =
-  endian::readNext(Data);
+  endian::readNext(Data);
   Info.UnavailableMsg =
   std::string(reinterpret_cast(Data),
   reinterpret_cast(Data) + MsgLength);
   Data += MsgLength;
 
   unsigned SwiftNameLength =
-  endian::readNext(Data);
+  endian::readNext(Data);
   Info.SwiftName =
   std::string(reinterpret_cast(Data),
   reinterpret_cast(Data) + SwiftNameLength);
@@ -124,7 +121,7 @@ void ReadCommonTypeInfo(const uint8_t *, 
CommonTypeInfo ) {
   ReadCommonEntityInfo(Data, Info);
 
   unsigned SwiftBridgeLength =
-  endian::readNext(Data);
+  endian::readNext(Data);
   if (SwiftBridgeLength > 0) {
 Info.setSwiftBridge(std::string(reinterpret_cast(Data),
 SwiftBridgeLength - 1));
@@ -132,7 +129,7 @@ void ReadCommonTypeInfo(const uint8_t *, 
CommonTypeInfo ) {
   }
 
   unsigned ErrorDomainLength =
-  endian::readNext(Data);
+  endian::readNext(Data);
   if (ErrorDomainLength > 0) {
 Info.setNSErrorDomain(std::optional(std::string(
 reinterpret_cast(Data), ErrorDomainLength - 1)));
@@ -163,9 +160,9 @@ class IdentifierTableInfo {
 
   static std::pair ReadKeyDataLength(const uint8_t *) 
{
 unsigned KeyLength =
-endian::readNext(Data);
+endian::readNext(Data);
 unsigned DataLength =
-endian::readNext(Data);
+endian::readNext(Data);
 return {KeyLength, DataLength};
   }
 
@@ -175,8 +172,7 @@ class IdentifierTableInfo {
 
   static data_type ReadData(internal_key_type key, const uint8_t *Data,
 unsigned Length) {
-return endian::readNext(
-Data);
+return endian::readNext(Data);
   }
 };
 
@@ -203,26 +199,24 @@ class ObjCContextIDTableInfo {
 
   static std::pair ReadKeyDataLength(const uint8_t *) 
{
 unsigned KeyLength =
-endian::readNext(Data);
+endian::readNext(Data);
 unsigned DataLength =
-endian::readNext(Data);
+endian::readNext(Data);
 return {KeyLength, DataLength};
   }
 
   static internal_key_type ReadKey(const uint8_t *Data, unsigned Length) {
 auto ParentCtxID =
-endian::readNext(Data);
+endian::readNext(Data);
 auto ContextKind =
-endian::readNext(Data);
-auto NameID =
-endian::readNext(Data);
+