aboutsummaryrefslogtreecommitdiff
path: root/llvm/utils/update_cc_test_checks.py
AgeCommit message (Collapse)AuthorFilesLines
2025-09-10[UTC] Record TBAA semantics when autogenerating check linesAntonio Frighetto1-0/+10
UpdateTestChecks have been updated to take into account TBAA semantics as well, when emitting checks. This is achieved by parsing TBAA metadata for each tool invocation – whose tool is identified by their prefixes –, and maintaining a global dict of prefixes, TBAA nodes.
2025-04-30Change update_xxx_checks to continue on error when processing mutliple ↵Matthias Braun1-249/+255
inputs (#137728) Change llvm/utils/update_xxx_checks.py scripts to: Catch exceptions individually for each test. On exception print which test triggered the exception and continue with the remaining test updates.
2025-02-19UpdateTestChecks: Don't check meta details in func definition w/--global ↵Jinsong Ji1-1/+3
none (#124205) When --check-globals none, we skipped all the globals in check lines. However, we are still checking the meta info in function defintion. The generated checks are still sensitive to metadata changes. This is to scrub the meta info and match them with {{.*}} instead.
2025-01-13Handle leading underscores in update_cc_test_checks.py (#121800)Momchil Velikov1-6/+24
For some ABIs `update_cc_test_checks.py` is unable to generate tests because of the mismatch between the mangled function names reported by clang's `-asd-dump` and the function names in LLVM IR. This patch fixes it by striping the leading underscore from the mangled name for global functions if the data layout string says they have one.
2024-05-19update_test_checks: match IR basic block labels (#88979)Nicolai Hähnle1-26/+23
Labels are matched using a regexp of the form '^(pattern):', which requires the addition of a "suffix" concept to NamelessValue. Aside from that, the key challenge is that block labels are values, and we typically capture values including the prefix '%'. However, when labels appear at the start of a basic block, the prefix '%' is not included, so we must capture block label values *without* the prefix '%'. We don't know ahead of time whether an IR value is a label or not. In most cases, they are prefixed by the word "label" (their type), but this isn't the case in phi nodes. We solve this issue by leveraging the two-phase nature of variable generalization: the first pass finds all occurences of a variable and determines whether the '%' prefix can be included or not. The second pass does the actual substitution. This change also unifies the generalization path for assembly with that for IR and analysis, in the hope that any future changes avoid diverging those cases future. I also considered the alternative of trying to detect the phi node case using more regular expression special cases but ultimately decided against that because it seemed more fragile, and perhaps the approach of keeping a tentative prefix that may later be discarded could also be eventually applied to some metadata and attribute cases. Note that an early version of this change was reviewed as https://reviews.llvm.org/D142452, before version numbers were introduced. This is a substantially updated version of that change.
2023-11-13Recommit changes to global checks (#71171)Henrik G. Olsson1-7/+13
Recommits the changes from https://reviews.llvm.org/D148216. Explicitly named globals are now matched literally, instead of emitting a capture group for the name. This resolves #70047. Metadata and annotations, on the other hand, are captured and matched against by default, since their identifiers are not stable. The reasons for revert (#63746) have been fixed: The first issue, that of duplicated checkers, has already been resolved in #70050. This PR resolves the second issue listed in #63746, regarding the order of named and unnamed globals. This is fixed by recording the index of substrings containing global values, and sorting the checks according to that index before emitting them. This results in global value checks being emitted in the order they were seen instead of being grouped separately.
2023-07-14Revert "[UTC] Add fallback support for specific metadata, and check their defs"Johannes Doerfert1-13/+7
This reverts commit 8a3fdf7b908978625e9a7e57fbb443e4e6f98976 as it is broken. See https://github.com/llvm/llvm-project/issues/63746. Effectively fixes: https://github.com/llvm/llvm-project/issues/63746
2023-07-05[UTC] Add fallback support for specific metadata, and check their defsHenrik G. Olsson1-7/+13
This prevents update_cc_tests.py from emitting hard-coded identifiers for metadata (global variable checkers still check hard-coded identifiers). Instead it emits regex checkers that match even if the identifiers change. Also adds a new mode for --check-globals: instead of simply being on or off, it now has the options 'none', 'smart' and 'all', with 'none' and 'all' corresponding to the previous modes. The 'smart' mode only emits checks for global definitions referenced in the IR or other metadata that itself has a definition checker emitted, making the rule transitive. It does not emit checks for attribute sets, since that is better checked by --check-attributes. This mode is made the new default. To make the change in default mode backwards compatible a version bump is introduced (to v3), and the default remains 'none' in v1 & v2. This will result in metadata checks being emitted more often, so filters are added to not check absolute file paths and compiler version git hashes. rdar://105239218
2023-05-17[NFC][Py Reformat] Reformat python files in llvmTobias Hieta1-397/+509
This is the first commit in a series that will reformat all the python files in the LLVM repository. Reformatting is done with `black`. See more information here: https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style Reviewed By: jhenderson, JDevlieghere, MatzeB Differential Revision: https://reviews.llvm.org/D150545
2023-03-02[UTC] Include return type/attributes under --version 2Nikita Popov1-0/+2
If --function-signature is used with --version 2, then also include the return type/attributes in the check lines. This is the implementation of D133943 rebased on the --version mechanism from D142473. This doesn't bump the default version yet, because I'd like to do that together with D140212 (which enables --function-signature by default), as these changes seem closely related. For now this functionality can be accessed by explicitly passing --version 2 to UTC. Fixes https://github.com/llvm/llvm-project/issues/61058. Differential Revision: https://reviews.llvm.org/D144963
2023-02-04[UpdateTestChecks][NFC] Share the code to get CHECK prefix between all scriptsShengchen Kan1-4/+1
Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D143307
2022-11-28[UpdateTestChecks] Fix `update_*_test_checks.py` to add "unused" prefixesMircea Trofin1-16/+32
The support introduced in D124306 was only added to update_llc_test_checks.py, but the motivating usecases (see https://lists.llvm.org/pipermail/llvm-dev/2021-February/148326.html) cover update_test_checks.py, update_cc_test_checks.py, and update_analyze_test_checks.py, too. Issue #59220. Differential Revision: https://reviews.llvm.org/D138836
2022-09-21[Utils] Refactor update_cc_test_checks.py to use shutilJohn McIver1-3/+11
The package `distutils` is deprecated and removal is planned for Python 3.12. All calls to `distutils.spawn.find_executable` are replaced with local version of `find_executable` which makes use of `shutils.which`. Reviewed By: arichardson, MaskRay Differential Revision: https://reviews.llvm.org/D134015
2022-09-20Revert "[Utils] Refactor update_cc_test_checks.py to use shutil"Ben Dunbobbin1-3/+3
This reverts commit 2e6c50855b7d879ded3776ba87b3d960e2035b89. This caused failures on windows bots: - https://lab.llvm.org/buildbot/#/builders/216/builds/10030 - https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci/clang-windows-x64/b8802513693562827489/overview
2022-09-20[Utils] Refactor update_cc_test_checks.py to use shutilJohn McIver1-3/+3
The package distutils is deprecated and removal is planned for Python 3.12. All calls to distutils.spawn.find_executable are replaced with shutil.which. Differential Revision: https://reviews.llvm.org/D134015
2022-07-20update-test-checks: safely handle tests with #if'sNicolai Hähnle1-0/+1
There is at least one Clang test (clang/test/CodeGen/arm_acle.c) which has functions guarded by #if's that cause those functions to be compiled only for a subset of RUN lines. This results in a case where one RUN line has a body for the function and another doesn't. Treat this case as a conflict for any prefixes that the two RUN lines have in common. This change exposed a bug where functions with '$' in the name weren't properly recognized in ARM assembly (despite there being a test case that was supposed to catch the problem!). This bug is fixed as well. Differential Revision: https://reviews.llvm.org/D130089
2022-07-13Change shebang from python to python3 in update_cc_test_checks.pyRoman Rusyaev1-1/+1
All update_test_checks.py scripts were updated in this revision https://reviews.llvm.org/D70730 except for update_cc_test_checks.py. Reviewed By: barannikov88 Differential Revision: https://reviews.llvm.org/D129590
2022-05-26[UpdateTestChecks] Auto-generate stub bodies for unused prefixesMircea Trofin1-10/+10
This is scoped to autogenerated tests. The goal is to support having each RUN line specify a list of check-prefixes where one can specify potentially redundant prefixes. For example, for X86, if one specified prefixes for both AVX1 and AVX2, and the codegen happened to match today, one of the prefixes would be used and the onther one not. If the unused prefix were dropped, and later, codegen differences were introduced, one would have to go figure out where to add what prefix (paraphrasing https://lists.llvm.org/pipermail/llvm-dev/2021-February/148326.html) To avoid getting errors due to unused prefixes, whole directories can be opted out (as discussed on that thread), but that means that tests that aren't autogenerated in such directories could have undetected unused prefix bugs. This patch proposes an alternative that both avoids the above, dir-level optout, and supports the main autogen scenario discussed first. The autogen tool appends at the end of the test file the list of unused prefixes, together with a note explaining that is the case. Each prefix is set up to always pass. This way, unexpected unused prefixes are easily discoverable, and expected cases "just work". Differential Revision: https://reviews.llvm.org/D124306
2022-05-14[update_llc_test_checks] Use FileCheck captures for MCInst/MCReg outputAlex Richardson1-1/+1
To avoid test churn when backends add/rename new instructions/registers, it makes sense to use FileCheck captures for the exact MCInst/Reg number. This is motivated by D125307, where I use --asm-show-inst to differentiate the output for multiple instructions with the same mnemonic. This does not quite fix the churn issue yet: While files with the generated checks will be immune to the numbers changing, the update script test still suffers from this problem since the number is encoded in the FileCheck variable name. I plan to address this in a follow-up patch. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D125307
2022-03-21Reapply [Utils] Fix %S substitutionNikita Popov1-1/+1
%S refers to the directory of %s, not to the cwd. This is mostly handled correctly, but update_cc_test_checks.py used the wrong path for non-FileCheck RUN lines. Reapplying this with a fix for an update_cc_test_checks test that was based on cwd semantics.
2022-03-21Revert "[Utils] Fix %S substitution"Nikita Popov1-1/+1
This reverts commit 8ee1ef2a087da1a101a6b2c0bea31788da289e0b. This breaks an update_cc_test_checks test that is based on an incorrect %S use, revert until I can fix it.
2022-03-21[Utils] Fix %S substitutionNikita Popov1-1/+1
%S refers to the directory of %s, not to the cwd. This is mostly handled correctly, but update_cc_test_checks.py used for the wrong path for non-FileCheck RUN lines.
2022-03-01[UpdateLLCTestChecks] Add support for isel debug output in ↵Yatao Wang1-1/+1
update_llc_test_checks.py Add a check on run lines to pick up isel options in llc commands and allow generating check lines of isel final output other than assembly. If llc command line contains -debug-only=isel, update_llc_test_checks.py will try to scrub isel output, otherwise, the script will fall back on default behaviour, which is try to scrub assembly output instead. The motivation of this change is to allow usage of update_llc_test_checks.py to autogenerate checks of instruction selection results. In this way, we can detect errors at an earlier stage before the compilation goes all the way to assembly. It is an example of having some transparency for the stages between IR and assembly. These generated tests are almost like "unit tests" of isel stage. This patch only implements the initial change to differentiate isel output from assembly output for Lanai. Other targets will not be supported for isel check generation at the moment. Although adding support for it will only require implementing the function regex and scrubber for corresponding targets. The Lanai implementation was chosen mainly for the simplicity of demonstrating the difference between isel checks and asm checks. This patch also do not include the implementation of function prefix, which is required for the generated isel checks to pass. I will put up a follow up revision for the function prefix change to complete isel support. Reviewed By: Flakebi Differential Revision: https://reviews.llvm.org/D119368
2022-01-31[UpdateTestChecks] Re-add --filter and --filter-out optionsDavid Greene1-3/+6
Re-add filtering options with fixes for failed tests. We were not passing the is_filtered argument in all check generator calls in update_cc_test_checks.py Enhance the various update_*_test_checks.py tools to allow filtering the tool output with regular expressions. The --filter option will emit only tool output lines matching the given regular expression while the --filter-out option will emit only tools output lines not matching the given regular expression. Filters are applied in order of appearance on the command line (or in UTC_ARGS) and the first matching filter terminates the search. This allows test authors to create more focused tests by removing irrelevant tool output and checking only the pieces of output necessary to test the desired functionality. Differential Revision: https://reviews.llvm.org/D117694
2022-01-28Revert "[UpdateTestChecks] Add --filter and --filter-out options"David Greene1-2/+1
Broke some update-test-checks tests. Reverting while developing a fix. This reverts commit 030f71698d52f228929da5e3148602f4a3daff7d.
2022-01-28[UpdateTestChecks] Add --filter and --filter-out optionsDavid Greene1-1/+2
Enhance the various update_*_test_checks.py tools to allow filtering the tool output with regular expressions. The --filter option will emit only tool output lines matching the given regular expression while the --filter-out option will emit only tools output lines not matching the given regular expression. Filters are applied in order of appearance on the command line (or in UTC_ARGS) and the first matching filter terminates the search. This allows test authors to create more focused tests by removing irrelevant tool output and checking only the pieces of output necessary to test the desired functionality. Differential Revision: https://reviews.llvm.org/D117694
2021-07-29[Utils] Do not remove comments in llc test scriptSebastian Neubauer1-1/+1
When checking if two prefixes can be merged for a function, update_llc_test_checks.py removed IR comments before comparing llc outputs of different RUN lines. This means, if one RUN line emited lines starting with ';' and another RUN line emited the same lines except the ones starting with ';', both RUNs would be merged (if they share a prefix). However, CHECK-NEXT lines check the comments, otherwise they fail, so the script should not merge RUNs if they contain different comments. Differential Revision: https://reviews.llvm.org/D101312
2021-07-28[Utils] Support class template specializations in update_cc_test_checksJessica Clarke1-23/+38
ClassTemplateSpecializationDecl not within a ClassTemplateDecl represents an explicit instatiation of a template and so should be handled as if it were a normal CXXRecordDecl. Unfortunately, having an equivalent for FunctionTemplateDecl remains a TODO in ASTDumper's VisitFunctionTemplateDecl, with all the explicit instantiations just being emitted inside the FunctionTemplateDecl along with all the other specializations, meaning we can't easily support explicit function instantiations in update_cc_test_checks. Reviewed By: arichardson Differential Revision: https://reviews.llvm.org/D106243
2021-06-25[UpdateCCTestChecks] Support --check-globalsJoel E. Denny1-0/+18
This option is already supported by update_test_checks.py, but it can also be useful in update_cc_test_checks.py. For example, I'd like to use it in OpenMP offload codegen tests to check global variables like `.offload_maptypes*`. Reviewed By: jdoerfert, arichardson, ggeorgakoudis Differential Revision: https://reviews.llvm.org/D104714
2021-06-20[UpdateTestUtils] Print test filename when complaining about conflicting prefixRoman Lebedev1-1/+2
Now that FileCheck eagerly complains when prefixes are unused, the update script does the same, and is becoming very common to need to drop some prefixes, yet figuring out the file it complains about isn't obvious unless it actually tells us.
2021-05-04[Utils] Run non-filecheck runlines in-order in update_cc_test_checksGiorgis Georgakoudis1-10/+17
The script update_cc_test_checks runs all non-filechecked runlines before the filechecked ones. This creates problems since outputs of those non-filechecked runlines may conflict and that will fail the execution of update_cc_test_checks. This patch executes non-filechecked in the order specified in the test file to avoid this issue. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D101683
2021-03-16[Utils] Support lit-like substitutions in update_cc_test_checksGiorgis Georgakoudis1-7/+17
Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D98712
2021-03-10Run non-filechecked commands in update_cc_test_checks.pyGiorgis Georgakoudis1-11/+25
Some tests in clang require running non-filechecked commands to generate the actual filecheck input. For example, tests for openmp offloading require generating the host bc without any checking, before running the clang command to actually generate the filechecked IR of the target device. This patch enables `update_cc_test_checks.py` to run non-filechecked run lines in-place. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D97068
2021-03-08Revert "Run non-filechecked commands in update_cc_test_checks.py"Jon Roelofs1-25/+11
This reverts commit 60d4c73b30a0e324c6ae314722eb036f70f4b03a. The new test is broken on macos hosts. Discussion here: https://reviews.llvm.org/D97068#2611269 https://reviews.llvm.org/D97068#2612675 ... revert to green.
2021-03-08Run non-filechecked commands in update_cc_test_checks.pyGiorgis Georgakoudis1-11/+25
Some tests in clang require running non-filechecked commands to generate the actual filecheck input. For example, tests for openmp offloading require generating the host bc without any checking, before running the clang command to actually generate the filechecked IR of the target device. This patch enables `update_cc_test_checks.py` to run non-filechecked run lines in-place. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D97068
2020-12-16[NFC] factor update test function test builder as a classMircea Trofin1-17/+16
This allows us to have shared logic over multiple test runs, e.g. do we have unused prefixes, or which function bodies have conflicting outputs for a prefix appearing in different RUN lines. This patch is just wrapping existing functionality, and replacing its uses. A subsequent patch would then fold the current functionality into the newly introduced class. Differential Revision: https://reviews.llvm.org/D93413
2020-09-18[UpdateCCTestChecks] Include generated functions if askedDavid Greene1-37/+80
Add the --include-generated-funcs option to update_cc_test_checks.py so that any functions created by the compiler that don't exist in the source will also be checked. We need to maintain the output order of generated function checks so that CHECK-LABEL works properly. To do so, maintain a list of functions output for each prefix in the order they are output. Use this list to output checks for generated functions in the proper order. Differential Revision: https://reviews.llvm.org/D83004
2020-08-12[UpdateTestChecks] Match unnamed values like "@[0-9]+" and "![0-9]+"Johannes Doerfert1-1/+2
With this patch we will match most *uses* of "temporary" named things in the IR via regular expressions, not their name at creation time. The new "values" we match are: - "unnamed" globals: `@[0-9]+` - debug metadata: `!dbg ![0-9]+` - loop metadata: `!loop ![0-9]+` - tbaa metadata: `!tbaa ![0-9]+` - range metadata: `!range ![0-9]+` - generic metadata: `metadata ![0-9]+` - attributes groups: `#[0-9]` We still don't match the declarations but that can be done later. This patch can introduce churn when existing check lines contain the old hardcoded versions of the above "values". We can add a flag to opt-out, or opt-in, if necessary. Reviewed By: arichardson, MaskRay Differential Revision: https://reviews.llvm.org/D85099
2020-08-03Fix update_cc_test_checks.py --llvm-bin after D78478Alex Richardson1-11/+16
Not passing --clang would result in a python exception after this change: (TypeError: expected str, bytes or os.PathLike object, not NoneType) because the --clang argument default was only being populated in the initial argument parsing pass but not later on. Fix this by adding an argparse callback to set the default values. Reviewed By: vitalybuka, MaskRay Differential Revision: https://reviews.llvm.org/D84511
2020-07-19[Utils] Check function attributes in update_test_checkssstefan11-1/+3
Summary: This introduces new flag to the update_test_checks and update_cc_test_checks that allows for function attributes to be checked in a check-line. If the flag is not set, the behavior should remain the same. Reviewers: jdoerfert Subscribers: arichardson, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D83629
2020-07-08[UpdateTestChecks] Add UTC_ARGS support for update_{llc,cc}_test_checks.pyAlex Richardson1-51/+38
https://reviews.llvm.org/D69701 added support for on-the-fly argument changes for update scripts. I recently wanted to keep some manual check lines in a test generated by update_cc_test_checks.py in our CHERI fork, so this commit adds support for UTC_ARGS in update_cc_test_checks.py. And since I was refactoring the code to be in common.py, I also added it for update_llc_test_checks.py. Reviewed By: jdoerfert, MaskRay Differential Revision: https://reviews.llvm.org/D78478
2020-06-18[update_cc_test_checks.py] Handle C++ methodsAlex Richardson1-4/+7
Previously the script only handled C input, this change extends the JSON parsing to to also include C++ function types such as methods, constructors and destructors. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D80914
2020-06-18[update_cc_test_checks.py] Correctly skip function definitionsAlex Richardson1-2/+12
Function declarations can in fact have an 'inner' node that lists the ParmVarDecls. It seems like either the JSON output has changed or that I tested the original JSON parsing change with test files that only have function definitions without arguments. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D80913
2020-02-14Fix line endings produced by update_cc_test_checks.pyAlex Richardson1-4/+4
Use the same appraoch as update_llc_test_checks.py to always write \n line endings. This should fix the Windows buildbots.
2020-02-04[update_cc_test_checks] Don't attach CHECK lines to function declarationsAlex Richardson1-0/+4
Previously we were adding the CHECK lines to both definitions and declarations. Update the JSON AST dump parsing code to skip all FunctionDecls without an "inner" node (i.e. no body). Reviewed By: MaskRay, greened Differential Revision: https://reviews.llvm.org/D73708
2020-01-02Make mangled_names.test and update_cc_test_checks.py work with Python 2.Nico Weber1-7/+12
Differential Revision: https://reviews.llvm.org/D71565
2019-12-02[update_cc_test_checks.py] Use CHECK_RE from commonAlex Richardson1-3/+1
Summary: This change modifies the common.CHECK_RE regex to also handle '//' comment prefixes which allows us to share it between clang and IR tests. Using the regex from common means that *-SAME lines are also stripped now. Before this change using the --function-signature flag would result in -SAME: lines from previous runs not being removed. Reviewers: MaskRay, jdoerfert Reviewed By: jdoerfert Subscribers: jdoerfert, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D70890
2019-12-02[update_cc_test_checks.py] Handle extern "C" and namespacesAlex Richardson1-9/+18
Summary: My change to use the clang AST JSON dump did not handle functions declared inside scopes other than the root TranslationUnitDecl. After this change update_cc_test_checks.py also works for C++ test cases that use extern "C" and namespaces. Reviewers: MaskRay Reviewed By: MaskRay Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D70389
2019-12-02[UpdateTestChecks] Share the code to parse RUN: lines between all scriptsAlex Richardson1-27/+9
Summary: This commit also introduces a common.debug() function to avoid many `if args.verbose:` statements. Depends on D70428. Reviewers: xbolva00, MaskRay, jdoerfert Reviewed By: MaskRay Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D70432
2019-11-20[update_cc_test_checks.py] Add the --function-signature flagAlex Richardson1-2/+5
Summary: This was added to update_test_checks.py in D68819 and I believe having it in update_cc_test_checks.py is also useful. Reviewers: jdoerfert, MaskRay Reviewed By: MaskRay Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D70429