From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13018 invoked by alias); 25 Mar 2009 19:43:42 -0000 Received: (qmail 13007 invoked by uid 22791); 25 Mar 2009 19:43:40 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 25 Mar 2009 19:43:35 +0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n2PJhXb5010766 for ; Wed, 25 Mar 2009 15:43:33 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n2PJhPvS009249; Wed, 25 Mar 2009 15:43:25 -0400 Received: from opsy.redhat.com (vpn-13-99.rdu.redhat.com [10.11.13.99]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n2PJhUwV030140; Wed, 25 Mar 2009 15:43:31 -0400 Received: by opsy.redhat.com (Postfix, from userid 500) id 12EB337815D; Wed, 25 Mar 2009 13:43:28 -0600 (MDT) To: gdb-patches@sourceware.org Subject: RFC: don't let CHECK_TYPEDEF yield a value From: Tom Tromey Reply-To: tromey@redhat.com Date: Wed, 25 Mar 2009 19:56:00 -0000 Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-03/txt/msg00559.txt.bz2 While reading stack.c I noticed this code: type = CHECK_TYPEDEF (SYMBOL_TYPE (sym)); while (TYPE_CODE (type) == TYPE_CODE_REF) type = CHECK_TYPEDEF (TYPE_TARGET_TYPE (type)); Because CHECK_TYPEDEF side-effects its argument, this can change the type of a symbol. That seems like a bug to me. I thought perhaps CHECK_TYPEDEF would be safer if it were explicitly a statement, that is, if it could not yield a value. This does not make it completely safe, but it does help emphasize the difference between CHECK_TYPEDEF and check_typedef. All the other CHECK_TYPEDEF calls appear to be safe. Built and regtested on x86-64 (compile farm). Let me know what you think. Tom 2009-03-25 Tom Tromey * gdbtypes.h (CHECK_TYPEDEF): Don't yield a value. * stack.c (print_this_frame_argument_p): Use check_typedef. diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 816a208..3c4e948 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -1185,7 +1185,10 @@ extern struct type *lookup_signed_typename (char *); extern struct type *check_typedef (struct type *); -#define CHECK_TYPEDEF(TYPE) (TYPE) = check_typedef (TYPE) +#define CHECK_TYPEDEF(TYPE) \ + do { \ + (TYPE) = check_typedef (TYPE); \ + } while (0) extern void check_stub_method_group (struct type *, int); diff --git a/gdb/stack.c b/gdb/stack.c index f185841..c780348 100644 --- a/gdb/stack.c +++ b/gdb/stack.c @@ -181,9 +181,9 @@ print_this_frame_argument_p (struct symbol *sym) /* The user asked to print only the scalar arguments, so do not print the non-scalar ones. */ - type = CHECK_TYPEDEF (SYMBOL_TYPE (sym)); + type = check_typedef (SYMBOL_TYPE (sym)); while (TYPE_CODE (type) == TYPE_CODE_REF) - type = CHECK_TYPEDEF (TYPE_TARGET_TYPE (type)); + type = check_typedef (TYPE_TARGET_TYPE (type)); switch (TYPE_CODE (type)) { case TYPE_CODE_ARRAY: