[cfe-commits] r157722 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaChecking.cpp test/SemaCXX/warn-memset-bad-sizeof-fixit.cpp test/SemaCXX/warn-memset-bad-sizeof.cpp
Anna Zaks
ganna at apple.com
Wed May 30 16:14:52 PDT 2012
Author: zaks
Date: Wed May 30 18:14:52 2012
New Revision: 157722
URL: http://llvm.org/viewvc/llvm-project?rev=157722&view=rev
Log:
Change wording of 'memcpy' type mismatch warning and remove fixit.
As per comments following r157659.
Removed:
cfe/trunk/test/SemaCXX/warn-memset-bad-sizeof-fixit.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaCXX/warn-memset-bad-sizeof.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=157722&r1=157721&r2=157722&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed May 30 18:14:52 2012
@@ -335,10 +335,14 @@
def note_bad_memaccess_silence : Note<
"explicitly cast the pointer to silence this warning">;
def warn_sizeof_pointer_expr_memaccess : Warning<
- "argument to 'sizeof' in '%0' call is the same expression as the "
- "%select{destination|source}1; did you mean to "
- "%select{dereference it|remove the addressof|provide an explicit length}2?">,
+ "'%0' call operates on objects of type %1 while the size is based on a "
+ "different type %2">,
InGroup<DiagGroup<"sizeof-pointer-memaccess">>;
+def warn_sizeof_pointer_expr_memaccess_note : Note<
+ "did you mean to %select{dereference the argument to 'sizeof' (and multiply "
+ "it by the number of elements)|remove the addressof in the argument to "
+ "'sizeof' (and multiply it by the number of elements)|provide an explicit "
+ "length}0?">;
def warn_sizeof_pointer_type_memaccess : Warning<
"argument to 'sizeof' in %0 call is the same pointer type %1 as the "
"%select{destination|source}2; expected %3 or an explicit length">,
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=157722&r1=157721&r2=157722&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed May 30 18:14:52 2012
@@ -2755,24 +2755,14 @@
// TODO: For strncpy() and friends, this could suggest sizeof(dst)
// over sizeof(src) as well.
unsigned ActionIdx = 0; // Default is to suggest dereferencing.
- FixItHint Fixit = FixItHint(); // Default hint.
StringRef ReadableName = FnName->getName();
- if (isa<DeclRefExpr>(SizeOfArg))
- Fixit = FixItHint::CreateInsertion(SizeOfArg->getLocStart(), "*");
-
if (const UnaryOperator *UnaryOp = dyn_cast<UnaryOperator>(Dest))
- if (UnaryOp->getOpcode() == UO_AddrOf) {
- Fixit = FixItHint::CreateRemoval(
- CharSourceRange::getTokenRange(SizeOfArg->getLocStart(),
- SizeOfArg->getLocStart()));
+ if (UnaryOp->getOpcode() == UO_AddrOf)
ActionIdx = 1; // If its an address-of operator, just remove it.
- }
if (Context.getTypeSize(PointeeTy) == Context.getCharWidth())
ActionIdx = 2; // If the pointee's size is sizeof(char),
// suggest an explicit length.
- unsigned DestSrcSelect =
- (BId == Builtin::BIstrndup ? 1 : ArgIdx);
// If the function is defined as a builtin macro, do not show macro
// expansion.
@@ -2790,14 +2780,18 @@
SM.getSpellingLoc(SSR.getEnd()));
}
- DiagRuntimeBehavior(SL, Dest,
+ DiagRuntimeBehavior(SL, SizeOfArg,
PDiag(diag::warn_sizeof_pointer_expr_memaccess)
<< ReadableName
- << DestSrcSelect
- << ActionIdx
+ << PointeeTy
+ << DestTy
<< DSR
- << SSR
- << Fixit);
+ << SSR);
+ DiagRuntimeBehavior(SL, SizeOfArg,
+ PDiag(diag::warn_sizeof_pointer_expr_memaccess_note)
+ << ActionIdx
+ << SSR);
+
break;
}
}
Removed: cfe/trunk/test/SemaCXX/warn-memset-bad-sizeof-fixit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-memset-bad-sizeof-fixit.cpp?rev=157721&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-memset-bad-sizeof-fixit.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-memset-bad-sizeof-fixit.cpp (removed)
@@ -1,24 +0,0 @@
-// RUN: cp %s %t
-// RUN: not %clang_cc1 -fixit -Werror -x c++ -std=c++98 %t
-// RUN: %clang_cc1 -fsyntax-only -Werror -x c++ -std=c++98 %t
-// RUN: cp %s %t
-// RUN: not %clang_cc1 -DUSE_BUILTINS -fixit -Werror -x c++ -std=c++98 %t
-// RUN: %clang_cc1 -DUSE_BUILTINS -fsyntax-only -Werror -x c++ -std=c++98 %t
-
-extern "C" void *memcpy(void *s1, const void *s2, unsigned n);
-
-#ifdef USE_BUILTINS
-# define BUILTIN(f) __builtin_ ## f
-#else
-# define BUILTIN(f) f
-#endif
-
-#define memcpy BUILTIN(memcpy)
-
-int testFixits(int *to, int *from) {
- memcpy(to, from, sizeof(to)); // \
- // expected-warning {{argument to 'sizeof' in 'memcpy' call is the same expression as the destination; did you mean to dereference it?}}
- memcpy(0, &from, sizeof(&from)); // \
- // expected-warning {{argument to 'sizeof' in 'memcpy' call is the same expression as the source; did you mean to remove the addressof?}}
- return 0;
-}
Modified: cfe/trunk/test/SemaCXX/warn-memset-bad-sizeof.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-memset-bad-sizeof.cpp?rev=157722&r1=157721&r2=157722&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-memset-bad-sizeof.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-memset-bad-sizeof.cpp Wed May 30 18:14:52 2012
@@ -35,27 +35,27 @@
/* Should warn */
memset(&s, 0, sizeof(&s)); // \
- // expected-warning {{argument to 'sizeof' in 'memset' call is the same expression as the destination}}
+ // expected-warning {{'memset' call operates on objects of type 'S' while the size is based on a different type 'S *'}} expected-note{{did you mean to remove the addressof in the argument to 'sizeof' (and multiply it by the number of elements)?}}
memset(ps, 0, sizeof(ps)); // \
- // expected-warning {{argument to 'sizeof' in 'memset' call is the same expression as the destination}}
+ // expected-warning {{'memset' call operates on objects of type 'S' while the size is based on a different type 'S *'}} expected-note{{did you mean to dereference the argument to 'sizeof' (and multiply it by the number of elements)?}}
memset(ps2, 0, sizeof(ps2)); // \
- // expected-warning {{argument to 'sizeof' in 'memset' call is the same expression as the destination}}
+ // expected-warning {{'memset' call operates on objects of type 'S' while the size is based on a different type 'PS' (aka 'S *')}} expected-note{{did you mean to dereference the argument to 'sizeof' (and multiply it by the number of elements)?}}
memset(ps2, 0, sizeof(typeof(ps2))); // \
// expected-warning {{argument to 'sizeof' in 'memset' call is the same pointer type}}
memset(ps2, 0, sizeof(PS)); // \
// expected-warning {{argument to 'sizeof' in 'memset' call is the same pointer type}}
memset(heap_buffer, 0, sizeof(heap_buffer)); // \
- // expected-warning {{argument to 'sizeof' in 'memset' call is the same expression as the destination}}
+ // expected-warning {{'memset' call operates on objects of type 'char' while the size is based on a different type 'char *'}} expected-note{{did you mean to provide an explicit length?}}
memcpy(&s, 0, sizeof(&s)); // \
- // expected-warning {{argument to 'sizeof' in 'memcpy' call is the same expression as the destination}}
+ // expected-warning {{'memcpy' call operates on objects of type 'S' while the size is based on a different type 'S *'}} expected-note{{did you mean to remove the addressof in the argument to 'sizeof' (and multiply it by the number of elements)?}}
memcpy(0, &s, sizeof(&s)); // \
- // expected-warning {{argument to 'sizeof' in 'memcpy' call is the same expression as the source}}
+ // expected-warning {{'memcpy' call operates on objects of type 'S' while the size is based on a different type 'S *'}} expected-note{{did you mean to remove the addressof in the argument to 'sizeof' (and multiply it by the number of elements)?}}
memmove(ps, 0, sizeof(ps)); // \
- // expected-warning {{argument to 'sizeof' in 'memmove' call is the same expression as the destination}}
+ // expected-warning {{'memmove' call operates on objects of type 'S' while the size is based on a different type 'S *'}} expected-note{{did you mean to dereference the argument to 'sizeof' (and multiply it by the number of elements)?}}
memcmp(ps, 0, sizeof(ps)); // \
- // expected-warning {{argument to 'sizeof' in 'memcmp' call is the same expression as the destination}}
+ // expected-warning {{'memcmp' call operates on objects of type 'S' while the size is based on a different type 'S *'}} expected-note{{did you mean to dereference the argument to 'sizeof' (and multiply it by the number of elements)?}}
/* Shouldn't warn */
memset((void*)&s, 0, sizeof(&s));
@@ -132,14 +132,14 @@
const char* BAR = "<- this, too";
strncmp(FOO, BAR, sizeof(FOO)); // \
- // expected-warning {{argument to 'sizeof' in 'strncmp' call is the same expression as the destination}}
+ // expected-warning {{'strncmp' call operates on objects of type 'const char' while the size is based on a different type 'const char *'}} expected-note{{did you mean to provide an explicit length?}}
strncasecmp(FOO, BAR, sizeof(FOO)); // \
- // expected-warning {{argument to 'sizeof' in 'strncasecmp' call is the same expression as the destination}}
+ // expected-warning {{'strncasecmp' call operates on objects of type 'const char' while the size is based on a different type 'const char *'}} expected-note{{did you mean to provide an explicit length?}}
char buff[80];
strncpy(buff, BAR, sizeof(BAR)); // \
- // expected-warning {{argument to 'sizeof' in 'strncpy' call is the same expression as the source}}
+ // expected-warning {{'strncpy' call operates on objects of type 'const char' while the size is based on a different type 'const char *'}} expected-note{{did you mean to provide an explicit length?}}
strndup(FOO, sizeof(FOO)); // \
- // expected-warning {{argument to 'sizeof' in 'strndup' call is the same expression as the source}}
+ // expected-warning {{'strndup' call operates on objects of type 'const char' while the size is based on a different type 'const char *'}} expected-note{{did you mean to provide an explicit length?}}
}
More information about the cfe-commits
mailing list