Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

Ticket #296 (closed defect: invalid)

Opened 10 years ago

Last modified 10 years ago

Bad codegen with -singleobj and optimization

Reported by: Deewiant Assigned to: lindquist
Priority: major Milestone: Beta
Component: backend Version: hg tip
Keywords: Cc:

Description

The following code behaves differently with -singleobj and an optimization level of -O2 or greater.

import tango.time.Time;
import tango.net.Socket;

void main() {
	auto ss = new SocketSet(1);
	auto sock = new Socket(AddressFamily.INET, SocketType.STREAM, ProtocolType.TCP);
	sock.listen(1);
	ss.add(sock);
	Socket.select(ss, null, null, TimeSpan.zero);
}

What should happen is it creates a socket, puts it in listening mode, and then checks if anybody's connected to it, aborting immediately if nobody has. Since the socket hasn't been bound to an address and port, nobody will have connected and the code should terminate.

Indeed, this is what typically happens:

$ strace -e trace=select ./arst
select(4, [3], NULL, NULL, {0, 0})      = 0 (Timeout)

However, if compiled against all relevant Tango modules with -singleobj -O2, the following occurs instead:

$ ldc -ofarst -singleobj arst.d ldc/bitmanip.d tango/stdc/posix/signal.d tango/stdc/posix/sys/select.d tango/stdc/posix/sys/stat.d tango/stdc/posix/sys/time.d tango/stdc/posix/sys/types.d tango/stdc/posix/time.d tango/stdc/posix/unistd.d tango/stdc/signal.d tango/stdc/stddef.d tango/stdc/stdint.d tango/net/Socket.d tango/stdc/string.d tango/stdc/config.d tango/stdc/time.d tango/stdc/errno.d tango/sys/Common.d tango/stdc/inttypes.d tango/sys/linux/epoll.d tango/stdc/posix/config.d tango/sys/linux/linux.d tango/stdc/posix/dlfcn.d tango/time/Time.d tango/stdc/posix/fcntl.d tango/stdc/posix/inttypes.d tango/stdc/posix/poll.d tango/stdc/posix/pwd.d -O2
$ strace -e trace=select ./arst
select(4, [3], NULL, NULL, {0, 139967249051584}

Uh-oh! Our timeout changed from 0 to some very large number (varies between runs; something random from memory?), which means the program is going to hang for quite a while, waiting for a connection that'll never come.

This happens on x86-64 with LDC r1348 (LLVM r71553) and Tango 0.99.8.

Change History

05/15/09 14:35:25 changed by Deewiant

  • summary changed from Bad codegen with -singleobj and -O2 or greater to Bad codegen with -singleobj and optimization.

Actually, -O1 causes a change as well, it's just more minor:

$ strace -e trace=select ./arst
select(4, [3], NULL, NULL, {0, 1})      = 0 (Timeout)

1 instead of 0 microseconds is hardly noticeable, but still incorrect.

05/15/09 15:37:54 changed by Deewiant

  • status changed from new to closed.
  • resolution set to invalid.

This is not a bug in LDC: it's Tango bug 1652.

Copyright © 2008, LDC Development Team.