From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1934 invoked by alias); 14 Jun 2011 20:03:47 -0000 Received: (qmail 1924 invoked by uid 22791); 14 Jun 2011 20:03:46 -0000 X-SWARE-Spam-Status: No, hits=-2.3 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) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 14 Jun 2011 20:03:31 +0000 Received: from wpaz24.hot.corp.google.com (wpaz24.hot.corp.google.com [172.24.198.88]) by smtp-out.google.com with ESMTP id p5EK3VM9027433 for ; Tue, 14 Jun 2011 13:03:31 -0700 Received: from pzk9 (pzk9.prod.google.com [10.243.19.137]) by wpaz24.hot.corp.google.com with ESMTP id p5EK3T6J005710 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Tue, 14 Jun 2011 13:03:30 -0700 Received: by pzk9 with SMTP id 9so3409458pzk.5 for ; Tue, 14 Jun 2011 13:03:29 -0700 (PDT) Received: by 10.68.15.170 with SMTP id y10mr3063940pbc.364.1308081808992; Tue, 14 Jun 2011 13:03:28 -0700 (PDT) Received: from coign.google.com (dhcp-172-18-113-222.mtv.corp.google.com [172.18.113.222]) by mx.google.com with ESMTPS id x1sm5811161pbb.82.2011.06.14.13.03.27 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 14 Jun 2011 13:03:28 -0700 (PDT) From: Ian Lance Taylor To: "Abhijit Nandy" Cc: "gcc" Subject: Re: How to insert external global variable declarations and pointer assignment statements through GCC plugin GIMPLE pass References: <68C14D8B8C1E48DC8FE5F9DAB722DB7A@abhiPC> <84220E2299EC44BBBB8A67D9B09BBBE1@abhiPC> <8699ADBA137D45809135AD97814C9B06@abhiPC> Date: Wed, 15 Jun 2011 09:14:00 -0000 In-Reply-To: <8699ADBA137D45809135AD97814C9B06@abhiPC> (Abhijit Nandy's message of "Tue, 14 Jun 2011 20:38:30 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2011-06/txt/msg00253.txt.bz2 "Abhijit Nandy" writes: > So I guess DECL_EXTERNAL(var_decl) = 1 causes the var_decl to be set > as an external declaration in the following code : Yes. DECL_EXTERNAL corresponds to the "extern" storage class specifier in C/C++. > I have another question. Right now I create the following declaration > char *p; > > using : > tree temp = create_tmp_var(TREE_TYPE(TREE_TYPE(elfset_decl)), "p"); > > where elfset_decl is set to be char* in a separate function. That creates a temporary variable. > However is there another way to create a pointer to char, especially > if I want the exact identifier 'p' instead of > char * p.1; > > which the gimple pass dump is showing me. > > I tried to do it as follows : > tree var_decl1 = build_decl(UNKNOWN_LOCATION, VAR_DECL, > get_identifier("p"), char_type_node); > TREE_STATIC(var_decl1) = 0; > DECL_EXTERNAL(var_decl1) = 0; > rest_of_decl_compilation (var_decl1, 1, 0); > > But nothing appears in the gimple pass dump. I think this may be due > to not actually inserting the declaration in the tree using a gimple > function. For a local variable you don't need to call rest_of_decl_compilation. If you want a local variable which is not a temporary variable, then you need to build a BLOCK and a BIND_EXPR which define the variable in some scope. The BIND_EXPR will point to the block, and the BIND_EXPR then needs to be added into the function code somehow so that the rest of the compiler sees it. Ian