[PATCH] D49588: [CStringSyntaxChecker] Fix build bot builds != x86 archs

David CARLIER via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 20 13:45:07 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL337611: [CStringSyntaxChecker] Fix build bot builds != x86 archs (authored by devnexen, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D49588?vs=156570&id=156600#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D49588

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
  cfe/trunk/test/Analysis/cstring-syntax.c


Index: cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
===================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp
@@ -147,7 +147,7 @@
   const Expr *DstArg = CE->getArg(0);
   const Expr *LenArg = CE->getArg(2);
 
-  const auto *DstArgDecl = dyn_cast<DeclRefExpr>(DstArg->IgnoreParenCasts());
+  const auto *DstArgDecl = dyn_cast<DeclRefExpr>(DstArg->IgnoreParenImpCasts());
   const auto *LenArgDecl = dyn_cast<DeclRefExpr>(LenArg->IgnoreParenLValueCasts());
   // - size_t dstlen = sizeof(dst)
   if (LenArgDecl) {
@@ -159,14 +159,15 @@
   // - integral value
   // We try to figure out if the last argument is possibly longer
   // than the destination can possibly handle if its size can be defined
-  if (const auto *IL = dyn_cast<IntegerLiteral>(LenArg->IgnoreParenCasts())) {
+  if (const auto *IL = dyn_cast<IntegerLiteral>(LenArg->IgnoreParenImpCasts())) {
     uint64_t ILRawVal = IL->getValue().getZExtValue();
-    if (const auto *Buffer = dyn_cast<ConstantArrayType>(DstArgDecl->getType())) {
-      ASTContext &C = BR.getContext();
-      uint64_t Usize = C.getTypeSizeInChars(DstArg->getType()).getQuantity();
-      uint64_t BufferLen = BR.getContext().getTypeSize(Buffer) / Usize;
-      if (BufferLen < ILRawVal)
-        return true;
+    if (DstArgDecl) {
+      if (const auto *Buffer = dyn_cast<ConstantArrayType>(DstArgDecl->getType())) {
+        ASTContext &C = BR.getContext();
+        uint64_t BufferLen = C.getTypeSize(Buffer) / 8;
+        if (BufferLen < ILRawVal)
+          return true;
+      }
     }
   }
 
Index: cfe/trunk/test/Analysis/cstring-syntax.c
===================================================================
--- cfe/trunk/test/Analysis/cstring-syntax.c
+++ cfe/trunk/test/Analysis/cstring-syntax.c
@@ -1,4 +1,7 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=unix.cstring.BadSizeArg -analyzer-store=region -Wno-strncat-size -Wno-strlcpy-strlcat-size -Wno-sizeof-array-argument -Wno-sizeof-pointer-memaccess -verify %s
+// RUN: %clang_analyze_cc1 -triple armv7-a15-linux -analyzer-checker=unix.cstring.BadSizeArg -analyzer-store=region -Wno-strncat-size -Wno-strlcpy-strlcat-size -Wno-sizeof-array-argument -Wno-sizeof-pointer-memaccess -verify %s
+// RUN: %clang_analyze_cc1 -triple aarch64_be-none-linux-gnu -analyzer-checker=unix.cstring.BadSizeArg -analyzer-store=region -Wno-strncat-size -Wno-strlcpy-strlcat-size -Wno-sizeof-array-argument -Wno-sizeof-pointer-memaccess -verify %s
+// RUN: %clang_analyze_cc1 -triple i386-apple-darwin10 -analyzer-checker=unix.cstring.BadSizeArg -analyzer-store=region -Wno-strncat-size -Wno-strlcpy-strlcat-size -Wno-sizeof-array-argument -Wno-sizeof-pointer-memaccess -verify %s
 
 typedef __SIZE_TYPE__ size_t;
 char  *strncat(char *, const char *, size_t);
@@ -27,4 +30,5 @@
   strlcpy(dest, src, 20); // expected-warning {{The third argument is larger than the size of the input buffer. Replace with the value 'sizeof(dest)` or lower}}
   strlcpy(dest, src, badlen); // expected-warning {{The third argument is larger than the size of the input buffer. Replace with the value 'sizeof(dest)` or lower}}
   strlcpy(dest, src, ulen);
+  strlcpy(dest + 5, src, 5);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49588.156600.patch
Type: text/x-patch
Size: 3317 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180720/0903e7c6/attachment.bin>


More information about the llvm-commits mailing list