Is this a compiler aliasing bug?

Chris Katko ckatko at gmail.com
Fri Sep 17 09:44:53 UTC 2021


I'm debugging some code I wrote back in 2017 and a bounding box 
collision detection kept giving spurious answers till I resorted 
to assuming nothing and dumped every variable and alias.

I kept getting results like it was checking against itself, and 
of course, that would result in finding a collision. So I threw 
an assert in to check if it was identical objects (as in an error 
outside this function), and it didn't fire off. It appears 
(unless my eyes are deceiving me?) that variable aliases 
themselves are broken.

$ dmd --version
DMD64 D Compiler v2.098.0-beta.2

code:

```d
class drawable_object_t obj;

bool is_colliding_with(drawable_object_t obj) //was a class member
	{
	assert(this != obj);  //does not fire off

	alias x1 = x;
	alias y1 = y;
	alias w1 = w;
	alias h1 = h;
		
	alias x2 = obj.x;
	alias y2 = obj.y;
	alias w2 = obj.w;
	alias h2 = obj.h;
		
	writeln("x1: ", x1, " y1: ", y1, " w1: ", w1, " h1: ", h1);
	writeln("x2: ", x2, " y2: ", y2, " w2: ", w2, " h2: ", h2);

	writeln("x1: ", x, " y1: ", y, " w1: ", w, " h1: ", h);
	writeln("x2: ", obj.x, " y2: ", obj.y, " w2: ", obj.w, " h2: ", 
obj.h);
         }
/*
output:

x1: 50 y1: 81 w1: 5 h1: 6
x2: 50 y2: 81 w2: 5 h2: 6		<------------
x1: 50 y1: 81 w1: 5 h1: 6
x2: 200 y2: 86.54 w2: 26 h2: 16		<------------
*/
```

The arrows point to the dependency. The top two sets of numbers 
should _not_ be identical.


More information about the Digitalmars-d-learn mailing list