Skip to content

Commit

Permalink
Test value casts which are Undefined Behavior
Browse files Browse the repository at this point in the history
Mark as TODO since UB is not consistent across all supported platforms.
  • Loading branch information
mdavidsaver committed Aug 1, 2024
1 parent e05ee2b commit 1ca7600
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion test/testdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* in file LICENSE that is included with this distribution.
*/

#include <limits>

#include <testMain.h>

#include <epicsUnitTest.h>
Expand Down Expand Up @@ -495,7 +497,7 @@ void testClear()

MAIN(testdata)
{
testPlan(156);
testPlan(172);
testSetup();
testTraverse();
testAssign();
Expand Down Expand Up @@ -544,6 +546,35 @@ MAIN(testdata)
testConvertScalar2<int32_t, uint64_t, int64_t>(-2147483648, 0x80000000, -2147483648);
testTodoEnd();
testConvertScalar2<int32_t, uint64_t, int64_t>(0, 0x100000000llu, -0);
testTodoBegin("UB");
// test non-finite -> integer casts
// copy in
testConvertScalar2<int64_t, double, int32_t>(0,
std::numeric_limits<double>::quiet_NaN(),
0);
testConvertScalar2<int64_t, double, int32_t>(0x7fffffffffffffff,
std::numeric_limits<double>::infinity(),
0x7fffffff);
testConvertScalar2<int64_t, double, int32_t>(0x8000000000000000,
-std::numeric_limits<double>::infinity(),
0x80000000);
testConvertScalar2<uint64_t, double, uint32_t>(0xffffffffffffffff,
std::numeric_limits<double>::infinity(),
0xffffffff);
// copy out
testConvertScalar2<double, double, int32_t>(std::numeric_limits<double>::quiet_NaN(),
std::numeric_limits<double>::quiet_NaN(),
0);
testConvertScalar2<double, double, int32_t>(std::numeric_limits<double>::infinity(),
std::numeric_limits<double>::infinity(),
0x7fffffff);
testConvertScalar2<double, double, int32_t>(-std::numeric_limits<double>::infinity(),
-std::numeric_limits<double>::infinity(),
0x80000000);
testConvertScalar2<double, double, uint32_t>(std::numeric_limits<double>::infinity(),
std::numeric_limits<double>::infinity(),
0xffffffff);
testTodoEnd();

testAssignSimilar();
testAssignSimilarNDArray();
Expand Down

0 comments on commit 1ca7600

Please sign in to comment.