[PATCH] D44278: CodeGen: simplify and validate exception personalities

2018-03-08 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd closed this revision.
compnerd added a comment.

SVN r327105


Repository:
  rC Clang

https://reviews.llvm.org/D44278



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


r327105 - CodeGen: simplify and validate exception personalities

2018-03-08 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Thu Mar  8 23:06:42 2018
New Revision: 327105

URL: http://llvm.org/viewvc/llvm-project?rev=327105=rev
Log:
CodeGen: simplify and validate exception personalities

Simplify the dispatching for the personality routines.  This really had
no test coverage previously, so add test coverage for the various cases.
This turns out to be pretty complicated as the various languages and
models interact to change personalities around.

You really should feel bad for the compiler if you are using exceptions.
There is no reason for this type of cruelty.

Added:
cfe/trunk/test/CodeGen/personality.c
cfe/trunk/test/CodeGenCXX/personality.cpp
cfe/trunk/test/CodeGenObjC/personality.m
cfe/trunk/test/CodeGenObjCXX/personality.mm
Modified:
cfe/trunk/lib/CodeGen/CGException.cpp

Modified: cfe/trunk/lib/CodeGen/CGException.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=327105=327104=327105=diff
==
--- cfe/trunk/lib/CodeGen/CGException.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGException.cpp Thu Mar  8 23:06:42 2018
@@ -116,6 +116,10 @@ static const EHPersonality 
 const LangOptions ) {
   if (L.SjLjExceptions)
 return EHPersonality::GNU_C_SJLJ;
+  if (L.DWARFExceptions)
+return EHPersonality::GNU_C;
+  if (T.isWindowsMSVCEnvironment())
+return EHPersonality::MSVC_CxxFrameHandler3;
   if (L.SEHExceptions)
 return EHPersonality::GNU_C_SEH;
   return EHPersonality::GNU_C;
@@ -129,6 +133,8 @@ static const EHPersonality 
   case ObjCRuntime::MacOSX:
   case ObjCRuntime::iOS:
   case ObjCRuntime::WatchOS:
+if (T.isWindowsMSVCEnvironment())
+  return EHPersonality::MSVC_CxxFrameHandler3;
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
 if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
@@ -149,6 +155,10 @@ static const EHPersonality 
   const LangOptions ) {
   if (L.SjLjExceptions)
 return EHPersonality::GNU_CPlusPlus_SJLJ;
+  if (L.DWARFExceptions)
+return EHPersonality::GNU_CPlusPlus;
+  if (T.isWindowsMSVCEnvironment())
+return EHPersonality::MSVC_CxxFrameHandler3;
   if (L.SEHExceptions)
 return EHPersonality::GNU_CPlusPlus_SEH;
   return EHPersonality::GNU_CPlusPlus;
@@ -199,25 +209,9 @@ const EHPersonality ::get(
   if (FD && FD->usesSEHTry())
 return getSEHPersonalityMSVC(T);
 
-  // Try to pick a personality function that is compatible with MSVC if we're
-  // not compiling Obj-C. Obj-C users better have an Obj-C runtime that 
supports
-  // the GCC-style personality function.
-  if (T.isWindowsMSVCEnvironment() && !L.ObjC1) {
-if (L.SjLjExceptions)
-  return EHPersonality::GNU_CPlusPlus_SJLJ;
-if (L.DWARFExceptions)
-  return EHPersonality::GNU_CPlusPlus;
-return EHPersonality::MSVC_CxxFrameHandler3;
-  }
-
-  if (L.CPlusPlus && L.ObjC1)
-return getObjCXXPersonality(T, L);
-  else if (L.CPlusPlus)
-return getCXXPersonality(T, L);
-  else if (L.ObjC1)
-return getObjCPersonality(T, L);
-  else
-return getCPersonality(T, L);
+  if (L.ObjC1)
+return L.CPlusPlus ? getObjCXXPersonality(T, L) : getObjCPersonality(T, L);
+  return L.CPlusPlus ? getCXXPersonality(T, L) : getCPersonality(T, L);
 }
 
 const EHPersonality ::get(CodeGenFunction ) {

Added: cfe/trunk/test/CodeGen/personality.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/personality.c?rev=327105=auto
==
--- cfe/trunk/test/CodeGen/personality.c (added)
+++ cfe/trunk/test/CodeGen/personality.c Thu Mar  8 23:06:42 2018
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fblocks -S 
-emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-GNU
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions 
-fdwarf-exceptions -fblocks -S -emit-llvm %s -o - | FileCheck %s -check-prefix 
CHECK-DWARF
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions 
-fseh-exceptions -fblocks -S -emit-llvm %s -o - | FileCheck %s -check-prefix 
CHECK-SEH
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions 
-fsjlj-exceptions -fblocks -S -emit-llvm %s -o - | FileCheck %s -check-prefix 
CHECK-SJLJ
+
+// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fexceptions -fblocks -S 
-emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-WIN
+// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fexceptions 
-fdwarf-exceptions -fblocks -S -emit-llvm %s -o - | FileCheck %s -check-prefix 
CHECK-WIN-DWARF
+// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -D __SEH_EXCEPTIONS__ 
-fms-extensions -fexceptions -fblocks -fseh-exceptions -S -emit-llvm %s -o - | 
FileCheck %s -check-prefix CHECK-WIN-SEH -check-prefix CHECK-WIN-SEH-X86
+// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -D __SEH_EXCEPTIONS__ 

[PATCH] D43902: [clang-format] Don't detect C++11 attribute specifiers as ObjC

2018-03-08 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton added a comment.

Great, I refactored it to avoid parsing the matching parens, so there's no more 
danger of O(N^2) parsing behavior.

I had to add a new `InCpp11AttributeSpecifier` boolean to `Context` so when 
parsing the inner `[]` we didn't treat it as an ObjC message send or an array 
subscript.




Comment at: lib/Format/TokenAnnotator.cpp:329
+  return nullptr;
+// C++17 '[[using namespace: foo, bar(baz, blech)]]'
+bool IsUsingNamespace =

djasper wrote:
> Can you  make this:
> 
>   // C++17 '[[using : foo, bar(baz, blech)]]'
> 
> To make clear that we are not looking for kw_namespace here?
Ah, good call. Done.



Comment at: lib/Format/TokenAnnotator.cpp:332
+AttrTok->startsSequence(tok::kw_using, tok::identifier, tok::colon);
+if (IsUsingNamespace) {
+  AttrTok = AttrTok->Next->Next->Next;

djasper wrote:
> No braces.
Done.



Comment at: lib/Format/TokenAnnotator.cpp:336
+auto parseCpp11Attribute = [](const FormatToken ,
+  bool AllowNamespace) -> const FormatToken * {
+  if (!Tok.isOneOf(tok::identifier, tok::ellipsis))

djasper wrote:
> Do you actually need to put the return type here? I would have thought that 
> it can be deduced as you pass back a const FormatToken* from a codepath and 
> nullptr from all the others.
Looks like we don't. Fixed.



Comment at: lib/Format/TokenAnnotator.cpp:342
+return nullptr;
+  if (AllowNamespace &&
+  AttrTok->startsSequence(tok::coloncolon, tok::identifier)) {

djasper wrote:
> No braces.
Done.



Comment at: lib/Format/TokenAnnotator.cpp:350
+const FormatToken *ParamToken = AttrTok->Next;
+while (ParamToken && ParamToken->isNot(tok::r_paren))
+  ParamToken = ParamToken->Next;

djasper wrote:
> Sorry that I have missed this before, I thought this was in a different file. 
> Can you try to avoid iterating trying to count or match parentheses inside 
> any of parseSquare/parseParen/parseAngle. We avoided that AFAICT for 
> everything else and I don't think it's necessary here. Especially as you are 
> not actually moving the token position forward, it's too easy to create a 
> quadratic algorithm here.
> 
> Also: Do you actually have a test case for the the parentheses case? This 
> thing could use a lot more comments...
Fixed. There is a test case for the parentheses case.

I definitely see from your other reviews that it's important to structure code 
the way you describe.

In this scenario, we technically have to deal with all of these 
(http://en.cppreference.com/w/cpp/language/attributes):

```
void f() {
  int y[3];
  int i [[cats::meow([[]])]]; // OK
  int i [[cats::meow(foo:bar)]]; // OK
  int i [[cats::meow(foo::bar)]]; // OK
}
```

I was able to fudge it and assume nobody will actually use attribute parameters 
containing colons in the arguments, which allowed me to avoid looking for 
closing parens. 



Comment at: lib/Format/TokenAnnotator.cpp:366
+  return AttrTok->Next;
+} else {
+  return nullptr;

djasper wrote:
> No braces for single statement ifs. Don't use "else" after "return".
Fixed.



Comment at: lib/Format/TokenAnnotator.cpp:396
+  while (CurrentToken != Cpp11AttributeSpecifierClosingRSquare) {
+if (CurrentToken->is(tok::colon)) {
+  CurrentToken->Type = TT_AttributeColon;

djasper wrote:
> No braces for single-statement ifs.
Fixed.



Comment at: lib/Format/TokenAnnotator.cpp:397
+if (CurrentToken->is(tok::colon)) {
+  CurrentToken->Type = TT_AttributeColon;
+}

djasper wrote:
> What happens if you don't assign this type here? Which formatting decision is 
> based on it?
Added a comment to explain:

  // Remember that this is a [[using ns: foo]] C++ attribute, so we 
don't   
  
  // add a space before the colon (unlike other colons).

  

There is a formatting test for this.



Comment at: unittests/Format/FormatTest.cpp:6064
+  verifyFormat("SomeType s [[unused]] (InitValue);");
+  verifyFormat("SomeType s [[gnu::unused]] (InitValue);");
+  verifyFormat("SomeType s [[using gnu: unused]] (InitValue);");

djasper wrote:
> If this is meant to contrast a TT_AttributeColon from a different colon, that 
> doesn't work. "::" is it's own token type coloncolon.
It's not, I just wanted to make sure we had a test with a namespace.


Repository:
  rC Clang

https://reviews.llvm.org/D43902




[PATCH] D43902: [clang-format] Don't detect C++11 attribute specifiers as ObjC

2018-03-08 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton updated this revision to Diff 137696.
benhamilton marked 9 inline comments as done.
benhamilton added a comment.

Refactor to avoid matching open and close parens. Fix @djasper comments.


Repository:
  rC Clang

https://reviews.llvm.org/D43902

Files:
  lib/Format/ContinuationIndenter.cpp
  lib/Format/FormatToken.h
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -6067,6 +6067,16 @@
AfterType);
 }
 
+TEST_F(FormatTest, UnderstandsSquareAttributes) {
+  verifyFormat("SomeType s [[unused]] (InitValue);");
+  verifyFormat("SomeType s [[gnu::unused]] (InitValue);");
+  verifyFormat("SomeType s [[using gnu: unused]] (InitValue);");
+  verifyFormat("[[gsl::suppress(\"clang-tidy-check-name\")]] void f() {}");
+  verifyFormat("void f() [[deprecated(\"so sorry\")]];");
+  verifyFormat("aa\n"
+   "[[unused]] aaa(int i);");
+}
+
 TEST_F(FormatTest, UnderstandsEllipsis) {
   verifyFormat("int printf(const char *fmt, ...);");
   verifyFormat("template  void Foo(Ts... ts) { Foo(ts...); }");
@@ -12088,29 +12098,34 @@
   EXPECT_EQ(FormatStyle::LK_ObjC, guessLanguage("foo", "@interface Foo\n@end\n"));
 }
 
-TEST_F(FormatTest, GuessLanguageWithForIn) {
-  EXPECT_EQ(FormatStyle::LK_Cpp,
-guessLanguage("foo.h", "for (Foo *x = 0; x != in; x++) {}"));
+TEST_F(FormatTest, GuessLanguageWithCpp11AttributeSpecifiers) {
+  EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "[[noreturn]];"));
   EXPECT_EQ(FormatStyle::LK_ObjC,
-guessLanguage("foo.h", "for (Foo *x in bar) {}"));
-  EXPECT_EQ(FormatStyle::LK_ObjC,
-guessLanguage("foo.h", "for (Foo *x in [bar baz]) {}"));
-  EXPECT_EQ(FormatStyle::LK_ObjC,
-guessLanguage("foo.h", "for (Foo *x in [bar baz:blech]) {}"));
+guessLanguage("foo.h", "array[[calculator getIndex]];"));
+  EXPECT_EQ(FormatStyle::LK_Cpp,
+guessLanguage("foo.h", "[[noreturn, deprecated(\"so sorry\")]];"));
   EXPECT_EQ(
-  FormatStyle::LK_ObjC,
-  guessLanguage("foo.h", "for (Foo *x in [bar baz:blech, 1, 2, 3, 0]) {}"));
+  FormatStyle::LK_Cpp,
+  guessLanguage("foo.h", "[[noreturn, deprecated(\"gone, sorry\")]];"));
   EXPECT_EQ(FormatStyle::LK_ObjC,
-guessLanguage("foo.h", "for (Foo *x in [bar baz:^{[uh oh];}]) {}"));
+guessLanguage("foo.h", "[[noreturn foo] bar];"));
   EXPECT_EQ(FormatStyle::LK_Cpp,
-guessLanguage("foo.h", "Foo *x; for (x = 0; x != in; x++) {}"));
+guessLanguage("foo.h", "[[clang::fallthrough]];"));
   EXPECT_EQ(FormatStyle::LK_ObjC,
-guessLanguage("foo.h", "Foo *x; for (x in y) {}"));
+guessLanguage("foo.h", "[[clang:fallthrough] foo];"));
+  EXPECT_EQ(FormatStyle::LK_Cpp,
+guessLanguage("foo.h", "[[gsl::suppress(\"type\")]];"));
+  EXPECT_EQ(FormatStyle::LK_Cpp,
+guessLanguage("foo.h", "[[using clang: fallthrough]];"));
+  EXPECT_EQ(FormatStyle::LK_ObjC,
+guessLanguage("foo.h", "[[abusing clang:fallthrough] bar];"));
+  EXPECT_EQ(FormatStyle::LK_Cpp,
+guessLanguage("foo.h", "[[using gsl: suppress(\"type\")]];"));
   EXPECT_EQ(
   FormatStyle::LK_Cpp,
-  guessLanguage(
-  "foo.h",
-  "for (const Foo& baz = in.value(); !baz.at_end(); ++baz) {}"));
+  guessLanguage("foo.h",
+"[[clang::callable_when(\"unconsumed\", \"unknown\")]]"));
+  EXPECT_EQ(FormatStyle::LK_Cpp, guessLanguage("foo.h", "[[foo::bar, ...]]"));
 }
 
 } // end namespace
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -328,13 +328,40 @@
 return false;
   }
 
