Skip to content

-Wshift-count-negative in drivers/net/ethernet/sfc/ #1439

@nathanchance

Description

@nathanchance

After commit 1e688dd2a3d6 ("powerpc/bug: Provide better flexibility to WARN_ON/__WARN_FLAGS() with asm goto") in the powerpc tree, I see the following warnings with Debian's and SUSE's configs:

$ curl -LSso .config https://github.com/openSUSE/kernel-source/raw/master/config/ppc64le/default

# Remove pahole requirement
$ scripts/config -d BPF_PRELOAD -d DEBUG_INFO_BTF

$ make -skj"$(nproc)" ARCH=powerpc CC=clang CROSS_COMPILE=powerpc64le-linux-gnu- LLVM_IAS=0 olddefconfig drivers/net/ethernet/sfc/
drivers/net/ethernet/sfc/farch.c:985:10: warning: shift count is negative [-Wshift-count-negative]
        WARN_ON(EFX_QWORD_FIELD(*event, FSF_AZ_RX_EV_Q_LABEL) !=
        ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/sfc/bitfield.h:222:26: note: expanded from macro 'EFX_QWORD_FIELD'
#define EFX_QWORD_FIELD         EFX_QWORD_FIELD64
                                ^
drivers/net/ethernet/sfc/bitfield.h:173:2: note: expanded from macro 'EFX_QWORD_FIELD64'
        EFX_EXTRACT_QWORD64(qword, EFX_LOW_BIT(field),          \
        ^
drivers/net/ethernet/sfc/bitfield.h:149:3: note: expanded from macro 'EFX_EXTRACT_QWORD64'
        (EFX_EXTRACT64((qword).u64[0], 0, 63, low, high) &              \
         ^
drivers/net/ethernet/sfc/bitfield.h:134:2: note: expanded from macro 'EFX_EXTRACT64'
        EFX_EXTRACT_NATIVE(le64_to_cpu(element), min, max, low, high)
        ^
drivers/net/ethernet/sfc/bitfield.h:127:20: note: expanded from macro 'EFX_EXTRACT_NATIVE'
         (native_element) << ((min) - (low)))
                          ^
arch/powerpc/include/asm/bug.h:122:30: note: expanded from macro 'WARN_ON'
                                   __label_warn_on, "r" (x));   \
                                   ~~~~~~~~~~~~~~~~~~~~~~^~~
arch/powerpc/include/asm/bug.h:75:7: note: expanded from macro 'WARN_ENTRY'
                  ##__VA_ARGS__ : : label)
                  ~~^~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler_types.h:254:42: note: expanded from macro 'asm_volatile_goto'
#define asm_volatile_goto(x...) asm goto(x)
                                         ^
1 warning generated.
drivers/net/ethernet/sfc/falcon/farch.c:994:10: warning: shift count is negative [-Wshift-count-negative]
        WARN_ON(EF4_QWORD_FIELD(*event, FSF_AZ_RX_EV_Q_LABEL) !=
        ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/sfc/falcon/bitfield.h:222:26: note: expanded from macro 'EF4_QWORD_FIELD'
#define EF4_QWORD_FIELD         EF4_QWORD_FIELD64
                                ^
drivers/net/ethernet/sfc/falcon/bitfield.h:173:2: note: expanded from macro 'EF4_QWORD_FIELD64'
        EF4_EXTRACT_QWORD64(qword, EF4_LOW_BIT(field),          \
        ^
drivers/net/ethernet/sfc/falcon/bitfield.h:149:3: note: expanded from macro 'EF4_EXTRACT_QWORD64'
        (EF4_EXTRACT64((qword).u64[0], 0, 63, low, high) &              \
         ^
drivers/net/ethernet/sfc/falcon/bitfield.h:134:2: note: expanded from macro 'EF4_EXTRACT64'
        EF4_EXTRACT_NATIVE(le64_to_cpu(element), min, max, low, high)
        ^
drivers/net/ethernet/sfc/falcon/bitfield.h:127:20: note: expanded from macro 'EF4_EXTRACT_NATIVE'
         (native_element) << ((min) - (low)))
                          ^
arch/powerpc/include/asm/bug.h:122:30: note: expanded from macro 'WARN_ON'
                                   __label_warn_on, "r" (x));   \
                                   ~~~~~~~~~~~~~~~~~~~~~~^~~
arch/powerpc/include/asm/bug.h:75:7: note: expanded from macro 'WARN_ENTRY'
                  ##__VA_ARGS__ : : label)
                  ~~^~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler_types.h:254:42: note: expanded from macro 'asm_volatile_goto'
#define asm_volatile_goto(x...) asm goto(x)
                                         ^
1 warning generated.

Doing the math, I have no idea how it thinks the shift is going to be negative... (all of the macros are in drivers/net/ethernet/sfc/falcon/bitfield.h)

EF4_QWORD_FIELD(*event, FSF_AZ_RX_EV_Q_LABEL)

EFX_QWORD_FIELD64(*event, FSF_AZ_RX_EV_Q_LABEL)

EF4_EXTRACT_QWORD64(*event, EF4_LOW_BIT(FSF_AZ_RX_EV_Q_LABEL), EF4_HIGH_BIT(FSF_AZ_RX_EV_Q_LABEL))

EF4_EXTRACT_QWORD64(*event, FSF_AZ_RX_EV_Q_LABEL_LBN, FSF_AZ_RX_EV_Q_LABEL_LBN + FSF_AZ_RX_EV_Q_LABEL_WIDTH - 1)

EF4_EXTRACT_QWORD64(*event, 32, 32 + 5 - 1)

EF4_EXTRACT_QWORD64(*event, 32, 36)

EF4_EXTRACT_QWORD64(*event, 32, 36)

EF4_EXTRACT64((*event).u64[0], 0, 63, 32, 36) & EF4_MASK64((36) + 1 - (32))

EF4_EXTRACT64((*event).u64[0], 0, 63, 32, 36) & EF4_MASK64(5)

EF4_EXTRACT64((*event).u64[0], 0, 63, 32, 36) & EF4_MASK64(5)

EF4_EXTRACT_NATIVE(le64_to_cpu((*event).u64[0]), 0, 63, 32, 36) & EF4_MASK64(5)

which finally evaluates to

#define EF4_EXTRACT_NATIVE(native_element, min, max, low, high)		\
	((low) > (max) || (high) < (min) ? 0 :				\
	 (low) > (min) ?						\
	 (native_element) >> ((low) - (min)) :				\
	 (native_element) << ((min) - (low)))

EF4_EXTRACT_NATIVE(le64_to_cpu((*event).u64[0]), 0, 63, 32, 36)
	((32) > (63) || (36) < (0) ? 0 :				\
	 (32) > (0) ?						\
	 (le64_to_cpu((*event).u64[0])) >> ((32) - (0)) :				\
	 (le64_to_cpu((*event).u64[0])) << ((0) - (32)))

Maybe it is trying to evaluate the last branch as a shift of -32? I also do not see what the commit that exposed the problem has to do with this.

Metadata

Metadata

Labels

-Wshift-count-negative[ARCH] powerpcThis bug impacts ARCH=powerpc[BUG] llvmA bug that should be fixed in upstream LLVM[FIXED][LLVM] 14This bug was fixed in LLVM 14.xasm gotorelated to the implementation of asm goto

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions