From 343ff521e25550b49e2217b774ffb7d9d0c8d1f7 Mon Sep 17 00:00:00 2001 From: Alok Kumar Sharma Date: Thu, 17 Dec 2020 21:46:37 +0530 Subject: [PATCH] [DebugInfo] Debug support for module array variables with pointer/allocatable attribute --- test/debug_info/module_allocatable_arr.f90 | 19 +++++++++++++++ test/debug_info/module_pointer_arr.f90 | 21 ++++++++++++++++ tools/flang2/flang2exe/lldebug.cpp | 28 +++++++++++++++------- 3 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 test/debug_info/module_allocatable_arr.f90 create mode 100644 test/debug_info/module_pointer_arr.f90 diff --git a/test/debug_info/module_allocatable_arr.f90 b/test/debug_info/module_allocatable_arr.f90 new file mode 100644 index 000000000000..317e1c645066 --- /dev/null +++ b/test/debug_info/module_allocatable_arr.f90 @@ -0,0 +1,19 @@ +!RUN: %flang -gdwarf-4 -S -emit-llvm %s -o - | FileCheck %s + +!CHECK-LABEL: distinct !DIGlobalVariable(name: "alc_arr" +!CHECK-SAME: type: [[TYPE:![0-9]+]] +!CHECK: [[TYPE]] = !DICompositeType(tag: DW_TAG_array_type, +!CHECK-SAME: elements: [[ELEMENTS:![0-9]+]], dataLocation: !DIExpression(DW_OP_push_object_address, DW_OP_deref), allocated: !DIExpression(DW_OP_push_object_address, DW_OP_deref) +!CHECK: [[ELEMENTS]] = !{[[ELEMENT:![0-9]+]]} +!CHECK: [[ELEMENT]] = !DISubrange(lowerBound: !DIExpression(DW_OP_push_object_address, DW_OP_plus_uconst, 96, DW_OP_deref), upperBound: !DIExpression(DW_OP_push_object_address, DW_OP_plus_uconst, 136, DW_OP_deref), stride: !DIExpression(DW_OP_push_object_address, DW_OP_plus_uconst, 128, DW_OP_deref, DW_OP_push_object_address, DW_OP_plus_uconst, 40, DW_OP_deref, DW_OP_mul)) + +module mod_allocatable_arr + integer, allocatable :: alc_arr(:) +end module + +program main + use mod_allocatable_arr + allocate (alc_arr(10)) + alc_arr = 99 + print *, alc_arr +end program diff --git a/test/debug_info/module_pointer_arr.f90 b/test/debug_info/module_pointer_arr.f90 new file mode 100644 index 000000000000..b374525e0dac --- /dev/null +++ b/test/debug_info/module_pointer_arr.f90 @@ -0,0 +1,21 @@ +!RUN: %flang -gdwarf-4 -S -emit-llvm %s -o - | FileCheck %s + +!CHECK-LABEL: distinct !DIGlobalVariable(name: "ptr_arr" +!CHECK-SAME: type: [[TYPE:![0-9]+]] +!CHECK: [[TYPE]] = !DICompositeType(tag: DW_TAG_array_type, +!CHECK-SAME: elements: [[ELEMENTS:![0-9]+]], dataLocation: !DIExpression(DW_OP_push_object_address, DW_OP_deref), associated: !DIExpression(DW_OP_push_object_address, DW_OP_deref) +!CHECK: [[ELEMENTS]] = !{[[ELEMENT:![0-9]+]]} +!CHECK: [[ELEMENT]] = !DISubrange(lowerBound: !DIExpression(DW_OP_push_object_address, DW_OP_plus_uconst, 96, DW_OP_deref), upperBound: !DIExpression(DW_OP_push_object_address, DW_OP_plus_uconst, 136, DW_OP_deref), stride: !DIExpression(DW_OP_push_object_address, DW_OP_plus_uconst, 128, DW_OP_deref, DW_OP_push_object_address, DW_OP_plus_uconst, 40, DW_OP_deref, DW_OP_mul)) + +module mod_pointer_arr + integer, pointer :: ptr_arr(:) +end module + +program main +use mod_pointer_arr + integer, target :: tgtarr(20) + tgtarr(1:20:2) = 22 + tgtarr(2:20:2) = 33 + ptr_arr => tgtarr(1:20:2) + print *, ptr_arr +end program diff --git a/tools/flang2/flang2exe/lldebug.cpp b/tools/flang2/flang2exe/lldebug.cpp index 913a3511ef42..4d5af7202966 100644 --- a/tools/flang2/flang2exe/lldebug.cpp +++ b/tools/flang2/flang2exe/lldebug.cpp @@ -581,11 +581,12 @@ lldbg_create_global_variable_mdnode(LL_DebugInfo *db, LL_MDRef context, LLMD_Builder mdb2 = llmd_init(db->module); llmd_set_class(mdb2, LL_DIGlobalVariableExpression); llmd_add_md(mdb2, cur_mdnode); - /* Handle the Fortran allocatable array cases. Emit expression mdnode with a - * sigle argument of DW_OP_deref because of using sptr array$p instead of - * sptr array for debugging purpose. - */ - if (ftn_array_need_debug_info(sptr)) { + if (!ll_feature_debug_info_ver90(&cpu_llvm_module->ir) && + ftn_array_need_debug_info(sptr)) { + /* Handle the Fortran allocatable array cases. Emit expression mdnode with + * a sigle argument of DW_OP_deref because of using sptr array$p instead + * of sptr array for debugging purpose. + */ const unsigned deref = lldbg_encode_expression_arg(LL_DW_OP_deref, 0); expr_mdnode = lldbg_emit_expression_mdnode(db, 1, deref); } else @@ -3316,10 +3317,20 @@ lldbg_emit_global_variable(LL_DebugInfo *db, SPTR sptr, ISZ_T off, int findex, savedScopeIsGlobal = db->scope_is_global; db->scope_is_global = true; db->gbl_var_sptr = sptr; - type_mdnode = - lldbg_emit_type(db, DTYPEG(sptr), sptr, findex, false, false, false); + SPTR new_sptr = (SPTR)REVMIDLNKG(sptr); get_extra_info_for_sptr(&display_name, &scope_mdnode, &type_mdnode, db, sptr); - display_name = SYMNAME(sptr); + if (ll_feature_debug_info_ver90(&cpu_llvm_module->ir) && CCSYMG(sptr) && + new_sptr && (STYPEG(new_sptr) == ST_ARRAY) && + (POINTERG(new_sptr) || ALLOCATTRG(new_sptr)) && SDSCG(new_sptr)) { + type_mdnode = lldbg_emit_type(db, DTYPEG(new_sptr), new_sptr, findex, false, + false, false); + display_name = SYMNAME(new_sptr); + flags = CCSYMG(new_sptr) ? DIFLAG_ARTIFICIAL : 0; + } else { + type_mdnode = + lldbg_emit_type(db, DTYPEG(sptr), sptr, findex, false, false, false); + flags = CCSYMG(sptr) ? DIFLAG_ARTIFICIAL : 0; + } file_mdnode = ll_feature_debug_info_need_file_descriptions(&db->module->ir) ? get_filedesc_mdnode(db, findex) : lldbg_emit_file(db, findex); @@ -3334,7 +3345,6 @@ lldbg_emit_global_variable(LL_DebugInfo *db, SPTR sptr, ISZ_T off, int findex, } else { fwd = ll_get_md_null(); } - flags = CCSYMG(sptr) ? DIFLAG_ARTIFICIAL : 0; if (!ll_feature_debug_info_ver90(&db->module->ir)) { if (ftn_array_need_debug_info(sptr)) { SPTR array_sptr = (SPTR)REVMIDLNKG(sptr);