Home > front end >  C : gcc compiler warning for large stack allocation
C : gcc compiler warning for large stack allocation

Time:12-26

Consider:

void largestackallocation() {
    double a[10000000];
}

int main() {
    return 0;
}

On compiling this with MSVC (Cl.exe and MSBuild.exe), a warning C6262 is issued suggesting to move allocation to heap instead of the stack. The compilation is in release mode with the following options:

/permissive- /ifcOutput "x64\Release\" /GS /GL /W3 /Gy /Zc:wchar_t /I"E:\local\boost_1_72_0" /Zi /Gm- /O2 /sdl /Fd"x64\Release\vc142.pdb" /Zc:inline /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /Gd /Oi /MD /FC /Fa"x64\Release\" /EHsc /nologo /Fo"x64\Release\" /FA /Fp"x64\Release\windows.pch" /diagnostics:column

On gcc, with a release mode build with the option to even convert warnings to errors:

g      -c -O2 -Werror -MMD -MP -MF "build/Release/GNU-Linux/_ext/511e4115/largestackallocation.o.d" -o build/Release/GNU-Linux/_ext/511e4115/largestackallocation.o ../src/largestackallocation.cpp
mkdir -p dist/Release/GNU-Linux

no warning/errors are issued. What is the option/setting to make gcc/g issue warnings on potentially large stack allocations?

CodePudding user response:

-Wlarger-than="max-bytes" might be what you're looking for. It warns you whenever an object is defined whose size exceeds "max-bytes".

  • Related