diff options
author | Anders Carlsson <andersca@mac.com> | 2008-12-21 22:39:40 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2008-12-21 22:39:40 +0000 |
commit | 3f70456b8adb0405ef2a47d51f9fc2d5937ae8ae (patch) | |
tree | 4a989498d0146c8d241641cf6633bb220a5b9eb9 | |
parent | a89d82c1c819d17042ec2db4283326a850229b21 (diff) |
Add codegen support for __null
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61314 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/AST/ExprConstant.cpp | 6 | ||||
-rw-r--r-- | lib/CodeGen/CGExprScalar.cpp | 3 | ||||
-rw-r--r-- | test/CodeGenCXX/__null.cpp | 9 | ||||
-rw-r--r-- | test/SemaCXX/__null.cpp | 3 |
4 files changed, 21 insertions, 0 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 11f07fb116..db9536633b 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -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()); diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index a5d5bc22af..71f9f92f9c 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -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( diff --git a/test/CodeGenCXX/__null.cpp b/test/CodeGenCXX/__null.cpp new file mode 100644 index 0000000000..29416ced02 --- /dev/null +++ b/test/CodeGenCXX/__null.cpp @@ -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; +} diff --git a/test/SemaCXX/__null.cpp b/test/SemaCXX/__null.cpp index 3d78e2e8db..798e0aa99d 100644 --- a/test/SemaCXX/__null.cpp +++ b/test/SemaCXX/__null.cpp @@ -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]; } |