]> granicus.if.org Git - clang/commitdiff
Convert assertion in memset checking to a runtime check (because real code may provid...
authorTed Kremenek <kremenek@apple.com>
Thu, 28 Apr 2011 01:38:02 +0000 (01:38 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 28 Apr 2011 01:38:02 +0000 (01:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130368 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp
test/Sema/memset-invalid.c [new file with mode: 0644]

index 7ee0eac370b9febfdb7b525b4fe63b735db0c107..f616a10524ed02eee5b120d2be436d7584fc25f9 100644 (file)
@@ -1804,7 +1804,12 @@ void Sema::CheckFormatString(const StringLiteral *FExpr,
 ///
 /// \param Call The call expression to diagnose.
 void Sema::CheckMemsetArguments(const CallExpr *Call) {
-  assert(Call->getNumArgs() == 3 && "Unexpected number of arguments to memset");
+  // It is possible to have a non-standard definition of memset.  Validate
+  // we have the proper number of arguments, and if not, abort further
+  // checking.
+  if (Call->getNumArgs() != 3)
+    return;
+
   const Expr *Dest = Call->getArg(0)->IgnoreParenImpCasts();
 
   QualType DestTy = Dest->getType();
diff --git a/test/Sema/memset-invalid.c b/test/Sema/memset-invalid.c
new file mode 100644 (file)
index 0000000..c763858
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+
+char memset(); // expected-warning {{incompatible redeclaration of library function 'memset'}} expected-note{{'memset' is a builtin with type}}
+char test() {
+  return memset();
+}