Skip to content

Commit 4cd8b0c

Browse files
authored
Merge pull request #1660 from SCIInstitute/gcc6-2-fix
GCC6.2 fix
2 parents f8d33c4 + 53333a7 commit 4cd8b0c

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

src/Core/Datatypes/Legacy/Field/HexVolMesh.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2649,9 +2649,9 @@ class HexVolMesh : public Mesh
26492649

26502650
/// These are for our own use (making the hash function.
26512651
static const int sz_quarter_int = (int)(sz_int / 4);
2652-
static const int top4_mask = ((~((int)0)) << sz_quarter_int << sz_quarter_int << sz_quarter_int);
2653-
static const int up4_mask = top4_mask ^ (~((int)0) << sz_quarter_int << sz_quarter_int);
2654-
static const int mid4_mask = top4_mask ^ (~((int)0) << sz_quarter_int);
2652+
static const int top4_mask = -(1 << sz_quarter_int << sz_quarter_int << sz_quarter_int);
2653+
static const int up4_mask = top4_mask ^ -(1 << sz_quarter_int << sz_quarter_int);
2654+
static const int mid4_mask = top4_mask ^ -(1 << sz_quarter_int);
26552655
static const int low4_mask = ~(top4_mask | mid4_mask);
26562656

26572657
/// This is the hash function
@@ -2714,7 +2714,7 @@ class HexVolMesh : public Mesh
27142714
/// These are for our own use (making the hash function.
27152715
static const int sz_int = sizeof(int) * 8; // in bits
27162716
static const int sz_half_int = sizeof(int) << 2; // in bits
2717-
static const int up_mask = ((~((int)0)) << sz_half_int);
2717+
static const int up_mask = -(1 << sz_half_int);
27182718
static const int low_mask = (~((int)0) ^ up_mask);
27192719

27202720
/// This is the hash function

src/Core/Datatypes/Legacy/Field/PrismVolMesh.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,9 +2408,9 @@ class PrismVolMesh : public Mesh
24082408

24092409
/// These are for our own use (making the hash function.
24102410
static const int sz_quarter_int = (int)(sz_int / 4);
2411-
static const int top4_mask = ((~((int)0)) << sz_quarter_int << sz_quarter_int << sz_quarter_int);
2412-
static const int up4_mask = top4_mask ^ (~((int)0) << sz_quarter_int << sz_quarter_int);
2413-
static const int mid4_mask = top4_mask ^ (~((int)0) << sz_quarter_int);
2411+
static const int top4_mask = -(1 << sz_quarter_int << sz_quarter_int << sz_quarter_int);
2412+
static const int up4_mask = top4_mask ^ -(1 << sz_quarter_int << sz_quarter_int);
2413+
static const int mid4_mask = top4_mask ^ -(1 << sz_quarter_int);
24142414
static const int low4_mask = ~(top4_mask | mid4_mask);
24152415

24162416
/// This is the hash function
@@ -2451,7 +2451,7 @@ class PrismVolMesh : public Mesh
24512451
/// These are for our own use (making the hash function.
24522452
static const int sz_int = sizeof(int) * 8; // in bits
24532453
static const int sz_half_int = sizeof(int) << 2; // in bits
2454-
static const int up_mask = ((~((int)0)) << sz_half_int);
2454+
static const int up_mask = -(1 << sz_half_int);
24552455
static const int low_mask = (~((int)0) ^ up_mask);
24562456

24572457
/// This is the hash function

src/Core/Datatypes/Legacy/Field/TetVolMesh.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,8 +2479,8 @@ class TetVolMesh : public Mesh
24792479

24802480
/// These are for our own use (making the hash function).
24812481
static const int sz_third_int = (int)(sz_int / 3);
2482-
static const int up_mask = (~((int)0) << sz_third_int << sz_third_int);
2483-
static const int mid_mask = up_mask ^ (~((int)0) << sz_third_int);
2482+
static const int up_mask = -(1 << sz_third_int << sz_third_int);
2483+
static const int mid_mask = up_mask ^ -(1 << sz_third_int);
24842484
static const int low_mask = ~(up_mask | mid_mask);
24852485

24862486
/// This is the hash function
@@ -2513,7 +2513,7 @@ class TetVolMesh : public Mesh
25132513
/// These are for our own use (making the hash function.
25142514
static const int sz_int = sizeof(int) * 8; // in bits
25152515
static const int sz_half_int = sizeof(int) << 2; // in bits
2516-
static const int up_mask = ((~((int)0)) << sz_half_int);
2516+
static const int up_mask = -(1 << sz_half_int);
25172517
static const int low_mask = (~((int)0) ^ up_mask);
25182518

25192519
/// This is the hash function

src/Core/Parser/Tests/ParserTests.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,3 +1579,33 @@ TEST_F(BasicParserTests, CreateFieldData_fracanisotropy)
15791579
15801580
*/
15811581

1582+
TEST(FieldHashTests, TestShiftingZero)
1583+
{
1584+
// copied from TetVolMesh.h, failing compilation on GCC 6.2.
1585+
static const int sz_int = sizeof(int) * 8; // in bits
1586+
1587+
/// These are for our own use (making the hash function).
1588+
static const int sz_third_int = (int)(sz_int / 3);
1589+
static const int up_mask = -1048576; // (~((int)0) << sz_third_int << sz_third_int);
1590+
static const int mid_mask = 1047552; // up_mask ^ (~((int)0) << sz_third_int);
1591+
static const int low_mask = ~(up_mask | mid_mask);
1592+
1593+
std::cout << "sz_int: " << sz_int << std::endl;
1594+
std::cout << "sz_third_int: " << sz_third_int << std::endl;
1595+
std::cout << "up_mask: " << up_mask << std::endl;
1596+
std::cout << "mid_mask: " << mid_mask << std::endl;
1597+
std::cout << "low_mask: " << low_mask << std::endl;
1598+
1599+
auto badGcc = ~((int)0);
1600+
std::cout << "badGcc: " << badGcc << std::endl;
1601+
1602+
auto redo_up_mask = -(1 << 10 << 10);
1603+
std::cout << "redo_up_mask: " << redo_up_mask << std::endl;
1604+
1605+
auto redo_mid_mask = redo_up_mask ^ (-(1 << sz_third_int));
1606+
auto redo_low_mask = ~(redo_up_mask | redo_mid_mask);
1607+
1608+
ASSERT_EQ(redo_up_mask, up_mask);
1609+
ASSERT_EQ(redo_mid_mask, mid_mask);
1610+
ASSERT_EQ(redo_low_mask, low_mask);
1611+
}

0 commit comments

Comments
 (0)