<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><span></span></div><div><div dir="ltr"><div><div><div><div><div><div><div><br></div>Hi,<br><br></div>This is with reference to the below discussion thread:<br><br><a href="http://clang-developers.42468.n3.nabble.com/Endless-operator-gt-chain-causing-infinite-loop-td4035258.html">http://clang-developers.42468.n3.nabble.com/Endless-operator-gt-chain-causing-infinite-loop-td4035258.html</a><br>
<br></div>I have tried to implement a command line argument to handle the issue.<br><br></div>The patch for the same is below:<br><br>Index: lib/Driver/Tools.cpp<br>===================================================================<br>
--- lib/Driver/Tools.cpp (revision 193400)<br>+++ lib/Driver/Tools.cpp (working copy)<br>@@ -2802,6 +2802,12 @@<br> CmdArgs.push_back(A->getValue());<br> }<br> <br>+ if (Arg *A = Args.getLastArg(options::OPT_foperatorarrow_depth_,<br>
+ options::OPT_foperatorarrow_depth_EQ)) {<br>+ CmdArgs.push_back("-foperatorarrow-depth");<br>+ CmdArgs.push_back(A->getValue());<br>+ }<br>+<br> if (Arg *A = Args.getLastArg(options::OPT_fconstexpr_depth_EQ)) {<br>
CmdArgs.push_back("-fconstexpr-depth");<br> CmdArgs.push_back(A->getValue());<br>Index: lib/Frontend/CompilerInvocation.cpp<br>===================================================================<br>--- lib/Frontend/CompilerInvocation.cpp (revision 193400)<br>
+++ lib/Frontend/CompilerInvocation.cpp (working copy)<br>@@ -1313,6 +1313,8 @@<br> Opts.MathErrno = !Opts.OpenCL && Args.hasArg(OPT_fmath_errno);<br> Opts.InstantiationDepth =<br> getLastArgIntValue(Args, OPT_ftemplate_depth, 256, Diags);<br>
+ Opts.ArrowDepth = <br>+ getLastArgIntValue(Args, OPT_foperatorarrow_depth, 256, Diags);<br> Opts.ConstexprCallDepth =<br> getLastArgIntValue(Args, OPT_fconstexpr_depth, 512, Diags);<br> Opts.ConstexprStepLimit =<br>
Index: lib/Sema/SemaExprCXX.cpp<br>===================================================================<br>--- lib/Sema/SemaExprCXX.cpp (revision 193400)<br>+++ lib/Sema/SemaExprCXX.cpp (working copy)<br>@@ -5188,8 +5188,19 @@<br>
llvm::SmallPtrSet<CanQualType,8> CTypes;<br> SmallVector<SourceLocation, 8> Locations;<br> CTypes.insert(Context.getCanonicalType(BaseType));<br>+ <br>+ static unsigned int arrow_instantiation_count = 0;<br>
+ while (BaseType->isRecordType()) {<br>+ arrow_instantiation_count++;<br>+ if (arrow_instantiation_count >= getLangOpts().ArrowDepth) {<br>+ Diag(OpLoc,diag::err_arrow_instantiation_depth_exceeded)<br>
+ << getLangOpts().ArrowDepth<br>+ << Base->getSourceRange();<br>+ Diag(OpLoc, diag::note_arrow_instantiation_depth)<br>+ << getLangOpts().ArrowDepth;<br>+ return ExprError();<br>
+ }<br> <br>- while (BaseType->isRecordType()) {<br> Result = BuildOverloadedArrowExpr(<br> S, Base, OpLoc,<br> // When in a template specialization and on the first loop iteration,<br>
Index: include/clang/Basic/DiagnosticSemaKinds.td<br>===================================================================<br>--- include/clang/Basic/DiagnosticSemaKinds.td (revision 193400)<br>+++ include/clang/Basic/DiagnosticSemaKinds.td (working copy)<br>
@@ -2561,6 +2561,11 @@<br> // can handle that case properly.<br> def note_ovl_candidate_non_deduced_mismatch_qualified : Note<<br> "candidate template ignored: could not match %q0 against %q1">;<br>+def err_arrow_instantiation_depth_exceeded : Error<<br>
+ "arrow operator instantiation exceeded maximum depth of %0">,<br>+ DefaultFatal, NoSFINAE;<br>+def note_arrow_instantiation_depth : Note<<br>+ "use -foperatorarrow-depth=N to increase arrow operator instantiation depth">;<br>
<br> // Note that we don't treat templates differently for this diagnostic.<br> def note_ovl_candidate_arity : Note<"candidate "<br>Index: include/clang/Basic/LangOptions.def<br>===================================================================<br>
--- include/clang/Basic/LangOptions.def (revision 193400)<br>+++ include/clang/Basic/LangOptions.def (working copy)<br>@@ -160,6 +160,8 @@<br> ENUM_LANGOPT(SignedOverflowBehavior, SignedOverflowBehaviorTy, 2, SOB_Undefined,<br>
"signed integer overflow handling")<br> <br>+BENIGN_LANGOPT(ArrowDepth, 32, 256,<br>+ "maximum arrow instantiation depth")<br> BENIGN_LANGOPT(InstantiationDepth, 32, 256,<br>
"maximum template instantiation depth")<br> BENIGN_LANGOPT(ConstexprCallDepth, 32, 512,<br>Index: include/clang/Driver/CC1Options.td<br>===================================================================<br>
--- include/clang/Driver/CC1Options.td (revision 193400)<br>+++ include/clang/Driver/CC1Options.td (working copy)<br>@@ -442,6 +442,8 @@<br> HelpText<"Default type visibility">;<br> def ftemplate_depth : Separate<["-"], "ftemplate-depth">,<br>
HelpText<"Maximum depth of recursive template instantiation">;<br>+def foperatorarrow_depth : Separate<["-"], "foperatorarrow-depth">,<br>+ HelpText<"Maximum depth of arrow operator instantiation">;<br>
def fconstexpr_depth : Separate<["-"], "fconstexpr-depth">,<br> HelpText<"Maximum depth of recursive constexpr function calls">;<br> def fconstexpr_steps : Separate<["-"], "fconstexpr-steps">,<br>
Index: include/clang/Driver/Options.td<br>===================================================================<br>--- include/clang/Driver/Options.td (revision 193400)<br>+++ include/clang/Driver/Options.td (working copy)<br>
@@ -775,6 +775,8 @@<br> def ftemplate_depth_ : Joined<["-"], "ftemplate-depth-">, Group<f_Group>;<br> def ftemplate_backtrace_limit_EQ : Joined<["-"], "ftemplate-backtrace-limit=">,<br>
Group<f_Group>;<br>+def foperatorarrow_depth_EQ : Joined<["-"], "foperatorarrow-depth=">, Group<f_Group>;<br>+def foperatorarrow_depth_ : Joined<["-"], "foperatorarrow-depth-">, Group<f_Group>;<br>
def ftest_coverage : Flag<["-"], "ftest-coverage">, Group<f_Group>;<br> def fvectorize : Flag<["-"], "fvectorize">, Group<f_Group>,<br> HelpText<"Enable the loop vectorization passes">;<br>
<br><br><br></div>Please if someone could help me by reviewing it and suggesting improvements?<br><br></div>Thanks,<br></div>Rahul<br></div>
</div></body></html>