[PATCH] D22313: [MC] Add command-line option to choose the max nest level in asm macros
t83wCSLq via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 13 12:39:22 PDT 2016
t83wCSLq created this revision.
t83wCSLq added a subscriber: llvm-commits.
This patch adds a command-line option (-asm-macro-max-nesting-depth <n>) to choose the maximum nesting level in assembly macros.
http://reviews.llvm.org/D22313
Files:
lib/MC/MCParser/AsmParser.cpp
Index: lib/MC/MCParser/AsmParser.cpp
===================================================================
--- lib/MC/MCParser/AsmParser.cpp
+++ lib/MC/MCParser/AsmParser.cpp
@@ -41,12 +41,17 @@
#include "llvm/Support/raw_ostream.h"
#include <cctype>
#include <deque>
+#include <sstream>
#include <string>
#include <vector>
using namespace llvm;
MCAsmParserSemaCallback::~MCAsmParserSemaCallback() {}
+static cl::opt<unsigned> 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<AsmToken> MCAsmMacroArgument;
@@ -2326,10 +2331,17 @@
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))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22313.63847.patch
Type: text/x-patch
Size: 1804 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160713/30482dc6/attachment.bin>
More information about the llvm-commits
mailing list