[llvm] [FileCheck] Fix --enable-var-scope for numvars after reassignment (PR #157158)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 9 06:32:41 PDT 2025


================
@@ -1218,6 +1218,8 @@ Pattern::MatchResult Pattern::match(StringRef Buffer,
     StringRef MatchedValue = MatchInfo[CaptureParenGroup];
     ExpressionFormat Format = DefinedNumericVariable->getImplicitFormat();
     APInt Value = Format.valueFromStringRepr(MatchedValue, SM);
+    Context->GlobalNumericVariableTable.try_emplace(NumericVariableDef.getKey(),
----------------
Clipi-12 wrote:

I had already thought of this, and that was the first implementation I did in a private fork. However, I didn't do the PR with that approach for two/three reasons:
1. There is a comment in clearLocalVars() that says that defineCmdlineVariables() expects the variable to be removed from GlobalNumericVariableTable, which is true (the first assert), since it uses GlobalNumericVariableTable.contains to check for collisions with "normal"/text-based variables.
2ish. That previous behaviour is expected in tests like FileCheckTest.cpp[FileCheckContext] e.g. lines 1605-1612 (keep in mind i haven't actaully tested this)
3. If we didn't remove it, every clearLocalVars() will loop through every numvar, even if it doesn't need to be cleared. (Although I don't think this is a very big penalty, since most tests will have at most a couple of numvars)

https://github.com/llvm/llvm-project/pull/157158


More information about the llvm-commits mailing list