Add codegen support for __null

llvm-svn: 61314
This commit is contained in:
Anders Carlsson 2008-12-21 22:39:40 +00:00
parent fc24b63b9a
commit 39def3adc8
4 changed files with 21 additions and 0 deletions

View File

@ -416,6 +416,12 @@ public:
return true;
}
bool VisitGNUNullExpr(const GNUNullExpr *E) {
Result = APSInt::getNullValue(getIntTypeSizeInBits(E->getType()));
Result.setIsUnsigned(E->getType()->isUnsignedIntegerType());
return true;
}
bool VisitCXXZeroInitValueExpr(const CXXZeroInitValueExpr *E) {
Result = APSInt::getNullValue(getIntTypeSizeInBits(E->getType()));
Result.setIsUnsigned(E->getType()->isUnsignedIntegerType());

View File

@ -113,6 +113,9 @@ public:
Value *VisitCXXZeroInitValueExpr(const CXXZeroInitValueExpr *E) {
return llvm::Constant::getNullValue(ConvertType(E->getType()));
}
Value *VisitGNUNullExpr(const GNUNullExpr *E) {
return llvm::Constant::getNullValue(ConvertType(E->getType()));
}
Value *VisitTypesCompatibleExpr(const TypesCompatibleExpr *E) {
return llvm::ConstantInt::get(ConvertType(E->getType()),
CGF.getContext().typesAreCompatible(

View File

@ -0,0 +1,9 @@
// RUN: clang %s -emit-llvm -o %t
int* a = __null;
int b = __null;
void f() {
int* c = __null;
int d = __null;
}

View File

@ -8,4 +8,7 @@ void f() {
// Verify statically that __null is the right size
int a[sizeof(typeof(__null)) == sizeof(void*)? 1 : -1];
// Verify that null is evaluated as 0.
int b[__null ? -1 : 1];
}