From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 36F8E3857BB7 for ; Mon, 20 Nov 2023 02:33:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 36F8E3857BB7 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 36F8E3857BB7 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::429 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700447625; cv=none; b=EE4YTu5HhaGbj/XMgZrBFzo4+gPT3LszQQ3lGJprbJYQtXykAB1jXtHXtR576YPh/zE9vwFxideTUJ5pet4fx/2px7m5KBP4cnw6TSeIkzQtpTPJKSlLt+GMBamPEtCGEToAjk7CisvkD2cXG81obGSS0q6zbOrwNboGO6DhkyI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700447625; c=relaxed/simple; bh=fFSwlRpqZy2YZ5y+9DyE++R/7NYhFMLY0SgRre/2uk4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=H5t/qH6rul18M3L/xLh5HzBVE95HwXJaOdSI8zBKjkPqGqTOPoSjLUV6MhQzq3JJ9KAF26VkA8oH7DG+OhLh7k9s+w7mHuLl0FN9Vc10soZ6npOJe5/jT95xyDrQg0sDm9UHT6YaMhAHYqDU4RCVFs+71VncqIJtzYPaPx7BBkA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6c10f098a27so3069901b3a.2 for ; Sun, 19 Nov 2023 18:33:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1700447623; x=1701052423; darn=gcc.gnu.org; h=mime-version:user-agent:message-id:in-reply-to:date:references :organization:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to; bh=sjV+lA+/ek1iEcP6PsXdbnBMKqZeCsY+IQONFEyjPqg=; b=JEUlfseZLuEL5uC8SZKVbVMvVw44dmyg9iIOC4g81KD+SoSzUvcShQ/1wEBvthZFbF Tkn0qdbr/sVN8ZSmxVzJdwyxFNJQe+w3ooc3TyEGRmtMTyA+hPLuz+RlXXCv5K5K2VPW 4rry0f8LZJFpZRuYcf4BgxRC2w9QxZ1SXumZWNsVoYHvEgaKLgT0q9wYSP+Lc622WSIP QvqMVSf8Fu+YeBBzG8cPflrPHJY8uekckUwffEFju7nZWJiOEQjV5OKN6+Q900oAow/v 24gynpa9RETKifb6s+Sd5AXqX0KvCI69Sq7lh7VcpYIi8wdeMB9NMugQbUCH2SvC8YG2 FbGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700447623; x=1701052423; h=mime-version:user-agent:message-id:in-reply-to:date:references :organization:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sjV+lA+/ek1iEcP6PsXdbnBMKqZeCsY+IQONFEyjPqg=; b=WALufw/eN6zU/SlY5pp917dqTpMmjJtA69+VRIeyCNuevHsYMUISX6kp8Xb2ItB/0S 0IdAORJ1aSF2CQxSbLYqw95e6m4dcjO4uG9kyxISVKlaeuVe0opoJBd4hxSu/Op5GkCu Gmu3HYLfjLIT4z/V81w+Plow3KjK0ojN3jtWh75mbowTnaVRhRmvxr5kf9jtuyXNII/Y 32o54Q8jxbptYl3XfCqFcUR53wCWqWvz8L8LEXcT+wLbQj5cSuIw+aRhdRvqrZs5CYZI 1M5Y2gP7bu/coeq317ADT5bZsVWHx558bZT16moijjSKkzwlu9Py4Eqfl4TUWjy9AX7N ahMw== X-Gm-Message-State: AOJu0YwwRX7T6DTPg9REKOyQQVSkBtgRGCF3JlU6CsB0Q1J6APXMzQCs e+/pwxsgMuqr66dCAFwSG3hpWe2uFhxa9Ap7CgQ= X-Google-Smtp-Source: AGHT+IFhX3dyMeNmM9MTIhHjV2pUgcqk4qh9ZR6D/nIKuikAJEXBDIQphJYRilGir9rrnUU6N3aU1Q== X-Received: by 2002:a05:6a20:4f92:b0:186:7988:c747 with SMTP id gh18-20020a056a204f9200b001867988c747mr3615775pzb.19.1700447623094; Sun, 19 Nov 2023 18:33:43 -0800 (PST) Received: from free.home ([2804:7f1:2080:51b3:d545:cbee:40c0:c7a7]) by smtp.gmail.com with ESMTPSA id w20-20020a170902d71400b001c726147a45sm4916685ply.190.2023.11.19.18.33.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Nov 2023 18:33:42 -0800 (PST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 3AK2XYDC146605 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sun, 19 Nov 2023 23:33:34 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Cc: David Malcolm , Rainer Orth , Mike Stump , Jason Merrill , Nathan Sidwell Subject: [PATCH #2/4] c++: mark short-enums as packed Organization: Free thinker, does not speak for AdaCore References: Date: Sun, 19 Nov 2023 23:33:34 -0300 In-Reply-To: (Alexandre Oliva's message of "Sun, 19 Nov 2023 04:36:23 -0300") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,WEIRD_QUOTING autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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. Regstrapped on x86_64-linux-gnu, also tested on arm-eabi with default cpu on trunk, and with tms570 on gcc-13. Ok to install? for gcc/cp/ChangeLog * decl.cc (finish_enum_value_list): Set TYPE_PACKED if use_short_enum, and propagate it to variants. --- gcc/cp/decl.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 038c5ab71f201..f6d5645d5080f 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -16881,6 +16881,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); -- Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/ Free Software Activist GNU Toolchain Engineer More tolerance and less prejudice are key for inclusion and diversity Excluding neuro-others for not behaving ""normal"" is *not* inclusive