From 935544d7e6a32d9e7986bfff6f42f43a7bc89386 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Thu, 6 Jul 2023 17:16:06 -0500 Subject: [PATCH] matrix_free/fe_evaluation.h: avoid a warning with g++-13 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit g++-13 is a bit too eager to warn about an array bounds violation here after its optimizer pass introduced a `__builtin_memset()`: ``` In file included from include/deal.II/matrix_free/operators.h:30, from include/deal.II/numerics/vector_tools_project.templates.h:36, from source/numerics/vector_tools_project_qpmf.cc:17: In member function ‘void dealii::FEEvaluationBase<...>: inlined from ‘void dealii::FEEvaluationBase<...>: include/deal.II/matrix_free/fe_evaluation.h:3937:20: warning: ‘void* __builtin_memset(void*, int, long unsigned int)’ offset [20, 1020] is out of the bounds [0, 16] of object ‘dof_indices’ with type ‘std::array’ [-Warray-bounds=] 3937 | dof_indices[v] = numbers::invalid_unsigned_int; | ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` which is a bit silly as the statement reads: ``` // implied Assert(n_filled_lanes <= n_lanes, ExcInternalError()); for (unsigned int v = n_filled_lanes; v < n_lanes; ++v) dof_indices[v] = numbers::invalid_unsigned_int; ``` So instead let's simply initialize all elements of `dof_indices` to `numbers::invalid_unsigned_int` via `std::fill` instead. I doubt that this has much performance influence in practice as it gets replaced by a `__builtin_memset()` right away. --- include/deal.II/matrix_free/fe_evaluation.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/deal.II/matrix_free/fe_evaluation.h b/include/deal.II/matrix_free/fe_evaluation.h index d78a017fe7..095dddd9cb 100644 --- a/include/deal.II/matrix_free/fe_evaluation.h +++ b/include/deal.II/matrix_free/fe_evaluation.h @@ -3917,7 +3917,11 @@ FEEvaluationBase:: } std::array dof_indices; + std::fill(dof_indices.begin(), + dof_indices.end(), + numbers::invalid_unsigned_int); + Assert(n_filled_lanes <= n_lanes, ExcInternalError()); for (unsigned int v = 0; v < n_filled_lanes; ++v) { Assert(mask[v] == false || cells[v] != numbers::invalid_unsigned_int, @@ -3933,9 +3937,6 @@ FEEvaluationBase:: dof_indices[v] = numbers::invalid_unsigned_int; } - for (unsigned int v = n_filled_lanes; v < n_lanes; ++v) - dof_indices[v] = numbers::invalid_unsigned_int; - // In the case with contiguous cell indices, we know that there are no // constraints and that the indices within each element are contiguous if (use_vectorized_path) -- 2.39.5