[PATCH] D51340: Add /Zc:DllexportInlines option to clang-cl

2018-09-06 Thread Takuto Ikuta via Phabricator via cfe-commits
takuto.ikuta updated this revision to Diff 164353.
takuto.ikuta edited the summary of this revision.
takuto.ikuta added a comment.
Herald added a subscriber: dschuff.

Make patch closer to Nico's original implementation, but warns local static 
variable instead of detecting it.
In checkClassLevelDLLAttribute, inline function definition is not fully parsed 
and I cannot make test passed in other way adding export only to inline 
function having local static variables.


https://reviews.llvm.org/D51340

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Driver/CLCompatOptions.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CodeGenCXX/dllexport-no-inline.cpp

Index: clang/test/CodeGenCXX/dllexport-no-inline.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/dllexport-no-inline.cpp
@@ -0,0 +1,131 @@
+// RUN: %clang_cc1 %s -fms-extensions -triple x86_64-windows-msvc   \
+// RUN: -fno-dllexport-inlines -emit-llvm -O0 -o - -verify -DNOEXPORT_INLINE | \
+// RUN: FileCheck --check-prefix=DEFAULT --check-prefix=NOINLINE %s
+
+// RUN: %clang_cc1 %s -fms-extensions -triple x86_64-windows-msvc   \
+// RUN: -emit-llvm -O0 -o - |   \
+// RUN: FileCheck --check-prefix=DEFAULT --check-prefix=INLINE %s
+
+
+// Function
+
+// DEFAULT-DAG: define dso_local dllexport void @"?NormalFunction@@YAXXZ"()
+void __declspec(dllexport) NormalFunction() {}
+
+
+// DEFAULT-DAG: define weak_odr dso_local dllexport void @"?AlwaysInlineFunction@@
+__forceinline void __declspec(dllexport) AlwaysInlineFunction() {}
+
+
+// Class member function
+
+class __declspec(dllexport) NoTemplateExportedClass {
+  // DEFAULT-NOT: NoTemplateExportedClass@NoTemplateExportedClass@@
+  NoTemplateExportedClass() = default;
+
+  // NOINLINE-NOT: InclassDefFunc@NoTemplateExportedClass
+  // INLINE-DAG: define weak_odr dso_local dllexport void @"?InclassDefFunc@NoTemplateExportedClass@@AEAAXXZ"
+  void InclassDefFunc() {}
+
+  int f();
+
+  // FIX: make this DEFAULT-DAG.
+  // INLINE-DAG: define weak_odr dso_local dllexport i32 @"?InclassDefFuncWithStaticVariable@NoTemplateExportedClass@@AEAAHXZ"
+  int InclassDefFuncWithStaticVariable() {
+#ifdef NOEXPORT_INLINE
+// expected-warning@+2 {{static 'static_variable' used in an inline function of exported class isn't exported due to -fno-dllexport-inlines}}
+#endif
+static int static_variable = f();
+
+static const int static_const_variable = 1; // expected-no-warning
+constexpr int static_constexpr_variable = 2; // expected-no-warning
+static const int static_const_array[] = {1, 2, 3}; // expected-no-warning
+
+return ++static_variable + static_const_variable + static_constexpr_variable +
+static_const_array[0];
+  }
+
+  // DEFAULT-NOT: InlineOutclassDefFuncWihtoutDefinition
+  __forceinline void InlineOutclassDefFuncWihtoutDefinition();
+
+  // FIX: Do not export this when -ms-no-dllexport-inline.
+  // DEFAULT-DAG: define weak_odr dso_local dllexport void @"?InlineOutclassDefFunc@NoTemplateExportedClass@@AEAAXXZ"
+  __forceinline void InlineOutclassDefFunc();
+
+  // FIX: Do not export this when -ms-no-dllexport-inline is given and warn for local static var.
+  // DEFAULT-DAG: define weak_odr dso_local dllexport i32 @"?InlineOutclassDefFuncWithStaticVariable@NoTemplateExportedClass@@AEAAHXZ"
+  __forceinline int InlineOutclassDefFuncWithStaticVariable();
+
+  // DEFAULT-DAG: define dso_local dllexport void @"?OutclassDefFunc@NoTemplateExportedClass@@AEAAXXZ"
+  void OutclassDefFunc();
+};
+
+void NoTemplateExportedClass::OutclassDefFunc() {}
+
+__forceinline void NoTemplateExportedClass::InlineOutclassDefFunc() {}
+
+__forceinline int NoTemplateExportedClass::InlineOutclassDefFuncWithStaticVariable() {
+static int static_variable = 0;
+return ++static_variable;
+}
+
+template
+class __declspec(dllexport) TemplateExportedClass {
+  void InclassDefFunc() {}
+  void OutclassDefFunc();
+
+  T templateValue;
+};
+
+// DEFAULT-NOT: define dso_local dllexport void @"?OutclassDefFunc@NoTemplateExportedClass@@
+template void TemplateExportedClass::OutclassDefFunc() {}
+
+class A11{};
+class B22{};
+
+// DEFAULT-DAG: define weak_odr dso_local dllexport void @"?InclassDefFunc@?$TemplateExportedClass@VA11@@
+// DEFAULT-DAG: define weak_odr dso_local dllexport void @"?OutclassDefFunc@?$TemplateExportedClass@VA11@@
+template class __declspec(dllexport) TemplateExportedClass;
+
+// DEFAULT-DAG: define weak_odr dso_local dllexport void @"?InclassDefFunc@?$TemplateExportedClass@VB22@@
+// DEFAULT-DAG: define weak_odr dso_local dllexport void @"?OutclassDefFunc@?$TemplateExportedClass@VB22@@
+template class TemplateExportedClass;
+

[PATCH] D49722: [CStringSyntaxChecker] Check strlcat sizeof check

2018-09-06 Thread David CARLIER via Phabricator via cfe-commits
devnexen added inline comments.



Comment at: test/Analysis/cstring-syntax.c:49
+  strlcat(dest, "0123456789", badlen / 2);
+  strlcat(dest, "0123456789", badlen); // expected-warning {{The third 
argument allows to potentially copy more bytes than it should. Replace with the 
value 'badlen' - strlen(dest) - 1 or lower}}
+  strlcat(dest, "0123456789", badlen - strlen(dest) - 1);

NoQ wrote:
> The suggested fix is a bit weird.
> 
> The correct code for appending `src` to `dst` is either `strlcat(dst, src, 
> sizeof(dst));` (the approach suggested by the man page) or `strlcat(dst + 
> strlen(dst) + 1, src, sizeof(dst) - strlen(dst) - 1)` (which is equivalent 
> but faster if you already know `strlen(dst)`). In both cases you can specify 
> a smaller value but not a larger value.
In fact in this case the message is misleading/a bit wrong.


https://reviews.llvm.org/D49722



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


[PATCH] D51281: [libclang] Return the proper pointee type for 'auto' deduced to pointer

2018-09-06 Thread Michael Wu via Phabricator via cfe-commits
michaelwu accepted this revision.
michaelwu added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D51281



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


[PATCH] D45898: [SemaCXX] Mark destructor as referenced

2018-09-06 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC341629: [Sema] Check that the destructor for each element of 
class type is (authored by ahatanak, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D45898

Files:
  lib/Sema/SemaInit.cpp
  test/CodeGenObjCXX/arc-list-init-destruct.mm
  test/SemaCXX/aggregate-initialization.cpp

Index: test/SemaCXX/aggregate-initialization.cpp
===
--- test/SemaCXX/aggregate-initialization.cpp
+++ test/SemaCXX/aggregate-initialization.cpp
@@ -186,3 +186,51 @@
   // amount of time.
   struct A { int n; int arr[1000 * 1000 * 1000]; } a = {1, {2}};
 }
+
+namespace ElementDestructor {
+  // The destructor for each element of class type is potentially invoked
+  // (15.4 [class.dtor]) from the context where the aggregate initialization
+  // occurs. Produce a diagnostic if an element's destructor isn't accessible.
+
+  class X { int f; ~X(); }; // expected-note {{implicitly declared private here}}
+  struct Y { X x; };
+
+  void test0() {
+auto *y = new Y {}; // expected-error {{temporary of type 'ElementDestructor::X' has private destructor}}
+  }
+
+  struct S0 { int f; ~S0() = delete; }; // expected-note 3 {{'~S0' has been explicitly marked deleted here}}
+  struct S1 { S0 s0; int f; };
+
+  S1 test1() {
+auto *t = new S1 { .f = 1 }; // expected-error {{attempt to use a deleted function}}
+return {2}; // expected-error {{attempt to use a deleted function}}
+  }
+
+  // Check if the type of an array element has a destructor.
+  struct S2 { S0 a[4]; };
+
+  void test2() {
+auto *t = new S2 {1,2,3,4}; // expected-error {{attempt to use a deleted function}}
+  }
+
+#if __cplusplus >= 201703L
+  namespace BaseDestructor {
+ struct S0 { int f; ~S0() = delete; }; // expected-note {{'~S0' has been explicitly marked deleted here}}
+
+// Check destructor of base class.
+struct S3 : S0 {};
+
+void test3() {
+  S3 s3 = {1}; // expected-error {{attempt to use a deleted function}}
+}
+  }
+#endif
+
+  // A's destructor doesn't have to be accessible from the context of C's
+  // initialization.
+  struct A { friend struct B; private: ~A(); };
+  struct B { B(); A a; };
+  struct C { B b; };
+  C c = { B() };
+}
Index: test/CodeGenObjCXX/arc-list-init-destruct.mm
===
--- test/CodeGenObjCXX/arc-list-init-destruct.mm
+++ test/CodeGenObjCXX/arc-list-init-destruct.mm
@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -std=c++1z -fobjc-arc -fobjc-exceptions -fcxx-exceptions -fexceptions -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: %[[V0:.*]] = type opaque
+// CHECK: %[[STRUCT_CLASS1:.*]] = type { %[[V0]]* }
+
+@interface Class0;
+@end
+
+struct Class1 {
+  Class0 *f;
+};
+
+struct Container {
+  Class1 a;
+  bool b;
+};
+
+bool getBool() {
+  return false;
+}
+
+Class0 *g;
+
+// CHECK: define {{.*}} @_Z4testv()
+// CHECK: invoke zeroext i1 @_Z7getBoolv()
+// CHECK: landingpad { i8*, i32 }
+// CHECK: call void @_ZN6Class1D1Ev(%[[STRUCT_CLASS1]]* %{{.*}})
+// CHECK: br label
+
+// CHECK: define linkonce_odr void @_ZN6Class1D1Ev(
+
+Container test() {
+  return {{g}, getBool()};
+}
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -1818,6 +1818,30 @@
   return FlexArrayDiag != diag::ext_flexible_array_init;
 }
 
