Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:51

0001 //===--- StackExhaustionHandler.h - A utility for warning once when close to out
0002 // of stack space -------*- C++ -*-===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 ///
0010 /// \file
0011 /// Defines a utilitiy for warning once when close to out of stack space.
0012 ///
0013 //===----------------------------------------------------------------------===//
0014 
0015 #ifndef LLVM_CLANG_BASIC_STACK_EXHAUSTION_HANDLER_H
0016 #define LLVM_CLANG_BASIC_STACK_EXHAUSTION_HANDLER_H
0017 
0018 #include "clang/Basic/Diagnostic.h"
0019 
0020 namespace clang {
0021 class StackExhaustionHandler {
0022 public:
0023   StackExhaustionHandler(DiagnosticsEngine &diags) : DiagsRef(diags) {}
0024 
0025   /// Run some code with "sufficient" stack space. (Currently, at least 256K
0026   /// is guaranteed). Produces a warning if we're low on stack space and
0027   /// allocates more in that case. Use this in code that may recurse deeply to
0028   /// avoid stack overflow.
0029   void runWithSufficientStackSpace(SourceLocation Loc,
0030                                    llvm::function_ref<void()> Fn);
0031 
0032   /// Check to see if we're low on stack space and produce a warning if we're
0033   /// low on stack space (Currently, at least 256Kis guaranteed).
0034   void warnOnStackNearlyExhausted(SourceLocation Loc);
0035 
0036 private:
0037   /// Warn that the stack is nearly exhausted.
0038   void warnStackExhausted(SourceLocation Loc);
0039 
0040   DiagnosticsEngine &DiagsRef;
0041   bool WarnedStackExhausted = false;
0042 };
0043 } // end namespace clang
0044 
0045 #endif // LLVM_CLANG_BASIC_STACK_EXHAUSTION_HANDLER_H