[PATCH] D31760: [lsan] Enable LSan on arm Linux, clang part

2017-04-07 Thread Maxim Ostapenko via Phabricator via cfe-commits
m.ostapenko updated this revision to Diff 94489.
m.ostapenko added a comment.

Also check for thumb.


Repository:
  rL LLVM

https://reviews.llvm.org/D31760

Files:
  lib/Driver/ToolChains/Linux.cpp
  test/Driver/fsanitize.c


Index: test/Driver/fsanitize.c
===
--- test/Driver/fsanitize.c
+++ test/Driver/fsanitize.c
@@ -237,6 +237,18 @@
 // RUN: %clang -target i686-linux-gnu -fsanitize=address,leak 
-fno-sanitize=address %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANA-SANL-NO-SANA-X86
 // CHECK-SANA-SANL-NO-SANA-X86: "-fsanitize=leak"
 
+// RUN: %clang -target arm-linux-gnu -fsanitize=leak %s -### 2>&1 | FileCheck 
%s --check-prefix=CHECK-SANL-ARM
+// CHECK-SANL-ARM: "-fsanitize=leak"
+
+// RUN: %clang -target arm-linux-gnu -fsanitize=address,leak 
-fno-sanitize=address %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANA-SANL-NO-SANA-ARM
+// CHECK-SANA-SANL-NO-SANA-ARM: "-fsanitize=leak"
+
+// RUN: %clang -target thumb-linux -fsanitize=leak %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANL-THUMB
+// CHECK-SANL-THUMB: "-fsanitize=leak"
+
+// RUN: %clang -target thumb-linux -fsanitize=address,leak 
-fno-sanitize=address %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-SANA-SANL-NO-SANA-THUMB
+// CHECK-SANA-SANL-NO-SANA-THUMB: "-fsanitize=leak"
+
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=memory %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-MSAN
 // CHECK-MSAN: "-fno-assume-sane-operator-new"
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-ASAN
Index: lib/Driver/ToolChains/Linux.cpp
===
--- lib/Driver/ToolChains/Linux.cpp
+++ lib/Driver/ToolChains/Linux.cpp
@@ -864,14 +864,16 @@
getTriple().getArch() == llvm::Triple::ppc64le;
   const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64 ||
  getTriple().getArch() == llvm::Triple::aarch64_be;
+  const bool IsArmArch =
+  getTriple().getArch() == llvm::Triple::arm || llvm::Triple::thumb;
   SanitizerMask Res = ToolChain::getSupportedSanitizers();
   Res |= SanitizerKind::Address;
   Res |= SanitizerKind::KernelAddress;
   Res |= SanitizerKind::Vptr;
   Res |= SanitizerKind::SafeStack;
   if (IsX86_64 || IsMIPS64 || IsAArch64)
 Res |= SanitizerKind::DataFlow;
-  if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86)
+  if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86 || IsArmArch)
 Res |= SanitizerKind::Leak;
   if (IsX86_64 || IsMIPS64 || IsAArch64 || IsPowerPC64)
 Res |= SanitizerKind::Thread;


Index: test/Driver/fsanitize.c
===
--- test/Driver/fsanitize.c
+++ test/Driver/fsanitize.c
@@ -237,6 +237,18 @@
 // RUN: %clang -target i686-linux-gnu -fsanitize=address,leak -fno-sanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANA-SANL-NO-SANA-X86
 // CHECK-SANA-SANL-NO-SANA-X86: "-fsanitize=leak"
 
+// RUN: %clang -target arm-linux-gnu -fsanitize=leak %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANL-ARM
+// CHECK-SANL-ARM: "-fsanitize=leak"
+
+// RUN: %clang -target arm-linux-gnu -fsanitize=address,leak -fno-sanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANA-SANL-NO-SANA-ARM
+// CHECK-SANA-SANL-NO-SANA-ARM: "-fsanitize=leak"
+
+// RUN: %clang -target thumb-linux -fsanitize=leak %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANL-THUMB
+// CHECK-SANL-THUMB: "-fsanitize=leak"
+
+// RUN: %clang -target thumb-linux -fsanitize=address,leak -fno-sanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANA-SANL-NO-SANA-THUMB
+// CHECK-SANA-SANL-NO-SANA-THUMB: "-fsanitize=leak"
+
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=memory %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MSAN
 // CHECK-MSAN: "-fno-assume-sane-operator-new"
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN
Index: lib/Driver/ToolChains/Linux.cpp
===
--- lib/Driver/ToolChains/Linux.cpp
+++ lib/Driver/ToolChains/Linux.cpp
@@ -864,14 +864,16 @@
getTriple().getArch() == llvm::Triple::ppc64le;
   const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64 ||
  getTriple().getArch() == llvm::Triple::aarch64_be;
+  const bool IsArmArch =
+  getTriple().getArch() == llvm::Triple::arm || llvm::Triple::thumb;
   SanitizerMask Res = ToolChain::getSupportedSanitizers();
   Res |= SanitizerKind::Address;
   Res |= SanitizerKind::KernelAddress;
   Res |= SanitizerKind::Vptr;
   Res |= SanitizerKind::SafeStack;
   if (IsX86_64 || IsMIPS64 || IsAArch64)
 Res |= SanitizerKind::DataFlow;
-  if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86)
+  if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86 || IsArmArch)
 Res |= Sani

[PATCH] D30739: [OpenMP] "declare simd" for AArch64 Advanced SIMD.

2017-04-07 Thread Francesco Petrogalli via Phabricator via cfe-commits
fpetrogalli added a comment.

Alexey,

thank you for reviewing this. If you don't mind, I will wait applying the 
changes you requested, Unfortunately I am not ready yet to send out an update 
as I am still working on the vector ABI. I will ping you when ready.

Francesco


https://reviews.llvm.org/D30739



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


[PATCH] D31746: Remove ASTUnits for closed documents and cache CompilationDatabase per directory in clangd.

2017-04-07 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 94492.
ilya-biryukov added a comment.

Minor fixes.
Fixed variable name issues and comment spelling errors.


https://reviews.llvm.org/D31746

Files:
  clangd/ASTManager.cpp
  clangd/ASTManager.h
  clangd/ClangDMain.cpp
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/ProtocolHandlers.cpp
  clangd/ProtocolHandlers.h

Index: clangd/ProtocolHandlers.h
===
--- clangd/ProtocolHandlers.h
+++ clangd/ProtocolHandlers.h
@@ -75,6 +75,16 @@
   DocumentStore &Store;
 };
 
+struct TextDocumentDidCloseHandler : Handler {
+  TextDocumentDidCloseHandler(JSONOutput &Output, DocumentStore &Store)
+  : Handler(Output), Store(Store) {}
+
+  void handleNotification(llvm::yaml::MappingNode *Params) override;
+
+private:
+  DocumentStore &Store;
+};
+
 struct TextDocumentOnTypeFormattingHandler : Handler {
   TextDocumentOnTypeFormattingHandler(JSONOutput &Output, DocumentStore &Store)
   : Handler(Output), Store(Store) {}
Index: clangd/ProtocolHandlers.cpp
===
--- clangd/ProtocolHandlers.cpp
+++ clangd/ProtocolHandlers.cpp
@@ -24,6 +24,17 @@
   Store.addDocument(DOTDP->textDocument.uri, DOTDP->textDocument.text);
 }
 
