https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124171

--- Comment #1 from Vineet Gupta <vineetg at gcc dot gnu.org> ---

(In reply to Vineet Gupta from comment #0)
> Currently gcc and clang differ in where function arguments promotion
> (zero/sign) happens: gcc does this in caller, while clang does this in
> callee: cfr [1][2]

There's obviously a snafu here. gcc currently does this in callee, while clang
in caller.

With following change, gcc handles argument promotion in caller as well.

diff --git a/gcc/config/bpf/bpf.h b/gcc/config/bpf/bpf.h

 #define PROMOTE_MODE(M, UNSIGNEDP, TYPE)       \
   do                                           \
     {                                          \
-      if (GET_MODE_CLASS (M) == MODE_INT       \
-         && GET_MODE_SIZE (M) < 8)             \
-       M = DImode;                             \
+      if ((M) == HImode || (M) == QImode)      \
+       (M) = SImode;                           \
     } while (0)

diff --git a/gcc/config/bpf/bpf.cc b/gcc/config/bpf/bpf.cc

+ #undef TARGET_PROMOTE_FUNCTION_MODE
+ #define TARGET_PROMOTE_FUNCTION_MODE \
+  default_promote_function_mode_always_promote

args_setup:
        r0 = *(u8 *) (r1+6)
        r2 = *(u16 *) (r1+4)
        r3 = *(u32 *) (r1+0)
        w2 = (s16) w2        <--
        w1 = (s8) w0         <--
        call    foo
        exit

args_consume:
        w1 += w2  
        r0 = r1
        w0 += w3
        exit

Reply via email to