flang icon indicating copy to clipboard operation
flang copied to clipboard

Fix a segmentation fault related to assumed length character functions.

Open qiaozhang-hnc opened this issue 3 years ago • 4 comments

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.

qiaozhang-hnc avatar Jun 15 '21 03:06 qiaozhang-hnc

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);

alokkrsharma avatar Mar 22 '22 09:03 alokkrsharma

@bryanpkc can you add the above suggested changes to the PR?

kiranchandramohan avatar Mar 23 '22 15:03 kiranchandramohan

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.

qiaozhang-hnc avatar Mar 24 '22 00:03 qiaozhang-hnc

@bryanpkc This PR has been updated.

qiaozhang-hnc avatar Apr 13 '22 10:04 qiaozhang-hnc

@qiaozhang-hnc Could you rebase this branch again?

bryanpkc avatar Aug 14 '22 16:08 bryanpkc

@qiaozhang-hnc Could you rebase this branch again?

Rebased.

qiaozhang-hnc avatar Aug 18 '22 09:08 qiaozhang-hnc