[cfe-commits] r42939 - in /cfe/trunk: AST/Builtins.cpp CodeGen/CGBuiltin.cpp CodeGen/CGExprScalar.cpp CodeGen/CodeGenFunction.cpp Sema/SemaDecl.cpp Sema/SemaExpr.cpp include/clang/AST/Builtins.def include/clang/Basic/TargetInfo.h

Anders Carlsson andersca at mac.com
Fri Oct 12 16:56:29 PDT 2007


Author: andersca
Date: Fri Oct 12 18:56:29 2007
New Revision: 42939

URL: http://llvm.org/viewvc/llvm-project?rev=42939&view=rev
Log:
Generate code for va_start and va_end.

Modified:
    cfe/trunk/AST/Builtins.cpp
    cfe/trunk/CodeGen/CGBuiltin.cpp
    cfe/trunk/CodeGen/CGExprScalar.cpp
    cfe/trunk/CodeGen/CodeGenFunction.cpp
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/Sema/SemaExpr.cpp
    cfe/trunk/include/clang/AST/Builtins.def
    cfe/trunk/include/clang/Basic/TargetInfo.h

Modified: cfe/trunk/AST/Builtins.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Builtins.cpp?rev=42939&r1=42938&r2=42939&view=diff

==============================================================================
--- cfe/trunk/AST/Builtins.cpp (original)
+++ cfe/trunk/AST/Builtins.cpp Fri Oct 12 18:56:29 2007
@@ -135,6 +135,7 @@
     break;
   case 'V':
     Type = Context.getBuiltinVaListType();
+    assert(!Type.isNull() && "builtin va list type not initialized!");
     break;
   }
   
@@ -145,6 +146,9 @@
       case '*':
         Type = Context.getPointerType(Type);
         break;
+      case '&':
+        Type = Context.getReferenceType(Type);
+        break;
       case 'C':
         Type = Type.getQualifiedType(QualType::Const);
         break;

Modified: cfe/trunk/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGBuiltin.cpp?rev=42939&r1=42938&r2=42939&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/CodeGen/CGBuiltin.cpp Fri Oct 12 18:56:29 2007
@@ -18,6 +18,8 @@
 #include "clang/AST/Expr.h"
 #include "llvm/Constants.h"
 #include "llvm/Function.h"
+#include "llvm/Intrinsics.h"
+
 using namespace clang;
 using namespace CodeGen;
 
@@ -45,7 +47,22 @@
     std::string S(Literal->getStrData(), Literal->getByteLength());
     
     return RValue::get(CGM.GetAddrOfConstantCFString(S));
-  }      
+  }
+  case Builtin::BI__builtin_va_start:
+  case Builtin::BI__builtin_va_end: {
+    llvm::Value *ArgValue = EmitScalarExpr(E->getArg(0));
+    const llvm::Type *DestType = llvm::PointerType::get(llvm::Type::Int8Ty);
+    if (ArgValue->getType() != DestType)
+      ArgValue = Builder.CreateBitCast(ArgValue, DestType, 
+                                       ArgValue->getNameStart());
+
+    llvm::Intrinsic::ID inst = (BuiltinID == Builtin::BI__builtin_va_start) ? 
+      llvm::Intrinsic::vastart : llvm::Intrinsic::vaend;
+    llvm::Value *F = llvm::Intrinsic::getDeclaration(&CGM.getModule(), inst);
+    llvm::Value *V = Builder.CreateCall(F, ArgValue);
+
+    return RValue::get(V);
+  }
   }
       
   return RValue::get(0);

Modified: cfe/trunk/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExprScalar.cpp?rev=42939&r1=42938&r2=42939&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/CodeGen/CGExprScalar.cpp Fri Oct 12 18:56:29 2007
@@ -418,6 +418,11 @@
     
     llvm::Value *Ops[] = {Idx0, Idx0};
     return Builder.CreateGEP(V, Ops, Ops+2, "arraydecay");
+  } else if (E->getType()->isReferenceType()) {
+    assert(cast<ReferenceType>(E->getType())->getReferenceeType() == 
+           Op->getType() && "Incompatible types!");
+    
+    return EmitLValue(Op).getAddress();
   }
   
   return EmitCastExpr(Op, E->getType());

