public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "anlauf at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/109861] Optimization is marking uninitialized C_PTR being passed to a C function, causes segfault. Date: Mon, 15 May 2023 21:22:28 +0000 [thread overview] Message-ID: <bug-109861-4-VQKPOd1non@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-109861-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109861 --- Comment #4 from anlauf at gcc dot gnu.org --- (In reply to Scot Breitenfeld from comment #3) > I guess the issue is whether marking TYPE(C_PTR) as CLOBBER is correct. I > looked through the 2018 standard and could not locate anything that > addresses this use case. Are you interpreting the possibility that a > TYPE(C_PTR) should not be declared INTENT(OUT)? Maybe I am missing your intention, but I interpret your code that you want to pass a (C) pointer to variable attr_rdata0 to return your result. But that needs to be intent(in). Your subroutine is not really supposed to return a pointer but a result in the location the pointer dereferences. Feel free to correct me. > I can instead change the subroutine to declare buf as > > INTEGER(C_INT), INTENT(OUT), TARGET :: buf > > and f_ptr = C_LOC(buf) and there is no issue. I cannot confirm this with my gcc installations, and there is no reason that this should make a difference. > So it seems to depend on the > TYPE of the argument being passed. There are cases where no clobber is currently generated. For example, if the dummy variable is a Fortran pointer, which has a completely different semantics from TYPE(C_PTR). Still I don't understand why you don't use INTENT(IN) for the pointer. In that case you could do things in the main like: CALL H5Aread_async_f(C_LOC(attr_rdata0)) which appears to represent what I am guessing, and which gets rejected for INTENT /= IN with a possibly more helpful error message.
next prev parent reply other threads:[~2023-05-15 21:22 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-05-15 14:00 [Bug fortran/109861] New: " brtnfld at hdfgroup dot org 2023-05-15 18:23 ` [Bug fortran/109861] " anlauf at gcc dot gnu.org 2023-05-15 18:49 ` anlauf at gcc dot gnu.org 2023-05-15 20:08 ` brtnfld at hdfgroup dot org 2023-05-15 21:22 ` anlauf at gcc dot gnu.org [this message] 2023-05-15 21:25 ` kargl at gcc dot gnu.org 2023-05-16 13:27 ` brtnfld at hdfgroup dot org 2023-05-16 13:29 ` brtnfld at hdfgroup dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-109861-4-VQKPOd1non@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).