[PATCH] D48989: -fdebug-prefix-map option for cc1as

2018-07-05 Thread Siddhartha Bagaria via Phabricator via cfe-commits
starsid added a comment.

In https://reviews.llvm.org/D48989#1153773, @compnerd wrote:

> However, please add a test to ensure that the paths are mapped when invoking 
> the assembler


I added the tests to check the mapping logic through llvm-mc in 
https://reviews.llvm.org/D48988. In this revision, I merely test if the driver 
is passing the flags to cc1as. The only thing that is untested is if cc1as_main 
is setting the options in MCContext correctly. If you want to see a test for 
that, please can you guide me a little on an appropriate way to test this 
within tools/clang/test.


Repository:
  rC Clang

https://reviews.llvm.org/D48989



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


[PATCH] D48989: -fdebug-prefix-map option for cc1as

2018-07-05 Thread Siddhartha Bagaria via Phabricator via cfe-commits
starsid updated this revision to Diff 154354.
starsid added a comment.

add a test for the Driver passing the new flag


Repository:
  rC Clang

https://reviews.llvm.org/D48989

Files:
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/Clang.cpp
  test/Driver/debug-prefix-map.S
  tools/driver/cc1as_main.cpp

Index: tools/driver/cc1as_main.cpp
===
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -94,6 +94,7 @@
   std::string DwarfDebugFlags;
   std::string DwarfDebugProducer;
   std::string DebugCompilationDir;
+  std::map DebugPrefixMap;
   llvm::DebugCompressionType CompressDebugSections =
   llvm::DebugCompressionType::None;
   std::string MainFileName;
@@ -233,6 +234,9 @@
   Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir);
   Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name);
 
+  for (const auto  : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ))
+Opts.DebugPrefixMap.insert(StringRef(Arg).split('='));
+
   // Frontend Options
   if (Args.hasArg(OPT_INPUT)) {
 bool First = true;
@@ -377,6 +381,9 @@
 Ctx.setDwarfDebugProducer(StringRef(Opts.DwarfDebugProducer));
   if (!Opts.DebugCompilationDir.empty())
 Ctx.setCompilationDir(Opts.DebugCompilationDir);
+  if (!Opts.DebugPrefixMap.empty())
+for (const auto  : Opts.DebugPrefixMap)
+  Ctx.addDebugPrefixMapEntry(KV.first, KV.second);
   if (!Opts.MainFileName.empty())
 Ctx.setMainFileName(StringRef(Opts.MainFileName));
   Ctx.setDwarfVersion(Opts.DwarfVersion);
Index: test/Driver/debug-prefix-map.S
===
--- /dev/null
+++ test/Driver/debug-prefix-map.S
@@ -0,0 +1,5 @@
+// RUN: %clang -### -g -fdebug-prefix-map=old=new %s 2>&1 | FileCheck %s
+
+// CHECK: fdebug-prefix-map=old=new
+
+// More tests for this flag in debug-prefix-map.c.
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -600,6 +600,18 @@
   }
 }
 
+/// Add a CC1 and CC1AS option to specify the debug file path prefix map.
+static void addDebugPrefixMapArg(const Driver , const ArgList , ArgStringList ) {
+  for (const Arg *A : Args.filtered(options::OPT_fdebug_prefix_map_EQ)) {
+StringRef Map = A->getValue();
+if (Map.find('=') == StringRef::npos)
+  D.Diag(diag::err_drv_invalid_argument_to_fdebug_prefix_map) << Map;
+else
+  CmdArgs.push_back(Args.MakeArgString("-fdebug-prefix-map=" + Map));
+A->claim();
+  }
+}
+
 /// Vectorize at all optimization levels greater than 1 except for -Oz.
 /// For -Oz the loop vectorizer is disable, while the slp vectorizer is enabled.
 static bool shouldEnableVectorizerAtOLevel(const ArgList , bool isSlpVec) {
@@ -3849,14 +3861,7 @@
   // Add in -fdebug-compilation-dir if necessary.
   addDebugCompDirArg(Args, CmdArgs);
 
-  for (const Arg *A : Args.filtered(options::OPT_fdebug_prefix_map_EQ)) {
-StringRef Map = A->getValue();
-if (Map.find('=') == StringRef::npos)
-  D.Diag(diag::err_drv_invalid_argument_to_fdebug_prefix_map) << Map;
-else
-  CmdArgs.push_back(Args.MakeArgString("-fdebug-prefix-map=" + Map));
-A->claim();
-  }
+  addDebugPrefixMapArg(D, Args, CmdArgs);
 
   if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_,
options::OPT_ftemplate_depth_EQ)) {
@@ -5409,6 +5414,8 @@
 // Add the -fdebug-compilation-dir flag if needed.
 addDebugCompDirArg(Args, CmdArgs);
 
+addDebugPrefixMapArg(getToolChain().getDriver(), Args, CmdArgs);
+
 // Set the AT_producer to the clang version when using the integrated
 // assembler on assembly source files.
 CmdArgs.push_back("-dwarf-debug-producer");
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1740,7 +1740,8 @@
 def fno_split_dwarf_inlining: Flag<["-"], "fno-split-dwarf-inlining">, Group,
   Flags<[CC1Option]>;
 def fdebug_prefix_map_EQ
-  : Joined<["-"], "fdebug-prefix-map=">, Group, Flags<[CC1Option]>,
+  : Joined<["-"], "fdebug-prefix-map=">, Group,
+Flags<[CC1Option,CC1AsOption]>,
 HelpText<"remap file source paths in debug info">;
 def g_Flag : Flag<["-"], "g">, Group,
   HelpText<"Generate source-level debug information">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48753: [libcxx] Use custom allocator's `construct` in C++03 when available.

2018-07-05 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: libcxx/include/memory:1470
+decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Pointer>(),
+_VSTD::declval<_Args>())),
+void

I think you should replace this `)))` with `)), void())` for absolute 
correctness (e.g. `construct` might plausibly return a pointer to the 
constructed object, and I think C++03 is okay with that).
Otherwise, awesome, this looks like what I'd expect. :)


https://reviews.llvm.org/D48753



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


[PATCH] D49002: [Index] Add index::IndexingOptions::IndexImplicitInstantiation

2018-07-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: akyrtzi, arphaman.
Herald added a subscriber: cfe-commits.

With IndexImplicitInstantiation=true, the following case records an occurrence 
of B::bar in A::foo, which will benefit cross reference tools.

template  struct B { void bar() {}};
template  struct A { void foo(B *x) { x->bar(); }};
int main() { A a; a.foo(0); }


Repository:
  rC Clang

https://reviews.llvm.org/D49002

Files:
  include/clang/Index/IndexingAction.h
  lib/Index/IndexDecl.cpp
  lib/Index/IndexTypeSourceInfo.cpp
  lib/Index/IndexingContext.cpp
  lib/Index/IndexingContext.h


Index: lib/Index/IndexingContext.h
===
--- lib/Index/IndexingContext.h
+++ lib/Index/IndexingContext.h
@@ -58,9 +58,7 @@
 
   bool shouldIndexFunctionLocalSymbols() const;
 
-  bool shouldIndexImplicitTemplateInsts() const {
-return false;
-  }
+  bool shouldIndexImplicitInstantiation() const;
 
   static bool isTemplateImplicitInstantiation(const Decl *D);
 
Index: lib/Index/IndexingContext.cpp
===
--- lib/Index/IndexingContext.cpp
+++ lib/Index/IndexingContext.cpp
@@ -36,6 +36,10 @@
   return IndexOpts.IndexFunctionLocals;
 }
 
