Subtle bug involving array returning function and the simple if construct


I have encountered a problem, most likely a bug in the PGI compiler 21.7. This problem shows up when the following pattern is used several times :


GZ_M_W being a function returning an array. Turning the previous statement into :


makes the problem disappear. The generated assembly code is then different.

The whole code is available here (several files are involved so I put it on github):

The error is this :

[ufh62jk@jean-zay2: pgi-bug-if-func]$ pgf90 --version

pgf90 (aka nvfortran) 21.7-0 64-bit target on x86-64 Linux -tp skylake 
PGI Compilers and Tools
Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES.  All rights reserved.
[ufh62jk@jean-zay2: pgi-bug-if-func]$ lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: RedHatEnterprise
Description:    Red Hat Enterprise Linux release 8.1 (Ootpa)
Release:        8.1
Codename:       Ootpa
[ufh62jk@jean-zay2: pgi-bug-if-func]$ ./main.x 
0: ALLOCATE: 7107430004627624728 bytes requested; not enough memory

Best regards,


Hi Philippe,

This is a subtle one. My best guess is that the stack is getting corrupted somehow. I’m not convinced that it’s really a problem with the if clause, rather this may just be perturbating the code enough to work around the issue. Also if I apply optimization to this case (like -O2), then the code works. However if I then change TURB_V1 to use the if only conditional as well, it will fail again even at -O2. So maybe?

I’m going to need engineering to take a look to get a better understanding what’s going on so I filed TPR #30537.


Thank you Mats