From patchwork Thu Mar 21 13:04:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1060094 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-498245-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="vmuFEs6t"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Q6T965Hvz9sQy for ; Fri, 22 Mar 2019 00:04:58 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=TzHYX3eIfpomHTRDUdtaGOpOhN8ZsfFVSgjK5xWiVz6s6pelDAV+r 6F3GdLzmoLH5pZ0m+ubxPFizaJP4IDv9+1JKzh9z2+rqFcmNu0/ouwmXBya1Wj4T 4Y1Ymw/ZG4Wd7Mv2/kQfHhv3fhQiFex3UseZ03roGerUQn0bzbVd40= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=5NHxIPrap06X0HkXMAlcgfIhJ4w=; b=vmuFEs6tVsVIcuPGy3Vx B1URsMXSvArzLQ3BHkn/aJZM6qZX8rpYhL1vNAmLtcY7RN5h3wilXiREuAM4DJYR PmZGnJaNX1c/cNpocHjhZ5SlHosxwtRMIIaXG3pLTeoE1NINB/CXwJsHzcaOiO0f SWpXprUJJEekTswc5MR5Z5I= Received: (qmail 12093 invoked by alias); 21 Mar 2019 13:04:51 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 12078 invoked by uid 89); 21 Mar 2019 13:04:50 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-6.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_NUMSUBJECT autolearn=ham version=3.3.1 spammy=get_alias_set, alias_set_type X-HELO: foss.arm.com Received: from usa-sjc-mx-foss1.foss.arm.com (HELO foss.arm.com) (217.140.101.70) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 21 Mar 2019 13:04:49 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 873B080D for ; Thu, 21 Mar 2019 06:04:47 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.39]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0D5573F614 for ; Thu, 21 Mar 2019 06:04:46 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Fix use of COMPLETE_TYPE_P for -Wstrict-aliasing=1 Date: Thu, 21 Mar 2019 13:04:45 +0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 The handling of -Wstrict-aliasing=1 applied COMPLETE_TYPE_P to the pointer type rather than the pointer target, so missed the warnings for "struct incomplete" in the testcase. I couldn't find any existing C tests for -Wstrict-aliasing=1, so I added a few extra tests besides the ones fixed by the patch. I'm sure there's lots more we could test -- this is just supposed to be better than the status quo (i.e. nothing). Tested on aarch64-linux-gnu. Not sure this is a regression in any meaningful sense, so I guess it should wait for GCC 10. OK for stage 1? Richard 2019-03-21 Richard Sandiford gcc/c-family/ * c-warn.c (strict_aliasing_warning): Apply COMPLETE_TYPE_P to the pointer target rather than the pointer itself. gcc/testsuite/ * gcc.dg/alias-16.c: New test. Index: gcc/c-family/c-warn.c =================================================================== --- gcc/c-family/c-warn.c 2019-03-21 13:01:18.000000000 +0000 +++ gcc/c-family/c-warn.c 2019-03-21 13:01:18.453582721 +0000 @@ -746,7 +746,7 @@ strict_aliasing_warning (location_t loc, are not revealed at higher levels. */ alias_set_type set1 = get_alias_set (TREE_TYPE (otype)); alias_set_type set2 = get_alias_set (TREE_TYPE (type)); - if (!COMPLETE_TYPE_P (type) + if (!COMPLETE_TYPE_P (TREE_TYPE (type)) || !alias_sets_must_conflict_p (set1, set2)) { warning_at (loc, OPT_Wstrict_aliasing, Index: gcc/testsuite/gcc.dg/alias-16.c =================================================================== --- /dev/null 2019-03-08 11:40:14.606883727 +0000 +++ gcc/testsuite/gcc.dg/alias-16.c 2019-03-21 13:01:18.453582721 +0000 @@ -0,0 +1,46 @@ +/* { dg-do compile } */ +/* { dg-options "-Wstrict-aliasing=1 -fstrict-aliasing" } */ + +struct incomplete; +struct s1 { int i; }; +struct s2 { double d; }; + +void +f (int *i, double *d, struct s1 *s1, struct s2 *s2, char *c) +{ + (char *) i; + (char *) d; + (char *) s1; + (char *) s2; + (char *) c; + + (int *) i; + (int *) d; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */ + (int *) s1; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */ + (int *) s2; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */ + (int *) c; + + (double *) i; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */ + (double *) d; + (double *) s1; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */ + (double *) s2; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */ + (double *) c; + + (struct incomplete *) i; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */ + (struct incomplete *) d; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */ + (struct incomplete *) s1; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */ + (struct incomplete *) s2; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */ + (struct incomplete *) c; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */ + + (struct s1 *) i; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */ + (struct s1 *) d; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */ + (struct s1 *) s1; + (struct s1 *) s2; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */ + (struct s1 *) c; + + (struct s2 *) i; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */ + (struct s2 *) d; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */ + (struct s2 *) s1; /* { dg-warning "dereferencing type-punned pointer might break strict-aliasing rules" } */ + (struct s2 *) s2; + (struct s2 *) c; +}