+  bool isCpp11AttributeSpecifier(const FormatToken ) {
+if (!Style.isCpp() || !Tok.startsSequence(tok::l_square, tok::l_square))
+  return false;
+const FormatToken *AttrTok = Tok.Next->Next;
+if (!AttrTok)
+  return false;
+// C++17 '[[using ns: foo, bar(baz, blech)]]'
+// We assume nobody will name an ObjC variable 'using'.
+if (AttrTok->startsSequence(tok::kw_using, tok::identifier, tok::colon))
+  return true;
+if (AttrTok->isNot(tok::identifier))
+  return false;
+while (AttrTok && !AttrTok->startsSequence(tok::r_square, tok::r_square)) {
+  // ObjC message send. We assume nobody will use : in a C++11 attribute
+  // specifier parameter, although this is technically valid:
+  // [[foo(:)]]
+  if (AttrTok->is(tok::colon) ||
+  AttrTok->startsSequence(tok::identifier, tok::identifier))
+return false;
+  if (AttrTok->is(tok::ellipsis))
+return true;
+  AttrTok = AttrTok->Next;
+}
+

[clang-tools-extra] r327103 - Revert "[clang-doc] Setup clang-doc frontend framework"

2018-03-08 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Thu Mar  8 19:47:18 2018
New Revision: 327103

URL: http://llvm.org/viewvc/llvm-project?rev=327103=rev
Log:
Revert "[clang-doc] Setup clang-doc frontend framework"

This reverts commit r327102, since it was breaking the linux-abi-test on
x86.

Removed:
clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
clang-tools-extra/trunk/clang-doc/CMakeLists.txt
clang-tools-extra/trunk/clang-doc/ClangDoc.cpp
clang-tools-extra/trunk/clang-doc/ClangDoc.h
clang-tools-extra/trunk/clang-doc/Mapper.cpp
clang-tools-extra/trunk/clang-doc/Mapper.h
clang-tools-extra/trunk/clang-doc/Representation.h
clang-tools-extra/trunk/clang-doc/Serialize.cpp
clang-tools-extra/trunk/clang-doc/Serialize.h
clang-tools-extra/trunk/clang-doc/tool/CMakeLists.txt
clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
clang-tools-extra/trunk/docs/clang-doc.rst
clang-tools-extra/trunk/test/clang-doc/mapper-class-in-class.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-class-in-function.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-class.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-comments.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-enum.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-function.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-method.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-namespace.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-struct.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-union.cpp
Modified:
clang-tools-extra/trunk/CMakeLists.txt
clang-tools-extra/trunk/test/CMakeLists.txt

Modified: clang-tools-extra/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/CMakeLists.txt?rev=327103=327102=327103=diff
==
--- clang-tools-extra/trunk/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/CMakeLists.txt Thu Mar  8 19:47:18 2018
@@ -7,7 +7,6 @@ add_subdirectory(clang-tidy-vs)
 endif()
 
 add_subdirectory(change-namespace)
-add_subdirectory(clang-doc)
 add_subdirectory(clang-query)
 add_subdirectory(clang-move)
 add_subdirectory(clangd)

Removed: clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp?rev=327102=auto
==
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp (removed)
@@ -1,517 +0,0 @@
-//===--  BitcodeWriter.cpp - ClangDoc Bitcode Writer *- C++ 
-*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-
-#include "BitcodeWriter.h"
-#include "llvm/ADT/IndexedMap.h"
-
-namespace clang {
-namespace doc {
-
-// Since id enums are not zero-indexed, we need to transform the given id into
-// its associated index.
-struct BlockIdToIndexFunctor {
-  using argument_type = unsigned;
-  unsigned operator()(unsigned ID) const { return ID - BI_FIRST; }
-};
-
-struct RecordIdToIndexFunctor {
-  using argument_type = unsigned;
-  unsigned operator()(unsigned ID) const { return ID - RI_FIRST; }
-};
-
-using AbbrevDsc = void (*)(std::shared_ptr );
-
-static void AbbrevGen(std::shared_ptr ,
-  const std::initializer_list Ops) {
-  for (const auto  : Ops)
-Abbrev->Add(Op);
-}
-
-static void BoolAbbrev(std::shared_ptr ) {
-  AbbrevGen(Abbrev,
-{// 0. Boolean
- llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
-   BitCodeConstants::BoolSize)});
-}
-
-static void IntAbbrev(std::shared_ptr ) {
-  AbbrevGen(Abbrev,
-{// 0. Fixed-size integer
- llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
-   BitCodeConstants::IntSize)});
-}
-
-static void SymbolIDAbbrev(std::shared_ptr ) {
-  AbbrevGen(Abbrev,
-{// 0. Fixed-size integer (length of the sha1'd USR)
- llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
-   BitCodeConstants::USRLengthSize),
- // 1. Fixed-size array of Char6 (USR)
- llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Array),
- llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
-   BitCodeConstants::USRBitLengthSize)});
-}
-
-static void StringAbbrev(std::shared_ptr ) {
-  AbbrevGen(Abbrev,
-{// 0. Fixed-size integer (length of the following string)
- llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
-   BitCodeConstants::StringLengthSize),

[PATCH] D41102: Setup clang-doc frontend framework

2018-03-08 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
juliehockett marked 11 inline comments as done.
Closed by commit rL327102: [clang-doc] Setup clang-doc frontend framework 
(authored by juliehockett, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D41102?vs=137457=137689#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D41102

Files:
  clang-tools-extra/trunk/CMakeLists.txt
  clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
  clang-tools-extra/trunk/clang-doc/CMakeLists.txt
  clang-tools-extra/trunk/clang-doc/ClangDoc.cpp
  clang-tools-extra/trunk/clang-doc/ClangDoc.h
  clang-tools-extra/trunk/clang-doc/Mapper.cpp
  clang-tools-extra/trunk/clang-doc/Mapper.h
  clang-tools-extra/trunk/clang-doc/Representation.h
  clang-tools-extra/trunk/clang-doc/Serialize.cpp
  clang-tools-extra/trunk/clang-doc/Serialize.h
  clang-tools-extra/trunk/clang-doc/tool/CMakeLists.txt
  clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
  clang-tools-extra/trunk/docs/clang-doc.rst
  clang-tools-extra/trunk/test/CMakeLists.txt
  clang-tools-extra/trunk/test/clang-doc/mapper-class-in-class.cpp
  clang-tools-extra/trunk/test/clang-doc/mapper-class-in-function.cpp
  clang-tools-extra/trunk/test/clang-doc/mapper-class.cpp
  clang-tools-extra/trunk/test/clang-doc/mapper-comments.cpp
  clang-tools-extra/trunk/test/clang-doc/mapper-enum.cpp
  clang-tools-extra/trunk/test/clang-doc/mapper-function.cpp
  clang-tools-extra/trunk/test/clang-doc/mapper-method.cpp
  clang-tools-extra/trunk/test/clang-doc/mapper-namespace.cpp
  clang-tools-extra/trunk/test/clang-doc/mapper-struct.cpp
  clang-tools-extra/trunk/test/clang-doc/mapper-union.cpp

Index: clang-tools-extra/trunk/test/clang-doc/mapper-namespace.cpp
===
--- clang-tools-extra/trunk/test/clang-doc/mapper-namespace.cpp
+++ clang-tools-extra/trunk/test/clang-doc/mapper-namespace.cpp
@@ -0,0 +1,17 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump-mapper -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/bc/8D042EFFC98B373450BC6B5B90A330C25A150E9C.bc --dump | FileCheck %s
+
+namespace A {}
+
+// CHECK: 
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+  // CHECK-NEXT: 
+  // CHECK-NEXT:  blob data = 'A'
+// CHECK-NEXT: 
Index: clang-tools-extra/trunk/test/clang-doc/mapper-class-in-function.cpp
===
--- clang-tools-extra/trunk/test/clang-doc/mapper-class-in-function.cpp
+++ clang-tools-extra/trunk/test/clang-doc/mapper-class-in-function.cpp
@@ -0,0 +1,38 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump-mapper -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/bc/B6AC4C5C9F2EA3F2B3ECE1A33D349F4EE502B24E.bc --dump | FileCheck %s --check-prefix CHECK-H
+// RUN: llvm-bcanalyzer %t/docs/bc/E03E804368784360D86C757B549D14BB84A94415.bc --dump | FileCheck %s --check-prefix CHECK-H-I
+
+void H() {
+  class I {};
+}
+
+// CHECK-H: 
+// CHECK-H-NEXT: 
+  // CHECK-H-NEXT: 
+// CHECK-H-NEXT: 
+// CHECK-H-NEXT: 
+  // CHECK-H-NEXT: 
+  // CHECK-H-NEXT:  blob data = 'H'
+  // CHECK-H-NEXT:  blob data = '{{.*}}'
+  // CHECK-H-NEXT: 
+// CHECK-H-NEXT:  blob data = 'void'
+  // CHECK-H-NEXT: 
+// CHECK-H-NEXT: 
+
+// CHECK-H-I: 
+// CHECK-H-I-NEXT: 
+  // CHECK-H-I-NEXT: 
+// CHECK-H-I-NEXT: 
+// CHECK-H-I-NEXT: 
+  // CHECK-H-I-NEXT: 
+  // CHECK-H-I-NEXT:  blob data = 'I'
+  // CHECK-H-I-NEXT:  blob data = 'B6AC4C5C9F2EA3F2B3ECE1A33D349F4EE502B24E'
+  // CHECK-H-I-NEXT:  blob data = '{{.*}}'
+  // CHECK-H-I-NEXT: 
+// CHECK-H-I-NEXT: 
+
+
Index: clang-tools-extra/trunk/test/clang-doc/mapper-class-in-class.cpp
===
--- clang-tools-extra/trunk/test/clang-doc/mapper-class-in-class.cpp
+++ clang-tools-extra/trunk/test/clang-doc/mapper-class-in-class.cpp
@@ -0,0 +1,35 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo "" > %t/compile_flags.txt
+// RUN: cp "%s" "%t/test.cpp"
+// RUN: clang-doc --dump-mapper -doxygen -p %t %t/test.cpp -output=%t/docs
+// RUN: llvm-bcanalyzer %t/docs/bc/641AB4A3D36399954ACDE29C7A8833032BF40472.bc --dump | FileCheck %s --check-prefix CHECK-X-Y
+// RUN: llvm-bcanalyzer %t/docs/bc/CA7C7935730B5EACD25F080E9C83FA087CCDC75E.bc --dump | FileCheck %s --check-prefix CHECK-X
+
+class X {
+  class Y {};
+};
+
+// CHECK-X: 
+// CHECK-X-NEXT: 
+  // CHECK-X-NEXT: 
+// CHECK-X-NEXT: 
+// CHECK-X-NEXT: 
+  // CHECK-X-NEXT: 
+  // CHECK-X-NEXT:  blob data = 'X'
+  // CHECK-X-NEXT:  blob data = '{{.*}}'
+  // CHECK-X-NEXT: 
+// CHECK-X-NEXT: 
+
+
+// CHECK-X-Y: 
+// CHECK-X-Y-NEXT: 
+  // CHECK-X-Y-NEXT: 
+// 

[clang-tools-extra] r327102 - [clang-doc] Setup clang-doc frontend framework

2018-03-08 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Thu Mar  8 19:16:39 2018
New Revision: 327102

URL: http://llvm.org/viewvc/llvm-project?rev=327102=rev
Log:
[clang-doc] Setup clang-doc frontend framework

Setting up the mapper part of the frontend framework for a clang-doc
tool. It creates a series of relevant matchers for declarations, and
uses the ToolExecutor to traverse the AST and extract the matching
declarations and comments. The mapper serializes the extracted
information to individual records for reducing and eventually doc
generation.

For a more detailed overview of the tool, see the design document on the
mailing list: http://lists.llvm.org/pipermail/cfe-dev/2017-December/056203.html

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

Added:
clang-tools-extra/trunk/clang-doc/
clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
clang-tools-extra/trunk/clang-doc/CMakeLists.txt
clang-tools-extra/trunk/clang-doc/ClangDoc.cpp
clang-tools-extra/trunk/clang-doc/ClangDoc.h
clang-tools-extra/trunk/clang-doc/Mapper.cpp
clang-tools-extra/trunk/clang-doc/Mapper.h
clang-tools-extra/trunk/clang-doc/Representation.h
clang-tools-extra/trunk/clang-doc/Serialize.cpp
clang-tools-extra/trunk/clang-doc/Serialize.h
clang-tools-extra/trunk/clang-doc/tool/
clang-tools-extra/trunk/clang-doc/tool/CMakeLists.txt
clang-tools-extra/trunk/clang-doc/tool/ClangDocMain.cpp
clang-tools-extra/trunk/docs/clang-doc.rst
clang-tools-extra/trunk/test/clang-doc/
clang-tools-extra/trunk/test/clang-doc/mapper-class-in-class.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-class-in-function.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-class.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-comments.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-enum.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-function.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-method.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-namespace.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-struct.cpp
clang-tools-extra/trunk/test/clang-doc/mapper-union.cpp
Modified:
clang-tools-extra/trunk/CMakeLists.txt
clang-tools-extra/trunk/test/CMakeLists.txt

Modified: clang-tools-extra/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/CMakeLists.txt?rev=327102=327101=327102=diff
==
--- clang-tools-extra/trunk/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/CMakeLists.txt Thu Mar  8 19:16:39 2018
@@ -7,6 +7,7 @@ add_subdirectory(clang-tidy-vs)
 endif()
 
 add_subdirectory(change-namespace)
+add_subdirectory(clang-doc)
 add_subdirectory(clang-query)
 add_subdirectory(clang-move)
 add_subdirectory(clangd)

Added: clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp?rev=327102=auto
==
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp (added)
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp Thu Mar  8 19:16:39 2018
@@ -0,0 +1,517 @@
+//===--  BitcodeWriter.cpp - ClangDoc Bitcode Writer *- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "BitcodeWriter.h"
+#include "llvm/ADT/IndexedMap.h"
+
+namespace clang {
+namespace doc {
+
+// Since id enums are not zero-indexed, we need to transform the given id into
+// its associated index.
+struct BlockIdToIndexFunctor {
+  using argument_type = unsigned;
+  unsigned operator()(unsigned ID) const { return ID - BI_FIRST; }
+};
+
+struct RecordIdToIndexFunctor {
+  using argument_type = unsigned;
+  unsigned operator()(unsigned ID) const { return ID - RI_FIRST; }
+};
+
+using AbbrevDsc = void (*)(std::shared_ptr );
+
+static void AbbrevGen(std::shared_ptr ,
+  const std::initializer_list Ops) {
+  for (const auto  : Ops)
+Abbrev->Add(Op);
+}
+
+static void BoolAbbrev(std::shared_ptr ) {
+  AbbrevGen(Abbrev,
+{// 0. Boolean
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
+   BitCodeConstants::BoolSize)});
+}
+
+static void IntAbbrev(std::shared_ptr ) {
+  AbbrevGen(Abbrev,
+{// 0. Fixed-size integer
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
+   BitCodeConstants::IntSize)});
+}
+
+static void SymbolIDAbbrev(std::shared_ptr ) {
+  AbbrevGen(Abbrev,
+{// 0. Fixed-size integer (length of the sha1'd USR)
+ llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
+

Re: r327099 - PR36645: Go looking for an appropriate array bound when constant-evaluating a

2018-03-08 Thread Tom Stellard via cfe-commits
On 03/08/2018 06:03 PM, Richard Smith wrote:
> Might be a good candidate for Clang 6.0.1.
> 

Merge request created: https://llvm.org/PR36655

-Tom

> On 8 March 2018 at 18:00, Richard Smith via cfe-commits 
> > wrote:
> 
> Author: rsmith
> Date: Thu Mar  8 18:00:01 2018
> New Revision: 327099
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=327099=rev 
> 
> Log:
> PR36645: Go looking for an appropriate array bound when 
> constant-evaluating a
> name of an array object.
> 
> Modified:
> cfe/trunk/lib/AST/ExprConstant.cpp
> cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
> 
> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=327099=327098=327099=diff
>  
> 
> 
> ==
> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
> +++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Mar  8 18:00:01 2018
> @@ -63,14 +63,22 @@ namespace {
> 
>static QualType getType(APValue::LValueBase B) {
>  if (!B) return QualType();
> -if (const ValueDecl *D = B.dyn_cast())
> +if (const ValueDecl *D = B.dyn_cast()) {
>// FIXME: It's unclear where we're supposed to take the type from, 
> and
> -  // this actually matters for arrays of unknown bound. Using the 
> type of
> -  // the most recent declaration isn't clearly correct in general. 
> Eg:
> +  // this actually matters for arrays of unknown bound. Eg:
>//
>// extern int arr[]; void f() { extern int arr[3]; };
>// constexpr int *p = [1]; // valid?
> -  return cast(D->getMostRecentDecl())->getType();
> +  //
> +  // For now, we take the array bound from the most recent 
> declaration.
> +  for (auto *Redecl = cast(D->getMostRecentDecl()); 
> Redecl;
> +   Redecl = cast_or_null(Redecl->getPreviousDecl())) {
> +QualType T = Redecl->getType();
> +if (!T->isIncompleteArrayType())
> +  return T;
> +  }
> +  return D->getType();
> +}
> 
>  const Expr *Base = B.get();
> 
> 
> Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=327099=327098=327099=diff
>  
> 
> 
> ==
> --- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
> +++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Thu Mar  8 
> 18:00:01 2018
> @@ -629,6 +629,10 @@ namespace ArrayOfUnknownBound {
> 
>extern const int carr[]; // expected-note {{here}}
>constexpr int n = carr[0]; // expected-error {{constant}} 
> expected-note {{non-constexpr variable}}
> +
> +  constexpr int local_extern[] = {1, 2, 3};
> +  void f() { extern const int local_extern[]; }
> +  static_assert(local_extern[1] == 2, "");
>  }
> 
>  namespace DependentValues {
> 
> 
> ___
> 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] D35103: Expand clang-interpreter with example of throwing in and from the JIT for Windows64.

2018-03-08 Thread Martell Malone via Phabricator via cfe-commits
martell added a comment.
Herald added a subscriber: mgrang.

ping @marsupial


https://reviews.llvm.org/D35103



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


[PATCH] D44189: [RISCV] Verify the input value of -march=

2018-03-08 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng updated this revision to Diff 137687.
kito-cheng added a comment.

This version only update variable name which changed in last version by 
accident.


https://reviews.llvm.org/D44189

Files:
  lib/Driver/ToolChains/Arch/RISCV.cpp
  test/Driver/riscv-arch.c

Index: test/Driver/riscv-arch.c
===
--- /dev/null
+++ test/Driver/riscv-arch.c
@@ -0,0 +1,29 @@
+// RUN: %clang -target riscv32-unknown-elf -march=rv32 -### %s -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32 %s
+// RV32: error: invalid arch name 'rv32'
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32m -### %s -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32M %s
+// RV32M: error: invalid arch name 'rv32m'
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32id -### %s -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32ID %s
+// RV32ID: error: invalid arch name 'rv32id'
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32l -### %s -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32L %s
+// RV32L: error: invalid arch name 'rv32l'
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32imadf -### %s -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32IMADF %s
+// RV32IMADF: error: invalid arch name 'rv32imadf'
+
+// RUN: %clang -target riscv64-unknown-elf -march=rv64 -### %s -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64 %s
+// RV64: error: invalid arch name 'rv64'
+
+// RUN: %clang -target riscv64-unknown-elf -march=rv64m -### %s -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64M %s
+// RV64M: error: invalid arch name 'rv64m'
+
+// RUN: %clang -target riscv64-unknown-elf -march=rv64id -### %s -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64ID %s
+// RV64ID: error: invalid arch name 'rv64id'
+
+// RUN: %clang -target riscv64-unknown-elf -march=rv64l -### %s -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64L %s
+// RV64L: error: invalid arch name 'rv64l'
+
+// RUN: %clang -target riscv64-unknown-elf -march=rv64imadf -### %s -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64IMADF %s
+// RV64IMADF: error: invalid arch name 'rv64imadf'
Index: lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- lib/Driver/ToolChains/Arch/RISCV.cpp
+++ lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -24,32 +24,81 @@
std::vector ) {
   if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
 StringRef MArch = A->getValue();
-// TODO: handle rv64
-std::pair MArchSplit = StringRef(MArch).split("rv32");
-if (!MArchSplit.second.size())
+if (!(MArch.startswith("rv32") || MArch.startswith("rv64")) ||
+(MArch.size() < 5)) {
+  // ISA string must begin with rv32 or rv64.
+  D.Diag(diag::err_drv_invalid_arch_name) << MArch;
   return;
+}
+
+// The canonical order specified in ISA manual.
+StringRef StdExts = "mafdc";
+
+bool hasF = false, hasD = false;
+char baseline = MArch[4];
+
+// TODO: Add 'e' once backend supported.
+switch (baseline) {
+default:
+  // First letter should be 'e', 'i' or 'g'.
+  D.Diag(diag::err_drv_invalid_arch_name) << MArch;
+  return;
+case 'i':
+  break;
+case 'g':
+  // g = imafd
+  StdExts = StdExts.drop_front(4);
+  Features.push_back("+m");
+  Features.push_back("+a");
+  Features.push_back("+f");
+  Features.push_back("+d");
+  hasF = true;
+  hasD = true;
+  break;
+}
 
-for (char c : MArchSplit.second) {
+auto StdExtsItr = StdExts.begin();
+// Skip rvxxx
+StringRef Exts = MArch.substr(5);
+
+for (char c : Exts) {
+  // Check march is satisfied the canonical order.
+  while (StdExtsItr != StdExts.end() && *StdExtsItr != c)
+ ++StdExtsItr;
+
+  if (StdExtsItr == StdExts.end()) {
+D.Diag(diag::err_drv_invalid_arch_name) << MArch;
+return;
+  }
+
+  // The order is OK, then push it into features.
   switch (c) {
-  case 'i':
-break;
+  default:
+D.Diag(diag::err_drv_invalid_arch_name) << MArch;
+return;
   case 'm':
 Features.push_back("+m");
 break;
   case 'a':
 Features.push_back("+a");
 break;
   case 'f':
 Features.push_back("+f");
+hasF = true;
 break;
   case 'd':
 Features.push_back("+d");
+hasD = true;
 break;
   case 'c':
 Features.push_back("+c");
 break;
   }
 }
+
+// Dependency check
+if (hasD && !hasF)
+  D.Diag(diag::err_drv_invalid_arch_name) << MArch;
   }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r327099 - PR36645: Go looking for an appropriate array bound when constant-evaluating a

2018-03-08 Thread Richard Smith via cfe-commits
Might be a good candidate for Clang 6.0.1.

On 8 March 2018 at 18:00, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rsmith
> Date: Thu Mar  8 18:00:01 2018
> New Revision: 327099
>
> URL: http://llvm.org/viewvc/llvm-project?rev=327099=rev
> Log:
> PR36645: Go looking for an appropriate array bound when
> constant-evaluating a
> name of an array object.
>
> Modified:
> cfe/trunk/lib/AST/ExprConstant.cpp
> cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
>
> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/
> ExprConstant.cpp?rev=327099=327098=327099=diff
> 
> ==
> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
> +++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Mar  8 18:00:01 2018
> @@ -63,14 +63,22 @@ namespace {
>
>static QualType getType(APValue::LValueBase B) {
>  if (!B) return QualType();
> -if (const ValueDecl *D = B.dyn_cast())
> +if (const ValueDecl *D = B.dyn_cast()) {
>// FIXME: It's unclear where we're supposed to take the type from,
> and
> -  // this actually matters for arrays of unknown bound. Using the
> type of
> -  // the most recent declaration isn't clearly correct in general. Eg:
> +  // this actually matters for arrays of unknown bound. Eg:
>//
>// extern int arr[]; void f() { extern int arr[3]; };
>// constexpr int *p = [1]; // valid?
> -  return cast(D->getMostRecentDecl())->getType();
> +  //
> +  // For now, we take the array bound from the most recent
> declaration.
> +  for (auto *Redecl = cast(D->getMostRecentDecl());
> Redecl;
> +   Redecl = cast_or_null(Redecl->getPreviousDecl())) {
> +QualType T = Redecl->getType();
> +if (!T->isIncompleteArrayType())
> +  return T;
> +  }
> +  return D->getType();
> +}
>
>  const Expr *Base = B.get();
>
>
> Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> SemaCXX/constant-expression-cxx11.cpp?rev=327099=
> 327098=327099=diff
> 
> ==
> --- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
> +++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Thu Mar  8
> 18:00:01 2018
> @@ -629,6 +629,10 @@ namespace ArrayOfUnknownBound {
>
>extern const int carr[]; // expected-note {{here}}
>constexpr int n = carr[0]; // expected-error {{constant}} expected-note
> {{non-constexpr variable}}
> +
> +  constexpr int local_extern[] = {1, 2, 3};
> +  void f() { extern const int local_extern[]; }
> +  static_assert(local_extern[1] == 2, "");
>  }
>
>  namespace DependentValues {
>
>
> ___
> 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


r327099 - PR36645: Go looking for an appropriate array bound when constant-evaluating a

2018-03-08 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Mar  8 18:00:01 2018
New Revision: 327099

URL: http://llvm.org/viewvc/llvm-project?rev=327099=rev
Log:
PR36645: Go looking for an appropriate array bound when constant-evaluating a
name of an array object.

Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=327099=327098=327099=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Mar  8 18:00:01 2018
@@ -63,14 +63,22 @@ namespace {
 
   static QualType getType(APValue::LValueBase B) {
 if (!B) return QualType();
-if (const ValueDecl *D = B.dyn_cast())
+if (const ValueDecl *D = B.dyn_cast()) {
   // FIXME: It's unclear where we're supposed to take the type from, and
-  // this actually matters for arrays of unknown bound. Using the type of
-  // the most recent declaration isn't clearly correct in general. Eg:
+  // this actually matters for arrays of unknown bound. Eg:
   //
   // extern int arr[]; void f() { extern int arr[3]; };
   // constexpr int *p = [1]; // valid?
-  return cast(D->getMostRecentDecl())->getType();
+  //
+  // For now, we take the array bound from the most recent declaration.
+  for (auto *Redecl = cast(D->getMostRecentDecl()); Redecl;
+   Redecl = cast_or_null(Redecl->getPreviousDecl())) {
+QualType T = Redecl->getType();
+if (!T->isIncompleteArrayType())
+  return T;
+  }
+  return D->getType();
+}
 
 const Expr *Base = B.get();
 

Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=327099=327098=327099=diff
==
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Thu Mar  8 18:00:01 
2018
@@ -629,6 +629,10 @@ namespace ArrayOfUnknownBound {
 
   extern const int carr[]; // expected-note {{here}}
   constexpr int n = carr[0]; // expected-error {{constant}} expected-note 
{{non-constexpr variable}}
+
+  constexpr int local_extern[] = {1, 2, 3};
+  void f() { extern const int local_extern[]; }
+  static_assert(local_extern[1] == 2, "");
 }
 
 namespace DependentValues {


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


[PATCH] D44263: Implement LWG 2221 - No formatted output operator for nullptr

2018-03-08 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith accepted this revision.
dexonsmith added a comment.
This revision is now accepted and ready to land.

LGTM.


https://reviews.llvm.org/D44263



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


[PATCH] D44250: MmapWriteExecChecker supporting mprotect call

2018-03-08 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL327098: [analyzer] MmapWriteExecChecker: Add support for 
mprotect(). (authored by dergachev, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D44250?vs=137557=137683#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44250

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
  cfe/trunk/test/Analysis/mmap-writeexec.c


Index: cfe/trunk/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
@@ -28,12 +28,13 @@
 namespace {
 class MmapWriteExecChecker : public Checker {
   CallDescription MmapFn;
+  CallDescription MprotectFn;
   static int ProtWrite;
   static int ProtExec;
   static int ProtRead;
   mutable std::unique_ptr BT;
 public:
-  MmapWriteExecChecker() : MmapFn("mmap", 6) {}
+  MmapWriteExecChecker() : MmapFn("mmap", 6), MprotectFn("mprotect", 3) {}
   void checkPreCall(const CallEvent , CheckerContext ) const;
   int ProtExecOv;
   int ProtReadOv;
@@ -46,8 +47,8 @@
 
 void MmapWriteExecChecker::checkPreCall(const CallEvent ,
  CheckerContext ) const {
-  if (Call.isCalled(MmapFn)) {
-SVal ProtVal = Call.getArgSVal(2); 
+  if (Call.isCalled(MmapFn) || Call.isCalled(MprotectFn)) {
+SVal ProtVal = Call.getArgSVal(2);
 Optional ProtLoc = 
ProtVal.getAs();
 int64_t Prot = ProtLoc->getValue().getSExtValue();
 if (ProtExecOv != ProtExec)
Index: cfe/trunk/test/Analysis/mmap-writeexec.c
===
--- cfe/trunk/test/Analysis/mmap-writeexec.c
+++ cfe/trunk/test/Analysis/mmap-writeexec.c
@@ -16,6 +16,7 @@
 
 typedef __typeof(sizeof(int)) size_t;
 void *mmap(void *, size_t, int, int, int, long);
+int mprotect(void *, size_t, int);
 
 void f1()
 {
@@ -34,3 +35,10 @@
   int prot = PROT_WRITE | PROT_EXEC;
   (void)callm(NULL, 1024, prot, MAP_PRIVATE | MAP_ANON, -1, 0); // 
expected-warning{{Both PROT_WRITE and PROT_EXEC flags are set. This can lead to 
exploitable memory regions, which could be overwritten with malicious code}}
 }
+
+void f3()
+{
+  void *p = mmap(NULL, 1024, PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); // 
no-warning
+  int m = mprotect(p, 1024, PROT_WRITE | PROT_EXEC); // expected-warning{{Both 
PROT_WRITE and PROT_EXEC flags are set. This can lead to exploitable memory 
regions, which could be overwritten with malicious code}}
+  (void)m;
+}


Index: cfe/trunk/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
@@ -28,12 +28,13 @@
 namespace {
 class MmapWriteExecChecker : public Checker {
   CallDescription MmapFn;
+  CallDescription MprotectFn;
   static int ProtWrite;
   static int ProtExec;
   static int ProtRead;
   mutable std::unique_ptr BT;
 public:
-  MmapWriteExecChecker() : MmapFn("mmap", 6) {}
+  MmapWriteExecChecker() : MmapFn("mmap", 6), MprotectFn("mprotect", 3) {}
   void checkPreCall(const CallEvent , CheckerContext ) const;
   int ProtExecOv;
   int ProtReadOv;
@@ -46,8 +47,8 @@
 
 void MmapWriteExecChecker::checkPreCall(const CallEvent ,
  CheckerContext ) const {
-  if (Call.isCalled(MmapFn)) {
-SVal ProtVal = Call.getArgSVal(2); 
+  if (Call.isCalled(MmapFn) || Call.isCalled(MprotectFn)) {
+SVal ProtVal = Call.getArgSVal(2);
 Optional ProtLoc = ProtVal.getAs();
 int64_t Prot = ProtLoc->getValue().getSExtValue();
 if (ProtExecOv != ProtExec)
Index: cfe/trunk/test/Analysis/mmap-writeexec.c
===
--- cfe/trunk/test/Analysis/mmap-writeexec.c
+++ cfe/trunk/test/Analysis/mmap-writeexec.c
@@ -16,6 +16,7 @@
 
 typedef __typeof(sizeof(int)) size_t;
 void *mmap(void *, size_t, int, int, int, long);
+int mprotect(void *, size_t, int);
 
 void f1()
 {
@@ -34,3 +35,10 @@
   int prot = PROT_WRITE | PROT_EXEC;
   (void)callm(NULL, 1024, prot, MAP_PRIVATE | MAP_ANON, -1, 0); // expected-warning{{Both PROT_WRITE and PROT_EXEC flags are set. This can lead to exploitable memory regions, which could be overwritten with malicious code}}
 }
+
+void f3()
+{
+  void *p = mmap(NULL, 1024, PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); // no-warning
+  int m = mprotect(p, 1024, PROT_WRITE | PROT_EXEC); // expected-warning{{Both PROT_WRITE and PROT_EXEC flags are set. This can lead to exploitable memory regions, which could be overwritten with malicious code}}
+  (void)m;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

r327098 - [analyzer] MmapWriteExecChecker: Add support for mprotect().

2018-03-08 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Thu Mar  8 17:47:24 2018
New Revision: 327098

URL: http://llvm.org/viewvc/llvm-project?rev=327098=rev
Log:
[analyzer] MmapWriteExecChecker: Add support for mprotect().

mprotect() allows setting memory access flags similarly to mmap(),
causing similar security issues if these flags are needlessly broad.

Patch by David Carlier!

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
cfe/trunk/test/Analysis/mmap-writeexec.c

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp?rev=327098=327097=327098=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp Thu Mar  8 
17:47:24 2018
@@ -28,12 +28,13 @@ using llvm::APSInt;
 namespace {
 class MmapWriteExecChecker : public Checker {
   CallDescription MmapFn;
+  CallDescription MprotectFn;
   static int ProtWrite;
   static int ProtExec;
   static int ProtRead;
   mutable std::unique_ptr BT;
 public:
-  MmapWriteExecChecker() : MmapFn("mmap", 6) {}
+  MmapWriteExecChecker() : MmapFn("mmap", 6), MprotectFn("mprotect", 3) {}
   void checkPreCall(const CallEvent , CheckerContext ) const;
   int ProtExecOv;
   int ProtReadOv;
@@ -46,8 +47,8 @@ int MmapWriteExecChecker::ProtRead  = 0x
 
 void MmapWriteExecChecker::checkPreCall(const CallEvent ,
  CheckerContext ) const {
-  if (Call.isCalled(MmapFn)) {
-SVal ProtVal = Call.getArgSVal(2); 
+  if (Call.isCalled(MmapFn) || Call.isCalled(MprotectFn)) {
+SVal ProtVal = Call.getArgSVal(2);
 Optional ProtLoc = 
ProtVal.getAs();
 int64_t Prot = ProtLoc->getValue().getSExtValue();
 if (ProtExecOv != ProtExec)

Modified: cfe/trunk/test/Analysis/mmap-writeexec.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/mmap-writeexec.c?rev=327098=327097=327098=diff
==
--- cfe/trunk/test/Analysis/mmap-writeexec.c (original)
+++ cfe/trunk/test/Analysis/mmap-writeexec.c Thu Mar  8 17:47:24 2018
@@ -16,6 +16,7 @@
 
 typedef __typeof(sizeof(int)) size_t;
 void *mmap(void *, size_t, int, int, int, long);
+int mprotect(void *, size_t, int);
 
 void f1()
 {
@@ -34,3 +35,10 @@ void f2()
   int prot = PROT_WRITE | PROT_EXEC;
   (void)callm(NULL, 1024, prot, MAP_PRIVATE | MAP_ANON, -1, 0); // 
expected-warning{{Both PROT_WRITE and PROT_EXEC flags are set. This can lead to 
exploitable memory regions, which could be overwritten with malicious code}}
 }
+
+void f3()
+{
+  void *p = mmap(NULL, 1024, PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); // 
no-warning
+  int m = mprotect(p, 1024, PROT_WRITE | PROT_EXEC); // expected-warning{{Both 
PROT_WRITE and PROT_EXEC flags are set. This can lead to exploitable memory 
regions, which could be overwritten with malicious code}}
+  (void)m;
+}


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


[PATCH] D44051: [CFG] [analyzer] Add construction context for implicit constructor conversions.

2018-03-08 Thread Phabricator via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL327096: [CFG] [analyzer] Add construction context for 
implicit constructor conversions. (authored by dergachev, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D44051?vs=136875=137682#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44051

Files:
  cfe/trunk/lib/Analysis/CFG.cpp
  cfe/trunk/lib/Analysis/ConstructionContext.cpp
  cfe/trunk/test/Analysis/cfg-rich-constructors.cpp
  cfe/trunk/test/Analysis/temporaries.cpp

Index: cfe/trunk/test/Analysis/temporaries.cpp
===
--- cfe/trunk/test/Analysis/temporaries.cpp
+++ cfe/trunk/test/Analysis/temporaries.cpp
@@ -940,3 +940,48 @@
 }
 } // namespace temporary_list_crash
 #endif // C++11
+
+namespace implicit_constructor_conversion {
+struct S {
+  int x;
+  S(int x) : x(x) {}
+  ~S() {}
+};
+
+class C {
+  int x;
+
+public:
+  C(const S ) : x(s.x) {}
+  ~C() {}
+  int getX() const { return x; }
+};
+
+void test() {
+  const C  = S(10);
+  clang_analyzer_eval(c1.getX() == 10);
+#ifdef TEMPORARY_DTORS
+  // expected-warning@-2{{TRUE}}
+#else
+  // expected-warning@-4{{UNKNOWN}}
+#endif
+
+  S s = 20;
+  clang_analyzer_eval(s.x == 20);
+#ifdef TEMPORARY_DTORS
+  // expected-warning@-2{{TRUE}}
+#else
+  // expected-warning@-4{{UNKNOWN}}
+#endif
+
+  C c2 = s;
+  clang_analyzer_eval(c2.getX() == 20);
+#ifdef TEMPORARY_DTORS
+  // expected-warning@-2{{TRUE}}
+#else
+  // expected-warning@-4{{UNKNOWN}}
+#endif
+}
+} // end namespace implicit_constructor_conversion
+
+
Index: cfe/trunk/test/Analysis/cfg-rich-constructors.cpp
===
--- cfe/trunk/test/Analysis/cfg-rich-constructors.cpp
+++ cfe/trunk/test/Analysis/cfg-rich-constructors.cpp
@@ -498,20 +498,70 @@
   ~B() {}
 };
 
-// FIXME: Find construction context for the implicit constructor conversion.
+// CHECK: void implicitConstructionConversionFromTemporary()
+// CHECK:  1: implicit_constructor_conversion::A() (CXXConstructExpr, [B1.3], class implicit_constructor_conversion::A)
+// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, NoOp, const class implicit_constructor_conversion::A)
+// CHECK-NEXT: 3: [B1.2]
+// CHECK-NEXT: 4: [B1.3] (CXXConstructExpr, [B1.6], [B1.8], class implicit_constructor_conversion::B)
+// CHECK-NEXT: 5: [B1.4] (ImplicitCastExpr, ConstructorConversion, class implicit_constructor_conversion::B)
+// CHECK-NEXT: 6: [B1.5] (BindTemporary)
+// CHECK-NEXT: 7: [B1.6] (ImplicitCastExpr, NoOp, const class implicit_constructor_conversion::B)
+// CHECK-NEXT: 8: [B1.7]
+// CHECK-NEXT: 9: [B1.8] (CXXConstructExpr, [B1.10], class implicit_constructor_conversion::B)
+// CHECK-NEXT:10: implicit_constructor_conversion::B b = implicit_constructor_conversion::A();
+// CHECK-NEXT:11: ~implicit_constructor_conversion::B() (Temporary object destructor)
+// CHECK-NEXT:12: [B1.10].~B() (Implicit destructor)
+void implicitConstructionConversionFromTemporary() {
+  B b = A();
+}
+
 // CHECK: void implicitConstructionConversionFromFunctionValue()
 // CHECK:  1: get
+// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, class implicit_constructor_conversion::A (*)(void))
+// CHECK-NEXT: 3: [B1.2]()
+// CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, NoOp, const class implicit_constructor_conversion::A)
+// CHECK-NEXT: 5: [B1.4]
+// CHECK-NEXT: 6: [B1.5] (CXXConstructExpr, [B1.8], [B1.10], class implicit_constructor_conversion::B)
+// CHECK-NEXT: 7: [B1.6] (ImplicitCastExpr, ConstructorConversion, class implicit_constructor_conversion::B)
+// CHECK-NEXT: 8: [B1.7] (BindTemporary)
+// CHECK-NEXT: 9: [B1.8] (ImplicitCastExpr, NoOp, const class implicit_constructor_conversion::B)
+// CHECK-NEXT:10: [B1.9]
+// CHECK-NEXT:11: [B1.10] (CXXConstructExpr, [B1.12], class implicit_constructor_conversion::B)
+// CHECK-NEXT:12: implicit_constructor_conversion::B b = get();
+// CHECK-NEXT:13: ~implicit_constructor_conversion::B() (Temporary object destructor)
+// CHECK-NEXT:14: [B1.12].~B() (Implicit destructor)
+void implicitConstructionConversionFromFunctionValue() {
+  B b = get();
+}
+
+// CHECK: void implicitConstructionConversionFromTemporaryWithLifetimeExtension()
+// CHECK:  1: implicit_constructor_conversion::A() (CXXConstructExpr, [B1.3], class implicit_constructor_conversion::A)
+// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, NoOp, const class implicit_constructor_conversion::A)
+// CHECK-NEXT: 3: [B1.2]
+// CHECK-NEXT: 4: [B1.3] (CXXConstructExpr, [B1.7], class implicit_constructor_conversion::B)
+// CHECK-NEXT: 5: [B1.4] (ImplicitCastExpr, ConstructorConversion, class implicit_constructor_conversion::B)
+// CHECK-NEXT: 6: 

r327096 - [CFG] [analyzer] Add construction context for implicit constructor conversions.

2018-03-08 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Thu Mar  8 17:39:59 2018
New Revision: 327096

URL: http://llvm.org/viewvc/llvm-project?rev=327096=rev
Log:
[CFG] [analyzer] Add construction context for implicit constructor conversions.

Implicit constructor conversions such as A a = B() are represented by
surrounding the constructor for B() with an ImplicitCastExpr of
CK_ConstructorConversion kind, similarly to how explicit constructor conversions
are surrounded by a CXXFunctionalCastExpr. Support this syntax pattern when
extracting the construction context for the implicit constructor that
performs the conversion.

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

Modified:
cfe/trunk/lib/Analysis/CFG.cpp
cfe/trunk/lib/Analysis/ConstructionContext.cpp
cfe/trunk/test/Analysis/cfg-rich-constructors.cpp
cfe/trunk/test/Analysis/temporaries.cpp

Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=327096=327095=327096=diff
==
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Thu Mar  8 17:39:59 2018
@@ -1202,8 +1202,13 @@ void CFGBuilder::findConstructionContext
   case Stmt::ImplicitCastExprClass: {
 auto *Cast = cast(Child);
 // TODO: We need to support CK_ConstructorConversion, maybe other kinds?
-if (Cast->getCastKind() == CK_NoOp)
+switch (Cast->getCastKind()) {
+case CK_NoOp:
+case CK_ConstructorConversion:
   findConstructionContexts(Layer, Cast->getSubExpr());
+default:
+  break;
+}
 break;
   }
   case Stmt::CXXBindTemporaryExprClass: {

Modified: cfe/trunk/lib/Analysis/ConstructionContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ConstructionContext.cpp?rev=327096=327095=327096=diff
==
--- cfe/trunk/lib/Analysis/ConstructionContext.cpp (original)
+++ cfe/trunk/lib/Analysis/ConstructionContext.cpp Thu Mar  8 17:39:59 2018
@@ -70,8 +70,11 @@ const ConstructionContext *ConstructionC
   C.getAllocator().Allocate();
   return new (CC) TemporaryObjectConstructionContext(BTE, MTE);
 } else if (const auto *MTE = dyn_cast(S)) {
+  // If the object requires destruction and is not lifetime-extended,
+  // then it must have a BTE within its MTE.
   assert(MTE->getType().getCanonicalType()
-->getAsCXXRecordDecl()->hasTrivialDestructor());
+->getAsCXXRecordDecl()->hasTrivialDestructor() ||
+ MTE->getStorageDuration() != SD_FullExpression);
   assert(TopLayer->isLast());
   auto *CC =
   C.getAllocator().Allocate();

Modified: cfe/trunk/test/Analysis/cfg-rich-constructors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cfg-rich-constructors.cpp?rev=327096=327095=327096=diff
==
--- cfe/trunk/test/Analysis/cfg-rich-constructors.cpp (original)
+++ cfe/trunk/test/Analysis/cfg-rich-constructors.cpp Thu Mar  8 17:39:59 2018
@@ -498,20 +498,70 @@ public:
   ~B() {}
 };
 
-// FIXME: Find construction context for the implicit constructor conversion.
+// CHECK: void implicitConstructionConversionFromTemporary()
+// CHECK:  1: implicit_constructor_conversion::A() (CXXConstructExpr, 
[B1.3], class implicit_constructor_conversion::A)
+// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, NoOp, const class 
implicit_constructor_conversion::A)
+// CHECK-NEXT: 3: [B1.2]
+// CHECK-NEXT: 4: [B1.3] (CXXConstructExpr, [B1.6], [B1.8], class 
implicit_constructor_conversion::B)
+// CHECK-NEXT: 5: [B1.4] (ImplicitCastExpr, ConstructorConversion, class 
implicit_constructor_conversion::B)
+// CHECK-NEXT: 6: [B1.5] (BindTemporary)
+// CHECK-NEXT: 7: [B1.6] (ImplicitCastExpr, NoOp, const class 
implicit_constructor_conversion::B)
+// CHECK-NEXT: 8: [B1.7]
+// CHECK-NEXT: 9: [B1.8] (CXXConstructExpr, [B1.10], class 
implicit_constructor_conversion::B)
+// CHECK-NEXT:10: implicit_constructor_conversion::B b = 
implicit_constructor_conversion::A();
+// CHECK-NEXT:11: ~implicit_constructor_conversion::B() (Temporary object 
destructor)
+// CHECK-NEXT:12: [B1.10].~B() (Implicit destructor)
+void implicitConstructionConversionFromTemporary() {
+  B b = A();
+}
+
 // CHECK: void implicitConstructionConversionFromFunctionValue()
 // CHECK:  1: get
+// CHECK-NEXT: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, class 
implicit_constructor_conversion::A (*)(void))
+// CHECK-NEXT: 3: [B1.2]()
+// CHECK-NEXT: 4: [B1.3] (ImplicitCastExpr, NoOp, const class 
implicit_constructor_conversion::A)
+// CHECK-NEXT: 5: [B1.4]
+// CHECK-NEXT: 6: [B1.5] (CXXConstructExpr, [B1.8], [B1.10], class 
implicit_constructor_conversion::B)
+// CHECK-NEXT: 7: [B1.6] (ImplicitCastExpr, 

[PATCH] D44278: CodeGen: simplify and validate exception personalities

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

lgtm, thanks! This is nicer.


Repository:
  rC Clang

https://reviews.llvm.org/D44278



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


[PATCH] D44222: [AArch64] Add vmulxh_lane FP16 intrinsics

2018-03-08 Thread Abderrazek Zaafrani via Phabricator via cfe-commits
az added inline comments.



Comment at: include/clang/Basic/arm_neon.td:1504
+  // Scalar floating point multiply extended (scalar, by element)
+  def SCALAR_FMULX_LANEH : IOpInst<"vmulx_lane", "ssdi", "Sh", 
OP_SCALAR_MUL_LN>;
+  def SCALAR_FMULX_LANEQH : IOpInst<"vmulx_laneq", "ssji", "Sh", 
OP_SCALAR_MUL_LN>;

SjoerdMeijer wrote:
> I found that unfortunately it's not that straightforward. This leads to wrong 
> code generation as it is generating a fmul instead of fmulx. I am suspecting 
> this instruction description should be using OP_SCALAR_MULX_LN, but also the 
> type decls are wrong. Need to dig a bit further here.
Sorry for confusion as the commented code was never intended to be used and it 
is a copy of the code for the intrinsic vmulh_lane(). It was done that way in 
order to point out that vmulh_lane() and vmulxh_lane() intrinsics should be 
implemented in a similar way. The only useful thing in the commented code is 
the explanation that we need the scalar intrinsic vmulxh_f16() which was 
implemented in the scalar intrinsic patch later on.
 
If we look at how vmulh_lane (a, b, lane) is implemented:
x = extract (b, lane);
res = a * x;
return res; 

Similarly, I thought at the time that vmulxh_lane (a, b, lane) can be 
implemented: 
x = extract (b, lane);
res = vmulxh_f16 (a, x);  // no llvm native mulx instruction, so we use the 
fp16 scalar intrinsic.
return res; 

I am not sure now that we can easily use scalar intrinsic while generating the 
arm_neon.h file. In case we can not do that, I am thinking that the frontend 
should generate a new builtin for intrinsic vmulxh_lane() that the backend 
recognizes and generate the right code for it which is fmulx  h0, h0, 
v1.h[lane]. If you made or will be making progress on this, then that is great. 
Otherwise, I can look at a frontend solution for it.  


https://reviews.llvm.org/D44222



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


[PATCH] D44250: MmapWriteExecChecker supporting mprotect call

2018-03-08 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ edited reviewers, added: NoQ; removed: dergachev.a.
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Looks good, thank you!


Repository:
  rC Clang

https://reviews.llvm.org/D44250



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


[PATCH] D44281: [analyzer] Suppress more MallocChecker positives in reference counting pointer destructors.

2018-03-08 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet.
Herald added subscribers: cfe-commits, rnkovacs.

https://reviews.llvm.org/D43791 wasn't quite enough because we often run out of 
inlining stack depth limit and for that reason fail to see the atomics we're 
looking for.

Add a more straightforward false positive suppression that is based on the name 
of the class. I.e. if we're releasing a pointer in a destructor of a "something 
shared/intrusive/reference/counting something ptr/pointer something", then any 
use-after-free or double-free that occurs later would likely be a false 
positive.


Repository:
  rC Clang

https://reviews.llvm.org/D44281

Files:
  lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  test/Analysis/NewDelete-atomics.cpp
  test/Analysis/NewDelete-refptr.cpp

Index: test/Analysis/NewDelete-refptr.cpp
===
--- /dev/null
+++ test/Analysis/NewDelete-refptr.cpp
@@ -0,0 +1,60 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks -DLEAKS -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete -std=c++11 -DTEST_INLINABLE_ALLOCATORS -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks -DLEAKS -std=c++11 -DTEST_INLINABLE_ALLOCATORS -verify %s
+
+// expected-no-diagnostics
+
+#include "Inputs/system-header-simulator-cxx.h"
+
+class Obj {
+  int RefCnt;
+
+public:
+  // Implementation is intentionally missing to emulate the situation in which
+  // we are unable to inline these methods for any irrelevant reason.
+  int incRef();
+  int decRef();
+
+  void foo();
+};
+
+class IntrusivePtr {
+  Obj *Ptr;
+
+public:
+  IntrusivePtr(Obj *Ptr) : Ptr(Ptr) {
+Ptr->incRef();
+  }
+
+  IntrusivePtr(const IntrusivePtr ) : Ptr(Other.Ptr) {
+Ptr->incRef();
+  }
+
+  ~IntrusivePtr() {
+  // We should not take the path on which the object is deleted.
+if (Ptr->decRef() == 1)
+  delete Ptr;
+  }
+
+  Obj *getPtr() const { return Ptr; } // no-warning
+};
+
+void testDestroyLocalRefPtr() {
+  IntrusivePtr p1(new Obj());
+  {
+IntrusivePtr p2(p1);
+  }
+
+  // p1 still maintains ownership. The object is not deleted.
+  p1.getPtr()->foo(); // no-warning
+}
+
+void testDestroySymbolicRefPtr(const IntrusivePtr ) {
+  {
+IntrusivePtr p2(p1);
+  }
+
+  // p1 still maintains ownership. The object is not deleted.
+  p1.getPtr()->foo(); // no-warning
+}
Index: test/Analysis/NewDelete-atomics.cpp
===
--- test/Analysis/NewDelete-atomics.cpp
+++ test/Analysis/NewDelete-atomics.cpp
@@ -2,6 +2,10 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks -DLEAKS -std=c++11 -verify %s
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete -std=c++11 -DTEST_INLINABLE_ALLOCATORS -verify %s
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks -DLEAKS -std=c++11 -DTEST_INLINABLE_ALLOCATORS -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-inline-max-stack-depth 2 -analyzer-config ipa-always-inline-size=2 -analyzer-checker=core,cplusplus.NewDelete -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-inline-max-stack-depth 2 -analyzer-config ipa-always-inline-size=2 -analyzer-checker=core,cplusplus.NewDeleteLeaks -DLEAKS -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-inline-max-stack-depth 2 -analyzer-config ipa-always-inline-size=2 -analyzer-checker=core,cplusplus.NewDelete -std=c++11 -DTEST_INLINABLE_ALLOCATORS -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-inline-max-stack-depth 2 -analyzer-config ipa-always-inline-size=2 -analyzer-checker=core,cplusplus.NewDeleteLeaks -DLEAKS -std=c++11 -DTEST_INLINABLE_ALLOCATORS -verify %s
 
 // expected-no-diagnostics
 
@@ -51,7 +55,7 @@
   delete Ptr;
   }
 
-  Obj *getPtr() const { return Ptr; }
+  Obj *getPtr() const { return Ptr; } // no-warning
 };
 
 void testDestroyLocalRefPtr() {
Index: lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -2828,6 +2828,21 @@
   return nullptr;
 }
 
+static bool isReferenceCountingPointerDestructor(const CXXDestructorDecl *DD) {
+  if (const IdentifierInfo *II = DD->getParent()->getIdentifier()) {
+StringRef N = II->getName();
+// FIXME: Use regular expressions when they get marked as acceptable
+// in the LLVM coding standard?
+if (N.contains_lower("ptr") || N.contains_lower("pointer")) {
+  if (N.contains_lower("ref") || N.contains_lower("cnt") ||
+  N.contains_lower("intrusive") || N.contains_lower("shared")) {
+return true;
+  }
+}
+  }
+  return false;
+}
+
 std::shared_ptr 

[PATCH] D44273: [CFG] [analyzer] Fix a crash on finding construction context for an lvalue/xvalue call expression.

2018-03-08 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 137675.
NoQ added a comment.

Add the tests to a CFG-oriented test file as well, because it doesn't have much 
to do with the analyzer.

FIXME: `temp-obj-dtors-cfg-output.cpp` is a mess. It'd be great to interleave 
code and expected output, like other CFG tests do, to make it readable.


https://reviews.llvm.org/D44273

Files:
  include/clang/Analysis/CFG.h
  lib/Analysis/CFG.cpp
  test/Analysis/temp-obj-dtors-cfg-output.cpp
  test/Analysis/temporaries.cpp

Index: test/Analysis/temporaries.cpp
===
--- test/Analysis/temporaries.cpp
+++ test/Analysis/temporaries.cpp
@@ -1032,4 +1032,17 @@
 }
 } // end namespace implicit_constructor_conversion
 
+namespace pass_references_through {
+class C {
+public:
+  ~C() {}
+};
+
+const C ();
+C &();
 
+// In these examples the foo() expression has record type, not reference type.
+// Don't try to figure out how to perform construction of the record here.
+const C () { return foo1(); } // no-crash
+C &() { return foo2(); } // no-crash
+} // end namespace pass_references_through
Index: test/Analysis/temp-obj-dtors-cfg-output.cpp
===
--- test/Analysis/temp-obj-dtors-cfg-output.cpp
+++ test/Analysis/temp-obj-dtors-cfg-output.cpp
@@ -205,6 +205,21 @@
   return 0;
 }
 
+namespace pass_references_through {
+class C {
+public:
+  ~C() {}
+};
+
+const C ();
+C &();
+
+// In these examples the foo() expression has record type, not reference type.
+// Don't try to figure out how to perform construction of the record here.
+const C () { return foo1(); } // no-crash
+C &() { return foo2(); } // no-crash
+} // end namespace pass_references_through
+
 // CHECK:   [B1 (ENTRY)]
 // CHECK: Succs (1): B0
 // CHECK:   [B0 (EXIT)]
@@ -1402,3 +1417,29 @@
 // CHECK: Succs (2): B8 B1
 // CHECK:   [B0 (EXIT)]
 // CHECK: Preds (3): B1 B2 B4
+// CHECK:   [B1 (ENTRY)]
+// CHECK: Succs (1): B0
+// CHECK:   [B0 (EXIT)]
+// CHECK: Preds (1): B1
+// CHECK:   [B2 (ENTRY)]
+// CHECK: Succs (1): B1
+// CHECK:   [B1]
+// CHECK: 1: foo1
+// CHECK: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, const class pass_references_through::C &(*)(void))
+// CHECK: 3: [B1.2]()
+// CHECK: 4: return [B1.3];
+// CHECK: Preds (1): B2
+// CHECK: Succs (1): B0
+// CHECK:   [B0 (EXIT)]
+// CHECK: Preds (1): B1
+// CHECK:   [B2 (ENTRY)]
+// CHECK: Succs (1): B1
+// CHECK:   [B1]
+// CHECK: 1: foo2
+// CHECK: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, class pass_references_through::C &&(*)(void))
+// CHECK: 3: [B1.2]()
+// CHECK: 4: return [B1.3];
+// CHECK: Preds (1): B2
+// CHECK: Succs (1): B0
+// CHECK:   [B0 (EXIT)]
+// CHECK: Preds (1): B1
Index: lib/Analysis/CFG.cpp
===
--- lib/Analysis/CFG.cpp
+++ lib/Analysis/CFG.cpp
@@ -729,7 +729,7 @@
 
   void appendCall(CFGBlock *B, CallExpr *CE) {
 if (BuildOpts.AddRichCXXConstructors) {
-  if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE)) {
+  if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE, *Context)) {
 if (const ConstructionContextLayer *Layer =
 ConstructionContextMap.lookup(CE)) {
   const ConstructionContext *CC =
@@ -1217,7 +1217,7 @@
   case Stmt::CXXOperatorCallExprClass:
   case Stmt::UserDefinedLiteralClass: {
 auto *CE = cast(Child);
-if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE))
+if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE, *Context))
   consumeConstructionContext(Layer, CE);
 break;
   }
Index: include/clang/Analysis/CFG.h
===
--- include/clang/Analysis/CFG.h
+++ include/clang/Analysis/CFG.h
@@ -181,14 +181,16 @@
 public:
   /// Returns true when call expression \p CE needs to be represented
   /// by CFGCXXRecordTypedCall, as opposed to a regular CFGStmt.
-  static bool isCXXRecordTypedCall(CallExpr *CE) {
-return CE->getType().getCanonicalType()->getAsCXXRecordDecl();
+  static bool isCXXRecordTypedCall(CallExpr *CE, const ASTContext ) {
+return CE->getCallReturnType(ACtx).getCanonicalType()->getAsCXXRecordDecl();
   }
 
   explicit CFGCXXRecordTypedCall(CallExpr *CE,
- const TemporaryObjectConstructionContext *C)
+ const TemporaryObjectConstructionContext *C)
   : CFGStmt(CE, CXXRecordTypedCall) {
-assert(isCXXRecordTypedCall(CE));
+// FIXME: This is not protected against squeezing a non-record-typed-call
+// into the constructor. An assertion would require passing an ASTContext
+// which would mean paying for something we don't use.
 assert(C);
 Data2.setPointer(const_cast(C));
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D41102: Setup clang-doc frontend framework

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

There's a few places where we can trim some of the boilerplate, which I think 
is important - it's hard to find the "real code" among all the plumbing in 
places.
Other than that, this seems OK to me.




Comment at: clang-doc/BitcodeWriter.h:116
+template  struct MapFromInfoToBlockId {
+  static const BlockId ID;
+};

I think you don't want to declare ID in the unspecialized template, so you get 
a compile error if you try to use it.

(Using traits for this sort of thing seems a bit overboard to me, but YMMV)



Comment at: clang-doc/BitcodeWriter.h:154
+  ClangDocBitcodeWriter(llvm::BitstreamWriter ,
+bool OmitFilenames = false)
+  : Stream(Stream), OmitFilenames(OmitFilenames) {

Hmm, you spend a lot of effort plumbing this variable around! Why is it so 
important?
Filesize? (I'm not that familiar with LLVM bitcode, but surely we'll end up 
with a string table anyway?)

If it really is an important option people will want, the command-line arg 
should probably say why.



Comment at: clang-doc/BitcodeWriter.h:241
+/// \param I The info to emit to bitcode.
+template  void ClangDocBitcodeWriter::emitBlock(const T ) {
+  StreamSubBlockGuard Block(Stream, MapFromInfoToBlockId::ID);

OK, I don't get this at all.

We have to declare emitBlockContent(NamespaceInfo) *and* the specialization of 
MapFromInfoToBlockId, and deal with the public interface 
emitBlock being a template function where you can't tell what's legal to pass, 
instead of writing:

```void emitBlock(const NamespaceInfo ) {
  SubStreamBlockGuard Block(Stream, BI_NAMESPACE_BLOCK_ID); // <-- this one line
  ...
}```

This really seems like templates for the sake of templates :(



Comment at: clang-doc/ClangDoc.h:10
+//
+// This file implements the main entry point for the clang-doc tool. It runs
+// the clang-doc mapper on a given set of source code files using a

This comment doesn't seem accurate - there's no main() in this file.
There's a FrontendActionFactory, but nothing in this file uses it.



Comment at: clang-doc/ClangDoc.h:37
+
+  clang::FrontendAction *create() override {
+class ClangDocConsumer : public clang::ASTConsumer {

nit: seems odd to put all this implementation in the header.
(personally I'd just expose a function returning 
unique_ptr from the header, but up to you...)



Comment at: clang-doc/ClangDoc.h:38
+  clang::FrontendAction *create() override {
+class ClangDocConsumer : public clang::ASTConsumer {
+public:

for ASTConsumers implemented by ASTVisitors, there seems a fairly strong 
convention to just make the same class extend both (MapASTVisitor, here).
That would eliminate one plumbing class...



Comment at: clang-doc/Mapper.cpp:33
+  ECtx->reportResult(llvm::toHex(llvm::toStringRef(serialize::hashUSR(USR))),
+ serialize::emitInfo(D, getComment(D, D->getASTContext()),
+ getLine(D, D->getASTContext()),

It seems a bit of a poor fit to use a complete bitcode file (header, version, 
block info) as your value format when you know the format, and know there'll be 
no version skew.
Is it easy just to emit the block we care about?



Comment at: clang-doc/Representation.h:29
+
+using USRString = std::array;
+

lebedev.ri wrote:
> Right, of course, internally this is kept in the binary format, which is just 
> 20 chars.
> This is not the string (the hex-ified version of sha1), but the raw sha1, the 
> binary.
> This should somehow convey that. This should be something closer to `USRSha1`.
I'm not sure that any of the implementation (either USR or SHA) belongs in the 
type name.
In clangd we called this type SymbolID, which seems like a reasonable name here 
too.



Comment at: clang-doc/Representation.h:44
+  CommentInfo(CommentInfo &) : Children(std::move(Other.Children)) {}
+  SmallString<16> Kind;
+  SmallString<64> Text;

this is probably the right place to document these fields - what are the legal 
kinds? what's the name of a comment, direction, etc?


https://reviews.llvm.org/D41102



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


[PATCH] D41517: mmintrin.h documentation fixes and updates

2018-03-08 Thread Douglas Yung via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL327090: [DOXYGEN] Fix doxygen and content issues in 
mmintrin.h (authored by dyung, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D41517?vs=137333=137674#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D41517

Files:
  cfe/trunk/lib/Headers/mmintrin.h


Index: cfe/trunk/lib/Headers/mmintrin.h
===
--- cfe/trunk/lib/Headers/mmintrin.h
+++ cfe/trunk/lib/Headers/mmintrin.h
@@ -52,7 +52,7 @@
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VMOVD / MOVD  instruction.
+/// This intrinsic corresponds to the  MOVD  instruction.
 ///
 /// \param __i
 ///A 32-bit integer value.
@@ -69,7 +69,7 @@
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VMOVD / MOVD  instruction.
+/// This intrinsic corresponds to the  MOVD  instruction.
 ///
 /// \param __m
 ///A 64-bit integer vector.
@@ -85,7 +85,7 @@
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VMOVQ / MOVD  instruction.
+/// This intrinsic corresponds to the  MOVQ  instruction.
 ///
 /// \param __i
 ///A 64-bit signed integer.
@@ -101,7 +101,7 @@
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VMOVQ / MOVD  instruction.
+/// This intrinsic corresponds to the  MOVQ  instruction.
 ///
 /// \param __m
 ///A 64-bit integer vector.
@@ -1289,7 +1289,7 @@
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VXORPS / XORPS  instruction.
+/// This intrinsic corresponds to the  PXOR  instruction.
 ///
 /// \returns An initialized 64-bit integer vector with all elements set to 
zero.
 static __inline__ __m64 __DEFAULT_FN_ATTRS
@@ -1381,7 +1381,8 @@
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VPSHUFD / PSHUFD  instruction.
+/// This intrinsic is a utility function and does not correspond to a specific
+///instruction.
 ///
 /// \param __i
 ///A 32-bit integer value used to initialize each vector element of the
@@ -1399,7 +1400,8 @@
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VPSHUFLW / PSHUFLW  instruction.
+/// This intrinsic is a utility function and does not correspond to a specific
+///instruction.
 ///
 /// \param __w
 ///A 16-bit integer value used to initialize each vector element of the
@@ -1416,8 +1418,8 @@
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VPUNPCKLBW + VPSHUFLW / PUNPCKLBW +
-///PSHUFLW  instruction.
+/// This intrinsic is a utility function and does not correspond to a specific
+///instruction.
 ///
 /// \param __b
 ///An 8-bit integer value used to initialize each vector element of the


Index: cfe/trunk/lib/Headers/mmintrin.h
===
--- cfe/trunk/lib/Headers/mmintrin.h
+++ cfe/trunk/lib/Headers/mmintrin.h
@@ -52,7 +52,7 @@
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VMOVD / MOVD  instruction.
+/// This intrinsic corresponds to the  MOVD  instruction.
 ///
 /// \param __i
 ///A 32-bit integer value.
@@ -69,7 +69,7 @@
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VMOVD / MOVD  instruction.
+/// This intrinsic corresponds to the  MOVD  instruction.
 ///
 /// \param __m
 ///A 64-bit integer vector.
@@ -85,7 +85,7 @@
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VMOVQ / MOVD  instruction.
+/// This intrinsic corresponds to the  MOVQ  instruction.
 ///
 /// \param __i
 ///A 64-bit signed integer.
@@ -101,7 +101,7 @@
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VMOVQ / MOVD  instruction.
+/// This intrinsic corresponds to the  MOVQ  instruction.
 ///
 /// \param __m
 ///A 64-bit integer vector.
@@ -1289,7 +1289,7 @@
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VXORPS / XORPS  instruction.
+/// This intrinsic corresponds to the  PXOR  instruction.
 ///
 /// \returns An initialized 64-bit integer vector with all elements set to zero.
 static __inline__ __m64 __DEFAULT_FN_ATTRS
@@ -1381,7 +1381,8 @@
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VPSHUFD / PSHUFD  instruction.
+/// This intrinsic is a utility function and does not correspond to a specific
+///instruction.
 ///
 /// \param __i
 ///A 32-bit integer value used to initialize each vector element of the
@@ -1399,7 +1400,8 @@
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VPSHUFLW / PSHUFLW  instruction.
+/// This intrinsic is a utility function and does not correspond to a specific
+///instruction.
 ///
 /// \param __w
 ///A 16-bit integer value used to initialize each vector element of the
@@ -1416,8 +1418,8 @@
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VPUNPCKLBW + VPSHUFLW / PUNPCKLBW +
-///PSHUFLW  

r327090 - [DOXYGEN] Fix doxygen and content issues in mmintrin.h

2018-03-08 Thread Douglas Yung via cfe-commits
Author: dyung
Date: Thu Mar  8 16:38:51 2018
New Revision: 327090

URL: http://llvm.org/viewvc/llvm-project?rev=327090=rev
Log:
[DOXYGEN] Fix doxygen and content issues in mmintrin.h

- Fix instruction mappings/listings for various intrinsics

This patch was made by Craig Flores

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


Modified:
cfe/trunk/lib/Headers/mmintrin.h

Modified: cfe/trunk/lib/Headers/mmintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/mmintrin.h?rev=327090=327089=327090=diff
==
--- cfe/trunk/lib/Headers/mmintrin.h (original)
+++ cfe/trunk/lib/Headers/mmintrin.h Thu Mar  8 16:38:51 2018
@@ -52,7 +52,7 @@ _mm_empty(void)
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VMOVD / MOVD  instruction.
+/// This intrinsic corresponds to the  MOVD  instruction.
 ///
 /// \param __i
 ///A 32-bit integer value.
@@ -69,7 +69,7 @@ _mm_cvtsi32_si64(int __i)
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VMOVD / MOVD  instruction.
+/// This intrinsic corresponds to the  MOVD  instruction.
 ///
 /// \param __m
 ///A 64-bit integer vector.
@@ -85,7 +85,7 @@ _mm_cvtsi64_si32(__m64 __m)
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VMOVQ / MOVD  instruction.
+/// This intrinsic corresponds to the  MOVQ  instruction.
 ///
 /// \param __i
 ///A 64-bit signed integer.
@@ -101,7 +101,7 @@ _mm_cvtsi64_m64(long long __i)
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VMOVQ / MOVD  instruction.
+/// This intrinsic corresponds to the  MOVQ  instruction.
 ///
 /// \param __m
 ///A 64-bit integer vector.
@@ -1289,7 +1289,7 @@ _mm_cmpgt_pi32(__m64 __m1, __m64 __m2)
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VXORPS / XORPS  instruction.
+/// This intrinsic corresponds to the  PXOR  instruction.
 ///
 /// \returns An initialized 64-bit integer vector with all elements set to 
zero.
 static __inline__ __m64 __DEFAULT_FN_ATTRS
@@ -1381,7 +1381,8 @@ _mm_set_pi8(char __b7, char __b6, char _
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VPSHUFD / PSHUFD  instruction.
+/// This intrinsic is a utility function and does not correspond to a specific
+///instruction.
 ///
 /// \param __i
 ///A 32-bit integer value used to initialize each vector element of the
@@ -1399,7 +1400,8 @@ _mm_set1_pi32(int __i)
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VPSHUFLW / PSHUFLW  instruction.
+/// This intrinsic is a utility function and does not correspond to a specific
+///instruction.
 ///
 /// \param __w
 ///A 16-bit integer value used to initialize each vector element of the
@@ -1416,8 +1418,8 @@ _mm_set1_pi16(short __w)
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the  VPUNPCKLBW + VPSHUFLW / PUNPCKLBW +
-///PSHUFLW  instruction.
+/// This intrinsic is a utility function and does not correspond to a specific
+///instruction.
 ///
 /// \param __b
 ///An 8-bit integer value used to initialize each vector element of the


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


[PATCH] D43906: [clang-format] Improve detection of Objective-C block types

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

Nice.. Removed a lot of complexity :). Let's see whether this heuristic is good 
enough.




Comment at: lib/Format/TokenAnnotator.cpp:210
 
-bool MightBeFunctionType = !Contexts[Contexts.size() - 2].IsExpression;
-bool ProbablyFunctionType = CurrentToken->isOneOf(tok::star, tok::amp);
+bool MightBeFunctionOrObjCBlockType =
+!Contexts[Contexts.size() - 2].IsExpression;

I'd suggest to put a comment here saying that this is for both ObjC blocks and 
Function types, because they look very similar in nature (maybe giving 
examples) and then not actually rename the variables. To me, the long names 
make the code harder to read.

But if you feel strongly the other way, I'd be ok with it.


Repository:
  rC Clang

https://reviews.llvm.org/D43906



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


[PATCH] D43494: [Modules] Fix creating fake definition data for lambdas.

2018-03-08 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Serialization/ASTReaderDecl.cpp:1790
+// set fake one.
+D->DefinitionData = DD;
   ReadCXXDefinitionData(*DD, D);

I think it would make sense to "claim" the definition more eagerly here, by 
also updating `Canon->DefinitionData` in this case, prior to reading the 
definition data (and in the case where we already have a canonical definition, 
pointing `D->DefinitionData` at that eagerly).


https://reviews.llvm.org/D43494



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


[PATCH] D43902: [clang-format] Don't detect C++11 attribute specifiers as ObjC

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



Comment at: lib/Format/TokenAnnotator.cpp:329
+  return nullptr;
+// C++17 '[[using namespace: foo, bar(baz, blech)]]'
+bool IsUsingNamespace =

Can you  make this:

  // C++17 '[[using : foo, bar(baz, blech)]]'

To make clear that we are not looking for kw_namespace here?



Comment at: lib/Format/TokenAnnotator.cpp:332
+AttrTok->startsSequence(tok::kw_using, tok::identifier, tok::colon);
+if (IsUsingNamespace) {
+  AttrTok = AttrTok->Next->Next->Next;

No braces.



Comment at: lib/Format/TokenAnnotator.cpp:336
+auto parseCpp11Attribute = [](const FormatToken ,
+  bool AllowNamespace) -> const FormatToken * {
+  if (!Tok.isOneOf(tok::identifier, tok::ellipsis))

Do you actually need to put the return type here? I would have thought that it 
can be deduced as you pass back a const FormatToken* from a codepath and 
nullptr from all the others.



Comment at: lib/Format/TokenAnnotator.cpp:342
+return nullptr;
+  if (AllowNamespace &&
+  AttrTok->startsSequence(tok::coloncolon, tok::identifier)) {

No braces.



Comment at: lib/Format/TokenAnnotator.cpp:350
+const FormatToken *ParamToken = AttrTok->Next;
+while (ParamToken && ParamToken->isNot(tok::r_paren))
+  ParamToken = ParamToken->Next;

Sorry that I have missed this before, I thought this was in a different file. 
Can you try to avoid iterating trying to count or match parentheses inside any 
of parseSquare/parseParen/parseAngle. We avoided that AFAICT for everything 
else and I don't think it's necessary here. Especially as you are not actually 
moving the token position forward, it's too easy to create a quadratic 
algorithm here.

Also: Do you actually have a test case for the the parentheses case? This thing 
could use a lot more comments...



Comment at: lib/Format/TokenAnnotator.cpp:366
+  return AttrTok->Next;
+} else {
+  return nullptr;

No braces for single statement ifs. Don't use "else" after "return".



Comment at: lib/Format/TokenAnnotator.cpp:396
+  while (CurrentToken != Cpp11AttributeSpecifierClosingRSquare) {
+if (CurrentToken->is(tok::colon)) {
+  CurrentToken->Type = TT_AttributeColon;

No braces for single-statement ifs.



Comment at: lib/Format/TokenAnnotator.cpp:397
+if (CurrentToken->is(tok::colon)) {
+  CurrentToken->Type = TT_AttributeColon;
+}

What happens if you don't assign this type here? Which formatting decision is 
based on it?



Comment at: unittests/Format/FormatTest.cpp:6064
+  verifyFormat("SomeType s [[unused]] (InitValue);");
+  verifyFormat("SomeType s [[gnu::unused]] (InitValue);");
+  verifyFormat("SomeType s [[using gnu: unused]] (InitValue);");

If this is meant to contrast a TT_AttributeColon from a different colon, that 
doesn't work. "::" is it's own token type coloncolon.


Repository:
  rC Clang

https://reviews.llvm.org/D43902



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


[PATCH] D44278: CodeGen: simplify and validate exception personalities

2018-03-08 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd updated this revision to Diff 137668.
compnerd added a comment.

add more context


Repository:
  rC Clang

https://reviews.llvm.org/D44278

Files:
  lib/CodeGen/CGException.cpp
  test/CodeGen/personality.c
  test/CodeGenCXX/personality.cpp
  test/CodeGenObjC/personality.m
  test/CodeGenObjCXX/personality.mm

Index: test/CodeGenObjCXX/personality.mm
===
--- /dev/null
+++ test/CodeGenObjCXX/personality.mm
@@ -0,0 +1,129 @@
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx-fragile -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-MACOSX-FRAGILE
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fdwarf-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx-fragile -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-MACOSX-FRAGILE
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fseh-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx-fragile -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-MACOSX-FRAGILE-SEH
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fsjlj-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx-fragile -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-MACOSX-FRAGILE-SJLJ
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fdwarf-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fseh-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fsjlj-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=ios -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fdwarf-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=ios -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fseh-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=ios -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fsjlj-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=ios -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=watchos -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fdwarf-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=watchos -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fseh-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=watchos -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fsjlj-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=watchos -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=gnustep-1.7 -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-GNUSTEP-1_7
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=gnustep -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-GNUSTEP
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=gcc -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-GCC
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fdwarf-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=gcc -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-GCC
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fseh-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=gcc -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-GCC-SEH
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fsjlj-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=gcc -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-GCC-SJLJ
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=objfw -S -emit-llvm %s -o - | 

[PATCH] D44278: CodeGen: simplify and validate exception personalities

2018-03-08 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd created this revision.
compnerd added reviewers: rnk, smeenai.

Simplify the dispatching for the personality routines.  This really had
no test coverage previously, so add test coverage for the various cases.
This turns out to be pretty complicated as the various languages and
models interact to change personalities around.

You really should feel bad for the compiler if you are using exceptions.
There is no reason for this type of cruelty.


Repository:
  rC Clang

https://reviews.llvm.org/D44278

Files:
  lib/CodeGen/CGException.cpp
  test/CodeGen/personality.c
  test/CodeGenCXX/personality.cpp
  test/CodeGenObjC/personality.m
  test/CodeGenObjCXX/personality.mm

Index: test/CodeGenObjCXX/personality.mm
===
--- /dev/null
+++ test/CodeGenObjCXX/personality.mm
@@ -0,0 +1,129 @@
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx-fragile -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-MACOSX-FRAGILE
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fdwarf-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx-fragile -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-MACOSX-FRAGILE
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fseh-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx-fragile -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-MACOSX-FRAGILE-SEH
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fsjlj-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx-fragile -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-MACOSX-FRAGILE-SJLJ
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fdwarf-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fseh-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fsjlj-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=ios -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fdwarf-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=ios -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fseh-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=ios -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fsjlj-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=ios -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=watchos -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fdwarf-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=watchos -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fseh-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=watchos -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fsjlj-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=watchos -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-NS
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=gnustep-1.7 -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-GNUSTEP-1_7
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=gnustep -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-GNUSTEP
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=gcc -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-GCC
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fdwarf-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=gcc -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-GCC
+// RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fseh-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=gcc -S -emit-llvm %s -o - | FileCheck %s 

[PATCH] D44273: [CFG] [analyzer] Fix a crash on finding construction context for an lvalue call expression.

2018-03-08 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 137661.
NoQ added a comment.

Same goes for rvalue references. Hmm, we have a fancy helper method for that 
exact purpose. But it's not super easy to use, had to sacrifice a sanity check 
assertion to use it.


https://reviews.llvm.org/D44273

Files:
  include/clang/Analysis/CFG.h
  lib/Analysis/CFG.cpp
  test/Analysis/temporaries.cpp


Index: test/Analysis/temporaries.cpp
===
--- test/Analysis/temporaries.cpp
+++ test/Analysis/temporaries.cpp
@@ -1032,4 +1032,17 @@
 }
 } // end namespace implicit_constructor_conversion
 
+namespace pass_references_through {
+class C {
+public:
+  ~C() {}
+};
+
+const C ();
+C &();
 
+// In these example the foo() expression has record type, not reference type.
+// Don't try to figure out how to perform construction of the record here.
+const C () { return foo1(); } // no-crash
+C &() { return foo2(); } // no-crash
+} // end namespace pass_references_through
Index: lib/Analysis/CFG.cpp
===
--- lib/Analysis/CFG.cpp
+++ lib/Analysis/CFG.cpp
@@ -729,7 +729,7 @@
 
   void appendCall(CFGBlock *B, CallExpr *CE) {
 if (BuildOpts.AddRichCXXConstructors) {
-  if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE)) {
+  if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE, *Context)) {
 if (const ConstructionContextLayer *Layer =
 ConstructionContextMap.lookup(CE)) {
   const ConstructionContext *CC =
@@ -1217,7 +1217,7 @@
   case Stmt::CXXOperatorCallExprClass:
   case Stmt::UserDefinedLiteralClass: {
 auto *CE = cast(Child);
-if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE))
+if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE, *Context))
   consumeConstructionContext(Layer, CE);
 break;
   }
Index: include/clang/Analysis/CFG.h
===
--- include/clang/Analysis/CFG.h
+++ include/clang/Analysis/CFG.h
@@ -181,14 +181,16 @@
 public:
   /// Returns true when call expression \p CE needs to be represented
   /// by CFGCXXRecordTypedCall, as opposed to a regular CFGStmt.
-  static bool isCXXRecordTypedCall(CallExpr *CE) {
-return CE->getType().getCanonicalType()->getAsCXXRecordDecl();
+  static bool isCXXRecordTypedCall(CallExpr *CE, const ASTContext ) {
+return 
CE->getCallReturnType(ACtx).getCanonicalType()->getAsCXXRecordDecl();
   }
 
   explicit CFGCXXRecordTypedCall(CallExpr *CE,
- const TemporaryObjectConstructionContext *C)
+ const TemporaryObjectConstructionContext *C)
   : CFGStmt(CE, CXXRecordTypedCall) {
-assert(isCXXRecordTypedCall(CE));
+// FIXME: This is not protected against squeezing a non-record-typed-call
+// into the constructor. An assertion would require passing an ASTContext
+// which would mean paying for something we don't use.
 assert(C);
 Data2.setPointer(const_cast(C));
   }


Index: test/Analysis/temporaries.cpp
===
--- test/Analysis/temporaries.cpp
+++ test/Analysis/temporaries.cpp
@@ -1032,4 +1032,17 @@
 }
 } // end namespace implicit_constructor_conversion
 
+namespace pass_references_through {
+class C {
+public:
+  ~C() {}
+};
+
+const C ();
+C &();
 
+// In these example the foo() expression has record type, not reference type.
+// Don't try to figure out how to perform construction of the record here.
+const C () { return foo1(); } // no-crash
+C &() { return foo2(); } // no-crash
+} // end namespace pass_references_through
Index: lib/Analysis/CFG.cpp
===
--- lib/Analysis/CFG.cpp
+++ lib/Analysis/CFG.cpp
@@ -729,7 +729,7 @@
 
   void appendCall(CFGBlock *B, CallExpr *CE) {
 if (BuildOpts.AddRichCXXConstructors) {
-  if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE)) {
+  if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE, *Context)) {
 if (const ConstructionContextLayer *Layer =
 ConstructionContextMap.lookup(CE)) {
   const ConstructionContext *CC =
@@ -1217,7 +1217,7 @@
   case Stmt::CXXOperatorCallExprClass:
   case Stmt::UserDefinedLiteralClass: {
 auto *CE = cast(Child);
-if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE))
+if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE, *Context))
   consumeConstructionContext(Layer, CE);
 break;
   }
Index: include/clang/Analysis/CFG.h
===
--- include/clang/Analysis/CFG.h
+++ include/clang/Analysis/CFG.h
@@ -181,14 +181,16 @@
 public:
   /// Returns true when call expression \p CE needs to be represented
   /// by CFGCXXRecordTypedCall, as opposed to a regular CFGStmt.
-  static bool isCXXRecordTypedCall(CallExpr *CE) {
-return 

[PATCH] D44273: [CFG] [analyzer] Fix a crash on finding construction context for an lvalue call expression.

2018-03-08 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 137662.
NoQ added a comment.

Fix typo in the comments.


https://reviews.llvm.org/D44273

Files:
  include/clang/Analysis/CFG.h
  lib/Analysis/CFG.cpp
  test/Analysis/temporaries.cpp


Index: test/Analysis/temporaries.cpp
===
--- test/Analysis/temporaries.cpp
+++ test/Analysis/temporaries.cpp
@@ -1032,4 +1032,17 @@
 }
 } // end namespace implicit_constructor_conversion
 
+namespace pass_references_through {
+class C {
+public:
+  ~C() {}
+};
+
+const C ();
+C &();
 
+// In these examples the foo() expression has record type, not reference type.
+// Don't try to figure out how to perform construction of the record here.
+const C () { return foo1(); } // no-crash
+C &() { return foo2(); } // no-crash
+} // end namespace pass_references_through
Index: lib/Analysis/CFG.cpp
===
--- lib/Analysis/CFG.cpp
+++ lib/Analysis/CFG.cpp
@@ -729,7 +729,7 @@
 
   void appendCall(CFGBlock *B, CallExpr *CE) {
 if (BuildOpts.AddRichCXXConstructors) {
-  if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE)) {
+  if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE, *Context)) {
 if (const ConstructionContextLayer *Layer =
 ConstructionContextMap.lookup(CE)) {
   const ConstructionContext *CC =
@@ -1217,7 +1217,7 @@
   case Stmt::CXXOperatorCallExprClass:
   case Stmt::UserDefinedLiteralClass: {
 auto *CE = cast(Child);
-if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE))
+if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE, *Context))
   consumeConstructionContext(Layer, CE);
 break;
   }
Index: include/clang/Analysis/CFG.h
===
--- include/clang/Analysis/CFG.h
+++ include/clang/Analysis/CFG.h
@@ -181,14 +181,16 @@
 public:
   /// Returns true when call expression \p CE needs to be represented
   /// by CFGCXXRecordTypedCall, as opposed to a regular CFGStmt.
-  static bool isCXXRecordTypedCall(CallExpr *CE) {
-return CE->getType().getCanonicalType()->getAsCXXRecordDecl();
+  static bool isCXXRecordTypedCall(CallExpr *CE, const ASTContext ) {
+return 
CE->getCallReturnType(ACtx).getCanonicalType()->getAsCXXRecordDecl();
   }
 
   explicit CFGCXXRecordTypedCall(CallExpr *CE,
- const TemporaryObjectConstructionContext *C)
+ const TemporaryObjectConstructionContext *C)
   : CFGStmt(CE, CXXRecordTypedCall) {
-assert(isCXXRecordTypedCall(CE));
+// FIXME: This is not protected against squeezing a non-record-typed-call
+// into the constructor. An assertion would require passing an ASTContext
+// which would mean paying for something we don't use.
 assert(C);
 Data2.setPointer(const_cast(C));
   }


Index: test/Analysis/temporaries.cpp
===
--- test/Analysis/temporaries.cpp
+++ test/Analysis/temporaries.cpp
@@ -1032,4 +1032,17 @@
 }
 } // end namespace implicit_constructor_conversion
 
+namespace pass_references_through {
+class C {
+public:
+  ~C() {}
+};
+
+const C ();
+C &();
 
+// In these examples the foo() expression has record type, not reference type.
+// Don't try to figure out how to perform construction of the record here.
+const C () { return foo1(); } // no-crash
+C &() { return foo2(); } // no-crash
+} // end namespace pass_references_through
Index: lib/Analysis/CFG.cpp
===
--- lib/Analysis/CFG.cpp
+++ lib/Analysis/CFG.cpp
@@ -729,7 +729,7 @@
 
   void appendCall(CFGBlock *B, CallExpr *CE) {
 if (BuildOpts.AddRichCXXConstructors) {
-  if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE)) {
+  if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE, *Context)) {
 if (const ConstructionContextLayer *Layer =
 ConstructionContextMap.lookup(CE)) {
   const ConstructionContext *CC =
@@ -1217,7 +1217,7 @@
   case Stmt::CXXOperatorCallExprClass:
   case Stmt::UserDefinedLiteralClass: {
 auto *CE = cast(Child);
-if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE))
+if (CFGCXXRecordTypedCall::isCXXRecordTypedCall(CE, *Context))
   consumeConstructionContext(Layer, CE);
 break;
   }
Index: include/clang/Analysis/CFG.h
===
--- include/clang/Analysis/CFG.h
+++ include/clang/Analysis/CFG.h
@@ -181,14 +181,16 @@
 public:
   /// Returns true when call expression \p CE needs to be represented
   /// by CFGCXXRecordTypedCall, as opposed to a regular CFGStmt.
-  static bool isCXXRecordTypedCall(CallExpr *CE) {
-return CE->getType().getCanonicalType()->getAsCXXRecordDecl();
+  static bool isCXXRecordTypedCall(CallExpr *CE, const ASTContext ) {
+return 

r327078 - Add a debug info testcase for the trvial_abi attribute.

2018-03-08 Thread Adrian Prantl via cfe-commits
Author: adrian
Date: Thu Mar  8 15:11:46 2018
New Revision: 327078

URL: http://llvm.org/viewvc/llvm-project?rev=327078=rev
Log:
Add a debug info testcase for the trvial_abi attribute.

Modified:
cfe/trunk/test/CodeGenCXX/debug-info-composite-cc.cpp

Modified: cfe/trunk/test/CodeGenCXX/debug-info-composite-cc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-composite-cc.cpp?rev=327078=327077=327078=diff
==
--- cfe/trunk/test/CodeGenCXX/debug-info-composite-cc.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-composite-cc.cpp Thu Mar  8 15:11:46 
2018
@@ -38,3 +38,13 @@ struct Complex {
   Complex(Complex ) : i(Copy.i) {};
   int i;
 } complex;
+
+// This type is manually marked as trivial_abi.
+// CHECK-DAG: !DICompositeType({{.*}}, name: "Marked",{{.*}}flags: 
DIFlagTypePassByValue
+struct __attribute__((trivial_abi)) Marked {
+  int *p;
+  Marked();
+  ~Marked();
+  Marked(const Marked &) noexcept;
+  Marked =(const Marked &);
+} marked;


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


[libclc] r327076 - amdgcn/fmax: fcanonicalize operands

2018-03-08 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Thu Mar  8 15:01:01 2018
New Revision: 327076

URL: http://llvm.org/viewvc/llvm-project?rev=327076=rev
Log:
amdgcn/fmax: fcanonicalize operands

v_max instruction needs canonicalized operands.
Passes CTS on carrizo

Reviewer: Aaron Watry 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/amdgcn/lib/math/fmax.cl
Modified:
libclc/trunk/amdgcn/lib/SOURCES

Modified: libclc/trunk/amdgcn/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/amdgcn/lib/SOURCES?rev=327076=327075=327076=diff
==
--- libclc/trunk/amdgcn/lib/SOURCES (original)
+++ libclc/trunk/amdgcn/lib/SOURCES Thu Mar  8 15:01:01 2018
@@ -1,5 +1,6 @@
 cl_khr_int64_extended_atomics/minmax_helpers.ll
 integer/popcount.cl
+math/fmax.cl
 math/fmin.cl
 math/ldexp.cl
 mem_fence/fence.cl

Added: libclc/trunk/amdgcn/lib/math/fmax.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/amdgcn/lib/math/fmax.cl?rev=327076=auto
==
--- libclc/trunk/amdgcn/lib/math/fmax.cl (added)
+++ libclc/trunk/amdgcn/lib/math/fmax.cl Thu Mar  8 15:01:01 2018
@@ -0,0 +1,31 @@
+#include 
+
+#include "../../../generic/lib/clcmacro.h"
+
+_CLC_DEF _CLC_OVERLOAD float fmax(float x, float y)
+{
+   /* fcanonicalize removes sNaNs and flushes denormals if not enabled.
+* Otherwise fmax instruction flushes the values for comparison,
+* but outputs original denormal */
+   x = __builtin_canonicalizef(x);
+   y = __builtin_canonicalizef(y);
+   return __builtin_fmaxf(x, y);
+}
+_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, fmax, float, float)
+
+#ifdef cl_khr_fp64
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+_CLC_DEF _CLC_OVERLOAD double fmax(double x, double y)
+{
+   x = __builtin_canonicalize(x);
+   y = __builtin_canonicalize(y);
+   return __builtin_fmax(x, y);
+}
+_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, fmax, double, double)
+
+#endif
+
+#define __CLC_BODY <../../../generic/lib/math/fmax.inc>
+#include 


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


[libclc] r327075 - amdgcn/fmin: fcanonicalize operands

2018-03-08 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Thu Mar  8 15:00:58 2018
New Revision: 327075

URL: http://llvm.org/viewvc/llvm-project?rev=327075=rev
Log:
amdgcn/fmin: fcanonicalize operands

v_min instruction needs canonicalized operands.
Passes CTS on carrizo

Reviewer: Aaron Watry 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/amdgcn/lib/math/fmin.cl
Modified:
libclc/trunk/amdgcn/lib/SOURCES

Modified: libclc/trunk/amdgcn/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/amdgcn/lib/SOURCES?rev=327075=327074=327075=diff
==
--- libclc/trunk/amdgcn/lib/SOURCES (original)
+++ libclc/trunk/amdgcn/lib/SOURCES Thu Mar  8 15:00:58 2018
@@ -1,5 +1,6 @@
 cl_khr_int64_extended_atomics/minmax_helpers.ll
 integer/popcount.cl
+math/fmin.cl
 math/ldexp.cl
 mem_fence/fence.cl
 synchronization/barrier.cl

Added: libclc/trunk/amdgcn/lib/math/fmin.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/amdgcn/lib/math/fmin.cl?rev=327075=auto
==
--- libclc/trunk/amdgcn/lib/math/fmin.cl (added)
+++ libclc/trunk/amdgcn/lib/math/fmin.cl Thu Mar  8 15:00:58 2018
@@ -0,0 +1,31 @@
+#include 
+
+#include "../../../generic/lib/clcmacro.h"
+
+_CLC_DEF _CLC_OVERLOAD float fmin(float x, float y)
+{
+   /* fcanonicalize removes sNaNs and flushes denormals if not enabled.
+* Otherwise fmin instruction flushes the values for comparison,
+* but outputs original denormal */
+   x = __builtin_canonicalizef(x);
+   y = __builtin_canonicalizef(y);
+   return __builtin_fminf(x, y);
+}
+_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, fmin, float, float)
+
+#ifdef cl_khr_fp64
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+_CLC_DEF _CLC_OVERLOAD double fmin(double x, double y)
+{
+   x = __builtin_canonicalizef(x);
+   y = __builtin_canonicalizef(y);
+   return __builtin_fminf(x, y);
+}
+_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, fmin, double, double)
+
+#endif
+
+#define __CLC_BODY <../../../generic/lib/math/fmin.inc>
+#include 


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


r327074 - [StaticAnalyzer] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).

2018-03-08 Thread Eugene Zelenko via cfe-commits
Author: eugenezelenko
Date: Thu Mar  8 14:45:13 2018
New Revision: 327074

URL: http://llvm.org/viewvc/llvm-project?rev=327074=rev
Log:
[StaticAnalyzer] Fix some Clang-tidy modernize and Include What You Use 
warnings; other minor fixes (NFC).

Modified:

cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h?rev=327074=327073=327074=diff
==
--- 
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h 
(original)
+++ 
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h 
Thu Mar  8 14:45:13 2018
@@ -1,4 +1,4 @@
-//===---  BugReporterVisitors.h - Generate PathDiagnostics ---*- C++ 
-*-===//
+//===- BugReporterVisitors.h - Generate PathDiagnostics -*- C++ 
-*-===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -15,11 +15,20 @@
 #ifndef LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_BUGREPORTERVISITORS_H
 #define LLVM_CLANG_STATICANALYZER_CORE_BUGREPORTER_BUGREPORTERVISITORS_H
 
+#include "clang/Basic/LLVM.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
 #include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include 
 
 namespace clang {
+
+class BinaryOperator;
 class CFGBlock;
+class DeclRefExpr;
+class Expr;
+class Stmt;
 
 namespace ento {
 
@@ -99,7 +108,7 @@ class FindLastStoreBRVisitor final
 : public BugReporterVisitorImpl {
   const MemRegion *R;
   SVal V;
-  bool Satisfied;
+  bool Satisfied = false;
 
   /// If the visitor is tracking the value directly responsible for the
   /// bug, we are going to employ false positive suppression.
@@ -113,10 +122,7 @@ public:
 
   FindLastStoreBRVisitor(KnownSVal V, const MemRegion *R,
  bool InEnableNullFPSuppression)
-  : R(R),
-V(V),
-Satisfied(false),
-EnableNullFPSuppression(InEnableNullFPSuppression) {}
+  : R(R), V(V), EnableNullFPSuppression(InEnableNullFPSuppression) {}
 
   void Profile(llvm::FoldingSetNodeID ) const override;
 
@@ -130,18 +136,17 @@ class TrackConstraintBRVisitor final
 : public BugReporterVisitorImpl {
   DefinedSVal Constraint;
   bool Assumption;
-  bool IsSatisfied;
+  bool IsSatisfied = false;
   bool IsZeroCheck;
 
   /// We should start tracking from the last node along the path in which the
   /// value is constrained.
-  bool IsTrackingTurnedOn;
+  bool IsTrackingTurnedOn = false;
 
 public:
   TrackConstraintBRVisitor(DefinedSVal constraint, bool assumption)
-  : Constraint(constraint), Assumption(assumption), IsSatisfied(false),
-IsZeroCheck(!Assumption && Constraint.getAs()),
-IsTrackingTurnedOn(false) {}
+  : Constraint(constraint), Assumption(assumption),
+IsZeroCheck(!Assumption && Constraint.getAs()) {}
 
   void Profile(llvm::FoldingSetNodeID ) const override;
 
@@ -157,7 +162,6 @@ public:
 private:
   /// Checks if the constraint is valid in the current state.
   bool isUnderconstrained(const ExplodedNode *N) const;
-
 };
 
 /// \class NilReceiverBRVisitor
@@ -165,7 +169,6 @@ private:
 class NilReceiverBRVisitor final
 : public BugReporterVisitorImpl {
 public:
-
   void Profile(llvm::FoldingSetNodeID ) const override {
 static int x = 0;
 ID.AddPointer();
@@ -184,7 +187,6 @@ public:
 /// Visitor that tries to report interesting diagnostics from conditions.
 class ConditionBRVisitor final
 : public BugReporterVisitorImpl {
-
   // FIXME: constexpr initialization isn't supported by MSVC2013.
   static const char *const GenericTrueMessage;
   static const char *const GenericFalseMessage;
@@ -277,7 +279,6 @@ public:
 /// if the region's contents are not modified/accessed by the call.
 class UndefOrNullArgVisitor final
 : public BugReporterVisitorImpl {
-
   /// The interesting memory region this visitor is tracking.
   const MemRegion *R;
 
@@ -303,14 +304,14 @@ class SuppressInlineDefensiveChecksVisit
   DefinedSVal V;
 
   /// Track if we found the node where the constraint was first added.
-  bool IsSatisfied;
+  bool IsSatisfied = false;
 
   /// Since the visitors can be registered on nodes previous to the last
   /// node in the BugReport, but the path traversal always starts with the last
   /// node, the visitor invariant (that we start with a node in which V is 
null)
   /// might not hold when node visitation starts. We are going to start 
tracking
   /// from the last node in which the value is null.
-  bool IsTrackingTurnedOn;
+  bool IsTrackingTurnedOn = false;
 
 public:
   

[PATCH] D44231: [clang-tidy] Check for sizeof that call functions

2018-03-08 Thread Paul Fultz II via Phabricator via cfe-commits
pfultz2 added a comment.

> If the return type of foo() is changed, then the use for s1 will be 
> automatically updated

But usually you write it as:

  using foo_return = uint16_t;
  foo_return foo();
  ...
  size_t s1 = sizeof(foo());
  size_t s2 = sizeof(foo_return);

So you just update the `foo_return` typedef, and it will update it everywhere 
that type is used.

> I think we need some data measurements over several large (>500k LoC) C and 
> C++ code bases to see how frequently this check yields false positives.

So I ran it on llvm. It mainly complained about areas where `sizeof` is used 
for building traits. I should add an extra check that the function is not 
overloaded.

It did complain once about `sizeof` in a detection idiom(in BitmaskEnum.h) and 
once with `sizeof(getVersion())`, like you mentioned.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44231



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


[PATCH] D44273: [CFG] [analyzer] Fix a crash on finding construction context for an lvalue call expression.

2018-03-08 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet.
Herald added subscribers: cfe-commits, rnkovacs.

The type of the call expression and the return value type of the function are 
not necessarily the same thing. In the attached example, the function is 
declared to return `const C &`, but the actual call-expression has type `const 
C` and is also an //lvalue//. Which is, well, kinda the same thing, but needs a 
different sort of boilerplate.

Previously we tried to find construction context for such call-expression and 
became surprised that this is not a temporary object context. Fix the crash by 
making sure that the call-expression is not an lvalue before trying to attach a 
construction context to it.


Repository:
  rC Clang

https://reviews.llvm.org/D44273

Files:
  include/clang/Analysis/CFG.h
  test/Analysis/temporaries.cpp


Index: test/Analysis/temporaries.cpp
===
--- test/Analysis/temporaries.cpp
+++ test/Analysis/temporaries.cpp
@@ -1032,4 +1032,17 @@
 }
 } // end namespace implicit_constructor_conversion
 
+namespace pass_references_through {
+class C {
+public:
+  ~C() {}
+};
+
+const C ();
 
+// In this example the foo() expression has record type,
+// not reference type. But luckily it's still an lvalue.
+// Don't try to figure out how to perform construction
+// of the record here.
+const C () { return foo(); } // no-crash
+} // end namespace pass_references_through
Index: include/clang/Analysis/CFG.h
===
--- include/clang/Analysis/CFG.h
+++ include/clang/Analysis/CFG.h
@@ -182,7 +182,8 @@
   /// Returns true when call expression \p CE needs to be represented
   /// by CFGCXXRecordTypedCall, as opposed to a regular CFGStmt.
   static bool isCXXRecordTypedCall(CallExpr *CE) {
-return CE->getType().getCanonicalType()->getAsCXXRecordDecl();
+return !CE->isLValue() &&
+   CE->getType().getCanonicalType()->getAsCXXRecordDecl();
   }
 
   explicit CFGCXXRecordTypedCall(CallExpr *CE,


Index: test/Analysis/temporaries.cpp
===
--- test/Analysis/temporaries.cpp
+++ test/Analysis/temporaries.cpp
@@ -1032,4 +1032,17 @@
 }
 } // end namespace implicit_constructor_conversion
 
+namespace pass_references_through {
+class C {
+public:
+  ~C() {}
+};
+
+const C ();
 
+// In this example the foo() expression has record type,
+// not reference type. But luckily it's still an lvalue.
+// Don't try to figure out how to perform construction
+// of the record here.
+const C () { return foo(); } // no-crash
+} // end namespace pass_references_through
Index: include/clang/Analysis/CFG.h
===
--- include/clang/Analysis/CFG.h
+++ include/clang/Analysis/CFG.h
@@ -182,7 +182,8 @@
   /// Returns true when call expression \p CE needs to be represented
   /// by CFGCXXRecordTypedCall, as opposed to a regular CFGStmt.
   static bool isCXXRecordTypedCall(CallExpr *CE) {
-return CE->getType().getCanonicalType()->getAsCXXRecordDecl();
+return !CE->isLValue() &&
+   CE->getType().getCanonicalType()->getAsCXXRecordDecl();
   }
 
   explicit CFGCXXRecordTypedCall(CallExpr *CE,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44093: [BUILTINS] structure pretty printer

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



Comment at: lib/CodeGen/CGBuiltin.cpp:1231
+  Types[getContext().VoidPtrTy] = "%p";
+  Types[getContext().FloatTy] = "%f";
+  Types[getContext().DoubleTy] = "%f";

paulsemel wrote:
> aaron.ballman wrote:
> > paulsemel wrote:
> > > aaron.ballman wrote:
> > > > It's unfortunate that you cannot distinguish between `float` and 
> > > > `double`. Do you need to use the format specifiers exactly?
> > > > 
> > > > What about other type information, like qualifiers or array extents? 
> > > > How should this handle types that do not exist in this mapping, like 
> > > > structure or enum types?
> > > So, I've think about it. What I am going to do is  that if I do not know 
> > > the type of the field, I am just going to print it as a pointer. I know 
> > > that it is not the best solution, but I think it's a okay-ish solution 
> > > until I implement the other types.
> > > For the qualifiers, at it is printed the same way with and without those, 
> > > I can just add the entries in the DenseMap.
> > > So, I've think about it. What I am going to do is that if I do not know 
> > > the type of the field, I am just going to print it as a pointer. I know 
> > > that it is not the best solution, but I think it's a okay-ish solution 
> > > until I implement the other types.
> > 
> > Eek. That seems unfortunate. I'm thinking about very common use cases, like:
> > ```
> > struct S {
> >   int i, j;
> >   float x, y;
> > };
> > 
> > struct T {
> >   struct S s;
> >   int k;
> > };
> > ```
> > Printing out `s` as a pointer seems... not particularly useful.
> Yes, I see that this is true for other types that I am not handling for the 
> moment.. What do you think is the best behavior for those cases ?
> Just not print anything and go to the next entry ?
I would probably try to recurse into the contained member with another layer of 
`{}` around its fields; if you restructured the code such that it is a 
function, this recursion probably wouldn't be too bad to implement.



Comment at: lib/CodeGen/CGBuiltin.cpp:1252
+  Types[getContext().getPointerType(getContext().CharTy)] = "%s";
+  GENERATE_TYPE_QUALIFIERS_NO_RESTRICT(getContext().CharTy, "%s")
+}

paulsemel wrote:
> aaron.ballman wrote:
> > What about other types that have format specifiers (ptrdiff_t, size_t, 
> > intptr_t, char16_t, etc)?
> So, for typedef, why not apply the `QualType::getCanonicalType` to our field 
> type, so that we try to get rid of those intermediate typedefs ?
It should be possible to do for type aliases, because you know the canonical 
type information. However, that won't work for builtin types that aren't a 
typedef like `char16_t`.


Repository:
  rC Clang

https://reviews.llvm.org/D44093



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


[PATCH] D44272: [clangd] Support incremental document syncing

2018-03-08 Thread Simon Marchi via Phabricator via cfe-commits
simark created this revision.
Herald added subscribers: cfe-commits, ioeric, jkorous-apple, ilya-biryukov, 
mgorny, klimek.
simark added a reviewer: malaperle.

This patch adds support for incremental document syncing, as described
in the LSP spec.  The protocol specifies ranges in terms of Position (a
line and a character), and our drafts are stored as plain strings.  So I
see two things that may not be super efficient for very large files:

- Converting a Position to an offset (the positionToOffset function) requires 
searching for end of lines until we reach the desired line.
- When we update a range, we construct a new string, which implies copying the 
whole document.

However, for the typical size of a C++ document and the frequency of
update (at which a user types), it may not be an issue.  This patch aims
at getting the basic feature in, and we can always improve it later if
we find it's too slow.

Signed-off-by: Simon Marchi 


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44272

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/DraftStore.cpp
  clangd/DraftStore.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  test/clangd/initialize-params-invalid.test
  test/clangd/initialize-params.test
  unittests/clangd/CMakeLists.txt
  unittests/clangd/DraftStoreTests.cpp

Index: unittests/clangd/DraftStoreTests.cpp
===
--- /dev/null
+++ unittests/clangd/DraftStoreTests.cpp
@@ -0,0 +1,164 @@
+//===-- DraftStoreTests.cpp - Clangd unit tests -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "Annotations.h"
+#include "DraftStore.h"
+#include "Protocol.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+
+using namespace llvm;
+
+namespace {
+using testing::ElementsAre;
+using testing::IsEmpty;
+
+struct IncrementalTestStep {
+  StringRef Src;
+  StringRef Contents;
+};
+
+static void
+runIncrementalUpdateTest(llvm::ArrayRef Steps) {
+  DraftStore DS;
+  std::string NewContents;
+  Annotations InitialSrc(Steps[0].Src);
+  const char Path[] = "/hello.cpp";
+
+  // Set the initial content.
+  DS.updateDraft(Path, InitialSrc.code(), {}, );
+  EXPECT_EQ(NewContents, InitialSrc.code());
+  EXPECT_EQ(*DS.getDraft(Path).Draft, InitialSrc.code());
+
+  // For each step, replace the range marked in \p Src with \p Contents, and
+  // verify that it's equal to the following step's \p Src.
+  for (size_t i = 1; i < Steps.size(); i++) {
+Annotations SrcBefore(Steps[i - 1].Src);
+Annotations SrcAfter(Steps[i].Src);
+StringRef Contents = Steps[i - 1].Contents;
+
+DS.updateDraft(Path, Contents, SrcBefore.range(), );
+EXPECT_EQ(NewContents, SrcAfter.code());
+EXPECT_EQ(*DS.getDraft(Path).Draft, SrcAfter.code());
+  }
+}
+
+TEST(DraftStoreIncrementalUpdateTest, Simple) {
+  // clang-format off
+  IncrementalTestStep Steps[] =
+{
+  // Replace a range
+  {
+R"cpp(static int
+hello[[World]]()
+{})cpp",
+"Universe"
+  },
+  // Delete a range
+  {
+R"cpp(static int
+hello[[Universe]]()
+{})cpp",
+""
+  },
+  // Add a range
+  {
+R"cpp(static int
+hello[[]]()
+{})cpp",
+"Monde"
+  },
+  {
+R"cpp(static int
+helloMonde()
+{})cpp",
+""
+  }
+};
+  // clang-format on
+
+  runIncrementalUpdateTest(Steps);
+}
+
+TEST(DraftStoreIncrementalUpdateTest, MultiLine) {
+  // clang-format off
+  IncrementalTestStep Steps[] =
+{
+  // Replace a range
+  {
+R"cpp(static [[int
+helloWorld]]()
+{})cpp",
+R"cpp(char
+welcome)cpp"
+  },
+  // Delete a range
+  {
+R"cpp(static char[[
+welcome]]()
+{})cpp",
+""
+  },
+  // Add a range
+  {
+R"cpp(static char[[]]()
+{})cpp",
+R"cpp(
+cookies)cpp"
+  },
+  {
+R"cpp(static char
+cookies()
+{})cpp",
+""
+  }
+};
+  // clang-format on
+
+  runIncrementalUpdateTest(Steps);
+}
+
+TEST(DraftStoreUpdateTest, Simple) {
+  StringRef Src =
+  R"cpp(static int
+helloWorld()
+{})cpp";
+
+  DraftStore DS;
+  StringRef Path = "/hello.cpp";
+  std::string NewContents;
+
+  // Add a document
+  DS.updateDraft(Path, Src, {}, );
+  EXPECT_EQ(NewContents, Src);
+  EXPECT_EQ(*DS.getDraft(Path).Draft, Src);
+  EXPECT_THAT(DS.getActiveFiles(), ElementsAre(Path));
+
+  StringRef Src2 =
+  R"cpp(static char
+thisIsAFunction()
+{})cpp";
+  DS.updateDraft(Path, Src2, {}, );
+  EXPECT_EQ(NewContents, Src2);
+  EXPECT_EQ(*DS.getDraft(Path).Draft, Src2);
+  EXPECT_THAT(DS.getActiveFiles(), ElementsAre(Path));
+
+  DS.removeDraft(Path);
+  EXPECT_FALSE(DS.getDraft(Path).Draft.hasValue());
+  

