[llvm] [FileCheck] Fix --enable-var-scope for numvars after reassignment (PR #157158)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 8 07:52:47 PDT 2025
Clipi-12 wrote:
Original PR description as per the last comment:
>This is my first contribution to LLVM, so [I don't have merge perms](https://llvm.org/docs/Contributing.html#how-to-submit-a-patch:~:text=If%20you%20do%20not%20have%20the%20ability%20to%20merge%20the%20PR%2C%20ask%20your%20reviewers%20to%20merge%20it%20on%20your%20behalf.%20You%20must%20do%20this%20explicitly%2C%20as%20reviewers%E2%80%99%20default%20assumption%20is%20that%20you%20are%20able%20to%20merge%20your%20own%20PR.). English is not my first language.
>
>---
>
>* `--enable-var-scope` makes it so that `lib/FileCheck.cpp#clearLocalVars` gets called.
>* That function loops through `GlobalNumericVariableTable` and then calls `NumericVariable#clear` on every item. It also removes it from `GlobalNumericVariableTable`.
>* `Pattern::match` calls `NumericVariable#setValue`, but it assumes the variable is already in `GlobalNumericVariableTable`.
>
>Due to this behaviour, if we:
>
>1. Set a numeric variable.
>1. Clear it with a `CHECK-LABEL:`.
>1. Reassign it.
>1. **[Try to]** clear it again with another `CHECK-LABEL:`.
>
>it won't actually clear it the second time, since to clear it, it needs to be in `GlobalNumericVariableTable` so that `clearLocalVars` can loop through it.
>
>---
>
>This patch simply inserts the numeric variable in `GlobalNumericVariableTable` right before the `NumericVariable#setValue` (in `Pattern::match`) is called.
>
>I edited the `var-scope.txt` test to account for this patch. I also added _--implicit-check-not_ since we don't expect any other errors than the ones we have tested.
>
>I also changed the _--check-prefixes_ since it was really confusing that both the variables and the prefixes were called the same, plus some prefixes being called LOCAL[1-3] but they had nothing to do with the file-content's "local[1-3]".
>I don't know if this last part conflicts with [the "be an isolated change" rule](https://llvm.org/docs/Contributing.html#how-to-submit-a-patch:~:text=be%20an%20isolated%20change), since this is a test-case-legibility-problem and not actual code, but i can remove it and force-push the fork if desired.
https://github.com/llvm/llvm-project/pull/157158
More information about the llvm-commits
mailing list