+bool IndexingContext::shouldIndexImplicitInstantiation() const {
+  return IndexOpts.IndexImplicitInstantiation;
+}
+
 bool IndexingContext::handleDecl(const Decl *D,
  SymbolRoleSet Roles,
  ArrayRef Relations) {
Index: lib/Index/IndexTypeSourceInfo.cpp
===
--- lib/Index/IndexTypeSourceInfo.cpp
+++ lib/Index/IndexTypeSourceInfo.cpp
@@ -129,7 +129,7 @@
   template
   bool HandleTemplateSpecializationTypeLoc(TypeLocType TL) {
 if (const auto *T = TL.getTypePtr()) {
-  if (IndexCtx.shouldIndexImplicitTemplateInsts()) {
+  if (IndexCtx.shouldIndexImplicitInstantiation()) {
 if (CXXRecordDecl *RD = T->getAsCXXRecordDecl())
   IndexCtx.handleReference(RD, TL.getTemplateNameLoc(),
Parent, ParentDC, SymbolRoleSet(), 
Relations);
Index: lib/Index/IndexDecl.cpp
===
--- lib/Index/IndexDecl.cpp
+++ lib/Index/IndexDecl.cpp
@@ -726,7 +726,7 @@
   if (D->isImplicit() && shouldIgnoreIfImplicit(D))
 return true;
 
-  if (isTemplateImplicitInstantiation(D))
+  if (isTemplateImplicitInstantiation(D) && 
!shouldIndexImplicitInstantiation())
 return true;
 
   IndexingDeclVisitor Visitor(*this);
Index: include/clang/Index/IndexingAction.h
===
--- include/clang/Index/IndexingAction.h
+++ include/clang/Index/IndexingAction.h
@@ -38,6 +38,7 @@
   SystemSymbolFilterKind SystemSymbolFilter
 = SystemSymbolFilterKind::DeclarationsOnly;
   bool IndexFunctionLocals = false;
+  bool IndexImplicitInstantiation = false;
 };
 
 /// \param WrappedAction another frontend action to wrap over or null.


Index: lib/Index/IndexingContext.h
===
--- lib/Index/IndexingContext.h
+++ lib/Index/IndexingContext.h
@@ -58,9 +58,7 @@
 
   bool shouldIndexFunctionLocalSymbols() const;
 
-  bool shouldIndexImplicitTemplateInsts() const {
-return false;
-  }
+  bool shouldIndexImplicitInstantiation() const;
 
   static bool isTemplateImplicitInstantiation(const Decl *D);
 
Index: lib/Index/IndexingContext.cpp
===
--- lib/Index/IndexingContext.cpp
+++ lib/Index/IndexingContext.cpp
@@ -36,6 +36,10 @@
   return IndexOpts.IndexFunctionLocals;
 }
 
+bool IndexingContext::shouldIndexImplicitInstantiation() const {
+  return IndexOpts.IndexImplicitInstantiation;
+}
+
 bool IndexingContext::handleDecl(const Decl *D,
  SymbolRoleSet Roles,
  ArrayRef Relations) {
Index: lib/Index/IndexTypeSourceInfo.cpp
===
--- lib/Index/IndexTypeSourceInfo.cpp
+++ lib/Index/IndexTypeSourceInfo.cpp
@@ -129,7 +129,7 @@
   template
   bool HandleTemplateSpecializationTypeLoc(TypeLocType TL) {
 if (const auto *T = TL.getTypePtr()) {
-  if (IndexCtx.shouldIndexImplicitTemplateInsts()) {
+  if (IndexCtx.shouldIndexImplicitInstantiation()) {
 if (CXXRecordDecl *RD = T->getAsCXXRecordDecl())
   IndexCtx.handleReference(RD, TL.getTemplateNameLoc(),
Parent, ParentDC, SymbolRoleSet(), Relations);
Index: lib/Index/IndexDecl.cpp
===
--- lib/Index/IndexDecl.cpp
+++ lib/Index/IndexDecl.cpp
@@ -726,7 +726,7 @@
   if (D->isImplicit() && shouldIgnoreIfImplicit(D))
 return true;
 
-  if (isTemplateImplicitInstantiation(D))
+  if 

[PATCH] D48862: Fix lib paths for OpenEmbedded targets

2018-07-05 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang added a comment.

The prerequisite llvm patch has been committed: r336401


https://reviews.llvm.org/D48862



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


[PATCH] D48852: [Sema] -Wformat-pedantic only for NSInteger/NSUInteger %tu/%td on Darwin

2018-07-05 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC336396: [Sema] -Wformat-pedantic only for 
NSInteger/NSUInteger %tu/%td on Darwin (authored by arphaman, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D48852

Files:
  include/clang/Analysis/Analyses/FormatString.h
  lib/Analysis/PrintfFormatString.cpp
  lib/Sema/SemaChecking.cpp
  test/SemaObjC/format-size-spec-nsinteger.m

Index: include/clang/Analysis/Analyses/FormatString.h
===
--- include/clang/Analysis/Analyses/FormatString.h
+++ include/clang/Analysis/Analyses/FormatString.h
@@ -257,7 +257,12 @@
   const Kind K;
   QualType T;
   const char *Name = nullptr;
-  bool Ptr = false, IsSizeT = false;
+  bool Ptr = false;
+
+  /// The TypeKind identifies certain well-known types like size_t and
+  /// ptrdiff_t.
+  enum class TypeKind { DontCare, SizeT, PtrdiffT };
+  TypeKind TK = TypeKind::DontCare;
 
 public:
   ArgType(Kind K = UnknownTy, const char *N = nullptr) : K(K), Name(N) {}
@@ -267,7 +272,9 @@
   static ArgType Invalid() { return ArgType(InvalidTy); }
   bool isValid() const { return K != InvalidTy; }
 
-  bool isSizeT() const { return IsSizeT; }
+  bool isSizeT() const { return TK == TypeKind::SizeT; }
+
+  bool isPtrdiffT() const { return TK == TypeKind::PtrdiffT; }
 
   /// Create an ArgType which corresponds to the type pointer to A.
   static ArgType PtrTo(const ArgType& A) {
@@ -280,7 +287,15 @@
   /// Create an ArgType which corresponds to the size_t/ssize_t type.
   static ArgType makeSizeT(const ArgType ) {
 ArgType Res = A;
-Res.IsSizeT = true;
+Res.TK = TypeKind::SizeT;
+return Res;
+  }
+
+  /// Create an ArgType which corresponds to the ptrdiff_t/unsigned ptrdiff_t
+  /// type.
+  static ArgType makePtrdiffT(const ArgType ) {
+ArgType Res = A;
+Res.TK = TypeKind::PtrdiffT;
 return Res;
   }
 
Index: test/SemaObjC/format-size-spec-nsinteger.m
===
--- test/SemaObjC/format-size-spec-nsinteger.m
+++ test/SemaObjC/format-size-spec-nsinteger.m
@@ -1,16 +1,25 @@
 // RUN: %clang_cc1 -triple thumbv7-apple-ios -Wno-objc-root-class -fsyntax-only -verify -Wformat %s
 // RUN: %clang_cc1 -triple thumbv7-apple-ios -Wno-objc-root-class -fsyntax-only -verify -Wformat-pedantic -DPEDANTIC %s
+// RUN: %clang_cc1 -triple thumbv7k-apple-watchos2.0.0 -fsyntax-only -fblocks -verify %s
+// RUN: %clang_cc1 -triple thumbv7k-apple-watchos2.0.0 -fsyntax-only -fblocks -verify -Wformat-pedantic -DPEDANTIC %s
 
 #if !defined(PEDANTIC)
 // expected-no-diagnostics
 #endif
 
 #if __LP64__
 typedef unsigned long NSUInteger;
 typedef long NSInteger;
+typedef long ptrdiff_t;
 #else
 typedef unsigned int NSUInteger;
 typedef int NSInteger;
+#if __is_target_os(watchos)
+  // Watch ABI uses long for ptrdiff_t.
+  typedef long ptrdiff_t;
+#else
+  typedef int ptrdiff_t;
+#endif
 #endif
 
 @class NSString;
@@ -28,3 +37,16 @@
   // expected-warning@-4 {{values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead}}
 #endif
 }
+
+void testPtrdiffSpecifier(ptrdiff_t x) {
+  NSInteger i = 0;
+  NSUInteger j = 0;
+
+  NSLog(@"ptrdiff_t NSUinteger: %tu", j);
+  NSLog(@"ptrdiff_t NSInteger: %td", i);
+  NSLog(@"ptrdiff_t %tu, %td", x, x);
+#if __is_target_os(watchos) && defined(PEDANTIC)
+  // expected-warning@-4 {{values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead}}
+  // expected-warning@-4 {{values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead}}
+#endif
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -6894,10 +6894,11 @@
 QualType CastTy;
 std::tie(CastTy, CastTyName) = shouldNotPrintDirectly(S.Context, IntendedTy, E);
 if (!CastTy.isNull()) {
-  // %zi/%zu are OK to use for NSInteger/NSUInteger of type int
+  // %zi/%zu and %td/%tu are OK to use for NSInteger/NSUInteger of type int
   // (long in ASTContext). Only complain to pedants.
   if ((CastTyName == "NSInteger" || CastTyName == "NSUInteger") &&
-  AT.isSizeT() && AT.matchesType(S.Context, CastTy))
+  (AT.isSizeT() || AT.isPtrdiffT()) &&
+  AT.matchesType(S.Context, CastTy))
 Pedantic = true;
   IntendedTy = CastTy;
   ShouldNotPrintDirectly = true;
Index: lib/Analysis/PrintfFormatString.cpp
===
--- lib/Analysis/PrintfFormatString.cpp
+++ lib/Analysis/PrintfFormatString.cpp
@@ -472,7 +472,8 @@
? ArgType(Ctx.LongLongTy, "__int64")
: ArgType(Ctx.IntTy, "__int32");
   case LengthModifier::AsPtrDiff:
-return ArgType(Ctx.getPointerDiffType(), 

r336396 - [Sema] -Wformat-pedantic only for NSInteger/NSUInteger %tu/%td on Darwin

2018-07-05 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Thu Jul  5 15:51:11 2018
New Revision: 336396

URL: http://llvm.org/viewvc/llvm-project?rev=336396=rev
Log:
[Sema] -Wformat-pedantic only for NSInteger/NSUInteger %tu/%td on Darwin

The '%tu'/'%td' as formatting specifiers have been used to print out the
NSInteger/NSUInteger values for a long time. Typically their ABI matches, but 
that's
not the case on watchOS. The ABI difference boils down to the following:

- Regular 32-bit darwin targets (like armv7) use 'ptrdiff_t' of type 'int',
  which matches 'NSInteger'.
- WatchOS arm target (armv7k) uses 'ptrdiff_t' of type 'long', which doesn't
  match 'NSInteger' of type 'int'.

Because of this ABI difference these specifiers trigger -Wformat warnings only
for watchOS builds, which is really inconvenient for cross-platform code.

This patch avoids this -Wformat warning for '%tu'/'%td' and NS[U]Integer only,
and instead uses the new -Wformat-pedantic warning that JF introduced in
https://reviews.llvm.org/D47290. This is acceptable because Darwin guarantees 
that,
despite the watchOS ABI differences, sizeof(ptrdiff_t) == sizeof(NS[U]Integer),
and alignof(ptrdiff_t) == alignof(NS[U]Integer) so the warning is therefore 
noisy
for pedantic reasons.

I'll update public documentation to ensure that this behaviour is properly
communicated.

rdar://41739204

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

Modified:
cfe/trunk/include/clang/Analysis/Analyses/FormatString.h
cfe/trunk/lib/Analysis/PrintfFormatString.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaObjC/format-size-spec-nsinteger.m

Modified: cfe/trunk/include/clang/Analysis/Analyses/FormatString.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/FormatString.h?rev=336396=336395=336396=diff
==
--- cfe/trunk/include/clang/Analysis/Analyses/FormatString.h (original)
+++ cfe/trunk/include/clang/Analysis/Analyses/FormatString.h Thu Jul  5 
15:51:11 2018
@@ -257,7 +257,12 @@ private:
   const Kind K;
   QualType T;
   const char *Name = nullptr;
-  bool Ptr = false, IsSizeT = false;
+  bool Ptr = false;
+
+  /// The TypeKind identifies certain well-known types like size_t and
+  /// ptrdiff_t.
+  enum class TypeKind { DontCare, SizeT, PtrdiffT };
+  TypeKind TK = TypeKind::DontCare;
 
 public:
   ArgType(Kind K = UnknownTy, const char *N = nullptr) : K(K), Name(N) {}
@@ -267,7 +272,9 @@ public:
   static ArgType Invalid() { return ArgType(InvalidTy); }
   bool isValid() const { return K != InvalidTy; }
 
-  bool isSizeT() const { return IsSizeT; }
+  bool isSizeT() const { return TK == TypeKind::SizeT; }
+
+  bool isPtrdiffT() const { return TK == TypeKind::PtrdiffT; }
 
   /// Create an ArgType which corresponds to the type pointer to A.
   static ArgType PtrTo(const ArgType& A) {
@@ -280,7 +287,15 @@ public:
   /// Create an ArgType which corresponds to the size_t/ssize_t type.
   static ArgType makeSizeT(const ArgType ) {
 ArgType Res = A;
-Res.IsSizeT = true;
+Res.TK = TypeKind::SizeT;
+return Res;
+  }
+
+  /// Create an ArgType which corresponds to the ptrdiff_t/unsigned ptrdiff_t
+  /// type.
+  static ArgType makePtrdiffT(const ArgType ) {
+ArgType Res = A;
+Res.TK = TypeKind::PtrdiffT;
 return Res;
   }
 

Modified: cfe/trunk/lib/Analysis/PrintfFormatString.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/PrintfFormatString.cpp?rev=336396=336395=336396=diff
==
--- cfe/trunk/lib/Analysis/PrintfFormatString.cpp (original)
+++ cfe/trunk/lib/Analysis/PrintfFormatString.cpp Thu Jul  5 15:51:11 2018
@@ -472,7 +472,8 @@ ArgType PrintfSpecifier::getArgType(ASTC
? ArgType(Ctx.LongLongTy, "__int64")
: ArgType(Ctx.IntTy, "__int32");
   case LengthModifier::AsPtrDiff:
-return ArgType(Ctx.getPointerDiffType(), "ptrdiff_t");
+return ArgType::makePtrdiffT(
+ArgType(Ctx.getPointerDiffType(), "ptrdiff_t"));
   case LengthModifier::AsAllocate:
   case LengthModifier::AsMAllocate:
   case LengthModifier::AsWide:
@@ -505,7 +506,8 @@ ArgType PrintfSpecifier::getArgType(ASTC
? ArgType(Ctx.UnsignedLongLongTy, "unsigned __int64")
: ArgType(Ctx.UnsignedIntTy, "unsigned __int32");
   case LengthModifier::AsPtrDiff:
-return ArgType(Ctx.getUnsignedPointerDiffType(), "unsigned ptrdiff_t");
+return ArgType::makePtrdiffT(
+ArgType(Ctx.getUnsignedPointerDiffType(), "unsigned ptrdiff_t"));
   case LengthModifier::AsAllocate:
   case LengthModifier::AsMAllocate:
   case LengthModifier::AsWide:

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=336396=336395=336396=diff

[PATCH] D48342: [libcxx] Optimize vectors construction of trivial types from an iterator range with const-ness mismatch.

2018-07-05 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai updated this revision to Diff 154327.
vsapsai added a comment.

- Clean up tests according to review. We don't need a new test for custom 
allocators, parent patch covers that.


https://reviews.llvm.org/D48342

Files:
  libcxx/include/memory
  
libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp


Index: 
libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
===
--- 
libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
+++ 
libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
@@ -13,6 +13,8 @@
 
 #include 
 #include 
+#include 
+#include 
 #include 
 
 #include "test_macros.h"
@@ -176,9 +178,20 @@
 #endif
 }
 
+// Initialize a vector with a different value type. Make sure initialization
+// is performed with each element value, not with a memory blob.
+void test_ctor_with_different_value_type() {
+  int array[3] = {0, 1, 2};
+  std::vector v(array, array + 3);
+  assert(std::fabs(v[0] - 0.0f) < FLT_EPSILON);
+  assert(std::fabs(v[1] - 1.0f) < FLT_EPSILON);
+  assert(std::fabs(v[2] - 2.0f) < FLT_EPSILON);
+}
+
 
 int main() {
   basic_test_cases();
   emplaceable_concept_tests(); // See PR34898
   test_ctor_under_alloc();
+  test_ctor_with_different_value_type();
 }
Index: libcxx/include/memory
===
--- libcxx/include/memory
+++ libcxx/include/memory
@@ -1642,23 +1642,29 @@
 construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
 }
 
-template 
+template 
 _LIBCPP_INLINE_VISIBILITY
 static
 typename enable_if
 <
-(is_same >::value
-|| !__has_construct::value) &&
- is_trivially_move_constructible<_Tp>::value,
+is_same
+<
+typename _VSTD::remove_const<_SourceTp>::type,
+typename _VSTD::remove_const<_DestTp>::type
+>::value &&
+(is_same::type> >::value
+|| is_same >::value
+|| !__has_construct::value) &&
+ is_trivially_move_constructible<_DestTp>::value,
 void
 >::type
-__construct_range_forward(allocator_type&, _Tp* __begin1, _Tp* __end1, 
_Tp*& __begin2)
+__construct_range_forward(allocator_type&, _SourceTp* __begin1, 
_SourceTp* __end1, _DestTp*& __begin2)
 {
-typedef typename remove_const<_Tp>::type _Vp;
+typedef typename remove_const<_DestTp>::type _Vp;
 ptrdiff_t _Np = __end1 - __begin1;
 if (_Np > 0)
 {
-_VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * 
sizeof(_Tp));
+_VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * 
sizeof(_DestTp));
 __begin2 += _Np;
 }
 }


Index: libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
===
--- libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
+++ libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
@@ -13,6 +13,8 @@
 
 #include 
 #include 
+#include 
+#include 
 #include 
 
 #include "test_macros.h"
@@ -176,9 +178,20 @@
 #endif
 }
 
+// Initialize a vector with a different value type. Make sure initialization
+// is performed with each element value, not with a memory blob.
+void test_ctor_with_different_value_type() {
+  int array[3] = {0, 1, 2};
+  std::vector v(array, array + 3);
+  assert(std::fabs(v[0] - 0.0f) < FLT_EPSILON);
+  assert(std::fabs(v[1] - 1.0f) < FLT_EPSILON);
+  assert(std::fabs(v[2] - 2.0f) < FLT_EPSILON);
+}
+
 
 int main() {
   basic_test_cases();
   emplaceable_concept_tests(); // See PR34898
   test_ctor_under_alloc();
+  test_ctor_with_different_value_type();
 }
Index: libcxx/include/memory
===
--- libcxx/include/memory
+++ libcxx/include/memory
@@ -1642,23 +1642,29 @@
 construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
 }
 
-template 
+template 
 _LIBCPP_INLINE_VISIBILITY
 static
 typename enable_if
 <
-(is_same >::value
-|| !__has_construct::value) &&
- is_trivially_move_constructible<_Tp>::value,
+is_same
+<
+typename _VSTD::remove_const<_SourceTp>::type,
+typename _VSTD::remove_const<_DestTp>::type
+>::value &&
+(is_same::type> >::value
+|| is_same >::value
+|| !__has_construct::value) &&
+ is_trivially_move_constructible<_DestTp>::value,
 void
 >::type
-

[PATCH] D48753: [libcxx] Use custom allocator's `construct` in C++03 when available.

2018-07-05 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai updated this revision to Diff 154326.
vsapsai added a comment.

- Use a better way to detect presence of `construct` with required signature. 
Clean up tests.

Don't know how other compilers will handle this but Clang accepts this
C++11-looking-but-accepted-in-C++03 code.


https://reviews.llvm.org/D48753

Files:
  libcxx/include/memory
  
libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
  
libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
  libcxx/test/support/min_allocator.h

Index: libcxx/test/support/min_allocator.h
===
--- libcxx/test/support/min_allocator.h
+++ libcxx/test/support/min_allocator.h
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "test_macros.h"
 
@@ -131,6 +132,57 @@
 friend bool operator!=(malloc_allocator x, malloc_allocator y) {return !(x == y);}
 };
 
+template 
+struct cpp03_allocator : bare_allocator
+{
+typedef T value_type;
+typedef value_type* pointer;
+
+static bool construct_called;
+
+void construct(pointer p, const value_type& val)
+{
+::new(p) value_type(val);
+construct_called = true;
+}
+
+std::size_t max_size() const
+{
+return UINT_MAX / sizeof(T);
+}
+};
+template  bool cpp03_allocator::construct_called = false;
+
+template 
+struct cpp03_overload_allocator : bare_allocator
+{
+typedef T value_type;
+typedef value_type* pointer;
+
+static bool construct_called;
+
+void construct(pointer p, const value_type& val)
+{
+construct(p, val, std::is_class());
+}
+void construct(pointer p, const value_type& val, std::true_type)
+{
+::new(p) value_type(val);
+construct_called = true;
+}
+void construct(pointer p, const value_type& val, std::false_type)
+{
+::new(p) value_type(val);
+construct_called = true;
+}
+
+std::size_t max_size() const
+{
+return UINT_MAX / sizeof(T);
+}
+};
+template  bool cpp03_overload_allocator::construct_called = false;
+
 
 #if TEST_STD_VER >= 11
 
Index: libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
===
--- libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
+++ libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp
@@ -129,9 +129,39 @@
 }
 
 void test_ctor_under_alloc() {
-#if TEST_STD_VER >= 11
   int arr1[] = {42};
   int arr2[] = {1, 101, 42};
+  {
+typedef std::vector > C;
+typedef C::allocator_type Alloc;
+Alloc a;
+{
+  Alloc::construct_called = false;
+  C v(arr1, arr1 + 1, a);
+  assert(Alloc::construct_called);
+}
+{
+  Alloc::construct_called = false;
+  C v(arr2, arr2 + 3, a);
+  assert(Alloc::construct_called);
+}
+  }
+  {
+typedef std::vector > C;
+typedef C::allocator_type Alloc;
+Alloc a;
+{
+  Alloc::construct_called = false;
+  C v(arr1, arr1 + 1, a);
+  assert(Alloc::construct_called);
+}
+{
+  Alloc::construct_called = false;
+  C v(arr2, arr2 + 3, a);
+  assert(Alloc::construct_called);
+}
+  }
+#if TEST_STD_VER >= 11
   {
 using C = TCT::vector<>;
 using T = typename C::value_type;
Index: libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
===
--- libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
+++ libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp
@@ -116,9 +116,37 @@
 }
 
 void test_ctor_under_alloc() {
-#if TEST_STD_VER >= 11
   int arr1[] = {42};
   int arr2[] = {1, 101, 42};
+  {
+typedef std::vector > C;
+typedef C::allocator_type Alloc;
+{
+  Alloc::construct_called = false;
+  C v(arr1, arr1 + 1);
+  assert(Alloc::construct_called);
+}
+{
+  Alloc::construct_called = false;
+  C v(arr2, arr2 + 3);
+  assert(Alloc::construct_called);
+}
+  }
+  {
+typedef std::vector > C;
+typedef C::allocator_type Alloc;
+{
+  Alloc::construct_called = false;
+  C v(arr1, arr1 + 1);
+  assert(Alloc::construct_called);
+}
+{
+  Alloc::construct_called = false;
+  C v(arr2, arr2 + 3);
+  assert(Alloc::construct_called);
+}
+  }
+#if TEST_STD_VER >= 11
   {
 using C = TCT::vector<>;
 using T = typename C::value_type;
Index: libcxx/include/memory
===
--- libcxx/include/memory
+++ libcxx/include/memory
@@ -1459,23 +1459,18 @@
 
 #else  // _LIBCPP_CXX03_LANG
 
-#ifndef _LIBCPP_HAS_NO_VARIADICS
-
-template 
-struct __has_construct
-: false_type
-{
-};
-
-#else  // 

[PATCH] D48989: -fdebug-prefix-map option for cc1as

2018-07-05 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd accepted this revision.
compnerd added a comment.
This revision is now accepted and ready to land.

This seems reasonable if you need the support in the assembler.  However, 
please add a test to ensure that the paths are mapped when invoking the 
assembler rather than the compiler.


Repository:
  rC Clang

https://reviews.llvm.org/D48989



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


[PATCH] D48412: [RISCV] Add support for interrupt attribute

2018-07-05 Thread Ana Pazos via Phabricator via cfe-commits
apazos updated this revision to Diff 154322.
apazos added a comment.

Made the check/warning for prototype explicit.


https://reviews.llvm.org/D48412

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/CodeGen/TargetInfo.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/Sema/riscv-interrupt-attr.c
  test/Sema/riscv-interrupt-attr.cpp

Index: test/Sema/riscv-interrupt-attr.cpp
===
--- /dev/null
+++ test/Sema/riscv-interrupt-attr.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 %s -triple riscv32-unknown-elf -verify -fsyntax-only
+// RUN: %clang_cc1 %s -triple riscv64-unknown-elf -verify -fsyntax-only
+
+[[gnu::interrupt]] [[gnu::interrupt]] void foo1() {} // expected-warning {{repeated RISC-V 'interrupt' attribute}} \
+ // expected-note {{repeated RISC-V 'interrupt' attribute is here}}
+[[gnu::interrupt]] void foo2() {}
+
Index: test/Sema/riscv-interrupt-attr.c
===
--- /dev/null
+++ test/Sema/riscv-interrupt-attr.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 %s -triple riscv32-unknown-elf -verify -fsyntax-only
+// RUN: %clang_cc1 %s -triple riscv64-unknown-elf -verify -fsyntax-only
+
+struct a { int b; };
+
+struct a test __attribute__((interrupt)); // expected-warning {{'interrupt' attribute only applies to functions}}
+
+__attribute__((interrupt("USER"))) void foo1(void) {} // expected-warning {{'interrupt' attribute argument not supported: USER}}
+
+__attribute__((interrupt("user", 1))) void foo2(void) {} // expected-error {{'interrupt' attribute takes no more than 1 argument}}
+
+__attribute__((interrupt)) int foo3(void) {return 0;} // expected-warning {{RISC-V 'interrupt' attribute only applies to functions that have a 'void' return type}}
+
+__attribute__((interrupt())) int foo4(); // expected-warning {{RISC-V 'interrupt' attribute only applies to functions that have a prototype}}
+
+__attribute__((interrupt())) int foo4() {} // expected-warning {{RISC-V 'interrupt' attribute only applies to functions that have a prototype}}
+
+__attribute__((interrupt())) void foo5(int a) {} // expected-warning {{RISC-V 'interrupt' attribute only applies to functions that have no parameters}}
+
+__attribute__((interrupt("user"), interrupt("supervisor"))) void foo6(void) {} // expected-warning {{repeated RISC-V 'interrupt' attribute}} \
+  // expected-note {{repeated RISC-V 'interrupt' attribute is here}}
+
+__attribute__((interrupt, interrupt)) void foo7(void) {} // expected-warning {{repeated RISC-V 'interrupt' attribute}} \
+ // expected-note {{repeated RISC-V 'interrupt' attribute is here}}
+
+__attribute__((interrupt(""))) void foo8(void) {} // expected-warning {{'interrupt' attribute argument not supported}}
+
+__attribute__((interrupt("user"))) void foo9(void);
+__attribute__((interrupt("supervisor"))) void foo9(void);
+__attribute__((interrupt("machine"))) void foo9(void);
+
+__attribute__((interrupt("user"))) void foo10(void) {}
+__attribute__((interrupt("supervisor"))) void foo11(void) {}
+__attribute__((interrupt("machine"))) void foo12(void) {}
+__attribute__((interrupt())) void foo13(void) {}
+__attribute__((interrupt)) void foo14(void) {}
+
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -5266,6 +5266,68 @@
   handleSimpleAttribute(S, D, AL);
 }
 
+static void handleRISCVInterruptAttr(Sema , Decl *D,
+ const AttributeList ) {
+  // Warn about repeated attributes.
+  if (const auto *A = D->getAttr()) {
+S.Diag(AL.getRange().getBegin(),
+  diag::warn_riscv_repeated_interrupt_attribute);
+S.Diag(A->getLocation(), diag::note_riscv_repeated_interrupt_attribute);
+return;
+  }
+
+  // Check the attribute argument. Argument is optional.
+  if (!checkAttributeAtMostNumArgs(S, AL, 1))
+return;
+
+  StringRef Str;
+  SourceLocation ArgLoc;
+
+  // 'machine'is the default interrupt mode.
+  if (AL.getNumArgs() == 0)
+Str = "machine";
+  else if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, ))
+return;
+
+  // Semantic checks for a function with the 'interrupt' attribute:
+  // - Must be a function.
+  // - Must have no parameters.
+  // - Must have the 'void' return type.
+  // - The attribute itself must either have no argument or one of the
+  //   valid interrupt types, see [RISCVInterruptDocs].
+
+  if (D->getFunctionType() == nullptr) {
+S.Diag(D->getLocation(), diag::warn_attribute_wrong_decl_type)
+  << "'interrupt'" << ExpectedFunction;
+return;
+  }
+
+  if (!hasFunctionProto(D)) {
+S.Diag(D->getLocation(), diag::warn_riscv_interrupt_attribute) << 2;
+return;
+  }
+
+  if (getFunctionOrMethodNumParams(D) != 0) {
+

[PATCH] D48903: [VirtualFileSystem] InMemoryFileSystem::status: Return a Status with the requested name

2018-07-05 Thread Simon Marchi via Phabricator via cfe-commits
simark updated this revision to Diff 154321.
simark marked 4 inline comments as done.
simark added a comment.

- Add RequestedName to InMemoryNode::getStatus.
- Also fix the directory_iterator code path.


Repository:
  rC Clang

https://reviews.llvm.org/D48903

Files:
  lib/Basic/VirtualFileSystem.cpp
  unittests/Basic/VirtualFileSystemTest.cpp
  unittests/Driver/ToolChainTest.cpp

Index: unittests/Driver/ToolChainTest.cpp
===
--- unittests/Driver/ToolChainTest.cpp
+++ unittests/Driver/ToolChainTest.cpp
@@ -113,7 +113,7 @@
   std::replace(S.begin(), S.end(), '\\', '/');
 #endif
   EXPECT_EQ("Found candidate GCC installation: "
-"/home/test/lib/gcc/arm-linux-gnueabi/4.6.1\n"
+"/home/test/bin/../lib/gcc/arm-linux-gnueabi/4.6.1\n"
 "Selected GCC installation: "
 "/home/test/bin/../lib/gcc/arm-linux-gnueabi/4.6.1\n"
 "Candidate multilib: .;@m32\n"
Index: unittests/Basic/VirtualFileSystemTest.cpp
===
--- unittests/Basic/VirtualFileSystemTest.cpp
+++ unittests/Basic/VirtualFileSystemTest.cpp
@@ -794,7 +794,7 @@
 
   auto Stat = FS.status("/b/c");
   ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
-  ASSERT_EQ("c", Stat->getName());
+  ASSERT_EQ("/b/c", Stat->getName());
   ASSERT_EQ("/b", *FS.getCurrentWorkingDirectory());
 
   Stat = FS.status("c");
@@ -919,6 +919,39 @@
   ASSERT_TRUE(Stat->isRegularFile());
 }
 
+// Test that the name returned by status() is in the same form as the path that
+// was requested (to match the behavior of RealFileSystem).
+TEST_F(InMemoryFileSystemTest, StatusName) {
+  NormalizedFS.addFile("/a/b/c", 0, MemoryBuffer::getMemBuffer("abc"),
+   /*User=*/None,
+   /*Group=*/None, sys::fs::file_type::regular_file);
+  NormalizedFS.setCurrentWorkingDirectory("/a/b");
+
+  // Access using InMemoryFileSystem::status.
+  auto Stat = NormalizedFS.status("../b/c");
+  ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n"
+<< NormalizedFS.toString();
+  ASSERT_TRUE(Stat->isRegularFile());
+  ASSERT_EQ("../b/c", Stat->getName());
+
+  // Access using InMemoryFileAdaptor::status.
+  auto File = NormalizedFS.openFileForRead("../b/c");
+  ASSERT_FALSE(File.getError()) << File.getError() << "\n"
+<< NormalizedFS.toString();
+  Stat = (*File)->status();
+  ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n"
+<< NormalizedFS.toString();
+  ASSERT_TRUE(Stat->isRegularFile());
+  ASSERT_EQ("../b/c", Stat->getName());
+
+  // Access using a directory iterator.
+  std::error_code EC;
+  clang::vfs::directory_iterator It = NormalizedFS.dir_begin("../b", EC);
+  clang::vfs::directory_iterator End;
+
+  ASSERT_EQ("../b/c", It->getName());
+}
+
 // NOTE: in the tests below, we use '//root/' as our root directory, since it is
 // a legal *absolute* path on Windows as well as *nix.
 class VFSFromYAMLTest : public ::testing::Test {
Index: lib/Basic/VirtualFileSystem.cpp
===
--- lib/Basic/VirtualFileSystem.cpp
+++ lib/Basic/VirtualFileSystem.cpp
@@ -479,7 +479,13 @@
   : Stat(std::move(Stat)), Kind(Kind) {}
   virtual ~InMemoryNode() = default;
 
-  const Status () const { return Stat; }
+  /// Return the \p Status for this node. \p RequestedName should be the name
+  /// through which the caller referred to this node. It will override
+  /// \p Status::Name in the return value, to mimic the behavior of \p RealFile.
+  Status getStatus(std::string RequestedName) const {
+return Status::copyWithNewName(Stat, RequestedName);
+  }
+  StringRef getName() const { return Stat.getName(); }
   InMemoryNodeKind getKind() const { return Kind; }
   virtual std::string toString(unsigned Indent) const = 0;
 };
@@ -496,22 +502,30 @@
   llvm::MemoryBuffer *getBuffer() { return Buffer.get(); }
 
   std::string toString(unsigned Indent) const override {
-return (std::string(Indent, ' ') + getStatus().getName() + "\n").str();
+return (std::string(Indent, ' ') + getName() + "\n").str();
   }
 
   static bool classof(const InMemoryNode *N) {
 return N->getKind() == IME_File;
   }
 };
 
-/// Adapt a InMemoryFile for VFS' File interface.
+/// Adapt a InMemoryFile for VFS' File interface.  The goal is to make
+/// \p InMemoryFileAdaptor mimic as much as possible the behavior of
+/// \p RealFile.
 class InMemoryFileAdaptor : public File {
   InMemoryFile 
 
+  /// The name to use when returning a Status for this file.
+  std::string RequestedName;
+
 public:
-  explicit InMemoryFileAdaptor(InMemoryFile ) : Node(Node) {}
+  explicit InMemoryFileAdaptor(InMemoryFile , std::string RequestedName)
+  : Node(Node), RequestedName(std::move(RequestedName)) {}
 
-  llvm::ErrorOr status() override { 

[PATCH] D48928: [ms] Fix mangling of string literals used to initialize arrays larger or smaller than the literal

2018-07-05 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision.
thakis added a comment.
This revision is now accepted and ready to land.

Nice!




Comment at: lib/AST/MicrosoftMangle.cpp:3198
+  ->getSize()
+  .getZExtValue();
+

nit: Also do `unsigned StingByteLength = StringLength * SL->getCharByteWidth()` 
here and use it the 3 times you have that computation below



Comment at: lib/AST/MicrosoftMangle.cpp:3210
 
-  auto GetLittleEndianByte = [](unsigned Index) {
+  auto GetLittleEndianByte = [, StringLength](unsigned Index) {
 unsigned CharByteWidth = SL->getCharByteWidth();

You're capturing StringLength here, but then you don't use it in the lambda 
body.



Comment at: lib/AST/MicrosoftMangle.cpp:3219
 
-  auto GetBigEndianByte = [](unsigned Index) {
+  auto GetBigEndianByte = [, StringLength](unsigned Index) {
 unsigned CharByteWidth = SL->getCharByteWidth();

likewise



Comment at: test/CodeGen/mangle-ms-string-literals.c:7
+  struct {int x; char s[2]; } truncatedAscii = {x, "hello"};
+  // CHECK: "??_C@_01CONKJJHI@he@"
+  struct {int x; char s[16]; } paddedAscii = {x, "hello"};

Nice, we used to mismangle this. MSVC matches the string here: 
https://godbolt.org/g/dbm6jT (old clang: https://godbolt.org/g/Yy7iCK)


https://reviews.llvm.org/D48928



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


[PATCH] D48903: [VirtualFileSystem] InMemoryFileSystem::status: Return a Status with the requested name

2018-07-05 Thread Simon Marchi via Phabricator via cfe-commits
simark marked 6 inline comments as done.
simark added inline comments.



Comment at: lib/Basic/VirtualFileSystem.cpp:516
+  explicit InMemoryFileAdaptor(InMemoryFile , std::string RequestedName)
+  : Node(Node), RequestedName (std::move (RequestedName))
+  {}

ilya-biryukov wrote:
> NIT: The formatting is broken here.
Hmm this is what git-clang-format does (unless this comment refers to a 
previous version where I had not run clang-format).



Comment at: lib/Basic/VirtualFileSystem.cpp:520
+  llvm::ErrorOr status() override {
+Status St = Node.getStatus();
+return Status::copyWithNewName(St, RequestedName);

ilya-biryukov wrote:
> Maybe add a `RequestedName` parameter to the `InMemoryNode` instead to make 
> sure it's not misused?
> It looks like all the clients calling it have to change the name and some are 
> not doing it now, e.g. the directory iterator will use statuses with full 
> paths.
Ok, I tried to do something like that.



Comment at: lib/Basic/VirtualFileSystem.cpp:521
+Status St = Node.getStatus();
+return Status::copyWithNewName(St, RequestedName);
+  }

ilya-biryukov wrote:
> Maybe add a comment that this matches the real file system behavior?
I added a comment to `InMemoryNode::getSatus`, since that's where the 
`copyWithNewName` is done now.



Comment at: lib/Basic/VirtualFileSystem.cpp:724
+  Status St = (*Node)->getStatus();
+  return Status::copyWithNewName(St, Path.str());
+}

ilya-biryukov wrote:
> NIT: we don't need `str()` here
Otherwise I'm getting this:

```
/home/emaisin/src/llvm/tools/clang/lib/Basic/VirtualFileSystem.cpp:1673:9: 
error: no matching function for call to 'copyWithNewName'
S = Status::copyWithNewName(S, Path);
^~~
/home/emaisin/src/llvm/tools/clang/lib/Basic/VirtualFileSystem.cpp:76:16: note: 
candidate function not viable: no known conversion from 'const llvm::Twine' to 
'llvm::StringRef' for 2nd argument
Status Status::copyWithNewName(const Status , StringRef NewName) {
   ^
/home/emaisin/src/llvm/tools/clang/lib/Basic/VirtualFileSystem.cpp:82:16: note: 
candidate function not viable: no known conversion from 'clang::vfs::Status' to 
'const llvm::sys::fs::file_status' for 1st argument
Status Status::copyWithNewName(const file_status , StringRef NewName) {
   ^
```


Repository:
  rC Clang

https://reviews.llvm.org/D48903



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


[PATCH] D48845: [Sema] Add fixit for unused lambda captures

2018-07-05 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexshap added inline comments.



Comment at: lib/Sema/SemaLambda.cpp:1548
+  // Find the end of the explicit capture for use in fixits.
+  SourceLocation EndLoc;
+  if (From.isThisCapture() && From.isCopyCapture()) {

alexshap wrote:
> maybe these lines 1548 -1559 can be factored out into a helper function ?
+ maybe use a different name (EndLoc feels too generic in this particular 
case), but i don't insist


Repository:
  rC Clang

https://reviews.llvm.org/D48845



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


[PATCH] D48845: [Sema] Add fixit for unused lambda captures

2018-07-05 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexshap added inline comments.



Comment at: lib/Sema/SemaLambda.cpp:1548
+  // Find the end of the explicit capture for use in fixits.
+  SourceLocation EndLoc;
+  if (From.isThisCapture() && From.isCopyCapture()) {

maybe these lines 1548 -1559 can be factored out into a helper function ?


Repository:
  rC Clang

https://reviews.llvm.org/D48845



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


[PATCH] D48845: [Sema] Add fixit for unused lambda captures

2018-07-05 Thread Andrew Comminos via Phabricator via cfe-commits
acomminos updated this revision to Diff 154313.
acomminos added a comment.

Add additional tests to ensure that explicit capture ranges are predicted 
correctly.


Repository:
  rC Clang

https://reviews.llvm.org/D48845

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaLambda.cpp
  test/FixIt/fixit-unused-lambda-capture.cpp

Index: test/FixIt/fixit-unused-lambda-capture.cpp
===
--- /dev/null
+++ test/FixIt/fixit-unused-lambda-capture.cpp
@@ -0,0 +1,58 @@
+// RUN: cp %s %t
+// RUN: %clang_cc1 -x c++ -fsyntax-only -Wunused-lambda-capture -std=c++1z -fixit %t
+// RUN: grep -v CHECK %t | FileCheck %s
+
+void test() {
+  int i = 0;
+  int j = 0;
+  int k = 0;
+  int c = 10;
+  int a[c];
+
+  [i,j] { return i; };
+  // CHECK: [i] { return i; };
+  [i,j] { return j; };
+  // CHECK: [j] { return j; };
+  [i,j,k] {};
+  // CHECK: [] {};
+  [i,j,k] { return i + j; };
+  // CHECK: [i,j] { return i + j; };
+  [i,j,k] { return j + k; };
+  // CHECK: [j,k] { return j + k; };
+  [i,j,k] { return i + k; };
+  // CHECK: [i,k] { return i + k; };
+  [i,j,k] { return i + j + k; };
+  // CHECK: [i,j,k] { return i + j + k; };
+  [&,i] { return k; };
+  // CHECK: [&] { return k; };
+  [=,] { return k; };
+  // CHECK: [=] { return k; };
+  [=,,] { return j; };
+  // CHECK: [=,] { return j; };
+  [=,,] { return i; };
+  // CHECK: [=,] { return i; };
+  [z = i] {};
+  // CHECK: [] {};
+  [i,z = i,j] { return z; };
+  // CHECK: [z = i] { return z; };
+  [] {};
+  // CHECK: [] {};
+}
+
+class ThisTest {
+  void test() {
+int i = 0;
+[this] {};
+// CHECK: [] {};
+[i,this] { return i; };
+// CHECK: [i] { return i; };
+[this,i] { return i; };
+// CHECK: [i] { return i; };
+[*this] {};
+// CHECK: [] {};
+[*this,i] { return i; };
+// CHECK: [i] { return i; };
+[i,*this] { return i; };
+// CHECK: [i] { return i; };
+  }
+};
Index: lib/Sema/SemaLambda.cpp
===
--- lib/Sema/SemaLambda.cpp
+++ lib/Sema/SemaLambda.cpp
@@ -1478,7 +1478,8 @@
   return false;
 }
 
-void Sema::DiagnoseUnusedLambdaCapture(const Capture ) {
+void Sema::DiagnoseUnusedLambdaCapture(const SourceRange CaptureRange,
+   const Capture ) {
   if (CaptureHasSideEffects(From))
 return;
 
@@ -1491,6 +1492,7 @@
   else
 diag << From.getVariable();
   diag << From.isNonODRUsed();
+  diag << FixItHint::CreateRemoval(CaptureRange);
 }
 
 ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc,
@@ -1532,19 +1534,51 @@
 
 // Translate captures.
 auto CurField = Class->field_begin();
+// True if the current capture has an initializer or default before it.
+bool CurHasPreviousInitializer = CaptureDefault != LCD_None;
+SourceLocation PrevCaptureLoc = CurHasPreviousInitializer ?
+CaptureDefaultLoc : IntroducerRange.getBegin();
+
 for (unsigned I = 0, N = LSI->Captures.size(); I != N; ++I, ++CurField) {
   const Capture  = LSI->Captures[I];
   assert(!From.isBlockCapture() && "Cannot capture __block variables");
   bool IsImplicit = I >= LSI->NumExplicitCaptures;
 
+  // Find the end of the explicit capture for use in fixits.
+  SourceLocation EndLoc;
+  if (From.isThisCapture() && From.isCopyCapture()) {
+// Skip dereference token in *this.
+EndLoc = getLocForEndOfToken(From.getLocation());
+  } else if (!From.isVLATypeCapture() && From.getInitExpr()) {
+// For initialized captures, use the end of the expression.
+EndLoc = From.getInitExpr()->getLocEnd();
+  } else {
+// Otherwise, use the location of the identifier token.
+EndLoc = From.getLocation();
+  }
+
   // Warn about unused explicit captures.
+  bool IsCaptureUsed = true;
   if (!CurContext->isDependentContext() && !IsImplicit && !From.isODRUsed()) {
 // Initialized captures that are non-ODR used may not be eliminated.
 bool NonODRUsedInitCapture =
 IsGenericLambda && From.isNonODRUsed() && From.getInitExpr();
-if (!NonODRUsedInitCapture)
-  DiagnoseUnusedLambdaCapture(From);
+if (!NonODRUsedInitCapture) {
+  // Include either the previous, next, or no comma to produce
+  // individually valid fixits, depending on the capture position.
+  SourceRange FixItRange;
+  bool IsLast = I + 1 == LSI->NumExplicitCaptures;
+  if (!CurHasPreviousInitializer && !IsLast) {
+FixItRange = SourceRange(From.getLocation(), getLocForEndOfToken(EndLoc));
+  } else {
+FixItRange = SourceRange(getLocForEndOfToken(PrevCaptureLoc), EndLoc);
+  }
+
+  DiagnoseUnusedLambdaCapture(FixItRange, From);
+  IsCaptureUsed = false;
+}
   }
+  CurHasPreviousInitializer |= IsCaptureUsed;
 
   // Handle 'this' capture.
   if 

[PATCH] D48412: [RISCV] Add support for interrupt attribute

2018-07-05 Thread Ana Pazos via Phabricator via cfe-commits
apazos added inline comments.



Comment at: test/Sema/riscv-interrupt-attr.c:23
+  // expected-note 
{{repeated RISC-V 'interrupt' attribute is here}}
+__attribute__((interrupt("user"))) void foo8() {}
+__attribute__((interrupt("supervisor"))) void foo9() {}

aaron.ballman wrote:
> apazos wrote:
> > aaron.ballman wrote:
> > > apazos wrote:
> > > > aaron.ballman wrote:
> > > > > aaron.ballman wrote:
> > > > > > Do you intend for functions without a prototype to be accepted? 
> > > > > > foo8() can be passed an arbitrary number of arguments, which is a 
> > > > > > bit different than what I thought you wanted the semantic check to 
> > > > > > be.
> > > > > This question remains outstanding.
> > > > The checks are validating both function definitions and function 
> > > > prototypes like these:
> > > > _attribute__((interrupt)) void foo1() {} 
> > > > __attribute__((interrupt)) void foo(void);
> > > > Not sure what the confusion is.
> > > Ah, now I see where the confusion is.
> > > 
> > > In C, an empty parameter list declares a function without a prototype; 
> > > functions without prototypes can accept any number of arguments. To 
> > > declare a function that accepts no arguments, you must have a prototype 
> > > for the function and the parameter list is void. In C++, all functions 
> > > are prototyped and an empty parameter list is equivalent to a parameter 
> > > list of void. The word "prototype" doesn't mean "forward declaration". 
> > > e.g.,
> > > ```
> > > // C code
> > > void foo1(); // Declaration; no prototype; accepts any number of 
> > > arguments.
> > > void foo2() {} // Definition; no prototype; accepts any number of 
> > > arguments.
> > > void foo3(void); // Declaration; prototype; accepts no arguments.
> > > void foo4(void) {} // Definition; prototype; accepts no arguments.
> > > 
> > > foo2(1, 2, 3); // ok
> > > foo4(1, 2, 3); // error
> > > ```
> > > Because a function without a prototype can accept any number of 
> > > arguments, I think you want to diagnose such a function signature.
> > Thanks for clarifying. 
> > 
> > I checked GCC behavior and it is less strict. For the example below, it 
> > silently accepts the interrupt attribute.
> > 
> > extern int foo2();
> > __attribute__((interrupt)) void foo();
> > void foo() {
> >   foo2();
> > }
> > 
> > while in LLVM we would be rejecting with the message: 
> > RISC-V 'interrupt' attribute only applies to functions that have no 
> > parameters. 
> > 
> > I find the reuse of the message confusing. 
> > 
> > If we want stricter rule then we probably also need a specific message for 
> > the  missing prototype.
> > 
> > I checked GCC behavior and it is less strict. For the example below, it 
> > silently accepts the interrupt attribute.
> 
> Does it drop the attribute?
> 
> > If we want stricter rule then we probably also need a specific message for 
> > the missing prototype.
> 
> If GCC silently drops the attribute in this case then we definitely want a 
> more strict rule. We already have a good diagnostic for this: 
> `warn_attribute_wrong_decl_type` with the expected type diagnostic index 
> being `ExpectedFunctionWithProtoType`.
It does not drop, it compiles without warnings and it produces the code that is 
expected when interrupt attribute is set.


https://reviews.llvm.org/D48412



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


[PATCH] D48996: [clangd] Mark "Document Symbols" as implemented in the docs

2018-07-05 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle created this revision.
Herald added subscribers: cfe-commits, jkorous, MaskRay, ioeric, ilya-biryukov.

Signed-off-by: Marc-Andre Laperle 


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48996

Files:
  docs/clangd.rst


Index: docs/clangd.rst
===
--- docs/clangd.rst
+++ docs/clangd.rst
@@ -81,7 +81,7 @@
 +-++--+
 | Code Lens   | Yes|   No |
 +-++--+
-| Document Symbols| Yes|   No |
+| Document Symbols| Yes|   Yes|
 +-++--+
 | Workspace Symbols   | Yes|   No |
 +-++--+


Index: docs/clangd.rst
===
--- docs/clangd.rst
+++ docs/clangd.rst
@@ -81,7 +81,7 @@
 +-++--+
 | Code Lens   | Yes|   No |
 +-++--+
-| Document Symbols| Yes|   No |
+| Document Symbols| Yes|   Yes|
 +-++--+
 | Workspace Symbols   | Yes|   No |
 +-++--+
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48845: [Sema] Add fixit for unused lambda captures

2018-07-05 Thread Andrew Comminos via Phabricator via cfe-commits
acomminos updated this revision to Diff 154307.
acomminos added a comment.

Handle initialization expressions and dereferenced `this` in lambda captures.

An alternative to handling various kinds of explicit captures would be 
propagating the source range for each lambda capture from the parser to each 
sema::Capture. This would only be applicable to explicit captures; is this 
preferable?


Repository:
  rC Clang

https://reviews.llvm.org/D48845

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaLambda.cpp
  test/FixIt/fixit-unused-lambda-capture.cpp

Index: test/FixIt/fixit-unused-lambda-capture.cpp
===
--- /dev/null
+++ test/FixIt/fixit-unused-lambda-capture.cpp
@@ -0,0 +1,52 @@
+// RUN: cp %s %t
+// RUN: %clang_cc1 -x c++ -fsyntax-only -Wunused-lambda-capture -std=c++1z -fixit %t
+// RUN: grep -v CHECK %t | FileCheck %s
+
+void test() {
+  int i = 0;
+  int j = 0;
+  int k = 0;
+  int c = 10;
+  int a[c];
+
+  [i,j] { return i; };
+  // CHECK: [i] { return i; };
+  [i,j] { return j; };
+  // CHECK: [j] { return j; };
+  [i,j,k] {};
+  // CHECK: [] {};
+  [i,j,k] { return i + j; };
+  // CHECK: [i,j] { return i + j; };
+  [i,j,k] { return j + k; };
+  // CHECK: [j,k] { return j + k; };
+  [i,j,k] { return i + k; };
+  // CHECK: [i,k] { return i + k; };
+  [i,j,k] { return i + j + k; };
+  // CHECK: [i,j,k] { return i + j + k; };
+  [&,i] { return k; };
+  // CHECK: [&] { return k; };
+  [=,] { return k; };
+  // CHECK: [=] { return k; };
+  [=,,] { return j; };
+  // CHECK: [=,] { return j; };
+  [=,,] { return i; };
+  // CHECK: [=,] { return i; };
+  [z = i] {};
+  // CHECK: [] {};
+  [i,z = i,j] { return z; };
+  // CHECK: [z = i] { return z; };
+  [] {};
+  // CHECK: [] {};
+}
+
+class ThisTest {
+  void test() {
+int i = 0;
+[this] {};
+// CHECK: [] {};
+[i,this] { return this; };
+// CHECK: [this] { return this; };
+[*this] {};
+// CHECK: [] {};
+  }
+};
Index: lib/Sema/SemaLambda.cpp
===
--- lib/Sema/SemaLambda.cpp
+++ lib/Sema/SemaLambda.cpp
@@ -1478,7 +1478,8 @@
   return false;
 }
 
-void Sema::DiagnoseUnusedLambdaCapture(const Capture ) {
+void Sema::DiagnoseUnusedLambdaCapture(const SourceRange CaptureRange,
+   const Capture ) {
   if (CaptureHasSideEffects(From))
 return;
 
@@ -1491,6 +1492,7 @@
   else
 diag << From.getVariable();
   diag << From.isNonODRUsed();
+  diag << FixItHint::CreateRemoval(CaptureRange);
 }
 
 ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc,
@@ -1532,19 +1534,51 @@
 
 // Translate captures.
 auto CurField = Class->field_begin();
+// True if the current capture has an initializer or default before it.
+bool CurHasPreviousInitializer = CaptureDefault != LCD_None;
+SourceLocation PrevCaptureLoc = CurHasPreviousInitializer ?
+CaptureDefaultLoc : IntroducerRange.getBegin();
+
 for (unsigned I = 0, N = LSI->Captures.size(); I != N; ++I, ++CurField) {
   const Capture  = LSI->Captures[I];
   assert(!From.isBlockCapture() && "Cannot capture __block variables");
   bool IsImplicit = I >= LSI->NumExplicitCaptures;
 
+  // Find the end of the explicit capture for use in fixits.
+  SourceLocation EndLoc;
+  if (From.isThisCapture() && From.isCopyCapture()) {
+// Skip dereference token in *this.
+EndLoc = getLocForEndOfToken(From.getLocation());
+  } else if (!From.isVLATypeCapture() && From.getInitExpr()) {
+// For initialized captures, use the end of the expression.
+EndLoc = From.getInitExpr()->getLocEnd();
+  } else {
+// Otherwise, use the location of the identifier token.
+EndLoc = From.getLocation();
+  }
+
   // Warn about unused explicit captures.
+  bool IsCaptureUsed = true;
   if (!CurContext->isDependentContext() && !IsImplicit && !From.isODRUsed()) {
 // Initialized captures that are non-ODR used may not be eliminated.
 bool NonODRUsedInitCapture =
 IsGenericLambda && From.isNonODRUsed() && From.getInitExpr();
-if (!NonODRUsedInitCapture)
-  DiagnoseUnusedLambdaCapture(From);
+if (!NonODRUsedInitCapture) {
+  // Delete either the preceding or next comma in the explicit capture
+  // list, depending on whether or not elements follow.
+  SourceRange FixItRange;
+  bool IsLast = I + 1 == LSI->NumExplicitCaptures;
+  if (!CurHasPreviousInitializer && !IsLast) {
+FixItRange = SourceRange(From.getLocation(), getLocForEndOfToken(EndLoc));
+  } else {
+FixItRange = SourceRange(getLocForEndOfToken(PrevCaptureLoc), EndLoc);
+  }
+
+  DiagnoseUnusedLambdaCapture(FixItRange, From);
+  IsCaptureUsed = false;
+}
   }
+  CurHasPreviousInitializer |= 

[PATCH] D48412: [RISCV] Add support for interrupt attribute

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



Comment at: test/Sema/riscv-interrupt-attr.c:23
+  // expected-note 
{{repeated RISC-V 'interrupt' attribute is here}}
+__attribute__((interrupt("user"))) void foo8() {}
+__attribute__((interrupt("supervisor"))) void foo9() {}

apazos wrote:
> aaron.ballman wrote:
> > apazos wrote:
> > > aaron.ballman wrote:
> > > > aaron.ballman wrote:
> > > > > Do you intend for functions without a prototype to be accepted? 
> > > > > foo8() can be passed an arbitrary number of arguments, which is a bit 
> > > > > different than what I thought you wanted the semantic check to be.
> > > > This question remains outstanding.
> > > The checks are validating both function definitions and function 
> > > prototypes like these:
> > > _attribute__((interrupt)) void foo1() {} 
> > > __attribute__((interrupt)) void foo(void);
> > > Not sure what the confusion is.
> > Ah, now I see where the confusion is.
> > 
> > In C, an empty parameter list declares a function without a prototype; 
> > functions without prototypes can accept any number of arguments. To declare 
> > a function that accepts no arguments, you must have a prototype for the 
> > function and the parameter list is void. In C++, all functions are 
> > prototyped and an empty parameter list is equivalent to a parameter list of 
> > void. The word "prototype" doesn't mean "forward declaration". e.g.,
> > ```
> > // C code
> > void foo1(); // Declaration; no prototype; accepts any number of arguments.
> > void foo2() {} // Definition; no prototype; accepts any number of arguments.
> > void foo3(void); // Declaration; prototype; accepts no arguments.
> > void foo4(void) {} // Definition; prototype; accepts no arguments.
> > 
> > foo2(1, 2, 3); // ok
> > foo4(1, 2, 3); // error
> > ```
> > Because a function without a prototype can accept any number of arguments, 
> > I think you want to diagnose such a function signature.
> Thanks for clarifying. 
> 
> I checked GCC behavior and it is less strict. For the example below, it 
> silently accepts the interrupt attribute.
> 
> extern int foo2();
> __attribute__((interrupt)) void foo();
> void foo() {
>   foo2();
> }
> 
> while in LLVM we would be rejecting with the message: 
> RISC-V 'interrupt' attribute only applies to functions that have no 
> parameters. 
> 
> I find the reuse of the message confusing. 
> 
> If we want stricter rule then we probably also need a specific message for 
> the  missing prototype.
> 
> I checked GCC behavior and it is less strict. For the example below, it 
> silently accepts the interrupt attribute.

Does it drop the attribute?

> If we want stricter rule then we probably also need a specific message for 
> the missing prototype.

If GCC silently drops the attribute in this case then we definitely want a more 
strict rule. We already have a good diagnostic for this: 
`warn_attribute_wrong_decl_type` with the expected type diagnostic index being 
`ExpectedFunctionWithProtoType`.


https://reviews.llvm.org/D48412



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


r336388 - [X86] Use shufflevector instead of a select with a constant mask for fmaddsub/fmsubadd IR emission.

2018-07-05 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Thu Jul  5 13:38:31 2018
New Revision: 336388

URL: http://llvm.org/viewvc/llvm-project?rev=336388=rev
Log:
[X86] Use shufflevector instead of a select with a constant mask for 
fmaddsub/fmsubadd IR emission.

Shufflevector is easier to generate and matches what the backend pattern 
matches without relying on constant selects being turned into shuffles.

While I was there I also made the IR regular expressions a little stricter to 
ensure operand order on the shuffle.

Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGen/avx512f-builtins.c
cfe/trunk/test/CodeGen/avx512vl-builtins.c
cfe/trunk/test/CodeGen/fma-builtins.c
cfe/trunk/test/CodeGen/fma4-builtins.c

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=336388=336387=336388=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Jul  5 13:38:31 2018
@@ -8660,17 +8660,13 @@ static Value *EmitX86FMAExpr(CodeGenFunc
 if (IsAddSub) {
   // Negate even elts in C using a mask.
   unsigned NumElts = Ty->getVectorNumElements();
-  SmallVector NMask;
-  Constant *Zero = ConstantInt::get(CGF.Builder.getInt1Ty(), 0);
-  Constant *One = ConstantInt::get(CGF.Builder.getInt1Ty(), 1);
-  for (unsigned i = 0; i < NumElts; ++i) {
-NMask.push_back(i % 2 == 0 ? One : Zero);
-  }
-  Value *NegMask = ConstantVector::get(NMask);
+  SmallVector Indices(NumElts);
+  for (unsigned i = 0; i != NumElts; ++i)
+Indices[i] = i + (i % 2) * NumElts;
 
   Value *NegC = CGF.Builder.CreateFNeg(C);
   Value *FMSub = CGF.Builder.CreateCall(FMA, {A, B, NegC} );
-  Res = CGF.Builder.CreateSelect(NegMask, FMSub, Res);
+  Res = CGF.Builder.CreateShuffleVector(FMSub, Res, Indices);
 }
   }
 

Modified: cfe/trunk/test/CodeGen/avx512f-builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/avx512f-builtins.c?rev=336388=336387=336388=diff
==
--- cfe/trunk/test/CodeGen/avx512f-builtins.c (original)
+++ cfe/trunk/test/CodeGen/avx512f-builtins.c Thu Jul  5 13:38:31 2018
@@ -846,66 +846,66 @@ __m512d test_mm512_maskz_fmsubadd_round_
 }
 __m512d test_mm512_fmaddsub_pd(__m512d __A, __m512d __B, __m512d __C) {
   // CHECK-LABEL: @test_mm512_fmaddsub_pd
-  // CHECK: call <8 x double> @llvm.fma.v8f64(<8 x double> %{{.*}}, <8 x 
double> %{{.*}}, <8 x double> %{{.*}})
-  // CHECK: fsub <8 x double> , %{{.*}}
-  // CHECK: call <8 x double> @llvm.fma.v8f64(<8 x double> %{{.*}}, <8 x 
double> %{{.*}}, <8 x double> %{{.*}})
-  // CHECK: select <8 x i1> , <8 x double> %{{.*}}, <8 x double> %{{.*}}
+  // CHECK: [[ADD:%.+]] = call <8 x double> @llvm.fma.v8f64(<8 x double> 
%{{.*}}, <8 x double> %{{.*}}, <8 x double> %{{.*}})
+  // CHECK: [[NEG:%.+]] = fsub <8 x double> , %{{.*}}
+  // CHECK: [[SUB:%.+]] = call <8 x double> @llvm.fma.v8f64(<8 x double> 
%{{.*}}, <8 x double> %{{.*}}, <8 x double> [[NEG]]
+  // CHECK: shufflevector <8 x double> [[SUB]], <8 x double> [[ADD]], <8 x 
i32> 
   return _mm512_fmaddsub_pd(__A, __B, __C);
 }
 __m512d test_mm512_mask_fmaddsub_pd(__m512d __A, __mmask8 __U, __m512d __B, 
__m512d __C) {
   // CHECK-LABEL: @test_mm512_mask_fmaddsub_pd
-  // CHECK: call <8 x double> @llvm.fma.v8f64(<8 x double> %{{.*}}, <8 x 
double> %{{.*}}, <8 x double> %{{.*}})
-  // CHECK: fsub <8 x double> , %{{.*}}
-  // CHECK: call <8 x double> @llvm.fma.v8f64(<8 x double> %{{.*}}, <8 x 
double> %{{.*}}, <8 x double> %{{.*}})
-  // CHECK: select <8 x i1> , <8 x double> %{{.*}}, <8 x double> %{{.*}}
+  // CHECK: [[ADD:%.+]] = call <8 x double> @llvm.fma.v8f64(<8 x double> 
%{{.*}}, <8 x double> %{{.*}}, <8 x double> %{{.*}})
+  // CHECK: [[NEG:%.+]] = fsub <8 x double> , %{{.*}}
+  // CHECK: [[SUB:%.+]] = call <8 x double> @llvm.fma.v8f64(<8 x double> 
%{{.*}}, <8 x double> %{{.*}}, <8 x double> [[NEG]]
+  // CHECK: shufflevector <8 x double> [[SUB]], <8 x double> [[ADD]], <8 x 
i32> 
   // CHECK: bitcast i8 %{{.*}} to <8 x i1>
   // CHECK: select <8 x i1> %{{.*}}, <8 x double> %{{.*}}, <8 x double> %{{.*}}
   return _mm512_mask_fmaddsub_pd(__A, __U, __B, __C);
 }
 __m512d test_mm512_mask3_fmaddsub_pd(__m512d __A, __m512d __B, __m512d __C, 
__mmask8 __U) {
   // CHECK-LABEL: @test_mm512_mask3_fmaddsub_pd
-  // CHECK: call <8 x double> @llvm.fma.v8f64(<8 x double> %{{.*}}, <8 x 
double> %{{.*}}, <8 x double> %{{.*}})
-  // CHECK: fsub <8 x double> , %{{.*}}
-  // CHECK: call <8 x double> @llvm.fma.v8f64(<8 x double> %{{.*}}, <8 x 
double> %{{.*}}, <8 x double> %{{.*}})
-  // CHECK: select <8 x i1> , <8 x double> %{{.*}}, <8 x double> %{{.*}}
+  // CHECK: [[ADD:%.+]] = call <8 x double> @llvm.fma.v8f64(<8 x double> 
%{{.*}}, <8 x double> %{{.*}}, <8 x double> %{{.*}})
+  // CHECK: 

[PATCH] D48412: [RISCV] Add support for interrupt attribute

2018-07-05 Thread Ana Pazos via Phabricator via cfe-commits
apazos added inline comments.



Comment at: test/Sema/riscv-interrupt-attr.c:23
+  // expected-note 
{{repeated RISC-V 'interrupt' attribute is here}}
+__attribute__((interrupt("user"))) void foo8() {}
+__attribute__((interrupt("supervisor"))) void foo9() {}

aaron.ballman wrote:
> apazos wrote:
> > aaron.ballman wrote:
> > > aaron.ballman wrote:
> > > > Do you intend for functions without a prototype to be accepted? foo8() 
> > > > can be passed an arbitrary number of arguments, which is a bit 
> > > > different than what I thought you wanted the semantic check to be.
> > > This question remains outstanding.
> > The checks are validating both function definitions and function prototypes 
> > like these:
> > _attribute__((interrupt)) void foo1() {} 
> > __attribute__((interrupt)) void foo(void);
> > Not sure what the confusion is.
> Ah, now I see where the confusion is.
> 
> In C, an empty parameter list declares a function without a prototype; 
> functions without prototypes can accept any number of arguments. To declare a 
> function that accepts no arguments, you must have a prototype for the 
> function and the parameter list is void. In C++, all functions are prototyped 
> and an empty parameter list is equivalent to a parameter list of void. The 
> word "prototype" doesn't mean "forward declaration". e.g.,
> ```
> // C code
> void foo1(); // Declaration; no prototype; accepts any number of arguments.
> void foo2() {} // Definition; no prototype; accepts any number of arguments.
> void foo3(void); // Declaration; prototype; accepts no arguments.
> void foo4(void) {} // Definition; prototype; accepts no arguments.
> 
> foo2(1, 2, 3); // ok
> foo4(1, 2, 3); // error
> ```
> Because a function without a prototype can accept any number of arguments, I 
> think you want to diagnose such a function signature.
Thanks for clarifying. 

I checked GCC behavior and it is less strict. For the example below, it 
silently accepts the interrupt attribute.

extern int foo2();
__attribute__((interrupt)) void foo();
void foo() {
  foo2();
}

while in LLVM we would be rejecting with the message: 
RISC-V 'interrupt' attribute only applies to functions that have no parameters. 

I find the reuse of the message confusing. 

If we want stricter rule then we probably also need a specific message for the  
missing prototype.



https://reviews.llvm.org/D48412



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


[PATCH] D48852: [Sema] -Wformat-pedantic only for NSInteger/NSUInteger %tu/%td on Darwin

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

In https://reviews.llvm.org/D48852#1153598, @arphaman wrote:

> In https://reviews.llvm.org/D48852#1153415, @aaron.ballman wrote:
>
> > > This is acceptable because Darwin guarantees that, despite the watchOS 
> > > ABI differences, sizeof(ptrdiff_t) == sizeof(NS[U]Integer)
> >
> > Can you describe these ABI differences please? Also, does Darwin guarantee 
> > that alignof(ptrdiff_t) == alignof(NS[U]Integer)?
>
>
> The ABI difference boils down to the following:
>
> Regular 32-bit Darwin targets (like armv7) use 'ptrdiff_t' of type 'int', 
> which matches 'NSInteger'.
>  WatchOS arm iOS target (armv7k) uses 'ptrdiff_t' of type 'long', which 
> doesn't match 'NSInteger' of type 'int'.


Thank you for the explanation, I appreciate it.


https://reviews.llvm.org/D48852



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


[PATCH] D48852: [Sema] -Wformat-pedantic only for NSInteger/NSUInteger %tu/%td on Darwin

2018-07-05 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 154294.
arphaman marked an inline comment as done.
arphaman added a comment.

Address review comments.


https://reviews.llvm.org/D48852

Files:
  include/clang/Analysis/Analyses/FormatString.h
  lib/Analysis/PrintfFormatString.cpp
  lib/Sema/SemaChecking.cpp
  test/SemaObjC/format-size-spec-nsinteger.m

Index: test/SemaObjC/format-size-spec-nsinteger.m
===
--- test/SemaObjC/format-size-spec-nsinteger.m
+++ test/SemaObjC/format-size-spec-nsinteger.m
@@ -1,16 +1,25 @@
 // RUN: %clang_cc1 -triple thumbv7-apple-ios -Wno-objc-root-class -fsyntax-only -verify -Wformat %s
 // RUN: %clang_cc1 -triple thumbv7-apple-ios -Wno-objc-root-class -fsyntax-only -verify -Wformat-pedantic -DPEDANTIC %s
+// RUN: %clang_cc1 -triple thumbv7k-apple-watchos2.0.0 -fsyntax-only -fblocks -verify %s
+// RUN: %clang_cc1 -triple thumbv7k-apple-watchos2.0.0 -fsyntax-only -fblocks -verify -Wformat-pedantic -DPEDANTIC %s
 
 #if !defined(PEDANTIC)
 // expected-no-diagnostics
 #endif
 
 #if __LP64__
 typedef unsigned long NSUInteger;
 typedef long NSInteger;
+typedef long ptrdiff_t;
 #else
 typedef unsigned int NSUInteger;
 typedef int NSInteger;
+#if __is_target_os(watchos)
+  // Watch ABI uses long for ptrdiff_t.
+  typedef long ptrdiff_t;
+#else
+  typedef int ptrdiff_t;
+#endif
 #endif
 
 @class NSString;
@@ -28,3 +37,16 @@
   // expected-warning@-4 {{values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead}}
 #endif
 }
+
+void testPtrdiffSpecifier(ptrdiff_t x) {
+  NSInteger i = 0;
+  NSUInteger j = 0;
+
+  NSLog(@"ptrdiff_t NSUinteger: %tu", j);
+  NSLog(@"ptrdiff_t NSInteger: %td", i);
+  NSLog(@"ptrdiff_t %tu, %td", x, x);
+#if __is_target_os(watchos) && defined(PEDANTIC)
+  // expected-warning@-4 {{values of type 'NSUInteger' should not be used as format arguments; add an explicit cast to 'unsigned long' instead}}
+  // expected-warning@-4 {{values of type 'NSInteger' should not be used as format arguments; add an explicit cast to 'long' instead}}
+#endif
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -6894,10 +6894,11 @@
 QualType CastTy;
 std::tie(CastTy, CastTyName) = shouldNotPrintDirectly(S.Context, IntendedTy, E);
 if (!CastTy.isNull()) {
-  // %zi/%zu are OK to use for NSInteger/NSUInteger of type int
+  // %zi/%zu and %td/%tu are OK to use for NSInteger/NSUInteger of type int
   // (long in ASTContext). Only complain to pedants.
   if ((CastTyName == "NSInteger" || CastTyName == "NSUInteger") &&
-  AT.isSizeT() && AT.matchesType(S.Context, CastTy))
+  (AT.isSizeT() || AT.isPtrdiffT()) &&
+  AT.matchesType(S.Context, CastTy))
 Pedantic = true;
   IntendedTy = CastTy;
   ShouldNotPrintDirectly = true;
Index: lib/Analysis/PrintfFormatString.cpp
===
--- lib/Analysis/PrintfFormatString.cpp
+++ lib/Analysis/PrintfFormatString.cpp
@@ -472,7 +472,8 @@
? ArgType(Ctx.LongLongTy, "__int64")
: ArgType(Ctx.IntTy, "__int32");
   case LengthModifier::AsPtrDiff:
-return ArgType(Ctx.getPointerDiffType(), "ptrdiff_t");
+return ArgType::makePtrdiffT(
+ArgType(Ctx.getPointerDiffType(), "ptrdiff_t"));
   case LengthModifier::AsAllocate:
   case LengthModifier::AsMAllocate:
   case LengthModifier::AsWide:
@@ -505,7 +506,8 @@
? ArgType(Ctx.UnsignedLongLongTy, "unsigned __int64")
: ArgType(Ctx.UnsignedIntTy, "unsigned __int32");
   case LengthModifier::AsPtrDiff:
-return ArgType(Ctx.getUnsignedPointerDiffType(), "unsigned ptrdiff_t");
+return ArgType::makePtrdiffT(
+ArgType(Ctx.getUnsignedPointerDiffType(), "unsigned ptrdiff_t"));
   case LengthModifier::AsAllocate:
   case LengthModifier::AsMAllocate:
   case LengthModifier::AsWide:
Index: include/clang/Analysis/Analyses/FormatString.h
===
--- include/clang/Analysis/Analyses/FormatString.h
+++ include/clang/Analysis/Analyses/FormatString.h
@@ -257,7 +257,12 @@
   const Kind K;
   QualType T;
   const char *Name = nullptr;
-  bool Ptr = false, IsSizeT = false;
+  bool Ptr = false;
+
+  /// The TypeKind identifies certain well-known types like size_t and
+  /// ptrdiff_t.
+  enum class TypeKind { DontCare, SizeT, PtrdiffT };
+  TypeKind TK = TypeKind::DontCare;
 
 public:
   ArgType(Kind K = UnknownTy, const char *N = nullptr) : K(K), Name(N) {}
@@ -267,7 +272,9 @@
   static ArgType Invalid() { return ArgType(InvalidTy); }
   bool isValid() const { return K != InvalidTy; }
 
-  bool isSizeT() const { return IsSizeT; }
+  bool isSizeT() const { return TK == 

[PATCH] D48852: [Sema] -Wformat-pedantic only for NSInteger/NSUInteger %tu/%td on Darwin

2018-07-05 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman marked an inline comment as done.
arphaman added a comment.

In https://reviews.llvm.org/D48852#1153415, @aaron.ballman wrote:

> > This is acceptable because Darwin guarantees that, despite the watchOS ABI 
> > differences, sizeof(ptrdiff_t) == sizeof(NS[U]Integer)
>
> Can you describe these ABI differences please? Also, does Darwin guarantee 
> that alignof(ptrdiff_t) == alignof(NS[U]Integer)?


The ABI difference boils down to the following:

Regular 32-bit Darwin targets (like armv7) use 'ptrdiff_t' of type 'int', which 
matches 'NSInteger'.
WatchOS arm iOS target (armv7k) uses 'ptrdiff_t' of type 'long', which doesn't 
match 'NSInteger' of type 'int'.

> Also, does Darwin guarantee that alignof(ptrdiff_t) == alignof(NS[U]Integer)?

Yes.




Comment at: include/clang/Analysis/Analyses/FormatString.h:265
+  enum class TypeKind { Unspecified, SizeT, PtrdiffT };
+  TypeKind TK = TypeKind::Unspecified;
 

jfb wrote:
> "unspecified" seems odd because it *is* specified, we just don't care. How 
> about something like "NothingSpecial" or "DontCare"?
Thanks. Changed to "DontCare".



Comment at: test/SemaObjC/format-size-spec-nsinteger.m:4
+// RUN: %clang_cc1 -triple thumbv7k-apple-watchos2.0.0 -fsyntax-only -fblocks 
-verify %s
+// RUN: %clang_cc1 -triple thumbv7k-apple-watchos2.0.0 -fsyntax-only -fblocks 
-verify -Wformat-pedantic -DPEDANTIC %s
 

jfb wrote:
> We use a bunch of different triples to test WatchOS:
> 
>5 thumbv7k-apple-watchos2.0
>3 i386-apple-watchos4
>2 x86_64-apple-watchos
>2 thumbv7k-apple-watchos
>2 armv7k-apple-watchos3.0.0
>2 armv7k-apple-watchos2.0
>2 armv7k-apple-watchos
>1 x86_64-apple-watchos-simulator
>1 thumbv7k-apple-watchos1.0
>1 i686-apple-watchos
>1 i386-apple-watchos3.0-simulator
>1 i386-apple-watchos3
>1 i386-apple-watchos2.1
>1 i386-apple-watchos2.0-simulator
>1 i386-apple-watchos2.0
>1 i386-apple-watchos-simulator
>1 i386-apple-watchos
>1 armv7k-apple-watchos2.1
>1 armv7-apple-watchos
>1 arm64-apple-watchos
>1 aarch64-apple-watchos
> 
> Do we care about v7k only for this test?
Yes.
armv7k is used to generate thumbv7k .
i386 is used by simulator, and doesn't have this ABI issue.
We don't support other arches for watches.


Repository:
  rC Clang

https://reviews.llvm.org/D48852



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


[PATCH] D47846: [clangd] Implementation of textDocument/documentSymbol

2018-07-05 Thread Marc-Andre Laperle via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL336386: [clangd] Implementation of 
textDocument/documentSymbol (authored by malaperle, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D47846

Files:
  clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
  clang-tools-extra/trunk/clangd/ClangdLSPServer.h
  clang-tools-extra/trunk/clangd/ClangdServer.cpp
  clang-tools-extra/trunk/clangd/ClangdServer.h
  clang-tools-extra/trunk/clangd/FindSymbols.cpp
  clang-tools-extra/trunk/clangd/FindSymbols.h
  clang-tools-extra/trunk/clangd/Protocol.cpp
  clang-tools-extra/trunk/clangd/Protocol.h
  clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
  clang-tools-extra/trunk/clangd/ProtocolHandlers.h
  clang-tools-extra/trunk/clangd/SourceCode.cpp
  clang-tools-extra/trunk/clangd/SourceCode.h
  clang-tools-extra/trunk/clangd/XRefs.cpp
  clang-tools-extra/trunk/test/clangd/initialize-params-invalid.test
  clang-tools-extra/trunk/test/clangd/initialize-params.test
  clang-tools-extra/trunk/test/clangd/symbols.test
  clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp
  clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp
  clang-tools-extra/trunk/unittests/clangd/SyncAPI.h

Index: clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp
+++ clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp
@@ -117,5 +117,12 @@
   return std::move(*Result);
 }
 
+llvm::Expected>
+runDocumentSymbols(ClangdServer , PathRef File) {
+  llvm::Optional>> Result;
+  Server.documentSymbols(File, capture(Result));
+  return std::move(*Result);
+}
+
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp
@@ -22,6 +22,7 @@
 using ::testing::AllOf;
 using ::testing::AnyOf;
 using ::testing::ElementsAre;
+using ::testing::ElementsAreArray;
 using ::testing::IsEmpty;
 using ::testing::UnorderedElementsAre;
 
@@ -37,6 +38,7 @@
   return (arg.containerName + "::" + arg.name) == Name;
 }
 MATCHER_P(WithKind, Kind, "") { return arg.kind == Kind; }
+MATCHER_P(SymRange, Range, "") { return arg.location.range == Range; }
 
 ClangdServer::Options optsForTests() {
   auto ServerOpts = ClangdServer::optsForTest();
@@ -287,5 +289,274 @@
   EXPECT_THAT(getSymbols("foo"), ElementsAre(QName("foo")));
 }
 
+namespace {
+class DocumentSymbolsTest : public ::testing::Test {
+public:
+  DocumentSymbolsTest()
+  : Server(CDB, FSProvider, DiagConsumer, optsForTests()) {}
+
+protected:
+  MockFSProvider FSProvider;
+  MockCompilationDatabase CDB;
+  IgnoreDiagnostics DiagConsumer;
+  ClangdServer Server;
+
+  std::vector getSymbols(PathRef File) {
+EXPECT_TRUE(Server.blockUntilIdleForTest()) << "Waiting for preamble";
+auto SymbolInfos = runDocumentSymbols(Server, File);
+EXPECT_TRUE(bool(SymbolInfos)) << "documentSymbols returned an error";
+return *SymbolInfos;
+  }
+
+  void addFile(StringRef FilePath, StringRef Contents) {
+FSProvider.Files[FilePath] = Contents;
+Server.addDocument(FilePath, Contents);
+  }
+};
+} // namespace
+
+TEST_F(DocumentSymbolsTest, BasicSymbols) {
+  std::string FilePath = testPath("foo.cpp");
+  Annotations Main(R"(
+  class Foo;
+  class Foo {
+Foo() {}
+Foo(int a) {}
+void $decl[[f]]();
+friend void f1();
+friend class Friend;
+Foo& operator=(const Foo&);
+~Foo();
+class Nested {
+void f();
+};
+  };
+  class Friend {
+  };
+
+  void f1();
+  inline void f2() {}
+  static const int KInt = 2;
+  const char* kStr = "123";
+
+  void f1() {}
+
+  namespace foo {
+  // Type alias
+  typedef int int32;
+  using int32_t = int32;
+
+  // Variable
+  int v1;
+
+  // Namespace
+  namespace bar {
+  int v2;
+  }
+  // Namespace alias
+  namespace baz = bar;
+
+  // FIXME: using declaration is not supported as the IndexAction will ignore
+  // implicit declarations (the implicit using shadow declaration) by default,
+  // and there is no way to customize this behavior at the moment.
+  using bar::v2;
+  } // namespace foo
+)");
+
+  addFile(FilePath, Main.code());
+  EXPECT_THAT(getSymbols(FilePath),
+  ElementsAreArray(
+  {AllOf(QName("Foo"), WithKind(SymbolKind::Class)),
+   AllOf(QName("Foo"), WithKind(SymbolKind::Class)),
+   AllOf(QName("Foo::Foo"), WithKind(SymbolKind::Method)),
+   AllOf(QName("Foo::Foo"), WithKind(SymbolKind::Method)),
+   

[clang-tools-extra] r336386 - [clangd] Implementation of textDocument/documentSymbol

2018-07-05 Thread Marc-Andre Laperle via cfe-commits
Author: malaperle
Date: Thu Jul  5 12:35:01 2018
New Revision: 336386

URL: http://llvm.org/viewvc/llvm-project?rev=336386=rev
Log:
[clangd] Implementation of textDocument/documentSymbol

Summary:
An AST-based approach is used to retrieve the document symbols rather than an
in-memory index query. The index is not an ideal fit to achieve this because of
the file-centric query being done here whereas the index is suited for
project-wide queries. Document symbols also includes more symbols and need to
keep the order as seen in the file.

Signed-off-by: Marc-Andre Laperle 

Subscribers: tomgr, ilya-biryukov, ioeric, MaskRay, jkorous, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/FindSymbols.cpp
clang-tools-extra/trunk/clangd/FindSymbols.h
clang-tools-extra/trunk/clangd/Protocol.cpp
clang-tools-extra/trunk/clangd/Protocol.h
clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
clang-tools-extra/trunk/clangd/ProtocolHandlers.h
clang-tools-extra/trunk/clangd/SourceCode.cpp
clang-tools-extra/trunk/clangd/SourceCode.h
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/test/clangd/initialize-params-invalid.test
clang-tools-extra/trunk/test/clangd/initialize-params.test
clang-tools-extra/trunk/test/clangd/symbols.test
clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp
clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp
clang-tools-extra/trunk/unittests/clangd/SyncAPI.h

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=336386=336385=336386=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Thu Jul  5 12:35:01 2018
@@ -112,6 +112,7 @@ void ClangdLSPServer::onInitialize(Initi
 {"documentHighlightProvider", true},
 {"hoverProvider", true},
 {"renameProvider", true},
+{"documentSymbolProvider", true},
 {"workspaceSymbolProvider", true},
 {"executeCommandProvider",
  json::obj{
@@ -294,6 +295,19 @@ void ClangdLSPServer::onDocumentFormatti
llvm::toString(ReplacementsOrError.takeError()));
 }
 
+void ClangdLSPServer::onDocumentSymbol(DocumentSymbolParams ) {
+  Server.documentSymbols(
+  Params.textDocument.uri.file(),
+  [this](llvm::Expected> Items) {
+if (!Items)
+  return replyError(ErrorCode::InvalidParams,
+llvm::toString(Items.takeError()));
+for (auto  : *Items)
+  Sym.kind = adjustKindToCapability(Sym.kind, SupportedSymbolKinds);
+reply(json::ary(*Items));
+  });
+}
+
 void ClangdLSPServer::onCodeAction(CodeActionParams ) {
   // We provide a code action for each diagnostic at the requested location
   // which has FixIts available.

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.h?rev=336386=336385=336386=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.h Thu Jul  5 12:35:01 2018
@@ -62,6 +62,7 @@ private:
   void
   onDocumentRangeFormatting(DocumentRangeFormattingParams ) override;
   void onDocumentFormatting(DocumentFormattingParams ) override;
+  void onDocumentSymbol(DocumentSymbolParams ) override;
   void onCodeAction(CodeActionParams ) override;
   void onCompletion(TextDocumentPositionParams ) override;
   void onSignatureHelp(TextDocumentPositionParams ) override;

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=336386=336385=336386=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Thu Jul  5 12:35:01 2018
@@ -456,6 +456,18 @@ void ClangdServer::workspaceSymbols(
  RootPath ? *RootPath : ""));
 }
 
+void ClangdServer::documentSymbols(
+StringRef File, Callback> CB) {
+  auto Action = [](Callback> CB,
+   llvm::Expected InpAST) {
+if (!InpAST)
+  return CB(InpAST.takeError());
+CB(clangd::getDocumentSymbols(InpAST->AST));
+  };
+  WorkScheduler.runWithAST("documentSymbols", File,
+   Bind(Action, std::move(CB)));
+}
+
 std::vector>
 

[PATCH] D48989: -fdebug-prefix-map option for cc1as

2018-07-05 Thread Siddhartha Bagaria via Phabricator via cfe-commits
starsid updated this revision to Diff 154285.
starsid added a comment.

include generator input file for flag property change


Repository:
  rC Clang

https://reviews.llvm.org/D48989

Files:
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/Clang.cpp
  tools/driver/cc1as_main.cpp


Index: tools/driver/cc1as_main.cpp
===
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -94,6 +94,7 @@
   std::string DwarfDebugFlags;
   std::string DwarfDebugProducer;
   std::string DebugCompilationDir;
+  std::map DebugPrefixMap;
   llvm::DebugCompressionType CompressDebugSections =
   llvm::DebugCompressionType::None;
   std::string MainFileName;
@@ -233,6 +234,9 @@
   Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir);
   Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name);
 
+  for (const auto  : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ))
+Opts.DebugPrefixMap.insert(StringRef(Arg).split('='));
+
   // Frontend Options
   if (Args.hasArg(OPT_INPUT)) {
 bool First = true;
@@ -377,6 +381,9 @@
 Ctx.setDwarfDebugProducer(StringRef(Opts.DwarfDebugProducer));
   if (!Opts.DebugCompilationDir.empty())
 Ctx.setCompilationDir(Opts.DebugCompilationDir);
+  if (!Opts.DebugPrefixMap.empty())
+for (const auto  : Opts.DebugPrefixMap)
+  Ctx.addDebugPrefixMapEntry(KV.first, KV.second);
   if (!Opts.MainFileName.empty())
 Ctx.setMainFileName(StringRef(Opts.MainFileName));
   Ctx.setDwarfVersion(Opts.DwarfVersion);
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -600,6 +600,18 @@
   }
 }
 
+/// Add a CC1 and CC1AS option to specify the debug file path prefix map.
+static void addDebugPrefixMapArg(const Driver& D, const ArgList , 
ArgStringList ) {
+  for (const Arg *A : Args.filtered(options::OPT_fdebug_prefix_map_EQ)) {
+StringRef Map = A->getValue();
+if (Map.find('=') == StringRef::npos)
+  D.Diag(diag::err_drv_invalid_argument_to_fdebug_prefix_map) << Map;
+else
+  CmdArgs.push_back(Args.MakeArgString("-fdebug-prefix-map=" + Map));
+A->claim();
+  }
+}
+
 /// Vectorize at all optimization levels greater than 1 except for -Oz.
 /// For -Oz the loop vectorizer is disable, while the slp vectorizer is 
enabled.
 static bool shouldEnableVectorizerAtOLevel(const ArgList , bool isSlpVec) 
{
@@ -3849,14 +3861,7 @@
   // Add in -fdebug-compilation-dir if necessary.
   addDebugCompDirArg(Args, CmdArgs);
 
-  for (const Arg *A : Args.filtered(options::OPT_fdebug_prefix_map_EQ)) {
-StringRef Map = A->getValue();
-if (Map.find('=') == StringRef::npos)
-  D.Diag(diag::err_drv_invalid_argument_to_fdebug_prefix_map) << Map;
-else
-  CmdArgs.push_back(Args.MakeArgString("-fdebug-prefix-map=" + Map));
-A->claim();
-  }
+  addDebugPrefixMapArg(D, Args, CmdArgs);
 
   if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_,
options::OPT_ftemplate_depth_EQ)) {
@@ -5409,6 +5414,8 @@
 // Add the -fdebug-compilation-dir flag if needed.
 addDebugCompDirArg(Args, CmdArgs);
 
+addDebugPrefixMapArg(getToolChain().getDriver(), Args, CmdArgs);
+
 // Set the AT_producer to the clang version when using the integrated
 // assembler on assembly source files.
 CmdArgs.push_back("-dwarf-debug-producer");
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1740,7 +1740,8 @@
 def fno_split_dwarf_inlining: Flag<["-"], "fno-split-dwarf-inlining">, 
Group,
   Flags<[CC1Option]>;
 def fdebug_prefix_map_EQ
-  : Joined<["-"], "fdebug-prefix-map=">, Group, Flags<[CC1Option]>,
+  : Joined<["-"], "fdebug-prefix-map=">, Group,
+Flags<[CC1Option,CC1AsOption]>,
 HelpText<"remap file source paths in debug info">;
 def g_Flag : Flag<["-"], "g">, Group,
   HelpText<"Generate source-level debug information">;


Index: tools/driver/cc1as_main.cpp
===
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -94,6 +94,7 @@
   std::string DwarfDebugFlags;
   std::string DwarfDebugProducer;
   std::string DebugCompilationDir;
+  std::map DebugPrefixMap;
   llvm::DebugCompressionType CompressDebugSections =
   llvm::DebugCompressionType::None;
   std::string MainFileName;
@@ -233,6 +234,9 @@
   Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir);
   Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name);
 
+  for (const auto  : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ))
+Opts.DebugPrefixMap.insert(StringRef(Arg).split('='));
+
   // Frontend Options
   if (Args.hasArg(OPT_INPUT)) {
 bool First = true;
@@ -377,6 +381,9 @@
 

[PATCH] D48989: -fdebug-prefix-map option for cc1as

2018-07-05 Thread Siddhartha Bagaria via Phabricator via cfe-commits
starsid created this revision.
starsid added a reviewer: compnerd.
Herald added a subscriber: cfe-commits.

Depends on https://reviews.llvm.org/D48988.


Repository:
  rC Clang

https://reviews.llvm.org/D48989

Files:
  lib/Driver/ToolChains/Clang.cpp
  tools/driver/cc1as_main.cpp


Index: tools/driver/cc1as_main.cpp
===
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -94,6 +94,7 @@
   std::string DwarfDebugFlags;
   std::string DwarfDebugProducer;
   std::string DebugCompilationDir;
+  std::map DebugPrefixMap;
   llvm::DebugCompressionType CompressDebugSections =
   llvm::DebugCompressionType::None;
   std::string MainFileName;
@@ -233,6 +234,9 @@
   Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir);
   Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name);
 
+  for (const auto  : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ))
+Opts.DebugPrefixMap.insert(StringRef(Arg).split('='));
+
   // Frontend Options
   if (Args.hasArg(OPT_INPUT)) {
 bool First = true;
@@ -377,6 +381,9 @@
 Ctx.setDwarfDebugProducer(StringRef(Opts.DwarfDebugProducer));
   if (!Opts.DebugCompilationDir.empty())
 Ctx.setCompilationDir(Opts.DebugCompilationDir);
+  if (!Opts.DebugPrefixMap.empty())
+for (const auto  : Opts.DebugPrefixMap)
+  Ctx.addDebugPrefixMapEntry(KV.first, KV.second);
   if (!Opts.MainFileName.empty())
 Ctx.setMainFileName(StringRef(Opts.MainFileName));
   Ctx.setDwarfVersion(Opts.DwarfVersion);
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -600,6 +600,18 @@
   }
 }
 
+/// Add a CC1 and CC1AS option to specify the debug file path prefix map.
+static void addDebugPrefixMapArg(const Driver& D, const ArgList , 
ArgStringList ) {
+  for (const Arg *A : Args.filtered(options::OPT_fdebug_prefix_map_EQ)) {
+StringRef Map = A->getValue();
+if (Map.find('=') == StringRef::npos)
+  D.Diag(diag::err_drv_invalid_argument_to_fdebug_prefix_map) << Map;
+else
+  CmdArgs.push_back(Args.MakeArgString("-fdebug-prefix-map=" + Map));
+A->claim();
+  }
+}
+
 /// Vectorize at all optimization levels greater than 1 except for -Oz.
 /// For -Oz the loop vectorizer is disable, while the slp vectorizer is 
enabled.
 static bool shouldEnableVectorizerAtOLevel(const ArgList , bool isSlpVec) 
{
@@ -3849,14 +3861,7 @@
   // Add in -fdebug-compilation-dir if necessary.
   addDebugCompDirArg(Args, CmdArgs);
 
-  for (const Arg *A : Args.filtered(options::OPT_fdebug_prefix_map_EQ)) {
-StringRef Map = A->getValue();
-if (Map.find('=') == StringRef::npos)
-  D.Diag(diag::err_drv_invalid_argument_to_fdebug_prefix_map) << Map;
-else
-  CmdArgs.push_back(Args.MakeArgString("-fdebug-prefix-map=" + Map));
-A->claim();
-  }
+  addDebugPrefixMapArg(D, Args, CmdArgs);
 
   if (Arg *A = Args.getLastArg(options::OPT_ftemplate_depth_,
options::OPT_ftemplate_depth_EQ)) {
@@ -5409,6 +5414,8 @@
 // Add the -fdebug-compilation-dir flag if needed.
 addDebugCompDirArg(Args, CmdArgs);
 
+addDebugPrefixMapArg(getToolChain().getDriver(), Args, CmdArgs);
+
 // Set the AT_producer to the clang version when using the integrated
 // assembler on assembly source files.
 CmdArgs.push_back("-dwarf-debug-producer");


Index: tools/driver/cc1as_main.cpp
===
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -94,6 +94,7 @@
   std::string DwarfDebugFlags;
   std::string DwarfDebugProducer;
   std::string DebugCompilationDir;
+  std::map DebugPrefixMap;
   llvm::DebugCompressionType CompressDebugSections =
   llvm::DebugCompressionType::None;
   std::string MainFileName;
@@ -233,6 +234,9 @@
   Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir);
   Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name);
 
+  for (const auto  : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ))
+Opts.DebugPrefixMap.insert(StringRef(Arg).split('='));
+
   // Frontend Options
   if (Args.hasArg(OPT_INPUT)) {
 bool First = true;
@@ -377,6 +381,9 @@
 Ctx.setDwarfDebugProducer(StringRef(Opts.DwarfDebugProducer));
   if (!Opts.DebugCompilationDir.empty())
 Ctx.setCompilationDir(Opts.DebugCompilationDir);
+  if (!Opts.DebugPrefixMap.empty())
+for (const auto  : Opts.DebugPrefixMap)
+  Ctx.addDebugPrefixMapEntry(KV.first, KV.second);
   if (!Opts.MainFileName.empty())
 Ctx.setMainFileName(StringRef(Opts.MainFileName));
   Ctx.setDwarfVersion(Opts.DwarfVersion);
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -600,6 +600,18 @@
   }
 }
 
