Re: [PATCH 02/10] compiler.h: drop fallback overflow checkers

From: Nathan Chancellor
Date: Tue Sep 14 2021 - 12:04:48 EST


On 9/14/2021 8:33 AM, Nick Desaulniers wrote:
On Fri, Sep 10, 2021 at 5:04 PM Nathan Chancellor <nathan@xxxxxxxxxx> wrote:

On Fri, Sep 10, 2021 at 04:40:39PM -0700, Nick Desaulniers wrote:
diff --git a/include/linux/overflow.h b/include/linux/overflow.h
index 0f12345c21fb..4669632bd72b 100644
--- a/include/linux/overflow.h
+++ b/include/linux/overflow.h
@@ -6,12 +6,9 @@
#include <linux/limits.h>

/*
- * In the fallback code below, we need to compute the minimum and
- * maximum values representable in a given type. These macros may also
- * be useful elsewhere, so we provide them outside the
- * COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW block.
- *
- * It would seem more obvious to do something like
+ * We need to compute the minimum and maximum values representable in a given
+ * type. These macros may also be useful elsewhere. It would seem more obvious
+ * to do something like:
*
* #define type_min(T) (T)(is_signed_type(T) ? (T)1 << (8*sizeof(T)-1) : 0)
* #define type_max(T) (T)(is_signed_type(T) ? ((T)1 << (8*sizeof(T)-1)) - 1 : ~(T)0)

The signed and type macros right below this comment can be removed as
they were only used in the !COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW case.

Did you check for users outside of this header?

I see:
type_min ->
lib/test_scanf.c:189
include/rdma/uverbs_ioctl.h:951
include/rdma/uverbs_ioctl.h:973

type_max ->
lib/test_scanf.c:189
lib/test_scanf.c:190
include/rdma/uverbs_ioctl.h:952
include/rdma/uverbs_ioctl.h:962
include/rdma/uverbs_ioctl.h:974
include/rdma/uverbs_ioctl.h:985

is_signed_type has many many users throughout the kernel.

Or were you referring to other defines?

Ah, I did not even think to look outside this file, I figured they were intended to only be used here :/ good catch.


Also applies to the tools/ version.

The version in tools/ should probably be "refreshed" ie. copy+pasted
over. Why there is a separate copy under tools/...


Yes, they probably should, as I noted in commit d0ee23f9d78b ("tools: compiler-gcc.h: Guard error attribute use with __has_attribute"). At the same time, I don't really want to do it :)

Cheers,
Nathan