From patchwork Sat Nov 17 22:45:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 999409 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-490383-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="g/KTiXoh"; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EXSHgJUg"; 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 42y9F30TPTz9s8F for ; Sun, 18 Nov 2018 09:46:13 +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 :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=pVRzFAh1H+pxMGR9rWS9o/FjeHTSDEh+dEUxypPeKSLhbY+n5Cico e0TxZcY4We96U2mVwPIJMOvANQknNbRxvxdfhz00pXiGUUw1FPLLxIFN44rRiTdV myFD+QTVk+ozen0j+oVn+JjCOzTs6Sjiu3V/jGLHCJBdCBLtbgB41Y= 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 :subject:to:message-id:date:mime-version:content-type; s= default; bh=UKkkFnYhXnnR/GWDiHFbUVHevCU=; b=g/KTiXohXGa53ix5h/Jl vaG6mkAE5jYAWEtu9asGQSNR/c/31kYorg+Xt86xMqDe7QqQsX7RvtDL6w9HIxZ5 3DtVxkwzgaIUtVLG3bOO/0gAGVy4H8NjgFdJJ1uhyWLzSH4hKJpu/yhPugCIgC+l Ew9pkLnpuUwjK2k0arSzm9E= Received: (qmail 50467 invoked by alias); 17 Nov 2018 22:46:03 -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 50139 invoked by uid 89); 17 Nov 2018 22:45:23 -0000 Authentication-Results: sourceware.org; auth=none X-HELO: mail-qk1-f180.google.com Received: from mail-qk1-f180.google.com (HELO mail-qk1-f180.google.com) (209.85.222.180) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 17 Nov 2018 22:45:22 +0000 Received: by mail-qk1-f180.google.com with SMTP id d135so43280069qkc.12 for ; Sat, 17 Nov 2018 14:45:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:message-id:date:user-agent:mime-version; bh=Yq98qvtnonjVG6wuhGsRO3udg/xt8IRGcb0DkAjKXdc=; b=EXSHgJUgXDNzqneu2RM80s79Bw6c3vaU2WoghpjyUuUdWTuEJARoJbILXsVM3/GfDo kpiswnYLhbYiyhPn/Cc4BK7WJIGCv9FMqfGn9mtPBn4P+LpNspZAfkUfi/R++WCmnmqh arh7IMRJzSxBALQLRrdfBqbUqFmTbEWOynOq+dV8rKRavZUsaJ4xQHCjoXbeXbkUE/+d kshU/wquYBu9CwrDzhBCcxPZLiOYFTFZ9Lg8Xx+XIHfFJkN/rSDQWS8fj1y//Vrq0+tW 7CLsRvQNHx1BBbVYIIp9lfh5b1X4Ugpc7hyLUwJRFd8gKcoM9eRjAt8tVm834dzx3v3A yRBQ== Received: from localhost.localdomain (97-118-99-160.hlrn.qwest.net. [97.118.99.160]) by smtp.gmail.com with ESMTPSA id q5sm22046245qtq.20.2018.11.17.14.45.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Nov 2018 14:45:13 -0800 (PST) From: Martin Sebor Subject: [PATCH] avoid error_mark_node in -Wsizeof-pointer-memaccess (PR 88065) To: Gcc Patch List Message-ID: Date: Sat, 17 Nov 2018 15:45:10 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 X-IsSubscribed: yes -Wsizeof-pointer-memaccess fails with an ICE when one of the arguments is ill-formed (error_mark_node). To avoid the error the attached patch has the function bail in this case. Martin PR c/88065 - ICE in -Wsizeof-pointer-memaccess on an invalid strncpy gcc/c-family/ChangeLog: PR c/88065 * c-warn.c (sizeof_pointer_memaccess_warning): Bail if source or destination is an error. gcc/testsuite/ChangeLog: PR c/88065 * gcc.dg/Wsizeof-pointer-memaccess2.c: New test. Index: gcc/c-family/c-warn.c =================================================================== --- gcc/c-family/c-warn.c (revision 266240) +++ gcc/c-family/c-warn.c (working copy) @@ -784,7 +784,10 @@ sizeof_pointer_memaccess_warning (location_t *size if (idx >= 3) return; - if (sizeof_arg[idx] == NULL || sizeof_arg[idx] == error_mark_node) + if (src == error_mark_node + || dest == error_mark_node + || sizeof_arg[idx] == NULL + || sizeof_arg[idx] == error_mark_node) return; type = TYPE_P (sizeof_arg[idx]) Index: gcc/testsuite/gcc.dg/Wsizeof-pointer-memaccess2.c =================================================================== --- gcc/testsuite/gcc.dg/Wsizeof-pointer-memaccess2.c (nonexistent) +++ gcc/testsuite/gcc.dg/Wsizeof-pointer-memaccess2.c (working copy) @@ -0,0 +1,24 @@ +/* PR c/88065 - ICE in -Wsizeof-pointer-memaccess on an invalid strncpy + { dg-do compile } + { dg-options "-Wall" } */ + +typedef __SIZE_TYPE__ size_t; + +char* strncpy (char*, const char*, size_t); + +struct S { char a[4], b[6]; }; + +void test_invalid_dst (struct S *p) +{ + strncpy (q->a, p->b, sizeof p->b); /* { dg-error ".q. undeclared" } */ +} + +void test_invalid_src (struct S *p) +{ + strncpy (p->a, q->b, sizeof p->b); /* { dg-error ".q. undeclared" } */ +} + +void test_invalid_bound (struct S *p) +{ + strncpy (p->a, p->b, sizeof q->b); /* { dg-error ".q. undeclared" } */ +}