+/// Add a CC1 and 

[PATCH] D48341: [clang-doc] Adding a second reduce pass

2018-07-05 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

Thanks for the refactoring and the comments! They made it a lot easier to 
understand the changes.

I'm focusing on how the changes would fit into the `ToolExecutor` framework in 
the review and will leave tool-specific logics to another reviewer who I assume 
would know the tool better than me :)




Comment at: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp:121
 llvm::Expected>
 getPath(StringRef Root, StringRef Ext, StringRef Name,
 llvm::SmallVectorImpl ) {

ioeric wrote:
> This deserves a comment. It's hard to tell what this does without looking at 
> the implementation. 
So it would probably be clearer to call this `getInfoOutputFile`?

Given how path is created, it might make more sense if the parameter order is 
`(Root, Namespaces, Name, Ext)` 



Comment at: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp:124
+//
+// Example: Given the below, the yaml path for class C will be 
/A/B/C.yaml
+//

nit: s/yaml//?



Comment at: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp:160
 
+void addToInfoPassOutput(
+StringRef Key, std::unique_ptr &,

Now that this only has one call site, it might be clearer to just inline this.



Comment at: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp:167
+
+bool mapResultsInMemory(
+tooling::ToolResults ,

`mapResultsInMemory` doesn't seem to describe what this does. Maybe 
`bitcodeResultsToInfos`? Please also add comment.



Comment at: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp:238
+  llvm::outs() << "Collecting infos...\n";
+  llvm::StringMap>> MapOutput;
+  if (mapResultsInMemory(*Exec->get()->getToolResults(), MapOutput))

nit: maybe `USRToInfos`?



Comment at: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp:244
+  llvm::outs() << "Reducing " << MapOutput.size() << " infos by name...\n";
+  tooling::InMemoryToolResults ReduceResults;
   for (auto  : MapOutput) {

The `ToolResults` abstraction is intended to be used by `ToolExecutor` 
framework only. It seems that what you want is just a `StringMap`?



Comment at: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp:262
 
+// Prepare for second reduce pass by re-mapping infos by enclosing scope.
+if (auto Error =

If what we want is a mapping from enclosing scope to infos, wouldn't it be 
easier if we make the mapper (the `ToolAction` in `execute`) collect 
`Scope->Infos` (instead of `USR`->`Infos`) in the first place?  



Comment at: clang-tools-extra/clang-doc/tool/ClangDocMain.cpp:276
+
+  // Second reducing phase (by scope) and docs generation phase
+  // This pass reduces the re-mapped infos by enclosing scope, meaning that all

Is there any reason why this needs to be a separate reduce pass? It seems that 
it should be possible to merge two reduce passes e.g. by making `mergeInfos` 
incremental. Having two reduce passes would diverge further from the potential 
MapReduce execution.



Comment at: clang-tools-extra/test/clang-doc/yaml-comments.cpp:30
+// CHECK: ---  
+// CHECK-NEXT: USR: 
'{{[0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z][0-9A-Z]}}'
+// CHECK-NEXT: ChildFunctions:  

Hmm, is this the same as `[0-9A-Z]{n}` ?


https://reviews.llvm.org/D48341



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


[PATCH] D47846: [clangd] Implementation of textDocument/documentSymbol

2018-07-05 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added a comment.

Thanks a lot for the great comments (as always)!


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47846



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


[PATCH] D47846: [clangd] Implementation of textDocument/documentSymbol

2018-07-05 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle updated this revision to Diff 154280.
malaperle marked 7 inline comments as done.
malaperle added a comment.

Address comments.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47846

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/FindSymbols.cpp
  clangd/FindSymbols.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/ProtocolHandlers.cpp
  clangd/ProtocolHandlers.h
  clangd/SourceCode.cpp
  clangd/SourceCode.h
  clangd/XRefs.cpp
  test/clangd/initialize-params-invalid.test
  test/clangd/initialize-params.test
  test/clangd/symbols.test
  unittests/clangd/FindSymbolsTests.cpp
  unittests/clangd/SyncAPI.cpp
  unittests/clangd/SyncAPI.h

Index: unittests/clangd/SyncAPI.h
===
--- unittests/clangd/SyncAPI.h
+++ unittests/clangd/SyncAPI.h
@@ -43,6 +43,9 @@
 llvm::Expected>
 runWorkspaceSymbols(ClangdServer , StringRef Query, int Limit);
 
+llvm::Expected>
+runDocumentSymbols(ClangdServer , PathRef File);
+
 } // namespace clangd
 } // namespace clang
 
Index: unittests/clangd/SyncAPI.cpp
===
--- unittests/clangd/SyncAPI.cpp
+++ unittests/clangd/SyncAPI.cpp
@@ -117,5 +117,12 @@
   return std::move(*Result);
 }
 
+llvm::Expected>
+runDocumentSymbols(ClangdServer , PathRef File) {
+  llvm::Optional>> Result;
+  Server.documentSymbols(File, capture(Result));
+  return std::move(*Result);
+}
+
 } // namespace clangd
 } // namespace clang
Index: unittests/clangd/FindSymbolsTests.cpp
===
--- unittests/clangd/FindSymbolsTests.cpp
+++ unittests/clangd/FindSymbolsTests.cpp
@@ -22,6 +22,7 @@
 using ::testing::AllOf;
 using ::testing::AnyOf;
 using ::testing::ElementsAre;
+using ::testing::ElementsAreArray;
 using ::testing::IsEmpty;
 using ::testing::UnorderedElementsAre;
 
@@ -37,6 +38,7 @@
   return (arg.containerName + "::" + arg.name) == Name;
 }
 MATCHER_P(WithKind, Kind, "") { return arg.kind == Kind; }
+MATCHER_P(SymRange, Range, "") { return arg.location.range == Range; }
 
 ClangdServer::Options optsForTests() {
   auto ServerOpts = ClangdServer::optsForTest();
@@ -287,5 +289,274 @@
   EXPECT_THAT(getSymbols("foo"), ElementsAre(QName("foo")));
 }
 
+namespace {
+class DocumentSymbolsTest : public ::testing::Test {
+public:
+  DocumentSymbolsTest()
+  : Server(CDB, FSProvider, DiagConsumer, optsForTests()) {}
+
+protected:
+  MockFSProvider FSProvider;
+  MockCompilationDatabase CDB;
+  IgnoreDiagnostics DiagConsumer;
+  ClangdServer Server;
+
+  std::vector getSymbols(PathRef File) {
+EXPECT_TRUE(Server.blockUntilIdleForTest()) << "Waiting for preamble";
+auto SymbolInfos = runDocumentSymbols(Server, File);
+EXPECT_TRUE(bool(SymbolInfos)) << "documentSymbols returned an error";
+return *SymbolInfos;
+  }
+
+  void addFile(StringRef FilePath, StringRef Contents) {
+FSProvider.Files[FilePath] = Contents;
+Server.addDocument(FilePath, Contents);
+  }
+};
+} // namespace
+
+TEST_F(DocumentSymbolsTest, BasicSymbols) {
+  std::string FilePath = testPath("foo.cpp");
+  Annotations Main(R"(
+  class Foo;
+  class Foo {
+Foo() {}
+Foo(int a) {}
+void $decl[[f]]();
+friend void f1();
+friend class Friend;
+Foo& operator=(const Foo&);
+~Foo();
+class Nested {
+void f();
+};
+  };
+  class Friend {
+  };
+
+  void f1();
+  inline void f2() {}
+  static const int KInt = 2;
+  const char* kStr = "123";
+
+  void f1() {}
+
+  namespace foo {
+  // Type alias
+  typedef int int32;
+  using int32_t = int32;
+
+  // Variable
+  int v1;
+
+  // Namespace
+  namespace bar {
+  int v2;
+  }
+  // Namespace alias
+  namespace baz = bar;
+
+  // FIXME: using declaration is not supported as the IndexAction will ignore
+  // implicit declarations (the implicit using shadow declaration) by default,
+  // and there is no way to customize this behavior at the moment.
+  using bar::v2;
+  } // namespace foo
+)");
+
+  addFile(FilePath, Main.code());
+  EXPECT_THAT(getSymbols(FilePath),
+  ElementsAreArray(
+  {AllOf(QName("Foo"), WithKind(SymbolKind::Class)),
+   AllOf(QName("Foo"), WithKind(SymbolKind::Class)),
+   AllOf(QName("Foo::Foo"), WithKind(SymbolKind::Method)),
+   AllOf(QName("Foo::Foo"), WithKind(SymbolKind::Method)),
+   AllOf(QName("Foo::f"), WithKind(SymbolKind::Method)),
+   AllOf(QName("f1"), WithKind(SymbolKind::Function)),
+   AllOf(QName("Foo::operator="), WithKind(SymbolKind::Method)),
+   AllOf(QName("Foo::~Foo"), WithKind(SymbolKind::Method)),
+   

Re: [PATCH] D48892: [libc++] Replace uses of _LIBCPP_ALWAYS_INLINE by _LIBCPP_INLINE_VISIBILITY

2018-07-05 Thread Davide Italiano via cfe-commits
On Thu, Jul 5, 2018 at 11:49 AM Davide Italiano via llvm-commits
 wrote:
>
> On Thu, Jul 5, 2018 at 11:37 AM Duncan P. N. Exon Smith via
> Phabricator  wrote:
> >
> > dexonsmith added a comment.
> >
> > In https://reviews.llvm.org/D48892#1153473, @davide wrote:
> >
> > > The lldb bot started failing very recently and the blamelist hints at 
> > > this change.
> > >
> > > http://green.lab.llvm.org/green/job/lldb-cmake//
> > >
> > > Can you please take a look?
> > >
> > > For your convenience, this is failing building LibCxx testcases with a 
> > > linker error:
> > >
> > >   Build Command Output:
> > >   Undefined symbols for architecture x86_64:
> > > "std::__1::__vector_base_common::__vector_base_common()", 
> > > referenced from:
> > > std::__1::__vector_base 
> > > >::__vector_base() in main.o
> > > std::__1::__vector_base > > std::__1::char_traits, std::__1::allocator >, 
> > > std::__1::allocator > > std::__1::char_traits, std::__1::allocator > > 
> > > >::__vector_base() in main.o
> > >   ld: symbol(s) not found for architecture x86_64
> > >   clang-7: error: linker command failed with exit code 1 (use -v to see 
> > > invocation)
> > >   make: *** [a.out] Error 1
> > >
> >
> >
> > Interesting.  The failing jobs all have things like this:
> >
> >   #include 
> >   #ifdef _LIBCPP_INLINE_VISIBILITY
> >   #undef _LIBCPP_INLINE_VISIBILITY
> >   #endif
> >   #define _LIBCPP_INLINE_VISIBILITY
> >   #include 
> >   #include 
> >
> > We should revert to green, but... why is LLDB doing that?
>
> FWIW, I don't think there's any really good reason for this. The
> original test was committed with this `VISIBILITY` dance but the
> commit message doesn't really contain any informations.
> I guess I'm going just to spin a build locally, see whether it sticks
> and remove the offending lines instead of reverting Louis commit.
>
> I'll follow up here.
>

Actually, never mind, I realized you just reverted this.

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


Re: [PATCH] D48892: [libc++] Replace uses of _LIBCPP_ALWAYS_INLINE by _LIBCPP_INLINE_VISIBILITY

2018-07-05 Thread Davide Italiano via cfe-commits
On Thu, Jul 5, 2018 at 11:37 AM Duncan P. N. Exon Smith via
Phabricator  wrote:
>
> dexonsmith added a comment.
>
> In https://reviews.llvm.org/D48892#1153473, @davide wrote:
>
> > The lldb bot started failing very recently and the blamelist hints at this 
> > change.
> >
> > http://green.lab.llvm.org/green/job/lldb-cmake//
> >
> > Can you please take a look?
> >
> > For your convenience, this is failing building LibCxx testcases with a 
> > linker error:
> >
> >   Build Command Output:
> >   Undefined symbols for architecture x86_64:
> > "std::__1::__vector_base_common::__vector_base_common()", 
> > referenced from:
> > std::__1::__vector_base 
> > >::__vector_base() in main.o
> > std::__1::__vector_base > std::__1::char_traits, std::__1::allocator >, 
> > std::__1::allocator > std::__1::char_traits, std::__1::allocator > > 
> > >::__vector_base() in main.o
> >   ld: symbol(s) not found for architecture x86_64
> >   clang-7: error: linker command failed with exit code 1 (use -v to see 
> > invocation)
> >   make: *** [a.out] Error 1
> >
>
>
> Interesting.  The failing jobs all have things like this:
>
>   #include 
>   #ifdef _LIBCPP_INLINE_VISIBILITY
>   #undef _LIBCPP_INLINE_VISIBILITY
>   #endif
>   #define _LIBCPP_INLINE_VISIBILITY
>   #include 
>   #include 
>
> We should revert to green, but... why is LLDB doing that?

FWIW, I don't think there's any really good reason for this. The
original test was committed with this `VISIBILITY` dance but the
commit message doesn't really contain any informations.
I guess I'm going just to spin a build locally, see whether it sticks
and remove the offending lines instead of reverting Louis commit.

I'll follow up here.

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


Re: [PATCH] D48892: [libc++] Replace uses of _LIBCPP_ALWAYS_INLINE by _LIBCPP_INLINE_VISIBILITY

2018-07-05 Thread Davide Italiano via cfe-commits
On Thu, Jul 5, 2018 at 11:46 AM Louis Dionne via Phabricator
 wrote:
>
> ldionne added a comment.
>
> I reverted this commit. Sorry for the blunder. I'll take a look at why LLDB's 
> tests are doing this.
>

No need to revert this immediately. I can probably take a look and fix
what the lldb tests are doing (and in case I can't, we can revert).
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48892: [libc++] Replace uses of _LIBCPP_ALWAYS_INLINE by _LIBCPP_INLINE_VISIBILITY

2018-07-05 Thread Louis Dionne via Phabricator via cfe-commits
ldionne added a comment.

I reverted this commit. Sorry for the blunder. I'll take a look at why LLDB's 
tests are doing this.


Repository:
  rCXX libc++

https://reviews.llvm.org/D48892



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


[libcxx] r336382 - Revert "[libc++] Replace uses of _LIBCPP_ALWAYS_INLINE by _LIBCPP_INLINE_VISIBILITY"

2018-07-05 Thread Louis Dionne via cfe-commits
Author: ldionne
Date: Thu Jul  5 11:41:50 2018
New Revision: 336382

URL: http://llvm.org/viewvc/llvm-project?rev=336382=rev
Log:
Revert "[libc++] Replace uses of _LIBCPP_ALWAYS_INLINE by 
_LIBCPP_INLINE_VISIBILITY"

This reverts commit r336369. The commit had two problems:
1. __pbump was marked as _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY instead of
   _LIBCPP_INLINE_VISIBILITY, which lead to two symbols being added in the
   dylib and the check-cxx-abilist failing.

2. The LLDB tests started failing because they undefine
   `_LIBCPP_INLINE_VISIBILITY`. I need to figure out why they do that and
   fix the tests before we can go forward with this change.

Modified:
libcxx/trunk/docs/DesignDocs/VisibilityMacros.rst
libcxx/trunk/include/__bsd_locale_fallbacks.h
libcxx/trunk/include/__config
libcxx/trunk/include/__locale
libcxx/trunk/include/__nullptr
libcxx/trunk/include/any
libcxx/trunk/include/cmath
libcxx/trunk/include/codecvt
libcxx/trunk/include/exception
libcxx/trunk/include/experimental/dynarray
libcxx/trunk/include/experimental/filesystem
libcxx/trunk/include/functional
libcxx/trunk/include/future
libcxx/trunk/include/initializer_list
libcxx/trunk/include/ios
libcxx/trunk/include/locale
libcxx/trunk/include/math.h
libcxx/trunk/include/memory
libcxx/trunk/include/new
libcxx/trunk/include/ostream
libcxx/trunk/include/regex
libcxx/trunk/include/stdexcept
libcxx/trunk/include/streambuf
libcxx/trunk/include/support/android/locale_bionic.h
libcxx/trunk/include/support/xlocale/__posix_l_fallback.h
libcxx/trunk/include/support/xlocale/__strtonum_fallback.h
libcxx/trunk/include/system_error
libcxx/trunk/include/typeinfo
libcxx/trunk/include/vector
libcxx/trunk/src/support/win32/thread_win32.cpp

Modified: libcxx/trunk/docs/DesignDocs/VisibilityMacros.rst
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/docs/DesignDocs/VisibilityMacros.rst?rev=336382=336381=336382=diff
==
--- libcxx/trunk/docs/DesignDocs/VisibilityMacros.rst (original)
+++ libcxx/trunk/docs/DesignDocs/VisibilityMacros.rst Thu Jul  5 11:41:50 2018
@@ -41,10 +41,10 @@ Visibility Macros
   library and has an empty definition otherwise.
 
 **_LIBCPP_INLINE_VISIBILITY**
-  Mark a function as not being part of the ABI of any final linked image that
-  uses it, and also as being internal to each TU that uses that function. In
-  other words, the address of a function marked with this attribute is not
-  guaranteed to be the same across translation units.
+  Mark a function as hidden and force inlining whenever possible.
+
+**_LIBCPP_ALWAYS_INLINE**
+  A synonym for `_LIBCPP_INLINE_VISIBILITY`
 
 **_LIBCPP_TYPE_VIS**
   Mark a type's typeinfo, vtable and members as having default visibility.

Modified: libcxx/trunk/include/__bsd_locale_fallbacks.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__bsd_locale_fallbacks.h?rev=336382=336381=336382=diff
==
--- libcxx/trunk/include/__bsd_locale_fallbacks.h (original)
+++ libcxx/trunk/include/__bsd_locale_fallbacks.h Thu Jul  5 11:41:50 2018
@@ -24,28 +24,28 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_ALWAYS_INLINE
 decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l)
 {
 __libcpp_locale_guard __current(__l);
 return MB_CUR_MAX;
 }
 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_ALWAYS_INLINE
 wint_t __libcpp_btowc_l(int __c, locale_t __l)
 {
 __libcpp_locale_guard __current(__l);
 return btowc(__c);
 }
 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_ALWAYS_INLINE
 int __libcpp_wctob_l(wint_t __c, locale_t __l)
 {
 __libcpp_locale_guard __current(__l);
 return wctob(__c);
 }
 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_ALWAYS_INLINE
 size_t __libcpp_wcsnrtombs_l(char *__dest, const wchar_t **__src, size_t __nwc,
  size_t __len, mbstate_t *__ps, locale_t __l)
 {
@@ -53,14 +53,14 @@ size_t __libcpp_wcsnrtombs_l(char *__des
 return wcsnrtombs(__dest, __src, __nwc, __len, __ps);
 }
 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_ALWAYS_INLINE
 size_t __libcpp_wcrtomb_l(char *__s, wchar_t __wc, mbstate_t *__ps, locale_t 
__l)
 {
 __libcpp_locale_guard __current(__l);
 return wcrtomb(__s, __wc, __ps);
 }
 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_ALWAYS_INLINE
 size_t __libcpp_mbsnrtowcs_l(wchar_t * __dest, const char **__src, size_t 
__nms,
   size_t __len, mbstate_t *__ps, locale_t __l)
 {
@@ -68,7 +68,7 @@ size_t __libcpp_mbsnrtowcs_l(wchar_t * _
 return mbsnrtowcs(__dest, __src, __nms, __len, __ps);
 }
 
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_ALWAYS_INLINE
 size_t __libcpp_mbrtowc_l(wchar_t *__pwc, const char *__s, size_t __n,
mbstate_t 

[PATCH] D48892: [libc++] Replace uses of _LIBCPP_ALWAYS_INLINE by _LIBCPP_INLINE_VISIBILITY

2018-07-05 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

In https://reviews.llvm.org/D48892#1153473, @davide wrote:

> The lldb bot started failing very recently and the blamelist hints at this 
> change.
>
> http://green.lab.llvm.org/green/job/lldb-cmake//
>
> Can you please take a look?
>
> For your convenience, this is failing building LibCxx testcases with a linker 
> error:
>
>   Build Command Output:
>   Undefined symbols for architecture x86_64:
> "std::__1::__vector_base_common::__vector_base_common()", 
> referenced from:
> std::__1::__vector_base 
> >::__vector_base() in main.o
> std::__1::__vector_base std::__1::char_traits, std::__1::allocator >, 
> std::__1::allocator, 
> std::__1::allocator > > >::__vector_base() in main.o
>   ld: symbol(s) not found for architecture x86_64
>   clang-7: error: linker command failed with exit code 1 (use -v to see 
> invocation)
>   make: *** [a.out] Error 1
>


Interesting.  The failing jobs all have things like this:

  #include 
  #ifdef _LIBCPP_INLINE_VISIBILITY
  #undef _LIBCPP_INLINE_VISIBILITY
  #endif
  #define _LIBCPP_INLINE_VISIBILITY
  #include 
  #include 

We should revert to green, but... why is LLDB doing that?


Repository:
  rCXX libc++

https://reviews.llvm.org/D48892



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


[PATCH] D48892: [libc++] Replace uses of _LIBCPP_ALWAYS_INLINE by _LIBCPP_INLINE_VISIBILITY

2018-07-05 Thread Davide Italiano via Phabricator via cfe-commits
davide reopened this revision.
davide added a comment.
This revision is now accepted and ready to land.

The lldb bot started failing very recently and the blamelist hints at this 
change.

http://green.lab.llvm.org/green/job/lldb-cmake//

Can you please take a look?

For your convenience, this is failing building LibCxx testcases with a linker 
error:

  Build Command Output:
  Undefined symbols for architecture x86_64:
"std::__1::__vector_base_common::__vector_base_common()", referenced 
from:
std::__1::__vector_base 
>::__vector_base() in main.o
std::__1::__vector_base, std::__1::allocator >, 
std::__1::allocator, 
std::__1::allocator > > >::__vector_base() in main.o
  ld: symbol(s) not found for architecture x86_64
  clang-7: error: linker command failed with exit code 1 (use -v to see 
invocation)
  make: *** [a.out] Error 1


Repository:
  rCXX libc++

https://reviews.llvm.org/D48892



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


[PATCH] D48981: Add caching when looking up coroutine_traits

2018-07-05 Thread Brian Gesiak via Phabricator via cfe-commits
modocache resigned from this revision.
modocache added a comment.

This LGTM but I'll just wait for @GorNishanov to accept the patch, just in case 
I'm missing something. I'd be happy to commit this for you once Gor accepts! :)


Repository:
  rC Clang

https://reviews.llvm.org/D48981



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


[PATCH] D48852: [Sema] -Wformat-pedantic only for NSInteger/NSUInteger %tu/%td on Darwin

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

> This is acceptable because Darwin guarantees that, despite the watchOS ABI 
> differences, sizeof(ptrdiff_t) == sizeof(NS[U]Integer)

Can you describe these ABI differences please? Also, does Darwin guarantee that 
alignof(ptrdiff_t) == alignof(NS[U]Integer)?


Repository:
  rC Clang

https://reviews.llvm.org/D48852



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


[PATCH] D48852: [Sema] -Wformat-pedantic only for NSInteger/NSUInteger %tu/%td on Darwin

2018-07-05 Thread JF Bastien via Phabricator via cfe-commits
jfb accepted this revision.
jfb added a comment.
This revision is now accepted and ready to land.

LGTM after a few questions.




Comment at: include/clang/Analysis/Analyses/FormatString.h:265
+  enum class TypeKind { Unspecified, SizeT, PtrdiffT };
+  TypeKind TK = TypeKind::Unspecified;
 

"unspecified" seems odd because it *is* specified, we just don't care. How 
about something like "NothingSpecial" or "DontCare"?



Comment at: test/SemaObjC/format-size-spec-nsinteger.m:4
+// RUN: %clang_cc1 -triple thumbv7k-apple-watchos2.0.0 -fsyntax-only -fblocks 
-verify %s
+// RUN: %clang_cc1 -triple thumbv7k-apple-watchos2.0.0 -fsyntax-only -fblocks 
-verify -Wformat-pedantic -DPEDANTIC %s
 

We use a bunch of different triples to test WatchOS:

   5 thumbv7k-apple-watchos2.0
   3 i386-apple-watchos4
   2 x86_64-apple-watchos
   2 thumbv7k-apple-watchos
   2 armv7k-apple-watchos3.0.0
   2 armv7k-apple-watchos2.0
   2 armv7k-apple-watchos
   1 x86_64-apple-watchos-simulator
   1 thumbv7k-apple-watchos1.0
   1 i686-apple-watchos
   1 i386-apple-watchos3.0-simulator
   1 i386-apple-watchos3
   1 i386-apple-watchos2.1
   1 i386-apple-watchos2.0-simulator
   1 i386-apple-watchos2.0
   1 i386-apple-watchos-simulator
   1 i386-apple-watchos
   1 armv7k-apple-watchos2.1
   1 armv7-apple-watchos
   1 arm64-apple-watchos
   1 aarch64-apple-watchos

Do we care about v7k only for this test?


Repository:
  rC Clang

https://reviews.llvm.org/D48852



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


[PATCH] D48982: [mips] Add '-mvirt', '-mno-virt', '-mginv', '-mno-ginv' options

2018-07-05 Thread Vladimir Stefanovic via Phabricator via cfe-commits
vstefanovic created this revision.
vstefanovic added a reviewer: atanasyan.
Herald added subscribers: cfe-commits, arichardson, sdardis.

'-mvirt'/'-mno-virt' enables/disables Virtualization ASE.
'-mginv'/'-mno-ginv' enables/disables GINV (Global Invalidate) ASE.


Repository:
  rC Clang

https://reviews.llvm.org/D48982

Files:
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/Arch/Mips.cpp
  test/Driver/mips-features.c


Index: test/Driver/mips-features.c
===
--- test/Driver/mips-features.c
+++ test/Driver/mips-features.c
@@ -420,3 +420,27 @@
 // RUN: -mcrc -mno-crc 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-CRC %s
 // CHECK-NO-CRC: "-target-feature" "-crc"
+//
+// -mvirt
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -mno-virt -mvirt 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-VIRT %s
+// CHECK-VIRT: "-target-feature" "+virt"
+//
+// -mno-virt
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -mvirt -mno-virt 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-VIRT %s
+// CHECK-NO-VIRT: "-target-feature" "-virt"
+//
+// -mginv
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -mno-ginv -mginv 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-GINV %s
+// CHECK-GINV: "-target-feature" "+ginv"
+//
+// -mno-ginv
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -mginv -mno-ginv 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-GINV %s
+// CHECK-NO-GINV: "-target-feature" "-ginv"
Index: lib/Driver/ToolChains/Arch/Mips.cpp
===
--- lib/Driver/ToolChains/Arch/Mips.cpp
+++ lib/Driver/ToolChains/Arch/Mips.cpp
@@ -352,6 +352,10 @@
   AddTargetFeature(Args, Features, options::OPT_mmt, options::OPT_mno_mt, 
"mt");
   AddTargetFeature(Args, Features, options::OPT_mcrc, options::OPT_mno_crc,
"crc");
+  AddTargetFeature(Args, Features, options::OPT_mvirt, options::OPT_mno_virt,
+   "virt");
+  AddTargetFeature(Args, Features, options::OPT_mginv, options::OPT_mno_ginv,
+   "ginv");
 
   if (Arg *A = Args.getLastArg(options::OPT_mindirect_jump_EQ)) {
 StringRef Val = StringRef(A->getValue());
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -2214,6 +2214,10 @@
   HelpText<"Disable SVR4-style position-independent code (Mips only)">;
 def mno_crc : Flag<["-"], "mno-crc">, Group,
   HelpText<"Disallow use of CRC instructions (Mips only)">;
+def mvirt : Flag<["-"], "mvirt">, Group;
+def mno_virt : Flag<["-"], "mno-virt">, Group;
+def mginv : Flag<["-"], "mginv">, Group;
+def mno_ginv : Flag<["-"], "mno-ginv">, Group;
 def mips1 : Flag<["-"], "mips1">,
   Alias, AliasArgs<["mips1"]>, Group,
   HelpText<"Equivalent to -march=mips1">, Flags<[HelpHidden]>;


Index: test/Driver/mips-features.c
===
--- test/Driver/mips-features.c
+++ test/Driver/mips-features.c
@@ -420,3 +420,27 @@
 // RUN: -mcrc -mno-crc 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-CRC %s
 // CHECK-NO-CRC: "-target-feature" "-crc"
+//
+// -mvirt
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -mno-virt -mvirt 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-VIRT %s
+// CHECK-VIRT: "-target-feature" "+virt"
+//
+// -mno-virt
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -mvirt -mno-virt 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-VIRT %s
+// CHECK-NO-VIRT: "-target-feature" "-virt"
+//
+// -mginv
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -mno-ginv -mginv 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-GINV %s
+// CHECK-GINV: "-target-feature" "+ginv"
+//
+// -mno-ginv
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -mginv -mno-ginv 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-GINV %s
+// CHECK-NO-GINV: "-target-feature" "-ginv"
Index: lib/Driver/ToolChains/Arch/Mips.cpp
===
--- lib/Driver/ToolChains/Arch/Mips.cpp
+++ lib/Driver/ToolChains/Arch/Mips.cpp
@@ -352,6 +352,10 @@
   AddTargetFeature(Args, Features, options::OPT_mmt, options::OPT_mno_mt, "mt");
   AddTargetFeature(Args, Features, options::OPT_mcrc, options::OPT_mno_crc,
"crc");
+  AddTargetFeature(Args, Features, options::OPT_mvirt, options::OPT_mno_virt,
+   "virt");
+  AddTargetFeature(Args, Features, options::OPT_mginv, options::OPT_mno_ginv,
+   "ginv");
 
   if (Arg *A = Args.getLastArg(options::OPT_mindirect_jump_EQ)) {
 StringRef Val = StringRef(A->getValue());
Index: include/clang/Driver/Options.td

[PATCH] D48981: Add caching when looking up coroutine_traits

2018-07-05 Thread Tanoy Sinha via Phabricator via cfe-commits
tks2103 created this revision.
tks2103 added reviewers: GorNishanov, modocache.

Currently clang looks up the coroutine_traits ClassTemplateDecl
everytime it looks up the promise type. This is unnecessary
as coroutine_traits doesn't change between promise type lookups.

This diff caches the coroutine_traits lookup.

Test Plan:
I added log statements in the new `lookupCoroutineTraits` function
to ensure that `LookupQualifiedName` was only called once even
when multiple coroutines existed in the source file.


Repository:
  rC Clang

https://reviews.llvm.org/D48981

Files:
  include/clang/Sema/Sema.h
  lib/Sema/Sema.cpp
  lib/Sema/SemaCoroutine.cpp


Index: lib/Sema/SemaCoroutine.cpp
===
--- lib/Sema/SemaCoroutine.cpp
+++ lib/Sema/SemaCoroutine.cpp
@@ -60,20 +60,8 @@
 return QualType();
   }
 
-  LookupResult Result(S, ().get("coroutine_traits"),
-  FuncLoc, Sema::LookupOrdinaryName);
-  if (!S.LookupQualifiedName(Result, StdExp)) {
-S.Diag(KwLoc, diag::err_implied_coroutine_type_not_found)
-<< "std::experimental::coroutine_traits";
-return QualType();
-  }
-
-  ClassTemplateDecl *CoroTraits = Result.getAsSingle();
+  ClassTemplateDecl *CoroTraits = S.lookupCoroutineTraits(KwLoc, FuncLoc);
   if (!CoroTraits) {
-Result.suppressDiagnostics();
-// We found something weird. Complain about the first thing we found.
-NamedDecl *Found = *Result.begin();
-S.Diag(Found->getLocation(), diag::err_malformed_std_coroutine_traits);
 return QualType();
   }
 
@@ -1538,3 +1526,27 @@
 return StmtError();
   return Res;
 }
+
+ClassTemplateDecl *Sema::lookupCoroutineTraits(SourceLocation KwLoc,
+   SourceLocation FuncLoc) {
+  if (!StdCoroutineTraitsCache) {
+if (auto StdExp = lookupStdExperimentalNamespace()) {
+  LookupResult Result(*this,
+  ().get("coroutine_traits"),
+  FuncLoc, LookupOrdinaryName);
+  if (!LookupQualifiedName(Result, StdExp)) {
+Diag(KwLoc, diag::err_implied_coroutine_type_not_found)
+<< "std::experimental::coroutine_traits";
+return nullptr;
+  }
+  if (!(StdCoroutineTraitsCache =
+Result.getAsSingle())) {
+Result.suppressDiagnostics();
+NamedDecl *Found = *Result.begin();
+Diag(Found->getLocation(), diag::err_malformed_std_coroutine_traits);
+return nullptr;
+  }
+}
+  }
+  return StdCoroutineTraitsCache;
+}
Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -131,9 +131,9 @@
   IsBuildingRecoveryCallExpr(false), Cleanup{}, 
LateTemplateParser(nullptr),
   LateTemplateParserCleanup(nullptr), OpaqueParser(nullptr), 
IdResolver(pp),
   StdExperimentalNamespaceCache(nullptr), StdInitializerList(nullptr),
-  CXXTypeInfoDecl(nullptr), MSVCGuidDecl(nullptr), NSNumberDecl(nullptr),
-  NSValueDecl(nullptr), NSStringDecl(nullptr),
-  StringWithUTF8StringMethod(nullptr),
+  StdCoroutineTraitsCache(nullptr), CXXTypeInfoDecl(nullptr),
+  MSVCGuidDecl(nullptr), NSNumberDecl(nullptr), NSValueDecl(nullptr),
+  NSStringDecl(nullptr), StringWithUTF8StringMethod(nullptr),
   ValueWithBytesObjCTypeMethod(nullptr), NSArrayDecl(nullptr),
   ArrayWithObjectsMethod(nullptr), NSDictionaryDecl(nullptr),
   DictionaryWithObjectsMethod(nullptr), GlobalNewDeleteDeclared(false),
Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -824,6 +824,10 @@
   /// \.
   ClassTemplateDecl *StdInitializerList;
 
+  /// The C++ "std::coroutine_traits" template, which is defined in
+  /// \
+  ClassTemplateDecl *StdCoroutineTraitsCache;
+
   /// The C++ "type_info" declaration, which is defined in \.
   RecordDecl *CXXTypeInfoDecl;
 
@@ -8572,6 +8576,8 @@
   bool buildCoroutineParameterMoves(SourceLocation Loc);
   VarDecl *buildCoroutinePromise(SourceLocation Loc);
   void CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *);
+  ClassTemplateDecl *lookupCoroutineTraits(SourceLocation KwLoc,
+   SourceLocation FuncLoc);
 
   
//======//
   // OpenCL extensions.


Index: lib/Sema/SemaCoroutine.cpp
===
--- lib/Sema/SemaCoroutine.cpp
+++ lib/Sema/SemaCoroutine.cpp
@@ -60,20 +60,8 @@
 return QualType();
   }
 
-  LookupResult Result(S, ().get("coroutine_traits"),
-  FuncLoc, Sema::LookupOrdinaryName);
-  if (!S.LookupQualifiedName(Result, StdExp)) {
-S.Diag(KwLoc, diag::err_implied_coroutine_type_not_found)
-<< "std::experimental::coroutine_traits";
-return QualType();
-  }
-

[libcxx] r336381 - Fix HTML blunder

2018-07-05 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Thu Jul  5 10:44:12 2018
New Revision: 336381

URL: http://llvm.org/viewvc/llvm-project?rev=336381=rev
Log:
Fix HTML blunder

Modified:
libcxx/trunk/www/cxx2a_status.html

Modified: libcxx/trunk/www/cxx2a_status.html
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx2a_status.html?rev=336381=336380=336381=diff
==
--- libcxx/trunk/www/cxx2a_status.html (original)
+++ libcxx/trunk/www/cxx2a_status.html Thu Jul  5 10:44:12 2018
@@ -210,7 +210,7 @@
https://wg21.link/LWG3067;>3067recursive_directory_iterator::pop
 must invalidateRapperswilNothing to do
https://wg21.link/LWG3071;>3071[networking.ts] read_until 
still refers to "input sequence"RapperswilNothing to 
do
https://wg21.link/LWG3074;>3074Non-member 
functions for valarray should only deduce from the 
valarrayRapperswil
-   https://wg21.link/LWG3076;>3076basic_string CTAD 
ambiguityRapperswilComplete
+   https://wg21.link/LWG3076;>3076basic_string CTAD 
ambiguityRapperswilComplete
https://wg21.link/LWG3079;>3079LWG 2935 
forgot to fix the existing_p overloads of 
create_directoryRapperswil
https://wg21.link/LWG3080;>3080Floating 
point from_chars pattern specification breaks 
round-trippingRapperswil
https://wg21.link/LWG3083;>3083What 
should ios::iword(-1) do?RapperswilNothing to 
do


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


r336380 - Add PCH tests for R336379

2018-07-05 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Thu Jul  5 10:23:15 2018
New Revision: 336380

URL: http://llvm.org/viewvc/llvm-project?rev=336380=rev
Log:
Add PCH tests for R336379

I seemingly forgot the tests for this commit, added here.

Added:
cfe/trunk/test/PCH/Inputs/pch-through-use0.cpp   (with props)
cfe/trunk/test/PCH/Inputs/pch-through-use1.cpp   (with props)
cfe/trunk/test/PCH/Inputs/pch-through-use2.cpp   (with props)
cfe/trunk/test/PCH/Inputs/pch-through-use3a.cpp   (with props)
cfe/trunk/test/PCH/Inputs/pch-through-use3b.cpp   (with props)
cfe/trunk/test/PCH/Inputs/pch-through1.h   (with props)
cfe/trunk/test/PCH/Inputs/pch-through2.h   (with props)
cfe/trunk/test/PCH/Inputs/pch-through3.h   (with props)
cfe/trunk/test/PCH/Inputs/pch-through4.h   (with props)
cfe/trunk/test/PCH/pch-through1.cpp   (with props)
cfe/trunk/test/PCH/pch-through2.cpp   (with props)
cfe/trunk/test/PCH/pch-through3a.cpp   (with props)
cfe/trunk/test/PCH/pch-through3b.cpp   (with props)

Added: cfe/trunk/test/PCH/Inputs/pch-through-use0.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/Inputs/pch-through-use0.cpp?rev=336380=auto
==
--- cfe/trunk/test/PCH/Inputs/pch-through-use0.cpp (added)
+++ cfe/trunk/test/PCH/Inputs/pch-through-use0.cpp Thu Jul  5 10:23:15 2018
@@ -0,0 +1,2 @@
+void foo() {
+}

Propchange: cfe/trunk/test/PCH/Inputs/pch-through-use0.cpp
--
svn:eol-style = native

Propchange: cfe/trunk/test/PCH/Inputs/pch-through-use0.cpp
--
svn:keywords = Author Date Id Rev URL

Propchange: cfe/trunk/test/PCH/Inputs/pch-through-use0.cpp
--
svn:mime-type = text/plain

Added: cfe/trunk/test/PCH/Inputs/pch-through-use1.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/Inputs/pch-through-use1.cpp?rev=336380=auto
==
--- cfe/trunk/test/PCH/Inputs/pch-through-use1.cpp (added)
+++ cfe/trunk/test/PCH/Inputs/pch-through-use1.cpp Thu Jul  5 10:23:15 2018
@@ -0,0 +1,5 @@
+#include "Inputs/pch-through1.h"
+#include "Inputs/pch-through3.h"
+void foo() {
+  through2(0);
+}

Propchange: cfe/trunk/test/PCH/Inputs/pch-through-use1.cpp
--
svn:eol-style = native

Propchange: cfe/trunk/test/PCH/Inputs/pch-through-use1.cpp
--
svn:keywords = Author Date Id Rev URL

Propchange: cfe/trunk/test/PCH/Inputs/pch-through-use1.cpp
--
svn:mime-type = text/plain

Added: cfe/trunk/test/PCH/Inputs/pch-through-use2.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/Inputs/pch-through-use2.cpp?rev=336380=auto
==
--- cfe/trunk/test/PCH/Inputs/pch-through-use2.cpp (added)
+++ cfe/trunk/test/PCH/Inputs/pch-through-use2.cpp Thu Jul  5 10:23:15 2018
@@ -0,0 +1,3 @@
+void foo() {
+  through4(0);
+}

Propchange: cfe/trunk/test/PCH/Inputs/pch-through-use2.cpp
--
svn:eol-style = native

Propchange: cfe/trunk/test/PCH/Inputs/pch-through-use2.cpp
--
svn:keywords = Author Date Id Rev URL

Propchange: cfe/trunk/test/PCH/Inputs/pch-through-use2.cpp
--
svn:mime-type = text/plain

Added: cfe/trunk/test/PCH/Inputs/pch-through-use3a.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/Inputs/pch-through-use3a.cpp?rev=336380=auto
==
--- cfe/trunk/test/PCH/Inputs/pch-through-use3a.cpp (added)
+++ cfe/trunk/test/PCH/Inputs/pch-through-use3a.cpp Thu Jul  5 10:23:15 2018
@@ -0,0 +1,2 @@
+#define AFOO 0
+#include "Inputs/pch-through1.h"

Propchange: cfe/trunk/test/PCH/Inputs/pch-through-use3a.cpp
--
svn:eol-style = native

Propchange: cfe/trunk/test/PCH/Inputs/pch-through-use3a.cpp
--
svn:keywords = Author Date Id Rev URL

Propchange: cfe/trunk/test/PCH/Inputs/pch-through-use3a.cpp
--
svn:mime-type = text/plain

Added: cfe/trunk/test/PCH/Inputs/pch-through-use3b.cpp
URL: 

r336379 - [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-07-05 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Thu Jul  5 10:22:13 2018
New Revision: 336379

URL: http://llvm.org/viewvc/llvm-project?rev=336379=rev
Log:
[clang-cl, PCH] Implement support for MS-style PCH through headers

Implement support for MS-style PCH through headers.

This enables support for /Yc and /Yu where the through header is either
on the command line or included in the source. It replaces the current
support the requires the header also be specified with /FI.

This change adds a -cc1 option -pch-through-header that is used to either
start or stop compilation during PCH create or use.

When creating a PCH, the compilation ends after compilation of the through
header.

When using a PCH, tokens are skipped until after the through header is seen.

Patch By: mikerice
Differential Revision: https://reviews.llvm.org/D46652

Modified:
cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/include/clang/Frontend/FrontendOptions.h
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/include/clang/Lex/PreprocessorOptions.h
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/lib/Lex/PPLexerChange.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/lib/Parse/ParseAST.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/test/Driver/cl-pch-search.cpp
cfe/trunk/test/Driver/cl-pch.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=336379=336378=336379=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Thu Jul  5 10:22:13 2018
@@ -404,6 +404,14 @@ def err_pp_invalid_directive : Error<"in
 def err_pp_directive_required : Error<
   "%0 must be used within a preprocessing directive">;
 def err_pp_file_not_found : Error<"'%0' file not found">, DefaultFatal;
+def err_pp_through_header_not_found : Error<
+  "'%0' required for precompiled header not found">, DefaultFatal;
+def err_pp_through_header_not_seen : Error<
+  "#include of '%0' not seen while attempting to "
+  "%select{create|use}1 precompiled header">, DefaultFatal;
+def warn_pp_macro_def_mismatch_with_pch : Warning<
+  "definition of macro %0 does not match definition in precompiled header">,
+  InGroup;
 def err_pp_file_not_found_not_fatal : Error<
   "'%0' file not found with  include; use \"quotes\" instead">;
 def err_pp_error_opening_file : Error<

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=336379=336378=336379=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Thu Jul  5 10:22:13 2018
@@ -607,10 +607,9 @@ def fixit_to_temp : Flag<["-"], "fixit-t
 
 def foverride_record_layout_EQ : Joined<["-"], "foverride-record-layout=">,
   HelpText<"Override record layouts with those in the given file">;
-def find_pch_source_EQ : Joined<["-"], "find-pch-source=">,
-  HelpText<"When building a pch, try to find the input file in include "
-   "directories, as if it had been included by the argument passed "
-   "to this flag.">;
+def pch_through_header_EQ : Joined<["-"], "pch-through-header=">,
+  HelpText<"Stop PCH generation after including this file.  When using a PCH, "
+   "skip tokens until after this file is included.">;
 def fno_pch_timestamp : Flag<["-"], "fno-pch-timestamp">,
   HelpText<"Disable inclusion of timestamp in precompiled headers">;
 def building_pch_with_obj : Flag<["-"], "building-pch-with-obj">,

Modified: cfe/trunk/include/clang/Frontend/FrontendOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendOptions.h?rev=336379=336378=336379=diff
==
--- cfe/trunk/include/clang/Frontend/FrontendOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendOptions.h Thu Jul  5 10:22:13 2018
@@ -435,10 +435,6 @@ public:
   /// Auxiliary triple for CUDA compilation.
   std::string AuxTriple;
 
-  /// If non-empty, search the pch input file as if it was a header
-  /// included by this file.
-  std::string FindPchSource;
-
   /// Filename to write statistics to.
   std::string StatsFile;
 

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=336379=336378=336379=diff
==
--- 

[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-07-05 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL336379: [clang-cl, PCH] Implement support for MS-style PCH 
through headers (authored by erichkeane, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46652?vs=153067=154264#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46652

Files:
  cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
  cfe/trunk/include/clang/Driver/CC1Options.td
  cfe/trunk/include/clang/Frontend/FrontendOptions.h
  cfe/trunk/include/clang/Lex/Preprocessor.h
  cfe/trunk/include/clang/Lex/PreprocessorOptions.h
  cfe/trunk/lib/Driver/Driver.cpp
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/lib/Frontend/CompilerInstance.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/lib/Lex/PPDirectives.cpp
  cfe/trunk/lib/Lex/PPLexerChange.cpp
  cfe/trunk/lib/Lex/Preprocessor.cpp
  cfe/trunk/lib/Parse/ParseAST.cpp
  cfe/trunk/lib/Serialization/ASTReader.cpp
  cfe/trunk/test/Driver/cl-pch-search.cpp
  cfe/trunk/test/Driver/cl-pch.cpp

Index: cfe/trunk/include/clang/Driver/CC1Options.td
===
--- cfe/trunk/include/clang/Driver/CC1Options.td
+++ cfe/trunk/include/clang/Driver/CC1Options.td
@@ -607,10 +607,9 @@
 
 def foverride_record_layout_EQ : Joined<["-"], "foverride-record-layout=">,
   HelpText<"Override record layouts with those in the given file">;
-def find_pch_source_EQ : Joined<["-"], "find-pch-source=">,
-  HelpText<"When building a pch, try to find the input file in include "
-   "directories, as if it had been included by the argument passed "
-   "to this flag.">;
+def pch_through_header_EQ : Joined<["-"], "pch-through-header=">,
+  HelpText<"Stop PCH generation after including this file.  When using a PCH, "
+   "skip tokens until after this file is included.">;
 def fno_pch_timestamp : Flag<["-"], "fno-pch-timestamp">,
   HelpText<"Disable inclusion of timestamp in precompiled headers">;
 def building_pch_with_obj : Flag<["-"], "building-pch-with-obj">,
Index: cfe/trunk/include/clang/Lex/PreprocessorOptions.h
===
--- cfe/trunk/include/clang/Lex/PreprocessorOptions.h
+++ cfe/trunk/include/clang/Lex/PreprocessorOptions.h
@@ -54,6 +54,13 @@
   /// definitions and expansions.
   bool DetailedRecord = false;
 
+  /// If non-empty, the filename used in an #include directive in the primary
+  /// source file (or command-line preinclude) that is used to implement
+  /// MSVC-style precompiled headers. When creating a PCH, after the #include
+  /// of this header, the PCH generation stops. When using a PCH, tokens are
+  /// skipped until after an #include of this header is seen.
+  std::string PCHThroughHeader;
+
   /// The implicit PCH included at the start of the translation unit, or empty.
   std::string ImplicitPCHInclude;
 
Index: cfe/trunk/include/clang/Lex/Preprocessor.h
===
--- cfe/trunk/include/clang/Lex/Preprocessor.h
+++ cfe/trunk/include/clang/Lex/Preprocessor.h
@@ -720,6 +720,12 @@
   /// The file ID for the preprocessor predefines.
   FileID PredefinesFileID;
 
+  /// The file ID for the PCH through header.
+  FileID PCHThroughHeaderFileID;
+
+  /// Whether tokens are being skipped until the through header is seen.
+  bool SkippingUntilPCHThroughHeader = false;
+
   /// \{
   /// Cache of macro expanders to reduce malloc traffic.
   enum { TokenLexerCacheSize = 8 };
@@ -1140,6 +1146,22 @@
   /// all macro expansions, macro definitions, etc.
   void createPreprocessingRecord();
 
+  /// Returns true if the FileEntry is the PCH through header.
+  bool isPCHThroughHeader(const FileEntry *File);
+
+  /// True if creating a PCH with a through header.
+  bool creatingPCHWithThroughHeader();
+
+  /// True if using a PCH with a through header.
+  bool usingPCHWithThroughHeader();
+
+  /// Skip tokens until after the #include of the through header.
+  void SkipTokensUntilPCHThroughHeader();
+
+  /// Process directives while skipping until the through header is found.
+  void HandleSkippedThroughHeaderDirective(Token ,
+   SourceLocation HashLoc);
+
   /// Enter the specified FileID as the main source file,
   /// which implicitly adds the builtin defines etc.
   void EnterMainSourceFile();
@@ -2020,6 +2042,9 @@
 PredefinesFileID = FID;
   }
 
+  /// Set the FileID for the PCH through header.
+  void setPCHThroughHeaderFileID(FileID FID);
+
   /// Returns true if we are lexing from a file and not a
   /// pragma or a macro.
   static bool IsFileLexer(const Lexer* L, const PreprocessorLexer* P) {
Index: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
+++ 

[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-07-05 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC336379: [clang-cl, PCH] Implement support for MS-style PCH 
through headers (authored by erichkeane, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D46652?vs=153067=154265#toc

Repository:
  rC Clang

https://reviews.llvm.org/D46652

Files:
  include/clang/Basic/DiagnosticLexKinds.td
  include/clang/Driver/CC1Options.td
  include/clang/Frontend/FrontendOptions.h
  include/clang/Lex/Preprocessor.h
  include/clang/Lex/PreprocessorOptions.h
  lib/Driver/Driver.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInstance.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/PPDirectives.cpp
  lib/Lex/PPLexerChange.cpp
  lib/Lex/Preprocessor.cpp
  lib/Parse/ParseAST.cpp
  lib/Serialization/ASTReader.cpp
  test/Driver/cl-pch-search.cpp
  test/Driver/cl-pch.cpp

Index: include/clang/Driver/CC1Options.td
===
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -607,10 +607,9 @@
 
 def foverride_record_layout_EQ : Joined<["-"], "foverride-record-layout=">,
   HelpText<"Override record layouts with those in the given file">;
-def find_pch_source_EQ : Joined<["-"], "find-pch-source=">,
-  HelpText<"When building a pch, try to find the input file in include "
-   "directories, as if it had been included by the argument passed "
-   "to this flag.">;
+def pch_through_header_EQ : Joined<["-"], "pch-through-header=">,
+  HelpText<"Stop PCH generation after including this file.  When using a PCH, "
+   "skip tokens until after this file is included.">;
 def fno_pch_timestamp : Flag<["-"], "fno-pch-timestamp">,
   HelpText<"Disable inclusion of timestamp in precompiled headers">;
 def building_pch_with_obj : Flag<["-"], "building-pch-with-obj">,
Index: include/clang/Lex/PreprocessorOptions.h
===
--- include/clang/Lex/PreprocessorOptions.h
+++ include/clang/Lex/PreprocessorOptions.h
@@ -54,6 +54,13 @@
   /// definitions and expansions.
   bool DetailedRecord = false;
 
+  /// If non-empty, the filename used in an #include directive in the primary
+  /// source file (or command-line preinclude) that is used to implement
+  /// MSVC-style precompiled headers. When creating a PCH, after the #include
+  /// of this header, the PCH generation stops. When using a PCH, tokens are
+  /// skipped until after an #include of this header is seen.
+  std::string PCHThroughHeader;
+
   /// The implicit PCH included at the start of the translation unit, or empty.
   std::string ImplicitPCHInclude;
 
Index: include/clang/Lex/Preprocessor.h
===
--- include/clang/Lex/Preprocessor.h
+++ include/clang/Lex/Preprocessor.h
@@ -720,6 +720,12 @@
   /// The file ID for the preprocessor predefines.
   FileID PredefinesFileID;
 
+  /// The file ID for the PCH through header.
+  FileID PCHThroughHeaderFileID;
+
+  /// Whether tokens are being skipped until the through header is seen.
+  bool SkippingUntilPCHThroughHeader = false;
+
   /// \{
   /// Cache of macro expanders to reduce malloc traffic.
   enum { TokenLexerCacheSize = 8 };
@@ -1140,6 +1146,22 @@
   /// all macro expansions, macro definitions, etc.
   void createPreprocessingRecord();
 
+  /// Returns true if the FileEntry is the PCH through header.
+  bool isPCHThroughHeader(const FileEntry *File);
+
+  /// True if creating a PCH with a through header.
+  bool creatingPCHWithThroughHeader();
+
+  /// True if using a PCH with a through header.
+  bool usingPCHWithThroughHeader();
+
+  /// Skip tokens until after the #include of the through header.
+  void SkipTokensUntilPCHThroughHeader();
+
+  /// Process directives while skipping until the through header is found.
+  void HandleSkippedThroughHeaderDirective(Token ,
+   SourceLocation HashLoc);
+
   /// Enter the specified FileID as the main source file,
   /// which implicitly adds the builtin defines etc.
   void EnterMainSourceFile();
@@ -2020,6 +2042,9 @@
 PredefinesFileID = FID;
   }
 
+  /// Set the FileID for the PCH through header.
+  void setPCHThroughHeaderFileID(FileID FID);
+
   /// Returns true if we are lexing from a file and not a
   /// pragma or a macro.
   static bool IsFileLexer(const Lexer* L, const PreprocessorLexer* P) {
Index: include/clang/Basic/DiagnosticLexKinds.td
===
--- include/clang/Basic/DiagnosticLexKinds.td
+++ include/clang/Basic/DiagnosticLexKinds.td
@@ -404,6 +404,14 @@
 def err_pp_directive_required : Error<
   "%0 must be used within a preprocessing directive">;
 def err_pp_file_not_found : Error<"'%0' file not found">, DefaultFatal;
+def err_pp_through_header_not_found : Error<
+  "'%0' required for precompiled header not found">, 

[PATCH] D48721: Patch to fix pragma metadata for do-while loops

2018-07-05 Thread Bjorn Pettersson via Phabricator via cfe-commits
bjope added a comment.

In https://reviews.llvm.org/D48721#1153138, @deepak2427 wrote:

> I have updated the test to not run the optimizer. The test I had added 
> previously for checking if the unroller is respecting the pragma is useful I 
> think. Not sure where that can be added though. 
>  I guess it's independent of this patch anyway. If the patch and test is 
> okay, will update bugzilla as well.


My idea was to forbid the IR that caused problems for the unroller (and other 
optimization passes). Then we do not need to fixup various passes to handle 
"misplaced" llvm.loop annotations correctly. And neither do we need to 
implement test cases to verify that the "misplaced" annotations are handled 
correctly for lots of passes.

I played around a little bit with teaching the IR Verifier in opt to check that 
!llvm.loop only is put in loop latches.
Something like this might do the trick, when added to 
Verifier::visitInstruction in lib/IR/Verifier.cpp:

  #include "llvm/Analysis/LoopInfo.h"
  
  if (I.getMetadata(LLVMContext::MD_loop)) {
// FIXME: Is SwitchInst also allowed?
Assert(isa(I), "llvm.loop only expected on branches", );
LoopInfo LI;
LI.analyze(DT);
Loop* L = LI.getLoopFor(BB);
Assert(L, "llvm.loop not in a loop", );
Assert(L->isLoopLatch(BB), "llvm.loop not in a latch", );
  }

Note that the above just was a simple test. We do not want to reinitialize 
LoopInfo for each found occurence of !llvm.loop.
Another problem is that the Verifier is used by lots of tools that currently do 
not link with LoopInfo from the Analysis code module.

So maybe this should go into the LoopVerifier pass instead (although I'm not 
sure if that is commonly used).
Or is there some other place where we can do it? Or some other way to do a 
similar check (without using LoopInfo)?

I can bring this up on llvm-dev, to get some more feedback on the idea of 
having a verifier for this, and how to do it properly.


https://reviews.llvm.org/D48721



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


[PATCH] D46652: [clang-cl, PCH] Implement support for MS-style PCH through headers

2018-07-05 Thread Mike Rice via Phabricator via cfe-commits
mikerice added inline comments.



Comment at: include/clang/Driver/CC1Options.td:604
+  HelpText<"When creating a pch stop at this file.  When using a pch start "
+   "after this file.">;
 def fno_pch_timestamp : Flag<["-"], "fno-pch-timestamp">,

hans wrote:
> mikerice wrote:
> > hans wrote:
> > > The "through header" terminology was new to me, and I didn't see it when 
> > > browsing the MSDN articles about precompiled headers. The HelpText here 
> > > probably isn't the right place, but it would be good if the term could be 
> > > documented somewhere to make it clearer exactly what the behaviour is. 
> > > It's not really obvious to me what "stop at this file" and "start after 
> > > this file"  means. I can guess, but it would be nice if it were more 
> > > explicit :-)
> > You definitely have to look hard at the MSDN docs to find mention of 
> > through headers.  If you look at the documentation for /Yc and /Yu you can 
> > see some vague references.  I think it may have been more prominent many 
> > years ago. 
> > 
> > The MSDN page says "For /Yc, filename specifies the point at which 
> > precompilation stops; the compiler precompiles all code though(sic) 
> > filename..." https://msdn.microsoft.com/en-us/library/z0atkd6c.aspx
> > 
> > I'll look for a place to document this better in a comment at least.
> > 
> > 
> Thanks for the pointer. Yeah, a clear explanation in a comment somewhere 
> would be really helpful. Another idea might be to have a little "precompiled 
> headers" section in the clang-cl section of docs/UsersManual.rst. Maybe we 
> could do a better job than MS at explaining it precisely? :-)
Thanks for the review.  In the last patch I updated the comment in 
PreprocessorOptions.h  to better explain what a through header is.  I like the 
idea of explaining this in UsersManual.rst.  I'll work on that in the next few 
weeks. 


https://reviews.llvm.org/D46652



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


[PATCH] D48892: [libc++] Replace uses of _LIBCPP_ALWAYS_INLINE by _LIBCPP_INLINE_VISIBILITY

2018-07-05 Thread Louis Dionne via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCXX336369: [libc++] Replace uses of _LIBCPP_ALWAYS_INLINE by 
_LIBCPP_INLINE_VISIBILITY (authored by ldionne, committed by ).
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D48892?vs=153958=154258#toc

Repository:
  rCXX libc++

https://reviews.llvm.org/D48892

Files:
  docs/DesignDocs/VisibilityMacros.rst
  include/__bsd_locale_fallbacks.h
  include/__config
  include/__locale
  include/__nullptr
  include/any
  include/cmath
  include/codecvt
  include/exception
  include/experimental/dynarray
  include/experimental/filesystem
  include/functional
  include/future
  include/initializer_list
  include/ios
  include/locale
  include/math.h
  include/memory
  include/new
  include/ostream
  include/regex
  include/stdexcept
  include/streambuf
  include/support/android/locale_bionic.h
  include/support/xlocale/__posix_l_fallback.h
  include/support/xlocale/__strtonum_fallback.h
  include/system_error
  include/typeinfo
  include/vector
  src/support/win32/thread_win32.cpp

Index: docs/DesignDocs/VisibilityMacros.rst
===
--- docs/DesignDocs/VisibilityMacros.rst
+++ docs/DesignDocs/VisibilityMacros.rst
@@ -41,10 +41,10 @@
   library and has an empty definition otherwise.
 
 **_LIBCPP_INLINE_VISIBILITY**
-  Mark a function as hidden and force inlining whenever possible.
-
-**_LIBCPP_ALWAYS_INLINE**
-  A synonym for `_LIBCPP_INLINE_VISIBILITY`
+  Mark a function as not being part of the ABI of any final linked image that
+  uses it, and also as being internal to each TU that uses that function. In
+  other words, the address of a function marked with this attribute is not
+  guaranteed to be the same across translation units.
 
 **_LIBCPP_TYPE_VIS**
   Mark a type's typeinfo, vtable and members as having default visibility.
Index: src/support/win32/thread_win32.cpp
===
--- src/support/win32/thread_win32.cpp
+++ src/support/win32/thread_win32.cpp
@@ -138,7 +138,7 @@
 }
 
 // Execute Once
-static inline _LIBCPP_ALWAYS_INLINE BOOL CALLBACK
+static inline _LIBCPP_INLINE_VISIBILITY BOOL CALLBACK
 __libcpp_init_once_execute_once_thunk(PINIT_ONCE __init_once, PVOID __parameter,
   PVOID *__context)
 {
@@ -178,7 +178,7 @@
   void *__arg;
 };
 
-static inline _LIBCPP_ALWAYS_INLINE unsigned WINAPI
+static inline _LIBCPP_INLINE_VISIBILITY unsigned WINAPI
 __libcpp_beginthreadex_thunk(void *__raw_data)
 {
   auto *__data =
Index: include/functional
===
--- include/functional
+++ include/functional
@@ -1399,7 +1399,7 @@
 #endif
 };
 
-_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
+_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
 void __throw_bad_function_call()
 {
 #ifndef _LIBCPP_NO_EXCEPTIONS
Index: include/__bsd_locale_fallbacks.h
===
--- include/__bsd_locale_fallbacks.h
+++ include/__bsd_locale_fallbacks.h
@@ -24,80 +24,80 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-inline _LIBCPP_ALWAYS_INLINE
+inline _LIBCPP_INLINE_VISIBILITY
 decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l)
 {
 __libcpp_locale_guard __current(__l);
 return MB_CUR_MAX;
 }
 
-inline _LIBCPP_ALWAYS_INLINE
+inline _LIBCPP_INLINE_VISIBILITY
 wint_t __libcpp_btowc_l(int __c, locale_t __l)
 {
 __libcpp_locale_guard __current(__l);
 return btowc(__c);
 }
 
-inline _LIBCPP_ALWAYS_INLINE
+inline _LIBCPP_INLINE_VISIBILITY
 int __libcpp_wctob_l(wint_t __c, locale_t __l)
 {
 __libcpp_locale_guard __current(__l);
 return wctob(__c);
 }
 
-inline _LIBCPP_ALWAYS_INLINE
+inline _LIBCPP_INLINE_VISIBILITY
 size_t __libcpp_wcsnrtombs_l(char *__dest, const wchar_t **__src, size_t __nwc,
  size_t __len, mbstate_t *__ps, locale_t __l)
 {
 __libcpp_locale_guard __current(__l);
 return wcsnrtombs(__dest, __src, __nwc, __len, __ps);
 }
 
-inline _LIBCPP_ALWAYS_INLINE
+inline _LIBCPP_INLINE_VISIBILITY
 size_t __libcpp_wcrtomb_l(char *__s, wchar_t __wc, mbstate_t *__ps, locale_t __l)
 {
 __libcpp_locale_guard __current(__l);
 return wcrtomb(__s, __wc, __ps);
 }
 
-inline _LIBCPP_ALWAYS_INLINE
+inline _LIBCPP_INLINE_VISIBILITY
 size_t __libcpp_mbsnrtowcs_l(wchar_t * __dest, const char **__src, size_t __nms,
   size_t __len, mbstate_t *__ps, locale_t __l)
 {
 __libcpp_locale_guard __current(__l);
 return mbsnrtowcs(__dest, __src, __nms, __len, __ps);
 }
 
-inline _LIBCPP_ALWAYS_INLINE
+inline _LIBCPP_INLINE_VISIBILITY
 size_t __libcpp_mbrtowc_l(wchar_t *__pwc, const char *__s, size_t __n,
mbstate_t *__ps, locale_t __l)
 {
 __libcpp_locale_guard __current(__l);
 return mbrtowc(__pwc, __s, __n, __ps);
 }
 
-inline _LIBCPP_ALWAYS_INLINE

[libcxx] r336369 - [libc++] Replace uses of _LIBCPP_ALWAYS_INLINE by _LIBCPP_INLINE_VISIBILITY

2018-07-05 Thread Louis Dionne via cfe-commits
Author: ldionne
Date: Thu Jul  5 09:49:38 2018
New Revision: 336369

URL: http://llvm.org/viewvc/llvm-project?rev=336369=rev
Log:
[libc++] Replace uses of _LIBCPP_ALWAYS_INLINE by _LIBCPP_INLINE_VISIBILITY

Summary:
We never actually mean to always inline a function -- all the uses of
the macro I could find are actually attempts to control the visibility
of symbols. This is better described by _LIBCPP_INLINE_VISIBILITY, which
is actually always defined the same.

This change is orthogonal to the decision of what we're actually going
to do with _LIBCPP_INLINE_VISIBILITY -- it just simplifies things by
having one canonical way of doing things.

Reviewers: EricWF

Subscribers: christof, llvm-commits, dexonsmith, erikvanderpoel, mclow.lists

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

Modified:
libcxx/trunk/docs/DesignDocs/VisibilityMacros.rst
libcxx/trunk/include/__bsd_locale_fallbacks.h
libcxx/trunk/include/__config
libcxx/trunk/include/__locale
libcxx/trunk/include/__nullptr
libcxx/trunk/include/any
libcxx/trunk/include/cmath
libcxx/trunk/include/codecvt
libcxx/trunk/include/exception
libcxx/trunk/include/experimental/dynarray
libcxx/trunk/include/experimental/filesystem
libcxx/trunk/include/functional
libcxx/trunk/include/future
libcxx/trunk/include/initializer_list
libcxx/trunk/include/ios
libcxx/trunk/include/locale
libcxx/trunk/include/math.h
libcxx/trunk/include/memory
libcxx/trunk/include/new
libcxx/trunk/include/ostream
libcxx/trunk/include/regex
libcxx/trunk/include/stdexcept
libcxx/trunk/include/streambuf
libcxx/trunk/include/support/android/locale_bionic.h
libcxx/trunk/include/support/xlocale/__posix_l_fallback.h
libcxx/trunk/include/support/xlocale/__strtonum_fallback.h
libcxx/trunk/include/system_error
libcxx/trunk/include/typeinfo
libcxx/trunk/include/vector
libcxx/trunk/src/support/win32/thread_win32.cpp

Modified: libcxx/trunk/docs/DesignDocs/VisibilityMacros.rst
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/docs/DesignDocs/VisibilityMacros.rst?rev=336369=336368=336369=diff
==
--- libcxx/trunk/docs/DesignDocs/VisibilityMacros.rst (original)
+++ libcxx/trunk/docs/DesignDocs/VisibilityMacros.rst Thu Jul  5 09:49:38 2018
@@ -41,10 +41,10 @@ Visibility Macros
   library and has an empty definition otherwise.
 
 **_LIBCPP_INLINE_VISIBILITY**
-  Mark a function as hidden and force inlining whenever possible.
-
-**_LIBCPP_ALWAYS_INLINE**
-  A synonym for `_LIBCPP_INLINE_VISIBILITY`
+  Mark a function as not being part of the ABI of any final linked image that
+  uses it, and also as being internal to each TU that uses that function. In
+  other words, the address of a function marked with this attribute is not
+  guaranteed to be the same across translation units.
 
 **_LIBCPP_TYPE_VIS**
   Mark a type's typeinfo, vtable and members as having default visibility.

Modified: libcxx/trunk/include/__bsd_locale_fallbacks.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__bsd_locale_fallbacks.h?rev=336369=336368=336369=diff
==
--- libcxx/trunk/include/__bsd_locale_fallbacks.h (original)
+++ libcxx/trunk/include/__bsd_locale_fallbacks.h Thu Jul  5 09:49:38 2018
@@ -24,28 +24,28 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-inline _LIBCPP_ALWAYS_INLINE
+inline _LIBCPP_INLINE_VISIBILITY
 decltype(MB_CUR_MAX) __libcpp_mb_cur_max_l(locale_t __l)
 {
 __libcpp_locale_guard __current(__l);
 return MB_CUR_MAX;
 }
 
-inline _LIBCPP_ALWAYS_INLINE
+inline _LIBCPP_INLINE_VISIBILITY
 wint_t __libcpp_btowc_l(int __c, locale_t __l)
 {
 __libcpp_locale_guard __current(__l);
 return btowc(__c);
 }
 
-inline _LIBCPP_ALWAYS_INLINE
+inline _LIBCPP_INLINE_VISIBILITY
 int __libcpp_wctob_l(wint_t __c, locale_t __l)
 {
 __libcpp_locale_guard __current(__l);
 return wctob(__c);
 }
 
-inline _LIBCPP_ALWAYS_INLINE
+inline _LIBCPP_INLINE_VISIBILITY
 size_t __libcpp_wcsnrtombs_l(char *__dest, const wchar_t **__src, size_t __nwc,
  size_t __len, mbstate_t *__ps, locale_t __l)
 {
@@ -53,14 +53,14 @@ size_t __libcpp_wcsnrtombs_l(char *__des
 return wcsnrtombs(__dest, __src, __nwc, __len, __ps);
 }
 
-inline _LIBCPP_ALWAYS_INLINE
+inline _LIBCPP_INLINE_VISIBILITY
 size_t __libcpp_wcrtomb_l(char *__s, wchar_t __wc, mbstate_t *__ps, locale_t 
__l)
 {
 __libcpp_locale_guard __current(__l);
 return wcrtomb(__s, __wc, __ps);
 }
 
-inline _LIBCPP_ALWAYS_INLINE
+inline _LIBCPP_INLINE_VISIBILITY
 size_t __libcpp_mbsnrtowcs_l(wchar_t * __dest, const char **__src, size_t 
__nms,
   size_t __len, mbstate_t *__ps, locale_t __l)
 {
@@ -68,7 +68,7 @@ size_t __libcpp_mbsnrtowcs_l(wchar_t * _
 return mbsnrtowcs(__dest, __src, __nms, __len, __ps);
 }
 
-inline 

[libcxx] r336368 - [NFC] Add to the synopsis of

2018-07-05 Thread Louis Dionne via cfe-commits
Author: ldionne
Date: Thu Jul  5 09:16:03 2018
New Revision: 336368

URL: http://llvm.org/viewvc/llvm-project?rev=336368=rev
Log:
[NFC] Add  to the synopsis of 

Summary:
It is part of the synopsis in the Standard and  does include it,
but it was left out of the synopsis comment.

Reviewers: EricWF, mclow.lists

Subscribers: christof, llvm-commits

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

Modified:
libcxx/trunk/include/utility

Modified: libcxx/trunk/include/utility
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/utility?rev=336368=336367=336368=diff
==
--- libcxx/trunk/include/utility (original)
+++ libcxx/trunk/include/utility Thu Jul  5 09:16:03 2018
@@ -14,6 +14,8 @@
 /*
 utility synopsis
 
+#include 
+
 namespace std
 {
 


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


RE: r334650 - Implement constexpr __builtin_*_overflow

2018-07-05 Thread Keane, Erich via cfe-commits
Fixed in R336364.  Thank you very much for the heads up!

From: Evgenii Stepanov [mailto:eugeni.stepa...@gmail.com]
Sent: Tuesday, July 3, 2018 12:59 PM
To: Keane, Erich 
Cc: cfe-commits 
Subject: Re: r334650 - Implement constexpr __builtin_*_overflow

Hi,

with this change, the following compiles to "ret i32 undef":

int main(int argc, char **argv) {
  constexpr int x = 1;
  constexpr int y = 2;
  int z;

  __builtin_sadd_overflow(x, y, );
  return z;
}


On Wed, Jun 13, 2018 at 1:43 PM, Erich Keane via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:
Author: erichkeane
Date: Wed Jun 13 13:43:27 2018
New Revision: 334650

URL: http://llvm.org/viewvc/llvm-project?rev=334650=rev
Log:
Implement constexpr __builtin_*_overflow

As requested here:https://bugs.llvm.org/show_bug.cgi?id=37633
permit the __builtin_*_overflow builtins in constexpr functions.

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

Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/builtins-overflow.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=334650=334649=334650=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Wed Jun 13 13:43:27 2018
@@ -8155,6 +8155,124 @@ bool IntExprEvaluator::VisitBuiltinCallE
   case Builtin::BIomp_is_initial_device:
 // We can decide statically which value the runtime would return if called.
 return Success(Info.getLangOpts().OpenMPIsDevice ? 0 : 1, E);
+  case Builtin::BI__builtin_add_overflow:
+  case Builtin::BI__builtin_sub_overflow:
+  case Builtin::BI__builtin_mul_overflow:
+  case Builtin::BI__builtin_sadd_overflow:
+  case Builtin::BI__builtin_uadd_overflow:
+  case Builtin::BI__builtin_uaddl_overflow:
+  case Builtin::BI__builtin_uaddll_overflow:
+  case Builtin::BI__builtin_usub_overflow:
+  case Builtin::BI__builtin_usubl_overflow:
+  case Builtin::BI__builtin_usubll_overflow:
+  case Builtin::BI__builtin_umul_overflow:
+  case Builtin::BI__builtin_umull_overflow:
+  case Builtin::BI__builtin_umulll_overflow:
+  case Builtin::BI__builtin_saddl_overflow:
+  case Builtin::BI__builtin_saddll_overflow:
+  case Builtin::BI__builtin_ssub_overflow:
+  case Builtin::BI__builtin_ssubl_overflow:
+  case Builtin::BI__builtin_ssubll_overflow:
+  case Builtin::BI__builtin_smul_overflow:
+  case Builtin::BI__builtin_smull_overflow:
+  case Builtin::BI__builtin_smulll_overflow: {
+LValue ResultLValue;
+APSInt LHS, RHS;
+
+QualType ResultType = E->getArg(2)->getType()->getPointeeType();
+if (!EvaluateInteger(E->getArg(0), LHS, Info) ||
+!EvaluateInteger(E->getArg(1), RHS, Info) ||
+!EvaluatePointer(E->getArg(2), ResultLValue, Info))
+  return false;
+
+APSInt Result;
+bool DidOverflow = false;
+
+// If the types don't have to match, enlarge all 3 to the largest of them.
+if (BuiltinOp == Builtin::BI__builtin_add_overflow ||
+BuiltinOp == Builtin::BI__builtin_sub_overflow ||
+BuiltinOp == Builtin::BI__builtin_mul_overflow) {
+  bool IsSigned = LHS.isSigned() || RHS.isSigned() ||
+  ResultType->isSignedIntegerOrEnumerationType();
+  bool AllSigned = LHS.isSigned() && RHS.isSigned() &&
+  ResultType->isSignedIntegerOrEnumerationType();
+  uint64_t LHSSize = LHS.getBitWidth();
+  uint64_t RHSSize = RHS.getBitWidth();
+  uint64_t ResultSize = Info.Ctx.getTypeSize(ResultType);
+  uint64_t MaxBits = std::max(std::max(LHSSize, RHSSize), ResultSize);
+
+  // Add an additional bit if the signedness isn't uniformly agreed to. We
+  // could do this ONLY if there is a signed and an unsigned that both have
+  // MaxBits, but the code to check that is pretty nasty.  The issue will 
be
+  // caught in the shrink-to-result later anyway.
+  if (IsSigned && !AllSigned)
+++MaxBits;
+
+  LHS = APSInt(IsSigned ? LHS.sextOrSelf(MaxBits) : 
LHS.zextOrSelf(MaxBits),
+   !IsSigned);
+  RHS = APSInt(IsSigned ? RHS.sextOrSelf(MaxBits) : 
RHS.zextOrSelf(MaxBits),
+   !IsSigned);
+  Result = APSInt(MaxBits, !IsSigned);
+}
+
+// Find largest int.
+switch (BuiltinOp) {
+default:
+  llvm_unreachable("Invalid value for BuiltinOp");
+case Builtin::BI__builtin_add_overflow:
+case Builtin::BI__builtin_sadd_overflow:
+case Builtin::BI__builtin_saddl_overflow:
+case Builtin::BI__builtin_saddll_overflow:
+case Builtin::BI__builtin_uadd_overflow:
+case Builtin::BI__builtin_uaddl_overflow:
+case Builtin::BI__builtin_uaddll_overflow:
+  Result = LHS.isSigned() ? LHS.sadd_ov(RHS, DidOverflow)
+  : LHS.uadd_ov(RHS, DidOverflow);
+  break;
+case Builtin::BI__builtin_sub_overflow:
+case Builtin::BI__builtin_ssub_overflow:

r336364 - Fix __builtin_*_overflow when out-param isn't constexpr

2018-07-05 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Thu Jul  5 08:52:58 2018
New Revision: 336364

URL: http://llvm.org/viewvc/llvm-project?rev=336364=rev
Log:
Fix __builtin_*_overflow when out-param isn't constexpr

As brought up on cfe-commits[1], r334650 causes the dependency of the
out parameter to the __builtin_*_overflow functions to be ignored. The result
was a usage that was otherwise constexpr (both operands to the operation were
constexpr) would be evaluated, but the out parameter wouldn't be modified, so
it would still be 'undef'.

This patch correctly handles the return value of handleAssignment to ensure that
this value is properly considered/evaluated.

[1] http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20180702/233667.html

Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/CodeGenCXX/builtins.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=336364=336363=336364=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Jul  5 08:52:58 2018
@@ -8346,7 +8346,8 @@ bool IntExprEvaluator::VisitBuiltinCallE
 }
 
 APValue APV{Result};
-handleAssignment(Info, E, ResultLValue, ResultType, APV);
+if (!handleAssignment(Info, E, ResultLValue, ResultType, APV))
+  return false;
 return Success(DidOverflow, E);
   }
   }

Modified: cfe/trunk/test/CodeGenCXX/builtins.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/builtins.cpp?rev=336364=336363=336364=diff
==
--- cfe/trunk/test/CodeGenCXX/builtins.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/builtins.cpp Thu Jul  5 08:52:58 2018
@@ -30,3 +30,19 @@ long y = __builtin_abs(-2l);
 extern const char char_memchr_arg[32];
 char *memchr_result = __builtin_char_memchr(char_memchr_arg, 123, 32);
 // CHECK: call i8* @memchr(i8* getelementptr inbounds ([32 x i8], [32 x i8]* 
@char_memchr_arg, i32 0, i32 0), i32 123, i64 32)
+
+int constexpr_overflow_result() {
+  constexpr int x = 1;
+  // CHECK: alloca i32
+  constexpr int y = 2;
+  // CHECK: alloca i32
+  int z;
+  // CHECK: [[Z:%.+]] = alloca i32
+
+  __builtin_sadd_overflow(x, y, );
+  return z;
+  // CHECK: [[RET_PTR:%.+]] = extractvalue { i32, i1 } %0, 0
+  // CHECK: store i32 [[RET_PTR]], i32* [[Z]]
+  // CHECK: [[RET_VAL:%.+]] = load i32, i32* [[Z]]
+  // CHECK: ret i32 [[RET_VAL]]
+}


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


[PATCH] D47154: Try to make builtin address space declarations not useless

2018-07-05 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: lib/CodeGen/CGBuiltin.cpp:3500
+if (auto *PtrTy = dyn_cast(PTy)) {
+  if (PtrTy->getAddressSpace() !=
+  ArgValue->getType()->getPointerAddressSpace()) {

arsenm wrote:
> Anastasia wrote:
> > arsenm wrote:
> > > Anastasia wrote:
> > > > Would this be correct for OpenCL? Should we use  
> > > > `isAddressSpaceSupersetOf` helper instead? Would it also sort the issue 
> > > > with constant AS (at least for OpenCL)? 
> > > The issue I mentioned for the other builtin is that it modifies the 
> > > memory, and doesn't have to do with the casting.
> > > 
> > > At this point the AddrSpaceCast has to be emitted. The checking if the 
> > > cast is legal I guess would be in the SemaExpr part. I know at one point 
> > > I was trying to use isAddressSpaceSupersetOf in 
> > > rewriteBuiltinFunctionDecl, but there was some problem with that. I think 
> > > it didn't make sense with the magic where the builtin without an address 
> > > space is supposed to accept any address space or something along those 
> > > lines.
> > Yes, I think Sema has to check it before indeed. I am not sure it works 
> > right with OpenCL rules though for the Builtin functions.  Would it make 
> > sense to add a negative test for this then? 
> I'm not sure what this test would look like. Do you mean a test that 
> erroneously is accepted now?
Ok, so at this point you are trying to change generation of `bitcast` to 
`addrspacecast` which makes sense to me. Do we still need a `bitcast` though?

I think `addrspacecast` can be used to convert type and address space too:
  The ‘addrspacecast‘ instruction converts ptrval from pty in address space n 
to type pty2 in address space m.

It would be nice to add proper Sema checking for `Builtins` for address space 
of pointers in OpenCL mode, but this might be more work.



Comment at: test/CodeGenOpenCL/numbered-address-space.cl:36
+#if 0
+// XXX: Should this compile?
+void 
test_generic_as_to_builtin_parameter_explicit_cast_numeric(__attribute__((address_space(3)))
 int *local_ptr, float src) {

arsenm wrote:
> Anastasia wrote:
> > `__attribute__((address_space(N)))` is not an OpenCL feature and I think 
> > it's not specified in C either? But I think generally non matching address 
> > spaces don't compile in Clang. So it might be useful to disallow this?
> I'm pretty sure it's a C extension. The way things seem to work now is 
> address spaces are accepted anywhere and everywhere.
Yes, the line below should give an error for OpenCL?
  generic int* generic_ptr = local_ptr;


https://reviews.llvm.org/D47154



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


[PATCH] D48721: Patch to fix pragma metadata for do-while loops

2018-07-05 Thread Deepak Panickal via Phabricator via cfe-commits
deepak2427 updated this revision to Diff 154244.
deepak2427 added a comment.

Updated with test from Bjorn Pettersson which is much more accurate and 
clearer. Thanks!


https://reviews.llvm.org/D48721

Files:
  lib/CodeGen/CGStmt.cpp
  test/CodeGen/pragma-do-while.cpp


Index: test/CodeGen/pragma-do-while.cpp
===
--- /dev/null
+++ test/CodeGen/pragma-do-while.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+
+// We expect to get a loop structure like this:
+//do.body:   ; preds = %do.cond, ...
+//  ...
+//  br label %do.cond
+//do.cond:   ; preds = %do.body
+//  ...
+//  br i1 %cmp, label %do.body, label %do.end
+//do.end:; preds = %do.cond
+//  ...
+//
+// Verify that the loop metadata only is put on the backedge.
+//
+// CHECK-NOT: llvm.loop
+// CHECK-LABEL: do.cond:
+// CHECK: br {{.*}}, label %do.body, label %do.end, !llvm.loop ![[LMD1:[0-9]+]]
+// CHECK-LABEL: do.end:
+// CHECK-NOT: llvm.loop
+// CHECK: ![[LMD1]] = distinct !{![[LMD1]], ![[LMD2:[0-9]+]]}
+// CHECK: ![[LMD2]] = !{!"llvm.loop.unroll.count", i32 4}
+
+int test(int a[], int n) {
+  int i = 0;
+  int sum = 0;
+
+#pragma unroll 4
+  do
+  {
+a[i] = a[i] + 1;
+sum = sum + a[i];
+i++;
+  } while (i < n);
+
+  return sum;
+}
Index: lib/CodeGen/CGStmt.cpp
===
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -777,19 +777,19 @@
   // Emit the body of the loop.
   llvm::BasicBlock *LoopBody = createBasicBlock("do.body");
 
-  const SourceRange  = S.getSourceRange();
-  LoopStack.push(LoopBody, CGM.getContext(), DoAttrs,
- SourceLocToDebugLoc(R.getBegin()),
- SourceLocToDebugLoc(R.getEnd()));
-
   EmitBlockWithFallThrough(LoopBody, );
   {
 RunCleanupsScope BodyScope(*this);
 EmitStmt(S.getBody());
   }
 
   EmitBlock(LoopCond.getBlock());
 
+  const SourceRange  = S.getSourceRange();
+  LoopStack.push(LoopBody, CGM.getContext(), DoAttrs,
+ SourceLocToDebugLoc(R.getBegin()),
+ SourceLocToDebugLoc(R.getEnd()));
+
   // C99 6.8.5.2: "The evaluation of the controlling expression takes place
   // after each execution of the loop body."
 


Index: test/CodeGen/pragma-do-while.cpp
===
--- /dev/null
+++ test/CodeGen/pragma-do-while.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+
+// We expect to get a loop structure like this:
+//do.body:   ; preds = %do.cond, ...
+//  ...
+//  br label %do.cond
+//do.cond:   ; preds = %do.body
+//  ...
+//  br i1 %cmp, label %do.body, label %do.end
+//do.end:; preds = %do.cond
+//  ...
+//
+// Verify that the loop metadata only is put on the backedge.
+//
+// CHECK-NOT: llvm.loop
+// CHECK-LABEL: do.cond:
+// CHECK: br {{.*}}, label %do.body, label %do.end, !llvm.loop ![[LMD1:[0-9]+]]
+// CHECK-LABEL: do.end:
+// CHECK-NOT: llvm.loop
+// CHECK: ![[LMD1]] = distinct !{![[LMD1]], ![[LMD2:[0-9]+]]}
+// CHECK: ![[LMD2]] = !{!"llvm.loop.unroll.count", i32 4}
+
+int test(int a[], int n) {
+  int i = 0;
+  int sum = 0;
+
+#pragma unroll 4
+  do
+  {
+a[i] = a[i] + 1;
+sum = sum + a[i];
+i++;
+  } while (i < n);
+
+  return sum;
+}
Index: lib/CodeGen/CGStmt.cpp
===
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -777,19 +777,19 @@
   // Emit the body of the loop.
   llvm::BasicBlock *LoopBody = createBasicBlock("do.body");
 
-  const SourceRange  = S.getSourceRange();
-  LoopStack.push(LoopBody, CGM.getContext(), DoAttrs,
- SourceLocToDebugLoc(R.getBegin()),
- SourceLocToDebugLoc(R.getEnd()));
-
   EmitBlockWithFallThrough(LoopBody, );
   {
 RunCleanupsScope BodyScope(*this);
 EmitStmt(S.getBody());
   }
 
   EmitBlock(LoopCond.getBlock());
 
+  const SourceRange  = S.getSourceRange();
+  LoopStack.push(LoopBody, CGM.getContext(), DoAttrs,
+ SourceLocToDebugLoc(R.getBegin()),
+ SourceLocToDebugLoc(R.getEnd()));
+
   // C99 6.8.5.2: "The evaluation of the controlling expression takes place
   // after each execution of the loop body."
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r335800 - [analyzer] Add support for pre-C++17 copy elision.

2018-07-05 Thread Alexander Kornienko via cfe-commits
Filed https://bugs.llvm.org/show_bug.cgi?id=38072 with an isolated test
case.

On Wed, Jul 4, 2018 at 4:18 PM Alexander Kornienko 
wrote:

> We've started seeing assertion failures after this commit.
> assert.h assertion failed at
> llvm/tools/clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:485 in static
> clang::ento::ProgramStateRef
> clang::ento::ExprEngine::elideDestructor(clang::ento::ProgramStateRef,
> const clang::CXXBindTemporaryExpr *, const clang::LocationContext *):
> !State->contains(I)
>
>
> The stack trace is
> clang::ento::ExprEngine::elideDestructor
> clang::ento::ExprEngine::prepareForObjectConstruction
> clang::ento::ExprEngine::prepareForObjectConstruction
> clang::ento::ExprEngine::VisitCXXConstructExpr
> clang::ento::ExprEngine::Visit
> clang::ento::ExprEngine::ProcessStmt
> clang::ento::ExprEngine::processCFGElement
> clang::ento::CoreEngine::HandlePostStmt
> clang::ento::CoreEngine::dispatchWorkItem
> clang::ento::CoreEngine::ExecuteWorkList
> clang::ento::ExprEngine::ExecuteWorkList
> ::AnalysisConsumer::ActionExprEngine
> ::AnalysisConsumer::HandleCode
> ::AnalysisConsumer::HandleDeclsCallGraph
> ::AnalysisConsumer::runAnalysisOnTranslationUnit
> ::AnalysisConsumer::HandleTranslationUnit
>
> I haven't come up with a test case yet.
>
> On Thu, Jun 28, 2018 at 2:34 AM Artem Dergachev via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: dergachev
>> Date: Wed Jun 27 17:30:18 2018
>> New Revision: 335800
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=335800=rev
>> Log:
>> [analyzer] Add support for pre-C++17 copy elision.
>>
>> r335795 adds copy elision information to CFG. This commit allows static
>> analyzer
>> to elide elidable copy constructors by constructing the objects that were
>> previously subject to elidable copy directly in the target region of the
>> copy.
>>
>> The chain of elided constructors may potentially be indefinitely long.
>> This
>> only happens when the object is being returned from a function which in
>> turn is
>> returned from another function, etc.
>>
>> NRVO is not supported yet.
>>
>> Differential Revision: https://reviews.llvm.org/D47671
>>
>> Modified:
>> cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
>> cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
>> cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
>> cfe/trunk/test/Analysis/cxx17-mandatory-elision.cpp
>> cfe/trunk/test/Analysis/gtest.cpp
>> cfe/trunk/test/Analysis/inlining/temp-dtors-path-notes.cpp
>> cfe/trunk/test/Analysis/lifetime-extension.cpp
>> cfe/trunk/test/Analysis/temporaries.cpp
>>
>> Modified:
>> cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h?rev=335800=335799=335800=diff
>>
>> ==
>> ---
>> cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
>> (original)
>> +++
>> cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h Wed
>> Jun 27 17:30:18 2018
>> @@ -780,9 +780,30 @@ private:
>>llvm::PointerUnion P,
>>const LocationContext *LC);
>>
>> +  /// If the given expression corresponds to a temporary that was used
>> for
>> +  /// passing into an elidable copy/move constructor and that constructor
>> +  /// was actually elided, track that we also need to elide the
>> destructor.
>> +  static ProgramStateRef elideDestructor(ProgramStateRef State,
>> + const CXXBindTemporaryExpr *BTE,
>> + const LocationContext *LC);
>> +
>> +  /// Stop tracking the destructor that corresponds to an elided
>> constructor.
>> +  static ProgramStateRef
>> +  cleanupElidedDestructor(ProgramStateRef State,
>> +  const CXXBindTemporaryExpr *BTE,
>> +  const LocationContext *LC);
>> +
>> +  /// Returns true if the given expression corresponds to a temporary
>> that
>> +  /// was constructed for passing into an elidable copy/move constructor
>> +  /// and that constructor was actually elided.
>> +  static bool isDestructorElided(ProgramStateRef State,
>> + const CXXBindTemporaryExpr *BTE,
>> + const LocationContext *LC);
>> +
>>/// Check if all objects under construction have been fully constructed
>>/// for the given context range (including FromLC, not including ToLC).
>> -  /// This is useful for assertions.
>> +  /// This is useful for assertions. Also checks if elided destructors
>> +  /// were cleaned up.
>>static bool areAllObjectsFullyConstructed(ProgramStateRef State,
>>  const LocationContext
>> *FromLC,
>>  const LocationContext *ToLC);
>>
>> Modified: 

[PATCH] D48721: Patch to fix pragma metadata for do-while loops

2018-07-05 Thread Deepak Panickal via Phabricator via cfe-commits
deepak2427 added a comment.

Yeah, you're right. Only one loop has to be checked in this case. I'll update 
the test as per your suggestion. Thank you!


https://reviews.llvm.org/D48721



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


[PATCH] D48721: Patch to fix pragma metadata for do-while loops

2018-07-05 Thread Bjorn Pettersson via Phabricator via cfe-commits
bjope added inline comments.



Comment at: test/CodeGen/pragma-do-while.cpp:1
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+int test(int a[], int n) {

I think that we can simplify it to use one loop here (as a regression test that 
we only put the label on one branch).

I also think that the important check is to verify that the llvm.loop is put on 
the branch in the "do.cond" block.

So may I suggest this slightly modified test case:


```
// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s

// We expect to get a loop structure like this:
//do.body:   ; preds = %do.cond, ...
//  ...
//  br label %do.cond
//do.cond:   ; preds = %do.body
//  ...
//  br i1 %cmp, label %do.body, label %do.end
//do.end:; preds = %do.cond
//  ...
//
// Verify that the loop metadata only is put on the backedge.
//
// CHECK-NOT: llvm.loop
// CHECK-LABEL: do.cond:
// CHECK: br {{.*}}, label %do.body, label %do.end, !llvm.loop ![[LMD1:[0-9]+]]
// CHECK-LABEL: do.end:
// CHECK-NOT: llvm.loop
// CHECK: ![[LMD1]] = distinct !{![[LMD1]], ![[LMD2:[0-9]+]]}
// CHECK: ![[LMD2]] = !{!"llvm.loop.unroll.count", i32 4}

int test(int a[], int n) {
  int i = 0;
  int sum = 0;

#pragma unroll 4
  do
  {
a[i] = a[i] + 1;
sum = sum + a[i];
i++;
  } while (i < n);

  return sum;
}
```


https://reviews.llvm.org/D48721



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


[clang-tools-extra] r336358 - [clang-move] ClangMoveTests: Remove dots in output paths

2018-07-05 Thread Simon Marchi via cfe-commits
Author: simark
Date: Thu Jul  5 07:53:17 2018
New Revision: 336358

URL: http://llvm.org/viewvc/llvm-project?rev=336358=rev
Log:
[clang-move] ClangMoveTests: Remove dots in output paths

Summary:
Following D48903 ([VirtualFileSystem] InMemoryFileSystem::status: Return
a Status with the requested name), the paths output by clang-move in the
FileToReplacements map may contain leading "./".  For example, where we
would get "foo.h", we'll now get "./foo.h".  This breaks the tests,
because we are doing exact string lookups in the FileToFileID and
Results maps (they contain "foo.h", but we search for "./foo.h").

To mitigate this, try to normalize a little bit the paths output by
clang-move to remove that leading "./".

This patch should be safe to merge before D48903, remove_dots will just
be a no-op.

Reviewers: ilya-biryukov, hokein

Reviewed By: hokein

Subscribers: ioeric, cfe-commits

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

Modified:
clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp

Modified: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp?rev=336358=336357=336358=diff
==
--- clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp Thu Jul  5 
07:53:17 2018
@@ -239,8 +239,10 @@ runClangMoveOnCode(const move::MoveDefin
   // The Key is file name, value is the new code after moving the class.
   std::map Results;
   for (const auto  : FileToReplacements) {
-StringRef FilePath = It.first;
-Results[FilePath] = Context.getRewrittenText(FileToFileID[FilePath]);
+// The path may come out as "./foo.h", normalize to "foo.h".
+SmallString<32> FilePath (It.first);
+llvm::sys::path::remove_dots(FilePath);
+Results[FilePath.str().str()] = 
Context.getRewrittenText(FileToFileID[FilePath]);
   }
   return Results;
 }


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


[PATCH] D48973: [SemaCodeComplete] Expose a method to create CodeCompletionString for macros.

2018-07-05 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Could you give a little more context about how this will be used? (where the 
completion items come from, and when the strings will get built)




Comment at: include/clang/Sema/CodeCompleteConsumer.h:921
bool IncludeBriefComments);
+  CodeCompletionString *
+  CreateCodeCompletionStringForMacro(Preprocessor ,

please document the new function - particularly why it's different and what's 
the use case it supports
(if I understand right, it's to allow storing CodeCompletionResult instances 
for later stringification only when they're for macros - why?)

One of the args you're *not* taking here is ASTContext, but if I understand 
right it must still be alive: `this->Macro` points into the IdentifierTable 
which is owned by ASTContext.
In some sense taking this arg seems like a safety feature!


Repository:
  rC Clang

https://reviews.llvm.org/D48973



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


[PATCH] D48951: [clang-move] ClangMoveTests: Remove dots in output paths

2018-07-05 Thread Simon Marchi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL336358: [clang-move] ClangMoveTests: Remove dots in output 
paths (authored by simark, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D48951

Files:
  clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp


Index: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
===
--- clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
+++ clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
@@ -239,8 +239,10 @@
   // The Key is file name, value is the new code after moving the class.
   std::map Results;
   for (const auto  : FileToReplacements) {
-StringRef FilePath = It.first;
-Results[FilePath] = Context.getRewrittenText(FileToFileID[FilePath]);
+// The path may come out as "./foo.h", normalize to "foo.h".
+SmallString<32> FilePath (It.first);
+llvm::sys::path::remove_dots(FilePath);
+Results[FilePath.str().str()] = 
Context.getRewrittenText(FileToFileID[FilePath]);
   }
   return Results;
 }


Index: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
===
--- clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
+++ clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
@@ -239,8 +239,10 @@
   // The Key is file name, value is the new code after moving the class.
   std::map Results;
   for (const auto  : FileToReplacements) {
-StringRef FilePath = It.first;
-Results[FilePath] = Context.getRewrittenText(FileToFileID[FilePath]);
+// The path may come out as "./foo.h", normalize to "foo.h".
+SmallString<32> FilePath (It.first);
+llvm::sys::path::remove_dots(FilePath);
+Results[FilePath.str().str()] = Context.getRewrittenText(FileToFileID[FilePath]);
   }
   return Results;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48903: [VirtualFileSystem] InMemoryFileSystem::status: Return a Status with the requested name

2018-07-05 Thread Simon Marchi via Phabricator via cfe-commits
simark added a comment.

In https://reviews.llvm.org/D48903#1153142, @hokein wrote:

> Seems to me you have a few comments unaddressed (and make sure you marked 
> them done when updating the patch).


Ah damn I missed them, I'm not too used to how Phabricator displays things.  
I'll do that.


Repository:
  rC Clang

https://reviews.llvm.org/D48903



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


[PATCH] D48973: [SemaCodeComplete] Expose a method to create CodeCompletionString for macros.

2018-07-05 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.
ioeric added a reviewer: sammccall.
Herald added a subscriber: cfe-commits.

The method only takes PPreprocessor and don't require structures that
might not be available (e.g. Sema and ASTContext) when CodeCompletionString
needs to be generated for macros.


Repository:
  rC Clang

https://reviews.llvm.org/D48973

Files:
  include/clang/Sema/CodeCompleteConsumer.h
  lib/Sema/SemaCodeComplete.cpp

Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -2745,6 +2745,52 @@
 CCTUInfo, IncludeBriefComments);
 }
 
+CodeCompletionString *CodeCompletionResult::CreateCodeCompletionStringForMacro(
+Preprocessor , CodeCompletionAllocator ,
+CodeCompletionTUInfo ) {
+  assert(Kind == RK_Macro);
+  CodeCompletionBuilder Result(Allocator, CCTUInfo, Priority, Availability);
+  const MacroInfo *MI = PP.getMacroInfo(Macro);
+  Result.AddTypedTextChunk(Result.getAllocator().CopyString(Macro->getName()));
+
+  if (!MI || !MI->isFunctionLike())
+return Result.TakeString();
+
+  // Format a function-like macro with placeholders for the arguments.
+  Result.AddChunk(CodeCompletionString::CK_LeftParen);
+  MacroInfo::param_iterator A = MI->param_begin(), AEnd = MI->param_end();
+
+  // C99 variadic macros add __VA_ARGS__ at the end. Skip it.
+  if (MI->isC99Varargs()) {
+--AEnd;
+
+if (A == AEnd) {
+  Result.AddPlaceholderChunk("...");
+}
+  }
+
+  for (MacroInfo::param_iterator A = MI->param_begin(); A != AEnd; ++A) {
+if (A != MI->param_begin())
+  Result.AddChunk(CodeCompletionString::CK_Comma);
+
+if (MI->isVariadic() && (A + 1) == AEnd) {
+  SmallString<32> Arg = (*A)->getName();
+  if (MI->isC99Varargs())
+Arg += ", ...";
+  else
+Arg += "...";
+  Result.AddPlaceholderChunk(Result.getAllocator().CopyString(Arg));
+  break;
+}
+
+// Non-variadic macros are simple.
+Result.AddPlaceholderChunk(
+Result.getAllocator().CopyString((*A)->getName()));
+  }
+  Result.AddChunk(CodeCompletionString::CK_RightParen);
+  return Result.TakeString();
+}
+
 /// If possible, create a new code completion string for the given
 /// result.
 ///
@@ -2758,6 +2804,9 @@
CodeCompletionAllocator ,
CodeCompletionTUInfo ,
bool IncludeBriefComments) {
+  if (Kind == RK_Macro)
+return CreateCodeCompletionStringForMacro(PP, Allocator, CCTUInfo);
+
   CodeCompletionBuilder Result(Allocator, CCTUInfo, Priority, Availability);
   
   PrintingPolicy Policy = getCompletionPrintingPolicy(Ctx, PP);
@@ -2783,49 +2832,6 @@
 return Result.TakeString();
   }
   
-  if (Kind == RK_Macro) {
-const MacroInfo *MI = PP.getMacroInfo(Macro);
-Result.AddTypedTextChunk(
-Result.getAllocator().CopyString(Macro->getName()));
-
-if (!MI || !MI->isFunctionLike())
-  return Result.TakeString();
-
-// Format a function-like macro with placeholders for the arguments.
-Result.AddChunk(CodeCompletionString::CK_LeftParen);
-MacroInfo::param_iterator A = MI->param_begin(), AEnd = MI->param_end();
-
-// C99 variadic macros add __VA_ARGS__ at the end. Skip it.
-if (MI->isC99Varargs()) {
-  --AEnd;
-  
-  if (A == AEnd) {
-Result.AddPlaceholderChunk("...");
-  }
-}
-
-for (MacroInfo::param_iterator A = MI->param_begin(); A != AEnd; ++A) {
-  if (A != MI->param_begin())
-Result.AddChunk(CodeCompletionString::CK_Comma);
-
-  if (MI->isVariadic() && (A+1) == AEnd) {
-SmallString<32> Arg = (*A)->getName();
-if (MI->isC99Varargs())
-  Arg += ", ...";
-else
-  Arg += "...";
-Result.AddPlaceholderChunk(Result.getAllocator().CopyString(Arg));
-break;
-  }
-
-  // Non-variadic macros are simple.
-  Result.AddPlaceholderChunk(
-  Result.getAllocator().CopyString((*A)->getName()));
-}
-Result.AddChunk(CodeCompletionString::CK_RightParen);
-return Result.TakeString();
-  }
-  
   assert(Kind == RK_Declaration && "Missed a result kind?");
   const NamedDecl *ND = Declaration;
   Result.addParentContext(ND->getDeclContext());
Index: include/clang/Sema/CodeCompleteConsumer.h
===
--- include/clang/Sema/CodeCompleteConsumer.h
+++ include/clang/Sema/CodeCompleteConsumer.h
@@ -918,6 +918,10 @@
CodeCompletionAllocator ,
CodeCompletionTUInfo ,
bool IncludeBriefComments);
+  CodeCompletionString *
+  CreateCodeCompletionStringForMacro(Preprocessor ,
+

[PATCH] D48903: [VirtualFileSystem] InMemoryFileSystem::status: Return a Status with the requested name

2018-07-05 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

Seems to me you have a few comments unaddressed (and make sure you marked them 
done when updating the patch).


Repository:
  rC Clang

https://reviews.llvm.org/D48903



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


[PATCH] D48951: [clang-move] ClangMoveTests: Remove dots in output paths

2018-07-05 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

Looks good.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48951



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


[PATCH] D48721: Patch to fix pragma metadata for do-while loops

2018-07-05 Thread Deepak Panickal via Phabricator via cfe-commits
deepak2427 added a comment.

I have updated the test to not run the optimizer. The test I had added 
previously for checking if the unroller is respecting the pragma is useful I 
think. Not sure where that can be added though. 
I guess it's independent of this patch anyway. If the patch and test is okay, 
will update bugzilla as well.


https://reviews.llvm.org/D48721



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


[PATCH] D48721: Patch to fix pragma metadata for do-while loops

2018-07-05 Thread Deepak Panickal via Phabricator via cfe-commits
deepak2427 updated this revision to Diff 154237.
deepak2427 added a comment.

Update the tests.


https://reviews.llvm.org/D48721

Files:
  lib/CodeGen/CGStmt.cpp
  test/CodeGen/pragma-do-while.cpp


Index: test/CodeGen/pragma-do-while.cpp
===
--- /dev/null
+++ test/CodeGen/pragma-do-while.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+int test(int a[], int n) {
+  int i = 0;
+  int sum = 0;
+
+//CHECK-NOT: llvm.loop
+
+#pragma unroll 4
+  do
+  //CHECK: do.body:
+  //CHECK: llvm.loop
+  {
+a[i] = a[i] + 1;
+sum = sum + a[i];
+i++;
+  } while (i < n);
+
+  i = 0;
+
+#pragma unroll 8
+  do
+  //CHECK: do.body{{[0-9]+}}:
+  //CHECK: llvm.loop
+  {
+a[i] = a[i] + 1;
+sum = sum + a[i];
+i++;
+  } while (i < n);
+
+  return sum;
+}
Index: lib/CodeGen/CGStmt.cpp
===
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -777,19 +777,19 @@
   // Emit the body of the loop.
   llvm::BasicBlock *LoopBody = createBasicBlock("do.body");
 
-  const SourceRange  = S.getSourceRange();
-  LoopStack.push(LoopBody, CGM.getContext(), DoAttrs,
- SourceLocToDebugLoc(R.getBegin()),
- SourceLocToDebugLoc(R.getEnd()));
-
   EmitBlockWithFallThrough(LoopBody, );
   {
 RunCleanupsScope BodyScope(*this);
 EmitStmt(S.getBody());
   }
 
   EmitBlock(LoopCond.getBlock());
 
+  const SourceRange  = S.getSourceRange();
+  LoopStack.push(LoopBody, CGM.getContext(), DoAttrs,
+ SourceLocToDebugLoc(R.getBegin()),
+ SourceLocToDebugLoc(R.getEnd()));
+
   // C99 6.8.5.2: "The evaluation of the controlling expression takes place
   // after each execution of the loop body."
 


Index: test/CodeGen/pragma-do-while.cpp
===
--- /dev/null
+++ test/CodeGen/pragma-do-while.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+int test(int a[], int n) {
+  int i = 0;
+  int sum = 0;
+
+//CHECK-NOT: llvm.loop
+
+#pragma unroll 4
+  do
+  //CHECK: do.body:
+  //CHECK: llvm.loop
+  {
+a[i] = a[i] + 1;
+sum = sum + a[i];
+i++;
+  } while (i < n);
+
+  i = 0;
+
+#pragma unroll 8
+  do
+  //CHECK: do.body{{[0-9]+}}:
+  //CHECK: llvm.loop
+  {
+a[i] = a[i] + 1;
+sum = sum + a[i];
+i++;
+  } while (i < n);
+
+  return sum;
+}
Index: lib/CodeGen/CGStmt.cpp
===
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -777,19 +777,19 @@
   // Emit the body of the loop.
   llvm::BasicBlock *LoopBody = createBasicBlock("do.body");
 
-  const SourceRange  = S.getSourceRange();
-  LoopStack.push(LoopBody, CGM.getContext(), DoAttrs,
- SourceLocToDebugLoc(R.getBegin()),
- SourceLocToDebugLoc(R.getEnd()));
-
   EmitBlockWithFallThrough(LoopBody, );
   {
 RunCleanupsScope BodyScope(*this);
 EmitStmt(S.getBody());
   }
 
   EmitBlock(LoopCond.getBlock());
 
+  const SourceRange  = S.getSourceRange();
+  LoopStack.push(LoopBody, CGM.getContext(), DoAttrs,
+ SourceLocToDebugLoc(R.getBegin()),
+ SourceLocToDebugLoc(R.getEnd()));
+
   // C99 6.8.5.2: "The evaluation of the controlling expression takes place
   // after each execution of the loop body."
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48715: [X86] Fix some vector cmp builtins - TRUE/FALSE predicates

2018-07-05 Thread Gabor Buella via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC336355: [X86] Fix some vector cmp builtins - TRUE/FALSE 
predicates (authored by GBuella, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D48715

Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/avx-builtins.c
  test/CodeGen/avx512f-builtins.c
  test/CodeGen/avx512vl-builtins.c

Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -10158,43 +10158,38 @@
 // e.g. both _CMP_GT_OS & _CMP_GT_OQ are translated to FCMP_OGT.
 FCmpInst::Predicate Pred;
 switch (CC) {
-case 0x00: Pred = FCmpInst::FCMP_OEQ; break;
-case 0x01: Pred = FCmpInst::FCMP_OLT; break;
-case 0x02: Pred = FCmpInst::FCMP_OLE; break;
-case 0x03: Pred = FCmpInst::FCMP_UNO; break;
-case 0x04: Pred = FCmpInst::FCMP_UNE; break;
-case 0x05: Pred = FCmpInst::FCMP_UGE; break;
-case 0x06: Pred = FCmpInst::FCMP_UGT; break;
-case 0x07: Pred = FCmpInst::FCMP_ORD; break;
-case 0x08: Pred = FCmpInst::FCMP_UEQ; break;
-case 0x09: Pred = FCmpInst::FCMP_ULT; break;
-case 0x0a: Pred = FCmpInst::FCMP_ULE; break;
-case 0x0c: Pred = FCmpInst::FCMP_ONE; break;
-case 0x0d: Pred = FCmpInst::FCMP_OGE; break;
-case 0x0e: Pred = FCmpInst::FCMP_OGT; break;
-case 0x10: Pred = FCmpInst::FCMP_OEQ; break;
-case 0x11: Pred = FCmpInst::FCMP_OLT; break;
-case 0x12: Pred = FCmpInst::FCMP_OLE; break;
-case 0x13: Pred = FCmpInst::FCMP_UNO; break;
-case 0x14: Pred = FCmpInst::FCMP_UNE; break;
-case 0x15: Pred = FCmpInst::FCMP_UGE; break;
-case 0x16: Pred = FCmpInst::FCMP_UGT; break;
-case 0x17: Pred = FCmpInst::FCMP_ORD; break;
-case 0x18: Pred = FCmpInst::FCMP_UEQ; break;
-case 0x19: Pred = FCmpInst::FCMP_ULT; break;
-case 0x1a: Pred = FCmpInst::FCMP_ULE; break;
-case 0x1c: Pred = FCmpInst::FCMP_ONE; break;
-case 0x1d: Pred = FCmpInst::FCMP_OGE; break;
-case 0x1e: Pred = FCmpInst::FCMP_OGT; break;
-// _CMP_TRUE_UQ, _CMP_TRUE_US produce -1,-1... vector
-// on any input and _CMP_FALSE_OQ, _CMP_FALSE_OS produce 0, 0...
-case 0x0b: // FALSE_OQ
-case 0x1b: // FALSE_OS
-  return llvm::Constant::getNullValue(ConvertType(E->getType()));
-case 0x0f: // TRUE_UQ
-case 0x1f: // TRUE_US
-  return llvm::Constant::getAllOnesValue(ConvertType(E->getType()));
-
+case 0x00: Pred = FCmpInst::FCMP_OEQ;   break;
+case 0x01: Pred = FCmpInst::FCMP_OLT;   break;
+case 0x02: Pred = FCmpInst::FCMP_OLE;   break;
+case 0x03: Pred = FCmpInst::FCMP_UNO;   break;
+case 0x04: Pred = FCmpInst::FCMP_UNE;   break;
+case 0x05: Pred = FCmpInst::FCMP_UGE;   break;
+case 0x06: Pred = FCmpInst::FCMP_UGT;   break;
+case 0x07: Pred = FCmpInst::FCMP_ORD;   break;
+case 0x08: Pred = FCmpInst::FCMP_UEQ;   break;
+case 0x09: Pred = FCmpInst::FCMP_ULT;   break;
+case 0x0a: Pred = FCmpInst::FCMP_ULE;   break;
+case 0x0b: Pred = FCmpInst::FCMP_FALSE; break;
+case 0x0c: Pred = FCmpInst::FCMP_ONE;   break;
+case 0x0d: Pred = FCmpInst::FCMP_OGE;   break;
+case 0x0e: Pred = FCmpInst::FCMP_OGT;   break;
+case 0x0f: Pred = FCmpInst::FCMP_TRUE;  break;
+case 0x10: Pred = FCmpInst::FCMP_OEQ;   break;
+case 0x11: Pred = FCmpInst::FCMP_OLT;   break;
+case 0x12: Pred = FCmpInst::FCMP_OLE;   break;
+case 0x13: Pred = FCmpInst::FCMP_UNO;   break;
+case 0x14: Pred = FCmpInst::FCMP_UNE;   break;
+case 0x15: Pred = FCmpInst::FCMP_UGE;   break;
+case 0x16: Pred = FCmpInst::FCMP_UGT;   break;
+case 0x17: Pred = FCmpInst::FCMP_ORD;   break;
+case 0x18: Pred = FCmpInst::FCMP_UEQ;   break;
+case 0x19: Pred = FCmpInst::FCMP_ULT;   break;
+case 0x1a: Pred = FCmpInst::FCMP_ULE;   break;
+case 0x1b: Pred = FCmpInst::FCMP_FALSE; break;
+case 0x1c: Pred = FCmpInst::FCMP_ONE;   break;
+case 0x1d: Pred = FCmpInst::FCMP_OGE;   break;
+case 0x1e: Pred = FCmpInst::FCMP_OGT;   break;
+case 0x1f: Pred = FCmpInst::FCMP_TRUE;  break;
 default: llvm_unreachable("Unhandled CC");
 }
 
Index: test/CodeGen/avx-builtins.c
===
--- test/CodeGen/avx-builtins.c
+++ test/CodeGen/avx-builtins.c
@@ -280,8 +280,7 @@
 
 __m256d test_mm256_cmp_pd_false_oq(__m256d a, __m256d b) {
   // CHECK-LABEL: test_mm256_cmp_pd_false_oq
-  // CHECK-NOT: call
-  // CHECK: ret <4 x double> zeroinitializer
+  // CHECK: fcmp false <4 x double> %{{.*}}, %{{.*}}
   return _mm256_cmp_pd(a, b, _CMP_FALSE_OQ);
 }
 
@@ -305,8 +304,7 @@
 
 __m256d test_mm256_cmp_pd_true_uq(__m256d a, __m256d b) {
   // CHECK-LABEL: test_mm256_cmp_pd_true_uq
-  // CHECK-NOT: call
-  // CHECK: ret <4 x double> 
+  // CHECK: fcmp true <4 x double> %{{.*}}, %{{.*}}
   return _mm256_cmp_pd(a, b, _CMP_TRUE_UQ);
 }
 
@@ -378,8 +376,7 @@
 
 __m256d 

r336355 - [X86] Fix some vector cmp builtins - TRUE/FALSE predicates

2018-07-05 Thread Gabor Buella via cfe-commits
Author: gbuella
Date: Thu Jul  5 07:26:56 2018
New Revision: 336355

URL: http://llvm.org/viewvc/llvm-project?rev=336355=rev
Log:
[X86] Fix some vector cmp builtins - TRUE/FALSE predicates

This patch removes on optimization used with the TRUE/FALSE
predicates, as was suggested in https://reviews.llvm.org/D45616
for r335339.
The optimization was buggy, since r335339 used it also
for *_mask builtins, without actually applying the mask -- the
mask argument was just ignored.

Reviewers: craig.topper, uriel.k, RKSimon, andrew.w.kaylor, spatel, scanon, 
efriedma

Reviewed By: spatel

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


Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGen/avx-builtins.c
cfe/trunk/test/CodeGen/avx512f-builtins.c
cfe/trunk/test/CodeGen/avx512vl-builtins.c

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=336355=336354=336355=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Jul  5 07:26:56 2018
@@ -10158,43 +10158,38 @@ Value *CodeGenFunction::EmitX86BuiltinEx
 // e.g. both _CMP_GT_OS & _CMP_GT_OQ are translated to FCMP_OGT.
 FCmpInst::Predicate Pred;
 switch (CC) {
-case 0x00: Pred = FCmpInst::FCMP_OEQ; break;
-case 0x01: Pred = FCmpInst::FCMP_OLT; break;
-case 0x02: Pred = FCmpInst::FCMP_OLE; break;
-case 0x03: Pred = FCmpInst::FCMP_UNO; break;
-case 0x04: Pred = FCmpInst::FCMP_UNE; break;
-case 0x05: Pred = FCmpInst::FCMP_UGE; break;
-case 0x06: Pred = FCmpInst::FCMP_UGT; break;
-case 0x07: Pred = FCmpInst::FCMP_ORD; break;
-case 0x08: Pred = FCmpInst::FCMP_UEQ; break;
-case 0x09: Pred = FCmpInst::FCMP_ULT; break;
-case 0x0a: Pred = FCmpInst::FCMP_ULE; break;
-case 0x0c: Pred = FCmpInst::FCMP_ONE; break;
-case 0x0d: Pred = FCmpInst::FCMP_OGE; break;
-case 0x0e: Pred = FCmpInst::FCMP_OGT; break;
-case 0x10: Pred = FCmpInst::FCMP_OEQ; break;
-case 0x11: Pred = FCmpInst::FCMP_OLT; break;
-case 0x12: Pred = FCmpInst::FCMP_OLE; break;
-case 0x13: Pred = FCmpInst::FCMP_UNO; break;
-case 0x14: Pred = FCmpInst::FCMP_UNE; break;
-case 0x15: Pred = FCmpInst::FCMP_UGE; break;
-case 0x16: Pred = FCmpInst::FCMP_UGT; break;
-case 0x17: Pred = FCmpInst::FCMP_ORD; break;
-case 0x18: Pred = FCmpInst::FCMP_UEQ; break;
-case 0x19: Pred = FCmpInst::FCMP_ULT; break;
-case 0x1a: Pred = FCmpInst::FCMP_ULE; break;
-case 0x1c: Pred = FCmpInst::FCMP_ONE; break;
-case 0x1d: Pred = FCmpInst::FCMP_OGE; break;
-case 0x1e: Pred = FCmpInst::FCMP_OGT; break;
-// _CMP_TRUE_UQ, _CMP_TRUE_US produce -1,-1... vector
-// on any input and _CMP_FALSE_OQ, _CMP_FALSE_OS produce 0, 0...
-case 0x0b: // FALSE_OQ
-case 0x1b: // FALSE_OS
-  return llvm::Constant::getNullValue(ConvertType(E->getType()));
-case 0x0f: // TRUE_UQ
-case 0x1f: // TRUE_US
-  return llvm::Constant::getAllOnesValue(ConvertType(E->getType()));
-
+case 0x00: Pred = FCmpInst::FCMP_OEQ;   break;
+case 0x01: Pred = FCmpInst::FCMP_OLT;   break;
+case 0x02: Pred = FCmpInst::FCMP_OLE;   break;
+case 0x03: Pred = FCmpInst::FCMP_UNO;   break;
+case 0x04: Pred = FCmpInst::FCMP_UNE;   break;
+case 0x05: Pred = FCmpInst::FCMP_UGE;   break;
+case 0x06: Pred = FCmpInst::FCMP_UGT;   break;
+case 0x07: Pred = FCmpInst::FCMP_ORD;   break;
+case 0x08: Pred = FCmpInst::FCMP_UEQ;   break;
+case 0x09: Pred = FCmpInst::FCMP_ULT;   break;
+case 0x0a: Pred = FCmpInst::FCMP_ULE;   break;
+case 0x0b: Pred = FCmpInst::FCMP_FALSE; break;
+case 0x0c: Pred = FCmpInst::FCMP_ONE;   break;
+case 0x0d: Pred = FCmpInst::FCMP_OGE;   break;
+case 0x0e: Pred = FCmpInst::FCMP_OGT;   break;
+case 0x0f: Pred = FCmpInst::FCMP_TRUE;  break;
+case 0x10: Pred = FCmpInst::FCMP_OEQ;   break;
+case 0x11: Pred = FCmpInst::FCMP_OLT;   break;
+case 0x12: Pred = FCmpInst::FCMP_OLE;   break;
+case 0x13: Pred = FCmpInst::FCMP_UNO;   break;
+case 0x14: Pred = FCmpInst::FCMP_UNE;   break;
+case 0x15: Pred = FCmpInst::FCMP_UGE;   break;
+case 0x16: Pred = FCmpInst::FCMP_UGT;   break;
+case 0x17: Pred = FCmpInst::FCMP_ORD;   break;
+case 0x18: Pred = FCmpInst::FCMP_UEQ;   break;
+case 0x19: Pred = FCmpInst::FCMP_ULT;   break;
+case 0x1a: Pred = FCmpInst::FCMP_ULE;   break;
+case 0x1b: Pred = FCmpInst::FCMP_FALSE; break;
+case 0x1c: Pred = FCmpInst::FCMP_ONE;   break;
+case 0x1d: Pred = FCmpInst::FCMP_OGE;   break;
+case 0x1e: Pred = FCmpInst::FCMP_OGT;   break;
+case 0x1f: Pred = FCmpInst::FCMP_TRUE;  break;
 default: llvm_unreachable("Unhandled CC");
 }
 

Modified: cfe/trunk/test/CodeGen/avx-builtins.c
URL: 

[PATCH] D48827: [clang-format ]Extend IncludeCategories regex documentation

2018-07-05 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir accepted this revision.
krasimir added a comment.
This revision is now accepted and ready to land.

Thank you!


Repository:
  rC Clang

https://reviews.llvm.org/D48827



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


[PATCH] D48715: [X86] Fix some vector cmp builtins - TRUE/FALSE predicates

2018-07-05 Thread Sanjay Patel via Phabricator via cfe-commits
spatel accepted this revision.
spatel added a comment.
This revision is now accepted and ready to land.

LGTM.


https://reviews.llvm.org/D48715



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


Re: r336225 - Fix allocation of Nullability attribute.

2018-07-05 Thread Aaron Ballman via cfe-commits
On Thu, Jul 5, 2018 at 8:54 AM, Keane, Erich  wrote:
> Unfortunately I'm not sure of a good way to validate this.  The only way I 
> was able to even discover this was with manual instrumentation of D48788.  
> There is a future opportunity to better instrument the source to find these 
> things in the future that'll catch more issues like this one however.

I kind of thought that might be the case. Thank you for verifying (and the fix)!

~Aaron

>
> -Original Message-
> From: aaron.ball...@gmail.com [mailto:aaron.ball...@gmail.com] On Behalf Of 
> Aaron Ballman
> Sent: Tuesday, July 3, 2018 1:43 PM
> To: Keane, Erich 
> Cc: cfe-commits 
> Subject: Re: r336225 - Fix allocation of Nullability attribute.
>
> On Tue, Jul 3, 2018 at 4:30 PM, Erich Keane via cfe-commits 
>  wrote:
>> Author: erichkeane
>> Date: Tue Jul  3 13:30:34 2018
>> New Revision: 336225
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=336225=rev
>> Log:
>> Fix allocation of Nullability attribute.
>>
>> Existing code always allocates for on the declarator's attribute pool,
>> but sometimes adds it to the declspec.  This patch ensures that the
>> correct pool is used.
>>
>>
>> Discovered while testing: https://reviews.llvm.org/D48788
>
> Can you devise a testcase for this change, or is that hard to get the 
> original behavior to fail in a consistent way?
>
> ~Aaron
>
>>
>> Modified:
>> cfe/trunk/lib/Parse/ParseObjc.cpp
>>
>> Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?
>> rev=336225=336224=336225=diff
>> ==
>> 
>> --- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
>> +++ cfe/trunk/lib/Parse/ParseObjc.cpp Tue Jul  3 13:30:34 2018
>> @@ -381,25 +381,23 @@ static void addContextSensitiveTypeNulla
>> SourceLocation 
>> nullabilityLoc,
>> bool ) {
>>// Create the attribute.
>> -  auto getNullabilityAttr = [&]() -> AttributeList * {
>> -return D.getAttributePool().create(
>> - P.getNullabilityKeyword(nullability),
>> - SourceRange(nullabilityLoc),
>> - nullptr, SourceLocation(),
>> - nullptr, 0,
>> - AttributeList::AS_ContextSensitiveKeyword);
>> +  auto getNullabilityAttr = [&](AttributePool ) -> AttributeList * {
>> +return Pool.create(P.getNullabilityKeyword(nullability),
>> +   SourceRange(nullabilityLoc), nullptr, 
>> SourceLocation(),
>> +   nullptr, 0,
>> + AttributeList::AS_ContextSensitiveKeyword);
>>};
>>
>>if (D.getNumTypeObjects() > 0) {
>>  // Add the attribute to the declarator chunk nearest the declarator.
>> -auto nullabilityAttr = getNullabilityAttr();
>> +auto nullabilityAttr = getNullabilityAttr(D.getAttributePool());
>>  DeclaratorChunk  = D.getTypeObject(0);
>>  nullabilityAttr->setNext(chunk.getAttrListRef());
>>  chunk.getAttrListRef() = nullabilityAttr;
>>} else if (!addedToDeclSpec) {
>>  // Otherwise, just put it on the declaration specifiers (if one
>>  // isn't there already).
>> -D.getMutableDeclSpec().addAttributes(getNullabilityAttr());
>> +D.getMutableDeclSpec().addAttributes(
>> +getNullabilityAttr(D.getDeclSpec().getAttributePool()));
>>  addedToDeclSpec = true;
>>}
>>  }
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r336347 - [mips] Add '-mcrc', '-mno-crc' options to enable/disable CRC ASE

2018-07-05 Thread Vladimir Stefanovic via cfe-commits
Author: vstefanovic
Date: Thu Jul  5 06:10:23 2018
New Revision: 336347

URL: http://llvm.org/viewvc/llvm-project?rev=336347=rev
Log:
[mips] Add '-mcrc', '-mno-crc' options to enable/disable CRC ASE

'-mcrc' is shared with ARM.
'-mno-crc' is Mips-only (ARM uses '-mnocrc').

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


Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
cfe/trunk/test/Driver/mips-features.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=336347=336346=336347=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Thu Jul  5 06:10:23 2018
@@ -1993,8 +1993,8 @@ def ffixed_r9 : Flag<["-"], "ffixed-r9">
   HelpText<"Reserve the r9 register (ARM only)">;
 def mno_movt : Flag<["-"], "mno-movt">, Group,
   HelpText<"Disallow use of movt/movw pairs (ARM only)">;
-def mcrc : Flag<["-"], "mcrc">, Group,
-  HelpText<"Allow use of CRC instructions (ARM only)">;
+def mcrc : Flag<["-"], "mcrc">, Group,
+  HelpText<"Allow use of CRC instructions (ARM/Mips only)">;
 def mnocrc : Flag<["-"], "mnocrc">, Group,
   HelpText<"Disallow use of CRC instructions (ARM only)">;
 def mno_neg_immediates: Flag<["-"], "mno-neg-immediates">, 
Group,
@@ -2212,6 +2212,8 @@ def mabicalls : Flag<["-"], "mabicalls">
   HelpText<"Enable SVR4-style position-independent code (Mips only)">;
 def mno_abicalls : Flag<["-"], "mno-abicalls">, Group,
   HelpText<"Disable SVR4-style position-independent code (Mips only)">;
+def mno_crc : Flag<["-"], "mno-crc">, Group,
+  HelpText<"Disallow use of CRC instructions (Mips only)">;
 def mips1 : Flag<["-"], "mips1">,
   Alias, AliasArgs<["mips1"]>, Group,
   HelpText<"Equivalent to -march=mips1">, Flags<[HelpHidden]>;

Modified: cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp?rev=336347=336346=336347=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp Thu Jul  5 06:10:23 2018
@@ -350,6 +350,8 @@ void mips::getMIPSTargetFeatures(const D
   AddTargetFeature(Args, Features, options::OPT_mno_madd4, options::OPT_mmadd4,
"nomadd4");
   AddTargetFeature(Args, Features, options::OPT_mmt, options::OPT_mno_mt, 
"mt");
+  AddTargetFeature(Args, Features, options::OPT_mcrc, options::OPT_mno_crc,
+   "crc");
 
   if (Arg *A = Args.getLastArg(options::OPT_mindirect_jump_EQ)) {
 StringRef Val = StringRef(A->getValue());

Modified: cfe/trunk/test/Driver/mips-features.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/mips-features.c?rev=336347=336346=336347=diff
==
--- cfe/trunk/test/Driver/mips-features.c (original)
+++ cfe/trunk/test/Driver/mips-features.c Thu Jul  5 06:10:23 2018
@@ -408,3 +408,15 @@
 // RUN:-mindirect-jump=hazard 2>&1 \
 // RUN:   | FileCheck --check-prefix=INDIRECT-BH %s
 // INDIRECT-BH: "-target-feature" "+use-indirect-jump-hazard"
+//
+// -mcrc
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -mno-crc -mcrc 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-CRC %s
+// CHECK-CRC: "-target-feature" "+crc"
+//
+// -mno-crc
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -mcrc -mno-crc 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-CRC %s
+// CHECK-NO-CRC: "-target-feature" "-crc"


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


[PATCH] D48169: [mips] Add '-mcrc', '-mno-crc' options to enable/disable CRC ASE

2018-07-05 Thread Vladimir Stefanovic via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC336347: [mips] Add -mcrc, -mno-crc 
options to enable/disable CRC ASE (authored by vstefanovic, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D48169

Files:
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/Arch/Mips.cpp
  test/Driver/mips-features.c


Index: test/Driver/mips-features.c
===
--- test/Driver/mips-features.c
+++ test/Driver/mips-features.c
@@ -408,3 +408,15 @@
 // RUN:-mindirect-jump=hazard 2>&1 \
 // RUN:   | FileCheck --check-prefix=INDIRECT-BH %s
 // INDIRECT-BH: "-target-feature" "+use-indirect-jump-hazard"
+//
+// -mcrc
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -mno-crc -mcrc 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-CRC %s
+// CHECK-CRC: "-target-feature" "+crc"
+//
+// -mno-crc
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -mcrc -mno-crc 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-CRC %s
+// CHECK-NO-CRC: "-target-feature" "-crc"
Index: lib/Driver/ToolChains/Arch/Mips.cpp
===
--- lib/Driver/ToolChains/Arch/Mips.cpp
+++ lib/Driver/ToolChains/Arch/Mips.cpp
@@ -350,6 +350,8 @@
   AddTargetFeature(Args, Features, options::OPT_mno_madd4, options::OPT_mmadd4,
"nomadd4");
   AddTargetFeature(Args, Features, options::OPT_mmt, options::OPT_mno_mt, 
"mt");
+  AddTargetFeature(Args, Features, options::OPT_mcrc, options::OPT_mno_crc,
+   "crc");
 
   if (Arg *A = Args.getLastArg(options::OPT_mindirect_jump_EQ)) {
 StringRef Val = StringRef(A->getValue());
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1993,8 +1993,8 @@
   HelpText<"Reserve the r9 register (ARM only)">;
 def mno_movt : Flag<["-"], "mno-movt">, Group,
   HelpText<"Disallow use of movt/movw pairs (ARM only)">;
-def mcrc : Flag<["-"], "mcrc">, Group,
-  HelpText<"Allow use of CRC instructions (ARM only)">;
+def mcrc : Flag<["-"], "mcrc">, Group,
+  HelpText<"Allow use of CRC instructions (ARM/Mips only)">;
 def mnocrc : Flag<["-"], "mnocrc">, Group,
   HelpText<"Disallow use of CRC instructions (ARM only)">;
 def mno_neg_immediates: Flag<["-"], "mno-neg-immediates">, 
Group,
@@ -2212,6 +2212,8 @@
   HelpText<"Enable SVR4-style position-independent code (Mips only)">;
 def mno_abicalls : Flag<["-"], "mno-abicalls">, Group,
   HelpText<"Disable SVR4-style position-independent code (Mips only)">;
+def mno_crc : Flag<["-"], "mno-crc">, Group,
+  HelpText<"Disallow use of CRC instructions (Mips only)">;
 def mips1 : Flag<["-"], "mips1">,
   Alias, AliasArgs<["mips1"]>, Group,
   HelpText<"Equivalent to -march=mips1">, Flags<[HelpHidden]>;


Index: test/Driver/mips-features.c
===
--- test/Driver/mips-features.c
+++ test/Driver/mips-features.c
@@ -408,3 +408,15 @@
 // RUN:-mindirect-jump=hazard 2>&1 \
 // RUN:   | FileCheck --check-prefix=INDIRECT-BH %s
 // INDIRECT-BH: "-target-feature" "+use-indirect-jump-hazard"
+//
+// -mcrc
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -mno-crc -mcrc 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-CRC %s
+// CHECK-CRC: "-target-feature" "+crc"
+//
+// -mno-crc
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -mcrc -mno-crc 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-CRC %s
+// CHECK-NO-CRC: "-target-feature" "-crc"
Index: lib/Driver/ToolChains/Arch/Mips.cpp
===
--- lib/Driver/ToolChains/Arch/Mips.cpp
+++ lib/Driver/ToolChains/Arch/Mips.cpp
@@ -350,6 +350,8 @@
   AddTargetFeature(Args, Features, options::OPT_mno_madd4, options::OPT_mmadd4,
"nomadd4");
   AddTargetFeature(Args, Features, options::OPT_mmt, options::OPT_mno_mt, "mt");
+  AddTargetFeature(Args, Features, options::OPT_mcrc, options::OPT_mno_crc,
+   "crc");
 
   if (Arg *A = Args.getLastArg(options::OPT_mindirect_jump_EQ)) {
 StringRef Val = StringRef(A->getValue());
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1993,8 +1993,8 @@
   HelpText<"Reserve the r9 register (ARM only)">;
 def mno_movt : Flag<["-"], "mno-movt">, Group,
   HelpText<"Disallow use of movt/movw pairs (ARM only)">;
-def mcrc : Flag<["-"], "mcrc">, Group,
-  HelpText<"Allow use of CRC instructions (ARM only)">;
+def mcrc : Flag<["-"], "mcrc">, Group,
+  HelpText<"Allow use of CRC instructions (ARM/Mips only)">;
 def mnocrc : Flag<["-"], "mnocrc">, Group,
   HelpText<"Disallow use of CRC instructions 

[PATCH] D48715: [X86] Fix some vector cmp builtins - TRUE/FALSE predicates

2018-07-05 Thread Gabor Buella via Phabricator via cfe-commits
GBuella added a comment.

ping @spatel


https://reviews.llvm.org/D48715



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


[PATCH] D48715: [X86] Fix some vector cmp builtins - TRUE/FALSE predicates

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

As suggested, I added test cases with all predicates (in r336346).


https://reviews.llvm.org/D48715

Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGen/avx-builtins.c
  test/CodeGen/avx512f-builtins.c
  test/CodeGen/avx512vl-builtins.c

Index: test/CodeGen/avx512vl-builtins.c
===
--- test/CodeGen/avx512vl-builtins.c
+++ test/CodeGen/avx512vl-builtins.c
@@ -1139,8 +1139,7 @@
 
 __mmask8 test_mm256_cmp_ps_mask_false_oq(__m256 a, __m256 b) {
   // CHECK-LABEL: test_mm256_cmp_ps_mask_false_oq
-  // CHECK-NOT: call
-  // CHECK: ret i8 0
+  // CHECK: fcmp false <8 x float> %{{.*}}, %{{.*}}
   return _mm256_cmp_ps_mask(a, b, _CMP_FALSE_OQ);
 }
 
@@ -1164,8 +1163,7 @@
 
 __mmask8 test_mm256_cmp_ps_mask_true_uq(__m256 a, __m256 b) {
   // CHECK-LABEL: test_mm256_cmp_ps_mask_true_uq
-  // CHECK-NOT: call
-  // CHECK: ret i8 -1
+  // CHECK: fcmp true <8 x float> %{{.*}}, %{{.*}}
   return _mm256_cmp_ps_mask(a, b, _CMP_TRUE_UQ);
 }
 
@@ -1237,8 +1235,7 @@
 
 __mmask8 test_mm256_cmp_ps_mask_false_os(__m256 a, __m256 b) {
   // CHECK-LABEL: test_mm256_cmp_ps_mask_false_os
-  // CHECK-NOT: call
-  // CHECK: ret i8 0
+  // CHECK: fcmp false <8 x float> %{{.*}}, %{{.*}}
   return _mm256_cmp_ps_mask(a, b, _CMP_FALSE_OS);
 }
 
@@ -1262,8 +1259,7 @@
 
 __mmask8 test_mm256_cmp_ps_mask_true_us(__m256 a, __m256 b) {
   // CHECK-LABEL: test_mm256_cmp_ps_mask_true_us
-  // CHECK-NOT: call
-  // CHECK: ret i8 -1
+  // CHECK: fcmp true <8 x float> %{{.*}}, %{{.*}}
   return _mm256_cmp_ps_mask(a, b, _CMP_TRUE_US);
 }
 
@@ -1346,8 +1342,8 @@
 
 __mmask8 test_mm256_mask_cmp_ps_mask_false_oq(__mmask8 m, __m256 a, __m256 b) {
   // CHECK-LABEL: test_mm256_mask_cmp_ps_mask_false_oq
-  // CHECK-NOT: call
-  // CHECK: ret i8 0
+  // CHECK: [[CMP:%.*]] = fcmp false <8 x float> %{{.*}}, %{{.*}}
+  // CHECK: and <8 x i1> [[CMP]], {{.*}}
   return _mm256_mask_cmp_ps_mask(m, a, b, _CMP_FALSE_OQ);
 }
 
@@ -1374,7 +1370,8 @@
 
 __mmask8 test_mm256_mask_cmp_ps_mask_true_uq(__mmask8 m, __m256 a, __m256 b) {
   // CHECK-LABEL: test_mm256_mask_cmp_ps_mask_true_uq
-  // FIXME
+  // CHECK: [[CMP:%.*]] = fcmp true <8 x float> %{{.*}}, %{{.*}}
+  // CHECK: and <8 x i1> [[CMP]], {{.*}}
   return _mm256_mask_cmp_ps_mask(m, a, b, _CMP_TRUE_UQ);
 }
 
@@ -1457,8 +1454,8 @@
 
 __mmask8 test_mm256_mask_cmp_ps_mask_false_os(__mmask8 m, __m256 a, __m256 b) {
   // CHECK-LABEL: test_mm256_mask_cmp_ps_mask_false_os
-  // CHECK-NOT: call
-  // CHECK: ret i8 0
+  // CHECK: [[CMP:%.*]] = fcmp false <8 x float> %{{.*}}, %{{.*}}
+  // CHECK: and <8 x i1> [[CMP]], {{.*}}
   return _mm256_mask_cmp_ps_mask(m, a, b, _CMP_FALSE_OS);
 }
 
@@ -1485,7 +1482,8 @@
 
 __mmask8 test_mm256_mask_cmp_ps_mask_true_us(__mmask8 m, __m256 a, __m256 b) {
   // CHECK-LABEL: test_mm256_mask_cmp_ps_mask_true_us
-  // FIXME
+  // CHECK: [[CMP:%.*]] = fcmp true <8 x float> %{{.*}}, %{{.*}}
+  // CHECK: and <8 x i1> [[CMP]], {{.*}}
   return _mm256_mask_cmp_ps_mask(m, a, b, _CMP_TRUE_US);
 }
 
@@ -1557,8 +1555,7 @@
 
 __mmask8 test_mm256_cmp_pd_mask_false_oq(__m256d a, __m256d b) {
   // CHECK-LABEL: test_mm256_cmp_pd_mask_false_oq
-  // CHECK-NOT: call
-  // CHECK: ret i8 0
+  // CHECK: fcmp false <4 x double> %{{.*}}, %{{.*}}
   return _mm256_cmp_pd_mask(a, b, _CMP_FALSE_OQ);
 }
 
@@ -1582,8 +1579,7 @@
 
 __mmask8 test_mm256_cmp_pd_mask_true_uq(__m256d a, __m256d b) {
   // CHECK-LABEL: test_mm256_cmp_pd_mask_true_uq
-  // CHECK-NOT: call
-  // CHECK: ret i8 -1
+  // CHECK: fcmp true <4 x double> %{{.*}}, %{{.*}}
   return _mm256_cmp_pd_mask(a, b, _CMP_TRUE_UQ);
 }
 
@@ -1655,8 +1651,7 @@
 
 __mmask8 test_mm256_cmp_pd_mask_false_os(__m256d a, __m256d b) {
   // CHECK-LABEL: test_mm256_cmp_pd_mask_false_os
-  // CHECK-NOT: call
-  // CHECK: ret i8 0
+  // CHECK: fcmp false <4 x double> %{{.*}}, %{{.*}}
   return _mm256_cmp_pd_mask(a, b, _CMP_FALSE_OS);
 }
 
@@ -1680,8 +1675,7 @@
 
 __mmask8 test_mm256_cmp_pd_mask_true_us(__m256d a, __m256d b) {
   // CHECK-LABEL: test_mm256_cmp_pd_mask_true_us
-  // CHECK-NOT: call
-  // CHECK: ret i8 -1
+  // CHECK: fcmp true <4 x double> %{{.*}}, %{{.*}}
   return _mm256_cmp_pd_mask(a, b, _CMP_TRUE_US);
 }
 
@@ -1764,8 +1758,8 @@
 
 __mmask8 test_mm256_mask_cmp_pd_mask_false_oq(__mmask8 m, __m256d a, __m256d b) {
   // CHECK-LABEL: test_mm256_mask_cmp_pd_mask_false_oq
-  // CHECK-NOT: call
-  // CHECK: ret i8 0
+  // CHECK: [[CMP:%.*]] = fcmp false <4 x double> %{{.*}}, %{{.*}}
+  // CHECK: and <4 x i1> [[CMP]], {{.*}}
   return _mm256_mask_cmp_pd_mask(m, a, b, _CMP_FALSE_OQ);
 }
 
@@ -1792,7 +1786,8 @@
 
 __mmask8 test_mm256_mask_cmp_pd_mask_true_uq(__mmask8 m, __m256d a, __m256d b) {
   // CHECK-LABEL: test_mm256_mask_cmp_pd_mask_true_uq
-  // FIXME
+  // CHECK: [[CMP:%.*]] = fcmp true <4 x double> %{{.*}}, %{{.*}}
+  // CHECK: and <4 x i1> [[CMP]], {{.*}}
   return _mm256_mask_cmp_pd_mask(m, a, b, _CMP_TRUE_UQ);
 }
 
@@ 

[PATCH] D48941: [ASTImporter] import FunctionDecl end locations

2018-07-05 Thread Rafael Stahl via Phabricator via cfe-commits
r.stahl updated this revision to Diff 154215.
r.stahl marked 2 inline comments as done.
r.stahl added a comment.

Alright, but then I would suggest to pass an invalid loc to the constructors 
instead to make it more explicit and save a map lookup in the import function.


Repository:
  rC Clang

https://reviews.llvm.org/D48941

Files:
  lib/AST/ASTImporter.cpp
  unittests/AST/ASTImporterTest.cpp


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -1620,7 +1620,7 @@
   FromSM);
 }
 
-TEST_P(ASTImporterTestBase, DISABLED_ImportNestedMacro) {
+TEST_P(ASTImporterTestBase, ImportNestedMacro) {
   Decl *FromTU = getTuDecl(
   R"(
   #define FUNC_INT void declToImport
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -2563,16 +2563,16 @@
D->isInlineSpecified(),
FromConversion->isExplicit(),
D->isConstexpr(),
-   Importer.Import(D->getLocEnd()));
+   SourceLocation());
   } else if (auto *Method = dyn_cast(D)) {
 ToFunction = CXXMethodDecl::Create(Importer.getToContext(), 
cast(DC),
InnerLocStart,
NameInfo, T, TInfo,
Method->getStorageClass(),
Method->isInlineSpecified(),
D->isConstexpr(),
-   Importer.Import(D->getLocEnd()));
+   SourceLocation());
   } else {
 ToFunction = FunctionDecl::Create(Importer.getToContext(), DC,
   InnerLocStart,
@@ -2589,6 +2589,7 @@
   ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
   ToFunction->setTrivial(D->isTrivial());
   ToFunction->setPure(D->isPure());
+  ToFunction->setRangeEnd(Importer.Import(D->getLocEnd()));
   Importer.Imported(D, ToFunction);
 
   // Set the parameters.


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -1620,7 +1620,7 @@
   FromSM);
 }
 
-TEST_P(ASTImporterTestBase, DISABLED_ImportNestedMacro) {
+TEST_P(ASTImporterTestBase, ImportNestedMacro) {
   Decl *FromTU = getTuDecl(
   R"(
   #define FUNC_INT void declToImport
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -2563,16 +2563,16 @@
D->isInlineSpecified(),
FromConversion->isExplicit(),
D->isConstexpr(),
-   Importer.Import(D->getLocEnd()));
+   SourceLocation());
   } else if (auto *Method = dyn_cast(D)) {
 ToFunction = CXXMethodDecl::Create(Importer.getToContext(), 
cast(DC),
InnerLocStart,
NameInfo, T, TInfo,
Method->getStorageClass(),
Method->isInlineSpecified(),
D->isConstexpr(),
-   Importer.Import(D->getLocEnd()));
+   SourceLocation());
   } else {
 ToFunction = FunctionDecl::Create(Importer.getToContext(), DC,
   InnerLocStart,
@@ -2589,6 +2589,7 @@
   ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
   ToFunction->setTrivial(D->isTrivial());
   ToFunction->setPure(D->isPure());
+  ToFunction->setRangeEnd(Importer.Import(D->getLocEnd()));
   Importer.Imported(D, ToFunction);
 
   // Set the parameters.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48961: [Index] Add indexing support for MACROs.

2018-07-05 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

I worry this is a trap: the indexing infrastructure here is designed so you can 
run it as a frontendaction, on an ASTUnit, or by passing a set of top level 
decls.
However the macro functionality necessarily only works when running as a 
frontend action, so the same consumer would have different semantics when using 
these functions.
Moreover, clangd does call indexTopLevelDecls(), so this API might actually be 
awkward for us to use.

Alternatives would be:

- write lots of loud documentation and hope people read it
- punt on generalization and just do what we need in clangd with PPCallbacks 
directly
- offer a peer API here for consuming macros, and have the indexTopLevelDecls() 
etc only take the symbol consumer, createIndexingAction() would create both 
(and you could have a createIndexingPPCallbacks() that takes only the macro 
consumer).

WDYT?




Comment at: include/clang/Index/IndexDataConsumer.h:50
+const MacroInfo , SymbolRoleSet Roles,
+SourceLocation Loc, bool Undefined = 
false);
 

I know this file isn't heavy on documentation, but I think `Undefined` needs 
some explanation/example where it might be true. And consider flipping to 
remove the negation.

Why a default parameter? Virtual + default is slightly confusing, and the 
#callers here should be few I think.



Comment at: include/clang/Index/IndexSymbol.h:138
 
+SymbolInfo getSymbolInfoForMacro();
+

this should take an arg - maybe macroinfo?
There are potentially subkinds here (function-like macros vs object-like ones) 
and it'll be harder to update callsites once they exist :-)


Repository:
  rC Clang

https://reviews.llvm.org/D48961



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


RE: r336225 - Fix allocation of Nullability attribute.

2018-07-05 Thread Keane, Erich via cfe-commits
Unfortunately I'm not sure of a good way to validate this.  The only way I was 
able to even discover this was with manual instrumentation of D48788.  There is 
a future opportunity to better instrument the source to find these things in 
the future that'll catch more issues like this one however.

-Original Message-
From: aaron.ball...@gmail.com [mailto:aaron.ball...@gmail.com] On Behalf Of 
Aaron Ballman
Sent: Tuesday, July 3, 2018 1:43 PM
To: Keane, Erich 
Cc: cfe-commits 
Subject: Re: r336225 - Fix allocation of Nullability attribute.

On Tue, Jul 3, 2018 at 4:30 PM, Erich Keane via cfe-commits 
 wrote:
> Author: erichkeane
> Date: Tue Jul  3 13:30:34 2018
> New Revision: 336225
>
> URL: http://llvm.org/viewvc/llvm-project?rev=336225=rev
> Log:
> Fix allocation of Nullability attribute.
>
> Existing code always allocates for on the declarator's attribute pool, 
> but sometimes adds it to the declspec.  This patch ensures that the 
> correct pool is used.
>
>
> Discovered while testing: https://reviews.llvm.org/D48788

Can you devise a testcase for this change, or is that hard to get the original 
behavior to fail in a consistent way?

~Aaron

>
> Modified:
> cfe/trunk/lib/Parse/ParseObjc.cpp
>
> Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?
> rev=336225=336224=336225=diff
> ==
> 
> --- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseObjc.cpp Tue Jul  3 13:30:34 2018
> @@ -381,25 +381,23 @@ static void addContextSensitiveTypeNulla
> SourceLocation nullabilityLoc,
> bool ) {
>// Create the attribute.
> -  auto getNullabilityAttr = [&]() -> AttributeList * {
> -return D.getAttributePool().create(
> - P.getNullabilityKeyword(nullability),
> - SourceRange(nullabilityLoc),
> - nullptr, SourceLocation(),
> - nullptr, 0,
> - AttributeList::AS_ContextSensitiveKeyword);
> +  auto getNullabilityAttr = [&](AttributePool ) -> AttributeList * {
> +return Pool.create(P.getNullabilityKeyword(nullability),
> +   SourceRange(nullabilityLoc), nullptr, 
> SourceLocation(),
> +   nullptr, 0, 
> + AttributeList::AS_ContextSensitiveKeyword);
>};
>
>if (D.getNumTypeObjects() > 0) {
>  // Add the attribute to the declarator chunk nearest the declarator.
> -auto nullabilityAttr = getNullabilityAttr();
> +auto nullabilityAttr = getNullabilityAttr(D.getAttributePool());
>  DeclaratorChunk  = D.getTypeObject(0);
>  nullabilityAttr->setNext(chunk.getAttrListRef());
>  chunk.getAttrListRef() = nullabilityAttr;
>} else if (!addedToDeclSpec) {
>  // Otherwise, just put it on the declaration specifiers (if one
>  // isn't there already).
> -D.getMutableDeclSpec().addAttributes(getNullabilityAttr());
> +D.getMutableDeclSpec().addAttributes(
> +getNullabilityAttr(D.getDeclSpec().getAttributePool()));
>  addedToDeclSpec = true;
>}
>  }
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32859: [Analyzer] Iterator Checker - Part 5: Move Assignment of Containers

2018-07-05 Thread Whisperity via Phabricator via cfe-commits
whisperity added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/IteratorChecker.cpp:1061
+  // first reassign all iterator positions to the new container which
+  // are not past the container (thus not greater or equal to the
+  // current "end" symbol.

`(` is not closed


https://reviews.llvm.org/D32859



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


[PATCH] D48961: [Index] Add indexing support for MACROs.

2018-07-05 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.
ioeric added reviewers: akyrtzi, arphaman.
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D48961

Files:
  include/clang/Index/IndexDataConsumer.h
  include/clang/Index/IndexSymbol.h
  lib/Index/IndexSymbol.cpp
  lib/Index/IndexingAction.cpp
  lib/Index/IndexingContext.cpp
  lib/Index/IndexingContext.h
  test/Index/Core/index-macros.c
  tools/c-index-test/core_main.cpp

Index: tools/c-index-test/core_main.cpp
===
--- tools/c-index-test/core_main.cpp
+++ tools/c-index-test/core_main.cpp
@@ -7,6 +7,7 @@
 //
 //===--===//
 
+#include "clang/Basic/LangOptions.h"
 #include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -16,6 +17,7 @@
 #include "clang/Index/IndexDataConsumer.h"
 #include "clang/Index/USRGeneration.h"
 #include "clang/Index/CodegenNameGenerator.h"
+#include "clang/Lex/Preprocessor.h"
 #include "clang/Serialization/ASTReader.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Signals.h"
@@ -77,6 +79,7 @@
 class PrintIndexDataConsumer : public IndexDataConsumer {
   raw_ostream 
   std::unique_ptr CGNameGen;
+  std::shared_ptr PP;
 
 public:
   PrintIndexDataConsumer(raw_ostream ) : OS(OS) {
@@ -86,6 +89,10 @@
 CGNameGen.reset(new CodegenNameGenerator(Ctx));
   }
 
+  void setPreprocessor(std::shared_ptr PP) override {
+this->PP = std::move(PP);
+  }
+
   bool handleDeclOccurence(const Decl *D, SymbolRoleSet Roles,
ArrayRef Relations,
SourceLocation Loc, ASTNodeInfo ASTNode) override {
@@ -145,6 +152,42 @@
 
 return true;
   }
+
+  bool handleMacroOccurence(const IdentifierInfo , const MacroInfo ,
+SymbolRoleSet Roles, SourceLocation Loc,
+bool Undefined) override {
+assert(PP);
+SourceManager  = PP->getSourceManager();
+
+Loc = SM.getFileLoc(Loc);
+FileID FID = SM.getFileID(Loc);
+unsigned Line = SM.getLineNumber(FID, SM.getFileOffset(Loc));
+unsigned Col = SM.getColumnNumber(FID, SM.getFileOffset(Loc));
+OS << Line << ':' << Col << " | ";
+
+printSymbolInfo(getSymbolInfoForMacro(), OS);
+OS << " | ";
+
+OS << Name.getName();
+OS << " | ";
+
+SmallString<256> USRBuf;
+if (generateUSRForMacro(Name.getName(), MI.getDefinitionLoc(), SM,
+USRBuf)) {
+  OS << "";
+} else {
+  OS << USRBuf;
+}
+
+OS << " | ";
+
+if (Undefined)
+  OS << "(undefined)";
+else
+  printSymbolRoles(Roles, OS);
+OS << " |\n";
+return true;
+  }
 };
 
 } // anonymous namespace
Index: test/Index/Core/index-macros.c
===
--- /dev/null
+++ test/Index/Core/index-macros.c
@@ -0,0 +1,12 @@
+// RUN: c-index-test core -print-source-symbols -- %s | FileCheck %s
+
+// CHECK: [[@LINE+1]]:9 | macro/C | X1 | c:index-macros.c@157@macro@X1 | Def |
+#define X1 1
+// CHECK: [[@LINE+1]]:9 | macro/C | DEF | c:index-macros.c@251@macro@DEF | Def |
+#define DEF(x) int x
+// CHECK: [[@LINE+1]]:8 | macro/C | X1 | c:index-macros.c@157@macro@X1 | (undefined) |
+#undef X1
+
+// CHECK: [[@LINE+2]]:1 | macro/C | DEF | c:index-macros.c@251@macro@DEF | Ref |
+// CHECK: [[@LINE+1]]:5 | variable/C | i | c:@i | i | Def | rel: 0
+DEF(i);
Index: lib/Index/IndexingContext.h
===
--- lib/Index/IndexingContext.h
+++ lib/Index/IndexingContext.h
@@ -10,9 +10,11 @@
 #ifndef LLVM_CLANG_LIB_INDEX_INDEXINGCONTEXT_H
 #define LLVM_CLANG_LIB_INDEX_INDEXINGCONTEXT_H
 
+#include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Index/IndexSymbol.h"
 #include "clang/Index/IndexingAction.h"
+#include "clang/Lex/MacroInfo.h"
 #include "llvm/ADT/ArrayRef.h"
 
 namespace clang {
@@ -80,6 +82,15 @@
const Expr *RefE = nullptr,
const Decl *RefD = nullptr);
 
+  void handleMacroDefined(const IdentifierInfo , SourceLocation Loc,
+  const MacroInfo );
+
+  void handleMacroUndefined(const IdentifierInfo , SourceLocation Loc,
+const MacroInfo );
+
+  void handleMacroReference(const IdentifierInfo , SourceLocation Loc,
+const MacroInfo );
+
   bool importedModule(const ImportDecl *ImportD);
 
   bool indexDecl(const Decl *D);
Index: lib/Index/IndexingContext.cpp
===
--- lib/Index/IndexingContext.cpp
+++ lib/Index/IndexingContext.cpp
@@ -8,6 +8,7 @@
 //===--===//
 
 #include "IndexingContext.h"
+#include "clang/Basic/SourceLocation.h"
 

Re: [clang-tools-extra] r336318 - [clangd] Treat class constructor as in the same scope as the class in ranking.

2018-07-05 Thread Mikael Holmén via cfe-commits

Ah, already fixed in r336329 I see.

On 07/05/2018 12:56 PM, Mikael Holmén via cfe-commits wrote:

Hi Eric,

I get the following with this patch:

/proj/flexasic/app/clang/3.6/bin/clang++  -march=corei7 
-DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-Itools/clang/tools/extra/clangd -I../tools/clang/tools/extra/clangd 
-I../tools/clang/include -Itools/clang/include -I/usr/include/libxml2 
-Iinclude -I../include -fPIC -fvisibility-inlines-hidden -Werror 
-Werror=date-time -std=c++11 -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
-Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color 
-ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual 
-Wno-nested-anon-types -O3    -UNDEBUG  -fno-exceptions -fno-rtti -MMD 
-MT 
tools/clang/tools/extra/clangd/CMakeFiles/clangDaemon.dir/Quality.cpp.o 
-MF 
tools/clang/tools/extra/clangd/CMakeFiles/clangDaemon.dir/Quality.cpp.o.d -o 
tools/clang/tools/extra/clangd/CMakeFiles/clangDaemon.dir/Quality.cpp.o 
-c ../tools/clang/tools/extra/clangd/Quality.cpp
../tools/clang/tools/extra/clangd/Quality.cpp:201:19: error: unused 
variable 'Ctor' [-Werror,-Wunused-variable]

   if (const auto *Ctor = llvm::dyn_cast(D))
   ^
1 error generated.

Regards,
Mikael

On 07/05/2018 10:14 AM, Eric Liu via cfe-commits wrote:

Author: ioeric
Date: Thu Jul  5 01:14:04 2018
New Revision: 336318

URL: http://llvm.org/viewvc/llvm-project?rev=336318=rev
Log:
[clangd] Treat class constructor as in the same scope as the class in 
ranking.


Reviewers: sammccall

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

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

Modified:
 clang-tools-extra/trunk/clangd/Quality.cpp
 clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp
 clang-tools-extra/trunk/unittests/clangd/TestTU.cpp
 clang-tools-extra/trunk/unittests/clangd/TestTU.h

Modified: clang-tools-extra/trunk/clangd/Quality.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.cpp?rev=336318=336317=336318=diff 

== 


--- clang-tools-extra/trunk/clangd/Quality.cpp (original)
+++ clang-tools-extra/trunk/clangd/Quality.cpp Thu Jul  5 01:14:04 2018
@@ -11,10 +11,12 @@
  #include "URI.h"
  #include "index/Index.h"
  #include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
  #include "clang/AST/DeclVisitor.h"
  #include "clang/Basic/CharInfo.h"
  #include "clang/Basic/SourceManager.h"
  #include "clang/Sema/CodeCompleteConsumer.h"
+#include "llvm/Support/Casting.h"
  #include "llvm/Support/FormatVariadic.h"
  #include "llvm/Support/MathExtras.h"
  #include "llvm/Support/raw_ostream.h"
@@ -195,6 +197,9 @@ ComputeScope(const NamedDecl *D) {
    if (auto *R = dyn_cast_or_null(D))
  if (R->isInjectedClassName())
    DC = DC->getParent();
+  // Class constructor should have the same scope as the class.
+  if (const auto *Ctor = llvm::dyn_cast(D))
+    DC = DC->getParent();
    bool InClass = false;
    for (; !DC->isFileContext(); DC = DC->getParent()) {
  if (DC->isFunctionOrMethod())

Modified: clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp?rev=336318=336317=336318=diff 

== 


--- clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp Thu Jul  
5 01:14:04 2018

@@ -21,6 +21,9 @@
  #include "Quality.h"
  #include "TestFS.h"
  #include "TestTU.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "llvm/Support/Casting.h"
  #include "gmock/gmock.h"
  #include "gtest/gtest.h"
@@ -199,6 +202,31 @@ TEST(QualityTests, SortText) {
    EXPECT_LT(sortText(0, "a"), sortText(0, "z"));
  }
+TEST(QualityTests, NoBoostForClassConstructor) {
+  auto Header = TestTU::withHeaderCode(R"cpp(
+    class Foo {
+    public:
+  Foo(int);
+    };
+  )cpp");
+  auto Symbols = Header.headerSymbols();
+  auto AST = Header.build();
+
+  const NamedDecl *Foo = (AST, "Foo");
+  SymbolRelevanceSignals Cls;
+  Cls.merge(CodeCompletionResult(Foo, /*Priority=*/0));
+
+  const NamedDecl *CtorDecl = (AST, [](const NamedDecl 
) {

+    return (ND.getQualifiedNameAsString() == "Foo::Foo") &&
+   llvm::isa();
+  });
+  SymbolRelevanceSignals Ctor;
+  Ctor.merge(CodeCompletionResult(CtorDecl, /*Priority=*/0));
+
+  EXPECT_EQ(Cls.Scope, SymbolRelevanceSignals::GlobalScope);
+  EXPECT_EQ(Ctor.Scope, SymbolRelevanceSignals::GlobalScope);
+}
+
  } // namespace
  } // namespace clangd
  } // namespace clang

Modified: clang-tools-extra/trunk/unittests/clangd/TestTU.cpp
URL: 

Re: [clang-tools-extra] r336318 - [clangd] Treat class constructor as in the same scope as the class in ranking.

2018-07-05 Thread Mikael Holmén via cfe-commits

Hi Eric,

I get the following with this patch:

/proj/flexasic/app/clang/3.6/bin/clang++  -march=corei7 
-DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-Itools/clang/tools/extra/clangd -I../tools/clang/tools/extra/clangd 
-I../tools/clang/include -Itools/clang/include -I/usr/include/libxml2 
-Iinclude -I../include -fPIC -fvisibility-inlines-hidden -Werror 
-Werror=date-time -std=c++11 -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
-Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color 
-ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual 
-Wno-nested-anon-types -O3-UNDEBUG  -fno-exceptions -fno-rtti -MMD 
-MT 
tools/clang/tools/extra/clangd/CMakeFiles/clangDaemon.dir/Quality.cpp.o 
-MF 
tools/clang/tools/extra/clangd/CMakeFiles/clangDaemon.dir/Quality.cpp.o.d 
-o 
tools/clang/tools/extra/clangd/CMakeFiles/clangDaemon.dir/Quality.cpp.o 
-c ../tools/clang/tools/extra/clangd/Quality.cpp
../tools/clang/tools/extra/clangd/Quality.cpp:201:19: error: unused 
variable 'Ctor' [-Werror,-Wunused-variable]

  if (const auto *Ctor = llvm::dyn_cast(D))
  ^
1 error generated.

Regards,
Mikael

On 07/05/2018 10:14 AM, Eric Liu via cfe-commits wrote:

Author: ioeric
Date: Thu Jul  5 01:14:04 2018
New Revision: 336318

URL: http://llvm.org/viewvc/llvm-project?rev=336318=rev
Log:
[clangd] Treat class constructor as in the same scope as the class in ranking.

Reviewers: sammccall

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

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

Modified:
 clang-tools-extra/trunk/clangd/Quality.cpp
 clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp
 clang-tools-extra/trunk/unittests/clangd/TestTU.cpp
 clang-tools-extra/trunk/unittests/clangd/TestTU.h

Modified: clang-tools-extra/trunk/clangd/Quality.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.cpp?rev=336318=336317=336318=diff
==
--- clang-tools-extra/trunk/clangd/Quality.cpp (original)
+++ clang-tools-extra/trunk/clangd/Quality.cpp Thu Jul  5 01:14:04 2018
@@ -11,10 +11,12 @@
  #include "URI.h"
  #include "index/Index.h"
  #include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
  #include "clang/AST/DeclVisitor.h"
  #include "clang/Basic/CharInfo.h"
  #include "clang/Basic/SourceManager.h"
  #include "clang/Sema/CodeCompleteConsumer.h"
+#include "llvm/Support/Casting.h"
  #include "llvm/Support/FormatVariadic.h"
  #include "llvm/Support/MathExtras.h"
  #include "llvm/Support/raw_ostream.h"
@@ -195,6 +197,9 @@ ComputeScope(const NamedDecl *D) {
if (auto *R = dyn_cast_or_null(D))
  if (R->isInjectedClassName())
DC = DC->getParent();
+  // Class constructor should have the same scope as the class.
+  if (const auto *Ctor = llvm::dyn_cast(D))
+DC = DC->getParent();
bool InClass = false;
for (; !DC->isFileContext(); DC = DC->getParent()) {
  if (DC->isFunctionOrMethod())

Modified: clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp?rev=336318=336317=336318=diff
==
--- clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp Thu Jul  5 
01:14:04 2018
@@ -21,6 +21,9 @@
  #include "Quality.h"
  #include "TestFS.h"
  #include "TestTU.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "llvm/Support/Casting.h"
  #include "gmock/gmock.h"
  #include "gtest/gtest.h"
  
@@ -199,6 +202,31 @@ TEST(QualityTests, SortText) {

EXPECT_LT(sortText(0, "a"), sortText(0, "z"));
  }
  
+TEST(QualityTests, NoBoostForClassConstructor) {

+  auto Header = TestTU::withHeaderCode(R"cpp(
+class Foo {
+public:
+  Foo(int);
+};
+  )cpp");
+  auto Symbols = Header.headerSymbols();
+  auto AST = Header.build();
+
+  const NamedDecl *Foo = (AST, "Foo");
+  SymbolRelevanceSignals Cls;
+  Cls.merge(CodeCompletionResult(Foo, /*Priority=*/0));
+
+  const NamedDecl *CtorDecl = (AST, [](const NamedDecl ) {
+return (ND.getQualifiedNameAsString() == "Foo::Foo") &&
+   llvm::isa();
+  });
+  SymbolRelevanceSignals Ctor;
+  Ctor.merge(CodeCompletionResult(CtorDecl, /*Priority=*/0));
+
+  EXPECT_EQ(Cls.Scope, SymbolRelevanceSignals::GlobalScope);
+  EXPECT_EQ(Ctor.Scope, SymbolRelevanceSignals::GlobalScope);
+}
+
  } // namespace
  } // namespace clangd
  } // namespace clang

Modified: clang-tools-extra/trunk/unittests/clangd/TestTU.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/TestTU.cpp?rev=336318=336317=336318=diff

[PATCH] D32845: [Analyzer] Iterator Checker - Part 4: Mismatched iterator checker for function parameters

2018-07-05 Thread Whisperity via Phabricator via cfe-commits
whisperity added inline comments.



Comment at: include/clang/StaticAnalyzer/Checkers/Checkers.td:317
 
+def MismatchedIteratorChecker : Checker<"MismatchedIterator">,
+  HelpText<"Check for use of iterators of different containers where iterators 
of the same container are expected">,

Is there any particular order entries of this file should be in? Seems to be 
broken now, but I guess when this patch comes up to the top of the stack it 
shall be fixed at a rebase.



Comment at: lib/StaticAnalyzer/Checkers/IteratorChecker.cpp:426
+  // For every template parameter which is an iterator type in the
+  // instantiation look for all functions parameters type by it and
+  // check whether they belong to the same container

functions' parameters' ?



Comment at: lib/StaticAnalyzer/Checkers/IteratorChecker.cpp:934
+}
+reportMismatchedBug("Iterator access mismatched.", Iter1, Iter2, C, N);
+  }

