[PATCH] D43510: [clangd] don't insert new includes if either original header or canonical header is already included.

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

- Merge with origin/master
- Use llvm::StringSet


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43510

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/CodeComplete.cpp
  clangd/Headers.cpp
  clangd/Headers.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  test/clangd/insert-include.test
  unittests/clangd/ClangdTests.cpp
  unittests/clangd/HeadersTests.cpp

Index: unittests/clangd/HeadersTests.cpp
===
--- unittests/clangd/HeadersTests.cpp
+++ unittests/clangd/HeadersTests.cpp
@@ -24,17 +24,28 @@
   }
 
 protected:
-  // Calculates the include path for \p Header, or returns "" on error.
-  std::string calculate(PathRef Header) {
+  // Calculates the include path, or returns "" on error.
+  std::string calculate(PathRef Original, PathRef Preferred = "",
+bool ExpectError = false) {
+if (Preferred.empty())
+  Preferred = Original;
 auto VFS = FS.getTaggedFileSystem(MainFile).Value;
 auto Cmd = CDB.getCompileCommand(MainFile);
 assert(static_cast(Cmd));
 VFS->setCurrentWorkingDirectory(Cmd->Directory);
-auto Path =
-calculateIncludePath(MainFile, FS.Files[MainFile], Header, *Cmd, VFS);
+auto ToHeaderFile = [](llvm::StringRef Header) {
+  return HeaderFile{Header,
+/*Verbatim=*/!llvm::sys::path::is_absolute(Header)};
+};
+auto Path = calculateIncludePath(MainFile, FS.Files[MainFile],
+ ToHeaderFile(Original),
+ ToHeaderFile(Preferred), *Cmd, VFS);
 if (!Path) {
   llvm::consumeError(Path.takeError());
+  EXPECT_TRUE(ExpectError);
   return std::string();
+} else {
+  EXPECT_FALSE(ExpectError);
 }
 return std::move(*Path);
   }
@@ -66,7 +77,21 @@
   FS.Files[MainFile] = R"cpp(
 #include "sub/bar.h"  // not shortest
 )cpp";
-  EXPECT_EQ(calculate(BarHeader), "");
+  EXPECT_EQ(calculate("\"sub/bar.h\""), ""); // Duplicate rewritten.
+  EXPECT_EQ(calculate(BarHeader), "");   // Duplicate resolved.
+  EXPECT_EQ(calculate(BarHeader, "\"BAR.h\""), ""); // Do not insert preferred.
+}
+
+TEST_F(HeadersTest, DontInsertDuplicatePreferred) {
+  std::string BarHeader = testPath("sub/bar.h");
+  FS.Files[BarHeader] = "";
+  FS.Files[MainFile] = R"cpp(
+#include "sub/bar.h"  // not shortest
+)cpp";
+  // Duplicate written.
+  EXPECT_EQ(calculate("\"original.h\"", "\"sub/bar.h\""), "");
+  // Duplicate resolved.
+  EXPECT_EQ(calculate("\"original.h\"", BarHeader), "");
 }
 
 TEST_F(HeadersTest, StillInsertIfTrasitivelyIncluded) {
@@ -88,6 +113,17 @@
   EXPECT_EQ(calculate(MainFile), "");
 }
 
