From 4d567c8e07e15ba3acb8603cbbec1fb1bc89b353 Mon Sep 17 00:00:00 2001 From: Jason Lowe Date: Wed, 26 Aug 2020 15:56:04 -0500 Subject: [PATCH 1/2] Evaluate CUDA_CUB_RET_IF_FAIL macro argument only once --- thrust/system/cuda/detail/core/util.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/thrust/system/cuda/detail/core/util.h b/thrust/system/cuda/detail/core/util.h index a2c87772e..df2ffb050 100644 --- a/thrust/system/cuda/detail/core/util.h +++ b/thrust/system/cuda/detail/core/util.h @@ -652,7 +652,10 @@ namespace core { } #define CUDA_CUB_RET_IF_FAIL(e) \ - if (cub::Debug((e), __FILE__, __LINE__)) return e; + do { \ + auto const error = (e); \ + if (cub::Debug(error, __FILE__, __LINE__)) return error; \ + } while(0); // uninitialized // ------- From 6fcf17cd932acbb05c932ffbb986a58e06d39ab4 Mon Sep 17 00:00:00 2001 From: Jason Lowe Date: Wed, 26 Aug 2020 16:55:37 -0500 Subject: [PATCH 2/2] Use a scope block for CUDA_CUB_RET_IF_FAIL macro --- thrust/system/cuda/detail/core/util.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/thrust/system/cuda/detail/core/util.h b/thrust/system/cuda/detail/core/util.h index df2ffb050..ea4ed6400 100644 --- a/thrust/system/cuda/detail/core/util.h +++ b/thrust/system/cuda/detail/core/util.h @@ -652,10 +652,10 @@ namespace core { } #define CUDA_CUB_RET_IF_FAIL(e) \ - do { \ + { \ auto const error = (e); \ if (cub::Debug(error, __FILE__, __LINE__)) return error; \ - } while(0); + } // uninitialized // -------