+void TextDocumentDidCloseHandler::handleNotification(
+llvm::yaml::MappingNode *Params) {
+  auto DCTDP = DidCloseTextDocumentParams::parse(Params);
+  if (!DCTDP) {
+Output.log("Failed to decode DidCloseTextDocumentParams!\n");
+return;
+  }
+
+  Store.removeDocument(DCTDP->textDocument.uri);
+}
+
 void TextDocumentDidChangeHandler::handleNotification(
 llvm::yaml::MappingNode *Params) {
   auto DCTDP = DidChangeTextDocumentParams::parse(Params);
@@ -159,7 +170,7 @@
   std::string Code = AST.getStore().getDocument(CAP->textDocument.uri);
   std::string Commands;
   for (Diagnostic &D : CAP->context.diagnostics) {
-std::vector Fixes = AST.getFixIts(D);
+std::vector Fixes = AST.getFixIts(CAP->textDocument.uri, D);
 std::string Edits = replacementsToEdits(Code, Fixes);
 
 if (!Edits.empty())
Index: clangd/Protocol.h
===
--- clangd/Protocol.h
+++ clangd/Protocol.h
@@ -113,6 +113,14 @@
   parse(llvm::yaml::MappingNode *Params);
 };
 
+struct DidCloseTextDocumentParams {
+  /// The document that was closed.
+  TextDocumentIdentifier textDocument;
+
+  static llvm::Optional
+  parse(llvm::yaml::MappingNode *Params);
+};
+
 struct TextDocumentContentChangeEvent {
   /// The new text of the document.
   std::string text;
Index: clangd/Protocol.cpp
===
--- clangd/Protocol.cpp
+++ clangd/Protocol.cpp
@@ -227,6 +227,33 @@
   return Result;
 }
 
+llvm::Optional
+DidCloseTextDocumentParams::parse(llvm::yaml::MappingNode *Params) {
+  DidCloseTextDocumentParams 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();
+
+if (KeyValue == "textDocument") {
+  auto *Map = dyn_cast(Value);
+  if (!Map)
+return llvm::None;
+  auto Parsed = TextDocumentIdentifier::parse(Map);
+  if (!Parsed)
+return llvm::None;
+  Result.textDocument = std::move(*Parsed);
+} else {
+  return llvm::None;
+}
+  }
+  return Result;
+}
+
 llvm::Optional
 DidChangeTextDocumentParams::parse(llvm::yaml::MappingNode *Params) {
   DidChangeTextDocumentParams Result;
Index: clangd/ClangDMain.cpp
===
--- clangd/ClangDMain.cpp
+++ clangd/ClangDMain.cpp
@@ -46,7 +46,9 @@
   Dispatcher.registerHandler(
   "textDocument/didOpen",
   llvm::make_unique(Out, Store));
-  // FIXME: Implement textDocument/didClose.
+  Dispatcher.registerHandler(
+  "textDocument/didClose",
+  llvm::make_unique(Out, Store));
   Dispatcher.registerHandler(
   "textDocument/didChange",
   llvm::make_unique(Out, Store));
Index: clangd/ASTManager.h
===
--- clangd/ASTManager.h
+++ clangd/ASTManager.h
@@ -29,27 +29,64 @@
 
 namespace clangd {
 
+/// Using 'unsigned' here to avoid undefined behaviour on overflow.
+typedef unsigned DocVersion;
+
+/// Stores ASTUnit and FixIts map for an opened document
+class DocData {
+public:
+  typedef std::map>
+  DiagnosticToReplacementMap;
+
+public:
+  void setAST(std::unique_ptr AST);
+  ASTUnit *getAST() const;
+
+  void cacheFixIts(DiagnosticToReplacementMap FixIts);
+  std::vector
+  getFixIts(const clangd::Diagnostic &D) const;
+
+private:
+  std::unique_ptr AST;
+  DiagnosticToReplacementMap FixIts;
+};
+
+enum class ASTManagerRequestType { ParseAndPublishDiagnostics, RemoveDo

[PATCH] D31746: Remove ASTUnits for closed documents and cache CompilationDatabase per directory in clangd.

2017-04-07 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 94494.
ilya-biryukov added a comment.

Moved locking of ClangObjectLock into request handlers.


https://reviews.llvm.org/D31746

Files:
  clangd/ASTManager.cpp
  clangd/ASTManager.h
  clangd/ClangDMain.cpp
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/ProtocolHandlers.cpp
  clangd/ProtocolHandlers.h

Index: clangd/ProtocolHandlers.h
===
--- clangd/ProtocolHandlers.h
+++ clangd/ProtocolHandlers.h
@@ -75,6 +75,16 @@
   DocumentStore &Store;
 };
 
+struct TextDocumentDidCloseHandler : Handler {
+  TextDocumentDidCloseHandler(JSONOutput &Output, DocumentStore &Store)
+  : Handler(Output), Store(Store) {}
+
+  void handleNotification(llvm::yaml::MappingNode *Params) override;
+
+private:
+  DocumentStore &Store;
+};
+
 struct TextDocumentOnTypeFormattingHandler : Handler {
   TextDocumentOnTypeFormattingHandler(JSONOutput &Output, DocumentStore &Store)
   : Handler(Output), Store(Store) {}
Index: clangd/ProtocolHandlers.cpp
===
--- clangd/ProtocolHandlers.cpp
+++ clangd/ProtocolHandlers.cpp
@@ -24,6 +24,17 @@
   Store.addDocument(DOTDP->textDocument.uri, DOTDP->textDocument.text);
 }
 
+void TextDocumentDidCloseHandler::handleNotification(
+llvm::yaml::MappingNode *Params) {
+  auto DCTDP = DidCloseTextDocumentParams::parse(Params);
+  if (!DCTDP) {
+Output.log("Failed to decode DidCloseTextDocumentParams!\n");
+return;
+  }
+
+  Store.removeDocument(DCTDP->textDocument.uri);
+}
+
 void TextDocumentDidChangeHandler::handleNotification(
 llvm::yaml::MappingNode *Params) {
   auto DCTDP = DidChangeTextDocumentParams::parse(Params);
@@ -159,7 +170,7 @@
   std::string Code = AST.getStore().getDocument(CAP->textDocument.uri);
   std::string Commands;
   for (Diagnostic &D : CAP->context.diagnostics) {
-std::vector Fixes = AST.getFixIts(D);
+std::vector Fixes = AST.getFixIts(CAP->textDocument.uri, D);
 std::string Edits = replacementsToEdits(Code, Fixes);
 
 if (!Edits.empty())
Index: clangd/Protocol.h
===
--- clangd/Protocol.h
+++ clangd/Protocol.h
@@ -113,6 +113,14 @@
   parse(llvm::yaml::MappingNode *Params);
 };
 
+struct DidCloseTextDocumentParams {
+  /// The document that was closed.
+  TextDocumentIdentifier textDocument;
+
+  static llvm::Optional
+  parse(llvm::yaml::MappingNode *Params);
+};
+
 struct TextDocumentContentChangeEvent {
   /// The new text of the document.
   std::string text;
Index: clangd/Protocol.cpp
===
--- clangd/Protocol.cpp
+++ clangd/Protocol.cpp
@@ -227,6 +227,33 @@
   return Result;
 }
 
+llvm::Optional
+DidCloseTextDocumentParams::parse(llvm::yaml::MappingNode *Params) {
+  DidCloseTextDocumentParams 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();
+
+if (KeyValue == "textDocument") {
+  auto *Map = dyn_cast(Value);
+  if (!Map)
+return llvm::None;
+  auto Parsed = TextDocumentIdentifier::parse(Map);
+  if (!Parsed)
+return llvm::None;
+  Result.textDocument = std::move(*Parsed);
+} else {
+  return llvm::None;
+}
+  }
+  return Result;
+}
+
 llvm::Optional
 DidChangeTextDocumentParams::parse(llvm::yaml::MappingNode *Params) {
   DidChangeTextDocumentParams Result;
Index: clangd/ClangDMain.cpp
===
--- clangd/ClangDMain.cpp
+++ clangd/ClangDMain.cpp
@@ -46,7 +46,9 @@
   Dispatcher.registerHandler(
   "textDocument/didOpen",
   llvm::make_unique(Out, Store));
-  // FIXME: Implement textDocument/didClose.
+  Dispatcher.registerHandler(
+  "textDocument/didClose",
+  llvm::make_unique(Out, Store));
   Dispatcher.registerHandler(
   "textDocument/didChange",
   llvm::make_unique(Out, Store));
Index: clangd/ASTManager.h
===
--- clangd/ASTManager.h
+++ clangd/ASTManager.h
@@ -29,27 +29,64 @@
 
 namespace clangd {
 
+/// Using 'unsigned' here to avoid undefined behaviour on overflow.
+typedef unsigned DocVersion;
+
+/// Stores ASTUnit and FixIts map for an opened document
+class DocData {
+public:
+  typedef std::map>
+  DiagnosticToReplacementMap;
+
+public:
+  void setAST(std::unique_ptr AST);
+  ASTUnit *getAST() const;
+
+  void cacheFixIts(DiagnosticToReplacementMap FixIts);
+  std::vector
+  getFixIts(const clangd::Diagnostic &D) const;
+
+private:
+  std::unique_ptr AST;
+  DiagnosticToReplacementMap FixIts;
+};
+
+enum class ASTManagerRequestType { ParseAndPublishDiagnostics, RemoveDocData };
+
+/

[PATCH] D31746: Remove ASTUnits for closed documents and cache CompilationDatabase per directory in clangd.

2017-04-07 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov marked 3 inline comments as done.
ilya-biryukov added a comment.

Addressed the locking comments. Locking inside the request handlers looks much 
nicer indeed.




Comment at: clangd/ASTManager.cpp:203
+  // TODO(ibiryukov): at this point DocDatasLock can be unlocked in 
asynchronous
+  // mode
 

krasimir wrote:
> Why not make the locking explicit here and don't require `handleRequest` and 
> `parseFileAndPublishDiagnostics` to be called under a lock?
Good point, my initial attempt was aimed at avoiding locking when 
RunSynchronously is true. But that's not a very useful constraint.


https://reviews.llvm.org/D31746



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


[PATCH] D31746: Remove ASTUnits for closed documents and cache CompilationDatabase per directory in clangd.

2017-04-07 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov marked an inline comment as done.
ilya-biryukov added a comment.

Regarding the testing. It looks like we have two ways of testing this:

1. Add clangd-specific protocol handlers that output useful stats(i.e. 
currently opened documents), use those in tests.
2. Add unit tests that emulate the protocol actions and run the checks in C++.

Option 1 seems preferable, we could probably use the 'workspace/executeCommand' 
for that.


https://reviews.llvm.org/D31746



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


[PATCH] D30777: Added `applyAtomicChanges` function.

2017-04-07 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 94497.
ioeric added a comment.
Herald added a subscriber: mgorny.

- Try to unbreak buildbots after r298913.
- Add clangFormat to dependency
- Update cmake


https://reviews.llvm.org/D30777

Files:
  include/clang/Tooling/Refactoring/AtomicChange.h
  lib/Tooling/Refactoring/AtomicChange.cpp
  lib/Tooling/Refactoring/CMakeLists.txt
  unittests/Tooling/RefactoringTest.cpp

Index: unittests/Tooling/RefactoringTest.cpp
===
--- unittests/Tooling/RefactoringTest.cpp
+++ unittests/Tooling/RefactoringTest.cpp
@@ -1291,5 +1291,427 @@
   Replacement(Context.Sources, SourceLocation(), 0, "b")));
 }
 
+class ApplyAtomicChangesTest : public ::testing::Test {
+protected:
+  ApplyAtomicChangesTest() : FilePath("file.cc") {
+Spec.Cleanup = true;
+Spec.Format = ApplyChangesSpec::kAll;
+Spec.Style = format::getLLVMStyle();
+  }
+
+  ~ApplyAtomicChangesTest() override {}
+
+  void setInput(llvm::StringRef Input) {
+Code = Input;
+FID = Context.createInMemoryFile(FilePath, Code);
+  }
+
+  SourceLocation getLoc(unsigned Offset) const {
+return Context.Sources.getLocForStartOfFile(FID).getLocWithOffset(Offset);
+  }
+
+  AtomicChange replacementToAtomicChange(llvm::StringRef Key, unsigned Offset,
+ unsigned Length,
+ llvm::StringRef Text) {
+AtomicChange Change(FilePath, Key);
+llvm::Error Err =
+Change.replace(Context.Sources, getLoc(Offset), Length, Text);
+EXPECT_FALSE(Err);
+return Change;
+  }
+
+  std::string rewrite(bool FailureExpected = false) {
+llvm::Expected ChangedCode =
+applyAtomicChanges(FilePath, Code, Changes, Spec);
+EXPECT_EQ(FailureExpected, !ChangedCode);
+if (!ChangedCode) {
+  llvm::errs() << "Failed to apply changes: "
+   << llvm::toString(ChangedCode.takeError()) << "\n";
+  return "";
+}
+return *ChangedCode;
+  }
+
+  RewriterTestContext Context;
+  FileID FID;
+  ApplyChangesSpec Spec;
+  std::string Code;
+  std::string FilePath;
+  llvm::SmallVector Changes;
+};
+
+TEST_F(ApplyAtomicChangesTest, BasicRefactoring) {
+  setInput("int a;");
+  AtomicChange Change(FilePath, "key1");
+  Changes.push_back(replacementToAtomicChange("key1", 4, 1, "b"));
+  EXPECT_EQ("int b;", rewrite());
+}
+
+TEST_F(ApplyAtomicChangesTest, SeveralRefactorings) {
+  setInput("int a;\n"
+   "int b;");
+  Changes.push_back(replacementToAtomicChange("key1", 0, 3, "float"));
+  Changes.push_back(replacementToAtomicChange("key2", 4, 1, "f"));
+  Changes.push_back(replacementToAtomicChange("key3", 11, 1, "g"));
+  Changes.push_back(replacementToAtomicChange("key4", 7, 3, "float"));
+  EXPECT_EQ("float f;\n"
+"float g;",
+rewrite());
+}
+
+TEST_F(ApplyAtomicChangesTest, IgnorePathsInRefactorings) {
+  setInput("int a;\n"
+   "int b;");
+  Changes.push_back(replacementToAtomicChange("key1", 4, 1, "aa"));
+
+  FileID ID = Context.createInMemoryFile("AnotherFile", "12345678912345");
+  Changes.emplace_back("AnotherFile", "key2");
+  auto Err = Changes.back().replace(
+  Context.Sources,
+  Context.Sources.getLocForStartOfFile(ID).getLocWithOffset(11), 1, "bb");
+  ASSERT_TRUE(!Err);
+  EXPECT_EQ("int aa;\n"
+"int bb;",
+rewrite());
+}
+
+TEST_F(ApplyAtomicChangesTest, AppliesDuplicateInsertions) {
+  setInput("int a;");
+  Changes.push_back(replacementToAtomicChange("key1", 5, 0, "b"));
+  Changes.push_back(replacementToAtomicChange("key2", 5, 0, "b"));
+  EXPECT_EQ("int abb;", rewrite());
+}
+
+TEST_F(ApplyAtomicChangesTest, BailsOnOverlappingRefactorings) {
+  setInput("int a;");
+  Changes.push_back(replacementToAtomicChange("key1", 0, 5, "float f"));
+  Changes.push_back(replacementToAtomicChange("key2", 4, 1, "b"));
+  EXPECT_EQ("", rewrite(/*FailureExpected=*/true));
+}
+
+TEST_F(ApplyAtomicChangesTest, BasicReformatting) {
+  setInput("int  a;");
+  Changes.push_back(replacementToAtomicChange("key1", 5, 1, "b"));
+  EXPECT_EQ("int b;", rewrite());
+}
+
+TEST_F(ApplyAtomicChangesTest, OnlyFormatWhenViolateColumnLimits) {
+  Spec.Format = ApplyChangesSpec::kViolations;
+  Spec.Style.ColumnLimit = 8;
+  setInput("int  a;\n"
+   "inta;\n"
+   "int  ;\n");
+  Changes.push_back(replacementToAtomicChange("key1", 5, 1, "x"));
+  Changes.push_back(replacementToAtomicChange("key2", 15, 1, "x"));
+  Changes.push_back(replacementToAtomicChange("key3", 23, 8, "xx"));
+  EXPECT_EQ("int  x;\n"
+"int x;\n"
+"int  xx;\n",
+rewrite());
+}
+
+TEST_F(ApplyAtomicChangesTest, LastLineViolateColumnLimits) {
+  Spec.Format = ApplyChangesSpec::kViolations;
+  Spec.Style.ColumnLimit = 8;
+  setInput("int  a;\n"
+   "inta;");
+  Changes.push_back(replacementToAtomicChange("key1", 0, 1, "i"));
+  Changes.push_back(replacement

[PATCH] D30777: Added `applyAtomicChanges` function.

2017-04-07 Thread Eric Liu via Phabricator via cfe-commits
ioeric reopened this revision.
ioeric added a comment.
This revision is now accepted and ready to land.

This (https://reviews.llvm.org/rL298913) was reverted upstream due to cyclic 
dependency on GreenDragon bot. Investigating...


Repository:
  rL LLVM

https://reviews.llvm.org/D30777



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


[PATCH] D31765: Skip Unicode character expansion in assembly files

2017-04-07 Thread Oliver Stannard via Phabricator via cfe-commits
olista01 added a comment.

The change itself looks fine, but I have a few comments on the test.

Tests of clang shouldn't actually run the assembler, as I think this one will 
fail if clang is built without the ARM backend. A better way to write the test 
would be to just run the preprocessor, and check that the occurrences of \u 
make it through unmodified.

You should also be able to use clang's -verify option to check the diagnostics, 
so that you don't need a dummy warning to avoid empty FileCheck input. Grep for 
expected-no-diagnostics in the existing tests for examples of this.


https://reviews.llvm.org/D31765



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


[PATCH] D31757: [clang-tidy] Add a clang-tidy check for possible inefficient vector operations

2017-04-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 94498.
hokein marked an inline comment as done.
hokein added a comment.

Mention the check in Release note.


https://reviews.llvm.org/D31757

Files:
  clang-tidy/performance/CMakeLists.txt
  clang-tidy/performance/InefficientVectorOperationCheck.cpp
  clang-tidy/performance/InefficientVectorOperationCheck.h
  clang-tidy/performance/PerformanceTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/performance-inefficient-vector-operation.rst
  test/clang-tidy/performance-inefficient-vector-operation.cpp

Index: test/clang-tidy/performance-inefficient-vector-operation.cpp
===
--- /dev/null
+++ test/clang-tidy/performance-inefficient-vector-operation.cpp
@@ -0,0 +1,102 @@
+// RUN: %check_clang_tidy %s performance-inefficient-vector-operation %t -- -format-style=llvm --
+
+typedef int size_t;
+
+namespace std {
+template 
+class vector {
+ public:
+  typedef T* iterator;
+  typedef const T* const_iterator;
+  typedef T& reference;
+  typedef const T& const_reference;
+  typedef size_t size_type;
+
+  explicit vector();
+  explicit vector(size_type n);
+
+  void push_back(const T& val);
+  void reserve(size_t n);
+  size_t size();
+  const_reference operator[] (size_type) const;
+  reference operator[] (size_type);
+};
+} // namespace std
+
+void f(std::vector& t) {
+  {
+std::vector v;
+// CHECK-FIXES: v.reserve(10);
+for (int i = 0; i < 10; ++i)
+  v.push_back(i);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: push_back is called inside a loop; consider pre-allocating the vector capacity before the loop
+  }
+  {
+std::vector v;
+// CHECK-FIXES: v.reserve(t.size());
+for (size_t i = 0; i < t.size(); ++i) {
+  v.push_back(t[i]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: push_back is called
+}
+  }
+  {
+std::vector v;
+// CHECK-FIXES: v.reserve(t.size() - 1);
+for (size_t i = 0; i < t.size() - 1; ++i) {
+  v.push_back(t[i]);
+} // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: push_back is called
+  }
+
+  //  Non-fixed Cases 
+  {
+std::vector v;
+v.reserve(20);
+// CHECK-FIXES-NOT: v.reserve(10);
+// There is a "reserve" call already.
+for (int i = 0; i < 10; ++i) {
+  v.push_back(i);
+}
+  }
+  {
+std::vector v(20);
+// CHECK-FIXES-NOT: v.reserve(10);
+// v is not constructed with default constructor.
+for (int i = 0; i < 10; ++i) {
+  v.push_back(i);
+}
+  }
+  {
+std::vector v;
+// CHECK-FIXES-NOT: v.reserve(10);
+// For-loop is not started with 0.
+for (int i = 1; i < 10; ++i) {
+  v.push_back(i);
+}
+  }
+  {
+std::vector v;
+// CHECK-FIXES-NOT: v.reserve(t.size());
+// v isn't referenced in for-loop body.
+for (size_t i = 0; i < t.size(); ++i) {
+  t.push_back(i);
+}
+  }
+  {
+std::vector v;
+int k;
+// CHECK-FIXES-NOT: v.reserve(10);
+// For-loop isn't a fixable loop.
+for (size_t i = 0; k < 10; ++i) {
+  v.push_back(t[i]);
+}
+  }
+  {
+std::vector v;
+int k;
+// CHECK-FIXES-NOT: v.reserve(10);
+// For-loop isn't a fixable loop.
+for (size_t i = 0; i < 10; ++k) {
+  v.push_back(t[i]);
+}
+  }
+}
Index: docs/clang-tidy/checks/performance-inefficient-vector-operation.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/performance-inefficient-vector-operation.rst
@@ -0,0 +1,17 @@
+.. title:: clang-tidy - performance-inefficient-vector-operation
+
+performance-inefficient-vector-operation
+
+
+Finds possible inefficient `std::vector` operations (e.g. `push_back`) that may
+cause unnecessary memory reallocations.
+
+.. code-block:: c++
+
+  std::vector v;
+  for (int i = 0; i < n; ++i) {
+v.push_back(n);
+// This will trigger the warning since the push_back may cause multiple
+// memory reallocations in v. This can be avoid by inserting a reserve(n)
+// statment before the for statment.
+  }
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -141,6 +141,7 @@
performance-for-range-copy
performance-implicit-cast-in-loop
performance-inefficient-string-concatenation
+   performance-inefficient-vector-operation
performance-type-promotion-in-math-fn
performance-unnecessary-copy-initialization
performance-unnecessary-value-param
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -62,7 +62,7 @@
 
   Finds modification of the ``std`` or ``posix`` namespace.
 
-- Improved `cppcoreguidelines-no-malloc 
+- Improved `cppcoreguidelines-no-malloc
   

[PATCH] D31757: [clang-tidy] Add a clang-tidy check for possible inefficient vector operations

2017-04-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In https://reviews.llvm.org/D31757#720351, @Eugene.Zelenko wrote:

> Isn't such analysis is path-sensitive and should be implemented in Static 
> Analyzer?


This check is more like a flow-sensitive analysis IMO, which can be supported 
by clang-tidy.

> Please mention this check in docs/ReleaseNotes.rst (in alphabetical order).

Done. I think we could add this tip in the `add_new_check.py` script, so that 
developers don't forget about it ;)


https://reviews.llvm.org/D31757



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


[clang-tools-extra] r299752 - [clang-tidy] A couple of minor fixes in modernize-use-using tests

2017-04-07 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Fri Apr  7 04:41:27 2017
New Revision: 299752

URL: http://llvm.org/viewvc/llvm-project?rev=299752&view=rev
Log:
[clang-tidy] A couple of minor fixes in modernize-use-using tests

Modified:
clang-tools-extra/trunk/test/clang-tidy/modernize-use-using-macros.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-use-using.cpp

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-using-macros.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-using-macros.cpp?rev=299752&r1=299751&r2=299752&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-using-macros.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-using-macros.cpp Fri 
Apr  7 04:41:27 2017
@@ -1,6 +1,6 @@
 // RUN: %check_clang_tidy %s modernize-use-using %t -- \
 // RUN:   -config="{CheckOptions: [{key: modernize-use-using.IgnoreMacros, 
value: 0}]}" \
-// RUN:   -- -std=c++11 -I %S/Inputs/modernize-use-using
+// RUN:   -- -std=c++11
 
 #define CODE typedef int INT
 

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-using.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-using.cpp?rev=299752&r1=299751&r2=299752&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-using.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-using.cpp Fri Apr  7 
04:41:27 2017
@@ -155,8 +155,9 @@ namespace my_space {
 }
 
 #define lol 4
-typedef unsigned Map[lol]; 
+typedef unsigned Map[lol];
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
+// CHECK-FIXES: typedef unsigned Map[lol];
 
 typedef void (*fun_type)();
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'


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


[PATCH] D31765: Skip Unicode character expansion in assembly files

2017-04-07 Thread Salman Arif via Phabricator via cfe-commits
salari01 updated this revision to Diff 94501.
salari01 added a comment.

Updated test to check preprocessed output instead of the assembled file. Cannot 
use `-verify` with the driver, but with `-E` and `-o -`, there is no longer a 
need to have the dummy warning to avoid the FileCheck error.


https://reviews.llvm.org/D31765

Files:
  lib/Lex/Lexer.cpp
  test/Lexer/asm-preproc-no-unicode.s


Index: test/Lexer/asm-preproc-no-unicode.s
===
--- /dev/null
+++ test/Lexer/asm-preproc-no-unicode.s
@@ -0,0 +1,8 @@
+// RUN: %clang -E -xassembler-with-cpp %s -o - 2>&1 | FileCheck %s
+
+// CHECK-NOT: warning: \u used with no following hex digits
+// CHECK: .word \u
+
+.macro foo, u
+.word \u
+.endm
Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -3603,17 +3603,19 @@
 
   // UCNs (C99 6.4.3, C++11 [lex.charset]p2)
   case '\\':
-if (uint32_t CodePoint = tryReadUCN(CurPtr, BufferPtr, &Result)) {
-  if (CheckUnicodeWhitespace(Result, CodePoint, CurPtr)) {
-if (SkipWhitespace(Result, CurPtr, TokAtPhysicalStartOfLine))
-  return true; // KeepWhitespaceMode
+if (!LangOpts.AsmPreprocessor) {
+  if (uint32_t CodePoint = tryReadUCN(CurPtr, BufferPtr, &Result)) {
+if (CheckUnicodeWhitespace(Result, CodePoint, CurPtr)) {
+  if (SkipWhitespace(Result, CurPtr, TokAtPhysicalStartOfLine))
+return true; // KeepWhitespaceMode
+
+  // We only saw whitespace, so just try again with this lexer.
+  // (We manually eliminate the tail call to avoid recursion.)
+  goto LexNextToken;
+}
 
-// We only saw whitespace, so just try again with this lexer.
-// (We manually eliminate the tail call to avoid recursion.)
-goto LexNextToken;
+return LexUnicode(Result, CodePoint, CurPtr);
   }
-
-  return LexUnicode(Result, CodePoint, CurPtr);
 }
 
 Kind = tok::unknown;


Index: test/Lexer/asm-preproc-no-unicode.s
===
--- /dev/null
+++ test/Lexer/asm-preproc-no-unicode.s
@@ -0,0 +1,8 @@
+// RUN: %clang -E -xassembler-with-cpp %s -o - 2>&1 | FileCheck %s
+
+// CHECK-NOT: warning: \u used with no following hex digits
+// CHECK: .word \u
+
+.macro foo, u
+.word \u
+.endm
Index: lib/Lex/Lexer.cpp
===
--- lib/Lex/Lexer.cpp
+++ lib/Lex/Lexer.cpp
@@ -3603,17 +3603,19 @@
 
   // UCNs (C99 6.4.3, C++11 [lex.charset]p2)
   case '\\':
-if (uint32_t CodePoint = tryReadUCN(CurPtr, BufferPtr, &Result)) {
-  if (CheckUnicodeWhitespace(Result, CodePoint, CurPtr)) {
-if (SkipWhitespace(Result, CurPtr, TokAtPhysicalStartOfLine))
-  return true; // KeepWhitespaceMode
+if (!LangOpts.AsmPreprocessor) {
+  if (uint32_t CodePoint = tryReadUCN(CurPtr, BufferPtr, &Result)) {
+if (CheckUnicodeWhitespace(Result, CodePoint, CurPtr)) {
+  if (SkipWhitespace(Result, CurPtr, TokAtPhysicalStartOfLine))
+return true; // KeepWhitespaceMode
+
+  // We only saw whitespace, so just try again with this lexer.
+  // (We manually eliminate the tail call to avoid recursion.)
+  goto LexNextToken;
+}
 
-// We only saw whitespace, so just try again with this lexer.
-// (We manually eliminate the tail call to avoid recursion.)
-goto LexNextToken;
+return LexUnicode(Result, CodePoint, CurPtr);
   }
-
-  return LexUnicode(Result, CodePoint, CurPtr);
 }
 
 Kind = tok::unknown;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31765: Skip Unicode character expansion in assembly files

2017-04-07 Thread Oliver Stannard via Phabricator via cfe-commits
olista01 accepted this revision.
olista01 added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D31765



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


[PATCH] D26794: [OpenCL] Blocks are allowed to capture arrays in OpenCL 2.0 and higher.

2017-04-07 Thread Egor Churaev via Phabricator via cfe-commits
echuraev added a comment.

Yes, I have an access to the new revision and I have read it.


https://reviews.llvm.org/D26794



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


[PATCH] D26794: [OpenCL] Blocks are allowed to capture arrays in OpenCL 2.0 and higher.

2017-04-07 Thread Egor Churaev via Phabricator via cfe-commits
echuraev updated this revision to Diff 94503.
echuraev marked an inline comment as done.

https://reviews.llvm.org/D26794

Files:
  lib/Sema/SemaExpr.cpp
  test/SemaOpenCL/blocks_with_array.cl


Index: test/SemaOpenCL/blocks_with_array.cl
===
--- /dev/null
+++ test/SemaOpenCL/blocks_with_array.cl
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -O0 -fblocks -triple spir64-unkown-unkown -emit-llvm %s -o 
-| FileCheck %s
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple spir64-unkown-unkown -emit-llvm 
%s -o -| FileCheck %s
+
+typedef int (^block_t)();
+
+int block_typedef_kernel(global int* res) {
+  int a[3] = {1, 2, 3};
+  block_t b = ^() {
+// CHECK:   %{{.*}} = getelementptr inbounds [3 x i32], [3 x i32] 
addrspace(4)* %{{.*}}, i64 0, i64 0
+return a[0];
+  };
+  return b();
+}
+
+// CHECK: define spir_func void @foo()
+void foo() {
+  struct v {
+int arr[2];
+  } s = {0, 1};
+  block_t bl1 = ^(){return s.arr[1];};
+// CHECK: define internal spir_func i32 @__foo_block_invoke(i8 addrspace(4)* 
%.block_descriptor)
+// CHECK:   %{{.*}} = getelementptr inbounds %struct.v, %struct.v 
addrspace(4)* %{{.*}}, i32 0, i32 0
+// CHECK:   %{{.*}} = getelementptr inbounds [2 x i32], [2 x i32] 
addrspace(4)* %{{.*}}, i64 0, i64 1
+  // array content copied into captured struct location
+  int arr[2] = {0, 1};
+  block_t bl2 = ^(){return arr[1];};
+// CHECK: define internal spir_func i32 @__foo_block_invoke_2(i8 addrspace(4)* 
%.block_descriptor)
+// CHECK:   %{{.*}} = getelementptr inbounds [2 x i32], [2 x i32] 
addrspace(4)* %{{.*}}, i64 0, i64 1
+  // array decayed to pointer while captured
+  s.arr[1] = arr[1] = 877;
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -13643,7 +13643,7 @@
   bool ByRef = false;
   
   // Blocks are not allowed to capture arrays.
-  if (CaptureType->isArrayType()) {
+  if (!S.getLangOpts().OpenCL && CaptureType->isArrayType()) {
 if (BuildAndDiagnose) {
   S.Diag(Loc, diag::err_ref_array_type);
   S.Diag(Var->getLocation(), diag::note_previous_decl) 


Index: test/SemaOpenCL/blocks_with_array.cl
===
--- /dev/null
+++ test/SemaOpenCL/blocks_with_array.cl
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -O0 -fblocks -triple spir64-unkown-unkown -emit-llvm %s -o -| FileCheck %s
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple spir64-unkown-unkown -emit-llvm %s -o -| FileCheck %s
+
+typedef int (^block_t)();
+
+int block_typedef_kernel(global int* res) {
+  int a[3] = {1, 2, 3};
+  block_t b = ^() {
+// CHECK:   %{{.*}} = getelementptr inbounds [3 x i32], [3 x i32] addrspace(4)* %{{.*}}, i64 0, i64 0
+return a[0];
+  };
+  return b();
+}
+
+// CHECK: define spir_func void @foo()
+void foo() {
+  struct v {
+int arr[2];
+  } s = {0, 1};
+  block_t bl1 = ^(){return s.arr[1];};
+// CHECK: define internal spir_func i32 @__foo_block_invoke(i8 addrspace(4)* %.block_descriptor)
+// CHECK:   %{{.*}} = getelementptr inbounds %struct.v, %struct.v addrspace(4)* %{{.*}}, i32 0, i32 0
+// CHECK:   %{{.*}} = getelementptr inbounds [2 x i32], [2 x i32] addrspace(4)* %{{.*}}, i64 0, i64 1
+  // array content copied into captured struct location
+  int arr[2] = {0, 1};
+  block_t bl2 = ^(){return arr[1];};
+// CHECK: define internal spir_func i32 @__foo_block_invoke_2(i8 addrspace(4)* %.block_descriptor)
+// CHECK:   %{{.*}} = getelementptr inbounds [2 x i32], [2 x i32] addrspace(4)* %{{.*}}, i64 0, i64 1
+  // array decayed to pointer while captured
+  s.arr[1] = arr[1] = 877;
+}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -13643,7 +13643,7 @@
   bool ByRef = false;
   
   // Blocks are not allowed to capture arrays.
-  if (CaptureType->isArrayType()) {
+  if (!S.getLangOpts().OpenCL && CaptureType->isArrayType()) {
 if (BuildAndDiagnose) {
   S.Diag(Loc, diag::err_ref_array_type);
   S.Diag(Var->getLocation(), diag::note_previous_decl) 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31805: [clang-tidy] Mention "add the check to release note" in add_new_check.py.

2017-04-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.

https://reviews.llvm.org/D31805

Files:
  clang-tidy/add_new_check.py


Index: clang-tidy/add_new_check.py
===
--- clang-tidy/add_new_check.py
+++ clang-tidy/add_new_check.py
@@ -304,6 +304,8 @@
   write_docs(module_path, module, check_name)
   update_checks_list(clang_tidy_path)
   print('Done. Now it\'s your turn!')
+  print('Please remember to mention this check in docs/ReleaseNotes.rst '
+'(in alphabetical order).')
 
 
 if __name__ == '__main__':


Index: clang-tidy/add_new_check.py
===
--- clang-tidy/add_new_check.py
+++ clang-tidy/add_new_check.py
@@ -304,6 +304,8 @@
   write_docs(module_path, module, check_name)
   update_checks_list(clang_tidy_path)
   print('Done. Now it\'s your turn!')
+  print('Please remember to mention this check in docs/ReleaseNotes.rst '
+'(in alphabetical order).')
 
 
 if __name__ == '__main__':
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r299754 - Skip Unicode character expansion in assembly files

2017-04-07 Thread Sanne Wouda via cfe-commits
Author: sanwou01
Date: Fri Apr  7 05:13:00 2017
New Revision: 299754

URL: http://llvm.org/viewvc/llvm-project?rev=299754&view=rev
Log:
Skip Unicode character expansion in assembly files

Summary: When using the C preprocessor with assembly files, either with a
capital `S` file extension, or with `-xassembler-with-cpp`, the Unicode escape
sequence `\u` is ignored. The `\u` pattern can be used for expanding a macro
argument that starts with `u`.

Author: Salman Arif 

Reviewers: rengolin, olista01

Reviewed By: olista01

Subscribers: cfe-commits

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

Added:
cfe/trunk/test/Lexer/asm-preproc-no-unicode.s
Modified:
cfe/trunk/lib/Lex/Lexer.cpp

Modified: cfe/trunk/lib/Lex/Lexer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=299754&r1=299753&r2=299754&view=diff
==
--- cfe/trunk/lib/Lex/Lexer.cpp (original)
+++ cfe/trunk/lib/Lex/Lexer.cpp Fri Apr  7 05:13:00 2017
@@ -3603,17 +3603,19 @@ LexNextToken:
 
   // UCNs (C99 6.4.3, C++11 [lex.charset]p2)
   case '\\':
-if (uint32_t CodePoint = tryReadUCN(CurPtr, BufferPtr, &Result)) {
-  if (CheckUnicodeWhitespace(Result, CodePoint, CurPtr)) {
-if (SkipWhitespace(Result, CurPtr, TokAtPhysicalStartOfLine))
-  return true; // KeepWhitespaceMode
+if (!LangOpts.AsmPreprocessor) {
+  if (uint32_t CodePoint = tryReadUCN(CurPtr, BufferPtr, &Result)) {
+if (CheckUnicodeWhitespace(Result, CodePoint, CurPtr)) {
+  if (SkipWhitespace(Result, CurPtr, TokAtPhysicalStartOfLine))
+return true; // KeepWhitespaceMode
 
-// We only saw whitespace, so just try again with this lexer.
-// (We manually eliminate the tail call to avoid recursion.)
-goto LexNextToken;
-  }
+  // We only saw whitespace, so just try again with this lexer.
+  // (We manually eliminate the tail call to avoid recursion.)
+  goto LexNextToken;
+}
 
-  return LexUnicode(Result, CodePoint, CurPtr);
+return LexUnicode(Result, CodePoint, CurPtr);
+  }
 }
 
 Kind = tok::unknown;

Added: cfe/trunk/test/Lexer/asm-preproc-no-unicode.s
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/asm-preproc-no-unicode.s?rev=299754&view=auto
==
--- cfe/trunk/test/Lexer/asm-preproc-no-unicode.s (added)
+++ cfe/trunk/test/Lexer/asm-preproc-no-unicode.s Fri Apr  7 05:13:00 2017
@@ -0,0 +1,8 @@
+// RUN: %clang -E -xassembler-with-cpp %s -o - 2>&1 | FileCheck %s
+
+// CHECK-NOT: warning: \u used with no following hex digits
+// CHECK: .word \u
+
+.macro foo, u
+.word \u
+.endm


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


[PATCH] D31765: Skip Unicode character expansion in assembly files

2017-04-07 Thread Sanne Wouda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL299754: Skip Unicode character expansion in assembly files 
(authored by sanwou01).

Changed prior to commit:
  https://reviews.llvm.org/D31765?vs=94501&id=94505#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D31765

Files:
  cfe/trunk/lib/Lex/Lexer.cpp
  cfe/trunk/test/Lexer/asm-preproc-no-unicode.s


Index: cfe/trunk/lib/Lex/Lexer.cpp
===
--- cfe/trunk/lib/Lex/Lexer.cpp
+++ cfe/trunk/lib/Lex/Lexer.cpp
@@ -3603,17 +3603,19 @@
 
   // UCNs (C99 6.4.3, C++11 [lex.charset]p2)
   case '\\':
-if (uint32_t CodePoint = tryReadUCN(CurPtr, BufferPtr, &Result)) {
-  if (CheckUnicodeWhitespace(Result, CodePoint, CurPtr)) {
-if (SkipWhitespace(Result, CurPtr, TokAtPhysicalStartOfLine))
-  return true; // KeepWhitespaceMode
+if (!LangOpts.AsmPreprocessor) {
+  if (uint32_t CodePoint = tryReadUCN(CurPtr, BufferPtr, &Result)) {
+if (CheckUnicodeWhitespace(Result, CodePoint, CurPtr)) {
+  if (SkipWhitespace(Result, CurPtr, TokAtPhysicalStartOfLine))
+return true; // KeepWhitespaceMode
+
+  // We only saw whitespace, so just try again with this lexer.
+  // (We manually eliminate the tail call to avoid recursion.)
+  goto LexNextToken;
+}
 
-// We only saw whitespace, so just try again with this lexer.
-// (We manually eliminate the tail call to avoid recursion.)
-goto LexNextToken;
+return LexUnicode(Result, CodePoint, CurPtr);
   }
-
-  return LexUnicode(Result, CodePoint, CurPtr);
 }
 
 Kind = tok::unknown;
Index: cfe/trunk/test/Lexer/asm-preproc-no-unicode.s
===
--- cfe/trunk/test/Lexer/asm-preproc-no-unicode.s
+++ cfe/trunk/test/Lexer/asm-preproc-no-unicode.s
@@ -0,0 +1,8 @@
+// RUN: %clang -E -xassembler-with-cpp %s -o - 2>&1 | FileCheck %s
+
+// CHECK-NOT: warning: \u used with no following hex digits
+// CHECK: .word \u
+
+.macro foo, u
+.word \u
+.endm


Index: cfe/trunk/lib/Lex/Lexer.cpp
===
--- cfe/trunk/lib/Lex/Lexer.cpp
+++ cfe/trunk/lib/Lex/Lexer.cpp
@@ -3603,17 +3603,19 @@
 
   // UCNs (C99 6.4.3, C++11 [lex.charset]p2)
   case '\\':
-if (uint32_t CodePoint = tryReadUCN(CurPtr, BufferPtr, &Result)) {
-  if (CheckUnicodeWhitespace(Result, CodePoint, CurPtr)) {
-if (SkipWhitespace(Result, CurPtr, TokAtPhysicalStartOfLine))
-  return true; // KeepWhitespaceMode
+if (!LangOpts.AsmPreprocessor) {
+  if (uint32_t CodePoint = tryReadUCN(CurPtr, BufferPtr, &Result)) {
+if (CheckUnicodeWhitespace(Result, CodePoint, CurPtr)) {
+  if (SkipWhitespace(Result, CurPtr, TokAtPhysicalStartOfLine))
+return true; // KeepWhitespaceMode
+
+  // We only saw whitespace, so just try again with this lexer.
+  // (We manually eliminate the tail call to avoid recursion.)
+  goto LexNextToken;
+}
 
-// We only saw whitespace, so just try again with this lexer.
-// (We manually eliminate the tail call to avoid recursion.)
-goto LexNextToken;
+return LexUnicode(Result, CodePoint, CurPtr);
   }
-
-  return LexUnicode(Result, CodePoint, CurPtr);
 }
 
 Kind = tok::unknown;
Index: cfe/trunk/test/Lexer/asm-preproc-no-unicode.s
===
--- cfe/trunk/test/Lexer/asm-preproc-no-unicode.s
+++ cfe/trunk/test/Lexer/asm-preproc-no-unicode.s
@@ -0,0 +1,8 @@
+// RUN: %clang -E -xassembler-with-cpp %s -o - 2>&1 | FileCheck %s
+
+// CHECK-NOT: warning: \u used with no following hex digits
+// CHECK: .word \u
+
+.macro foo, u
+.word \u
+.endm
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r299758 - [clangd] Extract FsPath from file:// uri

2017-04-07 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Fri Apr  7 06:03:26 2017
New Revision: 299758

URL: http://llvm.org/viewvc/llvm-project?rev=299758&view=rev
Log:
[clangd] Extract FsPath from file:// uri

Patch contributed by stanionascu!

rfc8089#appendix-E.2 specifies that paths can begin with a drive letter e.g. as 
file:///c:/.
In this case just consuming front file:// is not enough and the 3rd slash must 
be consumed to produce a valid path on windows.

The patch introduce a generic way of converting an uri to a filesystem path and 
back.

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

Modified:
clang-tools-extra/trunk/clangd/ASTManager.cpp
clang-tools-extra/trunk/clangd/ASTManager.h
clang-tools-extra/trunk/clangd/DocumentStore.h
clang-tools-extra/trunk/clangd/Protocol.cpp
clang-tools-extra/trunk/clangd/Protocol.h
clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts

Modified: clang-tools-extra/trunk/clangd/ASTManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ASTManager.cpp?rev=299758&r1=299757&r2=299758&view=diff
==
--- clang-tools-extra/trunk/clangd/ASTManager.cpp (original)
+++ clang-tools-extra/trunk/clangd/ASTManager.cpp Fri Apr  7 06:03:26 2017
@@ -28,7 +28,6 @@ getRemappedFiles(const DocumentStore &Do
   std::vector RemappedFiles;
   for (const auto &P : Docs.getAllDocuments()) {
 StringRef FileName = P.first;
-FileName.consume_front("file://");
 RemappedFiles.push_back(ASTUnit::RemappedFile(
 FileName,
 llvm::MemoryBuffer::getMemBufferCopy(P.second, FileName).release()));
@@ -142,7 +141,7 @@ void ASTManager::parseFileAndPublishDiag
 Diagnostics.pop_back(); // Drop trailing comma.
   Output.writeMessage(
   
R"({"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":")"
 +
-  File + R"(","diagnostics":[)" + Diagnostics + R"(]}})");
+  URI::fromFile(File).uri + R"(","diagnostics":[)" + Diagnostics + 
R"(]}})");
 }
 
 ASTManager::~ASTManager() {
@@ -155,42 +154,39 @@ ASTManager::~ASTManager() {
   ClangWorker.join();
 }
 
-void ASTManager::onDocumentAdd(StringRef Uri) {
+void ASTManager::onDocumentAdd(StringRef File) {
   if (RunSynchronously) {
-parseFileAndPublishDiagnostics(Uri);
+parseFileAndPublishDiagnostics(File);
 return;
   }
   std::lock_guard Guard(RequestLock);
   // Currently we discard all pending requests and just enqueue the latest one.
   RequestQueue.clear();
-  RequestQueue.push_back(Uri);
+  RequestQueue.push_back(File);
   ClangRequestCV.notify_one();
 }
 
 tooling::CompilationDatabase *
-ASTManager::getOrCreateCompilationDatabaseForFile(StringRef Uri) {
-  auto &I = CompilationDatabases[Uri];
+ASTManager::getOrCreateCompilationDatabaseForFile(StringRef File) {
+  auto &I = CompilationDatabases[File];
   if (I)
 return I.get();
 
-  Uri.consume_front("file://");
-
   std::string Error;
-  I = tooling::CompilationDatabase::autoDetectFromSource(Uri, Error);
+  I = tooling::CompilationDatabase::autoDetectFromSource(File, Error);
   Output.log("Failed to load compilation database: " + Twine(Error) + "\n");
   return I.get();
 }
 
 std::unique_ptr
-ASTManager::createASTUnitForFile(StringRef Uri, const DocumentStore &Docs) {
+ASTManager::createASTUnitForFile(StringRef File, const DocumentStore &Docs) {
   tooling::CompilationDatabase *CDB =
-  getOrCreateCompilationDatabaseForFile(Uri);
+  getOrCreateCompilationDatabaseForFile(File);
 
-  Uri.consume_front("file://");
   std::vector Commands;
 
   if (CDB) {
-Commands = CDB->getCompileCommands(Uri);
+Commands = CDB->getCompileCommands(File);
 // chdir. This is thread hostile.
 if (!Commands.empty())
   llvm::sys::fs::set_current_path(Commands.front().Directory);
@@ -198,8 +194,8 @@ ASTManager::createASTUnitForFile(StringR
   if (Commands.empty()) {
 // Add a fake command line if we know nothing.
 Commands.push_back(tooling::CompileCommand(
-llvm::sys::path::parent_path(Uri), llvm::sys::path::filename(Uri),
-{"clang", "-fsyntax-only", Uri.str()}, ""));
+llvm::sys::path::parent_path(File), llvm::sys::path::filename(File),
+{"clang", "-fsyntax-only", File.str()}, ""));
   }
 
   // Inject the resource dir.
@@ -278,7 +274,7 @@ public:
 } // namespace
 
 std::vector
-ASTManager::codeComplete(StringRef Uri, unsigned Line, unsigned Column) {
+ASTManager::codeComplete(StringRef File, unsigned Line, unsigned Column) {
   CodeCompleteOptions CCO;
   CCO.IncludeBriefComments = 1;
   // This is where code completion stores dirty buffers. Need to free after
@@ -290,15 +286,13 @@ ASTManager::codeComplete(StringRef Uri,
   std::vector Items;
   CompletionItemsCollector Collector(&Items, CCO);
   std::lock_guard Guard(ASTLock);
-  auto &Unit = ASTs[Uri];
+  auto &Unit = ASTs[File];
   if (!Unit)
-Unit = createAS

[PATCH] D31401: [clangd] Extract FsPath from file:// uri

2017-04-07 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL299758: [clangd] Extract FsPath from file:// uri (authored 
by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D31401?vs=94271&id=94507#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D31401

Files:
  clang-tools-extra/trunk/clangd/ASTManager.cpp
  clang-tools-extra/trunk/clangd/ASTManager.h
  clang-tools-extra/trunk/clangd/DocumentStore.h
  clang-tools-extra/trunk/clangd/Protocol.cpp
  clang-tools-extra/trunk/clangd/Protocol.h
  clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
  clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/extension.ts

Index: clang-tools-extra/trunk/clangd/ASTManager.h
===
--- clang-tools-extra/trunk/clangd/ASTManager.h
+++ clang-tools-extra/trunk/clangd/ASTManager.h
@@ -34,7 +34,7 @@
   ASTManager(JSONOutput &Output, DocumentStore &Store, bool RunSynchronously);
   ~ASTManager() override;
 
-  void onDocumentAdd(StringRef Uri) override;
+  void onDocumentAdd(StringRef File) override;
   // FIXME: Implement onDocumentRemove
 
   /// Get code completions at a specified \p Line and \p Column in \p File.
@@ -61,21 +61,21 @@
   // asynchronously.
   bool RunSynchronously;
 
-  /// Loads a compilation database for URI. May return nullptr if it fails. The
+  /// Loads a compilation database for File. May return nullptr if it fails. The
   /// database is cached for subsequent accesses.
   clang::tooling::CompilationDatabase *
-  getOrCreateCompilationDatabaseForFile(StringRef Uri);
-  // Creates a new ASTUnit for the document at Uri.
+  getOrCreateCompilationDatabaseForFile(StringRef File);
+  // Creates a new ASTUnit for the document at File.
   // FIXME: This calls chdir internally, which is thread unsafe.
   std::unique_ptr
-  createASTUnitForFile(StringRef Uri, const DocumentStore &Docs);
+  createASTUnitForFile(StringRef File, const DocumentStore &Docs);
 
   void runWorker();
   void parseFileAndPublishDiagnostics(StringRef File);
 
   /// Clang objects.
 
-  /// A map from Uri-s to ASTUnit-s. Guarded by \c ASTLock. ASTUnit-s are used
+  /// A map from File-s to ASTUnit-s. Guarded by \c ASTLock. ASTUnit-s are used
   /// for generating diagnostics and fix-it-s asynchronously by the worker
   /// thread and synchronously for code completion.
   ///
Index: clang-tools-extra/trunk/clangd/Protocol.h
===
--- clang-tools-extra/trunk/clangd/Protocol.h
+++ clang-tools-extra/trunk/clangd/Protocol.h
@@ -29,9 +29,20 @@
 namespace clang {
 namespace clangd {
 
+struct URI {
+  std::string uri;
+  std::string file;
+
+  static URI fromUri(llvm::StringRef uri);
+  static URI fromFile(llvm::StringRef file);
+
+  static URI parse(llvm::yaml::ScalarNode *Param);
+  static std::string unparse(const URI &U);
+};
+
 struct TextDocumentIdentifier {
   /// The text document's URI.
-  std::string uri;
+  URI uri;
 
   static llvm::Optional
   parse(llvm::yaml::MappingNode *Params);
@@ -90,7 +101,7 @@
 
 struct TextDocumentItem {
   /// The text document's URI.
-  std::string uri;
+  URI uri;
 
   /// The text document's language identifier.
   std::string languageId;
@@ -328,7 +339,7 @@
   /// this completion. Edits must not overlap with the main edit nor with
   /// themselves.
   std::vector additionalTextEdits;
-  
+
   // TODO(krasimir): The following optional fields defined by the language
   // server protocol are unsupported:
   //
Index: clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
===
--- clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
+++ clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
@@ -21,7 +21,7 @@
 Output.log("Failed to decode DidOpenTextDocumentParams!\n");
 return;
   }
-  Store.addDocument(DOTDP->textDocument.uri, DOTDP->textDocument.text);
+  Store.addDocument(DOTDP->textDocument.uri.file, DOTDP->textDocument.text);
 }
 
 void TextDocumentDidChangeHandler::handleNotification(
@@ -32,7 +32,7 @@
 return;
   }
   // We only support full syncing right now.
-  Store.addDocument(DCTDP->textDocument.uri, DCTDP->contentChanges[0].text);
+  Store.addDocument(DCTDP->textDocument.uri.file, DCTDP->contentChanges[0].text);
 }
 
 /// Turn a [line, column] pair into an offset in Code.
@@ -83,9 +83,6 @@
   // Call clang-format.
   // FIXME: Don't ignore style.
   format::FormatStyle Style = format::getLLVMStyle();
-  // On windows FileManager doesn't like file://. Just strip it, clang-format
-  // doesn't need it.
-  Filename.consume_front("file://");
   tooling::Replacements Replacements =
   format::reformat(Style, Code, Ranges, Filename);
 
@@ -102,12 +99,12 @@
 return;
   }
 
-  std::string Code = Store.getDocument(DRFP->textDocument.uri);
+  std::string Code = Store.getDocument(DRFP->textDocument.uri.file);
 
   size_t Begin = positionToOffset(Code, DR

r299759 - [scan-build-py] merge runner module to analyzer

2017-04-07 Thread Laszlo Nagy via cfe-commits
Author: rizsotto
Date: Fri Apr  7 06:04:49 2017
New Revision: 299759

URL: http://llvm.org/viewvc/llvm-project?rev=299759&view=rev
Log:
[scan-build-py] merge runner module to analyzer

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

Removed:
cfe/trunk/tools/scan-build-py/libscanbuild/runner.py
cfe/trunk/tools/scan-build-py/tests/unit/test_runner.py
Modified:
cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py
cfe/trunk/tools/scan-build-py/tests/unit/__init__.py
cfe/trunk/tools/scan-build-py/tests/unit/test_analyze.py
cfe/trunk/tools/scan-build-py/tests/unit/test_report.py

Modified: cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py?rev=299759&r1=299758&r2=299759&view=diff
==
--- cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py (original)
+++ cfe/trunk/tools/scan-build-py/libscanbuild/analyze.py Fri Apr  7 06:04:49 
2017
@@ -16,18 +16,23 @@ import os
 import os.path
 import json
 import logging
-import tempfile
 import multiprocessing
+import tempfile
+import functools
+import subprocess
 import contextlib
 import datetime
+
 from libscanbuild import command_entry_point, compiler_wrapper, \
-wrapper_environment, run_build
+wrapper_environment, run_build, run_command
 from libscanbuild.arguments import parse_args_for_scan_build, \
 parse_args_for_analyze_build
-from libscanbuild.runner import run
 from libscanbuild.intercept import capture
 from libscanbuild.report import document
-from libscanbuild.compilation import split_command
+from libscanbuild.compilation import split_command, classify_source, \
+compiler_language
+from libscanbuild.clang import get_version, get_arguments
+from libscanbuild.shell import decode
 
 __all__ = ['scan_build', 'analyze_build', 'analyze_compiler_wrapper']
 
@@ -51,7 +56,7 @@ def scan_build():
 exit_code = capture(args)
 # Run the analyzer against the captured commands.
 if need_analyzer(args.build):
-run_analyzer(args)
+run_analyzer_parallel(args)
 else:
 # Run build command and analyzer with compiler wrappers.
 environment = setup_environment(args)
@@ -70,7 +75,7 @@ def analyze_build():
 # will re-assign the report directory as new output
 with report_directory(args.output, args.keep_empty) as args.output:
 # Run the analyzer against a compilation db.
-run_analyzer(args)
+run_analyzer_parallel(args)
 # Cover report generation and bug counting.
 number_of_bugs = document(args)
 # Set exit status as it was requested.
@@ -90,7 +95,7 @@ def need_analyzer(args):
 return len(args) and not re.search('configure|autogen', args[0])
 
 
-def run_analyzer(args):
+def run_analyzer_parallel(args):
 """ Runs the analyzer against the given compilation database. """
 
 def exclude(filename):
@@ -259,3 +264,277 @@ def analyzer_params(args):
 result.append('-analyzer-viz-egraph-ubigraph')
 
 return prefix_with('-Xclang', result)
+
+
+def require(required):
+""" Decorator for checking the required values in state.
+
+It checks the required attributes in the passed state and stop when
+any of those is missing. """
+
+def decorator(function):
+@functools.wraps(function)
+def wrapper(*args, **kwargs):
+for key in required:
+if key not in args[0]:
+raise KeyError('{0} not passed to {1}'.format(
+key, function.__name__))
+
+return function(*args, **kwargs)
+
+return wrapper
+
+return decorator
+
+
+@require(['command',  # entry from compilation database
+  'directory',  # entry from compilation database
+  'file',  # entry from compilation database
+  'clang',  # clang executable name (and path)
+  'direct_args',  # arguments from command line
+  'force_debug',  # kill non debug macros
+  'output_dir',  # where generated report files shall go
+  'output_format',  # it's 'plist' or 'html' or both
+  'output_failures'])  # generate crash reports or not
+def run(opts):
+""" Entry point to run (or not) static analyzer against a single entry
+of the compilation database.
+
+This complex task is decomposed into smaller methods which are calling
+each other in chain. If the analyzis is not possibe the given method
+just return and break the chain.
+
+The passed parameter is a python dictionary. Each method first check
+that the needed parameters received. (This is done by the 'require'
+decorator. It's like an 'assert' to check the contract between the
+caller and the called method.) """
+
+try:
+command = opts.pop('command')
+command = command if isinstance(

r299760 - CloneDetection.h: Fix warnings. [-Wdocumentation]

2017-04-07 Thread NAKAMURA Takumi via cfe-commits
Author: chapuni
Date: Fri Apr  7 06:06:31 2017
New Revision: 299760

URL: http://llvm.org/viewvc/llvm-project?rev=299760&view=rev
Log:
CloneDetection.h: Fix warnings. [-Wdocumentation]

Modified:
cfe/trunk/include/clang/Analysis/CloneDetection.h

Modified: cfe/trunk/include/clang/Analysis/CloneDetection.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CloneDetection.h?rev=299760&r1=299759&r2=299760&view=diff
==
--- cfe/trunk/include/clang/Analysis/CloneDetection.h (original)
+++ cfe/trunk/include/clang/Analysis/CloneDetection.h Fri Apr  7 06:06:31 2017
@@ -55,7 +55,7 @@ public:
   /// that describe a non-empty sub-array in the body of the given 
CompoundStmt.
   ///
   /// \param Stmt A CompoundStmt that contains all statements in its body.
-  /// \param Decl The Decl containing this Stmt.
+  /// \param D The Decl containing this Stmt.
   /// \param StartIndex The inclusive start index in the children array of
   ///   \p Stmt
   /// \param EndIndex The exclusive end index in the children array of \p Stmt.
@@ -65,7 +65,7 @@ public:
   /// Constructs a StmtSequence holding a single statement.
   ///
   /// \param Stmt An arbitrary Stmt.
-  /// \param Decl The Decl containing this Stmt.
+  /// \param D The Decl containing this Stmt.
   StmtSequence(const Stmt *Stmt, const Decl *D);
 
   /// Constructs an empty StmtSequence.
@@ -202,7 +202,8 @@ public:
   /// Searches for clones in all previously passed statements.
   /// \param Result Output parameter to which all created clone groups are
   ///   added.
-  /// \param Passes The constraints that should be applied to the result.
+  /// \param ConstraintList The constraints that should be applied to the
+  // result.
   template 
   void findClones(std::vector &Result, Ts... ConstraintList) {
 // The initial assumption is that there is only one clone group and every


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


[clang-tools-extra] r299764 - Fix compiler warnings: "ISO c99 requires rest arguments to be used" on

2017-04-07 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Apr  7 07:37:32 2017
New Revision: 299764

URL: http://llvm.org/viewvc/llvm-project?rev=299764&view=rev
Log:
Fix compiler warnings: "ISO c99 requires rest arguments to be used" on
the test file.

Modified:
clang-tools-extra/trunk/unittests/clang-rename/RenameClassTest.cpp

Modified: clang-tools-extra/trunk/unittests/clang-rename/RenameClassTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-rename/RenameClassTest.cpp?rev=299764&r1=299763&r2=299764&view=diff
==
--- clang-tools-extra/trunk/unittests/clang-rename/RenameClassTest.cpp 
(original)
+++ clang-tools-extra/trunk/unittests/clang-rename/RenameClassTest.cpp Fri Apr  
7 07:37:32 2017
@@ -189,7 +189,7 @@ INSTANTIATE_TEST_CASE_P(
 // friends, everyone needs friends.
 {"class Foo { int i; friend class a::Foo; };",
  "class Foo { int i; friend class b::Bar; };", "", ""},
-})));
+})), );
 
 TEST_P(RenameClassTest, RenameClasses) {
   auto Param = GetParam();
@@ -298,7 +298,7 @@ INSTANTIATE_TEST_CASE_P(
 {"namespace o1 { class Foo { int i; friend class Old; }; }",
  "namespace o1 { class Foo { int i; friend class New; }; }",
  "::o1::Old", "::o1::New"},
-})));
+})), );
 
 TEST_P(NamespaceDetectionTest, RenameClasses) {
   auto Param = GetParam();
@@ -394,7 +394,7 @@ INSTANTIATE_TEST_CASE_P(
 {"template  struct Moo { ns::Old o_; }; Moo m;",
  "template  struct Moo { ns::New o_; }; Moo m;",
  "ns::Old", "ns::New"},
-})));
+})), );
 
 TEST_P(TemplatedClassRenameTest, RenameTemplateClasses) {
   auto Param = GetParam();


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


r299774 - Sema: prevent __declspec(naked) use on x64

2017-04-07 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Fri Apr  7 10:13:47 2017
New Revision: 299774

URL: http://llvm.org/viewvc/llvm-project?rev=299774&view=rev
Log:
Sema: prevent __declspec(naked) use on x64

MSDN (https://msdn.microsoft.com/en-us/library/h5w10wxs.aspx) indicates
that `__declspec(naked)` is only permitted on x86 and ARM targets.
Testing with cl does confirm this behaviour.  Provide a warning for use
of `__declspec(naked)` on x64.

Added:
cfe/trunk/test/Sema/declspec-naked.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/Sema/ms-inline-asm.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=299774&r1=299773&r2=299774&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Apr  7 10:13:47 
2017
@@ -3231,7 +3231,8 @@ def err_attribute_regparm_invalid_number
   "'regparm' parameter must be between 0 and %0 inclusive">;
 def err_attribute_not_supported_in_lang : Error<
   "%0 attribute is not supported in %select{C|C++|Objective-C}1">;
-
+def err_attribute_not_supported_on_arch
+: Error<"%0 attribute is not supported on '%1'">;
 
 // Clang-Specific Attributes
 def warn_attribute_iboutlet : Warning<

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=299774&r1=299773&r2=299774&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Apr  7 10:13:47 2017
@@ -1923,6 +1923,17 @@ static void handleNakedAttr(Sema &S, Dec
  Attr.getName()))
 return;
 
+  if (Attr.isDeclspecAttribute()) {
+const auto &Triple = S.getASTContext().getTargetInfo().getTriple();
+const auto &Arch = Triple.getArch();
+if (Arch != llvm::Triple::x86 &&
+(Arch != llvm::Triple::arm && Arch != llvm::Triple::thumb)) {
+  S.Diag(Attr.getLoc(), diag::err_attribute_not_supported_on_arch)
+  << Attr.getName() << Triple.getArchName();
+  return;
+}
+  }
+
   D->addAttr(::new (S.Context) NakedAttr(Attr.getRange(), S.Context,
  
Attr.getAttributeSpellingListIndex()));
 }

Added: cfe/trunk/test/Sema/declspec-naked.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/declspec-naked.c?rev=299774&view=auto
==
--- cfe/trunk/test/Sema/declspec-naked.c (added)
+++ cfe/trunk/test/Sema/declspec-naked.c Fri Apr  7 10:13:47 2017
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fsyntax-only -fdeclspec 
-verify %s
+// RUN: %clang_cc1 -triple thumbv7-unknown-windows-msvc -fsyntax-only 
-fdeclspec -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fsyntax-only 
-fdeclspec -verify %s
+#if defined(_M_IX86) || defined(_M_ARM)
+// CHECK: expected-no-diagnostics
+#endif
+
+void __declspec(naked) f(void) {}
+#if !defined(_M_IX86) && !defined(_M_ARM)
+// expected-error@-2{{'naked' attribute is not supported on 'x86_64'}}
+#endif

Modified: cfe/trunk/test/Sema/ms-inline-asm.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/ms-inline-asm.c?rev=299774&r1=299773&r2=299774&view=diff
==
--- cfe/trunk/test/Sema/ms-inline-asm.c (original)
+++ cfe/trunk/test/Sema/ms-inline-asm.c Fri Apr  7 10:13:47 2017
@@ -1,5 +1,5 @@
 // REQUIRES: x86-registered-target
-// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -fms-extensions 
-fasm-blocks -Wno-microsoft -Wunused-label -verify -fsyntax-only
+// RUN: %clang_cc1 %s -triple i386-apple-darwin10 -fms-extensions -fasm-blocks 
-Wno-microsoft -Wunused-label -verify -fsyntax-only
 
 void t1(void) { 
  __asm __asm // expected-error {{__asm used with no assembly instructions}}


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


Re: r299774 - Sema: prevent __declspec(naked) use on x64

2017-04-07 Thread Aaron Ballman via cfe-commits
On Fri, Apr 7, 2017 at 11:13 AM, Saleem Abdulrasool via cfe-commits
 wrote:
> Author: compnerd
> Date: Fri Apr  7 10:13:47 2017
> New Revision: 299774
>
> URL: http://llvm.org/viewvc/llvm-project?rev=299774&view=rev
> Log:
> Sema: prevent __declspec(naked) use on x64
>
> MSDN (https://msdn.microsoft.com/en-us/library/h5w10wxs.aspx) indicates
> that `__declspec(naked)` is only permitted on x86 and ARM targets.
> Testing with cl does confirm this behaviour.  Provide a warning for use
> of `__declspec(naked)` on x64.

Your patch is not providing a warning, it's providing an error, which
seems inappropriate (to me). Why is this attribute not silently
ignored there instead?

(Btw, I did not see a review thread for this, did I miss one?) More
comments below.

>
> Added:
> cfe/trunk/test/Sema/declspec-naked.c
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> cfe/trunk/test/Sema/ms-inline-asm.c
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=299774&r1=299773&r2=299774&view=diff
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Apr  7 10:13:47 
> 2017
> @@ -3231,7 +3231,8 @@ def err_attribute_regparm_invalid_number
>"'regparm' parameter must be between 0 and %0 inclusive">;
>  def err_attribute_not_supported_in_lang : Error<
>"%0 attribute is not supported in %select{C|C++|Objective-C}1">;
> -
> +def err_attribute_not_supported_on_arch
> +: Error<"%0 attribute is not supported on '%1'">;
>
>  // Clang-Specific Attributes
>  def warn_attribute_iboutlet : Warning<
>
> Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=299774&r1=299773&r2=299774&view=diff
> ==
> --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Apr  7 10:13:47 2017
> @@ -1923,6 +1923,17 @@ static void handleNakedAttr(Sema &S, Dec
>   Attr.getName()))
>  return;
>
> +  if (Attr.isDeclspecAttribute()) {
> +const auto &Triple = S.getASTContext().getTargetInfo().getTriple();

No need to have the Triple variable (which is a rather poor name given
that it's also the type name).
> +const auto &Arch = Triple.getArch();

Do not use auto for either of these.

~Aaron

> +if (Arch != llvm::Triple::x86 &&
> +(Arch != llvm::Triple::arm && Arch != llvm::Triple::thumb)) {
> +  S.Diag(Attr.getLoc(), diag::err_attribute_not_supported_on_arch)
> +  << Attr.getName() << Triple.getArchName();
> +  return;
> +}
> +  }
> +
>D->addAttr(::new (S.Context) NakedAttr(Attr.getRange(), S.Context,
>   
> Attr.getAttributeSpellingListIndex()));
>  }
>
> Added: cfe/trunk/test/Sema/declspec-naked.c
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/declspec-naked.c?rev=299774&view=auto
> ==
> --- cfe/trunk/test/Sema/declspec-naked.c (added)
> +++ cfe/trunk/test/Sema/declspec-naked.c Fri Apr  7 10:13:47 2017
> @@ -0,0 +1,11 @@
> +// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fsyntax-only 
> -fdeclspec -verify %s
> +// RUN: %clang_cc1 -triple thumbv7-unknown-windows-msvc -fsyntax-only 
> -fdeclspec -verify %s
> +// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fsyntax-only 
> -fdeclspec -verify %s
> +#if defined(_M_IX86) || defined(_M_ARM)
> +// CHECK: expected-no-diagnostics
> +#endif
> +
> +void __declspec(naked) f(void) {}
> +#if !defined(_M_IX86) && !defined(_M_ARM)
> +// expected-error@-2{{'naked' attribute is not supported on 'x86_64'}}
> +#endif
>
> Modified: cfe/trunk/test/Sema/ms-inline-asm.c
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/ms-inline-asm.c?rev=299774&r1=299773&r2=299774&view=diff
> ==
> --- cfe/trunk/test/Sema/ms-inline-asm.c (original)
> +++ cfe/trunk/test/Sema/ms-inline-asm.c Fri Apr  7 10:13:47 2017
> @@ -1,5 +1,5 @@
>  // REQUIRES: x86-registered-target
> -// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -fms-extensions 
> -fasm-blocks -Wno-microsoft -Wunused-label -verify -fsyntax-only
> +// RUN: %clang_cc1 %s -triple i386-apple-darwin10 -fms-extensions 
> -fasm-blocks -Wno-microsoft -Wunused-label -verify -fsyntax-only
>
>  void t1(void) {
>   __asm __asm // expected-error {{__asm used with no assembly instructions}}
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin

r299782 - Implement _interlockedbittestandset as a builtin

2017-04-07 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Fri Apr  7 11:41:47 2017
New Revision: 299782

URL: http://llvm.org/viewvc/llvm-project?rev=299782&view=rev
Log:
Implement _interlockedbittestandset as a builtin

It's used by MS headers in VS 2017 without including intrin.h, so we
can't implement it in the header anymore.

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

Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Headers/intrin.h
cfe/trunk/test/CodeGen/ms-intrinsics.c

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=299782&r1=299781&r2=299782&view=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Fri Apr  7 11:41:47 2017
@@ -756,6 +756,7 @@ LANGBUILTIN(_InterlockedOr,   "LiLiD*Li"
 LANGBUILTIN(_InterlockedXor8,  "ccD*c",   "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedXor16, "ssD*s",   "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedXor,   "LiLiD*Li","n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_interlockedbittestandset, "UcLiD*Li", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(__noop,   "i.",  "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(__popcnt16, "UsUs", "nc", ALL_MS_LANGUAGES)
 LANGBUILTIN(__popcnt,   "UiUi", "nc", ALL_MS_LANGUAGES)

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=299782&r1=299781&r2=299782&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Fri Apr  7 11:41:47 2017
@@ -492,6 +492,7 @@ enum class CodeGenFunction::MSVCIntrin {
   _InterlockedIncrement,
   _InterlockedOr,
   _InterlockedXor,
+  _interlockedbittestandset,
   __fastfail,
 };
 
@@ -559,6 +560,22 @@ Value *CodeGenFunction::EmitMSVCBuiltinE
   case MSVCIntrin::_InterlockedXor:
 return MakeBinaryAtomicValue(*this, AtomicRMWInst::Xor, E);
 
+  case MSVCIntrin::_interlockedbittestandset: {
+llvm::Value *Addr = EmitScalarExpr(E->getArg(0));
+llvm::Value *Bit = EmitScalarExpr(E->getArg(1));
+AtomicRMWInst *RMWI = Builder.CreateAtomicRMW(
+AtomicRMWInst::Or, Addr,
+Builder.CreateShl(ConstantInt::get(Bit->getType(), 1), Bit),
+llvm::AtomicOrdering::SequentiallyConsistent);
+// Shift the relevant bit to the least significant position, truncate to
+// the result type, and test the low bit.
+llvm::Value *Shifted = Builder.CreateLShr(RMWI, Bit);
+llvm::Value *Truncated =
+Builder.CreateTrunc(Shifted, ConvertType(E->getType()));
+return Builder.CreateAnd(Truncated,
+ ConstantInt::get(Truncated->getType(), 1));
+  }
+
   case MSVCIntrin::_InterlockedDecrement: {
 llvm::Type *IntTy = ConvertType(E->getType());
 AtomicRMWInst *RMWI = Builder.CreateAtomicRMW(
@@ -2238,6 +2255,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(
   case Builtin::BI_InterlockedXor16:
   case Builtin::BI_InterlockedXor:
 return RValue::get(EmitMSVCBuiltinExpr(MSVCIntrin::_InterlockedXor, E));
+  case Builtin::BI_interlockedbittestandset:
+return RValue::get(
+EmitMSVCBuiltinExpr(MSVCIntrin::_interlockedbittestandset, E));
 
   case Builtin::BI__exception_code:
   case Builtin::BI_exception_code:
@@ -2309,10 +2329,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 break;
   }
 
-  case Builtin::BI__fastfail: {
+  case Builtin::BI__fastfail:
 return RValue::get(EmitMSVCBuiltinExpr(MSVCIntrin::__fastfail, E));
-break;
-  }
 
   case Builtin::BI__builtin_coro_size: {
 auto & Context = getContext();

Modified: cfe/trunk/lib/Headers/intrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/intrin.h?rev=299782&r1=299781&r2=299782&view=diff
==
--- cfe/trunk/lib/Headers/intrin.h (original)
+++ cfe/trunk/lib/Headers/intrin.h Fri Apr  7 11:41:47 2017
@@ -173,7 +173,6 @@ void __cdecl _disable(void);
 void __cdecl _enable(void);
 long _InterlockedAddLargeStatistic(__int64 volatile *_Addend, long _Value);
 unsigned char _interlockedbittestandreset(long volatile *, long);
-static __inline__
 unsigned char _interlockedbittestandset(long volatile *, long);
 long _InterlockedCompareExchange_HLEAcquire(long volatile *, long, long);
 long _InterlockedCompareExchange_HLERelease(long volatile *, long, long);
@@ -369,11 +368,6 @@ _bittestandset(long *_BitBase, long _Bit
   *_BitBase = *_BitBase | (1 << _BitPos);
   return _Res;
 }
-static __inline__ unsigned char __DEFAULT_FN_ATTRS
-_interlockedbittestandset(long volatile *_BitBase, long _BitPos) {
-  long _PrevVal = __atomic_fetch_or(_BitBase, 1l << _BitPos, __ATOMIC_SEQ_CST);
-  return (_PrevVal >> _BitPos) & 1;
-}
 #if defined(__arm

r299785 - Attempt to fix ms-intrinsics.c test

2017-04-07 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Fri Apr  7 12:01:56 2017
New Revision: 299785

URL: http://llvm.org/viewvc/llvm-project?rev=299785&view=rev
Log:
Attempt to fix ms-intrinsics.c test

Modified:
cfe/trunk/test/CodeGen/ms-intrinsics.c

Modified: cfe/trunk/test/CodeGen/ms-intrinsics.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ms-intrinsics.c?rev=299785&r1=299784&r2=299785&view=diff
==
--- cfe/trunk/test/CodeGen/ms-intrinsics.c (original)
+++ cfe/trunk/test/CodeGen/ms-intrinsics.c Fri Apr  7 12:01:56 2017
@@ -438,12 +438,12 @@ unsigned char test_interlockedbittestand
   return _interlockedbittestandset(ptr, bit);
 }
 // CHECK-LABEL: define{{.*}} i8 @test_interlockedbittestandset
-// CHECK: %0 = shl i32 1, %bit
-// CHECK: %1 = atomicrmw or i32* %ptr, i32 %0 seq_cst
-// CHECK: %2 = lshr i32 %1, %bit
-// CHECK: %3 = trunc i32 %2 to i8
-// CHECK: %4 = and i8 %3, 1
-// CHECK: ret i8 %4
+// CHECK: [[MASKBIT:%[0-9]+]] = shl i32 1, %bit
+// CHECK: [[OLD:%[0-9]+]] = atomicrmw or i32* %ptr, i32 [[MASKBIT]] seq_cst
+// CHECK: [[SHIFT:%[0-9]+]] = lshr i32 [[OLD]], %bit
+// CHECK: [[TRUNC:%[0-9]+]] = trunc i32 [[SHIFT]] to i8
+// CHECK: [[AND:%[0-9]+]] = and i8 [[TRUNC]], 1
+// CHECK: ret i8 [[AND]]
 
 void test__fastfail() {
   __fastfail(42);


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


Re: r299774 - Sema: prevent __declspec(naked) use on x64

2017-04-07 Thread David Majnemer via cfe-commits
On Fri, Apr 7, 2017 at 8:30 AM, Aaron Ballman via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> On Fri, Apr 7, 2017 at 11:13 AM, Saleem Abdulrasool via cfe-commits
>  wrote:
> > Author: compnerd
> > Date: Fri Apr  7 10:13:47 2017
> > New Revision: 299774
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=299774&view=rev
> > Log:
> > Sema: prevent __declspec(naked) use on x64
> >
> > MSDN (https://msdn.microsoft.com/en-us/library/h5w10wxs.aspx) indicates
> > that `__declspec(naked)` is only permitted on x86 and ARM targets.
> > Testing with cl does confirm this behaviour.  Provide a warning for use
> > of `__declspec(naked)` on x64.
>
> Your patch is not providing a warning, it's providing an error, which
> seems inappropriate (to me). Why is this attribute not silently
> ignored there instead?
>

FWIW, MSVC diagnoses this with an error: https://godbolt.org/g/T5sQr5


>
> (Btw, I did not see a review thread for this, did I miss one?) More
> comments below.
>
> >
> > Added:
> > cfe/trunk/test/Sema/declspec-naked.c
> > Modified:
> > cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> > cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> > cfe/trunk/test/Sema/ms-inline-asm.c
> >
> > Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/
> DiagnosticSemaKinds.td?rev=299774&r1=299773&r2=299774&view=diff
> > 
> ==
> > --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> > +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Apr  7
> 10:13:47 2017
> > @@ -3231,7 +3231,8 @@ def err_attribute_regparm_invalid_number
> >"'regparm' parameter must be between 0 and %0 inclusive">;
> >  def err_attribute_not_supported_in_lang : Error<
> >"%0 attribute is not supported in %select{C|C++|Objective-C}1">;
> > -
> > +def err_attribute_not_supported_on_arch
> > +: Error<"%0 attribute is not supported on '%1'">;
> >
> >  // Clang-Specific Attributes
> >  def warn_attribute_iboutlet : Warning<
> >
> > Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaDeclAttr.cpp?rev=299774&r1=299773&r2=299774&view=diff
> > 
> ==
> > --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
> > +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Apr  7 10:13:47 2017
> > @@ -1923,6 +1923,17 @@ static void handleNakedAttr(Sema &S, Dec
> >   Attr.getName()))
> >  return;
> >
> > +  if (Attr.isDeclspecAttribute()) {
> > +const auto &Triple = S.getASTContext().getTargetInfo().getTriple();
>
> No need to have the Triple variable (which is a rather poor name given
> that it's also the type name).
> > +const auto &Arch = Triple.getArch();
>
> Do not use auto for either of these.
>
> ~Aaron
>
> > +if (Arch != llvm::Triple::x86 &&
> > +(Arch != llvm::Triple::arm && Arch != llvm::Triple::thumb)) {
> > +  S.Diag(Attr.getLoc(), diag::err_attribute_not_supported_on_arch)
> > +  << Attr.getName() << Triple.getArchName();
> > +  return;
> > +}
> > +  }
> > +
> >D->addAttr(::new (S.Context) NakedAttr(Attr.getRange(), S.Context,
> >   Attr.
> getAttributeSpellingListIndex()));
> >  }
> >
> > Added: cfe/trunk/test/Sema/declspec-naked.c
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/
> declspec-naked.c?rev=299774&view=auto
> > 
> ==
> > --- cfe/trunk/test/Sema/declspec-naked.c (added)
> > +++ cfe/trunk/test/Sema/declspec-naked.c Fri Apr  7 10:13:47 2017
> > @@ -0,0 +1,11 @@
> > +// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fsyntax-only
> -fdeclspec -verify %s
> > +// RUN: %clang_cc1 -triple thumbv7-unknown-windows-msvc -fsyntax-only
> -fdeclspec -verify %s
> > +// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fsyntax-only
> -fdeclspec -verify %s
> > +#if defined(_M_IX86) || defined(_M_ARM)
> > +// CHECK: expected-no-diagnostics
> > +#endif
> > +
> > +void __declspec(naked) f(void) {}
> > +#if !defined(_M_IX86) && !defined(_M_ARM)
> > +// expected-error@-2{{'naked' attribute is not supported on 'x86_64'}}
> > +#endif
> >
> > Modified: cfe/trunk/test/Sema/ms-inline-asm.c
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/
> ms-inline-asm.c?rev=299774&r1=299773&r2=299774&view=diff
> > 
> ==
> > --- cfe/trunk/test/Sema/ms-inline-asm.c (original)
> > +++ cfe/trunk/test/Sema/ms-inline-asm.c Fri Apr  7 10:13:47 2017
> > @@ -1,5 +1,5 @@
> >  // REQUIRES: x86-registered-target
> > -// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -fms-extensions
> -fasm-blocks -Wno-microsoft -Wunused-label -verify -fsyntax-

Re: r299774 - Sema: prevent __declspec(naked) use on x64

2017-04-07 Thread Richard Smith via cfe-commits
On 7 Apr 2017 11:49 am, "David Majnemer via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:



On Fri, Apr 7, 2017 at 8:30 AM, Aaron Ballman via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> On Fri, Apr 7, 2017 at 11:13 AM, Saleem Abdulrasool via cfe-commits
>  wrote:
> > Author: compnerd
> > Date: Fri Apr  7 10:13:47 2017
> > New Revision: 299774
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=299774&view=rev
> > Log:
> > Sema: prevent __declspec(naked) use on x64
> >
> > MSDN (https://msdn.microsoft.com/en-us/library/h5w10wxs.aspx) indicates
> > that `__declspec(naked)` is only permitted on x86 and ARM targets.
> > Testing with cl does confirm this behaviour.  Provide a warning for use
> > of `__declspec(naked)` on x64.
>
> Your patch is not providing a warning, it's providing an error, which
> seems inappropriate (to me). Why is this attribute not silently
> ignored there instead?
>

FWIW, MSVC diagnoses this with an error: https://godbolt.org/g/T5sQr5


Is there a reason we can't support this? Was our existing support broken in
some way? We generally allow our features to be combined in arbitrary ways
unless there's a reason not to.

(Btw, I did not see a review thread for this, did I miss one?) More
> comments below.
>
> >
> > Added:
> > cfe/trunk/test/Sema/declspec-naked.c
> > Modified:
> > cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> > cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> > cfe/trunk/test/Sema/ms-inline-asm.c
> >
> > Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
> Basic/DiagnosticSemaKinds.td?rev=299774&r1=299773&r2=299774&view=diff
> > 
> ==
> > --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> > +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Apr  7
> 10:13:47 2017
> > @@ -3231,7 +3231,8 @@ def err_attribute_regparm_invalid_number
> >"'regparm' parameter must be between 0 and %0 inclusive">;
> >  def err_attribute_not_supported_in_lang : Error<
> >"%0 attribute is not supported in %select{C|C++|Objective-C}1">;
> > -
> > +def err_attribute_not_supported_on_arch
> > +: Error<"%0 attribute is not supported on '%1'">;
> >
> >  // Clang-Specific Attributes
> >  def warn_attribute_iboutlet : Warning<
> >
> > Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaD
> eclAttr.cpp?rev=299774&r1=299773&r2=299774&view=diff
> > 
> ==
> > --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
> > +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Apr  7 10:13:47 2017
> > @@ -1923,6 +1923,17 @@ static void handleNakedAttr(Sema &S, Dec
> >   Attr.getName()))
> >  return;
> >
> > +  if (Attr.isDeclspecAttribute()) {
> > +const auto &Triple = S.getASTContext().getTargetInfo().getTriple();
>
> No need to have the Triple variable (which is a rather poor name given
> that it's also the type name).
> > +const auto &Arch = Triple.getArch();
>
> Do not use auto for either of these.
>
> ~Aaron
>
> > +if (Arch != llvm::Triple::x86 &&
> > +(Arch != llvm::Triple::arm && Arch != llvm::Triple::thumb)) {
> > +  S.Diag(Attr.getLoc(), diag::err_attribute_not_supported_on_arch)
> > +  << Attr.getName() << Triple.getArchName();
> > +  return;
> > +}
> > +  }
> > +
> >D->addAttr(::new (S.Context) NakedAttr(Attr.getRange(), S.Context,
> >   Attr.getAttributeSpellingList
> Index()));
> >  }
> >
> > Added: cfe/trunk/test/Sema/declspec-naked.c
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/decl
> spec-naked.c?rev=299774&view=auto
> > 
> ==
> > --- cfe/trunk/test/Sema/declspec-naked.c (added)
> > +++ cfe/trunk/test/Sema/declspec-naked.c Fri Apr  7 10:13:47 2017
> > @@ -0,0 +1,11 @@
> > +// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fsyntax-only
> -fdeclspec -verify %s
> > +// RUN: %clang_cc1 -triple thumbv7-unknown-windows-msvc -fsyntax-only
> -fdeclspec -verify %s
> > +// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fsyntax-only
> -fdeclspec -verify %s
> > +#if defined(_M_IX86) || defined(_M_ARM)
> > +// CHECK: expected-no-diagnostics
> > +#endif
> > +
> > +void __declspec(naked) f(void) {}
> > +#if !defined(_M_IX86) && !defined(_M_ARM)
> > +// expected-error@-2{{'naked' attribute is not supported on 'x86_64'}}
> > +#endif
> >
> > Modified: cfe/trunk/test/Sema/ms-inline-asm.c
> > URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/ms-
> inline-asm.c?rev=299774&r1=299773&r2=299774&view=diff
> > 
> ==
> > --- cfe/trunk/test/Sema/ms-inline-asm.

Re: r299774 - Sema: prevent __declspec(naked) use on x64

2017-04-07 Thread Aaron Ballman via cfe-commits
On Fri, Apr 7, 2017 at 2:53 PM, Richard Smith  wrote:
> On 7 Apr 2017 11:49 am, "David Majnemer via cfe-commits"
>  wrote:
>
>
>
> On Fri, Apr 7, 2017 at 8:30 AM, Aaron Ballman via cfe-commits
>  wrote:
>>
>> On Fri, Apr 7, 2017 at 11:13 AM, Saleem Abdulrasool via cfe-commits
>>  wrote:
>> > Author: compnerd
>> > Date: Fri Apr  7 10:13:47 2017
>> > New Revision: 299774
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=299774&view=rev
>> > Log:
>> > Sema: prevent __declspec(naked) use on x64
>> >
>> > MSDN (https://msdn.microsoft.com/en-us/library/h5w10wxs.aspx) indicates
>> > that `__declspec(naked)` is only permitted on x86 and ARM targets.
>> > Testing with cl does confirm this behaviour.  Provide a warning for use
>> > of `__declspec(naked)` on x64.
>>
>> Your patch is not providing a warning, it's providing an error, which
>> seems inappropriate (to me). Why is this attribute not silently
>> ignored there instead?
>
>
> FWIW, MSVC diagnoses this with an error: https://godbolt.org/g/T5sQr5
>
>
> Is there a reason we can't support this? Was our existing support broken in
> some way? We generally allow our features to be combined in arbitrary ways
> unless there's a reason not to.

For the __declspec spelling of the attribute, we shouldn't really do
*more* than what Microsoft allows, should we (even if we can)?

As for error vs warning, I was mostly pointing out that (1) the commit
comment doesn't match the behavior of the patch, which is always a
concern, and (2) most of our attributes warn rather than err, unless
there's a solid reason to err. If LLVM gets a naked attribute for a
function and the architecture doesn't support the concept, what
happens? I thought it ignored it (which suggests a warning rather than
an error, to a certain extent), but I could be wrong.

~Aaron

>
>> (Btw, I did not see a review thread for this, did I miss one?) More
>> comments below.
>>
>> >
>> > Added:
>> > cfe/trunk/test/Sema/declspec-naked.c
>> > Modified:
>> > cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> > cfe/trunk/lib/Sema/SemaDeclAttr.cpp
>> > cfe/trunk/test/Sema/ms-inline-asm.c
>> >
>> > Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=299774&r1=299773&r2=299774&view=diff
>> >
>> > ==
>> > --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>> > +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Apr  7
>> > 10:13:47 2017
>> > @@ -3231,7 +3231,8 @@ def err_attribute_regparm_invalid_number
>> >"'regparm' parameter must be between 0 and %0 inclusive">;
>> >  def err_attribute_not_supported_in_lang : Error<
>> >"%0 attribute is not supported in %select{C|C++|Objective-C}1">;
>> > -
>> > +def err_attribute_not_supported_on_arch
>> > +: Error<"%0 attribute is not supported on '%1'">;
>> >
>> >  // Clang-Specific Attributes
>> >  def warn_attribute_iboutlet : Warning<
>> >
>> > Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=299774&r1=299773&r2=299774&view=diff
>> >
>> > ==
>> > --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
>> > +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Apr  7 10:13:47 2017
>> > @@ -1923,6 +1923,17 @@ static void handleNakedAttr(Sema &S, Dec
>> >   Attr.getName()))
>> >  return;
>> >
>> > +  if (Attr.isDeclspecAttribute()) {
>> > +const auto &Triple = S.getASTContext().getTargetInfo().getTriple();
>>
>> No need to have the Triple variable (which is a rather poor name given
>> that it's also the type name).
>> > +const auto &Arch = Triple.getArch();
>>
>> Do not use auto for either of these.
>>
>> ~Aaron
>>
>> > +if (Arch != llvm::Triple::x86 &&
>> > +(Arch != llvm::Triple::arm && Arch != llvm::Triple::thumb)) {
>> > +  S.Diag(Attr.getLoc(), diag::err_attribute_not_supported_on_arch)
>> > +  << Attr.getName() << Triple.getArchName();
>> > +  return;
>> > +}
>> > +  }
>> > +
>> >D->addAttr(::new (S.Context) NakedAttr(Attr.getRange(), S.Context,
>> >
>> > Attr.getAttributeSpellingListIndex()));
>> >  }
>> >
>> > Added: cfe/trunk/test/Sema/declspec-naked.c
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/declspec-naked.c?rev=299774&view=auto
>> >
>> > ==
>> > --- cfe/trunk/test/Sema/declspec-naked.c (added)
>> > +++ cfe/trunk/test/Sema/declspec-naked.c Fri Apr  7 10:13:47 2017
>> > @@ -0,0 +1,11 @@
>> > +// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fsyntax-only
>> > -fdeclspec -verify %s
>> > +// RUN: %clang_cc1 -triple thumbv7-unknown-windows-msvc -fsyntax-only
>> > -fdecls

[libunwind] r299796 - [CMake][libunwind] Use -nodefaultlibs for CMake checks

2017-04-07 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Fri Apr  7 15:10:29 2017
New Revision: 299796

URL: http://llvm.org/viewvc/llvm-project?rev=299796&view=rev
Log:
[CMake][libunwind] Use -nodefaultlibs for CMake checks

Since libunwind is built with -nodefaultlibs, we should be using this
option even for CMake checks to avoid any inconsistency and also to
avoid dependency on a working C++ standard library just for the setting
up the build itself. The implementation is largely similar to the one
used by libc++.

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

Modified:
libunwind/trunk/cmake/config-ix.cmake

Modified: libunwind/trunk/cmake/config-ix.cmake
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/cmake/config-ix.cmake?rev=299796&r1=299795&r2=299796&view=diff
==
--- libunwind/trunk/cmake/config-ix.cmake (original)
+++ libunwind/trunk/cmake/config-ix.cmake Fri Apr  7 15:10:29 2017
@@ -3,13 +3,35 @@ include(CheckCCompilerFlag)
 include(CheckCXXCompilerFlag)
 include(CheckLibraryExists)
 
+check_library_exists(c fopen "" LIBUNWIND_HAS_C_LIB)
+
+# libunwind is built with -nodefaultlibs, so we want all our checks to also
+# use this option, otherwise we may end up with an inconsistency between
+# the flags we think we require during configuration (if the checks are
+# performed without -nodefaultlibs) and the flags that are actually
+# required during compilation (which has the -nodefaultlibs). libc is
+# required for the link to go through. We remove sanitizers from the
+# configuration checks to avoid spurious link errors.
+check_c_compiler_flag(-nodefaultlibs LIBUNWIND_HAS_NODEFAULTLIBS_FLAG)
+if (LIBUNWIND_HAS_NODEFAULTLIBS_FLAG)
+  set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")
+  if (LIBUNWIND_HAS_C_LIB)
+list(APPEND CMAKE_REQUIRED_LIBRARIES c)
+  endif ()
+  if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
+set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
+  endif ()
+  if (CMAKE_C_FLAGS MATCHES -fsanitize-coverage OR CMAKE_CXX_FLAGS MATCHES 
-fsanitize-coverage)
+set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} 
-fno-sanitize-coverage=edge,trace-cmp,indirect-calls,8bit-counters")
+  endif ()
+endif ()
+
 # Check compiler flags
 check_c_compiler_flag(-funwind-tables LIBUNWIND_HAS_FUNWIND_TABLES)
 check_cxx_compiler_flag(-fPIC LIBUNWIND_HAS_FPIC_FLAG)
 check_cxx_compiler_flag(-fno-exceptions   LIBUNWIND_HAS_NO_EXCEPTIONS_FLAG)
 check_cxx_compiler_flag(-fno-rtti LIBUNWIND_HAS_NO_RTTI_FLAG)
 check_cxx_compiler_flag(-fstrict-aliasing 
LIBUNWIND_HAS_FSTRICT_ALIASING_FLAG)
-check_cxx_compiler_flag(-nodefaultlibsLIBUNWIND_HAS_NODEFAULTLIBS_FLAG)
 check_cxx_compiler_flag(-nostdinc++   LIBUNWIND_HAS_NOSTDINCXX_FLAG)
 check_cxx_compiler_flag(-Wall LIBUNWIND_HAS_WALL_FLAG)
 check_cxx_compiler_flag(-WLIBUNWIND_HAS_W_FLAG)
@@ -44,7 +66,6 @@ if(LIBUNWIND_HAS_STD_CXX11)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
 endif()
 
-check_library_exists(c fopen "" LIBUNWIND_HAS_C_LIB)
 check_library_exists(dl dladdr "" LIBUNWIND_HAS_DL_LIB)
 check_library_exists(pthread pthread_once "" LIBUNWIND_HAS_PTHREAD_LIB)
 


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


[libcxxabi] r299797 - [CMake][libcxxabi] Use -nodefaultlibs for CMake checks

2017-04-07 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Fri Apr  7 15:10:41 2017
New Revision: 299797

URL: http://llvm.org/viewvc/llvm-project?rev=299797&view=rev
Log:
[CMake][libcxxabi] Use -nodefaultlibs for CMake checks

Since libc++abi is built with -nodefaultlibs, we should be using this
option even for CMake checks to avoid any inconsistency and also to
avoid dependency on a working C++ standard library just for the setting
up the build itself. The implementation is largely similar to the one
used by libc++.

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

Added:
libcxxabi/trunk/cmake/Modules/
libcxxabi/trunk/cmake/Modules/HandleCompilerRT.cmake
Modified:
libcxxabi/trunk/CMakeLists.txt
libcxxabi/trunk/cmake/config-ix.cmake

Modified: libcxxabi/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/CMakeLists.txt?rev=299797&r1=299796&r2=299797&view=diff
==
--- libcxxabi/trunk/CMakeLists.txt (original)
+++ libcxxabi/trunk/CMakeLists.txt Fri Apr  7 15:10:41 2017
@@ -8,6 +8,13 @@ if(POLICY CMP0042)
   cmake_policy(SET CMP0042 NEW) # Set MACOSX_RPATH=YES by default
 endif()
 
+# Add path for custom modules
+set(CMAKE_MODULE_PATH
+  "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
+  "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
+  ${CMAKE_MODULE_PATH}
+  )
+
 if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
   project(libcxxabi)
 
@@ -124,6 +131,7 @@ endif()
 
#===
 # Setup CMake Options
 
#===
+include(HandleCompilerRT)
 
 # Define options.
 option(LIBCXXABI_ENABLE_EXCEPTIONS "Use exceptions." ON)

Added: libcxxabi/trunk/cmake/Modules/HandleCompilerRT.cmake
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/cmake/Modules/HandleCompilerRT.cmake?rev=299797&view=auto
==
--- libcxxabi/trunk/cmake/Modules/HandleCompilerRT.cmake (added)
+++ libcxxabi/trunk/cmake/Modules/HandleCompilerRT.cmake Fri Apr  7 15:10:41 
2017
@@ -0,0 +1,58 @@
+function(find_compiler_rt_library name dest)
+  if (NOT DEFINED LIBCXXABI_COMPILE_FLAGS)
+message(FATAL_ERROR "LIBCXXABI_COMPILE_FLAGS must be defined when using 
this function")
+  endif()
+  set(dest "" PARENT_SCOPE)
+  set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${TARGET_TRIPLE} 
${LIBCXXABI_COMPILE_FLAGS}
+  "--rtlib=compiler-rt" "--print-libgcc-file-name")
+  if (CMAKE_CXX_COMPILER_ID MATCHES Clang AND CMAKE_CXX_COMPILER_TARGET)
+list(APPEND CLANG_COMMAND "--target=${CMAKE_CXX_COMPILER_TARGET}")
+  endif()
+  execute_process(
+  COMMAND ${CLANG_COMMAND}
+  RESULT_VARIABLE HAD_ERROR
+  OUTPUT_VARIABLE LIBRARY_FILE
+  )
+  string(STRIP "${LIBRARY_FILE}" LIBRARY_FILE)
+  string(REPLACE "builtins" "${name}" LIBRARY_FILE "${LIBRARY_FILE}")
+  if (NOT HAD_ERROR AND EXISTS "${LIBRARY_FILE}")
+message(STATUS "Found compiler-rt library: ${LIBRARY_FILE}")
+set(${dest} "${LIBRARY_FILE}" PARENT_SCOPE)
+  else()
+message(STATUS "Failed to find compiler-rt library")
+  endif()
+endfunction()
+
+function(find_compiler_rt_dir dest)
+  if (NOT DEFINED LIBCXXABI_COMPILE_FLAGS)
+message(FATAL_ERROR "LIBCXXABI_COMPILE_FLAGS must be defined when using 
this function")
+  endif()
+  set(dest "" PARENT_SCOPE)
+  if (APPLE)
+set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBCXXABI_COMPILE_FLAGS}
+"-print-file-name=lib")
+execute_process(
+COMMAND ${CLANG_COMMAND}
+RESULT_VARIABLE HAD_ERROR
+OUTPUT_VARIABLE LIBRARY_DIR
+)
+string(STRIP "${LIBRARY_DIR}" LIBRARY_DIR)
+set(LIBRARY_DIR "${LIBRARY_DIR}/darwin")
+  else()
+set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${LIBCXXABI_COMPILE_FLAGS}
+"--rtlib=compiler-rt" "--print-libgcc-file-name")
+execute_process(
+COMMAND ${CLANG_COMMAND}
+RESULT_VARIABLE HAD_ERROR
+OUTPUT_VARIABLE LIBRARY_FILE
+)
+string(STRIP "${LIBRARY_FILE}" LIBRARY_FILE)
+get_filename_component(LIBRARY_DIR "${LIBRARY_FILE}" DIRECTORY)
+  endif()
+  if (NOT HAD_ERROR AND EXISTS "${LIBRARY_DIR}")
+message(STATUS "Found compiler-rt directory: ${LIBRARY_DIR}")
+set(${dest} "${LIBRARY_DIR}" PARENT_SCOPE)
+  else()
+message(STATUS "Failed to find compiler-rt directory")
+  endif()
+endfunction()

Modified: libcxxabi/trunk/cmake/config-ix.cmake
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/cmake/config-ix.cmake?rev=299797&r1=299796&r2=299797&view=diff
==
--- libcxxabi/trunk/cmake/config-ix.cmake (original)
+++ libcxxabi/trunk/cmake/config-ix.cmake Fri Apr  7 15:10:41 2017
@@ -2,13 +2,45 @@ include(CheckLibraryExists)
 include(CheckCCompilerFlag)
 include(CheckCXXCompilerFlag)
 
+check_library_exists(c fopen "" LIBCXXABI_HAS_C_LIB)
+if (NOT LIBCXXABI_USE_C

[libunwind] r299798 - Revert "[CMake][libunwind] Use -nodefaultlibs for CMake checks"

2017-04-07 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Fri Apr  7 15:24:22 2017
New Revision: 299798

URL: http://llvm.org/viewvc/llvm-project?rev=299798&view=rev
Log:
Revert "[CMake][libunwind] Use -nodefaultlibs for CMake checks"

This reverts commit r299796.

Modified:
libunwind/trunk/cmake/config-ix.cmake

Modified: libunwind/trunk/cmake/config-ix.cmake
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/cmake/config-ix.cmake?rev=299798&r1=299797&r2=299798&view=diff
==
--- libunwind/trunk/cmake/config-ix.cmake (original)
+++ libunwind/trunk/cmake/config-ix.cmake Fri Apr  7 15:24:22 2017
@@ -3,35 +3,13 @@ include(CheckCCompilerFlag)
 include(CheckCXXCompilerFlag)
 include(CheckLibraryExists)
 
-check_library_exists(c fopen "" LIBUNWIND_HAS_C_LIB)
-
-# libunwind is built with -nodefaultlibs, so we want all our checks to also
-# use this option, otherwise we may end up with an inconsistency between
-# the flags we think we require during configuration (if the checks are
-# performed without -nodefaultlibs) and the flags that are actually
-# required during compilation (which has the -nodefaultlibs). libc is
-# required for the link to go through. We remove sanitizers from the
-# configuration checks to avoid spurious link errors.
-check_c_compiler_flag(-nodefaultlibs LIBUNWIND_HAS_NODEFAULTLIBS_FLAG)
-if (LIBUNWIND_HAS_NODEFAULTLIBS_FLAG)
-  set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nodefaultlibs")
-  if (LIBUNWIND_HAS_C_LIB)
-list(APPEND CMAKE_REQUIRED_LIBRARIES c)
-  endif ()
-  if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
-set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
-  endif ()
-  if (CMAKE_C_FLAGS MATCHES -fsanitize-coverage OR CMAKE_CXX_FLAGS MATCHES 
-fsanitize-coverage)
-set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} 
-fno-sanitize-coverage=edge,trace-cmp,indirect-calls,8bit-counters")
-  endif ()
-endif ()
-
 # Check compiler flags
 check_c_compiler_flag(-funwind-tables LIBUNWIND_HAS_FUNWIND_TABLES)
 check_cxx_compiler_flag(-fPIC LIBUNWIND_HAS_FPIC_FLAG)
 check_cxx_compiler_flag(-fno-exceptions   LIBUNWIND_HAS_NO_EXCEPTIONS_FLAG)
 check_cxx_compiler_flag(-fno-rtti LIBUNWIND_HAS_NO_RTTI_FLAG)
 check_cxx_compiler_flag(-fstrict-aliasing 
LIBUNWIND_HAS_FSTRICT_ALIASING_FLAG)
+check_cxx_compiler_flag(-nodefaultlibsLIBUNWIND_HAS_NODEFAULTLIBS_FLAG)
 check_cxx_compiler_flag(-nostdinc++   LIBUNWIND_HAS_NOSTDINCXX_FLAG)
 check_cxx_compiler_flag(-Wall LIBUNWIND_HAS_WALL_FLAG)
 check_cxx_compiler_flag(-WLIBUNWIND_HAS_W_FLAG)
@@ -66,6 +44,7 @@ if(LIBUNWIND_HAS_STD_CXX11)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
 endif()
 
+check_library_exists(c fopen "" LIBUNWIND_HAS_C_LIB)
 check_library_exists(dl dladdr "" LIBUNWIND_HAS_DL_LIB)
 check_library_exists(pthread pthread_once "" LIBUNWIND_HAS_PTHREAD_LIB)
 


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


Re: r299774 - Sema: prevent __declspec(naked) use on x64

2017-04-07 Thread Richard Smith via cfe-commits
On 7 April 2017 at 12:06, Aaron Ballman  wrote:

> On Fri, Apr 7, 2017 at 2:53 PM, Richard Smith 
> wrote:
> > On 7 Apr 2017 11:49 am, "David Majnemer via cfe-commits"
> >  wrote:
> >
> >
> >
> > On Fri, Apr 7, 2017 at 8:30 AM, Aaron Ballman via cfe-commits
> >  wrote:
> >>
> >> On Fri, Apr 7, 2017 at 11:13 AM, Saleem Abdulrasool via cfe-commits
> >>  wrote:
> >> > Author: compnerd
> >> > Date: Fri Apr  7 10:13:47 2017
> >> > New Revision: 299774
> >> >
> >> > URL: http://llvm.org/viewvc/llvm-project?rev=299774&view=rev
> >> > Log:
> >> > Sema: prevent __declspec(naked) use on x64
> >> >
> >> > MSDN (https://msdn.microsoft.com/en-us/library/h5w10wxs.aspx)
> indicates
> >> > that `__declspec(naked)` is only permitted on x86 and ARM targets.
> >> > Testing with cl does confirm this behaviour.  Provide a warning for
> use
> >> > of `__declspec(naked)` on x64.
> >>
> >> Your patch is not providing a warning, it's providing an error, which
> >> seems inappropriate (to me). Why is this attribute not silently
> >> ignored there instead?
> >
> >
> > FWIW, MSVC diagnoses this with an error: https://godbolt.org/g/T5sQr5
> >
> >
> > Is there a reason we can't support this? Was our existing support broken
> in
> > some way? We generally allow our features to be combined in arbitrary
> ways
> > unless there's a reason not to.
>
> For the __declspec spelling of the attribute, we shouldn't really do
> *more* than what Microsoft allows, should we (even if we can)?
>

Why not? What is the purpose / benefit of adding an arbitrary restriction
here, if the functionality naturally extends to other targets? (Also note
that we support __declspec for non-MS targets.) Of course, if this
*doesn't* work on other targets for some reason, then that might be a good
justification for not supporting it there.

As for error vs warning, I was mostly pointing out that (1) the commit
> comment doesn't match the behavior of the patch, which is always a
> concern, and (2) most of our attributes warn rather than err, unless
> there's a solid reason to err.


+1

If LLVM gets a naked attribute for a
> function and the architecture doesn't support the concept, what
> happens? I thought it ignored it (which suggests a warning rather than
> an error, to a certain extent), but I could be wrong.
>
> ~Aaron
>
> >
> >> (Btw, I did not see a review thread for this, did I miss one?) More
> >> comments below.
> >>
> >> >
> >> > Added:
> >> > cfe/trunk/test/Sema/declspec-naked.c
> >> > Modified:
> >> > cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> >> > cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> >> > cfe/trunk/test/Sema/ms-inline-asm.c
> >> >
> >> > Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> >> > URL:
> >> > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/
> DiagnosticSemaKinds.td?rev=299774&r1=299773&r2=299774&view=diff
> >> >
> >> > 
> ==
> >> > --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> >> > +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Apr  7
> >> > 10:13:47 2017
> >> > @@ -3231,7 +3231,8 @@ def err_attribute_regparm_invalid_number
> >> >"'regparm' parameter must be between 0 and %0 inclusive">;
> >> >  def err_attribute_not_supported_in_lang : Error<
> >> >"%0 attribute is not supported in %select{C|C++|Objective-C}1">;
> >> > -
> >> > +def err_attribute_not_supported_on_arch
> >> > +: Error<"%0 attribute is not supported on '%1'">;
> >> >
> >> >  // Clang-Specific Attributes
> >> >  def warn_attribute_iboutlet : Warning<
> >> >
> >> > Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> >> > URL:
> >> > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaDeclAttr.cpp?rev=299774&r1=299773&r2=299774&view=diff
> >> >
> >> > 
> ==
> >> > --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
> >> > +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Apr  7 10:13:47 2017
> >> > @@ -1923,6 +1923,17 @@ static void handleNakedAttr(Sema &S, Dec
> >> >   Attr.getName()))
> >> >  return;
> >> >
> >> > +  if (Attr.isDeclspecAttribute()) {
> >> > +const auto &Triple = S.getASTContext().
> getTargetInfo().getTriple();
> >>
> >> No need to have the Triple variable (which is a rather poor name given
> >> that it's also the type name).
> >> > +const auto &Arch = Triple.getArch();
> >>
> >> Do not use auto for either of these.
> >>, prior to which
> >> ~Aaron
> >>
> >> > +if (Arch != llvm::Triple::x86 &&
> >> > +(Arch != llvm::Triple::arm && Arch != llvm::Triple::thumb)) {
> >> > +  S.Diag(Attr.getLoc(), diag::err_attribute_not_
> supported_on_arch)
> >> > +  << Attr.getName() << Triple.getArchName();
> >> > +  return;
> >> > +}
> >> > +  }
> >> > +
> >> >D->addAttr(::new (S.Context) NakedAttr(Attr.getRange(), S.Cont

Re: r299774 - Sema: prevent __declspec(naked) use on x64

2017-04-07 Thread Saleem Abdulrasool via cfe-commits
Yeah, I shouldn't write commit messages late at night (I didn't commit
until the morning to keep an eye on the bots).

I opted to follow cl in terms of erroring.  I can make it a warning if you
feel strongly about that.

I think for naked functions being stricter is better.  The user can just as
easily accomplish the same thing with an out-of-line assembly input (or,
something terrible like module level assembly blocks).

With the GNU spelling, it restricts the function to just an asm blocks
without operands.  Furthermore, GCC restricts it to ARM, AVR, MSP430 (and
MCORE, NDS32, RL87, RX, SPU), which I think we should also do.  We
currently don't check that.

The declspec spelling is supposed to prevent inlining at all costs, and can
only be applied to non-member functions.  What's even more interesting is
that you don't have ASM blocks in ARM, so it being available is even more
questionable [1].  Plus, I imagine that unwinding would be pretty fragile
(since I don't think we could easily handle pdata/xdata emission in that
case).

Technically, it makes no sense for a target to not support the naked
attribute: it just elides the frame setup/tear down - we could just skip
functions with the naked attribute in PEI.  I don't think it's particularly
difficult to support the concept at the IR level.  The problem arises in
trying to analyze it.  If you want to completely skip that, why not just
use out-of-line assembly?  Or how do you generate unwinding information?

Am I overlooking a use case whuch cannot be accommodated with the same
guarantees without lulling the developer into a false sense of safety?

[1]: naked functions don't have a prologue/epilogue but you don't have an
ASM block, so how do add that?  Windows ABI requires a FP, RA frame setup,
how do you do that?  How do you generate the .pdata?

On Fri, Apr 7, 2017 at 12:06 PM Aaron Ballman via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> On Fri, Apr 7, 2017 at 2:53 PM, Richard Smith 
> wrote:
> > On 7 Apr 2017 11:49 am, "David Majnemer via cfe-commits"
> >  wrote:
> >
> >
> >
> > On Fri, Apr 7, 2017 at 8:30 AM, Aaron Ballman via cfe-commits
> >  wrote:
> >>
> >> On Fri, Apr 7, 2017 at 11:13 AM, Saleem Abdulrasool via cfe-commits
> >>  wrote:
> >> > Author: compnerd
> >> > Date: Fri Apr  7 10:13:47 2017
> >> > New Revision: 299774
> >> >
> >> > URL: http://llvm.org/viewvc/llvm-project?rev=299774&view=rev
> >> > Log:
> >> > Sema: prevent __declspec(naked) use on x64
> >> >
> >> > MSDN (https://msdn.microsoft.com/en-us/library/h5w10wxs.aspx)
> indicates
> >> > that `__declspec(naked)` is only permitted on x86 and ARM targets.
> >> > Testing with cl does confirm this behaviour.  Provide a warning for
> use
> >> > of `__declspec(naked)` on x64.
> >>
> >> Your patch is not providing a warning, it's providing an error, which
> >> seems inappropriate (to me). Why is this attribute not silently
> >> ignored there instead?
> >
> >
> > FWIW, MSVC diagnoses this with an error: https://godbolt.org/g/T5sQr5
> >
> >
> > Is there a reason we can't support this? Was our existing support broken
> in
> > some way? We generally allow our features to be combined in arbitrary
> ways
> > unless there's a reason not to.
>
> For the __declspec spelling of the attribute, we shouldn't really do
> *more* than what Microsoft allows, should we (even if we can)?
>
> As for error vs warning, I was mostly pointing out that (1) the commit
> comment doesn't match the behavior of the patch, which is always a
> concern, and (2) most of our attributes warn rather than err, unless
> there's a solid reason to err. If LLVM gets a naked attribute for a
> function and the architecture doesn't support the concept, what
> happens? I thought it ignored it (which suggests a warning rather than
> an error, to a certain extent), but I could be wrong.
>
> ~Aaron
>
> >
> >> (Btw, I did not see a review thread for this, did I miss one?) More
> >> comments below.
> >>
> >> >
> >> > Added:
> >> > cfe/trunk/test/Sema/declspec-naked.c
> >> > Modified:
> >> > cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> >> > cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> >> > cfe/trunk/test/Sema/ms-inline-asm.c
> >> >
> >> > Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> >> > URL:
> >> >
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=299774&r1=299773&r2=299774&view=diff
> >> >
> >> >
> ==
> >> > --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> >> > +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Apr  7
> >> > 10:13:47 2017
> >> > @@ -3231,7 +3231,8 @@ def err_attribute_regparm_invalid_number
> >> >"'regparm' parameter must be between 0 and %0 inclusive">;
> >> >  def err_attribute_not_supported_in_lang : Error<
> >> >"%0 attribute is not supported in %select{C|C++|Objective-C}1">;
> >> > -
> >> > +def err_attribute_not_s

r299800 - Toolchains: remove crtbegin on xwindows

2017-04-07 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Fri Apr  7 15:47:06 2017
New Revision: 299800

URL: http://llvm.org/viewvc/llvm-project?rev=299800&view=rev
Log:
Toolchains: remove crtbegin on xwindows

crtbegin is not really a proper windows support thing.  This was
duplicated when the toolchain was initially built.  If the injection of
crtbegin is needed, it can be done via the `/include` directive.
Furthermore, since `-fPIC` doesnt make sense on PE/COFF, crtbegin and
crtbeginS dont really need to be different.

Modified:
cfe/trunk/lib/Driver/ToolChains/CrossWindows.cpp
cfe/trunk/test/Driver/windows-cross.c

Modified: cfe/trunk/lib/Driver/ToolChains/CrossWindows.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/CrossWindows.cpp?rev=299800&r1=299799&r2=299800&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/CrossWindows.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/CrossWindows.cpp Fri Apr  7 15:47:06 2017
@@ -156,15 +156,6 @@ void tools::CrossWindows::Linker::Constr
 CmdArgs.push_back(Args.MakeArgString(ImpLib));
   }
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
-const std::string CRTPath(D.SysRoot + "/usr/lib/");
-const char *CRTBegin;
-
-CRTBegin =
-Args.hasArg(options::OPT_shared) ? "crtbeginS.obj" : "crtbegin.obj";
-CmdArgs.push_back(Args.MakeArgString(CRTPath + CRTBegin));
-  }
-
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   TC.AddFilePathLibArgs(Args, CmdArgs);
   AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);

Modified: cfe/trunk/test/Driver/windows-cross.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/windows-cross.c?rev=299800&r1=299799&r2=299800&view=diff
==
--- cfe/trunk/test/Driver/windows-cross.c (original)
+++ cfe/trunk/test/Driver/windows-cross.c Fri Apr  7 15:47:06 2017
@@ -1,27 +1,27 @@
 // RUN: %clang -### -target armv7-windows-itanium --sysroot 
%S/Inputs/Windows/ARM/8.1 -B %S/Inputs/Windows/ARM/8.1/usr/bin -fuse-ld=ld 
-stdlib=libstdc++ -rtlib=platform -o /dev/null %s 2>&1 \
 // RUN:   | FileCheck %s --check-prefix CHECK-BASIC
 
-// CHECK-BASIC: armv7-windows-itanium-ld" 
"--sysroot={{.*}}/Inputs/Windows/ARM/8.1" "-m" "thumb2pe" "-Bdynamic" "--entry" 
"mainCRTStartup" "--allow-multiple-definition" "-o" "{{[^"]*}}" 
"{{.*}}/Inputs/Windows/ARM/8.1/usr/lib/crtbegin.obj" 
"-L{{.*}}/Inputs/Windows/ARM/8.1/usr/lib" 
"-L{{.*}}/Inputs/Windows/ARM/8.1/usr/lib/gcc" "{{.*}}.o" "-lmsvcrt" "-lgcc" 
"--as-needed" "-lgcc_s" "--no-as-needed"
+// CHECK-BASIC: armv7-windows-itanium-ld" 
"--sysroot={{.*}}/Inputs/Windows/ARM/8.1" "-m" "thumb2pe" "-Bdynamic" "--entry" 
"mainCRTStartup" "--allow-multiple-definition" "-o" "{{[^"]*}}" 
"-L{{.*}}/Inputs/Windows/ARM/8.1/usr/lib" 
"-L{{.*}}/Inputs/Windows/ARM/8.1/usr/lib/gcc" "{{.*}}.o" "-lmsvcrt" "-lgcc" 
"--as-needed" "-lgcc_s" "--no-as-needed"
 
 // RUN: %clang -### -target armv7-windows-itanium --sysroot 
%s/Inputs/Windows/ARM/8.1 -B %S/Inputs/Windows/ARM/8.1/usr/bin -fuse-ld=ld 
-rtlib=compiler-rt -stdlib=libstdc++ -o /dev/null %s 2>&1 \
 // RUN:   | FileCheck %s --check-prefix CHECK-RTLIB
 
-// CHECK-RTLIB: armv7-windows-itanium-ld" 
"--sysroot={{.*}}/Inputs/Windows/ARM/8.1" "-m" "thumb2pe" "-Bdynamic" "--entry" 
"mainCRTStartup" "--allow-multiple-definition" "-o" "{{[^"]*}}" 
"{{.*}}/Inputs/Windows/ARM/8.1/usr/lib/crtbegin.obj" 
"-L{{.*}}/Inputs/Windows/ARM/8.1/usr/lib" 
"-L{{.*}}/Inputs/Windows/ARM/8.1/usr/lib/gcc" "{{.*}}.o" "-lmsvcrt" 
"{{.*[\\/]}}clang_rt.builtins-arm.lib"
+// CHECK-RTLIB: armv7-windows-itanium-ld" 
"--sysroot={{.*}}/Inputs/Windows/ARM/8.1" "-m" "thumb2pe" "-Bdynamic" "--entry" 
"mainCRTStartup" "--allow-multiple-definition" "-o" "{{[^"]*}}" 
"-L{{.*}}/Inputs/Windows/ARM/8.1/usr/lib" 
"-L{{.*}}/Inputs/Windows/ARM/8.1/usr/lib/gcc" "{{.*}}.o" "-lmsvcrt" 
"{{.*[\\/]}}clang_rt.builtins-arm.lib"
 
 // RUN: %clang -### -target armv7-windows-itanium --sysroot 
%S/Inputs/Windows/ARM/8.1 -B %S/Inputs/Windows/ARM/8.1/usr/bin -fuse-ld=ld 
-rtlib=compiler-rt -stdlib=libc++ -o /dev/null %s 2>&1 \
 // RUN:   | FileCheck %s --check-prefix CHECK-C-LIBCXX
 
-// CHECK-C-LIBCXX: armv7-windows-itanium-ld" 
"--sysroot={{.*}}/Inputs/Windows/ARM/8.1" "-m" "thumb2pe" "-Bdynamic" "--entry" 
"mainCRTStartup" "--allow-multiple-definition" "-o" "{{[^"]*}}" 
"{{.*}}/Inputs/Windows/ARM/8.1/usr/lib/crtbegin.obj" "{{.*}}.o" "-lmsvcrt" 
"{{.*[\\/]}}clang_rt.builtins-arm.lib"
+// CHECK-C-LIBCXX: armv7-windows-itanium-ld" 
"--sysroot={{.*}}/Inputs/Windows/ARM/8.1" "-m" "thumb2pe" "-Bdynamic" "--entry" 
"mainCRTStartup" "--allow-multiple-definition" "-o" "{{[^"]*}}" "{{.*}}.o" 
"-lmsvcrt" "{{.*[\\/]}}clang_rt.builtins-arm.lib"
 
 // RUN: %clangxx -### -target armv7-windows-itanium --sysroot 
%S/Inputs/Windows/ARM/8.1 -B %S/Inputs/Windows/ARM/8.1/usr/bin -fuse-ld=ld 
-rtlib=compiler-rt -stdlib=libc++ -o /dev/null %s 2>&1 \
 // R

r299806 - [cfi] Emit __cfi_check stub in the frontend.

2017-04-07 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Fri Apr  7 18:00:38 2017
New Revision: 299806

URL: http://llvm.org/viewvc/llvm-project?rev=299806&view=rev
Log:
[cfi] Emit __cfi_check stub in the frontend.

Previously __cfi_check was created in LTO optimization pipeline, which
means LLD has no way of knowing about the existence of this symbol
without rescanning the LTO output object. As a result, LLD fails to
export __cfi_check, even when given --export-dynamic-symbol flag.

Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGen/cfi-check-fail.c

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=299806&r1=299805&r2=299806&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Apr  7 18:00:38 2017
@@ -2783,6 +2783,24 @@ void CodeGenFunction::EmitCfiSlowPathChe
   EmitBlock(Cont);
 }
 
+// Emit a stub for __cfi_check function so that the linker knows about this
+// symbol in LTO mode.
+void CodeGenFunction::EmitCfiCheckStub() {
+  llvm::Module *M = &CGM.getModule();
+  auto &Ctx = M->getContext();
+  llvm::Function *F = llvm::Function::Create(
+  llvm::FunctionType::get(VoidTy, {Int64Ty, Int8PtrTy, Int8PtrTy}, false),
+  llvm::GlobalValue::WeakAnyLinkage, "__cfi_check", M);
+  llvm::BasicBlock *BB = llvm::BasicBlock::Create(Ctx, "entry", F);
+  // FIXME: consider emitting an intrinsic call like
+  // call void @llvm.cfi_check(i64 %0, i8* %1, i8* %2)
+  // which can be lowered in CrossDSOCFI pass to the actual contents of
+  // __cfi_check. This would allow inlining of __cfi_check calls.
+  llvm::CallInst::Create(
+  llvm::Intrinsic::getDeclaration(M, llvm::Intrinsic::trap), "", BB);
+  llvm::ReturnInst::Create(Ctx, nullptr, BB);
+}
+
 // This function is basically a switch over the CFI failure kind, which is
 // extracted from CFICheckFailData (1st function argument). Each case is either
 // llvm.trap or a call to one of the two runtime handlers, based on

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=299806&r1=299805&r2=299806&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Fri Apr  7 18:00:38 2017
@@ -3524,6 +3524,9 @@ public:
   /// "trap-func-name" if specified.
   llvm::CallInst *EmitTrapCall(llvm::Intrinsic::ID IntrID);
 
