[cfe-commits] r114917 - in /cfe/trunk: lib/AST/Expr.cpp lib/Sema/SemaDeclAttr.cpp test/SemaObjC/nonnull.m

Fariborz Jahanian fjahanian at apple.com
Mon Sep 27 15:42:37 PDT 2010


Author: fjahanian
Date: Mon Sep 27 17:42:37 2010
New Revision: 114917

URL: http://llvm.org/viewvc/llvm-project?rev=114917&view=rev
Log:
Patch to support transparent_union arguments
passed to nonnull attributed functions. Implements radar
6857843.

Modified:
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/test/SemaObjC/nonnull.m

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=114917&r1=114916&r2=114917&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Mon Sep 27 17:42:37 2010
@@ -1862,6 +1862,13 @@
   if (getType()->isNullPtrType())
     return true;
 
+  if (const RecordType *UT = getType()->getAsUnionType())
+    if (UT && UT->getDecl()->hasAttr<TransparentUnionAttr>())
+      if (const CompoundLiteralExpr *CLE = dyn_cast<CompoundLiteralExpr>(this)){
+        const Expr *InitExpr = CLE->getInitializer();
+        if (const InitListExpr *ILE = dyn_cast<InitListExpr>(InitExpr))
+          return ILE->getInit(0)->isNullPointerConstant(Ctx, NPC);
+      }
   // This expression must be an integer type.
   if (!getType()->isIntegerType() || 
       (Ctx.getLangOptions().CPlusPlus && getType()->isEnumeralType()))

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=114917&r1=114916&r2=114917&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Mon Sep 27 17:42:37 2010
@@ -371,6 +371,19 @@
       QualType T = getFunctionOrMethodArgType(d, I);
       if (T->isAnyPointerType() || T->isBlockPointerType())
         NonNullArgs.push_back(I);
+      else if (const RecordType *UT = T->getAsUnionType()) {
+        if (UT && UT->getDecl()->hasAttr<TransparentUnionAttr>()) {
+          RecordDecl *UD = UT->getDecl();
+          for (RecordDecl::field_iterator it = UD->field_begin(),
+               itend = UD->field_end(); it != itend; ++it) {
+            T = it->getType();
+            if (T->isAnyPointerType() || T->isBlockPointerType()) {
+              NonNullArgs.push_back(I);
+              break;
+            }
+          }
+        }
+      }
     }
 
     // No pointer arguments?  The attribute in this case is

Modified: cfe/trunk/test/SemaObjC/nonnull.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/nonnull.m?rev=114917&r1=114916&r2=114917&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/nonnull.m (original)
+++ cfe/trunk/test/SemaObjC/nonnull.m Mon Sep 27 17:42:37 2010
@@ -48,3 +48,22 @@
 }
 
 void func5(int) NONNULL_ATTR; //  no warning
+
+// rdar://6857843
+struct dispatch_object_s {
+    int x;
+};
+
+typedef union {
+    long first;
+    struct dispatch_object_s *_do;
+} dispatch_object_t __attribute__((transparent_union));
+
+__attribute__((nonnull))
+void _dispatch_queue_push_list(dispatch_object_t _head); // no warning
+
+void func6(dispatch_object_t _head) {
+  _dispatch_queue_push_list(0); // expected-warning {{null passed to a callee which requires a non-null argument}}
+  _dispatch_queue_push_list(_head._do);  // no warning
+}
+





More information about the cfe-commits mailing list