public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/111242] New: Out of bounds pointer arithmetic not caught in constexpr
@ 2023-08-30 16:51 llvm at rifkin dot dev
  2023-08-30 17:07 ` [Bug c++/111242] " pinskia at gcc dot gnu.org
  2023-08-30 17:07 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: llvm at rifkin dot dev @ 2023-08-30 16:51 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111242
           Summary: Out of bounds pointer arithmetic not caught in
                    constexpr
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: llvm at rifkin dot dev
  Target Milestone: ---

The following UB is not caught by gcc:

#include <vector>

constexpr auto tester() {
  std::vector<int> v = {1, 2, 3};
  auto p = &v[v.size() + 1];
  return &v[0] == p;
}

static_assert(!tester());


https://godbolt.org/z/Y3ofcb1b1

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

* [Bug c++/111242] Out of bounds pointer arithmetic not caught in constexpr
  2023-08-30 16:51 [Bug c++/111242] New: Out of bounds pointer arithmetic not caught in constexpr llvm at rifkin dot dev
@ 2023-08-30 17:07 ` pinskia at gcc dot gnu.org
  2023-08-30 17:07 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-30 17:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed reduced testcase:
```

#define size 3
constexpr auto tester() {
  int *v = new int[size];
  auto p = &v[size+1];
  bool t = &v[0] == p;
  delete[] v;
  return t;
}

static_assert(!tester());

#if 0
constexpr auto tester1() {
  int v[size];
  auto p = &v[size+1];
  bool t = &v[0] == p;
  return t;
}
static_assert(!tester1());
#endif
```

GCC does catch the static allocated one; just not the dynamic allocated one.

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

* [Bug c++/111242] Out of bounds pointer arithmetic not caught in constexpr
  2023-08-30 16:51 [Bug c++/111242] New: Out of bounds pointer arithmetic not caught in constexpr llvm at rifkin dot dev
  2023-08-30 17:07 ` [Bug c++/111242] " pinskia at gcc dot gnu.org
@ 2023-08-30 17:07 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-30 17:07 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-08-30
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
.

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

end of thread, other threads:[~2023-08-30 17:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-30 16:51 [Bug c++/111242] New: Out of bounds pointer arithmetic not caught in constexpr llvm at rifkin dot dev
2023-08-30 17:07 ` [Bug c++/111242] " pinskia at gcc dot gnu.org
2023-08-30 17:07 ` pinskia at gcc dot gnu.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).