public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "mikulas at artax dot karlin.mff.cuni.cz" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/63303] Pointer subtraction is broken when using -fsanitize=undefined
Date: Fri, 19 Sep 2014 16:15:00 -0000	[thread overview]
Message-ID: <bug-63303-4-BdsWonNBjJ@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-63303-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63303

--- Comment #6 from mikulas at artax dot karlin.mff.cuni.cz ---
"you really can't have an object bigger than half of the address space in
C/C++" - where does the standard claim this? If this is true, we should change
malloc so that it doesn't allocate 2GiB or larger objects.


Regarding pointer difference, the C standard says this:

When two pointers are subtracted, both shall point to elements of the same
array object, or one past the last element of the array object; the result is
the difference of the subscripts of the two array elements. The size of the
result is implementation-defined, and its type (a signed integer type) is
ptrdiff_t defined in the <stddef.h> header. If the result is not representable
in an object of that type, the behavior is undefined. In other words, if the
expressions P and Q point to, respectively, the i-th and j-th elements of an
array object, the expression (P)-(Q) has the value i−j provided the value fits
in an object of type ptrdiff_t.

So: p points to the beginning, q points one past the last element, so the first
condition is valid.

The result is the difference of the subscripts of those two array elements:
0x50000000 - 0 = 0x50000000 - this is clearly representable in the type
ptrdiff_t, so 0x50000000 result should be returned.
>From gcc-bugs-return-462131-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Sep 19 16:20:57 2014
Return-Path: <gcc-bugs-return-462131-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 3399 invoked by alias); 19 Sep 2014 16:20:57 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 3333 invoked by uid 48); 19 Sep 2014 16:20:50 -0000
From: "krebbel at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug debug/63300] 'const volatile' sometimes stripped in debug info
Date: Fri, 19 Sep 2014 16:20:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: debug
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: krebbel at gcc dot gnu.org
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_status cf_reconfirmed_on cc everconfirmed
Message-ID: <bug-63300-4-xNCZFiYOEJ@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-63300-4@http.gcc.gnu.org/bugzilla/>
References: <bug-63300-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2014-09/txt/msg01965.txt.bz2
Content-length: 1932

https://gcc.gnu.org/bugzilla/show_bug.cgi?idc300

Andreas Krebbel <krebbel at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-09-19
                 CC|                            |mark at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from Andreas Krebbel <krebbel at gcc dot gnu.org> ---
Reghunt indicates that this is caused by r214143.

For a const volatile type none of the following IFs is triggered:

  if ((cv_quals & TYPE_QUAL_CONST)
      /* If there are multiple type modifiers, prefer a path which
     leads to a qualified type.  */
      && (((cv_quals & ~TYPE_QUAL_CONST) == TYPE_UNQUALIFIED)
      || get_qualified_type (type, cv_quals) == NULL_TREE
      || (get_qualified_type (type, cv_quals & ~TYPE_QUAL_CONST)
          != NULL_TREE)))
    {
      mod_type_die = new_die (DW_TAG_const_type, mod_scope, type);
      sub_die = modified_type_die (type, cv_quals & ~TYPE_QUAL_CONST,
                   context_die);
    }
  else if ((cv_quals & TYPE_QUAL_VOLATILE)
       && (((cv_quals & ~TYPE_QUAL_VOLATILE) == TYPE_UNQUALIFIED)
           || get_qualified_type (type, cv_quals) == NULL_TREE
           || (get_qualified_type (type, cv_quals & ~TYPE_QUAL_VOLATILE)
           != NULL_TREE)))
    {
      mod_type_die = new_die (DW_TAG_volatile_type, mod_scope, type);
      sub_die = modified_type_die (type, cv_quals & ~TYPE_QUAL_VOLATILE,
                   context_die);
    }
  else if (cv_quals & TYPE_QUAL_RESTRICT)
    {
      mod_type_die = new_die (DW_TAG_restrict_type, mod_scope, type);
      sub_die = modified_type_die (type, cv_quals & ~TYPE_QUAL_RESTRICT,
                   context_die);
    }

So the DIE ends up with an unqualified type.


  parent reply	other threads:[~2014-09-19 16:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-19  1:42 [Bug c/63303] New: " mikulas at artax dot karlin.mff.cuni.cz
2014-09-19  7:26 ` [Bug c/63303] " jakub at gcc dot gnu.org
2014-09-19 13:38 ` mikulas at artax dot karlin.mff.cuni.cz
2014-09-19 13:47 ` jakub at gcc dot gnu.org
2014-09-19 15:50 ` mikulas at artax dot karlin.mff.cuni.cz
2014-09-19 15:57 ` jakub at gcc dot gnu.org
2014-09-19 16:15 ` mikulas at artax dot karlin.mff.cuni.cz [this message]
2014-09-19 16:21 ` joseph at codesourcery dot com
2014-09-19 16:22 ` jakub at gcc dot gnu.org
2014-09-19 16:29 ` mikulas at artax dot karlin.mff.cuni.cz
2014-09-22  7:42 ` rguenth at gcc dot gnu.org
2014-09-22 14:31 ` mikulas at artax dot karlin.mff.cuni.cz
2015-10-19 11:03 ` rguenth at gcc dot gnu.org

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-63303-4-BdsWonNBjJ@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).