Bug 19508 - [4.0 regression] dwarf2, ICE on __attribute__(aligned) in class template
Summary: [4.0 regression] dwarf2, ICE on __attribute__(aligned) in class template
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.0
Assignee: Giovanni Bajo
URL:
Keywords: ice-on-valid-code, patch
Depends on:
Blocks:
 
Reported: 2005-01-18 16:44 UTC by Jan van Dijk
Modified: 2005-02-18 19:14 UTC (History)
4 users (show)

See Also:
Host: i686-suse-linux
Target: i686-suse-linux
Build: i686-suse-linux
Known to work:
Known to fail:
Last reconfirmed: 2005-01-20 12:09:35


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan van Dijk 2005-01-18 16:44:28 UTC
When compiled with -g the following reduced testcase causes an ICE (see output 
below), without -g everything is fine. I noticed report PR19163 which exposes 
other (unrelated?) __attribute__(aligned) problems. This is a 3.4 regression. 
 
This is with today's trunk, configured without options (except --prefix). 
  
template <typename T>  
struct BVector  
{  
  typedef T value_type __attribute__ ((aligned(8)));  
};  
BVector<int> m;  
  
  
jan@nbelvis$ g++ -c luinvert.ii  
jan@nbelvis$ g++ -g -c luinvert.ii  
luinvert.ii: In instantiation of ?BVector<int>?:  
luinvert.ii:6:   instantiated from here  
luinvert.ii:3: internal compiler error: in is_base_type, at dwarf2out.c:8058  
...
Comment 1 Andrew Pinski 2005-01-18 17:20:18 UTC
: Search converges between 2004-10-17-014001-trunk (#594) and 2004-10-17-161001-trunk 
(#595).

Almost definetly caused by:
2004-10-17  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
        
        PR c++/17743
        * decl2.c (grokfield): Apply attributes also to TYPE_DECLs.
Comment 2 Paolo Carlini 2005-01-18 17:32:56 UTC
A remark: this specific issue doesn't seem to affect the minimal usage of
__attribute__((aligned)) present in tr1/type_traits (no typedefs): if/when
fixing this problem, *please* make sure to regtest libstdc++-v3!
Comment 3 Andrew Pinski 2005-01-20 04:25:06 UTC
We get <<< Unknown tree: template_type_parm >>> in is_base_type, that seems wrong
Comment 4 Andrew Pinski 2005-01-20 04:36:25 UTC
Hmm, after applying the attributes we get:
<type_decl 0x41da41d0 value_type
    type <template_type_parm 0x41da42b8 value_type type_0 type_6 VOID
        user align 64 symtab 0 alias set -1
       index 0 level 1 orig_level 1>
    nonlocal VOID file t.cc line 4
    align 1 context <record_type 0x41d9ce0c BVector<T>> attributes <tree_list 0x41da3438>
    result <template_type_parm 0x41d9cd24 T type_0 type_6 VOID
        align 8 symtab 0 alias set -1
       index 0 level 1 orig_level 1
        chain <type_decl 0x41d9cd98 T>>
   >

Notice how we have a copy in TREE_TYPE, the orginal which we would have done correctly is in 
DECL_ORIGINAL_TYPE.
Comment 5 Giovanni Bajo 2005-01-20 12:09:34 UTC
The problem here is that tsubst does not know about attributes, and we knew 
this already. So it won't look into DECL_ORIGINAL_TYPE because it assumes it is 
always NULL for template parameters. You may want to notice that the attribute 
is in fact ignored:

--------------------------------------------------------
template <typename T>  
struct BVector  
{  
  typedef T value_type __attribute__ ((aligned(8)));  
  value_type v;
};  
BVector<int> m;  

int main()
{
  printf("%d\n", __alignof__(m.v));
}
--------------------------------------------------------

This prints "4" on i686-pc-linux-gnu (if you compile it without -g to avoid the 
ICE).

I tried tsubsting within the ORIGINAL_TYPE of a TYPE_DECL too, and it works in 
avoiding the ICE, but for nothing else. Also, the long-term solution is to not 
apply attributes to template types, store the attribute list aside and apply it 
after substitution. So, after all, this would not be a step forward not even in 
that direction.

Thus, it is better to simply not apply the attribute to template types at all.
Comment 6 Giovanni Bajo 2005-01-20 12:19:36 UTC
Paolo, I think I'm going to have a warning like this:

19508.cc:7: warning: cannot apply attributes to template parameter 'T'

for the time being, to warn the user that the attribute is being ignored. I 
hope this does not conflict with some of yours TR1 plans.
Comment 7 Paolo Carlini 2005-01-20 12:26:32 UTC
> Paolo, I think I'm going to have a warning like this:

Well, if I understand well the current status, we *must* warn the user about
that. And, of course, I believe the current (for 4.0, that is) usage in tr1/
type_traits will *not* trigger the warning, because is ok. Indeed, I see the
alignment request respected in this kind of situation:

  template<std::size_t _Len>
    struct aligned_storage<_Len, 1>
    {
      union type
      {
	unsigned char __data[_Len];
	char __align __attribute__((aligned(1)));
      };
    };
Comment 8 Paolo Carlini 2005-01-20 12:32:57 UTC
Anyway, just regtest libstdc++-v3, as I already said: by now we have plenty
of the above usage and plenty of tests. Either at compile time or at run time
something will show up, in case.
Comment 9 Giovanni Bajo 2005-01-20 14:05:46 UTC
Patch posted:
http://gcc.gnu.org/ml/gcc-patches/2005-01/msg01325.html
Comment 10 GCC Commits 2005-02-18 19:12:04 UTC
Subject: Bug 19508

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	pinskia@gcc.gnu.org	2005-02-18 19:11:58

Modified files:
	gcc/cp         : ChangeLog decl2.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/ext: attrib20.C 

Log message:
	2005-01-20  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
	
	PR c++/19508
	* g++.dg/ext/attrib20.C: New test.
	
	2005-01-20  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
	
	PR c++/19508
	* decl2.c (grokfield): Do not apply attributes to template parameters
	as they are ignored by tsubst anyway.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4634&r2=1.4635
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl2.c.diff?cvsroot=gcc&r1=1.766&r2=1.767
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5048&r2=1.5049
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/attrib20.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 11 Andrew Pinski 2005-02-18 19:14:28 UTC
The ICE itself is fixed and the rest of the bug is referenced in PR 17743 so closing as fixed.