+/// Check if the type of a class element has an accessible destructor.
+///
+/// Aggregate initialization requires a class element's destructor be
+/// accessible per 11.6.1 [dcl.init.aggr]:
+///
+/// The destructor for each element of class type is potentially invoked
+/// (15.4 [class.dtor]) from the context where the aggregate initialization
+/// occurs.
+static bool hasAccessibleDestructor(QualType ElementType, SourceLocation Loc,
+Sema ) {
+  auto *CXXRD = ElementType->getAsCXXRecordDecl();
+  if (!CXXRD)
+return false;
+
+  CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(CXXRD);
+  SemaRef.CheckDestructorAccess(Loc, Destructor,
+SemaRef.PDiag(diag::err_access_dtor_temp)
+<< ElementType);
+  SemaRef.MarkFunctionReferenced(Loc, Destructor);
+  if (SemaRef.DiagnoseUseOfDecl(Destructor, Loc))
+return true;
+  return false;
+}
+
 void InitListChecker::CheckStructUnionTypes(
 const InitializedEntity , InitListExpr *IList, QualType DeclType,
 CXXRecordDecl::base_class_range Bases, RecordDecl::field_iterator Field,
@@ -1838,6 +1862,15 @@
   if (DeclType->isUnionType() && IList->getNumInits() == 0) {
 RecordDecl *RD = DeclType->getAs()->getDecl();
 
+if (!VerifyOnly)
+  for (FieldDecl *FD : RD->fields()) {
+QualType ET = SemaRef.Context.getBaseElementType(FD->getType());
+if 

r341629 - [Sema] Check that the destructor for each element of class type is

2018-09-06 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu Sep  6 19:38:01 2018
New Revision: 341629

URL: http://llvm.org/viewvc/llvm-project?rev=341629=rev
Log:
[Sema] Check that the destructor for each element of class type is
accessible from the context where aggregate initialization occurs.

rdar://problem/38168772

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

Added:
cfe/trunk/test/CodeGenObjCXX/arc-list-init-destruct.mm
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/SemaCXX/aggregate-initialization.cpp

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=341629=341628=341629=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Thu Sep  6 19:38:01 2018
@@ -1818,6 +1818,30 @@ bool InitListChecker::CheckFlexibleArray
   return FlexArrayDiag != diag::ext_flexible_array_init;
 }
 
+/// Check if the type of a class element has an accessible destructor.
+///
+/// Aggregate initialization requires a class element's destructor be
+/// accessible per 11.6.1 [dcl.init.aggr]:
+///
+/// The destructor for each element of class type is potentially invoked
+/// (15.4 [class.dtor]) from the context where the aggregate initialization
+/// occurs.
+static bool hasAccessibleDestructor(QualType ElementType, SourceLocation Loc,
+Sema ) {
+  auto *CXXRD = ElementType->getAsCXXRecordDecl();
+  if (!CXXRD)
+return false;
+
+  CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(CXXRD);
+  SemaRef.CheckDestructorAccess(Loc, Destructor,
+SemaRef.PDiag(diag::err_access_dtor_temp)
+<< ElementType);
+  SemaRef.MarkFunctionReferenced(Loc, Destructor);
+  if (SemaRef.DiagnoseUseOfDecl(Destructor, Loc))
+return true;
+  return false;
+}
+
 void InitListChecker::CheckStructUnionTypes(
 const InitializedEntity , InitListExpr *IList, QualType DeclType,
 CXXRecordDecl::base_class_range Bases, RecordDecl::field_iterator Field,
@@ -1838,6 +1862,15 @@ void InitListChecker::CheckStructUnionTy
   if (DeclType->isUnionType() && IList->getNumInits() == 0) {
 RecordDecl *RD = DeclType->getAs()->getDecl();
 
+if (!VerifyOnly)
+  for (FieldDecl *FD : RD->fields()) {
+QualType ET = SemaRef.Context.getBaseElementType(FD->getType());
+if (hasAccessibleDestructor(ET, IList->getEndLoc(), SemaRef)) {
+  hadError = true;
+  return;
+}
+  }
+
 // If there's a default initializer, use it.
 if (isa(RD) && 
cast(RD)->hasInClassInitializer()) {
   if (VerifyOnly)
@@ -1874,13 +1907,13 @@ void InitListChecker::CheckStructUnionTy
   // If we have any base classes, they are initialized prior to the fields.
   for (auto  : Bases) {
 Expr *Init = Index < IList->getNumInits() ? IList->getInit(Index) : 
nullptr;
-SourceLocation InitLoc = Init ? Init->getBeginLoc() : IList->getEndLoc();
 
 // Designated inits always initialize fields, so if we see one, all
 // remaining base classes have no explicit initializer.
 if (Init && isa(Init))
   Init = nullptr;
 
+SourceLocation InitLoc = Init ? Init->getBeginLoc() : IList->getEndLoc();
 InitializedEntity BaseEntity = InitializedEntity::InitializeBase(
 SemaRef.Context, , false, );
 if (Init) {
@@ -1890,6 +1923,12 @@ void InitListChecker::CheckStructUnionTy
 } else if (VerifyOnly) {
   CheckEmptyInitializable(BaseEntity, InitLoc);
 }
+
+if (!VerifyOnly)
+  if (hasAccessibleDestructor(Base.getType(), InitLoc, SemaRef)) {
+hadError = true;
+return;
+  }
   }
 
   // If structDecl is a forward declaration, this loop won't do
@@ -1900,9 +1939,11 @@ void InitListChecker::CheckStructUnionTy
   RecordDecl::field_iterator FieldEnd = RD->field_end();
   bool CheckForMissingFields =
 !IList->isIdiomaticZeroInitializer(SemaRef.getLangOpts());
+  bool HasDesignatedInit = false;
 
   while (Index < IList->getNumInits()) {
 Expr *Init = IList->getInit(Index);
+SourceLocation InitLoc = Init->getBeginLoc();
 
 if (DesignatedInitExpr *DIE = dyn_cast(Init)) {
   // If we're not the subobject that matches up with the '{' for
@@ -1911,6 +1952,8 @@ void InitListChecker::CheckStructUnionTy
   if (!SubobjectIsDesignatorContext)
 return;
 
+  HasDesignatedInit = true;
+
   // Handle this designated initializer. Field will be updated to
   // the next field that we'll be initializing.
   if (CheckDesignatedInitializer(Entity, IList, DIE, 0,
@@ -1918,6 +1961,17 @@ void InitListChecker::CheckStructUnionTy
  StructuredList, StructuredIndex,
  true, TopLevelObject))
 hadError = true;
+  else if (!VerifyOnly) {
+// Find the field named by the designated 

[PATCH] D51417: [analyzer][UninitializedObjectChecker] Updated comments

2018-09-06 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Comments always welcome!




Comment at: 
lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp:363-364
+
+  // ImmutableList::getHead() isn't a const method, hence the not too nice
+  // implementation.
   return (*Chain.begin()).getRegion();

Ugh, why is it not `const`?


Repository:
  rC Clang

https://reviews.llvm.org/D51417



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


[PATCH] D51057: [analyzer][UninitializedObjectChecker] Fixed dereferencing

2018-09-06 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: 
lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp:126-127
   if (V.isUndef()) {
+assert(!FR->getDecl()->getType()->isReferenceType() &&
+   "References must be initialized!");
 return addFieldToUninits(

Szelethus wrote:
> NoQ wrote:
> > Good catch.
> > 
> > It might still be possible to initialize a reference with an 
> > already-undefined pointer if core checkers are turned off, but we don't 
> > support turning them off, so i guess it's fine.
> I removed it, because it did crash couple times on LLVM. Note that the assert 
> checked whether the reference for undefined, not uninitialized :/.
> 
> It's no longer in the code, but this was it:
> ```
> assert(!FR->getDecl()->getType()->isReferenceType() &&
>"References must be initialized!");
> ```
Hmm, indeed, it seems that we don't have a checker for garbage references, only 
for null references(?).

I guess it's a good idea for a checker.



Comment at: test/Analysis/cxx-uninitialized-object.cpp:879-902
+struct LambdaWrapper {
+  void *func; // no-crash
+  int dontGetFilteredByNonPedanticMode = 0;
+
+  LambdaWrapper(void *ptr) : func(ptr) {} // expected-warning{{1 uninitialized 
field}}
+};
+

Szelethus wrote:
> I'm 99% sure this is a FP, but it doesn't originate from the checker. 
> Shouldn't `*ptr` be undef after the end of the code block as `lambda`'s 
> lifetime ends?
> 
> Nevertheless, it did cause a crash, so here's a quick fix for it.
I'm pretty sure that all sorts of contents of `lambda` aka `*ptr` are undefined 
once it goes out of scope. Moreover, `ptr` is now a dangling pointer, and 
reading from it would cause undefined behavior. I'm not sure if the analyzer 
actually models this though. 

But on the other hand, even if it didn't go out of scope, i don't really see 
where field `a` was initialized here.

Soo what makes you think it's a false positive?


https://reviews.llvm.org/D51057



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


[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like elements

2018-09-06 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

I'm generally fine with landing the patch as long as the overall direction is 
chosen (and be moved towards) for how to safely identify the non-deterministic 
iterators (my previous inline question). This has to be addressed before we 
move out of alpha, but i believe we should pick at least some direction now, 
because i've very little idea about how to actually do that safely, and i'm 
worried that we'll get stuck in a dead end here.

Package name sounds good.




Comment at: test/Analysis/ptr-sort.cpp:1
+// RUN: %clang_analyze_cc1 
-analyzer-checker=core,alpha.nondeterminism.PointerSorting %s 
-analyzer-output=text -verify
+

There's no need to test with -analyzer-output=text for a syntactic check, 
because you're not checking path diagnostics. It'll make tests tidier by not 
forcing you to test notes.

If you ever decide to add extra "note" pieces to your checker, they'll be shown 
in the default output anyway.


https://reviews.llvm.org/D50488



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


[PATCH] D49722: [CStringSyntaxChecker] Check strlcat sizeof check

2018-09-06 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: test/Analysis/cstring-syntax.c:49
+  strlcat(dest, "0123456789", badlen / 2);
+  strlcat(dest, "0123456789", badlen); // expected-warning {{The third 
argument allows to potentially copy more bytes than it should. Replace with the 
value 'badlen' - strlen(dest) - 1 or lower}}
+  strlcat(dest, "0123456789", badlen - strlen(dest) - 1);

The suggested fix is a bit weird.

The correct code for appending `src` to `dst` is either `strlcat(dst, src, 
sizeof(dst));` (the approach suggested by the man page) or `strlcat(dst + 
strlen(dst) + 1, src, sizeof(dst) - strlen(dst) - 1)` (which is equivalent but 
faster if you already know `strlen(dst)`). In both cases you can specify a 
smaller value but not a larger value.


https://reviews.llvm.org/D49722



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


[PATCH] D51669: [analyzer] [NFC] Prefer passing raw reference to value instead of a reference to unique_ptr

2018-09-06 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC341620: [analyzer] [NFC] Prefer passing around reference to 
std::unique_ptr (authored by george.karpenkov, committed by ).
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D51669?vs=163959=164338#toc

Repository:
  rC Clang

https://reviews.llvm.org/D51669

Files:
  lib/StaticAnalyzer/Core/BugReporter.cpp


Index: lib/StaticAnalyzer/Core/BugReporter.cpp
===
--- lib/StaticAnalyzer/Core/BugReporter.cpp
+++ lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -3010,7 +3010,7 @@
 /// into \p ExecutedLines.
 static void populateExecutedLinesWithFunctionSignature(
 const Decl *Signature, SourceManager ,
-std::unique_ptr ) {
+FilesToLineNumsMap ) {
   SourceRange SignatureSourceRange;
   const Stmt* Body = Signature->getBody();
   if (const auto FD = dyn_cast(Signature)) {
@@ -3030,19 +3030,19 @@
 
   FileID FID = SM.getFileID(SM.getExpansionLoc(Start));
   for (unsigned Line = StartLine; Line <= EndLine; Line++)
-ExecutedLines->operator[](FID).insert(Line);
+ExecutedLines[FID].insert(Line);
 }
 
 static void populateExecutedLinesWithStmt(
 const Stmt *S, SourceManager ,
-std::unique_ptr ) {
+FilesToLineNumsMap ) {
   SourceLocation Loc = S->getSourceRange().getBegin();
   if (!Loc.isValid())
 return;
   SourceLocation ExpansionLoc = SM.getExpansionLoc(Loc);
   FileID FID = SM.getFileID(ExpansionLoc);
   unsigned LineNo = SM.getExpansionLineNumber(ExpansionLoc);
-  ExecutedLines->operator[](FID).insert(LineNo);
+  ExecutedLines[FID].insert(LineNo);
 }
 
 /// \return all executed lines including function signatures on the path
@@ -3055,27 +3055,27 @@
 if (N->getFirstPred() == nullptr) {
   // First node: show signature of the entrance point.
   const Decl *D = N->getLocationContext()->getDecl();
-  populateExecutedLinesWithFunctionSignature(D, SM, ExecutedLines);
+  populateExecutedLinesWithFunctionSignature(D, SM, *ExecutedLines);
 } else if (auto CE = N->getLocationAs()) {
   // Inlined function: show signature.
   const Decl* D = CE->getCalleeContext()->getDecl();
-  populateExecutedLinesWithFunctionSignature(D, SM, ExecutedLines);
+  populateExecutedLinesWithFunctionSignature(D, SM, *ExecutedLines);
 } else if (const Stmt *S = PathDiagnosticLocation::getStmt(N)) {
-  populateExecutedLinesWithStmt(S, SM, ExecutedLines);
+  populateExecutedLinesWithStmt(S, SM, *ExecutedLines);
 
   // Show extra context for some parent kinds.
   const Stmt *P = N->getParentMap().getParent(S);
 
   // The path exploration can die before the node with the associated
   // return statement is generated, but we do want to show the whole
   // return.
   if (const auto *RS = dyn_cast_or_null(P)) {
-populateExecutedLinesWithStmt(RS, SM, ExecutedLines);
+populateExecutedLinesWithStmt(RS, SM, *ExecutedLines);
 P = N->getParentMap().getParent(RS);
   }
 
   if (P && (isa(P) || isa(P)))
-populateExecutedLinesWithStmt(P, SM, ExecutedLines);
+populateExecutedLinesWithStmt(P, SM, *ExecutedLines);
 }
 
 N = N->getFirstPred();


Index: lib/StaticAnalyzer/Core/BugReporter.cpp
===
--- lib/StaticAnalyzer/Core/BugReporter.cpp
+++ lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -3010,7 +3010,7 @@
 /// into \p ExecutedLines.
 static void populateExecutedLinesWithFunctionSignature(
 const Decl *Signature, SourceManager ,
-std::unique_ptr ) {
+FilesToLineNumsMap ) {
   SourceRange SignatureSourceRange;
   const Stmt* Body = Signature->getBody();
   if (const auto FD = dyn_cast(Signature)) {
@@ -3030,19 +3030,19 @@
 
   FileID FID = SM.getFileID(SM.getExpansionLoc(Start));
   for (unsigned Line = StartLine; Line <= EndLine; Line++)
-ExecutedLines->operator[](FID).insert(Line);
+ExecutedLines[FID].insert(Line);
 }
 
 static void populateExecutedLinesWithStmt(
 const Stmt *S, SourceManager ,
-std::unique_ptr ) {
+FilesToLineNumsMap ) {
   SourceLocation Loc = S->getSourceRange().getBegin();
   if (!Loc.isValid())
 return;
   SourceLocation ExpansionLoc = SM.getExpansionLoc(Loc);
   FileID FID = SM.getFileID(ExpansionLoc);
   unsigned LineNo = SM.getExpansionLineNumber(ExpansionLoc);
-  ExecutedLines->operator[](FID).insert(LineNo);
+  ExecutedLines[FID].insert(LineNo);
 }
 
 /// \return all executed lines including function signatures on the path
@@ -3055,27 +3055,27 @@
 if (N->getFirstPred() == nullptr) {
   // First node: show signature of the entrance point.
   const Decl *D = N->getLocationContext()->getDecl();
-  populateExecutedLinesWithFunctionSignature(D, SM, ExecutedLines);
+  populateExecutedLinesWithFunctionSignature(D, SM, *ExecutedLines);
 } else if (auto CE = 

[PATCH] D51515: [analyzer] Add coverage information to plist output, update tests

2018-09-06 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC341621: [analyzer] Add coverage information to plist output, 
update tests (authored by george.karpenkov, committed by ).
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D51515?vs=163423=164340#toc

Repository:
  rC Clang

https://reviews.llvm.org/D51515

Files:
  include/clang/Basic/PlistSupport.h
  lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  test/Analysis/Inputs/expected-plists/NewDelete-path-notes.cpp.plist
  test/Analysis/Inputs/expected-plists/conditional-path-notes.c.plist
  test/Analysis/Inputs/expected-plists/cxx-for-range.cpp.plist
  test/Analysis/Inputs/expected-plists/edges-new.mm.plist
  test/Analysis/Inputs/expected-plists/generics.m.plist
  test/Analysis/Inputs/expected-plists/inline-plist.c.plist
  test/Analysis/Inputs/expected-plists/inline-unique-reports.c.plist
  test/Analysis/Inputs/expected-plists/lambda-notes.cpp.plist
  test/Analysis/Inputs/expected-plists/malloc-plist.c.plist
  test/Analysis/Inputs/expected-plists/method-call-path-notes.cpp.plist
  test/Analysis/Inputs/expected-plists/model-file.cpp.plist
  test/Analysis/Inputs/expected-plists/null-deref-path-notes.m.plist
  test/Analysis/Inputs/expected-plists/nullability-notes.m.plist
  test/Analysis/Inputs/expected-plists/objc-arc.m.plist
  test/Analysis/Inputs/expected-plists/plist-macros.cpp.plist
  test/Analysis/Inputs/expected-plists/plist-output-alternate.m.plist
  test/Analysis/Inputs/expected-plists/plist-output.m.plist
  test/Analysis/Inputs/expected-plists/retain-release-path-notes.m.plist
  test/Analysis/Inputs/expected-plists/unix-fns.c.plist
  test/Analysis/MismatchedDeallocator-path-notes.cpp
  
test/Analysis/copypaste/Inputs/expected-plists/MismatchedDeallocator-path-notes.cpp.plist
  
test/Analysis/copypaste/Inputs/expected-plists/plist-diagnostics-notes-as-events.cpp.plist
  test/Analysis/copypaste/Inputs/expected-plists/plist-diagnostics.cpp.plist
  test/Analysis/cstring-plist.c
  
test/Analysis/diagnostics/Inputs/expected-plists/deref-track-symbolic-region.c.plist
  
test/Analysis/diagnostics/Inputs/expected-plists/plist-diagnostics-include-check.cpp.plist
  test/Analysis/diagnostics/Inputs/expected-plists/plist-multi-file.c.plist
  
test/Analysis/diagnostics/Inputs/expected-plists/report-issues-within-main-file.cpp.plist
  test/Analysis/diagnostics/Inputs/expected-plists/undef-value-caller.c.plist
  test/Analysis/diagnostics/Inputs/expected-plists/undef-value-param.c.plist
  test/Analysis/diagnostics/Inputs/expected-plists/undef-value-param.m.plist
  test/Analysis/diagnostics/plist-diagnostics-include-check.cpp
  test/Analysis/diagnostics/plist-multi-file.c
  test/Analysis/diagnostics/report-issues-within-main-file.cpp
  
test/Analysis/inlining/Inputs/expected-plists/eager-reclamation-path-notes.c.plist
  
test/Analysis/inlining/Inputs/expected-plists/eager-reclamation-path-notes.cpp.plist
  test/Analysis/inlining/Inputs/expected-plists/path-notes.c.plist
  test/Analysis/inlining/Inputs/expected-plists/path-notes.cpp.plist
  test/Analysis/inlining/Inputs/expected-plists/path-notes.m.plist
  test/Analysis/lambda-notes.cpp
  test/Analysis/malloc-plist.c
  test/Analysis/plist-stats-output.c
  test/Analysis/unix-fns.c



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


[PATCH] D45416: [AST, analyzer] Transform rvalue cast outputs to lvalues (fheinous-gnu-extensions)

2018-09-06 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.
Herald added a subscriber: Szelethus.

Dunno, i guess you can just commit it.




Comment at: lib/Sema/SemaStmtAsm.cpp:57
+  }
+Parent = Child;
+  }

Like father, like son :D


Repository:
  rC Clang

https://reviews.llvm.org/D45416



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


r341618 - [analyzer] Do not add invalid source location to the coverage information

2018-09-06 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Thu Sep  6 17:43:17 2018
New Revision: 341618

URL: http://llvm.org/viewvc/llvm-project?rev=341618=rev
Log:
[analyzer] Do not add invalid source location to the coverage information

Invalid source locations may arise from generated code.

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

Added:
cfe/trunk/test/Analysis/html_diagnostics/relevant_lines/synthesized_body.cpp
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp?rev=341618=341617=341618=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp Thu Sep  6 17:43:17 2018
@@ -1892,6 +1892,7 @@ static void updateExecutedLinesWithDiagn
 FullSourceLoc Loc = P->getLocation().asLocation().getExpansionLoc();
 FileID FID = Loc.getFileID();
 unsigned LineNo = Loc.getLineNumber();
+assert(FID.isValid());
 ExecutedLines[FID.getHashValue()].insert(LineNo);
   }
 }
@@ -3022,6 +3023,8 @@ static void populateExecutedLinesWithFun
   SourceLocation Start = SignatureSourceRange.getBegin();
   SourceLocation End = Body ? Body->getSourceRange().getBegin()
 : SignatureSourceRange.getEnd();
+  if (!Start.isValid() || !End.isValid())
+return;
   unsigned StartLine = SM.getExpansionLineNumber(Start);
   unsigned EndLine = SM.getExpansionLineNumber(End);
 
@@ -3034,6 +3037,8 @@ static void populateExecutedLinesWithStm
 const Stmt *S, SourceManager ,
 std::unique_ptr ) {
   SourceLocation Loc = S->getSourceRange().getBegin();
+  if (!Loc.isValid())
+return;
   SourceLocation ExpansionLoc = SM.getExpansionLoc(Loc);
   FileID FID = SM.getFileID(ExpansionLoc);
   unsigned LineNo = SM.getExpansionLineNumber(ExpansionLoc);

Added: 
cfe/trunk/test/Analysis/html_diagnostics/relevant_lines/synthesized_body.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/html_diagnostics/relevant_lines/synthesized_body.cpp?rev=341618=auto
==
--- 
cfe/trunk/test/Analysis/html_diagnostics/relevant_lines/synthesized_body.cpp 
(added)
+++ 
cfe/trunk/test/Analysis/html_diagnostics/relevant_lines/synthesized_body.cpp 
Thu Sep  6 17:43:17 2018
@@ -0,0 +1,25 @@
+// Faking std::call_once implementation.
+namespace std {
+typedef struct once_flag_s {
+  int _M_once = 0;
+} once_flag;
+
+template 
+void call_once(once_flag , Callable&& func, Args&&... args);
+} // namespace std
+
+int deref(int *x) {
+  return *x;
+}
+
+void call_deref_once() {
+  static std::once_flag once;
+  int *p = nullptr;
+  std::call_once(once, , p);
+}
+
+
+// RUN: rm -rf %t.output
+// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core -analyzer-output 
html -o %t.output %s
+// RUN: cat %t.output/* | FileCheck %s --match-full-lines
+// CHECK: var relevant_lines = {"1": {"3": 1,  "8": 1, "11": 1, "12": 1, "15": 
1, "16": 1, "17": 1, "18": 1}};


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


r341620 - [analyzer] [NFC] Prefer passing around reference to std::unique_ptr

2018-09-06 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Thu Sep  6 17:43:55 2018
New Revision: 341620

URL: http://llvm.org/viewvc/llvm-project?rev=341620=rev
Log:
[analyzer] [NFC] Prefer passing around reference to std::unique_ptr&

When object is owned elsewhere

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp?rev=341620=341619=341620=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp Thu Sep  6 17:43:55 2018
@@ -3010,7 +3010,7 @@ void BugReporter::FlushReport(BugReportE
 /// into \p ExecutedLines.
 static void populateExecutedLinesWithFunctionSignature(
 const Decl *Signature, SourceManager ,
-std::unique_ptr ) {
+FilesToLineNumsMap ) {
   SourceRange SignatureSourceRange;
   const Stmt* Body = Signature->getBody();
   if (const auto FD = dyn_cast(Signature)) {
@@ -3030,19 +3030,19 @@ static void populateExecutedLinesWithFun
 
   FileID FID = SM.getFileID(SM.getExpansionLoc(Start));
   for (unsigned Line = StartLine; Line <= EndLine; Line++)
-ExecutedLines->operator[](FID).insert(Line);
+ExecutedLines[FID].insert(Line);
 }
 
 static void populateExecutedLinesWithStmt(
 const Stmt *S, SourceManager ,
-std::unique_ptr ) {
+FilesToLineNumsMap ) {
   SourceLocation Loc = S->getSourceRange().getBegin();
   if (!Loc.isValid())
 return;
   SourceLocation ExpansionLoc = SM.getExpansionLoc(Loc);
   FileID FID = SM.getFileID(ExpansionLoc);
   unsigned LineNo = SM.getExpansionLineNumber(ExpansionLoc);
-  ExecutedLines->operator[](FID).insert(LineNo);
+  ExecutedLines[FID].insert(LineNo);
 }
 
 /// \return all executed lines including function signatures on the path
@@ -3055,13 +3055,13 @@ findExecutedLines(SourceManager , con
 if (N->getFirstPred() == nullptr) {
   // First node: show signature of the entrance point.
   const Decl *D = N->getLocationContext()->getDecl();
-  populateExecutedLinesWithFunctionSignature(D, SM, ExecutedLines);
+  populateExecutedLinesWithFunctionSignature(D, SM, *ExecutedLines);
 } else if (auto CE = N->getLocationAs()) {
   // Inlined function: show signature.
   const Decl* D = CE->getCalleeContext()->getDecl();
-  populateExecutedLinesWithFunctionSignature(D, SM, ExecutedLines);
+  populateExecutedLinesWithFunctionSignature(D, SM, *ExecutedLines);
 } else if (const Stmt *S = PathDiagnosticLocation::getStmt(N)) {
-  populateExecutedLinesWithStmt(S, SM, ExecutedLines);
+  populateExecutedLinesWithStmt(S, SM, *ExecutedLines);
 
   // Show extra context for some parent kinds.
   const Stmt *P = N->getParentMap().getParent(S);
@@ -3070,12 +3070,12 @@ findExecutedLines(SourceManager , con
   // return statement is generated, but we do want to show the whole
   // return.
   if (const auto *RS = dyn_cast_or_null(P)) {
-populateExecutedLinesWithStmt(RS, SM, ExecutedLines);
+populateExecutedLinesWithStmt(RS, SM, *ExecutedLines);
 P = N->getParentMap().getParent(RS);
   }
 
   if (P && (isa(P) || isa(P)))
-populateExecutedLinesWithStmt(P, SM, ExecutedLines);
+populateExecutedLinesWithStmt(P, SM, *ExecutedLines);
 }
 
 N = N->getFirstPred();


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


r341619 - [analyzer] Executed lines: store file IDs, not hashes.

2018-09-06 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Thu Sep  6 17:43:37 2018
New Revision: 341619

URL: http://llvm.org/viewvc/llvm-project?rev=341619=rev
Log:
[analyzer] Executed lines: store file IDs, not hashes.

Raw FileIDs are needed for the PlistDiagnostics to produce stable filenames.

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h?rev=341619=341618=341619=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h 
Thu Sep  6 17:43:37 2018
@@ -759,7 +759,7 @@ public:
 };
 
 /// File IDs mapped to sets of line numbers.
-using FilesToLineNumsMap = std::map>;
+using FilesToLineNumsMap = std::map>;
 
 /// PathDiagnostic - PathDiagnostic objects represent a single path-sensitive
 ///  diagnostic.  It represents an ordered-collection of PathDiagnosticPieces,

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp?rev=341619=341618=341619=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp Thu Sep  6 17:43:37 2018
@@ -1893,7 +1893,7 @@ static void updateExecutedLinesWithDiagn
 FileID FID = Loc.getFileID();
 unsigned LineNo = Loc.getLineNumber();
 assert(FID.isValid());
-ExecutedLines[FID.getHashValue()].insert(LineNo);
+ExecutedLines[FID].insert(LineNo);
   }
 }
 
@@ -3030,7 +3030,7 @@ static void populateExecutedLinesWithFun
 
   FileID FID = SM.getFileID(SM.getExpansionLoc(Start));
   for (unsigned Line = StartLine; Line <= EndLine; Line++)
-ExecutedLines->operator[](FID.getHashValue()).insert(Line);
+ExecutedLines->operator[](FID).insert(Line);
 }
 
 static void populateExecutedLinesWithStmt(
@@ -3042,7 +3042,7 @@ static void populateExecutedLinesWithStm
   SourceLocation ExpansionLoc = SM.getExpansionLoc(Loc);
   FileID FID = SM.getFileID(ExpansionLoc);
   unsigned LineNo = SM.getExpansionLineNumber(ExpansionLoc);
-  ExecutedLines->operator[](FID.getHashValue()).insert(LineNo);
+  ExecutedLines->operator[](FID).insert(LineNo);
 }
 
 /// \return all executed lines including function signatures on the path

Modified: cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp?rev=341619=341618=341619=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp Thu Sep  6 17:43:37 
2018
@@ -346,7 +346,7 @@ static void serializeExecutedLines(
 if (I != ExecutedLines.begin())
   os << ", ";
 
-os << "\"" << I->first << "\": {";
+os << "\"" << I->first.getHashValue() << "\": {";
 for (unsigned LineNo : I->second) {
   if (LineNo != *(I->second.begin()))
 os << ", ";


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


r341616 - [analyzer] Skip printing trivial nodes in exploded graph

2018-09-06 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Thu Sep  6 17:42:32 2018
New Revision: 341616

URL: http://llvm.org/viewvc/llvm-project?rev=341616=rev
Log:
[analyzer] Skip printing trivial nodes in exploded graph

A node is considered to be trivial if it only has one successor, one
predecessor, and a state equal to the predecessor.
Can drastically (> 2x) reduce the size of the generated exploded
graph.

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h?rev=341616=341615=341616=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h 
Thu Sep  6 17:42:32 2018
@@ -242,6 +242,11 @@ public:
 
   int64_t getID(ExplodedGraph *G) const;
 
+  /// The node is trivial if it has only one successor, only one predecessor,
+  /// and its program state is the same as the program state of the previous
+  /// node.
+  bool isTrivial() const;
+
 private:
   void replaceSuccessor(ExplodedNode *node) { Succs.replaceNode(node); }
   void replacePredecessor(ExplodedNode *node) { Preds.replaceNode(node); }
@@ -463,9 +468,19 @@ namespace llvm {
 
 static NodeRef getEntryNode(NodeRef N) { return N; }
 
-static ChildIteratorType child_begin(NodeRef N) { return N->succ_begin(); }
-
-static ChildIteratorType child_end(NodeRef N) { return N->succ_end(); }
+static ChildIteratorType child_begin(NodeRef N) {
+  if (N->succ_size() == 1 && (*N->succ_begin())->isTrivial()) {
+return child_begin(*N->succ_begin());
+  }
+  return N->succ_begin();
+}
+
+static ChildIteratorType child_end(NodeRef N) {
+  if (N->succ_size() == 1 && (*N->succ_begin())->isTrivial()) {
+return child_end(*N->succ_begin());
+  }
+  return N->succ_end();
+}
 
 static nodes_iterator nodes_begin(NodeRef N) { return df_begin(N); }
 

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp?rev=341616=341615=341616=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp Thu Sep  6 17:42:32 2018
@@ -290,6 +290,11 @@ int64_t ExplodedNode::getID(ExplodedGrap
   return *Out / alignof(ExplodedNode);
 }
 
+bool ExplodedNode::isTrivial() const {
+  return pred_size() == 1 && succ_size() == 1 &&
+ (*pred_begin())->getState()->getID() == getState()->getID();
+}
+
 ExplodedNode *ExplodedGraph::getNode(const ProgramPoint ,
  ProgramStateRef State,
  bool IsSink,

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=341616=341615=341616=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Thu Sep  6 17:42:32 2018
@@ -2974,6 +2974,7 @@ struct DOTGraphTraits : p
   }
 
   static void dumpProgramPoint(ProgramPoint Loc,
+   const PrintingPolicy ,
llvm::raw_string_ostream ) {
 switch (Loc.getKind()) {
 case ProgramPoint::BlockEntranceKind:
@@ -3112,8 +3113,7 @@ struct DOTGraphTraits : p
   assert(S != nullptr && "Expecting non-null Stmt");
 
   Out << S->getStmtClassName() << ' ' << (const void *)S << ' ';
-  LangOptions LO; // FIXME.
-  S->printPretty(Out, nullptr, PrintingPolicy(LO));
+  S->printPretty(Out, nullptr, PP);
   printLocation(Out, S->getBeginLoc());
 
   if (Loc.getAs())
@@ -3132,32 +3132,52 @@ struct DOTGraphTraits : p
 }
   }
 
+  static bool isNodeHidden(const ExplodedNode *N) {
+return N->isTrivial();
+  }
+
   static std::string getNodeLabel(const ExplodedNode *N, void*){
 std::string sbuf;
 llvm::raw_string_ostream Out(sbuf);
 
-// Program Location.
-ProgramPoint Loc = N->getLocation();
+// Find the first node which program point and tag has to be included in
+// the output.
+const ExplodedNode *FirstHiddenNode = N;
+while (FirstHiddenNode->pred_size() == 1 &&
+   isNodeHidden(*FirstHiddenNode->pred_begin())) {
+  FirstHiddenNode = *FirstHiddenNode->pred_begin();
+}
+
+ProgramStateRef State = 

r341617 - [analyzer] Push updating-the-executed-lines logic into the BugReporter.

2018-09-06 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Thu Sep  6 17:42:53 2018
New Revision: 341617

URL: http://llvm.org/viewvc/llvm-project?rev=341617=rev
Log:
[analyzer] Push updating-the-executed-lines logic into the BugReporter.

So it can be reused across different consumers.

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h?rev=341617=341616=341617=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h 
Thu Sep  6 17:42:53 2018
@@ -858,13 +858,13 @@ public:
   meta_iterator meta_end() const { return OtherDesc.end(); }
   void addMeta(StringRef s) { OtherDesc.push_back(s); }
 
-  using filesmap_iterator = FilesToLineNumsMap::const_iterator;
-
-  filesmap_iterator executedLines_begin() const {
-return ExecutedLines->begin();
+  const FilesToLineNumsMap () const {
+return *ExecutedLines;
   }
 
-  filesmap_iterator executedLines_end() const { return ExecutedLines->end(); }
+  FilesToLineNumsMap () {
+return *ExecutedLines;
+  }
 
   PathDiagnosticLocation getLocation() const {
 return Loc;

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp?rev=341617=341616=341617=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp Thu Sep  6 17:42:53 2018
@@ -1881,6 +1881,21 @@ static void dropFunctionEntryEdge(PathPi
 using VisitorsDiagnosticsTy = llvm::DenseMap>>;
 
+/// Populate executes lines with lines containing at least one diagnostics.
+static void updateExecutedLinesWithDiagnosticPieces(
+  PathDiagnostic ) {
+
+  PathPieces path = PD.path.flatten(/*ShouldFlattenMacros=*/true);
+  FilesToLineNumsMap  = PD.getExecutedLines();
+
+  for (const auto  : path) {
+FullSourceLoc Loc = P->getLocation().asLocation().getExpansionLoc();
+FileID FID = Loc.getFileID();
+unsigned LineNo = Loc.getLineNumber();
+ExecutedLines[FID.getHashValue()].insert(LineNo);
+  }
+}
+
 /// This function is responsible for generating diagnostic pieces that are
 /// *not* provided by bug report visitors.
 /// These diagnostics may differ depending on the consumer's settings,
@@ -2985,6 +3000,7 @@ void BugReporter::FlushReport(BugReportE
 for (const auto  : Meta)
   PD->addMeta(i);
 
+updateExecutedLinesWithDiagnosticPieces(*PD);
 Consumer->HandlePathDiagnostic(std::move(PD));
   }
 }

Modified: cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp?rev=341617=341616=341617=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp Thu Sep  6 17:42:53 
2018
@@ -337,23 +337,8 @@ static void serializeExecutedLines(
 const PathDiagnostic ,
 const PathPieces ,
 llvm::raw_string_ostream ) {
-  // Copy executed lines from path diagnostics.
-  std::map> ExecutedLines;
-  for (auto I = D.executedLines_begin(),
-E = D.executedLines_end(); I != E; ++I) {
-std::set  = ExecutedLines[I->first];
-for (unsigned LineNo : I->second) {
-  LinesInFile.insert(LineNo);
-}
-  }
 
-  // We need to include all lines for which any kind of diagnostics appears.
-  for (const auto  : path) {
-FullSourceLoc Loc = P->getLocation().asLocation().getExpansionLoc();
-FileID FID = Loc.getFileID();
-unsigned LineNo = Loc.getLineNumber();
-ExecutedLines[FID.getHashValue()].insert(LineNo);
-  }
+  const FilesToLineNumsMap  = D.getExecutedLines();
 
   os << "var relevant_lines = {";
   for (auto I = ExecutedLines.begin(),


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


[PATCH] D47344: LWG 2843 "Unclear behavior of std::pmr::memory_resource::do_allocate()"

2018-09-06 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

@EricWF ping?


Repository:
  rCXX libc++

https://reviews.llvm.org/D47344



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


[PATCH] D51189: [Sema][ObjC] Infer availability of +new from availability of -init

2018-09-06 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added a comment.

In https://reviews.llvm.org/D51189#1211910, @steven_wu wrote:

> I feel like this is a much tricky situation than just new and init. Following 
> example is the same situation.
>
>   __attribute__((objc_root_class))
>   @interface NSObject
>   - (void) foo;
>   - (void) bar;
>   @end
>  
>   @implementation NSObject
>   - (void) foo {}
>   - (void) bar { [self foo]; }
>   @end
>  
>   @interface MyObject : NSObject
>   - (void) foo __attribute__((unavailable));
>   @end
>  
>   void test(MyObject *obj) {
> [obj bar];
>   }
>
>
> We can do something about [NSObject new] because we know it's implementation 
> but we have to live with more general cases.


I agree that the general case is impossible to properly diagnose, but I think 
its totally reasonable for us to special case this pattern with NSObject.




Comment at: clang/lib/Sema/SemaDeclAttr.cpp:6951
+ std::string *Message,
+ ObjCInterfaceDecl *ClassMessageReceiver) {
   AvailabilityResult Result = D->getAvailability(Message);

arphaman wrote:
> Please be consistent with the name, you are using `ClassMessageReceiver`, 
> `ClassReceiver` and `Receiver` in different arguments in this patch.
Sure, sorry. I canonicalized on ClassReceiver.


https://reviews.llvm.org/D51189



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


[PATCH] D51189: [Sema][ObjC] Infer availability of +new from availability of -init

2018-09-06 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington updated this revision to Diff 164316.
erik.pilkington marked 4 inline comments as done.
erik.pilkington added a comment.

Address @arphaman's review comments.


https://reviews.llvm.org/D51189

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/DeclObjC.h
  clang/include/clang/AST/NSAPI.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/DeclObjC.cpp
  clang/lib/AST/NSAPI.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprObjC.cpp
  clang/test/SemaObjC/infer-availability-from-init.m

Index: clang/test/SemaObjC/infer-availability-from-init.m
===
--- /dev/null
+++ clang/test/SemaObjC/infer-availability-from-init.m
@@ -0,0 +1,58 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx-10.9 -Wunguarded-availability -fblocks -fsyntax-only -verify %s
+
+__attribute__((objc_root_class))
+@interface NSObject
++(instancetype)new;
+-(instancetype)init;
+@end
+
+@interface MyObject : NSObject
+-(instancetype)init __attribute__((unavailable)); // expected-note{{'init' has been explicitly marked unavailable here}}
+@end
+
+void usemyobject() {
+  [MyObject new]; // expected-error{{'new' is unavailable}}
+}
+
+@interface MyOtherObject : NSObject
++(instancetype)init __attribute__((unavailable));
++(instancetype)new;
+@end
+
+void usemyotherobject() {
+  [MyOtherObject new]; // no error; new is overrideen.
+}
+
+@interface NotGoodOverride : NSObject
++(instancetype)init __attribute__((unavailable));
+-(instancetype)new;
++(instancetype)new: (int)x;
+@end
+
+void usenotgoodoverride() {
+  [NotGoodOverride new]; // no error
+}
+
+@interface NotNSObject
++(instancetype)new;
+-(instancetype)init;
+@end
+
+@interface NotMyObject : NotNSObject
+-(instancetype)init __attribute__((unavailable));
+@end
+
+void usenotmyobject() {
+  [NotMyObject new]; // no error; this isn't NSObject
+}
+
+@interface FromSelf : NSObject
+-(instancetype)init __attribute__((unavailable)); // expected-note {{'init' has been explicitly marked unavailable here}}
++(FromSelf*)another_one;
+@end
+
+@implementation FromSelf
++(FromSelf*)another_one {
+  [self new]; // expected-error{{'new' is unavailable}}
+}
+@end
Index: clang/lib/Sema/SemaExprObjC.cpp
===
--- clang/lib/Sema/SemaExprObjC.cpp
+++ clang/lib/Sema/SemaExprObjC.cpp
@@ -2471,7 +2471,8 @@
 if (!Method)
   Method = Class->lookupPrivateClassMethod(Sel);
 
-if (Method && DiagnoseUseOfDecl(Method, SelectorSlotLocs))
+if (Method && DiagnoseUseOfDecl(Method, SelectorSlotLocs,
+nullptr, false, false, Class))
   return ExprError();
   }
 
@@ -2784,14 +2785,19 @@
   } else {
 if (ObjCMethodDecl *CurMeth = getCurMethodDecl()) {
   if (ObjCInterfaceDecl *ClassDecl = CurMeth->getClassInterface()) {
+// FIXME: Is this correct? Why are we assuming that a message to
+// Class will call a method in the current interface?
+
 // First check the public methods in the class interface.
 Method = ClassDecl->lookupClassMethod(Sel);
 
 if (!Method)
   Method = ClassDecl->lookupPrivateClassMethod(Sel);
+
+if (Method && DiagnoseUseOfDecl(Method, SelectorSlotLocs, nullptr,
+false, false, ClassDecl))
+  return ExprError();
   }
-  if (Method && DiagnoseUseOfDecl(Method, SelectorSlotLocs))
-return ExprError();
 }
 if (!Method) {
   // If not messaging 'self', look for any factory method named 'Sel'.
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -206,7 +206,8 @@
 bool Sema::DiagnoseUseOfDecl(NamedDecl *D, ArrayRef Locs,
  const ObjCInterfaceDecl *UnknownObjCClass,
  bool ObjCPropertyAccess,
- bool AvoidPartialAvailabilityChecks) {
+ bool AvoidPartialAvailabilityChecks,
+ ObjCInterfaceDecl *ClassReceiver) {
   SourceLocation Loc = Locs.front();
   if (getLangOpts().CPlusPlus && isa(D)) {
 // If there were any diagnostics suppressed by template argument deduction,
@@ -292,7 +293,7 @@
   }
 
   DiagnoseAvailabilityOfDecl(D, Locs, UnknownObjCClass, ObjCPropertyAccess,
- AvoidPartialAvailabilityChecks);
+ AvoidPartialAvailabilityChecks, ClassReceiver);
 
   DiagnoseUnusedOfDecl(*this, D, Loc);
 
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -6959,8 +6959,12 @@
 /// \param D The declaration to check.
 /// \param 

[PATCH] D51395: [analyzer] Dump a reproducible, deterministic ID of program state to exploded graph

2018-09-06 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL341600: [analyzer] Dump a reproducible, deterministic ID of 
program state to exploded… (authored by george.karpenkov, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D51395?vs=163247=164310#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D51395

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp


Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -3141,7 +3141,8 @@
 }
 
 ProgramStateRef state = N->getState();
-Out << "\\|StateID: " << (const void*) state.get()
+Out << "\\|StateID: " << state->getID() << " ("
+<< (const void*) state.get() << ")"
 << " NodeID: " << (const void*) N << "\\|";
 
 state->printDOT(Out, N->getLocationContext());
Index: cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -69,6 +69,13 @@
 stateMgr->getStoreManager().decrementReferenceCount(store);
 }
 
+int64_t ProgramState::getID() const {
+  Optional Out = getStateManager().Alloc.identifyObject(this);
+  assert(Out && "Wrong allocator used");
+  assert(*Out % alignof(ProgramState) == 0 && "Wrong alignment information");
+  return *Out / alignof(ProgramState);
+}
+
 ProgramStateManager::ProgramStateManager(ASTContext ,
  StoreManagerCreator CreateSMgr,
  ConstraintManagerCreator CreateCMgr,
Index: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -107,6 +107,8 @@
 
   ~ProgramState();
 
+  int64_t getID() const;
+
   /// Return the ProgramStateManager associated with this state.
   ProgramStateManager () const {
 return *stateMgr;


Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -3141,7 +3141,8 @@
 }
 
 ProgramStateRef state = N->getState();
-Out << "\\|StateID: " << (const void*) state.get()
+Out << "\\|StateID: " << state->getID() << " ("
+<< (const void*) state.get() << ")"
 << " NodeID: " << (const void*) N << "\\|";
 
 state->printDOT(Out, N->getLocationContext());
Index: cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -69,6 +69,13 @@
 stateMgr->getStoreManager().decrementReferenceCount(store);
 }
 
+int64_t ProgramState::getID() const {
+  Optional Out = getStateManager().Alloc.identifyObject(this);
+  assert(Out && "Wrong allocator used");
+  assert(*Out % alignof(ProgramState) == 0 && "Wrong alignment information");
+  return *Out / alignof(ProgramState);
+}
+
 ProgramStateManager::ProgramStateManager(ASTContext ,
  StoreManagerCreator CreateSMgr,
  ConstraintManagerCreator CreateCMgr,
Index: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -107,6 +107,8 @@
 
   ~ProgramState();
 
+  int64_t getID() const;
+
   /// Return the ProgramStateManager associated with this state.
   ProgramStateManager () const {
 return *stateMgr;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r341603 - [analyzer] [NFC] Move dumping program point into a separate function

2018-09-06 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Thu Sep  6 16:08:27 2018
New Revision: 341603

URL: http://llvm.org/viewvc/llvm-project?rev=341603=rev
Log:
[analyzer] [NFC] Move dumping program point into a separate function

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=341603=341602=341603=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Thu Sep  6 16:08:27 2018
@@ -2973,172 +2973,173 @@ struct DOTGraphTraits : p
 }
   }
 
-  static std::string getNodeLabel(const ExplodedNode *N, void*){
-std::string sbuf;
-llvm::raw_string_ostream Out(sbuf);
-
-// Program Location.
-ProgramPoint Loc = N->getLocation();
-
+  static void dumpProgramPoint(ProgramPoint Loc,
+   llvm::raw_string_ostream ) {
 switch (Loc.getKind()) {
-  case ProgramPoint::BlockEntranceKind:
-Out << "Block Entrance: B"
-<< Loc.castAs().getBlock()->getBlockID();
-break;
-
-  case ProgramPoint::BlockExitKind:
-assert(false);
-break;
-
-  case ProgramPoint::CallEnterKind:
-Out << "CallEnter";
-break;
-
-  case ProgramPoint::CallExitBeginKind:
-Out << "CallExitBegin";
-break;
-
-  case ProgramPoint::CallExitEndKind:
-Out << "CallExitEnd";
-break;
-
-  case ProgramPoint::PostStmtPurgeDeadSymbolsKind:
-Out << "PostStmtPurgeDeadSymbols";
-break;
-
-  case ProgramPoint::PreStmtPurgeDeadSymbolsKind:
-Out << "PreStmtPurgeDeadSymbols";
-break;
-
-  case ProgramPoint::EpsilonKind:
-Out << "Epsilon Point";
-break;
-
-  case ProgramPoint::LoopExitKind: {
-LoopExit LE = Loc.castAs();
-Out << "LoopExit: " << LE.getLoopStmt()->getStmtClassName();
-break;
-  }
+case ProgramPoint::BlockEntranceKind:
+  Out << "Block Entrance: B"
+  << Loc.castAs().getBlock()->getBlockID();
+  break;
+
+case ProgramPoint::BlockExitKind:
+  assert(false);
+  break;
+
+case ProgramPoint::CallEnterKind:
+  Out << "CallEnter";
+  break;
+
+case ProgramPoint::CallExitBeginKind:
+  Out << "CallExitBegin";
+  break;
+
+case ProgramPoint::CallExitEndKind:
+  Out << "CallExitEnd";
+  break;
+
+case ProgramPoint::PostStmtPurgeDeadSymbolsKind:
+  Out << "PostStmtPurgeDeadSymbols";
+  break;
+
+case ProgramPoint::PreStmtPurgeDeadSymbolsKind:
+  Out << "PreStmtPurgeDeadSymbols";
+  break;
+
+case ProgramPoint::EpsilonKind:
+  Out << "Epsilon Point";
+  break;
+
+case ProgramPoint::LoopExitKind: {
+  LoopExit LE = Loc.castAs();
+  Out << "LoopExit: " << LE.getLoopStmt()->getStmtClassName();
+  break;
+}
 
-  case ProgramPoint::PreImplicitCallKind: {
-ImplicitCallPoint PC = Loc.castAs();
-Out << "PreCall: ";
-
-// FIXME: Get proper printing options.
-PC.getDecl()->print(Out, LangOptions());
-printLocation(Out, PC.getLocation());
-break;
-  }
+case ProgramPoint::PreImplicitCallKind: {
+  ImplicitCallPoint PC = Loc.castAs();
+  Out << "PreCall: ";
+
+  // FIXME: Get proper printing options.
+  PC.getDecl()->print(Out, LangOptions());
+  printLocation(Out, PC.getLocation());
+  break;
+}
 
-  case ProgramPoint::PostImplicitCallKind: {
-ImplicitCallPoint PC = Loc.castAs();
-Out << "PostCall: ";
-
-// FIXME: Get proper printing options.
-PC.getDecl()->print(Out, LangOptions());
-printLocation(Out, PC.getLocation());
-break;
-  }
+case ProgramPoint::PostImplicitCallKind: {
+  ImplicitCallPoint PC = Loc.castAs();
+  Out << "PostCall: ";
+
+  // FIXME: Get proper printing options.
+  PC.getDecl()->print(Out, LangOptions());
+  printLocation(Out, PC.getLocation());
+  break;
+}
 
-  case ProgramPoint::PostInitializerKind: {
-Out << "PostInitializer: ";
-const CXXCtorInitializer *Init =
+case ProgramPoint::PostInitializerKind: {
+  Out << "PostInitializer: ";
+  const CXXCtorInitializer *Init =
   Loc.castAs().getInitializer();
-if (const FieldDecl *FD = Init->getAnyMember())
-  Out << *FD;
-else {
-  QualType Ty = Init->getTypeSourceInfo()->getType();
-  Ty = Ty.getLocalUnqualifiedType();
-  LangOptions LO; // FIXME.
-  Ty.print(Out, LO);
-}
-break;
+  if (const FieldDecl *FD = Init->getAnyMember())
+Out << *FD;
+  else {
+QualType Ty = 

[PATCH] D51655: [analyzer] Remove traces of ubigraph visualization

2018-09-06 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL341601: [analyzer] Remove traces of ubigraph visualization 
(authored by george.karpenkov, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D51655?vs=163895=164311#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D51655

Files:
  cfe/trunk/include/clang/Driver/CC1Options.td
  cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
  cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
  cfe/trunk/test/Analysis/ubigraph-viz.cpp
  cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py
  cfe/trunk/tools/scan-build/libexec/ccc-analyzer
  cfe/trunk/utils/analyzer/ubiviz

Index: cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -50,8 +50,6 @@
 
 #define DEBUG_TYPE "AnalysisConsumer"
 
-static std::unique_ptr CreateUbiViz();
-
 STATISTIC(NumFunctionTopLevel, "The # of functions at top level.");
 STATISTIC(NumFunctionsAnalyzed,
   "The # of functions and blocks analyzed (as top level "
@@ -743,21 +741,10 @@
   ExprEngine Eng(CTU, *Mgr, ObjCGCEnabled, VisitedCallees, ,
  IMode);
 
-  // Set the graph auditor.
-  std::unique_ptr Auditor;
-  if (Mgr->options.visualizeExplodedGraphWithUbiGraph) {
-Auditor = CreateUbiViz();
-ExplodedNode::SetAuditor(Auditor.get());
-  }
-
   // Execute the worklist algorithm.
   Eng.ExecuteWorkList(Mgr->getAnalysisDeclContextManager().getStackFrame(D),
   Mgr->options.getMaxNodesPerTopLevelFunction());
 
-  // Release the auditor (if any) so that it doesn't monitor the graph
-  // created BugReporter.
-  ExplodedNode::SetAuditor(nullptr);
-
   // Visualize the exploded graph.
   if (Mgr->options.visualizeExplodedGraphWithGraphViz)
 Eng.ViewGraph(Mgr->options.TrimGraph);
@@ -803,98 +790,3 @@
   CI.getFrontendOpts().Plugins,
   hasModelPath ? new ModelInjector(CI) : nullptr);
 }
-
-//===--===//
-// Ubigraph Visualization.  FIXME: Move to separate file.
-//===--===//
-
-namespace {
-
-class UbigraphViz : public ExplodedNode::Auditor {
-  std::unique_ptr Out;
-  std::string Filename;
-  unsigned Cntr;
-
-  typedef llvm::DenseMap VMap;
-  VMap M;
-
-public:
-  UbigraphViz(std::unique_ptr Out, StringRef Filename);
-
-  ~UbigraphViz() override;
-
-  void AddEdge(ExplodedNode *Src, ExplodedNode *Dst) override;
-};
-
-} // end anonymous namespace
-
-static std::unique_ptr CreateUbiViz() {
-  SmallString<128> P;
-  int FD;
-  llvm::sys::fs::createTemporaryFile("llvm_ubi", "", FD, P);
-  llvm::errs() << "Writing '" << P << "'.\n";
-
-  auto Stream = llvm::make_unique(FD, true);
-
-  return llvm::make_unique(std::move(Stream), P);
-}
-
-void UbigraphViz::AddEdge(ExplodedNode *Src, ExplodedNode *Dst) {
-
-  assert (Src != Dst && "Self-edges are not allowed.");
-
-  // Lookup the Src.  If it is a new node, it's a root.
-  VMap::iterator SrcI= M.find(Src);
-  unsigned SrcID;
-
-  if (SrcI == M.end()) {
-M[Src] = SrcID = Cntr++;
-*Out << "('vertex', " << SrcID << ", ('color','#00ff00'))\n";
-  }
-  else
-SrcID = SrcI->second;
-
-  // Lookup the Dst.
-  VMap::iterator DstI= M.find(Dst);
-  unsigned DstID;
-
-  if (DstI == M.end()) {
-M[Dst] = DstID = Cntr++;
-*Out << "('vertex', " << DstID << ")\n";
-  }
-  else {
-// We have hit DstID before.  Change its style to reflect a cache hit.
-DstID = DstI->second;
-*Out << "('change_vertex_style', " << DstID << ", 1)\n";
-  }
-
-  // Add the edge.
-  *Out << "('edge', " << SrcID << ", " << DstID
-   << ", ('arrow','true'), ('oriented', 'true'))\n";
-}
-
-UbigraphViz::UbigraphViz(std::unique_ptr OutStream,
- StringRef Filename)
-: Out(std::move(OutStream)), Filename(Filename), Cntr(0) {
-
-  *Out << "('vertex_style_attribute', 0, ('shape', 'icosahedron'))\n";
-  *Out << "('vertex_style', 1, 0, ('shape', 'sphere'), ('color', '#ffcc66'),"
-  " ('size', '1.5'))\n";
-}
-
-UbigraphViz::~UbigraphViz() {
-  Out.reset();
-  llvm::errs() << "Running 'ubiviz' program... ";
-  std::string ErrMsg;
-  std::string Ubiviz;
-  if (auto Path = llvm::sys::findProgramByName("ubiviz"))
-Ubiviz = *Path;
-  std::array Args{{Ubiviz, Filename}};
-
-  if (llvm::sys::ExecuteAndWait(Ubiviz, Args, llvm::None, {}, 0, 0, )) {
-llvm::errs() << "Error viewing graph: " << ErrMsg << 

r341602 - [analyzer] Dump stable identifiers for exploded nodes

2018-09-06 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Thu Sep  6 16:08:07 2018
New Revision: 341602

URL: http://llvm.org/viewvc/llvm-project?rev=341602=rev
Log:
[analyzer] Dump stable identifiers for exploded nodes

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h?rev=341602=341601=341602=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h 
Thu Sep  6 16:08:07 2018
@@ -240,6 +240,8 @@ public:
 return const_cast(this)->succ_end();
   }
 
+  int64_t getID(ExplodedGraph *G) const;
+
 private:
   void replaceSuccessor(ExplodedNode *node) { Succs.replaceNode(node); }
   void replacePredecessor(ExplodedNode *node) { Preds.replaceNode(node); }

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp?rev=341602=341601=341602=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp Thu Sep  6 16:08:07 2018
@@ -283,6 +283,13 @@ ExplodedNode * const *ExplodedNode::Node
   return Storage.getAddrOfPtr1() + 1;
 }
 
+int64_t ExplodedNode::getID(ExplodedGraph *G) const {
+  Optional Out = G->getAllocator().identifyObject(this);
+  assert(Out && "Wrong allocator used");
+  assert(*Out % alignof(ExplodedNode) == 0 && "Wrong alignment information");
+  return *Out / alignof(ExplodedNode);
+}
+
 ExplodedNode *ExplodedGraph::getNode(const ProgramPoint ,
  ProgramStateRef State,
  bool IsSink,

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=341602=341601=341602=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Thu Sep  6 16:08:07 2018
@@ -3141,9 +3141,13 @@ struct DOTGraphTraits : p
 }
 
 ProgramStateRef state = N->getState();
-Out << "\\|StateID: " << state->getID() << " ("
-<< (const void*) state.get() << ")"
-<< " NodeID: " << (const void*) N << "\\|";
+ExplodedGraph  =
+static_cast(state->getStateManager().getOwningEngine())
+->getGraph();
+
+Out << "\\|StateID: " << state->getID() << " (" << (const void 
*)state.get()
+<< ")"
+<< " NodeID: " << N->getID() << " (" << (const void *)N << 
")\\|";
 
 state->printDOT(Out, N->getLocationContext());
 


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


r341601 - [analyzer] Remove traces of ubigraph visualization

2018-09-06 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Thu Sep  6 16:07:47 2018
New Revision: 341601

URL: http://llvm.org/viewvc/llvm-project?rev=341601=rev
Log:
[analyzer] Remove traces of ubigraph visualization

Ubigraph project has been dead since about 2008, and to the best of my
knowledge, no one was using it.
Previously, I wasn't able to launch the existing binary at all.

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

Removed:
cfe/trunk/test/Analysis/ubigraph-viz.cpp
cfe/trunk/utils/analyzer/ubiviz
Modified:
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExplodedGraph.cpp
cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py
cfe/trunk/tools/scan-build/libexec/ccc-analyzer

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=341601=341600=341601=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Thu Sep  6 16:07:47 2018
@@ -80,8 +80,6 @@ def trim_egraph : Flag<["-"], "trim-egra
   HelpText<"Only show error-related paths in the analysis graph">;
 def analyzer_viz_egraph_graphviz : Flag<["-"], "analyzer-viz-egraph-graphviz">,
   HelpText<"Display exploded graph using GraphViz">;
-def analyzer_viz_egraph_ubigraph : Flag<["-"], "analyzer-viz-egraph-ubigraph">,
-  HelpText<"Display exploded graph using Ubigraph">;
 
 def analyzer_inline_max_stack_depth : Separate<["-"], 
"analyzer-inline-max-stack-depth">,
   HelpText<"Bound on stack depth while inlining (4 by default)">;

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h?rev=341601=341600=341601=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h Thu Sep  6 
16:07:47 2018
@@ -164,7 +164,6 @@ public:
 
   unsigned TrimGraph : 1;
   unsigned visualizeExplodedGraphWithGraphViz : 1;
-  unsigned visualizeExplodedGraphWithUbiGraph : 1;
   unsigned UnoptimizedCFG : 1;
   unsigned PrintStats : 1;
 
@@ -361,7 +360,7 @@ public:
 AnalyzerDisplayProgress(false), AnalyzeNestedBlocks(false),
 eagerlyAssumeBinOpBifurcation(false), TrimGraph(false),
 visualizeExplodedGraphWithGraphViz(false),
-visualizeExplodedGraphWithUbiGraph(false), UnoptimizedCFG(false),
+UnoptimizedCFG(false),
 PrintStats(false), NoRetryExhausted(false), CXXMemberInliningMode() {}
 
   /// Interprets an option's string value as a boolean. The "true" string is

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h?rev=341601=341600=341601=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h 
Thu Sep  6 16:07:47 2018
@@ -100,8 +100,7 @@ public:
   void FlushDiagnostics();
 
   bool shouldVisualize() const {
-return options.visualizeExplodedGraphWithGraphViz ||
-   options.visualizeExplodedGraphWithUbiGraph;
+return options.visualizeExplodedGraphWithGraphViz;
   }
 
   bool shouldInlineCall() const {

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h?rev=341601=341600=341601=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h 
Thu Sep  6 16:07:47 2018
@@ -240,18 +240,6 @@ public:
 return const_cast(this)->succ_end();
   }
 
-  // For debugging.
-
-public:
-  class Auditor {
-  public:
-virtual ~Auditor();
-
-virtual void AddEdge(ExplodedNode *Src, ExplodedNode *Dst) = 0;
-  };
-
-  static void SetAuditor(Auditor* A);
-
 private:
   void replaceSuccessor(ExplodedNode *node) { Succs.replaceNode(node); }
   void replacePredecessor(ExplodedNode *node) { Preds.replaceNode(node); }

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 

[PATCH] D51393: Provide a method for generating deterministic IDs for pointers allocated in BumpPtrAllocator

2018-09-06 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL341599: Provide a method for generating deterministic IDs 
for pointers allocated in… (authored by george.karpenkov, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D51393?vs=164294=164309#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D51393

Files:
  llvm/trunk/include/llvm/Support/Allocator.h


Index: llvm/trunk/include/llvm/Support/Allocator.h
===
--- llvm/trunk/include/llvm/Support/Allocator.h
+++ llvm/trunk/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,33 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = static_cast(Ptr);
+int64_t InSlabIdx = 0;
+for (size_t Idx = 0, E = Slabs.size(); Idx < E; Idx++) {
+  const char *S = static_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx + static_cast(P - S);
+  InSlabIdx += static_cast(computeSlabSize(Idx));
+}
+
+// Use negative index to denote custom sized slabs.
+int64_t InCustomSizedSlabIdx = -1;
+for (size_t Idx = 0, E = CustomSizedSlabs.size(); Idx < E; Idx++) {
+  const char *S = static_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return InCustomSizedSlabIdx - static_cast(P - S);
+  InCustomSizedSlabIdx -= static_cast(Size);
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)


Index: llvm/trunk/include/llvm/Support/Allocator.h
===
--- llvm/trunk/include/llvm/Support/Allocator.h
+++ llvm/trunk/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,33 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = static_cast(Ptr);
+int64_t InSlabIdx = 0;
+for (size_t Idx = 0, E = Slabs.size(); Idx < E; Idx++) {
+  const char *S = static_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx + static_cast(P - S);
+  InSlabIdx += static_cast(computeSlabSize(Idx));
+}
+
+// Use negative index to denote custom sized slabs.
+int64_t InCustomSizedSlabIdx = -1;
+for (size_t Idx = 0, E = CustomSizedSlabs.size(); Idx < E; Idx++) {
+  const char *S = static_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return InCustomSizedSlabIdx - static_cast(P - S);
+  InCustomSizedSlabIdx -= static_cast(Size);
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r341600 - [analyzer] Dump a reproducible, deterministic ID of program state to exploded graph

2018-09-06 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Thu Sep  6 16:07:26 2018
New Revision: 341600

URL: http://llvm.org/viewvc/llvm-project?rev=341600=rev
Log:
[analyzer] Dump a reproducible, deterministic ID of program state to exploded 
graph

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h?rev=341600=341599=341600=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
Thu Sep  6 16:07:26 2018
@@ -107,6 +107,8 @@ public:
 
   ~ProgramState();
 
+  int64_t getID() const;
+
   /// Return the ProgramStateManager associated with this state.
   ProgramStateManager () const {
 return *stateMgr;

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=341600=341599=341600=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Thu Sep  6 16:07:26 2018
@@ -3141,7 +3141,8 @@ struct DOTGraphTraits : p
 }
 
 ProgramStateRef state = N->getState();
-Out << "\\|StateID: " << (const void*) state.get()
+Out << "\\|StateID: " << state->getID() << " ("
+<< (const void*) state.get() << ")"
 << " NodeID: " << (const void*) N << "\\|";
 
 state->printDOT(Out, N->getLocationContext());

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp?rev=341600=341599=341600=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp Thu Sep  6 16:07:26 2018
@@ -69,6 +69,13 @@ ProgramState::~ProgramState() {
 stateMgr->getStoreManager().decrementReferenceCount(store);
 }
 
+int64_t ProgramState::getID() const {
+  Optional Out = getStateManager().Alloc.identifyObject(this);
+  assert(Out && "Wrong allocator used");
+  assert(*Out % alignof(ProgramState) == 0 && "Wrong alignment information");
+  return *Out / alignof(ProgramState);
+}
+
 ProgramStateManager::ProgramStateManager(ASTContext ,
  StoreManagerCreator CreateSMgr,
  ConstraintManagerCreator CreateCMgr,


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


[PATCH] D51038: [clang] Make sure codecompletion is called for calls even when inside a token.

2018-09-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: test/Index/complete-block-property-assignment.m:71
 
+// RUN: c-index-test -code-completion-at=%s:54:15 %s | FileCheck 
-check-prefix=CHECK-NO1 %s
+// CHECK-NO1: ObjCPropertyDecl:{ResultType int}{TypedText foo} (35)

ilya-biryukov wrote:
> ilya-biryukov wrote:
> > Any idea why behavior changed in that case?
> Looked at it more thoroughly now...
> So we're now showing both the signature help and the completion, right?
> If that the case, LG, but can we include the rest of completion items from 
> CHECK-N0? 
> 
> Maybe also add a comment that the last item is from overload set completion, 
> rather than the ordinary code completion? (To avoid confusion and make it 
> clear why we need an extra check there)
Yes, c-index-test binary collects results from both ProcessOverloadCandidate 
and ProcessCodeCompleteResults. Therefore they are merged. Adding the same set 
of results on the above is not enough for that particular case, due to the 
clever nature of CodeCompleteOverloadResult at 
https://github.com/llvm-mirror/clang/blob/master/lib/Sema/SemaCodeComplete.cpp#L4439.

It doesn't just try to tell you the overloads of that particular function but 
also tries to complete the current argument. Therefore the list simply gets 
huge by expansion of all the macros and other stuff.

But when looking into it I found out I was checking for wrong return values 
fixing that with the new diff.


Repository:
  rC Clang

https://reviews.llvm.org/D51038



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


[PATCH] D51038: [clang] Make sure codecompletion is called for calls even when inside a token.

2018-09-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 164307.
kadircet added a comment.

- Fix tests.


Repository:
  rC Clang

https://reviews.llvm.org/D51038

Files:
  include/clang/Parse/Parser.h
  lib/Parse/ParseExpr.cpp
  test/CodeCompletion/function-overloads-inside-param.cpp
  test/CodeCompletion/function-overloads.cpp
  test/Index/complete-block-property-assignment.m


Index: test/Index/complete-block-property-assignment.m
===
--- test/Index/complete-block-property-assignment.m
+++ test/Index/complete-block-property-assignment.m
@@ -60,13 +60,14 @@
 // RUN: c-index-test -code-completion-at=%s:51:16 %s | FileCheck 
-check-prefix=CHECK-NO %s
 // RUN: c-index-test -code-completion-at=%s:52:23 %s | FileCheck 
-check-prefix=CHECK-NO %s
 // RUN: c-index-test -code-completion-at=%s:53:12 %s | FileCheck 
-check-prefix=CHECK-NO %s
-// RUN: c-index-test -code-completion-at=%s:54:15 %s | FileCheck 
-check-prefix=CHECK-NO %s
 // RUN: c-index-test -code-completion-at=%s:56:15 %s | FileCheck 
-check-prefix=CHECK-NO %s
 // CHECK-NO: ObjCPropertyDecl:{ResultType int}{TypedText foo} (35)
 // CHECK-NO-NEXT: ObjCPropertyDecl:{ResultType Obj *}{TypedText obj} (35)
 // CHECK-NO-NEXT: ObjCPropertyDecl:{ResultType void (^)(Obj *)}{TypedText 
onAction} (35)
 // CHECK-NO-NEXT: ObjCPropertyDecl:{ResultType FooBlock}{TypedText 
onEventHandler} (35)
 // CHECK-NO-NEXT: ObjCPropertyDecl:{ResultType void (^)(int *)}{TypedText 
onReadonly} (35)
 // CHECK-NO-NEXT: ObjCPropertyDecl:{ResultType int (^)(int)}{TypedText 
processEvent} (35)
 
+// RUN: c-index-test -code-completion-at=%s:54:15 %s | FileCheck 
-check-prefix=CHECK-NO1 %s
+// CHECK-NO1: OverloadCandidate:{ResultType void}{Text func}{LeftParen 
(}{CurrentParameter int x}{RightParen )} (1)
 @end
Index: test/CodeCompletion/function-overloads.cpp
===
--- /dev/null
+++ test/CodeCompletion/function-overloads.cpp
@@ -0,0 +1,8 @@
+void f(int i, int j = 2, int k = 5);
+void f(float x, float y...);
+
+void test() {
+  ::f(
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:5:7 %s -o - | 
FileCheck -check-prefix=CHECK-CC1 %s
+  // CHECK-CC1: f(<#int i#>{#, <#int j = 2#>{#, <#int k = 5#>#}#})
+  // CHECK-CC1: f(<#float x#>, <#float y, ...#>)
Index: test/CodeCompletion/function-overloads-inside-param.cpp
===
--- /dev/null
+++ test/CodeCompletion/function-overloads-inside-param.cpp
@@ -0,0 +1,8 @@
+void f(int i, int j = 2, int k = 5);
+void f(float x, float y...);
+
+void test() {
+  ::f(1
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:5:8 %s -o - | 
FileCheck -check-prefix=CHECK-CC1 %s
+  // CHECK-CC1: f(<#int i#>{#, <#int j = 2#>{#, <#int k = 5#>#}#})
+  // CHECK-CC1: f(<#float x#>, <#float y, ...#>)
Index: lib/Parse/ParseExpr.cpp
===
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -1658,11 +1658,21 @@
 
   if (OpKind == tok::l_paren || !LHS.isInvalid()) {
 if (Tok.isNot(tok::r_paren)) {
-  if (ParseExpressionList(ArgExprs, CommaLocs, [&] {
-Actions.CodeCompleteCall(getCurScope(), LHS.get(), ArgExprs,
- PT.getOpenLocation());
-  })) {
+  auto Completer = [&] {
+if (CalledOverloadCompletion)
+  return;
+Actions.CodeCompleteCall(getCurScope(), LHS.get(), ArgExprs,
+ PT.getOpenLocation());
+CalledOverloadCompletion = true;
+  };
+  if (ParseExpressionList(ArgExprs, CommaLocs, Completer)) {
 (void)Actions.CorrectDelayedTyposInExpr(LHS);
+// If we got an error when parsing expression list, we don't call
+// the CodeCompleteCall handler inside the parser. So call it here
+// to make sure we get overload suggestions even when we are in the
+// middle of a parameter.
+if (PP.isCodeCompletionReached())
+  Completer();
 LHS = ExprError();
   } else if (LHS.isInvalid()) {
 for (auto  : ArgExprs)
Index: include/clang/Parse/Parser.h
===
--- include/clang/Parse/Parser.h
+++ include/clang/Parse/Parser.h
@@ -214,6 +214,10 @@
   /// should not be set directly.
   bool InMessageExpression;
 
+  /// Gets set to true after calling CodeCompleteCall, it is for a workaround 
to
+  /// make sure CodeComleteCall is only called at the deepest level.
+  bool CalledOverloadCompletion = false;
+
   /// The "depth" of the template parameters currently being parsed.
   unsigned TemplateParameterDepth;
 


Index: test/Index/complete-block-property-assignment.m
===
--- test/Index/complete-block-property-assignment.m

[PATCH] D51393: Provide a method for generating deterministic IDs for pointers allocated in BumpPtrAllocator

2018-09-06 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

I'm happy with the code.




Comment at: llvm/include/llvm/Support/Allocator.h:298
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx +  static_cast(P - S);
+  InSlabIdx += static_cast(computeSlabSize(Idx));

Two spaces here.


https://reviews.llvm.org/D51393



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


[PATCH] D42370: Issue local statics in correct DWARF lexical scope

2018-09-06 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Just to clarify - the general philosophy (there are many cases of exceptions 
due to complications in various areas) is that clang changes should have clang 
tests (source code to IR), LLVM changes should have LLVM tests (IR to assembly 
or object code+dwarf dump) & if debuginfo-tests are optional/as-desired.


https://reviews.llvm.org/D42370



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


[PATCH] D51393: Provide a method for generating deterministic IDs for pointers allocated in BumpPtrAllocator

2018-09-06 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov updated this revision to Diff 164294.
george.karpenkov added a comment.

More casts.


https://reviews.llvm.org/D51393

Files:
  llvm/include/llvm/Support/Allocator.h


Index: llvm/include/llvm/Support/Allocator.h
===
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,33 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = static_cast(Ptr);
+int64_t InSlabIdx = 0;
+for (size_t Idx = 0, E = Slabs.size(); Idx < E; Idx++) {
+  const char *S = static_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx +  static_cast(P - S);
+  InSlabIdx += static_cast(computeSlabSize(Idx));
+}
+
+// Use negative index to denote custom sized slabs.
+int64_t InCustomSizedSlabIdx = -1;
+for (size_t Idx = 0, E = CustomSizedSlabs.size(); Idx < E; Idx++) {
+  const char *S = static_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return InCustomSizedSlabIdx - static_cast(P - S);
+  InCustomSizedSlabIdx -= static_cast(Size);
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)


Index: llvm/include/llvm/Support/Allocator.h
===
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,33 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = static_cast(Ptr);
+int64_t InSlabIdx = 0;
+for (size_t Idx = 0, E = Slabs.size(); Idx < E; Idx++) {
+  const char *S = static_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx +  static_cast(P - S);
+  InSlabIdx += static_cast(computeSlabSize(Idx));
+}
+
+// Use negative index to denote custom sized slabs.
+int64_t InCustomSizedSlabIdx = -1;
+for (size_t Idx = 0, E = CustomSizedSlabs.size(); Idx < E; Idx++) {
+  const char *S = static_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return InCustomSizedSlabIdx - static_cast(P - S);
+  InCustomSizedSlabIdx -= static_cast(Size);
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51393: Provide a method for generating deterministic IDs for pointers allocated in BumpPtrAllocator

2018-09-06 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov updated this revision to Diff 164292.

https://reviews.llvm.org/D51393

Files:
  llvm/include/llvm/Support/Allocator.h


Index: llvm/include/llvm/Support/Allocator.h
===
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,34 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = reinterpret_cast(Ptr);
+int64_t InSlabIdx = 0;
+for (size_t Idx = 0, E = Slabs.size(); Idx < E; Idx++) {
+  const char *S = reinterpret_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx + (P - S);
+  InSlabIdx += computeSlabSize(Idx);
+}
+
+// Use negative index to denote custom sized slabs.
+int64_t InCustomSizedSlabIdx = -1;
+for (size_t Idx = 0, E = CustomSizedSlabs.size(); Idx < E; Idx++) {
+  const char *S =
+  reinterpret_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return InCustomSizedSlabIdx - (P - S);
+  InCustomSizedSlabIdx -= Size;
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)


Index: llvm/include/llvm/Support/Allocator.h
===
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,34 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = reinterpret_cast(Ptr);
+int64_t InSlabIdx = 0;
+for (size_t Idx = 0, E = Slabs.size(); Idx < E; Idx++) {
+  const char *S = reinterpret_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx + (P - S);
+  InSlabIdx += computeSlabSize(Idx);
+}
+
+// Use negative index to denote custom sized slabs.
+int64_t InCustomSizedSlabIdx = -1;
+for (size_t Idx = 0, E = CustomSizedSlabs.size(); Idx < E; Idx++) {
+  const char *S =
+  reinterpret_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return InCustomSizedSlabIdx - (P - S);
+  InCustomSizedSlabIdx -= Size;
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51393: Provide a method for generating deterministic IDs for pointers allocated in BumpPtrAllocator

2018-09-06 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov updated this revision to Diff 164291.

https://reviews.llvm.org/D51393

Files:
  llvm/include/llvm/Support/Allocator.h


Index: llvm/include/llvm/Support/Allocator.h
===
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,34 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = reinterpret_cast(Ptr);
+long InSlabIdx = 0;
+for (size_t Idx = 0, E = Slabs.size(); Idx < E; Idx++) {
+  const char *S = reinterpret_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx + (P - S);
+  InSlabIdx += computeSlabSize(Idx);
+}
+
+// Use negative index to denote custom sized slabs.
+long InCustomSizedSlabIdx = -1;
+for (size_t Idx = 0, E = CustomSizedSlabs.size(); Idx < E; Idx++) {
+  const char *S =
+  reinterpret_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return InCustomSizedSlabIdx - (P - S);
+  InCustomSizedSlabIdx -= Size;
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)


Index: llvm/include/llvm/Support/Allocator.h
===
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,34 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = reinterpret_cast(Ptr);
+long InSlabIdx = 0;
+for (size_t Idx = 0, E = Slabs.size(); Idx < E; Idx++) {
+  const char *S = reinterpret_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx + (P - S);
+  InSlabIdx += computeSlabSize(Idx);
+}
+
+// Use negative index to denote custom sized slabs.
+long InCustomSizedSlabIdx = -1;
+for (size_t Idx = 0, E = CustomSizedSlabs.size(); Idx < E; Idx++) {
+  const char *S =
+  reinterpret_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return InCustomSizedSlabIdx - (P - S);
+  InCustomSizedSlabIdx -= Size;
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51395: [analyzer] Dump a reproducible, deterministic ID of program state to exploded graph

2018-09-06 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

I very very much appreciate this.


https://reviews.llvm.org/D51395



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


[PATCH] D51752: NFC: move isRepeatedBytePattern from clang to Constant

2018-09-06 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

In https://reviews.llvm.org/D51752#1226474, @MatzeB wrote:

> In https://reviews.llvm.org/D51752#1226462, @MatzeB wrote:
>
> > - I assume the review lacks the changes on the llvm side?
>
>
> Oops missed the link to the llvm changes in the description... At least in 
> theory you should be able to make a review over all changes in parallel by 
> using subversion or the experimental llvm git monorepo with 
> llvm/utils/git-svn/git-llvm (admittedly haven't tried it myself yet either).


Haha yeah I'm still using my now years-old workflow. Haven't tried the new 
fancy ones yet, waiting for the actual move to do so :)


Repository:
  rC Clang

https://reviews.llvm.org/D51752



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


[PATCH] D51752: NFC: move isRepeatedBytePattern from clang to Constant

2018-09-06 Thread Matthias Braun via Phabricator via cfe-commits
MatzeB added a comment.

In https://reviews.llvm.org/D51752#1226462, @MatzeB wrote:

> - I assume the review lacks the changes on the llvm side?


Oops missed the link to the llvm changes in the description... At least in 
theory you should be able to make a review over all changes in parallel by 
using subversion or the experimental llvm git monorepo with 
llvm/utils/git-svn/git-llvm (admittedly haven't tried it myself yet either).


Repository:
  rC Clang

https://reviews.llvm.org/D51752



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


[PATCH] D51752: NFC: move isRepeatedBytePattern from clang to Constant

2018-09-06 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

In https://reviews.llvm.org/D51752#1226465, @jfb wrote:

> In https://reviews.llvm.org/D51752#1226462, @MatzeB wrote:
>
> > - I'm not a good person to review clang changes.
> > - I assume the review lacks the changes on the llvm side?
> > - On the LLVM side this feels like something for `Analysis/ValueTracking.h` 
> > in fact I already see `Value *isBytewiseValue(Value *V);` there, maybe that 
> > is good enough for your purpose?
>
>
> Indeed, I just noticed the same. I'll try to figure out why it isn't firing 
> where I want it to.


I think I'll just improve `isBytewiseValue` to do all the things 
`isRepeatedBytePattern` does. I'll update this patch to still delete 
`constantIsRepeatedBytePattern`, but use the new and improved `isBytewiseValue`.


Repository:
  rC Clang

https://reviews.llvm.org/D51752



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


[PATCH] D51752: NFC: move isRepeatedBytePattern from clang to Constant

2018-09-06 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

In https://reviews.llvm.org/D51752#1226462, @MatzeB wrote:

> - I'm not a good person to review clang changes.
> - I assume the review lacks the changes on the llvm side?
> - On the LLVM side this feels like something for `Analysis/ValueTracking.h` 
> in fact I already see `Value *isBytewiseValue(Value *V);` there, maybe that 
> is good enough for your purpose?


Indeed, I just noticed the same. I'll try to figure out why it isn't firing 
where I want it to.


Repository:
  rC Clang

https://reviews.llvm.org/D51752



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


[PATCH] D51752: NFC: move isRepeatedBytePattern from clang to Constant

2018-09-06 Thread Matthias Braun via Phabricator via cfe-commits
MatzeB added a comment.

- I'm not a good person to review clang changes.
- I assume the review lacks the changes on the llvm side?
- On the LLVM side this feels like something for `Analysis/ValueTracking.h` in 
fact I already see `Value *isBytewiseValue(Value *V);` there, maybe that is 
good enough for your purpose?


Repository:
  rC Clang

https://reviews.llvm.org/D51752



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


[PATCH] D51752: NFC: move isRepeatedBytePattern from clang to Constant

2018-09-06 Thread JF Bastien via Phabricator via cfe-commits
jfb created this revision.
Herald added subscribers: cfe-commits, dexonsmith.

This code was in CGDecl.cpp and really belongs to Constant. This will allow me
to use it in a subsequent patch.

LLVM part of this patch: https://reviews.llvm.org/D51751


Repository:
  rC Clang

https://reviews.llvm.org/D51752

Files:
  lib/CodeGen/CGDecl.cpp

Index: lib/CodeGen/CGDecl.cpp
===
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -948,111 +948,17 @@
  canEmitInitWithFewStoresAfterBZero(Init, StoreBudget);
 }
 
-/// A byte pattern.
-///
-/// Can be "any" pattern if the value was padding or known to be undef.
-/// Can be "none" pattern if a sequence doesn't exist.
-class BytePattern {
-  uint8_t Val;
-  enum class ValueType : uint8_t { Specific, Any, None } Type;
-  BytePattern(ValueType Type) : Type(Type) {}
-
-public:
-  BytePattern(uint8_t Value) : Val(Value), Type(ValueType::Specific) {}
-  static BytePattern Any() { return BytePattern(ValueType::Any); }
-  static BytePattern None() { return BytePattern(ValueType::None); }
-  bool isAny() const { return Type == ValueType::Any; }
-  bool isNone() const { return Type == ValueType::None; }
-  bool isValued() const { return Type == ValueType::Specific; }
-  uint8_t getValue() const {
-assert(isValued());
-return Val;
-  }
-  BytePattern merge(const BytePattern Other) const {
-if (isNone() || Other.isNone())
-  return None();
-if (isAny())
-  return Other;
-if (Other.isAny())
-  return *this;
-if (getValue() == Other.getValue())
-  return *this;
-return None();
-  }
-};
-
-/// Figures out whether the constant can be initialized with memset.
-static BytePattern constantIsRepeatedBytePattern(llvm::Constant *C) {
-  if (isa(C) || isa(C))
-return BytePattern(0x00);
-  if (isa(C))
-return BytePattern::Any();
-
-  if (isa(C)) {
-auto *Int = cast(C);
-if (Int->getBitWidth() % 8 != 0)
-  return BytePattern::None();
-const llvm::APInt  = Int->getValue();
-if (Value.isSplat(8))
-  return BytePattern(Value.getLoBits(8).getLimitedValue());
-return BytePattern::None();
-  }
-
-  if (isa(C)) {
-auto *FP = cast(C);
-llvm::APInt Bits = FP->getValueAPF().bitcastToAPInt();
-if (Bits.getBitWidth() % 8 != 0)
-  return BytePattern::None();
-if (!Bits.isSplat(8))
-  return BytePattern::None();
-return BytePattern(Bits.getLimitedValue() & 0xFF);
-  }
-
-  if (isa(C)) {
-llvm::Constant *Splat = cast(C)->getSplatValue();
-if (Splat)
-  return constantIsRepeatedBytePattern(Splat);
-return BytePattern::None();
-  }
-
-  if (isa(C) || isa(C)) {
-BytePattern Pattern(BytePattern::Any());
-for (unsigned I = 0, E = C->getNumOperands(); I != E; ++I) {
-  llvm::Constant *Elt = cast(C->getOperand(I));
-  Pattern = Pattern.merge(constantIsRepeatedBytePattern(Elt));
-  if (Pattern.isNone())
-return Pattern;
-}
-return Pattern;
-  }
-
-  if (llvm::ConstantDataSequential *CDS =
-  dyn_cast(C)) {
-BytePattern Pattern(BytePattern::Any());
-for (unsigned I = 0, E = CDS->getNumElements(); I != E; ++I) {
-  llvm::Constant *Elt = CDS->getElementAsConstant(I);
-  Pattern = Pattern.merge(constantIsRepeatedBytePattern(Elt));
-  if (Pattern.isNone())
-return Pattern;
-}
-return Pattern;
-  }
-
-  // BlockAddress, ConstantExpr, and everything else is scary.
-  return BytePattern::None();
-}
-
 /// Decide whether we should use memset to initialize a local variable instead
 /// of using a memcpy from a constant global. Assumes we've already decided to
 /// not user bzero.
 /// FIXME We could be more clever, as we are for bzero above, and generate
 ///   memset followed by stores. It's unclear that's worth the effort.
-static BytePattern shouldUseMemSetToInitialize(llvm::Constant *Init,
-   uint64_t GlobalSize) {
+static llvm::Constant::BytePattern
+shouldUseMemSetToInitialize(llvm::Constant *Init, uint64_t GlobalSize) {
   uint64_t SizeLimit = 32;
   if (GlobalSize <= SizeLimit)
-return BytePattern::None();
-  return constantIsRepeatedBytePattern(Init);
+return llvm::Constant::BytePattern::None();
+  return Init->isRepeatedBytePattern();
 }
 
 static void emitStoresForConstant(CodeGenModule , const VarDecl ,
@@ -1081,7 +987,8 @@
 return;
   }
 
-  BytePattern Pattern = shouldUseMemSetToInitialize(constant, ConstantSize);
+  llvm::Constant::BytePattern Pattern =
+  shouldUseMemSetToInitialize(constant, ConstantSize);
   if (!Pattern.isNone()) {
 uint8_t Value = Pattern.isAny() ? 0x00 : Pattern.getValue();
 Builder.CreateMemSet(Loc, llvm::ConstantInt::get(Int8Ty, Value), SizeVal,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51192: Fix reported range of partial token replacement

2018-09-06 Thread Stephen Kelly via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE341583: Fix reported range of partial token replacement 
(authored by steveire, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D51192?vs=163447=164275#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51192

Files:
  clang-tidy/ClangTidy.cpp


Index: clang-tidy/ClangTidy.cpp
===
--- clang-tidy/ClangTidy.cpp
+++ clang-tidy/ClangTidy.cpp
@@ -122,10 +122,6 @@
   << Message.Message << Name;
   for (const auto  : Error.Fix) {
 for (const auto  : FileAndReplacements.second) {
-  // Retrieve the source range for applicable fixes. Macro definitions
-  // on the command line have locations in a virtual buffer and don't
-  // have valid file paths and are therefore not applicable.
-  SourceRange Range;
   SourceLocation FixLoc;
   ++TotalFixes;
   bool CanBeApplied = false;
@@ -166,7 +162,11 @@
 FixLoc = getLocation(FixAbsoluteFilePath, Repl.getOffset());
 SourceLocation FixEndLoc =
 FixLoc.getLocWithOffset(Repl.getLength());
-Range = SourceRange(FixLoc, FixEndLoc);
+// Retrieve the source range for applicable fixes. Macro 
definitions
+// on the command line have locations in a virtual buffer and don't
+// have valid file paths and are therefore not applicable.
+CharSourceRange Range =
+CharSourceRange::getCharRange(SourceRange(FixLoc, FixEndLoc));
 Diag << FixItHint::CreateReplacement(Range,
  Repl.getReplacementText());
   }


Index: clang-tidy/ClangTidy.cpp
===
--- clang-tidy/ClangTidy.cpp
+++ clang-tidy/ClangTidy.cpp
@@ -122,10 +122,6 @@
   << Message.Message << Name;
   for (const auto  : Error.Fix) {
 for (const auto  : FileAndReplacements.second) {
-  // Retrieve the source range for applicable fixes. Macro definitions
-  // on the command line have locations in a virtual buffer and don't
-  // have valid file paths and are therefore not applicable.
-  SourceRange Range;
   SourceLocation FixLoc;
   ++TotalFixes;
   bool CanBeApplied = false;
@@ -166,7 +162,11 @@
 FixLoc = getLocation(FixAbsoluteFilePath, Repl.getOffset());
 SourceLocation FixEndLoc =
 FixLoc.getLocWithOffset(Repl.getLength());
-Range = SourceRange(FixLoc, FixEndLoc);
+// Retrieve the source range for applicable fixes. Macro definitions
+// on the command line have locations in a virtual buffer and don't
+// have valid file paths and are therefore not applicable.
+CharSourceRange Range =
+CharSourceRange::getCharRange(SourceRange(FixLoc, FixEndLoc));
 Diag << FixItHint::CreateReplacement(Range,
  Repl.getReplacementText());
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r341583 - Fix reported range of partial token replacement

2018-09-06 Thread Stephen Kelly via cfe-commits
Author: steveire
Date: Thu Sep  6 13:16:34 2018
New Revision: 341583

URL: http://llvm.org/viewvc/llvm-project?rev=341583=rev
Log:
Fix reported range of partial token replacement

Summary: Fixes bug: 38678

Reviewers: klimek, rsmith

Subscribers: cfe-commits

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

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

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=341583=341582=341583=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Thu Sep  6 13:16:34 2018
@@ -122,10 +122,6 @@ public:
   << Message.Message << Name;
   for (const auto  : Error.Fix) {
 for (const auto  : FileAndReplacements.second) {
-  // Retrieve the source range for applicable fixes. Macro definitions
-  // on the command line have locations in a virtual buffer and don't
-  // have valid file paths and are therefore not applicable.
-  SourceRange Range;
   SourceLocation FixLoc;
   ++TotalFixes;
   bool CanBeApplied = false;
@@ -166,7 +162,11 @@ public:
 FixLoc = getLocation(FixAbsoluteFilePath, Repl.getOffset());
 SourceLocation FixEndLoc =
 FixLoc.getLocWithOffset(Repl.getLength());
-Range = SourceRange(FixLoc, FixEndLoc);
+// Retrieve the source range for applicable fixes. Macro 
definitions
+// on the command line have locations in a virtual buffer and don't
+// have valid file paths and are therefore not applicable.
+CharSourceRange Range =
+CharSourceRange::getCharRange(SourceRange(FixLoc, FixEndLoc));
 Diag << FixItHint::CreateReplacement(Range,
  Repl.getReplacementText());
   }


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


[PATCH] D51192: Fix reported range of partial token replacement

2018-09-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D51192#1226341, @steveire wrote:

> Thanks.
>
> The `arc` tool already inserted `Differential Revision:` into my git commit, 
> but that's not what I wonder about. I'm looking for something I can insert 
> into my git commit so that the bug will automatically be closed when I commit 
> (and so that the bug will get a link to this PR when the PR is created). Does 
> such a thing exist here?


Ah, sorry for the misunderstanding. I don't think such a thing exists here, 
unfortunately.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51192



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


[PATCH] D51192: Fix reported range of partial token replacement

2018-09-06 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a comment.

Thanks.

The `arc` tool already inserted `Differential Revision:` into my git commit, 
but that's not what I wonder about. I'm looking for something I can insert into 
my git commit so that the bug will automatically be closed when I commit (and 
so that the bug will get a link to this PR when the PR is created). Does such a 
thing exist here?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51192



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


[PATCH] D51192: Fix reported range of partial token replacement

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

In https://reviews.llvm.org/D51192#1226326, @steveire wrote:

> As far as I know, no existing clang-tidy checks are affected. I discovered 
> this while implementing a custom check. See 
> https://bugs.llvm.org/show_bug.cgi?id=38678


It's unfortunate this is going in without tests, but it still LGTM.

> By the way, is there some keyword I should use in commit messages to link to 
> bugs properly?

Add the following to the end of the commit message and I believe it will 
automatically close the Phab review:

  Differential Revision: 

Where the URL is the URL to this review.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51192



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


[PATCH] D51683: Fix arm_neon.h and arm_fp16.h generation for compiling with std=c89

2018-09-06 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

Correct. The protected name is double underscore as both suffix and prefix.


https://reviews.llvm.org/D51683



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


[PATCH] D51192: Fix reported range of partial token replacement

2018-09-06 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a comment.

As far as I know, no existing clang-tidy checks are affected. I discovered this 
while implementing a custom check. See 
https://bugs.llvm.org/show_bug.cgi?id=38678

By the way, is there some keyword I should use in commit messages to link to 
bugs properly?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51192



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


[PATCH] D51192: Fix reported range of partial token replacement

2018-09-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D51192#1226312, @steveire wrote:

> In https://reviews.llvm.org/D51192#1226282, @aaron.ballman wrote:
>
> > I'd probably pipe the diagnostic output to a temporary file that gets 
> > FileChecked with strict whitespace to see if the underlines from the 
> > diagnostic match the expected locations. We do this in a few Clang tests, 
> > like SemaCXX\struct-class-redecl.cpp or Misc\wrong-encoding.c.
>
>
> Doesn't this require building-in a new check to clang-tidy which exists only 
> for the purpose of the test? Otherwise how would a test similar to 
> `SemaCXX\struct-class-redecl.cpp` work? What would be in the `RUN` line?


Oh, I had the impression that this was changing the behavior of existing checks 
in the tree as well, and that we'd have an existing clang-tidy check that 
exhibits the problematic behavior. Is that not the case?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51192



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


Re: r341141 - Extract parseBindID method

2018-09-06 Thread Stephen Kelly via cfe-commits



On 06/09/18 20:42, Roman Lebedev wrote:

You can specify the dependencies between the differentials in phabricator.



I didn't know that, thanks!
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r341141 - Extract parseBindID method

2018-09-06 Thread Roman Lebedev via cfe-commits
On Thu, Sep 6, 2018 at 10:05 PM, Stephen Kelly via cfe-commits
 wrote:
>
> Yes, this was a prerequisite to https://reviews.llvm.org/D51259. For some
> reason the reviewer accepted that one, but not this one. I simply assumed
> that was a mistake and committed this one.
I'm not sure this is how the review works in LLVM, in general.

> Perhaps part of the problem is that I do one thing per commit, and that
> confuses reviewers. Maybe I should squash things for review? I don't know.
You can specify the dependencies between the differentials in phabricator.

> Thanks for any post-commit review!
>
> Stephen.
Roman.

> On 31/08/18 07:06, Roman Lebedev via cfe-commits wrote:
>>
>> I don't think this was reviewed. The differential is not in 'accepted'
>> state.
>>
>> Roman.
>>
>> On Fri, Aug 31, 2018 at 2:11 AM, Stephen Kelly via cfe-commits
>>  wrote:
>>>
>>> Author: steveire
>>> Date: Thu Aug 30 16:11:01 2018
>>> New Revision: 341141
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=341141=rev
>>> Log:
>>> Extract parseBindID method
>>>
>>> Subscribers: cfe-commits
>>>
>>> Differential Revision: https://reviews.llvm.org/D51258
>>>
>>> Modified:
>>>  cfe/trunk/include/clang/ASTMatchers/Dynamic/Parser.h
>>>  cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp
>>>
>>> Modified: cfe/trunk/include/clang/ASTMatchers/Dynamic/Parser.h
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/Dynamic/Parser.h?rev=341141=341140=341141=diff
>>>
>>> ==
>>> --- cfe/trunk/include/clang/ASTMatchers/Dynamic/Parser.h (original)
>>> +++ cfe/trunk/include/clang/ASTMatchers/Dynamic/Parser.h Thu Aug 30
>>> 16:11:01 2018
>>> @@ -234,6 +234,7 @@ private:
>>>const NamedValueMap *NamedValues,
>>>Diagnostics *Error);
>>>
>>> +  bool parseBindID(std::string );
>>> bool parseExpressionImpl(VariantValue *Value);
>>> bool parseMatcherExpressionImpl(const TokenInfo ,
>>> VariantValue *Value);
>>>
>>> Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp?rev=341141=341140=341141=diff
>>>
>>> ==
>>> --- cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp (original)
>>> +++ cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp Thu Aug 30 16:11:01 2018
>>> @@ -359,6 +359,43 @@ bool Parser::parseIdentifierPrefixImpl(V
>>> return parseMatcherExpressionImpl(NameToken, Value);
>>>   }
>>>
>>> +bool Parser::parseBindID(std::string ) {
>>> +  // Parse .bind("foo")
>>> +  assert(Tokenizer->peekNextToken().Kind == TokenInfo::TK_Period);
>>> +  Tokenizer->consumeNextToken(); // consume the period.
>>> +  const TokenInfo BindToken = Tokenizer->consumeNextToken();
>>> +  if (BindToken.Kind == TokenInfo::TK_CodeCompletion) {
>>> +addCompletion(BindToken, MatcherCompletion("bind(\"", "bind", 1));
>>> +return false;
>>> +  }
>>> +
>>> +  const TokenInfo OpenToken = Tokenizer->consumeNextToken();
>>> +  const TokenInfo IDToken = Tokenizer->consumeNextToken();
>>> +  const TokenInfo CloseToken = Tokenizer->consumeNextToken();
>>> +
>>> +  // TODO: We could use different error codes for each/some to be more
>>> +  //   explicit about the syntax error.
>>> +  if (BindToken.Kind != TokenInfo::TK_Ident ||
>>> +  BindToken.Text != TokenInfo::ID_Bind) {
>>> +Error->addError(BindToken.Range, Error->ET_ParserMalformedBindExpr);
>>> +return false;
>>> +  }
>>> +  if (OpenToken.Kind != TokenInfo::TK_OpenParen) {
>>> +Error->addError(OpenToken.Range, Error->ET_ParserMalformedBindExpr);
>>> +return false;
>>> +  }
>>> +  if (IDToken.Kind != TokenInfo::TK_Literal ||
>>> !IDToken.Value.isString()) {
>>> +Error->addError(IDToken.Range, Error->ET_ParserMalformedBindExpr);
>>> +return false;
>>> +  }
>>> +  if (CloseToken.Kind != TokenInfo::TK_CloseParen) {
>>> +Error->addError(CloseToken.Range,
>>> Error->ET_ParserMalformedBindExpr);
>>> +return false;
>>> +  }
>>> +  BindID = IDToken.Value.getString();
>>> +  return true;
>>> +}
>>> +
>>>   /// Parse and validate a matcher expression.
>>>   /// \return \c true on success, in which case \c Value has the matcher
>>> parsed.
>>>   ///   If the input is malformed, or some argument has an error, it
>>> @@ -425,38 +462,8 @@ bool Parser::parseMatcherExpressionImpl(
>>>
>>> std::string BindID;
>>> if (Tokenizer->peekNextToken().Kind == TokenInfo::TK_Period) {
>>> -// Parse .bind("foo")
>>> -Tokenizer->consumeNextToken();  // consume the period.
>>> -const TokenInfo BindToken = Tokenizer->consumeNextToken();
>>> -if (BindToken.Kind == TokenInfo::TK_CodeCompletion) {
>>> -  addCompletion(BindToken, MatcherCompletion("bind(\"", "bind", 1));
>>> +if (!parseBindID(BindID))
>>> return false;
>>> -}
>>> -
>>> -const 

[PATCH] D51192: Fix reported range of partial token replacement

2018-09-06 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a comment.



In https://reviews.llvm.org/D51192#1226282, @aaron.ballman wrote:

> In https://reviews.llvm.org/D51192#1226257, @steveire wrote:
>
> > How? This is 'private' code. I don't think it's worth changing that or 
> > creating a test with a huge amount of infrastructure in order to test this 
> > indirectly.
>
>
> This is changing the observable behavior of the tool, so it should have tests 
> unless they're impossible to write.


Yes. The current behavior is not tested. I agree that tests are better than no 
tests.

>> Am I missing something?
> 
> I'd probably pipe the diagnostic output to a temporary file that gets 
> FileChecked with strict whitespace to see if the underlines from the 
> diagnostic match the expected locations. We do this in a few Clang tests, 
> like SemaCXX\struct-class-redecl.cpp or Misc\wrong-encoding.c.

Doesn't this require building-in a new check to clang-tidy which exists only 
for the purpose of the test? Otherwise how would a test similar to 
`SemaCXX\struct-class-redecl.cpp` work? What would be in the `RUN` line?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51192



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


[PATCH] D51747: [clangd] Implement deprecation diagnostics with lower severity.

2018-09-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 164268.
kadircet added a comment.

- Formatting.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51747

Files:
  clangd/ClangdServer.cpp
  clangd/Diagnostics.cpp
  unittests/clangd/ClangdUnitTests.cpp


Index: unittests/clangd/ClangdUnitTests.cpp
===
--- unittests/clangd/ClangdUnitTests.cpp
+++ unittests/clangd/ClangdUnitTests.cpp
@@ -38,6 +38,13 @@
   return arg.Range == Range && arg.Message == Message;
 }
 
+MATCHER_P3(Diag, Range, Message, Severity,
+   "Diag at " + llvm::to_string(Range) + " = [" + Message +
+   "] with Severity:" + llvm::to_string(Severity)) {
+  return arg.Range == Range && arg.Message == Message &&
+ arg.Severity == Severity;
+}
+
 MATCHER_P3(Fix, Range, Replacement, Message,
"Fix " + llvm::to_string(Range) + " => " +
testing::PrintToString(Replacement) + " = [" + Message + "]") {
@@ -220,6 +227,46 @@
   }
 }
 
+TEST(DiagnosticsTest, DiagnosticDeprecated) {
+  Annotations Test(R"cpp(
+void foo() __attribute__(($foodeprecation[[deprecated]]));
+class A {
+public:
+  int x __attribute__(($xdeprecation[[deprecated]]));
+};
+int main() {
+  $foo[[foo]]();
+  return A().$x[[x]];
+}
+  )cpp");
+  EXPECT_THAT(
+  TestTU::withCode(Test.code()).build().getDiagnostics(),
+  ElementsAre(
+  AllOf(Diag(Test.range("foo"), "'foo' is deprecated",
+ DiagnosticsEngine::Note),
+WithNote(
+Diag(Test.range("foodeprecation"),
+ "'foo' has been explicitly marked deprecated here"))),
+  AllOf(Diag(Test.range("x"), "'x' is deprecated",
+ DiagnosticsEngine::Note),
+WithNote(
+Diag(Test.range("xdeprecation"),
+ "'x' has been explicitly marked deprecated here");
+}
+
+TEST(DiagnosticsTest, DiagnosticDeprecatedWithFix) {
+  Annotations Test(R"cpp(
+void bar();
+void foo() __attribute__((deprecated("", "bar")));
+int main() {
+  $deprecated[[foo]]();
+}
+  )cpp");
+  EXPECT_THAT(TestTU::withCode(Test.code()).build().getDiagnostics(),
+  ElementsAre(WithFix(Fix(Test.range("deprecated"), "bar",
+  "change 'foo' to 'bar'";
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clangd/Diagnostics.cpp
===
--- clangd/Diagnostics.cpp
+++ clangd/Diagnostics.cpp
@@ -292,10 +292,11 @@
 D.Message = Message.str();
 D.InsideMainFile = InsideMainFile;
 D.File = Info.getSourceManager().getFilename(Info.getLocation());
-D.Severity = DiagLevel;
 D.Category = DiagnosticIDs::getCategoryNameFromID(
  DiagnosticIDs::getCategoryNumberForDiag(Info.getID()))
  .str();
+D.Severity =
+D.Category == "Deprecations" ? DiagnosticsEngine::Note : DiagLevel;
 return D;
   };
 
Index: clangd/ClangdServer.cpp
===
--- clangd/ClangdServer.cpp
+++ clangd/ClangdServer.cpp
@@ -534,6 +534,7 @@
   // Inject the resource dir.
   // FIXME: Don't overwrite it if it's already there.
   C->CommandLine.push_back("-resource-dir=" + ResourceDir);
+  C->CommandLine.push_back("-Wdeprecated-declarations");
   return std::move(*C);
 }
 


Index: unittests/clangd/ClangdUnitTests.cpp
===
--- unittests/clangd/ClangdUnitTests.cpp
+++ unittests/clangd/ClangdUnitTests.cpp
@@ -38,6 +38,13 @@
   return arg.Range == Range && arg.Message == Message;
 }
 
+MATCHER_P3(Diag, Range, Message, Severity,
+   "Diag at " + llvm::to_string(Range) + " = [" + Message +
+   "] with Severity:" + llvm::to_string(Severity)) {
+  return arg.Range == Range && arg.Message == Message &&
+ arg.Severity == Severity;
+}
+
 MATCHER_P3(Fix, Range, Replacement, Message,
"Fix " + llvm::to_string(Range) + " => " +
testing::PrintToString(Replacement) + " = [" + Message + "]") {
@@ -220,6 +227,46 @@
   }
 }
 
+TEST(DiagnosticsTest, DiagnosticDeprecated) {
+  Annotations Test(R"cpp(
+void foo() __attribute__(($foodeprecation[[deprecated]]));
+class A {
+public:
+  int x __attribute__(($xdeprecation[[deprecated]]));
+};
+int main() {
+  $foo[[foo]]();
+  return A().$x[[x]];
+}
+  )cpp");
+  EXPECT_THAT(
+  TestTU::withCode(Test.code()).build().getDiagnostics(),
+  ElementsAre(
+  AllOf(Diag(Test.range("foo"), "'foo' is deprecated",
+ DiagnosticsEngine::Note),
+WithNote(
+Diag(Test.range("foodeprecation"),
+ "'foo' has been explicitly marked deprecated here"))),
+  

[PATCH] D51747: [clangd] Implement deprecation diagnostics with lower severity.

2018-09-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clangd/Diagnostics.cpp:299
+D.Severity =
+D.Category == "Deprecations" ? DiagnosticsEngine::Note : DiagLevel;
 return D;

Couldn't find a better way to check for this one. Category types are coming 
from tablegen file 
https://github.com/llvm-mirror/clang/blob/master/include/clang/Basic/DiagnosticGroups.td#L128
 which does not expose category id, at least I couldn't find even if it does.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51747



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


[PATCH] D51741: [coro]Pass rvalue reference for named local variable to return_value

2018-09-06 Thread Tanoy Sinha via Phabricator via cfe-commits
tks2103 updated this revision to Diff 164265.
tks2103 added a comment.

get NRVOCandidate to determine if we should try to move return var


Repository:
  rC Clang

https://reviews.llvm.org/D51741

Files:
  lib/Sema/SemaCoroutine.cpp
  test/SemaCXX/coroutine-rvo.cpp


Index: test/SemaCXX/coroutine-rvo.cpp
===
--- /dev/null
+++ test/SemaCXX/coroutine-rvo.cpp
@@ -0,0 +1,69 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -stdlib=libc++ -std=c++1z 
-fcoroutines-ts -fsyntax-only
+
+namespace std::experimental {
+template  struct coroutine_handle {
+  coroutine_handle() = default;
+  static coroutine_handle from_address(void *) noexcept;
+};
+
+template <> struct coroutine_handle {
+  static coroutine_handle from_address(void *) noexcept;
+  coroutine_handle() = default;
+  template 
+  coroutine_handle(coroutine_handle) noexcept;
+};
+
+template 
+struct void_t_imp {
+  using type = void;
+};
+template 
+using void_t = typename void_t_imp::type;
+
+template 
+struct traits_sfinae_base {};
+
+template 
+struct traits_sfinae_base> {
+  using promise_type = typename T::promise_type;
+};
+
+template 
+struct coroutine_traits : public traits_sfinae_base {};
+}
+
+struct suspend_never {
+  bool await_ready() noexcept;
+  void await_suspend(std::experimental::coroutine_handle<>) noexcept;
+  void await_resume() noexcept;
+};
+
+struct MoveOnly {
+  MoveOnly() {};
+  MoveOnly(const MoveOnly&) = delete;
+  MoveOnly(MoveOnly&&) noexcept {};
+  ~MoveOnly() {};
+};
+
+template 
+struct task {
+  struct promise_type {
+auto initial_suspend() { return suspend_never{}; }
+auto final_suspend() { return suspend_never{}; }
+auto get_return_object() { return task{}; }
+static void unhandled_exception() {}
+void return_value(T&& value) {}
+  };
+};
+
+task f() {
+  MoveOnly value;
+  co_return value;
+}
+
+int main() {
+  f();
+  return 0;
+}
+
+// expected-no-diagnostics
Index: lib/Sema/SemaCoroutine.cpp
===
--- lib/Sema/SemaCoroutine.cpp
+++ lib/Sema/SemaCoroutine.cpp
@@ -841,6 +841,19 @@
 E = R.get();
   }
 
+  // Move the return value if we can
+  if (E) {
+auto NRVOCandidate = this->getCopyElisionCandidate(E->getType(), E, 
CES_AsIfByStdMove);
+if (NRVOCandidate) {
+  InitializedEntity Entity =
+  InitializedEntity::InitializeResult(Loc, E->getType(), 
NRVOCandidate);
+  ExprResult MoveResult =
+  this->PerformMoveOrCopyInitialization(Entity, NRVOCandidate, 
E->getType(), E);
+  if (MoveResult.get())
+E = MoveResult.get();
+}
+  }
+
   // FIXME: If the operand is a reference to a variable that's about to go out
   // of scope, we should treat the operand as an xvalue for this overload
   // resolution.


Index: test/SemaCXX/coroutine-rvo.cpp
===
--- /dev/null
+++ test/SemaCXX/coroutine-rvo.cpp
@@ -0,0 +1,69 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -stdlib=libc++ -std=c++1z -fcoroutines-ts -fsyntax-only
+
+namespace std::experimental {
+template  struct coroutine_handle {
+  coroutine_handle() = default;
+  static coroutine_handle from_address(void *) noexcept;
+};
+
+template <> struct coroutine_handle {
+  static coroutine_handle from_address(void *) noexcept;
+  coroutine_handle() = default;
+  template 
+  coroutine_handle(coroutine_handle) noexcept;
+};
+
+template 
+struct void_t_imp {
+  using type = void;
+};
+template 
+using void_t = typename void_t_imp::type;
+
+template 
+struct traits_sfinae_base {};
+
+template 
+struct traits_sfinae_base> {
+  using promise_type = typename T::promise_type;
+};
+
+template 
+struct coroutine_traits : public traits_sfinae_base {};
+}
+
+struct suspend_never {
+  bool await_ready() noexcept;
+  void await_suspend(std::experimental::coroutine_handle<>) noexcept;
+  void await_resume() noexcept;
+};
+
+struct MoveOnly {
+  MoveOnly() {};
+  MoveOnly(const MoveOnly&) = delete;
+  MoveOnly(MoveOnly&&) noexcept {};
+  ~MoveOnly() {};
+};
+
+template 
+struct task {
+  struct promise_type {
+auto initial_suspend() { return suspend_never{}; }
+auto final_suspend() { return suspend_never{}; }
+auto get_return_object() { return task{}; }
+static void unhandled_exception() {}
+void return_value(T&& value) {}
+  };
+};
+
+task f() {
+  MoveOnly value;
+  co_return value;
+}
+
+int main() {
+  f();
+  return 0;
+}
+
+// expected-no-diagnostics
Index: lib/Sema/SemaCoroutine.cpp
===
--- lib/Sema/SemaCoroutine.cpp
+++ lib/Sema/SemaCoroutine.cpp
@@ -841,6 +841,19 @@
 E = R.get();
   }
 
+  // Move the return value if we can
+  if (E) {
+auto NRVOCandidate = this->getCopyElisionCandidate(E->getType(), E, CES_AsIfByStdMove);
+if (NRVOCandidate) {
+  InitializedEntity Entity =
+  

[PATCH] D51192: Fix reported range of partial token replacement

2018-09-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D51192#1226257, @steveire wrote:

> How? This is 'private' code. I don't think it's worth changing that or 
> creating a test with a huge amount of infrastructure in order to test this 
> indirectly.


This is changing the observable behavior of the tool, so it should have tests 
unless they're impossible to write.

> Am I missing something?

I'd probably pipe the diagnostic output to a temporary file that gets 
FileChecked with strict whitespace to see if the underlines from the diagnostic 
match the expected locations. We do this in a few Clang tests, like 
SemaCXX\struct-class-redecl.cpp or Misc\wrong-encoding.c.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51192



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


Re: r341141 - Extract parseBindID method

2018-09-06 Thread Stephen Kelly via cfe-commits


Yes, this was a prerequisite to https://reviews.llvm.org/D51259. For 
some reason the reviewer accepted that one, but not this one. I simply 
assumed that was a mistake and committed this one.


Perhaps part of the problem is that I do one thing per commit, and that 
confuses reviewers. Maybe I should squash things for review? I don't know.


Thanks for any post-commit review!

Stephen.

On 31/08/18 07:06, Roman Lebedev via cfe-commits wrote:

I don't think this was reviewed. The differential is not in 'accepted' state.

Roman.

On Fri, Aug 31, 2018 at 2:11 AM, Stephen Kelly via cfe-commits
 wrote:

Author: steveire
Date: Thu Aug 30 16:11:01 2018
New Revision: 341141

URL: http://llvm.org/viewvc/llvm-project?rev=341141=rev
Log:
Extract parseBindID method

Subscribers: cfe-commits

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

Modified:
 cfe/trunk/include/clang/ASTMatchers/Dynamic/Parser.h
 cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp

Modified: cfe/trunk/include/clang/ASTMatchers/Dynamic/Parser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/Dynamic/Parser.h?rev=341141=341140=341141=diff
==
--- cfe/trunk/include/clang/ASTMatchers/Dynamic/Parser.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/Dynamic/Parser.h Thu Aug 30 16:11:01 
2018
@@ -234,6 +234,7 @@ private:
   const NamedValueMap *NamedValues,
   Diagnostics *Error);

+  bool parseBindID(std::string );
bool parseExpressionImpl(VariantValue *Value);
bool parseMatcherExpressionImpl(const TokenInfo ,
VariantValue *Value);

Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp?rev=341141=341140=341141=diff
==
--- cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Parser.cpp Thu Aug 30 16:11:01 2018
@@ -359,6 +359,43 @@ bool Parser::parseIdentifierPrefixImpl(V
return parseMatcherExpressionImpl(NameToken, Value);
  }

+bool Parser::parseBindID(std::string ) {
+  // Parse .bind("foo")
+  assert(Tokenizer->peekNextToken().Kind == TokenInfo::TK_Period);
+  Tokenizer->consumeNextToken(); // consume the period.
+  const TokenInfo BindToken = Tokenizer->consumeNextToken();
+  if (BindToken.Kind == TokenInfo::TK_CodeCompletion) {
+addCompletion(BindToken, MatcherCompletion("bind(\"", "bind", 1));
+return false;
+  }
+
+  const TokenInfo OpenToken = Tokenizer->consumeNextToken();
+  const TokenInfo IDToken = Tokenizer->consumeNextToken();
+  const TokenInfo CloseToken = Tokenizer->consumeNextToken();
+
+  // TODO: We could use different error codes for each/some to be more
+  //   explicit about the syntax error.
+  if (BindToken.Kind != TokenInfo::TK_Ident ||
+  BindToken.Text != TokenInfo::ID_Bind) {
+Error->addError(BindToken.Range, Error->ET_ParserMalformedBindExpr);
+return false;
+  }
+  if (OpenToken.Kind != TokenInfo::TK_OpenParen) {
+Error->addError(OpenToken.Range, Error->ET_ParserMalformedBindExpr);
+return false;
+  }
+  if (IDToken.Kind != TokenInfo::TK_Literal || !IDToken.Value.isString()) {
+Error->addError(IDToken.Range, Error->ET_ParserMalformedBindExpr);
+return false;
+  }
+  if (CloseToken.Kind != TokenInfo::TK_CloseParen) {
+Error->addError(CloseToken.Range, Error->ET_ParserMalformedBindExpr);
+return false;
+  }
+  BindID = IDToken.Value.getString();
+  return true;
+}
+
  /// Parse and validate a matcher expression.
  /// \return \c true on success, in which case \c Value has the matcher parsed.
  ///   If the input is malformed, or some argument has an error, it
@@ -425,38 +462,8 @@ bool Parser::parseMatcherExpressionImpl(

std::string BindID;
if (Tokenizer->peekNextToken().Kind == TokenInfo::TK_Period) {
-// Parse .bind("foo")
-Tokenizer->consumeNextToken();  // consume the period.
-const TokenInfo BindToken = Tokenizer->consumeNextToken();
-if (BindToken.Kind == TokenInfo::TK_CodeCompletion) {
-  addCompletion(BindToken, MatcherCompletion("bind(\"", "bind", 1));
+if (!parseBindID(BindID))
return false;
-}
-
-const TokenInfo OpenToken = Tokenizer->consumeNextToken();
-const TokenInfo IDToken = Tokenizer->consumeNextToken();
-const TokenInfo CloseToken = Tokenizer->consumeNextToken();
-
-// TODO: We could use different error codes for each/some to be more
-//   explicit about the syntax error.
-if (BindToken.Kind != TokenInfo::TK_Ident ||
-BindToken.Text != TokenInfo::ID_Bind) {
-  Error->addError(BindToken.Range, Error->ET_ParserMalformedBindExpr);
-  return false;
-}
-if (OpenToken.Kind != TokenInfo::TK_OpenParen) {
-  Error->addError(OpenToken.Range, Error->ET_ParserMalformedBindExpr);
-  

[PATCH] D51747: [clangd] Implement deprecation diagnostics with lower severity.

2018-09-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added reviewers: ioeric, sammccall, ilya-biryukov, hokein.
Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay.

Adds deprecation warnings to diagnostics. Also lowers the severity from
warning to notes to not to annoy people that work on big codebases.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51747

Files:
  clangd/ClangdServer.cpp
  clangd/Diagnostics.cpp
  unittests/clangd/ClangdUnitTests.cpp


Index: unittests/clangd/ClangdUnitTests.cpp
===
--- unittests/clangd/ClangdUnitTests.cpp
+++ unittests/clangd/ClangdUnitTests.cpp
@@ -38,6 +38,13 @@
   return arg.Range == Range && arg.Message == Message;
 }
 
+MATCHER_P3(Diag, Range, Message, Severity,
+   "Diag at " + llvm::to_string(Range) + " = [" + Message +
+   "] with Severity:" + llvm::to_string(Severity)) {
+  return arg.Range == Range && arg.Message == Message &&
+ arg.Severity == Severity;
+}
+
 MATCHER_P3(Fix, Range, Replacement, Message,
"Fix " + llvm::to_string(Range) + " => " +
testing::PrintToString(Replacement) + " = [" + Message + "]") {
@@ -220,6 +227,48 @@
   }
 }
 
+TEST(DiagnosticsTest, DiagnosticDeprecated) {
+  Annotations Test(R"cpp(
+void foo() __attribute__(($foodeprecation[[deprecated]]));
+class A {
+public:
+  int x __attribute__(($xdeprecation[[deprecated]]));
+};
+int main() {
+  $foo[[foo]]();
+  return A().$x[[x]];
+}
+  )cpp");
+  EXPECT_THAT(
+  TestTU::withCode(Test.code()).build().getDiagnostics(),
+  ElementsAre(
+  AllOf(Diag(Test.range("foo"), "'foo' is deprecated",
+ DiagnosticsEngine::Note),
+WithNote(
+Diag(Test.range("foodeprecation"),
+ "'foo' has been explicitly marked deprecated here"))),
+  AllOf(Diag(Test.range("x"), "'x' is deprecated",
+ DiagnosticsEngine::Note),
+WithNote(
+Diag(Test.range("xdeprecation"),
+ "'x' has been explicitly marked deprecated here");
+}
+
+TEST(DiagnosticsTest, DiagnosticDeprecatedWithFix) {
+  Annotations Test(R"cpp(
+void bar();
+void foo() __attribute__((deprecated("", "bar")));
+int main() {
+  $deprecated[[foo]]();
+}
+  )cpp");
+  EXPECT_THAT(
+  TestTU::withCode(Test.code()).build().getDiagnostics(),
+  ElementsAre(
+  WithFix(Fix(Test.range("deprecated"), "bar", "change 'foo' to 
'bar'"))
+  ));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clangd/Diagnostics.cpp
===
--- clangd/Diagnostics.cpp
+++ clangd/Diagnostics.cpp
@@ -292,10 +292,11 @@
 D.Message = Message.str();
 D.InsideMainFile = InsideMainFile;
 D.File = Info.getSourceManager().getFilename(Info.getLocation());
-D.Severity = DiagLevel;
 D.Category = DiagnosticIDs::getCategoryNameFromID(
  DiagnosticIDs::getCategoryNumberForDiag(Info.getID()))
  .str();
+D.Severity =
+D.Category == "Deprecations" ? DiagnosticsEngine::Note : DiagLevel;
 return D;
   };
 
Index: clangd/ClangdServer.cpp
===
--- clangd/ClangdServer.cpp
+++ clangd/ClangdServer.cpp
@@ -534,6 +534,7 @@
   // Inject the resource dir.
   // FIXME: Don't overwrite it if it's already there.
   C->CommandLine.push_back("-resource-dir=" + ResourceDir);
+  C->CommandLine.push_back("-Wdeprecated-declarations");
   return std::move(*C);
 }
 


Index: unittests/clangd/ClangdUnitTests.cpp
===
--- unittests/clangd/ClangdUnitTests.cpp
+++ unittests/clangd/ClangdUnitTests.cpp
@@ -38,6 +38,13 @@
   return arg.Range == Range && arg.Message == Message;
 }
 
+MATCHER_P3(Diag, Range, Message, Severity,
+   "Diag at " + llvm::to_string(Range) + " = [" + Message +
+   "] with Severity:" + llvm::to_string(Severity)) {
+  return arg.Range == Range && arg.Message == Message &&
+ arg.Severity == Severity;
+}
+
 MATCHER_P3(Fix, Range, Replacement, Message,
"Fix " + llvm::to_string(Range) + " => " +
testing::PrintToString(Replacement) + " = [" + Message + "]") {
@@ -220,6 +227,48 @@
   }
 }
 
+TEST(DiagnosticsTest, DiagnosticDeprecated) {
+  Annotations Test(R"cpp(
+void foo() __attribute__(($foodeprecation[[deprecated]]));
+class A {
+public:
+  int x __attribute__(($xdeprecation[[deprecated]]));
+};
+int main() {
+  $foo[[foo]]();
+  return A().$x[[x]];
+}
+  )cpp");
+  EXPECT_THAT(
+  TestTU::withCode(Test.code()).build().getDiagnostics(),
+  ElementsAre(
+  AllOf(Diag(Test.range("foo"), "'foo' is deprecated",
+

[PATCH] D51724: [clangd] Add "Deprecated" field to Symbol and CodeCompletion.

2018-09-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: unittests/clangd/SymbolCollectorTests.cpp:1020
+  const std::string Header = R"(
+void TestClangc() __attribute__((deprecated("", "")));
+void TestClangd();

No need for the optional parameters,  
```
void TestClangc() __attribute__((deprecated));
```
should work as well


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51724



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


[PATCH] D51192: Fix reported range of partial token replacement

2018-09-06 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a comment.

How? This is 'private' code. I don't think it's worth changing that or creating 
a test with a huge amount of infrastructure in order to test this indirectly.

Am I missing something?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51192



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


[PATCH] D51724: [clangd] Add "Deprecated" field to Symbol and CodeCompletion.

2018-09-06 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE341576: [clangd] Add Deprecated field to 
Symbol and CodeCompletion. (authored by ioeric, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D51724?vs=164259=164260#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51724

Files:
  clangd/CodeComplete.cpp
  clangd/CodeComplete.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/Quality.cpp
  clangd/index/Index.cpp
  clangd/index/Index.h
  clangd/index/MemIndex.cpp
  clangd/index/Merge.cpp
  clangd/index/Serialization.cpp
  clangd/index/SymbolCollector.cpp
  clangd/index/SymbolYAML.cpp
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/QualityTests.cpp
  unittests/clangd/SerializationTests.cpp
  unittests/clangd/SymbolCollectorTests.cpp

Index: unittests/clangd/QualityTests.cpp
===
--- unittests/clangd/QualityTests.cpp
+++ unittests/clangd/QualityTests.cpp
@@ -59,7 +59,7 @@
   F.References = 24; // TestTU doesn't count references, so fake it.
   Quality = {};
   Quality.merge(F);
-  EXPECT_FALSE(Quality.Deprecated); // FIXME: Include deprecated bit in index.
+  EXPECT_TRUE(Quality.Deprecated);
   EXPECT_FALSE(Quality.ReservedName);
   EXPECT_EQ(Quality.References, 24u);
   EXPECT_EQ(Quality.Category, SymbolQualitySignals::Function);
Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -77,6 +77,7 @@
   return Contains(AllOf(Named(std::move(Name)), Kind(K)));
 }
 MATCHER(IsDocumented, "") { return !arg.Documentation.empty(); }
+MATCHER(Deprecated, "") { return arg.Deprecated; }
 
 std::unique_ptr memIndex(std::vector Symbols) {
   SymbolSlab::Builder Slab;
@@ -161,7 +162,7 @@
   USR += Regex("^.*$").sub(USRFormat, Sym.Name); // e.g. func -> @F@func#
   Sym.ID = SymbolID(USR);
   Sym.SymInfo.Kind = Kind;
-  Sym.IsIndexedForCodeCompletion = true;
+  Sym.Flags |= Symbol::IndexedForCodeCompletion;
   Sym.Origin = SymbolOrigin::Static;
   return Sym;
 }
@@ -720,9 +721,11 @@
 TEST(CompletionTest, GlobalCompletionFiltering) {
 
   Symbol Class = cls("XYZ");
-  Class.IsIndexedForCodeCompletion = false;
+  Class.Flags = static_cast(
+  Class.Flags & ~(Symbol::IndexedForCodeCompletion));
   Symbol Func = func("XYZ::f");
-  Func.IsIndexedForCodeCompletion = false;
+  Func.Flags = static_cast(
+  Func.Flags & ~(Symbol::IndexedForCodeCompletion));
 
   auto Results = completions(R"(//  void f() {
   XYZ::f^
@@ -1374,6 +1377,7 @@
   EXPECT_EQ(R.documentation, "This is x().");
   EXPECT_THAT(R.additionalTextEdits, IsEmpty());
   EXPECT_EQ(R.sortText, sortText(1.0, "x"));
+  EXPECT_FALSE(R.deprecated);
 
   Opts.EnableSnippets = true;
   R = C.render(Opts);
@@ -1392,6 +1396,10 @@
   C.BundleSize = 2;
   R = C.render(Opts);
   EXPECT_EQ(R.detail, "[2 overloads]\n\"foo.h\"");
+
+  C.Deprecated = true;
+  R = C.render(Opts);
+  EXPECT_TRUE(R.deprecated);
 }
 
 TEST(CompletionTest, IgnoreRecoveryResults) {
@@ -1891,12 +1899,24 @@
   Sym.Name = "Clangd_Macro_Test";
   Sym.ID = SymbolID("c:foo.cpp@8@macro@Clangd_Macro_Test");
   Sym.SymInfo.Kind = index::SymbolKind::Macro;
-  Sym.IsIndexedForCodeCompletion = true;
+  Sym.Flags |= Symbol::IndexedForCodeCompletion;
   EXPECT_THAT(completions("#define Clangd_Macro_Test\nClangd_Macro_T^", {Sym})
   .Completions,
   UnorderedElementsAre(Named("Clangd_Macro_Test")));
 }
 
+TEST(CompletionTest, DeprecatedResults) {
+  std::string Body = R"cpp(
+void TestClangd();
+void TestClangc() __attribute__((deprecated("", "")));
+  )cpp";
+
+  EXPECT_THAT(
+  completions(Body + "int main() { TestClang^ }").Completions,
+  UnorderedElementsAre(AllOf(Named("TestClangd"), Not(Deprecated())),
+   AllOf(Named("TestClangc"), Deprecated(;
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: unittests/clangd/SerializationTests.cpp
===
--- unittests/clangd/SerializationTests.cpp
+++ unittests/clangd/SerializationTests.cpp
@@ -35,7 +35,7 @@
   End:
 Line: 1
 Column: 1
-IsIndexedForCodeCompletion:true
+Flags:1
 Documentation:'Foo doc'
 ReturnType:'int'
 IncludeHeaders:
@@ -62,7 +62,7 @@
   End:
 Line: 1
 Column: 1
-IsIndexedForCodeCompletion:false
+Flags:2
 Signature:'-sig'
 CompletionSnippetSuffix:'-snippet'
 ...
@@ -82,7 +82,8 @@
   EXPECT_EQ(Sym1.Documentation, "Foo doc");
   EXPECT_EQ(Sym1.ReturnType, "int");
   EXPECT_EQ(Sym1.CanonicalDeclaration.FileURI, "file:///path/foo.h");
-  EXPECT_TRUE(Sym1.IsIndexedForCodeCompletion);
+  EXPECT_TRUE(Sym1.Flags & Symbol::IndexedForCodeCompletion);
+  EXPECT_FALSE(Sym1.Flags & Symbol::Deprecated);
   EXPECT_THAT(Sym1.IncludeHeaders,
 

[clang-tools-extra] r341576 - [clangd] Add "Deprecated" field to Symbol and CodeCompletion.

2018-09-06 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Thu Sep  6 11:52:26 2018
New Revision: 341576

URL: http://llvm.org/viewvc/llvm-project?rev=341576=rev
Log:
[clangd] Add "Deprecated" field to Symbol and CodeCompletion.

Summary: Also set "deprecated" field in LSP CompletionItem.

Reviewers: sammccall, kadircet

Reviewed By: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/CodeComplete.h
clang-tools-extra/trunk/clangd/Protocol.cpp
clang-tools-extra/trunk/clangd/Protocol.h
clang-tools-extra/trunk/clangd/Quality.cpp
clang-tools-extra/trunk/clangd/index/Index.cpp
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/clangd/index/MemIndex.cpp
clang-tools-extra/trunk/clangd/index/Merge.cpp
clang-tools-extra/trunk/clangd/index/Serialization.cpp
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/clangd/index/SymbolYAML.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp
clang-tools-extra/trunk/unittests/clangd/SerializationTests.cpp
clang-tools-extra/trunk/unittests/clangd/SymbolCollectorTests.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=341576=341575=341576=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Thu Sep  6 11:52:26 2018
@@ -353,6 +353,8 @@ struct CodeCompletionBuilder {
   return std::tie(X.range.start.line, X.range.start.character) 
<
  std::tie(Y.range.start.line, Y.range.start.character);
 });
+  Completion.Deprecated |=
+  (C.SemaResult->Availability == CXAvailability_Deprecated);
 }
 if (C.IndexResult) {
   Completion.Origin |= C.IndexResult->Origin;
@@ -362,6 +364,7 @@ struct CodeCompletionBuilder {
 Completion.Kind = toCompletionItemKind(C.IndexResult->SymInfo.Kind);
   if (Completion.Name.empty())
 Completion.Name = C.IndexResult->Name;
+  Completion.Deprecated |= (C.IndexResult->Flags & Symbol::Deprecated);
 }
 
 // Turn absolute path into a literal string that can be #included.
@@ -1625,6 +1628,7 @@ CompletionItem CodeCompletion::render(co
   LSP.kind = Kind;
   LSP.detail = BundleSize > 1 ? llvm::formatv("[{0} overloads]", BundleSize)
   : ReturnType;
+  LSP.deprecated = Deprecated;
   if (InsertInclude)
 LSP.detail += "\n" + InsertInclude->Header;
   LSP.documentation = Documentation;
@@ -1656,6 +1660,7 @@ CompletionItem CodeCompletion::render(co
  : InsertTextFormat::PlainText;
   if (InsertInclude && InsertInclude->Insertion)
 LSP.additionalTextEdits.push_back(*InsertInclude->Insertion);
+
   return LSP;
 }
 

Modified: clang-tools-extra/trunk/clangd/CodeComplete.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.h?rev=341576=341575=341576=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.h (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.h Thu Sep  6 11:52:26 2018
@@ -177,6 +177,9 @@ struct CodeCompletion {
   };
   Scores Score;
 
+  /// Indicates if this item is deprecated.
+  bool Deprecated = false;
+
   // Serialize this to an LSP completion item. This is a lossy operation.
   CompletionItem render(const CodeCompleteOptions &) const;
 };

Modified: clang-tools-extra/trunk/clangd/Protocol.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=341576=341575=341576=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.cpp (original)
+++ clang-tools-extra/trunk/clangd/Protocol.cpp Thu Sep  6 11:52:26 2018
@@ -517,6 +517,8 @@ json::Value toJSON(const CompletionItem
 Result["textEdit"] = *CI.textEdit;
   if (!CI.additionalTextEdits.empty())
 Result["additionalTextEdits"] = json::Array(CI.additionalTextEdits);
+  if (CI.deprecated)
+Result["deprecated"] = CI.deprecated;
   return std::move(Result);
 }
 

Modified: clang-tools-extra/trunk/clangd/Protocol.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.h?rev=341576=341575=341576=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.h (original)
+++ clang-tools-extra/trunk/clangd/Protocol.h Thu Sep  6 11:52:26 2018
@@ -768,6 +768,9 @@ struct CompletionItem {
   /// themselves.
   std::vector additionalTextEdits;
 
+  

[PATCH] D51724: [clangd] Add "Deprecated" field to Symbol and CodeCompletion.

2018-09-06 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 164259.
ioeric added a comment.

- merged with origin/master


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51724

Files:
  clangd/CodeComplete.cpp
  clangd/CodeComplete.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/Quality.cpp
  clangd/index/Index.cpp
  clangd/index/Index.h
  clangd/index/MemIndex.cpp
  clangd/index/Merge.cpp
  clangd/index/Serialization.cpp
  clangd/index/SymbolCollector.cpp
  clangd/index/SymbolYAML.cpp
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/QualityTests.cpp
  unittests/clangd/SerializationTests.cpp
  unittests/clangd/SymbolCollectorTests.cpp

Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -80,8 +80,10 @@
 }
 MATCHER_P(RefCount, R, "") { return int(arg.References) == R; }
 MATCHER_P(ForCodeCompletion, IsIndexedForCodeCompletion, "") {
-  return arg.IsIndexedForCodeCompletion == IsIndexedForCodeCompletion;
+  return static_cast(arg.Flags & Symbol::IndexedForCodeCompletion) ==
+ IsIndexedForCodeCompletion;
 }
+MATCHER(Deprecated, "") { return arg.Flags & Symbol::Deprecated; }
 MATCHER(RefRange, "") {
   const Ref  = testing::get<0>(arg);
   const Range  = testing::get<1>(arg);
@@ -1014,6 +1016,17 @@
  DeclRange(Header.range("used");
 }
 
+TEST_F(SymbolCollectorTest, DeprecatedSymbols) {
+  const std::string Header = R"(
+void TestClangc() __attribute__((deprecated("", "")));
+void TestClangd();
+  )";
+  runSymbolCollector(Header, /**/ "");
+  EXPECT_THAT(Symbols, UnorderedElementsAre(
+   AllOf(QName("TestClangc"), Deprecated()),
+   AllOf(QName("TestClangd"), Not(Deprecated();
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: unittests/clangd/SerializationTests.cpp
===
--- unittests/clangd/SerializationTests.cpp
+++ unittests/clangd/SerializationTests.cpp
@@ -35,7 +35,7 @@
   End:
 Line: 1
 Column: 1
-IsIndexedForCodeCompletion:true
+Flags:1
 Documentation:'Foo doc'
 ReturnType:'int'
 IncludeHeaders:
@@ -62,7 +62,7 @@
   End:
 Line: 1
 Column: 1
-IsIndexedForCodeCompletion:false
+Flags:2
 Signature:'-sig'
 CompletionSnippetSuffix:'-snippet'
 ...
@@ -82,7 +82,8 @@
   EXPECT_EQ(Sym1.Documentation, "Foo doc");
   EXPECT_EQ(Sym1.ReturnType, "int");
   EXPECT_EQ(Sym1.CanonicalDeclaration.FileURI, "file:///path/foo.h");
-  EXPECT_TRUE(Sym1.IsIndexedForCodeCompletion);
+  EXPECT_TRUE(Sym1.Flags & Symbol::IndexedForCodeCompletion);
+  EXPECT_FALSE(Sym1.Flags & Symbol::Deprecated);
   EXPECT_THAT(Sym1.IncludeHeaders,
   UnorderedElementsAre(IncludeHeaderWithRef("include1", 7u),
IncludeHeaderWithRef("include2", 3u)));
@@ -94,7 +95,8 @@
   EXPECT_EQ(Sym2.Signature, "-sig");
   EXPECT_EQ(Sym2.ReturnType, "");
   EXPECT_EQ(Sym2.CanonicalDeclaration.FileURI, "file:///path/bar.h");
-  EXPECT_FALSE(Sym2.IsIndexedForCodeCompletion);
+  EXPECT_FALSE(Sym2.Flags & Symbol::IndexedForCodeCompletion);
+  EXPECT_TRUE(Sym2.Flags & Symbol::Deprecated);
 
   std::string ConcatenatedYAML;
   {
Index: unittests/clangd/QualityTests.cpp
===
--- unittests/clangd/QualityTests.cpp
+++ unittests/clangd/QualityTests.cpp
@@ -59,7 +59,7 @@
   F.References = 24; // TestTU doesn't count references, so fake it.
   Quality = {};
   Quality.merge(F);
-  EXPECT_FALSE(Quality.Deprecated); // FIXME: Include deprecated bit in index.
+  EXPECT_TRUE(Quality.Deprecated);
   EXPECT_FALSE(Quality.ReservedName);
   EXPECT_EQ(Quality.References, 24u);
   EXPECT_EQ(Quality.Category, SymbolQualitySignals::Function);
Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -77,6 +77,7 @@
   return Contains(AllOf(Named(std::move(Name)), Kind(K)));
 }
 MATCHER(IsDocumented, "") { return !arg.Documentation.empty(); }
+MATCHER(Deprecated, "") { return arg.Deprecated; }
 
 std::unique_ptr memIndex(std::vector Symbols) {
   SymbolSlab::Builder Slab;
@@ -161,7 +162,7 @@
   USR += Regex("^.*$").sub(USRFormat, Sym.Name); // e.g. func -> @F@func#
   Sym.ID = SymbolID(USR);
   Sym.SymInfo.Kind = Kind;
-  Sym.IsIndexedForCodeCompletion = true;
+  Sym.Flags |= Symbol::IndexedForCodeCompletion;
   Sym.Origin = SymbolOrigin::Static;
   return Sym;
 }
@@ -720,9 +721,11 @@
 TEST(CompletionTest, GlobalCompletionFiltering) {
 
   Symbol Class = cls("XYZ");
-  Class.IsIndexedForCodeCompletion = false;
+  Class.Flags = static_cast(
+  Class.Flags & ~(Symbol::IndexedForCodeCompletion));
   Symbol Func = 

[PATCH] D51724: [clangd] Add "Deprecated" field to Symbol and CodeCompletion.

2018-09-06 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 164258.
ioeric marked 5 inline comments as done.
ioeric added a comment.

- addressed review comments


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51724

Files:
  clangd/CodeComplete.cpp
  clangd/CodeComplete.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/Quality.cpp
  clangd/index/Index.cpp
  clangd/index/Index.h
  clangd/index/MemIndex.cpp
  clangd/index/Merge.cpp
  clangd/index/Serialization.cpp
  clangd/index/SymbolCollector.cpp
  clangd/index/SymbolYAML.cpp
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/QualityTests.cpp
  unittests/clangd/SerializationTests.cpp
  unittests/clangd/SymbolCollectorTests.cpp

Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -80,8 +80,10 @@
 }
 MATCHER_P(RefCount, R, "") { return int(arg.References) == R; }
 MATCHER_P(ForCodeCompletion, IsIndexedForCodeCompletion, "") {
-  return arg.IsIndexedForCodeCompletion == IsIndexedForCodeCompletion;
+  return static_cast(arg.Flags & Symbol::IndexedForCodeCompletion) ==
+ IsIndexedForCodeCompletion;
 }
+MATCHER(Deprecated, "") { return arg.Flags & Symbol::Deprecated; }
 MATCHER(RefRange, "") {
   const Ref  = testing::get<0>(arg);
   const Range  = testing::get<1>(arg);
@@ -1014,6 +1016,17 @@
  DeclRange(Header.range("used");
 }
 
+TEST_F(SymbolCollectorTest, DeprecatedSymbols) {
+  const std::string Header = R"(
+void TestClangc() __attribute__((deprecated("", "")));
+void TestClangd();
+  )";
+  runSymbolCollector(Header, /**/ "");
+  EXPECT_THAT(Symbols, UnorderedElementsAre(
+   AllOf(QName("TestClangc"), Deprecated()),
+   AllOf(QName("TestClangd"), Not(Deprecated();
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: unittests/clangd/SerializationTests.cpp
===
--- unittests/clangd/SerializationTests.cpp
+++ unittests/clangd/SerializationTests.cpp
@@ -35,7 +35,7 @@
   End:
 Line: 1
 Column: 1
-IsIndexedForCodeCompletion:true
+Flags:1
 Documentation:'Foo doc'
 ReturnType:'int'
 IncludeHeaders:
@@ -62,7 +62,7 @@
   End:
 Line: 1
 Column: 1
-IsIndexedForCodeCompletion:false
+Flags:2
 Signature:'-sig'
 CompletionSnippetSuffix:'-snippet'
 ...
@@ -82,7 +82,8 @@
   EXPECT_EQ(Sym1.Documentation, "Foo doc");
   EXPECT_EQ(Sym1.ReturnType, "int");
   EXPECT_EQ(Sym1.CanonicalDeclaration.FileURI, "file:///path/foo.h");
-  EXPECT_TRUE(Sym1.IsIndexedForCodeCompletion);
+  EXPECT_TRUE(Sym1.Flags & Symbol::IndexedForCodeCompletion);
+  EXPECT_FALSE(Sym1.Flags & Symbol::Deprecated);
   EXPECT_THAT(Sym1.IncludeHeaders,
   UnorderedElementsAre(IncludeHeaderWithRef("include1", 7u),
IncludeHeaderWithRef("include2", 3u)));
@@ -94,7 +95,8 @@
   EXPECT_EQ(Sym2.Signature, "-sig");
   EXPECT_EQ(Sym2.ReturnType, "");
   EXPECT_EQ(Sym2.CanonicalDeclaration.FileURI, "file:///path/bar.h");
-  EXPECT_FALSE(Sym2.IsIndexedForCodeCompletion);
+  EXPECT_FALSE(Sym2.Flags & Symbol::IndexedForCodeCompletion);
+  EXPECT_TRUE(Sym2.Flags & Symbol::Deprecated);
 
   std::string ConcatenatedYAML;
   {
Index: unittests/clangd/QualityTests.cpp
===
--- unittests/clangd/QualityTests.cpp
+++ unittests/clangd/QualityTests.cpp
@@ -59,7 +59,7 @@
   F.References = 24; // TestTU doesn't count references, so fake it.
   Quality = {};
   Quality.merge(F);
-  EXPECT_FALSE(Quality.Deprecated); // FIXME: Include deprecated bit in index.
+  EXPECT_TRUE(Quality.Deprecated);
   EXPECT_FALSE(Quality.ReservedName);
   EXPECT_EQ(Quality.References, 24u);
   EXPECT_EQ(Quality.Category, SymbolQualitySignals::Function);
Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -77,6 +77,7 @@
   return Contains(AllOf(Named(std::move(Name)), Kind(K)));
 }
 MATCHER(IsDocumented, "") { return !arg.Documentation.empty(); }
+MATCHER(Deprecated, "") { return arg.Deprecated; }
 
 std::unique_ptr memIndex(std::vector Symbols) {
   SymbolSlab::Builder Slab;
@@ -161,7 +162,7 @@
   USR += Regex("^.*$").sub(USRFormat, Sym.Name); // e.g. func -> @F@func#
   Sym.ID = SymbolID(USR);
   Sym.SymInfo.Kind = Kind;
-  Sym.IsIndexedForCodeCompletion = true;
+  Sym.Flags |= Symbol::IndexedForCodeCompletion;
   Sym.Origin = SymbolOrigin::Static;
   return Sym;
 }
@@ -720,9 +721,11 @@
 TEST(CompletionTest, GlobalCompletionFiltering) {
 
   Symbol Class = cls("XYZ");
-  Class.IsIndexedForCodeCompletion = false;
+  Class.Flags = static_cast(
+  Class.Flags & 

[PATCH] D51714: CMake: Deprecate using llvm-config to detect llvm installation

2018-09-06 Thread Stephen Kelly via Phabricator via cfe-commits
steveire accepted this revision.
steveire added a comment.
This revision is now accepted and ready to land.

Brilliant, I've wanted to do this for years, and I still have many improvements 
to the LLVM/Clang cmake files on my todo list. Good to know others are 
similarly motivated.




Comment at: CMakeLists.txt:13
 message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}")
+message(WARNING "Using llvm-config to detect the LLVM installation is \
+  deprecated.  The installed cmake files should be used \

message(DEPRECATION) is designed for deprecation messages. It announces itself 
as a "CMake Deprecation Warning at CMakeLists.txt:6 (message):".

The user can silence the warning with `-Wno-deprecated` or make it an error 
with `Wdeprecated` since old versions of CMake: 
https://cmake.org/pipermail/cmake-developers/2013-July/019634.html


Repository:
  rC Clang

https://reviews.llvm.org/D51714



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


[PATCH] D51741: [coro]Pass rvalue reference for named local variable to return_value

2018-09-06 Thread Tanoy Sinha via Phabricator via cfe-commits
tks2103 added a comment.

also fails 
https://github.com/llvm-mirror/clang/blob/master/test/SemaCXX/coroutines.cpp#L494
 with `address of overloaded function 'g' does not match required type 
''`
also fails 
https://github.com/llvm-mirror/clang/blob/master/test/SemaCXX/coroutines.cpp#L505
 with `address of overloaded function 'g' does not match required type 
''`


Repository:
  rC Clang

https://reviews.llvm.org/D51741



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


[PATCH] D51393: Provide a method for generating deterministic IDs for pointers allocated in BumpPtrAllocator

2018-09-06 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov updated this revision to Diff 164255.
george.karpenkov marked 2 inline comments as done.

https://reviews.llvm.org/D51393

Files:
  llvm/include/llvm/Support/Allocator.h


Index: llvm/include/llvm/Support/Allocator.h
===
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,34 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = reinterpret_cast(Ptr);
+long InSlabIdx = 0;
+for (size_t Idx = 0, E = Slabs.size(); Idx < E; Idx++) {
+  const char *S = reinterpret_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx + (P - S);
+  InSlabIdx += computeSlabSize(Idx);
+}
+
+// Use negative index to denote custom sized slabs.
+long InCustomSizedSlabIdx = -1;
+for (size_t Idx = 0, E = CustomSizedSlabs.size(); Idx < E; Idx++) {
+  const char *S =
+  reinterpret_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return InCustomSizedSlabIdx - (P - S);
+  InCustomSizedSlabIdx -= Size;
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)


Index: llvm/include/llvm/Support/Allocator.h
===
--- llvm/include/llvm/Support/Allocator.h
+++ llvm/include/llvm/Support/Allocator.h
@@ -21,6 +21,7 @@
 #ifndef LLVM_SUPPORT_ALLOCATOR_H
 #define LLVM_SUPPORT_ALLOCATOR_H
 
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -283,6 +284,34 @@
 
   size_t GetNumSlabs() const { return Slabs.size() + CustomSizedSlabs.size(); }
 
+  /// \return An index uniquely and reproducibly identifying
+  /// an input pointer \p Ptr in the given allocator.
+  /// The returned value is negative iff the object is inside a custom-size
+  /// slab.
+  /// Returns an empty optional if the pointer is not found in the allocator.
+  llvm::Optional identifyObject(const void *Ptr) {
+const char *P = reinterpret_cast(Ptr);
+long InSlabIdx = 0;
+for (size_t Idx = 0, E = Slabs.size(); Idx < E; Idx++) {
+  const char *S = reinterpret_cast(Slabs[Idx]);
+  if (P >= S && P < S + computeSlabSize(Idx))
+return InSlabIdx + (P - S);
+  InSlabIdx += computeSlabSize(Idx);
+}
+
+// Use negative index to denote custom sized slabs.
+long InCustomSizedSlabIdx = -1;
+for (size_t Idx = 0, E = CustomSizedSlabs.size(); Idx < E; Idx++) {
+  const char *S =
+  reinterpret_cast(CustomSizedSlabs[Idx].first);
+  size_t Size = CustomSizedSlabs[Idx].second;
+  if (P >= S && P < S + Size)
+return InCustomSizedSlabIdx - (P - S);
+  InCustomSizedSlabIdx -= Size;
+}
+return None;
+  }
+
   size_t getTotalMemory() const {
 size_t TotalMemory = 0;
 for (auto I = Slabs.begin(), E = Slabs.end(); I != E; ++I)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51741: [coro]Pass rvalue reference for named local variable to return_value

2018-09-06 Thread Tanoy Sinha via Phabricator via cfe-commits
tks2103 added a comment.

currently changes the behavior for a few cases:

something like

  void coro() {
co_return {4};
  }

throws `illegal initializer type 'void'`


Repository:
  rC Clang

https://reviews.llvm.org/D51741



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


r341572 - Re-land r334417 "[MS] Use mangled names and comdats for string merging with ASan"

2018-09-06 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Thu Sep  6 11:25:39 2018
New Revision: 341572

URL: http://llvm.org/viewvc/llvm-project?rev=341572=rev
Log:
Re-land r334417 "[MS] Use mangled names and comdats for string merging with 
ASan"

The issue with -fprofile-generate was fixed and the dependent CL
relanded in r340232.

Added:
cfe/trunk/test/CodeGen/asan-strings.c
Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=341572=341571=341572=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Sep  6 11:25:39 2018
@@ -4305,15 +4305,13 @@ CodeGenModule::GetAddrOfConstantStringFr
   StringRef GlobalVariableName;
   llvm::GlobalValue::LinkageTypes LT;
 
-  // Mangle the string literal if the ABI allows for it.  However, we cannot
-  // do this if  we are compiling with ASan or -fwritable-strings because they
-  // rely on strings having normal linkage.
-  if (!LangOpts.WritableStrings &&
-  !LangOpts.Sanitize.has(SanitizerKind::Address) &&
-  getCXXABI().getMangleContext().shouldMangleStringLiteral(S)) {
+  // Mangle the string literal if that's how the ABI merges duplicate strings.
+  // Don't do it if they are writable, since we don't want writes in one TU to
+  // affect strings in another.
+  if (getCXXABI().getMangleContext().shouldMangleStringLiteral(S) &&
+  !LangOpts.WritableStrings) {
 llvm::raw_svector_ostream Out(MangledNameBuffer);
 getCXXABI().getMangleContext().mangleStringLiteral(S, Out);
-
 LT = llvm::GlobalValue::LinkOnceODRLinkage;
 GlobalVariableName = MangledNameBuffer;
   } else {

Added: cfe/trunk/test/CodeGen/asan-strings.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/asan-strings.c?rev=341572=auto
==
--- cfe/trunk/test/CodeGen/asan-strings.c (added)
+++ cfe/trunk/test/CodeGen/asan-strings.c Thu Sep  6 11:25:39 2018
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fsanitize=address 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefix=LINUX
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fsanitize=address 
-disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefix=WINDOWS
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fsanitize=address 
-fwritable-strings -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s 
--check-prefix=WINWRITE
+
+// On Linux (and basically every non-MS target) string literals are emitted 
with
+// private linkage, which means ASan can freely instrument them. On Windows,
+// they are emitted with comdats. ASan's global instrumentation code for COFF
+// knows how to make the metadata comdat associative, so the string literal
+// global is only registered if the instrumented global prevails during 
linking.
+
+const char *foo() { return "asdf"; }
+
+// LINUX: @.str = private unnamed_addr constant [5 x i8] c"asdf\00", align 1
+
+// WINDOWS: @"??_C@_04JIHMPGLA@asdf?$AA@" = linkonce_odr dso_local 
unnamed_addr constant [5 x i8] c"asdf\00", comdat, align 1
+
+// WINWRITE: @.str = private unnamed_addr global [5 x i8] c"asdf\00", align 1


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


[PATCH] D51650: Implement target_clones multiversioning

2018-09-06 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 164251.
erichkeane marked 9 inline comments as done.
erichkeane added a comment.

fix aaron's comments.


https://reviews.llvm.org/D51650

Files:
  include/clang/AST/Decl.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/AST/Decl.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/attr-cpuspecific.c
  test/CodeGen/attr-target-clones.c
  test/Misc/pragma-attribute-supported-attributes-list.test
  test/Sema/attr-target-clones.c

Index: test/Sema/attr-target-clones.c
===
--- /dev/null
+++ test/Sema/attr-target-clones.c
@@ -0,0 +1,72 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu  -fsyntax-only -verify %s
+
+// expected-error@+1 {{'target_clones' multiversioning requires a default target}}
+void __attribute__((target_clones("sse4.2", "arch=sandybridge")))
+no_default(void);
+
+// expected-error@+2 {{'target_clones' and 'target' attributes are not compatible}}
+// expected-note@+1 {{conflicting attribute is here}}
+void __attribute__((target("sse4.2"), target_clones("arch=sandybridge")))
+ignored_attr(void);
+// expected-error@+2 {{'target' and 'target_clones' attributes are not compatible}}
+// expected-note@+1 {{conflicting attribute is here}}
+void __attribute__((target_clones("arch=sandybridge,default"), target("sse4.2")))
+ignored_attr2(void);
+
+int redecl(void);
+int __attribute__((target_clones("sse4.2", "default"))) redecl(void) { return 1; }
+
+int __attribute__((target_clones("sse4.2", "default"))) redecl2(void);
+int __attribute__((target_clones("sse4.2", "default"))) redecl2(void) { return 1; }
+
+int __attribute__((target_clones("sse4.2", "default"))) redecl3(void);
+int redecl3(void);
+
+int __attribute__((target_clones("sse4.2", "arch=atom", "default"))) redecl4(void);
+// expected-error@+3 {{'target_clones' attribute does not match previous declaration}}
+// expected-note@-2 {{previous declaration is here}}
+int __attribute__((target_clones("sse4.2", "arch=sandybridge", "default")))
+redecl4(void) { return 1; }
+
+int __attribute__((target("sse4.2"))) redef2(void) { return 1; }
+// expected-error@+2 {{multiversioning attributes cannot be combined}}
+// expected-note@-2 {{previous declaration is here}}
+int __attribute__((target_clones("sse4.2", "default"))) redef2(void) { return 1; }
+
+int __attribute__((target_clones("sse4.2,default"))) redef3(void) { return 1; }
+// expected-error@+2 {{redefinition of 'redef3'}}
+// expected-note@-2 {{previous definition is here}}
+int __attribute__((target_clones("sse4.2,default"))) redef3(void) { return 1; }
+
+int __attribute__((target_clones("sse4.2,default"))) redef4(void) { return 1; }
+// expected-error@+2 {{redefinition of 'redef4'}}
+// expected-note@-2 {{previous definition is here}}
+int __attribute__((target_clones("sse4.2,default"))) redef4(void) { return 1; }
+
+// No error here... duplicates are allowed because they alter name mangling.
+int __attribute__((target_clones("arch=atom,arch=atom", "arch=atom,default")))
+dupes(void) { return 1; }
+
+// expected-warning@+1 {{unsupported '' in the 'target_clones' attribute string;}}
+void __attribute__((target_clones("")))
+empty_target_1(void);
+// expected-warning@+1 {{unsupported '' in the 'target_clones' attribute string;}}
+void __attribute__((target_clones(",default")))
+empty_target_2(void);
+// expected-warning@+1 {{unsupported '' in the 'target_clones' attribute string;}}
+void __attribute__((target_clones("default,")))
+empty_target_3(void);
+// expected-warning@+1 {{unsupported '' in the 'target_clones' attribute string;}}
+void __attribute__((target_clones("default, ,avx2")))
+empty_target_4(void);
+
+// expected-warning@+1 {{unsupported '' in the 'target_clones' attribute string;}}
+void __attribute__((target_clones("default,avx2", "")))
+empty_target_5(void);
+
+int mv_after_use(void);
+int useage() {
+  return mv_after_use();
+}
+// expected-error@+1 {{function declaration cannot become a multiversioned function after first usage}}
+int __attribute__((target_clones("sse4.2", "default"))) mv_after_use(void) { return 1; }
Index: test/Misc/pragma-attribute-supported-attributes-list.test
===
--- test/Misc/pragma-attribute-supported-attributes-list.test
+++ test/Misc/pragma-attribute-supported-attributes-list.test
@@ -2,7 +2,7 @@
 
 // The number of supported attributes should never go down!
 
-// CHECK: #pragma clang attribute supports 128 attributes:
+// CHECK: #pragma clang attribute supports 129 attributes:
 // CHECK-NEXT: AMDGPUFlatWorkGroupSize (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumSGPR (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumVGPR 

[PATCH] D51741: [coro]Pass rvalue reference for named local variable to return_value

2018-09-06 Thread Tanoy Sinha via Phabricator via cfe-commits
tks2103 created this revision.
tks2103 added reviewers: modocache, GorNishanov.
Herald added a subscriber: cfe-commits.
tks2103 edited the summary of this revision.

Addressing https://bugs.llvm.org/show_bug.cgi?id=37265.

Implements [class.copy]/33 of coroutines TS

When the criteria for elision of a copy/move operation are met, but not
for an exception-declaration, and the object to be copied is designated by an 
lvalue, or when the
expression in a return or co_return statement is a (possibly parenthesized) 
id-expression that
names an object with automatic storage duration declared in the body or
parameter-declaration-clause of the innermost enclosing function or 
lambda-expression, overload resolution to select
the constructor for the copy or the return_value overload to call is first 
performed as if the object
were designated by an rvalue.


Repository:
  rC Clang

https://reviews.llvm.org/D51741

Files:
  lib/Sema/SemaCoroutine.cpp
  test/SemaCXX/coroutine-rvo.cpp


Index: test/SemaCXX/coroutine-rvo.cpp
===
--- /dev/null
+++ test/SemaCXX/coroutine-rvo.cpp
@@ -0,0 +1,69 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -stdlib=libc++ -std=c++1z 
-fcoroutines-ts -fsyntax-only
+
+namespace std::experimental {
+template  struct coroutine_handle {
+  coroutine_handle() = default;
+  static coroutine_handle from_address(void *) noexcept;
+};
+
+template <> struct coroutine_handle {
+  static coroutine_handle from_address(void *) noexcept;
+  coroutine_handle() = default;
+  template 
+  coroutine_handle(coroutine_handle) noexcept;
+};
+
+template 
+struct void_t_imp {
+  using type = void;
+};
+template 
+using void_t = typename void_t_imp::type;
+
+template 
+struct traits_sfinae_base {};
+
+template 
+struct traits_sfinae_base> {
+  using promise_type = typename T::promise_type;
+};
+
+template 
+struct coroutine_traits : public traits_sfinae_base {};
+}
+
+struct suspend_never {
+  bool await_ready() noexcept;
+  void await_suspend(std::experimental::coroutine_handle<>) noexcept;
+  void await_resume() noexcept;
+};
+
+struct MoveOnly {
+  MoveOnly() {};
+  MoveOnly(const MoveOnly&) = delete;
+  MoveOnly(MoveOnly&&) noexcept {};
+  ~MoveOnly() {};
+};
+
+template 
+struct task {
+  struct promise_type {
+auto initial_suspend() { return suspend_never{}; }
+auto final_suspend() { return suspend_never{}; }
+auto get_return_object() { return task{}; }
+static void unhandled_exception() {}
+void return_value(T&& value) {}
+  };
+};
+
+task f() {
+  MoveOnly value;
+  co_return value;
+}
+
+int main() {
+  f();
+  return 0;
+}
+
+// expected-no-diagnostics
Index: lib/Sema/SemaCoroutine.cpp
===
--- lib/Sema/SemaCoroutine.cpp
+++ lib/Sema/SemaCoroutine.cpp
@@ -841,6 +841,16 @@
 E = R.get();
   }
 
+  // Move the return value if we can
+  if (E) {
+InitializedEntity Entity =
+InitializedEntity::InitializeResult(Loc, E->getType(), false);
+ExprResult MoveResult =
+this->PerformMoveOrCopyInitialization(Entity, nullptr, E->getType(), 
E);
+if (MoveResult.get())
+  E = MoveResult.get();
+  }
+
   // FIXME: If the operand is a reference to a variable that's about to go out
   // of scope, we should treat the operand as an xvalue for this overload
   // resolution.


Index: test/SemaCXX/coroutine-rvo.cpp
===
--- /dev/null
+++ test/SemaCXX/coroutine-rvo.cpp
@@ -0,0 +1,69 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -stdlib=libc++ -std=c++1z -fcoroutines-ts -fsyntax-only
+
+namespace std::experimental {
+template  struct coroutine_handle {
+  coroutine_handle() = default;
+  static coroutine_handle from_address(void *) noexcept;
+};
+
+template <> struct coroutine_handle {
+  static coroutine_handle from_address(void *) noexcept;
+  coroutine_handle() = default;
+  template 
+  coroutine_handle(coroutine_handle) noexcept;
+};
+
+template 
+struct void_t_imp {
+  using type = void;
+};
+template 
+using void_t = typename void_t_imp::type;
+
+template 
+struct traits_sfinae_base {};
+
+template 
+struct traits_sfinae_base> {
+  using promise_type = typename T::promise_type;
+};
+
+template 
+struct coroutine_traits : public traits_sfinae_base {};
+}
+
+struct suspend_never {
+  bool await_ready() noexcept;
+  void await_suspend(std::experimental::coroutine_handle<>) noexcept;
+  void await_resume() noexcept;
+};
+
+struct MoveOnly {
+  MoveOnly() {};
+  MoveOnly(const MoveOnly&) = delete;
+  MoveOnly(MoveOnly&&) noexcept {};
+  ~MoveOnly() {};
+};
+
+template 
+struct task {
+  struct promise_type {
+auto initial_suspend() { return suspend_never{}; }
+auto final_suspend() { return suspend_never{}; }
+auto get_return_object() { return task{}; }
+static void unhandled_exception() {}
+void return_value(T&& value) {}
+  };
+};
+
+task f() {
+  

r341570 - [OPENMP] Fix PR38823: Do not emit vtable if it is not used in target

2018-09-06 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Sep  6 10:56:28 2018
New Revision: 341570

URL: http://llvm.org/viewvc/llvm-project?rev=341570=rev
Log:
[OPENMP] Fix PR38823: Do not emit vtable if it is not used in target
context.

If the explicit template instantiation definition defined outside of the
target context, its vtable should not be marked as used. This is true
for other situations where the compiler want to emit vtables
unconditionally.

Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/OpenMP/declare_target_codegen.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=341570=341569=341570=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Sep  6 10:56:28 2018
@@ -14903,6 +14903,11 @@ void Sema::MarkVTableUsed(SourceLocation
   if (!Class->isDynamicClass() || Class->isDependentContext() ||
   CurContext->isDependentContext() || isUnevaluatedContext())
 return;
+  // Do not mark as used if compiling for the device outside of the target
+  // region.
+  if (LangOpts.OpenMP && LangOpts.OpenMPIsDevice &&
+  !isInOpenMPDeclareTargetContext() && !getCurFunctionDecl())
+return;
 
   // Try to insert this class into the map.
   LoadExternalVTableUses();

Modified: cfe/trunk/test/OpenMP/declare_target_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/declare_target_codegen.cpp?rev=341570=341569=341570=diff
==
--- cfe/trunk/test/OpenMP/declare_target_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/declare_target_codegen.cpp Thu Sep  6 10:56:28 2018
@@ -12,7 +12,8 @@
 
 // SIMD-ONLY-NOT: {{__kmpc|__tgt}}
 
-// CHECK-NOT: define {{.*}}{{baz1|baz4|maini1}}
+// CHECK-NOT: define {{.*}}{{baz1|baz4|maini1|Base}}
+// CHECK-DAG: Bake
 // CHECK-NOT: @{{hhh|ggg|fff|eee}} =
 // CHECK-DAG: @aaa = external global i32,
 // CHECK-DAG: @bbb = global i32 0,
@@ -140,9 +141,25 @@ int baz5() {
   return a;
 }
 
+template 
+struct Base {
+  virtual ~Base() {}
+};
+
+template class Base;
+
+template 
+struct Bake {
+  virtual ~Bake() {}
+};
+
+#pragma omp declare target
+template class Bake;
+#pragma omp end declare target
+
 // CHECK-DAG: declare extern_weak signext i32 @__create()
 
-// CHECK-NOT: define {{.*}}{{baz1|baz4|maini1}}
+// CHECK-NOT: define {{.*}}{{baz1|baz4|maini1|Base}}
 
 // CHECK-DAG: !{i32 1, !"aaa", i32 0, i32 {{[0-9]+}}}
 // CHECK-DAG: !{i32 1, !"ccc", i32 0, i32 {{[0-9]+}}}


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


[PATCH] D51650: Implement target_clones multiversioning

2018-09-06 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: rsmith.
aaron.ballman added a comment.

Thank you for this! I have some cursory review comments, and possibly more 
later.




Comment at: include/clang/Basic/AttrDocs.td:1600
+  let Content = [{
+Clang supports the GNU style ``__attribute__((target_clones("OPTIONS")))``
+attribute. This attribute may be attached to a function definition and causes

It supports the C++ style as well, so perhaps "Clang supports the 
``target_clones("OPTIONS")`` attribute." instead?



Comment at: include/clang/Basic/AttrDocs.td:1601
+Clang supports the GNU style ``__attribute__((target_clones("OPTIONS")))``
+attribute. This attribute may be attached to a function definition and causes
+function multiversioning, where multiple versions  of the function will be

It can be on a declaration too, can't it?



Comment at: include/clang/Basic/AttrDocs.td:1602
+attribute. This attribute may be attached to a function definition and causes
+function multiversioning, where multiple versions  of the function will be
+emitted with different code generation options.  Additionally, these versions

Extraneous space between "versions of"



Comment at: include/clang/Basic/AttrDocs.td:1607
+
+All multiversioned functions must contain a ``default`` (fallback)
+implementation, otherwise usages of the function are considered invalid.

You should probably explain the options a bit more thoroughly around here; 
nothing explains that the options are architectures, for instance.



Comment at: include/clang/Basic/AttrDocs.td:1612
+Note that unlike the ``target`` syntax, every option listed creates a new
+version, desregarding whether it is split on a comma inside or outside a 
string.
+The following will emit 4 versions of the function.

typo: disregarding



Comment at: lib/CodeGen/CodeGenModule.cpp:2394
   const auto *F = cast(GD.getDecl());
+
   if (CodeGenOpts.OptimizationLevel == 0 && !F->hasAttr())

Spurious newline?



Comment at: lib/CodeGen/CodeGenModule.cpp:2559
+  assert(FD && "Not a FunctionDecl?");
+  auto *ClonesAttr = FD->getAttr();
+  assert(ClonesAttr && "Not a target_clones Function?");

`const auto *`



Comment at: lib/Sema/SemaDecl.cpp:9428
 S.Diag(OldFD->getLocation(), diag::err_multiversion_no_other_attrs)
-<< IsCPUSpecificCPUDispatchMVType;
+<< (MVType - 1);
 S.Diag(NewFD->getLocation(), diag::note_multiversioning_caused_here);

Rather than repeat this expression in multiple places, I prefer a named local 
variable.



Comment at: lib/Sema/SemaDeclAttr.cpp:3014
+  while (Str.size() != 0) {
+// remove the comma we found last time through.
+if (Str[0] == ',')

remove -> Remove


https://reviews.llvm.org/D51650



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


[PATCH] D51697: [Sema] Clean up some __builtin_*_chk diagnostics

2018-09-06 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL341566: [Sema] Clean up some __builtin_*_chk diagnostics 
(authored by epilk, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D51697?vs=164087=164237#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D51697

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/test/Sema/builtin-object-size.c
  cfe/trunk/test/Sema/builtins.c

Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -238,7 +238,8 @@
 
 static void SemaBuiltinMemChkCall(Sema , FunctionDecl *FDecl,
   CallExpr *TheCall, unsigned SizeIdx,
-  unsigned DstSizeIdx) {
+  unsigned DstSizeIdx,
+  StringRef LikelyMacroName) {
   if (TheCall->getNumArgs() <= SizeIdx ||
   TheCall->getNumArgs() <= DstSizeIdx)
 return;
@@ -256,12 +257,21 @@
   if (Size.ule(DstSize))
 return;
 
-  // confirmed overflow so generate the diagnostic.
-  IdentifierInfo *FnName = FDecl->getIdentifier();
+  // Confirmed overflow, so generate the diagnostic.
+  StringRef FunctionName = FDecl->getName();
   SourceLocation SL = TheCall->getBeginLoc();
-  SourceRange SR = TheCall->getSourceRange();
+  SourceManager  = S.getSourceManager();
+  // If we're in an expansion of a macro whose name corresponds to this builtin,
+  // use the simple macro name and location.
+  if (SL.isMacroID() && Lexer::getImmediateMacroName(SL, SM, S.getLangOpts()) ==
+LikelyMacroName) {
+FunctionName = LikelyMacroName;
+SL = SM.getImmediateMacroCallerLoc(SL);
+  }
 
-  S.Diag(SL, diag::warn_memcpy_chk_overflow) << SR << FnName;
+  S.Diag(SL, diag::warn_memcpy_chk_overflow)
+  << FunctionName << DstSize.toString(/*Radix=*/10)
+  << Size.toString(/*Radix=*/10);
 }
 
 static bool SemaBuiltinCallWithStaticChain(Sema , CallExpr *BuiltinCall) {
@@ -1219,21 +1229,37 @@
   // check secure string manipulation functions where overflows
   // are detectable at compile time
   case Builtin::BI__builtin___memcpy_chk:
+SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "memcpy");
+break;
   case Builtin::BI__builtin___memmove_chk:
+SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "memmove");
+break;
   case Builtin::BI__builtin___memset_chk:
+SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "memset");
+break;
   case Builtin::BI__builtin___strlcat_chk:
+SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "strlcat");
+break;
   case Builtin::BI__builtin___strlcpy_chk:
+SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "strlcpy");
+break;
   case Builtin::BI__builtin___strncat_chk:
+SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "strncat");
+break;
   case Builtin::BI__builtin___strncpy_chk:
+SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "strncpy");
+break;
   case Builtin::BI__builtin___stpncpy_chk:
-SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3);
+SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "stpncpy");
 break;
   case Builtin::BI__builtin___memccpy_chk:
-SemaBuiltinMemChkCall(*this, FDecl, TheCall, 3, 4);
+SemaBuiltinMemChkCall(*this, FDecl, TheCall, 3, 4, "memccpy");
 break;
   case Builtin::BI__builtin___snprintf_chk:
+SemaBuiltinMemChkCall(*this, FDecl, TheCall, 1, 3, "snprintf");
+break;
   case Builtin::BI__builtin___vsnprintf_chk:
-SemaBuiltinMemChkCall(*this, FDecl, TheCall, 1, 3);
+SemaBuiltinMemChkCall(*this, FDecl, TheCall, 1, 3, "vsnprintf");
 break;
   case Builtin::BI__builtin_call_with_static_chain:
 if (SemaBuiltinCallWithStaticChain(*this, TheCall))
Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -694,7 +694,8 @@
   InGroup>;
 
 def warn_memcpy_chk_overflow : Warning<
-  "%0 will always overflow destination buffer">,
+  "'%0' will always overflow; destination buffer has size %1,"
+  " but size argument is %2">,
   InGroup>;
 
 /// main()
Index: cfe/trunk/test/Sema/builtins.c
===
--- cfe/trunk/test/Sema/builtins.c
+++ cfe/trunk/test/Sema/builtins.c
@@ -221,30 +221,30 @@
 // expected-note {{change size argument to be the size of the destination}}
 __builtin___strlcpy_chk(buf, b, sizeof(b), __builtin_object_size(buf, 0)); // expected-warning {{size argument in '__builtin___strlcpy_chk' call appears to be size of the source; expected the size of the 

r341566 - [Sema] Clean up some __builtin_*_chk diagnostics

2018-09-06 Thread Erik Pilkington via cfe-commits
Author: epilk
Date: Thu Sep  6 10:19:33 2018
New Revision: 341566

URL: http://llvm.org/viewvc/llvm-project?rev=341566=rev
Log:
[Sema] Clean up some __builtin_*_chk diagnostics

Namely, print the likely macro name when it's used, and include the actual
computed sizes in the diagnostic message, which are sometimes not obvious.

rdar://43909200

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/builtin-object-size.c
cfe/trunk/test/Sema/builtins.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=341566=341565=341566=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Sep  6 10:19:33 
2018
@@ -694,7 +694,8 @@ def warn_assume_side_effects : Warning<
   InGroup>;
 
 def warn_memcpy_chk_overflow : Warning<
-  "%0 will always overflow destination buffer">,
+  "'%0' will always overflow; destination buffer has size %1,"
+  " but size argument is %2">,
   InGroup>;
 
 /// main()

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=341566=341565=341566=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Sep  6 10:19:33 2018
@@ -238,7 +238,8 @@ static bool SemaBuiltinOverflow(Sema ,
 
 static void SemaBuiltinMemChkCall(Sema , FunctionDecl *FDecl,
   CallExpr *TheCall, unsigned SizeIdx,
-  unsigned DstSizeIdx) {
+  unsigned DstSizeIdx,
+  StringRef LikelyMacroName) {
   if (TheCall->getNumArgs() <= SizeIdx ||
   TheCall->getNumArgs() <= DstSizeIdx)
 return;
@@ -256,12 +257,21 @@ static void SemaBuiltinMemChkCall(Sema &
   if (Size.ule(DstSize))
 return;
 
-  // confirmed overflow so generate the diagnostic.
-  IdentifierInfo *FnName = FDecl->getIdentifier();
+  // Confirmed overflow, so generate the diagnostic.
+  StringRef FunctionName = FDecl->getName();
   SourceLocation SL = TheCall->getBeginLoc();
-  SourceRange SR = TheCall->getSourceRange();
+  SourceManager  = S.getSourceManager();
+  // If we're in an expansion of a macro whose name corresponds to this 
builtin,
+  // use the simple macro name and location.
+  if (SL.isMacroID() && Lexer::getImmediateMacroName(SL, SM, S.getLangOpts()) 
==
+LikelyMacroName) {
+FunctionName = LikelyMacroName;
+SL = SM.getImmediateMacroCallerLoc(SL);
+  }
 
-  S.Diag(SL, diag::warn_memcpy_chk_overflow) << SR << FnName;
+  S.Diag(SL, diag::warn_memcpy_chk_overflow)
+  << FunctionName << DstSize.toString(/*Radix=*/10)
+  << Size.toString(/*Radix=*/10);
 }
 
 static bool SemaBuiltinCallWithStaticChain(Sema , CallExpr *BuiltinCall) {
@@ -1219,21 +1229,37 @@ Sema::CheckBuiltinFunctionCall(FunctionD
   // check secure string manipulation functions where overflows
   // are detectable at compile time
   case Builtin::BI__builtin___memcpy_chk:
+SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "memcpy");
+break;
   case Builtin::BI__builtin___memmove_chk:
+SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "memmove");
+break;
   case Builtin::BI__builtin___memset_chk:
+SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "memset");
+break;
   case Builtin::BI__builtin___strlcat_chk:
+SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "strlcat");
+break;
   case Builtin::BI__builtin___strlcpy_chk:
+SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "strlcpy");
+break;
   case Builtin::BI__builtin___strncat_chk:
+SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "strncat");
+break;
   case Builtin::BI__builtin___strncpy_chk:
+SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "strncpy");
+break;
   case Builtin::BI__builtin___stpncpy_chk:
-SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3);
+SemaBuiltinMemChkCall(*this, FDecl, TheCall, 2, 3, "stpncpy");
 break;
   case Builtin::BI__builtin___memccpy_chk:
-SemaBuiltinMemChkCall(*this, FDecl, TheCall, 3, 4);
+SemaBuiltinMemChkCall(*this, FDecl, TheCall, 3, 4, "memccpy");
 break;
   case Builtin::BI__builtin___snprintf_chk:
+SemaBuiltinMemChkCall(*this, FDecl, TheCall, 1, 3, "snprintf");
+break;
   case Builtin::BI__builtin___vsnprintf_chk:
-SemaBuiltinMemChkCall(*this, FDecl, TheCall, 1, 3);
+SemaBuiltinMemChkCall(*this, FDecl, TheCall, 1, 3, "vsnprintf");
 break;
   case Builtin::BI__builtin_call_with_static_chain:
 if 

[PATCH] D51084: Implement -Watomic-implicit-seq-cst

2018-09-06 Thread JF Bastien via Phabricator via cfe-commits
jfb updated this revision to Diff 164235.
jfb marked 4 inline comments as done.
jfb added a comment.

- Address comments.


Repository:
  rC Clang

https://reviews.llvm.org/D51084

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp
  test/Sema/atomic-implicit-seq_cst.c
  test/Sema/sync-implicit-seq_cst.c

Index: test/Sema/sync-implicit-seq_cst.c
===
--- /dev/null
+++ test/Sema/sync-implicit-seq_cst.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 %s -verify -ffreestanding -fsyntax-only -triple=i686-linux-gnu -std=c11 -Watomic-implicit-seq-cst -Wno-sync-fetch-and-nand-semantics-changed
+
+// __sync_* operations are implicitly sequentially-consistent. Some codebases
+// want to force explicit usage of memory order instead.
+
+void fetch_and_add(int *ptr, int val) { __sync_fetch_and_add(ptr, val); }   // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void fetch_and_sub(int *ptr, int val) { __sync_fetch_and_sub(ptr, val); }   // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void fetch_and_or(int *ptr, int val) { __sync_fetch_and_or(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void fetch_and_and(int *ptr, int val) { __sync_fetch_and_and(ptr, val); }   // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void fetch_and_xor(int *ptr, int val) { __sync_fetch_and_xor(ptr, val); }   // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void fetch_and_nand(int *ptr, int val) { __sync_fetch_and_nand(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+
+void add_and_fetch(int *ptr, int val) { __sync_add_and_fetch(ptr, val); }   // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void sub_and_fetch(int *ptr, int val) { __sync_sub_and_fetch(ptr, val); }   // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void or_and_fetch(int *ptr, int val) { __sync_or_and_fetch(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void and_and_fetch(int *ptr, int val) { __sync_and_and_fetch(ptr, val); }   // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void xor_and_fetch(int *ptr, int val) { __sync_xor_and_fetch(ptr, val); }   // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void nand_and_fetch(int *ptr, int val) { __sync_nand_and_fetch(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+
+void bool_compare_and_swap(int *ptr, int oldval, int newval) { __sync_bool_compare_and_swap(ptr, oldval, newval); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void val_compare_and_swap(int *ptr, int oldval, int newval) { __sync_val_compare_and_swap(ptr, oldval, newval); }   // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+
+void synchronize(void) { __sync_synchronize(); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+
+void lock_test_and_set(int *ptr, int val) { __sync_lock_test_and_set(ptr, val); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+void lock_release(int *ptr) { __sync_lock_release(ptr); } // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
Index: test/Sema/atomic-implicit-seq_cst.c
===
--- /dev/null
+++ test/Sema/atomic-implicit-seq_cst.c
@@ -0,0 +1,325 @@
+// RUN: %clang_cc1 %s -verify -ffreestanding -fsyntax-only -triple=i686-linux-gnu -std=c11 -Watomic-implicit-seq-cst
+
+// _Atomic operations are implicitly sequentially-consistent. Some codebases
+// want to force explicit usage of memory order instead.
+
+_Atomic(int) atom;
+void gimme_int(int);
+
+void bad_pre_inc(void) {
+  ++atom; // expected-warning {{implicit use of sequentially-consistent atomic may incur stronger memory barriers than necessary}}
+}
+
+void bad_pre_dec(void) {
+  --atom; // expected-warning {{implicit use of 

[PATCH] D51084: Implement -Watomic-implicit-seq-cst

2018-09-06 Thread JF Bastien via Phabricator via cfe-commits
jfb added inline comments.



Comment at: lib/Sema/SemaChecking.cpp:10974
+  if (E->IgnoreParenImpCasts()->getType()->isAtomicType())
+return;
   CheckImplicitConversion(S, E->IgnoreParenImpCasts(), S.Context.BoolTy, CC);

rjmccall wrote:
> Can you explain this one?
It would produce duplicate warnings of `!`, `&&`, `||`, and condition for `? 
:`. Bool-like conversion is a special case of implicit conversion, which we 
already check elsewhere.


Repository:
  rC Clang

https://reviews.llvm.org/D51084



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


r341564 - Re-commit "Enable DWARF accelerator tables by default when tuning for lldb (-glldb => -gpubnames)""

2018-09-06 Thread Pavel Labath via cfe-commits
Author: labath
Date: Thu Sep  6 10:01:45 2018
New Revision: 341564

URL: http://llvm.org/viewvc/llvm-project?rev=341564=rev
Log:
Re-commit "Enable DWARF accelerator tables by default when tuning for lldb 
(-glldb => -gpubnames)""

This recommits r341472, which was reverted due to test failures on macos bots.

The issue was that a macos target implies -glldb which, together with
this patch added a -gpubnames switch where there previously wasn't one.
The intentions of those checks was to check that -gpubnames is not
emitted by default so I add an explicit -ggdb arg to those command lines
to get same behavior on all platforms (the fact that -glldb *does* set
-gpubnames is tested by a separate test).

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

Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Driver/debug-options.c

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=341564=341563=341564=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Thu Sep  6 10:01:45 2018
@@ -3072,7 +3072,7 @@ static void RenderDebugOptions(const Too
   const auto *PubnamesArg =
   Args.getLastArg(options::OPT_ggnu_pubnames, 
options::OPT_gno_gnu_pubnames,
   options::OPT_gpubnames, options::OPT_gno_pubnames);
-  if (SplitDWARFArg ||
+  if (SplitDWARFArg || DebuggerTuning == llvm::DebuggerKind::LLDB ||
   (PubnamesArg && checkDebugInfoOption(PubnamesArg, Args, D, TC)))
 if (!PubnamesArg ||
 (!PubnamesArg->getOption().matches(options::OPT_gno_gnu_pubnames) &&

Modified: cfe/trunk/test/Driver/debug-options.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/debug-options.c?rev=341564=341563=341564=diff
==
--- cfe/trunk/test/Driver/debug-options.c (original)
+++ cfe/trunk/test/Driver/debug-options.c Thu Sep  6 10:01:45 2018
@@ -153,18 +153,21 @@
 // RUN:| FileCheck -check-prefix=GIGNORE %s
 //
 // RUN: %clang -### -c -ggnu-pubnames %s 2>&1 | FileCheck -check-prefix=GPUB %s
-// RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=NOPUB %s
+// RUN: %clang -### -c -ggdb %s 2>&1 | FileCheck -check-prefix=NOPUB %s
 // RUN: %clang -### -c -ggnu-pubnames -gno-gnu-pubnames %s 2>&1 | FileCheck 
-check-prefix=NOPUB %s
 // RUN: %clang -### -c -ggnu-pubnames -gno-pubnames %s 2>&1 | FileCheck 
-check-prefix=NOPUB %s
 //
 // RUN: %clang -### -c -gpubnames %s 2>&1 | FileCheck -check-prefix=PUB %s
-// RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=NOPUB %s
+// RUN: %clang -### -c -ggdb %s 2>&1 | FileCheck -check-prefix=NOPUB %s
 // RUN: %clang -### -c -gpubnames -gno-gnu-pubnames %s 2>&1 | FileCheck 
-check-prefix=NOPUB %s
 // RUN: %clang -### -c -gpubnames -gno-pubnames %s 2>&1 | FileCheck 
-check-prefix=NOPUB %s
 //
 // RUN: %clang -### -c -gsplit-dwarf %s 2>&1 | FileCheck -check-prefix=GPUB %s
 // RUN: %clang -### -c -gsplit-dwarf -gno-pubnames %s 2>&1 | FileCheck 
-check-prefix=NOPUB %s
 //
+// RUN: %clang -### -c -glldb %s 2>&1 | FileCheck -check-prefix=GPUB %s
+// RUN: %clang -### -c -glldb -gno-pubnames %s 2>&1 | FileCheck 
-check-prefix=NOPUB %s
+//
 // RUN: %clang -### -c -gdwarf-aranges %s 2>&1 | FileCheck 
-check-prefix=GARANGE %s
 //
 // RUN: %clang -### -fdebug-types-section -target x86_64-unknown-linux %s 2>&1 
\


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


[PATCH] D51714: CMake: Deprecate using llvm-config to detect llvm installation

2018-09-06 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

I don't have a strong opinion here.


Repository:
  rC Clang

https://reviews.llvm.org/D51714



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


[PATCH] D51510: Move AESNI generation to Skylake and Goldmont

2018-09-06 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Do you have commit access, or do you need someone to commit this for you?


Repository:
  rC Clang

https://reviews.llvm.org/D51510



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


[PATCH] D51724: [clangd] Add "Deprecated" field to Symbol and CodeCompletion.

2018-09-06 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Agree with Kadir's comments.
I'd just suggest reducing boilerplate a bit by taking some shortcuts.




Comment at: clangd/index/Index.h:167
 
+enum class SymbolFlag : uint8_t {
+  None = 0,

enum class is a pain for bitfields.
I'd just make this a plain enum nested inside symbol, then you don't need to 
define the operators and don't need to cast as often.



Comment at: clangd/index/Index.h:268
+  /// FIXME: also add deprecation message and fixit?
+  bool Deprecated() const {
+return static_cast(Flags & SymbolFlag::Deprecated);

kadircet wrote:
> nit: rename to isDeprecated ?
FWIW I don't think these accessors pull their weight: in calller code `if 
(Sym.Flags & Symbol::IsDeprecated)` is clear enough



Comment at: clangd/index/Serialization.cpp:309
 // data. Later we may want to support some backward compatibility.
 constexpr static uint32_t Version = 2;
 

3


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51724



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


[PATCH] D51697: [Sema] Clean up some __builtin_*_chk diagnostics

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

LGTM


Repository:
  rC Clang

https://reviews.llvm.org/D51697



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


[PATCH] D51724: [clangd] Add "Deprecated" field to Symbol and CodeCompletion.

2018-09-06 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clangd/index/Index.h:171
+  /// See also isIndexedForCodeCompletion().
+  IsIndexedForCodeCompletion = 1 << 0,
+  /// Indicates if the symbol is deprecated.

nit: rename to IndexedForCodeCompletion, since it is more of an attribute 
having is in the name doesn't seem so cool. Instead of the attributes 
themselves maybe the checkers below should have "is" prefix.



Comment at: clangd/index/Index.h:172
+  IsIndexedForCodeCompletion = 1 << 0,
+  /// Indicates if the symbol is deprecated.
+  Deprecated = 1 << 1,

nit: Add a comment similar to above one leading to Deprecated()?



Comment at: clangd/index/Index.h:268
+  /// FIXME: also add deprecation message and fixit?
+  bool Deprecated() const {
+return static_cast(Flags & SymbolFlag::Deprecated);

nit: rename to isDeprecated ?



Comment at: unittests/clangd/CodeCompleteTests.cpp:1359
   C.Origin = SymbolOrigin::AST | SymbolOrigin::Static;
+  C.Deprecated = true;
 

Maybe do this on its own render so that we can have both code paths covered. 
Just before rendering with `Opts.EnableSnippets = true` below. We can simply 
set this one render again and check deprecated is set to true.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51724



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


r341560 - Reverting r 341390 because it is causing test failures on GreenDragon.

2018-09-06 Thread A Bergen via cfe-commits
Author: sudofortune
Date: Thu Sep  6 09:29:40 2018
New Revision: 341560

URL: http://llvm.org/viewvc/llvm-project?rev=341560=rev
Log:
Reverting r 341390 because it is causing test failures on GreenDragon.

http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-incremental/52810/


Modified:
cfe/trunk/lib/Driver/ToolChains/MSVC.cpp
cfe/trunk/test/Driver/msvc-link.c

Modified: cfe/trunk/lib/Driver/ToolChains/MSVC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/MSVC.cpp?rev=341560=341559=341560=diff
==
--- cfe/trunk/lib/Driver/ToolChains/MSVC.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/MSVC.cpp Thu Sep  6 09:29:40 2018
@@ -355,15 +355,6 @@ void visualstudio::Linker::ConstructJob(
   options::OPT__SLASH_Zd))
 CmdArgs.push_back("-debug");
 
-  // Pass on /Brepro if it was passed to the compiler.
-  // Note that /Brepro maps to -mno-incremental-linker-compatible.
-  bool DefaultIncrementalLinkerCompatible =
-  C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment();
-  if (!Args.hasFlag(options::OPT_mincremental_linker_compatible,
-options::OPT_mno_incremental_linker_compatible,
-DefaultIncrementalLinkerCompatible))
-CmdArgs.push_back("-Brepro");
-
   bool DLL = Args.hasArg(options::OPT__SLASH_LD, options::OPT__SLASH_LDd,
  options::OPT_shared);
   if (DLL) {

Modified: cfe/trunk/test/Driver/msvc-link.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/msvc-link.c?rev=341560=341559=341560=diff
==
--- cfe/trunk/test/Driver/msvc-link.c (original)
+++ cfe/trunk/test/Driver/msvc-link.c Thu Sep  6 09:29:40 2018
@@ -3,7 +3,6 @@
 // BASIC: "-out:a.exe"
 // BASIC: "-defaultlib:libcmt"
 // BASIC: "-nologo"
-// BASIC-NOT: "-Brepro"
 
 // RUN: %clang -target i686-pc-windows-msvc -shared -o a.dll -### %s 2>&1 | 
FileCheck --check-prefix=DLL %s
 // DLL: link.exe"
@@ -17,14 +16,3 @@
 // LIBPATH: "-libpath:/usr/lib"
 // LIBPATH: "-nologo"
 
-// RUN: %clang_cl /Brepro -### %s 2>&1 | FileCheck --check-prefix=REPRO %s
-// REPRO: link.exe"
-// REPRO: "-out:msvc-link.exe"
-// REPRO: "-nologo"
-// REPRO: "-Brepro"
-
-// RUN: %clang_cl /Brepro- -### %s 2>&1 | FileCheck --check-prefix=NOREPRO %s
-// NOREPRO: link.exe"
-// NOREPRO: "-out:msvc-link.exe"
-// NOREPRO: "-nologo"
-// NOREPRO-NOT: "-Brepro"


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


[PATCH] D51714: CMake: Deprecate using llvm-config to detect llvm installation

2018-09-06 Thread Tom Stellard via Phabricator via cfe-commits
tstellar added a comment.

In https://reviews.llvm.org/D51714#1225545, @mgorny wrote:

> Is LLVM_CONFIG dropped from cache here? I suspect the warning might fire for 
> everyone who has LLVM configured.


Yes, it is dropped from the cache, is it a problem to having the warning fire 
for people who have already configured LLVM?


Repository:
  rC Clang

https://reviews.llvm.org/D51714



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


r341556 - Remove unnecessary semicolon to silence -Wpedantic warning. NFCI.

2018-09-06 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Thu Sep  6 08:16:17 2018
New Revision: 341556

URL: http://llvm.org/viewvc/llvm-project?rev=341556=rev
Log:
Remove unnecessary semicolon to silence -Wpedantic warning. NFCI.

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

Modified: cfe/trunk/lib/Sema/SemaExceptionSpec.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExceptionSpec.cpp?rev=341556=341555=341556=diff
==
--- cfe/trunk/lib/Sema/SemaExceptionSpec.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExceptionSpec.cpp Thu Sep  6 08:16:17 2018
@@ -238,7 +238,7 @@ static bool exceptionSpecNotKnownYet(con
   auto EST = 
MD->getType()->castAs()->getExceptionSpecType();
   return EST == EST_Unparsed ||
  (EST == EST_Unevaluated && MD->getParent()->isBeingDefined());
-};
+}
 
 static bool CheckEquivalentExceptionSpecImpl(
 Sema , const PartialDiagnostic , const PartialDiagnostic ,


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


[PATCH] D51302: [OpenCL] Relax diagnostics on OpenCL access qualifiers

2018-09-06 Thread Andrew Savonichev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL341553: [OpenCL] Relax diagnostics on OpenCL access 
qualifiers (authored by asavonic, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D51302?vs=163086=164222#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D51302

Files:
  cfe/trunk/lib/Sema/SemaDeclAttr.cpp
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/test/SemaOpenCL/access-qualifier.cl

Index: cfe/trunk/test/SemaOpenCL/access-qualifier.cl
===
--- cfe/trunk/test/SemaOpenCL/access-qualifier.cl
+++ cfe/trunk/test/SemaOpenCL/access-qualifier.cl
@@ -60,7 +60,7 @@
 
 kernel void k11(read_only write_only image1d_t i){} // expected-error{{multiple access qualifiers}}
 
-kernel void k12(read_only read_only image1d_t i){} // expected-error{{multiple access qualifiers}}
+kernel void k12(read_only read_only image1d_t i){} // expected-warning {{duplicate 'read_only' declaration specifier}}
 
 #if __OPENCL_C_VERSION__ >= 200
 kernel void k13(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'read_only pipe int'}}
@@ -78,3 +78,33 @@
 #if __OPENCL_C_VERSION__ < 200
 kernel void test_image3d_wo(write_only image3d_t img) {} // expected-error {{use of type '__write_only image3d_t' requires cl_khr_3d_image_writes extension to be enabled}}
 #endif
+
+#if __OPENCL_C_VERSION__ >= 200
+kernel void read_write_twice_typedef(read_write img1d_rw i){} // expected-warning {{duplicate 'read_write' declaration specifier}}
+// expected-note@-74 {{previously declared 'read_write' here}}
+
+kernel void pipe_ro_twice(read_only read_only pipe int i){} // expected-warning{{duplicate 'read_only' declaration specifier}}
+// Conflicting access qualifiers
+kernel void pipe_ro_twice_tw(read_write read_only read_only pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'read_only pipe int'}}
+kernel void pipe_ro_wo(read_only write_only pipe int i){} // expected-error{{multiple access qualifiers}}
+
+typedef read_only pipe int ROPipeInt;
+kernel void pipe_ro_twice_typedef(read_only ROPipeInt i){} // expected-warning{{duplicate 'read_only' declaration specifier}}
+// expected-note@-2 {{previously declared 'read_only' here}}
+
+kernel void pass_ro_typedef_to_wo(ROPipeInt p) {
+  myPipeWrite(p); // expected-error {{passing 'ROPipeInt' (aka 'read_only pipe int') to parameter of incompatible type 'write_only pipe int'}}
+  // expected-note@-25 {{passing argument to parameter here}}
+}
+#endif
+
+kernel void read_only_twice_typedef(__read_only img1d_ro i){} // expected-warning {{duplicate '__read_only' declaration specifier}}
+// expected-note@-95 {{previously declared 'read_only' here}}
+
+kernel void read_only_twice_default(read_only img1d_ro_default img){} // expected-warning {{duplicate 'read_only' declaration specifier}}
+// expected-note@-101 {{previously declared 'read_only' here}}
+
+kernel void image_wo_twice(write_only __write_only image1d_t i){} // expected-warning {{duplicate '__write_only' declaration specifier}}
+kernel void image_wo_twice_typedef(write_only img1d_wo i){} // expected-warning {{duplicate 'write_only' declaration specifier}}
+// expected-note@-103 {{previously declared 'write_only' here}}
+
Index: cfe/trunk/lib/Sema/SemaType.cpp
===
--- cfe/trunk/lib/Sema/SemaType.cpp
+++ cfe/trunk/lib/Sema/SemaType.cpp
@@ -7105,23 +7105,43 @@
   }
 
   if (const TypedefType* TypedefTy = CurType->getAs()) {
-QualType PointeeTy = TypedefTy->desugar();
-S.Diag(Attr.getLoc(), diag::err_opencl_multiple_access_qualifiers);
+QualType BaseTy = TypedefTy->desugar();
 
 std::string PrevAccessQual;
-switch (cast(PointeeTy.getTypePtr())->getKind()) {
-  #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
-case BuiltinType::Id:  \
-  PrevAccessQual = #Access;\
-  break;
-  #include "clang/Basic/OpenCLImageTypes.def"
-default:
-  assert(0 && "Unable to find corresponding image type.");
+if (BaseTy->isPipeType()) {
+  if (TypedefTy->getDecl()->hasAttr()) {
+OpenCLAccessAttr *Attr =
+TypedefTy->getDecl()->getAttr();
+PrevAccessQual = Attr->getSpelling();
+  } else {
+PrevAccessQual = "read_only";
+  }
+} else if (const BuiltinType* ImgType = BaseTy->getAs()) {
+
+  switch (ImgType->getKind()) {
+#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
+  case BuiltinType::Id:  \
+PrevAccessQual = #Access;\
+break;
+#include "clang/Basic/OpenCLImageTypes.def"
+  default:
+llvm_unreachable("Unable to find corresponding image 

[PATCH] D51302: [OpenCL] Relax diagnostics on OpenCL access qualifiers

2018-09-06 Thread Andrew Savonichev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC341553: [OpenCL] Relax diagnostics on OpenCL access 
qualifiers (authored by asavonic, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D51302

Files:
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  test/SemaOpenCL/access-qualifier.cl

Index: test/SemaOpenCL/access-qualifier.cl
===
--- test/SemaOpenCL/access-qualifier.cl
+++ test/SemaOpenCL/access-qualifier.cl
@@ -60,7 +60,7 @@
 
 kernel void k11(read_only write_only image1d_t i){} // expected-error{{multiple access qualifiers}}
 
-kernel void k12(read_only read_only image1d_t i){} // expected-error{{multiple access qualifiers}}
+kernel void k12(read_only read_only image1d_t i){} // expected-warning {{duplicate 'read_only' declaration specifier}}
 
 #if __OPENCL_C_VERSION__ >= 200
 kernel void k13(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'read_only pipe int'}}
@@ -78,3 +78,33 @@
 #if __OPENCL_C_VERSION__ < 200
 kernel void test_image3d_wo(write_only image3d_t img) {} // expected-error {{use of type '__write_only image3d_t' requires cl_khr_3d_image_writes extension to be enabled}}
 #endif
+
+#if __OPENCL_C_VERSION__ >= 200
+kernel void read_write_twice_typedef(read_write img1d_rw i){} // expected-warning {{duplicate 'read_write' declaration specifier}}
+// expected-note@-74 {{previously declared 'read_write' here}}
+
+kernel void pipe_ro_twice(read_only read_only pipe int i){} // expected-warning{{duplicate 'read_only' declaration specifier}}
+// Conflicting access qualifiers
+kernel void pipe_ro_twice_tw(read_write read_only read_only pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'read_only pipe int'}}
+kernel void pipe_ro_wo(read_only write_only pipe int i){} // expected-error{{multiple access qualifiers}}
+
+typedef read_only pipe int ROPipeInt;
+kernel void pipe_ro_twice_typedef(read_only ROPipeInt i){} // expected-warning{{duplicate 'read_only' declaration specifier}}
+// expected-note@-2 {{previously declared 'read_only' here}}
+
+kernel void pass_ro_typedef_to_wo(ROPipeInt p) {
+  myPipeWrite(p); // expected-error {{passing 'ROPipeInt' (aka 'read_only pipe int') to parameter of incompatible type 'write_only pipe int'}}
+  // expected-note@-25 {{passing argument to parameter here}}
+}
+#endif
+
+kernel void read_only_twice_typedef(__read_only img1d_ro i){} // expected-warning {{duplicate '__read_only' declaration specifier}}
+// expected-note@-95 {{previously declared 'read_only' here}}
+
+kernel void read_only_twice_default(read_only img1d_ro_default img){} // expected-warning {{duplicate 'read_only' declaration specifier}}
+// expected-note@-101 {{previously declared 'read_only' here}}
+
+kernel void image_wo_twice(write_only __write_only image1d_t i){} // expected-warning {{duplicate '__write_only' declaration specifier}}
+kernel void image_wo_twice_typedef(write_only img1d_wo i){} // expected-warning {{duplicate 'write_only' declaration specifier}}
+// expected-note@-103 {{previously declared 'write_only' here}}
+
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -7105,23 +7105,43 @@
   }
 
   if (const TypedefType* TypedefTy = CurType->getAs()) {
-QualType PointeeTy = TypedefTy->desugar();
-S.Diag(Attr.getLoc(), diag::err_opencl_multiple_access_qualifiers);
+QualType BaseTy = TypedefTy->desugar();
 
 std::string PrevAccessQual;
-switch (cast(PointeeTy.getTypePtr())->getKind()) {
-  #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
-case BuiltinType::Id:  \
-  PrevAccessQual = #Access;\
-  break;
-  #include "clang/Basic/OpenCLImageTypes.def"
-default:
-  assert(0 && "Unable to find corresponding image type.");
+if (BaseTy->isPipeType()) {
+  if (TypedefTy->getDecl()->hasAttr()) {
+OpenCLAccessAttr *Attr =
+TypedefTy->getDecl()->getAttr();
+PrevAccessQual = Attr->getSpelling();
+  } else {
+PrevAccessQual = "read_only";
+  }
+} else if (const BuiltinType* ImgType = BaseTy->getAs()) {
+
+  switch (ImgType->getKind()) {
+#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
+  case BuiltinType::Id:  \
+PrevAccessQual = #Access;\
+break;
+#include "clang/Basic/OpenCLImageTypes.def"
+  default:
+llvm_unreachable("Unable to find corresponding image type.");
+  }
+} else {
+  llvm_unreachable("unexpected type");
+}
+StringRef AttrName = Attr.getName()->getName();
+if (PrevAccessQual == AttrName.ltrim("_")) {
+  // Duplicated qualifiers

r341553 - [OpenCL] Relax diagnostics on OpenCL access qualifiers

2018-09-06 Thread Andrew Savonichev via cfe-commits
Author: asavonic
Date: Thu Sep  6 08:10:26 2018
New Revision: 341553

URL: http://llvm.org/viewvc/llvm-project?rev=341553=rev
Log:
[OpenCL] Relax diagnostics on OpenCL access qualifiers

Summary:
Emit warning for multiple access qualifiers if they do not conflict.

Patch by Alexey Bader

Reviewers: Anastasia, yaxunl

Reviewed By: Anastasia

Subscribers: asavonic, bader, cfe-commits

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

Modified:
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaOpenCL/access-qualifier.cl

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=341553=341552=341553=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Sep  6 08:10:26 2018
@@ -5900,10 +5900,16 @@ static void handleOpenCLAccessAttr(Sema
 
   // Check if there is only one access qualifier.
   if (D->hasAttr()) {
-S.Diag(AL.getLoc(), diag::err_opencl_multiple_access_qualifiers)
-<< D->getSourceRange();
-D->setInvalidDecl(true);
-return;
+if (D->getAttr()->getSemanticSpelling() ==
+AL.getSemanticSpelling()) {
+  S.Diag(AL.getLoc(), diag::warn_duplicate_declspec)
+  << AL.getName()->getName() << AL.getRange();
+} else {
+  S.Diag(AL.getLoc(), diag::err_opencl_multiple_access_qualifiers)
+  << D->getSourceRange();
+  D->setInvalidDecl(true);
+  return;
+}
   }
 
   // OpenCL v2.0 s6.6 - read_write can be used for image types to specify that 
an

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=341553=341552=341553=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Sep  6 08:10:26 2018
@@ -7105,23 +7105,43 @@ static void HandleOpenCLAccessAttr(QualT
   }
 
   if (const TypedefType* TypedefTy = CurType->getAs()) {
-QualType PointeeTy = TypedefTy->desugar();
-S.Diag(Attr.getLoc(), diag::err_opencl_multiple_access_qualifiers);
+QualType BaseTy = TypedefTy->desugar();
 
 std::string PrevAccessQual;
-switch (cast(PointeeTy.getTypePtr())->getKind()) {
-  #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
-case BuiltinType::Id:  \
-  PrevAccessQual = #Access;\
-  break;
-  #include "clang/Basic/OpenCLImageTypes.def"
-default:
-  assert(0 && "Unable to find corresponding image type.");
+if (BaseTy->isPipeType()) {
+  if (TypedefTy->getDecl()->hasAttr()) {
+OpenCLAccessAttr *Attr =
+TypedefTy->getDecl()->getAttr();
+PrevAccessQual = Attr->getSpelling();
+  } else {
+PrevAccessQual = "read_only";
+  }
+} else if (const BuiltinType* ImgType = BaseTy->getAs()) {
+
+  switch (ImgType->getKind()) {
+#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
+  case BuiltinType::Id:  \
+PrevAccessQual = #Access;\
+break;
+#include "clang/Basic/OpenCLImageTypes.def"
+  default:
+llvm_unreachable("Unable to find corresponding image type.");
+  }
+} else {
+  llvm_unreachable("unexpected type");
+}
+StringRef AttrName = Attr.getName()->getName();
+if (PrevAccessQual == AttrName.ltrim("_")) {
+  // Duplicated qualifiers
+  S.Diag(Attr.getLoc(), diag::warn_duplicate_declspec)
+ << AttrName << Attr.getRange();
+} else {
+  // Contradicting qualifiers
+  S.Diag(Attr.getLoc(), diag::err_opencl_multiple_access_qualifiers);
 }
 
 S.Diag(TypedefTy->getDecl()->getBeginLoc(),
-   diag::note_opencl_typedef_access_qualifier)
-<< PrevAccessQual;
+   diag::note_opencl_typedef_access_qualifier) << PrevAccessQual;
   } else if (CurType->isPipeType()) {
 if (Attr.getSemanticSpelling() == OpenCLAccessAttr::Keyword_write_only) {
   QualType ElemType = CurType->getAs()->getElementType();

Modified: cfe/trunk/test/SemaOpenCL/access-qualifier.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/access-qualifier.cl?rev=341553=341552=341553=diff
==
--- cfe/trunk/test/SemaOpenCL/access-qualifier.cl (original)
+++ cfe/trunk/test/SemaOpenCL/access-qualifier.cl Thu Sep  6 08:10:26 2018
@@ -60,7 +60,7 @@ kernel void k10(read_only Int img){} //
 
 kernel void k11(read_only write_only image1d_t i){} // 
expected-error{{multiple access qualifiers}}
 
-kernel void k12(read_only read_only image1d_t i){} // expected-error{{multiple 
access qualifiers}}
+kernel void 

[clang-tools-extra] r341552 - [clangd] Fix Dex initialization

2018-09-06 Thread Kirill Bobyrev via cfe-commits
Author: omtcyfz
Date: Thu Sep  6 08:10:10 2018
New Revision: 341552

URL: http://llvm.org/viewvc/llvm-project?rev=341552=rev
Log:
[clangd] Fix Dex initialization

This patch sets URI schemes of Dex to SymbolCollector's default schemes
in case callers tried to pass empty list of schemes. This was the case
for initialization in Clangd main and was a reason of incorrect
behavior.

Also, it fixes a bug with missed `continue;` after spotting invalid URI
scheme conversion.

Modified:
clang-tools-extra/trunk/clangd/index/dex/DexIndex.cpp
clang-tools-extra/trunk/clangd/index/dex/DexIndex.h

Modified: clang-tools-extra/trunk/clangd/index/dex/DexIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/DexIndex.cpp?rev=341552=341551=341552=diff
==
--- clang-tools-extra/trunk/clangd/index/dex/DexIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/dex/DexIndex.cpp Thu Sep  6 08:10:10 
2018
@@ -59,6 +59,7 @@ std::vector> c
"scheme. fuzzyFind request will ignore it.",
Path);
   llvm::consumeError(PathURI.takeError());
+  continue;
 }
 const auto PathProximityURIs = generateProximityURIs(PathURI->toString());
 for (const auto  : PathProximityURIs)

Modified: clang-tools-extra/trunk/clangd/index/dex/DexIndex.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/DexIndex.h?rev=341552=341551=341552=diff
==
--- clang-tools-extra/trunk/clangd/index/dex/DexIndex.h (original)
+++ clang-tools-extra/trunk/clangd/index/dex/DexIndex.h Thu Sep  6 08:10:10 2018
@@ -22,6 +22,7 @@
 
 #include "../Index.h"
 #include "../MemIndex.h"
+#include "../SymbolCollector.h"
 #include "Iterator.h"
 #include "Token.h"
 #include "Trigram.h"
@@ -40,8 +41,14 @@ class DexIndex : public SymbolIndex {
 public:
   // All symbols must outlive this index.
   template 
-  DexIndex(Range &, llvm::ArrayRef URISchemes)
-  : URISchemes(URISchemes) {
+  DexIndex(Range &, llvm::ArrayRef Schemes)
+  : URISchemes(Schemes) {
+// If Schemes don't contain any items, fall back to SymbolCollector's
+// default URI schemes.
+if (URISchemes.empty()) {
+  SymbolCollector::Options Opts;
+  URISchemes = Opts.URISchemes;
+}
 for (auto & : Symbols)
   this->Symbols.push_back();
 buildIndex();
@@ -90,7 +97,7 @@ private:
   llvm::DenseMap InvertedIndex;
   std::shared_ptr KeepAlive; // poor man's move-only std::any
 
-  const std::vector URISchemes;
+  std::vector URISchemes;
 };
 
 /// Returns Search Token for a number of parent directories of given Path.


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


[PATCH] D50488: [Analyzer] Checker for non-determinism caused by sorting of pointer-like elements

2018-09-06 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

In https://reviews.llvm.org/D50488#1225064, @george.karpenkov wrote:

> Why explicitly skip C  projects? We would not be able to match `std::X` 
> functions anyway.


Why spend time constructing matchers and running on the AST when we are sure 
that generating any result is impossible? Skipping the entire useless traversal 
of the tree can end up saving precious execution time that should not be 
overlooked.


https://reviews.llvm.org/D50488



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


[libcxx] r341551 - [libc++] Add a link to the Release notes from the main libc++ documentation

2018-09-06 Thread Louis Dionne via cfe-commits
Author: ldionne
Date: Thu Sep  6 08:05:43 2018
New Revision: 341551

URL: http://llvm.org/viewvc/llvm-project?rev=341551=rev
Log:
[libc++] Add a link to the Release notes from the main libc++ documentation

Modified:
libcxx/trunk/docs/index.rst

Modified: libcxx/trunk/docs/index.rst
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/docs/index.rst?rev=341551=341550=341551=diff
==
--- libcxx/trunk/docs/index.rst (original)
+++ libcxx/trunk/docs/index.rst Thu Sep  6 08:05:43 2018
@@ -34,6 +34,7 @@ Getting Started with libc++
 .. toctree::
:maxdepth: 2
 
+   ReleaseNotes
UsingLibcxx
BuildingLibcxx
TestingLibcxx


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


[PATCH] D51683: Fix arm_neon.h and arm_fp16.h generation for compiling with std=c89

2018-09-06 Thread James Greenhalgh via Phabricator via cfe-commits
jgreenhalgh added inline comments.



Comment at: cfe/trunk/utils/TableGen/NeonEmitter.cpp:2412
 
-  OS << "#define __ai static inline __attribute__((__always_inline__, "
+  OS << "#define __ai static __inline __attribute__((__always_inline__, "
 "__nodebug__))\n\n";

dnsampaio wrote:
> joerg wrote:
> > If you want to change it, at least change it properly to use __inline__.
> Sorry, I don't get the suggestion. Do you mean test if it is C89 and use 
> __inline, else, use inline?
I think the suggestion was unintentionally rendered as an underline by phab; 
and was supposed to be 
```
__inline__
```


https://reviews.llvm.org/D51683



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


[libcxx] r341550 - [libcxx] Add ReleaseNotes.rst file for release notes

2018-09-06 Thread Louis Dionne via cfe-commits
Author: ldionne
Date: Thu Sep  6 07:46:22 2018
New Revision: 341550

URL: http://llvm.org/viewvc/llvm-project?rev=341550=rev
Log:
[libcxx] Add ReleaseNotes.rst file for release notes

Added:
libcxx/trunk/docs/ReleaseNotes.rst

Added: libcxx/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/docs/ReleaseNotes.rst?rev=341550=auto
==
--- libcxx/trunk/docs/ReleaseNotes.rst (added)
+++ libcxx/trunk/docs/ReleaseNotes.rst Thu Sep  6 07:46:22 2018
@@ -0,0 +1,43 @@
+
+Libc++ 8.0.0 (In-Progress) Release Notes
+
+
+.. contents::
+   :local:
+   :depth: 2
+
+Written by the `Libc++ Team `_
+
+.. warning::
+
+   These are in-progress notes for the upcoming libc++ 8 release.
+   Release notes for previous releases can be found on
+   `the Download Page `_.
+
+Introduction
+
+
+This document contains the release notes for the libc++ C++ Standard Library,
+part of the LLVM Compiler Infrastructure, release 8.0.0. Here we describe the
+status of libc++ in some detail, including major improvements from the previous
+release and new feature work. For the general LLVM release notes, see `the LLVM
+documentation `_. All LLVM releases may
+be downloaded from the `LLVM releases web site `_.
+
+For more information about libc++, please see the `Libc++ Web Site
+`_ or the `LLVM Web Site `_.
+
+Note that if you are reading this file from a Subversion checkout or the
+main Libc++ web page, this document applies to the *next* release, not
+the current one. To see the release notes for a specific release, please
+see the `releases page `_.
+
+What's New in Libc++ 8.0.0?
+===
+
+New Features
+
+
+API Changes
+---
+


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


[PATCH] D42370: Issue local statics in correct DWARF lexical scope

2018-09-06 Thread Reid Kleckner via Phabricator via cfe-commits
rnk requested changes to this revision.
rnk added a comment.
This revision now requires changes to proceed.

Still needs a test.


https://reviews.llvm.org/D42370



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


[PATCH] D51722: [OpenCL] Allow blocks to capture arrays in OpenCL

2018-09-06 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd updated this revision to Diff 164214.
sidorovd added a comment.

Reference to the Spec was added


https://reviews.llvm.org/D51722

Files:
  lib/Sema/SemaExpr.cpp
  test/SemaOpenCL/block-array-capturing.cl


Index: test/SemaOpenCL/block-array-capturing.cl
===
--- /dev/null
+++ test/SemaOpenCL/block-array-capturing.cl
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple spir64-unkown-unkown -emit-llvm 
%s -o -| FileCheck %s
+// expected-no-diagnostics
+
+typedef int (^block_t)();
+
+int block_typedef_kernel(global int* res) {
+  // CHECK: %{{.*}} = alloca <{ i32, i32, [3 x i32] }>
+  int a[3] = {1, 2, 3};
+  // CHECK: call void @llvm.memcpy{{.*}}
+  block_t b = ^() { return a[0]; };
+  return b();
+}
+
+// CHECK: define {{.*}} @__block_typedef_kernel_block_invoke
+// CHECK: %{{.*}} = getelementptr inbounds [3 x i32], [3 x i32] addrspace(4)* 
%{{.*}}, i64 0, i64 0
+// CHECK-NOT: call void @llvm.memcpy{{.*}}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -14624,8 +14624,10 @@
   Expr *CopyExpr = nullptr;
   bool ByRef = false;
 
-  // Blocks are not allowed to capture arrays.
-  if (CaptureType->isArrayType()) {
+  // Blocks are not allowed to capture arrays, excepting OpenCL.
+  // OpenCL v2.0 s1.12.5 (revision 40): arrays are captured by reference
+  // (decayed to pointers).
+  if (!S.getLangOpts().OpenCL && CaptureType->isArrayType()) {
 if (BuildAndDiagnose) {
   S.Diag(Loc, diag::err_ref_array_type);
   S.Diag(Var->getLocation(), diag::note_previous_decl)


Index: test/SemaOpenCL/block-array-capturing.cl
===
--- /dev/null
+++ test/SemaOpenCL/block-array-capturing.cl
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple spir64-unkown-unkown -emit-llvm %s -o -| FileCheck %s
+// expected-no-diagnostics
+
+typedef int (^block_t)();
+
+int block_typedef_kernel(global int* res) {
+  // CHECK: %{{.*}} = alloca <{ i32, i32, [3 x i32] }>
+  int a[3] = {1, 2, 3};
+  // CHECK: call void @llvm.memcpy{{.*}}
+  block_t b = ^() { return a[0]; };
+  return b();
+}
+
+// CHECK: define {{.*}} @__block_typedef_kernel_block_invoke
+// CHECK: %{{.*}} = getelementptr inbounds [3 x i32], [3 x i32] addrspace(4)* %{{.*}}, i64 0, i64 0
+// CHECK-NOT: call void @llvm.memcpy{{.*}}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -14624,8 +14624,10 @@
   Expr *CopyExpr = nullptr;
   bool ByRef = false;
 
-  // Blocks are not allowed to capture arrays.
-  if (CaptureType->isArrayType()) {
+  // Blocks are not allowed to capture arrays, excepting OpenCL.
+  // OpenCL v2.0 s1.12.5 (revision 40): arrays are captured by reference
+  // (decayed to pointers).
+  if (!S.getLangOpts().OpenCL && CaptureType->isArrayType()) {
 if (BuildAndDiagnose) {
   S.Diag(Loc, diag::err_ref_array_type);
   S.Diag(Var->getLocation(), diag::note_previous_decl)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51484: [OpenCL] Add support of cl_intel_device_side_avc_motion_estimation extension

2018-09-06 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: include/clang/Basic/OpenCLExtensionTypes.def:27
+
+INTEL_SGAVC_TYPE(mce_payload_t, McePayload)
+INTEL_SGAVC_TYPE(ime_payload_t, ImePayload)

AlexeySachkov wrote:
> Anastasia wrote:
> > From the specification of this extension I can't quite see if these types 
> > have to be in Clang instead of the header. Can you please elaborate on any 
> > example where it wouldn't be possible for this type to be declared in the 
> > header using the technique explained in:
> > https://clang.llvm.org/docs/UsersManual.html#opencl-extensions 
> We cannot define these types in header because their layout is not defined in 
> specification, i.e. all of these types are opaque
This is not the reason to add functionality to Clang. You can easily sort such 
things with target specific headers or even general headers (see `ndrange_t` 
for example). Spec doesn't have to describe everything. The question is whether 
there is something about those types that can't be handled using standard 
include mechanisms. Usually it's prohibited behaviors that can't be represented 
with such mechanisms. Like if some operations have to be disallowed or allowed 
(since in OpenCL C you can't define user defined operators) with the types.

I think the trend is to avoid adding complexity into Clang, unless there is no 
other way to implement some feature correctly.


Repository:
  rC Clang

https://reviews.llvm.org/D51484



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


r341549 - Revert "[DebugInfo] Generate debug information for labels. (Fix PR37395)"

2018-09-06 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Thu Sep  6 07:27:40 2018
New Revision: 341549

URL: http://llvm.org/viewvc/llvm-project?rev=341549=rev
Log:
Revert "[DebugInfo] Generate debug information for labels. (Fix PR37395)"

This reverts commit r341519, which generates debug info that causes
backend crashes. (with -split-dwarf-file)

Details in https://reviews.llvm.org/D50495

Removed:
cfe/trunk/test/CodeGen/debug-label-inline.c
cfe/trunk/test/CodeGen/debug-label.c
Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h
cfe/trunk/lib/CodeGen/CGStmt.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=341549=341548=341549=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Sep  6 07:27:40 2018
@@ -3769,32 +3769,6 @@ CGDebugInfo::EmitDeclareOfAutoVariable(c
   return EmitDeclare(VD, Storage, llvm::None, Builder);
 }
 
-void CGDebugInfo::EmitLabel(const LabelDecl *D, CGBuilderTy ) {
-  assert(DebugKind >= codegenoptions::LimitedDebugInfo);
-  assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
-
-  if (D->hasAttr())
-return;
-
-  auto *Scope = cast(LexicalBlockStack.back());
-  llvm::DIFile *Unit = getOrCreateFile(D->getLocation());
-
-  // Get location information.
-  unsigned Line = getLineNumber(D->getLocation());
-  unsigned Column = getColumnNumber(D->getLocation());
-
-  StringRef Name = D->getName();
-
-  // Create the descriptor for the label.
-  auto *L =
-  DBuilder.createLabel(Scope, Name, Unit, Line, 
CGM.getLangOpts().Optimize);
-
-  // Insert an llvm.dbg.label into the current block.
-  DBuilder.insertLabel(L,
-   llvm::DebugLoc::get(Line, Column, Scope, CurInlinedAt),
-   Builder.GetInsertBlock());
-}
-
 llvm::DIType *CGDebugInfo::CreateSelfType(const QualType ,
   llvm::DIType *Ty) {
   llvm::DIType *CachedTy = getTypeOrNull(QualTy);

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=341549=341548=341549=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Thu Sep  6 07:27:40 2018
@@ -415,9 +415,6 @@ public:
llvm::Value *AI,
CGBuilderTy );
 
-  /// Emit call to \c llvm.dbg.label for an label.
-  void EmitLabel(const LabelDecl *D, CGBuilderTy );
-
   /// Emit call to \c llvm.dbg.declare for an imported variable
   /// declaration in a block.
   void EmitDeclareOfBlockDeclRefVariable(

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=341549=341548=341549=diff
==
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Thu Sep  6 07:27:40 2018
@@ -531,16 +531,6 @@ void CodeGenFunction::EmitLabel(const La
   }
 
   EmitBlock(Dest.getBlock());
-
-  // Emit debug info for labels.
-  if (CGDebugInfo *DI = getDebugInfo()) {
-if (CGM.getCodeGenOpts().getDebugInfo() >=
-codegenoptions::LimitedDebugInfo) {
-  DI->setLocation(D->getLocation());
-  DI->EmitLabel(D, Builder);
-}
-  }
-
   incrementProfileCounter(D->getStmt());
 }
 

Removed: cfe/trunk/test/CodeGen/debug-label-inline.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/debug-label-inline.c?rev=341548=auto
==
--- cfe/trunk/test/CodeGen/debug-label-inline.c (original)
+++ cfe/trunk/test/CodeGen/debug-label-inline.c (removed)
@@ -1,28 +0,0 @@
-// This test will test the correctness of generating DILabel and
-// llvm.dbg.label when the label is in inlined functions.
-//
-// RUN: %clang_cc1 -O2 %s -o - -emit-llvm -debug-info-kind=limited | FileCheck 
%s
-inline int f1(int a, int b) {
-  int sum;
-
-top:
-  sum = a + b;
-  return sum;
-}
-
-extern int ga, gb;
-
-int f2(void) {
-  int result;
-
-  result = f1(ga, gb);
-  // CHECK: call void @llvm.dbg.label(metadata [[LABEL_METADATA:!.*]]), !dbg 
[[LABEL_LOCATION:!.*]]
-
-  return result;
-}
-
-// CHECK: distinct !DISubprogram(name: "f1", {{.*}}, retainedNodes: 
[[ELEMENTS:!.*]])
-// CHECK: [[ELEMENTS]] = !{{{.*}}, [[LABEL_METADATA]]}
-// CHECK: [[LABEL_METADATA]] = !DILabel({{.*}}, name: "top", {{.*}}, line: 8)
-// CHECK: [[INLINEDAT:!.*]] = distinct !DILocation(line: 18,
-// CHECK: [[LABEL_LOCATION]] = !DILocation(line: 8, {{.*}}, inlinedAt: 
[[INLINEDAT]])

Removed: cfe/trunk/test/CodeGen/debug-label.c
URL: 

[PATCH] D51402: [OpenCL] Adding cl_intel_planar_yuv extension

2018-09-06 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: lib/Headers/opencl-c.h:26
+#if __OPENCL_C_VERSION__ >= CL_VERSION_1_2
+#ifndef cl_intel_planar_yuv
+#define cl_intel_planar_yuv

@yaxunl, do you think we need to add some kind of architecture guard for such 
things? Like it should only be added if the architecture supports the 
extension? But I guess `-cl-ext=+cl_intel_planar_yuv` trick might not work here 
because it's not a Clang known extension?

So may be the right solution here is to introduce a target specific header? For 
now it can be explicitly included but we could think of a target hook to 
preload a target specific header...


https://reviews.llvm.org/D51402



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


r341548 - Fix march triple used test from rL341475

2018-09-06 Thread Diogo N. Sampaio via cfe-commits
Author: dnsampaio
Date: Thu Sep  6 07:13:10 2018
New Revision: 341548

URL: http://llvm.org/viewvc/llvm-project?rev=341548=rev
Log:
Fix march triple used test from rL341475

Change the march triple of test files, possible fixing
test failures due rL341475


Modified:
cfe/trunk/test/Headers/arm-fp16-header.c
cfe/trunk/test/Headers/arm-neon-header.c

Modified: cfe/trunk/test/Headers/arm-fp16-header.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/arm-fp16-header.c?rev=341548=341547=341548=diff
==
--- cfe/trunk/test/Headers/arm-fp16-header.c (original)
+++ cfe/trunk/test/Headers/arm-fp16-header.c Thu Sep  6 07:13:10 2018
@@ -1,19 +1,19 @@
-// RUN: %clang -fsyntax-only  -ffreestanding --target=aarch64-arm-none-eabi 
-march=armv8.2-a+fp16 -std=c89 -xc %s
-// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64-arm-none-eabi -march=armv8.2-a+fp16 -std=c99 -xc %s
-// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64-arm-none-eabi -march=armv8.2-a+fp16 -std=c11 -xc %s
+// RUN: %clang -fsyntax-only  -ffreestanding  
--target=aarch64-none-eabi -march=armv8.2-a+fp16 -std=c89 -xc %s
+// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64-none-eabi -march=armv8.2-a+fp16 -std=c99 -xc %s
+// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64-none-eabi -march=armv8.2-a+fp16 -std=c11 -xc %s
 
-// RUN: %clang -fsyntax-only -ffreestanding --target=aarch64-armeb-none-eabi 
-march=armv8.2-a+fp16 -std=c89 -xc %s
-// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64-armeb-none-eabi -march=armv8.2-a+fp16 -std=c99 -xc %s
-// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64-armeb-none-eabi -march=armv8.2-a+fp16 -std=c11 -xc %s
+// RUN: %clang -fsyntax-only -ffreestanding   
--target=aarch64_be-none-eabi -march=armv8.2-a+fp16 -std=c89 -xc %s
+// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64_be-none-eabi -march=armv8.2-a+fp16 -std=c99 -xc %s
+// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64_be-none-eabi -march=armv8.2-a+fp16 -std=c11 -xc %s
 
-// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64-arm-none-eabi -march=armv8.2-a+fp16 -std=c++98 -xc++ %s
-// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64-arm-none-eabi -march=armv8.2-a+fp16 -std=c++11 -xc++ %s
-// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64-arm-none-eabi -march=armv8.2-a+fp16 -std=c++14 -xc++ %s
-// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64-arm-none-eabi -march=armv8.2-a+fp16 -std=c++17 -xc++ %s
+// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64-none-eabi -march=armv8.2-a+fp16 -std=c++98 -xc++ %s
+// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64-none-eabi -march=armv8.2-a+fp16 -std=c++11 -xc++ %s
+// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64-none-eabi -march=armv8.2-a+fp16 -std=c++14 -xc++ %s
+// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64-none-eabi -march=armv8.2-a+fp16 -std=c++17 -xc++ %s
 
-// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64-armeb-none-eabi -march=armv8.2-a+fp16 -std=c++98 -xc++ %s
-// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64-armeb-none-eabi -march=armv8.2-a+fp16 -std=c++11 -xc++ %s
-// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64-armeb-none-eabi -march=armv8.2-a+fp16 -std=c++14 -xc++ %s
-// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64-armeb-none-eabi -march=armv8.2-a+fp16 -std=c++17 -xc++ %s
+// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64_be-none-eabi -march=armv8.2-a+fp16 -std=c++98 -xc++ %s
+// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64_be-none-eabi -march=armv8.2-a+fp16 -std=c++11 -xc++ %s
+// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64_be-none-eabi -march=armv8.2-a+fp16 -std=c++14 -xc++ %s
+// RUN: %clang -fsyntax-only -Wall -Werror -ffreestanding 
--target=aarch64_be-none-eabi -march=armv8.2-a+fp16 -std=c++17 -xc++ %s
 
 #include 

Modified: cfe/trunk/test/Headers/arm-neon-header.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/arm-neon-header.c?rev=341548=341547=341548=diff
==
--- cfe/trunk/test/Headers/arm-neon-header.c (original)
+++ cfe/trunk/test/Headers/arm-neon-header.c Thu Sep  6 07:13:10 2018
@@ -2,23 +2,22 @@
 // RUN: %clang_cc1 -triple thumbv7-apple-darwin10 -target-cpu cortex-a8 
-fsyntax-only -fno-lax-vector-conversions -ffreestanding %s
 // RUN: %clang_cc1 -x c++ -triple thumbv7-apple-darwin10 -target-cpu cortex-a8 

  1   2   >