Generate code for va_start and va_end.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42939 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/CodeGen/CGBuiltin.cpp b/CodeGen/CGBuiltin.cpp
index 6dbd272..2ca84e2 100644
--- a/CodeGen/CGBuiltin.cpp
+++ b/CodeGen/CGBuiltin.cpp
@@ -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);
diff --git a/CodeGen/CGExprScalar.cpp b/CodeGen/CGExprScalar.cpp
index cd5c078..755fd56 100644
--- a/CodeGen/CGExprScalar.cpp
+++ b/CodeGen/CGExprScalar.cpp
@@ -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());
diff --git a/CodeGen/CodeGenFunction.cpp b/CodeGen/CodeGenFunction.cpp
index 80c75af..1457ec5 100644
--- a/CodeGen/CodeGenFunction.cpp
+++ b/CodeGen/CodeGenFunction.cpp
@@ -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();
 }