[PATCH] D87163: [DSE] Switch to MemorySSA-backed DSE by default.

2020-09-14 Thread Mikael Holmén via Phabricator via cfe-commits
uabelho added a comment.

Hi,

I'm seeing what I think is a miscompile with this:

  opt -S -dse -o - dse.ll

on

  @x = global [10 x [10 x i16]] zeroinitializer, align 1
  
  define i16 @f() {
  entry:
br label %do.body
  
  do.body:  ; preds = %if.end, %entry
%i.0 = phi i16 [ 0, %entry ], [ %inc, %if.end ]
%j.0 = phi i16 [ 0, %entry ], [ %add, %if.end ]
%arrayidx2 = getelementptr inbounds [10 x [10 x i16]], [10 x [10 x i16]]* 
@x, i16 0, i16 %i.0, i16 %j.0
store i16 2, i16* %arrayidx2, align 1
%exitcond = icmp eq i16 %i.0, 4
br i1 %exitcond, label %if.end10, label %if.end
  
  if.end:   ; preds = %do.body
%inc = add nuw nsw i16 %i.0, 1
%add = add nuw nsw i16 %j.0, 2
br label %do.body
  
  if.end10: ; preds = %do.body
store i16 1, i16* %arrayidx2, align 1
ret i16 0
  }

gives

  x = global [10 x [10 x i16]] zeroinitializer, align 1
  
  define i16 @f() {
  entry:
br label %do.body
  
  do.body:  ; preds = %if.end, %entry
%i.0 = phi i16 [ 0, %entry ], [ %inc, %if.end ]
%j.0 = phi i16 [ 0, %entry ], [ %add, %if.end ]
%arrayidx2 = getelementptr inbounds [10 x [10 x i16]], [10 x [10 x i16]]* 
@x, i16 0, i16 %i.0, i16 %j.0
%exitcond = icmp eq i16 %i.0, 4
br i1 %exitcond, label %if.end10, label %if.end
  
  if.end:   ; preds = %do.body
%inc = add nuw nsw i16 %i.0, 1
%add = add nuw nsw i16 %j.0, 2
br label %do.body
  
  if.end10: ; preds = %do.body
store i16 1, i16* %arrayidx2, align 1
ret i16 0
  }

So the store in the loop has been removed, which I think is incorrect.
The

  store i16 2

in the loop should be carried out at (i,j) == (0,0), (1,2), (2,4), (3,6) och 
(4,8) and then the last of them should be overwritten by the

  store i16 1

after the loop, but now the store in the loop is removed so we're only left 
with a written 1 at (4,8).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87163/new/

https://reviews.llvm.org/D87163

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


[PATCH] D83144: Allow to specify macro names for android-comparison-in-temp-failure-retry.

2020-09-14 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.

Looks good modulo comment.




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/android-comparison-in-temp-failure-retry-custom-macro.c:25
+void with_custom_macro() {
+  MY_TEMP_FAILURE_RETRY((foo()));
+  MY_TEMP_FAILURE_RETRY((int)(foo() == 1));

Are the extra parentheses required for the macro to work? Can it be just 
`MY_TEMP_FAILURE_RETRY(foo());` ?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83144/new/

https://reviews.llvm.org/D83144

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


[PATCH] D87587: [clang-format] Make one-line namespaces resistant to FixNamespaceComments, update documentation

2020-09-14 Thread Krystian Kuzniarek via Phabricator via cfe-commits
kuzkry added a comment.

Thanks @JakeMerdichAMD for your quick feedback.

> In any case, can you also add the full diff context? It makes it easier for 
> us to review.

I'll do that starting from the next patch because I'm afraid if I resubmit the 
longer version of the same patch, your comment would be hidden or considered 
obsolete as it would refer to an older revision.




Comment at: clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp:426-428
+  EXPECT_EQ("namespace A { a }// namespace A",
+fixNamespaceEndComments("namespace A { a }"));
+  EXPECT_EQ("namespace A { a };// namespace A",

JakeMerdichAMD wrote:
> I strongly believe that these ones are not correct. Namespaces that are 
> entirely on one line should never have a trailing comment, even if it has 
> content in it. 
> 
> A solution would also have to take into account whether future passes would 
> split this onto separate lines (and thus have a different result after 
> re-running clang-format), which was the reason for this limitation in the 
> first place. 
You're absolutely right. Btw. do you happen to know which style option controls 
this behaviour that splits these namespaces onto separate lines?
Anyway, I'm going to look into this in a few days.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87587/new/

https://reviews.llvm.org/D87587

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


[PATCH] D87598: [SyntaxTree][List] Fix: `ParameterDeclarationList` is the `List` inside `ParametersAndQualifiers`

2020-09-14 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
eduucaldas added a reviewer: gribozavr2.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87598

Files:
  clang/lib/Tooling/Syntax/Tree.cpp


Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -366,7 +366,7 @@
   case NodeKind::NestedNameSpecifier:
 return clang::tok::coloncolon;
   case NodeKind::CallArguments:
-  case NodeKind::ParametersAndQualifiers:
+  case NodeKind::ParameterDeclarationList:
 return clang::tok::comma;
   default:
 llvm_unreachable("This is not a subclass of List, thus "
@@ -379,7 +379,7 @@
   case NodeKind::NestedNameSpecifier:
 return TerminationKind::Terminated;
   case NodeKind::CallArguments:
-  case NodeKind::ParametersAndQualifiers:
+  case NodeKind::ParameterDeclarationList:
 return TerminationKind::Separated;
   default:
 llvm_unreachable("This is not a subclass of List, thus "
@@ -393,7 +393,7 @@
 return false;
   case NodeKind::CallArguments:
 return true;
-  case NodeKind::ParametersAndQualifiers:
+  case NodeKind::ParameterDeclarationList:
 return true;
   default:
 llvm_unreachable("This is not a subclass of List, thus canBeEmpty() "


Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -366,7 +366,7 @@
   case NodeKind::NestedNameSpecifier:
 return clang::tok::coloncolon;
   case NodeKind::CallArguments:
-  case NodeKind::ParametersAndQualifiers:
+  case NodeKind::ParameterDeclarationList:
 return clang::tok::comma;
   default:
 llvm_unreachable("This is not a subclass of List, thus "
@@ -379,7 +379,7 @@
   case NodeKind::NestedNameSpecifier:
 return TerminationKind::Terminated;
   case NodeKind::CallArguments:
-  case NodeKind::ParametersAndQualifiers:
+  case NodeKind::ParameterDeclarationList:
 return TerminationKind::Separated;
   default:
 llvm_unreachable("This is not a subclass of List, thus "
@@ -393,7 +393,7 @@
 return false;
   case NodeKind::CallArguments:
 return true;
-  case NodeKind::ParametersAndQualifiers:
+  case NodeKind::ParameterDeclarationList:
 return true;
   default:
 llvm_unreachable("This is not a subclass of List, thus canBeEmpty() "
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87599: [SyntaxTree] Provide `List::classof`

2020-09-14 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
eduucaldas added a reviewer: gribozavr2.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87599

Files:
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/lib/Tooling/Syntax/Tree.cpp


Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -273,6 +273,17 @@
   return nullptr;
 }
 
+bool classof(const syntax::Node *N) {
+  switch (N->getKind()) {
+  case syntax::NodeKind::NestedNameSpecifier:
+  case syntax::NodeKind::CallArguments:
+  case syntax::NodeKind::ParameterDeclarationList:
+return true;
+  default:
+return false;
+  }
+}
+
 std::vector>
 syntax::List::getElementsAsNodesAndDelimiters() {
   if (!getFirstChild())
Index: clang/include/clang/Tooling/Syntax/Tree.h
===
--- clang/include/clang/Tooling/Syntax/Tree.h
+++ clang/include/clang/Tooling/Syntax/Tree.h
@@ -213,6 +213,7 @@
   };
 
   using Tree::Tree;
+  static bool classof(const Node *N);
   /// Returns the elements and corresponding delimiters. Missing elements
   /// and delimiters are represented as null pointers.
   ///


Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -273,6 +273,17 @@
   return nullptr;
 }
 
+bool classof(const syntax::Node *N) {
+  switch (N->getKind()) {
+  case syntax::NodeKind::NestedNameSpecifier:
+  case syntax::NodeKind::CallArguments:
+  case syntax::NodeKind::ParameterDeclarationList:
+return true;
+  default:
+return false;
+  }
+}
+
 std::vector>
 syntax::List::getElementsAsNodesAndDelimiters() {
   if (!getFirstChild())
Index: clang/include/clang/Tooling/Syntax/Tree.h
===
--- clang/include/clang/Tooling/Syntax/Tree.h
+++ clang/include/clang/Tooling/Syntax/Tree.h
@@ -213,6 +213,7 @@
   };
 
   using Tree::Tree;
+  static bool classof(const Node *N);
   /// Returns the elements and corresponding delimiters. Missing elements
   /// and delimiters are represented as null pointers.
   ///
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87600: [SyntaxTree][List] `assertInvariants` for `List`s

2020-09-14 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
eduucaldas added a reviewer: gribozavr2.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87600

Files:
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/lib/Tooling/Syntax/Tree.cpp


Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -232,6 +232,19 @@
 assert(!C->isDetached());
 assert(C->getParent() == T);
   }
+
+  auto *L = dyn_cast(T);
+  if (!L)
+return;
+  for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
+assert(C->getRole() == NodeRole::ListElement ||
+   C->getRole() == NodeRole::ListDelimiter);
+if (C->getRole() == NodeRole::ListDelimiter) {
+  assert(isa(C));
+  assert(cast(C)->getToken()->kind() == L->getDelimiterTokenKind());
+}
+  }
+
 #endif
 }
 
@@ -372,7 +385,7 @@
   return children;
 }
 
-clang::tok::TokenKind syntax::List::getDelimiterTokenKind() {
+clang::tok::TokenKind syntax::List::getDelimiterTokenKind() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return clang::tok::coloncolon;
@@ -385,7 +398,7 @@
   }
 }
 
-syntax::List::TerminationKind syntax::List::getTerminationKind() {
+syntax::List::TerminationKind syntax::List::getTerminationKind() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return TerminationKind::Terminated;
@@ -398,7 +411,7 @@
   }
 }
 
-bool syntax::List::canBeEmpty() {
+bool syntax::List::canBeEmpty() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return false;
Index: clang/include/clang/Tooling/Syntax/Tree.h
===
--- clang/include/clang/Tooling/Syntax/Tree.h
+++ clang/include/clang/Tooling/Syntax/Tree.h
@@ -237,16 +237,16 @@
   ///
   /// Useful for discovering the correct delimiter to use when adding
   /// elements to empty or one-element lists.
-  clang::tok::TokenKind getDelimiterTokenKind();
+  clang::tok::TokenKind getDelimiterTokenKind() const;
 
-  TerminationKind getTerminationKind();
+  TerminationKind getTerminationKind() const;
 
   /// Whether this list can be empty in syntactically and semantically correct
   /// code.
   ///
   /// This list may be empty when the source code has errors even if
   /// canBeEmpty() returns false.
-  bool canBeEmpty();
+  bool canBeEmpty() const;
 };
 
 } // namespace syntax


Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -232,6 +232,19 @@
 assert(!C->isDetached());
 assert(C->getParent() == T);
   }
+
+  auto *L = dyn_cast(T);
+  if (!L)
+return;
+  for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
+assert(C->getRole() == NodeRole::ListElement ||
+   C->getRole() == NodeRole::ListDelimiter);
+if (C->getRole() == NodeRole::ListDelimiter) {
+  assert(isa(C));
+  assert(cast(C)->getToken()->kind() == L->getDelimiterTokenKind());
+}
+  }
+
 #endif
 }
 
@@ -372,7 +385,7 @@
   return children;
 }
 
-clang::tok::TokenKind syntax::List::getDelimiterTokenKind() {
+clang::tok::TokenKind syntax::List::getDelimiterTokenKind() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return clang::tok::coloncolon;
@@ -385,7 +398,7 @@
   }
 }
 
-syntax::List::TerminationKind syntax::List::getTerminationKind() {
+syntax::List::TerminationKind syntax::List::getTerminationKind() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return TerminationKind::Terminated;
@@ -398,7 +411,7 @@
   }
 }
 
-bool syntax::List::canBeEmpty() {
+bool syntax::List::canBeEmpty() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return false;
Index: clang/include/clang/Tooling/Syntax/Tree.h
===
--- clang/include/clang/Tooling/Syntax/Tree.h
+++ clang/include/clang/Tooling/Syntax/Tree.h
@@ -237,16 +237,16 @@
   ///
   /// Useful for discovering the correct delimiter to use when adding
   /// elements to empty or one-element lists.
-  clang::tok::TokenKind getDelimiterTokenKind();
+  clang::tok::TokenKind getDelimiterTokenKind() const;
 
-  TerminationKind getTerminationKind();
+  TerminationKind getTerminationKind() const;
 
   /// Whether this list can be empty in syntactically and semantically correct
   /// code.
   ///
   /// This list may be empty when the source code has errors even if
   /// canBeEmpty() returns false.
-  bool canBeEmpty();
+  bool canBeEmpty() const;
 };
 
 } // namespace syntax
___
cfe-commits mailing list
cfe-comm

[PATCH] D87450: [clangd] Implement hot index reloading for clangd-index-server

2020-09-14 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 291508.
kbobyrev marked 7 inline comments as done.
kbobyrev added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87450/new/

https://reviews.llvm.org/D87450

Files:
  clang-tools-extra/clangd/index/remote/server/Server.cpp

Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -12,15 +12,22 @@
 #include "index/Symbol.h"
 #include "index/remote/marshalling/Marshalling.h"
 #include "support/Logger.h"
+#include "support/Shutdown.h"
 #include "support/Trace.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Chrono.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/VirtualFileSystem.h"
 
+#include 
 #include 
 #include 
+#include 
+#include 
 
 #include "Index.grpc.pb.h"
 
@@ -63,15 +70,10 @@
 "server-address", llvm::cl::init("0.0.0.0:50051"),
 llvm::cl::desc("Address of the invoked server. Defaults to 0.0.0.0:50051"));
 
-std::unique_ptr openIndex(llvm::StringRef Index) {
-  return loadIndex(Index, /*UseIndex=*/true);
-}
-
 class RemoteIndexServer final : public SymbolIndex::Service {
 public:
-  RemoteIndexServer(std::unique_ptr Index,
-llvm::StringRef IndexRoot)
-  : Index(std::move(Index)) {
+  RemoteIndexServer(clangd::SymbolIndex &Index, llvm::StringRef IndexRoot)
+  : Index(Index) {
 llvm::SmallString<256> NativePath = IndexRoot;
 llvm::sys::path::native(NativePath);
 ProtobufMarshaller = std::unique_ptr(new Marshaller(
@@ -91,7 +93,7 @@
 }
 unsigned Sent = 0;
 unsigned FailedToSend = 0;
-Index->lookup(*Req, [&](const clangd::Symbol &Item) {
+Index.lookup(*Req, [&](const clangd::Symbol &Item) {
   auto SerializedItem = ProtobufMarshaller->toProtobuf(Item);
   if (!SerializedItem) {
 elog("Unable to convert Symbol to protobuf: {0}",
@@ -124,7 +126,7 @@
 }
 unsigned Sent = 0;
 unsigned FailedToSend = 0;
-bool HasMore = Index->fuzzyFind(*Req, [&](const clangd::Symbol &Item) {
+bool HasMore = Index.fuzzyFind(*Req, [&](const clangd::Symbol &Item) {
   auto SerializedItem = ProtobufMarshaller->toProtobuf(Item);
   if (!SerializedItem) {
 elog("Unable to convert Symbol to protobuf: {0}",
@@ -155,7 +157,7 @@
 }
 unsigned Sent = 0;
 unsigned FailedToSend = 0;
-bool HasMore = Index->refs(*Req, [&](const clangd::Ref &Item) {
+bool HasMore = Index.refs(*Req, [&](const clangd::Ref &Item) {
   auto SerializedItem = ProtobufMarshaller->toProtobuf(Item);
   if (!SerializedItem) {
 elog("Unable to convert Ref to protobuf: {0}",
@@ -188,7 +190,7 @@
 }
 unsigned Sent = 0;
 unsigned FailedToSend = 0;
-Index->relations(
+Index.relations(
 *Req, [&](const SymbolID &Subject, const clangd::Symbol &Object) {
   auto SerializedItem = ProtobufMarshaller->toProtobuf(Subject, Object);
   if (!SerializedItem) {
@@ -210,22 +212,57 @@
 return grpc::Status::OK;
   }
 
-  std::unique_ptr Index;
   std::unique_ptr ProtobufMarshaller;
+  clangd::SymbolIndex &Index;
 };
 
-void runServer(std::unique_ptr Index,
-   const std::string &ServerAddress) {
-  RemoteIndexServer Service(std::move(Index), IndexRoot);
+// Detect changes in \p IndexPath file and load new versions of the index
+// whenever they become available.
+void hotReload(clangd::SwapIndex *Index, llvm::StringRef IndexPath,
+   llvm::sys::fs::file_status &LastStatus) {
+  llvm::sys::fs::file_status Status;
+  const auto EC = llvm::sys::fs::status(IndexPath, Status, /*Follow=*/true);
+  if (EC)
+return;
+  const auto NewModificationTime = Status.getLastModificationTime();
+  // Current index is newer than the one before: no reload is needed.
+  if (NewModificationTime <= LastStatus.getLastModificationTime())
+return;
+  vlog("Found new index version: existing index was modified at {0}, new "
+   "index was modified at {1}. Attempting to reload.",
+   LastStatus.getLastModificationTime(), NewModificationTime);
+  std::unique_ptr NewIndex = loadIndex(IndexPath);
+  if (!NewIndex) {
+vlog("Failed to load new index. Old index will be served.");
+return;
+  }
+  Index->reset(std::move(NewIndex));
+  log("New index version loaded. Last modification time: {0}.",
+  NewModificationTime);
+  LastStatus = Status;
+}
+
+void runServer(clangd::SymbolIndex *Index, llvm::StringRef ServerAddress,
+   llvm::StringRef IndexPath) {
+  RemoteIndexServer Service(*Index, IndexRoot);
 
   grpc::EnableDefaultHealthCheckService(true);
   grpc::ServerBuilder Builder;

[PATCH] D87450: [clangd] Implement hot index reloading for clangd-index-server

2020-09-14 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev added inline comments.



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:226
+  llvm::sys::TimePoint<> LastModificationTime =
+  std::chrono::system_clock::now();
+  for (;; std::this_thread::sleep_for(std::chrono::seconds(90))) {

kadircet wrote:
> i think we should rather store the file_status from the original file in 
> here. as we want to reload whenever files size/modification_time has changed.
> it doesn't have to be moving forward let alone share the same timezone 
> restrictions and such provided by system_clock::now.
> 
> Also it would be nice to use a VFS in here, that way we can move this logic 
> into a helper in the future if other components need similar logic.
Can you elaborate more on VFS usage? I'm not sure how this would improve 
existing and potential future code over plain `llvm::sys::*` calls.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87450/new/

https://reviews.llvm.org/D87450

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


[PATCH] D86694: [scudo] Allow -fsanitize=scudo on Linux and Windows (WIP, don't land as is)

2020-09-14 Thread Russell Gallop via Phabricator via cfe-commits
russell.gallop updated this revision to Diff 291511.
russell.gallop added a comment.

Re-upload patch with G LLVM Github Monorepo set.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86694/new/

https://reviews.llvm.org/D86694

Files:
  clang/lib/Driver/ToolChains/MSVC.cpp
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
  compiler-rt/lib/scudo/CMakeLists.txt
  compiler-rt/lib/scudo/scudo_allocator.cpp
  compiler-rt/lib/scudo/scudo_crc32.cpp
  compiler-rt/lib/scudo/scudo_new_delete.cpp
  compiler-rt/lib/scudo/scudo_platform.h
  compiler-rt/lib/scudo/scudo_tsd.h
  compiler-rt/lib/scudo/scudo_tsd_shared.cpp
  compiler-rt/lib/scudo/scudo_tsd_shared.inc
  compiler-rt/test/sanitizer_common/CMakeLists.txt
  compiler-rt/test/scudo/interface.cpp
  compiler-rt/test/scudo/lit.cfg.py
  compiler-rt/test/scudo/malloc.cpp
  compiler-rt/test/scudo/memalign.c
  compiler-rt/test/scudo/mismatch.cpp
  compiler-rt/test/scudo/overflow.c
  compiler-rt/test/scudo/preload.cpp
  compiler-rt/test/scudo/rss.c
  compiler-rt/test/scudo/secondary.c
  compiler-rt/test/scudo/threads.c
  compiler-rt/test/scudo/tsd_destruction.c
  compiler-rt/test/scudo/valloc.c
  llvm/CMakeLists.txt
  llvm/cmake/modules/HandleLLVMOptions.cmake
  llvm/lib/Support/CMakeLists.txt

Index: llvm/lib/Support/CMakeLists.txt
===
--- llvm/lib/Support/CMakeLists.txt
+++ llvm/lib/Support/CMakeLists.txt
@@ -73,7 +73,7 @@
   string(REGEX REPLACE "(/|)$" "" LLVM_INTEGRATED_CRT_ALLOC "${LLVM_INTEGRATED_CRT_ALLOC}")
 
   if(NOT EXISTS "${LLVM_INTEGRATED_CRT_ALLOC}")
-message(FATAL_ERROR "Cannot find the path to `git clone` for the CRT allocator! (${LLVM_INTEGRATED_CRT_ALLOC}). Currently, rpmalloc, snmalloc and mimalloc are supported.")
+message(FATAL_ERROR "Cannot find the path to `git clone` for the CRT allocator! (${LLVM_INTEGRATED_CRT_ALLOC}). Currently, rpmalloc, snmalloc, mimalloc and scudo are supported.")
   endif()
 
   if(LLVM_INTEGRATED_CRT_ALLOC MATCHES "rpmalloc$")
@@ -89,6 +89,8 @@
 	  message(FATAL_ERROR "Cannot find the mimalloc static library. To build it, first apply the patch from https://github.com/microsoft/mimalloc/issues/268 then build the Release x64 target through ${LLVM_INTEGRATED_CRT_ALLOC}\\ide\\vs2019\\mimalloc.sln")
 endif()
 set(system_libs ${system_libs} "${MIMALLOC_LIB}" "-INCLUDE:malloc")
+  elseif(LLVM_INTEGRATED_CRT_ALLOC MATCHES "scudo")
+  set(system_libs ${system_libs} "${LLVM_INTEGRATED_CRT_ALLOC}" "-INCLUDE:malloc")
   endif()
 endif()
 
Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -789,6 +789,9 @@
 elseif (LLVM_USE_SANITIZER STREQUAL "Leaks")
   append_common_sanitizer_flags()
   append("-fsanitize=leak" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+elseif (LLVM_USE_SANITIZER STREQUAL "Scudo")
+  append_common_sanitizer_flags()
+  append("-fsanitize=scudo" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
 else()
   message(FATAL_ERROR "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}")
 endif()
@@ -796,6 +799,9 @@
 if (LLVM_USE_SANITIZER STREQUAL "Address")
   append_common_sanitizer_flags()
   append("-fsanitize=address" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+elseif (LLVM_USE_SANITIZER STREQUAL "Scudo")
+  append_common_sanitizer_flags()
+  append("-fsanitize=scudo" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
 else()
   message(FATAL_ERROR "This sanitizer not yet supported in the MSVC environment: ${LLVM_USE_SANITIZER}")
 endif()
Index: llvm/CMakeLists.txt
===
--- llvm/CMakeLists.txt
+++ llvm/CMakeLists.txt
@@ -572,8 +572,8 @@
   if(NOT WIN32)
 message(FATAL_ERROR "LLVM_INTEGRATED_CRT_ALLOC is only supported on Windows.")
   endif()
-  if(LLVM_USE_SANITIZER)
-message(FATAL_ERROR "LLVM_INTEGRATED_CRT_ALLOC cannot be used along with LLVM_USE_SANITIZER!")
+  if(LLVM_USE_SANITIZER AND NOT LLVM_USE_SANITIZER STREQUAL "Scudo")
+message(FATAL_ERROR "LLVM_INTEGRATED_CRT_ALLOC cannot be used along with LLVM_USE_SANITIZER (apart from Scudo)!")
   endif()
   if(CMAKE_BUILD_TYPE AND uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
 message(FATAL_ERROR "The Debug target isn't supported along with LLVM_INTEGRATED_CRT_ALLOC!")
Index: compiler-rt/test/scudo/valloc.c
===
--- compiler-rt/test/scudo/valloc.c
+++ compiler-rt/test/scudo/valloc.c
@@ -2,7 +2,7 @@
 // RUN: %run %t valid   2>&1
 // RUN: not %run %t invalid 2>&1 | FileCheck %s
 // RUN: %env_scudo_opts=allocator_may_return_null=1 %run %t invalid 2>&1
-// UNSUPPORTED: android
+// UNSUPPOR

[PATCH] D87528: Enable '#pragma STDC FENV_ACCESS' in frontend cf. D69272 - Work in Progress

2020-09-14 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D87528#2270561 , @rjmccall wrote:

> Richard, what do you think the right rule is for when to use the special 
> constant-evaluation rules for this feature in C++?  The C standard says that 
> constant expressions should use the default rules rather than considering the 
> dynamic environment, but C can get away with that because constant 
> expressions are restricted to a narrow set of syntactic situations.

Right, C has a lot of leeway here because floating-point operations aren't 
allowed in integer constant expressions in C; the only place FP operations are 
guaranteed to be evaluated during translation is in the initializers of 
variables of static storage duration, which are all notionally initialized 
before the program begins executing (and thus before a non-default FP 
environment can be entered) anyway. Needing to deal with (for example) 
floating-point operations in array bounds is a novel C++ problem.

I think the broadest set of places we could consider assuming the default FP 
environment is manifestly constant evaluated 
 contexts; that's probably the most 
natural category in C++ for this kind of thing. That is the same condition 
under which `std::is_constant_evaluated()` returns `true`. (The "manifestly 
constant evaluated" property is already tracked within the constant evaluator 
by the `InConstantContext` flag.) And your list:

> - initializers for objects of static storage duration if they would be 
> constant initializers if they weren't covered by the pragma; this should 
> roughly align C and C++ semantics for things like `static const` within a 
> function
> - any `constexpr` / `constinit` context, and it should be ill-formed to use 
> the pragma in such a context; that is, it's ignored from outside and 
> prohibited (directly) inside

... roughly matches "manifestly constant evaluated". (Aside: I don't think we 
need to, or should, prohibit the pragma inside `constexpr` functions. We'll try 
to reject such functions anyway if they can't produce constant expressions, so 
a special case rule seems redundant, and such functions can legitimately 
contain code only intended for use in non-constant contexts. Disallowing it in 
`consteval` functions might be OK, but we don't disallow calls to 
non-`constexpr` functions from `consteval` functions, for which the same 
concerns would apply.)

"Manifestly constant evaluated" describes the set of expressions that an 
implementation is required to reduce to a constant, and covers two sets of 
cases:

- expressions for which the program is ill-formed if they're not constant: 
template arguments, array bounds, enumerators, case labels, `consteval` 
function calls, `constexpr` and `constinit` variables, concepts, constexpr if
- expressions whose semantics are potentially affected by constantness, and for 
which an implementation is required to guarantee to commit to the constant 
semantics whenever it can: when checking to see if a variable with 
static/thread storage duration has static initialization, or whether an 
automatic variable of reference or const-qualified integral type is usable in 
constant expressions

If we go that way, there'd be at least one class of surprising cases. Here's an 
example of it:

  void f() {
  #pragma STDC FENV_ACCESS ON
fesetround(FE_DOWNWARD);
CONST bool b = (1.0 / 3.0) * 3.0 < 1.0;
if (b) g();
fesetround(FE_TONEAREST);
  }

Under the "manifestly constant evaluated" rule, with `-DCONST=`, this would 
call `g()`, but with `-DCONST=const`, it would *not* call `g()`, because the 
initializer of `b` would be manifestly constant evaluated. That's both 
surprising and different from the behavior in C. (The surprise isn't novel; 
C++'s `std::is_constant_evaluated()` has the same surprising semantics. It's 
not completely unreasonable to claim that C++ says that reference and `const` 
integral variables are implicitly `constexpr` whenever they can be, though 
that's not how the rule is expressed.) Basing this off "manifestly constant 
evaluated" would also be C-incompatible in at least one other way: we'd treat 
FP operations in an array bound as being in the default FP environment in C++ 
if that makes the overall evaluation constant, but in C they always result in a 
VLA.

So I suppose the question is, are we comfortable with all that, or do we want 
to use a different rule?

There's another uninventive rule at the opposite end of the spectrum. Prior 
discussion in the C++ committee, before we had "manifestly constant evaluated" 
and associated machinery, seemed to be converging on this model:

1. constrained FP operations are always treated as non-constant in all 
contexts, and
2. in a C++ translation unit, the initial state for `FENV_ACCESS` is always 
`OFF`.

That approach has the advantage of being both simple and compatible with all 
code we currently support, as well as probably compatible

[clang-tools-extra] 30667c9 - [clangd] Add error() function for creating formatv-style llvm::Errors. NFC

2020-09-14 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-09-14T10:43:42+02:00
New Revision: 30667c967d3f420d3f53fb1c9c2465550a1112df

URL: 
https://github.com/llvm/llvm-project/commit/30667c967d3f420d3f53fb1c9c2465550a1112df
DIFF: 
https://github.com/llvm/llvm-project/commit/30667c967d3f420d3f53fb1c9c2465550a1112df.diff

LOG: [clangd] Add error() function for creating formatv-style llvm::Errors. NFC

Summary:
This is considerably terser than the makeStringError and friends, and
avoids verbosity cliffs that discourage adding log information.

It follows the syntax used in log/elog/vlog/dlog that have been successful.

The main caveats are:
 - it's strictly out-of-place in logger.h, though kind of fits thematically and
   in implementation
 - it claims the "error" identifier, which seems a bit too opinionated
   to put higher up in llvm

I've updated some users of StringError mostly at random - there are lots
more mechanical changes but I'd like to get this reviewed before making
them all.

Reviewers: kbobyrev, hokein

Subscribers: mgorny, ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, 
kadircet, usaxena95, cfe-commits

Tags: #clang

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

Added: 
clang-tools-extra/clangd/unittests/LoggerTests.cpp

Modified: 
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/DraftStore.cpp
clang-tools-extra/clangd/JSONTransport.cpp
clang-tools-extra/clangd/PathMapping.cpp
clang-tools-extra/clangd/RIFF.cpp
clang-tools-extra/clangd/TUScheduler.cpp
clang-tools-extra/clangd/index/Serialization.cpp
clang-tools-extra/clangd/support/Logger.cpp
clang-tools-extra/clangd/support/Logger.h
clang-tools-extra/clangd/unittests/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 6ebb71c3b4d1..4cc1feabb15f 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -147,13 +147,9 @@ llvm::Error validateEdits(const DraftStore &DraftMgr, 
const FileEdits &FE) {
   if (!InvalidFileCount)
 return llvm::Error::success();
   if (InvalidFileCount == 1)
-return llvm::createStringError(llvm::inconvertibleErrorCode(),
-   "File must be saved first: " +
-   LastInvalidFile);
-  return llvm::createStringError(
-  llvm::inconvertibleErrorCode(),
-  "Files must be saved first: " + LastInvalidFile + " (and " +
-  llvm::to_string(InvalidFileCount - 1) + " others)");
+return error("File must be saved first: {0}", LastInvalidFile);
+  return error("Files must be saved first: {0} (and {1} others)",
+   LastInvalidFile, InvalidFileCount - 1);
 }
 
 } // namespace
@@ -284,10 +280,9 @@ class ClangdLSPServer::MessageHandler : public 
Transport::MessageHandler {
   }
 }
 if (OldestCB)
-  OldestCB->second(llvm::createStringError(
-  llvm::inconvertibleErrorCode(),
-  llvm::formatv("failed to receive a client reply for request ({0})",
-OldestCB->first)));
+  OldestCB->second(
+  error("failed to receive a client reply for request ({0})",
+OldestCB->first));
 return ID;
   }
 
@@ -661,8 +656,7 @@ void ClangdLSPServer::onSync(const NoParams &Params,
   if (Server->blockUntilIdleForTest(/*TimeoutSeconds=*/60))
 Reply(nullptr);
   else
-Reply(llvm::createStringError(llvm::inconvertibleErrorCode(),
-  "Not idle after a minute"));
+Reply(error("Not idle after a minute"));
 }
 
 void ClangdLSPServer::onDocumentDidOpen(
@@ -729,9 +723,7 @@ void ClangdLSPServer::onCommand(const ExecuteCommandParams 
&Params,
 std::string Reason = Response->failureReason
  ? *Response->failureReason
  : "unknown reason";
-return Reply(llvm::createStringError(
-llvm::inconvertibleErrorCode(),
-("edits were not applied: " + Reason).c_str()));
+return Reply(error("edits were not applied: {0}", Reason));
   }
   return Reply(SuccessMessage);
 });
@@ -752,9 +744,7 @@ void ClangdLSPServer::onCommand(const ExecuteCommandParams 
&Params,
  Params.tweakArgs) {
 auto Code = DraftMgr.getDraft(Params.tweakArgs->file.file());
 if (!Code)
-  return Reply(llvm::createStringError(
-  llvm::inconvertibleErrorCode(),
-  "trying to apply a code action for a non-added file"));
+  return Reply(error("trying to apply a code action for a non-added 
file"));
 
 auto Action = [this, ApplyEdit, Reply = std::move(Reply),
File = Params.tweakArgs->fil

[PATCH] D83419: [clangd] Add error() function for creating formatv-style llvm::Errors. NFC

2020-09-14 Thread Sam McCall via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG30667c967d3f: [clangd] Add error() function for creating 
formatv-style llvm::Errors. NFC (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D83419?vs=276531&id=291515#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83419/new/

https://reviews.llvm.org/D83419

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/DraftStore.cpp
  clang-tools-extra/clangd/JSONTransport.cpp
  clang-tools-extra/clangd/PathMapping.cpp
  clang-tools-extra/clangd/RIFF.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/index/Serialization.cpp
  clang-tools-extra/clangd/support/Logger.cpp
  clang-tools-extra/clangd/support/Logger.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/LoggerTests.cpp

Index: clang-tools-extra/clangd/unittests/LoggerTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/LoggerTests.cpp
@@ -0,0 +1,62 @@
+//===-- LoggerTests.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "support/Logger.h"
+#include "llvm/Support/Errc.h"
+#include "llvm/Support/Error.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+TEST(ErrorTest, Overloads) {
+  EXPECT_EQ("foo", llvm::toString(error("foo")));
+  // Inconvertible to error code when none is specified.
+  // Don't actually try to convert, it'll crash.
+  handleAllErrors(error("foo"), [&](const llvm::ErrorInfoBase &EI) {
+EXPECT_EQ(llvm::inconvertibleErrorCode(), EI.convertToErrorCode());
+  });
+
+  EXPECT_EQ("foo 42", llvm::toString(error("foo {0}", 42)));
+  handleAllErrors(error("foo {0}", 42), [&](const llvm::ErrorInfoBase &EI) {
+EXPECT_EQ(llvm::inconvertibleErrorCode(), EI.convertToErrorCode());
+  });
+
+  EXPECT_EQ("foo", llvm::toString(error(llvm::errc::invalid_argument, "foo")));
+  EXPECT_EQ(llvm::errc::invalid_argument,
+llvm::errorToErrorCode(error(llvm::errc::invalid_argument, "foo")));
+
+  EXPECT_EQ("foo 42",
+llvm::toString(error(llvm::errc::invalid_argument, "foo {0}", 42)));
+  EXPECT_EQ(llvm::errc::invalid_argument,
+llvm::errorToErrorCode(
+error(llvm::errc::invalid_argument, "foo {0}", 42)));
+}
+
+TEST(ErrorTest, Lifetimes) {
+  llvm::Optional Err;
+  {
+// Check the error contains the value when error() was called.
+std::string S = "hello, world";
+Err = error("S={0}", llvm::StringRef(S));
+S = "garbage";
+  }
+  EXPECT_EQ("S=hello, world", llvm::toString(std::move(*Err)));
+}
+
+TEST(ErrorTest, ConsumeError) {
+  llvm::Error Foo = error("foo");
+  llvm::Error Bar = error("bar: {0}", std::move(Foo));
+  EXPECT_EQ("bar: foo", llvm::toString(std::move(Bar)));
+  // No assert for unchecked Foo.
+}
+
+} // namespace
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -62,6 +62,7 @@
   IndexActionTests.cpp
   IndexTests.cpp
   JSONTransportTests.cpp
+  LoggerTests.cpp
   LSPClient.cpp
   ModulesTests.cpp
   ParsedASTTests.cpp
Index: clang-tools-extra/clangd/support/Logger.h
===
--- clang-tools-extra/clangd/support/Logger.h
+++ clang-tools-extra/clangd/support/Logger.h
@@ -45,6 +45,8 @@
 void log(Logger::Level L, const char *Fmt, Ts &&... Vals) {
   detail::log(L, llvm::formatv(Fmt, detail::wrap(std::forward(Vals))...));
 }
+
+llvm::Error error(std::error_code, std::string &&);
 } // namespace detail
 
 // Clangd logging functions write to a global logger set by LoggingSession.
@@ -67,6 +69,30 @@
 template  void vlog(const char *Fmt, Ts &&... Vals) {
   detail::log(Logger::Verbose, Fmt, std::forward(Vals)...);
 }
+// error() constructs an llvm::Error object, using formatv()-style arguments.
+// It is not automatically logged! (This function is a little out of place).
+// The error simply embeds the message string.
+template 
+llvm::Error error(std::error_code EC, const char *Fmt, Ts &&... Vals) {
+  // We must render the formatv_object eagerly, while references are valid.
+  return detail::error(
+  EC, llvm::formatv(Fmt, detail::wrap(std::forwar

[PATCH] D87600: [SyntaxTree][List] `assertInvariants` for `List`s

2020-09-14 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Tooling/Syntax/Tree.cpp:236
+
+  auto *L = dyn_cast(T);
+  if (!L)





Comment at: clang/lib/Tooling/Syntax/Tree.cpp:241
+assert(C->getRole() == NodeRole::ListElement ||
+   C->getRole() == NodeRole::ListDelimiter);
+if (C->getRole() == NodeRole::ListDelimiter) {

This assertion is true only for trees that represent correct code. To cover all 
cases, add the unknown role.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87600/new/

https://reviews.llvm.org/D87600

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


[PATCH] D87450: [clangd] Implement hot index reloading for clangd-index-server

2020-09-14 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:226
+  llvm::sys::TimePoint<> LastModificationTime =
+  std::chrono::system_clock::now();
+  for (;; std::this_thread::sleep_for(std::chrono::seconds(90))) {

kbobyrev wrote:
> kadircet wrote:
> > i think we should rather store the file_status from the original file in 
> > here. as we want to reload whenever files size/modification_time has 
> > changed.
> > it doesn't have to be moving forward let alone share the same timezone 
> > restrictions and such provided by system_clock::now.
> > 
> > Also it would be nice to use a VFS in here, that way we can move this logic 
> > into a helper in the future if other components need similar logic.
> Can you elaborate more on VFS usage? I'm not sure how this would improve 
> existing and potential future code over plain `llvm::sys::*` calls.
it is mostly for unit testing the helper when there's a wider usage. also some 
users of clangd($Employer's internal editor) doesn't really have a real fs, 
they surface it through a VFS.

it also makes the code a little bit more easier to read, but definitely doesn't 
require immediate action, so up to you.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87450/new/

https://reviews.llvm.org/D87450

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


[PATCH] D87527: [ASTMatchers] Fix `hasBody` for the descendants of `FunctionDecl`

2020-09-14 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

> Unfortunately template specializations do not catch the descendants of the 
> class for which the template is specialized. Therefore it does not work 
> correcly for the descendants of FunctionDecl, such as CXXMethodDecl, 
> CXXConstructorDecl, CXXDestructorDecl etc. This patch fixes this issue by 
> using a template metaprogram.

Yes, implicit type conversions are not considered during template argument 
deduction.

First I was thinking about why don't we just simply specialize for all 
subclasses of FunctionDecl (CXXMethodDecl, CXXConstructorDecl, 
CXXDestructorDecl, etc) ?
But then I realized, your solution with enable_if is more generic and will work 
even if a new subclass is added. Looks good to me.




Comment at: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp:1468
+
+TEST(HasBody, FindsBodyOfFunctionChildren) {
+  EXPECT_TRUE(matchAndVerifyResultTrue(

FindsBodyOfFunctionDeclSubclasses ?



Comment at: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp:1471
+  "class C { void f(); }; void C::f() {}",
+  cxxMethodDecl(hasBody(compoundStmt())).bind("met"),
+  std::make_unique>("met", 1)));

"met" -> "method" ?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87527/new/

https://reviews.llvm.org/D87527

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


[clang-tools-extra] 574dd60 - [clangd] Track tweaks that fail the apply stage

2020-09-14 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-09-14T11:24:02+02:00
New Revision: 574dd60547179a2c143ac14cdd6f5f5a40156d54

URL: 
https://github.com/llvm/llvm-project/commit/574dd60547179a2c143ac14cdd6f5f5a40156d54
DIFF: 
https://github.com/llvm/llvm-project/commit/574dd60547179a2c143ac14cdd6f5f5a40156d54.diff

LOG: [clangd] Track tweaks that fail the apply stage

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

Added: 


Modified: 
clang-tools-extra/clangd/ClangdServer.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdServer.cpp 
b/clang-tools-extra/clangd/ClangdServer.cpp
index a571ff56ce4c..27d1a2dc7cdc 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -536,9 +536,12 @@ void ClangdServer::enumerateTweaks(PathRef File, Range Sel,
 
 void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID,
   Callback CB) {
-  // Tracks number of times a tweak has been applied.
+  // Tracks number of times a tweak has been attempted.
   static constexpr trace::Metric TweakAttempt(
   "tweak_attempt", trace::Metric::Counter, "tweak_id");
+  // Tracks number of times a tweak has failed to produce edits.
+  static constexpr trace::Metric TweakFailed(
+  "tweak_failed", trace::Metric::Counter, "tweak_id");
   TweakAttempt.record(1, TweakID);
   auto Action = [File = File.str(), Sel, TweakID = TweakID.str(),
  CB = std::move(CB),
@@ -569,6 +572,8 @@ void ClangdServer::applyTweak(PathRef File, Range Sel, 
StringRef TweakID,
 if (llvm::Error Err = reformatEdit(E, Style))
   elog("Failed to format {0}: {1}", It.first(), std::move(Err));
   }
+} else {
+  TweakFailed.record(1, TweakID);
 }
 return CB(std::move(*Effect));
   };



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


[PATCH] D87501: [clangd] Track tweaks that fail the apply stage

2020-09-14 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG574dd6054717: [clangd] Track tweaks that fail the apply 
stage (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87501/new/

https://reviews.llvm.org/D87501

Files:
  clang-tools-extra/clangd/ClangdServer.cpp


Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -536,9 +536,12 @@
 
 void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID,
   Callback CB) {
-  // Tracks number of times a tweak has been applied.
+  // Tracks number of times a tweak has been attempted.
   static constexpr trace::Metric TweakAttempt(
   "tweak_attempt", trace::Metric::Counter, "tweak_id");
+  // Tracks number of times a tweak has failed to produce edits.
+  static constexpr trace::Metric TweakFailed(
+  "tweak_failed", trace::Metric::Counter, "tweak_id");
   TweakAttempt.record(1, TweakID);
   auto Action = [File = File.str(), Sel, TweakID = TweakID.str(),
  CB = std::move(CB),
@@ -569,6 +572,8 @@
 if (llvm::Error Err = reformatEdit(E, Style))
   elog("Failed to format {0}: {1}", It.first(), std::move(Err));
   }
+} else {
+  TweakFailed.record(1, TweakID);
 }
 return CB(std::move(*Effect));
   };


Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -536,9 +536,12 @@
 
 void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID,
   Callback CB) {
-  // Tracks number of times a tweak has been applied.
+  // Tracks number of times a tweak has been attempted.
   static constexpr trace::Metric TweakAttempt(
   "tweak_attempt", trace::Metric::Counter, "tweak_id");
+  // Tracks number of times a tweak has failed to produce edits.
+  static constexpr trace::Metric TweakFailed(
+  "tweak_failed", trace::Metric::Counter, "tweak_id");
   TweakAttempt.record(1, TweakID);
   auto Action = [File = File.str(), Sel, TweakID = TweakID.str(),
  CB = std::move(CB),
@@ -569,6 +572,8 @@
 if (llvm::Error Err = reformatEdit(E, Style))
   elog("Failed to format {0}: {1}", It.first(), std::move(Err));
   }
+} else {
+  TweakFailed.record(1, TweakID);
 }
 return CB(std::move(*Effect));
   };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83144: Allow to specify macro names for android-comparison-in-temp-failure-retry.

2020-09-14 Thread Florian Mayer via Phabricator via cfe-commits
fmayer updated this revision to Diff 291520.
fmayer added a comment.

Added more simple cases to the test.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83144/new/

https://reviews.llvm.org/D83144

Files:
  clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.cpp
  clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.h
  
clang-tools-extra/docs/clang-tidy/checks/android-comparison-in-temp-failure-retry.rst
  
clang-tools-extra/test/clang-tidy/checkers/android-comparison-in-temp-failure-retry-custom-macro.c

Index: clang-tools-extra/test/clang-tidy/checkers/android-comparison-in-temp-failure-retry-custom-macro.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/android-comparison-in-temp-failure-retry-custom-macro.c
@@ -0,0 +1,46 @@
+// RUN: %check_clang_tidy %s android-comparison-in-temp-failure-retry %t -- -config="{CheckOptions: [{key: android-comparison-in-temp-failure-retry.RetryMacros, value: 'MY_TEMP_FAILURE_RETRY,MY_OTHER_TEMP_FAILURE_RETRY'}]}"
+
+#define MY_TEMP_FAILURE_RETRY(x) \
+  ({ \
+typeof(x) __z;   \
+do   \
+  __z = (x); \
+while (__z == -1);   \
+__z; \
+  })
+
+#define MY_OTHER_TEMP_FAILURE_RETRY(x) \
+  ({   \
+typeof(x) __z; \
+do \
+  __z = (x);   \
+while (__z == -1); \
+__z;   \
+  })
+
+int foo();
+int bar(int a);
+
+void with_custom_macro() {
+  MY_TEMP_FAILURE_RETRY(foo());
+  MY_TEMP_FAILURE_RETRY(foo() == 1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: top-level comparison in MY_TEMP_FAILURE_RETRY
+  MY_TEMP_FAILURE_RETRY((foo()));
+  MY_TEMP_FAILURE_RETRY((int)(foo() == 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: top-level comparison in MY_TEMP_FAILURE_RETRY
+  MY_TEMP_FAILURE_RETRY((bar(foo() == 1)));
+  MY_TEMP_FAILURE_RETRY((int)((bar(foo() == 1)) == 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:49: warning: top-level comparison in MY_TEMP_FAILURE_RETRY
+}
+
+void with_other_custom_macro() {
+  MY_OTHER_TEMP_FAILURE_RETRY(foo());
+  MY_OTHER_TEMP_FAILURE_RETRY(foo() == 1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:37: warning: top-level comparison in MY_OTHER_TEMP_FAILURE_RETRY
+  MY_OTHER_TEMP_FAILURE_RETRY((foo()));
+  MY_OTHER_TEMP_FAILURE_RETRY((int)(foo() == 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:43: warning: top-level comparison in MY_OTHER_TEMP_FAILURE_RETRY
+  MY_OTHER_TEMP_FAILURE_RETRY((bar(foo() == 1)));
+  MY_OTHER_TEMP_FAILURE_RETRY((int)((bar(foo() == 1)) == 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:55: warning: top-level comparison in MY_OTHER_TEMP_FAILURE_RETRY
+}
Index: clang-tools-extra/docs/clang-tidy/checks/android-comparison-in-temp-failure-retry.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/android-comparison-in-temp-failure-retry.rst
+++ clang-tools-extra/docs/clang-tidy/checks/android-comparison-in-temp-failure-retry.rst
@@ -34,3 +34,10 @@
   while (TEMP_FAILURE_RETRY(read(STDIN_FILENO, cs, sizeof(cs))) != 0) {
 // Do something with cs.
   }
+
+Options
+---
+
+.. option:: RetryMacros
+
+   A comma-separated list of the names of retry macros to be checked.
Index: clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.h
===
--- clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.h
+++ clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.h
@@ -10,6 +10,9 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_COMPARISONINTEMPFAILURERETRYCHECK_H
 
 #include "../ClangTidyCheck.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include 
 
 namespace clang {
 namespace tidy {
@@ -22,10 +25,14 @@
 /// TEMP_FAILURE_RETRY is a macro provided by both glibc and Bionic.
 class ComparisonInTempFailureRetryCheck : public ClangTidyCheck {
 public:
-  ComparisonInTempFailureRetryCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  ComparisonInTempFailureRetryCheck(StringRef Name, ClangTidyContext *Context);
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+private:
+  const std::string RawRetryList;
+  SmallVector RetryMacros;
 };
 
 } // namespace android
Index: clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.cpp
===
--- clang-tools-extra/clang-tidy/android/ComparisonInTempFailureRetryCheck.cpp
+++ clang-tools-extra/clang-tidy/android/ComparisonInT

[PATCH] D83144: Allow to specify macro names for android-comparison-in-temp-failure-retry.

2020-09-14 Thread Florian Mayer via Phabricator via cfe-commits
fmayer added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/android-comparison-in-temp-failure-retry-custom-macro.c:25
+void with_custom_macro() {
+  MY_TEMP_FAILURE_RETRY((foo()));
+  MY_TEMP_FAILURE_RETRY((int)(foo() == 1));

alexfh wrote:
> Are the extra parentheses required for the macro to work? Can it be just 
> `MY_TEMP_FAILURE_RETRY(foo());` ?
Added the more simple case as well.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83144/new/

https://reviews.llvm.org/D83144

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


[PATCH] D87450: [clangd] Implement hot index reloading for clangd-index-server

2020-09-14 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 291521.
kbobyrev marked 2 inline comments as done.
kbobyrev added a comment.

Address remaining comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87450/new/

https://reviews.llvm.org/D87450

Files:
  clang-tools-extra/clangd/index/remote/server/Server.cpp

Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -12,15 +12,24 @@
 #include "index/Symbol.h"
 #include "index/remote/marshalling/Marshalling.h"
 #include "support/Logger.h"
+#include "support/Shutdown.h"
+#include "support/ThreadsafeFS.h"
 #include "support/Trace.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Chrono.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/VirtualFileSystem.h"
 
+#include 
 #include 
 #include 
+#include 
+#include 
 
 #include "Index.grpc.pb.h"
 
@@ -63,15 +72,10 @@
 "server-address", llvm::cl::init("0.0.0.0:50051"),
 llvm::cl::desc("Address of the invoked server. Defaults to 0.0.0.0:50051"));
 
-std::unique_ptr openIndex(llvm::StringRef Index) {
-  return loadIndex(Index, /*UseIndex=*/true);
-}
-
 class RemoteIndexServer final : public SymbolIndex::Service {
 public:
-  RemoteIndexServer(std::unique_ptr Index,
-llvm::StringRef IndexRoot)
-  : Index(std::move(Index)) {
+  RemoteIndexServer(clangd::SymbolIndex &Index, llvm::StringRef IndexRoot)
+  : Index(Index) {
 llvm::SmallString<256> NativePath = IndexRoot;
 llvm::sys::path::native(NativePath);
 ProtobufMarshaller = std::unique_ptr(new Marshaller(
@@ -91,7 +95,7 @@
 }
 unsigned Sent = 0;
 unsigned FailedToSend = 0;
-Index->lookup(*Req, [&](const clangd::Symbol &Item) {
+Index.lookup(*Req, [&](const clangd::Symbol &Item) {
   auto SerializedItem = ProtobufMarshaller->toProtobuf(Item);
   if (!SerializedItem) {
 elog("Unable to convert Symbol to protobuf: {0}",
@@ -124,7 +128,7 @@
 }
 unsigned Sent = 0;
 unsigned FailedToSend = 0;
-bool HasMore = Index->fuzzyFind(*Req, [&](const clangd::Symbol &Item) {
+bool HasMore = Index.fuzzyFind(*Req, [&](const clangd::Symbol &Item) {
   auto SerializedItem = ProtobufMarshaller->toProtobuf(Item);
   if (!SerializedItem) {
 elog("Unable to convert Symbol to protobuf: {0}",
@@ -155,7 +159,7 @@
 }
 unsigned Sent = 0;
 unsigned FailedToSend = 0;
-bool HasMore = Index->refs(*Req, [&](const clangd::Ref &Item) {
+bool HasMore = Index.refs(*Req, [&](const clangd::Ref &Item) {
   auto SerializedItem = ProtobufMarshaller->toProtobuf(Item);
   if (!SerializedItem) {
 elog("Unable to convert Ref to protobuf: {0}",
@@ -188,7 +192,7 @@
 }
 unsigned Sent = 0;
 unsigned FailedToSend = 0;
-Index->relations(
+Index.relations(
 *Req, [&](const SymbolID &Subject, const clangd::Symbol &Object) {
   auto SerializedItem = ProtobufMarshaller->toProtobuf(Subject, Object);
   if (!SerializedItem) {
@@ -210,22 +214,57 @@
 return grpc::Status::OK;
   }
 
-  std::unique_ptr Index;
   std::unique_ptr ProtobufMarshaller;
+  clangd::SymbolIndex &Index;
 };
 
-void runServer(std::unique_ptr Index,
-   const std::string &ServerAddress) {
-  RemoteIndexServer Service(std::move(Index), IndexRoot);
+// Detect changes in \p IndexPath file and load new versions of the index
+// whenever they become available.
+void hotReload(clangd::SwapIndex *Index, llvm::StringRef IndexPath,
+   llvm::vfs::Status &LastStatus,
+   llvm::IntrusiveRefCntPtr &FS) {
+  auto Status = FS->status(IndexPath);
+  if (!Status)
+return;
+  const auto NewModificationTime = Status->getLastModificationTime();
+  // Current index is newer than the one before: no reload is needed.
+  if (NewModificationTime <= LastStatus.getLastModificationTime())
+return;
+  vlog("Found new index version: existing index was modified at {0}, new "
+   "index was modified at {1}. Attempting to reload.",
+   LastStatus.getLastModificationTime(), NewModificationTime);
+  std::unique_ptr NewIndex = loadIndex(IndexPath);
+  if (!NewIndex) {
+vlog("Failed to load new index. Old index will be served.");
+return;
+  }
+  Index->reset(std::move(NewIndex));
+  log("New index version loaded. Last modification time: {0}.",
+  NewModificationTime);
+  LastStatus = *Status;
+}
+
+void runServer(clangd::SymbolIndex *Index, llvm::StringRef ServerAddress,
+   llvm::StringRef IndexPath) {
+  RemoteIndexServer Service(*Index, IndexRoot);
 
   grpc::EnableDefaultHealthChe

[clang-tools-extra] 687e1d7 - [clangd] makeStringError,make_error -> error()

2020-09-14 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-09-14T11:48:31+02:00
New Revision: 687e1d7121645d23aa5e919ed4d3c0e57af975cd

URL: 
https://github.com/llvm/llvm-project/commit/687e1d7121645d23aa5e919ed4d3c0e57af975cd
DIFF: 
https://github.com/llvm/llvm-project/commit/687e1d7121645d23aa5e919ed4d3c0e57af975cd.diff

LOG: [clangd] makeStringError,make_error -> error()

Added: 


Modified: 
clang-tools-extra/clangd/FindSymbols.cpp
clang-tools-extra/clangd/IncludeFixer.cpp
clang-tools-extra/clangd/JSONTransport.cpp
clang-tools-extra/clangd/Preamble.cpp
clang-tools-extra/clangd/SourceCode.cpp
clang-tools-extra/clangd/URI.cpp
clang-tools-extra/clangd/index/Background.cpp
clang-tools-extra/clangd/index/SymbolID.cpp
clang-tools-extra/clangd/index/YAMLSerialization.cpp
clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
clang-tools-extra/clangd/refactor/Rename.cpp
clang-tools-extra/clangd/refactor/Tweak.cpp
clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp
clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp
clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
clang-tools-extra/clangd/refactor/tweaks/ObjCLocalizeStringLiteral.cpp
clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp
clang-tools-extra/clangd/tool/ClangdMain.cpp
clang-tools-extra/clangd/unittests/TestFS.cpp
clang-tools-extra/clangd/xpc/XPCTransport.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/FindSymbols.cpp 
b/clang-tools-extra/clangd/FindSymbols.cpp
index 247165698825..e37d73103e36 100644
--- a/clang-tools-extra/clangd/FindSymbols.cpp
+++ b/clang-tools-extra/clangd/FindSymbols.cpp
@@ -43,12 +43,9 @@ struct ScoredSymbolGreater {
 llvm::Expected indexToLSPLocation(const SymbolLocation &Loc,
 llvm::StringRef TUPath) {
   auto Path = URI::resolve(Loc.FileURI, TUPath);
-  if (!Path) {
-return llvm::make_error(
-llvm::formatv("Could not resolve path for file '{0}': {1}", 
Loc.FileURI,
-  llvm::toString(Path.takeError())),
-llvm::inconvertibleErrorCode());
-  }
+  if (!Path)
+return error("Could not resolve path for file '{0}': {1}", Loc.FileURI,
+ Path.takeError());
   Location L;
   L.uri = URIForFile::canonicalize(*Path, TUPath);
   Position Start, End;

diff  --git a/clang-tools-extra/clangd/IncludeFixer.cpp 
b/clang-tools-extra/clangd/IncludeFixer.cpp
index 945f4eced88c..7704ccb82c0f 100644
--- a/clang-tools-extra/clangd/IncludeFixer.cpp
+++ b/clang-tools-extra/clangd/IncludeFixer.cpp
@@ -153,8 +153,7 @@ std::vector IncludeFixer::fixesForSymbols(const 
SymbolSlab &Syms) const {
   return ResolvedInserted.takeError();
 auto Spelled = Inserter->calculateIncludePath(*ResolvedInserted, File);
 if (!Spelled)
-  return llvm::createStringError(llvm::inconvertibleErrorCode(),
- "Header not on include path");
+  return error("Header not on include path");
 return std::make_pair(
 std::move(*Spelled),
 Inserter->shouldInsertInclude(*ResolvedDeclaring, *ResolvedInserted));

diff  --git a/clang-tools-extra/clangd/JSONTransport.cpp 
b/clang-tools-extra/clangd/JSONTransport.cpp
index c591da0db47d..eb5a83882b2b 100644
--- a/clang-tools-extra/clangd/JSONTransport.cpp
+++ b/clang-tools-extra/clangd/JSONTransport.cpp
@@ -12,6 +12,7 @@
 #include "support/Shutdown.h"
 #include "llvm/Support/Errno.h"
 #include "llvm/Support/Error.h"
+#include 
 
 namespace clang {
 namespace clangd {
@@ -100,9 +101,8 @@ class JSONTransport : public Transport {
   llvm::Error loop(MessageHandler &Handler) override {
 while (!feof(In)) {
   if (shutdownRequested())
-return llvm::createStringError(
-std::make_error_code(std::errc::operation_canceled),
-"Got signal, shutting down");
+return error(std::make_error_code(std::errc::operation_canceled),
+ "Got signal, shutting down");
   if (ferror(In))
 return llvm::errorCodeToError(
 std::error_code(errno, std::system_category()));

diff  --git a/clang-tools-extra/clangd/Preamble.cpp 
b/clang-tools-extra/clangd/Preamble.cpp
index b71afa0b1619..8e1ad7242eb0 100644
--- a/clang-tools-extra/clangd/Preamble.cpp
+++ b/clang-tools-extra/clangd/Preamble.cpp
@@ -243,8 +243,7 @@ scanPreamble(llvm::StringRef Contents, const 
tooling::CompileCommand &Cmd) {
   IgnoringDiagConsumer IgnoreDiags;
   auto CI = buildCompilerInvocation(PI, IgnoreDiags);
   if (!CI)
-return llvm::createStringError(llvm::inconvertibleErrorCode(),
-   "failed to create compiler invocation");

[PATCH] D71199: [clang-tidy] New check cppcoreguidelines-prefer-member-initializer

2020-09-14 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

Minor inline comments.

Could you please add a test case where the constructor is defined out of line? 
So far in every test, the constructor //body// was inside the class. Something 
like:

  struct S {
int i, j;
S();
  };
  
  S::S() {
i = 1;
j = 2;
  }

I'm also particularly interested in the case when the constructor is 
implemented in its "own" translation unit. Where will the initialiser be moved 
in that case? Into the header, where the record is defined, still?




Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp:21-23
+  return isa(S) || isa(S) || isa(S) ||
+ isa(S) || isa(S) || isa(S) ||
+ isa(S) || isa(S) || isa(S);

It was you who figured out in D85728 that `isa` has changed recently and is now 
variadic. Then this function can be simplified with the variadic version.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp:39-41
+  return isa(E) || isa(E) ||
+ isa(E) || isa(E) ||
+ isa(E) || isa(E);

Ditto.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp:126
+
+  for (const auto *S : Body->body()) {
+if (isControlStatement(S))





Comment at: 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-prefer-member-initializer.rst:6
+
+Finds member initializations in the constructor body which can be  converted
+into member initializers of the constructor instead. This not only improves




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71199/new/

https://reviews.llvm.org/D71199

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


[PATCH] D71199: [clang-tidy] New check cppcoreguidelines-prefer-member-initializer

2020-09-14 Thread Whisperity via Phabricator via cfe-commits
whisperity added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp:43
+static bool isLiteral(const Expr *E) {
+  return isa(E) ||
+ isa(E) ||

baloghadamsoftware wrote:
> aaron.ballman wrote:
> > What about other kinds of literals like user-defined literals, or literal 
> > class types? Should this be using `E->getType()->isLiteralType()`?
> `E->getType()->isLiteralType()` does not work since it tells about the type, 
> not the expression itself. Here we should return `true` for literals only, 
> not for any expressions whose type is a literal type. Thus `int` is a literal 
> type, `5` is an `int` literal, but `n` or `return_any_int()` not.
@baloghadamsoftware The original comment by Aaron is left unmarked as "done" 
here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71199/new/

https://reviews.llvm.org/D71199

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


[PATCH] D87600: [SyntaxTree][List] `assertInvariants` for `List`s

2020-09-14 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 291522.
eduucaldas marked 2 inline comments as done.
eduucaldas added a comment.

Fix build error and clang-tidy lint error


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87600/new/

https://reviews.llvm.org/D87600

Files:
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/lib/Tooling/Syntax/Tree.cpp


Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -223,7 +223,7 @@
   else
 assert(getParent() != nullptr);
 
-  auto *T = dyn_cast(this);
+  const auto *T = dyn_cast(this);
   if (!T)
 return;
   for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
@@ -232,6 +232,19 @@
 assert(!C->isDetached());
 assert(C->getParent() == T);
   }
+
+  const auto *L = dyn_cast(T);
+  if (!L)
+return;
+  for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
+assert(C->getRole() == NodeRole::ListElement ||
+   C->getRole() == NodeRole::ListDelimiter);
+if (C->getRole() == NodeRole::ListDelimiter) {
+  assert(isa(C));
+  assert(cast(C)->getToken()->kind() == L->getDelimiterTokenKind());
+}
+  }
+
 #endif
 }
 
@@ -273,7 +286,7 @@
   return nullptr;
 }
 
-bool classof(const syntax::Node *N) {
+bool syntax::List::classof(const syntax::Node *N) {
   switch (N->getKind()) {
   case syntax::NodeKind::NestedNameSpecifier:
   case syntax::NodeKind::CallArguments:
@@ -372,7 +385,7 @@
   return children;
 }
 
-clang::tok::TokenKind syntax::List::getDelimiterTokenKind() {
+clang::tok::TokenKind syntax::List::getDelimiterTokenKind() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return clang::tok::coloncolon;
@@ -385,7 +398,7 @@
   }
 }
 
-syntax::List::TerminationKind syntax::List::getTerminationKind() {
+syntax::List::TerminationKind syntax::List::getTerminationKind() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return TerminationKind::Terminated;
@@ -398,7 +411,7 @@
   }
 }
 
-bool syntax::List::canBeEmpty() {
+bool syntax::List::canBeEmpty() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return false;
Index: clang/include/clang/Tooling/Syntax/Tree.h
===
--- clang/include/clang/Tooling/Syntax/Tree.h
+++ clang/include/clang/Tooling/Syntax/Tree.h
@@ -237,16 +237,16 @@
   ///
   /// Useful for discovering the correct delimiter to use when adding
   /// elements to empty or one-element lists.
-  clang::tok::TokenKind getDelimiterTokenKind();
+  clang::tok::TokenKind getDelimiterTokenKind() const;
 
-  TerminationKind getTerminationKind();
+  TerminationKind getTerminationKind() const;
 
   /// Whether this list can be empty in syntactically and semantically correct
   /// code.
   ///
   /// This list may be empty when the source code has errors even if
   /// canBeEmpty() returns false.
-  bool canBeEmpty();
+  bool canBeEmpty() const;
 };
 
 } // namespace syntax


Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -223,7 +223,7 @@
   else
 assert(getParent() != nullptr);
 
-  auto *T = dyn_cast(this);
+  const auto *T = dyn_cast(this);
   if (!T)
 return;
   for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
@@ -232,6 +232,19 @@
 assert(!C->isDetached());
 assert(C->getParent() == T);
   }
+
+  const auto *L = dyn_cast(T);
+  if (!L)
+return;
+  for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
+assert(C->getRole() == NodeRole::ListElement ||
+   C->getRole() == NodeRole::ListDelimiter);
+if (C->getRole() == NodeRole::ListDelimiter) {
+  assert(isa(C));
+  assert(cast(C)->getToken()->kind() == L->getDelimiterTokenKind());
+}
+  }
+
 #endif
 }
 
@@ -273,7 +286,7 @@
   return nullptr;
 }
 
-bool classof(const syntax::Node *N) {
+bool syntax::List::classof(const syntax::Node *N) {
   switch (N->getKind()) {
   case syntax::NodeKind::NestedNameSpecifier:
   case syntax::NodeKind::CallArguments:
@@ -372,7 +385,7 @@
   return children;
 }
 
-clang::tok::TokenKind syntax::List::getDelimiterTokenKind() {
+clang::tok::TokenKind syntax::List::getDelimiterTokenKind() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return clang::tok::coloncolon;
@@ -385,7 +398,7 @@
   }
 }
 
-syntax::List::TerminationKind syntax::List::getTerminationKind() {
+syntax::List::TerminationKind syntax::List::getTerminationKind() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return TerminationKind::Terminated;
@@ -398,7 +411,7 @@
   }
 }
 
-bool syntax::List::canBeEmpty() {
+bool syntax::List::canBeEmpty() con

[PATCH] D87449: [clang-tidy] Add new check for SEI CERT rule SIG30-C.

2020-09-14 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 291524.
balazske added a comment.

Changed checker messages, reformatted text, rebase.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87449/new/

https://reviews.llvm.org/D87449

Files:
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/clang-tidy/cert/CMakeLists.txt
  clang-tools-extra/clang-tidy/cert/SignalHandlerCheck.cpp
  clang-tools-extra/clang-tidy/cert/SignalHandlerCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-sig30-c.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/signal.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/stdlib.h
  clang-tools-extra/test/clang-tidy/checkers/cert-sig30-c.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cert-sig30-c.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cert-sig30-c.cpp
@@ -0,0 +1,72 @@
+// RUN: %check_clang_tidy %s cert-sig30-c %t -- -- -isystem %S/Inputs/Headers
+
+#include "signal.h"
+#include "stdio.h"
+#include "stdlib.h"
+
+void handler_abort(int) {
+  abort();
+}
+
+void handler__Exit(int) {
+  _Exit(0);
+}
+
+void handler_quick_exit(int) {
+  quick_exit(0);
+}
+
+void handler_other(int) {
+  printf("1234");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' is considered as non asynchronous-safe and should not be called from a signal handler [cert-sig30-c]
+}
+
+void handler_signal(int) {
+  // FIXME: It is only OK to call signal with the current signal number.
+  signal(0, SIG_DFL);
+}
+
+void f_ok() {
+  abort();
+}
+
+void f_bad() {
+  printf("1234");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'printf' is considered as non asynchronous-safe and should not be called from a signal handler [cert-sig30-c]
+}
+
+void f_extern();
+
+void handler_ok(int) {
+  f_ok();
+  f_extern();
+}
+
+void handler_bad(int) {
+  f_bad();
+}
+
+// Function called "signal" that is not to be recognized by the checker.
+typedef void (*callback_t)(int);
+void signal(int, callback_t, int);
+
+void test() {
+  signal(SIGINT, handler_abort);
+  signal(SIGINT, handler__Exit);
+  signal(SIGINT, handler_quick_exit);
+  signal(SIGINT, handler_signal);
+  signal(SIGINT, handler_other);
+
+  signal(SIGINT, handler_ok);
+  signal(SIGINT, handler_bad);
+
+  signal(SIGINT, quick_exit);
+  signal(SIGINT, other_call);
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: 'other_call' is considered as non asynchronous-safe and should not be called from a signal handler [cert-sig30-c]
+
+  signal(SIGINT, SIG_IGN);
+  signal(SIGINT, SIG_DFL);
+
+  // Do not find problems here.
+  signal(SIGINT, handler_bad, 1);
+}
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/stdlib.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/stdlib.h
@@ -0,0 +1,18 @@
+//===--- stdlib.h - Stub header for tests ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _STDLIB_H_
+#define _STDLIB_H_
+
+void abort(void);
+void _Exit(int __status);
+void quick_exit(int __status);
+
+void other_call(int);
+
+#endif // _STDLIB_H_
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/signal.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/signal.h
@@ -0,0 +1,22 @@
+//===--- signal.h - Stub header for tests ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _SIGNAL_H_
+#define _SIGNAL_H_
+
+void _sig_ign(int);
+void _sig_dfl(int);
+
+#define SIGINT 1
+#define SIG_IGN _sig_ign
+#define SIG_DFL _sig_dfl
+
+typedef void (*sighandler_t)(int);
+sighandler_t signal(int signum, sighandler_t handler);
+
+#endif // _SIGNAL_H_
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -115,6 +115,7 @@
`cert-msc51-cpp `_,
`cert-oop57-cpp `_,
`cert-oop58-cpp `_,
+   `cert-sig30-c `_,
`clang-analyzer-core.DynamicTypePropagation `_,
`clang-analyzer-core.uninitialized.CapturedBlockVariable `_,
`clang-analyzer-cplusplus.InnerP

[PATCH] D87598: [SyntaxTree][List] Fix: `ParameterDeclarationList` is the `List` inside `ParametersAndQualifiers`

2020-09-14 Thread Eduardo Caldas via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG12232dc181cb: [SyntaxTree][List] Fix: 
`ParameterDeclarationList` is the `List` inside… (authored by eduucaldas).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87598/new/

https://reviews.llvm.org/D87598

Files:
  clang/lib/Tooling/Syntax/Tree.cpp


Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -366,7 +366,7 @@
   case NodeKind::NestedNameSpecifier:
 return clang::tok::coloncolon;
   case NodeKind::CallArguments:
-  case NodeKind::ParametersAndQualifiers:
+  case NodeKind::ParameterDeclarationList:
 return clang::tok::comma;
   default:
 llvm_unreachable("This is not a subclass of List, thus "
@@ -379,7 +379,7 @@
   case NodeKind::NestedNameSpecifier:
 return TerminationKind::Terminated;
   case NodeKind::CallArguments:
-  case NodeKind::ParametersAndQualifiers:
+  case NodeKind::ParameterDeclarationList:
 return TerminationKind::Separated;
   default:
 llvm_unreachable("This is not a subclass of List, thus "
@@ -393,7 +393,7 @@
 return false;
   case NodeKind::CallArguments:
 return true;
-  case NodeKind::ParametersAndQualifiers:
+  case NodeKind::ParameterDeclarationList:
 return true;
   default:
 llvm_unreachable("This is not a subclass of List, thus canBeEmpty() "


Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -366,7 +366,7 @@
   case NodeKind::NestedNameSpecifier:
 return clang::tok::coloncolon;
   case NodeKind::CallArguments:
-  case NodeKind::ParametersAndQualifiers:
+  case NodeKind::ParameterDeclarationList:
 return clang::tok::comma;
   default:
 llvm_unreachable("This is not a subclass of List, thus "
@@ -379,7 +379,7 @@
   case NodeKind::NestedNameSpecifier:
 return TerminationKind::Terminated;
   case NodeKind::CallArguments:
-  case NodeKind::ParametersAndQualifiers:
+  case NodeKind::ParameterDeclarationList:
 return TerminationKind::Separated;
   default:
 llvm_unreachable("This is not a subclass of List, thus "
@@ -393,7 +393,7 @@
 return false;
   case NodeKind::CallArguments:
 return true;
-  case NodeKind::ParametersAndQualifiers:
+  case NodeKind::ParameterDeclarationList:
 return true;
   default:
 llvm_unreachable("This is not a subclass of List, thus canBeEmpty() "
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 12232dc - [SyntaxTree][List] Fix: `ParameterDeclarationList` is the `List` inside `ParametersAndQualifiers`

2020-09-14 Thread Eduardo Caldas via cfe-commits

Author: Eduardo Caldas
Date: 2020-09-14T10:35:41Z
New Revision: 12232dc181cbe78fbd40a6ed1a89795a2c9a1154

URL: 
https://github.com/llvm/llvm-project/commit/12232dc181cbe78fbd40a6ed1a89795a2c9a1154
DIFF: 
https://github.com/llvm/llvm-project/commit/12232dc181cbe78fbd40a6ed1a89795a2c9a1154.diff

LOG: [SyntaxTree][List] Fix: `ParameterDeclarationList` is the `List` inside 
`ParametersAndQualifiers`

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

Added: 


Modified: 
clang/lib/Tooling/Syntax/Tree.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Syntax/Tree.cpp 
b/clang/lib/Tooling/Syntax/Tree.cpp
index ca1e2880af9f..2bff159696c1 100644
--- a/clang/lib/Tooling/Syntax/Tree.cpp
+++ b/clang/lib/Tooling/Syntax/Tree.cpp
@@ -366,7 +366,7 @@ clang::tok::TokenKind syntax::List::getDelimiterTokenKind() 
{
   case NodeKind::NestedNameSpecifier:
 return clang::tok::coloncolon;
   case NodeKind::CallArguments:
-  case NodeKind::ParametersAndQualifiers:
+  case NodeKind::ParameterDeclarationList:
 return clang::tok::comma;
   default:
 llvm_unreachable("This is not a subclass of List, thus "
@@ -379,7 +379,7 @@ syntax::List::TerminationKind 
syntax::List::getTerminationKind() {
   case NodeKind::NestedNameSpecifier:
 return TerminationKind::Terminated;
   case NodeKind::CallArguments:
-  case NodeKind::ParametersAndQualifiers:
+  case NodeKind::ParameterDeclarationList:
 return TerminationKind::Separated;
   default:
 llvm_unreachable("This is not a subclass of List, thus "
@@ -393,7 +393,7 @@ bool syntax::List::canBeEmpty() {
 return false;
   case NodeKind::CallArguments:
 return true;
-  case NodeKind::ParametersAndQualifiers:
+  case NodeKind::ParameterDeclarationList:
 return true;
   default:
 llvm_unreachable("This is not a subclass of List, thus canBeEmpty() "



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


[clang] 0f4cc64 - [SyntaxTree] Provide `List::classof`

2020-09-14 Thread Eduardo Caldas via cfe-commits

Author: Eduardo Caldas
Date: 2020-09-14T10:35:41Z
New Revision: 0f4cc64fd747fbb33aeccfaccb8873762d2511f2

URL: 
https://github.com/llvm/llvm-project/commit/0f4cc64fd747fbb33aeccfaccb8873762d2511f2
DIFF: 
https://github.com/llvm/llvm-project/commit/0f4cc64fd747fbb33aeccfaccb8873762d2511f2.diff

LOG: [SyntaxTree] Provide `List::classof`

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

Added: 


Modified: 
clang/include/clang/Tooling/Syntax/Tree.h
clang/lib/Tooling/Syntax/Tree.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Syntax/Tree.h 
b/clang/include/clang/Tooling/Syntax/Tree.h
index b49a09344c0f..5a09d4564969 100644
--- a/clang/include/clang/Tooling/Syntax/Tree.h
+++ b/clang/include/clang/Tooling/Syntax/Tree.h
@@ -213,6 +213,7 @@ class List : public Tree {
   };
 
   using Tree::Tree;
+  static bool classof(const Node *N);
   /// Returns the elements and corresponding delimiters. Missing elements
   /// and delimiters are represented as null pointers.
   ///

diff  --git a/clang/lib/Tooling/Syntax/Tree.cpp 
b/clang/lib/Tooling/Syntax/Tree.cpp
index 2bff159696c1..1c705f6fd7cf 100644
--- a/clang/lib/Tooling/Syntax/Tree.cpp
+++ b/clang/lib/Tooling/Syntax/Tree.cpp
@@ -273,6 +273,17 @@ syntax::Node *syntax::Tree::findChild(NodeRole R) {
   return nullptr;
 }
 
+bool classof(const syntax::Node *N) {
+  switch (N->getKind()) {
+  case syntax::NodeKind::NestedNameSpecifier:
+  case syntax::NodeKind::CallArguments:
+  case syntax::NodeKind::ParameterDeclarationList:
+return true;
+  default:
+return false;
+  }
+}
+
 std::vector>
 syntax::List::getElementsAsNodesAndDelimiters() {
   if (!getFirstChild())



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


[PATCH] D87599: [SyntaxTree] Provide `List::classof`

2020-09-14 Thread Eduardo Caldas via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0f4cc64fd747: [SyntaxTree] Provide `List::classof` (authored 
by eduucaldas).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87599/new/

https://reviews.llvm.org/D87599

Files:
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/lib/Tooling/Syntax/Tree.cpp


Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -273,6 +273,17 @@
   return nullptr;
 }
 
+bool classof(const syntax::Node *N) {
+  switch (N->getKind()) {
+  case syntax::NodeKind::NestedNameSpecifier:
+  case syntax::NodeKind::CallArguments:
+  case syntax::NodeKind::ParameterDeclarationList:
+return true;
+  default:
+return false;
+  }
+}
+
 std::vector>
 syntax::List::getElementsAsNodesAndDelimiters() {
   if (!getFirstChild())
Index: clang/include/clang/Tooling/Syntax/Tree.h
===
--- clang/include/clang/Tooling/Syntax/Tree.h
+++ clang/include/clang/Tooling/Syntax/Tree.h
@@ -213,6 +213,7 @@
   };
 
   using Tree::Tree;
+  static bool classof(const Node *N);
   /// Returns the elements and corresponding delimiters. Missing elements
   /// and delimiters are represented as null pointers.
   ///


Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -273,6 +273,17 @@
   return nullptr;
 }
 
+bool classof(const syntax::Node *N) {
+  switch (N->getKind()) {
+  case syntax::NodeKind::NestedNameSpecifier:
+  case syntax::NodeKind::CallArguments:
+  case syntax::NodeKind::ParameterDeclarationList:
+return true;
+  default:
+return false;
+  }
+}
+
 std::vector>
 syntax::List::getElementsAsNodesAndDelimiters() {
   if (!getFirstChild())
Index: clang/include/clang/Tooling/Syntax/Tree.h
===
--- clang/include/clang/Tooling/Syntax/Tree.h
+++ clang/include/clang/Tooling/Syntax/Tree.h
@@ -213,6 +213,7 @@
   };
 
   using Tree::Tree;
+  static bool classof(const Node *N);
   /// Returns the elements and corresponding delimiters. Missing elements
   /// and delimiters are represented as null pointers.
   ///
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87600: [SyntaxTree][List] `assertInvariants` for `List`s

2020-09-14 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 291532.
eduucaldas added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87600/new/

https://reviews.llvm.org/D87600

Files:
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/lib/Tooling/Syntax/Tree.cpp


Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -223,7 +223,7 @@
   else
 assert(getParent() != nullptr);
 
-  auto *T = dyn_cast(this);
+  const auto *T = dyn_cast(this);
   if (!T)
 return;
   for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
@@ -232,6 +232,19 @@
 assert(!C->isDetached());
 assert(C->getParent() == T);
   }
+
+  const auto *L = dyn_cast(T);
+  if (!L)
+return;
+  for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
+assert(C->getRole() == NodeRole::ListElement ||
+   C->getRole() == NodeRole::ListDelimiter);
+if (C->getRole() == NodeRole::ListDelimiter) {
+  assert(isa(C));
+  assert(cast(C)->getToken()->kind() == L->getDelimiterTokenKind());
+}
+  }
+
 #endif
 }
 
@@ -273,7 +286,7 @@
   return nullptr;
 }
 
-bool classof(const syntax::Node *N) {
+bool syntax::List::classof(const syntax::Node *N) {
   switch (N->getKind()) {
   case syntax::NodeKind::NestedNameSpecifier:
   case syntax::NodeKind::CallArguments:
@@ -372,7 +385,7 @@
   return children;
 }
 
-clang::tok::TokenKind syntax::List::getDelimiterTokenKind() {
+clang::tok::TokenKind syntax::List::getDelimiterTokenKind() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return clang::tok::coloncolon;
@@ -385,7 +398,7 @@
   }
 }
 
-syntax::List::TerminationKind syntax::List::getTerminationKind() {
+syntax::List::TerminationKind syntax::List::getTerminationKind() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return TerminationKind::Terminated;
@@ -398,7 +411,7 @@
   }
 }
 
-bool syntax::List::canBeEmpty() {
+bool syntax::List::canBeEmpty() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return false;
Index: clang/include/clang/Tooling/Syntax/Tree.h
===
--- clang/include/clang/Tooling/Syntax/Tree.h
+++ clang/include/clang/Tooling/Syntax/Tree.h
@@ -237,16 +237,16 @@
   ///
   /// Useful for discovering the correct delimiter to use when adding
   /// elements to empty or one-element lists.
-  clang::tok::TokenKind getDelimiterTokenKind();
+  clang::tok::TokenKind getDelimiterTokenKind() const;
 
-  TerminationKind getTerminationKind();
+  TerminationKind getTerminationKind() const;
 
   /// Whether this list can be empty in syntactically and semantically correct
   /// code.
   ///
   /// This list may be empty when the source code has errors even if
   /// canBeEmpty() returns false.
-  bool canBeEmpty();
+  bool canBeEmpty() const;
 };
 
 } // namespace syntax


Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -223,7 +223,7 @@
   else
 assert(getParent() != nullptr);
 
-  auto *T = dyn_cast(this);
+  const auto *T = dyn_cast(this);
   if (!T)
 return;
   for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
@@ -232,6 +232,19 @@
 assert(!C->isDetached());
 assert(C->getParent() == T);
   }
+
+  const auto *L = dyn_cast(T);
+  if (!L)
+return;
+  for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
+assert(C->getRole() == NodeRole::ListElement ||
+   C->getRole() == NodeRole::ListDelimiter);
+if (C->getRole() == NodeRole::ListDelimiter) {
+  assert(isa(C));
+  assert(cast(C)->getToken()->kind() == L->getDelimiterTokenKind());
+}
+  }
+
 #endif
 }
 
@@ -273,7 +286,7 @@
   return nullptr;
 }
 
-bool classof(const syntax::Node *N) {
+bool syntax::List::classof(const syntax::Node *N) {
   switch (N->getKind()) {
   case syntax::NodeKind::NestedNameSpecifier:
   case syntax::NodeKind::CallArguments:
@@ -372,7 +385,7 @@
   return children;
 }
 
-clang::tok::TokenKind syntax::List::getDelimiterTokenKind() {
+clang::tok::TokenKind syntax::List::getDelimiterTokenKind() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return clang::tok::coloncolon;
@@ -385,7 +398,7 @@
   }
 }
 
-syntax::List::TerminationKind syntax::List::getTerminationKind() {
+syntax::List::TerminationKind syntax::List::getTerminationKind() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return TerminationKind::Terminated;
@@ -398,7 +411,7 @@
   }
 }
 
-bool syntax::List::canBeEmpty() {
+bool syntax::List::canBeEmpty() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 r

[PATCH] D87600: [SyntaxTree][List] `assertInvariants` for `List`s

2020-09-14 Thread Eduardo Caldas via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGceb0128509c5: [SyntaxTree][List] `assertInvariants` for 
`List`s (authored by eduucaldas).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87600/new/

https://reviews.llvm.org/D87600

Files:
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/lib/Tooling/Syntax/Tree.cpp


Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -223,7 +223,7 @@
   else
 assert(getParent() != nullptr);
 
-  auto *T = dyn_cast(this);
+  const auto *T = dyn_cast(this);
   if (!T)
 return;
   for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
@@ -232,6 +232,19 @@
 assert(!C->isDetached());
 assert(C->getParent() == T);
   }
+
+  const auto *L = dyn_cast(T);
+  if (!L)
+return;
+  for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
+assert(C->getRole() == NodeRole::ListElement ||
+   C->getRole() == NodeRole::ListDelimiter);
+if (C->getRole() == NodeRole::ListDelimiter) {
+  assert(isa(C));
+  assert(cast(C)->getToken()->kind() == L->getDelimiterTokenKind());
+}
+  }
+
 #endif
 }
 
@@ -273,7 +286,7 @@
   return nullptr;
 }
 
-bool classof(const syntax::Node *N) {
+bool syntax::List::classof(const syntax::Node *N) {
   switch (N->getKind()) {
   case syntax::NodeKind::NestedNameSpecifier:
   case syntax::NodeKind::CallArguments:
@@ -372,7 +385,7 @@
   return children;
 }
 
-clang::tok::TokenKind syntax::List::getDelimiterTokenKind() {
+clang::tok::TokenKind syntax::List::getDelimiterTokenKind() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return clang::tok::coloncolon;
@@ -385,7 +398,7 @@
   }
 }
 
-syntax::List::TerminationKind syntax::List::getTerminationKind() {
+syntax::List::TerminationKind syntax::List::getTerminationKind() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return TerminationKind::Terminated;
@@ -398,7 +411,7 @@
   }
 }
 
-bool syntax::List::canBeEmpty() {
+bool syntax::List::canBeEmpty() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return false;
Index: clang/include/clang/Tooling/Syntax/Tree.h
===
--- clang/include/clang/Tooling/Syntax/Tree.h
+++ clang/include/clang/Tooling/Syntax/Tree.h
@@ -237,16 +237,16 @@
   ///
   /// Useful for discovering the correct delimiter to use when adding
   /// elements to empty or one-element lists.
-  clang::tok::TokenKind getDelimiterTokenKind();
+  clang::tok::TokenKind getDelimiterTokenKind() const;
 
-  TerminationKind getTerminationKind();
+  TerminationKind getTerminationKind() const;
 
   /// Whether this list can be empty in syntactically and semantically correct
   /// code.
   ///
   /// This list may be empty when the source code has errors even if
   /// canBeEmpty() returns false.
-  bool canBeEmpty();
+  bool canBeEmpty() const;
 };
 
 } // namespace syntax


Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -223,7 +223,7 @@
   else
 assert(getParent() != nullptr);
 
-  auto *T = dyn_cast(this);
+  const auto *T = dyn_cast(this);
   if (!T)
 return;
   for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
@@ -232,6 +232,19 @@
 assert(!C->isDetached());
 assert(C->getParent() == T);
   }
+
+  const auto *L = dyn_cast(T);
+  if (!L)
+return;
+  for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
+assert(C->getRole() == NodeRole::ListElement ||
+   C->getRole() == NodeRole::ListDelimiter);
+if (C->getRole() == NodeRole::ListDelimiter) {
+  assert(isa(C));
+  assert(cast(C)->getToken()->kind() == L->getDelimiterTokenKind());
+}
+  }
+
 #endif
 }
 
@@ -273,7 +286,7 @@
   return nullptr;
 }
 
-bool classof(const syntax::Node *N) {
+bool syntax::List::classof(const syntax::Node *N) {
   switch (N->getKind()) {
   case syntax::NodeKind::NestedNameSpecifier:
   case syntax::NodeKind::CallArguments:
@@ -372,7 +385,7 @@
   return children;
 }
 
-clang::tok::TokenKind syntax::List::getDelimiterTokenKind() {
+clang::tok::TokenKind syntax::List::getDelimiterTokenKind() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return clang::tok::coloncolon;
@@ -385,7 +398,7 @@
   }
 }
 
-syntax::List::TerminationKind syntax::List::getTerminationKind() {
+syntax::List::TerminationKind syntax::List::getTerminationKind() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return TerminationKind::Terminated;
@@ -398,7 +411,7 @@
   }
 }

[clang] ceb0128 - [SyntaxTree][List] `assertInvariants` for `List`s

2020-09-14 Thread Eduardo Caldas via cfe-commits

Author: Eduardo Caldas
Date: 2020-09-14T10:36:11Z
New Revision: ceb0128509c51100afbf804bda84d82b7ebe06b1

URL: 
https://github.com/llvm/llvm-project/commit/ceb0128509c51100afbf804bda84d82b7ebe06b1
DIFF: 
https://github.com/llvm/llvm-project/commit/ceb0128509c51100afbf804bda84d82b7ebe06b1.diff

LOG: [SyntaxTree][List] `assertInvariants` for `List`s

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

Added: 


Modified: 
clang/include/clang/Tooling/Syntax/Tree.h
clang/lib/Tooling/Syntax/Tree.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Syntax/Tree.h 
b/clang/include/clang/Tooling/Syntax/Tree.h
index 5a09d4564969..a544fc1827b7 100644
--- a/clang/include/clang/Tooling/Syntax/Tree.h
+++ b/clang/include/clang/Tooling/Syntax/Tree.h
@@ -237,16 +237,16 @@ class List : public Tree {
   ///
   /// Useful for discovering the correct delimiter to use when adding
   /// elements to empty or one-element lists.
-  clang::tok::TokenKind getDelimiterTokenKind();
+  clang::tok::TokenKind getDelimiterTokenKind() const;
 
-  TerminationKind getTerminationKind();
+  TerminationKind getTerminationKind() const;
 
   /// Whether this list can be empty in syntactically and semantically correct
   /// code.
   ///
   /// This list may be empty when the source code has errors even if
   /// canBeEmpty() returns false.
-  bool canBeEmpty();
+  bool canBeEmpty() const;
 };
 
 } // namespace syntax

diff  --git a/clang/lib/Tooling/Syntax/Tree.cpp 
b/clang/lib/Tooling/Syntax/Tree.cpp
index 1c705f6fd7cf..1edd2583105a 100644
--- a/clang/lib/Tooling/Syntax/Tree.cpp
+++ b/clang/lib/Tooling/Syntax/Tree.cpp
@@ -223,7 +223,7 @@ void syntax::Node::assertInvariants() const {
   else
 assert(getParent() != nullptr);
 
-  auto *T = dyn_cast(this);
+  const auto *T = dyn_cast(this);
   if (!T)
 return;
   for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
@@ -232,6 +232,19 @@ void syntax::Node::assertInvariants() const {
 assert(!C->isDetached());
 assert(C->getParent() == T);
   }
+
+  const auto *L = dyn_cast(T);
+  if (!L)
+return;
+  for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
+assert(C->getRole() == NodeRole::ListElement ||
+   C->getRole() == NodeRole::ListDelimiter);
+if (C->getRole() == NodeRole::ListDelimiter) {
+  assert(isa(C));
+  assert(cast(C)->getToken()->kind() == L->getDelimiterTokenKind());
+}
+  }
+
 #endif
 }
 
@@ -273,7 +286,7 @@ syntax::Node *syntax::Tree::findChild(NodeRole R) {
   return nullptr;
 }
 
-bool classof(const syntax::Node *N) {
+bool syntax::List::classof(const syntax::Node *N) {
   switch (N->getKind()) {
   case syntax::NodeKind::NestedNameSpecifier:
   case syntax::NodeKind::CallArguments:
@@ -372,7 +385,7 @@ std::vector 
syntax::List::getElementsAsNodes() {
   return children;
 }
 
-clang::tok::TokenKind syntax::List::getDelimiterTokenKind() {
+clang::tok::TokenKind syntax::List::getDelimiterTokenKind() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return clang::tok::coloncolon;
@@ -385,7 +398,7 @@ clang::tok::TokenKind syntax::List::getDelimiterTokenKind() 
{
   }
 }
 
-syntax::List::TerminationKind syntax::List::getTerminationKind() {
+syntax::List::TerminationKind syntax::List::getTerminationKind() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return TerminationKind::Terminated;
@@ -398,7 +411,7 @@ syntax::List::TerminationKind 
syntax::List::getTerminationKind() {
   }
 }
 
-bool syntax::List::canBeEmpty() {
+bool syntax::List::canBeEmpty() const {
   switch (this->getKind()) {
   case NodeKind::NestedNameSpecifier:
 return false;



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


[PATCH] D87163: [DSE] Switch to MemorySSA-backed DSE by default.

2020-09-14 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In D87163#2270568 , @uabelho wrote:

> Hi,
>
> I'm seeing what I think is a miscompile with this:

Thanks for the reproducer. We have to be more careful around pointers that may 
reference multiple locations in memory. I pushed f715d81c9df3 
 which 
limits elimination to stores that only reference a single location (or are in 
the same BB). The check is conservative and can be improved in the future, but 
the impact on the number of stores eliminated seems very low in practice. It 
would be great if you could check if that fixes the original reproducer.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87163/new/

https://reviews.llvm.org/D87163

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


[PATCH] D86137: Add ignore-unknown-options flag to clang-format.

2020-09-14 Thread George Rimar via Phabricator via cfe-commits
grimar added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:16079
+  auto Style9 = getStyle("file", "/d/.clang-format", "LLVM", "", &FS, true);
+  ASSERT_TRUE((bool)Style9);
 }

It looks like it is very similar to "Test 7:" and can be a part of it?
E.g:


```
...
llvm::consumeError(Style7a.takeError());

// 
auto Style7b = getStyle("file", "/d/.clang-format", "LLVM", "", &FS, true);
ASSERT_TRUE((bool)Style8);
```



Comment at: llvm/unittests/ObjectYAML/YAMLTest.cpp:39
+
+TEST(ObjectYAML, UnkownOption) {
+  std::string InputYAML = "Binary: \n"

Unk**n**ownOption



Comment at: llvm/unittests/ObjectYAML/YAMLTest.cpp:40
+TEST(ObjectYAML, UnkownOption) {
+  std::string InputYAML = "Binary: \n"
+  "InvalidKey: InvalidValue";

`std::string`->`StringRef`?



Comment at: llvm/unittests/ObjectYAML/YAMLTest.cpp:41
+  std::string InputYAML = "Binary: \n"
+  "InvalidKey: InvalidValue";
+  BinaryHolder BH;

Will this work if we switch the order of `InvalidKey` and `Binary`?

```
  std::string InputYAML = "InvalidKey: InvalidValue\n"
  "Binary: ";
```

I expect that yes and I think it is reasonable to do it to show that we don't 
stop parsing an YAML
when there is an unknown key.



Comment at: llvm/unittests/ObjectYAML/YAMLTest.cpp:44
+  llvm::yaml::Input Input(InputYAML);
+  // test 1: default in trying to parse invalid key is an error case
+  Input >> BH;

No full stop at the end.



Comment at: llvm/unittests/ObjectYAML/YAMLTest.cpp:57
+  EXPECT_EQ(BH2.Binary, BH_GT.Binary);
+  EXPECT_EQ(Input2.error().value(), 0);
+}

Do you need `BH_GT`? Can it be just:

```
  // test 2: only warn about invalid key if actively set.
  llvm::yaml::Input Input2(InputYAML);
  BinaryHolder BH2;
  Input2.setAllowUnknownKeys(true);
  Input2 >> BH2;
  EXPECT_EQ(Input2.error().value(), 0);
  EXPECT_EQ(BH2.Binary, yaml::BinaryRef(""));
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86137/new/

https://reviews.llvm.org/D86137

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


[PATCH] D87163: [DSE] Switch to MemorySSA-backed DSE by default.

2020-09-14 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In D87163#2270444 , @thakis wrote:

> Heads-up: We're seeing fairly widespread test failures with this in Chromium 
> that go away when we force this flag off. It's possible that it's due to only 
> a small number of issues and they might be previously-benign UB (no idea), 
> but I figured I'd give an early note. We'll send an update once we've reduced 
> a failing test.

Thanks for the heads-up. I just pushed another fix for the issue @uabelho. I'd 
guess at least some of the failures you are seeing should be related. If not, I 
think it makes sense to revert this once we have the reproducers and can work 
in ironing out the remaining issues.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87163/new/

https://reviews.llvm.org/D87163

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


[PATCH] D87604: [X86] Convert integer _mm_reduce_* intrinsics to emit llvm.reduction intrinsics (PR47506)

2020-09-14 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon created this revision.
RKSimon added a reviewer: craig.topper.
Herald added a project: clang.
RKSimon requested review of this revision.

Placeholder patch for when the reduction intrinsics drop their experimental 
status, emitting the equivalent reduction intrinsic in IR instead of expanding 
to shuffle+arithmetic sequences.

The fadd/fmul reductions might be trickier as they assume a similar bisection 
reduction while the generic intrinsics assume a sequential reduction (intel 
docs are ambiguous on the correct approach) - I'm not sure if we want to always 
tag them with reassoc? Anyway, that issue can wait until a separate fp patch 
along with the fmin/fmax reductions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87604

Files:
  clang/include/clang/Basic/BuiltinsX86.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Headers/avx512fintrin.h
  clang/test/CodeGen/X86/avx512-reduceIntrin.c
  clang/test/CodeGen/X86/avx512-reduceMinMaxIntrin.c

Index: clang/test/CodeGen/X86/avx512-reduceMinMaxIntrin.c
===
--- clang/test/CodeGen/X86/avx512-reduceMinMaxIntrin.c
+++ clang/test/CodeGen/X86/avx512-reduceMinMaxIntrin.c
@@ -4,30 +4,13 @@
 
 long long test_mm512_reduce_max_epi64(__m512i __W){
 // CHECK-LABEL: @test_mm512_reduce_max_epi64(
-// CHECK:shufflevector <8 x i64> %{{.*}}, <8 x i64> %{{.*}}, <8 x i32> 
-// CHECK:icmp sgt <8 x i64> %{{.*}}, %{{.*}}
-// CHECK:select <8 x i1> %{{.*}}, <8 x i64> %{{.*}}, <8 x i64> %{{.*}}
-// CHECK:shufflevector <8 x i64> %{{.*}}, <8 x i64> %{{.*}}, <8 x i32> 
-// CHECK:icmp sgt <8 x i64> %{{.*}}, %{{.*}}
-// CHECK:select <8 x i1> %{{.*}}, <8 x i64> %{{.*}}, <8 x i64> %{{.*}}
-// CHECK:shufflevector <8 x i64> %{{.*}}, <8 x i64> %{{.*}}, <8 x i32> 
-// CHECK:icmp sgt <8 x i64> %{{.*}}, %{{.*}}
-// CHECK:select <8 x i1> %{{.*}}, <8 x i64> %{{.*}}, <8 x i64> %{{.*}}
+// CHECK:call i64 @llvm.experimental.vector.reduce.smax.v8i64(<8 x i64> %{{.*}})
   return _mm512_reduce_max_epi64(__W);
 }
 
 unsigned long long test_mm512_reduce_max_epu64(__m512i __W){
 // CHECK-LABEL: @test_mm512_reduce_max_epu64(
-// CHECK:shufflevector <8 x i64> %{{.*}}, <8 x i64> %{{.*}}, <8 x i32> 
-// CHECK:icmp ugt <8 x i64> %{{.*}}, %{{.*}}
-// CHECK:select <8 x i1> %{{.*}}, <8 x i64> %{{.*}}, <8 x i64> %{{.*}}
-// CHECK:shufflevector <8 x i64> %{{.*}}, <8 x i64> %{{.*}}, <8 x i32> 
-// CHECK:icmp ugt <8 x i64> %{{.*}}, %{{.*}}
-// CHECK:select <8 x i1> %{{.*}}, <8 x i64> %{{.*}}, <8 x i64> %{{.*}}
-// CHECK:shufflevector <8 x i64> %{{.*}}, <8 x i64> %{{.*}}, <8 x i32> 
-// CHECK:icmp ugt <8 x i64> %{{.*}}, %{{.*}}
-// CHECK:select <8 x i1> %{{.*}}, <8 x i64> %{{.*}}, <8 x i64> %{{.*}}
-// CHECK:extractelement <8 x i64> %{{.*}}, i32 0
+// CHECK:call i64 @llvm.experimental.vector.reduce.umax.v8i64(<8 x i64> %{{.*}})
   return _mm512_reduce_max_epu64(__W);
 }
 
@@ -47,30 +30,13 @@
 
 long long test_mm512_reduce_min_epi64(__m512i __W){
 // CHECK-LABEL: @test_mm512_reduce_min_epi64(
-// CHECK:shufflevector <8 x i64> %{{.*}}, <8 x i64> %{{.*}}, <8 x i32> 
-// CHECK:icmp slt <8 x i64> %{{.*}}, %{{.*}}
-// CHECK:select <8 x i1> %{{.*}}, <8 x i64> %{{.*}}, <8 x i64> %{{.*}}
-// CHECK:shufflevector <8 x i64> %{{.*}}, <8 x i64> %{{.*}}, <8 x i32> 
-// CHECK:icmp slt <8 x i64> %{{.*}}, %{{.*}}
-// CHECK:select <8 x i1> %{{.*}}, <8 x i64> %{{.*}}, <8 x i64> %{{.*}}
-// CHECK:shufflevector <8 x i64> %{{.*}}, <8 x i64> %{{.*}}, <8 x i32> 
-// CHECK:icmp slt <8 x i64> %{{.*}}, %{{.*}}
-// CHECK:select <8 x i1> %{{.*}}, <8 x i64> %{{.*}}, <8 x i64> %{{.*}}
+// CHECK:call i64 @llvm.experimental.vector.reduce.smin.v8i64(<8 x i64> %{{.*}})
   return _mm512_reduce_min_epi64(__W);
 }
 
 unsigned long long test_mm512_reduce_min_epu64(__m512i __W){
 // CHECK-LABEL: @test_mm512_reduce_min_epu64(
-// CHECK:shufflevector <8 x i64> %{{.*}}, <8 x i64> %{{.*}}, <8 x i32> 
-// CHECK:icmp ult <8 x i64> %{{.*}}, %{{.*}}
-// CHECK:select <8 x i1> %{{.*}}, <8 x i64> %{{.*}}, <8 x i64> %{{.*}}
-// CHECK:shufflevector <8 x i64> %{{.*}}, <8 x i64> %{{.*}}, <8 x i32> 
-// CHECK:icmp ult <8 x i64> %{{.*}}, %{{.*}}
-// CHECK:select <8 x i1> %{{.*}}, <8 x i64> %{{.*}}, <8 x i64> %{{.*}}
-// CHECK:shufflevector <8 x i64> %{{.*}}, <8 x i64> %{{.*}}, <8 x i32> 
-// CHECK:icmp ult <8 x i64> %{{.*}}, %{{.*}}
-// CHECK:select <8 x i1> %{{.*}}, <8 x i64> %{{.*}}, <8 x i64> %{{.*}}
-// CHECK:extractelement <8 x i64> %{{.*}}, i32 0
+// CHECK:call i64 @llvm.experimental.vector.reduce.umin.v8i64(<8 x i64> %{{.*}})
   return _mm512_reduce_min_epu64(__W);
 }
 
@@ -92,15 +58,7 @@
 // CHECK-LABEL: @test_mm512_mask_reduce_max_epi64(
 // CHECK:bitcast i8 %{{.*}} to <8 x i1>
 // CHECK:select <8 x i1> %{{.*}}, <8 x i64> %{{.*}}, <8 x i64> %{{.*}}
-// CHECK:shufflevector <8 x i64> %{{.*}}, <8 x i64> %

[PATCH] D87163: [DSE] Switch to MemorySSA-backed DSE by default.

2020-09-14 Thread Mikael Holmén via Phabricator via cfe-commits
uabelho added a comment.

In D87163#2270860 , @fhahn wrote:

> In D87163#2270568 , @uabelho wrote:
>
>> Hi,
>>
>> I'm seeing what I think is a miscompile with this:
>
> Thanks for the reproducer. We have to be more careful around pointers that 
> may reference multiple locations in memory. I pushed f715d81c9df3 
>  which 
> limits elimination to stores that only reference a single location (or are in 
> the same BB). The check is conservative and can be improved in the future, 
> but the impact on the number of stores eliminated seems very low in practice. 
> It would be great if you could check if that fixes the original reproducer.

Great! I'll check and get back during the day.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87163/new/

https://reviews.llvm.org/D87163

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


[PATCH] D87395: Sema: add support for `__attribute__((__swift_objc_members__))`

2020-09-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87395/new/

https://reviews.llvm.org/D87395

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


[PATCH] D87527: [ASTMatchers] Fix `hasBody` for the descendants of `FunctionDecl`

2020-09-14 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

Can you expand on what is wrong currently for `FunctionDecl` descendants? Would 
the new test `FindsBodyOfFunctionChildren` fail with the current implementation?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87527/new/

https://reviews.llvm.org/D87527

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


[PATCH] D87532: Sema: add support for `__attribute__((__swift_bridge__))`

2020-09-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:2133
 
+def SwiftBridge : Attr {
+  let Spellings = [GNU<"swift_bridge">];

Is this a type or a declaration attribute? It looks like a declaration 
attribute based on the declaration and the list of subjects, but it looks like 
a type based on the `ExpectedType` diagnostic and the documentation. Or is this 
one of those unholy GNU attributes that's confused about what it appertains to?

Should this be inherited by redeclarations? Might be worth adding a test:
```
struct __attribute__((swift_bridge)) S;

struct S { // Should still have the attribute
  int i;
};
```



Comment at: clang/include/clang/Basic/AttrDocs.td:3483
+  let Content = [{
+The ``swift_bridged`` attribute indicates that the type to which the attribute
+appertains is bridged to the named Swift type.

If this is a type attribute, should it be listed as a `TypeAttr` above?



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:5535
+  // Don't duplicate annotations that are already set.
+  if (D->hasAttr()) {
+S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL.getAttrName();

Can a type bridge across multiple types? e.g., could you say this bridges to 
"foo" and "bar"?



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:5536
+  if (D->hasAttr()) {
+S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL.getAttrName();
+return;

Can drop the `getAttrName()` and just pass in `AL` directly.



Comment at: clang/test/SemaObjC/attr-swift_bridged_typedef.m:11
+
+// expected-error@+1 {{'__swift_bridge__' attribute takes one argument}}
+__attribute__((__swift_bridge__))

I'd appreciate a test that shows it diagnosing when given the wrong subject.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87532/new/

https://reviews.llvm.org/D87532

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


[PATCH] D87532: Sema: add support for `__attribute__((__swift_bridge__))`

2020-09-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:2137
+  let Subjects = SubjectList<[Tag, TypedefName, ObjCInterface, ObjCProtocol],
+ ErrorDiag, "ExpectedType">;
+  let Documentation = [SwiftBridgeDocs];

Are you sure the `ExpectedType` is needed?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87532/new/

https://reviews.llvm.org/D87532

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


[PATCH] D87607: [clang][aarch64] Support implicit casts between GNU and SVE vectors

2020-09-14 Thread Cullen Rhodes via Phabricator via cfe-commits
c-rhodes created this revision.
c-rhodes added reviewers: sdesmalen, efriedma, rsandifo-arm.
Herald added subscribers: kristof.beyls, tschuett.
Herald added a reviewer: rengolin.
Herald added a project: clang.
c-rhodes requested review of this revision.

This patch adds support for implicit casting between GNU vectors and SVE
vectors when `__ARM_FEATURE_SVE_BITS==N`, as defined by the Arm C
Language Extensions (ACLE, version 00bet5, section 3.7.3.3) for SVE [1].

This behavior makes it possible to use GNU vectors with ACLE functions
that operate on VLAT. For example:

  typedef int8_t vec __attribute__((vector_size(32)));
  vec f(vec x) { return svasrd_x(svptrue_b8(), x, 1); }

The `__ARM_FEATURE_SVE_VECTOR_OPERATORS` feature macro indicates
interoperability with the GNU vector extension. This is the first patch
providing support for this feature, which once complete will be enabled
by the `-msve-vector-bits` flag, as the `__ARM_FEATURE_SVE_BITS` feature
currently is.

[1] https://developer.arm.com/documentation/100987/latest


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87607

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/CodeGen/attr-arm-sve-vector-bits-cast.c
  clang/test/Sema/attr-arm-sve-vector-bits.c
  clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp

Index: clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp
===
--- clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp
+++ clang/test/SemaCXX/attr-arm-sve-vector-bits.cpp
@@ -1,10 +1,13 @@
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -fsyntax-only -verify -std=c++11 -msve-vector-bits=512 -fallow-half-arguments-and-returns %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -ffreestanding -fsyntax-only -verify -std=c++11 -msve-vector-bits=512 -fallow-half-arguments-and-returns %s
 // expected-no-diagnostics
 
+#include 
+
 #define N __ARM_FEATURE_SVE_BITS
 
 typedef __SVInt8_t svint8_t;
 typedef svint8_t fixed_int8_t __attribute__((arm_sve_vector_bits(N)));
+typedef int8_t gnu_int8_t __attribute__((vector_size(N / 8)));
 
 template struct S { T var; };
 
@@ -12,3 +15,6 @@
 
 svint8_t to_svint8_t(fixed_int8_t x) { return x; }
 fixed_int8_t from_svint8_t(svint8_t x) { return x; }
+
+svint8_t to_svint8_t__from_gnu_int8_t(gnu_int8_t x) { return x; }
+gnu_int8_t from_svint8_t__to_gnu_int8_t(svint8_t x) { return x; }
Index: clang/test/Sema/attr-arm-sve-vector-bits.c
===
--- clang/test/Sema/attr-arm-sve-vector-bits.c
+++ clang/test/Sema/attr-arm-sve-vector-bits.c
@@ -1,11 +1,16 @@
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -fsyntax-only -verify -msve-vector-bits=128 -fallow-half-arguments-and-returns %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -fsyntax-only -verify -msve-vector-bits=256 -fallow-half-arguments-and-returns %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -fsyntax-only -verify -msve-vector-bits=512 -fallow-half-arguments-and-returns %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -fsyntax-only -verify -msve-vector-bits=1024 -fallow-half-arguments-and-returns %s
-// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -fsyntax-only -verify -msve-vector-bits=2048 -fallow-half-arguments-and-returns %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -ffreestanding -fsyntax-only -verify -msve-vector-bits=128 -fallow-half-arguments-and-returns %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -ffreestanding -fsyntax-only -verify -msve-vector-bits=256 -fallow-half-arguments-and-returns %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -ffreestanding -fsyntax-only -verify -msve-vector-bits=512 -fallow-half-arguments-and-returns %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -ffreestanding -fsyntax-only -verify -msve-vector-bits=1024 -fallow-half-arguments-and-returns %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve -target-feature +bf16 -ffreestanding -fsyntax-only -verify -msve-vector-bits=2048 -fallow-half-arguments-and-returns %s
+
+#include 
 
 #define N __ARM_FEATURE_SVE_BITS
 
+typedef __fp16 float16_t;
+typedef float float32_t;
+typedef double float64_t;
 typedef __SVInt8_t svint8_t;
 typedef __SVInt16_t svint16_t;
 typedef __SVInt32_t svint32_t;
@@ -19,6 +24,7 @@
 typedef __SVFloat64_t svfloat64_t;
 
 #if defined(__ARM_FEATURE_SVE_BF16)
+typedef __bf16 bfloat16_t;
 typedef __SVBFloat16_t svbfloat16_t;
 #endif
 
@@ -43,6 +49,23 @@
 
 typedef svbool_t fixed_bool_t __att

[PATCH] D87534: Sema: introduce `__attribute__((__swift_name__))`

2020-09-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:2174
+   ObjCInterface, ObjCClassMethod, ObjCInstanceMethod, 
ObjCProperty, ObjCProtocol],
+  ErrorDiag, "ExpectedSwiftNameSubjects">;
+  let Documentation = [SwiftNameDocs];

I don't see anything adding `ExpectedSwiftNameSubjects` to the list of 
diagnostic enumerations, are you sure this is needed?



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:3985
+def warn_attr_swift_name_basename_invalid_identifier
+  : Warning<"%0 attribute has invalid identifier for base name">,
+InGroup;

I think several of these can be consolidated into a single diagnostic with 
`%select`:

`%0 attribute has invalid identifier for %select{context name|base 
name|parameter name}1`



Comment at: clang/include/clang/Sema/Sema.h:1839
+  /// attribute for the decl \p D. Raise a diagnostic if the name is invalid
+  /// for the given declaration.
+  ///

The docs should probably mention what `AL` is used for.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:4282
+StringRef Name, bool Override) {
+  if (const SwiftNameAttr *Inline = D->getAttr()) {
+if (Override) {

`const auto *`



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:4289
+if (Inline->getName() != Name && !Inline->isImplicit()) {
+  Diag(Inline->getLocation(), diag::warn_attribute_ignored) << Inline;
+  Diag(CI.getLoc(), diag::note_conflicting_attribute);

I think it would be more helpful if the diagnostic said why the attribute is 
being ignored (because the arguments don't match).



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:5658
+static Optional
+validateSwiftFunctionName(StringRef Name, unsigned &SwiftParamCount,
+  bool &IsSingleParamInit) {

FWIW, I'm not particularly qualified to review the logic here. Someone with 
more Swift experience should look at this bit.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:5660
+  bool &IsSingleParamInit) {
+  SwiftParamCount = 0;
+

Set `IsSingleParamInit` as well (nothing sets it before the early return on 
line 5673)?



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:5804-5805
+if (const auto *Method = dyn_cast(D)) {
+  ParamCount = Method->getSelector().getNumArgs();
+  Params = Method->parameters().slice(0, ParamCount);
+} else {

Do you have to worry about functions with `...` variadic parameters and how 
those impact counts (for either ObjC or regular methods)?



Comment at: clang/test/SemaObjC/attr-swift-name.m:1
+// RUN: %clang_cc1 -verify -fsyntax-only -fobjc-arc -fblocks %s
+

The `fblocks` makes me wonder -- should this attribute be one you can write on 
a block?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87534/new/

https://reviews.llvm.org/D87534

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


[PATCH] D87163: [DSE] Switch to MemorySSA-backed DSE by default.

2020-09-14 Thread Mikael Holmén via Phabricator via cfe-commits
uabelho added a comment.

In D87163#2270918 , @uabelho wrote:

> In D87163#2270860 , @fhahn wrote:
>
>> In D87163#2270568 , @uabelho wrote:
>>
>>> Hi,
>>>
>>> I'm seeing what I think is a miscompile with this:
>>
>> Thanks for the reproducer. We have to be more careful around pointers that 
>> may reference multiple locations in memory. I pushed f715d81c9df3 
>>  which 
>> limits elimination to stores that only reference a single location (or are 
>> in the same BB). The check is conservative and can be improved in the 
>> future, but the impact on the number of stores eliminated seems very low in 
>> practice. It would be great if you could check if that fixes the original 
>> reproducer.
>
> Great! I'll check and get back during the day.

Yep, the original reproducer passes now. Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87163/new/

https://reviews.llvm.org/D87163

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


[PATCH] D87396: Sema: add support for `__attribute__((__swift_typedef_bridged__))`

2020-09-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:2123
+  let Spellings = [GNU<"swift_bridged_typedef">];
+  let Subjects = SubjectList<[TypedefName], ErrorDiag, "typedefs">;
+  let Documentation = [SwiftBridgedTypedefDocs];

compnerd wrote:
> aaron.ballman wrote:
> > Does the default diagnostic text generate something bad that caused you to 
> > add `typedefs` here?
> I don't remember, I'll double check.
I noticed on a few other reviews that there was a field there, I wonder if the 
code originated before we added smarter logic for arbitrary subject lists.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:7543
+  case ParsedAttr::AT_SwiftBridgedTypedef:
+handleSimpleAttribute(S, D, AL);
+break;

compnerd wrote:
> aaron.ballman wrote:
> > Should there be any type checking that the underlying type of the typedef 
> > is a sensible one to bridge?
> I can't really think of anything that you could check that would be valuable. 
>  What types of things were you thinking?
I was mostly thinking about builtin types like `int`, but I don't insist.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87396/new/

https://reviews.llvm.org/D87396

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


[PATCH] D87518: [analyzer][Liveness][NFC] Remove an unneeded pass to collect variables that appear in an assignment

2020-09-14 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

> This problem only exists if we traverse a CFGBlock in order. And Liveness in 
> fact does it reverse order. So a distinct pass is indeed unnecessary, we can 
> note the appearance of the assignment by the time we reach the variable.

Should this patch depend on https://reviews.llvm.org/D87519?




Comment at: clang/include/clang/Analysis/CFG.h:1311
+
+  llvm::iterator_range nodes() { return *this; }
+  llvm::iterator_range const_nodes() const { return *this; }

Do we convert `this` to `CFGBlock *Entry` here? If yes, please comment it there 
in the code, so others should not be forced to dig up the first data member. 
(If no then this code is hard to understand.)

Even better, why not `return *Entry`?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87518/new/

https://reviews.llvm.org/D87518

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


[PATCH] D87527: [ASTMatchers] Fix `hasBody` for the descendants of `FunctionDecl`

2020-09-14 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

In D87527#2270939 , @ymandel wrote:

> Can you expand on what is wrong currently for `FunctionDecl` descendants? 
> Would the new test `FindsBodyOfFunctionChildren` fail with the current 
> implementation?

Yes, exactly. They return 2 findings instead of 1 because the matcher matches 
both the forward declaration and the definition. The cause for this is that 
template specializations do not work for the descendants of the class for which 
is template specialized. Instead, the generic version is used. Thus for the 
children of `FunctionDecl` the original `GetBodyMatcher` is instantiated which 
does not check whether `doesThisDeclarationHaveABody()` but returns a body 
instead which may be bound to another declaration of the same function in the 
declaration chain. This is obviously wrong.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87527/new/

https://reviews.llvm.org/D87527

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


[PATCH] D87518: [analyzer][Liveness][NFC] Remove an unneeded pass to collect variables that appear in an assignment

2020-09-14 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/include/clang/Analysis/CFG.h:1311
+
+  llvm::iterator_range nodes() { return *this; }
+  llvm::iterator_range const_nodes() const { return *this; }

martong wrote:
> Do we convert `this` to `CFGBlock *Entry` here? If yes, please comment it 
> there in the code, so others should not be forced to dig up the first data 
> member. (If no then this code is hard to understand.)
> 
> Even better, why not `return *Entry`?
Uuups, okay, so we use `begin` and `end` here, my bad. But then perhaps it is 
better to explicitly write this down. E.g. return {begin(), end()}, would be 
much cleaner IMHO.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87518/new/

https://reviews.llvm.org/D87518

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


[PATCH] D87527: [ASTMatchers] Fix `hasBody` for the descendants of `FunctionDecl`

2020-09-14 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

In D87527#2271016 , 
@baloghadamsoftware wrote:

> In D87527#2270939 , @ymandel wrote:
>
>> Can you expand on what is wrong currently for `FunctionDecl` descendants? 
>> Would the new test `FindsBodyOfFunctionChildren` fail with the current 
>> implementation?
>
> Yes, exactly. They return 2 findings instead of 1 because the matcher matches 
> both the forward declaration and the definition. The cause for this is that 
> template specializations do not work for the descendants of the class for 
> which is template specialized. Instead, the generic version is used. Thus for 
> the children of `FunctionDecl` the original `GetBodyMatcher` is instantiated 
> which does not check whether `doesThisDeclarationHaveABody()` but returns a 
> body instead which may be bound to another declaration of the same function 
> in the declaration chain. This is obviously wrong.

Thank you for clarifying. I might nitpick that it's not "obviously wrong": I'm 
actually writing code now that depends on exactly that behavior -- I don't care 
where the method decl body is, as long as it's visible in the current TU.  That 
said, I think you're right in wanting `FunctionDecl`'s behavior to align with 
that of its derived classes and I think it better to behave that way than how 
it currently behaves.  But, we should have an alternative available in case 
this change breaks anyone else depending on the current behavior.  Is there a 
different matcher with the semantics I've described?

Also, please clarify the comments in the header for this matcher. The current 
description is quite unclear for functions: "Matches a 'for', 'while', 'do 
while' statement or a function
definition that has a given body."


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87527/new/

https://reviews.llvm.org/D87527

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


[PATCH] D87527: [ASTMatchers] Fix `hasBody` for the descendants of `FunctionDecl`

2020-09-14 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

> Thank you for clarifying. I might nitpick that it's not "obviously wrong": 
> I'm actually writing code now that depends on exactly that behavior -- I 
> don't care where the method decl body is, as long as it's visible in the 
> current TU.  That said, I think you're right in wanting `FunctionDecl`'s 
> behavior to align with that of its derived classes and I think it better to 
> behave that way than how it currently behaves.  But, we should have an 
> alternative available in case this change breaks anyone else depending on the 
> current behavior.  Is there a different matcher with the semantics I've 
> described?
>
> Also, please clarify the comments in the header for this matcher. The current 
> description is quite unclear for functions: "Matches a 'for', 'while', 'do 
> while' statement or a function
> definition that has a given body."

We must decide about the namings. If we want to be in sync with the methods in 
`FunctionDecl`, then we keep `hasBody()` as is, but remove the template 
specialization, and create a new `doesThisDeclarationHaveABody()`. However, 
this involves changing existing checks. The other solution is to fix 
`hasBody()` like in this patch, and find a new name for the other behavior, 
such as e.g. `hasBodySomewhere()` or something similar.

The comments in the header are really poorly written, but there is the word 
//definition// which means that the matcher matches function definitions and 
not declarations. This is surely to be rephrased.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87527/new/

https://reviews.llvm.org/D87527

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


[PATCH] D87519: [analyzer][Liveness][NFC] Enqueue the CFGBlocks post-order

2020-09-14 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/Analysis/LiveVariables.cpp:522
 
-  // FIXME: we should enqueue using post order.
-  for (const CFGBlock *B : cfg->nodes()) {
+  for (const CFGBlock *B : *AC.getAnalysis()) {
 worklist.enqueueBlock(B);

xazax.hun wrote:
> With `BackwardDataflowWorklist`, each  `enqueueBlock` will insert the block 
> into a `llvm::PriorityQueue`. So regardless of the insertion order, `dequeue` 
> will return the nodes in the reverse post order. 
> 
> Inserting elements in the right order into the heap might be beneficial is we 
> need to to less work to "heapify". But on the other hand, we did more work to 
> insert them in the right order, in the first place. All in all, I am not sure 
> whether the comment is still valid and whether this patch would provide any 
> benefit over the original code. 
> 
Yes, what Gabor says makes sense. On the other hand I don't see any overhead - 
I might be wrong though - in the post order visitation. And it makes the code 
more consistent IMHO.

Well, it would be important to know why the original author put the 
```
// FIXME: we should enqueue using post order.
```
there. The blamed commit 77ff930fff15c3fc76101b38199dad355be0866b is not saying 
much.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87519/new/

https://reviews.llvm.org/D87519

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


[PATCH] D71199: [clang-tidy] New check cppcoreguidelines-prefer-member-initializer

2020-09-14 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 291562.
baloghadamsoftware added a comment.

No crash, no hang, no false positives on the LLVM Project.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71199/new/

https://reviews.llvm.org/D71199

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-prefer-member-initializer.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer-modernize-use-default-member-init-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer-modernize-use-default-member-init.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-prefer-member-initializer.cpp
@@ -0,0 +1,474 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-prefer-member-initializer %t -- -- -fcxx-exceptions
+
+extern void __assert_fail (__const char *__assertion, __const char *__file,
+unsigned int __line, __const char *__function)
+ __attribute__ ((__noreturn__));
+#define assert(expr) \
+  ((expr)  ? (void)(0)  : __assert_fail (#expr, __FILE__, __LINE__, __func__))
+
+class Simple1 {
+  int n;
+  double x;
+
+public:
+  Simple1() {
+// CHECK-FIXES: Simple1() : n(0), x(0.0) {
+n = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+x = 0.0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  Simple1(int nn, double xx) {
+// CHECK-FIXES: Simple1(int nn, double xx) : n(nn), x(xx) {
+n = nn;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+x = xx;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple1() = default;
+};
+
+class Simple2 {
+  int n;
+  double x;
+
+public:
+  Simple2() : n(0) {
+// CHECK-FIXES: Simple2() : n(0), x(0.0) {
+x = 0.0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  Simple2(int nn, double xx) : n(nn) {
+// CHECK-FIXES: Simple2(int nn, double xx) : n(nn), x(xx) {
+x = xx;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple2() = default;
+};
+
+class Simple3 {
+  int n;
+  double x;
+
+public:
+  Simple3() : x(0.0) {
+// CHECK-FIXES: Simple3() : n(0), x(0.0) {
+n = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  Simple3(int nn, double xx) : x(xx) {
+// CHECK-FIXES: Simple3(int nn, double xx) : n(nn), x(xx) {
+n = nn;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple3() = default;
+};
+
+int something_int();
+double something_double();
+
+class Simple4 {
+  int n;
+
+public:
+  Simple4() {
+// CHECK-FIXES: Simple4() : n(something_int()) {
+n = something_int();
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
+// CHECK-FIXES: {{^\ *$}}
+  }
+
+  ~Simple4() = default;
+};
+
+static bool dice();
+
+class Complex1 {
+  int n;
+  int m;
+
+public:
+  Complex1() : n(0) {
+if (dice())
+  m = 1;
+// NO-MESSAGES: initialization of 'm' is nested in a conditional expression
+  }
+
+  ~Complex1() = default;
+};
+
+class Complex2 {
+  int n;
+  int m;
+
+public:
+  Complex2() : n(0) {
+if (!dice())
+  return;
+m = 1;
+// NO-MESSAGES: 

[PATCH] D83500: [PowerPC][Power10] Implement custom codegen for the vec_replace_elt and vec_replace_unaligned builtins.

2020-09-14 Thread Amy Kwan via Phabricator via cfe-commits
amyk added a comment.

@nemanjai Could you please take another look to see if I have addressed your 
comments?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83500/new/

https://reviews.llvm.org/D83500

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


[PATCH] D86841: [clang] Add mustprogress and llvm.loop.mustprogress attribute deduction

2020-09-14 Thread Atmn Patel via Phabricator via cfe-commits
atmnpatel updated this revision to Diff 291567.
atmnpatel added a comment.

Fixed failing test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86841/new/

https://reviews.llvm.org/D86841

Files:
  clang/lib/CodeGen/CGLoopInfo.cpp
  clang/lib/CodeGen/CGLoopInfo.h
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/address-safety-attr-flavors.cpp
  clang/test/CodeGen/address-safety-attr.cpp
  clang/test/CodeGen/attr-noprogress.c
  clang/test/CodeGen/attr-noprogress.cpp
  clang/test/CodeGen/memtag-attr.cpp
  clang/test/CodeGen/no-builtin.cpp
  clang/test/CodeGenCXX/cxx11-trivial-initializer-struct.cpp
  clang/test/CodeGenCXX/fno-unroll-loops-metadata.cpp
  clang/test/CodeGenCXX/thunks-ehspec.cpp
  clang/test/CodeGenCXX/thunks.cpp
  clang/test/OpenMP/simd_metadata.c
  clang/test/Profile/c-unprofiled-blocks.c
  clang/test/utils/update_cc_test_checks/Inputs/basic-cplusplus.cpp.expected
  
clang/test/utils/update_cc_test_checks/Inputs/check-attributes.cpp.funcattrs.expected

Index: clang/test/utils/update_cc_test_checks/Inputs/check-attributes.cpp.funcattrs.expected
===
--- clang/test/utils/update_cc_test_checks/Inputs/check-attributes.cpp.funcattrs.expected
+++ clang/test/utils/update_cc_test_checks/Inputs/check-attributes.cpp.funcattrs.expected
@@ -11,7 +11,7 @@
   struct RT Z;
 };
 
-// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK: Function Attrs: noinline nounwind optnone mustprogress
 // CHECK-LABEL: @_Z3fooP2ST(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[S_ADDR:%.*]] = alloca %struct.ST*, align 8
Index: clang/test/utils/update_cc_test_checks/Inputs/basic-cplusplus.cpp.expected
===
--- clang/test/utils/update_cc_test_checks/Inputs/basic-cplusplus.cpp.expected
+++ clang/test/utils/update_cc_test_checks/Inputs/basic-cplusplus.cpp.expected
@@ -44,7 +44,7 @@
 // CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca %class.Foo*, align 8
 // CHECK-NEXT:store %class.Foo* [[THIS:%.*]], %class.Foo** [[THIS_ADDR]], align 8
 // CHECK-NEXT:[[THIS1:%.*]] = load %class.Foo*, %class.Foo** [[THIS_ADDR]], align 8
-// CHECK-NEXT:call void @_ZN3FooD2Ev(%class.Foo* [[THIS1]]) [[ATTR2:#.*]]
+// CHECK-NEXT:call void @_ZN3FooD2Ev(%class.Foo* [[THIS1]]) [[ATTR3:#.*]]
 // CHECK-NEXT:ret void
 //
 Foo::~Foo() {}
@@ -70,7 +70,7 @@
 // CHECK-NEXT:call void @_ZN3FooC1Ei(%class.Foo* [[F]], i32 1)
 // CHECK-NEXT:[[CALL:%.*]] = call i32 @_ZNK3Foo23function_defined_inlineEi(%class.Foo* [[F]], i32 2)
 // CHECK-NEXT:[[CALL1:%.*]] = call i32 @_ZNK3Foo28function_defined_out_of_lineEi(%class.Foo* [[F]], i32 3)
-// CHECK-NEXT:call void @_ZN3FooD1Ev(%class.Foo* [[F]]) [[ATTR2]]
+// CHECK-NEXT:call void @_ZN3FooD1Ev(%class.Foo* [[F]]) [[ATTR3]]
 // CHECK-NEXT:ret i32 0
 //
 int main() {
Index: clang/test/Profile/c-unprofiled-blocks.c
===
--- clang/test/Profile/c-unprofiled-blocks.c
+++ clang/test/Profile/c-unprofiled-blocks.c
@@ -16,7 +16,7 @@
   // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
   while (--i) {}
 
-  // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
+  // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}, !llvm.loop [[LOOP1:!.*]]
   do {} while (i++ < 75);
 
   // PGOUSE: switch {{.*}} [
@@ -46,7 +46,7 @@
 // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
 while (--i) {}
 
-// PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
+// PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}, !llvm.loop [[LOOP2:!.*]]
 do {} while (i++ < 75);
 
 // PGOUSE: switch {{.*}} [
Index: clang/test/OpenMP/simd_metadata.c
===
--- clang/test/OpenMP/simd_metadata.c
+++ clang/test/OpenMP/simd_metadata.c
@@ -137,7 +137,8 @@
 }
 // CHECK: store float {{.+}}, float* {{.+}}, align {{.+}}, !llvm.access.group ![[ACCESS_GROUP_13:[0-9]+]]
   }
-// CHECK: br label %{{.+}}, !llvm.loop [[LOOP_H3_HEADER:![0-9]+]]
+  // CHECK: br label %{{.+}}, !llvm.loop [[LOOP_H3_HEADER_INNER:![0-9]+]]
+  // CHECK: br label %{{.+}}, !llvm.loop [[LOOP_H3_HEADER:![0-9]+]]
 }
 
 // Metadata for h1:
Index: clang/test/CodeGenCXX/thunks.cpp
===
--- clang/test/CodeGenCXX/thunks.cpp
+++ clang/test/CodeGenCXX/thunks.cpp
@@ -529,7 +529,7 @@
 // CHECK-NONOPT-LABEL: define linkonce_odr void @_ZThn8_N6Test101C3fooEv
 
 // Checking with opt
-// CHECK-OPT-LABEL: define internal void @_ZThn8_N6Test4B12_GLOBAL__N_11C1fEv(%"struct.Test4B::(anonymous namespace)::C"* %this) unnamed_addr #0 align 2
+// CHECK-OPT-LABEL: define internal void @_ZThn8_N6Test4B12_GLOBAL__N_11C1fEv(%"struct.Test4B::(anonymous namespace)::C"* %this) unnamed_add

[PATCH] D87611: [SystemZ][z/OS] Set aligned allocation unavailable by default for z/OS

2020-09-14 Thread Fanbo Meng via Phabricator via cfe-commits
fanbo-meng created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
fanbo-meng requested review of this revision.

Aligned allocation is not supported on z/OS.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87611

Files:
  clang/lib/Driver/ToolChains/ZOS.cpp
  clang/lib/Driver/ToolChains/ZOS.h
  clang/test/Driver/unavailable_aligned_allocation.cpp
  clang/test/Lexer/aligned-allocation.cpp


Index: clang/test/Lexer/aligned-allocation.cpp
===
--- clang/test/Lexer/aligned-allocation.cpp
+++ clang/test/Lexer/aligned-allocation.cpp
@@ -6,10 +6,19 @@
 //
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -fexceptions -std=c++17 
-verify %s \
 // RUN:   -faligned-allocation -faligned-alloc-unavailable
+//
+// RUN: %clang_cc1 -triple s390x-ibm-zos -fexceptions -std=c++17 -verify %s \
+// RUN:   -DEXPECT_DEFINED
+//
+// RUN: %clang_cc1 -triple s390x-ibm-zos -fexceptions -std=c++17 -verify %s \
+// RUN:   -faligned-alloc-unavailable
+//
+// RUN: %clang_cc1 -triple s390x-ibm-zos -fexceptions -std=c++17 -verify %s \
+// RUN:   -faligned-allocation -faligned-alloc-unavailable
 
 // Test that __cpp_aligned_new is not defined when CC1 is passed
-// -faligned-alloc-unavailable by the Darwin driver, even when aligned
-// allocation is actually enabled.
+// -faligned-alloc-unavailable by the Darwin and the z/OS driver, even when
+// aligned allocation is actually enabled.
 
 // expected-no-diagnostics
 #ifdef EXPECT_DEFINED
Index: clang/test/Driver/unavailable_aligned_allocation.cpp
===
--- clang/test/Driver/unavailable_aligned_allocation.cpp
+++ clang/test/Driver/unavailable_aligned_allocation.cpp
@@ -22,6 +22,9 @@
 // RUN: -c -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=UNAVAILABLE
 //
+// RUN: %clang -target s390x-ibm-zos -c -### %s 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=UNAVAILABLE
+
 // UNAVAILABLE: "-faligned-alloc-unavailable"
 
 // RUN: %clang -target x86_64-apple-macosx10.14 -c -### %s 2>&1 \
@@ -59,5 +62,11 @@
 //
 // RUN: %clang -target x86_64-apple-macosx10.13 -fno-aligned-allocation -c 
-### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix=AVAILABLE
+//
+// RUN: %clang -target s390x-ibm-zos -faligned-allocation -c -### %s 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=AVAILABLE
+//
+// RUN: %clang -target s390x-ibm-zos -fno-aligned-allocation -c -### %s 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=AVAILABLE
 
 // AVAILABLE-NOT: "-faligned-alloc-unavailable"
Index: clang/lib/Driver/ToolChains/ZOS.h
===
--- clang/lib/Driver/ToolChains/ZOS.h
+++ clang/lib/Driver/ToolChains/ZOS.h
@@ -27,6 +27,10 @@
   bool isPICDefaultForced() const override { return false; }
 
   bool IsIntegratedAssemblerDefault() const override { return true; }
+
+  void addClangTargetOptions(
+  const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
+  Action::OffloadKind DeviceOffloadingKind) const override;
 };
 
 } // end namespace toolchains
Index: clang/lib/Driver/ToolChains/ZOS.cpp
===
--- clang/lib/Driver/ToolChains/ZOS.cpp
+++ clang/lib/Driver/ToolChains/ZOS.cpp
@@ -21,3 +21,13 @@
 : ToolChain(D, Triple, Args) {}
 
 ZOS::~ZOS() {}
+
+void ZOS::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+llvm::opt::ArgStringList &CC1Args,
+Action::OffloadKind DeviceOffloadKind) const {
+  // Pass "-faligned-alloc-unavailable" only when the user hasn't manually
+  // enabled or disabled aligned allocations.
+  if (!DriverArgs.hasArgNoClaim(options::OPT_faligned_allocation,
+options::OPT_fno_aligned_allocation))
+CC1Args.push_back("-faligned-alloc-unavailable");
+}


Index: clang/test/Lexer/aligned-allocation.cpp
===
--- clang/test/Lexer/aligned-allocation.cpp
+++ clang/test/Lexer/aligned-allocation.cpp
@@ -6,10 +6,19 @@
 //
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -fexceptions -std=c++17 -verify %s \
 // RUN:   -faligned-allocation -faligned-alloc-unavailable
+//
+// RUN: %clang_cc1 -triple s390x-ibm-zos -fexceptions -std=c++17 -verify %s \
+// RUN:   -DEXPECT_DEFINED
+//
+// RUN: %clang_cc1 -triple s390x-ibm-zos -fexceptions -std=c++17 -verify %s \
+// RUN:   -faligned-alloc-unavailable
+//
+// RUN: %clang_cc1 -triple s390x-ibm-zos -fexceptions -std=c++17 -verify %s \
+// RUN:   -faligned-allocation -faligned-alloc-unavailable
 
 // Test that __cpp_aligned_new is not defined when CC1 is passed
-// -faligned-alloc-unavailable by the Darwin driver, even when aligned
-// allocation is actually enabled.
+// -faligned-alloc-unavailable by the Darwin and the z/OS driver, even when
+// aligned allocation is a

[PATCH] D87527: [ASTMatchers] Fix `hasBody` for the descendants of `FunctionDecl`

2020-09-14 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

In D87527#2271059 , 
@baloghadamsoftware wrote:

> We must decide about the namings. If we want to be in sync with the methods 
> in `FunctionDecl`, then we keep `hasBody()` as is, but remove the template 
> specialization, and create a new `doesThisDeclarationHaveABody()`. However, 
> this involves changing existing checks. The other solution is to fix 
> `hasBody()` like in this patch, and find a new name for the other behavior, 
> such as e.g. `hasBodySomewhere()` or something similar.

Agreed. I think we should stick with your approach, since it involves fewer 
changes and is consistent with the AST API itself.  As for naming, 
`hasBodySomewhere()` works, but other options: `hasSomeBody`, `hasAnyBody`, 
`hasBodyForSomeDecl`.

FWIW, I checked our codebase and we definitely have a handful of uses that rely 
on current behavior. So, I think its important to add the new matcher before we 
commit this change.

> The comments in the header are really poorly written, but there is the word 
> //definition// which means that the matcher matches function definitions and 
> not declarations. This is surely to be rephrased.

+1

Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87527/new/

https://reviews.llvm.org/D87527

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


[PATCH] D87615: [clang][Driver] Force stack realignment on 32-bit Solaris/x86

2020-09-14 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added reviewers: MaskRay, rahmanl, efriedma, RKSimon.
ro added a project: clang.
Herald added a subscriber: fedor.sergeev.
ro requested review of this revision.

On Solaris/x86, several hundred 32-bit tests `FAIL`, all in the same way:

  env ASAN_OPTIONS=halt_on_error=false 
./halt_on_error_suppress_equal_pcs.cpp.tmp
  Segmentation Fault (core dumped)

They segfault during startup:

  Thread 2 received signal SIGSEGV, Segmentation fault.
  [Switching to Thread 1 (LWP 1)]
  0x080f21f0 in __sanitizer::internal_mmap(void*, unsigned long, int, int, int, 
unsigned long long) () at 
/vol/llvm/src/llvm-project/dist/compiler-rt/lib/sanitizer_common/sanitizer_solaris.cpp:65
  65 int prot, int flags, int fd, OFF_T offset) 
{
  1: x/i $pc
  => 0x80f21f0 <_ZN11__sanitizer13internal_mmapEPvmiiiy+16>:movaps 
0x30(%esp),%xmm0
  (gdb) p/x $esp
  $3 = 0xfeffd488

The problem is that `movaps` expects 16-byte alignment, while 32-bit Solaris/x86
only guarantees 4-byte alignment following the i386 psABI.

This patch avoid the issue by defaulting to `-mstackrealign`, just like `gcc`.

Tested on `amd64-pc-solaris2.11`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87615

Files:
  clang/lib/Driver/ToolChains/Clang.cpp


Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2030,6 +2030,14 @@
   const Driver &D = getToolChain().getDriver();
   addX86AlignBranchArgs(D, Args, CmdArgs, /*IsLTO=*/false);
 
+  // 32-bit Solaris/x86 only guarantees 4-byte stack alignment as required by
+  // the i386 psABI, so realign it as necessary for SSE instructions.
+  const llvm::Triple &Triple = getToolChain().getTriple();
+  if (Triple.isOSSolaris() && Triple.getArch() == llvm::Triple::x86 &&
+  Args.hasFlag(options::OPT_mstackrealign, options::OPT_mno_stackrealign,
+   true))
+CmdArgs.push_back("-mstackrealign");
+
   if (!Args.hasFlag(options::OPT_mred_zone, options::OPT_mno_red_zone, true) ||
   Args.hasArg(options::OPT_mkernel) ||
   Args.hasArg(options::OPT_fapple_kext))


Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2030,6 +2030,14 @@
   const Driver &D = getToolChain().getDriver();
   addX86AlignBranchArgs(D, Args, CmdArgs, /*IsLTO=*/false);
 
+  // 32-bit Solaris/x86 only guarantees 4-byte stack alignment as required by
+  // the i386 psABI, so realign it as necessary for SSE instructions.
+  const llvm::Triple &Triple = getToolChain().getTriple();
+  if (Triple.isOSSolaris() && Triple.getArch() == llvm::Triple::x86 &&
+  Args.hasFlag(options::OPT_mstackrealign, options::OPT_mno_stackrealign,
+   true))
+CmdArgs.push_back("-mstackrealign");
+
   if (!Args.hasFlag(options::OPT_mred_zone, options::OPT_mno_red_zone, true) ||
   Args.hasArg(options::OPT_mkernel) ||
   Args.hasArg(options::OPT_fapple_kext))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87455: [clang-tidy] performance-unnecessary-copy-initialization: Restrict UnnecessaryCopyInitialization check to variables initialized from free functions without arguments

2020-09-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp:126
   if (OldVar == nullptr) {
+// Only allow initialization of a const reference from a free function if 
it
+// has no arguments or only default arguments. Otherwise it could return

I'm not certain I agree with this change, but I'm also not certain I disagree 
with it. There are more ways to alias than just default arguments (global 
variables, etc) and the presence of a default argument is not really an 
indication about its return value in this case. e.g.,
```
const ExpensiveToCopyType &freeFunctionWithDefaultArg(int i = 12);
```
(I don't see a reason why `= 12` should impact whether use of this function 
diagnoses or not.)

Perhaps if this was tightened up a bit to care about the type of the default 
argument it might make sense, but even that gets tricky when you consider base 
classes, template types, etc. and doesn't cover all of the aliasing cases 
anyway. Is there an important use case for this behavior?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87455/new/

https://reviews.llvm.org/D87455

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


[PATCH] D83814: [clangd] Add Random Forest runtime for code completion.

2020-09-14 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz added inline comments.



Comment at: clang-tools-extra/clangd/unittests/DecisionForestTests.cpp:5
+
+namespace clangd {
+namespace clangd {

This is supposed to be "namespace clang", right?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83814/new/

https://reviews.llvm.org/D83814

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


[PATCH] D87459: [libcxx][test] ostream{,buf}_iterator::difference_type changes in C++20

2020-09-14 Thread Louis Dionne via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG71a16e40f78a: [libcxx] 
ostream{,buf}_iterator::difference_type changes in C++20 (authored by ldionne).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87459/new/

https://reviews.llvm.org/D87459

Files:
  libcxx/include/iterator
  libcxx/test/std/iterators/stream.iterators/ostream.iterator/types.pass.cpp
  libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/types.pass.cpp

Index: libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/types.pass.cpp
===
--- libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/types.pass.cpp
+++ libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/types.pass.cpp
@@ -19,6 +19,7 @@
 //   typedef basic_ostream   ostream_type;
 //   ...
 
+#include 
 #include 
 #include 
 #include 
@@ -34,7 +35,11 @@
 #else
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
+#if TEST_STD_VER <= 17
 static_assert((std::is_same::value), "");
+#else
+static_assert((std::is_same::value), "");
+#endif
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
 #endif
@@ -50,7 +55,11 @@
 #else
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
+#if TEST_STD_VER <= 17
 static_assert((std::is_same::value), "");
+#else
+static_assert((std::is_same::value), "");
+#endif
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
 #endif
Index: libcxx/test/std/iterators/stream.iterators/ostream.iterator/types.pass.cpp
===
--- libcxx/test/std/iterators/stream.iterators/ostream.iterator/types.pass.cpp
+++ libcxx/test/std/iterators/stream.iterators/ostream.iterator/types.pass.cpp
@@ -19,6 +19,7 @@
 // typedef basic_istream istream_type;
 // ...
 
+#include 
 #include 
 #include 
 
@@ -33,7 +34,11 @@
 #else
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
+#if TEST_STD_VER <= 17
 static_assert((std::is_same::value), "");
+#else
+static_assert((std::is_same::value), "");
+#endif
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
 #endif
@@ -47,7 +52,11 @@
 #else
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
+#if TEST_STD_VER <= 17
 static_assert((std::is_same::value), "");
+#else
+static_assert((std::is_same::value), "");
+#endif
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
 #endif
Index: libcxx/include/iterator
===
--- libcxx/include/iterator
+++ libcxx/include/iterator
@@ -1052,9 +1052,19 @@
 : public iterator
 {
 public:
-typedef _CharT char_type;
-typedef _Traits traits_type;
-typedef basic_ostream<_CharT,_Traits> ostream_type;
+typedef output_iterator_tag iterator_category;
+typedef voidvalue_type;
+#if _LIBCPP_STD_VER > 17
+typedef std::ptrdiff_t  difference_type;
+#else
+typedef voiddifference_type;
+#endif
+typedef voidpointer;
+typedef voidreference;
+typedef _CharT  char_type;
+typedef _Traits traits_type;
+typedef basic_ostream<_CharT, _Traits>  ostream_type;
+
 private:
 ostream_type* __out_stream_;
 const char_type* __delim_;
@@ -1151,10 +1161,20 @@
 : public iterator
 {
 public:
-typedef _CharT  char_type;
-typedef _Traits traits_type;
-typedef basic_streambuf<_CharT,_Traits> streambuf_type;
-typedef basic_ostream<_CharT,_Traits>   ostream_type;
+typedef output_iterator_tag iterator_category;
+typedef voidvalue_type;
+#if _LIBCPP_STD_VER > 17
+typedef std::ptrdiff_t  difference_type;
+#else
+typedef voiddifference_type;
+#endif
+typedef voidpointer;
+typedef voidreference;
+typedef _CharT  char_type;
+typedef _Traits traits_type;
+typedef basic_streambuf<_CharT, _Traits>streambuf_type;
+typedef basic_ostream<_CharT, _Traits>  ostream_type;
+
 private:
 streambuf_type* __sbuf_;
 public:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinf

[PATCH] D87615: [clang][Driver] Force stack realignment on 32-bit Solaris/x86

2020-09-14 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

Would it be possible to add some tests?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87615/new/

https://reviews.llvm.org/D87615

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


[clang] 3b7708e - Assert we've found the size of each (non-overlapping) structure. NFCI.

2020-09-14 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2020-09-14T16:10:52+01:00
New Revision: 3b7708e2deb48befcef764fb69f9217f55ac1155

URL: 
https://github.com/llvm/llvm-project/commit/3b7708e2deb48befcef764fb69f9217f55ac1155
DIFF: 
https://github.com/llvm/llvm-project/commit/3b7708e2deb48befcef764fb69f9217f55ac1155.diff

LOG: Assert we've found the size of each (non-overlapping) structure. NFCI.

Fixes clang static analyzer warning.

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index c55403920d8f..5384e9196896 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7692,6 +7692,7 @@ class MappableExprsHandler {
 break;
   }
 }
+assert(Size && "Failed to determine structure size");
 CombinedInfo.BasePointers.push_back(BP.getPointer());
 CombinedInfo.Pointers.push_back(LB.getPointer());
 CombinedInfo.Sizes.push_back(CGF.Builder.CreateIntCast(



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


[PATCH] D87396: Sema: add support for `__attribute__((__swift_typedef_bridged__))`

2020-09-14 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:2123
+  let Spellings = [GNU<"swift_bridged_typedef">];
+  let Subjects = SubjectList<[TypedefName], ErrorDiag, "typedefs">;
+  let Documentation = [SwiftBridgedTypedefDocs];

aaron.ballman wrote:
> compnerd wrote:
> > aaron.ballman wrote:
> > > Does the default diagnostic text generate something bad that caused you 
> > > to add `typedefs` here?
> > I don't remember, I'll double check.
> I noticed on a few other reviews that there was a field there, I wonder if 
> the code originated before we added smarter logic for arbitrary subject lists.
Yes, this code is definitely old.  If there are sites that you notice that 
could be changed to something new,  Im happy to work though those changes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87396/new/

https://reviews.llvm.org/D87396

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


[PATCH] D77491: [Sema] Introduce BuiltinAttr, per-declaration builtin-ness

2020-09-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:2088
+
+  if (Error || R.isNull())
+return nullptr;

Should we do this check *before* we create the C linkage decl spec above?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77491/new/

https://reviews.llvm.org/D77491

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


[PATCH] D87455: [clang-tidy] performance-unnecessary-copy-initialization: Restrict UnnecessaryCopyInitialization check to variables initialized from free functions without arguments

2020-09-14 Thread Felix Berger via Phabricator via cfe-commits
flx added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp:126
   if (OldVar == nullptr) {
+// Only allow initialization of a const reference from a free function if 
it
+// has no arguments or only default arguments. Otherwise it could return

aaron.ballman wrote:
> I'm not certain I agree with this change, but I'm also not certain I disagree 
> with it. There are more ways to alias than just default arguments (global 
> variables, etc) and the presence of a default argument is not really an 
> indication about its return value in this case. e.g.,
> ```
> const ExpensiveToCopyType &freeFunctionWithDefaultArg(int i = 12);
> ```
> (I don't see a reason why `= 12` should impact whether use of this function 
> diagnoses or not.)
> 
> Perhaps if this was tightened up a bit to care about the type of the default 
> argument it might make sense, but even that gets tricky when you consider 
> base classes, template types, etc. and doesn't cover all of the aliasing 
> cases anyway. Is there an important use case for this behavior?
This was mostly following the logic already applied to the copy constructor 
where the existing code also allowed default arguments. The idea is to not 
disallow functions with default arguments that are not overridden. 

I'll switch to not allowing any arguments. This will just exclude a few more 
cases, but better to be safe, until we might be able to verify the constness of 
all function arguments as well.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87455/new/

https://reviews.llvm.org/D87455

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


[PATCH] D86841: [clang] Add mustprogress and llvm.loop.mustprogress attribute deduction

2020-09-14 Thread Atmn Patel via Phabricator via cfe-commits
atmnpatel updated this revision to Diff 291581.
atmnpatel added a comment.

Tests renamed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86841/new/

https://reviews.llvm.org/D86841

Files:
  clang/lib/CodeGen/CGLoopInfo.cpp
  clang/lib/CodeGen/CGLoopInfo.h
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/address-safety-attr-flavors.cpp
  clang/test/CodeGen/address-safety-attr.cpp
  clang/test/CodeGen/attr-mustprogress.c
  clang/test/CodeGen/attr-mustprogress.cpp
  clang/test/CodeGen/memtag-attr.cpp
  clang/test/CodeGen/no-builtin.cpp
  clang/test/CodeGenCXX/cxx11-trivial-initializer-struct.cpp
  clang/test/CodeGenCXX/fno-unroll-loops-metadata.cpp
  clang/test/CodeGenCXX/thunks-ehspec.cpp
  clang/test/CodeGenCXX/thunks.cpp
  clang/test/OpenMP/simd_metadata.c
  clang/test/Profile/c-unprofiled-blocks.c
  clang/test/utils/update_cc_test_checks/Inputs/basic-cplusplus.cpp.expected
  
clang/test/utils/update_cc_test_checks/Inputs/check-attributes.cpp.funcattrs.expected

Index: clang/test/utils/update_cc_test_checks/Inputs/check-attributes.cpp.funcattrs.expected
===
--- clang/test/utils/update_cc_test_checks/Inputs/check-attributes.cpp.funcattrs.expected
+++ clang/test/utils/update_cc_test_checks/Inputs/check-attributes.cpp.funcattrs.expected
@@ -11,7 +11,7 @@
   struct RT Z;
 };
 
-// CHECK: Function Attrs: noinline nounwind optnone
+// CHECK: Function Attrs: noinline nounwind optnone mustprogress
 // CHECK-LABEL: @_Z3fooP2ST(
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[S_ADDR:%.*]] = alloca %struct.ST*, align 8
Index: clang/test/utils/update_cc_test_checks/Inputs/basic-cplusplus.cpp.expected
===
--- clang/test/utils/update_cc_test_checks/Inputs/basic-cplusplus.cpp.expected
+++ clang/test/utils/update_cc_test_checks/Inputs/basic-cplusplus.cpp.expected
@@ -44,7 +44,7 @@
 // CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca %class.Foo*, align 8
 // CHECK-NEXT:store %class.Foo* [[THIS:%.*]], %class.Foo** [[THIS_ADDR]], align 8
 // CHECK-NEXT:[[THIS1:%.*]] = load %class.Foo*, %class.Foo** [[THIS_ADDR]], align 8
-// CHECK-NEXT:call void @_ZN3FooD2Ev(%class.Foo* [[THIS1]]) [[ATTR2:#.*]]
+// CHECK-NEXT:call void @_ZN3FooD2Ev(%class.Foo* [[THIS1]]) [[ATTR3:#.*]]
 // CHECK-NEXT:ret void
 //
 Foo::~Foo() {}
@@ -70,7 +70,7 @@
 // CHECK-NEXT:call void @_ZN3FooC1Ei(%class.Foo* [[F]], i32 1)
 // CHECK-NEXT:[[CALL:%.*]] = call i32 @_ZNK3Foo23function_defined_inlineEi(%class.Foo* [[F]], i32 2)
 // CHECK-NEXT:[[CALL1:%.*]] = call i32 @_ZNK3Foo28function_defined_out_of_lineEi(%class.Foo* [[F]], i32 3)
-// CHECK-NEXT:call void @_ZN3FooD1Ev(%class.Foo* [[F]]) [[ATTR2]]
+// CHECK-NEXT:call void @_ZN3FooD1Ev(%class.Foo* [[F]]) [[ATTR3]]
 // CHECK-NEXT:ret i32 0
 //
 int main() {
Index: clang/test/Profile/c-unprofiled-blocks.c
===
--- clang/test/Profile/c-unprofiled-blocks.c
+++ clang/test/Profile/c-unprofiled-blocks.c
@@ -16,7 +16,7 @@
   // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
   while (--i) {}
 
-  // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
+  // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}, !llvm.loop [[LOOP1:!.*]]
   do {} while (i++ < 75);
 
   // PGOUSE: switch {{.*}} [
@@ -46,7 +46,7 @@
 // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
 while (--i) {}
 
-// PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
+// PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}, !llvm.loop [[LOOP2:!.*]]
 do {} while (i++ < 75);
 
 // PGOUSE: switch {{.*}} [
Index: clang/test/OpenMP/simd_metadata.c
===
--- clang/test/OpenMP/simd_metadata.c
+++ clang/test/OpenMP/simd_metadata.c
@@ -137,7 +137,8 @@
 }
 // CHECK: store float {{.+}}, float* {{.+}}, align {{.+}}, !llvm.access.group ![[ACCESS_GROUP_13:[0-9]+]]
   }
-// CHECK: br label %{{.+}}, !llvm.loop [[LOOP_H3_HEADER:![0-9]+]]
+  // CHECK: br label %{{.+}}, !llvm.loop [[LOOP_H3_HEADER_INNER:![0-9]+]]
+  // CHECK: br label %{{.+}}, !llvm.loop [[LOOP_H3_HEADER:![0-9]+]]
 }
 
 // Metadata for h1:
Index: clang/test/CodeGenCXX/thunks.cpp
===
--- clang/test/CodeGenCXX/thunks.cpp
+++ clang/test/CodeGenCXX/thunks.cpp
@@ -529,7 +529,7 @@
 // CHECK-NONOPT-LABEL: define linkonce_odr void @_ZThn8_N6Test101C3fooEv
 
 // Checking with opt
-// CHECK-OPT-LABEL: define internal void @_ZThn8_N6Test4B12_GLOBAL__N_11C1fEv(%"struct.Test4B::(anonymous namespace)::C"* %this) unnamed_addr #0 align 2
+// CHECK-OPT-LABEL: define internal void @_ZThn8_N6Test4B12_GLOBAL__N_11C1fEv(%"struct.Test4B::(anonymous namespace)::C"* %this) unnamed_addr

[PATCH] D87396: Sema: add support for `__attribute__((__swift_typedef_bridged__))`

2020-09-14 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd marked an inline comment as done.
compnerd added inline comments.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:7543
+  case ParsedAttr::AT_SwiftBridgedTypedef:
+handleSimpleAttribute(S, D, AL);
+break;

aaron.ballman wrote:
> compnerd wrote:
> > aaron.ballman wrote:
> > > Should there be any type checking that the underlying type of the typedef 
> > > is a sensible one to bridge?
> > I can't really think of anything that you could check that would be 
> > valuable.  What types of things were you thinking?
> I was mostly thinking about builtin types like `int`, but I don't insist.
Typedefing `int` to something else and importing that with a different name is 
reasonable I believe.  I'll add a test case.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87396/new/

https://reviews.llvm.org/D87396

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


[PATCH] D87395: Sema: add support for `__attribute__((__swift_objc_members__))`

2020-09-14 Thread Saleem Abdulrasool via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG916b43403588: Sema: add support for 
`__attribute__((__swift_objc_members__))` (authored by compnerd).

Changed prior to commit:
  https://reviews.llvm.org/D87395?vs=291269&id=291583#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87395/new/

https://reviews.llvm.org/D87395

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaObjC/attr-swift_objc_members.m


Index: clang/test/SemaObjC/attr-swift_objc_members.m
===
--- /dev/null
+++ clang/test/SemaObjC/attr-swift_objc_members.m
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+#if !__has_attribute(swift_objc_members)
+#error cannot verify presence of swift_objc_members attribute
+#endif
+
+__attribute__((__swift_objc_members__))
+__attribute__((__objc_root_class__))
+@interface I
+@end
+
+__attribute__((swift_objc_members))
+@protocol P
+@end
+// expected-error@-3 {{'swift_objc_members' attribute only applies to 
Objective-C interfaces}}
+
+__attribute__((swift_objc_members))
+extern void f(void);
+// expected-error@-2 {{'swift_objc_members' attribute only applies to 
Objective-C interfaces}}
+
+// expected-error@+1 {{'__swift_objc_members__' attribute takes no arguments}}
+__attribute__((__swift_objc_members__("J")))
+@interface J
+@end
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -150,6 +150,7 @@
 // CHECK-NEXT: SwiftError (SubjectMatchRule_function, 
SubjectMatchRule_objc_method)
 // CHECK-NEXT: SwiftErrorResult (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: SwiftIndirectResult (SubjectMatchRule_variable_is_parameter)
+// CHECK-NEXT: SwiftObjCMembers (SubjectMatchRule_objc_interface)
 // CHECK-NEXT: TLSModel (SubjectMatchRule_variable_is_thread_local)
 // CHECK-NEXT: Target (SubjectMatchRule_function)
 // CHECK-NEXT: TestTypestate (SubjectMatchRule_function_is_member)
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -7536,6 +7536,9 @@
   case ParsedAttr::AT_SwiftError:
 handleSwiftError(S, D, AL);
 break;
+  case ParsedAttr::AT_SwiftObjCMembers:
+handleSimpleAttribute(S, D, AL);
+break;
 
   // XRay attributes.
   case ParsedAttr::AT_XRayLogArgs:
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -3476,6 +3476,16 @@
   }];
 }
 
+def SwiftObjCMembersDocs : Documentation {
+  let Category = SwiftDocs;
+  let Heading = "swift_objc_members";
+  let Content = [{
+This attribute indicates that Swift subclasses and members of Swift extensions
+of this class will be implicitly marked with the ``@objcMembers`` Swift
+attribute, exposing them back to Objective-C.
+  }];
+}
+
 def SwiftErrorDocs : Documentation {
   let Category = SwiftDocs;
   let Heading = "swift_error";
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -2130,6 +2130,12 @@
   let ASTNode = 0;
 }
 
+def SwiftObjCMembers : Attr {
+  let Spellings = [GNU<"swift_objc_members">];
+  let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
+  let Documentation = [SwiftObjCMembersDocs];
+}
+
 def SwiftError : InheritableAttr {
   let Spellings = [GNU<"swift_error">];
   let Args = [


Index: clang/test/SemaObjC/attr-swift_objc_members.m
===
--- /dev/null
+++ clang/test/SemaObjC/attr-swift_objc_members.m
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+#if !__has_attribute(swift_objc_members)
+#error cannot verify presence of swift_objc_members attribute
+#endif
+
+__attribute__((__swift_objc_members__))
+__attribute__((__objc_root_class__))
+@interface I
+@end
+
+__attribute__((swift_objc_members))
+@protocol P
+@end
+// expected-error@-3 {{'swift_objc_members' attribute only applies to Objective-C interfaces}}
+
+__attribute__((swift_objc_members))
+extern void f(void);
+// expected-error@-2 {{'swift_objc_members' attribute only applies to Objective-C interfaces}}
+
+// expected-error@+1 {{'__swift_objc_members__' attribute takes no arguments}}
+__attribute__((__swift_objc_members__("J")))
+@interface J
+@end
Index: clang/test/Misc/pragma-at

[clang] 916b434 - Sema: add support for `__attribute__((__swift_objc_members__))`

2020-09-14 Thread Saleem Abdulrasool via cfe-commits

Author: Saleem Abdulrasool
Date: 2020-09-14T15:24:41Z
New Revision: 916b43403588a85425bbc82712427cf53ed877cc

URL: 
https://github.com/llvm/llvm-project/commit/916b43403588a85425bbc82712427cf53ed877cc
DIFF: 
https://github.com/llvm/llvm-project/commit/916b43403588a85425bbc82712427cf53ed877cc.diff

LOG: Sema: add support for `__attribute__((__swift_objc_members__))`

This adds the `__swift_objc_members__` attribute to the semantic
analysis.  It allows for annotating ObjC interfaces to provide Swift
semantics indicating that the types derived from this interface will be
back-bridged to Objective-C to allow interoperability with Objective-C
and Swift.

This is based on the work of the original changes in
https://github.com/llvm/llvm-project-staging/commit/8afaf3aad2af43cfedca7a24cd817848c4e95c0c

Differential Revision: https://reviews.llvm.org/D87395
Reviewed By: Aaron Ballman, Dmitri Gribenko

Added: 
clang/test/SemaObjC/attr-swift_objc_members.m

Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Misc/pragma-attribute-supported-attributes-list.test

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 1790ae01497fb..3221cf23c4b53 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2130,6 +2130,12 @@ def Regparm : TypeAttr {
   let ASTNode = 0;
 }
 
+def SwiftObjCMembers : Attr {
+  let Spellings = [GNU<"swift_objc_members">];
+  let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
+  let Documentation = [SwiftObjCMembersDocs];
+}
+
 def SwiftError : InheritableAttr {
   let Spellings = [GNU<"swift_error">];
   let Args = [

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 2fffc0daabee3..939f52dae3d5a 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -3476,6 +3476,16 @@ Swift.
   }];
 }
 
+def SwiftObjCMembersDocs : Documentation {
+  let Category = SwiftDocs;
+  let Heading = "swift_objc_members";
+  let Content = [{
+This attribute indicates that Swift subclasses and members of Swift extensions
+of this class will be implicitly marked with the ``@objcMembers`` Swift
+attribute, exposing them back to Objective-C.
+  }];
+}
+
 def SwiftErrorDocs : Documentation {
   let Category = SwiftDocs;
   let Heading = "swift_error";

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index e317211d8bee8..bf9d8497f5a26 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -7536,6 +7536,9 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, 
Decl *D,
   case ParsedAttr::AT_SwiftError:
 handleSwiftError(S, D, AL);
 break;
+  case ParsedAttr::AT_SwiftObjCMembers:
+handleSimpleAttribute(S, D, AL);
+break;
 
   // XRay attributes.
   case ParsedAttr::AT_XRayLogArgs:

diff  --git a/clang/test/Misc/pragma-attribute-supported-attributes-list.test 
b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
index 12800b9d54eaa..dcf7cd2b7f1a4 100644
--- a/clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -150,6 +150,7 @@
 // CHECK-NEXT: SwiftError (SubjectMatchRule_function, 
SubjectMatchRule_objc_method)
 // CHECK-NEXT: SwiftErrorResult (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: SwiftIndirectResult (SubjectMatchRule_variable_is_parameter)
+// CHECK-NEXT: SwiftObjCMembers (SubjectMatchRule_objc_interface)
 // CHECK-NEXT: TLSModel (SubjectMatchRule_variable_is_thread_local)
 // CHECK-NEXT: Target (SubjectMatchRule_function)
 // CHECK-NEXT: TestTypestate (SubjectMatchRule_function_is_member)

diff  --git a/clang/test/SemaObjC/attr-swift_objc_members.m 
b/clang/test/SemaObjC/attr-swift_objc_members.m
new file mode 100644
index 0..81328b6245947
--- /dev/null
+++ b/clang/test/SemaObjC/attr-swift_objc_members.m
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+#if !__has_attribute(swift_objc_members)
+#error cannot verify presence of swift_objc_members attribute
+#endif
+
+__attribute__((__swift_objc_members__))
+__attribute__((__objc_root_class__))
+@interface I
+@end
+
+__attribute__((swift_objc_members))
+@protocol P
+@end
+// expected-error@-3 {{'swift_objc_members' attribute only applies to 
Objective-C interfaces}}
+
+__attribute__((swift_objc_members))
+extern void f(void);
+// expected-error@-2 {{'swift_objc_members' attribute only applies to 
Objective-C interfaces}}
+
+// expected-error@+1 {{'__swift_objc_members__' attribute takes no arguments}}
+__attribute__((__swift_objc_members__("J")))
+@interface J
+@end



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

[PATCH] D87615: [clang][Driver] Force stack realignment on 32-bit Solaris/x86

2020-09-14 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

In D87615#2271268 , @RKSimon wrote:

> Would it be possible to add some tests?

Probably not reliably: the tests that usually fail bye the hundreds happen to 
`PASS` once in a while when the stack pointer is 16-byte aligned
by accident.  Otherwise, the failure is prominent enough, I'd think.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87615/new/

https://reviews.llvm.org/D87615

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


[PATCH] D87587: [clang-format][PR47290] Make one-line namespaces resistant to FixNamespaceComments, update documentation

2020-09-14 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay requested changes to this revision.
MyDeveloperDay added a comment.

I have a hard time when people change tests! just because one person wants them 
this way doesn't mean everyone will.

I am not sure about others but I'd be ok about seeing this as an option to 
override the value but not changing the default.

I like to think of unit tests as the "Beyonce Rule", "if you liked it you put a 
test on it!"... when people come along and say... "All these tests are 
wrong"... I start thinking... is this subjective or objective?

This would be a substantially smaller diff if you were adding the option.  
(option/doc/test...)

Full context diff please too!




Comment at: clang/lib/Format/NamespaceEndCommentsFixer.cpp:28
+static const int kShortNamespaceMaxLines = 0;
 
 // Computes the name of a namespace given the namespace token.

I think change this will break the world... why don't we expose this as an 
option and not change everything!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87587/new/

https://reviews.llvm.org/D87587

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


[PATCH] D87396: Sema: add support for `__attribute__((__swift_typedef_bridged__))`

2020-09-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:7543
+  case ParsedAttr::AT_SwiftBridgedTypedef:
+handleSimpleAttribute(S, D, AL);
+break;

compnerd wrote:
> aaron.ballman wrote:
> > compnerd wrote:
> > > aaron.ballman wrote:
> > > > Should there be any type checking that the underlying type of the 
> > > > typedef is a sensible one to bridge?
> > > I can't really think of anything that you could check that would be 
> > > valuable.  What types of things were you thinking?
> > I was mostly thinking about builtin types like `int`, but I don't insist.
> Typedefing `int` to something else and importing that with a different name 
> is reasonable I believe.  I'll add a test case.
Okay, perfect, thank you for verifying!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87396/new/

https://reviews.llvm.org/D87396

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


[PATCH] D87455: [clang-tidy] performance-unnecessary-copy-initialization: Restrict UnnecessaryCopyInitialization check to variables initialized from free functions without arguments

2020-09-14 Thread Felix Berger via Phabricator via cfe-commits
flx updated this revision to Diff 291584.
flx edited the summary of this revision.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87455/new/

https://reviews.llvm.org/D87455

Files:
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -23,6 +23,9 @@
 ExpensiveToCopyType global_expensive_to_copy_type;
 
 const ExpensiveToCopyType &ExpensiveTypeReference();
+const ExpensiveToCopyType &freeFunctionWithArg(const ExpensiveToCopyType &);
+const ExpensiveToCopyType &freeFunctionWithDefaultArg(
+const ExpensiveToCopyType *arg = nullptr);
 const TrivialToCopyType &TrivialTypeReference();
 
 void mutate(ExpensiveToCopyType &);
@@ -387,3 +390,18 @@
   for (const Element &E : Container()) {
   }
 }
+
+// This should not trigger the check as the argument could introduce an alias.
+void negativeInitializedFromFreeFunctionWithArg() {
+  ExpensiveToCopyType Orig;
+  const ExpensiveToCopyType Copy = freeFunctionWithArg(Orig);
+}
+
+void negativeInitializedFromFreeFunctionWithDefaultArg() {
+  const ExpensiveToCopyType Copy = freeFunctionWithDefaultArg();
+}
+
+void negativeInitialzedFromFreeFunctionWithNonDefaultArg() {
+  ExpensiveToCopyType Orig;
+  const ExpensiveToCopyType Copy = freeFunctionWithDefaultArg(&Orig);
+}
Index: clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
===
--- clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
+++ clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
@@ -29,6 +29,14 @@
   }
 }
 
+template 
+bool hasNonDefaultArgs(const Call &CallExpr, unsigned int StartIndex = 0) {
+  for (unsigned int I = StartIndex; I < CallExpr.getNumArgs(); ++I)
+if (!CallExpr.getArg(I)->isDefaultArgument())
+  return true;
+  return false;
+}
+
 } // namespace
 
 using namespace ::clang::ast_matchers;
@@ -54,7 +62,8 @@
 on(declRefExpr(to(varDecl().bind("objectArg");
   auto ConstRefReturningFunctionCall =
   callExpr(callee(functionDecl(returns(ConstReference))),
-   unless(callee(cxxMethodDecl(;
+   unless(callee(cxxMethodDecl(
+  .bind("initFunctionCall");
 
   auto localVarCopiedFrom = [this](const internal::Matcher &CopyCtorArg) {
 return compoundStmt(
@@ -96,6 +105,8 @@
   const auto *ObjectArg = Result.Nodes.getNodeAs("objectArg");
   const auto *BlockStmt = Result.Nodes.getNodeAs("blockStmt");
   const auto *CtorCall = Result.Nodes.getNodeAs("ctorCall");
+  const auto *InitFunctionCall =
+  Result.Nodes.getNodeAs("initFunctionCall");
 
   TraversalKindScope RAII(*Result.Context, ast_type_traits::TK_AsIs);
 
@@ -108,11 +119,15 @@
   // A constructor that looks like T(const T& t, bool arg = false) counts as a
   // copy only when it is called with default arguments for the arguments after
   // the first.
-  for (unsigned int i = 1; i < CtorCall->getNumArgs(); ++i)
-if (!CtorCall->getArg(i)->isDefaultArgument())
-  return;
+  if (hasNonDefaultArgs(*CtorCall, 1))
+return;
 
   if (OldVar == nullptr) {
+// Only allow initialization of a const reference from a free function if it
+// has no arguments. Otherwise it could return an alias to one of its
+// arguments and the arguments need to be checked for const use as well.
+if (InitFunctionCall != nullptr && InitFunctionCall->getNumArgs() > 0)
+  return;
 handleCopyFromMethodReturn(*NewVar, *BlockStmt, IssueFix, ObjectArg,
*Result.Context);
   } else {
@@ -127,10 +142,10 @@
   bool IsConstQualified = Var.getType().isConstQualified();
   if (!IsConstQualified && !isOnlyUsedAsConst(Var, BlockStmt, Context))
 return;
+
   if (ObjectArg != nullptr &&
   !isOnlyUsedAsConst(*ObjectArg, BlockStmt, Context))
 return;
-
   auto Diagnostic =
   diag(Var.getLocation(),
IsConstQualified ? "the const qualified variable %0 is "
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87455: [clang-tidy] performance-unnecessary-copy-initialization: Restrict UnnecessaryCopyInitialization check to variables initialized from free functions without arguments

2020-09-14 Thread Felix Berger via Phabricator via cfe-commits
flx added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp:126
   if (OldVar == nullptr) {
+// Only allow initialization of a const reference from a free function if 
it
+// has no arguments or only default arguments. Otherwise it could return

flx wrote:
> aaron.ballman wrote:
> > I'm not certain I agree with this change, but I'm also not certain I 
> > disagree with it. There are more ways to alias than just default arguments 
> > (global variables, etc) and the presence of a default argument is not 
> > really an indication about its return value in this case. e.g.,
> > ```
> > const ExpensiveToCopyType &freeFunctionWithDefaultArg(int i = 12);
> > ```
> > (I don't see a reason why `= 12` should impact whether use of this function 
> > diagnoses or not.)
> > 
> > Perhaps if this was tightened up a bit to care about the type of the 
> > default argument it might make sense, but even that gets tricky when you 
> > consider base classes, template types, etc. and doesn't cover all of the 
> > aliasing cases anyway. Is there an important use case for this behavior?
> This was mostly following the logic already applied to the copy constructor 
> where the existing code also allowed default arguments. The idea is to not 
> disallow functions with default arguments that are not overridden. 
> 
> I'll switch to not allowing any arguments. This will just exclude a few more 
> cases, but better to be safe, until we might be able to verify the constness 
> of all function arguments as well.
This is done now.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87455/new/

https://reviews.llvm.org/D87455

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


[PATCH] D86796: [Sema] Address-space sensitive index check for unbounded arrays

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

LGTM!




Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:8841-8844
+def warn_array_index_exceeds_max_addressable_bounds : Warning<
+  "array index %0 refers past the last possible element for an array in %1-bit 
"
+  "address space containing %2-bit (%3-byte) elements (max possible %4 
element%s5)">,
+  InGroup;

chrish_ericsson_atx wrote:
> aaron.ballman wrote:
> > I'd combine this with the above diagnostic given how similar they are:
> > ```
> > def warn_exceeds_max_addressable_bounds : Warning<
> >   "%select{array index %1|the pointer incremented by %1}0 refers past the 
> > last possible element for an array in %2-bit "
> >   "address space containing %3-bit (%4-byte) elements (max possible %5 
> > element%s6)">,
> >   InGroup;
> > ```
> I was attempting to follow the pattern set by the preceding four definitions, 
> which keep pointer math warnings and array index warnings separated, but are 
> otherwise nearly identical.  If there's value in that pattern for those other 
> warnings, I would assume the same value applies to keeping these separated.  
> Please re-ping if you disagree, otherwise, I'll leave these as two separate 
> warnings.
I don't think there's a whole lot of value, but I also don't insist on the 
change.



Comment at: clang/lib/Sema/SemaChecking.cpp:14063
+  if (isUnboundedArray) {
+if (index.isUnsigned() || !index.isNegative()) {
+  const auto &ASTC = getASTContext();

chrish_ericsson_atx wrote:
> aaron.ballman wrote:
> > ebevhan wrote:
> > > This could be early return to avoid the indentation.
> > +1 to using early return here. I might even get rid of `isUnboundedArray` 
> > and just use `!BaseType`
> @ebevhan's comment about early return was actually addressed in a previous 
> diff... I should have marked it as such.  My apologies.
> 
> I'd prefer to keep `isUnboundedArray` (with the case corrected, of course), 
> as it seems much clearer than `!BaseType` in terms of expressing what we are 
> actually checking here, and why.
That's fine by me, and my brain scrambled a bit -- I thought there was an early 
return possible for `!IsUnboundedArray` but I was looking at the wrong line.



Comment at: clang/lib/Sema/SemaChecking.cpp:14100
+  // dependent CharUnits)
+  DiagRuntimeBehavior(BaseExpr->getBeginLoc(), BaseExpr,
+  PDiag(DiagID)

chrish_ericsson_atx wrote:
> aaron.ballman wrote:
> > It's not clear to me whether we need to pay the extra expense of doing 
> > reachability checks for the diagnostic -- do you have evidence that there 
> > would be a high false positive rate if we always emit the diagnostic?
> Sorry-- I'm not following you here, @aaron.ballman. What reachability check 
> are you referring to?  The diagnostic isn't conditioned on anything (at least 
> not here, where your comment appears...), so I'm not sure what change you are 
> suggesting that would "always emit the diagnostic"...  Sorry to be slow on 
> the uptake here... Could you clarify that for me?
`DiagRuntimeBehavior()` does a reachability check on the given expression and 
will not emit the diagnostic if the code is not reachable. This check can be 
somewhat expensive and so it's usually only used when we need to eliminate 
false positives in common code patterns.

Instead of using `DiagRuntimeBehavior()`, you could use `Diag()` instead which 
doesn't do the reachability check. However, looking further at the changes, I 
think you're correct to use `DiagRuntimeBehavior()` -- we use it elsewhere in 
this same function. Sorry for the noise!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86796/new/

https://reviews.llvm.org/D86796

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


[PATCH] D69272: Enable '#pragma STDC FENV_ACCESS' in frontend

2020-09-14 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

In D69272#2268337 , @mibintc wrote:

> I am working on a task to ensure that clang is doing floating point constant 
> folding correctly.

Could you please share your plans on it? I recently also started implementing 
constant folding in `ExprConstant.cpp`. I have not made anything substantial 
yet, so I can easily switch to another task. Do you have any estimation when 
you could prepare the first version of the patch?

> But sometimes, if the floating point semantics are set to 'strict', even tho' 
> folding has occurred successfully in ExprConstant.cpp, when i look at 
> emit-llvm, there is arithmetic emitted for the floating point expression;

I used a bit different approach, may be it could be useful for you too. An 
initializer for global variable must be a constant, so things like `const xxx = 
1.0 + 2.0` are evaluated. No llvm arithmetic occurs in the resulting ll file. 
Using `pragma STDC FENV_ROUND` floating point environment may be set to 
non-default state, which constant evaluator must use.

In D69272#2268387 , @kpn wrote:

> Say, in D80952  I added support for 
> disabling strictfp support when a target doesn't support it. But it only 
> applies to command line arguments.
>
> Is there any chance at all that relevant pragmas can also be disabled with 
> the warning in the same cases?

This is definitely a good idea.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69272/new/

https://reviews.llvm.org/D69272

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


[PATCH] D87396: Sema: add support for `__attribute__((__swift_typedef_bridged__))`

2020-09-14 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd updated this revision to Diff 291587.
compnerd added a comment.

Add additional test case


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87396/new/

https://reviews.llvm.org/D87396

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaObjC/attr-swift_bridged_typedef.m


Index: clang/test/SemaObjC/attr-swift_bridged_typedef.m
===
--- /dev/null
+++ clang/test/SemaObjC/attr-swift_bridged_typedef.m
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+@interface NSString
+@end
+
+typedef NSString *NSStringAlias __attribute__((__swift_bridged_typedef__));
+
+typedef int IntAlias __attribute__((__swift_bridged_typedef__));
+
+struct __attribute__((swift_bridged_typedef)) S {};
+// expected-error@-1 {{'swift_bridged_typedef' attribute only applies to 
typedefs}}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -146,6 +146,7 @@
 // CHECK-NEXT: Section (SubjectMatchRule_function, 
SubjectMatchRule_variable_is_global, SubjectMatchRule_objc_method, 
SubjectMatchRule_objc_property)
 // CHECK-NEXT: SetTypestate (SubjectMatchRule_function_is_member)
 // CHECK-NEXT: SpeculativeLoadHardening (SubjectMatchRule_function, 
SubjectMatchRule_objc_method)
+// CHECK-NEXT: SwiftBridgedTypedef (SubjectMatchRule_type_alias)
 // CHECK-NEXT: SwiftContext (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: SwiftError (SubjectMatchRule_function, 
SubjectMatchRule_objc_method)
 // CHECK-NEXT: SwiftErrorResult (SubjectMatchRule_variable_is_parameter)
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -7533,6 +7533,9 @@
 break;
 
   // Swift attributes.
+  case ParsedAttr::AT_SwiftBridgedTypedef:
+handleSimpleAttribute(S, D, AL);
+break;
   case ParsedAttr::AT_SwiftError:
 handleSwiftError(S, D, AL);
 break;
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -3476,6 +3476,27 @@
   }];
 }
 
+def SwiftBridgedTypedefDocs : Documentation {
+  let Category = SwiftDocs;
+  let Heading = "swift_bridged";
+  let Content = [{
+The ``swift_bridged_typedef`` attribute indicates that when the typedef to 
which
+the attribute appertains is imported into Swift, it should refer to the bridged
+Swift type (e.g. Swift's ``String``) rather than the Objective-C type as 
written
+(e.g. ``NSString``).
+
+  .. code-block:: c
+
+@interface NSString;
+typedef NSString *AliasedString __attribute__((__swift_bridged_typedef__));
+
+extern void acceptsAliasedString(AliasedString _Nonnull parameter);
+
+In this case, the function ``acceptsAliasedString`` will be imported into Swift
+as a function which accepts a ``String`` type parameter.
+  }];
+}
+
 def SwiftObjCMembersDocs : Documentation {
   let Category = SwiftDocs;
   let Heading = "swift_objc_members";
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -2130,6 +2130,12 @@
   let ASTNode = 0;
 }
 
+def SwiftBridgedTypedef : Attr {
+  let Spellings = [GNU<"swift_bridged_typedef">];
+  let Subjects = SubjectList<[TypedefName], ErrorDiag>;
+  let Documentation = [SwiftBridgedTypedefDocs];
+}
+
 def SwiftObjCMembers : Attr {
   let Spellings = [GNU<"swift_objc_members">];
   let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;


Index: clang/test/SemaObjC/attr-swift_bridged_typedef.m
===
--- /dev/null
+++ clang/test/SemaObjC/attr-swift_bridged_typedef.m
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+@interface NSString
+@end
+
+typedef NSString *NSStringAlias __attribute__((__swift_bridged_typedef__));
+
+typedef int IntAlias __attribute__((__swift_bridged_typedef__));
+
+struct __attribute__((swift_bridged_typedef)) S {};
+// expected-error@-1 {{'swift_bridged_typedef' attribute only applies to typedefs}}
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -146,6 +146,7 @@
 // CHECK-NEXT: Section (SubjectMatchRule_function, SubjectMatchRule_variable_is_global, Subj

[PATCH] D87455: [clang-tidy] performance-unnecessary-copy-initialization: Restrict UnnecessaryCopyInitialization check to variables initialized from free functions without arguments

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

LGTM with some minor nits.




Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp:122
   // the first.
-  for (unsigned int i = 1; i < CtorCall->getNumArgs(); ++i)
-if (!CtorCall->getArg(i)->isDefaultArgument())
-  return;
+  if (hasNonDefaultArgs(*CtorCall, 1))
+return;

There's no real need for this change now, so I'd roll back to the previous form 
(then I don't have to wonder what the `1` means at the call site).



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp:145
 return;
+
   if (ObjectArg != nullptr &&

Some spurious whitespace changes that can also be rolled back.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87455/new/

https://reviews.llvm.org/D87455

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


[PATCH] D85408: Let -basic-block-sections=labels emit basicblock metadata in a new .bb_addr_map section, instead of emitting special unary-encoded symbols.

2020-09-14 Thread Rahman Lavaee via Phabricator via cfe-commits
rahmanl updated this revision to Diff 291589.
rahmanl added a comment.

- Remove the "labels" part of the clang test as the functionality is tested on 
LLVM tests.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85408/new/

https://reviews.llvm.org/D85408

Files:
  clang/docs/UsersManual.rst
  clang/test/CodeGen/basic-block-sections.c
  llvm/include/llvm/CodeGen/AsmPrinter.h
  llvm/include/llvm/CodeGen/MachineFunction.h
  llvm/include/llvm/MC/MCObjectFileInfo.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/CodeGen/BasicBlockSections.cpp
  llvm/lib/CodeGen/MIRParser/MIRParser.cpp
  llvm/lib/CodeGen/MachineBasicBlock.cpp
  llvm/lib/CodeGen/MachineFunction.cpp
  llvm/lib/MC/MCObjectFileInfo.cpp
  llvm/test/CodeGen/X86/basic-block-sections-labels-functions-sections.ll
  llvm/test/CodeGen/X86/basic-block-sections-labels.ll

Index: llvm/test/CodeGen/X86/basic-block-sections-labels.ll
===
--- llvm/test/CodeGen/X86/basic-block-sections-labels.ll
+++ llvm/test/CodeGen/X86/basic-block-sections-labels.ll
@@ -1,23 +1,24 @@
 ; Check the basic block sections labels option
-; RUN: llc < %s -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=labels | FileCheck %s -check-prefix=LINUX-LABELS
+; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-sections=labels | FileCheck %s
 
-define void @_Z3bazb(i1 zeroext) {
-  %2 = alloca i8, align 1
-  %3 = zext i1 %0 to i8
-  store i8 %3, i8* %2, align 1
-  %4 = load i8, i8* %2, align 1
-  %5 = trunc i8 %4 to i1
-  br i1 %5, label %6, label %8
+define void @_Z3bazb(i1 zeroext) personality i32 (...)* @__gxx_personality_v0 {
+  br i1 %0, label %2, label %7
 
-6:; preds = %1
-  %7 = call i32 @_Z3barv()
-  br label %10
+2:
+  %3 = invoke i32 @_Z3barv()
+  to label %7 unwind label %5
+  br label %9
 
-8:; preds = %1
-  %9 = call i32 @_Z3foov()
-  br label %10
+5:
+  landingpad { i8*, i32 }
+  catch i8* null
+  br label %9
 
-10:   ; preds = %8, %6
+7:
+  %8 = call i32 @_Z3foov()
+  br label %9
+
+9:
   ret void
 }
 
@@ -25,9 +26,31 @@
 
 declare i32 @_Z3foov() #1
 
-; LINUX-LABELS: .section
-; LINUX-LABELS: _Z3bazb:
-; LINUX-LABELS-NOT: .section
-; LINUX-LABELS: r.BB._Z3bazb:
-; LINUX-LABELS-NOT: .section
-; LINUX-LABELS: rr.BB._Z3bazb:
+declare i32 @__gxx_personality_v0(...)
+
+; CHECK-LABEL:	_Z3bazb:
+; CHECK-LABEL:	.Lfunc_begin0:
+; CHECK-LABEL:	.LBB_END0_0:
+; CHECK-LABEL:	.LBB0_1:
+; CHECK-LABEL:	.LBB_END0_1:
+; CHECK-LABEL:	.LBB0_2:
+; CHECK-LABEL:	.LBB_END0_2:
+; CHECK-LABEL:	.LBB0_3:
+; CHECK-LABEL:	.LBB_END0_3:
+; CHECK-LABEL:	.Lfunc_end0:
+
+; CHECK:	.section	.bb_addr_map,"o",@progbits,.text
+; CHECK-NEXT:	.quad	.Lfunc_begin0
+; CHECK-NEXT:	.byte	4
+; CHECK-NEXT:	.uleb128 .Lfunc_begin0-.Lfunc_begin0
+; CHECK-NEXT:	.uleb128 .LBB_END0_0-.Lfunc_begin0
+; CHECK-NEXT:	.byte	0
+; CHECK-NEXT:	.uleb128 .LBB0_1-.Lfunc_begin0
+; CHECK-NEXT:	.uleb128 .LBB_END0_1-.LBB0_1
+; CHECK-NEXT:	.byte	0
+; CHECK-NEXT:	.uleb128 .LBB0_2-.Lfunc_begin0
+; CHECK-NEXT:	.uleb128 .LBB_END0_2-.LBB0_2
+; CHECK-NEXT:	.byte	1
+; CHECK-NEXT:	.uleb128 .LBB0_3-.Lfunc_begin0
+; CHECK-NEXT:	.uleb128 .LBB_END0_3-.LBB0_3
+; CHECK-NEXT:	.byte	5
Index: llvm/test/CodeGen/X86/basic-block-sections-labels-functions-sections.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/basic-block-sections-labels-functions-sections.ll
@@ -0,0 +1,35 @@
+; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-sections=labels | FileCheck %s
+
+$_Z4fooTIiET_v = comdat any
+
+define dso_local i32 @_Z3barv() {
+  ret i32 0
+}
+;; Check we add SHF_LINK_ORDER for .bb_addr_map and link it with the corresponding .text sections.
+; CHECK:		.section .text._Z3barv,"ax",@progbits
+; CHECK-LABEL:	_Z3barv:
+; CHECK-NEXT:	[[BAR_BEGIN:.Lfunc_begin[0-9]+]]:
+; CHECK:		.section .bb_addr_map,"o",@progbits,.text._Z3barv{{$}}
+; CHECK-NEXT:		.quad [[BAR_BEGIN]]
+
+
+define dso_local i32 @_Z3foov() {
+  %1 = call i32 @_Z4fooTIiET_v()
+  ret i32 %1
+}
+; CHECK:		.section .text._Z3foov,"ax",@progbits
+; CHECK-LABEL:	_Z3foov:
+; CHECK-NEXT:	[[FOO_BEGIN:.Lfunc_begin[0-9]+]]:
+; CHECK:		.section  .bb_addr_map,"o",@progbits,.text._Z3foov{{$}}
+; CHECK-NEXT:		.quad [[FOO_BEGIN]]
+
+
+define linkonce_odr dso_local i32 @_Z4fooTIiET_v() comdat {
+  ret i32 0
+}
+;; Check we add .bb_addr_map section to a COMDAT group with the corresponding .text section if such a COMDAT exists.
+; CHECK:		.section .text._Z4fooTIiET_v,"axG",@progbits,_Z4fooTIiET_v,comdat
+; CHECK-LABEL:	_Z4fooTIiET_v:
+; CHECK-NEXT:	[[FOOCOMDAT_BEGIN:.Lfunc_begin[0-9]+]]:
+; CHECK:		.section .bb_addr_map,"Go",@progbits,_Z4fooTIiET_v,comdat,.text._Z4fooTIiET_v{{$}}
+; CHECK-NEXT:		.quad [[FOOCOMDAT_BEGIN]]
Index: llvm/lib/MC/MCObjectFileInfo.c

[PATCH] D87611: [SystemZ][z/OS] Set aligned allocation unavailable by default for z/OS

2020-09-14 Thread Fanbo Meng via Phabricator via cfe-commits
fanbo-meng updated this revision to Diff 291590.
fanbo-meng added a comment.

emit the correct diagnostics for z/OS.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87611/new/

https://reviews.llvm.org/D87611

Files:
  clang/include/clang/Basic/AlignedAllocation.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/unavailable_aligned_allocation.cpp

Index: clang/test/SemaCXX/unavailable_aligned_allocation.cpp
===
--- clang/test/SemaCXX/unavailable_aligned_allocation.cpp
+++ clang/test/SemaCXX/unavailable_aligned_allocation.cpp
@@ -1,12 +1,15 @@
-// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DMACOS %s
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s
-// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -faligned-allocation -faligned-alloc-unavailable -std=c++14 -verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -faligned-allocation -faligned-alloc-unavailable -std=c++14 -verify -DMACOS %s
 // RUN: %clang_cc1 -triple arm64-apple-ios10.0.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DIOS %s
 // RUN: %clang_cc1 -triple arm64-apple-ios10.0.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s
 // RUN: %clang_cc1 -triple arm64-apple-tvos10.0.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DTVOS %s
 // RUN: %clang_cc1 -triple arm64-apple-tvos10.0.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s
 // RUN: %clang_cc1 -triple armv7k-apple-watchos3.0.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DWATCHOS %s
 // RUN: %clang_cc1 -triple armv7k-apple-watchos3.0.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s
+// RUN: %clang_cc1 -triple s390x-ibm-zos -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DZOS %s
+// RUN: %clang_cc1 -triple s390x-ibm-zos -fexceptions -std=c++1z -verify -DNO_ERRORS %s
+// RUN: %clang_cc1 -triple s390x-ibm-zos -fexceptions -faligned-allocation -faligned-alloc-unavailable -std=c++14 -verify -DZOS %s
 
 namespace std {
   typedef decltype(sizeof(0)) size_t;
@@ -62,40 +65,40 @@
 #ifdef NO_ERRORS
 // expected-no-diagnostics
 #else
-// expected-error@-16 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on}}
+// expected-error-re@-16 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is {{only|not}} available on}}
 // expected-note@-17 {{if you supply your own aligned allocation functions}}
-// expected-error@-18 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
+// expected-error-re@-18 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is {{only|not}} available on}}
 // expected-note@-19 {{if you supply your own aligned allocation functions}}
 
-// expected-error@-20 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on}}
+// expected-error-re@-20 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is {{only|not}} available on}}
 // expected-note@-21 {{if you supply your own aligned allocation functions}}
-// expected-error@-22 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
+// expected-error-re@-22 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is {{only|not}} available on}}
 // expected-note@-23 {{if you supply your own aligned allocation functions}}
 
-// expected-error@-24 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
+// expected-error-re@-24 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is {{only|not}} available on}}
 // expected-note@-25 {{if you supply your own aligned allocation functions}}
 
-// expected-error@-26 {{aligned allocation function of type 'void *(std::size_t, std::align_val_t, const std::nothrow_t &) noexcept' is only available on}}
+// expected-error-re@-26 {{aligned allocation function of type 'void *(std::size_t, std::align_val_t, const std::nothrow_t &) noexcept' is {{only|not}} available on}}
 // expected-note@-27 {{if you supply your own aligned allocation functions}}
-// expected-error@-28 {{aligned deallocation function of type 'void (void *, std::align_val_t, const std::nothrow_t &) noexcept' is only available on}}
+// expected-error-re@-28 {{aligned deallocation function of type 'void (void *, std::align_val_t, const std::nothrow_t &) noexcept' is {{only|not}} available on}}
 // expected-note@-29 {{if 

[PATCH] D87588: [ASTMatchers] extract public matchers from const-analysis into own patch

2020-09-14 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 291592.
JonasToth added a comment.

- fix compilation error from removed brace


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87588/new/

https://reviews.llvm.org/D87588

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -741,6 +741,164 @@
 std::make_unique>("v", 4)));
 }
 
+TEST(ForEachArgumentWithParamType, ReportsNoFalsePositives) {
+  StatementMatcher ArgumentY =
+  declRefExpr(to(varDecl(hasName("y".bind("arg");
+  TypeMatcher IntType = qualType(isInteger()).bind("type");
+  StatementMatcher CallExpr =
+  callExpr(forEachArgumentWithParamType(ArgumentY, IntType));
+
+  // IntParam does not match.
+  EXPECT_TRUE(notMatches("void f(int* i) { int* y; f(y); }", CallExpr));
+  // ArgumentY does not match.
+  EXPECT_TRUE(notMatches("void f(int i) { int x; f(x); }", CallExpr));
+}
+
+TEST(ForEachArgumentWithParamType, MatchesCXXMemberCallExpr) {
+  StatementMatcher ArgumentY =
+  declRefExpr(to(varDecl(hasName("y".bind("arg");
+  TypeMatcher IntType = qualType(isInteger()).bind("type");
+  StatementMatcher CallExpr =
+  callExpr(forEachArgumentWithParamType(ArgumentY, IntType));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  "struct S {"
+  "  const S& operator[](int i) { return *this; }"
+  "};"
+  "void f(S S1) {"
+  "  int y = 1;"
+  "  S1[y];"
+  "}",
+  CallExpr, std::make_unique>("type", 1)));
+
+  StatementMatcher CallExpr2 =
+  callExpr(forEachArgumentWithParamType(ArgumentY, IntType));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  "struct S {"
+  "  static void g(int i);"
+  "};"
+  "void f() {"
+  "  int y = 1;"
+  "  S::g(y);"
+  "}",
+  CallExpr2, std::make_unique>("type", 1)));
+}
+
+TEST(ForEachArgumentWithParamType, MatchesCallExpr) {
+  StatementMatcher ArgumentY =
+  declRefExpr(to(varDecl(hasName("y".bind("arg");
+  TypeMatcher IntType = qualType(isInteger()).bind("type");
+  StatementMatcher CallExpr =
+  callExpr(forEachArgumentWithParamType(ArgumentY, IntType));
+
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  "void f(int i) { int y; f(y); }", CallExpr,
+  std::make_unique>("type")));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  "void f(int i) { int y; f(y); }", CallExpr,
+  std::make_unique>("arg")));
+
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  "void f(int i, int j) { int y; f(y, y); }", CallExpr,
+  std::make_unique>("type", 2)));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  "void f(int i, int j) { int y; f(y, y); }", CallExpr,
+  std::make_unique>("arg", 2)));
+}
+
+TEST(ForEachArgumentWithParamType, MatchesConstructExpr) {
+  StatementMatcher ArgumentY =
+  declRefExpr(to(varDecl(hasName("y".bind("arg");
+  TypeMatcher IntType = qualType(isInteger()).bind("type");
+  StatementMatcher ConstructExpr =
+  cxxConstructExpr(forEachArgumentWithParamType(ArgumentY, IntType));
+
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  "struct C {"
+  "  C(int i) {}"
+  "};"
+  "int y = 0;"
+  "C Obj(y);",
+  ConstructExpr, std::make_unique>("type")));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  "struct C {"
+  "  C(int i) {}"
+  "};"
+  "int y = 0;"
+  "C Obj(y);",
+  ConstructExpr, std::make_unique>("arg")));
+}
+
+TEST(ForEachArgumentWithParamType, HandlesKandRFunctions) {
+  StatementMatcher ArgumentY =
+  declRefExpr(to(varDecl(hasName("y".bind("arg");
+  TypeMatcher IntType = qualType(isInteger()).bind("type");
+  StatementMatcher CallExpr =
+  callExpr(forEachArgumentWithParamType(ArgumentY, IntType));
+
+  EXPECT_TRUE(matchesC("void f();\n"
+   "void call_it(void) { int x, y; f(x, y); }\n"
+   "void f(a, b) int a, b; {}\n"
+   "void call_it2(void) { int x, y; f(x, y); }",
+   CallExpr));
+}
+
+TEST(ForEachArgumentWithParamType, HandlesBoundNodesForNonMatches) {
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  "void g(int i, int j) {"
+  "  int a;"
+  "  int b;"
+  "  int c;"
+  "  g(a, 0);"
+  "  g(a, b);"
+  "  g(0, b);"
+  "}",
+  functionDecl(
+  forEachDescendant(varDecl().bind("v")),
+  forEachDescendant(callExpr(forEachArgumentWithParamType(
+  declRefExpr(to(decl(equalsBoundNode("v", qualType(),
+  std::make_unique>("v", 4)));
+}
+
+TEST(ForEachArgumentWithParamType, MatchesFunctionPtrCalls) {
+  StatementMatcher ArgumentY =
+  declRefExpr(to(varDecl(

[PATCH] D87611: [SystemZ][z/OS] Set aligned allocation unavailable by default for z/OS

2020-09-14 Thread Fanbo Meng via Phabricator via cfe-commits
fanbo-meng updated this revision to Diff 291593.
fanbo-meng added a comment.

Previous diff is incorrect and didn't include the entire change set, making a 
new one.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87611/new/

https://reviews.llvm.org/D87611

Files:
  clang/include/clang/Basic/AlignedAllocation.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Driver/ToolChains/ZOS.cpp
  clang/lib/Driver/ToolChains/ZOS.h
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/Driver/unavailable_aligned_allocation.cpp
  clang/test/Lexer/aligned-allocation.cpp
  clang/test/SemaCXX/unavailable_aligned_allocation.cpp

Index: clang/test/SemaCXX/unavailable_aligned_allocation.cpp
===
--- clang/test/SemaCXX/unavailable_aligned_allocation.cpp
+++ clang/test/SemaCXX/unavailable_aligned_allocation.cpp
@@ -1,12 +1,15 @@
-// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DMACOS %s
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s
-// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -faligned-allocation -faligned-alloc-unavailable -std=c++14 -verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -faligned-allocation -faligned-alloc-unavailable -std=c++14 -verify -DMACOS %s
 // RUN: %clang_cc1 -triple arm64-apple-ios10.0.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DIOS %s
 // RUN: %clang_cc1 -triple arm64-apple-ios10.0.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s
 // RUN: %clang_cc1 -triple arm64-apple-tvos10.0.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DTVOS %s
 // RUN: %clang_cc1 -triple arm64-apple-tvos10.0.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s
 // RUN: %clang_cc1 -triple armv7k-apple-watchos3.0.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DWATCHOS %s
 // RUN: %clang_cc1 -triple armv7k-apple-watchos3.0.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s
+// RUN: %clang_cc1 -triple s390x-ibm-zos -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DZOS %s
+// RUN: %clang_cc1 -triple s390x-ibm-zos -fexceptions -std=c++1z -verify -DNO_ERRORS %s
+// RUN: %clang_cc1 -triple s390x-ibm-zos -fexceptions -faligned-allocation -faligned-alloc-unavailable -std=c++14 -verify -DZOS %s
 
 namespace std {
   typedef decltype(sizeof(0)) size_t;
@@ -62,40 +65,40 @@
 #ifdef NO_ERRORS
 // expected-no-diagnostics
 #else
-// expected-error@-16 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on}}
+// expected-error-re@-16 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is {{only|not}} available on}}
 // expected-note@-17 {{if you supply your own aligned allocation functions}}
-// expected-error@-18 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
+// expected-error-re@-18 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is {{only|not}} available on}}
 // expected-note@-19 {{if you supply your own aligned allocation functions}}
 
-// expected-error@-20 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on}}
+// expected-error-re@-20 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is {{only|not}} available on}}
 // expected-note@-21 {{if you supply your own aligned allocation functions}}
-// expected-error@-22 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
+// expected-error-re@-22 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is {{only|not}} available on}}
 // expected-note@-23 {{if you supply your own aligned allocation functions}}
 
-// expected-error@-24 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
+// expected-error-re@-24 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is {{only|not}} available on}}
 // expected-note@-25 {{if you supply your own aligned allocation functions}}
 
-// expected-error@-26 {{aligned allocation function of type 'void *(std::size_t, std::align_val_t, const std::nothrow_t &) noexcept' is only available on}}
+// expected-error-re@-26 {{aligned allocation function of type 'void *(std::size_t, std::align_val_t, const std::nothrow_t &) noexcept' is {{only|not}} available on}}
 // expected-note@-27 {{if you supply your own aligned allocation functions}}
-// expected-error@-28 {{aligned deallocation function of type 'void (void *, std::align_val_t, const std::nothrow_t &) noex

[PATCH] D87534: Sema: introduce `__attribute__((__swift_name__))`

2020-09-14 Thread Doug Gregor via Phabricator via cfe-commits
doug.gregor added a comment.

Thank you for doing this!




Comment at: clang/include/clang/Basic/Attr.td:2173
+  SubjectList<[Enum, EnumConstant, Field, Function, GlobalVar, Struct, 
TypedefName,
+   ObjCInterface, ObjCClassMethod, ObjCInstanceMethod, 
ObjCProperty, ObjCProtocol],
+  ErrorDiag, "ExpectedSwiftNameSubjects">;

compnerd wrote:
> Note for @rjmccall and @doug.gregor - this version actually enumerates the 
> subjects to which this attribute appertains unlike what was in the original 
> swift version.  Are there other subjects which this should list?
Hmm. If we enumerate the subjects, we're going to have to update Clang whenever 
Swift's Clang importer learns a new trick. For example, this is probably 
missing CXXMethod and FunctionTmpl based on work that's going on in Swift. I 
suspect we're also missing ObjCCompatibilityAlias. I'm inclined to treat this 
more like AsmLabelAttr and not try to enumerate subjects at all.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87534/new/

https://reviews.llvm.org/D87534

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


[PATCH] D85408: Let -basic-block-sections=labels emit basicblock metadata in a new .bb_addr_map section, instead of emitting special unary-encoded symbols.

2020-09-14 Thread Rahman Lavaee via Phabricator via cfe-commits
rahmanl updated this revision to Diff 291595.
rahmanl added a comment.

- Merge branch 'master' into arcpatch-D85408


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85408/new/

https://reviews.llvm.org/D85408

Files:
  clang/docs/UsersManual.rst
  clang/test/CodeGen/basic-block-sections.c
  llvm/include/llvm/CodeGen/AsmPrinter.h
  llvm/include/llvm/CodeGen/MachineFunction.h
  llvm/include/llvm/MC/MCObjectFileInfo.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/CodeGen/BasicBlockSections.cpp
  llvm/lib/CodeGen/MIRParser/MIRParser.cpp
  llvm/lib/CodeGen/MachineBasicBlock.cpp
  llvm/lib/CodeGen/MachineFunction.cpp
  llvm/lib/MC/MCObjectFileInfo.cpp
  llvm/test/CodeGen/X86/basic-block-sections-labels-functions-sections.ll
  llvm/test/CodeGen/X86/basic-block-sections-labels.ll

Index: llvm/test/CodeGen/X86/basic-block-sections-labels.ll
===
--- llvm/test/CodeGen/X86/basic-block-sections-labels.ll
+++ llvm/test/CodeGen/X86/basic-block-sections-labels.ll
@@ -1,23 +1,24 @@
 ; Check the basic block sections labels option
-; RUN: llc < %s -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=labels | FileCheck %s -check-prefix=LINUX-LABELS
+; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-sections=labels | FileCheck %s
 
-define void @_Z3bazb(i1 zeroext) {
-  %2 = alloca i8, align 1
-  %3 = zext i1 %0 to i8
-  store i8 %3, i8* %2, align 1
-  %4 = load i8, i8* %2, align 1
-  %5 = trunc i8 %4 to i1
-  br i1 %5, label %6, label %8
+define void @_Z3bazb(i1 zeroext) personality i32 (...)* @__gxx_personality_v0 {
+  br i1 %0, label %2, label %7
 
-6:; preds = %1
-  %7 = call i32 @_Z3barv()
-  br label %10
+2:
+  %3 = invoke i32 @_Z3barv()
+  to label %7 unwind label %5
+  br label %9
 
-8:; preds = %1
-  %9 = call i32 @_Z3foov()
-  br label %10
+5:
+  landingpad { i8*, i32 }
+  catch i8* null
+  br label %9
 
-10:   ; preds = %8, %6
+7:
+  %8 = call i32 @_Z3foov()
+  br label %9
+
+9:
   ret void
 }
 
@@ -25,9 +26,31 @@
 
 declare i32 @_Z3foov() #1
 
-; LINUX-LABELS: .section
-; LINUX-LABELS: _Z3bazb:
-; LINUX-LABELS-NOT: .section
-; LINUX-LABELS: r.BB._Z3bazb:
-; LINUX-LABELS-NOT: .section
-; LINUX-LABELS: rr.BB._Z3bazb:
+declare i32 @__gxx_personality_v0(...)
+
+; CHECK-LABEL:	_Z3bazb:
+; CHECK-LABEL:	.Lfunc_begin0:
+; CHECK-LABEL:	.LBB_END0_0:
+; CHECK-LABEL:	.LBB0_1:
+; CHECK-LABEL:	.LBB_END0_1:
+; CHECK-LABEL:	.LBB0_2:
+; CHECK-LABEL:	.LBB_END0_2:
+; CHECK-LABEL:	.LBB0_3:
+; CHECK-LABEL:	.LBB_END0_3:
+; CHECK-LABEL:	.Lfunc_end0:
+
+; CHECK:	.section	.bb_addr_map,"o",@progbits,.text
+; CHECK-NEXT:	.quad	.Lfunc_begin0
+; CHECK-NEXT:	.byte	4
+; CHECK-NEXT:	.uleb128 .Lfunc_begin0-.Lfunc_begin0
+; CHECK-NEXT:	.uleb128 .LBB_END0_0-.Lfunc_begin0
+; CHECK-NEXT:	.byte	0
+; CHECK-NEXT:	.uleb128 .LBB0_1-.Lfunc_begin0
+; CHECK-NEXT:	.uleb128 .LBB_END0_1-.LBB0_1
+; CHECK-NEXT:	.byte	0
+; CHECK-NEXT:	.uleb128 .LBB0_2-.Lfunc_begin0
+; CHECK-NEXT:	.uleb128 .LBB_END0_2-.LBB0_2
+; CHECK-NEXT:	.byte	1
+; CHECK-NEXT:	.uleb128 .LBB0_3-.Lfunc_begin0
+; CHECK-NEXT:	.uleb128 .LBB_END0_3-.LBB0_3
+; CHECK-NEXT:	.byte	5
Index: llvm/test/CodeGen/X86/basic-block-sections-labels-functions-sections.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/basic-block-sections-labels-functions-sections.ll
@@ -0,0 +1,35 @@
+; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-sections=labels | FileCheck %s
+
+$_Z4fooTIiET_v = comdat any
+
+define dso_local i32 @_Z3barv() {
+  ret i32 0
+}
+;; Check we add SHF_LINK_ORDER for .bb_addr_map and link it with the corresponding .text sections.
+; CHECK:		.section .text._Z3barv,"ax",@progbits
+; CHECK-LABEL:	_Z3barv:
+; CHECK-NEXT:	[[BAR_BEGIN:.Lfunc_begin[0-9]+]]:
+; CHECK:		.section .bb_addr_map,"o",@progbits,.text._Z3barv{{$}}
+; CHECK-NEXT:		.quad [[BAR_BEGIN]]
+
+
+define dso_local i32 @_Z3foov() {
+  %1 = call i32 @_Z4fooTIiET_v()
+  ret i32 %1
+}
+; CHECK:		.section .text._Z3foov,"ax",@progbits
+; CHECK-LABEL:	_Z3foov:
+; CHECK-NEXT:	[[FOO_BEGIN:.Lfunc_begin[0-9]+]]:
+; CHECK:		.section  .bb_addr_map,"o",@progbits,.text._Z3foov{{$}}
+; CHECK-NEXT:		.quad [[FOO_BEGIN]]
+
+
+define linkonce_odr dso_local i32 @_Z4fooTIiET_v() comdat {
+  ret i32 0
+}
+;; Check we add .bb_addr_map section to a COMDAT group with the corresponding .text section if such a COMDAT exists.
+; CHECK:		.section .text._Z4fooTIiET_v,"axG",@progbits,_Z4fooTIiET_v,comdat
+; CHECK-LABEL:	_Z4fooTIiET_v:
+; CHECK-NEXT:	[[FOOCOMDAT_BEGIN:.Lfunc_begin[0-9]+]]:
+; CHECK:		.section .bb_addr_map,"Go",@progbits,_Z4fooTIiET_v,comdat,.text._Z4fooTIiET_v{{$}}
+; CHECK-NEXT:		.quad [[FOOCOMDAT_BEGIN]]
Index: llvm/lib/MC/MCObjectFileInfo.cpp

[PATCH] D87611: [SystemZ][z/OS] Set aligned allocation unavailable by default for z/OS

2020-09-14 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/lib/Driver/ToolChains/ZOS.cpp:25-27
+void ZOS::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
+llvm::opt::ArgStringList &CC1Args,
+Action::OffloadKind DeviceOffloadKind) const {

Please be consistent in using/not using additional namespace qualification. The 
declaration above this one takes advantage of the using directive for 
`llvm::opt`.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:1841
-<< IsDelete << FD.getType().getAsString() << OSName
-<< alignedAllocMinVersion(T.getOS()).getAsString();
 Diag(Loc, diag::note_silence_aligned_allocation_unavailable);

Just to ensure we are on the same page:
Passing `-Xclang -faligned-alloc-unavailable` on the non-Apple platforms does 
very bad things (hits "unreachable" and otherwise falls off the end of a 
function without initializing a return value). Part of this patch makes passing 
`-Xclang -faligned-alloc-unavailable` okay on z/OS.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87611/new/

https://reviews.llvm.org/D87611

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


[PATCH] D87532: Sema: add support for `__attribute__((__swift_bridge__))`

2020-09-14 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd marked 4 inline comments as done.
compnerd added inline comments.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:5535
+  // Don't duplicate annotations that are already set.
+  if (D->hasAttr()) {
+S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL.getAttrName();

aaron.ballman wrote:
> Can a type bridge across multiple types? e.g., could you say this bridges to 
> "foo" and "bar"?
No, I believe that you can not bridge to two different types.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87532/new/

https://reviews.llvm.org/D87532

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


[PATCH] D87532: Sema: add support for `__attribute__((__swift_bridge__))`

2020-09-14 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd updated this revision to Diff 291601.
compnerd marked an inline comment as done.
compnerd added a comment.

Address some feedback from @aaron.ballman


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87532/new/

https://reviews.llvm.org/D87532

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/SemaObjC/attr-swift_bridge.m

Index: clang/test/SemaObjC/attr-swift_bridge.m
===
--- /dev/null
+++ clang/test/SemaObjC/attr-swift_bridge.m
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+// expected-error@+1 {{'__swift_bridge__' attribute takes one argument}}
+__attribute__((__swift_bridge__))
+@interface I
+@end
+
+// expected-error@+1 {{'__swift_bridge__' attribute requires a string}}
+__attribute__((__swift_bridge__(1)))
+@interface J
+@end
+
+// expected-error@+1 {{'__swift_bridge__' attribute takes one argument}}
+__attribute__((__swift_bridge__("K", 1)))
+@interface K
+@end
+
+@interface L
+// expected-error@+1 {{'__swift_bridge__' attribute only applies to tag types, typedefs, Objective-C interfaces, and Objective-C protocols}}
+- (void)method __attribute__((__swift_bridge__("method")));
+@end
+
+__attribute__((__swift_bridge__("Array")))
+@interface NSArray
+@end
+
+__attribute__((__swift_bridge__("ProtocolP")))
+@protocol P
+@end
+
+typedef NSArray *NSArrayAlias __attribute__((__swift_bridge__("ArrayAlias")));
+
+struct __attribute__((__swift_bridge__("StructT"))) T {};
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -5524,6 +5524,22 @@
   D->addAttr(::new (S.Context) ObjCPreciseLifetimeAttr(S.Context, AL));
 }
 
+static void handleSwiftBridge(Sema &S, Decl *D, const ParsedAttr &AL) {
+  // Make sure that there is a string literal as the annotation's single
+  // argument.
+  StringRef BT;
+  if (!S.checkStringLiteralArgumentAttr(AL, 0, BT))
+return;
+
+  // Don't duplicate annotations that are already set.
+  if (D->hasAttr()) {
+S.Diag(AL.getLoc(), diag::warn_duplicate_attribute) << AL;
+return;
+  }
+
+  D->addAttr(::new (S.Context) SwiftBridgeAttr(S.Context, AL, BT));
+}
+
 static bool isErrorParameter(Sema &S, QualType QT) {
   const auto *PT = QT->getAs();
   if (!PT)
@@ -7533,6 +7549,9 @@
 break;
 
   // Swift attributes.
+  case ParsedAttr::AT_SwiftBridge:
+handleSwiftBridge(S, D, AL);
+break;
   case ParsedAttr::AT_SwiftBridgedTypedef:
 handleSimpleAttribute(S, D, AL);
 break;
Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -3476,6 +3476,15 @@
   }];
 }
 
+def SwiftBridgeDocs : Documentation {
+  let Category = SwiftDocs;
+  let Heading = "swift_bridge";
+  let Content = [{
+The ``swift_bridged`` attribute indicates that the type to which the attribute
+appertains is bridged to the named Swift type.
+  }];
+}
+
 def SwiftBridgedTypedefDocs : Documentation {
   let Category = SwiftDocs;
   let Heading = "swift_bridged";
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -2130,6 +2130,14 @@
   let ASTNode = 0;
 }
 
+def SwiftBridge : Attr {
+  let Spellings = [GNU<"swift_bridge">];
+  let Args = [StringArgument<"SwiftType">];
+  let Subjects = SubjectList<[Tag, TypedefName, ObjCInterface, ObjCProtocol],
+ ErrorDiag>;
+  let Documentation = [SwiftBridgeDocs];
+}
+
 def SwiftBridgedTypedef : Attr {
   let Spellings = [GNU<"swift_bridged_typedef">];
   let Subjects = SubjectList<[TypedefName], ErrorDiag>;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87081: [analyzer][StdLibraryFunctionsChecker] Elaborate the summary of fread and fwrite

2020-09-14 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 291606.
martong added a comment.

- Add tests to verify compatibility of the two checkers


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87081/new/

https://reviews.llvm.org/D87081

Files:
  clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  clang/test/Analysis/Inputs/system-header-simulator.h
  clang/test/Analysis/std-c-library-functions-arg-constraints.c
  clang/test/Analysis/std-c-library-functions-vs-stream-checker.c

Index: clang/test/Analysis/std-c-library-functions-vs-stream-checker.c
===
--- /dev/null
+++ clang/test/Analysis/std-c-library-functions-vs-stream-checker.c
@@ -0,0 +1,58 @@
+// Check the case when only the StreamChecker is enabled.
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core,alpha.unix.Stream \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -triple x86_64-unknown-linux \
+// RUN:   -verify=stream
+
+// Check the case when only the StdLibraryFunctionsChecker is enabled.
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:DisplayLoadedSummaries=true \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -triple x86_64-unknown-linux \
+// RUN:   -verify=stdLib 2>&1 | FileCheck %s
+
+// Check the case when both the StreamChecker and the
+// StdLibraryFunctionsChecker are enabled.
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core,alpha.unix.Stream \
+// RUN:   -analyzer-checker=apiModeling.StdCLibraryFunctions \
+// RUN:   -analyzer-config apiModeling.StdCLibraryFunctions:DisplayLoadedSummaries=true \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -triple x86_64-unknown-linux \
+// RUN:   -verify=both 2>&1 | FileCheck %s
+
+// Verify that the summaries are loaded when the StdLibraryFunctionsChecker is
+// enabled.
+//  CHECK: Loaded summary for: int getchar()
+// CHECK-NEXT: Loaded summary for: unsigned long fread(void *restrict, size_t, size_t, FILE *restrict)
+// CHECK-NEXT: Loaded summary for: unsigned long fwrite(const void *restrict, size_t, size_t, FILE *restrict)
+
+#include "Inputs/system-header-simulator.h"
+
+void clang_analyzer_eval(int);
+
+void test_fread_fwrite(FILE *fp, int *buf) {
+  fp = fopen("foo", "r");
+  if (!fp)
+return;
+  size_t x = fwrite(buf, sizeof(int), 10, fp);
+
+  clang_analyzer_eval(x <= 10); // \
+ // stream-warning{{TRUE}} \
+ // stdLib-warning{{TRUE}} \
+ // both-warning{{TRUE}} \
+
+  clang_analyzer_eval(x == 10); // \
+  // stream-warning{{TRUE}} \
+  // stream-warning{{FALSE}} \
+  // stdLib-warning{{UNKNOWN}} \
+  // both-warning{{TRUE}} \
+  // both-warning{{FALSE}}
+
+  fclose(fp);
+}
Index: clang/test/Analysis/std-c-library-functions-arg-constraints.c
===
--- clang/test/Analysis/std-c-library-functions-arg-constraints.c
+++ clang/test/Analysis/std-c-library-functions-arg-constraints.c
@@ -194,6 +194,22 @@
 // bugpath-warning{{Function argument constraint is not satisfied}} \
 // bugpath-note{{Function argument constraint is not satisfied}}
 }
+typedef __WCHAR_TYPE__ wchar_t;
+// This is one test case for the ARR38-C SEI-CERT rule.
+void ARR38_C_F(FILE *file) {
+  enum { BUFFER_SIZE = 1024 };
+  wchar_t wbuf[BUFFER_SIZE]; // bugpath-note{{'wbuf' initialized here}}
+
+  const size_t size = sizeof(*wbuf);
+  const size_t nitems = sizeof(wbuf);
+
+  // The 3rd parameter should be the number of elements to read, not
+  // the size in bytes.
+  fread(wbuf, size, nitems, file); // \
+  // report-warning{{Function argument constraint is not satisfied}} \
+  // bugpath-warning{{Function argument constraint is not satisfied}} \
+  // bugpath-note{{Function argument constraint is not satisfied}}
+}
 
 int __two_constrained_args(int, int);
 void test_constraints_on_multiple_args(int x, int y) {
Index: clang/test/Analysis/Inputs/system-header-simulator.h
===
--- clang/test/Analysis/Inputs/system-header-simulator.h
+++ clang/test/Analysis/Inputs/system-header-simulator.h
@@ -46,8 +46,8 @@
 FILE *tmpfile(void);
 FILE *freopen(const char *pathname, const char *mode, FILE *stream);
 int fclose(FILE *fp);
-size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
-size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
+size_t fread(void *restrict, size_t, size_t, FILE *restrict);
+size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
 int fputc(int ch, FILE *stream);
 int fseek(FILE *__stream, long int __off, int __whence);
 long int ftell(FILE *__stream);
Index: clang/lib/StaticAnalyzer/C

[PATCH] D85408: Let -basic-block-sections=labels emit basicblock metadata in a new .bb_addr_map section, instead of emitting special unary-encoded symbols.

2020-09-14 Thread Rahman Lavaee via Phabricator via cfe-commits
rahmanl updated this revision to Diff 291607.
rahmanl added a comment.

- Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85408/new/

https://reviews.llvm.org/D85408

Files:
  clang/docs/UsersManual.rst
  clang/test/CodeGen/basic-block-sections.c
  llvm/include/llvm/CodeGen/AsmPrinter.h
  llvm/include/llvm/CodeGen/MachineFunction.h
  llvm/include/llvm/MC/MCObjectFileInfo.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/CodeGen/BasicBlockSections.cpp
  llvm/lib/CodeGen/MIRParser/MIRParser.cpp
  llvm/lib/CodeGen/MachineBasicBlock.cpp
  llvm/lib/CodeGen/MachineFunction.cpp
  llvm/lib/MC/MCObjectFileInfo.cpp
  llvm/test/CodeGen/X86/basic-block-sections-labels-functions-sections.ll
  llvm/test/CodeGen/X86/basic-block-sections-labels.ll

Index: llvm/test/CodeGen/X86/basic-block-sections-labels.ll
===
--- llvm/test/CodeGen/X86/basic-block-sections-labels.ll
+++ llvm/test/CodeGen/X86/basic-block-sections-labels.ll
@@ -1,23 +1,24 @@
 ; Check the basic block sections labels option
-; RUN: llc < %s -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=labels | FileCheck %s -check-prefix=LINUX-LABELS
+; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-sections=labels | FileCheck %s
 
-define void @_Z3bazb(i1 zeroext) {
-  %2 = alloca i8, align 1
-  %3 = zext i1 %0 to i8
-  store i8 %3, i8* %2, align 1
-  %4 = load i8, i8* %2, align 1
-  %5 = trunc i8 %4 to i1
-  br i1 %5, label %6, label %8
+define void @_Z3bazb(i1 zeroext) personality i32 (...)* @__gxx_personality_v0 {
+  br i1 %0, label %2, label %7
 
-6:; preds = %1
-  %7 = call i32 @_Z3barv()
-  br label %10
+2:
+  %3 = invoke i32 @_Z3barv()
+  to label %7 unwind label %5
+  br label %9
 
-8:; preds = %1
-  %9 = call i32 @_Z3foov()
-  br label %10
+5:
+  landingpad { i8*, i32 }
+  catch i8* null
+  br label %9
 
-10:   ; preds = %8, %6
+7:
+  %8 = call i32 @_Z3foov()
+  br label %9
+
+9:
   ret void
 }
 
@@ -25,9 +26,31 @@
 
 declare i32 @_Z3foov() #1
 
-; LINUX-LABELS: .section
-; LINUX-LABELS: _Z3bazb:
-; LINUX-LABELS-NOT: .section
-; LINUX-LABELS: r.BB._Z3bazb:
-; LINUX-LABELS-NOT: .section
-; LINUX-LABELS: rr.BB._Z3bazb:
+declare i32 @__gxx_personality_v0(...)
+
+; CHECK-LABEL:	_Z3bazb:
+; CHECK-LABEL:	.Lfunc_begin0:
+; CHECK-LABEL:	.LBB_END0_0:
+; CHECK-LABEL:	.LBB0_1:
+; CHECK-LABEL:	.LBB_END0_1:
+; CHECK-LABEL:	.LBB0_2:
+; CHECK-LABEL:	.LBB_END0_2:
+; CHECK-LABEL:	.LBB0_3:
+; CHECK-LABEL:	.LBB_END0_3:
+; CHECK-LABEL:	.Lfunc_end0:
+
+; CHECK:	.section	.bb_addr_map,"o",@progbits,.text
+; CHECK-NEXT:	.quad	.Lfunc_begin0
+; CHECK-NEXT:	.byte	4
+; CHECK-NEXT:	.uleb128 .Lfunc_begin0-.Lfunc_begin0
+; CHECK-NEXT:	.uleb128 .LBB_END0_0-.Lfunc_begin0
+; CHECK-NEXT:	.byte	0
+; CHECK-NEXT:	.uleb128 .LBB0_1-.Lfunc_begin0
+; CHECK-NEXT:	.uleb128 .LBB_END0_1-.LBB0_1
+; CHECK-NEXT:	.byte	0
+; CHECK-NEXT:	.uleb128 .LBB0_2-.Lfunc_begin0
+; CHECK-NEXT:	.uleb128 .LBB_END0_2-.LBB0_2
+; CHECK-NEXT:	.byte	1
+; CHECK-NEXT:	.uleb128 .LBB0_3-.Lfunc_begin0
+; CHECK-NEXT:	.uleb128 .LBB_END0_3-.LBB0_3
+; CHECK-NEXT:	.byte	5
Index: llvm/test/CodeGen/X86/basic-block-sections-labels-functions-sections.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/basic-block-sections-labels-functions-sections.ll
@@ -0,0 +1,35 @@
+; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-sections=labels | FileCheck %s
+
+$_Z4fooTIiET_v = comdat any
+
+define dso_local i32 @_Z3barv() {
+  ret i32 0
+}
+;; Check we add SHF_LINK_ORDER for .bb_addr_map and link it with the corresponding .text sections.
+; CHECK:		.section .text._Z3barv,"ax",@progbits
+; CHECK-LABEL:	_Z3barv:
+; CHECK-NEXT:	[[BAR_BEGIN:.Lfunc_begin[0-9]+]]:
+; CHECK:		.section .bb_addr_map,"o",@progbits,.text._Z3barv{{$}}
+; CHECK-NEXT:		.quad [[BAR_BEGIN]]
+
+
+define dso_local i32 @_Z3foov() {
+  %1 = call i32 @_Z4fooTIiET_v()
+  ret i32 %1
+}
+; CHECK:		.section .text._Z3foov,"ax",@progbits
+; CHECK-LABEL:	_Z3foov:
+; CHECK-NEXT:	[[FOO_BEGIN:.Lfunc_begin[0-9]+]]:
+; CHECK:		.section  .bb_addr_map,"o",@progbits,.text._Z3foov{{$}}
+; CHECK-NEXT:		.quad [[FOO_BEGIN]]
+
+
+define linkonce_odr dso_local i32 @_Z4fooTIiET_v() comdat {
+  ret i32 0
+}
+;; Check we add .bb_addr_map section to a COMDAT group with the corresponding .text section if such a COMDAT exists.
+; CHECK:		.section .text._Z4fooTIiET_v,"axG",@progbits,_Z4fooTIiET_v,comdat
+; CHECK-LABEL:	_Z4fooTIiET_v:
+; CHECK-NEXT:	[[FOOCOMDAT_BEGIN:.Lfunc_begin[0-9]+]]:
+; CHECK:		.section .bb_addr_map,"Go",@progbits,_Z4fooTIiET_v,comdat,.text._Z4fooTIiET_v{{$}}
+; CHECK-NEXT:		.quad [[FOOCOMDAT_BEGIN]]
Index: llvm/lib/MC/MCObjectFileInfo.cpp
===
--- llvm/lib

[clang] 7841e21 - Let -basic-block-sections=labels emit basicblock metadata in a new .bb_addr_map section, instead of emitting special unary-encoded symbols.

2020-09-14 Thread Rahman Lavaee via cfe-commits

Author: Rahman Lavaee
Date: 2020-09-14T10:16:44-07:00
New Revision: 7841e21c98495ba5e33e0d2507d985bd5b938445

URL: 
https://github.com/llvm/llvm-project/commit/7841e21c98495ba5e33e0d2507d985bd5b938445
DIFF: 
https://github.com/llvm/llvm-project/commit/7841e21c98495ba5e33e0d2507d985bd5b938445.diff

LOG: Let -basic-block-sections=labels emit basicblock metadata in a new 
.bb_addr_map section, instead of emitting special unary-encoded symbols.

This patch introduces the new .bb_addr_map section feature which allows us to 
emit the bits needed for mapping binary profiles to basic blocks into a 
separate section.
The format of the emitted data is represented as follows. It includes a header 
for every function:

|  Address of the function  |  -> 8 bytes (pointer size)
|  Number of basic blocks in this function (>0) |  -> ULEB128

The header is followed by a BB record for every basic block. These records are 
ordered in the same order as MachineBasicBlocks are placed in the function. 
Each BB Info is structured as follows:

|  Offset of the basic block relative to function begin |  -> ULEB128
|  Binary size of the basic block   |  -> ULEB128
|  BB metadata  |  -> ULEB128  [ 
MBB.isReturn() OR MBB.hasTailCall() << 1  OR  MBB.isEHPad() << 2 ]

The new feature will replace the existing "BB labels" functionality with 
-basic-block-sections=labels.
The .bb_addr_map section scrubs the specially-encoded BB symbols from the 
binary and makes it friendly to profilers and debuggers.
Furthermore, the new feature reduces the binary size overhead from 70% bloat to 
only 12%.

For more information and results please refer to the RFC: 
https://lists.llvm.org/pipermail/llvm-dev/2020-July/143512.html

Reviewed By: MaskRay, snehasish

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

Added: 
llvm/test/CodeGen/X86/basic-block-sections-labels-functions-sections.ll

Modified: 
clang/docs/UsersManual.rst
clang/test/CodeGen/basic-block-sections.c
llvm/include/llvm/CodeGen/AsmPrinter.h
llvm/include/llvm/CodeGen/MachineFunction.h
llvm/include/llvm/MC/MCObjectFileInfo.h
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/lib/CodeGen/BasicBlockSections.cpp
llvm/lib/CodeGen/MIRParser/MIRParser.cpp
llvm/lib/CodeGen/MachineBasicBlock.cpp
llvm/lib/CodeGen/MachineFunction.cpp
llvm/lib/MC/MCObjectFileInfo.cpp
llvm/test/CodeGen/X86/basic-block-sections-labels.ll

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 1a1aea2ae538..2d0d71443dfd 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1700,9 +1700,12 @@ are listed below.
 
 **-fbasic-block-sections=[labels, all, list=, none]**
 
-  Controls whether Clang emits a label for each basic block.  Further, with
-  values "all" and "list=arg", each basic block or a subset of basic blocks
-  can be placed in its own unique section.
+  Controls how Clang emits text sections for basic blocks. With values ``all``
+  and ``list=``, each basic block or a subset of basic blocks can be 
placed
+  in its own unique section. With the "labels" value, normal text sections are
+  emitted, but a ``.bb_addr_map`` section is emitted which includes address
+  offsets for each basic block in the program, relative to the parent function
+  address.
 
   With the ``list=`` option, a file containing the subset of basic blocks
   that need to placed in unique sections can be specified.  The format of the

diff  --git a/clang/test/CodeGen/basic-block-sections.c 
b/clang/test/CodeGen/basic-block-sections.c
index 6cdea79f0fa7..dc414d70ba5f 100644
--- a/clang/test/CodeGen/basic-block-sections.c
+++ b/clang/test/CodeGen/basic-block-sections.c
@@ -1,12 +1,11 @@
 // REQUIRES: x86-registered-target
 
-// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -o - < %s | FileCheck %s 
--check-prefix=PLAIN
-// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fbasic-block-sections=all 
-fbasic-block-sections=none -o - < %s | FileCheck %s --check-prefix=PLAIN
+// RUN: %clang_cc1 -triple x86_64 -S -o - < %s | FileCheck %s 
--check-prefix=PLAIN
+// RUN: %clang_cc1 -triple x86_64 -S -fbasic-block-sections=all 
-fbasic-block-sections=none -o - < %s | FileCheck %s --check-prefix=PLAIN
 
-// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S 
-fbasic-block-sections=labels -o - < %s | FileCheck %s --check-prefix=BB_LABELS
-// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fbasic-block-sections=all 
-o - < %s | FileCheck %s --check-prefix=BB_WORLD --check-prefix=BB_ALL
-// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S 
-fbasic-block-sections=list=%S/Inputs/basic-block-sections.funcnames -o - < %s 
| FileCheck %s --check-prefix=BB_WORLD --check-prefix=BB_LIST
-// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -S -fbasic-block-sections=all 
-funique-basic-block-section-names -

[PATCH] D85408: Let -basic-block-sections=labels emit basicblock metadata in a new .bb_addr_map section, instead of emitting special unary-encoded symbols.

2020-09-14 Thread Rahman Lavaee via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7841e21c9849: Let -basic-block-sections=labels emit 
basicblock metadata in a new .bb_addr_map… (authored by rahmanl).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85408/new/

https://reviews.llvm.org/D85408

Files:
  clang/docs/UsersManual.rst
  clang/test/CodeGen/basic-block-sections.c
  llvm/include/llvm/CodeGen/AsmPrinter.h
  llvm/include/llvm/CodeGen/MachineFunction.h
  llvm/include/llvm/MC/MCObjectFileInfo.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/CodeGen/BasicBlockSections.cpp
  llvm/lib/CodeGen/MIRParser/MIRParser.cpp
  llvm/lib/CodeGen/MachineBasicBlock.cpp
  llvm/lib/CodeGen/MachineFunction.cpp
  llvm/lib/MC/MCObjectFileInfo.cpp
  llvm/test/CodeGen/X86/basic-block-sections-labels-functions-sections.ll
  llvm/test/CodeGen/X86/basic-block-sections-labels.ll

Index: llvm/test/CodeGen/X86/basic-block-sections-labels.ll
===
--- llvm/test/CodeGen/X86/basic-block-sections-labels.ll
+++ llvm/test/CodeGen/X86/basic-block-sections-labels.ll
@@ -1,23 +1,24 @@
 ; Check the basic block sections labels option
-; RUN: llc < %s -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=labels | FileCheck %s -check-prefix=LINUX-LABELS
+; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-sections=labels | FileCheck %s
 
-define void @_Z3bazb(i1 zeroext) {
-  %2 = alloca i8, align 1
-  %3 = zext i1 %0 to i8
-  store i8 %3, i8* %2, align 1
-  %4 = load i8, i8* %2, align 1
-  %5 = trunc i8 %4 to i1
-  br i1 %5, label %6, label %8
+define void @_Z3bazb(i1 zeroext) personality i32 (...)* @__gxx_personality_v0 {
+  br i1 %0, label %2, label %7
 
-6:; preds = %1
-  %7 = call i32 @_Z3barv()
-  br label %10
+2:
+  %3 = invoke i32 @_Z3barv()
+  to label %7 unwind label %5
+  br label %9
 
-8:; preds = %1
-  %9 = call i32 @_Z3foov()
-  br label %10
+5:
+  landingpad { i8*, i32 }
+  catch i8* null
+  br label %9
 
-10:   ; preds = %8, %6
+7:
+  %8 = call i32 @_Z3foov()
+  br label %9
+
+9:
   ret void
 }
 
@@ -25,9 +26,31 @@
 
 declare i32 @_Z3foov() #1
 
-; LINUX-LABELS: .section
-; LINUX-LABELS: _Z3bazb:
-; LINUX-LABELS-NOT: .section
-; LINUX-LABELS: r.BB._Z3bazb:
-; LINUX-LABELS-NOT: .section
-; LINUX-LABELS: rr.BB._Z3bazb:
+declare i32 @__gxx_personality_v0(...)
+
+; CHECK-LABEL:	_Z3bazb:
+; CHECK-LABEL:	.Lfunc_begin0:
+; CHECK-LABEL:	.LBB_END0_0:
+; CHECK-LABEL:	.LBB0_1:
+; CHECK-LABEL:	.LBB_END0_1:
+; CHECK-LABEL:	.LBB0_2:
+; CHECK-LABEL:	.LBB_END0_2:
+; CHECK-LABEL:	.LBB0_3:
+; CHECK-LABEL:	.LBB_END0_3:
+; CHECK-LABEL:	.Lfunc_end0:
+
+; CHECK:	.section	.bb_addr_map,"o",@progbits,.text
+; CHECK-NEXT:	.quad	.Lfunc_begin0
+; CHECK-NEXT:	.byte	4
+; CHECK-NEXT:	.uleb128 .Lfunc_begin0-.Lfunc_begin0
+; CHECK-NEXT:	.uleb128 .LBB_END0_0-.Lfunc_begin0
+; CHECK-NEXT:	.byte	0
+; CHECK-NEXT:	.uleb128 .LBB0_1-.Lfunc_begin0
+; CHECK-NEXT:	.uleb128 .LBB_END0_1-.LBB0_1
+; CHECK-NEXT:	.byte	0
+; CHECK-NEXT:	.uleb128 .LBB0_2-.Lfunc_begin0
+; CHECK-NEXT:	.uleb128 .LBB_END0_2-.LBB0_2
+; CHECK-NEXT:	.byte	1
+; CHECK-NEXT:	.uleb128 .LBB0_3-.Lfunc_begin0
+; CHECK-NEXT:	.uleb128 .LBB_END0_3-.LBB0_3
+; CHECK-NEXT:	.byte	5
Index: llvm/test/CodeGen/X86/basic-block-sections-labels-functions-sections.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/basic-block-sections-labels-functions-sections.ll
@@ -0,0 +1,35 @@
+; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-sections=labels | FileCheck %s
+
+$_Z4fooTIiET_v = comdat any
+
+define dso_local i32 @_Z3barv() {
+  ret i32 0
+}
+;; Check we add SHF_LINK_ORDER for .bb_addr_map and link it with the corresponding .text sections.
+; CHECK:		.section .text._Z3barv,"ax",@progbits
+; CHECK-LABEL:	_Z3barv:
+; CHECK-NEXT:	[[BAR_BEGIN:.Lfunc_begin[0-9]+]]:
+; CHECK:		.section .bb_addr_map,"o",@progbits,.text._Z3barv{{$}}
+; CHECK-NEXT:		.quad [[BAR_BEGIN]]
+
+
+define dso_local i32 @_Z3foov() {
+  %1 = call i32 @_Z4fooTIiET_v()
+  ret i32 %1
+}
+; CHECK:		.section .text._Z3foov,"ax",@progbits
+; CHECK-LABEL:	_Z3foov:
+; CHECK-NEXT:	[[FOO_BEGIN:.Lfunc_begin[0-9]+]]:
+; CHECK:		.section  .bb_addr_map,"o",@progbits,.text._Z3foov{{$}}
+; CHECK-NEXT:		.quad [[FOO_BEGIN]]
+
+
+define linkonce_odr dso_local i32 @_Z4fooTIiET_v() comdat {
+  ret i32 0
+}
+;; Check we add .bb_addr_map section to a COMDAT group with the corresponding .text section if such a COMDAT exists.
+; CHECK:		.section .text._Z4fooTIiET_v,"axG",@progbits,_Z4fooTIiET_v,comdat
+; CHECK-LABEL:	_Z4fooTIiET_v:
+; CHECK-NEXT:	[[FOOCOMDAT_BEGIN:.Lfunc_begin[0-9]+]]:
+; CHECK:		.section .bb_addr_map,"Go",@progbits,_Z4fooTIiET_v,comdat,.

[PATCH] D87587: [clang-format][PR47290] Make one-line namespaces resistant to FixNamespaceComments, update documentation

2020-09-14 Thread Krystian Kuzniarek via Phabricator via cfe-commits
kuzkry added a comment.

Hey @MyDeveloperDay, thanks for the review.

On the one hand, you're right, it's a breaking change and I dislike it too.
But please, reconsider because on the other hand:
a) adding a new option means increasing our maintenance cost by possibly adding 
a rarely-used switch (which I also dislike)
b) it's been a part of clang-format documentation since release 5 so we could 
make clang-format work as expected
c) this patch doesn't have to be applied to already released versions and could 
be merged with a new major release. I think people can expect certain things to 
work differently while changing major versions.
d) in general, people care about preserving their git history and they normally 
don't format all their code blindly. I think the most frequent use case it to 
format only adjacent parts of code.

So, I'd say both ways have their ups and downs.

@all
Still, so far I've got two change requests from you lot but they are mutually 
exclusive.
To sum it up, which do you prefer?
a) add a new option (@MyDeveloperDay's approach)
b) change kShortNamespaceMaxLines (my approach) assuming @JakeMerdichAMD's 
suggestions (non-empty one-line namespaces aren't given the end comment)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87587/new/

https://reviews.llvm.org/D87587

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


[PATCH] D87611: [SystemZ][z/OS] Set aligned allocation unavailable by default for z/OS

2020-09-14 Thread Fanbo Meng via Phabricator via cfe-commits
fanbo-meng added inline comments.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:1841
-<< IsDelete << FD.getType().getAsString() << OSName
-<< alignedAllocMinVersion(T.getOS()).getAsString();
 Diag(Loc, diag::note_silence_aligned_allocation_unavailable);

hubert.reinterpretcast wrote:
> Just to ensure we are on the same page:
> Passing `-Xclang -faligned-alloc-unavailable` on the non-Apple platforms does 
> very bad things (hits "unreachable" and otherwise falls off the end of a 
> function without initializing a return value). Part of this patch makes 
> passing `-Xclang -faligned-alloc-unavailable` okay on z/OS.
Yes, as we are trying to solve the same problem like Darwin (lack of support in 
system libraries), we use the same mechanism that are introduced for that.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87611/new/

https://reviews.llvm.org/D87611

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


[PATCH] D87455: [clang-tidy] performance-unnecessary-copy-initialization: Restrict UnnecessaryCopyInitialization check to variables initialized from free functions without arguments

2020-09-14 Thread Felix Berger via Phabricator via cfe-commits
flx updated this revision to Diff 291610.
flx marked an inline comment as done.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87455/new/

https://reviews.llvm.org/D87455

Files:
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -23,6 +23,9 @@
 ExpensiveToCopyType global_expensive_to_copy_type;
 
 const ExpensiveToCopyType &ExpensiveTypeReference();
+const ExpensiveToCopyType &freeFunctionWithArg(const ExpensiveToCopyType &);
+const ExpensiveToCopyType &freeFunctionWithDefaultArg(
+const ExpensiveToCopyType *arg = nullptr);
 const TrivialToCopyType &TrivialTypeReference();
 
 void mutate(ExpensiveToCopyType &);
@@ -387,3 +390,18 @@
   for (const Element &E : Container()) {
   }
 }
+
+// This should not trigger the check as the argument could introduce an alias.
+void negativeInitializedFromFreeFunctionWithArg() {
+  ExpensiveToCopyType Orig;
+  const ExpensiveToCopyType Copy = freeFunctionWithArg(Orig);
+}
+
+void negativeInitializedFromFreeFunctionWithDefaultArg() {
+  const ExpensiveToCopyType Copy = freeFunctionWithDefaultArg();
+}
+
+void negativeInitialzedFromFreeFunctionWithNonDefaultArg() {
+  ExpensiveToCopyType Orig;
+  const ExpensiveToCopyType Copy = freeFunctionWithDefaultArg(&Orig);
+}
Index: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
===
--- clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
+++ clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
@@ -54,7 +54,8 @@
 on(declRefExpr(to(varDecl().bind("objectArg");
   auto ConstRefReturningFunctionCall =
   callExpr(callee(functionDecl(returns(ConstReference))),
-   unless(callee(cxxMethodDecl(;
+   unless(callee(cxxMethodDecl(
+  .bind("initFunctionCall");
 
   auto localVarCopiedFrom = [this](const internal::Matcher &CopyCtorArg) 
{
 return compoundStmt(
@@ -96,6 +97,8 @@
   const auto *ObjectArg = Result.Nodes.getNodeAs("objectArg");
   const auto *BlockStmt = Result.Nodes.getNodeAs("blockStmt");
   const auto *CtorCall = Result.Nodes.getNodeAs("ctorCall");
+  const auto *InitFunctionCall =
+  Result.Nodes.getNodeAs("initFunctionCall");
 
   TraversalKindScope RAII(*Result.Context, ast_type_traits::TK_AsIs);
 
@@ -113,6 +116,11 @@
   return;
 
   if (OldVar == nullptr) {
+// Only allow initialization of a const reference from a free function if 
it
+// has no arguments. Otherwise it could return an alias to one of its
+// arguments and the arguments need to be checked for const use as well.
+if (InitFunctionCall != nullptr && InitFunctionCall->getNumArgs() > 0)
+  return;
 handleCopyFromMethodReturn(*NewVar, *BlockStmt, IssueFix, ObjectArg,
*Result.Context);
   } else {


Index: clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/performance-unnecessary-copy-initialization.cpp
@@ -23,6 +23,9 @@
 ExpensiveToCopyType global_expensive_to_copy_type;
 
 const ExpensiveToCopyType &ExpensiveTypeReference();
+const ExpensiveToCopyType &freeFunctionWithArg(const ExpensiveToCopyType &);
+const ExpensiveToCopyType &freeFunctionWithDefaultArg(
+const ExpensiveToCopyType *arg = nullptr);
 const TrivialToCopyType &TrivialTypeReference();
 
 void mutate(ExpensiveToCopyType &);
@@ -387,3 +390,18 @@
   for (const Element &E : Container()) {
   }
 }
+
+// This should not trigger the check as the argument could introduce an alias.
+void negativeInitializedFromFreeFunctionWithArg() {
+  ExpensiveToCopyType Orig;
+  const ExpensiveToCopyType Copy = freeFunctionWithArg(Orig);
+}
+
+void negativeInitializedFromFreeFunctionWithDefaultArg() {
+  const ExpensiveToCopyType Copy = freeFunctionWithDefaultArg();
+}
+
+void negativeInitialzedFromFreeFunctionWithNonDefaultArg() {
+  ExpensiveToCopyType Orig;
+  const ExpensiveToCopyType Copy = freeFunctionWithDefaultArg(&Orig);
+}
Index: clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
===
--- clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
+++ clang-tools-extra/clang-tidy/performance/Unnecessary

[PATCH] D87561: [Sema] List conversion validate character array

2020-09-14 Thread Mark de Wever via Phabricator via cfe-commits
Mordante marked 3 inline comments as done.
Mordante added a comment.

Thanks for the feedback!




Comment at: clang/lib/Sema/SemaOverload.cpp:4988
+
+if (ToType->isArrayType() && ToType->isCharType() &&
+isa(From->getInit(0))) {

rsmith wrote:
> `isCharType` is too narrow a check here. We also need to check for all the 
> other types that can be initialized from a string literal (`wchar_t`, 
> `char16_t`, ... -- including `unsigned short` in some cases). These details 
> are handled by 
> [`IsStringInit`](https://github.com/llvm/llvm-project/blob/master/clang/lib/Sema/SemaInit.cpp#L136).
>  Maybe it's worth exposing that as a `bool Sema::isStringInit` function or 
> similar to use from here?
I think exposing this function sounds good.



Comment at: clang/lib/Sema/SemaOverload.cpp:4991-4992
   InitializedEntity Entity =
-InitializedEntity::InitializeParameter(S.Context, ToType,
-   /*Consumed=*/false);
+  InitializedEntity::InitializeParameter(S.Context, ToType,
+ /*Consumed=*/false);
   if (S.CanPerformCopyInitialization(Entity, From)) {

rsmith wrote:
> Phabricator thinks you converted spaces to tabs here. Please can you check 
> and convert back if necessary?
That's odd in my editor I see spaces. I ran `git clang-format` on an earlier 
version where I made some changes here. I'll revert the hunk.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87561/new/

https://reviews.llvm.org/D87561

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


[PATCH] D87455: [clang-tidy] performance-unnecessary-copy-initialization: Restrict UnnecessaryCopyInitialization check to variables initialized from free functions without arguments

2020-09-14 Thread Felix Berger via Phabricator via cfe-commits
flx added a comment.

Thank you for the review, Aaron!

I don't have have commit access. Would you mind submitting it?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87455/new/

https://reviews.llvm.org/D87455

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


[PATCH] D84362: [NFC] Add missing functions to PartialDiagnostic

2020-09-14 Thread Artem Belevich via Phabricator via cfe-commits
tra added subscribers: aaron.ballman, rtrieu.
tra added a comment.

So, the idea here is to do some sort of duck-typing and allow DiagBuilder to 
work with both `DiagnosticBuilder` and `PartialDiagnostic`.

What bothers me is that unlike `Diagnostic` `PartialDiagnostic` seems to be 
commingling functionality of the builder with that of the diagnostic itself. 
I'm not sure if that's by design or just happened to be that way.

I think a better approach would be to refactor `PartialDiagnostic` and separate 
the builder functionality. That should make it possible to create a common 
diagnostic builder base class with Partial/Full diagnostic deriving their own 
builder, if needed.

That said, I'm not that familiar with the diags. Perhaps  @rtrieu 
@aaron.ballman would have better ideas.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84362/new/

https://reviews.llvm.org/D84362

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


[PATCH] D86671: [clang-tidy] Add new case type to check variables with Hungarian notation

2020-09-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp:216
+{"long","l"},
+{"long long",   "ll"},
+{"unsigned long",   "ul"},

`unsigned long long` -> `ull`



Comment at: 
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp:225
+{"WORD","w"},
+{"DWORD",   "dw"}};
+  // clang-format on

`ULONG` -> `ul`
`HANDLE` -> `h`




Comment at: 
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp:236
+  PrefixStr = "fn"; // Function Pointer
+} else if (QT->isPointerType()) {
+  // clang-format off

I'm not certain how valid it is to look at just the type and decide that it's a 
null-terminated string. For instance, the following is not an uncommon pattern: 
`void something(const char *buffer, size_t length);` and it would be a bit 
strange to change that into `szBuffer` as that would give an indication that 
the buffer is null terminated. You could look at surrounding code for 
additional information though, like other parameters in a function declaration. 
As an aside, this sort of heuristic search may also allow you to change 
`length` into `cbLength` instead of `nLength` for conventions like the 
Microsoft one.

However, for local variables, I don't see how you could even come up with a 
heuristic like you could with parameters, so I'm not certain what the right 
answer is here.



Comment at: 
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp:309
+
+  if (PtrCount > 0) {
+for (size_t Idx = 0; Idx < PtrCount; Idx++) {

No need for this `if` statement, the `for` loop won't run anyway if `PtrCount 
== 0`.



Comment at: 
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp:319
+std::string
+IdentifierNamingCheck::getDeclTypeName(const clang::NamedDecl *Decl) const {
+  const ValueDecl *ValDecl = dyn_cast(Decl);

`ND` instead of `Decl`.

The function name doesn't really help me to understand why you'd call this as 
opposed to getting the type information as a string from the `NamedDecl` 
itself. I'm a bit worried about maintaining this code as the language evolves 
-- Clang will get new keywords, and someone will have to remember to come 
update this code. Could you get away with using 
`Decl->getType()->getAsString()` and working with that rather than going back 
to the original source code and trying to parse manually?



Comment at: 
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp:320
+IdentifierNamingCheck::getDeclTypeName(const clang::NamedDecl *Decl) const {
+  const ValueDecl *ValDecl = dyn_cast(Decl);
+  if (!ValDecl) {

`const auto *` since the type is spelled out in the initialization.



Comment at: 
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp:554
+  case IdentifierNamingCheck::CT_HungarianNotation: {
+const NamedDecl *ND = dyn_cast(InputDecl);
+const std::string TypePrefix =

`const auto *` because the type is spelled out in the initialization.



Comment at: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h:39
 
+  std::string getDeclTypeName(const clang::NamedDecl *Decl) const;
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;

Can you go with `ND` (or something else) instead of `Decl` since that's a type 
name?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86671/new/

https://reviews.llvm.org/D86671

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


[PATCH] D87611: [SystemZ][z/OS] Set aligned allocation unavailable by default for z/OS

2020-09-14 Thread Fanbo Meng via Phabricator via cfe-commits
fanbo-meng updated this revision to Diff 291616.
fanbo-meng added a comment.

be consistent with namespace qualification


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87611/new/

https://reviews.llvm.org/D87611

Files:
  clang/include/clang/Basic/AlignedAllocation.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Driver/ToolChains/ZOS.cpp
  clang/lib/Driver/ToolChains/ZOS.h
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/Driver/unavailable_aligned_allocation.cpp
  clang/test/Lexer/aligned-allocation.cpp
  clang/test/SemaCXX/unavailable_aligned_allocation.cpp

Index: clang/test/SemaCXX/unavailable_aligned_allocation.cpp
===
--- clang/test/SemaCXX/unavailable_aligned_allocation.cpp
+++ clang/test/SemaCXX/unavailable_aligned_allocation.cpp
@@ -1,12 +1,15 @@
-// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DMACOS %s
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s
-// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -faligned-allocation -faligned-alloc-unavailable -std=c++14 -verify %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.13.0 -fexceptions -faligned-allocation -faligned-alloc-unavailable -std=c++14 -verify -DMACOS %s
 // RUN: %clang_cc1 -triple arm64-apple-ios10.0.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DIOS %s
 // RUN: %clang_cc1 -triple arm64-apple-ios10.0.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s
 // RUN: %clang_cc1 -triple arm64-apple-tvos10.0.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DTVOS %s
 // RUN: %clang_cc1 -triple arm64-apple-tvos10.0.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s
 // RUN: %clang_cc1 -triple armv7k-apple-watchos3.0.0 -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DWATCHOS %s
 // RUN: %clang_cc1 -triple armv7k-apple-watchos3.0.0 -fexceptions -std=c++1z -verify -DNO_ERRORS %s
+// RUN: %clang_cc1 -triple s390x-ibm-zos -fexceptions -faligned-alloc-unavailable -std=c++1z -verify -DZOS %s
+// RUN: %clang_cc1 -triple s390x-ibm-zos -fexceptions -std=c++1z -verify -DNO_ERRORS %s
+// RUN: %clang_cc1 -triple s390x-ibm-zos -fexceptions -faligned-allocation -faligned-alloc-unavailable -std=c++14 -verify -DZOS %s
 
 namespace std {
   typedef decltype(sizeof(0)) size_t;
@@ -62,40 +65,40 @@
 #ifdef NO_ERRORS
 // expected-no-diagnostics
 #else
-// expected-error@-16 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on}}
+// expected-error-re@-16 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is {{only|not}} available on}}
 // expected-note@-17 {{if you supply your own aligned allocation functions}}
-// expected-error@-18 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
+// expected-error-re@-18 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is {{only|not}} available on}}
 // expected-note@-19 {{if you supply your own aligned allocation functions}}
 
-// expected-error@-20 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is only available on}}
+// expected-error-re@-20 {{aligned allocation function of type 'void *(unsigned long, enum std::align_val_t)' is {{only|not}} available on}}
 // expected-note@-21 {{if you supply your own aligned allocation functions}}
-// expected-error@-22 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
+// expected-error-re@-22 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is {{only|not}} available on}}
 // expected-note@-23 {{if you supply your own aligned allocation functions}}
 
-// expected-error@-24 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is only available on}}
+// expected-error-re@-24 {{aligned deallocation function of type 'void (void *, enum std::align_val_t) noexcept' is {{only|not}} available on}}
 // expected-note@-25 {{if you supply your own aligned allocation functions}}
 
-// expected-error@-26 {{aligned allocation function of type 'void *(std::size_t, std::align_val_t, const std::nothrow_t &) noexcept' is only available on}}
+// expected-error-re@-26 {{aligned allocation function of type 'void *(std::size_t, std::align_val_t, const std::nothrow_t &) noexcept' is {{only|not}} available on}}
 // expected-note@-27 {{if you supply your own aligned allocation functions}}
-// expected-error@-28 {{aligned deallocation function of type 'void (void *, std::align_val_t, const std::nothrow_t &) noexcept' is only available on}}
+// expected-err

[PATCH] D87425: [CodeGen][typeid] Emit typeinfo directly if type is known at compile-time

2020-09-14 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu updated this revision to Diff 291619.
zequanwu added a comment.

If the operand of CXXTypeidExpr is already most derived object, no need to look 
up vtable.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87425/new/

https://reviews.llvm.org/D87425

Files:
  clang/include/clang/AST/ExprCXX.h
  clang/lib/AST/ExprCXX.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/test/CodeGenCXX/microsoft-abi-typeid.cpp
  clang/test/SemaCXX/constant-expression-cxx2a.cpp


Index: clang/test/SemaCXX/constant-expression-cxx2a.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx2a.cpp
+++ clang/test/SemaCXX/constant-expression-cxx2a.cpp
@@ -309,7 +309,7 @@
   static_assert(&B2().ti2 == &typeid(B2));
   extern B2 extern_b2;
   // expected-note@+1 {{typeid applied to object 'extern_b2' whose dynamic 
type is not constant}}
-  static_assert(&typeid(extern_b2) == &typeid(B2)); // expected-error 
{{constant expression}}
+  static_assert(&typeid(*&extern_b2) == &typeid(B2)); // expected-error 
{{constant expression}}
 
   constexpr B2 b2;
   constexpr const B &b1 = b2;
Index: clang/test/CodeGenCXX/microsoft-abi-typeid.cpp
===
--- clang/test/CodeGenCXX/microsoft-abi-typeid.cpp
+++ clang/test/CodeGenCXX/microsoft-abi-typeid.cpp
@@ -46,9 +46,11 @@
 
 const std::type_info* test5_typeid() { return &typeid(v); }
 // CHECK: define dso_local %struct.type_info* 
@"?test5_typeid@@YAPBUtype_info@@XZ"()
-// CHECK:[[RT:%.*]] = call i8* @__RTtypeid(i8* bitcast (%struct.V* 
@"?v@@3UV@@A" to i8*))
-// CHECK-NEXT:   [[RET:%.*]] = bitcast i8* [[RT]] to %struct.type_info*
-// CHECK-NEXT:   ret %struct.type_info* [[RET]]
+// CHECK:   ret %struct.type_info* bitcast (%rtti.TypeDescriptor7* 
@"??_R0?AUV@@@8" to %struct.type_info*)
+
+const std::type_info *test6_typeid() { return &typeid((V &)v); }
+// CHECK: define dso_local %struct.type_info* 
@"?test6_typeid@@YAPBUtype_info@@XZ"()
+// CHECK:   ret %struct.type_info* bitcast (%rtti.TypeDescriptor7* 
@"??_R0?AUV@@@8" to %struct.type_info*)
 
 namespace PR26329 {
 struct Polymorphic {
Index: clang/lib/CodeGen/CGExprCXX.cpp
===
--- clang/lib/CodeGen/CGExprCXX.cpp
+++ clang/lib/CodeGen/CGExprCXX.cpp
@@ -2199,7 +2199,8 @@
   //   polymorphic class type, the result refers to a std::type_info object
   //   representing the type of the most derived object (that is, the dynamic
   //   type) to which the glvalue refers.
-  if (E->isPotentiallyEvaluated())
+  // If the operand is already most derived object, no need to look up vtable.
+  if (E->isPotentiallyEvaluated() && !E->isMostDerived(getContext()))
 return EmitTypeidFromVTable(*this, E->getExprOperand(),
 StdTypeInfoPtrTy);
 
Index: clang/lib/AST/ExprCXX.cpp
===
--- clang/lib/AST/ExprCXX.cpp
+++ clang/lib/AST/ExprCXX.cpp
@@ -146,6 +146,20 @@
   return false;
 }
 
+bool CXXTypeidExpr::isMostDerived(ASTContext &Context) const {
+  if (isTypeOperand())
+return false;
+
+  const Expr *E = getExprOperand()->IgnoreParenNoopCasts(Context);
+  if (auto *DRE = dyn_cast(E)) {
+QualType Ty = DRE->getDecl()->getType();
+if (!Ty->isPointerType() && !Ty->isReferenceType())
+  return true;
+  }
+
+  return false;
+}
+
 QualType CXXTypeidExpr::getTypeOperand(ASTContext &Context) const {
   assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)");
   Qualifiers Quals;
Index: clang/include/clang/AST/ExprCXX.h
===
--- clang/include/clang/AST/ExprCXX.h
+++ clang/include/clang/AST/ExprCXX.h
@@ -840,6 +840,8 @@
   /// evaluated, per C++11 [expr.typeid]p3.
   bool isPotentiallyEvaluated() const;
 
+  bool isMostDerived(ASTContext &Context) const;
+
   bool isTypeOperand() const { return Operand.is(); }
 
   /// Retrieves the type operand of this typeid() expression after


Index: clang/test/SemaCXX/constant-expression-cxx2a.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx2a.cpp
+++ clang/test/SemaCXX/constant-expression-cxx2a.cpp
@@ -309,7 +309,7 @@
   static_assert(&B2().ti2 == &typeid(B2));
   extern B2 extern_b2;
   // expected-note@+1 {{typeid applied to object 'extern_b2' whose dynamic type is not constant}}
-  static_assert(&typeid(extern_b2) == &typeid(B2)); // expected-error {{constant expression}}
+  static_assert(&typeid(*&extern_b2) == &typeid(B2)); // expected-error {{constant expression}}
 
   constexpr B2 b2;
   constexpr const B &b1 = b2;
Index: clang/test/CodeGenCXX/microsoft-abi-typeid.cpp
===
--- clang/test/CodeGenCXX/microsoft-abi-typeid.cpp
+++ clang/test/CodeGenCXX/microsoft-abi-typeid

  1   2   >