Re: [libcxx] r294553 - [libcxx][CMake] Support in-tree libunwind when building as part of runtimes

2019-01-21 Thread Leslie Zhai via cfe-commits


在 2019/1/21 下午5:36, Leslie Zhai 写道:

Hi Asiri,

Did you fix the issue when building libcxx and libcxxabi use LLVM's 
libunwind?


Fixed :)

Just put libcxx, libcxxabi, libunwind and compiler-rt under `runtimes` 
directory.


Leslie Zhai




http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20170206/184841.html 



I experienced the similar issue:

CMake Error at projects/libcxxabi/src/CMakeLists.txt:163 
(target_link_libraries):
  Target "unwind" of type UTILITY may not be linked into another 
target.  One

  may link only to INTERFACE, OBJECT, STATIC or SHARED libraries, or to
  executables with the ENABLE_EXPORTS property set.


CMake Error at projects/libcxxabi/src/CMakeLists.txt:197 
(target_link_libraries):
  Target "unwind" of type UTILITY may not be linked into another 
target.  One

  may link only to INTERFACE, OBJECT, STATIC or SHARED libraries, or to
  executables with the ENABLE_EXPORTS property set.

...

CMake Error at projects/libcxx/lib/CMakeLists.txt:244 
(target_link_libraries):
  Target "unwind" of type UTILITY may not be linked into another 
target.  One

  may link only to INTERFACE, OBJECT, STATIC or SHARED libraries, or to
  executables with the ENABLE_EXPORTS property set.


CMake Error at projects/libcxx/lib/CMakeLists.txt:268 
(target_link_libraries):
  Target "unwind" of type UTILITY may not be linked into another 
target.  One

  may link only to INTERFACE, OBJECT, STATIC or SHARED libraries, or to
  executables with the ENABLE_EXPORTS property set.

- 8<  8<  8<  8<  8<  8< ---

My cmake option:

$ cmake .. -DCMAKE_INSTALL_PREFIX=/opt/loong-llvm \
    -DCMAKE_BUILD_TYPE=Release \
    -DLLVM_ENABLE_ASSERTIONS=ON \
    -DCMAKE_C_COMPILER=/opt/loong-llvm/bin/clang \
    -DCMAKE_CXX_COMPILER=/opt/loong-llvm/bin/clang++ \
    -DCMAKE_C_FLAGS="-fPIC" \
    -DCMAKE_CXX_FLAGS="-std=c++11 -fPIC" \
    -DLLVM_BUILD_LLVM_DYLIB=ON \
    -DLLVM_LINK_LLVM_DYLIB=ON \
    -DLLVM_INSTALL_UTILS=ON \
    -DLLVM_ENABLE_RTTI=ON \
    -DLLVM_ENABLE_FFI=ON \
    -DLLVM_ENABLE_EH=ON \
    -DLLVM_BUILD_TESTS=OFF \
    -DLLVM_BUILD_DOCS=OFF \
    -DLLVM_ENABLE_SPHINX=OFF \
    -DLLVM_ENABLE_DOXYGEN=OFF \
    -DLLDB_DISABLE_LIBEDIT=1 \
    -DSPHINX_WARNINGS_AS_ERRORS=OFF \
    -DFFI_INCLUDE_DIR=$(pkg-config --variable=includedir libffi) \
    -DFFI_LIBRARY_DIR:PATH="$(pkg-config --variable=libdir libffi)" \
    -DLLVM_BINUTILS_INCDIR=/usr/include \
    -DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=ON \
    -DLIBUNWIND_ENABLE_SHARED=OFF \
    -DLIBCXXABI_USE_LLVM_UNWINDER=ON \
    -DLLVM_DEFAULT_TARGET_TRIPLE="mips64el-redhat-linux" \
    -DCLANG_VENDOR="Loongson"

Regards,

Leslie Zhai



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [libcxx] r294553 - [libcxx][CMake] Support in-tree libunwind when building as part of runtimes

2019-01-21 Thread Leslie Zhai via cfe-commits

Hi Asiri,

Did you fix the issue when building libcxx and libcxxabi use LLVM's 
libunwind?


http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20170206/184841.html

I experienced the similar issue:

CMake Error at projects/libcxxabi/src/CMakeLists.txt:163 
(target_link_libraries):
  Target "unwind" of type UTILITY may not be linked into another 
