[PATCH 00/12] fixes for enum's base type

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This series contains fixes for several problems related
to the base type of enums (maybe better known as the
underlying type). One of the symptoms is invalid warnings
about truncated constants:
  "cast truncates bits from constant value (8000000000000000 becomes 0)"

With this series, the rules for an enum's base type become:
1) if all enumerators are of the same restricted type,
   then the base type is this restricted type
2) if all the enumerators have an (non-restricted)
   integer type, then the base type will be the
   smallest integer type at least as big as 'int' and
   able to hold all the values of the enum (so, first
   int, unsigned int, long, unsigned int, ...).
3) an enumerator without initializer is considered as
   being a non-restricted type.
4) non-integer or non-constant initializers are invalid
5) temporary, if the enumerators mix restricted and
   non-restricted types, each enumerator keep their
   original type and a warning is issued.
   Note: This is to keep compatibility with (a few)
         such uses in the kernel.
6) otherwise, the enum is invalid.

The differences with GCC are:
a) GCC favor unsigned types for enum's base types
b) irrespectively of a) GCC force to 'int' enumerators
   that fit in a int (the justification being to avoid
   promotions to unsigned types when comparing such
   enumerators with (signed) integers).
   So, yes, an enumerator will either have the same type
   as the enum base type or 'int' if it fit in an 'int'.


This series is available for review & testing in the Git repository at:

  git://github.com/lucvoo/sparse-dev.git fix-enum-type

for you to fetch changes up to 19483120177ae37f3780ca8e9fa7c211717e2ad3:

  enum: rewrite bound checking (2018-09-08 00:43:24 +0200)

----------------------------------------------------------------
Luc Van Oostenryck (12):
      doc: is_int_type() returns false for SYM_RESTRICTs
      enum: add testcase for UB in oversized shift
      enum: fix UB when rshifting by full width
      enum: add testcase for type of enum members
      enum: add testcase for base & enumerator type
      enum: fix cast_enum_list()
      enum: use the smallest type that fit
      enum: use the values to determine the base type
      enum: only warn (once) when mixing bitwiseness
      enum: warn when mixing different restricted types
      enum: warn on bad enums
      enum: rewrite bound checking

 parse.c                          | 118 +++++++++++++++++++--------------------
 symbol.h                         |   5 ++
 validation/bug-rshift-ub.c       |  16 ++++++
 validation/enum-base-type.c      |  28 ++++++++++
 validation/enum-bitwise-bad.c    |  20 +++++++
 validation/enum-bitwise-mixed.c  |  29 ++++++++++
 validation/enum-bitwise.c        |  19 +++++++
 validation/enum-bounds.c         |  23 ++++++++
 validation/enum-init-constness.c |   9 +++
 validation/enum-invalid.c        |  11 ++++
 validation/enum-min-size.c       |  29 ++++++++++
 validation/enum-same-type.c      |  14 +++++
 validation/enum-sign-gcc.c       |  63 +++++++++++++++++++++
 validation/enum-typecheck.c      |  39 +++++++++++++
 14 files changed, 362 insertions(+), 61 deletions(-)
 create mode 100644 validation/bug-rshift-ub.c
 create mode 100644 validation/enum-base-type.c
 create mode 100644 validation/enum-bitwise-bad.c
 create mode 100644 validation/enum-bitwise-mixed.c
 create mode 100644 validation/enum-bitwise.c
 create mode 100644 validation/enum-bounds.c
 create mode 100644 validation/enum-init-constness.c
 create mode 100644 validation/enum-invalid.c
 create mode 100644 validation/enum-min-size.c
 create mode 100644 validation/enum-same-type.c
 create mode 100644 validation/enum-sign-gcc.c
 create mode 100644 validation/enum-typecheck.c



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux