This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [G++] templates not instantiated early enough


On Thu, 3 Jun 2004, Andrew Pinski wrote:
> On Jun 3, 2004, at 22:33, Chris Lattner wrote:
> > The problem is that, in this testcase (which is reduced from a
> > non-pointless larger testcase), the some_template is never instantiated
> > with an int type.  This causes problems for my backend, which needs to
> > look at the types for arguments for foo.  Currently, since the
> > template is
> > never being instantiated, the TYPE_SIZE and other fields are null.  The
> > target that I'm working on specifically needs types laid out for
> > function
> > prototypes that take an aggregate value by value (as in this case).
> > Pointers to templates can be lazily instantiated as needed.
>
> Why does it need them?  You should only need them for prototypes
> which are used.

The problem is that the prototype *is* used.  In particular, the function
is mark_used and sent to the backend.  When the backend gets the prototype
(through assemble_external or similar) it doesn't have the type
information it needs for the instantiation of "some_template".  To emit
the prototype to the .s file, it needs information about structures passed
by value to function prototypes, even if the function isn't even called
(as in this case).

In this particular example, even if assemble_external is not used, the
same problem occurs later when the function is expanded, so it's not
specific to assemble_external/ASM_OUT_EXTERNAL.

> If you question is rather is the following valid code:
> template<typename Ty>
> struct some_template {typename Ty::t t;};
>
> void foo(some_template<int>  a);
>
> void (*f) (some_template<int>) = foo;
>
> As this case is where the template refers to an invalid type, int::t.

That's another great case that shows an example of this problem.  That
should be flaged as an error and reported for the same reason that I'm
having the problem.

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]