Skip to content

False positive dangling-pointer warning on wait_queue_add #40

@apsun

Description

@apsun

Occurs with GCC only when LTO is disabled and using opt level O1 and above.

In file included from sb16.c:6:
In function ‘list_add’,
    inlined from ‘wait_queue_add’ at wait.h:99:5,
    inlined from ‘sb16_read’ at sb16.c:183:12:
list.h:87:16: error: storing the address of local variable ‘__wait’ in ‘sb16_write_queue.next’ [-Werror=dangling-pointer=]
   87 |     head->next = node;
      |     ~~~~~~~~~~~^~~~~~
In file included from sb16.c:11:
sb16.c: In function ‘sb16_read’:
wait.h:22:17: note: ‘__wait’ declared here
   22 |     wait_node_t __wait;                                                   \
      |                 ^~~~~~
wait.h:50:5: note: in expansion of macro ‘WAIT_IMPL’
   50 |     WAIT_IMPL(expr, queue, nonblocking, true)
      |     ^~~~~~~~~
sb16.c:183:12: note: in expansion of macro ‘WAIT_INTERRUPTIBLE’
  183 |     return WAIT_INTERRUPTIBLE(
      |            ^~~~~~~~~~~~~~~~~~
sb16.c:63:20: note: ‘sb16_write_queue’ declared here
   63 | static list_define(sb16_write_queue);
      |                    ^~~~~~~~~~~~~~~~
list.h:21:12: note: in definition of macro ‘list_define’
   21 |     list_t name = { .prev = &(name), .next = &(name) }
      |            ^~~~
In function ‘list_add’,
    inlined from ‘wait_queue_add’ at wait.h:99:5,
    inlined from ‘sb16_write’ at sb16.c:229:14:
list.h:87:16: error: storing the address of local variable ‘__wait’ in ‘sb16_write_queue.next’ [-Werror=dangling-pointer=]
   87 |     head->next = node;
      |     ~~~~~~~~~~~^~~~~~
sb16.c: In function ‘sb16_write’:
wait.h:22:17: note: ‘__wait’ declared here
   22 |     wait_node_t __wait;                                                   \
      |                 ^~~~~~
wait.h:50:5: note: in expansion of macro ‘WAIT_IMPL’
   50 |     WAIT_IMPL(expr, queue, nonblocking, true)
      |     ^~~~~~~~~
sb16.c:229:14: note: in expansion of macro ‘WAIT_INTERRUPTIBLE’
  229 |     nbytes = WAIT_INTERRUPTIBLE(
      |              ^~~~~~~~~~~~~~~~~~
sb16.c:63:20: note: ‘sb16_write_queue’ declared here
   63 | static list_define(sb16_write_queue);
      |                    ^~~~~~~~~~~~~~~~
list.h:21:12: note: in definition of macro ‘list_define’
   21 |     list_t name = { .prev = &(name), .next = &(name) }
      |            ^~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions