From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id E93F93858C74 for ; Wed, 22 Nov 2023 18:12:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E93F93858C74 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E93F93858C74 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700676758; cv=none; b=U7hrjOLmTWrqBr6nbOd6pqc+qpOCk3DrCi0L0TJmh2K/sIGs5/oRjvoTm65wLLxbdpsl3Pq7E4a7JYQtJol0ijjd98TlOMjbraYZUyK9gyehP99KdVhTOkywLjBbNt4E/U6bJELFuiDBryJmVLnmrq11MIPwJ8e66FO9nSQTFXU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700676758; c=relaxed/simple; bh=JI/VmRkIBku3arHLbF+OyqxtLrtKbZJNIaqKC7smM4w=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=dvPiEALjhMMlrRQUFM2aAfiBKXwuZKWiGcBWyoFfqr1cbKo/f9imyaUw6558UA8DVyt0FLMXsxAIncQ7VUadxkKc8RGJH7m/WAcl/BxaQV5guY+DBhjOI1c69RqsoiLdgPCWBjFkpgKvRgoInTfGHxmo9KEmrVu0ErVPRzj9/bE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700676747; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u+NAZtLjR1mXak/STRDbsjbZKPDVVwnXwaeWbFbA0YY=; b=iQdrIziVVCWTGGJdUJ8AsnRj7hExxSF7URpKMuW2hOFINn3f4buTcutCLoYlLa9p0tmKZS wooMzjz5EuQrOrkY7vcVst4sM98jhhNL3vYiZ1JEfwGM7e2kmqWVbNE+SxpVu/QEy0OSHu b9mKUikr/J2TKJCiPbXPBMNXxf3pcU8= Received: from mail-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-594-mLMI8x0xMD-Rk7XLMLc4xA-1; Wed, 22 Nov 2023 13:12:26 -0500 X-MC-Unique: mLMI8x0xMD-Rk7XLMLc4xA-1 Received: by mail-ot1-f72.google.com with SMTP id 46e09a7af769-6d646a0d9bfso88893a34.3 for ; Wed, 22 Nov 2023 10:12:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700676745; x=1701281545; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=u+NAZtLjR1mXak/STRDbsjbZKPDVVwnXwaeWbFbA0YY=; b=H5X/UdqLRuR8IaCHQ7MM1mlyDRKij/MFic7SsxZIPjpq1+j9H9G+UkookIaXnhQRDP G7jwzANpunnX/QFprCR15XhkSm7Ph1yZ3S/0UoEkYfE1EJRC5P1DEgVBoroE5jB6ivZQ h3tEX9efB7UJ+hd4obY4Zlj5L9IVtv8+rlVjmTdeDIsLmdz0xIA/ICbl5x1ZEwCq6gTb Kf6aGEw8atZbAUtiIYCsScOuXTLZCzcLksI/tNs+GmezfdrlUlT39kkjnY7j3BAxY+s4 yjZwK4O8yksxZjnkPgsJbFvwIzfpqBR2DR/AcXtauAiZdfmOakWlHzihQ3TIkaWAsa6r 9k4A== X-Gm-Message-State: AOJu0Yy5/YgQfxSq88nn98GoW0x7L7mV8c/evy08kcbrrkZcxxaavdoY iu9KqcyAux2elgr9vhc1/ZXh9ynBR4aY/2EJDJXEBI9pK+AN06p0wnwmPGyAg7x4QL9UW1Chiho 4ZKaLEGqIYGL6U7zOJA== X-Received: by 2002:a05:6830:4412:b0:6d6:9ece:73e2 with SMTP id q18-20020a056830441200b006d69ece73e2mr4366413otv.17.1700676745379; Wed, 22 Nov 2023 10:12:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IEezxErFEj7yrmCmCSYfOlmL6FRKRxHIE9sxRogPOse1w9bZ5idmPyEVucJBE+x1bWzM3vcCA== X-Received: by 2002:a05:6830:4412:b0:6d6:9ece:73e2 with SMTP id q18-20020a056830441200b006d69ece73e2mr4366392otv.17.1700676745141; Wed, 22 Nov 2023 10:12:25 -0800 (PST) Received: from [192.168.1.145] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id ox21-20020a05620a829500b00767d4a3f4d9sm60690qkn.29.2023.11.22.10.12.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Nov 2023 10:12:24 -0800 (PST) Message-ID: <9d922575-6f5a-4458-b3dc-a25dce128e24@redhat.com> Date: Wed, 22 Nov 2023 13:12:22 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH #2/4] c++: mark short-enums as packed To: Alexandre Oliva Cc: gcc-patches@gcc.gnu.org, David Malcolm , Rainer Orth , Mike Stump , Nathan Sidwell , "H.J. Lu" References: <78e7499c-2278-44ff-8455-503e3690e3fd@redhat.com> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_SORBS_WEB,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no 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 11/22/23 03:17, Alexandre Oliva wrote: > 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. The enum is conceptually packed into a smaller integer type, sure. > 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? Since attribute ((packed)) has this meaning, it seems reasonable to set TYPE_PACKED to express it. > 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) The middle-end doesn't seem to use TYPE_PACKED for anything other than structure layout. >> 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? Exactly. If we want to warn about casting from pointer to less-aligned type to pointer to more-aligned type, that's already -Wcast-align=strict; whether the lower alignment is due to TYPE_PACKED seems irrelevant. The observation that the type-based warning is a subset of -Wcast-align=strict was previously made in the discussion of the patch for PR88928. And the motivating testcase for the warning was about converting from unaligned int* to aligned int*, not to a different type at all. And that warning doesn't involve TYPE_PACKED. The clang -Waddress-of-packed-member doesn't seem to include the type-based warning. >> 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? :-) I'm coming to the conclusion that your C++ patch is fine but we should remove the TYPE_PACKED warning from check_address_or_pointer_of_packed_member. And maybe add -Wcast-align=strict to -Wextra. Jason