From patchwork Wed Nov 22 21:12:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1867503 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hDjduVvo; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SbDWL5QhVz1yS0 for ; Thu, 23 Nov 2023 08:13:50 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8F4B8396E059 for ; Wed, 22 Nov 2023 21:13:04 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 4C07B384F015 for ; Wed, 22 Nov 2023 21:12:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4C07B384F015 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 4C07B384F015 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=1700687571; cv=none; b=MDg2Ee1dinChEQqhvBJUlpxy/Txc3qI+9ljSOp1NiTOTaoGC5RB2d+Q1mAbFHldRE2I0DuRQTc1mT966vUAQdLW+Xo/iUc1T+SRZ+3e0EqAgHBnEpQq+DrCt/2Eafka+yt2yy/u95L6iwvtAfzxIm82HHo8r3QDJQ3hu1iIgGPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700687571; c=relaxed/simple; bh=qdRHD5GHTFch1pX58IdQb+2j8aURSp1i258F8Ljw3n8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=OnJqpblz8NxUuKmHA8Q/f05bFaoJ2hpuED5mOaQVLQ3nbGWZ0Ggrj50f0E0xL5r8j/zDBSKeyAaJMyHLCzORTpsMx/wTCvwftFLTKj7BBN66yknE5T3q1/jCLbYMlPze0VmuAblDPatIYopo5fYYnSkBxbL2nrZb5ESbWKqiHKw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700687560; 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; bh=wfLXUkub55ZMWCBQrfNmbiha7I3RGhxGCPnWRALZTKU=; b=hDjduVvoU1LTvZGuyqfJhZGnUMBBwBuiI8UEoQst1QHh1WsqypNQL5UxZjajo2UHp4yDXl l/a7VUy8o5ESRRP7Agkz4vHZ+8NxE+AaYRIx38892OCSIIiZT94tvv6S7eL83XZe7a8zMl 7ur7dtJL6AJ2hibcx82d6eR5tY9aP5w= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-531-L4LrX0CDMxqw3ZIuxoAq5A-1; Wed, 22 Nov 2023 16:12:39 -0500 X-MC-Unique: L4LrX0CDMxqw3ZIuxoAq5A-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-67389986b6dso2757806d6.3 for ; Wed, 22 Nov 2023 13:12:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700687558; x=1701292358; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wfLXUkub55ZMWCBQrfNmbiha7I3RGhxGCPnWRALZTKU=; b=fHomwL2mc23pFfRBJAQahDGfnefCGSTDui+nq0tnqJ+ig39uQ12GDGHO9o3OoU8hpE rOKibMryqEgYTeqaLZGj3MAbd/3dOjVr0pBGgJ6pPVhAcU8VS+uqZ5SIkJ1p+LU5/K2C 8svAzxIXWjVHgTuIi3YSErYYsk3q7cgg7YGQFjU9317ExnBFci+hLUXtBw7fuefmypOT SFMKQ+/9KpYUp/C+1qC+VUGrtC6oDmiMegZfyINEdZIPwq+npREjQyywR2VPZht8mwCm 6q8kco7HlV2JLynIEQcrJlbWayIK9U1+4/RIWhQuSYr/IODixG/JA7fNJfD8pz5P+X/g D/lg== X-Gm-Message-State: AOJu0YxabF2Ifqu4CqT0IDUsyzdx+kUZd7fmA//KcHOpwq7fQI4p4Wz3 +k2IohBLxOslQqjxMQFxoNZZAePa+buI2SULJGeqVyUAeGf8oGnAQ0n8KXbGOVN9X/hjqSYJslk FT89C41v1j9nuiN65k+Q2LdHJkZHq5wp5Lb/o+LAnz8GMRtKVlc9u6DLQwXG3qRCo/gyEsL4rfA == X-Received: by 2002:ad4:5ca1:0:b0:671:9c02:cbaa with SMTP id q1-20020ad45ca1000000b006719c02cbaamr4094922qvh.39.1700687558437; Wed, 22 Nov 2023 13:12:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IFEsPzXOyyL4fPr08mE5hMAzxJ/JbSQzJH3uKGsYiGVWFwEj8Tq/yZWzz5XvS/olVru0sXHwA== X-Received: by 2002:ad4:5ca1:0:b0:671:9c02:cbaa with SMTP id q1-20020ad45ca1000000b006719c02cbaamr4094881qvh.39.1700687557929; Wed, 22 Nov 2023 13:12:37 -0800 (PST) Received: from jason.com (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 w26-20020a0cb55a000000b0066d1348bdddsm104680qvd.44.2023.11.22.13.12.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 13:12:37 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Cc: Jeff Law , Alexandre Oliva , "H . J . Lu" Subject: [PATCH 1/2] c-family: -Waddress-of-packed-member and casts Date: Wed, 22 Nov 2023 16:12:34 -0500 Message-Id: <20231122211235.3503229-1-jason@redhat.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-pc-linux-gnu, OK for trunk? -- 8< -- -Waddress-of-packed-member, in addition to the documented warning about taking the address of a packed member, also warns about casting from a pointer to a TYPE_PACKED type to a pointer to a type with greater alignment. This wrongly warns if the source is a pointer to enum when -fshort-enums is on, since that is also represented by TYPE_PACKED. And there's already -Wcast-align to catch casting from pointer to less aligned type (packed or otherwise) to pointer to more aligned type; even apart from the enum problem, this seems like a somewhat arbitrary subset of that warning. Though that isn't currently on by default. So, this patch removes the undocumented type-based warning from -Waddress-of-packed-member. Some of the tests where the warning is desirable I changed to use -Wcast-align=strict instead. The ones that require -Wno-incompatible-pointer-types, I just removed. gcc/c-family/ChangeLog: * c-warn.cc (check_address_or_pointer_of_packed_member): Remove warning based on TYPE_PACKED. gcc/testsuite/ChangeLog: * c-c++-common/Waddress-of-packed-member-1.c: Don't expect a warning on the cast cases. * c-c++-common/pr51628-35.c: Use -Wcast-align=strict. * g++.dg/warn/Waddress-of-packed-member3.C: Likewise. * gcc.dg/pr88928.c: Likewise. * gcc.dg/pr51628-20.c: Removed. * gcc.dg/pr51628-21.c: Removed. * gcc.dg/pr51628-25.c: Removed. --- gcc/c-family/c-warn.cc | 58 +------------------ .../Waddress-of-packed-member-1.c | 12 ++-- gcc/testsuite/c-c++-common/pr51628-35.c | 6 +- .../g++.dg/warn/Waddress-of-packed-member3.C | 8 +-- gcc/testsuite/gcc.dg/pr51628-20.c | 11 ---- gcc/testsuite/gcc.dg/pr51628-21.c | 11 ---- gcc/testsuite/gcc.dg/pr51628-25.c | 9 --- gcc/testsuite/gcc.dg/pr88928.c | 6 +- 8 files changed, 19 insertions(+), 102 deletions(-) delete mode 100644 gcc/testsuite/gcc.dg/pr51628-20.c delete mode 100644 gcc/testsuite/gcc.dg/pr51628-21.c delete mode 100644 gcc/testsuite/gcc.dg/pr51628-25.c base-commit: 65bd6de0de57abc86931a5e0b9a8d453ad530004 diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc index d2938b91043..2a399ba6d14 100644 --- a/gcc/c-family/c-warn.cc +++ b/gcc/c-family/c-warn.cc @@ -2991,10 +2991,9 @@ check_alignment_of_packed_member (tree type, tree field, bool rvalue) return NULL_TREE; } -/* Return struct or union type if the right hand value, RHS: - 1. Is a pointer value which isn't aligned to a pointer type TYPE. - 2. Is an address which takes the unaligned address of packed member - of struct or union when assigning to TYPE. +/* Return struct or union type if the right hand value, RHS + is an address which takes the unaligned address of packed member + of struct or union when assigning to TYPE. Otherwise, return NULL_TREE. */ static tree @@ -3021,57 +3020,6 @@ check_address_or_pointer_of_packed_member (tree type, tree rhs) type = TREE_TYPE (type); - if (TREE_CODE (rhs) == PARM_DECL - || VAR_P (rhs) - || TREE_CODE (rhs) == CALL_EXPR) - { - tree rhstype = TREE_TYPE (rhs); - if (TREE_CODE (rhs) == CALL_EXPR) - { - rhs = CALL_EXPR_FN (rhs); /* Pointer expression. */ - if (rhs == NULL_TREE) - return NULL_TREE; - rhs = TREE_TYPE (rhs); /* Pointer type. */ - /* We could be called while processing a template and RHS could be - a functor. In that case it's a class, not a pointer. */ - if (!rhs || !POINTER_TYPE_P (rhs)) - return NULL_TREE; - rhs = TREE_TYPE (rhs); /* Function type. */ - rhstype = TREE_TYPE (rhs); - if (!rhstype || !POINTER_TYPE_P (rhstype)) - return NULL_TREE; - rvalue = true; - } - if (rvalue && POINTER_TYPE_P (rhstype)) - rhstype = TREE_TYPE (rhstype); - while (TREE_CODE (rhstype) == ARRAY_TYPE) - rhstype = TREE_TYPE (rhstype); - if (TYPE_PACKED (rhstype)) - { - unsigned int type_align = min_align_of_type (type); - unsigned int rhs_align = min_align_of_type (rhstype); - if (rhs_align < type_align) - { - auto_diagnostic_group d; - location_t location = EXPR_LOC_OR_LOC (rhs, input_location); - if (warning_at (location, OPT_Waddress_of_packed_member, - "converting a packed %qT pointer (alignment %d) " - "to a %qT pointer (alignment %d) may result in " - "an unaligned pointer value", - rhstype, rhs_align, type, type_align)) - { - tree decl = TYPE_STUB_DECL (rhstype); - if (decl) - inform (DECL_SOURCE_LOCATION (decl), "defined here"); - decl = TYPE_STUB_DECL (type); - if (decl) - inform (DECL_SOURCE_LOCATION (decl), "defined here"); - } - } - } - return NULL_TREE; - } - tree context = NULL_TREE; /* Check alignment of the object. */ diff --git a/gcc/testsuite/c-c++-common/Waddress-of-packed-member-1.c b/gcc/testsuite/c-c++-common/Waddress-of-packed-member-1.c index 95a376664da..0f5188df70a 100644 --- a/gcc/testsuite/c-c++-common/Waddress-of-packed-member-1.c +++ b/gcc/testsuite/c-c++-common/Waddress-of-packed-member-1.c @@ -52,12 +52,12 @@ void foo (void) f0 = *&__real__ t0.f; /* { dg-bogus "may result in an unaligned pointer value" } */ f0 = *&__imag__ t0.f; /* { dg-bogus "may result in an unaligned pointer value" } */ i1 = (&t0.c, (int*) 0); /* { dg-bogus "may result in an unaligned pointer value" } */ - t2 = (struct t**) t10; /* { dg-warning "may result in an unaligned pointer value" "" { target { ! default_packed } } } */ - t2 = (struct t**) t100; /* { dg-warning "may result in an unaligned pointer value" "" { target { ! default_packed } } } */ - t2 = (struct t**) t1; /* { dg-warning "may result in an unaligned pointer value" "" { target { ! default_packed } } } */ - t2 = (struct t**) bar(); /* { dg-warning "may result in an unaligned pointer value" "" { target { ! default_packed } } } */ - t2 = (struct t**) baz(); /* { dg-warning "may result in an unaligned pointer value" "" { target { ! default_packed } } } */ - t2 = (struct t**) bazz(); /* { dg-warning "may result in an unaligned pointer value" "" { target { ! default_packed } } } */ + t2 = (struct t**) t10; /* { dg-bogus "may result in an unaligned pointer value" } */ + t2 = (struct t**) t100; /* { dg-bogus "may result in an unaligned pointer value" } */ + t2 = (struct t**) t1; /* { dg-bogus "may result in an unaligned pointer value" } */ + t2 = (struct t**) bar(); /* { dg-bogus "may result in an unaligned pointer value" } */ + t2 = (struct t**) baz(); /* { dg-bogus "may result in an unaligned pointer value" } */ + t2 = (struct t**) bazz(); /* { dg-bogus "may result in an unaligned pointer value" } */ i1 = &t0.b; /* { dg-warning "may result in an unaligned pointer value" "" { target { ! default_packed } } } */ i1 = &t1->b; /* { dg-warning "may result in an unaligned pointer value" "" { target { ! default_packed } } } */ i1 = &t10[0].b; /* { dg-warning "may result in an unaligned pointer value" "" { target { ! default_packed } } } */ diff --git a/gcc/testsuite/c-c++-common/pr51628-35.c b/gcc/testsuite/c-c++-common/pr51628-35.c index fa37d99beb7..a88c19ea0df 100644 --- a/gcc/testsuite/c-c++-common/pr51628-35.c +++ b/gcc/testsuite/c-c++-common/pr51628-35.c @@ -1,6 +1,6 @@ /* PR c/51628. */ /* { dg-do compile } */ -/* { dg-options "-O" } */ +/* { dg-options "-O -Wcast-align=strict" } */ struct B { int i; }; struct C { struct B b; } __attribute__ ((packed)); @@ -12,12 +12,12 @@ long * foo1 (void) { return (long *) p; -/* { dg-warning "may result in an unaligned pointer value" "" { target { ! default_packed } } .-1 } */ +/* { dg-warning "increases required alignment" "" { target { ! default_packed } } .-1 } */ } long * foo2 (void) { return (long *) bar (); -/* { dg-warning "may result in an unaligned pointer value" "" { target { ! default_packed } } .-1 } */ +/* { dg-warning "increases required alignment" "" { target { ! default_packed } } .-1 } */ } diff --git a/gcc/testsuite/g++.dg/warn/Waddress-of-packed-member3.C b/gcc/testsuite/g++.dg/warn/Waddress-of-packed-member3.C index aeffb969c01..28dd05d366c 100644 --- a/gcc/testsuite/g++.dg/warn/Waddress-of-packed-member3.C +++ b/gcc/testsuite/g++.dg/warn/Waddress-of-packed-member3.C @@ -1,5 +1,5 @@ // { dg-do compile { target { ! default_packed } } } -// Test that -Waddress-of-packed-member works with member functions. +// { dg-additional-options -Wcast-align=strict } struct S { char c; @@ -16,8 +16,8 @@ S** f () { S **s; - s = reinterpret_cast(foo ()); // { dg-warning "converting a packed" } - s = reinterpret_cast(x.memfn ()); // { dg-warning "converting a packed" } - s = reinterpret_cast(X::smemfn ()); // { dg-warning "converting a packed" } + s = reinterpret_cast(foo ()); // { dg-warning "increases required alignment" } + s = reinterpret_cast(x.memfn ()); // { dg-warning "increases required alignment" } + s = reinterpret_cast(X::smemfn ()); // { dg-warning "increases required alignment" } return s; } diff --git a/gcc/testsuite/gcc.dg/pr51628-20.c b/gcc/testsuite/gcc.dg/pr51628-20.c deleted file mode 100644 index 2249d85098b..00000000000 --- a/gcc/testsuite/gcc.dg/pr51628-20.c +++ /dev/null @@ -1,11 +0,0 @@ -/* PR c/51628. */ -/* { dg-do compile } */ -/* { dg-options "-O -Wno-incompatible-pointer-types" } */ - -struct B { int i; }; -struct C { struct B b; } __attribute__ ((packed)); - -extern struct C *p; - -long* g8 (void) { return p; } -/* { dg-warning "may result in an unaligned pointer value" "" { target { ! default_packed } } .-1 } */ diff --git a/gcc/testsuite/gcc.dg/pr51628-21.c b/gcc/testsuite/gcc.dg/pr51628-21.c deleted file mode 100644 index f1adbe64002..00000000000 --- a/gcc/testsuite/gcc.dg/pr51628-21.c +++ /dev/null @@ -1,11 +0,0 @@ -/* PR c/51628. */ -/* { dg-do compile } */ -/* { dg-options "-O -Wno-incompatible-pointer-types" } */ - -struct B { int i; }; -struct C { struct B b; } __attribute__ ((packed)); - -extern struct C p[]; - -long* g8 (void) { return p; } -/* { dg-warning "may result in an unaligned pointer value" "" { target { ! default_packed } } .-1 } */ diff --git a/gcc/testsuite/gcc.dg/pr51628-25.c b/gcc/testsuite/gcc.dg/pr51628-25.c deleted file mode 100644 index f00d9b1bcac..00000000000 --- a/gcc/testsuite/gcc.dg/pr51628-25.c +++ /dev/null @@ -1,9 +0,0 @@ -/* PR c/51628. */ -/* { dg-do compile } */ -/* { dg-options "-O -Wno-incompatible-pointer-types" } */ - -struct B { int i; }; -struct C { struct B b; } __attribute__ ((packed)); - -long* g8 (struct C *p) { return p; } -/* { dg-warning "may result in an unaligned pointer value" "" { target { ! default_packed } } .-1 } */ diff --git a/gcc/testsuite/gcc.dg/pr88928.c b/gcc/testsuite/gcc.dg/pr88928.c index 0b6c1d70f05..1d176d6d51d 100644 --- a/gcc/testsuite/gcc.dg/pr88928.c +++ b/gcc/testsuite/gcc.dg/pr88928.c @@ -1,6 +1,6 @@ -/* { dg-do compile } */ -/* { dg-options "-Wno-pedantic -Waddress-of-packed-member" } */ +/* { dg-do compile { target { ! default_packed } } } */ +/* { dg-options "-Wno-pedantic -Waddress-of-packed-member -Wcast-align=strict" } */ struct a { } __attribute__((__packed__)); void c (struct a **); void d (const struct a *b) { c ((struct a **) b); } -/* { dg-warning "may result in an unaligned pointer value" "" { target { ! default_packed } } .-1 } */ +/* { dg-warning "increases required alignment" "" { target *-*-* } .-1 } */ From patchwork Wed Nov 22 21:12:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1867504 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dmIxDUER; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SbDWT54bnz1yS0 for ; Thu, 23 Nov 2023 08:13:57 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AC040396E469 for ; Wed, 22 Nov 2023 21:13:06 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 1125B384F02F for ; Wed, 22 Nov 2023 21:12:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1125B384F02F 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 1125B384F02F 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=1700687572; cv=none; b=UtFWPXFVmh+QwxnKXyxBQqr+tATdv2fWiKmsubGQ3rDTwukhGSQijhxJvEWLnjzgFUEpyUeyaMgvDoCNVQXUQcHIImO9Mrb1B5lvDoS5OPXTrxxn99eQmW2stGs/Y5smX0k/Za8jCXCLYgnbWwGxs5PZbMDBfu8h7Zlh8TK23bM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700687572; c=relaxed/simple; bh=uWLU7YP1TFSv55yne/wtmyoiuJlzq4IOmyniZACzpVg=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=DrWRfNEY6qetSbNKbFotQoSAdnpI8/n4LcN6oHvhOLe2ZbPamDjyVUYyAf7Xcz9AiCY/4fY/784nZEtyIDplsXOGsxtCd4BBPFAq78wHOsOD52QPnFqY6cthFnv0tSQlanV4sWU88kGNpP39TryY/vfZ4NjocvI82EhPcjMDPGs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700687561; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DE0jLVExR9n2nYAGtr9ydwXsJ7Gm6OYfS/ky/PBT6XQ=; b=dmIxDUER3aksoZ5bHYgf58tNrSu15JdFZ8/OJ+5qBesjfLqm2TDdZdJ3lYx0fOr8GqPrth YsDUewNkAzzJXLDFuZEb9OBJJlHo7YcRG+qYQt+nqvQWDgQYG9haCOKIAANuDAYSDiVj97 IT0dAq8zT+KONM3ihkYCRvGmkyK9E3k= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-92-ePTDz-_bOHuwRrxBQWg9Qg-1; Wed, 22 Nov 2023 16:12:40 -0500 X-MC-Unique: ePTDz-_bOHuwRrxBQWg9Qg-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-677f3c0bb78so3386356d6.1 for ; Wed, 22 Nov 2023 13:12:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700687559; x=1701292359; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DE0jLVExR9n2nYAGtr9ydwXsJ7Gm6OYfS/ky/PBT6XQ=; b=OEzd4D6pEs6GJpVmB+O1kgqxt8QAB+udK8TNqMWpR7chicyTDtCCXAQACgbJbecwoK d12Riqa8SonvmZRteTNrHr+CeRUj1tMKaF4AVcpSz1yXYSrbuiSSN583oappOb7Yj2Mm DDtPE1KM7dXO/asi+7yzlOgTAlmbJB6lKZJMAvy4Gn7phxm/vjlt3FY05WXJhSIJXXAD Ro/KzWoCflRBRhAfmYxQWvqGCnsG3Kq/SDtqAhKHy/lwHln+Fu3Ywso1R2CmY1yCnEpX kVzIlQPf3GRD5Lkp2ehQK3srVhqOPqRqPGSEHd+xFLvXrz5eQ3m3KjRT7U3AVNa1iLLf eOyw== X-Gm-Message-State: AOJu0YyjMJJs2S5Irw93HeEB5mWjCcE0A6W+oEhaB4HbmS7ak0grwsxf giWW2rjrmQRWbiROogw899UhbJfEDAaVmWnhnAp1v91uZBD7NqKss2umUMRHKkSj9rjklHA6cyV 0S0Jx89/n74a2K7/e8uG0EvlxzizsSJ8lSdxmtHmYytq3qBqzx4SbxfoZEzFaVH1uRqGHDZ0RRA == X-Received: by 2002:a05:6214:cc2:b0:679:d3e4:f766 with SMTP id 2-20020a0562140cc200b00679d3e4f766mr4483529qvx.65.1700687559607; Wed, 22 Nov 2023 13:12:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IGmDxXm3aYAWgYX/4ntQsyXpstlH21zUnJKh3itHJeOYJQ1NPLiQZGZElp6OuRXGdNg5RfFmQ== X-Received: by 2002:a05:6214:cc2:b0:679:d3e4:f766 with SMTP id 2-20020a0562140cc200b00679d3e4f766mr4483507qvx.65.1700687559186; Wed, 22 Nov 2023 13:12:39 -0800 (PST) Received: from jason.com (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 w26-20020a0cb55a000000b0066d1348bdddsm104680qvd.44.2023.11.22.13.12.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 13:12:38 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] c-family: rename warn_for_address_or_pointer_of_packed_member Date: Wed, 22 Nov 2023 16:12:35 -0500 Message-Id: <20231122211235.3503229-2-jason@redhat.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231122211235.3503229-1-jason@redhat.com> References: <20231122211235.3503229-1-jason@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Following the last patch, let's rename the functions to reflect the change in behavior. gcc/c-family/ChangeLog: * c-warn.cc (check_address_or_pointer_of_packed_member): Rename to check_address_of_packed_member. (check_and_warn_address_or_pointer_of_packed_member): Rename to check_and_warn_address_of_packed_member. (warn_for_address_or_pointer_of_packed_member): Rename to warn_for_address_of_packed_member. * c-common.h: Adjust. gcc/c/ChangeLog: * c-typeck.cc (convert_for_assignment): Adjust call to warn_for_address_of_packed_member. gcc/cp/ChangeLog: * call.cc (convert_for_arg_passing) * typeck.cc (convert_for_assignment): Adjust call to warn_for_address_of_packed_member. --- gcc/c-family/c-common.h | 2 +- gcc/c-family/c-warn.cc | 32 ++++++++++++++------------------ gcc/c/c-typeck.cc | 4 ++-- gcc/cp/call.cc | 2 +- gcc/cp/typeck.cc | 2 +- 5 files changed, 19 insertions(+), 23 deletions(-) diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index b57e83d7c5d..9380452a93b 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -1482,7 +1482,7 @@ extern void warnings_for_convert_and_check (location_t, tree, tree, tree); extern void c_do_switch_warnings (splay_tree, location_t, tree, tree, bool); extern void warn_for_omitted_condop (location_t, tree); extern bool warn_for_restrict (unsigned, tree *, unsigned); -extern void warn_for_address_or_pointer_of_packed_member (tree, tree); +extern void warn_for_address_of_packed_member (tree, tree); extern void warn_parm_array_mismatch (location_t, tree, tree); extern void maybe_warn_sizeof_array_div (location_t, tree, tree, tree, tree); extern void do_warn_array_compare (location_t, tree_code, tree, tree); diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc index 2a399ba6d14..abe66dd3030 100644 --- a/gcc/c-family/c-warn.cc +++ b/gcc/c-family/c-warn.cc @@ -2991,13 +2991,13 @@ check_alignment_of_packed_member (tree type, tree field, bool rvalue) return NULL_TREE; } -/* Return struct or union type if the right hand value, RHS +/* Return struct or union type if the right hand value, RHS, is an address which takes the unaligned address of packed member of struct or union when assigning to TYPE. Otherwise, return NULL_TREE. */ static tree -check_address_or_pointer_of_packed_member (tree type, tree rhs) +check_address_of_packed_member (tree type, tree rhs) { bool rvalue = true; bool indirect = false; @@ -3042,14 +3042,12 @@ check_address_or_pointer_of_packed_member (tree type, tree rhs) return context; } -/* Check and warn if the right hand value, RHS: - 1. Is a pointer value which isn't aligned to a pointer type TYPE. - 2. Is an address which takes the unaligned address of packed member - of struct or union when assigning to TYPE. - */ +/* Check and warn if the right hand value, RHS, + is an address which takes the unaligned address of packed member + of struct or union when assigning to TYPE. */ static void -check_and_warn_address_or_pointer_of_packed_member (tree type, tree rhs) +check_and_warn_address_of_packed_member (tree type, tree rhs) { bool nop_p = false; tree orig_rhs; @@ -3067,11 +3065,11 @@ check_and_warn_address_or_pointer_of_packed_member (tree type, tree rhs) if (TREE_CODE (rhs) == COND_EXPR) { /* Check the THEN path. */ - check_and_warn_address_or_pointer_of_packed_member + check_and_warn_address_of_packed_member (type, TREE_OPERAND (rhs, 1)); /* Check the ELSE path. */ - check_and_warn_address_or_pointer_of_packed_member + check_and_warn_address_of_packed_member (type, TREE_OPERAND (rhs, 2)); } else @@ -3095,7 +3093,7 @@ check_and_warn_address_or_pointer_of_packed_member (tree type, tree rhs) } tree context - = check_address_or_pointer_of_packed_member (type, rhs); + = check_address_of_packed_member (type, rhs); if (context) { location_t loc = EXPR_LOC_OR_LOC (rhs, input_location); @@ -3107,14 +3105,12 @@ check_and_warn_address_or_pointer_of_packed_member (tree type, tree rhs) } } -/* Warn if the right hand value, RHS: - 1. Is a pointer value which isn't aligned to a pointer type TYPE. - 2. Is an address which takes the unaligned address of packed member - of struct or union when assigning to TYPE. -*/ +/* Warn if the right hand value, RHS, + is an address which takes the unaligned address of packed member + of struct or union when assigning to TYPE. */ void -warn_for_address_or_pointer_of_packed_member (tree type, tree rhs) +warn_for_address_of_packed_member (tree type, tree rhs) { if (!warn_address_of_packed_member) return; @@ -3123,7 +3119,7 @@ warn_for_address_or_pointer_of_packed_member (tree type, tree rhs) if (!POINTER_TYPE_P (type)) return; - check_and_warn_address_or_pointer_of_packed_member (type, rhs); + check_and_warn_address_of_packed_member (type, rhs); } /* Return EXPR + 1. Convenience helper used below. */ diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index 1dbb4471a88..3960c407ca7 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -6942,7 +6942,7 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type, if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype)) { - warn_for_address_or_pointer_of_packed_member (type, orig_rhs); + warn_for_address_of_packed_member (type, orig_rhs); return rhs; } @@ -7599,7 +7599,7 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type, /* If RHS isn't an address, check pointer or array of packed struct or union. */ - warn_for_address_or_pointer_of_packed_member (type, orig_rhs); + warn_for_address_of_packed_member (type, orig_rhs); return convert (type, rhs); } diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index 81b104f4b40..516e02ceb32 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -9306,7 +9306,7 @@ convert_for_arg_passing (tree type, tree val, tsubst_flags_t complain) } if (complain & tf_warning) - warn_for_address_or_pointer_of_packed_member (type, val); + warn_for_address_of_packed_member (type, val); return val; } diff --git a/gcc/cp/typeck.cc b/gcc/cp/typeck.cc index e995fb6ddd7..f2e90a86148 100644 --- a/gcc/cp/typeck.cc +++ b/gcc/cp/typeck.cc @@ -10378,7 +10378,7 @@ convert_for_assignment (tree type, tree rhs, maybe_warn_unparenthesized_assignment (rhs, complain); if (complain & tf_warning) - warn_for_address_or_pointer_of_packed_member (type, rhs); + warn_for_address_of_packed_member (type, rhs); return perform_implicit_conversion_flags (strip_top_quals (type), rhs, complain, flags);