Commit b972a1d
committed
Drop <new> requirement for JitCall wrappers.
The JitCall wrapper generator used to emit plain `new (ret) (T) (call())`,
`new (ptr) T(args...)`, and `new (p) T[n]` for its placement-new forms,
binding against the standard placement operators declared in <new>. That
forced every user of JitCall to pull <new> into the interpreter's TU and
every ctor-using test to pass `-include new` on the command line.
Append `, __ci_newtag` to the two scalar placement-new sites -- the
return-value branch of make_narg_call_with_return and the scalar-ctor
branch of make_narg_ctor_with_return -- so they resolve against
clang-repl's preloaded tagged overload `operator new(size_t, void*,
__clang_Interpreter_NewTag)`. That overload is declared by the Runtimes
string introduced in llvm/llvm-project@1566f1ffc6b5 and first released
in LLVM 18. CppInterOp already registers `__ci_newtag` as an absolute
symbol in the JIT dylib, so no new runtime machinery is needed.
The default-ctor wrapper's `nary > 1 && is_arena` branch is rewritten as
a loop of scalar tagged placement news rather than `new (p) T[n]`. Two
alternatives were considered and rejected:
(a) A tagged `operator new[](size_t, void*, Tag)` would give the
minimum per-wrapper emission, but clang does not recognise a
custom-signature array allocator as the standard placement form
and inserts an array cookie for types with non-trivial destructors
(Itanium C++ ABI §2.7), breaking the contract that
`Cpp::Construct(scope, arena, n)` returns `arena`.
(b) Forward-declaring the STANDARD-signature
`operator new[](size_t, void*)` would satisfy clang's placement
recognition, but the declaration is not portably replicable:
libstdc++, libc++, and the MSVC STL decorate it with different
noexcept macros, calling conventions, and [[nodiscard]]
attributes. A user-supplied `#include <new>` after interpreter
creation would clash with ours and crash the parse.
Cling is unaffected: it pre-includes <new> at IncrementalParser init, so
the empty tag on that backend is equivalent to plain scalar placement
new.
With the wrapper no longer needing <new>, the JitCall-adjacent tests
drop their `#include <new>` declares and `-include new` compiler flags.
Sites that were cargo pulling in <new> for unrelated reflection tests
(no JitCall use, no direct `<new>` dependency) drop the flag too --
where the test already pulls in `<memory>`, `<string>`, or `<vector>`,
the `<new>` declarations arrive transitively.
Two regression guards pin the contract:
* FunctionReflection_JitCallNoNewHeader asserts the no-<new> premise
via a non-noexcept redeclaration of `operator new(size_t, void*)`
(per [new.delete.placement] the standard placement forms are
noexcept, so the redeclaration parses cleanly only when <new> is
not in scope) and then exercises a scalar-return JitCall.
* FunctionReflection_ArrayConstructNoCookie constructs an array of a
class with a user-provided destructor, asserts
`Cpp::Construct(scope, arena, n) == arena`, and cross-checks each
element's value at `arena + i*sizeof(T)`. A future revert to a
tagged `operator new[]` or any non-standard-signature placement
allocator fires this test immediately.1 parent a727d4f commit b972a1d
7 files changed
Lines changed: 176 additions & 72 deletions
File tree
- lib/CppInterOp
- unittests/CppInterOp
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2767 | 2767 | | |
2768 | 2768 | | |
2769 | 2769 | | |
| 2770 | + | |
| 2771 | + | |
| 2772 | + | |
| 2773 | + | |
| 2774 | + | |
| 2775 | + | |
| 2776 | + | |
| 2777 | + | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
| 2785 | + | |
| 2786 | + | |
| 2787 | + | |
| 2788 | + | |
| 2789 | + | |
| 2790 | + | |
2770 | 2791 | | |
2771 | 2792 | | |
2772 | 2793 | | |
| |||
2790 | 2811 | | |
2791 | 2812 | | |
2792 | 2813 | | |
2793 | | - | |
2794 | | - | |
2795 | | - | |
2796 | | - | |
2797 | | - | |
2798 | | - | |
| 2814 | + | |
| 2815 | + | |
| 2816 | + | |
| 2817 | + | |
| 2818 | + | |
| 2819 | + | |
| 2820 | + | |
| 2821 | + | |
| 2822 | + | |
| 2823 | + | |
| 2824 | + | |
| 2825 | + | |
| 2826 | + | |
| 2827 | + | |
| 2828 | + | |
| 2829 | + | |
| 2830 | + | |
| 2831 | + | |
| 2832 | + | |
| 2833 | + | |
| 2834 | + | |
| 2835 | + | |
| 2836 | + | |
| 2837 | + | |
| 2838 | + | |
| 2839 | + | |
2799 | 2840 | | |
2800 | 2841 | | |
2801 | 2842 | | |
2802 | | - | |
2803 | | - | |
2804 | | - | |
2805 | | - | |
2806 | | - | |
2807 | | - | |
2808 | | - | |
2809 | | - | |
2810 | | - | |
| 2843 | + | |
| 2844 | + | |
| 2845 | + | |
| 2846 | + | |
| 2847 | + | |
| 2848 | + | |
| 2849 | + | |
| 2850 | + | |
2811 | 2851 | | |
2812 | 2852 | | |
2813 | | - | |
2814 | | - | |
2815 | | - | |
2816 | 2853 | | |
2817 | 2854 | | |
2818 | 2855 | | |
2819 | 2856 | | |
2820 | 2857 | | |
2821 | 2858 | | |
2822 | | - | |
2823 | | - | |
2824 | | - | |
| 2859 | + | |
| 2860 | + | |
| 2861 | + | |
| 2862 | + | |
2825 | 2863 | | |
2826 | 2864 | | |
2827 | | - | |
| 2865 | + | |
| 2866 | + | |
2828 | 2867 | | |
2829 | 2868 | | |
2830 | 2869 | | |
| |||
2908 | 2947 | | |
2909 | 2948 | | |
2910 | 2949 | | |
2911 | | - | |
| 2950 | + | |
| 2951 | + | |
2912 | 2952 | | |
2913 | 2953 | | |
2914 | 2954 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
705 | 705 | | |
706 | 706 | | |
707 | 707 | | |
708 | | - | |
709 | | - | |
| 708 | + | |
710 | 709 | | |
711 | 710 | | |
712 | 711 | | |
| |||
1560 | 1559 | | |
1561 | 1560 | | |
1562 | 1561 | | |
1563 | | - | |
| 1562 | + | |
1564 | 1563 | | |
1565 | 1564 | | |
1566 | 1565 | | |
| |||
1617 | 1616 | | |
1618 | 1617 | | |
1619 | 1618 | | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
1620 | 1650 | | |
1621 | 1651 | | |
1622 | 1652 | | |
| |||
1638 | 1668 | | |
1639 | 1669 | | |
1640 | 1670 | | |
1641 | | - | |
1642 | | - | |
1643 | | - | |
1644 | | - | |
| 1671 | + | |
1645 | 1672 | | |
1646 | 1673 | | |
1647 | 1674 | | |
| |||
1682 | 1709 | | |
1683 | 1710 | | |
1684 | 1711 | | |
1685 | | - | |
1686 | | - | |
| 1712 | + | |
1687 | 1713 | | |
1688 | 1714 | | |
1689 | 1715 | | |
| |||
1785 | 1811 | | |
1786 | 1812 | | |
1787 | 1813 | | |
1788 | | - | |
1789 | | - | |
| 1814 | + | |
1790 | 1815 | | |
1791 | 1816 | | |
1792 | 1817 | | |
| |||
2446 | 2471 | | |
2447 | 2472 | | |
2448 | 2473 | | |
2449 | | - | |
2450 | 2474 | | |
2451 | 2475 | | |
2452 | 2476 | | |
2453 | | - | |
2454 | 2477 | | |
2455 | 2478 | | |
2456 | 2479 | | |
| |||
2463 | 2486 | | |
2464 | 2487 | | |
2465 | 2488 | | |
2466 | | - | |
| 2489 | + | |
2467 | 2490 | | |
2468 | 2491 | | |
2469 | 2492 | | |
| |||
2534 | 2557 | | |
2535 | 2558 | | |
2536 | 2559 | | |
2537 | | - | |
2538 | | - | |
| 2560 | + | |
2539 | 2561 | | |
2540 | 2562 | | |
2541 | 2563 | | |
| |||
2577 | 2599 | | |
2578 | 2600 | | |
2579 | 2601 | | |
2580 | | - | |
2581 | | - | |
| 2602 | + | |
2582 | 2603 | | |
2583 | 2604 | | |
2584 | | - | |
2585 | 2605 | | |
2586 | 2606 | | |
2587 | 2607 | | |
| |||
2643 | 2663 | | |
2644 | 2664 | | |
2645 | 2665 | | |
2646 | | - | |
2647 | 2666 | | |
2648 | 2667 | | |
2649 | 2668 | | |
| |||
2695 | 2714 | | |
2696 | 2715 | | |
2697 | 2716 | | |
2698 | | - | |
2699 | | - | |
| 2717 | + | |
2700 | 2718 | | |
2701 | 2719 | | |
2702 | | - | |
2703 | 2720 | | |
2704 | 2721 | | |
2705 | 2722 | | |
| |||
2768 | 2785 | | |
2769 | 2786 | | |
2770 | 2787 | | |
2771 | | - | |
2772 | | - | |
| 2788 | + | |
2773 | 2789 | | |
2774 | 2790 | | |
2775 | | - | |
2776 | 2791 | | |
2777 | 2792 | | |
2778 | 2793 | | |
| |||
2834 | 2849 | | |
2835 | 2850 | | |
2836 | 2851 | | |
| 2852 | + | |
| 2853 | + | |
| 2854 | + | |
| 2855 | + | |
| 2856 | + | |
| 2857 | + | |
| 2858 | + | |
| 2859 | + | |
| 2860 | + | |
| 2861 | + | |
| 2862 | + | |
| 2863 | + | |
| 2864 | + | |
| 2865 | + | |
| 2866 | + | |
| 2867 | + | |
| 2868 | + | |
| 2869 | + | |
| 2870 | + | |
| 2871 | + | |
| 2872 | + | |
| 2873 | + | |
| 2874 | + | |
| 2875 | + | |
| 2876 | + | |
| 2877 | + | |
| 2878 | + | |
| 2879 | + | |
| 2880 | + | |
| 2881 | + | |
| 2882 | + | |
| 2883 | + | |
| 2884 | + | |
| 2885 | + | |
| 2886 | + | |
| 2887 | + | |
| 2888 | + | |
| 2889 | + | |
| 2890 | + | |
| 2891 | + | |
| 2892 | + | |
| 2893 | + | |
| 2894 | + | |
| 2895 | + | |
| 2896 | + | |
| 2897 | + | |
| 2898 | + | |
| 2899 | + | |
| 2900 | + | |
| 2901 | + | |
| 2902 | + | |
| 2903 | + | |
| 2904 | + | |
| 2905 | + | |
| 2906 | + | |
| 2907 | + | |
| 2908 | + | |
| 2909 | + | |
| 2910 | + | |
| 2911 | + | |
| 2912 | + | |
| 2913 | + | |
| 2914 | + | |
2837 | 2915 | | |
2838 | 2916 | | |
2839 | 2917 | | |
| |||
3003 | 3081 | | |
3004 | 3082 | | |
3005 | 3083 | | |
3006 | | - | |
| 3084 | + | |
3007 | 3085 | | |
3008 | 3086 | | |
3009 | 3087 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
161 | | - | |
| 161 | + | |
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| |||
538 | 538 | | |
539 | 539 | | |
540 | 540 | | |
541 | | - | |
542 | 541 | | |
543 | 542 | | |
544 | 543 | | |
| |||
555 | 554 | | |
556 | 555 | | |
557 | 556 | | |
558 | | - | |
559 | 557 | | |
560 | 558 | | |
561 | 559 | | |
| |||
0 commit comments