Limit the template instantiation depth to some user-configurable value
(default: 99). Beyond this limit, produce an error and consider the
current template instantiation a failure.

The stack we're building to track the instantiations will, eventually,
be used to produce instantiation backtraces from diagnostics within
template instantiation. However, we're not quite there yet.

This adds a new Clang driver option -ftemplate-depth=NNN, which should
eventually be generated from the GCC command-line operation
-ftemplate-depth-NNN (note the '-' rather than the '='!). I did not
make the driver changes to do this mapping.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66513 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Driver/clang.cpp b/Driver/clang.cpp
index 59c3799..72d2b9c 100644
--- a/Driver/clang.cpp
+++ b/Driver/clang.cpp
@@ -515,7 +515,10 @@
 TargetFeatures("mattr", llvm::cl::CommaSeparated,
         llvm::cl::desc("Target specific attributes (-mattr=help for details)"));
 
-
+static llvm::cl::opt<unsigned>
+TemplateDepth("ftemplate-depth", llvm::cl::init(99),
+              llvm::cl::desc("Maximum depth of recursive template "
+                             "instantiation"));
 
 // FIXME: add:
 //   -fdollars-in-identifiers
@@ -642,6 +645,8 @@
 
   Options.MathErrno = MathErrno;
 
+  Options.InstantiationDepth = TemplateDepth;
+
   // Override the default runtime if the user requested it.
   if (NeXTRuntime)
     Options.NeXTRuntime = 1;