<div dir="ltr"><div><div><div><div><div>basicaa with pointers to distinct globals.<br><br>static const int x = 4;<br>static const int y = 5;<br>static const double z = 6.0;<br><br>int types_match(void)<br>{<br>  return (char*)&x == (char*)&y;<br>}<br><br>int types_differ(void)<br>{<br>  return (char*)&x == (char*)&z;<br>}<br><br></div>I'd like both tests to resolve to 'false' at the IR level, but the mixed type one doesn't at O3:<br><br>target triple = "x86_64-unknown-linux-gnu"<br>@x = internal constant i32 4, align 4<br>@z = internal constant double 6.000000e+00, align 8<br><br>define i32 @types_match() {<br>  ret i32 0<br>}<br><br>define i32 @types_differ() {<br>  ret i32 zext (i1 icmp eq (double* bitcast (i32* @x to double*), double* @z) to i32)<br>}<br><br></div>Discovered in code which uses a static variable's address as a failure indicator. Imagine a function which returns 0 for out of memory, &some_var for bad arguments, pointer to something useful otherwise. The static variable happens to have a different type because flexible array members are involved with length 0 for the failure indicator and length !=0 in general.<br><br></div>I consider this a failure in the alias analysis - would a patch be welcome, or is this intended behaviour that I've missed the point of?<br><br></div>Cheers<br><br></div>Jon<br></div>