From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id 750C03858C29 for ; Wed, 22 Nov 2023 08:17:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 750C03858C29 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 750C03858C29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700641070; cv=none; b=d3VGbqEtK4K5EwH90EA1SEDfeWcPREBlPyMypFu9x/sqtgt1SnuLbY2ZK41mUA733pMz9CaMWxurOQLYh/ACbwp7Mj3OxP6ZtFu+L1BhuWlVBJQ6PjqeadNyQ7X2aQ2n9O3ofZj/3gtpz+PU5bZ8/3znQtjjYRLI5+HDDe1bTJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700641070; c=relaxed/simple; bh=Wnv1Xn6rEqmeEMt6RWS63ABjSQ1rV6Og5UxVxFL0nk0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=DykMjd5j28/q9SXnbEfrvZDXRjGlrWSLmwcvmMpseGEz/yIJSC6pVkuy9JPx4mYnZBSXonMFaXj3qgAfLhfLq/991Q6bACBmiWzd8adZlNeirnvhEEUXoLLVOa2XVw1jhSbljF4BI7SKR+U/O7jXKTY0oSz0F0eWUsLaqyUFVo0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1cf7a8ab047so1662395ad.1 for ; Wed, 22 Nov 2023 00:17:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1700641067; x=1701245867; 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=uSwQI7XgW+TAlkL85eYAXt8/78N8AwZnj/lWrTZwybE=; b=ORCYuM7tPWMxTLvKSycvhH9YzUq6F87JNIEm9Ap13bMgDwhIa/VST9Of9Os64kn9Ze T0l47XtcxNLE+9KldpVHyWGEZTnvkS41PkEBINqir/S9qV0+xonQfCS3OQozDR3YLEyq sX/QjSdoMqYnn1iefPJkLM4FTooZL/9J1VqQR6i1HmHcYQBi0Yw9dJi2zM7PpOj2Zrcy 0sYu6X9/v6JSiV/qx5PyiyKvuhbsMTfuoncWXVxTceL4Jr+QTqCbq6Y+bKRZSCZ8vd0W eQ8OA5NwXMvcD8jUSdYGYBjY0UPsqkWmbvRNJ3R4w/E1J9lSeXLW/RSvkyZUga6YQmL+ faFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700641067; x=1701245867; 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=uSwQI7XgW+TAlkL85eYAXt8/78N8AwZnj/lWrTZwybE=; b=e8kXZ2/VbFWJsyVumMo+o7fBud7Y/kIR2IOM1WUCgS3z1WNHnK5S24ABRwN6WZFQpu d6mTiXUnFXeUNGf67UsSfKtnFcc0Uz1kTAwGA1PtaPjXTFwWV2/KhWmdhpyY36+n2qnk StTvQ/yKYjj3mxejViO1BJuFxZKMoA2j3SvxwbNl0pkfIPgOW/ZG9dNEm4U0sK4zUWlR NqgM2h57BHqO7z6fMMajCVHIzldZW/5c+0NciEFQIJJ3NO2l/PEi8SnocbJGuqaIJtao QjtmdduzMhRGu5CMA+18FtxQB6W6EXjs8GHMoL+TW6PCYlSzHiDXz+azFKY6O8deqnyh UbXw== X-Gm-Message-State: AOJu0YzVnyNg2SW7gxQBvdkQ/AxtRMl0hAb2U9Z7Gmq+dSM5X5aQo4SX y/86OOd270rTvt5RI+43hmkmmw== X-Google-Smtp-Source: AGHT+IGwpFSX+x97jIidlkogdFsgK35j+R91WAaN2oHxrswVvZhkBXeb5Y8RmwQWeIfkOBjK27+9eQ== X-Received: by 2002:a17:902:f690:b0:1b8:b382:f6c3 with SMTP id l16-20020a170902f69000b001b8b382f6c3mr1877225plg.13.1700641067321; Wed, 22 Nov 2023 00:17:47 -0800 (PST) Received: from free.home ([2804:7f1:2080:6a8b:457b:26a6:ad8e:d7f8]) by smtp.gmail.com with ESMTPSA id p4-20020a170902bd0400b001b850c9d7b3sm9154035pls.249.2023.11.22.00.17.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 00:17:46 -0800 (PST) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 3AM8HZct217793 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 22 Nov 2023 05:17:35 -0300 From: Alexandre Oliva To: Jason Merrill Cc: gcc-patches@gcc.gnu.org, David Malcolm , Rainer Orth , Mike Stump , Nathan Sidwell , "H.J. Lu" Subject: Re: [PATCH #2/4] c++: mark short-enums as packed Organization: Free thinker, does not speak for AdaCore References: <78e7499c-2278-44ff-8455-503e3690e3fd@redhat.com> Date: Wed, 22 Nov 2023 05:17:35 -0300 In-Reply-To: <78e7499c-2278-44ff-8455-503e3690e3fd@redhat.com> (Jason Merrill's message of "Mon, 20 Nov 2023 14:55:52 -0500") 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=-4.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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: On Nov 20, 2023, Jason Merrill wrote: > I think the warning is wrong here. Interesting... Yeah, your analysis makes perfect sense. Still, we're left with a divergence WRT the TYPE_PACKED status of enum types between C and C++. It sort of kind of makes sense to mark short enums as packed, because, well, they are. Even enum types with explicit attribute packed, that IIUC uses the same underlying type selection as -fshort-enums, IIRC are not be marked with TYPE_PACKED in C++, at least not at the place where I proposed to set it. Do you consider that behavior correct? Even if the warning happens to be buggy in this regard, it is at best (or worst) accessory to this patch, in that it makes that difference between languages apparent, and I worry that there might be other middle end tests involving TYPE_PACKED that would get things different in C vs C++. (admittedly, I haven't searched for occurrences of TYPE_PACKED in the tree, but I could, to alleviate my concerns, in case there's a decision to keep them different) > In the analyzer testcase, we have a cast from an > enum pointer that we don't know what it points to, and even if it did > point to the obj_type member of struct connection, that wouldn't be a > problem because it's at offset 0. Maybe I misunderstand the point of the warning, but ISTM that the circumstance it's warning about is real: the member is not as aligned as the enclosing struct, so the cast is risky. Now, I suppose the idiom of finding the enclosing struct given a member is common enough that we don't want to warn about it in general. I'm not sure what makes packed structs special in this regard, though. I don't really see much difference, more laxly-aligned fields seem equally warn-worthy, whether the enclosing struct is packed or not, but what do I know? > Also, -fshort-enums has nothing to do with structure packing *nod*, it's about packing of the enum type itself. It is some sort of a degenerated aggregate type ;-) But yeah, I guess it doesn't fit the circumstance the warning was meant to catch, and the fact that in C is does is a consequence of marking C short enums as TYPE_PACKED. Which might be a bug in C. But wouldn't it be a bug in C++ if an enum with attribute packed weren't markd as TYPE_PACKED? Or is TYPE_PACKED really meant to say something about the enclosing struct rather than about the enclosed type itself? (am I getting too philosophical here? :-) Thanks, -- 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