public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/28573]  New: incorrectly allowing non-constant expression to offsetof()
@ 2006-08-02 15:14 karl dot corbin at Summit dot Fiserv dot com
  2006-08-02 16:05 ` [Bug c++/28573] [4.0/4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: karl dot corbin at Summit dot Fiserv dot com @ 2006-08-02 15:14 UTC (permalink / raw)
  To: gcc-bugs

The following code incorrectly compiles, and worse returns incorrect result.
on i686-pc-linux-gnu, both 4.1.0 and 4.1.1

-- start snip
#include <stddef.h>

// (incomplete) template class that encapsulates an array of chars
template<int i> class CharArray
{
public:
   char d[i];
   char& operator [] ( int indx )
   {
      return d[indx];
   }
};

struct Foo
{
   int i;
   CharArray<44> caCharArray;
};


int main( int argc, char* argv[] )
{
   Foo foo;
   int i;

// Shouldn't compile, and worse results in incorrect offset.
   i = offsetof(Foo, caCharArray[0]);

}

-- end snip
variables as an array index correctly give an error, but unfortunatly not
everything that looks like an constant array index is.


-- 
           Summary: incorrectly allowing non-constant expression to
                    offsetof()
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: karl dot corbin at Summit dot Fiserv dot com


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/28573] [4.0/4.1/4.2 Regression] incorrectly allowing non-constant expression to offsetof()
  2006-08-02 15:14 [Bug c++/28573] New: incorrectly allowing non-constant expression to offsetof() karl dot corbin at Summit dot Fiserv dot com
@ 2006-08-02 16:05 ` pinskia at gcc dot gnu dot org
  2006-08-06 22:12 ` bangerth at dealii dot org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-08-02 16:05 UTC (permalink / raw)
  To: gcc-bugs



-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid
      Known to fail|                            |3.3.3 4.0.0 4.1.0
      Known to work|                            |3.4.0
            Summary|incorrectly allowing non-   |[4.0/4.1/4.2 Regression]
                   |constant expression to      |incorrectly allowing non-
                   |offsetof()                  |constant expression to
                   |                            |offsetof()
   Target Milestone|---                         |4.0.4


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/28573] [4.0/4.1/4.2 Regression] incorrectly allowing non-constant expression to offsetof()
  2006-08-02 15:14 [Bug c++/28573] New: incorrectly allowing non-constant expression to offsetof() karl dot corbin at Summit dot Fiserv dot com
  2006-08-02 16:05 ` [Bug c++/28573] [4.0/4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
@ 2006-08-06 22:12 ` bangerth at dealii dot org
  2006-08-07  7:38 ` bonzini at gnu dot org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: bangerth at dealii dot org @ 2006-08-06 22:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from bangerth at dealii dot org  2006-08-06 22:12 -------
For some reason, this also passes icc. Interestingly, it isn't even the
case that offsetof manages to look through operator[] -- removing the
body of operator[] doesn't affect the result.

W.


-- 

bangerth at dealii dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bangerth at dealii dot org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2006-08-06 22:12:50
               date|                            |


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/28573] [4.0/4.1/4.2 Regression] incorrectly allowing non-constant expression to offsetof()
  2006-08-02 15:14 [Bug c++/28573] New: incorrectly allowing non-constant expression to offsetof() karl dot corbin at Summit dot Fiserv dot com
  2006-08-02 16:05 ` [Bug c++/28573] [4.0/4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
  2006-08-06 22:12 ` bangerth at dealii dot org
@ 2006-08-07  7:38 ` bonzini at gnu dot org
  2006-08-07 11:50 ` patchapp at dberlin dot org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: bonzini at gnu dot org @ 2006-08-07  7:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from bonzini at gnu dot org  2006-08-07 07:38 -------
This gives an ICE-on-invalid.

  template<int i> struct A
  {
    char d[i];
    char &operator [] ( int indx ) { return d[indx]; }
  };

  struct B
  {
    A<44> a;
  };

  int main()
  {
    return __builtin_offsetof(B, a[0]);
  }

Here, fold_offsetof_1 does not expect a CALL_EXPR to be there and dies.