+TEST_F(HeadersTest, PreferredHeader) {
+  FS.Files[MainFile] = "";
+  std::string BarHeader = testPath("sub/bar.h");
+  FS.Files[BarHeader] = "";
+  EXPECT_EQ(calculate(BarHeader, ""), "");
+
+  std::string BazHeader = testPath("sub/baz.h");
+  FS.Files[BazHeader] = "";
+  EXPECT_EQ(calculate(BarHeader, BazHeader), "\"baz.h\"");
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: unittests/clangd/ClangdTests.cpp
===
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -966,6 +966,8 @@
   MockFSProvider FS;
   ErrorCheckingDiagConsumer DiagConsumer;
   MockCompilationDatabase CDB;
+  std::string SearchDirArg = (llvm::Twine("-I") + testRoot()).str();
+  CDB.ExtraClangFlags.insert(CDB.ExtraClangFlags.end(), {SearchDirArg.c_str()});
   ClangdServer Server(CDB, DiagConsumer, FS,
   /*AsyncThreadsCount=*/0,
   /*StorePreamblesInMemory=*/true);
@@ -981,17 +983,30 @@
   FS.Files[FooCpp] = Code;
   Server.addDocument(FooCpp, Code);
 
-  auto Inserted = [&](llvm::StringRef Header, llvm::StringRef Expected) {
-auto Replaces = Server.insertInclude(FooCpp, Code, Header);
+  auto Inserted = [&](llvm::StringRef Original, llvm::StringRef Preferred,
+  llvm::StringRef Expected) {
+auto Replaces = Server.insertInclude(
+FooCpp, Code, Original, Preferred.empty() ? Original : Preferred);
 EXPECT_TRUE(static_cast(Replaces));
 auto Changed = tooling::applyAllReplacements(Code, *Replaces);
 EXPECT_TRUE(static_cast(Changed));
 return llvm::StringRef(*Changed).contains(
 (llvm::Twine("#include ") + Expected + "").str());
   };
 
-  EXPECT_TRUE(Inserted("\"y.h\"", "\"y.h\""));
-  EXPECT_TRUE(Inserted("", ""));
+  EXPECT_TRUE(Inserted("\"y.h\"", /*Preferred=*/"","\"y.h\""));
+  EXPECT_TRUE(Inserted("\"y.h\"", /*Preferred=*/"\"Y.h\"", "\"Y.h\""));
+  EXPECT_TRUE(Inserted("", /*Preferred=*/"", ""));
+  EXPECT_TRUE(Inserted("", /*Preferred=*/"", ""));
+
+  std::string OriginalHeader = URI::createFile(testPath("y.h")).toString

[clang-tools-extra] r326070 - [clangd] don't insert new includes if either original header or canonical header is already included.

2018-02-26 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Mon Feb 26 00:32:13 2018
New Revision: 326070

URL: http://llvm.org/viewvc/llvm-project?rev=326070&view=rev
Log:
[clangd] don't insert new includes if either original header or canonical 
header is already included.

Summary:
Changes:
o Store both the original header and the canonical header in LSP command.
o Also check that both original and canonical headers are not already included
by comparing both resolved header path and written literal includes.

This addresses the use case where private IWYU pragma is defined in a private
header while it would still be preferrable to include the private header, in the
internal implementation file. If we have seen that the priviate header is 
already
included, we don't try to insert the canonical include.

Reviewers: sammccall

Reviewed By: sammccall

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

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

Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/Headers.cpp
clang-tools-extra/trunk/clangd/Headers.h
clang-tools-extra/trunk/clangd/Protocol.cpp
clang-tools-extra/trunk/clangd/Protocol.h
clang-tools-extra/trunk/test/clangd/insert-include.test
clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=326070&r1=326069&r2=326070&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Mon Feb 26 00:32:13 2018
@@ -194,12 +194,20 @@ void ClangdLSPServer::onCommand(ExecuteC
  ExecuteCommandParams::CLANGD_INSERT_HEADER_INCLUDE +
  " called on non-added file " + FileURI.file())
 .str());
-auto Replaces = Server.insertInclude(FileURI.file(), *Code,
- Params.includeInsertion->header);
+llvm::StringRef DeclaringHeader = Params.includeInsertion->declaringHeader;
+if (DeclaringHeader.empty())
+  return replyError(
+  ErrorCode::InvalidParams,
+  "declaringHeader must be provided for include insertion.");
+llvm::StringRef PreferredHeader = Params.includeInsertion->preferredHeader;
+auto Replaces = Server.insertInclude(
+FileURI.file(), *Code, DeclaringHeader,
+PreferredHeader.empty() ? DeclaringHeader : PreferredHeader);
 if (!Replaces) {
   std::string ErrMsg =
   ("Failed to generate include insertion edits for adding " +
-   Params.includeInsertion->header + " into " + FileURI.file())
+   DeclaringHeader + " (" + PreferredHeader + ") into " +
+   FileURI.file())
   .str();
   log(ErrMsg + ":" + llvm::toString(Replaces.takeError()));
   replyError(ErrorCode::InternalError, ErrMsg);
@@ -209,7 +217,8 @@ void ClangdLSPServer::onCommand(ExecuteC
 WorkspaceEdit WE;
 WE.changes = {{FileURI.uri(), Edits}};
 
-reply("Inserted header " + Params.includeInsertion->header);
+reply(("Inserted header " + DeclaringHeader + " (" + PreferredHeader + ")")
+  .str());
 ApplyEdit(std::move(WE));
   } else {
 // We should not get here because ExecuteCommandParams would not have

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=326070&r1=326069&r2=326070&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Mon Feb 26 00:32:13 2018
@@ -313,31 +313,42 @@ void ClangdServer::rename(
   Bind(Action, File.str(), NewName.str(), std::move(Callback)));
 }
 
+/// Creates a `HeaderFile` from \p Header which can be either a URI or a 
literal
+/// include.
+static llvm::Expected toHeaderFile(StringRef Header,
+   llvm::StringRef HintPath) {
+  if (isLiteralInclude(Header))
+return HeaderFile{Header.str(), /*Verbatim=*/true};
+  auto U = URI::parse(Header);
+  if (!U)
+return U.takeError();
+  auto Resolved = URI::resolve(*U, HintPath);
+  if (!Resolved)
+return Resolved.takeError();
+  return HeaderFile{std::move(*Resolved), /*Verbatim=*/false};
+};
+
 Expected
 ClangdServer::insertInclude(PathRef File, StringRef Code,
-llvm::StringRef Header) {
+StringRef DeclaringHeader,
+StringRef In

[PATCH] D43510: [clangd] don't insert new includes if either original header or canonical header is already included.

2018-02-26 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL326070: [clangd] don't insert new includes if either 
original header or canonical… (authored by ioeric, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D43510

Files:
  clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
  clang-tools-extra/trunk/clangd/ClangdServer.cpp
  clang-tools-extra/trunk/clangd/ClangdServer.h
  clang-tools-extra/trunk/clangd/CodeComplete.cpp
  clang-tools-extra/trunk/clangd/Headers.cpp
  clang-tools-extra/trunk/clangd/Headers.h
  clang-tools-extra/trunk/clangd/Protocol.cpp
  clang-tools-extra/trunk/clangd/Protocol.h
  clang-tools-extra/trunk/test/clangd/insert-include.test
  clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
  clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp

Index: clang-tools-extra/trunk/test/clangd/insert-include.test
===
--- clang-tools-extra/trunk/test/clangd/insert-include.test
+++ clang-tools-extra/trunk/test/clangd/insert-include.test
@@ -4,10 +4,10 @@
 ---
 {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///main.cpp","languageId":"cpp","version":1,"text":"void f() {}"}}}
 ---
-{"jsonrpc":"2.0","id":3,"method":"workspace/executeCommand","params":{"arguments":[{"header":"","textDocument":{"uri":"test:///main.cpp"}}],"command":"clangd.insertInclude"}}
+{"jsonrpc":"2.0","id":3,"method":"workspace/executeCommand","params":{"arguments":[{"declaringHeader":"\"/usr/include/bits/vector\"", "preferredHeader":"","textDocument":{"uri":"test:///main.cpp"}}],"command":"clangd.insertInclude"}}
 #  CHECK:"id": 3,
 # CHECK-NEXT:"jsonrpc": "2.0",
-# CHECK-NEXT:"result": "Inserted header "
+# CHECK-NEXT:"result": "Inserted header \"/usr/include/bits/vector\" ()"
 # CHECK-NEXT:  }
 #  CHECK:"method": "workspace/applyEdit",
 # CHECK-NEXT:"params": {
Index: clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
@@ -966,6 +966,8 @@
   MockFSProvider FS;
   ErrorCheckingDiagConsumer DiagConsumer;
   MockCompilationDatabase CDB;
+  std::string SearchDirArg = (llvm::Twine("-I") + testRoot()).str();
+  CDB.ExtraClangFlags.insert(CDB.ExtraClangFlags.end(), {SearchDirArg.c_str()});
   ClangdServer Server(CDB, DiagConsumer, FS,
   /*AsyncThreadsCount=*/0,
   /*StorePreamblesInMemory=*/true);
@@ -981,17 +983,30 @@
   FS.Files[FooCpp] = Code;
   Server.addDocument(FooCpp, Code);
 
-  auto Inserted = [&](llvm::StringRef Header, llvm::StringRef Expected) {
-auto Replaces = Server.insertInclude(FooCpp, Code, Header);
+  auto Inserted = [&](llvm::StringRef Original, llvm::StringRef Preferred,
+  llvm::StringRef Expected) {
+auto Replaces = Server.insertInclude(
+FooCpp, Code, Original, Preferred.empty() ? Original : Preferred);
 EXPECT_TRUE(static_cast(Replaces));
 auto Changed = tooling::applyAllReplacements(Code, *Replaces);
 EXPECT_TRUE(static_cast(Changed));
 return llvm::StringRef(*Changed).contains(
 (llvm::Twine("#include ") + Expected + "").str());
   };
 
-  EXPECT_TRUE(Inserted("\"y.h\"", "\"y.h\""));
-  EXPECT_TRUE(Inserted("", ""));
+  EXPECT_TRUE(Inserted("\"y.h\"", /*Preferred=*/"","\"y.h\""));
+  EXPECT_TRUE(Inserted("\"y.h\"", /*Preferred=*/"\"Y.h\"", "\"Y.h\""));
+  EXPECT_TRUE(Inserted("", /*Preferred=*/"", ""));
+  EXPECT_TRUE(Inserted("", /*Preferred=*/"", ""));
+
+  std::string OriginalHeader = URI::createFile(testPath("y.h")).toString();
+  std::string PreferredHeader = URI::createFile(testPath("Y.h")).toString();
+  EXPECT_TRUE(Inserted(OriginalHeader,
+   /*Preferred=*/"", "\"y.h\""));
+  EXPECT_TRUE(Inserted(OriginalHeader,
+   /*Preferred=*/"", ""));
+  EXPECT_TRUE(Inserted(OriginalHeader, PreferredHeader, "\"Y.h\""));
+  EXPECT_TRUE(Inserted("", PreferredHeader, "\"Y.h\""));
 }
 
 } // namespace
Index: clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp
@@ -24,17 +24,28 @@
   }
 
 protected:
-  // Calculates the include path for \p Header, or returns "" on error.
-  std::string calculate(PathRef Header) {
+  // Calculates the include path, or returns "" on error.
+  std::string calculate(PathRef Original, PathRef Preferred = "",
+bool ExpectError = false) {
+if (Preferred.empty())
+  Preferred = Original;
 auto VFS = FS.getTaggedFileSystem(MainFile).Value;
 auto Cmd = CDB.getCompileCommand(MainFile);
 asser

[PATCH] D43621: [Driver] Allow using a canonical form of '-fuse-ld=' when cross-compiling on Windows.

2018-02-26 Thread Igor Kudrin via Phabricator via cfe-commits
ikudrin added a comment.

Not all toolchains call `ToolChain::GetLinkerPath`. For example, MSVC toolchain 
uses its own code:

  void visualstudio::Linker::ConstructJob(...) {
  ...
StringRef Linker = Args.getLastArgValue(options::OPT_fuse_ld_EQ, "link");
if (Linker.equals_lower("lld"))
  Linker = "lld-link";
  ...
  }

In my case, I am trying to cross-compile:

  > ...\clang.exe a.cpp -fuse-ld=lld -target i686-pc-linux-gnu
  clang.exe: error: invalid linker name in argument '-fuse-ld=lld'


Repository:
  rC Clang

https://reviews.llvm.org/D43621



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


[PATCH] D43162: [Parser] (C++) Make -Wextra-semi slightly more useful

2018-02-26 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Ping.


Repository:
  rC Clang

https://reviews.llvm.org/D43162



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


r326081 - [Support] Replace HashString with djbHash.

2018-02-26 Thread Jonas Devlieghere via cfe-commits
Author: jdevlieghere
Date: Mon Feb 26 03:30:13 2018
New Revision: 326081

URL: http://llvm.org/viewvc/llvm-project?rev=326081&view=rev
Log:
[Support] Replace HashString with djbHash.

This removes the HashString function from StringExtraces and replaces
its uses with calls to djbHash from DJB.h

This is *almost* NFC. While the algorithm is identical, the djbHash
implementation in StringExtras used 0 as its seed while the
implementation in DJB uses 5381. The latter has been shown to result in
less collisions and improved avalanching.

https://reviews.llvm.org/D43615
(cherry picked from commit 77f7f965bc9499a9ae768a296ca5a1f7347d1d2c)

Modified:
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Frontend/CacheTokens.cpp
cfe/trunk/lib/Lex/PTHLexer.cpp
cfe/trunk/lib/Serialization/ASTCommon.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=326081&r1=326080&r2=326081&view=diff
==
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Mon Feb 26 03:30:13 2018
@@ -35,9 +35,9 @@
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/ASTWriter.h"
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/CrashRecoveryContext.h"
+#include "llvm/Support/DJB.h"
 #include "llvm/Support/Host.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Mutex.h"
@@ -185,7 +185,7 @@ static std::atomic ActiveASTUn
 ASTUnit::ASTUnit(bool _MainFileIsAST)
   : Reader(nullptr), HadModuleLoaderFatalFailure(false),
 OnlyLocalDecls(false), CaptureDiagnostics(false),
-MainFileIsAST(_MainFileIsAST), 
+MainFileIsAST(_MainFileIsAST),
 TUKind(TU_Complete), WantTiming(getenv("LIBCLANG_TIMING")),
 OwnsRemappedFileBuffers(true),
 NumStoredDiagnosticsFromDriver(0),
@@ -196,7 +196,7 @@ ASTUnit::ASTUnit(bool _MainFileIsAST)
 CompletionCacheTopLevelHashValue(0),
 PreambleTopLevelHashValue(0),
 CurrentTopLevelHashValue(0),
-UnsafeToFree(false) { 
+UnsafeToFree(false) {
   if (getenv("LIBCLANG_OBJTRACKING"))
 fprintf(stderr, "+++ %u translation units\n", ++ActiveASTUnitObjects);
 }
@@ -219,8 +219,8 @@ ASTUnit::~ASTUnit() {
   delete RB.second;
   }
 
-  ClearCachedCompletionResults();  
-  
+  ClearCachedCompletionResults();
+
   if (getenv("LIBCLANG_OBJTRACKING"))
 fprintf(stderr, "--- %u translation units\n", --ActiveASTUnitObjects);
 }
@@ -229,20 +229,20 @@ void ASTUnit::setPreprocessor(std::share
   this->PP = std::move(PP);
 }
 
-/// \brief Determine the set of code-completion contexts in which this 
+/// \brief Determine the set of code-completion contexts in which this
 /// declaration should be shown.
 static unsigned getDeclShowContexts(const NamedDecl *ND,
 const LangOptions &LangOpts,
 bool &IsNestedNameSpecifier) {
   IsNestedNameSpecifier = false;
-  
+
   if (isa(ND))
 ND = dyn_cast(ND->getUnderlyingDecl());
   if (!ND)
 return 0;
-  
+
   uint64_t Contexts = 0;
-  if (isa(ND) || isa(ND) || 
+  if (isa(ND) || isa(ND) ||
   isa(ND) || isa(ND) ||
   isa(ND)) {
 // Types can appear in these contexts.
@@ -257,12 +257,12 @@ static unsigned getDeclShowContexts(cons
 // In C++, types can appear in expressions contexts (for functional casts).
 if (LangOpts.CPlusPlus)
   Contexts |= (1LL << CodeCompletionContext::CCC_Expression);
-
+
 // In Objective-C, message sends can send interfaces. In Objective-C++,
 // all types are available due to functional casts.
 if (LangOpts.CPlusPlus || isa(ND))
   Contexts |= (1LL << CodeCompletionContext::CCC_ObjCMessageReceiver);
-
+
 // In Objective-C, you can only be a subclass of another Objective-C class
 if (const auto *ID = dyn_cast(ND)) {
   // Objective-C interfaces can be used in a class property expression.
@@ -274,7 +274,7 @@ static unsigned getDeclShowContexts(cons
 // Deal with tag names.
 if (isa(ND)) {
   Contexts |= (1LL << CodeCompletionContext::CCC_EnumTag);
-  
+
   // Part of the nested-name-specifier in C++0x.
   if (LangOpts.CPlusPlus11)
 IsNestedNameSpecifier = true;
@@ -283,7 +283,7 @@ static unsigned getDeclShowContexts(cons
 Contexts |= (1LL << CodeCompletionContext::CCC_UnionTag);
   else
 Contexts |= (1LL << CodeCompletionContext::CCC_ClassOrStructTag);
-  
+
   if (LangOpts.CPlusPlus)
 IsNestedNameSpecifier = true;
 } else if (isa(ND))
@@ -300,24 +300,24 @@ static unsigned getDeclShowContexts(cons
 Contexts = (1LL << CodeCompletionContext::CCC_ObjCCategoryName);
   } else if (i

r326082 - Revert "[Support] Replace HashString with djbHash."

2018-02-26 Thread Jonas Devlieghere via cfe-commits
Author: jdevlieghere
Date: Mon Feb 26 04:05:18 2018
New Revision: 326082

URL: http://llvm.org/viewvc/llvm-project?rev=326082&view=rev
Log:
Revert "[Support] Replace HashString with djbHash."

It looks like some of our tests depend on the ordering of hashed values.
I'm reverting my changes while I try to reproduce and fix this locally.

Failing builds:

  lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/18388
  lab.llvm.org:8011/builders/clang-cmake-x86_64-sde-avx512-linux/builds/6743
  
lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/15607

Modified:
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Frontend/CacheTokens.cpp
cfe/trunk/lib/Lex/PTHLexer.cpp
cfe/trunk/lib/Serialization/ASTCommon.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=326082&r1=326081&r2=326082&view=diff
==
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Mon Feb 26 04:05:18 2018
@@ -35,9 +35,9 @@
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/ASTWriter.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/CrashRecoveryContext.h"
-#include "llvm/Support/DJB.h"
 #include "llvm/Support/Host.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Mutex.h"
@@ -185,7 +185,7 @@ static std::atomic ActiveASTUn
 ASTUnit::ASTUnit(bool _MainFileIsAST)
   : Reader(nullptr), HadModuleLoaderFatalFailure(false),
 OnlyLocalDecls(false), CaptureDiagnostics(false),
-MainFileIsAST(_MainFileIsAST),
+MainFileIsAST(_MainFileIsAST), 
 TUKind(TU_Complete), WantTiming(getenv("LIBCLANG_TIMING")),
 OwnsRemappedFileBuffers(true),
 NumStoredDiagnosticsFromDriver(0),
@@ -196,7 +196,7 @@ ASTUnit::ASTUnit(bool _MainFileIsAST)
 CompletionCacheTopLevelHashValue(0),
 PreambleTopLevelHashValue(0),
 CurrentTopLevelHashValue(0),
-UnsafeToFree(false) {
+UnsafeToFree(false) { 
   if (getenv("LIBCLANG_OBJTRACKING"))
 fprintf(stderr, "+++ %u translation units\n", ++ActiveASTUnitObjects);
 }
@@ -219,8 +219,8 @@ ASTUnit::~ASTUnit() {
   delete RB.second;
   }
 
-  ClearCachedCompletionResults();
-
+  ClearCachedCompletionResults();  
+  
   if (getenv("LIBCLANG_OBJTRACKING"))
 fprintf(stderr, "--- %u translation units\n", --ActiveASTUnitObjects);
 }
@@ -229,20 +229,20 @@ void ASTUnit::setPreprocessor(std::share
   this->PP = std::move(PP);
 }
 
-/// \brief Determine the set of code-completion contexts in which this
+/// \brief Determine the set of code-completion contexts in which this 
 /// declaration should be shown.
 static unsigned getDeclShowContexts(const NamedDecl *ND,
 const LangOptions &LangOpts,
 bool &IsNestedNameSpecifier) {
   IsNestedNameSpecifier = false;
-
+  
   if (isa(ND))
 ND = dyn_cast(ND->getUnderlyingDecl());
   if (!ND)
 return 0;
-
+  
   uint64_t Contexts = 0;
-  if (isa(ND) || isa(ND) ||
+  if (isa(ND) || isa(ND) || 
   isa(ND) || isa(ND) ||
   isa(ND)) {
 // Types can appear in these contexts.
@@ -257,12 +257,12 @@ static unsigned getDeclShowContexts(cons
 // In C++, types can appear in expressions contexts (for functional casts).
 if (LangOpts.CPlusPlus)
   Contexts |= (1LL << CodeCompletionContext::CCC_Expression);
-
+
 // In Objective-C, message sends can send interfaces. In Objective-C++,
 // all types are available due to functional casts.
 if (LangOpts.CPlusPlus || isa(ND))
   Contexts |= (1LL << CodeCompletionContext::CCC_ObjCMessageReceiver);
-
+
 // In Objective-C, you can only be a subclass of another Objective-C class
 if (const auto *ID = dyn_cast(ND)) {
   // Objective-C interfaces can be used in a class property expression.
@@ -274,7 +274,7 @@ static unsigned getDeclShowContexts(cons
 // Deal with tag names.
 if (isa(ND)) {
   Contexts |= (1LL << CodeCompletionContext::CCC_EnumTag);
-
+  
   // Part of the nested-name-specifier in C++0x.
   if (LangOpts.CPlusPlus11)
 IsNestedNameSpecifier = true;
@@ -283,7 +283,7 @@ static unsigned getDeclShowContexts(cons
 Contexts |= (1LL << CodeCompletionContext::CCC_UnionTag);
   else
 Contexts |= (1LL << CodeCompletionContext::CCC_ClassOrStructTag);
-
+  
   if (LangOpts.CPlusPlus)
 IsNestedNameSpecifier = true;
 } else if (isa(ND))
@@ -300,24 +300,24 @@ static unsigned getDeclShowContexts(cons
 Contexts = (1LL << CodeCompletionContext::CCC_ObjCCategoryName);
   } else if (isa(ND) || isa(ND)) {
 Contexts = (1LL << CodeCompl

r326083 - Explicitly initialize ForceEnableInt128 to avoid UB

2018-02-26 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon Feb 26 04:06:05 2018
New Revision: 326083

URL: http://llvm.org/viewvc/llvm-project?rev=326083&view=rev
Log:
Explicitly initialize ForceEnableInt128 to avoid UB

This fixes an uninitialized value read found by msan.

Modified:
cfe/trunk/include/clang/Basic/TargetOptions.h

Modified: cfe/trunk/include/clang/Basic/TargetOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetOptions.h?rev=326083&r1=326082&r2=326083&view=diff
==
--- cfe/trunk/include/clang/Basic/TargetOptions.h (original)
+++ cfe/trunk/include/clang/Basic/TargetOptions.h Mon Feb 26 04:06:05 2018
@@ -62,7 +62,7 @@ public:
   std::vector OpenCLExtensionsAsWritten;
 
   /// \brief If given, enables support for __int128_t and __uint128_t types.
-  bool ForceEnableInt128;
+  bool ForceEnableInt128 = false;
 };
 
 }  // end namespace clang


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


[PATCH] D43621: [Driver] Allow using a canonical form of '-fuse-ld=' when cross-compiling on Windows.

2018-02-26 Thread Igor Kudrin via Phabricator via cfe-commits
ikudrin updated this revision to Diff 135888.
ikudrin added a comment.

- Add a test.


https://reviews.llvm.org/D43621

Files:
  lib/Driver/ToolChain.cpp
  test/Driver/Inputs/fuse_ld_windows/ld.foo.exe
  test/Driver/fuse-ld-windows.c


Index: test/Driver/fuse-ld-windows.c
===
--- /dev/null
+++ test/Driver/fuse-ld-windows.c
@@ -0,0 +1,25 @@
+// REQUIRES: system-windows
+
+// We used to require adding ".exe" suffix when cross-compiling on Windows.
+// RUN: %clang %s -### -o %t.o -target i386-unknown-linux \
+// RUN: -B %S/Inputs/fuse_ld_windows -fuse-ld=foo 2>&1 \
+// RUN:   | FileCheck %s
+
+// Check that the old variant still works.
+// RUN: %clang %s -### -o %t.o -target i386-unknown-linux \
+// RUN: -B %S/Inputs/fuse_ld_windows -fuse-ld=foo.exe 2>&1 \
+// RUN:   | FileCheck %s
+
+// With the full path, the extension can be omitted, too,
+// because Windows allows that.
+// RUN: %clang %s -### -o %t.o -target i386-unknown-linux \
+// RUN: -fuse-ld=%S/Inputs/fuse_ld_windows/ld.foo 2>&1 \
+// RUN:   | FileCheck %s
+
+// Check that the full path with the extension works too.
+// RUN: %clang %s -### -o %t.o -target i386-unknown-linux \
+// RUN: -fuse-ld=%S/Inputs/fuse_ld_windows/ld.foo.exe 2>&1 \
+// RUN:   | FileCheck %s
+
+// CHECK-NOT: invalid linker name
+// CHECK: /Inputs/fuse_ld_windows{{/|}}ld.foo
Index: lib/Driver/ToolChain.cpp
===
--- lib/Driver/ToolChain.cpp
+++ lib/Driver/ToolChain.cpp
@@ -412,7 +412,7 @@
   if (llvm::sys::path::is_absolute(UseLinker)) {
 // If we're passed what looks like an absolute path, don't attempt to
 // second-guess that.
-if (llvm::sys::fs::exists(UseLinker))
+if (llvm::sys::fs::can_execute(UseLinker))
   return UseLinker;
   } else if (UseLinker.empty() || UseLinker == "ld") {
 // If we're passed -fuse-ld= with no argument, or with the argument ld,
@@ -427,7 +427,7 @@
 LinkerName.append(UseLinker);
 
 std::string LinkerPath(GetProgramPath(LinkerName.c_str()));
-if (llvm::sys::fs::exists(LinkerPath))
+if (llvm::sys::fs::can_execute(LinkerPath))
   return LinkerPath;
   }
 


Index: test/Driver/fuse-ld-windows.c
===
--- /dev/null
+++ test/Driver/fuse-ld-windows.c
@@ -0,0 +1,25 @@
+// REQUIRES: system-windows
+
+// We used to require adding ".exe" suffix when cross-compiling on Windows.
+// RUN: %clang %s -### -o %t.o -target i386-unknown-linux \
+// RUN: -B %S/Inputs/fuse_ld_windows -fuse-ld=foo 2>&1 \
+// RUN:   | FileCheck %s
+
+// Check that the old variant still works.
+// RUN: %clang %s -### -o %t.o -target i386-unknown-linux \
+// RUN: -B %S/Inputs/fuse_ld_windows -fuse-ld=foo.exe 2>&1 \
+// RUN:   | FileCheck %s
+
+// With the full path, the extension can be omitted, too,
+// because Windows allows that.
+// RUN: %clang %s -### -o %t.o -target i386-unknown-linux \
+// RUN: -fuse-ld=%S/Inputs/fuse_ld_windows/ld.foo 2>&1 \
+// RUN:   | FileCheck %s
+
+// Check that the full path with the extension works too.
+// RUN: %clang %s -### -o %t.o -target i386-unknown-linux \
+// RUN: -fuse-ld=%S/Inputs/fuse_ld_windows/ld.foo.exe 2>&1 \
+// RUN:   | FileCheck %s
+
+// CHECK-NOT: invalid linker name
+// CHECK: /Inputs/fuse_ld_windows{{/|}}ld.foo
Index: lib/Driver/ToolChain.cpp
===
--- lib/Driver/ToolChain.cpp
+++ lib/Driver/ToolChain.cpp
@@ -412,7 +412,7 @@
   if (llvm::sys::path::is_absolute(UseLinker)) {
 // If we're passed what looks like an absolute path, don't attempt to
 // second-guess that.
-if (llvm::sys::fs::exists(UseLinker))
+if (llvm::sys::fs::can_execute(UseLinker))
   return UseLinker;
   } else if (UseLinker.empty() || UseLinker == "ld") {
 // If we're passed -fuse-ld= with no argument, or with the argument ld,
@@ -427,7 +427,7 @@
 LinkerName.append(UseLinker);
 
 std::string LinkerPath(GetProgramPath(LinkerName.c_str()));
-if (llvm::sys::fs::exists(LinkerPath))
+if (llvm::sys::fs::can_execute(LinkerPath))
   return LinkerPath;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43732: Resolve build bot problems in unittests/Format/FormatTest.cpp

2018-02-26 Thread Bjorn Pettersson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC326086: Resolve build bot problems in 
unittests/Format/FormatTest.cpp (authored by bjope, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43732?vs=135794&id=135891#toc

Repository:
  rC Clang

https://reviews.llvm.org/D43732

Files:
  unittests/Format/FormatTest.cpp


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -11724,7 +11724,8 @@
 }
 
 TEST(FormatStyle, GetStyleWithEmptyFileName) {
-  auto Style1 = getStyle("file", "", "Google");
+  vfs::InMemoryFileSystem FS;
+  auto Style1 = getStyle("file", "", "Google", "", &FS);
   ASSERT_TRUE((bool)Style1);
   ASSERT_EQ(*Style1, getGoogleStyle());
 }


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -11724,7 +11724,8 @@
 }
 
 TEST(FormatStyle, GetStyleWithEmptyFileName) {
-  auto Style1 = getStyle("file", "", "Google");
+  vfs::InMemoryFileSystem FS;
+  auto Style1 = getStyle("file", "", "Google", "", &FS);
   ASSERT_TRUE((bool)Style1);
   ASSERT_EQ(*Style1, getGoogleStyle());
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43500: [clang-tidy]: modernize-use-default-member-init: Remove trailing comma and colon.

2018-02-26 Thread Jeremy Demeule via Phabricator via cfe-commits
jdemeule updated this revision to Diff 135895.
jdemeule added a comment.

As discuss, I have removed the modifications but keep the tests.
To have tests with meaning, I have also add a way to format code on 
'runCheckOnCode'.


https://reviews.llvm.org/D43500

Files:
  unittests/clang-tidy/CMakeLists.txt
  unittests/clang-tidy/ClangTidyTest.h
  unittests/clang-tidy/ModernizerModuleTest.cpp

Index: unittests/clang-tidy/ModernizerModuleTest.cpp
===
--- /dev/null
+++ unittests/clang-tidy/ModernizerModuleTest.cpp
@@ -0,0 +1,92 @@
+#include "ClangTidyTest.h"
+#include "modernize/UseDefaultMemberInitCheck.h"
+#include "gtest/gtest.h"
+
+using namespace clang::tidy::modernize;
+
+namespace clang {
+namespace tidy {
+namespace test {
+
+TEST(UseDefaultMemberInitCheckTest, NoChanges) {
+  EXPECT_NO_CHANGES(
+  UseDefaultMemberInitCheck,
+  "struct S { S() = default; bool a_ = false; bool b_ = false; };");
+  EXPECT_NO_CHANGES(UseDefaultMemberInitCheck, "struct S { S() : a_(true), "
+   "b_(true) {} bool a_{false}; "
+   "bool b_{false}; };");
+}
+
+TEST(UseDefaultMemberInitCheckTest, Basic) {
+  EXPECT_EQ("struct S {\n"
+"  S() {}\n"
+"  bool a_{false};\n"
+"};",
+runCheckAndFormatOnCode(
+"struct S { S() : a_(false) {} bool a_; };"));
+}
+
+TEST(UseDefaultMemberInitCheckTest, SeveralInitializers) {
+  EXPECT_EQ(
+  "struct S {\n"
+  "  S() {}\n"
+  "  bool a_{false};\n"
+  "  bool b_{true};\n"
+  "};",
+  runCheckAndFormatOnCode(
+  "struct S { S() : a_(false), b_(true) {} bool a_; bool b_; };"));
+}
+
+TEST(UseDefaultMemberInitCheckTest, ExceptSpec) {
+  EXPECT_EQ(
+  "struct S {\n"
+  "  S() noexcept(true) {}\n"
+  "  bool a_{false};\n"
+  "  bool b_{true};\n"
+  "};",
+  runCheckAndFormatOnCode(
+  "struct S { S() noexcept(true) : a_(false), b_(true) {} bool a_; "
+  "bool b_; };"));
+  EXPECT_EQ(
+  "#define NOEXCEPT_(X) noexcept(X)\n"
+  "struct S {\n"
+  "  S() NOEXCEPT_(true) {}\n"
+  "  bool a_{false};\n"
+  "  bool b_{true};\n"
+  "};",
+  runCheckAndFormatOnCode(
+  "#define NOEXCEPT_(X) noexcept(X)\n"
+  "struct S { S() NOEXCEPT_(true) : a_(false), b_(true) {} bool a_; "
+  "bool b_; };"));
+}
+
+TEST(UseDefaultMemberInitCheckTest, OnExisting) {
+  EXPECT_EQ("struct S {\n"
+"  S() {}\n"
+"  bool a_{false};\n"
+"  bool b_{true};\n"
+"};",
+runCheckAndFormatOnCode(
+"struct S { S() : a_(false), b_(true) {} bool a_{false}; bool "
+"b_{true}; };"));
+  EXPECT_EQ("struct S {\n"
+"  S() : a_(true) {}\n"
+"  bool a_{false};\n"
+"  bool b_{true};\n"
+"};",
+runCheckAndFormatOnCode(
+"struct S { S() : a_(true), b_(true) {} bool a_{false}; bool "
+"b_{true}; };"));
+  EXPECT_EQ("struct S {\n"
+"  S() : b_(false) {}\n"
+"  bool a_{false};\n"
+"  bool b_{true};\n"
+"};",
+runCheckAndFormatOnCode(
+"struct S { S() : a_(false), b_(false) {} bool a_{false}; bool "
+"b_{true}; };"));
+}
+
+} // namespace test
+} // namespace tidy
+} // namespace clang
Index: unittests/clang-tidy/ClangTidyTest.h
===
--- unittests/clang-tidy/ClangTidyTest.h
+++ unittests/clang-tidy/ClangTidyTest.h
@@ -13,6 +13,7 @@
 #include "ClangTidy.h"
 #include "ClangTidyDiagnosticConsumer.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Format/Format.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Tooling/Refactoring.h"
@@ -140,13 +141,60 @@
   }
   if (Errors)
 *Errors = Context.getErrors();
-  auto Result = tooling::applyAllReplacements(Code, Fixes);
-  if (!Result) {
-// FIXME: propogate the error.
-llvm::consumeError(Result.takeError());
-return "";
+
+  //   Options.
+  if (Options.FormatStyle) {
+auto Style = format::getStyle(*Options.FormatStyle,
+  Filename.getSingleStringRef(), "LLVM");
+
+llvm::Expected CleannedReplacements =
+format::cleanupAroundReplacements(Code, Fixes, *Style);
+if (!CleannedReplacements) {
+  llvm::errs() << llvm::toString(CleannedReplacements.takeError()) << "\n";
+  return "";
+}
+if (llvm::Expected FormattedReplacements =
+format::formatReplacements(Code, *CleannedReplacements, *Style)) {
+  CleannedReplacements = std::move(FormattedReplacements);
+  if (!CleannedReplacements)
+llvm_unreachable("!CleannedReplacements");
+} else {
+  llvm::errs

[PATCH] D42644: [asan] Intercept std::rethrow_exception indirectly.

2018-02-26 Thread Robert Schneider via Phabricator via cfe-commits
robot added inline comments.



Comment at: test/asan/TestCases/intercept-rethrow-exception.cc:48
+  // memcpy is intercepted by asan which performs checks on src and dst
+  using T = int[1000];
+  T x {};

vitalybuka wrote:
> You can include #include 
> and use __asan_region_is_poisoned
We don't have commit rights, can you commit it? Should we first change to 
`__asan_region_is_poisoned` and kill the program if it is indeed poisoined?


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D42644



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


r326089 - Re-commit r324991 "Fix for PR32992. Static const classes not exported."

2018-02-26 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Mon Feb 26 07:03:59 2018
New Revision: 326089

URL: http://llvm.org/viewvc/llvm-project?rev=326089&view=rev
Log:
Re-commit r324991 "Fix for PR32992. Static const classes not exported."

Fix for PR32992. Static const classes not exported.

Patch by zahiraam!

(This re-lands the commit, but using S.MarkVariableReferenced instead of
S.PendingInstantiations.push_back, and with an additional test.)

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

Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CodeGenCXX/dllexport.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=326089&r1=326088&r2=326089&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Feb 26 07:03:59 2018
@@ -5476,7 +5476,7 @@ static void CheckAbstractClassUsage(Abst
   }
 }
 
-static void ReferenceDllExportedMethods(Sema &S, CXXRecordDecl *Class) {
+static void ReferenceDllExportedMembers(Sema &S, CXXRecordDecl *Class) {
   Attr *ClassAttr = getDLLAttr(Class);
   if (!ClassAttr)
 return;
@@ -5491,6 +5491,14 @@ static void ReferenceDllExportedMethods(
 return;
 
   for (Decl *Member : Class->decls()) {
+// Defined static variables that are members of an exported base
+// class must be marked export too.
+auto *VD = dyn_cast(Member);
+if (VD && Member->getAttr() &&
+VD->getStorageClass() == SC_Static &&
+TSK == TSK_ImplicitInstantiation)
+  S.MarkVariableReferenced(VD->getLocation(), VD);
+
 auto *MD = dyn_cast(Member);
 if (!MD)
   continue;
@@ -10902,12 +10910,12 @@ void Sema::ActOnFinishCXXNonNestedClass(
 
 void Sema::referenceDLLExportedClassMethods() {
   if (!DelayedDllExportClasses.empty()) {
-// Calling ReferenceDllExportedMethods might cause the current function to
+// Calling ReferenceDllExportedMembers might cause the current function to
 // be called again, so use a local copy of DelayedDllExportClasses.
 SmallVector WorkList;
 std::swap(DelayedDllExportClasses, WorkList);
 for (CXXRecordDecl *Class : WorkList)
-  ReferenceDllExportedMethods(*this, Class);
+  ReferenceDllExportedMembers(*this, Class);
   }
 }
 

Modified: cfe/trunk/test/CodeGenCXX/dllexport.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllexport.cpp?rev=326089&r1=326088&r2=326089&view=diff
==
--- cfe/trunk/test/CodeGenCXX/dllexport.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dllexport.cpp Mon Feb 26 07:03:59 2018
@@ -29,6 +29,8 @@ struct External { int v; };
 // The vftable for struct W is comdat largest because we have RTTI.
 // M32-DAG: $"\01??_7W@@6B@" = comdat largest
 
+// M32-DAG: $"\01?smember@?$Base@H@PR32992@@0HA" = comdat any
+
 
 
//===--===//
 // Globals
@@ -94,7 +96,35 @@ inline int __declspec(dllexport) inlineS
   return x++;
 }
 
+namespace PR32992 {
+// Static data members of a instantiated base class should be exported.
+template 
+class Base {
+  virtual void myfunc() {}
+  static int smember;
+};
+// MSC-DAG: @"\01?smember@?$Base@H@PR32992@@0HA" = weak_odr dso_local 
dllexport global i32 77, comdat, align 4
+template  int Base::smember = 77;
+template 
+class __declspec(dllexport) Derived2 : Base {
+  void myfunc() {}
+};
+class Derived : public Derived2 {
+  void myfunc() {}
+};
+}  // namespace PR32992
 
+namespace PR32992_1 {
+namespace a { enum b { c }; }
+template  class d {
+   static constexpr a::b e = a::c;
+};
+namespace f {
+  template  class h : d {};
+}
+using f::h;
+class __declspec(dllexport) i : h<> {};
+}
 
 
//===--===//
 // Variable templates


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


[PATCH] D43763: libclang: Visit class template instantiations

2018-02-26 Thread Florian Jung via Phabricator via cfe-commits
Windfisch created this revision.
Windfisch added a project: clang-c.
Herald added a subscriber: cfe-commits.

Changes `clang_visitChildren()`'s behaviour to also **visit** all explicit and 
implicit **class template instantiations** upon visiting a `ClassTemplateDecl`. 
In analogy to clang++'s `-dump-ast` option, they are treated as children of the 
`ClassTemplateDecl` node.

This is done by

- adding the `CXCursor_ClassTemplateSpecialization` cursor kind,
- adding a `EnforceVisitBody` flag to 
`CursorVisitor::VisitClassTemplateSpecializationDecl`, which overrides the 
existing early exits in that method,
- and recursively descending into `theTemplateDecl->specializations()`.

This patch also adds a query function `clang_getTemplateSpecializationKind` and 
the associated enum type `CXTemplateSpecializationKind` to retrieve the 
specialisation kind. That way, users can distinguish between implicit 
instantiations (which they probably want to visit as child of the 
ClassTemplateDecl) and explicit instantiation (which they may want choose to 
ignore, because their node will reappear at the very location where the 
explicit instantiation takes place).


Repository:
  rC Clang

https://reviews.llvm.org/D43763

Files:
  include/clang-c/Index.h
  lib/Sema/SemaCodeComplete.cpp
  tools/libclang/CIndex.cpp
  tools/libclang/CIndexCXX.cpp
  tools/libclang/CursorVisitor.h
  tools/libclang/libclang.exports

Index: tools/libclang/libclang.exports
===
--- tools/libclang/libclang.exports
+++ tools/libclang/libclang.exports
@@ -259,6 +259,7 @@
 clang_getSpellingLocation
 clang_getTUResourceUsageName
 clang_getTemplateCursorKind
+clang_getTemplateSpecializationKind
 clang_getTokenExtent
 clang_getTokenKind
 clang_getTokenLocation
Index: tools/libclang/CIndexCXX.cpp
===
--- tools/libclang/CIndexCXX.cpp
+++ tools/libclang/CIndexCXX.cpp
@@ -80,6 +80,25 @@
   return CXCursor_NoDeclFound;
 }
 
+enum CXTemplateSpecializationKind clang_getTemplateSpecializationKind(CXCursor C) {
+  using namespace clang::cxcursor;
+  
+  if (C.kind == CXCursor_ClassTemplateSpecialization)
+  {
+switch (static_cast(getCursorDecl(C))->getSpecializationKind())
+{
+  #define TRANSL(val) case val: return CX##val;
+  TRANSL(TSK_Undeclared)
+  TRANSL(TSK_ImplicitInstantiation)
+  TRANSL(TSK_ExplicitSpecialization)
+  TRANSL(TSK_ExplicitInstantiationDeclaration)
+  TRANSL(TSK_ExplicitInstantiationDefinition)
+  #undef TRANSL
+}
+  }
+  return CXTSK_Undeclared;
+}
+
 CXCursor clang_getSpecializedCursorTemplate(CXCursor C) {
   if (!clang_isDeclaration(C.kind))
 return clang_getNullCursor();
Index: tools/libclang/CursorVisitor.h
===
--- tools/libclang/CursorVisitor.h
+++ tools/libclang/CursorVisitor.h
@@ -205,7 +205,7 @@
   bool VisitTranslationUnitDecl(TranslationUnitDecl *D);
   bool VisitTypedefDecl(TypedefDecl *D);
   bool VisitTagDecl(TagDecl *D);
-  bool VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D);
+  bool VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D, bool EnforceVisitBody = false);
   bool VisitClassTemplatePartialSpecializationDecl(
  ClassTemplatePartialSpecializationDecl *D);
   bool VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -498,7 +498,13 @@
 if (!D)
   return false;
 
-return VisitAttributes(D) || Visit(D);
+if (VisitAttributes(D))
+  return true;
+
+if (Cursor.kind == CXCursor_ClassTemplateSpecialization)
+  return VisitClassTemplateSpecializationDecl(static_cast(D), /*EnforceVisitBody*/ true);
+else
+  return Visit(D);
   }
 
   if (clang_isStatement(Cursor.kind)) {
@@ -701,22 +707,23 @@
 }
 
 bool CursorVisitor::VisitClassTemplateSpecializationDecl(
-  ClassTemplateSpecializationDecl *D) {
-  bool ShouldVisitBody = false;
-  switch (D->getSpecializationKind()) {
-  case TSK_Undeclared:
-  case TSK_ImplicitInstantiation:
-// Nothing to visit
-return false;
-  
-  case TSK_ExplicitInstantiationDeclaration:
-  case TSK_ExplicitInstantiationDefinition:
-break;
-  
-  case TSK_ExplicitSpecialization:
-ShouldVisitBody = true;
-break;
-  }
+  ClassTemplateSpecializationDecl *D, bool EnforceVisitBody) {
+  bool ShouldVisitBody = EnforceVisitBody;
+  if (!EnforceVisitBody)
+switch (D->getSpecializationKind()) {
+case TSK_Undeclared:
+case TSK_ImplicitInstantiation:
+  // Nothing to visit
+  return false;
+
+case TSK_ExplicitInstantiationDeclaration:
+case TSK_ExplicitInstantiationDef

r326091 - Re-land: "[Support] Replace HashString with djbHash."

2018-02-26 Thread Jonas Devlieghere via cfe-commits
Author: jdevlieghere
Date: Mon Feb 26 07:16:42 2018
New Revision: 326091

URL: http://llvm.org/viewvc/llvm-project?rev=326091&view=rev
Log:
Re-land: "[Support] Replace HashString with djbHash."

This patch removes the HashString function from StringExtraces and
replaces its uses with calls to djbHash from DJB.h.

This change is *almost* NFC. While the algorithm is identical, the
djbHash implementation in StringExtras used 0 as its default seed while
the implementation in DJB uses 5381. The latter has been shown to result
in less collisions and improved avalanching and is used by the DWARF
accelerator tables.

Because some test were implicitly relying on the hash order, I've
reverted to using zero as a seed for the following two files:

  lld/include/lld/Core/SymbolTable.h
  llvm/lib/Support/StringMap.cpp

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

Modified:
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Frontend/CacheTokens.cpp
cfe/trunk/lib/Lex/PTHLexer.cpp
cfe/trunk/lib/Serialization/ASTCommon.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=326091&r1=326090&r2=326091&view=diff
==
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Mon Feb 26 07:16:42 2018
@@ -35,9 +35,9 @@
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/ASTWriter.h"
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/CrashRecoveryContext.h"
+#include "llvm/Support/DJB.h"
 #include "llvm/Support/Host.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Mutex.h"
@@ -185,7 +185,7 @@ static std::atomic ActiveASTUn
 ASTUnit::ASTUnit(bool _MainFileIsAST)
   : Reader(nullptr), HadModuleLoaderFatalFailure(false),
 OnlyLocalDecls(false), CaptureDiagnostics(false),
-MainFileIsAST(_MainFileIsAST), 
+MainFileIsAST(_MainFileIsAST),
 TUKind(TU_Complete), WantTiming(getenv("LIBCLANG_TIMING")),
 OwnsRemappedFileBuffers(true),
 NumStoredDiagnosticsFromDriver(0),
@@ -196,7 +196,7 @@ ASTUnit::ASTUnit(bool _MainFileIsAST)
 CompletionCacheTopLevelHashValue(0),
 PreambleTopLevelHashValue(0),
 CurrentTopLevelHashValue(0),
-UnsafeToFree(false) { 
+UnsafeToFree(false) {
   if (getenv("LIBCLANG_OBJTRACKING"))
 fprintf(stderr, "+++ %u translation units\n", ++ActiveASTUnitObjects);
 }
@@ -219,8 +219,8 @@ ASTUnit::~ASTUnit() {
   delete RB.second;
   }
 
-  ClearCachedCompletionResults();  
-  
+  ClearCachedCompletionResults();
+
   if (getenv("LIBCLANG_OBJTRACKING"))
 fprintf(stderr, "--- %u translation units\n", --ActiveASTUnitObjects);
 }
@@ -229,20 +229,20 @@ void ASTUnit::setPreprocessor(std::share
   this->PP = std::move(PP);
 }
 
-/// \brief Determine the set of code-completion contexts in which this 
+/// \brief Determine the set of code-completion contexts in which this
 /// declaration should be shown.
 static unsigned getDeclShowContexts(const NamedDecl *ND,
 const LangOptions &LangOpts,
 bool &IsNestedNameSpecifier) {
   IsNestedNameSpecifier = false;
-  
+
   if (isa(ND))
 ND = dyn_cast(ND->getUnderlyingDecl());
   if (!ND)
 return 0;
-  
+
   uint64_t Contexts = 0;
-  if (isa(ND) || isa(ND) || 
+  if (isa(ND) || isa(ND) ||
   isa(ND) || isa(ND) ||
   isa(ND)) {
 // Types can appear in these contexts.
@@ -257,12 +257,12 @@ static unsigned getDeclShowContexts(cons
 // In C++, types can appear in expressions contexts (for functional casts).
 if (LangOpts.CPlusPlus)
   Contexts |= (1LL << CodeCompletionContext::CCC_Expression);
-
+
 // In Objective-C, message sends can send interfaces. In Objective-C++,
 // all types are available due to functional casts.
 if (LangOpts.CPlusPlus || isa(ND))
   Contexts |= (1LL << CodeCompletionContext::CCC_ObjCMessageReceiver);
-
+
 // In Objective-C, you can only be a subclass of another Objective-C class
 if (const auto *ID = dyn_cast(ND)) {
   // Objective-C interfaces can be used in a class property expression.
@@ -274,7 +274,7 @@ static unsigned getDeclShowContexts(cons
 // Deal with tag names.
 if (isa(ND)) {
   Contexts |= (1LL << CodeCompletionContext::CCC_EnumTag);
-  
+
   // Part of the nested-name-specifier in C++0x.
   if (LangOpts.CPlusPlus11)
 IsNestedNameSpecifier = true;
@@ -283,7 +283,7 @@ static unsigned getDeclShowContexts(cons
 Contexts |= (1LL << CodeCompletionContext::CCC_UnionTag);
   else
 Contexts |= (1LL << CodeCompletionContext::CCC_ClassOrStructTag);
-  
+
   if (L

[PATCH] D43281: [AMDGPU] fixes for lds f32 builtins

2018-02-26 Thread Daniil Fukalov via Phabricator via cfe-commits
dfukalov added a comment.

In https://reviews.llvm.org/D43281#1018657, @arsenm wrote:

> Can’t you just change the description to be the LangAS value? I also thought 
> these happened to be the same already


Am I right that you mean to change the semantic of the addrspace number in a 
description string for all targets?

At the moment it's finally checked in `ASTContext::getAddrSpaceQualType` that 
`LangAS` is equal addrspace returned by `QualType`.
And for addrspace "2" specified in description, this `QualType` is 
"__attribute__((address_space(3))) float". And returns "11" since it's target 
addrspace, defined in `LangAS` after `FirstTargetAddressSpace`.
So `ASTContext::getAddrSpaceQualType` goes through check 
`CanT.getAddressSpace() == AddressSpace` and then hits assertions that the 
parameter already has addrspace specified.


https://reviews.llvm.org/D43281



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


[PATCH] D43648: [clangd] Debounce streams of updates.

2018-02-26 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/TUScheduler.h:56
+  std::chrono::steady_clock::duration UpdateDebounce =
+  std::chrono::milliseconds(500));
   ~TUScheduler();

Maybe we could remove this default argument now that `ClangdServer` also has 
the default debounce?
I guess the key thing that bothers me is having multiple places that have the 
magical default constant of `500ms`, it would be nice to have it in one place.



Comment at: clangd/Threading.h:76
+private:
+  enum Type { Zero, Infinite, Finite } Type;
+  Deadline(enum Type Type) : Type(Type) {}

Maybe prefer grouping all the fields together? It seems we're giving that up to 
avoid writing one extra instance of `enum Type`.

```
  enum Type { Zero, Infinite, Finite };
  Deadline(enum Type Type) : Type(Type) {}

  enum Type Type;
  std::chrono::steady_clock::time_point Time;
```



Comment at: clangd/Threading.h:83
 Deadline timeoutSeconds(llvm::Optional Seconds);
+/// Wait once for on CV for the specified duration.
+void wait(std::unique_lock &Lock, std::condition_variable &CV,

s/Wait for on/Wait on/?



Comment at: unittests/clangd/TUSchedulerTests.cpp:127
+  /*ASTParsedCallback=*/nullptr,
+  /*UpdateDebounce=*/std::chrono::milliseconds(50));
+auto Path = testPath("foo.cpp");

I wonder if the default debounce of `500ms` will make other tests (especially 
those that use `ClangdServer`) too slow?
Maybe we should consider settings a smaller default (maybe even 
`Deadline::zero()`?) and having `500ms` set only by `ClangdLSPServer`?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43648



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


[PATCH] D43764: [clang-apply-replacements] Convert tooling::Replacements to tooling::AtomicChange for conflict resolving of changes, code cleanup, and code formatting.

2018-02-26 Thread Jeremy Demeule via Phabricator via cfe-commits
jdemeule created this revision.
jdemeule added reviewers: klimek, ioeric.
Herald added subscribers: cfe-commits, mgorny.

By converting Replacements by AtomicChange, clang-apply-replacements is able 
like clang-tidy to automatically cleanup and format changes.
This should permits to close this ticket: 
https://bugs.llvm.org/show_bug.cgi?id=35051 and attempt to follow hints from 
https://reviews.llvm.org/D43500 comments.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43764

Files:
  
clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h
  clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
  clang-apply-replacements/tool/CMakeLists.txt
  clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
  test/clang-apply-replacements/Inputs/conflict/expected.txt
  unittests/clang-apply-replacements/ApplyReplacementsTest.cpp
  unittests/clang-apply-replacements/CMakeLists.txt
  unittests/clang-apply-replacements/ReformattingTest.cpp

Index: unittests/clang-apply-replacements/ReformattingTest.cpp
===
--- unittests/clang-apply-replacements/ReformattingTest.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-//===- clang-apply-replacements/ReformattingTest.cpp --===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-
-#include "clang-apply-replacements/Tooling/ApplyReplacements.h"
-#include "common/VirtualFileHelper.h"
-#include "clang/Format/Format.h"
-#include "clang/Tooling/Refactoring.h"
-#include "gtest/gtest.h"
-
-using namespace clang;
-using namespace clang::tooling;
-using namespace clang::replace;
-
-typedef std::vector ReplacementsVec;
-
-static Replacement makeReplacement(unsigned Offset, unsigned Length,
-   unsigned ReplacementLength,
-   llvm::StringRef FilePath = "") {
-  return Replacement(FilePath, Offset, Length,
- std::string(ReplacementLength, '~'));
-}
-
-// generate a set of replacements containing one element
-static ReplacementsVec makeReplacements(unsigned Offset, unsigned Length,
-unsigned ReplacementLength,
-llvm::StringRef FilePath = "~") {
-  ReplacementsVec Replaces;
-  Replaces.push_back(
-  makeReplacement(Offset, Length, ReplacementLength, FilePath));
-  return Replaces;
-}
-
-// Put these functions in the clang::tooling namespace so arg-dependent name
-// lookup finds these functions for the EXPECT_EQ macros below.
-namespace clang {
-namespace tooling {
-
-std::ostream &operator<<(std::ostream &os, const Range &R) {
-  return os << "Range(" << R.getOffset() << ", " << R.getLength() << ")";
-}
-
-} // namespace tooling
-} // namespace clang
-
-// Ensure zero-length ranges are produced. Even lines where things are deleted
-// need reformatting.
-TEST(CalculateChangedRangesTest, producesZeroLengthRange) {
-  RangeVector Changes = calculateChangedRanges(makeReplacements(0, 4, 0));
-  EXPECT_EQ(Range(0, 0), Changes.front());
-}
-
-// Basic test to ensure replacements turn into ranges properly.
-TEST(CalculateChangedRangesTest, calculatesRanges) {
-  ReplacementsVec R;
-  R.push_back(makeReplacement(2, 0, 3));
-  R.push_back(makeReplacement(5, 2, 4));
-  RangeVector Changes = calculateChangedRanges(R);
-
-  Range ExpectedRanges[] = { Range(2, 3), Range(8, 4) };
-  EXPECT_TRUE(std::equal(Changes.begin(), Changes.end(), ExpectedRanges));
-}
Index: unittests/clang-apply-replacements/CMakeLists.txt
===
--- unittests/clang-apply-replacements/CMakeLists.txt
+++ unittests/clang-apply-replacements/CMakeLists.txt
@@ -9,12 +9,12 @@
 
 add_extra_unittest(ClangApplyReplacementsTests
   ApplyReplacementsTest.cpp
-  ReformattingTest.cpp
   )
 
 target_link_libraries(ClangApplyReplacementsTests
   PRIVATE
   clangApplyReplacements
   clangBasic
   clangToolingCore
+  clangToolingRefactor
   )
Index: unittests/clang-apply-replacements/ApplyReplacementsTest.cpp
===
--- unittests/clang-apply-replacements/ApplyReplacementsTest.cpp
+++ unittests/clang-apply-replacements/ApplyReplacementsTest.cpp
@@ -41,11 +41,12 @@
   IntrusiveRefCntPtr(new DiagnosticIDs()), DiagOpts.get());
   FileManager Files((FileSystemOptions()));
   SourceManager SM(Diagnostics, Files);
+  TUReplacements TURs;
   TUDiagnostics TUs =
   makeTUDiagnostics("path/to/source.cpp", "diagnostic", {}, {}, "path/to");
-  FileToReplacementsMap ReplacementsMap;
+  FileToChangeMap ReplacementsMap;
 
-  EXPECT_TRUE(mergeAndDeduplicate(TUs, ReplacementsMap, SM));
+  EXPECT_TRUE(mergeAndDeduplicate(TURs, TUs, Rep

[PATCH] D43585: [libunwind] Permit additional compiler flags to be passed to tests.

2018-02-26 Thread Simon Dardis via Phabricator via cfe-commits
sdardis accepted this revision.
sdardis added a comment.
This revision is now accepted and ready to land.

In https://reviews.llvm.org/D43585#1017957, @bsdjhb wrote:

> My only question is if this should be named LIBUNWIND_TEST_COMPILER_FLAGS to 
> match the name used in libc++?


I would say yes for the sake of consistency with the option it's controls and 
libcxx. Additionally, we also require config.test_linker_flags to be set as 
well, so we need LIBUNWIND_LINKER_FLAGS.

LGTM with those two additional changes. I've tested it with your N32 patch and 
it works.


Repository:
  rUNW libunwind

https://reviews.llvm.org/D43585



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


[PATCH] D39074: [libunwind][MIPS]: Add support for unwinding in N32 processes.

2018-02-26 Thread Simon Dardis via Phabricator via cfe-commits
sdardis accepted this revision.
sdardis added a comment.
This revision is now accepted and ready to land.
Herald added a subscriber: christof.

LGTM after  https://reviews.llvm.org/D43585 lands.


Repository:
  rUNW libunwind

https://reviews.llvm.org/D39074



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


[PATCH] D41880: Adding nocf_check attribute for cf-protection fine tuning

2018-02-26 Thread Oren Ben Simhon via Phabricator via cfe-commits
oren_ben_simhon marked 7 inline comments as done.
oren_ben_simhon added inline comments.



Comment at: include/clang/CodeGen/CGFunctionInfo.h:519
+  /// Whether this function has nocf_check attribute.
+  unsigned NoCfCheck : 1;
+

aaron.ballman wrote:
> This is unfortunate -- it bumps the bit-field over 32 bits. Can the bit be 
> stolen from elsewhere?
The field is orthogonal to the other fields moreover i think that double 
meaning of the same field will lead to future bugs. The class is not a compact 
packed structure, so i don't feel it worth the confusion.



Comment at: lib/Sema/SemaDeclAttr.cpp:1979-1980
+static void handleNoCfCheckAttr(Sema &S, Decl *D, const AttributeList &Attrs) {
+  if (!S.getLangOpts().CFProtectionBranch)
+S.Diag(Attrs.getLoc(), diag::warn_nocf_check_attribute_ignored);
+  else

aaron.ballman wrote:
> Can you use the `LangOpts` field to specify this in Attr.td? Then you can go 
> back to the simple handler.
When using LangOpts field in Attr.td, the diagnostic warning will not be 
descriptive as i use here (use -fcf-protection flag...).



Comment at: test/Sema/attr-nocf_check.cpp:1
+// RUN: %clang_cc1 -verify -fcf-protection=branch -target-feature +ibt 
-fsyntax-only %s
+

aaron.ballman wrote:
> aaron.ballman wrote:
> > For better test coverage, you can switch to the `[[gnu::nocf_check]]` 
> > spelling in this file and pass `-std=c++11`
> This one also likely needs an explicit triple.
Since it doesn't test the functionality of this specific attribute, I believe 
it is an overkill to switch to [[gnu::nocf_check]] spelling.


Repository:
  rL LLVM

https://reviews.llvm.org/D41880



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


[PATCH] D41880: Adding nocf_check attribute for cf-protection fine tuning

2018-02-26 Thread Oren Ben Simhon via Phabricator via cfe-commits
oren_ben_simhon updated this revision to Diff 135908.
oren_ben_simhon added a comment.

Implemented comments posted until 02/26 (Thanks Aaron)


Repository:
  rL LLVM

https://reviews.llvm.org/D41880

Files:
  include/clang/AST/Type.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/LangOptions.def
  include/clang/CodeGen/CGFunctionInfo.h
  include/clang/Sema/Sema.h
  lib/AST/ASTContext.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/CodeGen/CGCall.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp
  test/CodeGen/attributes.c
  test/CodeGen/cetintrin.c
  test/CodeGen/x86-cf-protection.c
  test/Misc/pragma-attribute-supported-attributes-list.test
  test/Sema/attr-nocf_check.c
  test/Sema/attr-nocf_check.cpp
  test/Sema/nocf_check_attr_not_allowed.c

Index: test/Sema/nocf_check_attr_not_allowed.c
===
--- /dev/null
+++ test/Sema/nocf_check_attr_not_allowed.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple powerpc-unknown-linux-gnu -fsyntax-only -verify -fcf-protection=branch %s
+// RUN: %clang_cc1 -triple arm-unknown-linux-gnu -fsyntax-only -verify -fcf-protection=branch %s
+
+void __attribute__((nocf_check)) foo(); // expected-warning {{unknown attribute 'nocf_check' ignored}}
Index: test/Sema/attr-nocf_check.cpp
===
--- /dev/null
+++ test/Sema/attr-nocf_check.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple=i386-unknown-unknown -verify -fcf-protection=branch -target-feature +ibt -std=c++11 -fsyntax-only %s
+
+// Function pointer definition.
+typedef void (*FuncPointerWithNoCfCheck)(void) __attribute__((nocf_check)); // no-warning
+typedef void (*FuncPointer)(void);
+
+// Dont allow function declaration and definition mismatch.
+void __attribute__((nocf_check)) testNoCfCheck();   // expected-note {{previous declaration is here}}
+void testNoCfCheck(){}; //  expected-error {{conflicting types for 'testNoCfCheck'}}
+
+// No variable or parameter declaration
+__attribute__((nocf_check)) int i;  // expected-warning {{'nocf_check' attribute only applies to function}}
+void testNoCfCheckImpl(double __attribute__((nocf_check)) i) {} // expected-warning {{'nocf_check' attribute only applies to function}}
+
+// Allow attributed function pointers as well as casting between attributed
+// and non-attributed function pointers.
+void testNoCfCheckMismatch(FuncPointer f) {
+  FuncPointerWithNoCfCheck fNoCfCheck = f; // expected-error {{cannot initialize a variable of type 'FuncPointerWithNoCfCheck'}}
+  (*fNoCfCheck)(); // no-warning
+}
+
+// 'nocf_check' Attribute has no parameters.
+int testNoCfCheckParams() __attribute__((nocf_check(1))); // expected-error {{'nocf_check' attribute takes no arguments}}
Index: test/Sema/attr-nocf_check.c
===
--- /dev/null
+++ test/Sema/attr-nocf_check.c
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -verify -fcf-protection=branch -target-feature +ibt -fsyntax-only %s
+
+// Function pointer definition.
+typedef void (*FuncPointerWithNoCfCheck)(void) __attribute__((nocf_check)); // no-warning
+typedef void (*FuncPointer)(void);
+
+// Dont allow function declaration and definition mismatch.
+void __attribute__((nocf_check)) testNoCfCheck();   // expected-note {{previous declaration is here}}
+void testNoCfCheck(){}; //  expected-error {{conflicting types for 'testNoCfCheck'}}
+
+// No variable or parameter declaration
+__attribute__((nocf_check)) int i;  // expected-warning {{'nocf_check' attribute only applies to function}}
+void testNoCfCheckImpl(double __attribute__((nocf_check)) i) {} // expected-warning {{'nocf_check' attribute only applies to function}}
+
+// Allow attributed function pointers as well as casting between attributed
+// and non-attributed function pointers.
+void testNoCfCheckMismatch(FuncPointer f) {
+  FuncPointerWithNoCfCheck fNoCfCheck = f; // expected-warning {{incompatible function pointer types}}
+  (*fNoCfCheck)(); // no-warning
+}
+
+// 'nocf_check' Attribute has no parameters.
+int testNoCfCheckParams() __attribute__((nocf_check(1))); // expected-error {{'nocf_check' attribute takes no arguments}}
Index: test/Misc/pragma-attribute-supported-attributes-list.test
===
--- test/Misc/pragma-attribute-supported-attributes-list.test
+++ test/Misc/pragma-attribute-supported-attributes-list.test
@@ -2,7 +2,7 @@
 
 // The number of supported attributes should never go down!
 
-// CHECK: #pragma clang attribute supports 66 attributes:
+// CHECK: #pragma clang attribute supports 67 attributes:
 // CHECK-NE

[PATCH] D42766: [DebugInfo] Support DWARFv5 source code embedding extension

2018-02-26 Thread Scott Linder via Phabricator via cfe-commits
scott.linder updated this revision to Diff 135909.
scott.linder added a comment.

New diff addresses feedback. I committed the refactoring as NFC and rebased, 
then clarified the extension comment.


https://reviews.llvm.org/D42766

Files:
  docs/ClangCommandLineReference.rst
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  lib/Driver/ToolChains/AMDGPU.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/Inputs/debug-info-embed-source.c
  test/CodeGen/debug-info-embed-source.c
  test/Driver/amdgpu-toolchain.c
  test/Driver/debug-options.c

Index: test/Driver/debug-options.c
===
--- test/Driver/debug-options.c
+++ test/Driver/debug-options.c
@@ -245,3 +245,13 @@
 // RUN: %clang -###  %s 2>&1 | FileCheck -check-prefix=NOMACRO %s
 // MACRO: "-debug-info-macro"
 // NOMACRO-NOT: "-debug-info-macro"
+//
+// RUN: %clang -### -gdwarf-5 -gembed-source %s 2>&1 | FileCheck -check-prefix=GEMBED_5 %s
+// RUN: %clang -### -gdwarf-2 -gembed-source %s 2>&1 | FileCheck -check-prefix=GEMBED_2 %s
+// RUN: %clang -### -gdwarf-5 -gno-embed-source %s 2>&1 | FileCheck -check-prefix=NOGEMBED_5 %s
+// RUN: %clang -### -gdwarf-2 -gno-embed-source %s 2>&1 | FileCheck -check-prefix=NOGEMBED_2 %s
+//
+// GEMBED_5:  "-gembed-source"
+// GEMBED_2:  error: invalid argument '-gembed-source' only allowed with '-gdwarf-5'
+// NOGEMBED_5-NOT:  "-gembed-source"
+// NOGEMBED_2-NOT:  error: invalid argument '-gembed-source' only allowed with '-gdwarf-5'
Index: test/Driver/amdgpu-toolchain.c
===
--- test/Driver/amdgpu-toolchain.c
+++ test/Driver/amdgpu-toolchain.c
@@ -3,4 +3,4 @@
 // AS_LINK: ld.lld{{.*}} "-shared"
 
 // RUN: %clang -### -g -target amdgcn--amdhsa -mcpu=kaveri %s 2>&1 | FileCheck -check-prefix=DWARF_VER %s
-// DWARF_VER: "-dwarf-version=2"
+// DWARF_VER: "-dwarf-version=5"
Index: test/CodeGen/debug-info-embed-source.c
===
--- /dev/null
+++ test/CodeGen/debug-info-embed-source.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1-debug-info-kind=limited -emit-llvm %p/Inputs/debug-info-embed-source.c -o - | FileCheck %s --check-prefix=NOEMBED
+// RUN: %clang_cc1 -gembed-source -debug-info-kind=limited -emit-llvm %p/Inputs/debug-info-embed-source.c -o - | FileCheck %s --check-prefix=EMBED
+
+// NOEMBED-NOT: !DIFile({{.*}}source:
+// EMBED: !DIFile({{.*}}source: "void foo() { }\0A"
Index: test/CodeGen/Inputs/debug-info-embed-source.c
===
--- /dev/null
+++ test/CodeGen/Inputs/debug-info-embed-source.c
@@ -0,0 +1 @@
+void foo() { }
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -545,6 +545,7 @@
   Opts.DebugTypeExtRefs = Args.hasArg(OPT_dwarf_ext_refs);
   Opts.DebugExplicitImport = Args.hasArg(OPT_dwarf_explicit_import);
   Opts.DebugFwdTemplateParams = Args.hasArg(OPT_debug_forward_template_params);
+  Opts.EmbedSource = Args.hasArg(OPT_gembed_source);
 
   for (const auto &Arg : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ))
 Opts.DebugPrefixMap.insert(StringRef(Arg).split('='));
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3024,6 +3024,18 @@
   if (DebugInfoKind == codegenoptions::LimitedDebugInfo && NeedFullDebug)
 DebugInfoKind = codegenoptions::FullDebugInfo;
 
+  if (Args.hasFlag(options::OPT_gembed_source, options::OPT_gno_embed_source, false)) {
+// Source embedding is a vendor extension to DWARF v5. By now we have
+// checked if a DWARF version was stated explicitly, and have otherwise
+// fallen back to the target default, so if this is still not at least 5 we
+// emit an error.
+if (DWARFVersion < 5)
+  D.Diag(diag::err_drv_argument_only_allowed_with)
+  << Args.getLastArg(options::OPT_gembed_source)->getAsString(Args)
+  << "-gdwarf-5";
+CmdArgs.push_back("-gembed-source");
+  }
+
   RenderDebugEnablingArgs(Args, CmdArgs, DebugInfoKind, DWARFVersion,
   DebuggerTuning);
 
Index: lib/Driver/ToolChains/AMDGPU.h
===
--- lib/Driver/ToolChains/AMDGPU.h
+++ lib/Driver/ToolChains/AMDGPU.h
@@ -56,7 +56,7 @@
 public:
   AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
   const llvm::opt::ArgList &Args);
-  unsigned GetDefaultDwarfVersion() const override { return 2; }
+  unsigned GetDefaultDwarfVersion() const override { return 5; }
   bool IsIntegratedAssemblerDefault() const override { return t

r326086 - Resolve build bot problems in unittests/Format/FormatTest.cpp

2018-02-26 Thread Bjorn Pettersson via cfe-commits
Author: bjope
Date: Mon Feb 26 06:14:11 2018
New Revision: 326086

URL: http://llvm.org/viewvc/llvm-project?rev=326086&view=rev
Log:
Resolve build bot problems in unittests/Format/FormatTest.cpp

Summary:
Make the new GetStyleWithEmptyFileName test case independent
of the file system used when running the test. Since the
test is supposed to use the fallback "Google" style we now
use a InMemoryFileSystem to make sure that we do not accidentaly
find a .clang-format file in the real file system. That could
for example happen when having the build directory inside the
llvm och clang repo (as there is a .clang-format file inside
the repos).

Reviewers: vsapsai, jolesiak, krasimir, benhamilton

Reviewed By: krasimir

Subscribers: uabelho, twoh, klimek, cfe-commits

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

Modified:
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=326086&r1=326085&r2=326086&view=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Feb 26 06:14:11 2018
@@ -11724,7 +11724,8 @@ TEST_F(FormatTest, NoSpaceAfterSuper) {
 }
 
 TEST(FormatStyle, GetStyleWithEmptyFileName) {
-  auto Style1 = getStyle("file", "", "Google");
+  vfs::InMemoryFileSystem FS;
+  auto Style1 = getStyle("file", "", "Google", "", &FS);
   ASSERT_TRUE((bool)Style1);
   ASSERT_EQ(*Style1, getGoogleStyle());
 }


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


r326099 - [CodeGen][DebugInfo] Refactor duplicated code, NFC

2018-02-26 Thread Scott Linder via cfe-commits
Author: scott.linder
Date: Mon Feb 26 08:31:08 2018
New Revision: 326099

URL: http://llvm.org/viewvc/llvm-project?rev=326099&view=rev
Log:
[CodeGen][DebugInfo] Refactor duplicated code, NFC

Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=326099&r1=326098&r2=326099&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Feb 26 08:31:08 2018
@@ -388,18 +388,14 @@ CGDebugInfo::computeChecksum(FileID FID,
 llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
   if (!Loc.isValid())
 // If Location is not valid then use main input file.
-return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
-   remapDIPath(TheCU->getDirectory()),
-   TheCU->getFile()->getChecksum());
+return getOrCreateMainFile();
 
   SourceManager &SM = CGM.getContext().getSourceManager();
   PresumedLoc PLoc = SM.getPresumedLoc(Loc);
 
   if (PLoc.isInvalid() || StringRef(PLoc.getFilename()).empty())
 // If the location is not valid then use main input file.
-return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
-   remapDIPath(TheCU->getDirectory()),
-   TheCU->getFile()->getChecksum());
+return getOrCreateMainFile();
 
   // Cache the results.
   const char *fname = PLoc.getFilename();


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


[PATCH] D42766: [DebugInfo] Support DWARFv5 source code embedding extension

2018-02-26 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D42766



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


[PATCH] D43766: [clang-tidy][modernize-make-unique] Checks c++14 flag before using std::make_unique

2018-02-26 Thread Frederic Tingaud via Phabricator via cfe-commits
ftingaud created this revision.
ftingaud added reviewers: hokein, Prazek.
ftingaud added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, xazax.hun.

For a c++11 code, the clang-tidy rule "modernize-make-unique" should return 
immediately, as std::make_unique is not supported.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43766

Files:
  clang-tidy/modernize/MakeSharedCheck.cpp
  clang-tidy/modernize/MakeSharedCheck.h
  clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tidy/modernize/MakeSmartPtrCheck.h
  clang-tidy/modernize/MakeUniqueCheck.cpp
  clang-tidy/modernize/MakeUniqueCheck.h


Index: clang-tidy/modernize/MakeUniqueCheck.h
===
--- clang-tidy/modernize/MakeUniqueCheck.h
+++ clang-tidy/modernize/MakeUniqueCheck.h
@@ -31,6 +31,8 @@
 
 protected:
   SmartPtrTypeMatcher getSmartPointerTypeMatcher() const override;
+
+  bool isVersionSupported(const clang::LangOptions &LangOpts) const override;
 };
 
 } // namespace modernize
Index: clang-tidy/modernize/MakeUniqueCheck.cpp
===
--- clang-tidy/modernize/MakeUniqueCheck.cpp
+++ clang-tidy/modernize/MakeUniqueCheck.cpp
@@ -36,6 +36,10 @@
 
equalsBoundNode(PointerType;
 }
 
+bool MakeUniqueCheck::isVersionSupported(const clang::LangOptions &LangOpts) 
const {
+   return LangOpts.CPlusPlus14;
+}
+
 } // namespace modernize
 } // namespace tidy
 } // namespace clang
Index: clang-tidy/modernize/MakeSmartPtrCheck.h
===
--- clang-tidy/modernize/MakeSmartPtrCheck.h
+++ clang-tidy/modernize/MakeSmartPtrCheck.h
@@ -40,6 +40,9 @@
   /// in this class.
   virtual SmartPtrTypeMatcher getSmartPointerTypeMatcher() const = 0;
 
+  /// Returns whether the C++ version is compatible with current check.
+  virtual bool isVersionSupported(const clang::LangOptions &LangOpts) const = 
0;
+
   static const char PointerType[];
   static const char ConstructorCall[];
   static const char ResetCall[];
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp
===
--- clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -62,15 +62,15 @@
 }
 
 void MakeSmartPtrCheck::registerPPCallbacks(CompilerInstance &Compiler) {
-  if (getLangOpts().CPlusPlus11) {
+  if (isVersionSupported(getLangOpts())) {
 Inserter.reset(new utils::IncludeInserter(
 Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle));
 Compiler.getPreprocessor().addPPCallbacks(Inserter->CreatePPCallbacks());
   }
 }
 
 void MakeSmartPtrCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {
-  if (!getLangOpts().CPlusPlus11)
+  if (!isVersionSupported(getLangOpts()))
 return;
 
   // Calling make_smart_ptr from within a member function of a type with a
Index: clang-tidy/modernize/MakeSharedCheck.h
===
--- clang-tidy/modernize/MakeSharedCheck.h
+++ clang-tidy/modernize/MakeSharedCheck.h
@@ -34,6 +34,8 @@
 
 protected:
   SmartPtrTypeMatcher getSmartPointerTypeMatcher() const override;
+
+  bool isVersionSupported(const clang::LangOptions &LangOpts) const override;
 };
 
 } // namespace modernize
Index: clang-tidy/modernize/MakeSharedCheck.cpp
===
--- clang-tidy/modernize/MakeSharedCheck.cpp
+++ clang-tidy/modernize/MakeSharedCheck.cpp
@@ -27,6 +27,10 @@
  qualType().bind(PointerType);
 }
 
+bool MakeSharedCheck::isVersionSupported(const clang::LangOptions &LangOpts) 
const {
+   return LangOpts.CPlusPlus11;
+}
+
 } // namespace modernize
 } // namespace tidy
 } // namespace clang


Index: clang-tidy/modernize/MakeUniqueCheck.h
===
--- clang-tidy/modernize/MakeUniqueCheck.h
+++ clang-tidy/modernize/MakeUniqueCheck.h
@@ -31,6 +31,8 @@
 
 protected:
   SmartPtrTypeMatcher getSmartPointerTypeMatcher() const override;
+
+  bool isVersionSupported(const clang::LangOptions &LangOpts) const override;
 };
 
 } // namespace modernize
Index: clang-tidy/modernize/MakeUniqueCheck.cpp
===
--- clang-tidy/modernize/MakeUniqueCheck.cpp
+++ clang-tidy/modernize/MakeUniqueCheck.cpp
@@ -36,6 +36,10 @@
 equalsBoundNode(PointerType;
 }
 
+bool MakeUniqueCheck::isVersionSupported(const clang::LangOptions &LangOpts) const {
+   return LangOpts.CPlusPlus14;
+}
+
 } // namespace modernize
 } // namespace tidy
 } // namespace clang
Index: clang-tidy/modernize/MakeSmartPtrCheck.h
===
--- clang-tidy/modernize/MakeSmartPtrCheck.h
+++ cla

[PATCH] D43749: [Attr] Fix alloc_size's diags to report arg idx not value

2018-02-26 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D43749#1018846, @aaron.ballman wrote:

> Committed (with whitespace fix for the test case) in r326058, thanks for the 
> patch!


Sure.  Thanks for committing.

By the way the commit log you added isn't quite right. The issue isn't base 0 
versus base 1.  The issue is attribute argument index versus attribute argument 
value.  See the test case for an example.

I'm not suggesting we somehow change the commit log.  I just want to be sure 
you see what I actually did here.


https://reviews.llvm.org/D43749



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


[PATCH] D43749: [Attr] Fix alloc_size's diags to report arg idx not value

2018-02-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D43749#1019359, @jdenny wrote:

> In https://reviews.llvm.org/D43749#1018846, @aaron.ballman wrote:
>
> > Committed (with whitespace fix for the test case) in r326058, thanks for 
> > the patch!
>
>
> Sure.  Thanks for committing.
>
> By the way the commit log you added isn't quite right. The issue isn't base 0 
> versus base 1.  The issue is attribute argument index versus attribute 
> argument value.  See the test case for an example.
>
> I'm not suggesting we somehow change the commit log.  I just want to be sure 
> you see what I actually did here.


Oh, yeah, I did muck up that commit log message a bit. Sorry about that!


https://reviews.llvm.org/D43749



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


[PATCH] D43500: [clang-tidy]: modernize-use-default-member-init: Remove trailing comma and colon.

2018-02-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: unittests/clang-tidy/ClangTidyTest.h:145
+
+  //   Options.
+  if (Options.FormatStyle) {

Extraneous whitespace.



Comment at: unittests/clang-tidy/ClangTidyTest.h:147
+  if (Options.FormatStyle) {
+auto Style = format::getStyle(*Options.FormatStyle,
+  Filename.getSingleStringRef(), "LLVM");

Please don't use `auto` unless the type is explicitly spelled out in the 
initialization. (Here and elsewhere in the patch.)



Comment at: unittests/clang-tidy/ClangTidyTest.h:159-160
+  CleannedReplacements = std::move(FormattedReplacements);
+  if (!CleannedReplacements)
+llvm_unreachable("!CleannedReplacements");
+} else {

This smells like it should be an assert rather than an unreachable.



Comment at: unittests/clang-tidy/ClangTidyTest.h:167
+if (!Result) {
+  // FIXME: propogate the error.
+  llvm::consumeError(Result.takeError());

Are you intending to implement this fixme in this patch?


https://reviews.llvm.org/D43500



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


[PATCH] D43749: [Attr] Fix alloc_size's diags to report arg idx not value

2018-02-26 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D43749#1019377, @aaron.ballman wrote:

> Oh, yeah, I did muck up that commit log message a bit. Sorry about that!


No problem.  :-)

I'll get to your comments in the other patches hopefully soon.  Thanks again.


https://reviews.llvm.org/D43749



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


[PATCH] D42766: [DebugInfo] Support DWARFv5 source code embedding extension

2018-02-26 Thread Scott Linder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL326102: [DebugInfo] Support DWARF v5 source code embedding 
extension (authored by scott.linder, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D42766?vs=135909&id=135918#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D42766

Files:
  cfe/trunk/docs/ClangCommandLineReference.rst
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/include/clang/Frontend/CodeGenOptions.def
  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
  cfe/trunk/lib/CodeGen/CGDebugInfo.h
  cfe/trunk/lib/Driver/ToolChains/AMDGPU.h
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/CodeGen/Inputs/debug-info-embed-source.c
  cfe/trunk/test/CodeGen/debug-info-embed-source.c
  cfe/trunk/test/Driver/amdgpu-toolchain.c
  cfe/trunk/test/Driver/debug-options.c

Index: cfe/trunk/test/CodeGen/Inputs/debug-info-embed-source.c
===
--- cfe/trunk/test/CodeGen/Inputs/debug-info-embed-source.c
+++ cfe/trunk/test/CodeGen/Inputs/debug-info-embed-source.c
@@ -0,0 +1 @@
+void foo() { }
Index: cfe/trunk/test/CodeGen/debug-info-embed-source.c
===
--- cfe/trunk/test/CodeGen/debug-info-embed-source.c
+++ cfe/trunk/test/CodeGen/debug-info-embed-source.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1-debug-info-kind=limited -emit-llvm %p/Inputs/debug-info-embed-source.c -o - | FileCheck %s --check-prefix=NOEMBED
+// RUN: %clang_cc1 -gembed-source -debug-info-kind=limited -emit-llvm %p/Inputs/debug-info-embed-source.c -o - | FileCheck %s --check-prefix=EMBED
+
+// NOEMBED-NOT: !DIFile({{.*}}source:
+// EMBED: !DIFile({{.*}}source: "void foo() { }\0A"
Index: cfe/trunk/test/Driver/debug-options.c
===
--- cfe/trunk/test/Driver/debug-options.c
+++ cfe/trunk/test/Driver/debug-options.c
@@ -245,3 +245,13 @@
 // RUN: %clang -###  %s 2>&1 | FileCheck -check-prefix=NOMACRO %s
 // MACRO: "-debug-info-macro"
 // NOMACRO-NOT: "-debug-info-macro"
+//
+// RUN: %clang -### -gdwarf-5 -gembed-source %s 2>&1 | FileCheck -check-prefix=GEMBED_5 %s
+// RUN: %clang -### -gdwarf-2 -gembed-source %s 2>&1 | FileCheck -check-prefix=GEMBED_2 %s
+// RUN: %clang -### -gdwarf-5 -gno-embed-source %s 2>&1 | FileCheck -check-prefix=NOGEMBED_5 %s
+// RUN: %clang -### -gdwarf-2 -gno-embed-source %s 2>&1 | FileCheck -check-prefix=NOGEMBED_2 %s
+//
+// GEMBED_5:  "-gembed-source"
+// GEMBED_2:  error: invalid argument '-gembed-source' only allowed with '-gdwarf-5'
+// NOGEMBED_5-NOT:  "-gembed-source"
+// NOGEMBED_2-NOT:  error: invalid argument '-gembed-source' only allowed with '-gdwarf-5'
Index: cfe/trunk/test/Driver/amdgpu-toolchain.c
===
--- cfe/trunk/test/Driver/amdgpu-toolchain.c
+++ cfe/trunk/test/Driver/amdgpu-toolchain.c
@@ -3,4 +3,4 @@
 // AS_LINK: ld.lld{{.*}} "-shared"
 
 // RUN: %clang -### -g -target amdgcn--amdhsa -mcpu=kaveri %s 2>&1 | FileCheck -check-prefix=DWARF_VER %s
-// DWARF_VER: "-dwarf-version=2"
+// DWARF_VER: "-dwarf-version=5"
Index: cfe/trunk/lib/CodeGen/CGDebugInfo.h
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.h
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.h
@@ -502,6 +502,9 @@
   Optional
   computeChecksum(FileID FID, SmallString<32> &Checksum) const;
 
+  /// Get the source of the given file ID.
+  Optional getSource(const SourceManager &SM, FileID FID);
+
   /// Get the file debug info descriptor for the input location.
   llvm::DIFile *getOrCreateFile(SourceLocation Loc);
 
Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
@@ -385,6 +385,19 @@
   return llvm::DIFile::CSK_MD5;
 }
 
+Optional CGDebugInfo::getSource(const SourceManager &SM, FileID FID) {
+  if (!CGM.getCodeGenOpts().EmbedSource)
+return None;
+
+  bool SourceInvalid = false;
+  StringRef Source = SM.getBufferData(FID, &SourceInvalid);
+
+  if (SourceInvalid)
+return None;
+
+  return Source;
+}
+
 llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
   if (!Loc.isValid())
 // If Location is not valid then use main input file.
@@ -416,16 +429,19 @@
 
   llvm::DIFile *F = DBuilder.createFile(remapDIPath(PLoc.getFilename()),
 remapDIPath(getCurrentDirname()),
-CSInfo);
+CSInfo,
+getSource(SM, SM.getFileID(Loc)));
 
   DIFileCache[fname].reset(F);
   return F;
 }
 
 llvm::DIFile *CGDebugInfo::getOrCreateMainFile() {
-  return DBuilder.createFile

r326102 - [DebugInfo] Support DWARF v5 source code embedding extension

2018-02-26 Thread Scott Linder via cfe-commits
Author: scott.linder
Date: Mon Feb 26 09:32:31 2018
New Revision: 326102

URL: http://llvm.org/viewvc/llvm-project?rev=326102&view=rev
Log:
[DebugInfo] Support DWARF v5 source code embedding extension

In DWARF v5 the Line Number Program Header is extensible, allowing values with
new content types. This vendor extension to DWARF v5 allows source text to be
embedded directly in the line tables of the debug line section.

Add new flag (-g[no-]embed-source) to Driver and CC1 which indicates
that source should be passed through to LLVM during CodeGen.

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

Added:
cfe/trunk/test/CodeGen/Inputs/debug-info-embed-source.c
cfe/trunk/test/CodeGen/debug-info-embed-source.c
Modified:
cfe/trunk/docs/ClangCommandLineReference.rst
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.h
cfe/trunk/lib/Driver/ToolChains/AMDGPU.h
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/Driver/amdgpu-toolchain.c
cfe/trunk/test/Driver/debug-options.c

Modified: cfe/trunk/docs/ClangCommandLineReference.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangCommandLineReference.rst?rev=326102&r1=326101&r2=326102&view=diff
==
--- cfe/trunk/docs/ClangCommandLineReference.rst (original)
+++ cfe/trunk/docs/ClangCommandLineReference.rst Mon Feb 26 09:32:31 2018
@@ -2573,6 +2573,10 @@ Debug information flags
 
 .. option:: -gdwarf-aranges
 
+.. option:: -gembed-source
+
+.. option:: -gno-embed-source
+
 .. option:: -ggnu-pubnames
 
 .. option:: -grecord-gcc-switches, -gno-record-gcc-switches

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=326102&r1=326101&r2=326102&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Mon Feb 26 09:32:31 2018
@@ -1703,6 +1703,11 @@ def gz : Flag<["-"], "gz">, Group;
 def gz_EQ : Joined<["-"], "gz=">, Group,
 HelpText<"DWARF debug sections compression type">;
+def gembed_source : Flag<["-"], "gembed-source">, Group, 
Flags<[CC1Option]>,
+HelpText<"Embed source text in DWARF debug sections">;
+def gno_embed_source : Flag<["-"], "gno-embed-source">, Group,
+Flags<[DriverOption]>,
+HelpText<"Restore the default behavior of not embedding source text in 
DWARF debug sections">;
 def headerpad__max__install__names : Joined<["-"], 
"headerpad_max_install_names">;
 def help : Flag<["-", "--"], "help">, Flags<[CC1Option,CC1AsOption]>,
   HelpText<"Display available options">;

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=326102&r1=326101&r2=326102&view=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Mon Feb 26 09:32:31 2018
@@ -318,6 +318,9 @@ CODEGENOPT(GnuPubnames, 1, 0)
 
 CODEGENOPT(NoPLT, 1, 0)
 
+/// Whether to embed source in DWARF debug line section.
+CODEGENOPT(EmbedSource, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=326102&r1=326101&r2=326102&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Feb 26 09:32:31 2018
@@ -385,6 +385,19 @@ CGDebugInfo::computeChecksum(FileID FID,
   return llvm::DIFile::CSK_MD5;
 }
 
+Optional CGDebugInfo::getSource(const SourceManager &SM, FileID 
FID) {
+  if (!CGM.getCodeGenOpts().EmbedSource)
+return None;
+
+  bool SourceInvalid = false;
+  StringRef Source = SM.getBufferData(FID, &SourceInvalid);
+
+  if (SourceInvalid)
+return None;
+
+  return Source;
+}
+
 llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
   if (!Loc.isValid())
 // If Location is not valid then use main input file.
@@ -416,16 +429,19 @@ llvm::DIFile *CGDebugInfo::getOrCreateFi
 
   llvm::DIFile *F = DBuilder.createFile(remapDIPath(PLoc.getFilename()),
 remapDIPath(getCurrentDirname()),
-CSInfo);
+CSInfo,
+getSource(SM, SM.getFileID(Loc)));
 
   DIFileCache[fname].reset(F);
   return F;
 }
 
 llvm::DIFile *CGDebugInfo::getOrCreateMainFile() {
-  return DBuilder.createFil

[PATCH] D43312: [clang-format] fix handling of consecutive unary operators

2018-02-26 Thread Kevin Lee via Phabricator via cfe-commits
kevinl added a comment.

@krasimir ping?

would appreciate you committing this for me. thanks!


Repository:
  rC Clang

https://reviews.llvm.org/D43312



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


[PATCH] D42644: [asan] Intercept std::rethrow_exception indirectly.

2018-02-26 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: test/asan/TestCases/intercept-rethrow-exception.cc:48
+  // memcpy is intercepted by asan which performs checks on src and dst
+  using T = int[1000];
+  T x {};

robot wrote:
> vitalybuka wrote:
> > You can include #include 
> > and use __asan_region_is_poisoned
> We don't have commit rights, can you commit it? Should we first change to 
> `__asan_region_is_poisoned` and kill the program if it is indeed poisoined?
Sure, I'll update and commit this for you.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D42644



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


r326108 - [Driver] Forward opt-remark hotness threshold to LTO

2018-02-26 Thread Adam Nemet via cfe-commits
Author: anemet
Date: Mon Feb 26 10:38:11 2018
New Revision: 326108

URL: http://llvm.org/viewvc/llvm-project?rev=326108&view=rev
Log:
[Driver] Forward opt-remark hotness threshold to LTO

Modified:
cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
cfe/trunk/test/Driver/darwin-ld.c

Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Darwin.cpp?rev=326108&r1=326107&r2=326108&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp Mon Feb 26 10:38:11 2018
@@ -452,7 +452,8 @@ void darwin::Linker::ConstructJob(Compil
   // we follow suite for ease of comparison.
   AddLinkArgs(C, Args, CmdArgs, Inputs);
 
-  // For LTO, pass the name of the optimization record file.
+  // For LTO, pass the name of the optimization record file and other
+  // opt-remarks flags.
   if (Args.hasFlag(options::OPT_fsave_optimization_record,
options::OPT_fno_save_optimization_record, false)) {
 CmdArgs.push_back("-mllvm");
@@ -467,6 +468,14 @@ void darwin::Linker::ConstructJob(Compil
 if (getLastProfileUseArg(Args)) {
   CmdArgs.push_back("-mllvm");
   CmdArgs.push_back("-lto-pass-remarks-with-hotness");
+
+  if (const Arg *A =
+  Args.getLastArg(options::OPT_fdiagnostics_hotness_threshold_EQ)) 
{
+CmdArgs.push_back("-mllvm");
+std::string Opt =
+std::string("-lto-pass-remarks-hotness-threshold=") + 
A->getValue();
+CmdArgs.push_back(Args.MakeArgString(Opt));
+  }
 }
   }
 

Modified: cfe/trunk/test/Driver/darwin-ld.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/darwin-ld.c?rev=326108&r1=326107&r2=326108&view=diff
==
--- cfe/trunk/test/Driver/darwin-ld.c (original)
+++ cfe/trunk/test/Driver/darwin-ld.c Mon Feb 26 10:38:11 2018
@@ -342,6 +342,10 @@
 // RUN: FileCheck -check-prefix=PASS_REMARKS_WITH_HOTNESS %s < %t.log
 // PASS_REMARKS_WITH_HOTNESS: "-mllvm" "-lto-pass-remarks-output" "-mllvm" 
"foo/bar.out.opt.yaml" "-mllvm" "-lto-pass-remarks-with-hotness"
 
+// RUN: %clang -target x86_64-apple-darwin12 %t.o -fsave-optimization-record 
-fprofile-instr-use=blah -fdiagnostics-hotness-threshold=100 -### -o 
foo/bar.out 2> %t.log
+// RUN: FileCheck -check-prefix=PASS_REMARKS_WITH_HOTNESS_THRESHOLD %s < %t.log
+// PASS_REMARKS_WITH_HOTNESS_THRESHOLD: "-mllvm" "-lto-pass-remarks-output" 
"-mllvm" "foo/bar.out.opt.yaml" "-mllvm" "-lto-pass-remarks-with-hotness" 
"-mllvm" "-lto-pass-remarks-hotness-threshold=100"
+
 // RUN: %clang -target x86_64-apple-ios6.0 -miphoneos-version-min=6.0 
-fprofile-instr-generate -### %t.o 2> %t.log
 // RUN: FileCheck -check-prefix=LINK_PROFILE_FIRST %s < %t.log
 // RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -### 
%t.o 2> %t.log


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


[PATCH] D43766: [clang-tidy][modernize-make-unique] Checks c++14 flag before using std::make_unique

2018-02-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

This fix is missing test coverage, can you add a C++11 and C++14 test to 
demonstrate the behavior differences?




Comment at: clang-tidy/modernize/MakeSharedCheck.cpp:30
 
+bool MakeSharedCheck::isVersionSupported(const clang::LangOptions &LangOpts) 
const {
+   return LangOpts.CPlusPlus11;

You can drop the `clang::` from the parameter type.



Comment at: clang-tidy/modernize/MakeUniqueCheck.cpp:39
 
+bool MakeUniqueCheck::isVersionSupported(const clang::LangOptions &LangOpts) 
const {
+   return LangOpts.CPlusPlus14;

Can drop it here as well.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43766



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


[PATCH] D43700: Emit proper CodeView even when not using the cl driver.

2018-02-26 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea added a comment.

Thanks for fixing this @zturner. I simply want to back-up what @probinson says 
above - most of the games we do at Ubisoft are currently using a different 
compilation toolchains for each platform (we ship at least 4-5 platforms for 
each top game). It can be clang or it can be MSVC; and most of the time it's 
different versions of clang. Our long-term goal is to preferably have only one 
toolchain for all our platforms & all our targets - that means one set of 
common g++ like flags, including Windows.


https://reviews.llvm.org/D43700



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


[PATCH] D43700: Emit proper CodeView even when not using the cl driver.

2018-02-26 Thread Colden Cullen via Phabricator via cfe-commits
colden added a comment.

In https://reviews.llvm.org/D43700#1019505, @aganea wrote:

> Thanks for fixing this @zturner. I simply want to back-up what @probinson 
> says above - most of the games we do at Ubisoft are currently using a 
> different compilation toolchains for each platform (we ship at least 4-5 
> platforms for each top game). It can be clang or it can be MSVC; and most of 
> the time it's different versions of clang. Our long-term goal is to 
> preferably have only one toolchain for all our platforms & all our targets - 
> that means one set of common g++ like flags, including Windows.


+1, this is what we're going for on Lumberyard as well. Well put.


https://reviews.llvm.org/D43700



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


[PATCH] D43700: Emit proper CodeView even when not using the cl driver.

2018-02-26 Thread Zachary Turner via Phabricator via cfe-commits
zturner added a comment.

@rnk by "in an MSVC environment" do you mean "when -fms-compatibility is 
present"?


https://reviews.llvm.org/D43700



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


[PATCH] D43547: [Indexing] Fixing inconsistencies between FUNCDNAME and generated code by improving ASTContext's API for MangleContext

2018-02-26 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

Code looks good, but we should test it. Can you add a CodeGenCXX test that 
shows the issue with FUNCDNAME? I see the issue with this program:

  #include 
  int main() {
const char *s1 = ([]() { return __FUNCDNAME__; })();
const char *s2 = ([]() { return __FUNCDNAME__; })();
printf("%s\n%s\n", s1, s2);
  }




Comment at: lib/AST/Expr.cpp:500-502
+  MangleContext& MC = Context.getMangleContext();
 
+  if (MC.shouldMangleDeclName(ND)) {

Oh, I see, FUNCDNAME was really broken. Ignore my previous comment.


https://reviews.llvm.org/D43547



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


[PATCH] D43700: Emit proper CodeView even when not using the cl driver.

2018-02-26 Thread Colden Cullen via Phabricator via cfe-commits
colden added a comment.

In https://reviews.llvm.org/D43700#1019506, @zturner wrote:

> @rnk by "in an MSVC environment" do you mean "when -fms-compatibility is 
> present"?


It looks like other places in this file are using 
`Triple.isWindowsMSVCEnvironment()`, which I think would make sense to use for 
this too. It's implemented as:

  bool isWindowsMSVCEnvironment() const {
return getOS() == Triple::Win32 &&
   (getEnvironment() == Triple::UnknownEnvironment ||
getEnvironment() == Triple::MSVC);
  }

This appears to default to true from a normal Windows cmd (on my Win10 machine, 
the default triple is `x86_64-pc-windows-msvc`).


https://reviews.llvm.org/D43700



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


[PATCH] D43700: Emit proper CodeView even when not using the cl driver.

2018-02-26 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

The `-g` meaning `-gcodeview` for MSVC environments change should be a separate 
diff though, right?


https://reviews.llvm.org/D43700



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


[PATCH] D43700: Emit proper CodeView even when not using the cl driver.

2018-02-26 Thread Zachary Turner via Phabricator via cfe-commits
zturner added a comment.

In https://reviews.llvm.org/D43700#1019533, @smeenai wrote:

> The `-g` meaning `-gcodeview` for MSVC environments change should be a 
> separate diff though, right?


Yes I'm not doing that in this patch.  Just wanted to clarify what he meant.  
I'm writing a test for this right now and then I'll commit.


https://reviews.llvm.org/D43700



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


r326113 - Emit proper CodeView when -gcodeview is passed without the cl driver.

2018-02-26 Thread Zachary Turner via cfe-commits
Author: zturner
Date: Mon Feb 26 11:25:39 2018
New Revision: 326113

URL: http://llvm.org/viewvc/llvm-project?rev=326113&view=rev
Log:
Emit proper CodeView when -gcodeview is passed without the cl driver.

Windows debuggers don't work properly when column info is emitted
with lines.  We handled this by checking if the driver mode was
cl, but it's possible to cause the gcc driver to emit codeview as
well, and in that path we were emitting column info with codeview.

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

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

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=326113&r1=326112&r2=326113&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Mon Feb 26 11:25:39 2018
@@ -2968,7 +2968,7 @@ static void RenderDebugOptions(const Too
 
   // Forward -gcodeview. EmitCodeView might have been set by CL-compatibility
   // argument parsing.
-  if (Args.hasArg(options::OPT_gcodeview) || EmitCodeView) {
+  if (EmitCodeView) {
 // DWARFVersion remains at 0 if no explicit choice was made.
 CmdArgs.push_back("-gcodeview");
   } else if (DWARFVersion == 0 &&
@@ -3567,6 +3567,8 @@ void Clang::ConstructJob(Compilation &C,
   types::ID InputType = Input.getType();
   if (D.IsCLMode())
 AddClangCLArgs(Args, InputType, CmdArgs, &DebugInfoKind, &EmitCodeView);
+  else
+EmitCodeView = Args.hasArg(options::OPT_gcodeview);
 
   const Arg *SplitDWARFArg = nullptr;
   RenderDebugOptions(getToolChain(), D, RawTriple, Args, EmitCodeView,

Added: cfe/trunk/test/Driver/codeview-column-info.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/codeview-column-info.c?rev=326113&view=auto
==
--- cfe/trunk/test/Driver/codeview-column-info.c (added)
+++ cfe/trunk/test/Driver/codeview-column-info.c Mon Feb 26 11:25:39 2018
@@ -0,0 +1,13 @@
+// Check that -dwarf-column-info does not get added to the cc1 line:
+// 1) When -gcodeview is present via the clang or clang++ driver
+// 2) When /Z7 is present via the cl driver.
+
+// RUN: %clang -### -c -g -gcodeview %s 2> %t1
+// RUN: FileCheck < %t1 %s
+// RUN: %clangxx -### -c -g -gcodeview %s 2> %t2
+// RUN: FileCheck < %t2 %s
+// RUN: %clang_cl -### /c /Z7 %s 2> %t2
+// RUN: FileCheck < %t2 %s
+
+// CHECK: "-cc1"
+// CHECK-NOT: "-dwarf-column-info"


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


[PATCH] D43700: Emit proper CodeView even when not using the cl driver.

2018-02-26 Thread Zachary Turner via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC326113: Emit proper CodeView when -gcodeview is passed 
without the cl driver. (authored by zturner, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43700?vs=135723&id=135932#toc

Repository:
  rC Clang

https://reviews.llvm.org/D43700

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


Index: test/Driver/codeview-column-info.c
===
--- test/Driver/codeview-column-info.c
+++ test/Driver/codeview-column-info.c
@@ -0,0 +1,13 @@
+// Check that -dwarf-column-info does not get added to the cc1 line:
+// 1) When -gcodeview is present via the clang or clang++ driver
+// 2) When /Z7 is present via the cl driver.
+
+// RUN: %clang -### -c -g -gcodeview %s 2> %t1
+// RUN: FileCheck < %t1 %s
+// RUN: %clangxx -### -c -g -gcodeview %s 2> %t2
+// RUN: FileCheck < %t2 %s
+// RUN: %clang_cl -### /c /Z7 %s 2> %t2
+// RUN: FileCheck < %t2 %s
+
+// CHECK: "-cc1"
+// CHECK-NOT: "-dwarf-column-info"
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -2968,7 +2968,7 @@
 
   // Forward -gcodeview. EmitCodeView might have been set by CL-compatibility
   // argument parsing.
-  if (Args.hasArg(options::OPT_gcodeview) || EmitCodeView) {
+  if (EmitCodeView) {
 // DWARFVersion remains at 0 if no explicit choice was made.
 CmdArgs.push_back("-gcodeview");
   } else if (DWARFVersion == 0 &&
@@ -3567,6 +3567,8 @@
   types::ID InputType = Input.getType();
   if (D.IsCLMode())
 AddClangCLArgs(Args, InputType, CmdArgs, &DebugInfoKind, &EmitCodeView);
+  else
+EmitCodeView = Args.hasArg(options::OPT_gcodeview);
 
   const Arg *SplitDWARFArg = nullptr;
   RenderDebugOptions(getToolChain(), D, RawTriple, Args, EmitCodeView,


Index: test/Driver/codeview-column-info.c
===
--- test/Driver/codeview-column-info.c
+++ test/Driver/codeview-column-info.c
@@ -0,0 +1,13 @@
+// Check that -dwarf-column-info does not get added to the cc1 line:
+// 1) When -gcodeview is present via the clang or clang++ driver
+// 2) When /Z7 is present via the cl driver.
+
+// RUN: %clang -### -c -g -gcodeview %s 2> %t1
+// RUN: FileCheck < %t1 %s
+// RUN: %clangxx -### -c -g -gcodeview %s 2> %t2
+// RUN: FileCheck < %t2 %s
+// RUN: %clang_cl -### /c /Z7 %s 2> %t2
+// RUN: FileCheck < %t2 %s
+
+// CHECK: "-cc1"
+// CHECK-NOT: "-dwarf-column-info"
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -2968,7 +2968,7 @@
 
   // Forward -gcodeview. EmitCodeView might have been set by CL-compatibility
   // argument parsing.
-  if (Args.hasArg(options::OPT_gcodeview) || EmitCodeView) {
+  if (EmitCodeView) {
 // DWARFVersion remains at 0 if no explicit choice was made.
 CmdArgs.push_back("-gcodeview");
   } else if (DWARFVersion == 0 &&
@@ -3567,6 +3567,8 @@
   types::ID InputType = Input.getType();
   if (D.IsCLMode())
 AddClangCLArgs(Args, InputType, CmdArgs, &DebugInfoKind, &EmitCodeView);
+  else
+EmitCodeView = Args.hasArg(options::OPT_gcodeview);
 
   const Arg *SplitDWARFArg = nullptr;
   RenderDebugOptions(getToolChain(), D, RawTriple, Args, EmitCodeView,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43773: Implement the container bits of P0805R1

2018-02-26 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists created this revision.
mclow.lists added a reviewer: EricWF.

P0805R1  
is about comparing heterogenous containers.

This is the implementation for `array`, `vector`, `deque`, `list` and 
`forward_list`.
The `tuple` bits will follow soon.

I hope to land this immediately after it is adopted in Jacksonville.


https://reviews.llvm.org/D43773

Files:
  include/array
  include/deque
  include/list
  include/vector
  test/std/containers/sequences/array/compare.fail.cpp
  test/std/containers/sequences/array/compare.pass.cpp
  test/std/containers/sequences/deque/compare.fail.cpp
  test/std/containers/sequences/deque/compare.pass.cpp
  test/std/containers/sequences/forwardlist/compare.fail.cpp
  test/std/containers/sequences/forwardlist/compare.pass.cpp
  test/std/containers/sequences/list/compare.fail.cpp
  test/std/containers/sequences/list/compare.pass.cpp
  test/std/containers/sequences/vector/compare.fail.cpp
  test/std/containers/sequences/vector/compare.pass.cpp

Index: test/std/containers/sequences/vector/compare.pass.cpp
===
--- test/std/containers/sequences/vector/compare.pass.cpp
+++ test/std/containers/sequences/vector/compare.pass.cpp
@@ -0,0 +1,90 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  bool operator==(const vector& x, const vector& y);
+// template  bool operator< (const vector& x, const vector& y);
+// template  bool operator!=(const vector& x, const vector& y);
+// template  bool operator> (const vector& x, const vector& y);
+// template  bool operator>=(const vector& x, const vector& y);
+// template  bool operator<=(const vector& x, const vector& y);
+// 
+// C++20
+// template
+//   bool operator==(const vector& x, const vector& y);
+// template
+//   bool operator< (const vector& x, const vector& y);
+// template
+//   bool operator!=(const vector& x, const vector& y);
+// template
+//   bool operator> (const vector& x, const vector& y);
+// template
+//   bool operator>=(const vector& x, const vector& y);
+// template
+//   bool operator<=(const vector& x, const vector& y);
+
+
+#include 
+#include 
+
+#include "min_allocator.h"
+#include "test_macros.h"
+
+template 
+void test_compare(const Vector& LHS, const Vector& RHS, bool isLess, bool isEqual) {
+  assert((LHS == RHS) ==  isEqual);
+  assert((LHS != RHS) == !isEqual);
+  assert((LHS  < RHS) ==  isLess);
+  assert((LHS <= RHS) ==  (isLess | isEqual));
+  assert((LHS  > RHS) == !(isLess | isEqual));
+  assert((LHS >= RHS) == !isLess);
+}
+
+template 
+void test_compare(const Vector1& LHS, const Vector2& RHS, bool isLess, bool isEqual) {
+  assert((LHS == RHS) ==  isEqual);
+  assert((LHS != RHS) == !isEqual);
+  assert((LHS  < RHS) ==  isLess);
+  assert((LHS <= RHS) ==  (isLess | isEqual));
+  assert((LHS  > RHS) == !(isLess | isEqual));
+  assert((LHS >= RHS) == !isLess);
+}
+
+int main()
+{
+  {
+typedef int T;
+typedef std::vector C;
+C c0 = {};
+C c1 = {1, 2, 3};
+C c2 = {1, 2, 3};
+C c3 = {3, 2, 1};
+C c4 = {1, 2, 1};
+test_compare(c0, c1, true, false);
+test_compare(c1, c2, false, true);
+test_compare(c1, c3, true, false);
+test_compare(c1, c4, false, false);
+  }
+
+#if TEST_STD_VER > 17
+  {
+std::vector   c0 = {};
+std::vector   c1 = {4};
+std::vector  c2 = {4L};
+std::vector c3 = {2};
+std::vector> c4 = {4};
+test_compare(c0, c1, true, false);  // same type, different lengths
+test_compare(c0, c2, true, false);  // different type, different lengths
+test_compare(c1, c2, false, true);  // different types, same length, same values
+test_compare(c1, c3, false, false); // different types, same length, different values
+test_compare(c1, c4, false, true);  // different types, same length, same value, different allocator
+  }
+#endif
+}
Index: test/std/containers/sequences/vector/compare.fail.cpp
===
--- test/std/containers/sequences/vector/compare.fail.cpp
+++ test/std/containers/sequences/vector/compare.fail.cpp
@@ -0,0 +1,70 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  bool operator==(const vector& x, const vector& y);
+// template  bool operator< (const vector

[PATCH] D43773: Implement the container bits of P0805R1

2018-02-26 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists updated this revision to Diff 135941.
mclow.lists added a comment.

forgot to include the changes for `` in the diff.


https://reviews.llvm.org/D43773

Files:
  include/array
  include/deque
  include/forward_list
  include/list
  include/vector
  test/std/containers/sequences/array/compare.fail.cpp
  test/std/containers/sequences/array/compare.pass.cpp
  test/std/containers/sequences/deque/compare.fail.cpp
  test/std/containers/sequences/deque/compare.pass.cpp
  test/std/containers/sequences/forwardlist/compare.fail.cpp
  test/std/containers/sequences/forwardlist/compare.pass.cpp
  test/std/containers/sequences/list/compare.fail.cpp
  test/std/containers/sequences/list/compare.pass.cpp
  test/std/containers/sequences/vector/compare.fail.cpp
  test/std/containers/sequences/vector/compare.pass.cpp

Index: test/std/containers/sequences/vector/compare.pass.cpp
===
--- test/std/containers/sequences/vector/compare.pass.cpp
+++ test/std/containers/sequences/vector/compare.pass.cpp
@@ -0,0 +1,90 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  bool operator==(const vector& x, const vector& y);
+// template  bool operator< (const vector& x, const vector& y);
+// template  bool operator!=(const vector& x, const vector& y);
+// template  bool operator> (const vector& x, const vector& y);
+// template  bool operator>=(const vector& x, const vector& y);
+// template  bool operator<=(const vector& x, const vector& y);
+// 
+// C++20
+// template
+//   bool operator==(const vector& x, const vector& y);
+// template
+//   bool operator< (const vector& x, const vector& y);
+// template
+//   bool operator!=(const vector& x, const vector& y);
+// template
+//   bool operator> (const vector& x, const vector& y);
+// template
+//   bool operator>=(const vector& x, const vector& y);
+// template
+//   bool operator<=(const vector& x, const vector& y);
+
+
+#include 
+#include 
+
+#include "min_allocator.h"
+#include "test_macros.h"
+
+template 
+void test_compare(const Vector& LHS, const Vector& RHS, bool isLess, bool isEqual) {
+  assert((LHS == RHS) ==  isEqual);
+  assert((LHS != RHS) == !isEqual);
+  assert((LHS  < RHS) ==  isLess);
+  assert((LHS <= RHS) ==  (isLess | isEqual));
+  assert((LHS  > RHS) == !(isLess | isEqual));
+  assert((LHS >= RHS) == !isLess);
+}
+
+template 
+void test_compare(const Vector1& LHS, const Vector2& RHS, bool isLess, bool isEqual) {
+  assert((LHS == RHS) ==  isEqual);
+  assert((LHS != RHS) == !isEqual);
+  assert((LHS  < RHS) ==  isLess);
+  assert((LHS <= RHS) ==  (isLess | isEqual));
+  assert((LHS  > RHS) == !(isLess | isEqual));
+  assert((LHS >= RHS) == !isLess);
+}
+
+int main()
+{
+  {
+typedef int T;
+typedef std::vector C;
+C c0 = {};
+C c1 = {1, 2, 3};
+C c2 = {1, 2, 3};
+C c3 = {3, 2, 1};
+C c4 = {1, 2, 1};
+test_compare(c0, c1, true, false);
+test_compare(c1, c2, false, true);
+test_compare(c1, c3, true, false);
+test_compare(c1, c4, false, false);
+  }
+
+#if TEST_STD_VER > 17
+  {
+std::vector   c0 = {};
+std::vector   c1 = {4};
+std::vector  c2 = {4L};
+std::vector c3 = {2};
+std::vector> c4 = {4};
+test_compare(c0, c1, true, false);  // same type, different lengths
+test_compare(c0, c2, true, false);  // different type, different lengths
+test_compare(c1, c2, false, true);  // different types, same length, same values
+test_compare(c1, c3, false, false); // different types, same length, different values
+test_compare(c1, c4, false, true);  // different types, same length, same value, different allocator
+  }
+#endif
+}
Index: test/std/containers/sequences/vector/compare.fail.cpp
===
--- test/std/containers/sequences/vector/compare.fail.cpp
+++ test/std/containers/sequences/vector/compare.fail.cpp
@@ -0,0 +1,70 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// 
+
+// template  bool operator==(const vector& x, const vector& y);
+// template  bool operator< (const vector& x, const vector& y);
+// template  bool operator!=(const vector& x, const vector& y);
+// template  bool operator> (const vector& x, const vector& y);
+// template  bool operator>=(const vector& x, const vector& y);
+// template  bool o

r326116 - Revert "Emit proper CodeView when -gcodeview is passed without the cl driver."

2018-02-26 Thread Zachary Turner via cfe-commits
Author: zturner
Date: Mon Feb 26 11:51:29 2018
New Revision: 326116

URL: http://llvm.org/viewvc/llvm-project?rev=326116&view=rev
Log:
Revert "Emit proper CodeView when -gcodeview is passed without the cl driver."

This reverts commit e17911006548518634fad66bb8648bcad49a1d64.

This is failing on ASAN bots because asan expects column info,
and it's also failing on some linux bots for unknown reasons which
i need to investigate.

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

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=326116&r1=326115&r2=326116&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Mon Feb 26 11:51:29 2018
@@ -2968,7 +2968,7 @@ static void RenderDebugOptions(const Too
 
   // Forward -gcodeview. EmitCodeView might have been set by CL-compatibility
   // argument parsing.
-  if (EmitCodeView) {
+  if (Args.hasArg(options::OPT_gcodeview) || EmitCodeView) {
 // DWARFVersion remains at 0 if no explicit choice was made.
 CmdArgs.push_back("-gcodeview");
   } else if (DWARFVersion == 0 &&
@@ -3567,8 +3567,6 @@ void Clang::ConstructJob(Compilation &C,
   types::ID InputType = Input.getType();
   if (D.IsCLMode())
 AddClangCLArgs(Args, InputType, CmdArgs, &DebugInfoKind, &EmitCodeView);
-  else
-EmitCodeView = Args.hasArg(options::OPT_gcodeview);
 
   const Arg *SplitDWARFArg = nullptr;
   RenderDebugOptions(getToolChain(), D, RawTriple, Args, EmitCodeView,

Removed: cfe/trunk/test/Driver/codeview-column-info.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/codeview-column-info.c?rev=326115&view=auto
==
--- cfe/trunk/test/Driver/codeview-column-info.c (original)
+++ cfe/trunk/test/Driver/codeview-column-info.c (removed)
@@ -1,13 +0,0 @@
-// Check that -dwarf-column-info does not get added to the cc1 line:
-// 1) When -gcodeview is present via the clang or clang++ driver
-// 2) When /Z7 is present via the cl driver.
-
-// RUN: %clang -### -c -g -gcodeview %s 2> %t1
-// RUN: FileCheck < %t1 %s
-// RUN: %clangxx -### -c -g -gcodeview %s 2> %t2
-// RUN: FileCheck < %t2 %s
-// RUN: %clang_cl -### /c /Z7 %s 2> %t2
-// RUN: FileCheck < %t2 %s
-
-// CHECK: "-cc1"
-// CHECK-NOT: "-dwarf-column-info"


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


[PATCH] D43700: Emit proper CodeView even when not using the cl driver.

2018-02-26 Thread Zachary Turner via Phabricator via cfe-commits
zturner added a comment.

I had to revert this for now.  It breaks the asan bots which expect column 
info.  That fix is easy, but it also breaks a random linux bots which I don't 
have the ability to debug at the moment because my linux machine is not 
working.  Hopefully I can get that resolved soon.


Repository:
  rC Clang

https://reviews.llvm.org/D43700



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


[PATCH] D43734: [RecordLayout] Don't align to non-power-of-2 sizes when using -mms-bitfields

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

If its easy enough to wire that through to the frontend as a proper diagnostic, 
that would be better with a test.  Otherwise, this is good to continue to make 
progress.


https://reviews.llvm.org/D43734



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


[PATCH] D43775: add UUID to the acronyms list of objc property name checks

2018-02-26 Thread Yan Zhang via Phabricator via cfe-commits
Wizard created this revision.
Herald added subscribers: cfe-commits, klimek.
Wizard added reviewers: benhamilton, hokein.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43775

Files:
  clang-tidy/objc/PropertyDeclarationCheck.cpp


Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -87,6 +87,7 @@
 "UI",
 "URI",
 "URL",
+"UUID",
 "VC",
 "VOIP",
 "VPN",


Index: clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -87,6 +87,7 @@
 "UI",
 "URI",
 "URL",
+"UUID",
 "VC",
 "VOIP",
 "VPN",
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r326118 - Fix for LLVM r326109

2018-02-26 Thread David Zarzycki via cfe-commits
Author: davezarzycki
Date: Mon Feb 26 12:21:30 2018
New Revision: 326118

URL: http://llvm.org/viewvc/llvm-project?rev=326118&view=rev
Log:
Fix for LLVM r326109

Modified:
clang-tools-extra/trunk/clang-query/QueryParser.cpp
clang-tools-extra/trunk/clang-query/QueryParser.h

Modified: clang-tools-extra/trunk/clang-query/QueryParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-query/QueryParser.cpp?rev=326118&r1=326117&r2=326118&view=diff
==
--- clang-tools-extra/trunk/clang-query/QueryParser.cpp (original)
+++ clang-tools-extra/trunk/clang-query/QueryParser.cpp Mon Feb 26 12:21:30 2018
@@ -50,25 +50,35 @@ StringRef QueryParser::lexWord() {
 // This is the StringSwitch-alike used by lexOrCompleteWord below. See that
 // function for details.
 template  struct QueryParser::LexOrCompleteWord {
+  StringRef Word;
   StringSwitch Switch;
 
   QueryParser *P;
-  StringRef Word;
   // Set to the completion point offset in Word, or StringRef::npos if
   // completion point not in Word.
   size_t WordCompletionPos;
 
-  LexOrCompleteWord(QueryParser *P, StringRef Word, size_t WCP)
-  : Switch(Word), P(P), Word(Word), WordCompletionPos(WCP) {}
+  // Lexes a word and stores it in Word. Returns a LexOrCompleteWord object
+  // that can be used like a llvm::StringSwitch, but adds cases as possible
+  // completions if the lexed word contains the completion point.
+  LexOrCompleteWord(QueryParser *P, StringRef &OutWord)
+  : Word(P->lexWord()), Switch(Word), P(P),
+WordCompletionPos(StringRef::npos) {
+OutWord = Word;
+if (P->CompletionPos && P->CompletionPos <= Word.data() + Word.size()) {
+  if (P->CompletionPos < Word.data())
+WordCompletionPos = 0;
+  else
+WordCompletionPos = P->CompletionPos - Word.data();
+}
+  }
 
-  template 
-  LexOrCompleteWord &Case(const char (&S)[N], const T &Value,
+  LexOrCompleteWord &Case(llvm::StringLiteral CaseStr, const T &Value,
   bool IsCompletion = true) {
-StringRef CaseStr(S, N - 1);
 
 if (WordCompletionPos == StringRef::npos)
-  Switch.Case(S, Value);
-else if (N != 1 && IsCompletion && WordCompletionPos <= CaseStr.size() &&
+  Switch.Case(CaseStr, Value);
+else if (CaseStr.size() != 0 && IsCompletion && WordCompletionPos <= 
CaseStr.size() &&
  CaseStr.substr(0, WordCompletionPos) ==
  Word.substr(0, WordCompletionPos))
   P->Completions.push_back(LineEditor::Completion(
@@ -76,29 +86,12 @@ template  struct QueryParser
 return *this;
   }
 
-  T Default(const T &Value) const { return Switch.Default(Value); }
+  T Default(T Value) { return Switch.Default(Value); }
 };
 
-// Lexes a word and stores it in Word. Returns a LexOrCompleteWord object
-// that can be used like a llvm::StringSwitch, but adds cases as possible
-// completions if the lexed word contains the completion point.
-template 
-QueryParser::LexOrCompleteWord
-QueryParser::lexOrCompleteWord(StringRef &Word) {
-  Word = lexWord();
-  size_t WordCompletionPos = StringRef::npos;
-  if (CompletionPos && CompletionPos <= Word.data() + Word.size()) {
-if (CompletionPos < Word.data())
-  WordCompletionPos = 0;
-else
-  WordCompletionPos = CompletionPos - Word.data();
-  }
-  return LexOrCompleteWord(this, Word, WordCompletionPos);
-}
-
 QueryRef QueryParser::parseSetBool(bool QuerySession::*Var) {
   StringRef ValStr;
-  unsigned Value = lexOrCompleteWord(ValStr)
+  unsigned Value = LexOrCompleteWord(this, ValStr)
.Case("false", 0)
.Case("true", 1)
.Default(~0u);
@@ -110,7 +103,7 @@ QueryRef QueryParser::parseSetBool(bool
 
 QueryRef QueryParser::parseSetOutputKind() {
   StringRef ValStr;
-  unsigned OutKind = lexOrCompleteWord(ValStr)
+  unsigned OutKind = LexOrCompleteWord(this, ValStr)
  .Case("diag", OK_Diag)
  .Case("print", OK_Print)
  .Case("dump", OK_Dump)
@@ -166,7 +159,7 @@ QueryRef QueryParser::completeMatcherExp
 
 QueryRef QueryParser::doParse() {
   StringRef CommandStr;
-  ParsedQueryKind QKind = lexOrCompleteWord(CommandStr)
+  ParsedQueryKind QKind = LexOrCompleteWord(this, CommandStr)
   .Case("", PQK_NoOp)
   .Case("help", PQK_Help)
   .Case("m", PQK_Match, /*IsCompletion=*/false)
@@ -221,7 +214,8 @@ QueryRef QueryParser::doParse() {
 
   case PQK_Set: {
 StringRef VarStr;
-ParsedQueryVariable Var = lexOrCompleteWord(VarStr)
+ParsedQueryVariable Var = LexOrCompleteWord(this,
+ VarStr)
   .Case("output", PQV_Output)
   .Case("bind-root", PQV_BindRoot)
  

[PATCH] D43392: [clang-tidy] Add Fuchsia checker for visibility attributes

2018-02-26 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 135944.
juliehockett marked 6 inline comments as done.
juliehockett added a comment.

After discussion, the goal of this checker slightly changed to target 
definitions in header files, rather than declarations. As a result, the check 
now adds the attribute to any definition (declaration or not) that appears in a 
header file.

Also updating tests.


https://reviews.llvm.org/D43392

Files:
  clang-tidy/fuchsia/AddVisibilityCheck.cpp
  clang-tidy/fuchsia/AddVisibilityCheck.h
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-add-visibility.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/fuchsia-add-visibility-pragma.hpp
  test/clang-tidy/fuchsia-add-visibility.cpp
  test/clang-tidy/fuchsia-add-visibility.hpp

Index: test/clang-tidy/fuchsia-add-visibility.hpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-add-visibility.hpp
@@ -0,0 +1,48 @@
+// RUN: %check_clang_tidy %s fuchsia-add-visibility %t -- \
+// RUN:   -config="{CheckOptions: [{key: fuchsia-add-visibility.Names, value: 'foo;bar;baz;foobar;f;g;h;i'}, \
+// RUN:{key: fuchsia-add-visibility.Visibility, value: 'protected'}]}" \
+// RUN:   -header-filter=.* \
+// RUN: -- -std=c++11
+
+void foo();
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: no explicit visibility attribute set for specified function
+// CHECK-FIXES: __attribute__((visibility("protected")))
+
+void foo();
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: no explicit visibility attribute set for specified function
+// CHECK-FIXES: __attribute__((visibility("protected")))
+
+__attribute__((visibility("default")))
+void i();
+// CHECK-MESSAGES: [[@LINE-2]]:1: warning: protected visibility attribute not set for specified function
+// CHECK-FIXES: __attribute__((visibility("protected")))
+
+__attribute__((visibility("default")))
+void i();
+// CHECK-MESSAGES: [[@LINE-2]]:1: warning: protected visibility attribute not set for specified function
+// CHECK-FIXES: __attribute__((visibility("protected")))
+
+__attribute__((visibility("protected")))
+void bar() {}
+
+__attribute__((visibility("protected")))
+void baz();
+void baz() {}
+
+__attribute__((visibility("default")))
+void foobar() {}
+// CHECK-MESSAGES: [[@LINE-2]]:1: warning: protected visibility attribute not set for specified function
+// CHECK-FIXES: __attribute__((visibility("protected")))
+
+__attribute__((visibility("protected"))) 
+void foo(int);
+void foo(double);
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: no explicit visibility attribute set for specified function
+// CHECK-FIXES: __attribute__((visibility("protected")))
+
+template 
+__attribute__((visibility("protected"))) 
+void h(Ty);
+
+template <>
+void h(int);
Index: test/clang-tidy/fuchsia-add-visibility.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-add-visibility.cpp
@@ -0,0 +1,10 @@
+// RUN: clang-tidy %s -checks=-*,fuchsia-add-visibility \
+// RUN:   -config="{CheckOptions: [{key: fuchsia-add-visibility.Names, value: 'foo;bar;baz;foobar;f;g'}, \
+// RUN:{key: fuchsia-add-visibility.Visibility, value: 'protected'}]}" \
+// RUN: -- -std=c++11 | count 0
+
+// Note: this test expects no diagnostics, but FileCheck cannot handle that,
+// hence the use of | count 0.
+
+void foo();
+void foo() {}
Index: test/clang-tidy/fuchsia-add-visibility-pragma.hpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-add-visibility-pragma.hpp
@@ -0,0 +1,36 @@
+// RUN: %check_clang_tidy %s fuchsia-add-visibility %t -- \
+// RUN:   -config="{CheckOptions: [{key: fuchsia-add-visibility.Names, value: 'foo;bar;baz;foobar;f;g'}, \
+// RUN:{key: fuchsia-add-visibility.Visibility, value: 'protected'}]}" \
+// RUN:   -header-filter=.* \
+// RUN: -- -std=c++11
+
+#pragma GCC visibility push(hidden)
+
+void foo();
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: protected visibility attribute not set for specified function
+// CHECK-FIXES: __attribute__((visibility("protected")))
+
+__attribute__((visibility("protected")))
+void bar() {}
+
+__attribute__((visibility("protected")))
+void baz();
+void baz() {}
+
+__attribute__((visibility("default")))
+void foobar() {}
+// CHECK-MESSAGES: [[@LINE-2]]:1: warning: protected visibility attribute not set for specified function
+// CHECK-FIXES: __attribute__((visibility("protected")))
+
+__attribute__((visibility("protected"))) 
+void foo(int);
+void foo(double);
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: protected visibility attribute not set for specified function
+// CHECK-FIXES: __attribute__((visibility("protected")))
+
+template 
+__attribute__((visibility("protected"))) 
+void foo(Ty);
+
+template <>
+void foo(int);
Index: docs/clang-tidy/checks/list.rst
===

[PATCH] D43392: [clang-tidy] Add Fuchsia checker for visibility attributes

2018-02-26 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added inline comments.



Comment at: clang-tidy/fuchsia/AddVisibilityCheck.cpp:52-53
+  Finder->addMatcher(
+  functionDecl(allOf(hasAnyName(SmallVector(Names.begin(),
+  Names.end())),
+ isDefinition(), unless(hasVisibilityAttr(V

aaron.ballman wrote:
> Can you use `makeArrayRef()` rather than using a `SmallVector` that allocates?
Type-wise it gets funky -- `makeArrayRef()` creates an `ArrayRef`, 
and the matcher wants a container of `StringRefs`. Is there a good way to do 
that without allocating?


https://reviews.llvm.org/D43392



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


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

2018-02-26 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett created this revision.
juliehockett added reviewers: aaron.ballman, hokein, ilya-biryukov.
juliehockett added a project: clang-tools-extra.
Herald added subscribers: xazax.hun, mgorny.

Adding a check to restrict specific includes. Given a list of includes that 
should not be used, the check issues a fixit to remove any include on that list 
from the source file.


https://reviews.llvm.org/D43778

Files:
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tidy/fuchsia/RestrictIncludesCheck.cpp
  clang-tidy/fuchsia/RestrictIncludesCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-restrict-includes.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/fuchsia-restrict-includes.cpp

Index: test/clang-tidy/fuchsia-restrict-includes.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-restrict-includes.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s fuchsia-restrict-includes %t \
+// RUN:		-config="{CheckOptions: [{key: fuchsia-restrict-includes.Includes, value: 'b.h;s.h;'}]}" \
+// RUN:   -- -std=c++11 -I %S/Inputs/Headers -isystem %S/Inputs/Headers
+
+#include "a.h"
+#include "b.h"
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: Restricted include found.
+// CHECK-FIXES-NOT: #include "b.h"
+
+#include 
+#include 
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: Restricted include found.
+// CHECK-FIXES-NOT: #include 
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -74,6 +74,7 @@
fuchsia-default-arguments
fuchsia-multiple-inheritance
fuchsia-overloaded-operator
+   fuchsia-restrict-includes
fuchsia-statically-constructed-objects
fuchsia-trailing-return
fuchsia-virtual-inheritance
Index: docs/clang-tidy/checks/fuchsia-restrict-includes.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/fuchsia-restrict-includes.rst
@@ -0,0 +1,27 @@
+.. title:: clang-tidy - fuchsia-restrict-includes
+
+fuchsia-restrict-includes
+=
+
+Checks for restricted headers and suggests their removal.
+
+For example, given the restricted include name 'a.h', if either:
+
+.. code-block:: c++
+
+  #include "a.h"
+
+or
+
+.. code-block:: c++
+
+  #include 
+
+appears, the fix would suggest its removal. 
+  
+Options
+---
+
+.. option:: Includes
+
+   A string containing a comma-separated list of header filenames to restrict. Default is an empty string.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -75,6 +75,11 @@
 
   Warns if a class inherits from multiple classes that are not pure virtual.
 
+- New `fuchsia-restrict-includes
+  `_ check
+
+  Checks for restricted headers and suggests their removal.
+
 - New `fuchsia-statically-constructed-objects
   `_ check
 
Index: clang-tidy/fuchsia/RestrictIncludesCheck.h
===
--- /dev/null
+++ clang-tidy/fuchsia/RestrictIncludesCheck.h
@@ -0,0 +1,44 @@
+//===--- RestrictIncludesCheck.h - clang-tidy-*- 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_CLANG_TIDY_FUCHSIA_RESTRICTHEADERSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTHEADERSCHECK_H
+
+#include "../ClangTidy.h"
+#include "../utils/OptionsUtils.h"
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+/// Checks for restricted headers and suggests their removal.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-restrict-includes.html
+class RestrictIncludesCheck : public ClangTidyCheck {
+ public:
+  RestrictIncludesCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context),
+RestrictedIncludes(utils::options::parseStringList(
+Options.get("Includes", "::std::vector"))) {}
+  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+  std::vector &getRestrictedIncludes() {
+return RestrictedIncludes;
+  }
+
+ private:
+  std::vector RestrictedIncludes;
+};
+
+}  // namespace fuchsia
+}  // namespace tidy
+}  // namespace clang
+
+#endif  // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTHEADERSCHECK_H
Index: clang-tidy/fuchsia/RestrictIncludesCheck.cpp
===

[PATCH] D43780: [Tooling] [1/1] Refactor FrontendActionFactory::create() to return std::unique_ptr<>

2018-02-26 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri created this revision.
lebedev.ri added reviewers: klimek, bkramer, alexfh, pcc.
lebedev.ri added projects: clang, clang-tools-extra.
Herald added subscribers: jkorous-apple, ioeric.

I'm not sure whether there are any principal reasons why it returns raw owning 
pointer,
or it is just a old code that was not updated post-C++11.

I'm not too sure what testing i should do, because `check-all` is not error 
clean here for some reason,
but it does not //appear// asif those failures are related to these changes.

This is Clang-tools-extra part.
Clang part is https://reviews.llvm.org/D43779.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43780

Files:
  clang-move/ClangMove.h
  clang-tidy/ClangTidy.cpp
  clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
  include-fixer/find-all-symbols/FindAllSymbolsAction.h
  modularize/CoverageChecker.cpp
  modularize/Modularize.cpp
  pp-trace/PPTrace.cpp
  unittests/clang-tidy/ClangTidyTest.h
  unittests/clangd/SymbolCollectorTests.cpp

Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -69,7 +69,7 @@
CommentHandler *PragmaHandler)
   : COpts(std::move(COpts)), PragmaHandler(PragmaHandler) {}
 
-  clang::FrontendAction *create() override {
+  std::unique_ptr create() override {
 class WrappedIndexAction : public WrapperFrontendAction {
 public:
   WrappedIndexAction(std::shared_ptr C,
@@ -95,8 +95,9 @@
 index::IndexingOptions::SystemSymbolFilterKind::All;
 IndexOpts.IndexFunctionLocals = false;
 Collector = std::make_shared(COpts);
-return new WrappedIndexAction(Collector, std::move(IndexOpts),
-  PragmaHandler);
+
+return llvm::make_unique(
+Collector, std::move(IndexOpts), PragmaHandler);
   }
 
   std::shared_ptr Collector;
Index: unittests/clang-tidy/ClangTidyTest.h
===
--- unittests/clang-tidy/ClangTidyTest.h
+++ unittests/clang-tidy/ClangTidyTest.h
@@ -107,7 +107,8 @@
   SmallVector, 1> Checks;
   CheckFactory::createChecks(&Context, Checks);
   tooling::ToolInvocation Invocation(
-  Args, new TestClangTidyAction(Checks, Finder, Context), Files.get());
+  Args, llvm::make_unique(Checks, Finder, Context),
+  Files.get());
   InMemoryFileSystem->addFile(Filename, 0,
   llvm::MemoryBuffer::getMemBuffer(Code));
   for (const auto &FileContent : PathsToContent) {
Index: pp-trace/PPTrace.cpp
===
--- pp-trace/PPTrace.cpp
+++ pp-trace/PPTrace.cpp
@@ -139,8 +139,8 @@
std::vector &CallbackCalls)
   : Ignore(Ignore), CallbackCalls(CallbackCalls) {}
 
-  PPTraceAction *create() override {
-return new PPTraceAction(Ignore, CallbackCalls);
+  std::unique_ptr create() override {
+return llvm::make_unique(Ignore, CallbackCalls);
   }
 
 private:
Index: modularize/Modularize.cpp
===
--- modularize/Modularize.cpp
+++ modularize/Modularize.cpp
@@ -722,8 +722,9 @@
   : Entities(Entities), PPTracker(preprocessorTracker),
 HadErrors(HadErrors) {}
 
-  CollectEntitiesAction *create() override {
-return new CollectEntitiesAction(Entities, PPTracker, HadErrors);
+  std::unique_ptr create() override {
+return llvm::make_unique(Entities, PPTracker,
+HadErrors);
   }
 
 private:
@@ -802,8 +803,8 @@
 public:
   CompileCheckFrontendActionFactory() {}
 
-  CompileCheckAction *create() override {
-return new CompileCheckAction();
+  std::unique_ptr create() override {
+return llvm::make_unique();
   }
 };
 
Index: modularize/CoverageChecker.cpp
===
--- modularize/CoverageChecker.cpp
+++ modularize/CoverageChecker.cpp
@@ -129,8 +129,8 @@
   CoverageCheckerFrontendActionFactory(CoverageChecker &Checker)
 : Checker(Checker) {}
 
-  CoverageCheckerAction *create() override {
-return new CoverageCheckerAction(Checker);
+  std::unique_ptr create() override {
+return llvm::make_unique(Checker);
   }
 
 private:
Index: include-fixer/find-all-symbols/FindAllSymbolsAction.h
===
--- include-fixer/find-all-symbols/FindAllSymbolsAction.h
+++ include-fixer/find-all-symbols/FindAllSymbolsAction.h
@@ -48,8 +48,8 @@
   const HeaderMapCollector::RegexHeaderMap *RegexHeaderMap = nullptr)
   : Reporter(Reporter), RegexHeaderMap(RegexHeaderMap) {}
 
-  clang::FrontendAction *create() override {
-return new FindAllSymbolsAction(Reporter, RegexHeaderMap);
+  std::unique_ptr create() override {
+return llvm::make_unique(R

[PATCH] D43779: [Tooling] [0/1] Refactor FrontendActionFactory::create() to return std::unique_ptr<>

2018-02-26 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri created this revision.
lebedev.ri added reviewers: klimek, bkramer, alexfh, pcc.
lebedev.ri added a project: clang.

Noticed during review of https://reviews.llvm.org/D41102.

I'm not sure whether there are any principal reasons why it returns raw owning 
pointer,
or it is just a old code that was not updated post-C++11.

I'm not too sure what testing i should do, because `check-all` is not error 
clean here for some reason,
but it does not //appear// asif those failures are related to these changes.

This is clang part.
Clang-tools-extra part is in the next differential.


Repository:
  rC Clang

https://reviews.llvm.org/D43779

Files:
  docs/LibTooling.rst
  docs/RAVFrontendAction.rst
  include/clang/Tooling/Tooling.h
  lib/Tooling/Tooling.cpp
  tools/clang-refactor/ClangRefactor.cpp
  unittests/AST/EvaluateAsRValueTest.cpp
  unittests/CrossTU/CrossTranslationUnitTest.cpp
  unittests/Sema/CodeCompleteTest.cpp
  unittests/Sema/ExternalSemaSourceTest.cpp
  unittests/Tooling/CommentHandlerTest.cpp
  unittests/Tooling/ExecutionTest.cpp
  unittests/Tooling/RefactoringTest.cpp
  unittests/Tooling/TestVisitor.h
  unittests/Tooling/ToolingTest.cpp

Index: unittests/Tooling/ToolingTest.cpp
===
--- unittests/Tooling/ToolingTest.cpp
+++ unittests/Tooling/ToolingTest.cpp
@@ -64,10 +64,10 @@
 
 TEST(runToolOnCode, FindsNoTopLevelDeclOnEmptyCode) {
   bool FoundTopLevelDecl = false;
-  EXPECT_TRUE(
-  runToolOnCode(new TestAction(llvm::make_unique(
-&FoundTopLevelDecl)),
-""));
+  EXPECT_TRUE(runToolOnCode(
+  llvm::make_unique(
+  llvm::make_unique(&FoundTopLevelDecl)),
+  ""));
   EXPECT_FALSE(FoundTopLevelDecl);
 }
 
@@ -104,17 +104,17 @@
 
 TEST(runToolOnCode, FindsClassDecl) {
   bool FoundClassDeclX = false;
-  EXPECT_TRUE(
-  runToolOnCode(new TestAction(llvm::make_unique(
-&FoundClassDeclX)),
-"class X;"));
+  EXPECT_TRUE(runToolOnCode(
+  llvm::make_unique(
+  llvm::make_unique(&FoundClassDeclX)),
+  "class X;"));
   EXPECT_TRUE(FoundClassDeclX);
 
   FoundClassDeclX = false;
-  EXPECT_TRUE(
-  runToolOnCode(new TestAction(llvm::make_unique(
-&FoundClassDeclX)),
-"class Y;"));
+  EXPECT_TRUE(runToolOnCode(
+  llvm::make_unique(
+  llvm::make_unique(&FoundClassDeclX)),
+  "class Y;"));
   EXPECT_FALSE(FoundClassDeclX);
 }
 
@@ -162,8 +162,8 @@
   Args.push_back("-Idef");
   Args.push_back("-fsyntax-only");
   Args.push_back("test.cpp");
-  clang::tooling::ToolInvocation Invocation(Args, new SyntaxOnlyAction,
-Files.get());
+  clang::tooling::ToolInvocation Invocation(
+  Args, llvm::make_unique(), Files.get());
   InMemoryFileSystem->addFile(
   "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("#include \n"));
   InMemoryFileSystem->addFile("def/abc", 0,
@@ -188,8 +188,8 @@
   Args.push_back("-Idef");
   Args.push_back("-fsyntax-only");
   Args.push_back("test.cpp");
-  clang::tooling::ToolInvocation Invocation(Args, new SyntaxOnlyAction,
-Files.get());
+  clang::tooling::ToolInvocation Invocation(
+  Args, llvm::make_unique(), Files.get());
   InMemoryFileSystem->addFile(
   "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("#include \n"));
   InMemoryFileSystem->addFile("def/abc", 0,
@@ -259,61 +259,64 @@
   std::vector Args = {"-std=c++11"};
   std::vector Args2 = {"-fno-delayed-template-parsing"};
 
-  EXPECT_TRUE(runToolOnCode(new SkipBodyAction,
+  EXPECT_TRUE(runToolOnCode(llvm::make_unique(),
 "int skipMe() { an_error_here }"));
-  EXPECT_FALSE(runToolOnCode(new SkipBodyAction,
+  EXPECT_FALSE(runToolOnCode(llvm::make_unique(),
  "int skipMeNot() { an_error_here }"));
 
   // Test constructors with initializers
   EXPECT_TRUE(runToolOnCodeWithArgs(
-  new SkipBodyAction,
+  llvm::make_unique(),
   "struct skipMe { skipMe() : an_error() { more error } };", Args));
   EXPECT_TRUE(runToolOnCodeWithArgs(
-  new SkipBodyAction, "struct skipMe { skipMe(); };"
-  "skipMe::skipMe() : an_error([](){;}) { more error }",
+  llvm::make_unique(),
+  "struct skipMe { skipMe(); };"
+  "skipMe::skipMe() : an_error([](){;}) { more error }",
   Args));
   EXPECT_TRUE(runToolOnCodeWithArgs(
-  new SkipBodyAction, "struct skipMe { skipMe(); };"
-  "skipMe::skipMe() : an_error{[](){;}} { more error }",
+  llvm::make_unique(),
+  "struct skipMe { skipMe(); };"
+  "skipMe::skipMe() : an_error{[](){;}} { more error }",
   Args));
   EXPECT_TRUE(runToolOnCodeWithArgs(
-  new SkipBodyAction,
+  llvm::make_unique(),
   "struct skipMe { skipMe(); };"
   "skipMe::skipMe() : a(e)>>(), f{}, g() { error 

[libcxx] r326120 - [libcxx] [test] Fix MSVC warnings and errors.

2018-02-26 Thread Stephan T. Lavavej via cfe-commits
Author: stl_msft
Date: Mon Feb 26 12:47:46 2018
New Revision: 326120

URL: http://llvm.org/viewvc/llvm-project?rev=326120&view=rev
Log:
[libcxx] [test] Fix MSVC warnings and errors.

test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp
test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan_init_op.pass.cpp
test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan.pass.cpp
test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op.pass.cpp
test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op_init.pass.cpp
test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp
test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop.pass.cpp
test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop_init.pass.cpp
Fix MSVC x64 truncation warnings.
warning C4267: conversion from 'size_t' to 'int', possible loss of data

test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp
Fix MSVC uninitialized memory warning.
warning C6001: Using uninitialized memory 'vl'.

test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.pass.cpp
Include  for the assert() macro.

Fixes D43273.

Modified:

libcxx/trunk/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan_init_op.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op_init.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop.pass.cpp

libcxx/trunk/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop_init.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp

libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR20855_tuple_ref_binding_diagnostics.pass.cpp

Modified: 
libcxx/trunk/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp?rev=326120&r1=326119&r2=326120&view=diff
==
--- 
libcxx/trunk/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan.pass.cpp
 Mon Feb 26 12:47:46 2018
@@ -55,31 +55,31 @@ test()
 test(Iter(ia), Iter(ia + i), 0, pRes, pRes + i);
 }
 
-int triangle(int n) { return n*(n+1)/2; }
+size_t triangle(size_t n) { return n*(n+1)/2; }
 
 //  Basic sanity
 void basic_tests()
 {
 {
-std::vector v(10);
+std::vector v(10);
 std::fill(v.begin(), v.end(), 3);
-std::exclusive_scan(v.begin(), v.end(), v.begin(), 50);
+std::exclusive_scan(v.begin(), v.end(), v.begin(), size_t{50});
 for (size_t i = 0; i < v.size(); ++i)
-assert(v[i] == 50 + (int) i * 3);
+assert(v[i] == 50 + i * 3);
 }
 
 {
-std::vector v(10);
+std::vector v(10);
 std::iota(v.begin(), v.end(), 0);
-std::exclusive_scan(v.begin(), v.end(), v.begin(), 30);
+std::exclusive_scan(v.begin(), v.end(), v.begin(), size_t{30});
 for (size_t i = 0; i < v.size(); ++i)
 assert(v[i] == 30 + triangle(i-1));
 }
 
 {
-std::vector v(10);
+std::vector v(10);
 std::iota(v.begin(), v.end(), 1);
-std::exclusive_scan(v.begin(), v.end(), v.begin(), 40);
+std::exclusive_scan(v.begin(), v.end(), v.begin(), size_t{40});
 for (size_t i = 0; i < v.size(); ++i)
 assert(v[i] == 40 + triangle(i));
 }

Modified: 
libcxx/trunk/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan_init_op.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan_init_op.pass.cpp?rev=326120&r1=326119&r2=326120&view=diff
==
--- 
libcxx/trunk/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan_init_op.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/numerics/numeric.ops/exclusive.scan/exclusive_scan_init_op.pass.cpp
 Mon Feb 26 12:47:46 2018
@@ -74,11 +74,11 @@ int main()
 {
 std::vector v(10);
 std::iota(v.begin(), v.end(), static_cast(1));
-std::vector res;
+std::vector res;
 std::exclusive_scan(v.begin(), v.end(), std::back_inserter(res), 1, 
std::multiplies<>());
 
 assert(res.size() == 10);
-int j = 1;
+size_t j = 1;
 assert(res[0] == 1);
 

[PATCH] D43392: [clang-tidy] Add Fuchsia checker for visibility attributes

2018-02-26 Thread Jake Ehrlich via Phabricator via cfe-commits
jakehehrlich added inline comments.



Comment at: clang-tidy/fuchsia/AddVisibilityCheck.cpp:26
+
+// AST_MATCHER(FunctionDecl, isInHeaderFile) {
+//   return Node.getExplicitVisibility(NamedDecl::VisibilityForType);

What are these comments doing here?



Comment at: clang-tidy/fuchsia/AddVisibilityCheck.cpp:49
+Vis = DefaultVisibility;
+  else
+   llvm::errs() << "Invalid visibliity attribute: " << VisAttr << "\n";

What about internal?



Comment at: clang-tidy/fuchsia/AddVisibilityCheck.cpp:64
+  Names.end())),
+ unless(hasVisibilityAttr(Vis
+  .bind("no-visibility"),

Something in the list that simply has explicit visibility should pass I think. 
For instance saying you have a blacklist of symbols instead of a whitelist. 
Sometimes internal or hidden might be used but we might want to add "hidden" by 
default. So "Vis" might be DefaultVisibility but we don't want to raise an 
error/change something labeled with internal visibility to hidden.


https://reviews.llvm.org/D43392



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


[PATCH] D43322: Diagnose cases of "return x" that should be "return std::move(x)" for efficiency

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

@rtrieu please take a look?


Repository:
  rC Clang

https://reviews.llvm.org/D43322



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


[PATCH] D43576: Solution to fix PR27066 - Redefinition with same mangled name as another definition (dllexport and uuid)

2018-02-26 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

In https://reviews.llvm.org/D43576#1016588, @rsmith wrote:

> In https://reviews.llvm.org/D43576#1016561, @majnemer wrote:
>
> > Here's my thinking: the `__uuidof` expression literally declares a variable 
> > called `_GUID_ddb47a6a_0f23_11d5_9109_00e0296b75d3` of type `__s_GUID` 
> > which is why it behaves the way it does: https://godbolt.org/g/74FY7U
>
>
> This is an implementation detail leaking, though. no? Note that that is a 
> reserved name.
>
> > I don't think it is reasonable to invent new semantics which are different 
> > from the MSVC ones because we find the MSVC ones inelegant.
>
> I mostly agree, but my point is that this is *not* the MSVC semantics, it's 
> merely an implementation detail that non-conforming code happens to be able 
> to observe. Suppose that `type_info` objects were similarly accessible in 
> MSVC by guessing their mangled names. Would you be arguing that we should 
> inject variables for those too? (And note that it is *nearly* true that 
> `type_info` objects work that way: https://godbolt.org/g/zByFFg -- but the 
> parser gets confused somehow when you reference them.) The only difference I 
> can see between these cases is that the reserved name used for the GUID case 
> happens to not contain any ?s and @s, so happens to be utterable as an 
> identifier.
>
> We should not attempt to be compatible with the cases where MSVC's 
> implementation details happen to leak into user-visible semantics.
>
> > What is the relative upside to a new kind of Decl? Better AST fidelity?
>
> Yes, exactly. The same reason we don't desguar other things any more than we 
> have to.


Before I start implementing this I want to make sure that we are on the same 
page on this.
From your comments it looks like we do not want to create global variables for 
the uuid globals. I tend to agree with that. I do like the idea of creating a 
new Decl type for the uuid declspec. But I want to make sure that I understand 
what you are referring to.
Currently this declaration:
struct
__declspec(uuid("{DDB47A6A-0F23-11D5-9109-00E0296B75D3}"))
S1;

a CXXRecordDecl type is generated with attributes (the uuid being an 
attribute). Are you proposing that instead a new type is generated for S1 say 
something like CXXUuidRecord? And create also a new TagType that corresponds to 
this new Decl?


https://reviews.llvm.org/D43576



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


r326122 - [analyzer] Quickfix: do not overflow in calculating offset in RegionManager

2018-02-26 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Mon Feb 26 13:03:06 2018
New Revision: 326122

URL: http://llvm.org/viewvc/llvm-project?rev=326122&view=rev
Log:
[analyzer] Quickfix: do not overflow in calculating offset in RegionManager

Addresses https://bugs.llvm.org/show_bug.cgi?id=36206

rdar://37159026

A proper fix would be much harder, and would involve changing the
appropriate code in ExprEngine to be aware of the size limitations of
the type used for addressing.

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

Added:
cfe/trunk/test/Analysis/region_store_overflow.c
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
cfe/trunk/test/Analysis/region-store.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp?rev=326122&r1=326121&r2=326122&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp Mon Feb 26 13:03:06 2018
@@ -23,6 +23,11 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/Debug.h"
+
+#include
+
+#define DEBUG_TYPE "MemRegion"
 
 using namespace clang;
 using namespace ento;
@@ -1149,6 +1154,36 @@ const SymbolicRegion *MemRegion::getSymb
   return nullptr;
 }
 
+/// Perform a given operation on two integers, return whether it overflows.
+/// Optionally write the resulting output into \p Res.
+static bool checkedOp(
+int64_t LHS,
+int64_t RHS,
+std::function Op,
+int64_t *Res = nullptr) {
+  llvm::APInt ALHS(/*BitSize=*/64, LHS, /*Signed=*/true);
+  llvm::APInt ARHS(/*BitSize=*/64, RHS, /*Signed=*/true);
+  bool Overflow;
+  llvm::APInt Out = Op(&ALHS, ARHS, Overflow);
+  if (!Overflow && Res)
+*Res = Out.getSExtValue();
+  return Overflow;
+}
+
+static bool checkedAdd(
+int64_t LHS,
+int64_t RHS,
+int64_t *Res=nullptr) {
+  return checkedOp(LHS, RHS, &llvm::APInt::sadd_ov, Res);
+}
+
+static bool checkedMul(
+int64_t LHS,
+int64_t RHS,
+int64_t *Res=nullptr) {
+  return checkedOp(LHS, RHS, &llvm::APInt::smul_ov, Res);
+}
+
 RegionRawOffset ElementRegion::getAsArrayOffset() const {
   CharUnits offset = CharUnits::Zero();
   const ElementRegion *ER = this;
@@ -1176,6 +1211,17 @@ RegionRawOffset ElementRegion::getAsArra
 }
 
 CharUnits size = C.getTypeSizeInChars(elemType);
+
+int64_t Mult;
+bool Overflow = checkedAdd(i, size.getQuantity(), &Mult);
+Overflow |= checkedMul(Mult, offset.getQuantity());
+if (Overflow) {
+  DEBUG(llvm::dbgs() << "MemRegion::getAsArrayOffset: "
+ << "offset overflowing, returning unknown\n");
+
+  return nullptr;
+}
+
 offset += (i * size);
   }
 

Modified: cfe/trunk/test/Analysis/region-store.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/region-store.cpp?rev=326122&r1=326121&r2=326122&view=diff
==
--- cfe/trunk/test/Analysis/region-store.cpp (original)
+++ cfe/trunk/test/Analysis/region-store.cpp Mon Feb 26 13:03:06 2018
@@ -25,4 +25,4 @@ int radar13445834(Derived *Builder, Loc
   Builder->setLoc(l);
   return Builder->accessBase();
   
-}
\ No newline at end of file
+}

Added: cfe/trunk/test/Analysis/region_store_overflow.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/region_store_overflow.c?rev=326122&view=auto
==
--- cfe/trunk/test/Analysis/region_store_overflow.c (added)
+++ cfe/trunk/test/Analysis/region_store_overflow.c Mon Feb 26 13:03:06 2018
@@ -0,0 +1,13 @@
+// REQUIRES: asserts
+// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core -mllvm -debug %s 
2>&1 | FileCheck %s
+
+int **h;
+int overflow_in_memregion(long j) {
+  for (int l = 0;; ++l) {
+if (j - l > 0)
+  return h[j - l][0]; // no-crash
+  }
+  return 0;
+}
+// CHECK: {{.*}}
+// CHECK: MemRegion::getAsArrayOffset: offset overflowing, returning unknown


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


[PATCH] D43218: [analyzer] Quickfix: do not overflow in calculating offset in RegionManager

2018-02-26 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC326122: [analyzer] Quickfix: do not overflow in calculating 
offset in RegionManager (authored by george.karpenkov, committed by ).
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D43218

Files:
  lib/StaticAnalyzer/Core/MemRegion.cpp
  test/Analysis/region-store.cpp
  test/Analysis/region_store_overflow.c


Index: test/Analysis/region-store.cpp
===
--- test/Analysis/region-store.cpp
+++ test/Analysis/region-store.cpp
@@ -25,4 +25,4 @@
   Builder->setLoc(l);
   return Builder->accessBase();
   
-}
\ No newline at end of file
+}
Index: test/Analysis/region_store_overflow.c
===
--- test/Analysis/region_store_overflow.c
+++ test/Analysis/region_store_overflow.c
@@ -0,0 +1,13 @@
+// REQUIRES: asserts
+// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core -mllvm -debug %s 
2>&1 | FileCheck %s
+
+int **h;
+int overflow_in_memregion(long j) {
+  for (int l = 0;; ++l) {
+if (j - l > 0)
+  return h[j - l][0]; // no-crash
+  }
+  return 0;
+}
+// CHECK: {{.*}}
+// CHECK: MemRegion::getAsArrayOffset: offset overflowing, returning unknown
Index: lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- lib/StaticAnalyzer/Core/MemRegion.cpp
+++ lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -23,6 +23,11 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/Debug.h"
+
+#include
+
+#define DEBUG_TYPE "MemRegion"
 
 using namespace clang;
 using namespace ento;
@@ -1149,6 +1154,36 @@
   return nullptr;
 }
 
+/// Perform a given operation on two integers, return whether it overflows.
+/// Optionally write the resulting output into \p Res.
+static bool checkedOp(
+int64_t LHS,
+int64_t RHS,
+std::function Op,
+int64_t *Res = nullptr) {
+  llvm::APInt ALHS(/*BitSize=*/64, LHS, /*Signed=*/true);
+  llvm::APInt ARHS(/*BitSize=*/64, RHS, /*Signed=*/true);
+  bool Overflow;
+  llvm::APInt Out = Op(&ALHS, ARHS, Overflow);
+  if (!Overflow && Res)
+*Res = Out.getSExtValue();
+  return Overflow;
+}
+
+static bool checkedAdd(
+int64_t LHS,
+int64_t RHS,
+int64_t *Res=nullptr) {
+  return checkedOp(LHS, RHS, &llvm::APInt::sadd_ov, Res);
+}
+
+static bool checkedMul(
+int64_t LHS,
+int64_t RHS,
+int64_t *Res=nullptr) {
+  return checkedOp(LHS, RHS, &llvm::APInt::smul_ov, Res);
+}
+
 RegionRawOffset ElementRegion::getAsArrayOffset() const {
   CharUnits offset = CharUnits::Zero();
   const ElementRegion *ER = this;
@@ -1176,6 +1211,17 @@
 }
 
 CharUnits size = C.getTypeSizeInChars(elemType);
+
+int64_t Mult;
+bool Overflow = checkedAdd(i, size.getQuantity(), &Mult);
+Overflow |= checkedMul(Mult, offset.getQuantity());
+if (Overflow) {
+  DEBUG(llvm::dbgs() << "MemRegion::getAsArrayOffset: "
+ << "offset overflowing, returning unknown\n");
+
+  return nullptr;
+}
+
 offset += (i * size);
   }
 


Index: test/Analysis/region-store.cpp
===
--- test/Analysis/region-store.cpp
+++ test/Analysis/region-store.cpp
@@ -25,4 +25,4 @@
   Builder->setLoc(l);
   return Builder->accessBase();
   
-}
\ No newline at end of file
+}
Index: test/Analysis/region_store_overflow.c
===
--- test/Analysis/region_store_overflow.c
+++ test/Analysis/region_store_overflow.c
@@ -0,0 +1,13 @@
+// REQUIRES: asserts
+// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core -mllvm -debug %s 2>&1 | FileCheck %s
+
+int **h;
+int overflow_in_memregion(long j) {
+  for (int l = 0;; ++l) {
+if (j - l > 0)
+  return h[j - l][0]; // no-crash
+  }
+  return 0;
+}
+// CHECK: {{.*}}
+// CHECK: MemRegion::getAsArrayOffset: offset overflowing, returning unknown
Index: lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- lib/StaticAnalyzer/Core/MemRegion.cpp
+++ lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -23,6 +23,11 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/Debug.h"
+
+#include
+
+#define DEBUG_TYPE "MemRegion"
 
 using namespace clang;
 using namespace ento;
@@ -1149,6 +1154,36 @@
   return nullptr;
 }
 
+/// Perform a given operation on two integers, return whether it overflows.
+/// Optionally write the resulting output into \p Res.
+static bool checkedOp(
+int64_t LHS,
+int64_t RHS,
+std::function Op,
+int64_t *Res = nullptr) {
+  llvm::APInt ALHS(/*BitSize=*/

[PATCH] D43773: Implement the container bits of P0805R1

2018-02-26 Thread Tim Song via Phabricator via cfe-commits
tcanens added a comment.

Hmm, for `vector` and `deque`, we define a temporary variable, check that sizes 
match and then use range-and-a-half `equal`:

  const typename vector<_Tp1, _Allocator1>::size_type __sz = __x.size();
  return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), 
__y.begin());

For `list` we check that sizes match and then use range-and-a-half `equal`, but 
don't use a temporary variable:

  return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), 
__y.begin());

For `array` we check that sizes match and then use dual-range `equal`:

  if (_Size1 != _Size2)
  return false;
  return _VSTD::equal(__x.begin(), __x.end(), __y.begin(), __y.end());

Is there a subtle reason for this inconsistency that I'm not seeing?


https://reviews.llvm.org/D43773



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


[PATCH] D43621: [Driver] Allow using a canonical form of '-fuse-ld=' when cross-compiling on Windows.

2018-02-26 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu added a comment.

This change looks good to me, but I think we shouldn't check in an executable 
binary file. Can you create `ld.foo.exe` in the test? Since you don't actually 
run ld.foo.exe, creating that executable should be very easy.


https://reviews.llvm.org/D43621



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


[PATCH] D43783: [OpenCL] Remove block invoke function from emitted block literal struct

2018-02-26 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: b-sumner, Anastasia, bader.
Herald added a subscriber: nhaehnle.

OpenCL runtime tracks the invoke function emitted for
any block expression. Due to restrictions on blocks in
OpenCL (v2.0 s6.12.5), it is always possible to know the
block invoke function when emitting call of block expression
or __enqueue_kernel builtin functions. Since __enqueu_kernel
already has an argument for the invoke function, it is redundant
to have invoke function member in the llvm block literal structure.

This patch removes invoke function from the llvm block literal
structure. It also removes the bitcast of block invoke function
to the "generic block literal type" which is useless for OpenCL.

This will save some space for the kernel argument, and also
eliminate some store instructions.


https://reviews.llvm.org/D43783

Files:
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGOpenCLRuntime.cpp
  lib/CodeGen/CGOpenCLRuntime.h
  test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
  test/CodeGenOpenCL/blocks.cl
  test/CodeGenOpenCL/cl20-device-side-enqueue.cl

Index: test/CodeGenOpenCL/cl20-device-side-enqueue.cl
===
--- test/CodeGenOpenCL/cl20-device-side-enqueue.cl
+++ test/CodeGenOpenCL/cl20-device-side-enqueue.cl
@@ -6,27 +6,25 @@
 typedef void (^bl_t)(local void *);
 typedef struct {int a;} ndrange_t;
 
-// COMMON: %struct.__opencl_block_literal_generic = type { i32, i32, i8 addrspace(4)* }
-
 // For a block global variable, first emit the block literal as a global variable, then emit the block variable itself.
-// COMMON: [[BL_GLOBAL:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32, i8 addrspace(4)* } { i32 {{[0-9]+}}, i32 {{[0-9]+}}, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*, i8 addrspace(3)*)* [[INV_G:@[^ ]+]] to i8*) to i8 addrspace(4)*) }
-// COMMON: @block_G =  addrspace(1) constant void (i8 addrspace(3)*) addrspace(4)* addrspacecast (void (i8 addrspace(3)*) addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* [[BL_GLOBAL]] to void (i8 addrspace(3)*) addrspace(1)*) to void (i8 addrspace(3)*) addrspace(4)*)
+// COMMON: [[BL_GLOBAL:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32 } { i32 {{[0-9]+}}, i32 {{[0-9]+}} }
+// COMMON: @block_G =  addrspace(1) constant void (i8 addrspace(3)*) addrspace(4)* addrspacecast (void (i8 addrspace(3)*) addrspace(1)* bitcast ({ i32, i32 } addrspace(1)* [[BL_GLOBAL]] to void (i8 addrspace(3)*) addrspace(1)*) to void (i8 addrspace(3)*) addrspace(4)*)
 
 // For anonymous blocks without captures, emit block literals as global variable.
-// COMMON: [[BLG1:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32, i8 addrspace(4)* } { i32 {{[0-9]+}}, i32 {{[0-9]+}}, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*, i8 addrspace(3)*)* {{@[^ ]+}} to i8*) to i8 addrspace(4)*) }
-// COMMON: [[BLG2:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32, i8 addrspace(4)* } { i32 {{[0-9]+}}, i32 {{[0-9]+}}, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*, i8 addrspace(3)*)* {{@[^ ]+}} to i8*) to i8 addrspace(4)*) }
-// COMMON: [[BLG3:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32, i8 addrspace(4)* } { i32 {{[0-9]+}}, i32 {{[0-9]+}}, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*, i8 addrspace(3)*)* {{@[^ ]+}} to i8*) to i8 addrspace(4)*) }
-// COMMON: [[BLG4:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32, i8 addrspace(4)* } { i32 {{[0-9]+}}, i32 {{[0-9]+}}, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*, i8 addrspace(3)*)* {{@[^ ]+}} to i8*) to i8 addrspace(4)*) }
-// COMMON: [[BLG5:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32, i8 addrspace(4)* } { i32 {{[0-9]+}}, i32 {{[0-9]+}}, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*, i8 addrspace(3)*)* {{@[^ ]+}} to i8*) to i8 addrspace(4)*) }
-// COMMON: [[BLG6:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32, i8 addrspace(4)* } { i32 {{[0-9]+}}, i32 {{[0-9]+}}, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*, i8 addrspace(3)*, i8 addrspace(3)*, i8 addrspace(3)*)* {{@[^ ]+}} to i8*) to i8 addrspace(4)*) }
-// COMMON: [[BLG7:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32, i8 addrspace(4)* } { i32 {{[0-9]+}}, i32 {{[0-9]+}}, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*, i8 addrspace(3)*)* {{@[^ ]+}} to i8*) to i8 addrspace(4)*) }
-// COMMON: [[BLG8:@__block_literal_global[^ ]*]] = internal addrspace(1) constant { i32, i32, i8 addrspace(4)* } { i32 {{[0-9]+}}, i32 {{[0-9]+}}, i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*)* [[INVG8:@[^ ]+]] to i8*) to i8 addrspace(4)*) }
-// COMMON: [[BLG9:@__block_literal_global[^ ]*]] = internal

r326131 - Revert "[analyzer] Quickfix: do not overflow in calculating offset in RegionManager"

2018-02-26 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Mon Feb 26 13:32:57 2018
New Revision: 326131

URL: http://llvm.org/viewvc/llvm-project?rev=326131&view=rev
Log:
Revert "[analyzer] Quickfix: do not overflow in calculating offset in 
RegionManager"

This reverts commit df306c4c5ab4a6b8d3c47432346d1f9b90c328b4.

Reverting until I can figured out the reasons for failures.

Removed:
cfe/trunk/test/Analysis/region_store_overflow.c
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
cfe/trunk/test/Analysis/region-store.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp?rev=326131&r1=326130&r2=326131&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp Mon Feb 26 13:32:57 2018
@@ -23,11 +23,6 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
 #include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/Debug.h"
-
-#include
-
-#define DEBUG_TYPE "MemRegion"
 
 using namespace clang;
 using namespace ento;
@@ -1154,36 +1149,6 @@ const SymbolicRegion *MemRegion::getSymb
   return nullptr;
 }
 
-/// Perform a given operation on two integers, return whether it overflows.
-/// Optionally write the resulting output into \p Res.
-static bool checkedOp(
-int64_t LHS,
-int64_t RHS,
-std::function Op,
-int64_t *Res = nullptr) {
-  llvm::APInt ALHS(/*BitSize=*/64, LHS, /*Signed=*/true);
-  llvm::APInt ARHS(/*BitSize=*/64, RHS, /*Signed=*/true);
-  bool Overflow;
-  llvm::APInt Out = Op(&ALHS, ARHS, Overflow);
-  if (!Overflow && Res)
-*Res = Out.getSExtValue();
-  return Overflow;
-}
-
-static bool checkedAdd(
-int64_t LHS,
-int64_t RHS,
-int64_t *Res=nullptr) {
-  return checkedOp(LHS, RHS, &llvm::APInt::sadd_ov, Res);
-}
-
-static bool checkedMul(
-int64_t LHS,
-int64_t RHS,
-int64_t *Res=nullptr) {
-  return checkedOp(LHS, RHS, &llvm::APInt::smul_ov, Res);
-}
-
 RegionRawOffset ElementRegion::getAsArrayOffset() const {
   CharUnits offset = CharUnits::Zero();
   const ElementRegion *ER = this;
@@ -1211,17 +1176,6 @@ RegionRawOffset ElementRegion::getAsArra
 }
 
 CharUnits size = C.getTypeSizeInChars(elemType);
-
-int64_t Mult;
-bool Overflow = checkedAdd(i, size.getQuantity(), &Mult);
-Overflow |= checkedMul(Mult, offset.getQuantity());
-if (Overflow) {
-  DEBUG(llvm::dbgs() << "MemRegion::getAsArrayOffset: "
- << "offset overflowing, returning unknown\n");
-
-  return nullptr;
-}
-
 offset += (i * size);
   }
 

Modified: cfe/trunk/test/Analysis/region-store.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/region-store.cpp?rev=326131&r1=326130&r2=326131&view=diff
==
--- cfe/trunk/test/Analysis/region-store.cpp (original)
+++ cfe/trunk/test/Analysis/region-store.cpp Mon Feb 26 13:32:57 2018
@@ -25,4 +25,4 @@ int radar13445834(Derived *Builder, Loc
   Builder->setLoc(l);
   return Builder->accessBase();
   
-}
+}
\ No newline at end of file

Removed: cfe/trunk/test/Analysis/region_store_overflow.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/region_store_overflow.c?rev=326130&view=auto
==
--- cfe/trunk/test/Analysis/region_store_overflow.c (original)
+++ cfe/trunk/test/Analysis/region_store_overflow.c (removed)
@@ -1,13 +0,0 @@
-// REQUIRES: asserts
-// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core -mllvm -debug %s 
2>&1 | FileCheck %s
-
-int **h;
-int overflow_in_memregion(long j) {
-  for (int l = 0;; ++l) {
-if (j - l > 0)
-  return h[j - l][0]; // no-crash
-  }
-  return 0;
-}
-// CHECK: {{.*}}
-// CHECK: MemRegion::getAsArrayOffset: offset overflowing, returning unknown


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


[PATCH] D43392: [clang-tidy] Add Fuchsia checker for visibility attributes

2018-02-26 Thread Jake Ehrlich via Phabricator via cfe-commits
jakehehrlich added a comment.

Can you add a test for when #pragma GCC visibility push(hidden) is used and the 
visibility attribute is hidden?


https://reviews.llvm.org/D43392



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


[PATCH] D42644: [asan] Intercept std::rethrow_exception indirectly.

2018-02-26 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCRT326132: [asan] Intercept std::rethrow_exception indirectly 
(authored by vitalybuka, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42644?vs=132990&id=135965#toc

Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D42644

Files:
  lib/asan/asan_interceptors.cc
  lib/asan/asan_interceptors.h
  test/asan/TestCases/intercept-rethrow-exception.cc

Index: test/asan/TestCases/intercept-rethrow-exception.cc
===
--- test/asan/TestCases/intercept-rethrow-exception.cc
+++ test/asan/TestCases/intercept-rethrow-exception.cc
@@ -0,0 +1,64 @@
+// Regression test for
+// https://bugs.llvm.org/show_bug.cgi?id=32434
+
+// RUN: %clangxx_asan -O0 %s -o %t
+// RUN: %run %t
+
+#include 
+#include 
+#include 
+
+namespace {
+
+// Not instrumented because std::rethrow_exception is a [[noreturn]] function,
+// for which the compiler would emit a call to __asan_handle_no_return which
+// unpoisons the stack.
+// We emulate here some code not compiled with asan. This function is not
+// [[noreturn]] because the scenario we're emulating doesn't always throw. If it
+// were [[noreturn]], the calling code would emit a call to
+// __asan_handle_no_return.
+void __attribute__((no_sanitize("address")))
+uninstrumented_rethrow_exception(std::exception_ptr const &exc_ptr) {
+  std::rethrow_exception(exc_ptr);
+}
+
+char *poisoned1;
+char *poisoned2;
+
+// Create redzones for stack variables in shadow memory and call
+// std::rethrow_exception which should unpoison the entire stack.
+void create_redzones_and_throw(std::exception_ptr const &exc_ptr) {
+  char a[100];
+  poisoned1 = a - 1;
+  poisoned2 = a + sizeof(a);
+  assert(__asan_address_is_poisoned(poisoned1));
+  assert(__asan_address_is_poisoned(poisoned2));
+  uninstrumented_rethrow_exception(exc_ptr);
+}
+
+} // namespace
+
+// Check that std::rethrow_exception is intercepted by asan and the interception
+// unpoisons the stack.
+// If std::rethrow_exception is NOT intercepted, then calls to this function
+// from instrumented code will still unpoison the stack because
+// std::rethrow_exception is a [[noreturn]] function and any [[noreturn]]
+// function call will be instrumented with __asan_handle_no_return.
+// However, calls to std::rethrow_exception from UNinstrumented code will not
+// unpoison the stack, so we need to intercept std::rethrow_exception to
+// unpoison the stack.
+int main() {
+  // In some implementations of std::make_exception_ptr, e.g. libstdc++ prior to
+  // gcc 7, this function calls __cxa_throw. The __cxa_throw is intercepted by
+  // asan to unpoison the entire stack; since this test essentially tests that
+  // the stack is unpoisoned by a call to std::rethrow_exception, we need to
+  // generate the exception_ptr BEFORE we have the local variables poison the
+  // stack.
+  std::exception_ptr my_exception_ptr = std::make_exception_ptr("up");
+
+  try {
+create_redzones_and_throw(my_exception_ptr);
+  } catch(char const *) {
+assert(!__asan_region_is_poisoned(poisoned1, poisoned2 - poisoned1 + 1));
+  }
+}
Index: lib/asan/asan_interceptors.cc
===
--- lib/asan/asan_interceptors.cc
+++ lib/asan/asan_interceptors.cc
@@ -33,6 +33,11 @@
 #include "sanitizer_common/sanitizer_posix.h"
 #endif
 
+#if ASAN_INTERCEPT__UNWIND_RAISEEXCEPTION || \
+ASAN_INTERCEPT__SJLJ_UNWIND_RAISEEXCEPTION
+#include 
+#endif
+
 #if defined(__i386) && SANITIZER_LINUX
 #define ASAN_PTHREAD_CREATE_VERSION "GLIBC_2.1"
 #elif defined(__mips__) && SANITIZER_LINUX
@@ -319,6 +324,32 @@
 }
 #endif
 
+#if ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION
+INTERCEPTOR(void, __cxa_rethrow_primary_exception, void *a) {
+  CHECK(REAL(__cxa_rethrow_primary_exception));
+  __asan_handle_no_return();
+  REAL(__cxa_rethrow_primary_exception)(a);
+}
+#endif
+
+#if ASAN_INTERCEPT__UNWIND_RAISEEXCEPTION
+INTERCEPTOR(_Unwind_Reason_Code, _Unwind_RaiseException,
+struct _Unwind_Exception *object) {
+  CHECK(REAL(_Unwind_RaiseException));
+  __asan_handle_no_return();
+  return REAL(_Unwind_RaiseException)(object);
+}
+#endif
+
+#if ASAN_INTERCEPT__SJLJ_UNWIND_RAISEEXCEPTION
+INTERCEPTOR(_Unwind_Reason_Code, _Unwind_SjLj_RaiseException,
+struct _Unwind_Exception *object) {
+  CHECK(REAL(_Unwind_SjLj_RaiseException));
+  __asan_handle_no_return();
+  return REAL(_Unwind_SjLj_RaiseException)(object);
+}
+#endif
+
 #if ASAN_INTERCEPT_INDEX
 # if ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX
 INTERCEPTOR(char*, index, const char *string, int c)
@@ -599,6 +630,17 @@
 #if ASAN_INTERCEPT___CXA_THROW
   ASAN_INTERCEPT_FUNC(__cxa_throw);
 #endif
+#if ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION
+  ASAN_INTERCEPT_FUNC(__cxa_rethrow_primary_exception);
+#endif
+  // Indirectly intercept std::rethrow_exception.
+#if ASAN_INTERCEPT__UNWIND_R

[PATCH] D43500: [clang-tidy]: modernize-use-default-member-init: Remove trailing comma and colon.

2018-02-26 Thread Jeremy Demeule via Phabricator via cfe-commits
jdemeule added inline comments.



Comment at: unittests/clang-tidy/ClangTidyTest.h:159-160
+  CleannedReplacements = std::move(FormattedReplacements);
+  if (!CleannedReplacements)
+llvm_unreachable("!CleannedReplacements");
+} else {

aaron.ballman wrote:
> This smells like it should be an assert rather than an unreachable.
Is returning an empty string OK?
This should let the assertion on the test do the job.



Comment at: unittests/clang-tidy/ClangTidyTest.h:167
+if (!Result) {
+  // FIXME: propogate the error.
+  llvm::consumeError(Result.takeError());

aaron.ballman wrote:
> Are you intending to implement this fixme in this patch?
I suggest to remove the copy/paste containing the fixme. Is-it OK?
Maybe with some hints I can suggest a fix for this later.


https://reviews.llvm.org/D43500



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


[PATCH] D43621: [Driver] Allow using a canonical form of '-fuse-ld=' when cross-compiling on Windows.

2018-02-26 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

In https://reviews.llvm.org/D43621#1019724, @ruiu wrote:

> This change looks good to me, but I think we shouldn't check in an executable 
> binary file. Can you create `ld.foo.exe` in the test? Since you don't 
> actually run ld.foo.exe, creating that executable should be very easy.


If I read the diff correctly, it is an empty file, so this should just work.


https://reviews.llvm.org/D43621



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


[PATCH] D43621: [Driver] Allow using a canonical form of '-fuse-ld=' when cross-compiling on Windows.

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

lgtm


https://reviews.llvm.org/D43621



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


r326136 - [analyzer] Exploration strategy prioritizing unexplored nodes first

2018-02-26 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Mon Feb 26 14:14:18 2018
New Revision: 326136

URL: http://llvm.org/viewvc/llvm-project?rev=326136&view=rev
Log:
[analyzer] Exploration strategy prioritizing unexplored nodes first

See D42775 for discussion.  Turns out, just exploring nodes which
weren't explored first is not quite enough, as e.g. the first quick
traversal resulting in a report can mark everything as "visited", and
then subsequent traversals of the same region will get all the pitfalls
of DFS.
Priority queue-based approach in comparison shows much greater
increase in coverage and even performance, without sacrificing memory.

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/WorkList.h
cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp
cfe/trunk/test/Analysis/exploration_order/prefer_unexplored.cc

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h?rev=326136&r1=326135&r2=326136&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h Mon Feb 26 
14:14:18 2018
@@ -192,6 +192,7 @@ public:
 DFS,
 BFS,
 UnexploredFirst,
+UnexploredFirstQueue,
 BFSBlockDFSContents,
 NotSet
   };

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/WorkList.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/WorkList.h?rev=326136&r1=326135&r2=326136&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/WorkList.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/WorkList.h Mon 
Feb 26 14:14:18 2018
@@ -84,6 +84,7 @@ public:
   static std::unique_ptr makeBFS();
   static std::unique_ptr makeBFSBlockDFSContents();
   static std::unique_ptr makeUnexploredFirst();
+  static std::unique_ptr makeUnexploredFirstPriorityQueue();
 };
 
 } // end GR namespace

Modified: cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp?rev=326136&r1=326135&r2=326136&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp Mon Feb 26 14:14:18 
2018
@@ -68,6 +68,8 @@ AnalyzerOptions::getExplorationStrategy(
 .Case("bfs", ExplorationStrategyKind::BFS)
 .Case("unexplored_first",
   ExplorationStrategyKind::UnexploredFirst)
+.Case("unexplored_first_queue",
+  ExplorationStrategyKind::UnexploredFirstQueue)
 .Case("bfs_block_dfs_contents",
   ExplorationStrategyKind::BFSBlockDFSContents)
 .Default(ExplorationStrategyKind::NotSet);

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp?rev=326136&r1=326135&r2=326136&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp Mon Feb 26 14:14:18 2018
@@ -20,7 +20,9 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/ADT/PriorityQueue.h"
 
 using namespace clang;
 using namespace ento;
@@ -192,6 +194,66 @@ std::unique_ptr WorkList::make
   return llvm::make_unique();
 }
 
+class UnexploredFirstPriorityQueue : public WorkList {
+  typedef unsigned BlockID;
+  typedef std::pair LocIdentifier;
+
+  // How many times each location was visited.
+  // Is signed because we negate it later in order to have a reversed
+  // comparison.
+  typedef llvm::DenseMap VisitedTimesMap;
+
+  // Compare by number of times the location was visited first (negated
+  // to prefer less often visited locations), then by insertion time (prefer
+  // expanding nodes inserted sooner first).
+  typedef std::pair QueuePriority;
+  typedef std::pair QueueItem;
+
+  struct ExplorationComparator {
+bool operator() (const QueueItem &LHS, const QueueItem &RHS) {
+  return LHS.second < RHS.second;
+}
+  };
+
+  // Number of inserted nodes, used to emulate DFS ordering in the priority
+  // queue when insertions are equal.
+  unsigned long Counter = 0;
+
+  // Number of times 

r326135 - [analyzer] Do not analyze bison-generated files

2018-02-26 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Mon Feb 26 14:14:16 2018
New Revision: 326135

URL: http://llvm.org/viewvc/llvm-project?rev=326135&view=rev
Log:
[analyzer] Do not analyze bison-generated files

Bison/YACC generated files result in a very large number of (presumably)
false positives from the analyzer.
These false positives are "true" in a sense of the information analyzer
sees: assuming that the lexer can return any token at any point a number
of uninitialized reads does occur.
(naturally, the analyzer can not capture a complex invariant that
certain tokens can only occur under certain conditions).

Current fix simply stops analysis on those files.
I have examined a very large number of such auto-generated files, and
they do all start with such a comment.
Conversely, user code is very unlikely to contain such a comment.

rdar://33608161

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

Added:
cfe/trunk/test/Analysis/yaccignore.c
Modified:
cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp?rev=326135&r1=326134&r2=326135&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp Mon Feb 26 
14:14:16 2018
@@ -389,7 +389,10 @@ private:
 
   /// \brief Check if we should skip (not analyze) the given function.
   AnalysisMode getModeForDecl(Decl *D, AnalysisMode Mode);
+  void runAnalysisOnTranslationUnit(ASTContext &C);
 
+  /// Print \p S to stderr if \c Opts->AnalyzerDisplayProgress is set.
+  void reportAnalyzerProgress(StringRef S);
 };
 } // end anonymous namespace
 
@@ -511,51 +514,72 @@ void AnalysisConsumer::HandleDeclsCallGr
   }
 }
 
+static bool isBisonFile(ASTContext &C) {
+  const SourceManager &SM = C.getSourceManager();
+  FileID FID = SM.getMainFileID();
+  StringRef Buffer = SM.getBuffer(FID)->getBuffer();
+  if (Buffer.startswith("/* A Bison parser, made by"))
+return true;
+  return false;
+}
+
+void AnalysisConsumer::runAnalysisOnTranslationUnit(ASTContext &C) {
+  BugReporter BR(*Mgr);
+  TranslationUnitDecl *TU = C.getTranslationUnitDecl();
+  checkerMgr->runCheckersOnASTDecl(TU, *Mgr, BR);
+
+  // Run the AST-only checks using the order in which functions are defined.
+  // If inlining is not turned on, use the simplest function order for path
+  // sensitive analyzes as well.
+  RecVisitorMode = AM_Syntax;
+  if (!Mgr->shouldInlineCall())
+RecVisitorMode |= AM_Path;
+  RecVisitorBR = &BR;
+
+  // Process all the top level declarations.
+  //
+  // Note: TraverseDecl may modify LocalTUDecls, but only by appending more
+  // entries.  Thus we don't use an iterator, but rely on LocalTUDecls
+  // random access.  By doing so, we automatically compensate for iterators
+  // possibly being invalidated, although this is a bit slower.
+  const unsigned LocalTUDeclsSize = LocalTUDecls.size();
+  for (unsigned i = 0 ; i < LocalTUDeclsSize ; ++i) {
+TraverseDecl(LocalTUDecls[i]);
+  }
+
+  if (Mgr->shouldInlineCall())
+HandleDeclsCallGraph(LocalTUDeclsSize);
+
+  // After all decls handled, run checkers on the entire TranslationUnit.
+  checkerMgr->runCheckersOnEndOfTranslationUnit(TU, *Mgr, BR);
+
+  RecVisitorBR = nullptr;
+}
+
+void AnalysisConsumer::reportAnalyzerProgress(StringRef S) {
+  if (Opts->AnalyzerDisplayProgress)
+llvm::errs() << S;
+}
+
 void AnalysisConsumer::HandleTranslationUnit(ASTContext &C) {
+
   // Don't run the actions if an error has occurred with parsing the file.
   DiagnosticsEngine &Diags = PP.getDiagnostics();
   if (Diags.hasErrorOccurred() || Diags.hasFatalErrorOccurred())
 return;
 
-  // Don't analyze if the user explicitly asked for no checks to be performed
-  // on this file.
-  if (Opts->DisableAllChecks)
-return;
-
-  {
-if (TUTotalTimer) TUTotalTimer->startTimer();
-
-// Introduce a scope to destroy BR before Mgr.
-BugReporter BR(*Mgr);
-TranslationUnitDecl *TU = C.getTranslationUnitDecl();
-checkerMgr->runCheckersOnASTDecl(TU, *Mgr, BR);
-
-// Run the AST-only checks using the order in which functions are defined.
-// If inlining is not turned on, use the simplest function order for path
-// sensitive analyzes as well.
-RecVisitorMode = AM_Syntax;
-if (!Mgr->shouldInlineCall())
-  RecVisitorMode |= AM_Path;
-RecVisitorBR = &BR;
-
-// Process all the top level declarations.
-//
-// Note: TraverseDecl may modify LocalTUDecls, but only by appending more
-// entries.  Thus we don't use an iterator, but rely on LocalTUDecls
-// random access.  By doing so, we automatically compensate for iterators
-// possibly being invalidated, although this is a bit slower.
-const unsigned LocalTUDeclsSize = LocalTUDecls.s

[PATCH] D43354: [analyzer] Exploration strategy prioritizing unexplored nodes first

2018-02-26 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC326136: [analyzer] Exploration strategy prioritizing 
unexplored nodes first (authored by george.karpenkov, committed by ).
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D43354

Files:
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  include/clang/StaticAnalyzer/Core/PathSensitive/WorkList.h
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  lib/StaticAnalyzer/Core/CoreEngine.cpp
  test/Analysis/exploration_order/prefer_unexplored.cc

Index: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
===
--- include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -192,6 +192,7 @@
 DFS,
 BFS,
 UnexploredFirst,
+UnexploredFirstQueue,
 BFSBlockDFSContents,
 NotSet
   };
Index: include/clang/StaticAnalyzer/Core/PathSensitive/WorkList.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/WorkList.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/WorkList.h
@@ -84,6 +84,7 @@
   static std::unique_ptr makeBFS();
   static std::unique_ptr makeBFSBlockDFSContents();
   static std::unique_ptr makeUnexploredFirst();
+  static std::unique_ptr makeUnexploredFirstPriorityQueue();
 };
 
 } // end GR namespace
Index: test/Analysis/exploration_order/prefer_unexplored.cc
===
--- test/Analysis/exploration_order/prefer_unexplored.cc
+++ test/Analysis/exploration_order/prefer_unexplored.cc
@@ -1,4 +1,5 @@
 // RUN: %clang_analyze_cc1 -w -analyzer-checker=core -analyzer-config exploration_strategy=unexplored_first -analyzer-output=text -verify %s | FileCheck %s
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=core -analyzer-config exploration_strategy=unexplored_first_queue -analyzer-output=text -verify %s | FileCheck %s
 
 extern int coin();
 
Index: lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
===
--- lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -68,6 +68,8 @@
 .Case("bfs", ExplorationStrategyKind::BFS)
 .Case("unexplored_first",
   ExplorationStrategyKind::UnexploredFirst)
+.Case("unexplored_first_queue",
+  ExplorationStrategyKind::UnexploredFirstQueue)
 .Case("bfs_block_dfs_contents",
   ExplorationStrategyKind::BFSBlockDFSContents)
 .Default(ExplorationStrategyKind::NotSet);
Index: lib/StaticAnalyzer/Core/CoreEngine.cpp
===
--- lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -20,7 +20,9 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/Support/Casting.h"
+#include "llvm/ADT/PriorityQueue.h"
 
 using namespace clang;
 using namespace ento;
@@ -192,6 +194,66 @@
   return llvm::make_unique();
 }
 
+class UnexploredFirstPriorityQueue : public WorkList {
+  typedef unsigned BlockID;
+  typedef std::pair LocIdentifier;
+
+  // How many times each location was visited.
+  // Is signed because we negate it later in order to have a reversed
+  // comparison.
+  typedef llvm::DenseMap VisitedTimesMap;
+
+  // Compare by number of times the location was visited first (negated
+  // to prefer less often visited locations), then by insertion time (prefer
+  // expanding nodes inserted sooner first).
+  typedef std::pair QueuePriority;
+  typedef std::pair QueueItem;
+
+  struct ExplorationComparator {
+bool operator() (const QueueItem &LHS, const QueueItem &RHS) {
+  return LHS.second < RHS.second;
+}
+  };
+
+  // Number of inserted nodes, used to emulate DFS ordering in the priority
+  // queue when insertions are equal.
+  unsigned long Counter = 0;
+
+  // Number of times a current location was reached.
+  VisitedTimesMap NumReached;
+
+  // The top item is the largest one.
+  llvm::PriorityQueue, ExplorationComparator>
+  queue;
+
+public:
+  bool hasWork() const override {
+return !queue.empty();
+  }
+
+  void enqueue(const WorkListUnit &U) override {
+const ExplodedNode *N = U.getNode();
+unsigned NumVisited = 0;
+if (auto BE = N->getLocation().getAs()) {
+  LocIdentifier LocId = std::make_pair(
+  BE->getBlock()->getBlockID(), N->getStackFrame());
+  NumVisited = NumReached[LocId]++;
+}
+
+queue.push(std::make_pair(U, std::make_pair(-NumVisited, ++Counter)));
+  }
+
+  WorkListUnit dequeue() override {
+QueueItem U = queue.top();
+queue.pop();
+return U.first;
+  }
+};
+
+std::unique_ptr WorkList::makeUnexplored

[PATCH] D43421: [analyzer] Do not analyze bison-generated files

2018-02-26 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC326135: [analyzer] Do not analyze bison-generated files 
(authored by george.karpenkov, committed by ).
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D43421

Files:
  lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
  test/Analysis/yaccignore.c

Index: test/Analysis/yaccignore.c
===
--- test/Analysis/yaccignore.c
+++ test/Analysis/yaccignore.c
@@ -0,0 +1,13 @@
+/* A Bison parser, made by GNU Bison 1.875.  */
+
+// RUN: rm -rf %t.plist
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=plist -o %t.plist -verify %s
+// RUN: FileCheck --input-file=%t.plist %s
+
+// expected-no-diagnostics
+int foo() {
+  int *x = 0;
+  return *x; // no-warning
+}
+
+// CHECK:   diagnostics
Index: lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===
--- lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -389,7 +389,10 @@
 
   /// \brief Check if we should skip (not analyze) the given function.
   AnalysisMode getModeForDecl(Decl *D, AnalysisMode Mode);
+  void runAnalysisOnTranslationUnit(ASTContext &C);
 
+  /// Print \p S to stderr if \c Opts->AnalyzerDisplayProgress is set.
+  void reportAnalyzerProgress(StringRef S);
 };
 } // end anonymous namespace
 
@@ -511,51 +514,72 @@
   }
 }
 
+static bool isBisonFile(ASTContext &C) {
+  const SourceManager &SM = C.getSourceManager();
+  FileID FID = SM.getMainFileID();
+  StringRef Buffer = SM.getBuffer(FID)->getBuffer();
+  if (Buffer.startswith("/* A Bison parser, made by"))
+return true;
+  return false;
+}
+
+void AnalysisConsumer::runAnalysisOnTranslationUnit(ASTContext &C) {
+  BugReporter BR(*Mgr);
+  TranslationUnitDecl *TU = C.getTranslationUnitDecl();
+  checkerMgr->runCheckersOnASTDecl(TU, *Mgr, BR);
+
+  // Run the AST-only checks using the order in which functions are defined.
+  // If inlining is not turned on, use the simplest function order for path
+  // sensitive analyzes as well.
+  RecVisitorMode = AM_Syntax;
+  if (!Mgr->shouldInlineCall())
+RecVisitorMode |= AM_Path;
+  RecVisitorBR = &BR;
+
+  // Process all the top level declarations.
+  //
+  // Note: TraverseDecl may modify LocalTUDecls, but only by appending more
+  // entries.  Thus we don't use an iterator, but rely on LocalTUDecls
+  // random access.  By doing so, we automatically compensate for iterators
+  // possibly being invalidated, although this is a bit slower.
+  const unsigned LocalTUDeclsSize = LocalTUDecls.size();
+  for (unsigned i = 0 ; i < LocalTUDeclsSize ; ++i) {
+TraverseDecl(LocalTUDecls[i]);
+  }
+
+  if (Mgr->shouldInlineCall())
+HandleDeclsCallGraph(LocalTUDeclsSize);
+
+  // After all decls handled, run checkers on the entire TranslationUnit.
+  checkerMgr->runCheckersOnEndOfTranslationUnit(TU, *Mgr, BR);
+
+  RecVisitorBR = nullptr;
+}
+
+void AnalysisConsumer::reportAnalyzerProgress(StringRef S) {
+  if (Opts->AnalyzerDisplayProgress)
+llvm::errs() << S;
+}
+
 void AnalysisConsumer::HandleTranslationUnit(ASTContext &C) {
+
   // Don't run the actions if an error has occurred with parsing the file.
   DiagnosticsEngine &Diags = PP.getDiagnostics();
   if (Diags.hasErrorOccurred() || Diags.hasFatalErrorOccurred())
 return;
 
-  // Don't analyze if the user explicitly asked for no checks to be performed
-  // on this file.
-  if (Opts->DisableAllChecks)
-return;
-
-  {
-if (TUTotalTimer) TUTotalTimer->startTimer();
-
-// Introduce a scope to destroy BR before Mgr.
-BugReporter BR(*Mgr);
-TranslationUnitDecl *TU = C.getTranslationUnitDecl();
-checkerMgr->runCheckersOnASTDecl(TU, *Mgr, BR);
-
-// Run the AST-only checks using the order in which functions are defined.
-// If inlining is not turned on, use the simplest function order for path
-// sensitive analyzes as well.
-RecVisitorMode = AM_Syntax;
-if (!Mgr->shouldInlineCall())
-  RecVisitorMode |= AM_Path;
-RecVisitorBR = &BR;
-
-// Process all the top level declarations.
-//
-// Note: TraverseDecl may modify LocalTUDecls, but only by appending more
-// entries.  Thus we don't use an iterator, but rely on LocalTUDecls
-// random access.  By doing so, we automatically compensate for iterators
-// possibly being invalidated, although this is a bit slower.
-const unsigned LocalTUDeclsSize = LocalTUDecls.size();
-for (unsigned i = 0 ; i < LocalTUDeclsSize ; ++i) {
-  TraverseDecl(LocalTUDecls[i]);
-}
-
-if (Mgr->shouldInlineCall())
-  HandleDeclsCallGraph(LocalTUDeclsSize);
-
-// After all decls handled, run checkers on the entire TranslationUnit.
-checkerMgr->runCheckersOnEndOfTranslationUnit(TU, *Mgr, BR);
+  if (TUTotalTimer) TUTotalTimer->startTimer();
 
-RecVisito

[PATCH] D41880: Adding nocf_check attribute for cf-protection fine tuning

2018-02-26 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: include/clang/CodeGen/CGFunctionInfo.h:519
+  /// Whether this function has nocf_check attribute.
+  unsigned NoCfCheck : 1;
+

oren_ben_simhon wrote:
> aaron.ballman wrote:
> > This is unfortunate -- it bumps the bit-field over 32 bits. Can the bit be 
> > stolen from elsewhere?
> The field is orthogonal to the other fields moreover i think that double 
> meaning of the same field will lead to future bugs. The class is not a 
> compact packed structure, so i don't feel it worth the confusion.
The class packs its fields for space savings because it's used fairly 
frequently; if we can keep the size from having to use another allocation unit, 
that's better. I wasn't suggesting we make a bit have double meaning, I was 
wondering if we could reduce the size of one of the other fields. For instance, 
I'd be surprised if we need all 8 bits for calling conventions, so we might be 
able to reduce that to a 7-bit field.



Comment at: lib/Sema/SemaDeclAttr.cpp:1979-1980
+static void handleNoCfCheckAttr(Sema &S, Decl *D, const AttributeList &Attrs) {
+  if (!S.getLangOpts().CFProtectionBranch)
+S.Diag(Attrs.getLoc(), diag::warn_nocf_check_attribute_ignored);
+  else

oren_ben_simhon wrote:
> aaron.ballman wrote:
> > Can you use the `LangOpts` field to specify this in Attr.td? Then you can 
> > go back to the simple handler.
> When using LangOpts field in Attr.td, the diagnostic warning will not be 
> descriptive as i use here (use -fcf-protection flag...).
That's true, and this code is fine for now. However, it does suggest that the 
declarative handler could be improved to support this sort of thing -- the same 
issue is present with *all* attributes gated on a language option.



Comment at: test/Sema/attr-nocf_check.cpp:1
+// RUN: %clang_cc1 -verify -fcf-protection=branch -target-feature +ibt 
-fsyntax-only %s
+

oren_ben_simhon wrote:
> aaron.ballman wrote:
> > aaron.ballman wrote:
> > > For better test coverage, you can switch to the `[[gnu::nocf_check]]` 
> > > spelling in this file and pass `-std=c++11`
> > This one also likely needs an explicit triple.
> Since it doesn't test the functionality of this specific attribute, I believe 
> it is an overkill to switch to [[gnu::nocf_check]] spelling.
> Since it doesn't test the functionality of this specific attribute, I believe 
> it is an overkill to switch to [[gnu::nocf_check]] spelling.

C++ attribute spellings have slightly different code paths than GNU attribute 
spellings, so the test isn't overkill. Also, this is a C++ test file that 
already uses C++11, so adding the C++11 spelling is an improvement over using 
the GNU spelling (that's already covered with C tests).

It's not critical, but it's still a strict improvement.


Repository:
  rL LLVM

https://reviews.llvm.org/D41880



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


[PATCH] D43787: Fix which Darwin versions have ObjC runtime with full subscripting support.

2018-02-26 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai created this revision.
vsapsai added reviewers: vsk, kubamracek.
Herald added a subscriber: jkorous-apple.

Update min deployment target in some tests so that they don't try
to link against libarclite and don't fail when it's not available.

rdar://problem/29253617


https://reviews.llvm.org/D43787

Files:
  clang/include/clang/Basic/ObjCRuntime.h
  clang/test/Driver/arclite-link.c
  compiler-rt/test/lit.common.cfg
  compiler-rt/test/tsan/Darwin/norace-objcxx-run-time.mm


Index: compiler-rt/test/tsan/Darwin/norace-objcxx-run-time.mm
===
--- compiler-rt/test/tsan/Darwin/norace-objcxx-run-time.mm
+++ compiler-rt/test/tsan/Darwin/norace-objcxx-run-time.mm
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan %s -lc++ -fobjc-arc -lobjc -o %t -framework Foundation
+// RUN: %clang_tsan %s -lc++ -fobjc-arc -lobjc -o %t -framework Foundation 
%darwin_min_target_with_full_runtime_arc_support
 // RUN: %run %t 2>&1 | FileCheck %s
 
 // Check that we do not report races between:
Index: compiler-rt/test/lit.common.cfg
===
--- compiler-rt/test/lit.common.cfg
+++ compiler-rt/test/lit.common.cfg
@@ -197,8 +197,14 @@
 pass
 
   config.substitutions.append( ("%macos_min_target_10_11", 
"-mmacosx-version-min=10.11") )
+
+  isIOS = getattr(config, 'ios', False)
+  # rdar://problem/22207160
+  config.substitutions.append( 
("%darwin_min_target_with_full_runtime_arc_support",
+  "-miphoneos-version-min=9.0" if isIOS else "-mmacosx-version-min=10.11") 
)
 else:
   config.substitutions.append( ("%macos_min_target_10_11", "") )
+  config.substitutions.append( 
("%darwin_min_target_with_full_runtime_arc_support", "") )
 
 if config.android:
   adb = os.environ.get('ADB', 'adb')
Index: clang/test/Driver/arclite-link.c
===
--- clang/test/Driver/arclite-link.c
+++ clang/test/Driver/arclite-link.c
@@ -1,6 +1,6 @@
 // RUN: touch %t.o
-// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime -lfoo 
-mmacosx-version-min=10.7 %t.o 2>&1 | FileCheck -check-prefix=CHECK-ARCLITE-OSX 
%s
-// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime 
-mmacosx-version-min=10.8 %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOARCLITE %s
+// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime -lfoo 
-mmacosx-version-min=10.10 %t.o 2>&1 | FileCheck 
-check-prefix=CHECK-ARCLITE-OSX %s
+// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime 
-mmacosx-version-min=10.11 %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOARCLITE 
%s
 // RUN: %clang -### -target i386-apple-darwin10 -fobjc-link-runtime 
-mmacosx-version-min=10.7 %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOARCLITE %s
 // RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime 
-nostdlib %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOSTDLIB %s
 
@@ -12,6 +12,6 @@
 // CHECK-NOARCLITE-NOT: libarclite
 // CHECK-NOSTDLIB-NOT: -lobjc
 
-// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime 
-fobjc-arc -mmacosx-version-min=10.7 %s 2>&1 | FileCheck 
-check-prefix=CHECK-UNUSED %s
+// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime 
-fobjc-arc -mmacosx-version-min=10.10 %s 2>&1 | FileCheck 
-check-prefix=CHECK-UNUSED %s
 
 // CHECK-UNUSED-NOT: warning: argument unused during compilation: 
'-fobjc-link-runtime'
Index: clang/include/clang/Basic/ObjCRuntime.h
===
--- clang/include/clang/Basic/ObjCRuntime.h
+++ clang/include/clang/Basic/ObjCRuntime.h
@@ -207,8 +207,8 @@
   bool hasSubscripting() const {
 switch (getKind()) {
 case FragileMacOSX: return false;
-case MacOSX: return getVersion() >= VersionTuple(10, 8);
-case iOS: return getVersion() >= VersionTuple(6);
+case MacOSX: return getVersion() >= VersionTuple(10, 11);
+case iOS: return getVersion() >= VersionTuple(9);
 case WatchOS: return true;
 
 // This is really a lie, because some implementations and versions


Index: compiler-rt/test/tsan/Darwin/norace-objcxx-run-time.mm
===
--- compiler-rt/test/tsan/Darwin/norace-objcxx-run-time.mm
+++ compiler-rt/test/tsan/Darwin/norace-objcxx-run-time.mm
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan %s -lc++ -fobjc-arc -lobjc -o %t -framework Foundation
+// RUN: %clang_tsan %s -lc++ -fobjc-arc -lobjc -o %t -framework Foundation %darwin_min_target_with_full_runtime_arc_support
 // RUN: %run %t 2>&1 | FileCheck %s
 
 // Check that we do not report races between:
Index: compiler-rt/test/lit.common.cfg
===
--- compiler-rt/test/lit.common.cfg
+++ compiler-rt/test/lit.common.cfg
@@ -197,8 +197,14 @@
 pass
 
   config.substitutions.append( ("%macos_min_target_10_11", "-mmacosx-version-min=10.11") )
+
+  isIOS = getattr(config, '

[PATCH] D43734: [RecordLayout] Don't align to non-power-of-2 sizes when using -mms-bitfields

2018-02-26 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.

Thanks!


https://reviews.llvm.org/D43734



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


[PATCH] D43787: Fix which Darwin versions have ObjC runtime with full subscripting support.

2018-02-26 Thread Vedant Kumar via Phabricator via cfe-commits
vsk accepted this revision.
vsk added a comment.
This revision is now accepted and ready to land.

Thanks for digging into and addressing this!


https://reviews.llvm.org/D43787



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


[PATCH] D43787: Fix which Darwin versions have ObjC runtime with full subscripting support.

2018-02-26 Thread Kuba (Brecka) Mracek via Phabricator via cfe-commits
kubamracek added a comment.

Great! So the versions in `ObjCRuntime.h` didn't really match what the iOS and 
macOS supported?


https://reviews.llvm.org/D43787



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


[PATCH] D41880: Adding nocf_check attribute for cf-protection fine tuning

2018-02-26 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: include/clang/CodeGen/CGFunctionInfo.h:519
+  /// Whether this function has nocf_check attribute.
+  unsigned NoCfCheck : 1;
+

aaron.ballman wrote:
> oren_ben_simhon wrote:
> > aaron.ballman wrote:
> > > This is unfortunate -- it bumps the bit-field over 32 bits. Can the bit 
> > > be stolen from elsewhere?
> > The field is orthogonal to the other fields moreover i think that double 
> > meaning of the same field will lead to future bugs. The class is not a 
> > compact packed structure, so i don't feel it worth the confusion.
> The class packs its fields for space savings because it's used fairly 
> frequently; if we can keep the size from having to use another allocation 
> unit, that's better. I wasn't suggesting we make a bit have double meaning, I 
> was wondering if we could reduce the size of one of the other fields. For 
> instance, I'd be surprised if we need all 8 bits for calling conventions, so 
> we might be able to reduce that to a 7-bit field.
Note that LLVM::CallingConv 
(http://llvm.org/doxygen/namespacellvm_1_1CallingConv.html) only uses up to 96, 
yet has a 'MaxID' of 1023 for some reason.  It seems that backing this down to 
255 would be more than reasonable and would prevent issues here, but wouldn't 
save any bits here.  We could possibly make it '127' in LLVM, but I fear that 
would limit the values pretty harshly.

HOWEVER, clang::CallingConv 
(https://clang.llvm.org/doxygen/Specifiers_8h_source.html#l00233) only has 17 
items.  Because of this, 7 bits is 1 more than necessary.  We could save a bit 
from ASTCallingConvention, and still permit nearly doubling calling 
conventions. 


Repository:
  rL LLVM

https://reviews.llvm.org/D41880



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


[PATCH] D43787: Fix which Darwin versions have ObjC runtime with full subscripting support.

2018-02-26 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

In https://reviews.llvm.org/D43787#1019886, @kubamracek wrote:

> Great! So the versions in `ObjCRuntime.h` didn't really match what the iOS 
> and macOS supported?


Yes, support for assigning nil for a key for NSMutableDictionary was added in 
macOS 10.11, iOS 9. Earlier versions require libarclite.


https://reviews.llvm.org/D43787



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


r326141 - Re-land "Emit proper CodeView when -gcodeview is passed without the cl driver."

2018-02-26 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Mon Feb 26 14:55:33 2018
New Revision: 326141

URL: http://llvm.org/viewvc/llvm-project?rev=326141&view=rev
Log:
Re-land "Emit proper CodeView when -gcodeview is passed without the cl driver."

Reverts r326116 and re-lands r326113 with a fix to ASan so that it
enables column info in its test suite.

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

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=326141&r1=326140&r2=326141&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Mon Feb 26 14:55:33 2018
@@ -2968,7 +2968,7 @@ static void RenderDebugOptions(const Too
 
   // Forward -gcodeview. EmitCodeView might have been set by CL-compatibility
   // argument parsing.
-  if (Args.hasArg(options::OPT_gcodeview) || EmitCodeView) {
+  if (EmitCodeView) {
 // DWARFVersion remains at 0 if no explicit choice was made.
 CmdArgs.push_back("-gcodeview");
   } else if (DWARFVersion == 0 &&
@@ -3567,6 +3567,8 @@ void Clang::ConstructJob(Compilation &C,
   types::ID InputType = Input.getType();
   if (D.IsCLMode())
 AddClangCLArgs(Args, InputType, CmdArgs, &DebugInfoKind, &EmitCodeView);
+  else
+EmitCodeView = Args.hasArg(options::OPT_gcodeview);
 
   const Arg *SplitDWARFArg = nullptr;
   RenderDebugOptions(getToolChain(), D, RawTriple, Args, EmitCodeView,

Added: cfe/trunk/test/Driver/codeview-column-info.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/codeview-column-info.c?rev=326141&view=auto
==
--- cfe/trunk/test/Driver/codeview-column-info.c (added)
+++ cfe/trunk/test/Driver/codeview-column-info.c Mon Feb 26 14:55:33 2018
@@ -0,0 +1,13 @@
+// Check that -dwarf-column-info does not get added to the cc1 line:
+// 1) When -gcodeview is present via the clang or clang++ driver
+// 2) When /Z7 is present via the cl driver.
+
+// RUN: %clang -### -c -g -gcodeview %s 2> %t1
+// RUN: FileCheck < %t1 %s
+// RUN: %clangxx -### -c -g -gcodeview %s 2> %t2
+// RUN: FileCheck < %t2 %s
+// RUN: %clang_cl -### /c /Z7 %s 2> %t2
+// RUN: FileCheck < %t2 %s
+
+// CHECK: "-cc1"
+// CHECK-NOT: "-dwarf-column-info"


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


[PATCH] D43666: [analyzer] When constructing a temporary without construction context, track it for destruction anyway.

2018-02-26 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: lib/StaticAnalyzer/Core/ExprEngine.cpp:2262
+  assert(DidCacheOutOnCleanup ||
+ areInitializedTemporariesClear(Pred->getState(),
 Pred->getLocationContext(),

dcoughlin wrote:
> It sounds like this means if we did cache out then there are places where the 
> initialized temporaries are not cleared (that is, we have extra gunk in the 
> state that we don't want).
> 
> Is that true? If so, then this relaxation of the assertion doesn't seem right 
> to me.
> 
> Do we need to introduce a new program point when calling `Bldr.generateNode` 
> on the cleaned up state (for example, with a new tag or a new program point 
> kind)? This would make it so that when we cache out when generating a node 
> for the state with the cleaned up temporaries we know that it is safe to 
> early return from processEndOfFunction(). It would be safe because we would 
> know that the other node (the one we cached out because of) has already had 
> its temporaries cleared and notified the checkers about the end of the 
> function, etc.
> 
> 
> 
> 
> 
Yep, this is a bug and also it can be simplified a lot.


https://reviews.llvm.org/D43666



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


[PATCH] D43576: Solution to fix PR27066 - Redefinition with same mangled name as another definition (dllexport and uuid)

2018-02-26 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In https://reviews.llvm.org/D43576#1019703, @zahiraam wrote:

> Currently this declaration:
> struct
>  __declspec(uuid("{DDB47A6A-0F23-11D5-9109-00E0296B75D3}"))
>  S1;
>
> a CXXRecordDecl type is generated with attributes (the uuid being an 
> attribute). Are you proposing that instead a new type is generated for S1 say 
> something like CXXUuidRecord? And create also a new TagType that corresponds 
> to this new Decl?


No. Concretely, I'd suggest we create a new `UuidDecl` object representing the 
`_GUID` object. An instance of `UuidDecl` would be created and owned by the 
`uuid` attribute, and `__uuidof(X)` would denote the `UuidDecl` owned by the 
`uuid` attribute on the `CXXRecordDecl`. We'd also need some way to form 
redeclaration chains for `UuidDecl`s (which means we'll need a map from UUID to 
`UuidDecl` somewhere, perhaps on the `ASTContext`).


https://reviews.llvm.org/D43576



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


[PATCH] D43666: [analyzer] When constructing a temporary without construction context, track it for destruction anyway.

2018-02-26 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 135994.
NoQ marked 3 inline comments as done.
NoQ added a comment.

Fix cleanup node generation logic.


https://reviews.llvm.org/D43666

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/Analysis/temporaries.cpp

Index: test/Analysis/temporaries.cpp
===
--- test/Analysis/temporaries.cpp
+++ test/Analysis/temporaries.cpp
@@ -900,7 +900,13 @@
 
 class C {
 public:
-  ~C() { glob = 1; }
+  ~C() {
+glob = 1;
+clang_analyzer_checkInlined(true);
+#ifdef TEMPORARY_DTORS
+// expected-warning@-2{{TRUE}}
+#endif
+  }
 };
 
 C get();
@@ -913,12 +919,11 @@
   // temporaries: the return value of get() and the elidable copy constructor
   // of that return value into is(). According to the CFG, we need to cleanup
   // both of them depending on whether the temporary corresponding to the
-  // return value of get() was initialized. However, for now we don't track
-  // temporaries returned from functions, so we take the wrong branch.
+  // return value of get() was initialized. However, we didn't track
+  // temporaries returned from functions, so we took the wrong branch.
   coin && is(get()); // no-crash
-  // FIXME: We should have called the destructor, i.e. should be TRUE,
-  // at least when we inline temporary destructors.
-  clang_analyzer_eval(glob == 1); // expected-warning{{UNKNOWN}}
+  // FIXME: Should be true once we inline all destructors.
+  clang_analyzer_eval(glob); // expected-warning{{UNKNOWN}}
 }
 } // namespace dont_forget_destructor_around_logical_op
 
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1089,6 +1089,34 @@
   }
 }
 
+void ExprEngine::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *BTE,
+   ExplodedNodeSet &PreVisit,
+   ExplodedNodeSet &Dst) {
+  // This is a fallback solution in case we didn't have a construction
+  // context when we were constructing the temporary. Otherwise the map should
+  // have been populated there.
+  if (!getAnalysisManager().options.includeTemporaryDtorsInCFG()) {
+// In case we don't have temporary destructors in the CFG, do not mark
+// the initialization - we would otherwise never clean it up.
+Dst = PreVisit;
+return;
+  }
+  StmtNodeBuilder StmtBldr(PreVisit, Dst, *currBldrCtx);
+  for (ExplodedNode *Node : PreVisit) {
+ProgramStateRef State = Node->getState();
+		const auto &Key = std::make_pair(BTE, Node->getStackFrame());
+
+if (!State->contains(Key)) {
+  // FIXME: Currently the state might also already contain the marker due to
+  // incorrect handling of temporaries bound to default parameters; for
+  // those, we currently skip the CXXBindTemporaryExpr but rely on adding
+  // temporary destructor nodes.
+  State = State->set(Key, nullptr);
+}
+StmtBldr.generateNode(BTE, Node, State);
+  }
+}
+
 namespace {
 class CollectReachableSymbolsCallback final : public SymbolVisitor {
   InvalidatedSymbols Symbols;
@@ -1251,7 +1279,9 @@
   Bldr.takeNodes(Pred);
   ExplodedNodeSet PreVisit;
   getCheckerManager().runCheckersForPreStmt(PreVisit, Pred, S, *this);
-  getCheckerManager().runCheckersForPostStmt(Dst, PreVisit, S, *this);
+  ExplodedNodeSet Next;
+  VisitCXXBindTemporaryExpr(cast(S), PreVisit, Next);
+  getCheckerManager().runCheckersForPostStmt(Dst, Next, S, *this);
   Bldr.addNodes(Dst);
   break;
 }
@@ -2194,13 +2224,13 @@
Pred->getLocationContext(),
Pred->getStackFrame()->getParent()));
 
-  // FIXME: We currently assert that temporaries are clear, as lifetime extended
-  // temporaries are not always modelled correctly. In some cases when we
-  // materialize the temporary, we do createTemporaryRegionIfNeeded(), and
-  // the region changes, and also the respective destructor becomes automatic
-  // from temporary. So for now clean up the state manually before asserting.
-  // Ideally, the code above the assertion should go away, but the assertion
-  // should remain.
+  // FIXME: We currently cannot assert that temporaries are clear, because
+  // lifetime extended temporaries are not always modelled correctly. In some
+  // cases when we materialize the temporary, we do
+  // createTemporaryRegionIfNeeded(), and the region changes, and also the
+  // respective destructor becomes automatic from temporary. So for now clean up
+  // the state manually before asserting. Ideally, the code above the assertion
+  // should go away, but the assertion should remain.
   {
 ExplodedNodeSet CleanUpTemporaries;
 NodeBuilder Bldr(Pred, CleanUpTemporaries, BC);
@@ -

[PATCH] D43748: [Attr] Fix paren, comma, and omitted arg printing in some cases

2018-02-26 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 135982.
jdenny added a comment.

Aaron: Because the last two arguments for objc_bridge_related must be delimited 
with commas, this revision takes the view that they are not optional but are 
permitted to be the empty string.

The test suite behaves as expected.  Are there any untested attributes that 
might be broken by this patch?  Hopefully they can be addressed in a similar 
manner.


https://reviews.llvm.org/D43748

Files:
  include/clang/Basic/Attr.td
  lib/Parse/ParseDecl.cpp
  test/Sema/attr-print.c
  test/Sema/attr-print.cpp
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -231,6 +231,7 @@
 virtual void writePCHReadArgs(raw_ostream &OS) const = 0;
 virtual void writePCHReadDecls(raw_ostream &OS) const = 0;
 virtual void writePCHWrite(raw_ostream &OS) const = 0;
+virtual std::string getIsOmitted() const { return "false"; }
 virtual void writeValue(raw_ostream &OS) const = 0;
 virtual void writeDump(raw_ostream &OS) const = 0;
 virtual void writeDumpChildren(raw_ostream &OS) const {}
@@ -298,33 +299,43 @@
std::string(getUpperName()) + "()");
 }
 
+std::string getIsOmitted() const override {
+  if (type == "FunctionDecl *")
+return "false";
+  if (type == "IdentifierInfo *")
+return "!get" + getUpperName().str() + "()";
+  if (type == "TypeSourceInfo *")
+return "false";
+  // FIXME: Do this declaratively in Attr.td.
+  if (getAttrName() == "AllocSize")
+return "0 == get" + getUpperName().str() + "()";
+  return "false";
+}
+
 void writeValue(raw_ostream &OS) const override {
-  if (type == "FunctionDecl *") {
+  if (type == "FunctionDecl *")
 OS << "\" << get" << getUpperName()
<< "()->getNameInfo().getAsString() << \"";
-  } else if (type == "IdentifierInfo *") {
-OS << "\";\n";
-if (isOptional())
-  OS << "if (get" << getUpperName() << "()) ";
-else
-  OS << "";
-OS << "OS << get" << getUpperName() << "()->getName();\n";
-OS << "OS << \"";
-  } else if (type == "TypeSourceInfo *") {
+  else if (type == "IdentifierInfo *")
+// Some non-optional (comma required) identifier arguments can be the
+// empty string but are then recorded as a nullptr.
+OS << "\" << (get" << getUpperName() << "() ? get" << getUpperName()
+   << "()->getName() : \"\") << \"";
+  else if (type == "TypeSourceInfo *")
 OS << "\" << get" << getUpperName() << "().getAsString() << \"";
-  } else {
+  else
 OS << "\" << get" << getUpperName() << "() << \"";
-  }
 }
 
 void writeDump(raw_ostream &OS) const override {
   if (type == "FunctionDecl *" || type == "NamedDecl *") {
 OS << "OS << \" \";\n";
 OS << "dumpBareDeclRef(SA->get" << getUpperName() << "());\n"; 
   } else if (type == "IdentifierInfo *") {
-if (isOptional())
-  OS << "if (SA->get" << getUpperName() << "())\n  ";
-OS << "OS << \" \" << SA->get" << getUpperName()
+// Some non-optional (comma required) identifier arguments can be the
+// empty string but are then recorded as a nullptr.
+OS << "if (SA->get" << getUpperName() << "())\n"
+   << "  OS << \" \" << SA->get" << getUpperName()
<< "()->getName();\n";
   } else if (type == "TypeSourceInfo *") {
 OS << "OS << \" \" << SA->get" << getUpperName()
@@ -576,12 +587,15 @@
  << "Type());\n";
 }
 
+std::string getIsOmitted() const override {
+  return "!is" + getLowerName().str() + "Expr || !" + getLowerName().str()
+ + "Expr";
+}
+
 void writeValue(raw_ostream &OS) const override {
   OS << "\";\n";
-  // The aligned attribute argument expression is optional.
-  OS << "if (is" << getLowerName() << "Expr && "
- << getLowerName() << "Expr)\n";
-  OS << "  " << getLowerName() << "Expr->printPretty(OS, nullptr, Policy);\n";
+  OS << "" << getLowerName()
+ << "Expr->printPretty(OS, nullptr, Policy);\n";
   OS << "OS << \"";
 }
 
@@ -1376,33 +1390,83 @@
   continue;
 }
 
-// Fake arguments aren't part of the parsed form and should not be
-// pretty-printed.
-bool hasNonFakeArgs = llvm::any_of(
-Args, [](const std::unique_ptr &A) { return !A->isFake(); });
-
-// FIXME: always printing the parenthesis isn't the correct behavior for
-// attributes which have optional arguments that were not provided. For
-// instance: __attribute__((aligned)) will be pretty printed as
-// __attribute__((aligned())). The logic should check

[PATCH] D43787: Fix which Darwin versions have ObjC runtime with full subscripting support.

2018-02-26 Thread Volodymyr Sapsai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL326143: Fix which Darwin versions have ObjC runtime with 
full subscripting support. (authored by vsapsai, committed by ).
Herald added subscribers: llvm-commits, delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D43787?vs=135985&id=135996#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43787

Files:
  compiler-rt/trunk/test/lit.common.cfg
  compiler-rt/trunk/test/tsan/Darwin/norace-objcxx-run-time.mm


Index: compiler-rt/trunk/test/tsan/Darwin/norace-objcxx-run-time.mm
===
--- compiler-rt/trunk/test/tsan/Darwin/norace-objcxx-run-time.mm
+++ compiler-rt/trunk/test/tsan/Darwin/norace-objcxx-run-time.mm
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan %s -lc++ -fobjc-arc -lobjc -o %t -framework Foundation
+// RUN: %clang_tsan %s -lc++ -fobjc-arc -lobjc -o %t -framework Foundation 
%darwin_min_target_with_full_runtime_arc_support
 // RUN: %run %t 2>&1 | FileCheck %s
 
 // Check that we do not report races between:
Index: compiler-rt/trunk/test/lit.common.cfg
===
--- compiler-rt/trunk/test/lit.common.cfg
+++ compiler-rt/trunk/test/lit.common.cfg
@@ -201,8 +201,14 @@
 pass
 
   config.substitutions.append( ("%macos_min_target_10_11", 
"-mmacosx-version-min=10.11") )
+
+  isIOS = getattr(config, 'ios', False)
+  # rdar://problem/22207160
+  config.substitutions.append( 
("%darwin_min_target_with_full_runtime_arc_support",
+  "-miphoneos-version-min=9.0" if isIOS else "-mmacosx-version-min=10.11") 
)
 else:
   config.substitutions.append( ("%macos_min_target_10_11", "") )
+  config.substitutions.append( 
("%darwin_min_target_with_full_runtime_arc_support", "") )
 
 if config.android:
   adb = os.environ.get('ADB', 'adb')


Index: compiler-rt/trunk/test/tsan/Darwin/norace-objcxx-run-time.mm
===
--- compiler-rt/trunk/test/tsan/Darwin/norace-objcxx-run-time.mm
+++ compiler-rt/trunk/test/tsan/Darwin/norace-objcxx-run-time.mm
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan %s -lc++ -fobjc-arc -lobjc -o %t -framework Foundation
+// RUN: %clang_tsan %s -lc++ -fobjc-arc -lobjc -o %t -framework Foundation %darwin_min_target_with_full_runtime_arc_support
 // RUN: %run %t 2>&1 | FileCheck %s
 
 // Check that we do not report races between:
Index: compiler-rt/trunk/test/lit.common.cfg
===
--- compiler-rt/trunk/test/lit.common.cfg
+++ compiler-rt/trunk/test/lit.common.cfg
@@ -201,8 +201,14 @@
 pass
 
   config.substitutions.append( ("%macos_min_target_10_11", "-mmacosx-version-min=10.11") )
+
+  isIOS = getattr(config, 'ios', False)
+  # rdar://problem/22207160
+  config.substitutions.append( ("%darwin_min_target_with_full_runtime_arc_support",
+  "-miphoneos-version-min=9.0" if isIOS else "-mmacosx-version-min=10.11") )
 else:
   config.substitutions.append( ("%macos_min_target_10_11", "") )
+  config.substitutions.append( ("%darwin_min_target_with_full_runtime_arc_support", "") )
 
 if config.android:
   adb = os.environ.get('ADB', 'adb')
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r326144 - Fix codeview-column-info.c test with a triple

2018-02-26 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Mon Feb 26 15:06:40 2018
New Revision: 326144

URL: http://llvm.org/viewvc/llvm-project?rev=326144&view=rev
Log:
Fix codeview-column-info.c test with a triple

Modified:
cfe/trunk/test/Driver/codeview-column-info.c

Modified: cfe/trunk/test/Driver/codeview-column-info.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/codeview-column-info.c?rev=326144&r1=326143&r2=326144&view=diff
==
--- cfe/trunk/test/Driver/codeview-column-info.c (original)
+++ cfe/trunk/test/Driver/codeview-column-info.c Mon Feb 26 15:06:40 2018
@@ -2,11 +2,11 @@
 // 1) When -gcodeview is present via the clang or clang++ driver
 // 2) When /Z7 is present via the cl driver.
 
-// RUN: %clang -### -c -g -gcodeview %s 2> %t1
+// RUN: %clang -### --target=x86_64-windows-msvc -c -g -gcodeview %s 2> %t1
 // RUN: FileCheck < %t1 %s
-// RUN: %clangxx -### -c -g -gcodeview %s 2> %t2
+// RUN: %clangxx -### --target=x86_64-windows-msvc -c -g -gcodeview %s 2> %t2
 // RUN: FileCheck < %t2 %s
-// RUN: %clang_cl -### /c /Z7 %s 2> %t2
+// RUN: %clang_cl -### --target=x86_64-windows-msvc /c /Z7 %s 2> %t2
 // RUN: FileCheck < %t2 %s
 
 // CHECK: "-cc1"


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


r326145 - Fix which Darwin versions have ObjC runtime with full subscripting support.

2018-02-26 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Mon Feb 26 15:10:23 2018
New Revision: 326145

URL: http://llvm.org/viewvc/llvm-project?rev=326145&view=rev
Log:
Fix which Darwin versions have ObjC runtime with full subscripting support.

Update min deployment target in some tests so that they don't try
to link against libarclite and don't fail when it's not available.

rdar://problem/29253617

Reviewers: vsk, kubamracek

Reviewed By: vsk

Subscribers: jkorous-apple, cfe-commits

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


Modified:
cfe/trunk/include/clang/Basic/ObjCRuntime.h
cfe/trunk/test/Driver/arclite-link.c

Modified: cfe/trunk/include/clang/Basic/ObjCRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/ObjCRuntime.h?rev=326145&r1=326144&r2=326145&view=diff
==
--- cfe/trunk/include/clang/Basic/ObjCRuntime.h (original)
+++ cfe/trunk/include/clang/Basic/ObjCRuntime.h Mon Feb 26 15:10:23 2018
@@ -207,8 +207,8 @@ public:
   bool hasSubscripting() const {
 switch (getKind()) {
 case FragileMacOSX: return false;
-case MacOSX: return getVersion() >= VersionTuple(10, 8);
-case iOS: return getVersion() >= VersionTuple(6);
+case MacOSX: return getVersion() >= VersionTuple(10, 11);
+case iOS: return getVersion() >= VersionTuple(9);
 case WatchOS: return true;
 
 // This is really a lie, because some implementations and versions

Modified: cfe/trunk/test/Driver/arclite-link.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/arclite-link.c?rev=326145&r1=326144&r2=326145&view=diff
==
--- cfe/trunk/test/Driver/arclite-link.c (original)
+++ cfe/trunk/test/Driver/arclite-link.c Mon Feb 26 15:10:23 2018
@@ -1,6 +1,6 @@
 // RUN: touch %t.o
-// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime -lfoo 
-mmacosx-version-min=10.7 %t.o 2>&1 | FileCheck -check-prefix=CHECK-ARCLITE-OSX 
%s
-// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime 
-mmacosx-version-min=10.8 %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOARCLITE %s
+// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime -lfoo 
-mmacosx-version-min=10.10 %t.o 2>&1 | FileCheck 
-check-prefix=CHECK-ARCLITE-OSX %s
+// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime 
-mmacosx-version-min=10.11 %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOARCLITE 
%s
 // RUN: %clang -### -target i386-apple-darwin10 -fobjc-link-runtime 
-mmacosx-version-min=10.7 %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOARCLITE %s
 // RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime 
-nostdlib %t.o 2>&1 | FileCheck -check-prefix=CHECK-NOSTDLIB %s
 
@@ -12,6 +12,6 @@
 // CHECK-NOARCLITE-NOT: libarclite
 // CHECK-NOSTDLIB-NOT: -lobjc
 
-// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime 
-fobjc-arc -mmacosx-version-min=10.7 %s 2>&1 | FileCheck 
-check-prefix=CHECK-UNUSED %s
+// RUN: %clang -### -target x86_64-apple-darwin10 -fobjc-link-runtime 
-fobjc-arc -mmacosx-version-min=10.10 %s 2>&1 | FileCheck 
-check-prefix=CHECK-UNUSED %s
 
 // CHECK-UNUSED-NOT: warning: argument unused during compilation: 
'-fobjc-link-runtime'


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


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

2018-02-26 Thread Eugene Zelenko via cfe-commits
Author: eugenezelenko
Date: Mon Feb 26 15:15:52 2018
New Revision: 326146

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

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

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h?rev=326146&r1=326145&r2=326146&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h Mon Feb 26 
15:15:52 2018
@@ -1,4 +1,4 @@
-//===--- CheckerManager.h - Static Analyzer Checker Manager -*- C++ 
-*-===//
+//===- CheckerManager.h - Static Analyzer Checker Manager ---*- C++ 
-*-===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -16,45 +16,56 @@
 
 #include "clang/Analysis/ProgramPoint.h"
 #include "clang/Basic/LangOptions.h"
-#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/Store.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallVector.h"
-#include 
+#include "llvm/ADT/StringRef.h"
 #include 
 
 namespace clang {
-  class Decl;
-  class Stmt;
-  class CallExpr;
+
+class AnalyzerOptions;
+class CallExpr;
+class CXXNewExpr;
+class Decl;
+class LocationContext;
+class Stmt;
+class TranslationUnitDecl;
 
 namespace ento {
-  class CheckerBase;
-  class CheckerRegistry;
-  class ExprEngine;
-  class AnalysisManager;
-  class BugReporter;
-  class CheckerContext;
-  class ObjCMethodCall;
-  class SVal;
-  class ExplodedNode;
-  class ExplodedNodeSet;
-  class ExplodedGraph;
-  class ProgramState;
-  class NodeBuilder;
-  struct NodeBuilderContext;
-  class MemRegion;
-  class SymbolReaper;
+
+class AnalysisManager;
+class BugReporter;
+class CallEvent;
+class CheckerBase;
+class CheckerContext;
+class CheckerRegistry;
+class ExplodedGraph;
+class ExplodedNode;
+class ExplodedNodeSet;
+class ExprEngine;
+class MemRegion;
+struct NodeBuilderContext;
+class ObjCMethodCall;
+class RegionAndSymbolInvalidationTraits;
+class SVal;
+class SymbolReaper;
 
 template  class CheckerFn;
 
 template 
 class CheckerFn {
-  typedef RET (*Func)(void *, Ps...);
+  using Func = RET (*)(void *, Ps...);
+
   Func Fn;
+
 public:
   CheckerBase *Checker;
-  CheckerFn(CheckerBase *checker, Func fn) : Fn(fn), Checker(checker) { }
+
+  CheckerFn(CheckerBase *checker, Func fn) : Fn(fn), Checker(checker) {}
+
   RET operator()(Ps... ps) const {
 return Fn(Checker, ps...);
   }
@@ -85,12 +96,15 @@ enum PointerEscapeKind {
 // name strings have a lifetime that keeps them alive at least until the path
 // diagnostics have been processed.
 class CheckName {
-  StringRef Name;
   friend class ::clang::ento::CheckerRegistry;
+
+  StringRef Name;
+
   explicit CheckName(StringRef Name) : Name(Name) {}
 
 public:
   CheckName() = default;
+
   StringRef getName() const { return Name; }
 };
 
@@ -121,9 +135,9 @@ public:
   const LangOptions &getLangOpts() const { return LangOpts; }
   AnalyzerOptions &getAnalyzerOptions() { return AOptions; }
 
-  typedef CheckerBase *CheckerRef;
-  typedef const void *CheckerTag;
-  typedef CheckerFn CheckerDtor;
+  using CheckerRef = CheckerBase *;
+  using CheckerTag = const void *;
+  using CheckerDtor = CheckerFn;
 
 
//===--===//
 // registerChecker
@@ -238,7 +252,6 @@ public:
   Eng);
   }
 
-
   /// \brief Run checkers for visiting obj-c messages.
   void runCheckersForObjCMessage(ObjCMessageVisitKind visitKind,
  ExplodedNodeSet &Dst,
@@ -368,7 +381,7 @@ public:
   const InvalidatedSymbols &Escaped,
   const CallEvent *Call,
   PointerEscapeKind Kind,
- RegionAndSymbolInvalidationTraits *ITraits);
+  RegionAndSymbolInvalidationTraits *ITraits);
 
   /// \brief Run checkers for handling assumptions on symbolic values.
   ProgramStateRef runCheckersForEvalAssume(ProgramStateRef state,
@@ -404,10 +417,11 @@ public:
   // Functions used by the registration mechanism, checkers should not touch
   // these directly.
 
-  typedef CheckerFn
-  CheckDeclFunc;
+  using CheckDeclFunc =
+  CheckerFn;
+
+  using HandlesDeclFunc = bool (*)(c

[PATCH] D43791: [analyzer] Suppress MallocChecker positives in destructors with atomics.

2018-02-26 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.

This patch is a targeted suppression heuristic for false positives 
`MallocChecker` produces when a shared / reference-counting pointer is copied 
(including, but not limited to, `llvm::IntrusiveRefCntPtr`). The program 
increments the reference count through an atomic `fetch_add` (which is often 
the C++11 `std::atomic::fetch_add()` that executes the respective C11 atomic 
when inlined), then decrements it via `fetch_sub` (or via `fetch_add` while 
adding -1), then sees if the reference count is zero by comparing the value 
returned by `fetch_sub` to 1, then deletes the object if the reference count is 
indeed zero.

These false positives get amplified by inlining temporary destructors, but even 
in code without any temporary destructors these positives are reproducible, as 
the tests suggest.

We cannot easily model the comparison to 1 correctly: even if we model all 
atomic expressions precisely, the original reference count may still have been 
symbolic to begin with. And if we tried to assume that no overflows occur on 
reference counts, this would still require pattern-matching heuristics to 
figure out if a certain variable is a reference counter.

The proposed fix is to suppress `MallocChecker` positives that are caused by 
releasing memory in a destructor stack frame (or its children stack frames) 
after performing any C11 atomic `fetch_add` or `fetch_sub` in that destructor's 
stack frame (or its children stack frames). This is done in a visitor 
suppression.


Repository:
  rC Clang

https://reviews.llvm.org/D43791

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

Index: test/Analysis/NewDelete-atomics.cpp
===
--- /dev/null
+++ test/Analysis/NewDelete-atomics.cpp
@@ -0,0 +1,74 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks -DLEAKS -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete -std=c++11 -DTEST_INLINABLE_ALLOCATORS -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks -DLEAKS -std=c++11 -DTEST_INLINABLE_ALLOCATORS -verify %s
+
+// expected-no-diagnostics
+
+#include "Inputs/system-header-simulator-cxx.h"
+
+typedef enum memory_order {
+  memory_order_relaxed = __ATOMIC_RELAXED,
+  memory_order_consume = __ATOMIC_CONSUME,
+  memory_order_acquire = __ATOMIC_ACQUIRE,
+  memory_order_release = __ATOMIC_RELEASE,
+  memory_order_acq_rel = __ATOMIC_ACQ_REL,
+  memory_order_seq_cst = __ATOMIC_SEQ_CST
+} memory_order;
+
+class Obj {
+  int RefCnt;
+
+public:
+  int incRef() {
+return __c11_atomic_fetch_add((volatile _Atomic(int) *)&RefCnt, 1,
+  memory_order_relaxed);
+  }
+
+  int decRef() {
+return __c11_atomic_fetch_sub((volatile _Atomic(int) *)&RefCnt, 1,
+  memory_order_relaxed);
+  }
+
+  void foo();
+};
+
+class IntrusivePtr {
+  Obj *Ptr;
+
+public:
+  IntrusivePtr(Obj *Ptr) : Ptr(Ptr) {
+Ptr->incRef();
+  }
+
+  IntrusivePtr(const IntrusivePtr &Other) : Ptr(Other.Ptr) {
+Ptr->incRef();
+  }
+
+  ~IntrusivePtr() {
+  // We should not take the path on which the object is deleted.
+if (Ptr->decRef() == 1)
+  delete Ptr;
+  }
+
+  Obj *getPtr() const { return Ptr; }
+};
+
+void testDestroyLocalRefPtr() {
+  IntrusivePtr p1(new Obj());
+  {
+IntrusivePtr p2(p1);
+  }
+
+  // p1 still maintains ownership. The object is not deleted.
+  p1.getPtr()->foo(); // no-warning
+}
+
+void testDestroySymbolicRefPtr(const IntrusivePtr &p1) {
+  {
+IntrusivePtr p2(p1);
+  }
+
+  // p1 still maintains ownership. The object is not deleted.
+  p1.getPtr()->foo(); // no-warning
+}
Index: lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -446,15 +446,24 @@
 // A symbol from when the primary region should have been reallocated.
 SymbolRef FailedReallocSymbol;
 
+// A C++ destructor stack frame in which memory was released. Used for
+// miscellaneous false positive suppression.
+const StackFrameContext *ReleaseDestructorLC;
+
 bool IsLeak;
 
   public:
 MallocBugVisitor(SymbolRef S, bool isLeak = false)
-   : Sym(S), Mode(Normal), FailedReallocSymbol(nullptr), IsLeak(isLeak) {}
+: Sym(S), Mode(Normal), FailedReallocSymbol(nullptr),
+  ReleaseDestructorLC(nullptr), IsLeak(isLeak) {}
+
+static void *getTag() {
+  static int Tag = 0;
+  return &Tag;
+}
 
 void Profile(llvm::FoldingSetNodeID &ID) const override {
-  static int X = 0;
-

[PATCH] D43606: [Driver] Add SafeStack to a map of incompatible sanitizers

2018-02-26 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 136002.
phosek marked an inline comment as done.
Herald added subscribers: Sanitizers, llvm-commits.

Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D43606

Files:
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/Driver/fsanitize.c


Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -526,22 +526,19 @@
 // NOSP-NOT: "-fsanitize=safe-stack"
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack -### %s 2>&1 | 
FileCheck %s -check-prefix=NO-SP
-// RUN: %clang -target x86_64-linux-gnu -fsanitize=address,safe-stack -### %s 
2>&1 | FileCheck %s -check-prefix=NO-SP-ASAN
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address,safe-stack -### %s 
2>&1 | FileCheck %s -check-prefix=SP-ASAN
 // RUN: %clang -target x86_64-linux-gnu -fstack-protector 
-fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack 
-fstack-protector-all -### %s 2>&1 | FileCheck %s -check-prefix=SP
 // RUN: %clang -target arm-linux-androideabi -fsanitize=safe-stack -### %s 
2>&1 | FileCheck %s -check-prefix=NO-SP
 // RUN: %clang -target aarch64-linux-android -fsanitize=safe-stack -### %s 
2>&1 | FileCheck %s -check-prefix=NO-SP
 // RUN: %clang -target i386-contiki-unknown -fsanitize=safe-stack -### %s 2>&1 
| FileCheck %s -check-prefix=NO-SP
 // NO-SP-NOT: stack-protector
 // NO-SP: "-fsanitize=safe-stack"
+// SP-ASAN: error: invalid argument '-fsanitize=safe-stack' not allowed with 
'-fsanitize=address'
 // SP: "-fsanitize=safe-stack"
 // SP: -stack-protector
 // NO-SP-NOT: stack-protector
 
-// NO-SP-ASAN-NOT: stack-protector
-// NO-SP-ASAN: "-fsanitize=address,safe-stack"
-// NO-SP-ASAN-NOT: stack-protector
-
 // RUN: %clang -target powerpc64-unknown-linux-gnu -fsanitize=memory %s -### 
2>&1 | FileCheck %s -check-prefix=CHECK-SANM
 // RUN: %clang -target powerpc64le-unknown-linux-gnu -fsanitize=memory %s -### 
2>&1 | FileCheck %s -check-prefix=CHECK-SANM
 // CHECK-SANM: "-fsanitize=memory"
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -378,7 +378,9 @@
   std::make_pair(Efficiency, Address | HWAddress | Leak | Thread | Memory |
  KernelAddress),
   std::make_pair(Scudo, Address | HWAddress | Leak | Thread | Memory |
-KernelAddress | Efficiency)};
+KernelAddress | Efficiency),
+  std::make_pair(SafeStack, Address | HWAddress | Leak | Thread | Memory |
+KernelAddress | Efficiency)};
   for (auto G : IncompatibleGroups) {
 SanitizerMask Group = G.first;
 if (Kinds & Group) {


Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -526,22 +526,19 @@
 // NOSP-NOT: "-fsanitize=safe-stack"
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP
-// RUN: %clang -target x86_64-linux-gnu -fsanitize=address,safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP-ASAN
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address,safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP-ASAN
 // RUN: %clang -target x86_64-linux-gnu -fstack-protector -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack -fstack-protector-all -### %s 2>&1 | FileCheck %s -check-prefix=SP
 // RUN: %clang -target arm-linux-androideabi -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP
 // RUN: %clang -target aarch64-linux-android -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP
 // RUN: %clang -target i386-contiki-unknown -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP
 // NO-SP-NOT: stack-protector
 // NO-SP: "-fsanitize=safe-stack"
+// SP-ASAN: error: invalid argument '-fsanitize=safe-stack' not allowed with '-fsanitize=address'
 // SP: "-fsanitize=safe-stack"
 // SP: -stack-protector
 // NO-SP-NOT: stack-protector
 
-// NO-SP-ASAN-NOT: stack-protector
-// NO-SP-ASAN: "-fsanitize=address,safe-stack"
-// NO-SP-ASAN-NOT: stack-protector
-
 // RUN: %clang -target powerpc64-unknown-linux-gnu -fsanitize=memory %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-SANM
 // RUN: %clang -target powerpc64le-unknown-linux-gnu -fsanitize=memory %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-SANM
 // CHECK-SANM: "-fsanitize=memory"
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -378,7

r326151 - [Driver] Add SafeStack to a map of incompatible sanitizers

2018-02-26 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Mon Feb 26 16:01:26 2018
New Revision: 326151

URL: http://llvm.org/viewvc/llvm-project?rev=326151&view=rev
Log:
[Driver] Add SafeStack to a map of incompatible sanitizers

This allows reporting an error when user tries to use SafeStack with
incompatible sanitizers.

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

Modified:
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/test/Driver/fsanitize.c

Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=326151&r1=326150&r2=326151&view=diff
==
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Mon Feb 26 16:01:26 2018
@@ -378,7 +378,9 @@ SanitizerArgs::SanitizerArgs(const ToolC
   std::make_pair(Efficiency, Address | HWAddress | Leak | Thread | Memory |
  KernelAddress),
   std::make_pair(Scudo, Address | HWAddress | Leak | Thread | Memory |
-KernelAddress | Efficiency)};
+KernelAddress | Efficiency),
+  std::make_pair(SafeStack, Address | HWAddress | Leak | Thread | Memory |
+KernelAddress | Efficiency)};
   for (auto G : IncompatibleGroups) {
 SanitizerMask Group = G.first;
 if (Kinds & Group) {

Modified: cfe/trunk/test/Driver/fsanitize.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize.c?rev=326151&r1=326150&r2=326151&view=diff
==
--- cfe/trunk/test/Driver/fsanitize.c (original)
+++ cfe/trunk/test/Driver/fsanitize.c Mon Feb 26 16:01:26 2018
@@ -526,7 +526,7 @@
 // NOSP-NOT: "-fsanitize=safe-stack"
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack -### %s 2>&1 | 
FileCheck %s -check-prefix=NO-SP
-// RUN: %clang -target x86_64-linux-gnu -fsanitize=address,safe-stack -### %s 
2>&1 | FileCheck %s -check-prefix=NO-SP-ASAN
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address,safe-stack -### %s 
2>&1 | FileCheck %s -check-prefix=SP-ASAN
 // RUN: %clang -target x86_64-linux-gnu -fstack-protector 
-fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack 
-fstack-protector-all -### %s 2>&1 | FileCheck %s -check-prefix=SP
 // RUN: %clang -target arm-linux-androideabi -fsanitize=safe-stack -### %s 
2>&1 | FileCheck %s -check-prefix=NO-SP
@@ -534,14 +534,11 @@
 // RUN: %clang -target i386-contiki-unknown -fsanitize=safe-stack -### %s 2>&1 
| FileCheck %s -check-prefix=NO-SP
 // NO-SP-NOT: stack-protector
 // NO-SP: "-fsanitize=safe-stack"
+// SP-ASAN: error: invalid argument '-fsanitize=safe-stack' not allowed with 
'-fsanitize=address'
 // SP: "-fsanitize=safe-stack"
 // SP: -stack-protector
 // NO-SP-NOT: stack-protector
 
-// NO-SP-ASAN-NOT: stack-protector
-// NO-SP-ASAN: "-fsanitize=address,safe-stack"
-// NO-SP-ASAN-NOT: stack-protector
-
 // RUN: %clang -target powerpc64-unknown-linux-gnu -fsanitize=memory %s -### 
2>&1 | FileCheck %s -check-prefix=CHECK-SANM
 // RUN: %clang -target powerpc64le-unknown-linux-gnu -fsanitize=memory %s -### 
2>&1 | FileCheck %s -check-prefix=CHECK-SANM
 // CHECK-SANM: "-fsanitize=memory"


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


[PATCH] D43606: [Driver] Add SafeStack to a map of incompatible sanitizers

2018-02-26 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL326151: [Driver] Add SafeStack to a map of incompatible 
sanitizers (authored by phosek, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43606?vs=136002&id=136004#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43606

Files:
  cfe/trunk/lib/Driver/SanitizerArgs.cpp
  cfe/trunk/test/Driver/fsanitize.c


Index: cfe/trunk/test/Driver/fsanitize.c
===
--- cfe/trunk/test/Driver/fsanitize.c
+++ cfe/trunk/test/Driver/fsanitize.c
@@ -526,22 +526,19 @@
 // NOSP-NOT: "-fsanitize=safe-stack"
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack -### %s 2>&1 | 
FileCheck %s -check-prefix=NO-SP
-// RUN: %clang -target x86_64-linux-gnu -fsanitize=address,safe-stack -### %s 
2>&1 | FileCheck %s -check-prefix=NO-SP-ASAN
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address,safe-stack -### %s 
2>&1 | FileCheck %s -check-prefix=SP-ASAN
 // RUN: %clang -target x86_64-linux-gnu -fstack-protector 
-fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack 
-fstack-protector-all -### %s 2>&1 | FileCheck %s -check-prefix=SP
 // RUN: %clang -target arm-linux-androideabi -fsanitize=safe-stack -### %s 
2>&1 | FileCheck %s -check-prefix=NO-SP
 // RUN: %clang -target aarch64-linux-android -fsanitize=safe-stack -### %s 
2>&1 | FileCheck %s -check-prefix=NO-SP
 // RUN: %clang -target i386-contiki-unknown -fsanitize=safe-stack -### %s 2>&1 
| FileCheck %s -check-prefix=NO-SP
 // NO-SP-NOT: stack-protector
 // NO-SP: "-fsanitize=safe-stack"
+// SP-ASAN: error: invalid argument '-fsanitize=safe-stack' not allowed with 
'-fsanitize=address'
 // SP: "-fsanitize=safe-stack"
 // SP: -stack-protector
 // NO-SP-NOT: stack-protector
 
-// NO-SP-ASAN-NOT: stack-protector
-// NO-SP-ASAN: "-fsanitize=address,safe-stack"
-// NO-SP-ASAN-NOT: stack-protector
-
 // RUN: %clang -target powerpc64-unknown-linux-gnu -fsanitize=memory %s -### 
2>&1 | FileCheck %s -check-prefix=CHECK-SANM
 // RUN: %clang -target powerpc64le-unknown-linux-gnu -fsanitize=memory %s -### 
2>&1 | FileCheck %s -check-prefix=CHECK-SANM
 // CHECK-SANM: "-fsanitize=memory"
Index: cfe/trunk/lib/Driver/SanitizerArgs.cpp
===
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp
@@ -378,7 +378,9 @@
   std::make_pair(Efficiency, Address | HWAddress | Leak | Thread | Memory |
  KernelAddress),
   std::make_pair(Scudo, Address | HWAddress | Leak | Thread | Memory |
-KernelAddress | Efficiency)};
+KernelAddress | Efficiency),
+  std::make_pair(SafeStack, Address | HWAddress | Leak | Thread | Memory |
+KernelAddress | Efficiency)};
   for (auto G : IncompatibleGroups) {
 SanitizerMask Group = G.first;
 if (Kinds & Group) {


Index: cfe/trunk/test/Driver/fsanitize.c
===
--- cfe/trunk/test/Driver/fsanitize.c
+++ cfe/trunk/test/Driver/fsanitize.c
@@ -526,22 +526,19 @@
 // NOSP-NOT: "-fsanitize=safe-stack"
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP
-// RUN: %clang -target x86_64-linux-gnu -fsanitize=address,safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP-ASAN
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address,safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP-ASAN
 // RUN: %clang -target x86_64-linux-gnu -fstack-protector -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack -fstack-protector-all -### %s 2>&1 | FileCheck %s -check-prefix=SP
 // RUN: %clang -target arm-linux-androideabi -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP
 // RUN: %clang -target aarch64-linux-android -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP
 // RUN: %clang -target i386-contiki-unknown -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP
 // NO-SP-NOT: stack-protector
 // NO-SP: "-fsanitize=safe-stack"
+// SP-ASAN: error: invalid argument '-fsanitize=safe-stack' not allowed with '-fsanitize=address'
 // SP: "-fsanitize=safe-stack"
 // SP: -stack-protector
 // NO-SP-NOT: stack-protector
 
-// NO-SP-ASAN-NOT: stack-protector
-// NO-SP-ASAN: "-fsanitize=address,safe-stack"
-// NO-SP-ASAN-NOT: stack-protector
-
 // RUN: %clang -target powerpc64-unknown-linux-gnu -fsanitize=memory %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-SANM
 // RUN: %clang -target powerpc64le-unknown-linux-gnu -fsanitize=memory %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-SANM
 // CHECK-SANM: "-fsanitize=memory"
Index: cfe/trunk/lib/Dr

r326152 - Revert "Revert "[analyzer] Quickfix: do not overflow in calculating offset in RegionManager""

2018-02-26 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Mon Feb 26 16:05:04 2018
New Revision: 326152

URL: http://llvm.org/viewvc/llvm-project?rev=326152&view=rev
Log:
Revert "Revert "[analyzer] Quickfix: do not overflow in calculating offset in 
RegionManager""

This reverts commit c4cc41166d93178a3ddd4b2b5a685cf74a459247.

Revert and fix uninitialized read.

Added:
cfe/trunk/test/Analysis/region_store_overflow.c
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
cfe/trunk/test/Analysis/region-store.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp?rev=326152&r1=326151&r2=326152&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp Mon Feb 26 16:05:04 2018
@@ -23,6 +23,11 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Support/Debug.h"
+
+#include
+
+#define DEBUG_TYPE "MemRegion"
 
 using namespace clang;
 using namespace ento;
@@ -1149,6 +1154,36 @@ const SymbolicRegion *MemRegion::getSymb
   return nullptr;
 }
 
+/// Perform a given operation on two integers, return whether it overflows.
+/// Optionally write the resulting output into \p Res.
+static bool checkedOp(
+int64_t LHS,
+int64_t RHS,
+std::function Op,
+int64_t *Res = nullptr) {
+  llvm::APInt ALHS(/*BitSize=*/64, LHS, /*Signed=*/true);
+  llvm::APInt ARHS(/*BitSize=*/64, RHS, /*Signed=*/true);
+  bool Overflow;
+  llvm::APInt Out = Op(&ALHS, ARHS, Overflow);
+  if (!Overflow && Res)
+*Res = Out.getSExtValue();
+  return Overflow;
+}
+
+static bool checkedAdd(
+int64_t LHS,
+int64_t RHS,
+int64_t *Res=nullptr) {
+  return checkedOp(LHS, RHS, &llvm::APInt::sadd_ov, Res);
+}
+
+static bool checkedMul(
+int64_t LHS,
+int64_t RHS,
+int64_t *Res=nullptr) {
+  return checkedOp(LHS, RHS, &llvm::APInt::smul_ov, Res);
+}
+
 RegionRawOffset ElementRegion::getAsArrayOffset() const {
   CharUnits offset = CharUnits::Zero();
   const ElementRegion *ER = this;
@@ -1176,6 +1211,18 @@ RegionRawOffset ElementRegion::getAsArra
 }
 
 CharUnits size = C.getTypeSizeInChars(elemType);
+
+int64_t Mult;
+bool Overflow = checkedAdd(i, size.getQuantity(), &Mult);
+if (!Overflow)
+  Overflow = checkedMul(Mult, offset.getQuantity());
+if (Overflow) {
+  DEBUG(llvm::dbgs() << "MemRegion::getAsArrayOffset: "
+ << "offset overflowing, returning unknown\n");
+
+  return nullptr;
+}
+
 offset += (i * size);
   }
 

Modified: cfe/trunk/test/Analysis/region-store.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/region-store.cpp?rev=326152&r1=326151&r2=326152&view=diff
==
--- cfe/trunk/test/Analysis/region-store.cpp (original)
+++ cfe/trunk/test/Analysis/region-store.cpp Mon Feb 26 16:05:04 2018
@@ -25,4 +25,4 @@ int radar13445834(Derived *Builder, Loc
   Builder->setLoc(l);
   return Builder->accessBase();
   
-}
\ No newline at end of file
+}

Added: cfe/trunk/test/Analysis/region_store_overflow.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/region_store_overflow.c?rev=326152&view=auto
==
--- cfe/trunk/test/Analysis/region_store_overflow.c (added)
+++ cfe/trunk/test/Analysis/region_store_overflow.c Mon Feb 26 16:05:04 2018
@@ -0,0 +1,13 @@
+// REQUIRES: asserts
+// RUN: %clang_analyze_cc1 -analyze -analyzer-checker=core -mllvm -debug %s 
2>&1 | FileCheck %s
+
+int **h;
+int overflow_in_memregion(long j) {
+  for (int l = 0;; ++l) {
+if (j - l > 0)
+  return h[j - l][0]; // no-crash
+  }
+  return 0;
+}
+// CHECK: {{.*}}
+// CHECK: MemRegion::getAsArrayOffset: offset overflowing, returning unknown


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


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

2018-02-26 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tidy/fuchsia/CMakeLists.txt:8
   OverloadedOperatorCheck.cpp
+  RestrictIncludesCheck.cpp
   StaticallyConstructedObjectsCheck.cpp

Will be good idea to be have consistent name and documentation terminology: 
include versus header.



Comment at: clang-tidy/fuchsia/RestrictIncludesCheck.cpp:48
+
+  typedef std::vector FileIncludes;
+  std::map IncludeDirectives;

Please use using and run Clang-tidy modernize.



Comment at: clang-tidy/fuchsia/RestrictIncludesCheck.cpp:70
+  for (auto &Bucket : IncludeDirectives) {
+auto &FileDirectives = Bucket.second;
+

Please don't use auto here, since type is not obvious.



Comment at: clang-tidy/fuchsia/RestrictIncludesCheck.cpp:80
+  unsigned ToLen =
+  std::strcspn(SM.getCharacterData(Include.Range.getBegin()), "\n") + 
1;
+  auto ToRange = CharSourceRange::getCharRange(

Please include .



Comment at: clang-tidy/fuchsia/RestrictIncludesCheck.cpp:81
+  std::strcspn(SM.getCharacterData(Include.Range.getBegin()), "\n") + 
1;
+  auto ToRange = CharSourceRange::getCharRange(
+  Include.Loc, ToLoc.getLocWithOffset(ToLen));

Please don't use auto here, since type is not obvious.



Comment at: clang-tidy/fuchsia/RestrictIncludesCheck.cpp:101
+  Compiler.getPreprocessor().addPPCallbacks(
+  ::llvm::make_unique(
+  *this, Compiler.getSourceManager()));

I don't think that you should prefix llvm with ::



Comment at: clang-tidy/fuchsia/RestrictIncludesCheck.h:25
+class RestrictIncludesCheck : public ClangTidyCheck {
+ public:
+  RestrictIncludesCheck(StringRef Name, ClangTidyContext *Context)

Please run Clang-format over code.



Comment at: clang-tidy/fuchsia/RestrictIncludesCheck.h:30
+Options.get("Includes", "::std::vector"))) {}
+  void registerPPCallbacks(CompilerInstance &Compiler) override;
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;

Please separate constructor with empty line from rest of methods.


https://reviews.llvm.org/D43778



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


[PATCH] D43791: [analyzer] Suppress MallocChecker positives in destructors with atomics.

2018-02-26 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/MallocChecker.cpp:527
   private:
+bool shouldSuppressOnAtomicReferenceCountingPointers(
+const Stmt *S, const LocationContext *CurrentLC);

Docstring.



Comment at: lib/StaticAnalyzer/Checkers/MallocChecker.cpp:2847
+
+  AtomicExpr::AtomicOp Op = AE->getOp();
+  if (Op != AtomicExpr::AO__c11_atomic_fetch_add &&

IMO would be slightly easier to read with logic reversed, e.g.

```
if (AE == dyn_cast<>(...))
   if (Op == add || Op == sub)
  for (...)
if (...)
  return true
return false
```

But this is a preference and can be ignored.



Comment at: lib/StaticAnalyzer/Checkers/MallocChecker.cpp:2899
+  // to find out if a likely-false-positive suppression should kick in.
+  for (const LocationContext *LC = CurrentLC; LC; LC = LC->getParent()) {
+if (isa(LC->getDecl())) {

I'm not sure what is going on here.
We are just traversing the stack frame, finding the first destructor in the 
`isReleased` branch?


Repository:
  rC Clang

https://reviews.llvm.org/D43791



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


  1   2   >