Re: Warning -Wclobbered in PG_TRY(...) - Mailing list pgsql-hackers

From Maxim Orlov
Subject Re: Warning -Wclobbered in PG_TRY(...)
Date
Msg-id CACG=ezahAraOdD2TE8aX8ABvONip09TvP8UPrQF4WFJ5FB79ZA@mail.gmail.com
Whole thread Raw
In response to Re: Warning -Wclobbered in PG_TRY(...)  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers

On Thu, 29 May 2025 at 18:26, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Go there and use the "keyword search" for "longjmp" --- they
don't seem to make it possible to bookmark individual pages.

Indeed, you are fully correct. I didn't analyse the code well enough. The equivalent code 
for PG_TRY/PG_FINALLY/PG_END_TRY will appear like the following:

do {
    jmp_buf *_save_exception_stack = PG_exception_stack;
    jmp_buf _local_sigjmp_buf;
    bool _do_rethrow = false;

    if (setjmp(_local_sigjmp_buf) == 0)
    {
        PG_exception_stack = &_local_sigjmp_buf;
        /* try here */
        longjmp(_local_sigjmp_buf, 1); /* elog ERROR */
    }
    else
        _do_rethrow = true;

    {
        PG_exception_stack = _save_exception_stack;
        /* catch */
    }

    if (_do_rethrow)
        pg_re_throw();

    PG_exception_stack = _save_exception_stack;
    /* finally */
} while (0);

There is no problem here. We only change _do_rethrow after longjmp. Apparently, we're 
dealing with a false positive warning here. Not sure, but it could be something like [0]. The 
correct solution in this case would be to disable clobbered warning.


--
Best regards,
Maxim Orlov.

pgsql-hackers by date:

Previous
From: jian he
Date:
Subject: Re: Foreign key validation failure in 18beta1
Next
From: Amit Kapila
Date:
Subject: Re: Replication slot is not able to sync up