aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/FileCheck/FileCheck.cpp
diff options
context:
space:
mode:
authorClipi <hugogalindolorenzo@gmail.com>2025-09-09 23:28:01 +0200
committerGitHub <noreply@github.com>2025-09-09 22:28:01 +0100
commitd0070994222af5dc4b4790237fea9e17fae30b78 (patch)
tree1b1c0f2fd2247a836ae66fdda8f98db85c05da9c /llvm/lib/FileCheck/FileCheck.cpp
parent78dfbcaa7b32eaf5a4e5888a1728114984712a4b (diff)
downloadllvm-d0070994222af5dc4b4790237fea9e17fae30b78.zip
llvm-d0070994222af5dc4b4790237fea9e17fae30b78.tar.gz
llvm-d0070994222af5dc4b4790237fea9e17fae30b78.tar.bz2
[FileCheck] Fix --enable-var-scope for numvars after reassignment (#157158)
* When `--enable-var-scope` is active, `lib/FileCheck.cpp#clearLocalVars` gets called. * That function loops through `GlobalNumericVariableTable` and then calls `NumericVariable::clear` on most items. It also removes them from `GlobalNumericVariableTable`. * When reassigning an already cleared variable, `Pattern::match` calls `NumericVariable::setValue`, but it doesn't reinsert it into `GlobalNumericVariableTable`. Therefore, the next time `clearLocalVars` is called, it won't be able to loop through the variables. Fix it by reinserting them in `GlobalNumericVariableTable` inside `Pattern::match`. Co-authored-by: Thomas Preud'homme <thomas.preudhomme@arm.com>
Diffstat (limited to 'llvm/lib/FileCheck/FileCheck.cpp')
-rw-r--r--llvm/lib/FileCheck/FileCheck.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/FileCheck/FileCheck.cpp b/llvm/lib/FileCheck/FileCheck.cpp
index ce35a5b..9245db4 100644
--- a/llvm/lib/FileCheck/FileCheck.cpp
+++ b/llvm/lib/FileCheck/FileCheck.cpp
@@ -1218,6 +1218,14 @@ Pattern::MatchResult Pattern::match(StringRef Buffer,
StringRef MatchedValue = MatchInfo[CaptureParenGroup];
ExpressionFormat Format = DefinedNumericVariable->getImplicitFormat();
APInt Value = Format.valueFromStringRepr(MatchedValue, SM);
+ // Numeric variables are already inserted into GlobalNumericVariableTable
+ // during parsing, but clearLocalVars might remove them, so we must
+ // reinsert them. Numeric-variable resolution does not access
+ // GlobalNumericVariableTable; it directly uses a pointer to the variable.
+ // However, other functions (such as clearLocalVars) may require active
+ // variables to be in the table.
+ Context->GlobalNumericVariableTable.try_emplace(NumericVariableDef.getKey(),
+ DefinedNumericVariable);
DefinedNumericVariable->setValue(Value, MatchedValue);
}