+  /// \brief Emit a stub for the cross-DSO CFI check function.
+  void EmitCfiCheckStub();
+
   /// \brief Emit a cross-DSO CFI failure handling function.
   void EmitCfiCheckFail();
 

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=299806&r1=299805&r2=299806&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Apr  7 18:00:38 2017
@@ -406,8 +406,10 @@ void CodeGenModule::Release() {
   EmitDeferredUnusedCoverageMappings();
   if (CoverageMapping)
 CoverageMapping->emit();
-  if (CodeGenOpts.SanitizeCfiCrossDso)
+  if (CodeGenOpts.SanitizeCfiCrossDso) {
 CodeGenFunction(*this).EmitCfiCheckFail();
+CodeGenFunction(*this).EmitCfiCheckStub();
+  }
   emitAtAvailableLinkGuard();
   emitLLVMUsed();
   if (SanStats)

Modified: cfe/trunk/test/CodeGen/cfi-check-fail.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/cfi-check-fail.c?rev=299806&r1=299805&r2=299806&view=diff
==
--- cfe/trunk/test/CodeGen/cfi-check-fail.c (original)
+++ cfe/trunk/test/CodeGen/cfi-check-fail.c Fri Apr  7 18:00:38 2017
@@ -72,3 +72,8 @@ void caller(void (*f)()) {
 
 // CHECK: [[CONT5]]:
 // CHECK:   ret void
+
+// CHECK: define weak void @__cfi_check(i64, i8*, i8*)
+// CHECK-NOT: }
+// CHECK: call void @llvm.trap()
+// CHECK-NEXT: ret void


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