This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Extend and document TestIRInterpreter.py
Needs RevisionPublic

Authored by teemperor on Sep 5 2019, 7:57 AM.

Details

Summary

There are a bunch of arithmetic and comparison instructions supported by the IRInterpreter and we
currently don't test these at all in the test suit. This patch extends the IRInterpreter test to try out these operations
with different types and values. Also documents the test case a bit while I'm at it.

Diff Detail

Event Timeline

teemperor created this revision.Sep 5 2019, 7:57 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 5 2019, 7:57 AM
shafik added a subscriber: shafik.Sep 5 2019, 9:30 AM
shafik added inline comments.
lldb/packages/Python/lldbsuite/test/commands/expression/ir-interpreter/TestIRInterpreter.py
55

I may be missing something here but this looks like it should be 32 instead of 7 or rather sizeof(int)*8

When we say doesn't work do we mean undefined behavior?

teemperor marked an inline comment as done.Sep 5 2019, 1:14 PM
teemperor added inline comments.
lldb/packages/Python/lldbsuite/test/commands/expression/ir-interpreter/TestIRInterpreter.py
55

Good catch, originally that was supposed to be > 7 so that we don't overflow any data type (assuming we ever extend the test to char). But I can change it to >= 32 until we actually use any 8-bit type.

And 'doesn't work' means that it will literally cause the test to fail and this test stops working. The interpreter will do something else than the JIT in these cases which is a bug. We probably should detect UB when interpreting these expressions and throw an error, but that's a whole new story. This is more about adding testing to the existing code.

teemperor planned changes to this revision.Sep 5 2019, 1:15 PM
shafik added inline comments.Sep 5 2019, 2:22 PM
lldb/packages/Python/lldbsuite/test/commands/expression/ir-interpreter/TestIRInterpreter.py
55

if I am not missing anything here in C++ and C the operands of expressions undergo the usual arithmetic conversions and for integral types they undergo integer promotions. This means that the smallest type should be int or unsigned int.

More details.

teemperor updated this revision to Diff 219059.Sep 6 2019, 3:42 AM
  • Relaxed can_handle_operands that it allows shifting unsigned large values (produced by initialising them with negative signed values).
  • Now checking for 32bit instead of 7 (thanks Shafik!)
shafik added inline comments.Sep 6 2019, 10:14 AM
lldb/packages/Python/lldbsuite/test/commands/expression/ir-interpreter/TestIRInterpreter.py
49

Maybe be worth noting here that for the unsigned case we are relying in the fact that converting an signed value to an unsigned value works as we would expect with twos complement numbers.

119

You don't see to use interp_result here

135

In the unsigned case should we be converting the python value which is signed manually to an unsigned value via a mask like it is discussed here

teemperor updated this revision to Diff 220857.Sep 19 2019, 6:19 AM
teemperor marked 7 inline comments as done.
  • Addressed feedback.
lldb/packages/Python/lldbsuite/test/commands/expression/ir-interpreter/TestIRInterpreter.py
55

Done, thanks!

119

Yeah, seems that declaring a $variable in LLDB just returns some nonsensical value and a meaningless error... We will know if we have an error later, but at the moment there doesn't seem to be any early error checking we can do here.

jankratochvil requested changes to this revision.Nov 1 2019, 3:40 AM
jankratochvil added a subscriber: jankratochvil.

On Fedora 31 x86_64 (that is with python3-3.7.4-5.fc31.x86_64) I get:

FAIL: LLDB (/quad/home/jkratoch/redhat/llvm-monorepo-clangassertpython3/bin/clang-10-x86_64) :: test_ir_interpreter_int_ops (TestIRInterpreter.IRInterpreterTestCase)
PASS: LLDB (/quad/home/jkratoch/redhat/llvm-monorepo-clangassertpython3/bin/clang-10-x86_64) :: test_type_conversions (TestIRInterpreter.IRInterpreterTestCase)
======================================================================
ERROR: test_ir_interpreter_int_ops (TestIRInterpreter.IRInterpreterTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jkratoch/redhat/llvm-monorepo/lldb/packages/Python/lldbsuite/test/decorators.py", line 112, in wrapper
    func(*args, **kwargs)
  File "/home/jkratoch/redhat/llvm-monorepo/lldb/packages/Python/lldbsuite/test/decorators.py", line 112, in wrapper
    func(*args, **kwargs)
  File "/home/jkratoch/redhat/llvm-monorepo/lldb/packages/Python/lldbsuite/test/decorators.py", line 112, in wrapper
    func(*args, **kwargs)
  File "/home/jkratoch/redhat/llvm-monorepo/lldb/packages/Python/lldbsuite/test/commands/expression/ir-interpreter/TestIRInterpreter.py", line 130, in test_ir_interpreter_int_ops
    if not op.can_handle_operands(var1, var2):
  File "/home/jkratoch/redhat/llvm-monorepo/lldb/packages/Python/lldbsuite/test/commands/expression/ir-interpreter/TestIRInterpreter.py", line 71, in can_handle_operands
    if rhs.value <= 0 or rhs.value >= 32:
TypeError: '<=' not supported between instances of 'c_uint' and 'int'
Config=x86_64-/quad/home/jkratoch/redhat/llvm-monorepo-clangassertpython3/bin/clang-10
----------------------------------------------------------------------
lldb/packages/Python/lldbsuite/test/commands/expression/ir-interpreter/TestIRInterpreter.py
69

Why not < 0?

71

Why not < 0?

This revision now requires changes to proceed.Nov 1 2019, 3:40 AM

Another problem of the test_ir_interpreter is that it fails even when JIT fails despite it should test the interpreter.

Another problem of the test_ir_interpreter is that it fails even when JIT fails despite it should test the interpreter.

Well, it also tests that the IRInterpreter is equivalent to what we would JIT (i.e., our interpreting-vs-JITing optimisation is actually working as intended).

I mean, when a process is not able to allocate memory, it cannot JIT, but still can interpret. Should the test report failure in this case?