public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "samueldotj at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/53790] New: ICE on dereferencing a extern union in asm statement
Date: Wed, 27 Jun 2012 21:17:00 -0000	[thread overview]
Message-ID: <bug-53790-4@http.gcc.gnu.org/bugzilla/> (raw)

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53790

             Bug #: 53790
           Summary: ICE on dereferencing a extern union in asm statement
    Classification: Unclassified
           Product: gcc
           Version: 4.6.3
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: samueldotj@gmail.com


Created attachment 27713
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27713
Preprocessed sources

gcc-4.6.3 causes ICE when compiling program which dereferences a extern union
in asm().

It is avoided if the union's structure is made known to the compiler at compile
time.(Defined inside the c file or in an include file).
Removing optimization(-O0) also avoid this problem.

------------------------------
typedef long long uint64;

typedef struct s {
    uint64 value;
} s_t;

static inline uint64
do_some_asm(s_t const *var)
{
   uint64 value;

   __asm__ __volatile__(
      "xor %1, %0"
      : "=r" (value)
      : "r" (var->value)
   );

   return value;
}

typedef union u u_t;

int main()
{
    extern u_t extern_var;
    return do_some_asm((s_t *)&extern_var);
}

----------------------------

$gcc -v -save-temps -O3 sample.c
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/4.6.3/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ./configure
Thread model: posix
gcc version 4.6.3 (GCC)
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O3' '-mtune=generic' '-march=x86-64'
 /usr/local/libexec/gcc/x86_64-unknown-linux-gnu/4.6.3/cc1 -E -quiet -v
sample.c -mtune=generic -march=x86-64 -O3 -fpch-preprocess -o sample.i
ignoring nonexistent directory
"/usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.6.3/../../../../x86_64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.6.3/include
 /usr/local/include
 /usr/local/lib/gcc/x86_64-unknown-linux-gnu/4.6.3/include-fixed
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O3' '-mtune=generic' '-march=x86-64'
 /usr/local/libexec/gcc/x86_64-unknown-linux-gnu/4.6.3/cc1 -fpreprocessed
sample.i -quiet -dumpbase sample.c -mtune=generic -march=x86-64 -auxbase sample
-O3 -version -o sample.s
GNU C (GCC) version 4.6.3 (x86_64-unknown-linux-gnu)
        compiled by GNU C version 4.6.3, GMP version 4.3.2, MPFR version
2.4.2-p1, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C (GCC) version 4.6.3 (x86_64-unknown-linux-gnu)
        compiled by GNU C version 4.6.3, GMP version 4.3.2, MPFR version
2.4.2-p1, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 4cf08a0fcb4b2719a02f394936c437ef
sample.c: In function ‘main’:
sample.c:15:17: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.

Currently I am working around this by applying the following patch.
diff -rupN gcc-4.6.3/gcc/expr.c gcc-4.6.3.new1/gcc/expr.c
--- gcc-4.6.3/gcc/expr.c        2012-02-09 09:28:22.000000000 -0800
+++ gcc-4.6.3.new1/gcc/expr.c   2012-06-20 22:53:10.613748645 -0700
@@ -9182,6 +9182,7 @@ expand_expr_real_1 (tree exp, rtx target
        orig_op0 = op0
          = expand_expr (tem,
                         (TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE
+              && TYPE_SIZE (TREE_TYPE (tem))
                          && (TREE_CODE (TYPE_SIZE (TREE_TYPE (tem)))
                              != INTEGER_CST)
                          && modifier != EXPAND_STACK_PARM


             reply	other threads:[~2012-06-27 21:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-27 21:17 samueldotj at gmail dot com [this message]
2012-06-27 21:18 ` [Bug middle-end/53790] " samueldotj at gmail dot com
2012-06-27 21:20 ` pinskia at gcc dot gnu.org
2012-06-27 21:25 ` samueldotj at gmail dot com
2012-06-27 21:31 ` samueldotj at gmail dot com
2012-06-28 10:00 ` [Bug middle-end/53790] [4.6/4.7/4.8 Regression] " rguenth at gcc dot gnu.org
2012-06-28 11:45 ` rguenth at gcc dot gnu.org
2012-06-28 11:53 ` rguenth at gcc dot gnu.org
2012-06-28 12:01 ` rguenth at gcc dot gnu.org
2012-06-28 12:02 ` rguenth at gcc dot gnu.org
2012-06-28 12:02 ` rguenth at gcc dot gnu.org
2012-06-29  0:26 ` samueldotj at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-53790-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).