Modified: cfe/trunk/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenFunction.cpp?rev=42939&r1=42938&r2=42939&view=diff

==============================================================================
--- cfe/trunk/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenFunction.cpp Fri Oct 12 18:56:29 2007
@@ -46,8 +46,8 @@
 }
 
 bool CodeGenFunction::hasAggregateLLVMType(QualType T) {
-  return !T->isRealType() && !T->isPointerType() && !T->isVoidType() &&
-         !T->isVectorType() && !T->isFunctionType();
+  return !T->isRealType() && !T->isPointerType() && !T->isReferenceType() &&
+         !T->isVoidType() && !T->isVectorType() && !T->isFunctionType();
 }
 
 

Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=42939&r1=42938&r2=42939&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Fri Oct 12 18:56:29 2007
@@ -152,7 +152,9 @@
                                       Scope *S) {
   Builtin::ID BID = (Builtin::ID)bid;
 
-  if (BID == Builtin::BI__builtin_va_start &&
+  if ((BID == Builtin::BI__builtin_va_start ||
+       BID == Builtin::BI__builtin_va_copy ||
+       BID == Builtin::BI__builtin_va_end) &&
       Context.getBuiltinVaListType().isNull()) {
     IdentifierInfo *VaIdent = &Context.Idents.get("__builtin_va_list");
     ScopedDecl *VaDecl = LookupScopedDecl(VaIdent, Decl::IDNS_Ordinary, 

Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=42939&r1=42938&r2=42939&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Fri Oct 12 18:56:29 2007
@@ -1014,7 +1014,10 @@
   if (lhsType == rhsType) // common case, fast path...
     return Compatible;
 
-  if (lhsType->isArithmeticType() && rhsType->isArithmeticType()) {
+  if (lhsType->isReferenceType() || rhsType->isReferenceType()) {
+    if (Type::referenceTypesAreCompatible(lhsType, rhsType))
+      return Compatible;
+  } else if (lhsType->isArithmeticType() && rhsType->isArithmeticType()) {
     if (lhsType->isVectorType() || rhsType->isVectorType()) {
       if (lhsType.getCanonicalType() != rhsType.getCanonicalType())
         return Incompatible;
@@ -1036,9 +1039,6 @@
   } else if (isa<TagType>(lhsType) && isa<TagType>(rhsType)) {
     if (Type::tagTypesAreCompatible(lhsType, rhsType))
       return Compatible;
-  } else if (lhsType->isReferenceType() || rhsType->isReferenceType()) {
-    if (Type::referenceTypesAreCompatible(lhsType, rhsType))
-      return Compatible;
   }
   return Incompatible;
 }

Modified: cfe/trunk/include/clang/AST/Builtins.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Builtins.def?rev=42939&r1=42938&r2=42939&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Builtins.def (original)
+++ cfe/trunk/include/clang/AST/Builtins.def Fri Oct 12 18:56:29 2007
@@ -41,6 +41,7 @@
 //
 // Types may be postfixed with the following modifiers:
 // * -> pointer
+// & -> reference
 // C -> const
 
 // The third value provided to the macro specifies information about attributes
@@ -59,6 +60,8 @@
 BUILTIN(__builtin_constant_p, "UsUs", "nc")
 BUILTIN(__builtin_classify_type, "i.", "nc")
 BUILTIN(__builtin___CFStringMakeConstantString, "FC*cC*", "nc")
-BUILTIN(__builtin_va_start, "vV.", "nc")
+BUILTIN(__builtin_va_start, "vV&.", "nc")
+BUILTIN(__builtin_va_end, "vV&", "nc")
+BUILTIN(__builtin_va_copy, "vV&V", "nc")
 
 #undef BUILTIN

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=42939&r1=42938&r2=42939&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Fri Oct 12 18:56:29 2007
@@ -187,7 +187,7 @@
   /// __builtin_va_list, which is target-specific.
   const char *getVAListDeclaration() const {
     // FIXME: dispatch to target impl.
-    return "typedef int __builtin_va_list;";
+    return "typedef char* __builtin_va_list;";
   }
   ///===---- Some helper methods ------------------------------------------===//
 





More information about the cfe-commits mailing list