vtk-m/vtkm/testing/UnitTestArrayPortalValueReference.cxx

329 lines
10 KiB
C++
Raw Normal View History

//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
2019-04-15 23:24:21 +00:00
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/testing/Testing.h>
#include <vtkm/TypeTraits.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/internal/ArrayPortalValueReference.h>
2017-05-18 14:29:41 +00:00
namespace
{
static constexpr vtkm::Id ARRAY_SIZE = 10;
2017-05-18 14:29:41 +00:00
template <typename ArrayPortalType>
void SetReference(vtkm::Id index, vtkm::internal::ArrayPortalValueReference<ArrayPortalType> ref)
{
using ValueType = typename ArrayPortalType::ValueType;
ref = TestValue(index, ValueType());
}
2017-05-18 14:29:41 +00:00
template <typename ArrayPortalType>
void CheckReference(vtkm::Id index, vtkm::internal::ArrayPortalValueReference<ArrayPortalType> ref)
{
using ValueType = typename ArrayPortalType::ValueType;
2017-05-18 14:29:41 +00:00
VTKM_TEST_ASSERT(test_equal(ref, TestValue(index, ValueType())), "Got bad value from reference.");
}
template <typename ArrayPortalType>
void TryOperatorsNoVec(vtkm::Id index,
vtkm::internal::ArrayPortalValueReference<ArrayPortalType> ref,
vtkm::TypeTraitsScalarTag)
{
using ValueType = typename ArrayPortalType::ValueType;
ValueType expected = TestValue(index, ValueType());
VTKM_TEST_ASSERT(ref.Get() == expected, "Reference did not start out as expected.");
VTKM_TEST_ASSERT(!(ref < ref));
VTKM_TEST_ASSERT(ref < ValueType(expected + ValueType(1)));
VTKM_TEST_ASSERT(ValueType(expected - ValueType(1)) < ref);
VTKM_TEST_ASSERT(!(ref > ref));
VTKM_TEST_ASSERT(ref > ValueType(expected - ValueType(1)));
VTKM_TEST_ASSERT(ValueType(expected + ValueType(1)) > ref);
VTKM_TEST_ASSERT(ref <= ref);
VTKM_TEST_ASSERT(ref <= ValueType(expected + ValueType(1)));
VTKM_TEST_ASSERT(ValueType(expected - ValueType(1)) <= ref);
VTKM_TEST_ASSERT(ref >= ref);
VTKM_TEST_ASSERT(ref >= ValueType(expected - ValueType(1)));
VTKM_TEST_ASSERT(ValueType(expected + ValueType(1)) >= ref);
}
template <typename ArrayPortalType>
void TryOperatorsNoVec(vtkm::Id,
vtkm::internal::ArrayPortalValueReference<ArrayPortalType>,
vtkm::TypeTraitsVectorTag)
{
}
template <typename ArrayPortalType>
void TryOperatorsInt(vtkm::Id index,
vtkm::internal::ArrayPortalValueReference<ArrayPortalType> ref,
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
vtkm::internal::ArrayPortalValueReference<ArrayPortalType> scratch,
vtkm::TypeTraitsScalarTag,
vtkm::TypeTraitsIntegerTag)
{
using ValueType = typename ArrayPortalType::ValueType;
ValueType expected = TestValue(index, ValueType());
VTKM_TEST_ASSERT(ref.Get() == expected, "Reference did not start out as expected.");
VTKM_TEST_ASSERT((ref % ref) == (expected % expected));
VTKM_TEST_ASSERT((ref % expected) == (expected % expected));
VTKM_TEST_ASSERT((expected % ref) == (expected % expected));
VTKM_TEST_ASSERT((ref ^ ref) == (expected ^ expected));
VTKM_TEST_ASSERT((ref ^ expected) == (expected ^ expected));
VTKM_TEST_ASSERT((expected ^ ref) == (expected ^ expected));
VTKM_TEST_ASSERT((ref | ref) == (expected | expected));
VTKM_TEST_ASSERT((ref | expected) == (expected | expected));
VTKM_TEST_ASSERT((expected | ref) == (expected | expected));
VTKM_TEST_ASSERT((ref & ref) == (expected & expected));
VTKM_TEST_ASSERT((ref & expected) == (expected & expected));
VTKM_TEST_ASSERT((expected & ref) == (expected & expected));
VTKM_TEST_ASSERT((ref << ref) == (expected << expected));
VTKM_TEST_ASSERT((ref << expected) == (expected << expected));
VTKM_TEST_ASSERT((expected << ref) == (expected << expected));
VTKM_TEST_ASSERT((ref << ref) == (expected << expected));
VTKM_TEST_ASSERT((ref << expected) == (expected << expected));
VTKM_TEST_ASSERT((expected << ref) == (expected << expected));
VTKM_TEST_ASSERT(~ref == ~expected);
VTKM_TEST_ASSERT(!(!ref));
VTKM_TEST_ASSERT(ref && ref);
VTKM_TEST_ASSERT(ref && expected);
VTKM_TEST_ASSERT(expected && ref);
VTKM_TEST_ASSERT(ref || ref);
VTKM_TEST_ASSERT(ref || expected);
VTKM_TEST_ASSERT(expected || ref);
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
scratch = ValueType(7);
const ValueType operand = ValueType(7);
#define RESET \
ref = TestValue(index, ValueType()); \
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
expected = TestValue(index, ValueType());
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
RESET;
ref &= scratch;
expected &= operand;
VTKM_TEST_ASSERT(ref == expected);
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
RESET;
ref &= operand;
expected &= operand;
VTKM_TEST_ASSERT(ref == expected);
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
RESET;
ref |= scratch;
expected |= operand;
VTKM_TEST_ASSERT(ref == expected);
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
RESET;
ref |= operand;
expected |= operand;
VTKM_TEST_ASSERT(ref == expected);
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
RESET;
ref >>= scratch;
expected >>= operand;
VTKM_TEST_ASSERT(ref == expected);
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
RESET;
ref >>= operand;
expected >>= operand;
VTKM_TEST_ASSERT(ref == expected);
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
RESET;
ref <<= scratch;
expected <<= operand;
VTKM_TEST_ASSERT(ref == expected);
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
RESET;
ref <<= operand;
expected <<= operand;
VTKM_TEST_ASSERT(ref == expected);
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
RESET;
ref ^= scratch;
expected ^= operand;
VTKM_TEST_ASSERT(ref == expected);
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
RESET;
ref ^= operand;
expected ^= operand;
VTKM_TEST_ASSERT(ref == expected);
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
#undef RESET
}
template <typename ArrayPortalType, typename DimTag, typename NumericTag>
void TryOperatorsInt(vtkm::Id,
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
vtkm::internal::ArrayPortalValueReference<ArrayPortalType>,
vtkm::internal::ArrayPortalValueReference<ArrayPortalType>,
DimTag,
NumericTag)
{
}
template <typename ArrayPortalType>
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
void TryOperators(vtkm::Id index,
vtkm::internal::ArrayPortalValueReference<ArrayPortalType> ref,
vtkm::internal::ArrayPortalValueReference<ArrayPortalType> scratch)
{
using ValueType = typename ArrayPortalType::ValueType;
ValueType expected = TestValue(index, ValueType());
VTKM_TEST_ASSERT(ref.Get() == expected, "Reference did not start out as expected.");
// Test comparison operators.
VTKM_TEST_ASSERT(ref == ref);
VTKM_TEST_ASSERT(ref == expected);
VTKM_TEST_ASSERT(expected == ref);
VTKM_TEST_ASSERT(!(ref != ref));
VTKM_TEST_ASSERT(!(ref != expected));
VTKM_TEST_ASSERT(!(expected != ref));
TryOperatorsNoVec(index, ref, typename vtkm::TypeTraits<ValueType>::DimensionalityTag());
VTKM_TEST_ASSERT((ref + ref) == (expected + expected));
VTKM_TEST_ASSERT((ref + expected) == (expected + expected));
VTKM_TEST_ASSERT((expected + ref) == (expected + expected));
VTKM_TEST_ASSERT((ref - ref) == (expected - expected));
VTKM_TEST_ASSERT((ref - expected) == (expected - expected));
VTKM_TEST_ASSERT((expected - ref) == (expected - expected));
VTKM_TEST_ASSERT((ref * ref) == (expected * expected));
VTKM_TEST_ASSERT((ref * expected) == (expected * expected));
VTKM_TEST_ASSERT((expected * ref) == (expected * expected));
VTKM_TEST_ASSERT((ref / ref) == (expected / expected));
VTKM_TEST_ASSERT((ref / expected) == (expected / expected));
VTKM_TEST_ASSERT((expected / ref) == (expected / expected));
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
scratch = ValueType(7);
const ValueType operand = ValueType(7);
#define RESET \
ref = TestValue(index, ValueType()); \
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
expected = TestValue(index, ValueType());
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
RESET;
ref += scratch;
expected += operand;
VTKM_TEST_ASSERT(ref == expected);
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
RESET;
ref += operand;
expected += operand;
VTKM_TEST_ASSERT(ref == expected);
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
RESET;
ref -= scratch;
expected -= operand;
VTKM_TEST_ASSERT(ref == expected);
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
RESET;
ref -= operand;
expected -= operand;
VTKM_TEST_ASSERT(ref == expected);
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
RESET;
ref *= scratch;
expected *= operand;
VTKM_TEST_ASSERT(ref == expected);
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
RESET;
ref *= operand;
expected *= operand;
VTKM_TEST_ASSERT(ref == expected);
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
RESET;
ref /= scratch;
expected /= operand;
VTKM_TEST_ASSERT(ref == expected);
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
RESET;
ref /= operand;
expected /= operand;
VTKM_TEST_ASSERT(ref == expected);
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
RESET;
TryOperatorsInt(index,
ref,
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
scratch,
typename vtkm::TypeTraits<ValueType>::DimensionalityTag(),
typename vtkm::TypeTraits<ValueType>::NumericTag());
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
#undef RESET
}
struct DoTestForType
{
2017-05-18 14:29:41 +00:00
template <typename ValueType>
VTKM_CONT void operator()(const ValueType&) const
{
vtkm::cont::ArrayHandle<ValueType> array;
array.Allocate(ARRAY_SIZE);
std::cout << "Set array using reference" << std::endl;
using PortalType = typename vtkm::cont::ArrayHandle<ValueType>::WritePortalType;
PortalType portal = array.WritePortal();
for (vtkm::Id index = 0; index < ARRAY_SIZE; ++index)
{
2017-05-18 14:29:41 +00:00
SetReference(index, vtkm::internal::ArrayPortalValueReference<PortalType>(portal, index));
}
std::cout << "Check values" << std::endl;
CheckPortal(portal);
std::cout << "Check references in set array." << std::endl;
for (vtkm::Id index = 0; index < ARRAY_SIZE; ++index)
{
2017-05-18 14:29:41 +00:00
CheckReference(index, vtkm::internal::ArrayPortalValueReference<PortalType>(portal, index));
}
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
std::cout << "Make a scratch buffer for ref-ref operations." << std::endl;
vtkm::cont::ArrayHandle<ValueType> scratchArray;
scratchArray.Allocate(1);
PortalType scratchPortal = scratchArray.WritePortal();
std::cout << "Check that operators work." << std::endl;
// Start at 1 to avoid issues with 0.
for (vtkm::Id index = 1; index < ARRAY_SIZE; ++index)
{
Fix UnitTestArrayPortalValueReference A recent change to the continuous integration setup has caused `UnitTestArrayPortalValueReference` to fail on one platform. The problem was that the test was doing two unsafe things with the right-shift assignment operator. The first unsafe thing was using itself as the operand. ```cpp ref >>= ref; ``` This causes clang to give a "self assign overload" warning. Using a variable as its own operand for a compute assign operation isn't great style, but for some operations it can cause weird errors. The reason for the warning is that for a true integer shift operation, the compiler will recognize that the result should be 0. So, when using this on base integer types, you will get 0. But overloads can give you something different, so that might lead to unexpected results. Because we _are_ using an overload (for the `ArrayPortalValueReference` class), the compiler tells us we can get potentially unexpected results. OK. That seems like something we can safely ignore (and were ignoring for some time). After all, the whole point of the `ArrayPortalValueReference` operators is to behave exactly the same as the values they wrap. That brings us to the second unsafe thing the test was doing: using an invalid value as the right hand operation. And this is where things get weird. The test was specifically failing when being run on `Int32`. It was setting the underlying value for `ref` to be `1000` to start with. So the expression `ref >>= ref` was trying to right shift `ref` by 1000 bits. Logically, this should of course give you 0. However, shifting a number by more bits than exist causes undefined behavior (c.f. https://wiki.sei.cmu.edu/confluence/display/c/INT34-C.+Do+not+shift+an+expression+by+a+negative+number+of+bits+or+by+greater+than+or+equal+to+the+number+of+bits+that+exist+in+the+operand). You might not get back the expected value, and this is exactly what was happening. What I think happened was that the compiler determined that any valid shift would be contained in 5 bits, so it truncated the value (1000) to the least signifcant 5 bits (which happens to be 8). It then shifted 1000 by 8 and got the value 3 instead of 0. The fix picks an operand number that is sure to be valid.
2020-07-14 22:10:06 +00:00
TryOperators(index,
vtkm::internal::ArrayPortalValueReference<PortalType>(portal, index),
vtkm::internal::ArrayPortalValueReference<PortalType>(scratchPortal, 0));
}
}
};
void DoTest()
{
// We are not testing on the default (exemplar) types because we want to test operators, and
// many basic C types could fail on basic operations. Small integer types (such as unsigned
// bytes) get automatically promoted to larger types, so doing somthing like a += operation
// causes annoying compiler warnings. Float types are also problematic because comparison
// operations like == can fail even when you expect the values to be the same.
vtkm::testing::Testing::TryTypes(DoTestForType(),
vtkm::List<vtkm::Int32, vtkm::UInt64, vtkm::Id3>());
}
} // anonymous namespace
int UnitTestArrayPortalValueReference(int argc, char* argv[])
{
return vtkm::testing::Testing::Run(DoTest, argc, argv);
}