From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25737 invoked by alias); 5 Jan 2007 06:48:08 -0000 Received: (qmail 25722 invoked by uid 22791); 5 Jan 2007 06:48:07 -0000 X-Spam-Check-By: sourceware.org Received: from smtp-105-friday.nerim.net (HELO kraid.nerim.net) (62.4.16.105) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 05 Jan 2007 06:48:00 +0000 Received: from zeus.integrable-solutions.net (gdr.net1.nerim.net [62.212.99.186]) by kraid.nerim.net (Postfix) with ESMTP id C84EE40E31; Fri, 5 Jan 2007 07:47:55 +0100 (CET) Received: from zeus.integrable-solutions.net (localhost [127.0.0.1]) by zeus.integrable-solutions.net (8.13.3/8.13.3/SuSE Linux 0.7) with ESMTP id l056lr04000500; Fri, 5 Jan 2007 07:47:56 +0100 Received: (from gdr@localhost) by zeus.integrable-solutions.net (8.13.3/8.13.3/Submit) id l056lr4i000499; Fri, 5 Jan 2007 07:47:53 +0100 To: Ian Lance Taylor Cc: Andrew Pinski , gcc-patches@gcc.gnu.org Subject: Re: PATCH RFA: C++ frontend warning: comparing function pointer to NULL References: <200701041848.l04Im9Z0015493@localhost.localdomain> From: Gabriel Dos Reis In-Reply-To: Date: Fri, 05 Jan 2007 06:48:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2007-01/txt/msg00341.txt.bz2 Ian Lance Taylor writes: | Andrew Pinski writes: | | > I remember when the C code was added for this warning (which looked almost | > the same), we would ICE for code like: | > | > int f(int a) | > { | > return (&a) == 0; | > } | > | > Looking at the above code looks like we would ICE in the C++ code with the | > above testcase. | > The C front-end checks for PARM and LABEL decls too: | > if (TREE_CODE (op0) == ADDR_EXPR | > && DECL_P (TREE_OPERAND (op0, 0)) | > && (TREE_CODE (TREE_OPERAND (op0, 0)) == PARM_DECL | > || TREE_CODE (TREE_OPERAND (op0, 0)) == LABEL_DECL | > || !DECL_WEAK (TREE_OPERAND (op0, 0)))) | > | > Could you add a testcase for the argument and label cases and make sure | > we don't ICE on them? | | You're absolutely right. Thanks a lot for the pointer. | | Here is the updated, retested, patch. | | Ian | | Index: gcc/cp/typeck.c | =================================================================== | --- gcc/cp/typeck.c (revision 120376) | +++ gcc/cp/typeck.c (working copy) | @@ -3334,10 +3334,28 @@ build_binary_op (enum tree_code code, tr | "comparison"); | else if ((code0 == POINTER_TYPE || TYPE_PTRMEM_P (type0)) | && null_ptr_cst_p (op1)) | - result_type = type0; | + { | + if (TREE_CODE (op0) == ADDR_EXPR | + && DECL_P (TREE_OPERAND (op0, 0)) | + && (TREE_CODE (TREE_OPERAND (op0, 0)) == PARM_DECL | + || TREE_CODE (TREE_OPERAND (op0, 0)) == LABEL_DECL | + || !DECL_WEAK (TREE_OPERAND (op0, 0)))) | + warning (OPT_Walways_true, "the address of %qD will never be NULL", | + TREE_OPERAND (op0, 0)); | + result_type = type0; | + } | else if ((code1 == POINTER_TYPE || TYPE_PTRMEM_P (type1)) | && null_ptr_cst_p (op0)) | - result_type = type1; | + { | + if (TREE_CODE (op1) == ADDR_EXPR | + && DECL_P (TREE_OPERAND (op1, 0)) | + && (TREE_CODE (TREE_OPERAND (op0, 0)) == PARM_DECL | + || TREE_CODE (TREE_OPERAND (op0, 0)) == LABEL_DECL | + || !DECL_WEAK (TREE_OPERAND (op0, 0)))) | + warning (OPT_Walways_true, "the address of %qD will never be NULL", | + TREE_OPERAND (op1, 0)); | + result_type = type1; You get brownie point, if you could abstract that check into a separate (static inline) function. Otherwise, OK. -- Gaby