{"action":"created","issue":{"url":"https://api.github.com/repos/flang-compiler/flang/issues/515","repository_url":"https://api.github.com/repos/flang-compiler/flang","labels_url":"https://api.github.com/repos/flang-compiler/flang/issues/515/labels{/name}","comments_url":"https://api.github.com/repos/flang-compiler/flang/issues/515/comments","events_url":"https://api.github.com/repos/flang-compiler/flang/issues/515/events","html_url":"https://github.com/flang-compiler/flang/issues/515","id":335766565,"node_id":"MDU6SXNzdWUzMzU3NjY1NjU=","number":515,"title":"[OpenMP][WRF but not from SPEC2017] segfault when writing to THREADPRIVATE string","user":{"login":"pawosm-arm","id":20681839,"node_id":"MDQ6VXNlcjIwNjgxODM5","avatar_url":"https://avatars2.githubusercontent.com/u/20681839?v=4","gravatar_id":"","url":"https://api.github.com/users/pawosm-arm","html_url":"https://github.com/pawosm-arm","followers_url":"https://api.github.com/users/pawosm-arm/followers","following_url":"https://api.github.com/users/pawosm-arm/following{/other_user}","gists_url":"https://api.github.com/users/pawosm-arm/gists{/gist_id}","starred_url":"https://api.github.com/users/pawosm-arm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pawosm-arm/subscriptions","organizations_url":"https://api.github.com/users/pawosm-arm/orgs","repos_url":"https://api.github.com/users/pawosm-arm/repos","events_url":"https://api.github.com/users/pawosm-arm/events{/privacy}","received_events_url":"https://api.github.com/users/pawosm-arm/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-06-26T11:02:34Z","updated_at":"2018-10-25T15:52:19Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Following code (frame/module_domain.F) segfaults at WRITE statement when the whole thing is built with -fopenmp:\r\n```\r\n        WRITE(wrf_err_message,*)&\r\n            'alloc_space_field: domain ',id,', ',num_bytes_allocated,' bytes allocated'\r\n        CALL  wrf_debug( 0, wrf_err_message )\r\n```\r\nwhere `wrf_err_message` is imported from other module in which it's declared OpenMP THREADPRIVATE (frame/module_wrf_error.F):\r\n```\r\nMODULE module_wrf_error\r\n  INTEGER           :: wrf_debug_level = 0\r\n  CHARACTER*256     :: wrf_err_message\r\n...\r\n    integer, parameter :: min_allowed_buffer_size=200\r\n!$OMP THREADPRIVATE (wrf_err_message)\r\nCONTAINS\r\n...\r\n```\r\n\r\nAs expected, the WRITE statement results in f90io_ldw_intern_init() call into the flang runtime (runtime/flang/ldwrite.c). For some reason, both CADR(cunit) and CLEN(cunit) are both zero, unless `!$OMP THREADPRIVATE (wrf_err_message)` line is removed. This clearly results in segfault on dereferencing CADR(cunit) down the line.\r\n\r\nNote that when I prepared small reproducer candidate, it worked, for any number of threads (in my reproducer I placed WRITE statement in a parallel region), so the interference must come from somewhere else, hence it requires more creative approach to nail it:\r\n```\r\nmodule wrfmod\r\n  implicit none\r\n  CHARACTER*256     :: wrf_err_message\r\n  !$OMP THREADPRIVATE (wrf_err_message)\r\nend module wrfmod\r\n\r\nprogram wrf\r\n  use wrfmod\r\n  implicit none\r\n  INTEGER(KIND=8)  :: num_bytes_allocated\r\n  INTEGER            :: id\r\n\r\n  id = 0\r\n  num_bytes_allocated = 0\r\n!$OMP PARALLEL\r\n  WRITE(wrf_err_message,*)&\r\n    'alloc_space_field: domain ',id,', ',num_bytes_allocated,' bytes allocated'\r\n  WRITE (*, *) wrf_err_message\r\n!$OMP END PARALLEL\r\nend program wrf\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/flang-compiler/flang/issues/comments/433105701","html_url":"https://github.com/flang-compiler/flang/issues/515#issuecomment-433105701","issue_url":"https://api.github.com/repos/flang-compiler/flang/issues/515","id":433105701,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMzEwNTcwMQ==","user":{"login":"gklimowicz","id":936096,"node_id":"MDQ6VXNlcjkzNjA5Ng==","avatar_url":"https://avatars3.githubusercontent.com/u/936096?v=4","gravatar_id":"","url":"https://api.github.com/users/gklimowicz","html_url":"https://github.com/gklimowicz","followers_url":"https://api.github.com/users/gklimowicz/followers","following_url":"https://api.github.com/users/gklimowicz/following{/other_user}","gists_url":"https://api.github.com/users/gklimowicz/gists{/gist_id}","starred_url":"https://api.github.com/users/gklimowicz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gklimowicz/subscriptions","organizations_url":"https://api.github.com/users/gklimowicz/orgs","repos_url":"https://api.github.com/users/gklimowicz/repos","events_url":"https://api.github.com/users/gklimowicz/events{/privacy}","received_events_url":"https://api.github.com/users/gklimowicz/received_events","type":"User","site_admin":false},"created_at":"2018-10-25T15:52:19Z","updated_at":"2018-10-25T15:52:19Z","author_association":"CONTRIBUTOR","body":"Aha. Fails only on Arm, I suspect. Correct?"}}
{"actor":{"display_login":"gklimowicz"}}