Commit 32cd773
Douglas Mun
Give
`prev = map.lookup(k)` returns a pointer into the map (NULL when the key
is absent), and the boolean-operand path converted that pointer straight
to i1 via convert_to_bool(). Two things went wrong in
`map.update(k, (prev or 0) + 1)`:
1. the pointer was tested for NULL rather than dereferenced, so the
stored count never took part in the expression; and
2. `or` returned i1 regardless of its operands, so the result was
sign-extended and the addition operated on a 0/1 flag.
The counter therefore stuck at 1 instead of accumulating -- silently, as
the program compiles and loads cleanly.
Fix both halves. `_prepare_bool_operand()` auto-dereferences pointer
operands, mirroring what `get_operand_value()` already does on the binary
-operator path; `deref_to_depth()` emits a null-checked load, so an absent
key yields a zero-valued pointee, which is the fallback `prev or 0` asks
for. The phi in `_handle_and_op`/`_handle_or_op` now carries the operand
values instead of a bool, matching Python, where `a or b` evaluates to an
operand and not to True/False. Operands that cannot yield an integer keep
their previous truth-value behaviour.
Truthiness contexts are unaffected: `if prev:` goes through
functions_pass.py, which calls convert_to_bool() directly, so pointer
NULL-ness still means "is the key present?" there.
Regression tests: the existing IR and llc tiers only assert that
compilation succeeds, so a wrong-value miscompile passes them both, which
is how this survived. tests/test_boolop_semantics.py asserts on the
emitted IR instead -- that or.result is not i1 and that the lookup is
actually loaded. Both fail before this change and pass after.
Refs #89and/or Python value semantics and deref map lookups1 parent 926ce3f commit 32cd773
3 files changed
Lines changed: 142 additions & 24 deletions
File tree
- pythonbpf/expr
- tests
- passing_tests/conditionals
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
401 | 401 | | |
402 | 402 | | |
403 | 403 | | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
404 | 440 | | |
405 | 441 | | |
406 | 442 | | |
407 | 443 | | |
408 | 444 | | |
409 | 445 | | |
410 | | - | |
411 | 446 | | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
412 | 450 | | |
413 | 451 | | |
414 | 452 | | |
| |||
423 | 461 | | |
424 | 462 | | |
425 | 463 | | |
| 464 | + | |
426 | 465 | | |
427 | 466 | | |
428 | 467 | | |
| 468 | + | |
429 | 469 | | |
430 | 470 | | |
431 | 471 | | |
432 | 472 | | |
433 | 473 | | |
434 | | - | |
| 474 | + | |
435 | 475 | | |
436 | | - | |
| 476 | + | |
437 | 477 | | |
438 | | - | |
439 | | - | |
| 478 | + | |
| 479 | + | |
440 | 480 | | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
446 | 486 | | |
447 | 487 | | |
448 | 488 | | |
449 | | - | |
| 489 | + | |
450 | 490 | | |
451 | 491 | | |
452 | 492 | | |
453 | 493 | | |
454 | | - | |
| 494 | + | |
455 | 495 | | |
456 | 496 | | |
457 | 497 | | |
| |||
460 | 500 | | |
461 | 501 | | |
462 | 502 | | |
463 | | - | |
464 | 503 | | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
465 | 508 | | |
466 | 509 | | |
467 | 510 | | |
| |||
476 | 519 | | |
477 | 520 | | |
478 | 521 | | |
| 522 | + | |
479 | 523 | | |
480 | 524 | | |
481 | 525 | | |
| 526 | + | |
482 | 527 | | |
483 | 528 | | |
484 | 529 | | |
485 | 530 | | |
486 | 531 | | |
487 | | - | |
| 532 | + | |
488 | 533 | | |
489 | | - | |
| 534 | + | |
490 | 535 | | |
491 | | - | |
492 | | - | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
493 | 542 | | |
494 | | - | |
495 | | - | |
496 | | - | |
497 | | - | |
498 | | - | |
| 543 | + | |
499 | 544 | | |
500 | 545 | | |
501 | 546 | | |
502 | | - | |
| 547 | + | |
503 | 548 | | |
504 | 549 | | |
505 | 550 | | |
506 | 551 | | |
507 | | - | |
| 552 | + | |
508 | 553 | | |
509 | 554 | | |
510 | 555 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
0 commit comments