Bug 1747 – class to base interface static cast is incorrect in some cases

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2007-12-22T11:29:00Z
Last change time
2017-07-22T12:36:08Z
Keywords
bounty, pull, wrong-code
Assigned to
nobody
Creator
witold.baryluk+d
See also
https://issues.dlang.org/show_bug.cgi?id=2013

Attachments

IDFilenameSummaryContent-TypeSize
247iiir.dTest Casetext/plain735

Comments

Comment #0 by witold.baryluk+d — 2007-12-22T11:29:03Z
# make check ... /usr/ports/lang/gdc/work/build/./gcc/gdc -B/usr/ports/lang/gdc/work/build/./gcc/ -B/usr/local/i386-portbld-freebsd8.0/bin/ -B/usr/local/i386-portbld-freebsd8.0/lib/ -isystem /usr/local/i386-portbld-freebsd8.0/include -isystem /usr/local/i386-portbld-freebsd8.0/sys-include -o std/math.t.o -g -frelease -O2 -fversion=GC_Use_Alloc_MMap -fversion=GC_Use_Stack_FreeBSD -fversion=GC_Use_Data_Fixed -nostdinc -pipe -fno-release -funittest -I ../.././../gcc-4.1-20071105/libphobos -I ../.././../gcc-4.1-20071105/libphobos/internal/gc -I ./i386-portbld-freebsd8.0 -c ../.././../gcc-4.1-20071105/libphobos/std/math.d .... gmake "AR_FLAGS=rc" "CC_FOR_BUILD=cc" "CC_FOR_TARGET=/usr/ports/lang/gdc/work/build/./gcc/xgcc -B/usr/ports/lang/gdc/work/build/./gcc/ -B/usr/local/i386-portbld-freebsd8.0/bin/ -B/usr/local/i386-portbld-freebsd8.0/lib/ -isystem /usr/local/i386-portbld-freebsd8.0/include -isystem /usr/local/i386-portbld-freebsd8.0/sys-include" "CFLAGS=-O2 -O3 -fno-strict-aliasing -pipe -funroll-loops -ffast-math -march=pentium3 -march=pentium3 " "CXXFLAGS=-O3 -fno-strict-aliasing -pipe -funroll-loops -ffast-math -march=pentium3 -march=pentium3 " "CFLAGS_FOR_BUILD=-O3 -fno-strict-aliasing -pipe -funroll-loops -ffast-math -march=pentium3 -march=pentium3 " "CFLAGS_FOR_TARGET=-O2 -O3 -fno-strict-aliasing -pipe -funroll-loops -ffast-math -march=pentium3 -march=pentium3 " "INSTALL=/usr/bin/install -c -o root -g wheel" "INSTALL_DATA=install -o root -g wheel -m 444" "INSTALL_PROGRAM=install -s -o root -g wheel -m 555" "INSTALL_SCRIPT=install -o root -g wheel -m 555" "LDFLAGS=" "LIBCFLAGS=-O2 -O3 -fno-strict-aliasing -pipe -funroll-loops -ffast-math -march=pentium3 -march=pentium3 " "LIBCFLAGS_FOR_TARGET=-O2 -O3 -fno-strict-aliasing -pipe -funroll-loops -ffast-math -march=pentium3 -march=pentium3 " "MAKE=gmake" "MAKEINFO=makeinfo --split-size=5000000 " "PICFLAG=" "PICFLAG_FOR_TARGET=" "SHELL=/bin/sh" "RUNTESTFLAGS=" "exec_prefix=/usr/local" "infodir=/usr/local/info/" "libdir=/usr/local/lib" "includedir=/usr/local/include" "prefix=/usr/local" "tooldir=/usr/local/i386-portbld-freebsd8.0" "gdc_include_dir=/usr/local/include/d/4.1.3" "AR=ar" "AS=/usr/ports/lang/gdc/work/build/./gcc/as" "LD=/usr/ports/lang/gdc/work/build/./gcc/collect-ld" "RANLIB=ranlib" "NM=/usr/ports/lang/gdc/work/build/./gcc/nm" "NM_FOR_BUILD=" "NM_FOR_TARGET=nm" "DESTDIR=" "WERROR=" check-local gmake[3]: Entering directory `/usr/ports/lang/gdc/work/build/i386-portbld-freebsd8.0/libphobos' ./unittest hypot(0, 0) = 0, should be 0 hypot(0, 0) = 0, should be 0 hypot(3, 4) = 5, should be 5 hypot(-300, -400) = 500, should be 500 hypot(3.3621e-4932, 3.3621e-4932) = 0, should be 4.75473e-4932 hypot(5.94866e+4931, 5.94866e+4931) = inf, should be 8.41267e+4931 inf Error: AssertError Failure ../.././../gcc-4.1-20071105/libphobos/std/math.d(1060) ... 0.456000000000000000005637851297 toReal(".456") 0.456000000000000016431300764452 .456L Error: AssertError Failure ../.././../gcc-4.1-20071105/libphobos/std/conv.d(1069) 1.68105e-4932 toString(toReal(toString(real.min))) 3.3621e-4932 toString(real.min) Error: AssertError Failure ../.././../gcc-4.1-20071105/libphobos/std/conv.d(1077) ... /usr/ports/lang/gdc# ./work/build/gcc/gdc --version gdc (GCC) 4.1.3 20071105 (prerelease (gdc 0.24, using dmd 1.020)) # gcc -v Using built-in specs. Target: i386-undermydesk-freebsd Configured with: FreeBSD/i386 system compiler Thread model: posix gcc version 4.2.1 20070719 [FreeBSD] # uname -a FreeBSD neutrino.smp.if.uj.edu 8.0-CURRENT-200712 FreeBSD 8.0-CURRENT-200712 #0: Mon Dec 3 23:53:49 UTC 2007 [email protected]:/usr/obj/usr/src/sys/GENERIC i38 CPU: Pentium 3 Compile options: -O3 -fno-strict-aliasing -pipe -funroll-loops -ffast-math -march=pentium3
Comment #1 by witold.baryluk+d — 2007-12-22T11:35:37Z
Compiled aggainst gcc-4.1-20071105 (bsd port gdc-0.24_3).
Comment #2 by dvdfrdmn — 2008-04-19T12:13:43Z
Created attachment 247 Test Case
Comment #3 by dvdfrdmn — 2008-04-19T12:15:26Z
Comment on attachment 247 Test Case Please ignore this comment.
Comment #4 by braddr — 2011-06-04T00:13:48Z
This is a general front end bug, not a gdc specific bug. Recategorizing it. Changing the attached code slightly shows that mA is what's being invoked rather than the intended mB. class ClassX : IntyD { void mA() { g |= 1; } void mB() { g |= 2; } void mD() { g |= 4; } } void main() { ClassX x = new ClassX; assert(g == 0); IntyB b = test(x); assert(g == 0); b.mB(); printf("g = %d\n", g); assert(g == 2); }
Comment #5 by andrej.mitrovich — 2014-02-12T06:22:55Z
Simplified test-case: ----- interface IA { void mA(); } interface IB : IA { void mB(); } interface IC : IB { } interface ID : IA, IC { void mD(); } extern(C) int printf(in char* format, ...); class C : ID { void mA() { assert(0, "mA called"); } void mB() { printf("mB called\n"); } void mD() { assert(0, "mD called"); } } void main() { C c = new C; (cast(IC)c).mB(); // ok, mB called (cast(IB)c).mB(); // fail, mA called } -----
Comment #6 by k.hara.pg — 2015-07-18T12:11:06Z
(In reply to Andrej Mitrovic from comment #5) > Simplified test-case: The cast from C to IB cast needs to be a static cast (pointer offset can be determined at compile time). But it's currently done by using dynamic cast, and then, because of issue 2013, the dynamic cast result is incorrect.
Comment #7 by k.hara.pg — 2015-07-18T13:08:56Z
Comment #8 by k.hara.pg — 2015-07-18T13:45:30Z
*** Issue 10785 has been marked as a duplicate of this issue. ***
Comment #9 by github-bugzilla — 2015-07-19T08:08:38Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/5cefffdfd8dca40403674e9c12b990a17e40aaa9 fix Issue 1747 - class to base interface static cast is incorrect in some cases A class to base interface conversion is always static cast (offset is idetermined at compile time). Also refactor e2ir.c code and add comment to describe what happens there. https://github.com/D-Programming-Language/dmd/commit/f78b25c9fb00bf024cd1d6e394f696bba4f2187b Merge pull request #4819 from 9rnsr/fix1747_2013 Issue 1747 & 2013 - class/interface cast is incorrect in some cases
Comment #10 by github-bugzilla — 2017-07-22T12:36:08Z
Commits pushed to dmd-cxx at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/5cefffdfd8dca40403674e9c12b990a17e40aaa9 fix Issue 1747 - class to base interface static cast is incorrect in some cases https://github.com/dlang/dmd/commit/f78b25c9fb00bf024cd1d6e394f696bba4f2187b Merge pull request #4819 from 9rnsr/fix1747_2013