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.129.124]) by sourceware.org (Postfix) with ESMTPS id 89C943858D33 for ; Mon, 20 Nov 2023 19:55:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 89C943858D33 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 89C943858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700510158; cv=none; b=fS/mEbS7T67PX03tzVIbtyTPcskOWLr5h8pg2lRHShmZ/28fXUp+GVNw8TTiOI5CEGsoDs2SgRynFeqnBEuWH/C62P//HWPWxL2E/g/Y8dh2kTLO3pYtNTP7PSf30/QephgEbV5BVAG9hX651q2+jKBdeHbS0b87cr/Nte2LhvQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700510158; c=relaxed/simple; bh=68EaRzhzLD1S1HiNjD/6in/EEv15cnOd8Kqzl70xjWg=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=xuMQBvrE3z2hJ9LGWJbLb+s1wlbWKwQnYzO+4/VGASwDypVZ3JCHoRb1lil7SIoIseZCiMQxW9oA7OIftRE21F/HCbeE39m2HRQkXhl1FoYVAnuUQt2XVptWINo4PSdnRW3ng3F61AILJ1Z3jnDbLXYME26aoNmkklNSZdVntuM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700510156; 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=sDyON834lvvMCmd4XFb65tYw0V8LYs8uMSmygDOut9U=; b=THadj3ycrd1/X1IirplMxr+JQf5yA8JExg295zlBUV1Hakl+mN7HUP6/rlsOy0NVkZ2i5n c0tkrtWX8P5vfWp/VVwcx6oP3gvkMM9OTe8ugaCB6RINjAPXyoX/Q2/qkXJQJ/nqu4Qtx6 7YGUCw33zsNQY2JZ9DAuOZ+ANS/ZdtU= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-101-prtyWOvOPvCTiU1b5CCPUA-1; Mon, 20 Nov 2023 14:55:54 -0500 X-MC-Unique: prtyWOvOPvCTiU1b5CCPUA-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-7788fb069abso1008855785a.0 for ; Mon, 20 Nov 2023 11:55:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700510154; x=1701114954; 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=sDyON834lvvMCmd4XFb65tYw0V8LYs8uMSmygDOut9U=; b=nAj8+iQQUzRQ8OrbmEM010naeqsBQ4klXPrzH8dxgBRp7ruzzAVvOOk/C65RuU6DgC xXz+rlOL8wQ8YNFuo9HJkXgGtN/jNt3FT7G3VIhmcxG1628SJ5YWc7NAPW25NfmKToZ4 pcsXxOZXsxs69IWp4VJ7/EKT8IwYMAe/F+rniwqiwqlklBDBV/0JFeXZnxbCk1imsjCQ Fz+LRpz4Aw04FswU7vsifVCGN3Tu2rUffAATDFlTeu2N/ZYy5ZNJaHPmKJeabMMEaTi1 UlQVA3BtADn4bTBiJRdmuBhGA4IGalnKvymlhz0wUEZQ7E3KTWwMN4CKiHRLDkmo+z0e ofAA== X-Gm-Message-State: AOJu0Yy5mN58UwYOUSLk/O2bHkeir7zumFagdRAJmPPRMlf3IJvT4Ukt uQ2DpktHlXHgzxuUpuSzRl3VxJIqH/GMeuDQgMKW0JYTNRsaD9zBhKEBrX9rM3ZuQsAgM4mupuH xLaoeNk90EX24am1ECA== X-Received: by 2002:a05:620a:4626:b0:779:d1a6:ee5c with SMTP id br38-20020a05620a462600b00779d1a6ee5cmr688763qkb.32.1700510154466; Mon, 20 Nov 2023 11:55:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IF3pcSt9xn48fD7SVlLEg9kDuiRd/IaRtBJmT/rPQeaOCc1qwieS3m+fHTumSu/tVbmawav+Q== X-Received: by 2002:a05:620a:4626:b0:779:d1a6:ee5c with SMTP id br38-20020a05620a462600b00779d1a6ee5cmr688741qkb.32.1700510154159; Mon, 20 Nov 2023 11:55:54 -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 pr13-20020a05620a86cd00b007770d47c621sm2883879qkn.66.2023.11.20.11.55.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Nov 2023 11:55:53 -0800 (PST) Message-ID: <78e7499c-2278-44ff-8455-503e3690e3fd@redhat.com> Date: Mon, 20 Nov 2023 14:55:52 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH #2/4] c++: mark short-enums as packed To: Alexandre Oliva , gcc-patches@gcc.gnu.org Cc: David Malcolm , Rainer Orth , Mike Stump , Nathan Sidwell , "H.J. Lu" References: 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=-6.1 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_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE 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 11/19/23 21:33, Alexandre Oliva wrote: > > 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. I think the warning is wrong here. The example given when it was added in r9-5005-gda77eace90fd99 was struct pair_t { char c; int i; } __attribute__ ((packed)); extern struct pair_t p; int *addr = &p.i; in this case, we're assigning a pointer to unaligned int to a normal pointer to int, and that's what the warning is for; conversion from a misaligned member. 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. Also, -fshort-enums has nothing to do with structure packing, it just affects the underlying type of the enum. We don't warn about conversion from pointer to char to pointer to struct with char member, and this is the exact same situation. And unlike a struct with __attribute__ ((packed)), enum A { a=1000 }; gets 16-bit alignment with -fshort-enums. So it seems to me that setting TYPE_PACKED from -fshort-enums is wrong. Or that the warning's use of TYPE_PACKED is wrong (e.g. it should look for a COMPONENT_REF of DECL_PACKED instead). Or both. Either way, I'm opposed to changing things so that the C++ front-end starts emitting the warning. Jason