Codegen support for nullptr from C++0x.

llvm-svn: 81835
This commit is contained in:
Anders Carlsson 2009-09-15 04:39:46 +00:00
parent 2b979ef128
commit 04c3bf4fab
4 changed files with 19 additions and 1 deletions

View File

@ -383,7 +383,8 @@ APValue PointerExprEvaluator::VisitCastExpr(const CastExpr* E) {
// Check for pointer->pointer cast
if (SubExpr->getType()->isPointerType() ||
SubExpr->getType()->isObjCObjectPointerType()) {
SubExpr->getType()->isObjCObjectPointerType() ||
SubExpr->getType()->isNullPtrType()) {
APValue Result;
if (EvaluatePointer(SubExpr, Result, Info))
return Result;

View File

@ -308,6 +308,10 @@ public:
return 0;
}
Value *VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E) {
return llvm::Constant::getNullValue(ConvertType(E->getType()));
}
// Binary Operators.
Value *EmitMul(const BinOpInfo &Ops) {
if (CGF.getContext().getLangOptions().OverflowChecking

View File

@ -229,6 +229,12 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) {
return getTypeForFormat(getLLVMContext(),
Context.getFloatTypeSemantics(T));
case BuiltinType::NullPtr: {
// Model std::nullptr_t as i8*
const llvm::Type *Ty = llvm::IntegerType::get(getLLVMContext(), 8);
return llvm::PointerType::getUnqual(Ty);
}
case BuiltinType::UInt128:
case BuiltinType::Int128:
return llvm::IntegerType::get(getLLVMContext(), 128);

View File

@ -0,0 +1,7 @@
// RUN: clang-cc -std=c++0x %s -emit-llvm -o %t
int* a = nullptr;
void f() {
int* a = nullptr;
}