https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121516

            Bug ID: 121516
           Summary: libgccjit++.h: improper usage of &params[0]
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: jit
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: dmalcolm at gcc dot gnu.org
                CC: antoyo at gcc dot gnu.org
  Target Milestone: ---

jit.dg/test-asm.cc fails here:

        PASSED: test-asm.cc.exe iteration 1 of 5: set_up_logging: logfile is
non-null
/opt/rh/gcc-toolset-15/root/usr/include/c++/15/bits/stl_vector.h:1263:
std::vector<_Tp, _Alloc>::reference std::vector
<_Tp, _Alloc>::operator[](size_type) [with _Tp = gccjit::param; _Alloc =
std::allocator<gccjit::param>; reference = gc
cjit::param&; size_type = long unsigned int]: Assertion '__n < this->size()'
failed.
PASS: test-asm.cc.exe iteration 1 of 5: set_up_logging: logfile is non-null
DISCARDED exp6 :
/opt/rh/gcc-toolset-15/root/usr/include/c++/15/bits/stl_vector.h:1263:
std::vector<_Tp, _Alloc>::refe
rence std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp =
gccjit::param; _Alloc = std::allocator<gccjit::param
>; reference = gccjit::param&; size_type = long unsigned int]: Assertion '__n < 
>this->size()' failed.
FAIL: test-asm.cc.exe killed: SIGABRT SIGABRT
FAIL: did not find a generated reproducer: test-asm.cc.exe.reproducer.c

test-asm.cc failure is out of bounds std::vector op:

/opt/rh/gcc-toolset-15/root/usr/include/c++/15/bits/stl_vector.h:1263:
std::vector<_Tp, _Alloc>::reference std::vector<_Tp,
_Alloc>::operator[](size_type) [with _Tp = gccjit::param; _Alloc =
std::allocator<gccjit::param>; reference = gccjit::param&; size_type = long
unsigned int]: Assertion '__n < this->size()' failed.
Aborted (core dumped)

(gdb) bt
#0  0x00007ffff4ebde9c in __pthread_kill_implementation () from
/lib64/libc.so.6
#1  0x00007ffff4e67a96 in raise () from /lib64/libc.so.6
#2  0x00007ffff4e4f8fa in abort () from /lib64/libc.so.6
#3  0x00007ffff50e0d70 in std::__glibcxx_assert_fail(char const*, int, char
const*, char const*) ()
   from /lib64/libstdc++.so.6
#4  0x0000000000404ea1 in std::vector<gccjit::param,
std::allocator<gccjit::param> >::operator[] (
    this=0x7fffffffd950, __n=0) at
/opt/rh/gcc-toolset-15/root/usr/include/c++/15/bits/stl_vector.h:1263
#5  0x0000000000403e59 in gccjit::context::new_function (this=0x7fffffffd938,
kind=GCC_JIT_FUNCTION_EXPORTED, 
    return_type=..., name="test_i386_basic_asm_1", params=std::vector of length
0, capacity 0, is_variadic=0, 
    loc=...) at
rpmbuild/BUILD/gcc-15.1.1-20250521/gcc/testsuite/../jit/libgccjit++.h:888
#6  0x0000000000401114 in make_single_block_func (ctxt=..., func_name=0x40d395
"test_i386_basic_asm_1")
    at rpmbuild/BUILD/gcc-15.1.1-20250521/gcc/testsuite/jit.dg/test-asm.cc:21
#7  0x0000000000401394 in create_test_i386_basic_asm_1 (c_ctxt=0x438000)
    at rpmbuild/BUILD/gcc-15.1.1-20250521/gcc/testsuite/jit.dg/test-asm.cc:71
#8  0x0000000000403b29 in create_code (ctxt=0x438000, user_data=0x0)
    at rpmbuild/BUILD/gcc-15.1.1-20250521/gcc/testsuite/jit.dg/test-asm.cc:448
#9  0x0000000000400f3f in test_jit (argv0=0x7fffffffe0a4
"/root/test-asm.cc.exe", user_data=0x0)
    at rpmbuild/BUILD/gcc-15.1.1-20250521/gcc/testsuite/jit.dg/harness.h:378
#10 0x000000000040104e in main (argc=1, argv=0x7fffffffdd68)
    at rpmbuild/BUILD/gcc-15.1.1-20250521/gcc/testsuite/jit.dg/harness.h:438

where:

(gdb) p params
$2 = std::vector of length 0, capacity 0

887       /* Treat std::vector as an array, relying on it not being resized: */
888       param *as_array_of_wrappers = &params[0];

We should be using vector::data() instead here.

Reply via email to