Skip to content

Commit

Permalink
libdrgn: binary_search_tree: use a slightly different terminating loo…
Browse files Browse the repository at this point in the history
…p hack

Clang 16 warns that:

  ../../libdrgn/memory_reader.c:37:1: error: variable 'i' set but not used [-Werror,-Wunused-but-set-variable]
  DEFINE_BINARY_SEARCH_TREE_FUNCTIONS(drgn_memory_segment_tree, node,
  ^
  ../../libdrgn/binary_search_tree.h:454:7: note: expanded from macro 'DEFINE_BINARY_SEARCH_TREE_FUNCTIONS'
          long i;                                                                 \
               ^
  1 error generated.

Use a slightly different hack that uses i but generates the same code
(tested on GCC 13.2.1, GCC 8.5.0, Clang 16.0.6, and Clang 15.0.7).

Signed-off-by: Omar Sandoval <[email protected]>
  • Loading branch information
osandov committed Sep 13, 2023
1 parent 695bb54 commit 62bd77c
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions libdrgn/binary_search_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,6 @@ static inline struct tree##_iterator \
tree##_next_impl(struct tree##_iterator it) \
{ \
struct binary_tree_node *node = tree##_entry_to_node(it.entry); \
long i; \
\
if (node->right) { \
node = node->right; \
/* \
Expand All @@ -461,15 +459,15 @@ tree##_next_impl(struct tree##_iterator it) \
* (otherwise the counter would overflow, which is undefined \
* behavior). \
*/ \
for (i = 0;; i++) { \
for (long i = 1; i != 0; i++) { \
if (!node->left) \
break; \
node = node->left; \
} \
return (struct tree##_iterator){ tree##_node_to_entry(node), }; \
} \
\
for (i = 0;; i++) { \
for (long i = 1; i != 0; i++) { \
if (!node->parent || node != node->parent->right) \
break; \
node = node->parent; \
Expand Down

0 comments on commit 62bd77c

Please sign in to comment.