Skip to content
Snippets Groups Projects

[cleanup] Remove warning about index access out of bounds.

Merged Robert K requested to merge cleanup/warning-refelemimpl into master
1 unresolved thread

Closes #35 (closed).

@simon.praetorius: This is the fix I had for the warnings, however, I'm not sure if this is the best way to fix this.

Edited by Simon Praetorius

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
252 252 {
253 253 for( int k = 0; k < dim-1; ++k )
254 254 jacobianTransposeds[ m+i ][ dim-codim-1 ][ k ] = -origins[ m+i ][ k ];
255 jacobianTransposeds[ m+i ][ dim-codim-1 ][ dim-1 ] = ct( 1 );
255 if( dim - codim - 1 >= 0 )
  • The same condition would also be useful in the line above (254), since also there the corresponding array element is accessed. Assuming the conditions in the assert() in the first line of that function hold, in the whole else-block it holds codim < dim. And thus dim - codim - 1 >= 0. We could thus also transform the whole else-block into an else if (codim < dim) block. But then we would have a missing return path for the potentially impossible case codim > dim.

    So, I was thinking. What if we transform the assert() checks in the top into proper exceptions that are always checked. Is this method anyhow time-critical? The introduced if-clause inside an inner loop is probably not performance-enhancing.

  • An alternative simple fix would be to change most else-clauses into else-if-clauses and add a final else { std::abort(); return 0; } or something. Maybe with an __unreachable() or similar attribute.

  • Simon Praetorius changed this line in version 2 of the diff

    changed this line in version 2 of the diff

  • I have uploaded the alternative simple fix into this branch.

  • Great, thanks. Merge at will.

  • Please register or sign in to reply
  • added 1 commit

    • cd91d194 - Handle all cases in referenceEmbeddings explicitly

    Compare with previous version

  • Robert K added 6 commits

    added 6 commits

    • cd91d194...a51164b6 - 4 commits from branch master
    • d231994d - [cleanup] Remove warning about index access out of bounds.
    • 3996749d - Handle all cases in referenceEmbeddings explicitly

    Compare with previous version

  • Robert K mentioned in merge request !238 (closed)

    mentioned in merge request !238 (closed)

  • Robert K approved this merge request

    approved this merge request

  • This MR fixes the warnings mentioned in #35 (closed), but not all warnings shown by gcc12 with -Wall. There are more places in other functions. It would be interesting whether there is an underlying pattern / source of the warning that we could fix instead of the symptoms only.

  • Simon Praetorius changed the description

    changed the description

  • Simon Praetorius mentioned in commit d1d63a4d

    mentioned in commit d1d63a4d

  • There are still a few warnings left. The question is: What happens in the case that dim == 0? Then codim must be 0 as well, due to 0 <= codim <= dim. This needs to be added as a check, i.e.,

    if( 0 < codim && codim <= dim ) // => dim > 0

    The second check should always be true, thus does not change the logic.

  • Maybe we should add a macro (into dune-common) DUNE_ASSERT_OR_ASSUME that is a simple assert in the debug case and an [[assume: ]] attribute (or something similar)` in the release case.

  • Simon Praetorius mentioned in merge request !239 (merged)

    mentioned in merge request !239 (merged)

  • Please register or sign in to reply
    Loading