public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95942] New: [11 regression] offsetof on an array: error: 'e' is not a constant expression
@ 2020-06-27 18:22 slyfox at inbox dot ru
2020-06-27 18:29 ` [Bug c++/95942] " slyfox at inbox dot ru
` (10 more replies)
0 siblings, 11 replies; 12+ messages in thread
From: slyfox at inbox dot ru @ 2020-06-27 18:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95942
Bug ID: 95942
Summary: [11 regression] offsetof on an array: error: 'e' is
not a constant expression
Product: gcc
Version: 10.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: slyfox at inbox dot ru
Target Milestone: ---
The original error is seen on https://www.dolphin-emu.org/ project as a build
error. Minimized example looks the following:
"""
// $ cat.bug.cc
struct a {
int b;
char c[100];
};
unsigned long d(long e) { return __builtin_offsetof(a, c[e]); }
"""
OK:
$ LANG=C g++-10.1.0 -c bug.cc -o bug.o
OK:
$ LANG=C clang++-10 -c bug.cc -o bug.o
FAIL:
$ LANG=C g++-11.0.0 -c bug.cc -o bug.o
bug.cc: In function 'void d(long int)':
bug.cc:8:42: error: 'e' is not a constant expression
8 | void d(long e) { __builtin_offsetof(a, c[e]); }
|
Who is wrong here? gcc-10 or gcc-11?
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/95942] [11 regression] offsetof on an array: error: 'e' is not a constant expression
2020-06-27 18:22 [Bug c++/95942] New: [11 regression] offsetof on an array: error: 'e' is not a constant expression slyfox at inbox dot ru
@ 2020-06-27 18:29 ` slyfox at inbox dot ru
2020-06-27 18:34 ` mpolacek at gcc dot gnu.org
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: slyfox at inbox dot ru @ 2020-06-27 18:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95942
--- Comment #1 from Sergei Trofimovich <slyfox at inbox dot ru> ---
Original code looks is at
https://github.com/dolphin-emu/dolphin/blob/2e8d1dd1dbcca7095e9d842f1df037cbe76868e4/Source/Core/Core/DSP/Jit/x64/DSPEmitter.cpp#L476:
"""
...
Gen::OpArg DSPEmitter::M_SDSP_r_st(size_t index)
{
return MDisp(R15, static_cast<int>(offsetof(SDSP, r.st[index])));
}
...
"""
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/95942] [11 regression] offsetof on an array: error: 'e' is not a constant expression
2020-06-27 18:22 [Bug c++/95942] New: [11 regression] offsetof on an array: error: 'e' is not a constant expression slyfox at inbox dot ru
2020-06-27 18:29 ` [Bug c++/95942] " slyfox at inbox dot ru
@ 2020-06-27 18:34 ` mpolacek at gcc dot gnu.org
2020-06-29 10:37 ` rguenth at gcc dot gnu.org
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2020-06-27 18:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95942
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Changed in r11-557-gbeb019d346b903c16b9fd349937de444b6a8b6c0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/95942] [11 regression] offsetof on an array: error: 'e' is not a constant expression
2020-06-27 18:22 [Bug c++/95942] New: [11 regression] offsetof on an array: error: 'e' is not a constant expression slyfox at inbox dot ru
2020-06-27 18:29 ` [Bug c++/95942] " slyfox at inbox dot ru
2020-06-27 18:34 ` mpolacek at gcc dot gnu.org
@ 2020-06-29 10:37 ` rguenth at gcc dot gnu.org
2020-07-15 20:26 ` ppalka at gcc dot gnu.org
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-06-29 10:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95942
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |rejects-valid
Target Milestone|--- |11.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/95942] [11 regression] offsetof on an array: error: 'e' is not a constant expression
2020-06-27 18:22 [Bug c++/95942] New: [11 regression] offsetof on an array: error: 'e' is not a constant expression slyfox at inbox dot ru
` (2 preceding siblings ...)
2020-06-29 10:37 ` rguenth at gcc dot gnu.org
@ 2020-07-15 20:26 ` ppalka at gcc dot gnu.org
2020-07-15 20:56 ` slyfox at inbox dot ru
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: ppalka at gcc dot gnu.org @ 2020-07-15 20:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95942
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2020-07-15
Ever confirmed|0 |1
CC| |ppalka at gcc dot gnu.org
Status|UNCONFIRMED |NEW
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/95942] [11 regression] offsetof on an array: error: 'e' is not a constant expression
2020-06-27 18:22 [Bug c++/95942] New: [11 regression] offsetof on an array: error: 'e' is not a constant expression slyfox at inbox dot ru
` (3 preceding siblings ...)
2020-07-15 20:26 ` ppalka at gcc dot gnu.org
@ 2020-07-15 20:56 ` slyfox at inbox dot ru
2020-07-15 21:09 ` jakub at gcc dot gnu.org
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: slyfox at inbox dot ru @ 2020-07-15 20:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95942
--- Comment #3 from Sergei Trofimovich <slyfox at inbox dot ru> ---
Another example is edb-debugger project
https://github.com/eteran/edb-debugger/blob/070d0196227a58ce2ba15c695944ba16ce66c080/plugins/DebuggerCore/unix/linux/arch/x86-generic/PlatformThread.cpp#L331:
long PlatformThread::setDebugRegister(std::size_t n, unsigned long value) {
return ptrace(PTRACE_POKEUSER, tid_, offsetof(struct user,
u_debugreg[n]), value);
}
Fails build on gcc-11 as:
edb-debugger/plugins/DebuggerCore/unix/linux/arch/x86-generic/PlatformThread.cpp:331:72:
error: 'n' is not a constant expression
331 | return ptrace(PTRACE_POKEUSER, tid_, offsetof(struct user,
u_debugreg[n]), value);
| ^
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/95942] [11 regression] offsetof on an array: error: 'e' is not a constant expression
2020-06-27 18:22 [Bug c++/95942] New: [11 regression] offsetof on an array: error: 'e' is not a constant expression slyfox at inbox dot ru
` (4 preceding siblings ...)
2020-07-15 20:56 ` slyfox at inbox dot ru
@ 2020-07-15 21:09 ` jakub at gcc dot gnu.org
2020-10-12 12:51 ` rguenth at gcc dot gnu.org
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-07-15 21:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95942
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
struct S { int a; int b[15]; };
int
foo (int n)
{
int m = n;
return __builtin_offsetof (S, b[m]);
}
has been rejected for years, while
struct S { int a; int b[15]; };
int
foo (int n)
{
return __builtin_offsetof (S, b[n]);
}
has been accepted.
The comment in cp/parser.c says:
/* ??? For offsetof, there is a question of what to allow here. If
offsetof is not being used in an integral constant expression context,
then we *could* get the right answer by computing the value at runtime.
If we are in an integral constant expression context, then we might
could accept any constant expression; hard to say without analysis.
Rather than open the barn door too wide right away, allow only integer
constant expressions here. */
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/95942] [11 regression] offsetof on an array: error: 'e' is not a constant expression
2020-06-27 18:22 [Bug c++/95942] New: [11 regression] offsetof on an array: error: 'e' is not a constant expression slyfox at inbox dot ru
` (5 preceding siblings ...)
2020-07-15 21:09 ` jakub at gcc dot gnu.org
@ 2020-10-12 12:51 ` rguenth at gcc dot gnu.org
2020-10-15 16:45 ` jason at gcc dot gnu.org
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-10-12 12:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95942
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Version|10.1.0 |11.0
Priority|P3 |P1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/95942] [11 regression] offsetof on an array: error: 'e' is not a constant expression
2020-06-27 18:22 [Bug c++/95942] New: [11 regression] offsetof on an array: error: 'e' is not a constant expression slyfox at inbox dot ru
` (6 preceding siblings ...)
2020-10-12 12:51 ` rguenth at gcc dot gnu.org
@ 2020-10-15 16:45 ` jason at gcc dot gnu.org
2020-10-15 21:40 ` slyfox at gcc dot gnu.org
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: jason at gcc dot gnu.org @ 2020-10-15 16:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95942
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|NEW |RESOLVED
--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> ---
C11 says,
....and
offsetof(type, member-designator)
which expands to an integer constant expression that has type size_t, the value
of which is the offset in bytes, to the structure member (designated by
member-designator), from the beginning of its structure (designated by type).
The type and member designator shall be such that given
static type t;
then the expression &(t.member-designator) evaluates to an address constant.
(If the specified member is a bit-field, the behavior is undefined.)
And __builtin_offsetof is only documented to be usable as an implementation of
the offsetof macro.
Since e is not constant, the expression above is not an address constant, so
the offsetof expression is ill-formed. The change mentioned in comment #2
fixed this and various related issues with wrongly treating parameters as
sufficiently constant.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/95942] [11 regression] offsetof on an array: error: 'e' is not a constant expression
2020-06-27 18:22 [Bug c++/95942] New: [11 regression] offsetof on an array: error: 'e' is not a constant expression slyfox at inbox dot ru
` (7 preceding siblings ...)
2020-10-15 16:45 ` jason at gcc dot gnu.org
@ 2020-10-15 21:40 ` slyfox at gcc dot gnu.org
2021-04-27 19:39 ` jakub at gcc dot gnu.org
2024-02-07 15:06 ` pinskia at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: slyfox at gcc dot gnu.org @ 2020-10-15 21:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95942
Sergei Trofimovich <slyfox at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |slyfox at gcc dot gnu.org
--- Comment #6 from Sergei Trofimovich <slyfox at gcc dot gnu.org> ---
Thank you! I'll report the bugs to affected upstreams.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/95942] [11 regression] offsetof on an array: error: 'e' is not a constant expression
2020-06-27 18:22 [Bug c++/95942] New: [11 regression] offsetof on an array: error: 'e' is not a constant expression slyfox at inbox dot ru
` (8 preceding siblings ...)
2020-10-15 21:40 ` slyfox at gcc dot gnu.org
@ 2021-04-27 19:39 ` jakub at gcc dot gnu.org
2024-02-07 15:06 ` pinskia at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-04-27 19:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95942
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |davem at devkitpro dot org
--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
*** Bug 100296 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug c++/95942] [11 regression] offsetof on an array: error: 'e' is not a constant expression
2020-06-27 18:22 [Bug c++/95942] New: [11 regression] offsetof on an array: error: 'e' is not a constant expression slyfox at inbox dot ru
` (9 preceding siblings ...)
2021-04-27 19:39 ` jakub at gcc dot gnu.org
@ 2024-02-07 15:06 ` pinskia at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-07 15:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95942
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jlame646 at gmail dot com
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 113804 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2024-02-07 15:06 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-27 18:22 [Bug c++/95942] New: [11 regression] offsetof on an array: error: 'e' is not a constant expression slyfox at inbox dot ru
2020-06-27 18:29 ` [Bug c++/95942] " slyfox at inbox dot ru
2020-06-27 18:34 ` mpolacek at gcc dot gnu.org
2020-06-29 10:37 ` rguenth at gcc dot gnu.org
2020-07-15 20:26 ` ppalka at gcc dot gnu.org
2020-07-15 20:56 ` slyfox at inbox dot ru
2020-07-15 21:09 ` jakub at gcc dot gnu.org
2020-10-12 12:51 ` rguenth at gcc dot gnu.org
2020-10-15 16:45 ` jason at gcc dot gnu.org
2020-10-15 21:40 ` slyfox at gcc dot gnu.org
2021-04-27 19:39 ` jakub at gcc dot gnu.org
2024-02-07 15:06 ` 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).