Skip to content

Commit 12220ab

Browse files
committed
Updated UBSAN builds to fail on errors, fixed some and suppressed the rest
Signed-off-by: Nick Avramoussis <[email protected]>
1 parent 8b727c6 commit 12220ab

File tree

11 files changed

+76
-21
lines changed

11 files changed

+76
-21
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ jobs:
153153
# Always run tests on weekly builds but skip Debug on commits as they take a while.
154154
# https://github.community/t/distinct-job-for-each-schedule/17811/2
155155
if: contains(github.event.schedule, '0 7 * * 1') || matrix.config.build == 'Release'
156-
run: cd build && ctest -V
156+
run: cd build && ctest -V -C ${{ matrix.config.build }}
157157

158158
testmacos11:
159159
if: |

.github/workflows/weekly.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ jobs:
155155
strategy:
156156
matrix:
157157
config:
158-
- { build: 'asan', cmake: '-DUSE_BLOSC=OFF' } # We never called blosc_destroy(), so disable blosc to silence these errors
159-
- { build: 'ubsan', cmake: '' } # Currently doesn't error, just reports all issues
158+
- { build: 'asan', components: 'core,test,nano,nanotest,axcore,axtest', cmake: '-DUSE_BLOSC=OFF' } # We never called blosc_destroy(), so disable blosc to silence these errors
159+
- { build: 'ubsan', components: 'core,test,axcore,axtest', cmake: '' } # Doesn't currently test NanoVDB
160160
#- { build: 'lsan', cmake: '' } # asan encompasses and includes lsan
161161
#- { build: 'tsan', cmake: '' } # requires full stack rebuild for valid results (including libc++)
162162
#- { build: 'msan', cmake: '' } # requires full stack rebuild for valid results (including libc++)
@@ -168,7 +168,7 @@ jobs:
168168
run: >
169169
./ci/build.sh -v
170170
--build-type=${{ matrix.config.build }}
171-
--components="core,test,nano,nanotest,axcore,axtest"
171+
--components="${{ matrix.config.components }}"
172172
--cargs=\"
173173
-DOPENVDB_CORE_STATIC=OFF
174174
-DOPENVDB_AX_STATIC=OFF

cmake/scripts/ubsan.supp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#################################################################################
2+
## This file is loaded by the Undefined Behaviour Sanitizer build for the unit ##
3+
## tests. It can be used to ignore various errors reported by the sanitizer. ##
4+
## This is especially useful with upstream issues (e.g. boost/tbb). For help ##
5+
## defining suppression rules, see: ##
6+
## https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html ##
7+
## The build is configured with CMAKE_BUILD_TYPE=ubsan. ##
8+
#################################################################################
9+
10+
##### Upstream #####
11+
12+
# Lots of warnings from TBB, ignore them
13+
alignment:tbb/concurrent_hash_map.h
14+
vptr:tbb/parallel_reduce.h
15+
vptr:tbb/task.h
16+
17+
##### OpenVDB #####
18+
19+
# The sOn/sOff static bool data held on the LeaffBuff<bool> objects can be
20+
# initialised to arbitrary true/false values. See the note in LeafBuffer.h
21+
enum:openvdb/tools/Activate.h
22+
# Some 2s complement tests, ignore the negative shifts
23+
# @todo Should address these
24+
shift-base:TestMultiResGrid.cc
25+
shift-base:openvdb/math/Coord.h
26+
27+
##### OpenVDB AX #####
28+
29+
# Ignore overflows reported from old OpenSimplexNoise
30+
signed-integer-overflow:openvdb_ax/math/OpenSimplexNoise.cc

openvdb/openvdb/math/Coord.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ class Coord
229229
template<int Log2N = 20>
230230
size_t hash() const
231231
{
232-
return ((1<<Log2N)-1) & (mVec[0]*73856093 ^ mVec[1]*19349663 ^ mVec[2]*83492791);
232+
const uint32_t* vec = reinterpret_cast<const uint32_t*>(mVec.data());
233+
return ((1<<Log2N)-1) & (vec[0]*73856093 ^ vec[1]*19349663 ^ vec[2]*83492791);
233234
}
234235

235236
private:

openvdb/openvdb/math/Math.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ template<typename Type>
872872
inline Type
873873
Truncate(Type x, unsigned int digits)
874874
{
875-
Type tenth = Pow(10,digits);
875+
Type tenth = static_cast<Type>(Pow(size_t(10), digits));
876876
return RoundDown(x*tenth+0.5)/tenth;
877877
}
878878

openvdb/openvdb/tree/LeafBuffer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,8 @@ class LeafBuffer<bool, Log2Dim>
446446
/// LeafNode::getValue() return a reference to a value. Since it's not possible
447447
/// to return a reference to a bit in a node mask, we return a reference to one
448448
/// of the following static values instead.
449+
///
450+
/// @todo Make these static inline with C++17
449451
template<Index Log2Dim> const bool LeafBuffer<bool, Log2Dim>::sOn = true;
450452
template<Index Log2Dim> const bool LeafBuffer<bool, Log2Dim>::sOff = false;
451453

openvdb/openvdb/unittest/CMakeLists.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,18 @@ if(USE_BLOSC OR OpenVDB_USES_BLOSC OR USE_ZLIB OR OpenVDB_USES_ZLIB)
208208
list(APPEND OPENVDB_CORE_DEPENDENT_LIBS ZLIB::ZLIB)
209209
endif()
210210

