This is the mail archive of the gcc-bugs@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]

Re: Trying to compile D. Piponi's template based primality test



    >>>>> "Me" == Laurent Bonnaud <bonnaud@irisa.fr> writes:
    Me> 
    Me> i'm trying to compile the attached program, but it fails because the
    Me> template instantiation depth is too deep.  The original program tests
    Me> the number '13'.  KCC can compile it in a few seconds and with 4MB of
    Me> memory.  With egcs, i replaced '13' with '1', used
    Me> -ftemplate-depth-1000 and it still does not compile.  The compilation
    Me> lasts several minutes, and cc1plus uses 80MB of memory.  I guess that
    Me> egcs gets caught in a loop, where it should not.  Does anybody know if
    Me> this is a bug a egcs, or how i could modify the program to work ?

    I retried this code with egcs-2.91.14 (980315) and now it compiles fine
    wihtout even having to use -ftemplate-depth-???.  Thank you for this
    great improvement !  However, the result is not always what is
    expected:

     1 is prime
     2 is prime
     3 is prime
     4 is not prime
     5 is prime
     6 is not prime
     7 is prime
     8 is not prime
     9 is not prime
    10 is not prime
    10 is prime
    11 is prime
    12 is prime
    13 is not prime
    14 is prime

On my Linux box, I do have to use -ftemplate-depth, but I also get the
right answer.  (The -ftemplate-depth doesn't surprise me; there's a
lot of template recursion in this program!)

Perhaps this change (which Jason has not yet had a chance to comment
on, and which is therefore not yet in the tree) fixed the problem.
You might try getting that patch from the list and trying it out.  If
that doesn't help, the bug might be platform specific.  

  1998-03-19  Mark Mitchell  <mmitchell@usa.net>

	  * cplus-dem.c (optable): Add sizeof.
	  (demangle_template_value_parm): New function containing code
	  previously found in demangle_template.
	  (demangle_integral_value): New function which handles complicated 
	  integral expressions.
	  (demangle_template): Use them.

  Thu Mar 19 11:10:47 1998  Mark Mitchell  <mmitchell@usa.net>

	  * Make-lang.in (c++filt): Don't delete cxxmain.c after we're done
	  with it; we might want it for debugging.
	  * cp-tree.h (type_unification): Change interface.
	  * class.c (finish_struct_1): Skip nested template types, just like
	  ordinary nested types.
	  (instantiate_type): Use new interface to type_unification.
	  * method.c (build_overload_scope_ref): New function.
	  (build_overload_int): Handle complex expressions.  Set
	  numeric_output_need_bar if necessary.
	  (build_overload_value): Handle non-PARM_DECL nodes; this
	  routine is now used by build_overload_int.  Remove some
	  assignments to numeric_output_need_bar.  Use
	  build_overload_scope_ref.
	  (build_qualified_name): Note that some template mangled names end
	  with digits, and set numeric_output_need_bar appropriately.  Use
	  build_underscore_int.
	  * pt.c (unify): Change interface.
	  (type_unification_real): Likewise.
	  (determine_specialization): Use new interfaces.
	  (tsubst): Deal gracefully with situations in which the argument
	  vector is not fully filled.
	  (fn_type_unification): Use new interfaces.
	  (type_unification): Likewise.  Remove NOP_EXPR hack.
	  (type_unification_real): Likewise.
	  (unify): Likewise.  Deal with unification of complex expresions.

-- 
Mark Mitchell <mmitchell@usa.net>
http://home.earthlink.net/~mbmitchell
Consulting Services Available


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