From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.theobroma-systems.com (vegas.theobroma-systems.com [144.76.126.164]) by sourceware.org (Postfix) with ESMTPS id 395AF3857C41 for ; Tue, 25 Aug 2020 13:08:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 395AF3857C41 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=theobroma-systems.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=erick.ochoa@theobroma-systems.com Received: from mail.linser.at ([80.109.168.170]:53838 helo=Martins-MacBook-Air.local) by mail.theobroma-systems.com with esmtpsa (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1kAYgp-0001hr-RT; Tue, 25 Aug 2020 15:08:39 +0200 To: GCC Development From: Erick Ochoa Cc: Philipp Tomsich , =?UTF-8?Q?Christoph_M=c3=bcllner?= Subject: Do all global structure variables escape in IPA-PTA? Message-ID: Date: Tue, 25 Aug 2020 15:09:13 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Aug 2020 13:08:43 -0000 Hi, I'm trying to understand how the escape analysis in IPA-PTA works. I was testing a hypothesis where if a structure contains an array of characters and this array of characters is passed to fopen, the structure and all subfields will escape. To do this, I made a program that has a global structure variable foo2 that is has a field passed as an argument to fopen. I also made another variable foo whose array is initialized by the result of rand. However, after compiling this program with -flto -flto-partition=none -fipa -fdump-ipa-pta -fdump-tree-all-all -Ofast (gcc --version 10.2.0) E.g. #include #include #include struct foo_t { char buffer1[100]; char buffer2[100]; }; struct foo_t foo; struct foo_t foo2; int main(int argc, char** argv) { fopen(foo2.buffer1, "r"); for (int i = 0; i < 100; i++) { foo.buffer1[i] = rand(); } int i = rand(); int retval = foo.buffer1[i % 100]; return retval; } I see the PTA dump state the following: ESCAPED = { STRING ESCAPED NONLOCAL foo2 } foo = { ESCAPED NONLOCAL } foo2 = { ESCAPED NONLOCAL } which I understand as * something externally visible might point to foo2 * foo2 might point to something externally visible * foo might point to something externally visible I have seen that global variables are stored in the .gnu.lto_.decls LTO file section. In the passes I have worked on I have ignored global variables. But can foo and foo2 be marked as escaping because the declarations are not streamed in yet? Or is there another reason I am not seeing? I am aware of aware of the several TODOs at the beginning of gcc/tree-ssa-structalias.c but I am unsure if they contribute to these variables being marked as escaping. (Maybe TODO 1 and TODO 2?) Just FYI, I've been reading: * Structure Aliasing in GCC * Gimple Alias Improvements for GCC 4.5 * Memory SSA - A Unified Approach for Sparsely Representing Memory Operations Thanks, I appreciate all help!