summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-08-18 22:48:41 +0000
committerTed Kremenek <kremenek@apple.com>2011-08-18 22:48:41 +0000
commit18db5d4e9da599eedb864e82d92f93605651c7f3 (patch)
tree90732c28f005b79acc539c26d0abdf008729f79e /clang/lib/Sema/SemaChecking.cpp
parent96b7ad2e1793a9690b9b7917e44e08874abe4aa9 (diff)
downloadbcm5719-llvm-18db5d4e9da599eedb864e82d92f93605651c7f3.tar.gz
bcm5719-llvm-18db5d4e9da599eedb864e82d92f93605651c7f3.zip
Enhance -Wstrl-incorrect-size to not report a FIXIT for destinations that are flexible arrays or have size 1.
llvm-svn: 138004
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r--clang/lib/Sema/SemaChecking.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 882668e5151..82c97a63cdb 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2071,18 +2071,26 @@ void Sema::CheckStrlcpycatArguments(const CallExpr *Call,
// pointers if we know the actual size, like if DstArg is 'array+2'
// we could say 'sizeof(array)-2'.
const Expr *DstArg = Call->getArg(0)->IgnoreParenImpCasts();
+ QualType DstArgTy = DstArg->getType();
- if (DstArg->getType()->isArrayType()) {
- llvm::SmallString<128> sizeString;
- llvm::raw_svector_ostream OS(sizeString);
- OS << "sizeof(";
- DstArg->printPretty(OS, Context, 0, Context.PrintingPolicy);
- OS << ")";
-
- Diag(OriginalSizeArg->getLocStart(), diag::note_strlcpycat_wrong_size)
- << FixItHint::CreateReplacement(OriginalSizeArg->getSourceRange(),
- OS.str());
+ // Only handle constant-sized or VLAs, but not flexible members.
+ if (const ConstantArrayType *CAT = Context.getAsConstantArrayType(DstArgTy)) {
+ // Only issue the FIXIT for arrays of size > 1.
+ if (CAT->getSize().getSExtValue() <= 1)
+ return;
+ } else if (!DstArgTy->isVariableArrayType()) {
+ return;
}
+
+ llvm::SmallString<128> sizeString;
+ llvm::raw_svector_ostream OS(sizeString);
+ OS << "sizeof(";
+ DstArg->printPretty(OS, Context, 0, Context.PrintingPolicy);
+ OS << ")";
+
+ Diag(OriginalSizeArg->getLocStart(), diag::note_strlcpycat_wrong_size)
+ << FixItHint::CreateReplacement(OriginalSizeArg->getSourceRange(),
+ OS.str());
}
//===--- CHECK: Return Address of Stack Variable --------------------------===//
OpenPOWER on IntegriCloud