From 7c9fc738b19db26417565d99f6cdff629ae67010 Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Wed, 27 Jul 2016 05:51:56 +0000 Subject: [MC] Add command-line option to choose the max nest level in asm macros. Submitted by: t83wCSLq Differential Revision: https://reviews.llvm.org/D22313 llvm-svn: 276842 --- llvm/lib/MC/MCParser/AsmParser.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'llvm/lib/MC/MCParser') diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp index 8f2ee7f1163..d85f1c613c7 100644 --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -34,6 +34,7 @@ #include "llvm/MC/MCStreamer.h" #include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCValue.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/MemoryBuffer.h" @@ -41,12 +42,17 @@ #include "llvm/Support/raw_ostream.h" #include #include +#include #include #include using namespace llvm; MCAsmParserSemaCallback::~MCAsmParserSemaCallback() {} +static cl::opt AsmMacroMaxNestingDepth( + "asm-macro-max-nesting-depth", cl::init(20), cl::Hidden, + cl::desc("The maximum nesting depth allowed for assembly macros.")); + namespace { /// \brief Helper types for tracking macro definitions. typedef std::vector MCAsmMacroArgument; @@ -2363,10 +2369,17 @@ void AsmParser::defineMacro(StringRef Name, MCAsmMacro Macro) { void AsmParser::undefineMacro(StringRef Name) { MacroMap.erase(Name); } bool AsmParser::handleMacroEntry(const MCAsmMacro *M, SMLoc NameLoc) { - // Arbitrarily limit macro nesting depth, to match 'as'. We can eliminate - // this, although we should protect against infinite loops. - if (ActiveMacros.size() == 20) - return TokError("macros cannot be nested more than 20 levels deep"); + // Arbitrarily limit macro nesting depth (default matches 'as'). We can + // eliminate this, although we should protect against infinite loops. + unsigned MaxNestingDepth = AsmMacroMaxNestingDepth; + if (ActiveMacros.size() == MaxNestingDepth) { + std::ostringstream MaxNestingDepthError; + MaxNestingDepthError << "macros cannot be nested more than " + << MaxNestingDepth << " levels deep." + << " Use -asm-macro-max-nesting-depth to increase " + "this limit."; + return TokError(MaxNestingDepthError.str()); + } MCAsmMacroArguments A; if (parseMacroArguments(M, A)) -- cgit v1.2.3