From patchwork Fri Apr 15 02:01:30 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lawrence Crowl X-Patchwork-Id: 91312 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id BF83DB6FBE for ; Fri, 15 Apr 2011 12:02:00 +1000 (EST) Received: (qmail 32283 invoked by alias); 15 Apr 2011 02:01:54 -0000 Received: (qmail 32144 invoked by uid 22791); 15 Apr 2011 02:01:50 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.67) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 15 Apr 2011 02:01:40 +0000 Received: from kpbe19.cbf.corp.google.com (kpbe19.cbf.corp.google.com [172.25.105.83]) by smtp-out.google.com with ESMTP id p3F21Wmg009342; Thu, 14 Apr 2011 19:01:33 -0700 Received: from jade.mtv.corp.google.com (jade.mtv.corp.google.com [172.18.116.94]) by kpbe19.cbf.corp.google.com with ESMTP id p3F21ViU027546; Thu, 14 Apr 2011 19:01:31 -0700 Received: by jade.mtv.corp.google.com (Postfix, from userid 21482) id 0021F222679; Thu, 14 Apr 2011 19:01:30 -0700 (PDT) To: reply@codereview.appspotmail.com, dnovillo@google.com, tromey@redhat.com, gcc-patches@gcc.gnu.org Subject: [pph] Macro Validation Correction (issue4425041) Message-Id: <20110415020131.0021F222679@jade.mtv.corp.google.com> Date: Thu, 14 Apr 2011 19:01:30 -0700 (PDT) From: crowl@google.com (Lawrence Crowl) X-System-Of-Record: true X-IsSubscribed: yes 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 An earlier change reduced the number of bits in cpp_hashnode.directive_index from 7 to 5, as that was sufficient for indexing the directives. Tom Tromey asked for a static check on the size. This patch adds that check. Unfortunately, five bits are not sufficient for the alternate use of cpp_hashnode.directive_index as a named operator index. So, I have reverted the number of bits from five back to seven. As a result, we now have 34 bits in small fields, and the size of cpp_hashnode will increase from two to three words on 32-bit systems. The size on 64-bit systems remains unchanged because these bits go into an alignment gap. --- This patch is available for review at http://codereview.appspot.com/4425041 Index: libcpp/ChangeLog.pph 2011-04-14 Lawrence Crowl * include/cpplib.h (cpp_hashnode): Use a macro for the number of bits in the directive_index bitfield. Change the number of bits back to 7. * directives.c (DIRECTIVE_TABLE): Add a gcc-build-time check that the index of the directive table fits within the number of bits above. * init.c (operator_array): Separate the named operator table into a macro. Use it in operator_array. Test that the values fit within the number of bits above. Index: libcpp/directives.c =================================================================== --- libcpp/directives.c (revision 172457) +++ libcpp/directives.c (working copy) @@ -137,10 +137,7 @@ static void cpp_pop_definition (cpp_read pcmcia-cs-3.0.9). This is no longer important as directive lookup is now O(1). All extensions other than #warning, #include_next, and #import are deprecated. The name is where the extension - appears to have come from. - - Make sure the bitfield directive_index in include/cpplib.h is large - enough to index the entire table. */ + appears to have come from. */ #define DIRECTIVE_TABLE \ D(define, T_DEFINE = 0, KANDR, IN_I) /* 270554 */ \ @@ -181,6 +178,13 @@ enum }; #undef D +/* Make sure the bitfield directive_index in include/cpplib.h is large + enough to index the entire table. */ + +unsigned char too_many_directives_for_bitfield[ + N_DIRECTIVES <= (1 << CPP_HASHNODE_INDEX_BITS) + ? 1 : -1]; + #define D(name, t, origin, flags) \ { do_##name, (const uchar *) #name, \ sizeof #name - 1, origin, flags }, Index: libcpp/include/cpplib.h =================================================================== --- libcpp/include/cpplib.h (revision 172457) +++ libcpp/include/cpplib.h (working copy) @@ -650,12 +650,14 @@ union GTY(()) _cpp_hashnode_value { unsigned short GTY ((tag ("NTV_ARGUMENT"))) arg_index; }; +#define CPP_HASHNODE_INDEX_BITS 7 + struct GTY(()) cpp_hashnode { struct ht_identifier ident; unsigned int is_directive : 1; - unsigned int directive_index : 5; /* If is_directive, - then index into directive table. - Otherwise, a NODE_OPERATOR. */ + unsigned int directive_index : CPP_HASHNODE_INDEX_BITS; + /* If is_directive, then index into directive table. + Otherwise, a NODE_OPERATOR. */ unsigned int used_by_directive : 1; /* In an active #if, #define etc. */ unsigned int expanded_to_text : 1; /* Produces tokens for parser. */ unsigned char rid_code; /* Rid code - for front ends. */ Index: libcpp/init.c =================================================================== --- libcpp/init.c (revision 172457) +++ libcpp/init.c (working copy) @@ -375,23 +375,34 @@ struct builtin_operator const unsigned short value; }; -#define B(n, t) { DSC(n), t } +#define NAMED_OPER_TABLE \ + B("and", CPP_AND_AND) \ + B("and_eq", CPP_AND_EQ) \ + B("bitand", CPP_AND) \ + B("bitor", CPP_OR) \ + B("compl", CPP_COMPL) \ + B("not", CPP_NOT) \ + B("not_eq", CPP_NOT_EQ) \ + B("or", CPP_OR_OR) \ + B("or_eq", CPP_OR_EQ) \ + B("xor", CPP_XOR) \ + B("xor_eq", CPP_XOR_EQ) \ + +#define B(n, t) { DSC(n), t }, static const struct builtin_operator operator_array[] = { - B("and", CPP_AND_AND), - B("and_eq", CPP_AND_EQ), - B("bitand", CPP_AND), - B("bitor", CPP_OR), - B("compl", CPP_COMPL), - B("not", CPP_NOT), - B("not_eq", CPP_NOT_EQ), - B("or", CPP_OR_OR), - B("or_eq", CPP_OR_EQ), - B("xor", CPP_XOR), - B("xor_eq", CPP_XOR_EQ) + NAMED_OPER_TABLE }; #undef B +/* Verify that the indicies of the named operators fit within the + number of bits available. */ + +#define B(n, t) unsigned char t ## _too_large_for_bitfield[ \ + t < (1 << CPP_HASHNODE_INDEX_BITS) ? 1 : -1]; +NAMED_OPER_TABLE +#undef B + /* Mark the C++ named operators in the hash table. */ static void mark_named_operators (cpp_reader *pfile, int flags)