]> granicus.if.org Git - clang/commitdiff
Generate code for va_start and va_end.
authorAnders Carlsson <andersca@mac.com>
Fri, 12 Oct 2007 23:56:29 +0000 (23:56 +0000)
committerAnders Carlsson <andersca@mac.com>
Fri, 12 Oct 2007 23:56:29 +0000 (23:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42939 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 219f00c47988424c1ef424d150f01de614a9583d..3fb3faf85f96949bbc71db4e2d2aea964f20b3d6 100644 (file)
@@ -135,6 +135,7 @@ static QualType DecodeTypeFromStr(const char *&Str, ASTContext &Context) {
     break;
   case 'V':
     Type = Context.getBuiltinVaListType();
+    assert(!Type.isNull() && "builtin va list type not initialized!");
     break;
   }
   
@@ -145,6 +146,9 @@ static QualType DecodeTypeFromStr(const char *&Str, ASTContext &Context) {
       case '*':
         Type = Context.getPointerType(Type);
         break;
+      case '&':
+        Type = Context.getReferenceType(Type);
+        break;
       case 'C':
         Type = Type.getQualifiedType(QualType::Const);
         break;
index 6dbd2725216b5fd084958f225043eb4ba2b82838..2ca84e25d446882b857dc480c5f8ea0f2b1d634a 100644 (file)
@@ -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 @@ RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
     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);
index cd5c078b5c911115324e4c06e2be1938a78bcd8f..755fd56de66007f61f6fb1316f1a2942ea0a694a 100644 (file)
@@ -418,6 +418,11 @@ Value *ScalarExprEmitter::VisitImplicitCastExpr(const ImplicitCastExpr *E) {
     
     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());
index 80c75afdb8156a750582c59918faf98300113478..1457ec56060c1df63eb20c8a333b43f3494cc406 100644 (file)
@@ -46,8 +46,8 @@ const llvm::Type *CodeGenFunction::ConvertType(QualType T) {
 }
 
 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();
 }
 
 
index e7b717c59c0df058e0b49b9c0bf77eeea799287c..472df150e8b5965beabf81547e3167cdb65d4570 100644 (file)
@@ -152,7 +152,9 @@ ScopedDecl *Sema::LazilyCreateBuiltin(IdentifierInfo *II, unsigned bid,
                                       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, 
index 44b3e73fbb44e077655a1aa7f3734403a64e626b..54e67141f20179cba742de0dac71dad2e70bc937 100644 (file)
@@ -1014,7 +1014,10 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) {
   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 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) {
   } 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;
 }
index 3325d385e52ae9ec3ddf077a41eae1c2c1e8e968..62b363b66d60fd495822caa3f994d3e3d4e840ae 100644 (file)
@@ -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_fabsl, "LdLd", "ncF")
 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
index e161e65ef3ffbcab4ccf8158071bbe09343c398a..02a0f88da517fadcdd9cffbf99f74d72f0d88e82 100644 (file)
@@ -187,7 +187,7 @@ public:
   /// __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 ------------------------------------------===//