This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
prevent undefined behaviour at a language level while probing getenv
authorH.Merijn Brand <perl5@tux.freedom.nl>
Wed, 9 Jun 2021 08:22:49 +0000 (10:22 +0200)
committerH.Merijn Brand <perl5@tux.freedom.nl>
Wed, 9 Jun 2021 08:22:49 +0000 (10:22 +0200)
commit93c7859ef0f08c82802b3e0e3072f22f8002f7fb
treeef2ee11804228549f42ad96ff96e2246f23990f9
parentc7120a50126e37db451b7e65051e40cb254c84ce
prevent undefined behaviour at a language level while probing getenv

Backport of a5823872283be23731f1bcde7e19a926c44b31a4

This test in Configure tries to probe for undefined behaviour in
getenv (), but provokes undefined behaviour in C/C++ by falling off
the end of a function with a non-void return type.

Without optimization clang++ generated a ud2 instruction here on
amd64 producing an illegal instruction exception.  With optimization
the test case fell off the end and started re-executing main (),
eventually producing a SIGBUS.

Simply dropping the value of getenv () here and returning NULL wasn't
useful, under -O2 the compiler optimized away the getenv () call,
voiding the whole point of the test.
U/threads/d_getenv_thread.U