This is an archive of the discontinued LLVM Phabricator instance.

[FileCheck, 3/4] Allow AP value for numeric expressions
ClosedPublic

Authored by thopre on May 18 2023, 9:17 AM.

Details

Summary

Use APInt to represent numeric variables and expressions, therefore
removing overflow concerns. Only remains underflow when the format of an
expression is unsigned (incl. hex values) but the result is negative.
Note that this can only happen when substituting an expression, not when
capturing since the regex used to capture unsigned value will not include
minus sign, hence all the code removal for match propagation testing.
This is what this patch implement.

Diff Detail

Event Timeline

thopre created this revision.May 18 2023, 9:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 18 2023, 9:17 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
thopre requested review of this revision.May 18 2023, 9:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 18 2023, 9:17 AM
thopre retitled this revision from Allow AP value for numeric expressions to [RFC] Allow AP value for numeric expressions.May 22 2023, 9:03 AM
thopre retitled this revision from [RFC] Allow AP value for numeric expressions to [RFC, FileCheck] Allow AP value for numeric expressions.May 31 2023, 3:00 AM
arichardson accepted this revision.Jun 26 2023, 7:51 AM

Overall LGTM but as this is a rather large diff I may have missed something.

llvm/lib/FileCheck/FileCheck.cpp
161

[[maybe_unused]] for the variable instead of the void cast?

llvm/lib/FileCheck/FileCheckImpl.h
122

To reduce the size of the diff we could have this class wrap a single apint but since you've made the changes to remove it already I think we may as well remove it.

161

Hmm maybe we should add using ExpressionValue = APInt to avoid all these changes.

llvm/test/FileCheck/match-time-error-propagation/matched-excluded-pattern.txt
4

It seems like some of this test is still useful, we just have to create a different error?

llvm/unittests/FileCheck/FileCheckTest.cpp
398

The test previously used 64 bit values, do we need 128 bit here?

This revision is now accepted and ready to land.Jun 26 2023, 7:51 AM

Ping?

Sorry @thopre, I have too many other reviews on my plate to ever realistically be able to get around to this.

Overall LGTM but as this is a rather large diff I may have missed something.

I'll try your suggestion to see if we can have 2 smaller diffs instead. Do you have any opinion on the question in the second paragraph of the description?

llvm/lib/FileCheck/FileCheckImpl.h
122

That's a good idea, I'll explore this to see if I can create 2 patches instead of 1. I don't mind a bit more work if it makes for an easier review.

161

They have different interface but I could use APInt inside ExpressionValue instead of int64_t as suggested above.

thopre updated this revision to Diff 537040.Jul 4 2023, 4:03 AM
  • Split APInt change into separate patches and only keep changes to support arbitrary precision
  • use [[maybe_unused]] instead of (void)
thopre marked 4 inline comments as done.Jul 4 2023, 4:04 AM
thopre added inline comments.
llvm/unittests/FileCheck/FileCheckTest.cpp
396–397

Unused, oops

487–490

Oops

thopre requested review of this revision.Jul 4 2023, 4:05 AM
thopre retitled this revision from [RFC, FileCheck] Allow AP value for numeric expressions to [RFC, FileCheck, 3/4] Allow AP value for numeric expressions.Jul 4 2023, 4:07 AM
thopre edited the summary of this revision. (Show Details)
thopre added inline comments.Jul 4 2023, 7:51 AM
llvm/test/FileCheck/match-time-error-propagation/matched-excluded-pattern.txt
4

This patch removes the one case where the error path tested by these tests can happen. After this patch the parsing of integer in valueFromStringRepr() would need to fail for the path to be triggered by the regex used to match numeric values ensures that integer are valid. See https://reviews.llvm.org/D154431 for more details.

arichardson added inline comments.Jul 4 2023, 9:25 AM
llvm/lib/FileCheck/FileCheck.cpp
246

std::max?

252

The API might be a bit nicer if evalbinop did the widening of apints?

263

This should be unnecessary.

llvm/test/FileCheck/match-time-error-propagation/matched-excluded-pattern.txt
4

Ah fair enough that makes sense. Is the error handling still tested after removing this test? If not, could keep coverage by changing the error to be a divide by zero?

thopre updated this revision to Diff 537174.Jul 4 2023, 2:01 PM
thopre marked 2 inline comments as done.

Address review comments

thopre added inline comments.Jul 4 2023, 2:07 PM
llvm/lib/FileCheck/FileCheck.cpp
252

EvalBinop is a function pointer to one of the expr* functions above. That would mean adding that logic in all those functions. This code here is in a single place instead. I could split it out into a separate function if you prefer?

llvm/test/FileCheck/match-time-error-propagation/matched-excluded-pattern.txt
4

TL;DR: the code tested by this is dead code, it cannot be exercise.

Long answer:
Divide by zero can only happens when substituting a numeric expression which leads to a match failure. These tests were for errors after a successful match, which only happened when a value could not fit in a numeric variable due to overflow/underflow. As can be seen by the removal of the code in match() in D154431 there is no more any failure in match() after a successful match. The whole code that this test was testing is effectively dead and could be removed, but I'm wary of removing it in case some change in FileCheck makes it necessary again.

thopre added a comment.Aug 4 2023, 3:28 AM

Ping?

Ping?

arichardson accepted this revision.Aug 6 2023, 5:49 PM

Looks good to me. Sorry for the delay.

llvm/lib/FileCheck/FileCheck.cpp
252

Ah yes of course. I don't really mind, so this should be fine.

This revision is now accepted and ready to land.Aug 6 2023, 5:49 PM
thopre retitled this revision from [RFC, FileCheck, 3/4] Allow AP value for numeric expressions to [FileCheck, 3/4] Allow AP value for numeric expressions.Aug 7 2023, 6:48 AM
thopre edited the summary of this revision. (Show Details)
This revision was automatically updated to reflect the committed changes.
llvm/test/FileCheck/match-time-error-propagation/matched-excluded-pattern.txt