[PATCH] D41976: Low-hanging fruit optimization in string::__move_assign().

2018-03-08 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

Thanks @tvanslyke and @mclow.lists, landed as r327064.


Repository:
  rCXX libc++

https://reviews.llvm.org/D41976



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


[PATCH] D41976: Low-hanging fruit optimization in string::__move_assign().

2018-03-08 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCXX327064: Low-hanging fruit optimization in 
string::__move_assign(). (authored by vedantk, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41976?vs=130819=137647#toc

Repository:
  rCXX libc++

https://reviews.llvm.org/D41976

Files:
  include/string
  
test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink_db1.pass.cpp

Index: include/string
===
--- include/string
+++ include/string
@@ -1257,6 +1257,8 @@
 
 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
 
+_LIBCPP_INLINE_VISIBILITY void __clear_and_shrink();
+
 _LIBCPP_INLINE_VISIBILITY
 bool __is_long() const _NOEXCEPT
 {return bool(__r_.first().__s.__size_ & __short_mask);}
@@ -1426,16 +1428,14 @@
 {
 if (!__str.__is_long())
 {
-clear();
-shrink_to_fit();
+__clear_and_shrink();
 __alloc() = __str.__alloc();
 }
 else
 {
 allocator_type __a = __str.__alloc();
 pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
-clear();
-shrink_to_fit();
+__clear_and_shrink();
 __alloc() = _VSTD::move(__a);
 __set_long_pointer(__p);
 __set_long_cap(__str.__get_long_cap());
@@ -2125,8 +2125,7 @@
 _NOEXCEPT_(is_nothrow_move_assignable::value)
 #endif
 {
-clear();
-shrink_to_fit();
+__clear_and_shrink();
 __r_.first() = __str.__r_.first();
 __move_assign_alloc(__str);
 __str.__zero();
@@ -3579,6 +3578,22 @@
 return true;
 }
 
+// __clear_and_shrink
+
+template
+inline _LIBCPP_INLINE_VISIBILITY
+void 
+basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink()
+{
+clear();
+if(__is_long())
+{
+__alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
+__set_long_cap(0);
+__set_short_size(0);
+}
+} 
+
 // operator==
 
 template
Index: test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink_db1.pass.cpp
===
--- test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink_db1.pass.cpp
+++ test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink_db1.pass.cpp
@@ -0,0 +1,48 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// Call __clear_and_shrink() and ensure string invariants hold
+
+#if _LIBCPP_DEBUG >= 1
+
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+
+#include 
+#include 
+
+int main()
+{
+std::string l = "Long string so that allocation definitely, for sure, absolutely happens. Probably.";
+std::string s = "short";
+
+assert(l.__invariants());
+assert(s.__invariants());
+
+s.__clear_and_shrink();
+assert(s.__invariants());
+assert(s.size() == 0);
+
+{ 
+std::string::size_type cap = l.capacity();
+l.__clear_and_shrink();
+assert(l.__invariants());
+assert(l.size() == 0);
+assert(l.capacity() < cap);
+}
+}
+
+#else
+
+int main()
+{
+}
+
+#endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r327064 - Low-hanging fruit optimization in string::__move_assign().

2018-03-08 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Thu Mar  8 13:15:26 2018
New Revision: 327064

URL: http://llvm.org/viewvc/llvm-project?rev=327064=rev
Log:
Low-hanging fruit optimization in string::__move_assign().

shrink_to_fit() ends up doing a lot work to get information that we
already know since we just called clear(). This change seems concise
enough to be worth the couple extra lines and my benchmarks show that it
is indeed a pretty decent win. It looks like the same thing is going on
twice in __copy_assign_alloc(), but I didn't want to go overboard since
this is my first contribution to llvm/libc++.

Patch by Timothy VanSlyke!

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

Added:

libcxx/trunk/test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink_db1.pass.cpp
Modified:
libcxx/trunk/include/string

Modified: libcxx/trunk/include/string
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=327064=327063=327064=diff
==
--- libcxx/trunk/include/string (original)
+++ libcxx/trunk/include/string Thu Mar  8 13:15:26 2018
@@ -1257,6 +1257,8 @@ public:
 
 _LIBCPP_INLINE_VISIBILITY bool __invariants() const;
 
+_LIBCPP_INLINE_VISIBILITY void __clear_and_shrink();
+
 _LIBCPP_INLINE_VISIBILITY
 bool __is_long() const _NOEXCEPT
 {return bool(__r_.first().__s.__size_ & __short_mask);}
@@ -1426,16 +1428,14 @@ private:
 {
 if (!__str.__is_long())
 {
-clear();
-shrink_to_fit();
+__clear_and_shrink();
 __alloc() = __str.__alloc();
 }
 else
 {
 allocator_type __a = __str.__alloc();
 pointer __p = __alloc_traits::allocate(__a, 
__str.__get_long_cap());
-clear();
-shrink_to_fit();
+__clear_and_shrink();
 __alloc() = _VSTD::move(__a);
 __set_long_pointer(__p);
 __set_long_cap(__str.__get_long_cap());
@@ -2125,8 +2125,7 @@ basic_string<_CharT, _Traits, _Allocator
 _NOEXCEPT_(is_nothrow_move_assignable::value)
 #endif
 {
-clear();
-shrink_to_fit();
+__clear_and_shrink();
 __r_.first() = __str.__r_.first();
 __move_assign_alloc(__str);
 __str.__zero();
@@ -3579,6 +3578,22 @@ basic_string<_CharT, _Traits, _Allocator
 return true;
 }
 
+// __clear_and_shrink
+
+template
+inline _LIBCPP_INLINE_VISIBILITY
+void 
+basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink()
+{
+clear();
+if(__is_long())
+{
+__alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() 
+ 1);
+__set_long_cap(0);
+__set_short_size(0);
+}
+} 
+
 // operator==
 
 template

Added: 
libcxx/trunk/test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink_db1.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink_db1.pass.cpp?rev=327064=auto
==
--- 
libcxx/trunk/test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink_db1.pass.cpp
 (added)
+++ 
libcxx/trunk/test/libcxx/strings/basic.string/string.modifiers/clear_and_shrink_db1.pass.cpp
 Thu Mar  8 13:15:26 2018
@@ -0,0 +1,48 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// Call __clear_and_shrink() and ensure string invariants hold
+
+#if _LIBCPP_DEBUG >= 1
+
+#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
+
+#include 
+#include 
+
+int main()
+{
+std::string l = "Long string so that allocation definitely, for sure, 
absolutely happens. Probably.";
+std::string s = "short";
+
+assert(l.__invariants());
+assert(s.__invariants());
+
+s.__clear_and_shrink();
+assert(s.__invariants());
+assert(s.size() == 0);
+
+{ 
+std::string::size_type cap = l.capacity();
+l.__clear_and_shrink();
+assert(l.__invariants());
+assert(l.size() == 0);
+assert(l.capacity() < cap);
+}
+}
+
+#else
+
+int main()
+{
+}
+
+#endif


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


[PATCH] D44217: [clang-tidy] Enable Python 3 support for add_new_check.py

2018-03-08 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe updated this revision to Diff 137646.

https://reviews.llvm.org/D44217

Files:
  clang-tools-extra/clang-tidy/add_new_check.py

Index: clang-tools-extra/clang-tidy/add_new_check.py
===
--- clang-tools-extra/clang-tidy/add_new_check.py
+++ clang-tools-extra/clang-tidy/add_new_check.py
@@ -9,12 +9,13 @@
 #
 #======#
 
+from __future__ import print_function
+
 import argparse
 import os
 import re
 import sys
 
-
 # Adapts the module's CMakelist file. Returns 'True' if it could add a new entry
 # and 'False' if the entry already existed.
 def adapt_cmake(module_path, check_name_camel):
@@ -30,7 +31,7 @@
   return False
 
   print('Updating %s...' % filename)
-  with open(filename, 'wb') as f:
+  with open(filename, 'w') as f:
 cpp_found = False
 file_added = False
 for line in lines:
@@ -50,7 +51,7 @@
   check_name_dashes = module + '-' + check_name
   filename = os.path.join(module_path, check_name_camel) + '.h'
   print('Creating %s...' % filename)
-  with open(filename, 'wb') as f:
+  with open(filename, 'w') as f:
 header_guard = ('LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_' + module.upper() + '_'
 + check_name_camel.upper() + '_H')
 f.write('//===--- ')
@@ -103,7 +104,7 @@
 def write_implementation(module_path, module, check_name_camel):
   filename = os.path.join(module_path, check_name_camel) + '.cpp'
   print('Creating %s...' % filename)
-  with open(filename, 'wb') as f:
+  with open(filename, 'w') as f:
 f.write('//===--- ')
 f.write(os.path.basename(filename))
 f.write(' - clang-tidy')
@@ -152,14 +153,15 @@
 
 # Modifies the module to include the new check.
 def adapt_module(module_path, module, check_name, check_name_camel):
-  modulecpp = filter(lambda p: p.lower() == module.lower() + 'tidymodule.cpp',
- os.listdir(module_path))[0]
+  modulecpp = list(filter(
+  lambda p: p.lower() == module.lower() + 'tidymodule.cpp',
+  os.listdir(module_path)))[0]
   filename = os.path.join(module_path, modulecpp)
   with open(filename, 'r') as f:
 lines = f.readlines()
 
   print('Updating %s...' % filename)
-  with open(filename, 'wb') as f:
+  with open(filename, 'w') as f:
 header_added = False
 header_found = False
 check_added = False
@@ -199,7 +201,7 @@
 lines = f.readlines()
 
   print('Updating %s...' % filename)
-  with open(filename, 'wb') as f:
+  with open(filename, 'w') as f:
 note_added = False
 header_found = False
 
@@ -227,7 +229,7 @@
   filename = os.path.normpath(os.path.join(module_path, '../../test/clang-tidy',
check_name_dashes + '.' + test_extension))
   print('Creating %s...' % filename)
-  with open(filename, 'wb') as f:
+  with open(filename, 'w') as f:
 f.write("""// RUN: %%check_clang_tidy %%s %(check_name_dashes)s %%t
 
 // FIXME: Add something that triggers the check here.
@@ -251,8 +253,8 @@
   filename = os.path.normpath(os.path.join(docs_dir, 'list.rst'))
   with open(filename, 'r') as f:
 lines = f.readlines()
-  doc_files = filter(lambda s: s.endswith('.rst') and s != 'list.rst',
- os.listdir(docs_dir))
+  doc_files = list(filter(lambda s: s.endswith('.rst') and s != 'list.rst',
+ os.listdir(docs_dir)))
   doc_files.sort()
 
   def format_link(doc_file):
@@ -275,7 +277,7 @@
   checks = map(format_link, doc_files)
 
   print('Updating %s...' % filename)
-  with open(filename, 'wb') as f:
+  with open(filename, 'w') as f:
 for line in lines:
   f.write(line)
   if line.startswith('.. toctree::'):
@@ -289,7 +291,7 @@
   filename = os.path.normpath(os.path.join(
   module_path, '../../docs/clang-tidy/checks/', check_name_dashes + '.rst'))
   print('Creating %s...' % filename)
-  with open(filename, 'wb') as f:
+  with open(filename, 'w') as f:
 f.write(""".. title:: clang-tidy - %(check_name_dashes)s
 
 %(check_name_dashes)s
@@ -333,16 +335,16 @@
 return
 
   if not args.module or not args.check:
-print 'Module and check must be specified.'
+print('Module and check must be specified.')
 parser.print_usage()
 return
 
   module = args.module
   check_name = args.check
 
   if check_name.startswith(module):
-print 'Check name "%s" must not start with the module "%s". Exiting.' % (
-check_name, module)
+print('Check name "%s" must not start with the module "%s". Exiting.' % (
+check_name, module))
 return
   check_name_camel = ''.join(map(lambda elem: elem.capitalize(),
  check_name.split('-'))) + 'Check'
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41517: mmintrin.h documentation fixes and updates

2018-03-08 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon accepted this revision.
RKSimon added a comment.
This revision is now accepted and ready to land.

LGTM - thanks


https://reviews.llvm.org/D41517



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


[PATCH] D43184: [WIP] [ItaniunCXXABI] Add an option for loading the type info vtable with dllimport

2018-03-08 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

Ping @rnk - let me reiterate the questions that are open:

In https://reviews.llvm.org/D43184#1009355, @rnk wrote:

> Here's a case where a local vtable would help:
>
>   struct __declspec(dllimport) A { virtual void a(); };
>   struct __declspec(dllimport) B { virtual void b(); };
>   struct __declspec(dllimport) C : A, B {
> void a() override;
> void b() override;
>   };
>   constexpr C c;
>
>
> I'm suggesting we can make a DSO local copy of _ZTV1C, so that we can refer 
> to it from `c`. It's OK if the vtable refers to the imported thunks, since 
> the address of virtual methods isn't user visible.
>
> Either that, or we need to make something like this change here, right?


Ok, I see - I think this should be doable the way you suggest, but I haven't 
done any further work on that yet. However I unfortunately don't think this can 
solve the class_type_info case at all:

For `__cxxabiv1::__class_type_info`, there's no declaration visible in scope at 
all, and the actual contents of the vtable of this class (and the other similar 
classes) doesn't seem to be defined in the ABI (it seems to differ 
significantly between libc++abi and libsupc++). Or do you have any idea of how 
to work around that as well? We could emit an empty local vtable and try to 
initialize that at runtime by copying from the dllimported real vtable - but I 
guess we don't even know the size of it, when its members are defined by the 
c++abi implementation.

So in case this approach as my hacky PoC does is the only feasible way left, I 
obviously need to fix it up. Any directions and suggestions on how to structure 
it properly? And suggestions for the user visible option, etc?

In https://reviews.llvm.org/D43184#1005281, @smeenai wrote:

> FYI, binutils auto-import actually creates a fake IAT entry rather than using 
> a dynamic initializer. I think it's actually a pretty cute trick. 
> http://blog.omega-prime.co.uk/2011/07/04/everything-you-never-wanted-to-know-about-dlls/#how-auto-import-works
>  has details. That only works when you're referencing an external imported 
> symbol directly though, and breaks when you need an offset from the imported 
> symbol.


Actually, it feels like that blogpost is rather outdated; I can't manage to 
make current binutils produce this form of fixups for the issue at all. What it 
does however, is create a runtime pseudo relocation; the linker generates extra 
info in the rdata section about the relocations it wasn't able to handle, which 
the mingw crt will fix up on startup before handing control over to the end 
user code. This can involve changing the protection of the code sections to 
writeable in order to do such fixups there. (This feature has been in binutils 
since 2002.)


Repository:
  rC Clang

https://reviews.llvm.org/D43184



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


[PATCH] D44247: [clangd] Use identifier range as the definition range.

2018-03-08 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added a comment.

In https://reviews.llvm.org/D44247#1031429, @sammccall wrote:

> In https://reviews.llvm.org/D44247#1031366, @sammccall wrote:
>
> > In https://reviews.llvm.org/D44247#1031345, @malaperle wrote:
> >
> > > I was going to change the symbol index to do the opposite :) The range of 
> > > definitions including the bodies of functions, etc is used in a "peek 
> > > definition" feature by several LSP clients. So for example in VSCode, you 
> > > can hold Ctrl and hover on a function call and see its definition in a 
> > > popup. There was some discussion about this in 
> > > https://reviews.llvm.org/D35894
> >
> >
> > Interesting - that seemed like a more natural interpretation of LSP to me.
> >  Others talked me down, motivated (I think) by nicer behavior of 
> > jump-to-definition... will bring it up again :)
>
>
> Man, this seemed compelling to me, but there's a little bit of wiggle room in 
> the spec (what's the "definition location"), so we looked at the MS language 
> servers...
>  ... and both their TS and C++ implementations return the range of the name 
> only, despite that (IMO) being a weird interpretation of the spec.
>  As for VSCode:
>
> - the "ctrl-to-hover" behavior starts at beginning of the line containing the 
> range, and has a heuristic for when to stop (even if you return the whole 
> definition range, I think). So whole-range is a bit better here (particularly 
> when type/template is on a separate line) but actually still not great.
> - "peek definition" shows the selected range in the middle of a block, with 
> the range highlighted. Having the whole code highlighted actually looks kinda 
> bad :/
> - "go to definition" puts your cursor at the start of the range, and the 
> identifier seems much better here.
>
>   So I *want* to agree, but we'll be fighting the other language servers and 
> editors (and @ioeric, @ilya-biryukov who think we'd be breaking more 
> important workflows)... I think we're actually better off just returning the 
> name.


Good points, thanks for investigating this. I agree that it should return the 
range of the name only so the direction of this patch looks good to me.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44247



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


[PATCH] D16403: Add scope information to CFG

2018-03-08 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In https://reviews.llvm.org/D16403#1031567, @thakis wrote:

> Since this affects analysis-based warnings, have you checked if this patch 
> has any effect on compile times?


Just in case - this is under an analyzer-only flag, so the actual warnings are 
not affected. I guess it might be useful to evaluate compilation time impact 
caused by checking the flag and bailing out, but i doubt it'd be noticeable.


Repository:
  rL LLVM

https://reviews.llvm.org/D16403



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


[PATCH] D41976: Low-hanging fruit optimization in string::__move_assign().

2018-03-08 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

In https://reviews.llvm.org/D41976#1031674, @vsk wrote:

> @mclow.lists is this still fine to commit? I can land it and watch the bots, 
> if you'd like.


Sure. Please do so.


https://reviews.llvm.org/D41976



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


[libclc] r327044 - amdgcn, popcount: Workaround broken llvm.ctpop intrinsic on some GCN ASICs

2018-03-08 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Thu Mar  8 10:58:07 2018
New Revision: 327044

URL: http://llvm.org/viewvc/llvm-project?rev=327044=rev
Log:
amdgcn,popcount: Workaround broken llvm.ctpop intrinsic on some GCN ASICs

This is only really needed for VI+ ASICs. However, llvm would cast the value to
i32 for older asics anyway. The proper fix is in LLVM-7 (r326535).
Fixes CTS popcount on carrizo.

Reviewer: Aaron Watry 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/amdgcn/lib/integer/
libclc/trunk/amdgcn/lib/integer/popcount.cl
libclc/trunk/amdgcn/lib/integer/popcount.inc
Modified:
libclc/trunk/amdgcn/lib/SOURCES

Modified: libclc/trunk/amdgcn/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/amdgcn/lib/SOURCES?rev=327044=327043=327044=diff
==
--- libclc/trunk/amdgcn/lib/SOURCES (original)
+++ libclc/trunk/amdgcn/lib/SOURCES Thu Mar  8 10:58:07 2018
@@ -1,4 +1,5 @@
 cl_khr_int64_extended_atomics/minmax_helpers.ll
+integer/popcount.cl
 math/ldexp.cl
 mem_fence/fence.cl
 synchronization/barrier.cl

Added: libclc/trunk/amdgcn/lib/integer/popcount.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/amdgcn/lib/integer/popcount.cl?rev=327044=auto
==
--- libclc/trunk/amdgcn/lib/integer/popcount.cl (added)
+++ libclc/trunk/amdgcn/lib/integer/popcount.cl Thu Mar  8 10:58:07 2018
@@ -0,0 +1,6 @@
+#include 
+#include 
+#include 
+
+#define __CLC_BODY "popcount.inc"
+#include 

Added: libclc/trunk/amdgcn/lib/integer/popcount.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/amdgcn/lib/integer/popcount.inc?rev=327044=auto
==
--- libclc/trunk/amdgcn/lib/integer/popcount.inc (added)
+++ libclc/trunk/amdgcn/lib/integer/popcount.inc Thu Mar  8 10:58:07 2018
@@ -0,0 +1,17 @@
+_CLC_OVERLOAD _CLC_DEF __CLC_GENTYPE popcount(__CLC_GENTYPE x) {
+/* LLVM-4+ implements i16 ops for VI+ ASICs. However, ctpop implementation
+ * is missing until r326535. Therefore we have to convert sub i32 types to uint
+ * as a workaround. */
+#if __clang_major__ < 7 && __clang_major__ > 3 && __CLC_GENSIZE < 32
+   /* Prevent sign extension on uint conversion */
+   const __CLC_U_GENTYPE y = __CLC_XCONCAT(as_, __CLC_U_GENTYPE)(x);
+   /* Convert to uintX */
+   const __CLC_XCONCAT(uint, __CLC_VECSIZE) z = 
__CLC_XCONCAT(convert_uint, __CLC_VECSIZE)(y);
+   /* Call popcount on uintX type */
+   const __CLC_XCONCAT(uint, __CLC_VECSIZE) res = __clc_native_popcount(z);
+   /* Convert the result back to gentype. */
+   return __CLC_XCONCAT(convert_, __CLC_GENTYPE)(res);
+#else
+   return __clc_native_popcount(x);
+#endif
+}


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


[libclc] r327043 - integer/gentype: Add __CLC_VECSIZE macro

2018-03-08 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Thu Mar  8 10:58:05 2018
New Revision: 327043

URL: http://llvm.org/viewvc/llvm-project?rev=327043=rev
Log:
integer/gentype: Add __CLC_VECSIZE macro

Reviewer: Aaron Watry 
Signed-off-by: Jan Vesely 

Modified:
libclc/trunk/generic/include/clc/integer/gentype.inc

Modified: libclc/trunk/generic/include/clc/integer/gentype.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/integer/gentype.inc?rev=327043=327042=327043=diff
==
--- libclc/trunk/generic/include/clc/integer/gentype.inc (original)
+++ libclc/trunk/generic/include/clc/integer/gentype.inc Thu Mar  8 10:58:05 
2018
@@ -7,7 +7,9 @@
 #define __CLC_U_GENTYPE uchar
 #define __CLC_S_GENTYPE char
 #define __CLC_SCALAR 1
+#define __CLC_VECSIZE
 #include __CLC_BODY
+#undef __CLC_VECSIZE
 #undef __CLC_SCALAR
 #undef __CLC_GENTYPE
 #undef __CLC_U_GENTYPE
@@ -16,7 +18,9 @@
 #define __CLC_GENTYPE char2
 #define __CLC_U_GENTYPE uchar2
 #define __CLC_S_GENTYPE char2
+#define __CLC_VECSIZE 2
 #include __CLC_BODY
+#undef __CLC_VECSIZE
 #undef __CLC_GENTYPE
 #undef __CLC_U_GENTYPE
 #undef __CLC_S_GENTYPE
@@ -24,7 +28,9 @@
 #define __CLC_GENTYPE char3
 #define __CLC_U_GENTYPE uchar3
 #define __CLC_S_GENTYPE char3
+#define __CLC_VECSIZE 3
 #include __CLC_BODY
+#undef __CLC_VECSIZE
 #undef __CLC_GENTYPE
 #undef __CLC_U_GENTYPE
 #undef __CLC_S_GENTYPE
@@ -32,7 +38,9 @@
 #define __CLC_GENTYPE char4
 #define __CLC_U_GENTYPE uchar4
 #define __CLC_S_GENTYPE char4
+#define __CLC_VECSIZE 4
 #include __CLC_BODY
+#undef __CLC_VECSIZE
 #undef __CLC_GENTYPE
 #undef __CLC_U_GENTYPE
 #undef __CLC_S_GENTYPE
@@ -40,7 +48,9 @@
 #define __CLC_GENTYPE char8
 #define __CLC_U_GENTYPE uchar8
 #define __CLC_S_GENTYPE char8
+#define __CLC_VECSIZE 8
 #include __CLC_BODY
+#undef __CLC_VECSIZE
 #undef __CLC_GENTYPE
 #undef __CLC_U_GENTYPE
 #undef __CLC_S_GENTYPE
@@ -48,7 +58,9 @@
 #define __CLC_GENTYPE char16
 #define __CLC_U_GENTYPE uchar16
 #define __CLC_S_GENTYPE char16
+#define __CLC_VECSIZE 16
 #include __CLC_BODY
+#undef __CLC_VECSIZE
 #undef __CLC_GENTYPE
 #undef __CLC_U_GENTYPE
 #undef __CLC_S_GENTYPE
@@ -60,7 +72,9 @@
 #define __CLC_U_GENTYPE uchar
 #define __CLC_S_GENTYPE char
 #define __CLC_SCALAR 1
+#define __CLC_VECSIZE
 #include __CLC_BODY
+#undef __CLC_VECSIZE
 #undef __CLC_SCALAR
 #undef __CLC_GENTYPE
 #undef __CLC_U_GENTYPE
@@ -69,7 +83,9 @@
 #define __CLC_GENTYPE uchar2
 #define __CLC_U_GENTYPE uchar2
 #define __CLC_S_GENTYPE char2
+#define __CLC_VECSIZE 2
 #include __CLC_BODY
+#undef __CLC_VECSIZE
 #undef __CLC_GENTYPE
 #undef __CLC_U_GENTYPE
 #undef __CLC_S_GENTYPE
@@ -77,7 +93,9 @@
 #define __CLC_GENTYPE uchar3
 #define __CLC_U_GENTYPE uchar3
 #define __CLC_S_GENTYPE char3
+#define __CLC_VECSIZE 3
 #include __CLC_BODY
+#undef __CLC_VECSIZE
 #undef __CLC_GENTYPE
 #undef __CLC_U_GENTYPE
 #undef __CLC_S_GENTYPE
@@ -85,7 +103,9 @@
 #define __CLC_GENTYPE uchar4
 #define __CLC_U_GENTYPE uchar4
 #define __CLC_S_GENTYPE char4
+#define __CLC_VECSIZE 4
 #include __CLC_BODY
+#undef __CLC_VECSIZE
 #undef __CLC_GENTYPE
 #undef __CLC_U_GENTYPE
 #undef __CLC_S_GENTYPE
@@ -93,7 +113,9 @@
 #define __CLC_GENTYPE uchar8
 #define __CLC_U_GENTYPE uchar8
 #define __CLC_S_GENTYPE char8
+#define __CLC_VECSIZE 8
 #include __CLC_BODY
+#undef __CLC_VECSIZE
 #undef __CLC_GENTYPE
 #undef __CLC_U_GENTYPE
 #undef __CLC_S_GENTYPE
@@ -101,7 +123,9 @@
 #define __CLC_GENTYPE uchar16
 #define __CLC_U_GENTYPE uchar16
 #define __CLC_S_GENTYPE char16
+#define __CLC_VECSIZE 16
 #include __CLC_BODY
+#undef __CLC_VECSIZE
 #undef __CLC_GENTYPE
 #undef __CLC_U_GENTYPE
 #undef __CLC_S_GENTYPE
@@ -115,7 +139,9 @@
 #define __CLC_U_GENTYPE ushort
 #define __CLC_S_GENTYPE short
 #define __CLC_SCALAR 1
+#define __CLC_VECSIZE
 #include __CLC_BODY
+#undef __CLC_VECSIZE
 #undef __CLC_SCALAR
 #undef __CLC_GENTYPE
 #undef __CLC_U_GENTYPE
@@ -124,7 +150,9 @@
 #define __CLC_GENTYPE short2
 #define __CLC_U_GENTYPE ushort2
 #define __CLC_S_GENTYPE short2
+#define __CLC_VECSIZE 2
 #include __CLC_BODY
+#undef __CLC_VECSIZE
 #undef __CLC_GENTYPE
 #undef __CLC_U_GENTYPE
 #undef __CLC_S_GENTYPE
@@ -132,7 +160,9 @@
 #define __CLC_GENTYPE short3
 #define __CLC_U_GENTYPE ushort3
 #define __CLC_S_GENTYPE short3
+#define __CLC_VECSIZE 3
 #include __CLC_BODY
+#undef __CLC_VECSIZE
 #undef __CLC_GENTYPE
 #undef __CLC_U_GENTYPE
 #undef __CLC_S_GENTYPE
@@ -140,7 +170,9 @@
 #define __CLC_GENTYPE short4
 #define __CLC_U_GENTYPE ushort4
 #define __CLC_S_GENTYPE short4
+#define __CLC_VECSIZE 4
 #include __CLC_BODY
+#undef __CLC_VECSIZE
 #undef __CLC_GENTYPE
 #undef __CLC_U_GENTYPE
 #undef __CLC_S_GENTYPE
@@ -148,7 +180,9 @@
 #define __CLC_GENTYPE short8
 #define __CLC_U_GENTYPE ushort8
 #define __CLC_S_GENTYPE short8
+#define __CLC_VECSIZE 8
 #include __CLC_BODY
+#undef __CLC_VECSIZE
 #undef __CLC_GENTYPE
 #undef __CLC_U_GENTYPE
 #undef __CLC_S_GENTYPE
@@ -156,7 +190,9 @@
 #define 

[libclc] r327042 - popcount: Provide function implementation rather than intrinsic redirect

2018-03-08 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Thu Mar  8 10:58:00 2018
New Revision: 327042

URL: http://llvm.org/viewvc/llvm-project?rev=327042=rev
Log:
popcount: Provide function implementation rather than intrinsic redirect

amdgcn will need to override this

Reviewer: Aaron Watry 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/generic/include/clc/integer/unary.inc
libclc/trunk/generic/include/integer/
libclc/trunk/generic/include/integer/popcount.h
libclc/trunk/generic/include/integer/unary_intrin.inc
  - copied, changed from r326821, 
libclc/trunk/generic/include/clc/integer/unary_intrin.inc
libclc/trunk/generic/lib/clc_unary.inc
libclc/trunk/generic/lib/integer/popcount.cl
Removed:
libclc/trunk/generic/include/clc/integer/unary_intrin.inc
Modified:
libclc/trunk/generic/include/clc/integer/popcount.h
libclc/trunk/generic/lib/SOURCES

Modified: libclc/trunk/generic/include/clc/integer/popcount.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/integer/popcount.h?rev=327042=327041=327042=diff
==
--- libclc/trunk/generic/include/clc/integer/popcount.h (original)
+++ libclc/trunk/generic/include/clc/integer/popcount.h Thu Mar  8 10:58:00 2018
@@ -1,6 +1,5 @@
-#undef popcount
-#define popcount __clc_popcount
-
-#define __CLC_FUNCTION __clc_popcount
-#define __CLC_INTRINSIC "llvm.ctpop"
-#include 
+#define __CLC_FUNCTION popcount
+#define __CLC_BODY 
+#include 
+#undef __CLC_FUNCTION
+#undef __CLC_BODY

Added: libclc/trunk/generic/include/clc/integer/unary.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/integer/unary.inc?rev=327042=auto
==
--- libclc/trunk/generic/include/clc/integer/unary.inc (added)
+++ libclc/trunk/generic/include/clc/integer/unary.inc Thu Mar  8 10:58:00 2018
@@ -0,0 +1 @@
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE x);

Removed: libclc/trunk/generic/include/clc/integer/unary_intrin.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/integer/unary_intrin.inc?rev=327041=auto
==
--- libclc/trunk/generic/include/clc/integer/unary_intrin.inc (original)
+++ libclc/trunk/generic/include/clc/integer/unary_intrin.inc (removed)
@@ -1,20 +0,0 @@
-#define __CLC_INTRINSIC_DEF(SCALAR_TYPE, BIT_SIZE) \
-_CLC_OVERLOAD SCALAR_TYPE __CLC_FUNCTION(SCALAR_TYPE x) __asm(__CLC_INTRINSIC 
".i" BIT_SIZE); \
-_CLC_OVERLOAD SCALAR_TYPE##2 __CLC_FUNCTION(SCALAR_TYPE##2 x) 
__asm(__CLC_INTRINSIC ".v2i" BIT_SIZE); \
-_CLC_OVERLOAD SCALAR_TYPE##3 __CLC_FUNCTION(SCALAR_TYPE##3 x) 
__asm(__CLC_INTRINSIC ".v3i" BIT_SIZE); \
-_CLC_OVERLOAD SCALAR_TYPE##4 __CLC_FUNCTION(SCALAR_TYPE##4 x) 
__asm(__CLC_INTRINSIC ".v4i" BIT_SIZE); \
-_CLC_OVERLOAD SCALAR_TYPE##8 __CLC_FUNCTION(SCALAR_TYPE##8 x) 
__asm(__CLC_INTRINSIC ".v8i" BIT_SIZE); \
-_CLC_OVERLOAD SCALAR_TYPE##16 __CLC_FUNCTION(SCALAR_TYPE##16 x) 
__asm(__CLC_INTRINSIC ".v16i" BIT_SIZE);
-
-__CLC_INTRINSIC_DEF(char, "8")
-__CLC_INTRINSIC_DEF(uchar, "8")
-__CLC_INTRINSIC_DEF(short, "16")
-__CLC_INTRINSIC_DEF(ushort, "16")
-__CLC_INTRINSIC_DEF(int, "32")
-__CLC_INTRINSIC_DEF(uint, "32")
-__CLC_INTRINSIC_DEF(long, "64")
-__CLC_INTRINSIC_DEF(ulong, "64")
-
-#undef __CLC_FUNCTION
-#undef __CLC_INTRINSIC
-#undef __CLC_INTRINSIC_DEF

Added: libclc/trunk/generic/include/integer/popcount.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/integer/popcount.h?rev=327042=auto
==
--- libclc/trunk/generic/include/integer/popcount.h (added)
+++ libclc/trunk/generic/include/integer/popcount.h Thu Mar  8 10:58:00 2018
@@ -0,0 +1,3 @@
+#define __CLC_FUNCTION __clc_native_popcount
+#define __CLC_INTRINSIC "llvm.ctpop"
+#include 

Copied: libclc/trunk/generic/include/integer/unary_intrin.inc (from r326821, 
libclc/trunk/generic/include/clc/integer/unary_intrin.inc)
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/integer/unary_intrin.inc?p2=libclc/trunk/generic/include/integer/unary_intrin.inc=libclc/trunk/generic/include/clc/integer/unary_intrin.inc=326821=327042=327042=diff
==
(empty)

Modified: libclc/trunk/generic/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=327042=327041=327042=diff
==
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Thu Mar  8 10:58:00 2018
@@ -70,6 +70,7 @@ integer/mad24.cl
 integer/mad_sat.cl
 integer/mul24.cl
 integer/mul_hi.cl
+integer/popcount.cl
 integer/rhadd.cl
 integer/rotate.cl
 integer/sub_sat.cl

Added: 

[PATCH] D41976: Low-hanging fruit optimization in string::__move_assign().

2018-03-08 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.
Herald added a subscriber: christof.

@mclow.lists is this still fine to commit? I can land it and watch the bots, if 
you'd like.


https://reviews.llvm.org/D41976



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


[PATCH] D44263: Implement LWG 2221 - No formatted output operator for nullptr

2018-03-08 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists created this revision.
mclow.lists added reviewers: EricWF, dexonsmith.

https://cplusplus.github.io/LWG/issue2221

This is straightforward; I'm putting it up for review because it will add 
symbols to the dylib


https://reviews.llvm.org/D44263

Files:
  include/ostream
  
test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/nullptr.pass.cpp

Index: test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/nullptr.pass.cpp
===
--- test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/nullptr.pass.cpp
+++ test/std/input.output/iostream.format/output.streams/ostream.formatted/ostream.inserters/nullptr.pass.cpp
@@ -0,0 +1,80 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  >
+//   class basic_ostream;
+
+// template
+//   basic_ostream& operator<<(basic_ostream& out, nullptr_t);
+//
+
+#include 
+#include 
+#include "test_macros.h"
+
+template 
+class testbuf
+: public std::basic_streambuf
+{
+typedef std::basic_streambuf base;
+std::basic_string str_;
+public:
+testbuf()
+{
+}
+
+std::basic_string str() const
+{return std::basic_string(base::pbase(), base::pptr());}
+
+protected:
+
+virtual typename base::int_type
+overflow(typename base::int_type ch = base::traits_type::eof())
+{
+if (ch != base::traits_type::eof())
+{
+int n = static_cast(str_.size());
+str_.push_back(ch);
+str_.resize(str_.capacity());
+base::setp(const_cast(str_.data()),
+   const_cast(str_.data() + str_.size()));
+base::pbump(n+1);
+}
+return ch;
+}
+};
+
+int main()
+{
+{
+std::wostream os((std::wstreambuf*)0);
+os << nullptr;
+assert(os.bad());
+assert(os.fail());
+}
+{
+testbuf sb;
+std::ostream os();
+assert(sb.str().length() == 0);
+os << nullptr;
+assert(sb.str().length() > 0);
+LIBCPP_ASSERT(sb.str() == "(nullptr)");  // output is an implementation-defined NTCTS
+}
+
+{
+testbuf sb;
+std::wostream os();
+assert(sb.str().length() == 0);
+os << nullptr;
+assert(sb.str().length() > 0);
+LIBCPP_ASSERT(sb.str() == L"(nullptr)");  // output is an implementation-defined NTCTS
+}
+}
Index: include/ostream
===
--- include/ostream
+++ include/ostream
@@ -56,6 +56,7 @@
 basic_ostream& operator<<(double f);
 basic_ostream& operator<<(long double f);
 basic_ostream& operator<<(const void* p);
+basic_ostream& operator<<(nullptr_t);   // C++17
 basic_ostream& operator<<(basic_streambuf* sb);
 
 // 27.7.2.7 Unformatted output:
@@ -216,6 +217,7 @@
 basic_ostream& operator<<(double __f);
 basic_ostream& operator<<(long double __f);
 basic_ostream& operator<<(const void* __p);
+basic_ostream& operator<<(nullptr_t);
 basic_ostream& operator<<(basic_streambuf* __sb);
 
 // 27.7.2.7 Unformatted output:
@@ -709,6 +711,14 @@
 return *this;
 }
 
+template 
+basic_ostream<_CharT, _Traits>&
+basic_ostream<_CharT, _Traits>::operator<<(nullptr_t)
+{
+	return *this << "(nullptr)";
+}
+
+
 template
 basic_ostream<_CharT, _Traits>&
 __put_character_sequence(basic_ostream<_CharT, _Traits>& __os,
@@ -742,7 +752,6 @@
 return __os;
 }
 
-
 template
 basic_ostream<_CharT, _Traits>&
 operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44231: [clang-tidy] Check for sizeof that call functions

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

In https://reviews.llvm.org/D44231#1031503, @pfultz2 wrote:

> > Can you point to some real world code that would benefit from this check?
>
> Yes, here:
>
> https://github.com/ROCmSoftwarePlatform/MIOpen/blob/master/src/convolution.cpp#L184
>
> It is erroneously calling `sizeof(yDesc.GetType())`. The `GetType` function 
> returns an enum that represents the float type. In this case it wants to 
> compute the size of the float type not the size of the enum that represents 
> the float type. There's actually many instances of this error in the codebase.


Thank you for the example.

>> I don't see this as being a common issue with code and I am concerned about 
>> false positives.
> 
> I have seen it as a common issue. It only runs for a function that returns an 
> integer type. Another possibility is to not warn for function calls that are 
> dependent on a template parameter.
> 
> Of course, there is still the option to disable it.
> 
>> For instance, it's reasonable to write sizeof(func_call()) in a context 
>> where you don't want to repeat the type name in multiple places.
> 
> Generally, a typedef is used to avoid repeating the type.

The typedef doesn't avoid the repeating type.

  uint16_t foo();
  ...
  size_t s1 = sizeof(foo()); // No repeated type
  size_t s2 = sizeof(uint16_t); // Repeated type

If the return type of `foo()` is changed, then the use for `s1` will be 
automatically updated while the use for `s2` will not. Your example of how to 
work around it using `decltype` isn't obvious and won't work for C users.

>> I've seen this construct used in LLVM's code base (see Prologue::getLength() 
>> in DWARFDebugLine.h for one such instance).
> 
> This is the first time I have seen this used legitimately outside of template 
> metaprogramming. Alternatively, you could also write `sizeof(decltype(expr))`.

I think we need some data measurements over several large (>500k LoC) C and C++ 
code bases to see how frequently this check yields false positives. I have a 
hard time imagining that the true positives will outweigh the false positives, 
but without concrete data, it's just guesswork.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44231



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


[PATCH] D41517: mmintrin.h documentation fixes and updates

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

I'm happy.


https://reviews.llvm.org/D41517



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


[PATCH] D43660: [OpenMP] Add OpenMP data sharing infrastructure using global memory

2018-03-08 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.

LG


Repository:
  rC Clang

https://reviews.llvm.org/D43660



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


[PATCH] D43660: [OpenMP] Add OpenMP data sharing infrastructure using global memory

2018-03-08 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 137600.
gtbercea added a comment.

Patch splitting: limit support in this patch to standalone target regions only. 
Support for combined directives will be fully covered in a subsequent patch.


Repository:
  rC Clang

https://reviews.llvm.org/D43660

Files:
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGOpenMPRuntime.h
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  lib/CodeGen/CGOpenMPRuntimeNVPTX.h
  lib/CodeGen/CGStmtOpenMP.cpp
  lib/CodeGen/CodeGenFunction.cpp
  test/OpenMP/nvptx_data_sharing.cpp
  test/OpenMP/nvptx_parallel_codegen.cpp

Index: test/OpenMP/nvptx_parallel_codegen.cpp
===
--- test/OpenMP/nvptx_parallel_codegen.cpp
+++ test/OpenMP/nvptx_parallel_codegen.cpp
@@ -64,254 +64,243 @@
 
   // CHECK-NOT: define {{.*}}void {{@__omp_offloading_.+template.+l17}}_worker()
 
+// CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+template.+l26}}_worker()
+// CHECK-DAG: [[OMP_EXEC_STATUS:%.+]] = alloca i8,
+// CHECK-DAG: [[OMP_WORK_FN:%.+]] = alloca i8*,
+// CHECK: store i8* null, i8** [[OMP_WORK_FN]],
+// CHECK: store i8 0, i8* [[OMP_EXEC_STATUS]],
+// CHECK: br label {{%?}}[[AWAIT_WORK:.+]]
+//
+// CHECK: [[AWAIT_WORK]]
+// CHECK: call void @llvm.nvvm.barrier0()
+// CHECK: [[KPR:%.+]] = call i1 @__kmpc_kernel_parallel(i8** [[OMP_WORK_FN]]
+// CHECK: [[KPRB:%.+]] = zext i1 [[KPR]] to i8
+// store i8 [[KPRB]], i8* [[OMP_EXEC_STATUS]], align 1
+// CHECK: [[WORK:%.+]] = load i8*, i8** [[OMP_WORK_FN]],
+// CHECK: [[SHOULD_EXIT:%.+]] = icmp eq i8* [[WORK]], null
+// CHECK: br i1 [[SHOULD_EXIT]], label {{%?}}[[EXIT:.+]], label {{%?}}[[SEL_WORKERS:.+]]
+//
+// CHECK: [[SEL_WORKERS]]
+// CHECK: [[ST:%.+]] = load i8, i8* [[OMP_EXEC_STATUS]]
+// CHECK: [[IS_ACTIVE:%.+]] = icmp ne i8 [[ST]], 0
+// CHECK: br i1 [[IS_ACTIVE]], label {{%?}}[[EXEC_PARALLEL:.+]], label {{%?}}[[BAR_PARALLEL:.+]]
+//
+// CHECK: [[EXEC_PARALLEL]]
+// CHECK: [[WF1:%.+]] = load i8*, i8** [[OMP_WORK_FN]],
+// CHECK: [[WM1:%.+]] = icmp eq i8* [[WF1]], bitcast (void (i16, i32)* [[PARALLEL_FN1:@.+]]_wrapper to i8*)
+// CHECK: br i1 [[WM1]], label {{%?}}[[EXEC_PFN1:.+]], label {{%?}}[[CHECK_NEXT1:.+]]
+//
+// CHECK: [[EXEC_PFN1]]
+// CHECK: call void [[PARALLEL_FN1]]_wrapper(
+// CHECK: br label {{%?}}[[TERM_PARALLEL:.+]]
+//
+// CHECK: [[CHECK_NEXT1]]
+// CHECK: [[WF2:%.+]] = load i8*, i8** [[OMP_WORK_FN]],
+// CHECK: [[WM2:%.+]] = icmp eq i8* [[WF2]], bitcast (void (i16, i32)* [[PARALLEL_FN2:@.+]]_wrapper to i8*)
+// CHECK: br i1 [[WM2]], label {{%?}}[[EXEC_PFN2:.+]], label {{%?}}[[CHECK_NEXT2:.+]]
+//
+// CHECK: [[EXEC_PFN2]]
+// CHECK: call void [[PARALLEL_FN2]]_wrapper(
+// CHECK: br label {{%?}}[[TERM_PARALLEL:.+]]
+//
+// CHECK: [[CHECK_NEXT2]]
+// CHECK: br label {{%?}}[[TERM_PARALLEL:.+]]
+//
+// CHECK: [[TERM_PARALLEL]]
+// CHECK: call void @__kmpc_kernel_end_parallel()
+// CHECK: br label {{%?}}[[BAR_PARALLEL]]
+//
+// CHECK: [[BAR_PARALLEL]]
+// CHECK: call void @llvm.nvvm.barrier0()
+// CHECK: br label {{%?}}[[AWAIT_WORK]]
+//
+// CHECK: [[EXIT]]
+// CHECK: ret void
 
+// CHECK: define {{.*}}void [[T6:@__omp_offloading_.+template.+l26]](i[[SZ:32|64]]
+// Create local storage for each capture.
+// CHECK:  [[LOCAL_A:%.+]] = alloca i[[SZ]],
+// CHECK-DAG:  store i[[SZ]] [[ARG_A:%.+]], i[[SZ]]* [[LOCAL_A]]
+// Store captures in the context.
+// CHECK-64-DAG:[[REF_A:%.+]] = bitcast i[[SZ]]* [[LOCAL_A]] to i32*
+//
+// CHECK-DAG: [[TID:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
+// CHECK-DAG: [[NTH:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
+// CHECK-DAG: [[WS:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.warpsize()
+// CHECK-DAG: [[TH_LIMIT:%.+]] = sub i32 [[NTH]], [[WS]]
+// CHECK: [[IS_WORKER:%.+]] = icmp ult i32 [[TID]], [[TH_LIMIT]]
+// CHECK: br i1 [[IS_WORKER]], label {{%?}}[[WORKER:.+]], label {{%?}}[[CHECK_MASTER:.+]]
+//
+// CHECK: [[WORKER]]
+// CHECK: {{call|invoke}} void [[T6]]_worker()
+// CHECK: br label {{%?}}[[EXIT:.+]]
+//
+// CHECK: [[CHECK_MASTER]]
+// CHECK-DAG: [[CMTID:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.tid.x()
+// CHECK-DAG: [[CMNTH:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
+// CHECK-DAG: [[CMWS:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.warpsize()
+// CHECK: [[IS_MASTER:%.+]] = icmp eq i32 [[CMTID]],
+// CHECK: br i1 [[IS_MASTER]], label {{%?}}[[MASTER:.+]], label {{%?}}[[EXIT]]
+//
+// CHECK: [[MASTER]]
+// CHECK-DAG: [[MNTH:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.ntid.x()
+// CHECK-DAG: [[MWS:%.+]] = call i32 @llvm.nvvm.read.ptx.sreg.warpsize()
+// CHECK: [[MTMP1:%.+]] = sub i32 [[MNTH]], [[MWS]]
+// CHECK: call void @__kmpc_kernel_init(i32 [[MTMP1]]
+// CHECK: call void @__kmpc_kernel_prepare_parallel(i8* bitcast (void (i16, i32)* [[PARALLEL_FN1]]_wrapper to i8*),
+// CHECK: call void @llvm.nvvm.barrier0()
+// CHECK: call void @llvm.nvvm.barrier0()
+// CHECK: call void @__kmpc_serialized_parallel(
+// CHECK: {{call|invoke}} void [[PARALLEL_FN3:@.+]](
+// 

[PATCH] D36836: [clang-tidy] Implement sonarsource-function-cognitive-complexity check

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

In https://reviews.llvm.org/D36836#1021863, @chandlerc wrote:

> In https://reviews.llvm.org/D36836#931995, @lebedev.ri wrote:
>
> > - Rebased
> > - As advised by @aaron.ballman, moved into it's own directory/module. 
> > Please review that, i'm not entirely sure i have done that fully correctly.
> >
> >   @chandlerc Hi! @aaron.ballman has suggested for me to try to talk to you 
> > about this. Is there some precedent for the licensing 'issue' at hand? Do 
> > you have any opinion? @dberlin did not react to the pings, so i'm not sure 
> > i personally can come up with anything better for `LICENSE.txt`
>
>
> Sadly, what you need here is legal advice for a good way to handle this, and 
> I'm not a lawyer and so I can't really give you that advice.
>
> To be clear, what you currently have isn't OK for several reasons, not least 
> of which what Aaron brought up that this is not in fact a license.
>
> > If there are no further ideas, i'll try to contact sonarsource.
>
> Unless Danny can volunteer his time, we finish with relicensing efforts and 
> can devote the foundation's lawyer's (sadly precious) time to this, I think 
> either you or sonarsource working to understand the best legal way to 
> contribute this would be the best way forward. Sorry that this is a tricky 
> situation. Happy to have a private discussion w/ your or sonarsources's 
> lawyer via my @llvm.org email address if useful.


Mailed and heard back (yay!).
They don't want to take active stance/first steps in this,
but they also did *not* retract that initial 'agreement' i quoted earlier (i 
did ask about that explicitly.).
So nothing is changed so far, this will have to wait until someone can 
volunteer their precious lawyer time.
(Can show the mail exchange if needed.)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D36836



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


[PATCH] D16403: Add scope information to CFG

2018-03-08 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Since this affects analysis-based warnings, have you checked if this patch has 
any effect on compile times?


Repository:
  rL LLVM

https://reviews.llvm.org/D16403



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


[PATCH] D44142: [clangd] Revamp handling of diagnostics.

2018-03-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 137589.
ilya-biryukov marked 9 inline comments as done.
ilya-biryukov added a comment.

This is not final, there are still unadressed comments.

- Significantly simplified the implementation by removing the DiagList, etc.
- Addressed some of the rest of the comments.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44142

Files:
  clangd/CMakeLists.txt
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/Diagnostics.cpp
  clangd/Diagnostics.h
  clangd/SourceCode.cpp
  clangd/SourceCode.h
  clangd/TUScheduler.cpp
  clangd/TUScheduler.h
  test/clangd/diagnostics.test
  test/clangd/execute-command.test
  test/clangd/extra-flags.test
  test/clangd/fixits.test
  unittests/clangd/ClangdTests.cpp
  unittests/clangd/ClangdUnitTests.cpp
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/TUSchedulerTests.cpp
  unittests/clangd/XRefsTests.cpp

Index: unittests/clangd/XRefsTests.cpp
===
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -42,7 +42,7 @@
 
 class IgnoreDiagnostics : public DiagnosticsConsumer {
   void onDiagnosticsReady(
-  PathRef File, Tagged Diagnostics) override {}
+  PathRef File, Tagged Diagnostics) override {}
 };
 
 // FIXME: this is duplicated with FileIndexTests. Share it.
