[clang-tools-extra] r304931 - [clang-tidy] When" -fno-exceptions is used", this warning is better to be suppressed.

2017-06-07 Thread Yan Wang via cfe-commits
Author: yawanng
Date: Wed Jun  7 12:41:59 2017
New Revision: 304931

URL: http://llvm.org/viewvc/llvm-project?rev=304931&view=rev
Log:
[clang-tidy]  When" -fno-exceptions is used", this warning is better to be 
suppressed.

Summary: clang-tidy is better not to issues this warning, which checks where 
the initializer for the object may throw an exception, when "-fno-exceptions" 
is used.

Reviewers: chh, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: xazax.hun

Tags: #clang-tools-extra

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

Modified:
clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp

Modified: clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp?rev=304931&r1=304930&r2=304931&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp Wed 
Jun  7 12:41:59 2017
@@ -19,7 +19,7 @@ namespace tidy {
 namespace cert {
 
 void StaticObjectExceptionCheck::registerMatchers(MatchFinder *Finder) {
-  if (!getLangOpts().CPlusPlus)
+  if ((!getLangOpts().CPlusPlus) || (!getLangOpts().CXXExceptions))
 return;
 
   // Match any static or thread_local variable declaration that has an

Modified: 
clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp?rev=304931&r1=304930&r2=304931&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp 
Wed Jun  7 12:41:59 2017
@@ -1,4 +1,9 @@
-// RUN: %check_clang_tidy %s cert-err58-cpp %t -- -- -std=c++11 -target 
x86_64-pc-linux-gnu
+// RUN: clang-tidy %s -checks="-*,cert-err58-cpp" -- -std=c++11 -target 
x86_64-pc-linux-gnu \
+// RUN:   | FileCheck %s -check-prefix=CHECK-EXCEPTIONS \
+// RUN:   -implicit-check-not="{{warning|error}}:"
+// RUN: clang-tidy %s -checks="-*,cert-err58-cpp" -- -fno-exceptions 
-std=c++11 -target x86_64-pc-linux-gnu \
+// RUN:   | FileCheck %s -allow-empty -check-prefix=CHECK-NONEXCEPTIONS \
+// RUN:   -implicit-check-not="{{warning|error}}:"
 
 struct S {
   S() noexcept(false);
@@ -52,39 +57,49 @@ UserConv_Bad some_bad_func() noexcept;
 UserConv_Good some_good_func() noexcept;
 
 S s;
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: initialization of 's' with static 
storage duration may throw an exception that cannot be caught [cert-err58-cpp]
-// CHECK-MESSAGES: 4:3: note: possibly throwing constructor declared here
+// CHECK-EXCEPTIONS: :[[@LINE-1]]:3: warning: initialization of 's' with 
static storage duration may throw an exception that cannot be caught 
[cert-err58-cpp]
+// CHECK-EXCEPTIONS: 9:3: note: possibly throwing constructor declared here
+// CHECK-NONEXCEPTIONS-NOT: warning:
 T t; // ok
 U u;
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: initialization of 'u' with static 
storage duration may throw an exception that cannot be caught
-// CHECK-MESSAGES: 12:3: note: possibly throwing constructor declared here
+// CHECK-EXCEPTIONS: :[[@LINE-1]]:3: warning: initialization of 'u' with 
static storage duration may throw an exception that cannot be caught
+// CHECK-EXCEPTIONS: 17:3: note: possibly throwing constructor declared here
+// CHECK-NONEXCEPTIONS-NOT: warning:
 V v("v");
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: initialization of 'v' with static 
storage duration may throw an exception that cannot be caught
-// CHECK-MESSAGES: 16:12: note: possibly throwing constructor declared here
+// CHECK-EXCEPTIONS: :[[@LINE-1]]:3: warning: initialization of 'v' with 
static storage duration may throw an exception that cannot be caught
+// CHECK-EXCEPTIONS: 21:12: note: possibly throwing constructor declared here
+// CHECK-NONEXCEPTIONS-NOT: warning:
 W w;
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: initialization of 'w' with static 
storage duration may throw an exception that cannot be caught
-// CHECK-MESSAGES: 24:3: note: possibly throwing constructor declared here
+// CHECK-EXCEPTIONS: :[[@LINE-1]]:3: warning: initialization of 'w' with 
static storage duration may throw an exception that cannot be caught
+// CHECK-EXCEPTIONS: 29:3: note: possibly throwing constructor declared here
+// CHECK-NONEXCEPTIONS-NOT: warning:
 X x1(S{});
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: initialization of 'x1' with static 
storage duration may throw an exception that cannot be caught
-// CHECK-MESSAGES: 4:3: note: possibly throwing constructor declared here
+// CHECK-EXCEPTIONS: :[[@LINE-1]

[clang-tools-extra] r304949 - [clang-tidy] When" -fno-exceptions is used", this warning is better to be suppressed.

2017-06-08 Thread Yan Wang via cfe-commits
Author: yawanng
Date: Wed Jun  7 17:39:20 2017
New Revision: 304949

URL: http://llvm.org/viewvc/llvm-project?rev=304949&view=rev
Log:
[clang-tidy] When" -fno-exceptions is used", this warning is better to be 
suppressed.

Summary:  "misc-noexcept-move-constructor" is better not to be issued when 
"-fno-exceptions" is set.

Reviewers: chh, alexfh, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: aaron.ballman, cfe-commits, xazax.hun

Tags: #clang-tools-extra

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

Modified:
clang-tools-extra/trunk/clang-tidy/misc/NoexceptMoveConstructorCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-noexcept-move-constructor.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/misc/NoexceptMoveConstructorCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/NoexceptMoveConstructorCheck.cpp?rev=304949&r1=304948&r2=304949&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/NoexceptMoveConstructorCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/misc/NoexceptMoveConstructorCheck.cpp 
Wed Jun  7 17:39:20 2017
@@ -20,7 +20,7 @@ namespace misc {
 void NoexceptMoveConstructorCheck::registerMatchers(MatchFinder *Finder) {
   // Only register the matchers for C++11; the functionality currently does not
   // provide any benefit to other languages, despite being benign.
-  if (!getLangOpts().CPlusPlus11)
+  if (!getLangOpts().CPlusPlus11 || !getLangOpts().CXXExceptions)
 return;
 
   Finder->addMatcher(

Modified: 
clang-tools-extra/trunk/test/clang-tidy/misc-noexcept-move-constructor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-noexcept-move-constructor.cpp?rev=304949&r1=304948&r2=304949&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-noexcept-move-constructor.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-noexcept-move-constructor.cpp 
Wed Jun  7 17:39:20 2017
@@ -1,16 +1,25 @@
-// RUN: %check_clang_tidy %s misc-noexcept-move-constructor %t
+// RUN: clang-tidy %s -checks="-*,misc-noexcept-move-constructor" -- 
-std=c++11 \
+// RUN:   | FileCheck %s -check-prefix=CHECK-EXCEPTIONS \
+// RUN:   -implicit-check-not="{{warning|error}}:"
+// RUN: clang-tidy %s -checks="-*,misc-noexcept-move-constructor" -- 
-fno-exceptions -std=c++11 \
+// RUN:   | FileCheck %s -allow-empty -check-prefix=CHECK-NONEXCEPTIONS \
+// RUN:   -implicit-check-not="{{warning|error}}:"
+
 
 class A {
   A(A &&);
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: move constructors should be 
marked noexcept [misc-noexcept-move-constructor]
+  // CHECK-EXCEPTIONS: :[[@LINE-1]]:3: warning: move constructors should be 
marked noexcept [misc-noexcept-move-constructor]
+  // CHECK-NONEXCEPTIONS-NOT: warning:
   A &operator=(A &&);
-  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: move assignment operators should
+  // CHECK-EXCEPTIONS: :[[@LINE-1]]:6: warning: move assignment operators 
should
+  // CHECK-NONEXCEPTIONS-NOT: warning:
 };
 
 struct B {
   static constexpr bool kFalse = false;
   B(B &&) noexcept(kFalse);
-  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: noexcept specifier on the move 
constructor evaluates to 'false' [misc-noexcept-move-constructor]
+  // CHECK-EXCEPTIONS: :[[@LINE-1]]:20: warning: noexcept specifier on the 
move constructor evaluates to 'false' [misc-noexcept-move-constructor]
+  // CHECK-NONEXCEPTIONS-NOT: warning:
 };
 
 class OK {};


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


[clang-tools-extra] r306165 - [clang-tidy][Part1] Add a new module Android and three new checks.

2017-06-23 Thread Yan Wang via cfe-commits
Author: yawanng
Date: Fri Jun 23 16:37:29 2017
New Revision: 306165

URL: http://llvm.org/viewvc/llvm-project?rev=306165&view=rev
Log:
[clang-tidy][Part1] Add a new module Android and three new checks.

Summary:
A common source of security bugs is code that opens a file descriptors without 
using the O_CLOEXEC flag.  (Without that flag, an opened sensitive file would 
remain open across a fork+exec to a lower-privileged SELinux domain, leaking 
that sensitive data.).

Add a new Android module and one checks in clang-tidy.
-- open(), openat(), and open64() should include O_CLOEXEC in their flags 
argument. [android-file-open-flag]

Links to part2 and part3:
https://reviews.llvm.org/D33745
https://reviews.llvm.org/D33747


Reviewers: chh, alexfh, aaron.ballman, hokein

Reviewed By: alexfh, hokein

Subscribers: jbcoe, joerg, malcolm.parsons, Eugene.Zelenko, srhines, mgorny, 
xazax.hun, cfe-commits, krytarowski

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/clang-tidy/android/
clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/android/FileOpenFlagCheck.cpp
clang-tools-extra/trunk/clang-tidy/android/FileOpenFlagCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/android-file-open-flag.rst
clang-tools-extra/trunk/test/clang-tidy/android-file-open-flag.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
clang-tools-extra/trunk/docs/clang-tidy/index.rst
clang-tools-extra/trunk/unittests/clang-tidy/CMakeLists.txt

Modified: clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/CMakeLists.txt?rev=306165&r1=306164&r2=306165&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/CMakeLists.txt Fri Jun 23 16:37:29 2017
@@ -26,6 +26,7 @@ add_clang_library(clangTidy
   clangToolingCore
   )
 
+add_subdirectory(android)
 add_subdirectory(boost)
 add_subdirectory(cert)
 add_subdirectory(cppcoreguidelines)

Added: clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp?rev=306165&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp Fri Jun 23 
16:37:29 2017
@@ -0,0 +1,40 @@
+//===--- AndroidTidyModule.cpp - 
clang-tidy===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+#include "FileOpenFlagCheck.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// This module is for Android specific checks.
+class AndroidModule : public ClangTidyModule {
+public:
+  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerCheck("android-file-open-flag");
+  }
+};
+
+// Register the AndroidTidyModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add
+X("android-module", "Adds Android platform checks.");
+
+} // namespace android
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the AndroidModule.
+volatile int AndroidModuleAnchorSource = 0;
+
+} // namespace tidy
+} // namespace clang

Added: clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt?rev=306165&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt (added)
+++ clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt Fri Jun 23 
16:37:29 2017
@@ -0,0 +1,14 @@
+set(LLVM_LINK_COMPONENTS support)
+
+add_clang_library(clangTidyAndroidModule
+  AndroidTidyModule.cpp
+  FileOpenFlagCheck.cpp
+
+  LINK_LIBS
+  clangAST
+  clangASTMatchers
+  clangBasic
+  clangLex
+  clangTidy
+  clangTidyUtils
+  )

Added: clang-tools-extra/trunk/clang-tid

[clang-tools-extra] r306172 - [clang-tidy] doc format fix

2017-06-23 Thread Yan Wang via cfe-commits
Author: yawanng
Date: Fri Jun 23 17:12:55 2017
New Revision: 306172

URL: http://llvm.org/viewvc/llvm-project?rev=306172&view=rev
Log:
[clang-tidy] doc format fix

Summary: The url in the doc is wrong. Fix the url.

Reviewers: chh

Reviewed By: chh

Subscribers: srhines, xazax.hun

Tags: #clang-tools-extra

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

Modified:
clang-tools-extra/trunk/docs/ReleaseNotes.rst

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=306172&r1=306171&r2=306172&view=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Fri Jun 23 17:12:55 2017
@@ -58,7 +58,7 @@ Improvements to clang-tidy
 --
 
 - New `android-file-open-flag
-`_ 
check
+  
`_ 
check
 
   Checks if the required file flag ``O_CLOEXEC`` exists in ``open()``,
   ``open64()`` and ``openat()``.


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


r309750 - [clang] Change the condition of unnecessary packed warning

2017-08-01 Thread Yan Wang via cfe-commits
Author: yawanng
Date: Tue Aug  1 14:41:39 2017
New Revision: 309750

URL: http://llvm.org/viewvc/llvm-project?rev=309750&view=rev
Log:
[clang] Change the condition of unnecessary packed warning

Summary:
Change the condition of this unnecessary packed warning. The packed is 
unnecessary when
1. the alignment of the struct/class won't alter.
2. the size is unchanged.
3. the offset of each field is the same.

Remove all field-level warning.

Reviewers: chh, akyrtzi, rtrieu

Reviewed By: chh

Subscribers: rsmith, srhines, cfe-commits, xazax.hun

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

Modified:
cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
cfe/trunk/test/CodeGenCXX/warn-padded-packed.cpp

Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=309750&r1=309749&r2=309750&view=diff
==
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Tue Aug  1 14:41:39 2017
@@ -632,6 +632,9 @@ protected:
   /// pointer, as opposed to inheriting one from a primary base class.
   bool HasOwnVFPtr;
 
+  /// \brief the flag of field offset changing due to packed attribute.
+  bool HasPackedField;
+
   typedef llvm::DenseMap BaseOffsetsMapTy;
 
   /// Bases - base classes and their offsets in the record.
@@ -666,7 +669,7 @@ protected:
 NonVirtualSize(CharUnits::Zero()),
 NonVirtualAlignment(CharUnits::One()), PrimaryBase(nullptr),
 PrimaryBaseIsVirtual(false), HasOwnVFPtr(false),
-FirstNearlyEmptyVBase(nullptr) {}
+HasPackedField(false), FirstNearlyEmptyVBase(nullptr) {}
 
   void Layout(const RecordDecl *D);
   void Layout(const CXXRecordDecl *D);
@@ -1847,7 +1850,6 @@ void ItaniumRecordLayoutBuilder::FinishL
   uint64_t UnpaddedSize = getSizeInBits() - UnfilledBitsInLastUnit;
   uint64_t UnpackedSizeInBits =
   llvm::alignTo(getSizeInBits(), Context.toBits(UnpackedAlignment));
-  CharUnits UnpackedSize = Context.toCharUnitsFromBits(UnpackedSizeInBits);
   uint64_t RoundedSize =
   llvm::alignTo(getSizeInBits(), Context.toBits(Alignment));
 
@@ -1882,10 +1884,11 @@ void ItaniumRecordLayoutBuilder::FinishL
   << (InBits ? 1 : 0); // (byte|bit)
 }
 
-// Warn if we packed it unnecessarily. If the alignment is 1 byte don't
-// bother since there won't be alignment issues.
-if (Packed && UnpackedAlignment > CharUnits::One() && 
-getSize() == UnpackedSize)
+// Warn if we packed it unnecessarily, when the unpacked alignment is not
+// greater than the one after packing, the size in bits doesn't change and
+// the offset of each field is identical.
+if (Packed && UnpackedAlignment <= Alignment &&
+UnpackedSizeInBits == getSizeInBits() && !HasPackedField)
   Diag(D->getLocation(), diag::warn_unnecessary_packed)
   << Context.getTypeDeclType(RD);
   }
@@ -1977,13 +1980,10 @@ void ItaniumRecordLayoutBuilder::CheckFi
   << Context.getTypeDeclType(D->getParent())
   << PadSize
   << (InBits ? 1 : 0); // (byte|bit)
-  }
-
-  // Warn if we packed it unnecessarily. If the alignment is 1 byte don't
-  // bother since there won't be alignment issues.
-  if (isPacked && UnpackedAlign > CharBitNum && Offset == UnpackedOffset)
-Diag(D->getLocation(), diag::warn_unnecessary_packed)
-<< D->getIdentifier();
+ }
+ if (isPacked && Offset != UnpackedOffset) {
+   HasPackedField = true;
+ }
 }
 
 static const CXXMethodDecl *computeKeyFunction(ASTContext &Context,

Modified: cfe/trunk/test/CodeGenCXX/warn-padded-packed.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/warn-padded-packed.cpp?rev=309750&r1=309749&r2=309750&view=diff
==
--- cfe/trunk/test/CodeGenCXX/warn-padded-packed.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/warn-padded-packed.cpp Tue Aug  1 14:41:39 2017
@@ -17,7 +17,7 @@ struct S3 {
 } __attribute__((packed));
 
 struct S4 {
-  int i; // expected-warning {{packed attribute is unnecessary for 'i'}}
+  int i;
   char c;
 } __attribute__((packed));
 
@@ -46,18 +46,18 @@ struct S8 : B {
   int i; // expected-warning {{padding struct 'S8' with 3 bytes to align 'i'}}
 };
 
-struct S9 { // expected-warning {{packed attribute is unnecessary for 'S9'}}
-  int x; // expected-warning {{packed attribute is unnecessary for 'x'}}
-  int y; // expected-warning {{packed attribute is unnecessary for 'y'}}
+struct S9 {
+  int x;
+  int y;
 } __attribute__((packed));
 
-struct S10 { // expected-warning {{packed attribute is unnecessary for 'S10'}}
-  int x; // expected-warning {{packed attribute is unnecessary for 'x'}}
+struct S10 {
+  int x;
   char a,b,c,d;
 } __attribute__((packed));
 
 
-struct S11 {
+struct S11 { // expected-warning {{packed attribute is unnecessary for 'S11'}}

[clang-tools-extra] r310630 - [clang-tidy] Refactor the code and add a close-on-exec check on memfd_create() in Android module.

2017-08-10 Thread Yan Wang via cfe-commits
Author: yawanng
Date: Thu Aug 10 10:18:10 2017
New Revision: 310630

URL: http://llvm.org/viewvc/llvm-project?rev=310630&view=rev
Log:
[clang-tidy] Refactor the code and add a close-on-exec check on memfd_create() 
in Android module.

Summary:
1. Refactor the structure of the code by adding a base class for all 
close-on-exec checks, which implements most of the needed functions.
2. memfd_create() is better to set MFD_CLOEXEC flag to avoid file descriptor 
leakage.

Reviewers: alexfh, aaron.ballman, hokein

Reviewed By: alexfh, hokein

Subscribers: Eugene.Zelenko, chh, cfe-commits, srhines, mgorny, JDevlieghere, 
xazax.hun

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp
clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h
clang-tools-extra/trunk/clang-tidy/android/CloexecMemfdCreateCheck.cpp
clang-tools-extra/trunk/clang-tidy/android/CloexecMemfdCreateCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-memfd-create.rst
clang-tools-extra/trunk/test/clang-tidy/android-cloexec-memfd-create.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp?rev=310630&r1=310629&r2=310630&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp Thu Aug 10 
10:18:10 2017
@@ -12,6 +12,7 @@
 #include "../ClangTidyModuleRegistry.h"
 #include "CloexecCreatCheck.h"
 #include "CloexecFopenCheck.h"
+#include "CloexecMemfdCreateCheck.h"
 #include "CloexecOpenCheck.h"
 #include "CloexecSocketCheck.h"
 
@@ -27,6 +28,8 @@ public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
 CheckFactories.registerCheck("android-cloexec-creat");
 CheckFactories.registerCheck("android-cloexec-fopen");
+CheckFactories.registerCheck(
+"android-cloexec-memfd-create");
 CheckFactories.registerCheck("android-cloexec-open");
 CheckFactories.registerCheck("android-cloexec-socket");
   }

Modified: clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt?rev=310630&r1=310629&r2=310630&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt Thu Aug 10 
10:18:10 2017
@@ -2,8 +2,10 @@ set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyAndroidModule
   AndroidTidyModule.cpp
+  CloexecCheck.cpp
   CloexecCreatCheck.cpp
   CloexecFopenCheck.cpp
+  CloexecMemfdCreateCheck.cpp
   CloexecOpenCheck.cpp
   CloexecSocketCheck.cpp
 

Added: clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp?rev=310630&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp Thu Aug 10 
10:18:10 2017
@@ -0,0 +1,105 @@
+//===--- CloexecCheck.cpp - 
clang-tidy-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "CloexecCheck.h"
+#include "../utils/ASTUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+namespace {
+
+const char *const FuncDeclBindingStr = "funcDecl";
+const char *const FuncBindingStr = "func";
+
+// Helper function to form the correct string mode for Type3.
+// Build the replace text. If it's string constant, add  directly in the
+// end of the string. Else, add .
+std::string buildFixMsgForStringFlag(const Expr *Arg, const SourceManager &SM,
+ const LangOptions &LangOpts, char Mode) {
+  if (Arg->getLocStart().isMacroID())
+return (Lexer::getSourceText(
+CharSourceRange::getTokenRange(Arg->getSourceRange()), SM,
+LangOpts) +
+" \"" + Twine(Mode) + "\"

[clang-tools-extra] r310643 - [clang-tidy] Fix a buildbot.

2017-08-10 Thread Yan Wang via cfe-commits
Author: yawanng
Date: Thu Aug 10 11:19:40 2017
New Revision: 310643

URL: http://llvm.org/viewvc/llvm-project?rev=310643&view=rev
Log:
[clang-tidy] Fix a buildbot.

Fix format in ReleaseNotes.rst.


Modified:
clang-tools-extra/trunk/docs/ReleaseNotes.rst

Modified: clang-tools-extra/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/ReleaseNotes.rst?rev=310643&r1=310642&r2=310643&view=diff
==
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst (original)
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst Thu Aug 10 11:19:40 2017
@@ -73,8 +73,8 @@ Improvements to clang-tidy
 - New `android-cloexec-memfd_create
 
`_
 check
 
-Checks if the required file flag ``MFD_CLOEXEC`` is present in the 
argument of
-  ``memfd_create()``.
+  Checks if the required file flag ``MFD_CLOEXEC`` is present in the argument
+  of ``memfd_create()``.
 
 - New `bugprone-integer-division
   
`_
 check


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


Re: [clang-tools-extra] r310630 - [clang-tidy] Refactor the code and add a close-on-exec check on memfd_create() in Android module.

2017-08-10 Thread Yan Wang via cfe-commits
lude\
> clang/Basic/Diagnostic.h(1133): note: or   'const
> clang::DiagnosticBuilder &clang::operator <<(const clang::DiagnosticBuilder
> &,unsigned int)'
> D:\buildslave\clang-x64-ninja-win7\llvm\tools\clang\include\
> clang/Basic/Diagnostic.h(1117): note: or   'const
> clang::DiagnosticBuilder &clang::operator <<(const clang::DiagnosticBuilder
> &,int)'
> D:\buildslave\clang-x64-ninja-win7\llvm\tools\clang\include\
> clang/Basic/Diagnostic.h(1110): note: or   'const
> clang::DiagnosticBuilder &clang::operator <<(const clang::DiagnosticBuilder
> &,const char *)'
> D:\buildslave\clang-x64-ninja-win7\llvm\tools\clang\include\
> clang/Basic/Diagnostic.h(1104): note: or   'const
> clang::DiagnosticBuilder &clang::operator <<(const clang::DiagnosticBuilder
> &,llvm::StringRef)'
> D:\buildslave\clang-x64-ninja-win7\llvm\tools\clang\include\
> clang/Basic/Diagnostic.h(1098): note: or   'const
> clang::DiagnosticBuilder &clang::operator <<(const clang::DiagnosticBuilder
> &,const clang::AddFlagValue)'
> D:\buildslave\clang-x64-ninja-win7\llvm\tools\clang\include\
> clang/Basic/DiagnosticOptions.h(58): note: or   'llvm::raw_ostream
> &clang::operator <<(llvm::raw_ostream &,clang::DiagnosticLevelMask)'
> D:\buildslave\clang-x64-ninja-win7\llvm\tools\clang\tools\
> extra\clang-tidy\android\CloexecCheck.cpp(99): note: while trying to
> match the argument list '(const clang::DiagnosticBuilder, const char)'
> ninja: build stopped: subcommand failed.
>
> On Thu, Aug 10, 2017 at 1:18 PM, Yan Wang via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: yawanng
>> Date: Thu Aug 10 10:18:10 2017
>> New Revision: 310630
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=310630&view=rev
>> Log:
>> [clang-tidy] Refactor the code and add a close-on-exec check on
>> memfd_create() in Android module.
>>
>> Summary:
>> 1. Refactor the structure of the code by adding a base class for all
>> close-on-exec checks, which implements most of the needed functions.
>> 2. memfd_create() is better to set MFD_CLOEXEC flag to avoid file
>> descriptor leakage.
>>
>> Reviewers: alexfh, aaron.ballman, hokein
>>
>> Reviewed By: alexfh, hokein
>>
>> Subscribers: Eugene.Zelenko, chh, cfe-commits, srhines, mgorny,
>> JDevlieghere, xazax.hun
>>
>> Tags: #clang-tools-extra
>>
>> Differential Revision: https://reviews.llvm.org/D35372
>>
>> Added:
>> clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h
>> clang-tools-extra/trunk/clang-tidy/android/CloexecMemfdCreat
>> eCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/android/CloexecMemfdCreateCheck.h
>> clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloex
>> ec-memfd-create.rst
>> clang-tools-extra/trunk/test/clang-tidy/android-cloexec-memf
>> d-create.cpp
>> Modified:
>> clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
>> clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
>> clang-tools-extra/trunk/docs/ReleaseNotes.rst
>> clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
>>
>> Modified: clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule
>> .cpp
>> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/
>> clang-tidy/android/AndroidTidyModule.cpp?rev=310630&r1=
>> 310629&r2=310630&view=diff
>> 
>> ==
>> --- clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
>> (original)
>> +++ clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp Thu
>> Aug 10 10:18:10 2017
>> @@ -12,6 +12,7 @@
>>  #include "../ClangTidyModuleRegistry.h"
>>  #include "CloexecCreatCheck.h"
>>  #include "CloexecFopenCheck.h"
>> +#include "CloexecMemfdCreateCheck.h"
>>  #include "CloexecOpenCheck.h"
>>  #include "CloexecSocketCheck.h"
>>
>> @@ -27,6 +28,8 @@ public:
>>void addCheckFactories(ClangTidyCheckFactories &CheckFactories)
>> override {
>>  CheckFactories.registerCheck("android-cl
>> oexec-creat");
>>  CheckFactories.registerCheck("android-cl
>> oexec-fopen");
>> +CheckFactories.registerCheck(
>> +"android-cloexec-memfd-create");
>>

[clang-tools-extra] r310669 - [clang-tidy] Fix for buildbot.

2017-08-10 Thread Yan Wang via cfe-commits
Author: yawanng
Date: Thu Aug 10 15:09:22 2017
New Revision: 310669

URL: http://llvm.org/viewvc/llvm-project?rev=310669&view=rev
Log:
[clang-tidy] Fix for buildbot.

Summary:
Fix an issue for windows.

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

Added:
clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp
clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.h
clang-tools-extra/trunk/clang-tidy/android/CloexecMemfdCreateCheck.cpp
clang-tools-extra/trunk/clang-tidy/android/CloexecMemfdCreateCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-memfd-create.rst
clang-tools-extra/trunk/test/clang-tidy/android-cloexec-memfd-create.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp?rev=310669&r1=310668&r2=310669&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp Thu Aug 10 
15:09:22 2017
@@ -12,6 +12,7 @@
 #include "../ClangTidyModuleRegistry.h"
 #include "CloexecCreatCheck.h"
 #include "CloexecFopenCheck.h"
+#include "CloexecMemfdCreateCheck.h"
 #include "CloexecOpenCheck.h"
 #include "CloexecSocketCheck.h"
 
@@ -27,6 +28,8 @@ public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
 CheckFactories.registerCheck("android-cloexec-creat");
 CheckFactories.registerCheck("android-cloexec-fopen");
+CheckFactories.registerCheck(
+"android-cloexec-memfd-create");
 CheckFactories.registerCheck("android-cloexec-open");
 CheckFactories.registerCheck("android-cloexec-socket");
   }

Modified: clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt?rev=310669&r1=310668&r2=310669&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt Thu Aug 10 
15:09:22 2017
@@ -2,8 +2,10 @@ set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyAndroidModule
   AndroidTidyModule.cpp
+  CloexecCheck.cpp
   CloexecCreatCheck.cpp
   CloexecFopenCheck.cpp
+  CloexecMemfdCreateCheck.cpp
   CloexecOpenCheck.cpp
   CloexecSocketCheck.cpp
 

Added: clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp?rev=310669&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecCheck.cpp Thu Aug 10 
15:09:22 2017
@@ -0,0 +1,105 @@
+//===--- CloexecCheck.cpp - 
clang-tidy-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "CloexecCheck.h"
+#include "../utils/ASTUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+namespace {
+
+const char *const FuncDeclBindingStr = "funcDecl";
+const char *const FuncBindingStr = "func";
+
+// Helper function to form the correct string mode for Type3.
+// Build the replace text. If it's string constant, add  directly in the
+// end of the string. Else, add .
+std::string buildFixMsgForStringFlag(const Expr *Arg, const SourceManager &SM,
+ const LangOptions &LangOpts, char Mode) {
+  if (Arg->getLocStart().isMacroID())
+return (Lexer::getSourceText(
+CharSourceRange::getTokenRange(Arg->getSourceRange()), SM,
+LangOpts) +
+" \"" + Twine(Mode) + "\"")
+.str();
+
+  StringRef SR = cast(Arg->IgnoreParenCasts())->getString();
+  return ("\"" + SR + Twine(Mode) + "\"").str();
+}
+} // namespace
+
+void CloexecCheck::registerMatchersImpl(
+MatchFinder *Finder, internal::Matcher Function) {
+  // We assume all the checked APIs are C functions.
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(isExternC(), Function).bind(FuncDeclBindingStr)))
+  .bind(FuncBindin

[clang-tools-extra] r306708 - [clang-tidy][Part2] Add a new module Android and three new checks

2017-06-29 Thread Yan Wang via cfe-commits
Author: yawanng
Date: Thu Jun 29 10:40:57 2017
New Revision: 306708

URL: http://llvm.org/viewvc/llvm-project?rev=306708&view=rev
Log:
[clang-tidy][Part2] Add a new module Android and three new checks

Summary: -- creat() should be replaced by open(). [android-creat-usage] 

Reviewers: chh, alexfh, aaron.ballman, hokein

Reviewed By: hokein

Subscribers: JDevlieghere, srhines, mgorny, xazax.hun

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.cpp
clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-creat.rst
clang-tools-extra/trunk/test/clang-tidy/android-cloexec-creat.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst

Modified: clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp?rev=306708&r1=306707&r2=306708&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp Thu Jun 29 
10:40:57 2017
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "CloexecCreatCheck.h"
 #include "FileOpenFlagCheck.h"
 
 using namespace clang::ast_matchers;
@@ -23,6 +24,7 @@ class AndroidModule : public ClangTidyMo
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
 CheckFactories.registerCheck("android-file-open-flag");
+CheckFactories.registerCheck("android-cloexec-creat");
   }
 };
 

Modified: clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt?rev=306708&r1=306707&r2=306708&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt Thu Jun 29 
10:40:57 2017
@@ -2,6 +2,7 @@ set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyAndroidModule
   AndroidTidyModule.cpp
+  CloexecCreatCheck.cpp
   FileOpenFlagCheck.cpp
 
   LINK_LIBS

Added: clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.cpp?rev=306708&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecCreatCheck.cpp Thu Jun 29 
10:40:57 2017
@@ -0,0 +1,59 @@
+//===--- CloexecCreatCheck.cpp - 
clang-tidy===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "CloexecCreatCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+void CloexecCreatCheck::registerMatchers(MatchFinder *Finder) {
+  auto CharPointerType = hasType(pointerType(pointee(isAnyCharacter(;
+  auto MODETType = hasType(namedDecl(hasName("mode_t")));
+
+  Finder->addMatcher(
+  callExpr(callee(functionDecl(isExternC(), returns(isInteger()),
+   hasName("creat"),
+   hasParameter(0, CharPointerType),
+   hasParameter(1, MODETType))
+  .bind("funcDecl")))
+  .bind("creatFn"),
+  this);
+}
+
+void CloexecCreatCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *MatchedCall = Result.Nodes.getNodeAs("creatFn");
+  const SourceManager &SM = *Result.SourceManager;
+
+  const std::string &ReplacementText =
+  (Twine("open (") +
+   Lexer::getSourceText(CharSourceRange::getTokenRange(
+MatchedCall->getArg(0)->getSourceRange()),
+SM, Result.Context->getLangOpts()) +
+   ", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, " +
+   Lexer::getSourceText(CharSourceRange::getTokenRange(
+MatchedCall->getArg(1)->getSourceRange()),
+SM, Result.Context->getLangOpts()) +
+   ")")
+  .str();
+
+  diag(MatchedCall->getL

[clang-tools-extra] r306709 - [clang-tidy][Part3] Add a new module Android and three new checks.

2017-06-29 Thread Yan Wang via cfe-commits
Author: yawanng
Date: Thu Jun 29 10:42:23 2017
New Revision: 306709

URL: http://llvm.org/viewvc/llvm-project?rev=306709&view=rev
Log:
[clang-tidy][Part3] Add a new module Android and three new checks.

Summary: -- fopen() should include "e" in their mode string. 
[android-fopen-mode]

Reviewers: chh, alexfh, aaron.ballman, hokein

Reviewed By: hokein

Subscribers: JDevlieghere, srhines, mgorny, xazax.hun

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/clang-tidy/android/CloexecFopenCheck.cpp
clang-tools-extra/trunk/clang-tidy/android/CloexecFopenCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-fopen.rst
clang-tools-extra/trunk/test/clang-tidy/android-cloexec-fopen.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst

Modified: clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp?rev=306709&r1=306708&r2=306709&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp Thu Jun 29 
10:42:23 2017
@@ -11,6 +11,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 #include "CloexecCreatCheck.h"
+#include "CloexecFopenCheck.h"
 #include "FileOpenFlagCheck.h"
 
 using namespace clang::ast_matchers;
@@ -25,6 +26,7 @@ public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
 CheckFactories.registerCheck("android-file-open-flag");
 CheckFactories.registerCheck("android-cloexec-creat");
+CheckFactories.registerCheck("android-cloexec-fopen");
   }
 };
 

Modified: clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt?rev=306709&r1=306708&r2=306709&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt Thu Jun 29 
10:42:23 2017
@@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS support)
 add_clang_library(clangTidyAndroidModule
   AndroidTidyModule.cpp
   CloexecCreatCheck.cpp
+  CloexecFopenCheck.cpp
   FileOpenFlagCheck.cpp
 
   LINK_LIBS

Added: clang-tools-extra/trunk/clang-tidy/android/CloexecFopenCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecFopenCheck.cpp?rev=306709&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/android/CloexecFopenCheck.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecFopenCheck.cpp Thu Jun 29 
10:42:23 2017
@@ -0,0 +1,74 @@
+//===--- CloexecFopenCheck.cpp - 
clang-tidy===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.  //
+//===--===//
+
+#include "CloexecFopenCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+namespace {
+static const char MODE = 'e';
+
+// Build the replace text. If it's string constant, add 'e' directly in the end
+// of the string. Else, add "e".
+std::string BuildReplaceText(const Expr *Arg, const SourceManager &SM,
+ const LangOptions &LangOpts) {
+  if (Arg->getLocStart().isMacroID())
+return (Lexer::getSourceText(
+CharSourceRange::getTokenRange(Arg->getSourceRange()), SM,
+LangOpts) +
+" \"" + Twine(MODE) + "\"")
+.str();
+
+  StringRef SR = cast(Arg->IgnoreParenCasts())->getString();
+  return ("\"" + SR + Twine(MODE) + "\"").str();
+}
+} // namespace
+
+void CloexecFopenCheck::registerMatchers(MatchFinder *Finder) {
+  auto CharPointerType = hasType(pointerType(pointee(isAnyCharacter(;
+
+  Finder->addMatcher(
+  callExpr(callee(functionDecl(isExternC(), returns(asString("FILE *")),
+   hasName("fopen"),
+   hasParameter(0, CharPointerType),
+   hasParameter(1, CharPointerType))
+  .bind("funcDecl")))
+  .bind("fopenFn"),
+  this);
+}
+
+void CloexecFopenCheck::check(const MatchFinder::MatchResult &Result) {

[clang-tools-extra] r306719 - [clang-tidy] Add docs to toctree

2017-06-29 Thread Yan Wang via cfe-commits
Author: yawanng
Date: Thu Jun 29 11:44:28 2017
New Revision: 306719

URL: http://llvm.org/viewvc/llvm-project?rev=306719&view=rev
Log:
[clang-tidy] Add docs to toctree

Summary: Add .rst files to toctree. Fix buildbot error.

Reviewers: chh

Reviewed By: chh

Subscribers: srhines, JDevlieghere, xazax.hun

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

Modified:
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst?rev=306719&r1=306718&r2=306719&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst Thu Jun 29 11:44:28 
2017
@@ -4,6 +4,8 @@ Clang-Tidy Checks
 =
 
 .. toctree::
+   android-cloexec-creat
+   android-cloexec-fopen
android-file-open-flag
boost-use-to-string
cert-dcl03-c (redirects to misc-static-assert) 


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


[clang-tools-extra] r306728 - [clang-tidy] Rename android-file-open-flag and fix a bug

2017-06-29 Thread Yan Wang via cfe-commits
Author: yawanng
Date: Thu Jun 29 12:13:29 2017
New Revision: 306728

URL: http://llvm.org/viewvc/llvm-project?rev=306728&view=rev
Log:
[clang-tidy] Rename android-file-open-flag and fix a bug

Summary:
1. Rename android-file-open-flag to android-cloexec-open.
2. Handle a case when the function is passed as an argument of a function-like 
macro.

Reviewers: chh

Reviewed By: chh

Subscribers: srhines, mgorny, JDevlieghere, xazax.hun, cfe-commits

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.cpp
  - copied, changed from r306725, 
clang-tools-extra/trunk/clang-tidy/android/FileOpenFlagCheck.cpp
clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.h
  - copied, changed from r306725, 
clang-tools-extra/trunk/clang-tidy/android/FileOpenFlagCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-open.rst
  - copied, changed from r306725, 
clang-tools-extra/trunk/docs/clang-tidy/checks/android-file-open-flag.rst
clang-tools-extra/trunk/test/clang-tidy/android-cloexec-open.cpp
Removed:
clang-tools-extra/trunk/clang-tidy/android/FileOpenFlagCheck.cpp
clang-tools-extra/trunk/clang-tidy/android/FileOpenFlagCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/android-file-open-flag.rst
clang-tools-extra/trunk/test/clang-tidy/android-file-open-flag.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp?rev=306728&r1=306727&r2=306728&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp Thu Jun 29 
12:13:29 2017
@@ -12,7 +12,7 @@
 #include "../ClangTidyModuleRegistry.h"
 #include "CloexecCreatCheck.h"
 #include "CloexecFopenCheck.h"
-#include "FileOpenFlagCheck.h"
+#include "CloexecOpenCheck.h"
 
 using namespace clang::ast_matchers;
 
@@ -24,9 +24,9 @@ namespace android {
 class AndroidModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
-CheckFactories.registerCheck("android-file-open-flag");
 CheckFactories.registerCheck("android-cloexec-creat");
 CheckFactories.registerCheck("android-cloexec-fopen");
+CheckFactories.registerCheck("android-cloexec-open");
   }
 };
 

Modified: clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt?rev=306728&r1=306727&r2=306728&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt Thu Jun 29 
12:13:29 2017
@@ -4,7 +4,7 @@ add_clang_library(clangTidyAndroidModule
   AndroidTidyModule.cpp
   CloexecCreatCheck.cpp
   CloexecFopenCheck.cpp
-  FileOpenFlagCheck.cpp
+  CloexecOpenCheck.cpp
 
   LINK_LIBS
   clangAST

Copied: clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.cpp (from 
r306725, clang-tools-extra/trunk/clang-tidy/android/FileOpenFlagCheck.cpp)
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.cpp?p2=clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.cpp&p1=clang-tools-extra/trunk/clang-tidy/android/FileOpenFlagCheck.cpp&r1=306725&r2=306728&rev=306728&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/FileOpenFlagCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.cpp Thu Jun 29 
12:13:29 2017
@@ -1,4 +1,4 @@
-//===--- FileOpenFlagCheck.cpp - 
clang-tidy===//
+//===--- CloexecOpenCheck.cpp - 
clang-tidy-===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -7,7 +7,7 @@
 //
 
//===--===//
 
-#include "FileOpenFlagCheck.h"
+#include "CloexecOpenCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Lex/Lexer.h"
@@ -21,11 +21,12 @@ namespace android {
 namespace {
 static constexpr const char *O_CLOEXEC = "O_CLOEXEC";
 
-bool HasCloseOnExecFlag(const Expr *Flags, const SourceManager &SM,
+bool hasCloseOnExecFlag(const Expr *Flags, const SourceManager &SM,
 const LangOptions &LangOpts) {
   // If

[clang-tools-extra] r307818 - [clang-tidy] Add a new Android check "android-cloexec-socket"

2017-07-12 Thread Yan Wang via cfe-commits
Author: yawanng
Date: Wed Jul 12 10:43:36 2017
New Revision: 307818

URL: http://llvm.org/viewvc/llvm-project?rev=307818&view=rev
Log:
[clang-tidy] Add a new Android check "android-cloexec-socket"

Summary: socket() is better to include SOCK_CLOEXEC in its type argument to 
avoid the file descriptor leakage.

Reviewers: chh, Eugene.Zelenko, alexfh, hokein, aaron.ballman

Reviewed By: chh, alexfh

Subscribers: srhines, mgorny, JDevlieghere, xazax.hun, cfe-commits

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.cpp
clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-socket.rst
clang-tools-extra/trunk/test/clang-tidy/android-cloexec-socket.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.cpp
clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.cpp
clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.h
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp?rev=307818&r1=307817&r2=307818&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp Wed Jul 12 
10:43:36 2017
@@ -13,6 +13,7 @@
 #include "CloexecCreatCheck.h"
 #include "CloexecFopenCheck.h"
 #include "CloexecOpenCheck.h"
+#include "CloexecSocketCheck.h"
 
 using namespace clang::ast_matchers;
 
@@ -27,6 +28,7 @@ public:
 CheckFactories.registerCheck("android-cloexec-creat");
 CheckFactories.registerCheck("android-cloexec-fopen");
 CheckFactories.registerCheck("android-cloexec-open");
+CheckFactories.registerCheck("android-cloexec-socket");
   }
 };
 

Modified: clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt?rev=307818&r1=307817&r2=307818&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt Wed Jul 12 
10:43:36 2017
@@ -5,6 +5,7 @@ add_clang_library(clangTidyAndroidModule
   CloexecCreatCheck.cpp
   CloexecFopenCheck.cpp
   CloexecOpenCheck.cpp
+  CloexecSocketCheck.cpp
 
   LINK_LIBS
   clangAST

Modified: clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.cpp?rev=307818&r1=307817&r2=307818&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.cpp Wed Jul 12 
10:43:36 2017
@@ -8,6 +8,7 @@
 
//===--===//
 
 #include "CloexecOpenCheck.h"
+#include "../utils/ASTUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Lex/Lexer.h"
@@ -18,35 +19,8 @@ namespace clang {
 namespace tidy {
 namespace android {
 
-namespace {
 static constexpr const char *O_CLOEXEC = "O_CLOEXEC";
 
-bool hasCloseOnExecFlag(const Expr *Flags, const SourceManager &SM,
-const LangOptions &LangOpts) {
-  // If the Flag is an integer constant, check it.
-  if (isa(Flags)) {
-if (!SM.isMacroBodyExpansion(Flags->getLocStart()) &&
-!SM.isMacroArgExpansion(Flags->getLocStart()))
-  return false;
-
-// Get the Marco name.
-auto MacroName = Lexer::getSourceText(
-CharSourceRange::getTokenRange(Flags->getSourceRange()), SM, LangOpts);
-
-return MacroName == O_CLOEXEC;
-  }
-  // If it's a binary OR operation.
-  if (const auto *BO = dyn_cast(Flags))
-if (BO->getOpcode() == clang::BinaryOperatorKind::BO_Or)
-  return hasCloseOnExecFlag(BO->getLHS()->IgnoreParenCasts(), SM,
-LangOpts) ||
- hasCloseOnExecFlag(BO->getRHS()->IgnoreParenCasts(), SM, 
LangOpts);
-
-  // Otherwise, assume it has the flag.
-  return true;
-}
-} // namespace
-
 void CloexecOpenCheck::registerMatchers(MatchFinder *Finder) {
   auto CharPointerType = hasType(pointerType(pointee(isAnyCharacter(;
 
@@ -82,8 +56,8 @@ void CloexecOpenCheck::check(const Match
 
   // Check the required flag.
   SourceManager &SM = *Result.SourceManager;
-  if (hasCloseO

[clang-tools-extra] r303001 - [clang-tidy] TwineLocalCheck: add param # checking

2017-05-14 Thread Yan Wang via cfe-commits
Author: yawanng
Date: Sat May 13 23:14:59 2017
New Revision: 303001

URL: http://llvm.org/viewvc/llvm-project?rev=303001&view=rev
Log:
[clang-tidy] TwineLocalCheck: add param # checking

Summary:
The statement **getArg** tries to get the first one without checking, which may 
cause segmentation fault.

 

Reviewers: chh, bkramer

Reviewed By: bkramer

Subscribers: cfe-commits, xazax.hun

Tags: #clang-tools-extra

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

Modified:
clang-tools-extra/trunk/clang-tidy/llvm/TwineLocalCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/llvm-twine-local.cpp

Modified: clang-tools-extra/trunk/clang-tidy/llvm/TwineLocalCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/llvm/TwineLocalCheck.cpp?rev=303001&r1=303000&r2=303001&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/llvm/TwineLocalCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/llvm/TwineLocalCheck.cpp Sat May 13 
23:14:59 2017
@@ -35,8 +35,11 @@ void TwineLocalCheck::check(const MatchF
 // of the initializer.
 const Expr *C = VD->getInit()->IgnoreImplicit();
 
-while (isa(C))
+while (isa(C)) {
+  if (cast(C)->getNumArgs() == 0)
+break;
   C = cast(C)->getArg(0)->IgnoreParenImpCasts();
+}
 
 SourceRange TypeRange =
 VD->getTypeSourceInfo()->getTypeLoc().getSourceRange();

Modified: clang-tools-extra/trunk/test/clang-tidy/llvm-twine-local.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/llvm-twine-local.cpp?rev=303001&r1=303000&r2=303001&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/llvm-twine-local.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/llvm-twine-local.cpp Sat May 13 
23:14:59 2017
@@ -5,6 +5,7 @@ class Twine {
 public:
   Twine(const char *);
   Twine(int);
+  Twine();
   Twine &operator+(const Twine &);
 };
 }
@@ -29,4 +30,35 @@ int main() {
 // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: twine variables are prone to 
use-after-free bugs
 // CHECK-MESSAGES: note: FIX-IT applied suggested code changes
 // CHECK-FIXES: const char * Prefix = false ? "__INT_FAST" : "__UINT_FAST";
+
+  const Twine t2 = Twine();
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: twine variables are prone to 
use-after-free bugs
+// CHECK-MESSAGES: note: FIX-IT applied suggested code changes
+// CHECK-FIXES: std::string t2 = (Twine()).str();
+  foo(Twine() + "b");
+
+  const Twine t3 = Twine(42);
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: twine variables are prone to 
use-after-free bugs
+// CHECK-MESSAGES: note: FIX-IT applied suggested code changes
+// CHECK-FIXES: std::string t3 = (Twine(42)).str();
+
+  const Twine t4 = Twine(42) + "b";
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: twine variables are prone to 
use-after-free bugs
+// CHECK-MESSAGES: note: FIX-IT applied suggested code changes
+// CHECK-FIXES: std::string t4 = (Twine(42) + "b").str();
+
+  const Twine t5 = Twine() + "b";
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: twine variables are prone to 
use-after-free bugs
+// CHECK-MESSAGES: note: FIX-IT applied suggested code changes
+// CHECK-FIXES: std::string t5 = (Twine() + "b").str();
+
+  const Twine t6 = true ? Twine() : Twine(42);
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: twine variables are prone to 
use-after-free bugs
+// CHECK-MESSAGES: note: FIX-IT applied suggested code changes
+// CHECK-FIXES: std::string t6 = (true ? Twine() : Twine(42)).str();
+
+  const Twine t7 = false ? Twine() : Twine("b");
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: twine variables are prone to 
use-after-free bugs
+// CHECK-MESSAGES: note: FIX-IT applied suggested code changes
+// CHECK-FIXES: std::string t7 = (false ? Twine() : Twine("b")).str();
 }


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