[PATCH] D42043: c-index: CXString: fix MSAN read-past-end bug

2018-01-18 Thread Steve O'Brien via Phabricator via cfe-commits
elsteveogrande updated this revision to Diff 130557.
elsteveogrande added a comment.

remove unneeded changes


Repository:
  rC Clang

https://reviews.llvm.org/D42043

Files:
  include/clang-c/CXString.h
  tools/c-index-test/c-index-test.c
  tools/libclang/CXString.cpp

Index: tools/libclang/CXString.cpp
===
--- tools/libclang/CXString.cpp
+++ tools/libclang/CXString.cpp
@@ -15,99 +15,130 @@
 
 #include "CXString.h"
 #include "CXTranslationUnit.h"
+#include "clang-c/CXString.h"
 #include "clang-c/Index.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "llvm/Support/ErrorHandling.h"
+#include 
 
-using namespace clang;
-
-/// Describes the kind of underlying data in CXString.
-enum CXStringFlag {
-  /// CXString contains a 'const char *' that it doesn't own.
-  CXS_Unmanaged,
-
-  /// CXString contains a 'const char *' that it allocated with malloc().
-  CXS_Malloc,
+static_assert(sizeof(CXString) <= 16, "");
 
-  /// CXString contains a CXStringBuf that needs to be returned to the
-  /// CXStringPool.
-  CXS_StringBuf
-};
+using namespace clang;
 
 namespace clang {
 namespace cxstring {
 
+/**
+ * This is for \b CXString 's which are created with \b CreateRef(StringRef).
+ * We'll store the info from the input \b StringRef: char ptr and size.
+ *
+ * We don't know for sure whether this is null-terminated so, when and if
+ * \b clang_getCString is called for this \b CXString, we'll allocate C string
+ * storage and copy data into the storage.  We'll memo-ize that in the
+ * \b CString member.
+ *
+ * This is refcounted; the \b Count member is initially 1.  When a \b CXString
+ * instance using this object is disposed via \b clang_disposeString, \b Count
+ * is decremented.  When this string is duplicated the \b Count increases.
+ *
+ * When \b Count finally drops to zero, the ptr at \b CString, and this object,
+ * should be deleted.
+ */
+struct RefCountedCharRange {
+  const char *Data;
+  const char *CString;
+  unsigned Size;
+  unsigned Count;
+};
+
 //===--===//
 // Basic generation of CXStrings.
 //===--===//
 
-CXString createEmpty() {
+CXString createRef(const char *String) {
   CXString Str;
-  Str.data = "";
-  Str.private_flags = CXS_Unmanaged;
+  Str.Contents = (const void *) String;
+  if (String) {
+Str.Size = strlen(String);
+Str.IsNullTerminated = true;
+  } else {
+Str.Size = 0;
+Str.IsNullTerminated = false;
+  }
+  Str.IsOwned = false;
+  Str.IsPooled = false;
   return Str;
 }
 
-CXString createNull() {
-  CXString Str;
-  Str.data = nullptr;
-  Str.private_flags = CXS_Unmanaged;
-  return Str;
+CXString createEmpty() {
+  return createRef("");
 }
 
-CXString createRef(const char *String) {
-  if (String && String[0] == '\0')
-return createEmpty();
+CXString createNull() {
+  return createRef(nullptr);
+}
 
-  CXString Str;
-  Str.data = String;
-  Str.private_flags = CXS_Unmanaged;
-  return Str;
+inline static const char *copyCharRange(const char *CS, unsigned Size) {
+  char *Spelling = (char *) malloc(Size + 1);
+  assert(Spelling);
+  if (CS) {
+memcpy(Spelling, CS, Size);
+  }
+  Spelling[Size] = 0;
+  return Spelling;
 }
 
 CXString createDup(const char *String) {
-  if (!String)
+  if (!String) {
 return createNull();
-
-  if (String[0] == '\0')
+  }
+  if (String[0] == '\0') {
 return createEmpty();
+  }
 
   CXString Str;
-  Str.data = strdup(String);
-  Str.private_flags = CXS_Malloc;
+  Str.Size = strlen(String);
+  Str.Contents = (const void *) copyCharRange(String, Str.Size);
+  Str.IsNullTerminated = true;
+  Str.IsOwned = true;
+  Str.IsPooled = false;
   return Str;
 }
 
 CXString createRef(StringRef String) {
-  // If the string is not nul-terminated, we have to make a copy.
-
-  // FIXME: This is doing a one past end read, and should be removed! For memory
-  // we don't manage, the API string can become unterminated at any time outside
-  // our control.
-
-  if (!String.empty() && String.data()[String.size()] != 0)
-return createDup(String);
-
-  CXString Result;
-  Result.data = String.data();
-  Result.private_flags = (unsigned) CXS_Unmanaged;
-  return Result;
+  assert (String.size() <= std::numeric_limits::max());
+  CXString Str;
+  Str.Size = unsigned(String.size());
+  Str.IsNullTerminated = false;
+  Str.IsOwned = false;
+  Str.IsPooled = false;
+  auto *RC = new RefCountedCharRange {
+/* Data */ String.data(),
+/* CString */ nullptr,
+/* Size */ Str.Size,
+/* Count */ 1,
+  };
+  Str.Contents = (const void *) RC;
+  return Str;
 }
 
 CXString createDup(StringRef String) {
-  CXString Result;
-  char *Spelling = static_cast(malloc(String.size() + 1));
-  memmove(Spelling, String.data(), String.size());
-  Spelling[String.size()] = 0;
-  Result.data = Spelling;
-  Result.private_flags = (unsigned) 

[PATCH] D42043: c-index: CXString: fix MSAN read-past-end bug

2018-01-18 Thread Steve O'Brien via Phabricator via cfe-commits
elsteveogrande updated this revision to Diff 130556.
elsteveogrande marked an inline comment as done.
elsteveogrande added a comment.

Fixes, but first, a question for reviewers:

Looking at the description of `clang_disposeString`:

  /**
   * \brief Free the given string.
   */
  CINDEX_LINKAGE void clang_disposeString(CXString string);

Does it seem incorrect to acquire some `const char *` pointer into this string, 
dispose the string, and then access the characters?

I've seen this happen a couple of times now.  As I make changes to my code I 
run into this pattern.  (Since now this triggers a use-after-free abort.)

I wanted to ask because, though it seemed obvious to me that this is incorrect 
usage, I'm now wondering if the expectation is that it's ok.  Or maybe wasn't 
technically ok, and we just "got away with it" before.  :)

Anyway, assuming it's only correct to use the string before disposing it, then 
the fixes this time around are:

- Fix an ASAN use-after-free in `c-index-test` mentioned above.  Get the 
`CXString`, pass it around, then dispose when we're done with it.
- Change `createEmpty` and `createNull` to delegate through `createRef`
- `createRef` tolerates `nullptr` correctly.
- I previously ran into ASAN aborts due to mixing malloc/free/operator 
new/delete.  I had changed everything to use operator new/delete.  However from 
C-land I can't `new char[length]`, only `malloc` (or `strdup` or whatever).  
Change everything to malloc/free instead.


Repository:
  rC Clang

https://reviews.llvm.org/D42043

Files:
  .watchmanconfig
  include/clang-c/CXString.h
  tools/c-index-test/c-index-test.c
  tools/libclang/CXString.cpp
  tools/libclang/CXString.h

Index: tools/libclang/CXString.h
===
--- tools/libclang/CXString.h
+++ tools/libclang/CXString.h
@@ -106,4 +106,3 @@
 }
 
 #endif
-
Index: tools/libclang/CXString.cpp
===
--- tools/libclang/CXString.cpp
+++ tools/libclang/CXString.cpp
@@ -15,99 +15,130 @@
 
 #include "CXString.h"
 #include "CXTranslationUnit.h"
+#include "clang-c/CXString.h"
 #include "clang-c/Index.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "llvm/Support/ErrorHandling.h"
+#include 
 
-using namespace clang;
-
-/// Describes the kind of underlying data in CXString.
-enum CXStringFlag {
-  /// CXString contains a 'const char *' that it doesn't own.
-  CXS_Unmanaged,
-
-  /// CXString contains a 'const char *' that it allocated with malloc().
-  CXS_Malloc,
+static_assert(sizeof(CXString) <= 16, "");
 
-  /// CXString contains a CXStringBuf that needs to be returned to the
-  /// CXStringPool.
-  CXS_StringBuf
-};
+using namespace clang;
 
 namespace clang {
 namespace cxstring {
 
+/**
+ * This is for \b CXString 's which are created with \b CreateRef(StringRef).
+ * We'll store the info from the input \b StringRef: char ptr and size.
+ *
+ * We don't know for sure whether this is null-terminated so, when and if
+ * \b clang_getCString is called for this \b CXString, we'll allocate C string
+ * storage and copy data into the storage.  We'll memo-ize that in the
+ * \b CString member.
+ *
+ * This is refcounted; the \b Count member is initially 1.  When a \b CXString
+ * instance using this object is disposed via \b clang_disposeString, \b Count
+ * is decremented.  When this string is duplicated the \b Count increases.
+ *
+ * When \b Count finally drops to zero, the ptr at \b CString, and this object,
+ * should be deleted.
+ */
+struct RefCountedCharRange {
+  const char *Data;
+  const char *CString;
+  unsigned Size;
+  unsigned Count;
+};
+
 //===--===//
 // Basic generation of CXStrings.
 //===--===//
 
-CXString createEmpty() {
+CXString createRef(const char *String) {
   CXString Str;
-  Str.data = "";
-  Str.private_flags = CXS_Unmanaged;
+  Str.Contents = (const void *) String;
+  if (String) {
+Str.Size = strlen(String);
+Str.IsNullTerminated = true;
+  } else {
+Str.Size = 0;
+Str.IsNullTerminated = false;
+  }
+  Str.IsOwned = false;
+  Str.IsPooled = false;
   return Str;
 }
 
-CXString createNull() {
-  CXString Str;
-  Str.data = nullptr;
-  Str.private_flags = CXS_Unmanaged;
-  return Str;
+CXString createEmpty() {
+  return createRef("");
 }
 
-CXString createRef(const char *String) {
-  if (String && String[0] == '\0')
-return createEmpty();
+CXString createNull() {
+  return createRef(nullptr);
+}
 
-  CXString Str;
-  Str.data = String;
-  Str.private_flags = CXS_Unmanaged;
-  return Str;
+inline static const char *copyCharRange(const char *CS, unsigned Size) {
+  char *Spelling = (char *) malloc(Size + 1);
+  assert(Spelling);
+  if (CS) {
+memcpy(Spelling, CS, Size);
+  }
+  Spelling[Size] = 0;
+  return Spelling;
 }
 
 CXString createDup(const char *String) {
- 

[PATCH] D42283: [Fuchsia] Tests for the Fuzzer support in Fuchsia driver

2018-01-18 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322922: [Fuchsia] Tests for the Fuzzer support in Fuchsia 
driver (authored by phosek, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D42283?vs=130552=130555#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D42283

Files:
  cfe/trunk/test/Driver/fuchsia.c


Index: cfe/trunk/test/Driver/fuchsia.c
===
--- cfe/trunk/test/Driver/fuchsia.c
+++ cfe/trunk/test/Driver/fuchsia.c
@@ -81,18 +81,33 @@
 // CHECK-ASAN-SHARED-NOT: "{{.*[/\\]}}libclang_rt.asan-preinit-x86_64.a"
 
 // RUN: %clang %s -### --target=x86_64-fuchsia \
+// RUN: -fsanitize=fuzzer 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-FUZZER-X86
+// CHECK-FUZZER-X86: "-fsanitize=fuzzer,fuzzer-no-link"
+// CHECK-FUZZER-X86: "{{.*[/\\]}}libclang_rt.fuzzer-x86_64.a"
+
+// RUN: %clang %s -### --target=aarch64-fuchsia \
+// RUN: -fsanitize=fuzzer 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-FUZZER-AARCH64
+// CHECK-FUZZER-AARCH64: "-fsanitize=fuzzer,fuzzer-no-link"
+// CHECK-FUZZER-AARCH64: "{{.*[/\\]}}libclang_rt.fuzzer-aarch64.a"
+
+// RUN: %clang %s -### --target=x86_64-fuchsia \
 // RUN: -fsanitize=scudo 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-X86
 // CHECK-SCUDO-X86: "-fsanitize=scudo"
 // CHECK-SCUDO-X86: "-pie"
+// CHECK-SCUDO-X86: "{{.*[/\\]}}libclang_rt.scudo-x86_64.so"
 
 // RUN: %clang %s -### --target=aarch64-fuchsia \
 // RUN: -fsanitize=scudo 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-AARCH64
 // CHECK-SCUDO-AARCH64: "-fsanitize=scudo"
 // CHECK-SCUDO-AARCH64: "-pie"
+// CHECK-SCUDO-AARCH64: "{{.*[/\\]}}libclang_rt.scudo-aarch64.so"
 
 // RUN: %clang %s -### --target=x86_64-fuchsia \
 // RUN: -fsanitize=scudo -fPIC -shared 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-SHARED
 // CHECK-SCUDO-SHARED: "-fsanitize=scudo"
+// CHECK-SCUDO-SHARED: "{{.*[/\\]}}libclang_rt.scudo-x86_64.so"


Index: cfe/trunk/test/Driver/fuchsia.c
===
--- cfe/trunk/test/Driver/fuchsia.c
+++ cfe/trunk/test/Driver/fuchsia.c
@@ -81,18 +81,33 @@
 // CHECK-ASAN-SHARED-NOT: "{{.*[/\\]}}libclang_rt.asan-preinit-x86_64.a"
 
 // RUN: %clang %s -### --target=x86_64-fuchsia \
+// RUN: -fsanitize=fuzzer 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-FUZZER-X86
+// CHECK-FUZZER-X86: "-fsanitize=fuzzer,fuzzer-no-link"
+// CHECK-FUZZER-X86: "{{.*[/\\]}}libclang_rt.fuzzer-x86_64.a"
+
+// RUN: %clang %s -### --target=aarch64-fuchsia \
+// RUN: -fsanitize=fuzzer 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-FUZZER-AARCH64
+// CHECK-FUZZER-AARCH64: "-fsanitize=fuzzer,fuzzer-no-link"
+// CHECK-FUZZER-AARCH64: "{{.*[/\\]}}libclang_rt.fuzzer-aarch64.a"
+
+// RUN: %clang %s -### --target=x86_64-fuchsia \
 // RUN: -fsanitize=scudo 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-X86
 // CHECK-SCUDO-X86: "-fsanitize=scudo"
 // CHECK-SCUDO-X86: "-pie"
+// CHECK-SCUDO-X86: "{{.*[/\\]}}libclang_rt.scudo-x86_64.so"
 
 // RUN: %clang %s -### --target=aarch64-fuchsia \
 // RUN: -fsanitize=scudo 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-AARCH64
 // CHECK-SCUDO-AARCH64: "-fsanitize=scudo"
 // CHECK-SCUDO-AARCH64: "-pie"
+// CHECK-SCUDO-AARCH64: "{{.*[/\\]}}libclang_rt.scudo-aarch64.so"
 
 // RUN: %clang %s -### --target=x86_64-fuchsia \
 // RUN: -fsanitize=scudo -fPIC -shared 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-SHARED
 // CHECK-SCUDO-SHARED: "-fsanitize=scudo"
+// CHECK-SCUDO-SHARED: "{{.*[/\\]}}libclang_rt.scudo-x86_64.so"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r322922 - [Fuchsia] Tests for the Fuzzer support in Fuchsia driver

2018-01-18 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Thu Jan 18 20:08:06 2018
New Revision: 322922

URL: http://llvm.org/viewvc/llvm-project?rev=322922=rev
Log:
[Fuchsia] Tests for the Fuzzer support in Fuchsia driver

This adds driver tests for the Fuzzer support.

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

Modified:
cfe/trunk/test/Driver/fuchsia.c

Modified: cfe/trunk/test/Driver/fuchsia.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fuchsia.c?rev=322922=322921=322922=diff
==
--- cfe/trunk/test/Driver/fuchsia.c (original)
+++ cfe/trunk/test/Driver/fuchsia.c Thu Jan 18 20:08:06 2018
@@ -81,18 +81,33 @@
 // CHECK-ASAN-SHARED-NOT: "{{.*[/\\]}}libclang_rt.asan-preinit-x86_64.a"
 
 // RUN: %clang %s -### --target=x86_64-fuchsia \
+// RUN: -fsanitize=fuzzer 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-FUZZER-X86
+// CHECK-FUZZER-X86: "-fsanitize=fuzzer,fuzzer-no-link"
+// CHECK-FUZZER-X86: "{{.*[/\\]}}libclang_rt.fuzzer-x86_64.a"
+
+// RUN: %clang %s -### --target=aarch64-fuchsia \
+// RUN: -fsanitize=fuzzer 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-FUZZER-AARCH64
+// CHECK-FUZZER-AARCH64: "-fsanitize=fuzzer,fuzzer-no-link"
+// CHECK-FUZZER-AARCH64: "{{.*[/\\]}}libclang_rt.fuzzer-aarch64.a"
+
+// RUN: %clang %s -### --target=x86_64-fuchsia \
 // RUN: -fsanitize=scudo 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-X86
 // CHECK-SCUDO-X86: "-fsanitize=scudo"
 // CHECK-SCUDO-X86: "-pie"
+// CHECK-SCUDO-X86: "{{.*[/\\]}}libclang_rt.scudo-x86_64.so"
 
 // RUN: %clang %s -### --target=aarch64-fuchsia \
 // RUN: -fsanitize=scudo 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-AARCH64
 // CHECK-SCUDO-AARCH64: "-fsanitize=scudo"
 // CHECK-SCUDO-AARCH64: "-pie"
+// CHECK-SCUDO-AARCH64: "{{.*[/\\]}}libclang_rt.scudo-aarch64.so"
 
 // RUN: %clang %s -### --target=x86_64-fuchsia \
 // RUN: -fsanitize=scudo -fPIC -shared 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-SHARED
 // CHECK-SCUDO-SHARED: "-fsanitize=scudo"
+// CHECK-SCUDO-SHARED: "{{.*[/\\]}}libclang_rt.scudo-x86_64.so"


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


[PATCH] D42283: [Fuchsia] Tests for the Fuzzer support in Fuchsia driver

2018-01-18 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
phosek added reviewers: jakehehrlich, mcgrathr, aarongreen.
Herald added subscribers: cfe-commits, cryptoad.

This adds driver tests for the Fuzzer support.


Repository:
  rC Clang

https://reviews.llvm.org/D42283

Files:
  test/Driver/fuchsia.c


Index: test/Driver/fuchsia.c
===
--- test/Driver/fuchsia.c
+++ test/Driver/fuchsia.c
@@ -80,19 +80,34 @@
 // CHECK-ASAN-SHARED: "{{.*[/\\]}}libclang_rt.asan-x86_64.so"
 // CHECK-ASAN-SHARED-NOT: "{{.*[/\\]}}libclang_rt.asan-preinit-x86_64.a"
 
+// RUN: %clang %s -### --target=x86_64-fuchsia \
+// RUN: -fsanitize=fuzzer 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-FUZZER-X86
+// CHECK-FUZZER-X86: "-fsanitize=fuzzer,fuzzer-no-link"
+// CHECK-FUZZER-X86: "{{.*[/\\]}}libclang_rt.fuzzer-x86_64.a"
+
+// RUN: %clang %s -### --target=aarch64-fuchsia \
+// RUN: -fsanitize=fuzzer 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-FUZZER-AARCH64
+// CHECK-FUZZER-AARCH64: "-fsanitize=fuzzer,fuzzer-no-link"
+// CHECK-FUZZER-AARCH64: "{{.*[/\\]}}libclang_rt.fuzzer-aarch64.a"
+
 // RUN: %clang %s -### --target=x86_64-fuchsia \
 // RUN: -fsanitize=scudo 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-X86
 // CHECK-SCUDO-X86: "-fsanitize=scudo"
 // CHECK-SCUDO-X86: "-pie"
+// CHECK-SCUDO-X86: "{{.*[/\\]}}libclang_rt.scudo-x86_64.so"
 
 // RUN: %clang %s -### --target=aarch64-fuchsia \
 // RUN: -fsanitize=scudo 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-AARCH64
 // CHECK-SCUDO-AARCH64: "-fsanitize=scudo"
 // CHECK-SCUDO-AARCH64: "-pie"
+// CHECK-SCUDO-AARCH64: "{{.*[/\\]}}libclang_rt.scudo-aarch64.so"
 
 // RUN: %clang %s -### --target=x86_64-fuchsia \
 // RUN: -fsanitize=scudo -fPIC -shared 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-SHARED
 // CHECK-SCUDO-SHARED: "-fsanitize=scudo"
+// CHECK-SCUDO-SHARED: "{{.*[/\\]}}libclang_rt.scudo-x86_64.so"


Index: test/Driver/fuchsia.c
===
--- test/Driver/fuchsia.c
+++ test/Driver/fuchsia.c
@@ -80,19 +80,34 @@
 // CHECK-ASAN-SHARED: "{{.*[/\\]}}libclang_rt.asan-x86_64.so"
 // CHECK-ASAN-SHARED-NOT: "{{.*[/\\]}}libclang_rt.asan-preinit-x86_64.a"
 
+// RUN: %clang %s -### --target=x86_64-fuchsia \
+// RUN: -fsanitize=fuzzer 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-FUZZER-X86
+// CHECK-FUZZER-X86: "-fsanitize=fuzzer,fuzzer-no-link"
+// CHECK-FUZZER-X86: "{{.*[/\\]}}libclang_rt.fuzzer-x86_64.a"
+
+// RUN: %clang %s -### --target=aarch64-fuchsia \
+// RUN: -fsanitize=fuzzer 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-FUZZER-AARCH64
+// CHECK-FUZZER-AARCH64: "-fsanitize=fuzzer,fuzzer-no-link"
+// CHECK-FUZZER-AARCH64: "{{.*[/\\]}}libclang_rt.fuzzer-aarch64.a"
+
 // RUN: %clang %s -### --target=x86_64-fuchsia \
 // RUN: -fsanitize=scudo 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-X86
 // CHECK-SCUDO-X86: "-fsanitize=scudo"
 // CHECK-SCUDO-X86: "-pie"
+// CHECK-SCUDO-X86: "{{.*[/\\]}}libclang_rt.scudo-x86_64.so"
 
 // RUN: %clang %s -### --target=aarch64-fuchsia \
 // RUN: -fsanitize=scudo 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-AARCH64
 // CHECK-SCUDO-AARCH64: "-fsanitize=scudo"
 // CHECK-SCUDO-AARCH64: "-pie"
+// CHECK-SCUDO-AARCH64: "{{.*[/\\]}}libclang_rt.scudo-aarch64.so"
 
 // RUN: %clang %s -### --target=x86_64-fuchsia \
 // RUN: -fsanitize=scudo -fPIC -shared 2>&1 \
 // RUN: | FileCheck %s -check-prefix=CHECK-SCUDO-SHARED
 // CHECK-SCUDO-SHARED: "-fsanitize=scudo"
+// CHECK-SCUDO-SHARED: "{{.*[/\\]}}libclang_rt.scudo-x86_64.so"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r322918 - [Refactor] Use enum instead of magic number in handleX86ForceAlignArgPointerAttr, NFC

2018-01-18 Thread Hongbin Zheng via cfe-commits
Author: ether
Date: Thu Jan 18 19:07:00 2018
New Revision: 322918

URL: http://llvm.org/viewvc/llvm-project?rev=322918=rev
Log:
[Refactor] Use enum instead of magic number in 
handleX86ForceAlignArgPointerAttr, NFC

Differential revision: https://reviews.llvm.org/D42227

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

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=322918=322917=322918=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Jan 18 19:07:00 2018
@@ -5554,7 +5554,7 @@ static void handleX86ForceAlignArgPointe
   // Attribute can only be applied to function types.
   if (!isa(D)) {
 S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
-  << Attr.getName() << /* function */0;
+  << Attr.getName() << ExpectedFunction;
 return;
   }
 


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


[libcxx] r322920 - Wrote my own version of is_permutation; that was dominating the timings

2018-01-18 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Thu Jan 18 19:17:45 2018
New Revision: 322920

URL: http://llvm.org/viewvc/llvm-project?rev=322920=rev
Log:
Wrote my own version of is_permutation; that was dominating the timings

Modified:
libcxx/trunk/fuzzing/fuzzing.cpp

Modified: libcxx/trunk/fuzzing/fuzzing.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/fuzzing/fuzzing.cpp?rev=322920=322919=322920=diff
==
--- libcxx/trunk/fuzzing/fuzzing.cpp (original)
+++ libcxx/trunk/fuzzing/fuzzing.cpp Thu Jan 18 19:17:45 2018
@@ -105,6 +105,60 @@ struct is_even
 
 typedef std::vector Vec;
 typedef std::vector StableVec;
+typedef StableVec::const_iterator SVIter;
+
+// Cheap version of is_permutation
+// Builds a set of buckets for each of the key values.
+// Sums all the payloads.
+// Not 100% perfect, but _way_ faster
+bool is_permutation(SVIter first1, SVIter last1, SVIter first2)
+{
+   size_t xBuckets[256]  = {0};
+   size_t xPayloads[256] = {0};
+   size_t yBuckets[256]  = {0};
+   size_t yPayloads[256] = {0};
+   
+   for (; first1 != last1; ++first1, ++first2)
+   {
+   xBuckets [first1->key]++;
+   xPayloads[first1->key] += first1->payload;
+
+   yBuckets [first2->key]++;
+   yPayloads[first2->key] += first2->payload;
+   }
+   
+   for (size_t i = 0; i < 256; ++i)
+   {
+   if (xBuckets[i]  != yBuckets[i])
+   return false;
+   if (xPayloads[i] != yPayloads[i])
+   return false;
+   }
+
+   return true;
+}
+
+template 
+bool is_permutation(Iter1 first1, Iter1 last1, Iter2 first2)
+{
+   static_assert((std::is_same::value_type, uint8_t>::value), "");
+   static_assert((std::is_same::value_type, uint8_t>::value), "");
+   
+   size_t xBuckets[256]  = {0};
+   size_t yBuckets[256]  = {0};
+   
+   for (; first1 != last1; ++first1, ++first2)
+   {
+   xBuckets [*first1]++;
+   yBuckets [*first2]++;
+   }
+   
+   for (size_t i = 0; i < 256; ++i)
+   if (xBuckets[i]  != yBuckets[i])
+   return false;
+
+   return true;
+}
 
 // == sort ==
 int sort(const uint8_t *data, size_t size)
@@ -113,7 +167,7 @@ int sort(const uint8_t *data, size_t siz
std::sort(working.begin(), working.end());
 
if (!std::is_sorted(working.begin(), working.end())) return 1;
-   if (!std::is_permutation(data, data + size, working.begin())) return 99;
+   if (!fuzzing::is_permutation(data, data + size, working.cbegin())) 
return 99;
return 0;
 }
 
@@ -135,7 +189,7 @@ int stable_sort(const uint8_t *data, siz
if (!std::is_sorted(range.first, range.second, total_less())) 
return 2; 
iter = range.second;
}
-   if (!std::is_permutation(input.begin(), input.end(), working.begin())) 
return 99;
+   if (!fuzzing::is_permutation(input.cbegin(), input.cend(), 
working.cbegin())) return 99;
return 0;
 }
 
@@ -147,7 +201,7 @@ int partition(const uint8_t *data, size_
 
if (!std::all_of (working.begin(), iter, is_even())) return 1;
if (!std::none_of(iter,   working.end(), is_even())) return 2;
-   if (!std::is_permutation(data, data + size, working.begin())) return 99;
+   if (!fuzzing::is_permutation(data, data + size, working.cbegin())) 
return 99;
return 0;
 }
 
@@ -190,7 +244,7 @@ int stable_partition (const uint8_t *dat
if (!std::none_of(iter,   working.end(), is_even())) 
return 2;
if (!std::is_sorted(working.begin(), iter, payload_less()))   return 3;
if (!std::is_sorted(iter,   working.end(), payload_less()))   return 4;
-   if (!std::is_permutation(input.begin(), input.end(), working.begin())) 
return 99;
+   if (!fuzzing::is_permutation(input.cbegin(), input.cend(), 
working.cbegin())) return 99;
return 0;
 }
 
@@ -216,7 +270,7 @@ int nth_element (const uint8_t *data, si
return 1;
if (!std::all_of(partition_iter, working.end(),   [=](uint8_t 
v) { return v >= nth; }))
return 2;
-   if (!std::is_permutation(data + 1, data + size, 
working.begin())) return 99;
+   if (!fuzzing::is_permutation(data + 1, data + size, 
working.cbegin())) return 99;
}
 
return 0;
@@ -241,7 +295,7 @@ int partial_sort (const uint8_t *data, s
return 2;   
}
if (!std::is_sorted(working.begin(), sort_iter)) return 3;
-   if (!std::is_permutation(data + 1, data + size, working.begin())) 
return 99;
+   if (!fuzzing::is_permutation(data + 1, data + size, working.cbegin())) 
return 99;
 
return 0;
 }
@@ -440,7 +494,7 @@ int make_heap (const uint8_t *data, size

[PATCH] D42227: [Refactor] Use enum instead of magic number in handleX86ForceAlignArgPointerAttr, NFC

2018-01-18 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322918: [Refactor] Use enum instead of magic number in… 
(authored by ether, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D42227

Files:
  lib/Sema/SemaDeclAttr.cpp


Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -5554,7 +5554,7 @@
   // Attribute can only be applied to function types.
   if (!isa(D)) {
 S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
-  << Attr.getName() << /* function */0;
+  << Attr.getName() << ExpectedFunction;
 return;
   }
 


Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -5554,7 +5554,7 @@
   // Attribute can only be applied to function types.
   if (!isa(D)) {
 S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
-  << Attr.getName() << /* function */0;
+  << Attr.getName() << ExpectedFunction;
 return;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42043: c-index: CXString: fix MSAN read-past-end bug

2018-01-18 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

Mind rebasing this when you have a chance?


Repository:
  rC Clang

https://reviews.llvm.org/D42043



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


[PATCH] D42259: c-index-test: small fix to CXString handling and disposal

2018-01-18 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

LGTM, for the record


Repository:
  rC Clang

https://reviews.llvm.org/D42259



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


[PATCH] D42275: [Fuchsia] Enable Fuzzer as a supported sanitizer on Fuchsia

2018-01-18 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322916: [Fuchsia] Enable Fuzzer as a supported sanitizer on 
Fuchsia (authored by phosek, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D42275

Files:
  lib/Driver/ToolChains/Fuchsia.cpp


Index: lib/Driver/ToolChains/Fuchsia.cpp
===
--- lib/Driver/ToolChains/Fuchsia.cpp
+++ lib/Driver/ToolChains/Fuchsia.cpp
@@ -278,8 +278,9 @@
 
 SanitizerMask Fuchsia::getSupportedSanitizers() const {
   SanitizerMask Res = ToolChain::getSupportedSanitizers();
-  Res |= SanitizerKind::SafeStack;
   Res |= SanitizerKind::Address;
+  Res |= SanitizerKind::Fuzzer;
+  Res |= SanitizerKind::SafeStack;
   Res |= SanitizerKind::Scudo;
   return Res;
 }


Index: lib/Driver/ToolChains/Fuchsia.cpp
===
--- lib/Driver/ToolChains/Fuchsia.cpp
+++ lib/Driver/ToolChains/Fuchsia.cpp
@@ -278,8 +278,9 @@
 
 SanitizerMask Fuchsia::getSupportedSanitizers() const {
   SanitizerMask Res = ToolChain::getSupportedSanitizers();
-  Res |= SanitizerKind::SafeStack;
   Res |= SanitizerKind::Address;
+  Res |= SanitizerKind::Fuzzer;
+  Res |= SanitizerKind::SafeStack;
   Res |= SanitizerKind::Scudo;
   return Res;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r322916 - [Fuchsia] Enable Fuzzer as a supported sanitizer on Fuchsia

2018-01-18 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Thu Jan 18 17:58:26 2018
New Revision: 322916

URL: http://llvm.org/viewvc/llvm-project?rev=322916=rev
Log:
[Fuchsia] Enable Fuzzer as a supported sanitizer on Fuchsia

libFuzzer has been ported to Fuchsia so enable it in the driver.

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

Modified:
cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp?rev=322916=322915=322916=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp Thu Jan 18 17:58:26 2018
@@ -278,8 +278,9 @@ void Fuchsia::AddCXXStdlibLibArgs(const
 
 SanitizerMask Fuchsia::getSupportedSanitizers() const {
   SanitizerMask Res = ToolChain::getSupportedSanitizers();
-  Res |= SanitizerKind::SafeStack;
   Res |= SanitizerKind::Address;
+  Res |= SanitizerKind::Fuzzer;
+  Res |= SanitizerKind::SafeStack;
   Res |= SanitizerKind::Scudo;
   return Res;
 }


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


[PATCH] D42276: [Driver] Add an -fexperimental-isel driver option to enable/disable GlobalISel

2018-01-18 Thread Amara Emerson via Phabricator via cfe-commits
aemerson updated this revision to Diff 130530.

Repository:
  rC Clang

https://reviews.llvm.org/D42276

Files:
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/Clang.cpp
  test/Driver/global-isel.c


Index: test/Driver/global-isel.c
===
--- /dev/null
+++ test/Driver/global-isel.c
@@ -0,0 +1,5 @@
+// RUN: %clang -fexperimental-isel -S -### %s 2>&1 | FileCheck 
-check-prefix=ENABLED %s
+// RUN: %clang -fno-experimental-isel -S -### %s 2>&1 | FileCheck 
-check-prefix=DISABLED %s
+
+// ENABLED: "-mllvm" "-global-isel=1"
+// DISABLED: "-mllvm" "-global-isel=0"
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -4690,6 +4690,15 @@
 CmdArgs.push_back("-fwhole-program-vtables");
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_fexperimental_isel,
+   options::OPT_fno_experimental_isel)) {
+CmdArgs.push_back("-mllvm");
+if (A->getOption().matches(options::OPT_fexperimental_isel))
+  CmdArgs.push_back("-global-isel=1");
+else
+  CmdArgs.push_back("-global-isel=0");
+  }
+
   // Finally add the compile command to the compilation.
   if (Args.hasArg(options::OPT__SLASH_fallback) &&
   Output.getType() == types::TY_Object &&
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1033,6 +1033,8 @@
 def finline_hint_functions: Flag<["-"], "finline-hint-functions">, 
Group, Flags<[CC1Option]>,
   HelpText<"Inline functions which are (explicitly or implicitly) marked 
inline">;
 def finline : Flag<["-"], "finline">, Group;
+def fexperimental_isel : Flag<["-"], "fexperimental-isel">, 
Group,
+  HelpText<"Enables the experimental global instruction selector">;
 def fexperimental_new_pass_manager : Flag<["-"], 
"fexperimental-new-pass-manager">,
   Group, Flags<[CC1Option]>,
   HelpText<"Enables an experimental new pass manager in LLVM.">;
@@ -1244,6 +1246,8 @@
 def fno_gnu_keywords : Flag<["-"], "fno-gnu-keywords">, Group, 
Flags<[CC1Option]>;
 def fno_inline_functions : Flag<["-"], "fno-inline-functions">, 
Group, Flags<[CC1Option]>;
 def fno_inline : Flag<["-"], "fno-inline">, Group, 
Flags<[CC1Option]>;
+def fno_experimental_isel : Flag<["-"], "fno-experimental-isel">, 
Group,
+  HelpText<"Disables the experimental global instruction selector">;
 def fno_experimental_new_pass_manager : Flag<["-"], 
"fno-experimental-new-pass-manager">,
   Group, Flags<[CC1Option]>,
   HelpText<"Disables an experimental new pass manager in LLVM.">;


Index: test/Driver/global-isel.c
===
--- /dev/null
+++ test/Driver/global-isel.c
@@ -0,0 +1,5 @@
+// RUN: %clang -fexperimental-isel -S -### %s 2>&1 | FileCheck -check-prefix=ENABLED %s
+// RUN: %clang -fno-experimental-isel -S -### %s 2>&1 | FileCheck -check-prefix=DISABLED %s
+
+// ENABLED: "-mllvm" "-global-isel=1"
+// DISABLED: "-mllvm" "-global-isel=0"
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -4690,6 +4690,15 @@
 CmdArgs.push_back("-fwhole-program-vtables");
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_fexperimental_isel,
+   options::OPT_fno_experimental_isel)) {
+CmdArgs.push_back("-mllvm");
+if (A->getOption().matches(options::OPT_fexperimental_isel))
+  CmdArgs.push_back("-global-isel=1");
+else
+  CmdArgs.push_back("-global-isel=0");
+  }
+
   // Finally add the compile command to the compilation.
   if (Args.hasArg(options::OPT__SLASH_fallback) &&
   Output.getType() == types::TY_Object &&
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1033,6 +1033,8 @@
 def finline_hint_functions: Flag<["-"], "finline-hint-functions">, Group, Flags<[CC1Option]>,
   HelpText<"Inline functions which are (explicitly or implicitly) marked inline">;
 def finline : Flag<["-"], "finline">, Group;
+def fexperimental_isel : Flag<["-"], "fexperimental-isel">, Group,
+  HelpText<"Enables the experimental global instruction selector">;
 def fexperimental_new_pass_manager : Flag<["-"], "fexperimental-new-pass-manager">,
   Group, Flags<[CC1Option]>,
   HelpText<"Enables an experimental new pass manager in LLVM.">;
@@ -1244,6 +1246,8 @@
 def fno_gnu_keywords : Flag<["-"], "fno-gnu-keywords">, Group, Flags<[CC1Option]>;
 def fno_inline_functions : Flag<["-"], "fno-inline-functions">, Group, Flags<[CC1Option]>;
 def fno_inline : Flag<["-"], "fno-inline">, Group, Flags<[CC1Option]>;
+def fno_experimental_isel : Flag<["-"], 

[PATCH] D42276: [Driver] Add an -fexperimental-isel driver option to enable/disable GlobalISel

2018-01-18 Thread Amara Emerson via Phabricator via cfe-commits
aemerson created this revision.
aemerson added reviewers: qcolombet, echristo.
Herald added subscribers: kristof.beyls, rovka.

Add an -fexperimental-isel driver option to enable/disable GlobalISel.

This is a more user friendly way of enabling GlobalISel instead of doing -mllvm 
-global-isel.


Repository:
  rC Clang

https://reviews.llvm.org/D42276

Files:
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/Clang.cpp
  test/Driver/global-isel.c


Index: test/Driver/global-isel.c
===
--- /dev/null
+++ test/Driver/global-isel.c
@@ -0,0 +1,5 @@
+// RUN: %clang -fexperimental-isel -S -### %s 2>&1 | FileCheck 
-check-prefix=ENABLED %s
+// RUN: %clang -fno-experimental-isel -S -### %s 2>&1 | FileCheck 
-check-prefix=DISABLED %s
+
+// ENABLED: "-mllvm" "-global-isel=1"
+// DISABLED: "-mllvm" "-global-isel=0"
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -4690,6 +4690,15 @@
 CmdArgs.push_back("-fwhole-program-vtables");
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_fexperimental_isel,
+   options::OPT_fno_experimental_isel)) {
+CmdArgs.push_back("-mllvm");
+if (A->getOption().matches(options::OPT_fexperimental_isel))
+  CmdArgs.push_back("-global-isel=1");
+else
+  CmdArgs.push_back("-global-isel=0");
+  }
+
   // Finally add the compile command to the compilation.
   if (Args.hasArg(options::OPT__SLASH_fallback) &&
   Output.getType() == types::TY_Object &&
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1033,6 +1033,9 @@
 def finline_hint_functions: Flag<["-"], "finline-hint-functions">, 
Group, Flags<[CC1Option]>,
   HelpText<"Inline functions which are (explicitly or implicitly) marked 
inline">;
 def finline : Flag<["-"], "finline">, Group;
+def fexperimental_isel : Flag<["-"], "fexperimental-isel">,
+  Group, Flags<[CC1Option]>,
+  HelpText<"Enables the experimental global instruction selector">;
 def fexperimental_new_pass_manager : Flag<["-"], 
"fexperimental-new-pass-manager">,
   Group, Flags<[CC1Option]>,
   HelpText<"Enables an experimental new pass manager in LLVM.">;
@@ -1244,6 +1247,9 @@
 def fno_gnu_keywords : Flag<["-"], "fno-gnu-keywords">, Group, 
Flags<[CC1Option]>;
 def fno_inline_functions : Flag<["-"], "fno-inline-functions">, 
Group, Flags<[CC1Option]>;
 def fno_inline : Flag<["-"], "fno-inline">, Group, 
Flags<[CC1Option]>;
+def fno_experimental_isel : Flag<["-"], "fno-experimental-isel">,
+  Group, Flags<[CC1Option]>,
+  HelpText<"Disables the experimental global instruction selector">;
 def fno_experimental_new_pass_manager : Flag<["-"], 
"fno-experimental-new-pass-manager">,
   Group, Flags<[CC1Option]>,
   HelpText<"Disables an experimental new pass manager in LLVM.">;


Index: test/Driver/global-isel.c
===
--- /dev/null
+++ test/Driver/global-isel.c
@@ -0,0 +1,5 @@
+// RUN: %clang -fexperimental-isel -S -### %s 2>&1 | FileCheck -check-prefix=ENABLED %s
+// RUN: %clang -fno-experimental-isel -S -### %s 2>&1 | FileCheck -check-prefix=DISABLED %s
+
+// ENABLED: "-mllvm" "-global-isel=1"
+// DISABLED: "-mllvm" "-global-isel=0"
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -4690,6 +4690,15 @@
 CmdArgs.push_back("-fwhole-program-vtables");
   }
 
+  if (Arg *A = Args.getLastArg(options::OPT_fexperimental_isel,
+   options::OPT_fno_experimental_isel)) {
+CmdArgs.push_back("-mllvm");
+if (A->getOption().matches(options::OPT_fexperimental_isel))
+  CmdArgs.push_back("-global-isel=1");
+else
+  CmdArgs.push_back("-global-isel=0");
+  }
+
   // Finally add the compile command to the compilation.
   if (Args.hasArg(options::OPT__SLASH_fallback) &&
   Output.getType() == types::TY_Object &&
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1033,6 +1033,9 @@
 def finline_hint_functions: Flag<["-"], "finline-hint-functions">, Group, Flags<[CC1Option]>,
   HelpText<"Inline functions which are (explicitly or implicitly) marked inline">;
 def finline : Flag<["-"], "finline">, Group;
+def fexperimental_isel : Flag<["-"], "fexperimental-isel">,
+  Group, Flags<[CC1Option]>,
+  HelpText<"Enables the experimental global instruction selector">;
 def fexperimental_new_pass_manager : Flag<["-"], "fexperimental-new-pass-manager">,
   Group, Flags<[CC1Option]>,
   HelpText<"Enables an experimental new pass manager in LLVM.">;
@@ 

[PATCH] D42275: [Fuchsia] Enable Fuzzer as a supported sanitizer on Fuchsia

2018-01-18 Thread Jake Ehrlich via Phabricator via cfe-commits
jakehehrlich accepted this revision.
jakehehrlich added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rC Clang

https://reviews.llvm.org/D42275



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


[PATCH] D42275: [Fuchsia] Enable Fuzzer as a supported sanitizer on Fuchsia

2018-01-18 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
phosek added reviewers: aarongreen, mcgrathr, jakehehrlich, kcc.
Herald added a subscriber: cfe-commits.

libFuzzer has been ported to Fuchsia so enable it in the driver.


Repository:
  rC Clang

https://reviews.llvm.org/D42275

Files:
  lib/Driver/ToolChains/Fuchsia.cpp


Index: lib/Driver/ToolChains/Fuchsia.cpp
===
--- lib/Driver/ToolChains/Fuchsia.cpp
+++ lib/Driver/ToolChains/Fuchsia.cpp
@@ -278,8 +278,9 @@
 
 SanitizerMask Fuchsia::getSupportedSanitizers() const {
   SanitizerMask Res = ToolChain::getSupportedSanitizers();
-  Res |= SanitizerKind::SafeStack;
   Res |= SanitizerKind::Address;
+  Res |= SanitizerKind::Fuzzer;
+  Res |= SanitizerKind::SafeStack;
   Res |= SanitizerKind::Scudo;
   return Res;
 }


Index: lib/Driver/ToolChains/Fuchsia.cpp
===
--- lib/Driver/ToolChains/Fuchsia.cpp
+++ lib/Driver/ToolChains/Fuchsia.cpp
@@ -278,8 +278,9 @@
 
 SanitizerMask Fuchsia::getSupportedSanitizers() const {
   SanitizerMask Res = ToolChain::getSupportedSanitizers();
-  Res |= SanitizerKind::SafeStack;
   Res |= SanitizerKind::Address;
+  Res |= SanitizerKind::Fuzzer;
+  Res |= SanitizerKind::SafeStack;
   Res |= SanitizerKind::Scudo;
   return Res;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42248: Always allow "#pragma region".

2018-01-18 Thread Matt Davis via Phabricator via cfe-commits
mattd updated this revision to Diff 130523.
mattd retitled this revision from "[LangOpts] Add a LangOpt to represent 
"#pragma region" support." to "Always allow "#pragma region".".
mattd edited the summary of this revision.
mattd added a comment.

I'm certainly fine with always allowing this pragma.   I can see it useful for 
other editors that might wish to utilize the hint.


https://reviews.llvm.org/D42248

Files:
  lib/Lex/Pragma.cpp
  test/Frontend/region-pragmas.c


Index: test/Frontend/region-pragmas.c
===
--- test/Frontend/region-pragmas.c
+++ test/Frontend/region-pragmas.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -Wall -verify %s
+// expected-no-diagnostics
+
+#pragma region foo
+#pragma endregion foo
Index: lib/Lex/Pragma.cpp
===
--- lib/Lex/Pragma.cpp
+++ lib/Lex/Pragma.cpp
@@ -1776,13 +1776,15 @@
   ModuleHandler->AddPragma(new PragmaModuleEndHandler());
   ModuleHandler->AddPragma(new PragmaModuleBuildHandler());
   ModuleHandler->AddPragma(new PragmaModuleLoadHandler());
+
+  // Add region pragmas.
+  AddPragmaHandler(new PragmaRegionHandler("region"));
+  AddPragmaHandler(new PragmaRegionHandler("endregion"));
 
   // MS extensions.
   if (LangOpts.MicrosoftExt) {
 AddPragmaHandler(new PragmaWarningHandler());
 AddPragmaHandler(new PragmaIncludeAliasHandler());
-AddPragmaHandler(new PragmaRegionHandler("region"));
-AddPragmaHandler(new PragmaRegionHandler("endregion"));
   }
 
   // Pragmas added by plugins


Index: test/Frontend/region-pragmas.c
===
--- test/Frontend/region-pragmas.c
+++ test/Frontend/region-pragmas.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -Wall -verify %s
+// expected-no-diagnostics
+
+#pragma region foo
+#pragma endregion foo
Index: lib/Lex/Pragma.cpp
===
--- lib/Lex/Pragma.cpp
+++ lib/Lex/Pragma.cpp
@@ -1776,13 +1776,15 @@
   ModuleHandler->AddPragma(new PragmaModuleEndHandler());
   ModuleHandler->AddPragma(new PragmaModuleBuildHandler());
   ModuleHandler->AddPragma(new PragmaModuleLoadHandler());
+
+  // Add region pragmas.
+  AddPragmaHandler(new PragmaRegionHandler("region"));
+  AddPragmaHandler(new PragmaRegionHandler("endregion"));
 
   // MS extensions.
   if (LangOpts.MicrosoftExt) {
 AddPragmaHandler(new PragmaWarningHandler());
 AddPragmaHandler(new PragmaIncludeAliasHandler());
-AddPragmaHandler(new PragmaRegionHandler("region"));
-AddPragmaHandler(new PragmaRegionHandler("endregion"));
   }
 
   // Pragmas added by plugins
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42273: Add hasTrailingReturn AST matcher

2018-01-18 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett created this revision.
juliehockett added a reviewer: aaron.ballman.
Herald added a subscriber: klimek.

Adds AST matcher for a FunctionDecl that has a trailing return type.


https://reviews.llvm.org/D42273

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
@@ -2112,5 +2112,14 @@
   EXPECT_TRUE(notMatches("enum X {};", enumDecl(isScoped(;
 }
 
+TEST(HasTrailingReturn, MatchesTrailingReturn) {
+  EXPECT_TRUE(matches("auto Y() -> int {};",
+  functionDecl(hasTrailingReturn(;
+  EXPECT_TRUE(matches(
+  "auto lambda2 = [](double x, double y) -> double {return x + y;};",
+  functionDecl(hasTrailingReturn(;
+  EXPECT_TRUE(notMatches("int X() {};", functionDecl(hasTrailingReturn(;
+}
+
 } // namespace ast_matchers
 } // namespace clang
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -296,6 +296,7 @@
   REGISTER_MATCHER(hasTemplateArgument);
   REGISTER_MATCHER(hasThen);
   REGISTER_MATCHER(hasThreadStorageDuration);
+  REGISTER_MATCHER(hasTrailingReturn);
   REGISTER_MATCHER(hasTrueExpression);
   REGISTER_MATCHER(hasTypeLoc);
   REGISTER_MATCHER(hasUnaryOperand);
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -5891,6 +5891,17 @@
   return Node.isScoped();
 }
 
+/// \brief Matches a function declared with a trailing return type.
+///
+/// Example matches Y (matcher = functionDecl(hasTrailingReturn()))
+/// \code
+/// int X() {};
+/// auto Y() -> int {};
+/// \endcode
+AST_MATCHER(FunctionDecl, hasTrailingReturn) {
+  return Node.getType()->castAs()->hasTrailingReturn();
+}
+
 } // namespace ast_matchers
 } // namespace clang
 
Index: docs/LibASTMatchersReference.html
===
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html
@@ -2749,6 +2749,15 @@
 
 
 
+Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDeclhasTrailingReturn
+Matches a 
function declared with a trailing return type.
+
+Example matches Y (matcher = functionDecl(hasTrailingReturn()))
+int X() {};
+auto Y() - int {};
+
+
+
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDeclisConstexpr
 Matches constexpr 
variable and function declarations.
 


Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2112,5 +2112,14 @@
   EXPECT_TRUE(notMatches("enum X {};", enumDecl(isScoped(;
 }
 
+TEST(HasTrailingReturn, MatchesTrailingReturn) {
+  EXPECT_TRUE(matches("auto Y() -> int {};",
+  functionDecl(hasTrailingReturn(;
+  EXPECT_TRUE(matches(
+  "auto lambda2 = [](double x, double y) -> double {return x + y;};",
+  functionDecl(hasTrailingReturn(;
+  EXPECT_TRUE(notMatches("int X() {};", functionDecl(hasTrailingReturn(;
+}
+
 } // namespace ast_matchers
 } // namespace clang
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -296,6 +296,7 @@
   REGISTER_MATCHER(hasTemplateArgument);
   REGISTER_MATCHER(hasThen);
   REGISTER_MATCHER(hasThreadStorageDuration);
+  REGISTER_MATCHER(hasTrailingReturn);
   REGISTER_MATCHER(hasTrueExpression);
   REGISTER_MATCHER(hasTypeLoc);
   REGISTER_MATCHER(hasUnaryOperand);
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -5891,6 +5891,17 @@
   return Node.isScoped();
 }
 
+/// \brief Matches a function declared with a trailing return type.
+///
+/// Example matches Y (matcher = functionDecl(hasTrailingReturn()))
+/// \code
+/// int X() {};
+/// auto Y() -> int {};
+/// \endcode
+AST_MATCHER(FunctionDecl, hasTrailingReturn) {
+  return Node.getType()->castAs()->hasTrailingReturn();
+}
+
 } // namespace ast_matchers
 } // namespace clang
 
Index: docs/LibASTMatchersReference.html
===
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html
@@ 

[PATCH] D41151: [analyzer] Adding LoopContext and improve loop modeling

2018-01-18 Thread Peter Szecsi via Phabricator via cfe-commits
szepet added inline comments.



Comment at: lib/StaticAnalyzer/Core/LoopUnrolling.cpp:28-46
 struct LoopState {
 private:
   enum Kind { Normal, Unrolled } K;
-  const Stmt *LoopStmt;
-  const LocationContext *LCtx;
-  unsigned maxStep;
-  LoopState(Kind InK, const Stmt *S, const LocationContext *L, unsigned N)
-  : K(InK), LoopStmt(S), LCtx(L), maxStep(N) {}
+  unsigned MaxStep;
+  LoopState(Kind InK, unsigned N) : K(InK), MaxStep(N) {}
 
 public:

NoQ wrote:
> Should the whole `LoopState` be reduced to a field(s) in `LoopContext`? It 
> seems to make sense to me, unless we're planning to modify it in the middle 
> of the loop.
I'm not sure about that. I mean, LoopContext is a general thing for all of the 
loops. It can easily happen that we modify the bound in the middle of the loop. 
Another thing what we keep track on if it is unrolled or not which is again 
something that we can decide to change in the middle of an iteration (e.g. it 
splits the state).

Yes, in our case MaxStep is not likely to change since we store loops that have 
a fix bound. (This could change in the future but maybe this is a too bold 
idea.)


https://reviews.llvm.org/D41151



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


[PATCH] D41843: [libcxx] implement where expressions.

2018-01-18 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray added inline comments.



Comment at: libcxx/include/experimental/simd:2330
+  simd<_Tp, _Abi>& __v) noexcept {
+  return where_expression, simd<_Tp, _Abi>>(__m, __v);
+}

style: `return {__m, __v};`?


https://reviews.llvm.org/D41843



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


[PATCH] D41151: [analyzer] Adding LoopContext and improve loop modeling

2018-01-18 Thread Peter Szecsi via Phabricator via cfe-commits
szepet updated this revision to Diff 130516.
szepet marked 2 inline comments as done.
szepet added a comment.

First, sorry for this delayed update, however, I was working on this and 
running this on real projects. I wanted to make sure that this update will be 
complete enough that this patch would not cause any harm (yes, these features 
are hidden behind a flag but anyway) and not crashes on edge cases I haven't 
thought of. The core used the fact that LocationContext only contains 
StackFramce and BlockInvocation and I aimed to eliminate all these code 
snippets (more like rewrite).

> This thing is very similar to https://reviews.llvm.org/D19979. Do we really 
> need to create a separate LoopContext or we can reuse ScopeContext instead?



> I guess LoopContext can be treated as a sub-class of ScopeContext. And i 
> don't mind having ScopeContext be split into small distinct sub-classes. 
> Because we're stuck in corner cases for covering all possible scopes, while 
> we're fine with covering only simple scopes (it's better than nothing) and 
> lacking a scope from time to time.

In this patch I left it as it was, so a separate context. I agree with Aleksei 
that yes, it could be implemented as a ScopeContext and checked if it contains 
a While/Do/For Statement.
On the other hand, I like the idea more, that we split ScopeContext into small 
distinct subclasses which would result in a more manageable code.
However, this would require refactoring on ScopeContext as well, in order to 
make it a great base class (like StmtPoint for ProgramPoint). Then, LoopContext 
would be its only subclass. So, I do not really see the point of doing these 
changes right now. I think in this state (when ScopeContext not used by the 
analyzer as I can see) the LoopContext could live as a separate Context and not 
make any harm. In case when another Context shows up which is similar 
LoopContext (e.g. ScopeContext) I would happily refactor it but right now, I do 
not see the point of this.


https://reviews.llvm.org/D41151

Files:
  include/clang/Analysis/AnalysisDeclContext.h
  include/clang/Analysis/ProgramPoint.h
  include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  include/clang/StaticAnalyzer/Core/PathSensitive/LoopUnrolling.h
  lib/Analysis/AnalysisDeclContext.cpp
  lib/StaticAnalyzer/Core/BugReporter.cpp
  lib/StaticAnalyzer/Core/CallEvent.cpp
  lib/StaticAnalyzer/Core/CoreEngine.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  lib/StaticAnalyzer/Core/LoopUnrolling.cpp
  lib/StaticAnalyzer/Core/PathDiagnostic.cpp
  test/Analysis/loop-unrolling.cpp

Index: test/Analysis/loop-unrolling.cpp
===
--- test/Analysis/loop-unrolling.cpp
+++ test/Analysis/loop-unrolling.cpp
@@ -373,7 +373,6 @@
   return 0;
 }
 
-
 void pr34943() {
   for (int i = 0; i < 6L; ++i) {
 clang_analyzer_numTimesReached(); // expected-warning {{6}}
Index: lib/StaticAnalyzer/Core/PathDiagnostic.cpp
===
--- lib/StaticAnalyzer/Core/PathDiagnostic.cpp
+++ lib/StaticAnalyzer/Core/PathDiagnostic.cpp
@@ -576,12 +576,18 @@
   return PathDiagnosticLocation::createEnd(CallerBody, SM, CallerCtx);
 return PathDiagnosticLocation::create(CallerInfo->getDecl(), SM);
   }
+  case CFGElement::LoopEntrance: {
+const Stmt *LoopStmt = Source.castAs().getLoopStmt();
+return PathDiagnosticLocation(LoopStmt, SM, CallerCtx);
+  }
+  case CFGElement::LoopExit: {
+const Stmt *LoopStmt = Source.castAs().getLoopStmt();
+return PathDiagnosticLocation::createEnd(LoopStmt, SM, CallerCtx);
+  }
   case CFGElement::TemporaryDtor:
   case CFGElement::NewAllocator:
 llvm_unreachable("not yet implemented!");
   case CFGElement::LifetimeEnds:
-  case CFGElement::LoopExit:
-  case CFGElement::LoopEntrance:
 llvm_unreachable("CFGElement kind should not be on callsite!");
   }
 
@@ -742,6 +748,10 @@
 return CEE->getCalleeContext()->getCallSite();
   if (Optional PIPP = P.getAs())
 return PIPP->getInitializer()->getInit();
+  if (Optional LE = P.getAs())
+return LE->getLoopStmt();
+  if (Optional LE = P.getAs())
+return LE->getLoopStmt();
 
   return nullptr;
 }
Index: lib/StaticAnalyzer/Core/LoopUnrolling.cpp
===
--- lib/StaticAnalyzer/Core/LoopUnrolling.cpp
+++ lib/StaticAnalyzer/Core/LoopUnrolling.cpp
@@ -13,11 +13,11 @@
 ///
 //===--===//
 
-#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/LoopUnrolling.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
-#include 

[PATCH] D41844: [libcxx] implement mask reductions

2018-01-18 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray added inline comments.



Comment at: libcxx/include/experimental/simd:1561
 
+template >
+_Tp reduce(const simd<_Tp, _Abi>& __v, _BinaryOp __op = _BinaryOp()) {

Specified in terms of the transparent `plus<>`.


https://reviews.llvm.org/D41844



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


[PATCH] D42272: [X86] Add rdpid command line option and intrinsics.

2018-01-18 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added reviewers: RKSimon, spatel, zvi, AndreiGrischenko.

This patch adds -mrdpid/-mno-rdpid and the rdpid intrinsic. The corresponding 
LLVM commit has already been made.


https://reviews.llvm.org/D42272

Files:
  include/clang/Basic/BuiltinsX86.def
  include/clang/Driver/Options.td
  lib/Basic/Targets/X86.cpp
  lib/Basic/Targets/X86.h
  lib/Headers/immintrin.h
  test/CodeGen/rdpid-builtins.c
  test/Driver/x86-target-features.c
  test/Preprocessor/predefined-arch-macros.c
  test/Preprocessor/x86_target_features.c

Index: test/Preprocessor/x86_target_features.c
===
--- test/Preprocessor/x86_target_features.c
+++ test/Preprocessor/x86_target_features.c
@@ -436,3 +436,6 @@
 // VPCLMULQDQNOPCLMUL-NOT: #define __PCLMUL__ 1
 // VPCLMULQDQNOPCLMUL-NOT: #define __VPCLMULQDQ__ 1
 
+// RUN: %clang -target i386-unknown-unknown -march=atom -mrdpid -x c -E -dM -o - %s | FileCheck -match-full-lines --check-prefix=RDPID %s
+
+// RDPID: #define __RDPID__ 1
Index: test/Preprocessor/predefined-arch-macros.c
===
--- test/Preprocessor/predefined-arch-macros.c
+++ test/Preprocessor/predefined-arch-macros.c
@@ -1086,6 +1086,7 @@
 // CHECK_ICL_M32: #define __PKU__ 1
 // CHECK_ICL_M32: #define __POPCNT__ 1
 // CHECK_ICL_M32: #define __PRFCHW__ 1
+// CHECK_ICL_M32: #define __RDPID__ 1
 // CHECK_ICL_M32: #define __RDRND__ 1
 // CHECK_ICL_M32: #define __RDSEED__ 1
 // CHECK_ICL_M32: #define __RTM__ 1
@@ -1141,6 +1142,7 @@
 // CHECK_ICL_M64: #define __PKU__ 1
 // CHECK_ICL_M64: #define __POPCNT__ 1
 // CHECK_ICL_M64: #define __PRFCHW__ 1
+// CHECK_ICL_M64: #define __RDPID__ 1
 // CHECK_ICL_M64: #define __RDRND__ 1
 // CHECK_ICL_M64: #define __RDSEED__ 1
 // CHECK_ICL_M64: #define __RTM__ 1
Index: test/Driver/x86-target-features.c
===
--- test/Driver/x86-target-features.c
+++ test/Driver/x86-target-features.c
@@ -125,3 +125,7 @@
 // VBMI2: "-target-feature" "+avx512vbmi2"
 // NO-VBMI2: "-target-feature" "-avx512vbmi2"
 
+// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mrdpid %s -### -o %t.o 2>&1 | FileCheck -check-prefix=RDPID %s
+// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-rdpid %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-RDPID %s
+// RDPID: "-target-feature" "+rdpid"
+// NO-RDPID: "-target-feature" "-rdpid"
Index: test/CodeGen/rdpid-builtins.c
===
--- /dev/null
+++ test/CodeGen/rdpid-builtins.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -ffreestanding -triple x86_64-unknown-unknown -target-feature +rdpid -emit-llvm -o - %s | FileCheck %s
+
+
+#include 
+
+unsigned int test_rdpid_u32(void) {
+// CHECK-LABEL: @test_rdpid_u32
+// CHECK: call i32 @llvm.x86.rdpid
+  return _rdpid_u32();
+}
Index: lib/Headers/immintrin.h
===
--- lib/Headers/immintrin.h
+++ lib/Headers/immintrin.h
@@ -247,6 +247,13 @@
 #include 
 #endif
 
+#if !defined(_MSC_VER) || __has_feature(modules) || defined(__RDPID__)
+static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__, __target__("rdpid")))
+_rdpid_u32(void) {
+  return __builtin_ia32_rdpid();
+}
+#endif // __RDPID__
+
 #if !defined(_MSC_VER) || __has_feature(modules) || defined(__RDRND__)
 static __inline__ int __attribute__((__always_inline__, __nodebug__, __target__("rdrnd")))
 _rdrand16_step(unsigned short *__p)
Index: lib/Basic/Targets/X86.h
===
--- lib/Basic/Targets/X86.h
+++ lib/Basic/Targets/X86.h
@@ -96,6 +96,7 @@
   bool HasCLWB = false;
   bool HasMOVBE = false;
   bool HasPREFETCHWT1 = false;
+  bool HasRDPID = false;
 
   /// \brief Enumeration of all of the X86 CPUs supported by Clang.
   ///
Index: lib/Basic/Targets/X86.cpp
===
--- lib/Basic/Targets/X86.cpp
+++ lib/Basic/Targets/X86.cpp
@@ -160,6 +160,7 @@
 setFeatureEnabledImpl(Features, "avx512vnni", true);
 setFeatureEnabledImpl(Features, "avx512vbmi2", true);
 setFeatureEnabledImpl(Features, "avx512vpopcntdq", true);
+setFeatureEnabledImpl(Features, "rdpid", true);
 LLVM_FALLTHROUGH;
   case CK_Cannonlake:
 setFeatureEnabledImpl(Features, "avx512ifma", true);
@@ -784,6 +785,8 @@
   HasPREFETCHWT1 = true;
 } else if (Feature == "+clzero") {
   HasCLZERO = true;
+} else if (Feature == "+rdpid") {
+  HasRDPID = true;
 }
 
 X86SSEEnum Level = llvm::StringSwitch(Feature)
@@ -1125,6 +1128,8 @@
 Builder.defineMacro("__PREFETCHWT1__");
   if (HasCLZERO)
 Builder.defineMacro("__CLZERO__");
+  if (HasRDPID)
+Builder.defineMacro("__RDPID__");
 
   // Each case falls through to the previous one here.
   switch (SSELevel) {
@@ -1253,6 +1258,7 @@
 

r322912 - [X86] Add missing check for RDSEED to ICL, CNL, SKX sections of test/Preprocessor/predefined-arch-macros.c

2018-01-18 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Thu Jan 18 16:28:42 2018
New Revision: 322912

URL: http://llvm.org/viewvc/llvm-project?rev=322912=rev
Log:
[X86] Add missing check for RDSEED to ICL, CNL, SKX sections of 
test/Preprocessor/predefined-arch-macros.c

Modified:
cfe/trunk/test/Preprocessor/predefined-arch-macros.c

Modified: cfe/trunk/test/Preprocessor/predefined-arch-macros.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/predefined-arch-macros.c?rev=322912=322911=322912=diff
==
--- cfe/trunk/test/Preprocessor/predefined-arch-macros.c (original)
+++ cfe/trunk/test/Preprocessor/predefined-arch-macros.c Thu Jan 18 16:28:42 
2018
@@ -890,6 +890,7 @@
 // CHECK_SKX_M32: #define __POPCNT__ 1
 // CHECK_SKX_M32: #define __PRFCHW__ 1
 // CHECK_SKX_M32: #define __RDRND__ 1
+// CHECK_SKX_M32: #define __RDSEED__ 1
 // CHECK_SKX_M32: #define __RTM__ 1
 // CHECK_SKX_M32: #define __SGX__ 1
 // CHECK_SKX_M32: #define __SSE2__ 1
@@ -934,6 +935,7 @@
 // CHECK_SKX_M64: #define __POPCNT__ 1
 // CHECK_SKX_M64: #define __PRFCHW__ 1
 // CHECK_SKX_M64: #define __RDRND__ 1
+// CHECK_SKX_M64: #define __RDSEED__ 1
 // CHECK_SKX_M64: #define __RTM__ 1
 // CHECK_SKX_M64: #define __SGX__ 1
 // CHECK_SKX_M64: #define __SSE2_MATH__ 1
@@ -983,6 +985,7 @@
 // CHECK_CNL_M32: #define __POPCNT__ 1
 // CHECK_CNL_M32: #define __PRFCHW__ 1
 // CHECK_CNL_M32: #define __RDRND__ 1
+// CHECK_CNL_M32: #define __RDSEED__ 1
 // CHECK_CNL_M32: #define __RTM__ 1
 // CHECK_CNL_M32: #define __SGX__ 1
 // CHECK_CNL_M32: #define __SHA__ 1
@@ -1030,6 +1033,7 @@
 // CHECK_CNL_M64: #define __POPCNT__ 1
 // CHECK_CNL_M64: #define __PRFCHW__ 1
 // CHECK_CNL_M64: #define __RDRND__ 1
+// CHECK_CNL_M64: #define __RDSEED__ 1
 // CHECK_CNL_M64: #define __RTM__ 1
 // CHECK_CNL_M64: #define __SGX__ 1
 // CHECK_CNL_M64: #define __SHA__ 1
@@ -1083,6 +1087,7 @@
 // CHECK_ICL_M32: #define __POPCNT__ 1
 // CHECK_ICL_M32: #define __PRFCHW__ 1
 // CHECK_ICL_M32: #define __RDRND__ 1
+// CHECK_ICL_M32: #define __RDSEED__ 1
 // CHECK_ICL_M32: #define __RTM__ 1
 // CHECK_ICL_M32: #define __SGX__ 1
 // CHECK_ICL_M32: #define __SHA__ 1
@@ -1137,6 +1142,7 @@
 // CHECK_ICL_M64: #define __POPCNT__ 1
 // CHECK_ICL_M64: #define __PRFCHW__ 1
 // CHECK_ICL_M64: #define __RDRND__ 1
+// CHECK_ICL_M64: #define __RDSEED__ 1
 // CHECK_ICL_M64: #define __RTM__ 1
 // CHECK_ICL_M64: #define __SGX__ 1
 // CHECK_ICL_M64: #define __SHA__ 1


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


[PATCH] D41150: [CFG] Adding new CFGStmt LoopEntrance for the StaticAnalyzer

2018-01-18 Thread Peter Szecsi via Phabricator via cfe-commits
szepet updated this revision to Diff 130505.
szepet added a comment.

> I essentially have one question at a glance - for loop counter variables, 
> don't we want LoopEntrance be before the initialization?

I guess this would just make too much sense. Done that.

Additionally, handle the cases when we just hop to the body of the loop via 
goto stmt.
Now the patches can be applied without any conflict (added the loopexit patch 
as a dependency).


https://reviews.llvm.org/D41150

Files:
  include/clang/Analysis/CFG.h
  lib/Analysis/CFG.cpp
  lib/StaticAnalyzer/Core/PathDiagnostic.cpp
  test/Analysis/loopexit-cfg-output.cpp

Index: test/Analysis/loopexit-cfg-output.cpp
===
--- test/Analysis/loopexit-cfg-output.cpp
+++ test/Analysis/loopexit-cfg-output.cpp
@@ -32,8 +32,9 @@
 // CHECK-NEXT:   Succs (2): B3 B1
 
 // CHECK:   [B5]
-// CHECK-NEXT:   1: 0
-// CHECK-NEXT:   2: int i = 0;
+// CHECK-NEXT:   1: ForStmt (LoopEntrance)
+// CHECK-NEXT:   2: 0
+// CHECK-NEXT:   3: int i = 0;
 // CHECK-NEXT:   Preds (1): B6
 // CHECK-NEXT:   Succs (1): B4
 
@@ -46,8 +47,8 @@
   return;
 }
 
-// CHECK:   [B4 (ENTRY)]
-// CHECK-NEXT:   Succs (1): B3
+// CHECK:   [B5 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B4
 
 // CHECK:   [B1]
 // CHECK-NEXT:   1: ForStmt (LoopExit)
@@ -62,15 +63,20 @@
 // CHECK-NEXT:   Preds (2): B2 B4
 // CHECK-NEXT:   Succs (2): B2 NULL
 
+// CHECK:   [B4]
+// CHECK-NEXT:   1: ForStmt (LoopEntrance)
+// CHECK-NEXT:   Preds (1): B5
+// CHECK-NEXT:   Succs (1): B3
+
 // CHECK:   [B0 (EXIT)]
 // CHECK-NEXT:   Preds (1): B1
 void check_forloop2() {
   for (;;)
 ;
 }
 
-// CHECK:   [B5 (ENTRY)]
-// CHECK-NEXT:   Succs (1): B4
+// CHECK:   [B6 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B5
 
 // CHECK:   [B1]
 // CHECK-NEXT:   1: WhileStmt (LoopExit)
@@ -91,6 +97,11 @@
 // CHECK-NEXT:   Preds (2): B2 B5
 // CHECK-NEXT:   Succs (2): B3 NULL
 
+// CHECK:   [B5]
+// CHECK-NEXT:   1: WhileStmt (LoopEntrance)
+// CHECK-NEXT:   Preds (1): B6
+// CHECK-NEXT:   Succs (1): B4
+
 // CHECK:   [B0 (EXIT)]
 // CHECK-NEXT:   Preds (1): B1
 void check_while1() {
@@ -125,6 +136,7 @@
 
 // CHECK:   [B4]
 // CHECK-NEXT:   1: int l;
+// CHECK-NEXT:   2: WhileStmt (LoopEntrance)
 // CHECK-NEXT:   Preds (1): B5
 // CHECK-NEXT:   Succs (1): B3
 
@@ -138,8 +150,8 @@
   return;
 }
 
-// CHECK:   [B4 (ENTRY)]
-// CHECK-NEXT:   Succs (1): B3
+// CHECK:   [B5 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B4
 
 // CHECK:   [B1]
 // CHECK-NEXT:   1: WhileStmt (LoopExit)
@@ -155,16 +167,21 @@
 // CHECK-NEXT:   Preds (2): B2 B4
 // CHECK-NEXT:   Succs (2): NULL B1
 
+// CHECK:   [B4]
+// CHECK-NEXT:   1: WhileStmt (LoopEntrance)
+// CHECK-NEXT:   Preds (1): B5
+// CHECK-NEXT:   Succs (1): B3
+
 // CHECK:   [B0 (EXIT)]
 // CHECK-NEXT:   Preds (1): B1
 void check_while3() {
   while (false) {
 ;
   }
 }
 
-// CHECK:   [B4 (ENTRY)]
-// CHECK-NEXT:   Succs (1): B2
+// CHECK:   [B5 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B4
 
 // CHECK:   [B1]
 // CHECK-NEXT:   1: DoStmt (LoopExit)
@@ -180,6 +197,11 @@
 // CHECK:   [B3]
 // CHECK-NEXT:   Succs (1): B2
 
+// CHECK:   [B4]
+// CHECK-NEXT:   1: DoStmt (LoopEntrance)
+// CHECK-NEXT:   Preds (1): B5
+// CHECK-NEXT:   Succs (1): B2
+
 // CHECK:   [B0 (EXIT)]
 // CHECK-NEXT:   Preds (1): B1
 void check_dowhile1() {
@@ -221,6 +243,7 @@
 // CHECK:   [B5]
 // CHECK-NEXT:   1: 2
 // CHECK-NEXT:   2: int j = 2;
+// CHECK-NEXT:   3: DoStmt (LoopEntrance)
 // CHECK-NEXT:   Preds (1): B6
 // CHECK-NEXT:   Succs (1): B3
 
@@ -274,8 +297,9 @@
 // CHECK-NEXT:   Succs (2): B5 B3
 
 // CHECK:   [B7]
-// CHECK-NEXT:   1: 1
-// CHECK-NEXT:   2: int j = 1;
+// CHECK-NEXT:   1: ForStmt (LoopEntrance)
+// CHECK-NEXT:   2: 1
+// CHECK-NEXT:   3: int j = 1;
 // CHECK-NEXT:   Preds (1): B8
 // CHECK-NEXT:   Succs (1): B6
 
@@ -292,6 +316,7 @@
 // CHECK-NEXT:   1: 40
 // CHECK-NEXT:   2: -[B9.1]
 // CHECK-NEXT:   3: int i = -40;
+// CHECK-NEXT:   4: WhileStmt (LoopEntrance)
 // CHECK-NEXT:   Preds (1): B10
 // CHECK-NEXT:   Succs (1): B8
 
@@ -305,19 +330,19 @@
   }
 }
 
-// CHECK:   [B9 (ENTRY)]
-// CHECK-NEXT:   Succs (1): B8
+// CHECK:   [B10 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B9
 
 // CHECK:   [B1]
 // CHECK-NEXT:   1: ForStmt (LoopExit)
-// CHECK-NEXT:   Preds (1): B7
+// CHECK-NEXT:   Preds (1): B8
 // CHECK-NEXT:   Succs (1): B0
 
 // CHECK:   [B2]
 // CHECK-NEXT:   1: j
 // CHECK-NEXT:   2: [B2.1]++
 // CHECK-NEXT:   Preds (1): B3
-// CHECK-NEXT:   Succs (1): B7
+// CHECK-NEXT:   Succs (1): B8
 
 // CHECK:   [B3]
 // CHECK-NEXT:   1: DoStmt (LoopExit)
@@ -346,22 +371,28 @@
 // CHECK-NEXT:   Succs (1): B5
 
 // CHECK:   [B7]
+// CHECK-NEXT:   1: DoStmt (LoopEntrance)
+// CHECK-NEXT:   Preds (1): B8
+// CHECK-NEXT:   Succs (1): B5
+
+// CHECK:   [B8]
 // CHECK-NEXT:   1: j
-// CHECK-NEXT:   2: [B7.1] (ImplicitCastExpr, LValueToRValue, 

[PATCH] D39398: [CFG][Analyzer] Add LoopExit element to the CFG in more cases

2018-01-18 Thread Peter Szecsi via Phabricator via cfe-commits
szepet added inline comments.



Comment at: test/Analysis/loopexit-cfg-output.cpp:912-914
+// CHECK:   [B5]
+// CHECK-NEXT:   Succs (1): B8
+

NoQ wrote:
> P.S. This is not a regression introduced by your patch, but i'm really 
> curious what does this block even do.
I believe this is the corresponding TransitionBlock to the WhileStmt (there is 
always a block which marks the looping back to the head of the loop event) but 
the optimization phase was good enough to detect that we will never proceed on 
that (since the first statement of the while loop is a goto jump).


https://reviews.llvm.org/D39398



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


[PATCH] D39398: [CFG][Analyzer] Add LoopExit element to the CFG in more cases

2018-01-18 Thread Peter Szecsi via Phabricator via cfe-commits
szepet updated this revision to Diff 130503.
szepet marked 2 inline comments as done.
szepet added a comment.

Added comments and removed indirect goto support from this patch.

>   This seems a bit scary because if there's no obvious one-to-once 
> correspondence between entrances and exits along every path, how would we 
> know when to pop loop contexts from the stack of location contexts? Like, if 
> we attach variable lifetime checks to the loop exit, would we need to write 
> additional code in the analyzer to see if the variable indeed goes out of 
> scope on the current path.

Yepp, we should check if the current loop (one quick method on the 
LocationContext) belongs to the LoopExit. This was already necessary in the 
previous patch since cases like:

  if(Cond)
for(;;){...}
  stmt1
  stmt2
  ...

In the above example even if `Cond` is false the analyzer will encounter the 
LoopExit since it is the first element of the `breakBlock` of the loop. (So it 
is within the same block as stmt1 and stmt2)

I have removed IndirectGoto support since it was not precise enough and rather 
handle this in the analyzer. (`isPrecisableModelableLoop` function in the 
https://reviews.llvm.org/D41151)


https://reviews.llvm.org/D39398

Files:
  include/clang/Analysis/CFG.h
  lib/Analysis/CFG.cpp
  test/Analysis/loopexit-cfg-output.cpp

Index: test/Analysis/loopexit-cfg-output.cpp
===
--- test/Analysis/loopexit-cfg-output.cpp
+++ test/Analysis/loopexit-cfg-output.cpp
@@ -458,19 +458,428 @@
 
 // CHECK:   [B0 (EXIT)]
 // CHECK-NEXT:   Preds (1): B1
-void check_break()
-{
-  for(int i = 2; i < 6; i++) {
-if(i == 4)
+void check_break() {
+  for (int i = 2; i < 6; i++) {
+if (i == 4)
   break;
   }
 
   int i = 1;
-  while(i<5){
+  while (i < 5) {
 i++;
-if(i%2)
+if (i % 2)
   break;
   }
-  
+
+  return;
+}
+
+// CHECK:   [B11 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B10
+
+// CHECK:   [B1]
+// CHECK-NEXT:   1: ForStmt (LoopExit)
+// CHECK-NEXT:   2: return;
+// CHECK-NEXT:   Preds (1): B9
+// CHECK-NEXT:   Succs (1): B0
+
+// CHECK:   [B2]
+// CHECK-NEXT:   1: i
+// CHECK-NEXT:   2: [B2.1]++
+// CHECK-NEXT:   Preds (1): B3
+// CHECK-NEXT:   Succs (1): B9
+
+// CHECK:   [B3]
+// CHECK-NEXT:   1: WhileStmt (LoopExit)
+// CHECK-NEXT:   Preds (1): B7
+// CHECK-NEXT:   Succs (1): B2
+
+// CHECK:   [B4]
+// CHECK-NEXT:   Preds (1): B6
+// CHECK-NEXT:   Succs (1): B7
+
+// CHECK:   [B5]
+// CHECK-NEXT:   1: WhileStmt (LoopExit)
+// CHECK-NEXT:   2: ForStmt (LoopExit)
+// CHECK-NEXT:   T: goto lab;
+// CHECK-NEXT:   Preds (1): B6
+// CHECK-NEXT:   Succs (1): B10
+
+// CHECK:   [B6]
+// CHECK-NEXT:   1: j
+// CHECK-NEXT:   2: [B6.1] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT:   3: 2
+// CHECK-NEXT:   4: [B6.2] % [B6.3]
+// CHECK-NEXT:   5: [B6.4] (ImplicitCastExpr, IntegralToBoolean, _Bool)
+// CHECK-NEXT:   T: if [B6.5]
+// CHECK-NEXT:   Preds (1): B7
+// CHECK-NEXT:   Succs (2): B5 B4
+
+// CHECK:   [B7]
+// CHECK-NEXT:   1: j
+// CHECK-NEXT:   2: [B7.1] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT:   3: 12
+// CHECK-NEXT:   4: [B7.2] < [B7.3]
+// CHECK-NEXT:   T: while [B7.4]
+// CHECK-NEXT:   Preds (2): B4 B8
+// CHECK-NEXT:   Succs (2): B6 B3
+
+// CHECK:   [B8]
+// CHECK-NEXT:   1: 1
+// CHECK-NEXT:   2: int j = 1;
+// CHECK-NEXT:   Preds (1): B9
+// CHECK-NEXT:   Succs (1): B7
+
+// CHECK:   [B9]
+// CHECK-NEXT:   1: i
+// CHECK-NEXT:   2: [B9.1] (ImplicitCastExpr, LValueToRValue, int)
+// CHECK-NEXT:   3: 10
+// CHECK-NEXT:   4: [B9.2] < [B9.3]
+// CHECK-NEXT:   T: for (...; [B9.4]; ...)
+// CHECK-NEXT:   Preds (2): B2 B10
+// CHECK-NEXT:   Succs (2): B8 B1
+
+// CHECK:   [B10]
+// CHECK-NEXT:   lab:
+// CHECK-NEXT:   1: 0
+// CHECK-NEXT:   2: int i = 0;
+// CHECK-NEXT:   Preds (2): B5 B11
+// CHECK-NEXT:   Succs (1): B9
+
+// CHECK:   [B0 (EXIT)]
+// CHECK-NEXT:   Preds (1): B1
+void check_goto() {
+lab:
+  for (int i = 0; i < 10; i++) {
+int j = 1;
+while (j < 12) {
+  if (j % 2)
+goto lab;
+}
+  }
+  return;
+}
+
+// CHECK:   [B11 (ENTRY)]
+// CHECK-NEXT:   Succs (1): B10
+
+// CHECK:   [B1]
+// CHECK-NEXT:   1: ForStmt (LoopExit)
+// CHECK-NEXT:   2: return;
+// CHECK-NEXT:   Preds (1): B9
+// CHECK-NEXT:   Succs (1): B0
+
+// CHECK:   [B2]
+// CHECK-NEXT:   1: i
+// CHECK-NEXT:   2: [B2.1]++
+// CHECK-NEXT:   Preds (1): B3
+// CHECK-NEXT:   Succs (1): B9
+
+// CHECK:   [B3]
+// CHECK-NEXT:   1: WhileStmt (LoopExit)
+// CHECK-NEXT:   Preds (1): B7
+// CHECK-NEXT:   Succs (1): B2
+
+// CHECK:   [B4]
+// CHECK-NEXT:   Preds (1): B6
+// CHECK-NEXT:   Succs (1): B7
+
+// CHECK:   [B5]
+// CHECK-NEXT:   1: WhileStmt (LoopExit)
+// CHECK-NEXT:   T: goto lab;
+// CHECK-NEXT:   Preds (1): B6
+// CHECK-NEXT:   Succs (1): B8
+
+// CHECK:   [B6]
+// CHECK-NEXT:   1: j
+// CHECK-NEXT:   2: [B6.1] 

[PATCH] D42249: [CodeGenCXX] annotate a GEP to a derived class with 'inbounds' (PR35909)

2018-01-18 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D42249



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


[PATCH] D42266: [analyzer] Prevent AnalyzerStatsChecker from crash

2018-01-18 Thread Peter Szecsi via Phabricator via cfe-commits
szepet created this revision.
szepet added reviewers: NoQ, dcoughlin, xazax.hun.
Herald added subscribers: dkrupp, a.sidorin, rnkovacs, baloghadamsoftware, 
whisperity.

The checker marks the locations where the analyzer creates sinks. However, it 
can happen that the sink was created because of a loop which does not contain 
condition statement, only breaks in the body. The `exhausted block` is the 
block which should contain the condition but empty, in this case.
This change only emits this marking in order to avoid the undefined behavior.


Repository:
  rC Clang

https://reviews.llvm.org/D42266

Files:
  lib/StaticAnalyzer/Checkers/AnalyzerStatsChecker.cpp
  test/Analysis/analyzer-stats.c


Index: test/Analysis/analyzer-stats.c
===
--- test/Analysis/analyzer-stats.c
+++ test/Analysis/analyzer-stats.c
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 
-analyzer-checker=core,deadcode.DeadStores,debug.Stats -verify 
-Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s
+// RUN: %clang_analyze_cc1 
-analyzer-checker=core,deadcode.DeadStores,debug.Stats -verify 
-Wno-unreachable-code -analyzer-opt-analyze-nested-blocks -analyzer-max-loop 4 
%s
 
 int foo();
 
@@ -12,3 +12,19 @@
   a /= 4;
   return a;
 }
+
+
+int sink() // expected-warning-re{{sink -> Total CFGBlocks: {{[0-9]+}} | 
Unreachable CFGBlocks: 1 | Exhausted Block: yes | Empty WorkList: yes}}
+{
+  for (int i = 0; i < 10; ++i) // expected-warning {{(sink): The analyzer 
generated a sink at this point}}
+++i;
+
+  return 0;
+}
+
+int emptyConditionLoop() // expected-warning-re{{emptyConditionLoop -> Total 
CFGBlocks: {{[0-9]+}} | Unreachable CFGBlocks: 0 | Exhausted Block: yes | Empty 
WorkList: yes}}
+{
+  int num = 1;
+  for (;;)
+num++;
+}
Index: lib/StaticAnalyzer/Checkers/AnalyzerStatsChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/AnalyzerStatsChecker.cpp
+++ lib/StaticAnalyzer/Checkers/AnalyzerStatsChecker.cpp
@@ -122,6 +122,8 @@
   E = CE.blocks_exhausted_end(); I != E; ++I) {
 const BlockEdge  =  I->first;
 const CFGBlock *Exit = BE.getDst();
+if (Exit->empty())
+  continue;
 const CFGElement  = Exit->front();
 if (Optional CS = CE.getAs()) {
   SmallString<128> bufI;


Index: test/Analysis/analyzer-stats.c
===
--- test/Analysis/analyzer-stats.c
+++ test/Analysis/analyzer-stats.c
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,deadcode.DeadStores,debug.Stats -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,deadcode.DeadStores,debug.Stats -verify -Wno-unreachable-code -analyzer-opt-analyze-nested-blocks -analyzer-max-loop 4 %s
 
 int foo();
 
@@ -12,3 +12,19 @@
   a /= 4;
   return a;
 }
+
+
+int sink() // expected-warning-re{{sink -> Total CFGBlocks: {{[0-9]+}} | Unreachable CFGBlocks: 1 | Exhausted Block: yes | Empty WorkList: yes}}
+{
+  for (int i = 0; i < 10; ++i) // expected-warning {{(sink): The analyzer generated a sink at this point}}
+++i;
+
+  return 0;
+}
+
+int emptyConditionLoop() // expected-warning-re{{emptyConditionLoop -> Total CFGBlocks: {{[0-9]+}} | Unreachable CFGBlocks: 0 | Exhausted Block: yes | Empty WorkList: yes}}
+{
+  int num = 1;
+  for (;;)
+num++;
+}
Index: lib/StaticAnalyzer/Checkers/AnalyzerStatsChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/AnalyzerStatsChecker.cpp
+++ lib/StaticAnalyzer/Checkers/AnalyzerStatsChecker.cpp
@@ -122,6 +122,8 @@
   E = CE.blocks_exhausted_end(); I != E; ++I) {
 const BlockEdge  =  I->first;
 const CFGBlock *Exit = BE.getDst();
+if (Exit->empty())
+  continue;
 const CFGElement  = Exit->front();
 if (Optional CS = CE.getAs()) {
   SmallString<128> bufI;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r316268 - [Sema] Fixes for enum handling for tautological comparison diagnostics

2018-01-18 Thread Alex L via cfe-commits
Hi Roman,

This commit has caused a regression in LLVM 6 which now triggers
-Wsign-compare for typeof(enum) and typeof(enumConstant). I filed
https://bugs.llvm.org/show_bug.cgi?id=36008. Could you please take a look
at it?

Thanks,
Alex

On 21 October 2017 at 09:44, Roman Lebedev via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: lebedevri
> Date: Sat Oct 21 09:44:03 2017
> New Revision: 316268
>
> URL: http://llvm.org/viewvc/llvm-project?rev=316268=rev
> Log:
> [Sema] Fixes for enum handling for tautological comparison diagnostics
>
> Summary:
> As Mattias Eriksson has reported in PR35009, in C, for enums, the
> underlying type should
> be used when checking for the tautological comparison, unlike C++, where
> the enumerator
> values define the value range. So if not in CPlusPlus mode, use the enum
> underlying type.
>
> Also, i have discovered a problem (a crash) when evaluating
> tautological-ness of the following comparison:
> ```
> enum A { A_a = 0 };
> if (a < 0) // expected-warning {{comparison of unsigned enum expression <
> 0 is always false}}
> return 0;
> ```
> This affects both the C and C++, but after the first fix, only C++ code
> was affected.
> That was also fixed, while preserving (i think?) the proper diagnostic
> output.
>
> And while there, attempt to enhance the test coverage.
> Yes, some tests got moved around, sorry about that :)
>
> Fixes PR35009
>
> Reviewers: aaron.ballman, rsmith, rjmccall
>
> Reviewed By: aaron.ballman
>
> Subscribers: Rakete, efriedma, materi, cfe-commits
>
> Tags: #clang
>
> Differential Revision: https://reviews.llvm.org/D39122
>
> Added:
> cfe/trunk/test/Sema/outof-range-enum-constant-compare.c
> cfe/trunk/test/Sema/tautological-constant-enum-compare.c
> Modified:
> cfe/trunk/lib/Sema/SemaChecking.cpp
> cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.c
> cfe/trunk/test/Sema/tautological-unsigned-enum-zero-compare.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaChecking.cpp?rev=316268=316267=316268=diff
> 
> ==
> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Sat Oct 21 09:44:03 2017
> @@ -8181,8 +8181,12 @@ struct IntRange {
>  if (const AtomicType *AT = dyn_cast(T))
>T = AT->getValueType().getTypePtr();
>
> -// For enum types, use the known bit width of the enumerators.
> -if (const EnumType *ET = dyn_cast(T)) {
> +if (!C.getLangOpts().CPlusPlus) {
> +  // For enum types in C code, use the underlying datatype.
> +  if (const EnumType *ET = dyn_cast(T))
> +T = ET->getDecl()->getIntegerType().getDesugaredType(C).
> getTypePtr();
> +} else if (const EnumType *ET = dyn_cast(T)) {
> +  // For enum types in C++, use the known bit width of the
> enumerators.
>EnumDecl *Enum = ET->getDecl();
>// In C++11, enums without definitions can have an explicitly
> specified
>// underlying type.  Use this type to compute the range.
> @@ -8584,8 +8588,10 @@ bool isNonBooleanUnsignedValue(Expr *E)
>  }
>
>  enum class LimitType {
> -  Max, // e.g. 32767 for short
> -  Min  // e.g. -32768 for short
> +  Max = 1U << 0U,  // e.g. 32767 for short
> +  Min = 1U << 1U,  // e.g. -32768 for short
> +  Both = Max | Min // When the value is both the Min and the Max limit at
> the
> +   // same time; e.g. in C++, A::a in enum A { a = 0 };
>  };
>
>  /// Checks whether Expr 'Constant' may be the
> @@ -8608,6 +8614,10 @@ llvm::Optional IsTypeLimit(Se
>
>IntRange OtherRange = IntRange::forValueOfType(S.Context, OtherT);
>
> +  // Special-case for C++ for enum with one enumerator with value of 0.
> +  if (OtherRange.Width == 0)
> +return Value == 0 ? LimitType::Both : llvm::Optional();
> +
>if (llvm::APSInt::isSameValue(
>llvm::APSInt::getMaxValue(OtherRange.Width,
>  OtherT->isUnsignedIntegerType()),
> @@ -8620,7 +8630,7 @@ llvm::Optional IsTypeLimit(Se
>Value))
>  return LimitType::Min;
>
> -  return llvm::Optional();
> +  return llvm::None;
>  }
>
>  bool HasEnumType(Expr *E) {
> @@ -8655,9 +8665,12 @@ bool CheckTautologicalComparison(Sema 
>
>bool ConstIsLowerBound = (Op == BO_LT || Op == BO_LE) ^ RhsConstant;
>bool ResultWhenConstEqualsOther = (Op == BO_LE || Op == BO_GE);
> -  bool ResultWhenConstNeOther =
> -  ConstIsLowerBound ^ (ValueType == LimitType::Max);
> -  if (ResultWhenConstEqualsOther != ResultWhenConstNeOther)
> +  if (ValueType != LimitType::Both) {
> +bool ResultWhenConstNeOther =
> +ConstIsLowerBound ^ (ValueType == LimitType::Max);
> +if (ResultWhenConstEqualsOther != ResultWhenConstNeOther)
> +  return false; // The comparison is not tautological.
> +  } else if (ResultWhenConstEqualsOther == ConstIsLowerBound)
>  return false; 

[PATCH] D42036: [clang-format] Keep comments aligned to macros

2018-01-18 Thread Mark Zeren via Phabricator via cfe-commits
mzeren-vmw marked 2 inline comments as done.
mzeren-vmw added inline comments.



Comment at: lib/Format/TokenAnnotator.cpp:1756
+  if (Alignment == CA_Preprocessor)
+(*I)->LevelOffset = 1;
 } else {

krasimir wrote:
> This feels a bit awkward: we're adding code that implicitly assumes the exact 
> style the preprocessor directives and comments around them are handled. Maybe 
> if this could become part of the level itself, it would feel less awkward.
I agree that the "long distance coupling" is awkward. Perhaps the new 
enumerator names make this a bit more palatable?



Comment at: lib/Format/TokenAnnotator.h:41
   AnnotatedLine(const UnwrappedLine )
-  : First(Line.Tokens.front().Tok), Level(Line.Level),
+  : First(Line.Tokens.front().Tok), Level(Line.Level), LevelOffset(0),
 MatchingOpeningBlockLineIndex(Line.MatchingOpeningBlockLineIndex),

krasimir wrote:
> Is there a way to not introduce `LevelOffset`, but have it part of `Level`?
`Level` is an abstract indentation level, while `LevelOffset` is "columns". 
They have different units. Maybe it would be feasible to change the units of 
"Level" to columns in order to merge these two variables, but doing so would 
throw away information. It also seems like a much larger change. We could 
create a composite type `class AnnotatedLevel { private: unsigned Level, 
unsigned Offset public:   }` but that seems 
over-engineered. Any other ideas?


Repository:
  rC Clang

https://reviews.llvm.org/D42036



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


[PATCH] D42217: Set Module Metadata "AvoidPLT" when -fno-plt is used.

2018-01-18 Thread Sriraman Tallam via Phabricator via cfe-commits
tmsriram updated this revision to Diff 130500.
tmsriram added a comment.

METADATA tag changed to "RtLibUseGOT".  Also see: 
https://reviews.llvm.org/D42224/


https://reviews.llvm.org/D42217

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGen/noplt.c


Index: test/CodeGen/noplt.c
===
--- test/CodeGen/noplt.c
+++ test/CodeGen/noplt.c
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -emit-llvm -fno-plt %s -o - | FileCheck %s 
-check-prefix=CHECK-NOPLT
+// RUN: %clang_cc1 -emit-llvm -fno-plt %s -o - | FileCheck %s 
-check-prefix=CHECK-NOPLT -check-prefix=CHECK-NOPLT-METADATA
 
 // CHECK-NOPLT: Function Attrs: nonlazybind
 // CHECK-NOPLT-NEXT: declare {{.*}}i32 @foo
+// CHECK-NOPLT-METADATA: !"RtLibUseGOT"
 int foo();
 
 int bar() {
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -555,6 +555,10 @@
   getModule().setPIELevel(static_cast(PLevel));
   }
 
+  if (CodeGenOpts.NoPLT) {
+getModule().setRtLibUseGOT();
+  }
+
   SimplifyPersonality();
 
   if (getCodeGenOpts().EmitDeclMetadata)


Index: test/CodeGen/noplt.c
===
--- test/CodeGen/noplt.c
+++ test/CodeGen/noplt.c
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -emit-llvm -fno-plt %s -o - | FileCheck %s -check-prefix=CHECK-NOPLT
+// RUN: %clang_cc1 -emit-llvm -fno-plt %s -o - | FileCheck %s -check-prefix=CHECK-NOPLT -check-prefix=CHECK-NOPLT-METADATA
 
 // CHECK-NOPLT: Function Attrs: nonlazybind
 // CHECK-NOPLT-NEXT: declare {{.*}}i32 @foo
+// CHECK-NOPLT-METADATA: !"RtLibUseGOT"
 int foo();
 
 int bar() {
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -555,6 +555,10 @@
   getModule().setPIELevel(static_cast(PLevel));
   }
 
+  if (CodeGenOpts.NoPLT) {
+getModule().setRtLibUseGOT();
+  }
+
   SimplifyPersonality();
 
   if (getCodeGenOpts().EmitDeclMetadata)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39050: Add index-while-building support to Clang

2018-01-18 Thread Nathan Hawes via Phabricator via cfe-commits
nathawes updated this revision to Diff 130496.
nathawes marked 6 inline comments as done.
nathawes added a comment.

- Applied the various refactorings suggested by @ioeric
- Extended c-index-test with a new option to print out the collected unit 
indexing data, and
- Added tests for the unit indexing functionality using the new option
- Fixed formatting


https://reviews.llvm.org/D39050

Files:
  include/clang/Basic/AllDiagnostics.h
  include/clang/Basic/CMakeLists.txt
  include/clang/Basic/Diagnostic.td
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticIDs.h
  include/clang/Basic/DiagnosticIndexKinds.td
  include/clang/Driver/Job.h
  include/clang/Driver/Options.td
  include/clang/Frontend/CompilerInstance.h
  include/clang/Frontend/FrontendOptions.h
  include/clang/Index/DeclOccurrence.h
  include/clang/Index/IndexDataConsumer.h
  include/clang/Index/IndexDiagnostic.h
  include/clang/Index/IndexingAction.h
  include/clang/Index/RecordingAction.h
  include/clang/Index/UnitIndexDataConsumer.h
  include/clang/Index/UnitIndexingAction.h
  include/clang/module.modulemap
  lib/Basic/DiagnosticIDs.cpp
  lib/Driver/Driver.cpp
  lib/Driver/Job.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/Darwin.cpp
  lib/Frontend/CompilerInstance.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/FrontendTool/CMakeLists.txt
  lib/FrontendTool/ExecuteCompilerInvocation.cpp
  lib/Index/CMakeLists.txt
  lib/Index/FileIndexData.cpp
  lib/Index/FileIndexData.h
  lib/Index/IndexingAction.cpp
  lib/Index/IndexingContext.cpp
  lib/Index/IndexingContext.h
  lib/Index/UnitIndexDataRecorder.cpp
  lib/Index/UnitIndexDataRecorder.h
  test/Index/Core/Inputs/module/ModDep.h
  test/Index/Core/Inputs/module/ModSystem.h
  test/Index/Core/Inputs/module/ModTop.h
  test/Index/Core/Inputs/module/ModTopSub1.h
  test/Index/Core/Inputs/module/ModTopSub2.h
  test/Index/Core/Inputs/module/module.modulemap
  test/Index/Core/Inputs/sys/system-head.h
  test/Index/Core/Inputs/transitive-include.h
  test/Index/Core/external-source-symbol-attr.m
  test/Index/Core/index-instantiated-source.cpp
  test/Index/Core/index-source.mm
  test/Index/Core/index-subkinds.m
  test/Index/Core/index-system.mm
  test/Index/Core/index-unit.mm
  test/Index/Store/assembly-invocation.c
  tools/c-index-test/core_main.cpp
  tools/diagtool/DiagnosticNames.cpp
  tools/libclang/CXIndexDataConsumer.cpp
  tools/libclang/CXIndexDataConsumer.h

Index: tools/libclang/CXIndexDataConsumer.h
===
--- tools/libclang/CXIndexDataConsumer.h
+++ tools/libclang/CXIndexDataConsumer.h
@@ -463,12 +463,12 @@
 private:
   bool handleDeclOccurence(const Decl *D, index::SymbolRoleSet Roles,
ArrayRef Relations,
-   FileID FID, unsigned Offset,
+   FileID FID, unsigned Offset, bool IsInSystemFile,
ASTNodeInfo ASTNode) override;
 
   bool handleModuleOccurence(const ImportDecl *ImportD,
- index::SymbolRoleSet Roles,
- FileID FID, unsigned Offset) override;
+ index::SymbolRoleSet Roles, FileID FID,
+ unsigned Offset, bool IsInSystemFile) override;
 
   void finish() override;
 
Index: tools/libclang/CXIndexDataConsumer.cpp
===
--- tools/libclang/CXIndexDataConsumer.cpp
+++ tools/libclang/CXIndexDataConsumer.cpp
@@ -150,11 +150,9 @@
 };
 }
 
-bool CXIndexDataConsumer::handleDeclOccurence(const Decl *D,
-  SymbolRoleSet Roles,
- ArrayRef Relations,
-  FileID FID, unsigned Offset,
-  ASTNodeInfo ASTNode) {
+bool CXIndexDataConsumer::handleDeclOccurence(
+const Decl *D, SymbolRoleSet Roles, ArrayRef Relations,
+FileID FID, unsigned Offset, bool IsInSystemFile, ASTNodeInfo ASTNode) {
   SourceLocation Loc = getASTContext().getSourceManager()
   .getLocForStartOfFile(FID).getLocWithOffset(Offset);
 
@@ -219,9 +217,9 @@
 }
 
 bool CXIndexDataConsumer::handleModuleOccurence(const ImportDecl *ImportD,
-SymbolRoleSet Roles,
-FileID FID,
-unsigned Offset) {
+SymbolRoleSet Roles, FileID FID,
+unsigned Offset,
+bool IsInSystemFile) {
   IndexingDeclVisitor(*this, SourceLocation(), nullptr).Visit(ImportD);
   return !shouldAbort();
 }
Index: tools/diagtool/DiagnosticNames.cpp
===
--- tools/diagtool/DiagnosticNames.cpp

[PATCH] D42248: [LangOpts] Add a LangOpt to represent "#pragma region" support.

2018-01-18 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

Well, my understanding is that the pragma is a complete no-op even for MSVC, 
and is used only as a marker for editors such as Visual Studio's.
So, unconditionally ignoring it would seem to be fine.


https://reviews.llvm.org/D42248



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


[PATCH] D42261: [clang-tidy objc-property-declaration] New option AdditionalAcronyms

2018-01-18 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: docs/clang-tidy/checks/objc-property-declaration.rst:45
+
+   If set, replaces the default list. (If you want to append to the default 
list, set AdditionalAcronyms instead.)
+

Please limit string length to 80 symbols.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42261



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


[PATCH] D39050: Add index-while-building support to Clang

2018-01-18 Thread Nathan Hawes via Phabricator via cfe-commits
nathawes planned changes to this revision.
nathawes marked 32 inline comments as done.
nathawes added a comment.

@ioeric I should have an updated patch up shortly with your inline comments 
addressed + new tests. Thanks again for reviewing!




Comment at: include/clang/Index/IndexUnitDataConsumer.h:67
+private:
+  virtual void _anchor();
+};

ioeric wrote:
> Comment? Why do we actually need this?
From [[ 
https://stackoverflow.com/questions/34913197/what-is-vtable-anchoring-and-how-does-it-work-in-a-shared-object
 | here ]], my understanding is that it's an optimization to avoid the vtable 
being included in multiple translation units. I'm not sure if that's actually a 
problem, I was just following IndexDataConsumer's lead. Added a comment.



Comment at: include/clang/Index/IndexingAction.h:114
+std::unique_ptr
+createUnitIndexingAction(const UnitIndexingOptions ,
+ IndexUnitDataConsumerFactory ConsumerFactory,

ioeric wrote:
>  What is the intended user of this function? It's unclear how users could 
> obtain a `ConsumerFactory ` (i.e. `UnitDetails`) without the functionalities 
> in `UnitDataConsumerActionImpl `.
> 
> (Also see comment in the implementation of `createIndexDataRecordingAction`.)
Sorry, I'm not sure what you mean here. Users shouldn't need to know anything 
about `UnitDataConsumerActionImpl`, they just need to provide a lambda/function 
reference that takes a `CompilerInstance&` and a `UnitDetails` and returns an 
`IndexUnitDataConsumer` (or `UnitIndexDataConsumer` once I rename it). This 
gets called once per translation unit to get a distinct data consumer for each 
unit, i.e. for the main translation unit as well as for each of its dependent 
modules that the main unit's data consumer says should be indexed via 
`shouldIndexModuleDependency(...)`.



Comment at: include/clang/Index/IndexingAction.h:128
+RecordingOptions
+getRecordingOptionsFromFrontendOptions(const FrontendOptions );
+

ioeric wrote:
> This is likely only useful for compiler invocation. I would put it in the 
> compiler invocation code.
There's another public `index::` API for writing out index data for individual 
clang module files in the follow up patch that takes a `RecordingOptions` and 
is used externally, from Swift. This function's useful on the Swift side to get 
the `RecordingOptions` from `FrontendOptions` it has already set up.



Comment at: lib/Index/IndexingAction.cpp:137
+
+CreatedASTConsumer = true;
+std::vector Consumers;

ioeric wrote:
> nit: Move this after `Impl->createIndexASTConsumer(CI)`.
> 
> Do we need to reset this flag? Calling `CreateASTConsumer ` multiple times on 
> the same instance seems to be allowed? 
Oops. Yes, we do :-)



Comment at: lib/Index/IndexingAction.cpp:504
+  /// \returns true if \c Mod was indexed
+  static bool indexModule(
+  const CompilerInstance , serialization::ModuleFile ,

ioeric wrote:
> Non-factory static method is often a code smell. Any reason not to make these 
> static methods private members? With that, you wouldn't need to pass along so 
> many parameters. You could make them `const` if you don't want members to be 
> modified.
Sorry, there's missing context – they're used from another public API that's in 
the follow-up patch. I'll bring that over and make these top-level static 
functions, since they don't belong exclusively to IndexDataConsumerActionImpl.



Comment at: lib/Index/IndexingAction.cpp:511
+  /// Get unit details for the given module file
+  static UnitDetails getUnitDetails(serialization::ModuleFile ,
+const CompilerInstance ,

ioeric wrote:
> Why is this overload public while others are private? Aren't they all used 
> only in this class?
Same as above – this is called from a public `index::` API in the follow-up 
patch.



Comment at: lib/Index/IndexingAction.cpp:758
+
+  class IndexUnitDataRecorder : public IndexUnitDataConsumer {
+  public:

ioeric wrote:
> I think the inheritance of `IndexUnitDataConsumer`  and the creation of 
> factory should be in user code (e.g. implementation for on-disk 
> persist-index-data should come from the compiler invocation code 
> `ExecuteCompilerInvocation.cpp` or at least a separate file in the library 
> that compiler invocation can use), and the user should only use 
> `createUnitIndexingAction` by providing a factory.  Currently, 
> `createUnitIndexingAction` and `createIndexDataRecordingAction` are mostly 
> identical except for the code that implements `IndexUnitDataConsumer ` and 
> creates the factory.
> 
> The current `createIndexDataRecordingAction` would probably only used by the 
> compiler invocation, and we can keep the generalized 
> `createUnitIndexingAction` in the public 

[PATCH] D42227: [Refactor] Use enum instead of magic number in handleX86ForceAlignArgPointerAttr, NFC

2018-01-18 Thread Hongbin Zheng via Phabricator via cfe-commits
etherzhhb added a comment.

Thanks, I will commit tonight. If you want this patch before that, you could 
commit it for me.


Repository:
  rC Clang

https://reviews.llvm.org/D42227



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


[PATCH] D42213: [ASTMatchers] [NFC] Fix code examples

2018-01-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 130493.
MaskRay added a comment.

More


Repository:
  rC Clang

https://reviews.llvm.org/D42213

Files:
  include/clang/ASTMatchers/ASTMatchers.h

Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -800,7 +800,7 @@
 ///   A b;
 ///   A c;
 ///
-///   template f() {};
+///   template void f() {};
 ///   void func() { f(); };
 /// \endcode
 /// classTemplateSpecializationDecl(hasTemplateArgument(
@@ -880,12 +880,12 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
-///   struct B { B* next; };
+///   struct B { int next; };
+///   template struct A {};
 ///   A<::next> a;
 /// \endcode
 /// classTemplateSpecializationDecl(hasAnyTemplateArgument(
-/// refersToDeclaration(fieldDecl(hasName("next"
+/// refersToDeclaration(fieldDecl(hasName("next")
 ///   matches the specialization \c A<::next> with \c fieldDecl(...) matching
 /// \c B::next
 AST_MATCHER_P(TemplateArgument, refersToDeclaration,
@@ -899,8 +899,8 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
-///   struct B { B* next; };
+///   struct B { int next; };
+///   template struct A {};
 ///   A<::next> a;
 /// \endcode
 /// templateSpecializationType(hasAnyTemplateArgument(
@@ -917,7 +917,7 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
+///   template struct C {};
 ///   C<42> c;
 /// \endcode
 /// classTemplateSpecializationDecl(
@@ -932,7 +932,7 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
+///   template struct C {};
 ///   C<42> c;
 /// \endcode
 /// classTemplateSpecializationDecl(
@@ -953,7 +953,7 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
+///   template struct C {};
 ///   C<42> c;
 /// \endcode
 /// classTemplateSpecializationDecl(
@@ -1523,12 +1523,12 @@
 /// \code
 ///   T u(f());
 ///   g(f());
-/// \endcode
-/// but does not match
-/// \code
-///   f();
 ///   f().func();
 /// \endcode
+/// but does not match
+/// \code
+///   f();
+/// \endcode
 extern const internal::VariadicDynCastAllOfMatcher
 materializeTemporaryExpr;
@@ -1789,7 +1789,7 @@
 ///   switch(a) { case 42: break; default: break; }
 /// \endcode
 /// switchStmt()
-///   matches 'switch(a)'.
+///   matches 'switch(a) {'.
 extern const internal::VariadicDynCastAllOfMatcher switchStmt;
 
 /// \brief Matches case and default statements inside switch statements.
@@ -1799,7 +1799,7 @@
 ///   switch(a) { case 42: break; default: break; }
 /// \endcode
 /// switchCase()
-///   matches 'case 42: break;' and 'default: break;'.
+///   matches 'case 42:' and 'default:'.
 extern const internal::VariadicDynCastAllOfMatcher switchCase;
 
 /// \brief Matches case statements inside switch statements.
@@ -1809,7 +1809,7 @@
 ///   switch(a) { case 42: break; default: break; }
 /// \endcode
 /// caseStmt()
-///   matches 'case 42: break;'.
+///   matches 'case 42:'.
 extern const internal::VariadicDynCastAllOfMatcher caseStmt;
 
 /// \brief Matches default statements inside switch statements.
@@ -1819,13 +1819,13 @@
 ///   switch(a) { case 42: break; default: break; }
 /// \endcode
 /// defaultStmt()
-///   matches 'default: break;'.
+///   matches 'default:'.
 extern const internal::VariadicDynCastAllOfMatcher
 defaultStmt;
 
 /// \brief Matches compound statements.
 ///
-/// Example matches '{}' and '{{}}'in 'for (;;) {{}}'
+/// Example matches '{}' and '{{}}' in 'for (;;) {{}}'
 /// \code
 ///   for (;;) {{}}
 /// \endcode
@@ -1838,7 +1838,7 @@
 ///   try {} catch(int i) {}
 /// \endcode
 /// cxxCatchStmt()
-///   matches 'catch(int i)'
+///   matches 'catch(int i) {}'
 extern const internal::VariadicDynCastAllOfMatcher
 cxxCatchStmt;
 
@@ -1848,7 +1848,7 @@
 ///   try {} catch(int i) {}
 /// \endcode
 /// cxxTryStmt()
-///   matches 'try {}'
+///   matches 'try {} catch(int i) {}'
 extern const internal::VariadicDynCastAllOfMatcher cxxTryStmt;
 
 /// \brief Matches throw expressions.
@@ -2502,11 +2502,12 @@
 /// \brief Matches AST nodes that have child AST nodes that match the
 /// provided matcher.
 ///
-/// Example matches X, Y
+/// Example matches X, Y, Y::X, Z::Y, Z::Y::X
 ///   (matcher = cxxRecordDecl(forEach(cxxRecordDecl(hasName("X")))
 /// \code
-///   class X {};  // Matches X, because X::X is a class of name X inside X.
-///   class Y { class X {}; };
+///   class X {};
+///   class Y { class X {}; };  // Matches Y, because Y::X is a class of name X
+/// // inside Y.
 ///   class Z { class Y { class X {}; }; };  // Does not match Z.
 /// \endcode
 ///
@@ -2522,11 +2523,12 @@
 /// \brief Matches AST nodes that have 

[PATCH] D42227: [Refactor] Use enum instead of magic number in handleX86ForceAlignArgPointerAttr, NFC

2018-01-18 Thread Eric Christopher via Phabricator via cfe-commits
echristo accepted this revision.
echristo added a comment.
This revision is now accepted and ready to land.

LGTM.

Let me know if you need this committed.


Repository:
  rC Clang

https://reviews.llvm.org/D42227



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


r322901 - Remove TautologicalInRangeCompare from Extra and TautologicalCompare.

2018-01-18 Thread Nico Weber via cfe-commits
Author: nico
Date: Thu Jan 18 13:40:27 2018
New Revision: 322901

URL: http://llvm.org/viewvc/llvm-project?rev=322901=rev
Log:
Remove TautologicalInRangeCompare from Extra and TautologicalCompare.

This removes the following (already default-off) warnings from -Wextra:
  -Wtautological-type-limit-compare,
  -Wtautological-unsigned-zero-compare
  -Wtautological-unsigned-enum-zero-compare

On the thread "[cfe-dev] -Wtautological-constant-compare issues", clang
code owners Richard Smith, John McCall, and Reid Kleckner as well as
libc++ code owner Marshall Clow stated that these new warnings are not
yet ready for prime time and shouldn't be part of -Wextra.

Furthermore, Vedant Kumar (Apple), Peter Hosek (Fuchsia), and me (Chromium)
expressed the same concerns (Vedant on that thread, Peter on
https://reviews.llvm.org/D39462, me on https://reviews.llvm.org/D41512).

So remove them from -Wextra, and remove TautologicalInRangeCompare from
TautologicalCompare too until they're usable with real-world code.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/test/Sema/tautological-constant-compare.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=322901=322900=322901=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Thu Jan 18 13:40:27 2018
@@ -444,8 +444,7 @@ def TautologicalInRangeCompare : DiagGro
 
TautologicalUnsignedEnumZeroCompare]>;
 def TautologicalOutOfRangeCompare : 
DiagGroup<"tautological-constant-out-of-range-compare">;
 def TautologicalConstantCompare : DiagGroup<"tautological-constant-compare",
-[TautologicalInRangeCompare,
- TautologicalOutOfRangeCompare]>;
+[TautologicalOutOfRangeCompare]>;
 def TautologicalPointerCompare : DiagGroup<"tautological-pointer-compare">;
 def TautologicalOverlapCompare : DiagGroup<"tautological-overlap-compare">;
 def TautologicalUndefinedCompare : DiagGroup<"tautological-undefined-compare">;
@@ -719,7 +718,6 @@ def IntToPointerCast : DiagGroup<"int-to
 def Move : DiagGroup<"move", [PessimizingMove, RedundantMove, SelfMove]>;
 
 def Extra : DiagGroup<"extra", [
-TautologicalInRangeCompare,
 MissingFieldInitializers,
 IgnoredQualifiers,
 InitializerOverrides,

Modified: cfe/trunk/test/Sema/tautological-constant-compare.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/tautological-constant-compare.c?rev=322901=322900=322901=diff
==
--- cfe/trunk/test/Sema/tautological-constant-compare.c (original)
+++ cfe/trunk/test/Sema/tautological-constant-compare.c Thu Jan 18 13:40:27 2018
@@ -2,8 +2,8 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only 
-Wtautological-constant-in-range-compare -DTEST -verify -x c++ %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only 
-Wtautological-type-limit-compare -DTEST -verify %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only 
-Wtautological-type-limit-compare -DTEST -verify -x c++ %s
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wextra 
-Wno-sign-compare -DTEST -verify %s
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wextra 
-Wno-sign-compare -DTEST -verify -x c++ %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wextra 
-Wno-sign-compare -verify %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wextra 
-Wno-sign-compare -verify -x c++ %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wall -verify %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -Wall -verify -x c++ 
%s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fsyntax-only -verify %s


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


[PATCH] D42249: [CodeGenCXX] annotate a GEP to a derived class with 'inbounds' (PR35909)

2018-01-18 Thread Sanjay Patel via Phabricator via cfe-commits
spatel updated this revision to Diff 130488.
spatel added a comment.

Patch updated:

1. Removed comment that didn't add value.
2. Added test with no sanitizing, reduced from PR35909.


https://reviews.llvm.org/D42249

Files:
  lib/CodeGen/CGClass.cpp
  test/CodeGenCXX/catch-undef-behavior.cpp
  test/CodeGenCXX/derived-cast.cpp


Index: test/CodeGenCXX/derived-cast.cpp
===
--- test/CodeGenCXX/derived-cast.cpp
+++ test/CodeGenCXX/derived-cast.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm %s -o - | 
FileCheck %s
+
+class A {
+int a;
+};
+
+class B {
+int b;
+public:
+A *getAsA();
+};
+
+class X : public A, public B {
+int x;
+};
+
+// PR35909 - https://bugs.llvm.org/show_bug.cgi?id=35909
+
+A *B::getAsA() {
+  return static_cast(this);
+
+  // CHECK-LABEL: define %class.A* @_ZN1B6getAsAEv
+  // CHECK: %[[THIS:.*]] = load %class.B*, %class.B**
+  // CHECK-NEXT: %[[BC:.*]] = bitcast %class.B* %[[THIS]] to i8*
+  // CHECK-NEXT: getelementptr inbounds i8, i8* %[[BC]], i64 -4
+}
+
Index: test/CodeGenCXX/catch-undef-behavior.cpp
===
--- test/CodeGenCXX/catch-undef-behavior.cpp
+++ test/CodeGenCXX/catch-undef-behavior.cpp
@@ -371,7 +371,7 @@
 void downcast_pointer(B *b) {
   (void) static_cast(b);
   // Alignment check from EmitTypeCheck(TCK_DowncastPointer, ...)
-  // CHECK: [[SUB:%[.a-z0-9]*]] = getelementptr i8, i8* {{.*}}, i64 -16
+  // CHECK: [[SUB:%[.a-z0-9]*]] = getelementptr inbounds i8, i8* {{.*}}, i64 
-16
   // CHECK-NEXT: [[C:%.+]] = bitcast i8* [[SUB]] to %class.C*
   // null check goes here
   // CHECK: [[FROM_PHI:%.+]] = phi %class.C* [ [[C]], {{.*}} ], {{.*}}
@@ -388,7 +388,7 @@
 void downcast_reference(B ) {
   (void) static_cast(b);
   // Alignment check from EmitTypeCheck(TCK_DowncastReference, ...)
-  // CHECK:  [[SUB:%[.a-z0-9]*]] = getelementptr i8, i8* {{.*}}, i64 -16
+  // CHECK:  [[SUB:%[.a-z0-9]*]] = getelementptr inbounds i8, i8* {{.*}}, 
i64 -16
   // CHECK-NEXT: [[C:%.+]] = bitcast i8* [[SUB]] to %class.C*
   // Objectsize check goes here
   // CHECK:  [[C_INT:%.+]] = ptrtoint %class.C* [[C]] to i64
Index: lib/CodeGen/CGClass.cpp
===
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -406,8 +406,8 @@
 
   // Apply the offset.
   llvm::Value *Value = Builder.CreateBitCast(BaseAddr.getPointer(), Int8PtrTy);
-  Value = Builder.CreateGEP(Value, Builder.CreateNeg(NonVirtualOffset),
-"sub.ptr");
+  Value = Builder.CreateInBoundsGEP(Value, Builder.CreateNeg(NonVirtualOffset),
+"sub.ptr");
 
   // Just cast.
   Value = Builder.CreateBitCast(Value, DerivedPtrTy);


Index: test/CodeGenCXX/derived-cast.cpp
===
--- test/CodeGenCXX/derived-cast.cpp
+++ test/CodeGenCXX/derived-cast.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+
+class A {
+int a;
+};
+
+class B {
+int b;
+public:
+A *getAsA();
+};
+
+class X : public A, public B {
+int x;
+};
+
+// PR35909 - https://bugs.llvm.org/show_bug.cgi?id=35909
+
+A *B::getAsA() {
+  return static_cast(this);
+
+  // CHECK-LABEL: define %class.A* @_ZN1B6getAsAEv
+  // CHECK: %[[THIS:.*]] = load %class.B*, %class.B**
+  // CHECK-NEXT: %[[BC:.*]] = bitcast %class.B* %[[THIS]] to i8*
+  // CHECK-NEXT: getelementptr inbounds i8, i8* %[[BC]], i64 -4
+}
+
Index: test/CodeGenCXX/catch-undef-behavior.cpp
===
--- test/CodeGenCXX/catch-undef-behavior.cpp
+++ test/CodeGenCXX/catch-undef-behavior.cpp
@@ -371,7 +371,7 @@
 void downcast_pointer(B *b) {
   (void) static_cast(b);
   // Alignment check from EmitTypeCheck(TCK_DowncastPointer, ...)
-  // CHECK: [[SUB:%[.a-z0-9]*]] = getelementptr i8, i8* {{.*}}, i64 -16
+  // CHECK: [[SUB:%[.a-z0-9]*]] = getelementptr inbounds i8, i8* {{.*}}, i64 -16
   // CHECK-NEXT: [[C:%.+]] = bitcast i8* [[SUB]] to %class.C*
   // null check goes here
   // CHECK: [[FROM_PHI:%.+]] = phi %class.C* [ [[C]], {{.*}} ], {{.*}}
@@ -388,7 +388,7 @@
 void downcast_reference(B ) {
   (void) static_cast(b);
   // Alignment check from EmitTypeCheck(TCK_DowncastReference, ...)
-  // CHECK:  [[SUB:%[.a-z0-9]*]] = getelementptr i8, i8* {{.*}}, i64 -16
+  // CHECK:  [[SUB:%[.a-z0-9]*]] = getelementptr inbounds i8, i8* {{.*}}, i64 -16
   // CHECK-NEXT: [[C:%.+]] = bitcast i8* [[SUB]] to %class.C*
   // Objectsize check goes here
   // CHECK:  [[C_INT:%.+]] = ptrtoint %class.C* [[C]] to i64
Index: lib/CodeGen/CGClass.cpp
===
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -406,8 +406,8 @@
 
   // Apply the offset.
   

[PATCH] D42036: [clang-format] Keep comments aligned to macros

2018-01-18 Thread Mark Zeren via Phabricator via cfe-commits
mzeren-vmw updated this revision to Diff 130487.
mzeren-vmw added a comment.

Documented CommentAlignment enumerators. Documenting them suggested better
enumerator names.

Added tests for multi-line comments, block comments and trailing comments.


Repository:
  rC Clang

https://reviews.llvm.org/D42036

Files:
  lib/Format/TokenAnnotator.cpp
  lib/Format/TokenAnnotator.h
  lib/Format/UnwrappedLineFormatter.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -2497,7 +2497,6 @@
"code();\n"
"#endif",
Style);
-
   // Include guards must cover the entire file.
   verifyFormat("code();\n"
"code();\n"
@@ -2593,21 +2592,97 @@
"code();\n"
"#endif",
Style));
-  // FIXME: The comment indent corrector in TokenAnnotator gets thrown off by
-  // preprocessor indentation.
-  EXPECT_EQ("#if 1\n"
-"  // comment\n"
-"#  define A 0\n"
-"// comment\n"
-"#  define B 0\n"
-"#endif",
-format("#if 1\n"
-   "// comment\n"
-   "#  define A 0\n"
-   "   // comment\n"
-   "#  define B 0\n"
-   "#endif",
-   Style));
+  // Comments aligned to macros stay aligned. This test is incompatible with
+  // verifyFormat() because messUp() removes the alignment.
+  {
+const char *Expected = ""
+   "// Level 0 unaligned comment\n"
+   "// Level 0 unaligned continuation\n"
+   "#ifndef HEADER_H\n"
+   "// Level 0 aligned comment\n"
+   "// Level 0 aligned continuation\n"
+   "#define HEADER_H\n"
+   "#if 1\n"
+   "   // aligned comment\n"
+   "   // aligned continuation\n"
+   "#  define A 0\n"
+   "// un-aligned comment\n"
+   "// un-aligned continuation\n"
+   "#  define B 0\n"
+   "// Trailing aligned comment\n"
+   "#endif\n"
+   "#endif";
+const char *ToFormat = ""
+   " // Level 0 unaligned comment\n"
+   " // Level 0 unaligned continuation\n"
+   "#ifndef HEADER_H\n"
+   "// Level 0 aligned comment\n"
+   "// Level 0 aligned continuation\n"
+   "#define HEADER_H\n"
+   "#if 1\n"
+   "   // aligned comment\n"
+   "   // aligned continuation\n"
+   "#  define A 0\n"
+   "  // un-aligned comment\n"
+   "  // un-aligned continuation\n"
+   "#  define B 0\n"
+   "   // Trailing aligned comment\n"
+   "#endif\n"
+   "#endif";
+EXPECT_EQ(Expected, format(ToFormat, Style));
+EXPECT_EQ(Expected, format(Expected, Style));
+  }
+  // Same as above, but block comments.
+  {
+const char *Expected = ""
+   "/*\n"
+   " * Level 0 unaligned block comment\n"
+   " */\n"
+   "#ifndef HEADER_H\n"
+   "/*\n"
+   " *  Level 0 aligned comment\n"
+   " */\n"
+   "#define HEADER_H\n"
+   "#if 1\n"
+   "   /*\n"
+   "* Aligned comment\n"
+   "*/\n"
+   "#  define A 0\n"
+   "/*\n"
+   " * Unaligned comment\n"
+   " */\n"
+   "#  define B 0\n"
+   "/*\n"
+   " * Trailing aligned comment\n"
+   " */\n"
+   "#endif\n"
+   "#endif";
+const char *ToFormat = ""
+   " /*\n"
+   "  * Level 0 unaligned block comment\n"
+   "  */\n"
+   "#ifndef HEADER_H\n"
+   "/*\n"
+   " *  Level 0 aligned comment\n"
+   " */\n"
+   "#define HEADER_H\n"
+   "#if 1\n"
+   "   /*\n"
+  

[PATCH] D42213: [ASTMatchers] [NFC] Fix code examples

2018-01-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 130486.
MaskRay added a comment.

More


Repository:
  rC Clang

https://reviews.llvm.org/D42213

Files:
  include/clang/ASTMatchers/ASTMatchers.h

Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -800,7 +800,7 @@
 ///   A b;
 ///   A c;
 ///
-///   template f() {};
+///   template void f() {};
 ///   void func() { f(); };
 /// \endcode
 /// classTemplateSpecializationDecl(hasTemplateArgument(
@@ -880,12 +880,12 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
-///   struct B { B* next; };
+///   struct B { int next; };
+///   template struct A {};
 ///   A<::next> a;
 /// \endcode
 /// classTemplateSpecializationDecl(hasAnyTemplateArgument(
-/// refersToDeclaration(fieldDecl(hasName("next"
+/// refersToDeclaration(fieldDecl(hasName("next")
 ///   matches the specialization \c A<::next> with \c fieldDecl(...) matching
 /// \c B::next
 AST_MATCHER_P(TemplateArgument, refersToDeclaration,
@@ -899,8 +899,8 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
-///   struct B { B* next; };
+///   struct B { int next; };
+///   template struct A {};
 ///   A<::next> a;
 /// \endcode
 /// templateSpecializationType(hasAnyTemplateArgument(
@@ -917,7 +917,7 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
+///   template struct C {};
 ///   C<42> c;
 /// \endcode
 /// classTemplateSpecializationDecl(
@@ -932,7 +932,7 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
+///   template struct C {};
 ///   C<42> c;
 /// \endcode
 /// classTemplateSpecializationDecl(
@@ -953,7 +953,7 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
+///   template struct C {};
 ///   C<42> c;
 /// \endcode
 /// classTemplateSpecializationDecl(
@@ -1523,12 +1523,12 @@
 /// \code
 ///   T u(f());
 ///   g(f());
-/// \endcode
-/// but does not match
-/// \code
-///   f();
 ///   f().func();
 /// \endcode
+/// but does not match
+/// \code
+///   f();
+/// \endcode
 extern const internal::VariadicDynCastAllOfMatcher
 materializeTemporaryExpr;
@@ -1789,7 +1789,7 @@
 ///   switch(a) { case 42: break; default: break; }
 /// \endcode
 /// switchStmt()
-///   matches 'switch(a)'.
+///   matches 'switch(a) {'.
 extern const internal::VariadicDynCastAllOfMatcher switchStmt;
 
 /// \brief Matches case and default statements inside switch statements.
@@ -1799,7 +1799,7 @@
 ///   switch(a) { case 42: break; default: break; }
 /// \endcode
 /// switchCase()
-///   matches 'case 42: break;' and 'default: break;'.
+///   matches 'case 42:' and 'default:'.
 extern const internal::VariadicDynCastAllOfMatcher switchCase;
 
 /// \brief Matches case statements inside switch statements.
@@ -1809,7 +1809,7 @@
 ///   switch(a) { case 42: break; default: break; }
 /// \endcode
 /// caseStmt()
-///   matches 'case 42: break;'.
+///   matches 'case 42:'.
 extern const internal::VariadicDynCastAllOfMatcher caseStmt;
 
 /// \brief Matches default statements inside switch statements.
@@ -1819,13 +1819,13 @@
 ///   switch(a) { case 42: break; default: break; }
 /// \endcode
 /// defaultStmt()
-///   matches 'default: break;'.
+///   matches 'default:'.
 extern const internal::VariadicDynCastAllOfMatcher
 defaultStmt;
 
 /// \brief Matches compound statements.
 ///
-/// Example matches '{}' and '{{}}'in 'for (;;) {{}}'
+/// Example matches '{}' and '{{}}' in 'for (;;) {{}}'
 /// \code
 ///   for (;;) {{}}
 /// \endcode
@@ -1838,7 +1838,7 @@
 ///   try {} catch(int i) {}
 /// \endcode
 /// cxxCatchStmt()
-///   matches 'catch(int i)'
+///   matches 'catch(int i) {}'
 extern const internal::VariadicDynCastAllOfMatcher
 cxxCatchStmt;
 
@@ -1848,7 +1848,7 @@
 ///   try {} catch(int i) {}
 /// \endcode
 /// cxxTryStmt()
-///   matches 'try {}'
+///   matches 'try {} catch(int i) {}'
 extern const internal::VariadicDynCastAllOfMatcher cxxTryStmt;
 
 /// \brief Matches throw expressions.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41938: [Analyzer] SValBuilder Comparison Rearrangement (with Restrictions and Analyzer Option)

2018-01-18 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added inline comments.



Comment at: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h:597
+  // than or equal to the quarter of the maximum value of that type.
+  bool shouldAggressivelySimplifyRelationalComparison();
+

High level comment: can you list all [[ https://en.wikipedia.org/wiki/Rewriting 
| rewriting ]] rules you are applying in a formula explicitly in a comment?
From the phabricator discussion I see that you are applying
```
A + n >= B + m -> A - B >= n + m // A, B symbolic, n and m are integers
```

but from the code it seems that you are applying more canonicalization rules?



Comment at: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:317
+// with simpler symbols on every recursive call.
+static bool isOverflowClampedBy4(SymbolRef Sym, ProgramStateRef State) {
+  SValBuilder  = State->getStateManager().getSValBuilder();

Can we have a better function name here? I can't think of one straight away, 
but "clamped" is not very self-descriptive. `isWithinConstantOverflowBounds`?



Comment at: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:326
+
+  llvm::APSInt Max = AT.getMaxValue() >> 2; // Divide by 4.
+  SVal IsCappedFromAbove =

Would just division produce the same result? Also probably it's better to make 
"4" a constant, at least with `#define`



Comment at: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:330
+  nonloc::ConcreteInt(Max), SVB.getConditionType());
+  if (auto DV = IsCappedFromAbove.getAs()) {
+if (State->assume(*DV, false))

6 lines of branching is probably better expressed as

```
if (!isa(IsCappedFromAbove) || 
State->assume(*dyn_cast(IsCappedFromAbove), false))
   return false
```



Comment at: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:337
+
+  llvm::APSInt Min = -Max;
+  SVal IsCappedFromBelow =

326-335 duplicates 338-346.
Perhaps we could have

```
static bool isCappedFrom(bool Above, llvm::APSInt bound, ...)
```

?



Comment at: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:352
+// Same for the concrete integers: see if I is within [min/4, max/4].
+static bool isOverflowClampedBy4(llvm::APSInt I) {
+  APSIntType AT(I);

Again, could we do better with a function name?



Comment at: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:357
+
+  llvm::APSInt Max = AT.getMaxValue() >> 2;
+  if (I > Max)

I think you want

```
return (I <= Max) && (I >= -Max)
```

instead of 358-365



Comment at: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:376
+  // Fail to decompose: "reduce" the problem to the "$x + 0" case.
+  return std::make_tuple(Sym, BO_Add, BV.getValue(0, Sym->getType()));
+}

Is it beneficial to do this though? At the point where `decomposeSymbol` is 
called we are still checking whether the rearrangement could be performed, so 
maybe just returning a false flag would be better?



Comment at: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:403
+  if (LOp == BO_Sub)
+LInt = -LInt;
+  else

I think this is a separate rewrite, which is better performed in a separate 
function.
If you move it to `decomposeSymbol` or to a separate function, you would get a 
lot of simplifications:

1. This function would be performing only a single rewrite.
2. You would no longer need to take `Lop` and `Rop` as parameters
3. At that point, two separate cases would be clearly seen: `Op` is a 
comparison operator, or `Op` is an additive operator.
I would separate those two rewrites in separate functions, distinguishing 
between them at the callsite.



Comment at: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:429
+  if (BinaryOperator::isComparisonOp(Op)) {
+// Prefer comparing to a non-negative number.
+// FIXME: Maybe it'd be better to have consistency in

It seems that having a concrete positive RHS is a part of your rewrite rule. In 
that case, that should be documented in a high-level overview of the rewrite 
rules.



Comment at: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:432
+// "$x - $y" vs. "$y - $x" because those are solver's keys.
+if (LInt > RInt) {
+  ResultSym = SymMgr.getSymSymExpr(RSym, BO_Sub, LSym, SymTy);

I think this could be shortened and made more explicit by constructing the LHS 
and RHS first, and then reversing both and the comparison operator if RHS is 
negative.



Comment at: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:472
+  if (BinaryOperator::isComparisonOp(Op) &&
+  Opts.shouldAggressivelySimplifyRelationalComparison()) {
+if (ResultTy != SVB.getConditionType())

I am confused why the option `shouldAggressivelySimplifyRelationalComparison` 
is checked here. Do we rewrite cases where `Op` is 

[libclc] r322897 - half_sin: Implement using sin

2018-01-18 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Thu Jan 18 13:12:01 2018
New Revision: 322897

URL: http://llvm.org/viewvc/llvm-project?rev=322897=rev
Log:
half_sin: Implement using sin

Passes CTS on carrizo
v2: Use full precision implementation

Reviewer: Jeroen Ketema 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/generic/include/clc/math/half_sin.h
libclc/trunk/generic/lib/math/half_sin.cl
Modified:
libclc/trunk/generic/include/clc/clc.h
libclc/trunk/generic/lib/SOURCES

Modified: libclc/trunk/generic/include/clc/clc.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=322897=322896=322897=diff
==
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Thu Jan 18 13:12:01 2018
@@ -79,6 +79,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 

Added: libclc/trunk/generic/include/clc/math/half_sin.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/half_sin.h?rev=322897=auto
==
--- libclc/trunk/generic/include/clc/math/half_sin.h (added)
+++ libclc/trunk/generic/include/clc/math/half_sin.h Thu Jan 18 13:12:01 2018
@@ -0,0 +1,9 @@
+#define __CLC_BODY 
+#define __CLC_FUNCTION half_sin
+#define __FLOAT_ONLY
+
+#include 
+
+#undef __FLOAT_ONLY
+#undef __CLC_BODY
+#undef __CLC_FUNCTION

Modified: libclc/trunk/generic/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=322897=322896=322897=diff
==
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Thu Jan 18 13:12:01 2018
@@ -113,6 +113,7 @@ math/half_log10.cl
 math/half_log2.cl
 math/half_recip.cl
 math/half_rsqrt.cl
+math/half_sin.cl
 math/half_sqrt.cl
 math/hypot.cl
 math/ilogb.cl

Added: libclc/trunk/generic/lib/math/half_sin.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/half_sin.cl?rev=322897=auto
==
--- libclc/trunk/generic/lib/math/half_sin.cl (added)
+++ libclc/trunk/generic/lib/math/half_sin.cl Thu Jan 18 13:12:01 2018
@@ -0,0 +1,6 @@
+#include 
+
+#define __CLC_FUNC sin
+#define __CLC_BODY 
+#define __FLOAT_ONLY
+#include 


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


[libclc] r322899 - half_divide: Implement using x/y

2018-01-18 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Thu Jan 18 13:12:06 2018
New Revision: 322899

URL: http://llvm.org/viewvc/llvm-project?rev=322899=rev
Log:
half_divide: Implement using x/y

Passes CTS on carrizo
v2: Use full precision implementation

Reviewer: Jeroen Ketema 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/generic/include/clc/math/half_divide.h
libclc/trunk/generic/lib/math/half_binary.inc
libclc/trunk/generic/lib/math/half_divide.cl
Modified:
libclc/trunk/generic/include/clc/clc.h
libclc/trunk/generic/lib/SOURCES

Modified: libclc/trunk/generic/include/clc/clc.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=322899=322898=322899=diff
==
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Thu Jan 18 13:12:06 2018
@@ -71,6 +71,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 

Added: libclc/trunk/generic/include/clc/math/half_divide.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/half_divide.h?rev=322899=auto
==
--- libclc/trunk/generic/include/clc/math/half_divide.h (added)
+++ libclc/trunk/generic/include/clc/math/half_divide.h Thu Jan 18 13:12:06 2018
@@ -0,0 +1,7 @@
+#define __CLC_BODY 
+#define __CLC_FUNCTION half_divide
+
+#include 
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION

Modified: libclc/trunk/generic/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=322899=322898=322899=diff
==
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Thu Jan 18 13:12:06 2018
@@ -105,6 +105,7 @@ math/fmod.cl
 math/fract.cl
 math/frexp.cl
 math/half_cos.cl
+math/half_divide.cl
 math/half_exp.cl
 math/half_exp10.cl
 math/half_exp2.cl

Added: libclc/trunk/generic/lib/math/half_binary.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/half_binary.inc?rev=322899=auto
==
--- libclc/trunk/generic/lib/math/half_binary.inc (added)
+++ libclc/trunk/generic/lib/math/half_binary.inc Thu Jan 18 13:12:06 2018
@@ -0,0 +1,9 @@
+#include 
+
+#define __CLC_HALF_FUNC(x) __CLC_CONCAT(half_, x)
+
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_HALF_FUNC(__CLC_FUNC)(__CLC_GENTYPE 
x, __CLC_GENTYPE y) {
+  return __CLC_FUNC(x, y);
+}
+
+#undef __CLC_HALF_FUNC

Added: libclc/trunk/generic/lib/math/half_divide.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/half_divide.cl?rev=322899=auto
==
--- libclc/trunk/generic/lib/math/half_divide.cl (added)
+++ libclc/trunk/generic/lib/math/half_divide.cl Thu Jan 18 13:12:06 2018
@@ -0,0 +1,9 @@
+#include 
+
+#define divide(x,y) (x/y)
+
+#define __CLC_FUNC divide
+#define __CLC_BODY 
+#define __FLOAT_ONLY
+#include 
+#undef divide


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


[libclc] r322898 - half_tan: Implement using tan

2018-01-18 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Thu Jan 18 13:12:04 2018
New Revision: 322898

URL: http://llvm.org/viewvc/llvm-project?rev=322898=rev
Log:
half_tan: Implement using tan

v2: Use full precision implementation

Reviewer: Jeroen Ketema 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/generic/include/clc/math/half_tan.h
libclc/trunk/generic/lib/math/half_tan.cl
Modified:
libclc/trunk/generic/include/clc/clc.h
libclc/trunk/generic/lib/SOURCES

Modified: libclc/trunk/generic/include/clc/clc.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=322898=322897=322898=diff
==
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Thu Jan 18 13:12:04 2018
@@ -81,6 +81,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 

Added: libclc/trunk/generic/include/clc/math/half_tan.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/half_tan.h?rev=322898=auto
==
--- libclc/trunk/generic/include/clc/math/half_tan.h (added)
+++ libclc/trunk/generic/include/clc/math/half_tan.h Thu Jan 18 13:12:04 2018
@@ -0,0 +1,9 @@
+#define __CLC_BODY 
+#define __CLC_FUNCTION half_tan
+#define __FLOAT_ONLY
+
+#include 
+
+#undef __FLOAT_ONLY
+#undef __CLC_BODY
+#undef __CLC_FUNCTION

Modified: libclc/trunk/generic/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=322898=322897=322898=diff
==
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Thu Jan 18 13:12:04 2018
@@ -115,6 +115,7 @@ math/half_recip.cl
 math/half_rsqrt.cl
 math/half_sin.cl
 math/half_sqrt.cl
+math/half_tan.cl
 math/hypot.cl
 math/ilogb.cl
 math/clc_ldexp.cl

Added: libclc/trunk/generic/lib/math/half_tan.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/half_tan.cl?rev=322898=auto
==
--- libclc/trunk/generic/lib/math/half_tan.cl (added)
+++ libclc/trunk/generic/lib/math/half_tan.cl Thu Jan 18 13:12:04 2018
@@ -0,0 +1,6 @@
+#include 
+
+#define __CLC_FUNC tan
+#define __CLC_BODY 
+#define __FLOAT_ONLY
+#include 


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


[libclc] r322893 - half_log: Implement using log

2018-01-18 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Thu Jan 18 13:11:50 2018
New Revision: 322893

URL: http://llvm.org/viewvc/llvm-project?rev=322893=rev
Log:
half_log: Implement using log

Passes CTS on carrizo
v2: Use full precision implementation

Reviewer: Jeroen Ketema 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/generic/include/clc/math/half_log.h
libclc/trunk/generic/lib/math/half_log.cl
Modified:
libclc/trunk/generic/include/clc/clc.h
libclc/trunk/generic/lib/SOURCES

Modified: libclc/trunk/generic/include/clc/clc.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=322893=322892=322893=diff
==
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Thu Jan 18 13:11:50 2018
@@ -74,6 +74,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 

Added: libclc/trunk/generic/include/clc/math/half_log.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/half_log.h?rev=322893=auto
==
--- libclc/trunk/generic/include/clc/math/half_log.h (added)
+++ libclc/trunk/generic/include/clc/math/half_log.h Thu Jan 18 13:11:50 2018
@@ -0,0 +1,9 @@
+#define __CLC_BODY 
+#define __CLC_FUNCTION half_log
+#define __FLOAT_ONLY
+
+#include 
+
+#undef __FLOAT_ONLY
+#undef __CLC_BODY
+#undef __CLC_FUNCTION

Modified: libclc/trunk/generic/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=322893=322892=322893=diff
==
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Thu Jan 18 13:11:50 2018
@@ -108,6 +108,7 @@ math/half_cos.cl
 math/half_exp.cl
 math/half_exp10.cl
 math/half_exp2.cl
+math/half_log.cl
 math/half_rsqrt.cl
 math/half_sqrt.cl
 math/hypot.cl

Added: libclc/trunk/generic/lib/math/half_log.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/half_log.cl?rev=322893=auto
==
--- libclc/trunk/generic/lib/math/half_log.cl (added)
+++ libclc/trunk/generic/lib/math/half_log.cl Thu Jan 18 13:11:50 2018
@@ -0,0 +1,6 @@
+#include 
+
+#define __CLC_FUNC log
+#define __CLC_BODY 
+#define __FLOAT_ONLY
+#include 


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


[libclc] r322896 - half_recip: Implement using 1/x

2018-01-18 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Thu Jan 18 13:11:58 2018
New Revision: 322896

URL: http://llvm.org/viewvc/llvm-project?rev=322896=rev
Log:
half_recip: Implement using 1/x

Passes CTS on carrizo
v2: Use full precision implementation

Reviewer: Jeroen Ketema 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/generic/include/clc/math/half_recip.h
libclc/trunk/generic/lib/math/half_recip.cl
Modified:
libclc/trunk/generic/include/clc/clc.h
libclc/trunk/generic/lib/SOURCES

Modified: libclc/trunk/generic/include/clc/clc.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=322896=322895=322896=diff
==
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Thu Jan 18 13:11:58 2018
@@ -77,6 +77,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 

Added: libclc/trunk/generic/include/clc/math/half_recip.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/half_recip.h?rev=322896=auto
==
--- libclc/trunk/generic/include/clc/math/half_recip.h (added)
+++ libclc/trunk/generic/include/clc/math/half_recip.h Thu Jan 18 13:11:58 2018
@@ -0,0 +1,9 @@
+#define __CLC_BODY 
+#define __CLC_FUNCTION half_recip
+#define __FLOAT_ONLY
+
+#include 
+
+#undef __FLOAT_ONLY
+#undef __CLC_BODY
+#undef __CLC_FUNCTION

Modified: libclc/trunk/generic/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=322896=322895=322896=diff
==
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Thu Jan 18 13:11:58 2018
@@ -111,6 +111,7 @@ math/half_exp2.cl
 math/half_log.cl
 math/half_log10.cl
 math/half_log2.cl
+math/half_recip.cl
 math/half_rsqrt.cl
 math/half_sqrt.cl
 math/hypot.cl

Added: libclc/trunk/generic/lib/math/half_recip.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/half_recip.cl?rev=322896=auto
==
--- libclc/trunk/generic/lib/math/half_recip.cl (added)
+++ libclc/trunk/generic/lib/math/half_recip.cl Thu Jan 18 13:11:58 2018
@@ -0,0 +1,10 @@
+#include 
+
+#define recip(x) (1.0f/x)
+
+#define __CLC_FUNC recip
+#define __CLC_BODY 
+#define __FLOAT_ONLY
+#include 
+
+#undef recip


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


[libclc] r322894 - half_log10: Implement using log10

2018-01-18 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Thu Jan 18 13:11:53 2018
New Revision: 322894

URL: http://llvm.org/viewvc/llvm-project?rev=322894=rev
Log:
half_log10: Implement using log10

Passes CTS on carrizo
v2: Use full precision implementation

Reviewer: Jeroen Ketema 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/generic/include/clc/math/half_log10.h
libclc/trunk/generic/lib/math/half_log10.cl
Modified:
libclc/trunk/generic/include/clc/clc.h
libclc/trunk/generic/lib/SOURCES

Modified: libclc/trunk/generic/include/clc/clc.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=322894=322893=322894=diff
==
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Thu Jan 18 13:11:53 2018
@@ -75,6 +75,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 

Added: libclc/trunk/generic/include/clc/math/half_log10.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/half_log10.h?rev=322894=auto
==
--- libclc/trunk/generic/include/clc/math/half_log10.h (added)
+++ libclc/trunk/generic/include/clc/math/half_log10.h Thu Jan 18 13:11:53 2018
@@ -0,0 +1,9 @@
+#define __CLC_BODY 
+#define __CLC_FUNCTION half_log10
+#define __FLOAT_ONLY
+
+#include 
+
+#undef __FLOAT_ONLY
+#undef __CLC_BODY
+#undef __CLC_FUNCTION

Modified: libclc/trunk/generic/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=322894=322893=322894=diff
==
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Thu Jan 18 13:11:53 2018
@@ -109,6 +109,7 @@ math/half_exp.cl
 math/half_exp10.cl
 math/half_exp2.cl
 math/half_log.cl
+math/half_log10.cl
 math/half_rsqrt.cl
 math/half_sqrt.cl
 math/hypot.cl

Added: libclc/trunk/generic/lib/math/half_log10.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/half_log10.cl?rev=322894=auto
==
--- libclc/trunk/generic/lib/math/half_log10.cl (added)
+++ libclc/trunk/generic/lib/math/half_log10.cl Thu Jan 18 13:11:53 2018
@@ -0,0 +1,6 @@
+#include 
+
+#define __CLC_FUNC log10
+#define __CLC_BODY 
+#define __FLOAT_ONLY
+#include 


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


[libclc] r322895 - half_log2: Implement using log2

2018-01-18 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Thu Jan 18 13:11:56 2018
New Revision: 322895

URL: http://llvm.org/viewvc/llvm-project?rev=322895=rev
Log:
half_log2: Implement using log2

Passes CTS on carrizo
v2: Use full precision implementation

Reviewer: Jeroen Ketema 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/generic/include/clc/math/half_log2.h
libclc/trunk/generic/lib/math/half_log2.cl
Modified:
libclc/trunk/generic/include/clc/clc.h
libclc/trunk/generic/lib/SOURCES

Modified: libclc/trunk/generic/include/clc/clc.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=322895=322894=322895=diff
==
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Thu Jan 18 13:11:56 2018
@@ -76,6 +76,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 

Added: libclc/trunk/generic/include/clc/math/half_log2.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/half_log2.h?rev=322895=auto
==
--- libclc/trunk/generic/include/clc/math/half_log2.h (added)
+++ libclc/trunk/generic/include/clc/math/half_log2.h Thu Jan 18 13:11:56 2018
@@ -0,0 +1,9 @@
+#define __CLC_BODY 
+#define __CLC_FUNCTION half_log2
+#define __FLOAT_ONLY
+
+#include 
+
+#undef __FLOAT_ONLY
+#undef __CLC_BODY
+#undef __CLC_FUNCTION

Modified: libclc/trunk/generic/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=322895=322894=322895=diff
==
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Thu Jan 18 13:11:56 2018
@@ -110,6 +110,7 @@ math/half_exp10.cl
 math/half_exp2.cl
 math/half_log.cl
 math/half_log10.cl
+math/half_log2.cl
 math/half_rsqrt.cl
 math/half_sqrt.cl
 math/hypot.cl

Added: libclc/trunk/generic/lib/math/half_log2.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/half_log2.cl?rev=322895=auto
==
--- libclc/trunk/generic/lib/math/half_log2.cl (added)
+++ libclc/trunk/generic/lib/math/half_log2.cl Thu Jan 18 13:11:56 2018
@@ -0,0 +1,6 @@
+#include 
+
+#define __CLC_FUNC log2
+#define __CLC_BODY 
+#define __FLOAT_ONLY
+#include 


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


[libclc] r322890 - half_exp: Implement using exp

2018-01-18 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Thu Jan 18 13:11:43 2018
New Revision: 322890

URL: http://llvm.org/viewvc/llvm-project?rev=322890=rev
Log:
half_exp: Implement using exp

Passes CTS on carrizo
v2: Use full precision implementation

Reviewer: Jeroen Ketema 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/generic/include/clc/math/half_exp.h
libclc/trunk/generic/lib/math/half_exp.cl
Modified:
libclc/trunk/generic/include/clc/clc.h
libclc/trunk/generic/lib/SOURCES

Modified: libclc/trunk/generic/include/clc/clc.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=322890=322889=322890=diff
==
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Thu Jan 18 13:11:43 2018
@@ -71,6 +71,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 

Added: libclc/trunk/generic/include/clc/math/half_exp.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/half_exp.h?rev=322890=auto
==
--- libclc/trunk/generic/include/clc/math/half_exp.h (added)
+++ libclc/trunk/generic/include/clc/math/half_exp.h Thu Jan 18 13:11:43 2018
@@ -0,0 +1,9 @@
+#define __CLC_BODY 
+#define __CLC_FUNCTION half_exp
+#define __FLOAT_ONLY
+
+#include 
+
+#undef __FLOAT_ONLY
+#undef __CLC_BODY
+#undef __CLC_FUNCTION

Modified: libclc/trunk/generic/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=322890=322889=322890=diff
==
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Thu Jan 18 13:11:43 2018
@@ -105,6 +105,7 @@ math/fmod.cl
 math/fract.cl
 math/frexp.cl
 math/half_cos.cl
+math/half_exp.cl
 math/half_rsqrt.cl
 math/half_sqrt.cl
 math/hypot.cl

Added: libclc/trunk/generic/lib/math/half_exp.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/half_exp.cl?rev=322890=auto
==
--- libclc/trunk/generic/lib/math/half_exp.cl (added)
+++ libclc/trunk/generic/lib/math/half_exp.cl Thu Jan 18 13:11:43 2018
@@ -0,0 +1,6 @@
+#include 
+
+#define __CLC_FUNC exp
+#define __CLC_BODY 
+#define __FLOAT_ONLY
+#include 


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


[libclc] r322892 - half_exp10: Implement using exp10

2018-01-18 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Thu Jan 18 13:11:48 2018
New Revision: 322892

URL: http://llvm.org/viewvc/llvm-project?rev=322892=rev
Log:
half_exp10: Implement using exp10

Passes CTS on carrizo
v2: Use full precision implementation

Reviewer: Jeroen Ketema 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/generic/include/clc/math/half_exp10.h
libclc/trunk/generic/lib/math/half_exp10.cl
Modified:
libclc/trunk/generic/include/clc/clc.h
libclc/trunk/generic/lib/SOURCES

Modified: libclc/trunk/generic/include/clc/clc.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=322892=322891=322892=diff
==
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Thu Jan 18 13:11:48 2018
@@ -72,6 +72,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 

Added: libclc/trunk/generic/include/clc/math/half_exp10.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/half_exp10.h?rev=322892=auto
==
--- libclc/trunk/generic/include/clc/math/half_exp10.h (added)
+++ libclc/trunk/generic/include/clc/math/half_exp10.h Thu Jan 18 13:11:48 2018
@@ -0,0 +1,9 @@
+#define __CLC_BODY 
+#define __CLC_FUNCTION half_exp10
+#define __FLOAT_ONLY
+
+#include 
+
+#undef __FLOAT_ONLY
+#undef __CLC_BODY
+#undef __CLC_FUNCTION

Modified: libclc/trunk/generic/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=322892=322891=322892=diff
==
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Thu Jan 18 13:11:48 2018
@@ -106,6 +106,7 @@ math/fract.cl
 math/frexp.cl
 math/half_cos.cl
 math/half_exp.cl
+math/half_exp10.cl
 math/half_exp2.cl
 math/half_rsqrt.cl
 math/half_sqrt.cl

Added: libclc/trunk/generic/lib/math/half_exp10.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/half_exp10.cl?rev=322892=auto
==
--- libclc/trunk/generic/lib/math/half_exp10.cl (added)
+++ libclc/trunk/generic/lib/math/half_exp10.cl Thu Jan 18 13:11:48 2018
@@ -0,0 +1,6 @@
+#include 
+
+#define __CLC_FUNC exp10
+#define __CLC_BODY 
+#define __FLOAT_ONLY
+#include 


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


[libclc] r322889 - half_cos: Implement using cos

2018-01-18 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Thu Jan 18 13:11:40 2018
New Revision: 322889

URL: http://llvm.org/viewvc/llvm-project?rev=322889=rev
Log:
half_cos: Implement using cos

Passes CTS on carrizo
v2: Use full precision implementation

Reviewer: Jeroen Ketema 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/generic/include/clc/math/half_cos.h
libclc/trunk/generic/lib/math/half_cos.cl
Modified:
libclc/trunk/generic/include/clc/clc.h
libclc/trunk/generic/lib/SOURCES

Modified: libclc/trunk/generic/include/clc/clc.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=322889=322888=322889=diff
==
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Thu Jan 18 13:11:40 2018
@@ -70,6 +70,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 

Added: libclc/trunk/generic/include/clc/math/half_cos.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/half_cos.h?rev=322889=auto
==
--- libclc/trunk/generic/include/clc/math/half_cos.h (added)
+++ libclc/trunk/generic/include/clc/math/half_cos.h Thu Jan 18 13:11:40 2018
@@ -0,0 +1,9 @@
+#define __CLC_BODY 
+#define __CLC_FUNCTION half_cos
+#define __FLOAT_ONLY
+
+#include 
+
+#undef __FLOAT_ONLY
+#undef __CLC_BODY
+#undef __CLC_FUNCTION

Modified: libclc/trunk/generic/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=322889=322888=322889=diff
==
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Thu Jan 18 13:11:40 2018
@@ -104,6 +104,7 @@ math/fmin.cl
 math/fmod.cl
 math/fract.cl
 math/frexp.cl
+math/half_cos.cl
 math/half_rsqrt.cl
 math/half_sqrt.cl
 math/hypot.cl

Added: libclc/trunk/generic/lib/math/half_cos.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/half_cos.cl?rev=322889=auto
==
--- libclc/trunk/generic/lib/math/half_cos.cl (added)
+++ libclc/trunk/generic/lib/math/half_cos.cl Thu Jan 18 13:11:40 2018
@@ -0,0 +1,6 @@
+#include 
+
+#define __CLC_FUNC cos
+#define __CLC_BODY 
+#define __FLOAT_ONLY
+#include 


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


[libclc] r322891 - half_exp2: Implement using exp2

2018-01-18 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Thu Jan 18 13:11:45 2018
New Revision: 322891

URL: http://llvm.org/viewvc/llvm-project?rev=322891=rev
Log:
half_exp2: Implement using exp2

Passes CTS on carrizo
v2: Use full precision implementation

Reviewer: Jeroen Ketema 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/generic/include/clc/math/half_exp2.h
libclc/trunk/generic/lib/math/half_exp2.cl
Modified:
libclc/trunk/generic/include/clc/clc.h
libclc/trunk/generic/lib/SOURCES

Modified: libclc/trunk/generic/include/clc/clc.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=322891=322890=322891=diff
==
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Thu Jan 18 13:11:45 2018
@@ -72,6 +72,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 

Added: libclc/trunk/generic/include/clc/math/half_exp2.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/half_exp2.h?rev=322891=auto
==
--- libclc/trunk/generic/include/clc/math/half_exp2.h (added)
+++ libclc/trunk/generic/include/clc/math/half_exp2.h Thu Jan 18 13:11:45 2018
@@ -0,0 +1,9 @@
+#define __CLC_BODY 
+#define __CLC_FUNCTION half_exp2
+#define __FLOAT_ONLY
+
+#include 
+
+#undef __FLOAT_ONLY
+#undef __CLC_BODY
+#undef __CLC_FUNCTION

Modified: libclc/trunk/generic/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=322891=322890=322891=diff
==
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Thu Jan 18 13:11:45 2018
@@ -106,6 +106,7 @@ math/fract.cl
 math/frexp.cl
 math/half_cos.cl
 math/half_exp.cl
+math/half_exp2.cl
 math/half_rsqrt.cl
 math/half_sqrt.cl
 math/hypot.cl

Added: libclc/trunk/generic/lib/math/half_exp2.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/half_exp2.cl?rev=322891=auto
==
--- libclc/trunk/generic/lib/math/half_exp2.cl (added)
+++ libclc/trunk/generic/lib/math/half_exp2.cl Thu Jan 18 13:11:45 2018
@@ -0,0 +1,6 @@
+#include 
+
+#define __CLC_FUNC exp2
+#define __CLC_BODY 
+#define __FLOAT_ONLY
+#include 


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


[libclc] r322887 - half_rsqrt: Cleanup implementation

2018-01-18 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Thu Jan 18 13:11:35 2018
New Revision: 322887

URL: http://llvm.org/viewvc/llvm-project?rev=322887=rev
Log:
half_rsqrt: Cleanup implementation

Passes CTS on carrizo
v2: Use full precision implementation

Reviewer: Jeroen Ketema 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/generic/lib/math/half_unary.inc
Removed:
libclc/trunk/generic/lib/math/half_rsqrt.inc
Modified:
libclc/trunk/generic/include/clc/math/half_rsqrt.h
libclc/trunk/generic/lib/math/half_rsqrt.cl

Modified: libclc/trunk/generic/include/clc/math/half_rsqrt.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/half_rsqrt.h?rev=322887=322886=322887=diff
==
--- libclc/trunk/generic/include/clc/math/half_rsqrt.h (original)
+++ libclc/trunk/generic/include/clc/math/half_rsqrt.h Thu Jan 18 13:11:35 2018
@@ -20,8 +20,6 @@
  * THE SOFTWARE.
  */
 
-#undef half_rsqrt
-
 #define __CLC_BODY 
 #define __CLC_FUNCTION half_rsqrt
 #define __FLOAT_ONLY

Modified: libclc/trunk/generic/lib/math/half_rsqrt.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/half_rsqrt.cl?rev=322887=322886=322887=diff
==
--- libclc/trunk/generic/lib/math/half_rsqrt.cl (original)
+++ libclc/trunk/generic/lib/math/half_rsqrt.cl Thu Jan 18 13:11:35 2018
@@ -1,28 +1,6 @@
-/*
- * Copyright (c) 2014,2015 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to 
deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
 #include 
 
-#define __CLC_BODY 
+#define __CLC_FUNC rsqrt
+#define __CLC_BODY 
 #define __FLOAT_ONLY
 #include 
-#undef __FLOAT_ONLY

Removed: libclc/trunk/generic/lib/math/half_rsqrt.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/half_rsqrt.inc?rev=322886=auto
==
--- libclc/trunk/generic/lib/math/half_rsqrt.inc (original)
+++ libclc/trunk/generic/lib/math/half_rsqrt.inc (removed)
@@ -1,25 +0,0 @@
-/*
- * Copyright (c) 2014,2015 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to 
deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE half_rsqrt(__CLC_GENTYPE val) {
-  return rsqrt(val);
-}

Added: libclc/trunk/generic/lib/math/half_unary.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/half_unary.inc?rev=322887=auto
==
--- libclc/trunk/generic/lib/math/half_unary.inc (added)
+++ libclc/trunk/generic/lib/math/half_unary.inc Thu Jan 18 13:11:35 2018
@@ -0,0 +1,9 @@
+#include 
+
+#define __CLC_HALF_FUNC(x) __CLC_CONCAT(half_, x)
+
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE __CLC_HALF_FUNC(__CLC_FUNC)(__CLC_GENTYPE 
val) {
+  return __CLC_FUNC(val);
+}
+

[libclc] r322888 - half_sqrt: Cleanup implementation

2018-01-18 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Thu Jan 18 13:11:38 2018
New Revision: 322888

URL: http://llvm.org/viewvc/llvm-project?rev=322888=rev
Log:
half_sqrt: Cleanup implementation

Passes CTS on carrizo
v2: Use full precision implementation

Reviewer: Jeroen Ketema 
Signed-off-by: Jan Vesely 

Removed:
libclc/trunk/generic/lib/math/half_sqrt.inc
Modified:
libclc/trunk/generic/include/clc/math/half_sqrt.h
libclc/trunk/generic/lib/math/half_sqrt.cl

Modified: libclc/trunk/generic/include/clc/math/half_sqrt.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/half_sqrt.h?rev=322888=322887=322888=diff
==
--- libclc/trunk/generic/include/clc/math/half_sqrt.h (original)
+++ libclc/trunk/generic/include/clc/math/half_sqrt.h Thu Jan 18 13:11:38 2018
@@ -20,8 +20,6 @@
  * THE SOFTWARE.
  */
 
-#undef half_sqrt
-
 #define __CLC_BODY 
 #define __CLC_FUNCTION half_sqrt
 #define __FLOAT_ONLY

Modified: libclc/trunk/generic/lib/math/half_sqrt.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/half_sqrt.cl?rev=322888=322887=322888=diff
==
--- libclc/trunk/generic/lib/math/half_sqrt.cl (original)
+++ libclc/trunk/generic/lib/math/half_sqrt.cl Thu Jan 18 13:11:38 2018
@@ -1,28 +1,6 @@
-/*
- * Copyright (c) 2014,2015 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to 
deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
 #include 
 
-#define __CLC_BODY 
+#define __CLC_FUNC sqrt
+#define __CLC_BODY 
 #define __FLOAT_ONLY
 #include 
-#undef __FLOAT_ONLY

Removed: libclc/trunk/generic/lib/math/half_sqrt.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/half_sqrt.inc?rev=322887=auto
==
--- libclc/trunk/generic/lib/math/half_sqrt.inc (original)
+++ libclc/trunk/generic/lib/math/half_sqrt.inc (removed)
@@ -1,25 +0,0 @@
-/*
- * Copyright (c) 2014,2015 Advanced Micro Devices, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to 
deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE half_sqrt(__CLC_GENTYPE val) {
-  return sqrt(val);
-}


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


[PATCH] D41746: Make std::get_temporary_buffer respect overaligned types when possible

2018-01-18 Thread Chris Kennelly via Phabricator via cfe-commits
ckennelly marked an inline comment as done.
ckennelly added a comment.

I don't have commit access, so can this be committed to trunk?


Repository:
  rCXX libc++

https://reviews.llvm.org/D41746



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


[PATCH] D42253: [clang-tidy objc-property-declaration] Expand list of ObjC acronyms

2018-01-18 Thread Ben Hamilton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322886: [clang-tidy objc-property-declaration] Expand list 
of ObjC acronyms (authored by benhamilton, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D42253

Files:
  clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
  clang-tools-extra/trunk/docs/clang-tidy/checks/objc-property-declaration.rst
  clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m

Index: clang-tools-extra/trunk/docs/clang-tidy/checks/objc-property-declaration.rst
===
--- clang-tools-extra/trunk/docs/clang-tidy/checks/objc-property-declaration.rst
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/objc-property-declaration.rst
@@ -23,8 +23,8 @@
 only provide warning messages since the property name could be complicated.
 Users will need to come up with a proper name by their own.
 
-This check also accepts special acronyms as prefix. Such prefix will suppress
-the check of Lower Camel Case according to the guide:
+This check also accepts special acronyms as prefixes or suffixes. Such prefixes or suffixes
+will suppress the Lower Camel Case check according to the guide:
 https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingBasics.html#//apple_ref/doc/uid/20001281-1002931-BBCFHEAB
 
 For a full list of well-known acronyms:
@@ -37,7 +37,7 @@
 
 .. option:: Acronyms
 
-   Semicolon-separated list of acronyms that can be used as prefix
-   of property names.
+   Semicolon-separated list of acronyms that can be used as a prefix
+   or a suffix of property names.
 
-   Defaults to `ASCII;PDF;XML;HTML;URL;RTF;HTTP;TIFF;JPG;PNG;GIF;LZW;ROM;RGB;CMYK;MIDI;FTP`.
+   If unset, defaults to "ACL;API;ARGB;ASCII;BGRA;CMYK;DNS;FPS;FTP;GIF;GPS;HD;HDR;HTML;HTTP;HTTPS;HUD;ID;JPG;JS;LAN;LZW;MDNS;MIDI;OS;PDF;PIN;PNG;POI;PSTN;PTR;QA;QOS;RGB;RGBA;RGBX;ROM;RPC;RTF;RTL;SDK;SSO;TCP;TIFF;TTS;UI;URI;URL;VC;VOIP;VPN;VR;WAN;XML".
Index: clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
===
--- clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
+++ clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
@@ -1,13 +1,17 @@
 // RUN: %check_clang_tidy %s objc-property-declaration %t
+@class NSData;
 @class NSString;
+@class UIViewController;
 
 @interface Foo
 @property(assign, nonatomic) int NotCamelCase;
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'NotCamelCase' should use lowerCamelCase style, according to the Apple Coding Guidelines [objc-property-declaration]
 // CHECK-FIXES: @property(assign, nonatomic) int notCamelCase;
 @property(assign, nonatomic) int camelCase;
 @property(strong, nonatomic) NSString *URLString;
 @property(strong, nonatomic) NSString *bundleID;
+@property(strong, nonatomic) NSData *RGBABytes;
+@property(strong, nonatomic) UIViewController *notificationsVC;
 @property(strong, nonatomic) NSString *URL_string;
 // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: property name 'URL_string' should use lowerCamelCase style, according to the Apple Coding Guidelines [objc-property-declaration]
 @end
Index: clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -24,25 +24,63 @@
 namespace {
 /// The acronyms are from
 /// https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/APIAbbreviations.html#//apple_ref/doc/uid/20001285-BCIHCGAE
+///
+/// Keep this list sorted.
 constexpr char DefaultSpecialAcronyms[] =
+"ACL;"
+"API;"
+"ARGB;"
 "ASCII;"
-"PDF;"
-"XML;"
+"BGRA;"
+"CMYK;"
+"DNS;"
+"FPS;"
+"FTP;"
+"GIF;"
+"GPS;"
+"HD;"
+"HDR;"
 "HTML;"
-"URL;"
-"RTF;"
 "HTTP;"
-"TIFF;"
+"HTTPS;"
+"HUD;"
+"ID;"
 "JPG;"
-"PNG;"
-"GIF;"
+"JS;"
+"LAN;"
 "LZW;"
-"ROM;"
-"RGB;"
-"CMYK;"
+"MDNS;"
 "MIDI;"
-"FTP;"
-"ID";
+"OS;"
+"PDF;"
+"PIN;"
+"PNG;"
+"POI;"
+"PSTN;"
+"PTR;"
+"QA;"
+"QOS;"
+"RGB;"
+"RGBA;"
+"RGBX;"
+"ROM;"
+"RPC;"
+"RTF;"
+"RTL;"
+"SDK;"
+"SSO;"
+"TCP;"
+"TIFF;"
+"TTS;"
+"UI;"
+"URI;"
+"URL;"
+"VC;"
+"VOIP;"
+"VPN;"
+"VR;"
+"WAN;"
+"XML";
 
 /// For now we will only fix 'CamelCase' property to
 /// 'camelCase'. For other cases the users need to
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42253: [clang-tidy objc-property-declaration] Expand list of ObjC acronyms

2018-01-18 Thread Ben Hamilton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE322886: [clang-tidy objc-property-declaration] Expand list 
of ObjC acronyms (authored by benhamilton, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42253?vs=130478=130480#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D42253

Files:
  clang-tidy/objc/PropertyDeclarationCheck.cpp
  docs/clang-tidy/checks/objc-property-declaration.rst
  test/clang-tidy/objc-property-declaration.m

Index: test/clang-tidy/objc-property-declaration.m
===
--- test/clang-tidy/objc-property-declaration.m
+++ test/clang-tidy/objc-property-declaration.m
@@ -1,13 +1,17 @@
 // RUN: %check_clang_tidy %s objc-property-declaration %t
+@class NSData;
 @class NSString;
+@class UIViewController;
 
 @interface Foo
 @property(assign, nonatomic) int NotCamelCase;
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'NotCamelCase' should use lowerCamelCase style, according to the Apple Coding Guidelines [objc-property-declaration]
 // CHECK-FIXES: @property(assign, nonatomic) int notCamelCase;
 @property(assign, nonatomic) int camelCase;
 @property(strong, nonatomic) NSString *URLString;
 @property(strong, nonatomic) NSString *bundleID;
+@property(strong, nonatomic) NSData *RGBABytes;
+@property(strong, nonatomic) UIViewController *notificationsVC;
 @property(strong, nonatomic) NSString *URL_string;
 // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: property name 'URL_string' should use lowerCamelCase style, according to the Apple Coding Guidelines [objc-property-declaration]
 @end
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -24,25 +24,63 @@
 namespace {
 /// The acronyms are from
 /// https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/APIAbbreviations.html#//apple_ref/doc/uid/20001285-BCIHCGAE
+///
+/// Keep this list sorted.
 constexpr char DefaultSpecialAcronyms[] =
+"ACL;"
+"API;"
+"ARGB;"
 "ASCII;"
-"PDF;"
-"XML;"
+"BGRA;"
+"CMYK;"
+"DNS;"
+"FPS;"
+"FTP;"
+"GIF;"
+"GPS;"
+"HD;"
+"HDR;"
 "HTML;"
-"URL;"
-"RTF;"
 "HTTP;"
-"TIFF;"
+"HTTPS;"
+"HUD;"
+"ID;"
 "JPG;"
-"PNG;"
-"GIF;"
+"JS;"
+"LAN;"
 "LZW;"
-"ROM;"
-"RGB;"
-"CMYK;"
+"MDNS;"
 "MIDI;"
-"FTP;"
-"ID";
+"OS;"
+"PDF;"
+"PIN;"
+"PNG;"
+"POI;"
+"PSTN;"
+"PTR;"
+"QA;"
+"QOS;"
+"RGB;"
+"RGBA;"
+"RGBX;"
+"ROM;"
+"RPC;"
+"RTF;"
+"RTL;"
+"SDK;"
+"SSO;"
+"TCP;"
+"TIFF;"
+"TTS;"
+"UI;"
+"URI;"
+"URL;"
+"VC;"
+"VOIP;"
+"VPN;"
+"VR;"
+"WAN;"
+"XML";
 
 /// For now we will only fix 'CamelCase' property to
 /// 'camelCase'. For other cases the users need to
Index: docs/clang-tidy/checks/objc-property-declaration.rst
===
--- docs/clang-tidy/checks/objc-property-declaration.rst
+++ docs/clang-tidy/checks/objc-property-declaration.rst
@@ -23,8 +23,8 @@
 only provide warning messages since the property name could be complicated.
 Users will need to come up with a proper name by their own.
 
-This check also accepts special acronyms as prefix. Such prefix will suppress
-the check of Lower Camel Case according to the guide:
+This check also accepts special acronyms as prefixes or suffixes. Such prefixes or suffixes
+will suppress the Lower Camel Case check according to the guide:
 https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingBasics.html#//apple_ref/doc/uid/20001281-1002931-BBCFHEAB
 
 For a full list of well-known acronyms:
@@ -37,7 +37,7 @@
 
 .. option:: Acronyms
 
-   Semicolon-separated list of acronyms that can be used as prefix
-   of property names.
+   Semicolon-separated list of acronyms that can be used as a prefix
+   or a suffix of property names.
 
-   Defaults to `ASCII;PDF;XML;HTML;URL;RTF;HTTP;TIFF;JPG;PNG;GIF;LZW;ROM;RGB;CMYK;MIDI;FTP`.
+   If unset, defaults to "ACL;API;ARGB;ASCII;BGRA;CMYK;DNS;FPS;FTP;GIF;GPS;HD;HDR;HTML;HTTP;HTTPS;HUD;ID;JPG;JS;LAN;LZW;MDNS;MIDI;OS;PDF;PIN;PNG;POI;PSTN;PTR;QA;QOS;RGB;RGBA;RGBX;ROM;RPC;RTF;RTL;SDK;SSO;TCP;TIFF;TTS;UI;URI;URL;VC;VOIP;VPN;VR;WAN;XML".
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r322886 - [clang-tidy objc-property-declaration] Expand list of ObjC acronyms

2018-01-18 Thread Ben Hamilton via cfe-commits
Author: benhamilton
Date: Thu Jan 18 12:51:24 2018
New Revision: 322886

URL: http://llvm.org/viewvc/llvm-project?rev=322886=rev
Log:
[clang-tidy objc-property-declaration] Expand list of ObjC acronyms

Summary:
We were missing some pretty common acronyms in the camelCase
property name check objc-property-declaration.

This expands the list and sorts it lexicographically, so we can
avoid duplicates.

Test Plan: make -j12 check-clang-tools

Reviewers: Wizard, hokein, klimek

Reviewed By: Wizard

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
clang-tools-extra/trunk/docs/clang-tidy/checks/objc-property-declaration.rst
clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m

Modified: clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp?rev=322886=322885=322886=diff
==
--- clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp Thu 
Jan 18 12:51:24 2018
@@ -24,25 +24,63 @@ namespace objc {
 namespace {
 /// The acronyms are from
 /// 
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/APIAbbreviations.html#//apple_ref/doc/uid/20001285-BCIHCGAE
+///
+/// Keep this list sorted.
 constexpr char DefaultSpecialAcronyms[] =
+"ACL;"
+"API;"
+"ARGB;"
 "ASCII;"
-"PDF;"
-"XML;"
+"BGRA;"
+"CMYK;"
+"DNS;"
+"FPS;"
+"FTP;"
+"GIF;"
+"GPS;"
+"HD;"
+"HDR;"
 "HTML;"
-"URL;"
-"RTF;"
 "HTTP;"
-"TIFF;"
+"HTTPS;"
+"HUD;"
+"ID;"
 "JPG;"
-"PNG;"
-"GIF;"
+"JS;"
+"LAN;"
 "LZW;"
-"ROM;"
-"RGB;"
-"CMYK;"
+"MDNS;"
 "MIDI;"
-"FTP;"
-"ID";
+"OS;"
+"PDF;"
+"PIN;"
+"PNG;"
+"POI;"
+"PSTN;"
+"PTR;"
+"QA;"
+"QOS;"
+"RGB;"
+"RGBA;"
+"RGBX;"
+"ROM;"
+"RPC;"
+"RTF;"
+"RTL;"
+"SDK;"
+"SSO;"
+"TCP;"
+"TIFF;"
+"TTS;"
+"UI;"
+"URI;"
+"URL;"
+"VC;"
+"VOIP;"
+"VPN;"
+"VR;"
+"WAN;"
+"XML";
 
 /// For now we will only fix 'CamelCase' property to
 /// 'camelCase'. For other cases the users need to

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/objc-property-declaration.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/objc-property-declaration.rst?rev=322886=322885=322886=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/objc-property-declaration.rst 
(original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/objc-property-declaration.rst 
Thu Jan 18 12:51:24 2018
@@ -23,8 +23,8 @@ The check will only fix 'CamelCase' to '
 only provide warning messages since the property name could be complicated.
 Users will need to come up with a proper name by their own.
 
-This check also accepts special acronyms as prefix. Such prefix will suppress
-the check of Lower Camel Case according to the guide:
+This check also accepts special acronyms as prefixes or suffixes. Such 
prefixes or suffixes
+will suppress the Lower Camel Case check according to the guide:
 
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingBasics.html#//apple_ref/doc/uid/20001281-1002931-BBCFHEAB
 
 For a full list of well-known acronyms:
@@ -37,7 +37,7 @@ Options
 
 .. option:: Acronyms
 
-   Semicolon-separated list of acronyms that can be used as prefix
-   of property names.
+   Semicolon-separated list of acronyms that can be used as a prefix
+   or a suffix of property names.
 
-   Defaults to 
`ASCII;PDF;XML;HTML;URL;RTF;HTTP;TIFF;JPG;PNG;GIF;LZW;ROM;RGB;CMYK;MIDI;FTP`.
+   If unset, defaults to 
"ACL;API;ARGB;ASCII;BGRA;CMYK;DNS;FPS;FTP;GIF;GPS;HD;HDR;HTML;HTTP;HTTPS;HUD;ID;JPG;JS;LAN;LZW;MDNS;MIDI;OS;PDF;PIN;PNG;POI;PSTN;PTR;QA;QOS;RGB;RGBA;RGBX;ROM;RPC;RTF;RTL;SDK;SSO;TCP;TIFF;TTS;UI;URI;URL;VC;VOIP;VPN;VR;WAN;XML".

Modified: clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m?rev=322886=322885=322886=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m Thu Jan 
18 12:51:24 2018
@@ -1,5 +1,7 @@
 // RUN: %check_clang_tidy %s objc-property-declaration %t
+@class NSData;
 @class NSString;
+@class UIViewController;
 
 @interface Foo
 

[PATCH] D42261: [clang-tidy objc-property-declaration] New option AdditionalAcronyms

2018-01-18 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added reviewers: Wizard, hokein, klimek.
Herald added a subscriber: cfe-commits.

The existing option objc-property-declaration.Acronyms
replaces the built-in set of acronyms.

While this behavior is OK for clients that don't want the default
behavior, many clients may just want to add their own custom acronyms
to the default list.

This revision introduces a new option,
objc-property-declaration.AdditionalAcronyms, which appends custom
acronyms to the default list (instead of replacing the default list).

I also updated the documentation.

Test Plan: make -j12 check-clang-tools


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42261

Files:
  clang-tidy/objc/PropertyDeclarationCheck.cpp
  clang-tidy/objc/PropertyDeclarationCheck.h
  docs/clang-tidy/checks/objc-property-declaration.rst
  test/clang-tidy/objc-property-declaration-additional.m
  test/clang-tidy/objc-property-declaration-custom.m


Index: test/clang-tidy/objc-property-declaration-custom.m
===
--- test/clang-tidy/objc-property-declaration-custom.m
+++ test/clang-tidy/objc-property-declaration-custom.m
@@ -11,4 +11,6 @@
 @property(assign, nonatomic) int ABCCustomPrefix;
 @property(strong, nonatomic) NSString *ABC_custom_prefix;
 // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: property name 'ABC_custom_prefix' 
should use lowerCamelCase style, according to the Apple Coding Guidelines 
[objc-property-declaration]
+@property(assign, nonatomic) int GIFIgnoreStandardAcronym;
+// CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 
'GIFIgnoreStandardAcronym' should use lowerCamelCase style, according to the 
Apple Coding Guidelines [objc-property-declaration]
 @end
Index: test/clang-tidy/objc-property-declaration-additional.m
===
--- test/clang-tidy/objc-property-declaration-additional.m
+++ test/clang-tidy/objc-property-declaration-additional.m
@@ -1,6 +1,6 @@
 // RUN: %check_clang_tidy %s objc-property-declaration %t \
 // RUN: -config='{CheckOptions: \
-// RUN:  [{key: objc-property-declaration.Acronyms, value: "ABC;TGIF"}]}' \
+// RUN:  [{key: objc-property-declaration.AdditionalAcronyms, value: 
"ABC;TGIF"}]}' \
 // RUN: --
 @class NSString;
 
@@ -11,4 +11,5 @@
 @property(assign, nonatomic) int ABCCustomPrefix;
 @property(strong, nonatomic) NSString *ABC_custom_prefix;
 // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: property name 'ABC_custom_prefix' 
should use lowerCamelCase style, according to the Apple Coding Guidelines 
[objc-property-declaration]
+@property(assign, nonatomic) int GIFShouldIncludeStandardAcronym;
 @end
Index: docs/clang-tidy/checks/objc-property-declaration.rst
===
--- docs/clang-tidy/checks/objc-property-declaration.rst
+++ docs/clang-tidy/checks/objc-property-declaration.rst
@@ -41,3 +41,12 @@
or a suffix of property names.
 
If unset, defaults to 
"ACL;API;ARGB;ASCII;BGRA;CMYK;DNS;FPS;FTP;GIF;GPS;HD;HDR;HTML;HTTP;HTTPS;HUD;ID;JPG;JS;LAN;LZW;MDNS;MIDI;OS;PDF;PIN;PNG;POI;PSTN;PTR;QA;QOS;RGB;RGBA;RGBX;ROM;RPC;RTF;RTL;SDK;SSO;TCP;TIFF;TTS;UI;URI;URL;VC;VOIP;VPN;VR;WAN;XML".
+
+   If set, replaces the default list. (If you want to append to the default 
list, set AdditionalAcronyms instead.)
+
+.. option:: AdditionalAcronyms
+
+   Semicolon-separated list of additional acronyms that can be used as a prefix
+   or a suffix of property names.
+
+   Appends to the list in Acronyms.
Index: clang-tidy/objc/PropertyDeclarationCheck.h
===
--- clang-tidy/objc/PropertyDeclarationCheck.h
+++ clang-tidy/objc/PropertyDeclarationCheck.h
@@ -35,6 +35,7 @@
 
 private:
 const std::vector SpecialAcronyms;
+const std::vector AdditionalAcronyms;
 };
 
 } // namespace objc
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -124,14 +124,22 @@
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
   SpecialAcronyms(utils::options::parseStringList(
-  Options.get("Acronyms", DefaultSpecialAcronyms))) {}
+  Options.get("Acronyms", DefaultSpecialAcronyms))),
+  AdditionalAcronyms(utils::options::parseStringList(
+  Options.get("AdditionalAcronyms", ""))) {}
 
 void PropertyDeclarationCheck::registerMatchers(MatchFinder *Finder) {
+  std::vector Acronyms;
+  Acronyms.reserve(SpecialAcronyms.size() + AdditionalAcronyms.size());
+  Acronyms.insert(Acronyms.end(), SpecialAcronyms.begin(),
+  SpecialAcronyms.end());
+  Acronyms.insert(Acronyms.end(), AdditionalAcronyms.begin(),
+  AdditionalAcronyms.end());
   Finder->addMatcher(
   

[PATCH] D42253: [clang-tidy objc-property-declaration] Expand list of ObjC acronyms

2018-01-18 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton updated this revision to Diff 130478.
benhamilton added a comment.

- Added comment about prefixes and suffixes.
- Updated list of acronyms.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42253

Files:
  clang-tidy/objc/PropertyDeclarationCheck.cpp
  docs/clang-tidy/checks/objc-property-declaration.rst
  test/clang-tidy/objc-property-declaration.m

Index: test/clang-tidy/objc-property-declaration.m
===
--- test/clang-tidy/objc-property-declaration.m
+++ test/clang-tidy/objc-property-declaration.m
@@ -1,13 +1,17 @@
 // RUN: %check_clang_tidy %s objc-property-declaration %t
+@class NSData;
 @class NSString;
+@class UIViewController;
 
 @interface Foo
 @property(assign, nonatomic) int NotCamelCase;
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'NotCamelCase' should use lowerCamelCase style, according to the Apple Coding Guidelines [objc-property-declaration]
 // CHECK-FIXES: @property(assign, nonatomic) int notCamelCase;
 @property(assign, nonatomic) int camelCase;
 @property(strong, nonatomic) NSString *URLString;
 @property(strong, nonatomic) NSString *bundleID;
+@property(strong, nonatomic) NSData *RGBABytes;
+@property(strong, nonatomic) UIViewController *notificationsVC;
 @property(strong, nonatomic) NSString *URL_string;
 // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: property name 'URL_string' should use lowerCamelCase style, according to the Apple Coding Guidelines [objc-property-declaration]
 @end
Index: docs/clang-tidy/checks/objc-property-declaration.rst
===
--- docs/clang-tidy/checks/objc-property-declaration.rst
+++ docs/clang-tidy/checks/objc-property-declaration.rst
@@ -23,8 +23,8 @@
 only provide warning messages since the property name could be complicated.
 Users will need to come up with a proper name by their own.
 
-This check also accepts special acronyms as prefix. Such prefix will suppress
-the check of Lower Camel Case according to the guide:
+This check also accepts special acronyms as prefixes or suffixes. Such prefixes or suffixes
+will suppress the Lower Camel Case check according to the guide:
 https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingBasics.html#//apple_ref/doc/uid/20001281-1002931-BBCFHEAB
 
 For a full list of well-known acronyms:
@@ -37,7 +37,7 @@
 
 .. option:: Acronyms
 
-   Semicolon-separated list of acronyms that can be used as prefix
-   of property names.
+   Semicolon-separated list of acronyms that can be used as a prefix
+   or a suffix of property names.
 
-   Defaults to `ASCII;PDF;XML;HTML;URL;RTF;HTTP;TIFF;JPG;PNG;GIF;LZW;ROM;RGB;CMYK;MIDI;FTP`.
+   If unset, defaults to "ACL;API;ARGB;ASCII;BGRA;CMYK;DNS;FPS;FTP;GIF;GPS;HD;HDR;HTML;HTTP;HTTPS;HUD;ID;JPG;JS;LAN;LZW;MDNS;MIDI;OS;PDF;PIN;PNG;POI;PSTN;PTR;QA;QOS;RGB;RGBA;RGBX;ROM;RPC;RTF;RTL;SDK;SSO;TCP;TIFF;TTS;UI;URI;URL;VC;VOIP;VPN;VR;WAN;XML".
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -24,25 +24,63 @@
 namespace {
 /// The acronyms are from
 /// https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/APIAbbreviations.html#//apple_ref/doc/uid/20001285-BCIHCGAE
+///
+/// Keep this list sorted.
 constexpr char DefaultSpecialAcronyms[] =
+"ACL;"
+"API;"
+"ARGB;"
 "ASCII;"
-"PDF;"
-"XML;"
+"BGRA;"
+"CMYK;"
+"DNS;"
+"FPS;"
+"FTP;"
+"GIF;"
+"GPS;"
+"HD;"
+"HDR;"
 "HTML;"
-"URL;"
-"RTF;"
 "HTTP;"
-"TIFF;"
+"HTTPS;"
+"HUD;"
+"ID;"
 "JPG;"
-"PNG;"
-"GIF;"
+"JS;"
+"LAN;"
 "LZW;"
-"ROM;"
-"RGB;"
-"CMYK;"
+"MDNS;"
 "MIDI;"
-"FTP;"
-"ID";
+"OS;"
+"PDF;"
+"PIN;"
+"PNG;"
+"POI;"
+"PSTN;"
+"PTR;"
+"QA;"
+"QOS;"
+"RGB;"
+"RGBA;"
+"RGBX;"
+"ROM;"
+"RPC;"
+"RTF;"
+"RTL;"
+"SDK;"
+"SSO;"
+"TCP;"
+"TIFF;"
+"TTS;"
+"UI;"
+"URI;"
+"URL;"
+"VC;"
+"VOIP;"
+"VPN;"
+"VR;"
+"WAN;"
+"XML";
 
 /// For now we will only fix 'CamelCase' property to
 /// 'camelCase'. For other cases the users need to
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42043: c-index: CXString: fix MSAN read-past-end bug

2018-01-18 Thread Steve O'Brien via Phabricator via cfe-commits
elsteveogrande marked 2 inline comments as done.
elsteveogrande added inline comments.



Comment at: tools/c-index-test/c-index-test.c:3268
 
-  filename = clang_getFileName(file);
-  index_data->main_filename = clang_getCString(filename);
-  clang_disposeString(filename);
+  index_data->main_filename = clang_getFileName(file);
 

elsteveogrande wrote:
> vsk wrote:
> > This looks like a separate bug fix. Is it possible to separate the 
> > main_filename changes from this patch?
> Will do!
Done: https://reviews.llvm.org/D42259


Repository:
  rC Clang

https://reviews.llvm.org/D42043



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


[PATCH] D42259: c-index-test: small fix to CXString handling and disposal

2018-01-18 Thread Phabricator via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322883: c-index-test: small fix to CXString handling and 
disposal (authored by steveo, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42259?vs=130475=130476#toc

Repository:
  rC Clang

https://reviews.llvm.org/D42259

Files:
  tools/c-index-test/c-index-test.c

Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -1128,6 +1128,13 @@
   }
 }
 
+static CXString createCXString(const char *CS) {
+  CXString Str;
+  Str.data = (const void *) CS;
+  Str.private_flags = 0;
+  return Str;
+}
+
 /**/
 /* Callbacks. */
 /**/
@@ -3090,7 +3097,7 @@
   int first_check_printed;
   int fail_for_error;
   int abort;
-  const char *main_filename;
+  CXString main_filename;
   ImportedASTFilesData *importedASTs;
   IndexDataStringList *strings;
   CXTranslationUnit TU;
@@ -3129,6 +3136,7 @@
   const char *cname;
   CXIdxClientFile file;
   unsigned line, column;
+  const char *main_filename;
   int isMainFile;
   
   index_data = (IndexData *)client_data;
@@ -3143,7 +3151,8 @@
   }
   filename = clang_getFileName((CXFile)file);
   cname = clang_getCString(filename);
-  if (strcmp(cname, index_data->main_filename) == 0)
+  main_filename = clang_getCString(index_data->main_filename);
+  if (strcmp(cname, main_filename) == 0)
 isMainFile = 1;
   else
 isMainFile = 0;
@@ -3345,14 +3354,11 @@
 static CXIdxClientFile index_enteredMainFile(CXClientData client_data,
CXFile file, void *reserved) {
   IndexData *index_data;
-  CXString filename;
 
   index_data = (IndexData *)client_data;
   printCheck(index_data);
 
-  filename = clang_getFileName(file);
-  index_data->main_filename = clang_getCString(filename);
-  clang_disposeString(filename);
+  index_data->main_filename = clang_getFileName(file);
 
   printf("[enteredMainFile]: ");
   printCXIndexFile((CXIdxClientFile)file);
@@ -3591,7 +3597,7 @@
   index_data.first_check_printed = 0;
   index_data.fail_for_error = 0;
   index_data.abort = 0;
-  index_data.main_filename = "";
+  index_data.main_filename = createCXString("");
   index_data.importedASTs = importedASTs;
   index_data.strings = NULL;
   index_data.TU = NULL;
@@ -3607,6 +3613,7 @@
   if (index_data.fail_for_error)
 result = -1;
 
+  clang_disposeString(index_data.main_filename);
   free_client_data(_data);
   return result;
 }
@@ -3628,7 +3635,7 @@
   index_data.first_check_printed = 0;
   index_data.fail_for_error = 0;
   index_data.abort = 0;
-  index_data.main_filename = "";
+  index_data.main_filename = createCXString("");
   index_data.importedASTs = importedASTs;
   index_data.strings = NULL;
   index_data.TU = TU;
@@ -3641,6 +3648,7 @@
 result = -1;
 
   clang_disposeTranslationUnit(TU);
+  clang_disposeString(index_data.main_filename);
   free_client_data(_data);
   return result;
 }
@@ -4133,9 +4141,7 @@
   if (!isUSR(I[2]))
 return not_usr("", I[2]);
   else {
-CXString x;
-x.data = (void*) I[2];
-x.private_flags = 0;
+CXString x = createCXString(I[2]);
 print_usr(clang_constructUSR_ObjCIvar(I[1], x));
   }
 
@@ -4160,9 +4166,7 @@
   if (!isUSR(I[3]))
 return not_usr("", I[3]);
   else {
-CXString x;
-x.data = (void*) I[3];
-x.private_flags = 0;
+CXString x = createCXString(I[3]);
 print_usr(clang_constructUSR_ObjCMethod(I[1], atoi(I[2]), x));
   }
   I += 4;
@@ -4190,9 +4194,7 @@
   if (!isUSR(I[2]))
 return not_usr("", I[2]);
   else {
-CXString x;
-x.data = (void*) I[2];
-x.private_flags = 0;
+CXString x = createCXString(I[2]);
 print_usr(clang_constructUSR_ObjCProperty(I[1], x));
   }
   I += 3;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42259: c-index-test: small fix to CXString handling and disposal

2018-01-18 Thread Steve O'Brien via Phabricator via cfe-commits
elsteveogrande created this revision.
elsteveogrande added reviewers: vsk, benlangmuir, akyrtzi.
Herald added a subscriber: cfe-commits.

(Separating some unrelated changes out of https://reviews.llvm.org/D42043)


Repository:
  rC Clang

https://reviews.llvm.org/D42259

Files:
  tools/c-index-test/c-index-test.c

Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -1128,6 +1128,13 @@
   }
 }
 
+static CXString createCXString(const char *CS) {
+  CXString Str;
+  Str.data = (const void *) CS;
+  Str.private_flags = 0;
+  return Str;
+}
+
 /**/
 /* Callbacks. */
 /**/
@@ -3090,7 +3097,7 @@
   int first_check_printed;
   int fail_for_error;
   int abort;
-  const char *main_filename;
+  CXString main_filename;
   ImportedASTFilesData *importedASTs;
   IndexDataStringList *strings;
   CXTranslationUnit TU;
@@ -3129,6 +3136,7 @@
   const char *cname;
   CXIdxClientFile file;
   unsigned line, column;
+  const char *main_filename;
   int isMainFile;
   
   index_data = (IndexData *)client_data;
@@ -3143,7 +3151,8 @@
   }
   filename = clang_getFileName((CXFile)file);
   cname = clang_getCString(filename);
-  if (strcmp(cname, index_data->main_filename) == 0)
+  main_filename = clang_getCString(index_data->main_filename);
+  if (strcmp(cname, main_filename) == 0)
 isMainFile = 1;
   else
 isMainFile = 0;
@@ -3345,14 +3354,11 @@
 static CXIdxClientFile index_enteredMainFile(CXClientData client_data,
CXFile file, void *reserved) {
   IndexData *index_data;
-  CXString filename;
 
   index_data = (IndexData *)client_data;
   printCheck(index_data);
 
-  filename = clang_getFileName(file);
-  index_data->main_filename = clang_getCString(filename);
-  clang_disposeString(filename);
+  index_data->main_filename = clang_getFileName(file);
 
   printf("[enteredMainFile]: ");
   printCXIndexFile((CXIdxClientFile)file);
@@ -3591,7 +3597,7 @@
   index_data.first_check_printed = 0;
   index_data.fail_for_error = 0;
   index_data.abort = 0;
-  index_data.main_filename = "";
+  index_data.main_filename = createCXString("");
   index_data.importedASTs = importedASTs;
   index_data.strings = NULL;
   index_data.TU = NULL;
@@ -3607,6 +3613,7 @@
   if (index_data.fail_for_error)
 result = -1;
 
+  clang_disposeString(index_data.main_filename);
   free_client_data(_data);
   return result;
 }
@@ -3628,7 +3635,7 @@
   index_data.first_check_printed = 0;
   index_data.fail_for_error = 0;
   index_data.abort = 0;
-  index_data.main_filename = "";
+  index_data.main_filename = createCXString("");
   index_data.importedASTs = importedASTs;
   index_data.strings = NULL;
   index_data.TU = TU;
@@ -3641,6 +3648,7 @@
 result = -1;
 
   clang_disposeTranslationUnit(TU);
+  clang_disposeString(index_data.main_filename);
   free_client_data(_data);
   return result;
 }
@@ -4133,9 +4141,7 @@
   if (!isUSR(I[2]))
 return not_usr("", I[2]);
   else {
-CXString x;
-x.data = (void*) I[2];
-x.private_flags = 0;
+CXString x = createCXString(I[2]);
 print_usr(clang_constructUSR_ObjCIvar(I[1], x));
   }
 
@@ -4160,9 +4166,7 @@
   if (!isUSR(I[3]))
 return not_usr("", I[3]);
   else {
-CXString x;
-x.data = (void*) I[3];
-x.private_flags = 0;
+CXString x = createCXString(I[3]);
 print_usr(clang_constructUSR_ObjCMethod(I[1], atoi(I[2]), x));
   }
   I += 4;
@@ -4190,9 +4194,7 @@
   if (!isUSR(I[2]))
 return not_usr("", I[2]);
   else {
-CXString x;
-x.data = (void*) I[2];
-x.private_flags = 0;
+CXString x = createCXString(I[2]);
 print_usr(clang_constructUSR_ObjCProperty(I[1], x));
   }
   I += 3;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41655: [clang-tidy] New check bugprone-unused-return-value

2018-01-18 Thread Kalle Huttunen via Phabricator via cfe-commits
khuttun added a comment.

The checker reports 7 warnings on LLVM + Clang code bases, all on 
std::unique_ptr::release:

lib/Bitcode/Reader/BitReader.cpp:114:3

- release() called on moved-from unique_ptr
- no harm, just unnecessary

lib/ExecutionEngine/ExecutionEngine.cpp:149:7

- release() called before erasing unique_ptr from a container
- false positive?

lib/Target/AMDGPU/GCNIterativeScheduler.cpp:196:5

- release() called before assigning new pointer to unique_ptr
- false positive?

lib/AsmParser/LLParser.cpp:855:3

- get() + release() could be replaced with release()

tools/clang/lib/Lex/ModuleMap.cpp:791:3

- false positive?

tools/clang/tools/extra/clangd/Compiler.cpp:61:3

- get() + release() could potentially be replaced with release()?

unittests/Support/Casting.cpp:144:3

- release() called to avoid calling delete on a pointer to global object
- false positive?


https://reviews.llvm.org/D41655



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


[PATCH] D42253: [clang-tidy objc-property-declaration] Expand list of ObjC acronyms

2018-01-18 Thread Yan Zhang via Phabricator via cfe-commits
Wizard added a comment.

Can you update the doc btw since the acronyms are not only for prefix anymore?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42253



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


[PATCH] D42043: c-index: CXString: fix MSAN read-past-end bug

2018-01-18 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

Thanks for working on this :).




Comment at: tools/libclang/CXString.cpp:213
+  if (string.IsNullTerminated) {
+CString = (const char *) string.Contents;
+  } else {

elsteveogrande wrote:
> vsk wrote:
> > Basic question: If a non-owning CXString is null-terminated, what provides 
> > the guarantee that the string is in fact valid when getCString() is called? 
> > Is the user of the C API responsible for ensuring the lifetime of the 
> > string is valid?
> I believe the API itself is the one building `CXString` instances, and the 
> user of the C API doesn't really create them, only use them.  So the API has 
> to ensure the string stays "good" while there may be references to it.
> 
> (Which feels a little fragile.  But I think that's the tradeoff being made.  
> You'll get either "fast" strings, or data guaranteed to be sane.  I'd opt for 
> safer data but I don't know who's using this C API and am afraid to introduce 
> a serious perf regression.  So it'll stay this way and I'll try my best to 
> solve *-SAN issues with these constraints :) )
Sgtm, it doesn't look like this is altering the API contract.


Repository:
  rC Clang

https://reviews.llvm.org/D42043



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


r322880 - Convert comment to C-style to prevent warning

2018-01-18 Thread Sam Clegg via cfe-commits
Author: sbc
Date: Thu Jan 18 11:31:33 2018
New Revision: 322880

URL: http://llvm.org/viewvc/llvm-project?rev=322880=rev
Log:
Convert comment to C-style to prevent warning

Modified:
cfe/trunk/tools/c-index-test/c-index-test.c

Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=322880=322879=322880=diff
==
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Thu Jan 18 11:31:33 2018
@@ -739,7 +739,7 @@ static CXString CursorToText(CXCursor Cu
   }
   }
   assert(0 && "unknown display type"); /* no llvm_unreachable in C. */
-  // Set to NULL to prevent uninitialized variable warnings.
+  /* Set to NULL to prevent uninitialized variable warnings. */
   text.data = NULL;
   text.private_flags = 0;
   return text;


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


[PATCH] D41655: [clang-tidy] New check bugprone-unused-return-value

2018-01-18 Thread Kalle Huttunen via Phabricator via cfe-commits
khuttun updated this revision to Diff 130461.
khuttun added a comment.

- Detect unused return values also inside other kinds of statements than 
compound statements
- Ignore void functions in the checker
- Check std::remove, std::remove_if and std::unique by default


https://reviews.llvm.org/D41655

Files:
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/UnusedReturnValueCheck.cpp
  clang-tidy/bugprone/UnusedReturnValueCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-unused-return-value.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/bugprone-unused-return-value-custom.cpp
  test/clang-tidy/bugprone-unused-return-value.cpp

Index: test/clang-tidy/bugprone-unused-return-value.cpp
===
--- /dev/null
+++ test/clang-tidy/bugprone-unused-return-value.cpp
@@ -0,0 +1,311 @@
+// RUN: %check_clang_tidy %s bugprone-unused-return-value %t
+
+namespace std {
+
+using size_t = decltype(sizeof(int));
+
+using max_align_t = long double;
+
+struct future {};
+
+enum class launch {
+  async,
+  deferred
+};
+
+template 
+future async(Function &&, Args &&...);
+
+template 
+future async(launch, Function &&, Args &&...);
+
+template 
+bool empty(const T &);
+
+template 
+ForwardIt remove(ForwardIt, ForwardIt, const T &);
+
+template 
+ForwardIt remove_if(ForwardIt, ForwardIt, UnaryPredicate);
+
+template 
+ForwardIt unique(ForwardIt, ForwardIt);
+
+// the check should be able to match std lib calls even if the functions are
+// declared inside inline namespaces
+inline namespace v1 {
+
+template 
+T *launder(T *);
+
+} // namespace v1
+
+template 
+struct allocator {
+  using value_type = T;
+  T *allocate(std::size_t);
+  T *allocate(std::size_t, const void *);
+};
+
+template 
+struct allocator_traits {
+  using value_type = typename Alloc::value_type;
+  using pointer = value_type *;
+  using size_type = size_t;
+  using const_void_pointer = const void *;
+  static pointer allocate(Alloc &, size_type);
+  static pointer allocate(Alloc &, size_type, const_void_pointer);
+};
+
+template 
+struct scoped_allocator_adaptor : public OuterAlloc {
+  using pointer = typename allocator_traits::pointer;
+  using size_type = typename allocator_traits::size_type;
+  using const_void_pointer = typename allocator_traits::const_void_pointer;
+  pointer allocate(size_type);
+  pointer allocate(size_type, const_void_pointer);
+};
+
+template 
+struct default_delete {};
+
+template >
+struct unique_ptr {
+  using pointer = T *;
+  pointer release() noexcept;
+};
+
+template >
+struct vector {
+  bool empty() const noexcept;
+};
+
+namespace filesystem {
+
+struct path {
+  bool empty() const noexcept;
+};
+
+} // namespace filesystem
+
+namespace pmr {
+
+struct memory_resource {
+  void *allocate(size_t, size_t = alignof(max_align_t));
+};
+
+template 
+struct polymorphic_allocator {
+  T *allocate(size_t);
+};
+
+} // namespace pmr
+
+} // namespace std
+
+struct Foo {
+  void f();
+};
+
+int increment(int i) {
+  return i + 1;
+}
+
+void useFuture(const std::future );
+
+struct FooAlloc {
+  using value_type = Foo;
+};
+
+void warning() {
+  std::async(increment, 42);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+
+  std::async(std::launch::async, increment, 42);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+
+  Foo F;
+  std::launder();
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+
+  std::unique_ptr UP;
+  UP.release();
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+
+  std::unique_ptr UP2;
+  UP2.release();
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+
+  std::allocator FA;
+  FA.allocate(1);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  FA.allocate(1, nullptr);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+
+  std::allocator_traits::allocate(FA, 1);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  std::allocator_traits::allocate(FA, 1, nullptr);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+
+  std::scoped_allocator_adaptor SAA;
+  SAA.allocate(1);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  

[PATCH] D42249: [CodeGenCXX] annotate a GEP to a derived class with 'inbounds' (PR35909)

2018-01-18 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: lib/CodeGen/CGClass.cpp:410
+
+  // The GEP is to a derived object, so this GEP must be 'inbounds'.
+  Value = Builder.CreateInBoundsGEP(Value, Builder.CreateNeg(NonVirtualOffset),

Not sure this comment really adds anything, unless you want to cite the 
standard.



Comment at: test/CodeGenCXX/catch-undef-behavior.cpp:391
   // Alignment check from EmitTypeCheck(TCK_DowncastReference, ...)
-  // CHECK:  [[SUB:%[.a-z0-9]*]] = getelementptr i8, i8* {{.*}}, i64 -16
+  // CHECK:  [[SUB:%[.a-z0-9]*]] = getelementptr inbounds i8, i8* {{.*}}, 
i64 -16
   // CHECK-NEXT: [[C:%.+]] = bitcast i8* [[SUB]] to %class.C*

We probably want a test which checks the output when ubsan isn't enabled.


https://reviews.llvm.org/D42249



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


[PATCH] D42043: c-index: CXString: fix MSAN read-past-end bug

2018-01-18 Thread Steve O'Brien via Phabricator via cfe-commits
elsteveogrande added a comment.

Thanks very much for looking at this @vsk !  I actually found an ASAN bug in my 
new code, mixing and matching `malloc/free` and `operator`s `new/delete`.




Comment at: tools/c-index-test/c-index-test.c:3268
 
-  filename = clang_getFileName(file);
-  index_data->main_filename = clang_getCString(filename);
-  clang_disposeString(filename);
+  index_data->main_filename = clang_getFileName(file);
 

vsk wrote:
> This looks like a separate bug fix. Is it possible to separate the 
> main_filename changes from this patch?
Will do!



Comment at: tools/libclang/CXString.cpp:59
 CXString createEmpty() {
   CXString Str;
+  Str.Contents = (const void *) "";

vsk wrote:
> Why shouldn't this be defined as createRef("")?
Hmm, good question.  `createRef` below actually calls back to `createEmpty` and 
`createNull` in the nonnull-but-empty and null cases.

I think I'll do this the other way around, and let `createRef` have the 
responsibility of dealing with these fields and nulls and whatnot.



Comment at: tools/libclang/CXString.cpp:213
+  if (string.IsNullTerminated) {
+CString = (const char *) string.Contents;
+  } else {

vsk wrote:
> Basic question: If a non-owning CXString is null-terminated, what provides 
> the guarantee that the string is in fact valid when getCString() is called? 
> Is the user of the C API responsible for ensuring the lifetime of the string 
> is valid?
I believe the API itself is the one building `CXString` instances, and the user 
of the C API doesn't really create them, only use them.  So the API has to 
ensure the string stays "good" while there may be references to it.

(Which feels a little fragile.  But I think that's the tradeoff being made.  
You'll get either "fast" strings, or data guaranteed to be sane.  I'd opt for 
safer data but I don't know who's using this C API and am afraid to introduce a 
serious perf regression.  So it'll stay this way and I'll try my best to solve 
*-SAN issues with these constraints :) )


Repository:
  rC Clang

https://reviews.llvm.org/D42043



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


[PATCH] D42213: [ASTMatchers] [NFC] Fix code examples

2018-01-18 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Don't forget that you also need to regenerate the HTML docs:

  $ cd docs/tools # yes, cd
  $ ./dump_ast_matchers.py


Repository:
  rC Clang

https://reviews.llvm.org/D42213



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


[PATCH] D42253: [clang-tidy objc-property-declaration] Expand list of ObjC acronyms

2018-01-18 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added reviewers: Wizard, hokein, klimek.
Herald added a subscriber: cfe-commits.

We were missing some pretty common acronyms in the camelCase
property name check objc-property-declaration.

This expands the list and sorts it lexicographically, so we can
avoid duplicates.

Test Plan: make -j12 check-clang-tools


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42253

Files:
  clang-tidy/objc/PropertyDeclarationCheck.cpp
  test/clang-tidy/objc-property-declaration.m

Index: test/clang-tidy/objc-property-declaration.m
===
--- test/clang-tidy/objc-property-declaration.m
+++ test/clang-tidy/objc-property-declaration.m
@@ -1,13 +1,17 @@
 // RUN: %check_clang_tidy %s objc-property-declaration %t
+@class NSData;
 @class NSString;
+@class UIViewController;
 
 @interface Foo
 @property(assign, nonatomic) int NotCamelCase;
 // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: property name 'NotCamelCase' should use lowerCamelCase style, according to the Apple Coding Guidelines [objc-property-declaration]
 // CHECK-FIXES: @property(assign, nonatomic) int notCamelCase;
 @property(assign, nonatomic) int camelCase;
 @property(strong, nonatomic) NSString *URLString;
 @property(strong, nonatomic) NSString *bundleID;
+@property(strong, nonatomic) NSData *RGBABytes;
+@property(strong, nonatomic) UIViewController *notificationsVC;
 @property(strong, nonatomic) NSString *URL_string;
 // CHECK-MESSAGES: :[[@LINE-1]]:40: warning: property name 'URL_string' should use lowerCamelCase style, according to the Apple Coding Guidelines [objc-property-declaration]
 @end
Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -24,25 +24,63 @@
 namespace {
 /// The acronyms are from
 /// https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/APIAbbreviations.html#//apple_ref/doc/uid/20001285-BCIHCGAE
+///
+/// Keep this list sorted.
 constexpr char DefaultSpecialAcronyms[] =
+"ACL;"
+"API;"
+"ARGB;"
 "ASCII;"
-"PDF;"
-"XML;"
+"BGRA;"
+"CMYK;"
+"DNS;"
+"FPS;"
+"FTP;"
+"GIF;"
+"GPS;"
+"HD;"
+"HDR;"
 "HTML;"
-"URL;"
-"RTF;"
 "HTTP;"
-"TIFF;"
+"HTTPS;"
+"HUD;"
+"ID;"
 "JPG;"
-"PNG;"
-"GIF;"
+"JS;"
+"LAN;"
 "LZW;"
-"ROM;"
-"RGB;"
-"CMYK;"
+"MDNS;"
 "MIDI;"
-"FTP;"
-"ID";
+"OS;"
+"PDF;"
+"PIN;"
+"PNG;"
+"POI;"
+"PSTN;"
+"PTR;"
+"QA;"
+"QOS;"
+"RGB;"
+"RGBA;"
+"RGBX;"
+"ROM;"
+"RPC;"
+"RTF;"
+"RTL;"
+"SDK;"
+"SSO;"
+"TCP;"
+"TIFF;"
+"TTS;"
+"UI;"
+"URI;"
+"URL;"
+"VC;"
+"VOIP;"
+"VPN;"
+"VR;"
+"WAN;"
+"XML";
 
 /// For now we will only fix 'CamelCase' property to
 /// 'camelCase'. For other cases the users need to
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42213: [ASTMatchers] [NFC] Fix code examples

2018-01-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 130458.
MaskRay added a comment.

More


Repository:
  rC Clang

https://reviews.llvm.org/D42213

Files:
  include/clang/ASTMatchers/ASTMatchers.h


Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -800,7 +800,7 @@
 ///   A b;
 ///   A c;
 ///
-///   template f() {};
+///   template void f() {};
 ///   void func() { f(); };
 /// \endcode
 /// classTemplateSpecializationDecl(hasTemplateArgument(
@@ -880,12 +880,12 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
-///   struct B { B* next; };
+///   struct B { int next; };
+///   template struct A {};
 ///   A<::next> a;
 /// \endcode
 /// classTemplateSpecializationDecl(hasAnyTemplateArgument(
-/// refersToDeclaration(fieldDecl(hasName("next"
+/// refersToDeclaration(fieldDecl(hasName("next")
 ///   matches the specialization \c A<::next> with \c fieldDecl(...) matching
 /// \c B::next
 AST_MATCHER_P(TemplateArgument, refersToDeclaration,
@@ -899,8 +899,8 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
-///   struct B { B* next; };
+///   struct B { int next; };
+///   template struct A {};
 ///   A<::next> a;
 /// \endcode
 /// templateSpecializationType(hasAnyTemplateArgument(
@@ -917,7 +917,7 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
+///   template struct C {};
 ///   C<42> c;
 /// \endcode
 /// classTemplateSpecializationDecl(
@@ -932,7 +932,7 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
+///   template struct C {};
 ///   C<42> c;
 /// \endcode
 /// classTemplateSpecializationDecl(
@@ -953,7 +953,7 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
+///   template struct C {};
 ///   C<42> c;
 /// \endcode
 /// classTemplateSpecializationDecl(
@@ -1523,12 +1523,12 @@
 /// \code
 ///   T u(f());
 ///   g(f());
-/// \endcode
-/// but does not match
-/// \code
-///   f();
 ///   f().func();
 /// \endcode
+/// but does not match
+/// \code
+///   f();
+/// \endcode
 extern const internal::VariadicDynCastAllOfMatcher
 materializeTemporaryExpr;


Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -800,7 +800,7 @@
 ///   A b;
 ///   A c;
 ///
-///   template f() {};
+///   template void f() {};
 ///   void func() { f(); };
 /// \endcode
 /// classTemplateSpecializationDecl(hasTemplateArgument(
@@ -880,12 +880,12 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
-///   struct B { B* next; };
+///   struct B { int next; };
+///   template struct A {};
 ///   A<::next> a;
 /// \endcode
 /// classTemplateSpecializationDecl(hasAnyTemplateArgument(
-/// refersToDeclaration(fieldDecl(hasName("next"
+/// refersToDeclaration(fieldDecl(hasName("next")
 ///   matches the specialization \c A<::next> with \c fieldDecl(...) matching
 /// \c B::next
 AST_MATCHER_P(TemplateArgument, refersToDeclaration,
@@ -899,8 +899,8 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
-///   struct B { B* next; };
+///   struct B { int next; };
+///   template struct A {};
 ///   A<::next> a;
 /// \endcode
 /// templateSpecializationType(hasAnyTemplateArgument(
@@ -917,7 +917,7 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
+///   template struct C {};
 ///   C<42> c;
 /// \endcode
 /// classTemplateSpecializationDecl(
@@ -932,7 +932,7 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
+///   template struct C {};
 ///   C<42> c;
 /// \endcode
 /// classTemplateSpecializationDecl(
@@ -953,7 +953,7 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
+///   template struct C {};
 ///   C<42> c;
 /// \endcode
 /// classTemplateSpecializationDecl(
@@ -1523,12 +1523,12 @@
 /// \code
 ///   T u(f());
 ///   g(f());
-/// \endcode
-/// but does not match
-/// \code
-///   f();
 ///   f().func();
 /// \endcode
+/// but does not match
+/// \code
+///   f();
+/// \endcode
 extern const internal::VariadicDynCastAllOfMatcher
 materializeTemporaryExpr;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42248: [LangOpts] Add a LangOpt to represent "#pragma region" support.

2018-01-18 Thread Matt Davis via Phabricator via cfe-commits
mattd added a comment.

In https://reviews.llvm.org/D42248#980541, @majnemer wrote:

> Why not always support the pragma regardless of the compiler mode? Our 
> "support" for it just ignores it anyway...


Thanks for the reply @majnemer.

I am not opposed to that idea.  My change just operates similar to the existing 
behavior.  The only reservation I had against not always accepting the pragma 
is that it might mislead devs who are not using PS4/VS based environments.


https://reviews.llvm.org/D42248



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


[PATCH] D42248: [LangOpts] Add a LangOpt to represent "#pragma region" support.

2018-01-18 Thread David Majnemer via Phabricator via cfe-commits
majnemer added a comment.

Why not always support the pragma regardless of the compiler mode? Our 
"support" for it just ignores it anyway...


https://reviews.llvm.org/D42248



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


[PATCH] D41074: [ClangFormat] ObjCSpaceBeforeProtocolList should be true in the google style

2018-01-18 Thread Ben Hamilton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322873: [ClangFormat] ObjCSpaceBeforeProtocolList should be 
true in the google style (authored by benhamilton, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41074?vs=126806=130448#toc

Repository:
  rC Clang

https://reviews.llvm.org/D41074

Files:
  lib/Format/Format.cpp
  unittests/Format/FormatTestObjC.cpp


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -694,7 +694,7 @@
   GoogleStyle.IndentCaseLabels = true;
   GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
   GoogleStyle.ObjCSpaceAfterProperty = false;
-  GoogleStyle.ObjCSpaceBeforeProtocolList = false;
+  GoogleStyle.ObjCSpaceBeforeProtocolList = true;
   GoogleStyle.PointerAlignment = FormatStyle::PAS_Left;
   GoogleStyle.RawStringFormats = {{
   FormatStyle::LK_TextProto,
Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -271,7 +271,7 @@
"@end");
 
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
-  verifyFormat("@interface Foo : NSObject {\n"
+  verifyFormat("@interface Foo : NSObject  {\n"
" @public\n"
"  int field1;\n"
" @protected\n"
@@ -283,15 +283,15 @@
"}\n"
"+ (id)init;\n"
"@end");
-  verifyFormat("@interface Foo : Bar\n"
+  verifyFormat("@interface Foo : Bar \n"
"+ (id)init;\n"
"@end");
-  verifyFormat("@interface Foo (HackStuff)\n"
+  verifyFormat("@interface Foo (HackStuff) \n"
"+ (id)init;\n"
"@end");
   Style.BinPackParameters = false;
   Style.ColumnLimit = 80;
-  verifyFormat("@interface a ()<\n"
+  verifyFormat("@interface a () <\n"
"a,\n"
",\n"
"aa,\n"
@@ -414,7 +414,7 @@
"@end");
 
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
-  verifyFormat("@protocol MyProtocol\n"
+  verifyFormat("@protocol MyProtocol \n"
"- (NSUInteger)numberOfThings;\n"
"@end");
 }


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -694,7 +694,7 @@
   GoogleStyle.IndentCaseLabels = true;
   GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
   GoogleStyle.ObjCSpaceAfterProperty = false;
-  GoogleStyle.ObjCSpaceBeforeProtocolList = false;
+  GoogleStyle.ObjCSpaceBeforeProtocolList = true;
   GoogleStyle.PointerAlignment = FormatStyle::PAS_Left;
   GoogleStyle.RawStringFormats = {{
   FormatStyle::LK_TextProto,
Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -271,7 +271,7 @@
"@end");
 
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
-  verifyFormat("@interface Foo : NSObject {\n"
+  verifyFormat("@interface Foo : NSObject  {\n"
" @public\n"
"  int field1;\n"
" @protected\n"
@@ -283,15 +283,15 @@
"}\n"
"+ (id)init;\n"
"@end");
-  verifyFormat("@interface Foo : Bar\n"
+  verifyFormat("@interface Foo : Bar \n"
"+ (id)init;\n"
"@end");
-  verifyFormat("@interface Foo (HackStuff)\n"
+  verifyFormat("@interface Foo (HackStuff) \n"
"+ (id)init;\n"
"@end");
   Style.BinPackParameters = false;
   Style.ColumnLimit = 80;
-  verifyFormat("@interface a ()<\n"
+  verifyFormat("@interface a () <\n"
"a,\n"
",\n"
"aa,\n"
@@ -414,7 +414,7 @@
"@end");
 
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
-  verifyFormat("@protocol MyProtocol\n"
+  verifyFormat("@protocol MyProtocol \n"
"- (NSUInteger)numberOfThings;\n"
"@end");
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r322873 - [ClangFormat] ObjCSpaceBeforeProtocolList should be true in the google style

2018-01-18 Thread Ben Hamilton via cfe-commits
Author: benhamilton
Date: Thu Jan 18 10:37:16 2018
New Revision: 322873

URL: http://llvm.org/viewvc/llvm-project?rev=322873=rev
Log:
[ClangFormat] ObjCSpaceBeforeProtocolList should be true in the google style

Summary:
The Google style guide is neutral on whether there should be a
space before the protocol list in an Objective-C @interface or
@implementation.

The majority of Objective-C code in both Apple's public
header files and Google's open-source uses a space before
the protocol list, so this changes the google style to
default ObjCSpaceBeforeProtocolList to true.

Test Plan: make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests

Reviewers: krasimir, djasper, klimek

Reviewed By: krasimir

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTestObjC.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=322873=322872=322873=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Thu Jan 18 10:37:16 2018
@@ -694,7 +694,7 @@ FormatStyle getGoogleStyle(FormatStyle::
   GoogleStyle.IndentCaseLabels = true;
   GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
   GoogleStyle.ObjCSpaceAfterProperty = false;
-  GoogleStyle.ObjCSpaceBeforeProtocolList = false;
+  GoogleStyle.ObjCSpaceBeforeProtocolList = true;
   GoogleStyle.PointerAlignment = FormatStyle::PAS_Left;
   GoogleStyle.RawStringFormats = {{
   FormatStyle::LK_TextProto,

Modified: cfe/trunk/unittests/Format/FormatTestObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestObjC.cpp?rev=322873=322872=322873=diff
==
--- cfe/trunk/unittests/Format/FormatTestObjC.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestObjC.cpp Thu Jan 18 10:37:16 2018
@@ -271,7 +271,7 @@ TEST_F(FormatTestObjC, FormatObjCInterfa
"@end");
 
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
-  verifyFormat("@interface Foo : NSObject {\n"
+  verifyFormat("@interface Foo : NSObject  {\n"
" @public\n"
"  int field1;\n"
" @protected\n"
@@ -283,15 +283,15 @@ TEST_F(FormatTestObjC, FormatObjCInterfa
"}\n"
"+ (id)init;\n"
"@end");
-  verifyFormat("@interface Foo : Bar\n"
+  verifyFormat("@interface Foo : Bar \n"
"+ (id)init;\n"
"@end");
-  verifyFormat("@interface Foo (HackStuff)\n"
+  verifyFormat("@interface Foo (HackStuff) \n"
"+ (id)init;\n"
"@end");
   Style.BinPackParameters = false;
   Style.ColumnLimit = 80;
-  verifyFormat("@interface a ()<\n"
+  verifyFormat("@interface a () <\n"
"a,\n"
",\n"
"aa,\n"
@@ -414,7 +414,7 @@ TEST_F(FormatTestObjC, FormatObjCProtoco
"@end");
 
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
-  verifyFormat("@protocol MyProtocol\n"
+  verifyFormat("@protocol MyProtocol \n"
"- (NSUInteger)numberOfThings;\n"
"@end");
 }


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


[libcxx] r322872 - Add memory tracking

2018-01-18 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Thu Jan 18 10:37:11 2018
New Revision: 322872

URL: http://llvm.org/viewvc/llvm-project?rev=322872=rev
Log:
Add memory tracking


Modified:
libcxx/trunk/fuzzing/fuzz_test.cpp

Modified: libcxx/trunk/fuzzing/fuzz_test.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/fuzzing/fuzz_test.cpp?rev=322872=322871=322872=diff
==
--- libcxx/trunk/fuzzing/fuzz_test.cpp (original)
+++ libcxx/trunk/fuzzing/fuzz_test.cpp Thu Jan 18 10:37:11 2018
@@ -19,6 +19,8 @@
 //
 //  Each file should contain a test case.
 
+//  TODO: should add some memory tracking, too.
+
 
 #include 
 #include 
@@ -29,6 +31,78 @@
 
 #include "fuzzing.h"
 
+//   Count memory allocations 
+
+struct MemoryCounters {
+size_t totalAllocationCount;
+size_t netAllocationCount;
+size_t totalBytesAllocated;
+};
+
+MemoryCounters gMemoryCounters;
+
+void ZeroMemoryCounters() {
+gMemoryCounters.totalAllocationCount = 0;
+gMemoryCounters.netAllocationCount = 0;
+gMemoryCounters.totalBytesAllocated = 0;
+}
+
+void* operator new(std::size_t size)
+{
+if (size == 0) size = 1;
+void *p = ::malloc(size);
+if (p == NULL)
+throw std::bad_alloc();
+gMemoryCounters.totalAllocationCount += 1;
+gMemoryCounters.netAllocationCount  += 1;
+gMemoryCounters.totalBytesAllocated += size;
+return p;
+}
+
+void* operator new(std::size_t size, const std::nothrow_t&) noexcept
+{
+try { return operator new(size); }
+catch (const std::bad_alloc &) {}
+return nullptr;
+}
+
+void* operator new[](std::size_t size)
+{
+return ::operator new(size);
+}
+
+void* operator new[](std::size_t size, const std::nothrow_t&) noexcept
+{
+try { return operator new(size); }
+catch (const std::bad_alloc &) {}
+return nullptr;
+}
+
+void  operator delete(void* ptr) noexcept
+{
+if (ptr)
+::free(ptr);
+gMemoryCounters.netAllocationCount -= 1;
+}
+
+void  operator delete(void* ptr, const std::nothrow_t&) noexcept
+{
+::operator delete(ptr);
+}
+
+void  operator delete[](void* ptr) noexcept
+{
+::operator delete(ptr);
+}
+
+void  operator delete[](void* ptr, const std::nothrow_t&) noexcept
+{
+::operator delete(ptr);
+}
+
+//   End count memory allocations 
+
+
 typedef int (*FuzzProc) (const uint8_t *data, size_t size);
 
 const std::map procs = {
@@ -64,21 +138,30 @@ void test_one(const char *filename, Fuzz
 std::ifstream f (filename, std::ios::binary);
 if (!f.is_open())
 std::cerr << "## Can't open '" << filename << "'" << std::endl;
-else {
+else
+{
 typedef std::istream_iterator Iter;
 std::copy(Iter(f), Iter(), std::back_inserter(v));
 if (verbose)
 std::cout << "File '" << filename << "' contains " << v.size() << 
" entries" << std::endl;
+ZeroMemoryCounters();
 const auto start_time = std::chrono::high_resolution_clock::now();
 int ret = fp (v.data(), v.size());
 const auto finish_time = std::chrono::high_resolution_clock::now();
+MemoryCounters mc = gMemoryCounters;
 if (ret != 0)
 std::cerr << "## Failure code: " << ret << std::endl;
 if (verbose)
+{
 std::cout << "Execution time: "
 << 
std::chrono::duration_cast(finish_time - 
start_time).count()
 << " milliseconds" << std::endl;
+std::cout << "Memory: " 
+  << mc.totalBytesAllocated  << " bytes allocated ("
+  << mc.totalAllocationCount << " allocations); "
+  << mc.netAllocationCount   << " allocations remain" << 
std::endl;
 }
+}
 }
 
 void usage (const char *name)


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


[PATCH] D42187: [clang-format] Adds a canonical delimiter to raw string formatting

2018-01-18 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

lg




Comment at: lib/Format/ContinuationIndenter.cpp:1336
+  unsigned OldSuffixSize = 2 + OldDelimiter.size();
+  std::string RawText =
+  Current.TokenText.substr(OldPrefixSize).drop_back(OldSuffixSize);

Can this be a StringRef? Can RawText outlive the Current token?


Repository:
  rC Clang

https://reviews.llvm.org/D42187



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


[PATCH] D42229: [cmake] [libcxxabi] Don't print warning when tests are disabled.

2018-01-18 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322870: [cmake] [libcxxabi] Dont print warning when 
tests are disabled. (authored by dhinton, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D42229

Files:
  libcxxabi/trunk/CMakeLists.txt


Index: libcxxabi/trunk/CMakeLists.txt
===
--- libcxxabi/trunk/CMakeLists.txt
+++ libcxxabi/trunk/CMakeLists.txt
@@ -440,18 +440,21 @@
 # soname, etc...
 add_subdirectory(src)
 
-if (NOT LIBCXXABI_INCLUDE_TESTS OR (LIBCXXABI_STANDALONE_BUILD AND NOT 
LIBCXXABI_ENABLE_SHARED))
-  # We can't reasonably test the system C++ library with a static libc++abi.
-  # We either need to be able to replace libc++abi at run time (with a shared
-  # libc++abi), or we need to be able to replace the C++ runtime (with a non-
-  # standalone build).
-  message(WARNING "The libc++abi tests aren't valid when libc++abi is built "
-  "standalone (i.e. outside of llvm/projects/libcxxabi ) and "
-  "is built without a shared library.  Either build a shared "
-  "library, build libc++abi at the same time as you build "
-  "libc++, or do without testing.  No check target will be "
-  "available!")
-else()
-  add_subdirectory(test)
-  add_subdirectory(fuzz)
+if (LIBCXXABI_INCLUDE_TESTS)
+  if (LIBCXXABI_STANDALONE_BUILD AND NOT LIBCXXABI_ENABLE_SHARED)
+# We can't reasonably test the system C++ library with a static
+# libc++abi.  We either need to be able to replace libc++abi at
+# run time (with a shared libc++abi), or we need to be able to
+# replace the C++ runtime (with a non- standalone build).
+message(WARNING "The libc++abi tests aren't valid when libc++abi "
+"is built standalone (i.e. outside of "
+"llvm/projects/libcxxabi ) and is built without "
+"a shared library.  Either build a shared "
+"library, build libc++abi at the same time as "
+"you build libc++, or do without testing.  No "
+"check target will be available!")
+  else()
+add_subdirectory(test)
+add_subdirectory(fuzz)
+  endif()
 endif()


Index: libcxxabi/trunk/CMakeLists.txt
===
--- libcxxabi/trunk/CMakeLists.txt
+++ libcxxabi/trunk/CMakeLists.txt
@@ -440,18 +440,21 @@
 # soname, etc...
 add_subdirectory(src)
 
-if (NOT LIBCXXABI_INCLUDE_TESTS OR (LIBCXXABI_STANDALONE_BUILD AND NOT LIBCXXABI_ENABLE_SHARED))
-  # We can't reasonably test the system C++ library with a static libc++abi.
-  # We either need to be able to replace libc++abi at run time (with a shared
-  # libc++abi), or we need to be able to replace the C++ runtime (with a non-
-  # standalone build).
-  message(WARNING "The libc++abi tests aren't valid when libc++abi is built "
-  "standalone (i.e. outside of llvm/projects/libcxxabi ) and "
-  "is built without a shared library.  Either build a shared "
-  "library, build libc++abi at the same time as you build "
-  "libc++, or do without testing.  No check target will be "
-  "available!")
-else()
-  add_subdirectory(test)
-  add_subdirectory(fuzz)
+if (LIBCXXABI_INCLUDE_TESTS)
+  if (LIBCXXABI_STANDALONE_BUILD AND NOT LIBCXXABI_ENABLE_SHARED)
+# We can't reasonably test the system C++ library with a static
+# libc++abi.  We either need to be able to replace libc++abi at
+# run time (with a shared libc++abi), or we need to be able to
+# replace the C++ runtime (with a non- standalone build).
+message(WARNING "The libc++abi tests aren't valid when libc++abi "
+"is built standalone (i.e. outside of "
+"llvm/projects/libcxxabi ) and is built without "
+"a shared library.  Either build a shared "
+"library, build libc++abi at the same time as "
+"you build libc++, or do without testing.  No "
+"check target will be available!")
+  else()
+add_subdirectory(test)
+add_subdirectory(fuzz)
+  endif()
 endif()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxxabi] r322870 - [cmake] [libcxxabi] Don't print warning when tests are disabled.

2018-01-18 Thread Don Hinton via cfe-commits
Author: dhinton
Date: Thu Jan 18 10:29:36 2018
New Revision: 322870

URL: http://llvm.org/viewvc/llvm-project?rev=322870=rev
Log:
[cmake] [libcxxabi] Don't print warning when tests are disabled.

Summary:
Don't print, possibly erroneous, warning if
LIBCXXABI_INCLUDE_TESTS is false.

This patch fixes a problem introduced in r291367.

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

Modified:
libcxxabi/trunk/CMakeLists.txt

Modified: libcxxabi/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/CMakeLists.txt?rev=322870=322869=322870=diff
==
--- libcxxabi/trunk/CMakeLists.txt (original)
+++ libcxxabi/trunk/CMakeLists.txt Thu Jan 18 10:29:36 2018
@@ -440,18 +440,21 @@ endif()
 # soname, etc...
 add_subdirectory(src)
 
-if (NOT LIBCXXABI_INCLUDE_TESTS OR (LIBCXXABI_STANDALONE_BUILD AND NOT 
LIBCXXABI_ENABLE_SHARED))
-  # We can't reasonably test the system C++ library with a static libc++abi.
-  # We either need to be able to replace libc++abi at run time (with a shared
-  # libc++abi), or we need to be able to replace the C++ runtime (with a non-
-  # standalone build).
-  message(WARNING "The libc++abi tests aren't valid when libc++abi is built "
-  "standalone (i.e. outside of llvm/projects/libcxxabi ) and "
-  "is built without a shared library.  Either build a shared "
-  "library, build libc++abi at the same time as you build "
-  "libc++, or do without testing.  No check target will be "
-  "available!")
-else()
-  add_subdirectory(test)
-  add_subdirectory(fuzz)
+if (LIBCXXABI_INCLUDE_TESTS)
+  if (LIBCXXABI_STANDALONE_BUILD AND NOT LIBCXXABI_ENABLE_SHARED)
+# We can't reasonably test the system C++ library with a static
+# libc++abi.  We either need to be able to replace libc++abi at
+# run time (with a shared libc++abi), or we need to be able to
+# replace the C++ runtime (with a non- standalone build).
+message(WARNING "The libc++abi tests aren't valid when libc++abi "
+"is built standalone (i.e. outside of "
+"llvm/projects/libcxxabi ) and is built without "
+"a shared library.  Either build a shared "
+"library, build libc++abi at the same time as "
+"you build libc++, or do without testing.  No "
+"check target will be available!")
+  else()
+add_subdirectory(test)
+add_subdirectory(fuzz)
+  endif()
 endif()


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


[PATCH] D42073: [clangd] Query all visible scopes based on all visible using-namespace declarationsand containing namespace for global qualified code completion.

2018-01-18 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clangd/CodeComplete.cpp:270
+  /// namespace scopes which are visible to the qualified-id completion token.
+  std::vector Scopes;
+};

ilya-biryukov wrote:
> sammccall wrote:
> > Just to check, if the user types:
> > "vec" --> None
> > "::vec" --> {""}
> > "std::vec" --> {"std"}
> > "using namespace std; vec" --> None
> > "using namespace std; ::vec" --> {"", "std"}
> > 
> > is this right?
> I think the idea was to have (I only highlight the differences):
> "vec" --> {""}
> "using namespace std; vec" --> {"", "std"}
> 
> @hokein , or am I getting it wrong?
You're probably right, just want to be sure we're talking about the same thing.

There's two layers here: the context detected from sema, and what we're going 
to send the index. The layering is more relevant now that more of this moves 
out of clangd.

for "vec", we should be sending {""} to the index for now, and later move 
towards doing global completion.
But if possible the detection code should report None, and the query-index code 
should translate it - there's no reason the detection code needs to be wrong 
just because clangd can't do qualifier insertion/smart ranking/etc.

That said, per our discussion this morning, the detected state shouldn't really 
be Optional, but rather struct { vector 
AccessibleScope, optional UnresolvedQualifier } or something like 
that...


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42073



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


[PATCH] D42181: [clangd] Merge index-provided completions with those from Sema.

2018-01-18 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 130440.
sammccall added a comment.

Converted the big codeComplete function to a CodeCompleteFlow class


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42181

Files:
  clangd/CodeComplete.cpp
  clangd/FuzzyMatch.h
  unittests/clangd/CodeCompleteTests.cpp

Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -17,7 +17,6 @@
 #include "SourceCode.h"
 #include "TestFS.h"
 #include "index/MemIndex.h"
-#include "index/Merge.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -82,7 +81,7 @@
   return arg.insertTextFormat == clangd::InsertTextFormat::Snippet &&
  arg.insertText == Text;
 }
-MATCHER(FilterContainsName, "") {
+MATCHER(NameContainsFilter, "") {
   if (arg.filterText.empty())
 return true;
   return llvm::StringRef(arg.insertText).contains(arg.filterText);
@@ -129,30 +128,53 @@
   .get()
   .second.Value;
   // Sanity-check that filterText is valid.
-  EXPECT_THAT(CompletionList.items, Each(FilterContainsName()));
+  EXPECT_THAT(CompletionList.items, Each(NameContainsFilter()));
   return CompletionList;
 }
 
+std::string replace(StringRef Haystack, StringRef Needle, StringRef Repl) {
+  std::string Result;
+  raw_string_ostream OS(Result);
+  std::pair Split;
+  for (Split = Haystack.split(Needle); !Split.second.empty();
+   Split = Split.first.split(Needle))
+OS << Split.first << Repl;
+  Result += Split.first;
+  OS.flush();
+  return Result;
+}
+
 // Helpers to produce fake index symbols for memIndex() or completions().
-Symbol sym(StringRef QName, index::SymbolKind Kind) {
+// USRFormat is a regex replacement string for the unqualified part of the USR.
+Symbol sym(StringRef QName, index::SymbolKind Kind, StringRef USRFormat) {
   Symbol Sym;
-  Sym.ID = SymbolID(QName);
+  std::string USR = "c:"; // We synthesize a few simple cases of USRs by hand!
   size_t Pos = QName.rfind("::");
   if (Pos == llvm::StringRef::npos) {
 Sym.Name = QName;
 Sym.Scope = "";
   } else {
 Sym.Name = QName.substr(Pos + 2);
 Sym.Scope = QName.substr(0, Pos);
+USR += "@N@" + replace(Sym.Scope, "::", "@N@"); // ns:: -> @N@ns
   }
+  USR += Regex("^.*$").sub(USRFormat, Sym.Name); // e.g. func -> @F@func#
+  Sym.ID = SymbolID(USR);
   Sym.CompletionPlainInsertText = Sym.Name;
+  Sym.CompletionSnippetInsertText = Sym.Name;
   Sym.CompletionLabel = Sym.Name;
   Sym.SymInfo.Kind = Kind;
   return Sym;
 }
-Symbol func(StringRef Name) { return sym(Name, index::SymbolKind::Function); }
-Symbol cls(StringRef Name) { return sym(Name, index::SymbolKind::Class); }
-Symbol var(StringRef Name) { return sym(Name, index::SymbolKind::Variable); }
+Symbol func(StringRef Name) { // Assumes the function has no args.
+  return sym(Name, index::SymbolKind::Function, "@F@\\0#"); // no args
+}
+Symbol cls(StringRef Name) {
+  return sym(Name, index::SymbolKind::Class, "@S@\\0@S@\\0");
+}
+Symbol var(StringRef Name) {
+  return sym(Name, index::SymbolKind::Variable, "@\\0");
+}
 
 TEST(CompletionTest, Limit) {
   clangd::CodeCompleteOptions Opts;
@@ -226,7 +248,7 @@
 ClassWithMembers().^
   }
   )cpp",
-  /*IndexSymbols=*/{}, Opts);
+  {cls("IndexClass"), var("index_var"), func("index_func")}, Opts);
 
   // Class members. The only items that must be present in after-dot
   // completion.
@@ -236,9 +258,11 @@
   EXPECT_IFF(Opts.IncludeIneligibleResults, Results.items,
  Has("private_field"));
   // Global items.
-  EXPECT_THAT(Results.items, Not(AnyOf(Has("global_var"), Has("global_func"),
-   Has("global_func()"), Has("GlobalClass"),
-   Has("MACRO"), Has("LocalClass";
+  EXPECT_THAT(
+  Results.items,
+  Not(AnyOf(Has("global_var"), Has("index_var"), Has("global_func"),
+Has("global_func()"), Has("index_func"), Has("GlobalClass"),
+Has("IndexClass"), Has("MACRO"), Has("LocalClass";
   // There should be no code patterns (aka snippets) in after-dot
   // completion. At least there aren't any we're aware of.
   EXPECT_THAT(Results.items, Not(Contains(Kind(CompletionItemKind::Snippet;
@@ -271,16 +295,17 @@
 ^
   }
   )cpp",
-  /*IndexSymbols=*/{}, Opts);
+  {cls("IndexClass"), var("index_var"), func("index_func")}, Opts);
 
   // Class members. Should never be present in global completions.
   EXPECT_THAT(Results.items,
   Not(AnyOf(Has("method"), Has("method()"), Has("field";
   // Global items.
   EXPECT_THAT(Results.items,
-  AllOf(Has("global_var"),
+  AllOf(Has("global_var"), Has("index_var"),
 Has(Opts.EnableSnippets ? "global_func()" : "global_func"),
-Has("GlobalClass")));
+

[PATCH] D42249: [CodeGenCXX] annotate a GEP to a derived class with 'inbounds' (PR35909)

2018-01-18 Thread Sanjay Patel via Phabricator via cfe-commits
spatel created this revision.
spatel added reviewers: efriedma, hfinkel, rjmccall, rsmith.
Herald added a subscriber: mcrosier.

I'm not sure if the code comment is adequate or even correct, but hopefully the 
change itself is valid.

Eli cited this section of the standard in PR35909 ( 
https://bugs.llvm.org/show_bug.cgi?id=35909 ):
[expr.static.cast] p11: "If the prvalue of type “pointer to cv1 B” points to a 
B that is actually a subobject of an object of type D, the resulting pointer 
points to the enclosing object of type D. Otherwise, the behavior is undefined."

In the motivating case in the bug report, LLVM can't eliminate a nullptr check 
because a GEP is not marked with 'inbounds':

  class A {
  int a;
  };
  class B {
  int b;
  public:
  A *getAsA();
  };
  class X : public A, public B {
  int x;
  };
  
  A *B::getAsA() {
  if (b == 42) {
  auto temp = static_cast(this);
  //__builtin_assume(temp != nullptr);
  return temp;
  }
  return nullptr;
  }
  
  void helper(A *);
  
  void test(B *b) {
  auto temp = b->getAsA();
  if (temp)
  return helper(temp);
  }


https://reviews.llvm.org/D42249

Files:
  lib/CodeGen/CGClass.cpp
  test/CodeGenCXX/catch-undef-behavior.cpp


Index: test/CodeGenCXX/catch-undef-behavior.cpp
===
--- test/CodeGenCXX/catch-undef-behavior.cpp
+++ test/CodeGenCXX/catch-undef-behavior.cpp
@@ -371,7 +371,7 @@
 void downcast_pointer(B *b) {
   (void) static_cast(b);
   // Alignment check from EmitTypeCheck(TCK_DowncastPointer, ...)
-  // CHECK: [[SUB:%[.a-z0-9]*]] = getelementptr i8, i8* {{.*}}, i64 -16
+  // CHECK: [[SUB:%[.a-z0-9]*]] = getelementptr inbounds i8, i8* {{.*}}, i64 
-16
   // CHECK-NEXT: [[C:%.+]] = bitcast i8* [[SUB]] to %class.C*
   // null check goes here
   // CHECK: [[FROM_PHI:%.+]] = phi %class.C* [ [[C]], {{.*}} ], {{.*}}
@@ -388,7 +388,7 @@
 void downcast_reference(B ) {
   (void) static_cast(b);
   // Alignment check from EmitTypeCheck(TCK_DowncastReference, ...)
-  // CHECK:  [[SUB:%[.a-z0-9]*]] = getelementptr i8, i8* {{.*}}, i64 -16
+  // CHECK:  [[SUB:%[.a-z0-9]*]] = getelementptr inbounds i8, i8* {{.*}}, 
i64 -16
   // CHECK-NEXT: [[C:%.+]] = bitcast i8* [[SUB]] to %class.C*
   // Objectsize check goes here
   // CHECK:  [[C_INT:%.+]] = ptrtoint %class.C* [[C]] to i64
Index: lib/CodeGen/CGClass.cpp
===
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -406,8 +406,10 @@
 
   // Apply the offset.
   llvm::Value *Value = Builder.CreateBitCast(BaseAddr.getPointer(), Int8PtrTy);
-  Value = Builder.CreateGEP(Value, Builder.CreateNeg(NonVirtualOffset),
-"sub.ptr");
+
+  // The GEP is to a derived object, so this GEP must be 'inbounds'.
+  Value = Builder.CreateInBoundsGEP(Value, Builder.CreateNeg(NonVirtualOffset),
+"sub.ptr");
 
   // Just cast.
   Value = Builder.CreateBitCast(Value, DerivedPtrTy);


Index: test/CodeGenCXX/catch-undef-behavior.cpp
===
--- test/CodeGenCXX/catch-undef-behavior.cpp
+++ test/CodeGenCXX/catch-undef-behavior.cpp
@@ -371,7 +371,7 @@
 void downcast_pointer(B *b) {
   (void) static_cast(b);
   // Alignment check from EmitTypeCheck(TCK_DowncastPointer, ...)
-  // CHECK: [[SUB:%[.a-z0-9]*]] = getelementptr i8, i8* {{.*}}, i64 -16
+  // CHECK: [[SUB:%[.a-z0-9]*]] = getelementptr inbounds i8, i8* {{.*}}, i64 -16
   // CHECK-NEXT: [[C:%.+]] = bitcast i8* [[SUB]] to %class.C*
   // null check goes here
   // CHECK: [[FROM_PHI:%.+]] = phi %class.C* [ [[C]], {{.*}} ], {{.*}}
@@ -388,7 +388,7 @@
 void downcast_reference(B ) {
   (void) static_cast(b);
   // Alignment check from EmitTypeCheck(TCK_DowncastReference, ...)
-  // CHECK:  [[SUB:%[.a-z0-9]*]] = getelementptr i8, i8* {{.*}}, i64 -16
+  // CHECK:  [[SUB:%[.a-z0-9]*]] = getelementptr inbounds i8, i8* {{.*}}, i64 -16
   // CHECK-NEXT: [[C:%.+]] = bitcast i8* [[SUB]] to %class.C*
   // Objectsize check goes here
   // CHECK:  [[C_INT:%.+]] = ptrtoint %class.C* [[C]] to i64
Index: lib/CodeGen/CGClass.cpp
===
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -406,8 +406,10 @@
 
   // Apply the offset.
   llvm::Value *Value = Builder.CreateBitCast(BaseAddr.getPointer(), Int8PtrTy);
-  Value = Builder.CreateGEP(Value, Builder.CreateNeg(NonVirtualOffset),
-"sub.ptr");
+
+  // The GEP is to a derived object, so this GEP must be 'inbounds'.
+  Value = Builder.CreateInBoundsGEP(Value, Builder.CreateNeg(NonVirtualOffset),
+"sub.ptr");
 
   // Just cast.
   Value = Builder.CreateBitCast(Value, DerivedPtrTy);
___
cfe-commits mailing list

[PATCH] D42248: [LangOpts] Add a LangOpt to represent "#pragma region" support.

2018-01-18 Thread Matt Davis via Phabricator via cfe-commits
mattd created this revision.
mattd added reviewers: rnk, rsmith.

Both MS and PS4 targets are capable of recognizing the
existence of:  #pragma region, #pragma endregion.

This patch adds a LangOpt and sets the value based on target 
information or MS compatibility. In the case of PS4 or MS we
should avoid emitting "unknown pragma" warnings for regions.
This change prevents that situation.


https://reviews.llvm.org/D42248

Files:
  include/clang/Basic/LangOptions.def
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/Pragma.cpp
  test/Frontend/region-pragmas.c


Index: test/Frontend/region-pragmas.c
===
--- test/Frontend/region-pragmas.c
+++ test/Frontend/region-pragmas.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple x86_64-scei-ps4 -Wall -verify %s
+// RUN: %clang_cc1 -fms-compatibility -Wall -verify %s
+// RUN: %clang_cc1 -Wall -Wno-unknown-pragmas -verify %s
+// expected-no-diagnostics
+
+#pragma region foo
+#pragma endregion foo
Index: lib/Lex/Pragma.cpp
===
--- lib/Lex/Pragma.cpp
+++ lib/Lex/Pragma.cpp
@@ -1781,6 +1781,10 @@
   if (LangOpts.MicrosoftExt) {
 AddPragmaHandler(new PragmaWarningHandler());
 AddPragmaHandler(new PragmaIncludeAliasHandler());
+  }
+
+  // Region support.
+  if (LangOpts.MicrosoftPragmaRegion) {
 AddPragmaHandler(new PragmaRegionHandler("region"));
 AddPragmaHandler(new PragmaRegionHandler("endregion"));
   }
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2160,6 +2160,7 @@
 
   Opts.MSVCCompat = Args.hasArg(OPT_fms_compatibility);
   Opts.MicrosoftExt = Opts.MSVCCompat || Args.hasArg(OPT_fms_extensions);
+  Opts.MicrosoftPragmaRegion = Opts.MicrosoftExt || T.isPS4();
   Opts.AsmBlocks = Args.hasArg(OPT_fasm_blocks) || Opts.MicrosoftExt;
   Opts.MSCompatibilityVersion = 0;
   if (const Arg *A = Args.getLastArg(OPT_fms_compatibility_version)) {
Index: include/clang/Basic/LangOptions.def
===
--- include/clang/Basic/LangOptions.def
+++ include/clang/Basic/LangOptions.def
@@ -85,6 +85,7 @@
 LANGOPT(C17   , 1, 0, "C17")
 LANGOPT(MSVCCompat, 1, 0, "Microsoft Visual C++ full compatibility 
mode")
 LANGOPT(MicrosoftExt  , 1, 0, "Microsoft C++ extensions")
+BENIGN_LANGOPT(MicrosoftPragmaRegion, 1, 0, "region pragma support")
 LANGOPT(AsmBlocks , 1, 0, "Microsoft inline asm blocks")
 LANGOPT(Borland   , 1, 0, "Borland extensions")
 LANGOPT(CPlusPlus , 1, 0, "C++")


Index: test/Frontend/region-pragmas.c
===
--- test/Frontend/region-pragmas.c
+++ test/Frontend/region-pragmas.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple x86_64-scei-ps4 -Wall -verify %s
+// RUN: %clang_cc1 -fms-compatibility -Wall -verify %s
+// RUN: %clang_cc1 -Wall -Wno-unknown-pragmas -verify %s
+// expected-no-diagnostics
+
+#pragma region foo
+#pragma endregion foo
Index: lib/Lex/Pragma.cpp
===
--- lib/Lex/Pragma.cpp
+++ lib/Lex/Pragma.cpp
@@ -1781,6 +1781,10 @@
   if (LangOpts.MicrosoftExt) {
 AddPragmaHandler(new PragmaWarningHandler());
 AddPragmaHandler(new PragmaIncludeAliasHandler());
+  }
+
+  // Region support.
+  if (LangOpts.MicrosoftPragmaRegion) {
 AddPragmaHandler(new PragmaRegionHandler("region"));
 AddPragmaHandler(new PragmaRegionHandler("endregion"));
   }
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2160,6 +2160,7 @@
 
   Opts.MSVCCompat = Args.hasArg(OPT_fms_compatibility);
   Opts.MicrosoftExt = Opts.MSVCCompat || Args.hasArg(OPT_fms_extensions);
+  Opts.MicrosoftPragmaRegion = Opts.MicrosoftExt || T.isPS4();
   Opts.AsmBlocks = Args.hasArg(OPT_fasm_blocks) || Opts.MicrosoftExt;
   Opts.MSCompatibilityVersion = 0;
   if (const Arg *A = Args.getLastArg(OPT_fms_compatibility_version)) {
Index: include/clang/Basic/LangOptions.def
===
--- include/clang/Basic/LangOptions.def
+++ include/clang/Basic/LangOptions.def
@@ -85,6 +85,7 @@
 LANGOPT(C17   , 1, 0, "C17")
 LANGOPT(MSVCCompat, 1, 0, "Microsoft Visual C++ full compatibility mode")
 LANGOPT(MicrosoftExt  , 1, 0, "Microsoft C++ extensions")
+BENIGN_LANGOPT(MicrosoftPragmaRegion, 1, 0, "region pragma support")
 LANGOPT(AsmBlocks , 1, 0, "Microsoft inline asm blocks")
 LANGOPT(Borland   , 1, 0, "Borland extensions")
 LANGOPT(CPlusPlus , 1, 0, "C++")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D41727: [libcxx] Disable tautological-type-limit-compare warning

2018-01-18 Thread Brian Cain via Phabricator via cfe-commits
bcain updated this revision to Diff 130431.
bcain added a comment.
Herald added a subscriber: cfe-commits.

Changed per review


Repository:
  rCXX libc++

https://reviews.llvm.org/D41727

Files:
  libcxx/utils/libcxx/test/config.py


Index: libcxx/utils/libcxx/test/config.py
===
--- libcxx/utils/libcxx/test/config.py
+++ libcxx/utils/libcxx/test/config.py
@@ -903,6 +903,7 @@
 if self.cxx.hasWarningFlag('-Wuser-defined-warnings'):
 self.cxx.warning_flags += ['-Wuser-defined-warnings']
 self.config.available_features.add('diagnose-if-support')
+
self.cxx.addWarningFlagIfSupported('-Wno-tautological-type-limit-compare')
 self.cxx.addWarningFlagIfSupported('-Wshadow')
 self.cxx.addWarningFlagIfSupported('-Wno-unused-command-line-argument')
 self.cxx.addWarningFlagIfSupported('-Wno-attributes')


Index: libcxx/utils/libcxx/test/config.py
===
--- libcxx/utils/libcxx/test/config.py
+++ libcxx/utils/libcxx/test/config.py
@@ -903,6 +903,7 @@
 if self.cxx.hasWarningFlag('-Wuser-defined-warnings'):
 self.cxx.warning_flags += ['-Wuser-defined-warnings']
 self.config.available_features.add('diagnose-if-support')
+self.cxx.addWarningFlagIfSupported('-Wno-tautological-type-limit-compare')
 self.cxx.addWarningFlagIfSupported('-Wshadow')
 self.cxx.addWarningFlagIfSupported('-Wno-unused-command-line-argument')
 self.cxx.addWarningFlagIfSupported('-Wno-attributes')
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40580: [clang-tidy] Adding Fuchsia checker for multiple inheritance

2018-01-18 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 130427.
juliehockett added a comment.

Rebasing from trunk


https://reviews.llvm.org/D40580

Files:
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tidy/fuchsia/MultipleInheritanceCheck.cpp
  clang-tidy/fuchsia/MultipleInheritanceCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-multiple-inheritance.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/fuchsia-multiple-inheritance.cpp

Index: test/clang-tidy/fuchsia-multiple-inheritance.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-multiple-inheritance.cpp
@@ -0,0 +1,131 @@
+// RUN: %check_clang_tidy %s fuchsia-multiple-inheritance %t
+
+class Base_A {
+public:
+  virtual int foo() { return 0; }
+};
+
+class Base_B {
+public:
+  virtual int bar() { return 0; }
+};
+
+class Base_A_child : public Base_A {
+public:
+  virtual int baz() { return 0; }
+};
+
+class Interface_A {
+public:
+  virtual int foo() = 0;
+};
+
+class Interface_B {
+public:
+  virtual int bar() = 0;
+};
+
+class Interface_C {
+public:
+  virtual int blat() = 0;
+};
+
+class Interface_A_with_member {
+public:
+  virtual int foo() = 0;
+  int val = 0;
+};
+
+class Interface_with_A_Parent : public Base_A {
+public:
+  virtual int baz() = 0;
+};
+
+// Inherits from multiple concrete classes.
+// CHECK-MESSAGES: [[@LINE+2]]:1: warning: inheriting mulitple classes which aren't pure virtual is discouraged [fuchsia-multiple-inheritance]
+// CHECK-NEXT: class Bad_Child1 : public Base_A, Base_B {};
+class Bad_Child1 : public Base_A, Base_B {};
+
+// CHECK-MESSAGES: [[@LINE+1]]:1: warning: inheriting mulitple classes which aren't pure virtual is discouraged [fuchsia-multiple-inheritance]
+class Bad_Child2 : public Base_A, Interface_A_with_member {
+  virtual int foo() override { return 0; }
+};
+
+// CHECK-MESSAGES: [[@LINE+2]]:1: warning: inheriting mulitple classes which aren't pure virtual is discouraged [fuchsia-multiple-inheritance]
+// CHECK-NEXT: class Bad_Child3 : public Interface_with_A_Parent, Base_B {
+class Bad_Child3 : public Interface_with_A_Parent, Base_B {
+  virtual int baz() override { return 0; }
+};
+
+// Easy cases of single inheritance
+class Simple_Child1 : public Base_A {};
+class Simple_Child2 : public Interface_A {
+  virtual int foo() override { return 0; }
+};
+
+// Valid uses of multiple inheritance
+class Good_Child1 : public Interface_A, Interface_B {
+  virtual int foo() override { return 0; }
+  virtual int bar() override { return 0; }
+};
+
+class Good_Child2 : public Base_A, Interface_B {
+  virtual int bar() override { return 0; }
+};
+
+class Good_Child3 : public Base_A_child, Interface_C, Interface_B {
+  virtual int bar() override { return 0; }
+  virtual int blat() override { return 0; }
+};
+
+struct B1 { int x; };
+struct B2 { int x;};
+// CHECK-MESSAGES: [[@LINE+2]]:1: warning: inheriting mulitple classes which aren't pure virtual is discouraged [fuchsia-multiple-inheritance]
+// CHECK-NEXT: struct D : B1, B2 {};
+struct D1 : B1, B2 {};
+
+struct Base1 { virtual void foo() = 0; };
+struct V1 : virtual Base1 {};
+struct V2 : virtual Base1 {};
+struct D2 : V1, V2 {};
+
+struct Base2 { virtual void foo(); };
+struct V3 : virtual Base2 {};
+struct V4 : virtual Base2 {};
+struct D3 : V3, V4 {};
+
+struct Base3 {};
+struct V5 : virtual Base3 { virtual void f(); };
+struct V6 : virtual Base3 { virtual void g(); };
+// CHECK-MESSAGES: [[@LINE+2]]:1: warning: inheriting mulitple classes which aren't pure virtual is discouraged [fuchsia-multiple-inheritance]
+// CHECK-NEXT: struct D4 : V5, V6 {};
+struct D4 : V5, V6 {};
+
+struct Base4 {};
+struct V7 : virtual Base4 { virtual void f() = 0; };
+struct V8 : virtual Base4 { virtual void g() = 0; };
+struct D5 : V7, V8 {};
+
+struct Base5 { virtual void f() = 0; };
+struct V9 : virtual Base5 { virtual void f(); };
+struct V10 : virtual Base5 { virtual void g() = 0; };
+struct D6 : V9, V10 {};
+
+struct Base6 { virtual void f(); };
+struct Base7 { virtual void g(); };
+struct V15 : virtual Base6 { virtual void f() = 0; };
+struct V16 : virtual Base7 { virtual void g() = 0; };
+// CHECK-MESSAGES: [[@LINE+2]]:1: warning: inheriting mulitple classes which aren't pure virtual is discouraged [fuchsia-multiple-inheritance]
+// CHECK-NEXT: struct D9 : V15, V16 {};
+struct D9 : V15, V16 {};
+
+struct Static_Base { static void foo(); };
+struct V11 : virtual Static_Base {};
+struct V12 : virtual Static_Base {};
+struct D7 : V11, V12 {};
+
+struct Static_Base_2 {};
+struct V13 : virtual Static_Base_2 { static void f(); };
+struct V14 : virtual Static_Base_2 { static void g(); };
+struct D8 : V13, V14 {};
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -70,6 +70,7 @@
cppcoreguidelines-slicing

[PATCH] D41947: Provide default virtual filesystem argument to ClangTool constructor

2018-01-18 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: include/clang/Tooling/Tooling.h:299
   /// clang modules.
+  /// \param BaseFS Base virtual filesystem used for OverlayFileSystem creation
   ClangTool(const CompilationDatabase ,

NIT: LLVM coding style requires full stop at the end of comments.
Could we also rephrase it to not mention the `OverlayFileSystem`, the important 
bit seems to be that we use it for all fs operations. Something like:
```
/// \param BaseFS VFS used for all underlying file accesses when running the 
tool.
```



Repository:
  rC Clang

https://reviews.llvm.org/D41947



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


[PATCH] D41594: Support `ivfsoverlay` option in Tooling

2018-01-18 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

With https://reviews.llvm.org/D41947 in place, do we still need this change? Or 
can it be "abandoned" now?


Repository:
  rC Clang

https://reviews.llvm.org/D41594



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


[PATCH] D42173: [clangd] Simplify code handling compile commands

2018-01-18 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 130428.
ilya-biryukov marked 7 inline comments as done.
ilya-biryukov added a comment.
Herald added a subscriber: ioeric.

Addressing review comments


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42173

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/ClangdUnitStore.cpp
  clangd/ClangdUnitStore.h

Index: clangd/ClangdUnitStore.h
===
--- clangd/ClangdUnitStore.h
+++ clangd/ClangdUnitStore.h
@@ -32,42 +32,19 @@
 
   std::shared_ptr
   getOrCreateFile(PathRef File, PathRef ResourceDir,
-  GlobalCompilationDatabase , bool StorePreamblesInMemory,
+  bool StorePreamblesInMemory,
   std::shared_ptr PCHs) {
 std::lock_guard Lock(Mutex);
-
 auto It = OpenedFiles.find(File);
 if (It == OpenedFiles.end()) {
-  auto Command = getCompileCommand(CDB, File, ResourceDir);
-
   It = OpenedFiles
-   .try_emplace(File, CppFile::Create(File, std::move(Command),
-  StorePreamblesInMemory,
+   .try_emplace(File, CppFile::Create(File, StorePreamblesInMemory,
   std::move(PCHs), ASTCallback))
.first;
 }
 return It->second;
   }
 
-  struct RecreateResult {
-/// A CppFile, stored in this CppFileCollection for the corresponding
-/// filepath after calling recreateFileIfCompileCommandChanged.
-std::shared_ptr FileInCollection;
-/// If a new CppFile had to be created to account for changed
-/// CompileCommand, a previous CppFile instance will be returned in this
-/// field.
-std::shared_ptr RemovedFile;
-  };
-
-  /// Similar to getOrCreateFile, but will replace a current CppFile for \p File
-  /// with a new one if CompileCommand, provided by \p CDB has changed.
-  /// If a currently stored CppFile had to be replaced, the previous instance
-  /// will be returned in RecreateResult.RemovedFile.
-  RecreateResult recreateFileIfCompileCommandChanged(
-  PathRef File, PathRef ResourceDir, GlobalCompilationDatabase ,
-  bool StorePreamblesInMemory,
-  std::shared_ptr PCHs);
-
   std::shared_ptr getFile(PathRef File) {
 std::lock_guard Lock(Mutex);
 
@@ -82,12 +59,6 @@
   std::shared_ptr removeIfPresent(PathRef File);
 
 private:
-  tooling::CompileCommand getCompileCommand(GlobalCompilationDatabase ,
-PathRef File, PathRef ResourceDir);
-
-  bool compileCommandsAreEqual(tooling::CompileCommand const ,
-   tooling::CompileCommand const );
-
   std::mutex Mutex;
   llvm::StringMap OpenedFiles;
   ASTParsedCallback ASTCallback;
Index: clangd/ClangdUnitStore.cpp
===
--- clangd/ClangdUnitStore.cpp
+++ clangd/ClangdUnitStore.cpp
@@ -25,53 +25,3 @@
   OpenedFiles.erase(It);
   return Result;
 }
-
-CppFileCollection::RecreateResult
-CppFileCollection::recreateFileIfCompileCommandChanged(
-PathRef File, PathRef ResourceDir, GlobalCompilationDatabase ,
-bool StorePreamblesInMemory, std::shared_ptr PCHs) {
-  auto NewCommand = getCompileCommand(CDB, File, ResourceDir);
-
-  std::lock_guard Lock(Mutex);
-
-  RecreateResult Result;
-
-  auto It = OpenedFiles.find(File);
-  if (It == OpenedFiles.end()) {
-It = OpenedFiles
- .try_emplace(File, CppFile::Create(File, std::move(NewCommand),
-StorePreamblesInMemory,
-std::move(PCHs), ASTCallback))
- .first;
-  } else if (!compileCommandsAreEqual(It->second->getCompileCommand(),
-  NewCommand)) {
-Result.RemovedFile = std::move(It->second);
-It->second =
-CppFile::Create(File, std::move(NewCommand), StorePreamblesInMemory,
-std::move(PCHs), ASTCallback);
-  }
-  Result.FileInCollection = It->second;
-  return Result;
-}
-
-tooling::CompileCommand
-CppFileCollection::getCompileCommand(GlobalCompilationDatabase ,
- PathRef File, PathRef ResourceDir) {
-  llvm::Optional C = CDB.getCompileCommand(File);
-  if (!C) // FIXME: Suppress diagnostics? Let the user know?
-C = CDB.getFallbackCommand(File);
-
-  // Inject the resource dir.
-  // FIXME: Don't overwrite it if it's already there.
-  C->CommandLine.push_back("-resource-dir=" + ResourceDir.str());
-  return std::move(*C);
-}
-
-bool CppFileCollection::compileCommandsAreEqual(
-tooling::CompileCommand const , tooling::CompileCommand const ) {
-  // tooling::CompileCommand.Output is ignored, it's not relevant for clangd.
-  return LHS.Directory == RHS.Directory &&
- LHS.CommandLine.size() == RHS.CommandLine.size() 

[PATCH] D42173: [clangd] Simplify code handling compile commands

2018-01-18 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/ClangdServer.cpp:35
 
+tooling::CompileCommand getCompileCommand(GlobalCompilationDatabase ,
+  PathRef File, PathRef ResourceDir) {

sammccall wrote:
> This seems like something of an odd fit: the clangdserver both produces and 
> consumes the compile commands, but ClangdUnit is responsible for storing it?
> 
> Are we sure it wouldn't be clearer to keep the "get compile command" action 
> in clangd unit (and propagate the "should rescan" flag), and just encapsulate 
> the resource-dir/fallback logic a bit better?
I've put the command into `ClangdUnit` to not change the code consuming compile 
commands (this is where you currently get compile commands from).

The final goal is to remove compile command from `ClangdUnit` and store it 
beside the contents of the file (somewhere inside ClangdServer or its component 
that manages the resources), ClangdUnit will only manage the built 
ASTs/Preambles.
This is what `ParseInputs` is for, it captures all things necessary to build 
AST/Preamble. When we'll start dropping ASTs for non-accessed files, we could 
be storing ParseInputs instead to be able to recreate the ASTs when necessary.



Comment at: clangd/ClangdServer.cpp:336
+  assert(Resources->getLatestCommand() &&
+ "CppFile is in inconsistent state, missing CompileCommand");
+  tooling::CompileCommand CompileCommand = *Resources->getLatestCommand();

sammccall wrote:
> what's inconsistent about this state? (and above)
There's an invariant that if a file is tracked, its compile command in CppFile 
should be set.
E.g., `!!(Untis.getFile(File))  == 
!!(Untis.getFile(File))->getLatestCompileCommand`.

We should probably spell it out explicitly in the assertion message. E.g. 
`"getFile() must only return files with populated commands"`
WDYT?



Comment at: clangd/ClangdServer.h:335
+  Tagged TaggedFS,
+  bool UpdateCompileCommand);
 

sammccall wrote:
> The name `UpdateCompileCommand` is confusing in the case that this file 
> hasn't been seen: it's not obvious whether you have to pass true, or whether 
> it doesn't matter.
> 
> Consider `AllowCachedFlags`, and inverting the sense?
> At least for me, it's more obvious that this flag is ignored if the cache is 
> empty.
> (or AllowCachedCompileCommand, which is a bit long for my taste, or 
> AllowCachedCommand, which is a bit vague)
I like `CachedFlags`, but it also seems a bit vague in the same sense that  
`CachedCommand` is vague.
I've opted for `AllowCachedCompileFlags`, it's long but shouldn't cause any 
confusion.



Comment at: clangd/ClangdUnit.h:67
+
+  /// Compilation arguments.
+  tooling::CompileCommand CompileCommand;

sammccall wrote:
> these comments just echo the type/name, remove?
Sorry, I thought I removed them prior to doing the commit.
Thanks for spotting that.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42173



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


[libcxx] r322864 - Use high_resolution_clock instead of steady_clock. Also now builds with gcc 7.2 (for comparison purposes)

2018-01-18 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Thu Jan 18 09:01:34 2018
New Revision: 322864

URL: http://llvm.org/viewvc/llvm-project?rev=322864=rev
Log:
Use high_resolution_clock instead of steady_clock. Also now builds with gcc 7.2 
(for comparison purposes)

Modified:
libcxx/trunk/fuzzing/fuzz_test.cpp

Modified: libcxx/trunk/fuzzing/fuzz_test.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/fuzzing/fuzz_test.cpp?rev=322864=322863=322864=diff
==
--- libcxx/trunk/fuzzing/fuzz_test.cpp (original)
+++ libcxx/trunk/fuzzing/fuzz_test.cpp Thu Jan 18 09:01:34 2018
@@ -22,6 +22,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -68,9 +69,9 @@ void test_one(const char *filename, Fuzz
 std::copy(Iter(f), Iter(), std::back_inserter(v));
 if (verbose)
 std::cout << "File '" << filename << "' contains " << v.size() << 
" entries" << std::endl;
-const auto start_time = std::chrono::steady_clock::now();
+const auto start_time = std::chrono::high_resolution_clock::now();
 int ret = fp (v.data(), v.size());
-const auto finish_time = std::chrono::steady_clock::now();
+const auto finish_time = std::chrono::high_resolution_clock::now();
 if (ret != 0)
 std::cerr << "## Failure code: " << ret << std::endl;
 if (verbose)


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


[libcxx] r322863 - A simple program for testing OSS-Fuzz test cases locally.

2018-01-18 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Thu Jan 18 08:52:19 2018
New Revision: 322863

URL: http://llvm.org/viewvc/llvm-project?rev=322863=rev
Log:
A simple program for testing OSS-Fuzz test cases locally.

Added:
libcxx/trunk/fuzzing/fuzz_test.cpp

Added: libcxx/trunk/fuzzing/fuzz_test.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/fuzzing/fuzz_test.cpp?rev=322863=auto
==
--- libcxx/trunk/fuzzing/fuzz_test.cpp (added)
+++ libcxx/trunk/fuzzing/fuzz_test.cpp Thu Jan 18 08:52:19 2018
@@ -0,0 +1,111 @@
+// -*- C++ -*-
+//===- fuzz_test.cpp 
--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+//  A simple program for running regressions on the fuzzing routines.
+//  This code is not part of any shipping product.
+//
+//  To build:
+//  clang++ -std=c++11 fuzz_test.cpp fuzzing.cpp
+//
+//  To use:
+//  fuzz_test -r partial_sort [-v] files...
+//
+//  Each file should contain a test case.
+
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "fuzzing.h"
+
+typedef int (*FuzzProc) (const uint8_t *data, size_t size);
+
+const std::map procs = {
+{"sort",fuzzing::sort},
+{"stable_sort", fuzzing::stable_sort},
+{"partition",   fuzzing::partition},
+{"partition_copy",  fuzzing::partition_copy},
+{"stable_partition",fuzzing::stable_partition},
+{"unique",  fuzzing::unique},
+{"unique_copy", fuzzing::unique_copy},
+{"nth_element", fuzzing::nth_element},
+{"partial_sort",fuzzing::partial_sort},
+{"partial_sort_copy",   fuzzing::partial_sort_copy},
+{"make_heap",   fuzzing::make_heap},
+{"push_heap",   fuzzing::push_heap},
+{"pop_heap",fuzzing::pop_heap},
+{"regex_ECMAScript",fuzzing::regex_ECMAScript},
+{"regex_POSIX", fuzzing::regex_POSIX},
+{"regex_extended",  fuzzing::regex_extended},
+{"regex_awk",   fuzzing::regex_awk},
+{"regex_grep",  fuzzing::regex_grep},
+{"regex_egrep", fuzzing::regex_egrep},
+{"search",  fuzzing::search}
+};
+
+
+
+bool verbose = false;
+
+void test_one(const char *filename, FuzzProc fp)
+{
+std::vector v;
+std::ifstream f (filename, std::ios::binary);
+if (!f.is_open())
+std::cerr << "## Can't open '" << filename << "'" << std::endl;
+else {
+typedef std::istream_iterator Iter;
+std::copy(Iter(f), Iter(), std::back_inserter(v));
+if (verbose)
+std::cout << "File '" << filename << "' contains " << v.size() << 
" entries" << std::endl;
+const auto start_time = std::chrono::steady_clock::now();
+int ret = fp (v.data(), v.size());
+const auto finish_time = std::chrono::steady_clock::now();
+if (ret != 0)
+std::cerr << "## Failure code: " << ret << std::endl;
+if (verbose)
+std::cout << "Execution time: "
+<< 
std::chrono::duration_cast(finish_time - 
start_time).count()
+<< " milliseconds" << std::endl;
+}
+}
+
+void usage (const char *name)
+{
+std::cout << "Usage: " << name << " -r proc [-v] files..." << std::endl;
+std::cout << "Supported routines:" << std::endl;
+for (const auto  : procs)
+std::cout << "" << p.first << std::endl;
+std::cout << std::endl;
+}
+
+// Poor man's command-line options
+const std::string dashR("-r");
+const std::string dashV("-v");
+
+int main(int argc, char *argv[])
+{
+if (argc < 4 || dashR != argv[1] || procs.find(argv[2]) == procs.end())
+usage(argv[0]);
+else {
+FuzzProc fp = procs.find(argv[2])->second;
+int firstFile = 3;
+if (dashV == argv[firstFile])
+{
+verbose = true;
+++firstFile;
+}
+for (int i = firstFile; i < argc; ++i)
+test_one(argv[i], fp);
+}
+}


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


[PATCH] D42181: [clangd] Merge index-provided completions with those from Sema.

2018-01-18 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 130417.
sammccall marked 7 inline comments as done.
sammccall added a comment.

Addressed review comments, except for "refactor into class" which is still todo.
Added explicit check of code completion context kind.
Added tests (mostly updating existing ones).


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42181

Files:
  clangd/CodeComplete.cpp
  unittests/clangd/CodeCompleteTests.cpp

Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -17,7 +17,6 @@
 #include "SourceCode.h"
 #include "TestFS.h"
 #include "index/MemIndex.h"
-#include "index/Merge.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -82,7 +81,7 @@
   return arg.insertTextFormat == clangd::InsertTextFormat::Snippet &&
  arg.insertText == Text;
 }
-MATCHER(FilterContainsName, "") {
+MATCHER(NameContainsFilter, "") {
   if (arg.filterText.empty())
 return true;
   return llvm::StringRef(arg.insertText).contains(arg.filterText);
@@ -129,30 +128,53 @@
   .get()
   .second.Value;
   // Sanity-check that filterText is valid.
-  EXPECT_THAT(CompletionList.items, Each(FilterContainsName()));
+  EXPECT_THAT(CompletionList.items, Each(NameContainsFilter()));
   return CompletionList;
 }
 
+std::string replace(StringRef Haystack, StringRef Needle, StringRef Repl) {
+  std::string Result;
+  raw_string_ostream OS(Result);
+  std::pair Split;
+  for (Split = Haystack.split(Needle); !Split.second.empty();
+   Split = Split.first.split(Needle))
+OS << Split.first << Repl;
+  Result += Split.first;
+  OS.flush();
+  return Result;
+}
+
 // Helpers to produce fake index symbols for memIndex() or completions().
-Symbol sym(StringRef QName, index::SymbolKind Kind) {
+// USRFormat is a regex replacement string for the unqualified part of the USR.
+Symbol sym(StringRef QName, index::SymbolKind Kind, StringRef USRFormat) {
   Symbol Sym;
-  Sym.ID = SymbolID(QName);
+  std::string USR = "c:"; // We synthesize a few simple cases of USRs by hand!
   size_t Pos = QName.rfind("::");
   if (Pos == llvm::StringRef::npos) {
 Sym.Name = QName;
 Sym.Scope = "";
   } else {
 Sym.Name = QName.substr(Pos + 2);
 Sym.Scope = QName.substr(0, Pos);
+USR += "@N@" + replace(Sym.Scope, "::", "@N@"); // ns:: -> @N@ns
   }
+  USR += Regex("^.*$").sub(USRFormat, Sym.Name); // e.g. func -> @F@func#
+  Sym.ID = SymbolID(USR);
   Sym.CompletionPlainInsertText = Sym.Name;
+  Sym.CompletionSnippetInsertText = Sym.Name;
   Sym.CompletionLabel = Sym.Name;
   Sym.SymInfo.Kind = Kind;
   return Sym;
 }
-Symbol func(StringRef Name) { return sym(Name, index::SymbolKind::Function); }
-Symbol cls(StringRef Name) { return sym(Name, index::SymbolKind::Class); }
-Symbol var(StringRef Name) { return sym(Name, index::SymbolKind::Variable); }
+Symbol func(StringRef Name) { // Assumes the function has no args.
+  return sym(Name, index::SymbolKind::Function, "@F@\\0#"); // no args
+}
+Symbol cls(StringRef Name) {
+  return sym(Name, index::SymbolKind::Class, "@S@\\0@S@\\0");
+}
+Symbol var(StringRef Name) {
+  return sym(Name, index::SymbolKind::Variable, "@\\0");
+}
 
 TEST(CompletionTest, Limit) {
   clangd::CodeCompleteOptions Opts;
@@ -226,7 +248,7 @@
 ClassWithMembers().^
   }
   )cpp",
-  /*IndexSymbols=*/{}, Opts);
+  {cls("IndexClass"), var("index_var"), func("index_func")}, Opts);
 
   // Class members. The only items that must be present in after-dot
   // completion.
@@ -236,9 +258,11 @@
   EXPECT_IFF(Opts.IncludeIneligibleResults, Results.items,
  Has("private_field"));
   // Global items.
-  EXPECT_THAT(Results.items, Not(AnyOf(Has("global_var"), Has("global_func"),
-   Has("global_func()"), Has("GlobalClass"),
-   Has("MACRO"), Has("LocalClass";
+  EXPECT_THAT(
+  Results.items,
+  Not(AnyOf(Has("global_var"), Has("index_var"), Has("global_func"),
+Has("global_func()"), Has("index_func"), Has("GlobalClass"),
+Has("IndexClass"), Has("MACRO"), Has("LocalClass";
   // There should be no code patterns (aka snippets) in after-dot
   // completion. At least there aren't any we're aware of.
   EXPECT_THAT(Results.items, Not(Contains(Kind(CompletionItemKind::Snippet;
@@ -271,16 +295,17 @@
 ^
   }
   )cpp",
-  /*IndexSymbols=*/{}, Opts);
+  {cls("IndexClass"), var("index_var"), func("index_func")}, Opts);
 
   // Class members. Should never be present in global completions.
   EXPECT_THAT(Results.items,
   Not(AnyOf(Has("method"), Has("method()"), Has("field";
   // Global items.
-  EXPECT_IFF(Opts.IncludeGlobals, Results.items,
- AllOf(Has("global_var"),
-   Has(Opts.EnableSnippets ? 

[PATCH] D40925: Add option -fkeep-static-consts

2018-01-18 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

That makes sense. Is it not possible to implement the required functionality 
using a flag vs an attribute? In an earlier comment you mentioned adding the 
global to @llvm.used to prevent GlobalDCE from removing it. Can you not do that 
when using a flag?


https://reviews.llvm.org/D40925



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


[PATCH] D41947: Provide default virtual filesystem argument to ClangTool constructor

2018-01-18 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In https://reviews.llvm.org/D41947#980305, @vladimir.plyashkun wrote:

> In https://reviews.llvm.org/D41947#980298, @ilya-biryukov wrote:
>
> > Looks good. Do you have commit access or do you need someone to land this 
> > patch for you?
>
>
> No, i don't have commit access.


I can land this for you together with the other patch that you're working on.
BTW, have you seen that you could set a child revision in phabricator? That 
would link these two changes together, making it clear that those changes are 
closely related.


Repository:
  rC Clang

https://reviews.llvm.org/D41947



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


[PATCH] D42073: [clangd] Query all visible scopes based on all visible using-namespace declarationsand containing namespace for global qualified code completion.

2018-01-18 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/CodeComplete.cpp:270
+  /// namespace scopes which are visible to the qualified-id completion token.
+  std::vector Scopes;
+};

sammccall wrote:
> Just to check, if the user types:
> "vec" --> None
> "::vec" --> {""}
> "std::vec" --> {"std"}
> "using namespace std; vec" --> None
> "using namespace std; ::vec" --> {"", "std"}
> 
> is this right?
I think the idea was to have (I only highlight the differences):
"vec" --> {""}
"using namespace std; vec" --> {"", "std"}

@hokein , or am I getting it wrong?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42073



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


  1   2   >