[clang-tools-extra] [clang-tidy] Enable plugin tests with LLVM_INSTALL_TOOLCHAIN_ONLY (PR #90370)

2024-05-01 Thread Igor Kudrin via cfe-commits

https://github.com/igorkudrin closed 
https://github.com/llvm/llvm-project/pull/90370
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Enable plugin tests with LLVM_INSTALL_TOOLCHAIN_ONLY (PR #90370)

2024-04-27 Thread Igor Kudrin via cfe-commits

igorkudrin wrote:

> I think out of tree builds of clang-tidy (back in the svn days, when people 
> did partial checkouts of individual projects) probably needed this to be able 
> to correctly correctly find the right headers. Maybe standalone builds aren't 
> permitted anymore? I think I mentioned this a bit in earlier revisions of 
> that PR https://reviews.llvm.org/D00#3284178

I don't have much to say about standalone builds. I hope to hear about them 
from the people who mentioned them in 
[D00](https://reviews.llvm.org/D00). But as far as I can see, 
`clang-tidy-headers` is an empty target, with no dependencies or actions; at 
least it looks like that when building with `ninja` on Linux or Windows. It 
seems unlikely that this is different for standalone builds. Removing the 
dependency on an empty target should be safe.

https://github.com/llvm/llvm-project/pull/90370
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Enable plugin tests with LLVM_INSTALL_TOOLCHAIN_ONLY (PR #90370)

2024-04-27 Thread Igor Kudrin via cfe-commits

https://github.com/igorkudrin created 
https://github.com/llvm/llvm-project/pull/90370

The only reason for the removed condition was that there was a dependency for 
`CTTestTidyModule` on the `clang-tidy-headers` target, which was only created 
under the same `NOT LLVM_INSTALL_TOOLCHAIN_ONLY` condition. It looks like this 
target is not needed for `CTTestTidyModule` to build and run, so the dependency 
can be removed along with the condition.

See also https://reviews.llvm.org/D00 for earlier discussions.

>From c3f10956436d2780219e2404db37aa7dceb168e3 Mon Sep 17 00:00:00 2001
From: Igor Kudrin 
Date: Sat, 27 Apr 2024 17:32:35 -0700
Subject: [PATCH] [clang-tidy] Enable plugin tests with
 LLVM_INSTALL_TOOLCHAIN_ONLY

The only reason for the removed condition was that there was a
dependency for `CTTestTidyModule` on the `clang-tidy-headers` target,
which was only created under the `NOT LLVM_INSTALL_TOOLCHAIN_ONLY`
condition. In fact, this target is not needed for `CTTestTidyModule`
to build and run.
---
 clang-tools-extra/test/CMakeLists.txt | 45 +++
 clang-tools-extra/test/lit.site.cfg.py.in |  2 +-
 2 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/clang-tools-extra/test/CMakeLists.txt 
b/clang-tools-extra/test/CMakeLists.txt
index f4c529ee8af207..7a1c168e22f97c 100644
--- a/clang-tools-extra/test/CMakeLists.txt
+++ b/clang-tools-extra/test/CMakeLists.txt
@@ -67,33 +67,30 @@ foreach(dep ${LLVM_UTILS_DEPS})
   endif()
 endforeach()
 
-if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
-  if (NOT WIN32 OR NOT LLVM_LINK_LLVM_DYLIB)
-llvm_add_library(
-CTTestTidyModule
-MODULE clang-tidy/CTTestTidyModule.cpp
-PLUGIN_TOOL clang-tidy
-DEPENDS clang-tidy-headers)
-  endif()
+if (NOT WIN32 OR NOT LLVM_LINK_LLVM_DYLIB)
+  llvm_add_library(
+  CTTestTidyModule
+  MODULE clang-tidy/CTTestTidyModule.cpp
+  PLUGIN_TOOL clang-tidy)
+endif()
 
-  if(CLANG_BUILT_STANDALONE)
-# LLVMHello library is needed below
-if (EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Transforms/Hello
-   AND NOT TARGET LLVMHello)
-  add_subdirectory(${LLVM_MAIN_SRC_DIR}/lib/Transforms/Hello
-lib/Transforms/Hello)
-endif()
+if(CLANG_BUILT_STANDALONE)
+  # LLVMHello library is needed below
+  if (EXISTS ${LLVM_MAIN_SRC_DIR}/lib/Transforms/Hello
+  AND NOT TARGET LLVMHello)
+add_subdirectory(${LLVM_MAIN_SRC_DIR}/lib/Transforms/Hello
+  lib/Transforms/Hello)
   endif()
+endif()
 
-  if(TARGET CTTestTidyModule)
-  list(APPEND CLANG_TOOLS_TEST_DEPS CTTestTidyModule LLVMHello)
-  target_include_directories(CTTestTidyModule PUBLIC BEFORE 
"${CLANG_TOOLS_SOURCE_DIR}")
-  if(CLANG_PLUGIN_SUPPORT AND (WIN32 OR CYGWIN))
-set(LLVM_LINK_COMPONENTS
-  Support
-)
-  endif()
-  endif()
+if(TARGET CTTestTidyModule)
+list(APPEND CLANG_TOOLS_TEST_DEPS CTTestTidyModule LLVMHello)
+target_include_directories(CTTestTidyModule PUBLIC BEFORE 
"${CLANG_TOOLS_SOURCE_DIR}")
+if(CLANG_PLUGIN_SUPPORT AND (WIN32 OR CYGWIN))
+  set(LLVM_LINK_COMPONENTS
+Support
+  )
+endif()
 endif()
 
 add_lit_testsuite(check-clang-extra "Running clang-tools-extra/test"
diff --git a/clang-tools-extra/test/lit.site.cfg.py.in 
b/clang-tools-extra/test/lit.site.cfg.py.in
index 4eb830a1baf1f1..e6503a4c097cac 100644
--- a/clang-tools-extra/test/lit.site.cfg.py.in
+++ b/clang-tools-extra/test/lit.site.cfg.py.in
@@ -10,7 +10,7 @@ config.python_executable = "@Python3_EXECUTABLE@"
 config.target_triple = "@LLVM_TARGET_TRIPLE@"
 config.host_triple = "@LLVM_HOST_TRIPLE@"
 config.clang_tidy_staticanalyzer = @CLANG_TIDY_ENABLE_STATIC_ANALYZER@
-config.has_plugins = @CLANG_PLUGIN_SUPPORT@ & ~@LLVM_INSTALL_TOOLCHAIN_ONLY@
+config.has_plugins = @CLANG_PLUGIN_SUPPORT@
 # Support substitution of the tools and libs dirs with user parameters. This is
 # used when we can't determine the tool dir at configuration time.
 config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")

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


[clang-tools-extra] [llvm] [clang] [compiler-rt] [flang] [lldb] [lld] [libcxx] [YAMLParser] Unfold multi-line scalar values (PR #70898)

2023-11-01 Thread Igor Kudrin via cfe-commits

https://github.com/igorkudrin updated 
https://github.com/llvm/llvm-project/pull/70898

>From 113c03bbf773c71d329ab2afd063753365e4ac68 Mon Sep 17 00:00:00 2001
From: Igor Kudrin 
Date: Thu, 26 Oct 2023 13:19:08 -0700
Subject: [PATCH] [YAMLParser] Unfold multi-line scalar values

Long scalar values can be split into multiple lines to improve
readability. The rules are described in Section 6.5. "Line Folding",
https://yaml.org/spec/1.2.2/#65-line-folding. In addition, for flow
scalar styles, the Spec states that "All leading and trailing white
space characters on each line are excluded from the content",
https://yaml.org/spec/1.2.2/#73-flow-scalar-styles.

The patch implements these unfolding rules for double-quoted,
single-quoted, and plain scalars.
---
 llvm/include/llvm/Support/YAMLParser.h  |   9 +-
 llvm/lib/Support/YAMLParser.cpp | 364 +---
 llvm/test/YAMLParser/spec-09-01.test|  11 +-
 llvm/test/YAMLParser/spec-09-02.test|  31 +-
 llvm/test/YAMLParser/spec-09-03.test|   7 +-
 llvm/test/YAMLParser/spec-09-04.test|   3 +-
 llvm/test/YAMLParser/spec-09-05.test|   7 +-
 llvm/test/YAMLParser/spec-09-06.test|   3 +-
 llvm/test/YAMLParser/spec-09-07.test|  11 +-
 llvm/test/YAMLParser/spec-09-08.test|  15 +-
 llvm/test/YAMLParser/spec-09-09.test|   7 +-
 llvm/test/YAMLParser/spec-09-10.test|   3 +-
 llvm/test/YAMLParser/spec-09-11.test|   6 +-
 llvm/test/YAMLParser/spec-09-13.test|  11 +-
 llvm/test/YAMLParser/spec-09-16.test|  17 +-
 llvm/test/YAMLParser/spec-09-17.test|   3 +-
 llvm/test/YAMLParser/spec1.2-07-05.test |   8 +
 llvm/test/YAMLParser/spec1.2-07-06.test |   7 +
 llvm/test/YAMLParser/spec1.2-07-09.test |   7 +
 llvm/test/YAMLParser/spec1.2-07-12.test |   7 +
 llvm/test/YAMLParser/spec1.2-07-14.test |  23 ++
 21 files changed, 367 insertions(+), 193 deletions(-)
 create mode 100644 llvm/test/YAMLParser/spec1.2-07-05.test
 create mode 100644 llvm/test/YAMLParser/spec1.2-07-06.test
 create mode 100644 llvm/test/YAMLParser/spec1.2-07-09.test
 create mode 100644 llvm/test/YAMLParser/spec1.2-07-12.test
 create mode 100644 llvm/test/YAMLParser/spec1.2-07-14.test

diff --git a/llvm/include/llvm/Support/YAMLParser.h 
b/llvm/include/llvm/Support/YAMLParser.h
index f4767641647c217..9d95a1e13a0dff4 100644
--- a/llvm/include/llvm/Support/YAMLParser.h
+++ b/llvm/include/llvm/Support/YAMLParser.h
@@ -240,9 +240,14 @@ class ScalarNode final : public Node {
 private:
   StringRef Value;
 
-  StringRef unescapeDoubleQuoted(StringRef UnquotedValue,
- StringRef::size_type Start,
+  StringRef getDoubleQuotedValue(StringRef UnquotedValue,
  SmallVectorImpl ) const;
+
+  static StringRef getSingleQuotedValue(StringRef RawValue,
+SmallVectorImpl );
+
+  static StringRef getPlainValue(StringRef RawValue,
+ SmallVectorImpl );
 };
 
 /// A block scalar node is an opaque datum that can be presented as a
diff --git a/llvm/lib/Support/YAMLParser.cpp b/llvm/lib/Support/YAMLParser.cpp
index 1422e40f91944ae..96b9aa95a96b3a6 100644
--- a/llvm/lib/Support/YAMLParser.cpp
+++ b/llvm/lib/Support/YAMLParser.cpp
@@ -2030,187 +2030,219 @@ bool Node::failed() const {
 }
 
 StringRef ScalarNode::getValue(SmallVectorImpl ) const {
-  // TODO: Handle newlines properly. We need to remove leading whitespace.
-  if (Value[0] == '"') { // Double quoted.
-// Pull off the leading and trailing "s.
-StringRef UnquotedValue = Value.substr(1, Value.size() - 2);
-// Search for characters that would require unescaping the value.
-StringRef::size_type i = UnquotedValue.find_first_of("\\\r\n");
-if (i != StringRef::npos)
-  return unescapeDoubleQuoted(UnquotedValue, i, Storage);
+  if (Value[0] == '"')
+return getDoubleQuotedValue(Value, Storage);
+  if (Value[0] == '\'')
+return getSingleQuotedValue(Value, Storage);
+  return getPlainValue(Value, Storage);
+}
+
+static StringRef
+parseScalarValue(StringRef UnquotedValue, SmallVectorImpl ,
+ StringRef LookupChars,
+ std::function &)>
+ UnescapeCallback) {
+  size_t I = UnquotedValue.find_first_of(LookupChars);
+  if (I == StringRef::npos)
 return UnquotedValue;
-  } else if (Value[0] == '\'') { // Single quoted.
-// Pull off the leading and trailing 's.
-StringRef UnquotedValue = Value.substr(1, Value.size() - 2);
-StringRef::size_type i = UnquotedValue.find('\'');
-if (i != StringRef::npos) {
-  // We're going to need Storage.
-  Storage.clear();
-  Storage.reserve(UnquotedValue.size());
-  for (; i != StringRef::npos; i = UnquotedValue.find('\'')) {
-StringRef Valid(UnquotedValue.begin(), i);
-llvm::append_range(Storage, Valid);
-Storage.push_back('\'');
-UnquotedValue = UnquotedValue.substr(i + 2);
-  }
-  

[lld] [lldb] [flang] [libcxx] [compiler-rt] [clang-tools-extra] [llvm] [clang] [YAMLParser] Unfold multi-line scalar values (PR #70898)

2023-11-01 Thread Igor Kudrin via cfe-commits

https://github.com/igorkudrin updated 
https://github.com/llvm/llvm-project/pull/70898

>From 113c03bbf773c71d329ab2afd063753365e4ac68 Mon Sep 17 00:00:00 2001
From: Igor Kudrin 
Date: Thu, 26 Oct 2023 13:19:08 -0700
Subject: [PATCH] [YAMLParser] Unfold multi-line scalar values

Long scalar values can be split into multiple lines to improve
readability. The rules are described in Section 6.5. "Line Folding",
https://yaml.org/spec/1.2.2/#65-line-folding. In addition, for flow
scalar styles, the Spec states that "All leading and trailing white
space characters on each line are excluded from the content",
https://yaml.org/spec/1.2.2/#73-flow-scalar-styles.

The patch implements these unfolding rules for double-quoted,
single-quoted, and plain scalars.
---
 llvm/include/llvm/Support/YAMLParser.h  |   9 +-
 llvm/lib/Support/YAMLParser.cpp | 364 +---
 llvm/test/YAMLParser/spec-09-01.test|  11 +-
 llvm/test/YAMLParser/spec-09-02.test|  31 +-
 llvm/test/YAMLParser/spec-09-03.test|   7 +-
 llvm/test/YAMLParser/spec-09-04.test|   3 +-
 llvm/test/YAMLParser/spec-09-05.test|   7 +-
 llvm/test/YAMLParser/spec-09-06.test|   3 +-
 llvm/test/YAMLParser/spec-09-07.test|  11 +-
 llvm/test/YAMLParser/spec-09-08.test|  15 +-
 llvm/test/YAMLParser/spec-09-09.test|   7 +-
 llvm/test/YAMLParser/spec-09-10.test|   3 +-
 llvm/test/YAMLParser/spec-09-11.test|   6 +-
 llvm/test/YAMLParser/spec-09-13.test|  11 +-
 llvm/test/YAMLParser/spec-09-16.test|  17 +-
 llvm/test/YAMLParser/spec-09-17.test|   3 +-
 llvm/test/YAMLParser/spec1.2-07-05.test |   8 +
 llvm/test/YAMLParser/spec1.2-07-06.test |   7 +
 llvm/test/YAMLParser/spec1.2-07-09.test |   7 +
 llvm/test/YAMLParser/spec1.2-07-12.test |   7 +
 llvm/test/YAMLParser/spec1.2-07-14.test |  23 ++
 21 files changed, 367 insertions(+), 193 deletions(-)
 create mode 100644 llvm/test/YAMLParser/spec1.2-07-05.test
 create mode 100644 llvm/test/YAMLParser/spec1.2-07-06.test
 create mode 100644 llvm/test/YAMLParser/spec1.2-07-09.test
 create mode 100644 llvm/test/YAMLParser/spec1.2-07-12.test
 create mode 100644 llvm/test/YAMLParser/spec1.2-07-14.test

diff --git a/llvm/include/llvm/Support/YAMLParser.h 
b/llvm/include/llvm/Support/YAMLParser.h
index f4767641647c217..9d95a1e13a0dff4 100644
--- a/llvm/include/llvm/Support/YAMLParser.h
+++ b/llvm/include/llvm/Support/YAMLParser.h
@@ -240,9 +240,14 @@ class ScalarNode final : public Node {
 private:
   StringRef Value;
 
-  StringRef unescapeDoubleQuoted(StringRef UnquotedValue,
- StringRef::size_type Start,
+  StringRef getDoubleQuotedValue(StringRef UnquotedValue,
  SmallVectorImpl ) const;
+
+  static StringRef getSingleQuotedValue(StringRef RawValue,
+SmallVectorImpl );
+
+  static StringRef getPlainValue(StringRef RawValue,
+ SmallVectorImpl );
 };
 
 /// A block scalar node is an opaque datum that can be presented as a
diff --git a/llvm/lib/Support/YAMLParser.cpp b/llvm/lib/Support/YAMLParser.cpp
index 1422e40f91944ae..96b9aa95a96b3a6 100644
--- a/llvm/lib/Support/YAMLParser.cpp
+++ b/llvm/lib/Support/YAMLParser.cpp
@@ -2030,187 +2030,219 @@ bool Node::failed() const {
 }
 
 StringRef ScalarNode::getValue(SmallVectorImpl ) const {
-  // TODO: Handle newlines properly. We need to remove leading whitespace.
-  if (Value[0] == '"') { // Double quoted.
-// Pull off the leading and trailing "s.
-StringRef UnquotedValue = Value.substr(1, Value.size() - 2);
-// Search for characters that would require unescaping the value.
-StringRef::size_type i = UnquotedValue.find_first_of("\\\r\n");
-if (i != StringRef::npos)
-  return unescapeDoubleQuoted(UnquotedValue, i, Storage);
+  if (Value[0] == '"')
+return getDoubleQuotedValue(Value, Storage);
+  if (Value[0] == '\'')
+return getSingleQuotedValue(Value, Storage);
+  return getPlainValue(Value, Storage);
+}
+
+static StringRef
+parseScalarValue(StringRef UnquotedValue, SmallVectorImpl ,
+ StringRef LookupChars,
+ std::function &)>
+ UnescapeCallback) {
+  size_t I = UnquotedValue.find_first_of(LookupChars);
+  if (I == StringRef::npos)
 return UnquotedValue;
-  } else if (Value[0] == '\'') { // Single quoted.
-// Pull off the leading and trailing 's.
-StringRef UnquotedValue = Value.substr(1, Value.size() - 2);
-StringRef::size_type i = UnquotedValue.find('\'');
-if (i != StringRef::npos) {
-  // We're going to need Storage.
-  Storage.clear();
-  Storage.reserve(UnquotedValue.size());
-  for (; i != StringRef::npos; i = UnquotedValue.find('\'')) {
-StringRef Valid(UnquotedValue.begin(), i);
-llvm::append_range(Storage, Valid);
-Storage.push_back('\'');
-UnquotedValue = UnquotedValue.substr(i + 2);
-  }
-  

[clang] 43c307f - [CMake] Add llvm-lib to Clang bootstrap dependency for LTO builds on Windows

2023-04-20 Thread Igor Kudrin via cfe-commits

Author: Igor Kudrin
Date: 2023-04-20T17:02:17-07:00
New Revision: 43c307fd690ffa97877f371ff18530fcd0bddd82

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

LOG: [CMake] Add llvm-lib to Clang bootstrap dependency for LTO builds on 
Windows

Without this dependency, it is possible that llvm-lib.exe will not be
built, in which case CMake will try to use lib.exe to build libraries,
but this tool cannot handle bitcode files.

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

Added: 


Modified: 
clang/CMakeLists.txt

Removed: 




diff  --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 1fff005d65251..4508ea4c77aa5 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -613,6 +613,9 @@ if (CLANG_ENABLE_BOOTSTRAP)
   # variable, and have LLVM's CMake append the envar to the archiver calls.
   set(LTO_LIBRARY 
-DDARWIN_LTO_LIBRARY=${LLVM_SHLIB_OUTPUT_INTDIR}/libLTO.dylib
 -DDYLD_LIBRARY_PATH=${LLVM_LIBRARY_OUTPUT_INTDIR})
+elseif(MSVC)
+  add_dependencies(clang-bootstrap-deps llvm-lib)
+  set(${CLANG_STAGE}_AR -DCMAKE_AR=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-lib)
 elseif(NOT WIN32)
   add_dependencies(clang-bootstrap-deps llvm-ar llvm-ranlib)
   if(NOT BOOTSTRAP_LLVM_ENABLE_LLD AND LLVM_BINUTILS_INCDIR)



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


[clang] 7352f42 - [clang-tblgen] Fix non-determinism in generating AttrSubMatchRulesParserStringSwitches.inc

2021-11-09 Thread Igor Kudrin via cfe-commits

Author: Igor Kudrin
Date: 2021-11-10T10:08:06+07:00
New Revision: 7352f42cdc3c44038408edcdc4eb9890546020eb

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

LOG: [clang-tblgen] Fix non-determinism in generating 
AttrSubMatchRulesParserStringSwitches.inc

llvm::MapVector, compared to std::map, guarantees the same iteration
order in different runs.

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

Added: 


Modified: 
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 2a55a5eb59581..c692e8b5b6bc8 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -16,6 +16,7 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
@@ -2043,7 +2044,7 @@ void 
PragmaClangAttributeSupport::generateParsingHelpers(raw_ostream ) {
   OS << "  return None;\n";
   OS << "}\n\n";
 
-  std::map>
+  llvm::MapVector>
   SubMatchRules;
   for (const auto  : Rules) {
 if (!Rule.isSubRule())



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


[clang] 5b7ea8e - [clang-tblgen] Fix non-determinism in generating AttributeReference.rst

2021-11-09 Thread Igor Kudrin via cfe-commits

Author: Igor Kudrin
Date: 2021-11-10T10:08:07+07:00
New Revision: 5b7ea8e62921e53fdea73d948eb0d48c071d4b73

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

LOG: [clang-tblgen] Fix non-determinism in generating AttributeReference.rst

As for now, the categories are printed in an arbitrary order which
depends on the addresses of dynamically allocated objects. The patch
sorts them in an alphabetical order thus making the output stable.

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

Added: 


Modified: 
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index c692e8b5b6bc..fe05a3466af1 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -4433,7 +4433,13 @@ void EmitClangAttrDocs(RecordKeeper , 
raw_ostream ) {
   // Gather the Documentation lists from each of the attributes, based on the
   // category provided.
   std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
-  std::map> SplitDocs;
+  struct CategoryLess {
+bool operator()(const Record *L, const Record *R) const {
+  return L->getValueAsString("Name") < R->getValueAsString("Name");
+}
+  };
+  std::map, CategoryLess>
+  SplitDocs;
   for (const auto *A : Attrs) {
 const Record  = *A;
 std::vector Docs = Attr.getValueAsListOfDefs("Documentation");



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


[clang] a0c9ec1 - [Driver] Honor "-gdwarf-N" at any position for assembler sources

2021-02-17 Thread Igor Kudrin via cfe-commits

Author: Igor Kudrin
Date: 2021-02-18T10:36:42+07:00
New Revision: a0c9ec1f5e70e8f15da170667b2a8e63d024f3ab

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

LOG: [Driver] Honor "-gdwarf-N" at any position for assembler sources

This fixes an issue when "-gdwarf-N" switch was ignored if it was given
before another debug option.

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/debug-options-as.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 2ae6c400f692..eaaef6b78ffb 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -981,6 +981,14 @@ static unsigned DwarfVersionNum(StringRef ArgValue) {
   .Default(0);
 }
 
+// Find a DWARF format version option.
+// This function is a complementary for DwarfVersionNum().
+static const Arg *getDwarfNArg(const ArgList ) {
+  return Args.getLastArg(options::OPT_gdwarf_2, options::OPT_gdwarf_3,
+ options::OPT_gdwarf_4, options::OPT_gdwarf_5,
+ options::OPT_gdwarf);
+}
+
 static void RenderDebugEnablingArgs(const ArgList , ArgStringList 
,
 codegenoptions::DebugInfoKind 
DebugInfoKind,
 unsigned DwarfVersion,
@@ -3848,9 +3856,7 @@ static void renderDebugOptions(const ToolChain , const 
Driver ,
   }
 
   // If a -gdwarf argument appeared, remember it.
-  const Arg *GDwarfN = Args.getLastArg(
-  options::OPT_gdwarf_2, options::OPT_gdwarf_3, options::OPT_gdwarf_4,
-  options::OPT_gdwarf_5, options::OPT_gdwarf);
+  const Arg *GDwarfN = getDwarfNArg(Args);
   bool EmitDwarf = false;
   if (GDwarfN) {
 if (checkDebugInfoOption(GDwarfN, Args, D, TC))
@@ -7168,18 +7174,14 @@ void ClangAs::ConstructJob(Compilation , const 
JobAction ,
   // Forward -g and handle debug info related flags, assuming we are dealing
   // with an actual assembly file.
   bool WantDebug = false;
-  unsigned DwarfVersion = 0;
   Args.ClaimAllArgs(options::OPT_g_Group);
-  if (Arg *A = Args.getLastArg(options::OPT_g_Group)) {
+  if (Arg *A = Args.getLastArg(options::OPT_g_Group))
 WantDebug = !A->getOption().matches(options::OPT_g0) &&
 !A->getOption().matches(options::OPT_ggdb0);
-if (WantDebug)
-  DwarfVersion = DwarfVersionNum(A->getSpelling());
-  }
 
-  unsigned DefaultDwarfVersion = ParseDebugDefaultVersion(getToolChain(), 
Args);
-  if (DwarfVersion == 0)
-DwarfVersion = DefaultDwarfVersion;
+  unsigned DwarfVersion = ParseDebugDefaultVersion(getToolChain(), Args);
+  if (const Arg *GDwarfN = getDwarfNArg(Args))
+DwarfVersion = DwarfVersionNum(GDwarfN->getSpelling());
 
   if (DwarfVersion == 0)
 DwarfVersion = getToolChain().GetDefaultDwarfVersion();

diff  --git a/clang/test/Driver/debug-options-as.c 
b/clang/test/Driver/debug-options-as.c
index f36188e8ab2b..90062d7d 100644
--- a/clang/test/Driver/debug-options-as.c
+++ b/clang/test/Driver/debug-options-as.c
@@ -60,3 +60,18 @@
 // GDWARF64_VER:  error: invalid argument '-gdwarf64' only allowed with 
'DWARFv3 or greater'
 // GDWARF64_32ARCH: error: invalid argument '-gdwarf64' only allowed with '64 
bit architecture'
 // GDWARF64_ELF: error: invalid argument '-gdwarf64' only allowed with 'ELF 
platforms'
+
+// Check that -gdwarf-N can be placed before other options of the "-g" group.
+// RUN: %clang -### -c -g -gdwarf-3 -target %itanium_abi_triple 
-fintegrated-as -x assembler %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=DWARF3 %s
+// RUN: %clang -### -c -gdwarf-3 -g -target %itanium_abi_triple 
-fintegrated-as -x assembler %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=DWARF3 %s
+// RUN: %clang -### -c -g -gdwarf-5 -target %itanium_abi_triple 
-fintegrated-as -x assembler %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=DWARF5 %s
+// RUN: %clang -### -c -gdwarf-5 -g -target %itanium_abi_triple 
-fintegrated-as -x assembler %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=DWARF5 %s
+
+// DWARF3: "-cc1as"
+// DWARF3: "-dwarf-version=3"
+// DWARF5: "-cc1as"
+// DWARF5: "-dwarf-version=5"



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


[clang] 72eee60 - [Driver] Support -gdwarf64 for assembly files

2021-02-17 Thread Igor Kudrin via cfe-commits

Author: Igor Kudrin
Date: 2021-02-17T17:03:34+07:00
New Revision: 72eee60b2451e8627e492d42bf1d43247685bef9

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

LOG: [Driver] Support -gdwarf64 for assembly files

The option was added in D90507 for C/C++ source files. This patch adds
support for assembly files.

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

Added: 
clang/test/Misc/cc1as-debug-format.s

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/debug-options-as.c
clang/tools/driver/cc1as_main.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b3e17e1bfe27..0451fa829c00 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2666,10 +2666,12 @@ def gdwarf_4 : Flag<["-"], "gdwarf-4">, Group,
   HelpText<"Generate source-level debug information with dwarf version 4">;
 def gdwarf_5 : Flag<["-"], "gdwarf-5">, Group,
   HelpText<"Generate source-level debug information with dwarf version 5">;
-def gdwarf64 : Flag<["-"], "gdwarf64">, Group, Flags<[CC1Option]>,
+def gdwarf64 : Flag<["-"], "gdwarf64">, Group,
+  Flags<[CC1Option, CC1AsOption]>,
   HelpText<"Enables DWARF64 format for ELF binaries, if debug information 
emission is enabled.">,
   MarshallingInfoFlag>;
-def gdwarf32 : Flag<["-"], "gdwarf32">, Group, Flags<[CC1Option]>,
+def gdwarf32 : Flag<["-"], "gdwarf32">, Group,
+  Flags<[CC1Option, CC1AsOption]>,
   HelpText<"Enables DWARF32 format for ELF binaries, if debug information 
emission is enabled.">;
 
 def gcodeview : Flag<["-"], "gcodeview">,

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 819f10eb2524..03166232cf42 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3749,6 +3749,29 @@ static DwarfFissionKind getDebugFissionKind(const Driver 
,
   return DwarfFissionKind::None;
 }
 
+static void renderDwarfFormat(const Driver , const llvm::Triple ,
+  const ArgList , ArgStringList ,
+  unsigned DwarfVersion) {
+  auto *DwarfFormatArg =
+  Args.getLastArg(options::OPT_gdwarf64, options::OPT_gdwarf32);
+  if (!DwarfFormatArg)
+return;
+
+  if (DwarfFormatArg->getOption().matches(options::OPT_gdwarf64)) {
+if (DwarfVersion < 3)
+  D.Diag(diag::err_drv_argument_only_allowed_with)
+  << DwarfFormatArg->getAsString(Args) << "DWARFv3 or greater";
+else if (!T.isArch64Bit())
+  D.Diag(diag::err_drv_argument_only_allowed_with)
+  << DwarfFormatArg->getAsString(Args) << "64 bit architecture";
+else if (!T.isOSBinFormatELF())
+  D.Diag(diag::err_drv_argument_only_allowed_with)
+  << DwarfFormatArg->getAsString(Args) << "ELF platforms";
+  }
+
+  DwarfFormatArg->render(Args, CmdArgs);
+}
+
 static void renderDebugOptions(const ToolChain , const Driver ,
const llvm::Triple , const ArgList ,
bool EmitCodeView, bool IRInput,
@@ -4049,25 +4072,7 @@ static void renderDebugOptions(const ToolChain , 
const Driver ,
   if (DebuggerTuning == llvm::DebuggerKind::SCE)
 CmdArgs.push_back("-dwarf-explicit-import");
 
-  auto *DwarfFormatArg =
-  Args.getLastArg(options::OPT_gdwarf64, options::OPT_gdwarf32);
-  if (DwarfFormatArg &&
-  DwarfFormatArg->getOption().matches(options::OPT_gdwarf64)) {
-const llvm::Triple  = TC.getTriple();
-if (EffectiveDWARFVersion < 3)
-  D.Diag(diag::err_drv_argument_only_allowed_with)
-  << DwarfFormatArg->getAsString(Args) << "DWARFv3 or greater";
-else if (!RawTriple.isArch64Bit())
-  D.Diag(diag::err_drv_argument_only_allowed_with)
-  << DwarfFormatArg->getAsString(Args) << "64 bit architecture";
-else if (!RawTriple.isOSBinFormatELF())
-  D.Diag(diag::err_drv_argument_only_allowed_with)
-  << DwarfFormatArg->getAsString(Args) << "ELF platforms";
-  }
-
-  if (DwarfFormatArg)
-DwarfFormatArg->render(Args, CmdArgs);
-
+  renderDwarfFormat(D, T, Args, CmdArgs, EffectiveDWARFVersion);
   RenderDebugInfoCompressionArgs(Args, CmdArgs, D, TC);
 }
 
@@ -7211,6 +7216,7 @@ void ClangAs::ConstructJob(Compilation , const 
JobAction ,
   }
   RenderDebugEnablingArgs(Args, CmdArgs, DebugInfoKind, DwarfVersion,
   llvm::DebuggerKind::Default);
+  renderDwarfFormat(D, Triple, Args, CmdArgs, DwarfVersion);
   RenderDebugInfoCompressionArgs(Args, CmdArgs, D, getToolChain());
 
 

diff  --git a/clang/test/Driver/debug-options-as.c 
b/clang/test/Driver/debug-options-as.c
index 51475680e9b1..f36188e8ab2b 100644
--- 

[clang] aa84289 - [DebugInfo] Keep the DWARF64 flag in the module metadata

2021-02-17 Thread Igor Kudrin via cfe-commits

Author: Igor Kudrin
Date: 2021-02-17T17:03:34+07:00
New Revision: aa842896299b014dc1837f1a01dfccbd94242c84

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

LOG: [DebugInfo] Keep the DWARF64 flag in the module metadata

This allows the option to affect the LTO output. Module::Max helps to
generate debug info for all modules in the same format.

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

Added: 
clang/test/CodeGen/dwarf-format.c
llvm/test/DebugInfo/X86/dwarf64-module-flag.ll

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
llvm/include/llvm/IR/Module.h
llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
llvm/lib/IR/Module.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 4688f13dae21..ff36d5529d4c 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -533,6 +533,9 @@ void CodeGenModule::Release() {
   CodeGenOpts.DwarfVersion);
   }
 
+  if (CodeGenOpts.Dwarf64)
+getModule().addModuleFlag(llvm::Module::Max, "DWARF64", 1);
+
   if (Context.getLangOpts().SemanticInterposition)
 // Require various optimization to respect semantic interposition.
 getModule().setSemanticInterposition(1);

diff  --git a/clang/test/CodeGen/dwarf-format.c 
b/clang/test/CodeGen/dwarf-format.c
new file mode 100644
index ..aff941993371
--- /dev/null
+++ b/clang/test/CodeGen/dwarf-format.c
@@ -0,0 +1,13 @@
+// RUN: %clang -target x86_64-linux-gnu -g -S -emit-llvm -o - %s | \
+// RUN:   FileCheck %s --check-prefix=NODWARF64
+// RUN: %clang -target x86_64-linux-gnu -g -gdwarf64 -S -emit-llvm -o - %s | \
+// RUN:   FileCheck %s --check-prefix=DWARF64
+// RUN: %clang -target x86_64-linux-gnu -g -gdwarf64 -gdwarf32 -S -emit-llvm 
-o - %s | \
+// RUN:   FileCheck %s --check-prefix=NODWARF64
+
+// DWARF64: !{i32 7, !"DWARF64", i32 1}
+// NODWARF64-NOT: !"DWARF64"
+
+int main (void) {
+  return 0;
+}

diff  --git a/llvm/include/llvm/IR/Module.h b/llvm/include/llvm/IR/Module.h
index 3664b275114d..3ac57b7e5750 100644
--- a/llvm/include/llvm/IR/Module.h
+++ b/llvm/include/llvm/IR/Module.h
@@ -805,6 +805,9 @@ class Module {
   /// Returns the Dwarf Version by checking module flags.
   unsigned getDwarfVersion() const;
 
+  /// Returns the DWARF format by checking module flags.
+  bool isDwarf64() const;
+
   /// Returns the CodeView Version by checking module flags.
   /// Returns zero if not present in module.
   unsigned getCodeViewFlag() const;

diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp 
b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 9eaef84c9130..3c2c1f5ded0a 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -392,10 +392,11 @@ DwarfDebug::DwarfDebug(AsmPrinter *A)
   DwarfVersion =
   TT.isNVPTX() ? 2 : (DwarfVersion ? DwarfVersion : dwarf::DWARF_VERSION);
 
-  bool Dwarf64 = Asm->TM.Options.MCOptions.Dwarf64 &&
- DwarfVersion >= 3 &&   // DWARF64 was introduced in DWARFv3.
- TT.isArch64Bit() &&// DWARF64 requires 64-bit relocations.
- TT.isOSBinFormatELF(); // Support only ELF for now.
+  bool Dwarf64 =
+  (Asm->TM.Options.MCOptions.Dwarf64 || MMI->getModule()->isDwarf64()) &&
+  DwarfVersion >= 3 &&   // DWARF64 was introduced in DWARFv3.
+  TT.isArch64Bit() &&// DWARF64 requires 64-bit relocations.
+  TT.isOSBinFormatELF(); // Support only ELF for now.
 
   UseRangesSection = !NoDwarfRangesSection && !TT.isNVPTX();
 

diff  --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index b4f10e2e2d23..9395b2bb849c 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/lib/IR/Module.cpp
@@ -509,6 +509,11 @@ unsigned Module::getDwarfVersion() const {
   return cast(Val->getValue())->getZExtValue();
 }
 
+bool Module::isDwarf64() const {
+  auto *Val = cast_or_null(getModuleFlag("DWARF64"));
+  return Val && cast(Val->getValue())->isOne();
+}
+
 unsigned Module::getCodeViewFlag() const {
   auto *Val = cast_or_null(getModuleFlag("CodeView"));
   if (!Val)

diff  --git a/llvm/test/DebugInfo/X86/dwarf64-module-flag.ll 
b/llvm/test/DebugInfo/X86/dwarf64-module-flag.ll
new file mode 100644
index ..7bdacae6d892
--- /dev/null
+++ b/llvm/test/DebugInfo/X86/dwarf64-module-flag.ll
@@ -0,0 +1,37 @@
+; This checks that the debug info is generated in the 64-bit format if the
+; module has the corresponding flag.
+
+; RUN: llc -mtriple=x86_64 -filetype=obj %s -o %t
+; RUN: llvm-dwarfdump -debug-info -debug-line %t | FileCheck %s
+
+; CHECK:  Compile Unit: {{.*}} format = DWARF64
+; CHECK:  debug_line[
+; CHECK-NEXT: Line table prologue:
+; CHECK-NEXT:   total_length:
+; CHECK-NEXT: format: 

[clang] 474d527 - [clang] Fix a misleading variable name. NFC.

2020-09-21 Thread Igor Kudrin via cfe-commits

Author: Igor Kudrin
Date: 2020-09-21T22:59:34+07:00
New Revision: 474d527c28f4e88ffda7b82e93e351aec2602380

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

LOG: [clang] Fix a misleading variable name. NFC.

The variable is true when frame pointers should be omitted in leaf
functions, not kept.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 0c03a90b8566..8ce59f5ba580 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -604,12 +604,12 @@ getFramePointerKind(const ArgList , const 
llvm::Triple ) {
   bool OmitFP = A && A->getOption().matches(options::OPT_fomit_frame_pointer);
   bool NoOmitFP =
   A && A->getOption().matches(options::OPT_fno_omit_frame_pointer);
-  bool KeepLeaf = Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
-   options::OPT_mno_omit_leaf_frame_pointer,
-   Triple.isAArch64() || Triple.isPS4CPU());
+  bool OmitLeafFP = Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
+ options::OPT_mno_omit_leaf_frame_pointer,
+ Triple.isAArch64() || Triple.isPS4CPU());
   if (NoOmitFP || mustUseNonLeafFramePointerForTarget(Triple) ||
   (!OmitFP && useFramePointerForTargetByDefault(Args, Triple))) {
-if (KeepLeaf)
+if (OmitLeafFP)
   return CodeGenOptions::FramePointerKind::NonLeaf;
 return CodeGenOptions::FramePointerKind::All;
   }



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


r361598 - Do not resolve directory junctions for `-fdiagnostics-absolute-paths` on Windows.

2019-05-23 Thread Igor Kudrin via cfe-commits
Author: ikudrin
Date: Thu May 23 21:46:22 2019
New Revision: 361598

URL: http://llvm.org/viewvc/llvm-project?rev=361598=rev
Log:
Do not resolve directory junctions for `-fdiagnostics-absolute-paths` on 
Windows.

If the source file path contains directory junctions, and we resolve them when
printing diagnostic messages, these paths look independent for an IDE.
For example, both Visual Studio and Visual Studio Code open separate editors
for such paths, which is not only inconvenient but might even result in losing
changes made in one of them.

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

Added:
cfe/trunk/test/Frontend/absolute-paths-windows.test
Modified:
cfe/trunk/lib/Frontend/TextDiagnostic.cpp
cfe/trunk/test/Frontend/lit.local.cfg

Modified: cfe/trunk/lib/Frontend/TextDiagnostic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnostic.cpp?rev=361598=361597=361598=diff
==
--- cfe/trunk/lib/Frontend/TextDiagnostic.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnostic.cpp Thu May 23 21:46:22 2019
@@ -765,7 +765,28 @@ void TextDiagnostic::emitFilename(String
 const DirectoryEntry *Dir = SM.getFileManager().getDirectory(
 llvm::sys::path::parent_path(Filename));
 if (Dir) {
+  // We want to print a simplified absolute path, i. e. without "dots".
+  //
+  // The hardest part here are the paths like "//../".
+  // On Unix-like systems, we cannot just collapse "/..", because
+  // paths are resolved sequentially, and, thereby, the path
+  // "/" may point to a different location. That is why
+  // we use FileManager::getCanonicalName(), which expands all indirections
+  // with llvm::sys::fs::real_path() and caches the result.
+  //
+  // On the other hand, it would be better to preserve as much of the
+  // original path as possible, because that helps a user to recognize it.
+  // real_path() expands all links, which sometimes too much. Luckily,
+  // on Windows we can just use llvm::sys::path::remove_dots(), because,
+  // on that system, both aforementioned paths point to the same place.
+#ifdef _WIN32
+  SmallString<4096> DirName = Dir->getName();
+  llvm::sys::fs::make_absolute(DirName);
+  llvm::sys::path::native(DirName);
+  llvm::sys::path::remove_dots(DirName, /* remove_dot_dot */ true);
+#else
   StringRef DirName = SM.getFileManager().getCanonicalName(Dir);
+#endif
   llvm::sys::path::append(AbsoluteFilename, DirName,
   llvm::sys::path::filename(Filename));
   Filename = StringRef(AbsoluteFilename.data(), AbsoluteFilename.size());

Added: cfe/trunk/test/Frontend/absolute-paths-windows.test
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/absolute-paths-windows.test?rev=361598=auto
==
--- cfe/trunk/test/Frontend/absolute-paths-windows.test (added)
+++ cfe/trunk/test/Frontend/absolute-paths-windows.test Thu May 23 21:46:22 2019
@@ -0,0 +1,9 @@
+// REQUIRES: system-windows
+// RUN: rm -rf %t.dir
+// RUN: mkdir -p %t.dir\real
+// RUN: cmd /c mklink /j %t.dir\junc %t.dir\real
+// RUN: echo "wrong code" > %t.dir\real\foo.cpp
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-absolute-paths 
%t.dir\junc\foo.cpp 2>&1 | FileCheck %s
+
+// CHECK-NOT: .dir\real\foo.cpp
+// CHECK: .dir\junc\foo.cpp

Modified: cfe/trunk/test/Frontend/lit.local.cfg
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/lit.local.cfg?rev=361598=361597=361598=diff
==
--- cfe/trunk/test/Frontend/lit.local.cfg (original)
+++ cfe/trunk/test/Frontend/lit.local.cfg Thu May 23 21:46:22 2019
@@ -1 +1 @@
-config.suffixes = ['.c', '.cpp', '.m', '.mm', '.ll', '.cl']
+config.suffixes = ['.c', '.cpp', '.m', '.mm', '.ll', '.cl', '.test']


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


r335445 - [CodeGen] Provide source locations for UBSan type checks when emitting constructor calls.

2018-06-24 Thread Igor Kudrin via cfe-commits
Author: ikudrin
Date: Sun Jun 24 22:48:04 2018
New Revision: 335445

URL: http://llvm.org/viewvc/llvm-project?rev=335445=rev
Log:
[CodeGen] Provide source locations for UBSan type checks when emitting 
constructor calls.

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

Added:
cfe/trunk/test/CodeGenCXX/ubsan-ctor-srcloc.cpp
Modified:
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=335445=335444=335445=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Sun Jun 24 22:48:04 2018
@@ -2031,7 +2031,7 @@ void CodeGenFunction::EmitCXXConstructor
/*ParamsToSkip*/ 0, Order);
 
   EmitCXXConstructorCall(D, Type, ForVirtualBase, Delegating, This, Args,
- Overlap);
+ Overlap, E->getExprLoc());
 }
 
 static bool canEmitDelegateCallArgs(CodeGenFunction ,
@@ -2064,14 +2064,14 @@ void CodeGenFunction::EmitCXXConstructor
  bool Delegating,
  Address This,
  CallArgList ,
- AggValueSlot::Overlap_t Overlap) {
+ AggValueSlot::Overlap_t Overlap,
+ SourceLocation Loc) {
   const CXXRecordDecl *ClassDecl = D->getParent();
 
   // C++11 [class.mfct.non-static]p2:
   //   If a non-static member function of a class X is called for an object 
that
   //   is not of type X, or of a type derived from X, the behavior is 
undefined.
-  // FIXME: Provide a source location here.
-  EmitTypeCheck(CodeGenFunction::TCK_ConstructorCall, SourceLocation(),
+  EmitTypeCheck(CodeGenFunction::TCK_ConstructorCall, Loc,
 This.getPointer(), getContext().getRecordType(ClassDecl));
 
   if (D->isTrivial() && D->isDefaultConstructor()) {
@@ -2180,7 +2180,8 @@ void CodeGenFunction::EmitInheritedCXXCo
   }
 
   EmitCXXConstructorCall(D, Ctor_Base, ForVirtualBase, /*Delegating*/false,
- This, Args, AggValueSlot::MayOverlap);
+ This, Args, AggValueSlot::MayOverlap,
+ E->getLocation());
 }
 
 void CodeGenFunction::EmitInlinedInheritingCXXConstructorCall(
@@ -2277,7 +2278,7 @@ CodeGenFunction::EmitSynthesizedCXXCopyC
/*ParamsToSkip*/ 1);
 
   EmitCXXConstructorCall(D, Ctor_Complete, false, false, This, Args,
- AggValueSlot::MayOverlap);
+ AggValueSlot::MayOverlap, E->getExprLoc());
 }
 
 void
@@ -2313,7 +2314,7 @@ CodeGenFunction::EmitDelegateCXXConstruc
 
   EmitCXXConstructorCall(Ctor, CtorType, /*ForVirtualBase=*/false,
  /*Delegating=*/true, This, DelegateArgs,
- AggValueSlot::MayOverlap);
+ AggValueSlot::MayOverlap, Loc);
 }
 
 namespace {

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=335445=335444=335445=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Sun Jun 24 22:48:04 2018
@@ -2362,7 +2362,8 @@ public:
   void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type,
   bool ForVirtualBase, bool Delegating,
   Address This, CallArgList ,
-  AggValueSlot::Overlap_t Overlap);
+  AggValueSlot::Overlap_t Overlap,
+  SourceLocation Loc);
 
   /// Emit assumption load for all bases. Requires to be be called only on
   /// most-derived class and not under construction of the object.

Added: cfe/trunk/test/CodeGenCXX/ubsan-ctor-srcloc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ubsan-ctor-srcloc.cpp?rev=335445=auto
==
--- cfe/trunk/test/CodeGenCXX/ubsan-ctor-srcloc.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/ubsan-ctor-srcloc.cpp Sun Jun 24 22:48:04 2018
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-linux -emit-llvm 
-fsanitize=alignment -fblocks %s -o %t.ll
+// RUN: FileCheck -check-prefix=ZEROINIT < %t.ll %s
+// RUN: FileCheck -check-prefix=SRCLOC < %t.ll %s
+// ZEROINIT-NOT: @{{.+}} = private unnamed_addr global {{.+}} zeroinitializer
+
+struct A {
+  A(int);
+  int k;
+};
+
+struct B : A {
+  B();
+  B(const B &);
+// SRCLOC-DAG: @{{.+}} = private unnamed_addr global {{.+}} @.src, i32 
[[@LINE+1]], i32 12 }
+  using A::A;
+  void f() 

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

2018-02-27 Thread Igor Kudrin via cfe-commits
Author: ikudrin
Date: Mon Feb 26 18:51:30 2018
New Revision: 326164

URL: http://llvm.org/viewvc/llvm-project?rev=326164=rev
Log:
[Driver] Allow using a canonical form of '-fuse-ld=' when cross-compiling on 
Windows.

clang used to require adding an ".exe" suffix when targeting ELF systems on 
Windows.

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

Added:
cfe/trunk/test/Driver/Inputs/fuse_ld_windows/
cfe/trunk/test/Driver/Inputs/fuse_ld_windows/ld.foo.exe   (with props)
cfe/trunk/test/Driver/fuse-ld-windows.c
Modified:
cfe/trunk/lib/Driver/ToolChain.cpp

Modified: cfe/trunk/lib/Driver/ToolChain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=326164=326163=326164=diff
==
--- cfe/trunk/lib/Driver/ToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChain.cpp Mon Feb 26 18:51:30 2018
@@ -412,7 +412,7 @@ std::string ToolChain::GetLinkerPath() c
   if (llvm::sys::path::is_absolute(UseLinker)) {
 // If we're passed what looks like an absolute path, don't attempt to
 // second-guess that.
-if (llvm::sys::fs::exists(UseLinker))
+if (llvm::sys::fs::can_execute(UseLinker))
   return UseLinker;
   } else if (UseLinker.empty() || UseLinker == "ld") {
 // If we're passed -fuse-ld= with no argument, or with the argument ld,
@@ -427,7 +427,7 @@ std::string ToolChain::GetLinkerPath() c
 LinkerName.append(UseLinker);
 
 std::string LinkerPath(GetProgramPath(LinkerName.c_str()));
-if (llvm::sys::fs::exists(LinkerPath))
+if (llvm::sys::fs::can_execute(LinkerPath))
   return LinkerPath;
   }
 

Added: cfe/trunk/test/Driver/Inputs/fuse_ld_windows/ld.foo.exe
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/fuse_ld_windows/ld.foo.exe?rev=326164=auto
==
(empty)

Propchange: cfe/trunk/test/Driver/Inputs/fuse_ld_windows/ld.foo.exe
--
svn:executable = *

Added: cfe/trunk/test/Driver/fuse-ld-windows.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fuse-ld-windows.c?rev=326164=auto
==
--- cfe/trunk/test/Driver/fuse-ld-windows.c (added)
+++ cfe/trunk/test/Driver/fuse-ld-windows.c Mon Feb 26 18:51:30 2018
@@ -0,0 +1,25 @@
+// REQUIRES: system-windows
+
+// We used to require adding ".exe" suffix when cross-compiling on Windows.
+// RUN: %clang %s -### -o %t.o -target i386-unknown-linux \
+// RUN: -B %S/Inputs/fuse_ld_windows -fuse-ld=foo 2>&1 \
+// RUN:   | FileCheck %s
+
+// Check that the old variant still works.
+// RUN: %clang %s -### -o %t.o -target i386-unknown-linux \
+// RUN: -B %S/Inputs/fuse_ld_windows -fuse-ld=foo.exe 2>&1 \
+// RUN:   | FileCheck %s
+
+// With the full path, the extension can be omitted, too,
+// because Windows allows that.
+// RUN: %clang %s -### -o %t.o -target i386-unknown-linux \
+// RUN: -fuse-ld=%S/Inputs/fuse_ld_windows/ld.foo 2>&1 \
+// RUN:   | FileCheck %s
+
+// Check that the full path with the extension works too.
+// RUN: %clang %s -### -o %t.o -target i386-unknown-linux \
+// RUN: -fuse-ld=%S/Inputs/fuse_ld_windows/ld.foo.exe 2>&1 \
+// RUN:   | FileCheck %s
+
+// CHECK-NOT: invalid linker name
+// CHECK: /Inputs/fuse_ld_windows{{/|}}ld.foo


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


[libcxxabi] r286337 - [libc++abi] Remove the test for checking using of fallback malloc in case of dynamic memory exhaustion.

2016-11-08 Thread Igor Kudrin via cfe-commits
Author: ikudrin
Date: Tue Nov  8 22:14:31 2016
New Revision: 286337

URL: http://llvm.org/viewvc/llvm-project?rev=286337=rev
Log:
[libc++abi] Remove the test for checking using of fallback malloc in case of 
dynamic memory exhaustion.

This test is too fragile and doesn't add significant value. See 
https://reviews.llvm.org/D26150 for some details.

Removed:
libcxxabi/trunk/test/test_exception_storage_nodynmem.pass.cpp

Removed: libcxxabi/trunk/test/test_exception_storage_nodynmem.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/test_exception_storage_nodynmem.pass.cpp?rev=286336=auto
==
--- libcxxabi/trunk/test/test_exception_storage_nodynmem.pass.cpp (original)
+++ libcxxabi/trunk/test/test_exception_storage_nodynmem.pass.cpp (removed)
@@ -1,40 +0,0 @@
-//===--- test_exception_storage_nodynmem.cpp 
--===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===--===//
-
-// UNSUPPORTED: libcxxabi-no-exceptions
-
-// cxa_exception_storage does not use dynamic memory in the single thread mode.
-// UNSUPPORTED: libcpp-has-no-threads
-
-// Our overwritten calloc() is not compatible with these sanitizers.
-// UNSUPPORTED: msan, tsan
-
-#include 
-#include 
-
-static bool OverwrittenCallocCalled = false;
-
-// Override calloc to simulate exhaustion of dynamic memory
-void *calloc(size_t, size_t) {
-OverwrittenCallocCalled = true;
-return 0;
-}
-
-int main(int argc, char *argv[]) {
-// Run the test a couple of times
-// to ensure that fallback memory doesn't leak.
-for (int I = 0; I < 1000; ++I)
-try {
-throw 42;
-} catch (...) {
-}
-
-assert(OverwrittenCallocCalled);
-return 0;
-}


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


[PATCH] D26150: [libc++abi] Fix test_exception_storage_nodynmem on MacOS

2016-11-08 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

The test is too implementation-specific, and trying to override a function like 
`calloc` makes it fragile. Unfortunately, I didn't find a better way to test 
the library's behavior in case of memory exhaustion, but now I believe that 
this test doesn't add any significant value. I'm going to remove it if no one 
objects.


https://reviews.llvm.org/D26150



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


[PATCH] D25608: [libclang] Make tests for python bindings pass on Windows.

2016-11-07 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

Ping.


https://reviews.llvm.org/D25608



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


[PATCH] D25608: [libclang] Make tests for python bindings pass on Windows.

2016-10-20 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

Ping.


https://reviews.llvm.org/D25608



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


r284464 - [libclang] Add missing cursor kinds to python bindings.

2016-10-18 Thread Igor Kudrin via cfe-commits
Author: ikudrin
Date: Tue Oct 18 04:42:03 2016
New Revision: 284464

URL: http://llvm.org/viewvc/llvm-project?rev=284464=rev
Log:
[libclang] Add missing cursor kinds to python bindings.

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

Modified:
cfe/trunk/bindings/python/clang/cindex.py

Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=284464=284463=284464=diff
==
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Tue Oct 18 04:42:03 2016
@@ -1008,6 +1008,12 @@ CursorKind.OBJ_BOOL_LITERAL_EXPR = Curso
 # Represents the "self" expression in a ObjC method.
 CursorKind.OBJ_SELF_EXPR = CursorKind(146)
 
+# OpenMP 4.0 [2.4, Array Section].
+CursorKind.OMP_ARRAY_SECTION_EXPR = CursorKind(147)
+
+# Represents an @available(...) check.
+CursorKind.OBJC_AVAILABILITY_CHECK_EXPR = CursorKind(148)
+
 
 # A statement whose specific kind is not exposed via this interface.
 #
@@ -1109,6 +1115,126 @@ CursorKind.NULL_STMT = CursorKind(230)
 # Adaptor class for mixing declarations with statements and expressions.
 CursorKind.DECL_STMT = CursorKind(231)
 
+# OpenMP parallel directive.
+CursorKind.OMP_PARALLEL_DIRECTIVE = CursorKind(232)
+
+# OpenMP SIMD directive.
+CursorKind.OMP_SIMD_DIRECTIVE = CursorKind(233)
+
+# OpenMP for directive.
+CursorKind.OMP_FOR_DIRECTIVE = CursorKind(234)
+
+# OpenMP sections directive.
+CursorKind.OMP_SECTIONS_DIRECTIVE = CursorKind(235)
+
+# OpenMP section directive.
+CursorKind.OMP_SECTION_DIRECTIVE = CursorKind(236)
+
+# OpenMP single directive.
+CursorKind.OMP_SINGLE_DIRECTIVE = CursorKind(237)
+
+# OpenMP parallel for directive.
+CursorKind.OMP_PARALLEL_FOR_DIRECTIVE = CursorKind(238)
+
+# OpenMP parallel sections directive.
+CursorKind.OMP_PARALLEL_SECTIONS_DIRECTIVE = CursorKind(239)
+
+# OpenMP task directive.
+CursorKind.OMP_TASK_DIRECTIVE = CursorKind(240)
+
+# OpenMP master directive.
+CursorKind.OMP_MASTER_DIRECTIVE = CursorKind(241)
+
+# OpenMP critical directive.
+CursorKind.OMP_CRITICAL_DIRECTIVE = CursorKind(242)
+
+# OpenMP taskyield directive.
+CursorKind.OMP_TASKYIELD_DIRECTIVE = CursorKind(243)
+
+# OpenMP barrier directive.
+CursorKind.OMP_BARRIER_DIRECTIVE = CursorKind(244)
+
+# OpenMP taskwait directive.
+CursorKind.OMP_TASKWAIT_DIRECTIVE = CursorKind(245)
+
+# OpenMP flush directive.
+CursorKind.OMP_FLUSH_DIRECTIVE = CursorKind(246)
+
+# Windows Structured Exception Handling's leave statement.
+CursorKind.SEH_LEAVE_STMT = CursorKind(247)
+
+# OpenMP ordered directive.
+CursorKind.OMP_ORDERED_DIRECTIVE = CursorKind(248)
+
+# OpenMP atomic directive.
+CursorKind.OMP_ATOMIC_DIRECTIVE = CursorKind(249)
+
+# OpenMP for SIMD directive.
+CursorKind.OMP_FOR_SIMD_DIRECTIVE = CursorKind(250)
+
+# OpenMP parallel for SIMD directive.
+CursorKind.OMP_PARALLELFORSIMD_DIRECTIVE = CursorKind(251)
+
+# OpenMP target directive.
+CursorKind.OMP_TARGET_DIRECTIVE = CursorKind(252)
+
+# OpenMP teams directive.
+CursorKind.OMP_TEAMS_DIRECTIVE = CursorKind(253)
+
+# OpenMP taskgroup directive.
+CursorKind.OMP_TASKGROUP_DIRECTIVE = CursorKind(254)
+
+# OpenMP cancellation point directive.
+CursorKind.OMP_CANCELLATION_POINT_DIRECTIVE = CursorKind(255)
+
+# OpenMP cancel directive.
+CursorKind.OMP_CANCEL_DIRECTIVE = CursorKind(256)
+
+# OpenMP target data directive.
+CursorKind.OMP_TARGET_DATA_DIRECTIVE = CursorKind(257)
+
+# OpenMP taskloop directive.
+CursorKind.OMP_TASK_LOOP_DIRECTIVE = CursorKind(258)
+
+# OpenMP taskloop simd directive.
+CursorKind.OMP_TASK_LOOP_SIMD_DIRECTIVE = CursorKind(259)
+
+# OpenMP distribute directive.
+CursorKind.OMP_DISTRIBUTE_DIRECTIVE = CursorKind(260)
+
+# OpenMP target enter data directive.
+CursorKind.OMP_TARGET_ENTER_DATA_DIRECTIVE = CursorKind(261)
+
+# OpenMP target exit data directive.
+CursorKind.OMP_TARGET_EXIT_DATA_DIRECTIVE = CursorKind(262)
+
+# OpenMP target parallel directive.
+CursorKind.OMP_TARGET_PARALLEL_DIRECTIVE = CursorKind(263)
+
+# OpenMP target parallel for directive.
+CursorKind.OMP_TARGET_PARALLELFOR_DIRECTIVE = CursorKind(264)
+
+# OpenMP target update directive.
+CursorKind.OMP_TARGET_UPDATE_DIRECTIVE = CursorKind(265)
+
+# OpenMP distribute parallel for directive.
+CursorKind.OMP_DISTRIBUTE_PARALLELFOR_DIRECTIVE = CursorKind(266)
+
+# OpenMP distribute parallel for simd directive.
+CursorKind.OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE = CursorKind(267)
+
+# OpenMP distribute simd directive.
+CursorKind.OMP_DISTRIBUTE_SIMD_DIRECTIVE = CursorKind(268)
+
+# OpenMP target parallel for simd directive.
+CursorKind.OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE = CursorKind(269)
+
+# OpenMP target simd directive.
+CursorKind.OMP_TARGET_SIMD_DIRECTIVE = CursorKind(270)
+
+# OpenMP teams distribute directive.
+CursorKind.OMP_TEAMS_DISTRIBUTE_DIRECTIVE = CursorKind(271)
+
 ###
 # Other Kinds
 
@@ -1161,6 +1287,8 @@ 

[PATCH] D25673: [libclang] Add missing cursor kinds to python bindings.

2016-10-18 Thread Igor Kudrin via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284464: [libclang] Add missing cursor kinds to python 
bindings. (authored by ikudrin).

Changed prior to commit:
  https://reviews.llvm.org/D25673?vs=74834=74960#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25673

Files:
  cfe/trunk/bindings/python/clang/cindex.py

Index: cfe/trunk/bindings/python/clang/cindex.py
===
--- cfe/trunk/bindings/python/clang/cindex.py
+++ cfe/trunk/bindings/python/clang/cindex.py
@@ -1008,6 +1008,12 @@
 # Represents the "self" expression in a ObjC method.
 CursorKind.OBJ_SELF_EXPR = CursorKind(146)
 
+# OpenMP 4.0 [2.4, Array Section].
+CursorKind.OMP_ARRAY_SECTION_EXPR = CursorKind(147)
+
+# Represents an @available(...) check.
+CursorKind.OBJC_AVAILABILITY_CHECK_EXPR = CursorKind(148)
+
 
 # A statement whose specific kind is not exposed via this interface.
 #
@@ -1109,6 +1115,126 @@
 # Adaptor class for mixing declarations with statements and expressions.
 CursorKind.DECL_STMT = CursorKind(231)
 
+# OpenMP parallel directive.
+CursorKind.OMP_PARALLEL_DIRECTIVE = CursorKind(232)
+
+# OpenMP SIMD directive.
+CursorKind.OMP_SIMD_DIRECTIVE = CursorKind(233)
+
+# OpenMP for directive.
+CursorKind.OMP_FOR_DIRECTIVE = CursorKind(234)
+
+# OpenMP sections directive.
+CursorKind.OMP_SECTIONS_DIRECTIVE = CursorKind(235)
+
+# OpenMP section directive.
+CursorKind.OMP_SECTION_DIRECTIVE = CursorKind(236)
+
+# OpenMP single directive.
+CursorKind.OMP_SINGLE_DIRECTIVE = CursorKind(237)
+
+# OpenMP parallel for directive.
+CursorKind.OMP_PARALLEL_FOR_DIRECTIVE = CursorKind(238)
+
+# OpenMP parallel sections directive.
+CursorKind.OMP_PARALLEL_SECTIONS_DIRECTIVE = CursorKind(239)
+
+# OpenMP task directive.
+CursorKind.OMP_TASK_DIRECTIVE = CursorKind(240)
+
+# OpenMP master directive.
+CursorKind.OMP_MASTER_DIRECTIVE = CursorKind(241)
+
+# OpenMP critical directive.
+CursorKind.OMP_CRITICAL_DIRECTIVE = CursorKind(242)
+
+# OpenMP taskyield directive.
+CursorKind.OMP_TASKYIELD_DIRECTIVE = CursorKind(243)
+
+# OpenMP barrier directive.
+CursorKind.OMP_BARRIER_DIRECTIVE = CursorKind(244)
+
+# OpenMP taskwait directive.
+CursorKind.OMP_TASKWAIT_DIRECTIVE = CursorKind(245)
+
+# OpenMP flush directive.
+CursorKind.OMP_FLUSH_DIRECTIVE = CursorKind(246)
+
+# Windows Structured Exception Handling's leave statement.
+CursorKind.SEH_LEAVE_STMT = CursorKind(247)
+
+# OpenMP ordered directive.
+CursorKind.OMP_ORDERED_DIRECTIVE = CursorKind(248)
+
+# OpenMP atomic directive.
+CursorKind.OMP_ATOMIC_DIRECTIVE = CursorKind(249)
+
+# OpenMP for SIMD directive.
+CursorKind.OMP_FOR_SIMD_DIRECTIVE = CursorKind(250)
+
+# OpenMP parallel for SIMD directive.
+CursorKind.OMP_PARALLELFORSIMD_DIRECTIVE = CursorKind(251)
+
+# OpenMP target directive.
+CursorKind.OMP_TARGET_DIRECTIVE = CursorKind(252)
+
+# OpenMP teams directive.
+CursorKind.OMP_TEAMS_DIRECTIVE = CursorKind(253)
+
+# OpenMP taskgroup directive.
+CursorKind.OMP_TASKGROUP_DIRECTIVE = CursorKind(254)
+
+# OpenMP cancellation point directive.
+CursorKind.OMP_CANCELLATION_POINT_DIRECTIVE = CursorKind(255)
+
+# OpenMP cancel directive.
+CursorKind.OMP_CANCEL_DIRECTIVE = CursorKind(256)
+
+# OpenMP target data directive.
+CursorKind.OMP_TARGET_DATA_DIRECTIVE = CursorKind(257)
+
+# OpenMP taskloop directive.
+CursorKind.OMP_TASK_LOOP_DIRECTIVE = CursorKind(258)
+
+# OpenMP taskloop simd directive.
+CursorKind.OMP_TASK_LOOP_SIMD_DIRECTIVE = CursorKind(259)
+
+# OpenMP distribute directive.
+CursorKind.OMP_DISTRIBUTE_DIRECTIVE = CursorKind(260)
+
+# OpenMP target enter data directive.
+CursorKind.OMP_TARGET_ENTER_DATA_DIRECTIVE = CursorKind(261)
+
+# OpenMP target exit data directive.
+CursorKind.OMP_TARGET_EXIT_DATA_DIRECTIVE = CursorKind(262)
+
+# OpenMP target parallel directive.
+CursorKind.OMP_TARGET_PARALLEL_DIRECTIVE = CursorKind(263)
+
+# OpenMP target parallel for directive.
+CursorKind.OMP_TARGET_PARALLELFOR_DIRECTIVE = CursorKind(264)
+
+# OpenMP target update directive.
+CursorKind.OMP_TARGET_UPDATE_DIRECTIVE = CursorKind(265)
+
+# OpenMP distribute parallel for directive.
+CursorKind.OMP_DISTRIBUTE_PARALLELFOR_DIRECTIVE = CursorKind(266)
+
+# OpenMP distribute parallel for simd directive.
+CursorKind.OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE = CursorKind(267)
+
+# OpenMP distribute simd directive.
+CursorKind.OMP_DISTRIBUTE_SIMD_DIRECTIVE = CursorKind(268)
+
+# OpenMP target parallel for simd directive.
+CursorKind.OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE = CursorKind(269)
+
+# OpenMP target simd directive.
+CursorKind.OMP_TARGET_SIMD_DIRECTIVE = CursorKind(270)
+
+# OpenMP teams distribute directive.
+CursorKind.OMP_TEAMS_DISTRIBUTE_DIRECTIVE = CursorKind(271)
+
 ###
 # Other Kinds
 
@@ -1161,6 +1287,8 @@
 CursorKind.MODULE_IMPORT_DECL = CursorKind(600)
 # A type alias template declaration
 CursorKind.TYPE_ALIAS_TEMPLATE_DECL = CursorKind(601)
+# A static_assert or _Static_assert node

[PATCH] D25470: [libclang] Fix a failure in a test for python bindings on CursorKind.OVERLOAD_CANDIDATE.

2016-10-18 Thread Igor Kudrin via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284463: [libclang] Fix a failure in a test for python 
bindings on CursorKind. (authored by ikudrin).

Changed prior to commit:
  https://reviews.llvm.org/D25470?vs=74237=74959#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25470

Files:
  cfe/trunk/bindings/python/tests/cindex/test_cursor_kind.py


Index: cfe/trunk/bindings/python/tests/cindex/test_cursor_kind.py
===
--- cfe/trunk/bindings/python/tests/cindex/test_cursor_kind.py
+++ cfe/trunk/bindings/python/tests/cindex/test_cursor_kind.py
@@ -42,7 +42,8 @@
 CursorKind.MACRO_DEFINITION,
 CursorKind.MACRO_INSTANTIATION,
 CursorKind.INCLUSION_DIRECTIVE,
-CursorKind.PREPROCESSING_DIRECTIVE):
+CursorKind.PREPROCESSING_DIRECTIVE,
+CursorKind.OVERLOAD_CANDIDATE):
 assert len(group) == 0
 else:
 assert len(group) == 1


Index: cfe/trunk/bindings/python/tests/cindex/test_cursor_kind.py
===
--- cfe/trunk/bindings/python/tests/cindex/test_cursor_kind.py
+++ cfe/trunk/bindings/python/tests/cindex/test_cursor_kind.py
@@ -42,7 +42,8 @@
 CursorKind.MACRO_DEFINITION,
 CursorKind.MACRO_INSTANTIATION,
 CursorKind.INCLUSION_DIRECTIVE,
-CursorKind.PREPROCESSING_DIRECTIVE):
+CursorKind.PREPROCESSING_DIRECTIVE,
+CursorKind.OVERLOAD_CANDIDATE):
 assert len(group) == 0
 else:
 assert len(group) == 1
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r284463 - [libclang] Fix a failure in a test for python bindings on CursorKind.OVERLOAD_CANDIDATE.

2016-10-18 Thread Igor Kudrin via cfe-commits
Author: ikudrin
Date: Tue Oct 18 04:30:33 2016
New Revision: 284463

URL: http://llvm.org/viewvc/llvm-project?rev=284463=rev
Log:
[libclang] Fix a failure in a test for python bindings on 
CursorKind.OVERLOAD_CANDIDATE.

The test fails because the value does not lay in any existing group.

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


Modified:
cfe/trunk/bindings/python/tests/cindex/test_cursor_kind.py

Modified: cfe/trunk/bindings/python/tests/cindex/test_cursor_kind.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_cursor_kind.py?rev=284463=284462=284463=diff
==
--- cfe/trunk/bindings/python/tests/cindex/test_cursor_kind.py (original)
+++ cfe/trunk/bindings/python/tests/cindex/test_cursor_kind.py Tue Oct 18 
04:30:33 2016
@@ -42,7 +42,8 @@ def test_kind_groups():
 CursorKind.MACRO_DEFINITION,
 CursorKind.MACRO_INSTANTIATION,
 CursorKind.INCLUSION_DIRECTIVE,
-CursorKind.PREPROCESSING_DIRECTIVE):
+CursorKind.PREPROCESSING_DIRECTIVE,
+CursorKind.OVERLOAD_CANDIDATE):
 assert len(group) == 0
 else:
 assert len(group) == 1


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


[PATCH] D25673: [libclang] Add missing cursor kinds to python bindings.

2016-10-17 Thread Igor Kudrin via cfe-commits
ikudrin created this revision.
ikudrin added reviewers: compnerd, ABataev, erik.pilkington, ogoffart.
ikudrin added a subscriber: cfe-commits.

https://reviews.llvm.org/D25673

Files:
  bindings/python/clang/cindex.py

Index: bindings/python/clang/cindex.py
===
--- bindings/python/clang/cindex.py
+++ bindings/python/clang/cindex.py
@@ -1008,6 +1008,12 @@
 # Represents the "self" expression in a ObjC method.
 CursorKind.OBJ_SELF_EXPR = CursorKind(146)
 
+# OpenMP 4.0 [2.4, Array Section].
+CursorKind.OMP_ARRAY_SECTION_EXPR = CursorKind(147)
+
+# Represents an @available(...) check.
+CursorKind.OBJC_AVAILABILITY_CHECK_EXPR = CursorKind(148)
+
 
 # A statement whose specific kind is not exposed via this interface.
 #
@@ -1109,6 +1115,126 @@
 # Adaptor class for mixing declarations with statements and expressions.
 CursorKind.DECL_STMT = CursorKind(231)
 
+# OpenMP parallel directive.
+CursorKind.OMP_PARALLEL_DIRECTIVE = CursorKind(232)
+
+# OpenMP SIMD directive.
+CursorKind.OMP_SIMD_DIRECTIVE = CursorKind(233)
+
+# OpenMP for directive.
+CursorKind.OMP_FOR_DIRECTIVE = CursorKind(234)
+
+# OpenMP sections directive.
+CursorKind.OMP_SECTIONS_DIRECTIVE = CursorKind(235)
+
+# OpenMP section directive.
+CursorKind.OMP_SECTION_DIRECTIVE = CursorKind(236)
+
+# OpenMP single directive.
+CursorKind.OMP_SINGLE_DIRECTIVE = CursorKind(237)
+
+# OpenMP parallel for directive.
+CursorKind.OMP_PARALLEL_FOR_DIRECTIVE = CursorKind(238)
+
+# OpenMP parallel sections directive.
+CursorKind.OMP_PARALLEL_SECTIONS_DIRECTIVE = CursorKind(239)
+
+# OpenMP task directive.
+CursorKind.OMP_TASK_DIRECTIVE = CursorKind(240)
+
+# OpenMP master directive.
+CursorKind.OMP_MASTER_DIRECTIVE = CursorKind(241)
+
+# OpenMP critical directive.
+CursorKind.OMP_CRITICAL_DIRECTIVE = CursorKind(242)
+
+# OpenMP taskyield directive.
+CursorKind.OMP_TASKYIELD_DIRECTIVE = CursorKind(243)
+
+# OpenMP barrier directive.
+CursorKind.OMP_BARRIER_DIRECTIVE = CursorKind(244)
+
+# OpenMP taskwait directive.
+CursorKind.OMP_TASKWAIT_DIRECTIVE = CursorKind(245)
+
+# OpenMP flush directive.
+CursorKind.OMP_FLUSH_DIRECTIVE = CursorKind(246)
+
+# Windows Structured Exception Handling's leave statement.
+CursorKind.SEH_LEAVE_STMT = CursorKind(247)
+
+# OpenMP ordered directive.
+CursorKind.OMP_ORDERED_DIRECTIVE = CursorKind(248)
+
+# OpenMP atomic directive.
+CursorKind.OMP_ATOMIC_DIRECTIVE = CursorKind(249)
+
+# OpenMP for SIMD directive.
+CursorKind.OMP_FOR_SIMD_DIRECTIVE = CursorKind(250)
+
+# OpenMP parallel for SIMD directive.
+CursorKind.OMP_PARALLELFORSIMD_DIRECTIVE = CursorKind(251)
+
+# OpenMP target directive.
+CursorKind.OMP_TARGET_DIRECTIVE = CursorKind(252)
+
+# OpenMP teams directive.
+CursorKind.OMP_TEAMS_DIRECTIVE = CursorKind(253)
+
+# OpenMP taskgroup directive.
+CursorKind.OMP_TASKGROUP_DIRECTIVE = CursorKind(254)
+
+# OpenMP cancellation point directive.
+CursorKind.OMP_CANCELLATION_POINT_DIRECTIVE = CursorKind(255)
+
+# OpenMP cancel directive.
+CursorKind.OMP_CANCEL_DIRECTIVE = CursorKind(256)
+
+# OpenMP target data directive.
+CursorKind.OMP_TARGET_DATA_DIRECTIVE = CursorKind(257)
+
+# OpenMP taskloop directive.
+CursorKind.OMP_TASK_LOOP_DIRECTIVE = CursorKind(258)
+
+# OpenMP taskloop simd directive.
+CursorKind.OMP_TASK_LOOP_SIMD_DIRECTIVE = CursorKind(259)
+
+# OpenMP distribute directive.
+CursorKind.OMP_DISTRIBUTE_DIRECTIVE = CursorKind(260)
+
+# OpenMP target enter data directive.
+CursorKind.OMP_TARGET_ENTER_DATA_DIRECTIVE = CursorKind(261)
+
+# OpenMP target exit data directive.
+CursorKind.OMP_TARGET_EXIT_DATA_DIRECTIVE = CursorKind(262)
+
+# OpenMP target parallel directive.
+CursorKind.OMP_TARGET_PARALLEL_DIRECTIVE = CursorKind(263)
+
+# OpenMP target parallel for directive.
+CursorKind.OMP_TARGET_PARALLELFOR_DIRECTIVE = CursorKind(264)
+
+# OpenMP target update directive.
+CursorKind.OMP_TARGET_UPDATE_DIRECTIVE = CursorKind(265)
+
+# OpenMP distribute parallel for directive.
+CursorKind.OMP_DISTRIBUTE_PARALLELFOR_DIRECTIVE = CursorKind(266)
+
+# OpenMP distribute parallel for simd directive.
+CursorKind.OMP_DISTRIBUTE_PARALLEL_FOR_SIMD_DIRECTIVE = CursorKind(267)
+
+# OpenMP distribute simd directive.
+CursorKind.OMP_DISTRIBUTE_SIMD_DIRECTIVE = CursorKind(268)
+
+# OpenMP target parallel for simd directive.
+CursorKind.OMP_TARGET_PARALLEL_FOR_SIMD_DIRECTIVE = CursorKind(269)
+
+# OpenMP target simd directive.
+CursorKind.OMP_TARGET_SIMD_DIRECTIVE = CursorKind(270)
+
+# OpenMP teams distribute directive.
+CursorKind.OMP_TEAMS_DISTRIBUTE_DIRECTIVE = CursorKind(271)
+
 ###
 # Other Kinds
 
@@ -1161,6 +1287,8 @@
 CursorKind.MODULE_IMPORT_DECL = CursorKind(600)
 # A type alias template declaration
 CursorKind.TYPE_ALIAS_TEMPLATE_DECL = CursorKind(601)
+# A static_assert or _Static_assert node
+CursorKind.STATIC_ASSERT = CursorKind(602)
 
 # A code completion overload candidate.
 CursorKind.OVERLOAD_CANDIDATE = CursorKind(700)

[PATCH] D25572: [Coverage] Support for C++17 if initializers

2016-10-14 Thread Igor Kudrin via cfe-commits
ikudrin accepted this revision.
ikudrin added a comment.
This revision is now accepted and ready to land.

LGTM.


https://reviews.llvm.org/D25572



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


[PATCH] D25539: [Coverage] Support for C++17 switch initializers

2016-10-14 Thread Igor Kudrin via cfe-commits
ikudrin accepted this revision.
ikudrin added a comment.
This revision is now accepted and ready to land.

LGTM.


https://reviews.llvm.org/D25539



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


[PATCH] D25608: [libclang] Make tests for python bindings pass on Windows.

2016-10-14 Thread Igor Kudrin via cfe-commits
ikudrin created this revision.
ikudrin added reviewers: hansonw, compnerd, indygreg, eliben.
ikudrin added a subscriber: cfe-commits.

Please note that this patch fixes only Windows-related issues. 
https://reviews.llvm.org/D25470 is required to pass all the tests.


https://reviews.llvm.org/D25608

Files:
  bindings/python/tests/cindex/INPUTS/windows/compile_commands.json
  bindings/python/tests/cindex/test_cdb.py
  bindings/python/tests/cindex/test_cursor.py
  bindings/python/tests/cindex/test_translation_unit.py

Index: bindings/python/tests/cindex/test_translation_unit.py
===
--- bindings/python/tests/cindex/test_translation_unit.py
+++ bindings/python/tests/cindex/test_translation_unit.py
@@ -94,7 +94,9 @@
 
 Returns the filename it was saved to.
 """
-_, path = tempfile.mkstemp()
+fd, path = tempfile.mkstemp()
+# On Windows, if a file is open it cannot be replaced or deleted.
+os.close(fd)
 tu.save(path)
 
 return path
@@ -142,6 +144,7 @@
 
 # Just in case there is an open file descriptor somewhere.
 del tu2
+del foo
 
 os.unlink(path)
 
Index: bindings/python/tests/cindex/test_cursor.py
===
--- bindings/python/tests/cindex/test_cursor.py
+++ bindings/python/tests/cindex/test_cursor.py
@@ -295,7 +295,7 @@
 
 assert enum.kind == CursorKind.ENUM_DECL
 enum_type = enum.enum_type
-assert enum_type.kind == TypeKind.UINT
+assert enum_type.kind in (TypeKind.UINT, TypeKind.INT)
 
 def test_enum_type_cpp():
 tu = get_tu('enum TEST : long long { FOO=1, BAR=2 };', lang="cpp")
@@ -451,4 +451,4 @@
 # all valid manglings.
 # [c-index-test handles this by running the source through clang, emitting
 #  an AST file and running libclang on that AST file]
-assert foo.mangled_name in ('_Z3fooii', '__Z3fooii', '?foo@@YAHHH')
+assert foo.mangled_name in ('_Z3fooii', '__Z3fooii', '?foo@@YAHHH@Z')
Index: bindings/python/tests/cindex/test_cdb.py
===
--- bindings/python/tests/cindex/test_cdb.py
+++ bindings/python/tests/cindex/test_cdb.py
@@ -5,7 +5,20 @@
 import os
 import gc
 
-kInputsDir = os.path.join(os.path.dirname(__file__), 'INPUTS')
+if os.name == 'nt':
+kInputsDir = os.path.join(os.path.dirname(__file__), 'INPUTS', 'windows')
+kProjectFile = 'C:\\home\\john.doe\\MyProject\\project.cpp'
+kProject2File = 'C:\\home\\john.doe\\MyProject\\project2.cpp'
+kProjectDir = 'C:/home/john.doe/MyProject'
+kProjectADir = 'C:/home/john.doe/MyProjectA'
+kProjectBDir = 'C:/home/john.doe/MyProjectB'
+else:
+kInputsDir = os.path.join(os.path.dirname(__file__), 'INPUTS')
+kProjectFile = '/home/john.doe/MyProject/project.cpp'
+kProject2File = '/home/john.doe/MyProject/project2.cpp'
+kProjectDir = '/home/john.doe/MyProject'
+kProjectADir = '/home/john.doe/MyProjectA'
+kProjectBDir = '/home/john.doe/MyProjectB'
 
 def test_create_fail():
 """Check we fail loading a database with an assertion"""
@@ -29,27 +42,27 @@
 def test_lookup_succeed():
 """Check we get some results if the file exists in the db"""
 cdb = CompilationDatabase.fromDirectory(kInputsDir)
-cmds = cdb.getCompileCommands('/home/john.doe/MyProject/project.cpp')
+cmds = cdb.getCompileCommands(kProjectFile)
 assert len(cmds) != 0
 
 def test_all_compilecommand():
 """Check we get all results from the db"""
 cdb = CompilationDatabase.fromDirectory(kInputsDir)
 cmds = cdb.getAllCompileCommands()
 assert len(cmds) == 3
 expected = [
-{ 'wd': '/home/john.doe/MyProject',
-  'file': '/home/john.doe/MyProject/project.cpp',
+{ 'wd': kProjectDir,
+  'file': kProjectFile,
   'line': ['clang++', '-o', 'project.o', '-c',
-   '/home/john.doe/MyProject/project.cpp']},
-{ 'wd': '/home/john.doe/MyProjectA',
-  'file': '/home/john.doe/MyProject/project2.cpp',
+   kProjectFile]},
+{ 'wd': kProjectADir,
+  'file': kProject2File,
   'line': ['clang++', '-o', 'project2.o', '-c',
-   '/home/john.doe/MyProject/project2.cpp']},
-{ 'wd': '/home/john.doe/MyProjectB',
-  'file': '/home/john.doe/MyProject/project2.cpp',
+   kProject2File]},
+{ 'wd': kProjectBDir,
+  'file': kProject2File,
   'line': ['clang++', '-DFEATURE=1', '-o', 'project2-feature.o', '-c',
-   '/home/john.doe/MyProject/project2.cpp']},
+   kProject2File]},
 
 ]
 for i in range(len(cmds)):
@@ -61,28 +74,28 @@
 def test_1_compilecommand():
 """Check file with single compile command"""
 cdb = CompilationDatabase.fromDirectory(kInputsDir)
-file = '/home/john.doe/MyProject/project.cpp'
+file = kProjectFile
 cmds = 

[PATCH] D25470: [libclang] Fix a failure in a test for python bindings on CursorKind.OVERLOAD_CANDIDATE.

2016-10-11 Thread Igor Kudrin via cfe-commits
ikudrin created this revision.
ikudrin added reviewers: hansonw, compnerd.
ikudrin added a subscriber: cfe-commits.

The test fails because the value does not lay in any existing group.

The value was added in r268167.


https://reviews.llvm.org/D25470

Files:
  bindings/python/tests/cindex/test_cursor_kind.py


Index: bindings/python/tests/cindex/test_cursor_kind.py
===
--- bindings/python/tests/cindex/test_cursor_kind.py
+++ bindings/python/tests/cindex/test_cursor_kind.py
@@ -42,7 +42,8 @@
 CursorKind.MACRO_DEFINITION,
 CursorKind.MACRO_INSTANTIATION,
 CursorKind.INCLUSION_DIRECTIVE,
-CursorKind.PREPROCESSING_DIRECTIVE):
+CursorKind.PREPROCESSING_DIRECTIVE,
+CursorKind.OVERLOAD_CANDIDATE):
 assert len(group) == 0
 else:
 assert len(group) == 1


Index: bindings/python/tests/cindex/test_cursor_kind.py
===
--- bindings/python/tests/cindex/test_cursor_kind.py
+++ bindings/python/tests/cindex/test_cursor_kind.py
@@ -42,7 +42,8 @@
 CursorKind.MACRO_DEFINITION,
 CursorKind.MACRO_INSTANTIATION,
 CursorKind.INCLUSION_DIRECTIVE,
-CursorKind.PREPROCESSING_DIRECTIVE):
+CursorKind.PREPROCESSING_DIRECTIVE,
+CursorKind.OVERLOAD_CANDIDATE):
 assert len(group) == 0
 else:
 assert len(group) == 1
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D17815: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-10-07 Thread Igor Kudrin via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL283531: Recommit r282692: [libc++abi] Use fallback_malloc to 
allocate __cxa_eh_globals… (authored by ikudrin).

Changed prior to commit:
  https://reviews.llvm.org/D17815?vs=72951=73893#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D17815

Files:
  libcxxabi/trunk/src/CMakeLists.txt
  libcxxabi/trunk/src/cxa_exception.cpp
  libcxxabi/trunk/src/cxa_exception_storage.cpp
  libcxxabi/trunk/src/fallback_malloc.cpp
  libcxxabi/trunk/src/fallback_malloc.h
  libcxxabi/trunk/src/fallback_malloc.ipp
  libcxxabi/trunk/test/test_exception_storage_nodynmem.pass.cpp
  libcxxabi/trunk/test/test_fallback_malloc.pass.cpp

Index: libcxxabi/trunk/src/cxa_exception.cpp
===
--- libcxxabi/trunk/src/cxa_exception.cpp
+++ libcxxabi/trunk/src/cxa_exception.cpp
@@ -15,13 +15,10 @@
 #include "cxxabi.h"
 
 #include // for std::terminate
-#include   // for malloc, free
 #include   // for memset
-#ifndef _LIBCXXABI_HAS_NO_THREADS
-#  include   // for fallback_malloc.ipp's mutexes
-#endif
 #include "cxa_exception.hpp"
 #include "cxa_handlers.hpp"
+#include "fallback_malloc.h"
 
 // +---+-+---+
 // | __cxa_exception   | _Unwind_Exception CLNGC++\0 | thrown object |
@@ -104,20 +101,6 @@
 return --exception->handlerCount;
 }
 
-#include "fallback_malloc.ipp"
-
-//  Allocate some memory from _somewhere_
-static void *do_malloc(size_t size) {
-void *ptr = std::malloc(size);
-if (NULL == ptr) // if malloc fails, fall back to emergency stash
-ptr = fallback_malloc(size);
-return ptr;
-}
-
-static void do_free(void *ptr) {
-is_fallback_ptr(ptr) ? fallback_free(ptr) : std::free(ptr);
-}
-
 /*
 If reason isn't _URC_FOREIGN_EXCEPTION_CAUGHT, then the terminateHandler
 stored in exc is called.  Otherwise the exceptionDestructor stored in 
@@ -158,7 +141,8 @@
 //  user's exception object.
 _LIBCXXABI_FUNC_VIS void *__cxa_allocate_exception(size_t thrown_size) throw() {
 size_t actual_size = cxa_exception_size_from_exception_thrown_size(thrown_size);
-__cxa_exception* exception_header = static_cast<__cxa_exception*>(do_malloc(actual_size));
+__cxa_exception *exception_header =
+static_cast<__cxa_exception *>(__malloc_with_fallback(actual_size));
 if (NULL == exception_header)
 std::terminate();
 std::memset(exception_header, 0, actual_size);
@@ -168,16 +152,16 @@
 
 //  Free a __cxa_exception object allocated with __cxa_allocate_exception.
 _LIBCXXABI_FUNC_VIS void __cxa_free_exception(void *thrown_object) throw() {
-do_free(cxa_exception_from_thrown_object(thrown_object));
+__free_with_fallback(cxa_exception_from_thrown_object(thrown_object));
 }
 
 
 //  This function shall allocate a __cxa_dependent_exception and
 //  return a pointer to it. (Really to the object, not past its' end).
 //  Otherwise, it will work like __cxa_allocate_exception.
 void * __cxa_allocate_dependent_exception () {
 size_t actual_size = sizeof(__cxa_dependent_exception);
-void *ptr = do_malloc(actual_size);
+void *ptr = __malloc_with_fallback(actual_size);
 if (NULL == ptr)
 std::terminate();
 std::memset(ptr, 0, actual_size);
@@ -188,7 +172,7 @@
 //  This function shall free a dependent_exception.
 //  It does not affect the reference count of the primary exception.
 void __cxa_free_dependent_exception (void * dependent_exception) {
-do_free(dependent_exception);
+__free_with_fallback(dependent_exception);
 }
 
 
Index: libcxxabi/trunk/src/fallback_malloc.cpp
===
--- libcxxabi/trunk/src/fallback_malloc.cpp
+++ libcxxabi/trunk/src/fallback_malloc.cpp
@@ -0,0 +1,226 @@
+//=== fallback_malloc.cpp -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "fallback_malloc.h"
+
+#include "config.h"
+
+#include  // for malloc, calloc, free
+#include  // for memset
+
+#ifndef _LIBCXXABI_HAS_NO_THREADS
+#include  // for mutexes
+#endif
+
+//  A small, simple heap manager based (loosely) on
+//  the startup heap manager from FreeBSD, optimized for space.
+//
+//  Manages a fixed-size memory pool, supports malloc and free only.
+//  No support for realloc.
+//
+//  Allocates chunks in multiples of four bytes, with a four byte header
+//  for each chunk. The overhead of each chunk is kept low by keeping pointers
+//  as two byte offsets within the heap, rather than (4 or 8 byte) pointers.
+
+namespace {
+
+// When POSIX threads are not available, make the 

[libcxxabi] r283531 - Recommit r282692: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-10-07 Thread Igor Kudrin via cfe-commits
Author: ikudrin
Date: Fri Oct  7 03:48:28 2016
New Revision: 283531

URL: http://llvm.org/viewvc/llvm-project?rev=283531=rev
Log:
Recommit r282692: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals 
in case of dynamic memory exhaustion.

Throwing an exception for the first time may lead to call calloc to
allocate memory for __cxa_eh_globals. If the memory pool is exhausted
at that moment, it results in abnormal termination of the program.

This patch addresses the issue by using fallback_malloc in that case.

In this revision, some restrictions were added into the test to not
run it in unsuitable environments.

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


Added:
libcxxabi/trunk/src/fallback_malloc.cpp
libcxxabi/trunk/src/fallback_malloc.h
libcxxabi/trunk/test/test_exception_storage_nodynmem.pass.cpp
Removed:
libcxxabi/trunk/src/fallback_malloc.ipp
Modified:
libcxxabi/trunk/src/CMakeLists.txt
libcxxabi/trunk/src/cxa_exception.cpp
libcxxabi/trunk/src/cxa_exception_storage.cpp
libcxxabi/trunk/test/test_fallback_malloc.pass.cpp

Modified: libcxxabi/trunk/src/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/CMakeLists.txt?rev=283531=283530=283531=diff
==
--- libcxxabi/trunk/src/CMakeLists.txt (original)
+++ libcxxabi/trunk/src/CMakeLists.txt Fri Oct  7 03:48:28 2016
@@ -12,6 +12,7 @@ set(LIBCXXABI_SOURCES
   cxa_vector.cpp
   cxa_virtual.cpp
   exception.cpp
+  fallback_malloc.cpp
   private_typeinfo.cpp
   stdexcept.cpp
   typeinfo.cpp

Modified: libcxxabi/trunk/src/cxa_exception.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_exception.cpp?rev=283531=283530=283531=diff
==
--- libcxxabi/trunk/src/cxa_exception.cpp (original)
+++ libcxxabi/trunk/src/cxa_exception.cpp Fri Oct  7 03:48:28 2016
@@ -15,13 +15,10 @@
 #include "cxxabi.h"
 
 #include // for std::terminate
-#include   // for malloc, free
 #include   // for memset
-#ifndef _LIBCXXABI_HAS_NO_THREADS
-#  include   // for fallback_malloc.ipp's mutexes
-#endif
 #include "cxa_exception.hpp"
 #include "cxa_handlers.hpp"
+#include "fallback_malloc.h"
 
 // +---+-+---+
 // | __cxa_exception   | _Unwind_Exception CLNGC++\0 | thrown object |
@@ -104,20 +101,6 @@ static inline  int decrementHandlerCount
 return --exception->handlerCount;
 }
 
-#include "fallback_malloc.ipp"
-
-//  Allocate some memory from _somewhere_
-static void *do_malloc(size_t size) {
-void *ptr = std::malloc(size);
-if (NULL == ptr) // if malloc fails, fall back to emergency stash
-ptr = fallback_malloc(size);
-return ptr;
-}
-
-static void do_free(void *ptr) {
-is_fallback_ptr(ptr) ? fallback_free(ptr) : std::free(ptr);
-}
-
 /*
 If reason isn't _URC_FOREIGN_EXCEPTION_CAUGHT, then the terminateHandler
 stored in exc is called.  Otherwise the exceptionDestructor stored in 
@@ -158,7 +141,8 @@ extern "C" {
 //  user's exception object.
 _LIBCXXABI_FUNC_VIS void *__cxa_allocate_exception(size_t thrown_size) throw() 
{
 size_t actual_size = 
cxa_exception_size_from_exception_thrown_size(thrown_size);
-__cxa_exception* exception_header = 
static_cast<__cxa_exception*>(do_malloc(actual_size));
+__cxa_exception *exception_header =
+static_cast<__cxa_exception *>(__malloc_with_fallback(actual_size));
 if (NULL == exception_header)
 std::terminate();
 std::memset(exception_header, 0, actual_size);
@@ -168,7 +152,7 @@ _LIBCXXABI_FUNC_VIS void *__cxa_allocate
 
 //  Free a __cxa_exception object allocated with __cxa_allocate_exception.
 _LIBCXXABI_FUNC_VIS void __cxa_free_exception(void *thrown_object) throw() {
-do_free(cxa_exception_from_thrown_object(thrown_object));
+__free_with_fallback(cxa_exception_from_thrown_object(thrown_object));
 }
 
 
@@ -177,7 +161,7 @@ _LIBCXXABI_FUNC_VIS void __cxa_free_exce
 //  Otherwise, it will work like __cxa_allocate_exception.
 void * __cxa_allocate_dependent_exception () {
 size_t actual_size = sizeof(__cxa_dependent_exception);
-void *ptr = do_malloc(actual_size);
+void *ptr = __malloc_with_fallback(actual_size);
 if (NULL == ptr)
 std::terminate();
 std::memset(ptr, 0, actual_size);
@@ -188,7 +172,7 @@ void * __cxa_allocate_dependent_exceptio
 //  This function shall free a dependent_exception.
 //  It does not affect the reference count of the primary exception.
 void __cxa_free_dependent_exception (void * dependent_exception) {
-do_free(dependent_exception);
+__free_with_fallback(dependent_exception);
 }
 
 

Modified: libcxxabi/trunk/src/cxa_exception_storage.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_exception_storage.cpp?rev=283531=283530=283531=diff

[PATCH] [Reopened] D17815: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-09-30 Thread Igor Kudrin via cfe-commits
ikudrin reopened this revision.
ikudrin added a comment.
This revision is now accepted and ready to land.

@rmaprath: There are some issues in the test which upset build bots and I need 
some time to fix them. You don't need to wait for me, I'll put my patch on the 
top of yours when my fix is ready.


Repository:
  rL LLVM

https://reviews.llvm.org/D17815



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


[libcxxabi] r282703 - Revert r282692: Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-09-29 Thread Igor Kudrin via cfe-commits
Author: ikudrin
Date: Thu Sep 29 03:11:57 2016
New Revision: 282703

URL: http://llvm.org/viewvc/llvm-project?rev=282703=rev
Log:
Revert r282692: Use fallback_malloc to allocate __cxa_eh_globals in case of 
dynamic memory exhaustion.

The test breaks build bots.

Added:
libcxxabi/trunk/src/fallback_malloc.ipp
  - copied unchanged from r282691, libcxxabi/trunk/src/fallback_malloc.ipp
Removed:
libcxxabi/trunk/src/fallback_malloc.cpp
libcxxabi/trunk/src/fallback_malloc.h
libcxxabi/trunk/test/test_exception_storage_nodynmem.pass.cpp
Modified:
libcxxabi/trunk/src/CMakeLists.txt
libcxxabi/trunk/src/cxa_exception.cpp
libcxxabi/trunk/src/cxa_exception_storage.cpp
libcxxabi/trunk/test/test_fallback_malloc.pass.cpp

Modified: libcxxabi/trunk/src/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/CMakeLists.txt?rev=282703=282702=282703=diff
==
--- libcxxabi/trunk/src/CMakeLists.txt (original)
+++ libcxxabi/trunk/src/CMakeLists.txt Thu Sep 29 03:11:57 2016
@@ -12,7 +12,6 @@ set(LIBCXXABI_SOURCES
   cxa_vector.cpp
   cxa_virtual.cpp
   exception.cpp
-  fallback_malloc.cpp
   private_typeinfo.cpp
   stdexcept.cpp
   typeinfo.cpp

Modified: libcxxabi/trunk/src/cxa_exception.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_exception.cpp?rev=282703=282702=282703=diff
==
--- libcxxabi/trunk/src/cxa_exception.cpp (original)
+++ libcxxabi/trunk/src/cxa_exception.cpp Thu Sep 29 03:11:57 2016
@@ -15,10 +15,13 @@
 #include "cxxabi.h"
 
 #include // for std::terminate
+#include   // for malloc, free
 #include   // for memset
+#ifndef _LIBCXXABI_HAS_NO_THREADS
+#  include   // for fallback_malloc.ipp's mutexes
+#endif
 #include "cxa_exception.hpp"
 #include "cxa_handlers.hpp"
-#include "fallback_malloc.h"
 
 // +---+-+---+
 // | __cxa_exception   | _Unwind_Exception CLNGC++\0 | thrown object |
@@ -101,6 +104,20 @@ static inline  int decrementHandlerCount
 return --exception->handlerCount;
 }
 
+#include "fallback_malloc.ipp"
+
+//  Allocate some memory from _somewhere_
+static void *do_malloc(size_t size) {
+void *ptr = std::malloc(size);
+if (NULL == ptr) // if malloc fails, fall back to emergency stash
+ptr = fallback_malloc(size);
+return ptr;
+}
+
+static void do_free(void *ptr) {
+is_fallback_ptr(ptr) ? fallback_free(ptr) : std::free(ptr);
+}
+
 /*
 If reason isn't _URC_FOREIGN_EXCEPTION_CAUGHT, then the terminateHandler
 stored in exc is called.  Otherwise the exceptionDestructor stored in 
@@ -141,8 +158,7 @@ extern "C" {
 //  user's exception object.
 _LIBCXXABI_FUNC_VIS void *__cxa_allocate_exception(size_t thrown_size) throw() 
{
 size_t actual_size = 
cxa_exception_size_from_exception_thrown_size(thrown_size);
-__cxa_exception *exception_header =
-static_cast<__cxa_exception *>(__malloc_with_fallback(actual_size));
+__cxa_exception* exception_header = 
static_cast<__cxa_exception*>(do_malloc(actual_size));
 if (NULL == exception_header)
 std::terminate();
 std::memset(exception_header, 0, actual_size);
@@ -152,7 +168,7 @@ _LIBCXXABI_FUNC_VIS void *__cxa_allocate
 
 //  Free a __cxa_exception object allocated with __cxa_allocate_exception.
 _LIBCXXABI_FUNC_VIS void __cxa_free_exception(void *thrown_object) throw() {
-__free_with_fallback(cxa_exception_from_thrown_object(thrown_object));
+do_free(cxa_exception_from_thrown_object(thrown_object));
 }
 
 
@@ -161,7 +177,7 @@ _LIBCXXABI_FUNC_VIS void __cxa_free_exce
 //  Otherwise, it will work like __cxa_allocate_exception.
 void * __cxa_allocate_dependent_exception () {
 size_t actual_size = sizeof(__cxa_dependent_exception);
-void *ptr = __malloc_with_fallback(actual_size);
+void *ptr = do_malloc(actual_size);
 if (NULL == ptr)
 std::terminate();
 std::memset(ptr, 0, actual_size);
@@ -172,7 +188,7 @@ void * __cxa_allocate_dependent_exceptio
 //  This function shall free a dependent_exception.
 //  It does not affect the reference count of the primary exception.
 void __cxa_free_dependent_exception (void * dependent_exception) {
-__free_with_fallback(dependent_exception);
+do_free(dependent_exception);
 }
 
 

Modified: libcxxabi/trunk/src/cxa_exception_storage.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_exception_storage.cpp?rev=282703=282702=282703=diff
==
--- libcxxabi/trunk/src/cxa_exception_storage.cpp (original)
+++ libcxxabi/trunk/src/cxa_exception_storage.cpp Thu Sep 29 03:11:57 2016
@@ -45,8 +45,8 @@ extern "C" {
 #else
 
 #include 
+#include   // for calloc, free
 #include "abort_message.h"
-#include 

Re: [PATCH] D17815: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-09-29 Thread Igor Kudrin via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL282692: [libc++abi] Use fallback_malloc to allocate 
__cxa_eh_globals in case of… (authored by ikudrin).

Changed prior to commit:
  https://reviews.llvm.org/D17815?vs=54189=72951#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D17815

Files:
  libcxxabi/trunk/src/CMakeLists.txt
  libcxxabi/trunk/src/cxa_exception.cpp
  libcxxabi/trunk/src/cxa_exception_storage.cpp
  libcxxabi/trunk/src/fallback_malloc.cpp
  libcxxabi/trunk/src/fallback_malloc.h
  libcxxabi/trunk/src/fallback_malloc.ipp
  libcxxabi/trunk/test/test_exception_storage_nodynmem.pass.cpp
  libcxxabi/trunk/test/test_fallback_malloc.pass.cpp

Index: libcxxabi/trunk/src/fallback_malloc.cpp
===
--- libcxxabi/trunk/src/fallback_malloc.cpp
+++ libcxxabi/trunk/src/fallback_malloc.cpp
@@ -0,0 +1,226 @@
+//=== fallback_malloc.cpp -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "fallback_malloc.h"
+
+#include "config.h"
+
+#include  // for malloc, calloc, free
+#include  // for memset
+
+#ifndef _LIBCXXABI_HAS_NO_THREADS
+#include  // for mutexes
+#endif
+
+//  A small, simple heap manager based (loosely) on
+//  the startup heap manager from FreeBSD, optimized for space.
+//
+//  Manages a fixed-size memory pool, supports malloc and free only.
+//  No support for realloc.
+//
+//  Allocates chunks in multiples of four bytes, with a four byte header
+//  for each chunk. The overhead of each chunk is kept low by keeping pointers
+//  as two byte offsets within the heap, rather than (4 or 8 byte) pointers.
+
+namespace {
+
+// When POSIX threads are not available, make the mutex operations a nop
+#ifndef _LIBCXXABI_HAS_NO_THREADS
+static pthread_mutex_t heap_mutex = PTHREAD_MUTEX_INITIALIZER;
+#else
+static void * heap_mutex = 0;
+#endif
+
+class mutexor {
+public:
+#ifndef _LIBCXXABI_HAS_NO_THREADS
+mutexor ( pthread_mutex_t *m ) : mtx_(m) { pthread_mutex_lock ( mtx_ ); }
+~mutexor () { pthread_mutex_unlock ( mtx_ ); }
+#else
+mutexor ( void * ) {}
+~mutexor () {}
+#endif
+private:
+mutexor ( const mutexor  );
+mutexor & operator = ( const mutexor  );
+#ifndef _LIBCXXABI_HAS_NO_THREADS
+pthread_mutex_t *mtx_;
+#endif
+};
+
+
+static const size_t HEAP_SIZE = 512;
+char heap [ HEAP_SIZE ] __attribute__((aligned));
+
+typedef unsigned short heap_offset;
+typedef unsigned short heap_size;
+
+struct heap_node {
+heap_offset next_node;  // offset into heap
+heap_size   len;// size in units of "sizeof(heap_node)"
+};
+
+static const heap_node *list_end = (heap_node *) (  [ HEAP_SIZE ] );   // one past the end of the heap
+static heap_node *freelist = NULL;
+
+heap_node *node_from_offset ( const heap_offset offset )
+{ return (heap_node *) ( heap + ( offset * sizeof (heap_node))); }
+
+heap_offset offset_from_node ( const heap_node *ptr )
+{ return static_cast(static_cast(reinterpret_cast(ptr) - heap)  / sizeof (heap_node)); }
+
+void init_heap () {
+freelist = (heap_node *) heap;
+freelist->next_node = offset_from_node ( list_end );
+freelist->len = HEAP_SIZE / sizeof (heap_node);
+}
+
+//  How big a chunk we allocate
+size_t alloc_size (size_t len)
+{ return (len + sizeof(heap_node) - 1) / sizeof(heap_node) + 1; }
+
+bool is_fallback_ptr ( void *ptr )
+{ return ptr >= heap && ptr < ( heap + HEAP_SIZE ); }
+
+void *fallback_malloc(size_t len) {
+heap_node *p, *prev;
+const size_t nelems = alloc_size ( len );
+mutexor mtx ( _mutex );
+
+if ( NULL == freelist )
+init_heap ();
+
+//  Walk the free list, looking for a "big enough" chunk
+for (p = freelist, prev = 0;
+p && p != list_end; prev = p, p = node_from_offset ( p->next_node)) {
+
+if (p->len > nelems) {  //  chunk is larger, shorten, and return the tail
+heap_node *q;
+
+p->len = static_cast(p->len - nelems);
+q = p + p->len;
+q->next_node = 0;
+q->len = static_cast(nelems);
+return (void *) (q + 1);
+}
+
+if (p->len == nelems) { // exact size match
+if (prev == 0)
+freelist = node_from_offset(p->next_node);
+else
+prev->next_node = p->next_node;
+p->next_node = 0;
+return (void *) (p + 1);
+}
+}
+return NULL;// couldn't find a spot big enough
+}
+
+//  Return the start of the next block
+heap_node *after ( struct heap_node *p ) { return p + p->len; }
+
+void fallback_free (void *ptr) {
+struct heap_node *cp = ((struct heap_node *) 

Re: [PATCH] D17815: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-09-26 Thread Igor Kudrin via cfe-commits

Hi Eric,

Ping...

On 19-Sep-16 13:57, Eric Fiselier wrote:


I'll look at these first thing next week. If you remember please ping 
me. (It's Cppcon this week)


Sorry I haven't reviewed this already. Thank you for working on this.


On Sep 18, 2016 11:55 PM, "Igor Kudrin" > wrote:


ikudrin added a comment.

Hi,

Ping.

The patch is under review for a long time and the described
problem is still here. As we've seen the issue in practice, I'm
sure that others may also run into it, and I do believe it should
be fixed, one way or another.

@EricWF, can I improve the patch somehow to pass the review? Or
maybe you prefer it to be fixed in some other way?


https://reviews.llvm.org/D17815 





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


Re: [PATCH] D17815: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-09-19 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

Hi,

Ping.

The patch is under review for a long time and the described problem is still 
here. As we've seen the issue in practice, I'm sure that others may also run 
into it, and I do believe it should be fixed, one way or another.

@EricWF, can I improve the patch somehow to pass the review? Or maybe you 
prefer it to be fixed in some other way?


https://reviews.llvm.org/D17815



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


Re: [PATCH] D17815: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-09-01 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

Ping...


https://reviews.llvm.org/D17815



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


r280199 - [Coverage] Suppress creating a code region if the same area is covered by an expansion region.

2016-08-31 Thread Igor Kudrin via cfe-commits
Author: ikudrin
Date: Wed Aug 31 02:04:16 2016
New Revision: 280199

URL: http://llvm.org/viewvc/llvm-project?rev=280199=rev
Log:
[Coverage] Suppress creating a code region if the same area is covered by an 
expansion region.

In most cases these code regions are just redundant, but sometimes they
could be assigned to the counter of the parent code region instead of
the counter of the nested block.

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

Modified:
cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
cfe/trunk/test/CoverageMapping/macroception.c
cfe/trunk/test/CoverageMapping/macros.c

Modified: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp?rev=280199=280198=280199=diff
==
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp (original)
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp Wed Aug 31 02:04:16 2016
@@ -92,6 +92,14 @@ public:
   /// \brief The source mapping regions for this function.
   std::vector SourceRegions;
 
+  /// \brief A set of regions which can be used as a filter.
+  ///
+  /// It is produced by emitExpansionRegions() and is used in
+  /// emitSourceRegions() to suppress producing code regions if
+  /// the same area is covered by expansion regions.
+  typedef llvm::SmallSet, 8>
+  SourceRegionFilter;
+
   CoverageMappingBuilder(CoverageMappingModuleGen , SourceManager ,
  const LangOptions )
   : CVM(CVM), SM(SM), LangOpts(LangOpts) {}
@@ -249,7 +257,7 @@ public:
 
   /// \brief Generate the coverage counter mapping regions from collected
   /// source regions.
-  void emitSourceRegions() {
+  void emitSourceRegions(const SourceRegionFilter ) {
 for (const auto  : SourceRegions) {
   assert(Region.hasEndLoc() && "incomplete region");
 
@@ -269,6 +277,13 @@ public:
   assert(SM.isWrittenInSameFile(LocStart, LocEnd) &&
  "region spans multiple files");
 
+  // Don't add code regions for the area covered by expansion regions.
+  // This not only suppresses redundant regions, but sometimes prevents
+  // creating regions with wrong counters if, for example, a statement's
+  // body ends at the end of a nested macro.
+  if (Filter.count(std::make_pair(LocStart, LocEnd)))
+continue;
+
   // Find the spilling locations for the mapping region.
   unsigned LineStart = SM.getSpellingLineNumber(LocStart);
   unsigned ColumnStart = SM.getSpellingColumnNumber(LocStart);
@@ -283,7 +298,8 @@ public:
   }
 
   /// \brief Generate expansion regions for each virtual file we've seen.
-  void emitExpansionRegions() {
+  SourceRegionFilter emitExpansionRegions() {
+SourceRegionFilter Filter;
 for (const auto  : FileIDMapping) {
   SourceLocation ExpandedLoc = FM.second.second;
   SourceLocation ParentLoc = getIncludeOrExpansionLoc(ExpandedLoc);
@@ -299,6 +315,7 @@ public:
   SourceLocation LocEnd = getPreciseTokenLocEnd(ParentLoc);
   assert(SM.isWrittenInSameFile(ParentLoc, LocEnd) &&
  "region spans multiple files");
+  Filter.insert(std::make_pair(ParentLoc, LocEnd));
 
   unsigned LineStart = SM.getSpellingLineNumber(ParentLoc);
   unsigned ColumnStart = SM.getSpellingColumnNumber(ParentLoc);
@@ -309,6 +326,7 @@ public:
   *ParentFileID, *ExpandedFileID, LineStart, ColumnStart, LineEnd,
   ColumnEnd));
 }
+return Filter;
   }
 };
 
@@ -350,7 +368,7 @@ struct EmptyCoverageMappingBuilder : pub
   void write(llvm::raw_ostream ) {
 SmallVector FileIDMapping;
 gatherFileIDs(FileIDMapping);
-emitSourceRegions();
+emitSourceRegions(SourceRegionFilter());
 
 if (MappingRegions.empty())
   return;
@@ -605,8 +623,8 @@ struct CounterCoverageMappingBuilder
   void write(llvm::raw_ostream ) {
 llvm::SmallVector VirtualFileMapping;
 gatherFileIDs(VirtualFileMapping);
-emitSourceRegions();
-emitExpansionRegions();
+SourceRegionFilter Filter = emitExpansionRegions();
+emitSourceRegions(Filter);
 gatherSkippedRegions();
 
 if (MappingRegions.empty())

Modified: cfe/trunk/test/CoverageMapping/macroception.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/macroception.c?rev=280199=280198=280199=diff
==
--- cfe/trunk/test/CoverageMapping/macroception.c (original)
+++ cfe/trunk/test/CoverageMapping/macroception.c Wed Aug 31 02:04:16 2016
@@ -11,7 +11,6 @@
 int main() M1
   return 0;
 }
-// CHECK-NEXT: File 1, 4:12 -> 4:14 = #0
 // CHECK-NEXT: Expansion,File 1, 4:12 -> 4:14 = #0
 // CHECK-NEXT: File 2, 3:12 -> 3:13 = #0
 
@@ -21,7 +20,6 @@ int main() M1
 void func2() {
   int x = 0;
 M11
-// CHECK-NEXT: File 1, 6:13 -> 6:16 = #0
 // CHECK-NEXT: Expansion,File 

Re: [PATCH] D23987: [Coverage] Suppress creating a code region if the same area is covered by an expansion region.

2016-08-31 Thread Igor Kudrin via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL280199: [Coverage] Suppress creating a code region if the 
same area is covered by an… (authored by ikudrin).

Changed prior to commit:
  https://reviews.llvm.org/D23987?vs=69709=69799#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23987

Files:
  cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
  cfe/trunk/test/CoverageMapping/macroception.c
  cfe/trunk/test/CoverageMapping/macros.c

Index: cfe/trunk/test/CoverageMapping/macros.c
===
--- cfe/trunk/test/CoverageMapping/macros.c
+++ cfe/trunk/test/CoverageMapping/macros.c
@@ -3,6 +3,7 @@
 #define MACRO return; bar()
 #define MACRO_2 bar()
 #define MACRO_1 return; MACRO_2
+#define MACRO_3 MACRO_2
 
 void bar() {}
 
@@ -24,7 +25,6 @@
   i = 2;
 }
 // CHECK-NEXT: File 1, 5:17 -> 5:32 = #0
-// CHECK-NEXT: File 1, 5:25 -> 5:32 = 0
 // CHECK-NEXT: Expansion,File 1, 5:25 -> 5:32 = 0
 // CHECK-NEXT: File 2, 4:17 -> 4:22 = 0
 
@@ -47,6 +47,15 @@
 // CHECK-NEXT: File 1, 4:17 -> 4:22 = #2
 // CHECK-NOT: File 1
 
+// CHECK-NEXT: func5
+void func5() { // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+4]]:2 = #0
+  int i = 0;
+  if (i > 5) // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:12 = #0
+MACRO_3; // CHECK-NEXT: Expansion,File 0, [[@LINE]]:5 -> [[@LINE]]:12 = #1
+}
+// CHECK-NEXT: Expansion,File 1, 6:17 -> 6:24 = #1
+// CHECK-NEXT: File 2, 4:17 -> 4:22 = #1
+
 int main(int argc, const char *argv[]) {
   func();
   func2();
Index: cfe/trunk/test/CoverageMapping/macroception.c
===
--- cfe/trunk/test/CoverageMapping/macroception.c
+++ cfe/trunk/test/CoverageMapping/macroception.c
@@ -11,7 +11,6 @@
 int main() M1
   return 0;
 }
-// CHECK-NEXT: File 1, 4:12 -> 4:14 = #0
 // CHECK-NEXT: Expansion,File 1, 4:12 -> 4:14 = #0
 // CHECK-NEXT: File 2, 3:12 -> 3:13 = #0
 
@@ -21,7 +20,6 @@
 void func2() {
   int x = 0;
 M11
-// CHECK-NEXT: File 1, 6:13 -> 6:16 = #0
 // CHECK-NEXT: Expansion,File 1, 6:13 -> 6:16 = #0
 // CHECK-NEXT: File 2, 5:13 -> 5:14 = #0
 
@@ -32,9 +30,7 @@
 void func3() M1
   int x = 0;
 M11
-// CHECK-NEXT: File 1, 4:12 -> 4:14 = #0
 // CHECK-NEXT: Expansion,File 1, 4:12 -> 4:14 = #0
-// CHECK-NEXT: File 2, 6:13 -> 6:16 = #0
 // CHECK-NEXT: Expansion,File 2, 6:13 -> 6:16 = #0
 // CHECK-NEXT: File 3, 3:12 -> 3:13 = #0
 // CHECK-NEXT: File 4, 5:13 -> 5:14 = #0
@@ -44,9 +40,7 @@
 // CHECK-NEXT: File 0, [[@LINE+2]]:16 -> [[@LINE+2]]:20 = #0
 // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:17 -> [[@LINE+1]]:20 = #0
 void func4() M1 M11
-// CHECK-NEXT: File 1, 4:12 -> 4:14 = #0
 // CHECK-NEXT: Expansion,File 1, 4:12 -> 4:14 = #0
-// CHECK-NEXT: File 2, 6:13 -> 6:16 = #0
 // CHECK-NEXT: Expansion,File 2, 6:13 -> 6:16 = #0
 // CHECK-NEXT: File 3, 3:12 -> 3:13 = #0
 // CHECK-NEXT: File 4, 5:13 -> 5:14 = #0
Index: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
===
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
@@ -92,6 +92,14 @@
   /// \brief The source mapping regions for this function.
   std::vector SourceRegions;
 
+  /// \brief A set of regions which can be used as a filter.
+  ///
+  /// It is produced by emitExpansionRegions() and is used in
+  /// emitSourceRegions() to suppress producing code regions if
+  /// the same area is covered by expansion regions.
+  typedef llvm::SmallSet, 8>
+  SourceRegionFilter;
+
   CoverageMappingBuilder(CoverageMappingModuleGen , SourceManager ,
  const LangOptions )
   : CVM(CVM), SM(SM), LangOpts(LangOpts) {}
@@ -249,7 +257,7 @@
 
   /// \brief Generate the coverage counter mapping regions from collected
   /// source regions.
-  void emitSourceRegions() {
+  void emitSourceRegions(const SourceRegionFilter ) {
 for (const auto  : SourceRegions) {
   assert(Region.hasEndLoc() && "incomplete region");
 
@@ -269,6 +277,13 @@
   assert(SM.isWrittenInSameFile(LocStart, LocEnd) &&
  "region spans multiple files");
 
+  // Don't add code regions for the area covered by expansion regions.
+  // This not only suppresses redundant regions, but sometimes prevents
+  // creating regions with wrong counters if, for example, a statement's
+  // body ends at the end of a nested macro.
+  if (Filter.count(std::make_pair(LocStart, LocEnd)))
+continue;
+
   // Find the spilling locations for the mapping region.
   unsigned LineStart = SM.getSpellingLineNumber(LocStart);
   unsigned ColumnStart = SM.getSpellingColumnNumber(LocStart);
@@ -283,7 +298,8 @@
   }
 
   /// \brief Generate expansion regions for each virtual file we've seen.
-  void emitExpansionRegions() {
+  SourceRegionFilter emitExpansionRegions() {
+SourceRegionFilter Filter;
 for (const auto  : 

Re: [PATCH] D23987: [Coverage] Suppress creating a code region if the same area is covered by an expansion region.

2016-08-30 Thread Igor Kudrin via cfe-commits
ikudrin updated this revision to Diff 69709.
ikudrin added a comment.

- Removed a default value in `emitSourceRegions()`, added the corresponding 
argument to its call in `EmptyCoverageMappingBuilder::write()`.
- Removed an additional sorting step in 
`CounterCoverageMappingBuilder::write()`, the patch is now depends on the 
extended sorting creteria in `CoverageMappingWriter::write()`, see 
https://reviews.llvm.org/D24034.


https://reviews.llvm.org/D23987

Files:
  lib/CodeGen/CoverageMappingGen.cpp
  test/CoverageMapping/macroception.c
  test/CoverageMapping/macros.c

Index: test/CoverageMapping/macros.c
===
--- test/CoverageMapping/macros.c
+++ test/CoverageMapping/macros.c
@@ -3,6 +3,7 @@
 #define MACRO return; bar()
 #define MACRO_2 bar()
 #define MACRO_1 return; MACRO_2
+#define MACRO_3 MACRO_2
 
 void bar() {}
 
@@ -24,7 +25,6 @@
   i = 2;
 }
 // CHECK-NEXT: File 1, 5:17 -> 5:32 = #0
-// CHECK-NEXT: File 1, 5:25 -> 5:32 = 0
 // CHECK-NEXT: Expansion,File 1, 5:25 -> 5:32 = 0
 // CHECK-NEXT: File 2, 4:17 -> 4:22 = 0
 
@@ -47,6 +47,15 @@
 // CHECK-NEXT: File 1, 4:17 -> 4:22 = #2
 // CHECK-NOT: File 1
 
+// CHECK-NEXT: func5
+void func5() { // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+4]]:2 = #0
+  int i = 0;
+  if (i > 5) // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:12 = #0
+MACRO_3; // CHECK-NEXT: Expansion,File 0, [[@LINE]]:5 -> [[@LINE]]:12 = #1
+}
+// CHECK-NEXT: Expansion,File 1, 6:17 -> 6:24 = #1
+// CHECK-NEXT: File 2, 4:17 -> 4:22 = #1
+
 int main(int argc, const char *argv[]) {
   func();
   func2();
Index: test/CoverageMapping/macroception.c
===
--- test/CoverageMapping/macroception.c
+++ test/CoverageMapping/macroception.c
@@ -11,7 +11,6 @@
 int main() M1
   return 0;
 }
-// CHECK-NEXT: File 1, 4:12 -> 4:14 = #0
 // CHECK-NEXT: Expansion,File 1, 4:12 -> 4:14 = #0
 // CHECK-NEXT: File 2, 3:12 -> 3:13 = #0
 
@@ -21,7 +20,6 @@
 void func2() {
   int x = 0;
 M11
-// CHECK-NEXT: File 1, 6:13 -> 6:16 = #0
 // CHECK-NEXT: Expansion,File 1, 6:13 -> 6:16 = #0
 // CHECK-NEXT: File 2, 5:13 -> 5:14 = #0
 
@@ -32,9 +30,7 @@
 void func3() M1
   int x = 0;
 M11
-// CHECK-NEXT: File 1, 4:12 -> 4:14 = #0
 // CHECK-NEXT: Expansion,File 1, 4:12 -> 4:14 = #0
-// CHECK-NEXT: File 2, 6:13 -> 6:16 = #0
 // CHECK-NEXT: Expansion,File 2, 6:13 -> 6:16 = #0
 // CHECK-NEXT: File 3, 3:12 -> 3:13 = #0
 // CHECK-NEXT: File 4, 5:13 -> 5:14 = #0
@@ -44,9 +40,7 @@
 // CHECK-NEXT: File 0, [[@LINE+2]]:16 -> [[@LINE+2]]:20 = #0
 // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:17 -> [[@LINE+1]]:20 = #0
 void func4() M1 M11
-// CHECK-NEXT: File 1, 4:12 -> 4:14 = #0
 // CHECK-NEXT: Expansion,File 1, 4:12 -> 4:14 = #0
-// CHECK-NEXT: File 2, 6:13 -> 6:16 = #0
 // CHECK-NEXT: Expansion,File 2, 6:13 -> 6:16 = #0
 // CHECK-NEXT: File 3, 3:12 -> 3:13 = #0
 // CHECK-NEXT: File 4, 5:13 -> 5:14 = #0
Index: lib/CodeGen/CoverageMappingGen.cpp
===
--- lib/CodeGen/CoverageMappingGen.cpp
+++ lib/CodeGen/CoverageMappingGen.cpp
@@ -92,6 +92,14 @@
   /// \brief The source mapping regions for this function.
   std::vector SourceRegions;
 
+  /// \brief A set of regions which can be used as a filter.
+  ///
+  /// It is produced by emitExpansionRegions() and is used in
+  /// emitSourceRegions() to suppress producing code regions if
+  /// the same area is covered by expansion regions.
+  typedef llvm::SmallSet, 8>
+  SourceRegionFilter;
+
   CoverageMappingBuilder(CoverageMappingModuleGen , SourceManager ,
  const LangOptions )
   : CVM(CVM), SM(SM), LangOpts(LangOpts) {}
@@ -249,7 +257,7 @@
 
   /// \brief Generate the coverage counter mapping regions from collected
   /// source regions.
-  void emitSourceRegions() {
+  void emitSourceRegions(const SourceRegionFilter ) {
 for (const auto  : SourceRegions) {
   assert(Region.hasEndLoc() && "incomplete region");
 
@@ -269,6 +277,13 @@
   assert(SM.isWrittenInSameFile(LocStart, LocEnd) &&
  "region spans multiple files");
 
+  // Don't add code regions for the area covered by expansion regions.
+  // This not only suppresses redundant regions, but sometimes prevents
+  // creating regions with wrong counters if, for example, a statement's
+  // body ends at the end of a nested macro.
+  if (Filter.count(std::make_pair(LocStart, LocEnd)))
+continue;
+
   // Find the spilling locations for the mapping region.
   unsigned LineStart = SM.getSpellingLineNumber(LocStart);
   unsigned ColumnStart = SM.getSpellingColumnNumber(LocStart);
@@ -283,7 +298,8 @@
   }
 
   /// \brief Generate expansion regions for each virtual file we've seen.
-  void emitExpansionRegions() {
+  SourceRegionFilter emitExpansionRegions() {
+SourceRegionFilter Filter;
 for (const auto  : 

Re: [PATCH] D23987: [Coverage] Suppress creating a code region if the same area is covered by an expansion region.

2016-08-30 Thread Igor Kudrin via cfe-commits
ikudrin added inline comments.


Comment at: lib/CodeGen/CoverageMappingGen.cpp:261
@@ -253,2 +260,3 @@
+  void emitSourceRegions(const SourceRegionFilter ) {
 for (const auto  : SourceRegions) {
   assert(Region.hasEndLoc() && "incomplete region");

Well, passing a distinct empty value from 
`EmptyCoverageMappingBuilder::write()` is a bit clearer.


Comment at: lib/CodeGen/CoverageMappingGen.cpp:633
@@ -614,3 +632,3 @@
 
 CoverageMappingWriter Writer(VirtualFileMapping, Builder.getExpressions(),
  MappingRegions);

I believe, it's mostly to make our tests happy, but I don't want to make more 
changes in the program's behaviour than needed.


https://reviews.llvm.org/D23987



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


Re: [PATCH] D23160: [Coverage] Prevent creating a redundant counter if a nested body ends with a macro.

2016-08-29 Thread Igor Kudrin via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL279962: [Coverage] Prevent creating a redundant counter if a 
nested body ends with a… (authored by ikudrin).

Changed prior to commit:
  https://reviews.llvm.org/D23160?vs=66790=69556#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23160

Files:
  cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
  cfe/trunk/test/CoverageMapping/macros.c

Index: cfe/trunk/test/CoverageMapping/macros.c
===
--- cfe/trunk/test/CoverageMapping/macros.c
+++ cfe/trunk/test/CoverageMapping/macros.c
@@ -36,8 +36,20 @@
 // CHECK-NEXT: File 1, 4:17 -> 4:22 = #0
 // CHECK-NEXT: File 2, 4:17 -> 4:22 = #0
 
+// CHECK-NEXT: func4
+void func4() { // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+6]]:2 = #0
+  int i = 0;
+  while (i++ < 10) // CHECK-NEXT: File 0, [[@LINE]]:10 -> [[@LINE]]:18 = (#0 + 
#1)
+if (i < 5) // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE+2]]:14 = #1
+   // CHECK-NEXT: File 0, [[@LINE-1]]:9 -> [[@LINE-1]]:14 = #1
+  MACRO_2; // CHECK-NEXT: Expansion,File 0, [[@LINE]]:7 -> [[@LINE]]:14 = 
#2
+}
+// CHECK-NEXT: File 1, 4:17 -> 4:22 = #2
+// CHECK-NOT: File 1
+
 int main(int argc, const char *argv[]) {
   func();
   func2();
   func3();
+  func4();
 }
Index: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
===
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
@@ -432,7 +432,8 @@
   SourceLocation NestedLoc = getStartOfFileOrMacro(EndLoc);
   assert(SM.isWrittenInSameFile(NestedLoc, EndLoc));
 
-  SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc);
+  if (!isRegionAlreadyAdded(NestedLoc, EndLoc))
+SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc);
 
   EndLoc = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(EndLoc));
   if (EndLoc.isInvalid())


Index: cfe/trunk/test/CoverageMapping/macros.c
===
--- cfe/trunk/test/CoverageMapping/macros.c
+++ cfe/trunk/test/CoverageMapping/macros.c
@@ -36,8 +36,20 @@
 // CHECK-NEXT: File 1, 4:17 -> 4:22 = #0
 // CHECK-NEXT: File 2, 4:17 -> 4:22 = #0
 
+// CHECK-NEXT: func4
+void func4() { // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+6]]:2 = #0
+  int i = 0;
+  while (i++ < 10) // CHECK-NEXT: File 0, [[@LINE]]:10 -> [[@LINE]]:18 = (#0 + #1)
+if (i < 5) // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE+2]]:14 = #1
+   // CHECK-NEXT: File 0, [[@LINE-1]]:9 -> [[@LINE-1]]:14 = #1
+  MACRO_2; // CHECK-NEXT: Expansion,File 0, [[@LINE]]:7 -> [[@LINE]]:14 = #2
+}
+// CHECK-NEXT: File 1, 4:17 -> 4:22 = #2
+// CHECK-NOT: File 1
+
 int main(int argc, const char *argv[]) {
   func();
   func2();
   func3();
+  func4();
 }
Index: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
===
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
@@ -432,7 +432,8 @@
   SourceLocation NestedLoc = getStartOfFileOrMacro(EndLoc);
   assert(SM.isWrittenInSameFile(NestedLoc, EndLoc));
 
-  SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc);
+  if (!isRegionAlreadyAdded(NestedLoc, EndLoc))
+SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc);
 
   EndLoc = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(EndLoc));
   if (EndLoc.isInvalid())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23987: [Coverage] Suppress creating a code region if the same area is covered by an expansion region.

2016-08-29 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

This patch fixes the following issue:

  $ cat > test.cpp << EOF
  void dummy() {}
  
  #define MACRO_1 dummy()
  
  #define MACRO_2 MACRO_1
  
  int main() {
int i = 0;
if (i > 5)
  MACRO_2;
  }
  EOF
  $ clang++ -fprofile-instr-generate -fcoverage-mapping dummy.cpp test.cpp
  $ ./a.out
  $ llvm-profdata merge -o default.profdata default.profraw
  $ llvm-cov show a.out -instr-profile --show-expansions default.profdata
  1|  0|void dummy() {}
  2|   |
  3|  0|#define MACRO_1 dummy()
  4|   |
  5|  1|#define MACRO_2 MACRO_1
  6|   |
  7|  1|int main() {
  8|  1|  int i = 0;
  9|  1|  if (i > 5)
 10|  1|MACRO_2;
--
|  |5|  1|#define MACRO_2 MACRO_1
|  |  --
|  |  |  |3|  0|#define MACRO_1 dummy()
|  |  --
--
 11|  1|}

The result of the fixed version:

1|  0|void dummy() {}
2|   |
3|  0|#define MACRO_1 dummy()
4|   |
5|  0|#define MACRO_2 MACRO_1
6|   |
7|  1|int main() {
8|  1|  int i = 0;
9|  1|  if (i > 5)
   10|  0|MACRO_2;
  --
  |  |5|  0|#define MACRO_2 MACRO_1
  |  |  --
  |  |  |  |3|  0|#define MACRO_1 dummy()
  |  |  --
  --
   11|  1|}


https://reviews.llvm.org/D23987



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


Re: [PATCH] D23160: [Coverage] Prevent creating a redundant counter if a nested body ends with a macro.

2016-08-29 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

I figured out that the last issue is an independent one, so I prepared a 
separate fix for it: https://reviews.llvm.org/D23987.


https://reviews.llvm.org/D23160



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


Re: [PATCH] D17815: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-08-10 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

Hi,

Ping.

The issue in the current implementation of the libc++abi library looks like a 
time bomb. Even though its probability could be considered as very low, in 
fact, it depends on the type of an application. At least, we ran into it in our 
environment.

I'd guess that no one would expect their program to terminate when a legal 
exception is thrown, or when memory is allocated. I'd like this issue to be 
fixed in one or another way.

@EricWF, can you look at the patch again, please?


https://reviews.llvm.org/D17815



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


Re: [PATCH] D23160: [Coverage] Prevent creating a redundant counter if a nested body ends with a macro.

2016-08-05 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

I've reduced the last sample to the following:

  0|1|void dummy() {}
   |2|
  0|3|#define MACRO_1 dummy()
   |4|
  1|5|#define MACRO_2 MACRO_1
   |6|
  1|7|int main() {
  1|8|  int i = 0;
  1|9|  if (i > 5)
  1|   10|MACRO_2;
  --
  |  |  1|5|#define MACRO_2 MACRO_1
  |  |  --
  |  |  |  |  0|3|#define MACRO_1 dummy()
  |  |  --
  --
  1|   11|  return 0;
  1|   12|}

Right now, I don't have a good idea how to fix this.


https://reviews.llvm.org/D23160



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


Re: [PATCH] D23160: [Coverage] Prevent creating a redundant counter if a nested body ends with a macro.

2016-08-04 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

In https://reviews.llvm.org/D23160#506061, @vsk wrote:

> I guess it never makes sense to have two regions with the exact same 
> start/end loc, and different counters. Do you think we should add assertions 
> in llvm (either in llvm-cov, or in the coverage reader) which guard against 
> this?


Right now we can have several ranges with the same start and end locations in 
case of macro fully expanded into another macro. We consider this situation 
possible and handle it in class `SegmentBuilder` in 
llvm/lib/ProfileData/Coverage/CoverageMapping.cpp. Maybe something has to be 
fixed here too.

By the way, thinking about your words, I found another example which results in 
spawning not only redundant but also wrong counters. I'm postponing landing 
this patch until I finish the investigation.

  4|1|void dummy() {}
   |2|
  4|3|#define M_INT dummy()
   |4|
 11|5|#define MACRO M_INT
   |6|
   |7|int main()
  1|8|{
  1|9|  int i = 0;
 11|   10|  while (i++ < 10)
 10|   11|if (i < 5)
 10|   12|  MACRO;
  --
  |  | 11|5|#define MACRO M_INT
  |  |  --
  |  |  |  |  4|3|#define M_INT dummy()
  |  |  --
  --
  1|   13|  return 0;
  1|   14|}


https://reviews.llvm.org/D23160



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


Re: [PATCH] D23160: [Coverage] Prevent creating a redundant counter if a nested body ends with a macro.

2016-08-04 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

The motivation sample:

  $ cat > test.cpp << EOF
  void dummy() {}
  
  #define MACRO dummy()
  
  int main()
  {
int i = 0;
while (i++ < 10)
  if (i < 5)
MACRO;
return 0;
  }
  EOF
  $ clang++ -fprofile-instr-generate -fcoverage-mapping dummy.cpp test.cpp
  $ ./a.out
  $ llvm-profdata merge -o default.profdata default.profraw
  $ llvm-cov show a.out -instr-profile --show-expansions default.profdata
  test.cpp:
4|1|void dummy() {}
 |2|
   14|3|#define MACRO dummy()
 |4|
 |5|int main()
1|6|{
1|7|  int i = 0;
   11|8|  while (i++ < 10)
   10|9|if (i < 5)
4|   10|  MACRO;
--
|  | 14|3|#define MACRO dummy()
--
1|   11|  return 0;
1|   12|}

After applying this patch the counter for MACRO shows a reasonable value:

  $ llvm-cov show a.out -instr-profile --show-expansions default.profdata
  test.cpp:
4|1|void dummy() {}
 |2|
4|3|#define MACRO dummy()
 |4|
 |5|int main()
1|6|{
1|7|  int i = 0;
   11|8|  while (i++ < 10)
   10|9|if (i < 5)
4|   10|  MACRO;
--
|  |  4|3|#define MACRO dummy()
--
1|   11|  return 0;
1|   12|}


https://reviews.llvm.org/D23160



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


[PATCH] D23160: [Coverage] Prevent creating a redundant counter if a nested body ends with a macro.

2016-08-04 Thread Igor Kudrin via cfe-commits
ikudrin created this revision.
ikudrin added reviewers: vsk, davidxl, bogner.
ikudrin added a subscriber: cfe-commits.

If there were several nested statements arranged in a way that all of them end 
up with the same macro,
then the expansion of this macro was assigned with all the corresponding 
counters of these statements.
As a result, the wrong counter value was shown for the macro in llvm-cov.

This patch fixes the issue by preventing adding a counter for an expanded 
source range
if it already has an assigned counter, which is expected to come from the most 
specific statement.

https://reviews.llvm.org/D23160

Files:
  lib/CodeGen/CoverageMappingGen.cpp
  test/CoverageMapping/macros.c

Index: test/CoverageMapping/macros.c
===
--- test/CoverageMapping/macros.c
+++ test/CoverageMapping/macros.c
@@ -36,8 +36,20 @@
 // CHECK-NEXT: File 1, 4:17 -> 4:22 = #0
 // CHECK-NEXT: File 2, 4:17 -> 4:22 = #0
 
+// CHECK-NEXT: func4
+void func4() { // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+6]]:2 = #0
+  int i = 0;
+  while (i++ < 10) // CHECK-NEXT: File 0, [[@LINE]]:10 -> [[@LINE]]:18 = (#0 + 
#1)
+if (i < 5) // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE+2]]:14 = #1
+   // CHECK-NEXT: File 0, [[@LINE-1]]:9 -> [[@LINE-1]]:14 = #1
+  MACRO_2; // CHECK-NEXT: Expansion,File 0, [[@LINE]]:7 -> [[@LINE]]:14 = 
#2
+}
+// CHECK-NEXT: File 1, 4:17 -> 4:22 = #2
+// CHECK-NOT: File 1
+
 int main(int argc, const char *argv[]) {
   func();
   func2();
   func3();
+  func4();
 }
Index: lib/CodeGen/CoverageMappingGen.cpp
===
--- lib/CodeGen/CoverageMappingGen.cpp
+++ lib/CodeGen/CoverageMappingGen.cpp
@@ -432,7 +432,8 @@
   SourceLocation NestedLoc = getStartOfFileOrMacro(EndLoc);
   assert(SM.isWrittenInSameFile(NestedLoc, EndLoc));
 
-  SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc);
+  if (!isRegionAlreadyAdded(NestedLoc, EndLoc))
+SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc);
 
   EndLoc = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(EndLoc));
   if (EndLoc.isInvalid())


Index: test/CoverageMapping/macros.c
===
--- test/CoverageMapping/macros.c
+++ test/CoverageMapping/macros.c
@@ -36,8 +36,20 @@
 // CHECK-NEXT: File 1, 4:17 -> 4:22 = #0
 // CHECK-NEXT: File 2, 4:17 -> 4:22 = #0
 
+// CHECK-NEXT: func4
+void func4() { // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+6]]:2 = #0
+  int i = 0;
+  while (i++ < 10) // CHECK-NEXT: File 0, [[@LINE]]:10 -> [[@LINE]]:18 = (#0 + #1)
+if (i < 5) // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE+2]]:14 = #1
+   // CHECK-NEXT: File 0, [[@LINE-1]]:9 -> [[@LINE-1]]:14 = #1
+  MACRO_2; // CHECK-NEXT: Expansion,File 0, [[@LINE]]:7 -> [[@LINE]]:14 = #2
+}
+// CHECK-NEXT: File 1, 4:17 -> 4:22 = #2
+// CHECK-NOT: File 1
+
 int main(int argc, const char *argv[]) {
   func();
   func2();
   func3();
+  func4();
 }
Index: lib/CodeGen/CoverageMappingGen.cpp
===
--- lib/CodeGen/CoverageMappingGen.cpp
+++ lib/CodeGen/CoverageMappingGen.cpp
@@ -432,7 +432,8 @@
   SourceLocation NestedLoc = getStartOfFileOrMacro(EndLoc);
   assert(SM.isWrittenInSameFile(NestedLoc, EndLoc));
 
-  SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc);
+  if (!isRegionAlreadyAdded(NestedLoc, EndLoc))
+SourceRegions.emplace_back(Region.getCounter(), NestedLoc, EndLoc);
 
   EndLoc = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(EndLoc));
   if (EndLoc.isInvalid())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D17815: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-06-23 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

Ping...

This patch is under review for more than two months, and I believe I've 
addressed all the comments. Could someone take a look at it, please?


http://reviews.llvm.org/D17815



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


Re: [PATCH] D17815: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-06-13 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

Ping.


http://reviews.llvm.org/D17815



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


r271995 - Reapply [Coverage] Fix an assertion failure if the definition of an unused function spans multiple files.

2016-06-07 Thread Igor Kudrin via cfe-commits
Author: ikudrin
Date: Tue Jun  7 05:07:51 2016
New Revision: 271995

URL: http://llvm.org/viewvc/llvm-project?rev=271995=rev
Log:
Reapply [Coverage] Fix an assertion failure if the definition of an unused 
function spans multiple files.

We have an assertion failure if, for example, the definition of an unused
inline function starts in one macro and ends in another. This patch fixes
the issue by finding the common ancestor of the start and end locations
of that function's body and changing the locations accordingly.

Thanks to NAKAMURA Takumi for helping with fixing the test failure on Windows.

Differential Revision: http://reviews.llvm.org/D20997

Added:
cfe/trunk/test/CoverageMapping/Inputs/ends_a_scope_only
cfe/trunk/test/CoverageMapping/Inputs/starts_a_scope_only
cfe/trunk/test/CoverageMapping/unused_function.cpp
Modified:
cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp

Modified: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp?rev=271995=271994=271995=diff
==
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp (original)
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp Tue Jun  7 05:07:51 2016
@@ -130,6 +130,16 @@ public:
 return strcmp(SM.getBufferName(SM.getSpellingLoc(Loc)), "") == 0;
   }
 
+  /// \brief Check whether \c Loc is included or expanded from \c Parent.
+  bool isNestedIn(SourceLocation Loc, FileID Parent) {
+do {
+  Loc = getIncludeOrExpansionLoc(Loc);
+  if (Loc.isInvalid())
+return false;
+} while (!SM.isInFileID(Loc, Parent));
+return true;
+  }
+
   /// \brief Get the start of \c S ignoring macro arguments and builtin macros.
   SourceLocation getStart(const Stmt *S) {
 SourceLocation Loc = S->getLocStart();
@@ -310,7 +320,27 @@ struct EmptyCoverageMappingBuilder : pub
 if (!D->hasBody())
   return;
 auto Body = D->getBody();
-SourceRegions.emplace_back(Counter(), getStart(Body), getEnd(Body));
+SourceLocation Start = getStart(Body);
+SourceLocation End = getEnd(Body);
+if (!SM.isWrittenInSameFile(Start, End)) {
+  // Walk up to find the common ancestor.
+  // Correct the locations accordingly.
+  FileID StartFileID = SM.getFileID(Start);
+  FileID EndFileID = SM.getFileID(End);
+  while (StartFileID != EndFileID && !isNestedIn(End, StartFileID)) {
+Start = getIncludeOrExpansionLoc(Start);
+assert(Start.isValid() &&
+   "Declaration start location not nested within a known region");
+StartFileID = SM.getFileID(Start);
+  }
+  while (StartFileID != EndFileID) {
+End = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(End));
+assert(End.isValid() &&
+   "Declaration end location not nested within a known region");
+EndFileID = SM.getFileID(End);
+  }
+}
+SourceRegions.emplace_back(Counter(), Start, End);
   }
 
   /// \brief Write the mapping data to the output stream
@@ -471,16 +501,6 @@ struct CounterCoverageMappingBuilder
   MostRecentLocation = getIncludeOrExpansionLoc(MostRecentLocation);
   }
 
-  /// \brief Check whether \c Loc is included or expanded from \c Parent.
-  bool isNestedIn(SourceLocation Loc, FileID Parent) {
-do {
-  Loc = getIncludeOrExpansionLoc(Loc);
-  if (Loc.isInvalid())
-return false;
-} while (!SM.isInFileID(Loc, Parent));
-return true;
-  }
-
   /// \brief Adjust regions and state when \c NewLoc exits a file.
   ///
   /// If moving from our most recently tracked location to \c NewLoc exits any

Added: cfe/trunk/test/CoverageMapping/Inputs/ends_a_scope_only
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/Inputs/ends_a_scope_only?rev=271995=auto
==
--- cfe/trunk/test/CoverageMapping/Inputs/ends_a_scope_only (added)
+++ cfe/trunk/test/CoverageMapping/Inputs/ends_a_scope_only Tue Jun  7 05:07:51 
2016
@@ -0,0 +1 @@
+}

Added: cfe/trunk/test/CoverageMapping/Inputs/starts_a_scope_only
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/Inputs/starts_a_scope_only?rev=271995=auto
==
--- cfe/trunk/test/CoverageMapping/Inputs/starts_a_scope_only (added)
+++ cfe/trunk/test/CoverageMapping/Inputs/starts_a_scope_only Tue Jun  7 
05:07:51 2016
@@ -0,0 +1 @@
+{

Added: cfe/trunk/test/CoverageMapping/unused_function.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/unused_function.cpp?rev=271995=auto
==
--- cfe/trunk/test/CoverageMapping/unused_function.cpp (added)
+++ cfe/trunk/test/CoverageMapping/unused_function.cpp Tue Jun  7 05:07:51 2016
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 

r271976 - Revert [Coverage] Fix an assertion failure if the definition of an unused function spans multiple files.

2016-06-06 Thread Igor Kudrin via cfe-commits
Author: ikudrin
Date: Mon Jun  6 23:11:51 2016
New Revision: 271976

URL: http://llvm.org/viewvc/llvm-project?rev=271976=rev
Log:
Revert [Coverage] Fix an assertion failure if the definition of an unused 
function spans multiple files.

r271969 The test case fails on Windows.

Removed:
cfe/trunk/test/CoverageMapping/Inputs/ends_a_scope_only
cfe/trunk/test/CoverageMapping/Inputs/starts_a_scope_only
cfe/trunk/test/CoverageMapping/unused_function.cpp
Modified:
cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp

Modified: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp?rev=271976=271975=271976=diff
==
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp (original)
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp Mon Jun  6 23:11:51 2016
@@ -130,16 +130,6 @@ public:
 return strcmp(SM.getBufferName(SM.getSpellingLoc(Loc)), "") == 0;
   }
 
-  /// \brief Check whether \c Loc is included or expanded from \c Parent.
-  bool isNestedIn(SourceLocation Loc, FileID Parent) {
-do {
-  Loc = getIncludeOrExpansionLoc(Loc);
-  if (Loc.isInvalid())
-return false;
-} while (!SM.isInFileID(Loc, Parent));
-return true;
-  }
-
   /// \brief Get the start of \c S ignoring macro arguments and builtin macros.
   SourceLocation getStart(const Stmt *S) {
 SourceLocation Loc = S->getLocStart();
@@ -320,27 +310,7 @@ struct EmptyCoverageMappingBuilder : pub
 if (!D->hasBody())
   return;
 auto Body = D->getBody();
-SourceLocation Start = getStart(Body);
-SourceLocation End = getEnd(Body);
-if (!SM.isWrittenInSameFile(Start, End)) {
-  // Walk up to find the common ancestor.
-  // Correct the locations accordingly.
-  FileID StartFileID = SM.getFileID(Start);
-  FileID EndFileID = SM.getFileID(End);
-  while (StartFileID != EndFileID && !isNestedIn(End, StartFileID)) {
-Start = getIncludeOrExpansionLoc(Start);
-assert(Start.isValid() &&
-   "Declaration start location not nested within a known region");
-StartFileID = SM.getFileID(Start);
-  }
-  while (StartFileID != EndFileID) {
-End = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(End));
-assert(End.isValid() &&
-   "Declaration end location not nested within a known region");
-EndFileID = SM.getFileID(End);
-  }
-}
-SourceRegions.emplace_back(Counter(), Start, End);
+SourceRegions.emplace_back(Counter(), getStart(Body), getEnd(Body));
   }
 
   /// \brief Write the mapping data to the output stream
@@ -501,6 +471,16 @@ struct CounterCoverageMappingBuilder
   MostRecentLocation = getIncludeOrExpansionLoc(MostRecentLocation);
   }
 
+  /// \brief Check whether \c Loc is included or expanded from \c Parent.
+  bool isNestedIn(SourceLocation Loc, FileID Parent) {
+do {
+  Loc = getIncludeOrExpansionLoc(Loc);
+  if (Loc.isInvalid())
+return false;
+} while (!SM.isInFileID(Loc, Parent));
+return true;
+  }
+
   /// \brief Adjust regions and state when \c NewLoc exits a file.
   ///
   /// If moving from our most recently tracked location to \c NewLoc exits any

Removed: cfe/trunk/test/CoverageMapping/Inputs/ends_a_scope_only
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/Inputs/ends_a_scope_only?rev=271975=auto
==
--- cfe/trunk/test/CoverageMapping/Inputs/ends_a_scope_only (original)
+++ cfe/trunk/test/CoverageMapping/Inputs/ends_a_scope_only (removed)
@@ -1 +0,0 @@
-}

Removed: cfe/trunk/test/CoverageMapping/Inputs/starts_a_scope_only
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/Inputs/starts_a_scope_only?rev=271975=auto
==
--- cfe/trunk/test/CoverageMapping/Inputs/starts_a_scope_only (original)
+++ cfe/trunk/test/CoverageMapping/Inputs/starts_a_scope_only (removed)
@@ -1 +0,0 @@
-{

Removed: cfe/trunk/test/CoverageMapping/unused_function.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/unused_function.cpp?rev=271975=auto
==
--- cfe/trunk/test/CoverageMapping/unused_function.cpp (original)
+++ cfe/trunk/test/CoverageMapping/unused_function.cpp (removed)
@@ -1,37 +0,0 @@
-// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping -emit-llvm-only %s | FileCheck %s
-
-#define START_SCOPE {
-#define END_SCOPE }
-
-// CHECK: _Z2f0v:
-// CHECK-NEXT: File 0, [[@LINE+1]]:18 -> [[@LINE+1]]:20 = 0
-inline void f0() {}
-
-// CHECK: _Z2f1v:
-// CHECK-NEXT: File 0, [[@LINE+1]]:18 -> [[@LINE+1]]:31 = 0
-inline void f1() START_SCOPE }
-
-// CHECK: _Z2f2v:
-// CHECK-NEXT: File 0, [[@LINE+1]]:18 -> 

Re: [PATCH] D20997: [Coverage] Fix an assertion failure if the definition of an unused function spans multiple files.

2016-06-06 Thread Igor Kudrin via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL271969: [Coverage] Fix an assertion failure if the 
definition of an unused function… (authored by ikudrin).

Changed prior to commit:
  http://reviews.llvm.org/D20997?vs=59806=59818#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D20997

Files:
  cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
  cfe/trunk/test/CoverageMapping/Inputs/ends_a_scope_only
  cfe/trunk/test/CoverageMapping/Inputs/starts_a_scope_only
  cfe/trunk/test/CoverageMapping/unused_function.cpp

Index: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
===
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
@@ -130,6 +130,16 @@
 return strcmp(SM.getBufferName(SM.getSpellingLoc(Loc)), "") == 0;
   }
 
+  /// \brief Check whether \c Loc is included or expanded from \c Parent.
+  bool isNestedIn(SourceLocation Loc, FileID Parent) {
+do {
+  Loc = getIncludeOrExpansionLoc(Loc);
+  if (Loc.isInvalid())
+return false;
+} while (!SM.isInFileID(Loc, Parent));
+return true;
+  }
+
   /// \brief Get the start of \c S ignoring macro arguments and builtin macros.
   SourceLocation getStart(const Stmt *S) {
 SourceLocation Loc = S->getLocStart();
@@ -310,7 +320,27 @@
 if (!D->hasBody())
   return;
 auto Body = D->getBody();
-SourceRegions.emplace_back(Counter(), getStart(Body), getEnd(Body));
+SourceLocation Start = getStart(Body);
+SourceLocation End = getEnd(Body);
+if (!SM.isWrittenInSameFile(Start, End)) {
+  // Walk up to find the common ancestor.
+  // Correct the locations accordingly.
+  FileID StartFileID = SM.getFileID(Start);
+  FileID EndFileID = SM.getFileID(End);
+  while (StartFileID != EndFileID && !isNestedIn(End, StartFileID)) {
+Start = getIncludeOrExpansionLoc(Start);
+assert(Start.isValid() &&
+   "Declaration start location not nested within a known region");
+StartFileID = SM.getFileID(Start);
+  }
+  while (StartFileID != EndFileID) {
+End = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(End));
+assert(End.isValid() &&
+   "Declaration end location not nested within a known region");
+EndFileID = SM.getFileID(End);
+  }
+}
+SourceRegions.emplace_back(Counter(), Start, End);
   }
 
   /// \brief Write the mapping data to the output stream
@@ -471,16 +501,6 @@
   MostRecentLocation = getIncludeOrExpansionLoc(MostRecentLocation);
   }
 
-  /// \brief Check whether \c Loc is included or expanded from \c Parent.
-  bool isNestedIn(SourceLocation Loc, FileID Parent) {
-do {
-  Loc = getIncludeOrExpansionLoc(Loc);
-  if (Loc.isInvalid())
-return false;
-} while (!SM.isInFileID(Loc, Parent));
-return true;
-  }
-
   /// \brief Adjust regions and state when \c NewLoc exits a file.
   ///
   /// If moving from our most recently tracked location to \c NewLoc exits any
Index: cfe/trunk/test/CoverageMapping/Inputs/ends_a_scope_only
===
--- cfe/trunk/test/CoverageMapping/Inputs/ends_a_scope_only
+++ cfe/trunk/test/CoverageMapping/Inputs/ends_a_scope_only
@@ -0,0 +1 @@
+}
Index: cfe/trunk/test/CoverageMapping/Inputs/starts_a_scope_only
===
--- cfe/trunk/test/CoverageMapping/Inputs/starts_a_scope_only
+++ cfe/trunk/test/CoverageMapping/Inputs/starts_a_scope_only
@@ -0,0 +1 @@
+{
Index: cfe/trunk/test/CoverageMapping/unused_function.cpp
===
--- cfe/trunk/test/CoverageMapping/unused_function.cpp
+++ cfe/trunk/test/CoverageMapping/unused_function.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only %s | FileCheck %s
+
+#define START_SCOPE {
+#define END_SCOPE }
+
+// CHECK: _Z2f0v:
+// CHECK-NEXT: File 0, [[@LINE+1]]:18 -> [[@LINE+1]]:20 = 0
+inline void f0() {}
+
+// CHECK: _Z2f1v:
+// CHECK-NEXT: File 0, [[@LINE+1]]:18 -> [[@LINE+1]]:31 = 0
+inline void f1() START_SCOPE }
+
+// CHECK: _Z2f2v:
+// CHECK-NEXT: File 0, [[@LINE+1]]:18 -> [[@LINE+1]]:29 = 0
+inline void f2() { END_SCOPE
+
+// CHECK: _Z2f3v:
+// CHECK-NEXT: File 0, [[@LINE+1]]:18 -> [[@LINE+1]]:39 = 0
+inline void f3() START_SCOPE END_SCOPE
+
+// CHECK: _Z2f4v:
+// CHECK-NEXT: File 0, [[@LINE+2]]:10 -> [[@LINE+3]]:2 = 0
+inline void f4()
+#include "Inputs/starts_a_scope_only"
+}
+
+// CHECK: _Z2f5v:
+// CHECK-NEXT: File 0, [[@LINE+1]]:18 -> [[@LINE+2]]:36 = 0
+inline void f5() {
+#include "Inputs/ends_a_scope_only"
+
+// CHECK: _Z2f6v:
+// CHECK-NEXT: File 0, [[@LINE+2]]:10 -> [[@LINE+3]]:36 = 0
+inline void f6()
+#include "Inputs/starts_a_scope_only"
+#include "Inputs/ends_a_scope_only"

r271969 - [Coverage] Fix an assertion failure if the definition of an unused function spans multiple files.

2016-06-06 Thread Igor Kudrin via cfe-commits
Author: ikudrin
Date: Mon Jun  6 21:17:03 2016
New Revision: 271969

URL: http://llvm.org/viewvc/llvm-project?rev=271969=rev
Log:
[Coverage] Fix an assertion failure if the definition of an unused function 
spans multiple files.

We have an assertion failure if, for example, the definition of an unused
inline function starts in one macro and ends in another. This patch fixes
the issue by finding the common ancestor of the start and end locations
of that function's body and changing the locations accordingly.

Differential Revision: http://reviews.llvm.org/D20997

Added:
cfe/trunk/test/CoverageMapping/Inputs/ends_a_scope_only
cfe/trunk/test/CoverageMapping/Inputs/starts_a_scope_only
cfe/trunk/test/CoverageMapping/unused_function.cpp
Modified:
cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp

Modified: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp?rev=271969=271968=271969=diff
==
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp (original)
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp Mon Jun  6 21:17:03 2016
@@ -130,6 +130,16 @@ public:
 return strcmp(SM.getBufferName(SM.getSpellingLoc(Loc)), "") == 0;
   }
 
+  /// \brief Check whether \c Loc is included or expanded from \c Parent.
+  bool isNestedIn(SourceLocation Loc, FileID Parent) {
+do {
+  Loc = getIncludeOrExpansionLoc(Loc);
+  if (Loc.isInvalid())
+return false;
+} while (!SM.isInFileID(Loc, Parent));
+return true;
+  }
+
   /// \brief Get the start of \c S ignoring macro arguments and builtin macros.
   SourceLocation getStart(const Stmt *S) {
 SourceLocation Loc = S->getLocStart();
@@ -310,7 +320,27 @@ struct EmptyCoverageMappingBuilder : pub
 if (!D->hasBody())
   return;
 auto Body = D->getBody();
-SourceRegions.emplace_back(Counter(), getStart(Body), getEnd(Body));
+SourceLocation Start = getStart(Body);
+SourceLocation End = getEnd(Body);
+if (!SM.isWrittenInSameFile(Start, End)) {
+  // Walk up to find the common ancestor.
+  // Correct the locations accordingly.
+  FileID StartFileID = SM.getFileID(Start);
+  FileID EndFileID = SM.getFileID(End);
+  while (StartFileID != EndFileID && !isNestedIn(End, StartFileID)) {
+Start = getIncludeOrExpansionLoc(Start);
+assert(Start.isValid() &&
+   "Declaration start location not nested within a known region");
+StartFileID = SM.getFileID(Start);
+  }
+  while (StartFileID != EndFileID) {
+End = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(End));
+assert(End.isValid() &&
+   "Declaration end location not nested within a known region");
+EndFileID = SM.getFileID(End);
+  }
+}
+SourceRegions.emplace_back(Counter(), Start, End);
   }
 
   /// \brief Write the mapping data to the output stream
@@ -471,16 +501,6 @@ struct CounterCoverageMappingBuilder
   MostRecentLocation = getIncludeOrExpansionLoc(MostRecentLocation);
   }
 
-  /// \brief Check whether \c Loc is included or expanded from \c Parent.
-  bool isNestedIn(SourceLocation Loc, FileID Parent) {
-do {
-  Loc = getIncludeOrExpansionLoc(Loc);
-  if (Loc.isInvalid())
-return false;
-} while (!SM.isInFileID(Loc, Parent));
-return true;
-  }
-
   /// \brief Adjust regions and state when \c NewLoc exits a file.
   ///
   /// If moving from our most recently tracked location to \c NewLoc exits any

Added: cfe/trunk/test/CoverageMapping/Inputs/ends_a_scope_only
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/Inputs/ends_a_scope_only?rev=271969=auto
==
--- cfe/trunk/test/CoverageMapping/Inputs/ends_a_scope_only (added)
+++ cfe/trunk/test/CoverageMapping/Inputs/ends_a_scope_only Mon Jun  6 21:17:03 
2016
@@ -0,0 +1 @@
+}

Added: cfe/trunk/test/CoverageMapping/Inputs/starts_a_scope_only
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/Inputs/starts_a_scope_only?rev=271969=auto
==
--- cfe/trunk/test/CoverageMapping/Inputs/starts_a_scope_only (added)
+++ cfe/trunk/test/CoverageMapping/Inputs/starts_a_scope_only Mon Jun  6 
21:17:03 2016
@@ -0,0 +1 @@
+{

Added: cfe/trunk/test/CoverageMapping/unused_function.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/unused_function.cpp?rev=271969=auto
==
--- cfe/trunk/test/CoverageMapping/unused_function.cpp (added)
+++ cfe/trunk/test/CoverageMapping/unused_function.cpp Mon Jun  6 21:17:03 2016
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping 
-dump-coverage-mapping -emit-llvm-only %s | FileCheck %s
+

Re: [PATCH] D20878: [Coverage] Do not push a new region after a CXXTryStmt

2016-06-06 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

I agree that it'd be expensive to put a new counter after each function call. 
Even if there is no `throw` statement within a TU, called functions still may 
raise exceptions.
Anyway, if we come across a `try` statement, we can guess that some exceptions 
are expected and do our best to support constructions like this:

  try {
...
  }
  catch (...) {
...
throw;
  }


http://reviews.llvm.org/D20878



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


Re: [PATCH] D20997: [Coverage] Fix an assertion failure if the definition of an unused function spans multiple files.

2016-06-06 Thread Igor Kudrin via cfe-commits
ikudrin updated the summary for this revision.
ikudrin removed rL LLVM as the repository for this revision.
ikudrin updated this revision to Diff 59806.
ikudrin added a comment.

- Use `StartFileID` and `EndFileID` variables to eliminate redundant calls to 
`SM.getFileID()`.
- Add comment strings to asserts.


http://reviews.llvm.org/D20997

Files:
  lib/CodeGen/CoverageMappingGen.cpp
  test/CoverageMapping/Inputs/ends_a_scope_only
  test/CoverageMapping/Inputs/starts_a_scope_only
  test/CoverageMapping/unused_function.cpp

Index: test/CoverageMapping/unused_function.cpp
===
--- /dev/null
+++ test/CoverageMapping/unused_function.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only %s | tee %t.out | FileCheck %s
+
+#define START_SCOPE {
+#define END_SCOPE }
+
+// CHECK: _Z2f0v:
+// CHECK-NEXT: File 0, [[@LINE+1]]:18 -> [[@LINE+1]]:20 = 0
+inline void f0() {}
+
+// CHECK: _Z2f1v:
+// CHECK-NEXT: File 0, [[@LINE+1]]:18 -> [[@LINE+1]]:31 = 0
+inline void f1() START_SCOPE }
+
+// CHECK: _Z2f2v:
+// CHECK-NEXT: File 0, [[@LINE+1]]:18 -> [[@LINE+1]]:29 = 0
+inline void f2() { END_SCOPE
+
+// CHECK: _Z2f3v:
+// CHECK-NEXT: File 0, [[@LINE+1]]:18 -> [[@LINE+1]]:39 = 0
+inline void f3() START_SCOPE END_SCOPE
+
+// CHECK: _Z2f4v:
+// CHECK-NEXT: File 0, [[@LINE+2]]:10 -> [[@LINE+3]]:2 = 0
+inline void f4()
+#include "Inputs/starts_a_scope_only"
+}
+
+// CHECK: _Z2f5v:
+// CHECK-NEXT: File 0, [[@LINE+1]]:18 -> [[@LINE+2]]:36 = 0
+inline void f5() {
+#include "Inputs/ends_a_scope_only"
+
+// CHECK: _Z2f6v:
+// CHECK-NEXT: File 0, [[@LINE+2]]:10 -> [[@LINE+3]]:36 = 0
+inline void f6()
+#include "Inputs/starts_a_scope_only"
+#include "Inputs/ends_a_scope_only"
Index: test/CoverageMapping/Inputs/starts_a_scope_only
===
--- /dev/null
+++ test/CoverageMapping/Inputs/starts_a_scope_only
@@ -0,0 +1 @@
+{
Index: test/CoverageMapping/Inputs/ends_a_scope_only
===
--- /dev/null
+++ test/CoverageMapping/Inputs/ends_a_scope_only
@@ -0,0 +1 @@
+}
Index: lib/CodeGen/CoverageMappingGen.cpp
===
--- lib/CodeGen/CoverageMappingGen.cpp
+++ lib/CodeGen/CoverageMappingGen.cpp
@@ -130,6 +130,16 @@
 return strcmp(SM.getBufferName(SM.getSpellingLoc(Loc)), "") == 0;
   }
 
+  /// \brief Check whether \c Loc is included or expanded from \c Parent.
+  bool isNestedIn(SourceLocation Loc, FileID Parent) {
+do {
+  Loc = getIncludeOrExpansionLoc(Loc);
+  if (Loc.isInvalid())
+return false;
+} while (!SM.isInFileID(Loc, Parent));
+return true;
+  }
+
   /// \brief Get the start of \c S ignoring macro arguments and builtin macros.
   SourceLocation getStart(const Stmt *S) {
 SourceLocation Loc = S->getLocStart();
@@ -310,7 +320,27 @@
 if (!D->hasBody())
   return;
 auto Body = D->getBody();
-SourceRegions.emplace_back(Counter(), getStart(Body), getEnd(Body));
+SourceLocation Start = getStart(Body);
+SourceLocation End = getEnd(Body);
+if (!SM.isWrittenInSameFile(Start, End)) {
+  // Walk up to find the common ancestor.
+  // Correct the locations accordingly.
+  FileID StartFileID = SM.getFileID(Start);
+  FileID EndFileID = SM.getFileID(End);
+  while (StartFileID != EndFileID && !isNestedIn(End, StartFileID)) {
+Start = getIncludeOrExpansionLoc(Start);
+assert(Start.isValid() &&
+   "Declaration start location not nested within a known region");
+StartFileID = SM.getFileID(Start);
+  }
+  while (StartFileID != EndFileID) {
+End = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(End));
+assert(End.isValid() &&
+   "Declaration end location not nested within a known region");
+EndFileID = SM.getFileID(End);
+  }
+}
+SourceRegions.emplace_back(Counter(), Start, End);
   }
 
   /// \brief Write the mapping data to the output stream
@@ -471,16 +501,6 @@
   MostRecentLocation = getIncludeOrExpansionLoc(MostRecentLocation);
   }
 
-  /// \brief Check whether \c Loc is included or expanded from \c Parent.
-  bool isNestedIn(SourceLocation Loc, FileID Parent) {
-do {
-  Loc = getIncludeOrExpansionLoc(Loc);
-  if (Loc.isInvalid())
-return false;
-} while (!SM.isInFileID(Loc, Parent));
-return true;
-  }
-
   /// \brief Adjust regions and state when \c NewLoc exits a file.
   ///
   /// If moving from our most recently tracked location to \c NewLoc exits any
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20997: [Coverage] Fix an assertion failure if the definition of an unused function spans multiple files.

2016-06-04 Thread Igor Kudrin via cfe-commits
ikudrin created this revision.
ikudrin added reviewers: vsk, bogner, davidxl.
ikudrin added a subscriber: cfe-commits.
ikudrin set the repository for this revision to rL LLVM.

We had an assertion failure if, for example, the definition of an unused inline 
function starts
in one macro and ends in another. This patch fixes the issue by finding the 
common ancestor
of the start and end locations of that function's body and changing the 
locations accordingly.

Repository:
  rL LLVM

http://reviews.llvm.org/D20997

Files:
  lib/CodeGen/CoverageMappingGen.cpp
  test/CoverageMapping/Inputs/ends_a_scope_only
  test/CoverageMapping/Inputs/starts_a_scope_only
  test/CoverageMapping/unused_function.cpp

Index: test/CoverageMapping/unused_function.cpp
===
--- /dev/null
+++ test/CoverageMapping/unused_function.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -fprofile-instrument=clang -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only %s | tee %t.out | FileCheck %s
+
+#define START_SCOPE {
+#define END_SCOPE }
+
+// CHECK: _Z2f0v:
+// CHECK-NEXT: File 0, [[@LINE+1]]:18 -> [[@LINE+1]]:20 = 0
+inline void f0() {}
+
+// CHECK: _Z2f1v:
+// CHECK-NEXT: File 0, [[@LINE+1]]:18 -> [[@LINE+1]]:31 = 0
+inline void f1() START_SCOPE }
+
+// CHECK: _Z2f2v:
+// CHECK-NEXT: File 0, [[@LINE+1]]:18 -> [[@LINE+1]]:29 = 0
+inline void f2() { END_SCOPE
+
+// CHECK: _Z2f3v:
+// CHECK-NEXT: File 0, [[@LINE+1]]:18 -> [[@LINE+1]]:39 = 0
+inline void f3() START_SCOPE END_SCOPE
+
+// CHECK: _Z2f4v:
+// CHECK-NEXT: File 0, [[@LINE+2]]:10 -> [[@LINE+3]]:2 = 0
+inline void f4()
+#include "Inputs/starts_a_scope_only"
+}
+
+// CHECK: _Z2f5v:
+// CHECK-NEXT: File 0, [[@LINE+1]]:18 -> [[@LINE+2]]:36 = 0
+inline void f5() {
+#include "Inputs/ends_a_scope_only"
+
+// CHECK: _Z2f6v:
+// CHECK-NEXT: File 0, [[@LINE+2]]:10 -> [[@LINE+3]]:36 = 0
+inline void f6()
+#include "Inputs/starts_a_scope_only"
+#include "Inputs/ends_a_scope_only"
Index: test/CoverageMapping/Inputs/starts_a_scope_only
===
--- /dev/null
+++ test/CoverageMapping/Inputs/starts_a_scope_only
@@ -0,0 +1 @@
+{
Index: test/CoverageMapping/Inputs/ends_a_scope_only
===
--- /dev/null
+++ test/CoverageMapping/Inputs/ends_a_scope_only
@@ -0,0 +1 @@
+}
Index: lib/CodeGen/CoverageMappingGen.cpp
===
--- lib/CodeGen/CoverageMappingGen.cpp
+++ lib/CodeGen/CoverageMappingGen.cpp
@@ -130,6 +130,16 @@
 return strcmp(SM.getBufferName(SM.getSpellingLoc(Loc)), "") == 0;
   }
 
+  /// \brief Check whether \c Loc is included or expanded from \c Parent.
+  bool isNestedIn(SourceLocation Loc, FileID Parent) {
+do {
+  Loc = getIncludeOrExpansionLoc(Loc);
+  if (Loc.isInvalid())
+return false;
+} while (!SM.isInFileID(Loc, Parent));
+return true;
+  }
+
   /// \brief Get the start of \c S ignoring macro arguments and builtin macros.
   SourceLocation getStart(const Stmt *S) {
 SourceLocation Loc = S->getLocStart();
@@ -310,7 +320,23 @@
 if (!D->hasBody())
   return;
 auto Body = D->getBody();
-SourceRegions.emplace_back(Counter(), getStart(Body), getEnd(Body));
+SourceLocation Start = getStart(Body);
+SourceLocation End = getEnd(Body);
+if (!SM.isWrittenInSameFile(Start, End)) {
+  // Walk up to find the common ancestor.
+  // Correct the locations accordingly.
+  FileID ParentFile = SM.getFileID(Start);
+  while (ParentFile != SM.getFileID(End) && !isNestedIn(End, ParentFile)) {
+Start = getIncludeOrExpansionLoc(Start);
+assert(Start.isValid());
+ParentFile = SM.getFileID(Start);
+  }
+  while (ParentFile != SM.getFileID(End)) {
+End = getPreciseTokenLocEnd(getIncludeOrExpansionLoc(End));
+assert(End.isValid());
+  }
+}
+SourceRegions.emplace_back(Counter(), Start, End);
   }
 
   /// \brief Write the mapping data to the output stream
@@ -471,16 +497,6 @@
   MostRecentLocation = getIncludeOrExpansionLoc(MostRecentLocation);
   }
 
-  /// \brief Check whether \c Loc is included or expanded from \c Parent.
-  bool isNestedIn(SourceLocation Loc, FileID Parent) {
-do {
-  Loc = getIncludeOrExpansionLoc(Loc);
-  if (Loc.isInvalid())
-return false;
-} while (!SM.isInFileID(Loc, Parent));
-return true;
-  }
-
   /// \brief Adjust regions and state when \c NewLoc exits a file.
   ///
   /// If moving from our most recently tracked location to \c NewLoc exits any
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D20878: [Coverage] Do not push a new region after a CXXTryStmt

2016-06-02 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

So, our tool isn't accurate in the case of throwing an exception. Is there a 
case where this patch makes things better than they were before? Is it possible 
to improve handling of exceptions instead?


http://reviews.llvm.org/D20878



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


Re: [PATCH] D20287: [Coverage] Ensure that the hash for a used function is non-zero.

2016-05-20 Thread Igor Kudrin via cfe-commits
ikudrin abandoned this revision.
ikudrin added a comment.

This change is not needed anymore because the whole issue was fixed in 
http://reviews.llvm.org/D20286.


http://reviews.llvm.org/D20287



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


Re: [PATCH] D20287: [Coverage] Ensure that the hash for a used function is non-zero.

2016-05-16 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

Does anyone known, why we need dummy coverage mapping records for unused 
functions? How are they used? Isn't it better to remove these dummy records to 
prevent confusion with the real ones?


http://reviews.llvm.org/D20287



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


Re: [PATCH] D20287: [Coverage] Ensure that the hash for a used function is non-zero.

2016-05-16 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

The motivation sample (using llvm-cov with http://reviews.llvm.org/D20286 
applied):

  $ cat > sample.h << EOF
  inline int sample_func(int A) {
return A;
  }
  EOF
  $ cat > dummy.cpp << EOF
  #include "sample.h"
  EOF
  $ cat > sample.cpp << EOF
  #include "sample.h"
  
  int main() {
return sample_func(5);
  }
  EOF
  $ clang++ -fprofile-instr-generate -fcoverage-mapping dummy.cpp sample.cpp
  $ ./a.out
  $ llvm-profdata merge -o default.profdata default.profraw
  $ llvm-cov show a.out -instr-profile default.profdata
  sample.h:
0|1|inline int sample_func(int A) {
0|2|  return A;
0|3|}
  
  sample.cpp:
 |1|#include "sample.h"
 |2|
1|3|int main() {
1|4|  return sample_func(5);
1|5|}

And if this patch is applied:

  $ clang++ -fprofile-instr-generate -fcoverage-mapping dummy.cpp sample.cpp
  $ ./a.out
  $ llvm-profdata merge -o default.profdata default.profraw
  $ llvm-cov show a.out -instr-profile default.profdata
  sample.h:
1|1|inline int sample_func(int A) {
1|2|  return A;
1|3|}
  
  sample.cpp:
 |1|#include "sample.h"
 |2|
1|3|int main() {
1|4|  return sample_func(5);
1|5|}


http://reviews.llvm.org/D20287



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


Re: [PATCH] D17815: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-05-16 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

Ping?..


http://reviews.llvm.org/D17815



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


Re: [PATCH] D17815: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-05-10 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

Ping...


http://reviews.llvm.org/D17815



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


Re: [PATCH] D19725: [Coverage] Fix an issue where a coverage region might not be created for a macro containing for or while statements.

2016-05-04 Thread Igor Kudrin via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL268511: [Coverage] Fix an issue where a coverage region 
might not be created for a… (authored by ikudrin).

Changed prior to commit:
  http://reviews.llvm.org/D19725?vs=55602=56159#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D19725

Files:
  cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
  cfe/trunk/test/CoverageMapping/macroscopes.cpp

Index: cfe/trunk/test/CoverageMapping/macroscopes.cpp
===
--- cfe/trunk/test/CoverageMapping/macroscopes.cpp
+++ cfe/trunk/test/CoverageMapping/macroscopes.cpp
@@ -22,6 +22,17 @@
 #define starts_a_while while (x < 5)
 #define simple_stmt ++x
 
+#define macro_with_for  \
+  x = 3;\
+  for (int i = 0; i < x; ++i) { \
+  }
+
+#define macro_with_while \
+  x = 4; \
+  while (x < 5) {\
+++x; \
+  }
+
 // CHECK: main
 // CHECK-NEXT: File 0, [[@LINE+1]]:12 -> {{[0-9]+}}:2 = #0
 int main() {
@@ -64,6 +75,11 @@
 simple_stmt;
   ends_a_scope
 
+  // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:17 = #0
+  macro_with_for
+  // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:19 = #0
+  macro_with_while
+
   return 0;
 }
 
@@ -103,3 +119,10 @@
 // CHECK-NEXT: File 11, 22:31 -> 22:36 = (#0 + #9)
 // CHECK-NEXT: File 12, 23:21 -> 23:24 = #9
 // CHECK-NEXT: File 13, 6:3 -> 7:4 = #9
+// CHECK-NEXT: File 14, 26:3 -> 28:4 = #0
+// CHECK-NEXT: File 14, 27:19 -> 27:24 = (#0 + #10)
+// CHECK-NEXT: File 14, 27:26 -> 27:29 = #10
+// CHECK-NEXT: File 14, 27:31 -> 28:4 = #10
+// CHECK-NEXT: File 15, 31:3 -> 34:4 = #0
+// CHECK-NEXT: File 15, 32:10 -> 32:15 = (#0 + #11)
+// CHECK-NEXT: File 15, 32:17 -> 34:4 = #11
Index: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
===
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
@@ -443,15 +443,31 @@
 return ExitCount;
   }
 
+  /// \brief Check whether a region with bounds \c StartLoc and \c EndLoc
+  /// is already added to \c SourceRegions.
+  bool isRegionAlreadyAdded(SourceLocation StartLoc, SourceLocation EndLoc) {
+return SourceRegions.rend() !=
+   std::find_if(SourceRegions.rbegin(), SourceRegions.rend(),
+[&](const SourceMappingRegion ) {
+  return Region.getStartLoc() == StartLoc &&
+ Region.getEndLoc() == EndLoc;
+});
+  }
+
   /// \brief Adjust the most recently visited location to \c EndLoc.
   ///
   /// This should be used after visiting any statements in non-source order.
   void adjustForOutOfOrderTraversal(SourceLocation EndLoc) {
 MostRecentLocation = EndLoc;
-// Avoid adding duplicate regions if we have a completed region on the top
-// of the stack and are adjusting to the end of a virtual file.
+// The code region for a whole macro is created in handleFileExit() when
+// it detects exiting of the virtual file of that macro. If we visited
+// statements in non-source order, we might already have such a region
+// added, for example, if a body of a loop is divided among multiple
+// macros. Avoid adding duplicate regions in such case.
 if (getRegion().hasEndLoc() &&
-MostRecentLocation == getEndOfFileOrMacro(MostRecentLocation))
+MostRecentLocation == getEndOfFileOrMacro(MostRecentLocation) &&
+isRegionAlreadyAdded(getStartOfFileOrMacro(MostRecentLocation),
+ MostRecentLocation))
   MostRecentLocation = getIncludeOrExpansionLoc(MostRecentLocation);
   }
 


Index: cfe/trunk/test/CoverageMapping/macroscopes.cpp
===
--- cfe/trunk/test/CoverageMapping/macroscopes.cpp
+++ cfe/trunk/test/CoverageMapping/macroscopes.cpp
@@ -22,6 +22,17 @@
 #define starts_a_while while (x < 5)
 #define simple_stmt ++x
 
+#define macro_with_for  \
+  x = 3;\
+  for (int i = 0; i < x; ++i) { \
+  }
+
+#define macro_with_while \
+  x = 4; \
+  while (x < 5) {\
+++x; \
+  }
+
 // CHECK: main
 // CHECK-NEXT: File 0, [[@LINE+1]]:12 -> {{[0-9]+}}:2 = #0
 int main() {
@@ -64,6 +75,11 @@
 simple_stmt;
   ends_a_scope
 
+  // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:17 = #0
+  macro_with_for
+  // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:19 = #0
+  macro_with_while
+
   return 0;
 }
 
@@ -103,3 +119,10 @@
 // CHECK-NEXT: File 11, 22:31 -> 22:36 = (#0 + #9)
 // CHECK-NEXT: File 12, 23:21 -> 23:24 = #9
 // CHECK-NEXT: File 13, 6:3 -> 7:4 = #9
+// CHECK-NEXT: File 14, 26:3 -> 28:4 = #0
+// CHECK-NEXT: File 14, 27:19 -> 27:24 = (#0 + #10)
+// CHECK-NEXT: File 14, 27:26 -> 27:29 = #10
+// CHECK-NEXT: File 14, 27:31 -> 

r268511 - [Coverage] Fix an issue where a coverage region might not be created for a macro containing a loop statement.

2016-05-04 Thread Igor Kudrin via cfe-commits
Author: ikudrin
Date: Wed May  4 10:38:26 2016
New Revision: 268511

URL: http://llvm.org/viewvc/llvm-project?rev=268511=rev
Log:
[Coverage] Fix an issue where a coverage region might not be created for a 
macro containing a loop statement.

The issue happened when a macro contained a full for or
while statement, which body ended at the end of the macro.

Differential Revision: http://reviews.llvm.org/D19725

Modified:
cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
cfe/trunk/test/CoverageMapping/macroscopes.cpp

Modified: cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp?rev=268511=268510=268511=diff
==
--- cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp (original)
+++ cfe/trunk/lib/CodeGen/CoverageMappingGen.cpp Wed May  4 10:38:26 2016
@@ -443,15 +443,31 @@ struct CounterCoverageMappingBuilder
 return ExitCount;
   }
 
+  /// \brief Check whether a region with bounds \c StartLoc and \c EndLoc
+  /// is already added to \c SourceRegions.
+  bool isRegionAlreadyAdded(SourceLocation StartLoc, SourceLocation EndLoc) {
+return SourceRegions.rend() !=
+   std::find_if(SourceRegions.rbegin(), SourceRegions.rend(),
+[&](const SourceMappingRegion ) {
+  return Region.getStartLoc() == StartLoc &&
+ Region.getEndLoc() == EndLoc;
+});
+  }
+
   /// \brief Adjust the most recently visited location to \c EndLoc.
   ///
   /// This should be used after visiting any statements in non-source order.
   void adjustForOutOfOrderTraversal(SourceLocation EndLoc) {
 MostRecentLocation = EndLoc;
-// Avoid adding duplicate regions if we have a completed region on the top
-// of the stack and are adjusting to the end of a virtual file.
+// The code region for a whole macro is created in handleFileExit() when
+// it detects exiting of the virtual file of that macro. If we visited
+// statements in non-source order, we might already have such a region
+// added, for example, if a body of a loop is divided among multiple
+// macros. Avoid adding duplicate regions in such case.
 if (getRegion().hasEndLoc() &&
-MostRecentLocation == getEndOfFileOrMacro(MostRecentLocation))
+MostRecentLocation == getEndOfFileOrMacro(MostRecentLocation) &&
+isRegionAlreadyAdded(getStartOfFileOrMacro(MostRecentLocation),
+ MostRecentLocation))
   MostRecentLocation = getIncludeOrExpansionLoc(MostRecentLocation);
   }
 

Modified: cfe/trunk/test/CoverageMapping/macroscopes.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CoverageMapping/macroscopes.cpp?rev=268511=268510=268511=diff
==
--- cfe/trunk/test/CoverageMapping/macroscopes.cpp (original)
+++ cfe/trunk/test/CoverageMapping/macroscopes.cpp Wed May  4 10:38:26 2016
@@ -22,6 +22,17 @@
 #define starts_a_while while (x < 5)
 #define simple_stmt ++x
 
+#define macro_with_for  \
+  x = 3;\
+  for (int i = 0; i < x; ++i) { \
+  }
+
+#define macro_with_while \
+  x = 4; \
+  while (x < 5) {\
+++x; \
+  }
+
 // CHECK: main
 // CHECK-NEXT: File 0, [[@LINE+1]]:12 -> {{[0-9]+}}:2 = #0
 int main() {
@@ -64,6 +75,11 @@ int main() {
 simple_stmt;
   ends_a_scope
 
+  // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:17 = #0
+  macro_with_for
+  // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:19 = #0
+  macro_with_while
+
   return 0;
 }
 
@@ -103,3 +119,10 @@ int main() {
 // CHECK-NEXT: File 11, 22:31 -> 22:36 = (#0 + #9)
 // CHECK-NEXT: File 12, 23:21 -> 23:24 = #9
 // CHECK-NEXT: File 13, 6:3 -> 7:4 = #9
+// CHECK-NEXT: File 14, 26:3 -> 28:4 = #0
+// CHECK-NEXT: File 14, 27:19 -> 27:24 = (#0 + #10)
+// CHECK-NEXT: File 14, 27:26 -> 27:29 = #10
+// CHECK-NEXT: File 14, 27:31 -> 28:4 = #10
+// CHECK-NEXT: File 15, 31:3 -> 34:4 = #0
+// CHECK-NEXT: File 15, 32:10 -> 32:15 = (#0 + #11)
+// CHECK-NEXT: File 15, 32:17 -> 34:4 = #11


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


Re: [PATCH] D19725: [Coverage] Fix an issue where a coverage region might not be created for a macro containing for or while statements.

2016-05-04 Thread Igor Kudrin via cfe-commits

Thank you!

On 02.05.2016 06:40, Justin Bogner wrote:

Igor Kudrin  writes:
  
+  /// \brief Check whether a region with bounds \c StartLoc and \c EndLoc

+  /// is already added to \c SourceRegions.
+  bool isRegionAlreadyAdded(SourceLocation StartLoc, SourceLocation EndLoc) {
+return SourceRegions.rend() !=
+   std::find_if(SourceRegions.rbegin(), SourceRegions.rend(),
Any particular reason for rbegin/rend? I guess you expect the match to
be near the end of the list when it exists?


Yes, exactly. I suppose that if that region exists, it's probably added 
recently.

+[=](const SourceMappingRegion ) {

There's no good reason to capture by value here. Best to use [&] for
efficiency.


OK.

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


[PATCH] D19725: [Coverage] Fix an issue where a coverage region might not be created for a macro containing for or while statements.

2016-04-29 Thread Igor Kudrin via cfe-commits
ikudrin created this revision.
ikudrin added reviewers: bogner, davidxl, vsk.
ikudrin added a subscriber: cfe-commits.

The situation happened when a macro contained a full loop statement,
which body ended at the end of the macro.

http://reviews.llvm.org/D19725

Files:
  lib/CodeGen/CoverageMappingGen.cpp
  test/CoverageMapping/macroscopes.cpp

Index: test/CoverageMapping/macroscopes.cpp
===
--- test/CoverageMapping/macroscopes.cpp
+++ test/CoverageMapping/macroscopes.cpp
@@ -22,6 +22,17 @@
 #define starts_a_while while (x < 5)
 #define simple_stmt ++x
 
+#define macro_with_for  \
+  x = 3;\
+  for (int i = 0; i < x; ++i) { \
+  }
+
+#define macro_with_while \
+  x = 4; \
+  while (x < 5) {\
+++x; \
+  }
+
 // CHECK: main
 // CHECK-NEXT: File 0, [[@LINE+1]]:12 -> {{[0-9]+}}:2 = #0
 int main() {
@@ -64,6 +75,11 @@
 simple_stmt;
   ends_a_scope
 
+  // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:17 = #0
+  macro_with_for
+  // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:19 = #0
+  macro_with_while
+
   return 0;
 }
 
@@ -103,3 +119,10 @@
 // CHECK-NEXT: File 11, 22:31 -> 22:36 = (#0 + #9)
 // CHECK-NEXT: File 12, 23:21 -> 23:24 = #9
 // CHECK-NEXT: File 13, 6:3 -> 7:4 = #9
+// CHECK-NEXT: File 14, 26:3 -> 28:4 = #0
+// CHECK-NEXT: File 14, 27:19 -> 27:24 = (#0 + #10)
+// CHECK-NEXT: File 14, 27:26 -> 27:29 = #10
+// CHECK-NEXT: File 14, 27:31 -> 28:4 = #10
+// CHECK-NEXT: File 15, 31:3 -> 34:4 = #0
+// CHECK-NEXT: File 15, 32:10 -> 32:15 = (#0 + #11)
+// CHECK-NEXT: File 15, 32:17 -> 34:4 = #11
Index: lib/CodeGen/CoverageMappingGen.cpp
===
--- lib/CodeGen/CoverageMappingGen.cpp
+++ lib/CodeGen/CoverageMappingGen.cpp
@@ -443,15 +443,30 @@
 return ExitCount;
   }
 
+  /// \brief Check whether a region with bounds \c StartLoc and \c EndLoc
+  /// is already added to \c SourceRegions.
+  bool isRegionAlreadyAdded(SourceLocation StartLoc, SourceLocation EndLoc) {
+return SourceRegions.rend() !=
+   std::find_if(SourceRegions.rbegin(), SourceRegions.rend(),
+[=](const SourceMappingRegion ) {
+  assert(Region.hasStartLoc() && "incomplete region");
+  assert(Region.hasEndLoc() && "incomplete region");
+  return Region.getStartLoc() == StartLoc &&
+ Region.getEndLoc() == EndLoc;
+});
+  }
+
   /// \brief Adjust the most recently visited location to \c EndLoc.
   ///
   /// This should be used after visiting any statements in non-source order.
   void adjustForOutOfOrderTraversal(SourceLocation EndLoc) {
 MostRecentLocation = EndLoc;
 // Avoid adding duplicate regions if we have a completed region on the top
-// of the stack and are adjusting to the end of a virtual file.
+// of the stack.
 if (getRegion().hasEndLoc() &&
-MostRecentLocation == getEndOfFileOrMacro(MostRecentLocation))
+MostRecentLocation == getEndOfFileOrMacro(MostRecentLocation) &&
+isRegionAlreadyAdded(getStartOfFileOrMacro(MostRecentLocation),
+ MostRecentLocation))
   MostRecentLocation = getIncludeOrExpansionLoc(MostRecentLocation);
   }
 


Index: test/CoverageMapping/macroscopes.cpp
===
--- test/CoverageMapping/macroscopes.cpp
+++ test/CoverageMapping/macroscopes.cpp
@@ -22,6 +22,17 @@
 #define starts_a_while while (x < 5)
 #define simple_stmt ++x
 
+#define macro_with_for  \
+  x = 3;\
+  for (int i = 0; i < x; ++i) { \
+  }
+
+#define macro_with_while \
+  x = 4; \
+  while (x < 5) {\
+++x; \
+  }
+
 // CHECK: main
 // CHECK-NEXT: File 0, [[@LINE+1]]:12 -> {{[0-9]+}}:2 = #0
 int main() {
@@ -64,6 +75,11 @@
 simple_stmt;
   ends_a_scope
 
+  // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:17 = #0
+  macro_with_for
+  // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:3 -> [[@LINE+1]]:19 = #0
+  macro_with_while
+
   return 0;
 }
 
@@ -103,3 +119,10 @@
 // CHECK-NEXT: File 11, 22:31 -> 22:36 = (#0 + #9)
 // CHECK-NEXT: File 12, 23:21 -> 23:24 = #9
 // CHECK-NEXT: File 13, 6:3 -> 7:4 = #9
+// CHECK-NEXT: File 14, 26:3 -> 28:4 = #0
+// CHECK-NEXT: File 14, 27:19 -> 27:24 = (#0 + #10)
+// CHECK-NEXT: File 14, 27:26 -> 27:29 = #10
+// CHECK-NEXT: File 14, 27:31 -> 28:4 = #10
+// CHECK-NEXT: File 15, 31:3 -> 34:4 = #0
+// CHECK-NEXT: File 15, 32:10 -> 32:15 = (#0 + #11)
+// CHECK-NEXT: File 15, 32:17 -> 34:4 = #11
Index: lib/CodeGen/CoverageMappingGen.cpp
===
--- lib/CodeGen/CoverageMappingGen.cpp
+++ lib/CodeGen/CoverageMappingGen.cpp
@@ -443,15 +443,30 @@
 

Re: [PATCH] D17815: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-04-19 Thread Igor Kudrin via cfe-commits
ikudrin updated this revision to Diff 54189.
ikudrin added a comment.

- Moved the content of `fallback_malloc.ipp` into `falback_malloc.cpp`.
- Removed `fallback_malloc.ipp`.
- Added `pragma GCC visibility push(hidden)` for the function's definitions.
- Added a check that the overwritten `calloc` is called to the test.
- Added a loop to run the test several times.

Please note that `test_fallback_malloc.pass.cpp` now has to #include 
`fallback_malloc.cpp`, because `fallback_malloc.ipp` was removed. I'd 
considered some other options, including declaring additional functions 
especially for testing purpose and even moving all fallback_malloc 
functionality into a separate class which could be tested independently. 
However, eventually, I found them more difficult and even much worse than the 
presented approach.


http://reviews.llvm.org/D17815

Files:
  src/CMakeLists.txt
  src/cxa_exception.cpp
  src/cxa_exception_storage.cpp
  src/fallback_malloc.cpp
  src/fallback_malloc.h
  src/fallback_malloc.ipp
  test/test_exception_storage_nodynmem.pass.cpp
  test/test_fallback_malloc.pass.cpp

Index: test/test_fallback_malloc.pass.cpp
===
--- test/test_fallback_malloc.pass.cpp
+++ test/test_fallback_malloc.pass.cpp
@@ -16,7 +16,7 @@
 
 // #define  DEBUG_FALLBACK_MALLOC
 #define INSTRUMENT_FALLBACK_MALLOC
-#include "../src/fallback_malloc.ipp"
+#include "../src/fallback_malloc.cpp"
 
 container alloc_series ( size_t sz ) {
 container ptrs;
Index: test/test_exception_storage_nodynmem.pass.cpp
===
--- /dev/null
+++ test/test_exception_storage_nodynmem.pass.cpp
@@ -0,0 +1,32 @@
+//===--- test_exception_storage_nodynmem.cpp --===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include 
+#include 
+
+static bool OverwrittenCallocCalled = false;
+
+// Override calloc to simulate exhaustion of dynamic memory
+void *calloc(size_t, size_t) {
+OverwrittenCallocCalled = true;
+return 0;
+}
+
+int main(int argc, char *argv[]) {
+// Run the test a couple of times
+// to ensure that fallback memory doesn't leak.
+for (int I = 0; I < 1000; ++I)
+try {
+throw 42;
+} catch (...) {
+}
+
+assert(OverwrittenCallocCalled);
+return 0;
+}
Index: src/fallback_malloc.ipp
===
--- src/fallback_malloc.ipp
+++ /dev/null
@@ -1,188 +0,0 @@
-//=== fallback_malloc.ipp -===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//  
-//  This file implements the "Exception Handling APIs"
-//  http://mentorembedded.github.io/cxx-abi/abi-eh.html
-//  
-//===--===//
-
-#include "config.h"
-
-//  A small, simple heap manager based (loosely) on 
-//  the startup heap manager from FreeBSD, optimized for space.
-//
-//  Manages a fixed-size memory pool, supports malloc and free only.
-//  No support for realloc.
-//
-//  Allocates chunks in multiples of four bytes, with a four byte header
-//  for each chunk. The overhead of each chunk is kept low by keeping pointers
-//  as two byte offsets within the heap, rather than (4 or 8 byte) pointers.
-
-namespace {
-
-// When POSIX threads are not available, make the mutex operations a nop
-#if LIBCXXABI_HAS_NO_THREADS
-static void * heap_mutex = 0;
-#else
-static pthread_mutex_t heap_mutex = PTHREAD_MUTEX_INITIALIZER;
-#endif
-
-class mutexor {
-public:
-#if LIBCXXABI_HAS_NO_THREADS
-mutexor ( void * ) {}
-~mutexor () {}
-#else
-mutexor ( pthread_mutex_t *m ) : mtx_(m) { pthread_mutex_lock ( mtx_ ); }
-~mutexor () { pthread_mutex_unlock ( mtx_ ); }
-#endif
-private:
-mutexor ( const mutexor  );
-mutexor & operator = ( const mutexor  );
-#if !LIBCXXABI_HAS_NO_THREADS
-pthread_mutex_t *mtx_;
-#endif
-};
-
-
-#define HEAP_SIZE   512
-char heap [ HEAP_SIZE ];
-
-typedef unsigned short heap_offset;
-typedef unsigned short heap_size;
-
-struct heap_node {
-heap_offset next_node;  // offset into heap
-heap_size   len;// size in units of "sizeof(heap_node)"
-};
-
-static const heap_node *list_end = (heap_node *) (  [ HEAP_SIZE ] );   // one past the end of the heap
-static heap_node *freelist = NULL;
-
-heap_node *node_from_offset ( const heap_offset offset )
-{ return (heap_node *) ( heap + ( offset * sizeof (heap_node))); }
-
-heap_offset offset_from_node ( const heap_node *ptr )

Re: [PATCH] D17815: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-04-18 Thread Igor Kudrin via cfe-commits
ikudrin updated this revision to Diff 54151.
ikudrin added a comment.

Regenerated the patch against project's root.


http://reviews.llvm.org/D17815

Files:
  src/CMakeLists.txt
  src/cxa_exception.cpp
  src/cxa_exception_storage.cpp
  src/fallback_malloc.cpp
  src/fallback_malloc.h
  test/test_exception_storage_nodynmem.pass.cpp

Index: test/test_exception_storage_nodynmem.pass.cpp
===
--- /dev/null
+++ test/test_exception_storage_nodynmem.pass.cpp
@@ -0,0 +1,21 @@
+//===--- test_exception_storage_nodynmem.cpp --===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include 
+
+// Override calloc to simulate exhaustion of dynamic memory
+void *calloc(size_t, size_t) { return 0; }
+
+int main(int argc, char *argv[]) {
+  try {
+throw 42;
+  } catch (...) {
+  }
+  return 0;
+}
Index: src/fallback_malloc.h
===
--- /dev/null
+++ src/fallback_malloc.h
@@ -0,0 +1,29 @@
+//===- fallback_malloc.h --===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef _FALLBACK_MALLOC_H
+#define _FALLBACK_MALLOC_H
+
+namespace __cxxabiv1 {
+
+#pragma GCC visibility push(hidden)
+
+// Allocate some memory from _somewhere_
+void * __cxa_malloc_with_fallback(size_t size);
+
+// Allocate and zero-initialize memory from _somewhere_
+void * __cxa_calloc_with_fallback(size_t count, size_t size);
+
+void __cxa_free_with_fallback(void *ptr);
+
+#pragma GCC visibility pop
+
+} // namespace __cxxabiv1
+
+#endif
Index: src/fallback_malloc.cpp
===
--- /dev/null
+++ src/fallback_malloc.cpp
@@ -0,0 +1,49 @@
+//=== fallback_malloc.ipp -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "config.h"
+
+#include  // for malloc, calloc, free
+#include  // for memset
+
+#if !LIBCXXABI_HAS_NO_THREADS
+#include  // for fallback_malloc.ipp's mutexes
+#endif
+
+#include "fallback_malloc.h"
+#include "fallback_malloc.ipp"
+
+namespace __cxxabiv1 {
+
+void * __cxa_malloc_with_fallback(size_t size) {
+void *ptr = std::malloc(size);
+if (NULL == ptr) // if malloc fails, fall back to emergency stash
+ptr = fallback_malloc(size);
+return ptr;
+}
+
+void * __cxa_calloc_with_fallback(size_t count, size_t size) {
+void *ptr = std::calloc(count, size);
+if (NULL != ptr)
+return ptr;
+// if calloc fails, fall back to emergency stash
+ptr = fallback_malloc(size * count);
+if (NULL != ptr)
+std::memset(ptr, 0, size * count);
+return ptr;
+}
+
+void __cxa_free_with_fallback(void *ptr) {
+if (is_fallback_ptr(ptr))
+fallback_free(ptr);
+else
+std::free(ptr);
+}
+
+} // namespace __cxxabiv1
Index: src/cxa_exception_storage.cpp
===
--- src/cxa_exception_storage.cpp
+++ src/cxa_exception_storage.cpp
@@ -45,8 +45,8 @@
 #else
 
 #include 
-#include   // for calloc, free
 #include "abort_message.h"
+#include "fallback_malloc.h"
 
 //  In general, we treat all pthread errors as fatal.
 //  We cannot call std::terminate() because that will in turn
@@ -58,7 +58,7 @@
 pthread_once_t flag_ = PTHREAD_ONCE_INIT;
 
 void destruct_ (void *p) {
-std::free ( p );
+__cxa_free_with_fallback ( p );
 if ( 0 != ::pthread_setspecific ( key_, NULL ) ) 
 abort_message("cannot zero out thread value for __cxa_get_globals()");
 }
@@ -77,7 +77,7 @@
 //  If this is the first time we've been asked for these globals, create them
 if ( NULL == retVal ) {
 retVal = static_cast<__cxa_eh_globals*>
-(std::calloc (1, sizeof (__cxa_eh_globals)));
+(__cxa_calloc_with_fallback (1, sizeof (__cxa_eh_globals)));
 if ( NULL == retVal )
 abort_message("cannot allocate __cxa_eh_globals");
 if ( 0 != pthread_setspecific ( key_, retVal ) )
Index: src/cxa_exception.cpp
===
--- src/cxa_exception.cpp
+++ 

Re: [PATCH] D17815: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-04-18 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

Ping! Could anyone check this patch, please?


http://reviews.llvm.org/D17815



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


Re: [PATCH] D17815: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-04-13 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

Ping...


http://reviews.llvm.org/D17815



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


Re: [PATCH] D17815: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-04-04 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

Ping...


http://reviews.llvm.org/D17815



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


Re: [PATCH] D17815: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-03-28 Thread Igor Kudrin via cfe-commits
ikudrin updated the summary for this revision.
ikudrin updated this revision to Diff 51782.
ikudrin added a comment.

Make cxa_exception.cpp and cxa_exception_storage.cpp to use the same emergency 
memory pool.


http://reviews.llvm.org/D17815

Files:
  libcxxabi/trunk/src/CMakeLists.txt
  libcxxabi/trunk/src/cxa_exception.cpp
  libcxxabi/trunk/src/cxa_exception_storage.cpp
  libcxxabi/trunk/src/fallback_malloc.cpp
  libcxxabi/trunk/src/fallback_malloc.h
  libcxxabi/trunk/test/test_exception_storage_nodynmem.pass.cpp

Index: libcxxabi/trunk/test/test_exception_storage_nodynmem.pass.cpp
===
--- /dev/null
+++ libcxxabi/trunk/test/test_exception_storage_nodynmem.pass.cpp
@@ -0,0 +1,21 @@
+//===--- test_exception_storage_nodynmem.cpp --===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include 
+
+// Override calloc to simulate exhaustion of dynamic memory
+void *calloc(size_t, size_t) { return 0; }
+
+int main(int argc, char *argv[]) {
+  try {
+throw 42;
+  } catch (...) {
+  }
+  return 0;
+}
Index: libcxxabi/trunk/src/fallback_malloc.h
===
--- /dev/null
+++ libcxxabi/trunk/src/fallback_malloc.h
@@ -0,0 +1,29 @@
+//===- fallback_malloc.h --===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef _FALLBACK_MALLOC_H
+#define _FALLBACK_MALLOC_H
+
+namespace __cxxabiv1 {
+
+#pragma GCC visibility push(hidden)
+
+// Allocate some memory from _somewhere_
+void * __cxa_malloc_with_fallback(size_t size);
+
+// Allocate and zero-initialize memory from _somewhere_
+void * __cxa_calloc_with_fallback(size_t count, size_t size);
+
+void __cxa_free_with_fallback(void *ptr);
+
+#pragma GCC visibility pop
+
+} // namespace __cxxabiv1
+
+#endif
Index: libcxxabi/trunk/src/fallback_malloc.cpp
===
--- /dev/null
+++ libcxxabi/trunk/src/fallback_malloc.cpp
@@ -0,0 +1,49 @@
+//=== fallback_malloc.ipp -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "config.h"
+
+#include  // for malloc, calloc, free
+#include  // for memset
+
+#if !LIBCXXABI_HAS_NO_THREADS
+#include  // for fallback_malloc.ipp's mutexes
+#endif
+
+#include "fallback_malloc.h"
+#include "fallback_malloc.ipp"
+
+namespace __cxxabiv1 {
+
+void * __cxa_malloc_with_fallback(size_t size) {
+void *ptr = std::malloc(size);
+if (NULL == ptr) // if malloc fails, fall back to emergency stash
+ptr = fallback_malloc(size);
+return ptr;
+}
+
+void * __cxa_calloc_with_fallback(size_t count, size_t size) {
+void *ptr = std::calloc(count, size);
+if (NULL != ptr)
+return ptr;
+// if calloc fails, fall back to emergency stash
+ptr = fallback_malloc(size * count);
+if (NULL != ptr)
+std::memset(ptr, 0, size * count);
+return ptr;
+}
+
+void __cxa_free_with_fallback(void *ptr) {
+if (is_fallback_ptr(ptr))
+fallback_free(ptr);
+else
+std::free(ptr);
+}
+
+} // namespace __cxxabiv1
Index: libcxxabi/trunk/src/cxa_exception_storage.cpp
===
--- libcxxabi/trunk/src/cxa_exception_storage.cpp
+++ libcxxabi/trunk/src/cxa_exception_storage.cpp
@@ -45,8 +45,8 @@
 #else
 
 #include 
-#include   // for calloc, free
 #include "abort_message.h"
+#include "fallback_malloc.h"
 
 //  In general, we treat all pthread errors as fatal.
 //  We cannot call std::terminate() because that will in turn
@@ -58,7 +58,7 @@
 pthread_once_t flag_ = PTHREAD_ONCE_INIT;
 
 void destruct_ (void *p) {
-std::free ( p );
+__cxa_free_with_fallback ( p );
 if ( 0 != ::pthread_setspecific ( key_, NULL ) ) 
 abort_message("cannot zero out thread value for __cxa_get_globals()");
 }
@@ -77,7 +77,7 @@
 //  If this is the first time we've been asked for these globals, create them
 if ( NULL == retVal ) {
 retVal = static_cast<__cxa_eh_globals*>
-(std::calloc (1, sizeof (__cxa_eh_globals)));
+

Re: [PATCH] D17815: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-03-15 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

Thanks! I'll see what I can do about it.


http://reviews.llvm.org/D17815



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


Re: [PATCH] D17815: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-03-14 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

Ping?..


http://reviews.llvm.org/D17815



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


Re: [PATCH] D17815: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-03-08 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

Ping.


http://reviews.llvm.org/D17815



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


[PATCH] D17815: [libc++abi] Use fallback_malloc to allocate __cxa_eh_globals in case of dynamic memory exhaustion.

2016-03-02 Thread Igor Kudrin via cfe-commits
ikudrin created this revision.
ikudrin added reviewers: mclow.lists, howard.hinnant, EricWF.
ikudrin added a subscriber: cfe-commits.

Throwing an exception for the first time may lead to calling calloc to allocate 
memory for __cxa_eh_globals. If the memory pool at that moment is exhausted, it 
results in abnormal termination of the program.

This patch addresses the issue by using fallback_malloc in that case.

http://reviews.llvm.org/D17815

Files:
  libcxxabi/trunk/src/cxa_exception_storage.cpp
  libcxxabi/trunk/test/test_exception_storage_nodynmem.pass.cpp

Index: libcxxabi/trunk/test/test_exception_storage_nodynmem.pass.cpp
===
--- /dev/null
+++ libcxxabi/trunk/test/test_exception_storage_nodynmem.pass.cpp
@@ -0,0 +1,21 @@
+//===--- test_exception_storage_nodynmem.cpp 
--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include 
+
+// Override calloc to simulate exhaustion of dynamic memory
+void *calloc(size_t, size_t) { return 0; }
+
+int main(int argc, char *argv[]) {
+  try {
+throw 42;
+  } catch (...) {
+  }
+  return 0;
+}
Index: libcxxabi/trunk/src/cxa_exception_storage.cpp
===
--- libcxxabi/trunk/src/cxa_exception_storage.cpp
+++ libcxxabi/trunk/src/cxa_exception_storage.cpp
@@ -46,19 +46,38 @@
 
 #include 
 #include   // for calloc, free
+#include   // for memset
 #include "abort_message.h"
 
 //  In general, we treat all pthread errors as fatal.
 //  We cannot call std::terminate() because that will in turn
 //  call __cxa_get_globals() and cause infinite recursion.
 
 namespace __cxxabiv1 {
+
+#include "fallback_malloc.ipp"
+
+//  Allocate some memory from _somewhere_
+static void *do_calloc(size_t count, size_t size) {
+void *ptr = std::calloc(count, size);
+if (NULL == ptr) { // if calloc fails, fall back to emergency stash
+ptr = fallback_malloc(size * count);
+if (NULL != ptr)
+std::memset(ptr, 0, size * count);
+}
+return ptr;
+}
+
+static void do_free(void *ptr) {
+is_fallback_ptr(ptr) ? fallback_free(ptr) : std::free(ptr);
+}
+
 namespace {
 pthread_key_t  key_;
 pthread_once_t flag_ = PTHREAD_ONCE_INIT;
 
 void destruct_ (void *p) {
-std::free ( p );
+do_free ( p );
 if ( 0 != ::pthread_setspecific ( key_, NULL ) ) 
 abort_message("cannot zero out thread value for 
__cxa_get_globals()");
 }
@@ -77,7 +96,7 @@
 //  If this is the first time we've been asked for these globals, create 
them
 if ( NULL == retVal ) {
 retVal = static_cast<__cxa_eh_globals*>
-(std::calloc (1, sizeof (__cxa_eh_globals)));
+(do_calloc (1, sizeof (__cxa_eh_globals)));
 if ( NULL == retVal )
 abort_message("cannot allocate __cxa_eh_globals");
 if ( 0 != pthread_setspecific ( key_, retVal ) )


Index: libcxxabi/trunk/test/test_exception_storage_nodynmem.pass.cpp
===
--- /dev/null
+++ libcxxabi/trunk/test/test_exception_storage_nodynmem.pass.cpp
@@ -0,0 +1,21 @@
+//===--- test_exception_storage_nodynmem.cpp --===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include 
+
+// Override calloc to simulate exhaustion of dynamic memory
+void *calloc(size_t, size_t) { return 0; }
+
+int main(int argc, char *argv[]) {
+  try {
+throw 42;
+  } catch (...) {
+  }
+  return 0;
+}
Index: libcxxabi/trunk/src/cxa_exception_storage.cpp
===
--- libcxxabi/trunk/src/cxa_exception_storage.cpp
+++ libcxxabi/trunk/src/cxa_exception_storage.cpp
@@ -46,19 +46,38 @@
 
 #include 
 #include   // for calloc, free
+#include   // for memset
 #include "abort_message.h"
 
 //  In general, we treat all pthread errors as fatal.
 //  We cannot call std::terminate() because that will in turn
 //  call __cxa_get_globals() and cause infinite recursion.
 
 namespace __cxxabiv1 {
+
+#include "fallback_malloc.ipp"
+
+//  Allocate some memory from _somewhere_
+static void *do_calloc(size_t count, size_t size) {
+void *ptr = std::calloc(count, size);
+if (NULL == ptr) { // if calloc fails, fall back to emergency stash
+ptr = fallback_malloc(size * count);
+if (NULL != ptr)
+

Re: [PATCH] D12832: [Driver] Add support for Windows 10 SDK

2015-09-23 Thread Igor Kudrin via cfe-commits
ikudrin updated this revision to Diff 35585.
ikudrin added a comment.

- Rebased to the top of history
- Made pathes local to clang subtree


http://reviews.llvm.org/D12832

Files:
  lib/Driver/MSVCToolChain.cpp
  lib/Driver/ToolChains.h

Index: lib/Driver/ToolChains.h
===
--- lib/Driver/ToolChains.h
+++ lib/Driver/ToolChains.h
@@ -871,7 +871,9 @@
   const llvm::opt::ArgList ,
   llvm::opt::ArgStringList ) const override;
 
-  bool getWindowsSDKDir(std::string , int , int ) const;
+  bool getWindowsSDKDir(std::string , int ,
+std::string ,
+std::string ) const;
   bool getWindowsSDKLibraryPath(std::string ) const;
   /// \brief Check if Universal CRT should be used if available
   bool useUniversalCRT(std::string ) const;
@@ -889,7 +891,9 @@
   void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList ,
  llvm::opt::ArgStringList ,
  const std::string ,
- const char *subfolder) const;
+ const Twine ,
+ const Twine  = "",
+ const Twine  = "") const;
 
   Tool *buildLinker() const override;
   Tool *buildAssembler() const override;
Index: lib/Driver/MSVCToolChain.cpp
===
--- lib/Driver/MSVCToolChain.cpp
+++ lib/Driver/MSVCToolChain.cpp
@@ -220,27 +220,88 @@
   }
 }
 
+// Find the most recent version of Universal CRT or Windows 10 SDK.
+// vcvarsqueryregistry.bat from Visual Studio 2015 sorts entries in the include
+// directory by name and uses the last one of the list.
+// So we compare entry names lexicographically to find the greatest one.
+static bool getWindows10SDKVersion(const std::string ,
+   std::string ) {
+  SDKVersion.clear();
+
+  std::error_code EC;
+  llvm::SmallString<128> IncludePath(SDKPath);
+  llvm::sys::path::append(IncludePath, "Include");
+  for (llvm::sys::fs::directory_iterator DirIt(IncludePath, EC), DirEnd;
+   DirIt != DirEnd && !EC; DirIt.increment(EC)) {
+if (!llvm::sys::fs::is_directory(DirIt->path()))
+  continue;
+StringRef CandidateName = llvm::sys::path::filename(DirIt->path());
+// If WDK is installed, there could be subfolders like "wdf" in the
+// "Include" directory.
+// Allow only directories which names start with "10.".
+if (!CandidateName.startswith("10."))
+  continue;
+if (CandidateName > SDKVersion)
+  SDKVersion = CandidateName;
+  }
+
+  return !SDKVersion.empty();
+}
+
 /// \brief Get Windows SDK installation directory.
-bool MSVCToolChain::getWindowsSDKDir(std::string , int ,
- int ) const {
-  std::string sdkVersion;
+bool MSVCToolChain::getWindowsSDKDir(std::string , int ,
+ std::string ,
+ std::string ) const {
+  std::string RegistrySDKVersion;
   // Try the Windows registry.
-  bool hasSDKDir = getSystemRegistryString(
-  "SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION",
-  "InstallationFolder", path, );
-  if (!sdkVersion.empty())
-std::sscanf(sdkVersion.c_str(), "v%d.%d", , );
-  return hasSDKDir && !path.empty();
+  if (!getSystemRegistryString(
+  "SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION",
+  "InstallationFolder", Path, ))
+return false;
+  if (Path.empty() || RegistrySDKVersion.empty())
+return false;
+
+  WindowsSDKIncludeVersion.clear();
+  WindowsSDKLibVersion.clear();
+  Major = 0;
+  std::sscanf(RegistrySDKVersion.c_str(), "v%d.", );
+  if (Major <= 7)
+return true;
+  if (Major == 8) {
+// Windows SDK 8.x installs libraries in a folder whose names depend on the
+// version of the OS you're targeting.  By default choose the newest, which
+// usually corresponds to the version of the OS you've installed the SDK on.
+const char *Tests[] = {"winv6.3", "win8", "win7"};
+for (const char *Test : Tests) {
+  llvm::SmallString<128> TestPath(Path);
+  llvm::sys::path::append(TestPath, "Lib", Test);
+  if (llvm::sys::fs::exists(TestPath.c_str())) {
+WindowsSDKLibVersion = Test;
+break;
+  }
+}
+return !WindowsSDKLibVersion.empty();
+  }
+  if (Major == 10) {
+if (!getWindows10SDKVersion(Path, WindowsSDKIncludeVersion))
+  return false;
+WindowsSDKLibVersion = WindowsSDKIncludeVersion;
+return true;
+  }
+  // Unsupported SDK version
+  return false;
 }
 
 // Gets the library path required to link against the Windows SDK.
 bool MSVCToolChain::getWindowsSDKLibraryPath(std::string ) const {
   std::string sdkPath;
   int sdkMajor = 0;
-  int sdkMinor = 0;
+  std::string windowsSDKIncludeVersion;
+  std::string windowsSDKLibVersion;
 
   

r248463 - [Driver] Add support for Windows 10 SDK

2015-09-23 Thread Igor Kudrin via cfe-commits
Author: ikudrin
Date: Thu Sep 24 00:16:36 2015
New Revision: 248463

URL: http://llvm.org/viewvc/llvm-project?rev=248463=rev
Log:
[Driver] Add support for Windows 10 SDK

Summary:
With Windows 10 SDK, Include and Lib directories now contain an additional 
subfolder with the name that corresponds to the full version of the SDK, for 
example:
  - C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\um
  - C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\um\x64


Reviewers: ruiu, rnk

Subscribers: majnemer, cfe-commits

Differential Revision: http://reviews.llvm.org/D12832

Modified:
cfe/trunk/lib/Driver/MSVCToolChain.cpp
cfe/trunk/lib/Driver/ToolChains.h

Modified: cfe/trunk/lib/Driver/MSVCToolChain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/MSVCToolChain.cpp?rev=248463=248462=248463=diff
==
--- cfe/trunk/lib/Driver/MSVCToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/MSVCToolChain.cpp Thu Sep 24 00:16:36 2015
@@ -220,27 +220,88 @@ static StringRef getWindowsSDKArch(llvm:
   }
 }
 
+// Find the most recent version of Universal CRT or Windows 10 SDK.
+// vcvarsqueryregistry.bat from Visual Studio 2015 sorts entries in the include
+// directory by name and uses the last one of the list.
+// So we compare entry names lexicographically to find the greatest one.
+static bool getWindows10SDKVersion(const std::string ,
+   std::string ) {
+  SDKVersion.clear();
+
+  std::error_code EC;
+  llvm::SmallString<128> IncludePath(SDKPath);
+  llvm::sys::path::append(IncludePath, "Include");
+  for (llvm::sys::fs::directory_iterator DirIt(IncludePath, EC), DirEnd;
+   DirIt != DirEnd && !EC; DirIt.increment(EC)) {
+if (!llvm::sys::fs::is_directory(DirIt->path()))
+  continue;
+StringRef CandidateName = llvm::sys::path::filename(DirIt->path());
+// If WDK is installed, there could be subfolders like "wdf" in the
+// "Include" directory.
+// Allow only directories which names start with "10.".
+if (!CandidateName.startswith("10."))
+  continue;
+if (CandidateName > SDKVersion)
+  SDKVersion = CandidateName;
+  }
+
+  return !SDKVersion.empty();
+}
+
 /// \brief Get Windows SDK installation directory.
-bool MSVCToolChain::getWindowsSDKDir(std::string , int ,
- int ) const {
-  std::string sdkVersion;
+bool MSVCToolChain::getWindowsSDKDir(std::string , int ,
+ std::string ,
+ std::string ) const {
+  std::string RegistrySDKVersion;
   // Try the Windows registry.
-  bool hasSDKDir = getSystemRegistryString(
-  "SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION",
-  "InstallationFolder", path, );
-  if (!sdkVersion.empty())
-std::sscanf(sdkVersion.c_str(), "v%d.%d", , );
-  return hasSDKDir && !path.empty();
+  if (!getSystemRegistryString(
+  "SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION",
+  "InstallationFolder", Path, ))
+return false;
+  if (Path.empty() || RegistrySDKVersion.empty())
+return false;
+
+  WindowsSDKIncludeVersion.clear();
+  WindowsSDKLibVersion.clear();
+  Major = 0;
+  std::sscanf(RegistrySDKVersion.c_str(), "v%d.", );
+  if (Major <= 7)
+return true;
+  if (Major == 8) {
+// Windows SDK 8.x installs libraries in a folder whose names depend on the
+// version of the OS you're targeting.  By default choose the newest, which
+// usually corresponds to the version of the OS you've installed the SDK 
on.
+const char *Tests[] = {"winv6.3", "win8", "win7"};
+for (const char *Test : Tests) {
+  llvm::SmallString<128> TestPath(Path);
+  llvm::sys::path::append(TestPath, "Lib", Test);
+  if (llvm::sys::fs::exists(TestPath.c_str())) {
+WindowsSDKLibVersion = Test;
+break;
+  }
+}
+return !WindowsSDKLibVersion.empty();
+  }
+  if (Major == 10) {
+if (!getWindows10SDKVersion(Path, WindowsSDKIncludeVersion))
+  return false;
+WindowsSDKLibVersion = WindowsSDKIncludeVersion;
+return true;
+  }
+  // Unsupported SDK version
+  return false;
 }
 
 // Gets the library path required to link against the Windows SDK.
 bool MSVCToolChain::getWindowsSDKLibraryPath(std::string ) const {
   std::string sdkPath;
   int sdkMajor = 0;
-  int sdkMinor = 0;
+  std::string windowsSDKIncludeVersion;
+  std::string windowsSDKLibVersion;
 
   path.clear();
-  if (!getWindowsSDKDir(sdkPath, sdkMajor, sdkMinor))
+  if (!getWindowsSDKDir(sdkPath, sdkMajor, windowsSDKIncludeVersion,
+windowsSDKLibVersion))
 return false;
 
   llvm::SmallString<128> libPath(sdkPath);
@@ -260,28 +321,10 @@ bool MSVCToolChain::getWindowsSDKLibrary
   return false;
 }
   } else {
-// Windows SDK 8.x installs libraries in a folder whose names depend on the
-// version of the OS you're 

Re: [PATCH] D12832: [Driver] Add support for Windows 10 SDK

2015-09-17 Thread Igor Kudrin via cfe-commits
ikudrin marked 2 inline comments as done.
ikudrin added a comment.

http://reviews.llvm.org/D12832



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


Re: [PATCH] D12832: [Driver] Added support for Windows 10 SDK

2015-09-17 Thread Igor Kudrin via cfe-commits
ikudrin updated this revision to Diff 34965.
ikudrin added a comment.

- reworked the conditional statement
- formatting


http://reviews.llvm.org/D12832

Files:
  cfe/trunk/lib/Driver/MSVCToolChain.cpp
  cfe/trunk/lib/Driver/ToolChains.h

Index: cfe/trunk/lib/Driver/ToolChains.h
===
--- cfe/trunk/lib/Driver/ToolChains.h
+++ cfe/trunk/lib/Driver/ToolChains.h
@@ -838,7 +838,9 @@
   const llvm::opt::ArgList ,
   llvm::opt::ArgStringList ) const override;
 
-  bool getWindowsSDKDir(std::string , int , int ) const;
+  bool getWindowsSDKDir(std::string , int ,
+std::string ,
+std::string ) const;
   bool getWindowsSDKLibraryPath(std::string ) const;
   /// \brief Check if Universal CRT should be used if available
   bool useUniversalCRT(std::string ) const;
@@ -856,7 +858,9 @@
   void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList ,
  llvm::opt::ArgStringList ,
  const std::string ,
- const char *subfolder) const;
+ const Twine ,
+ const Twine  = "",
+ const Twine  = "") const;
 
   Tool *buildLinker() const override;
   Tool *buildAssembler() const override;
Index: cfe/trunk/lib/Driver/MSVCToolChain.cpp
===
--- cfe/trunk/lib/Driver/MSVCToolChain.cpp
+++ cfe/trunk/lib/Driver/MSVCToolChain.cpp
@@ -220,27 +220,83 @@
   }
 }
 
+// Find the most recent version of Universal CRT or Windows 10 SDK.
+// vcvarsqueryregistry.bat from Visual Studio 2015 sorts entries in the include
+// directory by name and uses the last one of the list.
+// So we compare entry names lexicographically to find the greatest one.
+static bool getWindows10SDKVersion(const std::string ,
+   std::string ) {
+  SDKVersion.clear();
+
+  std::error_code EC;
+  llvm::SmallString<128> IncludePath(SDKPath);
+  llvm::sys::path::append(IncludePath, "Include");
+  for (llvm::sys::fs::directory_iterator DirIt(IncludePath, EC), DirEnd;
+   DirIt != DirEnd && !EC; DirIt.increment(EC)) {
+if (!llvm::sys::fs::is_directory(DirIt->path()))
+  continue;
+const StringRef CandidateName = llvm::sys::path::filename(DirIt->path());
+if (CandidateName > SDKVersion)
+  SDKVersion = CandidateName;
+  }
+
+  return !SDKVersion.empty();
+}
+
 /// \brief Get Windows SDK installation directory.
-bool MSVCToolChain::getWindowsSDKDir(std::string , int ,
- int ) const {
-  std::string sdkVersion;
+bool MSVCToolChain::getWindowsSDKDir(std::string , int ,
+ std::string ,
+ std::string ) const {
+  std::string RegistrySDKVersion;
   // Try the Windows registry.
-  bool hasSDKDir = getSystemRegistryString(
-  "SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION",
-  "InstallationFolder", path, );
-  if (!sdkVersion.empty())
-std::sscanf(sdkVersion.c_str(), "v%d.%d", , );
-  return hasSDKDir && !path.empty();
+  if (!getSystemRegistryString(
+  "SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION",
+  "InstallationFolder", Path, ))
+return false;
+  if (Path.empty() || RegistrySDKVersion.empty())
+return false;
+
+  WindowsSDKIncludeVersion.clear();
+  WindowsSDKLibVersion.clear();
+  Major = 0;
+  std::sscanf(RegistrySDKVersion.c_str(), "v%d.", );
+  if (Major <= 7)
+return true;
+  if (Major == 8) {
+// Windows SDK 8.x installs libraries in a folder whose names depend on the
+// version of the OS you're targeting.  By default choose the newest, which
+// usually corresponds to the version of the OS you've installed the SDK on.
+const char *Tests[] = {"winv6.3", "win8", "win7"};
+for (const char *Test : Tests) {
+  llvm::SmallString<128> TestPath(Path);
+  llvm::sys::path::append(TestPath, "Lib", Test);
+  if (llvm::sys::fs::exists(TestPath.c_str())) {
+WindowsSDKLibVersion = Test;
+break;
+  }
+}
+return !WindowsSDKLibVersion.empty();
+  }
+  if (Major == 10) {
+if (!getWindows10SDKVersion(Path, WindowsSDKIncludeVersion))
+  return false;
+WindowsSDKLibVersion = WindowsSDKIncludeVersion;
+return true;
+  }
+  // Unsupported SDK version
+  return false;
 }
 
 // Gets the library path required to link against the Windows SDK.
 bool MSVCToolChain::getWindowsSDKLibraryPath(std::string ) const {
   std::string sdkPath;
   int sdkMajor = 0;
-  int sdkMinor = 0;
+  std::string windowsSDKIncludeVersion;
+  std::string windowsSDKLibVersion;
 
   path.clear();
-  if (!getWindowsSDKDir(sdkPath, sdkMajor, sdkMinor))
+  if (!getWindowsSDKDir(sdkPath, sdkMajor, windowsSDKIncludeVersion,
+

Re: [PATCH] D12832: [Driver] Add support for Windows 10 SDK

2015-09-17 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

I found a new problem, after install WDK. I'll submit a new version in a moment.


http://reviews.llvm.org/D12832



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


Re: [PATCH] D12832: [Driver] Add support for Windows 10 SDK

2015-09-17 Thread Igor Kudrin via cfe-commits
ikudrin marked an inline comment as done.
ikudrin added a comment.

http://reviews.llvm.org/D12832



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


Re: [PATCH] D12832: [Driver] Add support for Windows 10 SDK

2015-09-17 Thread Igor Kudrin via cfe-commits
ikudrin updated this revision to Diff 35013.
ikudrin added a comment.

Skip directories like C:\Program Files (x86)\Windows Kits\10\Include\wdf, which 
come from WDK installation, when looking for SDK version. Now, we detect 
directories even better than vsvars32.bat in that situation.


http://reviews.llvm.org/D12832

Files:
  cfe/trunk/lib/Driver/MSVCToolChain.cpp
  cfe/trunk/lib/Driver/ToolChains.h

Index: cfe/trunk/lib/Driver/ToolChains.h
===
--- cfe/trunk/lib/Driver/ToolChains.h
+++ cfe/trunk/lib/Driver/ToolChains.h
@@ -838,7 +838,9 @@
   const llvm::opt::ArgList ,
   llvm::opt::ArgStringList ) const override;
 
-  bool getWindowsSDKDir(std::string , int , int ) const;
+  bool getWindowsSDKDir(std::string , int ,
+std::string ,
+std::string ) const;
   bool getWindowsSDKLibraryPath(std::string ) const;
   /// \brief Check if Universal CRT should be used if available
   bool useUniversalCRT(std::string ) const;
@@ -856,7 +858,9 @@
   void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList ,
  llvm::opt::ArgStringList ,
  const std::string ,
- const char *subfolder) const;
+ const Twine ,
+ const Twine  = "",
+ const Twine  = "") const;
 
   Tool *buildLinker() const override;
   Tool *buildAssembler() const override;
Index: cfe/trunk/lib/Driver/MSVCToolChain.cpp
===
--- cfe/trunk/lib/Driver/MSVCToolChain.cpp
+++ cfe/trunk/lib/Driver/MSVCToolChain.cpp
@@ -220,27 +220,88 @@
   }
 }
 
+// Find the most recent version of Universal CRT or Windows 10 SDK.
+// vcvarsqueryregistry.bat from Visual Studio 2015 sorts entries in the include
+// directory by name and uses the last one of the list.
+// So we compare entry names lexicographically to find the greatest one.
+static bool getWindows10SDKVersion(const std::string ,
+   std::string ) {
+  SDKVersion.clear();
+
+  std::error_code EC;
+  llvm::SmallString<128> IncludePath(SDKPath);
+  llvm::sys::path::append(IncludePath, "Include");
+  for (llvm::sys::fs::directory_iterator DirIt(IncludePath, EC), DirEnd;
+   DirIt != DirEnd && !EC; DirIt.increment(EC)) {
+if (!llvm::sys::fs::is_directory(DirIt->path()))
+  continue;
+StringRef CandidateName = llvm::sys::path::filename(DirIt->path());
+// If WDK is installed, there could be subfolders like "wdf" in the
+// "Include" directory.
+// Allow only directories which names start with "10.".
+if (!CandidateName.startswith("10."))
+  continue;
+if (CandidateName > SDKVersion)
+  SDKVersion = CandidateName;
+  }
+
+  return !SDKVersion.empty();
+}
+
 /// \brief Get Windows SDK installation directory.
-bool MSVCToolChain::getWindowsSDKDir(std::string , int ,
- int ) const {
-  std::string sdkVersion;
+bool MSVCToolChain::getWindowsSDKDir(std::string , int ,
+ std::string ,
+ std::string ) const {
+  std::string RegistrySDKVersion;
   // Try the Windows registry.
-  bool hasSDKDir = getSystemRegistryString(
-  "SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION",
-  "InstallationFolder", path, );
-  if (!sdkVersion.empty())
-std::sscanf(sdkVersion.c_str(), "v%d.%d", , );
-  return hasSDKDir && !path.empty();
+  if (!getSystemRegistryString(
+  "SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION",
+  "InstallationFolder", Path, ))
+return false;
+  if (Path.empty() || RegistrySDKVersion.empty())
+return false;
+
+  WindowsSDKIncludeVersion.clear();
+  WindowsSDKLibVersion.clear();
+  Major = 0;
+  std::sscanf(RegistrySDKVersion.c_str(), "v%d.", );
+  if (Major <= 7)
+return true;
+  if (Major == 8) {
+// Windows SDK 8.x installs libraries in a folder whose names depend on the
+// version of the OS you're targeting.  By default choose the newest, which
+// usually corresponds to the version of the OS you've installed the SDK on.
+const char *Tests[] = {"winv6.3", "win8", "win7"};
+for (const char *Test : Tests) {
+  llvm::SmallString<128> TestPath(Path);
+  llvm::sys::path::append(TestPath, "Lib", Test);
+  if (llvm::sys::fs::exists(TestPath.c_str())) {
+WindowsSDKLibVersion = Test;
+break;
+  }
+}
+return !WindowsSDKLibVersion.empty();
+  }
+  if (Major == 10) {
+if (!getWindows10SDKVersion(Path, WindowsSDKIncludeVersion))
+  return false;
+WindowsSDKLibVersion = WindowsSDKIncludeVersion;
+return true;
+  }
+  // Unsupported SDK version
+  return false;
 }
 
 // Gets the library path required to link against the Windows 

Re: [PATCH] D12832: [Driver] Added support for Windows 10 SDK

2015-09-16 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

Ping?


http://reviews.llvm.org/D12832



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


[PATCH] D12832: [Driver] Added support for Windows 10 SDK

2015-09-13 Thread Igor Kudrin via cfe-commits
ikudrin created this revision.
ikudrin added reviewers: ruiu, rnk.
ikudrin added a subscriber: cfe-commits.

With Windows 10 SDK, Include and Lib directories now contain an additional 
subfolder with the name that corresponds to the full version of the SDK, for 
example:
  - C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\um
  - C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\um\x64


http://reviews.llvm.org/D12832

Files:
  cfe/trunk/lib/Driver/MSVCToolChain.cpp
  cfe/trunk/lib/Driver/ToolChains.h

Index: cfe/trunk/lib/Driver/ToolChains.h
===
--- cfe/trunk/lib/Driver/ToolChains.h
+++ cfe/trunk/lib/Driver/ToolChains.h
@@ -838,7 +838,9 @@
   const llvm::opt::ArgList ,
   llvm::opt::ArgStringList ) const override;
 
-  bool getWindowsSDKDir(std::string , int , int ) const;
+  bool getWindowsSDKDir(std::string , int ,
+std::string ,
+std::string ) const;
   bool getWindowsSDKLibraryPath(std::string ) const;
   /// \brief Check if Universal CRT should be used if available
   bool useUniversalCRT(std::string ) const;
@@ -856,7 +858,9 @@
   void AddSystemIncludeWithSubfolder(const llvm::opt::ArgList ,
  llvm::opt::ArgStringList ,
  const std::string ,
- const char *subfolder) const;
+ const Twine ,
+ const Twine  = "",
+ const Twine  = "") const;
 
   Tool *buildLinker() const override;
   Tool *buildAssembler() const override;
Index: cfe/trunk/lib/Driver/MSVCToolChain.cpp
===
--- cfe/trunk/lib/Driver/MSVCToolChain.cpp
+++ cfe/trunk/lib/Driver/MSVCToolChain.cpp
@@ -220,27 +220,80 @@
   }
 }
 
+// Find the most recent version of Universal CRT or Windows 10 SDK.
+// vcvarsqueryregistry.bat from Visual Studio 2015 sorts entries in the include
+// directory by name and uses the last one of the list.
+// So we compare entry names lexicographically to find the greatest one.
+static bool getWindows10SDKVersion(const std::string ,
+   std::string ) {
+  SDKVersion.clear();
+
+  std::error_code EC;
+  llvm::SmallString<128> IncludePath(SDKPath);
+  llvm::sys::path::append(IncludePath, "Include");
+  for (llvm::sys::fs::directory_iterator DirIt(IncludePath, EC), DirEnd;
+   DirIt != DirEnd && !EC; DirIt.increment(EC)) {
+if (!llvm::sys::fs::is_directory(DirIt->path()))
+  continue;
+const StringRef CandidateName = llvm::sys::path::filename(DirIt->path());
+if (CandidateName > SDKVersion)
+  SDKVersion = CandidateName;
+  }
+
+  return !SDKVersion.empty();
+}
+
 /// \brief Get Windows SDK installation directory.
-bool MSVCToolChain::getWindowsSDKDir(std::string , int ,
- int ) const {
-  std::string sdkVersion;
+bool MSVCToolChain::getWindowsSDKDir(std::string , int ,
+ std::string ,
+ std::string ) const {
+  std::string RegistrySDKVersion;
   // Try the Windows registry.
-  bool hasSDKDir = getSystemRegistryString(
-  "SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION",
-  "InstallationFolder", path, );
-  if (!sdkVersion.empty())
-std::sscanf(sdkVersion.c_str(), "v%d.%d", , );
-  return hasSDKDir && !path.empty();
+  if (!getSystemRegistryString(
+  "SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\$VERSION",
+  "InstallationFolder", Path, ))
+return false;
+  if (Path.empty() || RegistrySDKVersion.empty())
+return false;
+
+  WindowsSDKIncludeVersion.clear();
+  WindowsSDKLibVersion.clear();
+  Major = 0;
+  std::sscanf(RegistrySDKVersion.c_str(), "v%d.", );
+  if (Major > 7 && Major < 10) {
+// Windows SDK 8.x installs libraries in a folder whose names depend on the
+// version of the OS you're targeting.  By default choose the newest, which
+// usually corresponds to the version of the OS you've installed the SDK on.
+const char *Tests[] = {"winv6.3", "win8", "win7"};
+for (const char *Test : Tests) {
+  llvm::SmallString<128> TestPath(Path);
+  llvm::sys::path::append(TestPath, "Lib", Test);
+  if (llvm::sys::fs::exists(TestPath.c_str())) {
+WindowsSDKLibVersion = Test;
+break;
+  }
+}
+if (WindowsSDKLibVersion.empty())
+  return false;
+  }
+  else {
+if (!getWindows10SDKVersion(Path, WindowsSDKIncludeVersion))
+  return false;
+WindowsSDKLibVersion = WindowsSDKIncludeVersion;
+  }
+  return true;
 }
 
 // Gets the library path required to link against the Windows SDK.
 bool MSVCToolChain::getWindowsSDKLibraryPath(std::string ) const {
   std::string sdkPath;
   int sdkMajor = 0;
-  int sdkMinor = 0;
+  std::string 

Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available

2015-09-11 Thread Igor Kudrin via cfe-commits

Please, can you show the output of the following commands:

1) set include
2) set lib
3) clang-cl.exe -### -fms-compatibility-version=19 foo.cpp

On 11.09.2015 17:44, İsmail Dönmez wrote:

This doesn't seem to work here, VS 2015 on Win 10 x64:

C:\Users\ismail\Desktop>clang-cl.exe -fms-compatibility-version=19 foo.cpp
LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
clang-cl.exe: error: linker command failed with exit code 1104 (use -v
to see invocation)

Works fine after setting LIB.

On Fri, Sep 11, 2015 at 3:11 AM, Reid Kleckner via cfe-commits
 wrote:

This revision was automatically updated to reflect the committed changes.
Closed by commit rL247362: [Driver] Use UniversalCRT on Windows if available 
(authored by rnk).

Changed prior to commit:
   http://reviews.llvm.org/D12695?vs=34475=34515#toc

Repository:
   rL LLVM

http://reviews.llvm.org/D12695

Files:
   cfe/trunk/lib/Driver/MSVCToolChain.cpp
   cfe/trunk/lib/Driver/ToolChains.h
   cfe/trunk/lib/Driver/Tools.cpp


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



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


Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available

2015-09-10 Thread Igor Kudrin via cfe-commits
ikudrin added a comment.

In http://reviews.llvm.org/D12695#243552, @rnk wrote:

> There's a bunch of whitespace issues that clang-format can resolve.


Thanks! I'll reformat it.

> We also have the convention that variables are StudlyCaps, which isn't 
> followed in a few places.


I've tried to follow the style of the source file. Do you think I should force 
this rule here?

> Do you need someone to commit this for you? If so, I can patch this in, test 
> it manually, and deal with the style stuff if you deal with the VSDir part.


I'd really appreciate it. I'll prepare a new version in a few minutes.


http://reviews.llvm.org/D12695



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


Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available

2015-09-10 Thread Igor Kudrin via cfe-commits
ikudrin marked an inline comment as done.
ikudrin added a comment.

In http://reviews.llvm.org/D12695#243320, @rnk wrote:

> FYI @ruiu is moving this code to LLVM in http://reviews.llvm.org/D12604.


Thanks. I think I'll move my changes to the new place when he's finished.


http://reviews.llvm.org/D12695



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


Re: [PATCH] D12695: [Driver] Use UniversalCRT on Windows if available

2015-09-10 Thread Igor Kudrin via cfe-commits
ikudrin updated this revision to Diff 34475.
ikudrin added a comment.

- Fixed formatting issues.
- Normalized VariableNames.
- Reworked the useUniversalCRT method to receive a path of Visual Studio.


http://reviews.llvm.org/D12695

Files:
  lib/Driver/MSVCToolChain.cpp
  lib/Driver/ToolChains.h
  lib/Driver/Tools.cpp

Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -8951,6 +8951,13 @@
   }
   CmdArgs.push_back(
   Args.MakeArgString(std::string("-libpath:") + LibDir.c_str()));
+
+  if (MSVC.useUniversalCRT(VisualStudioDir)) {
+std::string UniversalCRTLibPath;
+if (MSVC.getUniversalCRTLibraryPath(UniversalCRTLibPath))
+  CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") +
+   UniversalCRTLibPath.c_str()));
+  }
 }
 
 std::string WindowsSdkLibPath;
Index: lib/Driver/ToolChains.h
===
--- lib/Driver/ToolChains.h
+++ lib/Driver/ToolChains.h
@@ -840,6 +840,10 @@
 
   bool getWindowsSDKDir(std::string , int , int ) const;
   bool getWindowsSDKLibraryPath(std::string ) const;
+  /// \brief Check if Universal CRT should be used if available
+  bool useUniversalCRT(std::string ) const;
+  bool getUniversalCRTSdkDir(std::string , std::string ) const;
+  bool getUniversalCRTLibraryPath(std::string ) const;
   bool getVisualStudioInstallDir(std::string ) const;
   bool getVisualStudioBinariesFolder(const char *clangProgramPath,
  std::string ) const;
Index: lib/Driver/MSVCToolChain.cpp
===
--- lib/Driver/MSVCToolChain.cpp
+++ lib/Driver/MSVCToolChain.cpp
@@ -205,6 +205,21 @@
 #endif // USE_WIN32
 }
 
+// Convert LLVM's ArchType
+// to the corresponding name of Windows SDK libraries subfolder
+static StringRef getWindowsSDKArch(llvm::Triple::ArchType Arch) {
+  switch (Arch) {
+  case llvm::Triple::x86:
+return "x86";
+  case llvm::Triple::x86_64:
+return "x64";
+  case llvm::Triple::arm:
+return "arm";
+  default:
+return "";
+  }
+}
+
 /// \brief Get Windows SDK installation directory.
 bool MSVCToolChain::getWindowsSDKDir(std::string , int ,
  int ) const {
@@ -263,26 +278,75 @@
 if (!found)
   return false;
 
-llvm::sys::path::append(libPath, "um");
-switch (getArch()) {
-case llvm::Triple::x86:
-  llvm::sys::path::append(libPath, "x86");
-  break;
-case llvm::Triple::x86_64:
-  llvm::sys::path::append(libPath, "x64");
-  break;
-case llvm::Triple::arm:
-  llvm::sys::path::append(libPath, "arm");
-  break;
-default:
+const StringRef archName = getWindowsSDKArch(getArch());
+if (archName.empty())
   return false;
-}
+llvm::sys::path::append(libPath, "um", archName);
   }
 
   path = libPath.str();
   return true;
 }
 
+// Check if the Include path of a specified version of Visual Studio contains
+// specific header files. If not, they are probably shipped with Universal CRT.
+bool clang::driver::toolchains::MSVCToolChain::useUniversalCRT(
+std::string ) const {
+  llvm::SmallString<128> TestPath(VisualStudioDir);
+  llvm::sys::path::append(TestPath, "VC\\include\\stdlib.h");
+
+  return !llvm::sys::fs::exists(TestPath);
+}
+
+bool MSVCToolChain::getUniversalCRTSdkDir(std::string ,
+  std::string ) const {
+  // vcvarsqueryregistry.bat for Visual Studio 2015 queries the registry
+  // for the specific key "KitsRoot10". So do we.
+  if (!getSystemRegistryString(
+  "SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots", "KitsRoot10",
+  Path, nullptr))
+return false;
+
+  UCRTVersion.clear();
+
+  // Find the most recent version of Universal CRT.
+  // vcvarsqueryregistry.bat sorts entries in the include directory by names and
+  // uses the last one of the list.
+  // So we compare entry names lexicographically to find the greatest one.
+  std::error_code EC;
+  llvm::SmallString<128> IncludePath(Path);
+  llvm::sys::path::append(IncludePath, "Include");
+  for (llvm::sys::fs::directory_iterator DirIt(IncludePath, EC), DirEnd;
+   DirIt != DirEnd && !EC; DirIt.increment(EC)) {
+if (!llvm::sys::fs::is_directory(DirIt->path()))
+  continue;
+StringRef CandidateName = llvm::sys::path::filename(DirIt->path());
+if (CandidateName > UCRTVersion)
+  UCRTVersion = CandidateName;
+  }
+
+  return !UCRTVersion.empty();
+}
+
+bool MSVCToolChain::getUniversalCRTLibraryPath(std::string ) const {
+  std::string UniversalCRTSdkPath;
+  std::string UCRTVersion;
+
+  Path.clear();
+  if (!getUniversalCRTSdkDir(UniversalCRTSdkPath, UCRTVersion))
+return false;
+
+  StringRef ArchName = getWindowsSDKArch(getArch());
+  if (ArchName.empty())
+

[PATCH] D12695: [Driver] Use UniversalCRT on Windows if available

2015-09-08 Thread Igor Kudrin via cfe-commits
ikudrin created this revision.
ikudrin added a subscriber: cfe-commits.

With Visual Studio 2015 release, a part of runtime library was extracted and 
now comes with Windows Kits. This patch enables clang to use Universal CRT 
library if  %INCLUDE or %LIB environment varaibles are not specified.

See also https://llvm.org/bugs/show_bug.cgi?id=24741

http://reviews.llvm.org/D12695

Files:
  lib/Driver/MSVCToolChain.cpp
  lib/Driver/ToolChains.h
  lib/Driver/Tools.cpp

Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -8953,6 +8953,11 @@
   Args.MakeArgString(std::string("-libpath:") + LibDir.c_str()));
 }
 
+std::string UniversalCRTLibPath;
+if (MSVC.getUniversalCRTLibraryPath(UniversalCRTLibPath))
+  CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") +
+   UniversalCRTLibPath.c_str()));
+
 std::string WindowsSdkLibPath;
 if (MSVC.getWindowsSDKLibraryPath(WindowsSdkLibPath))
   CmdArgs.push_back(Args.MakeArgString(std::string("-libpath:") +
Index: lib/Driver/ToolChains.h
===
--- lib/Driver/ToolChains.h
+++ lib/Driver/ToolChains.h
@@ -836,6 +836,9 @@
 
   bool getWindowsSDKDir(std::string , int , int ) const;
   bool getWindowsSDKLibraryPath(std::string ) const;
+  bool getUniversalCRTSdkDir(std::string ,
+std::string ) const;
+  bool getUniversalCRTLibraryPath(std::string ) const;
   bool getVisualStudioInstallDir(std::string ) const;
   bool getVisualStudioBinariesFolder(const char *clangProgramPath,
  std::string ) const;
Index: lib/Driver/MSVCToolChain.cpp
===
--- lib/Driver/MSVCToolChain.cpp
+++ lib/Driver/MSVCToolChain.cpp
@@ -283,6 +283,66 @@
   return true;
 }
 
+bool MSVCToolChain::getUniversalCRTSdkDir(std::string ,
+  std::string ) const
+{
+  // vcvarsqueryregistry.bat for Visual Studio 2015 queries the registry
+  // for the specific key "KitsRoot10". So do we.
+  if (!getSystemRegistryString(
+"SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots",
+"KitsRoot10", path, nullptr))
+return false;
+
+  ucrtVersion.clear();
+
+  // Find the most recent version of Universal CRT.
+  // vcvarsqueryregistry.bat sorts entries in the include directory by names and
+  // uses the last one of the list.
+  // So we compare entry names lexicographically to find the greatest one.
+  std::error_code ec;
+  llvm::SmallString<128> includePath(path);
+  llvm::sys::path::append(includePath, "Include");
+  for (llvm::sys::fs::directory_iterator dirIt(includePath, ec), dirEnd;
+  dirIt != dirEnd && !ec; dirIt.increment(ec)) {
+if (!llvm::sys::fs::is_directory(dirIt->path()))
+  continue;
+StringRef name = llvm::sys::path::filename(dirIt->path());
+if (name > ucrtVersion)
+  ucrtVersion = name;
+  }
+
+  return !ucrtVersion.empty();
+}
+
+bool MSVCToolChain::getUniversalCRTLibraryPath(std::string ) const
+{
+  std::string universalCRTSdkPath;
+  std::string ucrtVersion;
+
+  path.clear();
+  if (!getUniversalCRTSdkDir(universalCRTSdkPath, ucrtVersion))
+return false;
+
+  llvm::SmallString<128> libPath(universalCRTSdkPath);
+  llvm::sys::path::append(libPath, "Lib", ucrtVersion, "ucrt");
+  switch (getArch()) {
+  case llvm::Triple::x86:
+llvm::sys::path::append(libPath, "x86");
+break;
+  case llvm::Triple::x86_64:
+llvm::sys::path::append(libPath, "x64");
+break;
+  case llvm::Triple::arm:
+llvm::sys::path::append(libPath, "arm");
+break;
+  default:
+return false;
+  }
+
+  path = libPath.str();
+  return true;
+}
+
 // Get the location to use for Visual Studio binaries.  The location priority
 // is: %VCINSTALLDIR% > %PATH% > newest copy of Visual Studio installed on
 // system (as reported by the registry).
@@ -460,6 +520,14 @@
   if (getVisualStudioInstallDir(VSDir)) {
 AddSystemIncludeWithSubfolder(DriverArgs, CC1Args, VSDir, "VC\\include");
 
+std::string universalCRTSdkPath;
+std::string ucrtVersion;
+if (getUniversalCRTSdkDir(universalCRTSdkPath, ucrtVersion)) {
+  llvm::SmallString<128> ucrtIncludePath(universalCRTSdkPath);
+  llvm::sys::path::append(ucrtIncludePath, "Include", ucrtVersion, "ucrt");
+  addSystemInclude(DriverArgs, CC1Args, ucrtIncludePath);
+}
+
 std::string WindowsSDKDir;
 int major, minor;
 if (getWindowsSDKDir(WindowsSDKDir, major, minor)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits