[PATCH] D34440: [Clang] Expand response files before loading compilation database

2017-07-05 Thread Vladimir Plyashkun via Phabricator via cfe-commits
vladimir.plyashkun updated this revision to Diff 105153.
vladimir.plyashkun added a subscriber: alexfh.
vladimir.plyashkun added a comment.

- moved test-case from separate file to existing one
- fixed `No newline at end of file` problem and put space inside comment


Repository:
  rL LLVM

https://reviews.llvm.org/D34440

Files:
  lib/Tooling/CommonOptionsParser.cpp
  unittests/Tooling/CompilationDatabaseTest.cpp

Index: unittests/Tooling/CompilationDatabaseTest.cpp
===
--- unittests/Tooling/CompilationDatabaseTest.cpp
+++ unittests/Tooling/CompilationDatabaseTest.cpp
@@ -10,12 +10,16 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclGroup.h"
 #include "clang/Frontend/FrontendAction.h"
+#include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/FileMatchTrie.h"
 #include "clang/Tooling/JSONCompilationDatabase.h"
 #include "clang/Tooling/Tooling.h"
+#include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "gtest/gtest.h"
 
+#include 
+
 namespace clang {
 namespace tooling {
 
@@ -626,5 +630,52 @@
   EXPECT_EQ(2, Argc);
 }
 
+class ParseCompilationDatabaseFromResponseFileTest : public testing::Test {
+public:
+  SmallString<128> TestDir;
+  SmallString<128> ResponseFileName;
+
+  ParseCompilationDatabaseFromResponseFileTest() {
+std::error_code EC = llvm::sys::fs::createUniqueDirectory("unittest", TestDir);
+EXPECT_TRUE(!EC);
+llvm::sys::path::append(ResponseFileName, TestDir, "resp");
+  }
+  void setResponseFileContent(const std::string &content) {
+std::ofstream File(ResponseFileName.c_str());
+EXPECT_TRUE(File.is_open());
+File << content;
+File.close();
+  }
+  ~ParseCompilationDatabaseFromResponseFileTest() override {
+llvm::sys::fs::remove(ResponseFileName);
+llvm::sys::fs::remove(TestDir);
+  }
+};
+
+TEST_F(ParseCompilationDatabaseFromResponseFileTest, GetCompileCommands) {
+  setResponseFileContent("-- -a=true -b");
+  SmallString<128> ResponseRef;
+  ResponseRef.append(1, '@');
+  ResponseRef.append(ResponseFileName.c_str());
+  int Argc = 3;
+  const char *Argv[] = { "1", "2", ResponseRef.c_str() };
+  llvm::cl::OptionCategory Category("options");
+  llvm::cl::opt option1("a", llvm::cl::desc(""), llvm::cl::init(false),
+  llvm::cl::cat(Category));
+  llvm::cl::opt option2("b", llvm::cl::desc(""), llvm::cl::init(false),
+  llvm::cl::cat(Category));
+  CommonOptionsParser Parser(Argc, Argv, Category);
+  CompilationDatabase &Database = Parser.getCompilations();
+  std::vector ActualCC = Database.getCompileCommands("source");
+  ASSERT_EQ(1u, ActualCC.size());
+  std::vector ExpectedCmd;
+  ExpectedCmd.push_back("clang-tool");
+  ExpectedCmd.push_back("-a=true");
+  ExpectedCmd.push_back("-b");
+  ExpectedCmd.push_back("source");
+
+  ASSERT_EQ(ExpectedCmd, ActualCC[0].CommandLine);
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Tooling/CommonOptionsParser.cpp
===
--- lib/Tooling/CommonOptionsParser.cpp
+++ lib/Tooling/CommonOptionsParser.cpp
@@ -25,6 +25,7 @@
 //===--===//
 
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/StringSaver.h"
 #include "clang/Tooling/ArgumentsAdjusters.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/Tooling.h"
@@ -115,6 +116,14 @@
   cl::cat(Category));
 
   cl::HideUnrelatedOptions(Category);
+  
+  // Expand response files before loading compilation database from command line
+  SmallVector newArgv(argv, argv + argc);
+  BumpPtrAllocator A;
+  StringSaver Saver(A);
+  cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine, newArgv);
+  argv = &newArgv[0];
+  argc = static_cast(newArgv.size());
 
   std::string ErrorMessage;
   Compilations =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r307067 - [OpenCL] Rename err_opencl_enqueue_kernel_expected_type

2017-07-05 Thread Joey Gouly via cfe-commits
Author: joey
Date: Tue Jul  4 04:50:23 2017
New Revision: 307067

URL: http://llvm.org/viewvc/llvm-project?rev=307067&view=rev
Log:
[OpenCL] Rename err_opencl_enqueue_kernel_expected_type

Rename err_opencl_enqueue_kernel_expected_type so that other builtins
can use the same diagnostic.

https://reviews.llvm.org/D34948

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaOpenCL/cl20-device-side-enqueue.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=307067&r1=307066&r2=307067&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jul  4 04:50:23 
2017
@@ -8457,8 +8457,6 @@ def err_opencl_builtin_to_addr_invalid_a
 // OpenCL v2.0 s6.13.17 Enqueue kernel restrictions.
 def err_opencl_enqueue_kernel_incorrect_args : Error<
   "illegal call to enqueue_kernel, incorrect argument types">;
-def err_opencl_enqueue_kernel_expected_type : Error<
-  "illegal call to enqueue_kernel, expected %0 argument type">;
 def err_opencl_enqueue_kernel_local_size_args : Error<
   "mismatch in number of block parameters and local size arguments passed">;
 def err_opencl_enqueue_kernel_invalid_local_size_type : Error<
@@ -8468,6 +8466,9 @@ def err_opencl_enqueue_kernel_blocks_non
 def err_opencl_enqueue_kernel_blocks_no_args : Error<
   "blocks with parameters are not accepted in this prototype of enqueue_kernel 
call">;
 
+def err_opencl_builtin_expected_type : Error<
+  "illegal call to %0, expected %1 argument type">;
+
 // OpenCL v2.2 s2.1.2.3 - Vector Component Access
 def ext_opencl_ext_vector_type_rgba_selector: ExtWarn<
   "vector component name '%0' is an OpenCL version 2.2 feature">,

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=307067&r1=307066&r2=307067&view=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Jul  4 04:50:23 2017
@@ -309,7 +309,8 @@ static bool SemaOpenCLBuiltinKernelWorkG
   Expr *BlockArg = TheCall->getArg(0);
   if (!isBlockPointer(BlockArg)) {
 S.Diag(BlockArg->getLocStart(),
-   diag::err_opencl_enqueue_kernel_expected_type) << "block";
+   diag::err_opencl_builtin_expected_type)
+<< TheCall->getDirectCallee() << "block";
 return true;
   }
   return checkOpenCLBlockArgs(S, BlockArg);
@@ -394,24 +395,24 @@ static bool SemaOpenCLBuiltinEnqueueKern
   // First argument always needs to be a queue_t type.
   if (!Arg0->getType()->isQueueT()) {
 S.Diag(TheCall->getArg(0)->getLocStart(),
-   diag::err_opencl_enqueue_kernel_expected_type)
-<< S.Context.OCLQueueTy;
+   diag::err_opencl_builtin_expected_type)
+<< TheCall->getDirectCallee() << S.Context.OCLQueueTy;
 return true;
   }
 
   // Second argument always needs to be a kernel_enqueue_flags_t enum value.
   if (!Arg1->getType()->isIntegerType()) {
 S.Diag(TheCall->getArg(1)->getLocStart(),
-   diag::err_opencl_enqueue_kernel_expected_type)
-<< "'kernel_enqueue_flags_t' (i.e. uint)";
+   diag::err_opencl_builtin_expected_type)
+<< TheCall->getDirectCallee() << "'kernel_enqueue_flags_t' (i.e. 
uint)";
 return true;
   }
 
   // Third argument is always an ndrange_t type.
   if (Arg2->getType().getUnqualifiedType().getAsString() != "ndrange_t") {
 S.Diag(TheCall->getArg(2)->getLocStart(),
-   diag::err_opencl_enqueue_kernel_expected_type)
-<< "'ndrange_t'";
+   diag::err_opencl_builtin_expected_type)
+<< TheCall->getDirectCallee() << "'ndrange_t'";
 return true;
   }
 
@@ -420,8 +421,8 @@ static bool SemaOpenCLBuiltinEnqueueKern
   if (NumArgs == 4) {
 // check that the last argument is the right block type.
 if (!isBlockPointer(Arg3)) {
-  S.Diag(Arg3->getLocStart(), 
diag::err_opencl_enqueue_kernel_expected_type)
-  << "block";
+  S.Diag(Arg3->getLocStart(), diag::err_opencl_builtin_expected_type)
+  << TheCall->getDirectCallee() << "block";
   return true;
 }
 // we have a block type, check the prototype
@@ -443,8 +444,8 @@ static bool SemaOpenCLBuiltinEnqueueKern
 // check common block argument.
 Expr *Arg6 = TheCall->getArg(6);
 if (!isBlockPointer(Arg6)) {
-  S.Diag(Arg6->getLocStart(), 
diag::err_opencl_enqueue_kernel_expected_type)
-  << "block";
+  S.Diag(Arg6->getLocStart(), diag::err_opencl_builtin_expected_type)
+  << TheCall->getDirectCallee() << "block";
   return true;
 }
 if (checkOpenCLBlockArgs(S, Arg6))
@@ -453,8 +454,8 @@ static bool S

[PATCH] D34947: [clangd] Add support for per-file extra flags

2017-07-05 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/GlobalCompilationDatabase.cpp:22
+return;
+  if (Command.CommandLine.empty())
+Command.CommandLine.push_back("clang");

If `Command.CommandLine.empty()` is true, extra flags will be added **before** 
'clang' in the command-line.
Maybe restore `assert(Command.CommandLine.size() >= 2)` (i.e. at least a 
compiler binary and input file should be in the commandline) and remove this if?



Comment at: clangd/GlobalCompilationDatabase.cpp:60
+PathRef File, std::vector ExtraFlags) {
+  ExtraFlagsForFile[File] = ExtraFlags;
 }

Maybe `std::move` the vector before assignment to avoid copying?


https://reviews.llvm.org/D34947



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


[PATCH] D34948: [OpenCL] Generalise err_opencl_enqueue_kernel_expected_type to be used with other builtins

2017-07-05 Thread Alexey Bader via Phabricator via cfe-commits
bader added a comment.

>> Do you have another built-in in mind which can use this diagnostic message?
>>  If so, it would make sense to re-use it in the same patch.
> 
> This is split off from https://reviews.llvm.org/D33945, which I will be 
> rebasing/re-uploading once this patch is committed.

I see. Thanks for clarification.
No other comments from my side.


https://reviews.llvm.org/D34948



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


[clang-tools-extra] r307068 - ClangdServer.cpp: Suppress a warning. [-Wunused-lambda-capture]

2017-07-05 Thread NAKAMURA Takumi via cfe-commits
Author: chapuni
Date: Tue Jul  4 05:12:14 2017
New Revision: 307068

URL: http://llvm.org/viewvc/llvm-project?rev=307068&view=rev
Log:
ClangdServer.cpp: Suppress a warning. [-Wunused-lambda-capture]

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

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=307068&r1=307067&r2=307068&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Tue Jul  4 05:12:14 2017
@@ -258,6 +258,7 @@ std::string ClangdServer::dumpAST(PathRe
 
   WorkScheduler.addToEnd([this, &DumpPromise, File, Version]() {
 assert(DraftMgr.getVersion(File) == Version && "Version has changed");
+(void)Version;
 
 Units.runOnExistingUnit(File, [&DumpPromise](ClangdUnit &Unit) {
   std::string Result;


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


[PATCH] D34329: [clang-diff] Initial implementation.

2017-07-05 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:385
+  }
+  int getSizeS() const { return RootIds.size(); }
+  NodeId getIdInRoot(SNodeId Id) const {

What's the purpose of the `S` prefix in the name of this method and a couple of 
other methods below? Can you replace it with something more descriptive or 
remove it altogether?


https://reviews.llvm.org/D34329



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


[PATCH] D34329: [clang-diff] Initial implementation.

2017-07-05 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:359
+
+  explicit SNodeId(int Id) : Id(Id){};
+  explicit SNodeId() = default;

NIT: This ';' is redundant.



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:363
+  operator int() const { return Id; }
+  SNodeId &operator++() { return ++this->Id, *this; }
+  SNodeId &operator--() { return --this->Id, *this; }

NIT: You don't need 'this' here or in the 2 methods below.



Comment at: lib/Tooling/ASTDiff/ASTDiff.cpp:809
+NodeId P1 = M.getSrc(P2);
+assert(P1.isValid());
+Node &Parent1 = T1.getMutableNode(P1);

Missing assertion message.


https://reviews.llvm.org/D34329



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


[PATCH] D34329: [clang-diff] Initial implementation.

2017-07-05 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: include/clang/Tooling/ASTDiff/ASTDiffInternal.h:38
+  operator int() const { return Id; }
+  NodeId &operator++() { return ++this->Id, *this; }
+  NodeId &operator--() { return --this->Id, *this; }

NIT: You don't need `this` here or in `--` as well.


https://reviews.llvm.org/D34329



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


[PATCH] D34853: Fix (benignly) incorrect GoogleTest specs in various lit configs.

2017-07-05 Thread Andrew Ng via Phabricator via cfe-commits
andrewng added a comment.

Hi,

I believe that this "build mode" is intended for the Visual Studio MSVC build. 
This build is special in that it can produce builds for multiple 
configurations, e.g. Debug, Release & RelWithDebInfo, within the same top level 
build output directory. It is this configuration type that defines the "build 
mode". This means that the unit tests will only pick up the configuration that 
matches that of the lit that was run. Without the "build mode" I believe lit 
might end up running all configurations of unit tests that have been built, 
which is probably not the intended behaviour.

Cheers,
Andrew


Repository:
  rL LLVM

https://reviews.llvm.org/D34853



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


[PATCH] D34329: [clang-diff] Initial implementation.

2017-07-05 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes updated this revision to Diff 105161.
johannes added a comment.

- style fixes
- correct getSimilarity()


https://reviews.llvm.org/D34329

Files:
  include/clang/Tooling/ASTDiff/ASTDiff.h
  include/clang/Tooling/ASTDiff/ASTDiffInternal.h
  lib/Tooling/ASTDiff/ASTDiff.cpp
  lib/Tooling/ASTDiff/CMakeLists.txt
  lib/Tooling/CMakeLists.txt
  test/Tooling/clang-diff-basic.cpp
  tools/CMakeLists.txt
  tools/clang-diff/CMakeLists.txt
  tools/clang-diff/ClangDiff.cpp

Index: tools/clang-diff/ClangDiff.cpp
===
--- /dev/null
+++ tools/clang-diff/ClangDiff.cpp
@@ -0,0 +1,110 @@
+//===- ClangDiff.cpp - compare source files by AST nodes --*- C++ -*- -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file implements a tool for syntax tree based comparison using
+// Tooling/ASTDiff.
+//
+//===--===//
+
+#include "clang/Tooling/ASTDiff/ASTDiff.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Support/CommandLine.h"
+
+using namespace llvm;
+using namespace clang;
+using namespace clang::tooling;
+
+static cl::OptionCategory ClangDiffCategory("clang-diff options");
+
+static cl::opt
+DumpAST("ast-dump",
+cl::desc("Print the internal representation of the AST as JSON."),
+cl::init(false), cl::cat(ClangDiffCategory));
+
+static cl::opt NoCompilationDatabase(
+"no-compilation-database",
+cl::desc(
+"Do not attempt to load build settings from a compilation database"),
+cl::init(false), cl::cat(ClangDiffCategory));
+
+static cl::opt SourcePath(cl::Positional, cl::desc(""),
+   cl::Required,
+   cl::cat(ClangDiffCategory));
+
+static cl::opt DestinationPath(cl::Positional,
+cl::desc(""),
+cl::Optional,
+cl::cat(ClangDiffCategory));
+
+static std::unique_ptr getAST(const StringRef Filename) {
+  std::string ErrorMessage;
+  std::unique_ptr Compilations;
+  if (!NoCompilationDatabase)
+Compilations =
+CompilationDatabase::autoDetectFromSource(Filename, ErrorMessage);
+  if (!Compilations) {
+if (!NoCompilationDatabase)
+  llvm::errs()
+  << "Error while trying to load a compilation database, running "
+ "without flags.\n"
+  << ErrorMessage;
+Compilations = llvm::make_unique(
+".", std::vector());
+  }
+  std::array Files = {{Filename}};
+  ClangTool Tool(*Compilations, Files);
+  std::vector> ASTs;
+  Tool.buildASTs(ASTs);
+  if (ASTs.size() != Files.size())
+return nullptr;
+  return std::move(ASTs[0]);
+}
+
+int main(int argc, const char **argv) {
+  cl::HideUnrelatedOptions(ClangDiffCategory);
+  if (!cl::ParseCommandLineOptions(argc, argv)) {
+cl::PrintOptionValues();
+return 1;
+  }
+
+  if (DumpAST) {
+if (!DestinationPath.empty()) {
+  llvm::errs() << "Error: Please specify exactly one filename.\n";
+  return 1;
+}
+std::unique_ptr AST = getAST(SourcePath);
+if (!AST)
+  return 1;
+diff::SyntaxTree Tree(AST->getASTContext());
+Tree.printAsJson(llvm::outs());
+return 0;
+  }
+
+  if (DestinationPath.empty()) {
+llvm::errs() << "Error: Exactly two paths are required.\n";
+return 1;
+  }
+
+  std::unique_ptr Src = getAST(SourcePath);
+  std::unique_ptr Dst = getAST(DestinationPath);
+  if (!Src || !Dst)
+return 1;
+
+  diff::ComparisonOptions Options;
+  diff::SyntaxTree SrcTree(Src->getASTContext());
+  diff::SyntaxTree DstTree(Dst->getASTContext());
+  diff::ASTDiff DiffTool(SrcTree, DstTree, Options);
+  for (const auto &Match : DiffTool.getMatches())
+DiffTool.printMatch(llvm::outs(), Match);
+  for (const auto &Change : DiffTool.getChanges())
+DiffTool.printChange(llvm::outs(), Change);
+
+  return 0;
+}
Index: tools/clang-diff/CMakeLists.txt
===
--- /dev/null
+++ tools/clang-diff/CMakeLists.txt
@@ -0,0 +1,13 @@
+set(LLVM_LINK_COMPONENTS
+  Support
+  )
+
+add_clang_executable(clang-diff
+  ClangDiff.cpp
+  )
+
+target_link_libraries(clang-diff
+  clangFrontend
+  clangTooling
+  clangToolingASTDiff
+  )
Index: tools/CMakeLists.txt
===
--- tools/CMakeLists.txt
+++ tools/CMakeLists.txt
@@ -2,6 +2,7 @@
 
 add_clang_subdirectory(diagtool)
 add_clang_subdirectory(driver)
+add_clang_subdirectory(clang-diff)
 add_clang_subdirectory(clang-format)
 add_clang_subdirectory(clang-format-vs)
 add_clang_s

[PATCH] D34937: Suppressing Reference Counting Diagnostics for Functions Containing 'rc_ownership_trusted_implementation' Annotate Attribute

2017-07-05 Thread Malhar Thakkar via Phabricator via cfe-commits
malhar1995 updated this revision to Diff 105160.
malhar1995 added a comment.
Herald added a subscriber: eraman.

Changed function name from 'isAnnotatedToSkipDiagnostics' to 
'isTrustedReferenceCountImplementation'.
Added some test-cases to test/Analysis/retain-release-inline.m.
Applied clang-format to the changed code.


Repository:
  rL LLVM

https://reviews.llvm.org/D34937

Files:
  lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
  test/Analysis/retain-release-inline.m

Index: test/Analysis/retain-release-inline.m
===
--- test/Analysis/retain-release-inline.m
+++ test/Analysis/retain-release-inline.m
@@ -285,6 +285,14 @@
   foo(s);
   bar(s);
 }
+
+__attribute__((annotate("rc_ownership_trusted_implementation"))) void test_with_trusted_implementation_annotate_attribute() {
+  NSString *s = [[NSString alloc] init]; // no-warning {{Ideally, a "leak" warning should've been raised here. But, as this function contains "rc_ownership_trusted_implementation" annotate attribute, the warning is suppressed}}
+  foo(s);
+  foo(s);
+  bar(s);
+}
+
 void test_neg() {
   NSString *s = [[NSString alloc] init]; // no-warning  
   foo(s);
@@ -294,6 +302,34 @@
   bar(s);
 }
 
+void test2() {
+  NSString *s = [[NSString alloc] init];
+  foo(s);
+  foo(s);
+  bar(s);
+  bar(s);
+  bar(s);
+  [s release]; // expected-warning {{Reference-counted object is used after it is released}}
+}
+
+__attribute__((annotate("rc_ownership_trusted_implementation"))) void test2_with_trusted_implementation_annotate_attribute() {
+  NSString *s = [[NSString alloc] init];
+  foo(s);
+  foo(s);
+  bar(s);
+  bar(s);
+  bar(s);
+  [s release]; // no-warning {{Ideally, a "use-after-release" warning should've been raised here. But, as this function contains "rc_ownership_trusted_implementation" annotate attribute, the warning is suppressed}}
+}
+
+void foo_bar() {
+  NSString *s = [[NSString alloc] init]; // no-warning {{Ideally, a "leak" warning should've been raised. But, as "test3" on the callstack has annotate attribute "rc_ownership_trusted_implementation", the warning is suppressed}}
+}
+
+__attribute__((annotate("rc_ownership_trusted_implementation"))) void test3_with_trusted_implementation_annotate_attribute() {
+  foo_bar();
+}
+
 //===--===//
 // Test returning retained and not-retained values.
 //===--===//
@@ -343,6 +379,14 @@
   CFRelease(str);
 }
 
+__attribute__((annotate("rc_ownership_trusted_implementation"))) void test_test_return_inline_2_with_trusted_implementation_annotate_attribute(char *bytes) {
+  CFStringRef str = CFStringCreateWithCStringNoCopy(0, bytes, NSNEXTSTEPStringEncoding, 0); // no-warning {{Ideally, a "leak" warning should've been raised here. But, as this function contains "rc_ownership_trusted_implementation" annotate attribute, the warning is suppressed}}
+  // After this call, 'str' really has +2 reference count.
+  CFStringRef str2 = test_return_inline(str);
+  // After this call, 'str' really has a +1 reference count.
+  CFRelease(str);
+}
+
 extern CFStringRef getString(void);
 CFStringRef testCovariantReturnType(void) __attribute__((cf_returns_retained));
 
Index: lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -1894,6 +1894,23 @@
   return SFC->getAnalysisDeclContext()->isBodyAutosynthesized();
 }
 
+/// Returns true if any declaration on the call-stack contains
+/// 'rc_ownership_trusted_implementation' annotate attribute.
+bool isTrustedReferenceCountImplementation(const LocationContext *LCtx) {
+  while (LCtx) {
+if (const StackFrameContext *SFC = dyn_cast(LCtx)) {
+  const Decl *D = SFC->getDecl();
+  for (const auto *Ann : D->specific_attrs()) {
+if (Ann->getAnnotation() == "rc_ownership_trusted_implementation") {
+  return true;
+}
+  }
+}
+LCtx = LCtx->getParent();
+  }
+  return false;
+}
+
 std::shared_ptr
 CFRefReportVisitor::VisitNode(const ExplodedNode *N, const ExplodedNode *PrevN,
   BugReporterContext &BRC, BugReport &BR) {
@@ -3345,11 +3362,13 @@
   }
 
   assert(BT);
-  auto report = std::unique_ptr(
-  new CFRefReport(*BT, C.getASTContext().getLangOpts(), C.isObjCGCEnabled(),
-  SummaryLog, N, Sym));
-  report->addRange(ErrorRange);
-  C.emitReport(std::move(report));
+  if (!isTrustedReferenceCountImplementation(N->getLocationContext())) {
+auto report = std::unique_ptr(
+new CFRefReport(*BT, C.getASTContext().getLangOpts(),
+C.isObjCGCEnabled(), SummaryLog, N, Sym));
+report->addRange(ErrorRange);
+C.emitReport(std::move(report));
+  }
 }
 
 //===--

[PATCH] D34329: [clang-diff] Initial implementation.

2017-07-05 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

LGTM. You can request commit access at 
http://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access.


https://reviews.llvm.org/D34329



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


r307074 - [index] Index nested name qualifiers in a forward declaration of a

2017-07-05 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue Jul  4 05:50:53 2017
New Revision: 307074

URL: http://llvm.org/viewvc/llvm-project?rev=307074&view=rev
Log:
[index] Index nested name qualifiers in a forward declaration of a
class template specialization

rdar://33122110

Modified:
cfe/trunk/lib/Index/IndexDecl.cpp
cfe/trunk/test/Index/Core/index-source.cpp

Modified: cfe/trunk/lib/Index/IndexDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexDecl.cpp?rev=307074&r1=307073&r2=307074&view=diff
==
--- cfe/trunk/lib/Index/IndexDecl.cpp (original)
+++ cfe/trunk/lib/Index/IndexDecl.cpp Tue Jul  4 05:50:53 2017
@@ -618,6 +618,8 @@ public:
 Template.is()
 ? (Decl *)Template.get()
 : Template.get();
+if (!D->isThisDeclarationADefinition())
+  IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), D);
 IndexCtx.indexTagDecl(
 D, SymbolRelation(SymbolRoleSet(SymbolRole::RelationSpecializationOf),
   SpecializationOf));

Modified: cfe/trunk/test/Index/Core/index-source.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-source.cpp?rev=307074&r1=307073&r2=307074&view=diff
==
--- cfe/trunk/test/Index/Core/index-source.cpp (original)
+++ cfe/trunk/test/Index/Core/index-source.cpp Tue Jul  4 05:50:53 2017
@@ -496,3 +496,19 @@ void localStructuredBindingAndRef() {
 }
 
 }
+
+namespace rd33122110 {
+
+struct Outer {
+template
+struct Nested { };
+};
+
+}
+
+template<>
+struct rd33122110::Outer::Nested;
+// CHECK: [[@LINE-1]]:8 | namespace/C++ | rd33122110 | c:@N@rd33122110 | 
 | Ref,RelCont | rel: 1
+// CHECK-NEXT: RelCont | Nested | c:@N@rd33122110@S@Outer@S@Nested>#I
+// CHECK: [[@LINE-3]]:20 | struct/C++ | Outer | c:@N@rd33122110@S@Outer | 
 | Ref,RelCont | rel: 1
+// CHECK-NEXT: RelCont | Nested | c:@N@rd33122110@S@Outer@S@Nested>#I


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


[PATCH] D34947: [clangd] Add support for per-file extra flags

2017-07-05 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/GlobalCompilationDatabase.cpp:20
+  const SmallVectorImpl &ExtraFlags) {
+  assert(Command && !Command->CommandLine.empty());
+  if (!Command || ExtraFlags.empty())

Maybe pass `Command` by reference to avoid checking for null?
Is there a guideline to use pointers to make things more explicit that I've 
missed?



Comment at: clangd/GlobalCompilationDatabase.cpp:21
+  assert(Command && !Command->CommandLine.empty());
+  if (!Command || ExtraFlags.empty())
+return;

There's an assert that `Command` is always non-null, so `!Command` is always 
`false`.
Maybe remove this check?



Comment at: clangd/GlobalCompilationDatabase.cpp:23
+return;
+  if (Command->CommandLine.empty())
+Command->CommandLine.push_back("clang");

There's an assert that checks that `CommandLine` is never empty.
Maybe remove this if statement?



Comment at: clangd/GlobalCompilationDatabase.cpp:27
+  ++It;
+  Command->CommandLine.insert(It, ExtraFlags.begin(), ExtraFlags.end());
+}

This way extra flags won't override flags from compilation database, we should 
put `ExtraFlags` right before the input files.

clangd will break if it receives CommandLine with more than one input file, so 
it should be safe to assume that the last arg is the name of the input file, 
i.e. always add `ExtraFlags` right before the last arg.



Comment at: clangd/GlobalCompilationDatabase.cpp:38
+  if (Commands.empty()) {
+std::vector CommandLine{"clang", "-fsyntax-only", File.str()};
+Commands.push_back(tooling::CompileCommand(

Maybe extract a small helper function to get default `CompileCommand` and use 
it both in `ClangdUnitStore` and here?
Just in case we'll ever want to change the defaults at some point.




Comment at: clangd/GlobalCompilationDatabase.cpp:47
+SmallVector UserFlags;
+StringRef(It->second).split(UserFlags, " ");
+// Append the user-specified flags to the compile commands.

This will break for options, containing spaces (e.g. `-I"/home/user/my dir with 
spaces"`). 
There should a function parsing command-line args somewhere in LLVM? Can we 
avoid splitting command-line args altogether (see next comment)?



Comment at: clangd/GlobalCompilationDatabase.cpp:58
+PathRef File, llvm::StringRef ExtraFlags) {
+  ExtraFlagsForFile[File] = ExtraFlags;
 }

Maybe store splitted command-line args in `ExtraFlagsForFile`?
`ycm_extra_conf.py` seems to pass splited command-line arguments, maybe change 
our extension to receive a list of arguments to avoid doing command-line arg 
splitting?


https://reviews.llvm.org/D34947



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


[PATCH] D33440: clang-format: better handle statement and namespace macros

2017-07-05 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

ping?


https://reviews.llvm.org/D33440



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


[PATCH] D34980: [OpenCL] Test on image access modifiers and image type can only be a type of a function argument.

2017-07-05 Thread Egor Churaev via Phabricator via cfe-commits
echuraev created this revision.
Herald added a subscriber: yaxunl.

https://reviews.llvm.org/D34980

Files:
  test/SemaOpenCL/images.cl


Index: test/SemaOpenCL/images.cl
===
--- test/SemaOpenCL/images.cl
+++ test/SemaOpenCL/images.cl
@@ -1,9 +1,43 @@
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
 
-void img2d_ro(__read_only image2d_t img) {} // expected-note{{passing argument 
to parameter 'img' here}} expected-note{{passing argument to parameter 'img' 
here}}
+void img2d_ro(__read_only image2d_t img) {} // expected-note 2{{passing 
argument to parameter 'img' here}}
 
 void imgage_access_test(image2d_t img2dro, write_only image2d_t img2dwo, 
image3d_t img3dro) {
   img2d_ro(img2dro);
   img2d_ro(img2dwo); // expected-error{{passing '__write_only image2d_t' to 
parameter of incompatible type '__read_only image2d_t'}}
   img2d_ro(img3dro); // expected-error{{passing '__read_only image3d_t' to 
parameter of incompatible type '__read_only image2d_t'}}
 }
+
+void myWrite(write_only image2d_t); // expected-note 2{{passing argument to 
parameter here}}
+void myRead (read_only image2d_t); // expected-note 2{{passing argument to 
parameter here}}
+void myReadWrite (read_write image2d_t);
+void myIndifferent (image2d_t); // expected-note 2{{passing argument to 
parameter here}}
+
+
+kernel void k1 (read_only image2d_t img) {
+  myWrite(img); // expected-error {{passing '__read_only image2d_t' to 
parameter of incompatible type '__write_only image2d_t'}}
+}
+
+kernel void k2 (write_only image2d_t img) {
+  myRead(img); // expected-error {{passing '__write_only image2d_t' to 
parameter of incompatible type '__read_only image2d_t'}}
+}
+
+// Should be all OK.
+kernel void k3 (read_write image2d_t img) {
+  myRead(img);  // expected-error {{passing '__read_write image2d_t' to 
parameter of incompatible type '__read_only image2d_t'}}
+  myWrite(img); // expected-error {{passing '__read_write image2d_t' to 
parameter of incompatible type '__write_only image2d_t'}}
+  myReadWrite(img); //read_write = read_write
+}
+
+// Legal to path everything to an 'indifferent' function.
+kernel void k4(read_write image2d_t i1, read_only image2d_t i2,
+   write_only image2d_t i3) {
+  myIndifferent(i1); // expected-error {{passing '__read_write image2d_t' to 
parameter of incompatible type '__read_only image2d_t'}}
+  myIndifferent(i2);
+  myIndifferent(i3); // expected-error {{passing '__write_only image2d_t' to 
parameter of incompatible type '__read_only image2d_t'}}
+}
+
+kernel void k5(read_only image2d_t srcimg)
+{
+  read_only image2d_t tmp = srcimg; // expected-error {{type '__read_only 
image2d_t' can only be used as a function parameter in OpenCL}}
+}


Index: test/SemaOpenCL/images.cl
===
--- test/SemaOpenCL/images.cl
+++ test/SemaOpenCL/images.cl
@@ -1,9 +1,43 @@
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
 
-void img2d_ro(__read_only image2d_t img) {} // expected-note{{passing argument to parameter 'img' here}} expected-note{{passing argument to parameter 'img' here}}
+void img2d_ro(__read_only image2d_t img) {} // expected-note 2{{passing argument to parameter 'img' here}}
 
 void imgage_access_test(image2d_t img2dro, write_only image2d_t img2dwo, image3d_t img3dro) {
   img2d_ro(img2dro);
   img2d_ro(img2dwo); // expected-error{{passing '__write_only image2d_t' to parameter of incompatible type '__read_only image2d_t'}}
   img2d_ro(img3dro); // expected-error{{passing '__read_only image3d_t' to parameter of incompatible type '__read_only image2d_t'}}
 }
+
+void myWrite(write_only image2d_t); // expected-note 2{{passing argument to parameter here}}
+void myRead (read_only image2d_t); // expected-note 2{{passing argument to parameter here}}
+void myReadWrite (read_write image2d_t);
+void myIndifferent (image2d_t); // expected-note 2{{passing argument to parameter here}}
+
+
+kernel void k1 (read_only image2d_t img) {
+  myWrite(img); // expected-error {{passing '__read_only image2d_t' to parameter of incompatible type '__write_only image2d_t'}}
+}
+
+kernel void k2 (write_only image2d_t img) {
+  myRead(img); // expected-error {{passing '__write_only image2d_t' to parameter of incompatible type '__read_only image2d_t'}}
+}
+
+// Should be all OK.
+kernel void k3 (read_write image2d_t img) {
+  myRead(img);  // expected-error {{passing '__read_write image2d_t' to parameter of incompatible type '__read_only image2d_t'}}
+  myWrite(img); // expected-error {{passing '__read_write image2d_t' to parameter of incompatible type '__write_only image2d_t'}}
+  myReadWrite(img); //read_write = read_write
+}
+
+// Legal to path everything to an 'indifferent' function.
+kernel void k4(read_write image2d_t i1, read_only image2d_t i2,
+ 

[PATCH] D33589: clang-format: consider not splitting tokens in optimization

2017-07-05 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

ping?


https://reviews.llvm.org/D33589



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


[PATCH] D34404: [Clang-Tidy] Preserve Message, FileOffset, FilePath in Clang-Tidy YAML output

2017-07-05 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh requested changes to this revision.
alexfh added inline comments.
This revision now requires changes to proceed.



Comment at: unittests/Tooling/DiagnosticsYamlTest.cpp:51
+
+  ASSERT_STREQ("---\n"
+"MainSourceFile:  path/to/source.cpp\n"

EXPECT_STREQ is more appropriate here. ASSERT_* family of macros terminates the 
test, and thus should only be used to verify the invariants that are absolutely 
required to continue the execution of the test, which is not the case here.



Comment at: unittests/clang-apply-replacements/ApplyReplacementsTest.cpp:18
+
+static tooling::Diagnostic makeDiagnostic(const StringRef DiagnosticName,
+  DiagnosticMessage &Message,

I'd remove `const` from `DiagnosticName`, since a StringRef doesn't allow to 
modify the string it points to (and marking by value arguments `const` is not 
common in LLVM). However, `Message` and `Replacements` allow to modify the 
referenced objects and thus should be marked `const`.

Also consider inlining this method, it doesn't buy you much.



Comment at: unittests/clang-apply-replacements/ApplyReplacementsTest.cpp:23
+  SmallVector EmptyNotes;
+  return tooling::Diagnostic(DiagnosticName, Message, Replacements, EmptyNotes,
+ tooling::Diagnostic::Warning, BuildDirectory);

Will `{}` work instead of `EmptyNotes`?



Comment at: unittests/clang-apply-replacements/ApplyReplacementsTest.cpp:23
+  SmallVector EmptyNotes;
+  return tooling::Diagnostic(DiagnosticName, Message, Replacements, EmptyNotes,
+ tooling::Diagnostic::Warning, BuildDirectory);

alexfh wrote:
> Will `{}` work instead of `EmptyNotes`?
`tooling::` is not needed due to the using directive above. Same below.



Comment at: unittests/clang-apply-replacements/ApplyReplacementsTest.cpp:54-56
+  bool success = mergeAndDeduplicate(TUs, ReplacementsMap, SM);
+
+  EXPECT_TRUE(success);

I'd remove the `success` variable and just call EXPECT_TRUE(merge...)


Repository:
  rL LLVM

https://reviews.llvm.org/D34404



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


[PATCH] D34981: RecursiveASTVisitor should visit the nested name qualifiers in a template specialisation

2017-07-05 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.

Right now because of this issue rename cannot be initiated at name qualifiers 
in a template specialisation, e.g.:

  struct Outer {
  template
  struct Nested { };
  };
  
  template<>
  struct Outer::Nested; // Rename cannot be initiated at 'Outer' because 
the NNSL is not visited by the RecursiveASTVisitor


Repository:
  rL LLVM

https://reviews.llvm.org/D34981

Files:
  include/clang/AST/RecursiveASTVisitor.h
  unittests/Tooling/RecursiveASTVisitorTest.cpp


Index: unittests/Tooling/RecursiveASTVisitorTest.cpp
===
--- unittests/Tooling/RecursiveASTVisitorTest.cpp
+++ unittests/Tooling/RecursiveASTVisitorTest.cpp
@@ -244,4 +244,62 @@
   InitListExprPostOrderNoQueueVisitor::Lang_C));
 }
 
+// Check to ensure that nested name specifiers are visited.
+class NestedNameSpecifiersVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool VisitRecordTypeLoc(RecordTypeLoc RTL) {
+if (!RTL)
+  return true;
+Match(RTL.getDecl()->getName(), RTL.getNameLoc());
+return true;
+  }
+
+  bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) {
+if (!NNS)
+  return true;
+if (const NamespaceDecl *ND =
+NNS.getNestedNameSpecifier()->getAsNamespace())
+  Match(ND->getName(), NNS.getLocalBeginLoc());
+return ExpectedLocationVisitor::TraverseNestedNameSpecifierLoc(NNS);
+  }
+};
+
+TEST(RecursiveASTVisitor,
+ NestedNameSpecifiersForTemplateSpecializatoinsAreVisited) {
+  StringRef Source = R"(
+namespace ns {
+struct Outer {
+template
+struct Nested { };
+
+template
+static T x;
+};
+}
+
+template<>
+struct ns::Outer::Nested;
+
+template<>
+struct ns::Outer::Nested { };
+
+template
+struct ns::Outer::Nested { };
+
+template<>
+int ns::Outer::x = 0;
+)";
+  NestedNameSpecifiersVisitor Visitor;
+  Visitor.ExpectMatch("ns", 13, 8);
+  Visitor.ExpectMatch("ns", 16, 8);
+  Visitor.ExpectMatch("ns", 19, 8);
+  Visitor.ExpectMatch("ns", 22, 5);
+  Visitor.ExpectMatch("Outer", 13, 12);
+  Visitor.ExpectMatch("Outer", 16, 12);
+  Visitor.ExpectMatch("Outer", 19, 12);
+  Visitor.ExpectMatch("Outer", 22, 9);
+  EXPECT_TRUE(Visitor.runOver(Source, 
NestedNameSpecifiersVisitor::Lang_CXX14));
+}
+
 } // end anonymous namespace
Index: include/clang/AST/RecursiveASTVisitor.h
===
--- include/clang/AST/RecursiveASTVisitor.h
+++ include/clang/AST/RecursiveASTVisitor.h
@@ -1799,6 +1799,7 @@
 if (TypeSourceInfo *TSI = D->getTypeAsWritten())   
\
   TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));  
\

\
+TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));  
\
 if (!getDerived().shouldVisitTemplateInstantiations() &&   
\
 D->getTemplateSpecializationKind() != TSK_ExplicitSpecialization)  
\
   /* Returning from here skips traversing the  
\


Index: unittests/Tooling/RecursiveASTVisitorTest.cpp
===
--- unittests/Tooling/RecursiveASTVisitorTest.cpp
+++ unittests/Tooling/RecursiveASTVisitorTest.cpp
@@ -244,4 +244,62 @@
   InitListExprPostOrderNoQueueVisitor::Lang_C));
 }
 
+// Check to ensure that nested name specifiers are visited.
+class NestedNameSpecifiersVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool VisitRecordTypeLoc(RecordTypeLoc RTL) {
+if (!RTL)
+  return true;
+Match(RTL.getDecl()->getName(), RTL.getNameLoc());
+return true;
+  }
+
+  bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) {
+if (!NNS)
+  return true;
+if (const NamespaceDecl *ND =
+NNS.getNestedNameSpecifier()->getAsNamespace())
+  Match(ND->getName(), NNS.getLocalBeginLoc());
+return ExpectedLocationVisitor::TraverseNestedNameSpecifierLoc(NNS);
+  }
+};
+
+TEST(RecursiveASTVisitor,
+ NestedNameSpecifiersForTemplateSpecializatoinsAreVisited) {
+  StringRef Source = R"(
+namespace ns {
+struct Outer {
+template
+struct Nested { };
+
+template
+static T x;
+};
+}
+
+template<>
+struct ns::Outer::Nested;
+
+template<>
+struct ns::Outer::Nested { };
+
+template
+struct ns::Outer::Nested { };
+
+template<>
+int ns::Outer::x = 0;
+)";
+  NestedNameSpecifiersVisitor Visitor;
+  Visitor.ExpectMatch("ns", 13, 8);
+  Visitor.ExpectMatch("ns", 16, 8);
+  Visitor.ExpectMatch("ns", 19, 8);
+  Visitor.ExpectMatch("ns", 22, 5);
+  Visitor.ExpectMatch("Outer", 13, 12);
+  Visitor.ExpectMatch("Outer", 16, 12);
+  Visitor.ExpectMatch("Outer", 19, 12);
+  Visitor.ExpectMatch("Outer", 22, 9);
+  EXPECT_TRUE(Visitor.runOver(Source, NestedNameSpecifiersVisitor::Lang_CXX14));
+}
+
 } // end anonymous namespace
I

[PATCH] D34206: [clang-tidy] Add "MakeSmartPtrFunction" option to modernize-make-shared/unique checks.

2017-07-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.

LG with a couple of nits.




Comment at: test/clang-tidy/modernize-make-shared-header.cpp:9
+// RUN:   -- -std=c++11 \
+// RUN:   -I%S/Inputs/modernize-smart-ptr
+

I'd put this on the previous line.



Comment at: test/clang-tidy/modernize-make-unique-header.cpp:9
+// RUN:   -- -std=c++11 \
+// RUN:   -I%S/Inputs/modernize-smart-ptr
+

I'd put this on the previous line.


https://reviews.llvm.org/D34206



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


[PATCH] D33589: clang-format: consider not splitting tokens in optimization

2017-07-05 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added inline comments.



Comment at: lib/Format/UnwrappedLineFormatter.cpp:723
   FormatDecision LastFormat = Node->State.NextToken->Decision;
   if (LastFormat == FD_Unformatted || LastFormat == FD_Continue)
+addNextStateToQueue(Penalty, Node, /*NewLine=*/false,

This is almost certainly a no-go. It turns the algorithm from exploring a state 
space with a branching factor of 2 into something with a branching factor of 4.

Even assuming we can perfectly reuse results from computations (or in other 
words hit the same state through different path using Dijkstra's algorithm), 
the additional bool in StateNode doubles the number of states we are going to 
visit. You don't even seem to make a distinction of whether the token under 
investigation can possibly be split. You do look at NoLineBreak(InOperand), but 
even if those are false, the vast majority of tokens will never be split.

However, even if you narrow that down, I am not convinced that fixing this 
inconsistency around the formatting penalties is worth the runtime performance 
hit. I am generally fine with changing the behavior in the way you are 
proposing, but only if it has zero (negative) effect on performance.



Comment at: lib/Format/UnwrappedLineFormatter.cpp:764
   return;
+if (!BreakToken && !Indenter->canSplit(PreviousNode->State))
+  return;

It's not clear to me why you'd return here.


https://reviews.llvm.org/D33589



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


[PATCH] D33844: terminating continue check

2017-07-05 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

Please don't forget to add cfe-commits to `Subscribers:` when initially sending 
the patch for review. Otherwise nobody on the list will see it.

Could you run the check on LLVM+Clang and post a summary of your findings here?


https://reviews.llvm.org/D33844



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


[PATCH] D34937: Suppressing Reference Counting Diagnostics for Functions Containing 'rc_ownership_trusted_implementation' Annotate Attribute

2017-07-05 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin added a comment.

Thanks for the tests.

Have you tried this on the ISL codebase to make sure it is suppressing the 
diagnostics in related to reference counting implementation that you expect?

I think it would be good to add some tests that reflect the reference counting 
implementation patterns in ISL that you want to make sure not to warn on. Can 
you simplify those patterns to their essence and add them as tests?




Comment at: test/Analysis/retain-release-inline.m:306
+void test2() {
+  NSString *s = [[NSString alloc] init];
+  foo(s);

What is the purpose of this test? Does it test new functionality added by your 
patch?



Comment at: test/Analysis/retain-release-inline.m:315
+
+__attribute__((annotate("rc_ownership_trusted_implementation"))) void 
test2_with_trusted_implementation_annotate_attribute() {
+  NSString *s = [[NSString alloc] init];

Can you simplify this test so that it directly tests the new functionality you 
added? In general we try to avoid duplicating unnecessary parts of other tests. 
This slows down running the tests and also adds a maintenance burden when we 
need to change the test.



Comment at: test/Analysis/retain-release-inline.m:316
+__attribute__((annotate("rc_ownership_trusted_implementation"))) void 
test2_with_trusted_implementation_annotate_attribute() {
+  NSString *s = [[NSString alloc] init];
+  foo(s);

I think it would be better to use C here rather than Objective-C. Can you 
change the test to use new prototypes for the specific purpose of this test. 
One that is annotated "__attribute__((cf_returns_retained))" (this is similar 
to __isl_give) and one with a parameter that is that is annotated 
"__attribute__((cf_consumed))".

The reason it doesn't make sense to use Objective-C here because we want this 
new annotation to be used for C frameworks with their own reference counting 
implementation -- and Objective-C's is built into the language.


Repository:
  rL LLVM

https://reviews.llvm.org/D34937



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


[PATCH] D34912: Handle cases where the value is too large to fit into the underlying type.

2017-07-05 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 105172.
v.g.vassilev added a comment.

Add test case.


https://reviews.llvm.org/D34912

Files:
  lib/AST/TemplateBase.cpp
  test/SemaTemplate/temp_arg_nontype.cpp


Index: test/SemaTemplate/temp_arg_nontype.cpp
===
--- test/SemaTemplate/temp_arg_nontype.cpp
+++ test/SemaTemplate/temp_arg_nontype.cpp
@@ -463,3 +463,8 @@
   T foo = "foo";
   void g() { A<&foo>().f(); }
 }
+
+namespace template_ull {
+  template  struct S{}; // expected-note-re {{conversion 
from 'int' to 'const template_ull::S<{{[0-9]+}}ull> &'}}
+  S<(unsigned long long)-1> s = 42; // expected-error {{no viable conversion 
from 'int' to 'S<(unsigned long long)-1>'}}
+}
Index: lib/AST/TemplateBase.cpp
===
--- lib/AST/TemplateBase.cpp
+++ lib/AST/TemplateBase.cpp
@@ -62,6 +62,12 @@
 Out << "'";
   } else {
 Out << Val;
+// Handle cases where the value is too large to fit into the underlying 
type
+// i.e. where the unsignedness matters.
+if (const BuiltinType *BT = T->getAs()) {
+  if (Val.isUnsigned() && Val.getBitWidth() == 64 && Val.isNegative())
+Out << "ull";
+}
   }
 }
 


Index: test/SemaTemplate/temp_arg_nontype.cpp
===
--- test/SemaTemplate/temp_arg_nontype.cpp
+++ test/SemaTemplate/temp_arg_nontype.cpp
@@ -463,3 +463,8 @@
   T foo = "foo";
   void g() { A<&foo>().f(); }
 }
+
+namespace template_ull {
+  template  struct S{}; // expected-note-re {{conversion from 'int' to 'const template_ull::S<{{[0-9]+}}ull> &'}}
+  S<(unsigned long long)-1> s = 42; // expected-error {{no viable conversion from 'int' to 'S<(unsigned long long)-1>'}}
+}
Index: lib/AST/TemplateBase.cpp
===
--- lib/AST/TemplateBase.cpp
+++ lib/AST/TemplateBase.cpp
@@ -62,6 +62,12 @@
 Out << "'";
   } else {
 Out << Val;
+// Handle cases where the value is too large to fit into the underlying type
+// i.e. where the unsignedness matters.
+if (const BuiltinType *BT = T->getAs()) {
+  if (Val.isUnsigned() && Val.getBitWidth() == 64 && Val.isNegative())
+Out << "ull";
+}
   }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34947: [clangd] Add support for per-file extra flags

2017-07-05 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: clangd/GlobalCompilationDatabase.cpp:20
+  const SmallVectorImpl &ExtraFlags) {
+  assert(Command && !Command->CommandLine.empty());
+  if (!Command || ExtraFlags.empty())

ilya-biryukov wrote:
> Maybe pass `Command` by reference to avoid checking for null?
> Is there a guideline to use pointers to make things more explicit that I've 
> missed?
There's a guideline to use pointers for google style, but I'm not aware for 
such for llvm style.


https://reviews.llvm.org/D34947



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


[PATCH] D34947: [clangd] Add support for per-file extra flags

2017-07-05 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 105147.
krasimir marked 7 inline comments as done.
krasimir added a comment.

- Addess review comments


https://reviews.llvm.org/D34947

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdUnitStore.cpp
  clangd/GlobalCompilationDatabase.cpp
  clangd/GlobalCompilationDatabase.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  test/clangd/extra-flags.test

Index: test/clangd/extra-flags.test
===
--- /dev/null
+++ test/clangd/extra-flags.test
@@ -0,0 +1,22 @@
+# RUN: clangd -run-synchronously < %s | FileCheck %s
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+#
+Content-Length: 205
+
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///foo.c","languageId":"c","version":1,"text":"int main() { int i; return i; }"},"metadata":{"extraFlags":["-Wall"]}}}
+# CHECK: {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///foo.c","diagnostics":[{"range":{"start": {"line": 0, "character": 28}, "end": {"line": 0, "character": 28}},"severity":2,"message":"variable 'i' is uninitialized when used here"},{"range":{"start": {"line": 0, "character": 19}, "end": {"line": 0, "character": 19}},"severity":3,"message":"initialize the variable 'i' to silence this warning"}]}}
+#
+Content-Length: 175
+
+{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///foo.c","version":2},"contentChanges":[{"text":"int main() { int i; return i; }"}]}}
+# CHECK: {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///foo.c","diagnostics":[{"range":{"start": {"line": 0, "character": 28}, "end": {"line": 0, "character": 28}},"severity":2,"message":"variable 'i' is uninitialized when used here"},{"range":{"start": {"line": 0, "character": 19}, "end": {"line": 0, "character": 19}},"severity":3,"message":"initialize the variable 'i' to silence this warning"}]}}
+#
+Content-Length: 44
+
+{"jsonrpc":"2.0","id":5,"method":"shutdown"}
+
+
Index: clangd/Protocol.h
===
--- clangd/Protocol.h
+++ clangd/Protocol.h
@@ -118,6 +118,12 @@
   static std::string unparse(const Location &P);
 };
 
+struct Metadata {
+  std::vector extraFlags;
+
+  static llvm::Optional parse(llvm::yaml::MappingNode *Params);
+};
+
 struct TextEdit {
   /// The range of the text document to be manipulated. To insert
   /// text into a document create a range where start === end.
@@ -152,6 +158,9 @@
   /// The document that was opened.
   TextDocumentItem textDocument;
 
+  /// Extension storing per-file metadata, such as compilation flags.
+  llvm::Optional metadata;
+
   static llvm::Optional
   parse(llvm::yaml::MappingNode *Params);
 };
Index: clangd/Protocol.cpp
===
--- clangd/Protocol.cpp
+++ clangd/Protocol.cpp
@@ -204,6 +204,33 @@
   return Result;
 }
 
+llvm::Optional Metadata::parse(llvm::yaml::MappingNode *Params) {
+  Metadata Result;
+  for (auto &NextKeyValue : *Params) {
+auto *KeyString = dyn_cast(NextKeyValue.getKey());
+if (!KeyString)
+  return llvm::None;
+
+llvm::SmallString<10> KeyStorage;
+StringRef KeyValue = KeyString->getValue(KeyStorage);
+auto *Value = NextKeyValue.getValue();
+
+llvm::SmallString<10> Storage;
+if (KeyValue == "extraFlags") {
+  auto *Seq = dyn_cast(Value);
+  if (!Seq)
+return llvm::None;
+  for (auto &Item : *Seq) {
+auto *Node = dyn_cast(&Item);
+if (!Node)
+  return llvm::None;
+Result.extraFlags.push_back(Node->getValue(Storage));
+  }
+}
+  }
+  return Result;
+}
+
 llvm::Optional TextEdit::parse(llvm::yaml::MappingNode *Params) {
   TextEdit Result;
   for (auto &NextKeyValue : *Params) {
@@ -265,6 +292,11 @@
   if (!Parsed)
 return llvm::None;
   Result.textDocument = std::move(*Parsed);
+} else if (KeyValue == "metadata") {
+  auto Parsed = Metadata::parse(Value);
+  if (!Parsed)
+return llvm::None;
+  Result.metadata = std::move(*Parsed);
 } else {
   return llvm::None;
 }
Index: clangd/GlobalCompilationDatabase.h
===
--- clangd/GlobalCompilationDatabase.h
+++ clangd/GlobalCompilationDatabase.h
@@ -25,6 +25,9 @@
 
 namespace clangd {
 
+/// Returns a default compile command to use for \p File.
+tooling::CompileCommand getDefaultCompileCommand(PathRef File);
+
 /// Provides compilation arguments used for building ClangdUnit.
 class GlobalCompilationDatabase {
 public:
@@ -45,14 +48,19 @@
   std::vector
   getCompileCommands(PathRef File) override;
 
+  void addExtraFlagsForFile(PathRef File, std::vector Extr

[PATCH] D34444: Teach codegen to work in incremental processing mode.

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

ping...


Repository:
  rL LLVM

https://reviews.llvm.org/D3



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


[PATCH] D34984: Store token literal data in PCH. Avoids disk read on PreProc expansion.

2017-07-05 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev created this revision.

Patch by Axel Naumann!


Repository:
  rL LLVM

https://reviews.llvm.org/D34984

Files:
  include/clang/Serialization/ASTReader.h
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp


Index: lib/Serialization/ASTWriter.cpp
===
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -4287,6 +4287,8 @@
   Record.push_back(Tok.getKind());
   // FIXME: Should translate token flags to a stable encoding.
   Record.push_back(Tok.getFlags());
+  if (Tok.isLiteral())
+ AddString(Tok.getLiteralData(), Record);
 }
 
 void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) {
Index: lib/Serialization/ASTReader.cpp
===
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -1517,6 +1517,12 @@
 Tok.setIdentifierInfo(II);
   Tok.setKind((tok::TokenKind)Record[Idx++]);
   Tok.setFlag((Token::TokenFlags)Record[Idx++]);
+  if (Tok.isLiteral()) {
+ const RecordData& RD = reinterpret_cast(Record);
+ std::string* Lit = new std::string(ReadString(RD, Idx));
+ TokenLiteralDataLoaded.push_back(Lit);
+ Tok.setLiteralData(Lit->c_str());
+  }
   return Tok;
 }
 
@@ -9909,6 +9915,9 @@
 ASTReader::~ASTReader() {
   if (OwnsDeserializationListener)
 delete DeserializationListener;
+  for (auto PStr: TokenLiteralDataLoaded) {
+ delete PStr;
+  }
 }
 
 IdentifierResolver &ASTReader::getIdResolver() {
Index: include/clang/Serialization/ASTReader.h
===
--- include/clang/Serialization/ASTReader.h
+++ include/clang/Serialization/ASTReader.h
@@ -604,6 +604,9 @@
   /// files.
   llvm::DenseSet LoadedUndefs;
 
+  /// \brief Token literal data loaded and owned by us.
+  std::vector TokenLiteralDataLoaded;
+
   typedef ContinuousRangeMap
 GlobalMacroMapType;
 


Index: lib/Serialization/ASTWriter.cpp
===
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -4287,6 +4287,8 @@
   Record.push_back(Tok.getKind());
   // FIXME: Should translate token flags to a stable encoding.
   Record.push_back(Tok.getFlags());
+  if (Tok.isLiteral())
+ AddString(Tok.getLiteralData(), Record);
 }
 
 void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) {
Index: lib/Serialization/ASTReader.cpp
===
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -1517,6 +1517,12 @@
 Tok.setIdentifierInfo(II);
   Tok.setKind((tok::TokenKind)Record[Idx++]);
   Tok.setFlag((Token::TokenFlags)Record[Idx++]);
+  if (Tok.isLiteral()) {
+ const RecordData& RD = reinterpret_cast(Record);
+ std::string* Lit = new std::string(ReadString(RD, Idx));
+ TokenLiteralDataLoaded.push_back(Lit);
+ Tok.setLiteralData(Lit->c_str());
+  }
   return Tok;
 }
 
@@ -9909,6 +9915,9 @@
 ASTReader::~ASTReader() {
   if (OwnsDeserializationListener)
 delete DeserializationListener;
+  for (auto PStr: TokenLiteralDataLoaded) {
+ delete PStr;
+  }
 }
 
 IdentifierResolver &ASTReader::getIdResolver() {
Index: include/clang/Serialization/ASTReader.h
===
--- include/clang/Serialization/ASTReader.h
+++ include/clang/Serialization/ASTReader.h
@@ -604,6 +604,9 @@
   /// files.
   llvm::DenseSet LoadedUndefs;
 
+  /// \brief Token literal data loaded and owned by us.
+  std::vector TokenLiteralDataLoaded;
+
   typedef ContinuousRangeMap
 GlobalMacroMapType;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34984: Store token literal data in PCH. Avoids disk read on PreProc expansion.

2017-07-05 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a subscriber: karies.
v.g.vassilev added a comment.

What would be the best way to test this. Shall we put:

  echo '#define LITERAL 42' > HEADER.h
  
  clang++ -std=c++14 -x c++-header -o HEADER.h.pch HEADER.h
  
  chmod a-r HEADER.h
  
  echo 'void f(int); void g() { f(12); }' | clang++ -std=c++14 -Xclang
  -fno-validate-pch -include-pch HEADER.h.pch -c -Xclang -emit-llvm -o -
  -x c++ -
  # works, we see the IR
  
  echo 'void f(int); void g() { f(LITERAL); }' | clang++ -std=c++14
  -Xclang -fno-validate-pch -include-pch HEADER.h.pch -c -Xclang
  -emit-llvm -o - -x c++ -
  fatal error: cannot open file
  '/home/axel/build/tmp/clang-repro-PCH-touches-disk-for-literal/HEADER.h':
  Permission denied
  1 error generated.


Repository:
  rL LLVM

https://reviews.llvm.org/D34984



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


[PATCH] D34985: Do not read the file to determine its name.

2017-07-05 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev created this revision.

Patch by Axel Naumann!


Repository:
  rL LLVM

https://reviews.llvm.org/D34985

Files:
  lib/Basic/SourceManager.cpp


Index: lib/Basic/SourceManager.cpp
===
--- lib/Basic/SourceManager.cpp
+++ lib/Basic/SourceManager.cpp
@@ -1474,7 +1474,15 @@
bool *Invalid) const {
   if (isInvalid(Loc, Invalid)) return "";
 
-  return getBuffer(getFileID(Loc), Invalid)->getBufferIdentifier();
+  // Try to get the name without reading the buffer.
+  FileID FID = getFileID(Loc);
+  const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, Invalid);
+  if (!Invalid && Entry.isFile()) {
+if (const FileEntry* FE = Entry.getFile().getContentCache()->ContentsEntry)
+  return FE->getName();
+  }
+
+  return getBuffer(FID, Invalid)->getBufferIdentifier();
 }
 
 


Index: lib/Basic/SourceManager.cpp
===
--- lib/Basic/SourceManager.cpp
+++ lib/Basic/SourceManager.cpp
@@ -1474,7 +1474,15 @@
bool *Invalid) const {
   if (isInvalid(Loc, Invalid)) return "";
 
-  return getBuffer(getFileID(Loc), Invalid)->getBufferIdentifier();
+  // Try to get the name without reading the buffer.
+  FileID FID = getFileID(Loc);
+  const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, Invalid);
+  if (!Invalid && Entry.isFile()) {
+if (const FileEntry* FE = Entry.getFile().getContentCache()->ContentsEntry)
+  return FE->getName();
+  }
+
+  return getBuffer(FID, Invalid)->getBufferIdentifier();
 }
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34985: Do not read the file to determine its name.

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

The test case could be shared from PR33688:

  echo 'void* func(char* p)   __attribute__((annotate("blah"))); void*
  func(char* p){return p;}' > HEADER.h
  
 clang++ -std=c++14 -x c++-header -o HEADER.h.pch HEADER.h
 chmod a-r HEADER.h
 echo 'char i; void* ptr = func(&i);' | clang++ -v -std=c++14 -Xclang
  -fno-validate-pch -include-pch HEADER.h.pch -c -Xclang -emit-llvm -o -
  -x c++ -


Repository:
  rL LLVM

https://reviews.llvm.org/D34985



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


r307087 - clang-format: [JS] space between pseudo keywords and template literals.

2017-07-05 Thread Martin Probst via cfe-commits
Author: mprobst
Date: Tue Jul  4 08:30:21 2017
New Revision: 307087

URL: http://llvm.org/viewvc/llvm-project?rev=307087&view=rev
Log:
clang-format: [JS] space between pseudo keywords and template literals.

Summary:
Before:
  yield`foo`;

After:
  yield `foo`;

This reinstates commit 71d3b5cd91 / r307023 and fixes the logic by
introducing an explicit table of JavaScript pseudo keywords.

Reviewers: djasper

Subscribers: klimek

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

Modified:
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/FormatToken.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.h?rev=307087&r1=307086&r2=307087&view=diff
==
--- cfe/trunk/lib/Format/FormatToken.h (original)
+++ cfe/trunk/lib/Format/FormatToken.h Tue Jul  4 08:30:21 2017
@@ -21,6 +21,7 @@
 #include "clang/Format/Format.h"
 #include "clang/Lex/Lexer.h"
 #include 
+#include 
 
 namespace clang {
 namespace format {
@@ -645,6 +646,13 @@ struct AdditionalKeywords {
 kw_var = &IdentTable.get("var");
 kw_yield = &IdentTable.get("yield");
 
+JsExtraKeywords = std::unordered_set(
+{kw_as, kw_async, kw_await, kw_declare, kw_finally, kw_from,
+ kw_function, kw_get, kw_import, kw_is, kw_let, kw_module, kw_set,
+ kw_type, kw_var, kw_yield,
+ // Keywords from the Java section.
+ kw_abstract, kw_extends, kw_implements, kw_instanceof, kw_interface});
+
 kw_abstract = &IdentTable.get("abstract");
 kw_assert = &IdentTable.get("assert");
 kw_extends = &IdentTable.get("extends");
@@ -733,6 +741,18 @@ struct AdditionalKeywords {
   IdentifierInfo *kw_qsignals;
   IdentifierInfo *kw_slots;
   IdentifierInfo *kw_qslots;
+
+  /// \brief Returns \c true if \p Tok is a true JavaScript identifier, returns
+  /// \c false if it is a keyword or a pseudo keyword.
+  bool IsJavaScriptIdentifier(const FormatToken &Tok) const {
+return Tok.is(tok::identifier) &&
+   JsExtraKeywords.find(Tok.Tok.getIdentifierInfo()) ==
+   JsExtraKeywords.end();
+  }
+
+private:
+  /// \brief The JavaScript keywords beyond the C++ keyword set.
+  std::unordered_set JsExtraKeywords;
 };
 
 } // namespace format

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=307087&r1=307086&r2=307087&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Jul  4 08:30:21 2017
@@ -2319,7 +2319,11 @@ bool TokenAnnotator::spaceRequiredBefore
 if ((Left.is(TT_TemplateString) && Left.TokenText.endswith("${")) ||
 (Right.is(TT_TemplateString) && Right.TokenText.startswith("}")))
   return false;
-if (Left.is(tok::identifier) && Right.is(TT_TemplateString))
+// In tagged template literals ("html`bar baz`"), there is no space between
+// the tag identifier and the template string. getIdentifierInfo makes sure
+// that the identifier is not a pseudo keyword like `yield`, either.
+if (Left.is(tok::identifier) && Keywords.IsJavaScriptIdentifier(Left) &&
+Right.is(TT_TemplateString))
   return false;
 if (Right.is(tok::star) &&
 Left.isOneOf(Keywords.kw_function, Keywords.kw_yield))

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=307087&r1=307086&r2=307087&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Tue Jul  4 08:30:21 2017
@@ -1622,6 +1622,7 @@ TEST_F(FormatTestJS, NestedTemplateStrin
 
 TEST_F(FormatTestJS, TaggedTemplateStrings) {
   verifyFormat("var x = html``;");
+  verifyFormat("yield `hello`;");
 }
 
 TEST_F(FormatTestJS, CastSyntax) {


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


Re: [PATCH] D34972: [CodeGen] Propagate dllexport to thunks

2017-07-05 Thread David Majnemer via cfe-commits
What about the import side?

On Mon, Jul 3, 2017 at 10:37 PM Shoaib Meenai via Phabricator via
cfe-commits  wrote:

> smeenai created this revision.
>
> Under Windows Itanium, we need to export virtual and non-virtual thunks
> if the functions being thunked are exported. These thunks would
> previously inherit their dllexport attribute from the declaration, but
> r298330 changed declarations to not have dllexport attributes. We
> therefore need to add the dllexport attribute to the definition
> ourselves now. This is consistent with MinGW GCC's behavior.
>
> This redoes r306770 but limits the logic to Itanium. MicrosoftCXXABI's
> setThunkLinkage ensures that thunks aren't exported under that ABI, so
> I'm handling this in ItaniumCXXABI's setThunkLinkage for symmetry.
>
>
> https://reviews.llvm.org/D34972
>
> Files:
>   lib/CodeGen/ItaniumCXXABI.cpp
>   test/CodeGenCXX/dllexport-vtable-thunks.cpp
>
>
> Index: test/CodeGenCXX/dllexport-vtable-thunks.cpp
> ===
> --- /dev/null
> +++ test/CodeGenCXX/dllexport-vtable-thunks.cpp
> @@ -0,0 +1,23 @@
> +// RUN: %clang_cc1 -triple x86_64-windows-gnu -fdeclspec -emit-llvm -o -
> %s | FileCheck %s
> +// RUN: %clang_cc1 -triple x86_64-windows-itanium -fdeclspec -emit-llvm
> -o - %s | FileCheck %s
> +
> +struct __declspec(dllexport) A {
> +  virtual void m();
> +};
> +struct __declspec(dllexport) B {
> +  virtual void m();
> +};
> +struct __declspec(dllexport) C : A, B {
> +  virtual void m();
> +};
> +void C::m() {}
> +// CHECK: define dllexport void @_ZThn8_N1C1mEv
> +
> +struct Base {
> +  virtual void m();
> +};
> +struct __declspec(dllexport) Derived : virtual Base {
> +  virtual void m();
> +};
> +void Derived::m() {}
> +// CHECK: define dllexport void @_ZTv0_n24_N7Derived1mEv
> Index: lib/CodeGen/ItaniumCXXABI.cpp
> ===
> --- lib/CodeGen/ItaniumCXXABI.cpp
> +++ lib/CodeGen/ItaniumCXXABI.cpp
> @@ -284,6 +284,11 @@
>  // linkage together with vtables when needed.
>  if (ForVTable && !Thunk->hasLocalLinkage())
>Thunk->setLinkage(llvm::GlobalValue::AvailableExternallyLinkage);
> +
> +// Propagate dllexport storage.
> +const CXXMethodDecl *MD = cast(GD.getDecl());
> +if (MD->hasAttr())
> +  Thunk->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
>}
>
>llvm::Value *performThisAdjustment(CodeGenFunction &CGF, Address This,
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34404: [Clang-Tidy] Preserve Message, FileOffset, FilePath in Clang-Tidy YAML output

2017-07-05 Thread Vladimir Plyashkun via Phabricator via cfe-commits
vladimir.plyashkun added inline comments.



Comment at: unittests/clang-apply-replacements/ApplyReplacementsTest.cpp:23
+  SmallVector EmptyNotes;
+  return tooling::Diagnostic(DiagnosticName, Message, Replacements, EmptyNotes,
+ tooling::Diagnostic::Warning, BuildDirectory);

alexfh wrote:
> alexfh wrote:
> > Will `{}` work instead of `EmptyNotes`?
> `tooling::` is not needed due to the using directive above. Same below.
Unfortunately, no.
Constructor expects non-const reference `SmallVector 
&Notes`, so i can't pass rvalue directly to it.


Repository:
  rL LLVM

https://reviews.llvm.org/D34404



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


[PATCH] D34404: [Clang-Tidy] Preserve Message, FileOffset, FilePath in Clang-Tidy YAML output

2017-07-05 Thread Vladimir Plyashkun via Phabricator via cfe-commits
vladimir.plyashkun added inline comments.



Comment at: unittests/clang-apply-replacements/ApplyReplacementsTest.cpp:18
+
+static tooling::Diagnostic makeDiagnostic(const StringRef DiagnosticName,
+  DiagnosticMessage &Message,

alexfh wrote:
> I'd remove `const` from `DiagnosticName`, since a StringRef doesn't allow to 
> modify the string it points to (and marking by value arguments `const` is not 
> common in LLVM). However, `Message` and `Replacements` allow to modify the 
> referenced objects and thus should be marked `const`.
> 
> Also consider inlining this method, it doesn't buy you much.
Same for here. 
Constructor for `Diagnostic` class requires non-const references for `Message` 
and `Replacements` arguments. So, it's invalid to mark them as `const`.


Repository:
  rL LLVM

https://reviews.llvm.org/D34404



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


[PATCH] D34937: Suppressing Reference Counting Diagnostics for Functions Containing 'rc_ownership_trusted_implementation' Annotate Attribute

2017-07-05 Thread Malhar Thakkar via Phabricator via cfe-commits
malhar1995 updated this revision to Diff 105186.
malhar1995 added a comment.

Added relevant test-cases to verify the added functionality.


Repository:
  rL LLVM

https://reviews.llvm.org/D34937

Files:
  lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
  test/Analysis/retain-release-inline.m

Index: test/Analysis/retain-release-inline.m
===
--- test/Analysis/retain-release-inline.m
+++ test/Analysis/retain-release-inline.m
@@ -12,7 +12,7 @@
 //
 // It includes the basic definitions for the test cases below.
 //===--===//
-
+#define NULL 0
 typedef unsigned int __darwin_natural_t;
 typedef unsigned long uintptr_t;
 typedef unsigned int uint32_t;
@@ -267,6 +267,10 @@
 
 extern CFStringRef CFStringCreateWithCStringNoCopy(CFAllocatorRef alloc, const char *cStr, CFStringEncoding encoding, CFAllocatorRef contentsDeallocator);
 
+typedef struct {
+int ref;
+} isl_basic_map;
+
 //===--===//
 // Test cases.
 //===--===//
@@ -285,6 +289,7 @@
   foo(s);
   bar(s);
 }
+
 void test_neg() {
   NSString *s = [[NSString alloc] init]; // no-warning  
   foo(s);
@@ -294,6 +299,48 @@
   bar(s);
 }
 
+__attribute__((cf_returns_retained)) isl_basic_map *isl_basic_map_copy(isl_basic_map *bmap);
+__attribute__((cf_returns_retained)) isl_basic_map *isl_basic_map_cow(__attribute__((cf_consumed)) isl_basic_map *bmap);
+isl_basic_map *isl_basic_map_decrement_reference_count(__attribute__((cf_consumed)) isl_basic_map *bmap);
+void free(void *);
+
+__attribute__((annotate("rc_ownership_trusted_implementation"))) __attribute__((cf_returns_retained)) isl_basic_map *test_use_after_release_with_trusted_implementation_annotate_attribute(__attribute__((cf_consumed)) isl_basic_map *bmap) {
+  // After this call, 'temp' has a +1 reference count.
+  isl_basic_map *temp = isl_basic_map_copy(bmap);
+  // After this call, 'bmap' has a +1 reference count.
+  bmap = isl_basic_map_cow(bmap);
+  // After this call, 'bmap' has a +0 reference count.
+  isl_basic_map_decrement_reference_count(bmap);
+  isl_basic_map_decrement_reference_count(bmap);  // no-warning {{A 'use-after-release' warning is not raised here as this function has 'rc_ownership_trusted_implementation' annotate attribute}}
+  return temp;
+}
+
+isl_basic_map *isl_basic_map_free(__attribute__((cf_consumed)) isl_basic_map *bmap) {
+  if (!bmap)
+return NULL;
+
+  if (--bmap->ref > 0)
+return NULL;
+
+  free(bmap);
+  return NULL;
+}
+
+__attribute__((cf_returns_retained)) isl_basic_map *test_leak_with_trusted_implementation_annotate_attribute(__attribute__((cf_consumed)) isl_basic_map *bmap) {
+  // After this call, 'temp' has a +1 reference count.
+  isl_basic_map *temp = isl_basic_map_copy(bmap);
+  // After this call, 'bmap' has a +1 reference count.
+  bmap = isl_basic_map_cow(bmap); // no-warning {{A 'leak' warning is not raised here as 'foo_bar' (annotated with 'rc_ownership_trusted_implementation') is on the call-stack}}
+  // After this call, assuming the predicate of the second if branch to be true, 'bmap' has a +1 reference count.
+  isl_basic_map_free(bmap);
+  return temp;
+}
+
+__attribute__((annotate("rc_ownership_trusted_implementation"))) __attribute__((cf_returns_retained)) isl_basic_map *foo_bar(__attribute__((cf_consumed)) isl_basic_map *bmap) {
+  bmap = test_leak_with_trusted_annotate_attribute(bmap);
+  return bmap;
+}
+
 //===--===//
 // Test returning retained and not-retained values.
 //===--===//
Index: lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -1894,6 +1894,23 @@
   return SFC->getAnalysisDeclContext()->isBodyAutosynthesized();
 }
 
+/// Returns true if any declaration on the call-stack contains
+/// 'rc_ownership_trusted_implementation' annotate attribute.
+bool isTrustedReferenceCountImplementation(const LocationContext *LCtx) {
+  while (LCtx) {
+if (const StackFrameContext *SFC = dyn_cast(LCtx)) {
+  const Decl *D = SFC->getDecl();
+  for (const auto *Ann : D->specific_attrs()) {
+if (Ann->getAnnotation() == "rc_ownership_trusted_implementation") {
+  return true;
+}
+  }
+}
+LCtx = LCtx->getParent();
+  }
+  return false;
+}
+
 std::shared_ptr
 CFRefReportVisitor::VisitNode(const ExplodedNode *N, const ExplodedNode *PrevN,
   BugReporterContext &BRC, BugReport &BR) {
@@ -3345,11 +3362,13 @@
   }
 
   assert(BT);
-  auto report = std::unique_ptr(
-  new CFRefReport(*BT, C.getASTC

[PATCH] D34987: [AMDGPU] Fix regressions on mesa/clover with libclc due to address space

2017-07-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
Herald added subscribers: t-tye, tpr, dstuttard, wdng, kzhuravl.

Currently AMDGPUTargetInfo does not initialize AddrSpaceMap in constructor, 
which causes regressions in mesa/clover with libclc.

This patch fixes that.


https://reviews.llvm.org/D34987

Files:
  lib/Basic/Targets.cpp
  test/CodeGenOpenCL/address-spaces.cl


Index: test/CodeGenOpenCL/address-spaces.cl
===
--- test/CodeGenOpenCL/address-spaces.cl
+++ test/CodeGenOpenCL/address-spaces.cl
@@ -4,6 +4,8 @@
 // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-opencl -DCL20 
-cl-std=CL2.0 -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20SPIR
 // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-amdgizcl -emit-llvm -o - | 
FileCheck %s -check-prefixes=CHECK,GIZ
 // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-amdgizcl -DCL20 
-cl-std=CL2.0 -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20GIZ
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-mesa-mesa3d -emit-llvm -o - | 
FileCheck --check-prefixes=CHECK,SPIR %s
+// RUN: %clang_cc1 %s -O0 -triple r600-- -emit-llvm -o - | FileCheck 
--check-prefixes=CHECK,SPIR %s
 
 // SPIR: i32* %arg
 // GIZ: i32 addrspace(5)* %arg
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -2049,7 +2049,7 @@
   return llvm::makeArrayRef(GCCRegNames);
 }
 
-static const LangAS::Map AMDGPUNonOpenCLPrivateIsZeroMap = {
+static const LangAS::Map AMDGPUPrivIsZeroDefIsGenMap = {
 4, // Default
 1, // opencl_global
 3, // opencl_local
@@ -2059,7 +2059,7 @@
 2, // cuda_constant
 3  // cuda_shared
 };
-static const LangAS::Map AMDGPUNonOpenCLGenericIsZeroMap = {
+static const LangAS::Map AMDGPUGenIsZeroDefIsGenMap = {
 0, // Default
 1, // opencl_global
 3, // opencl_local
@@ -2069,7 +2069,7 @@
 2, // cuda_constant
 3  // cuda_shared
 };
-static const LangAS::Map AMDGPUOpenCLPrivateIsZeroMap = {
+static const LangAS::Map AMDGPUPrivIsZeroDefIsPrivMap = {
 0, // Default
 1, // opencl_global
 3, // opencl_local
@@ -2079,7 +2079,7 @@
 2, // cuda_constant
 3  // cuda_shared
 };
-static const LangAS::Map AMDGPUOpenCLGenericIsZeroMap = {
+static const LangAS::Map AMDGPUGenIsZeroDefIsPrivMap = {
 5, // Default
 1, // opencl_global
 3, // opencl_local
@@ -2184,20 +2184,28 @@
 : DataLayoutStringR600);
 assert(DataLayout->getAllocaAddrSpace() == AS.Private);
 
+setAddressSpaceMap(Triple.getOS() == llvm::Triple::Mesa3D ||
+   Triple.getEnvironment() == llvm::Triple::OpenCL ||
+   Triple.getEnvironmentName() == "amdgizcl" ||
+   !isAMDGCN(Triple));
 UseAddrSpaceMapMangling = true;
   }
 
-  void adjust(LangOptions &Opts) override {
-TargetInfo::adjust(Opts);
+  void setAddressSpaceMap(bool DefaultIsGeneric) {
 if (isGenericZero(getTriple())) {
-  AddrSpaceMap = Opts.OpenCL ? &AMDGPUOpenCLGenericIsZeroMap
- : &AMDGPUNonOpenCLGenericIsZeroMap;
+  AddrSpaceMap = DefaultIsGeneric ? &AMDGPUGenIsZeroDefIsPrivMap
+  : &AMDGPUGenIsZeroDefIsGenMap;
 } else {
-  AddrSpaceMap = Opts.OpenCL ? &AMDGPUOpenCLPrivateIsZeroMap
- : &AMDGPUNonOpenCLPrivateIsZeroMap;
+  AddrSpaceMap = DefaultIsGeneric ? &AMDGPUPrivIsZeroDefIsPrivMap
+  : &AMDGPUPrivIsZeroDefIsGenMap;
 }
   }
 
+  void adjust(LangOptions &Opts) override {
+TargetInfo::adjust(Opts);
+setAddressSpaceMap(Opts.OpenCL || !isAMDGCN(getTriple()));
+  }
+
   uint64_t getPointerWidthV(unsigned AddrSpace) const override {
 if (GPU <= GK_CAYMAN)
   return 32;


Index: test/CodeGenOpenCL/address-spaces.cl
===
--- test/CodeGenOpenCL/address-spaces.cl
+++ test/CodeGenOpenCL/address-spaces.cl
@@ -4,6 +4,8 @@
 // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-opencl -DCL20 -cl-std=CL2.0 -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20SPIR
 // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-amdgizcl -emit-llvm -o - | FileCheck %s -check-prefixes=CHECK,GIZ
 // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-amdgizcl -DCL20 -cl-std=CL2.0 -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20GIZ
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-mesa-mesa3d -emit-llvm -o - | FileCheck --check-prefixes=CHECK,SPIR %s
+// RUN: %clang_cc1 %s -O0 -triple r600-- -emit-llvm -o - | FileCheck --check-prefixes=CHECK,SPIR %s
 
 // SPIR: i32* %arg
 // GIZ: i32 addrspace(5)* %arg
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -2049,7 +2049,7 @@
   return llvm::makeArrayRef(GCCRegNames);
 }
 
-static const LangAS::M

[PATCH] D34987: [AMDGPU] Fix regressions on mesa/clover with libclc due to address space

2017-07-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 105189.
yaxunl added a comment.

Fix typo.


https://reviews.llvm.org/D34987

Files:
  lib/Basic/Targets.cpp
  test/CodeGenOpenCL/address-spaces.cl


Index: test/CodeGenOpenCL/address-spaces.cl
===
--- test/CodeGenOpenCL/address-spaces.cl
+++ test/CodeGenOpenCL/address-spaces.cl
@@ -4,6 +4,8 @@
 // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-opencl -DCL20 
-cl-std=CL2.0 -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20SPIR
 // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-amdgizcl -emit-llvm -o - | 
FileCheck %s -check-prefixes=CHECK,GIZ
 // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-amdgizcl -DCL20 
-cl-std=CL2.0 -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20GIZ
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-mesa-mesa3d -emit-llvm -o - | 
FileCheck --check-prefixes=CHECK,SPIR %s
+// RUN: %clang_cc1 %s -O0 -triple r600-- -emit-llvm -o - | FileCheck 
--check-prefixes=CHECK,SPIR %s
 
 // SPIR: i32* %arg
 // GIZ: i32 addrspace(5)* %arg
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -2049,7 +2049,7 @@
   return llvm::makeArrayRef(GCCRegNames);
 }
 
-static const LangAS::Map AMDGPUNonOpenCLPrivateIsZeroMap = {
+static const LangAS::Map AMDGPUPrivIsZeroDefIsGenMap = {
 4, // Default
 1, // opencl_global
 3, // opencl_local
@@ -2059,7 +2059,7 @@
 2, // cuda_constant
 3  // cuda_shared
 };
-static const LangAS::Map AMDGPUNonOpenCLGenericIsZeroMap = {
+static const LangAS::Map AMDGPUGenIsZeroDefIsGenMap = {
 0, // Default
 1, // opencl_global
 3, // opencl_local
@@ -2069,7 +2069,7 @@
 2, // cuda_constant
 3  // cuda_shared
 };
-static const LangAS::Map AMDGPUOpenCLPrivateIsZeroMap = {
+static const LangAS::Map AMDGPUPrivIsZeroDefIsPrivMap = {
 0, // Default
 1, // opencl_global
 3, // opencl_local
@@ -2079,7 +2079,7 @@
 2, // cuda_constant
 3  // cuda_shared
 };
-static const LangAS::Map AMDGPUOpenCLGenericIsZeroMap = {
+static const LangAS::Map AMDGPUGenIsZeroDefIsPrivMap = {
 5, // Default
 1, // opencl_global
 3, // opencl_local
@@ -2184,20 +2184,28 @@
 : DataLayoutStringR600);
 assert(DataLayout->getAllocaAddrSpace() == AS.Private);
 
+setAddressSpaceMap(Triple.getOS() == llvm::Triple::Mesa3D ||
+   Triple.getEnvironment() == llvm::Triple::OpenCL ||
+   Triple.getEnvironmentName() == "amdgizcl" ||
+   !isAMDGCN(Triple));
 UseAddrSpaceMapMangling = true;
   }
 
-  void adjust(LangOptions &Opts) override {
-TargetInfo::adjust(Opts);
+  void setAddressSpaceMap(bool DefaultIsPrivate) {
 if (isGenericZero(getTriple())) {
-  AddrSpaceMap = Opts.OpenCL ? &AMDGPUOpenCLGenericIsZeroMap
- : &AMDGPUNonOpenCLGenericIsZeroMap;
+  AddrSpaceMap = DefaultIsPrivate ? &AMDGPUGenIsZeroDefIsPrivMap
+  : &AMDGPUGenIsZeroDefIsGenMap;
 } else {
-  AddrSpaceMap = Opts.OpenCL ? &AMDGPUOpenCLPrivateIsZeroMap
- : &AMDGPUNonOpenCLPrivateIsZeroMap;
+  AddrSpaceMap = DefaultIsPrivate ? &AMDGPUPrivIsZeroDefIsPrivMap
+  : &AMDGPUPrivIsZeroDefIsGenMap;
 }
   }
 
+  void adjust(LangOptions &Opts) override {
+TargetInfo::adjust(Opts);
+setAddressSpaceMap(Opts.OpenCL || !isAMDGCN(getTriple()));
+  }
+
   uint64_t getPointerWidthV(unsigned AddrSpace) const override {
 if (GPU <= GK_CAYMAN)
   return 32;


Index: test/CodeGenOpenCL/address-spaces.cl
===
--- test/CodeGenOpenCL/address-spaces.cl
+++ test/CodeGenOpenCL/address-spaces.cl
@@ -4,6 +4,8 @@
 // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-opencl -DCL20 -cl-std=CL2.0 -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20SPIR
 // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-amdgizcl -emit-llvm -o - | FileCheck %s -check-prefixes=CHECK,GIZ
 // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-amdgizcl -DCL20 -cl-std=CL2.0 -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20GIZ
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-mesa-mesa3d -emit-llvm -o - | FileCheck --check-prefixes=CHECK,SPIR %s
+// RUN: %clang_cc1 %s -O0 -triple r600-- -emit-llvm -o - | FileCheck --check-prefixes=CHECK,SPIR %s
 
 // SPIR: i32* %arg
 // GIZ: i32 addrspace(5)* %arg
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -2049,7 +2049,7 @@
   return llvm::makeArrayRef(GCCRegNames);
 }
 
-static const LangAS::Map AMDGPUNonOpenCLPrivateIsZeroMap = {
+static const LangAS::Map AMDGPUPrivIsZeroDefIsGenMap = {
 4, // Default
 1, // opencl_global
 3, // opencl_local
@@ -2

[PATCH] D34206: [clang-tidy] Add "MakeSmartPtrFunction" option to modernize-make-shared/unique checks.

2017-07-05 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 105190.
hokein marked 2 inline comments as done.
hokein added a comment.

Fix small nits.


https://reviews.llvm.org/D34206

Files:
  clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tidy/modernize/MakeSmartPtrCheck.h
  docs/clang-tidy/checks/modernize-make-shared.rst
  docs/clang-tidy/checks/modernize-make-unique.rst
  test/clang-tidy/Inputs/modernize-smart-ptr/shared_ptr.h
  test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h
  test/clang-tidy/modernize-make-shared-header.cpp
  test/clang-tidy/modernize-make-shared.cpp
  test/clang-tidy/modernize-make-unique-header.cpp
  test/clang-tidy/modernize-make-unique.cpp

Index: test/clang-tidy/modernize-make-unique.cpp
===
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -1,32 +1,8 @@
-// RUN: %check_clang_tidy %s modernize-make-unique %t
+// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++11 \
+// RUN:   -I%S/Inputs/modernize-smart-ptr
 
-namespace std {
-
-template 
-class default_delete {};
-
-template >
-class unique_ptr {
-public:
-  unique_ptr();
-  unique_ptr(type *ptr);
-  unique_ptr(const unique_ptr &t) = delete;
-  unique_ptr(unique_ptr &&t);
-  ~unique_ptr();
-  type &operator*() { return *ptr; }
-  type *operator->() { return ptr; }
-  type *release();
-  void reset();
-  void reset(type *pt);
-  void reset(type pt);
-  unique_ptr &operator=(unique_ptr &&);
-  template 
-  unique_ptr &operator=(unique_ptr &&);
-
-private:
-  type *ptr;
-};
-}
+#include "unique_ptr.h"
+// CHECK-FIXES: #include 
 
 struct Base {
   Base();
Index: test/clang-tidy/modernize-make-unique-header.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-make-unique-header.cpp
@@ -0,0 +1,17 @@
+// RUN: %check_clang_tidy %s modernize-make-unique %t -- \
+// RUN:   -config="{CheckOptions: \
+// RUN: [{key: modernize-make-unique.MakeSmartPtrFunction, \
+// RUN:   value: 'my::MakeUnique'}, \
+// RUN:  {key: modernize-make-unique.MakeSmartPtrFunctionHeader, \
+// RUN:   value: 'make_unique_util.h'} \
+// RUN: ]}" \
+// RUN:   -- -std=c++11 -I%S/Inputs/modernize-smart-ptr
+
+#include "unique_ptr.h"
+// CHECK-FIXES: #include "make_unique_util.h"
+
+void f() {
+  std::unique_ptr P1 = std::unique_ptr(new int());
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use my::MakeUnique instead
+  // CHECK-FIXES: std::unique_ptr P1 = my::MakeUnique();
+}
Index: test/clang-tidy/modernize-make-shared.cpp
===
--- test/clang-tidy/modernize-make-shared.cpp
+++ test/clang-tidy/modernize-make-shared.cpp
@@ -1,28 +1,8 @@
-// RUN: %check_clang_tidy %s modernize-make-shared %t
+// RUN: %check_clang_tidy %s modernize-make-shared %t -- -- -std=c++11 \
+// RUN:   -I%S/Inputs/modernize-smart-ptr
 
-namespace std {
-
-template 
-class shared_ptr {
-public:
-  shared_ptr();
-  shared_ptr(type *ptr);
-  shared_ptr(const shared_ptr &t) {}
-  shared_ptr(shared_ptr &&t) {}
-  ~shared_ptr();
-  type &operator*() { return *ptr; }
-  type *operator->() { return ptr; }
-  type *release();
-  void reset();
-  void reset(type *pt);
-  shared_ptr &operator=(shared_ptr &&);
-  template 
-  shared_ptr &operator=(shared_ptr &&);
-
-private:
-  type *ptr;
-};
-}
+#include "shared_ptr.h"
+// CHECK-FIXES: #include 
 
 struct Base {
   Base();
Index: test/clang-tidy/modernize-make-shared-header.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-make-shared-header.cpp
@@ -0,0 +1,17 @@
+// RUN: %check_clang_tidy %s modernize-make-shared %t -- \
+// RUN:   -config="{CheckOptions: \
+// RUN: [{key: modernize-make-shared.MakeSmartPtrFunction, \
+// RUN:   value: 'my::MakeShared'}, \
+// RUN:  {key: modernize-make-shared.MakeSmartPtrFunctionHeader, \
+// RUN:   value: 'make_shared_util.h'} \
+// RUN: ]}" \
+// RUN:   -- -std=c++11 -I%S/Inputs/modernize-smart-ptr
+
+#include "shared_ptr.h"
+// CHECK-FIXES: #include "make_shared_util.h"
+
+void f() {
+  std::shared_ptr P1 = std::shared_ptr(new int());
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use my::MakeShared instead
+  // CHECK-FIXES: std::shared_ptr P1 = my::MakeShared();
+}
Index: test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h
===
--- /dev/null
+++ test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h
@@ -0,0 +1,28 @@
+namespace std {
+
+template 
+class default_delete {};
+
+template >
+class unique_ptr {
+public:
+  unique_ptr();
+  unique_ptr(type *ptr);
+  unique_ptr(const unique_ptr &t) = delete;
+  unique_ptr(unique_ptr &&t);
+  ~unique_ptr();
+  type &operator*() { return *ptr; }
+  type *operator->() { return ptr; }
+  type *release();
+  void reset();
+  void reset(type *pt);
+  void reset(type pt);
+ 

[PATCH] D34913: [clang-tidy] Add a new Android check "android-cloexec-socket"

2017-07-05 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tidy/utils/CloexecFlagChecker.h:21
+/// specific macro flag in a given argument.
+bool hasCloseOnExecFlag(const Expr *Flags, const SourceManager &SM,
+const LangOptions &LangOpts,

Maybe put this function to `utils/ASTUtils.h` file.

The name `CloseOnExecFlag` is too specific, it actually checks whether the 
`flags` expr has a given flag IMO, might be call it `hasFlag` (a better name 
are welcome), and document more details of the API in the above comment.



Comment at: test/clang-tidy/android-cloexec-socket.cpp:20
+  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: 'socket' should use 
SOCK_CLOEXEC where possible [android-cloexec-socket]
+  // CHECK-FIXES: SOCK_STREAM | SOCK_CLOEXEC
+  TEMP_FAILURE_RETRY(socket(0, SOCK_STREAM, 0));

I'd use the complete statement for checking the fixes here, the same below.



Comment at: test/clang-tidy/android-cloexec-socket.cpp:92
+};
+

nit: remove the empty line.


Repository:
  rL LLVM

https://reviews.llvm.org/D34913



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


[PATCH] D34980: [OpenCL] Test on image access modifiers and image type can only be a type of a function argument.

2017-07-05 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: test/SemaOpenCL/images.cl:14
+void myReadWrite (read_write image2d_t);
+void myIndifferent (image2d_t); // expected-note 2{{passing argument to 
parameter here}}
+

Would it be better to rename to make the purpose more clear:
myIndifferent -> myDefault




Comment at: test/SemaOpenCL/images.cl:17
+
+kernel void k1 (read_only image2d_t img) {
+  myWrite(img); // expected-error {{passing '__read_only image2d_t' to 
parameter of incompatible type '__write_only image2d_t'}}

Like above I would try to give the function some descriptive names...



Comment at: test/SemaOpenCL/images.cl:25
+
+// Should be all OK.
+kernel void k3 (read_write image2d_t img) {

I don't get this comment.



Comment at: test/SemaOpenCL/images.cl:32
+
+// Legal to path everything to an 'indifferent' function.
+kernel void k4(read_write image2d_t i1, read_only image2d_t i2,

I don't get this comment too?



Comment at: test/SemaOpenCL/images.cl:36
+  myIndifferent(i1); // expected-error {{passing '__read_write image2d_t' to 
parameter of incompatible type '__read_only image2d_t'}}
+  myIndifferent(i2);
+  myIndifferent(i3); // expected-error {{passing '__write_only image2d_t' to 
parameter of incompatible type '__read_only image2d_t'}}

For consistency we could add
  //read_only = read_only



Comment at: test/SemaOpenCL/images.cl:40
+
+kernel void k5(read_only image2d_t srcimg)
+{

I think we test this in test/SemaOpenCL/invalid-image.cl

Feel free to combine in one file if you like.


https://reviews.llvm.org/D34980



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


[PATCH] D34987: [AMDGPU] Fix regressions on mesa/clover with libclc due to address space

2017-07-05 Thread Aaron Watry via Phabricator via cfe-commits
awatry accepted this revision.
awatry added a comment.
This revision is now accepted and ready to land.

FWIW, this looks ok to me.

Just as importantly, this fixes the address space mapping regressions for both 
r600 (BARTS) and GCN/AMDGPU (PITCAIRN) for me.


https://reviews.llvm.org/D34987



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


r307104 - Enable LLVM asan support for NetBSD/amd64

2017-07-05 Thread Kamil Rytarowski via cfe-commits
Author: kamil
Date: Tue Jul  4 12:55:56 2017
New Revision: 307104

URL: http://llvm.org/viewvc/llvm-project?rev=307104&view=rev
Log:
Enable LLVM asan support for NetBSD/amd64

Summary:
Enable LLVM asan sanitizer for NetBSD/amd64.

Don't generate -ldl for dlopen(3)-like functions on NetBSD.
These features are available in libc on NetBSD.

Sponsored by 

Reviewers: joerg, eugenis, kcc, dim

Reviewed By: dim

Subscribers: #clang, #sanitizers

Tags: #clang, #sanitizers

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

Modified:
cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp
cfe/trunk/lib/Driver/ToolChains/NetBSD.h

Modified: cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp?rev=307104&r1=307103&r2=307104&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp Tue Jul  4 12:55:56 2017
@@ -524,6 +524,7 @@ void tools::linkSanitizerRuntimeDeps(con
   CmdArgs.push_back("-lm");
   // There's no libdl on FreeBSD or RTEMS.
   if (TC.getTriple().getOS() != llvm::Triple::FreeBSD &&
+  TC.getTriple().getOS() != llvm::Triple::NetBSD &&
   TC.getTriple().getOS() != llvm::Triple::RTEMS)
 CmdArgs.push_back("-ldl");
 }

Modified: cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp?rev=307104&r1=307103&r2=307104&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/NetBSD.cpp Tue Jul  4 12:55:56 2017
@@ -15,6 +15,7 @@
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/Options.h"
+#include "clang/Driver/SanitizerArgs.h"
 #include "llvm/Option/ArgList.h"
 
 using namespace clang::driver;
@@ -246,6 +247,7 @@ void netbsd::Linker::ConstructJob(Compil
   Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag);
   Args.AddAllArgs(CmdArgs, options::OPT_r);
 
+  bool NeedsSanitizerDeps = addSanitizerRuntimes(getToolChain(), Args, 
CmdArgs);
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
 
   unsigned Major, Minor, Micro;
@@ -279,6 +281,8 @@ void netbsd::Linker::ConstructJob(Compil
   getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
   CmdArgs.push_back("-lm");
 }
+if (NeedsSanitizerDeps)
+  linkSanitizerRuntimeDeps(getToolChain(), CmdArgs);
 if (Args.hasArg(options::OPT_pthread))
   CmdArgs.push_back("-lpthread");
 CmdArgs.push_back("-lc");
@@ -410,3 +414,12 @@ void NetBSD::addLibStdCxxIncludePaths(co
   addLibStdCXXIncludePaths(getDriver().SysRoot, "/usr/include/g++", "", "", "",
"", DriverArgs, CC1Args);
 }
+
+SanitizerMask NetBSD::getSupportedSanitizers() const {
+  const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64;
+  SanitizerMask Res = ToolChain::getSupportedSanitizers();
+  if (IsX86_64) {
+Res |= SanitizerKind::Address;
+  }
+  return Res;
+}

Modified: cfe/trunk/lib/Driver/ToolChains/NetBSD.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/NetBSD.h?rev=307104&r1=307103&r2=307104&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/NetBSD.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/NetBSD.h Tue Jul  4 12:55:56 2017
@@ -66,6 +66,7 @@ public:
   llvm::opt::ArgStringList &CC1Args) const override;
 
   bool IsUnwindTablesDefault() const override { return true; }
+  SanitizerMask getSupportedSanitizers() const override;
 
 protected:
   Tool *buildAssembler() const override;


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


r307105 - [AMDGPU] Fix regressions on mesa/clover with libclc due to address space

2017-07-05 Thread Yaxun Liu via cfe-commits
Author: yaxunl
Date: Tue Jul  4 12:57:18 2017
New Revision: 307105

URL: http://llvm.org/viewvc/llvm-project?rev=307105&view=rev
Log:
[AMDGPU] Fix regressions on mesa/clover with libclc due to address space

Currently AMDGPUTargetInfo does not initialize AddrSpaceMap in constructor, 
which causes regressions in mesa/clover with libclc.

This patch fixes that.

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

Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/test/CodeGenOpenCL/address-spaces.cl

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=307105&r1=307104&r2=307105&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Tue Jul  4 12:57:18 2017
@@ -2049,7 +2049,7 @@ ArrayRef NVPTXTargetInfo::
   return llvm::makeArrayRef(GCCRegNames);
 }
 
-static const LangAS::Map AMDGPUNonOpenCLPrivateIsZeroMap = {
+static const LangAS::Map AMDGPUPrivIsZeroDefIsGenMap = {
 4, // Default
 1, // opencl_global
 3, // opencl_local
@@ -2059,7 +2059,7 @@ static const LangAS::Map AMDGPUNonOpenCL
 2, // cuda_constant
 3  // cuda_shared
 };
-static const LangAS::Map AMDGPUNonOpenCLGenericIsZeroMap = {
+static const LangAS::Map AMDGPUGenIsZeroDefIsGenMap = {
 0, // Default
 1, // opencl_global
 3, // opencl_local
@@ -2069,7 +2069,7 @@ static const LangAS::Map AMDGPUNonOpenCL
 2, // cuda_constant
 3  // cuda_shared
 };
-static const LangAS::Map AMDGPUOpenCLPrivateIsZeroMap = {
+static const LangAS::Map AMDGPUPrivIsZeroDefIsPrivMap = {
 0, // Default
 1, // opencl_global
 3, // opencl_local
@@ -2079,7 +2079,7 @@ static const LangAS::Map AMDGPUOpenCLPri
 2, // cuda_constant
 3  // cuda_shared
 };
-static const LangAS::Map AMDGPUOpenCLGenericIsZeroMap = {
+static const LangAS::Map AMDGPUGenIsZeroDefIsPrivMap = {
 5, // Default
 1, // opencl_global
 3, // opencl_local
@@ -2184,20 +2184,28 @@ public:
 : DataLayoutStringR600);
 assert(DataLayout->getAllocaAddrSpace() == AS.Private);
 
+setAddressSpaceMap(Triple.getOS() == llvm::Triple::Mesa3D ||
+   Triple.getEnvironment() == llvm::Triple::OpenCL ||
+   Triple.getEnvironmentName() == "amdgizcl" ||
+   !isAMDGCN(Triple));
 UseAddrSpaceMapMangling = true;
   }
 
-  void adjust(LangOptions &Opts) override {
-TargetInfo::adjust(Opts);
+  void setAddressSpaceMap(bool DefaultIsPrivate) {
 if (isGenericZero(getTriple())) {
-  AddrSpaceMap = Opts.OpenCL ? &AMDGPUOpenCLGenericIsZeroMap
- : &AMDGPUNonOpenCLGenericIsZeroMap;
+  AddrSpaceMap = DefaultIsPrivate ? &AMDGPUGenIsZeroDefIsPrivMap
+  : &AMDGPUGenIsZeroDefIsGenMap;
 } else {
-  AddrSpaceMap = Opts.OpenCL ? &AMDGPUOpenCLPrivateIsZeroMap
- : &AMDGPUNonOpenCLPrivateIsZeroMap;
+  AddrSpaceMap = DefaultIsPrivate ? &AMDGPUPrivIsZeroDefIsPrivMap
+  : &AMDGPUPrivIsZeroDefIsGenMap;
 }
   }
 
+  void adjust(LangOptions &Opts) override {
+TargetInfo::adjust(Opts);
+setAddressSpaceMap(Opts.OpenCL || !isAMDGCN(getTriple()));
+  }
+
   uint64_t getPointerWidthV(unsigned AddrSpace) const override {
 if (GPU <= GK_CAYMAN)
   return 32;

Modified: cfe/trunk/test/CodeGenOpenCL/address-spaces.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/address-spaces.cl?rev=307105&r1=307104&r2=307105&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/address-spaces.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/address-spaces.cl Tue Jul  4 12:57:18 2017
@@ -4,6 +4,8 @@
 // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-opencl -DCL20 
-cl-std=CL2.0 -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20SPIR
 // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-amdgizcl -emit-llvm -o - | 
FileCheck %s -check-prefixes=CHECK,GIZ
 // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-amdgizcl -DCL20 
-cl-std=CL2.0 -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20GIZ
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-mesa-mesa3d -emit-llvm -o - | 
FileCheck --check-prefixes=CHECK,SPIR %s
+// RUN: %clang_cc1 %s -O0 -triple r600-- -emit-llvm -o - | FileCheck 
--check-prefixes=CHECK,SPIR %s
 
 // SPIR: i32* %arg
 // GIZ: i32 addrspace(5)* %arg


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


[PATCH] D34987: [AMDGPU] Fix regressions on mesa/clover with libclc due to address space

2017-07-05 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307105: [AMDGPU] Fix regressions on mesa/clover with libclc 
due to address space (authored by yaxunl).

Changed prior to commit:
  https://reviews.llvm.org/D34987?vs=105189&id=105196#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34987

Files:
  cfe/trunk/lib/Basic/Targets.cpp
  cfe/trunk/test/CodeGenOpenCL/address-spaces.cl


Index: cfe/trunk/lib/Basic/Targets.cpp
===
--- cfe/trunk/lib/Basic/Targets.cpp
+++ cfe/trunk/lib/Basic/Targets.cpp
@@ -2049,7 +2049,7 @@
   return llvm::makeArrayRef(GCCRegNames);
 }
 
-static const LangAS::Map AMDGPUNonOpenCLPrivateIsZeroMap = {
+static const LangAS::Map AMDGPUPrivIsZeroDefIsGenMap = {
 4, // Default
 1, // opencl_global
 3, // opencl_local
@@ -2059,7 +2059,7 @@
 2, // cuda_constant
 3  // cuda_shared
 };
-static const LangAS::Map AMDGPUNonOpenCLGenericIsZeroMap = {
+static const LangAS::Map AMDGPUGenIsZeroDefIsGenMap = {
 0, // Default
 1, // opencl_global
 3, // opencl_local
@@ -2069,7 +2069,7 @@
 2, // cuda_constant
 3  // cuda_shared
 };
-static const LangAS::Map AMDGPUOpenCLPrivateIsZeroMap = {
+static const LangAS::Map AMDGPUPrivIsZeroDefIsPrivMap = {
 0, // Default
 1, // opencl_global
 3, // opencl_local
@@ -2079,7 +2079,7 @@
 2, // cuda_constant
 3  // cuda_shared
 };
-static const LangAS::Map AMDGPUOpenCLGenericIsZeroMap = {
+static const LangAS::Map AMDGPUGenIsZeroDefIsPrivMap = {
 5, // Default
 1, // opencl_global
 3, // opencl_local
@@ -2184,20 +2184,28 @@
 : DataLayoutStringR600);
 assert(DataLayout->getAllocaAddrSpace() == AS.Private);
 
+setAddressSpaceMap(Triple.getOS() == llvm::Triple::Mesa3D ||
+   Triple.getEnvironment() == llvm::Triple::OpenCL ||
+   Triple.getEnvironmentName() == "amdgizcl" ||
+   !isAMDGCN(Triple));
 UseAddrSpaceMapMangling = true;
   }
 
-  void adjust(LangOptions &Opts) override {
-TargetInfo::adjust(Opts);
+  void setAddressSpaceMap(bool DefaultIsPrivate) {
 if (isGenericZero(getTriple())) {
-  AddrSpaceMap = Opts.OpenCL ? &AMDGPUOpenCLGenericIsZeroMap
- : &AMDGPUNonOpenCLGenericIsZeroMap;
+  AddrSpaceMap = DefaultIsPrivate ? &AMDGPUGenIsZeroDefIsPrivMap
+  : &AMDGPUGenIsZeroDefIsGenMap;
 } else {
-  AddrSpaceMap = Opts.OpenCL ? &AMDGPUOpenCLPrivateIsZeroMap
- : &AMDGPUNonOpenCLPrivateIsZeroMap;
+  AddrSpaceMap = DefaultIsPrivate ? &AMDGPUPrivIsZeroDefIsPrivMap
+  : &AMDGPUPrivIsZeroDefIsGenMap;
 }
   }
 
+  void adjust(LangOptions &Opts) override {
+TargetInfo::adjust(Opts);
+setAddressSpaceMap(Opts.OpenCL || !isAMDGCN(getTriple()));
+  }
+
   uint64_t getPointerWidthV(unsigned AddrSpace) const override {
 if (GPU <= GK_CAYMAN)
   return 32;
Index: cfe/trunk/test/CodeGenOpenCL/address-spaces.cl
===
--- cfe/trunk/test/CodeGenOpenCL/address-spaces.cl
+++ cfe/trunk/test/CodeGenOpenCL/address-spaces.cl
@@ -4,6 +4,8 @@
 // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-opencl -DCL20 
-cl-std=CL2.0 -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20SPIR
 // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-amdgizcl -emit-llvm -o - | 
FileCheck %s -check-prefixes=CHECK,GIZ
 // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa-amdgizcl -DCL20 
-cl-std=CL2.0 -emit-llvm -o - | FileCheck %s --check-prefixes=CL20,CL20GIZ
+// RUN: %clang_cc1 %s -O0 -triple amdgcn-mesa-mesa3d -emit-llvm -o - | 
FileCheck --check-prefixes=CHECK,SPIR %s
+// RUN: %clang_cc1 %s -O0 -triple r600-- -emit-llvm -o - | FileCheck 
--check-prefixes=CHECK,SPIR %s
 
 // SPIR: i32* %arg
 // GIZ: i32 addrspace(5)* %arg


Index: cfe/trunk/lib/Basic/Targets.cpp
===
--- cfe/trunk/lib/Basic/Targets.cpp
+++ cfe/trunk/lib/Basic/Targets.cpp
@@ -2049,7 +2049,7 @@
   return llvm::makeArrayRef(GCCRegNames);
 }
 
-static const LangAS::Map AMDGPUNonOpenCLPrivateIsZeroMap = {
+static const LangAS::Map AMDGPUPrivIsZeroDefIsGenMap = {
 4, // Default
 1, // opencl_global
 3, // opencl_local
@@ -2059,7 +2059,7 @@
 2, // cuda_constant
 3  // cuda_shared
 };
-static const LangAS::Map AMDGPUNonOpenCLGenericIsZeroMap = {
+static const LangAS::Map AMDGPUGenIsZeroDefIsGenMap = {
 0, // Default
 1, // opencl_global
 3, // opencl_local
@@ -2069,7 +2069,7 @@
 2, // cuda_constant
 3  // cuda_shared
 };
-static const LangAS::Map AMDGPUOpenCLPrivateIsZeroMap = {
+static const LangAS::Map AMDGPUPrivIsZeroDefIsPrivMap = {
 0, // Default
 1, // opencl_global
 3, // opencl_local
@@ -2079,7 +2079,7 @@
 2, // cu

[PATCH] D34475: [RFC] [AArch64] Add support for __builtin_ms_va_list on aarch64

2017-07-05 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo updated this revision to Diff 105200.
mstorsjo added a comment.

Did a minor adjustment, to make sure a plain va_arg produces the right kind of 
output, when targeting windows directly (while the rest of the patch mostly is 
about supporting the MS ABI while targeting a different OS).


https://reviews.llvm.org/D34475

Files:
  include/clang/Basic/BuiltinsAArch64.def
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/Specifiers.h
  lib/AST/ItaniumMangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaDeclAttr.cpp

Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -4279,8 +4279,13 @@
   case AttributeList::AT_VectorCall: CC = CC_X86VectorCall; break;
   case AttributeList::AT_RegCall: CC = CC_X86RegCall; break;
   case AttributeList::AT_MSABI:
-CC = Context.getTargetInfo().getTriple().isOSWindows() ? CC_C :
- CC_X86_64Win64;
+
+CC = Context.getTargetInfo().getTriple().isOSWindows()
+ ? CC_C
+ : Context.getTargetInfo().getTriple().getArch() ==
+   llvm::Triple::aarch64
+   ? CC_AArch64Win64
+   : CC_X86_64Win64;
 break;
   case AttributeList::AT_SysVABI:
 CC = Context.getTargetInfo().getTriple().isOSWindows() ? CC_X86_64SysV :
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -1437,6 +1437,9 @@
 
 bool Sema::CheckAArch64BuiltinFunctionCall(unsigned BuiltinID,
  CallExpr *TheCall) {
+  if (BuiltinID == AArch64::BI__builtin_ms_va_start)
+return SemaBuiltinVAStart(BuiltinID, TheCall);
+
   if (BuiltinID == AArch64::BI__builtin_arm_ldrex ||
   BuiltinID == AArch64::BI__builtin_arm_ldaex ||
   BuiltinID == AArch64::BI__builtin_arm_strex ||
@@ -3619,12 +3622,15 @@
 static bool checkVAStartABI(Sema &S, unsigned BuiltinID, Expr *Fn) {
   const llvm::Triple &TT = S.Context.getTargetInfo().getTriple();
   bool IsX64 = TT.getArch() == llvm::Triple::x86_64;
+  bool IsAArch64 = TT.getArch() == llvm::Triple::aarch64;
   bool IsWindows = TT.isOSWindows();
-  bool IsMSVAStart = BuiltinID == X86::BI__builtin_ms_va_start;
+  bool IsMSVAStart = BuiltinID == X86::BI__builtin_ms_va_start ||
+ BuiltinID == AArch64::BI__builtin_ms_va_start;
+  clang::CallingConv CC = CC_C;
+  if (const FunctionDecl *FD = S.getCurFunctionDecl())
+CC = FD->getType()->getAs()->getCallConv();
+
   if (IsX64) {
-clang::CallingConv CC = CC_C;
-if (const FunctionDecl *FD = S.getCurFunctionDecl())
-  CC = FD->getType()->getAs()->getCallConv();
 if (IsMSVAStart) {
   // Don't allow this in System V ABI functions.
   if (CC == CC_X86_64SysV || (!IsWindows && CC != CC_X86_64Win64))
@@ -3644,6 +3650,22 @@
 return false;
   }
 
+  if (IsAArch64) {
+if (IsMSVAStart) {
+  // Don't allow this in AAPCS functions.
+  if (CC == CC_C || (!IsWindows && CC != CC_AArch64Win64))
+return S.Diag(Fn->getLocStart(),
+  diag::err_ms_va_start_used_in_aapcs_function);
+} else {
+  // On aarch64 Unix, don't allow this in Win64 ABI functions.
+  if (!IsWindows && CC == CC_AArch64Win64)
+return S.Diag(Fn->getLocStart(),
+  diag::err_va_start_used_in_wrong_abi_function)
+   << !IsWindows;
+}
+return false;
+  }
+
   if (IsMSVAStart)
 return S.Diag(Fn->getLocStart(), diag::err_x86_builtin_64_only);
   return false;
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -4770,10 +4770,11 @@
 
 private:
   ABIKind Kind;
+  bool IsMS;
 
 public:
-  AArch64ABIInfo(CodeGenTypes &CGT, ABIKind Kind)
-: SwiftABIInfo(CGT), Kind(Kind) {}
+  AArch64ABIInfo(CodeGenTypes &CGT, ABIKind Kind, bool MS)
+  : SwiftABIInfo(CGT), Kind(Kind), IsMS(MS) {}
 
 private:
   ABIKind getABIKind() const { return Kind; }
@@ -4803,9 +4804,12 @@
 
   Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
 QualType Ty) const override {
-return isDarwinPCS() ? EmitDarwinVAArg(VAListAddr, Ty, CGF)
- : EmitAAPCSVAArg(VAListAddr, Ty, CGF);
+return IsMS ? EmitMSVAArg(CGF, VAListAddr, Ty)
+: isDarwinPCS() ? EmitDarwinVAArg(VAListAddr, Ty, CGF)
+: EmitAAPCSVAArg(VAListAddr, Ty, CGF);
   }
+  Address EmitMSVAArg(CodeGenFunction &CGF, Address VAListAddr,
+  QualType Ty) const 

[PATCH] D34992: Emit static constexpr member as available_externally definition

2017-07-05 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini created this revision.

This enables better optimization, I don't if it is legal c++11 though.


https://reviews.llvm.org/D34992

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCXX/cxx11-extern-constexpr.cpp


Index: clang/test/CodeGenCXX/cxx11-extern-constexpr.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx11-extern-constexpr.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -std=c++11 %s -emit-llvm -o - -triple x86_64-linux-gnu | 
FileCheck %s
+
+template
+int min(const T &a, const T &b) {
+   return a > b ? b : a;
+}
+
+struct Foo {
+// CHECK: @_ZN3Foo3BARE = available_externally constant i32 42,
+  static constexpr int BAR = 42; 
+// CHECK: @_ZN3Foo4BAR2E = external constant i32,
+  static const int BAR2 = 43; 
+};
+// CHECK: @_ZL4BAR3 = available_externally constant i32 44,
+static constexpr int BAR3 = 44;
+
+int foo(int v) {
+   return min(min(Foo::BAR, Foo::BAR2), BAR3);
+}
+
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -2368,11 +2368,22 @@
   return llvm::ConstantExpr::getBitCast(Entry, Ty);
   }
 
+  auto Linkage = llvm::GlobalValue::ExternalLinkage;
+
+  llvm::Constant *Init = nullptr;
+  if (D && D->isConstexpr() && !D->isInline() && !D->hasAttr()) 
{
+const VarDecl *InitDecl;
+const Expr *InitExpr = D->getAnyInitializer(InitDecl);
+if (InitExpr) {
+  Init = EmitConstantInit(*InitDecl);
+  Linkage = llvm::GlobalValue::AvailableExternallyLinkage;
+}
+  }
+
   unsigned AddrSpace = GetGlobalVarAddressSpace(D, Ty->getAddressSpace());
   auto *GV = new llvm::GlobalVariable(
-  getModule(), Ty->getElementType(), false,
-  llvm::GlobalValue::ExternalLinkage, nullptr, MangledName, nullptr,
-  llvm::GlobalVariable::NotThreadLocal, AddrSpace);
+  getModule(), Ty->getElementType(), false, Linkage, Init, MangledName,
+  nullptr, llvm::GlobalVariable::NotThreadLocal, AddrSpace);
 
   // If we already created a global with the same mangled name (but different
   // type) before, take its name and remove it from its parent.


Index: clang/test/CodeGenCXX/cxx11-extern-constexpr.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx11-extern-constexpr.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -std=c++11 %s -emit-llvm -o - -triple x86_64-linux-gnu | FileCheck %s
+
+template
+int min(const T &a, const T &b) {
+	return a > b ? b : a;
+}
+
+struct Foo {
+// CHECK: @_ZN3Foo3BARE = available_externally constant i32 42,
+  static constexpr int BAR = 42; 
+// CHECK: @_ZN3Foo4BAR2E = external constant i32,
+  static const int BAR2 = 43; 
+};
+// CHECK: @_ZL4BAR3 = available_externally constant i32 44,
+static constexpr int BAR3 = 44;
+
+int foo(int v) {
+	return min(min(Foo::BAR, Foo::BAR2), BAR3);
+}
+
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -2368,11 +2368,22 @@
   return llvm::ConstantExpr::getBitCast(Entry, Ty);
   }
 
+  auto Linkage = llvm::GlobalValue::ExternalLinkage;
+
+  llvm::Constant *Init = nullptr;
+  if (D && D->isConstexpr() && !D->isInline() && !D->hasAttr()) {
+const VarDecl *InitDecl;
+const Expr *InitExpr = D->getAnyInitializer(InitDecl);
+if (InitExpr) {
+  Init = EmitConstantInit(*InitDecl);
+  Linkage = llvm::GlobalValue::AvailableExternallyLinkage;
+}
+  }
+
   unsigned AddrSpace = GetGlobalVarAddressSpace(D, Ty->getAddressSpace());
   auto *GV = new llvm::GlobalVariable(
-  getModule(), Ty->getElementType(), false,
-  llvm::GlobalValue::ExternalLinkage, nullptr, MangledName, nullptr,
-  llvm::GlobalVariable::NotThreadLocal, AddrSpace);
+  getModule(), Ty->getElementType(), false, Linkage, Init, MangledName,
+  nullptr, llvm::GlobalVariable::NotThreadLocal, AddrSpace);
 
   // If we already created a global with the same mangled name (but different
   // type) before, take its name and remove it from its parent.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r307115 - [modules ts] Declarations from a module interface unit are only visible outside

2017-07-05 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Jul  4 18:42:07 2017
New Revision: 307115

URL: http://llvm.org/viewvc/llvm-project?rev=307115&view=rev
Log:
[modules ts] Declarations from a module interface unit are only visible outside
the module if declared in an export block. 

Added:
cfe/trunk/test/CXX/modules-ts/basic/basic.link/p2/
cfe/trunk/test/CXX/modules-ts/basic/basic.link/p2/module.cpp
cfe/trunk/test/CXX/modules-ts/basic/basic.link/p2/module.cppm
cfe/trunk/test/CXX/modules-ts/basic/basic.link/p2/other.cpp
Modified:
cfe/trunk/include/clang/AST/DeclBase.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/DeclBase.cpp
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/test/CXX/modules-ts/dcl.dcl/dcl.module/dcl.module.import/p1.cpp
cfe/trunk/test/SemaCXX/modules-ts.cppm

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=307115&r1=307114&r2=307115&view=diff
==
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Tue Jul  4 18:42:07 2017
@@ -749,7 +749,7 @@ public:
   /// Set that this declaration is globally visible, even if it came from a
   /// module that is not visible.
   void setVisibleDespiteOwningModule() {
-if (hasOwningModule())
+if (getModuleOwnershipKind() == ModuleOwnershipKind::VisibleWhenImported)
   setModuleOwnershipKind(ModuleOwnershipKind::Visible);
   }
 

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=307115&r1=307114&r2=307115&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue Jul  4 18:42:07 2017
@@ -1266,6 +1266,7 @@ public:
 
   void emitAndClearUnusedLocalTypedefWarnings();
 
+  void ActOnStartOfTranslationUnit();
   void ActOnEndOfTranslationUnit();
 
   void CheckDelegatingCtorCycles();
@@ -1541,6 +1542,7 @@ public:
  llvm::SmallVectorImpl *Modules);
 
   bool hasVisibleMergedDefinition(NamedDecl *Def);
+  bool hasMergedDefinitionInCurrentModule(NamedDecl *Def);
 
   /// Determine if \p D and \p Suggested have a structurally compatible
   /// layout as described in C11 6.2.7/1.

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=307115&r1=307114&r2=307115&view=diff
==
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Tue Jul  4 18:42:07 2017
@@ -283,7 +283,7 @@ void Decl::setLexicalDeclContext(DeclCon
   setLocalOwningModule(cast(DC)->getOwningModule());
   }
 
-  assert((!hasOwningModule() || getOwningModule()) &&
+  assert((!hasOwningModule() || getOwningModule() || isModulePrivate()) &&
  "hidden declaration has no owning module");
 }
 

Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=307115&r1=307114&r2=307115&view=diff
==
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Tue Jul  4 18:42:07 2017
@@ -526,6 +526,8 @@ void Parser::LateTemplateParserCleanupCa
 }
 
 bool Parser::ParseFirstTopLevelDecl(DeclGroupPtrTy &Result) {
+  Actions.ActOnStartOfTranslationUnit();
+
   // C11 6.9p1 says translation units must have at least one top-level
   // declaration. C++ doesn't have this restriction. We also don't want to
   // complain if we have a precompiled header, although technically if the PCH

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=307115&r1=307114&r2=307115&view=diff
==
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Tue Jul  4 18:42:07 2017
@@ -705,6 +705,18 @@ void Sema::emitAndClearUnusedLocalTypede
   UnusedLocalTypedefNameCandidates.clear();
 }
 
+/// This is called before the very first declaration in the translation unit
+/// is parsed. Note that the ASTContext may have already injected some
+/// declarations.
+void Sema::ActOnStartOfTranslationUnit() {
+  if (getLangOpts().ModulesTS) {
+// We start in the global module; all those declarations are implicitly
+// module-private (though they do not have module linkage).
+Context.getTranslationUnitDecl()->setModuleOwnershipKind(
+Decl::ModuleOwnershipKind::ModulePrivate);
+  }
+}
+
 /// ActOnEndOfTranslationUnit - This is called at the very end of the
 /// translation unit when EOF is reached and all

Re: [PATCH v3] [PPC64]: Add support for Swift calling convention

2017-07-05 Thread Andrew Jeffery via cfe-commits
Ping - is anyone able to provide feedback?

Cheers,

Andrew

On Thu, 2017-06-22 at 16:02 +0930, Andrew Jeffery wrote:
> For the tests I've extracted the int5 and int8 cases to cater for
> different alignments for different platform ABIs. For Linux on POWER the
> 5 and 8 element vectors must be naturally aligned with respect to the
> total "soft" vector size, despite being represented as an aggregate.
> Specifically, the patch caters for the following differences in
> supporting powerpc64le-unknown-linux:
> 
>    $ diff -u test/CodeGen/64bit-swiftcall.c test/CodeGen/ppc64-swiftcall.c
> >    --- test/CodeGen/64bit-swiftcall.c   2017-04-20 17:14:59.797963820 
> > +0930
> >    +++ test/CodeGen/ppc64-swiftcall.c   2017-04-20 17:15:11.621965118 
> > +0930
>    @@ -1,7 +1,6 @@
>    -// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 
> -emit-llvm -o - %s | FileCheck %s
>    -// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone 
> -emit-llvm -o - %s | FileCheck %s
>    +// RUN: %clang_cc1 -triple powerpc64le-unknown-linux -emit-llvm -o - %s | 
> FileCheck %s
> 
>    -// REQUIRES: aarch64-registered-target,x86-registered-target
>    +// REQUIRES: powerpc-registered-target
> 
> #define SWIFTCALL __attribute__((swiftcall))
> #define OUT __attribute__((swift_indirect_result))
>    @@ -370,8 +369,8 @@
> 
> TEST(int8)
> // CHECK-LABEL: define {{.*}} @return_int8()
>    -// CHECK:   [[RET:%.*]] = alloca [[REC:<8 x i32>]], align 16
>    +// CHECK:   [[RET:%.*]] = alloca [[REC:<8 x i32>]], align 32
> // CHECK:   [[VAR:%.*]] = alloca [[REC]], align
> // CHECK:   store
> // CHECK:   load
> // CHECK:   store
>    @@ -414,8 +413,8 @@
> 
> TEST(int5)
> // CHECK-LABEL: define {{.*}} @return_int5()
>    -// CHECK:   [[RET:%.*]] = alloca [[REC:<5 x i32>]], align 16
>    +// CHECK:   [[RET:%.*]] = alloca [[REC:<5 x i32>]], align 32
> // CHECK:   [[VAR:%.*]] = alloca [[REC]], align
> // CHECK:   store
> // CHECK:   load
> // CHECK:   store
> 
> Despite some duplication, the advantage of this approach over using
> pattern matching for alignment in 64bit-swiftcall.c is that we ensure
> each platform is using the expected alignment but without duplicating
> the entirety of 64bit-swiftcall.c.
> 
> > Signed-off-by: Andrew Jeffery 
> ---
> 
> Hello,
> 
> The only change in v3 is rebasing it on top upstream HEAD, fixing a conflict 
> in
> one of the lit REQUIRES lines.
> 
> Ulrich, Hal, Bill: I've Cc'ed you as you were fingered by the blame output. As
> some background I sent the patch several months ago but it hasn't got much
> traction aside from a LGTM from Adrian (thanks!). I'm hoping it gets a bit 
> more
> attention as without it we get build failures for Swift on POWER, which is
> in-turn blocking some CI efforts. 
> 
> Cheers,
> 
> Andrew
> 
>  lib/Basic/Targets.cpp |  11 ++
>  lib/CodeGen/TargetInfo.cpp|  14 ++-
>  test/CodeGen/64bit-swiftcall-extvec-agg-align16.c | 117 
> ++
>  test/CodeGen/64bit-swiftcall-extvec-agg-align32.c | 116 +
>  test/CodeGen/64bit-swiftcall.c|  93 +
>  5 files changed, 258 insertions(+), 93 deletions(-)
>  create mode 100644 test/CodeGen/64bit-swiftcall-extvec-agg-align16.c
>  create mode 100644 test/CodeGen/64bit-swiftcall-extvec-agg-align32.c
> 
> diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp
> index e23a93e..54b5911 100644
> --- a/lib/Basic/Targets.cpp
> +++ b/lib/Basic/Targets.cpp
> @@ -1753,6 +1753,17 @@ public:
>  }
>  return false;
>    }
> +
> +  CallingConvCheckResult checkCallingConvention(CallingConv CC) const 
> override {
> +switch (CC) {
> +case CC_C:
> +case CC_Swift:
> +return CCCR_OK;
> +default:
> +break;
> +}
> +return CCCR_Warning;
> +  }
>  };
>  
>  class DarwinPPC32TargetInfo : public DarwinTargetInfo {
> diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp
> index 8d00e05..a82cd24 100644
> --- a/lib/CodeGen/TargetInfo.cpp
> +++ b/lib/CodeGen/TargetInfo.cpp
> @@ -4179,7 +4179,7 @@ 
> PPC32TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
>  
>  namespace {
>  /// PPC64_SVR4_ABIInfo - The 64-bit PowerPC ELF (SVR4) ABI information.
> -class PPC64_SVR4_ABIInfo : public ABIInfo {
> +class PPC64_SVR4_ABIInfo : public SwiftABIInfo {
>  public:
>    enum ABIKind {
>  ELFv1 = 0,
> @@ -4223,7 +4223,7 @@ private:
>  public:
>    PPC64_SVR4_ABIInfo(CodeGen::CodeGenTypes &CGT, ABIKind Kind, bool HasQPX,
>   bool SoftFloatABI)
> -  : ABIInfo(CGT), Kind(Kind), HasQPX(HasQPX),
> +  : SwiftABIInfo(CGT), Kind(Kind), HasQPX(HasQPX),
>  IsSoftFloatABI(SoftFloatABI) {}
>  
>    bool isPromotableTypeForABI(QualType Ty) const;
> @@ -4266,6 +4266,16 @@ public:
>  
>    Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
>  

[PATCH] D34770: [Bash-autocompletion] Auto complete cc1 options if -cc1 is specified

2017-07-05 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 105209.
yamaguchi added a comment.

Fixed typo.


https://reviews.llvm.org/D34770

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/autocomplete.c
  clang/utils/bash-autocomplete.sh
  llvm/include/llvm/Option/OptTable.h
  llvm/lib/Option/OptTable.cpp

Index: llvm/lib/Option/OptTable.cpp
===
--- llvm/lib/Option/OptTable.cpp
+++ llvm/lib/Option/OptTable.cpp
@@ -225,11 +225,15 @@
   return {};
 }
 
-std::vector OptTable::findByPrefix(StringRef Cur) const {
+std::vector
+OptTable::findByPrefix(StringRef Cur, unsigned short DisableFlags) const {
   std::vector Ret;
   for (const Info &In : OptionInfos.slice(FirstSearchableIndex)) {
 if (!In.Prefixes)
   continue;
+if (In.Flags & DisableFlags)
+  continue;
+
 for (int I = 0; In.Prefixes[I]; I++) {
   std::string S = std::string(In.Prefixes[I]) + std::string(In.Name);
   if (StringRef(S).startswith(Cur))
Index: llvm/include/llvm/Option/OptTable.h
===
--- llvm/include/llvm/Option/OptTable.h
+++ llvm/include/llvm/Option/OptTable.h
@@ -140,7 +140,8 @@
   //  to start with.
   ///
   /// \return The vector of flags which start with Cur.
-  std::vector findByPrefix(StringRef Cur) const;
+  std::vector findByPrefix(StringRef Cur,
+unsigned short DisableFlags) const;
 
   /// \brief Parse a single argument; returning the new argument and
   /// updating Index.
Index: clang/utils/bash-autocomplete.sh
===
--- clang/utils/bash-autocomplete.sh
+++ clang/utils/bash-autocomplete.sh
@@ -10,18 +10,23 @@
   # So, we need to partially undo bash tokenization here for integrity.
   local w1="${COMP_WORDS[$cword - 1]}"
   local w2="${COMP_WORDS[$cword - 2]}"
+  # Clang want to know if -cc1 or -Xclang option is specified or not, because we don't want to show
+  # cc1 options otherwise.
+  if [[ "${COMP_WORDS[1]}" == "-cc1" || "$w1" == "-Xclang" ]]; then
+arg="#"
+  fi
   if [[ "$cur" == -* ]]; then
 # -foo
-arg="$cur"
+arg="$arg$cur"
   elif [[ "$w1" == -*  && "$cur" == '=' ]]; then
 # -foo=
-arg="$w1=,"
+arg="$arg$w1=,"
   elif [[ "$w1" == -* ]]; then
 # -foo  or -foo bar
-arg="$w1,$cur"
+arg="$arg$w1,$cur"
   elif [[ "$w2" == -* && "$w1" == '=' ]]; then
 # -foo=bar
-arg="$w2=,$cur"
+arg="$arg$w2=,$cur"
   fi
 
   flags=$( "${COMP_WORDS[0]}" --autocomplete="$arg" 2>/dev/null )
Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -36,3 +36,7 @@
 // MTHREADMODELALL: posix single
 // RUN: %clang --autocomplete=-mrelocation-model, | FileCheck %s -check-prefix=MRELOCMODELALL
 // MRELOCMODELALL: dynamic-no-pic pic ropi ropi-rwpi rwpi static
+// RUN: %clang --autocomplete=-mrelocation-mode | FileCheck %s -check-prefix=MRELOCMODEL_CLANG
+// MRELOCMODEL_CLANG-NOT: -mrelocation-model
+// RUN: %clang --autocomplete=#-mrelocation-mode | FileCheck %s -check-prefix=MRELOCMODEL_CC1
+// MRELOCMODEL_CC1: -mrelocation-model
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1231,11 +1231,20 @@
 StringRef PassedFlags = A->getValue();
 std::vector SuggestedCompletions;
 
+unsigned short DisableFlags = options::NoDriverOption | options::Unsupported | options::Ignored;
+// We want to show cc1-only options only when clang is invoked as "clang -cc1".
+// When clang is invoked as "clang -cc1", we add "#" to the beginning of an --autocomplete
+// option so that the clang driver can distinguish whether it is requested to show cc1-only options or not.
+if (PassedFlags[0] == '#') {
+  DisableFlags &= ~options::NoDriverOption;
+  PassedFlags = PassedFlags.substr(1);
+}
+
 if (PassedFlags.find(',') == StringRef::npos) {
   // If the flag is in the form of "--autocomplete=-foo",
   // we were requested to print out all option names that start with "-foo".
   // For example, "--autocomplete=-fsyn" is expanded to "-fsyntax-only".
-  SuggestedCompletions = Opts->findByPrefix(PassedFlags);
+  SuggestedCompletions = Opts->findByPrefix(PassedFlags, DisableFlags);
 } else {
   // If the flag is in the form of "--autocomplete=foo,bar", we were
   // requested to print out all option values for "-foo" that start with
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34927: [Bash-autocompletion] Fix a bug that -foo=bar doesn't handled properly

2017-07-05 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 105208.
yamaguchi added a comment.

Update diff.
Thanks for the pointing out.


https://reviews.llvm.org/D34927

Files:
  clang/utils/bash-autocomplete.sh


Index: clang/utils/bash-autocomplete.sh
===
--- clang/utils/bash-autocomplete.sh
+++ clang/utils/bash-autocomplete.sh
@@ -34,12 +34,18 @@
   elif [[ "$w1" == -*  && "$cur" == '=' ]]; then
 # -foo=
 arg="$w1=,"
+  elif [[ "$cur" == -*= ]]; then
+# -foo=
+arg="$cur,"
   elif [[ "$w1" == -* ]]; then
 # -foo  or -foo bar
 arg="$w1,$cur"
   elif [[ "$w2" == -* && "$w1" == '=' ]]; then
 # -foo=bar
 arg="$w2=,$cur"
+  elif [[ ${cur: -1} != '=' && ${cur/=} != $cur ]]; then
+# -foo=bar
+arg="${cur%=*}=,${cur#*=}"
   fi
 
   # expand ~ to $HOME


Index: clang/utils/bash-autocomplete.sh
===
--- clang/utils/bash-autocomplete.sh
+++ clang/utils/bash-autocomplete.sh
@@ -34,12 +34,18 @@
   elif [[ "$w1" == -*  && "$cur" == '=' ]]; then
 # -foo=
 arg="$w1=,"
+  elif [[ "$cur" == -*= ]]; then
+# -foo=
+arg="$cur,"
   elif [[ "$w1" == -* ]]; then
 # -foo  or -foo bar
 arg="$w1,$cur"
   elif [[ "$w2" == -* && "$w1" == '=' ]]; then
 # -foo=bar
 arg="$w2=,$cur"
+  elif [[ ${cur: -1} != '=' && ${cur/=} != $cur ]]; then
+# -foo=bar
+arg="${cur%=*}=,${cur#*=}"
   fi
 
   # expand ~ to $HOME
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34930: [Bash-autocompletion] Show flags which has HelpText or GroupID

2017-07-05 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi added a comment.

We are going to ask community which flags should be autocompleted or not, and 
tidy Options.td.


https://reviews.llvm.org/D34930



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


[PATCH] D34770: [Bash-autocompletion] Auto complete cc1 options if -cc1 is specified

2017-07-05 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi added inline comments.



Comment at: clang/utils/bash-autocomplete.sh:16
+  if [[ "${COMP_WORDS[1]}" == "-cc1" || "$w1" == "-Xclang" ]]; then
+arg="#"
+  fi

compnerd wrote:
> `prefix` may be a better term?
Thanks for reviewing!
$arg has string like `-stdlib=,plat`, so `prefix` seems not very appropriate?


https://reviews.llvm.org/D34770



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


[PATCH] D34930: [Bash-autocompletion] Show flags which has HelpText or GroupID

2017-07-05 Thread Yuka Takahashi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307116: [Bash-autocompletion] Show flags which has HelpText 
or GroupID (authored by yamaguchi).

Changed prior to commit:
  https://reviews.llvm.org/D34930?vs=105017&id=105211#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34930

Files:
  llvm/trunk/lib/Option/OptTable.cpp


Index: llvm/trunk/lib/Option/OptTable.cpp
===
--- llvm/trunk/lib/Option/OptTable.cpp
+++ llvm/trunk/lib/Option/OptTable.cpp
@@ -228,7 +228,7 @@
 std::vector OptTable::findByPrefix(StringRef Cur) const {
   std::vector Ret;
   for (const Info &In : OptionInfos.slice(FirstSearchableIndex)) {
-if (!In.Prefixes)
+if (!In.Prefixes || (!In.HelpText && !In.GroupID))
   continue;
 for (int I = 0; In.Prefixes[I]; I++) {
   std::string S = std::string(In.Prefixes[I]) + std::string(In.Name);


Index: llvm/trunk/lib/Option/OptTable.cpp
===
--- llvm/trunk/lib/Option/OptTable.cpp
+++ llvm/trunk/lib/Option/OptTable.cpp
@@ -228,7 +228,7 @@
 std::vector OptTable::findByPrefix(StringRef Cur) const {
   std::vector Ret;
   for (const Info &In : OptionInfos.slice(FirstSearchableIndex)) {
-if (!In.Prefixes)
+if (!In.Prefixes || (!In.HelpText && !In.GroupID))
   continue;
 for (int I = 0; In.Prefixes[I]; I++) {
   std::string S = std::string(In.Prefixes[I]) + std::string(In.Name);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r307117 - Implement LWG 2937 - equivalent("dne", "exists") is not an error

2017-07-05 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Tue Jul  4 20:37:05 2017
New Revision: 307117

URL: http://llvm.org/viewvc/llvm-project?rev=307117&view=rev
Log:
Implement LWG 2937 - equivalent("dne", "exists") is not an error

This patch speculatively implements the PR for LWG 2937, which fixes
two issues with equivalent.

(1) It makes equivalent("dne", "exists") an error. Previously only
equivalent("dne", "dne") was an error and the former case was not (it 
returned false).
Now equivalent reports an error when either input doesn't exist.

(2) It makes equivalent(p1, p2) well-formed when `is_other(p1) && is_other(p2)`.
Previously this was an error, but there is seemingly no reason why it 
should be on POSIX system.

Modified:
libcxx/trunk/src/experimental/filesystem/operations.cpp

libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.equivalent/equivalent.pass.cpp
libcxx/trunk/www/upcoming_meeting.html

Modified: libcxx/trunk/src/experimental/filesystem/operations.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/experimental/filesystem/operations.cpp?rev=307117&r1=307116&r2=307117&view=diff
==
--- libcxx/trunk/src/experimental/filesystem/operations.cpp (original)
+++ libcxx/trunk/src/experimental/filesystem/operations.cpp Tue Jul  4 20:37:05 
2017
@@ -426,17 +426,20 @@ void __current_path(const path& p, std::
 
 bool __equivalent(const path& p1, const path& p2, std::error_code *ec)
 {
+auto make_unsupported_error = [&]() {
+  set_or_throw(make_error_code(errc::not_supported), ec,
+ "equivalent", p1, p2);
+  return false;
+};
 std::error_code ec1, ec2;
 struct ::stat st1 = {};
 struct ::stat st2 = {};
 auto s1 = detail::posix_stat(p1.native(), st1, &ec1);
+if (!exists(s1))
+  return make_unsupported_error();
 auto s2 = detail::posix_stat(p2.native(), st2, &ec2);
-
-if ((!exists(s1) && !exists(s2)) || (is_other(s1) && is_other(s2))) {
-set_or_throw(make_error_code(errc::not_supported), ec,
- "equivalent", p1, p2);
-return false;
-}
+if (!exists(s2))
+  return make_unsupported_error();
 if (ec) ec->clear();
 return (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino);
 }

Modified: 
libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.equivalent/equivalent.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.equivalent/equivalent.pass.cpp?rev=307117&r1=307116&r2=307117&view=diff
==
--- 
libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.equivalent/equivalent.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.equivalent/equivalent.pass.cpp
 Tue Jul  4 20:37:05 2017
@@ -26,63 +26,87 @@ using namespace std::experimental::files
 
 TEST_SUITE(equivalent_test_suite)
 
-TEST_CASE(signature_test)
-{
-const path p; ((void)p);
-std::error_code ec; ((void)ec);
-ASSERT_NOEXCEPT(equivalent(p, p, ec));
-ASSERT_NOT_NOEXCEPT(equivalent(p, p));
+TEST_CASE(signature_test) {
+  const path p;
+  ((void)p);
+  std::error_code ec;
+  ((void)ec);
+  ASSERT_NOEXCEPT(equivalent(p, p, ec));
+  ASSERT_NOT_NOEXCEPT(equivalent(p, p));
 }
 
-TEST_CASE(equivalent_test)
-{
-struct TestCase {
-path lhs;
-path rhs;
-bool expect;
-};
-const TestCase testCases[] = {
-{StaticEnv::Dir, StaticEnv::Dir, true},
-{StaticEnv::File, StaticEnv::Dir, false},
-{StaticEnv::Dir, StaticEnv::SymlinkToDir, true},
-{StaticEnv::Dir, StaticEnv::SymlinkToFile, false},
-{StaticEnv::File, StaticEnv::File, true},
-{StaticEnv::File, StaticEnv::SymlinkToFile, true},
-};
-for (auto& TC : testCases) {
-std::error_code ec;
-TEST_CHECK(equivalent(TC.lhs, TC.rhs, ec) == TC.expect);
-TEST_CHECK(!ec);
-}
+TEST_CASE(equivalent_test) {
+  struct TestCase {
+path lhs;
+path rhs;
+bool expect;
+  };
+  const TestCase testCases[] = {
+  {StaticEnv::Dir, StaticEnv::Dir, true},
+  {StaticEnv::File, StaticEnv::Dir, false},
+  {StaticEnv::Dir, StaticEnv::SymlinkToDir, true},
+  {StaticEnv::Dir, StaticEnv::SymlinkToFile, false},
+  {StaticEnv::File, StaticEnv::File, true},
+  {StaticEnv::File, StaticEnv::SymlinkToFile, true},
+  };
+  for (auto& TC : testCases) {
+std::error_code ec;
+TEST_CHECK(equivalent(TC.lhs, TC.rhs, ec) == TC.expect);
+TEST_CHECK(!ec);
+  }
 }
 
-TEST_CASE(equivalent_reports_double_dne)
-{
-const path E = StaticEnv::File;
-const path DNE = StaticEnv::DNE;
-{ // Test that no exception is thrown if one of the paths exists
-TEST_CHECK(equivalent(E, DNE) == false);
-TEST_CHECK(equivalent(DNE, E) == false);
-}
-{ // Test that an except

[libcxx] r307118 - Add dummy CMake target for *.pass.cpp tests when LIBCXX_CONFIGURE_IDE=ON.

2017-07-05 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Tue Jul  4 20:50:03 2017
New Revision: 307118

URL: http://llvm.org/viewvc/llvm-project?rev=307118&view=rev
Log:
Add dummy CMake target for *.pass.cpp tests when LIBCXX_CONFIGURE_IDE=ON.

In order for IDE's like CLion to correctly parse and highlight the tests
it needs to know roughly how to build them. This patch adds a dummy CMake target
for each/all of the .pass.cpp tests in the test suite to solve this problem.
The target is only created when LIBCXX_CONFIGURE_IDE=ON, so it shouldn't affect
most users.

Originally I wasn't sure that this change deserved to live upstream, but it's
quite frustrating to edit libc++ tests using CLion or Visual Studio without it,
in particular the filesystem tests which rely heavily on macros. Even though 
the change
should have no effect on non-IDE users/configurations I decided to commit it 
upstream
with the hopes it will benefit somebody other than me.

Modified:
libcxx/trunk/test/CMakeLists.txt

Modified: libcxx/trunk/test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/CMakeLists.txt?rev=307118&r1=307117&r2=307118&view=diff
==
--- libcxx/trunk/test/CMakeLists.txt (original)
+++ libcxx/trunk/test/CMakeLists.txt Tue Jul  4 20:50:03 2017
@@ -85,3 +85,36 @@ if (LIBCXX_GENERATE_COVERAGE)
   set(extract_dirs "${LIBCXX_SOURCE_DIR}/include;${LIBCXX_SOURCE_DIR}/src")
   setup_lcov_test_target_coverage("cxx" "${output_dir}" "${capture_dirs}" 
"${extract_dirs}")
 endif()
+
+
+if (LIBCXX_CONFIGURE_IDE)
+  # Create dummy targets for each of the tests in the test suite, this allows
+  # IDE's such as CLion to correctly highlight the tests because it knows
+  # roughly what include paths/compile flags/macro definitions are needed.
+  include_directories(support)
+  file(GLOB_RECURSE LIBCXX_TESTS ${CMAKE_CURRENT_SOURCE_DIR}/*.pass.cpp)
+  file(GLOB LIBCXX_TEST_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/support/*)
+  file(GLOB_RECURSE LIBCXX_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../include/*)
+  add_executable(libcxx_test_objects EXCLUDE_FROM_ALL
+  ${LIBCXX_TESTS} ${LIBCXX_TEST_HEADERS} ${LIBCXX_HEADERS})
+  add_dependencies(libcxx_test_objects cxx)
+
+  set(STATIC_ROOT 
${LIBCXX_SOURCE_DIR}/test/std/experimental/filesystem/Inputs/static_test_env)
+  add_definitions(-DLIBCXX_FILESYSTEM_STATIC_TEST_ROOT="${STATIC_ROOT}")
+
+  set(DYNAMIC_ROOT ${LIBCXX_BINARY_DIR}/test/filesystem/Output/dynamic_env)
+  add_definitions(-DLIBCXX_FILESYSTEM_DYNAMIC_TEST_ROOT="${DYNAMIC_ROOT}")
+
+  set(DYNAMIC_HELPER "python 
${LIBCXX_SOURCE_DIR}/test/support/filesystem_dynamic_test_helper.py ")
+  add_definitions(-DLIBCXX_FILESYSTEM_DYNAMIC_TEST_HELPER="${DYNAMIC_HELPER}")
+
+  split_list(LIBCXX_COMPILE_FLAGS)
+  split_list(LIBCXX_LINK_FLAGS)
+
+  set_target_properties(libcxx_test_objects
+  PROPERTIES
+COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
+LINK_FLAGS "${LIBCXX_LINK_FLAGS}"
+EXCLUDE_FROM_ALL ON
+  )
+endif()


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


[libcxx] r307119 - Fix equivalent test on OS X and FreeBSD

2017-07-05 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Tue Jul  4 20:54:38 2017
New Revision: 307119

URL: http://llvm.org/viewvc/llvm-project?rev=307119&view=rev
Log:
Fix equivalent test on OS X and FreeBSD

Modified:

libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.equivalent/equivalent.pass.cpp

Modified: 
libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.equivalent/equivalent.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.equivalent/equivalent.pass.cpp?rev=307119&r1=307118&r2=307119&view=diff
==
--- 
libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.equivalent/equivalent.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.equivalent/equivalent.pass.cpp
 Tue Jul  4 20:54:38 2017
@@ -99,14 +99,14 @@ TEST_CASE(equivalent_hardlink_succeeds)
 TEST_CASE(equivalent_is_other_succeeds) {
   scoped_test_env env;
   path const file = env.create_file("file", 42);
-  const path sock1 = env.create_socket("sock1");
-  const path sock2 = env.create_socket("sock2");
+  const path fifo1 = env.create_fifo("fifo1");
+  const path fifo2 = env.create_fifo("fifo2");
   // Required to test behavior for inputs where is_other(p) is true.
-  TEST_REQUIRE(is_other(sock1));
-  TEST_CHECK(!equivalent(file, sock1));
-  TEST_CHECK(!equivalent(sock2, file));
-  TEST_CHECK(!equivalent(sock1, sock2));
-  TEST_CHECK(equivalent(sock1, sock1));
+  TEST_REQUIRE(is_other(fifo1));
+  TEST_CHECK(!equivalent(file, fifo1));
+  TEST_CHECK(!equivalent(fifo2, file));
+  TEST_CHECK(!equivalent(fifo1, fifo2));
+  TEST_CHECK(equivalent(fifo1, fifo1));
 }
 
 TEST_SUITE_END()


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


[PATCH] D34995: [AMDGPU] Fix size and alignment of size_t and pointer types

2017-07-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
Herald added subscribers: t-tye, tpr, dstuttard, nhaehnle, wdng, kzhuravl.

This patch is split from https://reviews.llvm.org/D33842


https://reviews.llvm.org/D34995

Files:
  lib/Basic/Targets.cpp
  test/CodeGen/default-address-space.c
  test/CodeGenCXX/amdgcn-automatic-variable.cpp
  test/CodeGenOpenCL/amdgcn-automatic-variable.cl
  test/CodeGenOpenCL/amdgpu-nullptr.cl
  test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl
  test/Index/pipe-size.cl
  test/SemaCXX/amdgpu-sizeof-alignof.cpp

Index: test/SemaCXX/amdgpu-sizeof-alignof.cpp
===
--- /dev/null
+++ test/SemaCXX/amdgpu-sizeof-alignof.cpp
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -triple amdgcn---amdgiz -std=c++11 -fsyntax-only -verify %s
+// expected-no-diagnostics
+typedef __SIZE_TYPE__ size_t;
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+typedef __INTPTR_TYPE__ intptr_t;
+typedef __UINTPTR_TYPE__ uintptr_t;
+typedef __attribute__((address_space(1))) void *global_ptr_t;
+typedef __attribute__((address_space(2))) void *constant_ptr_t;
+typedef __attribute__((address_space(3))) void *local_ptr_t;
+typedef __attribute__((address_space(5))) void *private_ptr_t;
+
+void test() {
+  static_assert(sizeof(size_t) == 8, "bad size");
+  static_assert(alignof(size_t) == 8, "bad alignment");
+  static_assert(sizeof(intptr_t) == 8, "bad size");
+  static_assert(alignof(intptr_t) == 8, "bad alignment");
+  static_assert(sizeof(uintptr_t) == 8, "bad size");
+  static_assert(alignof(uintptr_t) == 8, "bad alignment");
+  static_assert(sizeof(ptrdiff_t) == 8, "bad size");
+  static_assert(alignof(ptrdiff_t) == 8, "bad alignment");
+
+  static_assert(sizeof(char) == 1, "bad size");
+  static_assert(alignof(char) == 1, "bad alignment");
+  static_assert(sizeof(short) == 2, "bad size");
+  static_assert(alignof(short) == 2, "bad alignment");
+  static_assert(sizeof(int) == 4, "bad size");
+  static_assert(alignof(int) == 4, "bad alignment");
+  static_assert(sizeof(long) == 8, "bad size");
+  static_assert(alignof(long) == 8, "bad alignment");
+  static_assert(sizeof(long long) == 8, "bad size");
+  static_assert(alignof(long long) == 8, "bad alignment");
+  static_assert(sizeof(float) == 4, "bad size");
+  static_assert(alignof(float) == 4, "bad alignment");
+  static_assert(sizeof(double) == 8, "bad size");
+  static_assert(alignof(double) == 8, "bad alignment");
+
+  static_assert(sizeof(void*) == 8, "bad size");
+  static_assert(alignof(void*) == 8, "bad alignment");
+  static_assert(sizeof(global_ptr_t) == 8, "bad size");
+  static_assert(alignof(global_ptr_t) == 8, "bad alignment");
+  static_assert(sizeof(constant_ptr_t) == 8, "bad size");
+  static_assert(alignof(constant_ptr_t) == 8, "bad alignment");
+  static_assert(sizeof(local_ptr_t) == 4, "bad size");
+  static_assert(alignof(local_ptr_t) == 4, "bad alignment");
+  static_assert(sizeof(private_ptr_t) == 4, "bad size");
+  static_assert(alignof(private_ptr_t) == 4, "bad alignment");
+}
Index: test/Index/pipe-size.cl
===
--- test/Index/pipe-size.cl
+++ test/Index/pipe-size.cl
@@ -11,6 +11,6 @@
 // SPIR: store i32 4, i32* %s, align 4
 // SPIR64: store %opencl.pipe_t addrspace(1)* %test, %opencl.pipe_t addrspace(1)** %test.addr, align 8
 // SPIR64: store i32 8, i32* %s, align 4
-// AMD: store %opencl.pipe_t addrspace(1)* %test, %opencl.pipe_t addrspace(1)* addrspace(5)* %test.addr, align 4
+// AMD: store %opencl.pipe_t addrspace(1)* %test, %opencl.pipe_t addrspace(1)* addrspace(5)* %test.addr, align 8
 // AMD: store i32 8, i32 addrspace(5)* %s, align 4
 }
Index: test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl
@@ -0,0 +1,70 @@
+// RUN: %clang_cc1 -triple r600 -cl-std=CL1.2 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn-mesa-mesa3d -cl-std=CL1.2 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn---opencl -cl-std=CL1.2 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn---opencl -cl-std=CL2.0 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn---amdgizcl -cl-std=CL1.2 %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple amdgcn---amdgizcl -cl-std=CL2.0 %s -emit-llvm -o - | FileCheck %s
+
+#ifdef __AMDGCN__
+#define PTSIZE 8
+#else
+#define PTSIZE 4
+#endif
+
+#ifdef cl_khr_fp64
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+#endif
+#ifdef cl_khr_fp16
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+#endif
+
+typedef __SIZE_TYPE__ size_t;
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+typedef __INTPTR_TYPE__ intptr_t;
+typedef __UINTPTR_TYPE__ uintptr_t;
+typedef global void *global_ptr_t;
+typedef constant void *constant_ptr_t;
+typedef local void *local_ptr_t;
+typedef private void *private_ptr_t;
+
+void check(bool);
+
+void test() {
+  // CHECK-NOT: cal

[PATCH] D34995: [AMDGPU] Fix size and alignment of size_t and pointer types

2017-07-05 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Looks good.


https://reviews.llvm.org/D34995



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


r307121 - [AMDGPU] Fix size and alignment of size_t and pointer types

2017-07-05 Thread Yaxun Liu via cfe-commits
Author: yaxunl
Date: Tue Jul  4 21:58:24 2017
New Revision: 307121

URL: http://llvm.org/viewvc/llvm-project?rev=307121&view=rev
Log:
[AMDGPU] Fix size and alignment of size_t and pointer types

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

Added:
cfe/trunk/test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl
cfe/trunk/test/SemaCXX/amdgpu-sizeof-alignof.cpp
Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/test/CodeGen/default-address-space.c
cfe/trunk/test/CodeGenCXX/amdgcn-automatic-variable.cpp
cfe/trunk/test/CodeGenOpenCL/amdgcn-automatic-variable.cl
cfe/trunk/test/CodeGenOpenCL/amdgpu-nullptr.cl
cfe/trunk/test/Index/pipe-size.cl

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=307121&r1=307120&r2=307121&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Tue Jul  4 21:58:24 2017
@@ -2189,6 +2189,15 @@ public:
Triple.getEnvironmentName() == "amdgizcl" ||
!isAMDGCN(Triple));
 UseAddrSpaceMapMangling = true;
+
+// Set pointer width and alignment for target address space 0.
+PointerWidth = PointerAlign = DataLayout->getPointerSizeInBits();
+if (getMaxPointerWidth() == 64) {
+  LongWidth = LongAlign = 64;
+  SizeType = UnsignedLong;
+  PtrDiffType = SignedLong;
+  IntPtrType = SignedLong;
+}
   }
 
   void setAddressSpaceMap(bool DefaultIsPrivate) {
@@ -2216,6 +2225,10 @@ public:
 return 64;
   }
 
+  uint64_t getPointerAlignV(unsigned AddrSpace) const override {
+return getPointerWidthV(AddrSpace);
+  }
+
   uint64_t getMaxPointerWidth() const override {
 return getTriple().getArch() == llvm::Triple::amdgcn ? 64 : 32;
   }
@@ -2392,12 +2405,7 @@ public:
   }
 
   /// \returns Target specific vtbl ptr address space.
-  unsigned getVtblPtrAddressSpace() const override {
-// \todo: We currently have address spaces defined in AMDGPU Backend. It
-// would be nice if we could use it here instead of using bare numbers 
(same
-// applies to getDWARFAddressSpace).
-return 2; // constant.
-  }
+  unsigned getVtblPtrAddressSpace() const override { return AS.Constant; }
 
   /// \returns If a target requires an address within a target specific address
   /// space \p AddressSpace to be converted in order to be used, then return 
the

Modified: cfe/trunk/test/CodeGen/default-address-space.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/default-address-space.c?rev=307121&r1=307120&r2=307121&view=diff
==
--- cfe/trunk/test/CodeGen/default-address-space.c (original)
+++ cfe/trunk/test/CodeGen/default-address-space.c Tue Jul  4 21:58:24 2017
@@ -50,7 +50,7 @@ void test3() {
 // PIZ: %[[arrayidx:.*]] = getelementptr inbounds i32, i32 addrspace(4)* 
%[[r0]]
 // PIZ: store i32 0, i32 addrspace(4)* %[[arrayidx]]
 // CHECK-LABEL: define void @test4(i32* %a)
-// CHECK: %[[alloca:.*]] = alloca i32*, align 4, addrspace(5)
+// CHECK: %[[alloca:.*]] = alloca i32*, align 8, addrspace(5)
 // CHECK: %[[a_addr:.*]] = addrspacecast{{.*}} %[[alloca]] to i32**
 // CHECK: store i32* %a, i32** %[[a_addr]]
 // CHECK: %[[r0:.*]] = load i32*, i32** %[[a_addr]]

Modified: cfe/trunk/test/CodeGenCXX/amdgcn-automatic-variable.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/amdgcn-automatic-variable.cpp?rev=307121&r1=307120&r2=307121&view=diff
==
--- cfe/trunk/test/CodeGenCXX/amdgcn-automatic-variable.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/amdgcn-automatic-variable.cpp Tue Jul  4 21:58:24 
2017
@@ -15,8 +15,8 @@ void func2(void) {
   // CHECK: %lv1 = alloca i32, align 4, addrspace(5)
   // CHECK: %lv2 = alloca i32, align 4, addrspace(5)
   // CHECK: %la = alloca [100 x i32], align 4, addrspace(5)
-  // CHECK: %lp1 = alloca i32*, align 4, addrspace(5)
-  // CHECK: %lp2 = alloca i32*, align 4, addrspace(5)
+  // CHECK: %lp1 = alloca i32*, align 8, addrspace(5)
+  // CHECK: %lp2 = alloca i32*, align 8, addrspace(5)
   // CHECK: %lvc = alloca i32, align 4, addrspace(5)
 
   // CHECK: %[[r0:.*]] = addrspacecast i32 addrspace(5)* %lv1 to i32*
@@ -34,12 +34,12 @@ void func2(void) {
   la[0] = 3;
 
   // CHECK: %[[r3:.*]] = addrspacecast i32* addrspace(5)* %lp1 to i32**
-  // CHECK: store i32* %[[r0]], i32** %[[r3]], align 4
+  // CHECK: store i32* %[[r0]], i32** %[[r3]], align 8
   int *lp1 = &lv1;
 
   // CHECK: %[[r4:.*]] = addrspacecast i32* addrspace(5)* %lp2 to i32**
   // CHECK: %[[arraydecay:.*]] = getelementptr inbounds [100 x i32], [100 x 
i32]* %[[r2]], i32 0, i32 0
-  // CHECK: store i32* %[[arraydecay]], i32** %[[r4]], align 4
+  // CHECK: store i32* %[[arraydecay]], i32** %[[r4]], align 8
   int *lp2 = la;
 
   /

[PATCH] D34995: [AMDGPU] Fix size and alignment of size_t and pointer types

2017-07-05 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307121: [AMDGPU] Fix size and alignment of size_t and 
pointer types (authored by yaxunl).

Changed prior to commit:
  https://reviews.llvm.org/D34995?vs=105213&id=105215#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34995

Files:
  cfe/trunk/lib/Basic/Targets.cpp
  cfe/trunk/test/CodeGen/default-address-space.c
  cfe/trunk/test/CodeGenCXX/amdgcn-automatic-variable.cpp
  cfe/trunk/test/CodeGenOpenCL/amdgcn-automatic-variable.cl
  cfe/trunk/test/CodeGenOpenCL/amdgpu-nullptr.cl
  cfe/trunk/test/CodeGenOpenCL/amdgpu-sizeof-alignof.cl
  cfe/trunk/test/Index/pipe-size.cl
  cfe/trunk/test/SemaCXX/amdgpu-sizeof-alignof.cpp

Index: cfe/trunk/test/Index/pipe-size.cl
===
--- cfe/trunk/test/Index/pipe-size.cl
+++ cfe/trunk/test/Index/pipe-size.cl
@@ -11,6 +11,6 @@
 // SPIR: store i32 4, i32* %s, align 4
 // SPIR64: store %opencl.pipe_t addrspace(1)* %test, %opencl.pipe_t addrspace(1)** %test.addr, align 8
 // SPIR64: store i32 8, i32* %s, align 4
-// AMD: store %opencl.pipe_t addrspace(1)* %test, %opencl.pipe_t addrspace(1)* addrspace(5)* %test.addr, align 4
+// AMD: store %opencl.pipe_t addrspace(1)* %test, %opencl.pipe_t addrspace(1)* addrspace(5)* %test.addr, align 8
 // AMD: store i32 8, i32 addrspace(5)* %s, align 4
 }
Index: cfe/trunk/test/CodeGenCXX/amdgcn-automatic-variable.cpp
===
--- cfe/trunk/test/CodeGenCXX/amdgcn-automatic-variable.cpp
+++ cfe/trunk/test/CodeGenCXX/amdgcn-automatic-variable.cpp
@@ -15,8 +15,8 @@
   // CHECK: %lv1 = alloca i32, align 4, addrspace(5)
   // CHECK: %lv2 = alloca i32, align 4, addrspace(5)
   // CHECK: %la = alloca [100 x i32], align 4, addrspace(5)
-  // CHECK: %lp1 = alloca i32*, align 4, addrspace(5)
-  // CHECK: %lp2 = alloca i32*, align 4, addrspace(5)
+  // CHECK: %lp1 = alloca i32*, align 8, addrspace(5)
+  // CHECK: %lp2 = alloca i32*, align 8, addrspace(5)
   // CHECK: %lvc = alloca i32, align 4, addrspace(5)
 
   // CHECK: %[[r0:.*]] = addrspacecast i32 addrspace(5)* %lv1 to i32*
@@ -34,12 +34,12 @@
   la[0] = 3;
 
   // CHECK: %[[r3:.*]] = addrspacecast i32* addrspace(5)* %lp1 to i32**
-  // CHECK: store i32* %[[r0]], i32** %[[r3]], align 4
+  // CHECK: store i32* %[[r0]], i32** %[[r3]], align 8
   int *lp1 = &lv1;
 
   // CHECK: %[[r4:.*]] = addrspacecast i32* addrspace(5)* %lp2 to i32**
   // CHECK: %[[arraydecay:.*]] = getelementptr inbounds [100 x i32], [100 x i32]* %[[r2]], i32 0, i32 0
-  // CHECK: store i32* %[[arraydecay]], i32** %[[r4]], align 4
+  // CHECK: store i32* %[[arraydecay]], i32** %[[r4]], align 8
   int *lp2 = la;
 
   // CHECK: call void @_Z5func1Pi(i32* %[[r0]])
@@ -80,3 +80,5 @@
   // CHECK: call void @_Z5func1Pi(i32* %[[r0]])
   func1(&x);
 }
+
+// CHECK-NOT: !opencl.ocl.version
Index: cfe/trunk/test/SemaCXX/amdgpu-sizeof-alignof.cpp
===
--- cfe/trunk/test/SemaCXX/amdgpu-sizeof-alignof.cpp
+++ cfe/trunk/test/SemaCXX/amdgpu-sizeof-alignof.cpp
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -triple amdgcn---amdgiz -std=c++11 -fsyntax-only -verify %s
+// expected-no-diagnostics
+typedef __SIZE_TYPE__ size_t;
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+typedef __INTPTR_TYPE__ intptr_t;
+typedef __UINTPTR_TYPE__ uintptr_t;
+typedef __attribute__((address_space(1))) void *global_ptr_t;
+typedef __attribute__((address_space(2))) void *constant_ptr_t;
+typedef __attribute__((address_space(3))) void *local_ptr_t;
+typedef __attribute__((address_space(5))) void *private_ptr_t;
+
+void test() {
+  static_assert(sizeof(size_t) == 8, "bad size");
+  static_assert(alignof(size_t) == 8, "bad alignment");
+  static_assert(sizeof(intptr_t) == 8, "bad size");
+  static_assert(alignof(intptr_t) == 8, "bad alignment");
+  static_assert(sizeof(uintptr_t) == 8, "bad size");
+  static_assert(alignof(uintptr_t) == 8, "bad alignment");
+  static_assert(sizeof(ptrdiff_t) == 8, "bad size");
+  static_assert(alignof(ptrdiff_t) == 8, "bad alignment");
+
+  static_assert(sizeof(char) == 1, "bad size");
+  static_assert(alignof(char) == 1, "bad alignment");
+  static_assert(sizeof(short) == 2, "bad size");
+  static_assert(alignof(short) == 2, "bad alignment");
+  static_assert(sizeof(int) == 4, "bad size");
+  static_assert(alignof(int) == 4, "bad alignment");
+  static_assert(sizeof(long) == 8, "bad size");
+  static_assert(alignof(long) == 8, "bad alignment");
+  static_assert(sizeof(long long) == 8, "bad size");
+  static_assert(alignof(long long) == 8, "bad alignment");
+  static_assert(sizeof(float) == 4, "bad size");
+  static_assert(alignof(float) == 4, "bad alignment");
+  static_assert(sizeof(double) == 8, "bad size");
+  static_assert(alignof(double) == 8, "bad alignment");
+
+  static_assert(sizeof(void*) == 8, "bad size");
+  static_assert(alignof(void*) == 8, "ba

r307123 - fix trivial typos in comments; NFC

2017-07-05 Thread Hiroshi Inoue via cfe-commits
Author: inouehrs
Date: Tue Jul  4 22:37:45 2017
New Revision: 307123

URL: http://llvm.org/viewvc/llvm-project?rev=307123&view=rev
Log:
fix trivial typos in comments; NFC

Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Sema/SemaLambda.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=307123&r1=307122&r2=307123&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Jul  4 22:37:45 2017
@@ -9508,7 +9508,7 @@ bool ComplexExprEvaluator::VisitBinaryOp
   case BO_Mul:
 if (Result.isComplexFloat()) {
   // This is an implementation of complex multiplication according to the
-  // constraints laid out in C11 Annex G. The implemantion uses the
+  // constraints laid out in C11 Annex G. The implemention uses the
   // following naming scheme:
   //   (a + ib) * (c + id)
   ComplexValue LHS = Result;
@@ -9589,7 +9589,7 @@ bool ComplexExprEvaluator::VisitBinaryOp
   case BO_Div:
 if (Result.isComplexFloat()) {
   // This is an implementation of complex division according to the
-  // constraints laid out in C11 Annex G. The implemantion uses the
+  // constraints laid out in C11 Annex G. The implemention uses the
   // following naming scheme:
   //   (a + ib) / (c + id)
   ComplexValue LHS = Result;

Modified: cfe/trunk/lib/Sema/SemaLambda.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLambda.cpp?rev=307123&r1=307122&r2=307123&view=diff
==
--- cfe/trunk/lib/Sema/SemaLambda.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLambda.cpp Tue Jul  4 22:37:45 2017
@@ -1595,7 +1595,7 @@ ExprResult Sema::BuildLambdaExpr(SourceL
   ContainsUnexpandedParameterPack);
   // If the lambda expression's call operator is not explicitly marked 
constexpr
   // and we are not in a dependent context, analyze the call operator to infer
-  // its constexpr-ness, supressing diagnostics while doing so.
+  // its constexpr-ness, suppressing diagnostics while doing so.
   if (getLangOpts().CPlusPlus1z && !CallOperator->isInvalidDecl() &&
   !CallOperator->isConstexpr() &&
   !isa(CallOperator->getBody()) &&


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


[PATCH] D34980: [OpenCL] Test on image access modifiers and image type can only be a type of a function argument.

2017-07-05 Thread Egor Churaev via Phabricator via cfe-commits
echuraev updated this revision to Diff 105218.
echuraev marked 6 inline comments as done.

https://reviews.llvm.org/D34980

Files:
  test/SemaOpenCL/images.cl


Index: test/SemaOpenCL/images.cl
===
--- test/SemaOpenCL/images.cl
+++ test/SemaOpenCL/images.cl
@@ -1,9 +1,32 @@
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
 
-void img2d_ro(__read_only image2d_t img) {} // expected-note{{passing argument 
to parameter 'img' here}} expected-note{{passing argument to parameter 'img' 
here}}
+void img2d_ro(read_only image2d_t); // expected-note 3{{passing argument to 
parameter here}}
+void img2d_wo(write_only image2d_t); // expected-note 2{{passing argument to 
parameter here}}
+void img2d_rw(read_write image2d_t); // expected-note 2{{passing argument to 
parameter here}}
+void img2d_default(image2d_t); // expected-note 2{{passing argument to 
parameter here}}
 
-void imgage_access_test(image2d_t img2dro, write_only image2d_t img2dwo, 
image3d_t img3dro) {
-  img2d_ro(img2dro);
-  img2d_ro(img2dwo); // expected-error{{passing '__write_only image2d_t' to 
parameter of incompatible type '__read_only image2d_t'}}
+void imgage_access_test(image2d_t img2dro, image3d_t img3dro) {
+  img2d_ro(img2dro); // read_only = read_only
   img2d_ro(img3dro); // expected-error{{passing '__read_only image3d_t' to 
parameter of incompatible type '__read_only image2d_t'}}
 }
+
+kernel void read_only_access_test(read_only image2d_t img) {
+  img2d_ro(img); // read_only = read_only
+  img2d_wo(img); // expected-error {{passing '__read_only image2d_t' to 
parameter of incompatible type '__write_only image2d_t'}}
+  img2d_rw(img); // expected-error {{passing '__read_only image2d_t' to 
parameter of incompatible type '__read_write image2d_t'}}
+  img2d_default(img); // read_only = read_only
+}
+
+kernel void write_only_access_test(write_only image2d_t img) {
+  img2d_ro(img); // expected-error {{passing '__write_only image2d_t' to 
parameter of incompatible type '__read_only image2d_t'}}
+  img2d_wo(img); // write_only = write_only
+  img2d_rw(img); // expected-error {{passing '__write_only image2d_t' to 
parameter of incompatible type '__read_write image2d_t'}}
+  img2d_default(img); // expected-error {{passing '__write_only image2d_t' to 
parameter of incompatible type '__read_only image2d_t'}}
+}
+
+kernel void read_write_access_test(read_write image2d_t img) {
+  img2d_ro(img);  // expected-error {{passing '__read_write image2d_t' to 
parameter of incompatible type '__read_only image2d_t'}}
+  img2d_wo(img); // expected-error {{passing '__read_write image2d_t' to 
parameter of incompatible type '__write_only image2d_t'}}
+  img2d_rw(img); //read_write = read_write
+  img2d_default(img); // expected-error {{passing '__read_write image2d_t' to 
parameter of incompatible type '__read_only image2d_t'}}
+}


Index: test/SemaOpenCL/images.cl
===
--- test/SemaOpenCL/images.cl
+++ test/SemaOpenCL/images.cl
@@ -1,9 +1,32 @@
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -pedantic -fsyntax-only
 
-void img2d_ro(__read_only image2d_t img) {} // expected-note{{passing argument to parameter 'img' here}} expected-note{{passing argument to parameter 'img' here}}
+void img2d_ro(read_only image2d_t); // expected-note 3{{passing argument to parameter here}}
+void img2d_wo(write_only image2d_t); // expected-note 2{{passing argument to parameter here}}
+void img2d_rw(read_write image2d_t); // expected-note 2{{passing argument to parameter here}}
+void img2d_default(image2d_t); // expected-note 2{{passing argument to parameter here}}
 
-void imgage_access_test(image2d_t img2dro, write_only image2d_t img2dwo, image3d_t img3dro) {
-  img2d_ro(img2dro);
-  img2d_ro(img2dwo); // expected-error{{passing '__write_only image2d_t' to parameter of incompatible type '__read_only image2d_t'}}
+void imgage_access_test(image2d_t img2dro, image3d_t img3dro) {
+  img2d_ro(img2dro); // read_only = read_only
   img2d_ro(img3dro); // expected-error{{passing '__read_only image3d_t' to parameter of incompatible type '__read_only image2d_t'}}
 }
+
+kernel void read_only_access_test(read_only image2d_t img) {
+  img2d_ro(img); // read_only = read_only
+  img2d_wo(img); // expected-error {{passing '__read_only image2d_t' to parameter of incompatible type '__write_only image2d_t'}}
+  img2d_rw(img); // expected-error {{passing '__read_only image2d_t' to parameter of incompatible type '__read_write image2d_t'}}
+  img2d_default(img); // read_only = read_only
+}
+
+kernel void write_only_access_test(write_only image2d_t img) {
+  img2d_ro(img); // expected-error {{passing '__write_only image2d_t' to parameter of incompatible type '__read_only image2d_t'}}
+  img2d_wo(img); // write_only = write_only
+  img2d_rw(img); // expect

r307129 - [modules ts] Improve merging of module-private declarations.

2017-07-05 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Wed Jul  5 00:47:11 2017
New Revision: 307129

URL: http://llvm.org/viewvc/llvm-project?rev=307129&view=rev
Log:
[modules ts] Improve merging of module-private declarations.

These cases occur frequently for declarations in the global module (above the
module-declaration) in a Modules TS module interface. When we merge a
definition from another module into such a module-private definition, ensure
that we transitively make everything lexically within that definition visible
to that translation unit.

Added:
cfe/trunk/test/CXX/modules-ts/dcl.dcl/dcl.module/p5.cpp
Modified:
cfe/trunk/include/clang/AST/DeclBase.h
cfe/trunk/lib/AST/DeclBase.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=307129&r1=307128&r2=307129&view=diff
==
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Wed Jul  5 00:47:11 2017
@@ -749,7 +749,7 @@ public:
   /// Set that this declaration is globally visible, even if it came from a
   /// module that is not visible.
   void setVisibleDespiteOwningModule() {
-if (getModuleOwnershipKind() == ModuleOwnershipKind::VisibleWhenImported)
+if (isHidden())
   setModuleOwnershipKind(ModuleOwnershipKind::Visible);
   }
 

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=307129&r1=307128&r2=307129&view=diff
==
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Wed Jul  5 00:47:11 2017
@@ -283,8 +283,10 @@ void Decl::setLexicalDeclContext(DeclCon
   setLocalOwningModule(cast(DC)->getOwningModule());
   }
 
-  assert((!hasOwningModule() || getOwningModule() || isModulePrivate()) &&
- "hidden declaration has no owning module");
+  assert(
+  (getModuleOwnershipKind() != ModuleOwnershipKind::VisibleWhenImported ||
+   getOwningModule()) &&
+  "hidden declaration has no owning module");
 }
 
 void Decl::setDeclContextsImpl(DeclContext *SemaDC, DeclContext *LexicalDC,

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=307129&r1=307128&r2=307129&view=diff
==
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Wed Jul  5 00:47:11 2017
@@ -1396,6 +1396,13 @@ bool Sema::hasVisibleMergedDefinition(Na
 }
 
 bool Sema::hasMergedDefinitionInCurrentModule(NamedDecl *Def) {
+  // FIXME: When not in local visibility mode, we can't tell the difference
+  // between a declaration being visible because we merged a local copy of
+  // the same declaration into it, and it being visible because its owning
+  // module is visible.
+  if (Def->getModuleOwnershipKind() == Decl::ModuleOwnershipKind::Visible &&
+  getLangOpts().ModulesLocalVisibility)
+return true;
   for (Module *Merged : Context.getModulesWithMergedDefinition(Def))
 if (Merged->getTopLevelModuleName() == getLangOpts().CurrentModule)
   return true;
@@ -1509,25 +1516,33 @@ bool LookupResult::isVisibleSlow(Sema &S
 // FIXME: Don't assume that "same translation unit" means the same thing
 // as "not from an AST file".
 assert(D->isModulePrivate() && "hidden decl has no module");
-return !D->isFromASTFile();
+if (!D->isFromASTFile() || SemaRef.hasMergedDefinitionInCurrentModule(D))
+  return true;
+  } else {
+// If the owning module is visible, and the decl is not module private,
+// then the decl is visible too. (Module private is ignored within the same
+// top-level module.)
+if (D->isModulePrivate()
+  ? DeclModule->getTopLevelModuleName() ==
+SemaRef.getLangOpts().CurrentModule ||
+SemaRef.hasMergedDefinitionInCurrentModule(D)
+  : SemaRef.isModuleVisible(DeclModule) ||
+SemaRef.hasVisibleMergedDefinition(D))
+  return true;
   }
 
-  // If the owning module is visible, and the decl is not module private,
-  // then the decl is visible too. (Module private is ignored within the same
-  // top-level module.)
-  if (D->isModulePrivate()
-? DeclModule->getTopLevelModuleName() ==
-  SemaRef.getLangOpts().CurrentModule ||
-  SemaRef.hasMergedDefinitionInCurrentModule(D)
-: SemaRef.isModuleVisible(DeclModule) ||
-  SemaRef.hasVisibleMergedDefinition(D))
-return true;
+  // Determine whether a decl context is a file context for the purpose of
+  // visibility. This looks through some (export and linkage spec) transparent
+  // context

[PATCH] D34206: [clang-tidy] Add "MakeSmartPtrFunction" option to modernize-make-shared/unique checks.

2017-07-05 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307130: [clang-tidy] Add "MakeSmartPtrFunction" option to 
modernize-make-shared/unique… (authored by hokein).

Repository:
  rL LLVM

https://reviews.llvm.org/D34206

Files:
  clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.h
  clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-make-shared.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-make-unique.rst
  
clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/shared_ptr.h
  
clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h
  clang-tools-extra/trunk/test/clang-tidy/modernize-make-shared-header.cpp
  clang-tools-extra/trunk/test/clang-tidy/modernize-make-shared.cpp
  clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique-header.cpp
  clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp

Index: clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique-header.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique-header.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique-header.cpp
@@ -0,0 +1,17 @@
+// RUN: %check_clang_tidy %s modernize-make-unique %t -- \
+// RUN:   -config="{CheckOptions: \
+// RUN: [{key: modernize-make-unique.MakeSmartPtrFunction, \
+// RUN:   value: 'my::MakeUnique'}, \
+// RUN:  {key: modernize-make-unique.MakeSmartPtrFunctionHeader, \
+// RUN:   value: 'make_unique_util.h'} \
+// RUN: ]}" \
+// RUN:   -- -std=c++11 -I%S/Inputs/modernize-smart-ptr
+
+#include "unique_ptr.h"
+// CHECK-FIXES: #include "make_unique_util.h"
+
+void f() {
+  std::unique_ptr P1 = std::unique_ptr(new int());
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use my::MakeUnique instead
+  // CHECK-FIXES: std::unique_ptr P1 = my::MakeUnique();
+}
Index: clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h
===
--- clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h
+++ clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h
@@ -0,0 +1,28 @@
+namespace std {
+
+template 
+class default_delete {};
+
+template >
+class unique_ptr {
+public:
+  unique_ptr();
+  unique_ptr(type *ptr);
+  unique_ptr(const unique_ptr &t) = delete;
+  unique_ptr(unique_ptr &&t);
+  ~unique_ptr();
+  type &operator*() { return *ptr; }
+  type *operator->() { return ptr; }
+  type *release();
+  void reset();
+  void reset(type *pt);
+  void reset(type pt);
+  unique_ptr &operator=(unique_ptr &&);
+  template 
+  unique_ptr &operator=(unique_ptr &&);
+
+private:
+  type *ptr;
+};
+
+}  // namespace std
Index: clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/shared_ptr.h
===
--- clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/shared_ptr.h
+++ clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/shared_ptr.h
@@ -0,0 +1,24 @@
+namespace std {
+
+template 
+class shared_ptr {
+public:
+  shared_ptr();
+  shared_ptr(type *ptr);
+  shared_ptr(const shared_ptr &t) {}
+  shared_ptr(shared_ptr &&t) {}
+  ~shared_ptr();
+  type &operator*() { return *ptr; }
+  type *operator->() { return ptr; }
+  type *release();
+  void reset();
+  void reset(type *pt);
+  shared_ptr &operator=(shared_ptr &&);
+  template 
+  shared_ptr &operator=(shared_ptr &&);
+
+private:
+  type *ptr;
+};
+
+}  // namespace std
Index: clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
@@ -1,32 +1,8 @@
-// RUN: %check_clang_tidy %s modernize-make-unique %t
+// RUN: %check_clang_tidy %s modernize-make-unique %t -- -- -std=c++11 \
+// RUN:   -I%S/Inputs/modernize-smart-ptr
 
-namespace std {
-
-template 
-class default_delete {};
-
-template >
-class unique_ptr {
-public:
-  unique_ptr();
-  unique_ptr(type *ptr);
-  unique_ptr(const unique_ptr &t) = delete;
-  unique_ptr(unique_ptr &&t);
-  ~unique_ptr();
-  type &operator*() { return *ptr; }
-  type *operator->() { return ptr; }
-  type *release();
-  void reset();
-  void reset(type *pt);
-  void reset(type pt);
-  unique_ptr &operator=(unique_ptr &&);
-  template 
-  unique_ptr &operator=(unique_ptr &&);
-
-private:
-  type *ptr;
-};
-}
+#include "unique_ptr.h"
+// CHECK-FIXES: #include 
 
 struct Base {
   Base();
Index: clang-tools-extra/trunk/test/clang-tidy/modernize-make-shared-header.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/modernize-make-shared-he

[clang-tools-extra] r307130 - [clang-tidy] Add "MakeSmartPtrFunction" option to modernize-make-shared/unique checks.

2017-07-05 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Jul  5 00:49:00 2017
New Revision: 307130

URL: http://llvm.org/viewvc/llvm-project?rev=307130&view=rev
Log:
[clang-tidy] Add "MakeSmartPtrFunction" option to modernize-make-shared/unique 
checks.

Reviewers: alexfh, aaron.ballman

Reviewed By: alexfh

Subscribers: JDevlieghere, Eugene.Zelenko, xazax.hun, cfe-commits

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

Added:
clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/

clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/shared_ptr.h

clang-tools-extra/trunk/test/clang-tidy/Inputs/modernize-smart-ptr/unique_ptr.h
clang-tools-extra/trunk/test/clang-tidy/modernize-make-shared-header.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique-header.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-make-shared.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-make-unique.rst
clang-tools-extra/trunk/test/clang-tidy/modernize-make-shared.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp?rev=307130&r1=307129&r2=307130&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp Wed Jul  
5 00:49:00 2017
@@ -8,7 +8,9 @@
 
//===--===//
 
 #include "MakeSharedCheck.h"
+#include "clang/Frontend/CompilerInstance.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Lex/Preprocessor.h"
 
 using namespace clang::ast_matchers;
 
@@ -17,6 +19,9 @@ namespace tidy {
 namespace modernize {
 
 namespace {
+
+constexpr char StdMemoryHeader[] = "memory";
+
 std::string GetNewExprName(const CXXNewExpr *NewExpr,
const SourceManager &SM,
const LangOptions &Lang) {
@@ -29,6 +34,7 @@ std::string GetNewExprName(const CXXNewE
   }
   return WrittenName.str();
 }
+
 } // namespace
 
 const char MakeSmartPtrCheck::PointerType[] = "pointerType";
@@ -37,9 +43,28 @@ const char MakeSmartPtrCheck::ResetCall[
 const char MakeSmartPtrCheck::NewExpression[] = "newExpression";
 
 MakeSmartPtrCheck::MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context,
- std::string makeSmartPtrFunctionName)
+ StringRef MakeSmartPtrFunctionName)
 : ClangTidyCheck(Name, Context),
-  makeSmartPtrFunctionName(std::move(makeSmartPtrFunctionName)) {}
+  IncludeStyle(utils::IncludeSorter::parseIncludeStyle(
+  Options.get("IncludeStyle", "llvm"))),
+  MakeSmartPtrFunctionHeader(
+  Options.get("MakeSmartPtrFunctionHeader", StdMemoryHeader)),
+  MakeSmartPtrFunctionName(
+  Options.get("MakeSmartPtrFunction", MakeSmartPtrFunctionName)) {}
+
+void MakeSmartPtrCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IncludeStyle", IncludeStyle);
+  Options.store(Opts, "MakeSmartPtrFunctionHeader", 
MakeSmartPtrFunctionHeader);
+  Options.store(Opts, "MakeSmartPtrFunction", MakeSmartPtrFunctionName);
+}
+
+void MakeSmartPtrCheck::registerPPCallbacks(CompilerInstance &Compiler) {
+  if (getLangOpts().CPlusPlus11) {
+Inserter.reset(new utils::IncludeInserter(
+Compiler.getSourceManager(), Compiler.getLangOpts(), IncludeStyle));
+Compiler.getPreprocessor().addPPCallbacks(Inserter->CreatePPCallbacks());
+  }
+}
 
 void MakeSmartPtrCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {
   if (!getLangOpts().CPlusPlus11)
@@ -107,7 +132,7 @@ void MakeSmartPtrCheck::checkConstruct(S
 return;
 
   auto Diag = diag(ConstructCallStart, "use %0 instead")
-  << makeSmartPtrFunctionName;
+  << MakeSmartPtrFunctionName;
 
   // Find the location of the template's left angle.
   size_t LAngle = ExprStr.find("<");
@@ -125,7 +150,7 @@ void MakeSmartPtrCheck::checkConstruct(S
 
   Diag << FixItHint::CreateReplacement(
   CharSourceRange::getCharRange(ConstructCallStart, ConstructCallEnd),
-  makeSmartPtrFunctionName);
+  MakeSmartPtrFunctionName);
 
   // If the smart_ptr is built with brace enclosed direct initialization, use
   // parenthesis instead.
@@ -142,6 +167,7 @@ void MakeSmartPtrCheck::checkConstruct(S
   }
 
   replaceNew(Diag, New, SM);
+  insertHeader(Diag, SM.getFileID(ConstructCallStart));
 }
 
 void MakeSmartPtrCheck::checkReset(SourceManager &SM,
@@ -155,11 +181,11 @@ void MakeSmartPtrCheck::checkReset(Sourc
   Lexer::getLocForEndOfToken(

[PATCH] D32914: Introduce Wzero-as-null-pointer-constant.

2017-07-05 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

@thakis ping?


https://reviews.llvm.org/D32914



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


[PATCH] D35000: [OpenCL] Added extended tests on metadata generation for half data type and arrays.

2017-07-05 Thread Egor Churaev via Phabricator via cfe-commits
echuraev created this revision.
Herald added a subscriber: yaxunl.

https://reviews.llvm.org/D35000

Files:
  test/CodeGenOpenCL/kernel-arg-info.cl


Index: test/CodeGenOpenCL/kernel-arg-info.cl
===
--- test/CodeGenOpenCL/kernel-arg-info.cl
+++ test/CodeGenOpenCL/kernel-arg-info.cl
@@ -61,6 +61,37 @@
 // CHECK-NOT: !kernel_arg_name
 // ARGINFO: !kernel_arg_name ![[MD54:[0-9]+]]
 
+kernel void foo6(constant half*constanthalfp,
+ constant half *restrict constanthalfrestrictp,
+ global half*globalhalfp,
+ global half *restrict globalhalfrestrictp,
+ global const half* globalconsthalfp,
+ global const half * restrict globalconsthalfrestrictp,
+
+ global volatile half*globalvolatilehalfp,
+ global volatile half *restrict globalvolatilehalfrestrictp,
+ global const volatile half* globalconstvolatilehalfp)
+{}
+// CHECK: !kernel_arg_type ![[MD61:[0-9]+]]
+// CHECK: !kernel_arg_base_type ![[MD61]]
+
+kernel void foo6_2(global const volatile half * restrict 
globalconstvolatilehalfrestrictp,
+   local half*localhalfp,
+   local half *restrict localhalfrestrictp,
+   local const half* localconsthalfp,
+   local const half * restrict localconsthalfrestrictp,
+   local volatile half*localvolatilehalfp,
+   local volatile half *restrict localvolatilehalfrestrictp,
+   local const volatile half* localconstvolatilehalfp,
+   local const volatile half * restrict 
localconstvolatilehalfrestrictp)
+{}
+// CHECK: !kernel_arg_type ![[MD61]]
+// CHECK: !kernel_arg_base_type ![[MD61]]
+
+typedef char char16 __attribute__((ext_vector_type(16)));
+__kernel void foo7(__global char16 arg[]) {}
+// CHECK: !kernel_arg_type ![[MD71:[0-9]+]]
+
 // CHECK: ![[MD11]] = !{i32 1, i32 0, i32 0, i32 2, i32 1, i32 1}
 // CHECK: ![[MD12]] = !{!"none", !"none", !"none", !"none", !"none", !"none"}
 // CHECK: ![[MD13]] = !{!"int*", !"int", !"int", !"float*", !"int*", !"int*"}
@@ -86,4 +117,6 @@
 // CHECK: ![[MD52]] = !{!"myImage", !"image1d_t"}
 // CHECK: ![[MD53]] = !{!"image1d_t", !"image1d_t"}
 // ARGINFO: ![[MD54]] = !{!"img1", !"img2"}
+// CHECK: ![[MD61]] = !{!"half*", !"half*", !"half*", !"half*", !"half*", 
!"half*", !"half*", !"half*", !"half*"}
+// CHECK: ![[MD71]] = !{!"char16*"}
 


Index: test/CodeGenOpenCL/kernel-arg-info.cl
===
--- test/CodeGenOpenCL/kernel-arg-info.cl
+++ test/CodeGenOpenCL/kernel-arg-info.cl
@@ -61,6 +61,37 @@
 // CHECK-NOT: !kernel_arg_name
 // ARGINFO: !kernel_arg_name ![[MD54:[0-9]+]]
 
+kernel void foo6(constant half*constanthalfp,
+ constant half *restrict constanthalfrestrictp,
+ global half*globalhalfp,
+ global half *restrict globalhalfrestrictp,
+ global const half* globalconsthalfp,
+ global const half * restrict globalconsthalfrestrictp,
+
+ global volatile half*globalvolatilehalfp,
+ global volatile half *restrict globalvolatilehalfrestrictp,
+ global const volatile half* globalconstvolatilehalfp)
+{}
+// CHECK: !kernel_arg_type ![[MD61:[0-9]+]]
+// CHECK: !kernel_arg_base_type ![[MD61]]
+
+kernel void foo6_2(global const volatile half * restrict globalconstvolatilehalfrestrictp,
+   local half*localhalfp,
+   local half *restrict localhalfrestrictp,
+   local const half* localconsthalfp,
+   local const half * restrict localconsthalfrestrictp,
+   local volatile half*localvolatilehalfp,
+   local volatile half *restrict localvolatilehalfrestrictp,
+   local const volatile half* localconstvolatilehalfp,
+   local const volatile half * restrict localconstvolatilehalfrestrictp)
+{}
+// CHECK: !kernel_arg_type ![[MD61]]
+// CHECK: !kernel_arg_base_type ![[MD61]]
+
+typedef char char16 __attribute__((ext_vector_type(16)));
+__kernel void foo7(__global char16 arg[]) {}
+// CHECK: !kernel_arg_type ![[MD71:[0-9]+]]
+
 // CHECK: ![[MD11]] = !{i32 1, i32 0, i32 0, i32 2, i32 1, i32 1}
 // CHECK: ![[MD12]] = !{!"none", !"none", !"none", !"none", !"none", !"none"}
 // CHECK: ![[MD13]] = !{!"int*", !"int", !"int", !"float*", !"int*", !"int*"}
@@ -86,4 +117,6 @@
 // CHECK: ![[MD52]] = !{!"myImage", !"image1d_t"}
 // CHECK: ![[MD53]] = !{!"image1d_t", !"image1d_t"}
 // ARGINFO: ![[MD54]] = !{!"img1", !"img2"}
+// CHECK: ![[MD61]] = !{!"half*", !"half*", !"half*", !"half*", !"half*", !"half*", !"half*", !"half*", !"half*"}
+// CHECK: ![[MD71]] = !{!"char16*"}
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/

[PATCH] D34985: Do not read the file to determine its name.

2017-07-05 Thread Axel Naumann via Phabricator via cfe-commits
karies added a comment.

To be clear: emitting annotations will trigger the determination of 
`PresumedLoc`s.  As part of that (but not the first part, IIRC) 
`SourceManager::getBufferName(()` will be called which will trigger the `fopen` 
of the file, just to get its name. Another task of `PresumedLoc` is to 
determine the line number which triggers an `fopen`; @v.g.vassilev is looking 
into a possible solution for that one.


Repository:
  rL LLVM

https://reviews.llvm.org/D34985



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


r307134 - Fix invalid warnings for header guards in preambles

2017-07-05 Thread Erik Verbruggen via cfe-commits
Author: erikjv
Date: Wed Jul  5 02:44:07 2017
New Revision: 307134

URL: http://llvm.org/viewvc/llvm-project?rev=307134&view=rev
Log:
Fix invalid warnings for header guards in preambles

Fixes https://bugs.llvm.org/show_bug.cgi?id=33574

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


Modified:
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/lib/Lex/Lexer.cpp
cfe/trunk/lib/Lex/PPLexerChange.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/lib/Parse/Parser.cpp

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=307134&r1=307133&r2=307134&view=diff
==
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Wed Jul  5 02:44:07 2017
@@ -1048,6 +1048,10 @@ public:
   /// which implicitly adds the builtin defines etc.
   void EnterMainSourceFile();
 
+  /// \brief After parser warm-up, initialize the conditional stack from
+  /// the preamble.
+  void replayPreambleConditionalStack();
+
   /// \brief Inform the preprocessor callbacks that processing is complete.
   void EndSourceFile();
 
@@ -1733,11 +1737,6 @@ public:
   /// \brief Return true if we're in the top-level file, not in a \#include.
   bool isInPrimaryFile() const;
 
-  /// \brief Return true if we're in the main file (specifically, if we are 0
-  /// (zero) levels deep \#include. This is used by the lexer to determine if
-  /// it needs to generate errors about unterminated \#if directives.
-  bool isInMainFile() const;
-
   /// \brief Handle cases where the \#include name is expanded
   /// from a macro as multiple tokens, which need to be glued together. 
   ///

Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=307134&r1=307133&r2=307134&view=diff
==
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Wed Jul  5 02:44:07 2017
@@ -2550,7 +2550,7 @@ bool Lexer::LexEndOfFile(Token &Result,
 return true;
   }
   
-  if (PP->isRecordingPreamble() && !PP->isInMainFile()) {
+  if (PP->isRecordingPreamble() && PP->isInPrimaryFile()) {
 PP->setRecordedPreambleConditionalStack(ConditionalStack);
 ConditionalStack.clear();
   }

Modified: cfe/trunk/lib/Lex/PPLexerChange.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPLexerChange.cpp?rev=307134&r1=307133&r2=307134&view=diff
==
--- cfe/trunk/lib/Lex/PPLexerChange.cpp (original)
+++ cfe/trunk/lib/Lex/PPLexerChange.cpp Wed Jul  5 02:44:07 2017
@@ -46,12 +46,6 @@ bool Preprocessor::isInPrimaryFile() con
   });
 }
 
-bool Preprocessor::isInMainFile() const {
-  if (IsFileLexer())
-return IncludeMacroStack.size() == 0;
-  return true;
-}
-
 /// getCurrentLexer - Return the current file lexer being lexed from.  Note
 /// that this ignores any potentially active macro expansions and _Pragma
 /// expansions going on at the time.

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=307134&r1=307133&r2=307134&view=diff
==
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Wed Jul  5 02:44:07 2017
@@ -535,7 +535,9 @@ void Preprocessor::EnterMainSourceFile()
 
   // Start parsing the predefines.
   EnterSourceFile(FID, nullptr, SourceLocation());
+}
 
+void Preprocessor::replayPreambleConditionalStack() {
   // Restore the conditional stack from the preamble, if there is one.
   if (PreambleConditionalStack.isReplaying()) {
 CurPPLexer->setConditionalLevels(PreambleConditionalStack.getStack());

Modified: cfe/trunk/lib/Parse/Parser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=307134&r1=307133&r2=307134&view=diff
==
--- cfe/trunk/lib/Parse/Parser.cpp (original)
+++ cfe/trunk/lib/Parse/Parser.cpp Wed Jul  5 02:44:07 2017
@@ -516,6 +516,8 @@ void Parser::Initialize() {
 
   // Prime the lexer look-ahead.
   ConsumeToken();
+
+  PP.replayPreambleConditionalStack();
 }
 
 void Parser::LateTemplateParserCleanupCallback(void *P) {


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


[PATCH] D34404: [Clang-Tidy] Preserve Message, FileOffset, FilePath in Clang-Tidy YAML output

2017-07-05 Thread Vladimir Plyashkun via Phabricator via cfe-commits
vladimir.plyashkun updated this revision to Diff 105240.
vladimir.plyashkun added a comment.

- use `EXPECT_*` instead of `ASSERT_*` where it's possible
- `Diagnostic` constructor now takes `const` references for it's arguments
- removed extra namespace qualifiers


Repository:
  rL LLVM

https://reviews.llvm.org/D34404

Files:
  include/clang/Tooling/Core/Diagnostic.h
  include/clang/Tooling/DiagnosticsYaml.h
  lib/Tooling/Core/Diagnostic.cpp
  unittests/Tooling/CMakeLists.txt
  unittests/Tooling/DiagnosticsYamlTest.cpp
  unittests/clang-apply-replacements/ApplyReplacementsTest.cpp
  unittests/clang-apply-replacements/CMakeLists.txt

Index: unittests/Tooling/DiagnosticsYamlTest.cpp
===
--- /dev/null
+++ unittests/Tooling/DiagnosticsYamlTest.cpp
@@ -0,0 +1,168 @@
+//===- unittests/Tooling/DiagnosticsYamlTest.cpp - Serialization tests ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Tests for serialization of Diagnostics.
+//
+//===--===//
+
+#include "clang/Tooling/Core/Diagnostic.h"
+#include "clang/Tooling/DiagnosticsYaml.h"
+#include "clang/Tooling/ReplacementsYaml.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace clang::tooling;
+
+static Diagnostic makeDiagnostic(StringRef DiagnosticName, 
+ const std::string &Message,
+ int FileOffset,
+ const std::string &FilePath,
+ const StringMap &Fix) {
+  DiagnosticMessage DiagMessage;
+  DiagMessage.Message = Message;
+  DiagMessage.FileOffset = FileOffset;
+  DiagMessage.FilePath = FilePath;
+  return Diagnostic(DiagnosticName, DiagMessage, Fix, {},
+Diagnostic::Warning, "path/to/build/directory");
+}
+
+TEST(DiagnosticsYamlTest, serializesDiagnostics) {
+  TranslationUnitDiagnostics TUD;
+  TUD.MainSourceFile = "path/to/source.cpp";
+
+  StringMap Fix1{
+{ "path/to/source.cpp", Replacements(Replacement("path/to/source.cpp", 100,
+12, "replacement #1")) } };
+  TUD.Diagnostics.push_back(makeDiagnostic("diagnostic#1", "message #1", 55, 
+   "path/to/source.cpp", Fix1));
+  
+  StringMap Fix2{
+{ "path/to/header.h",
+Replacements(Replacement("path/to/header.h", 62, 2, "replacement #2")) } };
+  TUD.Diagnostics.push_back(makeDiagnostic("diagnostic#2", "message #2", 60, 
+   "path/to/header.h", Fix2));
+
+  StringMap  Fix3;
+  TUD.Diagnostics.push_back(makeDiagnostic("diagnostic#3", "message #3", 72, 
+   "path/to/source2.cpp", Fix3));
+
+  std::string YamlContent;
+  raw_string_ostream YamlContentStream(YamlContent);
+
+  yaml::Output YAML(YamlContentStream);
+  YAML << TUD;
+
+  EXPECT_STREQ("---\n"
+"MainSourceFile:  path/to/source.cpp\n"
+"Diagnostics: \n"
+"  - DiagnosticName:  'diagnostic#1\'\n"
+"Message: 'message #1'\n"
+"FileOffset:  55\n"
+"FilePath:path/to/source.cpp\n"
+"Replacements:\n"
+"  - FilePath:path/to/source.cpp\n"
+"Offset:  100\n"
+"Length:  12\n"
+"ReplacementText: 'replacement #1'\n"
+"  - DiagnosticName:  'diagnostic#2'\n"
+"Message: 'message #2'\n"
+"FileOffset:  60\n"
+"FilePath:path/to/header.h\n"
+"Replacements:\n"
+"  - FilePath:path/to/header.h\n"
+"Offset:  62\n"
+"Length:  2\n"
+"ReplacementText: 'replacement #2'\n"
+"  - DiagnosticName:  'diagnostic#3'\n"
+"Message: 'message #3'\n"
+"FileOffset:  72\n"
+"FilePath:path/to/source2.cpp\n"
+"Replacements:\n"
+"...\n",
+  YamlContentStream.str().c_str());
+}
+
+TEST(DiagnosticsYamlTest, deserializesDiagnostics) {
+std::string YamlContent = "---\n"
+  "MainSourceFile:  path/to/source.cpp\n"
+  "Diagnostics: \n"
+  "  - DiagnosticName:  'diagnostic#1'\n"
+  "Message: 'message #1'\n"
+  "FileOffset:  55\n"
+  "FilePath:path/to/source.cpp\n"
+  "Replacements:\n"
+  "  - FilePath:path/to/source.cpp\n"
+  "Offset:  100\n"
+  "Length:  12\n"
+  "ReplacementText: 'replacement #1'\n"
+  "  - DiagnosticName:  'diagnostic#2'\n"
+  "Message: 'message #2'\n"
+  "FileOffset:  60\n"
+  "FilePath:path/to/header.h\n"
+ 

[PATCH] D35008: [AArch64] Produce the right kind of va_arg for windows

2017-07-05 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo created this revision.
Herald added subscribers: kristof.beyls, rengolin, aemerson.

On windows on arm64, the va_list is a plain pointer.


https://reviews.llvm.org/D35008

Files:
  lib/CodeGen/TargetInfo.cpp


Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -4770,10 +4770,11 @@
 
 private:
   ABIKind Kind;
+  bool IsMS;
 
 public:
-  AArch64ABIInfo(CodeGenTypes &CGT, ABIKind Kind)
-: SwiftABIInfo(CGT), Kind(Kind) {}
+  AArch64ABIInfo(CodeGenTypes &CGT, ABIKind Kind, bool MS)
+  : SwiftABIInfo(CGT), Kind(Kind), IsMS(MS) {}
 
 private:
   ABIKind getABIKind() const { return Kind; }
@@ -4803,9 +4804,12 @@
 
   Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
 QualType Ty) const override {
-return isDarwinPCS() ? EmitDarwinVAArg(VAListAddr, Ty, CGF)
- : EmitAAPCSVAArg(VAListAddr, Ty, CGF);
+return IsMS ? EmitMSVAArg(CGF, VAListAddr, Ty)
+: isDarwinPCS() ? EmitDarwinVAArg(VAListAddr, Ty, CGF)
+: EmitAAPCSVAArg(VAListAddr, Ty, CGF);
   }
+  Address EmitMSVAArg(CodeGenFunction &CGF, Address VAListAddr,
+  QualType Ty) const override;
 
   bool shouldPassIndirectlyForSwift(CharUnits totalSize,
 ArrayRef scalars,
@@ -4822,8 +4826,9 @@
 
 class AArch64TargetCodeGenInfo : public TargetCodeGenInfo {
 public:
-  AArch64TargetCodeGenInfo(CodeGenTypes &CGT, AArch64ABIInfo::ABIKind Kind)
-  : TargetCodeGenInfo(new AArch64ABIInfo(CGT, Kind)) {}
+  AArch64TargetCodeGenInfo(CodeGenTypes &CGT, AArch64ABIInfo::ABIKind Kind,
+   bool IsMS)
+  : TargetCodeGenInfo(new AArch64ABIInfo(CGT, Kind, IsMS)) {}
 
   StringRef getARCRetainAutoreleasedReturnValueMarker() const override {
 return "mov\tfp, fp\t\t# marker for objc_retainAutoreleaseReturnValue";
@@ -5312,6 +5317,14 @@
   TyInfo, SlotSize, /*AllowHigherAlign*/ true);
 }
 
+Address AArch64ABIInfo::EmitMSVAArg(CodeGenFunction &CGF, Address VAListAddr,
+QualType Ty) const {
+  return emitVoidPtrVAArg(CGF, VAListAddr, Ty, /*indirect*/ false,
+  CGF.getContext().getTypeInfoInChars(Ty),
+  CharUnits::fromQuantity(8),
+  /*allowHigherAlign*/ false);
+}
+
 
//===--===//
 // ARM ABI Implementation
 
//===--===//
@@ -8448,7 +8461,8 @@
 if (getTarget().getABI() == "darwinpcs")
   Kind = AArch64ABIInfo::DarwinPCS;
 
-return SetCGInfo(new AArch64TargetCodeGenInfo(Types, Kind));
+return SetCGInfo(new AArch64TargetCodeGenInfo(
+Types, Kind, Triple.getOS() == llvm::Triple::Win32));
   }
 
   case llvm::Triple::wasm32:


Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -4770,10 +4770,11 @@
 
 private:
   ABIKind Kind;
+  bool IsMS;
 
 public:
-  AArch64ABIInfo(CodeGenTypes &CGT, ABIKind Kind)
-: SwiftABIInfo(CGT), Kind(Kind) {}
+  AArch64ABIInfo(CodeGenTypes &CGT, ABIKind Kind, bool MS)
+  : SwiftABIInfo(CGT), Kind(Kind), IsMS(MS) {}
 
 private:
   ABIKind getABIKind() const { return Kind; }
@@ -4803,9 +4804,12 @@
 
   Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
 QualType Ty) const override {
-return isDarwinPCS() ? EmitDarwinVAArg(VAListAddr, Ty, CGF)
- : EmitAAPCSVAArg(VAListAddr, Ty, CGF);
+return IsMS ? EmitMSVAArg(CGF, VAListAddr, Ty)
+: isDarwinPCS() ? EmitDarwinVAArg(VAListAddr, Ty, CGF)
+: EmitAAPCSVAArg(VAListAddr, Ty, CGF);
   }
+  Address EmitMSVAArg(CodeGenFunction &CGF, Address VAListAddr,
+  QualType Ty) const override;
 
   bool shouldPassIndirectlyForSwift(CharUnits totalSize,
 ArrayRef scalars,
@@ -4822,8 +4826,9 @@
 
 class AArch64TargetCodeGenInfo : public TargetCodeGenInfo {
 public:
-  AArch64TargetCodeGenInfo(CodeGenTypes &CGT, AArch64ABIInfo::ABIKind Kind)
-  : TargetCodeGenInfo(new AArch64ABIInfo(CGT, Kind)) {}
+  AArch64TargetCodeGenInfo(CodeGenTypes &CGT, AArch64ABIInfo::ABIKind Kind,
+   bool IsMS)
+  : TargetCodeGenInfo(new AArch64ABIInfo(CGT, Kind, IsMS)) {}
 
   StringRef getARCRetainAutoreleasedReturnValueMarker() const override {
 return "mov\tfp, fp\t\t# marker for objc_retainAutoreleaseReturnValue";
@@ -5312,6 +5317,14 @@
   TyInfo, SlotSize, /*AllowHigherAlign*/ true);
 }
 
+Address AArch64ABIInfo::EmitMSVAArg(CodeGenFunction &CGF, Address VAListAddr,
+

r307143 - Add const to reference arguments of Diagnostic ctor

2017-07-05 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Wed Jul  5 04:45:09 2017
New Revision: 307143

URL: http://llvm.org/viewvc/llvm-project?rev=307143&view=rev
Log:
Add const to reference arguments of Diagnostic ctor

Modified:
cfe/trunk/include/clang/Tooling/Core/Diagnostic.h
cfe/trunk/lib/Tooling/Core/Diagnostic.cpp

Modified: cfe/trunk/include/clang/Tooling/Core/Diagnostic.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Core/Diagnostic.h?rev=307143&r1=307142&r2=307143&view=diff
==
--- cfe/trunk/include/clang/Tooling/Core/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Tooling/Core/Diagnostic.h Wed Jul  5 04:45:09 2017
@@ -58,9 +58,9 @@ struct Diagnostic {
   Diagnostic(llvm::StringRef DiagnosticName, Level DiagLevel,
  StringRef BuildDirectory);
 
-  Diagnostic(llvm::StringRef DiagnosticName, DiagnosticMessage &Message,
- llvm::StringMap &Fix,
- SmallVector &Notes, Level DiagLevel,
+  Diagnostic(llvm::StringRef DiagnosticName, const DiagnosticMessage &Message,
+ const llvm::StringMap &Fix,
+ const SmallVector &Notes, Level DiagLevel,
  llvm::StringRef BuildDirectory);
 
   /// \brief Name identifying the Diagnostic.

Modified: cfe/trunk/lib/Tooling/Core/Diagnostic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Core/Diagnostic.cpp?rev=307143&r1=307142&r2=307143&view=diff
==
--- cfe/trunk/lib/Tooling/Core/Diagnostic.cpp (original)
+++ cfe/trunk/lib/Tooling/Core/Diagnostic.cpp Wed Jul  5 04:45:09 2017
@@ -35,9 +35,9 @@ Diagnostic::Diagnostic(llvm::StringRef D
   BuildDirectory(BuildDirectory) {}
 
 Diagnostic::Diagnostic(llvm::StringRef DiagnosticName,
-   DiagnosticMessage &Message,
-   llvm::StringMap &Fix,
-   SmallVector &Notes,
+   const DiagnosticMessage &Message,
+   const llvm::StringMap &Fix,
+   const SmallVector &Notes,
Level DiagLevel, llvm::StringRef BuildDirectory)
 : DiagnosticName(DiagnosticName), Message(Message), Fix(Fix), Notes(Notes),
   DiagLevel(DiagLevel), BuildDirectory(BuildDirectory) {}


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


[PATCH] D34404: [Clang-Tidy] Preserve Message, FileOffset, FilePath in Clang-Tidy YAML output

2017-07-05 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: unittests/clang-apply-replacements/ApplyReplacementsTest.cpp:23
+  SmallVector EmptyNotes;
+  return tooling::Diagnostic(DiagnosticName, Message, Replacements, EmptyNotes,
+ tooling::Diagnostic::Warning, BuildDirectory);

vladimir.plyashkun wrote:
> alexfh wrote:
> > alexfh wrote:
> > > Will `{}` work instead of `EmptyNotes`?
> > `tooling::` is not needed due to the using directive above. Same below.
> Unfortunately, no.
> Constructor expects non-const reference `SmallVector 
> &Notes`, so i can't pass rvalue directly to it.
I overlooked this when committing someone's patch. Fixed in r307143. Now you 
can add `const` and probably also use `{}`.


Repository:
  rL LLVM

https://reviews.llvm.org/D34404



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


[PATCH] D34475: [RFC] [AArch64] Add support for __builtin_ms_va_list on aarch64

2017-07-05 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo updated this revision to Diff 105254.
mstorsjo edited the summary of this revision.
mstorsjo added reviewers: mgrang, t.p.northover.
mstorsjo added a comment.

Split the patch into two; one for generic handling of va_arg for win/arm64, and 
one for using the same functionality while targeting other OSes (i.e. for wine) 
via the __builtin_ms_* intrinsics.


https://reviews.llvm.org/D34475

Files:
  include/clang/Basic/BuiltinsAArch64.def
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/Specifiers.h
  lib/AST/ItaniumMangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaDeclAttr.cpp

Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -4279,8 +4279,13 @@
   case AttributeList::AT_VectorCall: CC = CC_X86VectorCall; break;
   case AttributeList::AT_RegCall: CC = CC_X86RegCall; break;
   case AttributeList::AT_MSABI:
-CC = Context.getTargetInfo().getTriple().isOSWindows() ? CC_C :
- CC_X86_64Win64;
+
+CC = Context.getTargetInfo().getTriple().isOSWindows()
+ ? CC_C
+ : Context.getTargetInfo().getTriple().getArch() ==
+   llvm::Triple::aarch64
+   ? CC_AArch64Win64
+   : CC_X86_64Win64;
 break;
   case AttributeList::AT_SysVABI:
 CC = Context.getTargetInfo().getTriple().isOSWindows() ? CC_X86_64SysV :
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -1440,6 +1440,9 @@
 
 bool Sema::CheckAArch64BuiltinFunctionCall(unsigned BuiltinID,
  CallExpr *TheCall) {
+  if (BuiltinID == AArch64::BI__builtin_ms_va_start)
+return SemaBuiltinVAStart(BuiltinID, TheCall);
+
   if (BuiltinID == AArch64::BI__builtin_arm_ldrex ||
   BuiltinID == AArch64::BI__builtin_arm_ldaex ||
   BuiltinID == AArch64::BI__builtin_arm_strex ||
@@ -3622,12 +3625,15 @@
 static bool checkVAStartABI(Sema &S, unsigned BuiltinID, Expr *Fn) {
   const llvm::Triple &TT = S.Context.getTargetInfo().getTriple();
   bool IsX64 = TT.getArch() == llvm::Triple::x86_64;
+  bool IsAArch64 = TT.getArch() == llvm::Triple::aarch64;
   bool IsWindows = TT.isOSWindows();
-  bool IsMSVAStart = BuiltinID == X86::BI__builtin_ms_va_start;
+  bool IsMSVAStart = BuiltinID == X86::BI__builtin_ms_va_start ||
+ BuiltinID == AArch64::BI__builtin_ms_va_start;
+  clang::CallingConv CC = CC_C;
+  if (const FunctionDecl *FD = S.getCurFunctionDecl())
+CC = FD->getType()->getAs()->getCallConv();
+
   if (IsX64) {
-clang::CallingConv CC = CC_C;
-if (const FunctionDecl *FD = S.getCurFunctionDecl())
-  CC = FD->getType()->getAs()->getCallConv();
 if (IsMSVAStart) {
   // Don't allow this in System V ABI functions.
   if (CC == CC_X86_64SysV || (!IsWindows && CC != CC_X86_64Win64))
@@ -3647,6 +3653,22 @@
 return false;
   }
 
+  if (IsAArch64) {
+if (IsMSVAStart) {
+  // Don't allow this in AAPCS functions.
+  if (CC == CC_C || (!IsWindows && CC != CC_AArch64Win64))
+return S.Diag(Fn->getLocStart(),
+  diag::err_ms_va_start_used_in_aapcs_function);
+} else {
+  // On aarch64 Unix, don't allow this in Win64 ABI functions.
+  if (!IsWindows && CC == CC_AArch64Win64)
+return S.Diag(Fn->getLocStart(),
+  diag::err_va_start_used_in_wrong_abi_function)
+   << !IsWindows;
+}
+return false;
+  }
+
   if (IsMSVAStart)
 return S.Diag(Fn->getLocStart(), diag::err_x86_builtin_64_only);
   return false;
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -967,6 +967,7 @@
   case CC_PreserveMost:
   case CC_PreserveAll:
   case CC_X86RegCall:
+  case CC_AArch64Win64:
 return 0;
   }
   return 0;
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -64,6 +64,7 @@
   case CC_PreserveMost: return llvm::CallingConv::PreserveMost;
   case CC_PreserveAll: return llvm::CallingConv::PreserveAll;
   case CC_Swift: return llvm::CallingConv::Swift;
+  case CC_AArch64Win64: return llvm::CallingConv::AArch64_Win64;
   }
 }
 
@@ -191,7 +192,8 @@
FTP, FD);
 }
 
-static CallingConv getCallingConventionForDecl(const Decl *D, bool IsWindows) {
+static CallingConv getCallingConventionForDecl(const Decl *D, bool IsWindows,
+   llvm::Triple::Arch

r307147 - [clang-format] Fix an uninitialized memory access

2017-07-05 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Wed Jul  5 05:24:01 2017
New Revision: 307147

URL: http://llvm.org/viewvc/llvm-project?rev=307147&view=rev
Log:
[clang-format] Fix an uninitialized memory access

Modified:
cfe/trunk/lib/Format/FormatToken.h

Modified: cfe/trunk/lib/Format/FormatToken.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.h?rev=307147&r1=307146&r2=307147&view=diff
==
--- cfe/trunk/lib/Format/FormatToken.h (original)
+++ cfe/trunk/lib/Format/FormatToken.h Wed Jul  5 05:24:01 2017
@@ -646,13 +646,6 @@ struct AdditionalKeywords {
 kw_var = &IdentTable.get("var");
 kw_yield = &IdentTable.get("yield");
 
-JsExtraKeywords = std::unordered_set(
-{kw_as, kw_async, kw_await, kw_declare, kw_finally, kw_from,
- kw_function, kw_get, kw_import, kw_is, kw_let, kw_module, kw_set,
- kw_type, kw_var, kw_yield,
- // Keywords from the Java section.
- kw_abstract, kw_extends, kw_implements, kw_instanceof, kw_interface});
-
 kw_abstract = &IdentTable.get("abstract");
 kw_assert = &IdentTable.get("assert");
 kw_extends = &IdentTable.get("extends");
@@ -680,6 +673,15 @@ struct AdditionalKeywords {
 kw_qsignals = &IdentTable.get("Q_SIGNALS");
 kw_slots = &IdentTable.get("slots");
 kw_qslots = &IdentTable.get("Q_SLOTS");
+
+// Keep this at the end of the constructor to make sure everything here is
+// already initialized.
+JsExtraKeywords = std::unordered_set(
+{kw_as, kw_async, kw_await, kw_declare, kw_finally, kw_from,
+ kw_function, kw_get, kw_import, kw_is, kw_let, kw_module, kw_set,
+ kw_type, kw_var, kw_yield,
+ // Keywords from the Java section.
+ kw_abstract, kw_extends, kw_implements, kw_instanceof, kw_interface});
   }
 
   // Context sensitive keywords.


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


[PATCH] D34947: [clangd] Add support for per-file extra flags

2017-07-05 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 105257.
krasimir marked 2 inline comments as done.
krasimir added a comment.

- Addess review comments


https://reviews.llvm.org/D34947

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdUnitStore.cpp
  clangd/GlobalCompilationDatabase.cpp
  clangd/GlobalCompilationDatabase.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  test/clangd/extra-flags.test

Index: test/clangd/extra-flags.test
===
--- /dev/null
+++ test/clangd/extra-flags.test
@@ -0,0 +1,22 @@
+# RUN: clangd -run-synchronously < %s | FileCheck %s
+# It is absolutely vital that this file has CRLF line endings.
+#
+Content-Length: 125
+
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
+#
+Content-Length: 205
+
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///foo.c","languageId":"c","version":1,"text":"int main() { int i; return i; }"},"metadata":{"extraFlags":["-Wall"]}}}
+# CHECK: {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///foo.c","diagnostics":[{"range":{"start": {"line": 0, "character": 28}, "end": {"line": 0, "character": 28}},"severity":2,"message":"variable 'i' is uninitialized when used here"},{"range":{"start": {"line": 0, "character": 19}, "end": {"line": 0, "character": 19}},"severity":3,"message":"initialize the variable 'i' to silence this warning"}]}}
+#
+Content-Length: 175
+
+{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file:///foo.c","version":2},"contentChanges":[{"text":"int main() { int i; return i; }"}]}}
+# CHECK: {"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///foo.c","diagnostics":[{"range":{"start": {"line": 0, "character": 28}, "end": {"line": 0, "character": 28}},"severity":2,"message":"variable 'i' is uninitialized when used here"},{"range":{"start": {"line": 0, "character": 19}, "end": {"line": 0, "character": 19}},"severity":3,"message":"initialize the variable 'i' to silence this warning"}]}}
+#
+Content-Length: 44
+
+{"jsonrpc":"2.0","id":5,"method":"shutdown"}
+
+
Index: clangd/Protocol.h
===
--- clangd/Protocol.h
+++ clangd/Protocol.h
@@ -118,6 +118,12 @@
   static std::string unparse(const Location &P);
 };
 
+struct Metadata {
+  std::vector extraFlags;
+
+  static llvm::Optional parse(llvm::yaml::MappingNode *Params);
+};
+
 struct TextEdit {
   /// The range of the text document to be manipulated. To insert
   /// text into a document create a range where start === end.
@@ -152,6 +158,9 @@
   /// The document that was opened.
   TextDocumentItem textDocument;
 
+  /// Extension storing per-file metadata, such as compilation flags.
+  llvm::Optional metadata;
+
   static llvm::Optional
   parse(llvm::yaml::MappingNode *Params);
 };
Index: clangd/Protocol.cpp
===
--- clangd/Protocol.cpp
+++ clangd/Protocol.cpp
@@ -204,6 +204,33 @@
   return Result;
 }
 
+llvm::Optional Metadata::parse(llvm::yaml::MappingNode *Params) {
+  Metadata Result;
+  for (auto &NextKeyValue : *Params) {
+auto *KeyString = dyn_cast(NextKeyValue.getKey());
+if (!KeyString)
+  return llvm::None;
+
+llvm::SmallString<10> KeyStorage;
+StringRef KeyValue = KeyString->getValue(KeyStorage);
+auto *Value = NextKeyValue.getValue();
+
+llvm::SmallString<10> Storage;
+if (KeyValue == "extraFlags") {
+  auto *Seq = dyn_cast(Value);
+  if (!Seq)
+return llvm::None;
+  for (auto &Item : *Seq) {
+auto *Node = dyn_cast(&Item);
+if (!Node)
+  return llvm::None;
+Result.extraFlags.push_back(Node->getValue(Storage));
+  }
+}
+  }
+  return Result;
+}
+
 llvm::Optional TextEdit::parse(llvm::yaml::MappingNode *Params) {
   TextEdit Result;
   for (auto &NextKeyValue : *Params) {
@@ -265,6 +292,11 @@
   if (!Parsed)
 return llvm::None;
   Result.textDocument = std::move(*Parsed);
+} else if (KeyValue == "metadata") {
+  auto Parsed = Metadata::parse(Value);
+  if (!Parsed)
+return llvm::None;
+  Result.metadata = std::move(*Parsed);
 } else {
   return llvm::None;
 }
Index: clangd/GlobalCompilationDatabase.h
===
--- clangd/GlobalCompilationDatabase.h
+++ clangd/GlobalCompilationDatabase.h
@@ -25,6 +25,9 @@
 
 namespace clangd {
 
+/// Returns a default compile command to use for \p File.
+tooling::CompileCommand getDefaultCompileCommand(PathRef File);
+
 /// Provides compilation arguments used for building ClangdUnit.
 class GlobalCompilationDatabase {
 public:
@@ -45,14 +48,19 @@
   std::vector
   getCompileCommands(PathRef File) override;
 
+  void addExtraFlagsForFile(PathRef File, std::vector Extr

[PATCH] D34947: [clangd] Add support for per-file extra flags

2017-07-05 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

I forgot to submit this last comment yesterday, sorry about that.




Comment at: clangd/GlobalCompilationDatabase.h:51
 
+  void addExtraFlagsForFile(PathRef File, std::vector ExtraFlags);
+

Maybe rename to `setExtraFlagsForFile`?
The name `addExtraFlags...` sounds like it appends to the existing list, but we 
actually replace the flags there.


https://reviews.llvm.org/D34947



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


r307151 - [driver][mips] Remove redundant curly brackets. NFC

2017-07-05 Thread Simon Atanasyan via cfe-commits
Author: atanasyan
Date: Wed Jul  5 05:57:32 2017
New Revision: 307151

URL: http://llvm.org/viewvc/llvm-project?rev=307151&view=rev
Log:
[driver][mips] Remove redundant curly brackets. NFC

Modified:
cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp?rev=307151&r1=307150&r2=307151&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp Wed Jul  5 05:57:32 2017
@@ -227,12 +227,11 @@ void mips::getMIPSTargetFeatures(const D
  O.matches(options::OPT_fno_PIE) || O.matches(options::OPT_fno_pie));
   }
 
-  if (IsN64 && NonPIC) {
+  if (IsN64 && NonPIC)
 Features.push_back("+noabicalls");
-  } else {
+  else
 AddTargetFeature(Args, Features, options::OPT_mno_abicalls,
  options::OPT_mabicalls, "noabicalls");
-  }
 
   mips::FloatABI FloatABI = mips::getMipsFloatABI(D, Args);
   if (FloatABI == mips::FloatABI::Soft) {


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


r307152 - [driver][mips] Use AddTargetFeature to check arguments and add feature flags. NFC

2017-07-05 Thread Simon Atanasyan via cfe-commits
Author: atanasyan
Date: Wed Jul  5 05:57:37 2017
New Revision: 307152

URL: http://llvm.org/viewvc/llvm-project?rev=307152&view=rev
Log:
[driver][mips] Use AddTargetFeature to check arguments and add feature flags. 
NFC

Modified:
cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp?rev=307152&r1=307151&r2=307152&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp Wed Jul  5 05:57:37 2017
@@ -297,13 +297,8 @@ void mips::getMIPSTargetFeatures(const D
 
   AddTargetFeature(Args, Features, options::OPT_mno_odd_spreg,
options::OPT_modd_spreg, "nooddspreg");
-
-  if (Arg *A = Args.getLastArg(options::OPT_mmadd4, options::OPT_mno_madd4)) {
-if (A->getOption().matches(options::OPT_mmadd4))
-  Features.push_back("-nomadd4");
-else
-  Features.push_back("+nomadd4");
-  }
+  AddTargetFeature(Args, Features, options::OPT_mno_madd4, options::OPT_mmadd4,
+   "nomadd4");
 }
 
 mips::NanEncoding mips::getSupportedNanEncoding(StringRef &CPU) {


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


r307156 - [SystemZ] Simplify handling of ISA revisions

2017-07-05 Thread Ulrich Weigand via cfe-commits
Author: uweigand
Date: Wed Jul  5 06:19:47 2017
New Revision: 307156

URL: http://llvm.org/viewvc/llvm-project?rev=307156&view=rev
Log:
[SystemZ] Simplify handling of ISA revisions

This moves determination of the ISA revision from the CPU name to
one single place, removing a bunch of duplicated code.  It also
makes the supported ISA revisions available as feature strings.

No functional change.


Modified:
cfe/trunk/lib/Basic/Targets.cpp

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=307156&r1=307155&r2=307156&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Wed Jul  5 06:19:47 2017
@@ -7424,13 +7424,14 @@ class SystemZTargetInfo : public TargetI
   static const Builtin::Info BuiltinInfo[];
   static const char *const GCCRegNames[];
   std::string CPU;
+  int ISARevision;
   bool HasTransactionalExecution;
   bool HasVector;
 
 public:
   SystemZTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
-  : TargetInfo(Triple), CPU("z10"), HasTransactionalExecution(false),
-HasVector(false) {
+  : TargetInfo(Triple), CPU("z10"), ISARevision(8),
+HasTransactionalExecution(false), HasVector(false) {
 IntMaxType = SignedLong;
 Int64Type = SignedLong;
 TLSSupported = true;
@@ -7452,14 +7453,7 @@ public:
 Builder.defineMacro("__zarch__");
 Builder.defineMacro("__LONG_DOUBLE_128__");
 
-const std::string ISARev = llvm::StringSwitch(CPU)
-   .Cases("arch8", "z10", "8")
-   .Cases("arch9", "z196", "9")
-   .Cases("arch10", "zEC12", "10")
-   .Cases("arch11", "z13", "11")
-   .Default("");
-if (!ISARev.empty())
-  Builder.defineMacro("__ARCH__", ISARev);
+Builder.defineMacro("__ARCH__", Twine(ISARevision));
 
 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
@@ -7492,37 +7486,35 @@ public:
   BuiltinVaListKind getBuiltinVaListKind() const override {
 return TargetInfo::SystemZBuiltinVaList;
   }
+  int getISARevision(const StringRef &Name) const {
+return llvm::StringSwitch(Name)
+  .Cases("arch8", "z10", 8)
+  .Cases("arch9", "z196", 9)
+  .Cases("arch10", "zEC12", 10)
+  .Cases("arch11", "z13", 11)
+  .Default(-1);
+  }
   bool setCPU(const std::string &Name) override {
 CPU = Name;
-bool CPUKnown = llvm::StringSwitch(Name)
-  .Case("z10", true)
-  .Case("arch8", true)
-  .Case("z196", true)
-  .Case("arch9", true)
-  .Case("zEC12", true)
-  .Case("arch10", true)
-  .Case("z13", true)
-  .Case("arch11", true)
-  .Default(false);
-
-return CPUKnown;
+ISARevision = getISARevision(CPU);
+return ISARevision != -1;
   }
   bool
   initFeatureMap(llvm::StringMap &Features, DiagnosticsEngine &Diags,
  StringRef CPU,
  const std::vector &FeaturesVec) const override {
-if (CPU == "zEC12" || CPU == "arch10")
-  Features["transactional-execution"] = true;
-if (CPU == "z13" || CPU == "arch11") {
+int ISARevision = getISARevision(CPU);
+if (ISARevision >= 10)
   Features["transactional-execution"] = true;
+if (ISARevision >= 11)
   Features["vector"] = true;
-}
 return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
   }
 
   bool handleTargetFeatures(std::vector &Features,
 DiagnosticsEngine &Diags) override {
 HasTransactionalExecution = false;
+HasVector = false;
 for (const auto &Feature : Features) {
   if (Feature == "+transactional-execution")
 HasTransactionalExecution = true;
@@ -7541,6 +7533,10 @@ public:
   bool hasFeature(StringRef Feature) const override {
 return llvm::StringSwitch(Feature)
 .Case("systemz", true)
+.Case("arch8", ISARevision >= 8)
+.Case("arch9", ISARevision >= 9)
+.Case("arch10", ISARevision >= 10)
+.Case("arch11", ISARevision >= 11)
 .Case("htm", HasTransactionalExecution)
 .Case("vx", HasVector)
 .Default(false);


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


[PATCH] D34404: [Clang-Tidy] Preserve Message, FileOffset, FilePath in Clang-Tidy YAML output

2017-07-05 Thread Vladimir Plyashkun via Phabricator via cfe-commits
vladimir.plyashkun updated this revision to Diff 105260.
vladimir.plyashkun added a comment.

- marked some arguments as `const`
- use `{}` instead of explicit variable declarations


Repository:
  rL LLVM

https://reviews.llvm.org/D34404

Files:
  include/clang/Tooling/DiagnosticsYaml.h
  unittests/Tooling/CMakeLists.txt
  unittests/Tooling/DiagnosticsYamlTest.cpp
  unittests/clang-apply-replacements/ApplyReplacementsTest.cpp
  unittests/clang-apply-replacements/CMakeLists.txt

Index: unittests/Tooling/DiagnosticsYamlTest.cpp
===
--- /dev/null
+++ unittests/Tooling/DiagnosticsYamlTest.cpp
@@ -0,0 +1,167 @@
+//===- unittests/Tooling/DiagnosticsYamlTest.cpp - Serialization tests ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Tests for serialization of Diagnostics.
+//
+//===--===//
+
+#include "clang/Tooling/Core/Diagnostic.h"
+#include "clang/Tooling/DiagnosticsYaml.h"
+#include "clang/Tooling/ReplacementsYaml.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+using namespace clang::tooling;
+
+static Diagnostic makeDiagnostic(StringRef DiagnosticName, 
+ const std::string &Message,
+ int FileOffset,
+ const std::string &FilePath,
+ const StringMap &Fix) {
+  DiagnosticMessage DiagMessage;
+  DiagMessage.Message = Message;
+  DiagMessage.FileOffset = FileOffset;
+  DiagMessage.FilePath = FilePath;
+  return Diagnostic(DiagnosticName, DiagMessage, Fix, {},
+Diagnostic::Warning, "path/to/build/directory");
+}
+
+TEST(DiagnosticsYamlTest, serializesDiagnostics) {
+  TranslationUnitDiagnostics TUD;
+  TUD.MainSourceFile = "path/to/source.cpp";
+
+  StringMap Fix1{
+{ "path/to/source.cpp", Replacements(Replacement("path/to/source.cpp", 100,
+12, "replacement #1")) } };
+  TUD.Diagnostics.push_back(makeDiagnostic("diagnostic#1", "message #1", 55, 
+   "path/to/source.cpp", Fix1));
+  
+  StringMap Fix2{
+{ "path/to/header.h",
+Replacements(Replacement("path/to/header.h", 62, 2, "replacement #2")) } };
+  TUD.Diagnostics.push_back(makeDiagnostic("diagnostic#2", "message #2", 60, 
+   "path/to/header.h", Fix2));
+
+  TUD.Diagnostics.push_back(makeDiagnostic("diagnostic#3", "message #3", 72, 
+   "path/to/source2.cpp", {}));
+
+  std::string YamlContent;
+  raw_string_ostream YamlContentStream(YamlContent);
+
+  yaml::Output YAML(YamlContentStream);
+  YAML << TUD;
+
+  EXPECT_STREQ("---\n"
+"MainSourceFile:  path/to/source.cpp\n"
+"Diagnostics: \n"
+"  - DiagnosticName:  'diagnostic#1\'\n"
+"Message: 'message #1'\n"
+"FileOffset:  55\n"
+"FilePath:path/to/source.cpp\n"
+"Replacements:\n"
+"  - FilePath:path/to/source.cpp\n"
+"Offset:  100\n"
+"Length:  12\n"
+"ReplacementText: 'replacement #1'\n"
+"  - DiagnosticName:  'diagnostic#2'\n"
+"Message: 'message #2'\n"
+"FileOffset:  60\n"
+"FilePath:path/to/header.h\n"
+"Replacements:\n"
+"  - FilePath:path/to/header.h\n"
+"Offset:  62\n"
+"Length:  2\n"
+"ReplacementText: 'replacement #2'\n"
+"  - DiagnosticName:  'diagnostic#3'\n"
+"Message: 'message #3'\n"
+"FileOffset:  72\n"
+"FilePath:path/to/source2.cpp\n"
+"Replacements:\n"
+"...\n",
+  YamlContentStream.str().c_str());
+}
+
+TEST(DiagnosticsYamlTest, deserializesDiagnostics) {
+std::string YamlContent = "---\n"
+  "MainSourceFile:  path/to/source.cpp\n"
+  "Diagnostics: \n"
+  "  - DiagnosticName:  'diagnostic#1'\n"
+  "Message: 'message #1'\n"
+  "FileOffset:  55\n"
+  "FilePath:path/to/source.cpp\n"
+  "Replacements:\n"
+  "  - FilePath:path/to/source.cpp\n"
+  "Offset:  100\n"
+  "Length:  12\n"
+  "ReplacementText: 'replacement #1'\n"
+  "  - DiagnosticName:  'diagnostic#2'\n"
+  "Message: 'message #2'\n"
+  "FileOffset:  60\n"
+  "FilePath:path/to/header.h\n"
+  "Replacements:\n"
+  "  - FilePath:path/to/header.h\n"
+  "Offset:  62\n"
+  "Length:  2\n"
+  "Replacem

[PATCH] D34404: [Clang-Tidy] Preserve Message, FileOffset, FilePath in Clang-Tidy YAML output

2017-07-05 Thread Vladimir Plyashkun via Phabricator via cfe-commits
vladimir.plyashkun added inline comments.



Comment at: unittests/clang-apply-replacements/ApplyReplacementsTest.cpp:23
+  SmallVector EmptyNotes;
+  return tooling::Diagnostic(DiagnosticName, Message, Replacements, EmptyNotes,
+ tooling::Diagnostic::Warning, BuildDirectory);

alexfh wrote:
> vladimir.plyashkun wrote:
> > alexfh wrote:
> > > alexfh wrote:
> > > > Will `{}` work instead of `EmptyNotes`?
> > > `tooling::` is not needed due to the using directive above. Same below.
> > Unfortunately, no.
> > Constructor expects non-const reference `SmallVector 
> > &Notes`, so i can't pass rvalue directly to it.
> I overlooked this when committing someone's patch. Fixed in r307143. Now you 
> can add `const` and probably also use `{}`.
Thanks, fixed it.


Repository:
  rL LLVM

https://reviews.llvm.org/D34404



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


[PATCH] D34913: [clang-tidy] Add a new Android check "android-cloexec-socket"

2017-07-05 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh requested changes to this revision.
alexfh added inline comments.



Comment at: test/clang-tidy/android-cloexec-socket.cpp:20
+  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: 'socket' should use 
SOCK_CLOEXEC where possible [android-cloexec-socket]
+  // CHECK-FIXES: SOCK_STREAM | SOCK_CLOEXEC
+  TEMP_FAILURE_RETRY(socket(0, SOCK_STREAM, 0));

hokein wrote:
> I'd use the complete statement for checking the fixes here, the same below.
Yes, CHECK-FIXES has fewer context than CHECK-MESSAGES (it doesn't have the 
line number, for example), and there's much more stuff that can go wrong than 
with the static diagnostic messages. So please make CHECK-FIXES as specific, as 
possible. Ideally, they should be unique, so that a wrong line can't be matched 
by a CHECK-FIXES. If needed, add unique comments on identical lines.


Repository:
  rL LLVM

https://reviews.llvm.org/D34913



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


Re: r304207 - Allow for unfinished #if blocks in preambles

2017-07-05 Thread Erik Verbruggen via cfe-commits

> On 30. Jun 2017, at 16:31, Erik Verbruggen via cfe-commits 
>  wrote:
> 
> 
>> On 23. Jun 2017, at 23:54, Richard Smith > > wrote:
>> 
>> On 23 June 2017 at 13:34, Benjamin Kramer via cfe-commits 
>> mailto:cfe-commits@lists.llvm.org>> wrote:
>> Since this change went in I'm seeing spurious errors whenever editing
>> a header file, filed https://bugs.llvm.org/show_bug.cgi?id=33574 
>>  for
>> that.
>> 
>> Does fixing the reversed condition I pointed out fix that?
> 
> Nope. See https://reviews.llvm.org/D34882  
> for a fix that passes the case mentioned in the bug report. I asked Benjamin 
> on IRC if he could test that patch a bit. Will polish it up when it's I know 
> if it introduces more/other problems.

Fix submitted as revision 307134.

-- Erik

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


[PATCH] D33470: [clang-tidy] Add misc-default-numerics

2017-07-05 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: test/clang-tidy/misc-default-numerics.cpp:28
+struct numeric_limits {
+  static int min() { return -1; }
+  static SpecializedType max() { return SpecializedType(); }

This is not a proper specialization according to the standard.

> A program may add a template specialization for any standard library template 
> to namespace std only if the declaration depends on a user-defined type and 
> the specialization meets the standard library requirements for the original 
> template and is not explicitly prohibited.

The functions are not marked `constexpr` or `noexcept`, and `min()` must return 
`SpecializedType`. Also the `is_specialized` member needs to be set to `true`. 
There are other requirements missing as well, but I think fixing the function 
signatures is the only important one.


https://reviews.llvm.org/D33470



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


[PATCH] D34937: Suppressing Reference Counting Diagnostics for Functions Containing 'rc_ownership_trusted_implementation' Annotate Attribute

2017-07-05 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin added a comment.

Thanks for the tests.

Have you tried this on the ISL codebase to make sure it is suppressing the 
diagnostics in related to reference counting implementation that you expect?

I think it would be good to add some tests that reflect the reference counting 
implementation patterns in ISL that you want to make sure not to warn on. Can 
you simplify those patterns to their essence and add them as tests?


Repository:
  rL LLVM

https://reviews.llvm.org/D34937



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


[PATCH] D34937: Suppressing Reference Counting Diagnostics for Functions Containing 'rc_ownership_trusted_implementation' Annotate Attribute

2017-07-05 Thread Malhar Thakkar via Phabricator via cfe-commits
malhar1995 added a comment.

In https://reviews.llvm.org/D34937#799504, @dcoughlin wrote:

> Thanks for the tests.
>
> Have you tried this on the ISL codebase to make sure it is suppressing the 
> diagnostics in related to reference counting implementation that you expect?
>
> I think it would be good to add some tests that reflect the reference 
> counting implementation patterns in ISL that you want to make sure not to 
> warn on. Can you simplify those patterns to their essence and add them as 
> tests?


Although, I have not tried running the new RetainCountChecker on the entire ISL 
codebase, I ran it on small chunks of it and it seemed to be working as 
expected. Also, the test-cases that I have added in my latest patch are indeed 
representative of the reference counting implementation in ISL. Ideally, in 
case of ISL, we don't want the analyzer to analyze the bodies of functions of 
the type obj_free(), obj_cow(), etc. as they result in a large number of 'leak' 
false positives but adding 'rc_ownership_trusted_implementation' annotate 
attribute to just these functions will not do the trick as when warnings are 
raised, these functions are no longer present on the call-stack.

Also, I just realized that I made a mistake with one of the two test-cases that 
I added. I'll fix that ASAP.


Repository:
  rL LLVM

https://reviews.llvm.org/D34937



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


[PATCH] D35012: [refactor] Add the AST source selection component

2017-07-05 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.
Herald added a subscriber: mgorny.

This patch adds the base AST source selection component to the refactoring 
library. AST selection is represented using a tree of `SelectedASTNode` values. 
Each selected node gets its own selection kind, which can actually be `None` 
even in the middle of tree (e.g. statement in a macro whose child is in a macro 
argument). The initial version constructs a "raw" selection tree, without 
applying filters and canonicalisation operations to the nodes.


Repository:
  rL LLVM

https://reviews.llvm.org/D35012

Files:
  include/clang/Tooling/Refactoring/ASTSelection.h
  lib/Tooling/Refactoring/ASTSelection.cpp
  lib/Tooling/Refactoring/CMakeLists.txt
  lib/Tooling/Refactoring/SourceLocationUtils.h
  unittests/Tooling/ASTSelectionTest.cpp
  unittests/Tooling/CMakeLists.txt

Index: unittests/Tooling/CMakeLists.txt
===
--- unittests/Tooling/CMakeLists.txt
+++ unittests/Tooling/CMakeLists.txt
@@ -11,6 +11,7 @@
 endif()
 
 add_clang_unittest(ToolingTests
+  ASTSelectionTest.cpp
   CastExprTest.cpp
   CommentHandlerTest.cpp
   CompilationDatabaseTest.cpp
Index: unittests/Tooling/ASTSelectionTest.cpp
===
--- /dev/null
+++ unittests/Tooling/ASTSelectionTest.cpp
@@ -0,0 +1,432 @@
+//===- unittest/Tooling/ASTSelectionTest.cpp --===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "TestVisitor.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Refactoring/ASTSelection.h"
+
+using namespace clang;
+using namespace tooling;
+
+namespace {
+
+struct FileLocation {
+  unsigned Line, Column;
+
+  SourceLocation translate(const SourceManager &SM) {
+return SM.translateLineCol(SM.getMainFileID(), Line, Column);
+  }
+};
+
+using FileRange = std::pair;
+
+class SelectionFinderVisitor : public TestVisitor {
+  FileLocation Location;
+  Optional SelectionRange;
+
+public:
+  Optional Selection;
+
+  SelectionFinderVisitor(FileLocation Location,
+ Optional SelectionRange)
+  : Location(Location), SelectionRange(SelectionRange) {}
+
+  bool VisitTranslationUnitDecl(const TranslationUnitDecl *TU) {
+const ASTContext &Context = TU->getASTContext();
+const SourceManager &SM = Context.getSourceManager();
+
+SourceRange SelRange;
+if (SelectionRange) {
+  SelRange = SourceRange(SelectionRange->first.translate(SM),
+ SelectionRange->second.translate(SM));
+}
+Selection = findSelectedASTNodes(Context, Location.translate(SM), SelRange);
+return false;
+  }
+};
+
+Optional
+findSelectedASTNodes(StringRef Source, FileLocation Location,
+ Optional SelectionRange,
+ SelectionFinderVisitor::Language Language =
+ SelectionFinderVisitor::Lang_CXX11) {
+  SelectionFinderVisitor Visitor(Location, SelectionRange);
+  EXPECT_TRUE(Visitor.runOver(Source, Language));
+  return std::move(Visitor.Selection);
+}
+
+void checkNodeImpl(bool IsTypeMatched, const SelectedASTNode &Node,
+   SourceSelectionKind SelectionKind, unsigned NumChildren) {
+  ASSERT_TRUE(IsTypeMatched);
+  EXPECT_EQ(Node.Children.size(), NumChildren);
+  ASSERT_EQ(Node.SelectionKind, SelectionKind);
+}
+
+void checkDeclName(const SelectedASTNode &Node, StringRef Name) {
+  const auto *ND = Node.Node.get();
+  EXPECT_TRUE(!!ND);
+  ASSERT_EQ(ND->getName(), Name);
+}
+
+template 
+const SelectedASTNode &
+checkNode(const SelectedASTNode &StmtNode, SourceSelectionKind SelectionKind,
+  unsigned NumChildren = 0,
+  typename std::enable_if::value, T>::type
+  *StmtOverloadChecker = nullptr) {
+  checkNodeImpl(isa(StmtNode.Node.get()), StmtNode, SelectionKind,
+NumChildren);
+  return StmtNode;
+}
+
+template 
+const SelectedASTNode &
+checkNode(const SelectedASTNode &DeclNode, SourceSelectionKind SelectionKind,
+  unsigned NumChildren = 0, StringRef Name = "",
+  typename std::enable_if::value, T>::type
+  *DeclOverloadChecker = nullptr) {
+  checkNodeImpl(isa(DeclNode.Node.get()), DeclNode, SelectionKind,
+NumChildren);
+  if (!Name.empty())
+checkDeclName(DeclNode, Name);
+  return DeclNode;
+}
+
+struct ForAllChildrenOf {
+  const SelectedASTNode &Node;
+
+  static void childKindVerifier(const SelectedASTNode &Node,
+SourceSelectionKind SelectionKind) {
+for (const SelectedASTNode &Child : Node.Children) {
+  ASSERT_EQ(Node.SelectionKind, SelectionKind);
+  childKindVerifier(Child, SelectionKind);
+}
+  }
+
+public:
+ 

[PATCH] D35012: [refactor] Add the AST source selection component

2017-07-05 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 105269.
arphaman added a comment.

A a test-case for implicit declarations.


Repository:
  rL LLVM

https://reviews.llvm.org/D35012

Files:
  include/clang/Tooling/Refactoring/ASTSelection.h
  lib/Tooling/Refactoring/ASTSelection.cpp
  lib/Tooling/Refactoring/CMakeLists.txt
  lib/Tooling/Refactoring/SourceLocationUtils.h
  unittests/Tooling/ASTSelectionTest.cpp
  unittests/Tooling/CMakeLists.txt

Index: unittests/Tooling/CMakeLists.txt
===
--- unittests/Tooling/CMakeLists.txt
+++ unittests/Tooling/CMakeLists.txt
@@ -11,6 +11,7 @@
 endif()
 
 add_clang_unittest(ToolingTests
+  ASTSelectionTest.cpp
   CastExprTest.cpp
   CommentHandlerTest.cpp
   CompilationDatabaseTest.cpp
Index: unittests/Tooling/ASTSelectionTest.cpp
===
--- /dev/null
+++ unittests/Tooling/ASTSelectionTest.cpp
@@ -0,0 +1,453 @@
+//===- unittest/Tooling/ASTSelectionTest.cpp --===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "TestVisitor.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Refactoring/ASTSelection.h"
+
+using namespace clang;
+using namespace tooling;
+
+namespace {
+
+struct FileLocation {
+  unsigned Line, Column;
+
+  SourceLocation translate(const SourceManager &SM) {
+return SM.translateLineCol(SM.getMainFileID(), Line, Column);
+  }
+};
+
+using FileRange = std::pair;
+
+class SelectionFinderVisitor : public TestVisitor {
+  FileLocation Location;
+  Optional SelectionRange;
+
+public:
+  Optional Selection;
+
+  SelectionFinderVisitor(FileLocation Location,
+ Optional SelectionRange)
+  : Location(Location), SelectionRange(SelectionRange) {}
+
+  bool VisitTranslationUnitDecl(const TranslationUnitDecl *TU) {
+const ASTContext &Context = TU->getASTContext();
+const SourceManager &SM = Context.getSourceManager();
+
+SourceRange SelRange;
+if (SelectionRange) {
+  SelRange = SourceRange(SelectionRange->first.translate(SM),
+ SelectionRange->second.translate(SM));
+}
+Selection = findSelectedASTNodes(Context, Location.translate(SM), SelRange);
+return false;
+  }
+};
+
+Optional
+findSelectedASTNodes(StringRef Source, FileLocation Location,
+ Optional SelectionRange,
+ SelectionFinderVisitor::Language Language =
+ SelectionFinderVisitor::Lang_CXX11) {
+  SelectionFinderVisitor Visitor(Location, SelectionRange);
+  EXPECT_TRUE(Visitor.runOver(Source, Language));
+  return std::move(Visitor.Selection);
+}
+
+void checkNodeImpl(bool IsTypeMatched, const SelectedASTNode &Node,
+   SourceSelectionKind SelectionKind, unsigned NumChildren) {
+  ASSERT_TRUE(IsTypeMatched);
+  EXPECT_EQ(Node.Children.size(), NumChildren);
+  ASSERT_EQ(Node.SelectionKind, SelectionKind);
+}
+
+void checkDeclName(const SelectedASTNode &Node, StringRef Name) {
+  const auto *ND = Node.Node.get();
+  EXPECT_TRUE(!!ND);
+  ASSERT_EQ(ND->getName(), Name);
+}
+
+template 
+const SelectedASTNode &
+checkNode(const SelectedASTNode &StmtNode, SourceSelectionKind SelectionKind,
+  unsigned NumChildren = 0,
+  typename std::enable_if::value, T>::type
+  *StmtOverloadChecker = nullptr) {
+  checkNodeImpl(isa(StmtNode.Node.get()), StmtNode, SelectionKind,
+NumChildren);
+  return StmtNode;
+}
+
+template 
+const SelectedASTNode &
+checkNode(const SelectedASTNode &DeclNode, SourceSelectionKind SelectionKind,
+  unsigned NumChildren = 0, StringRef Name = "",
+  typename std::enable_if::value, T>::type
+  *DeclOverloadChecker = nullptr) {
+  checkNodeImpl(isa(DeclNode.Node.get()), DeclNode, SelectionKind,
+NumChildren);
+  if (!Name.empty())
+checkDeclName(DeclNode, Name);
+  return DeclNode;
+}
+
+struct ForAllChildrenOf {
+  const SelectedASTNode &Node;
+
+  static void childKindVerifier(const SelectedASTNode &Node,
+SourceSelectionKind SelectionKind) {
+for (const SelectedASTNode &Child : Node.Children) {
+  ASSERT_EQ(Node.SelectionKind, SelectionKind);
+  childKindVerifier(Child, SelectionKind);
+}
+  }
+
+public:
+  ForAllChildrenOf(const SelectedASTNode &Node) : Node(Node) {}
+
+  void shouldHaveSelectionKind(SourceSelectionKind Kind) {
+childKindVerifier(Node, Kind);
+  }
+};
+
+ForAllChildrenOf allChildrenOf(const SelectedASTNode &Node) {
+  return ForAllChildrenOf(Node);
+}
+
+TEST(ASTSelectionFinder, CursorNoSelection) {
+  Optional Node =
+  findSelectedASTNodes(" void f() { }", {1, 1}, None);
+  EXPE

[PATCH] D34404: [Clang-Tidy] Preserve Message, FileOffset, FilePath in Clang-Tidy YAML output

2017-07-05 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

A few more nits.




Comment at: unittests/Tooling/DiagnosticsYamlTest.cpp:39
+
+  StringMap Fix1{
+{ "path/to/source.cpp", Replacements(Replacement("path/to/source.cpp", 100,

The assignment form of initialization is clearer for containers (and actually 
any type for which the initialization means "this variable is whatever is on 
the right side of the assignment" as opposed to "this variable is initialized 
by a constructor call taking these parameters").



Comment at: unittests/Tooling/DiagnosticsYamlTest.cpp:60
+
+  EXPECT_STREQ("---\n"
+"MainSourceFile:  path/to/source.cpp\n"

Why not EXPECT_EQ (and remove `.c_str()` from the second argument)?



Comment at: unittests/clang-apply-replacements/ApplyReplacementsTest.cpp:27
+  TU.MainSourceFile = MainSourceFile;
+  TU.Diagnostics.push_back(Diagnostic(DiagnosticName, Message, Replacements, 
{}, 
+  Diagnostic::Warning, BuildDirectory));

I believe, this can be expressed a bit less verbosely, e.g. `TUs.push_back({ 
MainSourceFile, {Diagnostic(...)}});`.


Repository:
  rL LLVM

https://reviews.llvm.org/D34404



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


[PATCH] D34404: [Clang-Tidy] Preserve Message, FileOffset, FilePath in Clang-Tidy YAML output

2017-07-05 Thread Vladimir Plyashkun via Phabricator via cfe-commits
vladimir.plyashkun added a comment.

Thanks, Alex for your suggestions.
I agree with your remarks, but i thought it's only style preferences.
I'll fix it soon.


Repository:
  rL LLVM

https://reviews.llvm.org/D34404



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


[PATCH] D34170: [libcxx] Moving compiler specific test infrastructure to compiler.py

2017-07-05 Thread Ben Craig via Phabricator via cfe-commits
bcraig updated this revision to Diff 105268.
bcraig added a comment.

Rebased.
Separating out logging into it's own class.
Also tweaked the output slightly so that the language dialect under test shows 
up as the first line of output.


https://reviews.llvm.org/D34170

Files:
  test/lit.cfg
  utils/libcxx/compiler.py
  utils/libcxx/test/config.py
  utils/libcxx/test/format.py
  utils/libcxx/test/target_info.py
  utils/libcxx/util.py

Index: utils/libcxx/util.py
===
--- utils/libcxx/util.py
+++ utils/libcxx/util.py
@@ -16,7 +16,50 @@
 import sys
 import tempfile
 import threading
-
+import inspect
+
+class Logger:
+def __init__(self):
+self._notes = []
+self._flushing = False
+
+def _write_message(self, kind, message):
+# Get the file/line where this message was generated.
+f = inspect.currentframe()
+# Step out of _write_message, and then out of wrapper.
+f = f.f_back.f_back
+file,line,_,_,_ = inspect.getframeinfo(f)
+location = '%s:%d' % (file, line)
+
+sys.stderr.write('%s: %s: %s\n' % (location, kind, message))
+
+def note(self, message):
+sys.stderr.write('%s\n' % (message))
+
+def deferred_note(self, message):
+if self._flushing:
+self._write_message('note', message)
+else:
+self._notes.append(message)
+
+def flush_notes(self):
+for note in self._notes:
+self._write_message('note', note)
+_flushing = True
+
+def warning(self, message):
+self._write_message('warning', message)
+self.numWarnings += 1
+
+def error(self, message):
+self._write_message('error', message)
+self.numErrors += 1
+
+def fatal(self, message):
+self._write_message('fatal', message)
+sys.exit(2)
+
+lit_logger = Logger()
 
 # FIXME: Most of these functions are cribbed from LIT
 def to_bytes(str):
Index: utils/libcxx/test/target_info.py
===
--- utils/libcxx/test/target_info.py
+++ utils/libcxx/test/target_info.py
@@ -14,6 +14,7 @@
 import re
 import subprocess
 import sys
+from libcxx.util import lit_logger
 
 class DefaultTargetInfo(object):
 def __init__(self, full_config):
@@ -23,7 +24,7 @@
 return sys.platform.lower().strip()
 
 def add_locale_features(self, features):
-self.full_config.lit_config.warning(
+lit_logger.warning(
 "No locales entry for target_system: %s" % self.platform())
 
 def add_cxx_compile_flags(self, flags): pass
@@ -46,7 +47,7 @@
 locale.setlocale(locale.LC_ALL, default_locale)
 
 
-def add_common_locales(features, lit_config, is_windows=False):
+def add_common_locales(features, is_windows=False):
 # A list of locales needed by the test-suite.
 # The list uses the canonical name for the locale used in the test-suite
 # TODO: On Linux ISO8859 *may* needs to hyphenated.
@@ -63,7 +64,7 @@
 if test_locale(loc_name):
 features.add('locale.{0}'.format(loc_id))
 else:
-lit_config.warning('The locale {0} is not supported by '
+lit_logger.warning('The locale {0} is not supported by '
'your platform. Some tests will be '
'unsupported.'.format(loc_name))
 
@@ -92,7 +93,7 @@
 pass
 
 if not out:
-self.full_config.lit_config.fatal(
+lit_logger.fatal(
 "cannot infer sdk version with: %r" % cmd)
 
 return re.sub(r'.*/[^0-9]+([0-9.]+)\.sdk', r'\1', out)
@@ -119,7 +120,7 @@
 return (True, name, version)
 
 def add_locale_features(self, features):
-add_common_locales(features, self.full_config.lit_config)
+add_common_locales(features)
 
 def add_cxx_compile_flags(self, flags):
 if self.full_config.use_deployment:
@@ -134,7 +135,7 @@
 res = -1
 if res == 0 and out:
 sdk_path = out
-self.full_config.lit_config.note('using SDKROOT: %r' % sdk_path)
+lit_logger.deferred_note('using SDKROOT: %r' % sdk_path)
 flags += ["-isysroot", sdk_path]
 
 def add_cxx_link_flags(self, flags):
@@ -179,7 +180,7 @@
 super(FreeBSDLocalTI, self).__init__(full_config)
 
 def add_locale_features(self, features):
-add_common_locales(features, self.full_config.lit_config)
+add_common_locales(features)
 
 def add_cxx_link_flags(self, flags):
 flags += ['-lc', '-lm', '-lpthread', '-lgcc_s', '-lcxxrt']
@@ -203,7 +204,7 @@
 return ver # Permitted to be None.
 
 def add_locale_features(self, features):
-add_common_locales(features, self.full_config.lit_config)
+add_common_locales(features)
 # Some linux distributions have different locale data than others.
 # Insert

[PATCH] D34824: clang-format: add an option -verbose to list the files being processed

2017-07-05 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added inline comments.



Comment at: tools/clang-format/ClangFormat.cpp:380
+if (Verbose.getNumOccurrences() != 0)
+outs() << "Formatting " << FileNames[0] << '\n';
 break;

djasper wrote:
> As clang-format often returns the result on stdout, maybe it'd be better to 
> use errs() here?
Right, otherwise, this:
clang-format -verbose foo.cpp > bar.cpp
won't work


https://reviews.llvm.org/D34824



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


[PATCH] D31326: Add option to export fixes to run-clang-tidy.py

2017-07-05 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh requested changes to this revision.
alexfh added inline comments.
This revision now requires changes to proceed.



Comment at: run-clang-tidy.py:49
+import yaml
+import glob
 

Please sort the imports



Comment at: run-clang-tidy.py:99
+  content = yaml.safe_load(f)
+  if not content: continue # Skip empty files
+

Please put `continue` on the next line.



Comment at: run-clang-tidy.py:105
+  elif merged['MainSourceFile'] != content['MainSourceFile']:
+# The values given for MainSourceFile are inconsistent.
+# Just empty MainSourceFile blank:

This is going to be the case for each non-trivial invocation of this script. Do 
we need to keep `MainSourceFile` at all?



Comment at: run-clang-tidy.py:242
+print 'Writing fixes to ' + args.export_fixes
+merge_replacement_files(tmpdir,args.export_fixes)
+

nit: Add a space after the comma.


https://reviews.llvm.org/D31326



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


[PATCH] D34440: [Clang] Expand response files before loading compilation database

2017-07-05 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh requested changes to this revision.
alexfh added inline comments.
This revision now requires changes to proceed.



Comment at: lib/Tooling/CommonOptionsParser.cpp:120
+  
+  // Expand response files before loading compilation database from command 
line
+  SmallVector newArgv(argv, argv + argc);

Add a trailing period, please.



Comment at: unittests/Tooling/CompilationDatabaseTest.cpp:638-652
+  ParseCompilationDatabaseFromResponseFileTest() {
+std::error_code EC = llvm::sys::fs::createUniqueDirectory("unittest", 
TestDir);
+EXPECT_TRUE(!EC);
+llvm::sys::path::append(ResponseFileName, TestDir, "resp");
+  }
+  void setResponseFileContent(const std::string &content) {
+std::ofstream File(ResponseFileName.c_str());

Can we do all this in the virtual file system 
(include/clang/Basic/VirtualFileSystem.h) to avoid creating files from the unit 
test?


Repository:
  rL LLVM

https://reviews.llvm.org/D34440



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


[PATCH] D34888: [OpenMP] Fix mapping of scalars for combined directives

2017-07-05 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea added a comment.

Does this also include the fixes in the following revision?

https://reviews.llvm.org/D29905


Repository:
  rL LLVM

https://reviews.llvm.org/D34888



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


[PATCH] D34936: [clangd] Add -ffreestanding on VFS tests.

2017-07-05 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a comment.

Thanks so much!


Repository:
  rL LLVM

https://reviews.llvm.org/D34936



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


[PATCH] D34170: [libcxx] Moving compiler specific test infrastructure to compiler.py

2017-07-05 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

I'll try and get to this tonight.


https://reviews.llvm.org/D34170



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


[PATCH] D34992: Emit static constexpr member as available_externally definition

2017-07-05 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Does this apply to all constexpr global variables? It could potentially fix 
https://bugs.llvm.org/show_bug.cgi?id=31860 .


https://reviews.llvm.org/D34992



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


  1   2   3   >