]> granicus.if.org Git - clang/commitdiff
when emitting pointer load from an lvalue or storing to an lvalue,
authorChris Lattner <sabre@nondot.org>
Sun, 10 Jul 2011 03:38:35 +0000 (03:38 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 10 Jul 2011 03:38:35 +0000 (03:38 +0000)
do an explicit bitcast to whatever ConvertType produces.  This will
go with the next patch.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134860 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExpr.cpp

index 5d7216293835161a13479214d41956a525cf4d89..c7a104ea45134d764df72f8ad518e6acadb4e214 100644 (file)
@@ -756,6 +756,10 @@ llvm::Value *CodeGenFunction::EmitFromMemory(llvm::Value *Value, QualType Ty) {
     return Builder.CreateTrunc(Value, Builder.getInt1Ty(), "tobool");
   }
 
+  // If this is a pointer r-value, make sure that it has the right scalar type.
+  if (isa<llvm::PointerType>(Value->getType()))
+    return Builder.CreateBitCast(Value, ConvertType(Ty));
+
   return Value;
 }
 
@@ -764,6 +768,14 @@ void CodeGenFunction::EmitStoreOfScalar(llvm::Value *Value, llvm::Value *Addr,
                                         QualType Ty,
                                         llvm::MDNode *TBAAInfo) {
   Value = EmitToMemory(Value, Ty);
+  
+  if (isa<llvm::PointerType>(Value->getType())) {
+    llvm::Type *EltTy =
+      cast<llvm::PointerType>(Addr->getType())->getElementType();
+    if (EltTy != Value->getType())
+      Value = Builder.CreateBitCast(Value, EltTy);
+  }
+  
   llvm::StoreInst *Store = Builder.CreateStore(Value, Addr, Volatile);
   if (Alignment)
     Store->setAlignment(Alignment);