diff options
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 6 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CGExprScalar.cpp | 3 | ||||
| -rw-r--r-- | clang/test/CodeGenCXX/__null.cpp | 9 | ||||
| -rw-r--r-- | clang/test/SemaCXX/__null.cpp | 3 |
4 files changed, 21 insertions, 0 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 11f07fb1166..db9536633be 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/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/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index a5d5bc22af0..71f9f92f9c4 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/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/clang/test/CodeGenCXX/__null.cpp b/clang/test/CodeGenCXX/__null.cpp new file mode 100644 index 00000000000..29416ced023 --- /dev/null +++ b/clang/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/clang/test/SemaCXX/__null.cpp b/clang/test/SemaCXX/__null.cpp index 3d78e2e8db7..798e0aa99d1 100644 --- a/clang/test/SemaCXX/__null.cpp +++ b/clang/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]; } |

