1*700637cbSDimitry Andric //===--- StackExhaustionHandler.cpp - - A utility for warning once when close 2*700637cbSDimitry Andric // to out of stack space -------*- C++ -*-===// 3*700637cbSDimitry Andric // 4*700637cbSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5*700637cbSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 6*700637cbSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7*700637cbSDimitry Andric // 8*700637cbSDimitry Andric //===----------------------------------------------------------------------===// 9*700637cbSDimitry Andric /// 10*700637cbSDimitry Andric /// \file 11*700637cbSDimitry Andric /// Defines a utilitiy for warning once when close to out of stack space. 12*700637cbSDimitry Andric /// 13*700637cbSDimitry Andric //===----------------------------------------------------------------------===// 14*700637cbSDimitry Andric 15*700637cbSDimitry Andric #include "clang/Basic/StackExhaustionHandler.h" 16*700637cbSDimitry Andric #include "clang/Basic/Stack.h" 17*700637cbSDimitry Andric runWithSufficientStackSpace(SourceLocation Loc,llvm::function_ref<void ()> Fn)18*700637cbSDimitry Andricvoid clang::StackExhaustionHandler::runWithSufficientStackSpace( 19*700637cbSDimitry Andric SourceLocation Loc, llvm::function_ref<void()> Fn) { 20*700637cbSDimitry Andric clang::runWithSufficientStackSpace([&] { warnStackExhausted(Loc); }, Fn); 21*700637cbSDimitry Andric } 22*700637cbSDimitry Andric warnOnStackNearlyExhausted(SourceLocation Loc)23*700637cbSDimitry Andricvoid clang::StackExhaustionHandler::warnOnStackNearlyExhausted( 24*700637cbSDimitry Andric SourceLocation Loc) { 25*700637cbSDimitry Andric if (isStackNearlyExhausted()) 26*700637cbSDimitry Andric warnStackExhausted(Loc); 27*700637cbSDimitry Andric } 28*700637cbSDimitry Andric warnStackExhausted(SourceLocation Loc)29*700637cbSDimitry Andricvoid clang::StackExhaustionHandler::warnStackExhausted(SourceLocation Loc) { 30*700637cbSDimitry Andric // Only warn about this once. 31*700637cbSDimitry Andric if (!WarnedStackExhausted) { 32*700637cbSDimitry Andric DiagsRef.Report(Loc, diag::warn_stack_exhausted); 33*700637cbSDimitry Andric WarnedStackExhausted = true; 34*700637cbSDimitry Andric } 35*700637cbSDimitry Andric } 36