r173872 - c: When checking on validity of sizeof passed as size of

Fariborz Jahanian fjahanian at apple.com
Tue Jan 29 17:12:44 PST 2013


Author: fjahanian
Date: Tue Jan 29 19:12:44 2013
New Revision: 173872

URL: http://llvm.org/viewvc/llvm-project?rev=173872&view=rev
Log:
c: When checking on validity of sizeof passed as size of
argument to be memset, check for its type to be complete 
before calling Context.getTypeSize(PointeeTy) to prevent 
crash. // rdar://13081751.

Added:
    cfe/trunk/test/Sema/memset-invalid-1.c
Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=173872&r1=173871&r2=173872&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Jan 29 19:12:44 2013
@@ -3253,7 +3253,8 @@ void Sema::CheckMemaccessArguments(const
           if (const UnaryOperator *UnaryOp = dyn_cast<UnaryOperator>(Dest))
             if (UnaryOp->getOpcode() == UO_AddrOf)
               ActionIdx = 1; // If its an address-of operator, just remove it.
-          if (Context.getTypeSize(PointeeTy) == Context.getCharWidth())
+          if (!PointeeTy->isIncompleteType() &&
+              (Context.getTypeSize(PointeeTy) == Context.getCharWidth()))
             ActionIdx = 2; // If the pointee's size is sizeof(char),
                            // suggest an explicit length.
 

Added: cfe/trunk/test/Sema/memset-invalid-1.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/memset-invalid-1.c?rev=173872&view=auto
==============================================================================
--- cfe/trunk/test/Sema/memset-invalid-1.c (added)
+++ cfe/trunk/test/Sema/memset-invalid-1.c Tue Jan 29 19:12:44 2013
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+// rdar://13081751
+
+typedef __SIZE_TYPE__ size_t;
+void *memset(void*, int, size_t);
+
+typedef struct __incomplete *incomplete;
+
+void mt_query_for_domain(const char *domain)
+{
+	incomplete	query = 0;
+	memset(query, 0, sizeof(query)); // expected-warning {{'memset' call operates on objects of type 'struct __incomplete' while the size is based on a different type 'incomplete'}} \
+	// expected-note {{did you mean to dereference the argument to 'sizeof' (and multiply it by the number of elements)?}}
+}
+





More information about the cfe-commits mailing list