From patchwork Tue Apr 21 07:38:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1274029 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=ab/rNecf; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 495wR64qLwz9sSM for ; Tue, 21 Apr 2020 17:38:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 588BE386F43C; Tue, 21 Apr 2020 07:38:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 588BE386F43C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1587454702; bh=RSnsXsdVWhzpkE65+HUZ++kfzQnQHnBi4476i/bBaJw=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=ab/rNecf9U3jdwUEpYJMk8LpS7i0dPm7n+RrzvPcT60/L3MHClQUjr3tS2Le47i51 bSpg5hfL70PfRnNhtp8Njdz8pUmQAepyi0WRiZEwew0csS2uC6ry32YavefjclVyIM SO2pR00lkqEj0NZrPoG49l9g/bqHi5naMlb7EndE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id 4BC1B384B0C1 for ; Tue, 21 Apr 2020 07:38:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4BC1B384B0C1 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-390-S3pCj9qWNt6mh2kBu73cgA-1; Tue, 21 Apr 2020 03:38:18 -0400 X-MC-Unique: S3pCj9qWNt6mh2kBu73cgA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1BD16107ACC4; Tue, 21 Apr 2020 07:38:17 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-112-104.ams2.redhat.com [10.36.112.104]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A3816A188B; Tue, 21 Apr 2020 07:38:16 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id 03L7cEhR027632; Tue, 21 Apr 2020 09:38:14 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id 03L7cCmE027631; Tue, 21 Apr 2020 09:38:12 +0200 Date: Tue, 21 Apr 2020 09:38:12 +0200 To: Richard Biener Subject: [PATCH v2] ubsan: Avoid -Wpadded warnings [PR94641] Message-ID: <20200421073812.GV2424@tucnak> References: <20200420225456.GS2424@tucnak> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-17.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi! On Tue, Apr 21, 2020 at 08:21:36AM +0200, Richard Biener wrote: > I believe most of those warnings should simply not look at > TYPE_ARTIFICIAL types. So why the above kludge certainly > works a better fix is on the -Wpadded side IMHO. So like this if it passes bootstrap/regtest? 2020-04-21 Jakub Jelinek PR c/94641 * stor-layout.c (place_field, finalize_record_size): Don't emit -Wpadded warning on TYPE_ARTIFICIAL rli->t. * ubsan.c (ubsan_get_type_descriptor_type, ubsan_get_source_location_type, ubsan_create_data): Set TYPE_ARTIFICIAL. * asan.c (asan_global_struct): Likewise. * c-c++-common/ubsan/pr94641.c: New test. Jakub --- gcc/stor-layout.c.jj 2020-01-12 11:54:36.935405533 +0100 +++ gcc/stor-layout.c 2020-04-21 09:34:27.743871177 +0200 @@ -1341,7 +1341,8 @@ place_field (record_layout_info rli, tre Bump the cumulative size to multiple of field alignment. */ if (!targetm.ms_bitfield_layout_p (rli->t) - && DECL_SOURCE_LOCATION (field) != BUILTINS_LOCATION) + && DECL_SOURCE_LOCATION (field) != BUILTINS_LOCATION + && !TYPE_ARTIFICIAL (rli->t)) warning (OPT_Wpadded, "padding struct to align %q+D", field); /* If the alignment is still within offset_align, just align @@ -1775,7 +1776,8 @@ finalize_record_size (record_layout_info if (TREE_CONSTANT (unpadded_size) && simple_cst_equal (unpadded_size, TYPE_SIZE (rli->t)) == 0 - && input_location != BUILTINS_LOCATION) + && input_location != BUILTINS_LOCATION + && !TYPE_ARTIFICIAL (rli->t)) warning (OPT_Wpadded, "padding struct size to alignment boundary"); if (warn_packed && TREE_CODE (rli->t) == RECORD_TYPE --- gcc/ubsan.c.jj 2020-04-20 11:46:07.892145312 +0200 +++ gcc/ubsan.c 2020-04-21 09:25:46.494055822 +0200 @@ -229,6 +229,7 @@ ubsan_get_type_descriptor_type (void) TYPE_FIELDS (ret) = fields[0]; TYPE_NAME (ret) = type_decl; TYPE_STUB_DECL (ret) = type_decl; + TYPE_ARTIFICIAL (ret) = 1; layout_type (ret); ubsan_type_descriptor_type = ret; return ret; @@ -277,6 +278,7 @@ ubsan_get_source_location_type (void) TYPE_FIELDS (ret) = fields[0]; TYPE_NAME (ret) = type_decl; TYPE_STUB_DECL (ret) = type_decl; + TYPE_ARTIFICIAL (ret) = 1; layout_type (ret); ubsan_source_location_type = ret; return ret; @@ -593,6 +595,7 @@ ubsan_create_data (const char *name, int TYPE_FIELDS (ret) = fields[0]; TYPE_NAME (ret) = type_decl; TYPE_STUB_DECL (ret) = type_decl; + TYPE_ARTIFICIAL (ret) = 1; layout_type (ret); /* Now, fill in the type. */ --- gcc/asan.c.jj 2020-03-18 13:36:22.004021340 +0100 +++ gcc/asan.c 2020-04-21 09:28:00.692968875 +0200 @@ -2661,6 +2661,7 @@ asan_global_struct (void) TYPE_FIELDS (ret) = fields[0]; TYPE_NAME (ret) = type_decl; TYPE_STUB_DECL (ret) = type_decl; + TYPE_ARTIFICIAL (ret) = 1; layout_type (ret); return ret; } --- gcc/testsuite/c-c++-common/ubsan/pr94641.c.jj 2020-04-21 09:24:36.694141289 +0200 +++ gcc/testsuite/c-c++-common/ubsan/pr94641.c 2020-04-21 09:24:36.694141289 +0200 @@ -0,0 +1,11 @@ +/* PR c/94641 */ +/* { dg-do compile } */ +/* { dg-options "-fsanitize=undefined -Wpadded" } */ + +void foo (void *) __attribute__((nonnull)); + +void +bar (void *p) +{ + foo (p); +}