summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-04-28 01:38:02 +0000
committerTed Kremenek <kremenek@apple.com>2011-04-28 01:38:02 +0000
commitb5fabb2f9fd53621ffd6afe27b20937f36993b3d (patch)
treeff7dac5ae3abe4e740abe015585b9aeb3e890fbc
parentd25f8eb393995474f10612ec7f9099a9930bb44a (diff)
downloadbcm5719-llvm-b5fabb2f9fd53621ffd6afe27b20937f36993b3d.tar.gz
bcm5719-llvm-b5fabb2f9fd53621ffd6afe27b20937f36993b3d.zip
Convert assertion in memset checking to a runtime check (because real code may provide a deviant definition of memset).
llvm-svn: 130368
-rw-r--r--clang/lib/Sema/SemaChecking.cpp7
-rw-r--r--clang/test/Sema/memset-invalid.c6
2 files changed, 12 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 7ee0eac370b..f616a10524e 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -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/clang/test/Sema/memset-invalid.c b/clang/test/Sema/memset-invalid.c
new file mode 100644
index 00000000000..c763858e26e
--- /dev/null
+++ b/clang/test/Sema/memset-invalid.c
@@ -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();
+}
OpenPOWER on IntegriCloud