target.  One

  may link only to INTERFACE, OBJECT, STATIC or SHARED libraries, or to
  executables with the ENABLE_EXPORTS property set.


CMake Error at projects/libcxxabi/src/CMakeLists.txt:197 
(target_link_libraries):
  Target "unwind" of type UTILITY may not be linked into another 
target.  One

  may link only to INTERFACE, OBJECT, STATIC or SHARED libraries, or to
  executables with the ENABLE_EXPORTS property set.

...

CMake Error at projects/libcxx/lib/CMakeLists.txt:244 
(target_link_libraries):
  Target "unwind" of type UTILITY may not be linked into another 
target.  One

  may link only to INTERFACE, OBJECT, STATIC or SHARED libraries, or to
  executables with the ENABLE_EXPORTS property set.


CMake Error at projects/libcxx/lib/CMakeLists.txt:268 
(target_link_libraries):
  Target "unwind" of type UTILITY may not be linked into another 
target.  One

  may link only to INTERFACE, OBJECT, STATIC or SHARED libraries, or to
  executables with the ENABLE_EXPORTS property set.

- 8<  8<  8<  8<  8<  8< ---

My cmake option:

$ cmake .. -DCMAKE_INSTALL_PREFIX=/opt/loong-llvm \
    -DCMAKE_BUILD_TYPE=Release \
    -DLLVM_ENABLE_ASSERTIONS=ON \
    -DCMAKE_C_COMPILER=/opt/loong-llvm/bin/clang \
    -DCMAKE_CXX_COMPILER=/opt/loong-llvm/bin/clang++ \
    -DCMAKE_C_FLAGS="-fPIC" \
    -DCMAKE_CXX_FLAGS="-std=c++11 -fPIC" \
    -DLLVM_BUILD_LLVM_DYLIB=ON \
    -DLLVM_LINK_LLVM_DYLIB=ON \
    -DLLVM_INSTALL_UTILS=ON \
    -DLLVM_ENABLE_RTTI=ON \
    -DLLVM_ENABLE_FFI=ON \
    -DLLVM_ENABLE_EH=ON \
    -DLLVM_BUILD_TESTS=OFF \
    -DLLVM_BUILD_DOCS=OFF \
    -DLLVM_ENABLE_SPHINX=OFF \
    -DLLVM_ENABLE_DOXYGEN=OFF \
    -DLLDB_DISABLE_LIBEDIT=1 \
    -DSPHINX_WARNINGS_AS_ERRORS=OFF \
    -DFFI_INCLUDE_DIR=$(pkg-config --variable=includedir libffi) \
    -DFFI_LIBRARY_DIR:PATH="$(pkg-config --variable=libdir libffi)" \
    -DLLVM_BINUTILS_INCDIR=/usr/include \
    -DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=ON \
    -DLIBUNWIND_ENABLE_SHARED=OFF \
    -DLIBCXXABI_USE_LLVM_UNWINDER=ON \
    -DLLVM_DEFAULT_TARGET_TRIPLE="mips64el-redhat-linux" \
    -DCLANG_VENDOR="Loongson"

Regards,

Leslie Zhai


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r305774 - [analyzer] Teach CloneDetection about Qt Meta-Object Compiler to filter auto generated files

2017-06-19 Thread Leslie Zhai via cfe-commits
Author: xiangzhai
Date: Tue Jun 20 01:44:46 2017
New Revision: 305774

URL: http://llvm.org/viewvc/llvm-project?rev=305774&view=rev
Log:
[analyzer] Teach CloneDetection about Qt Meta-Object Compiler to filter auto 
generated files

Reviewers: v.g.vassilev, teemperor

Reviewed By: teemperor

Differential Revision: https://reviews.llvm.org/D34353

Modified:
cfe/trunk/include/clang/Analysis/CloneDetection.h
cfe/trunk/lib/Analysis/CloneDetection.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/CloneChecker.cpp

Modified: cfe/trunk/include/clang/Analysis/CloneDetection.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CloneDetection.h?rev=305774&r1=305773&r2=305774&view=diff
==
--- cfe/trunk/include/clang/Analysis/CloneDetection.h (original)
+++ cfe/trunk/include/clang/Analysis/CloneDetection.h Tue Jun 20 01:44:46 2017
@@ -321,11 +321,11 @@ struct OnlyLargestCloneConstraint {
   void constrain(std::vector &Result);
 };
 
