Linux: -Wordered-compare-function-pointers in include/trace/events/xen.h

Created on 17 Sep 2018  路  8Comments  路  Source: ClangBuiltLinux/linux

In file included from arch/x86/xen/trace.c:21:
In file included from ./include/trace/events/xen.h:475:
In file included from ./include/trace/define_trace.h:96:
In file included from ./include/trace/trace_events.h:467:
./include/trace/events/xen.h:69:7: warning: ordered comparison of function pointers ('xen_mc_callback_fn_t' (aka 'void (*)(void *)') and
      'xen_mc_callback_fn_t') [-Wordered-compare-function-pointers]
                    __field(xen_mc_callback_fn_t, fn)
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./include/trace/trace_events.h:415:29: note: expanded from macro '__field'
#define __field(type, item)     __field_ext(type, item, FILTER_OTHER)
                                ^
./include/trace/trace_events.h:401:6: note: expanded from macro '__field_ext'
                                 is_signed_type(type), filter_type);    \
                                 ^
./include/linux/trace_events.h:536:44: note: expanded from macro 'is_signed_type'
#define is_signed_type(type)    (((type)(-1)) < (type)1)
                                              ^
note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
./include/trace/trace_events.h:77:16: note: expanded from macro 'TRACE_EVENT'
                             PARAMS(tstruct),                  \
                             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
./include/linux/tracepoint.h:97:25: note: expanded from macro 'PARAMS'
#define PARAMS(args...) args
                        ^
./include/trace/trace_events.h:455:2: note: expanded from macro 'DECLARE_EVENT_CLASS'
        tstruct;                                                        \
        ^~~~~~~
1 warning generated.
-Wordered-compare-function-pointers [ARCH] x86_64 [BUG] linux [FIXED][LINUX] 5.5

Most helpful comment

All 8 comments

comparisons of pointers to different objects or past 1 plus the end of an object is undefined behavior. https://wiki.sei.cmu.edu/confluence/display/c/ARR36-C.+Do+not+subtract+or+compare+two+pointers+that+do+not+refer+to+the+same+array has some more info.

Surely, this can't be the only place that someone is trying to trace a callback member/function pointer...

-           __field(xen_mc_callback_fn_t, fn)
+           __field(void*, fn)

assuming this isn't warning for the void*.

Steven Rostedt via PM:

Please do not send personal emails with patches. They should always Cc
a mailing list, specifically LKML.
...
As for the fix, this is more of a work around, find a better fix,
either update the is_signed_type() that can handle function types, or
fix clang.

Possible ways to fix the problem with some considerations:

Fix is_signed_type()

While this seems to be an easy fix, things get harder duo to compiler and C restrictions:

  1. If we want to have a similar comparison like we already have, then we are not allowed to use any relational operator besides == and !=. Otherwise we would raise the same warning again.
  2. Arithmetic and bit manipulation is forbidden for function pointers.
  3. @bulwahn stated via pm

Create some functionality to check if type is any pointer type and make that a precondition that clang understands and hence knows is_signed_type would not be evaluated for pointer type.

Problem: we need to figure out if we can check for pointer type and if the warning disappears because the context is considered by constant propagation before the warning is considered.

Force clang to ignore warning

Disable warning via pragmas. Problem: Healing symptom, not cause.

Fix clang:

All developers would benefit from a fix in clang but unfortunately a fix for this warning could be really hard to implement duo to the fact that the compiler has to understand the semantic of this expression. Other possibility could be to introduce a new is_signed_type pragma in the compiler. @nickdesaulniers Is this possible?

Still occurs with kernel 5.3.1 and LLVM/clang-9.0.0 on x86_64

BUILDSTDERR: In file included from ./include/trace/trace_events.h:467:
BUILDSTDERR: ./include/trace/events/xen.h:69:7: warning: ordered comparison of function pointers ('xen_mc_callback_fn_t' (aka 'void (*)(void *)') and 'xen_mc_callback_fn_t') [-Wordered-compare-function-pointers]
BUILDSTDERR:                     __field(xen_mc_callback_fn_t, fn)
BUILDSTDERR:                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BUILDSTDERR: ./include/trace/trace_events.h:415:29: note: expanded from macro '__field'
BUILDSTDERR: #define __field(type, item)     __field_ext(type, item, FILTER_OTHER)
BUILDSTDERR:                                 ^
BUILDSTDERR: ./include/trace/trace_events.h:401:6: note: expanded from macro '__field_ext'
BUILDSTDERR:                                  is_signed_type(type), filter_type);    \
BUILDSTDERR:                                  ^
BUILDSTDERR: ./include/linux/trace_events.h:549:44: note: expanded from macro 'is_signed_type'
BUILDSTDERR: #define is_signed_type(type)    (((type)(-1)) < (type)1)
BUILDSTDERR:                                               ^
BUILDSTDERR: note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
BUILDSTDERR: ./include/trace/trace_events.h:77:16: note: expanded from macro 'TRACE_EVENT'
BUILDSTDERR:                              PARAMS(tstruct),                  \
BUILDSTDERR:                              ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
BUILDSTDERR: ./include/linux/tracepoint.h:95:25: note: expanded from macro 'PARAMS'
BUILDSTDERR: #define PARAMS(args...) args
BUILDSTDERR:                         ^
BUILDSTDERR: ./include/trace/trace_events.h:455:2: note: expanded from macro 'DECLARE_EVENT_CLASS'
BUILDSTDERR:         tstruct;                                                        \
BUILDSTDERR:         ^~~~~~~
BUILDSTDERR: 1 warning generated.
Was this page helpful?
0 / 5 - 0 ratings