[cfe-commits] r39595 - in /cfe/cfe/trunk: CodeGen/CGExpr.cpp CodeGen/CodeGenFunction.h clang.xcodeproj/project.pbxproj include/clang/AST/Expr.h

clattner at cs.uiuc.edu clattner at cs.uiuc.edu
Wed Jul 11 09:46:03 PDT 2007


Author: clattner
Date: Wed Jul 11 11:46:03 2007
New Revision: 39595

URL: http://llvm.org/viewvc/llvm-project?rev=39595&view=rev
Log:
implement support for casts to/from pointers.

Modified:
    cfe/cfe/trunk/CodeGen/CGExpr.cpp
    cfe/cfe/trunk/CodeGen/CodeGenFunction.h
    cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
    cfe/cfe/trunk/include/clang/AST/Expr.h

Modified: cfe/cfe/trunk/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CGExpr.cpp?rev=39595&r1=39594&r2=39595&view=diff

==============================================================================
--- cfe/cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/cfe/trunk/CodeGen/CGExpr.cpp Wed Jul 11 11:46:03 2007
@@ -39,16 +39,29 @@
 /// EmitConversion - Convert the value specied by Val, whose type is ValTy, to
 /// the type specified by DstTy, following the rules of C99 6.3.
 RValue CodeGenFunction::EmitConversion(RValue Val, QualType ValTy,
-                                       QualType DstTy) {
+                                       QualType DstTy, SourceLocation Loc) {
   ValTy = ValTy.getCanonicalType();
   DstTy = DstTy.getCanonicalType();
   if (ValTy == DstTy) return Val;
   
-  if (const BuiltinType *DestBT = dyn_cast<BuiltinType>(DstTy)) {
+  if (isa<PointerType>(DstTy)) {
+    const llvm::Type *DestTy = ConvertType(DstTy, Loc);
+    
+    // The source value may be an integer, or a pointer.
+    assert(Val.isScalar() && "Can only convert from integer or pointer");
+    if (isa<llvm::PointerType>(Val.getVal()->getType()))
+      return RValue::get(Builder.CreateBitCast(Val.getVal(), DestTy, "conv"));
+    assert(ValTy->isIntegerType() && "Not ptr->ptr or int->ptr conversion?");
+    return RValue::get(Builder.CreatePtrToInt(Val.getVal(), DestTy, "conv"));
+  } else if (isa<PointerType>(ValTy)) {
+    // Must be an ptr to int cast.
+    const llvm::Type *DestTy = ConvertType(DstTy, Loc);
+    assert(isa<llvm::IntegerType>(DestTy) && "not ptr->int?");
+    return RValue::get(Builder.CreateIntToPtr(Val.getVal(), DestTy, "conv"));
+  } else if (const BuiltinType *DestBT = dyn_cast<BuiltinType>(DstTy)) {
     if (DestBT->getKind() == BuiltinType::Bool)
       return RValue::get(ConvertScalarValueToBool(Val, ValTy));
   }
-  
   assert(0 && "FIXME: Unsupported conversion!");
 }
 
@@ -261,7 +274,7 @@
   if (E->getType()->isVoidType())
     return RValue::getAggregate(0);
   
-  return EmitConversion(Src, SrcTy, E->getType());
+  return EmitConversion(Src, SrcTy, E->getType(), E->getLParenLoc());
 }
 
 //===----------------------------------------------------------------------===//
@@ -705,7 +718,8 @@
   RValue RHS = EmitExprWithUsualUnaryConversions(E->getRHS(), RHSTy);
   
   // Convert the RHS to the type of the LHS.
-  RHS = EmitConversion(RHS, RHSTy, E->getType());
+  // FIXME: I'm not thrilled about having to call getLocStart() here... :(
+  RHS = EmitConversion(RHS, RHSTy, E->getType(), E->getLocStart());
   
   // Store the value into the LHS.
   EmitStoreThroughLValue(RHS, LHS, E->getType());

Modified: cfe/cfe/trunk/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CodeGenFunction.h?rev=39595&r1=39594&r2=39595&view=diff

==============================================================================
--- cfe/cfe/trunk/CodeGen/CodeGenFunction.h (original)
+++ cfe/cfe/trunk/CodeGen/CodeGenFunction.h Wed Jul 11 11:46:03 2007
@@ -161,7 +161,8 @@
   
   /// EmitConversion - Convert the value specied by Val, whose type is ValTy, to
   /// the type specified by DstTy, following the rules of C99 6.3.
-  RValue EmitConversion(RValue Val, QualType ValTy, QualType DstTy);
+  RValue EmitConversion(RValue Val, QualType ValTy, QualType DstTy,
+                        SourceLocation Loc);
   
   /// ConvertScalarValueToBool - Convert the specified expression value to a
   /// boolean (i1) truth value.  This is equivalent to "Val == 0".

Modified: cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=39595&r1=39594&r2=39595&view=diff

==============================================================================
--- cfe/cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/cfe/trunk/clang.xcodeproj/project.pbxproj Wed Jul 11 11:46:03 2007
@@ -106,23 +106,6 @@
 		DED7D9E50A5257F6003AD0FB /* ScratchBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DED7D9E40A5257F6003AD0FB /* ScratchBuffer.cpp */; };
 /* End PBXBuildFile section */
 
-/* Begin PBXBuildStyle section */
-		84916BDA0C15E9B20080778F /* Development */ = {
-			isa = PBXBuildStyle;
-			buildSettings = {
-				COPY_PHASE_STRIP = NO;
-			};
-			name = Development;
-		};
-		84916BDB0C15E9B20080778F /* Deployment */ = {
-			isa = PBXBuildStyle;
-			buildSettings = {
-				COPY_PHASE_STRIP = YES;
-			};
-			name = Deployment;
-		};
-/* End PBXBuildStyle section */
-
 /* Begin PBXCopyFilesBuildPhase section */
 		8DD76F690486A84900D96B5E /* CopyFiles */ = {
 			isa = PBXCopyFilesBuildPhase;
@@ -186,7 +169,7 @@
 		1A30A9E80B93A4C800201A91 /* ExprCXX.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ExprCXX.h; path = clang/AST/ExprCXX.h; sourceTree = "<group>"; };
 		1A869A6E0BA2164C008DA07A /* LiteralSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LiteralSupport.h; sourceTree = "<group>"; };
 		1A869AA70BA21ABA008DA07A /* LiteralSupport.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = LiteralSupport.cpp; sourceTree = "<group>"; };
-		8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
+		8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
 		DE01DA480B12ADA300AC22CE /* PPCallbacks.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PPCallbacks.h; sourceTree = "<group>"; };
 		DE06756B0C051CFE00EBBFD8 /* ParseExprCXX.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = ParseExprCXX.cpp; path = Parse/ParseExprCXX.cpp; sourceTree = "<group>"; };
 		DE06B73D0A8307640050E87E /* LangOptions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LangOptions.h; sourceTree = "<group>"; };
@@ -564,12 +547,6 @@
 		08FB7793FE84155DC02AAC07 /* Project object */ = {
 			isa = PBXProject;
 			buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
-			buildSettings = {
-			};
-			buildStyles = (
-				84916BDA0C15E9B20080778F /* Development */,
-				84916BDB0C15E9B20080778F /* Deployment */,
-			);
 			hasScannedForEncodings = 1;
 			mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
 			projectDirPath = "";

Modified: cfe/cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Expr.h?rev=39595&r1=39594&r2=39595&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Expr.h Wed Jul 11 11:46:03 2007
@@ -412,6 +412,8 @@
   CastExpr(StmtClass SC, QualType ty, Expr *op) : 
     Expr(SC, QualType()), Ty(ty), Op(op), Loc(SourceLocation()) {}
   
+  SourceLocation getLParenLoc() const { return Loc; }
+  
   QualType getDestType() const { return Ty; }
   Expr *getSubExpr() const { return Op; }
   virtual SourceRange getSourceRange() const {





More information about the cfe-commits mailing list