[llvm] [MC] Increase asm-macro-max-nesting-depth default to 100 (PR #218455)
Matt Turner via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 25 20:45:40 PDT 2026
https://github.com/mattst88 updated https://github.com/llvm/llvm-project/pull/218455
>From a3459ea77e4f2593d92b88a671239000002be790 Mon Sep 17 00:00:00 2001
From: Matt Turner <mattst88 at gmail.com>
Date: Thu, 9 Jul 2026 22:00:52 -0400
Subject: [PATCH] [MC] Increase asm-macro-max-nesting-depth default to 100
The default of 20 rejects assembly the GNU assembler accepts, e.g. glibc's
sysdeps/unix/sysv/linux/alpha/rt_sigaction.S, which nests 31 deep. Raise the
default to 100 to match the GNU assembler, including at the boundary: 100
levels assemble and 101 do not.
Give macro-max-depth.s a depth parameter so one input covers both the default
and the flag overriding it.
Assisted-by: Claude Code
---
llvm/lib/MC/MCParser/MCAsmParser.cpp | 3 ++-
llvm/test/MC/AsmParser/macro-max-depth.s | 33 ++++++++++++++----------
2 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/llvm/lib/MC/MCParser/MCAsmParser.cpp b/llvm/lib/MC/MCParser/MCAsmParser.cpp
index 68bd0e4453d04..b06918c253452 100644
--- a/llvm/lib/MC/MCParser/MCAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/MCAsmParser.cpp
@@ -23,8 +23,9 @@
using namespace llvm;
namespace llvm {
+// 100 matches the GNU assembler's default macro nesting limit.
cl::opt<unsigned> AsmMacroMaxNestingDepth(
- "asm-macro-max-nesting-depth", cl::init(20), cl::Hidden,
+ "asm-macro-max-nesting-depth", cl::init(100), cl::Hidden,
cl::desc("The maximum nesting depth allowed for assembly macros."));
}
diff --git a/llvm/test/MC/AsmParser/macro-max-depth.s b/llvm/test/MC/AsmParser/macro-max-depth.s
index 47fbf9a1930ba..dfafc4dc75c42 100644
--- a/llvm/test/MC/AsmParser/macro-max-depth.s
+++ b/llvm/test/MC/AsmParser/macro-max-depth.s
@@ -1,20 +1,27 @@
-// RUN: llvm-mc -triple x86_64-unknown-unknown -asm-macro-max-nesting-depth=42 %s | FileCheck %s -check-prefix=CHECK_PASS
-// RUN: not llvm-mc -triple x86_64-unknown-unknown %s 2> %t
-// RUN: FileCheck -check-prefix=CHECK_FAIL < %t %s
+// RUN: llvm-mc -triple x86_64 -defsym DEPTH=30 %s \
+// RUN: | FileCheck %s --check-prefix=PASS
+// RUN: llvm-mc -triple x86_64 -defsym DEPTH=99 %s \
+// RUN: | FileCheck %s --check-prefix=PASS
+// RUN: not llvm-mc -triple x86_64 -defsym DEPTH=100 %s 2>&1 \
+// RUN: | FileCheck %s --check-prefix=TOODEEP-DEFAULT
-.macro rec head, tail:vararg
- .ifnb \tail
- rec \tail
+/// -asm-macro-max-nesting-depth overrides the default.
+// RUN: llvm-mc -triple x86_64 -asm-macro-max-nesting-depth=42 \
+// RUN: -defsym DEPTH=41 %s | FileCheck %s --check-prefix=PASS
+// RUN: not llvm-mc -triple x86_64 -asm-macro-max-nesting-depth=42 \
+// RUN: -defsym DEPTH=42 %s 2>&1 | FileCheck %s --check-prefix=TOODEEP-FLAG
+
+.macro rec n
+ .if \n > 0
+ rec "(\n - 1)"
.else
.long 42
.endif
.endm
-.macro amplify macro, args:vararg
- \macro \args \args \args \args
-.endm
-
-amplify rec 0 0 0 0 0 0 0 0 0 0
+rec DEPTH
-// CHECK_PASS: .long 42
-// CHECK_FAIL: error: macros cannot be nested more than {{[0-9]+}} levels deep. Use -asm-macro-max-nesting-depth to increase this limit.
+/// DEPTH=n nests n+1 deep, counting the outermost invocation.
+// PASS: .long 42
+// TOODEEP-DEFAULT: error: macros cannot be nested more than 100 levels deep. Use -asm-macro-max-nesting-depth to increase this limit.
+// TOODEEP-FLAG: error: macros cannot be nested more than 42 levels deep. Use -asm-macro-max-nesting-depth to increase this limit.
More information about the llvm-commits
mailing list