From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2140) id 4EEB8385B51C; Thu, 23 Nov 2023 11:46:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4EEB8385B51C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1700739978; bh=X/NUFNkXFIMBFcDbirod/8N8uRjIBnPWvVdHenoleK0=; h=From:To:Subject:Date:From; b=ELEoPISg1btsE/ceV1bNsCNlXGJeR/mMjv4ld86BEoSSbNe5aLq2NRpxF08RlkWcM wWrnEDKa/BhNjWEDzJEKGWOxYLaGXV2HKZrpUtw7YmQoWlgev6kv5gXB3UtNX1Isuf lI6oLjfMCT/Y1StekjGX5k2/rf40QgHgQJ8vDIGI= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Alexandre Oliva To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/aoliva/heads/testme)] c++: mark short-enums as packed X-Act-Checkin: gcc X-Git-Author: Alexandre Oliva X-Git-Refname: refs/users/aoliva/heads/testme X-Git-Oldrev: 89f0a0c26b831593c31b0270b5e93e548e03ac3c X-Git-Newrev: 0d1b4440f1f62aedcc9fe206f1f6845509cecdef Message-Id: <20231123114618.4EEB8385B51C@sourceware.org> Date: Thu, 23 Nov 2023 11:46:18 +0000 (GMT) List-Id: https://gcc.gnu.org/g:0d1b4440f1f62aedcc9fe206f1f6845509cecdef commit 0d1b4440f1f62aedcc9fe206f1f6845509cecdef Author: Alexandre Oliva Date: Sun Nov 19 01:22:31 2023 -0300 c++: mark short-enums as packed Unlike C, C++ doesn't mark enums shortened by -fshort-enums as packed. This makes for undesirable warning differences between C and C++, e.g. c-c++-common/analyzer/null-deref-pr108251-smp_fetch_ssl_fc_has_early*.c triggers a warning about a type cast from a pointer to enum that, when packed, might not be sufficiently aligned. This change is not enough for that warning to trigger. The tree expression generated by the C++ front-end is also a little too complicated for us get to the base pointer. A separate patch takes care of that. for gcc/cp/ChangeLog * decl.cc (finish_enum_value_list): Set TYPE_PACKED if use_short_enum, and propagate it to variants. Diff: --- gcc/cp/decl.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 4b3791c4606..4200a007d9a 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -16893,6 +16893,12 @@ finish_enum_value_list (tree enumtype) /* If -fstrict-enums, still constrain TYPE_MIN/MAX_VALUE. */ if (flag_strict_enums) set_min_and_max_values_for_integral_type (enumtype, precision, sgn); + + if (use_short_enum) + { + TYPE_PACKED (enumtype) = use_short_enum; + fixup_attribute_variants (enumtype); + } } else underlying_type = ENUM_UNDERLYING_TYPE (enumtype);