flang
flang copied to clipboard
Fix a segmentation fault related to assumed length character functions.
When an assumed length character function is not external, its symbol type will at first be set to ST_IDENT and the AUTOBJ field will be set to 1. When a invocation of it is encountered, its symbol type will be modified to ST_PROC. But its AUTOBJ
remains 1 which will causes a segmentation fault later.
This patch fixes the issue by removing the function from the automatic data list and setting its AUTOBJ to 0.
The other issue is that flang sets the return length as 0 for assumed length character functions, causing an ICE afterwards.
This patch fixes it by modifying the ast type of the function (from ‘A_FUNC’ to A_CALL), and adding code to process the argument for the length.
Thanks for working on this. You should get a failure once you re-base it (#1157). Below change should fix that. Can I request you to include below change in your patch ?
--- a/tools/flang2/flang2exe/lldebug.cpp
+++ b/tools/flang2/flang2exe/lldebug.cpp
@@ -2822,7 +2822,6 @@ lldbg_create_deferred_len_string_type_mdnode(LL_DebugInfo *db, SPTR sptr,
if (SDSCG(REVMIDLNKG(sptr)) && (DTY(DTYPEG(sptr)) == TY_PTR)) {
/* get the array descriptor */
SPTR sdscsptr = SDSCG(REVMIDLNKG(sptr));
- LL_Type *dataloctype = LLTYPE(sdscsptr);
BLKINFO *blk_info = get_lexical_block_info(db, sdscsptr, true);
LL_MDRef file_mdnode;
if (ll_feature_debug_info_need_file_descriptions(&db->module->ir))
@@ -2850,7 +2849,7 @@ lldbg_create_deferred_len_string_type_mdnode(LL_DebugInfo *db, SPTR sptr,
/* emit an @llvm.dbg.declare with required !DIExpression */
LL_MDRef expr_mdnode = lldbg_emit_expression_mdnode(db, 2, add, v1);
- insert_llvm_dbg_declare(mdLen, sdscsptr, dataloctype,
+ insert_llvm_dbg_declare(mdLen, sdscsptr, (LL_Type *) NULL,
make_mdref_op(expr_mdnode), OPF_NONE);
mdLenExp = lldbg_emit_empty_expression_mdnode(db);
@bryanpkc can you add the above suggested changes to the PR?
Thanks for working on this. You should get a failure once you re-base it (#1157). Below change should fix that. Can I request you to include below change in your patch ?
--- a/tools/flang2/flang2exe/lldebug.cpp +++ b/tools/flang2/flang2exe/lldebug.cpp @@ -2822,7 +2822,6 @@ lldbg_create_deferred_len_string_type_mdnode(LL_DebugInfo *db, SPTR sptr, if (SDSCG(REVMIDLNKG(sptr)) && (DTY(DTYPEG(sptr)) == TY_PTR)) { /* get the array descriptor */ SPTR sdscsptr = SDSCG(REVMIDLNKG(sptr)); - LL_Type *dataloctype = LLTYPE(sdscsptr); BLKINFO *blk_info = get_lexical_block_info(db, sdscsptr, true); LL_MDRef file_mdnode; if (ll_feature_debug_info_need_file_descriptions(&db->module->ir)) @@ -2850,7 +2849,7 @@ lldbg_create_deferred_len_string_type_mdnode(LL_DebugInfo *db, SPTR sptr, /* emit an @llvm.dbg.declare with required !DIExpression */ LL_MDRef expr_mdnode = lldbg_emit_expression_mdnode(db, 2, add, v1); - insert_llvm_dbg_declare(mdLen, sdscsptr, dataloctype, + insert_llvm_dbg_declare(mdLen, sdscsptr, (LL_Type *) NULL, make_mdref_op(expr_mdnode), OPF_NONE); mdLenExp = lldbg_emit_empty_expression_mdnode(db);
OK, already added.
@bryanpkc This PR has been updated.
@qiaozhang-hnc Could you rebase this branch again?
@qiaozhang-hnc Could you rebase this branch again?
Rebased.