-struct AutoGeneratedCloneConstraint {
+struct FilenamePatternConstraint {
   StringRef IgnoredFilesPattern;
   std::shared_ptr IgnoredFilesRegex;
 
-  AutoGeneratedCloneConstraint(StringRef IgnoredFilesPattern) 
+  FilenamePatternConstraint(StringRef IgnoredFilesPattern) 
   : IgnoredFilesPattern(IgnoredFilesPattern) {
 IgnoredFilesRegex = std::make_shared("^(" +
 IgnoredFilesPattern.str() + "$)");

Modified: cfe/trunk/lib/Analysis/CloneDetection.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CloneDetection.cpp?rev=305774&r1=305773&r2=305774&view=diff
==
--- cfe/trunk/lib/Analysis/CloneDetection.cpp (original)
+++ cfe/trunk/lib/Analysis/CloneDetection.cpp Tue Jun 20 01:44:46 2017
@@ -366,7 +366,7 @@ void OnlyLargestCloneConstraint::constra
   }
 }
 
-bool AutoGeneratedCloneConstraint::isAutoGenerated(const 
CloneDetector::CloneGroup &Group) {
+bool FilenamePatternConstraint::isAutoGenerated(const 
CloneDetector::CloneGroup &Group) {
   std::string Error;
   if (IgnoredFilesPattern.empty() || Group.empty() || 
   !IgnoredFilesRegex->isValid(Error))

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CloneChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CloneChecker.cpp?rev=305774&r1=305773&r2=305774&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CloneChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CloneChecker.cpp Tue Jun 20 01:44:46 
2017
@@ -82,7 +82,7 @@ void CloneChecker::checkEndOfTranslation
   std::vector AllCloneGroups;
 
   Detector.findClones(AllCloneGroups,
-  AutoGeneratedCloneConstraint(IgnoredFilesPattern),
+  FilenamePatternConstraint(IgnoredFilesPattern),
   RecursiveCloneTypeIIConstraint(),
   MinComplexityConstraint(MinComplexity),
   MinGroupSizeConstraint(2), OnlyLargestCloneConstraint());


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r305773 - [analyzer] Check NULL pointer dereference issue for memset function

2017-06-19 Thread Leslie Zhai via cfe-commits
Author: xiangzhai
Date: Tue Jun 20 01:41:06 2017
New Revision: 305773

URL: http://llvm.org/viewvc/llvm-project?rev=305773&view=rev
Log:
[analyzer] Check NULL pointer dereference issue for memset function

Reviewers: dcoughlin, zaks.anna, NoQ, danielmarjamaki

Reviewed By: NoQ, danielmarjamaki

Differential Revision: https://reviews.llvm.org/D31868

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
cfe/trunk/test/Analysis/null-deref-ps-region.c

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp?rev=305773&r1=305772&r2=305773&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp Tue Jun 20 
01:41:06 2017
@@ -120,6 +120,7 @@ public:
   void evalStdCopy(CheckerContext &C, const CallExpr *CE) const;
   void evalStdCopyBackward(CheckerContext &C, const CallExpr *CE) const;
   void evalStdCopyCommon(CheckerContext &C, const CallExpr *CE) const;
+  void evalMemset(CheckerContext &C, const CallExpr *CE) const;
 
   // Utility methods
   std::pair
@@ -1999,6 +2000,54 @@ void CStringChecker::evalStdCopyCommon(C
   C.addTransition(State);
 }
 
+void CStringChecker::evalMemset(CheckerContext &C, const CallExpr *CE) const {
+  if (CE->getNumArgs() != 3)
+return;
+
+  CurrentFunctionDescription = "memory set function";
+
+  const Expr *Mem = CE->getArg(0);
+  const Expr *Size = CE->getArg(2);
+  ProgramStateRef State = C.getState();
+
+  // See if the size argument is zero.
+  const LocationContext *LCtx = C.getLocationContext();
+  SVal SizeVal = State->getSVal(Size, LCtx);
+  QualType SizeTy = Size->getType();
+
+  ProgramStateRef StateZeroSize, StateNonZeroSize;
+  std::tie(StateZeroSize, StateNonZeroSize) =
+assumeZero(C, State, SizeVal, SizeTy);
+
+  // Get the value of the memory area.
+  SVal MemVal = State->getSVal(Mem, LCtx);
+
+  // If the size is zero, there won't be any actual memory access, so
+  // just bind the return value to the Mem buffer and return.
+  if (StateZeroSize && !StateNonZeroSize) {
+StateZeroSize = StateZeroSize->BindExpr(CE, LCtx, MemVal);
+C.addTransition(StateZeroSize);
+return;
+  }
+
+  // Ensure the memory area is not null.
+  // If it is NULL there will be a NULL pointer dereference.
+  State = checkNonNull(C, StateNonZeroSize, Mem, MemVal);
+  if (!State)
+return;
+
+  State = CheckBufferAccess(C, State, Size, Mem);
+  if (!State)
+return;
+  State = InvalidateBuffer(C, State, Mem, C.getSVal(Mem),
+   /*IsSourceBuffer*/false, Size);
+  if (!State)
+return;
+
+  State = State->BindExpr(CE, LCtx, MemVal);
+  C.addTransition(State);
+}
+
 static bool isCPPStdLibraryFunction(const FunctionDecl *FD, StringRef Name) {
   IdentifierInfo *II = FD->getIdentifier();
   if (!II)
@@ -2032,6 +2081,8 @@ bool CStringChecker::evalCall(const Call
 evalFunction =  &CStringChecker::evalMemcmp;
   else if (C.isCLibraryFunction(FDecl, "memmove"))
 evalFunction =  &CStringChecker::evalMemmove;
+  else if (C.isCLibraryFunction(FDecl, "memset"))
+evalFunction =  &CStringChecker::evalMemset;
   else if (C.isCLibraryFunction(FDecl, "strcpy"))
 evalFunction =  &CStringChecker::evalStrcpy;
   else if (C.isCLibraryFunction(FDecl, "strncpy"))

Modified: cfe/trunk/test/Analysis/null-deref-ps-region.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/null-deref-ps-region.c?rev=305773&r1=305772&r2=305773&view=diff
==
--- cfe/trunk/test/Analysis/null-deref-ps-region.c (original)
+++ cfe/trunk/test/Analysis/null-deref-ps-region.c Tue Jun 20 01:41:06 2017
@@ -1,6 +1,11 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core -std=gnu99 
-analyzer-store=region -verify %s
-// expected-no-diagnostics
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core,unix,alpha.unix 
-std=gnu99 -analyzer-store=region -verify %s
 
+#include "Inputs/system-header-simulator.h"
+
+typedef __typeof(sizeof(int)) size_t;
+void *memset(void *__s, int __c, size_t __n);
+void *malloc(size_t __size);
+void free(void *__ptr);
 
 // The store for 'a[1]' should not be removed mistakenly. SymbolicRegions may
 // also be live roots.
@@ -13,3 +18,55 @@ void f14(int *a) {
 i = *p; // no-warning
   }
 }
+
+void foo() {
+  int *x = malloc(sizeof(int));
+  memset(x, 0, sizeof(int));
+  int n = 1 / *x; // FIXME: no-warning
+  free(x);
+}
+
+void bar() {
+  int *x = malloc(sizeof(int));
+  memset(x, 0, 1);
+  int n = 1 / *x; // no-warning
+  free(x);
+}
+
+void testConcreteNull() {
+  int *x = 0;
+  memset(x, 0, 1); // expected-warning {{Null pointer argument in call to 
memory set function}}
+}
+
+void testStackArray() {
+  char buf[13];
+  memset(buf, 0, 1); // no-warnin

r305659 - [analyzer] Teach CloneDetection about Qt Meta-Object Compiler

2017-06-18 Thread Leslie Zhai via cfe-commits
Author: xiangzhai
Date: Sun Jun 18 20:55:50 2017
New Revision: 305659

URL: http://llvm.org/viewvc/llvm-project?rev=305659&view=rev
Log:
[analyzer] Teach CloneDetection about Qt Meta-Object Compiler

Reviewers: v.g.vassilev, zaks.anna, NoQ, teemperor

Reviewed By: v.g.vassilev, zaks.anna, NoQ, teemperor

Differential Revision: https://reviews.llvm.org/D31320

Added:
cfe/trunk/test/Analysis/copypaste/autogenerated_automoc.cpp
cfe/trunk/test/Analysis/copypaste/dbus_autogenerated.cpp
cfe/trunk/test/Analysis/copypaste/moc_autogenerated.cpp
cfe/trunk/test/Analysis/copypaste/not-autogenerated.cpp
cfe/trunk/test/Analysis/copypaste/ui_autogenerated.cpp
Modified:
cfe/trunk/include/clang/Analysis/CloneDetection.h
cfe/trunk/lib/Analysis/CloneDetection.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/CloneChecker.cpp

Modified: cfe/trunk/include/clang/Analysis/CloneDetection.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CloneDetection.h?rev=305659&r1=305658&r2=305659&view=diff
==
--- cfe/trunk/include/clang/Analysis/CloneDetection.h (original)
+++ cfe/trunk/include/clang/Analysis/CloneDetection.h Sun Jun 18 20:55:50 2017
@@ -17,6 +17,8 @@
 
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Regex.h"
 #include 
 
 namespace clang {
@@ -319,6 +321,26 @@ struct OnlyLargestCloneConstraint {
   void constrain(std::vector &Result);
 };
 
+struct AutoGeneratedCloneConstraint {
+  StringRef IgnoredFilesPattern;
+  std::shared_ptr IgnoredFilesRegex;
+
+  AutoGeneratedCloneConstraint(StringRef IgnoredFilesPattern) 
+  : IgnoredFilesPattern(IgnoredFilesPattern) {
+IgnoredFilesRegex = std::make_shared("^(" +
+IgnoredFilesPattern.str() + "$)");
+  }
+
+  bool isAutoGenerated(const CloneDetector::CloneGroup &Group);
+
+  void constrain(std::vector &CloneGroups) {
+CloneConstraint::filterGroups(
+CloneGroups, [this](const CloneDetector::CloneGroup &Group) {
+  return isAutoGenerated(Group);
+});
+  }
+};
+
 /// Analyzes the pattern of the referenced variables in a statement.
 class VariablePattern {
 

Modified: cfe/trunk/lib/Analysis/CloneDetection.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CloneDetection.cpp?rev=305659&r1=305658&r2=305659&view=diff
==
--- cfe/trunk/lib/Analysis/CloneDetection.cpp (original)
+++ cfe/trunk/lib/Analysis/CloneDetection.cpp Sun Jun 18 20:55:50 2017
@@ -18,9 +18,9 @@
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtVisitor.h"
 #include "clang/Lex/Lexer.h"
-#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MD5.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/Path.h"
 
 using namespace clang;
 
@@ -366,6 +366,23 @@ void OnlyLargestCloneConstraint::constra
   }
 }
 
+bool AutoGeneratedCloneConstraint::isAutoGenerated(const 
CloneDetector::CloneGroup &Group) {
+  std::string Error;
+  if (IgnoredFilesPattern.empty() || Group.empty() || 
+  !IgnoredFilesRegex->isValid(Error))
+return false;
+
+  for (const StmtSequence &S : Group) {
+const SourceManager &SM = S.getASTContext().getSourceManager();
+StringRef Filename = llvm::sys::path::filename(SM.getFilename(
+S.getContainingDecl()->getLocation()));
+if (IgnoredFilesRegex->match(Filename))
+  return true;
+  }
+
+  return false;
+}
+
 static size_t createHash(llvm::MD5 &Hash) {
   size_t HashCode;
 

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CloneChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CloneChecker.cpp?rev=305659&r1=305658&r2=305659&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CloneChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CloneChecker.cpp Sun Jun 18 20:55:50 
2017
@@ -73,12 +73,17 @@ void CloneChecker::checkEndOfTranslation
   bool ReportNormalClones = Mgr.getAnalyzerOptions().getBooleanOption(
   "ReportNormalClones", true, this);
 
+  StringRef IgnoredFilesPattern = Mgr.getAnalyzerOptions().getOptionAsString(
+  "IgnoredFilesPattern", "", this);
+
   // Let the CloneDetector create a list of clones from all the analyzed
   // statements. We don't filter for matching variable patterns at this point
   // because reportSuspiciousClones() wants to search them for errors.
   std::vector AllCloneGroups;
 
-  Detector.findClones(AllCloneGroups, RecursiveCloneTypeIIConstraint(),
+  Detector.findClones(AllCloneGroups,
+  AutoGeneratedCloneConstraint(IgnoredFilesPattern),
+  RecursiveCloneTypeIIConstraint(),
   MinComplexityConstraint(MinComplexity),
   MinGroupSizeConstraint(2), OnlyLargestCloneConstr

r301384 - [analyzer] Teach the MallocChecker about Glib API for two arguments

2017-04-25 Thread Leslie Zhai via cfe-commits
Author: xiangzhai
Date: Wed Apr 26 00:33:14 2017
New Revision: 301384

URL: http://llvm.org/viewvc/llvm-project?rev=301384&view=rev
Log:
[analyzer] Teach the MallocChecker about Glib API for two arguments

Reviewers: zaks.anna, NoQ, danielmarjamaki

Reviewed By: zaks.anna, NoQ, danielmarjamaki

Subscribers: cfe-commits, kalev, pwithnall

Differential Revision: https://reviews.llvm.org/D30771

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
cfe/trunk/test/Analysis/gmalloc.c

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp?rev=301384&r1=301383&r2=301384&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp Wed Apr 26 00:33:14 
2017
@@ -177,7 +177,10 @@ public:
 II_wcsdup(nullptr), II_win_wcsdup(nullptr), II_g_malloc(nullptr),
 II_g_malloc0(nullptr), II_g_realloc(nullptr), 
II_g_try_malloc(nullptr), 
 II_g_try_malloc0(nullptr), II_g_try_realloc(nullptr), 
-II_g_free(nullptr), II_g_memdup(nullptr) {}
+II_g_free(nullptr), II_g_memdup(nullptr), II_g_malloc_n(nullptr), 
+II_g_malloc0_n(nullptr), II_g_realloc_n(nullptr), 
+II_g_try_malloc_n(nullptr), II_g_try_malloc0_n(nullptr), 
+II_g_try_realloc_n(nullptr) {}
 
   /// In pessimistic mode, the checker assumes that it does not know which
   /// functions might free the memory.
@@ -241,7 +244,10 @@ private:
  *II_if_nameindex, *II_if_freenameindex, *II_wcsdup,
  *II_win_wcsdup, *II_g_malloc, *II_g_malloc0, 
  *II_g_realloc, *II_g_try_malloc, *II_g_try_malloc0, 
- *II_g_try_realloc, *II_g_free, *II_g_memdup;
+ *II_g_try_realloc, *II_g_free, *II_g_memdup, 
+ *II_g_malloc_n, *II_g_malloc0_n, *II_g_realloc_n, 
+ *II_g_try_malloc_n, *II_g_try_malloc0_n, 
+ *II_g_try_realloc_n;
   mutable Optional KernelZeroFlagVal;
 
   void initIdentifierInfo(ASTContext &C) const;
@@ -321,9 +327,12 @@ private:
  bool &ReleasedAllocated,
  bool ReturnsNullOnFailure = false) const;
 
-  ProgramStateRef ReallocMem(CheckerContext &C, const CallExpr *CE,
- bool FreesMemOnFailure,
- ProgramStateRef State) const;
+  ProgramStateRef ReallocMemAux(CheckerContext &C, const CallExpr *CE,
+bool FreesMemOnFailure,
+ProgramStateRef State, 
+bool SuffixWithN = false) const;
+  static SVal evalMulForBufferSize(CheckerContext &C, const Expr *Blocks,
+   const Expr *BlockBytes);
   static ProgramStateRef CallocMem(CheckerContext &C, const CallExpr *CE,
ProgramStateRef State);
 
@@ -569,6 +578,12 @@ void MallocChecker::initIdentifierInfo(A
   II_g_try_realloc = &Ctx.Idents.get("g_try_realloc");
   II_g_free = &Ctx.Idents.get("g_free");
   II_g_memdup = &Ctx.Idents.get("g_memdup");
+  II_g_malloc_n = &Ctx.Idents.get("g_malloc_n");
+  II_g_malloc0_n = &Ctx.Idents.get("g_malloc0_n");
+  II_g_realloc_n = &Ctx.Idents.get("g_realloc_n");
+  II_g_try_malloc_n = &Ctx.Idents.get("g_try_malloc_n");
+  II_g_try_malloc0_n = &Ctx.Idents.get("g_try_malloc0_n");
+  II_g_try_realloc_n = &Ctx.Idents.get("g_try_realloc_n");
 }
 
 bool MallocChecker::isMemFunction(const FunctionDecl *FD, ASTContext &C) const 
{
@@ -617,7 +632,10 @@ bool MallocChecker::isCMemFunction(const
   FunI == II_g_malloc || FunI == II_g_malloc0 || 
   FunI == II_g_realloc || FunI == II_g_try_malloc || 
   FunI == II_g_try_malloc0 || FunI == II_g_try_realloc ||
-  FunI == II_g_memdup)
+  FunI == II_g_memdup || FunI == II_g_malloc_n || 
+  FunI == II_g_malloc0_n || FunI == II_g_realloc_n || 
+  FunI == II_g_try_malloc_n || FunI == II_g_try_malloc0_n || 
+  FunI == II_g_try_realloc_n)
 return true;
 }
 
@@ -767,6 +785,17 @@ llvm::Optional MallocCh
   return None;
 }
 
+SVal MallocChecker::evalMulForBufferSize(CheckerContext &C, const Expr *Blocks,
+ const Expr *BlockBytes) {
+  SValBuilder &SB = C.getSValBuilder();
+  SVal BlocksVal = C.getSVal(Blocks);
+  SVal BlockBytesVal = C.getSVal(BlockBytes);
+  ProgramStateRef State = C.getState();
+  SVal TotalSize = SB.evalBinOp(State, BO_Mul, BlocksVal, BlockBytesVal,
+SB.getContext().getSizeType());
+  return TotalSize;
+}
+
 void MallocChecker::checkPostStmt(const CallExpr *CE, CheckerContext &C) const 
{
   if (C.wasInlined)
 return

r300818 - [AVR] Add -mmcu option to the driver

2017-04-19 Thread Leslie Zhai via cfe-commits
Author: xiangzhai
Date: Wed Apr 19 23:23:24 2017
New Revision: 300818

URL: http://llvm.org/viewvc/llvm-project?rev=300818&view=rev
Log:
[AVR] Add -mmcu option to the driver

A patch by Peter Wu!

Reviewers: jroelofs, xiangzhai

Reviewed By: jroelofs, dylanmckay, xiangzhai

Subscribers: dlj, dylanmckay, cfe-commits

Differential Revision: https://reviews.llvm.org/D29827

Added:
cfe/trunk/test/Driver/avr-mmcu.c
Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=300818&r1=300817&r2=300818&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Apr 19 23:23:24 2017
@@ -1661,6 +1661,7 @@ def mdll : Joined<["-"], "mdll">, Group<
 def municode : Joined<["-"], "municode">, Group, 
Flags<[DriverOption]>;
 def mthreads : Joined<["-"], "mthreads">, Group, 
Flags<[DriverOption]>;
 def mcpu_EQ : Joined<["-"], "mcpu=">, Group;
+def mmcu_EQ : Joined<["-"], "mmcu=">, Group;
 def mdynamic_no_pic : Joined<["-"], "mdynamic-no-pic">, Group;
 def mfix_and_continue : Flag<["-"], "mfix-and-continue">, 
Group;
 def mieee_fp : Flag<["-"], "mieee-fp">, Group;

Modified: cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp?rev=300818&r1=300817&r2=300818&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp Wed Apr 19 23:23:24 2017
@@ -261,6 +261,12 @@ std::string tools::getCPUName(const ArgL
 arm::getARMArchCPUFromArgs(Args, MArch, MCPU, FromAs);
 return arm::getARMTargetCPU(MCPU, MArch, T);
   }
+
+  case llvm::Triple::avr:
+if (const Arg *A = Args.getLastArg(options::OPT_mmcu_EQ))
+  return A->getValue();
+return "";
+
   case llvm::Triple::mips:
   case llvm::Triple::mipsel:
   case llvm::Triple::mips64:

Added: cfe/trunk/test/Driver/avr-mmcu.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/avr-mmcu.c?rev=300818&view=auto
==
--- cfe/trunk/test/Driver/avr-mmcu.c (added)
+++ cfe/trunk/test/Driver/avr-mmcu.c Wed Apr 19 23:23:24 2017
@@ -0,0 +1,5 @@
+// A test for the propagation of the -mmcu option to -cc1 and -cc1as
+
+// RUN: %clang -### -target avr -mmcu=atmega328p -save-temps %s 2>&1 | 
FileCheck %s
+// CHECK: clang{{.*}} "-cc1" {{.*}} "-target-cpu" "atmega328p"
+// CHECK: clang{{.*}} "-cc1as" {{.*}} "-target-cpu" "atmega328p"


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits