[PATCH] D39121: [clang-tidy] Misplaced Operator in Strlen in Alloc

2017-10-27 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 120545.
baloghadamsoftware added a comment.

Updated according to the comments.


https://reviews.llvm.org/D39121

Files:
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
  clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c
  test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp

Index: test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp
===
--- /dev/null
+++ test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp
@@ -0,0 +1,31 @@
+// RUN: %check_clang_tidy %s bugprone-misplaced-operator-in-strlen-in-alloc %t
+
+namespace std {
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+
+size_t strlen(const char*);
+}
+
+namespace non_std {
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+
+size_t strlen(const char*);
+}
+
+void bad_std_malloc_std_strlen(char *name) {
+  char *new_name = (char*) std::malloc(std::strlen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: Addition operator is applied to the argument of strlen
+  // CHECK-FIXES: {{^  char \*new_name = \(char\*\) std::malloc\(}}std::strlen(name) + 1{{\);$}}
+}
+
+void ignore_non_std_malloc_std_strlen(char *name) {
+  char *new_name = (char*) non_std::malloc(std::strlen(name + 1));
+  // Ignore functions of the malloc family in custom namespaces
+}
+
+void ignore_std_malloc_non_std_strlen(char *name) {
+  char *new_name = (char*) std::malloc(non_std::strlen(name + 1));
+  // Ignore functions of the strlen family in custom namespaces
+}
Index: test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c
===
--- /dev/null
+++ test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c
@@ -0,0 +1,78 @@
+// RUN: %check_clang_tidy %s bugprone-misplaced-operator-in-strlen-in-alloc %t
+
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+void *alloca(size_t);
+void *calloc(size_t, size_t);
+void *realloc(void *, size_t);
+
+size_t strlen(const char*);
+size_t strnlen(const char*, size_t);
+size_t strnlen_s(const char*, size_t);
+
+typedef unsigned wchar_t;
+
+size_t wcslen(const wchar_t*);
+size_t wcsnlen(const wchar_t*, size_t);
+size_t wcsnlen_s(const wchar_t*, size_t);
+
+void bad_malloc(char *name) {
+  char *new_name = (char*) malloc(strlen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: Addition operator is applied to the argument of strlen
+  // CHECK-FIXES: {{^  char \*new_name = \(char\*\) malloc\(}}strlen(name) + 1{{\);$}}
+  new_name = (char*) malloc(strnlen(name + 1, 10));
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: Addition operator is applied to the argument of strnlen
+  // CHECK-FIXES: {{^  new_name = \(char\*\) malloc\(}}strnlen(name, 10) + 1{{\);$}}
+  new_name = (char*) malloc(strnlen_s(name + 1, 10));
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: Addition operator is applied to the argument of strnlen_s
+  // CHECK-FIXES: {{^  new_name = \(char\*\) malloc\(}}strnlen_s(name, 10) + 1{{\);$}}
+}
+
+void bad_malloc_wide(wchar_t *name) {
+  wchar_t *new_name = (wchar_t*) malloc(wcslen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: Addition operator is applied to the argument of wcslen
+  // CHECK-FIXES: {{^  wchar_t \*new_name = \(wchar_t\*\) malloc\(}}wcslen(name) + 1{{\);$}}
+  new_name = (wchar_t*) malloc(wcsnlen(name + 1, 10));
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: Addition operator is applied to the argument of wcsnlen
+  // CHECK-FIXES: {{^  new_name = \(wchar_t\*\) malloc\(}}wcsnlen(name, 10) + 1{{\);$}}
+  new_name = (wchar_t*) malloc(wcsnlen_s(name + 1, 10));
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: Addition operator is applied to the argument of wcsnlen_s
+  // CHECK-FIXES: {{^  new_name = \(wchar_t\*\) malloc\(}}wcsnlen_s(name, 10) + 1{{\);$}}
+}
+
+void bad_alloca(char *name) {
+  char *new_name = (char*) alloca(strlen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: Addition operator is applied to the argument of strlen
+  // CHECK-FIXES: {{^  char \*new_name = \(char\*\) alloca\(}}strlen(name) + 1{{\);$}}
+}
+
+void bad_calloc(char *name) {
+  char *new_names = (char*) calloc(2, strlen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: Addition operator is applied to the argument of strlen
+  // CHECK-FIXES: {{^  char \*new_names = \(char\*\) calloc\(2, }}strlen(name) + 1{{\);$}}
+}
+
+void bad_realloc(char * old_name, char *name) {
+  char *new_name = (char*) realloc(old_name, strlen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: Addition operator is applied to the argument of strlen

[clang-tools-extra] r316744 - [clang-tidy ObjC] [3/3] New check objc-forbidden-subclassing

2017-10-27 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Oct 27 00:41:36 2017
New Revision: 316744

URL: http://llvm.org/viewvc/llvm-project?rev=316744&view=rev
Log:
[clang-tidy ObjC] [3/3] New check objc-forbidden-subclassing

Summary:
This is part 3 of 3 of a series of changes to improve Objective-C
linting in clang-tidy.

This adds a new clang-tidy check `objc-forbidden-subclassing` which
ensures clients do not create subclasses of Objective-C classes which
are not designed to be subclassed.

(Note that for code under your control, you should use
__attribute__((objc_subclassing_restricted)) instead -- this
is intended for third-party APIs which cannot be modified.)

By default, the following classes (which are publicly documented
as not supporting subclassing) are forbidden from subclassing:

ABNewPersonViewController
ABPeoplePickerNavigationController
ABPersonViewController
ABUnknownPersonViewController
NSHashTable
NSMapTable
NSPointerArray
NSPointerFunctions
NSTimer
UIActionSheet
UIAlertView
UIImagePickerController
UITextInputMode
UIWebView

Clients can set a CheckOption
`objc-forbidden-subclassing.ClassNames` to a semicolon-separated
list of class names, which overrides this list.

Test Plan: `ninja check-clang-tools`

Patch by Ben Hamilton!

Reviewers: hokein, alexfh

Reviewed By: hokein

Subscribers: saidinwot, Wizard, srhines, mgorny, xazax.hun

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

Added:
clang-tools-extra/trunk/clang-tidy/objc/ForbiddenSubclassingCheck.cpp
clang-tools-extra/trunk/clang-tidy/objc/ForbiddenSubclassingCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/objc-forbidden-subclassing.rst
clang-tools-extra/trunk/test/clang-tidy/objc-forbidden-subclassing-custom.m
clang-tools-extra/trunk/test/clang-tidy/objc-forbidden-subclassing.m
Modified:
clang-tools-extra/trunk/clang-tidy/objc/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/objc/ObjCTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
clang-tools-extra/trunk/unittests/clang-tidy/ObjCModuleTest.cpp

Modified: clang-tools-extra/trunk/clang-tidy/objc/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/objc/CMakeLists.txt?rev=316744&r1=316743&r2=316744&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/objc/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/objc/CMakeLists.txt Fri Oct 27 00:41:36 
2017
@@ -1,6 +1,7 @@
 set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyObjCModule
+  ForbiddenSubclassingCheck.cpp
   ObjCTidyModule.cpp
 
   LINK_LIBS

Added: clang-tools-extra/trunk/clang-tidy/objc/ForbiddenSubclassingCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/objc/ForbiddenSubclassingCheck.cpp?rev=316744&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/objc/ForbiddenSubclassingCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/objc/ForbiddenSubclassingCheck.cpp Fri 
Oct 27 00:41:36 2017
@@ -0,0 +1,118 @@
+//===--- ForbiddenSubclassingCheck.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 "ForbiddenSubclassingCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/ADT/Hashing.h"
+#include "llvm/ADT/SmallVector.h"
+#include "../utils/OptionsUtils.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace objc {
+
+namespace {
+
+constexpr char DefaultForbiddenSuperClassNames[] =
+"ABNewPersonViewController;"
+"ABPeoplePickerNavigationController;"
+"ABPersonViewController;"
+"ABUnknownPersonViewController;"
+"NSHashTable;"
+"NSMapTable;"
+"NSPointerArray;"
+"NSPointerFunctions;"
+"NSTimer;"
+"UIActionSheet;"
+"UIAlertView;"
+"UIImagePickerController;"
+"UITextInputMode;"
+"UIWebView";
+
+/// \brief Matches Objective-C classes that directly or indirectly
+/// have a superclass matching \c Base.
+///
+/// Note that a class is not considered to be a subclass of itself.
+///
+/// Example matches Y, Z
+/// (matcher = objcInterfaceDecl(hasName("X")))
+/// \code
+///   @interface X
+///   @end
+///   @interface Y : X  // directly derived
+///   @end
+///   @interface Z : Y  // indirectly derived
+///   @end
+/// \endcode
+AST_MATCHER_P(ObjCInterfaceDecl, isSubclassOf,
+  ast_matchers::internal::Matcher, Base) {
+  for (const auto *SuperClass = Node.getSuperClass();
+   SuperClass != nullptr;
+   SuperClass = SuperClass->getSuperClass()) {
+if (Base.match

[libunwind] r316745 - Express Registers_*::lastDwarfReg using _LIBUNWIND_HIGHEST_DWARF_REGISTER

2017-10-27 Thread Martin Storsjo via cfe-commits
Author: mstorsjo
Date: Fri Oct 27 00:59:01 2017
New Revision: 316745

URL: http://llvm.org/viewvc/llvm-project?rev=316745&view=rev
Log:
Express Registers_*::lastDwarfReg using _LIBUNWIND_HIGHEST_DWARF_REGISTER

This avoids having to keep the same information duplicated in multiple
places.

Adjust _LIBUNWIND_HIGHEST_DWARF_REGISTER to actually have the value
of the highest used register and only use the value
_LIBUNWIND_HIGHEST_DWARF_REGISTER + 1 (kMaxRegisterNumber + 1) for
allocating the savedRegisters array.

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

Modified:
libunwind/trunk/include/__libunwind_config.h
libunwind/trunk/src/DwarfInstructions.hpp
libunwind/trunk/src/DwarfParser.hpp
libunwind/trunk/src/Registers.hpp

Modified: libunwind/trunk/include/__libunwind_config.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/include/__libunwind_config.h?rev=316745&r1=316744&r2=316745&view=diff
==
--- libunwind/trunk/include/__libunwind_config.h (original)
+++ libunwind/trunk/include/__libunwind_config.h Fri Oct 27 00:59:01 2017
@@ -20,22 +20,22 @@
 #  define _LIBUNWIND_TARGET_I386
 #  define _LIBUNWIND_CONTEXT_SIZE 8
 #  define _LIBUNWIND_CURSOR_SIZE 19
-#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 9
+#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 8
 # elif defined(__x86_64__)
 #  define _LIBUNWIND_TARGET_X86_64 1
 #  define _LIBUNWIND_CONTEXT_SIZE 21
 #  define _LIBUNWIND_CURSOR_SIZE 33
-#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 17
+#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 16
 # elif defined(__ppc__)
 #  define _LIBUNWIND_TARGET_PPC 1
 #  define _LIBUNWIND_CONTEXT_SIZE 117
 #  define _LIBUNWIND_CURSOR_SIZE 128
-#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 113
+#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 112
 # elif defined(__aarch64__)
 #  define _LIBUNWIND_TARGET_AARCH64 1
 #  define _LIBUNWIND_CONTEXT_SIZE 66
 #  define _LIBUNWIND_CURSOR_SIZE 78
-#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 96
+#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 95
 # elif defined(__arm__)
 #  define _LIBUNWIND_TARGET_ARM 1
 #  if defined(__ARM_WMMX)
@@ -45,12 +45,12 @@
 #define _LIBUNWIND_CONTEXT_SIZE 42
 #define _LIBUNWIND_CURSOR_SIZE 49
 #  endif
-#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 96
+#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 95
 # elif defined(__or1k__)
 #  define _LIBUNWIND_TARGET_OR1K 1
 #  define _LIBUNWIND_CONTEXT_SIZE 16
 #  define _LIBUNWIND_CURSOR_SIZE 28
-#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 32
+#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 31
 # else
 #  error "Unsupported architecture."
 # endif
@@ -63,7 +63,7 @@
 # define _LIBUNWIND_TARGET_OR1K 1
 # define _LIBUNWIND_CONTEXT_SIZE 128
 # define _LIBUNWIND_CURSOR_SIZE 140
-# define _LIBUNWIND_HIGHEST_DWARF_REGISTER 120
+# define _LIBUNWIND_HIGHEST_DWARF_REGISTER 119
 #endif // _LIBUNWIND_IS_NATIVE_ONLY
 
 #endif // LIBUNWIND_CONFIG_H__

Modified: libunwind/trunk/src/DwarfInstructions.hpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/DwarfInstructions.hpp?rev=316745&r1=316744&r2=316745&view=diff
==
--- libunwind/trunk/src/DwarfInstructions.hpp (original)
+++ libunwind/trunk/src/DwarfInstructions.hpp Fri Oct 27 00:59:01 2017
@@ -167,7 +167,7 @@ int DwarfInstructions::stepWithDwa
   R newRegisters = registers;
   pint_t returnAddress = 0;
   const int lastReg = R::lastDwarfRegNum();
-  assert((int)CFI_Parser::kMaxRegisterNumber > lastReg &&
+  assert(static_cast(CFI_Parser::kMaxRegisterNumber) >= lastReg &&
  "register range too large");
   assert(lastReg >= (int)cieInfo.returnAddressRegister &&
  "register range does not contain return address register");

Modified: libunwind/trunk/src/DwarfParser.hpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/DwarfParser.hpp?rev=316745&r1=316744&r2=316745&view=diff
==
--- libunwind/trunk/src/DwarfParser.hpp (original)
+++ libunwind/trunk/src/DwarfParser.hpp Fri Oct 27 00:59:01 2017
@@ -87,7 +87,7 @@ public:
 uint32_t  codeOffsetAtStackDecrement;
 bool  registersInOtherRegisters;
 bool  sameValueUsed;
-RegisterLocation  savedRegisters[kMaxRegisterNumber];
+RegisterLocation  savedRegisters[kMaxRegisterNumber + 1];
   };
 
   struct PrologInfoStackEntry {

Modified: libunwind/trunk/src/Registers.hpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/Registers.hpp?rev=316745&r1=316744&r2=316745&view=diff
==
--- libunwind/trunk/src/Registers.hpp (original)
+++ libunwind/trunk/src/Registers.hpp Fri Oct 27 00:59:01 2017
@@ -44,7 +44,7 @@ public:
   voidsetVectorRegister(int num, v128 value);
   const char *getRegisterName(int num);

[PATCH] D39281: [libunwind] Express Registers_*::lastDwarfReg using _LIBUNWIND_HIGHEST_DWARF_REGISTER

2017-10-27 Thread Martin Storsjö via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316745: Express Registers_*::lastDwarfReg using 
_LIBUNWIND_HIGHEST_DWARF_REGISTER (authored by mstorsjo).

Changed prior to commit:
  https://reviews.llvm.org/D39281?vs=120467&id=120548#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39281

Files:
  libunwind/trunk/include/__libunwind_config.h
  libunwind/trunk/src/DwarfInstructions.hpp
  libunwind/trunk/src/DwarfParser.hpp
  libunwind/trunk/src/Registers.hpp

Index: libunwind/trunk/src/DwarfInstructions.hpp
===
--- libunwind/trunk/src/DwarfInstructions.hpp
+++ libunwind/trunk/src/DwarfInstructions.hpp
@@ -167,7 +167,7 @@
   R newRegisters = registers;
   pint_t returnAddress = 0;
   const int lastReg = R::lastDwarfRegNum();
-  assert((int)CFI_Parser::kMaxRegisterNumber > lastReg &&
+  assert(static_cast(CFI_Parser::kMaxRegisterNumber) >= lastReg &&
  "register range too large");
   assert(lastReg >= (int)cieInfo.returnAddressRegister &&
  "register range does not contain return address register");
Index: libunwind/trunk/src/DwarfParser.hpp
===
--- libunwind/trunk/src/DwarfParser.hpp
+++ libunwind/trunk/src/DwarfParser.hpp
@@ -87,7 +87,7 @@
 uint32_t  codeOffsetAtStackDecrement;
 bool  registersInOtherRegisters;
 bool  sameValueUsed;
-RegisterLocation  savedRegisters[kMaxRegisterNumber];
+RegisterLocation  savedRegisters[kMaxRegisterNumber + 1];
   };
 
   struct PrologInfoStackEntry {
Index: libunwind/trunk/src/Registers.hpp
===
--- libunwind/trunk/src/Registers.hpp
+++ libunwind/trunk/src/Registers.hpp
@@ -44,7 +44,7 @@
   voidsetVectorRegister(int num, v128 value);
   const char *getRegisterName(int num);
   voidjumpto();
-  static int  lastDwarfRegNum() { return 8; }
+  static int  lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER; }
 
   uint32_t  getSP() const  { return _registers.__esp; }
   void  setSP(uint32_t value)  { _registers.__esp = value; }
@@ -250,7 +250,7 @@
   voidsetVectorRegister(int num, v128 value);
   const char *getRegisterName(int num);
   voidjumpto();
-  static int  lastDwarfRegNum() { return 16; }
+  static int  lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER; }
 
   uint64_t  getSP() const  { return _registers.__rsp; }
   void  setSP(uint64_t value)  { _registers.__rsp = value; }
@@ -500,7 +500,7 @@
   voidsetVectorRegister(int num, v128 value);
   const char *getRegisterName(int num);
   voidjumpto();
-  static int  lastDwarfRegNum() { return 112; }
+  static int  lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER; }
 
   uint64_t  getSP() const { return _registers.__r1; }
   void  setSP(uint32_t value) { _registers.__r1 = value; }
@@ -1066,7 +1066,7 @@
   voidsetVectorRegister(int num, v128 value);
   const char *getRegisterName(int num);
   voidjumpto();
-  static int  lastDwarfRegNum() { return 95; }
+  static int  lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER; }
 
   uint64_t  getSP() const { return _registers.__sp; }
   void  setSP(uint64_t value) { _registers.__sp = value; }
@@ -1815,7 +1815,7 @@
   voidsetVectorRegister(int num, v128 value);
   const char *getRegisterName(int num);
   voidjumpto();
-  static int  lastDwarfRegNum() { return 31; }
+  static int  lastDwarfRegNum() { return _LIBUNWIND_HIGHEST_DWARF_REGISTER; }
 
   uint64_t  getSP() const { return _registers.__r[1]; }
   void  setSP(uint32_t value) { _registers.__r[1] = value; }
Index: libunwind/trunk/include/__libunwind_config.h
===
--- libunwind/trunk/include/__libunwind_config.h
+++ libunwind/trunk/include/__libunwind_config.h
@@ -20,22 +20,22 @@
 #  define _LIBUNWIND_TARGET_I386
 #  define _LIBUNWIND_CONTEXT_SIZE 8
 #  define _LIBUNWIND_CURSOR_SIZE 19
-#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 9
+#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 8
 # elif defined(__x86_64__)
 #  define _LIBUNWIND_TARGET_X86_64 1
 #  define _LIBUNWIND_CONTEXT_SIZE 21
 #  define _LIBUNWIND_CURSOR_SIZE 33
-#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 17
+#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 16
 # elif defined(__ppc__)
 #  define _LIBUNWIND_TARGET_PPC 1
 #  define _LIBUNWIND_CONTEXT_SIZE 117
 #  define _LIBUNWIND_CURSOR_SIZE 128
-#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 113
+#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 112
 # elif defined(__aarch64__)
 #  define _LIBUNWIND_TARGET_AARCH64 1
 #  define _LIBUNWIND_CONTEXT_SIZE 66
 #  define _LIBUNWIND_CURSOR_SIZE 78
-#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 96
+#  define _LIBUNWIND_HIGH

[libunwind] r316747 - Add support for dwarf unwinding on windows on x86_64

2017-10-27 Thread Martin Storsjo via cfe-commits
Author: mstorsjo
Date: Fri Oct 27 01:11:36 2017
New Revision: 316747

URL: http://llvm.org/viewvc/llvm-project?rev=316747&view=rev
Log:
Add support for dwarf unwinding on windows on x86_64

Clang doesn't currently support building for windows/x86_64 with
dwarf by setting command line parameters, but if manually modified
to use dwarf, we can make libunwind work in this configuration
as well.

Also include i386 in the docs when adding this as a supported
configuration; libunwind already works for i386 windows, but
can fail due to an issue unrelated to windows itself.

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

Modified:
libunwind/trunk/docs/index.rst
libunwind/trunk/include/__libunwind_config.h
libunwind/trunk/include/libunwind.h
libunwind/trunk/include/unwind.h
libunwind/trunk/src/AddressSpace.hpp
libunwind/trunk/src/Registers.hpp
libunwind/trunk/src/UnwindLevel1.c
libunwind/trunk/src/UnwindRegistersRestore.S
libunwind/trunk/src/UnwindRegistersSave.S

Modified: libunwind/trunk/docs/index.rst
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/docs/index.rst?rev=316747&r1=316746&r2=316747&view=diff
==
--- libunwind/trunk/docs/index.rst (original)
+++ libunwind/trunk/docs/index.rst Fri Oct 27 01:11:36 2017
@@ -52,6 +52,7 @@ LinuxARM  Clang,
 Linuxi386, x86_64, ARM64  Clang, GCC   DWARF CFI
 Mac OS X i386, x86_64 Clang, GCC   DWARF CFI
 NetBSD   x86_64   Clang, GCC   DWARF CFI
+Windows  i386, x86_64 ClangDWARF CFI
    
 
 The following minimum compiler versions are strongly recommended.

Modified: libunwind/trunk/include/__libunwind_config.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/include/__libunwind_config.h?rev=316747&r1=316746&r2=316747&view=diff
==
--- libunwind/trunk/include/__libunwind_config.h (original)
+++ libunwind/trunk/include/__libunwind_config.h Fri Oct 27 01:11:36 2017
@@ -23,9 +23,15 @@
 #  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 8
 # elif defined(__x86_64__)
 #  define _LIBUNWIND_TARGET_X86_64 1
-#  define _LIBUNWIND_CONTEXT_SIZE 21
-#  define _LIBUNWIND_CURSOR_SIZE 33
-#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 16
+#  if defined(_WIN64)
+#define _LIBUNWIND_CONTEXT_SIZE 54
+#define _LIBUNWIND_CURSOR_SIZE 66
+#define _LIBUNWIND_HIGHEST_DWARF_REGISTER 32
+#  else
+#define _LIBUNWIND_CONTEXT_SIZE 21
+#define _LIBUNWIND_CURSOR_SIZE 33
+#define _LIBUNWIND_HIGHEST_DWARF_REGISTER 16
+#  endif
 # elif defined(__ppc__)
 #  define _LIBUNWIND_TARGET_PPC 1
 #  define _LIBUNWIND_CONTEXT_SIZE 117

Modified: libunwind/trunk/include/libunwind.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/include/libunwind.h?rev=316747&r1=316746&r2=316747&view=diff
==
--- libunwind/trunk/include/libunwind.h (original)
+++ libunwind/trunk/include/libunwind.h Fri Oct 27 01:11:36 2017
@@ -188,7 +188,24 @@ enum {
   UNW_X86_64_R12 = 12,
   UNW_X86_64_R13 = 13,
   UNW_X86_64_R14 = 14,
-  UNW_X86_64_R15 = 15
+  UNW_X86_64_R15 = 15,
+  UNW_X86_64_RIP = 16,
+  UNW_X86_64_XMM0 = 17,
+  UNW_X86_64_XMM1 = 18,
+  UNW_X86_64_XMM2 = 19,
+  UNW_X86_64_XMM3 = 20,
+  UNW_X86_64_XMM4 = 21,
+  UNW_X86_64_XMM5 = 22,
+  UNW_X86_64_XMM6 = 23,
+  UNW_X86_64_XMM7 = 24,
+  UNW_X86_64_XMM8 = 25,
+  UNW_X86_64_XMM9 = 26,
+  UNW_X86_64_XMM10 = 27,
+  UNW_X86_64_XMM11 = 28,
+  UNW_X86_64_XMM12 = 29,
+  UNW_X86_64_XMM13 = 30,
+  UNW_X86_64_XMM14 = 31,
+  UNW_X86_64_XMM15 = 32,
 };
 
 

Modified: libunwind/trunk/include/unwind.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/include/unwind.h?rev=316747&r1=316746&r2=316747&view=diff
==
--- libunwind/trunk/include/unwind.h (original)
+++ libunwind/trunk/include/unwind.h Fri Oct 27 01:11:36 2017
@@ -122,7 +122,7 @@ struct _Unwind_Exception {
 _Unwind_Exception *exc);
   uintptr_t private_1; // non-zero means forced unwind
   uintptr_t private_2; // holds sp that phase1 found for phase2 to use
-#ifndef __LP64__
+#if __SIZEOF_POINTER__ == 4
   // The implementation of _Unwind_Exception uses an attribute mode on the
   // above fields which has the side effect of causing this whole struct to
   // round up to 32 bytes in size. To be more explicit, we add pad fields

Modified: libunwind/trunk/src/AddressSpace.hpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/AddressSpace.hpp?rev=316747&r1=316746&r2=316747&view=diff
==
--- libunwind/trunk/src/AddressSpace.hpp (original)
+++ libunwind/trunk/src/AddressSpace.hpp Fri Oct 27 01:11:36 20

[PATCH] D38819: [libunwind] Add support for dwarf unwinding on windows on x86_64

2017-10-27 Thread Martin Storsjö via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316747: Add support for dwarf unwinding on windows on x86_64 
(authored by mstorsjo).

Changed prior to commit:
  https://reviews.llvm.org/D38819?vs=120380&id=120552#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38819

Files:
  libunwind/trunk/docs/index.rst
  libunwind/trunk/include/__libunwind_config.h
  libunwind/trunk/include/libunwind.h
  libunwind/trunk/include/unwind.h
  libunwind/trunk/src/AddressSpace.hpp
  libunwind/trunk/src/Registers.hpp
  libunwind/trunk/src/UnwindLevel1.c
  libunwind/trunk/src/UnwindRegistersRestore.S
  libunwind/trunk/src/UnwindRegistersSave.S

Index: libunwind/trunk/docs/index.rst
===
--- libunwind/trunk/docs/index.rst
+++ libunwind/trunk/docs/index.rst
@@ -52,6 +52,7 @@
 Linuxi386, x86_64, ARM64  Clang, GCC   DWARF CFI
 Mac OS X i386, x86_64 Clang, GCC   DWARF CFI
 NetBSD   x86_64   Clang, GCC   DWARF CFI
+Windows  i386, x86_64 ClangDWARF CFI
    
 
 The following minimum compiler versions are strongly recommended.
Index: libunwind/trunk/src/UnwindLevel1.c
===
--- libunwind/trunk/src/UnwindLevel1.c
+++ libunwind/trunk/src/UnwindLevel1.c
@@ -86,7 +86,7 @@
 // this frame.
 if (frameInfo.handler != 0) {
   __personality_routine p =
-  (__personality_routine)(long)(frameInfo.handler);
+  (__personality_routine)(uintptr_t)(frameInfo.handler);
   _LIBUNWIND_TRACE_UNWINDING(
   "unwind_phase1(ex_ojb=%p): calling personality function %p",
   (void *)exception_object, (void *)(uintptr_t)p);
@@ -181,7 +181,7 @@
 // If there is a personality routine, tell it we are unwinding.
 if (frameInfo.handler != 0) {
   __personality_routine p =
-  (__personality_routine)(long)(frameInfo.handler);
+  (__personality_routine)(uintptr_t)(frameInfo.handler);
   _Unwind_Action action = _UA_CLEANUP_PHASE;
   if (sp == exception_object->private_2) {
 // Tell personality this was the frame it marked in phase 1.
Index: libunwind/trunk/src/Registers.hpp
===
--- libunwind/trunk/src/Registers.hpp
+++ libunwind/trunk/src/Registers.hpp
@@ -245,7 +245,7 @@
   boolvalidFloatRegister(int) const { return false; }
   double  getFloatRegister(int num) const;
   voidsetFloatRegister(int num, double value);
-  boolvalidVectorRegister(int) const { return false; }
+  boolvalidVectorRegister(int) const;
   v128getVectorRegister(int num) const;
   voidsetVectorRegister(int num, v128 value);
   const char *getRegisterName(int num);
@@ -292,8 +292,14 @@
 uint64_t __cs;
 uint64_t __fs;
 uint64_t __gs;
+#if defined(_WIN64)
+uint64_t __padding; // 16-byte align
+#endif
   };
   GPRs _registers;
+#if defined(_WIN64)
+  v128 _xmm[16];
+#endif
 };
 
 inline Registers_x86_64::Registers_x86_64(const void *registers) {
@@ -458,6 +464,38 @@
 return "r14";
   case UNW_X86_64_R15:
 return "r15";
+  case UNW_X86_64_XMM0:
+return "xmm0";
+  case UNW_X86_64_XMM1:
+return "xmm1";
+  case UNW_X86_64_XMM2:
+return "xmm2";
+  case UNW_X86_64_XMM3:
+return "xmm3";
+  case UNW_X86_64_XMM4:
+return "xmm4";
+  case UNW_X86_64_XMM5:
+return "xmm5";
+  case UNW_X86_64_XMM6:
+return "xmm6";
+  case UNW_X86_64_XMM7:
+return "xmm7";
+  case UNW_X86_64_XMM8:
+return "xmm8";
+  case UNW_X86_64_XMM9:
+return "xmm9";
+  case UNW_X86_64_XMM10:
+return "xmm10";
+  case UNW_X86_64_XMM11:
+return "xmm11";
+  case UNW_X86_64_XMM12:
+return "xmm12";
+  case UNW_X86_64_XMM13:
+return "xmm13";
+  case UNW_X86_64_XMM14:
+return "xmm14";
+  case UNW_X86_64_XMM15:
+return "xmm15";
   default:
 return "unknown register";
   }
@@ -471,12 +509,34 @@
   _LIBUNWIND_ABORT("no x86_64 float registers");
 }
 
-inline v128 Registers_x86_64::getVectorRegister(int) const {
+inline bool Registers_x86_64::validVectorRegister(int regNum) const {
+#if defined(_WIN64)
+  if (regNum < UNW_X86_64_XMM0)
+return false;
+  if (regNum > UNW_X86_64_XMM15)
+return false;
+  return true;
+#else
+  return false;
+#endif
+}
+
+inline v128 Registers_x86_64::getVectorRegister(int regNum) const {
+#if defined(_WIN64)
+  assert(validVectorRegister(regNum));
+  return _xmm[regNum - UNW_X86_64_XMM0];
+#else
   _LIBUNWIND_ABORT("no x86_64 vector registers");
+#endif
 }
 
-inline void Registers_x86_64::setVectorRegister(int, v128) {
+inline void Registers_x86_64::setVectorRegister(int regNum, v128 value) {
+#if defined(_WIN64)
+  assert(validVectorRegister(regNum));
+  _xmm[regNum - UNW_X86_64_XMM0] = value;
+#else
   _LIBUNWIND_ABORT("no x86_64 vecto

[PATCH] D39360: [C++11] Don't put empty quotes in static_assert diagnostic.

2017-10-27 Thread Nicolas Lesser via Phabricator via cfe-commits
Rakete abandoned this revision.
Rakete added a comment.

@kimgr Well, mostly because they bother me a bit, don't know what others think 
though. I just thought it would be nice if they didn't appear, mainly because 
there is no need to show empty quotes in the error message. Hmm, you have a 
point though... Didn't think of that. Thanks +1


https://reviews.llvm.org/D39360



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


[PATCH] D39331: Add flags to control the -finstrument-functions instrumentation calls to __cyg_profile functions

2017-10-27 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

The request for -fno-cygprofile-args was from another user. You raise a good 
point, it sounds like mcount() might be perfect for them :-)


https://reviews.llvm.org/D39331



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


[PATCH] D39280: [libunwind] Use uint64_t for unw_word_t in ARM EHABI

2017-10-27 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In https://reviews.llvm.org/D39280#908825, @compnerd wrote:

> I dont think that this is correct.  IIRC, the unwind specification expects 
> `unw_word_t` to match `uintptr_t` (that is, it should be 32-bits on 
> https://reviews.llvm.org/P32 environments).


I checked with GNU libunwind, and that seems to be true there. Updating our 
libunwind to match that doesn't seem to be too hard.


https://reviews.llvm.org/D39280



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


[PATCH] D39365: [libunwind] Change unw_word_t to always have the same size as the pointer size

2017-10-27 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.
Herald added subscribers: kristof.beyls, aemerson.

This matches the original libunwind API. This also unifies the type between ARM 
EHABI and the other configurations, and allows getting rid of a number of casts 
in log messages.

The cursor size updates for ppc and or1k are untested, but unw_proc_info_t 
shrinks by 4 uint64_t units on 32 bit platforms.


https://reviews.llvm.org/D39365

Files:
  include/__libunwind_config.h
  include/libunwind.h
  src/Unwind-EHABI.cpp
  src/UnwindLevel1-gcc-ext.c
  src/UnwindLevel1.c
  src/libunwind.cpp

Index: src/libunwind.cpp
===
--- src/libunwind.cpp
+++ src/libunwind.cpp
@@ -174,8 +174,8 @@
 /// Set value of specified register at cursor position in stack frame.
 _LIBUNWIND_EXPORT int unw_set_reg(unw_cursor_t *cursor, unw_regnum_t regNum,
   unw_word_t value) {
-  _LIBUNWIND_TRACE_API("unw_set_reg(cursor=%p, regNum=%d, value=0x%llX)",
-   static_cast(cursor), regNum, (long long)value);
+  _LIBUNWIND_TRACE_API("unw_set_reg(cursor=%p, regNum=%d, value=0x%" PRIXPTR ")",
+   static_cast(cursor), regNum, value);
   typedef LocalAddressSpace::pint_t pint_t;
   AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
   if (co->validReg(regNum)) {
Index: src/UnwindLevel1.c
===
--- src/UnwindLevel1.c
+++ src/UnwindLevel1.c
@@ -76,8 +76,8 @@
   unw_word_t pc;
   unw_get_reg(cursor, UNW_REG_IP, &pc);
   _LIBUNWIND_TRACE_UNWINDING(
-  "unwind_phase1(ex_ojb=%p): pc=0x%" PRIx64 ", start_ip=0x%" PRIx64
-  ", func=%s, lsda=0x%" PRIx64 ", personality=0x%" PRIx64 "",
+  "unwind_phase1(ex_ojb=%p): pc=0x%" PRIxPTR ", start_ip=0x%" PRIxPTR
+  ", func=%s, lsda=0x%" PRIxPTR ", personality=0x%" PRIxPTR "",
   (void *)exception_object, pc, frameInfo.start_ip, functionName,
   frameInfo.lsda, frameInfo.handler);
 }
@@ -170,9 +170,9 @@
  &offset) != UNW_ESUCCESS) ||
   (frameInfo.start_ip + offset > frameInfo.end_ip))
 functionName = ".anonymous.";
-  _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p): start_ip=0x%" PRIx64
- ", func=%s, sp=0x%" PRIx64 ", lsda=0x%" PRIx64
- ", personality=0x%" PRIx64,
+  _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p): start_ip=0x%" PRIxPTR
+ ", func=%s, sp=0x%" PRIxPTR ", lsda=0x%" PRIxPTR
+ ", personality=0x%" PRIxPTR,
  (void *)exception_object, frameInfo.start_ip,
  functionName, sp, frameInfo.lsda,
  frameInfo.handler);
@@ -213,8 +213,8 @@
   unw_get_reg(cursor, UNW_REG_IP, &pc);
   unw_get_reg(cursor, UNW_REG_SP, &sp);
   _LIBUNWIND_TRACE_UNWINDING("unwind_phase2(ex_ojb=%p): re-entering "
- "user code with ip=0x%" PRIx64
- ", sp=0x%" PRIx64,
+ "user code with ip=0x%" PRIxPTR
+ ", sp=0x%" PRIxPTR,
  (void *)exception_object, pc, sp);
 }
 unw_resume(cursor);
@@ -262,8 +262,8 @@
   (frameInfo.start_ip + offset > frameInfo.end_ip))
 functionName = ".anonymous.";
   _LIBUNWIND_TRACE_UNWINDING(
-  "unwind_phase2_forced(ex_ojb=%p): start_ip=0x%" PRIx64
-  ", func=%s, lsda=0x%" PRIx64 ", personality=0x%" PRIx64,
+  "unwind_phase2_forced(ex_ojb=%p): start_ip=0x%" PRIxPTR
+  ", func=%s, lsda=0x%" PRIxPTR ", personality=0x%" PRIxPTR,
   (void *)exception_object, frameInfo.start_ip, functionName,
   frameInfo.lsda, frameInfo.handler);
 }
@@ -467,17 +467,17 @@
   unw_cursor_t *cursor = (unw_cursor_t *)context;
   unw_word_t result;
   unw_get_reg(cursor, index, &result);
-  _LIBUNWIND_TRACE_API("_Unwind_GetGR(context=%p, reg=%d) => 0x%" PRIx64,
-   (void *)context, index, (uint64_t)result);
+  _LIBUNWIND_TRACE_API("_Unwind_GetGR(context=%p, reg=%d) => 0x%" PRIxPTR,
+   (void *)context, index, result);
   return (uintptr_t)result;
 }
 
 /// Called by personality handler during phase 2 to alter register values.
 _LIBUNWIND_EXPORT void _Unwind_SetGR(struct _Unwind_Context *context, int index,
  uintptr_t value) {
-  _LIBUNWIND_TRACE_API("_Unwind_SetGR(context=%p, reg=%d, value=0x%0" PRIx64
+  _LIBUNWIND_TRACE_API("_Unwind_SetGR(context=%p, reg=%d, value=0x%0" PRIxPTR
")",
-   (void *)context, index, (uint64_t)value);
+   (void *)context, index, value);
   unw_cursor_t *cursor 

[PATCH] D39366: [ASTMatchers] Matchers for new[] operators

2017-10-27 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware created this revision.
Herald added a subscriber: rnkovacs.

Two new matchers for ``CXXNewExpr`` are added which may be useful e.g. in 
clang-tidy checkers. One of them is ``isArrayForm`` which matches ``new[]`` but 
not plain ``new`. The other one, ``hasArraySize`` matches ``new[]`` for a given 
size.


https://reviews.llvm.org/D39366

Files:
  docs/LibASTMatchersReference.html
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -1983,5 +1983,15 @@
   namedDecl(hasExternalFormalLinkage(;
 }
 
+TEST(IsArray, Basic) {
+  EXPECT_TRUE(matches("struct MyClass {}; MyClass *p1 = new MyClass[10];",
+  cxxNewExpr(isArrayForm(;
+}
+
+TEST(HasArraySize, Basic) {
+  EXPECT_TRUE(matches("struct MyClass {}; MyClass *p1 = new MyClass[10];",
+  cxxNewExpr(hasArraySize(integerLiteral(equals(10));
+}
+
 } // namespace ast_matchers
 } // namespace clang
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -220,6 +220,7 @@
   REGISTER_MATCHER(hasAnyUsingShadowDecl);
   REGISTER_MATCHER(hasArgument);
   REGISTER_MATCHER(hasArgumentOfType);
+  REGISTER_MATCHER(hasArraySize);
   REGISTER_MATCHER(hasAttr);
   REGISTER_MATCHER(hasAutomaticStorageDuration);
   REGISTER_MATCHER(hasBase);
@@ -302,6 +303,7 @@
   REGISTER_MATCHER(isAnonymous);
   REGISTER_MATCHER(isAnyCharacter);
   REGISTER_MATCHER(isAnyPointer);
+  REGISTER_MATCHER(isArrayForm);
   REGISTER_MATCHER(isArrow);
   REGISTER_MATCHER(isBaseInitializer);
   REGISTER_MATCHER(isBitField);
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -5761,6 +5761,31 @@
   return Node.hasExternalFormalLinkage();
 }
 
+/// \brief Matches array new expressions.
+///
+/// Given:
+/// \code
+///   MyClass *p1 = new MyClass[10];
+/// \endcode
+/// cxxNewExpr(isArrayForm())
+///   matches the expression 'new MyClass[10]'.
+AST_MATCHER(CXXNewExpr, isArrayForm) {
+  return Node.isArray();
+}
+
+/// \brief Matches array new expressions with a given array size.
+///
+/// Given:
+/// \code
+///   MyClass *p1 = new MyClass[10];
+/// \endcode
+/// cxxNewExpr(hasArraySize(intgerLiteral(equals(10
+///   matches the expression 'new MyClass[10]'.
+AST_MATCHER_P(CXXNewExpr, hasArraySize, internal::Matcher, InnerMatcher) {
+  return Node.isArray() &&
+InnerMatcher.matches(*Node.getArraySize(), Finder, Builder);
+}
+
 } // end namespace ast_matchers
 } // end namespace clang
 
Index: docs/LibASTMatchersReference.html
===
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html
@@ -2232,6 +2232,16 @@
 
 
 
+MatcherCXXNewExpr>isArrayForm
+Matches array new expressions.
+
+Given:
+  MyClass *p1 = new MyClass[10];
+cxxNewExpr(isArrayForm())
+  matches the expression 'new MyClass[10]'.
+
+
+
 MatcherCXXOperatorCallExpr>hasOverloadedOperatorNameStringRef Name
 Matches overloaded operator names.
 
@@ -4380,6 +4390,16 @@
 
 
 
+MatcherCXXNewExpr>hasArraySizeMatcherExpr> InnerMatcher
+Matches array new expressions with a given array size.
+
+Given:
+  MyClass *p1 = new MyClass[10];
+cxxNewExpr(hasArraySize(intgerLiteral(equals(10
+  matches the expression 'new MyClass[10]'.
+
+
+
 MatcherCXXNewExpr>hasDeclarationMatcherDecl>  InnerMatcher
 Matches a node if the declaration associated with that node
 matches the given matcher.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39367: [clang-tidy] Add support for operator new[] in check bugprone-misplaced-operator-in-strlen-in-alloc

2017-10-27 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware created this revision.
Herald added a subscriber: rnkovacs.

The check now recognizes error cases like `new char[strlen(s + 1)]` and 
suggests a fix in the format `new char[strlen(s) + 1]`.


https://reviews.llvm.org/D39367

Files:
  clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
  test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp

Index: test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp
===
--- test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp
+++ test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp
@@ -29,3 +29,9 @@
   char *new_name = (char*) std::malloc(non_std::strlen(name + 1));
   // Ignore functions of the strlen family in custom namespaces
 }
+
+void bad_new_strlen(char *name) {
+  char *new_name = new char[std::strlen(name + 1)];
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: Addition operator is applied to the argument of strlen
+  // CHECK-FIXES: {{^  char \*new_name = new char\[}}std::strlen(name) + 1{{\];$}}
+}
Index: docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
===
--- docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
+++ docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
@@ -7,11 +7,12 @@
 ``strnlen()``, ``strnlen_s()``, ``wcslen()``, ``wcsnlen()`` and ``wcsnlen_s()``
 functions instead of to the result and use its return value as an argument of a
 memory allocation function (``malloc()``, ``calloc()``, ``realloc()``,
-``alloca()``). Cases where ``1`` is added both to the parameter and the result
-of the ``strlen()``-like function are ignored, as are cases where the whole
-addition is surrounded by extra parentheses.
+``alloca()``) or the ``new[]`` operator in `C++`. Cases where ``1`` is added
+both to the parameter and the result of the ``strlen()``-like function are
+ignored, as are cases where the whole addition is surrounded by extra
+parentheses.
 
-Example code:
+`C` example code:
 
 .. code-block:: c
 
@@ -28,6 +29,24 @@
   char *c = (char*) malloc(strlen(str) + 1);
 
 
+`C++` example code:
+
+.. code-block:: c++
+
+void bad_new(char *str) {
+  char *c = new char[strlen(str + 1)];
+}
+
+
+As in the `C` code with the ``malloc()`` function, the suggested fix is to
+add ``1`` to the return value of ``strlen()`` and not to its argument. In the
+example above the fix would be
+
+.. code-block:: c++
+
+  char *c = new char[strlen(str) + 1];
+
+
 Example for silencing the bug report:
 
 .. code-block:: c
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -64,7 +64,7 @@
   ``strlen()``, ``strnlen()``, ``strnlen_s()``, ``wcslen()``, ``wcsnlen()`` and
   ``wcsnlen_s()`` functions instead of to the result and use its return value as
   an argument of a memory allocation function (``malloc()``, ``calloc()``,
-  ``realloc()``, ``alloca()``).
+  ``realloc()``, ``alloca()``) or the ``new[]`` operator in `C++`.
 
 - Renamed checks to use correct term "implicit conversion" instead of "implicit
   cast" and modified messages and option names accordingly:
Index: clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
===
--- clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
+++ clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
@@ -48,26 +48,28 @@
   const auto Alloc1Func =
   functionDecl(anyOf(hasName("::calloc"), hasName("std::calloc"),
  hasName("::realloc"), hasName("std::realloc")));
-
   Finder->addMatcher(
   callExpr(callee(Alloc0Func), hasArgument(0, BadArg)).bind("Alloc"), this);
   Finder->addMatcher(
   callExpr(callee(Alloc1Func), hasArgument(1, BadArg)).bind("Alloc"), this);
+  Finder->addMatcher(
+  cxxNewExpr(isArrayForm(), hasArraySize(BadArg)).bind("Alloc"), this);
 }
 
 void MisplacedOperatorInStrlenInAllocCheck::check(
 const MatchFinder::MatchResult &Result) {
-  const auto *Alloc = Result.Nodes.getNodeAs("Alloc");
+  const Expr *Alloc = Result.Nodes.getNodeAs("Alloc");
+  if (!Alloc) Alloc = Result.Nodes.getNodeAs("Alloc");
   const auto *StrLen = Result.Nodes.getNodeAs("StrLen");
   const auto *BinOp = Result.Nodes.getNodeAs("BinOp");
 
   const StringRef StrLenText = Lexer::getSourceText(
   CharSourceRange::getTokenRange(StrLen->getSourceRange()),
   *Result.SourceManager, getLangOpts());
-  const StringRef StrLenBegin = StrLenText.substr(0, StrLenText.find('(') + 1);
   const StringRef Arg0Text = Lexer::getSourceText(
   CharSourceRange::getTokenRange(StrLen->getArg(0)->getSourceRange()),
   *Result.SourceManag

[PATCH] D39332: [clang-refactor] Introduce "local-qualified-rename" action.

2017-10-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Implementation LG.

My questions are mostly framework-level:

- should this be an Action, or just a Rule under the existing rename Action?
- {qname vs selection} x {local vs global} x ... seems like a combinatorial 
explosion in the number of rules. Shouldn't concerns like format of the input 
be taken care of before we get to the Rule?

@arphaman




Comment at: lib/Tooling/Refactoring/Rename/RenamingAction.cpp:143
+}
+auto USRs = getUSRsForDeclaration(ND, Context.getASTContext());
+return tooling::createRenameAtomicChanges(

if this is a local refactor, and there are no USRs (symbol doesn't exist), is 
this an error that needs to be signaled somehow?



Comment at: lib/Tooling/Refactoring/Rename/RenamingAction.cpp:154
+
+class LocalQualifiedRename final : public RefactoringAction {
+public:

As discussed offline, it's not clear why this is a separate Action, rather than 
a different Rule that's part of the same Action.

@arphaman how does the framework answer this question?


https://reviews.llvm.org/D39332



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


[PATCH] D38985: [refactor] Add support for editor commands that connect IDEs/editors to the refactoring actions

2017-10-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

This looks great!
Thanks for bearing with me.




Comment at: include/clang/Tooling/Refactoring/RefactoringActionRule.h:31
+  /// A human readable title for the refactoring.
+  StringRef Title;
+};

nit: I think the RefactoringDescriptor literals are easier to understand if 
Title comes before Description, so they're terse --> verbose.

But totally up to you.



Comment at: lib/Tooling/Refactoring/Rename/RenamingAction.cpp:66
+  "local-rename",
+  "Finds and renames symbols in code with no indexer support", "Rename"};
+  return Descriptor;

nit: please wrap before the title.

You can hint clang-format to wrap one-per-line by including a trailing comma in 
the init-list.


Repository:
  rL LLVM

https://reviews.llvm.org/D38985



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


[PATCH] D39332: [clang-refactor] Introduce "local-qualified-rename" action.

2017-10-27 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: lib/Tooling/Refactoring/Rename/RenamingAction.cpp:143
+}
+auto USRs = getUSRsForDeclaration(ND, Context.getASTContext());
+return tooling::createRenameAtomicChanges(

sammccall wrote:
> if this is a local refactor, and there are no USRs (symbol doesn't exist), is 
> this an error that needs to be signaled somehow?
This case should not be happened IMO. If we find the `ND`, we will rename `ND` 
at least.



Comment at: lib/Tooling/Refactoring/Rename/RenamingAction.cpp:154
+
+class LocalQualifiedRename final : public RefactoringAction {
+public:

sammccall wrote:
> As discussed offline, it's not clear why this is a separate Action, rather 
> than a different Rule that's part of the same Action.
> 
> @arphaman how does the framework answer this question?
There is a 
[document](https://clang.llvm.org/docs/RefactoringEngine.html#refactoring-action-rules)
 describing it, but still ambiguous.

We also had some questions about `local-rename` from the discussion, need 
@arphaman's input:

* `OccurrenceFinder` is not exposed now, it is merely used in 
`RenameOccurrences`. We think there should be a public interface to the 
clients, like for implementing interactive mode in IDE? 
* Currently the rules defined in the same action must have mutual command-line 
options, otherwise clang-refactor would complain the command-line option are 
being registered more than once. It might be very strict for some cases. For 
example, `-new-name` is most likely being used by many rules in `local-rename` 
action.
 


https://reviews.llvm.org/D39332



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


[PATCH] D39290: [rename] Use SymbolOccurrence in RenameLocFinder.

2017-10-27 Thread Haojian Wu via Phabricator via cfe-commits
hokein abandoned this revision.
hokein added inline comments.



Comment at: include/clang/Tooling/Refactoring/Rename/SymbolOccurrences.h:74
+// The declaration in which the nested name is contained (can be nullptr).
+const Decl *Context;
+// The nested name being replaced (can be nullptr).

ioeric wrote:
> A `SymbolOccurrence` is likely to out-live an AST (e.g. when used in 
> clang-refactor or serialized to files), so it might not be safe to store 
> references to ASTs here. If we really want AST information in the 
> `SymbolOccurrence`, we could probably derive from it and use only internally. 
> But it doesn't make sense to pass AST references out to users.
Yeah, right. It is not a good idea to add AST information in the 
SymbolOccurrence as it is out range of `Rule`. On the second thought, we don't 
need to add this information. Let's close this revision.


https://reviews.llvm.org/D39290



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


[PATCH] D39332: [clang-refactor] Introduce "local-qualified-rename" action.

2017-10-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: lib/Tooling/Refactoring/Rename/RenamingAction.cpp:143
+}
+auto USRs = getUSRsForDeclaration(ND, Context.getASTContext());
+return tooling::createRenameAtomicChanges(

hokein wrote:
> sammccall wrote:
> > if this is a local refactor, and there are no USRs (symbol doesn't exist), 
> > is this an error that needs to be signaled somehow?
> This case should not be happened IMO. If we find the `ND`, we will rename 
> `ND` at least.
Oops, of course. Maybe an assert?


https://reviews.llvm.org/D39332



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


[PATCH] D38985: [refactor] Add support for editor commands that connect IDEs/editors to the refactoring actions

2017-10-27 Thread Eric Liu via Phabricator via cfe-commits
ioeric accepted this revision.
ioeric added a comment.

lg




Comment at: include/clang/Tooling/Refactoring/RefactoringActionRule.h:48
+
+  // static const RefactoringDescriptor &describe() = 0;
 };

A comment would be nice here.



Comment at: lib/Tooling/Refactoring/RefactoringActions.cpp:28
+
+// FIXME: Remove the Actions alltogether.
+class ExtractRefactoring final : public RefactoringAction {

Maybe I'm missing the context here... Why do we want to remove the actions?


Repository:
  rL LLVM

https://reviews.llvm.org/D38985



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


[PATCH] D39367: [clang-tidy] Add support for operator new[] in check bugprone-misplaced-operator-in-strlen-in-alloc

2017-10-27 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp:62
+  const Expr *Alloc = Result.Nodes.getNodeAs("Alloc");
+  if (!Alloc) Alloc = Result.Nodes.getNodeAs("Alloc");
   const auto *StrLen = Result.Nodes.getNodeAs("StrLen");

Break after if condition. You could use the ternary operator, too.

Maybe a safeguard assertion if `Alloc` is nullptr after the second assignemt. 
This would uncover a potential bug.


Repository:
  rL LLVM

https://reviews.llvm.org/D39367



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


[PATCH] D39367: [clang-tidy] Add support for operator new[] in check bugprone-misplaced-operator-in-strlen-in-alloc

2017-10-27 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

Should the release notes be modified as well?


Repository:
  rL LLVM

https://reviews.llvm.org/D39367



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


r316758 - Test commit

2017-10-27 Thread Ivan Donchevskii via cfe-commits
Author: yvvan
Date: Fri Oct 27 04:05:40 2017
New Revision: 316758

URL: http://llvm.org/viewvc/llvm-project?rev=316758&view=rev
Log:
Test commit

Modified:
cfe/trunk/lib/Sema/SemaCodeComplete.cpp

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=316758&r1=316757&r2=316758&view=diff
==
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Fri Oct 27 04:05:40 2017
@@ -47,7 +47,7 @@ namespace {
 /// the result set (when it returns true) and which declarations should be
 /// filtered out (returns false).
 typedef bool (ResultBuilder::*LookupFilter)(const NamedDecl *) const;
-
+
 typedef CodeCompletionResult Result;
 
   private:


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


[PATCH] D39366: [ASTMatchers] Matchers for new[] operators

2017-10-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: include/clang/ASTMatchers/ASTMatchers.h:5772
+///   matches the expression 'new MyClass[10]'.
+AST_MATCHER(CXXNewExpr, isArrayForm) {
+  return Node.isArray();

We typically try to match the AST method names with the matcher names when 
possible, so this should be named `isArray()`.


https://reviews.llvm.org/D39366



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


[PATCH] D37299: [Modules] Add ability to specify module name to module file mapping in a file

2017-10-27 Thread Boris Kolpackov via Phabricator via cfe-commits
boris added a comment.

Ping.


https://reviews.llvm.org/D37299



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


[PATCH] D38842: [CrossTU] Fix handling of Cross Translation Unit directory path

2017-10-27 Thread Peter Szecsi via Phabricator via cfe-commits
szepet added a comment.

LGTM as well, but same note applies.


https://reviews.llvm.org/D38842



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


[PATCH] D39332: [clang-refactor] Introduce "local-qualified-rename" action.

2017-10-27 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 120575.
hokein added a comment.

Add an assert for non-empty USRs.


https://reviews.llvm.org/D39332

Files:
  include/clang/Tooling/Refactoring/RefactoringActionRegistry.def
  lib/Tooling/Refactoring/Rename/RenamingAction.cpp
  test/Refactor/LocalQualifiedRename/QualifiedRename.cpp
  tools/clang-refactor/ClangRefactor.cpp

Index: tools/clang-refactor/ClangRefactor.cpp
===
--- tools/clang-refactor/ClangRefactor.cpp
+++ tools/clang-refactor/ClangRefactor.cpp
@@ -500,8 +500,6 @@
   auto InvokeRule = [&](RefactoringResultConsumer &Consumer) {
 logInvocation(Subcommand, Context);
 for (RefactoringActionRule *Rule : MatchingRules) {
-  if (!Rule->hasSelectionRequirement())
-continue;
   Rule->invoke(Consumer, Context);
   return;
 }
@@ -529,6 +527,8 @@
   HasFailed = true;
 ActiveConsumer.endTU();
 return;
+  } else {
+InvokeRule(ActiveConsumer);
   }
   // FIXME (Alex L): Implement non-selection based invocation path.
   ActiveConsumer.endTU();
Index: test/Refactor/LocalQualifiedRename/QualifiedRename.cpp
===
--- /dev/null
+++ test/Refactor/LocalQualifiedRename/QualifiedRename.cpp
@@ -0,0 +1,24 @@
+// RUN: clang-refactor local-qualified-rename -old-qualified-name="foo::A" -new-name="bar::B" %s -- -std=c++11 2>&1 | grep -v CHECK | FileCheck %s
+
+namespace foo {
+class A {};
+}
+// CHECK: namespace foo {
+// CHECK-NEXT: class B {};
+// CHECK-NEXT: }
+
+namespace bar {
+void f(foo::A* a) {
+  foo::A b;
+}
+// CHECK: void f(B* a) {
+// CHECK-NEXT:   B b;
+// CHECK-NEXT: }
+}
+
+void f(foo::A* a) {
+  foo::A b;
+}
+// CHECK: void f(bar::B* a) {
+// CHECK-NEXT:   bar::B b;
+// CHECK-NEXT: }
Index: lib/Tooling/Refactoring/Rename/RenamingAction.cpp
===
--- lib/Tooling/Refactoring/Rename/RenamingAction.cpp
+++ lib/Tooling/Refactoring/Rename/RenamingAction.cpp
@@ -31,6 +31,8 @@
 #include "clang/Tooling/Refactoring/Rename/USRLocFinder.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/Errc.h"
+#include "llvm/Support/Error.h"
 #include 
 #include 
 
@@ -114,12 +116,73 @@
   }
 };
 
+class OldQualifiedNameOption : public RequiredRefactoringOption {
+ public:
+  StringRef getName() const override { return "old-qualified-name"; }
+  StringRef getDescription() const override {
+return "The old qualified name to be renamed";
+  }
+};
+
+class QualifiedRenameOccurrences : public SourceChangeRefactoringRule {
+public:
+  QualifiedRenameOccurrences(std::string OldQualifiedName,
+ std::string NewQualifiedName)
+  : OldQualifiedName(std::move(OldQualifiedName)),
+NewQualifiedName(std::move(NewQualifiedName)) {}
+
+  Expected
+  createSourceReplacements(RefactoringRuleContext &Context) override {
+const NamedDecl *ND =
+getNamedDeclFor(Context.getASTContext(), OldQualifiedName);
+if (!ND) {
+  return llvm::make_error("Could not find symbol " +
+ OldQualifiedName,
+ llvm::errc::invalid_argument);
+}
+auto USRs = getUSRsForDeclaration(ND, Context.getASTContext());
+assert(!USRs.empty());
+return tooling::createRenameAtomicChanges(
+USRs, NewQualifiedName,
+Context.getASTContext().getTranslationUnitDecl());
+  }
+
+private:
+  std::string OldQualifiedName;
+  std::string NewQualifiedName;
+};
+
+class LocalQualifiedRename final : public RefactoringAction {
+public:
+  StringRef getCommand() const override {
+return "local-qualified-rename";
+  }
+
+  StringRef getDescription() const override {
+return "Finds and rename qualified symbol in code with no indexer support";
+  }
+
+  /// Returns a set of refactoring actions rules that are defined by this
+  /// action.
+  RefactoringActionRules createActionRules() const override {
+RefactoringActionRules Rules;
+Rules.push_back(createRefactoringActionRule(
+OptionRequirement(),
+OptionRequirement()));
+return Rules;
+  }
+};
+
 } // end anonymous namespace
 
 std::unique_ptr createLocalRenameAction() {
   return llvm::make_unique();
 }
 
+std::unique_ptr createLocalQualifiedRenameAction() {
+  return llvm::make_unique();
+}
+
 Expected>
 createRenameReplacements(const SymbolOccurrences &Occurrences,
  const SourceManager &SM, const SymbolName &NewName) {
Index: include/clang/Tooling/Refactoring/RefactoringActionRegistry.def
===
--- include/clang/Tooling/Refactoring/RefactoringActionRegistry.def
+++ include/clang/Tooling/Refactoring/Re

[PATCH] D38596: Implement attribute target multiversioning

2017-10-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: include/clang/Basic/Attr.td:1917
+  MVK_All, // All Decls of this function have a 'target' attribute.  None 
differ
+   // in contents, so this is the 'hint' case.
+  MVK_MultiVersion, // All Decls of this function have a 'target' 
attribute, some

Align the comments (at least the wrapped part of them)?



Comment at: lib/Sema/SemaDecl.cpp:9304
+
+static TargetAttr::MultiVersionKind getMultiVersionKind(FunctionDecl *OldFD) {
+  for (FunctionDecl *F : OldFD->redecls())

`OldFD` can be `const` (and that can be propagated to the other decls).



Comment at: lib/Sema/SemaDecl.cpp:9315
+
+  if (TA->getFeaturesStr() == "default")
+return true;

Do you want to assert that `TA` is not null or handle treat null specially?



Comment at: lib/Sema/SemaDecl.cpp:9366
+  for (const auto *FD : OldFD->redecls())
+Result = CheckMultiVersionOption(FD) && Result;
+

Reverse the conditions so the inexpensive bit is checked first, or early-break 
if `Result` becomes `false`.



Comment at: lib/Sema/SemaDecl.cpp:9368
+
+  return CheckMultiVersionOption(NewFD) && Result;
+}

Reverse conditions.


https://reviews.llvm.org/D38596



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


r316764 - [CrossTU] Fix handling of Cross Translation Unit directory path

2017-10-27 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Fri Oct 27 05:53:37 2017
New Revision: 316764

URL: http://llvm.org/viewvc/llvm-project?rev=316764&view=rev
Log:
[CrossTU] Fix handling of Cross Translation Unit directory path

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

Modified:
cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp
cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp

Modified: cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp?rev=316764&r1=316763&r2=316764&view=diff
==
--- cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp (original)
+++ cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp Fri Oct 27 05:53:37 2017
@@ -93,10 +93,7 @@ parseCrossTUIndex(StringRef IndexPath, S
 index_error_code::multiple_definitions, IndexPath.str(), LineNo);
   StringRef FileName = LineRef.substr(Pos + 1);
   SmallString<256> FilePath = CrossTUDir;
-  if (llvm::sys::path::is_absolute(FileName))
-FilePath = FileName;
-  else
-llvm::sys::path::append(FilePath, FileName);
+  llvm::sys::path::append(FilePath, FileName);
   Result[FunctionLookupName] = FilePath.str().str();
 } else
   return llvm::make_error(

Modified: cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp?rev=316764&r1=316763&r2=316764&view=diff
==
--- cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp (original)
+++ cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp Fri Oct 27 
05:53:37 2017
@@ -109,9 +109,9 @@ TEST(CrossTranslationUnit, CanLoadFuncti
 
 TEST(CrossTranslationUnit, IndexFormatCanBeParsed) {
   llvm::StringMap Index;
-  Index["a"] = "b";
-  Index["c"] = "d";
-  Index["e"] = "f";
+  Index["a"] = "/b/f1";
+  Index["c"] = "/d/f2";
+  Index["e"] = "/f/f3";
   std::string IndexText = createCrossTUIndexString(Index);
 
   int IndexFD;
@@ -134,5 +134,25 @@ TEST(CrossTranslationUnit, IndexFormatCa
 EXPECT_TRUE(Index.count(E.getKey()));
 }
 
+TEST(CrossTranslationUnit, CTUDirIsHandledCorrectly) {
+  llvm::StringMap Index;
+  Index["a"] = "/b/c/d";
+  std::string IndexText = createCrossTUIndexString(Index);
+
+  int IndexFD;
+  llvm::SmallString<256> IndexFileName;
+  ASSERT_FALSE(llvm::sys::fs::createTemporaryFile("index", "txt", IndexFD,
+  IndexFileName));
+  llvm::ToolOutputFile IndexFile(IndexFileName, IndexFD);
+  IndexFile.os() << IndexText;
+  IndexFile.os().flush();
+  EXPECT_TRUE(llvm::sys::fs::exists(IndexFileName));
+  llvm::Expected> IndexOrErr =
+  parseCrossTUIndex(IndexFileName, "/ctudir");
+  EXPECT_TRUE((bool)IndexOrErr);
+  llvm::StringMap ParsedIndex = IndexOrErr.get();
+  EXPECT_EQ(ParsedIndex["a"], "/ctudir/b/c/d");
+}
+
 } // end namespace cross_tu
 } // end namespace clang


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


[PATCH] D39366: [ASTMatchers] Matchers for new[] operators

2017-10-27 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 120577.
baloghadamsoftware added a comment.

Matcher renamed to `isArray`.


https://reviews.llvm.org/D39366

Files:
  docs/LibASTMatchersReference.html
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -1983,5 +1983,15 @@
   namedDecl(hasExternalFormalLinkage(;
 }
 
+TEST(IsArray, Basic) {
+  EXPECT_TRUE(matches("struct MyClass {}; MyClass *p1 = new MyClass[10];",
+  cxxNewExpr(isArray(;
+}
+
+TEST(HasArraySize, Basic) {
+  EXPECT_TRUE(matches("struct MyClass {}; MyClass *p1 = new MyClass[10];",
+  cxxNewExpr(hasArraySize(integerLiteral(equals(10));
+}
+
 } // namespace ast_matchers
 } // namespace clang
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -220,6 +220,7 @@
   REGISTER_MATCHER(hasAnyUsingShadowDecl);
   REGISTER_MATCHER(hasArgument);
   REGISTER_MATCHER(hasArgumentOfType);
+  REGISTER_MATCHER(hasArraySize);
   REGISTER_MATCHER(hasAttr);
   REGISTER_MATCHER(hasAutomaticStorageDuration);
   REGISTER_MATCHER(hasBase);
@@ -302,6 +303,7 @@
   REGISTER_MATCHER(isAnonymous);
   REGISTER_MATCHER(isAnyCharacter);
   REGISTER_MATCHER(isAnyPointer);
+  REGISTER_MATCHER(isArray);
   REGISTER_MATCHER(isArrow);
   REGISTER_MATCHER(isBaseInitializer);
   REGISTER_MATCHER(isBitField);
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -5761,6 +5761,31 @@
   return Node.hasExternalFormalLinkage();
 }
 
+/// \brief Matches array new expressions.
+///
+/// Given:
+/// \code
+///   MyClass *p1 = new MyClass[10];
+/// \endcode
+/// cxxNewExpr(isArray())
+///   matches the expression 'new MyClass[10]'.
+AST_MATCHER(CXXNewExpr, isArray) {
+  return Node.isArray();
+}
+
+/// \brief Matches array new expressions with a given array size.
+///
+/// Given:
+/// \code
+///   MyClass *p1 = new MyClass[10];
+/// \endcode
+/// cxxNewExpr(hasArraySize(intgerLiteral(equals(10
+///   matches the expression 'new MyClass[10]'.
+AST_MATCHER_P(CXXNewExpr, hasArraySize, internal::Matcher, InnerMatcher) {
+  return Node.isArray() &&
+InnerMatcher.matches(*Node.getArraySize(), Finder, Builder);
+}
+
 } // end namespace ast_matchers
 } // end namespace clang
 
Index: docs/LibASTMatchersReference.html
===
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html
@@ -2232,6 +2232,16 @@
 
 
 
+MatcherCXXNewExpr>isArray
+Matches array new expressions.
+
+Given:
+  MyClass *p1 = new MyClass[10];
+cxxNewExpr(isArray())
+  matches the expression 'new MyClass[10]'.
+
+
+
 MatcherCXXOperatorCallExpr>hasOverloadedOperatorNameStringRef Name
 Matches overloaded operator names.
 
@@ -4380,6 +4390,16 @@
 
 
 
+MatcherCXXNewExpr>hasArraySizeMatcherExpr> InnerMatcher
+Matches array new expressions with a given array size.
+
+Given:
+  MyClass *p1 = new MyClass[10];
+cxxNewExpr(hasArraySize(intgerLiteral(equals(10
+  matches the expression 'new MyClass[10]'.
+
+
+
 MatcherCXXNewExpr>hasDeclarationMatcherDecl>  InnerMatcher
 Matches a node if the declaration associated with that node
 matches the given matcher.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38842: [CrossTU] Fix handling of Cross Translation Unit directory path

2017-10-27 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316764: [CrossTU] Fix handling of Cross Translation Unit 
directory path (authored by xazax).

Changed prior to commit:
  https://reviews.llvm.org/D38842?vs=118773&id=120576#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38842

Files:
  cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp
  cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp


Index: cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp
===
--- cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp
+++ cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp
@@ -93,10 +93,7 @@
 index_error_code::multiple_definitions, IndexPath.str(), LineNo);
   StringRef FileName = LineRef.substr(Pos + 1);
   SmallString<256> FilePath = CrossTUDir;
-  if (llvm::sys::path::is_absolute(FileName))
-FilePath = FileName;
-  else
-llvm::sys::path::append(FilePath, FileName);
+  llvm::sys::path::append(FilePath, FileName);
   Result[FunctionLookupName] = FilePath.str().str();
 } else
   return llvm::make_error(
Index: cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp
===
--- cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp
+++ cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp
@@ -109,9 +109,9 @@
 
 TEST(CrossTranslationUnit, IndexFormatCanBeParsed) {
   llvm::StringMap Index;
-  Index["a"] = "b";
-  Index["c"] = "d";
-  Index["e"] = "f";
+  Index["a"] = "/b/f1";
+  Index["c"] = "/d/f2";
+  Index["e"] = "/f/f3";
   std::string IndexText = createCrossTUIndexString(Index);
 
   int IndexFD;
@@ -134,5 +134,25 @@
 EXPECT_TRUE(Index.count(E.getKey()));
 }
 
+TEST(CrossTranslationUnit, CTUDirIsHandledCorrectly) {
+  llvm::StringMap Index;
+  Index["a"] = "/b/c/d";
+  std::string IndexText = createCrossTUIndexString(Index);
+
+  int IndexFD;
+  llvm::SmallString<256> IndexFileName;
+  ASSERT_FALSE(llvm::sys::fs::createTemporaryFile("index", "txt", IndexFD,
+  IndexFileName));
+  llvm::ToolOutputFile IndexFile(IndexFileName, IndexFD);
+  IndexFile.os() << IndexText;
+  IndexFile.os().flush();
+  EXPECT_TRUE(llvm::sys::fs::exists(IndexFileName));
+  llvm::Expected> IndexOrErr =
+  parseCrossTUIndex(IndexFileName, "/ctudir");
+  EXPECT_TRUE((bool)IndexOrErr);
+  llvm::StringMap ParsedIndex = IndexOrErr.get();
+  EXPECT_EQ(ParsedIndex["a"], "/ctudir/b/c/d");
+}
+
 } // end namespace cross_tu
 } // end namespace clang


Index: cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp
===
--- cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp
+++ cfe/trunk/lib/CrossTU/CrossTranslationUnit.cpp
@@ -93,10 +93,7 @@
 index_error_code::multiple_definitions, IndexPath.str(), LineNo);
   StringRef FileName = LineRef.substr(Pos + 1);
   SmallString<256> FilePath = CrossTUDir;
-  if (llvm::sys::path::is_absolute(FileName))
-FilePath = FileName;
-  else
-llvm::sys::path::append(FilePath, FileName);
+  llvm::sys::path::append(FilePath, FileName);
   Result[FunctionLookupName] = FilePath.str().str();
 } else
   return llvm::make_error(
Index: cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp
===
--- cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp
+++ cfe/trunk/unittests/CrossTU/CrossTranslationUnitTest.cpp
@@ -109,9 +109,9 @@
 
 TEST(CrossTranslationUnit, IndexFormatCanBeParsed) {
   llvm::StringMap Index;
-  Index["a"] = "b";
-  Index["c"] = "d";
-  Index["e"] = "f";
+  Index["a"] = "/b/f1";
+  Index["c"] = "/d/f2";
+  Index["e"] = "/f/f3";
   std::string IndexText = createCrossTUIndexString(Index);
 
   int IndexFD;
@@ -134,5 +134,25 @@
 EXPECT_TRUE(Index.count(E.getKey()));
 }
 
+TEST(CrossTranslationUnit, CTUDirIsHandledCorrectly) {
+  llvm::StringMap Index;
+  Index["a"] = "/b/c/d";
+  std::string IndexText = createCrossTUIndexString(Index);
+
+  int IndexFD;
+  llvm::SmallString<256> IndexFileName;
+  ASSERT_FALSE(llvm::sys::fs::createTemporaryFile("index", "txt", IndexFD,
+  IndexFileName));
+  llvm::ToolOutputFile IndexFile(IndexFileName, IndexFD);
+  IndexFile.os() << IndexText;
+  IndexFile.os().flush();
+  EXPECT_TRUE(llvm::sys::fs::exists(IndexFileName));
+  llvm::Expected> IndexOrErr =
+  parseCrossTUIndex(IndexFileName, "/ctudir");
+  EXPECT_TRUE((bool)IndexOrErr);
+  llvm::StringMap ParsedIndex = IndexOrErr.get();
+  EXPECT_EQ(ParsedIndex["a"], "/ctudir/b/c/d");
+}
+
 } // end namespace cross_tu
 } // end namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39074: [libunwind][MIPS]: Add support for unwinding in N32 processes.

2017-10-27 Thread John Baldwin via Phabricator via cfe-commits
bsdjhb updated this revision to Diff 120578.
bsdjhb marked 3 inline comments as done.
bsdjhb added a comment.

- Use correct #ifdef for N32.
- Rename N64 to newabi.


https://reviews.llvm.org/D39074

Files:
  include/__libunwind_config.h
  src/AddressSpace.hpp
  src/DwarfInstructions.hpp
  src/Registers.hpp
  src/UnwindCursor.hpp
  src/UnwindRegistersRestore.S
  src/UnwindRegistersSave.S
  src/libunwind.cpp

Index: src/libunwind.cpp
===
--- src/libunwind.cpp
+++ src/libunwind.cpp
@@ -60,8 +60,9 @@
 # define REGISTER_KIND Registers_or1k
 #elif defined(__mips__) && defined(_ABIO32) && defined(__mips_soft_float)
 # define REGISTER_KIND Registers_mips_o32
-#elif defined(__mips__) && defined(_ABI64) && defined(__mips_soft_float)
-# define REGISTER_KIND Registers_mips_n64
+#elif defined(__mips__) && (defined(_ABIN32) || defined(_ABI64)) &&\
+defined(__mips_soft_float)
+# define REGISTER_KIND Registers_mips_newabi
 #elif defined(__mips__)
 # warning The MIPS architecture is not supported with this ABI and environment!
 #else
Index: src/UnwindRegistersSave.S
===
--- src/UnwindRegistersSave.S
+++ src/UnwindRegistersSave.S
@@ -143,7 +143,8 @@
   or$2, $0, $0
   .set pop
 
-#elif defined(__mips__) && defined(_ABI64) && defined(__mips_soft_float)
+#elif defined(__mips__) && (defined(_ABI64) || defined(_ABIN32)) &&\
+defined(__mips_soft_float)
 
 #
 # extern int unw_getcontext(unw_context_t* thread_state)
Index: src/UnwindRegistersRestore.S
===
--- src/UnwindRegistersRestore.S
+++ src/UnwindRegistersRestore.S
@@ -545,15 +545,16 @@
   lw$4, (4 * 4)($4)
   .set pop
 
-#elif defined(__mips__) && defined(_ABI64) && defined(__mips_soft_float)
+#elif defined(__mips__) && (defined(_ABI64) || defined(_ABIN32)) &&\
+defined(__mips_soft_float)
 
 //
-// void libunwind::Registers_mips_n64::jumpto()
+// void libunwind::Registers_mips_newabi::jumpto()
 //
 // On entry:
 //  thread state pointer is in a0 ($4)
 //
-DEFINE_LIBUNWIND_PRIVATE_FUNCTION(_ZN9libunwind18Registers_mips_n646jumptoEv)
+DEFINE_LIBUNWIND_PRIVATE_FUNCTION(_ZN9libunwind21Registers_mips_newabi6jumptoEv)
   .set push
   .set noat
   .set noreorder
Index: src/UnwindCursor.hpp
===
--- src/UnwindCursor.hpp
+++ src/UnwindCursor.hpp
@@ -520,8 +520,8 @@
   }
 #endif
 
-#if defined(_LIBUNWIND_TARGET_MIPS_N64)
-  int stepWithCompactEncoding(Registers_mips_n64 &) {
+#if defined(_LIBUNWIND_TARGET_MIPS_NEWABI)
+  int stepWithCompactEncoding(Registers_mips_newabi &) {
 return UNW_EINVAL;
   }
 #endif
@@ -576,8 +576,8 @@
   }
 #endif
 
-#if defined(_LIBUNWIND_TARGET_MIPS_N64)
-  bool compactSaysUseDwarf(Registers_mips_n64 &, uint32_t *) const {
+#if defined(_LIBUNWIND_TARGET_MIPS_NEWABI)
+  bool compactSaysUseDwarf(Registers_mips_newabi &, uint32_t *) const {
 return true;
   }
 #endif
@@ -625,8 +625,8 @@
   }
 #endif
 
-#if defined (_LIBUNWIND_TARGET_MIPS_N64)
-  compact_unwind_encoding_t dwarfEncoding(Registers_mips_n64 &) const {
+#if defined (_LIBUNWIND_TARGET_MIPS_NEWABI)
+  compact_unwind_encoding_t dwarfEncoding(Registers_mips_newabi &) const {
 return 0;
   }
 #endif
Index: src/Registers.hpp
===
--- src/Registers.hpp
+++ src/Registers.hpp
@@ -2187,13 +2187,13 @@
 }
 #endif // _LIBUNWIND_TARGET_MIPS_O32
 
-#if defined(_LIBUNWIND_TARGET_MIPS_N64)
-/// Registers_mips_n64 holds the register state of a thread in a 64-bit MIPS
-/// process.
-class _LIBUNWIND_HIDDEN Registers_mips_n64 {
+#if defined(_LIBUNWIND_TARGET_MIPS_NEWABI)
+/// Registers_mips_newabi holds the register state of a thread in a NEWABI
+/// MIPS process including both the N32 and N64 ABIs.
+class _LIBUNWIND_HIDDEN Registers_mips_newabi {
 public:
-  Registers_mips_n64();
-  Registers_mips_n64(const void *registers);
+  Registers_mips_newabi();
+  Registers_mips_newabi(const void *registers);
 
   boolvalidRegister(int num) const;
   uint64_tgetRegister(int num) const;
@@ -2214,28 +2214,28 @@
   void  setIP(uint64_t value) { _registers.__pc = value; }
 
 private:
-  struct mips_n64_thread_state_t {
+  struct mips_newabi_thread_state_t {
 uint64_t __r[32];
 uint64_t __pc;
 uint64_t __hi;
 uint64_t __lo;
   };
 
-  mips_n64_thread_state_t _registers;
+  mips_newabi_thread_state_t _registers;
 };
 
-inline Registers_mips_n64::Registers_mips_n64(const void *registers) {
-  static_assert((check_fit::does_fit),
-"mips_n64 registers do not fit into unw_context_t");
+inline Registers_mips_newabi::Registers_mips_newabi(const void *registers) {
+  static_assert((check_fit::does_fit),
+"mips_newabi registers do not fit into unw_context_t");
   memcpy(&_registers, static_cast(re

[PATCH] D39367: [clang-tidy] Add support for operator new[] in check bugprone-misplaced-operator-in-strlen-in-alloc

2017-10-27 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 120579.
baloghadamsoftware added a comment.

Reformatted according to the comments.


https://reviews.llvm.org/D39367

Files:
  clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
  test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp

Index: test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp
===
--- test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp
+++ test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp
@@ -29,3 +29,9 @@
   char *new_name = (char*) std::malloc(non_std::strlen(name + 1));
   // Ignore functions of the strlen family in custom namespaces
 }
+
+void bad_new_strlen(char *name) {
+  char *new_name = new char[std::strlen(name + 1)];
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: Addition operator is applied to the argument of strlen
+  // CHECK-FIXES: {{^  char \*new_name = new char\[}}std::strlen(name) + 1{{\];$}}
+}
Index: docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
===
--- docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
+++ docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
@@ -7,11 +7,12 @@
 ``strnlen()``, ``strnlen_s()``, ``wcslen()``, ``wcsnlen()`` and ``wcsnlen_s()``
 functions instead of to the result and use its return value as an argument of a
 memory allocation function (``malloc()``, ``calloc()``, ``realloc()``,
-``alloca()``). Cases where ``1`` is added both to the parameter and the result
-of the ``strlen()``-like function are ignored, as are cases where the whole
-addition is surrounded by extra parentheses.
+``alloca()``) or the ``new[]`` operator in `C++`. Cases where ``1`` is added
+both to the parameter and the result of the ``strlen()``-like function are
+ignored, as are cases where the whole addition is surrounded by extra
+parentheses.
 
-Example code:
+`C` example code:
 
 .. code-block:: c
 
@@ -28,6 +29,24 @@
   char *c = (char*) malloc(strlen(str) + 1);
 
 
+`C++` example code:
+
+.. code-block:: c++
+
+void bad_new(char *str) {
+  char *c = new char[strlen(str + 1)];
+}
+
+
+As in the `C` code with the ``malloc()`` function, the suggested fix is to
+add ``1`` to the return value of ``strlen()`` and not to its argument. In the
+example above the fix would be
+
+.. code-block:: c++
+
+  char *c = new char[strlen(str) + 1];
+
+
 Example for silencing the bug report:
 
 .. code-block:: c
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -64,7 +64,7 @@
   ``strlen()``, ``strnlen()``, ``strnlen_s()``, ``wcslen()``, ``wcsnlen()`` and
   ``wcsnlen_s()`` functions instead of to the result and use its return value as
   an argument of a memory allocation function (``malloc()``, ``calloc()``,
-  ``realloc()``, ``alloca()``).
+  ``realloc()``, ``alloca()``) or the ``new[]`` operator in `C++`.
 
 - Renamed checks to use correct term "implicit conversion" instead of "implicit
   cast" and modified messages and option names accordingly:
Index: clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
===
--- clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
+++ clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
@@ -48,26 +48,32 @@
   const auto Alloc1Func =
   functionDecl(anyOf(hasName("::calloc"), hasName("std::calloc"),
  hasName("::realloc"), hasName("std::realloc")));
-
   Finder->addMatcher(
   callExpr(callee(Alloc0Func), hasArgument(0, BadArg)).bind("Alloc"), this);
   Finder->addMatcher(
   callExpr(callee(Alloc1Func), hasArgument(1, BadArg)).bind("Alloc"), this);
+  Finder->addMatcher(
+  cxxNewExpr(isArrayForm(), hasArraySize(BadArg)).bind("Alloc"), this);
 }
 
 void MisplacedOperatorInStrlenInAllocCheck::check(
 const MatchFinder::MatchResult &Result) {
-  const auto *Alloc = Result.Nodes.getNodeAs("Alloc");
+  const Expr *Alloc = Result.Nodes.getNodeAs("Alloc");
+  if (!Alloc)
+Alloc = Result.Nodes.getNodeAs("Alloc");
+  assert(Alloc && "Matched node bound by `Alloc` shoud be either `CallExpr`"
+ " or `CXXNewExpr`");
+
   const auto *StrLen = Result.Nodes.getNodeAs("StrLen");
   const auto *BinOp = Result.Nodes.getNodeAs("BinOp");
 
   const StringRef StrLenText = Lexer::getSourceText(
   CharSourceRange::getTokenRange(StrLen->getSourceRange()),
   *Result.SourceManager, getLangOpts());
-  const StringRef StrLenBegin = StrLenText.substr(0, StrLenText.find('(') + 1);
   const StringRef Arg0Text = Lexer::getSourceText(
   CharSourceRange::getTokenRange(StrLen->getArg(0)->getSo

[PATCH] D39074: [libunwind][MIPS]: Add support for unwinding in N32 processes.

2017-10-27 Thread John Baldwin via Phabricator via cfe-commits
bsdjhb marked 2 inline comments as done.
bsdjhb added inline comments.



Comment at: include/__libunwind_config.h:62
+#  define _LIBUNWIND_CONTEXT_SIZE 35
+#  define _LIBUNWIND_CURSOR_SIZE 46
+#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 66

sdardis wrote:
> Shouldn't this 46 be 47?
No, the other parts of a cursor besides the register context use ILP32 layout 
for N32 instead of LP64.  In particular, I think N32 has less padding after the 
two 'bool' members at the end of UnwindCursor<>.


https://reviews.llvm.org/D39074



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


[PATCH] D39367: [clang-tidy] Add support for operator new[] in check bugprone-misplaced-operator-in-strlen-in-alloc

2017-10-27 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware marked an inline comment as done.
baloghadamsoftware added a comment.

In https://reviews.llvm.org/D39367#909117, @JonasToth wrote:

> Should the release notes be modified as well?


I think so. I consider the inclusion of operator `new[]` important.


https://reviews.llvm.org/D39367



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


[PATCH] D39121: [clang-tidy] Misplaced Operator in Strlen in Alloc

2017-10-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Many of the comments are marked done, but the code does not reflect that it 
actually is done, so I'm not certain what's happened there.




Comment at: clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp:86
+  diag(Alloc->getLocStart(),
+   "Addition operator is applied to the argument of "
+   "%0 instead of its result; surround the addition subexpression with "

Addition -> addition

(Diagnostics are never complete sentences with capitalization and punctuation, 
unlike comments.)



Comment at: clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp:87-88
+   "Addition operator is applied to the argument of "
+   "%0 instead of its result; surround the addition subexpression with "
+   "parentheses to silence this warning")
+  << StrLen->getDirectCallee()->getName() << Hint;

The downside to this new wording is that it contradicts the fixit hint that's 
being supplied. The user sees "surround the addition with parens" as the 
textual advice, but the fixit shows a different way to silence the warning.

I'm not certain of the best way to address that, however. Basically, there are 
two ways this could be fixed and both could come with fixits, but I don't 
believe we have a way to do an either/or pair of fixits.

We could add "or hoist the addition" to the diagnostic, but that may be too 
cryptic and the diagnostic would be quite long. @alexfh -- do you have ideas?



Comment at: clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp:64-67
+  const auto StrLenText = Lexer::getSourceText(
+  CharSourceRange::getTokenRange(StrLen->getSourceRange()),
+  *Result.SourceManager, getLangOpts());
+  const auto StrLenBegin = StrLenText.substr(0, StrLenText.find('(') + 1);

aaron.ballman wrote:
> Please don't use `auto` as the type is not spelled out in the initialization. 
> Same elsewhere as well.
You marked this as done but I still see `auto` used improperly on this line and 
many others.



Comment at: docs/ReleaseNotes.rst:63
+
+  Finds cases a value is added to or subtracted from the string in the 
parameter
+  of ``strlen()`` method instead of to the result and use its return value as 
an

aaron.ballman wrote:
> aaron.ballman wrote:
> > This comment is no longer accurate and should be reworded.
> Still not quite right because it's talking about subtraction.
It's still talking about subtraction, so this does not appear to be done.



Comment at: 
docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst:6
+
+Finds cases a value is added to or subtracted from the string in the parameter
+of ``strlen()`` method instead of to the result and use its return value as an

aaron.ballman wrote:
> aaron.ballman wrote:
> > This comment is no longer accurate and should be reworded.
> Same comment about subtraction.
This is also not done.


https://reviews.llvm.org/D39121



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


[PATCH] D39367: [clang-tidy] Add support for operator new[] in check bugprone-misplaced-operator-in-strlen-in-alloc

2017-10-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp:64-65
+Alloc = Result.Nodes.getNodeAs("Alloc");
+  assert(Alloc && "Matched node bound by `Alloc` shoud be either `CallExpr`"
+ " or `CXXNewExpr`");
+

The backticks should be single quotes instead, I think.



Comment at: 
test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp:37
+  // CHECK-FIXES: {{^  char \*new_name = new char\[}}std::strlen(name) + 
1{{\];$}}
+}

Please add tests showing that the correct behavior does not diagnose. Also, 
please add a test showing that this works with overloaded `operator new[]()`.


https://reviews.llvm.org/D39367



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


[PATCH] D39366: [ASTMatchers] Matchers for new[] operators

2017-10-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!


https://reviews.llvm.org/D39366



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


[PATCH] D39121: [clang-tidy] Misplaced Operator in Strlen in Alloc

2017-10-27 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

In https://reviews.llvm.org/D39121#909172, @aaron.ballman wrote:

> Many of the comments are marked done, but the code does not reflect that it 
> actually is done, so I'm not certain what's happened there.


Neither do I. I will try to re-upload the diff.


https://reviews.llvm.org/D39121



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


[PATCH] D34158: For Linux/gnu compatibility, preinclude if the file is available

2017-10-27 Thread Melanie Blower via Phabricator via cfe-commits
mibintc updated this revision to Diff 120581.
mibintc added a comment.

The patch to clang is the same as before. The modifications are to the test 
cases, I verified that all these test cases need modifications. I will also be 
updating the associated diff for clang/tools/extra, please review that as well. 
 Without the test patches, these are the tests that fail (using check-all) . 
The failure mode is as described in a note I posted earlier this week, please 
let me know if you need further details.  @jyknight Looking for your review and 
approval, thanks!

  Clang :: Driver/crash-report-header.h
  Clang :: Driver/crash-report-spaces.c
  Clang :: Driver/crash-report.c
  Clang :: Driver/rewrite-map-in-diagnostics.c
  Clang :: Driver/stdc-predef.c
  Clang :: Index/IBOutletCollection.m
  Clang :: Index/annotate-macro-args.m
  Clang :: Index/annotate-tokens-pp.c
  Clang :: Index/annotate-tokens.c
  Clang :: Index/c-index-getCursor-test.m
  Clang :: Index/get-cursor-macro-args.m
  Clang :: Index/get-cursor.cpp
  Clang :: Preprocessor/ignore-pragmas.c
  Clang Tools :: pp-trace/pp-trace-pragma-general.cpp
  Clang Tools :: pp-trace/pp-trace-pragma-opencl.cpp
  Clang-Unit :: Tooling/./ToolingTests/CommentHandlerTest.BasicTest1
  Clang-Unit :: Tooling/./ToolingTests/CommentHandlerTest.BasicTest2
  Clang-Unit :: Tooling/./ToolingTests/CommentHandlerTest.BasicTest3
  Clang-Unit :: Tooling/./ToolingTests/CommentHandlerTest.IfBlock1
  Clang-Unit :: Tooling/./ToolingTests/CommentHandlerTest.IfBlock2
  Clang-Unit :: Tooling/./ToolingTests/CommentHandlerTest.IfBlock3
  Clang-Unit :: Tooling/./ToolingTests/CommentHandlerTest.PPDirectives


https://reviews.llvm.org/D34158

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Lex/PreprocessorOptions.h
  lib/Driver/Job.cpp
  lib/Driver/ToolChains/Linux.cpp
  lib/Driver/ToolChains/Linux.h
  lib/Frontend/CompilerInvocation.cpp
  lib/Frontend/InitPreprocessor.cpp
  test/Driver/Inputs/stdc-predef/usr/include/stdc-predef.h
  test/Driver/crash-report-header.h
  test/Driver/crash-report-spaces.c
  test/Driver/crash-report.c
  test/Driver/rewrite-map-in-diagnostics.c
  test/Driver/stdc-predef.c
  test/Driver/stdc-predef.i
  test/Index/IBOutletCollection.m
  test/Index/annotate-macro-args.m
  test/Index/annotate-tokens-pp.c
  test/Index/annotate-tokens.c
  test/Index/c-index-getCursor-test.m
  test/Index/get-cursor-macro-args.m
  test/Index/get-cursor.cpp
  test/Preprocessor/ignore-pragmas.c
  unittests/Tooling/TestVisitor.h

Index: unittests/Tooling/TestVisitor.h
===
--- unittests/Tooling/TestVisitor.h
+++ unittests/Tooling/TestVisitor.h
@@ -52,6 +52,7 @@
   /// \brief Runs the current AST visitor over the given code.
   bool runOver(StringRef Code, Language L = Lang_CXX) {
 std::vector Args;
+Args.push_back("-ffreestanding");
 switch (L) {
   case Lang_C:
 Args.push_back("-x");
Index: test/Preprocessor/ignore-pragmas.c
===
--- test/Preprocessor/ignore-pragmas.c
+++ test/Preprocessor/ignore-pragmas.c
@@ -1,8 +1,8 @@
-// RUN: %clang_cc1 -E %s -Wall -verify
-// RUN: %clang_cc1 -Eonly %s -Wall -verify
-// RUN: %clang -M -Wall %s -Xclang -verify
-// RUN: %clang -E -frewrite-includes %s -Wall -Xclang -verify
-// RUN: %clang -E -dD -dM %s -Wall -Xclang -verify
+// RUN: %clang_cc1 -E %s -Wall -ffreestanding -verify
+// RUN: %clang_cc1 -Eonly %s -Wall -ffreestanding -verify
+// RUN: %clang -M -Wall -ffreestanding %s -Xclang -verify
+// RUN: %clang -E -frewrite-includes %s -Wall -ffreestanding -Xclang -verify
+// RUN: %clang -E -dD -dM %s -Wall -ffreestanding -Xclang -verify
 // expected-no-diagnostics
 
 #pragma GCC visibility push (default)
Index: test/Index/get-cursor.cpp
===
--- test/Index/get-cursor.cpp
+++ test/Index/get-cursor.cpp
@@ -152,71 +152,71 @@
 void f_dynamic_noexcept() throw(int);
 void f_dynamic_noexcept_any() throw(...);
 
-// RUN: c-index-test -cursor-at=%s:6:4 %s | FileCheck -check-prefix=CHECK-COMPLETION-1 %s
+// RUN: c-index-test -cursor-at=%s:6:4 -ffreestanding %s | FileCheck -check-prefix=CHECK-COMPLETION-1 %s
 // CHECK-COMPLETION-1: CXXConstructor=X:6:3
 // CHECK-COMPLETION-1-NEXT: Completion string: {TypedText X}{LeftParen (}{Placeholder int}{Comma , }{Placeholder int}{RightParen )}
 
-// RUN: c-index-test -cursor-at=%s:31:16 %s | FileCheck -check-prefix=CHECK-COMPLETION-2 %s
+// RUN: c-index-test -cursor-at=%s:31:16 -ffreestanding %s | FileCheck -check-prefix=CHECK-COMPLETION-2 %s
 // CHECK-COMPLETION-2: CXXMethod=getAnotherX:31:5 (Definition)
 // CHECK-COMPLETION-2-NEXT: Completion string: {ResultType X}{TypedText getAnotherX}{LeftParen (}{RightParen )}
 
-// RUN: c-index-test -cursor-at=%s:12:20 %s | FileCheck -check-prefix=CHECK-VALUE-REF %s
-// RUN: c-index-test -cursor-at=%s:13:21 %s | FileCheck -check-prefix=CHECK-VALUE-REF %s
-// RUN: c-

[PATCH] D39370: [clang-tidy] Detect bugs in bugprone-misplaced-operator-in-strlen-in-alloc even in the case the allocation function is called using a constant function pointer

2017-10-27 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware created this revision.

Detect bugs even if a function of the `malloc()` family is called using a 
constant pointer.


https://reviews.llvm.org/D39370

Files:
  clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
  docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
  test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c


Index: test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c
===
--- test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c
+++ test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c
@@ -76,3 +76,11 @@
   // If expression is in extra parentheses, consider it as intentional
 }
 
+void (*(*const alloc_ptr)(size_t)) = malloc;
+
+void bad_indirect_alloc(char *name) {
+  char *new_name = (char*) alloc_ptr(strlen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: Addition operator is applied to 
the argument of strlen
+  // CHECK-FIXES: {{^  char \*new_name = \(char\*\) alloc_ptr\(}}strlen(name) 
+ 1{{\);$}}
+}
+
Index: docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
===
--- docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
+++ docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
@@ -7,9 +7,10 @@
 ``strnlen()``, ``strnlen_s()``, ``wcslen()``, ``wcsnlen()`` and ``wcsnlen_s()``
 functions instead of to the result and use its return value as an argument of a
 memory allocation function (``malloc()``, ``calloc()``, ``realloc()``,
-``alloca()``). Cases where ``1`` is added both to the parameter and the result
-of the ``strlen()``-like function are ignored, as are cases where the whole
-addition is surrounded by extra parentheses.
+``alloca()``). The check detects error cases even if one of these functions is
+called by a constant function pointer. Cases where ``1`` is added both to the
+parameter and the result of the ``strlen()``-like function are ignored, as are
+cases where the whole addition is surrounded by extra parentheses.
 
 Example code:
 
Index: clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
===
--- clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
+++ clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
@@ -49,10 +49,23 @@
   functionDecl(anyOf(hasName("::calloc"), hasName("std::calloc"),
  hasName("::realloc"), hasName("std::realloc")));
 
-  Finder->addMatcher(
-  callExpr(callee(Alloc0Func), hasArgument(0, BadArg)).bind("Alloc"), 
this);
-  Finder->addMatcher(
-  callExpr(callee(Alloc1Func), hasArgument(1, BadArg)).bind("Alloc"), 
this);
+  const auto Alloc0FuncPtr =
+  varDecl(hasType(isConstQualified()),
+  hasInitializer(ignoringParenImpCasts(
+  declRefExpr(hasDeclaration(Alloc0Func);
+  const auto Alloc1FuncPtr =
+  varDecl(hasType(isConstQualified()),
+  hasInitializer(ignoringParenImpCasts(
+  declRefExpr(hasDeclaration(Alloc1Func);
+
+  Finder->addMatcher(callExpr(callee(decl(anyOf(Alloc0Func, Alloc0FuncPtr))),
+  hasArgument(0, BadArg))
+ .bind("Alloc"),
+ this);
+  Finder->addMatcher(callExpr(callee(decl(anyOf(Alloc1Func, Alloc1FuncPtr))),
+  hasArgument(1, BadArg))
+ .bind("Alloc"),
+ this);
 }
 
 void MisplacedOperatorInStrlenInAllocCheck::check(


Index: test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c
===
--- test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c
+++ test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c
@@ -76,3 +76,11 @@
   // If expression is in extra parentheses, consider it as intentional
 }
 
+void (*(*const alloc_ptr)(size_t)) = malloc;
+
+void bad_indirect_alloc(char *name) {
+  char *new_name = (char*) alloc_ptr(strlen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: Addition operator is applied to the argument of strlen
+  // CHECK-FIXES: {{^  char \*new_name = \(char\*\) alloc_ptr\(}}strlen(name) + 1{{\);$}}
+}
+
Index: docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
===
--- docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
+++ docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
@@ -7,9 +7,10 @@
 ``strnlen()``, ``strnlen_s()``, ``wcslen()``, ``wcsnlen()`` and ``wcsnlen_s()``
 functions instead of to the result and use its return value as an argument of a
 memory allocation function (``malloc()``, ``calloc()``, ``realloc()``,
-``alloca()``). Cases where ``1`` i

[PATCH] D39121: [clang-tidy] Misplaced Operator in Strlen in Alloc

2017-10-27 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 120582.
baloghadamsoftware added a comment.

Second try to upload the correct diff...


https://reviews.llvm.org/D39121

Files:
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
  clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c
  test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp

Index: test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp
===
--- /dev/null
+++ test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp
@@ -0,0 +1,31 @@
+// RUN: %check_clang_tidy %s bugprone-misplaced-operator-in-strlen-in-alloc %t
+
+namespace std {
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+
+size_t strlen(const char*);
+}
+
+namespace non_std {
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+
+size_t strlen(const char*);
+}
+
+void bad_std_malloc_std_strlen(char *name) {
+  char *new_name = (char*) std::malloc(std::strlen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: Addition operator is applied to the argument of strlen
+  // CHECK-FIXES: {{^  char \*new_name = \(char\*\) std::malloc\(}}std::strlen(name) + 1{{\);$}}
+}
+
+void ignore_non_std_malloc_std_strlen(char *name) {
+  char *new_name = (char*) non_std::malloc(std::strlen(name + 1));
+  // Ignore functions of the malloc family in custom namespaces
+}
+
+void ignore_std_malloc_non_std_strlen(char *name) {
+  char *new_name = (char*) std::malloc(non_std::strlen(name + 1));
+  // Ignore functions of the strlen family in custom namespaces
+}
Index: test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c
===
--- /dev/null
+++ test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c
@@ -0,0 +1,78 @@
+// RUN: %check_clang_tidy %s bugprone-misplaced-operator-in-strlen-in-alloc %t
+
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+void *alloca(size_t);
+void *calloc(size_t, size_t);
+void *realloc(void *, size_t);
+
+size_t strlen(const char*);
+size_t strnlen(const char*, size_t);
+size_t strnlen_s(const char*, size_t);
+
+typedef unsigned wchar_t;
+
+size_t wcslen(const wchar_t*);
+size_t wcsnlen(const wchar_t*, size_t);
+size_t wcsnlen_s(const wchar_t*, size_t);
+
+void bad_malloc(char *name) {
+  char *new_name = (char*) malloc(strlen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: Addition operator is applied to the argument of strlen
+  // CHECK-FIXES: {{^  char \*new_name = \(char\*\) malloc\(}}strlen(name) + 1{{\);$}}
+  new_name = (char*) malloc(strnlen(name + 1, 10));
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: Addition operator is applied to the argument of strnlen
+  // CHECK-FIXES: {{^  new_name = \(char\*\) malloc\(}}strnlen(name, 10) + 1{{\);$}}
+  new_name = (char*) malloc(strnlen_s(name + 1, 10));
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: Addition operator is applied to the argument of strnlen_s
+  // CHECK-FIXES: {{^  new_name = \(char\*\) malloc\(}}strnlen_s(name, 10) + 1{{\);$}}
+}
+
+void bad_malloc_wide(wchar_t *name) {
+  wchar_t *new_name = (wchar_t*) malloc(wcslen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: Addition operator is applied to the argument of wcslen
+  // CHECK-FIXES: {{^  wchar_t \*new_name = \(wchar_t\*\) malloc\(}}wcslen(name) + 1{{\);$}}
+  new_name = (wchar_t*) malloc(wcsnlen(name + 1, 10));
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: Addition operator is applied to the argument of wcsnlen
+  // CHECK-FIXES: {{^  new_name = \(wchar_t\*\) malloc\(}}wcsnlen(name, 10) + 1{{\);$}}
+  new_name = (wchar_t*) malloc(wcsnlen_s(name + 1, 10));
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: Addition operator is applied to the argument of wcsnlen_s
+  // CHECK-FIXES: {{^  new_name = \(wchar_t\*\) malloc\(}}wcsnlen_s(name, 10) + 1{{\);$}}
+}
+
+void bad_alloca(char *name) {
+  char *new_name = (char*) alloca(strlen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: Addition operator is applied to the argument of strlen
+  // CHECK-FIXES: {{^  char \*new_name = \(char\*\) alloca\(}}strlen(name) + 1{{\);$}}
+}
+
+void bad_calloc(char *name) {
+  char *new_names = (char*) calloc(2, strlen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: Addition operator is applied to the argument of strlen
+  // CHECK-FIXES: {{^  char \*new_names = \(char\*\) calloc\(2, }}strlen(name) + 1{{\);$}}
+}
+
+void bad_realloc(char * old_name, char *name) {
+  char *new_name = (char*) realloc(old_name, strlen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: Addition operator is applied to the argument of s

[PATCH] D34624: extra test modifications for D34158

2017-10-27 Thread Melanie Blower via Phabricator via cfe-commits
mibintc updated this revision to Diff 120584.
mibintc added a comment.

Updated the test diff to correspond to the https://reviews.llvm.org/D34158 
patch uploaded today.


https://reviews.llvm.org/D34624

Files:
  test/pp-trace/pp-trace-pragma-general.cpp
  test/pp-trace/pp-trace-pragma-opencl.cpp


Index: test/pp-trace/pp-trace-pragma-opencl.cpp
===
--- test/pp-trace/pp-trace-pragma-opencl.cpp
+++ test/pp-trace/pp-trace-pragma-opencl.cpp
@@ -1,4 +1,4 @@
-// RUN: pp-trace -ignore FileChanged,MacroDefined %s -x cl | FileCheck 
--strict-whitespace %s
+// RUN: pp-trace -ignore FileChanged,MacroDefined %s -ffreestanding -x cl | 
FileCheck --strict-whitespace %s
 
 #pragma OPENCL EXTENSION all : disable
 #pragma OPENCL EXTENSION cl_khr_int64_base_atomics : disable
Index: test/pp-trace/pp-trace-pragma-general.cpp
===
--- test/pp-trace/pp-trace-pragma-general.cpp
+++ test/pp-trace/pp-trace-pragma-general.cpp
@@ -1,4 +1,4 @@
-// RUN: pp-trace -ignore FileChanged,MacroDefined %s | FileCheck 
--strict-whitespace %s
+// RUN: pp-trace -ignore FileChanged,MacroDefined %s -ffreestanding | 
FileCheck --strict-whitespace %s
 
 #pragma clang diagnostic push
 #pragma clang diagnostic pop


Index: test/pp-trace/pp-trace-pragma-opencl.cpp
===
--- test/pp-trace/pp-trace-pragma-opencl.cpp
+++ test/pp-trace/pp-trace-pragma-opencl.cpp
@@ -1,4 +1,4 @@
-// RUN: pp-trace -ignore FileChanged,MacroDefined %s -x cl | FileCheck --strict-whitespace %s
+// RUN: pp-trace -ignore FileChanged,MacroDefined %s -ffreestanding -x cl | FileCheck --strict-whitespace %s
 
 #pragma OPENCL EXTENSION all : disable
 #pragma OPENCL EXTENSION cl_khr_int64_base_atomics : disable
Index: test/pp-trace/pp-trace-pragma-general.cpp
===
--- test/pp-trace/pp-trace-pragma-general.cpp
+++ test/pp-trace/pp-trace-pragma-general.cpp
@@ -1,4 +1,4 @@
-// RUN: pp-trace -ignore FileChanged,MacroDefined %s | FileCheck --strict-whitespace %s
+// RUN: pp-trace -ignore FileChanged,MacroDefined %s -ffreestanding | FileCheck --strict-whitespace %s
 
 #pragma clang diagnostic push
 #pragma clang diagnostic pop
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39121: [clang-tidy] Misplaced Operator in Strlen in Alloc

2017-10-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

This upload looks considerably better, thank you!




Comment at: docs/ReleaseNotes.rst:63
+
+  Finds cases where ``1`` is added to the string in the parameter of
+  ``strlen()``, ``strnlen()``, ``strnlen_s()``, ``wcslen()``, ``wcsnlen()`` and

parameter of -> argument to



Comment at: docs/ReleaseNotes.rst:64
+  Finds cases where ``1`` is added to the string in the parameter of
+  ``strlen()``, ``strnlen()``, ``strnlen_s()``, ``wcslen()``, ``wcsnlen()`` and
+  ``wcsnlen_s()`` functions instead of to the result and use its return value 
as

and -> , and

(Add the Oxford comma.)



Comment at: docs/ReleaseNotes.rst:65
+  ``strlen()``, ``strnlen()``, ``strnlen_s()``, ``wcslen()``, ``wcsnlen()`` and
+  ``wcsnlen_s()`` functions instead of to the result and use its return value 
as
+  an argument of a memory allocation function (``malloc()``, ``calloc()``,

functions instead of to the result -> instead of the result

use its return value -> the value is used



Comment at: docs/ReleaseNotes.rst:66
+  ``wcsnlen_s()`` functions instead of to the result and use its return value 
as
+  an argument of a memory allocation function (``malloc()``, ``calloc()``,
+  ``realloc()``, ``alloca()``).

of a -> to a



Comment at: 
docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst:6
+
+Finds cases where ``1`` is added to the string in the parameter of 
``strlen()``,
+``strnlen()``, ``strnlen_s()``, ``wcslen()``, ``wcsnlen()`` and ``wcsnlen_s()``

Same wording changes from the release notes apply here as well.



Comment at: 
docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst:31
+
+Example for silencing the bug report:
+

bug report -> diagnostic


https://reviews.llvm.org/D39121



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


[PATCH] D39121: [clang-tidy] Misplaced Operator in Strlen in Alloc

2017-10-27 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 120593.
baloghadamsoftware added a comment.

Docs rephrased according to the comments.


https://reviews.llvm.org/D39121

Files:
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
  clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c
  test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp

Index: test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp
===
--- /dev/null
+++ test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp
@@ -0,0 +1,31 @@
+// RUN: %check_clang_tidy %s bugprone-misplaced-operator-in-strlen-in-alloc %t
+
+namespace std {
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+
+size_t strlen(const char*);
+}
+
+namespace non_std {
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+
+size_t strlen(const char*);
+}
+
+void bad_std_malloc_std_strlen(char *name) {
+  char *new_name = (char*) std::malloc(std::strlen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: Addition operator is applied to the argument of strlen
+  // CHECK-FIXES: {{^  char \*new_name = \(char\*\) std::malloc\(}}std::strlen(name) + 1{{\);$}}
+}
+
+void ignore_non_std_malloc_std_strlen(char *name) {
+  char *new_name = (char*) non_std::malloc(std::strlen(name + 1));
+  // Ignore functions of the malloc family in custom namespaces
+}
+
+void ignore_std_malloc_non_std_strlen(char *name) {
+  char *new_name = (char*) std::malloc(non_std::strlen(name + 1));
+  // Ignore functions of the strlen family in custom namespaces
+}
Index: test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c
===
--- /dev/null
+++ test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c
@@ -0,0 +1,78 @@
+// RUN: %check_clang_tidy %s bugprone-misplaced-operator-in-strlen-in-alloc %t
+
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+void *alloca(size_t);
+void *calloc(size_t, size_t);
+void *realloc(void *, size_t);
+
+size_t strlen(const char*);
+size_t strnlen(const char*, size_t);
+size_t strnlen_s(const char*, size_t);
+
+typedef unsigned wchar_t;
+
+size_t wcslen(const wchar_t*);
+size_t wcsnlen(const wchar_t*, size_t);
+size_t wcsnlen_s(const wchar_t*, size_t);
+
+void bad_malloc(char *name) {
+  char *new_name = (char*) malloc(strlen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: Addition operator is applied to the argument of strlen
+  // CHECK-FIXES: {{^  char \*new_name = \(char\*\) malloc\(}}strlen(name) + 1{{\);$}}
+  new_name = (char*) malloc(strnlen(name + 1, 10));
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: Addition operator is applied to the argument of strnlen
+  // CHECK-FIXES: {{^  new_name = \(char\*\) malloc\(}}strnlen(name, 10) + 1{{\);$}}
+  new_name = (char*) malloc(strnlen_s(name + 1, 10));
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: Addition operator is applied to the argument of strnlen_s
+  // CHECK-FIXES: {{^  new_name = \(char\*\) malloc\(}}strnlen_s(name, 10) + 1{{\);$}}
+}
+
+void bad_malloc_wide(wchar_t *name) {
+  wchar_t *new_name = (wchar_t*) malloc(wcslen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: Addition operator is applied to the argument of wcslen
+  // CHECK-FIXES: {{^  wchar_t \*new_name = \(wchar_t\*\) malloc\(}}wcslen(name) + 1{{\);$}}
+  new_name = (wchar_t*) malloc(wcsnlen(name + 1, 10));
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: Addition operator is applied to the argument of wcsnlen
+  // CHECK-FIXES: {{^  new_name = \(wchar_t\*\) malloc\(}}wcsnlen(name, 10) + 1{{\);$}}
+  new_name = (wchar_t*) malloc(wcsnlen_s(name + 1, 10));
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: Addition operator is applied to the argument of wcsnlen_s
+  // CHECK-FIXES: {{^  new_name = \(wchar_t\*\) malloc\(}}wcsnlen_s(name, 10) + 1{{\);$}}
+}
+
+void bad_alloca(char *name) {
+  char *new_name = (char*) alloca(strlen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: Addition operator is applied to the argument of strlen
+  // CHECK-FIXES: {{^  char \*new_name = \(char\*\) alloca\(}}strlen(name) + 1{{\);$}}
+}
+
+void bad_calloc(char *name) {
+  char *new_names = (char*) calloc(2, strlen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: Addition operator is applied to the argument of strlen
+  // CHECK-FIXES: {{^  char \*new_names = \(char\*\) calloc\(2, }}strlen(name) + 1{{\);$}}
+}
+
+void bad_realloc(char * old_name, char *name) {
+  char *new_name = (char*) realloc(old_name, strlen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: Addition operator is applied to the argument of 

[PATCH] D39367: [clang-tidy] Add support for operator new[] in check bugprone-misplaced-operator-in-strlen-in-alloc

2017-10-27 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 120595.
baloghadamsoftware added a comment.
Herald added a subscriber: mgorny.

Backsticks changed to single quotes, new tests added.


https://reviews.llvm.org/D39367

Files:
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
  clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-misplaced-operator-in-strlen-in-alloc.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c
  test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp

Index: test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp
===
--- /dev/null
+++ test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.cpp
@@ -0,0 +1,57 @@
+// RUN: %check_clang_tidy %s bugprone-misplaced-operator-in-strlen-in-alloc %t
+
+namespace std {
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+
+size_t strlen(const char*);
+}
+
+namespace non_std {
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+
+size_t strlen(const char*);
+}
+
+void bad_std_malloc_std_strlen(char *name) {
+  char *new_name = (char*) std::malloc(std::strlen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: Addition operator is applied to the argument of strlen
+  // CHECK-FIXES: {{^  char \*new_name = \(char\*\) std::malloc\(}}std::strlen(name) + 1{{\);$}}
+}
+
+void ignore_non_std_malloc_std_strlen(char *name) {
+  char *new_name = (char*) non_std::malloc(std::strlen(name + 1));
+  // Ignore functions of the malloc family in custom namespaces
+}
+
+void ignore_std_malloc_non_std_strlen(char *name) {
+  char *new_name = (char*) std::malloc(non_std::strlen(name + 1));
+  // Ignore functions of the strlen family in custom namespaces
+}
+
+void bad_new_strlen(char *name) {
+  char *new_name = new char[std::strlen(name + 1)];
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: Addition operator is applied to the argument of strlen
+  // CHECK-FIXES: {{^  char \*new_name = new char\[}}std::strlen(name) + 1{{\];$}}
+}
+
+void good_new_strlen(char *name) {
+  char *new_name = new char[std::strlen(name) + 1];
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:20: warning: Addition operator is applied to the argument of strlen
+}
+
+class C {
+  char c;
+public:
+  static void *operator new[](std::size_t count) {
+return ::operator new(count);
+  }
+};
+
+void bad_custom_new_strlen(char *name) {
+  C *new_name = new C[std::strlen(name + 1)];
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: Addition operator is applied to the argument of strlen
+  // CHECK-FIXES: {{^  C \*new_name = new C\[}}std::strlen(name) + 1{{\];$}}
+}
+
Index: test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c
===
--- /dev/null
+++ test/clang-tidy/bugprone-misplaced-operator-in-strlen-in-alloc.c
@@ -0,0 +1,78 @@
+// RUN: %check_clang_tidy %s bugprone-misplaced-operator-in-strlen-in-alloc %t
+
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+void *alloca(size_t);
+void *calloc(size_t, size_t);
+void *realloc(void *, size_t);
+
+size_t strlen(const char*);
+size_t strnlen(const char*, size_t);
+size_t strnlen_s(const char*, size_t);
+
+typedef unsigned wchar_t;
+
+size_t wcslen(const wchar_t*);
+size_t wcsnlen(const wchar_t*, size_t);
+size_t wcsnlen_s(const wchar_t*, size_t);
+
+void bad_malloc(char *name) {
+  char *new_name = (char*) malloc(strlen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: Addition operator is applied to the argument of strlen
+  // CHECK-FIXES: {{^  char \*new_name = \(char\*\) malloc\(}}strlen(name) + 1{{\);$}}
+  new_name = (char*) malloc(strnlen(name + 1, 10));
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: Addition operator is applied to the argument of strnlen
+  // CHECK-FIXES: {{^  new_name = \(char\*\) malloc\(}}strnlen(name, 10) + 1{{\);$}}
+  new_name = (char*) malloc(strnlen_s(name + 1, 10));
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: Addition operator is applied to the argument of strnlen_s
+  // CHECK-FIXES: {{^  new_name = \(char\*\) malloc\(}}strnlen_s(name, 10) + 1{{\);$}}
+}
+
+void bad_malloc_wide(wchar_t *name) {
+  wchar_t *new_name = (wchar_t*) malloc(wcslen(name + 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: Addition operator is applied to the argument of wcslen
+  // CHECK-FIXES: {{^  wchar_t \*new_name = \(wchar_t\*\) malloc\(}}wcslen(name) + 1{{\);$}}
+  new_name = (wchar_t*) malloc(wcsnlen(name + 1, 10));
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: Addition operator is applied to the argument of wcsnlen
+  // CHECK-FIXES: {{^  new_name = \(wchar_t\*\) malloc\(}}wcsnlen(name, 10) + 1{{\);$}}
+  new_name = (wchar_t*) malloc(wcsnlen_s(name + 1, 10));
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: 

[PATCH] D37470: [analyzer] Handle ObjC messages conservatively in CallDescription

2017-10-27 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

In https://reviews.llvm.org/D37470#906717, @dcoughlin wrote:

> I think it would be better to add a new 
> "test/Analysis/block-in-critical-section.m" file rather than enabling a 
> random alpha checker in a file that tests the analyzer core.


My reasoning was that the tested feature is within the core. The checker just 
happens to trigger this.


https://reviews.llvm.org/D37470



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


[PATCH] D37470: [analyzer] Handle ObjC messages conservatively in CallDescription

2017-10-27 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun updated this revision to Diff 120598.
xazax.hun added a comment.

- Added a separate test case as per Devin's suggestion


https://reviews.llvm.org/D37470

Files:
  lib/StaticAnalyzer/Core/CallEvent.cpp
  test/Analysis/block-in-critical-section.m


Index: test/Analysis/block-in-critical-section.m
===
--- /dev/null
+++ test/Analysis/block-in-critical-section.m
@@ -0,0 +1,9 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=core,alpha.unix.BlockInCriticalSection -verify 
-Wno-objc-root-class %s
+
+@interface SomeClass
+-(void)someMethod;
+@end
+
+void shouldNotCrash(SomeClass *o) {
+  [o someMethod];
+}
Index: lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- lib/StaticAnalyzer/Core/CallEvent.cpp
+++ lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -211,7 +211,9 @@
 }
 
 bool CallEvent::isCalled(const CallDescription &CD) const {
-  assert(getKind() != CE_ObjCMessage && "Obj-C methods are not supported");
+  // FIXME: Add ObjC Message support.
+  if (getKind() == CE_ObjCMessage)
+return false;
   if (!CD.IsLookupDone) {
 CD.IsLookupDone = true;
 CD.II = 
&getState()->getStateManager().getContext().Idents.get(CD.FuncName);


Index: test/Analysis/block-in-critical-section.m
===
--- /dev/null
+++ test/Analysis/block-in-critical-section.m
@@ -0,0 +1,9 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.unix.BlockInCriticalSection -verify -Wno-objc-root-class %s
+
+@interface SomeClass
+-(void)someMethod;
+@end
+
+void shouldNotCrash(SomeClass *o) {
+  [o someMethod];
+}
Index: lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- lib/StaticAnalyzer/Core/CallEvent.cpp
+++ lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -211,7 +211,9 @@
 }
 
 bool CallEvent::isCalled(const CallDescription &CD) const {
-  assert(getKind() != CE_ObjCMessage && "Obj-C methods are not supported");
+  // FIXME: Add ObjC Message support.
+  if (getKind() == CE_ObjCMessage)
+return false;
   if (!CD.IsLookupDone) {
 CD.IsLookupDone = true;
 CD.II = &getState()->getStateManager().getContext().Idents.get(CD.FuncName);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39121: [clang-tidy] Misplaced Operator in Strlen in Alloc

2017-10-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

My only remaining concern is with the diagnostic message/fixit interaction 
itself. Let's see if @alexfh has any suggestions there, or we think of an 
improvement ourselves.


https://reviews.llvm.org/D39121



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


[PATCH] D38171: Implement clang-tidy check aliases.

2017-10-27 Thread András Leitereg via Phabricator via cfe-commits
leanil updated this revision to Diff 120597.
leanil added a comment.

> Make clang-diagnostic-* checks first-class citizens and take full control of 
> all diagnostics, i.e. disable all Clang diagnostics by default, and enable 
> the ones that correspond to the enabled clang-diagnostic checks.

(As @alexfh suggested.)

Collecting all the diagnostics seems to be possible from multiple sources, I've 
decided to make `DiagnosticIDs::getAllDiagnostics` static.
I also had to replace explicit -W arguments with the new checks in some of the 
tests.


https://reviews.llvm.org/D38171

Files:
  clang-tidy/ClangTidy.cpp
  clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tidy/ClangTidyModule.h
  clang-tidy/cert/CERTTidyModule.cpp
  clang-tidy/tool/ClangTidyMain.cpp
  test/clang-tidy/cert-exp59-cpp.cpp
  test/clang-tidy/custom-diagnostics.cpp
  test/clang-tidy/diagnostic.cpp
  test/clang-tidy/list-clang-diagnostics.cpp
  test/clang-tidy/misc-suspicious-semicolon-fail.cpp
  test/clang-tidy/validate-check-names.cpp
  test/clang-tidy/warning-check-aliases.cpp
  test/clang-tidy/werrors-diagnostics.cpp

Index: test/clang-tidy/werrors-diagnostics.cpp
===
--- test/clang-tidy/werrors-diagnostics.cpp
+++ test/clang-tidy/werrors-diagnostics.cpp
@@ -1,11 +1,10 @@
-// RUN: clang-tidy %s -checks='-*,llvm-namespace-comment,clang-diagnostic*' \
-// RUN:   -- -Wunused-variable 2>&1 \
+// RUN: clang-tidy %s -checks='-*,llvm-namespace-comment,clang-diagnostic-unused-variable' -- 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-WARN -implicit-check-not='{{warning|error}}:'
-// RUN: not clang-tidy %s -checks='-*,llvm-namespace-comment,clang-diagnostic*' \
-// RUN:   -warnings-as-errors='clang-diagnostic*' -- -Wunused-variable 2>&1 \
+// RUN: not clang-tidy %s -checks='-*,llvm-namespace-comment,clang-diagnostic-unused-variable' \
+// RUN:   -warnings-as-errors='clang-diagnostic*' -- 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-WERR -implicit-check-not='{{warning|error}}:'
-// RUN: not clang-tidy %s -checks='-*,llvm-namespace-comment,clang-diagnostic*' \
-// RUN:   -warnings-as-errors='clang-diagnostic*' -quiet -- -Wunused-variable 2>&1 \
+// RUN: not clang-tidy %s -checks='-*,llvm-namespace-comment,clang-diagnostic-unused-variable' \
+// RUN:   -warnings-as-errors='clang-diagnostic*' -quiet -- 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-WERR-QUIET -implicit-check-not='{{warning|error}}:'
 
 void f() { int i; }
Index: test/clang-tidy/warning-check-aliases.cpp
===
--- /dev/null
+++ test/clang-tidy/warning-check-aliases.cpp
@@ -0,0 +1,21 @@
+// RUN: clang-tidy %s -checks='-*,clang-diagnostic-exceptions' -- 2>&1 | FileCheck -implicit-check-not='{{warning:|error:}}' %s
+// RUN: clang-tidy %s -checks='-*,cert-err54-cpp' -- 2>&1 | FileCheck -implicit-check-not='{{warning:|error:}}' -check-prefix=CHECK2 %s
+// RUN: clang-tidy %s -- 2>&1 | FileCheck -allow-empty -implicit-check-not='{{warning:|error:}}' -check-prefix=CHECK3 %s
+
+class B {};
+class D : public B {};
+
+void f() {
+  try {
+
+  } catch (B &X) {
+
+  } catch (D &Y) {
+  }
+}
+
+//CHECK: :13:12: warning: exception of type 'D &' will be caught by earlier handler [clang-diagnostic-exceptions]
+//CHECK: :11:12: note: for type 'B &'
+
+//CHECK2: :13:12: warning: exception of type 'D &' will be caught by earlier handler [cert-err54-cpp]
+//CHECK2: :11:12: note: for type 'B &'
Index: test/clang-tidy/validate-check-names.cpp
===
--- test/clang-tidy/validate-check-names.cpp
+++ test/clang-tidy/validate-check-names.cpp
@@ -1,2 +1,2 @@
 // Check names may only contain alphanumeric characters, '-', '_', and '.'.
-// RUN: clang-tidy -checks=* -list-checks | grep '^' | cut -b5- | not grep -v '^[a-zA-Z0-9_.\-]\+$'
+// RUN: clang-tidy -checks=*,-clang-diagnostic* -list-checks | grep '^' | cut -b5- | not grep -v '^[a-zA-Z0-9_.\-]\+$'
Index: test/clang-tidy/misc-suspicious-semicolon-fail.cpp
===
--- test/clang-tidy/misc-suspicious-semicolon-fail.cpp
+++ test/clang-tidy/misc-suspicious-semicolon-fail.cpp
@@ -1,8 +1,8 @@
 // RUN: clang-tidy %s -checks="-*,misc-suspicious-semicolon" -- -DERROR 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=CHECK-ERROR \
 // RUN:   -implicit-check-not="{{warning|error}}:"
-// RUN: clang-tidy %s -checks="-*,misc-suspicious-semicolon,clang-diagnostic*" \
-// RUN:-- -DWERROR -Wno-everything -Werror=unused-variable 2>&1 \
+// RUN: not clang-tidy %s -checks="-*,misc-suspicious-semicolon,clang-diagnostic-unused-variable" \
+// RUN:   -warnings-as-errors=clang-diagnostic-unused-variable -- -DWERROR 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=CHECK-WERROR \
 // RUN:   -implicit-check-not="{{warning|error}}:"
 
@@ -19,7 +19,7 @@
   // CHECK

[PATCH] D39367: [clang-tidy] Add support for operator new[] in check bugprone-misplaced-operator-in-strlen-in-alloc

2017-10-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp:64-65
+Alloc = Result.Nodes.getNodeAs("Alloc");
+  assert(Alloc && "Matched node bound by `Alloc` shoud be either `CallExpr`"
+ " or `CXXNewExpr`");
+

aaron.ballman wrote:
> The backticks should be single quotes instead, I think.
Missed the backticks around `CXXNewExpr`


https://reviews.llvm.org/D39367



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


[clang-tools-extra] r316767 - [clang-tidy] Fix bug 34845, offending standard bitmask types

2017-10-27 Thread Jonas Toth via cfe-commits
Author: jonastoth
Date: Fri Oct 27 07:44:08 2017
New Revision: 316767

URL: http://llvm.org/viewvc/llvm-project?rev=316767&view=rev
Log:
[clang-tidy] Fix bug 34845, offending standard bitmask types

Summary:
The C++ standard allows implementations to choose the underlying type for
bitmask types (e.g. std::ios_base::openmode). MSVC implemented some of them
as signed integers resulting in warnings for usual code like
`auto dd = std::ios_base::badbit | std::ios_base::failbit;`

These false positives were reported in 
https://bugs.llvm.org/show_bug.cgi?id=34845

The fix allows bitwise |,&,^ for known standard bitmask types under the 
condition
that both operands are such bitmask types.
Shifting and bitwise complement are still forbidden.

Reviewers: aaron.ballman, alexfh, hokein

Reviewed By: aaron.ballman

Subscribers: xazax.hun

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

Added:

clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-standard-types.cpp

clang-tools-extra/trunk/test/clang-tidy/hicpp-signed-bitwise-standard-types.h
Modified:
clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp?rev=316767&r1=316766&r2=316767&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/hicpp/SignedBitwiseCheck.cpp Fri Oct 27 
07:44:08 2017
@@ -20,34 +20,72 @@ namespace hicpp {
 
 void SignedBitwiseCheck::registerMatchers(MatchFinder *Finder) {
   const auto SignedIntegerOperand =
-  
expr(ignoringImpCasts(hasType(isSignedInteger(.bind("signed_operand");
+  
expr(ignoringImpCasts(hasType(isSignedInteger(.bind("signed-operand");
+
+  // The standard [bitmask.types] allows some integral types to be implemented
+  // as signed types. Exclude these types from diagnosing for bitwise or(|) and
+  // bitwise and(&). Shifting and complementing such values is still not
+  // allowed.
+  const auto BitmaskType = namedDecl(anyOf(
+  hasName("::std::locale::category"), hasName("::std::ctype_base::mask"),
+  hasName("::std::ios_base::fmtflags"), 
hasName("::std::ios_base::iostate"),
+  hasName("::std::ios_base::openmode")));
+  const auto IsStdBitmask = 
ignoringImpCasts(declRefExpr(hasType(BitmaskType)));
 
   // Match binary bitwise operations on signed integer arguments.
   Finder->addMatcher(
-  binaryOperator(allOf(anyOf(hasOperatorName("|"), hasOperatorName("&"),
- hasOperatorName("^"), hasOperatorName("<<"),
- hasOperatorName(">>")),
+  binaryOperator(
+  allOf(anyOf(hasOperatorName("^"), hasOperatorName("|"),
+  hasOperatorName("&")),
+
+unless(allOf(hasLHS(IsStdBitmask), hasRHS(IsStdBitmask))),
+
+hasEitherOperand(SignedIntegerOperand),
+hasLHS(hasType(isInteger())), hasRHS(hasType(isInteger()
+  .bind("binary-no-sign-interference"),
+  this);
+
+  // Shifting and complement is not allowed for any signed integer type because
+  // the sign bit may corrupt the result.
+  Finder->addMatcher(
+  binaryOperator(allOf(anyOf(hasOperatorName("<<"), hasOperatorName(">>")),
hasEitherOperand(SignedIntegerOperand),
hasLHS(hasType(isInteger())),
hasRHS(hasType(isInteger()
-  .bind("binary_signed"),
+  .bind("binary-sign-interference"),
   this);
 
   // Match unary operations on signed integer types.
   Finder->addMatcher(unaryOperator(allOf(hasOperatorName("~"),
  
hasUnaryOperand(SignedIntegerOperand)))
- .bind("unary_signed"),
+ .bind("unary-signed"),
  this);
 }
 
 void SignedBitwiseCheck::check(const MatchFinder::MatchResult &Result) {
   const ast_matchers::BoundNodes &N = Result.Nodes;
-  const auto *SignedBinary = N.getNodeAs("binary_signed");
-  const auto *SignedUnary = N.getNodeAs("unary_signed");
-  const auto *SignedOperand = N.getNodeAs("signed_operand");
+  const auto *SignedOperand = N.getNodeAs("signed-operand");
+  assert(SignedOperand &&
+ "No signed operand found in problematic bitwise operations");
+
+  bool IsUnary = false;
+  SourceLocation Location;
+
+  if (const auto *UnaryOp = N.getNodeAs("unary-signed")) {
+IsUnary = true;
+Location = UnaryOp->getLocStart();
+  } else {
+if (const auto *BinaryOp =
+N.getNodeAs("binary-no-sign-interference"))
+  Location = BinaryOp->getLocStart();
+else if (const auto *BinaryOp =
+ N.getNodeAs("binary-sign-interference"))
+  Location = BinaryOp-

[PATCH] D39374: CodeGen: Fix insertion position of addrspace cast for alloca

2017-10-27 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.

For non-zero alloca addr space, alloca is usually casted to default addr
space immediately.

For non-vla, alloca is inserted at AllocaInsertPt, therefore the addr
space cast should also be insterted at AllocaInsertPt. However,
for vla, alloca is inserted at the current insertion point of IRBuilder,
therefore the addr space cast should also inserted at the current
insertion point of IRBuilder.

Currently clang always insert addr space cast at AllocaInsertPt, which
causes invalid IR.

This patch fixes that.


https://reviews.llvm.org/D39374

Files:
  lib/CodeGen/CGExpr.cpp
  test/CodeGenCXX/vla.cpp


Index: test/CodeGenCXX/vla.cpp
===
--- test/CodeGenCXX/vla.cpp
+++ test/CodeGenCXX/vla.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin %s -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin %s -emit-llvm -o - | 
FileCheck -check-prefixes=X64,CHECK %s
+// RUN: %clang_cc1 -std=c++11 -triple amdgcn---amdgiz %s -emit-llvm -o - | 
FileCheck -check-prefixes=AMD,CHECK %s
 
 template
 struct S {
@@ -9,18 +10,26 @@
 int f() {
   // Make sure that the reference here is enough to trigger the instantiation 
of
   // the static data member.
-  // CHECK: @_ZN1SIiE1nE = linkonce_odr global i32 5
+  // CHECK: @_ZN1SIiE1nE = linkonce_odr{{.*}} global i32 5
   int a[S::n];
   return sizeof a;
 }
 
 // rdar://problem/9506377
 void test0(void *array, int n) {
   // CHECK-LABEL: define void @_Z5test0Pvi(
-  // CHECK:  [[ARRAY:%.*]] = alloca i8*, align 8
-  // CHECK-NEXT: [[N:%.*]] = alloca i32, align 4
-  // CHECK-NEXT: [[REF:%.*]] = alloca i16*, align 8
-  // CHECK-NEXT: [[S:%.*]] = alloca i16, align 2
+  // X64:[[ARRAY:%.*]] = alloca i8*, align 8
+  // AMD:[[ARRAY0:%.*]] = alloca i8*, align 8, addrspace(5)
+  // AMD-NEXT:   [[ARRAY:%.*]] = addrspacecast i8* addrspace(5)* [[ARRAY0]] to 
i8**
+  // X64-NEXT:   [[N:%.*]] = alloca i32, align 4
+  // AMD:[[N0:%.*]] = alloca i32, align 4, addrspace(5)
+  // AMD-NEXT:   [[N:%.*]] = addrspacecast i32 addrspace(5)* [[N0]] to i32*
+  // X64-NEXT:   [[REF:%.*]] = alloca i16*, align 8
+  // AMD:[[REF0:%.*]] = alloca i16*, align 8, addrspace(5)
+  // AMD-NEXT:   [[REF:%.*]] = addrspacecast i16* addrspace(5)* [[REF0]] to 
i16**
+  // X64-NEXT:   [[S:%.*]] = alloca i16, align 2
+  // AMD:[[S0:%.*]] = alloca i16, align 2, addrspace(5)
+  // AMD-NEXT:   [[S:%.*]] = addrspacecast i16 addrspace(5)* [[S0]] to i16*
   // CHECK-NEXT: store i8* 
   // CHECK-NEXT: store i32
 
@@ -59,6 +68,8 @@
 void test2(int b) {
   // CHECK-LABEL: define void {{.*}}test2{{.*}}(i32 %b)
   int varr[b];
+  // AMD: %__end = alloca i32*, align 8, addrspace(5)
+  // AMD: [[END:%.*]] = addrspacecast i32* addrspace(5)* %__end to i32**
   // get the address of %b by checking the first store that stores it 
   //CHECK: store i32 %b, i32* [[PTR_B:%.*]]
 
@@ -75,13 +86,16 @@
   //CHECK: [[VLA_SIZEOF:%.*]] = mul nuw i64 4, [[VLA_NUM_ELEMENTS_PRE]]
   //CHECK-NEXT: [[VLA_NUM_ELEMENTS_POST:%.*]] = udiv i64 [[VLA_SIZEOF]], 4
   //CHECK-NEXT: [[VLA_END_PTR:%.*]] = getelementptr inbounds i32, i32* 
{{%.*}}, i64 [[VLA_NUM_ELEMENTS_POST]]
-  //CHECK-NEXT: store i32* [[VLA_END_PTR]], i32** %__end
+  //X64-NEXT: store i32* [[VLA_END_PTR]], i32** %__end
+  //AMD-NEXT: store i32* [[VLA_END_PTR]], i32** [[END]]
   for (int d : varr) 0;
 }
 
 void test3(int b, int c) {
   // CHECK-LABEL: define void {{.*}}test3{{.*}}(i32 %b, i32 %c)
   int varr[b][c];
+  // AMD: %__end = alloca i32*, align 8, addrspace(5)
+  // AMD: [[END:%.*]] = addrspacecast i32* addrspace(5)* %__end to i32**
   // get the address of %b by checking the first store that stores it 
   //CHECK: store i32 %b, i32* [[PTR_B:%.*]]
   //CHECK-NEXT: store i32 %c, i32* [[PTR_C:%.*]]
@@ -105,7 +119,8 @@
   //CHECK-NEXT: [[VLA_NUM_ELEMENTS:%.*]] = udiv i64 [[VLA_SIZEOF]], 
[[VLA_SIZEOF_DIM2]]
   //CHECK-NEXT: [[VLA_END_INDEX:%.*]] = mul nsw i64 [[VLA_NUM_ELEMENTS]], 
[[VLA_DIM2_PRE]]
   //CHECK-NEXT: [[VLA_END_PTR:%.*]] = getelementptr inbounds i32, i32* 
{{%.*}}, i64 [[VLA_END_INDEX]]
-  //CHECK-NEXT: store i32* [[VLA_END_PTR]], i32** %__end
+  //X64-NEXT: store i32* [[VLA_END_PTR]], i32** %__end
+  //AMD-NEXT: store i32* [[VLA_END_PTR]], i32** [[END]]
  
   for (auto &d : varr) 0;
 }
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -75,7 +75,11 @@
   if (CastToDefaultAddrSpace && getASTAllocaAddressSpace() != LangAS::Default) 
{
 auto DestAddrSpace = getContext().getTargetAddressSpace(LangAS::Default);
 llvm::IRBuilderBase::InsertPointGuard IPG(Builder);
-Builder.SetInsertPoint(AllocaInsertPt);
+// When ArraySize is nullptr, alloca is inserted at AllocaInsertPt,
+// otherwise alloca is inserted at the current insertion point of the
+// builder.
+if 

[PATCH] D38171: Implement clang-tidy check aliases.

2017-10-27 Thread András Leitereg via Phabricator via cfe-commits
leanil added a comment.

In https://reviews.llvm.org/D38171#901427, @xazax.hun wrote:

> One problem to think about when we add all clang-diagnostic as "first or 
> second" class citizen, `checkes=*` might now enable all the warnings which 
> make no sense and might be surprising to the users. What do you think?


This is a good point. Should I insert ",-clang-diagnostic*" after any 
(positive) * ?


https://reviews.llvm.org/D38171



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


[PATCH] D39372: Make DiagnosticIDs::getAllDiagnostics static.

2017-10-27 Thread András Leitereg via Phabricator via cfe-commits
leanil created this revision.

It doesn't depend on instance specific data, so this would make it easier to 
use, for example here :


https://reviews.llvm.org/D39372

Files:
  include/clang/Basic/DiagnosticIDs.h
  lib/Basic/DiagnosticIDs.cpp


Index: lib/Basic/DiagnosticIDs.cpp
===
--- lib/Basic/DiagnosticIDs.cpp
+++ lib/Basic/DiagnosticIDs.cpp
@@ -578,7 +578,7 @@
 }
 
 void DiagnosticIDs::getAllDiagnostics(diag::Flavor Flavor,
- SmallVectorImpl &Diags) const 
{
+  SmallVectorImpl &Diags) {
   for (unsigned i = 0; i != StaticDiagInfoSize; ++i)
 if (StaticDiagInfo[i].getFlavor() == Flavor)
   Diags.push_back(StaticDiagInfo[i].DiagID);
Index: include/clang/Basic/DiagnosticIDs.h
===
--- include/clang/Basic/DiagnosticIDs.h
+++ include/clang/Basic/DiagnosticIDs.h
@@ -292,8 +292,8 @@
  SmallVectorImpl &Diags) const;
 
   /// \brief Get the set of all diagnostic IDs.
-  void getAllDiagnostics(diag::Flavor Flavor,
- SmallVectorImpl &Diags) const;
+  static void getAllDiagnostics(diag::Flavor Flavor,
+SmallVectorImpl &Diags);
 
   /// \brief Get the diagnostic option with the closest edit distance to the
   /// given group name.


Index: lib/Basic/DiagnosticIDs.cpp
===
--- lib/Basic/DiagnosticIDs.cpp
+++ lib/Basic/DiagnosticIDs.cpp
@@ -578,7 +578,7 @@
 }
 
 void DiagnosticIDs::getAllDiagnostics(diag::Flavor Flavor,
- SmallVectorImpl &Diags) const {
+  SmallVectorImpl &Diags) {
   for (unsigned i = 0; i != StaticDiagInfoSize; ++i)
 if (StaticDiagInfo[i].getFlavor() == Flavor)
   Diags.push_back(StaticDiagInfo[i].DiagID);
Index: include/clang/Basic/DiagnosticIDs.h
===
--- include/clang/Basic/DiagnosticIDs.h
+++ include/clang/Basic/DiagnosticIDs.h
@@ -292,8 +292,8 @@
  SmallVectorImpl &Diags) const;
 
   /// \brief Get the set of all diagnostic IDs.
-  void getAllDiagnostics(diag::Flavor Flavor,
- SmallVectorImpl &Diags) const;
+  static void getAllDiagnostics(diag::Flavor Flavor,
+SmallVectorImpl &Diags);
 
   /// \brief Get the diagnostic option with the closest edit distance to the
   /// given group name.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37554: [libclang] Allow crash recovery with LIBCLANG_NOTHREADS

2017-10-27 Thread Nikolai Kosjar via Phabricator via cfe-commits
nik added reviewers: ddunbar, krememek.
nik added a comment.

...added some more reviewers that I've found with git blame. Ping to the new 
ones :)


https://reviews.llvm.org/D37554



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


[PATCH] D39375: [clang] Add PPCallbacks list to preprocessor when building a preacompiled preamble.

2017-10-27 Thread William Enright via Phabricator via cfe-commits
Nebiroth created this revision.

Revision https://reviews.llvm.org/D38639 needs this commit in order to properly 
make open definition calls on include statements work.
Since this modifies clang and not clangd, I decided to include it in a 
different patch.


https://reviews.llvm.org/D39375

Files:
  include/clang/Frontend/PrecompiledPreamble.h
  lib/Frontend/ASTUnit.cpp
  lib/Frontend/PrecompiledPreamble.cpp

Index: lib/Frontend/PrecompiledPreamble.cpp
===
--- lib/Frontend/PrecompiledPreamble.cpp
+++ lib/Frontend/PrecompiledPreamble.cpp
@@ -203,7 +203,7 @@
 const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds,
 DiagnosticsEngine &Diagnostics, IntrusiveRefCntPtr VFS,
 std::shared_ptr PCHContainerOps,
-PreambleCallbacks &Callbacks) {
+PreambleCallbacks &Callbacks, std::unique_ptr PPCallbacks) {
   assert(VFS && "VFS is null");
 
   if (!Bounds.Size)
@@ -307,6 +307,7 @@
   if (!Act->BeginSourceFile(*Clang.get(), Clang->getFrontendOpts().Inputs[0]))
 return BuildPreambleError::BeginSourceFileFailed;
 
+  Clang->getPreprocessor().addPPCallbacks(std::move(PPCallbacks));
   Act->Execute();
 
   // Run the callbacks.
Index: lib/Frontend/ASTUnit.cpp
===
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -53,54 +53,52 @@
 using llvm::TimeRecord;
 
 namespace {
-  class SimpleTimer {
-bool WantTiming;
-TimeRecord Start;
-std::string Output;
-
-  public:
-explicit SimpleTimer(bool WantTiming) : WantTiming(WantTiming) {
-  if (WantTiming)
-Start = TimeRecord::getCurrentTime();
-}
-
-void setOutput(const Twine &Output) {
-  if (WantTiming)
-this->Output = Output.str();
-}
-
-~SimpleTimer() {
-  if (WantTiming) {
-TimeRecord Elapsed = TimeRecord::getCurrentTime();
-Elapsed -= Start;
-llvm::errs() << Output << ':';
-Elapsed.print(Elapsed, llvm::errs());
-llvm::errs() << '\n';
-  }
-}
-  };
+class SimpleTimer {
+  bool WantTiming;
+  TimeRecord Start;
+  std::string Output;
 
-  template 
-  std::unique_ptr valueOrNull(llvm::ErrorOr> Val) {
-if (!Val)
-  return nullptr;
-return std::move(*Val);
+public:
+  explicit SimpleTimer(bool WantTiming) : WantTiming(WantTiming) {
+if (WantTiming)
+  Start = TimeRecord::getCurrentTime();
+  }
+
+  void setOutput(const Twine &Output) {
+if (WantTiming)
+  this->Output = Output.str();
+  }
+
+  ~SimpleTimer() {
+if (WantTiming) {
+  TimeRecord Elapsed = TimeRecord::getCurrentTime();
+  Elapsed -= Start;
+  llvm::errs() << Output << ':';
+  Elapsed.print(Elapsed, llvm::errs());
+  llvm::errs() << '\n';
+}
   }
+};
 
-  template 
-  bool moveOnNoError(llvm::ErrorOr Val, T &Output) {
-if (!Val)
-  return false;
-Output = std::move(*Val);
-return true;
-  }
+template 
+std::unique_ptr valueOrNull(llvm::ErrorOr> Val) {
+  if (!Val)
+return nullptr;
+  return std::move(*Val);
+}
+
+template  bool moveOnNoError(llvm::ErrorOr Val, T &Output) {
+  if (!Val)
+return false;
+  Output = std::move(*Val);
+  return true;
+}
 
 /// \brief Get a source buffer for \p MainFilePath, handling all file-to-file
 /// and file-to-buffer remappings inside \p Invocation.
 static std::unique_ptr
 getBufferForFileHandlingRemapping(const CompilerInvocation &Invocation,
-  vfs::FileSystem *VFS,
-  StringRef FilePath) {
+  vfs::FileSystem *VFS, StringRef FilePath) {
   const auto &PreprocessorOpts = Invocation.getPreprocessorOpts();
 
   // Try to determine if the main file has been remapped, either from the
@@ -156,7 +154,7 @@
 return nullptr;
   return llvm::MemoryBuffer::getMemBufferCopy(Buffer->getBuffer(), FilePath);
 }
-}
+} // namespace
 
 struct ASTUnit::ASTWriterData {
   SmallString<128> Buffer;
@@ -167,9 +165,7 @@
   : Stream(Buffer), Writer(Stream, Buffer, PCMCache, {}) {}
 };
 
-void ASTUnit::clearFileLevelDecls() {
-  llvm::DeleteContainerSeconds(FileDecls);
-}
+void ASTUnit::clearFileLevelDecls() { llvm::DeleteContainerSeconds(FileDecls); }
 
 /// \brief After failing to build a precompiled preamble (due to
 /// errors in the source that occurs in the preamble), the number of
@@ -183,20 +179,15 @@
 static std::atomic ActiveASTUnitObjects;
 
 ASTUnit::ASTUnit(bool _MainFileIsAST)
-  : Reader(nullptr), HadModuleLoaderFatalFailure(false),
-OnlyLocalDecls(false), CaptureDiagnostics(false),
-MainFileIsAST(_MainFileIsAST), 
-TUKind(TU_Complete), WantTiming(getenv("LIBCLANG_TIMING")),
-OwnsRemappedFileBuffers(true),
-NumStoredDiagnosticsFromDriver(0),
-PreambleRebuildCounter(0),
-NumWarningsInPreamble(0),
-ShouldCacheCodeCompletionResults(false),
-IncludeBriefCommentsInCodeCompletion(false), UserFilesAreVolatile(fal

[PATCH] D38596: Implement attribute target multiversioning

2017-10-27 Thread Erich Keane via Phabricator via cfe-commits
erichkeane marked 2 inline comments as done.
erichkeane added inline comments.



Comment at: include/clang/Basic/Attr.td:1917
+  MVK_All, // All Decls of this function have a 'target' attribute.  None 
differ
+   // in contents, so this is the 'hint' case.
+  MVK_MultiVersion, // All Decls of this function have a 'target' 
attribute, some

aaron.ballman wrote:
> Align the comments (at least the wrapped part of them)?
Ugg... I did a ton of work to get these lined up, then format must have had its 
fun with it.  I'll reflow these again.



Comment at: lib/Sema/SemaDecl.cpp:9366
+  for (const auto *FD : OldFD->redecls())
+Result = CheckMultiVersionOption(FD) && Result;
+

aaron.ballman wrote:
> Reverse the conditions so the inexpensive bit is checked first, or 
> early-break if `Result` becomes `false`.
Ah, right... I think for a while during implementation the "Check" function was 
doing important work, but this must have been fixed along the way.  Fix 
incoming!


https://reviews.llvm.org/D38596



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


[PATCH] D39376: [PowerPC] Add implementation for -msave-toc-indirect option - clang portion

2017-10-27 Thread Zaara Syeda via Phabricator via cfe-commits
syzaara created this revision.

Add clang option -msave-toc-indirect for PowerPC.


https://reviews.llvm.org/D39376

Files:
  include/clang/Driver/Options.td
  test/Driver/ppc-features.cpp


Index: test/Driver/ppc-features.cpp
===
--- test/Driver/ppc-features.cpp
+++ test/Driver/ppc-features.cpp
@@ -134,6 +134,9 @@
 // RUN: %clang -target powerpc64-unknown-linux-gnu %s -mno-vsx -mvsx -### -o 
%t.o 2>&1 | FileCheck -check-prefix=CHECK-VSX %s
 // CHECK-VSX: "-target-feature" "+vsx"
 
+// RUN: %clang -target powerpc64-unknown-linux-gnu %s -msave-toc-indirect -### 
-o %t.o 2>&1 | FileCheck -check-prefix=CHECK-TOC %s
+// CHECK-TOC: "-target-feature" "+save-toc-indirect"
+
 // RUN: %clang -target powerpc64-unknown-linux-gnu %s -mno-htm -### -o %t.o 
2>&1 | FileCheck -check-prefix=CHECK-NOHTM %s
 // CHECK-NOHTM: "-target-feature" "-htm"
 
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1904,6 +1904,7 @@
 def maltivec : Flag<["-"], "maltivec">, Group;
 def mno_altivec : Flag<["-"], "mno-altivec">, Group;
 def mvsx : Flag<["-"], "mvsx">, Group;
+def msave_toc_indirect : Flag<["-"], "msave-toc-indirect">, 
Group;
 def mno_vsx : Flag<["-"], "mno-vsx">, Group;
 def mpower8_vector : Flag<["-"], "mpower8-vector">,
 Group;


Index: test/Driver/ppc-features.cpp
===
--- test/Driver/ppc-features.cpp
+++ test/Driver/ppc-features.cpp
@@ -134,6 +134,9 @@
 // RUN: %clang -target powerpc64-unknown-linux-gnu %s -mno-vsx -mvsx -### -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-VSX %s
 // CHECK-VSX: "-target-feature" "+vsx"
 
+// RUN: %clang -target powerpc64-unknown-linux-gnu %s -msave-toc-indirect -### -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-TOC %s
+// CHECK-TOC: "-target-feature" "+save-toc-indirect"
+
 // RUN: %clang -target powerpc64-unknown-linux-gnu %s -mno-htm -### -o %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOHTM %s
 // CHECK-NOHTM: "-target-feature" "-htm"
 
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1904,6 +1904,7 @@
 def maltivec : Flag<["-"], "maltivec">, Group;
 def mno_altivec : Flag<["-"], "mno-altivec">, Group;
 def mvsx : Flag<["-"], "mvsx">, Group;
+def msave_toc_indirect : Flag<["-"], "msave-toc-indirect">, Group;
 def mno_vsx : Flag<["-"], "mno-vsx">, Group;
 def mpower8_vector : Flag<["-"], "mpower8-vector">,
 Group;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38110: [libunwind][MIPS]: Add support for unwinding in O32 and N64 processes.

2017-10-27 Thread John Baldwin via Phabricator via cfe-commits
bsdjhb updated this revision to Diff 120623.
bsdjhb added a comment.

- Rebase for recent change to MAX_REGISTER meaning.


https://reviews.llvm.org/D38110

Files:
  include/__libunwind_config.h
  include/libunwind.h
  src/Registers.hpp
  src/UnwindCursor.hpp
  src/UnwindRegistersRestore.S
  src/UnwindRegistersSave.S
  src/config.h
  src/libunwind.cpp

Index: src/libunwind.cpp
===
--- src/libunwind.cpp
+++ src/libunwind.cpp
@@ -59,8 +59,12 @@
 # define REGISTER_KIND Registers_arm
 #elif defined(__or1k__)
 # define REGISTER_KIND Registers_or1k
+#elif defined(__mips__) && defined(_ABIO32) && defined(__mips_soft_float)
+# define REGISTER_KIND Registers_mips_o32
+#elif defined(__mips__) && defined(_ABI64) && defined(__mips_soft_float)
+# define REGISTER_KIND Registers_mips_n64
 #elif defined(__mips__)
-# warning The MIPS architecture is not supported.
+# warning The MIPS architecture is not supported with this ABI and environment!
 #else
 # error Architecture not supported
 #endif
Index: src/config.h
===
--- src/config.h
+++ src/config.h
@@ -67,7 +67,7 @@
 defined(__ppc__) || defined(__ppc64__) ||  \
 (!defined(__APPLE__) && defined(__arm__)) ||   \
 (defined(__arm64__) || defined(__aarch64__)) ||\
-(defined(__APPLE__) && defined(__mips__))
+defined(__mips__)
 #define _LIBUNWIND_BUILD_ZERO_COST_APIS
 #endif
 
Index: src/UnwindRegistersSave.S
===
--- src/UnwindRegistersSave.S
+++ src/UnwindRegistersSave.S
@@ -116,6 +116,118 @@
   xorl  %eax, %eax# return UNW_ESUCCESS
   ret
 
+#elif defined(__mips__) && defined(_ABIO32) && defined(__mips_soft_float)
+
+#
+# extern int unw_getcontext(unw_context_t* thread_state)
+#
+# On entry:
+#  thread_state pointer is in a0 ($4)
+#
+DEFINE_LIBUNWIND_FUNCTION(unw_getcontext)
+  .set push
+  .set noat
+  .set noreorder
+  .set nomacro
+  sw$1, (4 * 1)($4)
+  sw$2, (4 * 2)($4)
+  sw$3, (4 * 3)($4)
+  sw$4, (4 * 4)($4)
+  sw$5, (4 * 5)($4)
+  sw$6, (4 * 6)($4)
+  sw$7, (4 * 7)($4)
+  sw$8, (4 * 8)($4)
+  sw$9, (4 * 9)($4)
+  sw$10, (4 * 10)($4)
+  sw$11, (4 * 11)($4)
+  sw$12, (4 * 12)($4)
+  sw$13, (4 * 13)($4)
+  sw$14, (4 * 14)($4)
+  sw$15, (4 * 15)($4)
+  sw$16, (4 * 16)($4)
+  sw$17, (4 * 17)($4)
+  sw$18, (4 * 18)($4)
+  sw$19, (4 * 19)($4)
+  sw$20, (4 * 20)($4)
+  sw$21, (4 * 21)($4)
+  sw$22, (4 * 22)($4)
+  sw$23, (4 * 23)($4)
+  sw$24, (4 * 24)($4)
+  sw$25, (4 * 25)($4)
+  sw$26, (4 * 26)($4)
+  sw$27, (4 * 27)($4)
+  sw$28, (4 * 28)($4)
+  sw$29, (4 * 29)($4)
+  sw$30, (4 * 30)($4)
+  sw$31, (4 * 31)($4)
+  # Store return address to pc
+  sw$31, (4 * 32)($4)
+  # hi and lo
+  mfhi  $8
+  sw$8,  (4 * 33)($4)
+  mflo  $8
+  sw$8,  (4 * 34)($4)
+  jr	$31
+  # return UNW_ESUCCESS
+  or$2, $0, $0
+  .set pop
+
+#elif defined(__mips__) && defined(_ABI64) && defined(__mips_soft_float)
+
+#
+# extern int unw_getcontext(unw_context_t* thread_state)
+#
+# On entry:
+#  thread_state pointer is in a0 ($4)
+#
+DEFINE_LIBUNWIND_FUNCTION(unw_getcontext)
+  .set push
+  .set noat
+  .set noreorder
+  .set nomacro
+  sd$1, (8 * 1)($4)
+  sd$2, (8 * 2)($4)
+  sd$3, (8 * 3)($4)
+  sd$4, (8 * 4)($4)
+  sd$5, (8 * 5)($4)
+  sd$6, (8 * 6)($4)
+  sd$7, (8 * 7)($4)
+  sd$8, (8 * 8)($4)
+  sd$9, (8 * 9)($4)
+  sd$10, (8 * 10)($4)
+  sd$11, (8 * 11)($4)
+  sd$12, (8 * 12)($4)
+  sd$13, (8 * 13)($4)
+  sd$14, (8 * 14)($4)
+  sd$15, (8 * 15)($4)
+  sd$16, (8 * 16)($4)
+  sd$17, (8 * 17)($4)
+  sd$18, (8 * 18)($4)
+  sd$19, (8 * 19)($4)
+  sd$20, (8 * 20)($4)
+  sd$21, (8 * 21)($4)
+  sd$22, (8 * 22)($4)
+  sd$23, (8 * 23)($4)
+  sd$24, (8 * 24)($4)
+  sd$25, (8 * 25)($4)
+  sd$26, (8 * 26)($4)
+  sd$27, (8 * 27)($4)
+  sd$28, (8 * 28)($4)
+  sd$29, (8 * 29)($4)
+  sd$30, (8 * 30)($4)
+  sd$31, (8 * 31)($4)
+  # Store return address to pc
+  sd$31, (8 * 32)($4)
+  # hi and lo
+  mfhi  $8
+  sd$8,  (8 * 33)($4)
+  mflo  $8
+  sd$8,  (8 * 34)($4)
+  jr	$31
+  # return UNW_ESUCCESS
+  or$2, $0, $0
+  .set pop
+
 # elif defined(__mips__)
 
 #
Index: src/UnwindRegistersRestore.S
===
--- src/UnwindRegistersRestore.S
+++ src/UnwindRegistersRestore.S
@@ -524,6 +524,118 @@
   l.jr r9
l.nop
 
+#elif defined(__mips__) && defined(_ABIO32) && defined(__mips_soft_float)
+
+//
+// void libunwind::Registers_mips_o32::jumpto()
+//
+// On entry:
+//  thread state pointer is in a0 ($4)
+//
+DEFINE_LIBUNWIND_PRIVATE_FUNCTION(_ZN9libunwind18Registers_mips_o326jumptoEv)
+

[PATCH] D34030: Fix the postorder visting of the ClassTemplateSpecializationDecl nodes in the RecursiveASTVisitor.

2017-10-27 Thread Peter Siket via Phabricator via cfe-commits
MontyKutyi added a reviewer: bruno.
MontyKutyi added a comment.

Ping.


https://reviews.llvm.org/D34030



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


[PATCH] D39074: [libunwind][MIPS]: Add support for unwinding in N32 processes.

2017-10-27 Thread John Baldwin via Phabricator via cfe-commits
bsdjhb updated this revision to Diff 120624.
bsdjhb added a comment.

- Rebase after MAX_REGISTER change.


https://reviews.llvm.org/D39074

Files:
  include/__libunwind_config.h
  src/AddressSpace.hpp
  src/DwarfInstructions.hpp
  src/Registers.hpp
  src/UnwindCursor.hpp
  src/UnwindRegistersRestore.S
  src/UnwindRegistersSave.S
  src/libunwind.cpp

Index: src/libunwind.cpp
===
--- src/libunwind.cpp
+++ src/libunwind.cpp
@@ -61,8 +61,9 @@
 # define REGISTER_KIND Registers_or1k
 #elif defined(__mips__) && defined(_ABIO32) && defined(__mips_soft_float)
 # define REGISTER_KIND Registers_mips_o32
-#elif defined(__mips__) && defined(_ABI64) && defined(__mips_soft_float)
-# define REGISTER_KIND Registers_mips_n64
+#elif defined(__mips__) && (defined(_ABIN32) || defined(_ABI64)) &&\
+defined(__mips_soft_float)
+# define REGISTER_KIND Registers_mips_newabi
 #elif defined(__mips__)
 # warning The MIPS architecture is not supported with this ABI and environment!
 #else
Index: src/UnwindRegistersSave.S
===
--- src/UnwindRegistersSave.S
+++ src/UnwindRegistersSave.S
@@ -172,7 +172,8 @@
   or$2, $0, $0
   .set pop
 
-#elif defined(__mips__) && defined(_ABI64) && defined(__mips_soft_float)
+#elif defined(__mips__) && (defined(_ABI64) || defined(_ABIN32)) &&\
+defined(__mips_soft_float)
 
 #
 # extern int unw_getcontext(unw_context_t* thread_state)
Index: src/UnwindRegistersRestore.S
===
--- src/UnwindRegistersRestore.S
+++ src/UnwindRegistersRestore.S
@@ -580,15 +580,16 @@
   lw$4, (4 * 4)($4)
   .set pop
 
-#elif defined(__mips__) && defined(_ABI64) && defined(__mips_soft_float)
+#elif defined(__mips__) && (defined(_ABI64) || defined(_ABIN32)) &&\
+defined(__mips_soft_float)
 
 //
-// void libunwind::Registers_mips_n64::jumpto()
+// void libunwind::Registers_mips_newabi::jumpto()
 //
 // On entry:
 //  thread state pointer is in a0 ($4)
 //
-DEFINE_LIBUNWIND_PRIVATE_FUNCTION(_ZN9libunwind18Registers_mips_n646jumptoEv)
+DEFINE_LIBUNWIND_PRIVATE_FUNCTION(_ZN9libunwind21Registers_mips_newabi6jumptoEv)
   .set push
   .set noat
   .set noreorder
Index: src/UnwindCursor.hpp
===
--- src/UnwindCursor.hpp
+++ src/UnwindCursor.hpp
@@ -514,8 +514,8 @@
   }
 #endif
 
-#if defined(_LIBUNWIND_TARGET_MIPS_N64)
-  int stepWithCompactEncoding(Registers_mips_n64 &) {
+#if defined(_LIBUNWIND_TARGET_MIPS_NEWABI)
+  int stepWithCompactEncoding(Registers_mips_newabi &) {
 return UNW_EINVAL;
   }
 #endif
@@ -570,8 +570,8 @@
   }
 #endif
 
-#if defined(_LIBUNWIND_TARGET_MIPS_N64)
-  bool compactSaysUseDwarf(Registers_mips_n64 &, uint32_t *) const {
+#if defined(_LIBUNWIND_TARGET_MIPS_NEWABI)
+  bool compactSaysUseDwarf(Registers_mips_newabi &, uint32_t *) const {
 return true;
   }
 #endif
@@ -619,8 +619,8 @@
   }
 #endif
 
-#if defined (_LIBUNWIND_TARGET_MIPS_N64)
-  compact_unwind_encoding_t dwarfEncoding(Registers_mips_n64 &) const {
+#if defined (_LIBUNWIND_TARGET_MIPS_NEWABI)
+  compact_unwind_encoding_t dwarfEncoding(Registers_mips_newabi &) const {
 return 0;
   }
 #endif
Index: src/Registers.hpp
===
--- src/Registers.hpp
+++ src/Registers.hpp
@@ -2247,13 +2247,13 @@
 }
 #endif // _LIBUNWIND_TARGET_MIPS_O32
 
-#if defined(_LIBUNWIND_TARGET_MIPS_N64)
-/// Registers_mips_n64 holds the register state of a thread in a 64-bit MIPS
-/// process.
-class _LIBUNWIND_HIDDEN Registers_mips_n64 {
+#if defined(_LIBUNWIND_TARGET_MIPS_NEWABI)
+/// Registers_mips_newabi holds the register state of a thread in a NEWABI
+/// MIPS process including both the N32 and N64 ABIs.
+class _LIBUNWIND_HIDDEN Registers_mips_newabi {
 public:
-  Registers_mips_n64();
-  Registers_mips_n64(const void *registers);
+  Registers_mips_newabi();
+  Registers_mips_newabi(const void *registers);
 
   boolvalidRegister(int num) const;
   uint64_tgetRegister(int num) const;
@@ -2274,28 +2274,28 @@
   void  setIP(uint64_t value) { _registers.__pc = value; }
 
 private:
-  struct mips_n64_thread_state_t {
+  struct mips_newabi_thread_state_t {
 uint64_t __r[32];
 uint64_t __pc;
 uint64_t __hi;
 uint64_t __lo;
   };
 
-  mips_n64_thread_state_t _registers;
+  mips_newabi_thread_state_t _registers;
 };
 
-inline Registers_mips_n64::Registers_mips_n64(const void *registers) {
-  static_assert((check_fit::does_fit),
-"mips_n64 registers do not fit into unw_context_t");
+inline Registers_mips_newabi::Registers_mips_newabi(const void *registers) {
+  static_assert((check_fit::does_fit),
+"mips_newabi registers do not fit into unw_context_t");
   memcpy(&_registers, static_cast(registers),
  sizeof(_registers));
 }
 
-inline Regis

Re: [libunwind] r316745 - Express Registers_*::lastDwarfReg using _LIBUNWIND_HIGHEST_DWARF_REGISTER

2017-10-27 Thread John Baldwin via cfe-commits
On 10/27/17 8:59 AM, Martin Storsjo via cfe-commits wrote:
> Author: mstorsjo
> Date: Fri Oct 27 00:59:01 2017
> New Revision: 316745
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=316745&view=rev
> Log:
> Express Registers_*::lastDwarfReg using _LIBUNWIND_HIGHEST_DWARF_REGISTER
> 
> This avoids having to keep the same information duplicated in multiple
> places.
> 
> Adjust _LIBUNWIND_HIGHEST_DWARF_REGISTER to actually have the value
> of the highest used register and only use the value
> _LIBUNWIND_HIGHEST_DWARF_REGISTER + 1 (kMaxRegisterNumber + 1) for
> allocating the savedRegisters array.

Sorry I didn't realize it during the review, but I've just realized why
using HIGHEST_DWARF_REGISTER is not correct in the various Register classes.
If you are building without _LIBUNWIND_IS_NATIVE_ONLY defined, then you
will end up with all of the Register classes returning the same value
(119 from the end of __libunwind_config.h) instead of the architecture-specific
value.  This is a change in behavior, so the Registers.hpp portion of this
change should perhaps be reverted.

> Differential Revision: https://reviews.llvm.org/D39281
> 
> Modified:
> libunwind/trunk/include/__libunwind_config.h
> libunwind/trunk/src/DwarfInstructions.hpp
> libunwind/trunk/src/DwarfParser.hpp
> libunwind/trunk/src/Registers.hpp
> 
> Modified: libunwind/trunk/include/__libunwind_config.h
> URL: 
> http://llvm.org/viewvc/llvm-project/libunwind/trunk/include/__libunwind_config.h?rev=316745&r1=316744&r2=316745&view=diff
> ==
> --- libunwind/trunk/include/__libunwind_config.h (original)
> +++ libunwind/trunk/include/__libunwind_config.h Fri Oct 27 00:59:01 2017
> @@ -20,22 +20,22 @@
>  #  define _LIBUNWIND_TARGET_I386
>  #  define _LIBUNWIND_CONTEXT_SIZE 8
>  #  define _LIBUNWIND_CURSOR_SIZE 19
> -#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 9
> +#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 8
>  # elif defined(__x86_64__)
>  #  define _LIBUNWIND_TARGET_X86_64 1
>  #  define _LIBUNWIND_CONTEXT_SIZE 21
>  #  define _LIBUNWIND_CURSOR_SIZE 33
> -#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 17
> +#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 16
>  # elif defined(__ppc__)
>  #  define _LIBUNWIND_TARGET_PPC 1
>  #  define _LIBUNWIND_CONTEXT_SIZE 117
>  #  define _LIBUNWIND_CURSOR_SIZE 128
> -#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 113
> +#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 112
>  # elif defined(__aarch64__)
>  #  define _LIBUNWIND_TARGET_AARCH64 1
>  #  define _LIBUNWIND_CONTEXT_SIZE 66
>  #  define _LIBUNWIND_CURSOR_SIZE 78
> -#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 96
> +#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 95
>  # elif defined(__arm__)
>  #  define _LIBUNWIND_TARGET_ARM 1
>  #  if defined(__ARM_WMMX)
> @@ -45,12 +45,12 @@
>  #define _LIBUNWIND_CONTEXT_SIZE 42
>  #define _LIBUNWIND_CURSOR_SIZE 49
>  #  endif
> -#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 96
> +#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 95
>  # elif defined(__or1k__)
>  #  define _LIBUNWIND_TARGET_OR1K 1
>  #  define _LIBUNWIND_CONTEXT_SIZE 16
>  #  define _LIBUNWIND_CURSOR_SIZE 28
> -#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 32
> +#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 31
>  # else
>  #  error "Unsupported architecture."
>  # endif
> @@ -63,7 +63,7 @@
>  # define _LIBUNWIND_TARGET_OR1K 1
>  # define _LIBUNWIND_CONTEXT_SIZE 128
>  # define _LIBUNWIND_CURSOR_SIZE 140
> -# define _LIBUNWIND_HIGHEST_DWARF_REGISTER 120
> +# define _LIBUNWIND_HIGHEST_DWARF_REGISTER 119
>  #endif // _LIBUNWIND_IS_NATIVE_ONLY
>  
>  #endif // LIBUNWIND_CONFIG_H__
> 
> Modified: libunwind/trunk/src/DwarfInstructions.hpp
> URL: 
> http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/DwarfInstructions.hpp?rev=316745&r1=316744&r2=316745&view=diff
> ==
> --- libunwind/trunk/src/DwarfInstructions.hpp (original)
> +++ libunwind/trunk/src/DwarfInstructions.hpp Fri Oct 27 00:59:01 2017
> @@ -167,7 +167,7 @@ int DwarfInstructions::stepWithDwa
>R newRegisters = registers;
>pint_t returnAddress = 0;
>const int lastReg = R::lastDwarfRegNum();
> -  assert((int)CFI_Parser::kMaxRegisterNumber > lastReg &&
> +  assert(static_cast(CFI_Parser::kMaxRegisterNumber) >= lastReg 
> &&
>   "register range too large");
>assert(lastReg >= (int)cieInfo.returnAddressRegister &&
>   "register range does not contain return address register");
> 
> Modified: libunwind/trunk/src/DwarfParser.hpp
> URL: 
> http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/DwarfParser.hpp?rev=316745&r1=316744&r2=316745&view=diff
> ==
> --- libunwind/trunk/src/DwarfParser.hpp (original)
> +++ libunwind/trunk/src/DwarfParser.hpp Fri Oct 27 00:59:01 2017
> @@ -87,7 +87,7 @@ public:
>  uint32_t 

[PATCH] D36347: New lldb python module for adding diagnostic breakpoints

2017-10-27 Thread Don Hinton via Phabricator via cfe-commits
hintonda updated this revision to Diff 120628.
hintonda added a comment.

- Add support for individual DiagID's, and print out number of breakpoints 
added.


https://reviews.llvm.org/D36347

Files:
  utils/clangdiag.py

Index: utils/clangdiag.py
===
--- /dev/null
+++ utils/clangdiag.py
@@ -0,0 +1,192 @@
+#!/usr/bin/python
+
+#--
+# Be sure to add the python path that points to the LLDB shared library.
+#
+# # To use this in the embedded python interpreter using "lldb" just
+# import it with the full path using the "command script import"
+# command
+#   (lldb) command script import /path/to/clandiag.py
+#--
+
+import lldb
+import argparse
+import commands
+import shlex
+import os
+import re
+import subprocess
+
+class MyParser(argparse.ArgumentParser):
+def format_help(self):
+return ''' Commands for managing clang diagnostic breakpoints
+
+Syntax: clangdiag enable [|]
+clangdiag disable
+clangdiag diagtool [|reset]
+
+The following subcommands are supported:
+
+  enable   -- Enable clang diagnostic breakpoints.
+  disable  -- Disable all clang diagnostic breakpoints.
+  diagtool -- Return, set, or reset diagtool path.
+
+This command sets breakpoints in clang, and clang based tools, that
+emit diagnostics.  When a diagnostic is emitted, and clangdiag is
+enabled, it will use the appropriate diagtool application to determine
+the name of the DiagID, and set breakpoints in all locations that
+'diag::name' appears in the source.  Since the new breakpoints are set
+after they are encountered, users will need to launch the executable a
+second time in order to hit the new breakpoints.
+
+For in-tree builds, the diagtool application, used to map DiagID's to
+names, is found automatically in the same directory as the target
+executable.  However, out-or-tree builds must use the 'diagtool'
+subcommand to set the appropriate path for diagtool in the clang debug
+bin directory.  Since this mapping is created at build-time, it's
+important for users to use the same version that was generated when
+clang was compiled, or else the id's won't match.
+
+Notes:
+- Substrings can be passed for both  and .
+- If  is passed, only enable the DiagID(s) for that warning.
+- If  is passed, only enable that DiagID.
+- Rerunning enable clears existing breakpoints.
+- diagtool is used in breakpoint callbacks, so it can be changed
+  without the need to rerun enable.
+- Adding this to your ~.lldbinit file makes clangdiag available at startup:
+  "command script import /path/to/clangdiag.py"
+
+'''
+
+def create_diag_options():
+parser = MyParser(prog='clangdiag')
+subparsers = parser.add_subparsers(
+title='subcommands',
+dest='subcommands',
+metavar='')
+disable_parser = subparsers.add_parser('disable')
+enable_parser = subparsers.add_parser('enable')
+enable_parser.add_argument('id', nargs='?')
+diagtool_parser = subparsers.add_parser('diagtool')
+diagtool_parser.add_argument('path', nargs='?')
+return parser
+
+def getDiagtool(target, diagtool = None):
+id = target.GetProcess().GetProcessID()
+if 'diagtool' not in getDiagtool.__dict__:
+getDiagtool.diagtool = {}
+if diagtool:
+if diagtool == 'reset':
+getDiagtool.diagtool[id] = None
+elif os.path.exists(diagtool):
+getDiagtool.diagtool[id] = diagtool
+else:
+print('clangdiag: %s not found.' % diagtool)
+if not id in getDiagtool.diagtool or not getDiagtool.diagtool[id]:
+getDiagtool.diagtool[id] = None
+exe = target.GetExecutable()
+if not exe.Exists():
+print('clangdiag: Target (%s) not set.' % exe.GetFilename())
+else:
+diagtool = os.path.join(exe.GetDirectory(), 'diagtool')
+if os.path.exists(diagtool):
+getDiagtool.diagtool[id] = diagtool
+else:
+print('clangdiag: diagtool not found along side %s' % exe)
+
+return getDiagtool.diagtool[id]
+
+def setDiagBreakpoint(frame, bp_loc, dict):
+id = frame.FindVariable("DiagID").GetValue()
+if id is None:
+print('clangdiag: id is None')
+return False
+
+# Don't need to test this time, since we did that in enable.
+target = frame.GetThread().GetProcess().GetTarget()
+diagtool = getDiagtool(target)
+name = subprocess.check_output([diagtool, "find-diagnostic-id", id]).rstrip();
+# Make sure we only consider errors, warnings, and extentions.
+# FIXME: Make this configurable?
+prefixes = ['err_', 'warn_', 'exp_']
+if len([prefix for prefix in prefixes+[''] if name.startswith(prefix)][0]):
+bp = target.BreakpointCreateBySourceRegex(name, lldb.SBFileSpec())
+bp.AddName("clang::Dia

[clang-tools-extra] r316770 - [clangd] Harden clangd a bit against garbage input.

2017-10-27 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Fri Oct 27 09:33:15 2017
New Revision: 316770

URL: http://llvm.org/viewvc/llvm-project?rev=316770&view=rev
Log:
[clangd] Harden clangd a bit against garbage input.

There can be nullptrs here if the YAML fails to parse. Found by
clangd-fuzzer!

Modified:
clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp

Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp?rev=316770&r1=316769&r2=316770&view=diff
==
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original)
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Fri Oct 27 09:33:15 
2017
@@ -88,11 +88,7 @@ bool JSONRPCDispatcher::call(StringRef C
   if (Doc == YAMLStream.end())
 return false;
 
-  auto *Root = Doc->getRoot();
-  if (!Root)
-return false;
-
-  auto *Object = dyn_cast(Root);
+  auto *Object = dyn_cast_or_null(Doc->getRoot());
   if (!Object)
 return false;
 
@@ -101,7 +97,8 @@ bool JSONRPCDispatcher::call(StringRef C
   llvm::yaml::MappingNode *Params = nullptr;
   llvm::yaml::ScalarNode *Id = nullptr;
   for (auto &NextKeyValue : *Object) {
-auto *KeyString = dyn_cast(NextKeyValue.getKey());
+auto *KeyString =
+dyn_cast_or_null(NextKeyValue.getKey());
 if (!KeyString)
   return false;
 


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


[PATCH] D39375: [clang] Add PPCallbacks list to preprocessor when building a preacompiled preamble.

2017-10-27 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added a comment.

Can you revert the formatting changes in places you haven’t touched (mainly 
astunit.cpp)? I think you should be able to do that with git checkout -p HEAD~1


https://reviews.llvm.org/D39375



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


LLVM buildmaster will be updated and restarted tonight

2017-10-27 Thread Galina Kistanova via cfe-commits
Hello everyone,

LLVM buildmaster will be updated and restarted after 7 PM Pacific time.

Thanks

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


[PATCH] D38110: [libunwind][MIPS]: Add support for unwinding in O32 and N64 processes.

2017-10-27 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added inline comments.



Comment at: include/__libunwind_config.h:69
+#  define _LIBUNWIND_CURSOR_SIZE 47
+#  define _LIBUNWIND_HIGHEST_DWARF_REGISTER 65
 # else

Can we sink the two cases into the `__mips__` case?  Something like:

#if defined(__mips__)
# if defined(_ABIO32)
# elif defined(_ABIO64)
# elif defined(_ABIN32)
# elif defined(_ABI64)
# else
#   error "unknown MIPS ABI"
# endif
#else



Comment at: src/Registers.hpp:2063
+  voidjumpto();
+  static int  lastDwarfRegNum() { return 31; }
+

I believe we have a macro for this.


https://reviews.llvm.org/D38110



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


[PATCH] D36347: New lldb python module for adding diagnostic breakpoints

2017-10-27 Thread Don Hinton via Phabricator via cfe-commits
hintonda updated this revision to Diff 120629.
hintonda added a comment.

- Remove whitespace.


https://reviews.llvm.org/D36347

Files:
  utils/clangdiag.py

Index: utils/clangdiag.py
===
--- /dev/null
+++ utils/clangdiag.py
@@ -0,0 +1,192 @@
+#!/usr/bin/python
+
+#--
+# Be sure to add the python path that points to the LLDB shared library.
+#
+# # To use this in the embedded python interpreter using "lldb" just
+# import it with the full path using the "command script import"
+# command
+#   (lldb) command script import /path/to/clandiag.py
+#--
+
+import lldb
+import argparse
+import commands
+import shlex
+import os
+import re
+import subprocess
+
+class MyParser(argparse.ArgumentParser):
+def format_help(self):
+return ''' Commands for managing clang diagnostic breakpoints
+
+Syntax: clangdiag enable [|]
+clangdiag disable
+clangdiag diagtool [|reset]
+
+The following subcommands are supported:
+
+  enable   -- Enable clang diagnostic breakpoints.
+  disable  -- Disable all clang diagnostic breakpoints.
+  diagtool -- Return, set, or reset diagtool path.
+
+This command sets breakpoints in clang, and clang based tools, that
+emit diagnostics.  When a diagnostic is emitted, and clangdiag is
+enabled, it will use the appropriate diagtool application to determine
+the name of the DiagID, and set breakpoints in all locations that
+'diag::name' appears in the source.  Since the new breakpoints are set
+after they are encountered, users will need to launch the executable a
+second time in order to hit the new breakpoints.
+
+For in-tree builds, the diagtool application, used to map DiagID's to
+names, is found automatically in the same directory as the target
+executable.  However, out-or-tree builds must use the 'diagtool'
+subcommand to set the appropriate path for diagtool in the clang debug
+bin directory.  Since this mapping is created at build-time, it's
+important for users to use the same version that was generated when
+clang was compiled, or else the id's won't match.
+
+Notes:
+- Substrings can be passed for both  and .
+- If  is passed, only enable the DiagID(s) for that warning.
+- If  is passed, only enable that DiagID.
+- Rerunning enable clears existing breakpoints.
+- diagtool is used in breakpoint callbacks, so it can be changed
+  without the need to rerun enable.
+- Adding this to your ~.lldbinit file makes clangdiag available at startup:
+  "command script import /path/to/clangdiag.py"
+
+'''
+
+def create_diag_options():
+parser = MyParser(prog='clangdiag')
+subparsers = parser.add_subparsers(
+title='subcommands',
+dest='subcommands',
+metavar='')
+disable_parser = subparsers.add_parser('disable')
+enable_parser = subparsers.add_parser('enable')
+enable_parser.add_argument('id', nargs='?')
+diagtool_parser = subparsers.add_parser('diagtool')
+diagtool_parser.add_argument('path', nargs='?')
+return parser
+
+def getDiagtool(target, diagtool = None):
+id = target.GetProcess().GetProcessID()
+if 'diagtool' not in getDiagtool.__dict__:
+getDiagtool.diagtool = {}
+if diagtool:
+if diagtool == 'reset':
+getDiagtool.diagtool[id] = None
+elif os.path.exists(diagtool):
+getDiagtool.diagtool[id] = diagtool
+else:
+print('clangdiag: %s not found.' % diagtool)
+if not id in getDiagtool.diagtool or not getDiagtool.diagtool[id]:
+getDiagtool.diagtool[id] = None
+exe = target.GetExecutable()
+if not exe.Exists():
+print('clangdiag: Target (%s) not set.' % exe.GetFilename())
+else:
+diagtool = os.path.join(exe.GetDirectory(), 'diagtool')
+if os.path.exists(diagtool):
+getDiagtool.diagtool[id] = diagtool
+else:
+print('clangdiag: diagtool not found along side %s' % exe)
+
+return getDiagtool.diagtool[id]
+
+def setDiagBreakpoint(frame, bp_loc, dict):
+id = frame.FindVariable("DiagID").GetValue()
+if id is None:
+print('clangdiag: id is None')
+return False
+
+# Don't need to test this time, since we did that in enable.
+target = frame.GetThread().GetProcess().GetTarget()
+diagtool = getDiagtool(target)
+name = subprocess.check_output([diagtool, "find-diagnostic-id", id]).rstrip();
+# Make sure we only consider errors, warnings, and extentions.
+# FIXME: Make this configurable?
+prefixes = ['err_', 'warn_', 'exp_']
+if len([prefix for prefix in prefixes+[''] if name.startswith(prefix)][0]):
+bp = target.BreakpointCreateBySourceRegex(name, lldb.SBFileSpec())
+bp.AddName("clang::Diagnostic")
+
+return False
+
+def enable(exe_ctx, args):
+ 

[PATCH] D38985: [refactor] Add support for editor commands that connect IDEs/editors to the refactoring actions

2017-10-27 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: lib/Tooling/Refactoring/RefactoringActions.cpp:28
+
+// FIXME: Remove the Actions alltogether.
+class ExtractRefactoring final : public RefactoringAction {

ioeric wrote:
> Maybe I'm missing the context here... Why do we want to remove the actions?
There's now some redundancy between the command/description in action and the 
actual refactoring classes like ExtractFunction.
Remove might be a bad term here, something like rewrite would be better. I will 
change this in the commit.


Repository:
  rL LLVM

https://reviews.llvm.org/D38985



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


r316773 - New lldb python module for managing diagnostic breakpoints

2017-10-27 Thread Don Hinton via cfe-commits
Author: dhinton
Date: Fri Oct 27 10:02:33 2017
New Revision: 316773

URL: http://llvm.org/viewvc/llvm-project?rev=316773&view=rev
Log:
New lldb python module for managing diagnostic breakpoints

Summary:
Can be used to set breakpoints for either the diagnostics actually
emitted for the current compilation, a particular DiagID, or all
DiagIDs for a particular warning.

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

Added:
cfe/trunk/utils/clangdiag.py   (with props)

Added: cfe/trunk/utils/clangdiag.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/clangdiag.py?rev=316773&view=auto
==
--- cfe/trunk/utils/clangdiag.py (added)
+++ cfe/trunk/utils/clangdiag.py Fri Oct 27 10:02:33 2017
@@ -0,0 +1,192 @@
+#!/usr/bin/python
+
+#--
+# Be sure to add the python path that points to the LLDB shared library.
+#
+# # To use this in the embedded python interpreter using "lldb" just
+# import it with the full path using the "command script import"
+# command
+#   (lldb) command script import /path/to/clandiag.py
+#--
+
+import lldb
+import argparse
+import commands
+import shlex
+import os
+import re
+import subprocess
+
+class MyParser(argparse.ArgumentParser):
+def format_help(self):
+return ''' Commands for managing clang diagnostic breakpoints
+
+Syntax: clangdiag enable [|]
+clangdiag disable
+clangdiag diagtool [|reset]
+
+The following subcommands are supported:
+
+  enable   -- Enable clang diagnostic breakpoints.
+  disable  -- Disable all clang diagnostic breakpoints.
+  diagtool -- Return, set, or reset diagtool path.
+
+This command sets breakpoints in clang, and clang based tools, that
+emit diagnostics.  When a diagnostic is emitted, and clangdiag is
+enabled, it will use the appropriate diagtool application to determine
+the name of the DiagID, and set breakpoints in all locations that
+'diag::name' appears in the source.  Since the new breakpoints are set
+after they are encountered, users will need to launch the executable a
+second time in order to hit the new breakpoints.
+
+For in-tree builds, the diagtool application, used to map DiagID's to
+names, is found automatically in the same directory as the target
+executable.  However, out-or-tree builds must use the 'diagtool'
+subcommand to set the appropriate path for diagtool in the clang debug
+bin directory.  Since this mapping is created at build-time, it's
+important for users to use the same version that was generated when
+clang was compiled, or else the id's won't match.
+
+Notes:
+- Substrings can be passed for both  and .
+- If  is passed, only enable the DiagID(s) for that warning.
+- If  is passed, only enable that DiagID.
+- Rerunning enable clears existing breakpoints.
+- diagtool is used in breakpoint callbacks, so it can be changed
+  without the need to rerun enable.
+- Adding this to your ~.lldbinit file makes clangdiag available at startup:
+  "command script import /path/to/clangdiag.py"
+
+'''
+
+def create_diag_options():
+parser = MyParser(prog='clangdiag')
+subparsers = parser.add_subparsers(
+title='subcommands',
+dest='subcommands',
+metavar='')
+disable_parser = subparsers.add_parser('disable')
+enable_parser = subparsers.add_parser('enable')
+enable_parser.add_argument('id', nargs='?')
+diagtool_parser = subparsers.add_parser('diagtool')
+diagtool_parser.add_argument('path', nargs='?')
+return parser
+
+def getDiagtool(target, diagtool = None):
+id = target.GetProcess().GetProcessID()
+if 'diagtool' not in getDiagtool.__dict__:
+getDiagtool.diagtool = {}
+if diagtool:
+if diagtool == 'reset':
+getDiagtool.diagtool[id] = None
+elif os.path.exists(diagtool):
+getDiagtool.diagtool[id] = diagtool
+else:
+print('clangdiag: %s not found.' % diagtool)
+if not id in getDiagtool.diagtool or not getDiagtool.diagtool[id]:
+getDiagtool.diagtool[id] = None
+exe = target.GetExecutable()
+if not exe.Exists():
+print('clangdiag: Target (%s) not set.' % exe.GetFilename())
+else:
+diagtool = os.path.join(exe.GetDirectory(), 'diagtool')
+if os.path.exists(diagtool):
+getDiagtool.diagtool[id] = diagtool
+else:
+print('clangdiag: diagtool not found along side %s' % exe)
+
+return getDiagtool.diagtool[id]
+
+def setDiagBreakpoint(frame, bp_loc, dict):
+id = frame.FindVariable("DiagID").GetValue()
+if id is None:
+print('clangdiag: id is None')
+return False
+
+# Don't need to test this time, since we did that in enable.
+target = frame.GetThread().GetProcess().GetTarget()
+diagtool = get

[clang-tools-extra] r316774 - [clangd] Don't crash on extremely large JSON messages.

2017-10-27 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Fri Oct 27 10:06:41 2017
New Revision: 316774

URL: http://llvm.org/viewvc/llvm-project?rev=316774&view=rev
Log:
[clangd] Don't crash on extremely large JSON messages.

Found by clangd-fuzzer.

Added:
clang-tools-extra/trunk/test/clangd/too_large.test
Modified:
clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp

Modified: clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp?rev=316774&r1=316773&r2=316774&view=diff
==
--- clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp (original)
+++ clang-tools-extra/trunk/clangd/JSONRPCDispatcher.cpp Fri Oct 27 10:06:41 
2017
@@ -196,6 +196,15 @@ void clangd::runLanguageServerLoop(std::
   }
 }
 
+// Guard against large messages. This is usually a bug in the client code
+// and we don't want to crash downstream because of it.
+if (ContentLength > 1 << 30) { // 1024M
+  In.ignore(ContentLength);
+  Out.log("Skipped overly large message of " + Twine(ContentLength) +
+  " bytes.\n");
+  continue;
+}
+
 if (ContentLength > 0) {
   // Now read the JSON. Insert a trailing null byte as required by the YAML
   // parser.

Added: clang-tools-extra/trunk/test/clangd/too_large.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/too_large.test?rev=316774&view=auto
==
--- clang-tools-extra/trunk/test/clangd/too_large.test (added)
+++ clang-tools-extra/trunk/test/clangd/too_large.test Fri Oct 27 10:06:41 2017
@@ -0,0 +1,7 @@
+# RUN: not clangd -run-synchronously < %s 2>&1 | FileCheck 
-check-prefix=STDERR %s
+# vim: fileformat=dos
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 2147483648
+
+# STDERR: Skipped overly large message


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


[PATCH] D37470: [analyzer] Handle ObjC messages conservatively in CallDescription

2017-10-27 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

Thanks Gabor. Looks great to me!


https://reviews.llvm.org/D37470



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


[PATCH] D36347: New lldb python module for adding diagnostic breakpoints

2017-10-27 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316773: New lldb python module for managing diagnostic 
breakpoints (authored by dhinton).

Repository:
  rL LLVM

https://reviews.llvm.org/D36347

Files:
  cfe/trunk/utils/clangdiag.py

Index: cfe/trunk/utils/clangdiag.py
===
--- cfe/trunk/utils/clangdiag.py
+++ cfe/trunk/utils/clangdiag.py
@@ -0,0 +1,192 @@
+#!/usr/bin/python
+
+#--
+# Be sure to add the python path that points to the LLDB shared library.
+#
+# # To use this in the embedded python interpreter using "lldb" just
+# import it with the full path using the "command script import"
+# command
+#   (lldb) command script import /path/to/clandiag.py
+#--
+
+import lldb
+import argparse
+import commands
+import shlex
+import os
+import re
+import subprocess
+
+class MyParser(argparse.ArgumentParser):
+def format_help(self):
+return ''' Commands for managing clang diagnostic breakpoints
+
+Syntax: clangdiag enable [|]
+clangdiag disable
+clangdiag diagtool [|reset]
+
+The following subcommands are supported:
+
+  enable   -- Enable clang diagnostic breakpoints.
+  disable  -- Disable all clang diagnostic breakpoints.
+  diagtool -- Return, set, or reset diagtool path.
+
+This command sets breakpoints in clang, and clang based tools, that
+emit diagnostics.  When a diagnostic is emitted, and clangdiag is
+enabled, it will use the appropriate diagtool application to determine
+the name of the DiagID, and set breakpoints in all locations that
+'diag::name' appears in the source.  Since the new breakpoints are set
+after they are encountered, users will need to launch the executable a
+second time in order to hit the new breakpoints.
+
+For in-tree builds, the diagtool application, used to map DiagID's to
+names, is found automatically in the same directory as the target
+executable.  However, out-or-tree builds must use the 'diagtool'
+subcommand to set the appropriate path for diagtool in the clang debug
+bin directory.  Since this mapping is created at build-time, it's
+important for users to use the same version that was generated when
+clang was compiled, or else the id's won't match.
+
+Notes:
+- Substrings can be passed for both  and .
+- If  is passed, only enable the DiagID(s) for that warning.
+- If  is passed, only enable that DiagID.
+- Rerunning enable clears existing breakpoints.
+- diagtool is used in breakpoint callbacks, so it can be changed
+  without the need to rerun enable.
+- Adding this to your ~.lldbinit file makes clangdiag available at startup:
+  "command script import /path/to/clangdiag.py"
+
+'''
+
+def create_diag_options():
+parser = MyParser(prog='clangdiag')
+subparsers = parser.add_subparsers(
+title='subcommands',
+dest='subcommands',
+metavar='')
+disable_parser = subparsers.add_parser('disable')
+enable_parser = subparsers.add_parser('enable')
+enable_parser.add_argument('id', nargs='?')
+diagtool_parser = subparsers.add_parser('diagtool')
+diagtool_parser.add_argument('path', nargs='?')
+return parser
+
+def getDiagtool(target, diagtool = None):
+id = target.GetProcess().GetProcessID()
+if 'diagtool' not in getDiagtool.__dict__:
+getDiagtool.diagtool = {}
+if diagtool:
+if diagtool == 'reset':
+getDiagtool.diagtool[id] = None
+elif os.path.exists(diagtool):
+getDiagtool.diagtool[id] = diagtool
+else:
+print('clangdiag: %s not found.' % diagtool)
+if not id in getDiagtool.diagtool or not getDiagtool.diagtool[id]:
+getDiagtool.diagtool[id] = None
+exe = target.GetExecutable()
+if not exe.Exists():
+print('clangdiag: Target (%s) not set.' % exe.GetFilename())
+else:
+diagtool = os.path.join(exe.GetDirectory(), 'diagtool')
+if os.path.exists(diagtool):
+getDiagtool.diagtool[id] = diagtool
+else:
+print('clangdiag: diagtool not found along side %s' % exe)
+
+return getDiagtool.diagtool[id]
+
+def setDiagBreakpoint(frame, bp_loc, dict):
+id = frame.FindVariable("DiagID").GetValue()
+if id is None:
+print('clangdiag: id is None')
+return False
+
+# Don't need to test this time, since we did that in enable.
+target = frame.GetThread().GetProcess().GetTarget()
+diagtool = getDiagtool(target)
+name = subprocess.check_output([diagtool, "find-diagnostic-id", id]).rstrip();
+# Make sure we only consider errors, warnings, and extentions.
+# FIXME: Make this configurable?
+prefixes = ['err_', 'warn_', 'exp_']
+if len([prefix for prefix in prefixes+[''] if name.startswith(prefix)][0]):
+

[PATCH] D38596: Implement attribute target multiversioning

2017-10-27 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 120636.
erichkeane added a comment.

Fix comment in Attr.td that @aaron.ballman brought up on IRC.


https://reviews.llvm.org/D38596

Files:
  include/clang/AST/Decl.h
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TargetInfo.h
  include/clang/Sema/Sema.h
  lib/AST/Decl.cpp
  lib/Basic/Targets/X86.cpp
  lib/Basic/Targets/X86.h
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/Sema/SemaDecl.cpp
  test/CodeGen/attr-target-multiversion.c
  test/CodeGenCXX/attr-target-multiversion.cpp
  test/Sema/attr-target-multiversion.c
  test/SemaCXX/attr-target-multiversion.cpp

Index: test/SemaCXX/attr-target-multiversion.cpp
===
--- /dev/null
+++ test/SemaCXX/attr-target-multiversion.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -triple x86_64-linux -fsyntax-only -verify -emit-llvm-only %s
+
+struct S {
+  __attribute__((target("arch=sandybridge")))
+  void mv(){}
+  __attribute__((target("arch=ivybridge")))
+  void mv(){}
+  __attribute__((target("default")))
+  void mv(){}
+
+  // NOTE: Virtual functions aren't implement for multiversioning in GCC either,
+  // so this is a 'TBD' feature.
+  // expected-error@+2 {{function multiversioning with 'target' doesn't support virtual functions yet}}
+  __attribute__((target("arch=sandybridge")))
+  virtual void mv_2(){}
+  // expected-error@+3 {{class member cannot be redeclared}}
+  // expected-note@-2 {{previous definition is here}}
+  __attribute__((target("arch=ivybridge")))
+  virtual void mv_2(){}
+  // expected-error@+3 {{class member cannot be redeclared}}
+  // expected-note@-6 {{previous definition is here}}
+  __attribute__((target("default")))
+  virtual void mv_2(){}
+};
+
+// Note: Template attribute 'target' isn't implemented in GCC either, and would
+// end up causing some nasty issues attempting it, so ensure that it still gives
+// the same errors as without the attribute.
+
+template
+__attribute__((target("arch=sandybridge")))
+void mv_temp(){}
+
+template
+__attribute__((target("arch=ivybridge")))
+//expected-error@+2 {{redefinition of}}
+//expected-note@-5{{previous definition is here}}
+void mv_temp(){}
+
+template
+__attribute__((target("default")))
+void mv_temp(){}
+
+void foo() {
+  //expected-error@+2{{no matching function for call to}}
+  //expected-note@-8{{candidate template ignored}}
+  mv_temp();
+}
Index: test/Sema/attr-target-multiversion.c
===
--- /dev/null
+++ test/Sema/attr-target-multiversion.c
@@ -0,0 +1,136 @@
+// RUN: %clang_cc1 -triple x86_64-linux -fsyntax-only -verify -emit-llvm-only %s
+// RUN: %clang_cc1 -triple x86_64-linux -fsyntax-only -verify -emit-llvm-only -DCHECK_DEFAULT %s
+
+#if defined(CHECK_DEFAULT)
+__attribute__((target("arch=sandybridge")))
+//expected-error@+1 {{function multiversioning with 'target' requires a 'default' implementation}}
+void no_default(){}
+__attribute__((target("arch=ivybridge")))
+void no_default(){}
+#else
+// Only multiversioning causes issues with redeclaration changing 'target'.
+__attribute__((target("arch=sandybridge")))
+void fine_since_no_mv();
+void fine_since_no_mv();
+
+void also_fine_since_no_mv();
+__attribute__((target("arch=sandybridge")))
+void also_fine_since_no_mv();
+
+__attribute__((target("arch=sandybridge")))
+void also_fine_since_no_mv2();
+__attribute__((target("arch=sandybridge")))
+void also_fine_since_no_mv2();
+void also_fine_since_no_mv2();
+
+__attribute__((target("arch=sandybridge")))
+void mv(){}
+__attribute__((target("arch=ivybridge")))
+void mv(){}
+__attribute__((target("default")))
+void mv(){}
+
+void redecl_causes_mv();
+__attribute__((target("arch=sandybridge")))
+void redecl_causes_mv();
+// expected-error@+3 {{function redeclaration declares a multiversioned function, but a previous declaration lacks a 'target' attribute}}
+// expected-note@-4 {{previous declaration is here}}
+__attribute__((target("arch=ivybridge")))
+void redecl_causes_mv();
+
+__attribute__((target("arch=sandybridge")))
+void redecl_causes_mv2();
+void redecl_causes_mv2();
+// expected-error@+3 {{function redeclaration declares a multiversioned function, but a previous declaration lacks a 'target' attribute}}
+// expected-note@-2 {{previous declaration is here}}
+__attribute__((target("arch=ivybridge")))
+void redecl_causes_mv2();
+
+__attribute__((target("arch=sandybridge")))
+void redecl_without_attr();
+__attribute__((target("arch=ivybridge")))
+void redecl_without_attr();
+// expected-error@+2 {{function redeclaration is missing 'target' attribute in a multiversioned function}}
+// expected-note@-4 {{previous declaration is here}}
+void redecl_without_attr();
+
+__attribute__((target("arch=sandybridge")))
+void multiversion_with_predecl();
+__attribute__((targ

[PATCH] D38596: Implement attribute target multiversioning

2017-10-27 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I think the attribute and sema parts look good, but I leave the codegen bits to 
someone with more experience in that area.


https://reviews.llvm.org/D38596



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


[PATCH] D38596: Implement attribute target multiversioning

2017-10-27 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 120620.
erichkeane added a comment.

Fixes for Aaron's comments.


https://reviews.llvm.org/D38596

Files:
  include/clang/AST/Decl.h
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TargetInfo.h
  include/clang/Sema/Sema.h
  lib/AST/Decl.cpp
  lib/Basic/Targets/X86.cpp
  lib/Basic/Targets/X86.h
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/Sema/SemaDecl.cpp
  test/CodeGen/attr-target-multiversion.c
  test/CodeGenCXX/attr-target-multiversion.cpp
  test/Sema/attr-target-multiversion.c
  test/SemaCXX/attr-target-multiversion.cpp

Index: test/SemaCXX/attr-target-multiversion.cpp
===
--- /dev/null
+++ test/SemaCXX/attr-target-multiversion.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -triple x86_64-linux -fsyntax-only -verify -emit-llvm-only %s
+
+struct S {
+  __attribute__((target("arch=sandybridge")))
+  void mv(){}
+  __attribute__((target("arch=ivybridge")))
+  void mv(){}
+  __attribute__((target("default")))
+  void mv(){}
+
+  // NOTE: Virtual functions aren't implement for multiversioning in GCC either,
+  // so this is a 'TBD' feature.
+  // expected-error@+2 {{function multiversioning with 'target' doesn't support virtual functions yet}}
+  __attribute__((target("arch=sandybridge")))
+  virtual void mv_2(){}
+  // expected-error@+3 {{class member cannot be redeclared}}
+  // expected-note@-2 {{previous definition is here}}
+  __attribute__((target("arch=ivybridge")))
+  virtual void mv_2(){}
+  // expected-error@+3 {{class member cannot be redeclared}}
+  // expected-note@-6 {{previous definition is here}}
+  __attribute__((target("default")))
+  virtual void mv_2(){}
+};
+
+// Note: Template attribute 'target' isn't implemented in GCC either, and would
+// end up causing some nasty issues attempting it, so ensure that it still gives
+// the same errors as without the attribute.
+
+template
+__attribute__((target("arch=sandybridge")))
+void mv_temp(){}
+
+template
+__attribute__((target("arch=ivybridge")))
+//expected-error@+2 {{redefinition of}}
+//expected-note@-5{{previous definition is here}}
+void mv_temp(){}
+
+template
+__attribute__((target("default")))
+void mv_temp(){}
+
+void foo() {
+  //expected-error@+2{{no matching function for call to}}
+  //expected-note@-8{{candidate template ignored}}
+  mv_temp();
+}
Index: test/Sema/attr-target-multiversion.c
===
--- /dev/null
+++ test/Sema/attr-target-multiversion.c
@@ -0,0 +1,136 @@
+// RUN: %clang_cc1 -triple x86_64-linux -fsyntax-only -verify -emit-llvm-only %s
+// RUN: %clang_cc1 -triple x86_64-linux -fsyntax-only -verify -emit-llvm-only -DCHECK_DEFAULT %s
+
+#if defined(CHECK_DEFAULT)
+__attribute__((target("arch=sandybridge")))
+//expected-error@+1 {{function multiversioning with 'target' requires a 'default' implementation}}
+void no_default(){}
+__attribute__((target("arch=ivybridge")))
+void no_default(){}
+#else
+// Only multiversioning causes issues with redeclaration changing 'target'.
+__attribute__((target("arch=sandybridge")))
+void fine_since_no_mv();
+void fine_since_no_mv();
+
+void also_fine_since_no_mv();
+__attribute__((target("arch=sandybridge")))
+void also_fine_since_no_mv();
+
+__attribute__((target("arch=sandybridge")))
+void also_fine_since_no_mv2();
+__attribute__((target("arch=sandybridge")))
+void also_fine_since_no_mv2();
+void also_fine_since_no_mv2();
+
+__attribute__((target("arch=sandybridge")))
+void mv(){}
+__attribute__((target("arch=ivybridge")))
+void mv(){}
+__attribute__((target("default")))
+void mv(){}
+
+void redecl_causes_mv();
+__attribute__((target("arch=sandybridge")))
+void redecl_causes_mv();
+// expected-error@+3 {{function redeclaration declares a multiversioned function, but a previous declaration lacks a 'target' attribute}}
+// expected-note@-4 {{previous declaration is here}}
+__attribute__((target("arch=ivybridge")))
+void redecl_causes_mv();
+
+__attribute__((target("arch=sandybridge")))
+void redecl_causes_mv2();
+void redecl_causes_mv2();
+// expected-error@+3 {{function redeclaration declares a multiversioned function, but a previous declaration lacks a 'target' attribute}}
+// expected-note@-2 {{previous declaration is here}}
+__attribute__((target("arch=ivybridge")))
+void redecl_causes_mv2();
+
+__attribute__((target("arch=sandybridge")))
+void redecl_without_attr();
+__attribute__((target("arch=ivybridge")))
+void redecl_without_attr();
+// expected-error@+2 {{function redeclaration is missing 'target' attribute in a multiversioned function}}
+// expected-note@-4 {{previous declaration is here}}
+void redecl_without_attr();
+
+__attribute__((target("arch=sandybridge")))
+void multiversion_with_predecl();
+__attribute__((target("default")))
+void multiversion

[PATCH] D39332: [clang-refactor] Introduce "local-qualified-rename" action.

2017-10-27 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

I've committed https://reviews.llvm.org/D38985, so you'd have to rebase 
unfortunately. Things are still somewhat unstable :)




Comment at: lib/Tooling/Refactoring/Rename/RenamingAction.cpp:154
+
+class LocalQualifiedRename final : public RefactoringAction {
+public:

hokein wrote:
> sammccall wrote:
> > As discussed offline, it's not clear why this is a separate Action, rather 
> > than a different Rule that's part of the same Action.
> > 
> > @arphaman how does the framework answer this question?
> There is a 
> [document](https://clang.llvm.org/docs/RefactoringEngine.html#refactoring-action-rules)
>  describing it, but still ambiguous.
> 
> We also had some questions about `local-rename` from the discussion, need 
> @arphaman's input:
> 
> * `OccurrenceFinder` is not exposed now, it is merely used in 
> `RenameOccurrences`. We think there should be a public interface to the 
> clients, like for implementing interactive mode in IDE? 
> * Currently the rules defined in the same action must have mutual 
> command-line options, otherwise clang-refactor would complain the 
> command-line option are being registered more than once. It might be very 
> strict for some cases. For example, `-new-name` is most likely being used by 
> many rules in `local-rename` action.
>  
I think that this should be just a rule in `local-rename`.

So you'd be able to call:

`clang-refactor local-rename -selection=X -new-name=foo`
`clang-refactor local-rename -old-qualified-name=bar -new-name=foo`.


https://reviews.llvm.org/D39332



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


[PATCH] D38674: [analyzer] MisusedMovedObjectChecker: More precise warning message

2017-10-27 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added a comment.

Please, commit.


https://reviews.llvm.org/D38674



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


[PATCH] D37437: [analyzer] Fix some checker's output plist not containing the checker name

2017-10-27 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added a comment.

Just to be clear, since this leads to regression to the checker API, I am 
asking to look into other ways of solving this problem. For example, is there a 
way to ensure that the checker names are set at construction?


https://reviews.llvm.org/D37437



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


[PATCH] D39177: [CodeGen] Generate TBAA info for reference loads

2017-10-27 Thread Ivan Kosarev via Phabricator via cfe-commits
kosarev added inline comments.



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:1041
+else
+  BaseLV = CGF.EmitLoadOfReferenceLValue(BaseLV);
 BaseTy = BaseTy->getPointeeType();

Oh-oh, it looks I do something not functionally equivalent here. Sorry, will 
update in a moment.


https://reviews.llvm.org/D39177



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


r316777 - [WebAssembly] Add crt1.o with calling lld

2017-10-27 Thread Sam Clegg via cfe-commits
Author: sbc
Date: Fri Oct 27 11:10:19 2017
New Revision: 316777

URL: http://llvm.org/viewvc/llvm-project?rev=316777&view=rev
Log:
[WebAssembly] Add crt1.o with calling lld

Also, for OS unknown targets like wasm, don't include
'unknown' in the library path. This is a fix for rL316719.

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

Modified:
cfe/trunk/lib/Driver/ToolChain.cpp
cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
cfe/trunk/test/Driver/wasm-toolchain.c

Modified: cfe/trunk/lib/Driver/ToolChain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=316777&r1=316776&r2=316777&view=diff
==
--- cfe/trunk/lib/Driver/ToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChain.cpp Fri Oct 27 11:10:19 2017
@@ -309,14 +309,12 @@ static StringRef getArchNameForCompilerR
 
 std::string ToolChain::getCompilerRTPath() const {
   SmallString<128> Path(getDriver().ResourceDir);
-  StringRef OSLibName;
-  if (Triple.isOSFreeBSD())
-OSLibName = "freebsd";
-  else if (Triple.isOSBinFormatWasm())
-OSLibName = "wasm";
-  else
-OSLibName = getOS();
-  llvm::sys::path::append(Path, "lib", OSLibName);
+  if (Triple.isOSUnknown()) {
+llvm::sys::path::append(Path, "lib");
+  } else {
+StringRef OSLibName = Triple.isOSFreeBSD() ? "freebsd" : getOS();
+llvm::sys::path::append(Path, "lib", OSLibName);
+  }
   return Path.str();
 }
 

Modified: cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp?rev=316777&r1=316776&r2=316777&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp Fri Oct 27 11:10:19 2017
@@ -49,6 +49,9 @@ void wasm::Linker::ConstructJob(Compilat
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
 
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles))
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt1.o")));
+
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {

Modified: cfe/trunk/test/Driver/wasm-toolchain.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/wasm-toolchain.c?rev=316777&r1=316776&r2=316777&view=diff
==
--- cfe/trunk/test/Driver/wasm-toolchain.c (original)
+++ cfe/trunk/test/Driver/wasm-toolchain.c Fri Oct 27 11:10:19 2017
@@ -27,10 +27,10 @@
 
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK %s
 // LINK: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "[[temp]]" 
"-allow-undefined-file" "wasm.syms" "-lc" 
"{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" 
"-allow-undefined-file" "wasm.syms" "-lc" 
"{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
 
 // A basic C link command-line with optimization.
 
 // RUN: %clang -### -O2 -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK_OPT %s
 // LINK_OPT: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "[[temp]]" 
"-allow-undefined-file" "wasm.syms" "-lc" 
"{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" 
"-allow-undefined-file" "wasm.syms" "-lc" 
"{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"


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


[PATCH] D39177: [CodeGen] Generate TBAA info for reference loads

2017-10-27 Thread Ivan Kosarev via Phabricator via cfe-commits
kosarev updated this revision to Diff 120654.
kosarev added a comment.

- Fixed the type of the reference lvalue in loadToBegin().

John, can you please review the fix? Thanks.


https://reviews.llvm.org/D39177

Files:
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGStmtOpenMP.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGen/tbaa-reference.cpp

Index: test/CodeGen/tbaa-reference.cpp
===
--- test/CodeGen/tbaa-reference.cpp
+++ test/CodeGen/tbaa-reference.cpp
@@ -6,24 +6,32 @@
 
 struct B {
   S &s;
-  B(S &s) : s(s) {}
-  void bar();
+  B(S &s);
+  S &get();
 };
 
-void foo(S &s) {
-  B b(s);
-  b.bar();
-}
-
-// CHECK-LABEL: _Z3fooR1S
-// Check initialization of the reference parameter in foo().
-// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer:!.*]]
-//
+B::B(S &s) : s(s) {
 // CHECK-LABEL: _ZN1BC2ER1S
-// TODO: Check loading of the reference parameter in B::B(S&).
-// Check initialization of B::s in B::B(S&).
+// Check initialization of the reference parameter.
+// CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer:!.*]]
+
+// Check loading of the reference parameter.
+// CHECK: load %struct.S*, %struct.S** {{.*}}, !tbaa [[TAG_pointer]]
+
+// Check initialization of the reference member.
 // CHECK: store %struct.S* {{.*}}, %struct.S** {{.*}}, !tbaa [[TAG_pointer]]
-//
+}
+
+S &B::get() {
+// CHECK-LABEL: _ZN1B3getEv
+// Check that we access the reference as a structure member.
+// CHECK: load %struct.S*, %struct.S** {{.*}}, !tbaa [[TAG_B_s:!.*]]
+  return s;
+}
+
 // CHECK-DAG: [[TAG_pointer]] = !{[[TYPE_pointer:!.*]], [[TYPE_pointer]], i64 0}
+// CHECK-DAG: [[TAG_B_s]] = !{[[TYPE_B:!.*]], [[TYPE_pointer]], i64 0}
+//
+// CHECK-DAG: [[TYPE_B]] = !{!"_ZTS1B", [[TYPE_pointer]], i64 0}
 // CHECK-DAG: [[TYPE_pointer]] = !{!"any pointer", [[TYPE_char:!.*]], i64 0}
 // CHECK-DAG: [[TYPE_char]] = !{!"omnipotent char", {{!.*}}, i64 0}
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -1952,10 +1952,17 @@
LValueBaseInfo *BaseInfo = nullptr,
TBAAAccessInfo *TBAAInfo = nullptr);
 
-  Address EmitLoadOfReference(Address Ref, const ReferenceType *RefTy,
-  LValueBaseInfo *BaseInfo = nullptr,
-  TBAAAccessInfo *TBAAInfo = nullptr);
-  LValue EmitLoadOfReferenceLValue(Address Ref, const ReferenceType *RefTy);
+  Address EmitLoadOfReference(LValue RefLVal,
+  LValueBaseInfo *PointeeBaseInfo = nullptr,
+  TBAAAccessInfo *PointeeTBAAInfo = nullptr);
+  LValue EmitLoadOfReferenceLValue(LValue RefLVal);
+  LValue EmitLoadOfReferenceLValue(Address RefAddr, QualType RefTy,
+   AlignmentSource Source =
+   AlignmentSource::Type) {
+LValue RefLVal = MakeAddrLValue(RefAddr, RefTy, LValueBaseInfo(Source),
+CGM.getTBAAAccessInfo(RefTy));
+return EmitLoadOfReferenceLValue(RefLVal);
+  }
 
   Address EmitLoadOfPointer(Address Ptr, const PointerType *PtrTy,
 LValueBaseInfo *BaseInfo = nullptr,
Index: lib/CodeGen/CGStmtOpenMP.cpp
===
--- lib/CodeGen/CGStmtOpenMP.cpp
+++ lib/CodeGen/CGStmtOpenMP.cpp
@@ -417,8 +417,7 @@
   Address ArgAddr = ArgLVal.getAddress();
   if (!VarTy->isReferenceType()) {
 if (ArgLVal.getType()->isLValueReferenceType()) {
-  ArgAddr = CGF.EmitLoadOfReference(
-  ArgAddr, ArgLVal.getType()->castAs());
+  ArgAddr = CGF.EmitLoadOfReference(ArgLVal);
 } else if (!VarTy->isVariablyModifiedType() || !VarTy->isPointerType()) {
   assert(ArgLVal.getType()->isPointerType());
   ArgAddr = CGF.EmitLoadOfPointer(
Index: lib/CodeGen/CGOpenMPRuntime.cpp
===
--- lib/CodeGen/CGOpenMPRuntime.cpp
+++ lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1037,8 +1037,8 @@
 if (auto *PtrTy = BaseTy->getAs())
   BaseLV = CGF.EmitLoadOfPointerLValue(BaseLV.getAddress(), PtrTy);
 else {
-  BaseLV = CGF.EmitLoadOfReferenceLValue(BaseLV.getAddress(),
- BaseTy->castAs());
+  LValue RefLVal = CGF.MakeAddrLValue(BaseLV.getAddress(), BaseTy);
+  BaseLV = CGF.EmitLoadOfReferenceLValue(RefLVal);
 }
 BaseTy = BaseTy->getPointeeType();
   }
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -2160,22 +2160,30 @@
   return CGF.MakeAddrLValue(Addr, T, AlignmentSource::Decl);

[PATCH] D39354: [WebAssembly] Add crt1.o when calling lld

2017-10-27 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316777: [WebAssembly] Add crt1.o with calling lld (authored 
by sbc).

Repository:
  rL LLVM

https://reviews.llvm.org/D39354

Files:
  cfe/trunk/lib/Driver/ToolChain.cpp
  cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
  cfe/trunk/test/Driver/wasm-toolchain.c


Index: cfe/trunk/test/Driver/wasm-toolchain.c
===
--- cfe/trunk/test/Driver/wasm-toolchain.c
+++ cfe/trunk/test/Driver/wasm-toolchain.c
@@ -27,10 +27,10 @@
 
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK %s
 // LINK: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "[[temp]]" 
"-allow-undefined-file" "wasm.syms" "-lc" 
"{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" 
"-allow-undefined-file" "wasm.syms" "-lc" 
"{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
 
 // A basic C link command-line with optimization.
 
 // RUN: %clang -### -O2 -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK_OPT %s
 // LINK_OPT: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "[[temp]]" 
"-allow-undefined-file" "wasm.syms" "-lc" 
"{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" 
"-allow-undefined-file" "wasm.syms" "-lc" 
"{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
Index: cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
@@ -49,6 +49,9 @@
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
 
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles))
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt1.o")));
+
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
Index: cfe/trunk/lib/Driver/ToolChain.cpp
===
--- cfe/trunk/lib/Driver/ToolChain.cpp
+++ cfe/trunk/lib/Driver/ToolChain.cpp
@@ -309,14 +309,12 @@
 
 std::string ToolChain::getCompilerRTPath() const {
   SmallString<128> Path(getDriver().ResourceDir);
-  StringRef OSLibName;
-  if (Triple.isOSFreeBSD())
-OSLibName = "freebsd";
-  else if (Triple.isOSBinFormatWasm())
-OSLibName = "wasm";
-  else
-OSLibName = getOS();
-  llvm::sys::path::append(Path, "lib", OSLibName);
+  if (Triple.isOSUnknown()) {
+llvm::sys::path::append(Path, "lib");
+  } else {
+StringRef OSLibName = Triple.isOSFreeBSD() ? "freebsd" : getOS();
+llvm::sys::path::append(Path, "lib", OSLibName);
+  }
   return Path.str();
 }
 


Index: cfe/trunk/test/Driver/wasm-toolchain.c
===
--- cfe/trunk/test/Driver/wasm-toolchain.c
+++ cfe/trunk/test/Driver/wasm-toolchain.c
@@ -27,10 +27,10 @@
 
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK %s
 // LINK: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "[[temp]]" "-allow-undefined-file" "wasm.syms" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" "-allow-undefined-file" "wasm.syms" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
 
 // A basic C link command-line with optimization.
 
 // RUN: %clang -### -O2 -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK_OPT %s
 // LINK_OPT: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "[[temp]]" "-allow-undefined-file" "wasm.syms" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "[[temp]]" "-allow-undefined-file" "wasm.syms" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
Index: cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
@@ -49,6 +49,9 @@
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
 
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles))
+CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath("crt1.o")));
+
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs,

r316778 - [Sema] Fix an assert-on-invalid by avoiding function template specialisation

2017-10-27 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Fri Oct 27 11:13:31 2017
New Revision: 316778

URL: http://llvm.org/viewvc/llvm-project?rev=316778&view=rev
Log:
[Sema] Fix an assert-on-invalid by avoiding function template specialisation
deduction for invalid functions

The fabricated template parameters cause an assertion because their depth
is invalid.

rdar://34109988

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

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaTemplate/deduction-crash.cpp
cfe/trunk/test/SemaTemplate/explicit-specialization-member.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=316778&r1=316777&r2=316778&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Oct 27 11:13:31 2017
@@ -8962,10 +8962,10 @@ Sema::ActOnFunctionDeclarator(Scope *S,
   diag::ext_function_specialization_in_class :
   diag::err_function_specialization_in_class)
   << NewFD->getDeclName();
-  } else if (CheckFunctionTemplateSpecialization(NewFD,
-  (HasExplicitTemplateArgs ? &TemplateArgs
-   : nullptr),
- Previous))
+  } else if (!NewFD->isInvalidDecl() &&
+ CheckFunctionTemplateSpecialization(
+ NewFD, (HasExplicitTemplateArgs ? &TemplateArgs : 
nullptr),
+ Previous))
 NewFD->setInvalidDecl();
 
   // C++ [dcl.stc]p1:

Modified: cfe/trunk/test/SemaTemplate/deduction-crash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/deduction-crash.cpp?rev=316778&r1=316777&r2=316778&view=diff
==
--- cfe/trunk/test/SemaTemplate/deduction-crash.cpp (original)
+++ cfe/trunk/test/SemaTemplate/deduction-crash.cpp Fri Oct 27 11:13:31 2017
@@ -144,3 +144,20 @@ namespace var_template_partial_spec_inco
   template int n; // expected-error +{{}} 
expected-note {{}}
   int k = n;
 }
+
+namespace deduceFunctionSpecializationForInvalidOutOfLineFunction {
+
+template 
+struct SourceSelectionRequirement {
+  template
+  OutputT evaluateSelectionRequirement(InputT &&Value) {
+  }
+};
+
+template 
+OutputT SourceSelectionRequirement::
+evaluateSelectionRequirement(InputT &&Value) { // expected-error 
{{cannot specialize a member of an unspecialized template}}
+  return Value;
+}
+
+}

Modified: cfe/trunk/test/SemaTemplate/explicit-specialization-member.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/explicit-specialization-member.cpp?rev=316778&r1=316777&r2=316778&view=diff
==
--- cfe/trunk/test/SemaTemplate/explicit-specialization-member.cpp (original)
+++ cfe/trunk/test/SemaTemplate/explicit-specialization-member.cpp Fri Oct 27 
11:13:31 2017
@@ -38,24 +38,20 @@ namespace PR18246 {
 
   template
   template
-  void Baz::bar() { // expected-note {{couldn't infer template argument 
'N'}}
+  void Baz::bar() {
   }
 
-  // FIXME: We shouldn't try to match this against a prior declaration if
-  // template parameter matching failed.
   template
-  void Baz::bar<0>() { // expected-error {{cannot specialize a member of an 
unspecialized template}} \
-  // expected-error {{no function template matches}}
+  void Baz::bar<0>() { // expected-error {{cannot specialize a member of an 
unspecialized template}}
   }
 }
 
 namespace PR19340 {
 template struct Helper {
-  template static void func(const T *m) {} // expected-note {{failed 
template argument deduction}}
+  template static void func(const T *m) {}
 };
 
-template void Helper::func<2>() {} // expected-error {{cannot 
specialize a member}} \
-  // expected-error {{no 
function template matches}}
+template void Helper::func<2>() {} // expected-error {{cannot 
specialize a member}}
 }
 
 namespace SpecLoc {


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


[PATCH] D39357: Filter out invalid 'target' items from being passed to LLVM

2017-10-27 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: lib/CodeGen/CodeGenModule.cpp:4586
+ParsedAttr.Features.erase(
+remove_if(ParsedAttr.Features.begin(), ParsedAttr.Features.end(),
+[&](const std::string &Feat) {

Use llvm::remove_if which takes a type that has a range?


https://reviews.llvm.org/D39357



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


[PATCH] D37341: [Sema] Fix an assert-on-invalid by avoiding function template specialisation deduction for invalid functions with fabricated template arguments

2017-10-27 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316778: [Sema] Fix an assert-on-invalid by avoiding function 
template specialisation (authored by arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D37341?vs=119967&id=120658#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D37341

Files:
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/test/SemaTemplate/deduction-crash.cpp
  cfe/trunk/test/SemaTemplate/explicit-specialization-member.cpp


Index: cfe/trunk/test/SemaTemplate/explicit-specialization-member.cpp
===
--- cfe/trunk/test/SemaTemplate/explicit-specialization-member.cpp
+++ cfe/trunk/test/SemaTemplate/explicit-specialization-member.cpp
@@ -38,24 +38,20 @@
 
   template
   template
-  void Baz::bar() { // expected-note {{couldn't infer template argument 
'N'}}
+  void Baz::bar() {
   }
 
-  // FIXME: We shouldn't try to match this against a prior declaration if
-  // template parameter matching failed.
   template
-  void Baz::bar<0>() { // expected-error {{cannot specialize a member of an 
unspecialized template}} \
-  // expected-error {{no function template matches}}
+  void Baz::bar<0>() { // expected-error {{cannot specialize a member of an 
unspecialized template}}
   }
 }
 
 namespace PR19340 {
 template struct Helper {
-  template static void func(const T *m) {} // expected-note {{failed 
template argument deduction}}
+  template static void func(const T *m) {}
 };
 
-template void Helper::func<2>() {} // expected-error {{cannot 
specialize a member}} \
-  // expected-error {{no 
function template matches}}
+template void Helper::func<2>() {} // expected-error {{cannot 
specialize a member}}
 }
 
 namespace SpecLoc {
Index: cfe/trunk/test/SemaTemplate/deduction-crash.cpp
===
--- cfe/trunk/test/SemaTemplate/deduction-crash.cpp
+++ cfe/trunk/test/SemaTemplate/deduction-crash.cpp
@@ -144,3 +144,20 @@
   template int n; // expected-error +{{}} 
expected-note {{}}
   int k = n;
 }
+
+namespace deduceFunctionSpecializationForInvalidOutOfLineFunction {
+
+template 
+struct SourceSelectionRequirement {
+  template
+  OutputT evaluateSelectionRequirement(InputT &&Value) {
+  }
+};
+
+template 
+OutputT SourceSelectionRequirement::
+evaluateSelectionRequirement(InputT &&Value) { // expected-error 
{{cannot specialize a member of an unspecialized template}}
+  return Value;
+}
+
+}
Index: cfe/trunk/lib/Sema/SemaDecl.cpp
===
--- cfe/trunk/lib/Sema/SemaDecl.cpp
+++ cfe/trunk/lib/Sema/SemaDecl.cpp
@@ -8962,10 +8962,10 @@
   diag::ext_function_specialization_in_class :
   diag::err_function_specialization_in_class)
   << NewFD->getDeclName();
-  } else if (CheckFunctionTemplateSpecialization(NewFD,
-  (HasExplicitTemplateArgs ? &TemplateArgs
-   : nullptr),
- Previous))
+  } else if (!NewFD->isInvalidDecl() &&
+ CheckFunctionTemplateSpecialization(
+ NewFD, (HasExplicitTemplateArgs ? &TemplateArgs : 
nullptr),
+ Previous))
 NewFD->setInvalidDecl();
 
   // C++ [dcl.stc]p1:


Index: cfe/trunk/test/SemaTemplate/explicit-specialization-member.cpp
===
--- cfe/trunk/test/SemaTemplate/explicit-specialization-member.cpp
+++ cfe/trunk/test/SemaTemplate/explicit-specialization-member.cpp
@@ -38,24 +38,20 @@
 
   template
   template
-  void Baz::bar() { // expected-note {{couldn't infer template argument 'N'}}
+  void Baz::bar() {
   }
 
-  // FIXME: We shouldn't try to match this against a prior declaration if
-  // template parameter matching failed.
   template
-  void Baz::bar<0>() { // expected-error {{cannot specialize a member of an unspecialized template}} \
-  // expected-error {{no function template matches}}
+  void Baz::bar<0>() { // expected-error {{cannot specialize a member of an unspecialized template}}
   }
 }
 
 namespace PR19340 {
 template struct Helper {
-  template static void func(const T *m) {} // expected-note {{failed template argument deduction}}
+  template static void func(const T *m) {}
 };
 
-template void Helper::func<2>() {} // expected-error {{cannot specialize a member}} \
-  // expected-error {{no function template matches}}
+template void Helper::func<2>() {} // expected-error {{cannot specialize a member}}
 }
 
 namespace SpecLoc {
Index: cfe/trunk/test/SemaTemplate/deduction-crash.cpp
===
--- cfe/trunk/test/SemaTemplate/deduction

[PATCH] D38844: [analyzer] Make issue hash related tests more concise

2017-10-27 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added a comment.

Please, change the commit description to be more comprehensive.




Comment at: lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp:68
   // (globals should not be invalidated, etc), hence the use of evalCall.
-  FnCheck Handler = llvm::StringSwitch(C.getCalleeName(CE))
-.Case("clang_analyzer_eval", &ExprInspectionChecker::analyzerEval)
-.Case("clang_analyzer_checkInlined",
-  &ExprInspectionChecker::analyzerCheckInlined)
-.Case("clang_analyzer_crash", &ExprInspectionChecker::analyzerCrash)
-.Case("clang_analyzer_warnIfReached",
-  &ExprInspectionChecker::analyzerWarnIfReached)
-.Case("clang_analyzer_warnOnDeadSymbol",
-  &ExprInspectionChecker::analyzerWarnOnDeadSymbol)
-.StartsWith("clang_analyzer_explain", 
&ExprInspectionChecker::analyzerExplain)
-.StartsWith("clang_analyzer_dump", &ExprInspectionChecker::analyzerDump)
-.Case("clang_analyzer_getExtent", 
&ExprInspectionChecker::analyzerGetExtent)
-.Case("clang_analyzer_printState",
-  &ExprInspectionChecker::analyzerPrintState)
-.Case("clang_analyzer_numTimesReached",
-  &ExprInspectionChecker::analyzerNumTimesReached)
-.Default(nullptr);
+  FnCheck Handler =
+  llvm::StringSwitch(C.getCalleeName(CE))

Unrelated change?



Comment at: lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp:78
+&ExprInspectionChecker::analyzerWarnOnDeadSymbol)
+  .StartsWith("clang_analyzer_explain",
+  &ExprInspectionChecker::analyzerExplain)

I cannot tell what changed here...


https://reviews.llvm.org/D38844



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


[PATCH] D39357: Filter out invalid 'target' items from being passed to LLVM

2017-10-27 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 120659.
erichkeane added a comment.

Switched to llvm::remove_if(RANGE, lambda) instead of std::remove_if with 
begin/end per Craig's suggestion.


https://reviews.llvm.org/D39357

Files:
  include/clang/Basic/TargetInfo.h
  lib/Basic/Targets/X86.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGen/attr-target-x86.c

Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -4582,14 +4582,23 @@
 // If we have a TargetAttr build up the feature map based on that.
 TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse();
 
+ParsedAttr.Features.erase(
+llvm::remove_if(ParsedAttr.Features,
+[&](const std::string &Feat) {
+  return !Target.isValidFeatureName(
+  StringRef{Feat}.substr(1));
+}),
+ParsedAttr.Features.end());
+
 // Make a copy of the features as passed on the command line into the
 // beginning of the additional features from the function to override.
 ParsedAttr.Features.insert(ParsedAttr.Features.begin(),
 Target.getTargetOpts().FeaturesAsWritten.begin(),
 Target.getTargetOpts().FeaturesAsWritten.end());
 
-if (ParsedAttr.Architecture != "")
-  TargetCPU = ParsedAttr.Architecture ;
+if (ParsedAttr.Architecture != "" &&
+Target.isValidCPUName(ParsedAttr.Architecture))
+  TargetCPU = ParsedAttr.Architecture;
 
 // Now populate the feature map, first with the TargetCPU which is either
 // the default or a new one from the target attribute string. Then we'll use
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -1885,10 +1885,11 @@
   // the function.
   const auto *TD = FD->getAttr();
   TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse();
-  if (ParsedAttr.Architecture != "")
+  if (ParsedAttr.Architecture != "" &&
+  getTarget().isValidCPUName(ParsedAttr.Architecture))
 TargetCPU = ParsedAttr.Architecture;
   if (TargetCPU != "")
-FuncAttrs.addAttribute("target-cpu", TargetCPU);
+ FuncAttrs.addAttribute("target-cpu", TargetCPU);
   if (!Features.empty()) {
 std::sort(Features.begin(), Features.end());
 FuncAttrs.addAttribute(
Index: lib/Basic/Targets/X86.cpp
===
--- lib/Basic/Targets/X86.cpp
+++ lib/Basic/Targets/X86.cpp
@@ -1172,6 +1172,7 @@
   .Case("x86", true)
   .Case("x86_32", true)
   .Case("x86_64", true)
+  .Case("x87", true)
   .Case("xop", true)
   .Case("xsave", true)
   .Case("xsavec", true)
Index: include/clang/Basic/TargetInfo.h
===
--- include/clang/Basic/TargetInfo.h
+++ include/clang/Basic/TargetInfo.h
@@ -861,7 +861,7 @@
 
   /// brief Determine whether this TargetInfo supports the given CPU name.
   virtual bool isValidCPUName(StringRef Name) const {
-return false;
+return true;
   }
 
   /// \brief Use the specified ABI.
@@ -888,7 +888,7 @@
 
   /// \brief Determine whether this TargetInfo supports the given feature.
   virtual bool isValidFeatureName(StringRef Feature) const {
-return false;
+return true;
   }
 
   /// \brief Perform initialization based on the user configured
Index: test/CodeGen/attr-target-x86.c
===
--- test/CodeGen/attr-target-x86.c
+++ test/CodeGen/attr-target-x86.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -target-cpu x86-64 -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple i686-linux-gnu -target-cpu i686 -emit-llvm %s -o - | FileCheck %s
 
 int baz(int a) { return 4; }
 
@@ -19,7 +19,7 @@
 
 int __attribute__((target("no-mmx"))) qq(int a) { return 40; }
 
-int __attribute__((target("arch=lakemont"))) lake(int a) { return 4; }
+int __attribute__((target("arch=lakemont,mmx"))) lake(int a) { return 4; }
 
 // Check that we emit the additional subtarget and cpu features for foo and not for baz or bar.
 // CHECK: baz{{.*}} #0
@@ -36,11 +36,11 @@
 // CHECK: qax{{.*}} #5
 // CHECK: qq{{.*}} #6
 // CHECK: lake{{.*}} #7
-// CHECK: #0 = {{.*}}"target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87"
+// CHECK: #0 = {{.*}}"target-cpu"="i686" "target-features"="+x87"
 // CHECK: #1 = {{.*}}"target-cpu"="ivybridge" "target-features"="+aes,+avx,+cx16,+f16c,+fsgsbase,+fxsr,+mmx,+pclmul,+popcnt,+rdrnd,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+xsaveopt"
-// CHECK: #2 = {{.*}}"target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+x87,-aes,-avx,-avx2,-avx512bw,-avx512cd,-avx512dq,-avx512er,-avx512f,-avx512i

r316780 - [refactor] Describe refactorings in the operation classes

2017-10-27 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Fri Oct 27 11:19:11 2017
New Revision: 316780

URL: http://llvm.org/viewvc/llvm-project?rev=316780&view=rev
Log:
[refactor] Describe refactorings in the operation classes

This commit changes the way that the refactoring operation classes are
structured:
- Users have to call `initiate` instead of constructing an instance of the
  class. The `initiate` is now supposed to have custom initiation logic, and
  you don't need to subclass the builtin requirements.
- A new `describe` function returns a structure with the id, title and the
  description of the refactoring operation.

The refactoring action classes are now placed into one common place in
RefactoringActions.cpp instead of being separate.

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

Added:
cfe/trunk/include/clang/Tooling/Refactoring/Extract/
cfe/trunk/include/clang/Tooling/Refactoring/Extract/Extract.h
Removed:
cfe/trunk/include/clang/Tooling/Refactoring/RefactoringActionRegistry.def
Modified:
cfe/trunk/include/clang/Tooling/Refactoring/RefactoringActionRule.h
cfe/trunk/include/clang/Tooling/Refactoring/RefactoringActionRulesInternal.h
cfe/trunk/include/clang/Tooling/Refactoring/Rename/RenamingAction.h
cfe/trunk/include/clang/module.modulemap
cfe/trunk/lib/Tooling/Refactoring/Extract.cpp
cfe/trunk/lib/Tooling/Refactoring/RefactoringActions.cpp
cfe/trunk/lib/Tooling/Refactoring/Rename/RenamingAction.cpp
cfe/trunk/unittests/Tooling/RefactoringActionRulesTest.cpp

Added: cfe/trunk/include/clang/Tooling/Refactoring/Extract/Extract.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Refactoring/Extract/Extract.h?rev=316780&view=auto
==
--- cfe/trunk/include/clang/Tooling/Refactoring/Extract/Extract.h (added)
+++ cfe/trunk/include/clang/Tooling/Refactoring/Extract/Extract.h Fri Oct 27 
11:19:11 2017
@@ -0,0 +1,53 @@
+//===--- Extract.h - Clang refactoring library 
===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLING_REFACTOR_EXTRACT_EXTRACT_H
+#define LLVM_CLANG_TOOLING_REFACTOR_EXTRACT_EXTRACT_H
+
+#include "clang/Tooling/Refactoring/ASTSelection.h"
+#include "clang/Tooling/Refactoring/RefactoringActionRules.h"
+
+namespace clang {
+namespace tooling {
+
+/// An "Extract Function" refactoring moves code into a new function that's
+/// then called from the place where the original code was.
+class ExtractFunction final : public SourceChangeRefactoringRule {
+public:
+  /// Initiates the extract function refactoring operation.
+  ///
+  /// \param Code The selected set of statements.
+  /// \param DeclName The name name of the extract function. If None,
+  /// "extracted" is used.
+  static Expected initiate(RefactoringRuleContext &Context,
+CodeRangeASTSelection Code,
+Optional DeclName);
+
+  static const RefactoringDescriptor &describe();
+
+private:
+  ExtractFunction(CodeRangeASTSelection Code, Optional DeclName)
+  : Code(std::move(Code)),
+DeclName(DeclName ? std::move(*DeclName) : "extracted") {}
+
+  Expected
+  createSourceReplacements(RefactoringRuleContext &Context) override;
+
+  CodeRangeASTSelection Code;
+
+  // FIXME: Account for naming collisions:
+  //  - error when name is specified by user.
+  //  - rename to "extractedN" when name is implicit.
+  std::string DeclName;
+};
+
+} // end namespace tooling
+} // end namespace clang
+
+#endif // LLVM_CLANG_TOOLING_REFACTOR_EXTRACT_EXTRACT_H

Removed: 
cfe/trunk/include/clang/Tooling/Refactoring/RefactoringActionRegistry.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Refactoring/RefactoringActionRegistry.def?rev=316779&view=auto
==
--- cfe/trunk/include/clang/Tooling/Refactoring/RefactoringActionRegistry.def 
(original)
+++ cfe/trunk/include/clang/Tooling/Refactoring/RefactoringActionRegistry.def 
(removed)
@@ -1,8 +0,0 @@
-#ifndef REFACTORING_ACTION
-#define REFACTORING_ACTION(Name)
-#endif
-
-REFACTORING_ACTION(LocalRename)
-REFACTORING_ACTION(Extract)
-
-#undef REFACTORING_ACTION

Modified: cfe/trunk/include/clang/Tooling/Refactoring/RefactoringActionRule.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Refactoring/RefactoringActionRule.h?rev=316780&r1=316779&r2=316780&view=diff
==
--- cfe/trunk/include/clang/Tooling/Refactoring/RefactoringActionRule.h 
(original)
+++ cfe/trunk/include/clang/Tooling/Refactoring/Refacto

[PATCH] D38728: [analyzer] Use the signature of the primary template for issue hash calculation

2017-10-27 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna accepted this revision.
zaks.anna added a comment.

LGTM!


https://reviews.llvm.org/D38728



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


[PATCH] D39378: Remove x86,x86_32/64 from isValidFeatureName

2017-10-27 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.

These are not valid values for this, and are pretty
non-sensical, since LLVM doesn't understand them.


https://reviews.llvm.org/D39378

Files:
  lib/Basic/Targets/X86.cpp


Index: lib/Basic/Targets/X86.cpp
===
--- lib/Basic/Targets/X86.cpp
+++ lib/Basic/Targets/X86.cpp
@@ -1169,9 +1169,6 @@
   .Case("sse4.2", true)
   .Case("sse4a", true)
   .Case("tbm", true)
-  .Case("x86", true)
-  .Case("x86_32", true)
-  .Case("x86_64", true)
   .Case("xop", true)
   .Case("xsave", true)
   .Case("xsavec", true)


Index: lib/Basic/Targets/X86.cpp
===
--- lib/Basic/Targets/X86.cpp
+++ lib/Basic/Targets/X86.cpp
@@ -1169,9 +1169,6 @@
   .Case("sse4.2", true)
   .Case("sse4a", true)
   .Case("tbm", true)
-  .Case("x86", true)
-  .Case("x86_32", true)
-  .Case("x86_64", true)
   .Case("xop", true)
   .Case("xsave", true)
   .Case("xsavec", true)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D38985: [refactor] Add support for editor commands that connect IDEs/editors to the refactoring actions

2017-10-27 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
arphaman marked 3 inline comments as done.
Closed by commit rL316780: [refactor] Describe refactorings in the operation 
classes (authored by arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D38985?vs=120466&id=120660#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38985

Files:
  cfe/trunk/include/clang/Tooling/Refactoring/Extract/Extract.h
  cfe/trunk/include/clang/Tooling/Refactoring/RefactoringActionRegistry.def
  cfe/trunk/include/clang/Tooling/Refactoring/RefactoringActionRule.h
  cfe/trunk/include/clang/Tooling/Refactoring/RefactoringActionRulesInternal.h
  cfe/trunk/include/clang/Tooling/Refactoring/Rename/RenamingAction.h
  cfe/trunk/include/clang/module.modulemap
  cfe/trunk/lib/Tooling/Refactoring/Extract.cpp
  cfe/trunk/lib/Tooling/Refactoring/RefactoringActions.cpp
  cfe/trunk/lib/Tooling/Refactoring/Rename/RenamingAction.cpp
  cfe/trunk/unittests/Tooling/RefactoringActionRulesTest.cpp

Index: cfe/trunk/lib/Tooling/Refactoring/Rename/RenamingAction.cpp
===
--- cfe/trunk/lib/Tooling/Refactoring/Rename/RenamingAction.cpp
+++ cfe/trunk/lib/Tooling/Refactoring/Rename/RenamingAction.cpp
@@ -41,22 +41,6 @@
 
 namespace {
 
-class SymbolSelectionRequirement : public SourceRangeSelectionRequirement {
-public:
-  Expected evaluate(RefactoringRuleContext &Context) const {
-Expected Selection =
-SourceRangeSelectionRequirement::evaluate(Context);
-if (!Selection)
-  return Selection.takeError();
-const NamedDecl *ND =
-getNamedDeclAt(Context.getASTContext(), Selection->getBegin());
-if (!ND)
-  return Context.createDiagnosticError(
-  Selection->getBegin(), diag::err_refactor_selection_no_symbol);
-return getCanonicalSymbolDeclaration(ND);
-  }
-};
-
 class OccurrenceFinder final : public FindSymbolOccurrencesRefactoringRule {
 public:
   OccurrenceFinder(const NamedDecl *ND) : ND(ND) {}
@@ -74,50 +58,38 @@
   const NamedDecl *ND;
 };
 
-class RenameOccurrences final : public SourceChangeRefactoringRule {
-public:
-  RenameOccurrences(const NamedDecl *ND, std::string NewName)
-  : Finder(ND), NewName(std::move(NewName)) {}
-
-  Expected
-  createSourceReplacements(RefactoringRuleContext &Context) override {
-Expected Occurrences =
-Finder.findSymbolOccurrences(Context);
-if (!Occurrences)
-  return Occurrences.takeError();
-// FIXME: Verify that the new name is valid.
-SymbolName Name(NewName);
-return createRenameReplacements(
-*Occurrences, Context.getASTContext().getSourceManager(), Name);
-  }
-
-private:
-  OccurrenceFinder Finder;
-  std::string NewName;
-};
-
-class LocalRename final : public RefactoringAction {
-public:
-  StringRef getCommand() const override { return "local-rename"; }
-
-  StringRef getDescription() const override {
-return "Finds and renames symbols in code with no indexer support";
-  }
+} // end anonymous namespace
 
-  /// Returns a set of refactoring actions rules that are defined by this
-  /// action.
-  RefactoringActionRules createActionRules() const override {
-RefactoringActionRules Rules;
-Rules.push_back(createRefactoringActionRule(
-SymbolSelectionRequirement(), OptionRequirement()));
-return Rules;
-  }
-};
+const RefactoringDescriptor &RenameOccurrences::describe() {
+  static const RefactoringDescriptor Descriptor = {
+  "local-rename",
+  "Rename",
+  "Finds and renames symbols in code with no indexer support",
+  };
+  return Descriptor;
+}
 
-} // end anonymous namespace
+Expected
+RenameOccurrences::initiate(RefactoringRuleContext &Context,
+SourceRange SelectionRange, std::string NewName) {
+  const NamedDecl *ND =
+  getNamedDeclAt(Context.getASTContext(), SelectionRange.getBegin());
+  if (!ND)
+return Context.createDiagnosticError(
+SelectionRange.getBegin(), diag::err_refactor_selection_no_symbol);
+  return RenameOccurrences(getCanonicalSymbolDeclaration(ND), NewName);
+}
 
-std::unique_ptr createLocalRenameAction() {
-  return llvm::make_unique();
+Expected
+RenameOccurrences::createSourceReplacements(RefactoringRuleContext &Context) {
+  Expected Occurrences =
+  OccurrenceFinder(ND).findSymbolOccurrences(Context);
+  if (!Occurrences)
+return Occurrences.takeError();
+  // FIXME: Verify that the new name is valid.
+  SymbolName Name(NewName);
+  return createRenameReplacements(
+  *Occurrences, Context.getASTContext().getSourceManager(), Name);
 }
 
 Expected>
Index: cfe/trunk/lib/Tooling/Refactoring/RefactoringActions.cpp
===
--- cfe/trunk/lib/Tooling/Refactoring/RefactoringActions.cpp
+++ cfe/trunk/lib/Tooling/Refactoring/RefactoringActions.cpp
@@ -7,21 +7,80 @@
 //
 //===--==

[PATCH] D38844: [analyzer] Make issue hash related tests more concise

2017-10-27 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp:68
   // (globals should not be invalidated, etc), hence the use of evalCall.
-  FnCheck Handler = llvm::StringSwitch(C.getCalleeName(CE))
-.Case("clang_analyzer_eval", &ExprInspectionChecker::analyzerEval)
-.Case("clang_analyzer_checkInlined",
-  &ExprInspectionChecker::analyzerCheckInlined)
-.Case("clang_analyzer_crash", &ExprInspectionChecker::analyzerCrash)
-.Case("clang_analyzer_warnIfReached",
-  &ExprInspectionChecker::analyzerWarnIfReached)
-.Case("clang_analyzer_warnOnDeadSymbol",
-  &ExprInspectionChecker::analyzerWarnOnDeadSymbol)
-.StartsWith("clang_analyzer_explain", 
&ExprInspectionChecker::analyzerExplain)
-.StartsWith("clang_analyzer_dump", &ExprInspectionChecker::analyzerDump)
-.Case("clang_analyzer_getExtent", 
&ExprInspectionChecker::analyzerGetExtent)
-.Case("clang_analyzer_printState",
-  &ExprInspectionChecker::analyzerPrintState)
-.Case("clang_analyzer_numTimesReached",
-  &ExprInspectionChecker::analyzerNumTimesReached)
-.Default(nullptr);
+  FnCheck Handler =
+  llvm::StringSwitch(C.getCalleeName(CE))

zaks.anna wrote:
> Unrelated change?
Since I touched this snippet I reformatted it using clang-format. Apart from 
adding a new case before the default all other changes are formatting changes. 
I will revert the formatting changes. So in general, we prefer to minimize the 
diffs over converging to be clang-formatted?


https://reviews.llvm.org/D38844



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


[PATCH] D39378: Remove x86,x86_32/64 from isValidFeatureName

2017-10-27 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D39378



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


[PATCH] D39269: [Analyzer] [Tests] Do not discard output from CmpRuns.py when running integration tests

2017-10-27 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna accepted this revision.
zaks.anna added a comment.
This revision is now accepted and ready to land.

What kind of output will this start displaying?

(I believe currently the script does print the summary of the objects that are 
added or deleted.)


https://reviews.llvm.org/D39269



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


r316781 - Remove x86,x86_32/64 from isValidFeatureName

2017-10-27 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Fri Oct 27 11:29:02 2017
New Revision: 316781

URL: http://llvm.org/viewvc/llvm-project?rev=316781&view=rev
Log:
Remove x86,x86_32/64 from isValidFeatureName

These are not valid values for this, and are pretty
non-sensical, since LLVM doesn't understand them.

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

Modified:
cfe/trunk/lib/Basic/Targets/X86.cpp

Modified: cfe/trunk/lib/Basic/Targets/X86.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/X86.cpp?rev=316781&r1=316780&r2=316781&view=diff
==
--- cfe/trunk/lib/Basic/Targets/X86.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/X86.cpp Fri Oct 27 11:29:02 2017
@@ -1169,9 +1169,6 @@ bool X86TargetInfo::isValidFeatureName(S
   .Case("sse4.2", true)
   .Case("sse4a", true)
   .Case("tbm", true)
-  .Case("x86", true)
-  .Case("x86_32", true)
-  .Case("x86_64", true)
   .Case("xop", true)
   .Case("xsave", true)
   .Case("xsavec", true)


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


[PATCH] D39378: Remove x86,x86_32/64 from isValidFeatureName

2017-10-27 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316781: Remove x86,x86_32/64 from isValidFeatureName 
(authored by erichkeane).

Changed prior to commit:
  https://reviews.llvm.org/D39378?vs=120661&id=120663#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39378

Files:
  cfe/trunk/lib/Basic/Targets/X86.cpp


Index: cfe/trunk/lib/Basic/Targets/X86.cpp
===
--- cfe/trunk/lib/Basic/Targets/X86.cpp
+++ cfe/trunk/lib/Basic/Targets/X86.cpp
@@ -1169,9 +1169,6 @@
   .Case("sse4.2", true)
   .Case("sse4a", true)
   .Case("tbm", true)
-  .Case("x86", true)
-  .Case("x86_32", true)
-  .Case("x86_64", true)
   .Case("xop", true)
   .Case("xsave", true)
   .Case("xsavec", true)


Index: cfe/trunk/lib/Basic/Targets/X86.cpp
===
--- cfe/trunk/lib/Basic/Targets/X86.cpp
+++ cfe/trunk/lib/Basic/Targets/X86.cpp
@@ -1169,9 +1169,6 @@
   .Case("sse4.2", true)
   .Case("sse4a", true)
   .Case("tbm", true)
-  .Case("x86", true)
-  .Case("x86_32", true)
-  .Case("x86_64", true)
   .Case("xop", true)
   .Case("xsave", true)
   .Case("xsavec", true)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r316783 - Filter out invalid 'target' items from being passed to LLVM

2017-10-27 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Fri Oct 27 11:32:23 2017
New Revision: 316783

URL: http://llvm.org/viewvc/llvm-project?rev=316783&view=rev
Log:
Filter out invalid 'target' items from being passed to LLVM

Craig noticed that CodeGen wasn't properly ignoring the
values sent to the target attribute. This patch ignores
them.

This patch also sets the 'default' for this checking to
'supported', since only X86 has implemented the support
for checking valid CPU names and Feature Names.

One test was changed to i686, since it uses a lakemont,
which would otherwise be prohibited in x86_64.

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


Modified:
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/Basic/Targets/X86.cpp
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGen/attr-target-x86.c

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=316783&r1=316782&r2=316783&view=diff
==
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Fri Oct 27 11:32:23 2017
@@ -861,7 +861,7 @@ public:
 
   /// brief Determine whether this TargetInfo supports the given CPU name.
   virtual bool isValidCPUName(StringRef Name) const {
-return false;
+return true;
   }
 
   /// \brief Use the specified ABI.
@@ -888,7 +888,7 @@ public:
 
   /// \brief Determine whether this TargetInfo supports the given feature.
   virtual bool isValidFeatureName(StringRef Feature) const {
-return false;
+return true;
   }
 
   /// \brief Perform initialization based on the user configured

Modified: cfe/trunk/lib/Basic/Targets/X86.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/X86.cpp?rev=316783&r1=316782&r2=316783&view=diff
==
--- cfe/trunk/lib/Basic/Targets/X86.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/X86.cpp Fri Oct 27 11:32:23 2017
@@ -1169,6 +1169,7 @@ bool X86TargetInfo::isValidFeatureName(S
   .Case("sse4.2", true)
   .Case("sse4a", true)
   .Case("tbm", true)
+  .Case("x87", true)
   .Case("xop", true)
   .Case("xsave", true)
   .Case("xsavec", true)

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=316783&r1=316782&r2=316783&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Fri Oct 27 11:32:23 2017
@@ -1885,10 +1885,11 @@ void CodeGenModule::ConstructAttributeLi
   // the function.
   const auto *TD = FD->getAttr();
   TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse();
-  if (ParsedAttr.Architecture != "")
+  if (ParsedAttr.Architecture != "" &&
+  getTarget().isValidCPUName(ParsedAttr.Architecture))
 TargetCPU = ParsedAttr.Architecture;
   if (TargetCPU != "")
-FuncAttrs.addAttribute("target-cpu", TargetCPU);
+ FuncAttrs.addAttribute("target-cpu", TargetCPU);
   if (!Features.empty()) {
 std::sort(Features.begin(), Features.end());
 FuncAttrs.addAttribute(

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=316783&r1=316782&r2=316783&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Oct 27 11:32:23 2017
@@ -4582,14 +4582,23 @@ void CodeGenModule::getFunctionFeatureMa
 // If we have a TargetAttr build up the feature map based on that.
 TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse();
 
+ParsedAttr.Features.erase(
+llvm::remove_if(ParsedAttr.Features,
+[&](const std::string &Feat) {
+  return !Target.isValidFeatureName(
+  StringRef{Feat}.substr(1));
+}),
+ParsedAttr.Features.end());
+
 // Make a copy of the features as passed on the command line into the
 // beginning of the additional features from the function to override.
 ParsedAttr.Features.insert(ParsedAttr.Features.begin(),
 Target.getTargetOpts().FeaturesAsWritten.begin(),
 Target.getTargetOpts().FeaturesAsWritten.end());
 
-if (ParsedAttr.Architecture != "")
-  TargetCPU = ParsedAttr.Architecture ;
+if (ParsedAttr.Architecture != "" &&
+Target.isValidCPUName(ParsedAttr.Architecture))
+  TargetCPU = ParsedAttr.Architecture;
 
 // Now populate the feature map, first with the TargetCPU which is either
 // the default or a new one 

[PATCH] D39357: Filter out invalid 'target' items from being passed to LLVM

2017-10-27 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D39357



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


[PATCH] D39357: Filter out invalid 'target' items from being passed to LLVM

2017-10-27 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316783: Filter out invalid 'target' items from being passed 
to LLVM (authored by erichkeane).

Changed prior to commit:
  https://reviews.llvm.org/D39357?vs=120659&id=120664#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39357

Files:
  cfe/trunk/include/clang/Basic/TargetInfo.h
  cfe/trunk/lib/Basic/Targets/X86.cpp
  cfe/trunk/lib/CodeGen/CGCall.cpp
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/test/CodeGen/attr-target-x86.c

Index: cfe/trunk/test/CodeGen/attr-target-x86.c
===
--- cfe/trunk/test/CodeGen/attr-target-x86.c
+++ cfe/trunk/test/CodeGen/attr-target-x86.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -target-cpu x86-64 -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple i686-linux-gnu -target-cpu i686 -emit-llvm %s -o - | FileCheck %s
 
 int baz(int a) { return 4; }
 
@@ -19,7 +19,7 @@
 
 int __attribute__((target("no-mmx"))) qq(int a) { return 40; }
 
-int __attribute__((target("arch=lakemont"))) lake(int a) { return 4; }
+int __attribute__((target("arch=lakemont,mmx"))) lake(int a) { return 4; }
 
 // Check that we emit the additional subtarget and cpu features for foo and not for baz or bar.
 // CHECK: baz{{.*}} #0
@@ -36,11 +36,11 @@
 // CHECK: qax{{.*}} #5
 // CHECK: qq{{.*}} #6
 // CHECK: lake{{.*}} #7
-// CHECK: #0 = {{.*}}"target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87"
+// CHECK: #0 = {{.*}}"target-cpu"="i686" "target-features"="+x87"
 // CHECK: #1 = {{.*}}"target-cpu"="ivybridge" "target-features"="+aes,+avx,+cx16,+f16c,+fsgsbase,+fxsr,+mmx,+pclmul,+popcnt,+rdrnd,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+xsaveopt"
-// CHECK: #2 = {{.*}}"target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+x87,-aes,-avx,-avx2,-avx512bw,-avx512cd,-avx512dq,-avx512er,-avx512f,-avx512ifma,-avx512pf,-avx512vbmi,-avx512vl,-avx512vpopcntdq,-f16c,-fma,-fma4,-pclmul,-sha,-sse2,-sse3,-sse4.1,-sse4.2,-sse4a,-ssse3,-xop,-xsave,-xsaveopt"
-// CHECK: #3 = {{.*}}"target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87"
-// CHECK: #4 = {{.*}}"target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87,-avx,-avx2,-avx512bw,-avx512cd,-avx512dq,-avx512er,-avx512f,-avx512ifma,-avx512pf,-avx512vbmi,-avx512vl,-avx512vpopcntdq,-f16c,-fma,-fma4,-sse4.1,-sse4.2,-xop,-xsave,-xsaveopt"
+// CHECK: #2 = {{.*}}"target-cpu"="i686" "target-features"="+x87,-aes,-avx,-avx2,-avx512bw,-avx512cd,-avx512dq,-avx512er,-avx512f,-avx512ifma,-avx512pf,-avx512vbmi,-avx512vl,-avx512vpopcntdq,-f16c,-fma,-fma4,-pclmul,-sha,-sse2,-sse3,-sse4.1,-sse4.2,-sse4a,-ssse3,-xop,-xsave,-xsaveopt"
+// CHECK: #3 = {{.*}}"target-cpu"="i686" "target-features"="+mmx,+popcnt,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87"
+// CHECK: #4 = {{.*}}"target-cpu"="i686" "target-features"="+x87,-avx,-avx2,-avx512bw,-avx512cd,-avx512dq,-avx512er,-avx512f,-avx512ifma,-avx512pf,-avx512vbmi,-avx512vl,-avx512vpopcntdq,-f16c,-fma,-fma4,-sse4.1,-sse4.2,-xop,-xsave,-xsaveopt"
 // CHECK: #5 = {{.*}}"target-cpu"="ivybridge" "target-features"="+avx,+cx16,+f16c,+fsgsbase,+fxsr,+mmx,+pclmul,+popcnt,+rdrnd,+sse,+sse2,+sse3,+sse4.1,+sse4.2,+ssse3,+x87,+xsave,+xsaveopt,-aes"
-// CHECK: #6 = {{.*}}"target-cpu"="x86-64" "target-features"="+fxsr,+sse,+sse2,+x87,-3dnow,-3dnowa,-mmx"
-// CHECK: #7 = {{.*}}"target-cpu"="lakemont" "target-features"="+mmx,+sse,+sse2"
+// CHECK: #6 = {{.*}}"target-cpu"="i686" "target-features"="+x87,-3dnow,-3dnowa,-mmx"
+// CHECK: #7 = {{.*}}"target-cpu"="lakemont" "target-features"="+mmx"
Index: cfe/trunk/lib/CodeGen/CGCall.cpp
===
--- cfe/trunk/lib/CodeGen/CGCall.cpp
+++ cfe/trunk/lib/CodeGen/CGCall.cpp
@@ -1885,10 +1885,11 @@
   // the function.
   const auto *TD = FD->getAttr();
   TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse();
-  if (ParsedAttr.Architecture != "")
+  if (ParsedAttr.Architecture != "" &&
+  getTarget().isValidCPUName(ParsedAttr.Architecture))
 TargetCPU = ParsedAttr.Architecture;
   if (TargetCPU != "")
-FuncAttrs.addAttribute("target-cpu", TargetCPU);
+ FuncAttrs.addAttribute("target-cpu", TargetCPU);
   if (!Features.empty()) {
 std::sort(Features.begin(), Features.end());
 FuncAttrs.addAttribute(
Index: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp
@@ -4582,14 +4582,23 @@
 // If we have a TargetAttr build up the feature map based on that.
 TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse();
 
+ParsedAttr.Features.erase(
+llvm::remove_if(ParsedAttr.Features,
+[&](const std::string &Feat) {
+  retur

[PATCH] D39332: [clang-refactor] Introduce "local-qualified-rename" action.

2017-10-27 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: lib/Tooling/Refactoring/Rename/RenamingAction.cpp:154
+
+class LocalQualifiedRename final : public RefactoringAction {
+public:

arphaman wrote:
> hokein wrote:
> > sammccall wrote:
> > > As discussed offline, it's not clear why this is a separate Action, 
> > > rather than a different Rule that's part of the same Action.
> > > 
> > > @arphaman how does the framework answer this question?
> > There is a 
> > [document](https://clang.llvm.org/docs/RefactoringEngine.html#refactoring-action-rules)
> >  describing it, but still ambiguous.
> > 
> > We also had some questions about `local-rename` from the discussion, need 
> > @arphaman's input:
> > 
> > * `OccurrenceFinder` is not exposed now, it is merely used in 
> > `RenameOccurrences`. We think there should be a public interface to the 
> > clients, like for implementing interactive mode in IDE? 
> > * Currently the rules defined in the same action must have mutual 
> > command-line options, otherwise clang-refactor would complain the 
> > command-line option are being registered more than once. It might be very 
> > strict for some cases. For example, `-new-name` is most likely being used 
> > by many rules in `local-rename` action.
> >  
> I think that this should be just a rule in `local-rename`.
> 
> So you'd be able to call:
> 
> `clang-refactor local-rename -selection=X -new-name=foo`
> `clang-refactor local-rename -old-qualified-name=bar -new-name=foo`.
We need your help to understand how exactly `local-rename` is intended to be 
used. 

From the current code and previous conversations we had, it seems to me that 
the action would support the use case where a user selects an identifier in the 
editor (say, with cursor) and initiates a `local-rename` action but without 
providing the new name in the beginning. The rename rule finds and returns all 
occurrences (including token ranges)  to the editor, and users can then start 
typing in the new name, and in the same time, the editor performs text 
replacements according to ranges of occurrences and the new name typed in. Is 
this how `RenameOccurrences` is intended to be used in the future? 

If this is how `local-rename` is expected to be used, it would be hard to merge 
qualified rename into it, because both qualified old name and new name are 
required in order to calculate the range of a symbol reference, and this 
doesn't fit with the above workflow. But if my understanding is simply wrong 
(e.g. the editor would invoke `local-rename` again to perform the actual 
refactoring), then I think it makes a lot of sense to merge qualified rename 
into the current local-rename action.


https://reviews.llvm.org/D39332



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


  1   2   >