[cfe-commits] r130368 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/Sema/memset-invalid.c
Ted Kremenek
kremenek at apple.com
Wed Apr 27 18:38:02 PDT 2011
Author: kremenek
Date: Wed Apr 27 20:38:02 2011
New Revision: 130368
URL: http://llvm.org/viewvc/llvm-project?rev=130368&view=rev
Log:
Convert assertion in memset checking to a runtime check (because real code may provide a deviant definition of memset).
Added:
cfe/trunk/test/Sema/memset-invalid.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=130368&r1=130367&r2=130368&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Apr 27 20:38:02 2011
@@ -1804,7 +1804,12 @@
///
/// \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();
Added: cfe/trunk/test/Sema/memset-invalid.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/memset-invalid.c?rev=130368&view=auto
==============================================================================
--- cfe/trunk/test/Sema/memset-invalid.c (added)
+++ cfe/trunk/test/Sema/memset-invalid.c Wed Apr 27 20:38:02 2011
@@ -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();
+}
More information about the cfe-commits
mailing list