Bug#1135526: Possible miscompilation at -O2

David Bremner <[email protected]> Sat, 02 May 2026 17:43:34 +0900
Newsgroups gmane.linux.debian.devel.gcc
Message-ID <87tssq2ocp.fsf__20785.1237429836$1777711526$gmane$org@tethera.net>
At optimization level -O1 (or with gcc-15 15.2.0-16), notmuch 0.40
builds and the test suite passes. At -O2, many segfaults occur when
running the test suite. I looked at one such segfault, and the code in
question starts at line 332 of notmuch-reply.c.

Element 0 of reply_to_map gets field get_header initialized properly
with O1 but set to 0x0 at level O2. The latter is of course fatal
when the code just below tries to call through this table.
The other elements of the table look OK.

    struct {
	InternetAddressList * (*get_header)(GMimeMessage *message);
	GMimeAddressType recipient_type;
    } reply_to_map[] = {
	{ get_sender,   GMIME_ADDRESS_TYPE_TO },
	{ get_to,       GMIME_ADDRESS_TYPE_TO },
	{ get_cc,       GMIME_ADDRESS_TYPE_CC },
	{ get_bcc,      GMIME_ADDRESS_TYPE_BCC },
    };

I guess in principle there could be some undefined behaviour here, but
e.g. there is no warnings from -Wall or cppcheck.

All 4 functions are declared static void in the same compilation unit.

I tried building with gcc-16, and the behaviour looks similar: O1 is
fine, O2 yields segfaults in the test suite.