From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 78136 invoked by alias); 23 Dec 2019 17:30:44 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 78121 invoked by uid 89); 23 Dec 2019 17:30:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-6.7 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.1 spammy=astruct_s, HX-Spam-Relays-External:sk:mail.th, drops, H*RU:sk:mail.th X-HELO: mail.theobroma-systems.com Received: from vegas.theobroma-systems.com (HELO mail.theobroma-systems.com) (144.76.126.164) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Dec 2019 17:30:41 +0000 Received: from 198-48-134-99.cpe.pppoe.ca ([198.48.134.99]:52170 helo=[192.168.1.147]) by mail.theobroma-systems.com with esmtpsa (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1ijRXL-0007Ly-CE; Mon, 23 Dec 2019 18:30:31 +0100 From: Erick Ochoa Subject: Question about sizeof after struct change To: GCC Development , =?UTF-8?Q?Christoph_M=c3=bcllner?= , "Dr. Philipp Tomsich" Message-ID: Date: Mon, 23 Dec 2019 17:30:00 -0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2019-12/txt/msg00390.txt.bz2 Hi, I am working on an LTO pass which drops unused fields on structs. On my tests, I found that the gimple generated for `sizeof` is a constant. For example, for the following C code: ``` struct astruct_s { _Bool c; _Bool a; _Bool b; }; struct astruct_s astruct; int main() { int size = sizeof(astruct); return 0; } ``` Produces the following gimple code: ``` size_1 = 3; _2 = 0; : return _2; ``` Is there a way to determine where the value assigned to size_1 is obtained from? I would like to 1. inspect sizeof statements 2. determine whether the argument of sizeof is struct astruct_s 3. substitute struct astruct_s with a modified version of struct astruct_s which has field `a` removed. Therefore, at the end of this transformation we would have size_1 = 2; Similary, I would like pointer arithmetic to be affected. For example: ``` struct astruct_s { _Bool c; _Bool a; _Bool b; }; struct astruct_s astruct; int main() { _Bool *c = &astruct.c; _Bool *b = &astruct.b; ptrdiff_t d = b - c; printf("%d\n", d); } ``` Produces the following gimple code: ``` c_3 = &astruct.c; b_4 = &astruct.b; d_5 = b_4 - c_3; ``` Running the code results in the value 2 being printed . After running the transformation, the result should be 1. Can anyone point me in the right direction? So far I have tried changing the TYPE_FIELDS to drop field a, but that doesn't work and it is not general. I also have some code which creates a copy of RECORD_TYPE tree and modifies the tree and creates a new identifier for this modified RECORD_TYPE tree. However, I believe this may still not produce the intended behaviour. Any help is appreciated. Thanks! -Erick