r321861 - Commit new test file forgotten in previous commit

2018-01-05 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Thu Jan  4 23:59:57 2018
New Revision: 321861

URL: http://llvm.org/viewvc/llvm-project?rev=321861&view=rev
Log:
Commit new test file forgotten in previous commit

Added:
cfe/trunk/test/CodeGenCXX/ubsan-function-noexcept.cpp

Added: cfe/trunk/test/CodeGenCXX/ubsan-function-noexcept.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ubsan-function-noexcept.cpp?rev=321861&view=auto
==
--- cfe/trunk/test/CodeGenCXX/ubsan-function-noexcept.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/ubsan-function-noexcept.cpp Thu Jan  4 23:59:57 
2018
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -std=c++17 -fsanitize=function -emit-llvm -triple 
x86_64-linux-gnu %s -o - | FileCheck %s
+
+// Check that typeinfo recorded in function prolog doesn't have "Do" noexcept
+// qualifier in its mangled name.
+// CHECK: @[[RTTI:[0-9]+]] = private constant i8* bitcast ({ i8*, i8* }* 
@_ZTIFvvE to i8*)
+// CHECK: define void @_Z1fv() #{{.*}} prologue <{ i32, i32 }> <{ i32 {{.*}}, 
i32 trunc (i64 sub (i64 ptrtoint (i8** @[[RTTI]] to i64), i64 ptrtoint (void 
()* @_Z1fv to i64)) to i32) }>
+void f() noexcept {}
+
+// CHECK: define void @_Z1gPDoFvvE
+void g(void (*p)() noexcept) {
+  // Check that reference typeinfo at call site doesn't have "Do" noexcept
+  // qualifier in its mangled name, either.
+  // CHECK: icmp eq i8* %{{.*}}, bitcast ({ i8*, i8* }* @_ZTIFvvE to i8*), 
!nosanitize
+  p();
+}


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


[PATCH] D40720: No -fsanitize=function warning when calling noexcept function through non-noexcept pointer in C++17

2018-01-05 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg added a comment.

Should this be backported to Clang 6?  Not sure how widespread a problem this 
is in practice (it hit me with LibreOffice).


Repository:
  rC Clang

https://reviews.llvm.org/D40720



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


[PATCH] D20124: [PCH] Serialize skipped preprocessor ranges

2018-01-05 Thread Erik Verbruggen via Phabricator via cfe-commits
erikjv added a comment.

lgtm. Ilya?


https://reviews.llvm.org/D20124



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


[PATCH] D41668: [clangd] Add static index for the global code completion.

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



Comment at: clangd/ClangdServer.h:208
bool BuildDynamicSymbolIndex = false,
+   std::unique_ptr StaticIdx = nullptr,
llvm::Optional ResourceDir = llvm::None);

Please also add comment for this.



Comment at: clangd/ClangdServer.h:342
   std::unique_ptr FileIdx;
+  /// If set, this provides static index for project-wide global symbols.
+  std::unique_ptr StaticIdx;

... in addition to the `FileIdx` above?



Comment at: clangd/CodeComplete.cpp:571
+  // FIXME: find out a better way to show the index source.
+  Item.detail = llvm::Twine("[" + IndexSource + "]").str();
   return Item;

AFAIK, `Detail` is not visible in the completion item list unless you hover on 
an item. I'd suggest throwing a "[G]" prefix to labels of the global symbols. 
For completion `clang::^`, the list would look like:
```
clang::Local1
clang::Local2
[G]clang::Global1
[G]clang::Global2
```

WDYT?



Comment at: clangd/CodeComplete.cpp:651
  std::move(PCHs));
-  if (Opts.Index && CompletedName.SSInfo) {
+  if (CompletedName.SSInfo && (Opts.Index || Opts.StaticIndex)) {
 if (!Results.items.empty())

We might not want to lose (non-index-based) AST symbols if we only have 
`StaticIndex`. Maybe only use static index augment the dynamic index?



Comment at: clangd/CodeComplete.h:72
+  /// Static index for project-wide global symbols. It is set by the clangd
+  /// client.
+  /// The static index is loaded and built only once when clangd is being

ioeric wrote:
> `clangd client` is a confusing term? Do you mean clangd library users? Also, 
> I think this field is only set internally by clangd in this patch.
It's unclear whether this is set internally or expected to be set by users?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41668



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


[PATCH] D41730: [clangd] Use ToolExecutor to write the global-symbol-builder tool.

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

The implementation looks good, but to see whether sam has high-level comments 
on this.




Comment at: clangd/index/SymbolYAML.cpp:140
   llvm::yaml::Output Yout(OS);
   for (Symbol S : Symbols) // copy: Yout<< requires mutability.
 Yout<< S;

The function could be simplified by using the SymbolToYAML below.

```
std::string Str;
for (const Symbol& S : Symbols) {
   Str += SymbolToYAML(S);
}
```



Comment at: clangd/index/SymbolYAML.cpp:145
 
+std::string SymbolToYAML(const Symbol& Sym) {
+  std::string Str;

might be use `Symbol` as parameter type.



Comment at: clangd/index/SymbolYAML.h:30
 
+// Convert a single symbol to YAML-format string.
+std::string SymbolToYAML(const Symbol &Sym);

might be also mention `The YAML result is safe to concatenate`.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41730



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


[PATCH] D41729: Add a tool executor that runs actions on all TUs in the compilation database.

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

LGTM.




Comment at: include/clang/Tooling/AllTUsExecution.h:34
+  AllTUsToolExecutor(const CompilationDatabase &Compilations,
+ unsigned ThreadCount,
+ std::shared_ptr PCHContainerOps =

consider using a default parameter (= 0)? use the `llvm::hardware_concurrency` 
by default, and you don't have to pass the `0` in the unittest.



Comment at: lib/Tooling/AllTUsExecution.cpp:157
+X("all-TUs", "Runs FrontendActions on all TUs in the compilation database. 
"
+ "Tool results are deduplicated by the result key.");
+

also document all results are stored in memory, the result size should be 
suitable to be loaded in memory.



Comment at: unittests/Tooling/ExecutionTest.cpp:264
+  std::vector ExpectedSymbols;
+  for (unsigned i = 1; i <= NumFiles; i++) {
+std::string File = "f" + std::to_string(i) + ".cc";

nit: ++i.


Repository:
  rC Clang

https://reviews.llvm.org/D41729



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


[PATCH] D41729: Add a tool executor that runs actions on all TUs in the compilation database.

2018-01-05 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 128719.
ioeric marked 2 inline comments as done.
ioeric added a comment.

Address review comments.


Repository:
  rC Clang

https://reviews.llvm.org/D41729

Files:
  include/clang/Tooling/AllTUsExecution.h
  lib/Tooling/AllTUsExecution.cpp
  lib/Tooling/CMakeLists.txt
  lib/Tooling/Execution.cpp
  unittests/Tooling/ExecutionTest.cpp

Index: unittests/Tooling/ExecutionTest.cpp
===
--- unittests/Tooling/ExecutionTest.cpp
+++ unittests/Tooling/ExecutionTest.cpp
@@ -7,17 +7,19 @@
 //
 //===--===//
 
+#include "clang/Tooling/Execution.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Frontend/FrontendActions.h"
+#include "clang/Tooling/AllTUsExecution.h"
 #include "clang/Tooling/CompilationDatabase.h"
-#include "clang/Tooling/Execution.h"
 #include "clang/Tooling/StandaloneExecution.h"
 #include "clang/Tooling/ToolExecutorPluginRegistry.h"
 #include "clang/Tooling/Tooling.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
 #include 
@@ -217,5 +219,70 @@
   [](StringRef, StringRef Value) { EXPECT_EQ("1", Value); });
 }
 
+class FixedCompilationDatabaseWithFiles : public CompilationDatabase {
+public:
+  FixedCompilationDatabaseWithFiles(Twine Directory,
+ArrayRef Files,
+ArrayRef CommandLine)
+  : FixedCompilations(Directory, CommandLine), Files(Files) {}
+
+  std::vector
+  getCompileCommands(StringRef FilePath) const override {
+return FixedCompilations.getCompileCommands(FilePath);
+  }
+
+  std::vector getAllFiles() const override { return Files; }
+
+private:
+  FixedCompilationDatabase FixedCompilations;
+  std::vector Files;
+};
+
+MATCHER_P(Named, Name, "") { return arg.first == Name; }
+
+TEST(AllTUsToolTest, AFewFiles) {
+  FixedCompilationDatabaseWithFiles Compilations(".", {"a.cc", "b.cc", "c.cc"},
+ std::vector());
+  AllTUsToolExecutor Executor(Compilations, /*ThreadCount=*/0);
+  Executor.mapVirtualFile("a.cc", "void x() {}");
+  Executor.mapVirtualFile("b.cc", "void y() {}");
+  Executor.mapVirtualFile("c.cc", "void z() {}");
+
+  auto Err = Executor.execute(std::unique_ptr(
+  new ReportResultActionFactory(Executor.getExecutionContext(;
+  ASSERT_TRUE(!Err);
+  EXPECT_THAT(
+  Executor.getToolResults()->AllKVResults(),
+  ::testing::UnorderedElementsAre(Named("x"), Named("y"), Named("z")));
+}
+
+TEST(AllTUsToolTest, ManyFiles) {
+  unsigned NumFiles = 100;
+  std::vector Files;
+  std::map FileToContent;
+  std::vector ExpectedSymbols;
+  for (unsigned i = 1; i <= NumFiles; ++i) {
+std::string File = "f" + std::to_string(i) + ".cc";
+std::string Symbol = "looong_function_name_" + std::to_string(i);
+Files.push_back(File);
+FileToContent[File] = "void " + Symbol + "() {}";
+ExpectedSymbols.push_back(Symbol);
+  }
+  FixedCompilationDatabaseWithFiles Compilations(".", Files,
+ std::vector());
+  AllTUsToolExecutor Executor(Compilations, /*ThreadCount=*/0);
+  for (const auto &FileAndContent : FileToContent) {
+Executor.mapVirtualFile(FileAndContent.first, FileAndContent.second);
+  }
+
+  auto Err = Executor.execute(std::unique_ptr(
+  new ReportResultActionFactory(Executor.getExecutionContext(;
+  ASSERT_TRUE(!Err);
+  std::vector Results;
+  Executor.getToolResults()->forEachResult(
+  [&](StringRef Name, StringRef) { Results.push_back(Name); });
+  EXPECT_THAT(ExpectedSymbols, ::testing::UnorderedElementsAreArray(Results));
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Tooling/Execution.cpp
===
--- lib/Tooling/Execution.cpp
+++ lib/Tooling/Execution.cpp
@@ -96,10 +96,13 @@
 }
 
 // This anchor is used to force the linker to link in the generated object file
-// and thus register the StandaloneToolExecutorPlugin.
+// and thus register the StandaloneToolExecutorPlugin etc.
 extern volatile int StandaloneToolExecutorAnchorSource;
+extern volatile int AllTUsToolExecutorAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED StandaloneToolExecutorAnchorDest =
 StandaloneToolExecutorAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED AllTUsToolExecutorAnchorDest =
+AllTUsToolExecutorAnchorSource;
 
 } // end namespace tooling
 } // end namespace clang
Index: lib/Tooling/CMakeLists.txt
===
--- lib/Tooling/CMakeLists.txt
+++ lib/Tooling/CMakeLists.txt
@@ -8,6 +8,7 @@
 add_subdirectory(ASTDiff)
 
 add_clang_library(clangTooling
+  AllTUsExecution.cpp
   ArgumentsAdjusters.cpp
   CommonOpt

[PATCH] D41729: Add a tool executor that runs actions on all TUs in the compilation database.

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



Comment at: include/clang/Tooling/AllTUsExecution.h:34
+  AllTUsToolExecutor(const CompilationDatabase &Compilations,
+ unsigned ThreadCount,
+ std::shared_ptr PCHContainerOps =

hokein wrote:
> consider using a default parameter (= 0)? use the 
> `llvm::hardware_concurrency` by default, and you don't have to pass the `0` 
> in the unittest.
The constructors aren't usually used directly (outside of unit tests; interface 
design shouldn't be driven by tests), so I didn't use default parameters, since 
they are usually disliked...



Comment at: unittests/Tooling/ExecutionTest.cpp:264
+  std::vector ExpectedSymbols;
+  for (unsigned i = 1; i <= NumFiles; i++) {
+std::string File = "f" + std::to_string(i) + ".cc";

hokein wrote:
> nit: ++i.
Done. (I don't think this matters for simple types tho...)


Repository:
  rC Clang

https://reviews.llvm.org/D41729



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


[PATCH] D41729: Add a tool executor that runs actions on all TUs in the compilation database.

2018-01-05 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC321864: Add a tool executor that runs actions on all TUs in 
the compilation database. (authored by ioeric, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41729?vs=128719&id=128720#toc

Repository:
  rC Clang

https://reviews.llvm.org/D41729

Files:
  include/clang/Tooling/AllTUsExecution.h
  lib/Tooling/AllTUsExecution.cpp
  lib/Tooling/CMakeLists.txt
  lib/Tooling/Execution.cpp
  unittests/Tooling/ExecutionTest.cpp

Index: include/clang/Tooling/AllTUsExecution.h
===
--- include/clang/Tooling/AllTUsExecution.h
+++ include/clang/Tooling/AllTUsExecution.h
@@ -0,0 +1,76 @@
+//===--- AllTUsExecution.h - Execute actions on all TUs. -*- C++ *-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+//  This file defines a tool executor that runs given actions on all TUs in the
+//  compilation database. Tool results are deuplicated by the result key.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLING_ALLTUSEXECUTION_H
+#define LLVM_CLANG_TOOLING_ALLTUSEXECUTION_H
+
+#include "clang/Tooling/ArgumentsAdjusters.h"
+#include "clang/Tooling/Execution.h"
+
+namespace clang {
+namespace tooling {
+
+/// \brief Executes given frontend actions on all files/TUs in the compilation
+/// database. The final results will be deduplicated by the result key.
+class AllTUsToolExecutor : public ToolExecutor {
+public:
+  static const char *ExecutorName;
+
+  /// \brief Init with \p CompilationDatabase.
+  /// This uses \p ThreadCount threads to exececute the actions on all files in
+  /// parallel. If \p ThreadCount is 0, this uses `llvm::hardware_concurrency`.
+  AllTUsToolExecutor(const CompilationDatabase &Compilations,
+ unsigned ThreadCount,
+ std::shared_ptr PCHContainerOps =
+ std::make_shared());
+
+  /// \brief Init with \p CommonOptionsParser. This is expected to be used by
+  /// `createExecutorFromCommandLineArgs` based on commandline options.
+  ///
+  /// The executor takes ownership of \p Options.
+  AllTUsToolExecutor(CommonOptionsParser Options, unsigned ThreadCount,
+ std::shared_ptr PCHContainerOps =
+ std::make_shared());
+
+  StringRef getExecutorName() const override { return ExecutorName; }
+
+  using ToolExecutor::execute;
+
+  llvm::Error
+  execute(llvm::ArrayRef<
+  std::pair, ArgumentsAdjuster>>
+  Actions) override;
+
+  ExecutionContext *getExecutionContext() override { return &Context; };
+
+  ToolResults *getToolResults() override { return Results.get(); }
+
+  void mapVirtualFile(StringRef FilePath, StringRef Content) override {
+OverlayFiles[FilePath] = Content;
+  }
+
+private:
+  // Used to store the parser when the executor is initialized with parser.
+  llvm::Optional OptionsParser;
+  const CompilationDatabase &Compilations;
+  std::unique_ptr Results;
+  ExecutionContext Context;
+  llvm::StringMap OverlayFiles;
+  unsigned ThreadCount;
+};
+
+} // end namespace tooling
+} // end namespace clang
+
+#endif // LLVM_CLANG_TOOLING_ALLTUSEXECUTION_H
Index: lib/Tooling/Execution.cpp
===
--- lib/Tooling/Execution.cpp
+++ lib/Tooling/Execution.cpp
@@ -96,10 +96,13 @@
 }
 
 // This anchor is used to force the linker to link in the generated object file
-// and thus register the StandaloneToolExecutorPlugin.
+// and thus register the StandaloneToolExecutorPlugin etc.
 extern volatile int StandaloneToolExecutorAnchorSource;
+extern volatile int AllTUsToolExecutorAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED StandaloneToolExecutorAnchorDest =
 StandaloneToolExecutorAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED AllTUsToolExecutorAnchorDest =
+AllTUsToolExecutorAnchorSource;
 
 } // end namespace tooling
 } // end namespace clang
Index: lib/Tooling/CMakeLists.txt
===
--- lib/Tooling/CMakeLists.txt
+++ lib/Tooling/CMakeLists.txt
@@ -8,6 +8,7 @@
 add_subdirectory(ASTDiff)
 
 add_clang_library(clangTooling
+  AllTUsExecution.cpp
   ArgumentsAdjusters.cpp
   CommonOptionsParser.cpp
   CompilationDatabase.cpp
Index: lib/Tooling/AllTUsExecution.cpp
===
--- lib/Tooling/AllTUsExecution.cpp
+++ lib/Tooling/AllTUsExecution.cpp
@@ -0,0 +1,165 @@
+//===- lib/Tooling/AllTUsExecution.cpp - Execute actions on all TUs. --===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed un

r321864 - Add a tool executor that runs actions on all TUs in the compilation database.

2018-01-05 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Fri Jan  5 02:32:16 2018
New Revision: 321864

URL: http://llvm.org/viewvc/llvm-project?rev=321864&view=rev
Log:
Add a tool executor that runs actions on all TUs in the compilation database.

Summary: Tool results are deduplicated by the result key.

Reviewers: hokein

Subscribers: klimek, mgorny, cfe-commits

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

Added:
cfe/trunk/include/clang/Tooling/AllTUsExecution.h
cfe/trunk/lib/Tooling/AllTUsExecution.cpp
Modified:
cfe/trunk/lib/Tooling/CMakeLists.txt
cfe/trunk/lib/Tooling/Execution.cpp
cfe/trunk/unittests/Tooling/ExecutionTest.cpp

Added: cfe/trunk/include/clang/Tooling/AllTUsExecution.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/AllTUsExecution.h?rev=321864&view=auto
==
--- cfe/trunk/include/clang/Tooling/AllTUsExecution.h (added)
+++ cfe/trunk/include/clang/Tooling/AllTUsExecution.h Fri Jan  5 02:32:16 2018
@@ -0,0 +1,76 @@
+//===--- AllTUsExecution.h - Execute actions on all TUs. -*- C++ 
*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+//  This file defines a tool executor that runs given actions on all TUs in the
+//  compilation database. Tool results are deuplicated by the result key.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLING_ALLTUSEXECUTION_H
+#define LLVM_CLANG_TOOLING_ALLTUSEXECUTION_H
+
+#include "clang/Tooling/ArgumentsAdjusters.h"
+#include "clang/Tooling/Execution.h"
+
+namespace clang {
+namespace tooling {
+
+/// \brief Executes given frontend actions on all files/TUs in the compilation
+/// database. The final results will be deduplicated by the result key.
+class AllTUsToolExecutor : public ToolExecutor {
+public:
+  static const char *ExecutorName;
+
+  /// \brief Init with \p CompilationDatabase.
+  /// This uses \p ThreadCount threads to exececute the actions on all files in
+  /// parallel. If \p ThreadCount is 0, this uses `llvm::hardware_concurrency`.
+  AllTUsToolExecutor(const CompilationDatabase &Compilations,
+ unsigned ThreadCount,
+ std::shared_ptr PCHContainerOps =
+ std::make_shared());
+
+  /// \brief Init with \p CommonOptionsParser. This is expected to be used by
+  /// `createExecutorFromCommandLineArgs` based on commandline options.
+  ///
+  /// The executor takes ownership of \p Options.
+  AllTUsToolExecutor(CommonOptionsParser Options, unsigned ThreadCount,
+ std::shared_ptr PCHContainerOps =
+ std::make_shared());
+
+  StringRef getExecutorName() const override { return ExecutorName; }
+
+  using ToolExecutor::execute;
+
+  llvm::Error
+  execute(llvm::ArrayRef<
+  std::pair, ArgumentsAdjuster>>
+  Actions) override;
+
+  ExecutionContext *getExecutionContext() override { return &Context; };
+
+  ToolResults *getToolResults() override { return Results.get(); }
+
+  void mapVirtualFile(StringRef FilePath, StringRef Content) override {
+OverlayFiles[FilePath] = Content;
+  }
+
+private:
+  // Used to store the parser when the executor is initialized with parser.
+  llvm::Optional OptionsParser;
+  const CompilationDatabase &Compilations;
+  std::unique_ptr Results;
+  ExecutionContext Context;
+  llvm::StringMap OverlayFiles;
+  unsigned ThreadCount;
+};
+
+} // end namespace tooling
+} // end namespace clang
+
+#endif // LLVM_CLANG_TOOLING_ALLTUSEXECUTION_H

Added: cfe/trunk/lib/Tooling/AllTUsExecution.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/AllTUsExecution.cpp?rev=321864&view=auto
==
--- cfe/trunk/lib/Tooling/AllTUsExecution.cpp (added)
+++ cfe/trunk/lib/Tooling/AllTUsExecution.cpp Fri Jan  5 02:32:16 2018
@@ -0,0 +1,165 @@
+//===- lib/Tooling/AllTUsExecution.cpp - Execute actions on all TUs. 
--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/Tooling/AllTUsExecution.h"
+#include "clang/Tooling/ToolExecutorPluginRegistry.h"
+#include "llvm/Support/ThreadPool.h"
+
+namespace clang {
+namespace tooling {
+
+const char *AllTUsToolExecutor::ExecutorName = "AllTUsToolExecutor";
+
+namespace {
+llvm::Error make_string_error(const llvm::Twine &Message) {
+  return llvm::make_error(Message,
+ llvm::inconvertibleErrorCode());
+}
+
+ArgumentsAdjust

[PATCH] D41759: [clangd] Catch more symbols in SymbolCollector.

2018-01-05 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: ilya-biryukov.
Herald added a subscriber: klimek.

We currently only collect external-linkage symbols in the collector,
which results in missing some typical symbols (like no-linkage type alias 
symbols).

This patch relaxes the constraint a bit to allow collecting more symbols.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41759

Files:
  clangd/index/SymbolCollector.cpp
  unittests/clangd/SymbolCollectorTests.cpp


Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -29,6 +29,7 @@
 using testing::Eq;
 using testing::Field;
 using testing::UnorderedElementsAre;
+using testing::UnorderedElementsAreArray;
 
 // GMock helpers for matching Symbol.
 MATCHER_P(QName, Name, "") {
@@ -97,16 +98,53 @@
 };
 void f1();
 inline void f2() {}
+static const int KInt = 2;
+const char* kStr = "123";
   )";
   const std::string Main = R"(
 namespace {
 void ff() {} // ignore
 }
+
 void f1() {}
+
+namespace foo {
+// Type alias
+typedef int int32;
+using int32_t = int32;
+
+// Variable
+int v1;
+
+// Namespace
+namespace bar {
+int v2;
+}
+// Namespace alias
+namespace baz = bar;
+
+// FIXME: using declaration is not supported as the IndexAction will ignore
+// implicit declarations (the implicit using shadow declaration) by 
default,
+// and there is no way to customize this behavior at the moment.
+using bar::v2;
+} // namespace foo
   )";
   runSymbolCollector(Header, Main);
-  EXPECT_THAT(Symbols, UnorderedElementsAre(QName("Foo"), QName("Foo::f"),
-QName("f1"), QName("f2")));
+  EXPECT_THAT(Symbols,
+  UnorderedElementsAreArray(
+  {QName("Foo"),
+   QName("Foo::f"),
+   QName("f1"),
+   QName("f2"),
+   QName("KInt"),
+   QName("kStr"),
+   QName("foo"),
+   QName("foo::bar"),
+   QName("foo::int32"),
+   QName("foo::int32_t"),
+   QName("foo::v1"),
+   QName("foo::bar::v2"),
+   QName("foo::baz")}));
 }
 
 TEST_F(SymbolCollectorTest, YAMLConversions) {
Index: clangd/index/SymbolCollector.cpp
===
--- clangd/index/SymbolCollector.cpp
+++ clangd/index/SymbolCollector.cpp
@@ -80,8 +80,13 @@
 return true;
 
   if (const NamedDecl *ND = llvm::dyn_cast(D)) {
-// FIXME: Should we include the internal linkage symbols?
-if (!ND->hasExternalFormalLinkage() || ND->isInAnonymousNamespace())
+// FIXME: figure out a way to handle internal linkage symbols (e.g. static
+// variables, function) defined in the .cc files.
+// In real world projects, we have a relatively large set of header files
+// that define static variables (like "static const int A = 1;"), we still
+// want to collect these symbols, although they cause potential ODR
+// violations.
+if (ND->isInAnonymousNamespace())
   return true;
 
 llvm::SmallString<128> USR;


Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -29,6 +29,7 @@
 using testing::Eq;
 using testing::Field;
 using testing::UnorderedElementsAre;
+using testing::UnorderedElementsAreArray;
 
 // GMock helpers for matching Symbol.
 MATCHER_P(QName, Name, "") {
@@ -97,16 +98,53 @@
 };
 void f1();
 inline void f2() {}
+static const int KInt = 2;
+const char* kStr = "123";
   )";
   const std::string Main = R"(
 namespace {
 void ff() {} // ignore
 }
+
 void f1() {}
+
+namespace foo {
+// Type alias
+typedef int int32;
+using int32_t = int32;
+
+// Variable
+int v1;
+
+// Namespace
+namespace bar {
+int v2;
+}
+// Namespace alias
+namespace baz = bar;
+
+// FIXME: using declaration is not supported as the IndexAction will ignore
+// implicit declarations (the implicit using shadow declaration) by default,
+// and there is no way to customize this behavior at the moment.
+using bar::v2;
+} // namespace foo
   )";
   runSymbolCollector(Header, Main);
-  EXPECT_THAT(Symbols, UnorderedElementsAre(QName("Foo"), QName("Foo::f"),
-QName("f1"), QName("f2")));
+  EXPECT_THAT(Symbols,
+  UnorderedElementsAreArray(
+  {QName("Foo"),
+   QName("Foo::f"),
+   QName("f1"),
+   QName("f2"),
+   QName("KInt"),
+  

[PATCH] D41730: [clangd] Use ToolExecutor to write the global-symbol-builder tool.

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



Comment at: clangd/index/SymbolYAML.cpp:140
   llvm::yaml::Output Yout(OS);
   for (Symbol S : Symbols) // copy: Yout<< requires mutability.
 Yout<< S;

hokein wrote:
> The function could be simplified by using the SymbolToYAML below.
> 
> ```
> std::string Str;
> for (const Symbol& S : Symbols) {
>Str += SymbolToYAML(S);
> }
> ```
This saves two lines of code but would regress the performance, so I am 
inclined to the current approach.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41730



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


[PATCH] D41730: [clangd] Use ToolExecutor to write the global-symbol-builder tool.

2018-01-05 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 128723.
ioeric marked 2 inline comments as done.
ioeric added a comment.

Address review comments.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41730

Files:
  clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
  clangd/index/SymbolCollector.cpp
  clangd/index/SymbolCollector.h
  clangd/index/SymbolYAML.cpp
  clangd/index/SymbolYAML.h
  unittests/clangd/SymbolCollectorTests.cpp

Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -147,7 +147,7 @@
   UnorderedElementsAre(QName("clang::Foo2")));
 
   std::string ConcatenatedYAML =
-  SymbolToYAML(Symbols1) + SymbolToYAML(Symbols2);
+  SymbolsToYAML(Symbols1) + SymbolsToYAML(Symbols2);
   auto ConcatenatedSymbols = SymbolFromYAML(ConcatenatedYAML);
   EXPECT_THAT(ConcatenatedSymbols,
   UnorderedElementsAre(QName("clang::Foo1"),
Index: clangd/index/SymbolYAML.h
===
--- clangd/index/SymbolYAML.h
+++ clangd/index/SymbolYAML.h
@@ -27,9 +27,13 @@
 // Read symbols from a YAML-format string.
 SymbolSlab SymbolFromYAML(llvm::StringRef YAMLContent);
 
+// Convert a single symbol to YAML-format string.
+// The YAML result is safe to concatenate.
+std::string SymbolToYAML(Symbol Sym);
+
 // Convert symbols to a YAML-format string.
 // The YAML result is safe to concatenate if you have multiple symbol slabs.
-std::string SymbolToYAML(const SymbolSlab& Symbols);
+std::string SymbolsToYAML(const SymbolSlab& Symbols);
 
 } // namespace clangd
 } // namespace clang
Index: clangd/index/SymbolYAML.cpp
===
--- clangd/index/SymbolYAML.cpp
+++ clangd/index/SymbolYAML.cpp
@@ -133,14 +133,22 @@
   return std::move(Syms).build();
 }
 
-std::string SymbolToYAML(const SymbolSlab& Symbols) {
+std::string SymbolsToYAML(const SymbolSlab& Symbols) {
   std::string Str;
   llvm::raw_string_ostream OS(Str);
   llvm::yaml::Output Yout(OS);
   for (Symbol S : Symbols) // copy: Yout<< requires mutability.
 Yout<< S;
   return OS.str();
 }
 
+std::string SymbolToYAML(Symbol Sym) {
+  std::string Str;
+  llvm::raw_string_ostream OS(Str);
+  llvm::yaml::Output Yout(OS);
+  Yout << Sym;
+  return OS.str();
+}
+
 } // namespace clangd
 } // namespace clang
Index: clangd/index/SymbolCollector.h
===
--- clangd/index/SymbolCollector.h
+++ clangd/index/SymbolCollector.h
@@ -10,18 +10,23 @@
 #include "Index.h"
 #include "clang/Index/IndexDataConsumer.h"
 #include "clang/Index/IndexSymbol.h"
+#include "clang/Tooling/Execution.h"
 
 namespace clang {
 namespace clangd {
 
-// Collect all symbols from an AST.
-//
-// Clients (e.g. clangd) can use SymbolCollector together with
-// index::indexTopLevelDecls to retrieve all symbols when the source file is
-// changed.
+/// \brief Collect all symbols from an AST.
+///
+/// Clients (e.g. clangd) can use SymbolCollector together with
+/// index::indexTopLevelDecls to retrieve all symbols when the source file is
+/// changed.
 class SymbolCollector : public index::IndexDataConsumer {
 public:
-  SymbolCollector() = default;
+  /// \brief If Context is provided, collected symbols will also be reported via
+  /// the execution context with symbol IDs as keys and yamlized symbols as
+  /// values.
+  SymbolCollector(tooling::ExecutionContext *Context = nullptr)
+  : ExecutionCtx(Context) {}
 
   bool
   handleDeclOccurence(const Decl *D, index::SymbolRoleSet Roles,
@@ -34,6 +39,7 @@
 private:
   // All Symbols collected from the AST.
   SymbolSlab::Builder Symbols;
+  tooling::ExecutionContext *ExecutionCtx;
 };
 
 } // namespace clangd
Index: clangd/index/SymbolCollector.cpp
===
--- clangd/index/SymbolCollector.cpp
+++ clangd/index/SymbolCollector.cpp
@@ -8,6 +8,7 @@
 //===--===//
 
 #include "SymbolCollector.h"
+#include "index/SymbolYAML.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
@@ -106,6 +107,12 @@
 S.Name = ScopeAndName.second;
 S.SymInfo = index::getSymbolInfo(D);
 S.CanonicalDeclaration = Location;
+if (ExecutionCtx) {
+  std::string IDStr;
+  llvm::raw_string_ostream OS(IDStr);
+  OS << S.ID;
+  ExecutionCtx->reportResult(OS.str(), SymbolToYAML(S));
+}
 Symbols.insert(S);
   }
 
Index: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
===
--- clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
+++ clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
@@ -17,15 +17,15 @@
 #include "index/SymbolCollector.h"
 #

[PATCH] D41760: Introduce __builtin_load_no_speculate

2018-01-05 Thread Kristof Beyls via Phabricator via cfe-commits
kristof.beyls created this revision.
kristof.beyls added a reviewer: olista01.
Herald added subscribers: aheejin, javed.absar, dschuff, jfb, aemerson.

Recently, Google Project Zero disclosed several classes of attack
against speculative execution. One of these, known as variant-1
(CVE-2017-5753), allows explicit bounds checks to be bypassed under
speculation, providing an arbitrary read gadget. Further details can
be found on the GPZ blog [1].

This patch adds a new builtin function that provides a mechanism for
limiting speculation by a CPU after a bounds-checked memory access.
This patch provides the clang-side of the needed functionality; there is
also an llvm-side patch this patch is dependent on.
We've tried to design this in such a way that it can be used for any
target where this might be necessary.  The patch provides a generic
implementation of the builtin, with most of the target-specific
support in the LLVM counter part to this clang patch.

The signature of the new, polymorphic, builtin is:

T __builtin_load_no_speculate(const volatile T *ptr,

  const volatile void *lower,
  const volatile void *upper,
  T failval,
  const volatile void *cmpptr)

T can be any integral type (signed or unsigned char, int, short, long,
etc) or any pointer type.

The builtin implements the following logical behaviour:

inline T __builtin_load_no_speculate(const volatile T *ptr,

 const volatile void *lower,
 const volatile void *upper, T failval,
 const volatile void *cmpptr) {
  T result;
  if (cmpptr >= lower && cmpptr < upper)
result = *ptr;
  else
result = failval;
  return result;

}

In addition, the builtin ensures that future speculation using *ptr may
only continue iff cmpptr lies within the bounds specified.

To make the builtin easier to use, the final two arguments can both be
omitted: failval will default to 0 in this case and if cmpptr is omitted
ptr will be used for expansions of the range check.  In addition, either
lower or upper (but not both) may be a literal NULL and the expansion
will then ignore that boundary condition when expanding.

This also introduces the predefined pre-processor macro
__HAVE_LOAD_NO_SPECULATE, that allows users to check if their version of
the compiler supports this intrinsic.

The builtin is defined for all architectures, even if they do not
provide a mechanism for inhibiting speculation.  If they do not have
such support the compiler will emit a warning and simply implement the
architectural behavior of the builtin.

This patch can be used with the header file that Arm recently
published here: https://github.com/ARM-software/speculation-barrier.

Kernel patches are also being developed, eg:
https://lkml.org/lkml/2018/1/3/754.  The intent is that eventually
code like this will be able to use support directly from the compiler
in a portable manner.

Similar patches are also being developed for GCC and have been posted to
their development list, see
https://gcc.gnu.org/ml/gcc-patches/2018-01/msg00205.html

[1] More information on the topic can be found here:
https://googleprojectzero.blogspot.co.uk/2018/01/reading-privileged-memory-with-side.html
Arm specific information can be found here:
https://www.arm.com/security-update


https://reviews.llvm.org/D41760

Files:
  include/clang/Basic/Builtins.def
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TargetInfo.h
  include/clang/Sema/Sema.h
  lib/Basic/Targets/AArch64.cpp
  lib/Basic/Targets/AArch64.h
  lib/Basic/Targets/ARM.cpp
  lib/Basic/Targets/ARM.h
  lib/CodeGen/CGBuiltin.cpp
  lib/Frontend/InitPreprocessor.cpp
  lib/Sema/SemaChecking.cpp
  test/CodeGen/builtin-load-no-speculate.c
  test/Preprocessor/init.c
  test/Sema/builtin-load-no-speculate-c.c
  test/Sema/builtin-load-no-speculate-cxx.cpp
  test/Sema/builtin-load-no-speculate-target-not-supported.c

Index: test/Sema/builtin-load-no-speculate-target-not-supported.c
===
--- /dev/null
+++ test/Sema/builtin-load-no-speculate-target-not-supported.c
@@ -0,0 +1,6 @@
+// REQUIRES: arm-registered-target
+// RUN: %clang_cc1 -triple thumbv8m.baseline -fsyntax-only -verify %s
+
+void test_valid(int *ptr, int *lower, int *upper, int failval, int *cmpptr) {
+  __builtin_load_no_speculate(ptr, lower, upper, failval, cmpptr); // expected-warning {{this target does not support anti-speculation operations. Your program will still execute correctly, but speculation will not be inhibited}}
+}
Index: test/Sema/builtin-load-no-speculate-cxx.cpp
===
--- /dev/null
+++ test/Sema/builtin-load-no-speculate-cxx.cpp
@@ -0,0 +1,144 @@
+// REQUIRES: arm-registered-target
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64 -x c++ -std=c++11 -DENABLE_ERRORS -verify %s
+//

[PATCH] D40445: [C++17] Allow an empty expression in an if init statement

2018-01-05 Thread Nicolas Lesser via Phabricator via cfe-commits
Rakete updated this revision to Diff 128729.
Rakete added a comment.

Addressed review comments. I'll write up a patch in the next coming days then :)


https://reviews.llvm.org/D40445

Files:
  lib/Parse/ParseExprCXX.cpp
  test/CXX/stmt.stmt/stmt.select/p3.cpp

Index: test/CXX/stmt.stmt/stmt.select/p3.cpp
===
--- test/CXX/stmt.stmt/stmt.select/p3.cpp
+++ test/CXX/stmt.stmt/stmt.select/p3.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++1z -Wc++14-compat -verify %s -DCPP17
 
 int f();
 
@@ -10,10 +11,68 @@
   }
 }
 
-
 void h() {
   if (int x = f()) // expected-note 2{{previous definition}}
 int x; // expected-error{{redefinition of 'x'}}
   else
 int x; // expected-error{{redefinition of 'x'}}
 }
+
+void ifInitStatement() {
+  int Var = 0;
+
+  if (int I = 0; true) {}
+  if (Var + Var; true) {}
+  if (; true) {}
+#ifdef CPP17
+  // expected-warning@-4 {{if initialization statements are incompatible with C++ standards before C++17}}
+  // expected-warning@-4 {{if initialization statements are incompatible with C++ standards before C++17}}
+  // expected-warning@-4 {{if initialization statements are incompatible with C++ standards before C++17}}
+#else
+  // expected-warning@-8 {{'if' initialization statements are a C++17 extension}}
+  // expected-warning@-8 {{'if' initialization statements are a C++17 extension}}
+  // expected-warning@-8 {{'if' initialization statements are a C++17 extension}}
+#endif
+}
+
+void switchInitStatement() {
+  int Var = 0;
+
+  switch (int I = 0; Var) {}
+  switch (Var + Var; Var) {}
+  switch (; Var) {}
+#ifdef CPP17
+  // expected-warning@-4 {{switch initialization statements are incompatible with C++ standards before C++17}}
+  // expected-warning@-4 {{switch initialization statements are incompatible with C++ standards before C++17}}
+  // expected-warning@-4 {{switch initialization statements are incompatible with C++ standards before C++17}}
+#else
+  // expected-warning@-8 {{'switch' initialization statements are a C++17 extension}}
+  // expected-warning@-8 {{'switch' initialization statements are a C++17 extension}}
+  // expected-warning@-8 {{'switch' initialization statements are a C++17 extension}}
+#endif
+}
+
+// TODO: Better diagnostics for while init statements.
+void whileInitStatement() {
+  while (int I = 10; I--); // expected-error {{expected ')'}}
+  // expected-note@-1 {{to match this '('}}
+  // expected-error@-2 {{use of undeclared identifier 'I'}}
+
+  int Var = 10;
+  while (Var + Var; Var--) {} // expected-error {{expected ')'}}
+  // expected-note@-1 {{to match this '('}}
+  // expected-error@-2 {{expected ';' after expression}}
+  // expected-error@-3 {{expected expression}}
+  // expected-warning@-4 {{while loop has empty body}}
+  // expected-note@-5 {{put the semicolon on a separate line to silence this warning}}
+}
+
+// TODO: This is needed because clang can't seem to diagnose invalid syntax after the
+// last loop above. It would be nice to remove this.
+void whileInitStatement2() {
+  while (; false) {} // expected-error {{expected expression}}
+  // expected-warning@-1 {{expression result unused}}
+  // expected-error@-2 {{expected ';' after expression}}
+  // expected-error@-3 {{expected expression}}
+}
+
Index: lib/Parse/ParseExprCXX.cpp
===
--- lib/Parse/ParseExprCXX.cpp
+++ lib/Parse/ParseExprCXX.cpp
@@ -1742,17 +1742,34 @@
   ParsedAttributesWithRange attrs(AttrFactory);
   MaybeParseCXX11Attributes(attrs);
 
+  const auto WarnOnInit = [this, &CK] {
+Diag(Tok.getLocation(), getLangOpts().CPlusPlus17
+? diag::warn_cxx14_compat_init_statement
+: diag::ext_init_statement)
+<< (CK == Sema::ConditionKind::Switch);
+  };
+
   // Determine what kind of thing we have.
   switch (isCXXConditionDeclarationOrInitStatement(InitStmt)) {
   case ConditionOrInitStatement::Expression: {
 ProhibitAttributes(attrs);
 
+// We can have an empty expression here.
+//   if (; true);
+if (InitStmt && Tok.is(tok::semi)) {
+  WarnOnInit();
+  SourceLocation SemiLoc = ConsumeToken();
+  *InitStmt = Actions.ActOnNullStmt(SemiLoc);
+  return ParseCXXCondition(nullptr, Loc, CK);
+}
+
 // Parse the expression.
 ExprResult Expr = ParseExpression(); // expression
 if (Expr.isInvalid())
   return Sema::ConditionError();
 
 if (InitStmt && Tok.is(tok::semi)) {
+  WarnOnInit();
   *InitStmt = Actions.ActOnExprStmt(Expr.get());
   ConsumeToken();
   return ParseCXXCondition(nullptr, Loc, CK);
@@ -1762,10 +1779,7 @@
   }
 
   case ConditionOrInitStatement::InitStmtDecl: {
-Diag(Tok.getLocation(), getLangOpts().CPlusPlus17
-? diag::warn_cxx14_compat_init_statement
- 

[PATCH] D41733: [Driver] Suggest correctly spelled driver options

2018-01-05 Thread Jonathan Roelofs via Phabricator via cfe-commits
jroelofs added inline comments.



Comment at: lib/Driver/Driver.cpp:191
 if (A->getOption().hasFlag(options::Unsupported)) {
-  Diag(diag::err_drv_unsupported_opt) << A->getAsString(Args);
-  ContainsError |= Diags.getDiagnosticLevel(diag::err_drv_unsupported_opt,
-SourceLocation()) >
+  unsigned DiagID;
+  auto ArgString = A->getAsString(Args);

modocache wrote:
> jroelofs wrote:
> > No need for this variable.
> There's a call below to `Diags.getDiagnosticsLevel`, which takes this ID as 
> an argument. Are you suggesting I leave that line alone, and have it use the 
> diagnostic level of `err_drv_unsupported_opt`, even if 
> `err_drv_unsupported_opt_with_suggestion` is actually emitted here? That 
> seems reasonable to me, but just want to make sure that's what you had in 
> mind.
Oh, I didn't see that use... never mind.


Repository:
  rC Clang

https://reviews.llvm.org/D41733



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


[PATCH] D41448: Fix counting parameters/arguments for ObjC.

2018-01-05 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

Can we have tests please?


Repository:
  rC Clang

https://reviews.llvm.org/D41448



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


[PATCH] D35110: [Analyzer] Constraint Manager Negates Difference

2018-01-05 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.
Herald added subscribers: a.sidorin, rnkovacs, szepet.

This one is not blocked anymore since I removed the dependency.


https://reviews.llvm.org/D35110



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


[PATCH] D41733: [Driver] Suggest correctly spelled driver options

2018-01-05 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: test/Frontend/unknown-arg.c:3
+// RUN: FileCheck %s
+// RUN: not %clang_cc1 %s --hel[ -### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=DID-YOU-MEAN

Could we also make sure that things passed with `-Xclang` are also handled?


Repository:
  rC Clang

https://reviews.llvm.org/D41733



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


Re: r321816 - [OPENMP] Add debug info for generated functions.

2018-01-05 Thread Alexey Bataev via cfe-commits
Hi Jonas, I don't think it is necessary. It is better to backport my 2
next patches with bug fixes.

Best regards,
Alexey

04.01.2018 15:54, Jonas Hahnfeld пишет:
> Hi Alexey,
>
> should this change be backported to 6.0?
>
> Regards,
> Jonas
>
> Am 2018-01-04 20:45, schrieb Alexey Bataev via cfe-commits:
>> Author: abataev
>> Date: Thu Jan  4 11:45:16 2018
>> New Revision: 321816
>>
>> URL:
>> https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%3Frev%3D321816%26view%3Drev&data=02%7C01%7C%7Ceb0f898e6fe040bc1a4208d553b566ae%7C84df9e7fe9f640afb435%7C1%7C0%7C636506960925164662&sdata=g3DdxRoQ%2B8RbIORsLLfEJAAP4Zn2Orsshr6PwIthnQw%3D&reserved=0
>> Log:
>> [OPENMP] Add debug info for generated functions.
>>
>> Most of the generated functions for the OpenMP were generated with
>> disabled debug info. Patch fixes this for better user experience.
>>
>> Modified:
>>     cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
>>     cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
>>     cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
>>     cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
>>     cfe/trunk/test/OpenMP/target_parallel_debug_codegen.cpp
>>
>> Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
>> URL:
>> https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%2Fcfe%2Ftrunk%2Flib%2FCodeGen%2FCGOpenMPRuntime.cpp%3Frev%3D321816%26r1%3D321815%26r2%3D321816%26view%3Ddiff&data=02%7C01%7C%7Ceb0f898e6fe040bc1a4208d553b566ae%7C84df9e7fe9f640afb435%7C1%7C0%7C636506960925164662&sdata=2ppjOPjnpev4zlt1Fh6ByuYdotTiSr0Z1WyvBa8WWHo%3D&reserved=0
>>
>> ==
>>
>> --- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
>> +++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Thu Jan  4 11:45:16 2018
>> @@ -1216,7 +1216,8 @@ emitCombinerOrInitializer(CodeGenModule
>>    CodeGenFunction CGF(CGM);
>>    // Map "T omp_in;" variable to "*omp_in_parm" value in all
>> expressions.
>>    // Map "T omp_out;" variable to "*omp_out_parm" value in all
>> expressions.
>> -  CGF.StartFunction(GlobalDecl(), C.VoidTy, Fn, FnInfo, Args);
>> +  CGF.StartFunction(GlobalDecl(), C.VoidTy, Fn, FnInfo, Args,
>> In->getLocation(),
>> +    Out->getLocation());
>>    CodeGenFunction::OMPPrivateScope Scope(CGF);
>>    Address AddrIn = CGF.GetAddrOfLocalVar(&OmpInParm);
>>    Scope.addPrivate(In, [&CGF, AddrIn, PtrTy]() -> Address {
>> @@ -2383,7 +2384,8 @@ llvm::Function *CGOpenMPRuntime::emitThr
>>    // threadprivate copy of the variable VD
>>    CodeGenFunction CtorCGF(CGM);
>>    FunctionArgList Args;
>> -  ImplicitParamDecl Dst(CGM.getContext(),
>> CGM.getContext().VoidPtrTy,
>> +  ImplicitParamDecl Dst(CGM.getContext(), /*DC=*/nullptr, Loc,
>> +    /*Id=*/nullptr, CGM.getContext().VoidPtrTy,
>>  ImplicitParamDecl::Other);
>>    Args.push_back(&Dst);
>>
>> @@ -2393,13 +2395,13 @@ llvm::Function *CGOpenMPRuntime::emitThr
>>    auto Fn = CGM.CreateGlobalInitOrDestructFunction(
>>    FTy, ".__kmpc_global_ctor_.", FI, Loc);
>>    CtorCGF.StartFunction(GlobalDecl(),
>> CGM.getContext().VoidPtrTy, Fn, FI,
>> -    Args, SourceLocation());
>> +    Args, Loc, Loc);
>>    auto ArgVal = CtorCGF.EmitLoadOfScalar(
>>    CtorCGF.GetAddrOfLocalVar(&Dst), /*Volatile=*/false,
>>    CGM.getContext().VoidPtrTy, Dst.getLocation());
>>    Address Arg = Address(ArgVal, VDAddr.getAlignment());
>> -  Arg = CtorCGF.Builder.CreateElementBitCast(Arg,
>> -
>> CtorCGF.ConvertTypeForMem(ASTTy));
>> +  Arg = CtorCGF.Builder.CreateElementBitCast(
>> +  Arg, CtorCGF.ConvertTypeForMem(ASTTy));
>>    CtorCGF.EmitAnyExprToMem(Init, Arg,
>> Init->getType().getQualifiers(),
>>     /*IsInitializer=*/true);
>>    ArgVal = CtorCGF.EmitLoadOfScalar(
>> @@ -2414,7 +2416,8 @@ llvm::Function *CGOpenMPRuntime::emitThr
>>    // of the variable VD
>>    CodeGenFunction DtorCGF(CGM);
>>    FunctionArgList Args;
>> -  ImplicitParamDecl Dst(CGM.getContext(),
>> CGM.getContext().VoidPtrTy,
>> +  ImplicitParamDecl Dst(CGM.getContext(), /*DC=*/nullptr, Loc,
>> +    /*Id=*/nullptr, CGM.getContext().VoidPtrTy,
>>  ImplicitParamDecl::Other);
>>    Args.push_back(&Dst);
>>
>> @@ -2425,7 +2428,7 @@ llvm::Function *CGOpenMPRuntime::emitThr
>>    FTy, ".__kmpc_global_dtor_.", FI, Loc);
>>    auto NL = ApplyDebugLocation::CreateEmpty(DtorCGF);
>>    DtorCGF.StartFunction(GlobalDecl(), CGM.getContext().VoidTy,
>> Fn, FI, Args,
>> -    SourceLocation());
>> +    Loc, Loc);
>>    // Create a scope with an artificial location for the body of
>> thi

Re: r321816 - [OPENMP] Add debug info for generated functions.

2018-01-05 Thread Alexey Bataev via cfe-commits
Yes, I mean these 2.

-
Best regards,
Alexey Bataev

04.01.2018 16:02, Jonas Hahnfeld пишет:
> You mean r321818 and r321820? I skipped them because they are for
> NVPTX and target directives which aren't fully functional in 6.0
> anyway, right?
> Or patches in the future?
>
> Am 2018-01-04 21:58, schrieb Alexey Bataev:
>> Hi Jonas, I don't think it is necessary. It is better to backport my 2
>> next patches with bug fixes.
>>
>> Best regards,
>> Alexey
>>
>> 04.01.2018 15:54, Jonas Hahnfeld пишет:
>>
>>> Hi Alexey,
>>>
>>> should this change be backported to 6.0?
>>>
>>> Regards,
>>> Jonas
>>>
>>> Am 2018-01-04 20:45, schrieb Alexey Bataev via cfe-commits:
>>>
 Author: abataev
 Date: Thu Jan  4 11:45:16 2018
 New Revision: 321816

 URL:

>>>
>> https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%3Frev%3D321816%26view%3Drev&data=02%7C01%7C%7Ceb0f898e6fe040bc1a4208d553b566ae%7C84df9e7fe9f640afb435%7C1%7C0%7C636506960925164662&sdata=g3DdxRoQ%2B8RbIORsLLfEJAAP4Zn2Orsshr6PwIthnQw%3D&reserved=0
>>
 Log:
 [OPENMP] Add debug info for generated functions.

 Most of the generated functions for the OpenMP were generated with

 disabled debug info. Patch fixes this for better user experience.

 Modified:
 cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
 cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
 cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
 cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
 cfe/trunk/test/OpenMP/target_parallel_debug_codegen.cpp

 Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
 URL:

>>>
>> https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%2Fcfe%2Ftrunk%2Flib%2FCodeGen%2FCGOpenMPRuntime.cpp%3Frev%3D321816%26r1%3D321815%26r2%3D321816%26view%3Ddiff&data=02%7C01%7C%7Ceb0f898e6fe040bc1a4208d553b566ae%7C84df9e7fe9f640afb435%7C1%7C0%7C636506960925164662&sdata=2ppjOPjnpev4zlt1Fh6ByuYdotTiSr0Z1WyvBa8WWHo%3D&reserved=0
>>


>>>
>> ==
>>

 --- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
 +++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Thu Jan  4 11:45:16
 2018
 @@ -1216,7 +1216,8 @@ emitCombinerOrInitializer(CodeGenModule
 CodeGenFunction CGF(CGM);
 // Map "T omp_in;" variable to "*omp_in_parm" value in all
 expressions.
 // Map "T omp_out;" variable to "*omp_out_parm" value in all
 expressions.
 -  CGF.StartFunction(GlobalDecl(), C.VoidTy, Fn, FnInfo, Args);
 +  CGF.StartFunction(GlobalDecl(), C.VoidTy, Fn, FnInfo, Args,
 In->getLocation(),
 +    Out->getLocation());
 CodeGenFunction::OMPPrivateScope Scope(CGF);
 Address AddrIn = CGF.GetAddrOfLocalVar(&OmpInParm);
 Scope.addPrivate(In, [&CGF, AddrIn, PtrTy]() -> Address {
 @@ -2383,7 +2384,8 @@ llvm::Function *CGOpenMPRuntime::emitThr
 // threadprivate copy of the variable VD
 CodeGenFunction CtorCGF(CGM);
 FunctionArgList Args;
 -  ImplicitParamDecl Dst(CGM.getContext(),
 CGM.getContext().VoidPtrTy,
 +  ImplicitParamDecl Dst(CGM.getContext(), /*DC=*/nullptr,
 Loc,
 +    /*Id=*/nullptr,
 CGM.getContext().VoidPtrTy,
 ImplicitParamDecl::Other);
 Args.push_back(&Dst);

 @@ -2393,13 +2395,13 @@ llvm::Function *CGOpenMPRuntime::emitThr
 auto Fn = CGM.CreateGlobalInitOrDestructFunction(
 FTy, ".__kmpc_global_ctor_.", FI, Loc);
 CtorCGF.StartFunction(GlobalDecl(),
 CGM.getContext().VoidPtrTy, Fn, FI,
 -    Args, SourceLocation());
 +    Args, Loc, Loc);
 auto ArgVal = CtorCGF.EmitLoadOfScalar(
 CtorCGF.GetAddrOfLocalVar(&Dst), /*Volatile=*/false,
 CGM.getContext().VoidPtrTy, Dst.getLocation());
 Address Arg = Address(ArgVal, VDAddr.getAlignment());
 -  Arg = CtorCGF.Builder.CreateElementBitCast(Arg,
 -
 CtorCGF.ConvertTypeForMem(ASTTy));
 +  Arg = CtorCGF.Builder.CreateElementBitCast(
 +  Arg, CtorCGF.ConvertTypeForMem(ASTTy));
 CtorCGF.EmitAnyExprToMem(Init, Arg,
 Init->getType().getQualifiers(),
 /*IsInitializer=*/true);
 ArgVal = CtorCGF.EmitLoadOfScalar(
 @@ -2414,7 +2416,8 @@ llvm::Function *CGOpenMPRuntime::emitThr
 // of the variable VD
 CodeGenFunction DtorCGF(CGM);
 FunctionArgList Args;
 -  ImplicitParamDecl Dst(CGM.getContext(),
 CGM.getContext().VoidPtrTy,
 +  ImplicitParamDecl Dst(CGM.getContext(), /*DC=*/nullptr,
 Loc,
 +    /*Id=*/nullptr,
 CGM.getContext().VoidPtrTy,
 ImplicitParamDecl::Other);
 Args.push_back(&Dst);

 @@ -2425,7 +2428,7 @@ llvm::Function *CGOpenMPRuntime::emitThr
 FTy, ".__kmpc_global_dtor_.", FI, Loc);
 auto NL = ApplyDebugLocation

r321854 - NFC.

2018-01-05 Thread Evgeny Stupachenko via cfe-commits
Author: evstupac
Date: Thu Jan  4 18:22:52 2018
New Revision: 321854

URL: http://llvm.org/viewvc/llvm-project?rev=321854&view=rev
Log:
NFC.
The patch fixes r321395, that cuased
 -Werror=unused-but-set-variable issue for
 Diagnosed var on prod build.

From: Evgeny Stupachenko 

Modified:
cfe/trunk/lib/Serialization/ASTReader.cpp

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=321854&r1=321853&r2=321854&view=diff
==
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Thu Jan  4 18:22:52 2018
@@ -10660,6 +10660,7 @@ void ASTReader::diagnoseOdrViolations()
   Diagnosed = true;
   break;
 }
+(void)Diagnosed;
 assert(Diagnosed && "Unable to emit ODR diagnostic.");
   }
 }


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


[PATCH] D41764: [libcxx] [cmake] Add a config option LIBCXX_HAS_WIN32_THREADS for enforcing win32 threads

2018-01-05 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.
mstorsjo added reviewers: compnerd, EricWF.
Herald added a subscriber: mgorny.

This allows keeping libcxx using win32 threads even if a version of pthread.h 
is installed. This matches the existing cmake option LIBCXX_HAS_PTHREAD_API.


Repository:
  rCXX libc++

https://reviews.llvm.org/D41764

Files:
  CMakeLists.txt
  include/__config_site.in


Index: include/__config_site.in
===
--- include/__config_site.in
+++ include/__config_site.in
@@ -23,6 +23,7 @@
 #cmakedefine _LIBCPP_HAS_MUSL_LIBC
 #cmakedefine _LIBCPP_HAS_THREAD_API_PTHREAD
 #cmakedefine _LIBCPP_HAS_THREAD_API_EXTERNAL
+#cmakedefine _LIBCPP_HAS_THREAD_API_WIN32
 #cmakedefine _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL
 #cmakedefine _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS
 #cmakedefine _LIBCPP_NO_VCRUNTIME
Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -202,6 +202,7 @@
This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON)
 option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" 
OFF)
 option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread 
API" OFF)
+option(LIBCXX_HAS_WIN32_THREADS "Ignore auto-detection and force use of win32 
threads" OFF)
 option(LIBCXX_HAS_EXTERNAL_THREAD_API
   "Build libc++ with an externalized threading API.
This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF)
@@ -273,6 +274,10 @@
 message(FATAL_ERROR "LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY can only be set "
 "to ON when LIBCXX_ENABLE_THREADS is also set to ON.")
   endif()
+  if(LIBCXX_HAS_WIN32_THREADS)
+message(FATAL_ERROR "LIBCXX_HAS_WIN32_THREADS can only be set to ON"
+" when LIBCXX_ENABLE_THREADS is also set to ON.")
+  endif()
 
 endif()
 
@@ -287,6 +292,19 @@
 "and LIBCXX_HAS_PTHREAD_API cannot be both"
 "set to ON at the same time.")
   endif()
+  if (LIBCXX_HAS_WIN32_THREADS)
+message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
+"and LIBCXX_HAS_WIN32_THREADS cannot be both"
+"set to ON at the same time.")
+  endif()
+endif()
+
+if (LIBCXX_HAS_PTHREAD_API)
+  if (LIBCXX_HAS_WIN32_THREADS)
+message(FATAL_ERROR "The options LIBCXX_HAS_PTHREAD_API"
+"and LIBCXX_HAS_WIN32_THREADS cannot be both"
+"set to ON at the same time.")
+  endif()
 endif()
 
 # Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE
@@ -613,6 +631,7 @@
 
 config_define_if(LIBCXX_HAS_PTHREAD_API _LIBCPP_HAS_THREAD_API_PTHREAD)
 config_define_if(LIBCXX_HAS_EXTERNAL_THREAD_API 
_LIBCPP_HAS_THREAD_API_EXTERNAL)
+config_define_if(LIBCXX_HAS_WIN32_THREADS _LIBCPP_HAS_THREAD_API_WIN32)
 config_define_if(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY 
_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL)
 config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC)
 config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME)


Index: include/__config_site.in
===
--- include/__config_site.in
+++ include/__config_site.in
@@ -23,6 +23,7 @@
 #cmakedefine _LIBCPP_HAS_MUSL_LIBC
 #cmakedefine _LIBCPP_HAS_THREAD_API_PTHREAD
 #cmakedefine _LIBCPP_HAS_THREAD_API_EXTERNAL
+#cmakedefine _LIBCPP_HAS_THREAD_API_WIN32
 #cmakedefine _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL
 #cmakedefine _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS
 #cmakedefine _LIBCPP_NO_VCRUNTIME
Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -202,6 +202,7 @@
This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON)
 option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF)
 option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF)
+option(LIBCXX_HAS_WIN32_THREADS "Ignore auto-detection and force use of win32 threads" OFF)
 option(LIBCXX_HAS_EXTERNAL_THREAD_API
   "Build libc++ with an externalized threading API.
This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF)
@@ -273,6 +274,10 @@
 message(FATAL_ERROR "LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY can only be set "
 "to ON when LIBCXX_ENABLE_THREADS is also set to ON.")
   endif()
+  if(LIBCXX_HAS_WIN32_THREADS)
+message(FATAL_ERROR "LIBCXX_HAS_WIN32_THREADS can only be set to ON"
+" when LIBCXX_ENABLE_THREADS is also set to ON.")
+  endif()
 
 endif()
 
@@ -287,6 +292,19 @@
 "and LIBCXX_HAS_PTHREAD_API cannot be both"
 "set to ON at the same time.")
   endif()
+  if (LIBCXX_HAS_WIN32_THREADS)
+message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
+"and LIBCXX_HAS_WIN32_

[PATCH] D41733: [Driver] Suggest correctly spelled driver options

2018-01-05 Thread Brian Gesiak via Phabricator via cfe-commits
modocache updated this revision to Diff 128736.
modocache added a comment.

Test -Xclang as well. Thanks, @v.g.vassilev!


Repository:
  rC Clang

https://reviews.llvm.org/D41733

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/Driver/Driver.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/Driver/unknown-arg.c
  test/Driver/unsupported-option.c
  test/Frontend/unknown-arg.c

Index: test/Frontend/unknown-arg.c
===
--- /dev/null
+++ test/Frontend/unknown-arg.c
@@ -0,0 +1,9 @@
+// RUN: not %clang_cc1 %s -E --helium 2>&1 | \
+// RUN: FileCheck %s
+// RUN: not %clang_cc1 %s -E --hel[ 2>&1 | \
+// RUN: FileCheck %s --check-prefix=DID-YOU-MEAN
+// RUN: not %clang %s -E -Xclang --hel[ 2>&1 | \
+// RUN: FileCheck %s --check-prefix=DID-YOU-MEAN
+
+// CHECK: error: unknown argument: '--helium'
+// DID-YOU-MEAN: error: unknown argument '--hel[', did you mean '--help'?
Index: test/Driver/unsupported-option.c
===
--- /dev/null
+++ test/Driver/unsupported-option.c
@@ -0,0 +1,7 @@
+// RUN: not %clang %s --hedonism -### 2>&1 | \
+// RUN: FileCheck %s
+// RUN: not %clang %s --hell -### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=DID-YOU-MEAN
+
+// CHECK: error: unsupported option '--hedonism'
+// DID-YOU-MEAN: error: unsupported option '--hell', did you mean '--help'?
Index: test/Driver/unknown-arg.c
===
--- test/Driver/unknown-arg.c
+++ test/Driver/unknown-arg.c
@@ -1,9 +1,15 @@
 // RUN: not %clang %s -cake-is-lie -%0 -%d - -munknown-to-clang-option -print-stats -funknown-to-clang-option -### 2>&1 | \
 // RUN: FileCheck %s
+// RUN: not %clang %s -stdlibs=foo -hell -### 2>&1 | \
+// RUN: FileCheck %s --check-prefix=DID-YOU-MEAN
 // RUN: %clang_cl -cake-is-lie -%0 -%d - -munknown-to-clang-option -print-stats -funknown-to-clang-option -### -c -- %s 2>&1 | \
 // RUN: FileCheck %s --check-prefix=CL
+// RUN: %clang_cl -Brepo -### -- %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CL-DID-YOU-MEAN
 // RUN: not %clang_cl -cake-is-lie -%0 -%d - -munknown-to-clang-option -print-stats -funknown-to-clang-option -c -Werror=unknown-argument -### -- %s 2>&1 | \
 // RUN: FileCheck %s --check-prefix=CL-ERROR
+// RUN: not %clang_cl -helo -Werror=unknown-argument -### -- %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=CL-ERROR-DID-YOU-MEAN
 // RUN: %clang_cl -cake-is-lie -%0 -%d - -munknown-to-clang-option -print-stats -funknown-to-clang-option -c -Wno-unknown-argument -### -- %s 2>&1 | \
 // RUN: FileCheck %s --check-prefix=SILENT
 
@@ -14,20 +20,24 @@
 // CHECK: error: unknown argument: '-munknown-to-clang-option'
 // CHECK: error: unknown argument: '-print-stats'
 // CHECK: error: unknown argument: '-funknown-to-clang-option'
+// DID-YOU-MEAN: error: unknown argument '-stdlibs=foo', did you mean '-stdlib=foo'?
+// DID-YOU-MEAN: error: unknown argument '-hell', did you mean '-help'?
 // CL: warning: unknown argument ignored in clang-cl: '-cake-is-lie'
 // CL: warning: unknown argument ignored in clang-cl: '-%0'
 // CL: warning: unknown argument ignored in clang-cl: '-%d'
 // CL: warning: unknown argument ignored in clang-cl: '-'
 // CL: warning: unknown argument ignored in clang-cl: '-munknown-to-clang-option'
 // CL: warning: unknown argument ignored in clang-cl: '-print-stats'
 // CL: warning: unknown argument ignored in clang-cl: '-funknown-to-clang-option'
+// CL-DID-YOU-MEAN: warning: unknown argument ignored in clang-cl '-Brepo' (did you mean '-Brepro'?)
 // CL-ERROR: error: unknown argument ignored in clang-cl: '-cake-is-lie'
 // CL-ERROR: error: unknown argument ignored in clang-cl: '-%0'
 // CL-ERROR: error: unknown argument ignored in clang-cl: '-%d'
 // CL-ERROR: error: unknown argument ignored in clang-cl: '-'
 // CL-ERROR: error: unknown argument ignored in clang-cl: '-munknown-to-clang-option'
 // CL-ERROR: error: unknown argument ignored in clang-cl: '-print-stats'
 // CL-ERROR: error: unknown argument ignored in clang-cl: '-funknown-to-clang-option'
+// CL-ERROR-DID-YOU-MEAN: error: unknown argument ignored in clang-cl '-helo' (did you mean '-help'?)
 // SILENT-NOT: error:
 // SILENT-NOT: warning:
 
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2757,7 +2757,13 @@
 
   // Issue errors on unknown arguments.
   for (const Arg *A : Args.filtered(OPT_UNKNOWN)) {
-Diags.Report(diag::err_drv_unknown_argument) << A->getAsString(Args);
+auto ArgString = A->getAsString(Args);
+std::string Nearest;
+if (Opts->findNearest(ArgString, Nearest, IncludedFlagsBitmask) > 1)
+  Diags.Report(diag::err_drv_unknown_argument) << ArgString;
+else
+  Diags.Report(diag::err_drv_unknown_argument_with_suggestion)
+  << ArgString << Nearest;
  

[clang-tools-extra] r321867 - [clangd] Fix memory leak in code completion

2018-01-05 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri Jan  5 05:36:55 2018
New Revision: 321867

URL: http://llvm.org/viewvc/llvm-project?rev=321867&view=rev
Log:
[clangd] Fix memory leak in code completion

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

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=321867&r1=321866&r2=321867&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Fri Jan  5 05:36:55 2018
@@ -506,6 +506,7 @@ bool invokeCodeComplete(const Context &C
   &DummyDiagsConsumer, false),
   VFS);
   assert(CI && "Couldn't create CompilerInvocation");
+  CI->getFrontendOpts().DisableFree = false;
 
   std::unique_ptr ContentsBuffer =
   llvm::MemoryBuffer::getMemBufferCopy(Contents, FileName);


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


[PATCH] D35109: [Analyzer] SValBuilder Comparison Rearrangement

2018-01-05 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

In https://reviews.llvm.org/D35109#956075, @NoQ wrote:

> I'm totally fine with assuming the MAX/4 constraint on checker side - 
> extension math would still be better than the MAX/4 pattern-matching in core 
> because extension math should be more useful on its own. Otherwise, i'm also 
> fine with MAX/4 `>`/`<` under an off-by-default flag, if this is indeed 
> blocking future reviews. I'm just really uncomfortable with huge manual 
> checker-side symbolic computations, essentially declaring that checkers 
> should make their own solvers. Analyzer progress is already slowed down 
> dramatically by technical debt in a lot of places - we rarely have time to 
> address it, but at least we shouldn't introduce much more. This doesn't, in 
> my opinion, reduce the fascination of that whole thing you've constructed. It 
> is wonderful.


The problem with the type extension approach is that it is mathematically "more 
correct than it should be". I mean it fixes all overflow cases, even 
intentional ones which we probably do not want to do. I am not speaking about 
intentional overflow cases in the checkers or in the core infrastructure which 
could be fixed but intentional overlfow cases in the code we analyze.

So probably the MAX/4 approach is the correct one. But how to add a flag for 
this? Is it a flag enabled by the user or is it automatically enabled if the 
checker is enabled?


https://reviews.llvm.org/D35109



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


[PATCH] D41764: [libcxx] [cmake] Add a config option LIBCXX_HAS_WIN32_THREADS for enforcing win32 threads

2018-01-05 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

I think `LIBCXX_HAS_WIN32_THREAD_API` would be more consistent with the 
existing configuration define names?




Comment at: CMakeLists.txt:277
   endif()
+  if(LIBCXX_HAS_WIN32_THREADS)
+message(FATAL_ERROR "LIBCXX_HAS_WIN32_THREADS can only be set to ON"

The inconsistent usage of `if(` vs `if (` in this file is annoying me haha. Not 
this diff's fault of course, but still.


Repository:
  rCXX libc++

https://reviews.llvm.org/D41764



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


[PATCH] D41668: [clangd] Add static index for the global code completion.

2018-01-05 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 128741.
hokein marked 5 inline comments as done.
hokein added a comment.

Address comments.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41668

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/CodeComplete.cpp
  clangd/CodeComplete.h
  clangd/index/MemIndex.cpp
  clangd/index/MemIndex.h
  clangd/tool/ClangdMain.cpp
  unittests/clangd/CodeCompleteTests.cpp

Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -453,12 +453,6 @@
 
 std::unique_ptr simpleIndexFromSymbols(
 std::vector> Symbols) {
-  auto I = llvm::make_unique();
-  struct Snapshot {
-SymbolSlab Slab;
-std::vector Pointers;
-  };
-  auto Snap = std::make_shared();
   SymbolSlab::Builder Slab;
   for (const auto &Pair : Symbols) {
 Symbol Sym;
@@ -475,13 +469,7 @@
 Sym.SymInfo.Kind = Pair.second;
 Slab.insert(Sym);
   }
-  Snap->Slab = std::move(Slab).build();
-  for (auto &Iter : Snap->Slab)
-Snap->Pointers.push_back(&Iter);
-  auto S = std::shared_ptr>(std::move(Snap),
-&Snap->Pointers);
-  I->build(std::move(S));
-  return std::move(I);
+  return MemIndex::build(std::move(Slab).build());
 }
 
 TEST(CompletionTest, NoIndex) {
@@ -496,6 +484,23 @@
   EXPECT_THAT(Results.items, Has("No"));
 }
 
+TEST(CompletionTest, StaticAndDynamicIndex) {
+  clangd::CodeCompleteOptions Opts;
+  auto StaticIdx =
+  simpleIndexFromSymbols({{"ns::XYZ", index::SymbolKind::Class}});
+  Opts.StaticIndex = StaticIdx.get();
+  auto DynamicIdx =
+  simpleIndexFromSymbols({{"ns::foo", index::SymbolKind::Function}});
+  Opts.Index = DynamicIdx.get();
+
+  auto Results = completions(R"cpp(
+  void f() { ::ns::^ }
+  )cpp",
+ Opts);
+  EXPECT_THAT(Results.items, Contains(Labeled("[G]XYZ")));
+  EXPECT_THAT(Results.items, Contains(Labeled("foo")));
+}
+
 TEST(CompletionTest, SimpleIndexBased) {
   clangd::CodeCompleteOptions Opts;
   auto I = simpleIndexFromSymbols({{"ns::XYZ", index::SymbolKind::Class},
Index: clangd/tool/ClangdMain.cpp
===
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -11,6 +11,7 @@
 #include "JSONRPCDispatcher.h"
 #include "Path.h"
 #include "Trace.h"
+#include "index/SymbolYAML.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
@@ -26,7 +27,24 @@
 
 namespace {
 enum class PCHStorageFlag { Disk, Memory };
+
+// Build an in-memory static index for global symbols from a YAML-format file.
+// The size of global symbols should be relatively small, so that all symbols
+// can be managed in memory.
+std::unique_ptr BuildStaticIndex(llvm::StringRef YamlSymbolFile) {
+  auto Buffer = llvm::MemoryBuffer::getFile(YamlSymbolFile);
+  if (!Buffer) {
+llvm::errs() << "Can't open " << YamlSymbolFile << "\n";
+return nullptr;
+  }
+  auto Slab = SymbolFromYAML(Buffer.get()->getBuffer());
+  SymbolSlab::Builder SymsBuilder;
+  for (auto Sym : Slab)
+SymsBuilder.insert(Sym);
+
+  return MemIndex::build(std::move(SymsBuilder).build());
 }
+} // namespace
 
 static llvm::cl::opt CompileCommandsDir(
 "compile-commands-dir",
@@ -97,6 +115,15 @@
 "use index built from symbols in opened files"),
 llvm::cl::init(false), llvm::cl::Hidden);
 
+static llvm::cl::opt YamlSymbolFile(
+"yaml-symbol-file",
+llvm::cl::desc(
+"YAML-format global symbol file to build the static index. It is only "
+"available when 'enable-index-based-completion' is enabled.\n"
+"WARNING: This option is experimental only, and will be removed "
+"eventually. Don't rely on it."),
+llvm::cl::init(""), llvm::cl::Hidden);
+
 int main(int argc, char *argv[]) {
   llvm::cl::ParseCommandLineOptions(argc, argv, "clangd");
 
@@ -182,13 +209,16 @@
   // Change stdin to binary to not lose \r\n on windows.
   llvm::sys::ChangeStdinToBinary();
 
+  std::unique_ptr StaticIdx;
+  if (EnableIndexBasedCompletion && !YamlSymbolFile.empty())
+StaticIdx = BuildStaticIndex(YamlSymbolFile);
   clangd::CodeCompleteOptions CCOpts;
   CCOpts.EnableSnippets = EnableSnippets;
   CCOpts.IncludeIneligibleResults = IncludeIneligibleResults;
   // Initialize and run ClangdLSPServer.
   ClangdLSPServer LSPServer(Out, WorkerThreadsCount, StorePreamblesInMemory,
 CCOpts, ResourceDirRef, CompileCommandsDirPath,
-EnableIndexBasedCompletion);
+EnableIndexBasedCompletion, std::move(StaticIdx));
   constexpr int NoShutdownRequestErrorCode = 1;
   llvm::set_thread_name("clangd.main");
   return LSPServer.run(std::cin) ? 0 : NoShutdownRequestErrorCode

[PATCH] D41668: [clangd] Add static index for the global code completion.

2018-01-05 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clangd/ClangdServer.h:342
   std::unique_ptr FileIdx;
+  /// If set, this provides static index for project-wide global symbols.
+  std::unique_ptr StaticIdx;

ioeric wrote:
> ... in addition to the `FileIdx` above?
Updated the comment.



Comment at: clangd/CodeComplete.cpp:571
+  // FIXME: find out a better way to show the index source.
+  Item.detail = llvm::Twine("[" + IndexSource + "]").str();
   return Item;

ioeric wrote:
> AFAIK, `Detail` is not visible in the completion item list unless you hover 
> on an item. I'd suggest throwing a "[G]" prefix to labels of the global 
> symbols. For completion `clang::^`, the list would look like:
> ```
> clang::Local1
> clang::Local2
> [G]clang::Global1
> [G]clang::Global2
> ```
> 
> WDYT?
Yeah, this would make debugging easier. We could figure out a better shown way 
to the end users in the future.



Comment at: clangd/CodeComplete.cpp:651
  std::move(PCHs));
-  if (Opts.Index && CompletedName.SSInfo) {
+  if (CompletedName.SSInfo && (Opts.Index || Opts.StaticIndex)) {
 if (!Results.items.empty())

ioeric wrote:
> We might not want to lose (non-index-based) AST symbols if we only have 
> `StaticIndex`. Maybe only use static index augment the dynamic index?
The `Opts.StaticIndex` check is not need here, removed it -- the StaticIndex is 
set when `enable-index-based-completion` is on. 


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41668



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


[PATCH] D41487: [clang-format] Adds a FormatStyleSet

2018-01-05 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 128743.
krasimir added a comment.

- Address review comments


Repository:
  rC Clang

https://reviews.llvm.org/D41487

Files:
  include/clang/Format/Format.h
  lib/Format/Format.cpp

Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -888,15 +888,25 @@
   // Look for a suitable configuration starting from the end, so we can
   // find the configuration for the specific language first, and the default
   // configuration (which can only be at slot 0) after it.
+  FormatStyle::FormatStyleSet StyleSet;
+  bool LanguageFound = false;
   for (int i = Styles.size() - 1; i >= 0; --i) {
-if (Styles[i].Language == Language ||
-Styles[i].Language == FormatStyle::LK_None) {
-  *Style = Styles[i];
-  Style->Language = Language;
-  return make_error_code(ParseError::Success);
-}
-  }
-  return make_error_code(ParseError::Unsuitable);
+if (Styles[i].Language != FormatStyle::LK_None)
+  StyleSet.Add(Styles[i]);
+if (Styles[i].Language == Language)
+  LanguageFound = true;
+  }
+  if (!LanguageFound && !Styles.empty() &&
+  Styles[0].Language == FormatStyle::LK_None) {
+FormatStyle DefaultStyle = Styles[0];
+DefaultStyle.Language = Language;
+StyleSet.Add(DefaultStyle);
+LanguageFound = true;
+  }
+  if (!LanguageFound)
+return make_error_code(ParseError::Unsuitable);
+  *Style = *StyleSet.Get(Language);
+  return make_error_code(ParseError::Success);
 }
 
 std::string configurationAsText(const FormatStyle &Style) {
@@ -910,6 +920,30 @@
   return Stream.str();
 }
 
+llvm::Optional
+FormatStyle::FormatStyleSet::Get(FormatStyle::LanguageKind Language) const {
+  if (!Styles)
+return None;
+  auto It = Styles->find(Language);
+  if (It == Styles->end())
+return None;
+  FormatStyle Style = *It->second;
+  Style.StyleSet = *this;
+  return Style;
+}
+
+void FormatStyle::FormatStyleSet::Add(FormatStyle Style) {
+  Style.StyleSet.Styles.reset();
+  if (!Styles)
+Styles = std::make_shared();
+  (*Styles)[Style.Language].reset(new FormatStyle(Style));
+}
+
+llvm::Optional
+FormatStyle::GetLanguageStyle(FormatStyle::LanguageKind Language) const {
+  return StyleSet.Get(Language);
+}
+
 namespace {
 
 class JavaScriptRequoter : public TokenAnalyzer {
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -1685,6 +1685,36 @@
Standard == R.Standard && TabWidth == R.TabWidth &&
UseTab == R.UseTab;
   }
+
+  llvm::Optional GetLanguageStyle(LanguageKind Language) const;
+
+  // Stores per-language styles. A FormatStyle instance inside has an empty
+  // StyleSet. A FormatStyle instance returned by the Get method has its
+  // StyleSet set to a copy of the originating StyleSet, effectively keeping the
+  // internal representation of that StyleSet alive.
+  //
+  // The memory management and ownership reminds of a birds nest: chicks
+  // leaving the nest take photos of the nest with them.
+  struct FormatStyleSet {
+typedef std::map>
+MapType;
+
+llvm::Optional Get(FormatStyle::LanguageKind Language) const;
+void Add(FormatStyle Style);
+
+  private:
+std::shared_ptr Styles;
+  };
+
+  static FormatStyleSet BuildStyleSetFromConfiguration(
+  const FormatStyle &MainStyle,
+  const std::vector &ConfigurationStyles);
+
+private:
+  FormatStyleSet StyleSet;
+
+  friend std::error_code parseConfiguration(StringRef Text, FormatStyle *Style);
 };
 
 /// \brief Returns a format style complying with the LLVM coding standards:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41668: [clangd] Add static index for the global code completion.

2018-01-05 Thread Eric Liu via Phabricator via cfe-commits
ioeric accepted this revision.
ioeric added a comment.
This revision is now accepted and ready to land.

lgtm




Comment at: clangd/CodeComplete.cpp:554
+   const SpecifiedScope &SSInfo,
+   llvm::StringRef IndexSource = "") {
   CompletionItem Item;

Maybe `IndexSourceLabel`?



Comment at: clangd/CodeComplete.cpp:577
 
+
   return Item;

Is this blank line intended?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41668



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


[PATCH] D41720: [clang-tidy] Add a -show-color flag.

2018-01-05 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh requested changes to this revision.
alexfh added a comment.
This revision now requires changes to proceed.

Clang supports -fcolor-diagnostics. I guess, we could use it, e.g. via 
-extra-arg=-fcolor-diagnostics.




Comment at: clang-tidy/ClangTidyOptions.h:93
+  /// \brief Show color diagnostics.
+  llvm::Optional ShowColor;
+

This doesn't belong to ClangTidyOptions. It's specific to the CLI, but CLI is 
not the only frontend for clang-tidy.


https://reviews.llvm.org/D41720



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


[PATCH] D41716: clang-tidy: add IgnoreMacros option to readability-inconsistent-declaration-parameter-name

2018-01-05 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In https://reviews.llvm.org/D41716#967247, @vmiklos wrote:

> In https://reviews.llvm.org/D41716#967237, @lebedev.ri wrote:
>
> > That changes the defaults though. I thought clang-tidy *tried* to produce 
> > the same results
> >  on different clang-tidy versions with the same `.clang-tidy` config? Or is 
> > there no such guarantees?
>
>
> Hmm, I see this as a trade-off between backwards compatibility and 
> consistency. Here I went for consistency, so that all of 
> readability-inconsistent-declaration-parameter-name, 
> modernize-use-default-member-init and modernize-use-using default to 
> IgnoreMacros=1. But I don't have a too strong opinion on that, can change the 
> default to 0 if really wanted,


I'd personally prefer consistency in this case, especially because the option 
can be specified globally for all checks.


https://reviews.llvm.org/D41716



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


[PATCH] D41716: clang-tidy: add IgnoreMacros option to readability-inconsistent-declaration-parameter-name

2018-01-05 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

Thus, looks good. Thanks!


https://reviews.llvm.org/D41716



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


[PATCH] D15032: [clang-tidy] new checker cppcoreguidelines-pro-lifetime

2018-01-05 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh requested changes to this revision.
alexfh added a comment.
This revision now requires changes to proceed.
Herald added subscribers: kbarton, mgorny, nemanjai.

https://reviews.llvm.org/D15031 has landed quite a while ago. Could you rebase 
the patch?


https://reviews.llvm.org/D15032



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


[PATCH] D35787: [clang-tidy] Ignore vector in inefficient-vector-operation.

2018-01-05 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In https://reviews.llvm.org/D35787#830351, @hokein wrote:

> In https://reviews.llvm.org/D35787#819007, @alexfh wrote:
>
> > Should we look at whether the size is statically known?
>
>
> Do you mean the size of the template type T in `vector`?  STL only 
> provides a template specialization for `std::vector`, so I think 
> excluding `vector` is probably enough, or am I missing anything here?


I meant the size of the vector, i.e. the number of elements that is going to be 
pushed into it. Is it still reasonable to exempt vector, if, say, a 
million of bools is pushed into it?


https://reviews.llvm.org/D35787



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


[PATCH] D40712: [Driver] Add flag enabling the function stack size section that was added in r319430

2018-01-05 Thread Sean Eveson via Phabricator via cfe-commits
seaneveson updated this revision to Diff 128745.
seaneveson added a comment.

Thanks Bruno,

Changed the default for cc1 to be false regardless of the target. The default 
in the driver is still true for PS4 (only).


https://reviews.llvm.org/D40712

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/BackendUtil.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/stack-size-section.c
  test/Driver/stack-size-section.c


Index: test/Driver/stack-size-section.c
===
--- test/Driver/stack-size-section.c
+++ test/Driver/stack-size-section.c
@@ -0,0 +1,9 @@
+// RUN: %clang -target x86_64-unknown %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-ABSENT
+// RUN: %clang -target x86_64-scei-ps4 -fno-stack-size-section %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-ABSENT
+// CHECK-ABSENT-NOT: -fstack-size-section
+
+// RUN: %clang -target x86_64-unknown -fstack-size-section -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-PRESENT
+// RUN: %clang -target x86_64-scei-ps4 %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-PRESENT
+// CHECK-PRESENT: -fstack-size-section
+
+int foo() { return 42; }
Index: test/CodeGen/stack-size-section.c
===
--- test/CodeGen/stack-size-section.c
+++ test/CodeGen/stack-size-section.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple x86_64-unknown %s -S -o - | FileCheck %s 
--check-prefix=CHECK-ABSENT
+// CHECK-ABSENT-NOT: section .stack_sizes
+
+// RUN: %clang_cc1 -triple x86_64-unknown -fstack-size-section %s -S -o - | 
FileCheck %s --check-prefix=CHECK-PRESENT
+// CHECK-PRESENT: section .stack_sizes
+
+int foo() { return 42; }
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -682,6 +682,8 @@
OPT_fno_function_sections, false);
   Opts.DataSections = Args.hasFlag(OPT_fdata_sections,
OPT_fno_data_sections, false);
+  Opts.StackSizeSection =
+  Args.hasFlag(OPT_fstack_size_section, OPT_fno_stack_size_section, false);
   Opts.UniqueSectionNames = Args.hasFlag(OPT_funique_section_names,
  OPT_fno_unique_section_names, true);
 
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3798,6 +3798,10 @@
 CmdArgs.push_back(A->getValue());
   }
 
+  if (Args.hasFlag(options::OPT_fstack_size_section,
+   options::OPT_fno_stack_size_section, RawTriple.isPS4()))
+CmdArgs.push_back("-fstack-size-section");
+
   CmdArgs.push_back("-ferror-limit");
   if (Arg *A = Args.getLastArg(options::OPT_ferror_limit_EQ))
 CmdArgs.push_back(A->getValue());
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -448,6 +448,7 @@
   Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames;
   Options.EmulatedTLS = CodeGenOpts.EmulatedTLS;
   Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning();
+  Options.EmitStackSizeSection = CodeGenOpts.StackSizeSection;
 
   if (CodeGenOpts.EnableSplitDwarf)
 Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -83,6 +83,7 @@
 
 CODEGENOPT(XRayInstrumentFunctions , 1, 0) ///< Set when -fxray-instrument is
///< enabled.
+CODEGENOPT(StackSizeSection  , 1, 0) ///< Set when -fstack-size-section is 
enabled.
 
 ///< Set when -fxray-always-emit-customevents is enabled.
 CODEGENOPT(XRayAlwaysEmitCustomEvents , 1, 0)
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1574,6 +1574,10 @@
  Flags<[CC1Option]>, HelpText<"Place each data in its own section (ELF Only)">;
 def fno_data_sections : Flag <["-"], "fno-data-sections">, Group,
   Flags<[CC1Option]>;
+def fstack_size_section : Flag<["-"], "fstack-size-section">, Group, 
Flags<[CC1Option]>,
+  HelpText<"Emit section containing metadata on function stack sizes">;
+def fno_stack_size_section : Flag<["-"], "fno-stack-size-section">, 
Group, Flags<[CC1Option]>,
+  HelpText<"Don't emit section containing metadata on function stack sizes">;
 
 def funique_section_names : Flag <["-"], "funique-section-names">,
   Group, Flags<[CC1Option]>,


Index: test/Driver/stack-size-section.c
==

[PATCH] D41523: xmmintrin.h documentation fixes and updates

2018-01-05 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

Sort of related - should we enable -Wdocumentation (it's currently -Wall and 
-Weverything might be too much) on the respective clang builtin tests? 
Doesn't have to be part of this patch.




Comment at: lib/Headers/xmmintrin.h:1927
 ///
-/// This intrinsic corresponds to the  VPEXTRQ / MOVQ  instruction.
+/// This intrinsic corresponds to the  VPEXTRQ / PEXTRQ  instruction.
 ///

Not necessarily, it could be (v)movhps/(v)movhpd - but those are tricky to 
generate in current isel.


https://reviews.llvm.org/D41523



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


[PATCH] D41720: [clang-tidy] Add a -show-color flag.

2018-01-05 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In https://reviews.llvm.org/D41720#968338, @alexfh wrote:

> Clang supports -fcolor-diagnostics. I guess, we could use it, e.g. via 
> -extra-arg=-fcolor-diagnostics.


On a second thought, configuring the colors using -extra-arg doesn't seem like 
a good solution to me. A separate command line option is fine, but it should be 
just a frontend option independent of ClangTidyOptions.


https://reviews.llvm.org/D41720



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


[PATCH] D41487: [clang-format] Adds a FormatStyleSet

2018-01-05 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: lib/Format/Format.cpp:906-907
+  }
+  if (!LanguageFound)
+return make_error_code(ParseError::Unsuitable);
+  *Style = *StyleSet.Get(Language);

Optional: I'd probably slightly re-structure the above to:
  if (!LanguageFound) {
if (Styles.empty() || Styles[0].Language != FS::LK_None) {
  return make_error_code(PE::Unsuitable);
}
...
  }



Comment at: lib/Format/Format.cpp:936
+void FormatStyle::FormatStyleSet::Add(FormatStyle Style) {
+  Style.StyleSet.Styles.reset();
+  if (!Styles)

Should we rather check that a style that's added doesn't have its own Styles 
map? (I'd say you're not allowed to add a Style that was gotten into another 
StyleSet).


Repository:
  rC Clang

https://reviews.llvm.org/D41487



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


[PATCH] D35110: [Analyzer] Constraint Manager Negates Difference

2018-01-05 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

In https://reviews.llvm.org/D35110#968284, @baloghadamsoftware wrote:

> This one is not blocked anymore since I removed the dependency.


But I have to modify the test cases...


https://reviews.llvm.org/D35110



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


[PATCH] D41764: [libcxx] [cmake] Add a config option LIBCXX_HAS_WIN32_THREADS for enforcing win32 threads

2018-01-05 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In https://reviews.llvm.org/D41764#968318, @smeenai wrote:

> I think `LIBCXX_HAS_WIN32_THREAD_API` would be more consistent with the 
> existing configuration define names?


That sounds good to me too. I can update the patch later, or before committing 
if it's otherwise ok.




Comment at: CMakeLists.txt:277
   endif()
+  if(LIBCXX_HAS_WIN32_THREADS)
+message(FATAL_ERROR "LIBCXX_HAS_WIN32_THREADS can only be set to ON"

smeenai wrote:
> The inconsistent usage of `if(` vs `if (` in this file is annoying me haha. 
> Not this diff's fault of course, but still.
Oh, yes... The new lines here were copypasted from the pthread ones a bit 
further above, explaining the inconsistency.


Repository:
  rCXX libc++

https://reviews.llvm.org/D41764



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


[PATCH] D31417: [OpenMP] Add support for omp simd pragmas without runtime

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

I think we can abandon this one as support for -fopenmp-simd was committed 
already?


https://reviews.llvm.org/D31417



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


[PATCH] D41039: Add support for attribute "trivial_abi"

2018-01-05 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 128767.
ahatanak added a comment.

Address review comments.

I also made changes so that FunctionDecl::IsTrivialForCall is always set to 
true for special functions of "trivial_abi" classes.

There is still one microsoft IRGen test failing because I haven't implemented 
serialization of the "ForCall" bits I introduced in FunctionDecl and 
CXXRecordDecl.


https://reviews.llvm.org/D41039

Files:
  include/clang/AST/Decl.h
  include/clang/AST/DeclCXX.h
  include/clang/AST/Type.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/AST/DeclCXX.cpp
  lib/AST/Type.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenCXX/trivial_abi.cpp
  test/Misc/pragma-attribute-supported-attributes-list.test
  test/SemaObjCXX/attr-trivial-abi.mm

Index: test/SemaObjCXX/attr-trivial-abi.mm
===
--- /dev/null
+++ test/SemaObjCXX/attr-trivial-abi.mm
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -std=c++11 -fobjc-runtime-has-weak -fobjc-weak -fobjc-arc -fsyntax-only -verify %s
+
+void __attribute__((trivial_abi)) foo(); // expected-warning {{'trivial_abi' attribute only applies to classes}}
+
+struct [[clang::trivial_abi]] S0 {
+  int a;
+};
+
+struct __attribute__((trivial_abi)) S1 {
+  int a;
+};
+
+struct __attribute__((trivial_abi)) S2 { // expected-warning {{'trivial_abi' cannot be applied to 'S2'}}
+  __weak id a;
+};
+
+struct __attribute__((trivial_abi)) S3 { // expected-warning {{'trivial_abi' cannot be applied to 'S3'}}
+  virtual void m();
+};
+
+struct S4 {
+  int a;
+};
+
+struct __attribute__((trivial_abi)) S5 : public virtual S4 { // expected-warning {{'trivial_abi' cannot be applied to 'S5'}}
+};
+
+struct __attribute__((trivial_abi)) S9 : public S4 {
+};
+
+struct S6 {
+  __weak id a;
+};
+
+struct __attribute__((trivial_abi)) S7 { // expected-warning {{'trivial_abi' cannot be applied to 'S7'}}
+  S6 a;
+};
+
+struct __attribute__((trivial_abi)) S11 { // expected-warning {{'trivial_abi' cannot be applied to 'S11'}}
+  S6 a[2];
+};
+
+struct __attribute__((trivial_abi(1))) S8 { // expected-error {{'trivial_abi' attribute takes no arguments}}
+  int a;
+};
+
+template
+struct __attribute__((trivial_abi)) S10 {
+  T p;
+};
+
+S10 p1;
+
+// Do not warn when 'trivial_abi' is used to annotate a template class.
+S10<__weak id> p2;
Index: test/Misc/pragma-attribute-supported-attributes-list.test
===
--- test/Misc/pragma-attribute-supported-attributes-list.test
+++ test/Misc/pragma-attribute-supported-attributes-list.test
@@ -2,7 +2,7 @@
 
 // The number of supported attributes should never go down!
 
-// CHECK: #pragma clang attribute supports 66 attributes:
+// CHECK: #pragma clang attribute supports 67 attributes:
 // CHECK-NEXT: AMDGPUFlatWorkGroupSize (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumSGPR (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumVGPR (SubjectMatchRule_function)
@@ -66,6 +66,7 @@
 // CHECK-NEXT: TLSModel (SubjectMatchRule_variable_is_thread_local)
 // CHECK-NEXT: Target (SubjectMatchRule_function)
 // CHECK-NEXT: TestTypestate (SubjectMatchRule_function_is_member)
+// CHECK-NEXT: TrivialABI (SubjectMatchRule_record)
 // CHECK-NEXT: WarnUnusedResult (SubjectMatchRule_objc_method, SubjectMatchRule_enum, SubjectMatchRule_record, SubjectMatchRule_hasType_functionType)
 // CHECK-NEXT: XRayInstrument (SubjectMatchRule_function, SubjectMatchRule_objc_method)
 // CHECK-NEXT: XRayLogArgs (SubjectMatchRule_function, SubjectMatchRule_objc_method)
Index: test/CodeGenCXX/trivial_abi.cpp
===
--- /dev/null
+++ test/CodeGenCXX/trivial_abi.cpp
@@ -0,0 +1,196 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++11 -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: %[[STRUCT_SMALL:.*]] = type { i32* }
+// CHECK: %[[STRUCT_LARGE:.*]] = type { i32*, [128 x i32] }
+// CHECK: %[[STRUCT_TRIVIAL:.*]] = type { i32 }
+// CHECK: %[[STRUCT_NONTRIVIAL:.*]] = type { i32 }
+
+struct __attribute__((trivial_abi)) Small {
+  int *p;
+  Small();
+  ~Small();
+  Small(const Small &);
+  Small &operator=(const Small &);
+};
+
+struct __attribute__((trivial_abi)) Large {
+  int *p;
+  int a[128];
+  Large();
+  ~Large();
+  Large(const Large &);
+  Large &operator=(const Large &);
+};
+
+struct Trivial {
+  int a;
+};
+
+struct NonTrivial {
+  NonTrivial();
+  ~NonTrivial();
+  int a;
+};
+
+struct HasTrivial {
+  Small s;
+  Trivial m;
+};
+
+struct HasNonTrivial {
+  Small s;
+  NonTrivial m;
+};
+
+// CHECK: define void @_Z14testParamSmall5Small(i64 %[[A_COERCE:.*]])
+// CHECK: %[[A:.*]] = alloca %[[STRUCT_SMALL]], align 8
+// CHECK: %[[COERCE_DIVE:.*]] = getelementptr inbounds %[[STRUCT_SM

[PATCH] D41740: [clang-tidy] Adding a new bugprone check for streaming objects of type int8_t or uint8_t

2018-01-05 Thread Barry Revzin via Phabricator via cfe-commits
BRevzin updated this revision to Diff 128768.
BRevzin added a comment.

Updates based on review comments  - and rebased off of latest so as to get the 
ReleaseNotes right.  Added options so that the user can provide the list of 
stream types and int typedef types, as desired, defaulting to just 
`basic_ostream` and `int8_t`/`uint8_t`.


https://reviews.llvm.org/D41740

Files:
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/StreamInt8Check.cpp
  clang-tidy/bugprone/StreamInt8Check.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-stream-int8.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/bugprone-stream-int8.cpp

Index: test/clang-tidy/bugprone-stream-int8.cpp
===
--- /dev/null
+++ test/clang-tidy/bugprone-stream-int8.cpp
@@ -0,0 +1,46 @@
+// RUN: %check_clang_tidy %s bugprone-stream-int8 %t -- \
+// RUN:   -config="{CheckOptions: \
+// RUN: [{key: bugprone-stream-int8.AliasTypes, \
+// RUN:   value: 'int8_t; uint8_t; widget'}]}" \
+// RUN:   -- -std=c++11
+
+using int8_t = signed char;
+using uint8_t = unsigned char;
+using widget = unsigned char;
+
+namespace std {
+template 
+struct basic_ostream;
+
+using ostream = basic_ostream;
+
+basic_ostream& operator<<(basic_ostream&, char );
+basic_ostream& operator<<(basic_ostream&, unsigned char );
+basic_ostream& operator<<(basic_ostream&, signed char );
+basic_ostream& operator<<(basic_ostream&, int );
+}
+
+void BadStreaming(std::ostream& os, uint8_t i) {
+// CHECK-MESSAGES: :[[@LINE+1]]:11: warning: streaming uint8_t; did you mean to stream an int? [bugprone-stream-int8]
+os << i;
+
+// CHECK-MESSAGES: :[[@LINE+1]]:16: warning: streaming uint8_t; did you mean to stream an int? [bugprone-stream-int8]
+os << 4 << i;
+
+// CHECK-MESSAGES: :[[@LINE+1]]:11: warning: streaming int8_t; did you mean to stream an int? [bugprone-stream-int8]
+os << int8_t{};
+
+using Num = int8_t;
+// CHECK-MESSAGES: :[[@LINE+1]]:11: warning: streaming int8_t; did you mean to stream an int? [bugprone-stream-int8]
+os << Num{};
+
+// CHECK-MESSAGES: :[[@LINE+1]]:11: warning: streaming widget; did you mean to stream an int? [bugprone-stream-int8]
+os << widget{};
+}
+
+void GoodStreaming(std::ostream& os, uint8_t i) {
+using UC = unsigned char;
+
+unsigned char uc;
+os << +i << 4 << uc << UC{};
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -29,6 +29,7 @@
bugprone-misplaced-operator-in-strlen-in-alloc
bugprone-move-forwarding-reference
bugprone-multiple-statement-macro
+   bugprone-stream-int8
bugprone-string-constructor
bugprone-suspicious-memset-usage
bugprone-undefined-memory-manipulation
Index: docs/clang-tidy/checks/bugprone-stream-int8.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/bugprone-stream-int8.rst
@@ -0,0 +1,29 @@
+.. title:: clang-tidy - bugprone-stream-int8
+
+bugprone-stream-int8
+
+
+Checks that objects of type ``int8_t`` or ``uint8_t`` aren't streamed,  if those
+are typedefs to ``signed char`` or ``unsigned char``, as this likely intends to
+be streaming these types as ``int`` s instead.
+
+Examples:
+
+.. code-block:: c++
+
+  uint8_t value = 0;
+  std::cout << "Value is " << value; // prints ^@ instead of likely intended 0
+
+Options
+---
+
+.. option:: StreamTypes
+
+   A semicolon-separated list of class names that should be treated as streams.
+   By default only ``std::basic_ostream`` is considered.
+
+.. option:: AliasTypes
+
+   A semicolon-separated list of alias names that should be treated as integer
+   types to check against. By default only ``int8_t`` and ``uint8_t`` are
+   considered.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,7 +57,12 @@
 Improvements to clang-tidy
 --
 
-- ...
+- New `bugprone-stream-int8_t
+  `_ check
+
+  Checks that objects of type ``int8_t`` or ``uint8_t`` aren't streamed,  if those
+  are typedefs to ``signed char`` or ``unsigned char``, as this likely intends to
+  be streaming these types as ``int`` s instead.
 
 Improvements to include-fixer
 -
Index: clang-tidy/bugprone/StreamInt8Check.h
===
--- /dev/null
+++ clang-tidy/bugprone/StreamInt8Check.h
@@ -0,0 +1,43 @@
+//===--- StreamInt8Check.h - clang-tidy---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed u

[PATCH] D41740: [clang-tidy] Adding a new bugprone check for streaming objects of type int8_t or uint8_t

2018-01-05 Thread Barry Revzin via Phabricator via cfe-commits
BRevzin marked an inline comment as done.
BRevzin added a comment.

In https://reviews.llvm.org/D41740#968134, @JonasToth wrote:

> Could you please add a test case with a template that reduces the type to 
> int8 or uint8?


I don't actually know how to do that. I tried a few things, but getting the 
type of the expression through a template gets me directly to `unsigned char`, 
not to `uint8_t`.


https://reviews.llvm.org/D41740



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


[PATCH] D41039: Add support for attribute "trivial_abi"

2018-01-05 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak marked 10 inline comments as done.
ahatanak added inline comments.



Comment at: include/clang/AST/DeclCXX.h:443
+/// SMF_MoveConstructor, and SMF_Destructor are meaningful here.
+unsigned HasTrivialSpecialMembersForCall : 6;
+

rjmccall wrote:
> I think you could probably get away with only three bits here (and below) if 
> you reorder those three values to be the first three.  I don't know if that's 
> important in terms of packing DefinitionData at all.  Should be okay to not 
> do for now.
Yes, only three bits are needed here. I'll fix this later.



Comment at: include/clang/AST/DeclCXX.h:478
+/// ill-formed if it is annotated with "trivial_abi".
+unsigned DropTrivialABI : 1;
+

rjmccall wrote:
> So is it actually interesting to drop the attribute from the AST?  And why is 
> this bit necessary vs., say, just checking whether the attribute is present 
> but the class is not trivial-for-calls?
I think we need to check whether a struct annotated with "trivial_abi" is 
ill-formed before ActOnFields and CheckCompletedCXXClass set the triviality 
flags in Sema::ActOnFinishCXXMemberSpecification and drop the attribute if it 
is ill-formed. If we don't want to drop the attribute, we will have to find out 
whether "trivial_abi" has no effect before calls to 
FunctionDecl::setTrivialForCall are made.

I added this bit to CXXRecordDecl in the previous patch because I felt hesitant 
to iterate over the base classes and members of the class again, but I think 
that is better than adding a bit just to check whether the class is ill-formed. 
I've removed the bit in the new patch.


https://reviews.llvm.org/D41039



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


[PATCH] D41039: Add support for attribute "trivial_abi"

2018-01-05 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak marked an inline comment as done.
ahatanak added inline comments.



Comment at: include/clang/Basic/AttrDocs.td:2261
+- The class or its subobjects have Objective-C pointer type members and ARC is
+  enabled.
+  }];

rjmccall wrote:
> I think the right list of exceptions is:
> 
>   - The class directly declares a virtual base or virtual methods.
>   - The class has a base class that is non-trivial for the purposes of calls.
>   - The class has a non-static data member whose type is non-trivial for the 
> purposes of calls, which includes:
> - classes that are non-trivial for the purposes of calls
> - __weak-qualified types in Objective-C++
> - arrays of any of the above
> 
> I don't see why __strong types would be affected.  We've talked about 
> changing the C++ ABI for structs containing __strong members as part of the 
> __strong-pointers-in-structs feature, but that's not even implicated here 
> because there's an attribute which did not previously exist, so there's no 
> established ABI.
I realized I hadn't taken care of arrays of non-trivial structs. I fixed it in 
checkIllFormedTrivialABIStruct and added a test case to 
test/SemaObjCXX/attr-trivial-abi.mm.


https://reviews.llvm.org/D41039



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


[PATCH] D41423: [Lex] Avoid out-of-bounds dereference in LexAngledStringLiteral.

2018-01-05 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Ping. OSS-Fuzz classifies the bug as medium severity security issue, would be 
great to include the fix in Clang 6.0.


https://reviews.llvm.org/D41423



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


[PATCH] D41779: [clang-tidy] Fix DanglingHandleCheck for the correct conversion operation between basic_string and basic_string_view.

2018-01-05 Thread Samuel Benzaquen via Phabricator via cfe-commits
sbenza created this revision.
sbenza added a reviewer: hokein.
Herald added subscribers: cfe-commits, xazax.hun, klimek.

Fix DanglingHandleCheck to handle the final implementation of std::string and 
std::string_view.
These use a conversion operator instead of a conversion constructor.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41779

Files:
  clang-tidy/bugprone/DanglingHandleCheck.cpp
  test/clang-tidy/bugprone-dangling-handle.cpp


Index: test/clang-tidy/bugprone-dangling-handle.cpp
===
--- test/clang-tidy/bugprone-dangling-handle.cpp
+++ test/clang-tidy/bugprone-dangling-handle.cpp
@@ -45,19 +45,23 @@
   value_type& operator[](Key&& key);
 };
 
+class basic_string_view;
+
 class basic_string {
  public:
   basic_string();
   basic_string(const char*);
+
+  operator basic_string_view() const noexcept;
+
   ~basic_string();
 };
 
 typedef basic_string string;
 
 class basic_string_view {
  public:
   basic_string_view(const char*);
-  basic_string_view(const basic_string&);
 };
 
 typedef basic_string_view string_view;
Index: clang-tidy/bugprone/DanglingHandleCheck.cpp
===
--- clang-tidy/bugprone/DanglingHandleCheck.cpp
+++ clang-tidy/bugprone/DanglingHandleCheck.cpp
@@ -25,8 +25,12 @@
 ast_matchers::internal::BindableMatcher
 handleFrom(const ast_matchers::internal::Matcher &IsAHandle,
const ast_matchers::internal::Matcher &Arg) {
-  return cxxConstructExpr(hasDeclaration(cxxMethodDecl(ofClass(IsAHandle))),
-  hasArgument(0, Arg));
+  return expr(
+  anyOf(cxxConstructExpr(hasDeclaration(cxxMethodDecl(ofClass(IsAHandle))),
+ hasArgument(0, Arg)),
+cxxMemberCallExpr(hasType(cxxRecordDecl(IsAHandle)),
+  callee(memberExpr(member(cxxConversionDecl(,
+  on(Arg;
 }
 
 ast_matchers::internal::Matcher handleFromTemporaryValue(


Index: test/clang-tidy/bugprone-dangling-handle.cpp
===
--- test/clang-tidy/bugprone-dangling-handle.cpp
+++ test/clang-tidy/bugprone-dangling-handle.cpp
@@ -45,19 +45,23 @@
   value_type& operator[](Key&& key);
 };
 
+class basic_string_view;
+
 class basic_string {
  public:
   basic_string();
   basic_string(const char*);
+
+  operator basic_string_view() const noexcept;
+
   ~basic_string();
 };
 
 typedef basic_string string;
 
 class basic_string_view {
  public:
   basic_string_view(const char*);
-  basic_string_view(const basic_string&);
 };
 
 typedef basic_string_view string_view;
Index: clang-tidy/bugprone/DanglingHandleCheck.cpp
===
--- clang-tidy/bugprone/DanglingHandleCheck.cpp
+++ clang-tidy/bugprone/DanglingHandleCheck.cpp
@@ -25,8 +25,12 @@
 ast_matchers::internal::BindableMatcher
 handleFrom(const ast_matchers::internal::Matcher &IsAHandle,
const ast_matchers::internal::Matcher &Arg) {
-  return cxxConstructExpr(hasDeclaration(cxxMethodDecl(ofClass(IsAHandle))),
-  hasArgument(0, Arg));
+  return expr(
+  anyOf(cxxConstructExpr(hasDeclaration(cxxMethodDecl(ofClass(IsAHandle))),
+ hasArgument(0, Arg)),
+cxxMemberCallExpr(hasType(cxxRecordDecl(IsAHandle)),
+  callee(memberExpr(member(cxxConversionDecl(,
+  on(Arg;
 }
 
 ast_matchers::internal::Matcher handleFromTemporaryValue(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2018-01-05 Thread John Baldwin via Phabricator via cfe-commits
bsdjhb added a comment.

Ok, I'm definitely fine with splitting the rename out into a separate patch.  
Will wait for @sdardis to be sure.


https://reviews.llvm.org/D39074



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


[PATCH] D41780: Preserve unknown STDC pragma through preprocessor

2018-01-05 Thread Steven Wu via Phabricator via cfe-commits
steven_wu created this revision.
steven_wu added reviewers: efriedma, rsmith, arphaman.

should keep the unknown STDC pragma through preprocessor and we also
should not emit warning for unknown STDC pragma during preprocessor.

rdar://problem/35724351


Repository:
  rC Clang

https://reviews.llvm.org/D41780

Files:
  include/clang/Basic/DiagnosticLexKinds.td
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Parse/Parser.h
  lib/Frontend/PrintPreprocessedOutput.cpp
  lib/Lex/Pragma.cpp
  lib/Parse/ParsePragma.cpp
  test/Preprocessor/pragma_unknown.c

Index: test/Preprocessor/pragma_unknown.c
===
--- test/Preprocessor/pragma_unknown.c
+++ test/Preprocessor/pragma_unknown.c
@@ -1,14 +1,18 @@
 // RUN: %clang_cc1 -fsyntax-only -Wunknown-pragmas -verify %s
-// RUN: %clang_cc1 -E %s | FileCheck --strict-whitespace %s
+// RUN: %clang_cc1 -E %s 2>&1 | FileCheck --strict-whitespace %s
 
 // GCC doesn't expand macro args for unrecognized pragmas.
 #define bar xX
 #pragma foo bar   // expected-warning {{unknown pragma ignored}}
+// CHECK-NOT: unknown pragma in STDC namespace
 // CHECK: {{^}}#pragma foo bar{{$}}
 
 #pragma STDC FP_CONTRACT ON
 #pragma STDC FP_CONTRACT OFF
 #pragma STDC FP_CONTRACT DEFAULT
+// CHECK: {{^}}#pragma STDC FP_CONTRACT ON{{$}}
+// CHECK: {{^}}#pragma STDC FP_CONTRACT OFF{{$}}
+// CHECK: {{^}}#pragma STDC FP_CONTRACT DEFAULT{{$}}
 #pragma STDC FP_CONTRACT IN_BETWEEN  // expected-warning {{expected 'ON' or 'OFF' or 'DEFAULT' in pragma}}
 
 #pragma STDC FENV_ACCESS ON  // expected-warning {{pragma STDC FENV_ACCESS ON is not supported, ignoring pragma}}
Index: lib/Parse/ParsePragma.cpp
===
--- lib/Parse/ParsePragma.cpp
+++ lib/Parse/ParsePragma.cpp
@@ -95,6 +95,17 @@
 Token &FirstToken) override;
 };
 
+/// PragmaSTDC_UnknownHandler - "\#pragma STDC ...".
+struct PragmaSTDC_UnknownHandler : public PragmaHandler {
+  PragmaSTDC_UnknownHandler() = default;
+
+  void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
+Token &UnknownTok) override {
+// C99 6.10.6p2, unknown forms are not allowed.
+PP.Diag(UnknownTok, diag::ext_stdc_pragma_ignored);
+  }
+};
+
 struct PragmaFPHandler : public PragmaHandler {
   PragmaFPHandler() : PragmaHandler("fp") {}
   void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
@@ -233,6 +244,9 @@
   FPContractHandler.reset(new PragmaFPContractHandler());
   PP.AddPragmaHandler("STDC", FPContractHandler.get());
 
+  STDCUnknownHandler.reset(new PragmaSTDC_UnknownHandler());
+  PP.AddPragmaHandler("STDC", STDCUnknownHandler.get());
+
   PCSectionHandler.reset(new PragmaClangSectionHandler(Actions));
   PP.AddPragmaHandler("clang", PCSectionHandler.get());
 
@@ -371,6 +385,9 @@
   PP.RemovePragmaHandler("STDC", FPContractHandler.get());
   FPContractHandler.reset();
 
+  PP.RemovePragmaHandler("STDC", STDCUnknownHandler.get());
+  STDCUnknownHandler.reset();
+
   PP.RemovePragmaHandler("clang", OptimizeHandler.get());
   OptimizeHandler.reset();
 
Index: lib/Lex/Pragma.cpp
===
--- lib/Lex/Pragma.cpp
+++ lib/Lex/Pragma.cpp
@@ -1628,17 +1628,6 @@
   }
 };
 
-/// PragmaSTDC_UnknownHandler - "\#pragma STDC ...".
-struct PragmaSTDC_UnknownHandler : public PragmaHandler {
-  PragmaSTDC_UnknownHandler() = default;
-
-  void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
-Token &UnknownTok) override {
-// C99 6.10.6p2, unknown forms are not allowed.
-PP.Diag(UnknownTok, diag::ext_stdc_pragma_ignored);
-  }
-};
-
 /// PragmaARCCFCodeAuditedHandler - 
 ///   \#pragma clang arc_cf_code_audited begin/end
 struct PragmaARCCFCodeAuditedHandler : public PragmaHandler {
@@ -1815,9 +1804,9 @@
   ModuleHandler->AddPragma(new PragmaModuleBuildHandler());
   ModuleHandler->AddPragma(new PragmaModuleLoadHandler());
 
+  // #pragma STDC
   AddPragmaHandler("STDC", new PragmaSTDC_FENV_ACCESSHandler());
   AddPragmaHandler("STDC", new PragmaSTDC_CX_LIMITED_RANGEHandler());
-  AddPragmaHandler("STDC", new PragmaSTDC_UnknownHandler());
 
   // MS extensions.
   if (LangOpts.MicrosoftExt) {
@@ -1843,17 +1832,5 @@
   // in Preprocessor::RegisterBuiltinPragmas().
   AddPragmaHandler("GCC", new EmptyPragmaHandler());
   AddPragmaHandler("clang", new EmptyPragmaHandler());
-  if (PragmaHandler *NS = PragmaHandlers->FindHandler("STDC")) {
-// Preprocessor::RegisterBuiltinPragmas() already registers
-// PragmaSTDC_UnknownHandler as the empty handler, so remove it first,
-// otherwise there will be an assert about a duplicate handler.
-PragmaNamespace *STDCNamespace = NS->getIfNamespace();
-assert(STDCNamespace &&
-   "Invalid namespace, registered as a regular pragma handler!");
-if (PragmaHandler *Existing = STDCNamespace->FindHandler("", false

[PATCH] D36357: Added a better diagnostic when using the delete operator with lambdas

2018-01-05 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: lib/Parse/ParseExprCXX.cpp:2906-2912
+// Basic lookahead to check if we have a lambda expression. If we
+// encounter two braces with a semicolon, we can be pretty sure
+// that this is a lambda, not say a compound literal. 
+if (!SkipUntil(tok::l_brace, SkipUntilFlags::StopAtSemi) ||
+(NextToken().isNot(tok::r_brace) && !SkipUntil(tok::semi)) ||
+!SkipUntil(tok::r_brace, SkipUntilFlags::StopAtSemi)) {
+  TPA.Revert();

This seems error-prone. Given:

```
for (item *p = first, *oldp = p; p; p = p->next, delete [] oldp, oldp = p) {
  /*...*/;
}
```

... we'll decide the //delete-expression// is followed by a lambda. Likewise 
for cases like:

```
delete [] f->getPtr([] {
  return blah;
});
```

Our goal here should be a fast heuristic (don't use lookahead except when 
you're already confident you have a lambda) and zero false positives. How about 
these heuristics instead:

Assume that the `delete []` is actually `delete` followed by a lambda if either:

 * The next token is `{` or `<`, or
 * The next token is `(` and either
* the following token is `)` or
* the following tokens are a type specifier followed by an identifier

This should have no false positives, and only has false negatives if a lambda 
has an unnamed parameter or a parameter with a non-trivial parameter type. (For 
the last condition, we could try to tentatively parse an entire parameter and 
see if it has a name, which would handle all cases except an 
expression/declaration ambiguity in the parameter declaration, but that seems 
like overkill to me. This is already performing more lookahead than I'd like, 
but `delete []` expressions are rare enough that using two lookahead tokens for 
an improved error message seems OK.)


https://reviews.llvm.org/D36357



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


[PATCH] D41781: [DeclPrinter] Handle built-in C++ types in -ast-print.

2018-01-05 Thread Artem Belevich via Phabricator via cfe-commits
tra created this revision.
tra added a reviewer: arphaman.
Herald added subscribers: jlebar, sanjoy.

Fixes a crash in clang when it crashed with -ast-print on code that contained 
decltype(nullptr).


https://reviews.llvm.org/D41781

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/Sema/ast-print-cxx.cpp


Index: clang/test/Sema/ast-print-cxx.cpp
===
--- /dev/null
+++ clang/test/Sema/ast-print-cxx.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -std=c++11 %s -ast-print | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 %s -ast-print \
+// RUN:  | %clang_cc1 -std=c++11 -x c++ -fsyntax-only -
+
+// CHECK: typedef decltype(nullptr) nullptr_t;
+typedef decltype(nullptr) nullptr_t;
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -144,6 +144,8 @@
   BaseType = RTy->getPointeeType();
 else if (const AutoType *ATy = BaseType->getAs())
   BaseType = ATy->getDeducedType();
+else if (isa(BaseType))
+  break;
 else
   llvm_unreachable("Unknown declarator!");
   }


Index: clang/test/Sema/ast-print-cxx.cpp
===
--- /dev/null
+++ clang/test/Sema/ast-print-cxx.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -std=c++11 %s -ast-print | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 %s -ast-print \
+// RUN:  | %clang_cc1 -std=c++11 -x c++ -fsyntax-only -
+
+// CHECK: typedef decltype(nullptr) nullptr_t;
+typedef decltype(nullptr) nullptr_t;
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -144,6 +144,8 @@
   BaseType = RTy->getPointeeType();
 else if (const AutoType *ATy = BaseType->getAs())
   BaseType = ATy->getDeducedType();
+else if (isa(BaseType))
+  break;
 else
   llvm_unreachable("Unknown declarator!");
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41326: [clang-tidy] Added diagnostics about incorrect usage of NOLINT comment

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



Comment at: clang-tidy/ClangTidyDiagnosticConsumer.cpp:839-840
+case NolintCommentType::Nolint:
+  Message = "there is no diagnostics on this line, "
+"the NOLINT comment is redundant";
+  break;

xgsa wrote:
> aaron.ballman wrote:
> > xgsa wrote:
> > > aaron.ballman wrote:
> > > > xgsa wrote:
> > > > > aaron.ballman wrote:
> > > > > > I don't think the user is going to care about the distinction 
> > > > > > between no diagnostics being triggered and the expected diagnostic 
> > > > > > not being triggered. Also, it's dangerous to claim the lint comment 
> > > > > > is redundant because it's possible the user has NOLINT(foo, bar) 
> > > > > > and while foo is not triggered, bar still is. The NOLINT comment 
> > > > > > itself isn't redundant, it's that the check specified doesn't occur.
> > > > > > 
> > > > > > I would consolidate those scenarios into a single diagnostic: 
> > > > > > "expected diagnostic '%0' not generated" and "expected diagnostic 
> > > > > > '%0' not generated for the following line".
> > > > > > 
> > > > > > One concern I have with this functionality is: how should users 
> > > > > > silence a lint diagnostic that's target sensitive? e.g., a 
> > > > > > diagnostic that triggers based on the underlying type of size_t or 
> > > > > > the signedness of plain char. In that case, the diagnostic may 
> > > > > > trigger for some targets but not others, but on the targets where 
> > > > > > the diagnostic is not triggered, they now get a diagnostic they 
> > > > > > cannot silence. There should be a way to silence the "bad NOLINT" 
> > > > > > diagnostics.
> > > > > > I don't think the user is going to care about the distinction 
> > > > > > between no diagnostics being triggered and the expected diagnostic 
> > > > > > not being triggered. Also, it's dangerous to claim the lint comment 
> > > > > > is redundant because it's possible the user has NOLINT(foo, bar) 
> > > > > > and while foo is not triggered, bar still is. The NOLINT comment 
> > > > > > itself isn't redundant, it's that the check specified doesn't occur.
> > > > > > 
> > > > > > I would consolidate those scenarios into a single diagnostic: 
> > > > > > "expected diagnostic '%0' not generated" and "expected diagnostic 
> > > > > > '%0' not generated for the following line".
> > > > > 
> > > > > This branch of `if (NolintEntry.first.CheckName == 
> > > > > NolintCommentsCollector::AnyCheck)` reports only about 
> > > > > `NOLINT`/`NOLINTNEXTLINE` comments without check list, so I suppose 
> > > > > it's fair to claim that this comment is redundant (we have already 
> > > > > checked that no single check reported diagnostics on the line). The 
> > > > > `else`-branch reports the diagnostics for the definite check in a 
> > > > > list in case of `NOLINT(foo, bar)` (actually, if neither `foo` nor 
> > > > > `bar` checks reported diagnostics for the line, there will be a few 
> > > > > diagnostics from `nolint-usage` - not sure if it's good, but it seems 
> > > > > acceptable). That is why, I suppose, it is necessary to distinct 
> > > > > these cases.
> > > > > 
> > > > > > One concern I have with this functionality is: how should users 
> > > > > > silence a lint diagnostic that's target sensitive? e.g., a 
> > > > > > diagnostic that triggers based on the underlying type of size_t or 
> > > > > > the signedness of plain char. In that case, the diagnostic may 
> > > > > > trigger for some targets but not others, but on the targets where 
> > > > > > the diagnostic is not triggered, they now get a diagnostic they 
> > > > > > cannot silence. There should be a way to silence the "bad NOLINT" 
> > > > > > diagnostics.
> > > > > 
> > > > > There is such mechanism: it is possible to specify `// 
> > > > > NOLINT(nolint-usage)` or `//NOLINT(check1, check2, nolint-usage) to 
> > > > > silence the `nolint-usage`-mechanism. Please, see tests for details 
> > > > > and more examples. 
> > > > Can you provide an example where this distinction will make a 
> > > > difference to the user and help clarify a confusing situation? I cannot 
> > > > think of one, and it would be nice to simplify this code.
> > > > 
> > > > Thank you for the explanation about nolint-usage. This is not 
> > > > terminology I've seen before -- is this your invention, or is it a 
> > > > documented feature for NOLINT comments?
> > > >> Can you provide an example where this distinction will make a 
> > > >> difference to the user and help clarify a confusing situation? I 
> > > >> cannot think of one, and it would be nice to simplify this code.
> > > 
> > > Example for the diagnostics emitted in the `if`-branch:
> > > ```
> > > class A2 { explicit A2(int i); }; // NOLINT
> > > => warning: there is no diagnostics on this line, the NOLINT comment is 
> > > redundant
> > > ```
> > > Thus, the whole NOLINT comment should be removed.
> > > 
> > > Example for

[PATCH] D41780: Preserve unknown STDC pragma through preprocessor

2018-01-05 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

If you move all the #pragma STDC handlers from the lexer to the parser, you 
might be able to avoid adding an explicit STDC handler in 
PrintPreprocessedOutput.cpp.




Comment at: test/Preprocessor/pragma_unknown.c:32
 #pragma STDC SO_GREAT  // expected-warning {{unknown pragma in STDC namespace}}
 #pragma STDC   // expected-warning {{unknown pragma in STDC namespace}}
 

Maybe add CHECK lines to make sure these come out correctly?


Repository:
  rC Clang

https://reviews.llvm.org/D41780



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


[PATCH] D41780: Preserve unknown STDC pragma through preprocessor

2018-01-05 Thread Steven Wu via Phabricator via cfe-commits
steven_wu added a comment.

In https://reviews.llvm.org/D41780#968664, @efriedma wrote:

> If you move all the #pragma STDC handlers from the lexer to the parser, you 
> might be able to avoid adding an explicit STDC handler in 
> PrintPreprocessedOutput.cpp.


If it is safe to do that, I can change it. I am not sure if the other STDC 
pragmas would affect preprocessor output in any other way (which seems not).


Repository:
  rC Clang

https://reviews.llvm.org/D41780



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


[PATCH] D41780: Preserve unknown STDC pragma through preprocessor

2018-01-05 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Should be safe, I think; currently, FENV_ACCESS and CX_LIMITED_RANGE have no 
effect, and when we do start supporting them, we'll probably want to handle 
them in the parser, like we do for FP_CONTRACT.


Repository:
  rC Clang

https://reviews.llvm.org/D41780



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


[PATCH] D41764: [libcxx] [cmake] Add a config option LIBCXX_HAS_WIN32_THREADS for enforcing win32 threads

2018-01-05 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai accepted this revision.
smeenai added a comment.
This revision is now accepted and ready to land.

Can you add documentation for `_LIBCPP_HAS_THREAD_API_WIN32` to 
`docs/DesignDocs/ThreadingSupportAPI.rst`? It should have been documented 
before, but this seems like a good opportunity to correct that.

LGTM with that and the rename.


Repository:
  rCXX libc++

https://reviews.llvm.org/D41764



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


[PATCH] D36357: Added a better diagnostic when using the delete operator with lambdas

2018-01-05 Thread Nicolas Lesser via Phabricator via cfe-commits
Rakete added inline comments.



Comment at: lib/Parse/ParseExprCXX.cpp:2906-2912
+// Basic lookahead to check if we have a lambda expression. If we
+// encounter two braces with a semicolon, we can be pretty sure
+// that this is a lambda, not say a compound literal. 
+if (!SkipUntil(tok::l_brace, SkipUntilFlags::StopAtSemi) ||
+(NextToken().isNot(tok::r_brace) && !SkipUntil(tok::semi)) ||
+!SkipUntil(tok::r_brace, SkipUntilFlags::StopAtSemi)) {
+  TPA.Revert();

rsmith wrote:
> This seems error-prone. Given:
> 
> ```
> for (item *p = first, *oldp = p; p; p = p->next, delete [] oldp, oldp = p) {
>   /*...*/;
> }
> ```
> 
> ... we'll decide the //delete-expression// is followed by a lambda. Likewise 
> for cases like:
> 
> ```
> delete [] f->getPtr([] {
>   return blah;
> });
> ```
> 
> Our goal here should be a fast heuristic (don't use lookahead except when 
> you're already confident you have a lambda) and zero false positives. How 
> about these heuristics instead:
> 
> Assume that the `delete []` is actually `delete` followed by a lambda if 
> either:
> 
>  * The next token is `{` or `<`, or
>  * The next token is `(` and either
> * the following token is `)` or
> * the following tokens are a type specifier followed by an identifier
> 
> This should have no false positives, and only has false negatives if a lambda 
> has an unnamed parameter or a parameter with a non-trivial parameter type. 
> (For the last condition, we could try to tentatively parse an entire 
> parameter and see if it has a name, which would handle all cases except an 
> expression/declaration ambiguity in the parameter declaration, but that seems 
> like overkill to me. This is already performing more lookahead than I'd like, 
> but `delete []` expressions are rare enough that using two lookahead tokens 
> for an improved error message seems OK.)
Ah, I see. I had no idea that lookaheads were that expensive. Thanks for 
finding a better algorithm than me :)



https://reviews.llvm.org/D36357



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


[PATCH] D40819: Implement Attribute Target MultiVersioning (Improved edition!)

2018-01-05 Thread Erich Keane via Phabricator via cfe-commits
erichkeane marked 34 inline comments as done.
erichkeane added a comment.

Patch incoming, sorry it took so long!




Comment at: lib/CodeGen/CGBuiltin.cpp:7673
 
-Value *CodeGenFunction::EmitX86CpuInit() {
+Value *CodeGenFunction::EmitX86CpuInit(CGBuilderTy &Builder) {
   llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy,

echristo wrote:
> Why do you need to pass in a Builder?
Because when I first wrote this, the EmitResolver function was a free function. 
 I guess I missed this dependency along the way, thanks for the catch!



Comment at: lib/CodeGen/CodeGenFunction.cpp:2324
+  llvm::Triple::x86_64) &&
+ "Only implemented for x86 targets");
+

echristo wrote:
> Can you get here via trying to compile code for another cpu?
At the moment, no.  I'm asserting to make sure that is the case, and to be a 
hint for George/et-al who are implementing this in the future for other 
processors.



Comment at: lib/CodeGen/CodeGenModule.cpp:840-841
+
+  const auto *ND = cast(GD.getDecl());
+  UpdateMultiVersionNames(GD, ND);
+

rsmith wrote:
> I'm not especially enamoured with `getMangledName` mutating the IR. Can we 
> perform this rename as part of emitting the multiversion dispatcher or ifunc, 
> rather than here? (Or do we really not have anywhere else that this can live?)
Unfortunately it is too late at that point.  The problem is you have:

TARGET_SSE MVFunc(); 
TARGET_DEF MVFunc(); // At this point, a mangling-conflict occurs.

void foo() { 
MVFunc(); // Only at THIS point does the IFunc get created, too late to rewrite 
the SSE variant's name.  
}

That said, I moved it to a more appropriate place.



Comment at: lib/CodeGen/CodeGenModule.cpp:2056-2057
   const auto *F = cast(GD.getDecl());
+  if (F->isMultiVersion())
+return true;
   if (CodeGenOpts.OptimizationLevel == 0 && !F->hasAttr())

rsmith wrote:
> Please add a comment explaining this check. (I'm guessing the issue is that 
> we can't form a cross-translation-unit reference to the right function from 
> an IFUNC, so we can't rely on an available_externally definition actually 
> being usable? But it's not clear to me that this is the right resolution to 
> that, especially in light of the dllexport case below where it would not be 
> correct to emit the definition.)
The actual case I encountered was that when emitting the global in 
emitMultiVersionFunctions, the EmitGlobalDefinition was immediately skipping it 
here because it was an inline function.

I believe the correct response is to just call EmitGlobalFunctionDefinition 
from the emitMultiVersionFunctions handler.  This will have to be modified when 
I support virtual functions or constructors, but this will make it work.

IMO, the cross-TU issue you come up with would only be an issue when the value 
isn't emitted due to it being inline/static/etc.  In this case, the failed 
linking is an acceptable consequence to the user improperly providing a 
multiversion variant.



Comment at: lib/Sema/SemaDecl.cpp:9720
+  if (CheckMultiVersionFunction(*this, NewFD, Redeclaration, OldDecl,
+MergeTypeWithPrevious, Previous))
+return Redeclaration;

rsmith wrote:
> The parameter in `CheckMultiVersionFunction` corresponding to 
> `MergeTypeWithPrevious` here is called `MayNeedOverloadableChecks`, which is 
> also the name of a local variable in this function. Did you pass the wrong 
> bool? Or is the name of the parameter to `CheckMultiVersionFunction` wrong?
Looks like I'd just grabbed the wrong name for the parameter in 
CheckMultiVersionFunction.  Fixed!



Comment at: test/CodeGen/attr-target-mv-func-ptrs.c:10-15
+int bar() {
+  func(foo);
+  FuncPtr Free = &foo;
+  FuncPtr Free2 = foo;
+  return Free(1) + Free(2);
+}

rsmith wrote:
> What about uses in contexts where there is no target function type? For 
> example, `+foo;`
Added as a test in Sema/attr-target-mv.c.



Comment at: test/CodeGenCXX/attr-target-mv-member-funcs.cpp:3-8
+struct S {
+  int __attribute__((target("sse4.2"))) foo(int) { return 0; }
+  int __attribute__((target("arch=sandybridge"))) foo(int);
+  int __attribute__((target("arch=ivybridge"))) foo(int) { return 1; }
+  int __attribute__((target("default"))) foo(int) { return 2; }
+};

rsmith wrote:
> OK, multiversioned member functions! Let's look at some nasty corner cases!
> 
> Do you allow multiversioning of special member functions (copy constructor, 
> destructor, ...)? Some tests for that would be interesting. Note in 
> particular that `CXXRecordDecl::getDestructor` assumes that there is only one 
> destructor for a class, and I expect we make that assumption in a bunch of 
> other places too. Might be best to disallow multiversioning destructors for 
> now.
> 
> Do you allow a multiversion

[PATCH] D40819: Implement Attribute Target MultiVersioning (Improved edition!)

2018-01-05 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 128782.
erichkeane marked 7 inline comments as done.
erichkeane added a comment.

Fixes for all @echristo and @rsmith s comments.


https://reviews.llvm.org/D40819

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Decl.h
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TargetInfo.h
  include/clang/Basic/X86Target.def
  include/clang/Sema/Overload.h
  lib/Basic/Targets/X86.cpp
  lib/Basic/Targets/X86.h
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/Sema/Sema.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaOverload.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CodeGen/attr-target-mv-func-ptrs.c
  test/CodeGen/attr-target-mv-va-args.c
  test/CodeGen/attr-target-mv.c
  test/CodeGenCXX/attr-target-mv-constexpr.cpp
  test/CodeGenCXX/attr-target-mv-diff-ns.cpp
  test/CodeGenCXX/attr-target-mv-func-ptrs.cpp
  test/CodeGenCXX/attr-target-mv-member-funcs.cpp
  test/CodeGenCXX/attr-target-mv-out-of-line-defs.cpp
  test/CodeGenCXX/attr-target-mv-overloads.cpp
  test/Sema/attr-target-mv-bad-target.c
  test/Sema/attr-target-mv.c
  test/SemaCXX/attr-target-mv.cpp

Index: test/SemaCXX/attr-target-mv.cpp
===
--- /dev/null
+++ test/SemaCXX/attr-target-mv.cpp
@@ -0,0 +1,145 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu  -fsyntax-only -verify -fexceptions -fcxx-exceptions %s -std=c++14
+void __attribute__((target("sse4.2"))) no_default(void);
+void __attribute__((target("arch=sandybridge")))  no_default(void);
+
+void use1(void){
+  // expected-error@+1 {{no matching function for call to 'no_default'}}
+  no_default();
+}
+constexpr int __attribute__((target("sse4.2"))) foo(void) { return 0; }
+constexpr int __attribute__((target("arch=sandybridge"))) foo(void);
+//expected-error@+1 {{multiversioned function declaration has a different constexpr specification}}
+int __attribute__((target("arch=ivybridge"))) foo(void) {return 1;}
+constexpr int __attribute__((target("default"))) foo(void) { return 2; }
+
+int __attribute__((target("sse4.2"))) foo2(void) { return 0; }
+//expected-error@+2 {{multiversioned function declaration has a different constexpr specification}}
+//expected-note@+1 {{function multiversioning caused by this declaration}}
+constexpr int __attribute__((target("arch=sandybridge"))) foo2(void);
+int __attribute__((target("arch=ivybridge"))) foo2(void) {return 1;}
+int __attribute__((target("default"))) foo2(void) { return 2; }
+
+static int __attribute__((target("sse4.2"))) bar(void) { return 0; }
+static int __attribute__((target("arch=sandybridge"))) bar(void);
+//expected-error@+1 {{multiversioned function declaration has a different storage class}}
+int __attribute__((target("arch=ivybridge"))) bar(void) {return 1;}
+static int __attribute__((target("default"))) bar(void) { return 2; }
+
+int __attribute__((target("sse4.2"))) bar2(void) { return 0; }
+//expected-error@+2 {{multiversioned function declaration has a different storage class}}
+//expected-note@+1 {{function multiversioning caused by this declaration}}
+static int __attribute__((target("arch=sandybridge"))) bar2(void);
+int __attribute__((target("arch=ivybridge"))) bar2(void) {return 1;}
+int __attribute__((target("default"))) bar2(void) { return 2; }
+
+
+inline int __attribute__((target("sse4.2"))) baz(void) { return 0; }
+inline int __attribute__((target("arch=sandybridge"))) baz(void);
+//expected-error@+1 {{multiversioned function declaration has a different inline specification}}
+int __attribute__((target("arch=ivybridge"))) baz(void) {return 1;}
+inline int __attribute__((target("default"))) baz(void) { return 2; }
+
+int __attribute__((target("sse4.2"))) baz2(void) { return 0; }
+//expected-error@+2 {{multiversioned function declaration has a different inline specification}}
+//expected-note@+1 {{function multiversioning caused by this declaration}}
+inline int __attribute__((target("arch=sandybridge"))) baz2(void);
+int __attribute__((target("arch=ivybridge"))) baz2(void) {return 1;}
+int __attribute__((target("default"))) baz2(void) { return 2; }
+
+float __attribute__((target("sse4.2"))) bock(void) { return 0; }
+//expected-error@+2 {{multiversioned function declaration has a different return type}}
+//expected-note@+1 {{function multiversioning caused by this declaration}}
+int __attribute__((target("arch=sandybridge"))) bock(void);
+//expected-error@+2 {{multiversioned function declaration has a different return type}}
+//expected-note@+1 {{function multiversioning caused by this declaration}}
+int __attribute__((target("arch=ivybridge"))) bock(void) {return 1;}
+//expected-error@+2 {{multiversioned function declaration has a different return type}}
+//expected-note@+1 {{function multiversioning caused by this declaration}}
+int __attribute__((targ

[PATCH] D41750: Fix TLS support check for Darwin 32-bit simulator targets.

2018-01-05 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Thanks for prompt review.


https://reviews.llvm.org/D41750



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


r321890 - Fix TLS support check for Darwin 32-bit simulator targets.

2018-01-05 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Fri Jan  5 12:20:03 2018
New Revision: 321890

URL: http://llvm.org/viewvc/llvm-project?rev=321890&view=rev
Log:
Fix TLS support check for Darwin 32-bit simulator targets.

Also instead of checking architecture explicitly, use recently added
"simulator" environment in the triple.

rdar://problem/35083787

Reviewers: arphaman, bob.wilson

Reviewed By: arphaman

Subscribers: gparker42, cfe-commits

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

Modified:
cfe/trunk/lib/Basic/Targets/OSTargets.h
cfe/trunk/test/Sema/darwin-tls.c

Modified: cfe/trunk/lib/Basic/Targets/OSTargets.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/OSTargets.h?rev=321890&r1=321889&r2=321890&view=diff
==
--- cfe/trunk/lib/Basic/Targets/OSTargets.h (original)
+++ cfe/trunk/lib/Basic/Targets/OSTargets.h Fri Jan  5 12:20:03 2018
@@ -95,16 +95,22 @@ public:
 if (Triple.isMacOSX())
   this->TLSSupported = !Triple.isMacOSXVersionLT(10, 7);
 else if (Triple.isiOS()) {
-  // 64-bit iOS supported it from 8 onwards, 32-bit from 9 onwards.
-  if (Triple.getArch() == llvm::Triple::x86_64 ||
-  Triple.getArch() == llvm::Triple::aarch64)
+  // 64-bit iOS supported it from 8 onwards, 32-bit device from 9 onwards,
+  // 32-bit simulator from 10 onwards.
+  if (Triple.isArch64Bit())
 this->TLSSupported = !Triple.isOSVersionLT(8);
-  else if (Triple.getArch() == llvm::Triple::x86 ||
-   Triple.getArch() == llvm::Triple::arm ||
-   Triple.getArch() == llvm::Triple::thumb)
-this->TLSSupported = !Triple.isOSVersionLT(9);
-} else if (Triple.isWatchOS())
-  this->TLSSupported = !Triple.isOSVersionLT(2);
+  else if (Triple.isArch32Bit()) {
+if (!Triple.isSimulatorEnvironment())
+  this->TLSSupported = !Triple.isOSVersionLT(9);
+else
+  this->TLSSupported = !Triple.isOSVersionLT(10);
+  }
+} else if (Triple.isWatchOS()) {
+  if (!Triple.isSimulatorEnvironment())
+this->TLSSupported = !Triple.isOSVersionLT(2);
+  else
+this->TLSSupported = !Triple.isOSVersionLT(3);
+}
 
 this->MCountName = "\01mcount";
   }

Modified: cfe/trunk/test/Sema/darwin-tls.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/darwin-tls.c?rev=321890&r1=321889&r2=321890&view=diff
==
--- cfe/trunk/test/Sema/darwin-tls.c (original)
+++ cfe/trunk/test/Sema/darwin-tls.c Fri Jan  5 12:20:03 2018
@@ -1,12 +1,18 @@
 // RUN: not %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.6 %s 2>&1 | 
FileCheck %s --check-prefix NO-TLS
 // RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.7 %s 2>&1 | 
FileCheck %s --check-prefix TLS
+
 // RUN: not %clang_cc1 -fsyntax-only -triple arm64-apple-ios7.1 %s 2>&1 | 
FileCheck %s --check-prefix NO-TLS
 // RUN: %clang_cc1 -fsyntax-only -triple arm64-apple-ios8.0 %s 2>&1 | 
FileCheck %s --check-prefix TLS
 // RUN: not %clang_cc1 -fsyntax-only -triple thumbv7s-apple-ios8.3 %s 2>&1 | 
FileCheck %s --check-prefix NO-TLS
 // RUN: %clang_cc1 -fsyntax-only -triple thumbv7s-apple-ios9.0 %s 2>&1 | 
FileCheck %s --check-prefix TLS
 // RUN: %clang_cc1 -fsyntax-only -triple armv7-apple-ios9.0 %s 2>&1 | 
FileCheck %s --check-prefix TLS
+// RUN: not %clang_cc1 -fsyntax-only -triple i386-apple-ios9.0-simulator %s 
2>&1 | FileCheck %s --check-prefix NO-TLS
+// RUN: %clang_cc1 -fsyntax-only -triple i386-apple-ios10.0-simulator %s 2>&1 
| FileCheck %s --check-prefix TLS
+
 // RUN: not %clang_cc1 -fsyntax-only -triple thumbv7k-apple-watchos1.0 %s 2>&1 
| FileCheck %s --check-prefix NO-TLS
 // RUN: %clang_cc1 -fsyntax-only -triple thumbv7k-apple-watchos2.0 %s 2>&1 | 
FileCheck %s --check-prefix TLS
+// RUN: not %clang_cc1 -fsyntax-only -triple i386-apple-watchos2.0-simulator 
%s 2>&1 | FileCheck %s --check-prefix NO-TLS
+// RUN: %clang_cc1 -fsyntax-only -triple i386-apple-watchos3.0-simulator %s 
2>&1 | FileCheck %s --check-prefix TLS
 
 
 __thread int a;


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


[PATCH] D41750: Fix TLS support check for Darwin 32-bit simulator targets.

2018-01-05 Thread Volodymyr Sapsai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL321890: Fix TLS support check for Darwin 32-bit simulator 
targets. (authored by vsapsai, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41750?vs=128696&id=128783#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D41750

Files:
  cfe/trunk/lib/Basic/Targets/OSTargets.h
  cfe/trunk/test/Sema/darwin-tls.c


Index: cfe/trunk/test/Sema/darwin-tls.c
===
--- cfe/trunk/test/Sema/darwin-tls.c
+++ cfe/trunk/test/Sema/darwin-tls.c
@@ -1,12 +1,18 @@
 // RUN: not %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.6 %s 2>&1 | 
FileCheck %s --check-prefix NO-TLS
 // RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.7 %s 2>&1 | 
FileCheck %s --check-prefix TLS
+
 // RUN: not %clang_cc1 -fsyntax-only -triple arm64-apple-ios7.1 %s 2>&1 | 
FileCheck %s --check-prefix NO-TLS
 // RUN: %clang_cc1 -fsyntax-only -triple arm64-apple-ios8.0 %s 2>&1 | 
FileCheck %s --check-prefix TLS
 // RUN: not %clang_cc1 -fsyntax-only -triple thumbv7s-apple-ios8.3 %s 2>&1 | 
FileCheck %s --check-prefix NO-TLS
 // RUN: %clang_cc1 -fsyntax-only -triple thumbv7s-apple-ios9.0 %s 2>&1 | 
FileCheck %s --check-prefix TLS
 // RUN: %clang_cc1 -fsyntax-only -triple armv7-apple-ios9.0 %s 2>&1 | 
FileCheck %s --check-prefix TLS
+// RUN: not %clang_cc1 -fsyntax-only -triple i386-apple-ios9.0-simulator %s 
2>&1 | FileCheck %s --check-prefix NO-TLS
+// RUN: %clang_cc1 -fsyntax-only -triple i386-apple-ios10.0-simulator %s 2>&1 
| FileCheck %s --check-prefix TLS
+
 // RUN: not %clang_cc1 -fsyntax-only -triple thumbv7k-apple-watchos1.0 %s 2>&1 
| FileCheck %s --check-prefix NO-TLS
 // RUN: %clang_cc1 -fsyntax-only -triple thumbv7k-apple-watchos2.0 %s 2>&1 | 
FileCheck %s --check-prefix TLS
+// RUN: not %clang_cc1 -fsyntax-only -triple i386-apple-watchos2.0-simulator 
%s 2>&1 | FileCheck %s --check-prefix NO-TLS
+// RUN: %clang_cc1 -fsyntax-only -triple i386-apple-watchos3.0-simulator %s 
2>&1 | FileCheck %s --check-prefix TLS
 
 
 __thread int a;
Index: cfe/trunk/lib/Basic/Targets/OSTargets.h
===
--- cfe/trunk/lib/Basic/Targets/OSTargets.h
+++ cfe/trunk/lib/Basic/Targets/OSTargets.h
@@ -95,16 +95,22 @@
 if (Triple.isMacOSX())
   this->TLSSupported = !Triple.isMacOSXVersionLT(10, 7);
 else if (Triple.isiOS()) {
-  // 64-bit iOS supported it from 8 onwards, 32-bit from 9 onwards.
-  if (Triple.getArch() == llvm::Triple::x86_64 ||
-  Triple.getArch() == llvm::Triple::aarch64)
+  // 64-bit iOS supported it from 8 onwards, 32-bit device from 9 onwards,
+  // 32-bit simulator from 10 onwards.
+  if (Triple.isArch64Bit())
 this->TLSSupported = !Triple.isOSVersionLT(8);
-  else if (Triple.getArch() == llvm::Triple::x86 ||
-   Triple.getArch() == llvm::Triple::arm ||
-   Triple.getArch() == llvm::Triple::thumb)
-this->TLSSupported = !Triple.isOSVersionLT(9);
-} else if (Triple.isWatchOS())
-  this->TLSSupported = !Triple.isOSVersionLT(2);
+  else if (Triple.isArch32Bit()) {
+if (!Triple.isSimulatorEnvironment())
+  this->TLSSupported = !Triple.isOSVersionLT(9);
+else
+  this->TLSSupported = !Triple.isOSVersionLT(10);
+  }
+} else if (Triple.isWatchOS()) {
+  if (!Triple.isSimulatorEnvironment())
+this->TLSSupported = !Triple.isOSVersionLT(2);
+  else
+this->TLSSupported = !Triple.isOSVersionLT(3);
+}
 
 this->MCountName = "\01mcount";
   }


Index: cfe/trunk/test/Sema/darwin-tls.c
===
--- cfe/trunk/test/Sema/darwin-tls.c
+++ cfe/trunk/test/Sema/darwin-tls.c
@@ -1,12 +1,18 @@
 // RUN: not %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.6 %s 2>&1 | FileCheck %s --check-prefix NO-TLS
 // RUN: %clang_cc1 -fsyntax-only -triple x86_64-apple-macosx10.7 %s 2>&1 | FileCheck %s --check-prefix TLS
+
 // RUN: not %clang_cc1 -fsyntax-only -triple arm64-apple-ios7.1 %s 2>&1 | FileCheck %s --check-prefix NO-TLS
 // RUN: %clang_cc1 -fsyntax-only -triple arm64-apple-ios8.0 %s 2>&1 | FileCheck %s --check-prefix TLS
 // RUN: not %clang_cc1 -fsyntax-only -triple thumbv7s-apple-ios8.3 %s 2>&1 | FileCheck %s --check-prefix NO-TLS
 // RUN: %clang_cc1 -fsyntax-only -triple thumbv7s-apple-ios9.0 %s 2>&1 | FileCheck %s --check-prefix TLS
 // RUN: %clang_cc1 -fsyntax-only -triple armv7-apple-ios9.0 %s 2>&1 | FileCheck %s --check-prefix TLS
+// RUN: not %clang_cc1 -fsyntax-only -triple i386-apple-ios9.0-simulator %s 2>&1 | FileCheck %s --check-prefix NO-TLS
+// RUN: %clang_cc1 -fsyntax-only -triple i386-apple-ios10.0-simulator %s 2>&1 | FileCheck %s --check-prefix TLS
+
 // RUN: not %clang_cc1 -fsyntax-only -triple thumbv7k-apple-watchos1.0 %s 2>&1 | FileCheck %s --check-prefix NO-TLS
 // RUN: %clang_cc1 -fsy

[PATCH] D41039: Add support for attribute "trivial_abi"

2018-01-05 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 128781.

https://reviews.llvm.org/D41039

Files:
  include/clang/AST/Decl.h
  include/clang/AST/DeclCXX.h
  include/clang/AST/Type.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/AST/DeclCXX.cpp
  lib/AST/Type.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaType.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CodeGenCXX/trivial_abi.cpp
  test/Misc/pragma-attribute-supported-attributes-list.test
  test/SemaObjCXX/attr-trivial-abi.mm

Index: test/SemaObjCXX/attr-trivial-abi.mm
===
--- /dev/null
+++ test/SemaObjCXX/attr-trivial-abi.mm
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -std=c++11 -fobjc-runtime-has-weak -fobjc-weak -fobjc-arc -fsyntax-only -verify %s
+
+void __attribute__((trivial_abi)) foo(); // expected-warning {{'trivial_abi' attribute only applies to classes}}
+
+struct [[clang::trivial_abi]] S0 {
+  int a;
+};
+
+struct __attribute__((trivial_abi)) S1 {
+  int a;
+};
+
+struct __attribute__((trivial_abi)) S2 { // expected-warning {{'trivial_abi' cannot be applied to 'S2'}}
+  __weak id a;
+};
+
+struct __attribute__((trivial_abi)) S3 { // expected-warning {{'trivial_abi' cannot be applied to 'S3'}}
+  virtual void m();
+};
+
+struct S4 {
+  int a;
+};
+
+struct __attribute__((trivial_abi)) S5 : public virtual S4 { // expected-warning {{'trivial_abi' cannot be applied to 'S5'}}
+};
+
+struct __attribute__((trivial_abi)) S9 : public S4 {
+};
+
+struct S6 {
+  __weak id a;
+};
+
+struct __attribute__((trivial_abi)) S7 { // expected-warning {{'trivial_abi' cannot be applied to 'S7'}}
+  S6 a;
+};
+
+struct __attribute__((trivial_abi)) S11 { // expected-warning {{'trivial_abi' cannot be applied to 'S11'}}
+  S6 a[2];
+};
+
+struct __attribute__((trivial_abi(1))) S8 { // expected-error {{'trivial_abi' attribute takes no arguments}}
+  int a;
+};
+
+template
+struct __attribute__((trivial_abi)) S10 {
+  T p;
+};
+
+S10 p1;
+
+// Do not warn when 'trivial_abi' is used to annotate a template class.
+S10<__weak id> p2;
Index: test/Misc/pragma-attribute-supported-attributes-list.test
===
--- test/Misc/pragma-attribute-supported-attributes-list.test
+++ test/Misc/pragma-attribute-supported-attributes-list.test
@@ -2,7 +2,7 @@
 
 // The number of supported attributes should never go down!
 
-// CHECK: #pragma clang attribute supports 66 attributes:
+// CHECK: #pragma clang attribute supports 67 attributes:
 // CHECK-NEXT: AMDGPUFlatWorkGroupSize (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumSGPR (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumVGPR (SubjectMatchRule_function)
@@ -66,6 +66,7 @@
 // CHECK-NEXT: TLSModel (SubjectMatchRule_variable_is_thread_local)
 // CHECK-NEXT: Target (SubjectMatchRule_function)
 // CHECK-NEXT: TestTypestate (SubjectMatchRule_function_is_member)
+// CHECK-NEXT: TrivialABI (SubjectMatchRule_record)
 // CHECK-NEXT: WarnUnusedResult (SubjectMatchRule_objc_method, SubjectMatchRule_enum, SubjectMatchRule_record, SubjectMatchRule_hasType_functionType)
 // CHECK-NEXT: XRayInstrument (SubjectMatchRule_function, SubjectMatchRule_objc_method)
 // CHECK-NEXT: XRayLogArgs (SubjectMatchRule_function, SubjectMatchRule_objc_method)
Index: test/CodeGenCXX/trivial_abi.cpp
===
--- /dev/null
+++ test/CodeGenCXX/trivial_abi.cpp
@@ -0,0 +1,196 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++11 -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: %[[STRUCT_SMALL:.*]] = type { i32* }
+// CHECK: %[[STRUCT_LARGE:.*]] = type { i32*, [128 x i32] }
+// CHECK: %[[STRUCT_TRIVIAL:.*]] = type { i32 }
+// CHECK: %[[STRUCT_NONTRIVIAL:.*]] = type { i32 }
+
+struct __attribute__((trivial_abi)) Small {
+  int *p;
+  Small();
+  ~Small();
+  Small(const Small &);
+  Small &operator=(const Small &);
+};
+
+struct __attribute__((trivial_abi)) Large {
+  int *p;
+  int a[128];
+  Large();
+  ~Large();
+  Large(const Large &);
+  Large &operator=(const Large &);
+};
+
+struct Trivial {
+  int a;
+};
+
+struct NonTrivial {
+  NonTrivial();
+  ~NonTrivial();
+  int a;
+};
+
+struct HasTrivial {
+  Small s;
+  Trivial m;
+};
+
+struct HasNonTrivial {
+  Small s;
+  NonTrivial m;
+};
+
+// CHECK: define void @_Z14testParamSmall5Small(i64 %[[A_COERCE:.*]])
+// CHECK: %[[A:.*]] = alloca %[[STRUCT_SMALL]], align 8
+// CHECK: %[[COERCE_DIVE:.*]] = getelementptr inbounds %[[STRUCT_SMALL]], %[[STRUCT_SMALL]]* %[[A]], i32 0, i32 0
+// CHECK: %[[COERCE_VAL_IP:.*]] = inttoptr i64 %[[A_COERCE]] to i32*
+// CHECK: store i32* %[[COERCE_VAL_IP]], i32** %[[COERCE_DIVE]], align 8
+// CHECK: %[[CALL:.*]] = call %[[STRUCT_SMALL]]

[PATCH] D41039: Add support for attribute "trivial_abi"

2018-01-05 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

Sorry, the patch I've just uploaded was missing some changes I made.


https://reviews.llvm.org/D41039



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


[PATCH] D41039: Add support for attribute "trivial_abi"

2018-01-05 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 128784.
ahatanak added a comment.

- Serialize/deserialize the bits I added to FunctionDecl and CXXRecordDecl.
- Enable passing non-trivial structs when clang abi-compat version is 4.0 or 
lower.
- Fix a bug in Sema::CheckCompletedCXXClass where the CXXRecordDecl flags were 
not being set when the class had a defaulted special function. Fixed it by 
renaming finishedUserProvidedMethod to setTrivialForCallFlags and calling it in 
Sema::CheckCompletedCXXClass.


https://reviews.llvm.org/D41039

Files:
  include/clang/AST/Decl.h
  include/clang/AST/DeclCXX.h
  include/clang/AST/Type.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/AST/DeclCXX.cpp
  lib/AST/Type.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaType.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CodeGenCXX/trivial_abi.cpp
  test/Misc/pragma-attribute-supported-attributes-list.test
  test/SemaObjCXX/attr-trivial-abi.mm

Index: test/SemaObjCXX/attr-trivial-abi.mm
===
--- /dev/null
+++ test/SemaObjCXX/attr-trivial-abi.mm
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -std=c++11 -fobjc-runtime-has-weak -fobjc-weak -fobjc-arc -fsyntax-only -verify %s
+
+void __attribute__((trivial_abi)) foo(); // expected-warning {{'trivial_abi' attribute only applies to classes}}
+
+struct [[clang::trivial_abi]] S0 {
+  int a;
+};
+
+struct __attribute__((trivial_abi)) S1 {
+  int a;
+};
+
+struct __attribute__((trivial_abi)) S2 { // expected-warning {{'trivial_abi' cannot be applied to 'S2'}}
+  __weak id a;
+};
+
+struct __attribute__((trivial_abi)) S3 { // expected-warning {{'trivial_abi' cannot be applied to 'S3'}}
+  virtual void m();
+};
+
+struct S4 {
+  int a;
+};
+
+struct __attribute__((trivial_abi)) S5 : public virtual S4 { // expected-warning {{'trivial_abi' cannot be applied to 'S5'}}
+};
+
+struct __attribute__((trivial_abi)) S9 : public S4 {
+};
+
+struct S6 {
+  __weak id a;
+};
+
+struct __attribute__((trivial_abi)) S7 { // expected-warning {{'trivial_abi' cannot be applied to 'S7'}}
+  S6 a;
+};
+
+struct __attribute__((trivial_abi)) S11 { // expected-warning {{'trivial_abi' cannot be applied to 'S11'}}
+  S6 a[2];
+};
+
+struct __attribute__((trivial_abi(1))) S8 { // expected-error {{'trivial_abi' attribute takes no arguments}}
+  int a;
+};
+
+template
+struct __attribute__((trivial_abi)) S10 {
+  T p;
+};
+
+S10 p1;
+
+// Do not warn when 'trivial_abi' is used to annotate a template class.
+S10<__weak id> p2;
Index: test/Misc/pragma-attribute-supported-attributes-list.test
===
--- test/Misc/pragma-attribute-supported-attributes-list.test
+++ test/Misc/pragma-attribute-supported-attributes-list.test
@@ -2,7 +2,7 @@
 
 // The number of supported attributes should never go down!
 
-// CHECK: #pragma clang attribute supports 66 attributes:
+// CHECK: #pragma clang attribute supports 67 attributes:
 // CHECK-NEXT: AMDGPUFlatWorkGroupSize (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumSGPR (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumVGPR (SubjectMatchRule_function)
@@ -66,6 +66,7 @@
 // CHECK-NEXT: TLSModel (SubjectMatchRule_variable_is_thread_local)
 // CHECK-NEXT: Target (SubjectMatchRule_function)
 // CHECK-NEXT: TestTypestate (SubjectMatchRule_function_is_member)
+// CHECK-NEXT: TrivialABI (SubjectMatchRule_record)
 // CHECK-NEXT: WarnUnusedResult (SubjectMatchRule_objc_method, SubjectMatchRule_enum, SubjectMatchRule_record, SubjectMatchRule_hasType_functionType)
 // CHECK-NEXT: XRayInstrument (SubjectMatchRule_function, SubjectMatchRule_objc_method)
 // CHECK-NEXT: XRayLogArgs (SubjectMatchRule_function, SubjectMatchRule_objc_method)
Index: test/CodeGenCXX/trivial_abi.cpp
===
--- /dev/null
+++ test/CodeGenCXX/trivial_abi.cpp
@@ -0,0 +1,197 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++11 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++11 -fclang-abi-compat=4.0 -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: %[[STRUCT_SMALL:.*]] = type { i32* }
+// CHECK: %[[STRUCT_LARGE:.*]] = type { i32*, [128 x i32] }
+// CHECK: %[[STRUCT_TRIVIAL:.*]] = type { i32 }
+// CHECK: %[[STRUCT_NONTRIVIAL:.*]] = type { i32 }
+
+struct __attribute__((trivial_abi)) Small {
+  int *p;
+  Small();
+  ~Small();
+  Small(const Small &);
+  Small &operator=(const Small &);
+};
+
+struct __attribute__((trivial_abi)) Large {
+  int *p;
+  int a[128];
+  Large();
+  ~Large();
+  Large(const Large &);
+  Large &operator=(const Large &);
+};
+
+struct Trivial {
+  int a;
+};
+
+struct NonTrivia

[libcxx] r321896 - [cmake] Add a config option LIBCXX_HAS_WIN32_THREAD_API for enforcing win32 threads

2018-01-05 Thread Martin Storsjo via cfe-commits
Author: mstorsjo
Date: Fri Jan  5 12:48:29 2018
New Revision: 321896

URL: http://llvm.org/viewvc/llvm-project?rev=321896&view=rev
Log:
[cmake] Add a config option LIBCXX_HAS_WIN32_THREAD_API for enforcing win32 
threads

This allows keeping libcxx using win32 threads even if a
version of pthread.h is installed.

This matches the existing cmake option LIBCXX_HAS_PTHREAD_API.

Also add missing documentation about the internal define
_LIBCPP_HAS_THREAD_API_WIN32.

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

Modified:
libcxx/trunk/CMakeLists.txt
libcxx/trunk/docs/DesignDocs/ThreadingSupportAPI.rst
libcxx/trunk/include/__config_site.in

Modified: libcxx/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/CMakeLists.txt?rev=321896&r1=321895&r2=321896&view=diff
==
--- libcxx/trunk/CMakeLists.txt (original)
+++ libcxx/trunk/CMakeLists.txt Fri Jan  5 12:48:29 2018
@@ -202,6 +202,7 @@ option(LIBCXX_ENABLE_MONOTONIC_CLOCK
This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON)
 option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" 
OFF)
 option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread 
API" OFF)
+option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of 
win32 thread API" OFF)
 option(LIBCXX_HAS_EXTERNAL_THREAD_API
   "Build libc++ with an externalized threading API.
This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF)
@@ -273,6 +274,10 @@ if(NOT LIBCXX_ENABLE_THREADS)
 message(FATAL_ERROR "LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY can only be set "
 "to ON when LIBCXX_ENABLE_THREADS is also set to ON.")
   endif()
+  if (LIBCXX_HAS_WIN32_THREAD_API)
+message(FATAL_ERROR "LIBCXX_HAS_WIN32_THREAD_API can only be set to ON"
+" when LIBCXX_ENABLE_THREADS is also set to ON.")
+  endif()
 
 endif()
 
@@ -287,6 +292,19 @@ if (LIBCXX_HAS_EXTERNAL_THREAD_API)
 "and LIBCXX_HAS_PTHREAD_API cannot be both"
 "set to ON at the same time.")
   endif()
+  if (LIBCXX_HAS_WIN32_THREAD_API)
+message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
+"and LIBCXX_HAS_WIN32_THREAD_API cannot be both"
+"set to ON at the same time.")
+  endif()
+endif()
+
+if (LIBCXX_HAS_PTHREAD_API)
+  if (LIBCXX_HAS_WIN32_THREAD_API)
+message(FATAL_ERROR "The options LIBCXX_HAS_PTHREAD_API"
+"and LIBCXX_HAS_WIN32_THREAD_API cannot be both"
+"set to ON at the same time.")
+  endif()
 endif()
 
 # Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE
@@ -613,6 +631,7 @@ config_define_if_not(LIBCXX_ENABLE_THREA
 
 config_define_if(LIBCXX_HAS_PTHREAD_API _LIBCPP_HAS_THREAD_API_PTHREAD)
 config_define_if(LIBCXX_HAS_EXTERNAL_THREAD_API 
_LIBCPP_HAS_THREAD_API_EXTERNAL)
+config_define_if(LIBCXX_HAS_WIN32_THREAD_API _LIBCPP_HAS_THREAD_API_WIN32)
 config_define_if(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY 
_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL)
 config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC)
 config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME)

Modified: libcxx/trunk/docs/DesignDocs/ThreadingSupportAPI.rst
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/docs/DesignDocs/ThreadingSupportAPI.rst?rev=321896&r1=321895&r2=321896&view=diff
==
--- libcxx/trunk/docs/DesignDocs/ThreadingSupportAPI.rst (original)
+++ libcxx/trunk/docs/DesignDocs/ThreadingSupportAPI.rst Fri Jan  5 12:48:29 
2018
@@ -66,6 +66,10 @@ Threading Configuration Macros
   This macro is defined when libc++ should use POSIX threads to implement the
   internal threading API.
 
+**_LIBCPP_HAS_THREAD_API_WIN32**
+  This macro is defined when libc++ should use Win32 threads to implement the
+  internal threading API.
+
 **_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL**
   This macro is defined when libc++ expects the definitions of the internal
   threading API to be provided by an external library. When defined

Modified: libcxx/trunk/include/__config_site.in
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config_site.in?rev=321896&r1=321895&r2=321896&view=diff
==
--- libcxx/trunk/include/__config_site.in (original)
+++ libcxx/trunk/include/__config_site.in Fri Jan  5 12:48:29 2018
@@ -23,6 +23,7 @@
 #cmakedefine _LIBCPP_HAS_MUSL_LIBC
 #cmakedefine _LIBCPP_HAS_THREAD_API_PTHREAD
 #cmakedefine _LIBCPP_HAS_THREAD_API_EXTERNAL
+#cmakedefine _LIBCPP_HAS_THREAD_API_WIN32
 #cmakedefine _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL
 #cmakedefine _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS
 #cmakedefine _LIBCPP_NO_VCRUNTIME


___
cfe-commits maili

[PATCH] D41764: [libcxx] [cmake] Add a config option LIBCXX_HAS_WIN32_THREADS for enforcing win32 threads

2018-01-05 Thread Martin Storsjö via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL321896: [cmake] Add a config option 
LIBCXX_HAS_WIN32_THREAD_API for enforcing win32… (authored by mstorsjo, 
committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41764?vs=128734&id=128786#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D41764

Files:
  libcxx/trunk/CMakeLists.txt
  libcxx/trunk/docs/DesignDocs/ThreadingSupportAPI.rst
  libcxx/trunk/include/__config_site.in


Index: libcxx/trunk/docs/DesignDocs/ThreadingSupportAPI.rst
===
--- libcxx/trunk/docs/DesignDocs/ThreadingSupportAPI.rst
+++ libcxx/trunk/docs/DesignDocs/ThreadingSupportAPI.rst
@@ -66,6 +66,10 @@
   This macro is defined when libc++ should use POSIX threads to implement the
   internal threading API.
 
+**_LIBCPP_HAS_THREAD_API_WIN32**
+  This macro is defined when libc++ should use Win32 threads to implement the
+  internal threading API.
+
 **_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL**
   This macro is defined when libc++ expects the definitions of the internal
   threading API to be provided by an external library. When defined
Index: libcxx/trunk/include/__config_site.in
===
--- libcxx/trunk/include/__config_site.in
+++ libcxx/trunk/include/__config_site.in
@@ -23,6 +23,7 @@
 #cmakedefine _LIBCPP_HAS_MUSL_LIBC
 #cmakedefine _LIBCPP_HAS_THREAD_API_PTHREAD
 #cmakedefine _LIBCPP_HAS_THREAD_API_EXTERNAL
+#cmakedefine _LIBCPP_HAS_THREAD_API_WIN32
 #cmakedefine _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL
 #cmakedefine _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS
 #cmakedefine _LIBCPP_NO_VCRUNTIME
Index: libcxx/trunk/CMakeLists.txt
===
--- libcxx/trunk/CMakeLists.txt
+++ libcxx/trunk/CMakeLists.txt
@@ -202,6 +202,7 @@
This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON)
 option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" 
OFF)
 option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread 
API" OFF)
+option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of 
win32 thread API" OFF)
 option(LIBCXX_HAS_EXTERNAL_THREAD_API
   "Build libc++ with an externalized threading API.
This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF)
@@ -273,6 +274,10 @@
 message(FATAL_ERROR "LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY can only be set "
 "to ON when LIBCXX_ENABLE_THREADS is also set to ON.")
   endif()
+  if (LIBCXX_HAS_WIN32_THREAD_API)
+message(FATAL_ERROR "LIBCXX_HAS_WIN32_THREAD_API can only be set to ON"
+" when LIBCXX_ENABLE_THREADS is also set to ON.")
+  endif()
 
 endif()
 
@@ -287,6 +292,19 @@
 "and LIBCXX_HAS_PTHREAD_API cannot be both"
 "set to ON at the same time.")
   endif()
+  if (LIBCXX_HAS_WIN32_THREAD_API)
+message(FATAL_ERROR "The options LIBCXX_HAS_EXTERNAL_THREAD_API"
+"and LIBCXX_HAS_WIN32_THREAD_API cannot be both"
+"set to ON at the same time.")
+  endif()
+endif()
+
+if (LIBCXX_HAS_PTHREAD_API)
+  if (LIBCXX_HAS_WIN32_THREAD_API)
+message(FATAL_ERROR "The options LIBCXX_HAS_PTHREAD_API"
+"and LIBCXX_HAS_WIN32_THREAD_API cannot be both"
+"set to ON at the same time.")
+  endif()
 endif()
 
 # Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE
@@ -613,6 +631,7 @@
 
 config_define_if(LIBCXX_HAS_PTHREAD_API _LIBCPP_HAS_THREAD_API_PTHREAD)
 config_define_if(LIBCXX_HAS_EXTERNAL_THREAD_API 
_LIBCPP_HAS_THREAD_API_EXTERNAL)
+config_define_if(LIBCXX_HAS_WIN32_THREAD_API _LIBCPP_HAS_THREAD_API_WIN32)
 config_define_if(LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY 
_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL)
 config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC)
 config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME)


Index: libcxx/trunk/docs/DesignDocs/ThreadingSupportAPI.rst
===
--- libcxx/trunk/docs/DesignDocs/ThreadingSupportAPI.rst
+++ libcxx/trunk/docs/DesignDocs/ThreadingSupportAPI.rst
@@ -66,6 +66,10 @@
   This macro is defined when libc++ should use POSIX threads to implement the
   internal threading API.
 
+**_LIBCPP_HAS_THREAD_API_WIN32**
+  This macro is defined when libc++ should use Win32 threads to implement the
+  internal threading API.
+
 **_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL**
   This macro is defined when libc++ expects the definitions of the internal
   threading API to be provided by an external library. When defined
Index: libcxx/trunk/include/__config_site.in
===
--- libcxx/trunk/include/__config_site.in
+++ libcxx/trunk/include/__config_site.in
@@ -23,6 +23,7 @@
 #cmakedefine _LIBC

[PATCH] D41039: Add support for attribute "trivial_abi"

2018-01-05 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: include/clang/AST/DeclCXX.h:1489-1491
+  bool shouldBeDestructedInCallee() const {
+return data().CanPassInRegisters && hasNonTrivialDestructor();
+  }

This will return incorrect results on MSVC, where every class type should be 
destroyed in the callee. Since this is only used  by CodeGen, and only used in 
combination with the MSVC "destroy right-to-left in callee" ABI setting, please 
sink it to CodeGen.



Comment at: lib/CodeGen/CGCall.cpp:3518
+ CGM.getCXXABI().getRecordArgABI(RD) != CGCXXABI::RAA_Default) ||
+TypeDestructedInCallee;
 if (DestroyedInCallee)

This looks wrong (but the wrongness is pre-existing): in the weird MSVC x86_64 
case where a small object of class type is passed in registers despite having a 
non-trivial destructor, this will set `DestroyedInCallee` to false, meaning 
that the parameter will be destroyed twice, in both the caller and callee.

And yep, that's exactly what both Clang and MSVC do: 
https://godbolt.org/g/zjeQq6

If we fixed that, we could unconditionally `setExternallyDestructed()` here. 
But let's leave that discussion for a separate patch :)



Comment at: lib/CodeGen/CGDecl.cpp:1822
+  bool IsScalar = hasScalarEvaluationKind(Ty);
+  if ((!IsScalar && !CurFuncIsThunk &&
+   getTarget().getCXXABI().areArgsDestroyedLeftToRightInCallee()) ||

Should these conditions not also apply to the `shouldBeDestructedInCallee` 
case? We don't want to destroy `trivial_abi` parameters in thunks, only in the 
eventual target function.



Comment at: lib/Sema/SemaDeclCXX.cpp:5923
+M->setTrivialForCall(HasTrivialABI);
+Record->finishedUserProvidedMethod(M);
+  }

This should have a different name if you're only going to call it for 
user-provided copy ctors, move ctors, and dtors.



Comment at: lib/Sema/SemaDeclCXX.cpp:12108-12114
+  if (!IsTrivialForCall) {
+if (ClassDecl->needsOverloadResolutionForCopyConstructor())
+  IsTrivialForCall =
+  SpecialMemberIsTrivial(CopyConstructor, CXXCopyConstructor, true);
+else
+  IsTrivialForCall = ClassDecl->hasTrivialCopyConstructorForCall();
+  }

Nit: can you use the same form of `?:` expression as is used a few lines above 
to make it obvious to a reader that this computation parallels that one?


https://reviews.llvm.org/D41039



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


[PATCH] D41781: [DeclPrinter] Handle built-in C++ types in -ast-print.

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

Never mind. There must be something else going on in the case where I've 
discovered the crash. the test case in this patch does not really reproduce the 
issue by itself. :-(


https://reviews.llvm.org/D41781



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


r321899 - Add AST dumping support for _Generic expressions.

2018-01-05 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Jan  5 13:31:07 2018
New Revision: 321899

URL: http://llvm.org/viewvc/llvm-project?rev=321899&view=rev
Log:
Add AST dumping support for _Generic expressions.

Modified:
cfe/trunk/lib/AST/ASTDumper.cpp

Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=321899&r1=321898&r2=321899&view=diff
==
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Fri Jan  5 13:31:07 2018
@@ -539,6 +539,7 @@ namespace  {
 void VisitAddrLabelExpr(const AddrLabelExpr *Node);
 void VisitBlockExpr(const BlockExpr *Node);
 void VisitOpaqueValueExpr(const OpaqueValueExpr *Node);
+void VisitGenericSelectionExpr(const GenericSelectionExpr *E);
 
 // C++
 void VisitCXXNamedCastExpr(const CXXNamedCastExpr *Node);
@@ -1946,10 +1947,15 @@ void ASTDumper::dumpStmt(const Stmt *S)
   return;
 }
 
+// Some statements have custom mechanisms for dumping their children.
 if (const DeclStmt *DS = dyn_cast(S)) {
   VisitDeclStmt(DS);
   return;
 }
+if (const GenericSelectionExpr *GSE = dyn_cast(S)) {
+  VisitGenericSelectionExpr(GSE);
+  return;
+}
 
 ConstStmtVisitor::Visit(S);
 
@@ -2272,6 +2278,32 @@ void ASTDumper::VisitOpaqueValueExpr(con
 dumpStmt(Source);
 }
 
+void ASTDumper::VisitGenericSelectionExpr(const GenericSelectionExpr *E) {
+  VisitExpr(E);
+  if (E->isResultDependent())
+OS << " result_dependent";
+  dumpStmt(E->getControllingExpr());
+  dumpTypeAsChild(E->getControllingExpr()->getType()); // FIXME: remove
+
+  for (unsigned I = 0, N = E->getNumAssocs(); I != N; ++I) {
+dumpChild([=] {
+  if (const TypeSourceInfo *TSI = E->getAssocTypeSourceInfo(I)) {
+OS << "case ";
+dumpType(TSI->getType());
+  } else {
+OS << "default";
+  }
+
+  if (!E->isResultDependent() && E->getResultIndex() == I)
+OS << " selected";
+
+  if (const TypeSourceInfo *TSI = E->getAssocTypeSourceInfo(I))
+dumpTypeAsChild(TSI->getType());
+  dumpStmt(E->getAssocExpr(I));
+});
+  }
+}
+
 // GNU extensions.
 
 void ASTDumper::VisitAddrLabelExpr(const AddrLabelExpr *Node) {


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


[PATCH] D41523: xmmintrin.h documentation fixes and updates

2018-01-05 Thread Katya Romanova via Phabricator via cfe-commits
kromanova added a comment.

In https://reviews.llvm.org/D41523#968359, @RKSimon wrote:

> Sort of related - should we enable -Wdocumentation (it's currently -Wall and 
> -Weverything might be too much) on the respective clang builtin tests? 
> Doesn't have to be part of this patch.


Good idea, Simon. I will give it a shot. Could you please let me know the name 
of the directory, where clang builtin tests are located?


https://reviews.llvm.org/D41523



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


[PATCH] D41523: xmmintrin.h documentation fixes and updates

2018-01-05 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

The builtins are tested in tests like test/CodeGen/sse-builtins.c


https://reviews.llvm.org/D41523



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


[PATCH] D40819: Implement Attribute Target MultiVersioning (Improved edition!)

2018-01-05 Thread Erich Keane via Phabricator via cfe-commits
erichkeane planned changes to this revision.
erichkeane added a comment.

Forgot friend functions, Working on it now, sorry about that.


https://reviews.llvm.org/D40819



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


[PATCH] D41733: [Driver] Suggest correctly spelled driver options

2018-01-05 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno accepted this revision.
bruno added a comment.
This revision is now accepted and ready to land.

Thanks! LGTM.


Repository:
  rC Clang

https://reviews.llvm.org/D41733



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


[PATCH] D40819: Implement Attribute Target MultiVersioning (Improved edition!)

2018-01-05 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 128792.
erichkeane added a comment.
This revision is now accepted and ready to land.

Added test for friend functions.


https://reviews.llvm.org/D40819

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Decl.h
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TargetInfo.h
  include/clang/Basic/X86Target.def
  include/clang/Sema/Overload.h
  lib/Basic/Targets/X86.cpp
  lib/Basic/Targets/X86.h
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/Sema/Sema.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaOverload.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CodeGen/attr-target-mv-func-ptrs.c
  test/CodeGen/attr-target-mv-va-args.c
  test/CodeGen/attr-target-mv.c
  test/CodeGenCXX/attr-target-mv-constexpr.cpp
  test/CodeGenCXX/attr-target-mv-diff-ns.cpp
  test/CodeGenCXX/attr-target-mv-func-ptrs.cpp
  test/CodeGenCXX/attr-target-mv-member-funcs.cpp
  test/CodeGenCXX/attr-target-mv-out-of-line-defs.cpp
  test/CodeGenCXX/attr-target-mv-overloads.cpp
  test/Sema/attr-target-mv-bad-target.c
  test/Sema/attr-target-mv.c
  test/SemaCXX/attr-target-mv.cpp

Index: test/SemaCXX/attr-target-mv.cpp
===
--- /dev/null
+++ test/SemaCXX/attr-target-mv.cpp
@@ -0,0 +1,145 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu  -fsyntax-only -verify -fexceptions -fcxx-exceptions %s -std=c++14
+void __attribute__((target("sse4.2"))) no_default(void);
+void __attribute__((target("arch=sandybridge")))  no_default(void);
+
+void use1(void){
+  // expected-error@+1 {{no matching function for call to 'no_default'}}
+  no_default();
+}
+constexpr int __attribute__((target("sse4.2"))) foo(void) { return 0; }
+constexpr int __attribute__((target("arch=sandybridge"))) foo(void);
+//expected-error@+1 {{multiversioned function declaration has a different constexpr specification}}
+int __attribute__((target("arch=ivybridge"))) foo(void) {return 1;}
+constexpr int __attribute__((target("default"))) foo(void) { return 2; }
+
+int __attribute__((target("sse4.2"))) foo2(void) { return 0; }
+//expected-error@+2 {{multiversioned function declaration has a different constexpr specification}}
+//expected-note@+1 {{function multiversioning caused by this declaration}}
+constexpr int __attribute__((target("arch=sandybridge"))) foo2(void);
+int __attribute__((target("arch=ivybridge"))) foo2(void) {return 1;}
+int __attribute__((target("default"))) foo2(void) { return 2; }
+
+static int __attribute__((target("sse4.2"))) bar(void) { return 0; }
+static int __attribute__((target("arch=sandybridge"))) bar(void);
+//expected-error@+1 {{multiversioned function declaration has a different storage class}}
+int __attribute__((target("arch=ivybridge"))) bar(void) {return 1;}
+static int __attribute__((target("default"))) bar(void) { return 2; }
+
+int __attribute__((target("sse4.2"))) bar2(void) { return 0; }
+//expected-error@+2 {{multiversioned function declaration has a different storage class}}
+//expected-note@+1 {{function multiversioning caused by this declaration}}
+static int __attribute__((target("arch=sandybridge"))) bar2(void);
+int __attribute__((target("arch=ivybridge"))) bar2(void) {return 1;}
+int __attribute__((target("default"))) bar2(void) { return 2; }
+
+
+inline int __attribute__((target("sse4.2"))) baz(void) { return 0; }
+inline int __attribute__((target("arch=sandybridge"))) baz(void);
+//expected-error@+1 {{multiversioned function declaration has a different inline specification}}
+int __attribute__((target("arch=ivybridge"))) baz(void) {return 1;}
+inline int __attribute__((target("default"))) baz(void) { return 2; }
+
+int __attribute__((target("sse4.2"))) baz2(void) { return 0; }
+//expected-error@+2 {{multiversioned function declaration has a different inline specification}}
+//expected-note@+1 {{function multiversioning caused by this declaration}}
+inline int __attribute__((target("arch=sandybridge"))) baz2(void);
+int __attribute__((target("arch=ivybridge"))) baz2(void) {return 1;}
+int __attribute__((target("default"))) baz2(void) { return 2; }
+
+float __attribute__((target("sse4.2"))) bock(void) { return 0; }
+//expected-error@+2 {{multiversioned function declaration has a different return type}}
+//expected-note@+1 {{function multiversioning caused by this declaration}}
+int __attribute__((target("arch=sandybridge"))) bock(void);
+//expected-error@+2 {{multiversioned function declaration has a different return type}}
+//expected-note@+1 {{function multiversioning caused by this declaration}}
+int __attribute__((target("arch=ivybridge"))) bock(void) {return 1;}
+//expected-error@+2 {{multiversioned function declaration has a different return type}}
+//expected-note@+1 {{function multiversioning caused by this declaration}}
+int __attribute__((target("default

[PATCH] D40712: [Driver] Add flag enabling the function stack size section that was added in r319430

2018-01-05 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno accepted this revision.
bruno added a comment.
This revision is now accepted and ready to land.

Thanks! LGTM


https://reviews.llvm.org/D40712



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


[PATCH] D40819: Implement Attribute Target MultiVersioning (Improved edition!)

2018-01-05 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 128793.
erichkeane added a comment.

Sorry for the thrash, thought of a better way to do the test just as I clicked 
'save' last time :)


https://reviews.llvm.org/D40819

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Decl.h
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TargetInfo.h
  include/clang/Basic/X86Target.def
  include/clang/Sema/Overload.h
  lib/Basic/Targets/X86.cpp
  lib/Basic/Targets/X86.h
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/Sema/Sema.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaOverload.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CodeGen/attr-target-mv-func-ptrs.c
  test/CodeGen/attr-target-mv-va-args.c
  test/CodeGen/attr-target-mv.c
  test/CodeGenCXX/attr-target-mv-constexpr.cpp
  test/CodeGenCXX/attr-target-mv-diff-ns.cpp
  test/CodeGenCXX/attr-target-mv-func-ptrs.cpp
  test/CodeGenCXX/attr-target-mv-member-funcs.cpp
  test/CodeGenCXX/attr-target-mv-out-of-line-defs.cpp
  test/CodeGenCXX/attr-target-mv-overloads.cpp
  test/Sema/attr-target-mv-bad-target.c
  test/Sema/attr-target-mv.c
  test/SemaCXX/attr-target-mv.cpp

Index: test/SemaCXX/attr-target-mv.cpp
===
--- /dev/null
+++ test/SemaCXX/attr-target-mv.cpp
@@ -0,0 +1,145 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu  -fsyntax-only -verify -fexceptions -fcxx-exceptions %s -std=c++14
+void __attribute__((target("sse4.2"))) no_default(void);
+void __attribute__((target("arch=sandybridge")))  no_default(void);
+
+void use1(void){
+  // expected-error@+1 {{no matching function for call to 'no_default'}}
+  no_default();
+}
+constexpr int __attribute__((target("sse4.2"))) foo(void) { return 0; }
+constexpr int __attribute__((target("arch=sandybridge"))) foo(void);
+//expected-error@+1 {{multiversioned function declaration has a different constexpr specification}}
+int __attribute__((target("arch=ivybridge"))) foo(void) {return 1;}
+constexpr int __attribute__((target("default"))) foo(void) { return 2; }
+
+int __attribute__((target("sse4.2"))) foo2(void) { return 0; }
+//expected-error@+2 {{multiversioned function declaration has a different constexpr specification}}
+//expected-note@+1 {{function multiversioning caused by this declaration}}
+constexpr int __attribute__((target("arch=sandybridge"))) foo2(void);
+int __attribute__((target("arch=ivybridge"))) foo2(void) {return 1;}
+int __attribute__((target("default"))) foo2(void) { return 2; }
+
+static int __attribute__((target("sse4.2"))) bar(void) { return 0; }
+static int __attribute__((target("arch=sandybridge"))) bar(void);
+//expected-error@+1 {{multiversioned function declaration has a different storage class}}
+int __attribute__((target("arch=ivybridge"))) bar(void) {return 1;}
+static int __attribute__((target("default"))) bar(void) { return 2; }
+
+int __attribute__((target("sse4.2"))) bar2(void) { return 0; }
+//expected-error@+2 {{multiversioned function declaration has a different storage class}}
+//expected-note@+1 {{function multiversioning caused by this declaration}}
+static int __attribute__((target("arch=sandybridge"))) bar2(void);
+int __attribute__((target("arch=ivybridge"))) bar2(void) {return 1;}
+int __attribute__((target("default"))) bar2(void) { return 2; }
+
+
+inline int __attribute__((target("sse4.2"))) baz(void) { return 0; }
+inline int __attribute__((target("arch=sandybridge"))) baz(void);
+//expected-error@+1 {{multiversioned function declaration has a different inline specification}}
+int __attribute__((target("arch=ivybridge"))) baz(void) {return 1;}
+inline int __attribute__((target("default"))) baz(void) { return 2; }
+
+int __attribute__((target("sse4.2"))) baz2(void) { return 0; }
+//expected-error@+2 {{multiversioned function declaration has a different inline specification}}
+//expected-note@+1 {{function multiversioning caused by this declaration}}
+inline int __attribute__((target("arch=sandybridge"))) baz2(void);
+int __attribute__((target("arch=ivybridge"))) baz2(void) {return 1;}
+int __attribute__((target("default"))) baz2(void) { return 2; }
+
+float __attribute__((target("sse4.2"))) bock(void) { return 0; }
+//expected-error@+2 {{multiversioned function declaration has a different return type}}
+//expected-note@+1 {{function multiversioning caused by this declaration}}
+int __attribute__((target("arch=sandybridge"))) bock(void);
+//expected-error@+2 {{multiversioned function declaration has a different return type}}
+//expected-note@+1 {{function multiversioning caused by this declaration}}
+int __attribute__((target("arch=ivybridge"))) bock(void) {return 1;}
+//expected-error@+2 {{multiversioned function declaration has a different return type}}
+//expected-note@+1 {{function multiversioning caused by this declaration}}
+int __attribute_

[PATCH] D41780: Preserve unknown STDC pragma through preprocessor

2018-01-05 Thread Steven Wu via Phabricator via cfe-commits
steven_wu updated this revision to Diff 128794.
steven_wu added a comment.

Move STDC pragma handler to parser.


Repository:
  rC Clang

https://reviews.llvm.org/D41780

Files:
  include/clang/Basic/DiagnosticLexKinds.td
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Parse/Parser.h
  lib/Lex/Pragma.cpp
  lib/Parse/ParsePragma.cpp
  test/Preprocessor/pragma_unknown.c

Index: test/Preprocessor/pragma_unknown.c
===
--- test/Preprocessor/pragma_unknown.c
+++ test/Preprocessor/pragma_unknown.c
@@ -1,29 +1,45 @@
 // RUN: %clang_cc1 -fsyntax-only -Wunknown-pragmas -verify %s
-// RUN: %clang_cc1 -E %s | FileCheck --strict-whitespace %s
+// RUN: %clang_cc1 -E %s 2>&1 | FileCheck --strict-whitespace %s
 
 // GCC doesn't expand macro args for unrecognized pragmas.
 #define bar xX
 #pragma foo bar   // expected-warning {{unknown pragma ignored}}
+// CHECK-NOT: unknown pragma in STDC namespace
 // CHECK: {{^}}#pragma foo bar{{$}}
 
 #pragma STDC FP_CONTRACT ON
 #pragma STDC FP_CONTRACT OFF
 #pragma STDC FP_CONTRACT DEFAULT
 #pragma STDC FP_CONTRACT IN_BETWEEN  // expected-warning {{expected 'ON' or 'OFF' or 'DEFAULT' in pragma}}
+// CHECK: {{^}}#pragma STDC FP_CONTRACT ON{{$}}
+// CHECK: {{^}}#pragma STDC FP_CONTRACT OFF{{$}}
+// CHECK: {{^}}#pragma STDC FP_CONTRACT DEFAULT{{$}}
+// CHECK: {{^}}#pragma STDC FP_CONTRACT IN_BETWEEN{{$}}
 
 #pragma STDC FENV_ACCESS ON  // expected-warning {{pragma STDC FENV_ACCESS ON is not supported, ignoring pragma}}
 #pragma STDC FENV_ACCESS OFF
 #pragma STDC FENV_ACCESS DEFAULT
 #pragma STDC FENV_ACCESS IN_BETWEEN   // expected-warning {{expected 'ON' or 'OFF' or 'DEFAULT' in pragma}}
+// CHECK: {{^}}#pragma STDC FENV_ACCESS ON{{$}}
+// CHECK: {{^}}#pragma STDC FENV_ACCESS OFF{{$}}
+// CHECK: {{^}}#pragma STDC FENV_ACCESS DEFAULT{{$}}
+// CHECK: {{^}}#pragma STDC FENV_ACCESS IN_BETWEEN{{$}}
 
 #pragma STDC CX_LIMITED_RANGE ON
 #pragma STDC CX_LIMITED_RANGE OFF
 #pragma STDC CX_LIMITED_RANGE DEFAULT 
 #pragma STDC CX_LIMITED_RANGE IN_BETWEEN   // expected-warning {{expected 'ON' or 'OFF' or 'DEFAULT' in pragma}}
+// CHECK: {{^}}#pragma STDC CX_LIMITED_RANGE ON{{$}}
+// CHECK: {{^}}#pragma STDC CX_LIMITED_RANGE OFF{{$}}
+// CHECK: {{^}}#pragma STDC CX_LIMITED_RANGE DEFAULT{{$}}
+// CHECK: {{^}}#pragma STDC CX_LIMITED_RANGE IN_BETWEEN{{$}}
 
 #pragma STDC CX_LIMITED_RANGE// expected-warning {{expected 'ON' or 'OFF' or 'DEFAULT' in pragma}}
 #pragma STDC CX_LIMITED_RANGE ON FULL POWER  // expected-warning {{expected end of directive in pragma}}
+// CHECK: {{^}}#pragma STDC CX_LIMITED_RANGE{{$}}
+// CHECK: {{^}}#pragma STDC CX_LIMITED_RANGE ON FULL POWER{{$}}
 
 #pragma STDC SO_GREAT  // expected-warning {{unknown pragma in STDC namespace}}
 #pragma STDC   // expected-warning {{unknown pragma in STDC namespace}}
-
+// CHECK: {{^}}#pragma STDC SO_GREAT{{$}}
+// CHECK: {{^}}#pragma STDC{{$}}
Index: lib/Parse/ParsePragma.cpp
===
--- lib/Parse/ParsePragma.cpp
+++ lib/Parse/ParsePragma.cpp
@@ -95,6 +95,44 @@
 Token &FirstToken) override;
 };
 
+// Pragma STDC implementations.
+
+/// PragmaSTDC_FENV_ACCESSHandler - "\#pragma STDC FENV_ACCESS ...".
+struct PragmaSTDC_FENV_ACCESSHandler : public PragmaHandler {
+  PragmaSTDC_FENV_ACCESSHandler() : PragmaHandler("FENV_ACCESS") {}
+
+  void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
+Token &Tok) override {
+tok::OnOffSwitch OOS;
+if (PP.LexOnOffSwitch(OOS))
+ return;
+if (OOS == tok::OOS_ON)
+  PP.Diag(Tok, diag::warn_stdc_fenv_access_not_supported);
+  }
+};
+
+/// PragmaSTDC_CX_LIMITED_RANGEHandler - "\#pragma STDC CX_LIMITED_RANGE ...".
+struct PragmaSTDC_CX_LIMITED_RANGEHandler : public PragmaHandler {
+  PragmaSTDC_CX_LIMITED_RANGEHandler() : PragmaHandler("CX_LIMITED_RANGE") {}
+
+  void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
+Token &Tok) override {
+tok::OnOffSwitch OOS;
+PP.LexOnOffSwitch(OOS);
+  }
+};
+
+/// PragmaSTDC_UnknownHandler - "\#pragma STDC ...".
+struct PragmaSTDC_UnknownHandler : public PragmaHandler {
+  PragmaSTDC_UnknownHandler() = default;
+
+  void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
+Token &UnknownTok) override {
+// C99 6.10.6p2, unknown forms are not allowed.
+PP.Diag(UnknownTok, diag::ext_stdc_pragma_ignored);
+  }
+};
+
 struct PragmaFPHandler : public PragmaHandler {
   PragmaFPHandler() : PragmaHandler("fp") {}
   void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
@@ -233,6 +271,15 @@
   FPContractHandler.reset(new PragmaFPContractHandler());
   PP.AddPragmaHandler("STDC", FPContractHandler.get());
 
+  STDCFENVHandler.reset(new PragmaSTDC_FENV_ACCESSHandler());
+  PP.AddPragmaHandler("STDC", STDCFENVHandler.get());
+
+  STDCCXLIMITHandler.reset(new PragmaSTD

[PATCH] D40983: Generate Libclang invocation reproducers using a new -cc1gen-reproducer option

2018-01-05 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno accepted this revision.
bruno added a comment.
This revision is now accepted and ready to land.

Makes sense, LGTM.

Should we add documentation explaining how to use this? I'm fine if it comes in 
a follow up commit.


https://reviews.llvm.org/D40983



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


[PATCH] D41785: Print the qualified name when dumping deserialized decls.

2018-01-05 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev created this revision.
v.g.vassilev added a reviewer: rsmith.

This is very useful to understand and debug the lazy template specializations 
used in pch and modules.


Repository:
  rC Clang

https://reviews.llvm.org/D41785

Files:
  lib/Frontend/FrontendAction.cpp


Index: lib/Frontend/FrontendAction.cpp
===
--- lib/Frontend/FrontendAction.cpp
+++ lib/Frontend/FrontendAction.cpp
@@ -88,8 +88,10 @@
 
   void DeclRead(serialization::DeclID ID, const Decl *D) override {
 llvm::outs() << "PCH DECL: " << D->getDeclKindName();
-if (const NamedDecl *ND = dyn_cast(D))
-  llvm::outs() << " - " << *ND;
+if (const NamedDecl *ND = dyn_cast(D)) {
+  llvm::outs() << " - ";
+  ND->printQualifiedName(llvm::outs());
+}
 llvm::outs() << "\n";
 
 DelegatingDeserializationListener::DeclRead(ID, D);


Index: lib/Frontend/FrontendAction.cpp
===
--- lib/Frontend/FrontendAction.cpp
+++ lib/Frontend/FrontendAction.cpp
@@ -88,8 +88,10 @@
 
   void DeclRead(serialization::DeclID ID, const Decl *D) override {
 llvm::outs() << "PCH DECL: " << D->getDeclKindName();
-if (const NamedDecl *ND = dyn_cast(D))
-  llvm::outs() << " - " << *ND;
+if (const NamedDecl *ND = dyn_cast(D)) {
+  llvm::outs() << " - ";
+  ND->printQualifiedName(llvm::outs());
+}
 llvm::outs() << "\n";
 
 DelegatingDeserializationListener::DeclRead(ID, D);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r321906 - Track shadow modules with a generation counter.

2018-01-05 Thread Bruno Cardoso Lopes via cfe-commits
Author: bruno
Date: Fri Jan  5 14:13:56 2018
New Revision: 321906

URL: http://llvm.org/viewvc/llvm-project?rev=321906&view=rev
Log:
Track shadow modules with a generation counter.

This is a follow up to r321855, closing the gap between our internal shadow
modules implementation and upstream. It has been tested for longer and
provides a better approach for tracking shadow modules. Mostly NFCI.

rdar://problem/23612102

Modified:
cfe/trunk/include/clang/Lex/HeaderSearch.h
cfe/trunk/include/clang/Lex/ModuleMap.h
cfe/trunk/lib/Frontend/FrontendAction.cpp
cfe/trunk/lib/Lex/HeaderSearch.cpp
cfe/trunk/lib/Lex/ModuleMap.cpp

Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=321906&r1=321905&r2=321906&view=diff
==
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Fri Jan  5 14:13:56 2018
@@ -726,7 +726,6 @@ private:
   LoadModuleMapResult loadModuleMapFileImpl(const FileEntry *File,
 bool IsSystem,
 const DirectoryEntry *Dir,
-bool IsExplicitlyProvided,
 FileID ID = FileID(),
 unsigned *Offset = nullptr);
 

Modified: cfe/trunk/include/clang/Lex/ModuleMap.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/ModuleMap.h?rev=321906&r1=321905&r2=321906&view=diff
==
--- cfe/trunk/include/clang/Lex/ModuleMap.h (original)
+++ cfe/trunk/include/clang/Lex/ModuleMap.h Fri Jan  5 14:13:56 2018
@@ -198,16 +198,14 @@ private:
   /// header.
   llvm::DenseMap UmbrellaDirs;
 
-  /// \brief The set of modules provided explicitly (e.g. by 
-fmodule-map-file),
-  /// which are allowed to shadow other implicitly discovered modules.
-  llvm::DenseSet ExplicitlyProvidedModules;
+  /// \brief A generation counter that is used to test whether modules of the
+  /// same name may shadow or are illegal redefintions.
+  ///
+  /// Modules from earlier scopes may shadow modules from later ones.
+  /// Modules from the same scope may not have the same name.
+  unsigned CurrentModuleScopeID = 0;
 
-  bool mayShadowModuleBeingParsed(Module *ExistingModule,
-  bool IsExplicitlyProvided) {
-assert(!ExistingModule->Parent && "expected top-level module");
-return !IsExplicitlyProvided &&
-   ExplicitlyProvidedModules.count(ExistingModule);
-  }
+  llvm::DenseMap ModuleScopeIDs;
 
   /// \brief The set of attributes that can be attached to a module.
   struct Attributes {
@@ -489,9 +487,9 @@ public:
   ///
   /// \returns The found or newly-created module, along with a boolean value
   /// that will be true if the module is newly-created.
-  std::pair
-  findOrCreateModule(StringRef Name, Module *Parent, bool IsFramework,
- bool IsExplicit, bool UsesExplicitModuleMapFile = false);
+  std::pair findOrCreateModule(StringRef Name, Module *Parent,
+   bool IsFramework,
+   bool IsExplicit);
 
   /// \brief Create a 'global module' for a C++ Modules TS module interface
   /// unit.
@@ -521,6 +519,19 @@ public:
   Module *createShadowedModule(StringRef Name, bool IsFramework,
Module *ShadowingModule);
 
+  /// \brief Creates a new declaration scope for module names, allowing
+  /// previously defined modules to shadow definitions from the new scope.
+  ///
+  /// \note Module names from earlier scopes will shadow names from the new
+  /// scope, which is the opposite of how shadowing works for variables.
+  void finishModuleDeclarationScope() { CurrentModuleScopeID += 1; }
+
+  bool mayShadowNewModule(Module *ExistingModule) {
+assert(!ExistingModule->Parent && "expected top-level module");
+assert(ModuleScopeIDs.count(ExistingModule) && "unknown module");
+return ModuleScopeIDs[ExistingModule] < CurrentModuleScopeID;
+  }
+
   /// \brief Retrieve the module map file containing the definition of the 
given
   /// module.
   ///
@@ -606,8 +617,6 @@ public:
   /// \brief Marks this header as being excluded from the given module.
   void excludeHeader(Module *Mod, Module::Header Header);
 
-  void setExplicitlyProvided(Module *Mod);
-
   /// \brief Parse the given module map file, and record any modules we 
   /// encounter.
   ///
@@ -634,7 +643,6 @@ public:
   /// \returns true if an error occurred, false otherwise.
   bool parseModuleMapFile(const FileEntry *File, bool IsSystem,
   const DirectoryEntry *HomeDir,
-  bool IsExplicitlyProvided = false,
 

[PATCH] D41039: Add support for attribute "trivial_abi"

2018-01-05 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 128798.
ahatanak marked an inline comment as done.

https://reviews.llvm.org/D41039

Files:
  include/clang/AST/Decl.h
  include/clang/AST/DeclCXX.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/AST/DeclCXX.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaType.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CodeGenCXX/trivial_abi.cpp
  test/Misc/pragma-attribute-supported-attributes-list.test
  test/SemaObjCXX/attr-trivial-abi.mm

Index: test/SemaObjCXX/attr-trivial-abi.mm
===
--- /dev/null
+++ test/SemaObjCXX/attr-trivial-abi.mm
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -std=c++11 -fobjc-runtime-has-weak -fobjc-weak -fobjc-arc -fsyntax-only -verify %s
+
+void __attribute__((trivial_abi)) foo(); // expected-warning {{'trivial_abi' attribute only applies to classes}}
+
+struct [[clang::trivial_abi]] S0 {
+  int a;
+};
+
+struct __attribute__((trivial_abi)) S1 {
+  int a;
+};
+
+struct __attribute__((trivial_abi)) S2 { // expected-warning {{'trivial_abi' cannot be applied to 'S2'}}
+  __weak id a;
+};
+
+struct __attribute__((trivial_abi)) S3 { // expected-warning {{'trivial_abi' cannot be applied to 'S3'}}
+  virtual void m();
+};
+
+struct S4 {
+  int a;
+};
+
+struct __attribute__((trivial_abi)) S5 : public virtual S4 { // expected-warning {{'trivial_abi' cannot be applied to 'S5'}}
+};
+
+struct __attribute__((trivial_abi)) S9 : public S4 {
+};
+
+struct S6 {
+  __weak id a;
+};
+
+struct __attribute__((trivial_abi)) S7 { // expected-warning {{'trivial_abi' cannot be applied to 'S7'}}
+  S6 a;
+};
+
+struct __attribute__((trivial_abi)) S11 { // expected-warning {{'trivial_abi' cannot be applied to 'S11'}}
+  S6 a[2];
+};
+
+struct __attribute__((trivial_abi(1))) S8 { // expected-error {{'trivial_abi' attribute takes no arguments}}
+  int a;
+};
+
+template
+struct __attribute__((trivial_abi)) S10 {
+  T p;
+};
+
+S10 p1;
+
+// Do not warn when 'trivial_abi' is used to annotate a template class.
+S10<__weak id> p2;
Index: test/Misc/pragma-attribute-supported-attributes-list.test
===
--- test/Misc/pragma-attribute-supported-attributes-list.test
+++ test/Misc/pragma-attribute-supported-attributes-list.test
@@ -2,7 +2,7 @@
 
 // The number of supported attributes should never go down!
 
-// CHECK: #pragma clang attribute supports 66 attributes:
+// CHECK: #pragma clang attribute supports 67 attributes:
 // CHECK-NEXT: AMDGPUFlatWorkGroupSize (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumSGPR (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumVGPR (SubjectMatchRule_function)
@@ -66,6 +66,7 @@
 // CHECK-NEXT: TLSModel (SubjectMatchRule_variable_is_thread_local)
 // CHECK-NEXT: Target (SubjectMatchRule_function)
 // CHECK-NEXT: TestTypestate (SubjectMatchRule_function_is_member)
+// CHECK-NEXT: TrivialABI (SubjectMatchRule_record)
 // CHECK-NEXT: WarnUnusedResult (SubjectMatchRule_objc_method, SubjectMatchRule_enum, SubjectMatchRule_record, SubjectMatchRule_hasType_functionType)
 // CHECK-NEXT: XRayInstrument (SubjectMatchRule_function, SubjectMatchRule_objc_method)
 // CHECK-NEXT: XRayLogArgs (SubjectMatchRule_function, SubjectMatchRule_objc_method)
Index: test/CodeGenCXX/trivial_abi.cpp
===
--- /dev/null
+++ test/CodeGenCXX/trivial_abi.cpp
@@ -0,0 +1,197 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++11 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++11 -fclang-abi-compat=4.0 -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: %[[STRUCT_SMALL:.*]] = type { i32* }
+// CHECK: %[[STRUCT_LARGE:.*]] = type { i32*, [128 x i32] }
+// CHECK: %[[STRUCT_TRIVIAL:.*]] = type { i32 }
+// CHECK: %[[STRUCT_NONTRIVIAL:.*]] = type { i32 }
+
+struct __attribute__((trivial_abi)) Small {
+  int *p;
+  Small();
+  ~Small();
+  Small(const Small &);
+  Small &operator=(const Small &);
+};
+
+struct __attribute__((trivial_abi)) Large {
+  int *p;
+  int a[128];
+  Large();
+  ~Large();
+  Large(const Large &);
+  Large &operator=(const Large &);
+};
+
+struct Trivial {
+  int a;
+};
+
+struct NonTrivial {
+  NonTrivial();
+  ~NonTrivial();
+  int a;
+};
+
+struct HasTrivial {
+  Small s;
+  Trivial m;
+};
+
+struct HasNonTrivial {
+  Small s;
+  NonTrivial m;
+};
+
+// CHECK: define void @_Z14testParamSmall5Small(i64 %[[A_COERCE:.*]])
+// CHECK: %[[A:.*]] = alloca %[[STRUCT_SMALL]], align 8
+// CHECK: %[[COERCE_DIVE:.*]] = getelementptr inbounds %[[STRUCT_SMALL]], %[[STRUCT_SMALL]]* %[[A]], i32 0, i32 0
+// CHECK: %[[COERCE_VAL_IP:.*]] = inttoptr i64 %

[PATCH] D41039: Add support for attribute "trivial_abi"

2018-01-05 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak marked 3 inline comments as done.
ahatanak added inline comments.



Comment at: include/clang/AST/DeclCXX.h:1489-1491
+  bool shouldBeDestructedInCallee() const {
+return data().CanPassInRegisters && hasNonTrivialDestructor();
+  }

rsmith wrote:
> This will return incorrect results on MSVC, where every class type should be 
> destroyed in the callee. Since this is only used  by CodeGen, and only used 
> in combination with the MSVC "destroy right-to-left in callee" ABI setting, 
> please sink it to CodeGen.
I sank the code to CGCall.cpp and CGDecl.cpp and removed the method.



Comment at: lib/CodeGen/CGCall.cpp:3518
+ CGM.getCXXABI().getRecordArgABI(RD) != CGCXXABI::RAA_Default) ||
+TypeDestructedInCallee;
 if (DestroyedInCallee)

rsmith wrote:
> This looks wrong (but the wrongness is pre-existing): in the weird MSVC 
> x86_64 case where a small object of class type is passed in registers despite 
> having a non-trivial destructor, this will set `DestroyedInCallee` to false, 
> meaning that the parameter will be destroyed twice, in both the caller and 
> callee.
> 
> And yep, that's exactly what both Clang and MSVC do: 
> https://godbolt.org/g/zjeQq6
> 
> If we fixed that, we could unconditionally `setExternallyDestructed()` here. 
> But let's leave that discussion for a separate patch :)
OK, I'll leave this for future work.



Comment at: lib/Sema/SemaDeclCXX.cpp:5923
+M->setTrivialForCall(HasTrivialABI);
+Record->finishedUserProvidedMethod(M);
+  }

rsmith wrote:
> This should have a different name if you're only going to call it for 
> user-provided copy ctors, move ctors, and dtors.
I renamed the function to setTrivialForCallFlags.



Comment at: lib/Sema/SemaDeclCXX.cpp:12108-12114
+  if (!IsTrivialForCall) {
+if (ClassDecl->needsOverloadResolutionForCopyConstructor())
+  IsTrivialForCall =
+  SpecialMemberIsTrivial(CopyConstructor, CXXCopyConstructor, true);
+else
+  IsTrivialForCall = ClassDecl->hasTrivialCopyConstructorForCall();
+  }

rsmith wrote:
> Nit: can you use the same form of `?:` expression as is used a few lines 
> above to make it obvious to a reader that this computation parallels that one?
Done. I clang-formated the code above too.


https://reviews.llvm.org/D41039



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


[PATCH] D41416: [modules] [pch] Do not deserialize all lazy template specializations when looking for one.

2018-01-05 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 128797.
v.g.vassilev added a comment.

Reduce hash collisions for template specializations.

Currently when we hash a tag type the visitor calls `ODRHash::AddDecl` which 
mostly relies on the decl name give distinct hash value. The types coming from 
template specializations have very similar properties (including decl names). 
For those we need to provide more information in order to disambiguate them.

This patch adds the template arguments for the template specialization decl 
corresponding to its type. We manage to reduce further the amount of 
deserializations from 1117 down to 451.


https://reviews.llvm.org/D41416

Files:
  include/clang/AST/DeclTemplate.h
  lib/AST/DeclTemplate.cpp
  lib/AST/ODRHash.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/Modules/cxx-templates.cpp

Index: test/Modules/cxx-templates.cpp
===
--- test/Modules/cxx-templates.cpp
+++ test/Modules/cxx-templates.cpp
@@ -249,24 +249,24 @@
 
 // CHECK-DUMP:  ClassTemplateDecl {{.*}} <{{.*[/\\]}}cxx-templates-common.h:1:1, {{.*}}>  col:{{.*}} in cxx_templates_common SomeTemplate
 // CHECK-DUMP:ClassTemplateSpecializationDecl {{.*}} prev {{.*}} SomeTemplate
-// CHECK-DUMP-NEXT: TemplateArgument type 'char [2]'
+// CHECK-DUMP-NEXT: TemplateArgument type 'char [1]'
 // CHECK-DUMP:ClassTemplateSpecializationDecl {{.*}} SomeTemplate definition
 // CHECK-DUMP-NEXT: DefinitionData
 // CHECK-DUMP-NEXT:   DefaultConstructor
 // CHECK-DUMP-NEXT:   CopyConstructor
 // CHECK-DUMP-NEXT:   MoveConstructor
 // CHECK-DUMP-NEXT:   CopyAssignment
 // CHECK-DUMP-NEXT:   MoveAssignment
 // CHECK-DUMP-NEXT:   Destructor
-// CHECK-DUMP-NEXT: TemplateArgument type 'char [2]'
-// CHECK-DUMP:ClassTemplateSpecializationDecl {{.*}} prev {{.*}} SomeTemplate
 // CHECK-DUMP-NEXT: TemplateArgument type 'char [1]'
+// CHECK-DUMP:ClassTemplateSpecializationDecl {{.*}} prev {{.*}} SomeTemplate
+// CHECK-DUMP-NEXT: TemplateArgument type 'char [2]'
 // CHECK-DUMP:ClassTemplateSpecializationDecl {{.*}} SomeTemplate definition
 // CHECK-DUMP-NEXT: DefinitionData
 // CHECK-DUMP-NEXT:   DefaultConstructor
 // CHECK-DUMP-NEXT:   CopyConstructor
 // CHECK-DUMP-NEXT:   MoveConstructor
 // CHECK-DUMP-NEXT:   CopyAssignment
 // CHECK-DUMP-NEXT:   MoveAssignment
 // CHECK-DUMP-NEXT:   Destructor
-// CHECK-DUMP-NEXT: TemplateArgument type 'char [1]'
+// CHECK-DUMP-NEXT: TemplateArgument type 'char [2]'
Index: lib/Serialization/ASTWriterDecl.cpp
===
--- lib/Serialization/ASTWriterDecl.cpp
+++ lib/Serialization/ASTWriterDecl.cpp
@@ -162,22 +162,61 @@
   Record.AddSourceLocation(typeParams->getRAngleLoc());
 }
 
-/// Add to the record the first declaration from each module file that
-/// provides a declaration of D. The intent is to provide a sufficient
-/// set such that reloading this set will load all current redeclarations.
-void AddFirstDeclFromEachModule(const Decl *D, bool IncludeLocal) {
-  llvm::MapVector Firsts;
+/// Collect the first declaration from each module file that provides a
+/// declaration of D.
+void CollectFirstDeclFromEachModule(const Decl *D, bool IncludeLocal,
+llvm::MapVector &Firsts) {
+
   // FIXME: We can skip entries that we know are implied by others.
   for (const Decl *R = D->getMostRecentDecl(); R; R = R->getPreviousDecl()) {
 if (R->isFromASTFile())
   Firsts[Writer.Chain->getOwningModuleFile(R)] = R;
 else if (IncludeLocal)
   Firsts[nullptr] = R;
   }
+}
+
+/// Add to the record the first declaration from each module file that
+/// provides a declaration of D. The intent is to provide a sufficient
+/// set such that reloading this set will load all current redeclarations.
+void AddFirstDeclFromEachModule(const Decl *D, bool IncludeLocal) {
+  llvm::MapVector Firsts;
+  CollectFirstDeclFromEachModule(D, IncludeLocal, Firsts);
+
   for (const auto &F : Firsts)
 Record.AddDeclRef(F.second);
 }
 
+/// Add to the record the first template specialization from each module
+/// file that provides a declaration of D. We store the DeclId and an
+/// ODRHash of the template arguments of D which should provide enough
+/// information to load D only if the template instantiator needs it.
+void AddFirstSpecializationDeclFromEachModule(const Decl *D,
+  bool IncludeLocal) {
+  assert(isa(D) ||
+ isa(D) || isa(D) &&
+ "Must not be called with other decls");
+  llvm::MapVector Firsts;
+  CollectFirstDeclFromEa

[PATCH] D41416: [modules] [pch] Do not deserialize all lazy template specializations when looking for one.

2018-01-05 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 128802.
v.g.vassilev added a comment.

Reduce further the deserializations from 451 to 449 by providing a more 
complete implementation of `ODRHash::AddTemplateArgument`.

Kudos @rtrieu!


https://reviews.llvm.org/D41416

Files:
  include/clang/AST/DeclTemplate.h
  lib/AST/DeclTemplate.cpp
  lib/AST/ODRHash.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/Modules/cxx-templates.cpp

Index: test/Modules/cxx-templates.cpp
===
--- test/Modules/cxx-templates.cpp
+++ test/Modules/cxx-templates.cpp
@@ -249,24 +249,24 @@
 
 // CHECK-DUMP:  ClassTemplateDecl {{.*}} <{{.*[/\\]}}cxx-templates-common.h:1:1, {{.*}}>  col:{{.*}} in cxx_templates_common SomeTemplate
 // CHECK-DUMP:ClassTemplateSpecializationDecl {{.*}} prev {{.*}} SomeTemplate
-// CHECK-DUMP-NEXT: TemplateArgument type 'char [2]'
+// CHECK-DUMP-NEXT: TemplateArgument type 'char [1]'
 // CHECK-DUMP:ClassTemplateSpecializationDecl {{.*}} SomeTemplate definition
 // CHECK-DUMP-NEXT: DefinitionData
 // CHECK-DUMP-NEXT:   DefaultConstructor
 // CHECK-DUMP-NEXT:   CopyConstructor
 // CHECK-DUMP-NEXT:   MoveConstructor
 // CHECK-DUMP-NEXT:   CopyAssignment
 // CHECK-DUMP-NEXT:   MoveAssignment
 // CHECK-DUMP-NEXT:   Destructor
-// CHECK-DUMP-NEXT: TemplateArgument type 'char [2]'
-// CHECK-DUMP:ClassTemplateSpecializationDecl {{.*}} prev {{.*}} SomeTemplate
 // CHECK-DUMP-NEXT: TemplateArgument type 'char [1]'
+// CHECK-DUMP:ClassTemplateSpecializationDecl {{.*}} prev {{.*}} SomeTemplate
+// CHECK-DUMP-NEXT: TemplateArgument type 'char [2]'
 // CHECK-DUMP:ClassTemplateSpecializationDecl {{.*}} SomeTemplate definition
 // CHECK-DUMP-NEXT: DefinitionData
 // CHECK-DUMP-NEXT:   DefaultConstructor
 // CHECK-DUMP-NEXT:   CopyConstructor
 // CHECK-DUMP-NEXT:   MoveConstructor
 // CHECK-DUMP-NEXT:   CopyAssignment
 // CHECK-DUMP-NEXT:   MoveAssignment
 // CHECK-DUMP-NEXT:   Destructor
-// CHECK-DUMP-NEXT: TemplateArgument type 'char [1]'
+// CHECK-DUMP-NEXT: TemplateArgument type 'char [2]'
Index: lib/Serialization/ASTWriterDecl.cpp
===
--- lib/Serialization/ASTWriterDecl.cpp
+++ lib/Serialization/ASTWriterDecl.cpp
@@ -162,22 +162,61 @@
   Record.AddSourceLocation(typeParams->getRAngleLoc());
 }
 
-/// Add to the record the first declaration from each module file that
-/// provides a declaration of D. The intent is to provide a sufficient
-/// set such that reloading this set will load all current redeclarations.
-void AddFirstDeclFromEachModule(const Decl *D, bool IncludeLocal) {
-  llvm::MapVector Firsts;
+/// Collect the first declaration from each module file that provides a
+/// declaration of D.
+void CollectFirstDeclFromEachModule(const Decl *D, bool IncludeLocal,
+llvm::MapVector &Firsts) {
+
   // FIXME: We can skip entries that we know are implied by others.
   for (const Decl *R = D->getMostRecentDecl(); R; R = R->getPreviousDecl()) {
 if (R->isFromASTFile())
   Firsts[Writer.Chain->getOwningModuleFile(R)] = R;
 else if (IncludeLocal)
   Firsts[nullptr] = R;
   }
+}
+
+/// Add to the record the first declaration from each module file that
+/// provides a declaration of D. The intent is to provide a sufficient
+/// set such that reloading this set will load all current redeclarations.
+void AddFirstDeclFromEachModule(const Decl *D, bool IncludeLocal) {
+  llvm::MapVector Firsts;
+  CollectFirstDeclFromEachModule(D, IncludeLocal, Firsts);
+
   for (const auto &F : Firsts)
 Record.AddDeclRef(F.second);
 }
 
+/// Add to the record the first template specialization from each module
+/// file that provides a declaration of D. We store the DeclId and an
+/// ODRHash of the template arguments of D which should provide enough
+/// information to load D only if the template instantiator needs it.
+void AddFirstSpecializationDeclFromEachModule(const Decl *D,
+  bool IncludeLocal) {
+  assert(isa(D) ||
+ isa(D) || isa(D) &&
+ "Must not be called with other decls");
+  llvm::MapVector Firsts;
+  CollectFirstDeclFromEachModule(D, IncludeLocal, Firsts);
+
+  for (const auto &F : Firsts) {
+Record.AddDeclRef(F.second);
+ArrayRef Args;
+if (auto *CTSD = dyn_cast(D))
+  Args = CTSD->getTemplateArgs().asArray();
+else if (auto *VTSD = dyn_cast(D))
+  Args = VTSD->getTemplateArgs().asArray();
+else if (auto *FD = dyn_cast(D))
+  Args = FD->getTemplateSpecial

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

2018-01-05 Thread Zhao, Weiming via cfe-commits
We can wrap the random_device as a minstd_rand, a linear congruential 
enginer that a lot of C lib uses for rand().
However based on documentation, we should just provides dummy 
implementation which throws an exception in the constructor of 
random_device [1,2]
But again, compared with run-time exception, a link time error is better 
if we simply skip the implementation.


[1]
"explicit random_device(const string& token = implementation-defined );
...
Throws: A value of an implementation-defined type derived from exception 
if the random_device could not be initialized."
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4659.pdf 
section 29.6.6  Class random_device (page 1082)


[2] "Notice that random devices may not always be available to produce 
random numbers (and in some systems, they may even never be available). 
This is signaled by throwing an exception derived from the standard 
exception  on construction 
 or when a number 
is requested with operator() 
. "   
http://www.cplusplus.com/reference/random/random_device/


Weiming


On 1/2/2018 11:12 AM, Arthur O'Dwyer via Phabricator wrote:

Quuxplusone added a comment.

@weimingz: Since your platform supports `srand(0)`, is it possible to look at how your 
platform implements `srand(0)` and "inline" that implementation into 
`random_device`? That seems like it would be more in keeping with the other ifdefs in 
this file.

I'm confident that constructing an instance of `random_device` MUST NOT 
actually call `srand`. (I'd like to say that it shouldn't even call `rand`.) 
Either of those calls would be observable by the programmer. But there is a 
precedent for e.g. `random_shuffle` making calls to `rand`.


Repository:
   rCXX libc++

https://reviews.llvm.org/D41316





--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by 
The Linux FoundationWe

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


[PATCH] D41780: Preserve unknown STDC pragma through preprocessor

2018-01-05 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rC Clang

https://reviews.llvm.org/D41780



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


[PATCH] D41780: Preserve unknown STDC pragma through preprocessor

2018-01-05 Thread Steven Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
steven_wu marked an inline comment as done.
Closed by commit rL321909: Preserve unknown STDC pragma through preprocessor 
(authored by steven_wu, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D41780

Files:
  cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
  cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
  cfe/trunk/include/clang/Parse/Parser.h
  cfe/trunk/lib/Lex/Pragma.cpp
  cfe/trunk/lib/Parse/ParsePragma.cpp
  cfe/trunk/test/Preprocessor/pragma_unknown.c

Index: cfe/trunk/lib/Parse/ParsePragma.cpp
===
--- cfe/trunk/lib/Parse/ParsePragma.cpp
+++ cfe/trunk/lib/Parse/ParsePragma.cpp
@@ -95,6 +95,44 @@
 Token &FirstToken) override;
 };
 
+// Pragma STDC implementations.
+
+/// PragmaSTDC_FENV_ACCESSHandler - "\#pragma STDC FENV_ACCESS ...".
+struct PragmaSTDC_FENV_ACCESSHandler : public PragmaHandler {
+  PragmaSTDC_FENV_ACCESSHandler() : PragmaHandler("FENV_ACCESS") {}
+
+  void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
+Token &Tok) override {
+tok::OnOffSwitch OOS;
+if (PP.LexOnOffSwitch(OOS))
+ return;
+if (OOS == tok::OOS_ON)
+  PP.Diag(Tok, diag::warn_stdc_fenv_access_not_supported);
+  }
+};
+
+/// PragmaSTDC_CX_LIMITED_RANGEHandler - "\#pragma STDC CX_LIMITED_RANGE ...".
+struct PragmaSTDC_CX_LIMITED_RANGEHandler : public PragmaHandler {
+  PragmaSTDC_CX_LIMITED_RANGEHandler() : PragmaHandler("CX_LIMITED_RANGE") {}
+
+  void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
+Token &Tok) override {
+tok::OnOffSwitch OOS;
+PP.LexOnOffSwitch(OOS);
+  }
+};
+
+/// PragmaSTDC_UnknownHandler - "\#pragma STDC ...".
+struct PragmaSTDC_UnknownHandler : public PragmaHandler {
+  PragmaSTDC_UnknownHandler() = default;
+
+  void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
+Token &UnknownTok) override {
+// C99 6.10.6p2, unknown forms are not allowed.
+PP.Diag(UnknownTok, diag::ext_stdc_pragma_ignored);
+  }
+};
+
 struct PragmaFPHandler : public PragmaHandler {
   PragmaFPHandler() : PragmaHandler("fp") {}
   void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
@@ -233,6 +271,15 @@
   FPContractHandler.reset(new PragmaFPContractHandler());
   PP.AddPragmaHandler("STDC", FPContractHandler.get());
 
+  STDCFENVHandler.reset(new PragmaSTDC_FENV_ACCESSHandler());
+  PP.AddPragmaHandler("STDC", STDCFENVHandler.get());
+
+  STDCCXLIMITHandler.reset(new PragmaSTDC_CX_LIMITED_RANGEHandler());
+  PP.AddPragmaHandler("STDC", STDCCXLIMITHandler.get());
+
+  STDCUnknownHandler.reset(new PragmaSTDC_UnknownHandler());
+  PP.AddPragmaHandler("STDC", STDCUnknownHandler.get());
+
   PCSectionHandler.reset(new PragmaClangSectionHandler(Actions));
   PP.AddPragmaHandler("clang", PCSectionHandler.get());
 
@@ -371,6 +418,15 @@
   PP.RemovePragmaHandler("STDC", FPContractHandler.get());
   FPContractHandler.reset();
 
+  PP.RemovePragmaHandler("STDC", STDCFENVHandler.get());
+  STDCFENVHandler.reset();
+
+  PP.RemovePragmaHandler("STDC", STDCCXLIMITHandler.get());
+  STDCCXLIMITHandler.reset();
+
+  PP.RemovePragmaHandler("STDC", STDCUnknownHandler.get());
+  STDCUnknownHandler.reset();
+
   PP.RemovePragmaHandler("clang", OptimizeHandler.get());
   OptimizeHandler.reset();
 
Index: cfe/trunk/lib/Lex/Pragma.cpp
===
--- cfe/trunk/lib/Lex/Pragma.cpp
+++ cfe/trunk/lib/Lex/Pragma.cpp
@@ -1601,44 +1601,6 @@
   }
 };
 
-// Pragma STDC implementations.
-
-/// PragmaSTDC_FENV_ACCESSHandler - "\#pragma STDC FENV_ACCESS ...".
-struct PragmaSTDC_FENV_ACCESSHandler : public PragmaHandler {
-  PragmaSTDC_FENV_ACCESSHandler() : PragmaHandler("FENV_ACCESS") {}
-
-  void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
-Token &Tok) override {
-tok::OnOffSwitch OOS;
-if (PP.LexOnOffSwitch(OOS))
- return;
-if (OOS == tok::OOS_ON)
-  PP.Diag(Tok, diag::warn_stdc_fenv_access_not_supported);
-  }
-};
-
-/// PragmaSTDC_CX_LIMITED_RANGEHandler - "\#pragma STDC CX_LIMITED_RANGE ...".
-struct PragmaSTDC_CX_LIMITED_RANGEHandler : public PragmaHandler {
-  PragmaSTDC_CX_LIMITED_RANGEHandler() : PragmaHandler("CX_LIMITED_RANGE") {}
-
-  void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
-Token &Tok) override {
-tok::OnOffSwitch OOS;
-PP.LexOnOffSwitch(OOS);
-  }
-};
-
-/// PragmaSTDC_UnknownHandler - "\#pragma STDC ...".
-struct PragmaSTDC_UnknownHandler : public PragmaHandler {
-  PragmaSTDC_UnknownHandler() = default;
-
-  void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
-Token &UnknownTok) override {
-// C99 6.10.6p2, unknown forms are not allowed.
-PP.Diag(UnknownTok, diag::ext_stdc_pragma_ignored

r321909 - Preserve unknown STDC pragma through preprocessor

2018-01-05 Thread Steven Wu via cfe-commits
Author: steven_wu
Date: Fri Jan  5 14:45:03 2018
New Revision: 321909

URL: http://llvm.org/viewvc/llvm-project?rev=321909&view=rev
Log:
Preserve unknown STDC pragma through preprocessor

Summary:
#pragma STDC FP_CONTRACT handler is only registered in parser so we
should keep the unknown STDC pragma through preprocessor and we also
should not emit warning for unknown STDC pragma during preprocessor.

rdar://problem/35724351

Reviewers: efriedma, rsmith, arphaman

Reviewed By: efriedma

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Lex/Pragma.cpp
cfe/trunk/lib/Parse/ParsePragma.cpp
cfe/trunk/test/Preprocessor/pragma_unknown.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=321909&r1=321908&r2=321909&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Fri Jan  5 14:45:03 2018
@@ -505,17 +505,12 @@ def warn_pragma_message : Warning<"%0">,
 def err_pragma_message : Error<"%0">;
 def warn_pragma_ignored : Warning<"unknown pragma ignored">,
InGroup, DefaultIgnore;
-def ext_stdc_pragma_ignored : ExtWarn<"unknown pragma in STDC namespace">,
-   InGroup;
 def ext_on_off_switch_syntax :
ExtWarn<"expected 'ON' or 'OFF' or 'DEFAULT' in pragma">,
InGroup;
 def ext_pragma_syntax_eod :
ExtWarn<"expected end of directive in pragma">,
InGroup;
-def warn_stdc_fenv_access_not_supported :
-   Warning<"pragma STDC FENV_ACCESS ON is not supported, ignoring pragma">,
-   InGroup;
 def warn_pragma_diagnostic_invalid :
ExtWarn<"pragma diagnostic expected 'error', 'warning', 'ignored', 'fatal',"
 " 'push', or 'pop'">,

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=321909&r1=321908&r2=321909&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Fri Jan  5 14:45:03 
2018
@@ -973,6 +973,12 @@ def warn_pragma_init_seg_unsupported_tar
 def err_pragma_fp_contract_scope : Error<
   "'#pragma fp_contract' can only appear at file scope or at the start of a "
   "compound statement">; 
+// - #pragma stdc unknown
+def ext_stdc_pragma_ignored : ExtWarn<"unknown pragma in STDC namespace">,
+   InGroup;
+def warn_stdc_fenv_access_not_supported :
+   Warning<"pragma STDC FENV_ACCESS ON is not supported, ignoring pragma">,
+   InGroup;
 // - #pragma comment
 def err_pragma_comment_malformed : Error<
   "pragma comment requires parenthesized identifier and optional string">;

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=321909&r1=321908&r2=321909&view=diff
==
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Fri Jan  5 14:45:03 2018
@@ -185,6 +185,9 @@ class Parser : public CodeCompletionHand
   std::unique_ptr UnrollHintHandler;
   std::unique_ptr NoUnrollHintHandler;
   std::unique_ptr FPHandler;
+  std::unique_ptr STDCFENVHandler;
+  std::unique_ptr STDCCXLIMITHandler;
+  std::unique_ptr STDCUnknownHandler;
   std::unique_ptr AttributePragmaHandler;
 
   std::unique_ptr CommentSemaHandler;

Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=321909&r1=321908&r2=321909&view=diff
==
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Fri Jan  5 14:45:03 2018
@@ -1601,44 +1601,6 @@ struct PragmaPopMacroHandler : public Pr
   }
 };
 
-// Pragma STDC implementations.
-
-/// PragmaSTDC_FENV_ACCESSHandler - "\#pragma STDC FENV_ACCESS ...".
-struct PragmaSTDC_FENV_ACCESSHandler : public PragmaHandler {
-  PragmaSTDC_FENV_ACCESSHandler() : PragmaHandler("FENV_ACCESS") {}
-
-  void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
-Token &Tok) override {
-tok::OnOffSwitch OOS;
-if (PP.LexOnOffSwitch(OOS))
- return;
-if (OOS == tok::OOS_ON)
-  PP.Diag(Tok, diag::warn_stdc_fenv_access_not_supported);
-  }
-};
-
-/// PragmaSTDC_CX_LIMITED_RANGEHandler - "\#pragma STDC CX_LIMITED_RANGE ...".
-struct PragmaSTDC_CX_LIMITED_RANGEHandler : public PragmaHandler {
-  PragmaSTDC_CX_LIMITED_RANGEHandler() : PragmaHandler("CX_LIMITED_RANGE") {}

[PATCH] D41416: [modules] [pch] Do not deserialize all lazy template specializations when looking for one.

2018-01-05 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

Finer grained clang stats can be seen here 
.


https://reviews.llvm.org/D41416



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


[PATCH] D41546: [clang-tidy] Adding Fuchsia checker for statically constructed objects

2018-01-05 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 128806.
juliehockett marked 3 inline comments as done.
juliehockett added a comment.

1. Narrowing check to only warn if the declaration is a global non-trivial 
object with explicit static storage, unless the object either has a `constexpr` 
constructor or the object has no explicit constructor.
2. Restricting check to only consider C++11 or higher.
3. Updating tests to reflect the above


https://reviews.llvm.org/D41546

Files:
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.cpp
  clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-statically-constructed-objects.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/fuchsia-statically-constructed-objects.cpp

Index: test/clang-tidy/fuchsia-statically-constructed-objects.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-statically-constructed-objects.cpp
@@ -0,0 +1,67 @@
+// RUN: %check_clang_tidy %s fuchsia-statically-constructed-objects %t
+
+// Trivial static is fine
+static int i;
+
+class ClassWithNoCtor {};
+
+class ClassWithCtor {
+public:
+  ClassWithCtor(int Val) : Val(Val) {}
+private:
+  int Val;
+};
+
+class ClassWithConstexpr {
+public:
+  ClassWithConstexpr(int Val1) : Val(Val) {}
+  constexpr ClassWithConstexpr() : Val(0) {}
+
+private:
+  int Val;
+};
+
+ClassWithNoCtor A;
+ClassWithConstexpr C;
+ClassWithConstexpr E(0);
+ClassWithCtor G(0);
+
+static ClassWithNoCtor A2;
+static ClassWithConstexpr C2;
+static ClassWithConstexpr E2(0);
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: explicit global static objects are disallowed: if possible, use a constexpr constructor instead [fuchsia-statically-constructed-objects]
+// CHECK-MESSAGES-NEXT:  static ClassWithConstexpr E2(0);
+static ClassWithCtor G2(0);
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: explicit global static objects are disallowed: if possible, use a constexpr constructor instead [fuchsia-statically-constructed-objects]
+// CHECK-MESSAGES-NEXT:  static ClassWithCtor G2(0);
+
+struct StructWithConstexpr { constexpr StructWithConstexpr(); };
+struct StructWithNoCtor {};
+struct StructWithCtor { StructWithCtor(); };
+
+StructWithNoCtor SNoCtor;
+StructWithConstexpr SConstexpr;
+StructWithCtor SCtor;
+
+static StructWithConstexpr SConstexpr2;
+static StructWithNoCtor SNoCtor2;
+static StructWithCtor SCtor2;
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: explicit global static objects are disallowed: if possible, use a constexpr constructor instead [fuchsia-statically-constructed-objects]
+// CHECK-MESSAGES-NEXT:  static StructWithCtor SCtor2;
+
+extern StructWithCtor SCtor3;
+
+class ClassWithStaticMember {
+private:
+  static StructWithNoCtor S;
+};
+
+ClassWithStaticMember Z();
+
+void f() {
+  // Function static is fine
+  static int i;
+  static ClassWithConstexpr E3(0);
+  static ClassWithCtor G3(0);
+  static StructWithCtor SCtor;
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -70,6 +70,7 @@
cppcoreguidelines-special-member-functions
fuchsia-default-arguments
fuchsia-overloaded-operator
+   fuchsia-statically-constructed-objects
fuchsia-virtual-inheritance
google-build-explicit-make-pair
google-build-namespaces
Index: docs/clang-tidy/checks/fuchsia-statically-constructed-objects.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/fuchsia-statically-constructed-objects.rst
@@ -0,0 +1,41 @@
+.. title:: clang-tidy - fuchsia-statically-constructed-objects
+
+fuchsia-statically-constructed-objects
+==
+
+Warns if global non-trivial objects with explicit static storage are 
+constructed, unless the object either has a ``constexpr`` constructor or has no 
+explicit constructor.
+
+For example:
+
+.. code-block:: c++
+
+  class A {};
+
+  class B {
+  public:
+B(int Val) : Val(Val) {}
+  private:
+int Val;
+  };
+
+  class C {
+  public:
+C(int Val) : Val(Val) {}
+constexpr C() : Val(0) {}
+
+  private:
+int Val;
+  };
+
+  static A a; // No warning, as there is no explicit constructor
+  static C c(0);  // No warning, as constructor is constexpr
+
+  static B b(0);  // Warning, as constructor is not constexpr
+  static C c2(0, 1);  // Warning, as constructor is not constexpr
+  
+  static int i;   // No warning, as it is trivial
+  B b2(0);// No warning, as it is not explicitly static
+
+See the features disallowed in Fuchsia at https://fuchsia.googlesource.com/zircon/+/master/docs/cxx.md
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@

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

2018-01-05 Thread Weiming Zhao via Phabricator via cfe-commits
weimingz added a comment.

We can wrap the random_device as a minstd_rand, a linear congruential enginer 
that a lot of C lib uses for rand().
However based on documentation, we should just provides dummy implementation 
which throws an exception in the constructor of random_device [1,2]
But compared with run-time exception, a link time error is better if we simply 
skip the implementation. Any thoughts?

[1]

> explicit random_device(const string& token = implementation-defined );
>  ...
>  Throws: A value of an implementation-defined type derived from exception if 
> the random_device could not be initialized.

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4659.pdf section 
29.6.6  Class random_device (page 1082)

[2]

> Notice that random devices may not always be available to produce random 
> numbers (and in some systems, they may even never be available). This is 
> signaled by throwing an exception derived from the standard exception or when 
> a number is requested with operator()

http://www.cplusplus.com/reference/random/random_device/


Repository:
  rCXX libc++

https://reviews.llvm.org/D41316



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


[PATCH] D41039: Add support for attribute "trivial_abi"

2018-01-05 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak marked 2 inline comments as done.
ahatanak added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:1827
+
+  if (!IsScalar && !CurFuncIsThunk &&
+  (getTarget().getCXXABI().areArgsDestroyedLeftToRightInCallee() ||

This is not correct since it isn't checking Arg.isIndirect(). I'll fix it and 
upload a new patch.


https://reviews.llvm.org/D41039



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


[PATCH] D41788: [DeclPrinter] Fix two cases that crash clang -ast-print.

2018-01-05 Thread Artem Belevich via Phabricator via cfe-commits
tra created this revision.
tra added a reviewer: arphaman.
Herald added subscribers: jlebar, sanjoy.

Both crashes are related to handling anonymous structures.

- clang didn't handle () around an anonymous struct variable.
- clang also crashed on syntax errors that could lead to other syntactic 
constructs following the declaration of an anonymous struct. While the code is 
invalid, that's not a good reason to panic compiler.


https://reviews.llvm.org/D41788

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/test/Sema/ast-print.c
  clang/test/SemaCXX/ast-print-crash.cpp


Index: clang/test/SemaCXX/ast-print-crash.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/ast-print-crash.cpp
@@ -0,0 +1,12 @@
+// RUN: not %clang_cc1 -triple %ms_abi_triple -ast-print %s -std=gnu++11 \
+// RUN: | FileCheck %s
+
+// The test compiles a file with a syntax error which used to cause a crash 
with
+// -ast-print. Compilation fails due to the syntax error, but compiler should
+// not crash and print out whatever it manager to parse.
+
+// CHECK:  struct {
+// CHECK-NEXT: } dont_crash_on_syntax_error;
+// CHECK-NEXT: decltype(nullptr) p;
+struct {
+} dont_crash_on_syntax_error /* missing ; */ decltype(nullptr) p;
Index: clang/test/Sema/ast-print.c
===
--- clang/test/Sema/ast-print.c
+++ clang/test/Sema/ast-print.c
@@ -15,6 +15,10 @@
   };
 };
 
+// This used to crash clang.
+struct {
+}(s1);
+
 int foo(const struct blah *b) {
   // CHECK: return b->b;
   return b->b;
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -128,9 +128,7 @@
   // FIXME: This should be on the Type class!
   QualType BaseType = T;
   while (!BaseType->isSpecifierType()) {
-if (isa(BaseType))
-  break;
-else if (const PointerType* PTy = BaseType->getAs())
+if (const PointerType *PTy = BaseType->getAs())
   BaseType = PTy->getPointeeType();
 else if (const BlockPointerType *BPy = BaseType->getAs())
   BaseType = BPy->getPointeeType();
@@ -144,8 +142,11 @@
   BaseType = RTy->getPointeeType();
 else if (const AutoType *ATy = BaseType->getAs())
   BaseType = ATy->getDeducedType();
+else if (const ParenType *PTy = BaseType->getAs())
+  BaseType = PTy->desugar();
 else
-  llvm_unreachable("Unknown declarator!");
+  // This must be a syntax error.
+  break;
   }
   return BaseType;
 }


Index: clang/test/SemaCXX/ast-print-crash.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/ast-print-crash.cpp
@@ -0,0 +1,12 @@
+// RUN: not %clang_cc1 -triple %ms_abi_triple -ast-print %s -std=gnu++11 \
+// RUN: | FileCheck %s
+
+// The test compiles a file with a syntax error which used to cause a crash with
+// -ast-print. Compilation fails due to the syntax error, but compiler should
+// not crash and print out whatever it manager to parse.
+
+// CHECK:  struct {
+// CHECK-NEXT: } dont_crash_on_syntax_error;
+// CHECK-NEXT: decltype(nullptr) p;
+struct {
+} dont_crash_on_syntax_error /* missing ; */ decltype(nullptr) p;
Index: clang/test/Sema/ast-print.c
===
--- clang/test/Sema/ast-print.c
+++ clang/test/Sema/ast-print.c
@@ -15,6 +15,10 @@
   };
 };
 
+// This used to crash clang.
+struct {
+}(s1);
+
 int foo(const struct blah *b) {
   // CHECK: return b->b;
   return b->b;
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -128,9 +128,7 @@
   // FIXME: This should be on the Type class!
   QualType BaseType = T;
   while (!BaseType->isSpecifierType()) {
-if (isa(BaseType))
-  break;
-else if (const PointerType* PTy = BaseType->getAs())
+if (const PointerType *PTy = BaseType->getAs())
   BaseType = PTy->getPointeeType();
 else if (const BlockPointerType *BPy = BaseType->getAs())
   BaseType = BPy->getPointeeType();
@@ -144,8 +142,11 @@
   BaseType = RTy->getPointeeType();
 else if (const AutoType *ATy = BaseType->getAs())
   BaseType = ATy->getDeducedType();
+else if (const ParenType *PTy = BaseType->getAs())
+  BaseType = PTy->desugar();
 else
-  llvm_unreachable("Unknown declarator!");
+  // This must be a syntax error.
+  break;
   }
   return BaseType;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41789: [clang-tidy] Function-scoped static variables should not trigger google-objc-global-variable-declaration

2018-01-05 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added reviewers: Wizard, hokein, klimek.
Herald added subscribers: cfe-commits, xazax.hun.

google-objc-global-variable-declaration currently triggers on
valid code like:

- (void)foo { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ /* 
... */ }); }

The Google Objective-C style guide says:

http://google.github.io/styleguide/objcguide.html#common-variable-names

> File scope or global variables (as opposed to constants) declared
>  outside the scope of a method or function should be rare, and should
>  have the prefix g.

which is meant to insinuate that static variables inside a method or
function don't need a special name.

Test Plan: `make -j12 check-clang-tools`


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41789

Files:
  clang-tidy/google/GlobalVariableDeclarationCheck.cpp
  test/clang-tidy/google-objc-global-variable-declaration.m


Index: test/clang-tidy/google-objc-global-variable-declaration.m
===
--- test/clang-tidy/google-objc-global-variable-declaration.m
+++ test/clang-tidy/google-objc-global-variable-declaration.m
@@ -30,12 +30,12 @@
 // CHECK-FIXES: static NSString* const k_Alpha = @"SecondNotAlpha";
 
 static NSString* const kGood = @"hello";
-// CHECK-MESSAGES-NOT: :[[@LINE-1]]:24: warning: const global variable 'kGood' 
must have a name which starts with 'k[A-Z]' 
[google-objc-global-variable-declaration]
 static NSString* gMyIntGood = 0;
-// CHECK-MESSAGES-NOT: :[[@LINE-1]]:18: warning: non-const global variable 
'gMyIntGood' must have a name which starts with 'g[A-Z]' 
[google-objc-global-variable-declaration]
+
 @implementation Foo
 - (void)f {
 int x = 0;
-// CHECK-MESSAGES-NOT: :[[@LINE-1]]:9: warning: non-const global variable 
'gMyIntGood' must have a name which starts with 'g[A-Z]' 
[google-objc-global-variable-declaration]
+static int bar;
+static const int baz = 42;
 }
 @end
Index: clang-tidy/google/GlobalVariableDeclarationCheck.cpp
===
--- clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -24,6 +24,10 @@
 
 namespace {
 
+AST_MATCHER(VarDecl, isLocalVariable) {
+  return Node.isLocalVarDecl();
+}
+
 FixItHint generateFixItHint(const VarDecl *Decl, bool IsConst) {
   char FC = Decl->getName()[0];
   if (!llvm::isAlpha(FC) || Decl->getName().size() == 1) {
@@ -57,12 +61,17 @@
   // need to add two matchers since we need to bind different ids to 
distinguish
   // constants and variables. Since bind() can only be called on node matchers,
   // we cannot make it in one matcher.
+  //
+  // Note that hasGlobalStorage() matches static variables declared locally
+  // inside a function or method, so we need to exclude those with
+  // isLocalVariable().
   Finder->addMatcher(
   varDecl(hasGlobalStorage(), unless(hasType(isConstQualified())),
-  unless(matchesName("::g[A-Z]")))
+  unless(isLocalVariable()), unless(matchesName("::g[A-Z]")))
   .bind("global_var"),
   this);
   Finder->addMatcher(varDecl(hasGlobalStorage(), hasType(isConstQualified()),
+ unless(isLocalVariable()),
  unless(matchesName("::k[A-Z]")))
  .bind("global_const"),
  this);


Index: test/clang-tidy/google-objc-global-variable-declaration.m
===
--- test/clang-tidy/google-objc-global-variable-declaration.m
+++ test/clang-tidy/google-objc-global-variable-declaration.m
@@ -30,12 +30,12 @@
 // CHECK-FIXES: static NSString* const k_Alpha = @"SecondNotAlpha";
 
 static NSString* const kGood = @"hello";
-// CHECK-MESSAGES-NOT: :[[@LINE-1]]:24: warning: const global variable 'kGood' must have a name which starts with 'k[A-Z]' [google-objc-global-variable-declaration]
 static NSString* gMyIntGood = 0;
-// CHECK-MESSAGES-NOT: :[[@LINE-1]]:18: warning: non-const global variable 'gMyIntGood' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
+
 @implementation Foo
 - (void)f {
 int x = 0;
-// CHECK-MESSAGES-NOT: :[[@LINE-1]]:9: warning: non-const global variable 'gMyIntGood' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
+static int bar;
+static const int baz = 42;
 }
 @end
Index: clang-tidy/google/GlobalVariableDeclarationCheck.cpp
===
--- clang-tidy/google/GlobalVariableDeclarationCheck.cpp
+++ clang-tidy/google/GlobalVariableDeclarationCheck.cpp
@@ -24,6 +24,10 @@
 
 namespace {
 
+AST_MATCHER(VarDecl, isLocalVariable) {
+  return Node.isLocalVarDecl();
+}
+
 FixItHint generateFixItHint(const VarDecl *Decl, bool IsConst) {
   char FC = Decl->getName()[0];
   if (!llvm::isAlpha(FC) || Decl->g

[PATCH] D41039: Add support for attribute "trivial_abi"

2018-01-05 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: lib/CodeGen/CGCall.cpp:3498
   bool HasAggregateEvalKind = hasAggregateEvaluationKind(type);
+  bool TypeDestructedInCallee = false;
+  if (const auto *RD = type->getAsCXXRecordDecl())

This is a confusing name for this flag, because there are other reasons why we 
can choose to destroy in the callee (specifically the MS ABI reason). Rather, I 
think this is capturing that "this parameter's ABI was affected by a 
`trivial_abi` attribute", which implies that it should be destroyed (only) in 
the callee. Maybe calling this something like `HasTrivialABIOverride` would 
help.



Comment at: lib/CodeGen/CGDecl.cpp:1822
+  bool IsScalar = hasScalarEvaluationKind(Ty);
+  bool TypeDestructedInCallee = false;
+  if (const auto *RD = Ty->getAsCXXRecordDecl())

Same comment regarding this name.



Comment at: lib/CodeGen/MicrosoftCXXABI.cpp:833
 // passed in registers, which is non-conforming.
 if (RD->hasNonTrivialDestructor() &&
 getContext().getTypeSize(RD->getTypeForDecl()) > 64)

Should we be checking `hasNonTrivialDestructorForCalls` here? What should 
happen if we have a small class whose copy constructor is trivial for calls but 
whose destructor is not? The existing machinations of this ABI only work 
because they can make an additional trivial copy of the function parameter when 
passing it direct, *even if* it has a non-trivial destructor. I don't think 
that's correct in general if the copy constructor is only trival-for-calls. 
Consider:

```
struct X {
  shared_ptr sp; // shared_ptr is trivial-for-calls
  ~X();
};
```

In the absence of the destructor, X should be passed direct.
In the presence of the destructor, though, passing direct would result in the X 
destructor running in both caller and callee, and X being passed through 
registers without running the copy constructor. Which results in a 
double-delete.

So I think what we want here is this:

 * If the copy ctor and dtor are both trivial-for-calls, pass direct.
 * Otherwise, if the copy ctor is trivial (not just trivial-for-calls) and the 
object is small, pass direct (regardless of the triviality of the dtor -- we'll 
make a copy, notionally using the trivial copy ctor, and destroy both the 
original and the copy).
 * Otherwise, pass indirect.


https://reviews.llvm.org/D41039



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


[PATCH] D41039: Add support for attribute "trivial_abi"

2018-01-05 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 128815.
ahatanak marked an inline comment as done.
ahatanak added a comment.

Check whether the argument is passed indirectly before pushing the cleanup.


https://reviews.llvm.org/D41039

Files:
  include/clang/AST/Decl.h
  include/clang/AST/DeclCXX.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/AST/DeclCXX.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaType.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CodeGenCXX/trivial_abi.cpp
  test/Misc/pragma-attribute-supported-attributes-list.test
  test/SemaObjCXX/attr-trivial-abi.mm

Index: test/SemaObjCXX/attr-trivial-abi.mm
===
--- /dev/null
+++ test/SemaObjCXX/attr-trivial-abi.mm
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -std=c++11 -fobjc-runtime-has-weak -fobjc-weak -fobjc-arc -fsyntax-only -verify %s
+
+void __attribute__((trivial_abi)) foo(); // expected-warning {{'trivial_abi' attribute only applies to classes}}
+
+struct [[clang::trivial_abi]] S0 {
+  int a;
+};
+
+struct __attribute__((trivial_abi)) S1 {
+  int a;
+};
+
+struct __attribute__((trivial_abi)) S2 { // expected-warning {{'trivial_abi' cannot be applied to 'S2'}}
+  __weak id a;
+};
+
+struct __attribute__((trivial_abi)) S3 { // expected-warning {{'trivial_abi' cannot be applied to 'S3'}}
+  virtual void m();
+};
+
+struct S4 {
+  int a;
+};
+
+struct __attribute__((trivial_abi)) S5 : public virtual S4 { // expected-warning {{'trivial_abi' cannot be applied to 'S5'}}
+};
+
+struct __attribute__((trivial_abi)) S9 : public S4 {
+};
+
+struct S6 {
+  __weak id a;
+};
+
+struct __attribute__((trivial_abi)) S7 { // expected-warning {{'trivial_abi' cannot be applied to 'S7'}}
+  S6 a;
+};
+
+struct __attribute__((trivial_abi)) S11 { // expected-warning {{'trivial_abi' cannot be applied to 'S11'}}
+  S6 a[2];
+};
+
+struct __attribute__((trivial_abi(1))) S8 { // expected-error {{'trivial_abi' attribute takes no arguments}}
+  int a;
+};
+
+template
+struct __attribute__((trivial_abi)) S10 {
+  T p;
+};
+
+S10 p1;
+
+// Do not warn when 'trivial_abi' is used to annotate a template class.
+S10<__weak id> p2;
Index: test/Misc/pragma-attribute-supported-attributes-list.test
===
--- test/Misc/pragma-attribute-supported-attributes-list.test
+++ test/Misc/pragma-attribute-supported-attributes-list.test
@@ -2,7 +2,7 @@
 
 // The number of supported attributes should never go down!
 
-// CHECK: #pragma clang attribute supports 66 attributes:
+// CHECK: #pragma clang attribute supports 67 attributes:
 // CHECK-NEXT: AMDGPUFlatWorkGroupSize (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumSGPR (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumVGPR (SubjectMatchRule_function)
@@ -66,6 +66,7 @@
 // CHECK-NEXT: TLSModel (SubjectMatchRule_variable_is_thread_local)
 // CHECK-NEXT: Target (SubjectMatchRule_function)
 // CHECK-NEXT: TestTypestate (SubjectMatchRule_function_is_member)
+// CHECK-NEXT: TrivialABI (SubjectMatchRule_record)
 // CHECK-NEXT: WarnUnusedResult (SubjectMatchRule_objc_method, SubjectMatchRule_enum, SubjectMatchRule_record, SubjectMatchRule_hasType_functionType)
 // CHECK-NEXT: XRayInstrument (SubjectMatchRule_function, SubjectMatchRule_objc_method)
 // CHECK-NEXT: XRayLogArgs (SubjectMatchRule_function, SubjectMatchRule_objc_method)
Index: test/CodeGenCXX/trivial_abi.cpp
===
--- /dev/null
+++ test/CodeGenCXX/trivial_abi.cpp
@@ -0,0 +1,197 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++11 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++11 -fclang-abi-compat=4.0 -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: %[[STRUCT_SMALL:.*]] = type { i32* }
+// CHECK: %[[STRUCT_LARGE:.*]] = type { i32*, [128 x i32] }
+// CHECK: %[[STRUCT_TRIVIAL:.*]] = type { i32 }
+// CHECK: %[[STRUCT_NONTRIVIAL:.*]] = type { i32 }
+
+struct __attribute__((trivial_abi)) Small {
+  int *p;
+  Small();
+  ~Small();
+  Small(const Small &);
+  Small &operator=(const Small &);
+};
+
+struct __attribute__((trivial_abi)) Large {
+  int *p;
+  int a[128];
+  Large();
+  ~Large();
+  Large(const Large &);
+  Large &operator=(const Large &);
+};
+
+struct Trivial {
+  int a;
+};
+
+struct NonTrivial {
+  NonTrivial();
+  ~NonTrivial();
+  int a;
+};
+
+struct HasTrivial {
+  Small s;
+  Trivial m;
+};
+
+struct HasNonTrivial {
+  Small s;
+  NonTrivial m;
+};
+
+// CHECK: define void @_Z14testParamSmall5Small(i64 %[[A_COERCE:.*]])
+// CHECK: %[[A:.*]] = alloca %[[STRUCT_SMALL]], align 8
+// CHECK: %[[COERCE_DIVE:.*]] = getelementptr inbounds %[[S

  1   2   >