Optimization of signed integer overflow since GCC 8

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear all,

I am having the problem, that since GCC 8 in the following code the if-section is optimized away for any optimization levels above 0.
But actually for a negative value of 'a', the value of 'ret' will overflow and thus 'ret' will be < 0, so the if-section cannot be optimized away.

#include <stdint.h>
int32_t foo(int32_t a)
{
    int32_t ret = INT32_MAX - a;

    if (ret < 0) {
        ret -= 50;
    }

    return ret;
}

I am guessing, this is due to the fact, that signed integer overflow is undefined behavior in C/C++ and thus the compiler assumes this is prevented. Can you confirm this?
Can you give a hint, if this is a correct assumption and why this was introduced?

Which part of GCC 8 release notes represents this optimization?

Best regards
Lars

[https://wilo-download.cdn.mediamid.com/footer/WILO674319_Join_the_ecolution_E_Mail_Signatur_350_260.jpg] <https://wilo.com/>
________________________________

WILO SE
Wilopark 1, 44263 Dortmund
Amtsgericht Dortmund, HRB 21356
www.wilo.com

Vorstand/Executive Board:
Oliver Hermes (President & CEO), Dr. Patrick Niehr, Georg Weber, Mathias Weyers
Aufsichtsratsvorsitzender/Chairman of the Supervisory Board:
Lars Roßner

Dieses Dokument ist vertraulich zu behandeln. Die Weitergabe sowie Vervielfaeltigung, Verwertung und Mitteilung seines Inhalts ist nur mit unserer ausdruecklichen Genehmigung gestattet. Alle Rechte vorbehalten, insbesondere fuer den Fall der Schutzrechtsanmeldung.
This document has to be treated confidentially. Its contents are not to be passed on, duplicated, exploited or disclosed without our expressed permission. All rights reserved, especially the right to apply for protective rights.

Datenschutz ist uns wichtig! Daher gehen wir sorgsam mit Ihren Daten um. Näheres finden Sie in unseren Datenschutzhinweisen<https://wilo.com/de/de/Wilo-Deutschland/Datenschutzhinweise.html>. Sollten Sie keinen Kontakt mehr mit uns wünschen, wenden Sie sich bitte an datenschutz@xxxxxxxx<mailto:datenschutz@xxxxxxxx>.
Data Protection is important to us! Therefore we handle your data carefully. Please find the details in our Note on Data Protection<https://wilo.com/de/de/Note-on-data-protection.html>. If you do not wish to stay in touch with us anymore, please write to data-privacy@xxxxxxxx<mailto:data-privacy@xxxxxxxx>.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux