[PATCH] D41102: Setup clang-doc frontend framework

2018-01-30 Thread Jake Ehrlich via Phabricator via cfe-commits
jakehehrlich added inline comments.



Comment at: tools/clang-doc/ClangDocReporter.cpp:55
+Docs.Namespaces[Name] = std::move(I);
+populateBasicInfo(*Docs.Namespaces[Name], Name, D->getNameAsString(),
+  getParentNamespace(D));

If you make a "populateNamespaceInfo" method that just calls populateBasicInfo 
but checks to see that the namespace hasn't already been added you can move 
this outside of this if statement which will make it more uniform with the 
other invocations. Also if you then specialize a general form of 
"populateInfo",  include a specialization for NamespaceInfo, and do a few more 
things in other methods I think most of these methods become identical (the 
Function stuff is still different).



Comment at: tools/clang-doc/ClangDocReporter.cpp:70
+  if (Pair == Docs.Types.end()) {
+std::unique_ptr I = make_unique();
+Docs.Types[Name] = std::move(I);

ditto



Comment at: tools/clang-doc/ClangDocReporter.cpp:74
+
+  if (D->isThisDeclarationADefinition())
+populateTypeInfo(*Docs.Types[Name], D, Name, File);

Is this a check that populateTypeInfo could do instead? Or do we sometimes want 
to call populateTypeInfo on non-definitions?



Comment at: tools/clang-doc/ClangDocReporter.cpp:87
+  if (Pair == Docs.Enums.end()) {
+std::unique_ptr I = make_unique();
+Docs.Enums[Name] = std::move(I);

ditto



Comment at: tools/clang-doc/ClangDocReporter.cpp:91
+
+  if (D->isThisDeclarationADefinition())
+populateEnumInfo(*Docs.Enums[Name], D, Name, File);

Same comment here as I had on createTypeInfo/populateTypeInfo



Comment at: tools/clang-doc/ClangDocReporter.cpp:118
+
+  if (D->isThisDeclarationADefinition())
+populateFunctionInfo(*Docs.Namespaces[Namespace]->Functions[MangledName], 
D,

Is this something that can go inside populateFunctionInfo?



Comment at: tools/clang-doc/ClangDocReporter.h:166
+ StringRef Namespace);
+  void populateTypeInfo(TypeInfo &I, const RecordDecl *D, StringRef Name,
+StringRef File);

sans the BasicInfo one I think you should use the same specialization trick 
here. After you do that the main difference between createInfo methods will be 
what collection they add too. That suggests to me that the collection the info 
is added to should be made a parameter to a method that does all the actual 
work.


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] D42174: [clangd] Refactored threading in ClangdServer

2018-01-30 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.

Ship it!




Comment at: clangd/ClangdServer.cpp:37
+template 
+Ret waitForASTAction(Scheduler &S, PathRef File, Func &&F) {
+  std::packaged_task)> Task(

sammccall wrote:
> Would be nice to have parallel names to the Scheduler methods, e.g. 
> blockingASTRead() and blockingPreambleRead()
Nit: these names got out of sync again



Comment at: clangd/TUScheduler.h:23
+/// synchronously).
+unsigned getDefaultAsyncThreadsCount();
+

just use llvm::hardware_concurrency()?



Comment at: clangd/Threading.h:30
+  ThreadPool(unsigned AsyncThreadsCount);
+  ~ThreadPool();
+

add a comment to the destructor saying what it blocks on?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42174



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


[PATCH] D41102: Setup clang-doc frontend framework

2018-01-30 Thread Jake Ehrlich via Phabricator via cfe-commits
jakehehrlich added inline comments.



Comment at: tools/clang-doc/ClangDocReporter.cpp:53-54
+  if (Pair == Docs.Namespaces.end()) {
+std::unique_ptr I = make_unique();
+Docs.Namespaces[Name] = std::move(I);
+populateBasicInfo(*Docs.Namespaces[Name], Name, D->getNameAsString(),

There's no need for I here, also use llvm::make_unique



Comment at: tools/clang-doc/ClangDocReporter.h:133
+
+  void createNamespaceInfo(const NamespaceDecl *D, const FullComment *C,
+   int LineNumber, StringRef File);

I think you should use explicit template specialization to make these 
"createFooInfo" methods uniform. This will enable other code that calls these 
methods to be written in a more uniform fashion.

so define something like

```
template
void createInfo(const T *D, const FullComment *C, ...);
```
 
and then define various specializations of that member function instead of 
creating a new method for each createFooInfo method.


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] D41102: Setup clang-doc frontend framework

2018-01-30 Thread Jake Ehrlich via Phabricator via cfe-commits
jakehehrlich added a comment.

If its possible to split VisitEnumDecl, and VisitRecordDecl into separate 
methods and the same is possible for VisitFunctionDecl and VisitCXXMethodDecl 
then I think all of your methods will look like the following 
VisitNamespaceDecl. That being the case you might want to factor this out 
somehow (which I think also would resolve my comment about isUnparsed being 
used the same way a lot).

for instance you might have a function like

  template 
  bool ClangDocVisitor::visitDecl(const T *D) {
if (!isUnparsed(D->getLocation()))
  return true;
Reporter.createInfo(D, getComment(D), getLine(D), getFile(D)); // Use 
explicit template specialization to make "createInfo" uniform
return true;
  }

and then define a macro like the following

  #define DEFINE_VISIT_METHOD(TYPE) \
  bool ClangDocVisitor::Visit##TYPE(const TYPE *D) { return visitDecl(D); }




Comment at: tools/clang-doc/ClangDoc.cpp:22
+
+bool ClangDocVisitor::VisitTagDecl(const TagDecl *D) {
+  if (!isUnparsed(D->getLocation()))

Is it possible to use VisitEnumDecl and VisitRecordDecl separately here?



Comment at: tools/clang-doc/ClangDoc.cpp:35
+
+  // Error?
+  return true;

I think you should use llvm_unrechable here



Comment at: tools/clang-doc/ClangDoc.cpp:40
+bool ClangDocVisitor::VisitNamespaceDecl(const NamespaceDecl *D) {
+  if (!isUnparsed(D->getLocation()))
+return true;

It looks like you're using this pattern a lot. It might be worth factoring this 
out somehow.



Comment at: tools/clang-doc/ClangDoc.cpp:46
+
+bool ClangDocVisitor::VisitFunctionDecl(const FunctionDecl *D) {
+  if (!isUnparsed(D->getLocation()))

Can you separate this into VisitFunctionDecl and VisitCXXMethodDecl?



Comment at: tools/clang-doc/ClangDoc.cpp:60
+
+comments::FullComment *ClangDocVisitor::getComment(const Decl *D) {
+  RawComment *Comment = Context->getRawCommentForDeclNoCache(D);

Can this be a const method?



Comment at: tools/clang-doc/ClangDoc.cpp:76
+
+std::string ClangDocVisitor::getFile(const Decl *D) const {
+  PresumedLoc PLoc = Manager.getPresumedLoc(D->getLocStart());

I think this method should return a StringRef instead of an std::string because 
the const char* returned by getFilename should live at least as long as the 
source manager.



Comment at: tools/clang-doc/ClangDoc.cpp:85
+  continue;
+std::shared_ptr CI = std::make_shared();
+Reporter.parseFullComment(Comment->parse(*Context, nullptr, nullptr), CI);

So haven't looked enough at the reporter code yet but it seems to me this 
should a unique pointer. You seem to already be aware of that based on a TODO I 
saw in the reporter code though. Is it possible that "parseFullComent" should 
just take a plain old pointer instead of a unique_ptr or shared_ptr? 



Comment at: tools/clang-doc/ClangDoc.cpp:92
+
+bool ClangDocVisitor::isUnparsed(SourceLocation Loc) const {
+  if (!Loc.isValid())

Can you add a comment documenting what this function does?



Comment at: tools/clang-doc/ClangDoc.cpp:108
+  if (const auto *Ctor = dyn_cast(D))
+MC->mangleCXXCtor(Ctor, CXXCtorType::Ctor_Complete, MangledName);
+  else if (const auto *Dtor = dyn_cast(D))

I think it's kind of annoying that this can't be a const method because of 
these mangle calls. I don't really understand why MangleContext works the way 
that it does but it could be that this is a situation where the "mutable" 
keyword should be used on MC to allow what should be a const method to actully 
be const. That might be something to look into.



Comment at: tools/clang-doc/ClangDoc.cpp:113
+MC->mangleName(D, MangledName);
+  return MangledName.str();
+}

I think you want to return S here so that the move constructor is used instead. 
str() returns a reference to S which will cause the copy constructor to be 
called. I *think* most std::string implementations have a copy on write 
optimization but it's strictly more ideal to use the move constructor.



Comment at: tools/clang-doc/ClangDoc.cpp:123
+ClangDocAction::CreateASTConsumer(CompilerInstance &C, StringRef InFile) {
+  return make_unique(&C.getASTContext(), Reporter);
+}

Pro Tip: Always explicitly refer to this as "llvm::make_unique" because you'll 
have to revert this change if you don't.

Some of the build bots have C++14 headers instead of C++11 headers. This means 
that llvm::make_unique and std::make_unique will both be defined. This means 
that using "make_unique" will cause an error even though only llvm::make_unique 
can be referred to unqualified. So even if you're inside of the llvm namespace 
you should explicitly refer to "llvm::make_unique" and n

[PATCH] D42174: [clangd] Refactored threading in ClangdServer

2018-01-30 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov marked 2 inline comments as done.
ilya-biryukov added a comment.

All comments should be addressed now. Let me know if I missed anything else.




Comment at: clangd/threading/TUScheduler.h:1
+//===--- TUScheduler.h ---*-C++-*-===//
+//

ilya-biryukov wrote:
> sammccall wrote:
> > this class needs tests
> Will do :-(
Added a simple test for it. Please take a look and let me know if you have more 
ideas on how we should test it.



Comment at: clangd/threading/ThreadPool.h:1
+//===--- ThreadPool.h *- 
C++-*-===//
+//

ilya-biryukov wrote:
> sammccall wrote:
> > this class needs tests
> Will do :-(
We have `ClangdThreadingTest.StressTest` and `TUSchedulerTests` that both run 
concurrent operations on `ThreadPool`.
As you pointed out, this should provide enough coverage for `ThreadPool`, so I 
didn't create any extra tests for it. 


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42174



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


[PATCH] D42174: [clangd] Refactored threading in ClangdServer

2018-01-30 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 132100.
ilya-biryukov added a comment.

- Properly ignore errors.
- Run all requests to completion when destroying ThreadPool.
- Added simple tests for TUScheduler.
- Fixed include guards.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42174

Files:
  clangd/CMakeLists.txt
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnitStore.h
  clangd/TUScheduler.cpp
  clangd/TUScheduler.h
  clangd/Threading.cpp
  clangd/Threading.h
  unittests/clangd/CMakeLists.txt
  unittests/clangd/TUSchedulerTests.cpp

Index: unittests/clangd/TUSchedulerTests.cpp
===
--- /dev/null
+++ unittests/clangd/TUSchedulerTests.cpp
@@ -0,0 +1,176 @@
+//===-- TUSchedulerTests.cpp *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "TUScheduler.h"
+#include "TestFS.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+
+namespace clang {
+namespace clangd {
+
+using ::testing::Pair;
+using ::testing::Pointee;
+
+void ignoreUpdate(Context, llvm::Optional>) {}
+void ignoreError(llvm::Error Err) {
+  handleAllErrors(std::move(Err), [](const llvm::ErrorInfoBase &) {});
+}
+
+class TUSchedulerTests : public ::testing::Test {
+protected:
+  ParseInputs getInputs(PathRef File, std::string Contents) {
+return ParseInputs{*CDB.getCompileCommand(File), buildTestFS(Files),
+   std::move(Contents)};
+  }
+
+  void changeFile(PathRef File, std::string Contents) {
+Files[File] = Contents;
+  }
+
+private:
+  llvm::StringMap Files;
+  MockCompilationDatabase CDB;
+};
+
+TEST_F(TUSchedulerTests, MissingFiles) {
+  TUScheduler S(getDefaultAsyncThreadsCount(),
+/*StorePreamblesInMemory=*/true,
+/*ASTParsedCallback=*/nullptr);
+
+  auto Added = getVirtualTestFilePath("added.cpp");
+  changeFile(Added, "");
+
+  auto Missing = getVirtualTestFilePath("missing.cpp");
+  changeFile(Missing, "");
+
+  S.update(Context::empty(), Added, getInputs(Added, ""), ignoreUpdate);
+
+  // Assert each operation for missing file is an error (even if it's available
+  // in VFS).
+  S.runWithAST(Missing, [&](llvm::Expected AST) {
+ASSERT_FALSE(bool(AST));
+ignoreError(AST.takeError());
+  });
+  S.runWithPreamble(Missing, [&](llvm::Expected Preamble) {
+ASSERT_FALSE(bool(Preamble));
+ignoreError(Preamble.takeError());
+  });
+  S.remove(Missing, [&](llvm::Error Err) {
+EXPECT_TRUE(bool(Err));
+ignoreError(std::move(Err));
+  });
+
+  // Assert there aren't any errors for added file.
+  S.runWithAST(
+  Added, [&](llvm::Expected AST) { EXPECT_TRUE(bool(AST)); });
+  S.runWithPreamble(Added, [&](llvm::Expected Preamble) {
+EXPECT_TRUE(bool(Preamble));
+  });
+  S.remove(Added, [&](llvm::Error Err) { EXPECT_FALSE(bool(Err)); });
+
+  // Assert that all operations fail after removing the file.
+  S.runWithAST(Added, [&](llvm::Expected AST) {
+ASSERT_FALSE(bool(AST));
+ignoreError(AST.takeError());
+  });
+  S.runWithPreamble(Added, [&](llvm::Expected Preamble) {
+ASSERT_FALSE(bool(Preamble));
+ignoreError(Preamble.takeError());
+  });
+  S.remove(Added, [&](llvm::Error Err) {
+EXPECT_TRUE(bool(Err));
+ignoreError(std::move(Err));
+  });
+}
+
+TEST_F(TUSchedulerTests, ManyUpdates) {
+  const int FilesCount = 3;
+  const int UpdatesPerFile = 10;
+
+  std::mutex Mut;
+  int TotalASTReads = 0;
+  int TotalPreambleReads = 0;
+  int TotalUpdates = 0;
+
+  // Run TUScheduler and collect some stats.
+  {
+TUScheduler S(getDefaultAsyncThreadsCount(),
+  /*StorePreamblesInMemory=*/true,
+  /*ASTParsedCallback=*/nullptr);
+
+std::vector Files;
+for (int I = 0; I < FilesCount; ++I) {
+  Files.push_back(
+  getVirtualTestFilePath("foo" + std::to_string(I) + ".cpp").str());
+  changeFile(Files.back(), "");
+}
+
+llvm::StringRef Contents1 = R"cpp(int a;)cpp";
+llvm::StringRef Contents2 = R"cpp(int main() { return 1; })cpp";
+llvm::StringRef Contents3 =
+R"cpp(int a; int b; int sum() { return a + b; })cpp";
+
+llvm::StringRef AllContents[] = {Contents1, Contents2, Contents3};
+const int AllContentsSize = 3;
+
+for (int FileI = 0; FileI < FilesCount; ++FileI) {
+  for (int UpdateI = 0; UpdateI < UpdatesPerFile; ++UpdateI) {
+auto Contents = AllContents[(FileI + UpdateI) % AllContentsSize];
+
+auto File = Files[FileI];
+auto Inputs = getInputs(File, Contents.str());
+static Key> FileAndUpdateKey;
+auto Ctx = Context::empty().derive(FileAndUpdateKey,
+   std::make_pair(Fi

[PATCH] D42660: [PR32482] Fix bitfield layout for -mms-bitfield and pragma pack

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

Oh, that makes much more sense, thanks.


Repository:
  rL LLVM

https://reviews.llvm.org/D42660



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


[PATCH] D37831: [WebAssembly] Don't pass -ffunction-section/-fdata-sections

2018-01-30 Thread Sam Clegg via Phabricator via cfe-commits
sbc100 added a comment.

After a little discussion about this and the -gc-sections linker flag, the 
augments for the tools having sensible defaults seem to be winning.

This means we don't need the driver to pass these options, which makes our 
commands lines shorter, and it also means that people who use the tools 
directly get the sensible defaults too.


Repository:
  rC Clang

https://reviews.llvm.org/D37831



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


[PATCH] D37831: [WebAssembly] Don't pass -ffunction-section/-fdata-sections by default

2018-01-30 Thread Sam Clegg via Phabricator via cfe-commits
sbc100 updated this revision to Diff 132098.
sbc100 added a comment.
Herald added subscribers: cfe-commits, sunfish.

- update tests


Repository:
  rC Clang

https://reviews.llvm.org/D37831

Files:
  lib/Driver/ToolChains/CommonArgs.cpp
  test/Driver/wasm-toolchain.c
  test/Driver/wasm-toolchain.cpp


Index: test/Driver/wasm-toolchain.cpp
===
--- test/Driver/wasm-toolchain.cpp
+++ test/Driver/wasm-toolchain.cpp
@@ -1,21 +1,8 @@
 // A basic clang -cc1 command-line. WebAssembly is somewhat special in
-// enabling -ffunction-sections, -fdata-sections, and -fvisibility=hidden by
-// default.
+// enabling -fvisibility=hidden by default.
 
 // RUN: %clangxx %s -### -no-canonical-prefixes -target wasm32-unknown-unknown 
2>&1 | FileCheck -check-prefix=CC1 %s
-// CC1: clang{{.*}} "-cc1" "-triple" "wasm32-unknown-unknown" {{.*}} 
"-fvisibility" "hidden" {{.*}} "-ffunction-sections" "-fdata-sections"
-
-// Ditto, but ensure that a user -fno-function-sections disables the
-// default -ffunction-sections.
-
-// RUN: %clangxx %s -### -target wasm32-unknown-unknown -fno-function-sections 
2>&1 | FileCheck -check-prefix=NO_FUNCTION_SECTIONS %s
-// NO_FUNCTION_SECTIONS-NOT: function-sections
-
-// Ditto, but ensure that a user -fno-data-sections disables the
-// default -fdata-sections.
-
-// RUN: %clangxx %s -### -target wasm32-unknown-unknown -fno-data-sections 
2>&1 | FileCheck -check-prefix=NO_DATA_SECTIONS %s
-// NO_DATA_SECTIONS-NOT: data-sections
+// CC1: clang{{.*}} "-cc1" "-triple" "wasm32-unknown-unknown" {{.*}} 
"-fvisibility" "hidden" {{.*}}
 
 // Ditto, but ensure that a user -fvisibility=default disables the default
 // -fvisibility=hidden.
Index: test/Driver/wasm-toolchain.c
===
--- test/Driver/wasm-toolchain.c
+++ test/Driver/wasm-toolchain.c
@@ -1,21 +1,8 @@
 // A basic clang -cc1 command-line. WebAssembly is somewhat special in
-// enabling -ffunction-sections, -fdata-sections, and -fvisibility=hidden by
-// default.
+// enabling -fvisibility=hidden by default.
 
 // RUN: %clang %s -### -no-canonical-prefixes -target wasm32-unknown-unknown 
2>&1 | FileCheck -check-prefix=CC1 %s
-// CC1: clang{{.*}} "-cc1" "-triple" "wasm32-unknown-unknown" {{.*}} 
"-fvisibility" "hidden" {{.*}} "-ffunction-sections" "-fdata-sections"
-
-// Ditto, but ensure that a user -fno-function-sections disables the
-// default -ffunction-sections.
-
-// RUN: %clang %s -### -target wasm32-unknown-unknown -fno-function-sections 
2>&1 | FileCheck -check-prefix=NO_FUNCTION_SECTIONS %s
-// NO_FUNCTION_SECTIONS-NOT: function-sections
-
-// Ditto, but ensure that a user -fno-data-sections disables the
-// default -fdata-sections.
-
-// RUN: %clang %s -### -target wasm32-unknown-unknown -fno-data-sections 2>&1 
| FileCheck -check-prefix=NO_DATA_SECTIONS %s
-// NO_DATA_SECTIONS-NOT: data-sections
+// CC1: clang{{.*}} "-cc1" "-triple" "wasm32-unknown-unknown" {{.*}} 
"-fvisibility" "hidden" {{.*}}
 
 // Ditto, but ensure that a user -fvisibility=default disables the default
 // -fvisibility=hidden.
Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -363,12 +363,9 @@
   return Parallelism;
 }
 
-// CloudABI and WebAssembly use -ffunction-sections and -fdata-sections by
-// default.
+// CloudABI uses -ffunction-sections and -fdata-sections by default.
 bool tools::isUseSeparateSections(const llvm::Triple &Triple) {
-  return Triple.getOS() == llvm::Triple::CloudABI ||
- Triple.getArch() == llvm::Triple::wasm32 ||
- Triple.getArch() == llvm::Triple::wasm64;
+  return Triple.getOS() == llvm::Triple::CloudABI;
 }
 
 void tools::AddGoldPlugin(const ToolChain &ToolChain, const ArgList &Args,


Index: test/Driver/wasm-toolchain.cpp
===
--- test/Driver/wasm-toolchain.cpp
+++ test/Driver/wasm-toolchain.cpp
@@ -1,21 +1,8 @@
 // A basic clang -cc1 command-line. WebAssembly is somewhat special in
-// enabling -ffunction-sections, -fdata-sections, and -fvisibility=hidden by
-// default.
+// enabling -fvisibility=hidden by default.
 
 // RUN: %clangxx %s -### -no-canonical-prefixes -target wasm32-unknown-unknown 2>&1 | FileCheck -check-prefix=CC1 %s
-// CC1: clang{{.*}} "-cc1" "-triple" "wasm32-unknown-unknown" {{.*}} "-fvisibility" "hidden" {{.*}} "-ffunction-sections" "-fdata-sections"
-
-// Ditto, but ensure that a user -fno-function-sections disables the
-// default -ffunction-sections.
-
-// RUN: %clangxx %s -### -target wasm32-unknown-unknown -fno-function-sections 2>&1 | FileCheck -check-prefix=NO_FUNCTION_SECTIONS %s
-// NO_FUNCTION_SECTIONS-NOT: function-sections
-
-// Ditto, but ensure that a user -fno-data-sections disables the
-// default -fdata-sections.
-
-// RUN: %clangxx %s -### -target wasm32

[PATCH] D42725: IRGen: Move vtable load after argument evaluation.

2018-01-30 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc created this revision.
pcc added reviewers: vlad.tsyrklevich, rsmith.

This change reduces the live range of the loaded function pointer,
resulting in a slight code size decrease (~10KB in clang), and also
improves the security of CFI for virtual calls by making it less
likely that the function pointer will be spilled, and ensuring that
it is not spilled across a function call boundary.

Fixes PR35353.


https://reviews.llvm.org/D42725

Files:
  clang/lib/CodeGen/CGCXXABI.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGCall.h
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/test/CodeGenCXX/cfi-vcall-check-after-args.cpp
  clang/test/CodeGenCXX/cxx2a-destroying-delete.cpp
  clang/test/CodeGenCXX/microsoft-abi-multiple-nonvirtual-inheritance.cpp
  clang/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp
  
clang/test/CodeGenCXX/microsoft-abi-vtables-multiple-nonvirtual-inheritance-this-adjustment.cpp

Index: clang/test/CodeGenCXX/microsoft-abi-vtables-multiple-nonvirtual-inheritance-this-adjustment.cpp
===
--- clang/test/CodeGenCXX/microsoft-abi-vtables-multiple-nonvirtual-inheritance-this-adjustment.cpp
+++ clang/test/CodeGenCXX/microsoft-abi-vtables-multiple-nonvirtual-inheritance-this-adjustment.cpp
@@ -156,23 +156,17 @@
 
 // BITCODE-LABEL: define {{.*}}\01?ffun@test4@@YAXAAUC@1@@Z
 void ffun(C &c) {
-  // BITCODE: load
-  // BITCODE: bitcast
-  // BITCODE: bitcast
   // BITCODE: [[THIS1:%.+]] = bitcast %"struct.test4::C"* {{.*}} to i8*
   // BITCODE: [[THIS2:%.+]] = getelementptr inbounds i8, i8* [[THIS1]], i32 4
-  // BITCODE-NEXT: call x86_thiscallcc {{.*}}(i8* [[THIS2]])
+  // BITCODE: call x86_thiscallcc {{.*}}(i8* [[THIS2]])
   c.bar();
 }
 
 // BITCODE-LABEL: define {{.*}}\01?fop@test4@@YAXAAUC@1@@Z
 void fop(C &c) {
-  // BITCODE: load
-  // BITCODE: bitcast
-  // BITCODE: bitcast
   // BITCODE: [[THIS1:%.+]] = bitcast %"struct.test4::C"* {{.*}} to i8*
   // BITCODE: [[THIS2:%.+]] = getelementptr inbounds i8, i8* [[THIS1]], i32 4
-  // BITCODE-NEXT: call x86_thiscallcc {{.*}}(i8* [[THIS2]])
+  // BITCODE: call x86_thiscallcc {{.*}}(i8* [[THIS2]])
   -c;
 }
 
Index: clang/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp
===
--- clang/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp
+++ clang/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp
@@ -163,20 +163,20 @@
 // CHECK: %[[VBENTRY:.*]] = getelementptr inbounds i32, i32* %[[VBTABLE]], i32 1
 // CHECK: %[[VBOFFSET32:.*]] = load i32, i32* %[[VBENTRY]]
 // CHECK: %[[VBOFFSET:.*]] = add nsw i32 0, %[[VBOFFSET32]]
-// CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8, i8* %[[OBJ_i8]], i32 %[[VBOFFSET]]
-// CHECK: %[[VFPTR:.*]] = bitcast i8* %[[VBASE_i8]] to void (i8*)***
-// CHECK: %[[VFTABLE:.*]] = load void (i8*)**, void (i8*)*** %[[VFPTR]]
-// CHECK: %[[VFUN:.*]] = getelementptr inbounds void (i8*)*, void (i8*)** %[[VFTABLE]], i64 2
-// CHECK: %[[VFUN_VALUE:.*]] = load void (i8*)*, void (i8*)** %[[VFUN]]
+// CHECK: %[[VBASE:.*]] = getelementptr inbounds i8, i8* %[[OBJ_i8]], i32 %[[VBOFFSET]]
 //
 // CHECK: %[[OBJ_i8:.*]] = bitcast %struct.B* %[[OBJ]] to i8*
 // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8, i8* %[[OBJ_i8]], i32 0
 // CHECK: %[[VBPTR8:.*]] = bitcast i8* %[[VBPTR]] to i32**
 // CHECK: %[[VBTABLE:.*]] = load i32*, i32** %[[VBPTR8]]
 // CHECK: %[[VBENTRY:.*]] = getelementptr inbounds i32, i32* %[[VBTABLE]], i32 1
 // CHECK: %[[VBOFFSET32:.*]] = load i32, i32* %[[VBENTRY]]
 // CHECK: %[[VBOFFSET:.*]] = add nsw i32 0, %[[VBOFFSET32]]
-// CHECK: %[[VBASE:.*]] = getelementptr inbounds i8, i8* %[[OBJ_i8]], i32 %[[VBOFFSET]]
+// CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8, i8* %[[OBJ_i8]], i32 %[[VBOFFSET]]
+// CHECK: %[[VFPTR:.*]] = bitcast i8* %[[VBASE_i8]] to void (i8*)***
+// CHECK: %[[VFTABLE:.*]] = load void (i8*)**, void (i8*)*** %[[VFPTR]]
+// CHECK: %[[VFUN:.*]] = getelementptr inbounds void (i8*)*, void (i8*)** %[[VFTABLE]], i64 2
+// CHECK: %[[VFUN_VALUE:.*]] = load void (i8*)*, void (i8*)** %[[VFUN]]
 //
 // CHECK: call x86_thiscallcc void %[[VFUN_VALUE]](i8* %[[VBASE]])
 //
@@ -196,10 +196,7 @@
 // CHECK: %[[VBOFFSET32:.*]] = load i32, i32* %[[VBENTRY]]
 // CHECK: %[[VBOFFSET:.*]] = add nsw i32 0, %[[VBOFFSET32]]
 // CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8, i8* %[[OBJ_i8]], i32 %[[VBOFFSET]]
-// CHECK: %[[VFPTR:.*]] = bitcast i8* %[[VBASE_i8]] to i8* (%struct.B*, i32)***
-// CHECK: %[[VFTABLE:.*]] = load i8* (%struct.B*, i32)**, i8* (%struct.B*, i32)*** %[[VFPTR]]
-// CHECK: %[[VFUN:.*]] = getelementptr inbounds i8* (%struct.B*, i32)*, i8* (%struct.B*, i32)** %[[VFTABLE]], i64 0
-// CHECK: %[[VFUN_VALUE:.*]] = load i8* (%struct.B*, i32)*, i8* (%struct.B*, i32)** %[[VFUN]]
+// CHECK: %[[VBASE:.*]] = bitcast i8* %[[VBASE_i8]] to %struct.B*
 //
 // CHECK: %[[OBJ_i8:.*]] = bitcast %st

[PATCH] D41316: [libcxx] Allow random_device to be built optionally

2018-01-30 Thread Weiming Zhao via Phabricator via cfe-commits
weimingz updated this revision to Diff 132089.
weimingz added a comment.
Herald added a subscriber: hintonda.

Disable tests that depend on random_device. 
filesystem tests rely on random_device as seed to create random path. Although 
it's possible to avoid the random_device but if the build target has no 
random_device, it's very possible that neither filesystem nor other seeding 
device like clock is available.


Repository:
  rCXX libc++

https://reviews.llvm.org/D41316

Files:
  CMakeLists.txt
  include/__config_site.in
  include/random
  src/random.cpp
  test/libcxx/experimental/filesystem/lit.local.cfg
  test/std/experimental/filesystem/lit.local.cfg
  test/std/numerics/rand/rand.device/lit.local.cfg

Index: test/std/numerics/rand/rand.device/lit.local.cfg
===
--- /dev/null
+++ test/std/numerics/rand/rand.device/lit.local.cfg
@@ -0,0 +1,3 @@
+# Disable all of the random device tests if the correct feature is not available.
+if 'libcpp-has-no-random-device' in config.available_features:
+  config.unsupported = True
Index: test/std/experimental/filesystem/lit.local.cfg
===
--- test/std/experimental/filesystem/lit.local.cfg
+++ test/std/experimental/filesystem/lit.local.cfg
@@ -1,3 +1,7 @@
 # Disable all of the filesystem tests if the correct feature is not available.
 if 'c++filesystem' not in config.available_features:
   config.unsupported = True
+
+# filesystem_test_helper uses random_device to generate random path.
+if 'libcpp-has-no-random-device' in config.available_features:
+  config.unsupported = True
Index: test/libcxx/experimental/filesystem/lit.local.cfg
===
--- test/libcxx/experimental/filesystem/lit.local.cfg
+++ test/libcxx/experimental/filesystem/lit.local.cfg
@@ -1,3 +1,7 @@
 # Disable all of the filesystem tests if the correct feature is not available.
 if 'c++filesystem' not in config.available_features:
   config.unsupported = True
+
+# filesystem_test_helper uses random_device to generate random path.
+if 'libcpp-has-no-random-device' in config.available_features:
+  config.unsupported = True
Index: src/random.cpp
===
--- src/random.cpp
+++ src/random.cpp
@@ -8,6 +8,7 @@
 //===--===//
 
 #include <__config>
+#ifndef _LIBCPP_HAS_NO_RANDOM_DEVICE
 
 #if defined(_LIBCPP_USING_WIN32_RANDOM)
 // Must be defined before including stdlib.h to enable rand_s().
@@ -177,3 +178,4 @@
 }
 
 _LIBCPP_END_NAMESPACE_STD
+#endif // _LIBCPP_HAS_NO_RANDOM_DEVICE
Index: include/random
===
--- include/random
+++ include/random
@@ -3476,6 +3476,7 @@
 
 typedef shuffle_order_engine knuth_b;
 
+#ifndef _LIBCPP_HAS_NO_RANDOM_DEVICE
 // random_device
 
 class _LIBCPP_TYPE_VIS random_device
@@ -3511,6 +3512,7 @@
 random_device(const random_device&); // = delete;
 random_device& operator=(const random_device&); // = delete;
 };
+#endif // _LIBCPP_HAS_NO_RANDOM_DEVICE
 
 // seed_seq
 
Index: include/__config_site.in
===
--- include/__config_site.in
+++ include/__config_site.in
@@ -20,6 +20,7 @@
 #cmakedefine _LIBCPP_HAS_NO_THREADS
 #cmakedefine _LIBCPP_HAS_NO_MONOTONIC_CLOCK
 #cmakedefine _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
+#cmakedefine _LIBCPP_HAS_NO_RANDOM_DEVICE
 #cmakedefine _LIBCPP_HAS_MUSL_LIBC
 #cmakedefine _LIBCPP_HAS_THREAD_API_PTHREAD
 #cmakedefine _LIBCPP_HAS_THREAD_API_EXTERNAL
Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -71,6 +71,7 @@
 option(LIBCXX_ENABLE_FILESYSTEM "Build filesystem as part of libc++experimental.a"
 ${ENABLE_FILESYSTEM_DEFAULT})
 option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS})
+option(LIBCXX_ENABLE_RANDOM_DEVICE "Build random_device class" On)
 
 # Benchmark options ---
 option(LIBCXX_INCLUDE_BENCHMARKS "Build the libc++ benchmarks and their dependancies" ON)
@@ -629,6 +630,7 @@
 config_define_if_not(LIBCXX_ENABLE_THREADS _LIBCPP_HAS_NO_THREADS)
 config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK)
 config_define_if_not(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS)
+config_define_if_not(LIBCXX_ENABLE_RANDOM_DEVICE _LIBCPP_HAS_NO_RANDOM_DEVICE)
 
 config_define_if(LIBCXX_HAS_PTHREAD_API _LIBCPP_HAS_THREAD_API_PTHREAD)
 config_define_if(LIBCXX_HAS_EXTERNAL_THREAD_API _LIBCPP_HAS_THREAD_API_EXTERNAL)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D26418: [clang-tidy] Add '-suppress-checks-filter' option to suppress diagnostics from certain files

2018-01-30 Thread P F via cfe-commits

> On Jan 30, 2018, at 7:50 AM, Andrew Peter Marlow via Phabricator via 
> cfe-commits  wrote:
> 
> marlowa added a comment.
> 
> In https://reviews.llvm.org/D26418#653146, @nkakuev wrote:
> 
>> Ping.
> 
> 
> another ping. I am desperate for this enhancement and am really glad that 
> nkakuev has done all the hard development work. I am currently being nobbled 
> in my use of clang-tidy because the project is using Rogue Wave Stingray 
> headers and BCG Control bar headers. Both these components cause loads of 
> clang-tidy issues when the headers get included. This enhancement seems to 
> provide just the mechanism I need.

You can already filter headers the same way you filter warnings by using 
`-isystem` flags.


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


Re: r294872 - CodeGen: annotate ObjC ARC functions with ABI constraints

2018-01-30 Thread Saleem Abdulrasool via cfe-commits
Thanks for the note here.  I’ll try to take a look at that, but, yes, the
frontend change itself is correct.  I’ve seen many, many places where the
ObjCARC passes break down in the backend, and I’ve filed a few bugs on it
in the hope that someone from Apple would take a look at some point.  I’m
happy to work on it if someone could help with some of the issues that crop
up.

Instruction bundles would only work partially and not really solve the
problem.  The issue is that even the Post RA scheduler can break apart call
sequences, reordering things.  The Machine Constant Island Pass is another
place this breaks down, as it can create water in between the sequence.
The MI passes tend to expect the bundles to have been broken up, and we
need something which is kept all the way through the MC level.

On Tue, Jan 30, 2018 at 12:38 PM Akira Hatanaka  wrote:

> Hi Saleem,
>
> I had to revert this patch since this patch caused crashes in code that
> was working fine before.
>
> As I mentioned in the commit message, I believe this patch is correct, but
> it causes the
> objc_retainAutoreleasedReturnValue/objc_autoreleaseReturnValue handshake to
> fail in some cases because middle-end and backend passes insert
> instructions between the call to the function returning an object and the
> call to objc_retainAutoreleasedReturnValue. We probably should find a way
> to prevent inserting instructions between the calls (maybe using
> instruction bundles), but we haven’t had the time to implement the fix.
> Feel free to fix the bug if you’d like to do so.
>
> > On Feb 11, 2017, at 1:34 PM, Saleem Abdulrasool via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> >
> > Author: compnerd
> > Date: Sat Feb 11 15:34:18 2017
> > New Revision: 294872
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=294872&view=rev
> > Log:
> > CodeGen: annotate ObjC ARC functions with ABI constraints
> >
> > Certain ARC runtime functions have an ABI contract of being forwarding.
> > Annotate the functions with the appropriate `returned` attribute on the
> > arguments.  This hoists some of the runtime ABI contract information
> > into the frontend rather than the backend transformations.
> >
> > The test adjustments are to mark the returned function parameter as
> > such.  The minor change to the IR output is due to the fact that the
> > returned reference of the object causes it to extend the lifetime of the
> > object by returning an autoreleased return value.  The result is that
> > the explicit objc_autorelease call is no longer formed, as autorelease
> > elision is now possible on the return.
> >
> > Modified:
> >cfe/trunk/lib/CodeGen/CGObjC.cpp
> >cfe/trunk/test/CodeGenObjC/arc.m
> >
> > Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=294872&r1=294871&r2=294872&view=diff
> >
> ==
> > --- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
> > +++ cfe/trunk/lib/CodeGen/CGObjC.cpp Sat Feb 11 15:34:18 2017
> > @@ -1802,6 +1802,22 @@ void CodeGenFunction::EmitARCIntrinsicUs
> > }
> >
> >
> > +static bool IsForwarding(StringRef Name) {
> > +  return llvm::StringSwitch(Name)
> > +  .Cases("objc_autoreleaseReturnValue", //
> ARCInstKind::AutoreleaseRV
> > + "objc_autorelease",//
> ARCInstKind::Autorelease
> > + "objc_retainAutoreleaseReturnValue",   //
> ARCInstKind::FusedRetainAutoreleaseRV
> > + "objc_retainAutoreleasedReturnValue",  //
> ARCInstKind::RetainRV
> > + "objc_retainAutorelease",  //
> ARCInstKind::FusedRetainAutorelease
> > + "objc_retainedObject", //
> ARCInstKind::NoopCast
> > + "objc_retain", //
> ARCInstKind::Retain
> > + "objc_unretainedObject",   //
> ARCInstKind::NoopCast
> > + "objc_unretainedPointer",  //
> ARCInstKind::NoopCast
> > + "objc_unsafeClaimAutoreleasedReturnValue", //
> ARCInstKind::ClaimRV
> > + true)
> > +  .Default(false);
> > +}
> > +
> > static llvm::Constant *createARCRuntimeFunction(CodeGenModule &CGM,
> > llvm::FunctionType *FTy,
> > StringRef Name) {
> > @@ -1819,6 +1835,13 @@ static llvm::Constant *createARCRuntimeF
> >   // performance.
> >   F->addFnAttr(llvm::Attribute::NonLazyBind);
> > }
> > +
> > +if (IsForwarding(Name)) {
> > +  llvm::AttrBuilder B;
> > +  B.addAttribute(llvm::Attribute::Returned);
> > +
> > +  F->arg_begin()->addAttr(llvm::AttributeSet::get(F->getContext(),
> 1, B));
> > +}
> >   }
> >
> >   return RTF;
> >
> > Modified: cfe/trunk/test/CodeGenObjC/arc.m
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc.m?re

[PATCH] D42721: [analyzer] NFC: Use construction contexts for finding the target region for the construction.

2018-01-30 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.
NoQ added a dependency: D42719: [CFG] [analyzer] Add construction context when 
constructor is wrapped into ExprWithCleanups..

Previously, we were scanning the CFG forward in order to find out which CFG 
element contains the expression which is being initialized by the current 
constructor. Now we have all the context that we needed directly in the CFG 
(woohoo). As shown in the previous patches in the stack of patches, the new 
context thing is pretty easy to extend to more cases that we previously didn't 
support at all. More refactoring would follow soon.


Repository:
  rC Clang

https://reviews.llvm.org/D42721

Files:
  include/clang/Analysis/CFG.h
  include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp

Index: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -115,12 +115,14 @@
   const LocationContext *LCtx = Pred->getLocationContext();
   ProgramStateRef State = Pred->getState();
 
-  // See if we're constructing an existing region by looking at the next
-  // element in the CFG.
-
-  if (auto Elem = findElementDirectlyInitializedByCurrentConstructor()) {
-if (Optional StmtElem = Elem->getAs()) {
-  if (const CXXNewExpr *CNE = dyn_cast(StmtElem->getStmt())) {
+  // See if we're constructing an existing region by looking at the
+  // current construction context.
+  const NodeBuilderContext &CurrBldrCtx = getBuilderContext();
+  const CFGBlock *B = CurrBldrCtx.getBlock();
+  const CFGElement &E = (*B)[currStmtIdx];
+  if (auto CC = E.getAs()) {
+if (const Stmt *TriggerStmt = CC->getTriggerStmt()) {
+  if (const CXXNewExpr *CNE = dyn_cast(TriggerStmt)) {
 if (AMgr.getAnalyzerOptions().mayInlineCXXAllocator()) {
   // TODO: Detect when the allocator returns a null pointer.
   // Constructor shall not be called in this case.
@@ -136,20 +138,18 @@
 return MR;
   }
 }
-  } else if (auto *DS = dyn_cast(StmtElem->getStmt())) {
+  } else if (auto *DS = dyn_cast(TriggerStmt)) {
 if (const auto *Var = dyn_cast(DS->getSingleDecl())) {
   if (Var->getInit() && Var->getInit()->IgnoreImplicit() == CE) {
 SVal LValue = State->getLValue(Var, LCtx);
 QualType Ty = Var->getType();
 LValue = makeZeroElementRegion(State, LValue, Ty, CallOpts);
 return LValue.getAsRegion();
   }
 }
-  } else {
-llvm_unreachable("Unexpected directly initialized element!");
   }
-} else if (Optional InitElem = Elem->getAs()) {
-  const CXXCtorInitializer *Init = InitElem->getInitializer();
+  // TODO: Consider other directly initialized elements.
+} else if (const CXXCtorInitializer *Init = CC->getTriggerInit()) {
   assert(Init->isAnyMemberInitializer());
   const CXXMethodDecl *CurCtor = cast(LCtx->getDecl());
   Loc ThisPtr =
@@ -182,56 +182,6 @@
   return MRMgr.getCXXTempObjectRegion(CE, LCtx);
 }
 
-/// Returns true if the initializer for \Elem can be a direct
-/// constructor.
-static bool canHaveDirectConstructor(CFGElement Elem){
-  // DeclStmts and CXXCtorInitializers for fields can be directly constructed.
-
-  if (Optional StmtElem = Elem.getAs()) {
-if (isa(StmtElem->getStmt())) {
-  return true;
-}
-if (isa(StmtElem->getStmt())) {
-  return true;
-}
-  }
-
-  if (Elem.getKind() == CFGElement::Initializer) {
-return true;
-  }
-
-  return false;
-}
-
-Optional
-ExprEngine::findElementDirectlyInitializedByCurrentConstructor() {
-  const NodeBuilderContext &CurrBldrCtx = getBuilderContext();
-  // See if we're constructing an existing region by looking at the next
-  // element in the CFG.
-  const CFGBlock *B = CurrBldrCtx.getBlock();
-  // TODO: Retrieve construction target from CFGConstructor directly.
-  assert(
-  (*B)[currStmtIdx].getAs() ||
-  isa(((*B)[currStmtIdx]).castAs().getStmt()));
-  unsigned int NextStmtIdx = currStmtIdx + 1;
-  if (NextStmtIdx >= B->size())
-return None;
-
-  CFGElement Next = (*B)[NextStmtIdx];
-
-  // Is this a destructor? If so, we might be in the middle of an assignment
-  // to a local or member: look ahead one more element to see what we find.
-  while (Next.getAs() && NextStmtIdx + 1 < B->size()) {
-++NextStmtIdx;
-Next = (*B)[NextStmtIdx];
-  }
-
-  if (canHaveDirectConstructor(Next))
-return Next;
-
-  return None;
-}
-
 const CXXConstructExpr *
 ExprEngine::findDirectConstructorForCurrentCFGElement() {
   // Go backward in the CFG to see if the previous element (ignoring
@@ -243,7 +193,6 @@
 return nullptr;
 
   const CFGBlock *B = getBuilderContext().getBlock();
-  assert(canHa

[PATCH] D42719: [CFG] [analyzer] Add construction context when constructor is wrapped into ExprWithCleanups.

2018-01-30 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

> With this change, we're fully ready to make use of construction contexts in 
> the analyzer (in the next patch).

The next patch is https://reviews.llvm.org/D42721.


Repository:
  rC Clang

https://reviews.llvm.org/D42719



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


[PATCH] D41102: Setup clang-doc frontend framework

2018-01-30 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 132075.
juliehockett edited the summary of this revision.
juliehockett added a reviewer: jakehehrlich.
juliehockett added a comment.

1. Updating and expanding tests
2. Updating output options (can now write to files)
3. Cleaning up pointers and whatnot




https://reviews.llvm.org/D41102

Files:
  test/CMakeLists.txt
  test/Tooling/clang-doc-basic.cpp
  test/Tooling/clang-doc-namespace.cpp
  test/Tooling/clang-doc-type.cpp
  test/lit.cfg.py
  tools/CMakeLists.txt
  tools/clang-doc/CMakeLists.txt
  tools/clang-doc/ClangDoc.cpp
  tools/clang-doc/ClangDoc.h
  tools/clang-doc/ClangDocReporter.cpp
  tools/clang-doc/ClangDocReporter.h
  tools/clang-doc/ClangDocYAML.h
  tools/clang-doc/tool/CMakeLists.txt
  tools/clang-doc/tool/ClangDocMain.cpp

Index: tools/clang-doc/tool/ClangDocMain.cpp
===
--- /dev/null
+++ tools/clang-doc/tool/ClangDocMain.cpp
@@ -0,0 +1,103 @@
+//===-- ClangDocMain.cpp - Clangdoc -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ClangDoc.h"
+#include "clang/Driver/Options.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/APFloat.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
+#include "llvm/Support/Signals.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace clang;
+using namespace llvm;
+
+namespace {
+
+static cl::OptionCategory ClangDocCategory("clang-doc options");
+
+static cl::opt
+OutDirectory("root", cl::desc("Directory for generated files."),
+ cl::init("docs"), cl::cat(ClangDocCategory));
+
+static cl::opt
+EmitLLVM("emit-llvm",
+ cl::desc("Output in LLVM bitstream format (default is YAML)."),
+ cl::init(false), cl::cat(ClangDocCategory));
+
+static cl::opt DumpResult("dump", cl::desc("Dump results to stdout."),
+cl::init(false), cl::cat(ClangDocCategory));
+
+static cl::opt OmitFilenames("omit-filenames",
+   cl::desc("Omit filenames in output."),
+   cl::init(false), cl::cat(ClangDocCategory));
+
+static cl::opt
+DoxygenOnly("doxygen",
+cl::desc("Use only doxygen-style comments to generate docs."),
+cl::init(false), cl::cat(ClangDocCategory));
+
+} // namespace
+
+int main(int argc, const char **argv) {
+  sys::PrintStackTraceOnErrorSignal(argv[0]);
+  tooling::CommonOptionsParser OptionsParser(argc, argv, ClangDocCategory);
+  std::error_code OK;
+
+  doc::OutFormat EmitFormat;
+  SmallString<128> IRFilePath;
+  sys::path::native(OutDirectory, IRFilePath);
+  std::string IRFilename;
+  if (EmitLLVM) {
+EmitFormat = doc::OutFormat::LLVM;
+sys::path::append(IRFilePath, "llvm");
+IRFilename = "docs.bc";
+  } else {
+EmitFormat = doc::OutFormat::YAML;
+sys::path::append(IRFilePath, "yaml");
+IRFilename = "docs.yaml";
+  }
+
+  std::error_code DirectoryStatus = sys::fs::create_directories(IRFilePath);
+  if (DirectoryStatus != OK) {
+errs() << "Unable to create documentation directories.\n";
+return 1;
+  }
+
+  sys::path::append(IRFilePath, IRFilename);
+
+  doc::ClangDocReporter Reporter(OptionsParser.getSourcePathList(),
+ OmitFilenames);
+  doc::ClangDocContext Context{EmitFormat};
+
+  tooling::ClangTool Tool(OptionsParser.getCompilations(),
+  OptionsParser.getSourcePathList());
+
+  if (!DoxygenOnly)
+Tool.appendArgumentsAdjuster(tooling::getInsertArgumentAdjuster(
+"-fparse-all-comments", tooling::ArgumentInsertPosition::BEGIN));
+
+  doc::ClangDocActionFactory Factory(Context, Reporter);
+
+  outs() << "Parsing codebase...\n";
+  int Status = Tool.run(&Factory);
+  if (Status)
+return Status;
+
+  outs() << "Writing intermediate docs...\n";
+  if (DumpResult)
+Reporter.serialize(EmitFormat, "");
+  else
+Reporter.serialize(EmitFormat, IRFilePath);
+  return 0;
+}
Index: tools/clang-doc/tool/CMakeLists.txt
===
--- /dev/null
+++ tools/clang-doc/tool/CMakeLists.txt
@@ -0,0 +1,18 @@
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
+
+add_clang_executable(clang-doc
+  ClangDocMain.cpp
+  )
+
+target_link_libraries(clang-doc
+  PRIVATE
+  clangAST
+  clangASTMatchers
+  clangBasic
+  clangFormat
+  clangFrontend
+  clangDoc
+  clangRewrite
+  clangTooling
+  clangToolingCore
+  )
Index: tools/clang-doc/ClangDocYAML.h
===
--- /dev/null
+++ tools/cl

[PATCH] D42719: [CFG] [analyzer] Add construction context when constructor is wrapped into ExprWithCleanups.

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

As an improvement over https://reviews.llvm.org/D42699 and 
https://reviews.llvm.org/D42700, this unwraps `ExprWithCleanups` surrounding 
immediate constructors of variables which take temporaries as constructor 
arguments (such as `iterator i = begin()` - a copy constructor accepts a 
temporary here).

With this change, we're fully ready to make use of construction contexts in the 
analyzer (in the next patch). Once we do, the plan is to be adding more and 
more construction contexts for the new cases that were not previously supported 
by the analyzer.

Minor refactoring involved.


Repository:
  rC Clang

https://reviews.llvm.org/D42719

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

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
@@ -492,7 +492,7 @@
 // CHECK: 1: [B10.5] ? [B8.6] : [B9.15]
 // CHECK: 2: [B7.1] (ImplicitCastExpr, NoOp, const class A)
 // CHECK: 3: [B7.2]
-// CHECK: 4: [B7.3] (CXXConstructExpr, class A)
+// CHECK: 4: [B7.3] (CXXConstructExpr, [B7.5], class A)
 // CHECK: 5: A a = B() ? A() : A(B());
 // CHECK: T: (Temp Dtor) [B9.2]
 // CHECK: Preds (2): B8 B9
@@ -625,7 +625,7 @@
 // CHECK: 2: [B4.1] (BindTemporary)
 // CHECK: 3: [B4.2] (ImplicitCastExpr, NoOp, const struct C)
 // CHECK: 4: [B4.3]
-// CHECK: 5: [B4.4] (CXXConstructExpr, struct C)
+// CHECK: 5: [B4.4] (CXXConstructExpr, [B4.6], struct C)
 // CHECK: 6: C c = C();
 // CHECK: 7: ~C() (Temporary object destructor)
 // CHECK: 8: c
@@ -675,15 +675,15 @@
 // CHECK: 1: D() (CXXConstructExpr, struct D)
 // CXX98: 2: [B3.1] (ImplicitCastExpr, NoOp, const struct D)
 // CXX98: 3: [B3.2]
-// CXX98: 4: [B3.3] (CXXConstructExpr, struct D)
+// CXX98: 4: [B3.3] (CXXConstructExpr, [B3.5], struct D)
 // CXX98: 5: D d = D();
 // CXX98: 6: d
 // CXX98: 7: [B3.6].operator bool
 // CXX98: 8: [B3.6]
 // CXX98: 9: [B3.8] (ImplicitCastExpr, UserDefinedConversion, _Bool)
 // CXX98: T: if [B3.9]
 // CXX11: 2: [B3.1]
-// CXX11: 3: [B3.2] (CXXConstructExpr, struct D)
+// CXX11: 3: [B3.2] (CXXConstructExpr, [B3.4], struct D)
 // CXX11: 4: D d = D();
 // CXX11: 5: d
 // CXX11: 6: [B3.5].operator bool
@@ -838,7 +838,7 @@
 // CXX11: 1: [B7.3] ?: [B6.6]
 // CHECK: 2: [B4.1] (ImplicitCastExpr, NoOp, const class A)
 // CHECK: 3: [B4.2]
-// CHECK: 4: [B4.3] (CXXConstructExpr, class A)
+// CHECK: 4: [B4.3] (CXXConstructExpr, [B4.5], class A)
 // CHECK: 5: A a = A() ?: A();
 // CHECK: T: (Temp Dtor) [B6.2]
 // CHECK: Preds (2): B5 B6
@@ -993,7 +993,7 @@
 // CHECK: 2: [B1.1] (BindTemporary)
 // CHECK: 3: [B1.2] (ImplicitCastExpr, NoOp, const class A)
 // CHECK: 4: [B1.3]
-// CHECK: 5: [B1.4] (CXXConstructExpr, class A)
+// CHECK: 5: [B1.4] (CXXConstructExpr, [B1.6], class A)
 // CHECK: 6: A a = A();
 // CHECK: 7: ~A() (Temporary object destructor)
 // CHECK: 8: int b;
@@ -1033,7 +1033,7 @@
 // CHECK: 4: [B1.3] (BindTemporary)
 // CHECK: 5: [B1.4] (ImplicitCastExpr, NoOp, const class A)
 // CHECK: 6: [B1.5]
-// CHECK: 7: [B1.6] (CXXConstructExpr, class A)
+// CHECK: 7: [B1.6] (CXXConstructExpr, [B1.8], class A)
 // CHECK: 8: A a = A::make();
 // CHECK: 9: ~A() (Temporary object destructor)
 // CHECK:10: int b;
Index: lib/Analysis/CFG.cpp
===
--- lib/Analysis/CFG.cpp
+++ lib/Analysis/CFG.cpp
@@ -645,6 +645,11 @@
 return Block;
   }
 
+  // Scan the child statement to find various constructors that might have been
+  // triggered by the given trigger.
+  void VisitForConstructionContext(ConstructionContext::TriggerTy Trigger,
+   Stmt *Child);
+
   void autoCreateBlock() { if (!Block) Block = createBlock(); }
   CFGBlock *createBlock(bool add_successor = true);
   CFGBlock *createNoReturnBlock();
@@ -1129,6 +1134,16 @@
   return nullptr;
 }
 
+void CFGBuilder::VisitForConstructionContext(
+ConstructionContext::TriggerTy Trigger, Stmt *Child) {
+  if (!Child)
+return;
+  if (auto *Constructor = dyn_cast(Child))
+CurrentConstructionContext = ConstructionContext(Constructor, Trigger);
+  if (auto *Cleanups = dyn_cast(Child))
+VisitForConstructionContext(Trigger, Cleanups->getSubExpr());
+}
+
 /// BuildCFG - Constructs a CFG from an AST (a Stmt*).  The AST can represent an
 ///  arbitrary statement.  Examples include a single expression or a function
 ///  body (compound statement).  The ownership of the returned CFG is
@@ -1256,8 +1271,7 @@
   ap

[PATCH] D42170: Fixit for 'typedef' instead of 'typename' typo

2018-01-30 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added inline comments.



Comment at: FixIt/fixit-typedef-instead-of-typename-typo.cpp:14
+// CHECK: expected-error@-6 {{unknown type name 'a'}}
+// CHECK: expected-error@-6 {{expected member name or ';' after declaration 
specifiers}}

You don't need `// CHECK:` prefix for `expected-error`. And without `FileCheck` 
CHECK lines aren't verified. In fact, the test should fail as it expects the 
fix-it to be for the line 4, not line 3. I'm not sure you can test diagnostic 
and parseable fixits with a single RUN line, luckily we can have multiple RUN 
lines.

I don't think those relative error lines are good from readability standpoint. 
But please keep in mind that all my comments about readability are subjective 
and should be taken with the grain of salt. The problem is that one needs to 
count lines to understand which line diagnostic is referring to. From my 
experience it is easy to understand something like
```
blah  // expected-error
  // expected-note@-1
```
because you don't need to calculate lines, it is clear -1 refers to the 
previous line. But in your case I have to calculate 6 or 7 lines back.

Here is for comparison "expected-" annotations closer to corresponding lines
```lang=c++
template  // expected-error{{expected template 
parameter}}
 // expected-note@-1{{did you mean to use 
'typename'?}}
// CHECK: fix-it:{{.*}}:{4:23-4:30}:"typename"
struct Foo {
  // Should not produce error about type since parsing speculatively with fixit 
applied.
  B member;
  // Let's just check that other errors get reported.
  a // expected-error{{unknown type name 'a'}}
}; // expected-error{{expected member name or ';' after declaration specifiers}}
```
I'm not entirely happy with the result as it looks too dense and noisy but it 
conveys my thought.


https://reviews.llvm.org/D42170



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


[PATCH] D42444: [analyzer] Extend SuppressInlineDefensiveChecksVisitor to all macros, including non-function-like ones

2018-01-30 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC323827: [analyzer] Extend 
SuppressInlineDefensiveChecksVisitor to all macros, including… (authored by 
george.karpenkov, committed by ).
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D42444

Files:
  lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  test/Analysis/inlining/false-positive-suppression.c
  test/Analysis/plist-macros.cpp

Index: test/Analysis/plist-macros.cpp
===
--- test/Analysis/plist-macros.cpp
+++ test/Analysis/plist-macros.cpp
@@ -65,6 +65,7 @@
   ;
 int useMultiNote(int *p, int y) {;
   y++;
+  if (p) {}
   multiNoteMacro
 
   return *p; // expected-warning {{Dereference of null pointer}}
@@ -1216,7 +1217,41 @@
 // CHECK-NEXT:   
 // CHECK-NEXT:   
 // CHECK-NEXT:line68
-// CHECK-NEXT:col16
+// CHECK-NEXT:col4
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:  
+// CHECK-NEXT:
+// CHECK-NEXT:   
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT:  kindcontrol
+// CHECK-NEXT:  edges
+// CHECK-NEXT:   
+// CHECK-NEXT:
+// CHECK-NEXT: start
+// CHECK-NEXT:  
+// CHECK-NEXT:   
+// CHECK-NEXT:line68
+// CHECK-NEXT:col3
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:   
+// CHECK-NEXT:line68
+// CHECK-NEXT:col4
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:  
+// CHECK-NEXT: end
+// CHECK-NEXT:  
+// CHECK-NEXT:   
+// CHECK-NEXT:line68
+// CHECK-NEXT:col7
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:   
+// CHECK-NEXT:line68
+// CHECK-NEXT:col7
 // CHECK-NEXT:file0
 // CHECK-NEXT:   
 // CHECK-NEXT:  
@@ -1228,20 +1263,20 @@
 // CHECK-NEXT:  location
 // CHECK-NEXT:  
 // CHECK-NEXT:   line68
-// CHECK-NEXT:   col3
+// CHECK-NEXT:   col7
 // CHECK-NEXT:   file0
 // CHECK-NEXT:  
 // CHECK-NEXT:  ranges
 // CHECK-NEXT:  
 // CHECK-NEXT:
 // CHECK-NEXT: 
 // CHECK-NEXT:  line68
-// CHECK-NEXT:  col3
+// CHECK-NEXT:  col7
 // CHECK-NEXT:  file0
 // CHECK-NEXT: 
 // CHECK-NEXT: 
 // CHECK-NEXT:  line68
-// CHECK-NEXT:  col16
+// CHECK-NEXT:  col7
 // CHECK-NEXT:  file0
 // CHECK-NEXT: 
 // CHECK-NEXT:
@@ -1253,23 +1288,57 @@
 // CHECK-NEXT:  Assuming 'p' is null
 // CHECK-NEXT: 
 // CHECK-NEXT: 
+// CHECK-NEXT:  kindcontrol
+// CHECK-NEXT:  edges
+// CHECK-NEXT:   
+// CHECK-NEXT:
+// CHECK-NEXT: start
+// CHECK-NEXT:  
+// CHECK-NEXT:   
+// CHECK-NEXT:line68
+// CHECK-NEXT:col7
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:   
+// CHECK-NEXT:line68
+// CHECK-NEXT:col7
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:  
+// CHECK-NEXT: end
+// CHECK-NEXT:  
+// CHECK-NEXT:   
+// CHECK-NEXT:line69
+// CHECK-NEXT:col3
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:   
+// CHECK-NEXT:line69
+// CHECK-NEXT:col16
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:  
+// CHECK-NEXT:
+// CHECK-NEXT:   
+// CHECK-NEXT: 
+// CHECK-NEXT: 
 // CHECK-NEXT:  kindevent
 // CHECK-NEXT:  location
 // CHECK-NEXT:  
-// CHECK-NEXT:   line68
+// CHECK-NEXT:   line69
 // CHECK-NEXT:   col3
 // CHECK-NEXT:   file0
 // CHECK-NEXT:  
 // CHECK-NEXT:  ranges
 // CHECK-NEXT:  
 // CHECK-NEXT:
 // CHECK-NEXT: 
-// CHECK-NEXT:  line68
+// CHECK-NEXT:  line69
 // CHECK-NEXT:  col3
 // CHECK-NEXT:  file0
 // CHECK-NEXT: 
 // CHECK-NEXT: 
-// CHECK-NEXT:  line68
+// CHECK-NEXT:  line69
 // CHECK-NEXT:  col16
 // CHECK-NEXT:  file0
 // CHECK-NEXT: 
@@ -1289,25 +1358,25 @@
 // CHECK-NEXT: start
 // CHECK-NEXT:  
 // CHECK-NEXT:   
-// CHECK-NEXT:line68
+// CHECK-NEXT:line69
 // CHECK-NEXT:col3
 // CHECK-NEXT:file0
 // CHECK-NEXT:   
 // CHECK-NEXT:   
-// CHECK-NEXT:line68
+// CHECK-NEXT:line69
 // CHECK-NEXT:col16
 // CHECK-NEXT:file0
 // CHECK-NEXT:   
 // CHECK-NEXT:  
 // CHECK-NEXT: end
 // CHECK-NEXT:  
 // CHECK-NEXT:   
-// CHECK-NEX

r323827 - [analyzer] Extend SuppressInlineDefensiveChecksVisitor to all macros, including non-function-like ones

2018-01-30 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Tue Jan 30 14:58:06 2018
New Revision: 323827

URL: http://llvm.org/viewvc/llvm-project?rev=323827&view=rev
Log:
[analyzer] Extend SuppressInlineDefensiveChecksVisitor to all macros, including 
non-function-like ones

No reason to treat function-like macros differently here.

Tracked in rdar://29907377

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/inlining/false-positive-suppression.c
cfe/trunk/test/Analysis/plist-macros.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=323827&r1=323826&r2=323827&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Tue Jan 30 
14:58:06 2018
@@ -921,20 +921,14 @@ SuppressInlineDefensiveChecksVisitor::Vi
 
 SourceLocation TerminatorLoc = CurTerminatorStmt->getLocStart();
 if (TerminatorLoc.isMacroID()) {
-  const SourceManager &SMgr = BRC.getSourceManager();
-  std::pair TLInfo = 
SMgr.getDecomposedLoc(TerminatorLoc);
-  SrcMgr::SLocEntry SE = SMgr.getSLocEntry(TLInfo.first);
-  const SrcMgr::ExpansionInfo &EInfo = SE.getExpansion();
-  if (EInfo.isFunctionMacroExpansion()) {
-SourceLocation BugLoc = BugPoint->getStmt()->getLocStart();
+  SourceLocation BugLoc = BugPoint->getStmt()->getLocStart();
 
-// Suppress reports unless we are in that same macro.
-if (!BugLoc.isMacroID() ||
-getMacroName(BugLoc, BRC) != getMacroName(TerminatorLoc, BRC)) {
-  BR.markInvalid("Suppress Macro IDC", CurLC);
-}
-return nullptr;
+  // Suppress reports unless we are in that same macro.
+  if (!BugLoc.isMacroID() ||
+  getMacroName(BugLoc, BRC) != getMacroName(TerminatorLoc, BRC)) {
+BR.markInvalid("Suppress Macro IDC", CurLC);
   }
+  return nullptr;
 }
   }
   return nullptr;

Modified: cfe/trunk/test/Analysis/inlining/false-positive-suppression.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/false-positive-suppression.c?rev=323827&r1=323826&r2=323827&view=diff
==
--- cfe/trunk/test/Analysis/inlining/false-positive-suppression.c (original)
+++ cfe/trunk/test/Analysis/inlining/false-positive-suppression.c Tue Jan 30 
14:58:06 2018
@@ -111,14 +111,12 @@ void testInlineCheckInNestedMacro(int *p
   *p = 1; // no-warning
 }
 
-// If there is a check in a macro that is not function-like, don't treat
-// it like a function so don't suppress.
 #define NON_FUNCTION_MACRO_WITH_CHECK ( ((p) != 0) ? *p : 17)
 void testNonFunctionMacro(int *p) {
   int i = NON_FUNCTION_MACRO_WITH_CHECK ;
   (void)i;
 
-  *p = 1; // expected-warning {{Dereference of null pointer (loaded from 
variable 'p')}}
+  *p = 1; // no-warning
 }
 
 

Modified: cfe/trunk/test/Analysis/plist-macros.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/plist-macros.cpp?rev=323827&r1=323826&r2=323827&view=diff
==
--- cfe/trunk/test/Analysis/plist-macros.cpp (original)
+++ cfe/trunk/test/Analysis/plist-macros.cpp Tue Jan 30 14:58:06 2018
@@ -65,6 +65,7 @@ if (y) \
   ;
 int useMultiNote(int *p, int y) {;
   y++;
+  if (p) {}
   multiNoteMacro
 
   return *p; // expected-warning {{Dereference of null pointer}}
@@ -1216,7 +1217,41 @@ void test2(int *p) {
 // CHECK-NEXT:   
 // CHECK-NEXT:   
 // CHECK-NEXT:line68
-// CHECK-NEXT:col16
+// CHECK-NEXT:col4
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:  
+// CHECK-NEXT:
+// CHECK-NEXT:   
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT:  kindcontrol
+// CHECK-NEXT:  edges
+// CHECK-NEXT:   
+// CHECK-NEXT:
+// CHECK-NEXT: start
+// CHECK-NEXT:  
+// CHECK-NEXT:   
+// CHECK-NEXT:line68
+// CHECK-NEXT:col3
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:   
+// CHECK-NEXT:line68
+// CHECK-NEXT:col4
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:  
+// CHECK-NEXT: end
+// CHECK-NEXT:  
+// CHECK-NEXT:   
+// CHECK-NEXT:line68
+// CHECK-NEXT:col7
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:   
+// CHECK-NEXT:line68
+// CHECK-NEXT:col7
 // CHECK-NEXT:file0
 // CHECK-NEXT:   
 // CHECK-NEXT:  
@@ -1228,7 +1263,7 @@ void test2(int *p) {
 /

[PATCH] D42645: New simple Checker for mmap calls

2018-01-30 Thread David CARLIER via Phabricator via cfe-commits
devnexen updated this revision to Diff 132054.

Repository:
  rC Clang

https://reviews.llvm.org/D42645

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp

Index: lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
@@ -0,0 +1,78 @@
+// MmapWriteExecChecker.cpp - Check for the prot argument -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This checker tests the 3rd argument of mmap's calls to check if
+// it is writable and executable in the same time. It's somehow
+// an optional checker since for example in JIT libraries it is pretty common.
+//
+//===--===//
+
+#include "ClangSACheckers.h"
+
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+
+using namespace clang;
+using namespace ento;
+using llvm::APSInt;
+
+namespace {
+class MmapWriteExecChecker : public Checker {
+  CallDescription MmapFn;
+  static int ProtWrite;
+  static int ProtExec;
+  mutable std::unique_ptr BT;
+public:
+  MmapWriteExecChecker() : MmapFn("mmap") {}
+  void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
+};
+}
+
+int MmapWriteExecChecker::ProtWrite = 0x02;
+int MmapWriteExecChecker::ProtExec  = 0x04;
+
+void MmapWriteExecChecker::checkPreCall(const CallEvent &Call,
+ CheckerContext &C) const {
+  if (Call.isCalled(MmapFn)) {
+if (Call.getNumArgs() < 3)
+  return;
+
+llvm::Triple Triple = C.getASTContext().getTargetInfo().getTriple();
+
+if (Triple.isOSGlibc())
+  ProtExec = 0x01;
+
+SVal ProtVal = Call.getArgSVal(2); 
+Optional ProtLoc = ProtVal.getAs();
+int64_t Prot = ProtLoc->getValue().getSExtValue();
+
+if ((Prot & (ProtWrite | ProtExec)) == (ProtWrite | ProtExec)) {
+  if (!BT)
+BT.reset(new BugType(this, "W^X check fails", "Write Exec prot flags set"));
+
+  ExplodedNode *N = C.generateErrorNode();
+  if (!N)
+return;
+
+  auto Report = llvm::make_unique(
+  *BT, "Both PROT_WRITE and PROT_EXEC flags had been set. It can "
+   "leads to exploitable memory regions, overwritten with malicious code"
+ , N);
+  Report->addRange(Call.getArgSourceRange(2));
+  C.emitReport(std::move(Report));
+}
+  }
+}
+
+void ento::registerMmapWriteExecChecker(CheckerManager &mgr) {
+  mgr.registerChecker();
+}
Index: lib/StaticAnalyzer/Checkers/CMakeLists.txt
===
--- lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -49,6 +49,7 @@
   MallocChecker.cpp
   MallocOverflowSecurityChecker.cpp
   MallocSizeofChecker.cpp
+  MmapWriteExecChecker.cpp
   MisusedMovedObjectChecker.cpp
   MPI-Checker/MPIBugReporter.cpp
   MPI-Checker/MPIChecker.cpp
Index: include/clang/StaticAnalyzer/Checkers/Checkers.td
===
--- include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -86,7 +86,7 @@
 
 // The APIModeling package is for checkers that model APIs and don't perform
 // any diagnostics. These checkers are always turned on; this package is
-// intended for API modeling that is not controlled by the target triple.
+// intended for API modeling that is not controlled by the the target triple.
 def APIModeling : Package<"apiModeling">, Hidden;
 def GoogleAPIModeling : Package<"google">, InPackage;
 
@@ -394,6 +394,10 @@
   def FloatLoopCounter : Checker<"FloatLoopCounter">,
 HelpText<"Warn on using a floating point value as a loop counter (CERT: FLP30-C, FLP30-CPP)">,
 DescFile<"CheckSecuritySyntaxOnly.cpp">;
+
+  def MmapWriteExecChecker : Checker<"MmapWriteExec">,
+HelpText<"Check if mmap() call is not both writable and executable">,
+DescFile<"MmapWriteExecChecker.cpp">;
 }
 
 let ParentPackage = SecurityAlpha in {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42672: [CFG] [analyzer] Heavier CFGConstructor elements.

2018-01-30 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 132053.
NoQ added a comment.

Remove the stack of contexts for now. We're not using it anywhere yet, and i'm 
not sure if it'd be necessary.


https://reviews.llvm.org/D42672

Files:
  include/clang/Analysis/AnalysisDeclContext.h
  include/clang/Analysis/CFG.h
  include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  lib/Analysis/AnalysisDeclContext.cpp
  lib/Analysis/CFG.cpp
  lib/Analysis/LiveVariables.cpp
  lib/StaticAnalyzer/Core/AnalysisManager.cpp
  lib/StaticAnalyzer/Core/CoreEngine.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  lib/StaticAnalyzer/Core/PathDiagnostic.cpp
  test/Analysis/cfg.cpp

Index: test/Analysis/cfg.cpp
===
--- test/Analysis/cfg.cpp
+++ test/Analysis/cfg.cpp
@@ -116,7 +116,7 @@
 // CHECK-NEXT:   Succs (1): B1
 // CHECK: [B1]
 // CHECK-NEXT:   1:  CFGNewAllocator(A *)
-// CHECK-NEXT:   2:  (CXXConstructExpr, class A)
+// CHECK-NEXT:   2:  (CXXConstructExpr, [B1.3], class A)
 // CHECK-NEXT:   3: new A([B1.2])
 // CHECK-NEXT:   4: A *a = new A();
 // CHECK-NEXT:   5: a
@@ -138,7 +138,7 @@
 // CHECK: [B1]
 // CHECK-NEXT:   1: 5
 // CHECK-NEXT:   2: CFGNewAllocator(A *)
-// CHECK-NEXT:   3:  (CXXConstructExpr, class A [5])
+// CHECK-NEXT:   3:  (CXXConstructExpr, [B1.4], class A [5])
 // CHECK-NEXT:   4: new A {{\[\[}}B1.1]]
 // CHECK-NEXT:   5: A *a = new A [5];
 // CHECK-NEXT:   6: a
@@ -331,7 +331,7 @@
 // CHECK-NEXT:  3: [B1.2] (ImplicitCastExpr, ArrayToPointerDecay, int *)
 // CHECK-NEXT:  4: [B1.3] (ImplicitCastExpr, BitCast, void *)
 // CHECK-NEXT:  5: CFGNewAllocator(MyClass *)
-// CHECK-NEXT:  6:  (CXXConstructExpr, class MyClass)
+// CHECK-NEXT:  6:  (CXXConstructExpr, [B1.7], class MyClass)
 // CHECK-NEXT:  7: new ([B1.4]) MyClass([B1.6])
 // CHECK-NEXT:  8: MyClass *obj = new (buffer) MyClass();
 // CHECK-NEXT:  Preds (1): B2
@@ -363,7 +363,7 @@
 // CHECK-NEXT:  4: [B1.3] (ImplicitCastExpr, BitCast, void *)
 // CHECK-NEXT:  5: 5
 // CHECK-NEXT:  6: CFGNewAllocator(MyClass *)
-// CHECK-NEXT:  7:  (CXXConstructExpr, class MyClass [5])
+// CHECK-NEXT:  7:  (CXXConstructExpr, [B1.8], class MyClass [5])
 // CHECK-NEXT:  8: new ([B1.4]) MyClass {{\[\[}}B1.5]]
 // CHECK-NEXT:  9: MyClass *obj = new (buffer) MyClass [5];
 // CHECK-NEXT:  Preds (1): B2
Index: lib/StaticAnalyzer/Core/PathDiagnostic.cpp
===
--- lib/StaticAnalyzer/Core/PathDiagnostic.cpp
+++ lib/StaticAnalyzer/Core/PathDiagnostic.cpp
@@ -553,6 +553,9 @@
   case CFGElement::Statement:
 return PathDiagnosticLocation(Source.castAs().getStmt(),
   SM, CallerCtx);
+  case CFGElement::Constructor:
+return PathDiagnosticLocation(
+Source.castAs().getConstructor(), SM, CallerCtx);
   case CFGElement::Initializer: {
 const CFGInitializer &Init = Source.castAs();
 return PathDiagnosticLocation(Init.getInitializer()->getInit(),
Index: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -209,7 +209,10 @@
   // See if we're constructing an existing region by looking at the next
   // element in the CFG.
   const CFGBlock *B = CurrBldrCtx.getBlock();
-  assert(isa(((*B)[currStmtIdx]).castAs().getStmt()));
+  // TODO: Retrieve construction target from CFGConstructor directly.
+  assert(
+  (*B)[currStmtIdx].getAs() ||
+  isa(((*B)[currStmtIdx]).castAs().getStmt()));
   unsigned int NextStmtIdx = currStmtIdx + 1;
   if (NextStmtIdx >= B->size())
 return None;
@@ -250,10 +253,14 @@
 Previous = (*B)[PreviousStmtIdx];
   }
 
-  if (Optional PrevStmtElem = Previous.getAs()) {
+  if (auto PrevStmtElem = Previous.getAs()) {
 if (auto *CtorExpr = dyn_cast(PrevStmtElem->getStmt())) {
   return CtorExpr;
 }
+  } else if (auto PrevCtorElem = Previous.getAs()) {
+if (auto *CtorExpr = PrevCtorElem->getConstructor()) {
+  return CtorExpr;
+}
   }
 
   return nullptr;
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -454,10 +454,13 @@
 
   switch (E.getKind()) {
 case CFGElement::Statement:
-  ProcessStmt(const_cast(E.castAs().getStmt()), Pred);
+  ProcessStmt(E.castAs(), Pred);
+  return;
+case CFGElement::Constructor:
+  ProcessConstructor(E.castAs(), Pred);
   return;
 case CFGElement::Initializer:
-  ProcessInitializer(E.castAs().getInitializer(), Pred);
+  ProcessInitializer(E.castAs(), Pred);
   return;
 case CFGElement::NewAllocator:
   ProcessNewAllocator(E.castAs().getAllocatorExpr(),
@@ -479,7 +482,7 @@
 }
 
 static bool shouldRemoveDeadBindings(AnalysisManager &AMgr,
-

[PATCH] D16403: Add scope information to CFG

2018-01-30 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

@szepet: so i see that `LoopExit` goes in the beginning of the cleanup block 
after the loop, while various `ScopeEnd`s go after the `LoopExit`. Would loop 
unrolling be significantly broken if you simply subscribe to `ScopeEnd` instead 
of `LoopExit` and avoid cleaning up the loop state until destructors are 
processed? I might not be remembering correctly - is `LoopExit` only used for 
cleanup, or do we have more work to be done here?


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] D16403: Add scope information to CFG

2018-01-30 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Thank you, this explanation looks very reasonable.

All right, so right after the termination of the loop we have

  [B1]
  1: ForStmt (LoopExit)
  2: [B4.5].~A() (Implicit destructor)
  3: [B5.3].~A() (Implicit destructor)
  4: CFGScopeEnd(a)
  5: CFGScopeEnd(b)

... where `[B4.5]` is `A b = a;` and `[B5.3]` is `A a;`. Am i understanding 
correctly that while destroying `a` you can still use the storage of `b` 
safely? Or should `a` go out of scope before `b` gets destroyed? Also, is the 
order of scope ends actually correct here - shouldn't `b` go out of scope 
earlier? Given that they are in very different lifetime scopes (`a` is one for 
the whole loop, `b` is per-loop-iteration). I guess the order would matter for 
the analyzer.


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] D42650: [clang-format] New format param BinPackObjCProtocolList

2018-01-30 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton marked 3 inline comments as done.
benhamilton added a comment.

Thanks for the review!




Comment at: lib/Format/Format.cpp:765
 GoogleStyle.ColumnLimit = 100;
+GoogleStyle.BinPackObjCProtocolList = FormatStyle::BPS_Never;
   }

stephanemoore wrote:
> I propose that we defer this to a future commit while we establish consensus 
> at Google.
Moved to D42708.



Comment at: unittests/Format/FormatTestObjC.cpp:325-334
+  Style.ColumnLimit = 40;
+  // BinPackParameters should be true by default.
+  verifyFormat("void (int e, int e,\n"
+   "  int e, int e);\n");
+  // BinPackObjCProtocolList should be BPS_Never by default.
+  verifyFormat("@interface f () <\n"
+   "f,\n"

stephanemoore wrote:
> Similar to my other comment, I propose deferring the changes to Google style 
> to a future commit.
Moved to D42708.


Repository:
  rC Clang

https://reviews.llvm.org/D42650



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


[PATCH] D42708: [clang-format] Set BinPackObjCProtocolList to Never for google style

2018-01-30 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added reviewers: krasimir, jolesiak, stephanemoore.

This is split off from https://reviews.llvm.org/D42650, and sets 
BinPackObjCProtocolList
to Never for the google style.

Depends On https://reviews.llvm.org/D42650

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


Repository:
  rC Clang

https://reviews.llvm.org/D42708

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


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -322,13 +322,16 @@
   verifyFormat("@interface Foo (HackStuff) \n"
"+ (id)init;\n"
"@end");
-  Style.BinPackParameters = false;
-  Style.ColumnLimit = 80;
-  verifyFormat("@interface a () <\n"
-   "a,\n"
-   ",\n"
-   "aa,\n"
-   "> {\n"
+  Style.ColumnLimit = 40;
+  // BinPackParameters should be true by default.
+  verifyFormat("void (int e, int e,\n"
+   "  int e, int e);\n");
+  // BinPackObjCProtocolList should be BPS_Never by default.
+  verifyFormat("@interface f () <\n"
+   "f,\n"
+   "f,\n"
+   "f,\n"
+   "f> {\n"
"}");
 }
 
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -762,6 +762,7 @@
 GoogleStyle.SpacesInContainerLiterals = false;
   } else if (Language == FormatStyle::LK_ObjC) {
 GoogleStyle.ColumnLimit = 100;
+GoogleStyle.BinPackObjCProtocolList = FormatStyle::BPS_Never;
   }
 
   return GoogleStyle;


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -322,13 +322,16 @@
   verifyFormat("@interface Foo (HackStuff) \n"
"+ (id)init;\n"
"@end");
-  Style.BinPackParameters = false;
-  Style.ColumnLimit = 80;
-  verifyFormat("@interface a () <\n"
-   "a,\n"
-   ",\n"
-   "aa,\n"
-   "> {\n"
+  Style.ColumnLimit = 40;
+  // BinPackParameters should be true by default.
+  verifyFormat("void (int e, int e,\n"
+   "  int e, int e);\n");
+  // BinPackObjCProtocolList should be BPS_Never by default.
+  verifyFormat("@interface f () <\n"
+   "f,\n"
+   "f,\n"
+   "f,\n"
+   "f> {\n"
"}");
 }
 
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -762,6 +762,7 @@
 GoogleStyle.SpacesInContainerLiterals = false;
   } else if (Language == FormatStyle::LK_ObjC) {
 GoogleStyle.ColumnLimit = 100;
+GoogleStyle.BinPackObjCProtocolList = FormatStyle::BPS_Never;
   }
 
   return GoogleStyle;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42650: [clang-format] New format param BinPackObjCProtocolList

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

Move Google style changes out. Use clearer name for local variable.


Repository:
  rC Clang

https://reviews.llvm.org/D42650

Files:
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  unittests/Format/FormatTestObjC.cpp

Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -281,15 +281,28 @@
"c, c,\n"
"c, c> {\n"
"}");
-
-  Style.BinPackParameters = false;
+  Style.BinPackObjCProtocolList = FormatStyle::BPS_Never;
   verifyFormat("@interface d () <\n"
"d,\n"
"d,\n"
"d,\n"
"d> {\n"
"}");
 
+  Style.BinPackParameters = false;
+  Style.BinPackObjCProtocolList = FormatStyle::BPS_Auto;
+  verifyFormat("@interface e () <\n"
+   "e,\n"
+   "e,\n"
+   "e,\n"
+   "e> {\n"
+   "}");
+  Style.BinPackObjCProtocolList = FormatStyle::BPS_Always;
+  verifyFormat("@interface f () <\n"
+   "f, f,\n"
+   "f, f> {\n"
+   "}");
+
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
   verifyFormat("@interface Foo : NSObject  {\n"
" @public\n"
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -105,6 +105,14 @@
   }
 };
 
+template <> struct ScalarEnumerationTraits {
+  static void enumeration(IO &IO, FormatStyle::BinPackStyle &Value) {
+IO.enumCase(Value, "Auto", FormatStyle::BPS_Auto);
+IO.enumCase(Value, "Always", FormatStyle::BPS_Always);
+IO.enumCase(Value, "Never", FormatStyle::BPS_Never);
+  }
+};
+
 template <> struct ScalarEnumerationTraits {
   static void enumeration(IO &IO, FormatStyle::BinaryOperatorStyle &Value) {
 IO.enumCase(Value, "All", FormatStyle::BOS_All);
@@ -323,6 +331,7 @@
Style.AlwaysBreakTemplateDeclarations);
 IO.mapOptional("BinPackArguments", Style.BinPackArguments);
 IO.mapOptional("BinPackParameters", Style.BinPackParameters);
+IO.mapOptional("BinPackObjCProtocolList", Style.BinPackObjCProtocolList);
 IO.mapOptional("BraceWrapping", Style.BraceWrapping);
 IO.mapOptional("BreakBeforeBinaryOperators",
Style.BreakBeforeBinaryOperators);
@@ -599,6 +608,7 @@
   LLVMStyle.AlwaysBreakTemplateDeclarations = false;
   LLVMStyle.BinPackArguments = true;
   LLVMStyle.BinPackParameters = true;
+  LLVMStyle.BinPackObjCProtocolList = FormatStyle::BPS_Auto;
   LLVMStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_None;
   LLVMStyle.BreakBeforeTernaryOperators = true;
   LLVMStyle.BreakBeforeBraces = FormatStyle::BS_Attach;
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -1222,9 +1222,20 @@
 Current.MatchingParen->getPreviousNonComment() &&
 Current.MatchingParen->getPreviousNonComment()->is(tok::comma);
 
+// If BinPackObjCProtocolList is unspecified, fall back to BinPackParameters
+// for backwards compatibility.
+bool BinPackObjCProtocolList =
+(Style.BinPackObjCProtocolList == FormatStyle::BPS_Auto &&
+ Style.BinPackParameters) ||
+Style.BinPackObjCProtocolList == FormatStyle::BPS_Always;
+
+bool BinPackDeclaration =
+(State.Line->Type != LT_ObjCDecl && Style.BinPackParameters) ||
+(State.Line->Type == LT_ObjCDecl && BinPackObjCProtocolList);
+
 AvoidBinPacking =
 (Style.Language == FormatStyle::LK_JavaScript && EndsInComma) ||
-(State.Line->MustBeDeclaration && !Style.BinPackParameters) ||
+(State.Line->MustBeDeclaration && !BinPackDeclaration) ||
 (!State.Line->MustBeDeclaration && !Style.BinPackArguments) ||
 (Style.ExperimentalAutoDetectBinPacking &&
  (Current.PackingKind == PPK_OnePerLine ||
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -390,6 +390,49 @@
   /// \endcode
   bool BinPackParameters;
 
+  /// \brief The style of wrapping parameters on the same line (bin-packed) or
+  /// on one line each.
+  enum BinPackStyle {
+/// Automatically determine parameter bin-packing behavior.
+BPS_Auto,
+/// Always bin-pack parameters.
+BPS_Always,
+/// Never 

[PATCH] D42641: [MinGW] Emit typeinfo locally for dllimported classes without key functions

2018-01-30 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo updated this revision to Diff 132045.
mstorsjo added a comment.

Adjusted the fix by moving the change into ShouldUseExternalRTTIDescriptor - 
this causes less changes to other tests. @majnemer - do you think this is 
better or worse than having the fix in isVTableExternal?


https://reviews.llvm.org/D42641

Files:
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/dllimport-missing-key.cpp
  test/CodeGenCXX/dllimport-rtti.cpp


Index: test/CodeGenCXX/dllimport-rtti.cpp
===
--- test/CodeGenCXX/dllimport-rtti.cpp
+++ test/CodeGenCXX/dllimport-rtti.cpp
@@ -12,7 +12,7 @@
 // MSVC-DAG: @"\01??_R3S@@8" = linkonce_odr
 
 // GNU-DAG: @_ZTV1S = available_externally dllimport
-// GNU-DAG: @_ZTI1S = external dllimport
+// GNU-DAG: @_ZTI1S = linkonce_odr
 
 struct U : S {
 } u;
Index: test/CodeGenCXX/dllimport-missing-key.cpp
===
--- /dev/null
+++ test/CodeGenCXX/dllimport-missing-key.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple i686-windows-gnu -emit-llvm -std=c++1y -O0 -o - %s 
-w | FileCheck --check-prefix=GNU %s
+
+class __declspec(dllimport) QObjectData {
+public:
+virtual ~QObjectData() = 0;
+void *ptr;
+
+int method() const;
+};
+
+class LocalClass : public QObjectData {
+};
+
+void call() {
+(new LocalClass())->method();
+}
+
+// GNU-DAG: @_ZTV11QObjectData = available_externally dllimport
+// GNU-DAG: @_ZTS11QObjectData = linkonce_odr
+// GNU-DAG: @_ZTI11QObjectData = linkonce_odr
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -2761,6 +2761,11 @@
 // N.B. We must always emit the RTTI data ourselves if there exists a key
 // function.
 bool IsDLLImport = RD->hasAttr();
+
+// Don't import the RTTI but emit it locally
+if (CGM.getTriple().isWindowsGNUEnvironment() && IsDLLImport)
+  return false;
+
 if (CGM.getVTables().isVTableExternal(RD))
   return IsDLLImport && !CGM.getTriple().isWindowsItaniumEnvironment()
  ? false


Index: test/CodeGenCXX/dllimport-rtti.cpp
===
--- test/CodeGenCXX/dllimport-rtti.cpp
+++ test/CodeGenCXX/dllimport-rtti.cpp
@@ -12,7 +12,7 @@
 // MSVC-DAG: @"\01??_R3S@@8" = linkonce_odr
 
 // GNU-DAG: @_ZTV1S = available_externally dllimport
-// GNU-DAG: @_ZTI1S = external dllimport
+// GNU-DAG: @_ZTI1S = linkonce_odr
 
 struct U : S {
 } u;
Index: test/CodeGenCXX/dllimport-missing-key.cpp
===
--- /dev/null
+++ test/CodeGenCXX/dllimport-missing-key.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple i686-windows-gnu -emit-llvm -std=c++1y -O0 -o - %s -w | FileCheck --check-prefix=GNU %s
+
+class __declspec(dllimport) QObjectData {
+public:
+virtual ~QObjectData() = 0;
+void *ptr;
+
+int method() const;
+};
+
+class LocalClass : public QObjectData {
+};
+
+void call() {
+(new LocalClass())->method();
+}
+
+// GNU-DAG: @_ZTV11QObjectData = available_externally dllimport
+// GNU-DAG: @_ZTS11QObjectData = linkonce_odr
+// GNU-DAG: @_ZTI11QObjectData = linkonce_odr
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -2761,6 +2761,11 @@
 // N.B. We must always emit the RTTI data ourselves if there exists a key
 // function.
 bool IsDLLImport = RD->hasAttr();
+
+// Don't import the RTTI but emit it locally
+if (CGM.getTriple().isWindowsGNUEnvironment() && IsDLLImport)
+  return false;
+
 if (CGM.getVTables().isVTableExternal(RD))
   return IsDLLImport && !CGM.getTriple().isWindowsItaniumEnvironment()
  ? false
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r323822 - Add LWG3051

2018-01-30 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Tue Jan 30 13:49:17 2018
New Revision: 323822

URL: http://llvm.org/viewvc/llvm-project?rev=323822&view=rev
Log:
Add LWG3051

Modified:
libcxx/trunk/www/upcoming_meeting.html

Modified: libcxx/trunk/www/upcoming_meeting.html
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/www/upcoming_meeting.html?rev=323822&r1=323821&r2=323822&view=diff
==
--- libcxx/trunk/www/upcoming_meeting.html (original)
+++ libcxx/trunk/www/upcoming_meeting.html Tue Jan 30 13:49:17 2018
@@ -90,6 +90,7 @@
 https://wg21.link/LWG3043";>3043Bogus 
postcondition for filesystem_error 
constructorJacksonville
 https://wg21.link/LWG3045";>3045atomic
 doesn't have value_type or 
difference_typeJacksonville
 https://wg21.link/LWG3048";>3048transform_reduce(exec, 
first1, last1, first2, init) discards execution 
policyJacksonville
+https://wg21.link/LWG3051";>3051Floating 
point classifications were inadvertently changed in 
P0175JacksonvilleNothing to do
 
   
 
@@ -126,6 +127,7 @@
  3043 - We have a 'TODO(ericwf)' here
  3045 - We haven't done the  rework yet.
  3048 - We haven't done the parallel algorithms yet.
+ 3051 - Fixing an inadvertent wording change
 
 
 Last Updated: 29-Jan-2018


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


[PATCH] D42560: [analyzer] dump() ExprEngine's internal traits into the ExplodedGraph view.

2018-01-30 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 132042.
NoQ marked 2 inline comments as done.
NoQ added a comment.

> More debug info is always good.

I know, right?^^

> But that's all bikeshedding though

Well, it's great for me because i'd finally learn how to write programs :)


https://reviews.llvm.org/D42560

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

Index: lib/StaticAnalyzer/Core/ProgramState.cpp
===
--- lib/StaticAnalyzer/Core/ProgramState.cpp
+++ lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -450,7 +450,7 @@
   Mgr.getConstraintManager().print(this, Out, NL, Sep);
 
   // Print checker-specific data.
-  Mgr.getOwningEngine()->printState(Out, this, NL, Sep);
+  Mgr.getOwningEngine()->printState(Out, this, NL, Sep, LC);
 }
 
 void ProgramState::printDOT(raw_ostream &Out, const LocationContext *LC) const {
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -383,8 +383,62 @@
  LCtx, Call);
 }
 
+static void printInitializedTemporariesForContext(raw_ostream &Out,
+  ProgramStateRef State,
+  const char *NL,
+  const char *Sep,
+  const LocationContext *LC) {
+  PrintingPolicy PP =
+  LC->getAnalysisDeclContext()->getASTContext().getPrintingPolicy();
+  for (auto I : State->get()) {
+if (I.second != LC)
+  continue;
+Out << '(' << I.second << ',' << I.first << ") ";
+I.first->printPretty(Out, nullptr, PP);
+Out << NL;
+  }
+}
+
+static void printCXXNewAllocatorValuesForContext(raw_ostream &Out,
+ ProgramStateRef State,
+ const char *NL,
+ const char *Sep,
+ const LocationContext *LC) {
+  PrintingPolicy PP =
+  LC->getAnalysisDeclContext()->getASTContext().getPrintingPolicy();
+
+  for (auto I : State->get()) {
+std::pair Key = I.first;
+SVal Value = I.second;
+if (Key.second != LC)
+  continue;
+Out << '(' << Key.second << ',' << Key.first << ") ";
+Key.first->printPretty(Out, nullptr, PP);
+Out << " : " << Value << NL;
+  }
+}
+
 void ExprEngine::printState(raw_ostream &Out, ProgramStateRef State,
-const char *NL, const char *Sep) {
+const char *NL, const char *Sep,
+const LocationContext *LCtx) {
+  if (LCtx) {
+if (!State->get().isEmpty()) {
+  Out << Sep << "Initialized temporaries:" << NL;
+
+  LCtx->dumpStack(Out, "", NL, Sep, [&](const LocationContext *LC) {
+printInitializedTemporariesForContext(Out, State, NL, Sep, LC);
+  });
+}
+
+if (!State->get().isEmpty()) {
+  Out << Sep << "operator new() allocator return values:" << NL;
+
+  LCtx->dumpStack(Out, "", NL, Sep, [&](const LocationContext *LC) {
+printCXXNewAllocatorValuesForContext(Out, State, NL, Sep, LC);
+  });
+}
+  }
+
   getCheckerManager().runCheckersForPrintState(Out, State, NL, Sep);
 }
 
Index: include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
@@ -155,7 +155,8 @@
 
   /// printState - Called by ProgramStateManager to print checker-specific data.
   virtual void printState(raw_ostream &Out, ProgramStateRef State,
-  const char *NL, const char *Sep) = 0;
+  const char *NL, const char *Sep,
+  const LocationContext *LCtx = nullptr) = 0;
 
   /// Called by CoreEngine when the analysis worklist is either empty or the
   //  maximum number of analysis steps have been reached.
Index: include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -299,8 +299,9 @@
const CallEvent *Call) override;
 
   /// printState - Called by ProgramStateManager to print checker-specific data.
-  void printState(raw_ostream &Out, ProgramStateRef State,
-  const char *NL, const char *Sep) override;
+  void printState(raw_ostream &Out, ProgramStateRef State

[PATCH] D42560: [analyzer] dump() ExprEngine's internal traits into the ExplodedGraph view.

2018-01-30 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: lib/StaticAnalyzer/Core/ExprEngine.cpp:400
+Out << '(' << I.second << ',' << I.first << ") ";
+I.first->printPretty(Out, nullptr, PrintingPolicy(LO));
+Out << NL;

a.sidorin wrote:
> Why not ASTContext::getPrintingPolicy()?
Dunno, maybe the rest of the file should be fixed as well.


https://reviews.llvm.org/D42560



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


[PATCH] D42642: [CUDA] Detect installation in PATH

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

LGTM.




Comment at: lib/Driver/ToolChains/Cuda.cpp:96-105
+  if (llvm::ErrorOr ptxas =
+  llvm::sys::findProgramByName("ptxas")) {
+SmallString<256> ptxasAbsolutePath;
+llvm::sys::fs::real_path(*ptxas, ptxasAbsolutePath);
+
+StringRef ptxasDir = llvm::sys::path::parent_path(ptxasAbsolutePath);
+if (llvm::sys::path::filename(ptxasDir) == "bin")

Hahnfeld wrote:
> tra wrote:
> > Another corner case:
> > Debian scatters CUDA install all over the filesystem. To make it work with 
> > clang it has a 'shim' package which re-creates complete CUDA install using 
> > symlinks to its scattered bits. 
> > https://bugs.llvm.org/show_bug.cgi?id=35249.  If PATH includes such a shim 
> > with a symlink pointing to location somewhere else in the filesystem, this 
> > variant of the patch will not work.
> > 
> > I'd add another candidate derived from the path returned by find. This 
> > should cover all reasonable scenarios I can think of.
> > 
> > Caveat: clang on Debian already has a special case to add this shim to the 
> > list of candidates ( D40453 ), so this patch should not affect it. Still, 
> > it's possible for the similar case to happen somewhere else where we do not 
> > have any explicit workarounds in clang.
> > 
> > BTW, should this heuristic apply on Windows, too? IIRC cuda installer does 
> > add CUDA's bin dir to PATH.
> > 
> I'd rather not complicate this further. I asked on D40453 and the reply was
> >>! In D40453#936114, @sylvestre.ledru wrote:
> > Debian packages don't update the PATH and we are aiming at providing 
> > packages working out of the box.
> 
> So IMO if distributions opt to fully diverge from CUDA's standard directory 
> layout they should add special cases here to make it work.
> 
> I'm not really sure regarding Windows:
> 1. From what I recall the `PATH` variable was somewhat dubious under 
> Windows...
> 2. Does the installer actually allow to customize the installation path? If 
> not, how likely is it that users move the directory manually?
> I can't test on Windows, so I'd generally prefer if you adjust the code and 
> add tests in a separate patch...
I don't have windows either.
OK, we can handle oddball CUDA installations and exotic platforms until someone 
wants it.




https://reviews.llvm.org/D42642



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


[PATCH] D42650: [clang-format] New format param BinPackObjCProtocolList

2018-01-30 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore requested changes to this revision.
stephanemoore added inline comments.
This revision now requires changes to proceed.



Comment at: lib/Format/ContinuationIndenter.cpp:1232
+
+bool BinPackParameters =
+(State.Line->Type != LT_ObjCDecl && Style.BinPackParameters) ||

Given that we now have a new setting distinguishing bin packing of Objective-C 
protocol conformance lists and bin packing of parameters perhaps this local 
variable should be named more generally? Maybe "BinPackDeclaration" would be 
appropriate because this local variable takes effect if 
`State.Line->MustBeDeclaration` is true?



Comment at: lib/Format/Format.cpp:765
 GoogleStyle.ColumnLimit = 100;
+GoogleStyle.BinPackObjCProtocolList = FormatStyle::BPS_Never;
   }

I propose that we defer this to a future commit while we establish consensus at 
Google.



Comment at: unittests/Format/FormatTestObjC.cpp:325-334
+  Style.ColumnLimit = 40;
+  // BinPackParameters should be true by default.
+  verifyFormat("void (int e, int e,\n"
+   "  int e, int e);\n");
+  // BinPackObjCProtocolList should be BPS_Never by default.
+  verifyFormat("@interface f () <\n"
+   "f,\n"

Similar to my other comment, I propose deferring the changes to Google style to 
a future commit.


Repository:
  rC Clang

https://reviews.llvm.org/D42650



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


[PATCH] D42642: [CUDA] Detect installation in PATH

2018-01-30 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld marked 5 inline comments as done.
Hahnfeld added a subscriber: sylvestre.ledru.
Hahnfeld added inline comments.



Comment at: lib/Driver/ToolChains/Cuda.cpp:96-105
+  if (llvm::ErrorOr ptxas =
+  llvm::sys::findProgramByName("ptxas")) {
+SmallString<256> ptxasAbsolutePath;
+llvm::sys::fs::real_path(*ptxas, ptxasAbsolutePath);
+
+StringRef ptxasDir = llvm::sys::path::parent_path(ptxasAbsolutePath);
+if (llvm::sys::path::filename(ptxasDir) == "bin")

tra wrote:
> Another corner case:
> Debian scatters CUDA install all over the filesystem. To make it work with 
> clang it has a 'shim' package which re-creates complete CUDA install using 
> symlinks to its scattered bits. https://bugs.llvm.org/show_bug.cgi?id=35249.  
> If PATH includes such a shim with a symlink pointing to location somewhere 
> else in the filesystem, this variant of the patch will not work.
> 
> I'd add another candidate derived from the path returned by find. This should 
> cover all reasonable scenarios I can think of.
> 
> Caveat: clang on Debian already has a special case to add this shim to the 
> list of candidates ( D40453 ), so this patch should not affect it. Still, 
> it's possible for the similar case to happen somewhere else where we do not 
> have any explicit workarounds in clang.
> 
> BTW, should this heuristic apply on Windows, too? IIRC cuda installer does 
> add CUDA's bin dir to PATH.
> 
I'd rather not complicate this further. I asked on D40453 and the reply was
>>! In D40453#936114, @sylvestre.ledru wrote:
> Debian packages don't update the PATH and we are aiming at providing packages 
> working out of the box.

So IMO if distributions opt to fully diverge from CUDA's standard directory 
layout they should add special cases here to make it work.

I'm not really sure regarding Windows:
1. From what I recall the `PATH` variable was somewhat dubious under Windows...
2. Does the installer actually allow to customize the installation path? If 
not, how likely is it that users move the directory manually?
I can't test on Windows, so I'd generally prefer if you adjust the code and add 
tests in a separate patch...


https://reviews.llvm.org/D42642



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


[PATCH] D42660: [PR32482] Fix bitfield layout for -mms-bitfield and pragma pack

2018-01-30 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Oops, that logic turned out to be incorrect. We simply have to start a new 
storage unit when the new bitfield's size is wider than the available bits.


Repository:
  rL LLVM

https://reviews.llvm.org/D42660



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


[PATCH] D42660: [PR32482] Fix bitfield layout for -mms-bitfield and pragma pack

2018-01-30 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 132034.
arphaman added a comment.
Herald added a subscriber: llvm-commits.

Fix packing logic.


Repository:
  rL LLVM

https://reviews.llvm.org/D42660

Files:
  lib/AST/RecordLayoutBuilder.cpp
  test/CodeGen/mms-bitfields.c
  test/Sema/mms-bitfields.c


Index: test/Sema/mms-bitfields.c
===
--- test/Sema/mms-bitfields.c
+++ test/Sema/mms-bitfields.c
@@ -11,3 +11,18 @@
 
 // MS pads out bitfields between different types.
 static int arr[(sizeof(t) == 8) ? 1 : -1];
+
+#pragma pack (push,1)
+
+typedef unsigned int UINT32;
+
+struct Inner {
+  UINT32A:  1;
+  UINT32B:  1;
+  UINT32C:  1;
+  UINT32D: 30;
+} Inner;
+
+#pragma pack (pop)
+
+static int arr2[(sizeof(Inner) == 8) ? 1 : -1];
Index: test/CodeGen/mms-bitfields.c
===
--- test/CodeGen/mms-bitfields.c
+++ test/CodeGen/mms-bitfields.c
@@ -20,3 +20,46 @@
 } s3;
 
 // CHECK: %struct.s3 = type { i32, [4 x i8], %struct.s1 }
+
+// PR32482:
+
+#pragma pack (push,1)
+
+typedef unsigned int UINT32;
+
+struct Inner {
+  UINT32A:  1;
+  UINT32B:  1;
+  UINT32C:  1;
+  UINT32D: 30;
+} Inner;
+
+#pragma pack (pop)
+
+// CHECK: %struct.Inner = type { i32, i32 }
+
+// CHECK: %struct.A = type { i32, i32, i32 }
+
+#pragma pack(push, 1)
+
+union HEADER {
+  struct A {
+int :  3;  // Bits 2:0
+int a   :  9;  // Bits 11:3
+int :  12;  // Bits 23:12
+int b   :  17;  // Bits 40:24
+int :  7;  // Bits 47:41
+int c   :  4;  // Bits 51:48
+int :  4;  // Bits 55:52
+int d   :  3;  // Bits 58:56
+int :  5;  // Bits 63:59
+  } Bits;
+} HEADER;
+
+#pragma pack(pop)
+
+struct Inner variable = { 1,0,1, 21 };
+union HEADER hdr = {{1,2,3,4}};
+
+// CHECK: @variable = global { i8, [3 x i8], i8, i8, i8, i8 } { i8 5, [3 x i8] 
undef, i8 21, i8 0, i8 0, i8 0 }, align 1
+// CHECK: @hdr = global { { i8, i8, [2 x i8], i8, i8, i8, i8, i8, [3 x i8] } } 
{ { i8, i8, [2 x i8], i8, i8, i8, i8, i8, [3 x i8] } { i8 8, i8 0, [2 x i8] 
undef, i8 2, i8 0, i8 0, i8 3, i8 4, [3 x i8] undef } }, align 1
Index: lib/AST/RecordLayoutBuilder.cpp
===
--- lib/AST/RecordLayoutBuilder.cpp
+++ lib/AST/RecordLayoutBuilder.cpp
@@ -1504,9 +1504,10 @@
 FieldAlign = TypeSize;
 
 // If the previous field was not a bitfield, or was a bitfield
-// with a different storage unit size, we're done with that
-// storage unit.
-if (LastBitfieldTypeSize != TypeSize) {
+// with a different storage unit size, or if this field doesn't fit into
+// the current storage unit, we're done with that storage unit.
+if (LastBitfieldTypeSize != TypeSize ||
+UnfilledBitsInLastUnit < FieldSize) {
   // Also, ignore zero-length bitfields after non-bitfields.
   if (!LastBitfieldTypeSize && !FieldSize)
 FieldAlign = 1;


Index: test/Sema/mms-bitfields.c
===
--- test/Sema/mms-bitfields.c
+++ test/Sema/mms-bitfields.c
@@ -11,3 +11,18 @@
 
 // MS pads out bitfields between different types.
 static int arr[(sizeof(t) == 8) ? 1 : -1];
+
+#pragma pack (push,1)
+
+typedef unsigned int UINT32;
+
+struct Inner {
+  UINT32A:  1;
+  UINT32B:  1;
+  UINT32C:  1;
+  UINT32D: 30;
+} Inner;
+
+#pragma pack (pop)
+
+static int arr2[(sizeof(Inner) == 8) ? 1 : -1];
Index: test/CodeGen/mms-bitfields.c
===
--- test/CodeGen/mms-bitfields.c
+++ test/CodeGen/mms-bitfields.c
@@ -20,3 +20,46 @@
 } s3;
 
 // CHECK: %struct.s3 = type { i32, [4 x i8], %struct.s1 }
+
+// PR32482:
+
+#pragma pack (push,1)
+
+typedef unsigned int UINT32;
+
+struct Inner {
+  UINT32A:  1;
+  UINT32B:  1;
+  UINT32C:  1;
+  UINT32D: 30;
+} Inner;
+
+#pragma pack (pop)
+
+// CHECK: %struct.Inner = type { i32, i32 }
+
+// CHECK: %struct.A = type { i32, i32, i32 }
+
+#pragma pack(push, 1)
+
+union HEADER {
+  struct A {
+int :  3;  // Bits 2:0
+int a   :  9;  // Bits 11:3
+int :  12;  // Bits 23:12
+int b   :  17;  // Bits 40:24
+int :  7;  // Bits 47:41
+int c   :  4;  // Bits 51:48
+int :  4;  // Bits

[PATCH] D42645: New simple Checker for mmap calls

2018-01-30 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ edited reviewers, added: NoQ; removed: dergachev.a.
NoQ added a comment.

Actually, most of our `security` package is off by default (in the driver) for 
that very reason, so please never mind and just keep it in `security` :)

You can also put the checker straight into `security` bypassing `alpha` if 
you're not seeing any obvious problems with it - because it seems fairly 
straightforward and obvious.


Repository:
  rC Clang

https://reviews.llvm.org/D42645



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


[PATCH] D42693: [libcxx] Handle invalid escaped characters in POSIX regex

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



Comment at: include/regex:3465
+case '{':
+case '}':
+break;

FWIW, I don't understand what's going on in this switch.
Is it intentional that `'('` and `'|'` now take different paths here?



Comment at: test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp:60
+assert(!error_escape_thrown("\\.", basic));
+assert(!error_escape_thrown("\\*", basic));
 }

I would think about adding test cases here to document the intended behavior of
- "\\n" and "\\t" which are valid of course;
- "\\\n" which could be a common typo and should probably throw;
- "\\/" which is common in Perl but maybe should throw anyway;
- "\\1" in a regex mode that doesn't support backreferences;
- "\\0".
If these are already covered elsewhere in the suite, then never mind me.


https://reviews.llvm.org/D42693



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


[PATCH] D42645: New simple Checker for mmap calls

2018-01-30 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

> `// It's somehow an optional checker since for example in JIT libraries it is 
> pretty common.`

Dunno, it seems that most of our security checks are something like that, and 
i'm not sure how to deal with it. This one sounds like it would probably go to 
some sort of `optin.security` (off-by-default). I also guess that there's no 
easy suppression, i.e. the user cannot easily change his code to suppress the 
warning in a specific place where it is intentional. In the analyzer we don't 
have many opt-in checks, because we focus more on users that want the analyzer 
to work as best as possible out of the box; for now we don't have a good 
interface for discovering optional checks (until an external entity makes the 
decision for the user while including the analyzer, eg. localization checks in 
Xcode), so most users would probably never see them.

Also, do you need path sensitivity here? Like, if it is not common to pass the 
flags around in variables, or or call `mmap` by function pointer, then you'd 
have equally easy time catching most of these bugs with a simple syntax check, 
maybe a clang-tidy matcher.

Hint - people like it when patches have large contexts (`git diff -U9` or 
something like that), they'd be clickable in the review interface.


Repository:
  rC Clang

https://reviews.llvm.org/D42645



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


[PATCH] D42642: [CUDA] Detect installation in PATH

2018-01-30 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: lib/Driver/ToolChains/Cuda.cpp:96-105
+  if (llvm::ErrorOr ptxas =
+  llvm::sys::findProgramByName("ptxas")) {
+SmallString<256> ptxasAbsolutePath;
+llvm::sys::fs::real_path(*ptxas, ptxasAbsolutePath);
+
+StringRef ptxasDir = llvm::sys::path::parent_path(ptxasAbsolutePath);
+if (llvm::sys::path::filename(ptxasDir) == "bin")

Another corner case:
Debian scatters CUDA install all over the filesystem. To make it work with 
clang it has a 'shim' package which re-creates complete CUDA install using 
symlinks to its scattered bits. https://bugs.llvm.org/show_bug.cgi?id=35249.  
If PATH includes such a shim with a symlink pointing to location somewhere else 
in the filesystem, this variant of the patch will not work.

I'd add another candidate derived from the path returned by find. This should 
cover all reasonable scenarios I can think of.

Caveat: clang on Debian already has a special case to add this shim to the list 
of candidates ( D40453 ), so this patch should not affect it. Still, it's 
possible for the similar case to happen somewhere else where we do not have any 
explicit workarounds in clang.

BTW, should this heuristic apply on Windows, too? IIRC cuda installer does add 
CUDA's bin dir to PATH.



https://reviews.llvm.org/D42642



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


[PATCH] D42704: [clang-format] Do not break Objective-C string literals inside array literals

2018-01-30 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added reviewers: jolesiak, stephanemoore, djasper.
Herald added subscribers: cfe-commits, klimek.

Concatenating Objective-C string literals inside an array literal
raises the warning -Wobjc-string-concatenation (which is enabled by default).

clang-format currently splits and concatenates string literals like
the following:

  NSArray *myArray = @[ @"a" ];

into:

  NSArray *myArray =
@[ @""
   @"a" ];

which raises the warning. This is https://bugs.llvm.org/show_bug.cgi?id=36153 .

The options I can think of to fix this are:

1. Have clang-format disable Wobjc-string-concatenation by emitting

pragmas around the formatted code

2. Have clang-format wrap the string literals in a macro (which

disables the warning)

3. Disable string splitting for Objective-C string literals inside

array literals

I think 1) has no precedent, and I couldn't find a good
identity() macro for 2). So, this diff implements 3).

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


Repository:
  rC Clang

https://reviews.llvm.org/D42704

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


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -915,6 +915,12 @@
   verifyFormat("[someFunction someLongParameter:@[\n"
"  NSBundle.mainBundle.infoDictionary[@\"a\"]\n"
"]];");
+  Style.ColumnLimit = 20;
+  // We can't break string literals inside NSArray literals
+  // (that raises -Wobjc-string-concatenation).
+  verifyFormat("NSArray *foo = @[\n"
+   "  @\"aa\"\n"
+   "];\n");
 }
 } // end namespace
 } // end namespace format
Index: lib/Format/ContinuationIndenter.h
===
--- lib/Format/ContinuationIndenter.h
+++ lib/Format/ContinuationIndenter.h
@@ -208,7 +208,8 @@
 NoLineBreakInOperand(false), LastOperatorWrapped(true),
 ContainsLineBreak(false), ContainsUnwrappedBuilder(false),
 AlignColons(true), ObjCSelectorNameFound(false),
-HasMultipleNestedBlocks(false), NestedBlockInlined(false) {}
+HasMultipleNestedBlocks(false), NestedBlockInlined(false),
+IsInsideObjCArrayLiteral(false) {}
 
   /// \brief The position to which a specific parenthesis level needs to be
   /// indented.
@@ -318,6 +319,10 @@
   // "function" in JavaScript) is not wrapped to a new line.
   bool NestedBlockInlined : 1;
 
+  /// \brief \c true if the current \c ParenState represents an Objective-C
+  /// array literal.
+  bool IsInsideObjCArrayLiteral : 1;
+
   bool operator<(const ParenState &Other) const {
 if (Indent != Other.Indent)
   return Indent < Other.Indent;
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -1270,6 +1270,9 @@
   State.Stack.back().NestedBlockIndent = NestedBlockIndent;
   State.Stack.back().BreakBeforeParameter = BreakBeforeParameter;
   State.Stack.back().HasMultipleNestedBlocks = Current.BlockParameterCount > 1;
+  State.Stack.back().IsInsideObjCArrayLiteral =
+  Current.is(TT_ArrayInitializerLSquare) && Current.Previous &&
+  Current.Previous->is(tok::at);
 }
 
 void ContinuationIndenter::moveStatePastScopeCloser(LineState &State) {
@@ -1562,6 +1565,11 @@
 // likely want to terminate the string before any line breaking is done.
 if (Current.IsUnterminatedLiteral)
   return nullptr;
+// Don't break string literals inside Objective-C array literals (doing so
+// raises the warning -Wobjc-string-concatenation).
+if (State.Stack.back().IsInsideObjCArrayLiteral) {
+  return nullptr;
+}
 
 StringRef Text = Current.TokenText;
 StringRef Prefix;


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -915,6 +915,12 @@
   verifyFormat("[someFunction someLongParameter:@[\n"
"  NSBundle.mainBundle.infoDictionary[@\"a\"]\n"
"]];");
+  Style.ColumnLimit = 20;
+  // We can't break string literals inside NSArray literals
+  // (that raises -Wobjc-string-concatenation).
+  verifyFormat("NSArray *foo = @[\n"
+   "  @\"aa\"\n"
+   "];\n");
 }
 } // end namespace
 } // end namespace format
Index: lib/Format/ContinuationIndenter.h
===
--- lib/Format/ContinuationIndenter.h
+++ lib/Format/ContinuationInde

Re: r294872 - CodeGen: annotate ObjC ARC functions with ABI constraints

2018-01-30 Thread Akira Hatanaka via cfe-commits
Hi Saleem,

I had to revert this patch since this patch caused crashes in code that was 
working fine before.

As I mentioned in the commit message, I believe this patch is correct, but it 
causes the objc_retainAutoreleasedReturnValue/objc_autoreleaseReturnValue 
handshake to fail in some cases because middle-end and backend passes insert 
instructions between the call to the function returning an object and the call 
to objc_retainAutoreleasedReturnValue. We probably should find a way to prevent 
inserting instructions between the calls (maybe using instruction bundles), but 
we haven’t had the time to implement the fix. Feel free to fix the bug if you’d 
like to do so.

> On Feb 11, 2017, at 1:34 PM, Saleem Abdulrasool via cfe-commits 
>  wrote:
> 
> Author: compnerd
> Date: Sat Feb 11 15:34:18 2017
> New Revision: 294872
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=294872&view=rev
> Log:
> CodeGen: annotate ObjC ARC functions with ABI constraints
> 
> Certain ARC runtime functions have an ABI contract of being forwarding.
> Annotate the functions with the appropriate `returned` attribute on the
> arguments.  This hoists some of the runtime ABI contract information
> into the frontend rather than the backend transformations.
> 
> The test adjustments are to mark the returned function parameter as
> such.  The minor change to the IR output is due to the fact that the
> returned reference of the object causes it to extend the lifetime of the
> object by returning an autoreleased return value.  The result is that
> the explicit objc_autorelease call is no longer formed, as autorelease
> elision is now possible on the return.
> 
> Modified:
>cfe/trunk/lib/CodeGen/CGObjC.cpp
>cfe/trunk/test/CodeGenObjC/arc.m
> 
> Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=294872&r1=294871&r2=294872&view=diff
> ==
> --- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGObjC.cpp Sat Feb 11 15:34:18 2017
> @@ -1802,6 +1802,22 @@ void CodeGenFunction::EmitARCIntrinsicUs
> }
> 
> 
> +static bool IsForwarding(StringRef Name) {
> +  return llvm::StringSwitch(Name)
> +  .Cases("objc_autoreleaseReturnValue", // 
> ARCInstKind::AutoreleaseRV
> + "objc_autorelease",// 
> ARCInstKind::Autorelease
> + "objc_retainAutoreleaseReturnValue",   // 
> ARCInstKind::FusedRetainAutoreleaseRV
> + "objc_retainAutoreleasedReturnValue",  // 
> ARCInstKind::RetainRV
> + "objc_retainAutorelease",  // 
> ARCInstKind::FusedRetainAutorelease
> + "objc_retainedObject", // 
> ARCInstKind::NoopCast
> + "objc_retain", // 
> ARCInstKind::Retain
> + "objc_unretainedObject",   // 
> ARCInstKind::NoopCast
> + "objc_unretainedPointer",  // 
> ARCInstKind::NoopCast
> + "objc_unsafeClaimAutoreleasedReturnValue", // 
> ARCInstKind::ClaimRV
> + true)
> +  .Default(false);
> +}
> +
> static llvm::Constant *createARCRuntimeFunction(CodeGenModule &CGM,
> llvm::FunctionType *FTy,
> StringRef Name) {
> @@ -1819,6 +1835,13 @@ static llvm::Constant *createARCRuntimeF
>   // performance.
>   F->addFnAttr(llvm::Attribute::NonLazyBind);
> }
> +
> +if (IsForwarding(Name)) {
> +  llvm::AttrBuilder B;
> +  B.addAttribute(llvm::Attribute::Returned);
> +
> +  F->arg_begin()->addAttr(llvm::AttributeSet::get(F->getContext(), 1, 
> B));
> +}
>   }
> 
>   return RTF;
> 
> Modified: cfe/trunk/test/CodeGenObjC/arc.m
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc.m?rev=294872&r1=294871&r2=294872&view=diff
> ==
> --- cfe/trunk/test/CodeGenObjC/arc.m (original)
> +++ cfe/trunk/test/CodeGenObjC/arc.m Sat Feb 11 15:34:18 2017
> @@ -7,30 +7,30 @@
> // RUN: %clang_cc1 -fobjc-runtime=macosx-10.7.0 -triple x86_64-apple-darwin11 
> -Wno-objc-root-class -Wno-incompatible-pointer-types 
> -Wno-arc-unsafe-retained-assign -emit-llvm -fblocks -fobjc-arc 
> -fobjc-runtime-has-weak -o - %s | FileCheck -check-prefix=ARC-NATIVE %s
> 
> // ARC-ALIEN: declare extern_weak void @objc_storeStrong(i8**, i8*)
> -// ARC-ALIEN: declare extern_weak i8* @objc_retain(i8*)
> -// ARC-ALIEN: declare extern_weak i8* @objc_autoreleaseReturnValue(i8*)
> +// ARC-ALIEN: declare extern_weak i8* @objc_retain(i8* returned)
> +// ARC-ALIEN: declare extern_weak i8* @objc_autoreleaseReturnValue(i8* 
> returned)
> // ARC-ALIEN: declare i8* @objc_msgSend(i8*, i8*, ...) [[NLB:#[0-9]+]]
> // ARC-ALIEN: declare extern_weak void @objc_release(i8*)
> -// 

[PATCH] D42642: [CUDA] Detect installation in PATH

2018-01-30 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld updated this revision to Diff 132029.
Hahnfeld added a comment.

Follow symlinked `ptxas` executables.


https://reviews.llvm.org/D42642

Files:
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/Cuda.cpp
  test/Driver/Inputs/CUDA-nolibdevice/usr/local/cuda/bin/ptxas
  test/Driver/Inputs/CUDA-symlinks/opt/cuda/bin/ptxas
  test/Driver/Inputs/CUDA-symlinks/opt/cuda/include/.keep
  test/Driver/Inputs/CUDA-symlinks/opt/cuda/lib/.keep
  
test/Driver/Inputs/CUDA-symlinks/opt/cuda/nvvm/libdevice/libdevice.compute_30.10.bc
  
test/Driver/Inputs/CUDA-symlinks/opt/cuda/nvvm/libdevice/libdevice.compute_35.10.bc
  test/Driver/Inputs/CUDA-symlinks/usr/bin/ptxas
  test/Driver/Inputs/CUDA/usr/local/cuda/bin/ptxas
  test/Driver/cuda-detect-path.cu
  test/Driver/cuda-detect.cu
  test/Driver/cuda-not-found.cu
  test/Driver/cuda-version-check.cu

Index: test/Driver/cuda-version-check.cu
===
--- test/Driver/cuda-version-check.cu
+++ test/Driver/cuda-version-check.cu
@@ -2,50 +2,50 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target
 
-// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_20 --sysroot=%S/Inputs/CUDA 2>&1 %s | \
+// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_20 --cuda-path=%S/Inputs/CUDA/usr/local/cuda 2>&1 %s | \
 // RUN:FileCheck %s --check-prefix=OK
-// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_20 --sysroot=%S/Inputs/CUDA_80 2>&1 %s | \
+// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_20 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda 2>&1 %s | \
 // RUN:FileCheck %s --check-prefix=OK
-// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --sysroot=%S/Inputs/CUDA_80 2>&1 %s | \
+// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda 2>&1 %s | \
 // RUN:FileCheck %s --check-prefix=OK
 
 // The installation at Inputs/CUDA is CUDA 7.0, which doesn't support sm_60.
-// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --sysroot=%S/Inputs/CUDA 2>&1 %s | \
+// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-path=%S/Inputs/CUDA/usr/local/cuda 2>&1 %s | \
 // RUN:FileCheck %s --check-prefix=ERR_SM60
 
 // This should only complain about sm_60, not sm_35.
 // RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-gpu-arch=sm_35 \
-// RUN:--sysroot=%S/Inputs/CUDA 2>&1 %s | \
+// RUN:--cuda-path=%S/Inputs/CUDA/usr/local/cuda 2>&1 %s | \
 // RUN:FileCheck %s --check-prefix=ERR_SM60 --check-prefix=OK_SM35
 
 // We should get two errors here, one for sm_60 and one for sm_61.
 // RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-gpu-arch=sm_61 \
-// RUN:--sysroot=%S/Inputs/CUDA 2>&1 %s | \
+// RUN:--cuda-path=%S/Inputs/CUDA/usr/local/cuda 2>&1 %s | \
 // RUN:FileCheck %s --check-prefix=ERR_SM60 --check-prefix=ERR_SM61
 
 // We should still get an error if we pass -nocudainc, because this compilation
 // would invoke ptxas, and we do a version check on that, too.
-// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 -nocudainc --sysroot=%S/Inputs/CUDA 2>&1 %s | \
+// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 -nocudainc --cuda-path=%S/Inputs/CUDA/usr/local/cuda 2>&1 %s | \
 // RUN:FileCheck %s --check-prefix=ERR_SM60
 
 // If with -nocudainc and -E, we don't touch the CUDA install, so we
 // shouldn't get an error.
 // RUN: %clang --target=x86_64-linux -v -### -E --cuda-device-only --cuda-gpu-arch=sm_60 -nocudainc \
-// RUN:--sysroot=%S/Inputs/CUDA 2>&1 %s | \
+// RUN:--cuda-path=%S/Inputs/CUDA/usr/local/cuda 2>&1 %s | \
 // RUN:FileCheck %s --check-prefix=OK
 
 // --no-cuda-version-check should suppress all of these errors.
-// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --sysroot=%S/Inputs/CUDA 2>&1 \
+// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-path=%S/Inputs/CUDA/usr/local/cuda 2>&1 \
 // RUN:--no-cuda-version-check %s | \
 // RUN:FileCheck %s --check-prefix=OK
 
 // We need to make sure the version check is done only for the device toolchain,
 // therefore we should not get an error in host-only mode. We use the -S here
 // to avoid the error being produced in case by the assembler tool, which does
 // the same check.
-// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-host-only --sysroot=%S/Inputs/CUDA -S 2>&1 %s | \
+// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-host-only --cuda-path=%S/Inputs/CUDA/usr/local/cuda -S 2>&1 %s | \
 // RUN:FileCheck %s --check-prefix=OK
-// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-device-only --sysroot=%S/Inputs/CUDA -S 2>&1 %s | \
+// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-device-only --cuda-path=%S/Inputs/CUDA/usr/local/c

r323814 - Revert "CodeGen: annotate ObjC ARC functions with ABI constraints"

2018-01-30 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Tue Jan 30 12:19:34 2018
New Revision: 323814

URL: http://llvm.org/viewvc/llvm-project?rev=323814&view=rev
Log:
Revert "CodeGen: annotate ObjC ARC functions with ABI constraints"

This reverts commit r294872.

Although this patch is correct, it caused the 
objc_autoreleaseRValue/objc_retainAutoreleasedReturnValue

Modified:
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/test/CodeGenObjC/arc.m

Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=323814&r1=323813&r2=323814&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Tue Jan 30 12:19:34 2018
@@ -1815,22 +1815,6 @@ void CodeGenFunction::EmitARCIntrinsicUs
 }
 
 
-static bool IsForwarding(StringRef Name) {
-  return llvm::StringSwitch(Name)
-  .Cases("objc_autoreleaseReturnValue", // 
ARCInstKind::AutoreleaseRV
- "objc_autorelease",// 
ARCInstKind::Autorelease
- "objc_retainAutoreleaseReturnValue",   // 
ARCInstKind::FusedRetainAutoreleaseRV
- "objc_retainAutoreleasedReturnValue",  // 
ARCInstKind::RetainRV
- "objc_retainAutorelease",  // 
ARCInstKind::FusedRetainAutorelease
- "objc_retainedObject", // 
ARCInstKind::NoopCast
- "objc_retain", // ARCInstKind::Retain
- "objc_unretainedObject",   // 
ARCInstKind::NoopCast
- "objc_unretainedPointer",  // 
ARCInstKind::NoopCast
- "objc_unsafeClaimAutoreleasedReturnValue", // ARCInstKind::ClaimRV
- true)
-  .Default(false);
-}
-
 static llvm::Constant *createARCRuntimeFunction(CodeGenModule &CGM,
 llvm::FunctionType *FTy,
 StringRef Name) {
@@ -1848,9 +1832,6 @@ static llvm::Constant *createARCRuntimeF
   // performance.
   F->addFnAttr(llvm::Attribute::NonLazyBind);
 }
-
-if (IsForwarding(Name))
-  F->arg_begin()->addAttr(llvm::Attribute::Returned);
   }
 
   return RTF;

Modified: cfe/trunk/test/CodeGenObjC/arc.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc.m?rev=323814&r1=323813&r2=323814&view=diff
==
--- cfe/trunk/test/CodeGenObjC/arc.m (original)
+++ cfe/trunk/test/CodeGenObjC/arc.m Tue Jan 30 12:19:34 2018
@@ -7,30 +7,30 @@
 // RUN: %clang_cc1 -fobjc-runtime=macosx-10.7.0 -triple x86_64-apple-darwin11 
-Wno-objc-root-class -Wno-incompatible-pointer-types 
-Wno-arc-unsafe-retained-assign -emit-llvm -fblocks -fobjc-arc 
-fobjc-runtime-has-weak -o - %s | FileCheck -check-prefix=ARC-NATIVE %s
 
 // ARC-ALIEN: declare extern_weak void @objc_storeStrong(i8**, i8*)
-// ARC-ALIEN: declare extern_weak i8* @objc_retain(i8* returned)
-// ARC-ALIEN: declare extern_weak i8* @objc_autoreleaseReturnValue(i8* 
returned)
+// ARC-ALIEN: declare extern_weak i8* @objc_retain(i8*)
+// ARC-ALIEN: declare extern_weak i8* @objc_autoreleaseReturnValue(i8*)
 // ARC-ALIEN: declare i8* @objc_msgSend(i8*, i8*, ...) [[NLB:#[0-9]+]]
 // ARC-ALIEN: declare extern_weak void @objc_release(i8*)
-// ARC-ALIEN: declare extern_weak i8* @objc_retainAutoreleasedReturnValue(i8* 
returned)
+// ARC-ALIEN: declare extern_weak i8* @objc_retainAutoreleasedReturnValue(i8*)
 // ARC-ALIEN: declare extern_weak i8* @objc_initWeak(i8**, i8*)
 // ARC-ALIEN: declare extern_weak i8* @objc_storeWeak(i8**, i8*)
 // ARC-ALIEN: declare extern_weak i8* @objc_loadWeakRetained(i8**)
 // ARC-ALIEN: declare extern_weak void @objc_destroyWeak(i8**)
-// declare extern_weak i8* @objc_autorelease(i8*)
-// ARC-ALIEN: declare extern_weak i8* @objc_retainAutorelease(i8* returned)
+// ARC-ALIEN: declare extern_weak i8* @objc_autorelease(i8*)
+// ARC-ALIEN: declare extern_weak i8* @objc_retainAutorelease(i8*)
 
 // ARC-NATIVE: declare void @objc_storeStrong(i8**, i8*)
-// ARC-NATIVE: declare i8* @objc_retain(i8* returned) [[NLB:#[0-9]+]]
-// ARC-NATIVE: declare i8* @objc_autoreleaseReturnValue(i8* returned)
+// ARC-NATIVE: declare i8* @objc_retain(i8*) [[NLB:#[0-9]+]]
+// ARC-NATIVE: declare i8* @objc_autoreleaseReturnValue(i8*)
 // ARC-NATIVE: declare i8* @objc_msgSend(i8*, i8*, ...) [[NLB]]
 // ARC-NATIVE: declare void @objc_release(i8*) [[NLB]]
-// ARC-NATIVE: declare i8* @objc_retainAutoreleasedReturnValue(i8* returned)
+// ARC-NATIVE: declare i8* @objc_retainAutoreleasedReturnValue(i8*)
 // ARC-NATIVE: declare i8* @objc_initWeak(i8**, i8*)
 // ARC-NATIVE: declare i8* @objc_storeWeak(i8**, i8*)
 // ARC-NATIVE: declare i8* @objc_loadWeakRetained(i8**)
 // ARC-NATIVE: declare void @objc_destroyWeak(i8**)
-// declare i8* @objc_autorelease(i8*)
-// ARC-NATIVE: declare i8* @objc_ret

[PATCH] D38943: [ASTImporter] import SubStmt of CaseStmt

2018-01-30 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin added inline comments.
Herald added subscribers: llvm-commits, rnkovacs.



Comment at: cfe/trunk/unittests/AST/ASTImporterTest.cpp:100
 
+  // This traverses the AST to catch certain bugs like poorly or not
+  // implemented subtrees.

I just saw this change and I cannot find the reason, why do we need to print 
the imported declaration after we have printed the entire translation unit? Is 
there some special case?


Repository:
  rL LLVM

https://reviews.llvm.org/D38943



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


[PATCH] D42645: New simple Checker for mmap calls

2018-01-30 Thread David CARLIER via Phabricator via cfe-commits
devnexen updated this revision to Diff 132024.

Repository:
  rC Clang

https://reviews.llvm.org/D42645

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp

Index: lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
@@ -0,0 +1,78 @@
+// MmapWriteExecChecker.cpp - Check for the prot argument -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This checker tests the 3rd argument of mmap's calls to check if
+// it is writable and executable in the same time. It's somehow
+// an optional checker since for example in JIT libraries it is pretty common.
+//
+//===--===//
+
+#include "ClangSACheckers.h"
+
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
+#include "clang/StaticAnalyzer/Core/Checker.h"
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+
+using namespace clang;
+using namespace ento;
+using llvm::APSInt;
+
+namespace {
+class MmapWriteExecChecker : public Checker {
+  CallDescription MmapFn;
+  static int ProtWrite;
+  static int ProtExec;
+  mutable std::unique_ptr BT;
+public:
+  MmapWriteExecChecker() : MmapFn("mmap") {}
+  void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
+};
+}
+
+int MmapWriteExecChecker::ProtWrite = 0x02;
+int MmapWriteExecChecker::ProtExec  = 0x04;
+
+void MmapWriteExecChecker::checkPreCall(const CallEvent &Call,
+ CheckerContext &C) const {
+  if (Call.isCalled(MmapFn)) {
+if (Call.getNumArgs() < 3)
+  return;
+
+llvm::Triple Triple = C.getASTContext().getTargetInfo().getTriple();
+
+if (Triple.isOSGlibc())
+  ProtExec = 0x01;
+
+SVal ProtVal = Call.getArgSVal(2); 
+Optional ProtLoc = ProtVal.getAs();
+int64_t Prot = ProtLoc->getValue().getSExtValue();
+
+if ((Prot & (ProtWrite | ProtExec)) == (ProtWrite | ProtExec)) {
+  if (!BT)
+BT.reset(new BugType(this, "W^X check fails", "Write Exec prot flags set"));
+
+  ExplodedNode *N = C.generateErrorNode();
+  if (!N)
+return;
+
+  auto Report = llvm::make_unique(
+  *BT, "Both PROT_WRITE and PROT_EXEC flags had been set. It can "
+   "leads to exploitable memory regions, overwritten with malicious code"
+ , N);
+  Report->addRange(Call.getArgSourceRange(2));
+  C.emitReport(std::move(Report));
+}
+  }
+}
+
+void ento::registerMmapWriteExecChecker(CheckerManager &mgr) {
+  mgr.registerChecker();
+}
Index: lib/StaticAnalyzer/Checkers/CMakeLists.txt
===
--- lib/StaticAnalyzer/Checkers/CMakeLists.txt
+++ lib/StaticAnalyzer/Checkers/CMakeLists.txt
@@ -49,6 +49,7 @@
   MallocChecker.cpp
   MallocOverflowSecurityChecker.cpp
   MallocSizeofChecker.cpp
+  MmapWriteExecChecker.cpp
   MisusedMovedObjectChecker.cpp
   MPI-Checker/MPIBugReporter.cpp
   MPI-Checker/MPIChecker.cpp
Index: include/clang/StaticAnalyzer/Checkers/Checkers.td
===
--- include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -86,7 +86,7 @@
 
 // The APIModeling package is for checkers that model APIs and don't perform
 // any diagnostics. These checkers are always turned on; this package is
-// intended for API modeling that is not controlled by the target triple.
+// intended for API modeling that is not controlled by the the target triple.
 def APIModeling : Package<"apiModeling">, Hidden;
 def GoogleAPIModeling : Package<"google">, InPackage;
 
@@ -414,6 +414,10 @@
   HelpText<"Check for overflows in the arguments to malloc()">,
   DescFile<"MallocOverflowSecurityChecker.cpp">;
 
+def MmapWriteExecChecker : Checker<"MmapWriteExec">,
+  HelpText<"Check if mmap() call is not both writable and executable">,
+  DescFile<"MmapWriteExecChecker.cpp">;
+
 } // end "alpha.security"
 
 //===--===//
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42560: [analyzer] dump() ExprEngine's internal traits into the ExplodedGraph view.

2018-01-30 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov accepted this revision.
george.karpenkov added a comment.
This revision is now accepted and ready to land.

But that's all bikeshedding though


https://reviews.llvm.org/D42560



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


[PATCH] D42581: [NVPTX] Emit debug info in DWARF-2 by default for Cuda devices.

2018-01-30 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: lib/Driver/ToolChains/Cuda.cpp:436-437
 assert(Output.isNothing() && "Invalid output.");
-  if (Args.hasArg(options::OPT_g_Flag))
+  if (mustEmitDebugInfo(Args) == FullDebug)
 CmdArgs.push_back("-g");
 

Do we need to pass -g to make lineinfo debugging work?


Repository:
  rC Clang

https://reviews.llvm.org/D42581



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


[PATCH] D42560: [analyzer] dump() ExprEngine's internal traits into the ExplodedGraph view.

2018-01-30 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added a comment.

looks good otherwise.




Comment at: lib/StaticAnalyzer/Core/ExprEngine.cpp:418
+  for (auto I : NewAllocValsMap) {
+  std::pair Key = I.first;
+  SVal Value = I.second;

indent?
actually, an even better version would be probably moving those function back 
inline into printState, but instead moving out the lambdas passed to 
`dumpStack`.
That would solve the eight-levels-of-indentation problem, and get rid of 
super-verbose lambdas


https://reviews.llvm.org/D42560



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


[PATCH] D42581: [NVPTX] Emit debug info in DWARF-2 by default for Cuda devices.

2018-01-30 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev updated this revision to Diff 132016.
ABataev added a comment.

1. Updated after review.
2. Changed the default behavior of --[no]cuda-noopt-device-debug. If the 
optimization level is not specified or is O0 and debug info must be emitted, 
the device debug info is emitted. If optimization level is specified and >O0 
and debug info must be emitted, the debug info for device is emitted only if 
--cuda-noopt-device-debug is specified.


Repository:
  rC Clang

https://reviews.llvm.org/D42581

Files:
  lib/Driver/ToolChains/Cuda.cpp
  lib/Driver/ToolChains/Cuda.h
  test/Driver/cuda-dwarf-2.cu
  test/Driver/cuda-external-tools.cu
  test/Driver/openmp-offload-gpu.c

Index: test/Driver/openmp-offload-gpu.c
===
--- test/Driver/openmp-offload-gpu.c
+++ test/Driver/openmp-offload-gpu.c
@@ -142,3 +142,53 @@
 // RUN:   | FileCheck -check-prefix=CHK-NOLIBDEVICE %s
 
 // CHK-NOLIBDEVICE-NOT: error:{{.*}}sm_60
+
+/// ###
+
+/// Check that dbug info is emitted in dwarf-2
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O0 --no-cuda-noopt-device-debug 2>&1 \
+// RUN:   | FileCheck -check-prefix=NO_DEBUG %s
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O3 2>&1 \
+// RUN:   | FileCheck -check-prefix=NO_DEBUG %s
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O3 --no-cuda-noopt-device-debug 2>&1 \
+// RUN:   | FileCheck -check-prefix=NO_DEBUG %s
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g0 2>&1 \
+// RUN:   | FileCheck -check-prefix=NO_DEBUG %s
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -ggdb0 -O3 --cuda-noopt-device-debug 2>&1 \
+// RUN:   | FileCheck -check-prefix=NO_DEBUG %s
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -gline-tables-only 2>&1 \
+// RUN:   | FileCheck -check-prefix=NO_DEBUG -check-prefix=LINE_TABLE %s
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -ggdb1 -O2 --cuda-noopt-device-debug 2>&1 \
+// RUN:   | FileCheck -check-prefix=NO_DEBUG -check-prefix=LINE_TABLE %s
+
+// NO_DEBUG: ptxas
+// LINE_TABLE: "-lineinfo"
+// NO_DEBUG-NOT: "-g"
+// NO_DEBUG: nvlink
+// NO_DEBUG-NOT: "-g"
+
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g 2>&1 \
+// RUN:   | FileCheck -check-prefix=HAS_DEBUG %s
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O0 --cuda-noopt-device-debug 2>&1 \
+// RUN:   | FileCheck -check-prefix=HAS_DEBUG %s
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g -O3 --cuda-noopt-device-debug 2>&1 \
+// RUN:   | FileCheck -check-prefix=HAS_DEBUG %s
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g2 2>&1 \
+// RUN:   | FileCheck -check-prefix=HAS_DEBUG %s
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -ggdb2 -O0 --cuda-noopt-device-debug 2>&1 \
+// RUN:   | FileCheck -check-prefix=HAS_DEBUG %s
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -g3 -O3 --cuda-noopt-device-debug 2>&1 \
+// RUN:   | FileCheck -check-prefix=HAS_DEBUG %s
+// RUN:   %clang -### -no-canonical-prefixes -fopenmp=libomp -fopenmp-targets=nvptx64-nvidia-cuda -Xopenmp-target -march=sm_60 %s -ggdb3 -O2 --cuda-noopt-device-debug 2>&1 \
+// RUN:   | FileCheck -check-prefix=HAS_DEBUG %s
+
+// HAS_DEBUG: "-triple" "nvptx64-nvidia-cuda"
+// HAS_DEBUG-SAME: "-dwarf-version=2"
+// HAS_DEBUG-SAME: "-fopenmp-is-device"
+// HAS_DEBUG: ptxas
+// HAS_DEBUG-SAME: "-g"
+// HAS_DEBUG-SAME: "--dont-merge-basicblocks"
+// HAS_DEBUG-SAME: "--return-at-end"
+// HAS_DEBUG: nvlink
+// HAS_DEBUG-SAME: "-g"
+
Index: test/Driver/cuda-external-tools.cu
===
--- test/Driver/cuda-external-tools.cu
+++ test/Driver/cuda-external-tools.cu
@@ -20,7 +20,7 @@
 // RUN: | FileCheck -check-prefix ARCH64 -check-prefix SM20 -check-prefix OPT3 %s
 
 // With debugging enabled, ptxas should be run with with no ptxas optimizations.
-// RUN: %clang -### -target x86_64-linux-gnu --cud

[PATCH] D42560: [analyzer] dump() ExprEngine's internal traits into the ExplodedGraph view.

2018-01-30 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin added a comment.

More debug info is always good.




Comment at: lib/StaticAnalyzer/Core/ExprEngine.cpp:400
+Out << '(' << I.second << ',' << I.first << ") ";
+I.first->printPretty(Out, nullptr, PrintingPolicy(LO));
+Out << NL;

Why not ASTContext::getPrintingPolicy()?


https://reviews.llvm.org/D42560



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


[PATCH] D42560: [analyzer] dump() ExprEngine's internal traits into the ExplodedGraph view.

2018-01-30 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 132010.
NoQ added a comment.

Address comments :)


https://reviews.llvm.org/D42560

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

Index: lib/StaticAnalyzer/Core/ProgramState.cpp
===
--- lib/StaticAnalyzer/Core/ProgramState.cpp
+++ lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -450,7 +450,7 @@
   Mgr.getConstraintManager().print(this, Out, NL, Sep);
 
   // Print checker-specific data.
-  Mgr.getOwningEngine()->printState(Out, this, NL, Sep);
+  Mgr.getOwningEngine()->printState(Out, this, NL, Sep, LC);
 }
 
 void ProgramState::printDOT(raw_ostream &Out, const LocationContext *LC) const {
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -383,8 +383,57 @@
  LCtx, Call);
 }
 
+static void printInitializedTemporaries(raw_ostream &Out, ProgramStateRef State,
+const char *NL, const char *Sep,
+const LocationContext *LCtx) {
+  LangOptions LO; // FIXME.
+  auto InitTempSet = State->get();
+  if (!InitTempSet.isEmpty()) {
+Out << Sep << "Initialized temporaries:" << NL;
+
+LCtx->dumpStack(Out, "", NL, Sep,
+[&Out, &LO, InitTempSet, NL](const LocationContext *LC) {
+  for (auto I : InitTempSet) {
+if (I.second != LC)
+  continue;
+Out << '(' << I.second << ',' << I.first << ") ";
+I.first->printPretty(Out, nullptr, PrintingPolicy(LO));
+Out << NL;
+  }
+});
+  }
+}
+
+static void printCXXNewAllocatorValues(raw_ostream &Out, ProgramStateRef State,
+const char *NL, const char *Sep,
+const LocationContext *LCtx) {
+  LangOptions LO; // FIXME.
+  auto NewAllocValsMap = State->get();
+  if (!NewAllocValsMap.isEmpty()) {
+Out << Sep << "operator new() allocator return values:" << NL;
+
+LCtx->dumpStack(Out, "", NL, Sep,
+[&Out, &LO, NewAllocValsMap, NL](const LocationContext *LC) {
+  for (auto I : NewAllocValsMap) {
+  std::pair Key = I.first;
+  SVal Value = I.second;
+if (Key.second != LC)
+  continue;
+Out << '(' << Key.second << ',' << Key.first << ") ";
+Key.first->printPretty(Out, nullptr, PrintingPolicy(LO));
+Out << " : " << Value << NL;
+  }
+});
+  }
+}
+
 void ExprEngine::printState(raw_ostream &Out, ProgramStateRef State,
-const char *NL, const char *Sep) {
+const char *NL, const char *Sep,
+const LocationContext *LCtx) {
+  if (LCtx) {
+printInitializedTemporaries(Out, State, NL, Sep, LCtx);
+printCXXNewAllocatorValues(Out, State, NL, Sep, LCtx);
+  }
   getCheckerManager().runCheckersForPrintState(Out, State, NL, Sep);
 }
 
Index: include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h
@@ -155,7 +155,8 @@
 
   /// printState - Called by ProgramStateManager to print checker-specific data.
   virtual void printState(raw_ostream &Out, ProgramStateRef State,
-  const char *NL, const char *Sep) = 0;
+  const char *NL, const char *Sep,
+  const LocationContext *LCtx = nullptr) = 0;
 
   /// Called by CoreEngine when the analysis worklist is either empty or the
   //  maximum number of analysis steps have been reached.
Index: include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -299,8 +299,9 @@
const CallEvent *Call) override;
 
   /// printState - Called by ProgramStateManager to print checker-specific data.
-  void printState(raw_ostream &Out, ProgramStateRef State,
-  const char *NL, const char *Sep) override;
+  void printState(raw_ostream &Out, ProgramStateRef State, const char *NL,
+  const char *Sep,
+  const LocationContext *LCtx = nullptr) override;
 
   ProgramStateManager& getStateManager() override { return StateMgr; }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists

[PATCH] D42642: [CUDA] Detect installation in PATH

2018-01-30 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In https://reviews.llvm.org/D42642#992137, @tra wrote:

> I've thought a bit more about this and there's another quirk -- symlinks.
>
> What if we've found /usr/bin/ptxas and is a symlink pointing to the real 
> ptxas in the CUDA installation? If we add /usr to the list of candidates it 
> will not help us at all. We should probably find the real path and add 
> another candidate path derived from it.


Yes, this might be a valid use case, for example linking `/usr/bin/ptxas` to 
`/opt/cuda/bin/ptxas` or something. I think there should be an LLVM function to 
get the `realpath`, let me check that.
(In fact I have symlinks in my environment but it doesn't matter in this case 
because we are just linking the complete CUDA installation to another path...)




Comment at: lib/Driver/ToolChains/Cuda.cpp:206
 // -nocudalib hasn't been specified.
-if (LibDeviceMap.empty() && !Args.hasArg(options::OPT_nocudalib))
+if (CheckLibDevice && LibDeviceMap.empty())
   continue;

tra wrote:
> Hahnfeld wrote:
> > tra wrote:
> > > I think this may be too strict.
> > > 
> > > Checking directory structure for the purposes of detecting CUDA SDK 
> > > should work well enough to weed out false detection for 'split' CUDA 
> > > installation and we've verified libdevice directory presence above. 
> > > 
> > > Checking for libdevice bitcode is somewhat orthogonal to this. IMO, 
> > > regardless of how we've found the installation directory, whether we have 
> > > suitable libdevice version there should not matter if user explicitly 
> > > passed -nocudalib. Insisting on libdevice presence in this situation 
> > > would be somewhat surprising. 
> > > 
> > > 
> > > 
> > > 
> > > 
> > So you are suggesting to revert the change to this line, right?
> Yes, if you agree with my reasoning.
> 
I generally agree that the working bitcode files are orthogonal to the 
directory structure. However I would argue that there won't be a real world 
scenario of an empty directory called `nvvm/libdevice` without any libdevice 
files in there. That said it probably doesn't make a difference, so I'll follow 
the separation of concerns.


https://reviews.llvm.org/D42642



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


[PATCH] D42693: [libcxx] Handle invalid escaped characters in POSIX regex

2018-01-30 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

I like this.  One nit and a question.




Comment at: include/regex:3490
 {
 switch (*__temp)
 {

Do we need any more cases here?



Comment at: test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp:50
 
+std::regex_constants::syntax_option_type basic =
+std::regex_constants::basic;

should be `const`.   (Yes, this is me being picky)


https://reviews.llvm.org/D42693



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


[PATCH] D42642: [CUDA] Detect installation in PATH

2018-01-30 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

I've thought a bit more about this and there's another quirk -- symlinks.

What if we've found /usr/bin/ptxas and is a symlink pointing to the real ptxas 
in the CUDA installation? If we add /usr to the list of candidates it will not 
help us at all. We should probably find the real path and add another candidate 
path derived from it.




Comment at: lib/Driver/ToolChains/Cuda.cpp:206
 // -nocudalib hasn't been specified.
-if (LibDeviceMap.empty() && !Args.hasArg(options::OPT_nocudalib))
+if (CheckLibDevice && LibDeviceMap.empty())
   continue;

Hahnfeld wrote:
> tra wrote:
> > I think this may be too strict.
> > 
> > Checking directory structure for the purposes of detecting CUDA SDK should 
> > work well enough to weed out false detection for 'split' CUDA installation 
> > and we've verified libdevice directory presence above. 
> > 
> > Checking for libdevice bitcode is somewhat orthogonal to this. IMO, 
> > regardless of how we've found the installation directory, whether we have 
> > suitable libdevice version there should not matter if user explicitly 
> > passed -nocudalib. Insisting on libdevice presence in this situation would 
> > be somewhat surprising. 
> > 
> > 
> > 
> > 
> > 
> So you are suggesting to revert the change to this line, right?
Yes, if you agree with my reasoning.



https://reviews.llvm.org/D42642



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


[PATCH] D42682: [clang-tidy] Add misc-io-functions-misused checker

2018-01-30 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

May be //bugprone// is better module then //misc//?




Comment at: docs/ReleaseNotes.rst:63
+
+  Check if the fgetwc, getwc, getwchar, istream::get standard iostream C 
functions 
+  return values incorrectly stored in char type value.

Please add () to function names and enclose each of them in ``. Same in 
documentation.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42682



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


[PATCH] D42642: [CUDA] Detect installation in PATH

2018-01-30 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added inline comments.



Comment at: lib/Driver/ToolChains/Cuda.cpp:206
 // -nocudalib hasn't been specified.
-if (LibDeviceMap.empty() && !Args.hasArg(options::OPT_nocudalib))
+if (CheckLibDevice && LibDeviceMap.empty())
   continue;

tra wrote:
> I think this may be too strict.
> 
> Checking directory structure for the purposes of detecting CUDA SDK should 
> work well enough to weed out false detection for 'split' CUDA installation 
> and we've verified libdevice directory presence above. 
> 
> Checking for libdevice bitcode is somewhat orthogonal to this. IMO, 
> regardless of how we've found the installation directory, whether we have 
> suitable libdevice version there should not matter if user explicitly passed 
> -nocudalib. Insisting on libdevice presence in this situation would be 
> somewhat surprising. 
> 
> 
> 
> 
> 
So you are suggesting to revert the change to this line, right?


https://reviews.llvm.org/D42642



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


[PATCH] D42642: [CUDA] Detect installation in PATH

2018-01-30 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: lib/Driver/ToolChains/Cuda.cpp:206
 // -nocudalib hasn't been specified.
-if (LibDeviceMap.empty() && !Args.hasArg(options::OPT_nocudalib))
+if (CheckLibDevice && LibDeviceMap.empty())
   continue;

I think this may be too strict.

Checking directory structure for the purposes of detecting CUDA SDK should work 
well enough to weed out false detection for 'split' CUDA installation and we've 
verified libdevice directory presence above. 

Checking for libdevice bitcode is somewhat orthogonal to this. IMO, regardless 
of how we've found the installation directory, whether we have suitable 
libdevice version there should not matter if user explicitly passed -nocudalib. 
Insisting on libdevice presence in this situation would be somewhat surprising. 







https://reviews.llvm.org/D42642



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


[PATCH] D42673: [RISCV] Pick the correct RISCV linker instead of calling riscv-gcc to link

2018-01-30 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

My main concern with this patch is that the description doesn't really match 
what it does. The current in-tree code _doesn't_ call gcc to link for the 
tested configuration (a multilib toolchain), and this is verified with the 
tests in test/Driver/riscv32-toolchain.c. https://reviews.llvm.org/D39963 
originally added support for a baremetal toolchain, but was changed to focus on 
the multilib Linux toolchain for a couple of reasons:

1. This was a more straight-forward change
2. Downstream users such as yourself had a higher priority for building for a 
Linux target
3. It looks like we'd want to discuss the possibility of adding RISC-V support 
to lib/Driver/ToolChains/BareMetal rather than adding yet another 
target-specific toolchain

This patch seems identical to my changes to add a baremetal toolchain 
(https://github.com/lowRISC/riscv-llvm/blob/master/clang/0003-RISCV-Implement-clang-driver-for-the-baremetal-RISCV.patch
 which was previously submitted as part of https://reviews.llvm.org/D39963).

Are you compiling for a Linux target or for bare metal? One problem with the 
multilib detection code is that if it fails it tends to do so silently. I see 
two paths forward depending on the immediate problem you're seeing:

1. If you're seeing an issue with the correct linker being selected when 
compiling using a Linux toolchain, the correct fix would be to modify that 
detection logic committed in https://reviews.llvm.org/rL322276 and add new tests
2. If the issue is that you're now trying to use Clang for a bare-metal target, 
we should discuss whether to move forwards with my baremetal patch as-is or to 
try to modify lib/Driver/ToolChains/BareMetal - probably worth discussing this 
on cfe-dev.

The fact you've hardcoded "riscv32-unknown-linux-gnu-ld" as the linker name 
makes me wonder if the current issue you're seeing is 1)?


Repository:
  rC Clang

https://reviews.llvm.org/D42673



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


[PATCH] D41698: [DebugInfo] Enable debug information for C99 VLA types

2018-01-30 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:990
+  D.getLocation(), D.getLocation(), &NameIdent, QT,
+  getContext().CreateTypeSourceInfo(QT), SC_Auto);
+

sdesmalen wrote:
> aprantl wrote:
> > I think it does, but can you assert me that this generates the same code 
> > with and without -g ?
> I'm not really sure what you mean with 'generates the same code', because 
> without -g this function is not invoked? However, this function only affects 
> debug information, not anything else related to the actual creation of the 
> VLA. So without -g, no 'dbg.declare()' or corresponding DILocalVariables are 
> generated for each subexpression of each dimension.
What I meant is that regardless of code being compile with or without -g, the 
.text section of the resulting binary is identical.


https://reviews.llvm.org/D41698



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


[PATCH] D41698: [DebugInfo] Enable debug information for C99 VLA types

2018-01-30 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen updated this revision to Diff 131990.
sdesmalen marked 4 inline comments as done.
sdesmalen added a comment.
Herald added a subscriber: jholewinski.

- Changed return type of getVLASize() to a struct with named members.
- EmitDeclare and EmitDeclareOfAutoVariable now return a DILocalVariable* 
rather than it being returned in a pointer that was passed as default argument.


https://reviews.llvm.org/D41698

Files:
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  lib/CodeGen/CGStmtOpenMP.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGen/debug-info-vla.c
  test/CodeGenCXX/debug-info-vla.cpp

Index: test/CodeGenCXX/debug-info-vla.cpp
===
--- test/CodeGenCXX/debug-info-vla.cpp
+++ test/CodeGenCXX/debug-info-vla.cpp
@@ -13,8 +13,10 @@
 // CHECK: [[ELEM_TYPE]] = !{[[NOCOUNT:.*]]}
 // CHECK: [[NOCOUNT]] = !DISubrange(count: -1)
 //
+// CHECK: [[VAR:![0-9]+]] = !DILocalVariable(name: "vla_expr"
 // CHECK: !DICompositeType(tag: DW_TAG_array_type,
 // CHECK-NOT:   size:
 // CHECK-SAME:  elements: [[ELEM_TYPE:![0-9]+]]
-// CHECK: [[ELEM_TYPE]] = !{[[THREE:.*]], [[NOCOUNT]]}
+// CHECK: [[ELEM_TYPE]] = !{[[THREE:.*]], [[VARRANGE:![0-9]+]]}
 // CHECK: [[THREE]] = !DISubrange(count: 3)
+// CHECK: [[VARRANGE]] = !DISubrange(count: [[VAR]])
Index: test/CodeGen/debug-info-vla.c
===
--- test/CodeGen/debug-info-vla.c
+++ test/CodeGen/debug-info-vla.c
@@ -2,9 +2,11 @@
 
 void testVLAwithSize(int s)
 {
-// CHECK: dbg.declare
-// CHECK: dbg.declare({{.*}}, metadata ![[VAR:.*]], metadata !DIExpression())
-// CHECK: ![[VAR]] = !DILocalVariable(name: "vla",{{.*}} line: [[@LINE+1]]
+// CHECK-DAG: dbg.declare({{.*}} %vla_expr, metadata ![[VLAEXPR:[0-9]+]]
+// CHECK-DAG: dbg.declare({{.*}} %vla, metadata ![[VAR:[0-9]+]]
+// CHECK-DAG: ![[VLAEXPR]] = !DILocalVariable(name: "vla_expr"
+// CHECK-DAG: ![[VAR]] = !DILocalVariable(name: "vla",{{.*}} line: [[@LINE+2]]
+// CHECK-DAG: !DISubrange(count: ![[VLAEXPR]])
   int vla[s];
   int i;
   for (i = 0; i < s; i++) {
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -2198,12 +2198,24 @@
   /// This function can be called with a null (unreachable) insert point.
   void EmitVariablyModifiedType(QualType Ty);
 
-  /// getVLASize - Returns an LLVM value that corresponds to the size,
+  struct VlaSizePair {
+llvm::Value *NumElts;
+QualType Type;
+
+VlaSizePair(llvm::Value *NE, QualType T) : NumElts(NE), Type(T) {}
+  };
+
+  /// Return the number of elements for a single dimension
+  /// for the given array type.
+  VlaSizePair getVLAElements1D(const VariableArrayType *vla);
+  VlaSizePair getVLAElements1D(QualType vla);
+
+  /// Returns an LLVM value that corresponds to the size,
   /// in non-variably-sized elements, of a variable length array type,
   /// plus that largest non-variably-sized element type.  Assumes that
   /// the type has already been emitted with EmitVariablyModifiedType.
-  std::pair getVLASize(const VariableArrayType *vla);
-  std::pair getVLASize(QualType vla);
+  VlaSizePair getVLASize(const VariableArrayType *vla);
+  VlaSizePair getVLASize(QualType vla);
 
   /// LoadCXXThis - Load the value of 'this'. This function is only valid while
   /// generating code for an C++ member function.
@@ -2511,6 +2523,14 @@
   void emitAutoVarTypeCleanup(const AutoVarEmission &emission,
   QualType::DestructionKind dtorKind);
 
+  /// Emits the alloca and debug information for the size expressions for each
+  /// dimension of an array. It registers the association of its (1-dimensional)
+  /// QualTypes and size expression's debug node, so that CGDebugInfo can
+  /// reference this node when creating the DISubrange object to describe the
+  /// array types.
+  void EmitAndRegisterVariableArrayDimensions(CGDebugInfo *DI,
+  const VarDecl &D);
+
   void EmitStaticVarDecl(const VarDecl &D,
  llvm::GlobalValue::LinkageTypes Linkage);
 
Index: lib/CodeGen/CodeGenFunction.cpp
===
--- lib/CodeGen/CodeGenFunction.cpp
+++ lib/CodeGen/CodeGenFunction.cpp
@@ -1758,12 +1758,9 @@
 if (const VariableArrayType *vlaType =
   dyn_cast_or_null(
   getContext().getAsArrayType(Ty))) {
-  QualType eltType;
-  llvm::Value *numElts;
-  std::tie(numElts, eltType) = getVLASize(vlaType);
-
-  SizeVal = numElts;
-  CharUnits eltSize = g

[PATCH] D41698: [DebugInfo] Enable debug information for C99 VLA types

2018-01-30 Thread Sander de Smalen via Phabricator via cfe-commits
sdesmalen added inline comments.



Comment at: lib/CodeGen/CGDebugInfo.h:474
+   CGBuilderTy &Builder,
+   llvm::Metadata **MetadataDecl = nullptr);
 

aprantl wrote:
> same here. Why not just use a return value?
Initially I thought it would make more sense for the EmitDeclare function to 
return the actual call instruction to llvm.dbg.declare, but I see that 
returning DILocalVariable* makes more sense and that this is in line with the 
other methods of this class.



Comment at: lib/CodeGen/CGDecl.cpp:990
+  D.getLocation(), D.getLocation(), &NameIdent, QT,
+  getContext().CreateTypeSourceInfo(QT), SC_Auto);
+

aprantl wrote:
> I think it does, but can you assert me that this generates the same code with 
> and without -g ?
I'm not really sure what you mean with 'generates the same code', because 
without -g this function is not invoked? However, this function only affects 
debug information, not anything else related to the actual creation of the VLA. 
So without -g, no 'dbg.declare()' or corresponding DILocalVariables are 
generated for each subexpression of each dimension.


https://reviews.llvm.org/D41698



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


[PATCH] D42693: [libcxx] Handle invalid escaped characters in POSIX regex

2018-01-30 Thread Mikhail Maltsev via Phabricator via cfe-commits
miyuki created this revision.
miyuki added reviewers: EricWF, mclow.lists.

Currently when parsing basic POSIX regular expressions libc++
silently skips invalid escaped characters and trailing escapes.
This patch changes the behavior, so that a std::regex_error with
code set to error_escape is thrown in these cases.


https://reviews.llvm.org/D42693

Files:
  include/regex
  test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp


Index: test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
===
--- test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
+++ test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
@@ -19,11 +19,13 @@
 #include 
 #include "test_macros.h"
 
-static bool error_escape_thrown(const char *pat)
+static bool error_escape_thrown(const char *pat,
+std::regex_constants::syntax_option_type
+syntax = std::regex_constants::ECMAScript)
 {
 bool result = false;
 try {
-std::regex re(pat);
+std::regex re(pat, syntax);
 } catch (const std::regex_error &ex) {
 result = (ex.code() == std::regex_constants::error_escape);
 }
@@ -45,4 +47,15 @@
 assert(!error_escape_thrown("[\\cA]"));
 assert(!error_escape_thrown("\\cA"));
 
+std::regex_constants::syntax_option_type basic =
+std::regex_constants::basic;
+
+assert(error_escape_thrown("\\a", basic));
+assert(error_escape_thrown("\\", basic));
+
+assert(!error_escape_thrown("\\(a\\)", basic));
+assert(!error_escape_thrown("\\(a+\\)\\1", basic));
+assert(!error_escape_thrown("a\\{1,2\\}", basic));
+assert(!error_escape_thrown("\\.", basic));
+assert(!error_escape_thrown("\\*", basic));
 }
Index: include/regex
===
--- include/regex
+++ include/regex
@@ -3442,23 +3442,32 @@
 {
 if (__first != __last)
 {
-_ForwardIterator __temp = _VSTD::next(__first);
-if (__temp != __last)
+if (*__first == '\\')
 {
-if (*__first == '\\')
+_ForwardIterator __temp = _VSTD::next(__first);
+if (__temp == __last)
+__throw_regex_error();
+
+switch (*__temp)
 {
-switch (*__temp)
-{
-case '^':
-case '.':
-case '*':
-case '[':
-case '$':
-case '\\':
-__push_char(*__temp);
-__first = ++__temp;
+case '^':
+case '.':
+case '*':
+case '[':
+case '$':
+case '\\':
+__push_char(*__temp);
+__first = ++__temp;
+break;
+case '(':
+case ')':
+case '{':
+case '}':
+break;
+default:
+if (*__temp >= '1' && *__temp <= '9')
 break;
-}
+__throw_regex_error();
 }
 }
 }


Index: test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
===
--- test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
+++ test/std/re/re.regex/re.regex.construct/bad_escape.pass.cpp
@@ -19,11 +19,13 @@
 #include 
 #include "test_macros.h"
 
-static bool error_escape_thrown(const char *pat)
+static bool error_escape_thrown(const char *pat,
+std::regex_constants::syntax_option_type
+syntax = std::regex_constants::ECMAScript)
 {
 bool result = false;
 try {
-std::regex re(pat);
+std::regex re(pat, syntax);
 } catch (const std::regex_error &ex) {
 result = (ex.code() == std::regex_constants::error_escape);
 }
@@ -45,4 +47,15 @@
 assert(!error_escape_thrown("[\\cA]"));
 assert(!error_escape_thrown("\\cA"));
 
+std::regex_constants::syntax_option_type basic =
+std::regex_constants::basic;
+
+assert(error_escape_thrown("\\a", basic));
+assert(error_escape_thrown("\\", basic));
+
+assert(!error_escape_thrown("\\(a\\)", basic));
+assert(!error_escape_thrown("\\(a+\\)\\1", basic));
+assert(!error_escape_thrown("a\\{1,2\\}", basic));
+assert(!error_escape_thrown("\\.", basic));
+assert(!error_escape_thrown("\\*", basic));
 }
Index: include/regex
===
--- include/regex
+++ include/regex
@@ -3442,23 +3442,32 @@
 {
 if (__first != __last)
 {
-_ForwardIterator __temp = _VSTD::next(__first);
-if (__temp != __last)
+if (*__first == '\\')
 {
-if (*__first == '\\')
+_ForwardIterator __temp = _VSTD::next(__first);
+if (__

[PATCH] D42581: [NVPTX] Emit debug info in DWARF-2 by default for Cuda devices.

2018-01-30 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: lib/Driver/ToolChains/Cuda.cpp:353
   CmdArgs.push_back(Args.MakeArgString(Output.getFilename()));
+  if (mustEmitDebugInfo(Args) && Args.hasArg(options::OPT_g_Flag))
+CmdArgs.push_back("-g");

tra wrote:
> ABataev wrote:
> > tra wrote:
> > > ABataev wrote:
> > > > tra wrote:
> > > > > There's more than one -g option. Presumably you still want -g here 
> > > > > for -g{1,2,3} or -ggdb{1,2,3} or -gdwarf2.
> > > > > 
> > > > > Speaking of dwarf, what's going to happen if someone passes -gdwarf5? 
> > > > >  Should we downgrade it to -gdwarf2 on device side and issue a 
> > > > > warning?
> > > > > 
> > > > That's exactly what I want to avoid. I think we can ignore these 
> > > > options and handle only `-g` option.
> > > > Or I can add a function to ToolChain class to force using the default 
> > > > settings for debugger tuning and DWARF version rather than take them 
> > > > from the driver options.
> > > You should handle at least -gN/-gline-tables-only/-g. Now that we can 
> > > emit dwarf debug info, I would want to be able to control it to some 
> > > degree -- off/line-info-only/full.
> > > 
> > > I'm still not sure what's the plan for -gdwarfN unsupported on device 
> > > side? 
> > > - do we ignore it and always emit dwarf2?
> > > - do we accept it, emit requested version and let user stare at ptxas (or 
> > > cuda-gdb) errors when it fails to deal with it?
> > > 
> > > 
> > > 
> > > 
> > 1. Ok, will look at this
> > 2. -gdwarfN should be ignored, we should always emit DWARF2, otherwise, it 
> > will break ptxas.
> Works for me. Please add a test to verify that it's always dwarf2 on device 
> side.
After some thoughts, I think it would better to follow Paul's suggestion, i.e. 
force DWARF2 for NVPTX in the backend. In this case, -gdwarfN will not break 
anything in the debug info for NVPTX.


Repository:
  rC Clang

https://reviews.llvm.org/D42581



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


[clang-tools-extra] r323792 - [clangd] Trace code completion.

2018-01-30 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Tue Jan 30 09:20:54 2018
New Revision: 323792

URL: http://llvm.org/viewvc/llvm-project?rev=323792&view=rev
Log:
[clangd] Trace code completion.

Context passing is a little messy, but will go away with TLS soon.

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

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=323792&r1=323791&r2=323792&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Tue Jan 30 09:20:54 2018
@@ -19,6 +19,7 @@
 #include "Compiler.h"
 #include "FuzzyMatch.h"
 #include "Logger.h"
+#include "Trace.h"
 #include "index/Index.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendActions.h"
@@ -637,6 +638,7 @@ bool semaCodeComplete(const Context &Ctx
   const clang::CodeCompleteOptions &Options,
   const SemaCompleteInput &Input,
   llvm::function_ref Callback = nullptr) {
+  auto Tracer = llvm::make_unique(Ctx, "Sema completion");
   std::vector ArgStrs;
   for (const auto &S : Input.Command.CommandLine)
 ArgStrs.push_back(S.c_str());
@@ -697,9 +699,12 @@ bool semaCodeComplete(const Context &Ctx
 "Execute() failed when running codeComplete for " + Input.FileName);
 return false;
   }
+  Tracer.reset();
 
   if (Callback)
 Callback();
+
+  Tracer = llvm::make_unique(Ctx, "Sema completion cleanup");
   Action.EndSourceFile();
 
   return true;
@@ -796,6 +801,7 @@ clang::CodeCompleteOptions CodeCompleteO
 // This score is combined with the result quality score for the final 
score.
 //   - TopN determines the results with the best score.
 class CodeCompleteFlow {
+  trace::Span Tracer;
   const Context &Ctx;
   const CodeCompleteOptions &Opts;
   // Sema takes ownership of Recorder. Recorder is valid until Sema cleanup.
@@ -808,8 +814,8 @@ class CodeCompleteFlow {
 public:
   // A CodeCompleteFlow object is only useful for calling run() exactly once.
   CodeCompleteFlow(const Context &Ctx, const CodeCompleteOptions &Opts)
-  : Ctx(Ctx), Opts(Opts), RecorderOwner(new CompletionRecorder(Opts)),
-Recorder(*RecorderOwner) {}
+  : Tracer(Ctx, "CodeCompleteFlow"), Ctx(Tracer.Ctx), Opts(Opts),
+RecorderOwner(new CompletionRecorder(Opts)), Recorder(*RecorderOwner) 
{}
 
   CompletionList run(const SemaCompleteInput &SemaCCInput) && {
 // We run Sema code completion first. It builds an AST and calculates:
@@ -824,6 +830,11 @@ public:
  log(Ctx, "Code complete: no Sema callback, 0 
results");
  });
 
+SPAN_ATTACH(Tracer, "sema_results", NSema);
+SPAN_ATTACH(Tracer, "index_results", NIndex);
+SPAN_ATTACH(Tracer, "merged_results", NBoth);
+SPAN_ATTACH(Tracer, "returned_results", Output.items.size());
+SPAN_ATTACH(Tracer, "incomplete", Output.isIncomplete);
 log(Ctx,
 llvm::formatv("Code complete: {0} results from Sema, {1} from Index, "
   "{2} matched, {3} returned{4}.",
@@ -860,6 +871,9 @@ private:
   SymbolSlab queryIndex() {
 if (!Opts.Index || !allowIndex(Recorder.CCContext.getKind()))
   return SymbolSlab();
+trace::Span Tracer(Ctx, "Query index");
+SPAN_ATTACH(Tracer, "limit", Opts.Limit);
+
 SymbolSlab::Builder ResultsBuilder;
 // Build the query.
 FuzzyFindRequest Req;
@@ -868,12 +882,15 @@ private:
 Req.Query = Filter->pattern();
 Req.Scopes =
 getQueryScopes(Recorder.CCContext, 
Recorder.CCSema->getSourceManager());
-log(Ctx, llvm::formatv(
- "Code complete: fuzzyFind(\"{0}\", Scopes: [{1}]", Req.Query,
- llvm::join(Req.Scopes.begin(), Req.Scopes.end(), ",")));
+log(Tracer.Ctx,
+llvm::formatv("Code complete: fuzzyFind(\"{0}\", Scopes: [{1}]",
+  Req.Query,
+  llvm::join(Req.Scopes.begin(), Req.Scopes.end(), ",")));
 // Run the query against the index.
-Incomplete |= !Opts.Index->fuzzyFind(
-Ctx, Req, [&](const Symbol &Sym) { ResultsBuilder.insert(Sym); });
+Incomplete |=
+!Opts.Index->fuzzyFind(Tracer.Ctx, Req, [&](const Symbol &Sym) {
+  ResultsBuilder.insert(Sym);
+});
 return std::move(ResultsBuilder).build();
   }
 
@@ -882,6 +899,7 @@ private:
   std::vector>
   mergeResults(const std::vector &SemaResults,
const SymbolSlab &IndexResults) {
+trace::Span Tracer(Ctx, "Merge and score results");
 // We only keep the best N results at any time, in "native" format.
 TopN Top(Opts.Limit == 0 ? TopN::Unbounded : Opts.Limit);
 llvm::DenseSet UsedIndexResults;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.

[PATCH] D42680: [ThinLTO] Ignore -fthinlto-index= for non-ThinLTO files

2018-01-30 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In https://reviews.llvm.org/D42680#991938, @pcc wrote:

> This doesn't seem right to me. In a mixed full/thin LTO link the full LTO 
> module would be compiled during the indexing phase. We don't want to compile 
> it again in the backend as it could lead at best to duplicate symbol errors 
> and at worst to miscompiles of `llvm.type.*` intrinsic calls.


Good point. The build system will presumably expect an output file to be 
generated, so probably just compile an "empty" Module in this case?


https://reviews.llvm.org/D42680



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


[PATCH] D42680: [ThinLTO] Ignore -fthinlto-index= for non-ThinLTO files

2018-01-30 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc requested changes to this revision.
pcc added a comment.
This revision now requires changes to proceed.

This doesn't seem right to me. In a mixed full/thin LTO link the full LTO 
module would be compiled during the indexing phase. We don't want to compile it 
again in the backend as it could lead at best to duplicate symbol errors and at 
worst to miscompiles of `llvm.type.*` intrinsic calls.


https://reviews.llvm.org/D42680



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


[PATCH] D42680: [ThinLTO] Ignore -fthinlto-index= for non-ThinLTO files

2018-01-30 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson accepted this revision.
tejohnson added a comment.
This revision is now accepted and ready to land.

LGTM (minor comment fix in test needed)




Comment at: clang/test/CodeGen/thinlto_backend.ll:23
 
+; Ensure we don't fail with index and non-ThinLTO object file, and run 
non-ThinLTO compilation which
+; RUN: opt -o %t5.o %s

Comment line length too long, and sentence isn't complete.


https://reviews.llvm.org/D42680



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


[PATCH] D41318: Start setting dso_local in clang

2018-01-30 Thread Sean Fertile via Phabricator via cfe-commits
sfertile added a comment.

Sorry, I missed that you wanted this reviewed again, I'll make sure to review 
it today.


https://reviews.llvm.org/D41318



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


Re: r323360 - [Hexagon] Accept lowercase b in -hvx-length=64b and -hvx-length=128b

2018-01-30 Thread Hans Wennborg via cfe-commits
Merged to 6.0 in r323769.

On Wed, Jan 24, 2018 at 7:42 PM, Krzysztof Parzyszek via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: kparzysz
> Date: Wed Jan 24 10:42:19 2018
> New Revision: 323360
>
> URL: http://llvm.org/viewvc/llvm-project?rev=323360&view=rev
> Log:
> [Hexagon] Accept lowercase b in -hvx-length=64b and -hvx-length=128b
>
> Modified:
> cfe/trunk/lib/Driver/ToolChains/Hexagon.cpp
> cfe/trunk/test/Driver/hexagon-hvx.c
>
> Modified: cfe/trunk/lib/Driver/ToolChains/Hexagon.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/
> ToolChains/Hexagon.cpp?rev=323360&r1=323359&r2=323360&view=diff
> 
> ==
> --- cfe/trunk/lib/Driver/ToolChains/Hexagon.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Hexagon.cpp Wed Jan 24 10:42:19 2018
> @@ -46,7 +46,7 @@ static void handleHVXWarnings(const Driv
>// Handle the unsupported values passed to mhvx-length.
>if (Arg *A = Args.getLastArg(options::OPT_mhexagon_hvx_length_EQ)) {
>  StringRef Val = A->getValue();
> -if (Val != "64B" && Val != "128B")
> +if (!Val.equals_lower("64b") && !Val.equals_lower("128b"))
>D.Diag(diag::err_drv_unsupported_option_argument)
><< A->getOption().getName() << Val;
>}
>
> Modified: cfe/trunk/test/Driver/hexagon-hvx.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/
> hexagon-hvx.c?rev=323360&r1=323359&r2=323360&view=diff
> 
> ==
> --- cfe/trunk/test/Driver/hexagon-hvx.c (original)
> +++ cfe/trunk/test/Driver/hexagon-hvx.c Wed Jan 24 10:42:19 2018
> @@ -21,6 +21,9 @@
>
>  // RUN: %clang -c %s -### -target hexagon-unknown-elf -mv62 -mhvx \
>  // RUN:  -mhvx-length=128B 2>&1 | FileCheck -check-prefix=CHECKHVX2 %s
> +
> +// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv62 -mhvx \
> +// RUN:  -mhvx-length=128b 2>&1 | FileCheck -check-prefix=CHECKHVX2 %s
>  // CHECKHVX2-NOT: "-target-feature" "+hvx-length64b"
>  // CHECKHVX2: "-target-feature" "+hvx-length128b"
>
> @@ -79,8 +82,10 @@
>  // The default mode on v60,v62 is 64B.
>  // RUN: %clang -c %s -### -target hexagon-unknown-elf -mv60 -mhvx \
>  // RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVXLENGTH-64B %s
> -// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv60 -mhvx
> -mhvx-length=64B\
> -// RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVXLENGTH-64B %s
> +// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv60 -mhvx \
> +// RUN:  -mhvx-length=64b 2>&1 | FileCheck -check-prefix=CHECK-HVXLENGTH-64B
> %s
> +// RUN: %clang -c %s -### -target hexagon-unknown-elf -mv60 -mhvx \
> +// RUN:  -mhvx-length=64B 2>&1 | FileCheck -check-prefix=CHECK-HVXLENGTH-64B
> %s
>  // CHECK-HVXLENGTH-64B: "-target-feature" "+hvx{{.*}}" "-target-feature"
> "+hvx-length64b"
>  // RUN: %clang -c %s -### -target hexagon-unknown-elf -mv62 -mhvx
> -mhvx-length=128B\
>  // RUN:  2>&1 | FileCheck -check-prefix=CHECK-HVXLENGTH-128B %s
>
>
> ___
> 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


[clang-tools-extra] r323768 - clang-tidy/rename_check.py misc-incorrect-roundings bugprone-incorrect-roundings

2018-01-30 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Jan 30 07:12:24 2018
New Revision: 323768

URL: http://llvm.org/viewvc/llvm-project?rev=323768&view=rev
Log:
clang-tidy/rename_check.py misc-incorrect-roundings bugprone-incorrect-roundings

More specifically,
clang-tidy/rename_check.py misc-incorrect-roundings \
  bugprone-incorrect-roundings --check_class_name IncorrectRoundings

Added:
clang-tools-extra/trunk/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp
  - copied, changed from r323766, 
clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/IncorrectRoundingsCheck.h
  - copied, changed from r323766, 
clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.h

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-incorrect-roundings.rst
  - copied, changed from r323766, 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-incorrect-roundings.rst
clang-tools-extra/trunk/test/clang-tidy/bugprone-incorrect-roundings.cpp
  - copied, changed from r323766, 
clang-tools-extra/trunk/test/clang-tidy/misc-incorrect-roundings.cpp
Removed:
clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp
clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.h
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-incorrect-roundings.rst
clang-tools-extra/trunk/test/clang-tidy/misc-incorrect-roundings.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=323768&r1=323767&r2=323768&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Tue Jan 
30 07:12:24 2018
@@ -18,6 +18,7 @@
 #include "FoldInitTypeCheck.h"
 #include "ForwardDeclarationNamespaceCheck.h"
 #include "InaccurateEraseCheck.h"
+#include "IncorrectRoundingsCheck.h"
 #include "IntegerDivisionCheck.h"
 #include "MisplacedOperatorInStrlenInAllocCheck.h"
 #include "MoveForwardingReferenceCheck.h"
@@ -51,6 +52,8 @@ public:
 "bugprone-forward-declaration-namespace");
 CheckFactories.registerCheck(
 "bugprone-inaccurate-erase");
+CheckFactories.registerCheck(
+"bugprone-incorrect-roundings");
 CheckFactories.registerCheck(
 "bugprone-integer-division");
 CheckFactories.registerCheck(

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt?rev=323768&r1=323767&r2=323768&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Tue Jan 30 
07:12:24 2018
@@ -10,6 +10,7 @@ add_clang_library(clangTidyBugproneModul
   FoldInitTypeCheck.cpp
   ForwardDeclarationNamespaceCheck.cpp
   InaccurateEraseCheck.cpp
+  IncorrectRoundingsCheck.cpp
   IntegerDivisionCheck.cpp
   MisplacedOperatorInStrlenInAllocCheck.cpp
   MoveForwardingReferenceCheck.cpp

Copied: clang-tools-extra/trunk/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp 
(from r323766, clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp)
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp?p2=clang-tools-extra/trunk/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp&p1=clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp&r1=323766&r2=323768&rev=323768&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/IncorrectRoundings.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp Tue 
Jan 30 07:12:24 2018
@@ -1,4 +1,4 @@
-//===--- IncorrectRoundings.cpp - clang-tidy 
--===//
+//===--- IncorrectRoundingsCheck.cpp - clang-tidy 
--===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -7,7 +7,7 @@
 //
 
//===--===//
 
-#include "IncorrectRoundings.h"
+#include "IncorrectRoundingsCheck.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/Type.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -18,7 +18,7 @@ using namespace clang::ast_matchers;
 
 namespace clang {
 namespace tidy {
-namespa

[clang-tools-extra] r323766 - clang-tidy/rename_check.py misc-string-compare readability-string-compare

2018-01-30 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Jan 30 06:55:50 2018
New Revision: 323766

URL: http://llvm.org/viewvc/llvm-project?rev=323766&view=rev
Log:
clang-tidy/rename_check.py misc-string-compare readability-string-compare

Added:
clang-tools-extra/trunk/clang-tidy/readability/StringCompareCheck.cpp
  - copied, changed from r323765, 
clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/StringCompareCheck.h
  - copied, changed from r323765, 
clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/readability-string-compare.rst
  - copied, changed from r323765, 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-compare.rst
clang-tools-extra/trunk/test/clang-tidy/readability-string-compare.cpp
  - copied, changed from r323765, 
clang-tools-extra/trunk/test/clang-tidy/misc-string-compare.cpp
Removed:
clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-string-compare.rst
clang-tools-extra/trunk/test/clang-tidy/misc-string-compare.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt?rev=323766&r1=323765&r2=323766&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt Tue Jan 30 06:55:50 
2018
@@ -17,7 +17,6 @@ add_clang_library(clangTidyMiscModule
   SizeofContainerCheck.cpp
   SizeofExpressionCheck.cpp
   StaticAssertCheck.cpp
-  StringCompareCheck.cpp
   StringIntegerAssignmentCheck.cpp
   StringLiteralWithEmbeddedNulCheck.cpp
   SuspiciousEnumUsageCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp?rev=323766&r1=323765&r2=323766&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp Tue Jan 30 
06:55:50 2018
@@ -24,7 +24,6 @@
 #include "SizeofContainerCheck.h"
 #include "SizeofExpressionCheck.h"
 #include "StaticAssertCheck.h"
-#include "StringCompareCheck.h"
 #include "StringIntegerAssignmentCheck.h"
 #include "StringLiteralWithEmbeddedNulCheck.h"
 #include "SuspiciousEnumUsageCheck.h"
@@ -75,7 +74,6 @@ public:
 CheckFactories.registerCheck(
 "misc-sizeof-expression");
 CheckFactories.registerCheck("misc-static-assert");
-CheckFactories.registerCheck("misc-string-compare");
 CheckFactories.registerCheck(
 "misc-string-integer-assignment");
 CheckFactories.registerCheck(

Removed: clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.cpp?rev=323765&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/StringCompareCheck.cpp (removed)
@@ -1,82 +0,0 @@
-//===--- MiscStringCompare.cpp - 
clang-tidy===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-
-#include "StringCompareCheck.h"
-#include "../utils/FixItHintUtils.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Tooling/FixIt.h"
-
-using namespace clang::ast_matchers;
-
-namespace clang {
-namespace tidy {
-namespace misc {
-
-static const StringRef CompareMessage = "do not use 'compare' to test equality 
"
-"of strings; use the string equality "
-"operator instead";
-
-void StringCompareCheck::registerMatchers(MatchFinder *Finder) {
-  if (!getLangOpts().CPlusPlus)
-return;
-
-  const auto StrCompare = cxxMemberCallExpr(
-  callee(cxxMethodDecl(hasName("compare"),
-   ofClass(classTemplateSpecializationDecl(
-

[clang-tools-extra] r323765 - [clang-tidy] Use a more specific regex

2018-01-30 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Tue Jan 30 06:55:39 2018
New Revision: 323765

URL: http://llvm.org/viewvc/llvm-project?rev=323765&view=rev
Log:
[clang-tidy] Use a more specific regex

Modified:
clang-tools-extra/trunk/clang-tidy/rename_check.py

Modified: clang-tools-extra/trunk/clang-tidy/rename_check.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/rename_check.py?rev=323765&r1=323764&r2=323765&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/rename_check.py (original)
+++ clang-tools-extra/trunk/clang-tidy/rename_check.py Tue Jan 30 06:55:39 2018
@@ -213,7 +213,7 @@ def main():
 
   # Remove the check from the old module.
   cmake_lists = os.path.join(old_module_path, 'CMakeLists.txt')
-  check_found = deleteMatchingLines(cmake_lists, check_name_camel)
+  check_found = deleteMatchingLines(cmake_lists, '\\b' + check_name_camel)
   if not check_found:
 print("Check name '%s' not found in %s. Exiting." %
 (check_name_camel, cmake_lists))
@@ -223,7 +223,7 @@ def main():
   lambda p: p.lower() == old_module.lower() + 'tidymodule.cpp',
   os.listdir(old_module_path))[0]
   deleteMatchingLines(os.path.join(old_module_path, modulecpp),
-  check_name_camel + '|' + args.old_check_name)
+  '\\b' + check_name_camel + '|\\b' + args.old_check_name)
 
   for filename in getListOfFiles(clang_tidy_path):
 originalName = filename


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


[PATCH] D42581: [NVPTX] Emit debug info in DWARF-2 by default for Cuda devices.

2018-01-30 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In https://reviews.llvm.org/D42581#989760, @probinson wrote:

> If you want to force DWARF 2, probably clamping the version in LLVM would be 
> simpler?  Although most of the debug-info tests are architecture-specific and 
> wouldn't run for an NVPTX target anyway.


Hi, I think it would be better to do both: make it default in the frontend and 
in the backend.


Repository:
  rC Clang

https://reviews.llvm.org/D42581



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


[PATCH] D42642: [CUDA] Detect installation in PATH

2018-01-30 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In https://reviews.llvm.org/D42642#991154, @tra wrote:

> In https://reviews.llvm.org/D42642#991127, @Hahnfeld wrote:
>
> > In https://reviews.llvm.org/D42642#990976, @tra wrote:
> >
> > > Some linux distributions integrate CUDA into the standard directory 
> > > structure. I.e. binaries go into /usr/bin, headers into /usr/include, 
> > > bitcode goes somewhere else, etc. ptxas will be found, but we would still 
> > > fail to detect CUDA. I'd add  one more test case to make sure that's 
> > > still the case.
> >
> >
> > I'm not sure how this can work, we only require `bin/` and `include/` to 
> > exist, and `nvvm/libdevice/` if `-nocudalib` isn't specified. I agree this 
> > can be a problem because the defaults might detect an invalid 
> > installation...
>
>
> Good point. Perhaps we want to be more strict about CUDA installation 
> checking if we've found it indirectly via PATH (as opposed to explicit 
> --cuda-path or a known common install path).
>  Should we always check for nvvm/libdevice directory? It's unlikely to be 
> under /usr or /usr/local and it will be always present in a CUDA installation 
> of all currently supported CUDA versions.


That sounds like a sane check. I updated the implementation and added 
corresponding checks.


https://reviews.llvm.org/D42642



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


[PATCH] D42642: [CUDA] Detect installation in PATH

2018-01-30 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld updated this revision to Diff 131963.
Hahnfeld added a comment.

Check for `libdevice` in candidates from `PATH`.


https://reviews.llvm.org/D42642

Files:
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/Cuda.cpp
  test/Driver/Inputs/CUDA-nolibdevice/usr/local/cuda/bin/ptxas
  test/Driver/Inputs/CUDA/usr/local/cuda/bin/ptxas
  test/Driver/cuda-detect-path.cu
  test/Driver/cuda-detect.cu
  test/Driver/cuda-not-found.cu
  test/Driver/cuda-version-check.cu

Index: test/Driver/cuda-version-check.cu
===
--- test/Driver/cuda-version-check.cu
+++ test/Driver/cuda-version-check.cu
@@ -2,50 +2,50 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target
 
-// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_20 --sysroot=%S/Inputs/CUDA 2>&1 %s | \
+// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_20 --cuda-path=%S/Inputs/CUDA/usr/local/cuda 2>&1 %s | \
 // RUN:FileCheck %s --check-prefix=OK
-// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_20 --sysroot=%S/Inputs/CUDA_80 2>&1 %s | \
+// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_20 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda 2>&1 %s | \
 // RUN:FileCheck %s --check-prefix=OK
-// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --sysroot=%S/Inputs/CUDA_80 2>&1 %s | \
+// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda 2>&1 %s | \
 // RUN:FileCheck %s --check-prefix=OK
 
 // The installation at Inputs/CUDA is CUDA 7.0, which doesn't support sm_60.
-// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --sysroot=%S/Inputs/CUDA 2>&1 %s | \
+// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-path=%S/Inputs/CUDA/usr/local/cuda 2>&1 %s | \
 // RUN:FileCheck %s --check-prefix=ERR_SM60
 
 // This should only complain about sm_60, not sm_35.
 // RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-gpu-arch=sm_35 \
-// RUN:--sysroot=%S/Inputs/CUDA 2>&1 %s | \
+// RUN:--cuda-path=%S/Inputs/CUDA/usr/local/cuda 2>&1 %s | \
 // RUN:FileCheck %s --check-prefix=ERR_SM60 --check-prefix=OK_SM35
 
 // We should get two errors here, one for sm_60 and one for sm_61.
 // RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-gpu-arch=sm_61 \
-// RUN:--sysroot=%S/Inputs/CUDA 2>&1 %s | \
+// RUN:--cuda-path=%S/Inputs/CUDA/usr/local/cuda 2>&1 %s | \
 // RUN:FileCheck %s --check-prefix=ERR_SM60 --check-prefix=ERR_SM61
 
 // We should still get an error if we pass -nocudainc, because this compilation
 // would invoke ptxas, and we do a version check on that, too.
-// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 -nocudainc --sysroot=%S/Inputs/CUDA 2>&1 %s | \
+// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 -nocudainc --cuda-path=%S/Inputs/CUDA/usr/local/cuda 2>&1 %s | \
 // RUN:FileCheck %s --check-prefix=ERR_SM60
 
 // If with -nocudainc and -E, we don't touch the CUDA install, so we
 // shouldn't get an error.
 // RUN: %clang --target=x86_64-linux -v -### -E --cuda-device-only --cuda-gpu-arch=sm_60 -nocudainc \
-// RUN:--sysroot=%S/Inputs/CUDA 2>&1 %s | \
+// RUN:--cuda-path=%S/Inputs/CUDA/usr/local/cuda 2>&1 %s | \
 // RUN:FileCheck %s --check-prefix=OK
 
 // --no-cuda-version-check should suppress all of these errors.
-// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --sysroot=%S/Inputs/CUDA 2>&1 \
+// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-path=%S/Inputs/CUDA/usr/local/cuda 2>&1 \
 // RUN:--no-cuda-version-check %s | \
 // RUN:FileCheck %s --check-prefix=OK
 
 // We need to make sure the version check is done only for the device toolchain,
 // therefore we should not get an error in host-only mode. We use the -S here
 // to avoid the error being produced in case by the assembler tool, which does
 // the same check.
-// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-host-only --sysroot=%S/Inputs/CUDA -S 2>&1 %s | \
+// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-host-only --cuda-path=%S/Inputs/CUDA/usr/local/cuda -S 2>&1 %s | \
 // RUN:FileCheck %s --check-prefix=OK
-// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-device-only --sysroot=%S/Inputs/CUDA -S 2>&1 %s | \
+// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-device-only --cuda-path=%S/Inputs/CUDA/usr/local/cuda -S 2>&1 %s | \
 // RUN:FileCheck %s --check-prefix=ERR_SM60
 
 // OK-NOT: error: GPU arch
Index: test/Driver/cuda-not-found.cu
===
--- test/Driver/cuda-not-found.cu
+++ test/Driver/cuda-not-found.cu
@@ -3,10 +3,10 @@
 // Check that we raise an error if we're trying to compile CUDA code but can't
 // find 

[PATCH] D40259: [libcxx] LWG2993: reference_wrapper

2018-01-30 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists accepted this revision.
mclow.lists added a comment.

Please be sure to update www/cxx2a_status.html to mark 2993 as "Complete".
Other than that, looks good to me! Thanks!


https://reviews.llvm.org/D40259



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


[PATCH] D42685: [clang-format] Adds space around braces in text protos

2018-01-30 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.

Looks good.


Repository:
  rC Clang

https://reviews.llvm.org/D42685



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


[PATCH] D26418: [clang-tidy] Add '-suppress-checks-filter' option to suppress diagnostics from certain files

2018-01-30 Thread Andrew Peter Marlow via Phabricator via cfe-commits
marlowa added a comment.

In https://reviews.llvm.org/D26418#653146, @nkakuev wrote:

> Ping.


another ping. I am desperate for this enhancement and am really glad that 
nkakuev has done all the hard development work. I am currently being nobbled in 
my use of clang-tidy because the project is using Rogue Wave Stingray headers 
and BCG Control bar headers. Both these components cause loads of clang-tidy 
issues when the headers get included. This enhancement seems to provide just 
the mechanism I need.


https://reviews.llvm.org/D26418



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


[PATCH] D42685: [clang-format] Adds space around braces in text protos

2018-01-30 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
krasimir added a reviewer: djasper.
Herald added subscribers: cfe-commits, klimek.

This patch modifies the text proto Google style to add spaces around braces.

I investigated using something different than Cpp11BracedListStyle, but it 
turns out it's what we want and also the java and js styles also depend on that.


Repository:
  rC Clang

https://reviews.llvm.org/D42685

Files:
  lib/Format/Format.cpp
  unittests/Format/FormatTestProto.cpp
  unittests/Format/FormatTestRawStrings.cpp
  unittests/Format/FormatTestTextProto.cpp

Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -49,9 +49,9 @@
 TEST_F(FormatTestTextProto, SupportsMessageFields) {
   verifyFormat("msg_field: {}");
 
-  verifyFormat("msg_field: {field_a: A}");
+  verifyFormat("msg_field: { field_a: A }");
 
-  verifyFormat("msg_field: {field_a: \"OK\" field_b: 123}");
+  verifyFormat("msg_field: { field_a: \"OK\" field_b: 123 }");
 
   verifyFormat("msg_field: {\n"
"  field_a: 1\n"
@@ -63,9 +63,9 @@
 
   verifyFormat("msg_field {}");
 
-  verifyFormat("msg_field {field_a: A}");
+  verifyFormat("msg_field { field_a: A }");
 
-  verifyFormat("msg_field {field_a: \"OK\" field_b: 123}");
+  verifyFormat("msg_field { field_a: \"OK\" field_b: 123 }");
 
   verifyFormat("msg_field {\n"
"  field_a: 1\n"
@@ -78,11 +78,11 @@
"  field_h: 1234.567e-89\n"
"}");
 
-  verifyFormat("msg_field: {msg_field {field_a: 1}}");
+  verifyFormat("msg_field: { msg_field { field_a: 1 } }");
 
   verifyFormat("id: \"ala.bala\"\n"
-   "item {type: ITEM_A rank: 1 score: 90.0}\n"
-   "item {type: ITEM_B rank: 2 score: 70.5}\n"
+   "item { type: ITEM_A rank: 1 score: 90.0 }\n"
+   "item { type: ITEM_B rank: 2 score: 70.5 }\n"
"item {\n"
"  type: ITEM_A\n"
"  rank: 3\n"
@@ -102,24 +102,24 @@
   verifyFormat("field_a: OK\n"
"field_b: \"OK\"\n"
"field_c: \"OK\"\n"
-   "msg_field: {field_d: 123}\n"
+   "msg_field: { field_d: 123 }\n"
"field_e: OK\n"
"field_f: OK");
 
   verifyFormat("field_a: OK\n"
"field_b: \"OK\"\n"
"field_c: \"OK\"\n"
-   "msg_field: {field_d: 123 field_e: OK}");
+   "msg_field: { field_d: 123 field_e: OK }");
 
   verifyFormat("a: {\n"
"  field_a: OK\n"
-   "  field_b {field_c: OK}\n"
+   "  field_b { field_c: OK }\n"
"  field_d: OKOKOK\n"
"  field_e: OK\n"
"}");
 
   verifyFormat("field_a: OK,\n"
-   "field_b {field_c: OK},\n"
+   "field_b { field_c: OK },\n"
"field_d: OKOKOK,\n"
"field_e: OK");
 }
@@ -150,10 +150,10 @@
   verifyFormat("msg_field: >>");
   verifyFormat("msg_field ");
   verifyFormat("msg_field , field_c: OK>");
-  verifyFormat("msg_field >");
+  verifyFormat("msg_field >");
   verifyFormat("msg_field: ");
   verifyFormat("msg_field: , field_c: OK>");
-  verifyFormat("msg_field: >");
+  verifyFormat("msg_field: >");
   verifyFormat("field_a: \"OK\", msg_field: , field_c: {}");
   verifyFormat("field_a , msg_field: , field_c <>");
   verifyFormat("field_a  msg_field:  field_c <>");
@@ -200,7 +200,7 @@
 
   verifyFormat("msg_field: <\n"
"  field_a: \"OK\"\n"
-   "  msg_field: {field_b: OK}\n"
+   "  msg_field: { field_b: OK }\n"
"  field_g: OK\n"
"  field_g: OK\n"
"  field_g: OK\n"
@@ -226,7 +226,7 @@
"  field_b2: ok,\n"
"  field_b3: <\n"
"field_x {}  // Comment\n"
-   "field_y: {field_z: 1}\n"
+   "field_y: { field_z: 1 }\n"
"field_w: ok\n"
"  >\n"
"  field {\n"
@@ -258,7 +258,7 @@
   verifyFormat("app_id: 'com.javax.swing.salsa.latino'\n"
"head_id: 1\n"
"data \n"
-   "data {key: value}");
+   "data { key: value }");
 
   verifyFormat("app {\n"
"  app_id: 'com.javax.swing.salsa.latino'\n"
@@ -274,24 +274,24 @@
 
   verifyFormat("app_id: 'com.javax.swing.salsa.latino'\n"
"headheadheadheadheadhead_id: 1\n"
-   "product_data {product {1}}");
+   "product_data { product { 1 } }");
 
   verifyFormat("app_id: 'com.javax.swing.salsa.latino'\n"
"headheadheadheadheadhead_id: 1\n"
-   "product_data ");
+   "product_data ");
 
   verifyFormat("app_id: 'com.javax.swing.salsa.latino'\n"
"headheadheadheadheadhead_id: 1\n"
"prod

[clang-tools-extra] r323722 - add prefix with '_' support for property name. Corresponding apple dev doc: https://developer.apple.com/library/content/qa/qa1908/_index.html

2018-01-30 Thread Yan Zhang via cfe-commits
Author: wizard
Date: Mon Jan 29 17:44:00 2018
New Revision: 323722

URL: http://llvm.org/viewvc/llvm-project?rev=323722&view=rev
Log:
add prefix with '_' support for property name. Corresponding apple dev doc: 
https://developer.apple.com/library/content/qa/qa1908/_index.html

Reviewers: benhamilton, hokein

Reviewed By: benhamilton

Subscribers: klimek, cfe-commits

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

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

clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration-additional.m
clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration-custom.m
clang-tools-extra/trunk/test/clang-tidy/objc-property-declaration.m

Modified: clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp?rev=323722&r1=323721&r2=323722&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp Mon 
Jan 29 17:44:00 2018
@@ -8,13 +8,14 @@
 
//===--===//
 
 #include "PropertyDeclarationCheck.h"
+#include 
 #include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "llvm/ADT/STLExtras.h"
+#include "clang/Basic/CharInfo.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Regex.h"
-#include 
 
 using namespace clang::ast_matchers;
 
@@ -23,6 +24,16 @@ namespace tidy {
 namespace objc {
 
 namespace {
+
+// For StandardProperty the naming style is 'lowerCamelCase'.
+// For CategoryProperty especially in categories of system class,
+// to avoid naming conflict, the suggested naming style is
+// 'abc_lowerCamelCase' (adding lowercase prefix followed by '_').
+enum NamingStyle {
+  StandardProperty = 1,
+  CategoryProperty = 2,
+};
+
 /// The acronyms are from
 /// 
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/APIAbbreviations.html#//apple_ref/doc/uid/20001285-BCIHCGAE
 ///
@@ -84,22 +95,31 @@ constexpr llvm::StringLiteral DefaultSpe
 "XML",
 };
 
-/// For now we will only fix 'CamelCase' property to
-/// 'camelCase'. For other cases the users need to
+/// For now we will only fix 'CamelCase' or 'abc_CamelCase' property to
+/// 'camelCase' or 'abc_camelCase'. For other cases the users need to
 /// come up with a proper name by their own.
 /// FIXME: provide fix for snake_case to snakeCase
-FixItHint generateFixItHint(const ObjCPropertyDecl *Decl) {
-  if (isupper(Decl->getName()[0])) {
-auto NewName = Decl->getName().str();
-NewName[0] = tolower(NewName[0]);
-return FixItHint::CreateReplacement(
-CharSourceRange::getTokenRange(SourceRange(Decl->getLocation())),
-llvm::StringRef(NewName));
+FixItHint generateFixItHint(const ObjCPropertyDecl *Decl, NamingStyle Style) {
+  auto Name = Decl->getName();
+  auto NewName = Decl->getName().str();
+  size_t Index = 0;
+  if (Style == CategoryProperty) {
+Index = Name.find_first_of('_') + 1;
+NewName.replace(0, Index - 1, Name.substr(0, Index - 1).lower());
+  }
+  if (Index < Name.size()) {
+NewName[Index] = tolower(NewName[Index]);
+if (NewName != Name) {
+  return FixItHint::CreateReplacement(
+  CharSourceRange::getTokenRange(SourceRange(Decl->getLocation())),
+  llvm::StringRef(NewName));
+}
   }
   return FixItHint();
 }
 
-std::string validPropertyNameRegex(const std::vector 
&EscapedAcronyms) {
+std::string validPropertyNameRegex(llvm::ArrayRef EscapedAcronyms,
+   bool UsedInMatcher) {
   // Allow any of these names:
   // foo
   // fooBar
@@ -108,10 +128,31 @@ std::string validPropertyNameRegex(const
   // URL
   // URLString
   // bundleID
-  return std::string("::((") +
-  llvm::join(EscapedAcronyms.begin(), EscapedAcronyms.end(), "|") +
-  ")[A-Z]?)?[a-z]+[a-z0-9]*([A-Z][a-z0-9]+)*" + "(" +
-  llvm::join(EscapedAcronyms.begin(), EscapedAcronyms.end(), "|") + ")?$";
+  std::string StartMatcher = UsedInMatcher ? "::" : "^";
+
+  return StartMatcher + "((" +
+ llvm::join(EscapedAcronyms.begin(), EscapedAcronyms.end(), "|") +
+ ")[A-Z]?)?[a-z]+[a-z0-9]*([A-Z][a-z0-9]+)*" + "(" +
+ llvm::join(EscapedAcronyms.begin(), EscapedAcronyms.end(), "|") +
+ ")?$";
+}
+
+bool hasCategoryPropertyPrefix(llvm::StringRef PropertyName) {
+  auto RegexExp = llvm::Regex("^[a-zA-Z]+_[a-zA-Z0-9][a-zA-Z0-9_]+$");
+  return RegexExp.match(PropertyName);
+}
+
+bool prefixedPropertyNameValid(llvm:

[PATCH] D42684: clang-format: Allow optimizer to break template declaration.

2018-01-30 Thread Francois Ferrand via Phabricator via cfe-commits
Typz updated this revision to Diff 131946.
Typz added a comment.

fix commit message


Repository:
  rC Clang

https://reviews.llvm.org/D42684

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

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -5367,7 +5367,7 @@
"const typename  aaa);");
 
   FormatStyle AlwaysBreak = getLLVMStyle();
-  AlwaysBreak.AlwaysBreakTemplateDeclarations = true;
+  AlwaysBreak.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_All;
   verifyFormat("template \nclass C {};", AlwaysBreak);
   verifyFormat("template \nvoid f();", AlwaysBreak);
   verifyFormat("template \nvoid f() {}", AlwaysBreak);
@@ -5385,6 +5385,31 @@
"public:\n"
"  E *f();\n"
"};");
+
+  FormatStyle NeverBreak = getLLVMStyle();
+  NeverBreak.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_None;
+  verifyFormat("template  class C {};", NeverBreak);
+  verifyFormat("template  void f();", NeverBreak);
+  verifyFormat("template  void f() {}", NeverBreak);
+  verifyFormat("template \nvoid foo(aa ) {}",
+   NeverBreak);
+  verifyFormat("void aaa(\n"
+   "ccc);",
+   NeverBreak);
+  verifyFormat("template  class Fooo,\n"
+   "  template  class Baaar> struct C {};",
+   NeverBreak);
+  verifyFormat("template  // T can be A, B or C.\n"
+   "struct C {};",
+   NeverBreak);
+  verifyFormat("template  class A {\n"
+   "public:\n"
+   "  E *f();\n"
+   "};", NeverBreak);
+  NeverBreak.PenaltyBreakTemplateDeclaration = 100;
+  verifyFormat("template  void\nfoo(aa ) {}",
+   NeverBreak);
 }
 
 TEST_F(FormatTest, WrapsTemplateParameters) {
@@ -10166,7 +10191,6 @@
   CHECK_PARSE_BOOL(AllowShortCaseLabelsOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortIfStatementsOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
-  CHECK_PARSE_BOOL(AlwaysBreakTemplateDeclarations);
   CHECK_PARSE_BOOL(BinPackArguments);
   CHECK_PARSE_BOOL(BinPackParameters);
   CHECK_PARSE_BOOL(BreakAfterJavaFieldAnnotations);
@@ -10229,6 +10253,8 @@
   PenaltyBreakAssignment, 1234u);
   CHECK_PARSE("PenaltyBreakBeforeFirstCallParameter: 1234",
   PenaltyBreakBeforeFirstCallParameter, 1234u);
+  CHECK_PARSE("PenaltyBreakTemplateDeclaration: 1234",
+  PenaltyBreakTemplateDeclaration, 1234u);
   CHECK_PARSE("PenaltyExcessCharacter: 1234", PenaltyExcessCharacter, 1234u);
   CHECK_PARSE("PenaltyReturnTypeOnItsOwnLine: 1234",
   PenaltyReturnTypeOnItsOwnLine, 1234u);
@@ -10383,6 +10409,18 @@
   AlwaysBreakAfterReturnType,
   FormatStyle::RTBS_TopLevelDefinitions);
 
+  Style.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_All;
+  CHECK_PARSE("AlwaysBreakTemplateDeclarations: None", AlwaysBreakTemplateDeclarations,
+  FormatStyle::BTDS_None);
+  CHECK_PARSE("AlwaysBreakTemplateDeclarations: BeforeFunction", AlwaysBreakTemplateDeclarations,
+  FormatStyle::BTDS_BeforeFunction);
+  CHECK_PARSE("AlwaysBreakTemplateDeclarations: All", AlwaysBreakTemplateDeclarations,
+  FormatStyle::BTDS_All);
+  CHECK_PARSE("AlwaysBreakTemplateDeclarations: false", AlwaysBreakTemplateDeclarations,
+  FormatStyle::BTDS_BeforeFunction);
+  CHECK_PARSE("AlwaysBreakTemplateDeclarations: true", AlwaysBreakTemplateDeclarations,
+  FormatStyle::BTDS_All);
+
   Style.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_All;
   CHECK_PARSE("AlwaysBreakAfterDefinitionReturnType: None",
   AlwaysBreakAfterDefinitionReturnType, FormatStyle::DRTBS_None);
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2171,6 +2171,8 @@
   return 2;
 return 1;
   }
+  if (Left.ClosesTemplateDeclaration)
+  return Style.PenaltyBreakTemplateDeclaration;
   if (Left.is(TT_ConditionalExpr))
 return prec::Conditional;
   prec::Level Level = Left.getPrecedence();
@@ -2641,7 +2643,7 @@
   if (Right.Previous->ClosesTemplateDeclaration &&
   Right.Previous->MatchingParen &&
   Right.Previous->MatchingParen->NestingLevel == 0 &&
-  Style.AlwaysBreakTemplateDeclarations)
+  Style.AlwaysBreakTemplateDeclarations == FormatStyle::BTDS_All)
 return true;
   if (Right.is(TT_CtorInitializerComma) &&
   Style.BreakConstructorInitializers == FormatStyle::BCIS_Before

[PATCH] D42684: clang-format: Allow optimizer to break template declaration.

2018-01-30 Thread Francois Ferrand via Phabricator via cfe-commits
Typz created this revision.
Typz added reviewers: krasimir, djasper, klimek.

Introduce ``PenaltyBreakTemplateDeclaration`` to control the penalty,
and change ``AlwaysBreakTemplateDeclarations`` to an enum with 3 modes:

- ``None`` for automatic (e.g. penalty based) wrapping of template

declaration

- ``BeforeFunction`` for always wrapping before functions, and applying

penalty before classes (e.g. same as legacy behavior when
AlwaysBreakTemplateDeclarations=false)

- ``Always`` for always wrapping (e.g. same as legacy behavior when

AlwaysBreakTemplateDeclarations=true)


Repository:
  rC Clang

https://reviews.llvm.org/D42684

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

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -5367,7 +5367,7 @@
"const typename  aaa);");
 
   FormatStyle AlwaysBreak = getLLVMStyle();
-  AlwaysBreak.AlwaysBreakTemplateDeclarations = true;
+  AlwaysBreak.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_All;
   verifyFormat("template \nclass C {};", AlwaysBreak);
   verifyFormat("template \nvoid f();", AlwaysBreak);
   verifyFormat("template \nvoid f() {}", AlwaysBreak);
@@ -5385,6 +5385,31 @@
"public:\n"
"  E *f();\n"
"};");
+
+  FormatStyle NeverBreak = getLLVMStyle();
+  NeverBreak.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_None;
+  verifyFormat("template  class C {};", NeverBreak);
+  verifyFormat("template  void f();", NeverBreak);
+  verifyFormat("template  void f() {}", NeverBreak);
+  verifyFormat("template \nvoid foo(aa ) {}",
+   NeverBreak);
+  verifyFormat("void aaa(\n"
+   "ccc);",
+   NeverBreak);
+  verifyFormat("template  class Fooo,\n"
+   "  template  class Baaar> struct C {};",
+   NeverBreak);
+  verifyFormat("template  // T can be A, B or C.\n"
+   "struct C {};",
+   NeverBreak);
+  verifyFormat("template  class A {\n"
+   "public:\n"
+   "  E *f();\n"
+   "};", NeverBreak);
+  NeverBreak.PenaltyBreakTemplateDeclaration = 100;
+  verifyFormat("template  void\nfoo(aa ) {}",
+   NeverBreak);
 }
 
 TEST_F(FormatTest, WrapsTemplateParameters) {
@@ -10166,7 +10191,6 @@
   CHECK_PARSE_BOOL(AllowShortCaseLabelsOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortIfStatementsOnASingleLine);
   CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
-  CHECK_PARSE_BOOL(AlwaysBreakTemplateDeclarations);
   CHECK_PARSE_BOOL(BinPackArguments);
   CHECK_PARSE_BOOL(BinPackParameters);
   CHECK_PARSE_BOOL(BreakAfterJavaFieldAnnotations);
@@ -10229,6 +10253,8 @@
   PenaltyBreakAssignment, 1234u);
   CHECK_PARSE("PenaltyBreakBeforeFirstCallParameter: 1234",
   PenaltyBreakBeforeFirstCallParameter, 1234u);
+  CHECK_PARSE("PenaltyBreakTemplateDeclaration: 1234",
+  PenaltyBreakTemplateDeclaration, 1234u);
   CHECK_PARSE("PenaltyExcessCharacter: 1234", PenaltyExcessCharacter, 1234u);
   CHECK_PARSE("PenaltyReturnTypeOnItsOwnLine: 1234",
   PenaltyReturnTypeOnItsOwnLine, 1234u);
@@ -10383,6 +10409,18 @@
   AlwaysBreakAfterReturnType,
   FormatStyle::RTBS_TopLevelDefinitions);
 
+  Style.AlwaysBreakTemplateDeclarations = FormatStyle::BTDS_All;
+  CHECK_PARSE("AlwaysBreakTemplateDeclarations: None", AlwaysBreakTemplateDeclarations,
+  FormatStyle::BTDS_None);
+  CHECK_PARSE("AlwaysBreakTemplateDeclarations: BeforeFunction", AlwaysBreakTemplateDeclarations,
+  FormatStyle::BTDS_BeforeFunction);
+  CHECK_PARSE("AlwaysBreakTemplateDeclarations: All", AlwaysBreakTemplateDeclarations,
+  FormatStyle::BTDS_All);
+  CHECK_PARSE("AlwaysBreakTemplateDeclarations: false", AlwaysBreakTemplateDeclarations,
+  FormatStyle::BTDS_BeforeFunction);
+  CHECK_PARSE("AlwaysBreakTemplateDeclarations: true", AlwaysBreakTemplateDeclarations,
+  FormatStyle::BTDS_All);
+
   Style.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_All;
   CHECK_PARSE("AlwaysBreakAfterDefinitionReturnType: None",
   AlwaysBreakAfterDefinitionReturnType, FormatStyle::DRTBS_None);
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2171,6 +2171,8 @@
   return 2;
 return 1;
   }
+  if (Left.ClosesTemplateDeclaration)
+  return Style.PenaltyBreakTemplateDeclaration;
   if (Left.is(TT_ConditionalExpr))
  

[PATCH] D42493: [clang-format] Fix ObjC message arguments formatting.

2018-01-30 Thread Jacek Olesiak via Phabricator via cfe-commits
jolesiak updated this revision to Diff 131943.
jolesiak added a comment.

- Add test


Repository:
  rC Clang

https://reviews.llvm.org/D42493

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

Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -655,6 +655,39 @@
"ofSize:aa:bbb\n"
"  atOrigin:cc:dd];");
 
+  // Inline block as a first argument.
+  verifyFormat("[object justBlock:^{\n"
+   "  a = 42;\n"
+   "}];");
+  verifyFormat("[object\n"
+   "justBlock:^{\n"
+   "  a = 42;\n"
+   "}\n"
+   " notBlock:42\n"
+   "a:42];");
+  verifyFormat("[object\n"
+   "firstBlock:^{\n"
+   "  a = 42;\n"
+   "}\n"
+   "blockWithLongerName:^{\n"
+   "  a = 42;\n"
+   "}];");
+  verifyFormat("[object\n"
+   "blockWithLongerName:^{\n"
+   "  a = 42;\n"
+   "}\n"
+   "secondBlock:^{\n"
+   "  a = 42;\n"
+   "}];");
+  verifyFormat("[object\n"
+   "firstBlock:^{\n"
+   "  a = 42;\n"
+   "}\n"
+   "notBlock:42\n"
+   "secondBlock:^{\n"
+   "  a = 42;\n"
+   "}];");
+
   Style.ColumnLimit = 70;
   verifyFormat(
   "void f() {\n"
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -401,6 +401,8 @@
 if (Contexts.back().FirstObjCSelectorName) {
   Contexts.back().FirstObjCSelectorName->LongestObjCSelectorName =
   Contexts.back().LongestObjCSelectorName;
+  Contexts.back().FirstObjCSelectorName->ObjCSelectorNameParts =
+  Left->ParameterCount;
   if (Left->BlockParameterCount > 1)
 Contexts.back().FirstObjCSelectorName->LongestObjCSelectorName = 0;
 }
@@ -414,6 +416,11 @@
   TT_DesignatedInitializerLSquare)) {
   Left->Type = TT_ObjCMethodExpr;
   StartsObjCMethodExpr = true;
+  // ParameterCount might have been set to 1 before expression was
+  // recognized as ObjCMethodExpr (as '1 + number of commas' formula is
+  // used for other expression types). Parameter counter has to be,
+  // therefore, reset to 0.
+  Left->ParameterCount = 0;
   Contexts.back().ColonIsObjCMethodExpr = true;
   if (Parent && Parent->is(tok::r_paren))
 Parent->Type = TT_CastRParen;
@@ -486,7 +493,10 @@
   void updateParameterCount(FormatToken *Left, FormatToken *Current) {
 if (Current->is(tok::l_brace) && Current->BlockKind == BK_Block)
   ++Left->BlockParameterCount;
-if (Current->is(tok::comma)) {
+if (Left->Type == TT_ObjCMethodExpr) {
+  if (Current->is(tok::colon))
+++Left->ParameterCount;
+} else if (Current->is(tok::comma)) {
   ++Left->ParameterCount;
   if (!Left->Role)
 Left->Role.reset(new CommaSeparatedList(Style));
Index: lib/Format/FormatToken.h
===
--- lib/Format/FormatToken.h
+++ lib/Format/FormatToken.h
@@ -240,6 +240,10 @@
   /// e.g. because several of them are block-type.
   unsigned LongestObjCSelectorName = 0;
 
+  /// \brief How many parts ObjC selector have (i.e. how many parameters method
+  /// has).
+  unsigned ObjCSelectorNameParts = 0;
+
   /// \brief Stores the number of required fake parentheses and the
   /// corresponding operator precedence.
   ///
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -266,6 +266,11 @@
 return true;
   if (Previous.is(tok::semi) && State.LineContainsContinuedForLoopSection)
 return true;
+  if (Style.Language == FormatStyle::LK_ObjC &&
+  Current.ObjCSelectorNameParts > 1 &&
+  Current.startsSequence(TT_SelectorName, tok::colon, tok::caret)) {
+return true;
+  }
   if ((startsNextParameter(Current, Style) || Previous.is(tok::semi) ||
(Previous.is(TT_TemplateCloser) && Current.is(TT_StartOfName) &&
 Style.isCpp() &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42174: [clangd] Refactored threading in ClangdServer

2018-01-30 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

As discussed offline, basically the only thing to do for testing ThreadPool is 
to bash it with a workload, and some sort of whole-program stress test seems 
ideal for this and will also give some coverage to other components (and we 
should run under tsan!).

TUScheduler on the other hand is a big important class with a clear interface 
and contract, and is about to get a new implementation - testcases verifying 
the contracts will be extremely valuable.
These tests don't really need to be concurrency-heavy I think.




Comment at: clangd/TUScheduler.h:10
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_THREADING_SCHEDULER_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_THREADING_SCHEDULER_H

header guards are stale, sorry!



Comment at: clangd/Threading.h:10
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_THREADING_THREADPOOL_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_THREADING_THREADPOOL_H

this one also stale


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42174



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


[PATCH] D42682: [clang-tidy] Add misc-io-functions-misused checker

2018-01-30 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added a comment.

Why only the wide versions?
Even narrow versions return an int so that you can check for EOF.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42682



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


[PATCH] D42174: [clangd] Refactored threading in ClangdServer

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



Comment at: clangd/threading/TUScheduler.h:1
+//===--- TUScheduler.h ---*-C++-*-===//
+//

sammccall wrote:
> this class needs tests
Will do :-(



Comment at: clangd/threading/ThreadPool.h:1
+//===--- ThreadPool.h *- 
C++-*-===//
+//

sammccall wrote:
> this class needs tests
Will do :-(


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42174



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


[clang-tools-extra] r323751 - [clangd] Fix windows path manipulation

2018-01-30 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Tue Jan 30 03:23:11 2018
New Revision: 323751

URL: http://llvm.org/viewvc/llvm-project?rev=323751&view=rev
Log:
[clangd] Fix windows path manipulation

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

Modified: clang-tools-extra/trunk/clangd/Protocol.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=323751&r1=323750&r2=323751&view=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.cpp (original)
+++ clang-tools-extra/trunk/clangd/Protocol.cpp Tue Jan 30 03:23:11 2018
@@ -37,8 +37,12 @@ bool fromJSON(const json::Expr &E, URIFo
   "Clangd only supports 'file' URI scheme for workspace files: " + *S);
   return false;
 }
-// We know that body of a file URI is absolute path.
-R.file = U->body();
+auto Path = URI::resolve(*U);
+if (!Path) {
+  log(Context::empty(), llvm::toString(Path.takeError()));
+  return false;
+}
+R.file = *Path;
 return true;
   }
   return false;


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


[PATCH] D42493: [clang-format] Fix ObjC message arguments formatting.

2018-01-30 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: unittests/Format/FormatTestObjC.cpp:678
+   "  a = 42;\n"
+   "}\n"
+   "secondBlock:^{\n"

Can you put a test with a non-block between two blocks please


Repository:
  rC Clang

https://reviews.llvm.org/D42493



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


[PATCH] D42174: [clangd] Refactored threading in ClangdServer

2018-01-30 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 131941.
ilya-biryukov added a comment.

- Remove threading/ dir, moved everything to the top-level
- Rename ThreadPool.h to Threading.h


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42174

Files:
  clangd/CMakeLists.txt
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/ClangdUnitStore.h
  clangd/TUScheduler.cpp
  clangd/TUScheduler.h
  clangd/Threading.cpp
  clangd/Threading.h

Index: clangd/Threading.h
===
--- /dev/null
+++ clangd/Threading.h
@@ -0,0 +1,81 @@
+//===--- ThreadPool.h *- C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_THREADING_THREADPOOL_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_THREADING_THREADPOOL_H
+
+#include "Function.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace clangd {
+/// A simple fixed-size thread pool implementation.
+class ThreadPool {
+public:
+  /// If \p AsyncThreadsCount is 0, requests added using addToFront and addToEnd
+  /// will be processed synchronously on the calling thread.
+  // Otherwise, \p AsyncThreadsCount threads will be created to schedule the
+  // requests.
+  ThreadPool(unsigned AsyncThreadsCount);
+  ~ThreadPool();
+
+  /// Add a new request to run function \p F with args \p As to the start of the
+  /// queue. The request will be run on a separate thread.
+  template 
+  void addToFront(Func &&F, Args &&... As) {
+if (RunSynchronously) {
+  std::forward(F)(std::forward(As)...);
+  return;
+}
+
+{
+  std::lock_guard Lock(Mutex);
+  RequestQueue.push_front(
+  BindWithForward(std::forward(F), std::forward(As)...));
+}
+RequestCV.notify_one();
+  }
+
+  /// Add a new request to run function \p F with args \p As to the end of the
+  /// queue. The request will be run on a separate thread.
+  template  void addToEnd(Func &&F, Args &&... As) {
+if (RunSynchronously) {
+  std::forward(F)(std::forward(As)...);
+  return;
+}
+
+{
+  std::lock_guard Lock(Mutex);
+  RequestQueue.push_back(
+  BindWithForward(std::forward(F), std::forward(As)...));
+}
+RequestCV.notify_one();
+  }
+
+private:
+  bool RunSynchronously;
+  mutable std::mutex Mutex;
+  /// We run some tasks on separate threads(parsing, CppFile cleanup).
+  /// These threads looks into RequestQueue to find requests to handle and
+  /// terminate when Done is set to true.
+  std::vector Workers;
+  /// Setting Done to true will make the worker threads terminate.
+  bool Done = false;
+  /// A queue of requests.
+  std::deque> RequestQueue;
+  /// Condition variable to wake up worker threads.
+  std::condition_variable RequestCV;
+};
+} // namespace clangd
+} // namespace clang
+#endif
Index: clangd/Threading.cpp
===
--- /dev/null
+++ clangd/Threading.cpp
@@ -0,0 +1,61 @@
+#include "Threading.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/Threading.h"
+
+namespace clang {
+namespace clangd {
+ThreadPool::ThreadPool(unsigned AsyncThreadsCount)
+: RunSynchronously(AsyncThreadsCount == 0) {
+  if (RunSynchronously) {
+// Don't start the worker thread if we're running synchronously
+return;
+  }
+
+  Workers.reserve(AsyncThreadsCount);
+  for (unsigned I = 0; I < AsyncThreadsCount; ++I) {
+Workers.push_back(std::thread([this, I]() {
+  llvm::set_thread_name(llvm::formatv("scheduler/{0}", I));
+  while (true) {
+UniqueFunction Request;
+
+// Pick request from the queue
+{
+  std::unique_lock Lock(Mutex);
+  // Wait for more requests.
+  RequestCV.wait(Lock,
+ [this] { return !RequestQueue.empty() || Done; });
+  if (Done)
+return;
+
+  assert(!RequestQueue.empty() && "RequestQueue was empty");
+
+  // We process requests starting from the front of the queue. Users of
+  // ThreadPool have a way to prioritise their requests by putting
+  // them to the either side of the queue (using either addToEnd or
+  // addToFront).
+  Request = std::move(RequestQueue.front());
+  RequestQueue.pop_front();
+} // unlock Mutex
+
+Request();
+  }
+}));
+  }
+}
+
+ThreadPool::~ThreadPool() {
+  if (RunSynchronously)
+return; // no worker thread is running in that case
+
+  {
+std::lock_guard Lock(Mutex);
+// Wake up the worker thread
+Done = true;
+  } // unlock Mutex
+  RequestCV.notify_all();
+
+  for (auto &Worker : Workers)
+Worker.join();
+}
+} // names

[PATCH] D42682: [clang-tidy] Add misc-io-functions-misused checker

2018-01-30 Thread Gábor Horváth via Phabricator via cfe-commits
hgabii created this revision.
hgabii added a reviewer: clang-tools-extra.
hgabii added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, hintonda, mgorny, srhines.

Add misc-io-functions-misused checker to warns for cases when the return value 
of certain standard iostream C functions (fgetwc, getwc, getwchar, 
istream::get()) return int value which is then incorrectly stored in char typed 
values.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42682

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/IoFunctionsMisusedCheck.cpp
  clang-tidy/misc/IoFunctionsMisusedCheck.h
  clang-tidy/misc/MiscTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-io-functions-misused.rst
  test/clang-tidy/misc-io-functions-misused.cpp

Index: test/clang-tidy/misc-io-functions-misused.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-io-functions-misused.cpp
@@ -0,0 +1,74 @@
+// RUN: %check_clang_tidy %s misc-io-functions-misused %t
+
+typedef int wint_t;
+typedef void *FILE;
+
+namespace std {
+wint_t getwchar();
+wint_t getwc(FILE);
+wint_t fgetwc(FILE);
+class istream {
+public:
+  wint_t get();
+};
+} // namespace std
+
+int char_io_getwchar() {
+  char c;
+  c = std::getwchar();
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: consider to cast the return value of 'getwchar' from type integer to type char, possible loss of precision if an error has occurred or the end of file has been reached [misc-io-functions-misused]
+  return c;
+}
+
+int char_io_getwc(FILE *fp) {
+  char c;
+  c = std::getwc(fp);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: consider to cast the return value of 'getwc' from type integer to type char, possible loss of precision if an error has occurred or the end of file has been reached [misc-io-functions-misused]
+  return c;
+}
+
+int char_io_fgetwc(FILE *fp) {
+  char c;
+  c = std::fgetwc(fp);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: consider to cast the return value of 'fgetwc' from type integer to type char, possible loss of precision if an error has occurred or the end of file has been reached [misc-io-functions-misused]
+  return c;
+}
+
+int char_io_get(std::istream &is) {
+  char c;
+  c = is.get();
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: consider to cast the return value of 'get' from type integer to type char, possible loss of precision if an error has occurred or the end of file has been reached [misc-io-functions-misused]
+  return c;
+}
+
+void char_type_in_argument(char c) {}
+
+void call_char_type_in_argument_with_getwchar() {
+  char_type_in_argument(std::getwchar());
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: consider to cast the return value of 'getwchar' from type integer to type char, possible loss of precision if an error has occurred or the end of file has been reached [misc-io-functions-misused]
+}
+
+// Negatives
+int int_io_getwchar() {
+  int x;
+  x = std::getwchar();
+  return x;
+}
+
+int int_io_getwc(FILE *fp) {
+  int x;
+  x = std::getwc(fp);
+  return x;
+}
+
+int int_io_fgetwc(FILE *fp) {
+  int x;
+  x = std::fgetwc(fp);
+  return x;
+}
+
+int int_io_get(std::istream &is) {
+  int x;
+  x = is.get();
+  return x;
+}
Index: docs/clang-tidy/checks/misc-io-functions-misused.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-io-functions-misused.rst
@@ -0,0 +1,34 @@
+.. title:: clang-tidy - misc-io-functions-misused
+
+misc-io-functions-misused
+=
+
+This checker warns for cases when the return value of certain standard iostream C functions
+(fgetwc, getwc, getwchar, istream::get()) return int value which is then incorrectly stored 
+in char typed values which can cause overflow at type conversion.
+This check is valid in C and C++.
+
+Checking for implicit cast from integer to char.
+
+.. code-block:: c++
+	
+	char c;
+c = std::getwchar(); // Implicit cast from integer to char
+
+Check will warns for fgetwc, getwc, getwchar functions from global or 'std' namespace
+and will warn for get function from istream.
+
+.. code-block:: c++
+
+	namespace ownnamespace { ... }
+	std::istream is = ...
+	char c;
+c = is.get();   // Warning about incorrectly stored int value
+c = ownnamespace::get() // Won't warn
+	
+Check will also warns for incorrectly used functions in parameter passing.
+
+.. code-block:: c++
+	
+	void f(char c){ ...	}
+	f(std::fgetwc( ... ));  //  Warning about passed int value instead of char
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -7,9 +7,9 @@
android-cloexec-accept
android-cloexec-accept4
android-cloexec-creat
+   android-cloexec-dup
android-cloexec-epoll-create
android-cloexec-epoll-create1
-   android-cloexec-du

Re: r323485 - [Driver] Add an -fexperimental-isel driver option to enable/disable GlobalISel.

2018-01-30 Thread Hans Wennborg via cfe-commits
Merged in r323745.

On Mon, Jan 29, 2018 at 10:46 PM, Amara Emerson 
wrote:

> Hi Hans,
>
> Can we have this for the 6.0 branch? I'm also going to send a patch to add
> the release notes clang and LLVM about this flag and GISel being enabled at
> -O0.
>
> Cheers,
> Amara
>
> On 25 January 2018 at 16:27, Amara Emerson via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: aemerson
>> Date: Thu Jan 25 16:27:22 2018
>> New Revision: 323485
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=323485&view=rev
>> Log:
>> [Driver] Add an -fexperimental-isel driver option to enable/disable
>> GlobalISel.
>>
>> Differential Revision: https://reviews.llvm.org/D42276
>>
>> Added:
>> cfe/trunk/test/Driver/global-isel.c
>> Modified:
>> cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
>> cfe/trunk/include/clang/Basic/DiagnosticGroups.td
>> cfe/trunk/include/clang/Driver/Options.td
>> cfe/trunk/lib/Driver/ToolChains/Clang.cpp
>>
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>> Basic/DiagnosticDriverKinds.td?rev=323485&r1=323484&r2=323485&view=diff
>> 
>> ==
>> --- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Thu Jan 25
>> 16:27:22 2018
>> @@ -361,4 +361,12 @@ def warn_drv_fine_grained_bitfield_acces
>>  def note_drv_verify_prefix_spelling : Note<
>>"-verify prefixes must start with a letter and contain only
>> alphanumeric"
>>" characters, hyphens, and underscores">;
>> +
>> +def warn_drv_experimental_isel_incomplete : Warning<
>> +  "-fexperimental-isel support for the '%0' architecture is incomplete">,
>> +  InGroup;
>> +
>> +def warn_drv_experimental_isel_incomplete_opt : Warning<
>> +  "-fexperimental-isel support is incomplete for this architecture at
>> the current optimization level">,
>> +  InGroup;
>>  }
>>
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>> Basic/DiagnosticGroups.td?rev=323485&r1=323484&r2=323485&view=diff
>> 
>> ==
>> --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Thu Jan 25
>> 16:27:22 2018
>> @@ -985,3 +985,6 @@ def UnknownArgument : DiagGroup<"unknown
>>  // A warning group for warnings about code that clang accepts when
>>  // compiling OpenCL C/C++ but which is not compatible with the SPIR spec.
>>  def SpirCompat : DiagGroup<"spir-compat">;
>> +
>> +// Warning for the experimental-isel options.
>> +def ExperimentalISel : DiagGroup<"experimental-isel">;
>>
>> Modified: cfe/trunk/include/clang/Driver/Options.td
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>> Driver/Options.td?rev=323485&r1=323484&r2=323485&view=diff
>> 
>> ==
>> --- cfe/trunk/include/clang/Driver/Options.td (original)
>> +++ cfe/trunk/include/clang/Driver/Options.td Thu Jan 25 16:27:22 2018
>> @@ -1033,6 +1033,8 @@ def finline_functions : Flag<["-"], "fin
>>  def finline_hint_functions: Flag<["-"], "finline-hint-functions">,
>> Group, Flags<[CC1Option]>,
>>HelpText<"Inline functions which are (explicitly or implicitly) marked
>> inline">;
>>  def finline : Flag<["-"], "finline">, Group;
>> +def fexperimental_isel : Flag<["-"], "fexperimental-isel">,
>> Group,
>> +  HelpText<"Enables the experimental global instruction selector">;
>>  def fexperimental_new_pass_manager : Flag<["-"],
>> "fexperimental-new-pass-manager">,
>>Group, Flags<[CC1Option]>,
>>HelpText<"Enables an experimental new pass manager in LLVM.">;
>> @@ -1244,6 +1246,8 @@ def fno_exceptions : Flag<["-"], "fno-ex
>>  def fno_gnu_keywords : Flag<["-"], "fno-gnu-keywords">, Group,
>> Flags<[CC1Option]>;
>>  def fno_inline_functions : Flag<["-"], "fno-inline-functions">,
>> Group, Flags<[CC1Option]>;
>>  def fno_inline : Flag<["-"], "fno-inline">, Group,
>> Flags<[CC1Option]>;
>> +def fno_experimental_isel : Flag<["-"], "fno-experimental-isel">,
>> Group,
>> +  HelpText<"Disables the experimental global instruction selector">;
>>  def fno_experimental_new_pass_manager : Flag<["-"],
>> "fno-experimental-new-pass-manager">,
>>Group, Flags<[CC1Option]>,
>>HelpText<"Disables an experimental new pass manager in LLVM.">;
>>
>> Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Too
>> lChains/Clang.cpp?rev=323485&r1=323484&r2=323485&view=diff
>> 
>> ==
>> --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
>> +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Thu Jan 25 16:27:22 2018
>> @@ -469

Re: r322245 - [X86] Make -mavx512f imply -mfma and -mf16c in the frontend like it does in the backend.

2018-01-30 Thread Hans Wennborg via cfe-commits
Merged to 6.0 in r323741.

On Thu, Jan 11, 2018 at 2:37 AM, Craig Topper via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: ctopper
> Date: Wed Jan 10 17:37:59 2018
> New Revision: 322245
>
> URL: http://llvm.org/viewvc/llvm-project?rev=322245&view=rev
> Log:
> [X86] Make -mavx512f imply -mfma and -mf16c in the frontend like it does
> in the backend.
>
> Similarly, make -mno-fma and -mno-f16c imply -mno-avx512f.
>
> Withou this  "-mno-sse -mavx512f" ends up with avx512f being enabled in
> the frontend but disabled in the backend.
>
> Modified:
> cfe/trunk/lib/Basic/Targets/X86.cpp
>
> Modified: cfe/trunk/lib/Basic/Targets/X86.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/
> Targets/X86.cpp?rev=322245&r1=322244&r2=322245&view=diff
> 
> ==
> --- cfe/trunk/lib/Basic/Targets/X86.cpp (original)
> +++ cfe/trunk/lib/Basic/Targets/X86.cpp Wed Jan 10 17:37:59 2018
> @@ -430,7 +430,7 @@ void X86TargetInfo::setSSELevel(llvm::St
>if (Enabled) {
>  switch (Level) {
>  case AVX512F:
> -  Features["avx512f"] = true;
> +  Features["avx512f"] = Features["fma"] = Features["f16c"] = true;
>LLVM_FALLTHROUGH;
>  case AVX2:
>Features["avx2"] = true;
> @@ -644,6 +644,8 @@ void X86TargetInfo::setFeatureEnabledImp
>} else if (Name == "fma") {
>  if (Enabled)
>setSSELevel(Features, AVX, Enabled);
> +else
> +  setSSELevel(Features, AVX512F, Enabled);
>} else if (Name == "fma4") {
>  setXOPLevel(Features, FMA4, Enabled);
>} else if (Name == "xop") {
> @@ -653,6 +655,8 @@ void X86TargetInfo::setFeatureEnabledImp
>} else if (Name == "f16c") {
>  if (Enabled)
>setSSELevel(Features, AVX, Enabled);
> +else
> +  setSSELevel(Features, AVX512F, Enabled);
>} else if (Name == "sha") {
>  if (Enabled)
>setSSELevel(Features, SSE2, Enabled);
>
>
> ___
> 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] D42680: [ThinLTO] Ignore -fthinlto-index= for non-ThinLTO files

2018-01-30 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka created this revision.
vitalybuka added reviewers: pcc, tejohnson.
Herald added subscribers: eraman, inglorion, mehdi_amini.

Sometimes -flto=thin can produce regular LTO object files. Then backend may
receive them with -fthinlto-index= flag. Previous behavior was to report
error in this case. To avoid error build system needs to detect that
-flto=thin produced non-ThinLTO output. This can be quite complicated
and inefficient assuming that usually build system does not need to parse
object files.

As workaround we can just ignore -fthinlto-index= and fall-back to
non-ThinLTO version.


https://reviews.llvm.org/D42680

Files:
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/CodeGen/thinlto_backend.ll


Index: clang/test/CodeGen/thinlto_backend.ll
===
--- clang/test/CodeGen/thinlto_backend.ll
+++ clang/test/CodeGen/thinlto_backend.ll
@@ -20,6 +20,10 @@
 ; CHECK-OBJ-IGNORE-EMPTY: T f1
 ; CHECK-OBJ-IGNORE-EMPTY: U f2
 
+; Ensure we don't fail with index and non-ThinLTO object file, and run 
non-ThinLTO compilation which
+; RUN: opt -o %t5.o %s
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t4.o -x ir %t5.o -c 
-fthinlto-index=%t.thinlto.bc
+
 ; Ensure f2 was imported
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c 
-fthinlto-index=%t.thinlto.bc
 ; RUN: llvm-nm %t3.o | FileCheck --check-prefix=CHECK-OBJ %s
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -946,16 +946,17 @@
   });
   return {};
 };
-
 Expected BMOrErr = FindThinLTOModule(MBRef);
-if (!BMOrErr)
-  return DiagErrors(BMOrErr.takeError());
-
-Expected> MOrErr =
-BMOrErr->parseModule(*VMContext);
-if (!MOrErr)
-  return DiagErrors(MOrErr.takeError());
-return std::move(*MOrErr);
+if (BMOrErr) {
+  Expected> MOrErr =
+  BMOrErr->parseModule(*VMContext);
+  if (!MOrErr)
+return DiagErrors(MOrErr.takeError());
+  return std::move(*MOrErr);
+} else {
+  // Suppress error and fall-back to regular parsing.
+  handleAllErrors(BMOrErr.takeError(), [&](ErrorInfoBase &EIB) {});
+}
   }
 
   llvm::SMDiagnostic Err;


Index: clang/test/CodeGen/thinlto_backend.ll
===
--- clang/test/CodeGen/thinlto_backend.ll
+++ clang/test/CodeGen/thinlto_backend.ll
@@ -20,6 +20,10 @@
 ; CHECK-OBJ-IGNORE-EMPTY: T f1
 ; CHECK-OBJ-IGNORE-EMPTY: U f2
 
+; Ensure we don't fail with index and non-ThinLTO object file, and run non-ThinLTO compilation which
+; RUN: opt -o %t5.o %s
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t4.o -x ir %t5.o -c -fthinlto-index=%t.thinlto.bc
+
 ; Ensure f2 was imported
 ; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t3.o -x ir %t1.o -c -fthinlto-index=%t.thinlto.bc
 ; RUN: llvm-nm %t3.o | FileCheck --check-prefix=CHECK-OBJ %s
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -946,16 +946,17 @@
   });
   return {};
 };
-
 Expected BMOrErr = FindThinLTOModule(MBRef);
-if (!BMOrErr)
-  return DiagErrors(BMOrErr.takeError());
-
-Expected> MOrErr =
-BMOrErr->parseModule(*VMContext);
-if (!MOrErr)
-  return DiagErrors(MOrErr.takeError());
-return std::move(*MOrErr);
+if (BMOrErr) {
+  Expected> MOrErr =
+  BMOrErr->parseModule(*VMContext);
+  if (!MOrErr)
+return DiagErrors(MOrErr.takeError());
+  return std::move(*MOrErr);
+} else {
+  // Suppress error and fall-back to regular parsing.
+  handleAllErrors(BMOrErr.takeError(), [&](ErrorInfoBase &EIB) {});
+}
   }
 
   llvm::SMDiagnostic Err;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42174: [clangd] Refactored threading in ClangdServer

2018-01-30 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Can you please remove the `threading/` subdirectory?
It seems premature for these two files, and `TUScheduler` doesn't fit. It's 
unclear that there will be more.

I'd suggest renaming `Threadpool.h` -> `Threading.h`, CancellationFlag might 
fit in there, though up to you.




Comment at: clangd/threading/TUScheduler.h:1
+//===--- TUScheduler.h ---*-C++-*-===//
+//

this class needs tests



Comment at: clangd/threading/ThreadPool.h:1
+//===--- ThreadPool.h *- 
C++-*-===//
+//

this class needs tests


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42174



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


[PATCH] D42669: [clangd] Enable completion index by default, limit results to 100.

2018-01-30 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL323734: [clangd] Enable completion index by default, limit 
results to 100. (authored by sammccall, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D42669

Files:
  clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp


Index: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
@@ -87,10 +87,10 @@
 llvm::cl::init(PCHStorageFlag::Disk));
 
 static llvm::cl::opt LimitCompletionResult(
-"limit-completion",
+"completion-limit",
 llvm::cl::desc("Limit the number of completion results returned by clangd. 
"
"0 means no limit."),
-llvm::cl::init(0));
+llvm::cl::init(100));
 
 static llvm::cl::opt RunSynchronously(
 "run-synchronously",
@@ -117,9 +117,9 @@
 static llvm::cl::opt EnableIndexBasedCompletion(
 "enable-index-based-completion",
 llvm::cl::desc(
-"Enable index-based global code completion (experimental). Clangd will 
"
-"use index built from symbols in opened files"),
-llvm::cl::init(false), llvm::cl::Hidden);
+"Enable index-based global code completion. "
+"Clang uses an index built from symbols in opened files"),
+llvm::cl::init(true));
 
 static llvm::cl::opt YamlSymbolFile(
 "yaml-symbol-file",


Index: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
@@ -87,10 +87,10 @@
 llvm::cl::init(PCHStorageFlag::Disk));
 
 static llvm::cl::opt LimitCompletionResult(
-"limit-completion",
+"completion-limit",
 llvm::cl::desc("Limit the number of completion results returned by clangd. "
"0 means no limit."),
-llvm::cl::init(0));
+llvm::cl::init(100));
 
 static llvm::cl::opt RunSynchronously(
 "run-synchronously",
@@ -117,9 +117,9 @@
 static llvm::cl::opt EnableIndexBasedCompletion(
 "enable-index-based-completion",
 llvm::cl::desc(
-"Enable index-based global code completion (experimental). Clangd will "
-"use index built from symbols in opened files"),
-llvm::cl::init(false), llvm::cl::Hidden);
+"Enable index-based global code completion. "
+"Clang uses an index built from symbols in opened files"),
+llvm::cl::init(true));
 
 static llvm::cl::opt YamlSymbolFile(
 "yaml-symbol-file",
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r323734 - [clangd] Enable completion index by default, limit results to 100.

2018-01-30 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Tue Jan 30 01:21:30 2018
New Revision: 323734

URL: http://llvm.org/viewvc/llvm-project?rev=323734&view=rev
Log:
[clangd] Enable completion index by default, limit results to 100.

Summary:
This should speed up global code completion by avoiding deserializing
preamble declarations to look up names. The tradeoff is memory usage.
Currently the index is fairly naive and may not be much faster, but there's lots
of performance headroom.

These two changes go together because results from the index get copied a couple
of times, so we should avoid it for huge sets.

Also the flag should be -completion-limit, rather than -limit-completion.

Reviewers: hokein, ioeric, ilya-biryukov

Subscribers: klimek, jkorous-apple, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp

Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp?rev=323734&r1=323733&r2=323734&view=diff
==
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original)
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Tue Jan 30 01:21:30 2018
@@ -87,10 +87,10 @@ static llvm::cl::opt PCH
 llvm::cl::init(PCHStorageFlag::Disk));
 
 static llvm::cl::opt LimitCompletionResult(
-"limit-completion",
+"completion-limit",
 llvm::cl::desc("Limit the number of completion results returned by clangd. 
"
"0 means no limit."),
-llvm::cl::init(0));
+llvm::cl::init(100));
 
 static llvm::cl::opt RunSynchronously(
 "run-synchronously",
@@ -117,9 +117,9 @@ static llvm::cl::opt TraceFile(
 static llvm::cl::opt EnableIndexBasedCompletion(
 "enable-index-based-completion",
 llvm::cl::desc(
-"Enable index-based global code completion (experimental). Clangd will 
"
-"use index built from symbols in opened files"),
-llvm::cl::init(false), llvm::cl::Hidden);
+"Enable index-based global code completion. "
+"Clang uses an index built from symbols in opened files"),
+llvm::cl::init(true));
 
 static llvm::cl::opt YamlSymbolFile(
 "yaml-symbol-file",


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


[PATCH] D42669: [clangd] Enable completion index by default, limit results to 100.

2018-01-30 Thread Eric Liu via Phabricator via cfe-commits
ioeric accepted this revision.
ioeric added a comment.

Woohoo!


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42669



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


[PATCH] D42361: [Tooling] Returns non-zero status code when files are skipped.

2018-01-30 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: lib/Tooling/Tooling.cpp:404
 if (CompileCommandsForFile.empty()) {
   // FIXME: There are two use cases here: doing a fuzzy
   // "find . -name '*.cc' |xargs tool" match, where as a user I don't care

bkramer wrote:
> This comment explains why the implementation doesn't error. Can you make sure 
> the xargs use case is still working properly?
I somehow missed the big `FIXME`... thanks for the catch! 

I don't think this is a very typical use case that should affect design 
decision here, and I would expect `xargs` users to do something like `xargs 
tool $@ || true` if they really want to ignore errors. WDYT?


Repository:
  rC Clang

https://reviews.llvm.org/D42361



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


Re: [libclc] r323677 - math.h: Set HAVE_HW_FMA32 based on compiler provided macro

2018-01-30 Thread Roman Lebedev via cfe-commits
On Tue, Jan 30, 2018 at 2:38 AM, Jan Vesely  wrote:
> On Mon, 2018-01-29 at 22:15 +0300, Roman Lebedev via cfe-commits wrote:
>> On Mon, Jan 29, 2018 at 10:05 PM, Jan Vesely via cfe-commits
>>  wrote:
>> > Author: jvesely
>> > Date: Mon Jan 29 11:05:08 2018
>> > New Revision: 323677
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=323677&view=rev
>> > Log:
>> > math.h: Set HAVE_HW_FMA32 based on compiler provided macro
>> >
>> > Fixes sin/cos piglits on non-FMA capable asics.
>> > Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=35983
>> >
>> > Reviewer: Tom Stellard
>> > Signed-off-by: Jan Vesely 
>> >
>> > Modified:
>> > libclc/trunk/generic/lib/math/math.h
>> >
>> > Modified: libclc/trunk/generic/lib/math/math.h
>> > URL: 
>> > http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/math.h?rev=323677&r1=323676&r2=323677&view=diff
>> > ==
>> > --- libclc/trunk/generic/lib/math/math.h (original)
>> > +++ libclc/trunk/generic/lib/math/math.h Mon Jan 29 11:05:08 2018
>> > @@ -31,7 +31,12 @@
>> >  #define PNOR 0x100
>> >  #define PINF 0x200
>> >
>> > +#if (defined __AMDGCN__ | defined __R600__) & !defined __HAS_FMAF__
>>
>> Shouldn't that be || and && ?
>
> Yes, that would be more readable.

> It should work the same though, since the values are 0 and 1.
Yes.

>Do you want to send a patch?
No, feel free to just commit the fix :)

> Jan
>
>>
>> > +#define HAVE_HW_FMA32() (0)
>> > +#else
>> >  #define HAVE_HW_FMA32() (1)
>> > +#endif
>> > +
>> >  #define HAVE_BITALIGN() (0)
>> >  #define HAVE_FAST_FMA32() (0)
>> >
>> >
>> >
>> > ___
>> > 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
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >