r331743 - [x86] Introduce the encl[u|s|v] intrinsics

2018-05-08 Thread Gabor Buella via cfe-commits
Author: gbuella
Date: Tue May  8 00:12:34 2018
New Revision: 331743

URL: http://llvm.org/viewvc/llvm-project?rev=331743&view=rev
Log:
[x86] Introduce the encl[u|s|v] intrinsics

Reviewers: craig.topper, zvi

Reviewed By: craig.topper

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

Added:
cfe/trunk/lib/Headers/sgxintrin.h   (with props)
cfe/trunk/test/Headers/sgxintrin.c   (with props)
Modified:
cfe/trunk/lib/Headers/CMakeLists.txt
cfe/trunk/lib/Headers/module.modulemap
cfe/trunk/lib/Headers/x86intrin.h

Modified: cfe/trunk/lib/Headers/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/CMakeLists.txt?rev=331743&r1=331742&r2=331743&view=diff
==
--- cfe/trunk/lib/Headers/CMakeLists.txt (original)
+++ cfe/trunk/lib/Headers/CMakeLists.txt Tue May  8 00:12:34 2018
@@ -78,6 +78,7 @@ set(files
   prfchwintrin.h
   rdseedintrin.h
   rtmintrin.h
+  sgxintrin.h
   s390intrin.h
   shaintrin.h
   smmintrin.h

Modified: cfe/trunk/lib/Headers/module.modulemap
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/module.modulemap?rev=331743&r1=331742&r2=331743&view=diff
==
--- cfe/trunk/lib/Headers/module.modulemap (original)
+++ cfe/trunk/lib/Headers/module.modulemap Tue May  8 00:12:34 2018
@@ -68,6 +68,7 @@ module _Builtin_intrinsics [system] [ext
 textual header "waitpkgintrin.h"
 textual header "movdirintrin.h"
 textual header "pconfigintrin.h"
+textual header "sgxintrin.h"
 
 explicit module mm_malloc {
   requires !freestanding

Added: cfe/trunk/lib/Headers/sgxintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/sgxintrin.h?rev=331743&view=auto
==
--- cfe/trunk/lib/Headers/sgxintrin.h (added)
+++ cfe/trunk/lib/Headers/sgxintrin.h Tue May  8 00:12:34 2018
@@ -0,0 +1,70 @@
+/*=== sgxintrin.h - X86 SGX intrinsics configuration ---===
+ *
+ * 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.
+ *
+ *===---===
+ */
+
+#ifndef __X86INTRIN_H
+#error "Never use  directly; include  instead."
+#endif
+
+#ifndef __SGXINTRIN_H
+#define __SGXINTRIN_H
+
+/* Define the default attributes for the functions in this file. */
+#define __DEFAULT_FN_ATTRS \
+  __attribute__((__always_inline__, __nodebug__,  __target__("sgx")))
+
+static __inline unsigned int __DEFAULT_FN_ATTRS
+_enclu_u32(unsigned int __leaf, __SIZE_TYPE__ __d[])
+{
+  unsigned int __result;
+  __asm__ ("enclu"
+   : "=a" (__result), "=b" (__d[0]), "=c" (__d[1]), "=d" (__d[2])
+   : "a" (__leaf), "b" (__d[0]), "c" (__d[1]), "d" (__d[2])
+   : "cc");
+  return __result;
+}
+
+static __inline unsigned int __DEFAULT_FN_ATTRS
+_encls_u32(unsigned int __leaf, __SIZE_TYPE__ __d[])
+{
+  unsigned int __result;
+  __asm__ ("encls"
+   : "=a" (__result), "=b" (__d[0]), "=c" (__d[1]), "=d" (__d[2])
+   : "a" (__leaf), "b" (__d[0]), "c" (__d[1]), "d" (__d[2])
+   : "cc");
+  return __result;
+}
+
+static __inline unsigned int __DEFAULT_FN_ATTRS
+_enclv_u32(unsigned int __leaf, __SIZE_TYPE__ __d[])
+{
+  unsigned int __result;
+  __asm__ ("enclv"
+   : "=a" (__result), "=b" (__d[0]), "=c" (__d[1]), "=d" (__d[2])
+   : "a" (__leaf), "b" (__d[0]), "c" (__d[1]), "d" (__d[2])
+   : "cc");
+  return __result;
+}
+
+#undef __DEFAULT_FN_ATTRS
+
+#endif

Propchange: cfe/trunk/lib/Headers/sgxintrin.h
--
svn:eol-style = native

Propchange: cfe/trunk/lib/Headers/sgxintrin.h
--
svn:keywords = Author Date Id Rev URL

Propchange: c

[PATCH] D46435: [x86] Introduce the encl[u|s|v] intrinsics

2018-05-08 Thread Gabor Buella via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC331743: [x86] Introduce the encl[u|s|v] intrinsics (authored 
by GBuella, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D46435?vs=145205&id=145638#toc

Repository:
  rC Clang

https://reviews.llvm.org/D46435

Files:
  lib/Headers/CMakeLists.txt
  lib/Headers/module.modulemap
  lib/Headers/sgxintrin.h
  lib/Headers/x86intrin.h
  test/Headers/sgxintrin.c

Index: test/Headers/sgxintrin.c
===
--- test/Headers/sgxintrin.c
+++ test/Headers/sgxintrin.c
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 %s -ffreestanding -triple x86_64-unknown-unknown -target-feature +sgx -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-64
+// RUN: %clang_cc1 %s -ffreestanding -triple i386 -target-feature +sgx -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-32
+
+#include 
+#include 
+#include 
+
+uint32_t test_encls(uint32_t leaf, size_t data[3]) {
+// CHECK-64: call { i32, i64, i64, i64 } asm "encls", "={ax},={bx},={cx},={dx},{ax},{bx},{cx},{dx},~{cc},~{dirflag},~{fpsr},~{flags}"(i32 %{{.*}}, i64 %{{.*}}, i64 %{{.*}}, i64 %{{.*}})
+// CHECK-32: call { i32, i32, i32, i32 } asm "encls", "={ax},={bx},={cx},={dx},{ax},{bx},{cx},{dx},~{cc},~{dirflag},~{fpsr},~{flags}"(i32 %{{.*}}, i32 %{{.*}}, i32 %{{.*}}, i32 %{{.*}})
+
+  return _encls_u32(leaf, data);
+}
+
+uint32_t test_enclu(uint32_t leaf, size_t data[3]) {
+// CHECK-64: call { i32, i64, i64, i64 } asm "enclu", "={ax},={bx},={cx},={dx},{ax},{bx},{cx},{dx},~{cc},~{dirflag},~{fpsr},~{flags}"(i32 %{{.*}}, i64 %{{.*}}, i64 %{{.*}}, i64 %{{.*}})
+// CHECK-32: call { i32, i32, i32, i32 } asm "enclu", "={ax},={bx},={cx},={dx},{ax},{bx},{cx},{dx},~{cc},~{dirflag},~{fpsr},~{flags}"(i32 %{{.*}}, i32 %{{.*}}, i32 %{{.*}}, i32 %{{.*}})
+
+  return _enclu_u32(leaf, data);
+}
+
+uint32_t test_enclv(uint32_t leaf, size_t data[3]) {
+// CHECK-64: call { i32, i64, i64, i64 } asm "enclv", "={ax},={bx},={cx},={dx},{ax},{bx},{cx},{dx},~{cc},~{dirflag},~{fpsr},~{flags}"(i32 %{{.*}}, i64 %{{.*}}, i64 %{{.*}}, i64 %{{.*}})
+// CHECK-32: call { i32, i32, i32, i32 } asm "enclv", "={ax},={bx},={cx},={dx},{ax},{bx},{cx},{dx},~{cc},~{dirflag},~{fpsr},~{flags}"(i32 %{{.*}}, i32 %{{.*}}, i32 %{{.*}}, i32 %{{.*}})
+
+  return _enclv_u32(leaf, data);
+}
Index: lib/Headers/sgxintrin.h
===
--- lib/Headers/sgxintrin.h
+++ lib/Headers/sgxintrin.h
@@ -0,0 +1,70 @@
+/*=== sgxintrin.h - X86 SGX intrinsics configuration ---===
+ *
+ * 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.
+ *
+ *===---===
+ */
+
+#ifndef __X86INTRIN_H
+#error "Never use  directly; include  instead."
+#endif
+
+#ifndef __SGXINTRIN_H
+#define __SGXINTRIN_H
+
+/* Define the default attributes for the functions in this file. */
+#define __DEFAULT_FN_ATTRS \
+  __attribute__((__always_inline__, __nodebug__,  __target__("sgx")))
+
+static __inline unsigned int __DEFAULT_FN_ATTRS
+_enclu_u32(unsigned int __leaf, __SIZE_TYPE__ __d[])
+{
+  unsigned int __result;
+  __asm__ ("enclu"
+   : "=a" (__result), "=b" (__d[0]), "=c" (__d[1]), "=d" (__d[2])
+   : "a" (__leaf), "b" (__d[0]), "c" (__d[1]), "d" (__d[2])
+   : "cc");
+  return __result;
+}
+
+static __inline unsigned int __DEFAULT_FN_ATTRS
+_encls_u32(unsigned int __leaf, __SIZE_TYPE__ __d[])
+{
+  unsigned int __result;
+  __asm__ ("encls"
+   : "=a" (__result), "=b" (__d[0]), "=c" (__d[1]), "=d" (__d[2])
+   : "a" (__leaf), "b" (__d[0]), "c" (__d[1]), "d" (__d[2])
+   : "cc");
+  return __result;
+}
+
+static __inline unsigned int __DEFAULT_FN_ATTRS
+_enclv_u32(unsigned int __leaf, __SIZE_TYPE__ __d[])
+{
+  unsigned int __result;
+  __asm__ ("enclv"
+   : "=a" (__result), "=b" (__d[0]), "=c" (__d[1]), "

[PATCH] D46115: [ASTImporter] properly import SrcLoc of Attr

2018-05-08 Thread Rafael Stahl via Phabricator via cfe-commits
r.stahl updated this revision to Diff 145641.
r.stahl marked 6 inline comments as done.

https://reviews.llvm.org/D46115

Files:
  include/clang/AST/ASTImporter.h
  lib/AST/ASTImporter.cpp
  test/Import/attr/Inputs/S.cpp
  test/Import/attr/test.cpp

Index: test/Import/attr/Inputs/S.cpp
===
--- test/Import/attr/Inputs/S.cpp
+++ test/Import/attr/Inputs/S.cpp
@@ -0,0 +1,13 @@
+extern void f() __attribute__((const));
+
+struct S {
+  struct {
+int a __attribute__((packed));
+  };
+};
+
+void stmt() {
+#pragma unroll
+  for (;;)
+;
+}
Index: test/Import/attr/test.cpp
===
--- test/Import/attr/test.cpp
+++ test/Import/attr/test.cpp
@@ -0,0 +1,26 @@
+// RUN: clang-import-test -dump-ast -import %S/Inputs/S.cpp -expression %s | FileCheck %s
+// CHECK: FunctionDecl
+// CHECK-SAME: S.cpp:1:1, col:13
+// CHECK-NEXT: ConstAttr
+// CHECK-SAME: col:32
+
+// CHECK: IndirectFieldDecl
+// CHECK-NEXT: Field
+// CHECK-NEXT: Field
+// CHECK-NEXT: PackedAttr
+// CHECK-SAME: col:26
+
+// CHECK: AttributedStmt
+// CHECK-NEXT: LoopHintAttr
+// CHECK-SAME: line:10:9
+
+extern void f() __attribute__((const));
+
+struct S;
+
+void stmt();
+
+void expr() {
+  f();
+  struct S s;
+}
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -2646,8 +2646,8 @@
   Importer.getToContext(), DC, Loc, Name.getAsIdentifierInfo(), T,
   {NamedChain, D->getChainingSize()});
 
-  for (const auto *Attr : D->attrs())
-ToIndirectField->addAttr(Attr->clone(Importer.getToContext()));
+  for (const auto *A : D->attrs())
+ToIndirectField->addAttr(Importer.Import(A));
 
   ToIndirectField->setAccess(D->getAccess());
   ToIndirectField->setLexicalDeclContext(LexicalDC);
@@ -4721,15 +4721,8 @@
   SourceLocation ToAttrLoc = Importer.Import(S->getAttrLoc());
   ArrayRef FromAttrs(S->getAttrs());
   SmallVector ToAttrs(FromAttrs.size());
-  ASTContext &_ToContext = Importer.getToContext();
-  std::transform(FromAttrs.begin(), FromAttrs.end(), ToAttrs.begin(),
-[&_ToContext](const Attr *A) -> const Attr * {
-  return A->clone(_ToContext);
-});
-  for (const auto *ToA : ToAttrs) {
-if (!ToA)
-  return nullptr;
-  }
+  if (ImportArrayChecked(FromAttrs.begin(), FromAttrs.end(), ToAttrs.begin()))
+return nullptr;
   Stmt *ToSubStmt = Importer.Import(S->getSubStmt());
   if (!ToSubStmt && S->getSubStmt())
 return nullptr;
@@ -6544,6 +6537,12 @@
Import(FromTSI->getTypeLoc().getLocStart()));
 }
 
+Attr *ASTImporter::Import(const Attr *FromAttr) {
+  Attr *ToAttr = FromAttr->clone(ToContext);
+  ToAttr->setRange(Import(FromAttr->getRange()));
+  return ToAttr;
+}
+
 Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) {
   llvm::DenseMap::iterator Pos = ImportedDecls.find(FromD);
   if (Pos != ImportedDecls.end()) {
@@ -7199,8 +7198,8 @@
 
 Decl *ASTImporter::Imported(Decl *From, Decl *To) {
   if (From->hasAttrs()) {
-for (auto *FromAttr : From->getAttrs())
-  To->addAttr(FromAttr->clone(To->getASTContext()));
+for (const auto *FromAttr : From->getAttrs())
+  To->addAttr(Import(FromAttr));
   }
   if (From->isUsed()) {
 To->setIsUsed();
Index: include/clang/AST/ASTImporter.h
===
--- include/clang/AST/ASTImporter.h
+++ include/clang/AST/ASTImporter.h
@@ -41,6 +41,7 @@
 class Stmt;
 class TagDecl;
 class TypeSourceInfo;
+class Attr;
 
   /// \brief Imports selected nodes from one AST context into another context,
   /// merging AST nodes where appropriate.
@@ -130,6 +131,12 @@
 /// context, or NULL if an error occurred.
 TypeSourceInfo *Import(TypeSourceInfo *FromTSI);
 
+/// \brief Import the given attribute from the "from" context into the
+/// "to" context.
+///
+/// \returns the equivalent attribute in the "to" context.
+Attr *Import(const Attr *FromAttr);
+
 /// \brief Import the given declaration from the "from" context into the 
 /// "to" context.
 ///
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46115: [ASTImporter] properly import SrcLoc of Attr

2018-05-08 Thread Rafael Stahl via Phabricator via cfe-commits
r.stahl added inline comments.



Comment at: include/clang/AST/ASTImporter.h:137
+///
+/// \returns the equivalent attribute in the "to" context, or NULL if an
+/// error occurred.

a.sidorin wrote:
> nullptr
I tried to stay consistent with the other descriptions. Will be removed anyway 
(see below).



Comment at: lib/AST/ASTImporter.cpp:2650
+  for (const auto *A : D->attrs())
+ToIndirectField->addAttr(Importer.Import(const_cast(A)));
 

a.sidorin wrote:
> Could we just remove 'const' qualifier from `A` to avoid `const_cast`? (Same 
> below)
I made the interface const instead.



Comment at: lib/AST/ASTImporter.cpp:6547
+Attr *ASTImporter::Import(Attr *FromAttr) {
+  if (!FromAttr)
+return nullptr;

a.sidorin wrote:
> Is it possible to get into a situation where a nullptr attribute is imported?
I looked at the Decl variant and thought it should act similarly, but as far as 
I can tell, null attributes should not exist.


https://reviews.llvm.org/D46115



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


r331745 - [C++2a] Implement operator<=>: Fix another bug in the code gen tests.

2018-05-08 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Tue May  8 00:56:05 2018
New Revision: 331745

URL: http://llvm.org/viewvc/llvm-project?rev=331745&view=rev
Log:
[C++2a] Implement operator<=>: Fix another bug in the code gen tests.

Sorry for the failures. I'm quite new at writing code gen tests, and
I'm not sure the best way to make them portable.

Modified:
cfe/trunk/test/CodeGenCXX/cxx2a-compare.cpp

Modified: cfe/trunk/test/CodeGenCXX/cxx2a-compare.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx2a-compare.cpp?rev=331745&r1=331744&r2=331745&view=diff
==
--- cfe/trunk/test/CodeGenCXX/cxx2a-compare.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/cxx2a-compare.cpp Tue May  8 00:56:05 2018
@@ -79,7 +79,8 @@ auto mem_ptr_test(MemPtrT x, MemPtrT y)
   // CHECK: %cmp.ptr = icmp eq [[TY:i[0-9]+]] %lhs.memptr.ptr, %rhs.memptr.ptr
   // CHECK: %cmp.ptr.null = icmp eq [[TY]] %lhs.memptr.ptr, 0
   // CHECK: %cmp.adj = icmp eq [[TY]] %lhs.memptr.adj, %rhs.memptr.adj
-  // CHECK: %[[OR:.*]] = or i1 %cmp.ptr.null, %cmp.adj
+  // CHECK: %[[OR:.*]] = or i1
+  // CHECK-SAME %cmp.adj
   // CHECK: %memptr.eq = and i1 %cmp.ptr, %[[OR]]
   // CHECK: %sel.eq = select i1 %memptr.eq, i8 [[EQ]], i8 [[NE]]
   // CHECK: %__value_ = getelementptr inbounds %[[SE]], %[[SE]]* %[[DEST]]


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


[PATCH] D45680: [C++2a] Implement operator<=> Part 2: Operator Rewritting and Overload Resolution.

2018-05-08 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 145643.
EricWF added a comment.

- Rebase on master.

I think the correct direction to head with this patch is to start removing the 
bits of the implementation which evaluate and build rewritten expressions 
during overload resolution. I'll submit such an update tomorrow.


https://reviews.llvm.org/D45680

Files:
  include/clang/AST/Expr.h
  include/clang/AST/ExprCXX.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/AST/Stmt.h
  include/clang/Basic/StmtNodes.td
  include/clang/Sema/Overload.h
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/Expr.cpp
  lib/AST/ExprClassification.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/StmtPrinter.cpp
  lib/AST/StmtProfile.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/Sema/SemaExceptionSpec.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOverload.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/CodeGenCXX/cxx2a-compare.cpp
  test/SemaCXX/compare-cxx2a.cpp

Index: test/SemaCXX/compare-cxx2a.cpp
===
--- test/SemaCXX/compare-cxx2a.cpp
+++ test/SemaCXX/compare-cxx2a.cpp
@@ -292,20 +292,21 @@
 
 template 
 struct Tag {};
-// expected-note@+1 {{candidate}}
-Tag<0> operator<=>(EnumA, EnumA) {
-  return {};
+std::strong_ordering operator<=>(EnumA, EnumA) {
+  return std::strong_ordering::equal;
 }
-Tag<1> operator<=>(EnumA, EnumB) {
-  return {};
+// expected-note@+1 {{candidate function}},
+std::strong_ordering operator<=>(EnumA a, EnumB b) {
+  return ((int)a <=> (int)b);
 }
 
 void test_enum_ovl_provided() {
   auto r1 = (EnumA::A <=> EnumA::A);
-  ASSERT_EXPR_TYPE(r1, Tag<0>);
+  ASSERT_EXPR_TYPE(r1, std::strong_ordering);
   auto r2 = (EnumA::A <=> EnumB::B);
-  ASSERT_EXPR_TYPE(r2, Tag<1>);
-  (void)(EnumB::B <=> EnumA::A); // expected-error {{invalid operands to binary expression ('EnumCompareTests::EnumB' and 'EnumCompareTests::EnumA')}}
+  ASSERT_EXPR_TYPE(r2, std::strong_ordering);
+  (void)(EnumB::B <=> EnumA::A); // OK, chooses reverse order synthesized candidate.
+  (void)(EnumB::B <=> EnumC::C); // expected-error {{invalid operands to binary expression ('EnumCompareTests::EnumB' and 'EnumCompareTests::EnumC')}}
 }
 
 void enum_float_test() {
@@ -421,3 +422,116 @@
 }
 
 } // namespace ComplexTest
+
+namespace TestRewritting {
+
+struct T {
+  int x;
+  // expected-note@+1 {{candidate}}
+  constexpr std::strong_ordering operator<=>(T y) const {
+return (x <=> y.x);
+  }
+};
+
+struct U {
+  int x;
+  // FIXME: This diagnostic is wrong-ish.
+  // expected-note@+1 {{candidate function not viable: requires single argument 'y', but 2 arguments were provided}}
+  constexpr std::strong_equality operator<=>(T y) const {
+if (x == y.x)
+  return std::strong_equality::equal;
+return std::strong_equality::nonequal;
+  }
+};
+
+struct X { int x; };
+struct Y { int x; };
+template 
+struct Tag {};
+// expected-note@+1 2 {{candidate}}
+Tag<0> operator<=>(X, Y) {
+  return {};
+}
+// expected-note@+1 2 {{candidate}}
+constexpr auto operator<=>(Y y, X x) {
+  return y.x <=> x.x;
+}
+
+void foo() {
+  T t{42};
+  T t2{0};
+  U u{101};
+  auto r1 = (t <=> u);
+  ASSERT_EXPR_TYPE(r1, std::strong_equality);
+  auto r2 = (t <=> t2);
+  ASSERT_EXPR_TYPE(r2, std::strong_ordering);
+
+  auto r3 = t == u;
+  ASSERT_EXPR_TYPE(r3, bool);
+
+  (void)(t < u); // expected-error {{invalid operands to binary expression ('TestRewritting::T' and 'TestRewritting::U')}}
+
+  constexpr X x{1};
+  constexpr Y y{2};
+  constexpr auto r4 = (y < x);
+  static_assert(r4 == false);
+  constexpr auto r5 = (x < y);
+  static_assert(r5 == true);
+}
+
+} // namespace TestRewritting
+
+// The implicit object parameter is not considered when performing partial
+// ordering. That makes the reverse synthesized candidates ambiguous with the
+// rewritten candidates if any of them resolve to a member function.
+namespace TestOvlMatchingIgnoresImplicitObject {
+struct U;
+// expected-note@+2 {{candidate}}
+struct T {
+  std::strong_ordering operator<=>(U const &RHS) const;
+};
+// expected-note@+2 {{candidate}}
+struct U {
+  std::strong_ordering operator<=>(T const &RHS) const;
+};
+
+struct V {
+  int x;
+};
+auto operator<=>(V const &LHS, V &&RHS) { // expected-note 4 {{candidate}}
+  return LHS.x <=> RHS.x;
+}
+auto operator<(V const &, V &&) { // expected-note {{candidate}}
+  return std::strong_equality::equal;
+}
+
+void test() {
+  // expected-error@+1 {{use of overloaded operator '<' is ambiguous}}
+  (void)(T{} < U{});
+  // expected-error@+1 {{use of overloaded operator '<' is ambiguous}}
+  (void)(V{} < V{});
+  // expected-error@+1 {{use of overloaded operator '<=>' is ambiguous}}
+  (void)(V{} <=> V{});
+}
+
+} // namespace TestOvlMatchingIgnoresImplicitObject
+
+namespace TestRewrittenTemplate {
+
+template 
+auto test(T const 

[PATCH] D46386: Adding __atomic_fetch_min/max intrinsics to clang

2018-05-08 Thread Elena Demikhovsky via Phabricator via cfe-commits
delena updated this revision to Diff 145646.
delena added a comment.

Removed the unsigned version of atomics. Enhanced semantics check.
Added more tests.
Added documentation.


Repository:
  rC Clang

https://reviews.llvm.org/D46386

Files:
  docs/LanguageExtensions.rst
  include/clang/Basic/Builtins.def
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/Expr.cpp
  lib/CodeGen/CGAtomic.cpp
  lib/Sema/SemaChecking.cpp
  test/CodeGen/Atomics.c
  test/Sema/atomic-ops.c

Index: test/Sema/atomic-ops.c
===
--- test/Sema/atomic-ops.c
+++ test/Sema/atomic-ops.c
@@ -173,6 +173,9 @@
   __atomic_fetch_sub(P, 3, memory_order_seq_cst);
   __atomic_fetch_sub(D, 3, memory_order_seq_cst); // expected-error {{must be a pointer to integer or pointer}}
   __atomic_fetch_sub(s1, 3, memory_order_seq_cst); // expected-error {{must be a pointer to integer or pointer}}
+  __atomic_fetch_min(D, 3, memory_order_seq_cst); // expected-error {{must be a pointer to signed or unsigned 32-bit integer}}
+  __atomic_fetch_max(P, 3, memory_order_seq_cst); // expected-error {{must be a pointer to signed or unsigned 32-bit integer}}
+  __atomic_fetch_max(p, 3);   // expected-error {{too few arguments to function call, expected 3, have 2}}
 
   __c11_atomic_fetch_and(i, 1, memory_order_seq_cst);
   __c11_atomic_fetch_and(p, 1, memory_order_seq_cst); // expected-error {{must be a pointer to atomic integer}}
@@ -456,6 +459,20 @@
   (void)__atomic_fetch_nand(p, val, memory_order_acq_rel);
   (void)__atomic_fetch_nand(p, val, memory_order_seq_cst);
 
+  (void)__atomic_fetch_min(p, val, memory_order_relaxed);
+  (void)__atomic_fetch_min(p, val, memory_order_acquire);
+  (void)__atomic_fetch_min(p, val, memory_order_consume);
+  (void)__atomic_fetch_min(p, val, memory_order_release);
+  (void)__atomic_fetch_min(p, val, memory_order_acq_rel);
+  (void)__atomic_fetch_min(p, val, memory_order_seq_cst);
+
+  (void)__atomic_fetch_max(p, val, memory_order_relaxed);
+  (void)__atomic_fetch_max(p, val, memory_order_acquire);
+  (void)__atomic_fetch_max(p, val, memory_order_consume);
+  (void)__atomic_fetch_max(p, val, memory_order_release);
+  (void)__atomic_fetch_max(p, val, memory_order_acq_rel);
+  (void)__atomic_fetch_max(p, val, memory_order_seq_cst);
+
   (void)__atomic_and_fetch(p, val, memory_order_relaxed);
   (void)__atomic_and_fetch(p, val, memory_order_acquire);
   (void)__atomic_and_fetch(p, val, memory_order_consume);
Index: test/CodeGen/Atomics.c
===
--- test/CodeGen/Atomics.c
+++ test/CodeGen/Atomics.c
@@ -291,3 +291,10 @@
   __sync_lock_release (&sll); // CHECK: store atomic {{.*}} release, align 8
   __sync_lock_release (&ull); // CHECK: store atomic {{.*}} release, align 8
 }
+
+void test_atomic(void) {
+  ui = __atomic_fetch_min(&ui, 5, __ATOMIC_RELAXED); // CHECK: atomicrmw umin {{.*}} monotonic
+  si = __atomic_fetch_min(&si, 5, __ATOMIC_SEQ_CST); // CHECK: atomicrmw min {{.*}} seq_cst
+  ui = __atomic_fetch_max(&ui, 5, __ATOMIC_ACQUIRE); // CHECK: atomicrmw umax {{.*}} acquire
+  si = __atomic_fetch_max(&si, 5, __ATOMIC_RELEASE); // CHECK: atomicrmw max {{.*}} release
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -3037,6 +3037,7 @@
  Op == AtomicExpr::AO__atomic_exchange_n ||
  Op == AtomicExpr::AO__atomic_compare_exchange_n;
   bool IsAddSub = false;
+  bool IsMinMax = false;
 
   switch (Op) {
   case AtomicExpr::AO__c11_atomic_init:
@@ -3090,6 +3091,12 @@
 Form = Arithmetic;
 break;
 
+  case AtomicExpr::AO__atomic_fetch_min:
+  case AtomicExpr::AO__atomic_fetch_max:
+IsMinMax = true;
+Form = Arithmetic;
+break;
+
   case AtomicExpr::AO__c11_atomic_exchange:
   case AtomicExpr::AO__opencl_atomic_exchange:
   case AtomicExpr::AO__atomic_exchange_n:
@@ -3172,12 +3179,21 @@
   // For an arithmetic operation, the implied arithmetic must be well-formed.
   if (Form == Arithmetic) {
 // gcc does not enforce these rules for GNU atomics, but we do so for sanity.
-if (IsAddSub && !ValType->isIntegerType() && !ValType->isPointerType()) {
+if (IsAddSub && !ValType->isIntegerType()
+&& !ValType->isPointerType()) {
   Diag(DRE->getLocStart(), diag::err_atomic_op_needs_atomic_int_or_ptr)
 << IsC11 << Ptr->getType() << Ptr->getSourceRange();
   return ExprError();
 }
-if (!IsAddSub && !ValType->isIntegerType()) {
+if (IsMinMax) {
+  const BuiltinType *BT = ValType->getAs();
+  if (!BT || (BT->getKind() != BuiltinType::Int &&
+  BT->getKind() != BuiltinType::UInt)) {
+Diag(DRE->getLocStart(), diag::err_atomic_op_needs_int32_or_ptr);
+return ExprError();
+  }
+}
+if (!IsAddSub && !IsMinMax && !ValType->isIntegerType()) {
   Diag(DRE->

[PATCH] D45815: [libclang] Allow skipping function bodies in preamble only

2018-05-08 Thread Nikolai Kosjar via Phabricator via cfe-commits
nik updated this revision to Diff 145648.
nik marked 3 inline comments as done.
nik edited the summary of this revision.
nik added a comment.

Addressed comments.


Repository:
  rC Clang

https://reviews.llvm.org/D45815

Files:
  include/clang-c/Index.h
  include/clang/Frontend/ASTUnit.h
  lib/Frontend/ASTUnit.cpp
  test/Parser/skip-function-bodies.h
  test/Parser/skip-function-bodies.mm
  tools/c-index-test/c-index-test.c
  tools/libclang/CIndex.cpp

Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -3380,9 +3380,15 @@
 = options & CXTranslationUnit_CacheCompletionResults;
   bool IncludeBriefCommentsInCodeCompletion
 = options & CXTranslationUnit_IncludeBriefCommentsInCodeCompletion;
-  bool SkipFunctionBodies = options & CXTranslationUnit_SkipFunctionBodies;
   bool SingleFileParse = options & CXTranslationUnit_SingleFileParse;
   bool ForSerialization = options & CXTranslationUnit_ForSerialization;
+  SkipFunctionBodiesScope SkipFunctionBodies = SkipFunctionBodiesScope::None;
+  if (options & CXTranslationUnit_SkipFunctionBodies) {
+SkipFunctionBodies =
+(options & CXTranslationUnit_LimitSkipFunctionBodiesToPreamble)
+? SkipFunctionBodiesScope::Preamble
+: SkipFunctionBodiesScope::PreambleAndMainFile;
+  }
 
   // Configure the diagnostics.
   IntrusiveRefCntPtr
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
@@ -82,6 +82,8 @@
 options |= CXTranslationUnit_CreatePreambleOnFirstParse;
   if (getenv("CINDEXTEST_KEEP_GOING"))
 options |= CXTranslationUnit_KeepGoing;
+  if (getenv("CINDEXTEST_LIMIT_SKIP_FUNCTION_BODIES_TO_PREAMBLE"))
+options |= CXTranslationUnit_LimitSkipFunctionBodiesToPreamble;
 
   return options;
 }
Index: test/Parser/skip-function-bodies.mm
===
--- test/Parser/skip-function-bodies.mm
+++ test/Parser/skip-function-bodies.mm
@@ -1,4 +1,4 @@
-// RUN: env CINDEXTEST_SKIP_FUNCTION_BODIES=1 c-index-test -test-load-source all %s | FileCheck %s
+#include "skip-function-bodies.h"
 
 class A {
   class B {};
@@ -27,6 +27,7 @@
   class K {};
 }
 
+// RUN: env CINDEXTEST_SKIP_FUNCTION_BODIES=1 c-index-test -test-load-source all %s | FileCheck %s
 // CHECK: skip-function-bodies.mm:3:7: ClassDecl=A:3:7 (Definition) Extent=[3:1 - 14:2]
 // CHECK: skip-function-bodies.mm:4:9: ClassDecl=B:4:9 (Definition) Extent=[4:3 - 4:13]
 // CHECK: skip-function-bodies.mm:6:1: CXXAccessSpecifier=:6:1 (Definition) Extent=[6:1 - 6:8]
@@ -43,3 +44,13 @@
 // CHECK-NOT: skip-function-bodies.mm:21:11: TypeRef=class A:3:7 Extent=[21:11 - 21:12]
 // CHECK: skip-function-bodies.mm:26:6: FunctionDecl=J:26:6 Extent=[26:1 - 26:9]
 // CHECK-NOT: skip-function-bodies.mm:27:9: ClassDecl=K:27:9 (Definition) Extent=[27:3 - 27:13]
+
+// RUN: env CINDEXTEST_EDITING=1 \
+// RUN:  CINDEXTEST_CREATE_PREAMBLE_ON_FIRST_PARSE=1 \
+// RUN:  CINDEXTEST_SKIP_FUNCTION_BODIES=1 \
+// RUN:  CINDEXTEST_LIMIT_SKIP_FUNCTION_BODIES_TO_PREAMBLE=1 \
+// RUN:  c-index-test -test-load-source all %s | FileCheck -check-prefix=CHECK-PREAMBLE %s
+// CHECK-PREAMBLE: skip-function-bodies.h:1:5: FunctionDecl=header1:1:5 Extent=[1:1 - 1:19]
+// CHECK-PREAMBLE-NOT: skip-function-bodies.h:2:3: ReturnStmt= Extent=[2:3 - 2:11]
+// CHECK-PREAMBLE: skip-function-bodies.mm:8:12: StructDecl=C:8:12 (Definition) Extent=[8:5 - 10:6]
+// CHECK-PREAMBLE: skip-function-bodies.mm:9:12: CXXMethod=d:9:12 (Definition) Extent=[9:7 - 9:18]
Index: test/Parser/skip-function-bodies.h
===
--- /dev/null
+++ test/Parser/skip-function-bodies.h
@@ -0,0 +1,3 @@
+int header1(int t) {
+  return t;
+}
Index: lib/Frontend/ASTUnit.cpp
===
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -1271,7 +1271,7 @@
 std::unique_ptr
 ASTUnit::getMainBufferWithPrecompiledPreamble(
 std::shared_ptr PCHContainerOps,
-const CompilerInvocation &PreambleInvocationIn,
+CompilerInvocation &PreambleInvocationIn,
 IntrusiveRefCntPtr VFS, bool AllowRebuild,
 unsigned MaxLines) {
   auto MainFilePath =
@@ -1338,9 +1338,18 @@
 SimpleTimer PreambleTimer(WantTiming);
 PreambleTimer.setOutput("Precompiling preamble");
 
+const bool PreviousSkipFunctionBodies =
+PreambleInvocationIn.getFrontendOpts().SkipFunctionBodies;
+if (SkipFunctionBodies == SkipFunctionBodiesScope::Preamble)
+  PreambleInvocationIn.getFrontendOpts().SkipFunctionBodies = true;
+
 llvm::ErrorOr NewPreamble = PrecompiledPreamble::Build(
 PreambleInvocationIn, MainFileBuffer.get(), Bounds, *Diagnostics, VFS,
 PCHContainerOps, /*StoreInMemory=*/false, Callbacks);
+
+PreambleInvoc

[PATCH] D45815: [libclang] Allow skipping function bodies in preamble only

2018-05-08 Thread Nikolai Kosjar via Phabricator via cfe-commits
nik added inline comments.



Comment at: include/clang/Frontend/ASTUnit.h:370
+  IntrusiveRefCntPtr VFS,
+  SkipFunctionBodiesScope SkipFunctionBodiesScp =
+  SkipFunctionBodiesScope::None,

ilya-biryukov wrote:
> NIT: Maybe keep the name `SkipFunctionBodies`? It seems that putting `Scp` at 
> the end does not add any clarity.
IIRC I've done that to better distinguish it from e.g. 
"getFrontendOpts().SkipFunctionBodies", but yes, they are not so often used 
together, removed "Scp" suffix.



Comment at: include/clang/Frontend/ASTUnit.h:831
ArrayRef RemappedFiles = None,
+   SkipFunctionBodiesScope SkipFunctionBodiesScp =
+   SkipFunctionBodiesScope::None,

ilya-biryukov wrote:
> This parameter seems slightly out of place.
> The scope of skipped function bodies should be a property of the whole 
> `ASTUnit`, changing it on every reparse would mean more complexity and 
> wouldn't be used anyway.
> 
> I suggest storing a field of type `SkipFunctionBodiesScope` instead of adding 
> parameters to `Reparse` and `LoadFromCompilerInvocation`.
Agree, this makes the change significantly shorter :)


Repository:
  rC Clang

https://reviews.llvm.org/D45815



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


[PATCH] D45680: [C++2a] Implement operator<=> Part 2: Operator Rewritting and Overload Resolution.

2018-05-08 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

I'm still not sure how to best generate a diff that best ignores white spaces 
changes caused by clang-format or my editor.

I'll work on removing existing whitespace changes.


https://reviews.llvm.org/D45680



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


[PATCH] D46572: [clang-format] Add raw string formatting to release notes

2018-05-08 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D46572

Files:
  docs/ReleaseNotes.rst


Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -216,6 +216,10 @@
 clang-format
 
 
+- Clang-format will now support detecting and formatting code snippets in raw
+  string literals.  This is configured through the `RawStringFormats` style
+  option.
+
 - ...
 
 libclang


Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -216,6 +216,10 @@
 clang-format
 
 
+- Clang-format will now support detecting and formatting code snippets in raw
+  string literals.  This is configured through the `RawStringFormats` style
+  option.
+
 - ...
 
 libclang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46572: [clang-format] Add raw string formatting to release notes

2018-05-08 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rC Clang

https://reviews.llvm.org/D46572



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


[PATCH] D46519: [clang-format] Respect BreakBeforeClosingBrace while calculating length

2018-05-08 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added inline comments.



Comment at: lib/Format/ContinuationIndenter.cpp:44
+  int MatchingStackIndex = Stack.size() - 1;
+  while (MatchingStackIndex >= 0 && Stack[MatchingStackIndex].Tok != &Tok)
+--MatchingStackIndex;

I think this needs a long explanatory comment, possibly with an example of the 
problem it is actually solving.

Also, I am somewhat skeptical as we are using this logic for all paren kinds, 
not just braces. That seems to be unnecessary work and also might be unexpected 
at some point (although I cannot come up with a test case where that would be 
wrong).



Comment at: lib/Format/ContinuationIndenter.cpp:49
+  break;
+while (MatchingStackIndex >= 0 &&
+   Stack[MatchingStackIndex].Tok != End->Next->MatchingParen)

Maybe pull out a lambda:

  auto FindParenState = [&](const FormatToken *Tok) {
while (MatchingStackIndex >= 0 && Stack[MatchingStackIndex].Tok != &Tok)
  --MatchingStackIndex;
return MatchingStackIndex >= 0 ? &Stack[MatchingStackIndex] : nullptr;
  };

Then you could write the rest as:

  ...
  FindParenState(&Tok);
  const auto* End = Tok.MatchingParen
  for (; End->Next; End = End->Next) {
if (End->Next->CanBreakBefore || !End->Next->closesScope())
  break;
auto ParenState = FindParenState(End->Next->MatchingParen);
if (ParenState && ParenState.BreakBeforeClosingBrace)
  break;
  }
  return End->TotalLength - Tok.TotalLength + 1;


(not entirely sure it's better)



Comment at: lib/Format/ContinuationIndenter.h:215
+  /// \brief The token opening this parenthesis level, or nullptr if this level
+  /// is opened by fake parenthesis.
+  const FormatToken *Tok;

The comment should include that this is not considered for memoization as the 
same state will always be represented by the same token (similar to other 
below). I wonder whether we should actually move the fields that don't affect 
memoization out to a different structure at some point.


Repository:
  rC Clang

https://reviews.llvm.org/D46519



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


r331750 - [clang-format] Add raw string formatting to release notes

2018-05-08 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Tue May  8 02:25:12 2018
New Revision: 331750

URL: http://llvm.org/viewvc/llvm-project?rev=331750&view=rev
Log:
[clang-format] Add raw string formatting to release notes

Reviewers: hans

Reviewed By: hans

Subscribers: cfe-commits

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

Modified:
cfe/trunk/docs/ReleaseNotes.rst

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=331750&r1=331749&r2=331750&view=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Tue May  8 02:25:12 2018
@@ -216,6 +216,10 @@ AST Matchers
 clang-format
 
 
+- Clang-format will now support detecting and formatting code snippets in raw
+  string literals.  This is configured through the `RawStringFormats` style
+  option.
+
 - ...
 
 libclang


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


[PATCH] D46572: [clang-format] Add raw string formatting to release notes

2018-05-08 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL331750: [clang-format] Add raw string formatting to release 
notes (authored by krasimir, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D46572

Files:
  cfe/trunk/docs/ReleaseNotes.rst


Index: cfe/trunk/docs/ReleaseNotes.rst
===
--- cfe/trunk/docs/ReleaseNotes.rst
+++ cfe/trunk/docs/ReleaseNotes.rst
@@ -216,6 +216,10 @@
 clang-format
 
 
+- Clang-format will now support detecting and formatting code snippets in raw
+  string literals.  This is configured through the `RawStringFormats` style
+  option.
+
 - ...
 
 libclang


Index: cfe/trunk/docs/ReleaseNotes.rst
===
--- cfe/trunk/docs/ReleaseNotes.rst
+++ cfe/trunk/docs/ReleaseNotes.rst
@@ -216,6 +216,10 @@
 clang-format
 
 
+- Clang-format will now support detecting and formatting code snippets in raw
+  string literals.  This is configured through the `RawStringFormats` style
+  option.
+
 - ...
 
 libclang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46115: [ASTImporter] properly import SrcLoc of Attr

2018-05-08 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin accepted this revision.
a.sidorin added a comment.
This revision is now accepted and ready to land.

Looks good!




Comment at: lib/AST/ASTImporter.cpp:2650
+  for (const auto *A : D->attrs())
+ToIndirectField->addAttr(Importer.Import(const_cast(A)));
 

r.stahl wrote:
> a.sidorin wrote:
> > Could we just remove 'const' qualifier from `A` to avoid `const_cast`? 
> > (Same below)
> I made the interface const instead.
Yes, that's even better!



Comment at: lib/AST/ASTImporter.cpp:4724
   SmallVector ToAttrs(FromAttrs.size());
-  ASTContext &_ToContext = Importer.getToContext();
   std::transform(FromAttrs.begin(), FromAttrs.end(), ToAttrs.begin(),
+[this](const Attr *A) -> const Attr * {

a.sidorin wrote:
> Could we use ImportArrayChecked instead?
We can use just `ImportArrayChecked(FromAttrs, ToAttrs.begin())`. But this is 
more a hint than a requirement.


https://reviews.llvm.org/D46115



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


r331753 - Fix 'not all control paths return a value' MSVC warnings. NFCI.

2018-05-08 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Tue May  8 02:40:32 2018
New Revision: 331753

URL: http://llvm.org/viewvc/llvm-project?rev=331753&view=rev
Log:
Fix 'not all control paths return a value' MSVC warnings. NFCI.

Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/CodeGen/CGExprAgg.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=331753&r1=331752&r2=331753&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue May  8 02:40:32 2018
@@ -8616,6 +8616,7 @@ EvaluateComparisonBinaryOperator(EvalInf
   case APFloat::cmpUnordered:
 return CCR::Unordered;
   }
+  llvm_unreachable("Unrecognised APFloat::cmpResult enum");
 };
 return Success(GetCmpRes(), E);
   }

Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=331753&r1=331752&r2=331753&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Tue May  8 02:40:32 2018
@@ -920,6 +920,7 @@ static llvm::Value *EmitCompare(CGBuilde
 case CK_Equal:
   return {"cmp.eq", FI::FCMP_OEQ, II::ICMP_EQ, II::ICMP_EQ};
 }
+llvm_unreachable("Unrecognised CompareKind enum");
   }();
 
   if (ArgTy->hasFloatingRepresentation())


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


[PATCH] D46524: [clangd] Extract scoring/ranking logic, and shave yaks.

2018-05-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

The new uploaded diff has lots of unrelated changes to clang-tidy, clang-move, 
etc...
Looking at commits, it seems `arc diff` was called with the wrong base 
commit... 
Could you please reupload the change?




Comment at: clangd/Quality.h:45
+
+// Attributes of a symbol that affect how much we like it.
+struct SymbolQualitySignals {

ilya-biryukov wrote:
> Maybe use doxygen-style comments to be consistent with the rest of LLVM?
Some changes are missing?
File still uses 2-slash instead of 3-slash comments.



Comment at: clangd/Quality.h:66
+  float NameMatch = 1;
+  bool Unavailable = false;
+

sammccall wrote:
> ilya-biryukov wrote:
> > Maybe rename to `Inaccessible`? It seems to be closer to what this bool 
> > means in C++, if I'm reading the code correctly.
> > Or add a comment explaining what "unavailable" means?
> So it's `Unavailable || Inaccessible`, where neither is all that well-defined 
> :-)
> I renamed to `Forbidden` to avoid conflation with either, and added examples 
> as a comment.
Thanks! `Forbidden` with a comment LG.



Comment at: unittests/clangd/TestTU.h:28
+  TestTU() = default;
+  TestTU(llvm::StringRef Code, llvm::StringRef HeaderCode = "")
+  : Code(Code), HeaderCode(HeaderCode) {}

sammccall wrote:
> ilya-biryukov wrote:
> > I really like this helper, now that we can reuse the code between different 
> > tests!
> > It took me some time to get the semantics of this constructor, though.
> > I suggest to have a few constructor functions with more descriptive name 
> > (my names are not great, but should give the idea):
> > ```
> > static TestTU FromSourceFile(StringRef Code);
> > static TestTU FromHeaderFile(StringRef Code);
> > static TestTU WithImplicitInclude(StringRef Source, StringRef 
> > IncludedHeader);
> > ```
> > 
> > 
> > 
> Done, Just added `withCode` and `withHeaderCode` for now, and anyone who 
> wants something more complicated can set the fields directly.
> (The names mirror the struct fields)
LG, thanks.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46524



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


[PATCH] D46115: [ASTImporter] properly import SrcLoc of Attr

2018-05-08 Thread Rafael Stahl via Phabricator via cfe-commits
r.stahl updated this revision to Diff 145660.
r.stahl added a comment.

Didn't see that overload, thanks!

I need someone to commit this for me.


https://reviews.llvm.org/D46115

Files:
  include/clang/AST/ASTImporter.h
  lib/AST/ASTImporter.cpp
  test/Import/attr/Inputs/S.cpp
  test/Import/attr/test.cpp

Index: test/Import/attr/Inputs/S.cpp
===
--- test/Import/attr/Inputs/S.cpp
+++ test/Import/attr/Inputs/S.cpp
@@ -0,0 +1,13 @@
+extern void f() __attribute__((const));
+
+struct S {
+  struct {
+int a __attribute__((packed));
+  };
+};
+
+void stmt() {
+#pragma unroll
+  for (;;)
+;
+}
Index: test/Import/attr/test.cpp
===
--- test/Import/attr/test.cpp
+++ test/Import/attr/test.cpp
@@ -0,0 +1,26 @@
+// RUN: clang-import-test -dump-ast -import %S/Inputs/S.cpp -expression %s | FileCheck %s
+// CHECK: FunctionDecl
+// CHECK-SAME: S.cpp:1:1, col:13
+// CHECK-NEXT: ConstAttr
+// CHECK-SAME: col:32
+
+// CHECK: IndirectFieldDecl
+// CHECK-NEXT: Field
+// CHECK-NEXT: Field
+// CHECK-NEXT: PackedAttr
+// CHECK-SAME: col:26
+
+// CHECK: AttributedStmt
+// CHECK-NEXT: LoopHintAttr
+// CHECK-SAME: line:10:9
+
+extern void f() __attribute__((const));
+
+struct S;
+
+void stmt();
+
+void expr() {
+  f();
+  struct S s;
+}
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -2646,8 +2646,8 @@
   Importer.getToContext(), DC, Loc, Name.getAsIdentifierInfo(), T,
   {NamedChain, D->getChainingSize()});
 
-  for (const auto *Attr : D->attrs())
-ToIndirectField->addAttr(Attr->clone(Importer.getToContext()));
+  for (const auto *A : D->attrs())
+ToIndirectField->addAttr(Importer.Import(A));
 
   ToIndirectField->setAccess(D->getAccess());
   ToIndirectField->setLexicalDeclContext(LexicalDC);
@@ -4721,15 +4721,8 @@
   SourceLocation ToAttrLoc = Importer.Import(S->getAttrLoc());
   ArrayRef FromAttrs(S->getAttrs());
   SmallVector ToAttrs(FromAttrs.size());
-  ASTContext &_ToContext = Importer.getToContext();
-  std::transform(FromAttrs.begin(), FromAttrs.end(), ToAttrs.begin(),
-[&_ToContext](const Attr *A) -> const Attr * {
-  return A->clone(_ToContext);
-});
-  for (const auto *ToA : ToAttrs) {
-if (!ToA)
-  return nullptr;
-  }
+  if (ImportArrayChecked(FromAttrs, ToAttrs.begin()))
+return nullptr;
   Stmt *ToSubStmt = Importer.Import(S->getSubStmt());
   if (!ToSubStmt && S->getSubStmt())
 return nullptr;
@@ -6544,6 +6537,12 @@
Import(FromTSI->getTypeLoc().getLocStart()));
 }
 
+Attr *ASTImporter::Import(const Attr *FromAttr) {
+  Attr *ToAttr = FromAttr->clone(ToContext);
+  ToAttr->setRange(Import(FromAttr->getRange()));
+  return ToAttr;
+}
+
 Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) {
   llvm::DenseMap::iterator Pos = ImportedDecls.find(FromD);
   if (Pos != ImportedDecls.end()) {
@@ -7199,8 +7198,8 @@
 
 Decl *ASTImporter::Imported(Decl *From, Decl *To) {
   if (From->hasAttrs()) {
-for (auto *FromAttr : From->getAttrs())
-  To->addAttr(FromAttr->clone(To->getASTContext()));
+for (const auto *FromAttr : From->getAttrs())
+  To->addAttr(Import(FromAttr));
   }
   if (From->isUsed()) {
 To->setIsUsed();
Index: include/clang/AST/ASTImporter.h
===
--- include/clang/AST/ASTImporter.h
+++ include/clang/AST/ASTImporter.h
@@ -41,6 +41,7 @@
 class Stmt;
 class TagDecl;
 class TypeSourceInfo;
+class Attr;
 
   /// \brief Imports selected nodes from one AST context into another context,
   /// merging AST nodes where appropriate.
@@ -130,6 +131,12 @@
 /// context, or NULL if an error occurred.
 TypeSourceInfo *Import(TypeSourceInfo *FromTSI);
 
+/// \brief Import the given attribute from the "from" context into the
+/// "to" context.
+///
+/// \returns the equivalent attribute in the "to" context.
+Attr *Import(const Attr *FromAttr);
+
 /// \brief Import the given declaration from the "from" context into the 
 /// "to" context.
 ///
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46519: [clang-format] Respect BreakBeforeClosingBrace while calculating length

2018-05-08 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 145661.
krasimir marked 2 inline comments as done.
krasimir added a comment.

- Address review comments


Repository:
  rC Clang

https://reviews.llvm.org/D46519

Files:
  lib/Format/ContinuationIndenter.cpp
  lib/Format/ContinuationIndenter.h
  lib/Format/UnwrappedLineFormatter.cpp
  unittests/Format/FormatTestProto.cpp
  unittests/Format/FormatTestRawStrings.cpp
  unittests/Format/FormatTestTextProto.cpp

Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -469,6 +469,7 @@
"ccc: <\n"
"  operator: 1\n"
"  operator: 2\n"
+   "  operator: 3\n"
"  operator { key: value }\n"
">\n"
"  >\n"
Index: unittests/Format/FormatTestRawStrings.cpp
===
--- unittests/Format/FormatTestRawStrings.cpp
+++ unittests/Format/FormatTestRawStrings.cpp
@@ -822,6 +822,41 @@
 )test", Style));
 }
 
+TEST_F(FormatTestRawStrings, KeepsRBraceFolloedByMoreLBracesOnSameLine) {
+  FormatStyle Style = getRawStringPbStyleWithColumns(80);
+
+  expect_eq(
+R"test(
+int f() {
+  if (1) {
+T s = PARSE_TEXT_PROTO(R"pb(
+  t {
+p {
+  [cc.pp.] { field_1: "123_1" }
+  [cc.pp.] { field_2: "123_2" }
+}
+  }
+)pb");
+  }
+}
+)test",
+format(
+R"test(
+int f() {
+  if (1) {
+   T s = PARSE_TEXT_PROTO(R"pb(
+   t {
+   p {
+   [cc.pp.] { field_1: "123_1" }
+   [cc.pp.] { field_2: "123_2" }}}
+   )pb");
+  }
+}
+)test",
+Style));
+}
+
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -486,6 +486,7 @@
"ccc: <\n"
"  operator: 1\n"
"  operator: 2\n"
+   "  operator: 3\n"
"  operator { key: value }\n"
">\n"
"  >\n"
Index: lib/Format/UnwrappedLineFormatter.cpp
===
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -659,8 +659,8 @@
 static void printLineState(const LineState &State) {
   llvm::dbgs() << "State: ";
   for (const ParenState &P : State.Stack) {
-llvm::dbgs() << P.Indent << "|" << P.LastSpace << "|" << P.NestedBlockIndent
- << " ";
+llvm::dbgs() << (P.Tok ? P.Tok->TokenText : "F") << "|" << P.Indent << "|"
+ << P.LastSpace << "|" << P.NestedBlockIndent << " ";
   }
   llvm::dbgs() << State.NextToken->TokenText << "\n";
 }
Index: lib/Format/ContinuationIndenter.h
===
--- lib/Format/ContinuationIndenter.h
+++ lib/Format/ContinuationIndenter.h
@@ -200,16 +200,23 @@
 };
 
 struct ParenState {
-  ParenState(unsigned Indent, unsigned LastSpace, bool AvoidBinPacking,
- bool NoLineBreak)
-  : Indent(Indent), LastSpace(LastSpace), NestedBlockIndent(Indent),
-BreakBeforeClosingBrace(false), AvoidBinPacking(AvoidBinPacking),
-BreakBeforeParameter(false), NoLineBreak(NoLineBreak),
-NoLineBreakInOperand(false), LastOperatorWrapped(true),
-ContainsLineBreak(false), ContainsUnwrappedBuilder(false),
-AlignColons(true), ObjCSelectorNameFound(false),
-HasMultipleNestedBlocks(false), NestedBlockInlined(false),
-IsInsideObjCArrayLiteral(false) {}
+  ParenState(const FormatToken *Tok, unsigned Indent, unsigned LastSpace,
+ bool AvoidBinPacking, bool NoLineBreak)
+  : Tok(Tok), Indent(Indent), LastSpace(LastSpace),
+NestedBlockIndent(Indent), BreakBeforeClosingBrace(false),
+AvoidBinPacking(AvoidBinPacking), BreakBeforeParameter(false),
+NoLineBreak(NoLineBreak), NoLineBreakInOperand(false),
+LastOperatorWrapped(true), ContainsLineBreak(false),
+ContainsUnwrappedBuilder(false), AlignColons(true),
+ObjCSelectorNameFound(false), HasMultipleNestedBlocks(false),
+NestedBlockInlined(false), IsInsideObjCArrayLiteral(false) {}
+
+  /// \brief The token opening this parenthesis level, or nullptr if this level
+  /// is opened by fake parenthesis.
+  ///
+  /// Not considered for memoization as it will always hav

[PATCH] D46519: [clang-format] Respect BreakBeforeClosingBrace while calculating length

2018-05-08 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir marked an inline comment as done and an inline comment as not done.
krasimir added inline comments.



Comment at: lib/Format/ContinuationIndenter.cpp:44
+  int MatchingStackIndex = Stack.size() - 1;
+  while (MatchingStackIndex >= 0 && Stack[MatchingStackIndex].Tok != &Tok)
+--MatchingStackIndex;

djasper wrote:
> I think this needs a long explanatory comment, possibly with an example of 
> the problem it is actually solving.
> 
> Also, I am somewhat skeptical as we are using this logic for all paren kinds, 
> not just braces. That seems to be unnecessary work and also might be 
> unexpected at some point (although I cannot come up with a test case where 
> that would be wrong).
Thanks! Added an example and tweaked it a little bit so that it doesn't 
traverse the stack unless it is visiting `tok::r_brace`.



Comment at: lib/Format/ContinuationIndenter.cpp:49
+  break;
+while (MatchingStackIndex >= 0 &&
+   Stack[MatchingStackIndex].Tok != End->Next->MatchingParen)

djasper wrote:
> Maybe pull out a lambda:
> 
>   auto FindParenState = [&](const FormatToken *Tok) {
> while (MatchingStackIndex >= 0 && Stack[MatchingStackIndex].Tok != &Tok)
>   --MatchingStackIndex;
> return MatchingStackIndex >= 0 ? &Stack[MatchingStackIndex] : nullptr;
>   };
> 
> Then you could write the rest as:
> 
>   ...
>   FindParenState(&Tok);
>   const auto* End = Tok.MatchingParen
>   for (; End->Next; End = End->Next) {
> if (End->Next->CanBreakBefore || !End->Next->closesScope())
>   break;
> auto ParenState = FindParenState(End->Next->MatchingParen);
> if (ParenState && ParenState.BreakBeforeClosingBrace)
>   break;
>   }
>   return End->TotalLength - Tok.TotalLength + 1;
> 
> 
> (not entirely sure it's better)
Yeah, a lambda is good.


Repository:
  rC Clang

https://reviews.llvm.org/D46519



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


[PATCH] D46519: [clang-format] Respect BreakBeforeClosingBrace while calculating length

2018-05-08 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Generally looks good.




Comment at: lib/Format/ContinuationIndenter.cpp:93
+  break;
+if (End->Next->is(tok::r_brace)) {
+  const ParenState *State = FindParenState(End->Next->MatchingParen);

I r_brace enough? Do we have something similar for TT_ArrayInitializer? I'd 
look at usages of BreakBeforeClosingBrace to determine.


Repository:
  rC Clang

https://reviews.llvm.org/D46519



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


[PATCH] D41537: Optionally add code completion results for arrow instead of dot

2018-05-08 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added inline comments.



Comment at: include/clang-c/Index.h:5220
+CINDEX_LINKAGE CXString
+clang_getCompletionCorrection(CXCompletionString completion_string,
+  unsigned correction_index,

ilya-biryukov wrote:
> I'm a bit vary about exposing source manager and language options in the API 
> just for the sake of corrections.
> I suggest we add an extra parameter of an existing class 
> (`CXCodeCompleteResults`) instead and remove the corresponding helpers to get 
> source manager and language options:
> `clang_getCompletionNumCorrections(CXCompletionString completion_string, 
> CXCodeCompleteResults* results);`
> 
Haha, I had that interface initially but thought it's too ugly and needs to be 
improved :)



Comment at: include/clang/Sema/CodeCompleteConsumer.h:564
+
+  /// \brief For this completion result correction is required.
+  std::vector Corrections;

ilya-biryukov wrote:
> Adding some docs here would be useful. These fix-its could be interpreted too 
> broadly at this point.
> I suggest the following semantics and the comment:
> 
> ```
> /// \brief FixIts that *must* be applied before inserting the text for the 
> corresponding completion item.
> /// Completion items with non-empty fixits will not be returned by default, 
> they should be explicitly requested by setting 
> CompletionOptions::IncludeCorrections.
> /// For the editors to be able to compute position of the cursor for the 
> completion item itself, the following conditions are guaranteed to hold for 
> RemoveRange of the stored fixits:
> ///  - Ranges in the fixits are guaranteed to never contain the completion 
> point (or identifier under completion point, if any) inside them, except at 
> the start or at the end of the range.
> ///  - If a fixit range starts or ends with completion point (or starts or 
> ends after the identifier under completion point), it will contain at least 
> one character. It allows to unambiguously recompute completion point after 
> applying the fixit.
> /// The intuition is that provided fixits change code around the identifier 
> we complete, but are not allowed to touch the identifier itself or the 
> completion point.
> /// One example of completion items with corrections are the ones replacing 
> '.' with '->' and vice versa:
> ///  std::unique_ptr> vec_ptr;
> ///  vec_ptr.^  // completion returns an item 'push_back', replacing '.' 
> with '->'
> ///  vec_ptr->^ // completion returns an item 'release', replacing '->' 
> with '.'let's put 
> ```
> 
> Do those invariants sound reasonable? Could we add asserts that they hold 
> when constructing the completion results?
Thanks! I usually feel the lack of patience when writing descriptions :)



Comment at: include/clang/Sema/CodeCompleteConsumer.h:564
+
+  /// \brief For this completion result correction is required.
+  std::vector Corrections;

yvvan wrote:
> ilya-biryukov wrote:
> > Adding some docs here would be useful. These fix-its could be interpreted 
> > too broadly at this point.
> > I suggest the following semantics and the comment:
> > 
> > ```
> > /// \brief FixIts that *must* be applied before inserting the text for the 
> > corresponding completion item.
> > /// Completion items with non-empty fixits will not be returned by default, 
> > they should be explicitly requested by setting 
> > CompletionOptions::IncludeCorrections.
> > /// For the editors to be able to compute position of the cursor for the 
> > completion item itself, the following conditions are guaranteed to hold for 
> > RemoveRange of the stored fixits:
> > ///  - Ranges in the fixits are guaranteed to never contain the completion 
> > point (or identifier under completion point, if any) inside them, except at 
> > the start or at the end of the range.
> > ///  - If a fixit range starts or ends with completion point (or starts or 
> > ends after the identifier under completion point), it will contain at least 
> > one character. It allows to unambiguously recompute completion point after 
> > applying the fixit.
> > /// The intuition is that provided fixits change code around the identifier 
> > we complete, but are not allowed to touch the identifier itself or the 
> > completion point.
> > /// One example of completion items with corrections are the ones replacing 
> > '.' with '->' and vice versa:
> > ///  std::unique_ptr> vec_ptr;
> > ///  vec_ptr.^  // completion returns an item 'push_back', replacing 
> > '.' with '->'
> > ///  vec_ptr->^ // completion returns an item 'release', replacing '->' 
> > with '.'let's put 
> > ```
> > 
> > Do those invariants sound reasonable? Could we add asserts that they hold 
> > when constructing the completion results?
> Thanks! I usually feel the lack of patience when writing descriptions :)
"Could we add asserts that they hold when constructing the completion results"

The current 

[PATCH] D41537: Optionally add code completion results for arrow instead of dot

2018-05-08 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 145664.
yvvan added a comment.

Address comments and provide diff with full context


https://reviews.llvm.org/D41537

Files:
  include/clang-c/Index.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/CodeCompleteConsumer.h
  include/clang/Sema/CodeCompleteOptions.h
  include/clang/Sema/Sema.h
  lib/Frontend/ASTUnit.cpp
  lib/Parse/ParseExpr.cpp
  lib/Sema/CodeCompleteConsumer.cpp
  lib/Sema/SemaCodeComplete.cpp
  test/FixIt/fixit.cpp
  test/Index/complete-arrow-dot.cpp
  test/SemaCXX/member-expr.cpp
  tools/c-index-test/c-index-test.c
  tools/libclang/CIndexCodeCompletion.cpp
  tools/libclang/libclang.exports

Index: tools/libclang/libclang.exports
===
--- tools/libclang/libclang.exports
+++ tools/libclang/libclang.exports
@@ -171,6 +171,8 @@
 clang_getCompletionChunkCompletionString
 clang_getCompletionChunkKind
 clang_getCompletionChunkText
+clang_getCompletionNumFixIts
+clang_getCompletionFixIt
 clang_getCompletionNumAnnotations
 clang_getCompletionParent
 clang_getCompletionPriority
Index: tools/libclang/CIndexCodeCompletion.cpp
===
--- tools/libclang/CIndexCodeCompletion.cpp
+++ tools/libclang/CIndexCodeCompletion.cpp
@@ -16,6 +16,7 @@
 #include "CIndexDiagnostic.h"
 #include "CLog.h"
 #include "CXCursor.h"
+#include "CXSourceLocation.h"
 #include "CXString.h"
 #include "CXTranslationUnit.h"
 #include "clang/AST/Decl.h"
@@ -306,6 +307,48 @@
 
 } // end anonymous namespace
 
+unsigned clang_getCompletionNumFixIts(CXCompletionString completion_string) {
+  CodeCompletionString *CCStr = (CodeCompletionString *)completion_string;
+
+  if (!CCStr)
+return 0;
+  return static_cast(CCStr->getFixIts().size());
+}
+
+CXString clang_getCompletionFixIt(CXCompletionString completion_string,
+  unsigned correction_index,
+  CXSourceRange *replacement_range,
+  CXCodeCompleteResults *results) {
+  CodeCompletionString *CCStr = (CodeCompletionString *)completion_string;
+
+  if (!CCStr) {
+if (replacement_range)
+  *replacement_range = clang_getNullRange();
+return cxstring::createNull();
+  }
+
+  llvm::ArrayRef FixIts = CCStr->getFixIts();
+  if (FixIts.size() <= correction_index) {
+if (replacement_range)
+  *replacement_range = clang_getNullRange();
+return cxstring::createNull();
+  }
+
+  const FixItHint &FixIt = FixIts[correction_index];
+  if (replacement_range) {
+AllocatedCXCodeCompleteResults *allocated_results = (AllocatedCXCodeCompleteResults *)results;
+if (!allocated_results) {
+  *replacement_range = clang_getNullRange();
+} else {
+  *replacement_range = cxloc::translateSourceRange(*allocated_results->SourceMgr,
+   allocated_results->LangOpts,
+   FixIt.RemoveRange);
+}
+  }
+
+  return cxstring::createRef(FixIt.CodeToInsert.c_str());
+}
+
 /// \brief Tracks the number of code-completion result objects that are 
 /// currently active.
 ///
@@ -532,7 +575,7 @@
 unsigned NumResults) override {
   StoredResults.reserve(StoredResults.size() + NumResults);
   for (unsigned I = 0; I != NumResults; ++I) {
-CodeCompletionString *StoredCompletion
+CodeCompletionString *StoredCompletion
   = Results[I].CreateCodeCompletionString(S, Context, getAllocator(),
   getCodeCompletionTUInfo(),
   includeBriefComments());
@@ -644,13 +687,13 @@
   unsigned options) {
   bool IncludeBriefComments = options & CXCodeComplete_IncludeBriefComments;
   bool SkipPreamble = options & CXCodeComplete_SkipPreamble;
+  bool IncludeFixIts = options & CXCodeComplete_IncludeFixIts;
 
 #ifdef UDP_CODE_COMPLETION_LOGGER
 #ifdef UDP_CODE_COMPLETION_LOGGER_PORT
   const llvm::TimeRecord &StartTime =  llvm::TimeRecord::getCurrentTime();
 #endif
 #endif
-
   bool EnableLogging = getenv("LIBCLANG_CODE_COMPLETION_LOGGING") != nullptr;
 
   if (cxtu::isNotUsableTU(TU)) {
@@ -691,6 +734,7 @@
   CodeCompleteOptions Opts;
   Opts.IncludeBriefComments = IncludeBriefComments;
   Opts.LoadExternal = !SkipPreamble;
+  Opts.IncludeFixIts = IncludeFixIts;
   CaptureCompletionResults Capture(Opts, *Results, &TU);
 
   // Perform completion.
@@ -964,7 +1008,7 @@
 = (CodeCompletionString *)XR.CompletionString;
   CodeCompletionString *Y
 = (CodeCompletionString *)YR.CompletionString;
-  
+
   SmallString<256> XBuffer;
   StringRef XText = GetTypedName(X, XBuffer);
   SmallString<256> YBuffer;
Index: tools/c-index-test/c-index-test.c
===

[PATCH] D46522: [clang] cmake: resolve symlinks in ClangConfig.cmake

2018-05-08 Thread Peter Wu via Phabricator via cfe-commits
Lekensteyn added reviewers: brad.king, gottesmm, mgorny.
Lekensteyn added a comment.

Hi, this patch was required to make `find_package(Clang CONFIG)` work when 
`/usr/lib/llvm/clang-X.Y` was a symlink and is integrated in the Debian 
packaging. Please have a look, thanks!

One unfortunate limitation (that existed before) is that `find_package(Clang 
5.0)` does not work because `CLANG_VERSION_*` is not defined. So
`find_package(LLVM 6.0)` could locate 
`/usr/lib/cmake/llvm-6.0/LLVMConfig.cmake` but then
`find_package(Clang)` could end up using `/usr/lib/cmake/clang-5.0`. (This was 
discovered while testing a Clang 6.0 build on a system with Clang 5.0 
co-installed.)

The reason for me to use different Clang versions is for CI purposes. As such, 
I am currently using `CMAKE_PREFIX_PATH=/usr/lib/llvm-6.0` which will find the 
correct version without explicitly having to specify it in `find_package`.


Repository:
  rC Clang

https://reviews.llvm.org/D46522



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


[PATCH] D46159: [clang-tidy] Add a flag to enable alpha checkers

2018-05-08 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

Given Artem's answer (and if there are no objections from other CSA 
maintainers), I have no concerns with this patch going in. A couple of minor 
nits.




Comment at: clang-tidy/ClangTidyDiagnosticConsumer.h:190-191
 
+  /// \brief Turns on experimental alpha checkers from the static analyzer.
+  bool isAlphaChecksAllowed() const {
+return AllowEnablingAnalyzerAlphaCheckers;

Let's call this function more consistently with all other instances of this 
setting, e.g. canEnableAnalyzerAlphaCheckers() (alternatively, 
mayEnableAnalyzerAlphaCheckers) and change the comment to be in line with the 
actual meaning of the function (it doesn't turn on alpha checkers, it merely 
allows them to be enabled).



Comment at: test/clang-tidy/enable-alpha-checks.cpp:1
+// Check if '-allow-enabling-analyzer-alpha-checkers' is visible for users
+// RUN: clang-tidy -help | not grep 'allow-enabling-analyzer-alpha-checkers'

nit: Add a trailing period.


https://reviews.llvm.org/D46159



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


[PATCH] D46233: [ASTMatchers] Overload isConstexpr for ifStmts

2018-05-08 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG


https://reviews.llvm.org/D46233



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


[PATCH] D46159: [clang-tidy] Add a flag to enable alpha checkers

2018-05-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

Aside from a minor commenting nit, also LGTM.




Comment at: clang-tidy/tool/ClangTidyMain.cpp:195
 
+/// This option allows enabling alpha checkers from the static analyzer, that
+/// are experimental. This option is set to false and not visible in help,

I'd reword to: This option allows enabling the experimental alpha checkers from 
the static analyzer.


https://reviews.llvm.org/D46159



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


r331759 - [ASTMatchers] Overload isConstexpr for ifStmts

2018-05-08 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Tue May  8 04:53:32 2018
New Revision: 331759

URL: http://llvm.org/viewvc/llvm-project?rev=331759&view=rev
Log:
[ASTMatchers] Overload isConstexpr for ifStmts

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

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=331759&r1=331758&r2=331759&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Tue May  8 04:53:32 2018
@@ -2789,15 +2789,19 @@ auto Y() -> int {}
 
 
 MatcherFunctionDecl>isConstexpr
-Matches constexpr 
variable and function declarations.
+Matches constexpr 
variable and function declarations,
+   and if constexpr.
 
 Given:
   constexpr int foo = 42;
   constexpr int bar();
+  void baz() { if constexpr(1 > 0) {} }
 varDecl(isConstexpr())
   matches the declaration of foo.
 functionDecl(isConstexpr())
   matches the declaration of bar.
+ifStmt(isConstexpr())
+  matches the if statement in baz.
 
 
 
@@ -3039,6 +3043,23 @@ functionProtoType(parameterCountIs(3))
 
 
 
+MatcherIfStmt>isConstexpr
+Matches constexpr 
variable and function declarations,
+   and if constexpr.
+
+Given:
+  constexpr int foo = 42;
+  constexpr int bar();
+  void baz() { if constexpr(1 > 0) {} }
+varDecl(isConstexpr())
+  matches the declaration of foo.
+functionDecl(isConstexpr())
+  matches the declaration of bar.
+ifStmt(isConstexpr())
+  matches the if statement in baz.
+
+
+
 MatcherIntegerLiteral>equalsbool Value
 
 
@@ -3803,15 +3824,19 @@ int a;
 
 
 MatcherVarDecl>isConstexpr
-Matches constexpr 
variable and function declarations.
+Matches constexpr 
variable and function declarations,
+   and if constexpr.
 
 Given:
   constexpr int foo = 42;
   constexpr int bar();
+  void baz() { if constexpr(1 > 0) {} }
 varDecl(isConstexpr())
   matches the declaration of foo.
 functionDecl(isConstexpr())
   matches the declaration of bar.
+ifStmt(isConstexpr())
+  matches the if statement in baz.
 
 
 

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=331759&r1=331758&r2=331759&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Tue May  8 04:53:32 2018
@@ -3763,20 +3763,25 @@ AST_POLYMORPHIC_MATCHER(isNoThrow,
   return FnTy->isNothrow();
 }
 
-/// \brief Matches constexpr variable and function declarations.
+/// \brief Matches constexpr variable and function declarations,
+///and if constexpr.
 ///
 /// Given:
 /// \code
 ///   constexpr int foo = 42;
 ///   constexpr int bar();
+///   void baz() { if constexpr(1 > 0) {} }
 /// \endcode
 /// varDecl(isConstexpr())
 ///   matches the declaration of foo.
 /// functionDecl(isConstexpr())
 ///   matches the declaration of bar.
+/// ifStmt(isConstexpr())
+///   matches the if statement in baz.
 AST_POLYMORPHIC_MATCHER(isConstexpr,
 AST_POLYMORPHIC_SUPPORTED_TYPES(VarDecl,
-FunctionDecl)) {
+FunctionDecl,
+IfStmt)) {
   return Node.isConstexpr();
 }
 

Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp?rev=331759&r1=331758&r2=331759&view=diff
==
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Tue May  8 
04:53:32 2018
@@ -894,6 +894,10 @@ TEST(isConstexpr, MatchesConstexprDeclar
   varDecl(hasName("foo"), isConstexpr(;
   EXPECT_TRUE(matches("constexpr int bar();",
   functionDecl(hasName("bar"), isConstexpr(;
+  EXPECT_TRUE(matchesConditionally("void baz() { if constexpr(1 > 0) {} }",
+   ifStmt(isConstexpr()), true, "-std=c++17"));
+  EXPECT_TRUE(matchesConditionally("void baz() { if (1 > 0) {} }",
+   ifStmt(isConstexpr()), false, 
"-std=c++17"));
 }
 
 TEST(TemplateArgumentCountIs, Matc

[PATCH] D46233: [ASTMatchers] Overload isConstexpr for ifStmts

2018-05-08 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC331759: [ASTMatchers] Overload isConstexpr for ifStmts 
(authored by xazax, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D46233?vs=145370&id=145668#toc

Repository:
  rC Clang

https://reviews.llvm.org/D46233

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

Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -894,6 +894,10 @@
   varDecl(hasName("foo"), isConstexpr(;
   EXPECT_TRUE(matches("constexpr int bar();",
   functionDecl(hasName("bar"), isConstexpr(;
+  EXPECT_TRUE(matchesConditionally("void baz() { if constexpr(1 > 0) {} }",
+   ifStmt(isConstexpr()), true, "-std=c++17"));
+  EXPECT_TRUE(matchesConditionally("void baz() { if (1 > 0) {} }",
+   ifStmt(isConstexpr()), false, "-std=c++17"));
 }
 
 TEST(TemplateArgumentCountIs, Matches) {
Index: docs/LibASTMatchersReference.html
===
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html
@@ -2789,15 +2789,19 @@
 
 
 MatcherFunctionDecl>isConstexpr
-Matches constexpr variable and function declarations.
+Matches constexpr variable and function declarations,
+   and if constexpr.
 
 Given:
   constexpr int foo = 42;
   constexpr int bar();
+  void baz() { if constexpr(1 > 0) {} }
 varDecl(isConstexpr())
   matches the declaration of foo.
 functionDecl(isConstexpr())
   matches the declaration of bar.
+ifStmt(isConstexpr())
+  matches the if statement in baz.
 
 
 
@@ -3039,6 +3043,23 @@
 
 
 
+MatcherIfStmt>isConstexpr
+Matches constexpr variable and function declarations,
+   and if constexpr.
+
+Given:
+  constexpr int foo = 42;
+  constexpr int bar();
+  void baz() { if constexpr(1 > 0) {} }
+varDecl(isConstexpr())
+  matches the declaration of foo.
+functionDecl(isConstexpr())
+  matches the declaration of bar.
+ifStmt(isConstexpr())
+  matches the if statement in baz.
+
+
+
 MatcherIntegerLiteral>equalsbool Value
 
 
@@ -3803,15 +3824,19 @@
 
 
 MatcherVarDecl>isConstexpr
-Matches constexpr variable and function declarations.
+Matches constexpr variable and function declarations,
+   and if constexpr.
 
 Given:
   constexpr int foo = 42;
   constexpr int bar();
+  void baz() { if constexpr(1 > 0) {} }
 varDecl(isConstexpr())
   matches the declaration of foo.
 functionDecl(isConstexpr())
   matches the declaration of bar.
+ifStmt(isConstexpr())
+  matches the if statement in baz.
 
 
 
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -3763,20 +3763,25 @@
   return FnTy->isNothrow();
 }
 
-/// \brief Matches constexpr variable and function declarations.
+/// \brief Matches constexpr variable and function declarations,
+///and if constexpr.
 ///
 /// Given:
 /// \code
 ///   constexpr int foo = 42;
 ///   constexpr int bar();
+///   void baz() { if constexpr(1 > 0) {} }
 /// \endcode
 /// varDecl(isConstexpr())
 ///   matches the declaration of foo.
 /// functionDecl(isConstexpr())
 ///   matches the declaration of bar.
+/// ifStmt(isConstexpr())
+///   matches the if statement in baz.
 AST_POLYMORPHIC_MATCHER(isConstexpr,
 AST_POLYMORPHIC_SUPPORTED_TYPES(VarDecl,
-FunctionDecl)) {
+FunctionDecl,
+IfStmt)) {
   return Node.isConstexpr();
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46504: [clang-tidy] Profile is a per-AST (per-TU) data.

2018-05-08 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG with a couple of nits.




Comment at: clang-tidy/ClangTidyDiagnosticConsumer.cpp:181
 std::unique_ptr OptionsProvider)
-: DiagEngine(nullptr), OptionsProvider(std::move(OptionsProvider)),
-  Profile(nullptr) {
+: DiagEngine(nullptr), OptionsProvider(std::move(OptionsProvider)) {
   // Before the first translation unit we can get errors related to 
command-line

lebedev.ri wrote:
> Eugene.Zelenko wrote:
> > Will be good idea to use default member initialization for DiagEngine too.
> Yes, but in the context of the diff that would be a completely unrelated 
> change, i try to avoid those..
I'd better leave the initializer here for consistency with the other fields.



Comment at: clang-tidy/ClangTidyDiagnosticConsumer.h:168
+  /// \brief Control profile collection in clang-tidy.
+  void setCheckProfileData(bool Profile);
+  bool getCheckProfileData() const { return Profile; }

It seems to be `setEnableProfiling()` now.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46504



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


[PATCH] D46188: [clang-tidy] Add a flag to enable debug checkers

2018-05-08 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh requested changes to this revision.
alexfh added a comment.
This revision now requires changes to proceed.

I don't think debug CSA checkers belong to clang-tidy. If one needs to dump 
CFG, they are probably doing quite involved stuff already, so going a step 
further and running `clang -cc1 -analyze` would not be difficult. The 
motivation for exposing alpha checkers (letting users test them and provide 
feedback) doesn't work for debug checkers.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46188



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


[PATCH] D42933: [Sema] Avoid -Wformat warning for NSInteger/NSUInteger 'int' values with %zu/%zi long specifiers

2018-05-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D42933#1090268, @jfb wrote:

> I was just looking at this, and I think @arphaman's patch is pretty much the 
> right approach (with 2 suggested fixes below).
>
> I don't think the code we're currently warning on is broken: a user code has 
> `NSInteger` with `%zd` or `NSUInteger` with `%zu`, and on all platforms which 
> support those types the implementor has guaranteed that `(sizeof(size_t) == 
> sizeof(NSInteger)) && (sizeof(ssize_t) == sizeof(NSUInteger))`.


Yes, but is this guaranteed to be the case or does it happen to be the case? 
I'm worried about the less mainstream uses where you might find ObjC code where 
this does not hold but -Wformat points out a portability concern.

> I agree that, if we're playing C++ pedant and look at the typedefs, then it's 
> undefined behavior and the code is broken.

This is reason alone to diagnose the code, because the optimizer is welcome to 
use that UB to perform transformations the programmer did not expect. However, 
I'm not certain our optimizer is currently paying attention to that UB 
directly, so this may not be an immediate issue (but could be a pitfall for the 
future) but I'm not certain about other optimizers for which portability would 
still be a concern.

> However the implementation provided more guarantees than C++ does through its 
> platform typedefs so pendantry need not apply (or rather: clang should look 
> no further than the typedef, and trust the platform in this particular case).
> 
> We of course should still warn on sign mismatch.
> 
> I don't think this should even be a warning with pedantic on: there's no 
> portability issue at all because all OSes and architectures where this could 
> ever fire are guaranteed to do the right thing.

Can you point me to this guarantee, as I was unable to find one (but that 
doesn't mean it doesn't exist)?

> Suggested fixes:
> 
> 1. Don't compare `CastTyName` directly, instead recurse as 
> `shouldNotPrintDirectly` does so `typedef` nesting is also handled.
> 2. Add a test that sign mismatched is still diagnosed.
> 
>   If you all agree I'll post an updated patch.


Repository:
  rC Clang

https://reviews.llvm.org/D42933



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


[PATCH] D46188: [clang-tidy] Add a flag to enable debug checkers

2018-05-08 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added subscribers: george.karpenkov, NoQ, dcoughlin.
lebedev.ri added a comment.

In https://reviews.llvm.org/D46188#1091221, @alexfh wrote:

> I don't think debug CSA checkers belong to clang-tidy. If one needs to dump 
> CFG, they are probably doing quite involved stuff already, so going a step 
> further and running `clang -cc1 -analyze` would not be difficult. The 
> motivation for exposing alpha checkers (letting users test them and provide 
> feedback) doesn't work for debug checkers.


There is word play here.
They are debug CSA checkers. But not all of them are debugging the CSA. Many of 
them are just utility checkers that could be just as easily a clang-tidy 
debug/utility checkers:

  $ scan-build -h | grep "   debug."
 debug.AnalysisOrder Print callbacks that are called during 
analysis in order   <- for CSA debugging
 debug.ConfigDumper  Dump config table  
<- for CSA debugging
 debug.DumpCFG   Display Control-Flow Graphs
<- 
 debug.DumpCallGraph Display Call Graph 
<- 
 debug.DumpCalls Print calls as they are traversed by the 
engine<- for CSA debugging
 debug.DumpDominatorsPrint the dominance tree for a given CFG   
<- 
 debug.DumpLiveVars  Print results of live variable analysis
<- 
 debug.DumpTraversal Print branch conditions as they are 
traversed by the engine<- for CSA debugging
 debug.ExprInspectionCheck the analyzer's understanding of 
expressions  <- for CSA debugging
 debug.Stats Emit warnings with analyzer statistics 
<- for CSA debugging
 debug.TaintTest Mark tainted symbols as such.  
<- for CSA debugging
 debug.ViewCFG   View Control-Flow Graphs using GraphViz
<- 
 debug.ViewCallGraph View Call Graph using GraphViz 
<- 
 debug.ViewExplodedGraph View Exploded Graphs using GraphViz
<- 

(CC people from https://reviews.llvm.org/D46187: @dcoughlin @george.karpenkov 
@NoQ)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46188



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


[PATCH] D46504: [clang-tidy] Profile is a per-AST (per-TU) data.

2018-05-08 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In https://reviews.llvm.org/D46504#1091210, @alexfh wrote:

> LG with a couple of nits.


Thank you for the review, faster than ever :)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46504



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


[PATCH] D46115: [ASTImporter] properly import SrcLoc of Attr

2018-05-08 Thread Aleksei Sidorin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL331762: [ASTImporter] Properly import SourceLocations of 
Attrs (authored by a.sidorin, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46115?vs=145660&id=145675#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46115

Files:
  cfe/trunk/include/clang/AST/ASTImporter.h
  cfe/trunk/lib/AST/ASTImporter.cpp
  cfe/trunk/test/Import/attr/Inputs/S.cpp
  cfe/trunk/test/Import/attr/test.cpp

Index: cfe/trunk/lib/AST/ASTImporter.cpp
===
--- cfe/trunk/lib/AST/ASTImporter.cpp
+++ cfe/trunk/lib/AST/ASTImporter.cpp
@@ -2687,8 +2687,8 @@
   Importer.getToContext(), DC, Loc, Name.getAsIdentifierInfo(), T,
   {NamedChain, D->getChainingSize()});
 
-  for (const auto *Attr : D->attrs())
-ToIndirectField->addAttr(Attr->clone(Importer.getToContext()));
+  for (const auto *A : D->attrs())
+ToIndirectField->addAttr(Importer.Import(A));
 
   ToIndirectField->setAccess(D->getAccess());
   ToIndirectField->setLexicalDeclContext(LexicalDC);
@@ -4766,15 +4766,8 @@
   SourceLocation ToAttrLoc = Importer.Import(S->getAttrLoc());
   ArrayRef FromAttrs(S->getAttrs());
   SmallVector ToAttrs(FromAttrs.size());
-  ASTContext &_ToContext = Importer.getToContext();
-  std::transform(FromAttrs.begin(), FromAttrs.end(), ToAttrs.begin(),
-[&_ToContext](const Attr *A) -> const Attr * {
-  return A->clone(_ToContext);
-});
-  for (const auto *ToA : ToAttrs) {
-if (!ToA)
-  return nullptr;
-  }
+  if (ImportContainerChecked(FromAttrs, ToAttrs))
+return nullptr;
   Stmt *ToSubStmt = Importer.Import(S->getSubStmt());
   if (!ToSubStmt && S->getSubStmt())
 return nullptr;
@@ -6657,6 +6650,12 @@
Import(FromTSI->getTypeLoc().getLocStart()));
 }
 
+Attr *ASTImporter::Import(const Attr *FromAttr) {
+  Attr *ToAttr = FromAttr->clone(ToContext);
+  ToAttr->setRange(Import(FromAttr->getRange()));
+  return ToAttr;
+}
+
 Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) {
   llvm::DenseMap::iterator Pos = ImportedDecls.find(FromD);
   if (Pos != ImportedDecls.end()) {
@@ -7290,8 +7289,8 @@
 
 Decl *ASTImporter::Imported(Decl *From, Decl *To) {
   if (From->hasAttrs()) {
-for (auto *FromAttr : From->getAttrs())
-  To->addAttr(FromAttr->clone(To->getASTContext()));
+for (const auto *FromAttr : From->getAttrs())
+  To->addAttr(Import(FromAttr));
   }
   if (From->isUsed()) {
 To->setIsUsed();
Index: cfe/trunk/include/clang/AST/ASTImporter.h
===
--- cfe/trunk/include/clang/AST/ASTImporter.h
+++ cfe/trunk/include/clang/AST/ASTImporter.h
@@ -41,6 +41,7 @@
 class Stmt;
 class TagDecl;
 class TypeSourceInfo;
+class Attr;
 
   /// \brief Imports selected nodes from one AST context into another context,
   /// merging AST nodes where appropriate.
@@ -126,6 +127,12 @@
 /// context, or NULL if an error occurred.
 TypeSourceInfo *Import(TypeSourceInfo *FromTSI);
 
+/// \brief Import the given attribute from the "from" context into the
+/// "to" context.
+///
+/// \returns the equivalent attribute in the "to" context.
+Attr *Import(const Attr *FromAttr);
+
 /// \brief Import the given declaration from the "from" context into the 
 /// "to" context.
 ///
Index: cfe/trunk/test/Import/attr/Inputs/S.cpp
===
--- cfe/trunk/test/Import/attr/Inputs/S.cpp
+++ cfe/trunk/test/Import/attr/Inputs/S.cpp
@@ -0,0 +1,13 @@
+extern void f() __attribute__((const));
+
+struct S {
+  struct {
+int a __attribute__((packed));
+  };
+};
+
+void stmt() {
+#pragma unroll
+  for (;;)
+;
+}
Index: cfe/trunk/test/Import/attr/test.cpp
===
--- cfe/trunk/test/Import/attr/test.cpp
+++ cfe/trunk/test/Import/attr/test.cpp
@@ -0,0 +1,26 @@
+// RUN: clang-import-test -dump-ast -import %S/Inputs/S.cpp -expression %s | FileCheck %s
+// CHECK: FunctionDecl
+// CHECK-SAME: S.cpp:1:1, col:13
+// CHECK-NEXT: ConstAttr
+// CHECK-SAME: col:32
+
+// CHECK: IndirectFieldDecl
+// CHECK-NEXT: Field
+// CHECK-NEXT: Field
+// CHECK-NEXT: PackedAttr
+// CHECK-SAME: col:26
+
+// CHECK: AttributedStmt
+// CHECK-NEXT: LoopHintAttr
+// CHECK-SAME: line:10:9
+
+extern void f() __attribute__((const));
+
+struct S;
+
+void stmt();
+
+void expr() {
+  f();
+  struct S s;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r331762 - [ASTImporter] Properly import SourceLocations of Attrs

2018-05-08 Thread Aleksei Sidorin via cfe-commits
Author: a.sidorin
Date: Tue May  8 05:45:21 2018
New Revision: 331762

URL: http://llvm.org/viewvc/llvm-project?rev=331762&view=rev
Log:
[ASTImporter] Properly import SourceLocations of Attrs

Patch by Rafael Stahl!

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


Added:
cfe/trunk/test/Import/attr/
cfe/trunk/test/Import/attr/Inputs/
cfe/trunk/test/Import/attr/Inputs/S.cpp
cfe/trunk/test/Import/attr/test.cpp
Modified:
cfe/trunk/include/clang/AST/ASTImporter.h
cfe/trunk/lib/AST/ASTImporter.cpp

Modified: cfe/trunk/include/clang/AST/ASTImporter.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTImporter.h?rev=331762&r1=331761&r2=331762&view=diff
==
--- cfe/trunk/include/clang/AST/ASTImporter.h (original)
+++ cfe/trunk/include/clang/AST/ASTImporter.h Tue May  8 05:45:21 2018
@@ -41,6 +41,7 @@ class NamedDecl;
 class Stmt;
 class TagDecl;
 class TypeSourceInfo;
+class Attr;
 
   /// \brief Imports selected nodes from one AST context into another context,
   /// merging AST nodes where appropriate.
@@ -126,6 +127,12 @@ class TypeSourceInfo;
 /// context, or NULL if an error occurred.
 TypeSourceInfo *Import(TypeSourceInfo *FromTSI);
 
+/// \brief Import the given attribute from the "from" context into the
+/// "to" context.
+///
+/// \returns the equivalent attribute in the "to" context.
+Attr *Import(const Attr *FromAttr);
+
 /// \brief Import the given declaration from the "from" context into the 
 /// "to" context.
 ///

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=331762&r1=331761&r2=331762&view=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Tue May  8 05:45:21 2018
@@ -2687,8 +2687,8 @@ Decl *ASTNodeImporter::VisitIndirectFiel
   Importer.getToContext(), DC, Loc, Name.getAsIdentifierInfo(), T,
   {NamedChain, D->getChainingSize()});
 
-  for (const auto *Attr : D->attrs())
-ToIndirectField->addAttr(Attr->clone(Importer.getToContext()));
+  for (const auto *A : D->attrs())
+ToIndirectField->addAttr(Importer.Import(A));
 
   ToIndirectField->setAccess(D->getAccess());
   ToIndirectField->setLexicalDeclContext(LexicalDC);
@@ -4766,15 +4766,8 @@ Stmt *ASTNodeImporter::VisitAttributedSt
   SourceLocation ToAttrLoc = Importer.Import(S->getAttrLoc());
   ArrayRef FromAttrs(S->getAttrs());
   SmallVector ToAttrs(FromAttrs.size());
-  ASTContext &_ToContext = Importer.getToContext();
-  std::transform(FromAttrs.begin(), FromAttrs.end(), ToAttrs.begin(),
-[&_ToContext](const Attr *A) -> const Attr * {
-  return A->clone(_ToContext);
-});
-  for (const auto *ToA : ToAttrs) {
-if (!ToA)
-  return nullptr;
-  }
+  if (ImportContainerChecked(FromAttrs, ToAttrs))
+return nullptr;
   Stmt *ToSubStmt = Importer.Import(S->getSubStmt());
   if (!ToSubStmt && S->getSubStmt())
 return nullptr;
@@ -6657,6 +6650,12 @@ TypeSourceInfo *ASTImporter::Import(Type
Import(FromTSI->getTypeLoc().getLocStart()));
 }
 
+Attr *ASTImporter::Import(const Attr *FromAttr) {
+  Attr *ToAttr = FromAttr->clone(ToContext);
+  ToAttr->setRange(Import(FromAttr->getRange()));
+  return ToAttr;
+}
+
 Decl *ASTImporter::GetAlreadyImportedOrNull(Decl *FromD) {
   llvm::DenseMap::iterator Pos = ImportedDecls.find(FromD);
   if (Pos != ImportedDecls.end()) {
@@ -7290,8 +7289,8 @@ void ASTImporter::CompleteDecl (Decl *D)
 
 Decl *ASTImporter::Imported(Decl *From, Decl *To) {
   if (From->hasAttrs()) {
-for (auto *FromAttr : From->getAttrs())
-  To->addAttr(FromAttr->clone(To->getASTContext()));
+for (const auto *FromAttr : From->getAttrs())
+  To->addAttr(Import(FromAttr));
   }
   if (From->isUsed()) {
 To->setIsUsed();

Added: cfe/trunk/test/Import/attr/Inputs/S.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/attr/Inputs/S.cpp?rev=331762&view=auto
==
--- cfe/trunk/test/Import/attr/Inputs/S.cpp (added)
+++ cfe/trunk/test/Import/attr/Inputs/S.cpp Tue May  8 05:45:21 2018
@@ -0,0 +1,13 @@
+extern void f() __attribute__((const));
+
+struct S {
+  struct {
+int a __attribute__((packed));
+  };
+};
+
+void stmt() {
+#pragma unroll
+  for (;;)
+;
+}

Added: cfe/trunk/test/Import/attr/test.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/attr/test.cpp?rev=331762&view=auto
==
--- cfe/trunk/test/Import/attr/test.cpp (added)
+++ cfe/trunk/test/Import/attr/test.cpp Tue May  8 05:45:21 2018
@@ -0,0 +1,26 @@
+// RUN: clang-import-test -dump-ast -import %S/Inputs/S.cpp -expression %s | 
FileCheck %s
+// CHECK: FunctionDecl
+// CHECK

[PATCH] D46519: [clang-format] Respect BreakBeforeClosingBrace while calculating length

2018-05-08 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 145677.
krasimir added a comment.

- Added other parens detection


Repository:
  rC Clang

https://reviews.llvm.org/D46519

Files:
  lib/Format/ContinuationIndenter.cpp
  lib/Format/ContinuationIndenter.h
  lib/Format/UnwrappedLineFormatter.cpp
  unittests/Format/FormatTestProto.cpp
  unittests/Format/FormatTestRawStrings.cpp
  unittests/Format/FormatTestTextProto.cpp

Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -469,6 +469,7 @@
"ccc: <\n"
"  operator: 1\n"
"  operator: 2\n"
+   "  operator: 3\n"
"  operator { key: value }\n"
">\n"
"  >\n"
@@ -495,5 +496,16 @@
"}", Style);
 }
 
+TEST_F(FormatTestTextProto, BreaksAfterBraceFollowedByClosingBraceOnNextLine) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+  Style.ColumnLimit = 60;
+  verifyFormat("keys: [\n"
+   "  data: { item: '' }\n"
+   "]");
+  verifyFormat("keys: <\n"
+   "  data: { item: '' }\n"
+   ">");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: unittests/Format/FormatTestRawStrings.cpp
===
--- unittests/Format/FormatTestRawStrings.cpp
+++ unittests/Format/FormatTestRawStrings.cpp
@@ -822,6 +822,41 @@
 )test", Style));
 }
 
+TEST_F(FormatTestRawStrings, KeepsRBraceFolloedByMoreLBracesOnSameLine) {
+  FormatStyle Style = getRawStringPbStyleWithColumns(80);
+
+  expect_eq(
+R"test(
+int f() {
+  if (1) {
+T s = PARSE_TEXT_PROTO(R"pb(
+  t {
+p {
+  [cc.pp.] { field_1: "123_1" }
+  [cc.pp.] { field_2: "123_2" }
+}
+  }
+)pb");
+  }
+}
+)test",
+format(
+R"test(
+int f() {
+  if (1) {
+   T s = PARSE_TEXT_PROTO(R"pb(
+   t {
+   p {
+   [cc.pp.] { field_1: "123_1" }
+   [cc.pp.] { field_2: "123_2" }}}
+   )pb");
+  }
+}
+)test",
+Style));
+}
+
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -486,6 +486,7 @@
"ccc: <\n"
"  operator: 1\n"
"  operator: 2\n"
+   "  operator: 3\n"
"  operator { key: value }\n"
">\n"
"  >\n"
Index: lib/Format/UnwrappedLineFormatter.cpp
===
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -659,8 +659,8 @@
 static void printLineState(const LineState &State) {
   llvm::dbgs() << "State: ";
   for (const ParenState &P : State.Stack) {
-llvm::dbgs() << P.Indent << "|" << P.LastSpace << "|" << P.NestedBlockIndent
- << " ";
+llvm::dbgs() << (P.Tok ? P.Tok->TokenText : "F") << "|" << P.Indent << "|"
+ << P.LastSpace << "|" << P.NestedBlockIndent << " ";
   }
   llvm::dbgs() << State.NextToken->TokenText << "\n";
 }
Index: lib/Format/ContinuationIndenter.h
===
--- lib/Format/ContinuationIndenter.h
+++ lib/Format/ContinuationIndenter.h
@@ -200,16 +200,23 @@
 };
 
 struct ParenState {
-  ParenState(unsigned Indent, unsigned LastSpace, bool AvoidBinPacking,
- bool NoLineBreak)
-  : Indent(Indent), LastSpace(LastSpace), NestedBlockIndent(Indent),
-BreakBeforeClosingBrace(false), AvoidBinPacking(AvoidBinPacking),
-BreakBeforeParameter(false), NoLineBreak(NoLineBreak),
-NoLineBreakInOperand(false), LastOperatorWrapped(true),
-ContainsLineBreak(false), ContainsUnwrappedBuilder(false),
-AlignColons(true), ObjCSelectorNameFound(false),
-HasMultipleNestedBlocks(false), NestedBlockInlined(false),
-IsInsideObjCArrayLiteral(false) {}
+  ParenState(const FormatToken *Tok, unsigned Indent, unsigned LastSpace,
+ bool AvoidBinPacking, bool NoLineBreak)
+  : Tok(Tok), Indent(Indent), LastSpace(LastSpace),
+NestedBlockIndent(Indent), BreakBeforeClosingBrace(false),
+AvoidBinPacking(AvoidBinPacking), BreakBeforeParameter(false),
+   

[PATCH] D46519: [clang-format] Respect BreakBeforeClosingBrace while calculating length

2018-05-08 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir marked an inline comment as done.
krasimir added inline comments.



Comment at: lib/Format/ContinuationIndenter.cpp:93
+  break;
+if (End->Next->is(tok::r_brace)) {
+  const ParenState *State = FindParenState(End->Next->MatchingParen);

djasper wrote:
> I r_brace enough? Do we have something similar for TT_ArrayInitializer? I'd 
> look at usages of BreakBeforeClosingBrace to determine.
Thanks! Based on:
https://github.com/llvm-mirror/clang/blob/bf81db4ab70b45a77fba0d9f7d43190f1ad91bb9/lib/Format/ContinuationIndenter.cpp#L804
I've added also cases for array `[`-s and text proto `<`-s and updated comments.


Repository:
  rC Clang

https://reviews.llvm.org/D46519



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


[clang-tools-extra] r331763 - [clang-tidy] Profile is a per-AST (per-TU) data.

2018-05-08 Thread Roman Lebedev via cfe-commits
Author: lebedevri
Date: Tue May  8 06:14:21 2018
New Revision: 331763

URL: http://llvm.org/viewvc/llvm-project?rev=331763&view=rev
Log:
[clang-tidy] Profile is a per-AST (per-TU) data.

Summary:
As discussed in D45931, currently, profiling output of clang-tidy is somewhat 
not great.
It outputs one profile at the end of the execution, and that profile contains 
the data
from the last TU that was processed. So if the tool run on multiple TU's, the 
data is
not accumulated, it is simply discarded.

It would be nice to improve this.

This differential is the first step - make this profiling info per-TU,
and output it after the tool has finished processing each TU.
In particular, when `ClangTidyASTConsumer` destructor runs.

Next step will be to add a CSV (JSON?) printer to store said profiles under 
user-specified directory prefix.

Reviewers: alexfh, sbenza

Reviewed By: alexfh

Subscribers: Eugene.Zelenko, mgorny, xazax.hun, mgrang, klimek, cfe-commits

Tags: #clang-tools-extra

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

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

clang-tools-extra/trunk/test/clang-tidy/clang-tidy-enable-check-profile-one-tu.cpp

clang-tools-extra/trunk/test/clang-tidy/clang-tidy-enable-check-profile-two-tu.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidy.h
clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h
clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp

Modified: clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/CMakeLists.txt?rev=331763&r1=331762&r2=331763&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/CMakeLists.txt Tue May  8 06:14:21 2018
@@ -7,6 +7,7 @@ add_clang_library(clangTidy
   ClangTidyModule.cpp
   ClangTidyDiagnosticConsumer.cpp
   ClangTidyOptions.cpp
+  ClangTidyProfiling.cpp
 
   DEPENDS
   ClangSACheckers

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=331763&r1=331762&r2=331763&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Tue May  8 06:14:21 2018
@@ -18,6 +18,7 @@
 #include "ClangTidy.h"
 #include "ClangTidyDiagnosticConsumer.h"
 #include "ClangTidyModuleRegistry.h"
+#include "ClangTidyProfiling.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
@@ -267,12 +268,17 @@ private:
 class ClangTidyASTConsumer : public MultiplexConsumer {
 public:
   ClangTidyASTConsumer(std::vector> Consumers,
+   std::unique_ptr Profiling,
std::unique_ptr Finder,
std::vector> Checks)
-  : MultiplexConsumer(std::move(Consumers)), Finder(std::move(Finder)),
+  : MultiplexConsumer(std::move(Consumers)),
+Profiling(std::move(Profiling)), Finder(std::move(Finder)),
 Checks(std::move(Checks)) {}
 
 private:
+  // Destructor order matters! Profiling must be destructed last.
+  // Or at least after Finder.
+  std::unique_ptr Profiling;
   std::unique_ptr Finder;
   std::vector> Checks;
 };
@@ -353,8 +359,12 @@ ClangTidyASTConsumerFactory::CreateASTCo
   CheckFactories->createChecks(&Context, Checks);
 
   ast_matchers::MatchFinder::MatchFinderOptions FinderOptions;
-  if (auto *P = Context.getCheckProfileData())
-FinderOptions.CheckProfiling.emplace(P->Records);
+
+  std::unique_ptr Profiling;
+  if (Context.getEnableProfiling()) {
+Profiling = llvm::make_unique();
+FinderOptions.CheckProfiling.emplace(Profiling->Records);
+  }
 
   std::unique_ptr Finder(
   new ast_matchers::MatchFinder(std::move(FinderOptions)));
@@ -383,7 +393,8 @@ ClangTidyASTConsumerFactory::CreateASTCo
 Consumers.push_back(std::move(AnalysisConsumer));
   }
   return llvm::make_unique(
-  std::move(Consumers), std::move(Finder), std::move(Checks));
+  std::move(Consumers), std::move(Profiling), std::move(Finder),
+  std::move(Checks));
 }
 
 std::vector ClangTidyASTConsumerFactory::getCheckNames() {
@@ -472,7 +483,7 @@ void runClangTidy(clang::tidy::ClangTidy
   const CompilationDatabase &Compilations,
   ArrayRef InputFiles,
   llvm::IntrusiveRefCntPtr BaseFS,
-  ProfileData *Profile) {
+  bool EnableCheckProfile) {
   ClangTool Tool(Compilations, InputFiles,
   

[PATCH] D46504: [clang-tidy] Profile is a per-AST (per-TU) data.

2018-05-08 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL331763: [clang-tidy] Profile is a per-AST (per-TU) data. 
(authored by lebedevri, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46504?vs=145402&id=145678#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46504

Files:
  clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
  clang-tools-extra/trunk/clang-tidy/ClangTidy.h
  clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/trunk/clang-tidy/ClangTidyProfiling.cpp
  clang-tools-extra/trunk/clang-tidy/ClangTidyProfiling.h
  clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
  
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-enable-check-profile-one-tu.cpp
  
clang-tools-extra/trunk/test/clang-tidy/clang-tidy-enable-check-profile-two-tu.cpp

Index: clang-tools-extra/trunk/clang-tidy/ClangTidyProfiling.cpp
===
--- clang-tools-extra/trunk/clang-tidy/ClangTidyProfiling.cpp
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyProfiling.cpp
@@ -0,0 +1,65 @@
+//===--- ClangTidyProfiling.cpp - clang-tidy *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ClangTidyProfiling.h"
+#include "llvm/ADT/STLExtras.h"
+
+#define DEBUG_TYPE "clang-tidy-profiling"
+
+namespace clang {
+namespace tidy {
+
+void ClangTidyProfiling::preprocess() {
+  // Convert from a insertion-friendly map to sort-friendly vector.
+  Timers.clear();
+  Timers.reserve(Records.size());
+  for (const auto &P : Records) {
+Timers.emplace_back(P.getValue(), P.getKey());
+Total += P.getValue();
+  }
+  assert(Timers.size() == Records.size() && "Size mismatch after processing");
+
+  // We want the measurements to be sorted by decreasing time spent.
+  llvm::sort(Timers.begin(), Timers.end());
+}
+
+void ClangTidyProfiling::printProfileData(llvm::raw_ostream &OS) const {
+  std::string Line = "===" + std::string(73, '-') + "===\n";
+  OS << Line;
+
+  if (Total.getUserTime())
+OS << "   ---User Time---";
+  if (Total.getSystemTime())
+OS << "   --System Time--";
+  if (Total.getProcessTime())
+OS << "   --User+System--";
+  OS << "   ---Wall Time---";
+  if (Total.getMemUsed())
+OS << "  ---Mem---";
+  OS << "  --- Name ---\n";
+
+  // Loop through all of the timing data, printing it out.
+  for (auto I = Timers.rbegin(), E = Timers.rend(); I != E; ++I) {
+I->first.print(Total, OS);
+OS << I->second << '\n';
+  }
+
+  Total.print(Total, OS);
+  OS << "Total\n";
+  OS << Line << "\n";
+  OS.flush();
+}
+
+ClangTidyProfiling::~ClangTidyProfiling() {
+  preprocess();
+  printProfileData(llvm::errs());
+}
+
+} // namespace tidy
+} // namespace clang
Index: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
===
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
@@ -18,6 +18,7 @@
 #include "ClangTidy.h"
 #include "ClangTidyDiagnosticConsumer.h"
 #include "ClangTidyModuleRegistry.h"
+#include "ClangTidyProfiling.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
@@ -267,12 +268,17 @@
 class ClangTidyASTConsumer : public MultiplexConsumer {
 public:
   ClangTidyASTConsumer(std::vector> Consumers,
+   std::unique_ptr Profiling,
std::unique_ptr Finder,
std::vector> Checks)
-  : MultiplexConsumer(std::move(Consumers)), Finder(std::move(Finder)),
+  : MultiplexConsumer(std::move(Consumers)),
+Profiling(std::move(Profiling)), Finder(std::move(Finder)),
 Checks(std::move(Checks)) {}
 
 private:
+  // Destructor order matters! Profiling must be destructed last.
+  // Or at least after Finder.
+  std::unique_ptr Profiling;
   std::unique_ptr Finder;
   std::vector> Checks;
 };
@@ -353,8 +359,12 @@
   CheckFactories->createChecks(&Context, Checks);
 
   ast_matchers::MatchFinder::MatchFinderOptions FinderOptions;
-  if (auto *P = Context.getCheckProfileData())
-FinderOptions.CheckProfiling.emplace(P->Records);
+
+  std::unique_ptr Profiling;
+  if (Context.getEnableProfiling()) {
+Profiling = llvm::make_unique();
+FinderOptions.CheckProfiling.emplace(Profiling->Records);
+  }
 
   std::unique_ptr Finder(
   new ast_matchers::MatchFinder(std::move(FinderOptions)));
@@ -383,7 +393,8 @@
 Consumers.push_back(std::move(AnalysisConsumer));
   }
   return llvm::make_unique(
-  std::m

[PATCH] D46541: [CodeGen] Improve diagnostics related to target attributes

2018-05-08 Thread Gabor Buella via Phabricator via cfe-commits
GBuella updated this revision to Diff 145680.

https://reviews.llvm.org/D46541

Files:
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  test/CodeGen/target-features-error-2.c
  test/CodeGen/target-features-error.c

Index: test/CodeGen/target-features-error.c
===
--- test/CodeGen/target-features-error.c
+++ test/CodeGen/target-features-error.c
@@ -3,6 +3,5 @@
   return a + 4;
 }
 int bar() {
-  return foo(4); // expected-error {{always_inline function 'foo' requires target feature 'sse4.2', but would be inlined into function 'bar' that is compiled without support for 'sse4.2'}}
+  return foo(4); // expected-error {{always_inline function 'foo' requires target feature 'avx', but would be inlined into function 'bar' that is compiled without support for 'avx'}}
 }
-
Index: test/CodeGen/target-features-error-2.c
===
--- test/CodeGen/target-features-error-2.c
+++ test/CodeGen/target-features-error-2.c
@@ -3,13 +3,14 @@
 // RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_2
 // RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_3
 // RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_4
+// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX512f
 
 #define __MM_MALLOC_H
 #include 
 
 #if NEED_SSE42
 int baz(__m256i a) {
-  return _mm256_extract_epi32(a, 3); // expected-error {{always_inline function '_mm256_extract_epi32' requires target feature 'sse4.2', but would be inlined into function 'baz' that is compiled without support for 'sse4.2'}}
+  return _mm256_extract_epi32(a, 3); // expected-error {{always_inline function '_mm256_extract_epi32' requires target feature 'avx', but would be inlined into function 'baz' that is compiled without support for 'avx'}}
 }
 #endif
 
@@ -36,3 +37,9 @@
   return _mm_cmp_sd(a, b, 0); // expected-error {{'__builtin_ia32_cmpsd' needs target feature avx}}
 }
 #endif
+
+#if NEED_AVX512f
+unsigned short need_avx512f(unsigned short a, unsigned short b) {
+  return __builtin_ia32_korhi(a, b); // expected-error {{'__builtin_ia32_korhi' needs target feature avx512f}}
+}
+#endif
Index: lib/CodeGen/CodeGenModule.h
===
--- lib/CodeGen/CodeGenModule.h
+++ lib/CodeGen/CodeGenModule.h
@@ -1082,6 +1082,8 @@
   /// It's up to you to ensure that this is safe.
   void AddDefaultFnAttrs(llvm::Function &F);
 
+  TargetAttr::ParsedTargetAttr filterFunctionTargetAttrs(const TargetAttr *TD);
+
   // Fills in the supplied string map with the set of target features for the
   // passed in function.
   void getFunctionFeatureMap(llvm::StringMap &FeatureMap,
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -4995,22 +4995,28 @@
   }
 }
 
+TargetAttr::ParsedTargetAttr CodeGenModule::filterFunctionTargetAttrs(const TargetAttr *TD) {
+  assert(TD != nullptr);
+  TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse();
+
+  ParsedAttr.Features.erase(
+  llvm::remove_if(ParsedAttr.Features,
+  [&](const std::string &Feat) {
+return !Target.isValidFeatureName(
+StringRef{Feat}.substr(1));
+  }),
+  ParsedAttr.Features.end());
+  return ParsedAttr;
+}
+
+
 // Fills in the supplied string map with the set of target features for the
 // passed in function.
 void CodeGenModule::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
   const FunctionDecl *FD) {
   StringRef TargetCPU = Target.getTargetOpts().CPU;
   if (const auto *TD = FD->getAttr()) {
-// If we have a TargetAttr build up the feature map based on that.
-TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse();
-
-ParsedAttr.Features.erase(
-llvm::remove_if(ParsedAttr.Features,
-[&](const std::string &Feat) {
-  return !Target.isValidFeatureName(
-  StringRef{Feat}.substr(1));
-}),
-ParsedAttr.Features.end());
+TargetAttr::ParsedTargetAttr ParsedAttr = filterFunctionTargetAttrs(TD);
 
 // Make a copy of the features as passed on the command line into the
 // beginning of the additional features from the function to override.
Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -2330,13 +2330,23 @@
 
   } else if (TargetDecl->hasAttr()) {
 // Get the required features for the callee.
+
+const TargetAttr *TD = TargetDecl->getAttr();
+TargetAttr::ParsedTargetAttr ParsedAttr = CGM.filterFunctionTargetAttrs

[PATCH] D46540: [X86] ptwrite intrinsic

2018-05-08 Thread Gabor Buella via Phabricator via cfe-commits
GBuella updated this revision to Diff 145681.
GBuella added a comment.

Rebased.


https://reviews.llvm.org/D46540

Files:
  include/clang/Basic/BuiltinsX86.def
  include/clang/Basic/BuiltinsX86_64.def
  include/clang/Driver/Options.td
  lib/Basic/Targets/X86.cpp
  lib/Basic/Targets/X86.h
  lib/Headers/CMakeLists.txt
  lib/Headers/cpuid.h
  lib/Headers/module.modulemap
  lib/Headers/ptwriteintrin.h
  lib/Headers/x86intrin.h
  test/CodeGen/ptwrite.c
  test/Driver/x86-target-features.c
  test/Preprocessor/predefined-arch-macros.c

Index: test/Preprocessor/predefined-arch-macros.c
===
--- test/Preprocessor/predefined-arch-macros.c
+++ test/Preprocessor/predefined-arch-macros.c
@@ -1402,6 +1402,7 @@
 // CHECK_GLMP_M32: #define __PCLMUL__ 1
 // CHECK_GLMP_M32: #define __POPCNT__ 1
 // CHECK_GLMP_M32: #define __PRFCHW__ 1
+// CHECK_GLMP_M32: #define __PTWRITE__ 1
 // CHECK_GLMP_M32: #define __RDPID__ 1
 // CHECK_GLMP_M32: #define __RDRND__ 1
 // CHECK_GLMP_M32: #define __RDSEED__ 1
@@ -1437,6 +1438,7 @@
 // CHECK_GLMP_M64: #define __PCLMUL__ 1
 // CHECK_GLMP_M64: #define __POPCNT__ 1
 // CHECK_GLMP_M64: #define __PRFCHW__ 1
+// CHECK_GLMP_M64: #define __PTWRITE__ 1
 // CHECK_GLMP_M64: #define __RDPID__ 1
 // CHECK_GLMP_M64: #define __RDRND__ 1
 // CHECK_GLMP_M64: #define __RDSEED__ 1
@@ -1474,6 +1476,7 @@
 // CHECK_TRM_M32: #define __PCLMUL__ 1
 // CHECK_TRM_M32: #define __POPCNT__ 1
 // CHECK_TRM_M32: #define __PRFCHW__ 1
+// CHECK_TRM_M32: #define __PTWRITE__ 1
 // CHECK_TRM_M32: #define __RDPID__ 1
 // CHECK_TRM_M32: #define __RDRND__ 1
 // CHECK_TRM_M32: #define __RDSEED__ 1
@@ -1514,6 +1517,7 @@
 // CHECK_TRM_M64: #define __PCLMUL__ 1
 // CHECK_TRM_M64: #define __POPCNT__ 1
 // CHECK_TRM_M64: #define __PRFCHW__ 1
+// CHECK_TRM_M64: #define __PTWRITE__ 1
 // CHECK_TRM_M64: #define __RDPID__ 1
 // CHECK_TRM_M64: #define __RDRND__ 1
 // CHECK_TRM_M64: #define __RDSEED__ 1
Index: test/Driver/x86-target-features.c
===
--- test/Driver/x86-target-features.c
+++ test/Driver/x86-target-features.c
@@ -164,3 +164,8 @@
 // RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-pconfig %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-PCONFIG %s
 // PCONFIG: "-target-feature" "+pconfig"
 // NO-PCONFIG: "-target-feature" "-pconfig"
+
+// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mptwrite %s -### -o %t.o 2>&1 | FileCheck -check-prefix=PTWRITE %s
+// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-ptwrite %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-PTWRITE %s
+// PTWRITE: "-target-feature" "+ptwrite"
+// NO-PTWRITE: "-target-feature" "-ptwrite"
Index: test/CodeGen/ptwrite.c
===
--- /dev/null
+++ test/CodeGen/ptwrite.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 %s -ffreestanding -triple=x86_64-unknown-unknown -target-feature +ptwrite -emit-llvm -o - -Wall -Werror -pedantic | FileCheck %s --check-prefix=X86 --check-prefix=X86_64
+// RUN: %clang_cc1 %s -ffreestanding -triple=i386-unknown-unknown -target-feature +ptwrite -emit-llvm -o - -Wall -Werror -pedantic | FileCheck %s --check-prefix=X86
+
+#include 
+
+#include 
+
+void test_ptwrite32(uint32_t value) {
+  //X86-LABEL: @test_ptwrite32
+  //X86: call void @llvm.x86.ptwrite32(i32 %{{.*}})
+  _ptwrite32(value);
+}
+
+#ifdef __x86_64__
+
+void test_ptwrite64(uint64_t value) {
+  //X86_64-LABEL: @test_ptwrite64
+  //X86_64: call void @llvm.x86.ptwrite64(i64 %{{.*}})
+  _ptwrite64(value);
+}
+
+#endif /* __x86_64__ */
Index: lib/Headers/x86intrin.h
===
--- lib/Headers/x86intrin.h
+++ lib/Headers/x86intrin.h
@@ -113,4 +113,8 @@
 #include 
 #endif
 
+#if !defined(_MSC_VER) || __has_feature(modules) || defined(__PTWRITE__)
+#include 
+#endif
+
 #endif /* __X86INTRIN_H */
Index: lib/Headers/ptwriteintrin.h
===
--- /dev/null
+++ lib/Headers/ptwriteintrin.h
@@ -0,0 +1,51 @@
+/*=== ptwriteintrin.h - PTWRITE intrinsic ===
+ *
+ * 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 N

[PATCH] D46000: [AST] Added a helper to extract a user-friendly text of a comment.

2018-05-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 145683.
ilya-biryukov marked 3 inline comments as done.
ilya-biryukov added a comment.
Herald added a subscriber: mgorny.

- Move unit tests from clangd code to AST tests
- Assert locations are valid
- Address review other comments


Repository:
  rC Clang

https://reviews.llvm.org/D46000

Files:
  include/clang/AST/CommentLexer.h
  include/clang/AST/RawCommentList.h
  lib/AST/CommentLexer.cpp
  lib/AST/RawCommentList.cpp
  unittests/AST/CMakeLists.txt
  unittests/AST/CommentTextTest.cpp

Index: unittests/AST/CommentTextTest.cpp
===
--- /dev/null
+++ unittests/AST/CommentTextTest.cpp
@@ -0,0 +1,113 @@
+//===- unittest/AST/CommentTextTest.cpp - Comment text extraction test ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Tests for user-friendly output formatting of comments, i.e.
+// RawComment::getFormattedText().
+//
+//===--===//
+
+#include "clang/AST/RawCommentList.h"
+#include "clang/Basic/CommentOptions.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/FileSystemOptions.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/VirtualFileSystem.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include 
+
+namespace clang {
+
+class CommentTextTest : public ::testing::Test {
+protected:
+  std::string formatComment(llvm::StringRef CommentText) {
+llvm::IntrusiveRefCntPtr EmptyFS(
+new vfs::InMemoryFileSystem);
+FileSystemOptions Opts;
+FileManager FileMgr(Opts, EmptyFS);
+
+DiagnosticsEngine Diags(new DiagnosticIDs, new DiagnosticOptions);
+SourceManager SourceMgr(Diags, FileMgr);
+
+auto File = SourceMgr.createFileID(
+llvm::MemoryBuffer::getMemBuffer(CommentText, "test-comment"));
+
+auto CommentStartOffset = CommentText.find("/");
+assert(CommentStartOffset != llvm::StringRef::npos);
+
+SourceRange CommentRange(
+SourceMgr.getLocForStartOfFile(File).getLocWithOffset(
+CommentStartOffset),
+SourceMgr.getLocForEndOfFile(File));
+CommentOptions EmptyOpts;
+// FIXME: technically, merged that we set here is incorrect, but that
+// shouldn't matter.
+RawComment Comment(SourceMgr, CommentRange, EmptyOpts, /*Merged=*/true);
+return Comment.getFormattedText(SourceMgr, Diags);
+  }
+};
+
+TEST_F(CommentTextTest, FormattedText) {
+  // clang-format off
+  auto ExpectedOutput =
+R"(This function does this and that.
+For example,
+   Runnning it in that case will give you
+   this result.
+That's about it.)";
+  // Two-slash comments.
+  EXPECT_EQ(ExpectedOutput, formatComment(
+R"cpp(
+// This function does this and that.
+// For example,
+//Runnning it in that case will give you
+//this result.
+// That's about it.)cpp"));
+
+  // Three-slash comments.
+  EXPECT_EQ(ExpectedOutput, formatComment(
+R"cpp(
+/// This function does this and that.
+/// For example,
+///Runnning it in that case will give you
+///this result.
+/// That's about it.)cpp"));
+
+  // Block comments.
+  EXPECT_EQ(ExpectedOutput, formatComment(
+R"cpp(
+/* This function does this and that.
+ * For example,
+ *Runnning it in that case will give you
+ *this result.
+ * That's about it.*/)cpp"));
+
+  // Doxygen-style block comments.
+  EXPECT_EQ(ExpectedOutput, formatComment(
+R"cpp(
+/** This function does this and that.
+  * For example,
+  *Runnning it in that case will give you
+  *this result.
+  * That's about it.*/)cpp"));
+
+  // Weird indentation.
+  EXPECT_EQ(ExpectedOutput, formatComment(
+R"cpp(
+   // This function does this and that.
+  //  For example,
+  // Runnning it in that case will give you
+//   this result.
+   // That's about it.)cpp"));
+  // clang-format on
+}
+
+} // namespace clang
Index: unittests/AST/CMakeLists.txt
===
--- unittests/AST/CMakeLists.txt
+++ unittests/AST/CMakeLists.txt
@@ -9,6 +9,7 @@
   ASTVectorTest.cpp
   CommentLexer.cpp
   CommentParser.cpp
+  CommentTextTest.cpp
   DataCollectionTest.cpp
   DeclPrinterTest.cpp
   DeclTest.cpp
Index: lib/AST/RawCommentList.cpp
===
--- lib/AST/RawCommentList.cpp
+++ lib/AST/RawCommentList.cpp
@@ -335,3 +335,98 @@
  BeforeThanCompare(SourceMgr));
   std::swap(Comments, MergedComments);
 }
+
+std::string RawComment::getFormattedText(const ASTContext &Ctx) const {
+  return getFormattedText(Ctx.getSourceManager(), Ctx.getDiagnostics

[PATCH] D46000: [AST] Added a helper to extract a user-friendly text of a comment.

2018-05-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: lib/AST/RawCommentList.cpp:376
+SourceMgr.getSpellingColumnNumber(Tok.getLocation(), &LocInvalid);
+if (LocInvalid)
+  TokColumn = 0;

ioeric wrote:
> This is a bit confusing... Could you please add comments about the behavior 
> here (as chatted offline)?
After thinking about it for a while, decided to add an assert that location was 
valid instead.
Invalid locations don't make any sense there, since we won't be able to get the 
comment text in case of invalid locs.



Comment at: lib/AST/RawCommentList.cpp:394
+: std::min(WhitespaceLen,
+   (size_t)std::max((int)IndentColumn - (int)TokColumn, 
0));
+llvm::StringRef Trimmed = TokText.drop_front(SkipLen);

ioeric wrote:
> use `static_cast` instead of conversions.
Done. Rewrote the code to keep the reduce the number of casts too. It was 
unreadable with 3 static casts and default formatting.


Repository:
  rC Clang

https://reviews.llvm.org/D46000



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


[PATCH] D46001: [CodeComplete] Expose helpers to get RawComment of completion result.

2018-05-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

@arphaman, friendly ping. In case you're the wrong person to review it, I'll 
try to find someone else.


Repository:
  rC Clang

https://reviews.llvm.org/D46001



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


r331766 - [OpenCL] Factor out language version printing

2018-05-08 Thread Sven van Haastregt via cfe-commits
Author: svenvh
Date: Tue May  8 06:47:43 2018
New Revision: 331766

URL: http://llvm.org/viewvc/llvm-project?rev=331766&view=rev
Log:
[OpenCL] Factor out language version printing

Generate a printable OpenCL language version number in a single place
and select between the OpenCL C or OpenCL C++ version accordingly.

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

Modified:
cfe/trunk/include/clang/Basic/LangOptions.h
cfe/trunk/lib/Basic/LangOptions.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp

Modified: cfe/trunk/include/clang/Basic/LangOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=331766&r1=331765&r2=331766&view=diff
==
--- cfe/trunk/include/clang/Basic/LangOptions.h (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.h Tue May  8 06:47:43 2018
@@ -254,6 +254,9 @@ public:
   bool assumeFunctionsAreConvergent() const {
 return (CUDA && CUDAIsDevice) || OpenCL;
   }
+
+  /// \brief Return the OpenCL C or C++ version as a VersionTuple.
+  VersionTuple getOpenCLVersionTuple() const;
 };
 
 /// \brief Floating point control options

Modified: cfe/trunk/lib/Basic/LangOptions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/LangOptions.cpp?rev=331766&r1=331765&r2=331766&view=diff
==
--- cfe/trunk/lib/Basic/LangOptions.cpp (original)
+++ cfe/trunk/lib/Basic/LangOptions.cpp Tue May  8 06:47:43 2018
@@ -43,3 +43,8 @@ bool LangOptions::isNoBuiltinFunc(String
   return true;
   return false;
 }
+
+VersionTuple LangOptions::getOpenCLVersionTuple() const {
+  const int Ver = OpenCLCPlusPlus ? OpenCLCPlusPlusVersion : OpenCLVersion;
+  return VersionTuple(Ver / 100, (Ver % 100) / 10);
+}

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=331766&r1=331765&r2=331766&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue May  8 06:47:43 2018
@@ -76,7 +76,6 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Regex.h"
-#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetOptions.h"
 #include 
@@ -2157,11 +2156,9 @@ static void ParseLangArgs(LangOptions &O
   // this option was added for compatibility with OpenCL 1.0.
   if (Args.getLastArg(OPT_cl_strict_aliasing)
&& Opts.OpenCLVersion > 100) {
-std::string VerSpec = llvm::to_string(Opts.OpenCLVersion / 100) +
-  std::string(".") +
-  llvm::to_string((Opts.OpenCLVersion % 100) / 10);
 Diags.Report(diag::warn_option_invalid_ocl_version)
-  << VerSpec << Args.getLastArg(OPT_cl_strict_aliasing)->getAsString(Args);
+<< Opts.getOpenCLVersionTuple().getAsString()
+<< Args.getLastArg(OPT_cl_strict_aliasing)->getAsString(Args);
   }
 
   // We abuse '-f[no-]gnu-keywords' to force overriding all GNU-extension

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=331766&r1=331765&r2=331766&view=diff
==
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Tue May  8 06:47:43 2018
@@ -29,7 +29,6 @@
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringSwitch.h"
-#include "llvm/Support/ScopedPrinter.h"
 
 using namespace clang;
 
@@ -3806,11 +3805,8 @@ void Parser::ParseDeclarationSpecifiers(
 Diag(Tok, DiagID)
   << PrevSpec << FixItHint::CreateRemoval(Tok.getLocation());
   else if (DiagID == diag::err_opencl_unknown_type_specifier) {
-const int OpenCLVer = getLangOpts().OpenCLVersion;
-std::string VerSpec = llvm::to_string(OpenCLVer / 100) +
-  std::string (".") +
-  llvm::to_string((OpenCLVer % 100) / 10);
-Diag(Tok, DiagID) << VerSpec << PrevSpec << isStorageClass;
+Diag(Tok, DiagID) << 
getLangOpts().getOpenCLVersionTuple().getAsString()
+  << PrevSpec << isStorageClass;
   } else
 Diag(Tok, DiagID) << PrevSpec;
 }


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


[PATCH] D46382: [OpenCL] Factor out language version printing

2018-05-08 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL331766: [OpenCL] Factor out language version printing 
(authored by svenvh, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46382?vs=144991&id=145684#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46382

Files:
  cfe/trunk/include/clang/Basic/LangOptions.h
  cfe/trunk/lib/Basic/LangOptions.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/lib/Parse/ParseDecl.cpp


Index: cfe/trunk/lib/Basic/LangOptions.cpp
===
--- cfe/trunk/lib/Basic/LangOptions.cpp
+++ cfe/trunk/lib/Basic/LangOptions.cpp
@@ -43,3 +43,8 @@
   return true;
   return false;
 }
+
+VersionTuple LangOptions::getOpenCLVersionTuple() const {
+  const int Ver = OpenCLCPlusPlus ? OpenCLCPlusPlusVersion : OpenCLVersion;
+  return VersionTuple(Ver / 100, (Ver % 100) / 10);
+}
Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -76,7 +76,6 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Regex.h"
-#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetOptions.h"
 #include 
@@ -2157,11 +2156,9 @@
   // this option was added for compatibility with OpenCL 1.0.
   if (Args.getLastArg(OPT_cl_strict_aliasing)
&& Opts.OpenCLVersion > 100) {
-std::string VerSpec = llvm::to_string(Opts.OpenCLVersion / 100) +
-  std::string(".") +
-  llvm::to_string((Opts.OpenCLVersion % 100) / 10);
 Diags.Report(diag::warn_option_invalid_ocl_version)
-  << VerSpec << Args.getLastArg(OPT_cl_strict_aliasing)->getAsString(Args);
+<< Opts.getOpenCLVersionTuple().getAsString()
+<< Args.getLastArg(OPT_cl_strict_aliasing)->getAsString(Args);
   }
 
   // We abuse '-f[no-]gnu-keywords' to force overriding all GNU-extension
Index: cfe/trunk/lib/Parse/ParseDecl.cpp
===
--- cfe/trunk/lib/Parse/ParseDecl.cpp
+++ cfe/trunk/lib/Parse/ParseDecl.cpp
@@ -29,7 +29,6 @@
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringSwitch.h"
-#include "llvm/Support/ScopedPrinter.h"
 
 using namespace clang;
 
@@ -3806,11 +3805,8 @@
 Diag(Tok, DiagID)
   << PrevSpec << FixItHint::CreateRemoval(Tok.getLocation());
   else if (DiagID == diag::err_opencl_unknown_type_specifier) {
-const int OpenCLVer = getLangOpts().OpenCLVersion;
-std::string VerSpec = llvm::to_string(OpenCLVer / 100) +
-  std::string (".") +
-  llvm::to_string((OpenCLVer % 100) / 10);
-Diag(Tok, DiagID) << VerSpec << PrevSpec << isStorageClass;
+Diag(Tok, DiagID) << 
getLangOpts().getOpenCLVersionTuple().getAsString()
+  << PrevSpec << isStorageClass;
   } else
 Diag(Tok, DiagID) << PrevSpec;
 }
Index: cfe/trunk/include/clang/Basic/LangOptions.h
===
--- cfe/trunk/include/clang/Basic/LangOptions.h
+++ cfe/trunk/include/clang/Basic/LangOptions.h
@@ -254,6 +254,9 @@
   bool assumeFunctionsAreConvergent() const {
 return (CUDA && CUDAIsDevice) || OpenCL;
   }
+
+  /// \brief Return the OpenCL C or C++ version as a VersionTuple.
+  VersionTuple getOpenCLVersionTuple() const;
 };
 
 /// \brief Floating point control options


Index: cfe/trunk/lib/Basic/LangOptions.cpp
===
--- cfe/trunk/lib/Basic/LangOptions.cpp
+++ cfe/trunk/lib/Basic/LangOptions.cpp
@@ -43,3 +43,8 @@
   return true;
   return false;
 }
+
+VersionTuple LangOptions::getOpenCLVersionTuple() const {
+  const int Ver = OpenCLCPlusPlus ? OpenCLCPlusPlusVersion : OpenCLVersion;
+  return VersionTuple(Ver / 100, (Ver % 100) / 10);
+}
Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -76,7 +76,6 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Regex.h"
-#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetOptions.h"
 #include 
@@ -2157,11 +2156,9 @@
   // this option was added for compatibility with OpenCL 1.0.
   if (Args.getLastArg(OPT_cl_strict_aliasing)
&& Opts.OpenCLVersion > 100) {
-std::string VerSpec = llvm::to_string(Opts.OpenCLVersion / 100) +
-  std::string(".") +
-  llvm::to_strin

[PATCH] D46188: [clang-tidy] Add a flag to enable debug checkers

2018-05-08 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In https://reviews.llvm.org/D46188#1091237, @lebedev.ri wrote:

> In https://reviews.llvm.org/D46188#1091221, @alexfh wrote:
>
> > I don't think debug CSA checkers belong to clang-tidy. If one needs to dump 
> > CFG, they are probably doing quite involved stuff already, so going a step 
> > further and running `clang -cc1 -analyze` would not be difficult. The 
> > motivation for exposing alpha checkers (letting users test them and provide 
> > feedback) doesn't work for debug checkers.
>
>
> There is word play here.
>  They are debug CSA checkers. But not all of them are debugging the CSA. Many 
> of them are just utility checkers that could be just as easily a clang-tidy 
> debug/utility checkers:


I roughly understand what debug CSA checkers are. However, I don't see much 
value in exposing them in clang-tidy. While it may be valuable to look at the 
CFG dump when developing a clang-tidy check, for example, but this can be done 
using clang

  $ clang -cc1 -help | grep cfg
   -cfg-add-implicit-dtors Add C++ implicit destructors to CFGs for all analyses
   -cfg-add-initializers   Add C++ initializers to CFGs for all analyses
   -cfg-dump   Display Control-Flow Graphs
   -cfg-view   View Control-Flow Graphs using GraphViz
   -unoptimized-cfgGenerate unoptimized CFGs for all analyses

All CSA debug checkers can also be invoked using clang -cc1 --analyze. The only 
thing clang-tidy could bring is a possibility to more easily run all these 
tools on a file from a project that is using a compilation database. However, 
that doesn't seem like a very valuable functionality, because 1. working on 
small artificial test cases (or test cases reduced from real code) is easier, 
2. in a rare case when a file from a real project needs to be analyzed, it's 
possible to get compilation arguments and feed them to clang (e.g. using 
clang-tidy -extra-arg=-v file.cpp).


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46188



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


[PATCH] D46187: [Analyzer] getRegisteredCheckers(): handle debug checkers too.

2018-05-08 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In https://reviews.llvm.org/D46187#1088722, @NoQ wrote:

> It seems that you're using debug checkers of the analyzer to gain some free 
> tools for exploring the source code (such as displaying a call graph) for 
> free, right?
>
> I believe we could also benefit from a method of extracting the analyzer's 
> `clang -cc1` run-line from clang-tidy.


It should be possible now using `clang-tidy -extra-arg=-v some/file.cpp` (or 
`clang-check -extra-arg=-v ...`).


Repository:
  rC Clang

https://reviews.llvm.org/D46187



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


r331768 - [OPENMP, NVPTX] Fix linkage of the global entries.

2018-05-08 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue May  8 07:16:57 2018
New Revision: 331768

URL: http://llvm.org/viewvc/llvm-project?rev=331768&view=rev
Log:
[OPENMP, NVPTX] Fix linkage of the global entries.

The linkage of the global entries must be weak to enable support of
redefinition of the same target regions in multiple compilation units.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/test/OpenMP/declare_target_codegen.cpp
cfe/trunk/test/OpenMP/declare_target_codegen_globalization.cpp
cfe/trunk/test/OpenMP/declare_target_link_codegen.cpp
cfe/trunk/test/OpenMP/nvptx_data_sharing.cpp
cfe/trunk/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp
cfe/trunk/test/OpenMP/nvptx_target_firstprivate_codegen.cpp
cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp

cfe/trunk/test/OpenMP/nvptx_target_teams_distribute_parallel_for_generic_mode_codegen.cpp
cfe/trunk/test/OpenMP/target_codegen.cpp
cfe/trunk/test/OpenMP/target_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_depend_codegen.cpp
cfe/trunk/test/OpenMP/target_firstprivate_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_parallel_debug_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_depend_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_for_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_for_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_parallel_for_debug_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_for_depend_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_for_simd_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_for_simd_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_parallel_for_simd_depend_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_if_codegen.cpp
cfe/trunk/test/OpenMP/target_parallel_num_threads_codegen.cpp
cfe/trunk/test/OpenMP/target_private_codegen.cpp
cfe/trunk/test/OpenMP/target_reduction_codegen.cpp
cfe/trunk/test/OpenMP/target_simd_codegen.cpp
cfe/trunk/test/OpenMP/target_simd_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_simd_depend_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_teams_depend_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_depend_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_codegen.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_depend_codegen.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_firstprivate_codegen.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_private_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_simd_codegen.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_simd_codegen_registration.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_simd_depend_codegen.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_simd_firstprivate_codegen.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_simd_private_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_simd_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_simd_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_simd_depend_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_num_teams_codegen.cpp
cfe/trunk/test/OpenMP/target_teams_thread_limit_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=331768&r1=331767&r2=331768&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue May  8 07:16:57 2018
@@ -3863,9 +3863,9 @@ void CGOpenMPRuntime::createOffloadEntry
 llvm::ConstantInt::get(CGM.Int32Ty, Flags),
 llvm::ConstantInt::get(CGM.Int32Ty, 0)};
   std::string EntryName = getName({"omp_offloading", "entry", ""});
-  llvm::GlobalVariable *Entry =
-  createConstantGlobalStruct(CGM, getTgtOffloadEntryQTy(), Data,
- Twine(EntryName).concat(Name), Linkage);
+  llvm::GlobalVariable *Entry = createConstantGlobalStruct(
+  CGM, getTgtOffloadEntryQTy(), Data, Twine(EntryName).concat(Name),
+  llvm::GlobalValue::WeakAnyLinkage);
 
   // The entry has to be created in the section the linker expects it to be.
   std::string Section = getName({"omp_offloading", "entries"});
@@ -6281,13 +6281,13 @@ void CGOpenMPRuntime::emitTargetOutlined
 
   if (CGM.getLangOpts()

[PATCH] D46439: Fix incorrect packed aligned structure layout

2018-05-08 Thread Momchil Velikov via Phabricator via cfe-commits
chill updated this revision to Diff 145687.

https://reviews.llvm.org/D46439

Files:
  lib/Sema/SemaDecl.cpp
  test/Layout/itanium-pack-and-align.cpp


Index: test/Layout/itanium-pack-and-align.cpp
===
--- /dev/null
+++ test/Layout/itanium-pack-and-align.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm-only 
-fdump-record-layouts %s \
+// RUN:| FileCheck %s
+
+struct S {
+  char x;
+  int y;
+} __attribute__((packed, aligned(8)));
+
+struct alignas(8) T {
+  char x;
+  int y;
+} __attribute__((packed));
+
+S s;
+T t;
+// CHECK:  0 | struct T
+// CHECK-NEXT:  0 |   char x
+// CHECK-NEXT:  1 |   int y
+// CHECK-NEXT:| [sizeof=8, dsize=8, align=8,
+// CHECK-NEXT:|  nvsize=8, nvalign=8]
+
+// CHECK:  0 | struct S
+// CHECK-NEXT:  0 |   char x
+// CHECK-NEXT:  1 |   int y
+// CHECK-NEXT:| [sizeof=8, dsize=8, align=8,
+// CHECK-NETX:|  nvsize=8, nvalign=8]
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -15573,6 +15573,10 @@
 if (!Completed)
   Record->completeDefinition();
 
+// Handle attributes before checking the layout.
+if (Attr)
+  ProcessDeclAttributeList(S, Record, Attr);
+
 // We may have deferred checking for a deleted destructor. Check now.
 if (CXXRecordDecl *CXXRecord = dyn_cast(Record)) {
   auto *Dtor = CXXRecord->getDestructor();
@@ -15703,9 +15707,6 @@
   CDecl->setIvarRBraceLoc(RBrac);
 }
   }
-
-  if (Attr)
-ProcessDeclAttributeList(S, Record, Attr);
 }
 
 /// \brief Determine whether the given integral value is representable within


Index: test/Layout/itanium-pack-and-align.cpp
===
--- /dev/null
+++ test/Layout/itanium-pack-and-align.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm-only -fdump-record-layouts %s \
+// RUN:| FileCheck %s
+
+struct S {
+  char x;
+  int y;
+} __attribute__((packed, aligned(8)));
+
+struct alignas(8) T {
+  char x;
+  int y;
+} __attribute__((packed));
+
+S s;
+T t;
+// CHECK:  0 | struct T
+// CHECK-NEXT:  0 |   char x
+// CHECK-NEXT:  1 |   int y
+// CHECK-NEXT:| [sizeof=8, dsize=8, align=8,
+// CHECK-NEXT:|  nvsize=8, nvalign=8]
+
+// CHECK:  0 | struct S
+// CHECK-NEXT:  0 |   char x
+// CHECK-NEXT:  1 |   int y
+// CHECK-NEXT:| [sizeof=8, dsize=8, align=8,
+// CHECK-NETX:|  nvsize=8, nvalign=8]
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -15573,6 +15573,10 @@
 if (!Completed)
   Record->completeDefinition();
 
+// Handle attributes before checking the layout.
+if (Attr)
+  ProcessDeclAttributeList(S, Record, Attr);
+
 // We may have deferred checking for a deleted destructor. Check now.
 if (CXXRecordDecl *CXXRecord = dyn_cast(Record)) {
   auto *Dtor = CXXRecord->getDestructor();
@@ -15703,9 +15707,6 @@
   CDecl->setIvarRBraceLoc(RBrac);
 }
   }
-
-  if (Attr)
-ProcessDeclAttributeList(S, Record, Attr);
 }
 
 /// \brief Determine whether the given integral value is representable within
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46439: Fix incorrect packed aligned structure layout

2018-05-08 Thread Momchil Velikov via Phabricator via cfe-commits
chill marked an inline comment as done.
chill added a comment.

Update: updated comment, added a test.




Comment at: lib/Sema/SemaDecl.cpp:15651
 }
   } else {
 ObjCIvarDecl **ClsFields =

rsmith wrote:
> Do we need to do any attribute processing in this Objective-C interface / 
> implementation / category case?
I think we didn't need it, or else `ProcessDeclAttributeList` would have been 
called with a null `Record` argument.


https://reviews.llvm.org/D46439



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


[PATCH] D43778: [clang-tidy] Adding RestrictIncludes check to Fuchsia module

2018-05-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/fuchsia/FuchsiaTidyModule.cpp:41
+CheckFactories.registerCheck(
+"fuchsia-restrict-includes");
 CheckFactories.registerCheck(

I think this should be named `fuchsia-restrict-system-includes`.



Comment at: clang-tidy/fuchsia/RestrictIncludesCheck.cpp:60
+StringRef SearchPath, StringRef RelativePath, const Module *Imported) {
+  if (!llvm::is_contained(Check.getAllowedIncludes(), FileName) && IsAngled)
+// Bucket the allowed include directives by the id of the file they were

I'm not certain that `IsAngled` is sufficient. For instance, say the user 
prohibits use of `vector`, nothing prevents the user from writing `#include 
"vector"` to access the system header (assuming there is no user header with 
the same name). e.g., https://godbolt.org/g/Scfv3U

Perhaps we could use `SourceManager::isInSystemHeader()` or extract some logic 
from it to test whether the actual included file is in the system header search 
path?



Comment at: docs/ReleaseNotes.rst:116
+
+  Checks for allowed includes and suggests removal of any others. If no 
includes
+  are specified, the check will exit without issuing any warnings.

Be explicit that this only impacts system headers.



Comment at: docs/clang-tidy/checks/fuchsia-restrict-includes.rst:6-7
+
+Checks for allowed includes and suggests removal of any others. If no includes
+are specified, the check will exit without issuing any warnings. 
+

Should also be explicit about system headers.



Comment at: test/clang-tidy/Inputs/fuchsia-restrict-includes/system/r.h:2
+void f() {}
\ No newline at end of file


Please add in the EOF.



Comment at: 
test/clang-tidy/Inputs/fuchsia-restrict-includes/system/transitive.h:2
+#include 
\ No newline at end of file


Please add in the EOF.



Comment at: test/clang-tidy/fuchsia-restrict-includes.cpp:31
+}
\ No newline at end of file


Please add in the EOF.


https://reviews.llvm.org/D43778



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


[PATCH] D46000: [AST] Added a helper to extract a user-friendly text of a comment.

2018-05-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 145691.
ilya-biryukov added a comment.

- Fixed infinite loop with comments that contain doxygen commands


Repository:
  rC Clang

https://reviews.llvm.org/D46000

Files:
  include/clang/AST/CommentLexer.h
  include/clang/AST/RawCommentList.h
  lib/AST/CommentLexer.cpp
  lib/AST/RawCommentList.cpp
  unittests/AST/CMakeLists.txt
  unittests/AST/CommentTextTest.cpp

Index: unittests/AST/CommentTextTest.cpp
===
--- /dev/null
+++ unittests/AST/CommentTextTest.cpp
@@ -0,0 +1,128 @@
+//===- unittest/AST/CommentTextTest.cpp - Comment text extraction test ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Tests for user-friendly output formatting of comments, i.e.
+// RawComment::getFormattedText().
+//
+//===--===//
+
+#include "clang/AST/RawCommentList.h"
+#include "clang/Basic/CommentOptions.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/FileSystemOptions.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/VirtualFileSystem.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include 
+
+namespace clang {
+
+class CommentTextTest : public ::testing::Test {
+protected:
+  std::string formatComment(llvm::StringRef CommentText) {
+llvm::IntrusiveRefCntPtr EmptyFS(
+new vfs::InMemoryFileSystem);
+FileSystemOptions Opts;
+FileManager FileMgr(Opts, EmptyFS);
+
+DiagnosticsEngine Diags(new DiagnosticIDs, new DiagnosticOptions);
+SourceManager SourceMgr(Diags, FileMgr);
+
+auto File = SourceMgr.createFileID(
+llvm::MemoryBuffer::getMemBuffer(CommentText, "test-comment"));
+
+auto CommentStartOffset = CommentText.find("/");
+assert(CommentStartOffset != llvm::StringRef::npos);
+
+SourceRange CommentRange(
+SourceMgr.getLocForStartOfFile(File).getLocWithOffset(
+CommentStartOffset),
+SourceMgr.getLocForEndOfFile(File));
+CommentOptions EmptyOpts;
+// FIXME: technically, merged that we set here is incorrect, but that
+// shouldn't matter.
+RawComment Comment(SourceMgr, CommentRange, EmptyOpts, /*Merged=*/true);
+return Comment.getFormattedText(SourceMgr, Diags);
+  }
+};
+
+TEST_F(CommentTextTest, FormattedText) {
+  // clang-format off
+  auto ExpectedOutput =
+R"(This function does this and that.
+For example,
+   Runnning it in that case will give you
+   this result.
+That's about it.)";
+  // Two-slash comments.
+  EXPECT_EQ(ExpectedOutput, formatComment(
+R"cpp(
+// This function does this and that.
+// For example,
+//Runnning it in that case will give you
+//this result.
+// That's about it.)cpp"));
+
+  // Three-slash comments.
+  EXPECT_EQ(ExpectedOutput, formatComment(
+R"cpp(
+/// This function does this and that.
+/// For example,
+///Runnning it in that case will give you
+///this result.
+/// That's about it.)cpp"));
+
+  // Block comments.
+  EXPECT_EQ(ExpectedOutput, formatComment(
+R"cpp(
+/* This function does this and that.
+ * For example,
+ *Runnning it in that case will give you
+ *this result.
+ * That's about it.*/)cpp"));
+
+  // Doxygen-style block comments.
+  EXPECT_EQ(ExpectedOutput, formatComment(
+R"cpp(
+/** This function does this and that.
+  * For example,
+  *Runnning it in that case will give you
+  *this result.
+  * That's about it.*/)cpp"));
+
+  // Weird indentation.
+  EXPECT_EQ(ExpectedOutput, formatComment(
+R"cpp(
+   // This function does this and that.
+  //  For example,
+  // Runnning it in that case will give you
+//   this result.
+   // That's about it.)cpp"));
+  // clang-format on
+}
+
+TEST_F(CommentTextTest, KeepsDoxygenControlSeqs) {
+  // clang-format off
+  auto ExpectedOutput =
+R"(\brief This is the brief part of the comment.
+\param a something about a.
+@param b something about b.)";
+
+  EXPECT_EQ(ExpectedOutput, formatComment(
+R"cpp(
+/// \brief This is the brief part of the comment.
+/// \param a something about a.
+/// @param b something about b.)cpp"));
+  // clang-format on
+}
+
+} // namespace clang
Index: unittests/AST/CMakeLists.txt
===
--- unittests/AST/CMakeLists.txt
+++ unittests/AST/CMakeLists.txt
@@ -9,6 +9,7 @@
   ASTVectorTest.cpp
   CommentLexer.cpp
   CommentParser.cpp
+  CommentTextTest.cpp
   DataCollectionTest.cpp
   DeclPrinterTest.cpp
   DeclTest.cpp
Index: lib/AST/RawCommentList.cpp
===
--- lib/AST/RawCommentLi

[PATCH] D41537: Optionally add code completion results for arrow instead of dot

2018-05-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: include/clang-c/Index.h:5237
+/**
+ * \brief FixIts that *must* be applied before inserting the text for the
+ * corresponding completion item. Completion items with non-empty fixits will

This seems too large for a brief comment :-) 
Maybe break with a newline after the first sentence.



Comment at: include/clang/Sema/CodeCompleteConsumer.h:564
+
+  /// \brief For this completion result correction is required.
+  std::vector Corrections;

yvvan wrote:
> yvvan wrote:
> > ilya-biryukov wrote:
> > > Adding some docs here would be useful. These fix-its could be interpreted 
> > > too broadly at this point.
> > > I suggest the following semantics and the comment:
> > > 
> > > ```
> > > /// \brief FixIts that *must* be applied before inserting the text for 
> > > the corresponding completion item.
> > > /// Completion items with non-empty fixits will not be returned by 
> > > default, they should be explicitly requested by setting 
> > > CompletionOptions::IncludeCorrections.
> > > /// For the editors to be able to compute position of the cursor for the 
> > > completion item itself, the following conditions are guaranteed to hold 
> > > for RemoveRange of the stored fixits:
> > > ///  - Ranges in the fixits are guaranteed to never contain the 
> > > completion point (or identifier under completion point, if any) inside 
> > > them, except at the start or at the end of the range.
> > > ///  - If a fixit range starts or ends with completion point (or starts 
> > > or ends after the identifier under completion point), it will contain at 
> > > least one character. It allows to unambiguously recompute completion 
> > > point after applying the fixit.
> > > /// The intuition is that provided fixits change code around the 
> > > identifier we complete, but are not allowed to touch the identifier 
> > > itself or the completion point.
> > > /// One example of completion items with corrections are the ones 
> > > replacing '.' with '->' and vice versa:
> > > ///  std::unique_ptr> vec_ptr;
> > > ///  vec_ptr.^  // completion returns an item 'push_back', replacing 
> > > '.' with '->'
> > > ///  vec_ptr->^ // completion returns an item 'release', replacing 
> > > '->' with '.'let's put 
> > > ```
> > > 
> > > Do those invariants sound reasonable? Could we add asserts that they hold 
> > > when constructing the completion results?
> > Thanks! I usually feel the lack of patience when writing descriptions :)
> "Could we add asserts that they hold when constructing the completion results"
> 
> The current way of creating them actually assures that by default. And to 
> check it once again it's required to change many things.
> Starting with the fact that there is no SourceRange contains() methos or 
> something similar,
> The current way of creating them actually assures that by default. And to 
> check it once again it's required to change many things.
It's still nice to have a sanity check there, mostly for the sake of new checks 
that are gonna get added.
But even the current one is tricky, since it may actually contain a range that 
ends exactly at the cursor (when completing right after the dot/arrow `foo->|`).

> Starting with the fact that there is no SourceRange contains() methos or 
> something similar,
Moreover, `SourceRange` doesn't have clear semantics AFAIK. It can either be a 
half-open or closed range.
Let's add a FIXME, at least, that we should add those asserts later.




Comment at: include/clang/Sema/CodeCompleteConsumer.h:564
+
+  /// \brief FixIts that *must* be applied before inserting the text for the
+  /// corresponding completion item. Completion items with non-empty fixits 
will

I suggest moving this doc comment to `getFixits` method, as it is the public 
interface.



Comment at: include/clang/Sema/CodeCompleteConsumer.h:592
+   StringRef ParentName, const char *BriefComment,
+   std::vector FixIts);
   ~CodeCompletionString() = default;

We can't store fixits in `CodeCompletionString`, it should not contain source 
locatins, which are only valid for the lifetime of SourceManager.
Note that CCS has a lifetime independent of both the SourceManager and the AST.
Storing them in CodeCompletionResult should be good enough for all our 
use-cases.



Comment at: include/clang/Sema/CodeCompleteConsumer.h:814
 
+  /// \brief FixIts that *must* be applied before inserting the text for the
+  /// corresponding completion item. Completion items with non-empty fixits 
will

We shouldn't duplicate such a large comment in too many places, it would be 
impossible to keep it in sync.
I would suggest only keeping it in `CodeCompletionResult` and add a reference 
to it in other places.
libclang is a bit tricky, though. It is distributed without other LLV

[PATCH] D46540: [X86] ptwrite intrinsic

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

LGTM


https://reviews.llvm.org/D46540



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


[PATCH] D46541: [CodeGen] Improve diagnostics related to target attributes

2018-05-08 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: lib/CodeGen/CodeGenFunction.cpp:2346
+  return Feat.substr(1) == F.getKey();
+   }))
+ReqFeatures.insert(ReqFeatures.begin(), F.getKey());

This and the next line are indented funny.


https://reviews.llvm.org/D46541



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


[PATCH] D42933: [Sema] Avoid -Wformat warning for NSInteger/NSUInteger 'int' values with %zu/%zi long specifiers

2018-05-08 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

In https://reviews.llvm.org/D42933#1091234, @aaron.ballman wrote:

> In https://reviews.llvm.org/D42933#1090268, @jfb wrote:
>
> > I was just looking at this, and I think @arphaman's patch is pretty much 
> > the right approach (with 2 suggested fixes below).
> >
> > I don't think the code we're currently warning on is broken: a user code 
> > has `NSInteger` with `%zd` or `NSUInteger` with `%zu`, and on all platforms 
> > which support those types the implementor has guaranteed that 
> > `(sizeof(size_t) == sizeof(NSInteger)) && (sizeof(ssize_t) == 
> > sizeof(NSUInteger))`.
>
>
> Yes, but is this guaranteed to be the case or does it happen to be the case? 
> I'm worried about the less mainstream uses where you might find ObjC code 
> where this does not hold but -Wformat points out a portability concern.


Also keep in mind that Obj-C might be used on non-Apple platforms, e.g. there's 
an active review going on for GNUstep ABI v2 right now 
(https://reviews.llvm.org/D46052), and WinObjC is also a thing. Those platforms 
might not necessarily provide the same guarantees or consistency that Apple's 
do.

>> I agree that, if we're playing C++ pedant and look at the typedefs, then 
>> it's undefined behavior and the code is broken.
> 
> This is reason alone to diagnose the code, because the optimizer is welcome 
> to use that UB to perform transformations the programmer did not expect. 
> However, I'm not certain our optimizer is currently paying attention to that 
> UB directly, so this may not be an immediate issue (but could be a pitfall 
> for the future) but I'm not certain about other optimizers for which 
> portability would still be a concern.

I would honestly find it a bit surprising (and scary) if the optimizer actually 
took advantage of UB in the case where the size and alignment of the specifier 
and the actual type matches.


Repository:
  rC Clang

https://reviews.llvm.org/D42933



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


[PATCH] D46475: [HIP] Set proper triple and offload kind for the toolchain

2018-05-08 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 145699.
yaxunl marked an inline comment as done.
yaxunl added a comment.

Revised by John's comments.


https://reviews.llvm.org/D46475

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Driver/Options.td
  include/clang/Driver/Types.h
  lib/Driver/Driver.cpp
  lib/Driver/Types.cpp
  test/Driver/Inputs/hip_multiple_inputs/a.cu
  test/Driver/Inputs/hip_multiple_inputs/b.hip
  test/Driver/hip-inputs.hip

Index: test/Driver/hip-inputs.hip
===
--- /dev/null
+++ test/Driver/hip-inputs.hip
@@ -0,0 +1,23 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang -ccc-print-phases -target x86_64-linux-gnu \
+// RUN:   -x hip --cuda-gpu-arch=gfx803 -c \
+// RUN:   %S/Inputs/hip_multiple_inputs/a.cu \
+// RUN:   %S/Inputs/hip_multiple_inputs/b.hip 2>&1 \
+// RUN: | FileCheck %s
+
+// RUN: not %clang -ccc-print-phases -target x86_64-linux-gnu \
+// RUN:   --cuda-gpu-arch=gfx803 -c \
+// RUN:   %S/Inputs/hip_multiple_inputs/a.cu \
+// RUN:   %S/Inputs/hip_multiple_inputs/b.hip 2>&1 \
+// RUN: | FileCheck -check-prefix=MIX %s
+
+// RUN: not %clang -ccc-print-phases -target x86_64-linux-gnu \
+// RUN:   --cuda-gpu-arch=gfx803 -c \
+// RUN:   --hip-link %S/Inputs/hip_multiple_inputs/a.cu 2>&1 \
+// RUN: | FileCheck -check-prefix=MIX %s
+
+// CHECK-NOT: error: Mixed Cuda and HIP compilation is not supported.
+// MIX: error: Mixed Cuda and HIP compilation is not supported.
Index: lib/Driver/Types.cpp
===
--- lib/Driver/Types.cpp
+++ lib/Driver/Types.cpp
@@ -172,6 +172,15 @@
   case TY_CUDA:
   case TY_PP_CUDA:
   case TY_CUDA_DEVICE:
+return true;
+  }
+}
+
+bool types::isHIP(ID Id) {
+  switch (Id) {
+  default:
+return false;
+
   case TY_HIP:
   case TY_PP_HIP:
   case TY_HIP_DEVICE:
@@ -230,6 +239,7 @@
.Case("fpp", TY_Fortran)
.Case("FPP", TY_Fortran)
.Case("gch", TY_PCH)
+   .Case("hip", TY_HIP)
.Case("hpp", TY_CXXHeader)
.Case("iim", TY_PP_CXXModule)
.Case("lib", TY_Object)
Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -538,24 +538,46 @@
   InputList &Inputs) {
 
   //
-  // CUDA
+  // CUDA/HIP
   //
-  // We need to generate a CUDA toolchain if any of the inputs has a CUDA type.
-  if (llvm::any_of(Inputs, [](std::pair &I) {
+  // We need to generate a CUDA toolchain if any of the inputs has a CUDA
+  // or HIP type. However, mixed CUDA/HIP compilation is not supported.
+  bool IsCuda =
+  llvm::any_of(Inputs, [](std::pair &I) {
 return types::isCuda(I.first);
-  })) {
+  });
+  bool IsHIP =
+  llvm::any_of(Inputs,
+   [](std::pair &I) {
+ return types::isHIP(I.first);
+   }) ||
+  C.getInputArgs().hasArg(options::OPT_hip_link);
+  if (IsCuda && IsHIP) {
+Diag(clang::diag::err_drv_mix_cuda_hip);
+return;
+  }
+  if (IsCuda || IsHIP) {
 const ToolChain *HostTC = C.getSingleOffloadToolChain();
 const llvm::Triple &HostTriple = HostTC->getTriple();
-llvm::Triple CudaTriple(HostTriple.isArch64Bit() ? "nvptx64-nvidia-cuda"
- : "nvptx-nvidia-cuda");
-// Use the CUDA and host triples as the key into the ToolChains map, because
-// the device toolchain we create depends on both.
+StringRef DeviceTripleStr;
+auto OFK = IsHIP ? Action::OFK_HIP : Action::OFK_Cuda;
+if (IsHIP) {
+  // HIP is only supported on amdgcn.
+  DeviceTripleStr = "amdgcn-amd-amdhsa";
+} else {
+  // CUDA is only supported on nvptx.
+  DeviceTripleStr = HostTriple.isArch64Bit() ? "nvptx64-nvidia-cuda"
+ : "nvptx-nvidia-cuda";
+}
+llvm::Triple CudaTriple(DeviceTripleStr);
+// Use the CUDA/HIP and host triples as the key into the ToolChains map,
+// because the device toolchain we create depends on both.
 auto &CudaTC = ToolChains[CudaTriple.str() + "/" + HostTriple.str()];
 if (!CudaTC) {
   CudaTC = llvm::make_unique(
-  *this, CudaTriple, *HostTC, C.getInputArgs(), Action::OFK_Cuda);
+  *this, CudaTriple, *HostTC, C.getInputArgs(), OFK);
 }
-C.addOffloadDeviceToolChain(CudaTC.get(), Action::OFK_Cuda);
+C.addOffloadDeviceToolChain(CudaTC.get(), OFK);
   }
 
   //
Index: include/clang/Driver/Types.h
===
--- include/clang/Driver/Types.h
+++ include/clang/Driver/Types.h
@@ -77,6 +77,9 @@
   /// isCuda - Is this a CUDA input.
   bool isCuda(ID Id);
 
+  /// isHIP - Is this a HIP input.
+  bool isHIP(ID Id);
+
   /// isObjC - Is

[PATCH] D45093: [AST] Fix -ast-print for _Bool when have diagnostics

2018-05-08 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 145711.
jdenny edited the summary of this revision.
jdenny added a comment.

Made the suggested changes.


https://reviews.llvm.org/D45093

Files:
  include/clang/Sema/Sema.h
  lib/Frontend/ASTConsumers.cpp
  lib/Sema/Sema.cpp
  test/Misc/ast-print-bool.c

Index: test/Misc/ast-print-bool.c
===
--- /dev/null
+++ test/Misc/ast-print-bool.c
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -verify -ast-print %s -xc -DDEF_BOOL_CBOOL \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-CBOOL,CBOOL
+//
+// RUN: %clang_cc1 -verify -ast-print %s -xc -DDEF_BOOL_CBOOL -DDIAG \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-CBOOL,CBOOL
+//
+// RUN: %clang_cc1 -verify -ast-print %s -xc -DDEF_BOOL_INT \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-INT,CBOOL
+//
+// RUN: %clang_cc1 -verify -ast-print %s -xc -DDEF_BOOL_INT -DDIAG \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-INT,CBOOL
+//
+// RUN: %clang_cc1 -verify -ast-print %s -xc++ \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-BOOL
+//
+// RUN: %clang_cc1 -verify -ast-print %s -xc++ -DDIAG \
+// RUN: | FileCheck %s --check-prefixes=BOOL-AS-BOOL
+
+#if DEF_BOOL_CBOOL
+# define bool _Bool
+#elif DEF_BOOL_INT
+# define bool int
+#endif
+
+// BOOL-AS-CBOOL: _Bool i;
+// BOOL-AS-INT:   int i;
+// BOOL-AS-BOOL:  bool i;
+bool i;
+
+#ifndef __cplusplus
+// CBOOL: _Bool j;
+_Bool j;
+#endif
+
+// Induce a diagnostic (and verify we actually managed to do so), which used to
+// permanently alter the -ast-print printing policy for _Bool.  How bool is
+// defined by the preprocessor is examined only once per compilation, when the
+// diagnostic is emitted, and it used to affect the entirety of -ast-print, so
+// test only one definition of bool per compilation.
+#if DIAG
+void fn() { 1; } // expected-warning {{expression result unused}}
+#else
+// expected-no-diagnostics
+#endif
Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -52,8 +52,8 @@
 PrintingPolicy Sema::getPrintingPolicy(const ASTContext &Context,
const Preprocessor &PP) {
   PrintingPolicy Policy = Context.getPrintingPolicy();
-  // Our printing policy is copied over the ASTContext printing policy whenever
-  // a diagnostic is emitted, so recompute it.
+  // In diagnostics, we print _Bool as bool if the latter is defined as the
+  // former.
   Policy.Bool = Context.getLangOpts().Bool;
   if (!Policy.Bool) {
 if (const MacroInfo *BoolMacro = PP.getMacroInfo(Context.getBoolName())) {
@@ -1284,7 +1284,8 @@
 }
   }
 
-  // Set up the context's printing policy based on our current state.
+  // Copy the diagnostic printing policy over the ASTContext printing policy.
+  // TODO: Stop doing that.  See: https://reviews.llvm.org/D45093#1090292
   Context.setPrintingPolicy(getPrintingPolicy());
 
   // Emit the diagnostic.
Index: lib/Frontend/ASTConsumers.cpp
===
--- lib/Frontend/ASTConsumers.cpp
+++ lib/Frontend/ASTConsumers.cpp
@@ -87,9 +87,10 @@
 << DC->getPrimaryContext() << "\n";
 } else
   Out << "Not a DeclContext\n";
-  } else if (OutputKind == Print)
-D->print(Out, /*Indentation=*/0, /*PrintInstantiation=*/true);
-  else if (OutputKind != None)
+  } else if (OutputKind == Print) {
+PrintingPolicy Policy(D->getASTContext().getLangOpts());
+D->print(Out, Policy, /*Indentation=*/0, /*PrintInstantiation=*/true);
+  } else if (OutputKind != None)
 D->dump(Out, OutputKind == DumpFull);
 }
 
Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -2111,12 +2111,12 @@
   void checkPartialSpecializationVisibility(SourceLocation Loc,
 NamedDecl *Spec);
 
-  /// \brief Retrieve a suitable printing policy.
+  /// \brief Retrieve a suitable printing policy for diagnostics.
   PrintingPolicy getPrintingPolicy() const {
 return getPrintingPolicy(Context, PP);
   }
 
-  /// \brief Retrieve a suitable printing policy.
+  /// \brief Retrieve a suitable printing policy for diagnostics.
   static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx,
   const Preprocessor &PP);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42933: [Sema] Avoid -Wformat warning for NSInteger/NSUInteger 'int' values with %zu/%zi long specifiers

2018-05-08 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

In https://reviews.llvm.org/D42933#1091234, @aaron.ballman wrote:

> In https://reviews.llvm.org/D42933#1090268, @jfb wrote:
>
> > I was just looking at this, and I think @arphaman's patch is pretty much 
> > the right approach (with 2 suggested fixes below).
> >
> > I don't think the code we're currently warning on is broken: a user code 
> > has `NSInteger` with `%zd` or `NSUInteger` with `%zu`, and on all platforms 
> > which support those types the implementor has guaranteed that 
> > `(sizeof(size_t) == sizeof(NSInteger)) && (sizeof(ssize_t) == 
> > sizeof(NSUInteger))`.
>
>
> Yes, but is this guaranteed to be the case or does it happen to be the case? 
> I'm worried about the less mainstream uses where you might find ObjC code 
> where this does not hold but -Wformat points out a portability concern.


For Darwin platform, yes. That's why this diagnostic should only be squelched 
for Darwin platforms.

>> However the implementation provided more guarantees than C++ does through 
>> its platform typedefs so pendantry need not apply (or rather: clang should 
>> look no further than the typedef, and trust the platform in this particular 
>> case).
>> 
>> We of course should still warn on sign mismatch.
>> 
>> I don't think this should even be a warning with pedantic on: there's no 
>> portability issue at all because all OSes and architectures where this could 
>> ever fire are guaranteed to do the right thing.
> 
> Can you point me to this guarantee, as I was unable to find one (but that 
> doesn't mean it doesn't exist)?

Once this patch is committed I'll update the corresponding documentation on 
developer.apple.com

In https://reviews.llvm.org/D42933#1091411, @smeenai wrote:

> In https://reviews.llvm.org/D42933#1091234, @aaron.ballman wrote:
>
> > In https://reviews.llvm.org/D42933#1090268, @jfb wrote:
> >
> > > I was just looking at this, and I think @arphaman's patch is pretty much 
> > > the right approach (with 2 suggested fixes below).
> > >
> > > I don't think the code we're currently warning on is broken: a user code 
> > > has `NSInteger` with `%zd` or `NSUInteger` with `%zu`, and on all 
> > > platforms which support those types the implementor has guaranteed that 
> > > `(sizeof(size_t) == sizeof(NSInteger)) && (sizeof(ssize_t) == 
> > > sizeof(NSUInteger))`.
> >
> >
> > Yes, but is this guaranteed to be the case or does it happen to be the 
> > case? I'm worried about the less mainstream uses where you might find ObjC 
> > code where this does not hold but -Wformat points out a portability concern.
>
>
> Also keep in mind that Obj-C might be used on non-Apple platforms, e.g. 
> there's an active review going on for GNUstep ABI v2 right now 
> (https://reviews.llvm.org/D46052), and WinObjC is also a thing. Those 
> platforms might not necessarily provide the same guarantees or consistency 
> that Apple's do.


Indeed, I want to make sure that this change only affects Darwin platforms.

>>> I agree that, if we're playing C++ pedant and look at the typedefs, then 
>>> it's undefined behavior and the code is broken.
>> 
>> This is reason alone to diagnose the code, because the optimizer is welcome 
>> to use that UB to perform transformations the programmer did not expect. 
>> However, I'm not certain our optimizer is currently paying attention to that 
>> UB directly, so this may not be an immediate issue (but could be a pitfall 
>> for the future) but I'm not certain about other optimizers for which 
>> portability would still be a concern.
> 
> I would honestly find it a bit surprising (and scary) if the optimizer 
> actually took advantage of UB in the case where the size and alignment of the 
> specifier and the actual type matches.

Hear, hear! I'm happy to fix any such optimization out of their misguided 
optimism :-)


Repository:
  rC Clang

https://reviews.llvm.org/D42933



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


[PATCH] D44435: CUDA ctor/dtor Module-Unique Symbol Name

2018-05-08 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

Great! Let's close this review then.
And good luck with cling.


https://reviews.llvm.org/D44435



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


[PATCH] D46541: [CodeGen] Improve diagnostics related to target attributes

2018-05-08 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: lib/CodeGen/CodeGenFunction.cpp:2342
   // Only positive features are "required".
-  if (F.getValue())
+  if (F.getValue()) {
+if (std::any_of(ParsedAttr.Features.begin(), ParsedAttr.Features.end(),

Rather than walking the ParsedAttr.Features for each feature in the map. And 
having to shift the ReqFeatures vectors sometimes. How about doing this

-Walk through all features in ParsedAttr, for each feature with a +, query the 
callee feature map. If it's enabled there, push it to ReqFeatures.
-Walk through all features in the callee feature map and if enabled push those.

This will lead to duplicates in the list, but all the explicitly mentioned 
features will be listed first.


https://reviews.llvm.org/D46541



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


[PATCH] D46320: Remove \brief commands from doxygen comments.

2018-05-08 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm! (Back from a week long vacation)


https://reviews.llvm.org/D46320



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


[PATCH] D46540: [X86] ptwrite intrinsic

2018-05-08 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

Could you maybe add some short summaries to your patches? It's hard for 
non-Intel employees to guess what all these instructions do...


https://reviews.llvm.org/D46540



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


[PATCH] D46241: [CodeGen] Recognize more cases of zero initialization

2018-05-08 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 145735.
sepavloff added a comment.

Added treatment of structures/unions


Repository:
  rC Clang

https://reviews.llvm.org/D46241

Files:
  include/clang/AST/Expr.h
  lib/AST/ExprConstant.cpp
  lib/CodeGen/CGExprConstant.cpp
  test/CodeGen/const-init.c
  test/CodeGen/designated-initializers.c
  test/CodeGen/union-init2.c
  test/CodeGenCXX/cxx11-initializer-aggregate.cpp
  test/CodeGenCXX/cxx1z-initializer-aggregate.cpp
  test/SemaCXX/large-array-init.cpp

Index: test/SemaCXX/large-array-init.cpp
===
--- test/SemaCXX/large-array-init.cpp
+++ /dev/null
@@ -1,10 +0,0 @@
-// RUN: %clang_cc1 -S -o %t.ll -mllvm -debug-only=exprconstant %s 2>&1 | \
-// RUN: FileCheck %s
-// REQUIRES: asserts
-
-struct S { int i; };
-
-static struct S arr[1] = {{ 0 }};
-// CHECK: The number of elements to initialize: 1.
-
-struct S *foo() { return arr; }
Index: test/CodeGenCXX/cxx1z-initializer-aggregate.cpp
===
--- test/CodeGenCXX/cxx1z-initializer-aggregate.cpp
+++ test/CodeGenCXX/cxx1z-initializer-aggregate.cpp
@@ -17,14 +17,14 @@
 
   C c1 = {};
   C c2 = {1};
-  // CHECK: @_ZN8Constant2c1E = global { i8 } zeroinitializer, align 1
+  // CHECK: @_ZN8Constant2c1E = global %"struct.Constant::C" zeroinitializer, align 1
   // CHECK: @_ZN8Constant2c2E = global { i8 } { i8 1 }, align 1
 
   // Test packing bases into tail padding.
   D d1 = {};
   D d2 = {1, 2, 3};
   D d3 = {1};
-  // CHECK: @_ZN8Constant2d1E = global { i32, i8, i8 } zeroinitializer, align 4
+  // CHECK: @_ZN8Constant2d1E = global %"struct.Constant::D" zeroinitializer, align 4
   // CHECK: @_ZN8Constant2d2E = global { i32, i8, i8 } { i32 1, i8 2, i8 3 }, align 4
   // CHECK: @_ZN8Constant2d3E = global { i32, i8, i8 } { i32 1, i8 0, i8 0 }, align 4
 
Index: test/CodeGenCXX/cxx11-initializer-aggregate.cpp
===
--- test/CodeGenCXX/cxx11-initializer-aggregate.cpp
+++ test/CodeGenCXX/cxx11-initializer-aggregate.cpp
@@ -51,3 +51,30 @@
   // meaningful.
   B b[30] = {};
 }
+
+namespace ZeroInit {
+  enum { Zero, One };
+  constexpr int zero() { return 0; }
+  constexpr int *null() { return nullptr; }
+  struct Filler {
+int x;
+Filler();
+  };
+  struct S1 {
+int x;
+  };
+
+  // These declarations, if implemented elementwise, require huge
+  // amout of memory and compiler time.
+  unsigned char data_1[1024 * 1024 * 1024 * 2u] = { 0 };
+  unsigned char data_2[1024 * 1024 * 1024 * 2u] = { Zero };
+  unsigned char data_3[1024][1024][1024] = {{{0}}};
+  unsigned char data_4[1024 * 1024 * 1024 * 2u] = { zero() };
+  int *data_5[1024 * 1024 * 512] = { nullptr };
+  int *data_6[1024 * 1024 * 512] = { null() };
+  struct S1 data_7[1024 * 1024 * 512] = {{0}};
+
+  // This variable must be initialized elementwise.
+  Filler data_e1[1024] = {};
+  // CHECK: getelementptr inbounds {{.*}} @_ZN8ZeroInit7data_e1E
+}
Index: test/CodeGen/union-init2.c
===
--- test/CodeGen/union-init2.c
+++ test/CodeGen/union-init2.c
@@ -5,7 +5,7 @@
 union x {long long b;union x* a;} r = {.a = &r};
 
 
-// CHECK: global { [3 x i8], [5 x i8] } { [3 x i8] zeroinitializer, [5 x i8] undef }
+// CHECK: global %union.z zeroinitializer
 union z {
   char a[3];
   long long b;
Index: test/CodeGen/designated-initializers.c
===
--- test/CodeGen/designated-initializers.c
+++ test/CodeGen/designated-initializers.c
@@ -8,7 +8,7 @@
 // CHECK: @u = global %union.anon zeroinitializer
 union { int i; float f; } u = { };
 
-// CHECK: @u2 = global { i32, [4 x i8] } { i32 0, [4 x i8] undef }
+// CHECK: @u2 = global %union.anon.0 zeroinitializer
 union { int i; double f; } u2 = { };
 
 // CHECK: @u3 = global  %union.anon.1 zeroinitializer
Index: test/CodeGen/const-init.c
===
--- test/CodeGen/const-init.c
+++ test/CodeGen/const-init.c
@@ -167,7 +167,7 @@
 int : 1;
 int x;
   } a = {};
-  // CHECK: @g30.a = internal global %struct.anon.1 <{ i8 undef, i32 0 }>, align 1
+  // CHECK: @g30.a = internal global %struct.anon.1 zeroinitializer, align 1
 #pragma pack()
 }
 
Index: lib/CodeGen/CGExprConstant.cpp
===
--- lib/CodeGen/CGExprConstant.cpp
+++ lib/CodeGen/CGExprConstant.cpp
@@ -1392,20 +1392,37 @@
   return type;
 }
 
+/// Checks if the specified initializer is equivalent to zero initialization.
+static bool isZeroInitializer(ConstantEmitter &CE, const Expr *Init) {
+  if (auto *E = dyn_cast_or_null(Init)) {
+CXXConstructorDecl *CD = E->getConstructor();
+return CD->isDefaultConstructor() && CD->isTrivial();
+  }
+
+  if (auto *IL = dyn_cast_or_null(Init)) {
+for (auto I : IL->inits())
+  if (!isZero

[PATCH] D46241: [CodeGen] Recognize more cases of zero initialization

2018-05-08 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

> Hmm. In C++, a static object which isn't constant-initialized is 
> zero-initialized, which is required to set any padding bits to zero (N4640 
> [dcl.init]p6) in both structs and unions. In C, a static object which doesn't 
> have an initializer also has all any padding bits set to zero (N1548 
> 6.7.9p10). Now, this object has an initializer (that acts as a 
> constant-initializer in C++), so those rules don't directly apply; but I 
> would argue that the intent of the standards is not that padding bits become 
> undefined when you happen to have an initializer. So I actually think the 
> zeroinitializer emission is more correct.

Using undefined values instead of zero initialization was implemented in 
https://reviews.llvm.org/rL101535. There is no much info about the reason of 
the implementation. Clang uses undefined values for padding bits, in particular 
in unions, when the first member is not widest. The code:

  union C1 {
  char sel;
  double dval;
};
union C1 val_1 = { 0 };

produces:

  @val_1 = dso_local global { i8, [7 x i8] } { i8 0, [7 x i8] undef }, align 8  

Another case is unnamed bit fields.

struct C2 {
  int : 4;
  int x;
};
struct C2 val_2 = { 0 };

produces:

  @val_2 = dso_local global { [4 x i8], i32 } { [4 x i8] undef, i32 0 }, align 4

Strictly speaking, this IR does not mean violation of the standard, but it can 
modify code generation in some cases. If we decided to use zeroinitializer in 
this case, we probably would need to revise using undefined values in 
initializers, otherwise similar declarations like:

union C1 val_1a = { 0 };
union C1 val_1b = { 1 };

would produce different IR representations, with and without undefined values.

The test `SemaCXX/large-array-init.cpp` is removed in this change. This test 
was added in https://reviews.llvm.org/rL325120 to solve 
https://bugs.llvm.org/show_bug.cgi?id=18978, which describes the same problem, 
as solved by this patch. This patch presents more efficient solution, with it 
the tests compiles 50 time faster. If r325120 does not solve additional 
problems, it can be reverted.


Repository:
  rC Clang

https://reviews.llvm.org/D46241



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


r331786 - [lit] Fix running tests that require 'examples'.

2018-05-08 Thread Zachary Turner via cfe-commits
Author: zturner
Date: Tue May  8 11:20:10 2018
New Revision: 331786

URL: http://llvm.org/viewvc/llvm-project?rev=331786&view=rev
Log:
[lit] Fix running tests that require 'examples'.

Differential Revision: https://reviews.llvm.org/D46514
Patch by Nikolai Kosjar.

Modified:
cfe/trunk/test/lit.cfg.py

Modified: cfe/trunk/test/lit.cfg.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/lit.cfg.py?rev=331786&r1=331785&r2=331786&view=diff
==
--- cfe/trunk/test/lit.cfg.py (original)
+++ cfe/trunk/test/lit.cfg.py Tue May  8 11:20:10 2018
@@ -63,6 +63,7 @@ tools = [
 ]
 
 if config.clang_examples:
+config.available_features.add('examples')
 tools.append('clang-interpreter')
 
 llvm_config.add_tool_substitutions(tools, tool_dirs)


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


[PATCH] D46593: Allow copy elision in path concatenation

2018-05-08 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 updated this revision to Diff 145740.
Herald added a subscriber: cfe-commits.

Repository:
  rCXX libc++

https://reviews.llvm.org/D46593

Files:
  include/experimental/filesystem


Index: include/experimental/filesystem
===
--- include/experimental/filesystem
+++ include/experimental/filesystem
@@ -1140,7 +1140,9 @@
 
 inline _LIBCPP_INLINE_VISIBILITY
 path operator/(const path& __lhs, const path& __rhs) {
-return path(__lhs) /= __rhs;
+path __result(__lhs);
+__result /= __rhs;
+return __result;
 }
 
 template 


Index: include/experimental/filesystem
===
--- include/experimental/filesystem
+++ include/experimental/filesystem
@@ -1140,7 +1140,9 @@
 
 inline _LIBCPP_INLINE_VISIBILITY
 path operator/(const path& __lhs, const path& __rhs) {
-return path(__lhs) /= __rhs;
+path __result(__lhs);
+__result /= __rhs;
+return __result;
 }
 
 template 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46593: Allow copy elision in path concatenation

2018-05-08 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 updated this revision to Diff 145742.
Herald added a subscriber: christof.

https://reviews.llvm.org/D46593

Files:
  libcxx/trunk/include/experimental/filesystem


Index: libcxx/trunk/include/experimental/filesystem
===
--- libcxx/trunk/include/experimental/filesystem
+++ libcxx/trunk/include/experimental/filesystem
@@ -1140,7 +1140,9 @@
 
 inline _LIBCPP_INLINE_VISIBILITY
 path operator/(const path& __lhs, const path& __rhs) {
-return path(__lhs) /= __rhs;
+path __result(__lhs);
+__result /= __rhs;
+return __result;
 }
 
 template 


Index: libcxx/trunk/include/experimental/filesystem
===
--- libcxx/trunk/include/experimental/filesystem
+++ libcxx/trunk/include/experimental/filesystem
@@ -1140,7 +1140,9 @@
 
 inline _LIBCPP_INLINE_VISIBILITY
 path operator/(const path& __lhs, const path& __rhs) {
-return path(__lhs) /= __rhs;
+path __result(__lhs);
+__result /= __rhs;
+return __result;
 }
 
 template 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46593: Allow copy elision in path concatenation

2018-05-08 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 updated this revision to Diff 145745.
xbolva00 added a comment.

Can anybody give me advice from where to generate patch? I do it from libcxx.


https://reviews.llvm.org/D46593

Files:
  include/experimental/filesystem


Index: include/experimental/filesystem
===
--- include/experimental/filesystem
+++ include/experimental/filesystem
@@ -1140,7 +1140,9 @@
 
 inline _LIBCPP_INLINE_VISIBILITY
 path operator/(const path& __lhs, const path& __rhs) {
-return path(__lhs) /= __rhs;
+path __result(__lhs);
+__result /= __rhs;
+return __result;
 }
 
 template 


Index: include/experimental/filesystem
===
--- include/experimental/filesystem
+++ include/experimental/filesystem
@@ -1140,7 +1140,9 @@
 
 inline _LIBCPP_INLINE_VISIBILITY
 path operator/(const path& __lhs, const path& __rhs) {
-return path(__lhs) /= __rhs;
+path __result(__lhs);
+__result /= __rhs;
+return __result;
 }
 
 template 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46593: Allow copy elision in path concatenation

2018-05-08 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

Generating the patch from libc++ is fine (and this patch looks like it has sane 
paths).


https://reviews.llvm.org/D46593



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


[PATCH] D46593: Allow copy elision in path concatenation

2018-05-08 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

In https://reviews.llvm.org/D46593#1091732, @smeenai wrote:

> Generating the patch from libc++ is fine (and this patch looks like it has 
> sane paths).


Thank you


https://reviews.llvm.org/D46593



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


[PATCH] D46471: [HIP] Add hip offload kind

2018-05-08 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.

Small nit. LGTM otherwise.




Comment at: lib/Driver/ToolChains/Clang.cpp:133-135
 Work(*C.getSingleOffloadToolChain());
 
+  if (JA.isHostOffloading(Action::OFK_HIP))

CUDA and HIP are mutually exclusive, so this should probably be `else if`


https://reviews.llvm.org/D46471



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


[PATCH] D46535: Correct warning on Float->Integer conversions.

2018-05-08 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

The check for whether an input is "out of range" doesn't handle fractions 
correctly.  Testcase:

  int a() { return 2147483647.5; }
  unsigned b() { return -.5; }


Repository:
  rC Clang

https://reviews.llvm.org/D46535



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


[PATCH] D42933: [Sema] Avoid -Wformat warning for NSInteger/NSUInteger 'int' values with %zu/%zi long specifiers

2018-05-08 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

In https://reviews.llvm.org/D42933#1090384, @jfb wrote:

> In https://reviews.llvm.org/D42933#1090286, @smeenai wrote:
>
> > I'd be fine with adding an option to relax the printf checking if the size 
> > and alignment of the specifier and the actual type match, even if the types 
> > themselves differ (`-Wformat-relaxed` or something similar), so that you'd 
> > still get warnings on cases where the specifier mismatch could cause 
> > runtime issues.
>
>
> What are the cases that you're worried about? The only ones I'm trying to 
> capture here are `NSInteger` with `%zd` and `NSUInteger` with `%zu`, are 
> there others?
>
> > I think that would be preferable to special-casing the Apple types.
>
> If there are more that should be captured and a similar point solution 
> doesn't apply, agreed. However I'd like to understand if we agree on the 
> guarantees that the platform offers for the two specific cases I'm targeting.


I also think that special casing these two specifiers doesn't make sense. The 
problem is a general issue -- and one I've often found irritating. This exact 
same situation comes up all the time in non-Darwin contexts too.

E.g. one I find particularly annoying is "%lld" vs "%ld" in printf.

Some 64-bit platforms define e.g. `int64_t` as `long long`, and others as 
`long`. Although both types are size 8, align 8, and mean exactly the same 
thing, they are still distinct. And so, users write code like `int64_t x = 0; 
printf("%ld", x);`...which then emits warnings on the platform that defines 
int64_t as a `long long`. Obviously, the code _could_ be using `PRId64` 
instead...but it often doesn't. So it'd sure be nice if you could restrict the 
warning to only warn about actual problems, and suppress these 
superficially-incompatible-but-not-really warnings.

So, +1 from me for the general-purpose `-Wformat-relaxed` flag (or whatever 
other flag name is appropriate).


Repository:
  rC Clang

https://reviews.llvm.org/D42933



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


[PATCH] D46349: [X86] Mark builtins 'const' where possible

2018-05-08 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Ping


https://reviews.llvm.org/D46349



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


[PATCH] D42933: [Sema] Avoid -Wformat warning for NSInteger/NSUInteger 'int' values with %zu/%zi long specifiers

2018-05-08 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

In https://reviews.llvm.org/D42933#1091809, @jyknight wrote:

> I also think that special casing these two specifiers doesn't make sense. The 
> problem is a general issue -- and one I've often found irritating. This exact 
> same situation comes up all the time in non-Darwin contexts too.


I don't think that's true. In this very specific case the platform guarantees 
that `(sizeof(size_t) == sizeof(NSInteger)) && (sizeof(ssize_t) == 
sizeof(NSUInteger))` for all architectures this platform supports. This exact 
same situation does not come up all the time in other contexts because the 
`int` / `long` / `long long` distinction isn't backed by a portability 
guarantee. The warning is there to say "this code isn't portable!", but in the 
very specific case of `NSInteger` and `NSUInteger` it is and users rely on it 
so it cannot be broken. The warning is therefore spurious, users therefore 
rightly complain.


Repository:
  rC Clang

https://reviews.llvm.org/D42933



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


[PATCH] D42933: [Sema] Avoid -Wformat warning for NSInteger/NSUInteger 'int' values with %zu/%zi long specifiers

2018-05-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: rjmccall.
aaron.ballman added a subscriber: rjmccall.
aaron.ballman added a comment.

In https://reviews.llvm.org/D42933#1091502, @jfb wrote:

> In https://reviews.llvm.org/D42933#1091234, @aaron.ballman wrote:
>
> > In https://reviews.llvm.org/D42933#1090268, @jfb wrote:
> >
> > > I was just looking at this, and I think @arphaman's patch is pretty much 
> > > the right approach (with 2 suggested fixes below).
> > >
> > > I don't think the code we're currently warning on is broken: a user code 
> > > has `NSInteger` with `%zd` or `NSUInteger` with `%zu`, and on all 
> > > platforms which support those types the implementor has guaranteed that 
> > > `(sizeof(size_t) == sizeof(NSInteger)) && (sizeof(ssize_t) == 
> > > sizeof(NSUInteger))`.
> >
> >
> > Yes, but is this guaranteed to be the case or does it happen to be the 
> > case? I'm worried about the less mainstream uses where you might find ObjC 
> > code where this does not hold but -Wformat points out a portability concern.
>
>
> For Darwin platform, yes. That's why this diagnostic should only be squelched 
> for Darwin platforms.


Ah, I missed the fact that you were proposing this only for Darwin.

 I agree that, if we're playing C++ pedant and look at the typedefs, then 
 it's undefined behavior and the code is broken.
>>> 
>>> This is reason alone to diagnose the code, because the optimizer is welcome 
>>> to use that UB to perform transformations the programmer did not expect. 
>>> However, I'm not certain our optimizer is currently paying attention to 
>>> that UB directly, so this may not be an immediate issue (but could be a 
>>> pitfall for the future) but I'm not certain about other optimizers for 
>>> which portability would still be a concern.
>> 
>> I would honestly find it a bit surprising (and scary) if the optimizer 
>> actually took advantage of UB in the case where the size and alignment of 
>> the specifier and the actual type matches.
> 
> Hear, hear! I'm happy to fix any such optimization out of their misguided 
> optimism :-)

People used to think the same thing about many other optimizations that had 
non-local effects, but we've come to learn that these are not uncommon and 
incredibly hard for users to track down when it happens. Some enterprising soul 
could lower the call with an undef on the wrongly-typed argument and then who 
knows what happens. However, it's also reasonable for us to define undefined 
behavior for a given platform and that sounds like exactly this case.

If we're looking at only a specific change for Darwin, I think it's reasonable 
to make it to `-Wformat` rather than require `-Wformat-relaxed` (though we may 
still want to assert that the size and alignment of the underlying type match 
expectations).

I've added @rjmccall as a reviewer to see what his opinions are on this, but 
I'm inclined to say this is a reasonable change to make for Darwin targets.


Repository:
  rC Clang

https://reviews.llvm.org/D42933



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


[PATCH] D45517: [analyzer] WIP: False positive refutation with Z3

2018-05-08 Thread Reka Kovacs via Phabricator via cfe-commits
rnkovacs updated this revision to Diff 145762.
rnkovacs marked 4 inline comments as done.
rnkovacs edited the summary of this revision.
rnkovacs added a comment.

Expression chaining is fixed. The visitor now collects constraints that are 
about to disappear along the bug path and checks them once in the end.


https://reviews.llvm.org/D45517

Files:
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
  include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
  include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  lib/StaticAnalyzer/Core/BugReporter.cpp
  lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  lib/StaticAnalyzer/Core/ProgramState.cpp
  lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp

Index: lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
===
--- lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
+++ lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
@@ -7,6 +7,7 @@
 //
 //===--===//
 
+#include "RangedConstraintManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
@@ -915,6 +916,13 @@
   void print(ProgramStateRef St, raw_ostream &Out, const char *nl,
  const char *sep) override;
 
+  void reset() override;
+
+  bool isModelFeasible() override;
+
+  void addRangeConstraints(ConstraintRangeTy PrevCR, ConstraintRangeTy SuccCR,
+   bool OnlyPurged) override;
+
   //===--===//
   // Implementation for interface from SimpleConstraintManager.
   //===--===//
@@ -1235,6 +1243,57 @@
   return State->set(CZ);
 }
 
+void Z3ConstraintManager::reset() { Solver.reset(); }
+
+bool Z3ConstraintManager::isModelFeasible() {
+  return Solver.check() != Z3_L_FALSE;
+}
+
+void Z3ConstraintManager::addRangeConstraints(ConstraintRangeTy PrevCR,
+  ConstraintRangeTy SuccCR,
+  bool OnlyPurged) {
+  if (OnlyPurged && PrevCR.isEmpty())
+return;
+  if (!OnlyPurged && SuccCR.isEmpty())
+return;
+  ConstraintRangeTy CR = OnlyPurged ? PrevCR : SuccCR;
+
+  for (ConstraintRangeTy::iterator I = CR.begin(), E = CR.end(); I != E; ++I) {
+SymbolRef Sym = I.getKey();
+
+if (OnlyPurged && SuccCR.contains(Sym))
+  continue;
+
+Z3Expr Constraints = Z3Expr::fromBoolean(false);
+
+for (const auto &Range : I.getData()) {
+  const llvm::APSInt &From = Range.From();
+  const llvm::APSInt &To = Range.To();
+
+  assert((getAPSIntType(From) == getAPSIntType(To)) &&
+ "Range values have different types!");
+  QualType RangeTy = getAPSIntType(From);
+  // Skip ranges whose endpoints cannot be converted to APSInts with
+  // a valid APSIntType.
+  if (RangeTy.isNull())
+continue;
+
+  QualType SymTy;
+  Z3Expr Exp = getZ3Expr(Sym, &SymTy);
+  bool IsSignedTy = SymTy->isSignedIntegerOrEnumerationType();
+
+  Z3Expr FromExp = Z3Expr::fromAPSInt(From);
+  Z3Expr ToExp = Z3Expr::fromAPSInt(To);
+
+  Z3Expr LHS = getZ3BinExpr(Exp, SymTy, BO_GE, FromExp, RangeTy, nullptr);
+  Z3Expr RHS = getZ3BinExpr(Exp, SymTy, BO_LE, ToExp, RangeTy, nullptr);
+  Z3Expr SymRange = Z3Expr::fromBinOp(LHS, BO_LAnd, RHS, IsSignedTy);
+  Constraints = Z3Expr::fromBinOp(Constraints, BO_LOr, SymRange, IsSignedTy);
+}
+Solver.addConstraint(Constraints);
+  }
+}
+
 //===--===//
 // Internal implementation.
 //===--===//
Index: lib/StaticAnalyzer/Core/ProgramState.cpp
===
--- lib/StaticAnalyzer/Core/ProgramState.cpp
+++ lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -13,6 +13,8 @@
 
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
 #include "clang/Analysis/CFG.h"
+#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h"
@@ -78,6 +80,10 @@
 CallEventMgr(new CallEventManager(alloc)), Alloc(alloc) {
   StoreMgr = (*CreateSMgr)(*this);
   ConstraintMgr = (*CreateCMgr)(*this, SubEng);
+  AnalyzerOptions &Opts = SubEng->getAnalysisManager().getAnalyzerOptions();
+  RefutationMgr = Opts.shouldCrosscheckWithZ3()
+  ? CreateZ3ConstraintManager(*thi

[PATCH] D45517: [analyzer] WIP: False positive refutation with Z3

2018-05-08 Thread Reka Kovacs via Phabricator via cfe-commits
rnkovacs added inline comments.



Comment at: lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:2342
+BugReport &BR) {
+  if (isInvalidated)
+return nullptr;

george.karpenkov wrote:
> Is this field actually necessary? Do we ever check the same bug report with 
> the same visitor multiple times?
I believe this function is called for each node on the bug path. I have a 
similar field to indicate the first visited node in the new version, but there 
may exist a better solution for that as well.



Comment at: lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:2351
+
+  if (!RefutationMgr.checkRangedStateConstraints(Succ->getState())) {
+const LocationContext *LC = Succ->getLocationContext();

george.karpenkov wrote:
> For the initial version I would just do all work in the visitor, but that's a 
> matter of taste.
I think that doing all the work in the visitor would need exposing even more of 
`Z3ConstraintManager`'s internals as of `RangedConstraintManager`. I tried to 
keep such changes minimal.



Comment at: lib/StaticAnalyzer/Core/ProgramState.cpp:86
+  ? CreateZ3ConstraintManager(*this, SubEng)
+  : nullptr;
 }

george.karpenkov wrote:
> Would then we crash on NPE if `getRefutationManager` is called? Getters 
> should preferably not cause crashes.
Um, currently yes, it will give a backend error if clang isn't built with Z3, 
but the option is on.


https://reviews.llvm.org/D45517



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


[PATCH] D46535: Correct warning on Float->Integer conversions.

2018-05-08 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In https://reviews.llvm.org/D46535#1091787, @efriedma wrote:

> The check for whether an input is "out of range" doesn't handle fractions 
> correctly.  Testcase:
>
>   int a() { return 2147483647.5; }
>   unsigned b() { return -.5; }
>


Hrm... For some reaosn I had it in my head that both of those were UB...  
Interestingly, EDG/ICC thinks the second one is.  I'll look into this more to 
see if I can refine the warning.


Repository:
  rC Clang

https://reviews.llvm.org/D46535



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


[PATCH] D46475: [HIP] Set proper triple and offload kind for the toolchain

2018-05-08 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Thanks, LGTM.


https://reviews.llvm.org/D46475



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


[PATCH] D46471: [HIP] Add hip offload kind

2018-05-08 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added inline comments.



Comment at: lib/Driver/ToolChains/Clang.cpp:133-135
 Work(*C.getSingleOffloadToolChain());
 
+  if (JA.isHostOffloading(Action::OFK_HIP))

tra wrote:
> CUDA and HIP are mutually exclusive, so this should probably be `else if`
Will do when committing.


https://reviews.llvm.org/D46471



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


[clang-tools-extra] r331805 - Fix Wdocumentation warning. NFCI.

2018-05-08 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Tue May  8 13:24:45 2018
New Revision: 331805

URL: http://llvm.org/viewvc/llvm-project?rev=331805&view=rev
Log:
Fix Wdocumentation warning. NFCI.

Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidy.h

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.h?rev=331805&r1=331804&r2=331805&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.h Tue May  8 13:24:45 2018
@@ -222,8 +222,8 @@ ClangTidyOptions::OptionMap getCheckOpti
 
 /// \brief Run a set of clang-tidy checks on a set of files.
 ///
-/// \param Profile if provided, it enables check profile collection in
-/// MatchFinder, and will contain the result of the profile.
+/// \param EnableCheckProfile If provided, it enables check profile collection
+/// in MatchFinder, and will contain the result of the profile.
 void runClangTidy(clang::tidy::ClangTidyContext &Context,
   const tooling::CompilationDatabase &Compilations,
   ArrayRef InputFiles,


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


[PATCH] D46386: Adding __atomic_fetch_min/max intrinsics to clang

2018-05-08 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: docs/LanguageExtensions.rst:1998
+``__ATOMIC_CONSUME``, ``__ATOMIC_ACQUIRE``, ``__ATOMIC_RELEASE``,
+``__ATOMIC_ACQ_REL``, or ``__ATOMIC_SEQ_CST`` following C++11 memory model 
semantics.
+

Thank you for adding this documentation.  Please do clarify what the memory 
ordering semantics actually are when the atomic object does not need to be 
updated, though, and verify that target code generation actually obeys that 
ordering.  For example, if the memory ordering makes this a release operation, 
`__atomic_fetch_min` must always store the result back to the atomic object, 
even if the new value was actually greater than the stored value; I believe 
that would not be required with a relaxed operation.


Repository:
  rC Clang

https://reviews.llvm.org/D46386



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


[PATCH] D46349: [X86] Mark builtins 'const' where possible

2018-05-08 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.

I'm pretty sure this has zero visible effect, but I guess it makes sense as 
documentation.  LGTM.


https://reviews.llvm.org/D46349



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


[PATCH] D46601: [OpenCL] Fix typos in emitted enqueue kernel function names

2018-05-08 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: Anastasia, b-sumner.

Two typos: 
vaarg => vararg
get_kernel_preferred_work_group_multiple => 
get_kernel_preferred_work_group_size_multiple


https://reviews.llvm.org/D46601

Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGenOpenCL/cl20-device-side-enqueue.cl

Index: test/CodeGenOpenCL/cl20-device-side-enqueue.cl
===
--- test/CodeGenOpenCL/cl20-device-side-enqueue.cl
+++ test/CodeGenOpenCL/cl20-device-side-enqueue.cl
@@ -88,7 +88,7 @@
   // B64: %[[TMP:.*]] = alloca [1 x i64]
   // B64: %[[TMP1:.*]] = getelementptr [1 x i64], [1 x i64]* %[[TMP]], i32 0, i32 0
   // B64: store i64 256, i64* %[[TMP1]], align 8
-  // COMMON-LABEL: call i32 @__enqueue_kernel_vaargs(
+  // COMMON-LABEL: call i32 @__enqueue_kernel_varargs(
   // COMMON-SAME: %opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{([0-9]+)?}},
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK1:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*),
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG1]] to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1,
@@ -109,7 +109,7 @@
   // B64: %[[TMP:.*]] = alloca [1 x i64]
   // B64: %[[TMP1:.*]] = getelementptr [1 x i64], [1 x i64]* %[[TMP]], i32 0, i32 0
   // B64: store i64 %{{.*}}, i64* %[[TMP1]], align 8
-  // COMMON-LABEL: call i32 @__enqueue_kernel_vaargs(
+  // COMMON-LABEL: call i32 @__enqueue_kernel_varargs(
   // COMMON-SAME: %opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{([0-9]+)?}},
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK2:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*),
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG2]] to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1,
@@ -133,7 +133,7 @@
   // B64: %[[TMP:.*]] = alloca [1 x i64]
   // B64: %[[TMP1:.*]] = getelementptr [1 x i64], [1 x i64]* %[[TMP]], i32 0, i32 0
   // B64: store i64 256, i64* %[[TMP1]], align 8
-  // COMMON-LABEL: call i32 @__enqueue_kernel_events_vaargs
+  // COMMON-LABEL: call i32 @__enqueue_kernel_events_varargs
   // COMMON-SAME: (%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]],  %struct.ndrange_t* {{.*}}, i32 2, %opencl.clk_event_t{{.*}} [[WAIT_EVNT]], %opencl.clk_event_t{{.*}} [[EVNT]],
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK3:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*),
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG3]] to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1,
@@ -157,7 +157,7 @@
   // B64: %[[TMP:.*]] = alloca [1 x i64]
   // B64: %[[TMP1:.*]] = getelementptr [1 x i64], [1 x i64]* %[[TMP]], i32 0, i32 0
   // B64: store i64 %{{.*}}, i64* %[[TMP1]], align 8
-  // COMMON-LABEL: call i32 @__enqueue_kernel_events_vaargs
+  // COMMON-LABEL: call i32 @__enqueue_kernel_events_varargs
   // COMMON-SAME: (%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]],  %struct.ndrange_t* {{.*}}, i32 2, %opencl.clk_event_t{{.*}}* addrspace(4)* [[WAIT_EVNT]], %opencl.clk_event_t{{.*}}* addrspace(4)* [[EVNT]],
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK4:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*),
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG4]] to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1,
@@ -179,7 +179,7 @@
   // B64: %[[TMP:.*]] = alloca [1 x i64]
   // B64: %[[TMP1:.*]] = getelementptr [1 x i64], [1 x i64]* %[[TMP]], i32 0, i32 0
   // B64: store i64 %{{.*}}, i64* %[[TMP1]], align 8
-  // COMMON-LABEL: call i32 @__enqueue_kernel_vaargs
+  // COMMON-LABEL: call i32 @__enqueue_kernel_varargs
   // COMMON-SAME: (%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{([0-9]+)?}},
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK5:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*),
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG5]] to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1,
@@ -208,7 +208,7 @@
   // B64: store i64 2, i64* %[[TMP2]], align 8
   // B64: %[[TMP3:.*]] = getelementptr [3 x i64], [3 x i64]* %[[TMP]], i32 0, i32 2
   // B64: store i64 4, i64* %[[TMP3]], align 8
-  // COMMON-LABEL: call i32 @__enqueue_kernel_vaargs
+  // COMMON-LABEL: call i32 @__enqueue_kernel_varargs
   // COMMON-SAME: (%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{([0-9]+)?}},
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK6:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*),
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BLG6]] to i8 addrspace(1)*) to i8 addrspace(4)*), i32 3,
@@ -229,7 +229,7 @@

[PATCH] D46601: [OpenCL] Fix typos in emitted enqueue kernel function names

2018-05-08 Thread Brian Sumner via Phabricator via cfe-commits
b-sumner added a comment.

Thanks!  Looks good to me.


https://reviews.llvm.org/D46601



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


r331806 - Change -foutline to -moutline

2018-05-08 Thread Jessica Paquette via cfe-commits
Author: paquette
Date: Tue May  8 13:53:19 2018
New Revision: 331806

URL: http://llvm.org/viewvc/llvm-project?rev=331806&view=rev
Log:
Change -foutline to -moutline

Nitpicky, but the MachineOutliner is a machine-level pass, and so we should
reflect that by using "m" instead of "n".

Figured we should get this in before people get used to the letter f. :)

Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Driver/aarch64-outliner.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=331806&r1=331805&r2=331806&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue May  8 13:53:19 2018
@@ -1317,8 +1317,6 @@ def fno_exceptions : Flag<["-"], "fno-ex
 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 foutline : Flag<["-"], "foutline">, Group, 
Flags<[CC1Option]>,
-HelpText<"Enable function outlining (AArch64 only)">;
 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">,
@@ -1908,6 +1906,8 @@ def mmacos_version_min_EQ : Joined<["-"]
   Group, Alias;
 def mms_bitfields : Flag<["-"], "mms-bitfields">, Group, 
Flags<[CC1Option]>,
   HelpText<"Set the default structure layout to be compatible with the 
Microsoft compiler standard">;
+def moutline : Flag<["-"], "moutline">, Group, 
Flags<[CC1Option]>,
+HelpText<"Enable function outlining (AArch64 only)">;
 def mno_ms_bitfields : Flag<["-"], "mno-ms-bitfields">, Group,
   HelpText<"Do not set the default structure layout to be compatible with the 
Microsoft compiler standard">;
 def mstackrealign : Flag<["-"], "mstackrealign">, Group, 
Flags<[CC1Option]>,

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=331806&r1=331805&r2=331806&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Tue May  8 13:53:19 2018
@@ -1485,7 +1485,7 @@ void Clang::AddAArch64TargetArgs(const A
   CmdArgs.push_back("-aarch64-enable-global-merge=true");
   }
 
-  if (Args.getLastArg(options::OPT_foutline)) {
+  if (Args.getLastArg(options::OPT_moutline)) {
 CmdArgs.push_back("-mllvm");
 CmdArgs.push_back("-enable-machine-outliner");
   }

Modified: cfe/trunk/test/Driver/aarch64-outliner.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/aarch64-outliner.c?rev=331806&r1=331805&r2=331806&view=diff
==
--- cfe/trunk/test/Driver/aarch64-outliner.c (original)
+++ cfe/trunk/test/Driver/aarch64-outliner.c Tue May  8 13:53:19 2018
@@ -1,4 +1,4 @@
 // REQUIRES: aarch64-registered-target
 
-// RUN: %clang -target aarch64 -foutline -S %s -### 2>&1 | FileCheck %s
+// RUN: %clang -target aarch64 -moutline -S %s -### 2>&1 | FileCheck %s
 // CHECK: "-mllvm" "-enable-machine-outliner"


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


r331807 - [Driver] Don't add -dwarf-column-info when using -gcodeview on non-msvc targets

2018-05-08 Thread Martin Storsjo via cfe-commits
Author: mstorsjo
Date: Tue May  8 13:55:23 2018
New Revision: 331807

URL: http://llvm.org/viewvc/llvm-project?rev=331807&view=rev
Log:
[Driver] Don't add -dwarf-column-info when using -gcodeview on non-msvc targets

-dwarf-column-info is omitted if -gcodeview is specified for msvc
targets at the moment, but since -gcodeview is an option that can be
specified for any target, there's little reason to restrict this
handling to msvc targets.

This allows getting proper codeview debug info by passing -gcodeview
for e.g. MinGW targets as well.

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

Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Driver/codeview-column-info.c

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=331807&r1=331806&r2=331807&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Tue May  8 13:55:23 2018
@@ -3000,7 +3000,7 @@ static void RenderDebugOptions(const Too
   // debuggers don't handle missing end columns well, so it's better not to
   // include any column info.
   if (Args.hasFlag(options::OPT_gcolumn_info, options::OPT_gno_column_info,
-   /*Default=*/!(IsWindowsMSVC && EmitCodeView) &&
+   /*Default=*/!EmitCodeView &&
DebuggerTuning != llvm::DebuggerKind::SCE))
 CmdArgs.push_back("-dwarf-column-info");
 

Modified: cfe/trunk/test/Driver/codeview-column-info.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/codeview-column-info.c?rev=331807&r1=331806&r2=331807&view=diff
==
--- cfe/trunk/test/Driver/codeview-column-info.c (original)
+++ cfe/trunk/test/Driver/codeview-column-info.c Tue May  8 13:55:23 2018
@@ -6,6 +6,8 @@
 // RUN: FileCheck < %t1 %s
 // RUN: %clangxx -### --target=x86_64-windows-msvc -c -g -gcodeview %s 2> %t2
 // RUN: FileCheck < %t2 %s
+// RUN: %clangxx -### --target=x86_64-windows-gnu -c -g -gcodeview %s 2> %t2
+// RUN: FileCheck < %t2 %s
 // RUN: %clang_cl -### --target=x86_64-windows-msvc /c /Z7 -- %s 2> %t2
 // RUN: FileCheck < %t2 %s
 


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


[PATCH] D46287: [Driver] Don't add -dwarf-column-info when using -gcodeview on non-msvc targets

2018-05-08 Thread Martin Storsjö via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL331807: [Driver] Don't add -dwarf-column-info when 
using -gcodeview on non-msvc targets (authored by mstorsjo, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46287?vs=144630&id=145776#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46287

Files:
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/test/Driver/codeview-column-info.c


Index: cfe/trunk/test/Driver/codeview-column-info.c
===
--- cfe/trunk/test/Driver/codeview-column-info.c
+++ cfe/trunk/test/Driver/codeview-column-info.c
@@ -6,6 +6,8 @@
 // RUN: FileCheck < %t1 %s
 // RUN: %clangxx -### --target=x86_64-windows-msvc -c -g -gcodeview %s 2> %t2
 // RUN: FileCheck < %t2 %s
+// RUN: %clangxx -### --target=x86_64-windows-gnu -c -g -gcodeview %s 2> %t2
+// RUN: FileCheck < %t2 %s
 // RUN: %clang_cl -### --target=x86_64-windows-msvc /c /Z7 -- %s 2> %t2
 // RUN: FileCheck < %t2 %s
 
Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -3000,7 +3000,7 @@
   // debuggers don't handle missing end columns well, so it's better not to
   // include any column info.
   if (Args.hasFlag(options::OPT_gcolumn_info, options::OPT_gno_column_info,
-   /*Default=*/!(IsWindowsMSVC && EmitCodeView) &&
+   /*Default=*/!EmitCodeView &&
DebuggerTuning != llvm::DebuggerKind::SCE))
 CmdArgs.push_back("-dwarf-column-info");
 


Index: cfe/trunk/test/Driver/codeview-column-info.c
===
--- cfe/trunk/test/Driver/codeview-column-info.c
+++ cfe/trunk/test/Driver/codeview-column-info.c
@@ -6,6 +6,8 @@
 // RUN: FileCheck < %t1 %s
 // RUN: %clangxx -### --target=x86_64-windows-msvc -c -g -gcodeview %s 2> %t2
 // RUN: FileCheck < %t2 %s
+// RUN: %clangxx -### --target=x86_64-windows-gnu -c -g -gcodeview %s 2> %t2
+// RUN: FileCheck < %t2 %s
 // RUN: %clang_cl -### --target=x86_64-windows-msvc /c /Z7 -- %s 2> %t2
 // RUN: FileCheck < %t2 %s
 
Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -3000,7 +3000,7 @@
   // debuggers don't handle missing end columns well, so it's better not to
   // include any column info.
   if (Args.hasFlag(options::OPT_gcolumn_info, options::OPT_gno_column_info,
-   /*Default=*/!(IsWindowsMSVC && EmitCodeView) &&
+   /*Default=*/!EmitCodeView &&
DebuggerTuning != llvm::DebuggerKind::SCE))
 CmdArgs.push_back("-dwarf-column-info");
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r331810 - Add a mno-outline flag to disable the MachineOutliner

2018-05-08 Thread Jessica Paquette via cfe-commits
Author: paquette
Date: Tue May  8 13:58:32 2018
New Revision: 331810

URL: http://llvm.org/viewvc/llvm-project?rev=331810&view=rev
Log:
Add a mno-outline flag to disable the MachineOutliner

Since we're working on turning the MachineOutliner by default under -Oz for
AArch64, it makes sense to have an -mno-outline flag available. This currently
doesn't do much (it basically just undoes -moutline).

When the MachineOutliner is on by default under AArch64, this flag should
set -mllvm -enable-machine-outliner=never.

Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Driver/aarch64-outliner.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=331810&r1=331809&r2=331810&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue May  8 13:58:32 2018
@@ -1908,6 +1908,8 @@ def mms_bitfields : Flag<["-"], "mms-bit
   HelpText<"Set the default structure layout to be compatible with the 
Microsoft compiler standard">;
 def moutline : Flag<["-"], "moutline">, Group, 
Flags<[CC1Option]>,
 HelpText<"Enable function outlining (AArch64 only)">;
+def mno_outline : Flag<["-"], "mno-outline">, Group, 
Flags<[CC1Option]>,
+HelpText<"Disable function outlining (AArch64 only)">;
 def mno_ms_bitfields : Flag<["-"], "mno-ms-bitfields">, Group,
   HelpText<"Do not set the default structure layout to be compatible with the 
Microsoft compiler standard">;
 def mstackrealign : Flag<["-"], "mstackrealign">, Group, 
Flags<[CC1Option]>,

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=331810&r1=331809&r2=331810&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Tue May  8 13:58:32 2018
@@ -1485,7 +1485,8 @@ void Clang::AddAArch64TargetArgs(const A
   CmdArgs.push_back("-aarch64-enable-global-merge=true");
   }
 
-  if (Args.getLastArg(options::OPT_moutline)) {
+  if (!Args.hasArg(options::OPT_mno_outline) &&
+   Args.getLastArg(options::OPT_moutline)) {
 CmdArgs.push_back("-mllvm");
 CmdArgs.push_back("-enable-machine-outliner");
   }

Modified: cfe/trunk/test/Driver/aarch64-outliner.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/aarch64-outliner.c?rev=331810&r1=331809&r2=331810&view=diff
==
--- cfe/trunk/test/Driver/aarch64-outliner.c (original)
+++ cfe/trunk/test/Driver/aarch64-outliner.c Tue May  8 13:58:32 2018
@@ -1,4 +1,9 @@
 // REQUIRES: aarch64-registered-target
 
-// RUN: %clang -target aarch64 -moutline -S %s -### 2>&1 | FileCheck %s
-// CHECK: "-mllvm" "-enable-machine-outliner"
+// RUN: %clang -target aarch64 -moutline -S %s -### 2>&1 | FileCheck %s 
-check-prefix=ON
+// ON: "-mllvm" "-enable-machine-outliner"
+
+// RUN: %clang -target aarch64 -moutline -mno-outline -S %s -### 2>&1 | 
FileCheck %s -check-prefix=OFF1
+// RUN: %clang -target aarch64 -mno-outline -moutline -S %s -### 2>&1 | 
FileCheck %s -check-prefix=OFF2
+// OFF1-NOT: "-mllvm" "-enable-machine-outliner"
+// OFF2-NOT: "-mllvm" "-enable-machine-outliner"


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


r331811 - [HIP] Add hip offload kind

2018-05-08 Thread Yaxun Liu via cfe-commits
Author: yaxunl
Date: Tue May  8 14:02:12 2018
New Revision: 331811

URL: http://llvm.org/viewvc/llvm-project?rev=331811&view=rev
Log:
[HIP] Add hip offload kind

There are quite differences in HIP action builder and action job creation,
which justifies to define a separate offload kind.

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

Modified:
cfe/trunk/include/clang/Driver/Action.h
cfe/trunk/lib/Driver/Action.cpp
cfe/trunk/lib/Driver/Compilation.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp

Modified: cfe/trunk/include/clang/Driver/Action.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Action.h?rev=331811&r1=331810&r2=331811&view=diff
==
--- cfe/trunk/include/clang/Driver/Action.h (original)
+++ cfe/trunk/include/clang/Driver/Action.h Tue May  8 14:02:12 2018
@@ -88,6 +88,7 @@ public:
 // The device offloading tool chains - one bit for each programming model.
 OFK_Cuda = 0x02,
 OFK_OpenMP = 0x04,
+OFK_HIP = 0x08,
   };
 
   static const char *getClassName(ActionClass AC);

Modified: cfe/trunk/lib/Driver/Action.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Action.cpp?rev=331811&r1=331810&r2=331811&view=diff
==
--- cfe/trunk/lib/Driver/Action.cpp (original)
+++ cfe/trunk/lib/Driver/Action.cpp Tue May  8 14:02:12 2018
@@ -96,6 +96,8 @@ std::string Action::getOffloadingKindPre
 return "device-cuda";
   case OFK_OpenMP:
 return "device-openmp";
+  case OFK_HIP:
+return "device-hip";
 
 // TODO: Add other programming models here.
   }
@@ -104,8 +106,13 @@ std::string Action::getOffloadingKindPre
 return {};
 
   std::string Res("host");
+  assert(!((ActiveOffloadKindMask & OFK_Cuda) &&
+   (ActiveOffloadKindMask & OFK_HIP)) &&
+ "Cannot offload CUDA and HIP at the same time");
   if (ActiveOffloadKindMask & OFK_Cuda)
 Res += "-cuda";
+  if (ActiveOffloadKindMask & OFK_HIP)
+Res += "-hip";
   if (ActiveOffloadKindMask & OFK_OpenMP)
 Res += "-openmp";
 
@@ -142,6 +149,8 @@ StringRef Action::GetOffloadKindName(Off
 return "cuda";
   case OFK_OpenMP:
 return "openmp";
+  case OFK_HIP:
+return "hip";
 
 // TODO: Add other programming models here.
   }

Modified: cfe/trunk/lib/Driver/Compilation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Compilation.cpp?rev=331811&r1=331810&r2=331811&view=diff
==
--- cfe/trunk/lib/Driver/Compilation.cpp (original)
+++ cfe/trunk/lib/Driver/Compilation.cpp Tue May  8 14:02:12 2018
@@ -196,10 +196,10 @@ static bool ActionFailed(const Action *A
   if (FailingCommands.empty())
 return false;
 
-  // CUDA can have the same input source code compiled multiple times so do not
-  // compiled again if there are already failures. It is OK to abort the CUDA
-  // pipeline on errors.
-  if (A->isOffloading(Action::OFK_Cuda))
+  // CUDA/HIP can have the same input source code compiled multiple times so do
+  // not compiled again if there are already failures. It is OK to abort the
+  // CUDA pipeline on errors.
+  if (A->isOffloading(Action::OFK_Cuda) || A->isOffloading(Action::OFK_HIP))
 return true;
 
   for (const auto &CI : FailingCommands)

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=331811&r1=331810&r2=331811&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Tue May  8 14:02:12 2018
@@ -131,6 +131,10 @@ forAllAssociatedToolChains(Compilation &
 Work(*C.getSingleOffloadToolChain());
   else if (JA.isDeviceOffloading(Action::OFK_Cuda))
 Work(*C.getSingleOffloadToolChain());
+  else if (JA.isHostOffloading(Action::OFK_HIP))
+Work(*C.getSingleOffloadToolChain());
+  else if (JA.isDeviceOffloading(Action::OFK_HIP))
+Work(*C.getSingleOffloadToolChain());
 
   if (JA.isHostOffloading(Action::OFK_OpenMP)) {
 auto TCs = C.getOffloadToolChains();
@@ -3105,13 +3109,14 @@ void Clang::ConstructJob(Compilation &C,
   // Check number of inputs for sanity. We need at least one input.
   assert(Inputs.size() >= 1 && "Must have at least one input.");
   const InputInfo &Input = Inputs[0];
-  // CUDA compilation may have multiple inputs (source file + results of
+  // CUDA/HIP compilation may have multiple inputs (source file + results of
   // device-side compilations). OpenMP device jobs also take the host IR as a
   // second input. All other jobs are expected to have exactly one
   // input.
   bool IsCuda = JA.isOffloading(Action::OFK_Cuda);
+  bool IsHIP = JA.isOffloading(Action::OFK_HIP);
   bool IsOpenMPDevice = JA.isDeviceOffloading(Action::O

[PATCH] D42933: [Sema] Avoid -Wformat warning for NSInteger/NSUInteger 'int' values with %zu/%zi long specifiers

2018-05-08 Thread James Y Knight via Phabricator via cfe-commits
jyknight added a comment.

In https://reviews.llvm.org/D42933#1091817, @jfb wrote:

> In https://reviews.llvm.org/D42933#1091809, @jyknight wrote:
>
> > I also think that special casing these two specifiers doesn't make sense. 
> > The problem is a general issue -- and one I've often found irritating. This 
> > exact same situation comes up all the time in non-Darwin contexts too.
>
>
> I don't think that's true. In this very specific case the platform guarantees 
> that `(sizeof(size_t) == sizeof(NSInteger)) && (sizeof(ssize_t) == 
> sizeof(NSUInteger))` for all architectures this platform supports. This exact 
> same situation does not come up all the time in other contexts because the 
> `int` / `long` / `long long` distinction isn't backed by a portability 
> guarantee. The warning is there to say "this code isn't portable!", but in 
> the very specific case of `NSInteger` and `NSUInteger` it is and users rely 
> on it so it cannot be broken. The warning is therefore spurious, users 
> therefore rightly complain.


The printf format specifier warning is not primarily a cross-platform 
portability checker. And, although in a few limited cases it can act somewhat 
like one, in general it does not. Take my previous example -- you get no 
warning on a platform that has int64_t as a typedef for long -- if this feature 
is to be useful as a portability checker, it should require that you used the 
PRId64 macro. Or, given `ssize_t x = 0; printf("%ld", x);`, it doesn't tell you 
to use "%zd" instead if ssize_t is a typedef for long -- although to be 
portable you ought to.

No, the major usefulness of the printf warning is to tell you that your code is 
incorrect for the _current_ platform. And //most// importantly when you chose 
the wrong size for your argument.

Those types which have matched size and alignment are still different types, 
and so it's technically appropriate to warn about using the wrong specifier 
there, too. But it's also entirely reasonable to not want to be bothered by 
such useless trivia, so skipping the warning when there's only a technical and 
not actual mismatch seems entirely sensible. (I might suggest that it should 
even be the default behavior for the warning, and if you want the stricter 
checks you'd ask for them...but I bet I'll get more pushback on that...)


Repository:
  rC Clang

https://reviews.llvm.org/D42933



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


[PATCH] D46471: [HIP] Add hip offload kind

2018-05-08 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
yaxunl marked an inline comment as done.
Closed by commit rL331811: [HIP] Add hip offload kind (authored by yaxunl, 
committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46471?vs=145472&id=145780#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46471

Files:
  cfe/trunk/include/clang/Driver/Action.h
  cfe/trunk/lib/Driver/Action.cpp
  cfe/trunk/lib/Driver/Compilation.cpp
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp

Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -131,6 +131,10 @@
 Work(*C.getSingleOffloadToolChain());
   else if (JA.isDeviceOffloading(Action::OFK_Cuda))
 Work(*C.getSingleOffloadToolChain());
+  else if (JA.isHostOffloading(Action::OFK_HIP))
+Work(*C.getSingleOffloadToolChain());
+  else if (JA.isDeviceOffloading(Action::OFK_HIP))
+Work(*C.getSingleOffloadToolChain());
 
   if (JA.isHostOffloading(Action::OFK_OpenMP)) {
 auto TCs = C.getOffloadToolChains();
@@ -3105,13 +3109,14 @@
   // Check number of inputs for sanity. We need at least one input.
   assert(Inputs.size() >= 1 && "Must have at least one input.");
   const InputInfo &Input = Inputs[0];
-  // CUDA compilation may have multiple inputs (source file + results of
+  // CUDA/HIP compilation may have multiple inputs (source file + results of
   // device-side compilations). OpenMP device jobs also take the host IR as a
   // second input. All other jobs are expected to have exactly one
   // input.
   bool IsCuda = JA.isOffloading(Action::OFK_Cuda);
+  bool IsHIP = JA.isOffloading(Action::OFK_HIP);
   bool IsOpenMPDevice = JA.isDeviceOffloading(Action::OFK_OpenMP);
-  assert((IsCuda || (IsOpenMPDevice && Inputs.size() == 2) ||
+  assert((IsCuda || IsHIP || (IsOpenMPDevice && Inputs.size() == 2) ||
   Inputs.size() == 1) &&
  "Unable to handle multiple inputs.");
 
@@ -3123,10 +3128,10 @@
   bool IsWindowsMSVC = RawTriple.isWindowsMSVCEnvironment();
   bool IsIAMCU = RawTriple.isOSIAMCU();
 
-  // Adjust IsWindowsXYZ for CUDA compilations.  Even when compiling in device
-  // mode (i.e., getToolchain().getTriple() is NVPTX, not Windows), we need to
-  // pass Windows-specific flags to cc1.
-  if (IsCuda) {
+  // Adjust IsWindowsXYZ for CUDA/HIP compilations.  Even when compiling in
+  // device mode (i.e., getToolchain().getTriple() is NVPTX/AMDGCN, not
+  // Windows), we need to pass Windows-specific flags to cc1.
+  if (IsCuda || IsHIP) {
 IsWindowsMSVC |= AuxTriple && AuxTriple->isWindowsMSVCEnvironment();
 IsWindowsGNU |= AuxTriple && AuxTriple->isWindowsGNUEnvironment();
 IsWindowsCygnus |= AuxTriple && AuxTriple->isWindowsCygwinEnvironment();
@@ -3150,18 +3155,21 @@
 Args.ClaimAllArgs(options::OPT_MJ);
   }
 
-  if (IsCuda) {
-// We have to pass the triple of the host if compiling for a CUDA device and
-// vice-versa.
+  if (IsCuda || IsHIP) {
+// We have to pass the triple of the host if compiling for a CUDA/HIP device
+// and vice-versa.
 std::string NormalizedTriple;
-if (JA.isDeviceOffloading(Action::OFK_Cuda))
+if (JA.isDeviceOffloading(Action::OFK_Cuda) ||
+JA.isDeviceOffloading(Action::OFK_HIP))
   NormalizedTriple = C.getSingleOffloadToolChain()
  ->getTriple()
  .normalize();
 else
-  NormalizedTriple = C.getSingleOffloadToolChain()
- ->getTriple()
- .normalize();
+  NormalizedTriple =
+  (IsCuda ? C.getSingleOffloadToolChain()
+  : C.getSingleOffloadToolChain())
+  ->getTriple()
+  .normalize();
 
 CmdArgs.push_back("-aux-triple");
 CmdArgs.push_back(Args.MakeArgString(NormalizedTriple));
Index: cfe/trunk/lib/Driver/Compilation.cpp
===
--- cfe/trunk/lib/Driver/Compilation.cpp
+++ cfe/trunk/lib/Driver/Compilation.cpp
@@ -196,10 +196,10 @@
   if (FailingCommands.empty())
 return false;
 
-  // CUDA can have the same input source code compiled multiple times so do not
-  // compiled again if there are already failures. It is OK to abort the CUDA
-  // pipeline on errors.
-  if (A->isOffloading(Action::OFK_Cuda))
+  // CUDA/HIP can have the same input source code compiled multiple times so do
+  // not compiled again if there are already failures. It is OK to abort the
+  // CUDA pipeline on errors.
+  if (A->isOffloading(Action::OFK_Cuda) || A->isOffloading(Action::OFK_HIP))
 return true;
 
   for (const auto &CI : FailingCommands)
Index: cfe/trunk/lib/Driver/Action.cpp
===
--- cfe/trunk/lib/Driver/Action.cpp
+++ cfe/trunk/l

[PATCH] D42933: [Sema] Avoid -Wformat warning for NSInteger/NSUInteger 'int' values with %zu/%zi long specifiers

2018-05-08 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a subscriber: rsmith.
smeenai added a comment.

In https://reviews.llvm.org/D42933#1091943, @jyknight wrote:

> In https://reviews.llvm.org/D42933#1091817, @jfb wrote:
>
> > In https://reviews.llvm.org/D42933#1091809, @jyknight wrote:
> >
> > > I also think that special casing these two specifiers doesn't make sense. 
> > > The problem is a general issue -- and one I've often found irritating. 
> > > This exact same situation comes up all the time in non-Darwin contexts 
> > > too.
> >
> >
> > I don't think that's true. In this very specific case the platform 
> > guarantees that `(sizeof(size_t) == sizeof(NSInteger)) && (sizeof(ssize_t) 
> > == sizeof(NSUInteger))` for all architectures this platform supports. This 
> > exact same situation does not come up all the time in other contexts 
> > because the `int` / `long` / `long long` distinction isn't backed by a 
> > portability guarantee. The warning is there to say "this code isn't 
> > portable!", but in the very specific case of `NSInteger` and `NSUInteger` 
> > it is and users rely on it so it cannot be broken. The warning is therefore 
> > spurious, users therefore rightly complain.
>
>
> The printf format specifier warning is not primarily a cross-platform 
> portability checker. And, although in a few limited cases it can act somewhat 
> like one, in general it does not. Take my previous example -- you get no 
> warning on a platform that has int64_t as a typedef for long -- if this 
> feature is to be useful as a portability checker, it should require that you 
> used the PRId64 macro. Or, given `ssize_t x = 0; printf("%ld", x);`, it 
> doesn't tell you to use "%zd" instead if ssize_t is a typedef for long -- 
> although to be portable you ought to.
>
> No, the major usefulness of the printf warning is to tell you that your code 
> is incorrect for the _current_ platform. And //most// importantly when you 
> chose the wrong size for your argument.
>
> Those types which have matched size and alignment are still different types, 
> and so it's technically appropriate to warn about using the wrong specifier 
> there, too. But it's also entirely reasonable to not want to be bothered by 
> such useless trivia, so skipping the warning when there's only a technical 
> and not actual mismatch seems entirely sensible. (I might suggest that it 
> should even be the default behavior for the warning, and if you want the 
> stricter checks you'd ask for them...but I bet I'll get more pushback on 
> that...)


+1 to everything you said; what are other people's opinions on this? @rsmith 
perhaps?


Repository:
  rC Clang

https://reviews.llvm.org/D42933



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


[PATCH] D43778: [clang-tidy] Adding RestrictIncludes check to Fuchsia module

2018-05-08 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 145788.
juliehockett marked 10 inline comments as done.
juliehockett added a comment.

Made the check for system headers more comprehensive & fixed newline issues


https://reviews.llvm.org/D43778

Files:
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp
  clang-tidy/fuchsia/RestrictSystemIncludesCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/a.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/j.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/r.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/s.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/t.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/transitive.h
  test/clang-tidy/Inputs/fuchsia-restrict-system-includes/transitive2.h
  test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp
  test/clang-tidy/fuchsia-restrict-system-includes.cpp

Index: test/clang-tidy/fuchsia-restrict-system-includes.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-restrict-system-includes.cpp
@@ -0,0 +1,25 @@
+// RUN: %check_clang_tidy %s fuchsia-restrict-system-includes %t \
+// RUN:		-- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: 's.h'}]}" \
+// RUN:   -- -std=c++11 -I %S/Inputs/fuchsia-restrict-system-includes -isystem %S/Inputs/fuchsia-restrict-system-includes/system
+
+#include "a.h"
+
+#include 
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include t.h not allowed
+// CHECK-FIXES-NOT: #include 
+
+#include "s.h"
+#include "t.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include t.h not allowed
+// CHECK-FIXES-NOT: #include "t.h"
+
+#define foo 
+
+#include foo
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include j.h not allowed
+// CHECK-FIXES-NOT: #include foo
+
+#/* comment */ include /* comment */ foo
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include j.h not allowed
+// CHECK-FIXES-NOT: # /* comment */ include /* comment */ foo
Index: test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-restrict-system-includes-headers.cpp
@@ -0,0 +1,20 @@
+// RUN: cp -r %S/Inputs/fuchsia-restrict-system-includes %T/Inputs
+// RUN: %check_clang_tidy %s fuchsia-restrict-system-includes %t \
+// RUN:		-- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: 'transitive.h;s.h'}]}" \
+// RUN:   -system-headers -header-filter=.* \
+// RUN:   -- -std=c++11 -I %T/Inputs/fuchsia-restrict-system-includes -isystem %T/Inputs/fuchsia-restrict-system-includes/system
+// RUN: FileCheck -input-file=%T/Inputs/transitive2.h %s -check-prefix=CHECK-HEADER-FIXES
+
+// transitive.h includes  and 
+#include 
+// CHECK-MESSAGES: :1:1: warning: system include r.h not allowed, transitively included from {{(.*\/)*}}Inputs/fuchsia-restrict-system-includes/system/transitive.h
+// CHECK-MESSAGES: :2:1: warning: system include t.h not allowed, transitively included from {{(.*\/)*}}Inputs/fuchsia-restrict-system-includes/system/transitive.h
+
+// transitive.h includes  and 
+#include "transitive2.h"
+// CHECK-MESSAGES: :2:1: warning: system include t.h not allowed, transitively included from {{(.*\/)*}}Inputs/fuchsia-restrict-system-includes/transitive2.h
+// CHECK-HEADER-FIXES-NOT: #include 
+
+int main() {
+  // f() is declared in r.h
+}
Index: test/clang-tidy/Inputs/fuchsia-restrict-system-includes/transitive2.h
===
--- /dev/null
+++ test/clang-tidy/Inputs/fuchsia-restrict-system-includes/transitive2.h
@@ -0,0 +1,2 @@
+#include 
+#include 
Index: test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/transitive.h
===
--- /dev/null
+++ test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/transitive.h
@@ -0,0 +1,3 @@
+#include 
+#include 
+#include 
Index: test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/r.h
===
--- /dev/null
+++ test/clang-tidy/Inputs/fuchsia-restrict-system-includes/system/r.h
@@ -0,0 +1 @@
+void f() {}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -95,6 +95,7 @@
fuchsia-default-arguments
fuchsia-multiple-inheritance
fuchsia-overloaded-operator
+   fuchsia-restrict-system-includes
fuchsia-statically-constructed-objects
fuchsia-trailing-return
fuchsia-virtual-inheritance
Index: docs/cla

[PATCH] D46112: Allow _Atomic to be specified on incomplete types

2018-05-08 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

I think the request was that we check that a type is trivially copyable when we 
perform an atomic operation?  I don't see the code for that anywhere.

Also needs some test coverage for atomic operations which aren't calls, like 
"typedef struct S S; void f(_Atomic S *s, _Atomic S *s2) { *s = *s2; };".


https://reviews.llvm.org/D46112



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


  1   2   >