Skip to content

Commit

Permalink
Suppress santize alignment warnings on 64-bit builds
Browse files Browse the repository at this point in the history
  • Loading branch information
mikee47 committed Jun 27, 2024
1 parent 8685d62 commit 66ab95e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/include/FlashString/Map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class Map : public Object<Map<KeyType, ContentType>, Pair>
* @brief Get a map entry by index, if it exists
* @note Result validity can be checked using if()
*/
const Pair valueAt(unsigned index) const
FSTR_ALIGN32 const Pair valueAt(unsigned index) const
{
if(index >= this->length()) {
return Pair::empty();
Expand All @@ -139,7 +139,7 @@ class Map : public Object<Map<KeyType, ContentType>, Pair>
* @retval int If key isn't found, return -1
*/
template <typename TRefKey, typename T = KeyType>
typename std::enable_if<!std::is_class<T>::value, int>::type indexOf(const TRefKey& key) const
FSTR_ALIGN32 typename std::enable_if<!std::is_class<T>::value, int>::type indexOf(const TRefKey& key) const
{
auto p = this->data();
auto len = this->length();
Expand All @@ -159,8 +159,8 @@ class Map : public Object<Map<KeyType, ContentType>, Pair>
* @retval int If key isn't found, return -1
*/
template <typename TRefKey, typename T = KeyType>
typename std::enable_if<std::is_same<T, String>::value, int>::type indexOf(const TRefKey& key,
bool ignoreCase = true) const
FSTR_ALIGN32 typename std::enable_if<std::is_same<T, String>::value, int>::type
indexOf(const TRefKey& key, bool ignoreCase = true) const
{
auto p = this->data();
auto len = this->length();
Expand Down
5 changes: 3 additions & 2 deletions src/include/FlashString/MapPair.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ template <typename KeyType, class ContentType> class MapPair
/**
* @brief Get the key (non-class key types)
*/
template <typename T = KeyType> typename std::enable_if<!std::is_class<T>::value, KeyType>::type key() const
template <typename T = KeyType>
FSTR_ALIGN32 typename std::enable_if<!std::is_class<T>::value, KeyType>::type key() const
{
// Ensure access is aligned for 1/2 byte keys
return readValue<KeyType>(&key_);
Expand All @@ -72,7 +73,7 @@ template <typename KeyType, class ContentType> class MapPair
* @brief Get the key (String key type)
*/
template <typename T = KeyType>
typename std::enable_if<std::is_same<T, String>::value, const KeyType&>::type key() const
FSTR_ALIGN32 typename std::enable_if<std::is_same<T, String>::value, const KeyType&>::type key() const
{
return (key_ == nullptr) ? String::empty() : *key_;
}
Expand Down
5 changes: 3 additions & 2 deletions src/include/FlashString/ObjectIterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ template <class ObjectType, typename ElementType> class ObjectIterator
* @brief Accessor returns a reference for pointer-type elements
*/
template <typename T = ElementType>
typename std::enable_if<std::is_pointer<T>::value, const typename std::remove_pointer<ElementType>::type&>::type
operator*() const
FSTR_ALIGN32
typename std::enable_if<std::is_pointer<T>::value, const typename std::remove_pointer<ElementType>::type&>::type
operator*() const
{
auto ptr = data[index];
return ptr ? *ptr : std::remove_pointer<ElementType>::type::empty();
Expand Down
2 changes: 1 addition & 1 deletion src/include/FlashString/Utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ template <typename T> FSTR_INLINE typename std::enable_if<sizeof(T) == 2, T>::ty
return static_cast<T>(pgm_read_word(ptr));
}

template <typename T> FSTR_INLINE typename std::enable_if<sizeof(T) == 4, T>::type readValue(const T* ptr)
template <typename T> FSTR_ALIGN32 FSTR_INLINE typename std::enable_if<sizeof(T) == 4, T>::type readValue(const T* ptr)
{
union {
uint32_t u32;
Expand Down
2 changes: 1 addition & 1 deletion src/include/FlashString/Vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ template <class ObjectType> class Vector : public Object<Vector<ObjectType>, con
return printer().printTo(p);
}

FSTR_INLINE static const ObjectType& unsafeValueAt(const DataPtrType dataptr, unsigned index)
FSTR_ALIGN32 static const ObjectType& unsafeValueAt(const DataPtrType dataptr, unsigned index)
{
auto ptr = dataptr[index];
return ptr ? *ptr : ObjectType::empty();
Expand Down
1 change: 1 addition & 0 deletions src/include/FlashString/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define FSTR_NOINLINE __attribute__((noinline))
#define FSTR_ALIGNED __attribute__((aligned(4)))
#define FSTR_PACKED __attribute__((packed))
#define FSTR_ALIGN32 __attribute__((no_sanitize("alignment")))

#ifdef __clang__
// Clang has a habit of throwing stuff away we want
Expand Down

0 comments on commit 66ab95e

Please sign in to comment.