Index: unittests/clangd/TUSchedulerTests.cpp
===
--- unittests/clangd/TUSchedulerTests.cpp
+++ unittests/clangd/TUSchedulerTests.cpp
@@ -21,7 +21,7 @@
 using ::testing::Pair;
 using ::testing::Pointee;
 
-void ignoreUpdate(llvm::Optional) {}
+void ignoreUpdate(llvm::Optional) {}
 void ignoreError(llvm::Error Err) {
   handleAllErrors(std::move(Err), [](const llvm::ErrorInfoBase &) {});
 }
@@ -102,20 +102,20 @@
 /*UpdateDebounce=*/std::chrono::steady_clock::duration::zero());
 auto Path = testPath("foo.cpp");
 S.update(Path, getInputs(Path, ""), WantDiagnostics::Yes,
- [&](std::vector) { Ready.wait(); });
+ [&](std::vector) { Ready.wait(); });
 
 S.update(Path, getInputs(Path, "request diags"), WantDiagnostics::Yes,
- [&](std::vector Diags) { ++CallbackCount; });
+ [&](std::vector Diags) { ++CallbackCount; });
 S.update(Path, getInputs(Path, "auto (clobbered)"), WantDiagnostics::Auto,
- [&](std::vector Diags) {
+ [&](std::vector Diags) {
ADD_FAILURE() << "auto should have been cancelled by auto";
  });
 S.update(Path, getInputs(Path, "request no diags"), WantDiagnostics::No,
- [&](std::vector Diags) {
+ [&](std::vector Diags) {
ADD_FAILURE() << "no diags should not be called back";
  });
 S.update(Path, getInputs(Path, "auto (produces)"), WantDiagnostics::Auto,
- [&](std::vector Diags) { ++CallbackCount; });
+ [&](std::vector Diags) { ++CallbackCount; });
 Ready.notify();
   }
   EXPECT_EQ(2, CallbackCount);
@@ -131,15 +131,15 @@
 // FIXME: we could probably use timeouts lower than 1 second here.
 auto Path = testPath("foo.cpp");
 S.update(Path, getInputs(Path, "auto (debounced)"), WantDiagnostics::Auto,
- [&](std::vector Diags) {
+ [&](std::vector Diags) {
ADD_FAILURE() << "auto should have been debounced and canceled";
  });
 std::this_thread::sleep_for(std::chrono::milliseconds(200));
 S.update(Path, getInputs(Path, "auto (timed out)"), WantDiagnostics::Auto,
- [&](std::vector Diags) { ++CallbackCount; });
+ [&](std::vector Diags) { ++CallbackCount; });
 std::this_thread::sleep_for(std::chrono::seconds(2));
 S.update(Path, getInputs(Path, "auto (shut down)"), WantDiagnostics::Auto,
- [&](std::vector Diags) { ++CallbackCount; });
+ [&](std::vector Diags) { ++CallbackCount; });
   }
   EXPECT_EQ(2, CallbackCount);
 }
@@ -191,7 +191,7 @@
   WithContextValue WithNonce(NonceKey, ++Nonce);
   S.update(File, Inputs, WantDiagnostics::Auto,
[Nonce, , ](
-   llvm::Optional Diags) {
+   llvm::Optional Diags) {
  EXPECT_THAT(Context::current().get(NonceKey),
  Pointee(Nonce));
 
Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -56,13 +56,13 @@
 using ::testing::Contains;
 using ::testing::Each;
 using ::testing::ElementsAre;
+using ::testing::Field;
 using ::testing::Not;
 using ::testing::UnorderedElementsAre;

[PATCH] D44142: [clangd] Revamp handling of diagnostics.

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



Comment at: clangd/ClangdLSPServer.cpp:329
+  {"title",
+   llvm::formatv("Apply FixIt {0}", GetFixitMessage(D.message))},
   {"command", ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND},

sammccall wrote:
> nit: while here, can we add a colon after FixIt (or if appropriate in 
> practice, just drop the prefix altogether?). My recollection is this is a bit 
> hard to parse.
I added a colon for now, but happy to look into removing the prefix. The 
use-case that's slightly confusing is:

```use of undeclared identifier 'foo'. did you mean 'bar'?```
Since the actual fix-it is at the end, it's might be a bit hard to understand.



Comment at: clangd/Diagnostics.cpp:200
+
+  DiagWithFixIts Main = PreBuild(D.main());
+  Main.Diag.message = presentMainMessage(D);

sammccall wrote:
> (nit: if the goal with the callback function is to avoid allocations, 
> shouldn't we reuse the DiagWithFixIts?)
Can we actually avoid allocating some of the strings there?
We're `std::move`ing the result into the callback, so we don't seem to waste 
memory too.



Comment at: clangd/Diagnostics.h:58
+/// by fields of PersistentDiag.
+class DiagList {
+public:

sammccall wrote:
> This is cool :) but really looks like premature optimization.
> Particularly, if the diagnostics were a self-contained value type, this could 
> just be vector I think. And if we care about copying strings (I'm not 
> sure we do), being lifetime-scoped to the ASTcontext is probably OK.
> 
> (rawDiags() has potential uses but having callers explicitly traverse is 
> going to be clearer as your comment suggests)
Using a straight-forward representation for now. 



Comment at: clangd/Diagnostics.h:123
+/// still be included as part of their main diagnostic's message.
+void toLSPDiags(const DiagList ,
+llvm::function_ref OutFn);

sammccall wrote:
> I don't think this overload pays for itself - making callers write the outer 
> loop would be a little clearer, I think.
> 
> (I'd consider having that fn return a smallvector instead of taking a 
> callback, but don't feel strongly)
Still using a callback, but happy to return a `SmallVector` instead. It seems 
the pattern for using `SmallVector` in llvm is passing it in as an output 
parameter (so that the users might decide themselves what's the count of items 
on the stack), which is slightly ugly.
It might be fine to return `SmallVector` here though, this function can 
probably make assumptions about the number of notes in a diagnostic.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44142



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


[PATCH] D41517: mmintrin.h documentation fixes and updates

2018-03-08 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

Any more comments?


https://reviews.llvm.org/D41517



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


[PATCH] D44218: Correct the alignment for the PS4 target

2018-03-08 Thread Matthew Voss via Phabricator via cfe-commits
ormris abandoned this revision.
ormris added a comment.

@echristo accepted this revision via cfe-commits. As it's now commited, I'm 
abandoning this revision.


Repository:
  rC Clang

https://reviews.llvm.org/D44218



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


[PATCH] D44231: [clang-tidy] Check for sizeof that call functions

2018-03-08 Thread Paul Fultz II via Phabricator via cfe-commits
pfultz2 added a comment.

> Can you point to some real world code that would benefit from this check?

Yes, here:

https://github.com/ROCmSoftwarePlatform/MIOpen/blob/master/src/convolution.cpp#L184

It is erroneously calling `sizeof(yDesc.GetType())`. The `GetType` function 
returns an enum that represents the float type. In this case it wants to 
compute the size of the float type not the size of the enum that represents the 
float type. There's actually many instances of this error in the codebase.

> I don't see this as being a common issue with code and I am concerned about 
> false positives.

I have seen it as a common issue. It only runs for a function that returns an 
integer type. Another possibility is to not warn for function calls that are 
dependent on a template parameter.

Of course, there is still the option to disable it.

> For instance, it's reasonable to write sizeof(func_call()) in a context where 
> you don't want to repeat the type name in multiple places.

Generally, a typedef is used to avoid repeating the type.

> I've seen this construct used in LLVM's code base (see Prologue::getLength() 
> in DWARFDebugLine.h for one such instance).

This is the first time I have seen this used legitimately outside of template 
metaprogramming. Alternatively, you could also write `sizeof(decltype(expr))`.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44231



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


[PATCH] D37014: [clang-tidy] Add a checker to remove useless intermediate variables before return statements with comparisons

2018-03-08 Thread Tristan Bourvon via Phabricator via cfe-commits
tbourvon updated this revision to Diff 137588.
tbourvon added a comment.

Moves the custom matcher to the check instead of having it in `utils/Matchers.h`


https://reviews.llvm.org/D37014

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/UnnecessaryIntermediateVarCheck.cpp
  clang-tidy/readability/UnnecessaryIntermediateVarCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-unnecessary-intermediate-var.rst
  test/clang-tidy/readability-unnecessary-intermediate-var.cpp
  unittests/clang-tidy/ReadabilityModuleTest.cpp

Index: unittests/clang-tidy/ReadabilityModuleTest.cpp
===
--- unittests/clang-tidy/ReadabilityModuleTest.cpp
+++ unittests/clang-tidy/ReadabilityModuleTest.cpp
@@ -1,6 +1,8 @@
 #include "ClangTidyTest.h"
 #include "readability/BracesAroundStatementsCheck.h"
 #include "readability/NamespaceCommentCheck.h"
+#include "readability/UnnecessaryIntermediateVarCheck.h"
+#include "../../../unittests/ASTMatchers/ASTMatchersTest.h"
 #include "gtest/gtest.h"
 
 namespace clang {
@@ -500,6 +502,19 @@
 runCheckOnCode(Input));
 }
 
+TEST(StatementMatcher, HasSuccessor) {
+  using namespace ast_matchers;
+  using namespace matchers;
+
+  StatementMatcher DeclHasSuccessorReturnStmt =
+  declStmt(hasSuccessor(returnStmt()));
+
+  EXPECT_TRUE(
+  matches("void foo() { int bar; return; }", DeclHasSuccessorReturnStmt));
+  EXPECT_TRUE(notMatches("void foo() { int bar; bar++; return; }",
+ DeclHasSuccessorReturnStmt));
+}
+
 } // namespace test
 } // namespace tidy
 } // namespace clang
