From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16494 invoked by alias); 4 Jun 2016 12:31:08 -0000 Mailing-List: contact fortran-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: fortran-owner@gcc.gnu.org Received: (qmail 16476 invoked by uid 89); 4 Jun 2016 12:31:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=H*M:pro, journal, aerospace, Journal X-HELO: mta-p6.oit.umn.edu Received: from mta-p6.oit.umn.edu (HELO mta-p6.oit.umn.edu) (134.84.196.206) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Sat, 04 Jun 2016 12:30:56 +0000 Received: from localhost (unknown [127.0.0.1]) by mta-p6.oit.umn.edu (Postfix) with ESMTP id 10FB9BB7 for ; Sat, 4 Jun 2016 12:30:54 +0000 (UTC) Received: from mta-p6.oit.umn.edu ([127.0.0.1]) by localhost (mta-p6.oit.umn.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1zmQBwpROYVf for ; Sat, 4 Jun 2016 07:30:53 -0500 (CDT) Received: from mail-io0-f198.google.com (mail-io0-f198.google.com [209.85.223.198]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mta-p6.oit.umn.edu (Postfix) with ESMTPS id D7F6DBA5 for ; Sat, 4 Jun 2016 07:30:53 -0500 (CDT) Received: by mail-io0-f198.google.com with SMTP id w64so53794397iow.1 for ; Sat, 04 Jun 2016 05:30:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=PLbKguRzgswfiCvVyckkB1oPO5XGtLwxIObzqaM6pqs=; b=Y7Q5P8iJpZqT+Qn5ay4NIn9fAwRsFmhG/52YlkpjvOwD65Nkqtc7wdBpLw32S4eo5d U338cFq7ccMefu4twuHXtDrCfdwWw27e/oBxQfiz9BFfIshSaCiJn5AZ2H3F4Bp8gPbl BMq59v/UWVq91219zAUPZBW+jlhf3FNG6jW/ozzmJm3vsedyH9SjfV9iljCRP58ZCDCI ApeCaWT9i3968wVc9Ay5KdSMaDImF6wCmiAt02jsOwfCRq3Yn5reSfy+X0R4s0bhPfW3 wiJjYiC186S/mUwSDkp7i9/nMLZhc8YSTri9hBya9xsGmnJBVb44VP86PSvFJHawKeok 8Zwg== X-Gm-Message-State: ALyK8tJ9Fmsi6wVDBiTfPMwE5ag/r9kGzwJARHrkyaqUYSDjTQVcPAZteIsHDFD9KBARWoI364Bta9WVidQfOqxCg0kzhuOLmrNMd+pwQoM3q+1VwmHqVsZCjQzvx6fuoCMD94mGI5A= X-Received: by 10.107.134.143 with SMTP id q15mr11031775ioi.25.1465043453363; Sat, 04 Jun 2016 05:30:53 -0700 (PDT) X-Received: by 10.107.134.143 with SMTP id q15mr11031740ioi.25.1465043453051; Sat, 04 Jun 2016 05:30:53 -0700 (PDT) Received: from [2601:449:8300:70bc:511:6830:204b:730c] ([2601:449:8300:70bc:511:6830:204b:730c]) by smtp.gmail.com with ESMTPSA id o2sm1844965ith.19.2016.06.04.05.30.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Jun 2016 05:30:51 -0700 (PDT) Date: Sat, 04 Jun 2016 12:31:00 -0000 From: "Ryan S. Elliott" To: fortran@gcc.gnu.org Subject: Re: iso_c_bindings and optimization interaction bug In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (OSX 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed X-SW-Source: 2016-06/txt/msg00014.txt.bz2 I've now submitted this as a bug to bugzilla. It is number 71412 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71412 On Fri, 29 Apr 2016, Ryan S. Elliott wrote: > Hello, > > I may have discovered a problem in the way gfortran optimizes > functions/subroutines when c interoperability (and specifically the c_loc() > intrinsic) are used. > > The attached code illustrates the issue. A variable is allocated and a > pointer is to the allocated memory is sent to C and stored in global memory. > Next the memory is initialized in the same routine that it was allocated. > Finally, in a different routine the memory pointer is retrieved from c and > the value stored in memory is printed. With optimization -O3 the > initialization is optimized out. With optimization -O0 the initialization > occurs and the code runs correctly. > > The typical output and sequence of steps to run the code is given below. > > I would greatly appreciate any analysis of this issue. Is it a bug? Is my > code non-compliant in some way? etc. > > Thanks, Ryan > > ------------------------------------------------------------------------------- > > vagrant@vagrant-ubuntu-trusty-64:/vagrant$ cd skeleton/ > > vagrant@vagrant-ubuntu-trusty-64:/vagrant/skeleton$ make > gfortran -m32 -O3 -g -Wall -pedantic -c skeleton-f.F90 > gcc -m32 -O3 -g -Wall -ansi -pedantic -c skeleton-c.c > gfortran -m32 -O3 -g -Wall skeleton*.o -o skeleton > > vagrant@vagrant-ubuntu-trusty-64:/vagrant/skeleton$ ./skeleton > -- in storePtr: pointer address --> 0x95caba0 <-- value --> -144534256 > -- just a print statement --> nothing > -- in getPtr: pointer address --> 0x95caba0 <-- value --> -144534256 > -- value of 'val2' variable --> -144534256 > > vagrant@vagrant-ubuntu-trusty-64:/vagrant/skeleton$ make clean > rm -f skeleton skeleton*.o *.mod > > vagrant@vagrant-ubuntu-trusty-64:/vagrant/skeleton$ make OPT=-O0 > gfortran -m32 -O0 -g -Wall -pedantic -c skeleton-f.F90 > gcc -m32 -O0 -g -Wall -ansi -pedantic -c skeleton-c.c > gfortran -m32 -O0 -g -Wall skeleton*.o -o skeleton > > vagrant@vagrant-ubuntu-trusty-64:/vagrant/skeleton$ ./skeleton > -- in storePtr: pointer address --> 0x8d09ba0 <-- value --> -143915760 > -- just a print statement --> nothing > -- in getPtr: pointer address --> 0x8d09ba0 <-- value --> 21 > -- value of 'val2' variable --> 21 > -- Ryan S. Elliott, Ph.D. and Associate Professor Aerospace Engineering & Mechanics, University of Minnesota (612) 624-2376 (626-1558 fax) http://www.aem.umn.edu/~relliott/ download vCard KIM Editor (http://openKIM.org) Associate Editor: Journal of Elasticity (http://springer.com/10659) MSI Associate Fellow (http://msi.umn.edu) CMT textbook webpage (http://modelingmaterials.org) ---------- A synonym is a word you use when you can't spell the word you first thought of. Burt Bacharach ----------