; Function Attrs: nobuiltin nounwind declare void @_ZdlPv(i8*) #6
The most important operation is at %4:
1 2 3 4 5 6
# Call new to obtain the memory address %3 = call i8* @_Znwy(i64 1) #7 # Convert the address obtained to struct.A* %4 = bitcast i8* %3 to %struct.A* # Store the converted address as the declared pointer store %struct.A* %4, %struct.A** %2, align 8
Tests show that overloading operator new within a class also causes the conversion.
; Function Attrs: nobuiltin nounwind declare void @_ZdlPv(i8*) #5
declare i8* @malloc(i64) #1
As observed, the conversion from void* to struct.A* still occurs at %4. I haven’t found an explicit requirement in the standard stating that operator new should convert void* to T*, but the standard mentions the following description:
The pointer returned shall be suitably aligned so that it can be converted to a pointer of any complete object type with a fundamental alignment requirement (3.11) and then used to access the object or array in the storage allocated (until the storage is explicitly deallocated by a call to a corresponding deallocation function).
The article is finished. If you have any questions, please comment and communicate.