Index: test/clang-tidy/readability-unnecessary-intermediate-var.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-unnecessary-intermediate-var.cpp
@@ -0,0 +1,245 @@
+// RUN: %check_clang_tidy %s readability-unnecessary-intermediate-var %t
+
+bool f() {
+  auto test = 1; // Test
+  // CHECK-FIXES: {{^}}  // Test{{$}}
+  return (test == 1);
+  // CHECK-FIXES: {{^}}  return (1 == 1);{{$}}
+  // CHECK-MESSAGES: :[[@LINE-4]]:8: warning: unnecessary intermediate variable 'test' [readability-unnecessary-intermediate-var]
+  // CHECK-MESSAGES: :[[@LINE-3]]:11: note: because it is only used when returning the result of this comparison
+  // CHECK-MESSAGES: :[[@LINE-6]]:8: note: consider removing the variable declaration
+  // CHECK-MESSAGES: :[[@LINE-5]]:11: note: and directly using the variable initialization expression here
+}
+
+bool f2() {
+  auto test1 = 1; // Test1
+  // CHECK-FIXES: {{^}}  // Test1{{$}}
+  auto test2 = 2; // Test2
+  // CHECK-FIXES: {{^}}  // Test2{{$}}
+  return (test1 == test2);
+  // CHECK-FIXES: {{^}}  return (1 == 2);{{$}}
+  // CHECK-MESSAGES: :[[@LINE-6]]:8: warning: unnecessary intermediate variable 'test1' [readability-unnecessary-intermediate-var]
+  // CHECK-MESSAGES: :[[@LINE-5]]:8: warning: and so is 'test2' [readability-unnecessary-intermediate-var]
+  // CHECK-MESSAGES: :[[@LINE-4]]:11: note: because they are only used when returning the result of this comparison
+  // CHECK-MESSAGES: :[[@LINE-9]]:8: note: consider removing both this variable declaration
+  // CHECK-MESSAGES: :[[@LINE-8]]:8: note: and this one
+  // CHECK-MESSAGES: :[[@LINE-7]]:11: note: and directly using the variable initialization expressions here
+}
+
+bool f3() {
+  auto test1 = 1; // Test1
+  // CHECK-FIXES: {{^}}  // Test1{{$}}
+  auto test2 = 2; // Test2
+  return (test1 == 2);
+  // CHECK-FIXES: {{^}}  return (1 == 2);{{$}}
+  // CHECK-MESSAGES: :[[@LINE-5]]:8: warning: unnecessary intermediate variable 'test1' [readability-unnecessary-intermediate-var]
+  // CHECK-MESSAGES: :[[@LINE-3]]:11: note: because it is only used when returning the result of this comparison
+  // CHECK-MESSAGES: :[[@LINE-7]]:8: note: consider removing the variable declaration
+  // CHECK-MESSAGES: :[[@LINE-5]]:11: note: and directly using the variable initialization expression here
+}
+
+bool f4() {
+  auto test1 = 1; // Test1
+  auto test2 = 2; // Test2
+  // CHECK-FIXES: {{^}}  // Test2{{$}}
+  return (test2 == 3);
+  // CHECK-FIXES: {{^}}  return (2 == 3);{{$}}
+  // CHECK-MESSAGES: :[[@LINE-4]]:8: warning: unnecessary intermediate variable 'test2' [readability-unnecessary-intermediate-var]
+  // CHECK-MESSAGES: :[[@LINE-3]]:11: note: because it is only used when returning the result of this comparison
+  // CHECK-MESSAGES: :[[@LINE-6]]:8: note: consider removing the variable declaration
+  // CHECK-MESSAGES: :[[@LINE-5]]:11: note: and directly using the variable initialization expression here
+}
+
+bool f5() {
+  auto test1 = 1; // Test1
+  // CHECK-FIXES: {{^}}  // Test1{{$}}
+  auto test2 = 2; // Test2
+  return (2 == test1);
+  // CHECK-FIXES: {{^}}  return (1 == 2);{{$}}
+  // CHECK-MESSAGES: :[[@LINE-5]]:8: warning: unnecessary intermediate 

[PATCH] D44226: [clangd] Add -log-lsp-to-stderr option

2018-03-08 Thread Simon Marchi via Phabricator via cfe-commits
simark marked 2 inline comments as done.
simark added inline comments.



Comment at: clangd/tool/ClangdMain.cpp:79
 
+static llvm::cl::opt Verbose("verbose", llvm::cl::desc("Be more 
verbose"),
+   llvm::cl::init(false));

ilya-biryukov wrote:
> simark wrote:
> > ilya-biryukov wrote:
> > > Maybe just call it `-v`?
> > I would have like to add both "-v" and "-verbose", but it doesn't seem 
> > possible to have two flags for the same option.  "-v" it is then, it is 
> > quite standard.
> I would go with having just `-v` with no aliases.
> 
> But this should do the trick if you prefer to have `-verbose` as an option:
> ```
> llvm::cl::opt Verbose("v", llvm::cl::alias("verbose") , //
> ```
Ah ok thanks for the info.  I'll leave it with just `-v` here, but knowing this 
could be handy in the future.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44226



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


[PATCH] D44226: [clangd] Add -log-lsp-to-stderr option

2018-03-08 Thread Simon Marchi via Phabricator via cfe-commits
simark updated this revision to Diff 137582.
simark added a comment.

Update

- Add vlog method to Logger interface
- Add method name to "method not found" error message


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44226

Files:
  clangd/ClangdLSPServer.cpp
  clangd/JSONRPCDispatcher.cpp
  clangd/JSONRPCDispatcher.h
  clangd/Logger.cpp
  clangd/Logger.h
  clangd/ProtocolHandlers.cpp
  clangd/tool/ClangdMain.cpp
  test/clangd/unsupported-method.test

Index: test/clangd/unsupported-method.test
===
--- test/clangd/unsupported-method.test
+++ test/clangd/unsupported-method.test
@@ -6,7 +6,7 @@
 {"jsonrpc":"2.0","id":1,"method":"textDocument/jumpInTheAirLikeYouJustDontCare","params":{}}
 #  CHECK:  "error": {
 # CHECK-NEXT:"code": -32601,
-# CHECK-NEXT:"message": "method not found"
+# CHECK-NEXT:"message": "method not found (textDocument/jumpInTheAirLikeYouJustDontCare)"
 # CHECK-NEXT:  },
 # CHECK-NEXT:  "id": 1,
 # CHECK-NEXT:  "jsonrpc": "2.0"
Index: clangd/tool/ClangdMain.cpp
===
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -76,6 +76,9 @@
"messages delimited by --- lines, with # comment support")),
 llvm::cl::init(JSONStreamStyle::Standard));
 
+static llvm::cl::opt Verbose("v", llvm::cl::desc("Be more verbose"),
+   llvm::cl::init(false));
+
 static llvm::cl::opt
 PrettyPrint("pretty", llvm::cl::desc("Pretty-print JSON output"),
 llvm::cl::init(false));
@@ -190,9 +193,9 @@
 
   JSONOutput Out(llvm::outs(), llvm::errs(),
  InputMirrorStream ? InputMirrorStream.getPointer() : nullptr,
- PrettyPrint);
+ PrettyPrint, Verbose);
 
-  clangd::LoggingSession LoggingSession(Out);
+  clangd::LoggingSession LoggingSession(Out, Verbose);
 
   // If --compile-commands-dir arg was invoked, check value and override default
   // path.
Index: clangd/ProtocolHandlers.cpp
===
--- clangd/ProtocolHandlers.cpp
+++ clangd/ProtocolHandlers.cpp
@@ -27,14 +27,15 @@
   void operator()(StringRef Method, void (ProtocolCallbacks::*Handler)(Param)) {
 // Capture pointers by value, as the lambda will outlive this object.
 auto *Callbacks = this->Callbacks;
-Dispatcher.registerHandler(Method, [=](const json::Expr ) {
-  typename std::remove_reference::type P;
-  if (fromJSON(RawParams, P)) {
-(Callbacks->*Handler)(P);
-  } else {
-log("Failed to decode " + Method + " request.");
-  }
-});
+Dispatcher.registerHandler(
+Method, [=](StringRef Method, const json::Expr ) {
+  typename std::remove_reference::type P;
+  if (fromJSON(RawParams, P)) {
+(Callbacks->*Handler)(P);
+  } else {
+log("Failed to decode " + Method + " request.");
+  }
+});
   }
 
   JSONRPCDispatcher 
