public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug d/95155] New: d: wrong vtable offset in virtual function call
@ 2020-05-15 21:08 ibuclaw at gdcproject dot org
2020-05-15 23:19 ` [Bug d/95155] " ibuclaw at gdcproject dot org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: ibuclaw at gdcproject dot org @ 2020-05-15 21:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95155
Bug ID: 95155
Summary: d: wrong vtable offset in virtual function call
Product: gcc
Version: 9.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: d
Assignee: ibuclaw at gdcproject dot org
Reporter: ibuclaw at gdcproject dot org
Target Milestone: ---
Seen when compiling self-hosted D compiler.
release/gcc-9 compiles:
isBaseOf (struct TypeClass * const this, struct Type * t, int * poffset)
{
if (t != 0B && t->ty == 7)
{
{
struct ClassDeclaration * cd;
cd = ((struct TypeClass *) t)->sym;
if (MEM[(bool (*<T1704>) (struct ClassDeclaration *, struct
ClassDeclaration *, int *))this->sym->__vptr + 704B] (this->sym, cd, poffset))
{
return <retval> = 1;
}
}
}
return <retval> = 0;
}
release/gcc-10 compiles:
isBaseOf (struct TypeClass * const this, struct Type * t, int * poffset)
{
if (t != 0B && t->ty == 7)
{
{
struct ClassDeclaration * cd;
cd = ((struct TypeClass *) t)->sym;
if (MEM[(bool (*<T171b>) (struct ClassDeclaration *, struct
ClassDeclaration *, int *))this->sym->__vptr + 736B] (this->sym, cd, poffset))
{
return <retval> = 1;
}
}
}
return <retval> = 0;
}
Applied all changes to gcc/d to the gcc-9 branch, and the problem gets
resolved, so will have to comb through the diff to find out what missing change
is causing gdc-9 to miscompile.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug d/95155] d: wrong vtable offset in virtual function call
2020-05-15 21:08 [Bug d/95155] New: d: wrong vtable offset in virtual function call ibuclaw at gdcproject dot org
@ 2020-05-15 23:19 ` ibuclaw at gdcproject dot org
2020-05-16 22:21 ` cvs-commit at gcc dot gnu.org
2020-05-16 22:28 ` ibuclaw at gdcproject dot org
2 siblings, 0 replies; 4+ messages in thread
From: ibuclaw at gdcproject dot org @ 2020-05-15 23:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95155
--- Comment #1 from Iain Buclaw <ibuclaw at gdcproject dot org> ---
Looks like fix was in r10-7280, taken from the upstream backport in
https://github.com/dlang/dmd/pull/10913
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug d/95155] d: wrong vtable offset in virtual function call
2020-05-15 21:08 [Bug d/95155] New: d: wrong vtable offset in virtual function call ibuclaw at gdcproject dot org
2020-05-15 23:19 ` [Bug d/95155] " ibuclaw at gdcproject dot org
@ 2020-05-16 22:21 ` cvs-commit at gcc dot gnu.org
2020-05-16 22:28 ` ibuclaw at gdcproject dot org
2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-05-16 22:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95155
--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Iain Buclaw
<ibuclaw@gcc.gnu.org>:
https://gcc.gnu.org/g:7d505b0ed8565b8c120ddd2b0b4630c93eecdec5
commit r9-8599-g7d505b0ed8565b8c120ddd2b0b4630c93eecdec5
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date: Sat May 16 23:33:15 2020 +0200
d: Fix wrong vtable offset in virtual function call
The Semantic (pass 1) analysis for classes is handled by
ClassDeclaration::semantic. For a given class, this method may be ran
multiple times in order to resolve forward references. The method
incrementally tries to resolve the types referred to by the members of
the class.
The subsequent calls to this method are short-circuited if the class
members have been fully analyzed. For this the code tests that it is
not the first/main call to the method (semanticRun == PASS.init else
branch), scx is not set, and that the this->symtab is already set. If
all these conditions are met, the method returns. But before returning,
the method was setting this->semanticRun to PASSsemanticdone. It should
not set semanticRun since the class has not been fully analyzed yet.
The base class analysis for this class could be pending and as a result
vtable may not have been fully created.
This fake setting of semanticRun results in the semantic analyzer to
believe that the class has been fully analyzed. As exposed by the
issues in upstream, it may result in compile time errors when a derived
type class is getting analyzed and because of this fake semanticdone on
the base class, the semantic analysis construes that an overriden method
is not defined in the base class. PR95155 exposes anoter scenario where
a buggy vtable may be created and a call to a class method may result in
execution of some adhoc code.
gcc/d/ChangeLog:
PR d/95155
* dmd/dclass.c (ClassDeclaration::semantic): Don't prematurely
set done on semantic analysis.
gcc/testsuite/ChangeLog:
PR d/95155
* gdc.test/compilable/imports/pr9471a.d: New test.
* gdc.test/compilable/imports/pr9471b.d: New test.
* gdc.test/compilable/imports/pr9471c.d: New test.
* gdc.test/compilable/imports/pr9471d.d: New test.
* gdc.test/compilable/pr9471.d: New test.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug d/95155] d: wrong vtable offset in virtual function call
2020-05-15 21:08 [Bug d/95155] New: d: wrong vtable offset in virtual function call ibuclaw at gdcproject dot org
2020-05-15 23:19 ` [Bug d/95155] " ibuclaw at gdcproject dot org
2020-05-16 22:21 ` cvs-commit at gcc dot gnu.org
@ 2020-05-16 22:28 ` ibuclaw at gdcproject dot org
2 siblings, 0 replies; 4+ messages in thread
From: ibuclaw at gdcproject dot org @ 2020-05-16 22:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95155
Iain Buclaw <ibuclaw at gdcproject dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|UNCONFIRMED |RESOLVED
--- Comment #3 from Iain Buclaw <ibuclaw at gdcproject dot org> ---
Fixed.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-05-16 22:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-15 21:08 [Bug d/95155] New: d: wrong vtable offset in virtual function call ibuclaw at gdcproject dot org
2020-05-15 23:19 ` [Bug d/95155] " ibuclaw at gdcproject dot org
2020-05-16 22:21 ` cvs-commit at gcc dot gnu.org
2020-05-16 22:28 ` ibuclaw at gdcproject 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).