@@ -157,12 +157,6 @@ namespace {
157157 if (V->getType () == DestTy)
158158 return V;
159159
160- if (V->getType ()->isPointerTy () && DestTy->isIntegerTy ())
161- return Builder.CreatePtrToInt (V, DestTy);
162-
163- if (V->getType ()->isIntegerTy () && DestTy->isPointerTy ())
164- return Builder.CreateIntToPtr (V, DestTy);
165-
166160 if (V->getType ()->isPointerTy () && DestTy->isPointerTy ()) {
167161 PointerType* SrcPtrTy = cast<PointerType>(V->getType ());
168162 PointerType* DstPtrTy = cast<PointerType>(DestTy);
@@ -171,6 +165,30 @@ namespace {
171165 return Builder.CreateAddrSpaceCast (V, DestTy);
172166 }
173167
168+ if (V->getType ()->isPointerTy ()) {
169+ if (DestTy->isIntegerTy ()) {
170+ return Builder.CreatePtrToInt (V, DestTy);
171+ }
172+ else if (DestTy->isFloatingPointTy ()) {
173+ uint32_t Size = DestTy->getPrimitiveSizeInBits ();
174+ Value* Cast = Builder.CreatePtrToInt (
175+ V, Builder.getIntNTy (Size));
176+ return Builder.CreateBitCast (Cast, DestTy);
177+ }
178+ }
179+
180+ if (DestTy->isPointerTy ()) {
181+ if (V->getType ()->isIntegerTy ()) {
182+ return Builder.CreateIntToPtr (V, DestTy);
183+ }
184+ else if (V->getType ()->isFloatingPointTy ()) {
185+ uint32_t Size = V->getType ()->getPrimitiveSizeInBits ();
186+ Value* Cast = Builder.CreateBitCast (
187+ V, Builder.getIntNTy (Size));
188+ return Builder.CreateIntToPtr (Cast, DestTy);
189+ }
190+ }
191+
174192 return Builder.CreateBitCast (V, DestTy);
175193 }
176194
0 commit comments