Index: clangd/Logger.h
===
--- clangd/Logger.h
+++ clangd/Logger.h
@@ -15,24 +15,28 @@
 namespace clang {
 namespace clangd {
 
-/// Main logging function.
+/// Main logging functions.
 /// Logs messages to a global logger, which can be set up by LoggingSesssion.
 /// If no logger is registered, writes to llvm::errs().
 void log(const llvm::Twine );
 
+/// Same as the above, but for verbose messages.
+void vlog(const llvm::Twine );
+
 /// Interface to allow custom logging in clangd.
 class Logger {
 public:
   virtual ~Logger() = default;
 
-  /// Implementations of this method must be thread-safe.
+  /// Implementations of these methods must be thread-safe.
   virtual void log(const llvm::Twine ) = 0;
+  virtual void vlog(const llvm::Twine ) = 0;
 };
 
 /// Only one LoggingSession can be active at a time.
 class LoggingSession {
 public:
-  LoggingSession(clangd::Logger );
+  LoggingSession(clangd::Logger , bool Verbose);
   ~LoggingSession();
 
   LoggingSession(LoggingSession &&) = delete;
Index: clangd/Logger.cpp
===
--- clangd/Logger.cpp
+++ clangd/Logger.cpp
@@ -16,11 +16,14 @@
 
 namespace {
 Logger *L = nullptr;
+bool Verbose_ = false;
+
 } // namespace
 
-LoggingSession::LoggingSession(clangd::Logger ) {
+LoggingSession::LoggingSession(clangd::Logger , bool Verbose) {
   assert(!L);
   L = 
+  Verbose_ = Verbose;
 }
 
 LoggingSession::~LoggingSession() { L = nullptr; }
@@ -35,5 +38,12 @@
   }
 }
 
+void vlog(const llvm::Twine ) {
+  if (L)
+L->vlog(Message);
+  else
+log(Message);
+}
+
 } // namespace clangd
 } // namespace clang
Index: clangd/JSONRPCDispatcher.h
===
--- clangd/JSONRPCDispatcher.h
+++ clangd/JSONRPCDispatcher.h
@@ -30,14 +30,17 @@
   // JSONOutput now that we pass 

[PATCH] D44226: [clangd] Add -log-lsp-to-stderr option

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



Comment at: clangd/Logger.cpp:19
 Logger *L = nullptr;
+bool Verbose_ = false;
 } // namespace

simark wrote:
> ilya-biryukov wrote:
> > Could we move the flag to implementation of `Logger`?
> > I.e.:
> > ```
> > class Logger {
> >   virtual log(const llvm::Twine , bool Verbose);
> > };
> > 
> > // Implementation of top-level log
> > void clangd::log(const llvm::Twine ) {
> >L->log(Message, /*Verbose=*/false);
> >// should also handle missing Logger by logging into llvm::errs()
> > }
> > 
> > // Implementation of top-level vlog.
> > void clangd::vlog(const llvm::Twine ) {
> >L->log(Message, /*Verbose=*/true);
> >// should also handle missing Logger by logging into llvm::errs()
> > }
> > ```
> > 
> > An implementation of the interface would decide whether to log or not, 
> > based on command-line argument.
> That's what I thought of doing first.  The issue is that if we don't set a 
> logger with LoggingSession, the log function prints to stderr itself.  So if 
> we don't check the Verbose flag there, the -v flag will have no effect when 
> LoggingSession has not been called (I don't know if it's really a problem or 
> not, since in practice we call it).
It shouldn't be a problem.
We're only missing `LoggingSession` in tests, so let's just print messages from 
`vlog` into `stderr` in the same way we do it with `log` now.



Comment at: clangd/tool/ClangdMain.cpp:79
 
+static llvm::cl::opt Verbose("verbose", llvm::cl::desc("Be more 
verbose"),
+   llvm::cl::init(false));

simark wrote:
> ilya-biryukov wrote:
> > Maybe just call it `-v`?
> I would have like to add both "-v" and "-verbose", but it doesn't seem 
> possible to have two flags for the same option.  "-v" it is then, it is quite 
> standard.
I would go with having just `-v` with no aliases.

But this should do the trick if you prefer to have `-verbose` as an option:
```
llvm::cl::opt Verbose("v", llvm::cl::alias("verbose") , //
```


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44226



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


[PATCH] D44251: [clangd] Early return for #include goto definition.

2018-03-08 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE327023: [clangd] Early return for #include goto 
definition. (authored by hokein, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D44251?vs=137559=137581#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44251

Files:
  clangd/XRefs.cpp


Index: clangd/XRefs.cpp
===
--- clangd/XRefs.cpp
+++ clangd/XRefs.cpp
@@ -174,6 +174,18 @@
 
   SourceLocation SourceLocationBeg = getBeginningOfIdentifier(AST, Pos, FE);
 
+  std::vector Result;
+  // Handle goto definition for #include.
+  for (auto  : AST.getInclusionLocations()) {
+Range R = IncludeLoc.first;
+Position Pos = sourceLocToPosition(SourceMgr, SourceLocationBeg);
+
+if (R.contains(Pos))
+  Result.push_back(Location{URIForFile{IncludeLoc.second}, {}});
+  }
+  if (!Result.empty())
+return Result;
+
   auto DeclMacrosFinder = std::make_shared(
   llvm::errs(), SourceLocationBeg, AST.getASTContext(),
   AST.getPreprocessor());
@@ -187,7 +199,6 @@
 
   std::vector Decls = DeclMacrosFinder->takeDecls();
   std::vector MacroInfos = DeclMacrosFinder->takeMacroInfos();
-  std::vector Result;
 
   for (auto Item : Decls) {
 auto L = getDeclarationLocation(AST, Item->getSourceRange());
@@ -203,15 +214,6 @@
   Result.push_back(*L);
   }
 
-  /// Process targets for paths inside #include directive.
-  for (auto  : AST.getInclusionLocations()) {
-Range R = IncludeLoc.first;
-Position Pos = sourceLocToPosition(SourceMgr, SourceLocationBeg);
-
-if (R.contains(Pos))
-  Result.push_back(Location{URIForFile{IncludeLoc.second}, {}});
-  }
-
   return Result;
 }
 


Index: clangd/XRefs.cpp
===
--- clangd/XRefs.cpp
+++ clangd/XRefs.cpp
@@ -174,6 +174,18 @@
 
   SourceLocation SourceLocationBeg = getBeginningOfIdentifier(AST, Pos, FE);
 
+  std::vector Result;
+  // Handle goto definition for #include.
+  for (auto  : AST.getInclusionLocations()) {
+Range R = IncludeLoc.first;
+Position Pos = sourceLocToPosition(SourceMgr, SourceLocationBeg);
+
+if (R.contains(Pos))
+  Result.push_back(Location{URIForFile{IncludeLoc.second}, {}});
+  }
+  if (!Result.empty())
+return Result;
+
   auto DeclMacrosFinder = std::make_shared(
   llvm::errs(), SourceLocationBeg, AST.getASTContext(),
   AST.getPreprocessor());
@@ -187,7 +199,6 @@
 
   std::vector Decls = DeclMacrosFinder->takeDecls();
   std::vector MacroInfos = DeclMacrosFinder->takeMacroInfos();
-  std::vector Result;
 
   for (auto Item : Decls) {
 auto L = getDeclarationLocation(AST, Item->getSourceRange());
@@ -203,15 +214,6 @@
   Result.push_back(*L);
   }
 
-  /// Process targets for paths inside #include directive.
-  for (auto  : AST.getInclusionLocations()) {
-Range R = IncludeLoc.first;
-Position Pos = sourceLocToPosition(SourceMgr, SourceLocationBeg);
-
-if (R.contains(Pos))
-  Result.push_back(Location{URIForFile{IncludeLoc.second}, {}});
-  }
-
   return Result;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44251: [clangd] Early return for #include goto definition.

2018-03-08 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL327023: [clangd] Early return for #include goto definition. 
(authored by hokein, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D44251

Files:
  clang-tools-extra/trunk/clangd/XRefs.cpp


Index: clang-tools-extra/trunk/clangd/XRefs.cpp
===
--- clang-tools-extra/trunk/clangd/XRefs.cpp
+++ clang-tools-extra/trunk/clangd/XRefs.cpp
@@ -174,6 +174,18 @@
 
   SourceLocation SourceLocationBeg = getBeginningOfIdentifier(AST, Pos, FE);
 
+  std::vector Result;
+  // Handle goto definition for #include.
+  for (auto  : AST.getInclusionLocations()) {
+Range R = IncludeLoc.first;
+Position Pos = sourceLocToPosition(SourceMgr, SourceLocationBeg);
+
+if (R.contains(Pos))
+  Result.push_back(Location{URIForFile{IncludeLoc.second}, {}});
+  }
+  if (!Result.empty())
+return Result;
+
   auto DeclMacrosFinder = std::make_shared(
   llvm::errs(), SourceLocationBeg, AST.getASTContext(),
   AST.getPreprocessor());
@@ -187,7 +199,6 @@
 
   std::vector Decls = DeclMacrosFinder->takeDecls();
   std::vector MacroInfos = DeclMacrosFinder->takeMacroInfos();
-  std::vector Result;
 
   for (auto Item : Decls) {
 auto L = getDeclarationLocation(AST, Item->getSourceRange());
@@ -203,15 +214,6 @@
   Result.push_back(*L);
   }
 
-  /// Process targets for paths inside #include directive.
-  for (auto  : AST.getInclusionLocations()) {
-Range R = IncludeLoc.first;
-Position Pos = sourceLocToPosition(SourceMgr, SourceLocationBeg);
-
-if (R.contains(Pos))
-  Result.push_back(Location{URIForFile{IncludeLoc.second}, {}});
-  }
-
   return Result;
 }
 


Index: clang-tools-extra/trunk/clangd/XRefs.cpp
===
--- clang-tools-extra/trunk/clangd/XRefs.cpp
+++ clang-tools-extra/trunk/clangd/XRefs.cpp
@@ -174,6 +174,18 @@
 
   SourceLocation SourceLocationBeg = getBeginningOfIdentifier(AST, Pos, FE);
 
+  std::vector Result;
+  // Handle goto definition for #include.
+  for (auto  : AST.getInclusionLocations()) {
+Range R = IncludeLoc.first;
+Position Pos = sourceLocToPosition(SourceMgr, SourceLocationBeg);
+
+if (R.contains(Pos))
+  Result.push_back(Location{URIForFile{IncludeLoc.second}, {}});
+  }
+  if (!Result.empty())
+return Result;
+
   auto DeclMacrosFinder = std::make_shared(
   llvm::errs(), SourceLocationBeg, AST.getASTContext(),
   AST.getPreprocessor());
@@ -187,7 +199,6 @@
 
   std::vector Decls = DeclMacrosFinder->takeDecls();
   std::vector MacroInfos = DeclMacrosFinder->takeMacroInfos();
-  std::vector Result;
 
   for (auto Item : Decls) {
 auto L = getDeclarationLocation(AST, Item->getSourceRange());
@@ -203,15 +214,6 @@
   Result.push_back(*L);
   }
 
-  /// Process targets for paths inside #include directive.
-  for (auto  : AST.getInclusionLocations()) {
-Range R = IncludeLoc.first;
-Position Pos = sourceLocToPosition(SourceMgr, SourceLocationBeg);
-
-if (R.contains(Pos))
-  Result.push_back(Location{URIForFile{IncludeLoc.second}, {}});
-  }
-
   return Result;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r327023 - [clangd] Early return for #include goto definition.

2018-03-08 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Thu Mar  8 08:28:12 2018
New Revision: 327023

URL: http://llvm.org/viewvc/llvm-project?rev=327023=rev
Log:
[clangd] Early return for #include goto definition.

Summary: This would save cost of walking over the AST, NFC.

Reviewers: ilya-biryukov

Subscribers: klimek, jkorous-apple, cfe-commits, ioeric

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

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

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=327023=327022=327023=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Thu Mar  8 08:28:12 2018
@@ -174,6 +174,18 @@ std::vector findDefinitions(Pa
 
   SourceLocation SourceLocationBeg = getBeginningOfIdentifier(AST, Pos, FE);
 
+  std::vector Result;
+  // Handle goto definition for #include.
+  for (auto  : AST.getInclusionLocations()) {
+Range R = IncludeLoc.first;
+Position Pos = sourceLocToPosition(SourceMgr, SourceLocationBeg);
+
+if (R.contains(Pos))
+  Result.push_back(Location{URIForFile{IncludeLoc.second}, {}});
+  }
+  if (!Result.empty())
+return Result;
+
   auto DeclMacrosFinder = std::make_shared(
   llvm::errs(), SourceLocationBeg, AST.getASTContext(),
   AST.getPreprocessor());
@@ -187,7 +199,6 @@ std::vector findDefinitions(Pa
 
   std::vector Decls = DeclMacrosFinder->takeDecls();
   std::vector MacroInfos = DeclMacrosFinder->takeMacroInfos();
-  std::vector Result;
 
   for (auto Item : Decls) {
 auto L = getDeclarationLocation(AST, Item->getSourceRange());
@@ -203,15 +214,6 @@ std::vector findDefinitions(Pa
   Result.push_back(*L);
   }
 
-  /// Process targets for paths inside #include directive.
-  for (auto  : AST.getInclusionLocations()) {
-Range R = IncludeLoc.first;
-Position Pos = sourceLocToPosition(SourceMgr, SourceLocationBeg);
-
-if (R.contains(Pos))
-  Result.push_back(Location{URIForFile{IncludeLoc.second}, {}});
-  }
-
   return Result;
 }
 


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


[PATCH] D44226: [clangd] Add -log-lsp-to-stderr option

2018-03-08 Thread Simon Marchi via Phabricator via cfe-commits
simark added inline comments.



Comment at: clangd/tool/ClangdMain.cpp:79
 
+static llvm::cl::opt Verbose("verbose", llvm::cl::desc("Be more 
verbose"),
+   llvm::cl::init(false));

ilya-biryukov wrote:
> Maybe just call it `-v`?
I would have like to add both "-v" and "-verbose", but it doesn't seem possible 
to have two flags for the same option.  "-v" it is then, it is quite standard.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44226



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


[PATCH] D44226: [clangd] Add -log-lsp-to-stderr option

2018-03-08 Thread Simon Marchi via Phabricator via cfe-commits
simark marked an inline comment as done.
simark added inline comments.



Comment at: clangd/Logger.cpp:19
 Logger *L = nullptr;
+bool Verbose_ = false;
 } // namespace

ilya-biryukov wrote:
> Could we move the flag to implementation of `Logger`?
> I.e.:
> ```
> class Logger {
>   virtual log(const llvm::Twine , bool Verbose);
> };
> 
> // Implementation of top-level log
> void clangd::log(const llvm::Twine ) {
>L->log(Message, /*Verbose=*/false);
>// should also handle missing Logger by logging into llvm::errs()
> }
> 
> // Implementation of top-level vlog.
> void clangd::vlog(const llvm::Twine ) {
>L->log(Message, /*Verbose=*/true);
>// should also handle missing Logger by logging into llvm::errs()
> }
> ```
> 
> An implementation of the interface would decide whether to log or not, based 
> on command-line argument.
That's what I thought of doing first.  The issue is that if we don't set a 
logger with LoggingSession, the log function prints to stderr itself.  So if we 
don't check the Verbose flag there, the -v flag will have no effect when 
LoggingSession has not been called (I don't know if it's really a problem or 
not, since in practice we call it).


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44226



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


[PATCH] D44093: [BUILTINS] structure pretty printer

2018-03-08 Thread Paul Semel via Phabricator via cfe-commits
paulsemel updated this revision to Diff 137578.
paulsemel marked 3 inline comments as done.
paulsemel added a comment.

Applied Aaron suggestions


Repository:
  rC Clang

https://reviews.llvm.org/D44093

Files:
  include/clang/Basic/Builtins.def
  lib/CodeGen/CGBuiltin.cpp
  lib/Sema/SemaChecking.cpp

Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -1110,6 +1110,66 @@
 // so ensure that they are declared.
 DeclareGlobalNewDelete();
 break;
+  case Builtin::BI__builtin_dump_struct: {
+// We first want to ensure we are called with 2 arguments
+if (checkArgCount(*this, TheCall, 2))
+  return ExprError();
+// Ensure that the first argument is of type 'struct XX *'
+const Expr *PtrArg = TheCall->getArg(0)->IgnoreParenImpCasts();
+const QualType PtrArgType = PtrArg->getType();
+if (!PtrArgType->isPointerType()) {
+  this->Diag(PtrArg->getLocStart(), diag::err_typecheck_convert_incompatible)
+<< PtrArgType << "\'structure pointer type\'"
+<< 1 << 0 << 3 << 1
+<< PtrArgType << "\'structure pointer type\'";
+  return ExprError();
+}
+
+const RecordType *RT = PtrArgType->getPointeeType()->getAs();
+if (!RT) {
+  this->Diag(PtrArg->getLocStart(), diag::err_typecheck_convert_incompatible)
+<< PtrArgType << "\'structure pointer type\'"
+<< 1 << 0 << 3 << 1
+<< PtrArgType << "\'structure pointer type\'";
+  return ExprError();
+}
+// Ensure that the second argument is of type 'FunctionType'
+const Expr *FnPtrArg = TheCall->getArg(1)->IgnoreImpCasts();
+const QualType FnPtrArgType = FnPtrArg->getType();
+if (!FnPtrArgType->isPointerType()) {
+  this->Diag(FnPtrArg->getLocStart(), diag::err_typecheck_convert_incompatible)
+<< FnPtrArgType << "\'int (*)(const char *, ...)\'"
+<< 1 << 0 << 3 << 2
+<< FnPtrArgType << "\'int (*)(const char *, ...)\'";
+  return ExprError();
+}
+
+const FunctionType *FuncType =
+  FnPtrArgType->getPointeeType()->getAs();
+
+if (!FuncType) {
+  this->Diag(FnPtrArg->getLocStart(), diag::err_typecheck_convert_incompatible)
+<< FnPtrArgType << "\'int (*)(const char *, ...)\'"
+<< 1 << 0 << 3 << 2
+<< FnPtrArgType << "\'int (*)(const char *, ...)\'";
+  return ExprError();
+}
+
+const FunctionProtoType *FT = dyn_cast(FuncType);
+if (FT) {
+  if (!FT->isVariadic() ||
+  FT->getReturnType() != Context.IntTy) {
+  this->Diag(FnPtrArg->getLocStart(), diag::err_typecheck_convert_incompatible)
+<< FnPtrArgType<< "\'int (*)(const char *, ...)\'"
+<< 1 << 0 << 3 << 2
+<< FnPtrArgType << "\'int (*)(const char *, ...)\'";
+return ExprError();
+  }
+}
+
+TheCall->setType(Context.IntTy);
+break;
+  }
 
   // check secure string manipulation functions where overflows
   // are detectable at compile time
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -14,6 +14,7 @@
 #include "CGCXXABI.h"
 #include "CGObjCRuntime.h"
 #include "CGOpenCLRuntime.h"
+#include "CGRecordLayout.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "ConstantEmitter.h"
@@ -1196,6 +1197,84 @@
 return RValue::get(ComplexVal.first);
   }
 
+  case Builtin::BI__builtin_dump_struct: {
+Value *Func = EmitScalarExpr(E->getArg(1)->IgnoreImpCasts());
+CharUnits Arg0Align = EmitPointerWithAlignment(E->getArg(0)).getAlignment();
+
+const Expr *Arg0 = E->getArg(0)->IgnoreImpCasts();
+QualType Arg0Type = Arg0->getType()->getPointeeType();
+const RecordType *RT = Arg0Type->getAs();
+
+RecordDecl *RD = RT->getDecl()->getDefinition();
+ASTContext  = RD->getASTContext();
+const ASTRecordLayout  = Ctx.getASTRecordLayout(RD);
+
+Value *GString = Builder.CreateGlobalStringPtr(Arg0Type.getAsString()
+   + " {\n");
+Value *Res = Builder.CreateCall(Func, {GString});
+
+static llvm::DenseMap Types;
+if (Types.empty()) {
+  Types[getContext().CharTy] = "%c";
+  Types[getContext().BoolTy] = "%d";
+  Types[getContext().IntTy] = "%d";
+  Types[getContext().UnsignedIntTy] = "%u";
+  Types[getContext().LongTy] = "%ld";
+  Types[getContext().UnsignedLongTy] = "%lu";
+  Types[getContext().LongLongTy] = "%lld";
+  Types[getContext().UnsignedLongLongTy] = "%llu";
+  Types[getContext().ShortTy] = "%hd";
+  Types[getContext().UnsignedShortTy] = "%hu";
+  Types[getContext().VoidPtrTy] = "%p";
+  Types[getContext().FloatTy] = "%f";
+  Types[getContext().DoubleTy] = "%f";
+  Types[getContext().LongDoubleTy] = "%Lf";
+  

[PATCH] D44247: [clangd] Use identifier range as the definition range.

2018-03-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In https://reviews.llvm.org/D44247#1031366, @sammccall wrote:

> In https://reviews.llvm.org/D44247#1031345, @malaperle wrote:
>
> > I was going to change the symbol index to do the opposite :) The range of 
> > definitions including the bodies of functions, etc is used in a "peek 
> > definition" feature by several LSP clients. So for example in VSCode, you 
> > can hold Ctrl and hover on a function call and see its definition in a 
> > popup. There was some discussion about this in 
> > https://reviews.llvm.org/D35894
>
>
> Interesting - that seemed like a more natural interpretation of LSP to me.
>  Others talked me down, motivated (I think) by nicer behavior of 
> jump-to-definition... will bring it up again :)


Man, this seemed compelling to me, but there's a little bit of wiggle room in 
the spec (what's the "definition location"), so we looked at the MS language 
servers...
... and both their TS and C++ implementations return the range of the name 
only, despite that (IMO) being a weird interpretation of the spec.
As for VSCode:

- the "ctrl-to-hover" behavior starts at beginning of the line containing the 
range, and has a heuristic for when to stop (even if you return the whole 
definition range, I think). So whole-range is a bit better here (particularly 
when type/template is on a separate line) but actually still not great.
- "peek definition" shows the selected range in the middle of a block, with the 
range highlighted. Having the whole code highlighted actually looks kinda bad :/
- "go to definition" puts your cursor at the start of the range, and the 
identifier seems much better here.

So I *want* to agree, but we'll be fighting the other language servers and 
editors (and @ioeric, @ilya-biryukov who think we'd be breaking more important 
workflows)... I think we're actually better off just returning the name.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44247



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


[clang-tools-extra] r327019 - [clangd] Bump vscode extension version to 0.0.5

2018-03-08 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Thu Mar  8 08:14:11 2018
New Revision: 327019

URL: http://llvm.org/viewvc/llvm-project?rev=327019=rev
Log:
[clangd] Bump vscode extension version to 0.0.5

Modified:
clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json

Modified: clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json?rev=327019=327018=327019=diff
==
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json (original)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json Thu Mar  
8 08:14:11 2018
@@ -2,7 +2,7 @@
 "name": "vscode-clangd",
 "displayName": "vscode-clangd",
 "description": "Clang Language Server",
-"version": "0.0.4",
+"version": "0.0.5",
 "publisher": "llvm-vs-code-extensions",
 "homepage": "https://clang.llvm.org/extra/clangd.html;,
 "engines": {


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


[PATCH] D39053: [Bitfield] Add more cases to making the bitfield a separate location

2018-03-08 Thread Petar Jovanovic via Phabricator via cfe-commits
petarj added a comment.

Is everyone OK with the patch now?


https://reviews.llvm.org/D39053



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


[PATCH] D44093: [BUILTINS] structure pretty printer

2018-03-08 Thread Paul Semel via Phabricator via cfe-commits
paulsemel marked 12 inline comments as done.
paulsemel added inline comments.



Comment at: lib/CodeGen/CGBuiltin.cpp:1231
+  Types[getContext().VoidPtrTy] = "%p";
+  Types[getContext().FloatTy] = "%f";
+  Types[getContext().DoubleTy] = "%f";

aaron.ballman wrote:
> paulsemel wrote:
> > aaron.ballman wrote:
> > > It's unfortunate that you cannot distinguish between `float` and 
> > > `double`. Do you need to use the format specifiers exactly?
> > > 
> > > What about other type information, like qualifiers or array extents? How 
> > > should this handle types that do not exist in this mapping, like 
> > > structure or enum types?
> > So, I've think about it. What I am going to do is  that if I do not know 
> > the type of the field, I am just going to print it as a pointer. I know 
> > that it is not the best solution, but I think it's a okay-ish solution 
> > until I implement the other types.
> > For the qualifiers, at it is printed the same way with and without those, I 
> > can just add the entries in the DenseMap.
> > So, I've think about it. What I am going to do is that if I do not know the 
> > type of the field, I am just going to print it as a pointer. I know that it 
> > is not the best solution, but I think it's a okay-ish solution until I 
> > implement the other types.
> 
> Eek. That seems unfortunate. I'm thinking about very common use cases, like:
> ```
> struct S {
>   int i, j;
>   float x, y;
> };
> 
> struct T {
>   struct S s;
>   int k;
> };
> ```
> Printing out `s` as a pointer seems... not particularly useful.
Yes, I see that this is true for other types that I am not handling for the 
moment.. What do you think is the best behavior for those cases ?
Just not print anything and go to the next entry ?



Comment at: lib/CodeGen/CGBuiltin.cpp:1218
+Types[getContext().getConstType(type)] = format; \
+Types[getContext().getVolatileType(type)] = format; \
+Types[getContext().getConstType(getContext().getVolatileType(type))] = 
format;

aaron.ballman wrote:
> This seems insufficient, as there are other qualifiers (restrict, ObjC GC 
> qualifiers, etc). I think a better way to do this is to call 
> `QualType::getUnqualifiedType()` on the type accessing the map.
Yes, I think you're totally right !



Comment at: lib/CodeGen/CGBuiltin.cpp:1252
+  Types[getContext().getPointerType(getContext().CharTy)] = "%s";
+  GENERATE_TYPE_QUALIFIERS_NO_RESTRICT(getContext().CharTy, "%s")
+}

aaron.ballman wrote:
> What about other types that have format specifiers (ptrdiff_t, size_t, 
> intptr_t, char16_t, etc)?
So, for typedef, why not apply the `QualType::getCanonicalType` to our field 
type, so that we try to get rid of those intermediate typedefs ?



Comment at: lib/Sema/SemaChecking.cpp:1121
+  this->Diag(Arg0->getLocStart(), 
diag::err_dump_struct_invalid_argument_type)
+<< Arg0->getType() << "structure pointer type";
+  return ExprError();

aaron.ballman wrote:
> The string literals should be part of a `%select` in the diagnostic itself 
> rather than printed this way.
So, I am now using an other diagnostic definition, so I am constrained to keep 
using string literals I think..



Comment at: lib/Sema/SemaChecking.cpp:1135
+  this->Diag(Arg1->getLocStart(), 
diag::err_dump_struct_invalid_argument_type)
+<< Arg1->getType() << "printf like function pointer type";
+  return ExprError();

aaron.ballman wrote:
> What is a "printf like function pointer type"?
I have changed this to the actual prototype of a "printf like" function so that 
it's way clearer of what I am expecting !


Repository:
  rC Clang

https://reviews.llvm.org/D44093



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


[PATCH] D44226: [clangd] Add -log-lsp-to-stderr option

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



Comment at: clangd/Logger.cpp:19
 Logger *L = nullptr;
+bool Verbose_ = false;
 } // namespace

Could we move the flag to implementation of `Logger`?
I.e.:
```
class Logger {
  virtual log(const llvm::Twine , bool Verbose);
};

// Implementation of top-level log
void clangd::log(const llvm::Twine ) {
   L->log(Message, /*Verbose=*/false);
   // should also handle missing Logger by logging into llvm::errs()
}

// Implementation of top-level vlog.
void clangd::vlog(const llvm::Twine ) {
   L->log(Message, /*Verbose=*/true);
   // should also handle missing Logger by logging into llvm::errs()
}
```

An implementation of the interface would decide whether to log or not, based on 
command-line argument.



Comment at: clangd/tool/ClangdMain.cpp:79
 
+static llvm::cl::opt Verbose("verbose", llvm::cl::desc("Be more 
verbose"),
+   llvm::cl::init(false));

Maybe just call it `-v`?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44226



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


[PATCH] D43197: [OpenMP] Add flag for linking runtime bitcode library

2018-03-08 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea added inline comments.



Comment at: lib/Driver/ToolChains/Cuda.cpp:536-542
+  StringRef CompilerPath = env;
+  while (!CompilerPath.empty()) {
+std::pair Split =
+CompilerPath.split(llvm::sys::EnvPathSeparator);
+LibraryPaths.push_back(Split.first);
+CompilerPath = Split.second;
+  }

Hahnfeld wrote:
> gtbercea wrote:
> > Hahnfeld wrote:
> > > `tools::addDirectoryList` uses `StringRef::find`, I'm not sure if 
> > > `StringRef::split` creates real copies of the string...
> > What is your suggestion?
> IMO you should use whatever existing code does, in that case 
> `StringRef::find`.
Is this comment still relevant in the light of the most recent changes?


Repository:
  rC Clang

https://reviews.llvm.org/D43197



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


[PATCH] D44251: [clangd] Early return for #include goto definition.

2018-03-08 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In https://reviews.llvm.org/D44251#1031373, @ilya-biryukov wrote:

> Sorry, being pedantic here... We're not saving time on parsing, but on 
> walking over the AST :-)


Yeah, rephased it.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44251



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


[PATCH] D44231: [clang-tidy] Check for sizeof that call functions

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

In https://reviews.llvm.org/D44231#1031380, @pfultz2 wrote:

> > Can you elaborate a bit more about this?
>
> This catches problems when calling `sizeof(f())` when `f` returns an 
> integer(or enum). This is because, most likely, the integer represents the 
> type to be chosen, however, `sizeof` is being computed for an integer and not 
> the type the integer represents. That is, the user has an enum for the 
> `data_type`:
>
>   enum data_type {
>   float_type,
>   double_type
>   };
>
>
> At some point the user may call a function to get the data type(perhaps 
> `x.GetType()`) and pass it on to `sizeof`, like `sizeof(x.GetType())`, which 
> is incorrect.


Can you point to some real world code that would benefit from this check? I 
don't see this as being a common issue with code and I am concerned about false 
positives. For instance, it's reasonable to write `sizeof(func_call())` in a 
context where you don't want to repeat the type name in multiple places. I've 
seen this construct used in LLVM's code base (see Prologue::getLength() in 
DWARFDebugLine.h for one such instance).


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44231



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


[PATCH] D44226: [clangd] Add -log-lsp-to-stderr option

2018-03-08 Thread Simon Marchi via Phabricator via cfe-commits
simark added a comment.

Now, if the client calls a method that we do not support (), clangd just 
outputs:

  C/C++: [10:55:16.033] Error -32601: method not found

It would be useful to at least print in this error message the name of the 
method.  Because the "unknown method" handler shares the type signature of 
regular handlers, I would have to add a parameter with the method name to all 
existing handlers.  I'll try that.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44226



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


[PATCH] D44226: [clangd] Add -log-lsp-to-stderr option

2018-03-08 Thread Simon Marchi via Phabricator via cfe-commits
simark updated this revision to Diff 137573.
simark added a comment.

Update

- Change switch to -verbose
- Add vlog function, do the filtering there


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44226

Files:
  clangd/JSONRPCDispatcher.cpp
  clangd/Logger.cpp
  clangd/Logger.h
  clangd/tool/ClangdMain.cpp

Index: clangd/tool/ClangdMain.cpp
===
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -76,6 +76,9 @@
"messages delimited by --- lines, with # comment support")),
 llvm::cl::init(JSONStreamStyle::Standard));
 
+static llvm::cl::opt Verbose("verbose", llvm::cl::desc("Be more verbose"),
+   llvm::cl::init(false));
+
 static llvm::cl::opt
 PrettyPrint("pretty", llvm::cl::desc("Pretty-print JSON output"),
 llvm::cl::init(false));
@@ -192,7 +195,7 @@
  InputMirrorStream ? InputMirrorStream.getPointer() : nullptr,
  PrettyPrint);
 
-  clangd::LoggingSession LoggingSession(Out);
+  clangd::LoggingSession LoggingSession(Out, Verbose);
 
   // If --compile-commands-dir arg was invoked, check value and override default
   // path.
Index: clangd/Logger.h
===
--- clangd/Logger.h
+++ clangd/Logger.h
@@ -15,11 +15,14 @@
 namespace clang {
 namespace clangd {
 
-/// Main logging function.
+/// Main logging functions.
 /// Logs messages to a global logger, which can be set up by LoggingSesssion.
 /// If no logger is registered, writes to llvm::errs().
 void log(const llvm::Twine );
 
+/// Same as the above, but for verbose messages.
+void vlog(const llvm::Twine );
+
 /// Interface to allow custom logging in clangd.
 class Logger {
 public:
@@ -32,7 +35,7 @@
 /// Only one LoggingSession can be active at a time.
 class LoggingSession {
 public:
-  LoggingSession(clangd::Logger );
+  LoggingSession(clangd::Logger , bool Verbose);
   ~LoggingSession();
 
   LoggingSession(LoggingSession &&) = delete;
Index: clangd/Logger.cpp
===
--- clangd/Logger.cpp
+++ clangd/Logger.cpp
@@ -16,11 +16,13 @@
 
 namespace {
 Logger *L = nullptr;
+bool Verbose_ = false;
 } // namespace
 
-LoggingSession::LoggingSession(clangd::Logger ) {
+LoggingSession::LoggingSession(clangd::Logger , bool Verbose) {
   assert(!L);
   L = 
+  Verbose_ = Verbose;
 }
 
 LoggingSession::~LoggingSession() { L = nullptr; }
@@ -35,5 +37,10 @@
   }
 }
 
+void vlog(const llvm::Twine ) {
+  if (Verbose_)
+log(Message);
+}
+
 } // namespace clangd
 } // namespace clang
Index: clangd/JSONRPCDispatcher.cpp
===
--- clangd/JSONRPCDispatcher.cpp
+++ clangd/JSONRPCDispatcher.cpp
@@ -66,7 +66,7 @@
 Outs << "Content-Length: " << S.size() << "\r\n\r\n" << S;
 Outs.flush();
   }
-  log(llvm::Twine("--> ") + S);
+  vlog(llvm::Twine("--> ") + S);
 }
 
 void JSONOutput::log(const Twine ) {
@@ -306,7 +306,7 @@
 if (auto JSON = ReadMessage(In, Out)) {
   if (auto Doc = json::parse(*JSON)) {
 // Log the formatted message.
-log(llvm::formatv(Out.Pretty ? "<-- {0:2}\n" : "<-- {0}\n", *Doc));
+vlog(llvm::formatv(Out.Pretty ? "<-- {0:2}\n" : "<-- {0}\n", *Doc));
 // Finally, execute the action for this JSON message.
 if (!Dispatcher.call(*Doc, Out))
   log("JSON dispatch failed!\n");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42624: [clang-tidy] Add a utility Matcher to match the next statement within a statement sequence

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

In https://reviews.llvm.org/D42624#1031073, @sylvestre.ledru wrote:

> @aaron.ballman Hello, Do you think it is ready to land? Thanks


@alexfh was asking to make this matcher local to the check rather than add it 
to Matchers.h, so I think this patch should be abandoned and rolled into 
https://reviews.llvm.org/D37014 directly, but the dependency is fine to pick up 
in that patch.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42624



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


[PATCH] D44241: [clang-tidy] Add a check for constructing non-trivial types without assigning to a variable

2018-03-08 Thread Paul Fultz II via Phabricator via cfe-commits
pfultz2 added a comment.

> How does this differ from misc-unused-raii?

Actually, I was unaware of this check. This seems like a better place to start. 
Whats missing from the misc-unused-raii is that it doesn't catch it when 
constructing with curly braces(ie `NonTrivial{}`). Let me work on updating that 
check instead.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44241



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


[PATCH] D44231: [clang-tidy] Check for sizeof that call functions

2018-03-08 Thread Paul Fultz II via Phabricator via cfe-commits
pfultz2 added a comment.

> Can you elaborate a bit more about this?

This catches problems when calling `sizeof(f())` when `f` returns an integer(or 
enum). This is because, most likely, the integer represents the type to be 
chosen, however, `sizeof` is being computed for an integer and not the type the 
integer represents. That is, the user has an enum for the `data_type`:

  enum data_type {
  float_type,
  double_type
  };

At some point the user may call a function to get the data type(perhaps 
`x.GetType()`) and pass it on to `sizeof`, like `sizeof(x.GetType())`, which is 
incorrect.

> I think we also need to update the check document (adding proper section of 
> this new behavior, and the new option).

I will update the doc.




Comment at: clang-tidy/misc/SizeofExpressionCheck.cpp:220
+ Result.Nodes.getNodeAs("sizeof-integer-call")) {
+diag(E->getLocStart(), "suspicious usage of 'sizeof(expr)' to an integer");
   } else if (const auto *E = Result.Nodes.getNodeAs("sizeof-this")) {

alexfh wrote:
> I'm not sure I understand the message "suspicious usage of ... to an 
> integer". Specifically, what does the "to an integer" part mean?
That could probably be worded better. It means the `expr` is an integer type. 
Maybe I should say `suspicious usage of 'sizeof() on an expression that results 
in an integer`?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44231



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


[PATCH] D44251: [clangd] Early return for #include goto definition.

2018-03-08 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added a comment.

In https://reviews.llvm.org/D44251#1031370, @ilya-biryukov wrote:

> LGTM.
>  I think this was part of initial changed and I asked to make it this way, 
> but I don't remember why.


I think it was just to have a single place that returns. I think it's OK to 
early return in this case, it's a good optimization.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44251



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


[PATCH] D44251: [clangd] Early return for #include goto definition.

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

Sorry, being pedantic here... We're not saving time on parsing, but on walking 
over the AST :-)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44251



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


[PATCH] D44251: [clangd] Early return for #include goto definition.

2018-03-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM.
I think this was part of initial changed and I asked to make it this way, but I 
don't remember why.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44251



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


[PATCH] D44158: [clangd:vscode] Resolve symlinks for file paths from clangd.

2018-03-08 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL327009: [clangd:vscode] Resolve symlinks for file paths from 
clangd. (authored by ioeric, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D44158

Files:
  clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts


Index: clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts
===
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts
@@ -1,12 +1,13 @@
 import * as vscode from 'vscode';
 import * as vscodelc from 'vscode-languageclient';
+import { realpathSync } from 'fs';
 
 /**
  * Method to get workspace configuration option
  * @param option name of the option (e.g. for clangd.path should be path)
  * @param defaultValue default value to return if option is not set
  */
-function getConfig(option: string, defaultValue?: any) : T {
+function getConfig(option: string, defaultValue?: any): T {
 const config = vscode.workspace.getConfiguration('clangd');
 return config.get(option, defaultValue);
 }
@@ -24,18 +25,29 @@
 };
 const traceFile = getConfig('trace');
 if (!!traceFile) {
-  const trace = {CLANGD_TRACE : traceFile};
-  clangd.options = {env : {...process.env, ...trace}};
+const trace = { CLANGD_TRACE: traceFile };
+clangd.options = { env: { ...process.env, ...trace } };
 }
 const serverOptions: vscodelc.ServerOptions = clangd;
 
 const filePattern: string = '**/*.{' +
-  ['cpp', 'c', 'cc', 'cxx', 'c++', 'm', 'mm', 'h', 'hh', 'hpp', 'hxx', 
'inc'].join() + '}';
+['cpp', 'c', 'cc', 'cxx', 'c++', 'm', 'mm', 'h', 'hh', 'hpp', 'hxx', 
'inc'].join() + '}';
 const clientOptions: vscodelc.LanguageClientOptions = {
 // Register the server for C/C++ files
-documentSelector: [{scheme: 'file', pattern: filePattern}],
+documentSelector: [{ scheme: 'file', pattern: filePattern }],
 synchronize: !syncFileEvents ? undefined : {
 fileEvents: vscode.workspace.createFileSystemWatcher(filePattern)
+},
+// Resolve symlinks for all files provided by clangd.
+// This is a workaround for a bazel + clangd issue - bazel produces a 
symlink tree to build in,
+// and when navigating to the included file, clangd passes its path 
inside the symlink tree
+// rather than its filesystem path.
+// FIXME: remove this once clangd knows enough about bazel to resolve 
the
+// symlinks where needed (or if this causes problems for other 
workflows).
+uriConverters: {
+code2Protocol: (value: vscode.Uri) => value.toString(),
+protocol2Code: (value: string) =>
+vscode.Uri.file(realpathSync(vscode.Uri.parse(value).fsPath))
 }
 };
 


Index: clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts
===
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts
@@ -1,12 +1,13 @@
 import * as vscode from 'vscode';
 import * as vscodelc from 'vscode-languageclient';
+import { realpathSync } from 'fs';
 
 /**
  * Method to get workspace configuration option
  * @param option name of the option (e.g. for clangd.path should be path)
  * @param defaultValue default value to return if option is not set
  */
-function getConfig(option: string, defaultValue?: any) : T {
+function getConfig(option: string, defaultValue?: any): T {
 const config = vscode.workspace.getConfiguration('clangd');
 return config.get(option, defaultValue);
 }
@@ -24,18 +25,29 @@
 };
 const traceFile = getConfig('trace');
 if (!!traceFile) {
-  const trace = {CLANGD_TRACE : traceFile};
-  clangd.options = {env : {...process.env, ...trace}};
+const trace = { CLANGD_TRACE: traceFile };
+clangd.options = { env: { ...process.env, ...trace } };
 }
 const serverOptions: vscodelc.ServerOptions = clangd;
 
 const filePattern: string = '**/*.{' +
-  ['cpp', 'c', 'cc', 'cxx', 'c++', 'm', 'mm', 'h', 'hh', 'hpp', 'hxx', 'inc'].join() + '}';
+['cpp', 'c', 'cc', 'cxx', 'c++', 'm', 'mm', 'h', 'hh', 'hpp', 'hxx', 'inc'].join() + '}';
 const clientOptions: vscodelc.LanguageClientOptions = {
 // Register the server for C/C++ files
-documentSelector: [{scheme: 'file', pattern: filePattern}],
+documentSelector: [{ scheme: 'file', pattern: filePattern }],
 synchronize: !syncFileEvents ? undefined : {
 fileEvents: vscode.workspace.createFileSystemWatcher(filePattern)
+},
+// Resolve symlinks for all files provided by clangd.
+// This is a 

[PATCH] D44247: [clangd] Use identifier range as the definition range.

2018-03-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In https://reviews.llvm.org/D44247#1031345, @malaperle wrote:

> I was going to change the symbol index to do the opposite :) The range of 
> definitions including the bodies of functions, etc is used in a "peek 
> definition" feature by several LSP clients. So for example in VSCode, you can 
> hold Ctrl and hover on a function call and see its definition in a popup. 
> There was some discussion about this in https://reviews.llvm.org/D35894


Interesting - that seemed like a more natural interpretation of LSP to me.
Others talked me down, motivated (I think) by nicer behavior of 
jump-to-definition... will bring it up again :)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44247



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


[clang-tools-extra] r327009 - [clangd:vscode] Resolve symlinks for file paths from clangd.

2018-03-08 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Thu Mar  8 07:28:42 2018
New Revision: 327009

URL: http://llvm.org/viewvc/llvm-project?rev=327009=rev
Log:
[clangd:vscode] Resolve symlinks for file paths from clangd.

Summary:
For features like go-to-definition, clangd can point clients to symlink paths
(e.g. in bazel execroot) which might not be desired if the symlink points to a
file in the workspace. Clangd might not be able to build the file, and users
might prefer to edit the file on the real path.

This change converts file paths from clangd to real path (e.g. resolving 
symlinks).
Long term, we might want to the symlink handling logic to clangd where clangd
can better decide whether symlinks should be resolved according to e.g. compile
commands.

Reviewers: sammccall

Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts

Modified: clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts?rev=327009=327008=327009=diff
==
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts 
(original)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts Thu 
Mar  8 07:28:42 2018
@@ -1,12 +1,13 @@
 import * as vscode from 'vscode';
 import * as vscodelc from 'vscode-languageclient';
+import { realpathSync } from 'fs';
 
 /**
  * Method to get workspace configuration option
  * @param option name of the option (e.g. for clangd.path should be path)
  * @param defaultValue default value to return if option is not set
  */
-function getConfig(option: string, defaultValue?: any) : T {
+function getConfig(option: string, defaultValue?: any): T {
 const config = vscode.workspace.getConfiguration('clangd');
 return config.get(option, defaultValue);
 }
@@ -24,18 +25,29 @@ export function activate(context: vscode
 };
 const traceFile = getConfig('trace');
 if (!!traceFile) {
-  const trace = {CLANGD_TRACE : traceFile};
-  clangd.options = {env : {...process.env, ...trace}};
+const trace = { CLANGD_TRACE: traceFile };
+clangd.options = { env: { ...process.env, ...trace } };
 }
 const serverOptions: vscodelc.ServerOptions = clangd;
 
 const filePattern: string = '**/*.{' +
-  ['cpp', 'c', 'cc', 'cxx', 'c++', 'm', 'mm', 'h', 'hh', 'hpp', 'hxx', 
'inc'].join() + '}';
+['cpp', 'c', 'cc', 'cxx', 'c++', 'm', 'mm', 'h', 'hh', 'hpp', 'hxx', 
'inc'].join() + '}';
 const clientOptions: vscodelc.LanguageClientOptions = {
 // Register the server for C/C++ files
-documentSelector: [{scheme: 'file', pattern: filePattern}],
+documentSelector: [{ scheme: 'file', pattern: filePattern }],
 synchronize: !syncFileEvents ? undefined : {
 fileEvents: vscode.workspace.createFileSystemWatcher(filePattern)
+},
+// Resolve symlinks for all files provided by clangd.
+// This is a workaround for a bazel + clangd issue - bazel produces a 
symlink tree to build in,
+// and when navigating to the included file, clangd passes its path 
inside the symlink tree
+// rather than its filesystem path.
+// FIXME: remove this once clangd knows enough about bazel to resolve 
the
+// symlinks where needed (or if this causes problems for other 
workflows).
+uriConverters: {
+code2Protocol: (value: vscode.Uri) => value.toString(),
+protocol2Code: (value: string) =>
+vscode.Uri.file(realpathSync(vscode.Uri.parse(value).fsPath))
 }
 };
 


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


[PATCH] D44247: [clangd] Use identifier range as the definition range.

2018-03-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clangd/SourceCode.cpp:55
+  const auto& SM = D->getASTContext().getSourceManager();
+  SourceLocation SpellingLoc = SM.getSpellingLoc(D->getLocation());
+  if (D->getLocation().isMacroID()) {

As discussed offline, this heuristic is... limited.

```#define X Y
class X{}```

and now we say the definition of the class Y is on the first line.

I think we should really be basing the heuristics on the whole definition 
range, even if we're then going to return just the position of the name.

This patch just moves logic around so we don't need to do it now, but it could 
use a FIXME



Comment at: clangd/SourceCode.h:34
 
+/// Get the source location of the given D.
+///

This is a useful function, but it doesn't belong in SourceCode with its current 
scope. See the file header :)

We could add an "AST.h" or similar file, or expand the scope of SourceCode, but 
we haven't needed to yet because clang/AST normally has what we need.

Can this be a method on NamedDecl or a function alongside?
But since (later comment) the logic seems wrong, I'm not sure it makes sense to 
move it at the moment. Maybe create a separate header?



Comment at: clangd/SourceCode.h:36
+///
+/// For symbols defined inside macros:
+///  * use expansion location, if the symbol is formed via macro concatenation.

Not sure it's neccesary to spell out the details of what's happening inside 
macros, but it would be useful to describe the normal case :-)
e.g. This is usually the spelling location, where the name of the decl occurs 
in source code.



Comment at: clangd/SourceCode.h:39
+///  * use spelling location, otherwise.
+SourceLocation getDeclSourceLoc(const clang::Decl* D);
+

This name seems opaque to me.

findName?



Comment at: clangd/SourceCode.h:39
+///  * use spelling location, otherwise.
+SourceLocation getDeclSourceLoc(const clang::Decl* D);
+

sammccall wrote:
> This name seems opaque to me.
> 
> findName?
would it be more useful to return the range, and just pick out the start if 
you're not interested in both?



Comment at: clangd/XRefs.cpp:136
 llvm::Optional
 getDeclarationLocation(ParsedAST , const SourceRange ) {
   const SourceManager  = AST.getASTContext().getSourceManager();

The name of this function is *really* confusing, so it took me a long time to 
understand the callsite.
Consider rename to makeLocaction



Comment at: clangd/XRefs.cpp:194
+auto Loc = getDeclSourceLoc(D);
+// We use the identifier range as the definition range which matches the
+// index.

I think this comment relates to the previous line, not the next one.
But consider just removing it - if getDeclSourceLoc had a clearer name, it'd be 
self-documenting.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44247



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


r327008 - [OPENMP] Emit sizes/init ptrs etc. data for task reductions before

2018-03-08 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Mar  8 07:24:08 2018
New Revision: 327008

URL: http://llvm.org/viewvc/llvm-project?rev=327008=rev
Log:
[OPENMP] Emit sizes/init ptrs etc. data for task reductions before
using.

We may emit the code in wrong order because of incorrect implementation
of the runtime functions for task reductions. Threadprivate storages may
be initialized after real initialization of the reduction items. Patch
fixes this problem.

Modified:
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/test/OpenMP/task_in_reduction_codegen.cpp
cfe/trunk/test/OpenMP/taskloop_reduction_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=327008=327007=327008=diff
==
--- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Thu Mar  8 07:24:08 2018
@@ -2886,6 +2886,11 @@ void CodeGenFunction::EmitOMPTaskBasedDi
   for (unsigned Cnt = 0, E = Data.ReductionVars.size(); Cnt < E; ++Cnt) {
 RedCG.emitSharedLValue(CGF, Cnt);
 RedCG.emitAggregateType(CGF, Cnt);
+// FIXME: This must removed once the runtime library is fixed.
+// Emit required threadprivate variables for
+// initilizer/combiner/finalizer.
+CGF.CGM.getOpenMPRuntime().emitTaskReductionFixups(CGF, 
S.getLocStart(),
+   RedCG, Cnt);
 Address Replacement = CGF.CGM.getOpenMPRuntime().getTaskReductionItem(
 CGF, S.getLocStart(), ReductionsPtr, RedCG.getSharedLValue(Cnt));
 Replacement =
@@ -2898,11 +2903,6 @@ void CodeGenFunction::EmitOMPTaskBasedDi
 Replacement = RedCG.adjustPrivateAddress(CGF, Cnt, Replacement);
 Scope.addPrivate(RedCG.getBaseDecl(Cnt),
  [Replacement]() { return Replacement; });
-// FIXME: This must removed once the runtime library is fixed.
-// Emit required threadprivate variables for
-// initilizer/combiner/finalizer.
-CGF.CGM.getOpenMPRuntime().emitTaskReductionFixups(CGF, 
S.getLocStart(),
-   RedCG, Cnt);
   }
 }
 // Privatize all private variables except for in_reduction items.
@@ -2935,6 +2935,11 @@ void CodeGenFunction::EmitOMPTaskBasedDi
 RedCG.emitAggregateType(CGF, Cnt);
 // The taskgroup descriptor variable is always implicit firstprivate 
and
 // privatized already during procoessing of the firstprivates.
+// FIXME: This must removed once the runtime library is fixed.
+// Emit required threadprivate variables for
+// initilizer/combiner/finalizer.
+CGF.CGM.getOpenMPRuntime().emitTaskReductionFixups(CGF, 
S.getLocStart(),
+   RedCG, Cnt);
 llvm::Value *ReductionsPtr =
 CGF.EmitLoadOfScalar(CGF.EmitLValue(TaskgroupDescriptors[Cnt]),
  TaskgroupDescriptors[Cnt]->getExprLoc());
@@ -2949,11 +2954,6 @@ void CodeGenFunction::EmitOMPTaskBasedDi
 Replacement = RedCG.adjustPrivateAddress(CGF, Cnt, Replacement);
 InRedScope.addPrivate(RedCG.getBaseDecl(Cnt),
   [Replacement]() { return Replacement; });
-// FIXME: This must removed once the runtime library is fixed.
-// Emit required threadprivate variables for
-// initilizer/combiner/finalizer.
-CGF.CGM.getOpenMPRuntime().emitTaskReductionFixups(CGF, 
S.getLocStart(),
-   RedCG, Cnt);
   }
 }
 (void)InRedScope.Privatize();

Modified: cfe/trunk/test/OpenMP/task_in_reduction_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/task_in_reduction_codegen.cpp?rev=327008=327007=327008=diff
==
--- cfe/trunk/test/OpenMP/task_in_reduction_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/task_in_reduction_codegen.cpp Thu Mar  8 07:24:08 2018
@@ -78,9 +78,11 @@ int main(int argc, char **argv) {
 // CHECK-NEXT:  call i8* @__kmpc_task_reduction_get_th_data(i32 [[GTID]], i8* 
[[TD1]], i8* [[A_PTR]])
 // CHECK:   [[D_REF:%.+]] = getelementptr inbounds %
 // CHECK-NEXT:  [[D_ADDR:%.+]] = load i16*, i16** [[D_REF]],
+// CHECK:   call i8* @__kmpc_threadprivate_cached(
 // CHECK:   [[TD2:%.+]] = load i8*, i8** [[TD2_ADDR]],
 // CHECK-NEXT:  [[D_PTR:%.+]] = bitcast i16* [[D_ADDR]] to i8*
 // CHECK-NEXT:  call i8* @__kmpc_task_reduction_get_th_data(i32 [[GTID]], i8* 
[[TD2]], i8* [[D_PTR]])
 // CHECK:   add nsw i32
 // CHECK:   store i32 %
+// CHECK-NOT:   call i8* @__kmpc_threadprivate_cached(
 #endif

Modified: cfe/trunk/test/OpenMP/taskloop_reduction_codegen.cpp
URL: 

[PATCH] D44247: [clangd] Use identifier range as the definition range.

2018-03-08 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added a comment.

I was going to change the symbol index to do the opposite :) The range of 
definitions including the bodies of functions, etc is used in a "peek 
definition" feature by several LSP clients. So for example in VSCode, you can 
hold Ctrl and hover on a function call and see its definition in a popup. There 
was some discussion about this in https://reviews.llvm.org/D35894


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44247



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


[libcxx] r327005 - Implement LWG#2518 - Non-member swap for propagate_const should call member swap

2018-03-08 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Thu Mar  8 07:01:50 2018
New Revision: 327005

URL: http://llvm.org/viewvc/llvm-project?rev=327005=rev
Log:
Implement LWG#2518 - Non-member swap for propagate_const should call member swap

Modified:
libcxx/trunk/include/experimental/propagate_const
libcxx/trunk/www/cxx1z_status.html

Modified: libcxx/trunk/include/experimental/propagate_const
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/propagate_const?rev=327005=327004=327005=diff
==
--- libcxx/trunk/include/experimental/propagate_const (original)
+++ libcxx/trunk/include/experimental/propagate_const Thu Mar  8 07:01:50 2018
@@ -463,8 +463,7 @@ template 
 _LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR void swap(propagate_const<_Tp>& __pc1, propagate_const<_Tp>& 
__pc2) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)
 {
-  using _VSTD::swap;
-  swap(_VSTD_LFTS_V2::get_underlying(__pc1), 
_VSTD_LFTS_V2::get_underlying(__pc2));
+  __pc1.swap(__pc2);
 }
 
 template 

Modified: libcxx/trunk/www/cxx1z_status.html
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/cxx1z_status.html?rev=327005=327004=327005=diff
==
--- libcxx/trunk/www/cxx1z_status.html (original)
+++ libcxx/trunk/www/cxx1z_status.html Thu Mar  8 07:01:50 2018
@@ -375,7 +375,7 @@
https://wg21.link/LWG2503;>2503multiline 
option should be added to syntax_option_typeIssaquah
https://wg21.link/LWG2510;>2510Tag types 
should not be DefaultConstructibleIssaquah
https://wg21.link/LWG2514;>2514Type 
traits must not be finalIssaquahComplete
-   https://wg21.link/LWG2518;>2518[fund.ts.v2] Non-member swap 
for propagate_const should call member swapIssaquah
+   https://wg21.link/LWG2518;>2518[fund.ts.v2] Non-member swap 
for propagate_const should call member 
swapIssaquahComplete
https://wg21.link/LWG2519;>2519Iterator 
operator-= has gratuitous undefined 
behaviourIssaquahComplete
https://wg21.link/LWG2521;>2521[fund.ts.v2] weak_ptr's 
converting move constructor should be modified as well for array 
supportIssaquah
https://wg21.link/LWG2525;>2525[fund.ts.v2] 
get_memory_resource should be const and 
noexceptIssaquah
@@ -504,7 +504,7 @@
 
   
 
-  Last Updated: 12-Feb-2018
+  Last Updated: 8-Mar-2018
 
 
 


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


[PATCH] D44158: [clangd:vscode] Resolve symlinks for file paths from clangd.

2018-03-08 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: clangd/clients/clangd-vscode/src/extension.ts:3
 import * as vscodelc from 'vscode-languageclient';
+import { realpathSync } from 'fs';
 

sammccall wrote:
> nit: the braces don't do anything here, right?
I'm not sure... this was added by vscode. 



Comment at: clangd/clients/clangd-vscode/src/extension.ts:28
 if (!!traceFile) {
-  const trace = {CLANGD_TRACE : traceFile};
-  clangd.options = {env : {...process.env, ...trace}};
+const trace = { CLANGD_TRACE: traceFile };
+clangd.options = { env: { ...process.env, ...trace } };

sammccall wrote:
> (this is an unrelated formatting change, so consider reverting anyway)
> My clang-format doesn't add the whitespace inside {}, and the indentation 
> change seems just wrong... what are you using to format?
This was also vscode which formats a whole file by default. Yeah, it's 
unrelated, but it's a bit annoying to revert all formatting changes...

Regarding the indentation, I think it just follows the current indentation in 
the file.



Comment at: clangd/clients/clangd-vscode/src/extension.ts:41
+},
+// Resolve symlinks for all files provided by clangd.
+// FIXME: it might make more sense to rely on clangd to handle 
symlinks.

sammccall wrote:
> I think this comment needs to be more precise, because it's important we know 
> when to remove this.
> 
> This is a workaround for a bazel + clangd issue - bazel produces a symlink 
> tree to build in, and  when navigating to the included file, clangd passes 
> its path inside the symlink tree rather than its filesystem path. We work 
> around this by resolving all symlinks on the client.
> We should remove this once clangd knows enough about bazel to resolve the 
> symlinks where needed (or if this causes problems for other workflows).
> 
> (that's not necessarily text that needs to go into the comment, but I think 
> all the information does...)
Done. Thanks!


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44158



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


[PATCH] D44158: [clangd:vscode] Resolve symlinks for file paths from clangd.

2018-03-08 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 137564.
ioeric marked an inline comment as done.
ioeric added a comment.

- add context about the workaround.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44158

Files:
  clangd/clients/clangd-vscode/src/extension.ts


Index: clangd/clients/clangd-vscode/src/extension.ts
===
--- clangd/clients/clangd-vscode/src/extension.ts
+++ clangd/clients/clangd-vscode/src/extension.ts
@@ -1,12 +1,13 @@
 import * as vscode from 'vscode';
 import * as vscodelc from 'vscode-languageclient';
+import { realpathSync } from 'fs';
 
 /**
  * Method to get workspace configuration option
  * @param option name of the option (e.g. for clangd.path should be path)
  * @param defaultValue default value to return if option is not set
  */
-function getConfig(option: string, defaultValue?: any) : T {
+function getConfig(option: string, defaultValue?: any): T {
 const config = vscode.workspace.getConfiguration('clangd');
 return config.get(option, defaultValue);
 }
@@ -24,18 +25,29 @@
 };
 const traceFile = getConfig('trace');
 if (!!traceFile) {
-  const trace = {CLANGD_TRACE : traceFile};
-  clangd.options = {env : {...process.env, ...trace}};
+const trace = { CLANGD_TRACE: traceFile };
+clangd.options = { env: { ...process.env, ...trace } };
 }
 const serverOptions: vscodelc.ServerOptions = clangd;
 
 const filePattern: string = '**/*.{' +
-  ['cpp', 'c', 'cc', 'cxx', 'c++', 'm', 'mm', 'h', 'hh', 'hpp', 'hxx', 
'inc'].join() + '}';
+['cpp', 'c', 'cc', 'cxx', 'c++', 'm', 'mm', 'h', 'hh', 'hpp', 'hxx', 
'inc'].join() + '}';
 const clientOptions: vscodelc.LanguageClientOptions = {
 // Register the server for C/C++ files
-documentSelector: [{scheme: 'file', pattern: filePattern}],
+documentSelector: [{ scheme: 'file', pattern: filePattern }],
 synchronize: !syncFileEvents ? undefined : {
 fileEvents: vscode.workspace.createFileSystemWatcher(filePattern)
+},
+// Resolve symlinks for all files provided by clangd.
+// This is a workaround for a bazel + clangd issue - bazel produces a 
symlink tree to build in,
+// and when navigating to the included file, clangd passes its path 
inside the symlink tree
+// rather than its filesystem path.
+// FIXME: remove this once clangd knows enough about bazel to resolve 
the
+// symlinks where needed (or if this causes problems for other 
workflows).
+uriConverters: {
+code2Protocol: (value: vscode.Uri) => value.toString(),
+protocol2Code: (value: string) =>
+vscode.Uri.file(realpathSync(vscode.Uri.parse(value).fsPath))
 }
 };
 


Index: clangd/clients/clangd-vscode/src/extension.ts
===
--- clangd/clients/clangd-vscode/src/extension.ts
+++ clangd/clients/clangd-vscode/src/extension.ts
@@ -1,12 +1,13 @@
 import * as vscode from 'vscode';
 import * as vscodelc from 'vscode-languageclient';
+import { realpathSync } from 'fs';
 
 /**
  * Method to get workspace configuration option
  * @param option name of the option (e.g. for clangd.path should be path)
  * @param defaultValue default value to return if option is not set
  */
-function getConfig(option: string, defaultValue?: any) : T {
+function getConfig(option: string, defaultValue?: any): T {
 const config = vscode.workspace.getConfiguration('clangd');
 return config.get(option, defaultValue);
 }
@@ -24,18 +25,29 @@
 };
 const traceFile = getConfig('trace');
 if (!!traceFile) {
-  const trace = {CLANGD_TRACE : traceFile};
-  clangd.options = {env : {...process.env, ...trace}};
+const trace = { CLANGD_TRACE: traceFile };
+clangd.options = { env: { ...process.env, ...trace } };
 }
 const serverOptions: vscodelc.ServerOptions = clangd;
 
 const filePattern: string = '**/*.{' +
-  ['cpp', 'c', 'cc', 'cxx', 'c++', 'm', 'mm', 'h', 'hh', 'hpp', 'hxx', 'inc'].join() + '}';
+['cpp', 'c', 'cc', 'cxx', 'c++', 'm', 'mm', 'h', 'hh', 'hpp', 'hxx', 'inc'].join() + '}';
 const clientOptions: vscodelc.LanguageClientOptions = {
 // Register the server for C/C++ files
-documentSelector: [{scheme: 'file', pattern: filePattern}],
+documentSelector: [{ scheme: 'file', pattern: filePattern }],
 synchronize: !syncFileEvents ? undefined : {
 fileEvents: vscode.workspace.createFileSystemWatcher(filePattern)
+},
+// Resolve symlinks for all files provided by clangd.
+// This is a workaround for a bazel + clangd issue - bazel produces a symlink tree to build in,
+// and when navigating to the included file, clangd passes its path inside the symlink tree
+// rather than its filesystem path.
+// FIXME: 

  1   2   >