Bug 66969 - Internal compiler error, segmentation fault
Summary: Internal compiler error, segmentation fault
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.9.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid, ice-on-invalid-code
: 86120 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-07-22 14:22 UTC by Luiz Gustavo
Modified: 2023-10-15 20:23 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-08-30 00:00:00


Attachments
Source code and system info (1.33 KB, application/x-tar)
2015-07-22 14:22 UTC, Luiz Gustavo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Luiz Gustavo 2015-07-22 14:22:37 UTC
Created attachment 36034 [details]
Source code and system info

The program itself has a bug, in function f the expression "size(A(1,:))" at x variable definition, line 11, should to be "size(B(1,:))" instead. But that causes a segmentation fault on compiling.
Comment 1 Dominique d'Humieres 2015-08-30 13:36:08 UTC
Confirmed from 4.8 up to trunk (6.0), backtrace

* thread #1: tid = 0x3763a43, 0x000000010098b77a f951`get_chain_decl at tree-nested.c:240, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x50)
    frame #0: 0x000000010098b77a f951`get_chain_decl at tree-nested.c:240
   237 	static tree
   238 	get_frame_type (struct nesting_info *info)
   239 	{
-> 240 	  tree type = info->frame_type;
   241 	  if (!type)
   242 	    {
   243 	      char *name;
(lldb) bt
* thread #1: tid = 0x3763a43, 0x000000010098b77a f951`get_chain_decl at tree-nested.c:240, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x50)
  * frame #0: 0x000000010098b77a f951`get_chain_decl at tree-nested.c:240
    frame #1: 0x000000010098b77a f951`get_chain_decl(info=0x0000000144000b30) + 10
    frame #2: 0x000000010098dc53 f951`get_nonlocal_debug_decl(info=0x0000000144000b30, decl=0x000000014350b990) + 723 at tree-nested.c:858
    frame #3: 0x000000010098dd79 f951`convert_nonlocal_reference_op(tp=0x00000001436d6108, walk_subtrees=<unavailable>, data=0x00007fff5fbfeef0) + 265 at tree-nested.c:941
    frame #4: 0x0000000100b3e6a3 f951`walk_tree_1(tp=0x00000001436d6108, func=0x000000010098dc70, data=0x00007fff5fbfeef0, pset=0x0000000000000000, lh=0x0000000000000000)(tree_node**, int*, void*), void*, hash_set<tree_node*, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, default_hash_traits<tree_node*> >*)) + 371 at tree.c:11296
    frame #5: 0x000000010098de38 f951`convert_nonlocal_reference_op(tp=0x00000001436d6108, walk_subtrees=<unavailable>, data=0x00007fff5fbfeef0) + 456 at tree-nested.c:1037
    frame #6: 0x0000000100b3e6a3 f951`walk_tree_1(tp=0x00000001436d4d18, func=0x000000010098dc70, data=0x00007fff5fbfeef0, pset=0x0000000000000000, lh=0x0000000000000000)(tree_node**, int*, void*), void*, hash_set<tree_node*, default_hash_traits<tree_node*> >*, tree_node* (*)(tree_node**, int*, tree_node* (*)(tree_node**, int*, void*), void*, hash_set<tree_node*, default_hash_traits<tree_node*> >*)) + 371 at tree.c:11296
    frame #7: 0x0000000100686063 f951`walk_gimple_op(stmt=0x00000001436d4cd0, callback_op=0x000000010098dc70, wi=0x00007fff5fbfeef0)(tree_node**, int*, void*), walk_stmt_info*) + 1539 at gimple-walk.c:204
    frame #8: 0x00000001006863d4 f951`walk_gimple_stmt(gsi=0x00007fff5fbfeab0, callback_stmt=0x000000010098e560, callback_op=0x000000010098dc70, wi=0x00007fff5fbfeef0)(gimple_stmt_iterator*, bool*, walk_stmt_info*), tree_node* (*)(tree_node**, int*, void*), walk_stmt_info*) + 148 at gimple-walk.c:562
    frame #9: 0x0000000100686621 f951`walk_gimple_seq_mod(pseq=<unavailable>, callback_stmt=0x000000010098e560, callback_op=0x000000010098dc70, wi=0x00007fff5fbfeef0)(gimple_stmt_iterator*, bool*, walk_stmt_info*), tree_node* (*)(tree_node**, int*, void*), walk_stmt_info*) + 81 at gimple-walk.c:54
    frame #10: 0x0000000100686543 f951`walk_gimple_stmt(gsi=0x00007fff5fbfeb40, callback_stmt=0x000000010098e560, callback_op=0x000000010098dc70, wi=0x00007fff5fbfeef0)(gimple_stmt_iterator*, bool*, walk_stmt_info*), tree_node* (*)(tree_node**, int*, void*), walk_stmt_info*) + 515 at gimple-walk.c:608
    frame #11: 0x0000000100686621 f951`walk_gimple_seq_mod(pseq=<unavailable>, callback_stmt=0x000000010098e560, callback_op=0x000000010098dc70, wi=0x00007fff5fbfeef0)(gimple_stmt_iterator*, bool*, walk_stmt_info*), tree_node* (*)(tree_node**, int*, void*), walk_stmt_info*) + 81 at gimple-walk.c:54
    frame #12: 0x0000000100686513 f951`walk_gimple_stmt(gsi=0x00007fff5fbfebd0, callback_stmt=0x000000010098e560, callback_op=0x000000010098dc70, wi=0x00007fff5fbfeef0)(gimple_stmt_iterator*, bool*, walk_stmt_info*), tree_node* (*)(tree_node**, int*, void*), walk_stmt_info*) + 467 at gimple-walk.c:572
Comment 2 kargls 2015-10-02 22:01:41 UTC
I believe the code is invalid.  Here a small rewrite

program bug

   implicit none

   real, target, allocatable :: a(:,:)
   allocate(a(10,10))
   a = 1.0
   print*, f(a) 

   contains

      function f(b) result(x)
         real, target, intent(in):: b(:,:)
         real, pointer :: c(:,:)
         real :: x(size(c(1,:)))
         c => b(1:2,:)
         x = c(2,:)
      end function f

end program bug


The line 'real :: x(size(c(1,:))' is referencing an
unassociated pointer.  If I add the 'integer :: n = size(c(1,:))
I get 

% gfc6 -c bug.f90
bug.f90:15:29:

          integer :: n = size(c(1,:))
                             1
Error: Deferred array 'c' at (1) is not permitted in an initialization
expression

A similar error should probably occur here.
Comment 3 anlauf 2023-10-12 20:39:23 UTC
*** Bug 86120 has been marked as a duplicate of this bug. ***
Comment 4 anlauf 2023-10-15 20:23:09 UTC
We might need to tighten the check of restricted expressions:

diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index 663fe63dea6..6996e1e93d1 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -2849,6 +2852,21 @@ check_inquiry (gfc_expr *e, int not_restricted)
 	  && ap->expr->expr_type == EXPR_VARIABLE
 	  && asym->attr.dummy && asym->attr.optional)
 	return MATCH_NO;
+
+      if (not_restricted == 0
+	  && ap->expr->expr_type == EXPR_VARIABLE
+	  && !(asym->attr.flavor == FL_PARAMETER)
+	  && !asym->attr.dummy
+	  && !asym->attr.in_common
+	  && !asym->attr.use_assoc
+	  && !asym->attr.host_assoc
+	  && !asym->attr.implied_index
+	  && (asym->attr.allocatable
+	      || asym->attr.pointer
+	      || (asym->as && asym->as->type == AS_DEFERRED)))
+	{
+	  return MATCH_ERROR;
+	}
     }
 
   return MATCH_YES;


This needs to be refined further.