From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2845 invoked by alias); 14 Jul 2014 11:09:31 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 2686 invoked by uid 48); 14 Jul 2014 11:09:21 -0000 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/41227] COMMON block, BIND(C) and LTO interoperability issues Date: Mon, 14 Jul 2014 11:09:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 4.5.0 X-Bugzilla-Keywords: lto, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-07/txt/msg00876.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41227 --- Comment #15 from Richard Biener --- Ok, the warning is implemented with checking gimple type compatibility in lto/lto-symtab.c: if (!types_compatible_p (TREE_TYPE (prevailing->decl), TREE_TYPE (decl))) diagnosed_p |= warning_at (DECL_SOURCE_LOCATION (decl), 0, "type of %qD does not match original " "declaration", decl); I'm not sure it is wise to drop the outermost single-element struct type from all types during compute of canonical types. We can adjust gimple_get_alias_set to at least assign the same alias sets to such struct and its element, but that doesn't cure the warning (obviously). At least that avoids generating wrong code... like with @@ -2307,6 +2308,27 @@ gimple_get_alias_set (tree t) || t == unsigned_char_type_node) return 0; + /* For C, Fortran interoperability assign the same alias-set to + a record with a single element as that element. */ + if (TREE_CODE (t) == RECORD_TYPE) + { + tree f = NULL_TREE; + for (tree fld = TYPE_FIELDS (t); fld != NULL_TREE; fld = TREE_CHAIN (fld)) + { + if (TREE_CODE (fld) != FIELD_DECL) + continue; + if (f == NULL_TREE) + f = fld; + else + { + f = NULL_TREE; + break; + } + } + if (f) + return get_alias_set (TREE_TYPE (f)); + } + /* Allow aliasing between signed and unsigned variants of the same but I'm sure we don't want to call get_alias_set on all globals during WPA phase (Where the warning is emitted). Humm. We can special-case that case in lto-symtab.c of course. Btw, what kind of single-elements can I expect? I suppose they can be arbitrary (so aggregate as well)?