Bug 48767 - compiler error: Segmentation fault with set void in va_arg
Summary: compiler error: Segmentation fault with set void in va_arg
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.4.6
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-26 00:47 UTC by Nobuhiro Iwamatsu
Modified: 2011-05-30 06:03 UTC (History)
1 user (show)

See Also:
Host:
Target: sh*-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-04-26 09:26:30


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nobuhiro Iwamatsu 2011-04-26 00:47:29 UTC
Hi,

When we set void in va_arg, it becomes Segmentation fault.
This problem was confirmed on gcc-4.3, 4.4, 4.5 and 4.6.

$ cat a.c
#include <stdarg.h>
void f(va_list ap) { va_arg(ap,void); }
$ gcc -c  a.c
a.c: In function 'f':
a.c:2: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.4/README.Bugs> for instructions.

$gcc -v 
Using built-in specs.
Target: sh4-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.6-2' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --with-multiarch-defaults=sh4-linux-gnu --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --with-multilib-list=m4,m4-nofpu --with-cpu=sh4 --enable-checking=release --build=sh4-linux-gnu --host=sh4-linux-gnu --target=sh4-linux-gnu
Thread model: posix
gcc version 4.4.6 (Debian 4.4.6-2)
Comment 1 Kazumoto Kojima 2011-04-26 09:26:30 UTC
This is a target problem.  The patch below will fix it.
BTW, I'm not sure that it's an invalid use of void or not in C,
though g++ treats it as invalid.

       * config/sh/sh.c (sh_gimplify_va_arg_expr): Don't call
       targetm.calls.must_pass_in_stack for void type.

--- ORIG/trunk/gcc/config/sh/sh.c	2011-04-23 09:43:19.000000000 +0900
+++ trunk/gcc/config/sh/sh.c	2011-04-26 10:40:25.000000000 +0900
@@ -8062,9 +8062,14 @@ sh_gimplify_va_arg_expr (tree valist, tr
   HOST_WIDE_INT size, rsize;
   tree tmp, pptr_type_node;
   tree addr, lab_over = NULL, result = NULL;
-  int pass_by_ref = targetm.calls.must_pass_in_stack (TYPE_MODE (type), type);
+  bool pass_by_ref;
   tree eff_type;
 
+  if (!VOID_TYPE_P (type))
+    pass_by_ref = targetm.calls.must_pass_in_stack (TYPE_MODE (type), type);
+  else
+    pass_by_ref = false;
+
   if (pass_by_ref)
     type = build_pointer_type (type);
Comment 2 Nobuhiro Iwamatsu 2011-04-27 02:37:37 UTC
Hi,

Thanks for your work.

(In reply to comment #1)
> This is a target problem.  The patch below will fix it.

I confirm fix on gcc-4.4, 4,5 and 4.6.
Thanks!

> BTW, I'm not sure that it's an invalid use of void or not in C,
> though g++ treats it as invalid.

Yes, I think too.
I will ask upstream writing such code.

Nobuhiro
Comment 3 Kazumoto Kojima 2011-04-27 12:49:09 UTC
Fixed on trunk.
Comment 4 Nobuhiro Iwamatsu 2011-05-30 05:36:31 UTC
Could you backport earch branches?
If you need patch, I will create.
Comment 5 Kazumoto Kojima 2011-05-30 06:03:35 UTC
It isn't a regression, is it?
My gcc-4.2 segfaults too for that testcase.