The reason for the reporter's bug is similar but we do not ICE because we have
another INDIRECT_REF because of dereferencing the "char&" reference, and the
tree is like

INDIRECT_REF( CALL_EXPR ( operator[], INDIRECT_REF(null), 0 ) )

fold_offsetof_1 does not expect anything inside the INDIRECT_REF, and blindly
returns 0.

Testing a patch.


-- 

bonzini at gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |bonzini at gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2006-08-06 22:12:50         |2006-08-07 07:38:41
               date|                            |


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/28573] [4.0/4.1/4.2 Regression] incorrectly allowing non-constant expression to offsetof()
  2006-08-02 15:14 [Bug c++/28573] New: incorrectly allowing non-constant expression to offsetof() karl dot corbin at Summit dot Fiserv dot com
                   ` (2 preceding siblings ...)
  2006-08-07  7:38 ` bonzini at gnu dot org
@ 2006-08-07 11:50 ` patchapp at dberlin dot org
  2006-08-17  7:03 ` bonzini at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: patchapp at dberlin dot org @ 2006-08-07 11:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from patchapp at dberlin dot org  2006-08-07 11:50 -------
Subject: Bug number PR28573

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is
http://gcc.gnu.org/ml/gcc-patches/2006-08/msg00170.html


-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/28573] [4.0/4.1/4.2 Regression] incorrectly allowing non-constant expression to offsetof()
  2006-08-02 15:14 [Bug c++/28573] New: incorrectly allowing non-constant expression to offsetof() karl dot corbin at Summit dot Fiserv dot com
                   ` (3 preceding siblings ...)
  2006-08-07 11:50 ` patchapp at dberlin dot org
@ 2006-08-17  7:03 ` bonzini at gcc dot gnu dot org
  2006-11-01 18:22 ` [Bug c++/28573] [4.0/4.1 " mmitchel at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: bonzini at gcc dot gnu dot org @ 2006-08-17  7:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from bonzini at gnu dot org  2006-08-17 07:03 -------
Subject: Bug 28573

Author: bonzini
Date: Thu Aug 17 07:02:55 2006
New Revision: 116208

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=116208
Log:
2006-08-17  Paolo Bonzini <bonzini@gnu.org>

        PR c++/28573
        * c-common.c (fold_offsetof_1): Add an argument and recurse down to it
        or the INTEGER_CST.  Fail on a CALL_EXPR. 
        (fold_offsetof): Pass new argument to fold_offsetof_1.
        * c-parser.c (c_parser_postfix_expression): Don't include a NULL
        operand into an INDIRECT_REF. 
        * c-typeck.c (build_unary_op): Adjust call to fold_offsetof.

cp:
2006-08-17  Paolo Bonzini  <bonzini@gnu.org>

        PR c++/28573
        * semantics.c (finish_offsetof): Add new argument to fold_offsetof.

testsuite:
2006-08-17  Paolo Bonzini  <bonzini@gnu.org>

        PR c++/28573
        * g++.dg/parse/offsetof6.C: New test.
        * g++.dg/parse/offsetof7.C: New test.


Added:
    trunk/gcc/testsuite/g++.dg/parse/offsetof6.C
    trunk/gcc/testsuite/g++.dg/parse/offsetof7.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/c-common.c
    trunk/gcc/c-common.h
    trunk/gcc/c-parser.c
    trunk/gcc/c-typeck.c
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/semantics.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/28573] [4.0/4.1 Regression] incorrectly allowing non-constant expression to offsetof()
  2006-08-02 15:14 [Bug c++/28573] New: incorrectly allowing non-constant expression to offsetof() karl dot corbin at Summit dot Fiserv dot com
                   ` (4 preceding siblings ...)
  2006-08-17  7:03 ` bonzini at gcc dot gnu dot org
@ 2006-11-01 18:22 ` mmitchel at gcc dot gnu dot org
  2007-02-03 18:42 ` gdr at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2006-11-01 18:22 UTC (permalink / raw)
  To: gcc-bugs



-- 

mmitchel at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/28573] [4.0/4.1 Regression] incorrectly allowing non-constant expression to offsetof()
  2006-08-02 15:14 [Bug c++/28573] New: incorrectly allowing non-constant expression to offsetof() karl dot corbin at Summit dot Fiserv dot com
                   ` (5 preceding siblings ...)
  2006-11-01 18:22 ` [Bug c++/28573] [4.0/4.1 " mmitchel at gcc dot gnu dot org
@ 2007-02-03 18:42 ` gdr at gcc dot gnu dot org
  2007-02-03 20:42 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: gdr at gcc dot gnu dot org @ 2007-02-03 18:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from gdr at gcc dot gnu dot org  2007-02-03 18:42 -------
won't fix in GCC-4.0.x.  Adjustine milestone.


-- 

gdr at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.0.4                       |4.1.3


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/28573] [4.0/4.1 Regression] incorrectly allowing non-constant expression to offsetof()
  2006-08-02 15:14 [Bug c++/28573] New: incorrectly allowing non-constant expression to offsetof() karl dot corbin at Summit dot Fiserv dot com
                   ` (6 preceding siblings ...)
  2007-02-03 18:42 ` gdr at gcc dot gnu dot org
@ 2007-02-03 20:42 ` pinskia at gcc dot gnu dot org
  2007-02-14  9:32 ` mmitchel at gcc dot gnu dot org
  2008-07-04 15:47 ` [Bug c++/28573] [4.1 " jsm28 at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-02-03 20:42 UTC (permalink / raw)
  To: gcc-bugs



-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.1.3                       |4.1.2


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/28573] [4.0/4.1 Regression] incorrectly allowing non-constant expression to offsetof()
  2006-08-02 15:14 [Bug c++/28573] New: incorrectly allowing non-constant expression to offsetof() karl dot corbin at Summit dot Fiserv dot com
                   ` (7 preceding siblings ...)
  2007-02-03 20:42 ` pinskia at gcc dot gnu dot org
@ 2007-02-14  9:32 ` mmitchel at gcc dot gnu dot org
  2008-07-04 15:47 ` [Bug c++/28573] [4.1 " jsm28 at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2007-02-14  9:32 UTC (permalink / raw)
  To: gcc-bugs



-- 

mmitchel at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.1.2                       |4.1.3


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug c++/28573] [4.1 Regression] incorrectly allowing non-constant expression to offsetof()
  2006-08-02 15:14 [Bug c++/28573] New: incorrectly allowing non-constant expression to offsetof() karl dot corbin at Summit dot Fiserv dot com
                   ` (8 preceding siblings ...)
  2007-02-14  9:32 ` mmitchel at gcc dot gnu dot org
@ 2008-07-04 15:47 ` jsm28 at gcc dot gnu dot org
  9 siblings, 0 replies; 11+ messages in thread
From: jsm28 at gcc dot gnu dot org @ 2008-07-04 15:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jsm28 at gcc dot gnu dot org  2008-07-04 15:46 -------
Closing 4.1 branch.


-- 

jsm28 at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
      Known to fail|3.3.3 4.0.0 4.0.4 4.1.1     |3.3.3 4.0.0 4.0.4 4.1.1
                   |                            |4.1.3
         Resolution|                            |FIXED
   Target Milestone|4.1.3                       |4.2.0


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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-07-04 15:47 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-02 15:14 [Bug c++/28573] New: incorrectly allowing non-constant expression to offsetof() karl dot corbin at Summit dot Fiserv dot com
2006-08-02 16:05 ` [Bug c++/28573] [4.0/4.1/4.2 Regression] " pinskia at gcc dot gnu dot org
2006-08-06 22:12 ` bangerth at dealii dot org
2006-08-07  7:38 ` bonzini at gnu dot org
2006-08-07 11:50 ` patchapp at dberlin dot org
2006-08-17  7:03 ` bonzini at gcc dot gnu dot org
2006-11-01 18:22 ` [Bug c++/28573] [4.0/4.1 " mmitchel at gcc dot gnu dot org
2007-02-03 18:42 ` gdr at gcc dot gnu dot org
2007-02-03 20:42 ` pinskia at gcc dot gnu dot org
2007-02-14  9:32 ` mmitchel at gcc dot gnu dot org
2008-07-04 15:47 ` [Bug c++/28573] [4.1 " jsm28 at gcc dot gnu dot org

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).