If this string is the message that gets printed to the user, I think it must be 
rephrased a bit. If this message came across me, I'd be puzzled at first to 
understand what it is trying to mean.


https://reviews.llvm.org/D32845



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


r336332 - [ASTImporter] Fix import of objects with anonymous types

2018-07-05 Thread Gabor Marton via cfe-commits
Author: martong
Date: Thu Jul  5 02:51:13 2018
New Revision: 336332

URL: http://llvm.org/viewvc/llvm-project?rev=336332=rev
Log:
[ASTImporter] Fix import of objects with anonymous types

Summary:
Currently, anonymous types are merged into the same redecl chain even if they
are structurally inequivalent. This results that global objects are not
imported, if there are at least two global objects with different anonymous
types. This patch provides a fix.

Reviewers: a.sidorin, balazske, r.stahl

Subscribers: rnkovacs, dkrupp, cfe-commits

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

Modified:
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/unittests/AST/ASTImporterTest.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=336332=336331=336332=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Thu Jul  5 02:51:13 2018
@@ -2072,17 +2072,8 @@ Decl *ASTNodeImporter::VisitRecordDecl(R
 
   if (auto *FoundRecord = dyn_cast(Found)) {
 if (!SearchName) {
-  // If both unnamed structs/unions are in a record context, make sure
-  // they occur in the same location in the context records.
-  if (Optional Index1 =
-  StructuralEquivalenceContext::findUntaggedStructOrUnionIndex(
-  D)) {
-if (Optional Index2 = StructuralEquivalenceContext::
-findUntaggedStructOrUnionIndex(FoundRecord)) {
-  if (*Index1 != *Index2)
-continue;
-}
-  }
+  if (!IsStructuralMatch(D, FoundRecord, false))
+continue;
 }
 
 PrevDecl = FoundRecord;

Modified: cfe/trunk/unittests/AST/ASTImporterTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTImporterTest.cpp?rev=336332=336331=336332=diff
==
--- cfe/trunk/unittests/AST/ASTImporterTest.cpp (original)
+++ cfe/trunk/unittests/AST/ASTImporterTest.cpp Thu Jul  5 02:51:13 2018
@@ -1682,6 +1682,35 @@ TEST_P(
 .match(ToTU, classTemplateSpecializationDecl()));
 }
 
+TEST_P(ASTImporterTestBase, ObjectsWithUnnamedStructType) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  struct { int a; int b; } object0 = { 2, 3 };
+  struct { int x; int y; int z; } object1;
+  )",
+  Lang_CXX, "input0.cc");
+
+  auto getRecordDecl = [](VarDecl *VD) {
+auto *ET = cast(VD->getType().getTypePtr());
+return cast(ET->getNamedType().getTypePtr())->getDecl();
+  };
+
+  auto *Obj0 =
+  FirstDeclMatcher().match(FromTU, varDecl(hasName("object0")));
+  auto *From0 = getRecordDecl(Obj0);
+  auto *Obj1 =
+  FirstDeclMatcher().match(FromTU, varDecl(hasName("object1")));
+  auto *From1 = getRecordDecl(Obj1);
+
+  auto *To0 = Import(From0, Lang_CXX);
+  auto *To1 = Import(From1, Lang_CXX);
+
+  EXPECT_TRUE(To0);
+  EXPECT_TRUE(To1);
+  EXPECT_NE(To0, To1);
+  EXPECT_NE(To0->getCanonicalDecl(), To1->getCanonicalDecl());
+}
+
 struct ImportFunctions : ASTImporterTestBase {};
 
 TEST_P(ImportFunctions,


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


[PATCH] D48773: [ASTImporter] Fix import of objects with anonymous types

2018-07-05 Thread Gabor Marton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC336332: [ASTImporter] Fix import of objects with anonymous 
types (authored by martong, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D48773?vs=154187=154192#toc

Repository:
  rC Clang

https://reviews.llvm.org/D48773

Files:
  lib/AST/ASTImporter.cpp
  unittests/AST/ASTImporterTest.cpp


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -1682,6 +1682,35 @@
 .match(ToTU, classTemplateSpecializationDecl()));
 }
 
+TEST_P(ASTImporterTestBase, ObjectsWithUnnamedStructType) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  struct { int a; int b; } object0 = { 2, 3 };
+  struct { int x; int y; int z; } object1;
+  )",
+  Lang_CXX, "input0.cc");
+
+  auto getRecordDecl = [](VarDecl *VD) {
+auto *ET = cast(VD->getType().getTypePtr());
+return cast(ET->getNamedType().getTypePtr())->getDecl();
+  };
+
+  auto *Obj0 =
+  FirstDeclMatcher().match(FromTU, varDecl(hasName("object0")));
+  auto *From0 = getRecordDecl(Obj0);
+  auto *Obj1 =
+  FirstDeclMatcher().match(FromTU, varDecl(hasName("object1")));
+  auto *From1 = getRecordDecl(Obj1);
+
+  auto *To0 = Import(From0, Lang_CXX);
+  auto *To1 = Import(From1, Lang_CXX);
+
+  EXPECT_TRUE(To0);
+  EXPECT_TRUE(To1);
+  EXPECT_NE(To0, To1);
+  EXPECT_NE(To0->getCanonicalDecl(), To1->getCanonicalDecl());
+}
+
 struct ImportFunctions : ASTImporterTestBase {};
 
 TEST_P(ImportFunctions,
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -2072,17 +2072,8 @@
 
   if (auto *FoundRecord = dyn_cast(Found)) {
 if (!SearchName) {
-  // If both unnamed structs/unions are in a record context, make sure
-  // they occur in the same location in the context records.
-  if (Optional Index1 =
-  StructuralEquivalenceContext::findUntaggedStructOrUnionIndex(
-  D)) {
-if (Optional Index2 = StructuralEquivalenceContext::
-findUntaggedStructOrUnionIndex(FoundRecord)) {
-  if (*Index1 != *Index2)
-continue;
-}
-  }
+  if (!IsStructuralMatch(D, FoundRecord, false))
+continue;
 }
 
 PrevDecl = FoundRecord;


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -1682,6 +1682,35 @@
 .match(ToTU, classTemplateSpecializationDecl()));
 }
 
+TEST_P(ASTImporterTestBase, ObjectsWithUnnamedStructType) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  struct { int a; int b; } object0 = { 2, 3 };
+  struct { int x; int y; int z; } object1;
+  )",
+  Lang_CXX, "input0.cc");
+
+  auto getRecordDecl = [](VarDecl *VD) {
+auto *ET = cast(VD->getType().getTypePtr());
+return cast(ET->getNamedType().getTypePtr())->getDecl();
+  };
+
+  auto *Obj0 =
+  FirstDeclMatcher().match(FromTU, varDecl(hasName("object0")));
+  auto *From0 = getRecordDecl(Obj0);
+  auto *Obj1 =
+  FirstDeclMatcher().match(FromTU, varDecl(hasName("object1")));
+  auto *From1 = getRecordDecl(Obj1);
+
+  auto *To0 = Import(From0, Lang_CXX);
+  auto *To1 = Import(From1, Lang_CXX);
+
+  EXPECT_TRUE(To0);
+  EXPECT_TRUE(To1);
+  EXPECT_NE(To0, To1);
+  EXPECT_NE(To0->getCanonicalDecl(), To1->getCanonicalDecl());
+}
+
 struct ImportFunctions : ASTImporterTestBase {};
 
 TEST_P(ImportFunctions,
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -2072,17 +2072,8 @@
 
   if (auto *FoundRecord = dyn_cast(Found)) {
 if (!SearchName) {
-  // If both unnamed structs/unions are in a record context, make sure
-  // they occur in the same location in the context records.
-  if (Optional Index1 =
-  StructuralEquivalenceContext::findUntaggedStructOrUnionIndex(
-  D)) {
-if (Optional Index2 = StructuralEquivalenceContext::
-findUntaggedStructOrUnionIndex(FoundRecord)) {
-  if (*Index1 != *Index2)
-continue;
-}
-  }
+  if (!IsStructuralMatch(D, FoundRecord, false))
+continue;
 }
 
 PrevDecl = FoundRecord;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32747: [Analyzer] Iterator Checker - Part 3: Invalidation check, first for (copy) assignments

2018-07-05 Thread Whisperity via Phabricator via cfe-commits
whisperity added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/IteratorChecker.cpp:92
+  // Whether iterator is valid
+  bool Valid;
+

Seeing that in line 106 you consider this record immutable, you might want to 
add a `const` on this field too.



Comment at: test/Analysis/invalidated-iterator.cpp:32
+  *i0; // expected-warning{{Invalidated iterator accessed}}
+}

This might not be applicable here, but isn't there a test case for copy 
operations where the iterator isn't invalidated? Something of a positive test 
to be added here. My only idea is something with weird reference-to-pointer 
magic. Might not worth the hassle.


https://reviews.llvm.org/D32747



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


[clang-tools-extra] r336330 - [NFS] Wipe trailing whitespaces

2018-07-05 Thread Kirill Bobyrev via cfe-commits
Author: omtcyfz
Date: Thu Jul  5 02:37:26 2018
New Revision: 336330

URL: http://llvm.org/viewvc/llvm-project?rev=336330=rev
Log:
[NFS] Wipe trailing whitespaces

This patch is a preparation for another one containing meaningful
changes. This patch simply removes trailing whitespaces in few files
affected by the upcoming patch and reformats

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

Modified: clang-tools-extra/trunk/clangd/Quality.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.cpp?rev=336330=336329=336330=diff
==
--- clang-tools-extra/trunk/clangd/Quality.cpp (original)
+++ clang-tools-extra/trunk/clangd/Quality.cpp Thu Jul  5 02:37:26 2018
@@ -64,7 +64,8 @@ static SymbolQualitySignals::SymbolCateg
   return Switch().Visit();
 }
 
