]> granicus.if.org Git - clang/commitdiff
Add codegen support for __null
authorAnders Carlsson <andersca@mac.com>
Sun, 21 Dec 2008 22:39:40 +0000 (22:39 +0000)
committerAnders Carlsson <andersca@mac.com>
Sun, 21 Dec 2008 22:39:40 +0000 (22:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61314 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp
lib/CodeGen/CGExprScalar.cpp
test/CodeGenCXX/__null.cpp [new file with mode: 0644]
test/SemaCXX/__null.cpp

index 11f07fb1166b7c115270a072b3ef633f60d7b3d7..db9536633be3358fd611b11178bef3d438066d24 100644 (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());
index a5d5bc22af0eb6749bc3de019eef02c3a9467824..71f9f92f9c4f2696bd3da073e3b0b24a3d369228 100644 (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(
diff --git a/test/CodeGenCXX/__null.cpp b/test/CodeGenCXX/__null.cpp
new file mode 100644 (file)
index 0000000..29416ce
--- /dev/null
@@ -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;
+}
index 3d78e2e8db7d4aaf8aa0464bb51aaa5ebb212748..798e0aa99d165fd2ac317a45352b830d37968039 100644 (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];
 }