[Bug c/83172] New: -Wstack-size= doesn't detect the correct stack size with VLA or alloca
hao.hou at utah dot edu
gcc-bugzilla@gcc.gnu.org
Sun Nov 26 23:41:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83172
Bug ID: 83172
Summary: -Wstack-size= doesn't detect the correct stack size
with VLA or alloca
Product: gcc
Version: 4.8.5
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: hao.hou at utah dot edu
Target Milestone: ---
Created attachment 42723
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42723&action=edit
The preprocessed source code repoduce the bug
The -Wstack-usage= doesn't deduce the correct stack size and reports an
unbounded stack size in the following case:
1. The function uses a variable length array
2. The function uses alloca
Even with alloca(constant) or __builtin_unreachable hints the VLA size,
compiler still mark the max stack size unbounded.
Another related option -Wvla-larger-than= does inferred the maximum VLA size
from the __builtin_unreachable hints.
The expected behavior should be -Wstack-usage= also follows the hint, at least,
for the alloca(constant) case, it should realize the stack size could not be
unbounded.
GCC Version:
Using built-in specs.
COLLECT_GCC=gcc-7
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
7.1.0-10ubuntu1~16.04.york0'
--with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr
--with-gcc-major-version-only --program-suffix=-7
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib
--with-target-system-zlib --enable-objc-gc=auto --enable-multiarch
--disable-werror --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 7.1.0 (Ubuntu 7.1.0-10ubuntu1~16.04.york0)
And the preprocessed file that repo this bug is attached.
The command used to repo the bug and it's output:
$ gcc-7 -save-temps -Wvla-larger-than=128 -Wstack-usage=102400 -O3 -c t.c
t.c: In function ‘stack_usage_only’:
t.c:21:5: warning: stack usage might be unbounded [-Wstack-usage=]
int stack_usage_only(unsigned x)
^~~~~~~~~~~~~~~~
t.c: In function ‘alloca_fails_even_with_const’:
t.c:30:5: warning: stack usage might be unbounded [-Wstack-usage=]
int alloca_fails_even_with_const()
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expected:
Compiles without any warning.
More information about the Gcc-bugs
mailing list