Mordante created this revision.
Mordante added reviewers: rnk, rsmith, aaron.ballman.
Mordante added a project: clang.

This allows the caller of the function to add a note about how to fix the stack 
exhaustion. This can be useful to aid the user. For example it can be used to 
show a help message for https://bugs.llvm.org/show_bug.cgi?id=14030


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D69478

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp


Index: clang/lib/Sema/Sema.cpp
===================================================================
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -386,17 +386,21 @@
   SemaPPCallbackHandler->reset();
 }
 
-void Sema::warnStackExhausted(SourceLocation Loc) {
+void Sema::warnStackExhausted(SourceLocation Loc, unsigned NoteDiagID) {
   // Only warn about this once.
   if (!WarnedStackExhausted) {
     Diag(Loc, diag::warn_stack_exhausted);
+    if (NoteDiagID)
+      Diag(Loc, NoteDiagID);
     WarnedStackExhausted = true;
   }
 }
 
 void Sema::runWithSufficientStackSpace(SourceLocation Loc,
-                                       llvm::function_ref<void()> Fn) {
-  clang::runWithSufficientStackSpace([&] { warnStackExhausted(Loc); }, Fn);
+                                       llvm::function_ref<void()> Fn,
+                                       unsigned NoteDiagID) {
+  clang::runWithSufficientStackSpace(
+      [&] { warnStackExhausted(Loc, NoteDiagID); }, Fn);
 }
 
 /// makeUnavailableInSystemHeader - There is an error in the current
Index: clang/include/clang/Sema/Sema.h
===================================================================
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -1307,14 +1307,17 @@
   void PrintStats() const;
 
   /// Warn that the stack is nearly exhausted.
-  void warnStackExhausted(SourceLocation Loc);
+  /// \param NoteDiagID Extra information of the user how to resolve the issue.
+  void warnStackExhausted(SourceLocation Loc, unsigned NoteDiagID = 0);
 
   /// Run some code with "sufficient" stack space. (Currently, at least 256K is
   /// guaranteed). Produces a warning if we're low on stack space and allocates
   /// more in that case. Use this in code that may recurse deeply (for example,
   /// in template instantiation) to avoid stack overflow.
+  /// \param NoteDiagID Extra information of the user how to resolve the issue.
   void runWithSufficientStackSpace(SourceLocation Loc,
-                                   llvm::function_ref<void()> Fn);
+                                   llvm::function_ref<void()> Fn,
+                                   unsigned NoteDiagID = 0);
 
   /// Helper class that creates diagnostics with optional
   /// template instantiation stacks.


Index: clang/lib/Sema/Sema.cpp
===================================================================
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -386,17 +386,21 @@
   SemaPPCallbackHandler->reset();
 }
 
-void Sema::warnStackExhausted(SourceLocation Loc) {
+void Sema::warnStackExhausted(SourceLocation Loc, unsigned NoteDiagID) {
   // Only warn about this once.
   if (!WarnedStackExhausted) {
     Diag(Loc, diag::warn_stack_exhausted);
+    if (NoteDiagID)
+      Diag(Loc, NoteDiagID);
     WarnedStackExhausted = true;
   }
 }
 
 void Sema::runWithSufficientStackSpace(SourceLocation Loc,
-                                       llvm::function_ref<void()> Fn) {
-  clang::runWithSufficientStackSpace([&] { warnStackExhausted(Loc); }, Fn);
+                                       llvm::function_ref<void()> Fn,
+                                       unsigned NoteDiagID) {
+  clang::runWithSufficientStackSpace(
+      [&] { warnStackExhausted(Loc, NoteDiagID); }, Fn);
 }
 
 /// makeUnavailableInSystemHeader - There is an error in the current
Index: clang/include/clang/Sema/Sema.h
===================================================================
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -1307,14 +1307,17 @@
   void PrintStats() const;
 
   /// Warn that the stack is nearly exhausted.
-  void warnStackExhausted(SourceLocation Loc);
+  /// \param NoteDiagID Extra information of the user how to resolve the issue.
+  void warnStackExhausted(SourceLocation Loc, unsigned NoteDiagID = 0);
 
   /// Run some code with "sufficient" stack space. (Currently, at least 256K is
   /// guaranteed). Produces a warning if we're low on stack space and allocates
   /// more in that case. Use this in code that may recurse deeply (for example,
   /// in template instantiation) to avoid stack overflow.
+  /// \param NoteDiagID Extra information of the user how to resolve the issue.
   void runWithSufficientStackSpace(SourceLocation Loc,
-                                   llvm::function_ref<void()> Fn);
+                                   llvm::function_ref<void()> Fn,
+                                   unsigned NoteDiagID = 0);
 
   /// Helper class that creates diagnostics with optional
   /// template instantiation stacks.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to