211-
target_link_libraries(vdb_test
212-
${OPENVDB_TEST_DEPENDENT_LIBS}
213-
)
211+
target_link_libraries(vdb_test ${OPENVDB_TEST_DEPENDENT_LIBS})
212+
add_test(NAME vdb_unit_test COMMAND $<TARGET_FILE:vdb_test> -v)
213+
214+
# For the undefined behaviour sanitizer, add the suppression file and
215+
# additional options
216+
217+
get_filename_component(PATH_TO_PROJECT_ROOT ${CMAKE_CURRENT_LIST_DIR} DIRECTORY)
218+
get_filename_component(PATH_TO_PROJECT_ROOT ${PATH_TO_PROJECT_ROOT} DIRECTORY)
219+
get_filename_component(PATH_TO_PROJECT_ROOT ${PATH_TO_PROJECT_ROOT} DIRECTORY)
220+
set(UBSAN_SUPRESSION_FILE ${PATH_TO_PROJECT_ROOT}/cmake/scripts/ubsan.supp)
221+
222+
set_tests_properties(vdb_unit_test PROPERTIES
223+
ENVIRONMENT
224+
"$<$<CONFIG:UBSAN>:UBSAN_OPTIONS=halt_on_error=1 report_error_type=1 suppressions=${UBSAN_SUPRESSION_FILE}>")
214225

215-
add_test(vdb_unit_test vdb_test -v)

openvdb/openvdb/unittest/TestCoord.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ TEST_F(TestCoord, testCoordBBox)
315315
EXPECT_EQ(count, n);
316316
}
317317

318-
{// bit-wise operations
319-
const openvdb::Coord min(-1,-2,3), max(2,3,5);
318+
{// bit-wise operations (note that the API doesn't define behaviour for shifting neg coords)
319+
const openvdb::Coord min(1,2,3), max(2,3,5);
320320
const openvdb::CoordBBox b(min, max);
321321
EXPECT_EQ(openvdb::CoordBBox(min>>1,max>>1), b>>size_t(1));
322322
EXPECT_EQ(openvdb::CoordBBox(min>>3,max>>3), b>>size_t(3));

openvdb/openvdb/unittest/TestIndexIterator.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ TEST_F(TestIndexIterator, testProfile)
321321

322322
{ // for loop
323323
ProfileTimer timer("ForLoop: sum");
324-
volatile int sum = 0;
324+
volatile uint64_t sum = 0;
325325
for (int i = 0; i < elements; i++) {
326326
sum += i;
327327
}
@@ -330,7 +330,7 @@ TEST_F(TestIndexIterator, testProfile)
330330

331331
{ // index iterator
332332
ProfileTimer timer("IndexIter: sum");
333-
volatile int sum = 0;
333+
volatile uint64_t sum = 0;
334334
ValueVoxelCIter iter(0, elements);
335335
for (; iter; ++iter) {
336336
sum += *iter;
@@ -350,7 +350,7 @@ TEST_F(TestIndexIterator, testProfile)
350350

351351
{ // manual value iteration
352352
ProfileTimer timer("ValueIteratorManual: sum");
353-
volatile int sum = 0;
353+
volatile uint64_t sum = 0;
354354
auto indexIter(leafNode.cbeginValueOn());
355355
int offset = 0;
356356
for (; indexIter; ++indexIter) {
@@ -366,7 +366,7 @@ TEST_F(TestIndexIterator, testProfile)
366366

367367
{ // value on iterator (all on)
368368
ProfileTimer timer("ValueIndexIter: sum");
369-
volatile int sum = 0;
369+
volatile uint64_t sum = 0;
370370
auto indexIter(leafNode.cbeginValueAll());
371371
IndexIter<LeafNode::ValueAllCIter, NullFilter>::ValueIndexIter iter(indexIter);
372372
for (; iter; ++iter) {

openvdb/openvdb/unittest/TestPointConversion.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ genPoints(const int numPoints, const double scale, const bool stride,
138138
AttributeWrapper<float>::Handle uniformHandle(uniform);
139139
AttributeWrapper<openvdb::Name>::Handle stringHandle(string);
140140

141-
int i = 0;
141+
size_t i = 0;
142142

143143
// loop over a [0 to n) x [0 to n) grid.
144144
for (int a = 0; a < n; ++a) {
@@ -164,14 +164,14 @@ genPoints(const int numPoints, const double scale, const bool stride,
164164

165165
if (stride)
166166
{
167-
xyzHandle.set(i, 0, i);
168-
xyzHandle.set(i, 1, i*i);
169-
xyzHandle.set(i, 2, i*i*i);
167+
xyzHandle.set(i, 0, static_cast<int>(i));
168+
xyzHandle.set(i, 1, static_cast<int>(i*i));
169+
xyzHandle.set(i, 2, static_cast<int>(i*i*i));
170170
}
171171

172172
// add points with even id to the group
173173
if ((i % 2) == 0) {
174-
group.setOffsetOn(i);
174+
group.setOffsetOn(static_cast<int>(i));
175175
stringHandle.set(i, /*stride*/0, "testA");
176176
}
177177
else {

0 commit comments

Comments
 (0)