1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
Last-Update: 2017-03-11
Forwarded: not-needed
Bug-Upstream: https://github.com/lizardfs/lizardfs/issues/526
Origin: upstream, https://github.com/lizardfs/lizardfs/commit/422175eb1aa8c2a1e4d0727ee3fe8190e1ae1340
From: Hazeman <hazeman@skytechnology.pl>
Date: Mon, 6 Mar 2017 13:57:16 +0100
Description: common: Fix aliasing issue in compact_vector
This commit fixes pointer/data storage aliasing issue that occurs in gcc 6.2.
Change-Id: I39307532f168eabfc1b39b81e6c1fbb8eb1b3fce
--- a/src/common/compact_vector.h
+++ b/src/common/compact_vector.h
@@ -162,10 +162,10 @@
}
private:
union {
- pointer ptr_;
- uint8_t data_[sizeof(pointer)];
+ volatile pointer ptr_;
+ uint8_t data_[sizeof(pointer)];
};
size_type size_;
};
@@ -278,10 +278,10 @@
}
private:
union {
- uint64_t ptr_;
- uint8_t data_[8];
+ volatile uint64_t ptr_;
+ uint8_t data_[8];
};
#if !defined(NDEBUG) || defined(LIZARDFS_TEST_POINTER_OBFUSCATION)
pointer debug_ptr_;
#endif
--- a/src/common/compact_vector_unittest.cc
+++ b/src/common/compact_vector_unittest.cc
@@ -179,4 +179,12 @@
vec1.assign(6, 1);
EXPECT_NE(vec1.data(), (uint8_t *)&vec1);
}
+
+TEST(CompactVectorTest, GCC6) {
+ compact_vector<uint32_t> sessionid;
+ uint32_t val = 1978;
+
+ sessionid.push_back(val);
+ EXPECT_EQ(sessionid[0], val);
+}
|