-static SymbolQualitySignals::SymbolCategory categorize(const 
CodeCompletionResult ) {
+static SymbolQualitySignals::SymbolCategory
+categorize(const CodeCompletionResult ) {
   if (R.Declaration)
 return categorize(*R.Declaration);
   if (R.Kind == CodeCompletionResult::RK_Macro)
@@ -72,57 +73,57 @@ static SymbolQualitySignals::SymbolCateg
   // Everything else is a keyword or a pattern. Patterns are mostly keywords
   // too, except a few which we recognize by cursor kind.
   switch (R.CursorKind) {
-case CXCursor_CXXMethod:
-  return SymbolQualitySignals::Function;
-case CXCursor_ModuleImportDecl:
-  return SymbolQualitySignals::Namespace;
-case CXCursor_MacroDefinition:
-  return SymbolQualitySignals::Macro;
-case CXCursor_TypeRef:
-  return SymbolQualitySignals::Type;
-case CXCursor_MemberRef:
-  return SymbolQualitySignals::Variable;
-default:
-  return SymbolQualitySignals::Keyword;
+  case CXCursor_CXXMethod:
+return SymbolQualitySignals::Function;
+  case CXCursor_ModuleImportDecl:
+return SymbolQualitySignals::Namespace;
+  case CXCursor_MacroDefinition:
+return SymbolQualitySignals::Macro;
+  case CXCursor_TypeRef:
+return SymbolQualitySignals::Type;
+  case CXCursor_MemberRef:
+return SymbolQualitySignals::Variable;
+  default:
+return SymbolQualitySignals::Keyword;
   }
 }
 
 static SymbolQualitySignals::SymbolCategory
 categorize(const index::SymbolInfo ) {
   switch (D.Kind) {
-case index::SymbolKind::Namespace:
-case index::SymbolKind::NamespaceAlias:
-  return SymbolQualitySignals::Namespace;
-case index::SymbolKind::Macro:
-  return SymbolQualitySignals::Macro;
-case index::SymbolKind::Enum:
-case index::SymbolKind::Struct:
-case index::SymbolKind::Class:
-case index::SymbolKind::Protocol:
-case index::SymbolKind::Extension:
-case index::SymbolKind::Union:
-case index::SymbolKind::TypeAlias:
-  return SymbolQualitySignals::Type;
-case index::SymbolKind::Function:
-case index::SymbolKind::ClassMethod:
-case index::SymbolKind::InstanceMethod:
-case index::SymbolKind::StaticMethod:
-case index::SymbolKind::InstanceProperty:
-case index::SymbolKind::ClassProperty:
-case index::SymbolKind::StaticProperty:
-case index::SymbolKind::Constructor:
-case index::SymbolKind::Destructor:
-case index::SymbolKind::ConversionFunction:
-  return SymbolQualitySignals::Function;
-case index::SymbolKind::Variable:
-case index::SymbolKind::Field:
-case index::SymbolKind::EnumConstant:
-case index::SymbolKind::Parameter:
-  return SymbolQualitySignals::Variable;
-case index::SymbolKind::Using:
-case index::SymbolKind::Module:
-case index::SymbolKind::Unknown:
-  return SymbolQualitySignals::Unknown;
+  case index::SymbolKind::Namespace:
+  case index::SymbolKind::NamespaceAlias:
+return SymbolQualitySignals::Namespace;
+  case index::SymbolKind::Macro:
+return SymbolQualitySignals::Macro;
+  case index::SymbolKind::Enum:
+  case index::SymbolKind::Struct:
+  case index::SymbolKind::Class:
+  case index::SymbolKind::Protocol:
+  case index::SymbolKind::Extension:
+  case index::SymbolKind::Union:
+  case index::SymbolKind::TypeAlias:
+return SymbolQualitySignals::Type;
+  case index::SymbolKind::Function:
+  case index::SymbolKind::ClassMethod:
+  case index::SymbolKind::InstanceMethod:
+  case index::SymbolKind::StaticMethod:
+  case index::SymbolKind::InstanceProperty:
+  case index::SymbolKind::ClassProperty:
+  case index::SymbolKind::StaticProperty:
+  case index::SymbolKind::Constructor:
+  case index::SymbolKind::Destructor:
+  case index::SymbolKind::ConversionFunction:
+return SymbolQualitySignals::Function;
+  case index::SymbolKind::Variable:
+  case index::SymbolKind::Field:
+  case index::SymbolKind::EnumConstant:
+  case index::SymbolKind::Parameter:
+return SymbolQualitySignals::Variable;
+  case index::SymbolKind::Using:
+  case index::SymbolKind::Module:
+  case index::SymbolKind::Unknown:
+return 

[clang-tools-extra] r336329 - Fix -Wunused-variable warning. NFCI.

2018-07-05 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Thu Jul  5 02:35:12 2018
New Revision: 336329

URL: http://llvm.org/viewvc/llvm-project?rev=336329=rev
Log:
Fix -Wunused-variable warning. NFCI.

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

Modified: clang-tools-extra/trunk/clangd/Quality.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.cpp?rev=336329=336328=336329=diff
==
--- clang-tools-extra/trunk/clangd/Quality.cpp (original)
+++ clang-tools-extra/trunk/clangd/Quality.cpp Thu Jul  5 02:35:12 2018
@@ -198,7 +198,7 @@ ComputeScope(const NamedDecl *D) {
 if (R->isInjectedClassName())
   DC = DC->getParent();
   // Class constructor should have the same scope as the class.
-  if (const auto *Ctor = llvm::dyn_cast(D))
+  if (isa(D))
 DC = DC->getParent();
   bool InClass = false;
   for (; !DC->isFileContext(); DC = DC->getParent()) {


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


[PATCH] D48773: [ASTImporter] Fix import of objects with anonymous types

2018-07-05 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 154187.
martong added a comment.

`PrevDecl` is set after the `!SearchName` branch, as it had been done before.
This way original behaviour is kept as much as possible.


Repository:
  rC Clang

https://reviews.llvm.org/D48773

Files:
  lib/AST/ASTImporter.cpp
  unittests/AST/ASTImporterTest.cpp


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -1622,6 +1622,35 @@
 .match(ToTU, classTemplateSpecializationDecl()));
 }
 
+TEST_P(ASTImporterTestBase, ObjectsWithUnnamedStructType) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  struct { int a; int b; } object0 = { 2, 3 };
+  struct { int x; int y; int z; } object1;
+  )",
+  Lang_CXX, "input0.cc");
+
+  auto getRecordDecl = [](VarDecl *VD) {
+auto *ET = cast(VD->getType().getTypePtr());
+return cast(ET->getNamedType().getTypePtr())->getDecl();
+  };
+
+  auto *Obj0 =
+  FirstDeclMatcher().match(FromTU, varDecl(hasName("object0")));
+  auto *From0 = getRecordDecl(Obj0);
+  auto *Obj1 =
+  FirstDeclMatcher().match(FromTU, varDecl(hasName("object1")));
+  auto *From1 = getRecordDecl(Obj1);
+
+  auto *To0 = Import(From0, Lang_CXX);
+  auto *To1 = Import(From1, Lang_CXX);
+
+  EXPECT_TRUE(To0);
+  EXPECT_TRUE(To1);
+  EXPECT_NE(To0, To1);
+  EXPECT_NE(To0->getCanonicalDecl(), To1->getCanonicalDecl());
+}
+
 struct ImportFunctions : ASTImporterTestBase {};
 
 TEST_P(ImportFunctions,
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -2072,17 +2072,8 @@
 
   if (auto *FoundRecord = dyn_cast(Found)) {
 if (!SearchName) {
-  // If both unnamed structs/unions are in a record context, make sure
-  // they occur in the same location in the context records.
-  if (Optional Index1 =
-  StructuralEquivalenceContext::findUntaggedStructOrUnionIndex(
-  D)) {
-if (Optional Index2 = StructuralEquivalenceContext::
-findUntaggedStructOrUnionIndex(FoundRecord)) {
-  if (*Index1 != *Index2)
-continue;
-}
-  }
+  if (!IsStructuralMatch(D, FoundRecord, false))
+continue;
 }
 
 PrevDecl = FoundRecord;


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -1622,6 +1622,35 @@
 .match(ToTU, classTemplateSpecializationDecl()));
 }
 
+TEST_P(ASTImporterTestBase, ObjectsWithUnnamedStructType) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  struct { int a; int b; } object0 = { 2, 3 };
+  struct { int x; int y; int z; } object1;
+  )",
+  Lang_CXX, "input0.cc");
+
+  auto getRecordDecl = [](VarDecl *VD) {
+auto *ET = cast(VD->getType().getTypePtr());
+return cast(ET->getNamedType().getTypePtr())->getDecl();
+  };
+
+  auto *Obj0 =
+  FirstDeclMatcher().match(FromTU, varDecl(hasName("object0")));
+  auto *From0 = getRecordDecl(Obj0);
+  auto *Obj1 =
+  FirstDeclMatcher().match(FromTU, varDecl(hasName("object1")));
+  auto *From1 = getRecordDecl(Obj1);
+
+  auto *To0 = Import(From0, Lang_CXX);
+  auto *To1 = Import(From1, Lang_CXX);
+
+  EXPECT_TRUE(To0);
+  EXPECT_TRUE(To1);
+  EXPECT_NE(To0, To1);
+  EXPECT_NE(To0->getCanonicalDecl(), To1->getCanonicalDecl());
+}
+
 struct ImportFunctions : ASTImporterTestBase {};
 
 TEST_P(ImportFunctions,
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -2072,17 +2072,8 @@
 
   if (auto *FoundRecord = dyn_cast(Found)) {
 if (!SearchName) {
-  // If both unnamed structs/unions are in a record context, make sure
-  // they occur in the same location in the context records.
-  if (Optional Index1 =
-  StructuralEquivalenceContext::findUntaggedStructOrUnionIndex(
-  D)) {
-if (Optional Index2 = StructuralEquivalenceContext::
-findUntaggedStructOrUnionIndex(FoundRecord)) {
-  if (*Index1 != *Index2)
-continue;
-}
-  }
+  if (!IsStructuralMatch(D, FoundRecord, false))
+continue;
 }
 
 PrevDecl = FoundRecord;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r336321 - [clangd] Log sema completion context kind and query scopes. NFC

2018-07-05 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Thu Jul  5 01:29:33 2018
New Revision: 336321

URL: http://llvm.org/viewvc/llvm-project?rev=336321=rev
Log:
[clangd] Log sema completion context kind and query scopes. NFC

Reviewers: sammccall

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

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

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

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=336321=336320=336321=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Thu Jul  5 01:29:33 2018
@@ -41,6 +41,7 @@
 #include "clang/Sema/Sema.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include 
 
@@ -940,6 +941,7 @@ class CodeCompleteFlow {
   int NSema = 0, NIndex = 0, NBoth = 0; // Counters for logging.
   bool Incomplete = false; // Would more be available with a higher limit?
   llvm::Optional Filter;   // Initialized once Sema runs.
+  std::vector QueryScopes;  // Initialized once Sema runs.
   // Include-insertion and proximity scoring rely on the include structure.
   // This is available after Sema has run.
   llvm::Optional Inserter;  // Available during runWithSema.
@@ -1001,6 +1003,10 @@ public:
   Inserter.reset(); // Make sure this doesn't out-live Clang.
   SPAN_ATTACH(Tracer, "sema_completion_kind",
   getCompletionKindString(Recorder->CCContext.getKind()));
+  log(llvm::formatv(
+  "Code complete: sema context {0}, query scopes [{1}]",
+  getCompletionKindString(Recorder->CCContext.getKind()),
+  llvm::join(QueryScopes.begin(), QueryScopes.end(), ",")));
 });
 
 Recorder = RecorderOwner.get();
@@ -1028,6 +1034,8 @@ private:
   CodeCompleteResult runWithSema() {
 Filter = FuzzyMatcher(
 Recorder->CCSema->getPreprocessor().getCodeCompletionFilter());
+QueryScopes = getQueryScopes(Recorder->CCContext,
+ Recorder->CCSema->getSourceManager());
 // Sema provides the needed context to query the index.
 // FIXME: in addition to querying for extra/overlapping symbols, we should
 //explicitly request symbols corresponding to Sema results.
@@ -1059,8 +1067,7 @@ private:
   Req.MaxCandidateCount = Opts.Limit;
 Req.Query = Filter->pattern();
 Req.RestrictForCodeCompletion = true;
-Req.Scopes = getQueryScopes(Recorder->CCContext,
-Recorder->CCSema->getSourceManager());
+Req.Scopes = QueryScopes;
 // FIXME: we should send multiple weighted paths here.
 Req.ProximityPaths.push_back(FileName);
 log(llvm::formatv("Code complete: fuzzyFind(\"{0}\", scopes=[{1}])",


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


[PATCH] D48724: [clangd] Log sema completion context kind and query scopes. NFC

2018-07-05 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE336321: [clangd] Log sema completion context kind and 
query scopes. NFC (authored by ioeric, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D48724?vs=154185=154186#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48724

Files:
  clangd/CodeComplete.cpp


Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -41,6 +41,7 @@
 #include "clang/Sema/Sema.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include 
 
@@ -940,6 +941,7 @@
   int NSema = 0, NIndex = 0, NBoth = 0; // Counters for logging.
   bool Incomplete = false; // Would more be available with a higher limit?
   llvm::Optional Filter;   // Initialized once Sema runs.
+  std::vector QueryScopes;  // Initialized once Sema runs.
   // Include-insertion and proximity scoring rely on the include structure.
   // This is available after Sema has run.
   llvm::Optional Inserter;  // Available during runWithSema.
@@ -1001,6 +1003,10 @@
   Inserter.reset(); // Make sure this doesn't out-live Clang.
   SPAN_ATTACH(Tracer, "sema_completion_kind",
   getCompletionKindString(Recorder->CCContext.getKind()));
+  log(llvm::formatv(
+  "Code complete: sema context {0}, query scopes [{1}]",
+  getCompletionKindString(Recorder->CCContext.getKind()),
+  llvm::join(QueryScopes.begin(), QueryScopes.end(), ",")));
 });
 
 Recorder = RecorderOwner.get();
@@ -1028,6 +1034,8 @@
   CodeCompleteResult runWithSema() {
 Filter = FuzzyMatcher(
 Recorder->CCSema->getPreprocessor().getCodeCompletionFilter());
+QueryScopes = getQueryScopes(Recorder->CCContext,
+ Recorder->CCSema->getSourceManager());
 // Sema provides the needed context to query the index.
 // FIXME: in addition to querying for extra/overlapping symbols, we should
 //explicitly request symbols corresponding to Sema results.
@@ -1059,8 +1067,7 @@
   Req.MaxCandidateCount = Opts.Limit;
 Req.Query = Filter->pattern();
 Req.RestrictForCodeCompletion = true;
-Req.Scopes = getQueryScopes(Recorder->CCContext,
-Recorder->CCSema->getSourceManager());
+Req.Scopes = QueryScopes;
 // FIXME: we should send multiple weighted paths here.
 Req.ProximityPaths.push_back(FileName);
 log(llvm::formatv("Code complete: fuzzyFind(\"{0}\", scopes=[{1}])",


Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -41,6 +41,7 @@
 #include "clang/Sema/Sema.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include 
 
@@ -940,6 +941,7 @@
   int NSema = 0, NIndex = 0, NBoth = 0; // Counters for logging.
   bool Incomplete = false; // Would more be available with a higher limit?
   llvm::Optional Filter;   // Initialized once Sema runs.
+  std::vector QueryScopes;  // Initialized once Sema runs.
   // Include-insertion and proximity scoring rely on the include structure.
   // This is available after Sema has run.
   llvm::Optional Inserter;  // Available during runWithSema.
@@ -1001,6 +1003,10 @@
   Inserter.reset(); // Make sure this doesn't out-live Clang.
   SPAN_ATTACH(Tracer, "sema_completion_kind",
   getCompletionKindString(Recorder->CCContext.getKind()));
+  log(llvm::formatv(
+  "Code complete: sema context {0}, query scopes [{1}]",
+  getCompletionKindString(Recorder->CCContext.getKind()),
+  llvm::join(QueryScopes.begin(), QueryScopes.end(), ",")));
 });
 
 Recorder = RecorderOwner.get();
@@ -1028,6 +1034,8 @@
   CodeCompleteResult runWithSema() {
 Filter = FuzzyMatcher(
 Recorder->CCSema->getPreprocessor().getCodeCompletionFilter());
+QueryScopes = getQueryScopes(Recorder->CCContext,
+ Recorder->CCSema->getSourceManager());
 // Sema provides the needed context to query the index.
 // FIXME: in addition to querying for extra/overlapping symbols, we should
 //explicitly request symbols corresponding to Sema results.
@@ -1059,8 +1067,7 @@
   Req.MaxCandidateCount = Opts.Limit;
 Req.Query = Filter->pattern();
 Req.RestrictForCodeCompletion = true;
-Req.Scopes = getQueryScopes(Recorder->CCContext,
-Recorder->CCSema->getSourceManager());
+Req.Scopes = QueryScopes;
 // FIXME: we should send multiple weighted paths here.
 Req.ProximityPaths.push_back(FileName);
 

[PATCH] D48724: [clangd] Log sema completion context kind and query scopes. NFC

2018-07-05 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 154185.
ioeric added a comment.

-Rebase


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48724

Files:
  clangd/CodeComplete.cpp


Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -41,6 +41,7 @@
 #include "clang/Sema/Sema.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include 
 
@@ -940,6 +941,7 @@
   int NSema = 0, NIndex = 0, NBoth = 0; // Counters for logging.
   bool Incomplete = false; // Would more be available with a higher limit?
   llvm::Optional Filter;   // Initialized once Sema runs.
+  std::vector QueryScopes;  // Initialized once Sema runs.
   // Include-insertion and proximity scoring rely on the include structure.
   // This is available after Sema has run.
   llvm::Optional Inserter;  // Available during runWithSema.
@@ -1001,6 +1003,10 @@
   Inserter.reset(); // Make sure this doesn't out-live Clang.
   SPAN_ATTACH(Tracer, "sema_completion_kind",
   getCompletionKindString(Recorder->CCContext.getKind()));
+  log(llvm::formatv(
+  "Code complete: sema context {0}, query scopes [{1}]",
+  getCompletionKindString(Recorder->CCContext.getKind()),
+  llvm::join(QueryScopes.begin(), QueryScopes.end(), ",")));
 });
 
 Recorder = RecorderOwner.get();
@@ -1028,6 +1034,8 @@
   CodeCompleteResult runWithSema() {
 Filter = FuzzyMatcher(
 Recorder->CCSema->getPreprocessor().getCodeCompletionFilter());
+QueryScopes = getQueryScopes(Recorder->CCContext,
+ Recorder->CCSema->getSourceManager());
 // Sema provides the needed context to query the index.
 // FIXME: in addition to querying for extra/overlapping symbols, we should
 //explicitly request symbols corresponding to Sema results.
@@ -1059,8 +1067,7 @@
   Req.MaxCandidateCount = Opts.Limit;
 Req.Query = Filter->pattern();
 Req.RestrictForCodeCompletion = true;
-Req.Scopes = getQueryScopes(Recorder->CCContext,
-Recorder->CCSema->getSourceManager());
+Req.Scopes = QueryScopes;
 // FIXME: we should send multiple weighted paths here.
 Req.ProximityPaths.push_back(FileName);
 log(llvm::formatv("Code complete: fuzzyFind(\"{0}\", scopes=[{1}])",


Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -41,6 +41,7 @@
 #include "clang/Sema/Sema.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include 
 
@@ -940,6 +941,7 @@
   int NSema = 0, NIndex = 0, NBoth = 0; // Counters for logging.
   bool Incomplete = false; // Would more be available with a higher limit?
   llvm::Optional Filter;   // Initialized once Sema runs.
+  std::vector QueryScopes;  // Initialized once Sema runs.
   // Include-insertion and proximity scoring rely on the include structure.
   // This is available after Sema has run.
   llvm::Optional Inserter;  // Available during runWithSema.
@@ -1001,6 +1003,10 @@
   Inserter.reset(); // Make sure this doesn't out-live Clang.
   SPAN_ATTACH(Tracer, "sema_completion_kind",
   getCompletionKindString(Recorder->CCContext.getKind()));
+  log(llvm::formatv(
+  "Code complete: sema context {0}, query scopes [{1}]",
+  getCompletionKindString(Recorder->CCContext.getKind()),
+  llvm::join(QueryScopes.begin(), QueryScopes.end(), ",")));
 });
 
 Recorder = RecorderOwner.get();
@@ -1028,6 +1034,8 @@
   CodeCompleteResult runWithSema() {
 Filter = FuzzyMatcher(
 Recorder->CCSema->getPreprocessor().getCodeCompletionFilter());
+QueryScopes = getQueryScopes(Recorder->CCContext,
+ Recorder->CCSema->getSourceManager());
 // Sema provides the needed context to query the index.
 // FIXME: in addition to querying for extra/overlapping symbols, we should
 //explicitly request symbols corresponding to Sema results.
@@ -1059,8 +1067,7 @@
   Req.MaxCandidateCount = Opts.Limit;
 Req.Query = Filter->pattern();
 Req.RestrictForCodeCompletion = true;
-Req.Scopes = getQueryScopes(Recorder->CCContext,
-Recorder->CCSema->getSourceManager());
+Req.Scopes = QueryScopes;
 // FIXME: we should send multiple weighted paths here.
 Req.ProximityPaths.push_back(FileName);
 log(llvm::formatv("Code complete: fuzzyFind(\"{0}\", scopes=[{1}])",
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[clang-tools-extra] r336320 - Revert "[clangd] FileDistance: temporarily disable in CodeComplete, it's behaving badly"

2018-07-05 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Thu Jul  5 01:26:53 2018
New Revision: 336320

URL: http://llvm.org/viewvc/llvm-project?rev=336320=rev
Log:
Revert "[clangd] FileDistance: temporarily disable in CodeComplete, it's 
behaving badly"

The bad behavior seems to have been fixed by r336242 after all.
I thought it was persisting, but that was a different bug fixed by D48940

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

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=336320=336319=336320=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Thu Jul  5 01:26:53 2018
@@ -1142,8 +1142,7 @@ private:
 SymbolQualitySignals Quality;
 SymbolRelevanceSignals Relevance;
 Relevance.Query = SymbolRelevanceSignals::CodeComplete;
-// FIXME: re-enable this after working out why it eats memory.
-// Relevance.FileProximityMatch = FileProximity.getPointer();
+Relevance.FileProximityMatch = FileProximity.getPointer();
 auto  = Bundle.front();
 if (auto FuzzyScore = fuzzyScore(First))
   Relevance.NameMatch = *FuzzyScore;


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


[PATCH] D48933: [clangd] Treat class constructor as in the same scope as the class in ranking.

2018-07-05 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE336318: [clangd] Treat class constructor as in the same 
scope as the class in ranking. (authored by ioeric, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D48933?vs=154182=154183#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48933

Files:
  clangd/Quality.cpp
  unittests/clangd/QualityTests.cpp
  unittests/clangd/TestTU.cpp
  unittests/clangd/TestTU.h

Index: unittests/clangd/TestTU.cpp
===
--- unittests/clangd/TestTU.cpp
+++ unittests/clangd/TestTU.cpp
@@ -93,26 +93,35 @@
   return LookupDecl(*Scope, Components.back());
 }
 
-const NamedDecl (ParsedAST , llvm::StringRef Name) {
+const NamedDecl (ParsedAST ,
+ std::function Callback) {
   struct Visitor : RecursiveASTVisitor {
-llvm::StringRef Name;
+decltype(Callback) CB;
 llvm::SmallVector Decls;
 bool VisitNamedDecl(const NamedDecl *ND) {
-  if (auto *ID = ND->getIdentifier())
-if (ID->getName() == Name)
-  Decls.push_back(ND);
+  if (CB(*ND))
+Decls.push_back(ND);
   return true;
 }
   } Visitor;
-  Visitor.Name = Name;
+  Visitor.CB = Callback;
   for (Decl *D : AST.getLocalTopLevelDecls())
 Visitor.TraverseDecl(D);
   if (Visitor.Decls.size() != 1) {
-ADD_FAILURE() << Visitor.Decls.size() << " symbols named " << Name;
+ADD_FAILURE() << Visitor.Decls.size() << " symbols matched.";
 assert(Visitor.Decls.size() == 1);
   }
   return *Visitor.Decls.front();
 }
 
+const NamedDecl (ParsedAST , llvm::StringRef Name) {
+  return findAnyDecl(AST, [Name](const NamedDecl ) {
+if (auto *ID = ND.getIdentifier())
+  if (ID->getName() == Name)
+return true;
+return false;
+  });
+}
+
 } // namespace clangd
 } // namespace clang
Index: unittests/clangd/QualityTests.cpp
===
--- unittests/clangd/QualityTests.cpp
+++ unittests/clangd/QualityTests.cpp
@@ -21,6 +21,9 @@
 #include "Quality.h"
 #include "TestFS.h"
 #include "TestTU.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "llvm/Support/Casting.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -199,6 +202,31 @@
   EXPECT_LT(sortText(0, "a"), sortText(0, "z"));
 }
 
+TEST(QualityTests, NoBoostForClassConstructor) {
+  auto Header = TestTU::withHeaderCode(R"cpp(
+class Foo {
+public:
+  Foo(int);
+};
+  )cpp");
+  auto Symbols = Header.headerSymbols();
+  auto AST = Header.build();
+
+  const NamedDecl *Foo = (AST, "Foo");
+  SymbolRelevanceSignals Cls;
+  Cls.merge(CodeCompletionResult(Foo, /*Priority=*/0));
+
+  const NamedDecl *CtorDecl = (AST, [](const NamedDecl ) {
+return (ND.getQualifiedNameAsString() == "Foo::Foo") &&
+   llvm::isa();
+  });
+  SymbolRelevanceSignals Ctor;
+  Ctor.merge(CodeCompletionResult(CtorDecl, /*Priority=*/0));
+
+  EXPECT_EQ(Cls.Scope, SymbolRelevanceSignals::GlobalScope);
+  EXPECT_EQ(Ctor.Scope, SymbolRelevanceSignals::GlobalScope);
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: unittests/clangd/TestTU.h
===
--- unittests/clangd/TestTU.h
+++ unittests/clangd/TestTU.h
@@ -56,6 +56,9 @@
 const Symbol (const SymbolSlab &, llvm::StringRef QName);
 // Look up an AST symbol by qualified name, which must be unique and top-level.
 const NamedDecl (ParsedAST , llvm::StringRef QName);
+// Look up a main-file AST symbol that satisfies \p Filter.
+const NamedDecl (ParsedAST ,
+ std::function Filter);
 // Look up a main-file AST symbol by unqualified name, which must be unique.
 const NamedDecl (ParsedAST , llvm::StringRef Name);
 
Index: clangd/Quality.cpp
===
--- clangd/Quality.cpp
+++ clangd/Quality.cpp
@@ -11,10 +11,12 @@
 #include "URI.h"
 #include "index/Index.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclVisitor.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
@@ -195,6 +197,9 @@
   if (auto *R = dyn_cast_or_null(D))
 if (R->isInjectedClassName())
   DC = DC->getParent();
+  // Class constructor should have the same scope as the class.
+  if (const auto *Ctor = llvm::dyn_cast(D))
+DC = DC->getParent();
   bool InClass = false;
   for (; !DC->isFileContext(); DC = DC->getParent()) {
 if (DC->isFunctionOrMethod())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r336318 - [clangd] Treat class constructor as in the same scope as the class in ranking.

2018-07-05 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Thu Jul  5 01:14:04 2018
New Revision: 336318

URL: http://llvm.org/viewvc/llvm-project?rev=336318=rev
Log:
[clangd] Treat class constructor as in the same scope as the class in ranking.

Reviewers: sammccall

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

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

Modified:
clang-tools-extra/trunk/clangd/Quality.cpp
clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp
clang-tools-extra/trunk/unittests/clangd/TestTU.cpp
clang-tools-extra/trunk/unittests/clangd/TestTU.h

Modified: clang-tools-extra/trunk/clangd/Quality.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.cpp?rev=336318=336317=336318=diff
==
--- clang-tools-extra/trunk/clangd/Quality.cpp (original)
+++ clang-tools-extra/trunk/clangd/Quality.cpp Thu Jul  5 01:14:04 2018
@@ -11,10 +11,12 @@
 #include "URI.h"
 #include "index/Index.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclVisitor.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
@@ -195,6 +197,9 @@ ComputeScope(const NamedDecl *D) {
   if (auto *R = dyn_cast_or_null(D))
 if (R->isInjectedClassName())
   DC = DC->getParent();
+  // Class constructor should have the same scope as the class.
+  if (const auto *Ctor = llvm::dyn_cast(D))
+DC = DC->getParent();
   bool InClass = false;
   for (; !DC->isFileContext(); DC = DC->getParent()) {
 if (DC->isFunctionOrMethod())

Modified: clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp?rev=336318=336317=336318=diff
==
--- clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp Thu Jul  5 
01:14:04 2018
@@ -21,6 +21,9 @@
 #include "Quality.h"
 #include "TestFS.h"
 #include "TestTU.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "llvm/Support/Casting.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -199,6 +202,31 @@ TEST(QualityTests, SortText) {
   EXPECT_LT(sortText(0, "a"), sortText(0, "z"));
 }
 
+TEST(QualityTests, NoBoostForClassConstructor) {
+  auto Header = TestTU::withHeaderCode(R"cpp(
+class Foo {
+public:
+  Foo(int);
+};
+  )cpp");
+  auto Symbols = Header.headerSymbols();
+  auto AST = Header.build();
+
+  const NamedDecl *Foo = (AST, "Foo");
+  SymbolRelevanceSignals Cls;
+  Cls.merge(CodeCompletionResult(Foo, /*Priority=*/0));
+
+  const NamedDecl *CtorDecl = (AST, [](const NamedDecl ) {
+return (ND.getQualifiedNameAsString() == "Foo::Foo") &&
+   llvm::isa();
+  });
+  SymbolRelevanceSignals Ctor;
+  Ctor.merge(CodeCompletionResult(CtorDecl, /*Priority=*/0));
+
+  EXPECT_EQ(Cls.Scope, SymbolRelevanceSignals::GlobalScope);
+  EXPECT_EQ(Ctor.Scope, SymbolRelevanceSignals::GlobalScope);
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang

Modified: clang-tools-extra/trunk/unittests/clangd/TestTU.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/TestTU.cpp?rev=336318=336317=336318=diff
==
--- clang-tools-extra/trunk/unittests/clangd/TestTU.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/TestTU.cpp Thu Jul  5 01:14:04 2018
@@ -93,26 +93,35 @@ const NamedDecl (ParsedAST 
   return LookupDecl(*Scope, Components.back());
 }
 
-const NamedDecl (ParsedAST , llvm::StringRef Name) {
+const NamedDecl (ParsedAST ,
+ std::function Callback) {
   struct Visitor : RecursiveASTVisitor {
-llvm::StringRef Name;
+decltype(Callback) CB;
 llvm::SmallVector Decls;
 bool VisitNamedDecl(const NamedDecl *ND) {
-  if (auto *ID = ND->getIdentifier())
-if (ID->getName() == Name)
-  Decls.push_back(ND);
+  if (CB(*ND))
+Decls.push_back(ND);
   return true;
 }
   } Visitor;
-  Visitor.Name = Name;
+  Visitor.CB = Callback;
   for (Decl *D : AST.getLocalTopLevelDecls())
 Visitor.TraverseDecl(D);
   if (Visitor.Decls.size() != 1) {
-ADD_FAILURE() << Visitor.Decls.size() << " symbols named " << Name;
+ADD_FAILURE() << Visitor.Decls.size() << " symbols matched.";
 assert(Visitor.Decls.size() == 1);
   }
   return *Visitor.Decls.front();
 }
 
+const NamedDecl (ParsedAST , llvm::StringRef Name) {
+  return findAnyDecl(AST, [Name](const NamedDecl ) {
+if (auto *ID = ND.getIdentifier())
+  if (ID->getName() == Name)
+ 

  1   2   >