[PATCH] D60760: Adapt -fsanitize=function to SANITIZER_NON_UNIQUE_TYPEINFO

2019-05-02 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Did this get reviewed?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D60760



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


r359761 - Fix typo in test case.

2019-05-02 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu May  2 00:38:07 2019
New Revision: 359761

URL: http://llvm.org/viewvc/llvm-project?rev=359761&view=rev
Log:
Fix typo in test case.

Modified:
cfe/trunk/test/CodeGenObjC/protocols.m

Modified: cfe/trunk/test/CodeGenObjC/protocols.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/protocols.m?rev=359761&r1=359760&r2=359761&view=diff
==
--- cfe/trunk/test/CodeGenObjC/protocols.m (original)
+++ cfe/trunk/test/CodeGenObjC/protocols.m Thu May  2 00:38:07 2019
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | 
FileCheck %s
 
-// HECK: @[[PROTO_P1:"_OBJC_PROTOCOL_$_P1"]] = weak hidden
+// CHECK: @"\01l_OBJC_$_PROTOCOL_METHOD_TYPES_P1" = private global
 // CHECK: @[[PROTO_P1:"_OBJC_PROTOCOL_\$_P1"]] = weak hidden
 // CHECK: @[[LABEL_PROTO_P1:"_OBJC_LABEL_PROTOCOL_\$_P1"]] = weak hidden 
global %{{.*}}* @[[PROTO_P1]]
 // CHECK: @[[PROTO_P2:"_OBJC_PROTOCOL_\$_P2"]] = weak hidden


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


[PATCH] D61316: [clangd] Improvements to header mapping: more precise parsing of cppreference symbol pages.

2019-05-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clangd/include-mapping/gen_std.py:90
+# Decl may not be for the symbol name we're looking for.
+if not re.search("\\b%s\\b" % symbol_name, text):
+  continue

does this also work with functions? For example floor will be written as:
```constexpr ToDuration floor(const duration& d);```
which does not contain floor as a word. 
https://en.cppreference.com/w/cpp/chrono/duration/floor



Comment at: clangd/include-mapping/gen_std.py:95
+if was_decl:
+  current_headers = []
+was_decl = False

why not perform clean-up unconditionally?


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D61316



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


[clang-tools-extra] r359763 - [clangd] Restore conventional names for lit configs, and .in/.py split. Fix build_mode indirection.

2019-05-02 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Thu May  2 01:00:39 2019
New Revision: 359763

URL: http://llvm.org/viewvc/llvm-project?rev=359763&view=rev
Log:
[clangd] Restore conventional names for lit configs, and .in/.py split. Fix 
build_mode indirection.

Added:
clang-tools-extra/trunk/clangd/test/lit.cfg.py
clang-tools-extra/trunk/clangd/test/lit.site.cfg.py.in
clang-tools-extra/trunk/clangd/unittests/lit.cfg.py
  - copied, changed from r359674, 
clang-tools-extra/trunk/clangd/unittests/lit.cfg.in
clang-tools-extra/trunk/clangd/unittests/lit.site.cfg.py.in
Removed:
clang-tools-extra/trunk/clangd/test/lit.cfg.in
clang-tools-extra/trunk/clangd/unittests/lit.cfg.in
Modified:
clang-tools-extra/trunk/clangd/test/CMakeLists.txt
clang-tools-extra/trunk/clangd/unittests/CMakeLists.txt

Modified: clang-tools-extra/trunk/clangd/test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/test/CMakeLists.txt?rev=359763&r1=359762&r2=359763&view=diff
==
--- clang-tools-extra/trunk/clangd/test/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/test/CMakeLists.txt Thu May  2 01:00:39 2019
@@ -1,3 +1,13 @@
+# Set CLANG_TOOLS_DIR to buildtree/bin, or buildtree/%(build_mode)s/bin if the
+# location is dynamic. The latter must be interpolated by lit configs.
+# FIXME: this is duplicated in many places.
+if (CMAKE_CFG_INTDIR STREQUAL ".")
+  set(LLVM_BUILD_MODE ".")
+else ()
+  set(LLVM_BUILD_MODE "%(build_mode)s")
+endif ()
+string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} CLANG_TOOLS_DIR 
${LLVM_RUNTIME_OUTPUT_INTDIR})
+
 set(CLANGD_TEST_DEPS
   clangd
   ClangdTests
@@ -18,8 +28,8 @@ foreach(dep FileCheck count not)
 endforeach()
 
 configure_lit_site_cfg(
-  ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.in
-  ${CMAKE_CURRENT_BINARY_DIR}/lit.cfg)
+  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
+  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py)
 
 add_lit_testsuite(check-clangd "Running the Clangd regression tests"
   ${CMAKE_CURRENT_BINARY_DIR}/../unittests;${CMAKE_CURRENT_BINARY_DIR}

Removed: clang-tools-extra/trunk/clangd/test/lit.cfg.in
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/test/lit.cfg.in?rev=359762&view=auto
==
--- clang-tools-extra/trunk/clangd/test/lit.cfg.in (original)
+++ clang-tools-extra/trunk/clangd/test/lit.cfg.in (removed)
@@ -1,30 +0,0 @@
-@LIT_SITE_CFG_IN_HEADER@
-
-import lit.llvm
-import lit.formats
-
-# Reuse clang configuration (PATH setup, etc).
-config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@"
-config.clang_tools_dir = "@CLANG_TOOLS_DIR@"
-config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
-config.clang_libs_dir = "@CLANG_LIBS_DIR@"
-config.llvm_libs_dir = "@LLVM_LIBS_DIR@"
-config.target_triple = "@TARGET_TRIPLE@"
-config.host_triple = "@LLVM_HOST_TRIPLE@"
-lit.llvm.initialize(lit_config, config)
-lit.llvm.llvm_config.use_clang()
-
-config.name = 'Clangd'
-config.suffixes = ['.test']
-config.excludes = ['Inputs']
-config.test_format = lit.formats.ShTest(not lit.llvm.llvm_config.use_lit_shell)
-config.test_source_root = "@CMAKE_CURRENT_SOURCE_DIR@"
-config.test_exec_root = "@CMAKE_CURRENT_BINARY_DIR@"
-
-# Clangd-specific lit environment.
-config.substitutions.append(('%clangd-benchmark-dir',
- "@CMAKE_CURRENT_BINARY_DIR@/../benchmarks"))
-
-if @CLANGD_BUILD_XPC@:
-  config.available_features.add('clangd-xpc-support')
-

Added: clang-tools-extra/trunk/clangd/test/lit.cfg.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/test/lit.cfg.py?rev=359763&view=auto
==
--- clang-tools-extra/trunk/clangd/test/lit.cfg.py (added)
+++ clang-tools-extra/trunk/clangd/test/lit.cfg.py Thu May  2 01:00:39 2019
@@ -0,0 +1,19 @@
+import lit.llvm
+
+lit.llvm.initialize(lit_config, config)
+lit.llvm.llvm_config.use_clang()
+
+config.name = 'Clangd'
+config.suffixes = ['.test']
+config.excludes = ['Inputs']
+config.test_format = lit.formats.ShTest(not lit.llvm.llvm_config.use_lit_shell)
+config.test_source_root = config.clangd_source_dir + "/test"
+config.test_exec_root = config.clangd_binary_dir + "/test"
+
+# Clangd-specific lit environment.
+config.substitutions.append(('%clangd-benchmark-dir',
+ config.clangd_binary_dir + "/benchmarks"))
+
+if config.clangd_build_xpc:
+  config.available_features.add('clangd-xpc-support')
+

Added: clang-tools-extra/trunk/clangd/test/lit.site.cfg.py.in
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/test/lit.site.cfg.py.in?rev=359763&view=auto
==
--- clang-tools-extra/trunk/clangd/test/lit.site.cfg.py.in (added)
+++ clang-tools-extra/trunk/clangd/test/lit.site.cfg.py.in Thu May  2 01:00:39 
2019
@@ -0,0 +

[PATCH] D61316: [clangd] Improvements to header mapping: more precise parsing of cppreference symbol pages.

2019-05-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clangd/include-mapping/gen_std.py:60
+
+def ParseSymbolPage(symbol_page_html, symbol_name):
   """Parse symbol page and retrieve the include header defined in this page.

I think this requires some corresponding changes in 
`clangd/include-mapping/test.py`


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D61316



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


[PATCH] D61316: [clangd] Improvements to header mapping: more precise parsing of cppreference symbol pages.

2019-05-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clangd/include-mapping/gen_std.py:95
+if was_decl:
+  current_headers = []
+was_decl = False

kadircet wrote:
> why not perform clean-up unconditionally?
ok I see the reason for that one, 
https://en.cppreference.com/w/cpp/numeric/math/abs, NVM


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D61316



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


[PATCH] D60760: Adapt -fsanitize=function to SANITIZER_NON_UNIQUE_TYPEINFO

2019-05-02 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg added a comment.

In D60760#1487342 , @lebedev.ri wrote:

> Did this get reviewed?


I didn't get any responses at all, so decided to push it anyway.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D60760



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


[PATCH] D61276: [clang-format] Fix bug in block comment reflow that joins * and /

2019-05-02 Thread Owen Pan via Phabricator via cfe-commits
owenpan planned changes to this revision.
owenpan added a comment.

There are some corner cases this patch doesn't cover.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61276



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


[PATCH] D61422: [clang-tidy] Extend bugprone-sizeof-expression check to detect sizeof misuse in pointer arithmetic

2019-05-02 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware created this revision.
baloghadamsoftware added reviewers: alexfh, aaron.ballman, lebedev.ri.
baloghadamsoftware added a project: clang-tools-extra.
Herald added subscribers: gamesh411, Szelethus, rnkovacs.
Herald added a project: clang.

Some programmers tend to forget that subtracting two pointers results in the 
difference between them in number of elements of the pointee type instead of 
bytes. This leads to codes such as `size_t size = (p - q) / sizeof(int)` where 
`p` and `q` are of type `int*`. Or similarily, `if (p - q < buffer_size * 
sizeof(int)) { ... }`. This patch extends `bugprone-sizeof-expression` to 
detect such cases.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D61422

Files:
  clang-tidy/bugprone/SizeofExpressionCheck.cpp
  test/clang-tidy/bugprone-sizeof-expression.cpp

Index: test/clang-tidy/bugprone-sizeof-expression.cpp
===
--- test/clang-tidy/bugprone-sizeof-expression.cpp
+++ test/clang-tidy/bugprone-sizeof-expression.cpp
@@ -231,6 +231,29 @@
   return sum;
 }
 
+int Test6() {
+  int sum = 0;
+
+  int N = AsInt(), M = AsInt();
+  int *P = &N, *Q = &M;
+  sum += sizeof(int) == P - Q;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+  sum += 5 * sizeof(int) != P - Q;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+  sum += sizeof(int) < P - Q;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+  sum += 5 * sizeof(int) <= P - Q;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+  sum += sizeof(int) + (P - Q);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+  sum += 5 * sizeof(int) - (P - Q);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+  sum += (P - Q) / sizeof(int);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+
+  return sum;
+}
+
 int ValidExpressions() {
   int A[] = {1, 2, 3, 4};
   static const char str[] = "hello";
Index: clang-tidy/bugprone/SizeofExpressionCheck.cpp
===
--- clang-tidy/bugprone/SizeofExpressionCheck.cpp
+++ clang-tidy/bugprone/SizeofExpressionCheck.cpp
@@ -84,8 +84,11 @@
   const auto IntegerCallExpr = expr(ignoringParenImpCasts(
   callExpr(anyOf(hasType(isInteger()), hasType(enumType())),
unless(isInTemplateInstantiation();
-  const auto SizeOfExpr =
-  expr(anyOf(sizeOfExpr(has(type())), sizeOfExpr(has(expr();
+  const auto SizeOfExpr = expr(anyOf(
+  sizeOfExpr(
+  has(hasUnqualifiedDesugaredType(type().bind("sizeof-arg-type",
+  sizeOfExpr(has(expr(hasType(
+  hasUnqualifiedDesugaredType(type().bind("sizeof-arg-type";
   const auto SizeOfZero = expr(
   sizeOfExpr(has(ignoringParenImpCasts(expr(integerLiteral(equals(0)));
 
@@ -209,6 +212,36 @@
hasSizeOfDescendant(8, expr(SizeOfExpr, unless(SizeOfZero
   .bind("sizeof-sizeof-expr"),
   this);
+
+  // Detect sizeof in pointer aritmetic like: N * sizeof(S) == P1 - P2 or
+  // (P1 - P2) / sizeof(S) where P1 and P2 are pointers to type S
+  const auto PtrDiffExpr = binaryOperator(
+  hasOperatorName("-"),
+  hasLHS(expr(hasType(hasUnqualifiedDesugaredType(
+  pointerType(pointee(type().bind("left-ptr-type"))),
+  hasRHS(expr(hasType(hasUnqualifiedDesugaredType(
+  pointerType(pointee(type().bind("right-ptr-type";
+
+  Finder->addMatcher(
+  binaryOperator(
+  anyOf(hasOperatorName("=="), hasOperatorName("!="),
+hasOperatorName("<"), hasOperatorName("<="),
+hasOperatorName(">"), hasOperatorName(">="),
+hasOperatorName("+"), hasOperatorName("-")),
+  hasEitherOperand(expr(anyOf(
+  ignoringParenImpCasts(SizeOfExpr),
+  ignoringParenImpCasts(binaryOperator(
+  hasOperatorName("*"),
+  hasEitherOperand(ignoringParenImpCasts(SizeOfExpr))),
+  hasEitherOperand(ignoringParenImpCasts(PtrDiffExpr)))
+  .bind("sizeof-in-ptr-arithmetic-mul"),
+  this);
+
+  Finder->addMatcher(binaryOperator(hasOperatorName("/"),
+hasLHS(ignoringParenImpCasts(PtrDiffExpr)),
+hasRHS(ignoringParenImpCasts(SizeOfExpr)))
+ .bind("sizeof-in-ptr-arithmetic-div"),
+ this);
 }
 
 void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
@@ -275,6 +308,26 @@
   } else if (const auto *E =
  Result.Nodes.getNodeAs("sizeof-multiply-sizeof")) {
 diag(

[PATCH] D60760: Adapt -fsanitize=function to SANITIZER_NON_UNIQUE_TYPEINFO

2019-05-02 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D60760#1487387 , @sberg wrote:

> In D60760#1487342 , @lebedev.ri 
> wrote:
>
> > Did this get reviewed?
>
>
> I didn't get any responses at all, so decided to push it anyway.


That is not really how reviews work in LLVM.
Either it's a NFC / eligible for post-commit review, and can just be committed, 
or not.
E.g., is this missing test coverage?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D60760



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


[PATCH] D61239: [libclang] Allow field offset lookups in types with incomplete arrays.

2019-05-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D61239#1486692 , @JornVernee wrote:

> In D61239#1486634 , @aaron.ballman 
> wrote:
>
> > LGTM, thank you! That's strange that clang-format would remove the newline 
> > from the end of the file. I don't get that behavior when I try it, so it 
> > makes me wonder what's different.
>
>
> Yeah, my mistake. It was there after all. The output from clang-format looked 
> the same as what I had before, but I think I just didn't catch the newline 
> when copy-pasting the diff the first time :)


Ah that makes more sense, phew!

> Also, I don't have committer access. Would you mind committing this?

Happy to do so -- I'll try to get it in this week if I have the time, but it 
may not happen until early next week.


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

https://reviews.llvm.org/D61239



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


[PATCH] D61316: [clangd] Improvements to header mapping: more precise parsing of cppreference symbol pages.

2019-05-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 197717.
sammccall added a comment.

rebase


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D61316

Files:
  clangd/StdSymbolMap.inc
  clangd/include-mapping/gen_std.py
  clangd/include-mapping/test.py

Index: clangd/include-mapping/test.py
===
--- clangd/include-mapping/test.py
+++ clangd/include-mapping/test.py
@@ -46,9 +46,13 @@
   
   
   
+  
+void foo()
+this is matched
+  
 
 """
-self.assertEqual(ParseSymbolPage(html), [''])
+self.assertEqual(ParseSymbolPage(html, 'foo'), set(['']))
 
 
   def testParseSymbolPage_MulHeaders(self):
@@ -63,6 +67,10 @@
  
 
   
+  
+void bar()
+this mentions foo, but isn't matched
+  
   
  Defined in header 
  
@@ -75,10 +83,14 @@
 
 
   
+  
+void foo()
+this is matched
+  
 
 """
-self.assertEqual(ParseSymbolPage(html),
-['', '', ''])
+self.assertEqual(ParseSymbolPage(html, "foo"),
+ set(['', '']))
 
 
   def testParseSymbolPage_MulHeadersInSameDiv(self):
@@ -86,6 +98,7 @@
 # Defined in header 
 # Defined in header 
 html = """
+
 
 
  Defined in header 
@@ -93,8 +106,14 @@
 
 
 
+
+  void foo()
+  this is matched
+
+
 """
-self.assertEqual(ParseSymbolPage(html), ['', ''])
+self.assertEqual(ParseSymbolPage(html, "foo"),
+ set(['', '']))
 
 
 if __name__ == '__main__':
Index: clangd/include-mapping/gen_std.py
===
--- clangd/include-mapping/gen_std.py
+++ clangd/include-mapping/gen_std.py
@@ -35,6 +35,7 @@
 import datetime
 import multiprocessing
 import os
+import re
 import signal
 import sys
 
@@ -50,7 +51,13 @@
 //===--===//
 """
 
-def ParseSymbolPage(symbol_page_html):
+def HasClass(tag, *classes):
+  for c in tag.get('class', []):
+if c in classes:
+  return True
+  return False
+
+def ParseSymbolPage(symbol_page_html, symbol_name):
   """Parse symbol page and retrieve the include header defined in this page.
   The symbol page provides header for the symbol, specifically in
   "Defined in header " section. An example:
@@ -61,17 +68,43 @@
 
   Returns a list of headers.
   """
-  headers = []
+  headers = set()
+  all_headers = set()
 
   soup = BeautifulSoup(symbol_page_html, "html.parser")
-  #  "Defined in header " are defined in  or
-  #  .
-  for header_tr in soup.select('tr.t-dcl-header,tr.t-dsc-header'):
-if "Defined in header " in header_tr.text:
-  # The interesting header content (e.g. ) is wrapped in .
-  for header_code in header_tr.find_all("code"):
-headers.append(header_code.text)
-  return headers
+  # Rows in table are like:
+  #   Defined in header   .t-dsc-header
+  #   Defined in header   .t-dsc-header
+  #   decl1.t-dcl
+  #   Defined in header   .t-dsc-header
+  #   decl2.t-dcl
+  for table in soup.select('table.t-dcl-begin, table.t-dsc-begin'):
+current_headers = []
+was_decl = False
+for row in table.select('tr'):
+  if HasClass(row, 't-dcl', 't-dsc'):
+was_decl = True
+# Declaration is in the first cell.
+text = row.find('td').text
+# Decl may not be for the symbol name we're looking for.
+if not re.search("\\b%s\\b" % symbol_name, text):
+  continue
+headers.update(current_headers)
+  elif HasClass(row, 't-dsc-header'):
+# If we saw a decl since the last header, this is a new block of headers
+# for a new block of decls.
+if was_decl:
+  current_headers = []
+was_decl = False
+# There are also .t-dsc-header for "defined in namespace".
+if not "Defined in header " in row.text:
+  continue
+# The interesting header content (e.g. ) is wrapped in .
+for header_code in row.find_all("code"):
+  current_headers.append(header_code.text)
+  all_headers.add(header_code.text)
+  # If the symbol was never named, consider all named headers.
+  return headers or all_headers
 
 
 def ParseIndexPage(index_page_html):
@@ -106,7 +139,7 @@
 
 def ReadSymbolPage(path, name):
   with open(path) as f:
-return ParseSymbolPage(f.read())
+return ParseSymbolPage(f.read(), name)
 
 
 def GetSymbols(pool, root_dir, index_page_name, namespace):
Index: clangd/StdSymbolMap.inc
===
--- clangd/StdSymbolMap.inc
+++ clangd/StdSymbolMap.inc
@@ -134,12 +134,15 @@
 SYMBOL(bad_variant_access, std::, )
 SYMBOL(bad_weak_ptr, std::, )
 SYMBOL(basic_common_reference, std::, )
+SYMBOL(basic_filebuf, std::, )
 SYMBOL(basic_fstream, std::, )
 SYMBOL(basic_ifstream, std::, )
 SYM

[PATCH] D61316: [clangd] Improvements to header mapping: more precise parsing of cppreference symbol pages.

2019-05-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clangd/include-mapping/gen_std.py:90
+# Decl may not be for the symbol name we're looking for.
+if not re.search("\\b%s\\b" % symbol_name, text):
+  continue

kadircet wrote:
> does this also work with functions? For example floor will be written as:
> ```constexpr ToDuration floor(const duration& d);```
> which does not contain floor as a word. 
> https://en.cppreference.com/w/cpp/chrono/duration/floor
> which does not contain floor as a word
`\b` matches between a word character and non-word character.
Both ` ` and `(` are non-word characters, so we should be fine?



Comment at: clangd/include-mapping/gen_std.py:95
+if was_decl:
+  current_headers = []
+was_decl = False

kadircet wrote:
> why not perform clean-up unconditionally?
This isn't cleanup.

```
header1
header2
declX
```

declX is associated with header1 and header2

```
header1
declY
header2
declX
```

declX is associated with header2 only. We reset current_headers when we see 
header2 because it was preceded by a decl. I'll add a comment.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D61316



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


[PATCH] D61316: [clangd] Improvements to header mapping: more precise parsing of cppreference symbol pages.

2019-05-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 197716.
sammccall added a comment.

Add explanatory comment about headers reset.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D61316

Files:
  clangd/CodeComplete.cpp
  clangd/StdSymbolMap.inc
  clangd/include-mapping/gen_std.py
  clangd/include-mapping/test.py
  clangd/index/Serialization.cpp
  clangd/test/CMakeLists.txt
  clangd/unittests/CMakeLists.txt
  clangd/unittests/CanonicalIncludesTests.cpp
  clangd/unittests/SerializationTests.cpp
  clangd/unittests/SymbolCollectorTests.cpp
  clangd/unittests/xpc/CMakeLists.txt

Index: clangd/unittests/xpc/CMakeLists.txt
===
--- clangd/unittests/xpc/CMakeLists.txt
+++ clangd/unittests/xpc/CMakeLists.txt
@@ -8,7 +8,8 @@
   ${CLANGD_SOURCE_DIR}
   )
 
-add_extra_unittest(ClangdXpcTests
+add_custom_target(ClangdXpcUnitTests)
+add_unittest(ClangdXpcUnitTests ClangdXpcTests
   ConversionTests.cpp
   )
 
Index: clangd/unittests/SymbolCollectorTests.cpp
===
--- clangd/unittests/SymbolCollectorTests.cpp
+++ clangd/unittests/SymbolCollectorTests.cpp
@@ -931,47 +931,15 @@
   UnorderedElementsAre(IncludeHeaderWithRef(TestHeaderURI, 1u)));
 }
 
-#ifndef _WIN32
 TEST_F(SymbolCollectorTest, CanonicalSTLHeader) {
   CollectorOpts.CollectIncludePath = true;
   CanonicalIncludes Includes;
   addSystemHeadersMapping(&Includes);
   CollectorOpts.Includes = &Includes;
-  // bits/basic_string.h$ should be mapped to 
-  TestHeaderName = "/nasty/bits/basic_string.h";
-  TestFileName = "/nasty/bits/basic_string.cpp";
-  TestHeaderURI = URI::create(TestHeaderName).toString();
-  runSymbolCollector("class string {};", /*Main=*/"");
-  EXPECT_THAT(Symbols, UnorderedElementsAre(AllOf(QName("string"),
-  DeclURI(TestHeaderURI),
-  IncludeHeader("";
-}
-#endif
-
-TEST_F(SymbolCollectorTest, STLiosfwd) {
-  CollectorOpts.CollectIncludePath = true;
-  CanonicalIncludes Includes;
-  addSystemHeadersMapping(&Includes);
-  CollectorOpts.Includes = &Includes;
-  // Symbols from  should be mapped individually.
-  TestHeaderName = testPath("iosfwd");
-  TestFileName = testPath("iosfwd.cpp");
-  std::string Header = R"(
-namespace std {
-  class no_map {};
-  class ios {};
-  class ostream {};
-  class filebuf {};
-} // namespace std
-  )";
-  runSymbolCollector(Header, /*Main=*/"");
+  runSymbolCollector("namespace std { class string {}; }", /*Main=*/"");
   EXPECT_THAT(Symbols,
-  UnorderedElementsAre(
-  QName("std"),
-  AllOf(QName("std::no_map"), IncludeHeader("")),
-  AllOf(QName("std::ios"), IncludeHeader("")),
-  AllOf(QName("std::ostream"), IncludeHeader("")),
-  AllOf(QName("std::filebuf"), IncludeHeader("";
+  Contains(AllOf(QName("std::string"), DeclURI(TestHeaderURI),
+ IncludeHeader("";
 }
 
 TEST_F(SymbolCollectorTest, IWYUPragma) {
Index: clangd/unittests/SerializationTests.cpp
===
--- clangd/unittests/SerializationTests.cpp
+++ clangd/unittests/SerializationTests.cpp
@@ -40,8 +40,8 @@
   End:
 Line: 1
 Column: 1
-Origin:4
-Flags:1
+Origin:128
+Flags:129
 Documentation:'Foo doc'
 ReturnType:'int'
 IncludeHeaders:
@@ -115,7 +115,8 @@
   EXPECT_EQ(Sym1.Documentation, "Foo doc");
   EXPECT_EQ(Sym1.ReturnType, "int");
   EXPECT_EQ(StringRef(Sym1.CanonicalDeclaration.FileURI), "file:///path/foo.h");
-  EXPECT_EQ(Sym1.Origin, SymbolOrigin::Static);
+  EXPECT_EQ(Sym1.Origin, static_cast(1 << 7));
+  EXPECT_EQ(static_cast(Sym1.Flags), 129);
   EXPECT_TRUE(Sym1.Flags & Symbol::IndexedForCodeCompletion);
   EXPECT_FALSE(Sym1.Flags & Symbol::Deprecated);
   EXPECT_THAT(Sym1.IncludeHeaders,
Index: clangd/unittests/CanonicalIncludesTests.cpp
===
--- /dev/null
+++ clangd/unittests/CanonicalIncludesTests.cpp
@@ -0,0 +1,62 @@
+//===-- CanonicalIncludesTests.cpp - --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "index/CanonicalIncludes.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+TEST(CanonicalIncludesTest, CXXStandardLibrary) {
+  CanonicalIncludes CI;
+  addSystemHeadersMapping(&CI);
+
+  // Usual standard library symbols are mapped correctly.
+  EXPECT_EQ("", CI.mapHeader("path/vector.

[PATCH] D61316: [clangd] Improvements to header mapping: more precise parsing of cppreference symbol pages.

2019-05-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 197715.
sammccall marked 2 inline comments as done.
sammccall added a comment.
Herald added a subscriber: mgorny.

Update tests.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D61316

Files:
  clangd/CodeComplete.cpp
  clangd/StdSymbolMap.inc
  clangd/include-mapping/gen_std.py
  clangd/include-mapping/test.py
  clangd/index/Serialization.cpp
  clangd/test/CMakeLists.txt
  clangd/unittests/CMakeLists.txt
  clangd/unittests/CanonicalIncludesTests.cpp
  clangd/unittests/SerializationTests.cpp
  clangd/unittests/SymbolCollectorTests.cpp
  clangd/unittests/xpc/CMakeLists.txt

Index: clangd/unittests/xpc/CMakeLists.txt
===
--- clangd/unittests/xpc/CMakeLists.txt
+++ clangd/unittests/xpc/CMakeLists.txt
@@ -8,7 +8,8 @@
   ${CLANGD_SOURCE_DIR}
   )
 
-add_extra_unittest(ClangdXpcTests
+add_custom_target(ClangdXpcUnitTests)
+add_unittest(ClangdXpcUnitTests ClangdXpcTests
   ConversionTests.cpp
   )
 
Index: clangd/unittests/SymbolCollectorTests.cpp
===
--- clangd/unittests/SymbolCollectorTests.cpp
+++ clangd/unittests/SymbolCollectorTests.cpp
@@ -931,47 +931,15 @@
   UnorderedElementsAre(IncludeHeaderWithRef(TestHeaderURI, 1u)));
 }
 
-#ifndef _WIN32
 TEST_F(SymbolCollectorTest, CanonicalSTLHeader) {
   CollectorOpts.CollectIncludePath = true;
   CanonicalIncludes Includes;
   addSystemHeadersMapping(&Includes);
   CollectorOpts.Includes = &Includes;
-  // bits/basic_string.h$ should be mapped to 
-  TestHeaderName = "/nasty/bits/basic_string.h";
-  TestFileName = "/nasty/bits/basic_string.cpp";
-  TestHeaderURI = URI::create(TestHeaderName).toString();
-  runSymbolCollector("class string {};", /*Main=*/"");
-  EXPECT_THAT(Symbols, UnorderedElementsAre(AllOf(QName("string"),
-  DeclURI(TestHeaderURI),
-  IncludeHeader("";
-}
-#endif
-
-TEST_F(SymbolCollectorTest, STLiosfwd) {
-  CollectorOpts.CollectIncludePath = true;
-  CanonicalIncludes Includes;
-  addSystemHeadersMapping(&Includes);
-  CollectorOpts.Includes = &Includes;
-  // Symbols from  should be mapped individually.
-  TestHeaderName = testPath("iosfwd");
-  TestFileName = testPath("iosfwd.cpp");
-  std::string Header = R"(
-namespace std {
-  class no_map {};
-  class ios {};
-  class ostream {};
-  class filebuf {};
-} // namespace std
-  )";
-  runSymbolCollector(Header, /*Main=*/"");
+  runSymbolCollector("namespace std { class string {}; }", /*Main=*/"");
   EXPECT_THAT(Symbols,
-  UnorderedElementsAre(
-  QName("std"),
-  AllOf(QName("std::no_map"), IncludeHeader("")),
-  AllOf(QName("std::ios"), IncludeHeader("")),
-  AllOf(QName("std::ostream"), IncludeHeader("")),
-  AllOf(QName("std::filebuf"), IncludeHeader("";
+  Contains(AllOf(QName("std::string"), DeclURI(TestHeaderURI),
+ IncludeHeader("";
 }
 
 TEST_F(SymbolCollectorTest, IWYUPragma) {
Index: clangd/unittests/SerializationTests.cpp
===
--- clangd/unittests/SerializationTests.cpp
+++ clangd/unittests/SerializationTests.cpp
@@ -40,8 +40,8 @@
   End:
 Line: 1
 Column: 1
-Origin:4
-Flags:1
+Origin:128
+Flags:129
 Documentation:'Foo doc'
 ReturnType:'int'
 IncludeHeaders:
@@ -115,7 +115,8 @@
   EXPECT_EQ(Sym1.Documentation, "Foo doc");
   EXPECT_EQ(Sym1.ReturnType, "int");
   EXPECT_EQ(StringRef(Sym1.CanonicalDeclaration.FileURI), "file:///path/foo.h");
-  EXPECT_EQ(Sym1.Origin, SymbolOrigin::Static);
+  EXPECT_EQ(Sym1.Origin, static_cast(1 << 7));
+  EXPECT_EQ(static_cast(Sym1.Flags), 129);
   EXPECT_TRUE(Sym1.Flags & Symbol::IndexedForCodeCompletion);
   EXPECT_FALSE(Sym1.Flags & Symbol::Deprecated);
   EXPECT_THAT(Sym1.IncludeHeaders,
Index: clangd/unittests/CanonicalIncludesTests.cpp
===
--- /dev/null
+++ clangd/unittests/CanonicalIncludesTests.cpp
@@ -0,0 +1,62 @@
+//===-- CanonicalIncludesTests.cpp - --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "index/CanonicalIncludes.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+TEST(CanonicalIncludesTest, CXXStandardLibrary) {
+  CanonicalIncludes CI;
+  addSystemHeadersMapping(&CI);
+
+  // Usual standard library symbols are mapped correc

[PATCH] D61269: [CommandLine] Change help output to prefix long options with `--` instead of `-`. NFC . Part 3 of 5

2019-05-02 Thread Thomas Preud'homme via Phabricator via cfe-commits
thopre accepted this revision.
thopre added a comment.
This revision is now accepted and ready to land.

That's much better thank you. I like the stream shift operator overload, nice 
touch. LGTM but give it a day for other to give feedback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61269



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


[PATCH] D61349: [clangd] Standard library mapping: prefer "primary" versions of functions over variants.

2019-05-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 197719.
sammccall added a comment.

Add note about skipping variants, and mention the weird begin/end case.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D61349

Files:
  clangd/StdSymbolMap.inc
  clangd/include-mapping/gen_std.py
  clangd/include-mapping/test.py

Index: clangd/include-mapping/test.py
===
--- clangd/include-mapping/test.py
+++ clangd/include-mapping/test.py
@@ -24,16 +24,17 @@
 
 actual = ParseIndexPage(html)
 expected = [
-  ("abs", "abs.html"),
-  ("abs", "complex/abs.html"),
-  ("acos", "acos.html"),
-  ("acosh", "acosh.html"),
-  ("as_bytes", "as_bytes.html"),
+  ("abs", "abs.html", True),
+  ("abs", "complex/abs.html", True),
+  ("acos", "acos.html", False),
+  ("acosh", "acosh.html", False),
+  ("as_bytes", "as_bytes.html", False),
 ]
 self.assertEqual(len(actual), len(expected))
 for i in range(0, len(actual)):
   self.assertEqual(expected[i][0], actual[i][0])
   self.assertTrue(actual[i][1].endswith(expected[i][1]))
+  self.assertEqual(expected[i][2], actual[i][2])
 
 
   def testParseSymbolPage_SingleHeader(self):
Index: clangd/include-mapping/gen_std.py
===
--- clangd/include-mapping/gen_std.py
+++ clangd/include-mapping/gen_std.py
@@ -28,7 +28,7 @@
gen_std.py -cppreference  > StdSymbolMap.inc
 """
 
-from bs4 import BeautifulSoup
+from bs4 import BeautifulSoup, NavigableString
 
 import argparse
 import collections
@@ -82,15 +82,21 @@
   abs() (int) 
   acos() 
 
-  Returns a list of tuple (symbol_name, relative_path_to_symbol_page).
+  Returns a list of tuple (symbol_name, relative_path_to_symbol_page, variant).
   """
   symbols = []
   soup = BeautifulSoup(index_page_html, "html.parser")
   for symbol_href in soup.select("a[title]"):
+# Ignore annotated symbols like "acos<>() (std::complex)".
+# These tend to be overloads, and we the primary is more useful.
+# This accidentally accepts begin/end despite the (iterator) caption: the
+# (since C++11) note is first. They are good symbols, so the bug is unfixed.
+caption = symbol_href.next_sibling
+variant = isinstance(caption, NavigableString) and "(" in caption
 symbol_tt = symbol_href.find("tt")
 if symbol_tt:
   symbols.append((symbol_tt.text.rstrip("<>()"), # strip any trailing <>()
-  symbol_href["href"]))
+  symbol_href["href"], variant))
   return symbols
 
 class Symbol:
@@ -125,7 +131,11 @@
   with open(index_page_path, "r") as f:
 # Read each symbol page in parallel.
 results = [] # (symbol_name, promise of [header...])
-for symbol_name, symbol_page_path in ParseIndexPage(f.read()):
+for symbol_name, symbol_page_path, variant in ParseIndexPage(f.read()):
+  # Variant symbols (e.g. the std::locale version of isalpha) add ambiguity.
+  # FIXME: use these as a fallback rather than ignoring entirely.
+  if variant:
+continue
   path = os.path.join(root_dir, symbol_page_path)
   results.append((symbol_name,
   pool.apply_async(ReadSymbolPage, (path, symbol_name
Index: clangd/StdSymbolMap.inc
===
--- clangd/StdSymbolMap.inc
+++ clangd/StdSymbolMap.inc
@@ -42,6 +42,8 @@
 SYMBOL(UnsignedIntegral, std::, )
 SYMBOL(_Exit, std::, )
 SYMBOL(accumulate, std::, )
+SYMBOL(acos, std::, )
+SYMBOL(acosh, std::, )
 SYMBOL(add_const, std::, )
 SYMBOL(add_const_t, std::, )
 SYMBOL(add_cv, std::, )
@@ -82,8 +84,13 @@
 SYMBOL(array, std::, )
 SYMBOL(as_const, std::, )
 SYMBOL(asctime, std::, )
+SYMBOL(asin, std::, )
+SYMBOL(asinh, std::, )
 SYMBOL(async, std::, )
 SYMBOL(at_quick_exit, std::, )
+SYMBOL(atan, std::, )
+SYMBOL(atan2, std::, )
+SYMBOL(atanh, std::, )
 SYMBOL(atexit, std::, )
 SYMBOL(atof, std::, )
 SYMBOL(atoi, std::, )
@@ -220,6 +227,8 @@
 SYMBOL(copy_if, std::, )
 SYMBOL(copy_n, std::, )
 SYMBOL(copysign, std::, )
+SYMBOL(cos, std::, )
+SYMBOL(cosh, std::, )
 SYMBOL(count, std::, )
 SYMBOL(count_if, std::, )
 SYMBOL(cout, std::, )
@@ -292,6 +301,7 @@
 SYMBOL(exchange, std::, )
 SYMBOL(exclusive_scan, std::, )
 SYMBOL(exit, std::, )
+SYMBOL(exp, std::, )
 SYMBOL(exp2, std::, )
 SYMBOL(expm1, std::, )
 SYMBOL(exponential_distribution, std::, )
@@ -609,20 +619,31 @@
 SYMBOL(is_void_v, std::, )
 SYMBOL(is_volatile, std::, )
 SYMBOL(is_volatile_v, std::, )
+SYMBOL(isalnum, std::, )
+SYMBOL(isalpha, std::, )
+SYMBOL(isblank, std::, )
+SYMBOL(iscntrl, std::, )
+SYMBOL(isdigit, std::, )
 SYMBOL(isfinite, std::, )
+SYMBOL(isgraph, std::, )
 SYMBOL(isgreater, std::, )
 SYMBOL(isgreaterequal, std::, )
 SYMBOL(isinf, std::, )
 SYMBOL(isless, std::, )
 SYMBOL(islessequal, std::, )
 SYMBOL(islessgreater, std::

[PATCH] D60937: [clangd] Fix code completion of macros defined in the preamble region of the main file.

2019-05-02 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM.

I suggest considering a more direct way to solve the same problem: we could 
collect symbols for the main-file macros when building the preamble and store 
them in `PreambleData` (or somewhere else with the same lifetime).
I don't see any reasons why the current approach won't work, though, so looks 
ok too.




Comment at: unittests/clangd/CodeCompleteTests.cpp:2081
+  R"cpp(#include "foo.h"
+  define CLANGD_PREAMBLE_MAIN x
 

are we missing `#` here?


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D60937



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


[PATCH] D61276: [clang-format] Fix bug in block comment reflow that joins * and /

2019-05-02 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 197720.
owenpan added a comment.

Updated the patch to cover all scenarios in which the bug might be triggered.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61276

Files:
  clang/lib/Format/BreakableToken.cpp
  clang/lib/Format/BreakableToken.h
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -11137,6 +11137,24 @@
   FormatStyle Style = getLLVMStyle();
   Style.ColumnLimit = 20;
 
+  // See PR41213
+  EXPECT_EQ("/*\n"
+" *\t456789012345678\n"
+" * /x\n"
+" */",
+format("/*\n"
+   " *\t456789012345678 /x\n"
+   " */",
+   Style));
+  EXPECT_EQ("/*\n"
+" *3456789012345678\n"
+" * /x\n"
+" */",
+format("/*\n"
+   " *3456789012345678 /x\n"
+   " */",
+   Style));
+
   verifyFormat("int a; // the\n"
"   // comment", Style);
   EXPECT_EQ("int a; /* first line\n"
Index: clang/lib/Format/BreakableToken.h
===
--- clang/lib/Format/BreakableToken.h
+++ clang/lib/Format/BreakableToken.h
@@ -361,6 +361,9 @@
 bool InPPDirective, encoding::Encoding Encoding,
 const FormatStyle &Style, bool UseCRLF);
 
+  Split getSplit(unsigned LineIndex, unsigned TailOffset, unsigned ColumnLimit,
+ unsigned ContentStartColumn,
+ llvm::Regex &CommentPragmasRegex) const override;
   unsigned getRangeLength(unsigned LineIndex, unsigned Offset,
   StringRef::size_type Length,
   unsigned StartColumn) const override;
Index: clang/lib/Format/BreakableToken.cpp
===
--- clang/lib/Format/BreakableToken.cpp
+++ clang/lib/Format/BreakableToken.cpp
@@ -65,7 +65,8 @@
 static BreakableToken::Split
 getCommentSplit(StringRef Text, unsigned ContentStartColumn,
 unsigned ColumnLimit, unsigned TabWidth,
-encoding::Encoding Encoding, const FormatStyle &Style) {
+encoding::Encoding Encoding, const FormatStyle &Style,
+bool DecorationEndsWithStar = false) {
   LLVM_DEBUG(llvm::dbgs() << "Comment split: \"" << Text
   << "\", Column limit: " << ColumnLimit
   << ", Content start: " << ContentStartColumn << 
"\n");
@@ -123,7 +124,10 @@
 if (SpaceOffset == 1 && Text[SpaceOffset - 1] == '*')
   return BreakableToken::Split(StringRef::npos, 0);
 StringRef BeforeCut = Text.substr(0, SpaceOffset).rtrim(Blanks);
-StringRef AfterCut = Text.substr(SpaceOffset).ltrim(Blanks);
+StringRef AfterCut = Text.substr(SpaceOffset);
+// Don't trim the leading blanks if it would create a */ after the break.
+if (!DecorationEndsWithStar || AfterCut.size() <= 1 || AfterCut[1] != '/')
+  AfterCut = AfterCut.ltrim(Blanks);
 return BreakableToken::Split(BeforeCut.size(),
  AfterCut.begin() - BeforeCut.end());
   }
@@ -452,6 +456,18 @@
   });
 }
 
+BreakableToken::Split
+BreakableBlockComment::getSplit(unsigned LineIndex, unsigned TailOffset,
+   unsigned ColumnLimit, unsigned ContentStartColumn,
+   llvm::Regex &CommentPragmasRegex) const {
+  // Don't break lines matching the comment pragmas regex.
+  if (CommentPragmasRegex.match(Content[LineIndex]))
+return Split(StringRef::npos, 0);
+  return getCommentSplit(Content[LineIndex].substr(TailOffset),
+ ContentStartColumn, ColumnLimit, Style.TabWidth,
+ Encoding, Style, Decoration.endswith("*"));
+}
+
 void BreakableBlockComment::adjustWhitespace(unsigned LineIndex,
  int IndentDelta) {
   // When in a preprocessor directive, the trailing backslash in a block 
comment


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -11137,6 +11137,24 @@
   FormatStyle Style = getLLVMStyle();
   Style.ColumnLimit = 20;
 
+  // See PR41213
+  EXPECT_EQ("/*\n"
+" *\t456789012345678\n"
+" * /x\n"
+" */",
+format("/*\n"
+   " *\t456789012345678 /x\n"
+   " */",
+   Style));
+  EXPECT_EQ("/*\n"
+" *3456789012345678\n"
+" * /x\n"
+" */",
+format("/*\n"
+   " *3456789012345678

[PATCH] D60934: [clang] adding explicit(bool) from c++2a

2019-05-02 Thread Tyker via Phabricator via cfe-commits
Tyker added inline comments.



Comment at: clang/lib/Sema/SemaInit.cpp:9361
 // Only consider converting constructors.
-if (GD->isExplicit())
+if (!GD->isMaybeNotExplicit())
   continue;

rsmith wrote:
> Tyker wrote:
> > rsmith wrote:
> > > Tyker wrote:
> > > > rsmith wrote:
> > > > > Tyker wrote:
> > > > > > rsmith wrote:
> > > > > > > We need to substitute into the deduction guide first to detect 
> > > > > > > whether it forms a "converting constructor", and that will need 
> > > > > > > to be done inside `AddTemplateOverloadCandidate`.
> > > > > > similarly as the previous if. this check removes deduction guide 
> > > > > > that are already resolve to be explicit when we are in a context 
> > > > > > that doesn't allow explicit.
> > > > > > every time the explicitness was checked before my change i replaced 
> > > > > > it by a check that removes already resolved explicit specifiers.
> > > > > Unlike in the previous case, we do //not// yet pass an 
> > > > > `AllowExplicit` flag into `AddTemplateOverloadCandidate` here, so 
> > > > > this will incorrectly allow dependent //explicit-specifier//s that 
> > > > > evaluate to `true` in copy-initialization contexts.
> > > > the default value for `AllowExplicit` is false. so the conversion will 
> > > > be removed in `AddTemplateOverloadCandidate`.
> > > That doesn't sound right: that'd mean we never use explicit deduction 
> > > guides (we never pass `AllowExplicit = true` to 
> > > `AddTemplateOverloadCandidate`). Do we have any test coverage that 
> > > demonstrates that conditionally-explicit deduction guides are handled 
> > > properly?
> > my mistake. the default value for AllowExplicit is false. but 
> > AddTemplateOverloadCandidate will only remove conversions and constructors. 
> > dependent explicit specifier that are resolved to true on deduction guides 
> > are removed at line 9480. they are not removed from the overload set. CTAD 
> > just fails if a explicit deduction guide is selected in a CopyInitList. i 
> > agree this is weird but the behavior is the same as before the patch.
> > the result on clang is:
> > ```
> > template
> > struct A {
> >   explicit A(T);
> > };
> > A a = 0; // error with explicit constructor meaning CTAD succeed.
> > A a = { 0 }; // error with explicit deduction guide
> > ```
> > all compiler don't agree on this https://godbolt.org/z/ElHlkE. icc and 
> > clang have this behavior, gcc and msvc fail at CTAD time on both 
> > initialization. as of what the standard say from what i read, it isn't 
> > clear, the standard is clear when calling an explicit constructor should 
> > fail. but it doesn't appear to say for deduction guides.
> > as this was the previous behavior i did not change it with explicit(bool).
> > the standard is clear when calling an explicit constructor should fail. but 
> > it doesn't appear to say for deduction guides
> 
> The standard says that you take the set of deduction guides and notionally 
> form a set of constructors from them (see [over.match.class.deduct]). So the 
> constructor rules apply to deduction guides too.
> 
> > as this was the previous behavior i did not change it with explicit(bool).
> 
> I don't think that's correct. We filter out explicit deduction guides for 
> non-list copy-initialization on line ~9239 (prior to this change). Today we 
> get this result:
> 
> ```
> template struct X { X(int); };
> 
> explicit X(int) -> X; // #1
> 
> X a = 0; // error: no viable deduction guide, #1 is not a candidate
> X b = {0}; // error: selected explicit deduction guide #1
> X c{0}; // ok
> X d(0); // ok
> ```
> 
> ... which is correct. If we change the deduction guide to have a dependent 
> `explicit(bool)` specifier:
> 
> ```
> template
> explicit(E) X(int) -> X;
> ```
> 
> ... we should get the same result, but I think we won't get that result with 
> this patch: I think we'll incorrectly select an explicit deduction guide for 
> the declaration of `a`, because we never filter out explicit deduction guides.
> 
> `DeduceTemplateSpecializationFromInitializer` should compute an 
> `AllowExplicit` flag (`= !Kind.isCopyInit() || ListInit`), pass it into 
> `AddTemplateOverloadCandidate`, and that should filter out explicit deduction 
> guide specializations if it's `true`.
there was an issue. now fixed.



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

https://reviews.llvm.org/D60934



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


[PATCH] D61316: [clangd] Improvements to header mapping: more precise parsing of cppreference symbol pages.

2019-05-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D61316



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


[PATCH] D61349: [clangd] Standard library mapping: prefer "primary" versions of functions over variants.

2019-05-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D61349



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


[clang-tools-extra] r359770 - [clangd] Standard library mapping: prefer "primary" versions of functions over variants.

2019-05-02 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Thu May  2 02:31:24 2019
New Revision: 359770

URL: http://llvm.org/viewvc/llvm-project?rev=359770&view=rev
Log:
[clangd] Standard library mapping: prefer "primary" versions of functions over 
variants.

Reviewers: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/StdSymbolMap.inc
clang-tools-extra/trunk/clangd/include-mapping/gen_std.py
clang-tools-extra/trunk/clangd/include-mapping/test.py

Modified: clang-tools-extra/trunk/clangd/StdSymbolMap.inc
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/StdSymbolMap.inc?rev=359770&r1=359769&r2=359770&view=diff
==
--- clang-tools-extra/trunk/clangd/StdSymbolMap.inc (original)
+++ clang-tools-extra/trunk/clangd/StdSymbolMap.inc Thu May  2 02:31:24 2019
@@ -42,6 +42,8 @@ SYMBOL(UniformRandomBitGenerator, std::,
 SYMBOL(UnsignedIntegral, std::, )
 SYMBOL(_Exit, std::, )
 SYMBOL(accumulate, std::, )
+SYMBOL(acos, std::, )
+SYMBOL(acosh, std::, )
 SYMBOL(add_const, std::, )
 SYMBOL(add_const_t, std::, )
 SYMBOL(add_cv, std::, )
@@ -82,8 +84,13 @@ SYMBOL(arg, std::, )
 SYMBOL(array, std::, )
 SYMBOL(as_const, std::, )
 SYMBOL(asctime, std::, )
+SYMBOL(asin, std::, )
+SYMBOL(asinh, std::, )
 SYMBOL(async, std::, )
 SYMBOL(at_quick_exit, std::, )
+SYMBOL(atan, std::, )
+SYMBOL(atan2, std::, )
+SYMBOL(atanh, std::, )
 SYMBOL(atexit, std::, )
 SYMBOL(atof, std::, )
 SYMBOL(atoi, std::, )
@@ -220,6 +227,8 @@ SYMBOL(copy_backward, std::, 
 SYMBOL(copy_if, std::, )
 SYMBOL(copy_n, std::, )
 SYMBOL(copysign, std::, )
+SYMBOL(cos, std::, )
+SYMBOL(cosh, std::, )
 SYMBOL(count, std::, )
 SYMBOL(count_if, std::, )
 SYMBOL(cout, std::, )
@@ -292,6 +301,7 @@ SYMBOL(exception_ptr, std::, 
 SYMBOL(exchange, std::, )
 SYMBOL(exclusive_scan, std::, )
 SYMBOL(exit, std::, )
+SYMBOL(exp, std::, )
 SYMBOL(exp2, std::, )
 SYMBOL(expm1, std::, )
 SYMBOL(exponential_distribution, std::, )
@@ -609,20 +619,31 @@ SYMBOL(is_void, std::, )
 SYMBOL(is_void_v, std::, )
 SYMBOL(is_volatile, std::, )
 SYMBOL(is_volatile_v, std::, )
+SYMBOL(isalnum, std::, )
+SYMBOL(isalpha, std::, )
+SYMBOL(isblank, std::, )
+SYMBOL(iscntrl, std::, )
+SYMBOL(isdigit, std::, )
 SYMBOL(isfinite, std::, )
+SYMBOL(isgraph, std::, )
 SYMBOL(isgreater, std::, )
 SYMBOL(isgreaterequal, std::, )
 SYMBOL(isinf, std::, )
 SYMBOL(isless, std::, )
 SYMBOL(islessequal, std::, )
 SYMBOL(islessgreater, std::, )
+SYMBOL(islower, std::, )
 SYMBOL(isnan, std::, )
 SYMBOL(isnormal, std::, )
 SYMBOL(ispow2, std::, )
+SYMBOL(isprint, std::, )
+SYMBOL(ispunct, std::, )
+SYMBOL(isspace, std::, )
 SYMBOL(istream_iterator, std::, )
 SYMBOL(istreambuf_iterator, std::, )
 SYMBOL(istringstream, std::, )
 SYMBOL(isunordered, std::, )
+SYMBOL(isupper, std::, )
 SYMBOL(iswalnum, std::, )
 SYMBOL(iswalpha, std::, )
 SYMBOL(iswblank, std::, )
@@ -636,6 +657,7 @@ SYMBOL(iswpunct, std::, )
 SYMBOL(iswspace, std::, )
 SYMBOL(iswupper, std::, )
 SYMBOL(iswxdigit, std::, )
+SYMBOL(isxdigit, std::, )
 SYMBOL(iter_swap, std::, )
 SYMBOL(iterator, std::, )
 SYMBOL(iterator_traits, std::, )
@@ -663,6 +685,8 @@ SYMBOL(localeconv, std::, )
 SYMBOL(localtime, std::, )
 SYMBOL(lock, std::, )
 SYMBOL(lock_guard, std::, )
+SYMBOL(log, std::, )
+SYMBOL(log10, std::, )
 SYMBOL(log1p, std::, )
 SYMBOL(log2, std::, )
 SYMBOL(log2p1, std::, )
@@ -824,6 +848,7 @@ SYMBOL(poisson_distribution, std::, )
 SYMBOL(polymorphic_allocator, std::, )
 SYMBOL(pop_heap, std::, )
+SYMBOL(pow, std::, )
 SYMBOL(prev, std::, )
 SYMBOL(prev_permutation, std::, )
 SYMBOL(printf, std::, )
@@ -886,6 +911,7 @@ SYMBOL(regex_token_iterator, std::, )
 SYMBOL(reinterpret_pointer_cast, std::, )
 SYMBOL(remainder, std::, )
+SYMBOL(remove, std::, )
 SYMBOL(remove_all_extents, std::, )
 SYMBOL(remove_all_extents_t, std::, )
 SYMBOL(remove_const, std::, )
@@ -970,6 +996,8 @@ SYMBOL(shuffle_order_engine, std::, )
 SYMBOL(signal, std::, )
 SYMBOL(signbit, std::, )
+SYMBOL(sin, std::, )
+SYMBOL(sinh, std::, )
 SYMBOL(size, std::, )
 SYMBOL(skipws, std::, )
 SYMBOL(slice, std::, )
@@ -980,6 +1008,7 @@ SYMBOL(sort, std::, )
 SYMBOL(sort_heap, std::, )
 SYMBOL(span, std::, )
 SYMBOL(sprintf, std::, )
+SYMBOL(sqrt, std::, )
 SYMBOL(srand, std::, )
 SYMBOL(sregex_iterator, std::, )
 SYMBOL(sregex_token_iterator, std::, )
@@ -1038,6 +1067,8 @@ SYMBOL(syncbuf, std::, )
 SYMBOL(system, std::, )
 SYMBOL(system_category, std::, )
 SYMBOL(system_error, std::, )
+SYMBOL(tan, std::, )
+SYMBOL(tanh, std::, )
 SYMBOL(tera, std::, )
 SYMBOL(terminate, std::, )
 SYMBOL(terminate_handler, std::, )
@@ -1062,6 +1093,8 @@ SYMBOL(to_address, std::, )
 SYMBOL(to_chars, std::, )
 SYMBOL(to_integer, std::, )
 SYMBOL(to_string, std::, )
+SYMBOL(tolower, std::, )
+SYMBOL(toupper, std::, )
 SYMBOL(towctrans, std::, )
 SYMBOL(towlower, std::, )
 SYMBOL(towupper

[PATCH] D61349: [clangd] Standard library mapping: prefer "primary" versions of functions over variants.

2019-05-02 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE359770: [clangd] Standard library mapping: prefer 
"primary" versions of functions over… (authored by sammccall, 
committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D61349?vs=197719&id=197723#toc

Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D61349

Files:
  clangd/StdSymbolMap.inc
  clangd/include-mapping/gen_std.py
  clangd/include-mapping/test.py

Index: clangd/StdSymbolMap.inc
===
--- clangd/StdSymbolMap.inc
+++ clangd/StdSymbolMap.inc
@@ -42,6 +42,8 @@
 SYMBOL(UnsignedIntegral, std::, )
 SYMBOL(_Exit, std::, )
 SYMBOL(accumulate, std::, )
+SYMBOL(acos, std::, )
+SYMBOL(acosh, std::, )
 SYMBOL(add_const, std::, )
 SYMBOL(add_const_t, std::, )
 SYMBOL(add_cv, std::, )
@@ -82,8 +84,13 @@
 SYMBOL(array, std::, )
 SYMBOL(as_const, std::, )
 SYMBOL(asctime, std::, )
+SYMBOL(asin, std::, )
+SYMBOL(asinh, std::, )
 SYMBOL(async, std::, )
 SYMBOL(at_quick_exit, std::, )
+SYMBOL(atan, std::, )
+SYMBOL(atan2, std::, )
+SYMBOL(atanh, std::, )
 SYMBOL(atexit, std::, )
 SYMBOL(atof, std::, )
 SYMBOL(atoi, std::, )
@@ -220,6 +227,8 @@
 SYMBOL(copy_if, std::, )
 SYMBOL(copy_n, std::, )
 SYMBOL(copysign, std::, )
+SYMBOL(cos, std::, )
+SYMBOL(cosh, std::, )
 SYMBOL(count, std::, )
 SYMBOL(count_if, std::, )
 SYMBOL(cout, std::, )
@@ -292,6 +301,7 @@
 SYMBOL(exchange, std::, )
 SYMBOL(exclusive_scan, std::, )
 SYMBOL(exit, std::, )
+SYMBOL(exp, std::, )
 SYMBOL(exp2, std::, )
 SYMBOL(expm1, std::, )
 SYMBOL(exponential_distribution, std::, )
@@ -609,20 +619,31 @@
 SYMBOL(is_void_v, std::, )
 SYMBOL(is_volatile, std::, )
 SYMBOL(is_volatile_v, std::, )
+SYMBOL(isalnum, std::, )
+SYMBOL(isalpha, std::, )
+SYMBOL(isblank, std::, )
+SYMBOL(iscntrl, std::, )
+SYMBOL(isdigit, std::, )
 SYMBOL(isfinite, std::, )
+SYMBOL(isgraph, std::, )
 SYMBOL(isgreater, std::, )
 SYMBOL(isgreaterequal, std::, )
 SYMBOL(isinf, std::, )
 SYMBOL(isless, std::, )
 SYMBOL(islessequal, std::, )
 SYMBOL(islessgreater, std::, )
+SYMBOL(islower, std::, )
 SYMBOL(isnan, std::, )
 SYMBOL(isnormal, std::, )
 SYMBOL(ispow2, std::, )
+SYMBOL(isprint, std::, )
+SYMBOL(ispunct, std::, )
+SYMBOL(isspace, std::, )
 SYMBOL(istream_iterator, std::, )
 SYMBOL(istreambuf_iterator, std::, )
 SYMBOL(istringstream, std::, )
 SYMBOL(isunordered, std::, )
+SYMBOL(isupper, std::, )
 SYMBOL(iswalnum, std::, )
 SYMBOL(iswalpha, std::, )
 SYMBOL(iswblank, std::, )
@@ -636,6 +657,7 @@
 SYMBOL(iswspace, std::, )
 SYMBOL(iswupper, std::, )
 SYMBOL(iswxdigit, std::, )
+SYMBOL(isxdigit, std::, )
 SYMBOL(iter_swap, std::, )
 SYMBOL(iterator, std::, )
 SYMBOL(iterator_traits, std::, )
@@ -663,6 +685,8 @@
 SYMBOL(localtime, std::, )
 SYMBOL(lock, std::, )
 SYMBOL(lock_guard, std::, )
+SYMBOL(log, std::, )
+SYMBOL(log10, std::, )
 SYMBOL(log1p, std::, )
 SYMBOL(log2, std::, )
 SYMBOL(log2p1, std::, )
@@ -824,6 +848,7 @@
 SYMBOL(polar, std::, )
 SYMBOL(polymorphic_allocator, std::, )
 SYMBOL(pop_heap, std::, )
+SYMBOL(pow, std::, )
 SYMBOL(prev, std::, )
 SYMBOL(prev_permutation, std::, )
 SYMBOL(printf, std::, )
@@ -886,6 +911,7 @@
 SYMBOL(regex_traits, std::, )
 SYMBOL(reinterpret_pointer_cast, std::, )
 SYMBOL(remainder, std::, )
+SYMBOL(remove, std::, )
 SYMBOL(remove_all_extents, std::, )
 SYMBOL(remove_all_extents_t, std::, )
 SYMBOL(remove_const, std::, )
@@ -970,6 +996,8 @@
 SYMBOL(sig_atomic_t, std::, )
 SYMBOL(signal, std::, )
 SYMBOL(signbit, std::, )
+SYMBOL(sin, std::, )
+SYMBOL(sinh, std::, )
 SYMBOL(size, std::, )
 SYMBOL(skipws, std::, )
 SYMBOL(slice, std::, )
@@ -980,6 +1008,7 @@
 SYMBOL(sort_heap, std::, )
 SYMBOL(span, std::, )
 SYMBOL(sprintf, std::, )
+SYMBOL(sqrt, std::, )
 SYMBOL(srand, std::, )
 SYMBOL(sregex_iterator, std::, )
 SYMBOL(sregex_token_iterator, std::, )
@@ -1038,6 +1067,8 @@
 SYMBOL(system, std::, )
 SYMBOL(system_category, std::, )
 SYMBOL(system_error, std::, )
+SYMBOL(tan, std::, )
+SYMBOL(tanh, std::, )
 SYMBOL(tera, std::, )
 SYMBOL(terminate, std::, )
 SYMBOL(terminate_handler, std::, )
@@ -1062,6 +1093,8 @@
 SYMBOL(to_chars, std::, )
 SYMBOL(to_integer, std::, )
 SYMBOL(to_string, std::, )
+SYMBOL(tolower, std::, )
+SYMBOL(toupper, std::, )
 SYMBOL(towctrans, std::, )
 SYMBOL(towlower, std::, )
 SYMBOL(towupper, std::, )
@@ -1118,6 +1151,7 @@
 SYMBOL(upper_bound, std::, )
 SYMBOL(uppercase, std::, )
 SYMBOL(use_facet, std::, )
+SYMBOL(uses_allocator, std::, )
 SYMBOL(uses_allocator_v, std::, )
 SYMBOL(va_list, std::, )
 SYMBOL(valarray, std::, )
Index: clangd/include-mapping/gen_std.py
===
--- clangd/include-mapping/gen_std.py
+++ clangd/include-mapping/gen_std.py
@@ -28,7 +28,7 @@
gen_std.py -cppreference  > StdSymbolMap.inc
 """
 
-from bs4 import BeautifulSoup
+from bs4 import BeautifulSoup, NavigableStri

[clang-tools-extra] r359771 - [clangd] Improvements to header mapping: more precise parsing of cppreference symbol pages.

2019-05-02 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Thu May  2 02:34:30 2019
New Revision: 359771

URL: http://llvm.org/viewvc/llvm-project?rev=359771&view=rev
Log:
[clangd] Improvements to header mapping: more precise parsing of cppreference 
symbol pages.

Summary:
Previously we were just jumping from the symbol index to the symbol page, and
grabbing all the headers mentioned there. But the page often lists multiple
symbols, and so we got false positives and thus ambiguities (which were 
dropped).

Now we look at which declarations are for the symbol we want, and prefer headers
listed above that symbol. If there are none, we fall back to the old behavior.

Reviewers: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/StdSymbolMap.inc
clang-tools-extra/trunk/clangd/include-mapping/gen_std.py
clang-tools-extra/trunk/clangd/include-mapping/test.py

Modified: clang-tools-extra/trunk/clangd/StdSymbolMap.inc
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/StdSymbolMap.inc?rev=359771&r1=359770&r2=359771&view=diff
==
--- clang-tools-extra/trunk/clangd/StdSymbolMap.inc (original)
+++ clang-tools-extra/trunk/clangd/StdSymbolMap.inc Thu May  2 02:34:30 2019
@@ -141,12 +141,15 @@ SYMBOL(bad_typeid, std::, )
 SYMBOL(bad_variant_access, std::, )
 SYMBOL(bad_weak_ptr, std::, )
 SYMBOL(basic_common_reference, std::, )
+SYMBOL(basic_filebuf, std::, )
 SYMBOL(basic_fstream, std::, )
 SYMBOL(basic_ifstream, std::, )
 SYMBOL(basic_ios, std::, )
 SYMBOL(basic_iostream, std::, )
+SYMBOL(basic_istream, std::, )
 SYMBOL(basic_istringstream, std::, )
 SYMBOL(basic_ofstream, std::, )
+SYMBOL(basic_ostream, std::, )
 SYMBOL(basic_ostringstream, std::, )
 SYMBOL(basic_osyncstream, std::, )
 SYMBOL(basic_regex, std::, )
@@ -200,6 +203,7 @@ SYMBOL(cmatch, std::, )
 SYMBOL(codecvt, std::, )
 SYMBOL(codecvt_base, std::, )
 SYMBOL(codecvt_byname, std::, )
+SYMBOL(codecvt_mode, std::, )
 SYMBOL(codecvt_utf16, std::, )
 SYMBOL(codecvt_utf8, std::, )
 SYMBOL(codecvt_utf8_utf16, std::, )
@@ -254,6 +258,7 @@ SYMBOL(declare_no_pointers, std::, )
 SYMBOL(declval, std::, )
 SYMBOL(default_delete, std::, )
+SYMBOL(default_random_engine, std::, )
 SYMBOL(default_searcher, std::, )
 SYMBOL(defaultfloat, std::, )
 SYMBOL(defer_lock, std::, )
@@ -273,8 +278,10 @@ SYMBOL(discrete_distribution, std::, )
 SYMBOL(disjunction_v, std::, )
 SYMBOL(distance, std::, )
+SYMBOL(div_t, std::, )
 SYMBOL(divides, std::, )
 SYMBOL(domain_error, std::, )
+SYMBOL(double_t, std::, )
 SYMBOL(dynamic_extent, std::, )
 SYMBOL(dynamic_pointer_cast, std::, )
 SYMBOL(emit_on_flush, std::, )
@@ -333,6 +340,7 @@ SYMBOL(fgetpos, std::, )
 SYMBOL(fgets, std::, )
 SYMBOL(fgetwc, std::, )
 SYMBOL(fgetws, std::, )
+SYMBOL(filebuf, std::, )
 SYMBOL(fill, std::, )
 SYMBOL(fill_n, std::, )
 SYMBOL(find, std::, )
@@ -344,6 +352,7 @@ SYMBOL(fisher_f_distribution, std::, )
 SYMBOL(float_denorm_style, std::, )
 SYMBOL(float_round_style, std::, )
+SYMBOL(float_t, std::, )
 SYMBOL(floor, std::, )
 SYMBOL(floor2, std::, )
 SYMBOL(flush, std::, )
@@ -432,6 +441,9 @@ SYMBOL(ifstream, std::, )
 SYMBOL(ignore, std::, )
 SYMBOL(ilogb, std::, )
 SYMBOL(imag, std::, )
+SYMBOL(imaxabs, std::, )
+SYMBOL(imaxdiv, std::, )
+SYMBOL(imaxdiv_t, std::, )
 SYMBOL(in_place, std::, )
 SYMBOL(in_place_index, std::, )
 SYMBOL(in_place_index_t, std::, )
@@ -450,6 +462,8 @@ SYMBOL(inserter, std::, )
 SYMBOL(integer_sequence, std::, )
 SYMBOL(integral_constant, std::, )
 SYMBOL(internal, std::, )
+SYMBOL(intmax_t, std::, )
+SYMBOL(intptr_t, std::, )
 SYMBOL(invalid_argument, std::, )
 SYMBOL(invoke, std::, )
 SYMBOL(invoke_result, std::, )
@@ -639,6 +653,7 @@ SYMBOL(ispow2, std::, )
 SYMBOL(isprint, std::, )
 SYMBOL(ispunct, std::, )
 SYMBOL(isspace, std::, )
+SYMBOL(istream, std::, )
 SYMBOL(istream_iterator, std::, )
 SYMBOL(istreambuf_iterator, std::, )
 SYMBOL(istringstream, std::, )
@@ -664,11 +679,15 @@ SYMBOL(iterator_traits, std::, )
 SYMBOL(kill_dependency, std::, )
 SYMBOL(kilo, std::, )
+SYMBOL(knuth_b, std::, )
+SYMBOL(labs, std::, )
 SYMBOL(launch, std::, )
 SYMBOL(launder, std::, )
 SYMBOL(lcm, std::, )
 SYMBOL(lconv, std::, )
 SYMBOL(ldexp, std::, )
+SYMBOL(ldiv, std::, )
+SYMBOL(ldiv_t, std::, )
 SYMBOL(left, std::, )
 SYMBOL(length_error, std::, )
 SYMBOL(less, std::, )
@@ -678,6 +697,9 @@ SYMBOL(lexicographical_compare_3way, std
 SYMBOL(lgamma, std::, )
 SYMBOL(linear_congruential_engine, std::, )
 SYMBOL(list, std::, )
+SYMBOL(llabs, std::, )
+SYMBOL(lldiv, std::, )
+SYMBOL(lldiv_t, std::, )
 SYMBOL(llrint, std::, )
 SYMBOL(llround, std::, )
 SYMBOL(locale, std::, )
@@ -755,6 +777,8 @@ SYMBOL(min, std::, )
 SYMBOL(min_element, std::, )
 SYMBOL(minmax, std::, )
 SYMBOL(minmax_element, std::, )
+SYMBOL(minstd_rand, std::, )
+SYMBOL(minstd_rand0, std::, )
 SYMBOL(minus, std::,

[PATCH] D61316: [clangd] Improvements to header mapping: more precise parsing of cppreference symbol pages.

2019-05-02 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE359771: [clangd] Improvements to header mapping: more 
precise parsing of cppreference… (authored by sammccall, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D61316?vs=197717&id=197724#toc

Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D61316

Files:
  clangd/StdSymbolMap.inc
  clangd/include-mapping/gen_std.py
  clangd/include-mapping/test.py

Index: clangd/include-mapping/gen_std.py
===
--- clangd/include-mapping/gen_std.py
+++ clangd/include-mapping/gen_std.py
@@ -35,6 +35,7 @@
 import datetime
 import multiprocessing
 import os
+import re
 import signal
 import sys
 
@@ -50,7 +51,13 @@
 //===--===//
 """
 
-def ParseSymbolPage(symbol_page_html):
+def HasClass(tag, *classes):
+  for c in tag.get('class', []):
+if c in classes:
+  return True
+  return False
+
+def ParseSymbolPage(symbol_page_html, symbol_name):
   """Parse symbol page and retrieve the include header defined in this page.
   The symbol page provides header for the symbol, specifically in
   "Defined in header " section. An example:
@@ -61,17 +68,43 @@
 
   Returns a list of headers.
   """
-  headers = []
+  headers = set()
+  all_headers = set()
 
   soup = BeautifulSoup(symbol_page_html, "html.parser")
-  #  "Defined in header " are defined in  or
-  #  .
-  for header_tr in soup.select('tr.t-dcl-header,tr.t-dsc-header'):
-if "Defined in header " in header_tr.text:
-  # The interesting header content (e.g. ) is wrapped in .
-  for header_code in header_tr.find_all("code"):
-headers.append(header_code.text)
-  return headers
+  # Rows in table are like:
+  #   Defined in header   .t-dsc-header
+  #   Defined in header   .t-dsc-header
+  #   decl1.t-dcl
+  #   Defined in header   .t-dsc-header
+  #   decl2.t-dcl
+  for table in soup.select('table.t-dcl-begin, table.t-dsc-begin'):
+current_headers = []
+was_decl = False
+for row in table.select('tr'):
+  if HasClass(row, 't-dcl', 't-dsc'):
+was_decl = True
+# Declaration is in the first cell.
+text = row.find('td').text
+# Decl may not be for the symbol name we're looking for.
+if not re.search("\\b%s\\b" % symbol_name, text):
+  continue
+headers.update(current_headers)
+  elif HasClass(row, 't-dsc-header'):
+# If we saw a decl since the last header, this is a new block of headers
+# for a new block of decls.
+if was_decl:
+  current_headers = []
+was_decl = False
+# There are also .t-dsc-header for "defined in namespace".
+if not "Defined in header " in row.text:
+  continue
+# The interesting header content (e.g. ) is wrapped in .
+for header_code in row.find_all("code"):
+  current_headers.append(header_code.text)
+  all_headers.add(header_code.text)
+  # If the symbol was never named, consider all named headers.
+  return headers or all_headers
 
 
 def ParseIndexPage(index_page_html):
@@ -112,7 +145,7 @@
 
 def ReadSymbolPage(path, name):
   with open(path) as f:
-return ParseSymbolPage(f.read())
+return ParseSymbolPage(f.read(), name)
 
 
 def GetSymbols(pool, root_dir, index_page_name, namespace):
Index: clangd/include-mapping/test.py
===
--- clangd/include-mapping/test.py
+++ clangd/include-mapping/test.py
@@ -47,9 +47,13 @@
   
   
   
+  
+void foo()
+this is matched
+  
 
 """
-self.assertEqual(ParseSymbolPage(html), [''])
+self.assertEqual(ParseSymbolPage(html, 'foo'), set(['']))
 
 
   def testParseSymbolPage_MulHeaders(self):
@@ -64,6 +68,10 @@
  
 
   
+  
+void bar()
+this mentions foo, but isn't matched
+  
   
  Defined in header 
  
@@ -76,10 +84,14 @@
 
 
   
+  
+void foo()
+this is matched
+  
 
 """
-self.assertEqual(ParseSymbolPage(html),
-['', '', ''])
+self.assertEqual(ParseSymbolPage(html, "foo"),
+ set(['', '']))
 
 
   def testParseSymbolPage_MulHeadersInSameDiv(self):
@@ -87,6 +99,7 @@
 # Defined in header 
 # Defined in header 
 html = """
+
 
 
  Defined in header 
@@ -94,8 +107,14 @@
 
 
 
+
+  void foo()
+  this is matched
+
+
 """
-self.assertEqual(ParseSymbolPage(html), ['', ''])
+self.assertEqual(ParseSymbolPage(html, "foo"),
+ set(['', '']))
 
 
 if __name__ == '__main__':
Index: clangd/StdSymbolMap.inc
===
--- clangd/StdSymbolMap.inc
+++ clangd/StdSymbolMap.inc
@@ -141,1

[PATCH] D59692: [ASTImporter] Fix name conflict handling

2019-05-02 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Ping


Repository:
  rC Clang

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

https://reviews.llvm.org/D59692



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


[PATCH] D61126: [clangd] Also perform merging for symbol definitions

2019-05-02 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 197725.
kadircet added a comment.

- Update diff


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61126

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -186,7 +186,8 @@
 
 TEST(LocateSymbol, WithIndexPreferredLocation) {
   Annotations SymbolHeader(R"cpp(
-class $[[Proto]] {};
+class $p[[Proto]] {};
+void $f[[func]]() {};
   )cpp");
   TestTU TU;
   TU.HeaderCode = SymbolHeader.code();
@@ -195,13 +196,25 @@
 
   Annotations Test(R"cpp(// only declaration in AST.
 // Shift to make range different.
-class [[Proto]];
-P^roto* create();
+class Proto;
+void func() {}
+P$p^roto* create() {
+  fu$f^nc();
+  return nullptr;
+}
   )cpp");
 
   auto AST = TestTU::withCode(Test.code()).build();
-  auto Locs = clangd::locateSymbolAt(AST, Test.point(), Index.get());
-  EXPECT_THAT(Locs, ElementsAre(Sym("Proto", SymbolHeader.range(;
+  {
+auto Locs = clangd::locateSymbolAt(AST, Test.point("p"), Index.get());
+auto CodeGenLoc = SymbolHeader.range("p");
+EXPECT_THAT(Locs, ElementsAre(Sym("Proto", CodeGenLoc, CodeGenLoc)));
+  }
+  {
+auto Locs = clangd::locateSymbolAt(AST, Test.point("f"), Index.get());
+auto CodeGenLoc = SymbolHeader.range("f");
+EXPECT_THAT(Locs, ElementsAre(Sym("func", CodeGenLoc, CodeGenLoc)));
+  }
 }
 
 TEST(LocateSymbol, All) {
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -346,24 +346,27 @@
 Index->lookup(QueryRequest, [&](const Symbol &Sym) {
   auto &R = Result[ResultIndex.lookup(Sym.ID)];
 
-  // Special case: if the AST yielded a definition, then it may not be
-  // the right *declaration*. Prefer the one from the index.
   if (R.Definition) { // from AST
+// In case of generated files we prefer to omit the definition in the
+// generated code.
+if (auto Loc = toLSPLocation(
+getPreferredLocation(*R.Definition, Sym.Definition, Scratch),
+*MainFilePath))
+  R.Definition = *Loc;
+
+// Special case: if the AST yielded a definition, then it may not be
+// the right *declaration*. Prefer the one from the index.
 if (auto Loc = toLSPLocation(Sym.CanonicalDeclaration, *MainFilePath))
   R.PreferredDeclaration = *Loc;
   } else {
 R.Definition = toLSPLocation(Sym.Definition, *MainFilePath);
 
-if (Sym.CanonicalDeclaration) {
-  // Use merge logic to choose AST or index declaration.
-  // We only do this for declarations as definitions from AST
-  // is generally preferred (e.g. definitions in main file).
-  if (auto Loc = toLSPLocation(
-  getPreferredLocation(R.PreferredDeclaration,
-   Sym.CanonicalDeclaration, Scratch),
-  *MainFilePath))
-R.PreferredDeclaration = *Loc;
-}
+// Use merge logic to choose AST or index declaration.
+if (auto Loc = toLSPLocation(
+getPreferredLocation(R.PreferredDeclaration,
+ Sym.CanonicalDeclaration, Scratch),
+*MainFilePath))
+  R.PreferredDeclaration = *Loc;
   }
 });
   }


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -186,7 +186,8 @@
 
 TEST(LocateSymbol, WithIndexPreferredLocation) {
   Annotations SymbolHeader(R"cpp(
-class $[[Proto]] {};
+class $p[[Proto]] {};
+void $f[[func]]() {};
   )cpp");
   TestTU TU;
   TU.HeaderCode = SymbolHeader.code();
@@ -195,13 +196,25 @@
 
   Annotations Test(R"cpp(// only declaration in AST.
 // Shift to make range different.
-class [[Proto]];
-P^roto* create();
+class Proto;
+void func() {}
+P$p^roto* create() {
+  fu$f^nc();
+  return nullptr;
+}
   )cpp");
 
   auto AST = TestTU::withCode(Test.code()).build();
-  auto Locs = clangd::locateSymbolAt(AST, Test.point(), Index.get());
-  EXPECT_THAT(Locs, ElementsAre(Sym("Proto", SymbolHeader.range(;
+  {
+auto Locs = clangd::locateSymbolAt(AST, Test.point("p"), Index.get());
+auto CodeGenLoc = SymbolHeader.range("p");
+EXPECT_THAT(Locs, ElementsAre(Sym(

[PATCH] D59798: [analyzer] Add analyzer option to limit the number of imported TUs

2019-05-02 Thread Gabor Marton via Phabricator via cfe-commits
martong added a reviewer: xazax.hun.
martong added a comment.

@xazax.hun Could you please take a look?


Repository:
  rC Clang

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

https://reviews.llvm.org/D59798



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


[PATCH] D61424: [ASTImporter] Fix inequivalence of unresolved exception spec

2019-05-02 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: a_sidorin, shafik.
Herald added subscribers: cfe-commits, gamesh411, Szelethus, dkrupp, rnkovacs.
Herald added a reviewer: a.sidorin.
Herald added a project: clang.

Structural equivalence of methods can falsely report false when the
exception specifier is unresolved (i.e unevaluated or not instantiated).

(This caused one assertion during bitcoin ctu-analysis.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D61424

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp


Index: clang/lib/AST/ASTStructuralEquivalence.cpp
===
--- clang/lib/AST/ASTStructuralEquivalence.cpp
+++ clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -322,6 +322,36 @@
   return true;
 }
 
+/// Check the eqeuivalence of exception specifications.
+static bool IsEquivalentExceptionSpec(StructuralEquivalenceContext &Context,
+  const FunctionProtoType *Proto1,
+  const FunctionProtoType *Proto2) {
+
+  auto Spec1 = Proto1->getExceptionSpecType();
+  auto Spec2 = Proto2->getExceptionSpecType();
+
+  if (isUnresolvedExceptionSpec(Spec1) || isUnresolvedExceptionSpec(Spec2))
+return true;
+
+  if (Spec1 != Spec2)
+return false;
+  if (Spec1 == EST_Dynamic) {
+if (Proto1->getNumExceptions() != Proto2->getNumExceptions())
+  return false;
+for (unsigned I = 0, N = Proto1->getNumExceptions(); I != N; ++I) {
+  if (!IsStructurallyEquivalent(Context, Proto1->getExceptionType(I),
+Proto2->getExceptionType(I)))
+return false;
+}
+  } else if (isComputedNoexcept(Spec1)) {
+if (!IsStructurallyEquivalent(Context, Proto1->getNoexceptExpr(),
+  Proto2->getNoexceptExpr()))
+  return false;
+  }
+
+  return true;
+}
+
 /// Determine structural equivalence of two types.
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  QualType T1, QualType T2) {
@@ -536,24 +566,8 @@
 cast(OrigT1.getDesugaredType(Context.FromCtx));
 const auto *OrigProto2 =
 cast(OrigT2.getDesugaredType(Context.ToCtx));
-auto Spec1 = OrigProto1->getExceptionSpecType();
-auto Spec2 = OrigProto2->getExceptionSpecType();
-
-if (Spec1 != Spec2)
+if (!IsEquivalentExceptionSpec(Context, OrigProto1, OrigProto2))
   return false;
-if (Spec1 == EST_Dynamic) {
-  if (OrigProto1->getNumExceptions() != OrigProto2->getNumExceptions())
-return false;
-  for (unsigned I = 0, N = OrigProto1->getNumExceptions(); I != N; ++I) {
-if (!IsStructurallyEquivalent(Context, OrigProto1->getExceptionType(I),
-  OrigProto2->getExceptionType(I)))
-  return false;
-  }
-} else if (isComputedNoexcept(Spec1)) {
-  if (!IsStructurallyEquivalent(Context, OrigProto1->getNoexceptExpr(),
-OrigProto2->getNoexceptExpr()))
-return false;
-}
 
 // Fall through to check the bits common with FunctionNoProtoType.
 LLVM_FALLTHROUGH;
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -3101,6 +3101,10 @@
 auto *Recent = const_cast(
   FoundByLookup->getMostRecentDecl());
 ToFunction->setPreviousDecl(Recent);
+// FIXME Should we merge exception specifications?  E.g. In the "To"
+// context the existing function may have exception specification with
+// noexcept-unevaluated, while the newly imported function may have an
+// evaluated noexcept.
   }
 
   // Import Ctor initializers.


Index: clang/lib/AST/ASTStructuralEquivalence.cpp
===
--- clang/lib/AST/ASTStructuralEquivalence.cpp
+++ clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -322,6 +322,36 @@
   return true;
 }
 
+/// Check the eqeuivalence of exception specifications.
+static bool IsEquivalentExceptionSpec(StructuralEquivalenceContext &Context,
+  const FunctionProtoType *Proto1,
+  const FunctionProtoType *Proto2) {
+
+  auto Spec1 = Proto1->getExceptionSpecType();
+  auto Spec2 = Proto2->getExceptionSpecType();
+
+  if (isUnresolvedExceptionSpec(Spec1) || isUnresolvedExceptionSpec(Spec2))
+return true;
+
+  if (Spec1 != Spec2)
+return false;
+  if (Spec1 == EST_Dynamic) {
+if (Proto1->getNumExceptions() != Proto2->getNumExceptions())
+  return false;
+for (unsigned I = 0, N = Proto1->getNumExceptions(); I != N; ++I) {
+  if (!IsStructurallyEquivalent(Context, Proto1->getExceptionType(I),
+Proto2->getExceptionType(I)))
+return false;
+}
+

[PATCH] D61239: [libclang] Allow field offset lookups in types with incomplete arrays.

2019-05-02 Thread Jorn Vernee via Phabricator via cfe-commits
JornVernee added a comment.

In D61239#1487406 , @aaron.ballman 
wrote:

> In D61239#1486692 , @JornVernee 
> wrote:
>
> > Also, I don't have committer access. Would you mind committing this?
>
>
> Happy to do so -- I'll try to get it in this week if I have the time, but it 
> may not happen until early next week.


Take your time. Thanks for al the help!


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

https://reviews.llvm.org/D61239



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


[PATCH] D61319: [PR41674] [OpenCL] Fix initialisation of this via pointer

2019-05-02 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: test/CodeGenOpenCLCXX/addrspace-of-this.cl:94
 // Test the address space of 'this' when invoking a method that is declared in 
the file contex.
-// COMMON: %call1 = call i32 @_ZNU3AS41C7outsideEv(%class.C addrspace(4)* 
addrspacecast (%class.C addrspace(1)* @c to %class.C addrspace(4)*))
+// COMMON: %call2 = call i32 @_ZNU3AS41C7outsideEv(%class.C addrspace(4)* 
addrspacecast (%class.C addrspace(1)* @c to %class.C addrspace(4)*))
 

Ok I think we should regex name of call registers or may be even prevent 
checking it if it's not required. The same applies to other places btw.



Comment at: test/CodeGenOpenCLCXX/addrspace-of-this.cl:136
 // COMMON: [[CALL:%call[0-9]+]] = call spir_func dereferenceable(4) %class.C 
addrspace(4)* @_Z3foov()
-// EXPL: call void @_ZNU3AS41CC1EOU3AS4S_(%class.C addrspace(4)* 
[[C5GEN:%[0-9]+]], %class.C addrspace(4)* dereferenceable(4) %call4)
+// EXPL: call void @_ZNU3AS41CC1EOU3AS4S_(%class.C addrspace(4)* 
[[C5GEN:%[0-9]+]], %class.C addrspace(4)* dereferenceable(4) %call5)
 // IMPL: [[C5VOID:%[0-9]+]] = bitcast %class.C* %c5 to i8*

Shouldn't `%call5` just be `[[CALL]]`? If not I see little value in checking 
the name...


Repository:
  rC Clang

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

https://reviews.llvm.org/D61319



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


[PATCH] D61140: Copy Argument Passing Restrictions setting when importing a CXXRecordDecl definition

2019-05-02 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor closed this revision.
teemperor added a comment.

This has been landed as rC359338  but 
somehow Phabricator didn't close this. Closing this manually.


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

https://reviews.llvm.org/D61140



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


[PATCH] D60937: [clangd] Fix code completion of macros defined in the preamble region of the main file.

2019-05-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 197734.
sammccall added a comment.
Herald added a subscriber: mgrang.

Record macro names while building preamble instead of lexing it later.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D60937

Files:
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/CodeComplete.cpp
  clangd/index/SymbolCollector.cpp
  clangd/unittests/CodeCompleteTests.cpp

Index: clangd/unittests/CodeCompleteTests.cpp
===
--- clangd/unittests/CodeCompleteTests.cpp
+++ clangd/unittests/CodeCompleteTests.cpp
@@ -2073,19 +2073,28 @@
   UnorderedElementsAre(Named("Clangd_Macro_Test")));
 }
 
-TEST(CompletionTest, NoMacroFromPreambleIfIndexIsSet) {
+TEST(CompletionTest, MacroFromPreamble) {
+  MockFSProvider FS;
+  MockCompilationDatabase CDB;
+  std::string FooHeader = testPath("foo.h");
+  FS.Files[FooHeader] = "#define CLANGD_PREAMBLE_HEADER x\n";
+  IgnoreDiagnostics DiagConsumer;
+  ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest());
   auto Results = completions(
-  R"cpp(#define CLANGD_PREAMBLE x
+  R"cpp(#include "foo.h"
+  #define CLANGD_PREAMBLE_MAIN x
 
   int x = 0;
   #define CLANGD_MAIN x
   void f() { CLANGD_^ }
   )cpp",
   {func("CLANGD_INDEX")});
-  // Index is overriden in code completion options, so the preamble symbol is
-  // not seen.
-  EXPECT_THAT(Results.Completions, UnorderedElementsAre(Named("CLANGD_MAIN"),
-Named("CLANGD_INDEX")));
+  // We should get results from the main file, including the preamble section.
+  // However no results from included files (the index should cover them).
+  EXPECT_THAT(Results.Completions,
+  UnorderedElementsAre(Named("CLANGD_PREAMBLE_MAIN"),
+   Named("CLANGD_MAIN"),
+   Named("CLANGD_INDEX")));
 }
 
 TEST(CompletionTest, DeprecatedResults) {
Index: clangd/index/SymbolCollector.cpp
===
--- clangd/index/SymbolCollector.cpp
+++ clangd/index/SymbolCollector.cpp
@@ -24,6 +24,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/Specifiers.h"
 #include "clang/Index/IndexSymbol.h"
+#include "clang/Index/IndexingAction.h"
 #include "clang/Index/USRGeneration.h"
 #include "clang/Lex/Preprocessor.h"
 #include "llvm/Support/Casting.h"
Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -44,6 +44,8 @@
 #include "clang/Format/Format.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendActions.h"
+#include "clang/Lex/ExternalPreprocessorSource.h"
+#include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
 #include "clang/Sema/DeclSpec.h"
@@ -1017,6 +1019,23 @@
   llvm::IntrusiveRefCntPtr VFS;
 };
 
+void loadMainFilePreambleMacros(const Preprocessor &PP,
+const PreambleData &Preamble) {
+  // The ExternalPreprocessorSource has our macros, if we know where to look.
+  // We can read all the macros using PreambleMacros->ReadDefinedMacros(),
+  // but this includes transitively included files, so may deserialize a lot.
+  ExternalPreprocessorSource *PreambleMacros = PP.getExternalSource();
+  // As we have the names of the macros, we can look up their IdentifierInfo
+  // and then use this to load just the macros we want.
+  IdentifierInfoLookup *PreambleIdentifiers =
+  PP.getIdentifierTable().getExternalIdentifierLookup();
+  if (!PreambleIdentifiers || !PreambleMacros)
+return;
+  for (const auto& MacroName : Preamble.MainFileMacros)
+if (auto *II = PreambleIdentifiers->get(MacroName))
+  PreambleMacros->updateOutOfDateIdentifier(*II);
+}
+
 // Invokes Sema code completion on a file.
 // If \p Includes is set, it will be updated based on the compiler invocation.
 bool semaCodeComplete(std::unique_ptr Consumer,
@@ -1058,9 +1077,9 @@
   // However, if we're completing *inside* the preamble section of the draft,
   // overriding the preamble will break sema completion. Fortunately we can just
   // skip all includes in this case; these completions are really simple.
-  bool CompletingInPreamble =
-  ComputePreambleBounds(*CI->getLangOpts(), ContentsBuffer.get(), 0).Size >
-  Input.Offset;
+  PreambleBounds PreambleRegion =
+  ComputePreambleBounds(*CI->getLangOpts(), ContentsBuffer.get(), 0);
+  bool CompletingInPreamble = PreambleRegion.Size > Input.Offset;
   // NOTE: we must call BeginSourceFile after prepareCompilerInstance. Otherwise
   // the remapped buffers do not get freed.
   IgnoreDiagnostics DummyDiagsConsumer;
@@ -1078,6 +1097,14 @@
 Input

[PATCH] D60937: [clangd] Fix code completion of macros defined in the preamble region of the main file.

2019-05-02 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.

LGTM. Neat!


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D60937



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


[clang-tools-extra] r359778 - [clangd] Fix code completion of macros defined in the preamble region of the main file.

2019-05-02 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Thu May  2 04:06:44 2019
New Revision: 359778

URL: http://llvm.org/viewvc/llvm-project?rev=359778&view=rev
Log:
[clangd] Fix code completion of macros defined in the preamble region of the 
main file.

Summary:
This is a tricky case (we baked the assumption that symbols come from
the preamble xor mainfile pretty deeply) and the fix is a bit of a hack:
We look at the code to guess the macro names, and deserialize them from
the preamble "by hand".

Reviewers: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=359778&r1=359777&r2=359778&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Thu May  2 04:06:44 2019
@@ -20,6 +20,8 @@
 #include "index/Index.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendActions.h"
@@ -94,6 +96,36 @@ private:
   std::vector TopLevelDecls;
 };
 
+class CollectMainFileMacros : public PPCallbacks {
+public:
+  explicit CollectMainFileMacros(const SourceManager &SM,
+ std::vector *Out)
+  : SM(SM), Out(Out) {}
+
+  void FileChanged(SourceLocation Loc, FileChangeReason,
+   SrcMgr::CharacteristicKind, FileID Prev) {
+InMainFile = SM.isWrittenInMainFile(Loc);
+  }
+
+  void MacroDefined(const Token &MacroName, const MacroDirective *MD) {
+assert(MacroName.is(tok::identifier));
+if (InMainFile)
+  MainFileMacros.insert(MacroName.getIdentifierInfo()->getName());
+  }
+
+  void EndOfMainFile() {
+for (const auto& Entry : MainFileMacros)
+  Out->push_back(Entry.getKey());
+llvm::sort(*Out);
+  }
+
+ private:
+  const SourceManager &SM;
+  bool InMainFile = true;
+  llvm::StringSet<> MainFileMacros;
+  std::vector *Out;
+};
+
 class CppFilePreambleCallbacks : public PreambleCallbacks {
 public:
   CppFilePreambleCallbacks(PathRef File, PreambleParsedCallback ParsedCallback)
@@ -103,6 +135,10 @@ public:
 
   IncludeStructure takeIncludes() { return std::move(Includes); }
 
+  std::vector takeMainFileMacros() {
+return std::move(MainFileMacros);
+  }
+
   CanonicalIncludes takeCanonicalIncludes() { return std::move(CanonIncludes); 
}
 
   void AfterExecute(CompilerInstance &CI) override {
@@ -118,7 +154,9 @@ public:
 
   std::unique_ptr createPPCallbacks() override {
 assert(SourceMgr && "SourceMgr must be set at this point");
-return collectIncludeStructureCallback(*SourceMgr, &Includes);
+return llvm::make_unique(
+collectIncludeStructureCallback(*SourceMgr, &Includes),
+llvm::make_unique(*SourceMgr, &MainFileMacros));
   }
 
   CommentHandler *getCommentHandler() override {
@@ -131,6 +169,7 @@ private:
   PreambleParsedCallback ParsedCallback;
   IncludeStructure Includes;
   CanonicalIncludes CanonIncludes;
+  std::vector MainFileMacros;
   std::unique_ptr IWYUHandler = nullptr;
   SourceManager *SourceMgr = nullptr;
 };
@@ -459,11 +498,13 @@ const CanonicalIncludes &ParsedAST::getC
 
 PreambleData::PreambleData(PrecompiledPreamble Preamble,
std::vector Diags, IncludeStructure Includes,
+   std::vector MainFileMacros,
std::unique_ptr StatCache,
CanonicalIncludes CanonIncludes)
 : Preamble(std::move(Preamble)), Diags(std::move(Diags)),
-  Includes(std::move(Includes)), StatCache(std::move(StatCache)),
-  CanonIncludes(std::move(CanonIncludes)) {}
+  Includes(std::move(Includes)), MainFileMacros(std::move(MainFileMacros)),
+  StatCache(std::move(StatCache)), CanonIncludes(std::move(CanonIncludes)) 
{
+}
 
 ParsedAST::ParsedAST(std::shared_ptr Preamble,
  std::unique_ptr Clang,
@@ -542,7 +583,8 @@ buildPreamble(PathRef FileName, Compiler
 std::vector Diags = PreambleDiagnostics.take();
 return std::make_shared(
 std::move(*BuiltPreamble), std::move(Diags),
-SerializedDeclsCollector.takeIncludes(), std::move(StatCache),
+SerializedDeclsCollector.takeIncludes(),
+SerializedDeclsCollector.takeMainFileMacros(), std::move(StatCache),
 SerializedDeclsCollector.takeC

[PATCH] D60937: [clangd] Fix code completion of macros defined in the preamble region of the main file.

2019-05-02 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE359778: [clangd] Fix code completion of macros defined in 
the preamble region of the… (authored by sammccall, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D60937?vs=197734&id=197741#toc

Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D60937

Files:
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/CodeComplete.cpp
  clangd/index/SymbolCollector.cpp
  clangd/unittests/CodeCompleteTests.cpp

Index: clangd/CodeComplete.cpp
===
--- clangd/CodeComplete.cpp
+++ clangd/CodeComplete.cpp
@@ -44,6 +44,8 @@
 #include "clang/Format/Format.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendActions.h"
+#include "clang/Lex/ExternalPreprocessorSource.h"
+#include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
 #include "clang/Sema/DeclSpec.h"
@@ -1017,6 +1019,23 @@
   llvm::IntrusiveRefCntPtr VFS;
 };
 
+void loadMainFilePreambleMacros(const Preprocessor &PP,
+const PreambleData &Preamble) {
+  // The ExternalPreprocessorSource has our macros, if we know where to look.
+  // We can read all the macros using PreambleMacros->ReadDefinedMacros(),
+  // but this includes transitively included files, so may deserialize a lot.
+  ExternalPreprocessorSource *PreambleMacros = PP.getExternalSource();
+  // As we have the names of the macros, we can look up their IdentifierInfo
+  // and then use this to load just the macros we want.
+  IdentifierInfoLookup *PreambleIdentifiers =
+  PP.getIdentifierTable().getExternalIdentifierLookup();
+  if (!PreambleIdentifiers || !PreambleMacros)
+return;
+  for (const auto& MacroName : Preamble.MainFileMacros)
+if (auto *II = PreambleIdentifiers->get(MacroName))
+  PreambleMacros->updateOutOfDateIdentifier(*II);
+}
+
 // Invokes Sema code completion on a file.
 // If \p Includes is set, it will be updated based on the compiler invocation.
 bool semaCodeComplete(std::unique_ptr Consumer,
@@ -1058,9 +1077,9 @@
   // However, if we're completing *inside* the preamble section of the draft,
   // overriding the preamble will break sema completion. Fortunately we can just
   // skip all includes in this case; these completions are really simple.
-  bool CompletingInPreamble =
-  ComputePreambleBounds(*CI->getLangOpts(), ContentsBuffer.get(), 0).Size >
-  Input.Offset;
+  PreambleBounds PreambleRegion =
+  ComputePreambleBounds(*CI->getLangOpts(), ContentsBuffer.get(), 0);
+  bool CompletingInPreamble = PreambleRegion.Size > Input.Offset;
   // NOTE: we must call BeginSourceFile after prepareCompilerInstance. Otherwise
   // the remapped buffers do not get freed.
   IgnoreDiagnostics DummyDiagsConsumer;
@@ -1078,6 +1097,14 @@
 Input.FileName);
 return false;
   }
+  // Macros can be defined within the preamble region of the main file.
+  // They don't fall nicely into our index/Sema dichotomy:
+  //  - they're not indexed for completion (they're not available across files)
+  //  - but Sema code complete won't see them: as part of the preamble, they're
+  //deserialized only when mentioned.
+  // Force them to be deserialized so SemaCodeComplete sees them.
+  if (Input.Preamble)
+loadMainFilePreambleMacros(Clang->getPreprocessor(), *Input.Preamble);
   if (Includes)
 Clang->getPreprocessor().addPPCallbacks(
 collectIncludeStructureCallback(Clang->getSourceManager(), Includes));
Index: clangd/ClangdUnit.cpp
===
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -20,6 +20,8 @@
 #include "index/Index.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendActions.h"
@@ -94,6 +96,36 @@
   std::vector TopLevelDecls;
 };
 
+class CollectMainFileMacros : public PPCallbacks {
+public:
+  explicit CollectMainFileMacros(const SourceManager &SM,
+ std::vector *Out)
+  : SM(SM), Out(Out) {}
+
+  void FileChanged(SourceLocation Loc, FileChangeReason,
+   SrcMgr::CharacteristicKind, FileID Prev) {
+InMainFile = SM.isWrittenInMainFile(Loc);
+  }
+
+  void MacroDefined(const Token &MacroName, const MacroDirective *MD) {
+assert(MacroName.is(tok::identifier));
+if (InMainFile)
+  MainFileMacros.insert(MacroName.getIdentifierInfo()->getName());
+  }
+
+  void EndOfMainFile() {
+for (const auto& Entry : MainFileMacros)
+  Out->push_back(Entry.getKey());
+llvm::sort(*Out);
+  }
+
+ private:
+  cons

[PATCH] D59885: [Lex] Allow to consume tokens while preprocessing

2019-05-02 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov marked an inline comment as done.
ilya-biryukov added a comment.

In D59885#1485159 , @rsmith wrote:

> I'd like to understand more about the intended use cases of this 
> functionality. What information do clients want?


We are aiming to collect all expanded tokens, all raw tokens and how they 
relate to each other (i.e. which raw tokens form macro calls, #include 
directives, etc that produced particular subrange of expanded tokens).
We go through all this trouble to allow mapping expanded tokens (which is what 
you "see" in the AST, even though AST does not store them) back to the raw 
tokens that produced them (which you can finally map to textual offsets, the 
final output in various tooling-related scenarios).
That information is used specifically to map (an allowed subset of) changes in 
the expanded token stream to textual changes.

We could actually get most of this information merely by looking at source 
locations. The only bit that we're missing is how to map from a macro call 
tokens into **all** expanded tokens that were produced by it.
I'll play around with reporting only the expanded token stream here and using 
source locations to produce the rest of the information we need.




Comment at: clang/lib/Lex/Preprocessor.cpp:870-900
+  TokenSource Source;
   do {
+Source = TokenSource();
+
 switch (CurLexerKind) {
 case CLK_Lexer:
+  Source.InDirective = CurLexer->ParsingPreprocessorDirective;

rsmith wrote:
> This is a lot of extra stuff to be doing in the main `Lex` loop. Adding one 
> (perfectly-predicted) branch on `OnToken` seems like it should be fine, but 
> this seems like a bit more added complexity than I'd prefer. I'd like some 
> performance measurements of `-cc1 -Eonly` to see if this makes any real 
> difference.
Happy to do the measurements. Do you have a good collection of input files for 
this in mind?



Comment at: clang/lib/Lex/Preprocessor.cpp:896
 case CLK_LexAfterModuleImport:
-  ReturnedToken = LexAfterModuleImport(Result);
+  Source.InDirective = true;
+

rsmith wrote:
> This isn't a directive; these are normal tokens.
Sorry if it's a silly question, just wanted to clarify I'm not missing anything 
here.

These tokens are the name of the module,  "import-suffix" and the semicolon 
that follows it?
And they end up being used to build the AST for `ImportDecl`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59885



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


[PATCH] D61319: [PR41674] [OpenCL] Fix initialisation of this via pointer

2019-05-02 Thread Kévin Petit via Phabricator via cfe-commits
kpet added a comment.

Most of these are pre-existing issues with the tests but I agree they're worth 
fixing. I'll update the tests.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61319



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


[PATCH] D61319: [PR41674] [OpenCL] Fix initialisation of this via pointer

2019-05-02 Thread Kévin Petit via Phabricator via cfe-commits
kpet updated this revision to Diff 197749.
kpet added a comment.

Clean up the tests.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61319

Files:
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CodeGenOpenCLCXX/addrspace-of-this.cl


Index: clang/test/CodeGenOpenCLCXX/addrspace-of-this.cl
===
--- clang/test/CodeGenOpenCLCXX/addrspace-of-this.cl
+++ clang/test/CodeGenOpenCLCXX/addrspace-of-this.cl
@@ -59,7 +59,8 @@
 
 __kernel void test__global() {
   int i = c.get();
-  int i2 = c.outside();
+  int i2 = (&c)->get();
+  int i3 = c.outside();
   C c1(c);
   C c2;
   c2 = c1;
@@ -85,10 +86,12 @@
 // COMMON-LABEL: @_Z12test__globalv()
 
 // Test the address space of 'this' when invoking a method.
-// COMMON: %call = call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* 
addrspacecast (%class.C addrspace(1)* @c to %class.C addrspace(4)*))
+// COMMON: call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(1)* @c to %class.C addrspace(4)*))
+// Test the address space of 'this' when invoking a method using a pointer to 
the object.
+// COMMON: call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(1)* @c to %class.C addrspace(4)*))
 
 // Test the address space of 'this' when invoking a method that is declared in 
the file contex.
-// COMMON: %call1 = call i32 @_ZNU3AS41C7outsideEv(%class.C addrspace(4)* 
addrspacecast (%class.C addrspace(1)* @c to %class.C addrspace(4)*))
+// COMMON: call i32 @_ZNU3AS41C7outsideEv(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(1)* @c to %class.C addrspace(4)*))
 
 // Test the address space of 'this' when invoking copy-constructor.
 // COMMON: [[C1GEN:%[0-9]+]] = addrspacecast %class.C* %c1 to %class.C 
addrspace(4)*
@@ -130,7 +133,7 @@
 // Test the address space of 'this' when invoking the move assignment
 // COMMON: [[C5GEN:%[0-9]+]] = addrspacecast %class.C* %c5 to %class.C 
addrspace(4)*
 // COMMON: [[CALL:%call[0-9]+]] = call spir_func dereferenceable(4) %class.C 
addrspace(4)* @_Z3foov()
-// EXPL: call void @_ZNU3AS41CC1EOU3AS4S_(%class.C addrspace(4)* 
[[C5GEN:%[0-9]+]], %class.C addrspace(4)* dereferenceable(4) %call4)
+// EXPL: call void @_ZNU3AS41CC1EOU3AS4S_(%class.C addrspace(4)* 
[[C5GEN:%[0-9]+]], %class.C addrspace(4)* dereferenceable(4) [[CALL]])
 // IMPL: [[C5VOID:%[0-9]+]] = bitcast %class.C* %c5 to i8*
 // IMPL: [[CALLVOID:%[0-9]+]] = bitcast %class.C addrspace(4)* [[CALL]] to i8 
addrspace(4)*
 // IMPL: call void @llvm.memcpy.p0i8.p4i8.i32(i8* {{.*}}[[C5VOID]], i8 
addrspace(4)* {{.*}}[[CALLVOID]]
@@ -155,7 +158,7 @@
 // EXPL-NOT: call void @_ZNU3AS41CC1Ev(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(3)* @_ZZ11test__localvE1c to %class.C addrspace(4)*))
 
 // Test the address space of 'this' when invoking a method.
-// COMMON: %call = call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* 
addrspacecast (%class.C addrspace(3)* @_ZZ11test__localvE1c to %class.C 
addrspace(4)*))
+// COMMON: call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(3)* @_ZZ11test__localvE1c to %class.C addrspace(4)*))
 
 // Test the address space of 'this' when invoking copy-constructor.
 // COMMON: [[C1GEN:%[0-9]+]] = addrspacecast %class.C* %c1 to %class.C 
addrspace(4)*
@@ -185,7 +188,7 @@
 
 // Test the address space of 'this' when invoking a method.
 // COMMON: [[CGEN:%[0-9]+]] = addrspacecast %class.C* %c to %class.C 
addrspace(4)*
-// COMMON: %call = call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* [[CGEN]])
+// COMMON: call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* [[CGEN]])
 
 // Test the address space of 'this' when invoking a copy-constructor.
 // COMMON: [[C1GEN:%[0-9]+]] = addrspacecast %class.C* %c1 to %class.C 
addrspace(4)*
@@ -202,7 +205,7 @@
 // Test the address space of 'this' when invoking a copy-assignment.
 // COMMON: [[C1GEN:%[0-9]+]] = addrspacecast %class.C* %c1 to %class.C 
addrspace(4)*
 // COMMON: [[C2GEN:%[0-9]+]] = addrspacecast %class.C* %c2 to %class.C 
addrspace(4)*
-// EXPL: %call1 = call dereferenceable(4) %class.C addrspace(4)* 
@_ZNU3AS41CaSERU3AS4KS_(%class.C addrspace(4)* [[C2GEN]], %class.C 
addrspace(4)* dereferenceable(4) [[C1GEN]])
+// EXPL: call dereferenceable(4) %class.C addrspace(4)* 
@_ZNU3AS41CaSERU3AS4KS_(%class.C addrspace(4)* [[C2GEN]], %class.C 
addrspace(4)* dereferenceable(4) [[C1GEN]])
 // IMPL: [[C2GENVOID:%[0-9]+]] = bitcast %class.C addrspace(4)* [[C2GEN]] to 
i8 addrspace(4)*
 // IMPL: [[C1GENVOID:%[0-9]+]] = bitcast %class.C addrspace(4)* [[C1GEN]] to 
i8 addrspace(4)*
 // IMPL:  call void @llvm.memcpy.p4i8.p4i8.i32(i8 addrspace(4)* 
{{.*}}[[C2GENVOID]], i8 addrspace(4)* {{.*}}[[C1GENVOID]]
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -5278,12 +5278,1

[PATCH] D61386: [clang-tidy] Add support writing a check as a Transformer rewrite rule.

2019-05-02 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

I like the new framework!




Comment at: clang-tools-extra/clang-tidy/utils/TransformerTidy.cpp:43
+  if (Rule.Explanation) {
+if (Expected Explanation = Rule.Explanation(Result)) {
+  Message = *Explanation;

these if-else are single statement, so the braces can be ellided.



Comment at: clang-tools-extra/unittests/clang-tidy/TransformerTidyTest.cpp:38
+  IfInverterTidy(StringRef Name, ClangTidyContext *Context)
+  : TransformerTidy(invertIf(), Name, Context) {}
+};

If we allow to pass in a callable, that returns a `RewriteRule`we would have a 
more flexible framework in clang-tidy.
Going with this for now is ok in my opinion as the only good usecase that comes 
to my mind would be statistics.

But If some transformation needs to remember what has been done before only a 
`RewriteRule` as state is not sufficient and stateful actions would require 
global state (MEH!).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61386



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


[PATCH] D61438: [ASTImporter] Use llvm::Expected and Error in the importer API

2019-05-02 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: shafik, teemperor, aprantl, a_sidorin, balazske.
Herald added subscribers: lldb-commits, cfe-commits, gamesh411, Szelethus, 
dkrupp, rnkovacs.
Herald added a reviewer: a.sidorin.
Herald added projects: clang, LLDB.

This is the final phase of the refactoring towards using llvm::Expected
and llvm::Error in the ASTImporter API.
This involves the following:

- remove old Import functions which returned with a pointer,
- use the Import_New functions (which return with Err or Expected) everywhere 
and handle their return value
- rename Import_New functions to Import

This affects both Clang and LLDB.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D61438

Files:
  clang/include/clang/AST/ASTImporter.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ExternalASTMerger.cpp
  clang/lib/CrossTU/CrossTranslationUnit.cpp
  clang/lib/Frontend/ASTMerge.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
  lldb/source/Symbol/ClangASTContext.cpp
  lldb/source/Symbol/ClangASTImporter.cpp
  lldb/source/Symbol/CxxModuleHandler.cpp

Index: lldb/source/Symbol/CxxModuleHandler.cpp
===
--- lldb/source/Symbol/CxxModuleHandler.cpp
+++ lldb/source/Symbol/CxxModuleHandler.cpp
@@ -218,8 +218,10 @@
   for (const TemplateArgument &arg : foreign_args.asArray()) {
 switch (arg.getKind()) {
 case TemplateArgument::Type: {
-  llvm::Expected type = m_importer->Import_New(arg.getAsType());
+  llvm::Expected type = m_importer->Import(arg.getAsType());
   if (!type) {
+// FIXME log? Indicate error to user?
+lldbassert(0 && "Couldn't import a type!");
 llvm::consumeError(type.takeError());
 return {};
   }
@@ -229,8 +231,10 @@
 case TemplateArgument::Integral: {
   llvm::APSInt integral = arg.getAsIntegral();
   llvm::Expected type =
-  m_importer->Import_New(arg.getIntegralType());
+  m_importer->Import(arg.getIntegralType());
   if (!type) {
+// FIXME log? Indicate error to user?
+lldbassert(0 && "Couldn't import a type!");
 llvm::consumeError(type.takeError());
 return {};
   }
Index: lldb/source/Symbol/ClangASTImporter.cpp
===
--- lldb/source/Symbol/ClangASTImporter.cpp
+++ lldb/source/Symbol/ClangASTImporter.cpp
@@ -62,8 +62,15 @@
 
   ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, dst_ast);
 
-  if (delegate_sp)
-return delegate_sp->Import(type);
+  if (delegate_sp) {
+if (llvm::Expected ret_or_error = delegate_sp->Import(type))
+  return *ret_or_error;
+else {
+  // FIXME log? Indicate error to user?
+  lldbassert(0 && "Couldn't import a type!");
+  llvm::consumeError(ret_or_error.takeError());
+}
+  }
 
   return QualType();
 }
@@ -106,7 +113,7 @@
   ASTImporterDelegate::CxxModuleScope std_scope(*delegate_sp, dst_ast);
 
   if (delegate_sp) {
-clang::Decl *result = delegate_sp->Import(decl);
+llvm::Expected result = delegate_sp->Import(decl);
 
 if (!result) {
   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
@@ -127,9 +134,14 @@
   "metadata 0x%" PRIx64,
   decl->getDeclKindName(), user_id);
   }
+
+  // FIXME log?
+  llvm::consumeError(result.takeError());
+
+  return nullptr;
 }
 
-return result;
+return *result;
   }
 
   return nullptr;
@@ -641,7 +653,11 @@
 TagDecl *origin_tag_decl = llvm::dyn_cast(decl_origin.decl);
 
 for (Decl *origin_child_decl : origin_tag_decl->decls()) {
-  delegate_sp->Import(origin_child_decl);
+  llvm::Expected imported_or_err =
+  delegate_sp->Import(origin_child_decl);
+  if (!imported_or_err)
+// FIXME return with false?
+consumeError(imported_or_err.takeError());
 }
 
 if (RecordDecl *record_decl = dyn_cast(origin_tag_decl)) {
@@ -666,7 +682,11 @@
   llvm::dyn_cast(decl_origin.decl);
 
   for (Decl *origin_child_decl : origin_interface_decl->decls()) {
-delegate_sp->Import(origin_child_decl);
+llvm::Expected imported_or_err =
+delegate_sp->Import(origin_child_decl);
+if (!imported_or_err)
+  // FIXME return with false?
+  consumeError(imported_or_err.takeError());
   }
 
   return true;
@@ -919,7 +939,16 @@
   to_cxx_record->startDefinition();
   */
 
-  ImportDefinition(from);
+  llvm::Error Err = ImportDefinition(from);
+  if (Err) {
+// FIXME Indicate import error to user?
+Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
+if (log)
+  log->Printf("[ClangASTImporter] Error during importing definition!");
+lldbassert(0 && "Coul

[PATCH] D61274: [Sema][AST] Explicit visibility for OpenCL/CUDA kernels/variables

2019-05-02 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: lib/AST/Decl.cpp:738
+  (isa(D) && D->hasAttr()) ||
+  (isa(D) && D->hasAttr())) {
+Visibility Vis = LV.getVisibility();

yaxunl wrote:
> we also need this for `__constant__` variables.
And what about `__global` and `__constant` program scope variables in OpenCL?


Repository:
  rC Clang

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

https://reviews.llvm.org/D61274



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


[PATCH] D54757: [clang-tidy] new check: bugprone-branch-clone

2019-05-02 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

I actually managed to reproduce the crash.

  extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp:200: 
clang::DiagnosticBuilder clang::tidy::ClangTidyContext::diag(llvm::StringRef, 
clang::SourceLocation, llvm::StringRef, DiagnosticIDs::Level): Assertion 
`Loc.isValid()' failed.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D54757



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


[PATCH] D61422: [clang-tidy] Extend bugprone-sizeof-expression check to detect sizeof misuse in pointer arithmetic

2019-05-02 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 197768.
baloghadamsoftware added a comment.

Type `int` in tests replaced by `struct S` because it has more "sugar". Check 
also fixed to handle this case.


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

https://reviews.llvm.org/D61422

Files:
  clang-tidy/bugprone/SizeofExpressionCheck.cpp
  test/clang-tidy/bugprone-sizeof-expression.cpp

Index: test/clang-tidy/bugprone-sizeof-expression.cpp
===
--- test/clang-tidy/bugprone-sizeof-expression.cpp
+++ test/clang-tidy/bugprone-sizeof-expression.cpp
@@ -231,6 +231,35 @@
   return sum;
 }
 
+int Test6() {
+  int sum = 0;
+
+  struct S A = AsStruct(), B = AsStruct();
+  struct S *P = &A, *Q = &B;
+  sum += sizeof(struct S) == P - Q;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+  sum += 5 * sizeof(S) != P - Q;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+  sum += sizeof(S) < P - Q;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+  sum += 5 * sizeof(S) <= P - Q;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+  sum += 5 * sizeof(*P) >= P - Q;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+  sum += Q - P > 3 * sizeof(*P);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+  sum += sizeof(S) + (P - Q);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+  sum += 5 * sizeof(S) - (P - Q);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+  sum += (P - Q) / sizeof(S);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+  sum += (P - Q) / sizeof(*Q);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious usage of 'sizeof(...)' in pointer arithmetic
+
+  return sum;
+}
+
 int ValidExpressions() {
   int A[] = {1, 2, 3, 4};
   static const char str[] = "hello";
Index: clang-tidy/bugprone/SizeofExpressionCheck.cpp
===
--- clang-tidy/bugprone/SizeofExpressionCheck.cpp
+++ clang-tidy/bugprone/SizeofExpressionCheck.cpp
@@ -84,8 +84,11 @@
   const auto IntegerCallExpr = expr(ignoringParenImpCasts(
   callExpr(anyOf(hasType(isInteger()), hasType(enumType())),
unless(isInTemplateInstantiation();
-  const auto SizeOfExpr =
-  expr(anyOf(sizeOfExpr(has(type())), sizeOfExpr(has(expr();
+  const auto SizeOfExpr = expr(anyOf(
+  sizeOfExpr(
+  has(hasUnqualifiedDesugaredType(type().bind("sizeof-arg-type",
+  sizeOfExpr(has(expr(hasType(
+  hasUnqualifiedDesugaredType(type().bind("sizeof-arg-type";
   const auto SizeOfZero = expr(
   sizeOfExpr(has(ignoringParenImpCasts(expr(integerLiteral(equals(0)));
 
@@ -209,6 +212,36 @@
hasSizeOfDescendant(8, expr(SizeOfExpr, unless(SizeOfZero
   .bind("sizeof-sizeof-expr"),
   this);
+
+  // Detect sizeof in pointer aritmetic like: N * sizeof(S) == P1 - P2 or
+  // (P1 - P2) / sizeof(S) where P1 and P2 are pointers to type S
+  const auto PtrDiffExpr = binaryOperator(
+  hasOperatorName("-"),
+  hasLHS(expr(hasType(hasUnqualifiedDesugaredType(pointerType(pointee(
+  hasUnqualifiedDesugaredType(type().bind("left-ptr-type",
+  hasRHS(expr(hasType(hasUnqualifiedDesugaredType(pointerType(pointee(
+  hasUnqualifiedDesugaredType(type().bind("right-ptr-type");
+
+  Finder->addMatcher(
+  binaryOperator(
+  anyOf(hasOperatorName("=="), hasOperatorName("!="),
+hasOperatorName("<"), hasOperatorName("<="),
+hasOperatorName(">"), hasOperatorName(">="),
+hasOperatorName("+"), hasOperatorName("-")),
+  hasEitherOperand(expr(anyOf(
+  ignoringParenImpCasts(SizeOfExpr),
+  ignoringParenImpCasts(binaryOperator(
+  hasOperatorName("*"),
+  hasEitherOperand(ignoringParenImpCasts(SizeOfExpr))),
+  hasEitherOperand(ignoringParenImpCasts(PtrDiffExpr)))
+  .bind("sizeof-in-ptr-arithmetic-mul"),
+  this);
+
+  Finder->addMatcher(binaryOperator(hasOperatorName("/"),
+hasLHS(ignoringParenImpCasts(PtrDiffExpr)),
+hasRHS(ignoringParenImpCasts(SizeOfExpr)))
+ .bind("sizeof-in-ptr-arithmetic-div"),
+ this);
 }
 
 void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
@@ -275,6 +308,26 @@
   } else if (const auto *E =
  Result.Nodes

[PATCH] D61318: [Sema] Prevent binding references with mismatching address spaces to temporaries

2019-05-02 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia updated this revision to Diff 197769.
Anastasia added a comment.

Added extra overload for `isAddressSpaceSupersetOf`.


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

https://reviews.llvm.org/D61318

Files:
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticIDs.h
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Initialization.h
  lib/Sema/SemaInit.cpp
  test/SemaOpenCLCXX/address-space-references.cl

Index: test/SemaOpenCLCXX/address-space-references.cl
===
--- test/SemaOpenCLCXX/address-space-references.cl
+++ test/SemaOpenCLCXX/address-space-references.cl
@@ -9,3 +9,7 @@
 void foo() {
   bar(1) // expected-error{{binding reference of type 'const __global unsigned int' to value of type 'int' changes address space}}
 }
+
+__global const int &f(__global float &ref) {
+  return ref; // expected-error{{reference of type 'const __global int &' cannot bind to a temporary object because of address space mismatch}}
+}
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -3336,6 +3336,7 @@
   case FK_NonConstLValueReferenceBindingToVectorElement:
   case FK_NonConstLValueReferenceBindingToUnrelated:
   case FK_RValueReferenceBindingToLValue:
+  case FK_ReferenceAddrspaceMismatchTemporary:
   case FK_ReferenceInitDropsQualifiers:
   case FK_ReferenceInitFailed:
   case FK_ConversionFailed:
@@ -4831,9 +4832,16 @@
 
   Sequence.AddReferenceBindingStep(cv1T1IgnoreAS, /*bindingTemporary=*/true);
 
-  if (T1Quals.hasAddressSpace())
+  if (T1Quals.hasAddressSpace()) {
+if (!Qualifiers::isAddressSpaceSupersetOf(T1Quals.getAddressSpace(),
+  LangAS::Default)) {
+  Sequence.SetFailed(
+  InitializationSequence::FK_ReferenceAddrspaceMismatchTemporary);
+  return;
+}
 Sequence.AddQualificationConversionStep(cv1T1, isLValueRef ? VK_LValue
: VK_XValue);
+  }
 }
 
 /// Attempt character array initialization from a string literal
@@ -8497,6 +8505,11 @@
   << Args[0]->getSourceRange();
 break;
 
+  case FK_ReferenceAddrspaceMismatchTemporary:
+S.Diag(Kind.getLocation(), diag::err_reference_bind_temporary_addrspace)
+<< DestType << Args[0]->getSourceRange();
+break;
+
   case FK_ReferenceInitDropsQualifiers: {
 QualType SourceType = OnlyArg->getType();
 QualType NonRefType = DestType.getNonReferenceType();
@@ -8832,6 +8845,10 @@
   OS << "reference initialization drops qualifiers";
   break;
 
+case FK_ReferenceAddrspaceMismatchTemporary:
+  OS << "reference with mismatching address space bound to temporary";
+  break;
+
 case FK_ReferenceInitFailed:
   OS << "reference initialization failed";
   break;
Index: include/clang/Sema/Initialization.h
===
--- include/clang/Sema/Initialization.h
+++ include/clang/Sema/Initialization.h
@@ -1010,6 +1010,9 @@
 /// Reference binding drops qualifiers.
 FK_ReferenceInitDropsQualifiers,
 
+/// Reference with mismatching address space binding to temporary.
+FK_ReferenceAddrspaceMismatchTemporary,
+
 /// Reference binding failed.
 FK_ReferenceInitFailed,
 
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -1840,6 +1840,9 @@
   "reference %diff{to %select{type|incomplete type}1 $ could not bind to an "
   "%select{rvalue|lvalue}2 of type $|could not bind to %select{rvalue|lvalue}2 of "
   "incompatible type}0,3">;
+def err_reference_bind_temporary_addrspace : Error<
+  "reference of type %0 cannot bind to a temporary object because of "
+  "address space mismatch">;
 def err_reference_bind_init_list : Error<
   "reference to type %0 cannot bind to an initializer list">;
 def err_init_list_bad_dest_type : Error<
Index: include/clang/Basic/DiagnosticIDs.h
===
--- include/clang/Basic/DiagnosticIDs.h
+++ include/clang/Basic/DiagnosticIDs.h
@@ -36,7 +36,7 @@
   DIAG_SIZE_AST   =  150,
   DIAG_SIZE_COMMENT   =  100,
   DIAG_SIZE_CROSSTU   =  100,
-  DIAG_SIZE_SEMA  = 3500,
+  DIAG_SIZE_SEMA  = 3600,
   DIAG_SIZE_ANALYSIS  =  100,
   DIAG_SIZE_REFACTORING   = 1000,
 };
Index: include/clang/AST/Type.h
===
--- include/clang/AST/Type.h
+++ include/clang/AST/Type.h
@@ -460,21 +460,24 @@
 Mask |= qs.Mask;
   }
 
-  /// Returns true if this address space is a superset of the other one.
+  /// Returns true if address space A is a superset of B.
   /// OpenCL

[PATCH] D59885: [Lex] Allow to consume tokens while preprocessing

2019-05-02 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov marked an inline comment as done.
ilya-biryukov added inline comments.



Comment at: clang/lib/Lex/Preprocessor.cpp:956-957
   --LexLevel;
+  if (OnToken)
+OnToken(Result, Source);
 }

rsmith wrote:
> This seems like it's going to be extremely hard to use. If you just want the 
> expanded token stream, then removing all the other calls to `OnToken` and 
> only calling it here when `LexLevel == 0` will give you that.
I've tried `LexLevel == 0 && IsNewToken` and it **almost** works.
The only trouble left is dealing with the delayed parsing. E.g. I'm getting the 
callbacks for the same tokens multiple times in cases like parsing of method 
bodies.

Any ideas on how to best tackle this?

The example is:
```
struct X {
  int method() { return 10; }
  int a = 10;
};
```

Seeing multiple callbacks for `{ return 10; }` and `= 10;`, want to see only 
the first one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59885



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


RE: [PATCH] D42642: [CUDA] Detect installation in PATH

2019-05-02 Thread Alexandre Ganea via cfe-commits
Thanks Michael, it makes sense. I'm still with the old SVN setup on Windows. 
WSL uses the NTFS partition through drvfs (your case 2.)
I'll switch to the git monorepo, it looks like the latest git supports [1] 
symlinks on Windows (with the restrictions you've mentioned) and they should be 
mapped properly inside WSL in that case.

Should we then assume symlinks will always work for end-users? Should we 
validate that somehow, during cmake setup?

Alex.

[1] https://github.com/libgit2/libgit2/pull/4713

-Message d'origine-
De : Michael Kruse  
Envoyé : 1 mai 2019 17:23
À : reviews+d42642+public+5dc9c99d2f2d3...@reviews.llvm.org; Alexandre Ganea 
via Phabricator 
Cc : hah...@hahnjo.de; jle...@google.com; t...@google.com; Alexandre Ganea 
; cfe-commits ; 
llvm-commits ; sylvestre.le...@gmail.com
Objet : Re: [PATCH] D42642: [CUDA] Detect installation in PATH

Hi,

I had my own difficulties with this. It depends on how the repository
containing the symlink has been checked-out. For instance:

1. Using a windows git (such as git extensions, mingw-git, git for windows)
2. Using git inside wsl on a drvfs mount (i.e. a windows folder
mounted into the Unix filesystem)
3. Using git inside wsl on a lxfs mount (I.e. native mount such as '/')

In case 1. git does not create a Ubuntu symlink. Also, there are no
Unix symlinks in Windows filesystems, so when Unix tools (such as git)
request to create a symlink, it creates something else (AFAIR it's a
text file containing the symlink path, but having lost its symlink
properties). Case 3 should work.

I still managed to make cases 1 and 2 work by deleting the text file
and re-creating it with windows's "mklink" tool (which requires either
admin rights or developer mode turned on). It seems the WSL layer
translates this as a symlink to the Linux environment.

Michael





Am Mi., 1. Mai 2019 um 16:59 Uhr schrieb Alexandre Ganea via
Phabricator via llvm-commits :
>
> aganea added a subscriber: rnk.
> aganea added a comment.
>
> So it turns out this is a symlink issue. The file 
> `clang/trunk/test/Driver/Inputs/CUDA-symlinks/usr/bin/ptxas` has been 
> synchronized on my Windows 10 PC as a regular text file, not a symlink. It 
> looks like TortoiseSVN doesn't implement symlinks. As WSL inherits of my file 
> system, it will not find the symbolic link. I suppose `REQUIRES: 
> !system-windows` isn't enough for `cuda-detect-path.cu`, and it would need 
> something like `REQUIRES: symlinks` along with support in lit. @rnk
>
>
> Repository:
>   rL LLVM
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D42642/new/
>
> https://reviews.llvm.org/D42642
>
>
>
> ___
> llvm-commits mailing list
> llvm-comm...@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D61396: [hip] Fix ambiguity from `>>>` of CUDA.

2019-05-02 Thread Michael Liao via Phabricator via cfe-commits
hliao added a comment.

@rsmith do you have the chance to review this simple fix?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61396



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


r359789 - [OpenCL] Deduce static data members to __global addr space.

2019-05-02 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu May  2 07:40:40 2019
New Revision: 359789

URL: http://llvm.org/viewvc/llvm-project?rev=359789&view=rev
Log:
[OpenCL] Deduce static data members to __global addr space.

Similarly to static variables in OpenCL, static class data
members should be deduced to __global addr space.

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


Added:
cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
Modified:
cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=359789&r1=359788&r2=359789&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu May  2 07:40:40 2019
@@ -7308,8 +7308,10 @@ static void deduceOpenCLImplicitAddrSpac
// otherwise it will fail some sema check.
   IsFuncReturnType || IsFuncType ||
   // Do not deduce addr space for member types of struct, except the 
pointee
-  // type of a pointer member type.
-  (D.getContext() == DeclaratorContext::MemberContext && !IsPointee) ||
+  // type of a pointer member type or static data members.
+  (D.getContext() == DeclaratorContext::MemberContext &&
+   (!IsPointee &&
+D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_static)) ||
   // Do not deduce addr space for types used to define a typedef and the
   // typedef itself, except the pointee type of a pointer type which is 
used
   // to define the typedef.

Added: cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl?rev=359789&view=auto
==
--- cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl (added)
+++ cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl Thu May  2 07:40:40 
2019
@@ -0,0 +1,12 @@
+//RUN: %clang_cc1 %s -cl-std=c++ -pedantic -ast-dump -verify
+
+//expected-no-diagnostics
+
+//CHECK: |-VarDecl  foo {{.*}} 'const __global int' constexpr cinit
+constexpr int foo = 0;
+
+class c {
+public:
+  //CHECK: `-VarDecl {{.*}} foo2 'const __global int' static constexpr cinit
+  static constexpr int foo2 = 0;
+};


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


[PATCH] D59885: [Lex] Allow to consume tokens while preprocessing

2019-05-02 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 197778.
ilya-biryukov added a comment.

- Simplify the interface, get only the expanded token stream
- An attempt to not report tokens from delayed parsing twice, almost works


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59885

Files:
  clang/include/clang/Lex/Preprocessor.h
  clang/include/clang/Lex/TokenLexer.h
  clang/lib/Lex/Preprocessor.cpp


Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -867,20 +867,27 @@
   // We loop here until a lex function returns a token; this avoids recursion.
   bool ReturnedToken;
   bool IsNewToken = true;
+  // Whether to call the OnToken callback on this token.
+  bool Report;
   do {
 switch (CurLexerKind) {
 case CLK_Lexer:
+  Report = true;
   ReturnedToken = CurLexer->Lex(Result);
   break;
 case CLK_TokenLexer:
+  Report = CurTokenLexer->isMacroExpansion();
   ReturnedToken = CurTokenLexer->Lex(Result);
   break;
 case CLK_CachingLexer:
   CachingLex(Result, IsNewToken);
+  Report = IsNewToken;
   ReturnedToken = true;
   break;
 case CLK_LexAfterModuleImport:
-  ReturnedToken = LexAfterModuleImport(Result);
+  LexAfterModuleImport(Result);
+  Report = true;
+  ReturnedToken = true;
   break;
 }
   } while (!ReturnedToken);
@@ -937,6 +944,8 @@
 
   LastTokenWasAt = Result.is(tok::at);
   --LexLevel;
+  if (OnToken && LexLevel == 0 && Report)
+OnToken(Result);
 }
 
 /// Lex a header-name token (including one formed from header-name-tokens if
Index: clang/include/clang/Lex/TokenLexer.h
===
--- clang/include/clang/Lex/TokenLexer.h
+++ clang/include/clang/Lex/TokenLexer.h
@@ -147,6 +147,10 @@
   /// preprocessor directive.
   bool isParsingPreprocessorDirective() const;
 
+  /// Returns true iff the TokenLexer is expanding a macro and not replaying a
+  /// stream of tokens.
+  bool isMacroExpansion() const { return Macro != nullptr; }
+
 private:
   void destroy();
 
Index: clang/include/clang/Lex/Preprocessor.h
===
--- clang/include/clang/Lex/Preprocessor.h
+++ clang/include/clang/Lex/Preprocessor.h
@@ -33,6 +33,7 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/FunctionExtras.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/PointerUnion.h"
@@ -48,8 +49,8 @@
 #include 
 #include 
 #include 
-#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -124,6 +125,7 @@
   friend class VAOptDefinitionContext;
   friend class VariadicMacroScopeGuard;
 
+  llvm::unique_function OnToken;
   std::shared_ptr PPOpts;
   DiagnosticsEngine*Diags;
   LangOptions   &LangOpts;
@@ -997,6 +999,12 @@
   }
   /// \}
 
+  /// Register a function that would be called on each token in the final
+  /// expanded token stream.
+  void setTokenWatcher(llvm::unique_function F) {
+OnToken = std::move(F);
+  }
+
   bool isMacroDefined(StringRef Id) {
 return isMacroDefined(&Identifiers.get(Id));
   }


Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -867,20 +867,27 @@
   // We loop here until a lex function returns a token; this avoids recursion.
   bool ReturnedToken;
   bool IsNewToken = true;
+  // Whether to call the OnToken callback on this token.
+  bool Report;
   do {
 switch (CurLexerKind) {
 case CLK_Lexer:
+  Report = true;
   ReturnedToken = CurLexer->Lex(Result);
   break;
 case CLK_TokenLexer:
+  Report = CurTokenLexer->isMacroExpansion();
   ReturnedToken = CurTokenLexer->Lex(Result);
   break;
 case CLK_CachingLexer:
   CachingLex(Result, IsNewToken);
+  Report = IsNewToken;
   ReturnedToken = true;
   break;
 case CLK_LexAfterModuleImport:
-  ReturnedToken = LexAfterModuleImport(Result);
+  LexAfterModuleImport(Result);
+  Report = true;
+  ReturnedToken = true;
   break;
 }
   } while (!ReturnedToken);
@@ -937,6 +944,8 @@
 
   LastTokenWasAt = Result.is(tok::at);
   --LexLevel;
+  if (OnToken && LexLevel == 0 && Report)
+OnToken(Result);
 }
 
 /// Lex a header-name token (including one formed from header-name-tokens if
Index: clang/include/clang/Lex/TokenLexer.h
===
--- clang/include/clang/Lex/TokenLexer.h
+++ clang/include/clang/Lex/TokenLexer.h
@@ -147,6 +147,10 @@
   /// preprocessor directive.
   bool isParsingPreprocessorDirective() const;
 
+  /// Returns true iff the TokenLexer is expanding 

[PATCH] D61442: [clangd] Fix header-guard check for include insertion, and don't index header guards.

2019-05-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added subscribers: cfe-commits, arphaman, mgrang, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.

Both of these attempt to check whether a header guard exists while parsing the
file. However the file is only marked as guarded once clang finishes processing
it. We defer the checks and work until SymbolCollector::finish().

This is ugly and ad-hoc, deferring *all* work might be cleaner.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D61442

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

Index: clangd/unittests/SymbolCollectorTests.cpp
===
--- clangd/unittests/SymbolCollectorTests.cpp
+++ clangd/unittests/SymbolCollectorTests.cpp
@@ -20,6 +20,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/VirtualFileSystem.h"
+#include "gmock/gmock-matchers.h"
 #include "gmock/gmock-more-matchers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -34,9 +35,9 @@
 using testing::_;
 using testing::AllOf;
 using testing::Contains;
+using testing::Each;
 using testing::ElementsAre;
 using testing::Field;
-using testing::IsEmpty;
 using testing::Not;
 using testing::Pair;
 using testing::UnorderedElementsAre;
@@ -1028,6 +1029,26 @@
   Not(IncludeHeader();
 }
 
+// Features that depend on header-guards are fragile. Header guards are only
+// recognized when the file ends, so we have to defer checking for them.
+TEST_F(SymbolCollectorTest, HeaderGuardDetected) {
+  CollectorOpts.CollectIncludePath = true;
+  CollectorOpts.CollectMacro = true;
+  runSymbolCollector(R"cpp(
+#ifndef HEADER_GUARD_
+#define HEADER_GUARD_
+
+// Symbols are seen before the header guard is complete.
+int decl();
+#define MACRO
+
+#endif // Header guard is recognized here.
+  )cpp",
+ "");
+  EXPECT_THAT(Symbols, Not(Contains(QName("HEADER_GUARD_";
+  EXPECT_THAT(Symbols, Each(IncludeHeader()));
+}
+
 TEST_F(SymbolCollectorTest, NonModularHeader) {
   auto TU = TestTU::withHeaderCode("int x();");
   EXPECT_THAT(TU.headerSymbols(), ElementsAre(IncludeHeader()));
Index: clangd/index/SymbolCollector.h
===
--- clangd/index/SymbolCollector.h
+++ clangd/index/SymbolCollector.h
@@ -125,6 +125,11 @@
 
   // All Symbols collected from the AST.
   SymbolSlab::Builder Symbols;
+  // File IDs for Symbol.IncludeHeaders.
+  // The final spelling is calculated in finish().
+  llvm::DenseMap IncludeFiles;
+  // Indexed macros, to be erased if they turned out to be include guards.
+  llvm::DenseSet IndexedMacros;
   // All refs collected from the AST.
   // Only symbols declared in preamble (from #include) and referenced from the
   // main file will be included.
Index: clangd/index/SymbolCollector.cpp
===
--- clangd/index/SymbolCollector.cpp
+++ clangd/index/SymbolCollector.cpp
@@ -352,9 +352,8 @@
   const auto &SM = PP->getSourceManager();
   auto DefLoc = MI->getDefinitionLoc();
 
-  // Header guards are not interesting in index. Builtin macros don't have
-  // useful locations and are not needed for code completions.
-  if (MI->isUsedForHeaderGuard() || MI->isBuiltinMacro())
+  // Builtin macros don't have useful locations and aren't needed in completion.
+  if (MI->isBuiltinMacro())
 return true;
 
   // Skip main-file symbols if we are not collecting them.
@@ -409,17 +408,12 @@
   std::string SnippetSuffix;
   getSignature(*CCS, &Signature, &SnippetSuffix);
 
-  std::string Include;
-  if (Opts.CollectIncludePath && shouldCollectIncludePath(S.SymInfo.Kind)) {
-if (auto Header = getIncludeHeader(
-Name->getName(), SM.getDecomposedExpansionLoc(DefLoc).first))
-  Include = std::move(*Header);
-  }
+  if (Opts.CollectIncludePath && shouldCollectIncludePath(S.SymInfo.Kind))
+IncludeFiles[S.ID] = SM.getDecomposedExpansionLoc(DefLoc).first;
   S.Signature = Signature;
   S.CompletionSnippetSuffix = SnippetSuffix;
-  if (!Include.empty())
-S.IncludeHeaders.emplace_back(Include, 1);
 
+  IndexedMacros.insert(Name);
   Symbols.insert(S);
   return true;
 }
@@ -440,6 +434,14 @@
   }
   if (Opts.CollectMacro) {
 assert(PP);
+// First, drop header guards. We can't identify these until EOF.
+for (const IdentifierInfo *II : IndexedMacros) {
+  if (const auto *MI = PP->getMacroDefinition(II).getMacroInfo())
+if (auto ID = getSymbolID(*II, MI, PP->getSourceManager()))
+  if (MI->isUsedForHeaderGuard())
+Symbols.erase(*ID);
+}
+// Now increment refcounts.
 for (const IdentifierInfo *II : ReferencedMacros) {
   if (co

[PATCH] D61304: [OpenCL][PR41609] Deduce static data members to __global addr space

2019-05-02 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL359789: [OpenCL] Deduce static data members to __global addr 
space. (authored by stulova, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D61304?vs=197299&id=197781#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D61304

Files:
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl


Index: cfe/trunk/lib/Sema/SemaType.cpp
===
--- cfe/trunk/lib/Sema/SemaType.cpp
+++ cfe/trunk/lib/Sema/SemaType.cpp
@@ -7308,8 +7308,10 @@
// otherwise it will fail some sema check.
   IsFuncReturnType || IsFuncType ||
   // Do not deduce addr space for member types of struct, except the 
pointee
-  // type of a pointer member type.
-  (D.getContext() == DeclaratorContext::MemberContext && !IsPointee) ||
+  // type of a pointer member type or static data members.
+  (D.getContext() == DeclaratorContext::MemberContext &&
+   (!IsPointee &&
+D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_static)) ||
   // Do not deduce addr space for types used to define a typedef and the
   // typedef itself, except the pointee type of a pointer type which is 
used
   // to define the typedef.
Index: cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
===
--- cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
+++ cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
@@ -0,0 +1,12 @@
+//RUN: %clang_cc1 %s -cl-std=c++ -pedantic -ast-dump -verify
+
+//expected-no-diagnostics
+
+//CHECK: |-VarDecl  foo {{.*}} 'const __global int' constexpr cinit
+constexpr int foo = 0;
+
+class c {
+public:
+  //CHECK: `-VarDecl {{.*}} foo2 'const __global int' static constexpr cinit
+  static constexpr int foo2 = 0;
+};


Index: cfe/trunk/lib/Sema/SemaType.cpp
===
--- cfe/trunk/lib/Sema/SemaType.cpp
+++ cfe/trunk/lib/Sema/SemaType.cpp
@@ -7308,8 +7308,10 @@
// otherwise it will fail some sema check.
   IsFuncReturnType || IsFuncType ||
   // Do not deduce addr space for member types of struct, except the pointee
-  // type of a pointer member type.
-  (D.getContext() == DeclaratorContext::MemberContext && !IsPointee) ||
+  // type of a pointer member type or static data members.
+  (D.getContext() == DeclaratorContext::MemberContext &&
+   (!IsPointee &&
+D.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_static)) ||
   // Do not deduce addr space for types used to define a typedef and the
   // typedef itself, except the pointee type of a pointer type which is used
   // to define the typedef.
Index: cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
===
--- cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
+++ cfe/trunk/test/SemaOpenCLCXX/address-space-deduction.cl
@@ -0,0 +1,12 @@
+//RUN: %clang_cc1 %s -cl-std=c++ -pedantic -ast-dump -verify
+
+//expected-no-diagnostics
+
+//CHECK: |-VarDecl  foo {{.*}} 'const __global int' constexpr cinit
+constexpr int foo = 0;
+
+class c {
+public:
+  //CHECK: `-VarDecl {{.*}} foo2 'const __global int' static constexpr cinit
+  static constexpr int foo2 = 0;
+};
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D60454: [OpenCL] Prevent mangling kernel functions

2019-05-02 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia updated this revision to Diff 197791.
Anastasia added a comment.

Extended `FunctionDecl` exten C logic to take kernel function into account.


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

https://reviews.llvm.org/D60454

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/Decl.cpp
  lib/Sema/SemaDecl.cpp
  test/CodeGenOpenCLCXX/addrspace-of-this.cl
  test/CodeGenOpenCLCXX/local_addrspace_init.cl
  test/SemaOpenCLCXX/kernel_invalid.cl

Index: test/SemaOpenCLCXX/kernel_invalid.cl
===
--- /dev/null
+++ test/SemaOpenCLCXX/kernel_invalid.cl
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 %s -cl-std=c++ -pedantic -verify -fsyntax-only
+
+struct C {
+  kernel void m(); //expected-error{{kernel functions cannot be class members}}
+};
+
+template 
+kernel void templ(T par) { //expected-error{{kernel functions cannot be used in a template declaration, instantiation or specialization}}
+}
+
+template 
+kernel void bar(int par) { //expected-error{{kernel functions cannot be used in a template declaration, instantiation or specialization}}
+}
+
+kernel void foo(int); //expected-note{{previous declaration is here}}
+
+kernel void foo(float); //expected-error{{conflicting types for 'foo'}}
Index: test/CodeGenOpenCLCXX/local_addrspace_init.cl
===
--- test/CodeGenOpenCLCXX/local_addrspace_init.cl
+++ test/CodeGenOpenCLCXX/local_addrspace_init.cl
@@ -1,8 +1,8 @@
 // RUN: %clang_cc1 %s -triple spir -cl-std=c++ -emit-llvm -O0 -o - | FileCheck %s
 
 // Test that we don't initialize local address space objects.
-//CHECK: @_ZZ4testvE1i = internal addrspace(3) global i32 undef
-//CHECK: @_ZZ4testvE2ii = internal addrspace(3) global %class.C undef
+//CHECK: @_ZZ4testE1i = internal addrspace(3) global i32 undef
+//CHECK: @_ZZ4testE2ii = internal addrspace(3) global %class.C undef
 class C {
   int i;
 };
Index: test/CodeGenOpenCLCXX/addrspace-of-this.cl
===
--- test/CodeGenOpenCLCXX/addrspace-of-this.cl
+++ test/CodeGenOpenCLCXX/addrspace-of-this.cl
@@ -82,7 +82,7 @@
 // EXPL-LABEL: @__cxx_global_var_init()
 // EXPL: call void @_ZNU3AS41CC1Ev(%class.C addrspace(4)* addrspacecast (%class.C addrspace(1)* @c to %class.C addrspace(4)*))
 
-// COMMON-LABEL: @_Z12test__globalv()
+// COMMON-LABEL: @test__global()
 
 // Test the address space of 'this' when invoking a method.
 // COMMON: %call = call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* addrspacecast (%class.C addrspace(1)* @c to %class.C addrspace(4)*))
@@ -149,19 +149,19 @@
 
 TEST(__local)
 
-// COMMON-LABEL: _Z11test__localv
+// COMMON-LABEL: @test__local 
 
 // Test that we don't initialize an object in local address space.
-// EXPL-NOT: call void @_ZNU3AS41CC1Ev(%class.C addrspace(4)* addrspacecast (%class.C addrspace(3)* @_ZZ11test__localvE1c to %class.C addrspace(4)*))
+// EXPL-NOT: call void @_ZNU3AS41CC1Ev(%class.C addrspace(4)* addrspacecast (%class.C addrspace(3)* @_ZZ11test__localE1c to %class.C addrspace(4)*))
 
 // Test the address space of 'this' when invoking a method.
-// COMMON: %call = call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* addrspacecast (%class.C addrspace(3)* @_ZZ11test__localvE1c to %class.C addrspace(4)*))
+// COMMON: %call = call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* addrspacecast (%class.C addrspace(3)* @_ZZ11test__localE1c to %class.C addrspace(4)*))
 
 // Test the address space of 'this' when invoking copy-constructor.
 // COMMON: [[C1GEN:%[0-9]+]] = addrspacecast %class.C* %c1 to %class.C addrspace(4)*
-// EXPL: call void @_ZNU3AS41CC1ERU3AS4KS_(%class.C addrspace(4)* [[C1GEN]], %class.C addrspace(4)* dereferenceable(4) addrspacecast (%class.C addrspace(3)* @_ZZ11test__localvE1c to %class.C addrspace(4)*))
+// EXPL: call void @_ZNU3AS41CC1ERU3AS4KS_(%class.C addrspace(4)* [[C1GEN]], %class.C addrspace(4)* dereferenceable(4) addrspacecast (%class.C addrspace(3)* @_ZZ11test__localE1c to %class.C addrspace(4)*))
 // IMPL:  [[C1VOID:%[0-9]+]] = bitcast %class.C* %c1 to i8*
-// IMPL:  call void @llvm.memcpy.p0i8.p4i8.i32(i8* {{.*}}[[C1VOID]], i8 addrspace(4)* {{.*}}addrspacecast (i8 addrspace(3)* bitcast (%class.C addrspace(3)* @_ZZ11test__localvE1c to i8 addrspace(3)*) to i8 addrspace(4)*), i32 4, i1 false)
+// IMPL:  call void @llvm.memcpy.p0i8.p4i8.i32(i8* {{.*}}[[C1VOID]], i8 addrspace(4)* {{.*}}addrspacecast (i8 addrspace(3)* bitcast (%class.C addrspace(3)* @_ZZ11test__localE1c to i8 addrspace(3)*) to i8 addrspace(4)*), i32 4, i1 false)
 
 // Test the address space of 'this' when invoking a constructor.
 // EXPL: [[C2GEN:%[0-9]+]] = addrspacecast %class.C* %c2 to %class.C addrspace(4)*
@@ -177,7 +177,7 @@
 
 TEST(__private)
 
-// CHECK-LABEL: @_Z13test__privatev
+// CHECK-LABEL: @test__private
 
 // Test the address space of 'this' when invoking a constructor for an object in non-default address space
 // EXPL: [[CGE

[PATCH] D59885: [Lex] Allow to consume tokens while preprocessing

2019-05-02 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov marked an inline comment as not done.
ilya-biryukov added inline comments.



Comment at: clang/lib/Lex/Preprocessor.cpp:956-957
   --LexLevel;
+  if (OnToken)
+OnToken(Result, Source);
 }

ilya-biryukov wrote:
> rsmith wrote:
> > This seems like it's going to be extremely hard to use. If you just want 
> > the expanded token stream, then removing all the other calls to `OnToken` 
> > and only calling it here when `LexLevel == 0` will give you that.
> I've tried `LexLevel == 0 && IsNewToken` and it **almost** works.
> The only trouble left is dealing with the delayed parsing. E.g. I'm getting 
> the callbacks for the same tokens multiple times in cases like parsing of 
> method bodies.
> 
> Any ideas on how to best tackle this?
> 
> The example is:
> ```
> struct X {
>   int method() { return 10; }
>   int a = 10;
> };
> ```
> 
> Seeing multiple callbacks for `{ return 10; }` and `= 10;`, want to see only 
> the first one.
It almost works now, see the update revision.
Almost no tokens get reported by the callback twice now, except the following 
case.
Input:
```
struct X {
  int method() { return method(); }
};
```
After the body of the class, we get a an extra callback for `)` token from one 
of the functions under `ParsedLexedMethodDef`.
This seems to be happening only for parenthesis.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59885



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


[PATCH] D61319: [PR41674] [OpenCL] Fix initialisation of this via pointer

2019-05-02 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks!


Repository:
  rC Clang

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

https://reviews.llvm.org/D61319



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


[PATCH] D61444: Do not warn on switches over enums that do not use [[maybe_unused]] enumerators

2019-05-02 Thread David Blaikie via Phabricator via cfe-commits
dblaikie created this revision.
dblaikie added a reviewer: aaron.ballman.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

PR36231, [dcl.attr.unused]p3


Repository:
  rC Clang

https://reviews.llvm.org/D61444

Files:
  lib/Sema/SemaStmt.cpp
  test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p3.cpp


Index: test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p3.cpp
===
--- test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p3.cpp
+++ test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p3.cpp
@@ -5,9 +5,17 @@
 
 struct [[maybe_unused]] S {};
 
+enum E1 {
+  EnumVal [[maybe_unused]],
+  UsedEnumVal,
+};
+
 void f() {
   int x; // expected-warning {{unused variable}}
   typedef int I; // expected-warning {{unused typedef 'I'}}
+  E1 e;
+  switch (e) { // expected-warning {{enumeration value 'UsedEnumVal' not 
handled in switch}}
+  }
 
   // Should not warn about these due to not being used.
   [[maybe_unused]] int y;
@@ -17,10 +25,16 @@
   S s;
   maybe_unused_int test;
   y = 12;
+  switch (e) {
+  case UsedEnumVal:
+break;
+  }
 }
 
 #ifdef EXT
 // expected-warning@6 {{use of the 'maybe_unused' attribute is a C++17 
extension}}
-// expected-warning@13 {{use of the 'maybe_unused' attribute is a C++17 
extension}}
-// expected-warning@14 {{use of the 'maybe_unused' attribute is a C++17 
extension}}
+// expected-warning@9 {{use of the 'maybe_unused' attribute is a C++17 
extension}}
+// expected-warning@9 {{attributes on an enumerator declaration are a C++17 
extension}}
+// expected-warning@21 {{use of the 'maybe_unused' attribute is a C++17 
extension}}
+// expected-warning@22 {{use of the 'maybe_unused' attribute is a C++17 
extension}}
 #endif
Index: lib/Sema/SemaStmt.cpp
===
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -1162,6 +1162,9 @@
   break;
 }
 
+if (EI->second->hasAttr())
+  continue;
+
 // Drop unneeded case values
 while (CI != CaseVals.end() && CI->first < EI->first)
   CI++;


Index: test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p3.cpp
===
--- test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p3.cpp
+++ test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p3.cpp
@@ -5,9 +5,17 @@
 
 struct [[maybe_unused]] S {};
 
+enum E1 {
+  EnumVal [[maybe_unused]],
+  UsedEnumVal,
+};
+
 void f() {
   int x; // expected-warning {{unused variable}}
   typedef int I; // expected-warning {{unused typedef 'I'}}
+  E1 e;
+  switch (e) { // expected-warning {{enumeration value 'UsedEnumVal' not handled in switch}}
+  }
 
   // Should not warn about these due to not being used.
   [[maybe_unused]] int y;
@@ -17,10 +25,16 @@
   S s;
   maybe_unused_int test;
   y = 12;
+  switch (e) {
+  case UsedEnumVal:
+break;
+  }
 }
 
 #ifdef EXT
 // expected-warning@6 {{use of the 'maybe_unused' attribute is a C++17 extension}}
-// expected-warning@13 {{use of the 'maybe_unused' attribute is a C++17 extension}}
-// expected-warning@14 {{use of the 'maybe_unused' attribute is a C++17 extension}}
+// expected-warning@9 {{use of the 'maybe_unused' attribute is a C++17 extension}}
+// expected-warning@9 {{attributes on an enumerator declaration are a C++17 extension}}
+// expected-warning@21 {{use of the 'maybe_unused' attribute is a C++17 extension}}
+// expected-warning@22 {{use of the 'maybe_unused' attribute is a C++17 extension}}
 #endif
Index: lib/Sema/SemaStmt.cpp
===
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -1162,6 +1162,9 @@
   break;
 }
 
+if (EI->second->hasAttr())
+  continue;
+
 // Drop unneeded case values
 while (CI != CaseVals.end() && CI->first < EI->first)
   CI++;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D42642: [CUDA] Detect installation in PATH

2019-05-02 Thread Michael Kruse via cfe-commits
An update:

I just re-tried creating a symbolic link from inside wsl on drvfs
(case 2). It now created a symlink just as "mklink" does. What might
have changed is that I updated to a newer insider preview or that I
enabled developer mode when I tried the first time.

[1] seems to apply for case 1. [2] has a nice overview about what can
happen here.

Michael

[1] https://github.com/libgit2/libgit2/pull/4713
[2] 
https://stackoverflow.com/questions/11662868/what-happens-when-i-clone-a-repository-with-symlinks-on-windows

Am Do., 2. Mai 2019 um 10:17 Uhr schrieb Alexandre Ganea
:
>
> Thanks Michael, it makes sense. I'm still with the old SVN setup on Windows. 
> WSL uses the NTFS partition through drvfs (your case 2.)
> I'll switch to the git monorepo, it looks like the latest git supports [1] 
> symlinks on Windows (with the restrictions you've mentioned) and they should 
> be mapped properly inside WSL in that case.
>
> Should we then assume symlinks will always work for end-users? Should we 
> validate that somehow, during cmake setup?
>
> Alex.
>
> [1] https://github.com/libgit2/libgit2/pull/4713
>
> -Message d'origine-
> De : Michael Kruse 
> Envoyé : 1 mai 2019 17:23
> À : reviews+d42642+public+5dc9c99d2f2d3...@reviews.llvm.org; Alexandre Ganea 
> via Phabricator 
> Cc : hah...@hahnjo.de; jle...@google.com; t...@google.com; Alexandre Ganea 
> ; cfe-commits ; 
> llvm-commits ; sylvestre.le...@gmail.com
> Objet : Re: [PATCH] D42642: [CUDA] Detect installation in PATH
>
> Hi,
>
> I had my own difficulties with this. It depends on how the repository
> containing the symlink has been checked-out. For instance:
>
> 1. Using a windows git (such as git extensions, mingw-git, git for windows)
> 2. Using git inside wsl on a drvfs mount (i.e. a windows folder
> mounted into the Unix filesystem)
> 3. Using git inside wsl on a lxfs mount (I.e. native mount such as '/')
>
> In case 1. git does not create a Ubuntu symlink. Also, there are no
> Unix symlinks in Windows filesystems, so when Unix tools (such as git)
> request to create a symlink, it creates something else (AFAIR it's a
> text file containing the symlink path, but having lost its symlink
> properties). Case 3 should work.
>
> I still managed to make cases 1 and 2 work by deleting the text file
> and re-creating it with windows's "mklink" tool (which requires either
> admin rights or developer mode turned on). It seems the WSL layer
> translates this as a symlink to the Linux environment.
>
> Michael
>
>
>
>
>
> Am Mi., 1. Mai 2019 um 16:59 Uhr schrieb Alexandre Ganea via
> Phabricator via llvm-commits :
> >
> > aganea added a subscriber: rnk.
> > aganea added a comment.
> >
> > So it turns out this is a symlink issue. The file 
> > `clang/trunk/test/Driver/Inputs/CUDA-symlinks/usr/bin/ptxas` has been 
> > synchronized on my Windows 10 PC as a regular text file, not a symlink. It 
> > looks like TortoiseSVN doesn't implement symlinks. As WSL inherits of my 
> > file system, it will not find the symbolic link. I suppose `REQUIRES: 
> > !system-windows` isn't enough for `cuda-detect-path.cu`, and it would need 
> > something like `REQUIRES: symlinks` along with support in lit. @rnk
> >
> >
> > Repository:
> >   rL LLVM
> >
> > CHANGES SINCE LAST ACTION
> >   https://reviews.llvm.org/D42642/new/
> >
> > https://reviews.llvm.org/D42642
> >
> >
> >
> > ___
> > llvm-commits mailing list
> > llvm-comm...@lists.llvm.org
> > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r359796 - Revert rL359778 : [clangd] Fix code completion of macros defined in the preamble region of the main file.

2019-05-02 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Thu May  2 08:47:33 2019
New Revision: 359796

URL: http://llvm.org/viewvc/llvm-project?rev=359796&view=rev
Log:
Revert rL359778 : [clangd] Fix code completion of macros defined in the 
preamble region of the main file.

Summary:
This is a tricky case (we baked the assumption that symbols come from
the preamble xor mainfile pretty deeply) and the fix is a bit of a hack:
We look at the code to guess the macro names, and deserialize them from
the preamble "by hand".

Reviewers: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

Fix buildbots 
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/47684/

Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=359796&r1=359795&r2=359796&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Thu May  2 08:47:33 2019
@@ -20,8 +20,6 @@
 #include "index/Index.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/Basic/LangOptions.h"
-#include "clang/Basic/SourceManager.h"
-#include "clang/Basic/TokenKinds.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendActions.h"
@@ -96,36 +94,6 @@ private:
   std::vector TopLevelDecls;
 };
 
-class CollectMainFileMacros : public PPCallbacks {
-public:
-  explicit CollectMainFileMacros(const SourceManager &SM,
- std::vector *Out)
-  : SM(SM), Out(Out) {}
-
-  void FileChanged(SourceLocation Loc, FileChangeReason,
-   SrcMgr::CharacteristicKind, FileID Prev) {
-InMainFile = SM.isWrittenInMainFile(Loc);
-  }
-
-  void MacroDefined(const Token &MacroName, const MacroDirective *MD) {
-assert(MacroName.is(tok::identifier));
-if (InMainFile)
-  MainFileMacros.insert(MacroName.getIdentifierInfo()->getName());
-  }
-
-  void EndOfMainFile() {
-for (const auto& Entry : MainFileMacros)
-  Out->push_back(Entry.getKey());
-llvm::sort(*Out);
-  }
-
- private:
-  const SourceManager &SM;
-  bool InMainFile = true;
-  llvm::StringSet<> MainFileMacros;
-  std::vector *Out;
-};
-
 class CppFilePreambleCallbacks : public PreambleCallbacks {
 public:
   CppFilePreambleCallbacks(PathRef File, PreambleParsedCallback ParsedCallback)
@@ -135,10 +103,6 @@ public:
 
   IncludeStructure takeIncludes() { return std::move(Includes); }
 
-  std::vector takeMainFileMacros() {
-return std::move(MainFileMacros);
-  }
-
   CanonicalIncludes takeCanonicalIncludes() { return std::move(CanonIncludes); 
}
 
   void AfterExecute(CompilerInstance &CI) override {
@@ -154,9 +118,7 @@ public:
 
   std::unique_ptr createPPCallbacks() override {
 assert(SourceMgr && "SourceMgr must be set at this point");
-return llvm::make_unique(
-collectIncludeStructureCallback(*SourceMgr, &Includes),
-llvm::make_unique(*SourceMgr, &MainFileMacros));
+return collectIncludeStructureCallback(*SourceMgr, &Includes);
   }
 
   CommentHandler *getCommentHandler() override {
@@ -169,7 +131,6 @@ private:
   PreambleParsedCallback ParsedCallback;
   IncludeStructure Includes;
   CanonicalIncludes CanonIncludes;
-  std::vector MainFileMacros;
   std::unique_ptr IWYUHandler = nullptr;
   SourceManager *SourceMgr = nullptr;
 };
@@ -498,13 +459,11 @@ const CanonicalIncludes &ParsedAST::getC
 
 PreambleData::PreambleData(PrecompiledPreamble Preamble,
std::vector Diags, IncludeStructure Includes,
-   std::vector MainFileMacros,
std::unique_ptr StatCache,
CanonicalIncludes CanonIncludes)
 : Preamble(std::move(Preamble)), Diags(std::move(Diags)),
-  Includes(std::move(Includes)), MainFileMacros(std::move(MainFileMacros)),
-  StatCache(std::move(StatCache)), CanonIncludes(std::move(CanonIncludes)) 
{
-}
+  Includes(std::move(Includes)), StatCache(std::move(StatCache)),
+  CanonIncludes(std::move(CanonIncludes)) {}
 
 ParsedAST::ParsedAST(std::shared_ptr Preamble,
  std::unique_ptr Clang,
@@ -583,8 +542,7 @@ buildPreamble(PathRef FileName, Compiler
 std::vector Diags = PreambleDiagnostics.take();
 return std::make_shared(
 std::move(*BuiltPreamble), std::move(Diags),
-SerializedDeclsCollector.takeIncludes(),
-SerializedDeclsCollector.takeMainFileMacros(), st

[PATCH] D61408: Use primary template parameter names for variable template debug info

2019-05-02 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D61408#1487030 , @dblaikie wrote:

> Seems totally reasonable to me & it's what we do for other templates 
> (function and class), it seems.
>
> Might want to check alias templates too?


Ah, nevermind - alias templates can't be partially specialized. No worries then 
:)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61408



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


[PATCH] D60937: [clangd] Fix code completion of macros defined in the preamble region of the main file.

2019-05-02 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

@sammccall I'm sorry but I had to revert this to fix the buildbots: 
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/47684/


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D60937



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


[PATCH] D60937: [clangd] Fix code completion of macros defined in the preamble region of the main file.

2019-05-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D60937#1487976 , @RKSimon wrote:

> @sammccall I'm sorry but I had to revert this to fix the buildbots: 
> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/47684/


No worries, thanks for reverting.
I think this is just a bad assert, I'll fix it and reland.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D60937



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


[PATCH] D61399: [OpenMP][Clang] Support for target math functions

2019-05-02 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 197798.
gtbercea added a comment.

- Clean-up. Add header.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61399

Files:
  lib/Driver/ToolChains/Clang.cpp
  lib/Headers/CMakeLists.txt
  lib/Headers/__clang_cuda_cmath.h
  lib/Headers/__clang_cuda_device_functions.h
  lib/Headers/__clang_cuda_libdevice_declares.h
  lib/Headers/__clang_cuda_math_forward_declares.h
  lib/Headers/openmp_wrappers/__clang_openmp_math.h
  lib/Headers/openmp_wrappers/cmath
  lib/Headers/openmp_wrappers/math.h

Index: lib/Headers/openmp_wrappers/math.h
===
--- /dev/null
+++ lib/Headers/openmp_wrappers/math.h
@@ -0,0 +1,17 @@
+/*===- math.h - Alternative math.h header --===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+
+#include <__clang_openmp_math.h>
+
+#ifndef __NO_HOST_MATH__
+#include_next 
+#else
+#undef __NO_HOST_MATH__
+#endif
+
Index: lib/Headers/openmp_wrappers/cmath
===
--- /dev/null
+++ lib/Headers/openmp_wrappers/cmath
@@ -0,0 +1,16 @@
+/*===-- cmath - Alternative cmath header ---===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+
+#include <__clang_openmp_math.h>
+
+#ifndef __NO_HOST_MATH__
+#include_next 
+#else
+#undef __NO_HOST_MATH__
+#endif
Index: lib/Headers/openmp_wrappers/__clang_openmp_math.h
===
--- /dev/null
+++ lib/Headers/openmp_wrappers/__clang_openmp_math.h
@@ -0,0 +1,49 @@
+/*=== __clang_openmp_math.h - OpenMP target math support ---===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+
+#if defined(__NVPTX__) && defined(_OPENMP)
+/// TODO:
+/// We are currently reusing the functionality of the Clang-CUDA code path
+/// as an alternative to the host declarations provided by math.h and cmath.
+/// This is suboptimal.
+///
+/// We should instead declare the device functions in a similar way, e.g.,
+/// through OpenMP 5.0 variants, and afterwards populate the module with the
+/// host declarations by unconditionally including the host math.h or cmath,
+/// respectively. This is actually what the Clang-CUDA code path does, using
+/// __device__ instead of variants to avoid redeclarations and get the desired
+/// overload resolution.
+
+#define __CUDA__
+
+#if defined(__cplusplus)
+  #include <__clang_cuda_math_forward_declares.h>
+#endif
+
+// CUDA 9.1 no longer provides declarations for libdevice functions, so we need
+// to provide our own.
+#include <__clang_cuda_libdevice_declares.h>
+
+// Wrappers for many device-side standard library functions became compiler
+// builtins in CUDA-9 and have been removed from the CUDA headers. Clang now
+// provides its own implementation of the wrappers.
+// #if CUDA_VERSION >= 9000
+#include <__clang_cuda_device_functions.h>
+
+#if defined(__cplusplus)
+  #include <__clang_cuda_cmath.h>
+#endif
+
+#undef __CUDA__
+
+/// Magic macro for stopping the math.h/cmath host header from being included.
+#define __NO_HOST_MATH__
+
+#endif
+
Index: lib/Headers/__clang_cuda_math_forward_declares.h
===
--- lib/Headers/__clang_cuda_math_forward_declares.h
+++ lib/Headers/__clang_cuda_math_forward_declares.h
@@ -20,8 +20,12 @@
 // would preclude the use of our own __device__ overloads for these functions.
 
 #pragma push_macro("__DEVICE__")
+#ifdef _OPENMP
+#define __DEVICE__ static __inline__ __attribute__((always_inline))
+#else
 #define __DEVICE__ \
   static __inline__ __attribute__((always_inline)) __attribute__((device))
+#endif
 
 __DEVICE__ double abs(double);
 __DEVICE__ float abs(float);
Index: lib/Headers/__clang_cuda_libdevice_declares.h
===
--- lib/Headers/__clang_cuda_libdevice_declares.h
+++ lib/Headers/__clang_cuda_libdevice_declares.h
@@ -10,443 +10,453 @@
 #ifndef __CLANG_CUDA_LIBDEVICE_DECLARES_H__
 #define __CLANG_CUDA_LIBDEVICE_DECLARES_H__
 
+#if defined(__cplusp

r359798 - [OpenCL] Fix initialisation of this via pointer.

2019-05-02 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Thu May  2 09:10:50 2019
New Revision: 359798

URL: http://llvm.org/viewvc/llvm-project?rev=359798&view=rev
Log:
[OpenCL] Fix initialisation of this via pointer.

When the expression used to initialise 'this' has a pointer type,
check the address space of the pointee type instead of the pointer
type to decide whether an address space cast is required.
It is the pointee type that carries the address space qualifier.

Fixing PR41674.

Patch by kpet (Kevin Petit)!

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


Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=359798&r1=359797&r2=359798&view=diff
==
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu May  2 09:10:50 2019
@@ -5279,12 +5279,12 @@ Sema::PerformObjectArgumentInitializatio
   }
 
   if (!Context.hasSameType(From->getType(), DestType)) {
-if (From->getType().getAddressSpace() != DestType.getAddressSpace())
-  From = ImpCastExprToType(From, DestType, CK_AddressSpaceConversion,
- From->getValueKind()).get();
+CastKind CK;
+if (FromRecordType.getAddressSpace() != DestType.getAddressSpace())
+  CK = CK_AddressSpaceConversion;
 else
-  From = ImpCastExprToType(From, DestType, CK_NoOp,
- From->getValueKind()).get();
+  CK = CK_NoOp;
+From = ImpCastExprToType(From, DestType, CK, From->getValueKind()).get();
   }
   return From;
 }

Modified: cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl?rev=359798&r1=359797&r2=359798&view=diff
==
--- cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl (original)
+++ cfe/trunk/test/CodeGenOpenCLCXX/addrspace-of-this.cl Thu May  2 09:10:50 
2019
@@ -59,7 +59,8 @@ __global C c;
 
 __kernel void test__global() {
   int i = c.get();
-  int i2 = c.outside();
+  int i2 = (&c)->get();
+  int i3 = c.outside();
   C c1(c);
   C c2;
   c2 = c1;
@@ -85,10 +86,12 @@ __kernel void test__global() {
 // COMMON-LABEL: @_Z12test__globalv()
 
 // Test the address space of 'this' when invoking a method.
-// COMMON: %call = call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* 
addrspacecast (%class.C addrspace(1)* @c to %class.C addrspace(4)*))
+// COMMON: call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(1)* @c to %class.C addrspace(4)*))
+// Test the address space of 'this' when invoking a method using a pointer to 
the object.
+// COMMON: call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(1)* @c to %class.C addrspace(4)*))
 
 // Test the address space of 'this' when invoking a method that is declared in 
the file contex.
-// COMMON: %call1 = call i32 @_ZNU3AS41C7outsideEv(%class.C addrspace(4)* 
addrspacecast (%class.C addrspace(1)* @c to %class.C addrspace(4)*))
+// COMMON: call i32 @_ZNU3AS41C7outsideEv(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(1)* @c to %class.C addrspace(4)*))
 
 // Test the address space of 'this' when invoking copy-constructor.
 // COMMON: [[C1GEN:%[0-9]+]] = addrspacecast %class.C* %c1 to %class.C 
addrspace(4)*
@@ -130,7 +133,7 @@ __kernel void test__global() {
 // Test the address space of 'this' when invoking the move assignment
 // COMMON: [[C5GEN:%[0-9]+]] = addrspacecast %class.C* %c5 to %class.C 
addrspace(4)*
 // COMMON: [[CALL:%call[0-9]+]] = call spir_func dereferenceable(4) %class.C 
addrspace(4)* @_Z3foov()
-// EXPL: call void @_ZNU3AS41CC1EOU3AS4S_(%class.C addrspace(4)* 
[[C5GEN:%[0-9]+]], %class.C addrspace(4)* dereferenceable(4) %call4)
+// EXPL: call void @_ZNU3AS41CC1EOU3AS4S_(%class.C addrspace(4)* 
[[C5GEN:%[0-9]+]], %class.C addrspace(4)* dereferenceable(4) [[CALL]])
 // IMPL: [[C5VOID:%[0-9]+]] = bitcast %class.C* %c5 to i8*
 // IMPL: [[CALLVOID:%[0-9]+]] = bitcast %class.C addrspace(4)* [[CALL]] to i8 
addrspace(4)*
 // IMPL: call void @llvm.memcpy.p0i8.p4i8.i32(i8* {{.*}}[[C5VOID]], i8 
addrspace(4)* {{.*}}[[CALLVOID]]
@@ -155,7 +158,7 @@ TEST(__local)
 // EXPL-NOT: call void @_ZNU3AS41CC1Ev(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(3)* @_ZZ11test__localvE1c to %class.C addrspace(4)*))
 
 // Test the address space of 'this' when invoking a method.
-// COMMON: %call = call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* 
addrspacecast (%class.C addrspace(3)* @_ZZ11test__localvE1c to %class.C 
addrspace(4)*))
+// COMMON: call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(3)* @_ZZ11test__localvE1c to %class.C addrspace(4)*))
 
 // Test the address space of 'this' when invo

[PATCH] D61319: [PR41674] [OpenCL] Fix initialisation of this via pointer

2019-05-02 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC359798: [OpenCL] Fix initialisation of this via pointer. 
(authored by stulova, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D61319?vs=197749&id=197800#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D61319

Files:
  lib/Sema/SemaOverload.cpp
  test/CodeGenOpenCLCXX/addrspace-of-this.cl


Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -5279,12 +5279,12 @@
   }
 
   if (!Context.hasSameType(From->getType(), DestType)) {
-if (From->getType().getAddressSpace() != DestType.getAddressSpace())
-  From = ImpCastExprToType(From, DestType, CK_AddressSpaceConversion,
- From->getValueKind()).get();
+CastKind CK;
+if (FromRecordType.getAddressSpace() != DestType.getAddressSpace())
+  CK = CK_AddressSpaceConversion;
 else
-  From = ImpCastExprToType(From, DestType, CK_NoOp,
- From->getValueKind()).get();
+  CK = CK_NoOp;
+From = ImpCastExprToType(From, DestType, CK, From->getValueKind()).get();
   }
   return From;
 }
Index: test/CodeGenOpenCLCXX/addrspace-of-this.cl
===
--- test/CodeGenOpenCLCXX/addrspace-of-this.cl
+++ test/CodeGenOpenCLCXX/addrspace-of-this.cl
@@ -59,7 +59,8 @@
 
 __kernel void test__global() {
   int i = c.get();
-  int i2 = c.outside();
+  int i2 = (&c)->get();
+  int i3 = c.outside();
   C c1(c);
   C c2;
   c2 = c1;
@@ -85,10 +86,12 @@
 // COMMON-LABEL: @_Z12test__globalv()
 
 // Test the address space of 'this' when invoking a method.
-// COMMON: %call = call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* 
addrspacecast (%class.C addrspace(1)* @c to %class.C addrspace(4)*))
+// COMMON: call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(1)* @c to %class.C addrspace(4)*))
+// Test the address space of 'this' when invoking a method using a pointer to 
the object.
+// COMMON: call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(1)* @c to %class.C addrspace(4)*))
 
 // Test the address space of 'this' when invoking a method that is declared in 
the file contex.
-// COMMON: %call1 = call i32 @_ZNU3AS41C7outsideEv(%class.C addrspace(4)* 
addrspacecast (%class.C addrspace(1)* @c to %class.C addrspace(4)*))
+// COMMON: call i32 @_ZNU3AS41C7outsideEv(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(1)* @c to %class.C addrspace(4)*))
 
 // Test the address space of 'this' when invoking copy-constructor.
 // COMMON: [[C1GEN:%[0-9]+]] = addrspacecast %class.C* %c1 to %class.C 
addrspace(4)*
@@ -130,7 +133,7 @@
 // Test the address space of 'this' when invoking the move assignment
 // COMMON: [[C5GEN:%[0-9]+]] = addrspacecast %class.C* %c5 to %class.C 
addrspace(4)*
 // COMMON: [[CALL:%call[0-9]+]] = call spir_func dereferenceable(4) %class.C 
addrspace(4)* @_Z3foov()
-// EXPL: call void @_ZNU3AS41CC1EOU3AS4S_(%class.C addrspace(4)* 
[[C5GEN:%[0-9]+]], %class.C addrspace(4)* dereferenceable(4) %call4)
+// EXPL: call void @_ZNU3AS41CC1EOU3AS4S_(%class.C addrspace(4)* 
[[C5GEN:%[0-9]+]], %class.C addrspace(4)* dereferenceable(4) [[CALL]])
 // IMPL: [[C5VOID:%[0-9]+]] = bitcast %class.C* %c5 to i8*
 // IMPL: [[CALLVOID:%[0-9]+]] = bitcast %class.C addrspace(4)* [[CALL]] to i8 
addrspace(4)*
 // IMPL: call void @llvm.memcpy.p0i8.p4i8.i32(i8* {{.*}}[[C5VOID]], i8 
addrspace(4)* {{.*}}[[CALLVOID]]
@@ -155,7 +158,7 @@
 // EXPL-NOT: call void @_ZNU3AS41CC1Ev(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(3)* @_ZZ11test__localvE1c to %class.C addrspace(4)*))
 
 // Test the address space of 'this' when invoking a method.
-// COMMON: %call = call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* 
addrspacecast (%class.C addrspace(3)* @_ZZ11test__localvE1c to %class.C 
addrspace(4)*))
+// COMMON: call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(3)* @_ZZ11test__localvE1c to %class.C addrspace(4)*))
 
 // Test the address space of 'this' when invoking copy-constructor.
 // COMMON: [[C1GEN:%[0-9]+]] = addrspacecast %class.C* %c1 to %class.C 
addrspace(4)*
@@ -185,7 +188,7 @@
 
 // Test the address space of 'this' when invoking a method.
 // COMMON: [[CGEN:%[0-9]+]] = addrspacecast %class.C* %c to %class.C 
addrspace(4)*
-// COMMON: %call = call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* [[CGEN]])
+// COMMON: call i32 @_ZNU3AS41C3getEv(%class.C addrspace(4)* [[CGEN]])
 
 // Test the address space of 'this' when invoking a copy-constructor.
 // COMMON: [[C1GEN:%[0-9]+]] = addrspacecast %class.C* %c1 to %class.C 
addrspace(4)*
@@ -202,7 +205,7 @@
 // Test the address space of 'this' when invoking a copy-assignment.
 // COMMON: [[C1GEN:%[0-9]+]] = addrspaceca

[clang-tools-extra] r359799 - Reapply r359778: [clangd] Fix code completion of macros defined in the preamble region of the main file.

2019-05-02 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Thu May  2 09:12:36 2019
New Revision: 359799

URL: http://llvm.org/viewvc/llvm-project?rev=359799&view=rev
Log:
Reapply r359778: [clangd] Fix code completion of macros defined in the preamble 
region of the main file.

The bad assert has been removed, and updateOutOfDateIdentifier has been guarded.
This reverts commit r359796.

Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=359799&r1=359798&r2=359799&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Thu May  2 09:12:36 2019
@@ -20,6 +20,8 @@
 #include "index/Index.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendActions.h"
@@ -94,6 +96,35 @@ private:
   std::vector TopLevelDecls;
 };
 
+class CollectMainFileMacros : public PPCallbacks {
+public:
+  explicit CollectMainFileMacros(const SourceManager &SM,
+ std::vector *Out)
+  : SM(SM), Out(Out) {}
+
+  void FileChanged(SourceLocation Loc, FileChangeReason,
+   SrcMgr::CharacteristicKind, FileID Prev) {
+InMainFile = SM.isWrittenInMainFile(Loc);
+  }
+
+  void MacroDefined(const Token &MacroName, const MacroDirective *MD) {
+if (InMainFile)
+  MainFileMacros.insert(MacroName.getIdentifierInfo()->getName());
+  }
+
+  void EndOfMainFile() {
+for (const auto& Entry : MainFileMacros)
+  Out->push_back(Entry.getKey());
+llvm::sort(*Out);
+  }
+
+ private:
+  const SourceManager &SM;
+  bool InMainFile = true;
+  llvm::StringSet<> MainFileMacros;
+  std::vector *Out;
+};
+
 class CppFilePreambleCallbacks : public PreambleCallbacks {
 public:
   CppFilePreambleCallbacks(PathRef File, PreambleParsedCallback ParsedCallback)
@@ -103,6 +134,10 @@ public:
 
   IncludeStructure takeIncludes() { return std::move(Includes); }
 
+  std::vector takeMainFileMacros() {
+return std::move(MainFileMacros);
+  }
+
   CanonicalIncludes takeCanonicalIncludes() { return std::move(CanonIncludes); 
}
 
   void AfterExecute(CompilerInstance &CI) override {
@@ -118,7 +153,9 @@ public:
 
   std::unique_ptr createPPCallbacks() override {
 assert(SourceMgr && "SourceMgr must be set at this point");
-return collectIncludeStructureCallback(*SourceMgr, &Includes);
+return llvm::make_unique(
+collectIncludeStructureCallback(*SourceMgr, &Includes),
+llvm::make_unique(*SourceMgr, &MainFileMacros));
   }
 
   CommentHandler *getCommentHandler() override {
@@ -131,6 +168,7 @@ private:
   PreambleParsedCallback ParsedCallback;
   IncludeStructure Includes;
   CanonicalIncludes CanonIncludes;
+  std::vector MainFileMacros;
   std::unique_ptr IWYUHandler = nullptr;
   SourceManager *SourceMgr = nullptr;
 };
@@ -459,11 +497,13 @@ const CanonicalIncludes &ParsedAST::getC
 
 PreambleData::PreambleData(PrecompiledPreamble Preamble,
std::vector Diags, IncludeStructure Includes,
+   std::vector MainFileMacros,
std::unique_ptr StatCache,
CanonicalIncludes CanonIncludes)
 : Preamble(std::move(Preamble)), Diags(std::move(Diags)),
-  Includes(std::move(Includes)), StatCache(std::move(StatCache)),
-  CanonIncludes(std::move(CanonIncludes)) {}
+  Includes(std::move(Includes)), MainFileMacros(std::move(MainFileMacros)),
+  StatCache(std::move(StatCache)), CanonIncludes(std::move(CanonIncludes)) 
{
+}
 
 ParsedAST::ParsedAST(std::shared_ptr Preamble,
  std::unique_ptr Clang,
@@ -542,7 +582,8 @@ buildPreamble(PathRef FileName, Compiler
 std::vector Diags = PreambleDiagnostics.take();
 return std::make_shared(
 std::move(*BuiltPreamble), std::move(Diags),
-SerializedDeclsCollector.takeIncludes(), std::move(StatCache),
+SerializedDeclsCollector.takeIncludes(),
+SerializedDeclsCollector.takeMainFileMacros(), std::move(StatCache),
 SerializedDeclsCollector.takeCanonicalIncludes());
   } else {
 elog("Could not build a preamble for file {0}", FileName);

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.h?rev=359799&r1=359798&r2=359799&view=diff
==

[PATCH] D61281: [clang-format] Fixed self assignment

2019-05-02 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a reviewer: RKSimon.
RKSimon added a comment.

In D61281#1485833 , @MyDeveloperDay 
wrote:

> Did this cause some issue? Does this fix something if so can we add a test, 
> because maybe the line isn't needed
>
> I would think we'd want to keep this as an identifier. we are just treating 
> arg? the same as we would arg


@MyDeveloperDay didn't you write this code in D58404 
?


Repository:
  rC Clang

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

https://reviews.llvm.org/D61281



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


[PATCH] D60605: [clangd] Revamp textDocument/onTypeFormatting.

2019-05-02 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In D60605#1485375 , @sammccall wrote:

> I'm not able to reproduce this, can you give a complete example?


After adding a newline here:

  int test(bool x) {
if (x)
  return 10; // All spelled tokens are accounted for.
 // that takes two lines^
  }

I get:

  int test(bool x) {
if (x)
  return 10; // All spelled tokens are accounted for.
// that takes two lines
^
  }

Maybe that's due to some extra logic applied in VSCode on top of what we do.
Let me know if this does not reproduce.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D60605



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


[PATCH] D61126: [clangd] Also perform merging for symbol definitions

2019-05-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/XRefs.cpp:350
   if (R.Definition) { // from AST
+// In case of generated files we prefer to omit the definition in the
+// generated code.

Maybe move this below the PreferredDeclaration assignment?

It might just be me, but the generated code case seems much more obscure than 
the AST/index conflict case.



Comment at: clang-tools-extra/clangd/XRefs.cpp:350
   if (R.Definition) { // from AST
+// In case of generated files we prefer to omit the definition in the
+// generated code.

sammccall wrote:
> Maybe move this below the PreferredDeclaration assignment?
> 
> It might just be me, but the generated code case seems much more obscure than 
> the AST/index conflict case.
The connection between the comment and the code seems a little obscure to me.
maybe. // We may still prefer the definition from the index, e.g. for generated 
symbols.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61126



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


[PATCH] D59887: [Syntax] Introduce TokenBuffer, start clangToolingSyntax library

2019-05-02 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 197803.
ilya-biryukov added a comment.

- Get only expanded stream from the preprocessor, recompute mappings and 
spelled stream separately


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59887

Files:
  clang/include/clang/Tooling/Syntax/Tokens.h
  clang/lib/Tooling/CMakeLists.txt
  clang/lib/Tooling/Syntax/CMakeLists.txt
  clang/lib/Tooling/Syntax/Tokens.cpp
  clang/unittests/Tooling/CMakeLists.txt
  clang/unittests/Tooling/Syntax/CMakeLists.txt
  clang/unittests/Tooling/Syntax/TokensTest.cpp

Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -0,0 +1,622 @@
+//===- TokensTest.cpp -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Tooling/Syntax/Tokens.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/Expr.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/DiagnosticIDs.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/FileManager.h"
+#include "clang/Basic/FileSystemOptions.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/TokenKinds.def"
+#include "clang/Basic/TokenKinds.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Frontend/Utils.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "clang/Lex/Token.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/None.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/Support/raw_os_ostream.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Testing/Support/Annotations.h"
+#include "llvm/Testing/Support/SupportHelpers.h"
+#include "gmock/gmock-matchers.h"
+#include "gmock/gmock-more-matchers.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace clang;
+using namespace clang::syntax;
+
+using llvm::ValueIs;
+using ::testing::AllOf;
+using ::testing::Contains;
+using ::testing::ElementsAre;
+using ::testing::Matcher;
+using ::testing::Not;
+using ::testing::StartsWith;
+
+namespace {
+// Checks the passed ArrayRef has the same begin() and end() iterators as the
+// argument.
+MATCHER_P(SameRange, A, "") {
+  return A.begin() == arg.begin() && A.end() == arg.end();
+}
+// Matchers for syntax::Token.
+MATCHER_P(Kind, K, "") { return arg.kind() == K; }
+MATCHER_P2(HasText, Text, SourceMgr, "") {
+  return arg.text(*SourceMgr) == Text;
+}
+/// Checks the start and end location of a token are equal to SourceRng.
+MATCHER_P(RangeIs, SourceRng, "") {
+  return arg.location() == SourceRng.first &&
+ arg.endLocation() == SourceRng.second;
+}
+
+class TokenCollectorTest : public ::testing::Test {
+public:
+  /// Run the clang frontend, collect the preprocessed tokens from the frontend
+  /// invocation and store them in this->Buffer.
+  /// This also clears SourceManager before running the compiler.
+  void recordTokens(llvm::StringRef Code) {
+class RecordTokens : public ASTFrontendAction {
+public:
+  explicit RecordTokens(TokenBuffer &Result) : Result(Result) {}
+
+  bool BeginSourceFileAction(CompilerInstance &CI) override {
+assert(!Collector && "expected only a single call to BeginSourceFile");
+Collector.emplace(CI.getPreprocessor());
+return true;
+  }
+  void EndSourceFileAction() override {
+assert(Collector && "BeginSourceFileAction was never called");
+Result = std::move(*Collector).consume();
+  }
+
+  std::unique_ptr
+  CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override {
+return llvm::make_unique();
+  }
+
+private:
+  TokenBuffer &Result;
+  llvm::Optional Collector;
+};
+
+constexpr const char *FileName = "./input.cpp";
+FS->addFile(FileName, time_t(), llvm::MemoryBuffer::getMemBufferCopy(""));
+// Prepare to run a compiler.
+std::vector Args = {"tok-test", "-std=c++03", "-fsyntax-only",
+  FileName};
+auto CI = createInvocationFromCommandLine(Args, Diags, FS);
+assert(CI);
+CI->getFrontendOpts().DisableFree = false;

[PATCH] D61444: Do not warn on switches over enums that do not use [[maybe_unused]] enumerators

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

LGTM!


Repository:
  rC Clang

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

https://reviews.llvm.org/D61444



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


r359800 - Do not warn on switches over enums that do not use [[maybe_unused]] enumerators

2019-05-02 Thread David Blaikie via cfe-commits
Author: dblaikie
Date: Thu May  2 09:30:49 2019
New Revision: 359800

URL: http://llvm.org/viewvc/llvm-project?rev=359800&view=rev
Log:
Do not warn on switches over enums that do not use [[maybe_unused]] enumerators

PR36231, [dcl.attr.unused]p3

Reviewers: aaron.ballman

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

Modified:
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p3.cpp

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=359800&r1=359799&r2=359800&view=diff
==
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Thu May  2 09:30:49 2019
@@ -1162,6 +1162,9 @@ Sema::ActOnFinishSwitchStmt(SourceLocati
   break;
 }
 
+if (EI->second->hasAttr())
+  continue;
+
 // Drop unneeded case values
 while (CI != CaseVals.end() && CI->first < EI->first)
   CI++;

Modified: cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p3.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p3.cpp?rev=359800&r1=359799&r2=359800&view=diff
==
--- cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p3.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p3.cpp Thu May  2 
09:30:49 2019
@@ -5,9 +5,17 @@ static_assert(__has_cpp_attribute(maybe_
 
 struct [[maybe_unused]] S {};
 
+enum E1 {
+  EnumVal [[maybe_unused]],
+  UsedEnumVal,
+};
+
 void f() {
   int x; // expected-warning {{unused variable}}
   typedef int I; // expected-warning {{unused typedef 'I'}}
+  E1 e;
+  switch (e) { // expected-warning {{enumeration value 'UsedEnumVal' not 
handled in switch}}
+  }
 
   // Should not warn about these due to not being used.
   [[maybe_unused]] int y;
@@ -17,10 +25,16 @@ void f() {
   S s;
   maybe_unused_int test;
   y = 12;
+  switch (e) {
+  case UsedEnumVal:
+break;
+  }
 }
 
 #ifdef EXT
 // expected-warning@6 {{use of the 'maybe_unused' attribute is a C++17 
extension}}
-// expected-warning@13 {{use of the 'maybe_unused' attribute is a C++17 
extension}}
-// expected-warning@14 {{use of the 'maybe_unused' attribute is a C++17 
extension}}
+// expected-warning@9 {{use of the 'maybe_unused' attribute is a C++17 
extension}}
+// expected-warning@9 {{attributes on an enumerator declaration are a C++17 
extension}}
+// expected-warning@21 {{use of the 'maybe_unused' attribute is a C++17 
extension}}
+// expected-warning@22 {{use of the 'maybe_unused' attribute is a C++17 
extension}}
 #endif


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


[PATCH] D61444: Do not warn on switches over enums that do not use [[maybe_unused]] enumerators

2019-05-02 Thread David Blaikie via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC359800: Do not warn on switches over enums that do not use 
[[maybe_unused]] enumerators (authored by dblaikie, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D61444?vs=197794&id=197806#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D61444

Files:
  lib/Sema/SemaStmt.cpp
  test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p3.cpp


Index: test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p3.cpp
===
--- test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p3.cpp
+++ test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p3.cpp
@@ -5,9 +5,17 @@
 
 struct [[maybe_unused]] S {};
 
+enum E1 {
+  EnumVal [[maybe_unused]],
+  UsedEnumVal,
+};
+
 void f() {
   int x; // expected-warning {{unused variable}}
   typedef int I; // expected-warning {{unused typedef 'I'}}
+  E1 e;
+  switch (e) { // expected-warning {{enumeration value 'UsedEnumVal' not 
handled in switch}}
+  }
 
   // Should not warn about these due to not being used.
   [[maybe_unused]] int y;
@@ -17,10 +25,16 @@
   S s;
   maybe_unused_int test;
   y = 12;
+  switch (e) {
+  case UsedEnumVal:
+break;
+  }
 }
 
 #ifdef EXT
 // expected-warning@6 {{use of the 'maybe_unused' attribute is a C++17 
extension}}
-// expected-warning@13 {{use of the 'maybe_unused' attribute is a C++17 
extension}}
-// expected-warning@14 {{use of the 'maybe_unused' attribute is a C++17 
extension}}
+// expected-warning@9 {{use of the 'maybe_unused' attribute is a C++17 
extension}}
+// expected-warning@9 {{attributes on an enumerator declaration are a C++17 
extension}}
+// expected-warning@21 {{use of the 'maybe_unused' attribute is a C++17 
extension}}
+// expected-warning@22 {{use of the 'maybe_unused' attribute is a C++17 
extension}}
 #endif
Index: lib/Sema/SemaStmt.cpp
===
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -1162,6 +1162,9 @@
   break;
 }
 
+if (EI->second->hasAttr())
+  continue;
+
 // Drop unneeded case values
 while (CI != CaseVals.end() && CI->first < EI->first)
   CI++;


Index: test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p3.cpp
===
--- test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p3.cpp
+++ test/CXX/dcl.dcl/dcl.attr/dcl.attr.unused/p3.cpp
@@ -5,9 +5,17 @@
 
 struct [[maybe_unused]] S {};
 
+enum E1 {
+  EnumVal [[maybe_unused]],
+  UsedEnumVal,
+};
+
 void f() {
   int x; // expected-warning {{unused variable}}
   typedef int I; // expected-warning {{unused typedef 'I'}}
+  E1 e;
+  switch (e) { // expected-warning {{enumeration value 'UsedEnumVal' not handled in switch}}
+  }
 
   // Should not warn about these due to not being used.
   [[maybe_unused]] int y;
@@ -17,10 +25,16 @@
   S s;
   maybe_unused_int test;
   y = 12;
+  switch (e) {
+  case UsedEnumVal:
+break;
+  }
 }
 
 #ifdef EXT
 // expected-warning@6 {{use of the 'maybe_unused' attribute is a C++17 extension}}
-// expected-warning@13 {{use of the 'maybe_unused' attribute is a C++17 extension}}
-// expected-warning@14 {{use of the 'maybe_unused' attribute is a C++17 extension}}
+// expected-warning@9 {{use of the 'maybe_unused' attribute is a C++17 extension}}
+// expected-warning@9 {{attributes on an enumerator declaration are a C++17 extension}}
+// expected-warning@21 {{use of the 'maybe_unused' attribute is a C++17 extension}}
+// expected-warning@22 {{use of the 'maybe_unused' attribute is a C++17 extension}}
 #endif
Index: lib/Sema/SemaStmt.cpp
===
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -1162,6 +1162,9 @@
   break;
 }
 
+if (EI->second->hasAttr())
+  continue;
+
 // Drop unneeded case values
 while (CI != CaseVals.end() && CI->first < EI->first)
   CI++;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D61422: [clang-tidy] Extend bugprone-sizeof-expression check to detect sizeof misuse in pointer arithmetic

2019-05-02 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Out of curiosity, have you run this over any large code bases to see what the 
false positive and true positive rate is?




Comment at: clang-tidy/bugprone/SizeofExpressionCheck.cpp:217
+  // Detect sizeof in pointer aritmetic like: N * sizeof(S) == P1 - P2 or
+  // (P1 - P2) / sizeof(S) where P1 and P2 are pointers to type S
+  const auto PtrDiffExpr = binaryOperator(

Missing full stop at the end of the comment.


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

https://reviews.llvm.org/D61422



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


[clang-tools-extra] r359801 - Fixed: Duck-typing in readability-redundant-smartptr-get didn't catch MSVC STL smart pointers.

2019-05-02 Thread Florian Gross via cfe-commits
Author: fgross
Date: Thu May  2 09:41:28 2019
New Revision: 359801

URL: http://llvm.org/viewvc/llvm-project?rev=359801&view=rev
Log:
Fixed: Duck-typing in readability-redundant-smartptr-get didn't catch MSVC STL 
smart pointers.

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

Added:

clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get-msvc.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/readability/RedundantSmartptrGetCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/RedundantSmartptrGetCheck.cpp?rev=359801&r1=359800&r2=359801&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/readability/RedundantSmartptrGetCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/readability/RedundantSmartptrGetCheck.cpp 
Thu May  2 09:41:28 2019
@@ -30,6 +30,10 @@ internal::Matcher callToGet(const
   .bind("redundant_get");
 }
 
+internal::Matcher knownSmartptr() {
+  return recordDecl(hasAnyName("::std::unique_ptr", "::std::shared_ptr"));
+}
+
 void registerMatchersForGetArrowStart(MatchFinder *Finder,
   MatchFinder::MatchCallback *Callback) {
   const auto QuacksLikeASmartptr = recordDecl(
@@ -39,21 +43,23 @@ void registerMatchersForGetArrowStart(Ma
   has(cxxMethodDecl(hasName("operator*"), returns(qualType(references(
   type().bind("op*Type")));
 
+  // Make sure we are not missing the known standard types.
+  const auto Smartptr = anyOf(knownSmartptr(), QuacksLikeASmartptr);
+
   // Catch 'ptr.get()->Foo()'
-  Finder->addMatcher(memberExpr(expr().bind("memberExpr"), isArrow(),
-hasObjectExpression(ignoringImpCasts(
-callToGet(QuacksLikeASmartptr,
- Callback);
+  Finder->addMatcher(
+  memberExpr(expr().bind("memberExpr"), isArrow(),
+ hasObjectExpression(ignoringImpCasts(callToGet(Smartptr,
+  Callback);
 
   // Catch '*ptr.get()' or '*ptr->get()'
   Finder->addMatcher(
-  unaryOperator(hasOperatorName("*"),
-hasUnaryOperand(callToGet(QuacksLikeASmartptr))),
+  unaryOperator(hasOperatorName("*"), 
hasUnaryOperand(callToGet(Smartptr))),
   Callback);
 
   // Catch '!ptr.get()'
-  const auto CallToGetAsBool = ignoringParenImpCasts(callToGet(recordDecl(
-  QuacksLikeASmartptr, has(cxxConversionDecl(returns(booleanType()));
+  const auto CallToGetAsBool = ignoringParenImpCasts(callToGet(
+  recordDecl(Smartptr, has(cxxConversionDecl(returns(booleanType()));
   Finder->addMatcher(
   unaryOperator(hasOperatorName("!"), hasUnaryOperand(CallToGetAsBool)),
   Callback);
@@ -71,10 +77,7 @@ void registerMatchersForGetEquals(MatchF
   // This one is harder to do with duck typing.
   // The operator==/!= that we are looking for might be member or non-member,
   // might be on global namespace or found by ADL, might be a template, etc.
-  // For now, lets keep a list of known standard types.
-
-  const auto IsAKnownSmartptr =
-  recordDecl(hasAnyName("::std::unique_ptr", "::std::shared_ptr"));
+  // For now, lets keep it to the known standard types.
 
   // Matches against nullptr.
   Finder->addMatcher(
@@ -82,7 +85,7 @@ void registerMatchersForGetEquals(MatchF
  hasEitherOperand(ignoringImpCasts(
  anyOf(cxxNullPtrLiteralExpr(), gnuNullExpr(),
integerLiteral(equals(0),
- hasEitherOperand(callToGet(IsAKnownSmartptr))),
+ hasEitherOperand(callToGet(knownSmartptr(,
   Callback);
 
   // FIXME: Match and fix if (l.get() == r.get()).

Added: 
clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get-msvc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get-msvc.cpp?rev=359801&view=auto
==
--- 
clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get-msvc.cpp
 (added)
+++ 
clang-tools-extra/trunk/test/clang-tidy/readability-redundant-smartptr-get-msvc.cpp
 Thu May  2 09:41:28 2019
@@ -0,0 +1,94 @@
+// RUN: %check_clang_tidy %s readability-redundant-smartptr-get %t
+
+#define NULL __null
+
+namespace std {
+
+// MSVC headers define operator templates instead of plain operators.
+
+template 
+struct unique_ptr {
+  template 
+  T2& operator*() const;
+  template 
+  T2* operator->() const;
+  T* get() const;
+  explicit operator bool() const noexcept;
+};
+
+template 
+struct shared_ptr {
+  template 
+  T2& operator*() const;
+  template 
+  T2* operator->() const;
+  T* get() const;
+  explicit operat

[PATCH] D61209: [clang-tidy] Fix readability-redundant-smartptr-get for MSVC STL

2019-05-02 Thread Florian Gross via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE359801: Fixed: Duck-typing in 
readability-redundant-smartptr-get didn't catch MSVC STL… (authored by 
fgross, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D61209?vs=196960&id=197809#toc

Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D61209

Files:
  clang-tidy/readability/RedundantSmartptrGetCheck.cpp
  test/clang-tidy/readability-redundant-smartptr-get-msvc.cpp

Index: test/clang-tidy/readability-redundant-smartptr-get-msvc.cpp
===
--- test/clang-tidy/readability-redundant-smartptr-get-msvc.cpp
+++ test/clang-tidy/readability-redundant-smartptr-get-msvc.cpp
@@ -0,0 +1,94 @@
+// RUN: %check_clang_tidy %s readability-redundant-smartptr-get %t
+
+#define NULL __null
+
+namespace std {
+
+// MSVC headers define operator templates instead of plain operators.
+
+template 
+struct unique_ptr {
+  template 
+  T2& operator*() const;
+  template 
+  T2* operator->() const;
+  T* get() const;
+  explicit operator bool() const noexcept;
+};
+
+template 
+struct shared_ptr {
+  template 
+  T2& operator*() const;
+  template 
+  T2* operator->() const;
+  T* get() const;
+  explicit operator bool() const noexcept;
+};
+
+}  // namespace std
+
+struct Bar {
+  void Do();
+  void ConstDo() const;
+};
+
+void Positive() {
+  std::unique_ptr* up;
+  (*up->get()).Do();
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: redundant get() call
+  // CHECK-MESSAGES: (*up->get()).Do();
+  // CHECK-FIXES: (**up).Do();
+
+  std::unique_ptr uu;
+  std::shared_ptr *ss;
+  bool bb = uu.get() == nullptr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: redundant get() call
+  // CHECK-MESSAGES: uu.get() == nullptr;
+  // CHECK-FIXES: bool bb = uu == nullptr;
+
+  if (up->get());
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call
+  // CHECK-MESSAGES: if (up->get());
+  // CHECK-FIXES: if (*up);
+  if ((uu.get()));
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
+  // CHECK-MESSAGES: if ((uu.get()));
+  // CHECK-FIXES: if ((uu));
+  bb = !ss->get();
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: redundant get() call
+  // CHECK-MESSAGES: bb = !ss->get();
+  // CHECK-FIXES: bb = !*ss;
+
+  bb = nullptr != ss->get();
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: redundant get() call
+  // CHECK-MESSAGES: nullptr != ss->get();
+  // CHECK-FIXES: bb = nullptr != *ss;
+
+  bb = std::unique_ptr().get() == NULL;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
+  // CHECK-MESSAGES: bb = std::unique_ptr().get() == NULL;
+  // CHECK-FIXES: bb = std::unique_ptr() == NULL;
+  bb = ss->get() == NULL;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: redundant get() call
+  // CHECK-MESSAGES: bb = ss->get() == NULL;
+  // CHECK-FIXES: bb = *ss == NULL;
+
+  std::unique_ptr x, y;
+  if (x.get() == nullptr);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call
+  // CHECK-MESSAGES: if (x.get() == nullptr);
+  // CHECK-FIXES: if (x == nullptr);
+  if (nullptr == y.get());
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: redundant get() call
+  // CHECK-MESSAGES: if (nullptr == y.get());
+  // CHECK-FIXES: if (nullptr == y);
+  if (x.get() == NULL);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant get() call
+  // CHECK-MESSAGES: if (x.get() == NULL);
+  // CHECK-FIXES: if (x == NULL);
+  if (NULL == x.get());
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: redundant get() call
+  // CHECK-MESSAGES: if (NULL == x.get());
+  // CHECK-FIXES: if (NULL == x);
+}
Index: clang-tidy/readability/RedundantSmartptrGetCheck.cpp
===
--- clang-tidy/readability/RedundantSmartptrGetCheck.cpp
+++ clang-tidy/readability/RedundantSmartptrGetCheck.cpp
@@ -30,6 +30,10 @@
   .bind("redundant_get");
 }
 
+internal::Matcher knownSmartptr() {
+  return recordDecl(hasAnyName("::std::unique_ptr", "::std::shared_ptr"));
+}
+
 void registerMatchersForGetArrowStart(MatchFinder *Finder,
   MatchFinder::MatchCallback *Callback) {
   const auto QuacksLikeASmartptr = recordDecl(
@@ -39,21 +43,23 @@
   has(cxxMethodDecl(hasName("operator*"), returns(qualType(references(
   type().bind("op*Type")));
 
+  // Make sure we are not missing the known standard types.
+  const auto Smartptr = anyOf(knownSmartptr(), QuacksLikeASmartptr);
+
   // Catch 'ptr.get()->Foo()'
-  Finder->addMatcher(memberExpr(expr().bind("memberExpr"), isArrow(),
-hasObjectExpression(ignoringImpCasts(
-callToGet(QuacksLikeASmartptr,
- Callback);
+  Finder->addMatcher(
+  memberExpr(expr().bind("memberExpr"), isArrow(),
+ 

[PATCH] D59885: [Lex] Allow to consume tokens while preprocessing

2019-05-02 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov marked an inline comment as not done.
ilya-biryukov added inline comments.



Comment at: clang/lib/Lex/Preprocessor.cpp:956-957
   --LexLevel;
+  if (OnToken)
+OnToken(Result, Source);
 }

ilya-biryukov wrote:
> ilya-biryukov wrote:
> > rsmith wrote:
> > > This seems like it's going to be extremely hard to use. If you just want 
> > > the expanded token stream, then removing all the other calls to `OnToken` 
> > > and only calling it here when `LexLevel == 0` will give you that.
> > I've tried `LexLevel == 0 && IsNewToken` and it **almost** works.
> > The only trouble left is dealing with the delayed parsing. E.g. I'm getting 
> > the callbacks for the same tokens multiple times in cases like parsing of 
> > method bodies.
> > 
> > Any ideas on how to best tackle this?
> > 
> > The example is:
> > ```
> > struct X {
> >   int method() { return 10; }
> >   int a = 10;
> > };
> > ```
> > 
> > Seeing multiple callbacks for `{ return 10; }` and `= 10;`, want to see 
> > only the first one.
> It almost works now, see the update revision.
> Almost no tokens get reported by the callback twice now, except the following 
> case.
> Input:
> ```
> struct X {
>   int method() { return method(); }
> };
> ```
> After the body of the class, we get a an extra callback for `)` token from 
> one of the functions under `ParsedLexedMethodDef`.
> This seems to be happening only for parenthesis.
More precisely, this happens from a following sequence of calls:

```
Lex() {LexLevel=0}
CachingLex() {LexLevel=1} // which does not have a token in `CachedTokens`, so 
it recurses into ...
Lex() {LexLevel=1}// which results in a call to ...
CurTokenLexer->Lex()
```

At this point `CurTokenLexer` returns a token of a pre-lexed method definition, 
but the current implementation forgets that this was the case by the time the 
token is processed at the the top of the callstack (`Lex() {LexLevel=0}`).
So the token ends up being reported by a callback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59885



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


[PATCH] D61452: [WebAssembly] Always include /lib in library path

2019-05-02 Thread Sam Clegg via Phabricator via cfe-commits
sbc100 created this revision.
Herald added subscribers: cfe-commits, sunfish, aheejin, jgravelle-google, 
dschuff.
Herald added a project: clang.

Even though the toolchain supports multiarch, we still want to
be able to support single-arch sysroots.

This also helps for the case where libraries don't correctly install to
the multi-arch directory.

This matches the behavior of the linux toolchain and of gcc.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D61452

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


Index: clang/lib/Driver/ToolChains/WebAssembly.cpp
===
--- clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -106,17 +106,17 @@
 
   getProgramPaths().push_back(getDriver().getInstalledDir());
 
-  if (getTriple().getOS() == llvm::Triple::UnknownOS) {
+  if (getTriple().getOS() != llvm::Triple::UnknownOS) {
 // Theoretically an "unknown" OS should mean no standard libraries, however
 // it could also mean that a custom set of libraries is in use, so just add
 // /lib to the search path. Disable multiarch in this case, to discourage
 // paths containing "unknown" from acquiring meanings.
-getFilePaths().push_back(getDriver().SysRoot + "/lib");
-  } else {
 const std::string MultiarchTriple =
 getMultiarchTriple(getDriver(), Triple, getDriver().SysRoot);
 getFilePaths().push_back(getDriver().SysRoot + "/lib/" + MultiarchTriple);
   }
+
+  getFilePaths().push_back(getDriver().SysRoot + "/lib");
 }
 
 bool WebAssembly::IsMathErrnoDefault() const { return false; }


Index: clang/lib/Driver/ToolChains/WebAssembly.cpp
===
--- clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -106,17 +106,17 @@
 
   getProgramPaths().push_back(getDriver().getInstalledDir());
 
-  if (getTriple().getOS() == llvm::Triple::UnknownOS) {
+  if (getTriple().getOS() != llvm::Triple::UnknownOS) {
 // Theoretically an "unknown" OS should mean no standard libraries, however
 // it could also mean that a custom set of libraries is in use, so just add
 // /lib to the search path. Disable multiarch in this case, to discourage
 // paths containing "unknown" from acquiring meanings.
-getFilePaths().push_back(getDriver().SysRoot + "/lib");
-  } else {
 const std::string MultiarchTriple =
 getMultiarchTriple(getDriver(), Triple, getDriver().SysRoot);
 getFilePaths().push_back(getDriver().SysRoot + "/lib/" + MultiarchTriple);
   }
+
+  getFilePaths().push_back(getDriver().SysRoot + "/lib");
 }
 
 bool WebAssembly::IsMathErrnoDefault() const { return false; }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D60974: Clang IFSO driver action.

2019-05-02 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi marked an inline comment as done.
plotfi added a comment.

In D60974#1486631 , @jakehehrlich 
wrote:

> In D60974#1486384 , @compnerd wrote:
>
> > @jakehehrlich - unfortunately, removing the attributes on the sections will 
> > make the content look different with `nm` which is something we do need to 
> > appear proper for consumers of the interface libraries.  Versioning has a 
> > number of problems inherent to it (unfortunately, its the closest to 
> > multi-level namespaces in ELF).  I think that getting something in tree and 
> > iterating on it is far better than continuing to argue over this in the 
> > dream of something that unifies the TAPI approach and this approach.  The 
> > section names are relevant (you can add attributes to put symbols into 
> > alternate sections and you can have section relative relocations).  I think 
> > that you are loosing fidelity in the final output which is sufficient for 
> > your needs, but I think that there are places where the full fidelity can 
> > be needed.
> >
> > This currently works and allows us to generate the interface library which 
> > means that this is actually further than what you are proposing still.  Is 
> > there something technical that this is doing incorrectly or breaking 
> > something?  Otherwise, this really does seem like it is devolving into a 
> > bike shedding argument that isn't really going anywhere.  This is not a 
> > large amount of code and there is backing to maintain it, so it is not an 
> > issue of "this is adding un-maintained complexity" either.
> >
> > Just like the LLVM APIs, this can/will evolve.  I don't see why this needs 
> > to be set in stone from the initial implementation.  There are use cases 
> > which can come up which require reworking the solution.
>
>
>
>
> 1. The output of nm when you give it what exactly is different? What output 
> are you expecting? You aren't making that specific. Passing the unmerged 
> output though nm doesn't make any sense. If you have a precise use case for 
> section names you should mention it. We can always add symbol information 
> back as needed if we first start with something more minimal. What output of 
> nm are you expecting a
> 2. We're basically in agreement on what should happen here. I don't think 
> it's a dream of unifying these things. It looks like a very close reality to 
> me.
> 3. You mention sections and relocation as being relevant information. Can you 
> give a specific use case? Section names in general are not meaningful 
> information. They're just there for humans to debug things. Putting symbols 
> in different sections lets the linker treat them specially but in the end 
> binary sections are not relevant to much of anything.


Jake, I am still not sure what you would prefer for moving forward. The current 
patch can output the yaml format I originally proposed or the one that looks 
similar to the one you proposed. What I need to know is:

- Do you want the merging if the "ifo" files to happen inside of llvm-elfabi?
- Do you care if we upstream the yaml we proposed as a first step (which is 
really a distilled version of that yaml2obj can consume anyways. this right now 
functions actually) ???
- Or, would you rather the ifo files be merged by a different separate tool 
(something maybe called llvm-ifsogen)???


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60974



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


[libunwind] r359804 - [gn] Support for building libunwind

2019-05-02 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Thu May  2 10:29:37 2019
New Revision: 359804

URL: http://llvm.org/viewvc/llvm-project?rev=359804&view=rev
Log:
[gn] Support for building libunwind

This change introduces support for building libuwind. The library
build should be complete, but not all CMake options have been
replicated in GN. We also don't support tests yet.

We only support two stage build at the moment.

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

Modified:
libunwind/trunk/src/CMakeLists.txt

Modified: libunwind/trunk/src/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/CMakeLists.txt?rev=359804&r1=359803&r2=359804&view=diff
==
--- libunwind/trunk/src/CMakeLists.txt (original)
+++ libunwind/trunk/src/CMakeLists.txt Thu May  2 10:29:37 2019
@@ -3,20 +3,23 @@
 set(LIBUNWIND_CXX_SOURCES
 libunwind.cpp
 Unwind-EHABI.cpp
-Unwind-seh.cpp)
+Unwind-seh.cpp
+)
 unwind_append_if(LIBUNWIND_CXX_SOURCES APPLE Unwind_AppleExtras.cpp)
 
 set(LIBUNWIND_C_SOURCES
 UnwindLevel1.c
 UnwindLevel1-gcc-ext.c
-Unwind-sjlj.c)
+Unwind-sjlj.c
+)
 set_source_files_properties(${LIBUNWIND_C_SOURCES}
 PROPERTIES
   COMPILE_FLAGS "-std=c99")
 
 set(LIBUNWIND_ASM_SOURCES
 UnwindRegistersRestore.S
-UnwindRegistersSave.S)
+UnwindRegistersSave.S
+)
 set_source_files_properties(${LIBUNWIND_ASM_SOURCES}
 PROPERTIES
   LANGUAGE C)
@@ -33,11 +36,13 @@ set(LIBUNWIND_HEADERS
 Registers.hpp
 RWMutex.hpp
 UnwindCursor.hpp
-${CMAKE_CURRENT_SOURCE_DIR}/../include/libunwind.h
-${CMAKE_CURRENT_SOURCE_DIR}/../include/unwind.h)
+../include/libunwind.h
+../include/unwind.h
+)
 
 unwind_append_if(LIBUNWIND_HEADERS APPLE
-  
"${CMAKE_CURRENT_SOURCE_DIR}/../include/mach-o/compact_unwind_encoding.h")
+../include/mach-o/compact_unwind_encoding.h
+)
 
 if (MSVC_IDE)
   # Force them all into the headers dir on MSVC, otherwise they end up at


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


[PATCH] D61399: [OpenMP][Clang] Support for target math functions

2019-05-02 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel accepted this revision.
hfinkel added inline comments.
This revision is now accepted and ready to land.



Comment at: lib/Driver/ToolChains/Clang.cpp:1163
+  llvm::sys::path::append(P, "openmp_wrappers");
+  CmdArgs.push_back("-internal-isystem");
+  CmdArgs.push_back(Args.MakeArgString(P));

Please add a driver test covering this.



Comment at: lib/Headers/openmp_wrappers/__clang_openmp_math.h:20
+/// respectively. This is actually what the Clang-CUDA code path does, using
+/// __device__ instead of variants to avoid redeclarations and get the desired
+/// overload resolution.

And this is why I wanted to just make `__device__` work in OpenMP mode. But, as 
a temporary solution until we get `declare variant` working, I'm okay with this.

Modulo the naming nit and the missing driver test, LGTM.



Comment at: lib/Headers/openmp_wrappers/__clang_openmp_math.h:46
+/// Magic macro for stopping the math.h/cmath host header from being included.
+#define __NO_HOST_MATH__
+

I'd prefer that, as this is clang specific, we make this clear by naming this 
`__CLANG_NO_HOST_MATH__`.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61399



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


[PATCH] D51329: [Attribute/Diagnostics] Print macro if definition is an attribute declaration

2019-05-02 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

*ping*


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D51329



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


[PATCH] D61408: Use primary template parameter names for variable template debug info

2019-05-02 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

In D61408#1487978 , @dblaikie wrote:

> Ah, nevermind - alias templates can't be partially specialized. No worries 
> then :)


That, and I think alias templates can only be created for types? So I don't 
think we can get to this codepath with an alias from `using X = Y`.

Thanks for the review, landing soon with minorly improved comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61408



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


[PATCH] D61452: [WebAssembly] Always include /lib in library path

2019-05-02 Thread Sam Clegg via Phabricator via cfe-commits
sbc100 updated this revision to Diff 197821.
sbc100 added a comment.
Herald added a subscriber: ormris.

tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61452

Files:
  clang/lib/Driver/ToolChains/WebAssembly.cpp
  clang/test/Driver/wasm-toolchain.c
  clang/test/Driver/wasm-toolchain.cpp


Index: clang/test/Driver/wasm-toolchain.cpp
===
--- clang/test/Driver/wasm-toolchain.cpp
+++ clang/test/Driver/wasm-toolchain.cpp
@@ -26,13 +26,13 @@
 
 // RUN: %clangxx -### -no-canonical-prefixes -target wasm32-wasi 
--sysroot=/foo --stdlib=c++ %s 2>&1 | FileCheck -check-prefix=LINK_KNOWN %s
 // LINK_KNOWN: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "crt1.o" "[[temp]]" 
"-lc++" "-lc++abi" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "-L/foo/lib" "crt1.o" 
"[[temp]]" "-lc++" "-lc++abi" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" 
"-o" "a.out"
 
 // A basic C++ link command-line with optimization with known OS.
 
 // RUN: %clangxx -### -O2 -no-canonical-prefixes -target wasm32-wasi 
--sysroot=/foo %s --stdlib=c++ 2>&1 | FileCheck -check-prefix=LINK_OPT_KNOWN %s
 // LINK_OPT_KNOWN: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK_OPT_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "crt1.o" "[[temp]]" 
"-lc++" "-lc++abi" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK_OPT_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "-L/foo/lib" 
"crt1.o" "[[temp]]" "-lc++" "-lc++abi" "-lc" 
"{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
 
 // A basic C++ compile command-line with known OS.
 
Index: clang/test/Driver/wasm-toolchain.c
===
--- clang/test/Driver/wasm-toolchain.c
+++ clang/test/Driver/wasm-toolchain.c
@@ -26,13 +26,13 @@
 
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-wasi --sysroot=/foo 
%s 2>&1 | FileCheck -check-prefix=LINK_KNOWN %s
 // LINK_KNOWN: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "crt1.o" "[[temp]]" 
"-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "-L/foo/lib" "crt1.o" 
"[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
 
 // A basic C link command-line with optimization with known OS.
 
 // RUN: %clang -### -O2 -no-canonical-prefixes -target wasm32-wasi 
--sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK_OPT_KNOWN %s
 // LINK_OPT_KNOWN: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK_OPT_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "crt1.o" "[[temp]]" 
"-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK_OPT_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "-L/foo/lib" 
"crt1.o" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" 
"a.out"
 
 // A basic C compile command-line with known OS.
 
Index: clang/lib/Driver/ToolChains/WebAssembly.cpp
===
--- clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -106,17 +106,17 @@
 
   getProgramPaths().push_back(getDriver().getInstalledDir());
 
-  if (getTriple().getOS() == llvm::Triple::UnknownOS) {
+  if (getTriple().getOS() != llvm::Triple::UnknownOS) {
 // Theoretically an "unknown" OS should mean no standard libraries, however
 // it could also mean that a custom set of libraries is in use, so just add
 // /lib to the search path. Disable multiarch in this case, to discourage
 // paths containing "unknown" from acquiring meanings.
-getFilePaths().push_back(getDriver().SysRoot + "/lib");
-  } else {
 const std::string MultiarchTriple =
 getMultiarchTriple(getDriver(), Triple, getDriver().SysRoot);
 getFilePaths().push_back(getDriver().SysRoot + "/lib/" + MultiarchTriple);
   }
+
+  getFilePaths().push_back(getDriver().SysRoot + "/lib");
 }
 
 bool WebAssembly::IsMathErrnoDefault() const { return false; }


Index: clang/test/Driver/wasm-toolchain.cpp
===
--- clang/test/Driver/wasm-toolchain.cpp
+++ clang/test/Driver/wasm-toolchain.cpp
@@ -26,13 +26,13 @@
 
 // RUN: %clangxx -### -no-canonical-prefixes -target wasm32-wasi --sysroot=/foo --stdlib=c++ %s 2>&1 | FileCheck -check-prefix=LINK_KNOWN %s
 // LINK_KNOWN: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "crt1.o" "[[temp]]" "-lc++" "-lc++abi" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "-L/foo/lib" "crt1.o" "[[temp]]" "-lc++" "-lc++abi" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a

[PATCH] D61335: [LibTooling] Add support to Transformer for composing rules as an ordered choice.

2019-05-02 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

- Could you provide a few real-world motivating examples?  Especially 
interested in cases that were complicated before and are easy to do now?
- Do we expect most the rules to be written using the new API or is this 
something that's gonna be used in `5-10%` of the cases?
- Could we consider expressing the `CompositeRewriteRule` as a `RewriteRule` 
itself? That might require extending the `RewriteRule` abstraction, but the 
mental model that makes sense to me is: a rewrite rule matches some AST nodes 
and applies replacements to them. A `CompositeRewriteRule` seems to match the 
same model, despite the fact it contains other rules. Would be nice if we could 
make this fact internal to the implementation.

Also a bit uneasy about the naming. `Composite` suggests the individual rules 
compose one after another, while in practice only one alternative is chosen.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61335



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


[PATCH] D61452: [WebAssembly] Always include /lib in library path

2019-05-02 Thread Sam Clegg via Phabricator via cfe-commits
sbc100 updated this revision to Diff 197823.
sbc100 added a comment.

- update comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61452

Files:
  clang/lib/Driver/ToolChains/WebAssembly.cpp
  clang/test/Driver/wasm-toolchain.c
  clang/test/Driver/wasm-toolchain.cpp


Index: clang/test/Driver/wasm-toolchain.cpp
===
--- clang/test/Driver/wasm-toolchain.cpp
+++ clang/test/Driver/wasm-toolchain.cpp
@@ -26,13 +26,13 @@
 
 // RUN: %clangxx -### -no-canonical-prefixes -target wasm32-wasi 
--sysroot=/foo --stdlib=c++ %s 2>&1 | FileCheck -check-prefix=LINK_KNOWN %s
 // LINK_KNOWN: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "crt1.o" "[[temp]]" 
"-lc++" "-lc++abi" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "-L/foo/lib" "crt1.o" 
"[[temp]]" "-lc++" "-lc++abi" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" 
"-o" "a.out"
 
 // A basic C++ link command-line with optimization with known OS.
 
 // RUN: %clangxx -### -O2 -no-canonical-prefixes -target wasm32-wasi 
--sysroot=/foo %s --stdlib=c++ 2>&1 | FileCheck -check-prefix=LINK_OPT_KNOWN %s
 // LINK_OPT_KNOWN: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK_OPT_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "crt1.o" "[[temp]]" 
"-lc++" "-lc++abi" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK_OPT_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "-L/foo/lib" 
"crt1.o" "[[temp]]" "-lc++" "-lc++abi" "-lc" 
"{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
 
 // A basic C++ compile command-line with known OS.
 
Index: clang/test/Driver/wasm-toolchain.c
===
--- clang/test/Driver/wasm-toolchain.c
+++ clang/test/Driver/wasm-toolchain.c
@@ -26,13 +26,13 @@
 
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-wasi --sysroot=/foo 
%s 2>&1 | FileCheck -check-prefix=LINK_KNOWN %s
 // LINK_KNOWN: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "crt1.o" "[[temp]]" 
"-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "-L/foo/lib" "crt1.o" 
"[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
 
 // A basic C link command-line with optimization with known OS.
 
 // RUN: %clang -### -O2 -no-canonical-prefixes -target wasm32-wasi 
--sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK_OPT_KNOWN %s
 // LINK_OPT_KNOWN: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK_OPT_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "crt1.o" "[[temp]]" 
"-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK_OPT_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "-L/foo/lib" 
"crt1.o" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" 
"a.out"
 
 // A basic C compile command-line with known OS.
 
Index: clang/lib/Driver/ToolChains/WebAssembly.cpp
===
--- clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -106,17 +106,15 @@
 
   getProgramPaths().push_back(getDriver().getInstalledDir());
 
-  if (getTriple().getOS() == llvm::Triple::UnknownOS) {
-// Theoretically an "unknown" OS should mean no standard libraries, however
-// it could also mean that a custom set of libraries is in use, so just add
-// /lib to the search path. Disable multiarch in this case, to discourage
-// paths containing "unknown" from acquiring meanings.
-getFilePaths().push_back(getDriver().SysRoot + "/lib");
-  } else {
+  if (getTriple().getOS() != llvm::Triple::UnknownOS) {
+// Disable multiarch for UnknownOS, to discourage paths containing 
"unknown"
+// from acquiring meanings.
 const std::string MultiarchTriple =
 getMultiarchTriple(getDriver(), Triple, getDriver().SysRoot);
 getFilePaths().push_back(getDriver().SysRoot + "/lib/" + MultiarchTriple);
   }
+
+  getFilePaths().push_back(getDriver().SysRoot + "/lib");
 }
 
 bool WebAssembly::IsMathErrnoDefault() const { return false; }


Index: clang/test/Driver/wasm-toolchain.cpp
===
--- clang/test/Driver/wasm-toolchain.cpp
+++ clang/test/Driver/wasm-toolchain.cpp
@@ -26,13 +26,13 @@
 
 // RUN: %clangxx -### -no-canonical-prefixes -target wasm32-wasi --sysroot=/foo --stdlib=c++ %s 2>&1 | FileCheck -check-prefix=LINK_KNOWN %s
 // LINK_KNOWN: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "crt1.o" "[[temp]]" "-lc++" "-lc++abi" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"
+// LINK_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "-L/foo

r359809 - Use primary template parameter names for variable template debug info

2019-05-02 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Thu May  2 10:45:54 2019
New Revision: 359809

URL: http://llvm.org/viewvc/llvm-project?rev=359809&view=rev
Log:
Use primary template parameter names for variable template debug info

Summary:
Fixes PR41677

Consider:
  template  constexpr bool is_same_v = false;
  template  constexpr bool is_same_v = true;
  template constexpr bool is_same_v;

Before this change, when emitting debug info for the
`is_same_v` global variable, clang would crash because it
would try to use the template parameter list from the partial
specialization to give parameter names to template arguments. This
doesn't work in general, since a partial specialization can have fewer
arguments than the primary template. Therefore, always use the primary
template. Hypothetically we could try to use the parameter names from
the partial specialization when possible, but it's not clear this really
helps debugging in practice.

Reviewers: JDevlieghere, aprantl, ormris, dblaikie

Subscribers: cfe-commits

Tags: #clang

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

Added:
cfe/trunk/test/CodeGenCXX/debug-info-var-template-partial.cpp
Modified:
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/test/CodeGenCXX/debug-info-template-member.cpp

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=359809&r1=359808&r2=359809&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu May  2 10:45:54 2019
@@ -1827,32 +1827,24 @@ CGDebugInfo::CollectFunctionTemplatePara
 }
 
 llvm::DINodeArray CGDebugInfo::CollectVarTemplateParams(const VarDecl *VL,
-llvm::DIFile *Unit) {
-  if (auto *TS = dyn_cast(VL)) {
-auto T = TS->getSpecializedTemplateOrPartial();
-auto TA = TS->getTemplateArgs().asArray();
-// Collect parameters for a partial specialization
-if (T.is()) {
-  const TemplateParameterList *TList =
-T.get()
-->getTemplateParameters();
-  return CollectTemplateParams(TList, TA, Unit);
-}
-
-// Collect parameters for an explicit specialization
-if (T.is()) {
-  const TemplateParameterList *TList = T.get()
-->getTemplateParameters();
-  return CollectTemplateParams(TList, TA, Unit);
-}
-  }
-  return llvm::DINodeArray();
+llvm::DIFile *Unit) {
+  // Always get the full list of parameters, not just the ones from the
+  // specialization. A partial specialization may have fewer parameters than
+  // there are arguments.
+  auto *TS = dyn_cast(VL);
+  if (!TS)
+return llvm::DINodeArray();
+  VarTemplateDecl *T = TS->getSpecializedTemplate();
+  const TemplateParameterList *TList = T->getTemplateParameters();
+  auto TA = TS->getTemplateArgs().asArray();
+  return CollectTemplateParams(TList, TA, Unit);
 }
 
 llvm::DINodeArray CGDebugInfo::CollectCXXTemplateParams(
 const ClassTemplateSpecializationDecl *TSpecial, llvm::DIFile *Unit) {
-  // Always get the full list of parameters, not just the ones from
-  // the specialization.
+  // Always get the full list of parameters, not just the ones from the
+  // specialization. A partial specialization may have fewer parameters than
+  // there are arguments.
   TemplateParameterList *TPList =
   TSpecial->getSpecializedTemplate()->getTemplateParameters();
   const TemplateArgumentList &TAList = TSpecial->getTemplateArgs();

Modified: cfe/trunk/test/CodeGenCXX/debug-info-template-member.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-template-member.cpp?rev=359809&r1=359808&r2=359809&view=diff
==
--- cfe/trunk/test/CodeGenCXX/debug-info-template-member.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-template-member.cpp Thu May  2 
10:45:54 2019
@@ -30,7 +30,7 @@ inline int add3(int x) {
 // CHECK: {{![0-9]+}} = distinct !DIGlobalVariable(
 // CHECK-SAME: name: "var"
 // CHECK-SAME: templateParams: {{![0-9]+}}
-// CHECK: !DITemplateTypeParameter(name: "P", type: {{![0-9]+}})
+// CHECK: !DITemplateTypeParameter(name: "T", type: {{![0-9]+}})
 // CHECK: {{![0-9]+}} = distinct !DIGlobalVariable(
 // CHECK-SAME: name: "varray"
 // CHECK-SAME: templateParams: {{![0-9]+}}

Added: cfe/trunk/test/CodeGenCXX/debug-info-var-template-partial.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-var-template-partial.cpp?rev=359809&view=auto
==
--- cfe/trunk/test/CodeGenCXX/debug-info-var-template-partial.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/debug-info-var-template-partial.cpp Thu May  2 
10:45:54 2019
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-linux-gnu %s -o - 
-debug-info-kind=limited | FileCheck %s
+
+

[PATCH] D61408: Use primary template parameter names for variable template debug info

2019-05-02 Thread Reid Kleckner via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL359809: Use primary template parameter names for variable 
template debug info (authored by rnk, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D61408?vs=197654&id=197828#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D61408

Files:
  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
  cfe/trunk/test/CodeGenCXX/debug-info-template-member.cpp
  cfe/trunk/test/CodeGenCXX/debug-info-var-template-partial.cpp


Index: cfe/trunk/test/CodeGenCXX/debug-info-var-template-partial.cpp
===
--- cfe/trunk/test/CodeGenCXX/debug-info-var-template-partial.cpp
+++ cfe/trunk/test/CodeGenCXX/debug-info-var-template-partial.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-linux-gnu %s -o - 
-debug-info-kind=limited | FileCheck %s
+
+template  constexpr bool is_same_v = false;
+template  constexpr bool is_same_v = true;
+
+template constexpr bool is_same_v;
+static_assert(is_same_v, "should get partial spec");
+
+// Note that the template arguments for the instantiated variable use the
+// parameter names from the primary template. The partial specialization might
+// not have enough parameters.
+
+// CHECK: distinct !DIGlobalVariable(name: "is_same_v", linkageName: 
"_Z9is_same_vIiiE", {{.*}} templateParams: ![[PARAMS:[0-9]+]])
+// CHECK: ![[PARAMS]] = !{![[LHS:[0-9]+]], ![[RHS:[0-9]+]]}
+// CHECK: ![[LHS]] = !DITemplateTypeParameter(name: "LHS", type: 
![[INT:[0-9]+]])
+// CHECK: ![[INT]] = !DIBasicType(name: "int", size: 32, encoding: 
DW_ATE_signed)
+// CHECK: ![[RHS]] = !DITemplateTypeParameter(name: "RHS", type: ![[INT]])
Index: cfe/trunk/test/CodeGenCXX/debug-info-template-member.cpp
===
--- cfe/trunk/test/CodeGenCXX/debug-info-template-member.cpp
+++ cfe/trunk/test/CodeGenCXX/debug-info-template-member.cpp
@@ -30,7 +30,7 @@
 // CHECK: {{![0-9]+}} = distinct !DIGlobalVariable(
 // CHECK-SAME: name: "var"
 // CHECK-SAME: templateParams: {{![0-9]+}}
-// CHECK: !DITemplateTypeParameter(name: "P", type: {{![0-9]+}})
+// CHECK: !DITemplateTypeParameter(name: "T", type: {{![0-9]+}})
 // CHECK: {{![0-9]+}} = distinct !DIGlobalVariable(
 // CHECK-SAME: name: "varray"
 // CHECK-SAME: templateParams: {{![0-9]+}}
Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
@@ -1827,32 +1827,24 @@
 }
 
 llvm::DINodeArray CGDebugInfo::CollectVarTemplateParams(const VarDecl *VL,
-llvm::DIFile *Unit) {
-  if (auto *TS = dyn_cast(VL)) {
-auto T = TS->getSpecializedTemplateOrPartial();
-auto TA = TS->getTemplateArgs().asArray();
-// Collect parameters for a partial specialization
-if (T.is()) {
-  const TemplateParameterList *TList =
-T.get()
-->getTemplateParameters();
-  return CollectTemplateParams(TList, TA, Unit);
-}
-
-// Collect parameters for an explicit specialization
-if (T.is()) {
-  const TemplateParameterList *TList = T.get()
-->getTemplateParameters();
-  return CollectTemplateParams(TList, TA, Unit);
-}
-  }
-  return llvm::DINodeArray();
+llvm::DIFile *Unit) {
+  // Always get the full list of parameters, not just the ones from the
+  // specialization. A partial specialization may have fewer parameters than
+  // there are arguments.
+  auto *TS = dyn_cast(VL);
+  if (!TS)
+return llvm::DINodeArray();
+  VarTemplateDecl *T = TS->getSpecializedTemplate();
+  const TemplateParameterList *TList = T->getTemplateParameters();
+  auto TA = TS->getTemplateArgs().asArray();
+  return CollectTemplateParams(TList, TA, Unit);
 }
 
 llvm::DINodeArray CGDebugInfo::CollectCXXTemplateParams(
 const ClassTemplateSpecializationDecl *TSpecial, llvm::DIFile *Unit) {
-  // Always get the full list of parameters, not just the ones from
-  // the specialization.
+  // Always get the full list of parameters, not just the ones from the
+  // specialization. A partial specialization may have fewer parameters than
+  // there are arguments.
   TemplateParameterList *TPList =
   TSpecial->getSpecializedTemplate()->getTemplateParameters();
   const TemplateArgumentList &TAList = TSpecial->getTemplateArgs();


Index: cfe/trunk/test/CodeGenCXX/debug-info-var-template-partial.cpp
===
--- cfe/trunk/test/CodeGenCXX/debug-info-var-template-partial.cpp
+++ cfe/trunk/test/CodeGenCXX/debug-info-var-template-partial.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -emit-llvm -triple x86_64-linux-gnu %s -o - -debug-info-kind=limited | FileCheck 

[PATCH] D61399: [OpenMP][Clang] Support for target math functions

2019-05-02 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

I don't like this implementation. Seems to me, it breaks one of the OpenMP 
standard requirements: the program can be compiled without openmp support. I 
assume, that with this includes the program won't be able to be compiled 
without OpenMP support anymore because it may use some device-specific math 
functions explicitly.
Instead, I would like to see some additional, device-scpecific math header 
file, that must be included explicitly to support some device-specific math 
functions. And we need to provide default implementations for those extra math 
functions for all the platforms we're going to support, including default host 
implementations.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61399



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


[PATCH] D61399: [OpenMP][Clang] Support for target math functions

2019-05-02 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

Moreover, I think this will cause troubles even in simple cases. Assume we have 
`target if(cond)` construct. In this case we will need to compile the target 
region for both, the device and the host. If the target region uses some 
device-specific math functions, it will break the compilation for the host.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61399



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


[PATCH] D61455: Change the metadata for heapallocsite calls when the type is cast.

2019-05-02 Thread Amy Huang via Phabricator via cfe-commits
akhuang created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
akhuang abandoned this revision.
akhuang added a comment.

accidentally created a new revision


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D61455

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGen/debug-info-codeview-heapallocsite.c


Index: clang/test/CodeGen/debug-info-codeview-heapallocsite.c
===
--- clang/test/CodeGen/debug-info-codeview-heapallocsite.c
+++ clang/test/CodeGen/debug-info-codeview-heapallocsite.c
@@ -1,27 +1,23 @@
 // RUN: %clang_cc1 -triple x86_64-windows-msvc -debug-info-kind=limited 
-gcodeview -fdeclspec -S -emit-llvm < %s | FileCheck %s
 
-struct Foo {
-  int x;
-};
+struct Foo;
+struct Bar;
 
 __declspec(allocator) void *alloc_void();
-__declspec(allocator) struct Foo *alloc_foo();
 
-void call_alloc_void() {
-  struct Foo *p = (struct Foo*)alloc_void();
+void call_alloc() {
+  struct Foo *p = alloc_void();
+  struct Foo *q = (struct Foo*)alloc_void();
+  struct Foo *r = (struct Foo*)(struct Bar*)alloc_void();
 }
 
-void call_alloc_foo() {
-  struct Foo *p = alloc_foo();
-}
-
-// CHECK-LABEL: define {{.*}}void @call_alloc_void
+// CHECK-LABEL: define {{.*}}void @call_alloc
 // CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG1:!.*]]
-
-// CHECK-LABEL: define {{.*}}void @call_alloc_foo
-// CHECK: call %struct.Foo* {{.*}}@alloc_foo{{.*}} !heapallocsite [[DBG2:!.*]]
+// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG2:!.*]]
+// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG3:!.*]]
 
 // CHECK: [[DBG1]] = !{}
-// CHECK: [[DBG2]] = distinct !DICompositeType(tag: DW_TAG_structure_type,
+// CHECK: [[DBG2]] = !DICompositeType(tag: DW_TAG_structure_type,
 // CHECK-SAME: name: "Foo"
-
+// CHECK: [[DBG3]] = !DICompositeType(tag: DW_TAG_structure_type,
+// CHECK-SAME: name: "Bar"
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -2063,6 +2063,12 @@
   }
 }
 
+// Update heapallocsite metadata when there is an explicit cast.
+if (llvm::CallInst *CI = dyn_cast(Src))
+  if (CI->getMetadata("heapallocsite") && dyn_cast(CE))
+  CGF.getDebugInfo()->
+  addHeapAllocSiteMetadata(CI, CE->getType(), CE->getExprLoc());
+
 return Builder.CreateBitCast(Src, DstTy);
   }
   case CK_AddressSpaceConversion: {
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -4370,7 +4370,6 @@
   }
 
   // Add metadata for calls to MSAllocator functions
-  // FIXME: Get the type that the return value is cast to.
   if (getDebugInfo() && TargetDecl &&
   TargetDecl->hasAttr())
 getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy, Loc);


Index: clang/test/CodeGen/debug-info-codeview-heapallocsite.c
===
--- clang/test/CodeGen/debug-info-codeview-heapallocsite.c
+++ clang/test/CodeGen/debug-info-codeview-heapallocsite.c
@@ -1,27 +1,23 @@
 // RUN: %clang_cc1 -triple x86_64-windows-msvc -debug-info-kind=limited -gcodeview -fdeclspec -S -emit-llvm < %s | FileCheck %s
 
-struct Foo {
-  int x;
-};
+struct Foo;
+struct Bar;
 
 __declspec(allocator) void *alloc_void();
-__declspec(allocator) struct Foo *alloc_foo();
 
-void call_alloc_void() {
-  struct Foo *p = (struct Foo*)alloc_void();
+void call_alloc() {
+  struct Foo *p = alloc_void();
+  struct Foo *q = (struct Foo*)alloc_void();
+  struct Foo *r = (struct Foo*)(struct Bar*)alloc_void();
 }
 
-void call_alloc_foo() {
-  struct Foo *p = alloc_foo();
-}
-
-// CHECK-LABEL: define {{.*}}void @call_alloc_void
+// CHECK-LABEL: define {{.*}}void @call_alloc
 // CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG1:!.*]]
-
-// CHECK-LABEL: define {{.*}}void @call_alloc_foo
-// CHECK: call %struct.Foo* {{.*}}@alloc_foo{{.*}} !heapallocsite [[DBG2:!.*]]
+// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG2:!.*]]
+// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG3:!.*]]
 
 // CHECK: [[DBG1]] = !{}
-// CHECK: [[DBG2]] = distinct !DICompositeType(tag: DW_TAG_structure_type,
+// CHECK: [[DBG2]] = !DICompositeType(tag: DW_TAG_structure_type,
 // CHECK-SAME: name: "Foo"
-
+// CHECK: [[DBG3]] = !DICompositeType(tag: DW_TAG_structure_type,
+// CHECK-SAME: name: "Bar"
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -2063,6 +2063,12 @@
   }
 }
 
+//

[PATCH] D61438: [ASTImporter] Use llvm::Expected and Error in the importer API

2019-05-02 Thread Raphael Isemann via Phabricator via cfe-commits
teemperor added a comment.

I think the best way to handle these errors in LLDB is to just log and then 
return some default value. That should make the current command print an error, 
which is better than terminating LLDB.

Otherwise the LLDB part of this patch LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61438



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


[PATCH] D61454: [CodeGen][ObjC] Remove the leading 'l_' from ObjC symbols and make private symbols in the __DATA segment internal.

2019-05-02 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak created this revision.
ahatanak added reviewers: rjmccall, vsk.
ahatanak added a project: clang.
Herald added subscribers: dexonsmith, jkorous.

This change is a continuation of https://reviews.llvm.org/D59234 and makes the 
symbols within __DATA visible.

rdar://problem/48887111


Repository:
  rC Clang

https://reviews.llvm.org/D61454

Files:
  lib/CodeGen/CGObjCMac.cpp
  test/CodeGenObjC/arc.m
  test/CodeGenObjC/boxing.m
  test/CodeGenObjC/exceptions-asm-attribute.m
  test/CodeGenObjC/externally-initialized-selectors.m
  test/CodeGenObjC/forward-protocol-metadata-symbols.m
  test/CodeGenObjC/instance-method-metadata.m
  test/CodeGenObjC/interface-layout-64.m
  test/CodeGenObjC/metadata-class-properties.m
  test/CodeGenObjC/metadata-symbols-32.m
  test/CodeGenObjC/metadata-symbols-64.m
  test/CodeGenObjC/metadata_symbols.m
  test/CodeGenObjC/mrc-weak.m
  test/CodeGenObjC/non-lazy-classes.m
  test/CodeGenObjC/ns-constant-strings.m
  test/CodeGenObjC/private-extern-selector-reference.m
  test/CodeGenObjC/property-category-impl.m
  test/CodeGenObjC/property-list-in-class.m
  test/CodeGenObjC/property-list-in-extension.m
  test/CodeGenObjC/protocol-comdat.m
  test/CodeGenObjC/protocols.m
  test/CodeGenObjC/section-name.m
  test/CodeGenObjC/sections.m
  test/CodeGenObjCXX/externally-initialized-selectors.mm
  test/CodeGenObjCXX/mrc-weak.mm

Index: test/CodeGenObjCXX/mrc-weak.mm
===
--- test/CodeGenObjCXX/mrc-weak.mm
+++ test/CodeGenObjCXX/mrc-weak.mm
@@ -7,7 +7,7 @@
 @end
 
 // CHECK-MODERN: @OBJC_CLASS_NAME_{{.*}} = {{.*}} c"\01\00"
-// CHECK-MODERN: @"\01l_OBJC_CLASS_RO_$_Foo" = {{.*}} { i32 772
+// CHECK-MODERN: @"_OBJC_CLASS_RO_$_Foo" = {{.*}} { i32 772
 //   772 == 0x304
 //^ HasMRCWeakIvars
 //^ HasCXXDestructorOnly
Index: test/CodeGenObjCXX/externally-initialized-selectors.mm
===
--- test/CodeGenObjCXX/externally-initialized-selectors.mm
+++ test/CodeGenObjCXX/externally-initialized-selectors.mm
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -fobjc-runtime=macosx-fragile-10.5 -o - -emit-llvm %s | FileCheck %s
-// RUN: %clang_cc1 -o - -emit-llvm %s | FileCheck %s
+// RUN: %clang_cc1 -fobjc-runtime=macosx-fragile-10.5 -o - -emit-llvm %s | FileCheck -check-prefix=FRAGILE %s
+// RUN: %clang_cc1 -o - -emit-llvm %s | FileCheck -check-prefix=NONFRAGILE %s
 
-// CHECK: @OBJC_SELECTOR_REFERENCES_ = private externally_initialized global
+// NONFRAGILE: @OBJC_SELECTOR_REFERENCES_ = internal externally_initialized global
+// FRAGILE: @OBJC_SELECTOR_REFERENCES_ = private externally_initialized global
 
 void test(id x) {
   [x doSomething];
Index: test/CodeGenObjC/sections.m
===
--- test/CodeGenObjC/sections.m
+++ test/CodeGenObjC/sections.m
@@ -37,9 +37,9 @@
 // CHECK-COFF: @"OBJC_CLASSLIST_SUP_REFS_$_" = {{.*}}, section ".objc_superrefs$B"
 // CHECK-COFF: @OBJC_SELECTOR_REFERENCES_ = {{.*}}, section ".objc_selrefs$B"
 // CHECK-COFF: @"OBJC_CLASSLIST_REFERENCES_$_" = {{.*}}, section ".objc_classrefs$B"
-// CHECK-COFF: @"\01l_objc_msgSend_fixup_class" = {{.*}}, section ".objc_msgrefs$B"
+// CHECK-COFF: @_objc_msgSend_fixup_class = {{.*}}, section ".objc_msgrefs$B"
 // CHECK-COFF: @"_OBJC_LABEL_PROTOCOL_$_P" = {{.*}}, section ".objc_protolist$B"
-// CHECK-COFF: @"\01l_OBJC_PROTOCOL_REFERENCE_$_P" = {{.*}}, section ".objc_protorefs$B"
+// CHECK-COFF: @"_OBJC_PROTOCOL_REFERENCE_$_P" = {{.*}}, section ".objc_protorefs$B"
 // CHECK-COFF: @"OBJC_LABEL_CLASS_$" = {{.*}}, section ".objc_classlist$B"
 // CHECK-COFF: @"OBJC_LABEL_NONLAZY_CLASS_$" = {{.*}}, section ".objc_nlclslist$B"
 // CHECK-COFF: @"OBJC_LABEL_CATEGORY_$" = {{.*}}, section ".objc_catlist$B"
@@ -49,9 +49,9 @@
 // CHECK-ELF: @"OBJC_CLASSLIST_SUP_REFS_$_" = {{.*}}, section "objc_superrefs"
 // CHECK-ELF: @OBJC_SELECTOR_REFERENCES_ = {{.*}}, section "objc_selrefs"
 // CHECK-ELF: @"OBJC_CLASSLIST_REFERENCES_$_" = {{.*}}, section "objc_classrefs"
-// CHECK-ELF: @"\01l_objc_msgSend_fixup_class" = {{.*}}, section "objc_msgrefs"
+// CHECK-ELF: @_objc_msgSend_fixup_class = {{.*}}, section "objc_msgrefs"
 // CHECK-ELF: @"_OBJC_LABEL_PROTOCOL_$_P" = {{.*}}, section "objc_protolist"
-// CHECK-ELF: @"\01l_OBJC_PROTOCOL_REFERENCE_$_P" = {{.*}}, section "objc_protorefs"
+// CHECK-ELF: @"_OBJC_PROTOCOL_REFERENCE_$_P" = {{.*}}, section "objc_protorefs"
 // CHECK-ELF: @"OBJC_LABEL_CLASS_$" = {{.*}}, section "objc_classlist"
 // CHECK-ELF: @"OBJC_LABEL_NONLAZY_CLASS_$" = {{.*}}, section "objc_nlclslist"
 // CHECK-ELF: @"OBJC_LABEL_CATEGORY_$" = {{.*}}, section "objc_catlist"
@@ -61,9 +61,9 @@
 // CHECK-MACHO: @"OBJC_CLASSLIST_SUP_REFS_$_" = {{.*}}, section "__DATA,__objc_superrefs,regular,no_dead_strip"
 // CHECK-MACHO: @OBJC_SELECTOR_REFERENCES_ = {{.*}}, section "__DATA,__objc_selrefs,literal_pointers,no_dead_strip"
 // CHECK-MACHO: @"OBJC_CLASSLIST_REFERENCES_$_"

[PATCH] D61455: Change the metadata for heapallocsite calls when the type is cast.

2019-05-02 Thread Amy Huang via Phabricator via cfe-commits
akhuang abandoned this revision.
akhuang added a comment.

accidentally created a new revision


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61455



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


[PATCH] D61399: [OpenMP][Clang] Support for target math functions

2019-05-02 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added a comment.

In D61399#1488262 , @ABataev wrote:

> I don't like this implementation. Seems to me, it breaks one of the OpenMP 
> standard requirements: the program can be compiled without openmp support. I 
> assume, that with this includes the program won't be able to be compiled 
> without OpenMP support anymore because it may use some device-specific math 
> functions explicitly.
>  Instead, I would like to see some additional, device-scpecific math header 
> file, that must be included explicitly to support some device-specific math 
> functions. And we need to provide default implementations for those extra 
> math functions for all the platforms we're going to support, including 
> default host implementations.


Can you provide an example of a conforming program that can't be compiled 
without OpenMP support? Regardless of the use of any device-specific functions 
(which isn't covered by the standard, of course, but might be needed in 
practice), the code still needs to be compilable by the host in order to 
generate the host-fallback version. This doesn't change that. Thus, any program 
that uses anything from this math.h, etc. needs to compile for the host, and 
thus, likely compiles without OpenMP support. Maybe I'm missing your point, 
however.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61399



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


[PATCH] D61407: [MS] Change the metadata for heapallocsite calls when the function return type is cast.

2019-05-02 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 197830.
akhuang marked an inline comment as done.
akhuang added a comment.

- Add test case for multiple casts
- Remove unrelated changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61407

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGen/debug-info-codeview-heapallocsite.c


Index: clang/test/CodeGen/debug-info-codeview-heapallocsite.c
===
--- clang/test/CodeGen/debug-info-codeview-heapallocsite.c
+++ clang/test/CodeGen/debug-info-codeview-heapallocsite.c
@@ -1,27 +1,23 @@
 // RUN: %clang_cc1 -triple x86_64-windows-msvc -debug-info-kind=limited 
-gcodeview -fdeclspec -S -emit-llvm < %s | FileCheck %s
 
-struct Foo {
-  int x;
-};
+struct Foo;
+struct Bar;
 
 __declspec(allocator) void *alloc_void();
-__declspec(allocator) struct Foo *alloc_foo();
 
-void call_alloc_void() {
-  struct Foo *p = (struct Foo*)alloc_void();
+void call_alloc() {
+  struct Foo *p = alloc_void();
+  struct Foo *q = (struct Foo*)alloc_void();
+  struct Foo *r = (struct Foo*)(struct Bar*)alloc_void();
 }
 
-void call_alloc_foo() {
-  struct Foo *p = alloc_foo();
-}
-
-// CHECK-LABEL: define {{.*}}void @call_alloc_void
+// CHECK-LABEL: define {{.*}}void @call_alloc
 // CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG1:!.*]]
-
-// CHECK-LABEL: define {{.*}}void @call_alloc_foo
-// CHECK: call %struct.Foo* {{.*}}@alloc_foo{{.*}} !heapallocsite [[DBG2:!.*]]
+// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG2:!.*]]
+// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG3:!.*]]
 
 // CHECK: [[DBG1]] = !{}
-// CHECK: [[DBG2]] = distinct !DICompositeType(tag: DW_TAG_structure_type,
+// CHECK: [[DBG2]] = !DICompositeType(tag: DW_TAG_structure_type,
 // CHECK-SAME: name: "Foo"
-
+// CHECK: [[DBG3]] = !DICompositeType(tag: DW_TAG_structure_type,
+// CHECK-SAME: name: "Bar"
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -2063,6 +2063,12 @@
   }
 }
 
+// Update heapallocsite metadata when there is an explicit cast.
+if (llvm::CallInst *CI = dyn_cast(Src))
+  if (CI->getMetadata("heapallocsite") && dyn_cast(CE))
+  CGF.getDebugInfo()->
+  addHeapAllocSiteMetadata(CI, CE->getType(), CE->getExprLoc());
+
 return Builder.CreateBitCast(Src, DstTy);
   }
   case CK_AddressSpaceConversion: {
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -4370,7 +4370,6 @@
   }
 
   // Add metadata for calls to MSAllocator functions
-  // FIXME: Get the type that the return value is cast to.
   if (getDebugInfo() && TargetDecl &&
   TargetDecl->hasAttr())
 getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy, Loc);


Index: clang/test/CodeGen/debug-info-codeview-heapallocsite.c
===
--- clang/test/CodeGen/debug-info-codeview-heapallocsite.c
+++ clang/test/CodeGen/debug-info-codeview-heapallocsite.c
@@ -1,27 +1,23 @@
 // RUN: %clang_cc1 -triple x86_64-windows-msvc -debug-info-kind=limited -gcodeview -fdeclspec -S -emit-llvm < %s | FileCheck %s
 
-struct Foo {
-  int x;
-};
+struct Foo;
+struct Bar;
 
 __declspec(allocator) void *alloc_void();
-__declspec(allocator) struct Foo *alloc_foo();
 
-void call_alloc_void() {
-  struct Foo *p = (struct Foo*)alloc_void();
+void call_alloc() {
+  struct Foo *p = alloc_void();
+  struct Foo *q = (struct Foo*)alloc_void();
+  struct Foo *r = (struct Foo*)(struct Bar*)alloc_void();
 }
 
-void call_alloc_foo() {
-  struct Foo *p = alloc_foo();
-}
-
-// CHECK-LABEL: define {{.*}}void @call_alloc_void
+// CHECK-LABEL: define {{.*}}void @call_alloc
 // CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG1:!.*]]
-
-// CHECK-LABEL: define {{.*}}void @call_alloc_foo
-// CHECK: call %struct.Foo* {{.*}}@alloc_foo{{.*}} !heapallocsite [[DBG2:!.*]]
+// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG2:!.*]]
+// CHECK: call i8* {{.*}}@alloc_void{{.*}} !heapallocsite [[DBG3:!.*]]
 
 // CHECK: [[DBG1]] = !{}
-// CHECK: [[DBG2]] = distinct !DICompositeType(tag: DW_TAG_structure_type,
+// CHECK: [[DBG2]] = !DICompositeType(tag: DW_TAG_structure_type,
 // CHECK-SAME: name: "Foo"
-
+// CHECK: [[DBG3]] = !DICompositeType(tag: DW_TAG_structure_type,
+// CHECK-SAME: name: "Bar"
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ 

[PATCH] D60349: [COFF, ARM64] Fix ABI implementation of struct returns

2019-05-02 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang updated this revision to Diff 197831.
mgrang edited the summary of this revision.

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

https://reviews.llvm.org/D60349

Files:
  include/clang/AST/DeclCXX.h
  include/clang/CodeGen/CGFunctionInfo.h
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/Sema/SemaDeclCXX.cpp
  test/CodeGen/arm64-microsoft-arguments.cpp
  test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp

Index: test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
===
--- test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
+++ test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
@@ -69,6 +69,11 @@
   int bb;
 };
 
+struct SmallWithPrivate {
+private:
+ int i;
+};
+
 // WIN32: declare dso_local void @"{{.*take_bools_and_chars.*}}"
 // WIN32:   (<{ i8, [3 x i8], i8, [3 x i8], %struct.SmallWithDtor,
 // WIN32:   i8, [3 x i8], i8, [3 x i8], i32, i8, [3 x i8] }>* inalloca)
@@ -165,7 +170,7 @@
 // WIN64:   call void @"??1SmallWithDtor@@QEAA@XZ"
 // WIN64: }
 // WOA64: define dso_local void @"?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(i64 %s.coerce) {{.*}} {
-// WOA64:   call void @"??1SmallWithDtor@@QEAA@XZ"
+// WOA64:   call void @"??1SmallWithDtor@@QEAA@XZ"(%struct.SmallWithDtor* %s)
 // WOA64: }
 
 // FIXME: MSVC incompatible!
@@ -173,6 +178,12 @@
 // WOA:   call arm_aapcs_vfpcc void @"??1SmallWithDtor@@QAA@XZ"(%struct.SmallWithDtor* %s)
 // WOA: }
 
+
+// Test that the eligible non-aggregate is passed directly, but returned
+// indirectly on ARM64 Windows.
+// WOA64: define dso_local void @"?small_arg_with_private_member@@YA?AUSmallWithPrivate@@U1@@Z"(%struct.SmallWithPrivate* inreg noalias sret %agg.result, i64 %s.coerce) {{.*}} {
+SmallWithPrivate small_arg_with_private_member(SmallWithPrivate s) { return s; }
+
 void call_small_arg_with_dtor() {
   small_arg_with_dtor(SmallWithDtor());
 }
Index: test/CodeGen/arm64-microsoft-arguments.cpp
===
--- test/CodeGen/arm64-microsoft-arguments.cpp
+++ test/CodeGen/arm64-microsoft-arguments.cpp
@@ -1,25 +1,203 @@
 // RUN: %clang_cc1 -triple aarch64-windows -ffreestanding -emit-llvm -O0 \
 // RUN: -x c++ -o - %s | FileCheck %s
 
-struct pod { int a, b, c, d, e; };
+// Pass and return for type size <= 8 bytes.
+// CHECK: define {{.*}} i64 @{{.*}}f1{{.*}}()
+// CHECK: call i64 {{.*}}func1{{.*}}(i64 %3)
+struct S1 {
+  int a[2];
+};
+
+S1 func1(S1 x);
+S1 f1() {
+  S1 x;
+  return func1(x);
+}
+
+// Pass and return type size <= 16 bytes.
+// CHECK: define {{.*}} [2 x i64] @{{.*}}f2{{.*}}()
+// CHECK: call [2 x i64] {{.*}}func2{{.*}}([2 x i64] %3)
+struct S2 {
+  int a[4];
+};
+
+S2 func2(S2 x);
+S2 f2() {
+  S2 x;
+  return func2(x);
+}
+
+// Pass and return for type size > 16 bytes.
+// CHECK: define {{.*}} void @{{.*}}f3{{.*}}(%struct.S3* noalias sret %agg.result)
+// CHECK: call void {{.*}}func3{{.*}}(%struct.S3* sret %agg.result, %struct.S3* %agg.tmp)
+struct S3 {
+  int a[5];
+};
+
+S3 func3(S3 x);
+S3 f3() {
+  S3 x;
+  return func3(x);
+}
+
+// Pass and return aggregate (of size < 16 bytes) with non-trivial destructor.
+// Passed directly but returned indirectly.
+// CHECK: define {{.*}} void {{.*}}f4{{.*}}(%struct.S4* inreg noalias sret %agg.result)
+// CHECK: call void {{.*}}func4{{.*}}(%struct.S4* inreg sret %agg.result, [2 x i64] %4)
+struct S4 {
+  int a[3];
+  ~S4();
+};
+
+S4 func4(S4 x);
+S4 f4() {
+  S4 x;
+  return func4(x);
+}
+
+// Pass and return from instance method called from instance method.
+// CHECK: define {{.*}} void @{{.*}}bar@Q1{{.*}}(%class.Q1* %this, %class.P1* inreg noalias sret %agg.result)
+// CHECK: call void {{.*}}foo@P1{{.*}}(%class.P1* %ref.tmp, %class.P1* inreg sret %agg.result, i8 %0)
+
+class P1 {
+public:
+  P1 foo(P1 x);
+};
+
+class Q1 {
+public:
+  P1 bar();
+};
+
+P1 Q1::bar() {
+  P1 p1;
+  return P1().foo(p1);
+}
+
+// Pass and return from instance method called from free function.
+// CHECK: define {{.*}} void {{.*}}bar{{.*}}()
+// CHECK: call void {{.*}}foo@P2{{.*}}(%class.P2* %ref.tmp, %class.P2* inreg sret %retval, i8 %0)
+class P2 {
+public:
+  P2 foo(P2 x);
+};
+
+P2 bar() {
+  P2 p2;
+  return P2().foo(p2);
+}
 
-struct non_pod {
-  int a;
-  non_pod() {}
+// Pass and return an object with a user-provided constructor (passed directly,
+// returned indirectly)
+// CHECK: define {{.*}} void @{{.*}}f5{{.*}}(%struct.S5* inreg noalias sret %agg.result)
+// CHECK: call void {{.*}}func5{{.*}}(%struct.S5* inreg sret %agg.result, i64 {{.*}})
+struct S5 {
+  S5();
+  int x;
 };
 
-struct pod s;
-struct non_pod t;
+S5 func5(S5 x);
+S5 f5() {
+  S5 x;
+  return func5(x);
+}
 
-struct pod bar() { return s; }
-struct non_pod foo() { return t; }
-// CHECK: define {{.*}} void @{{.*}}bar{{.*}}(%struct.pod* noalias sret %agg.result)
-// CHECK: define {{.*}} void @{{.*}}foo{{.*}}(%struct.non_pod* noalias %agg.result)
+// Pass and return an object with a non-trivial

[PATCH] D61407: [MS] Change the metadata for heapallocsite calls when the function return type is cast.

2019-05-02 Thread Amy Huang via Phabricator via cfe-commits
akhuang marked 2 inline comments as done.
akhuang added a comment.

Reverted `getCompleteTypeIndex` change, to be fixed elsewhere


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61407



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


[PATCH] D61399: [OpenMP][Clang] Support for target math functions

2019-05-02 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D61399#1488299 , @hfinkel wrote:

> In D61399#1488262 , @ABataev wrote:
>
> > I don't like this implementation. Seems to me, it breaks one of the OpenMP 
> > standard requirements: the program can be compiled without openmp support. 
> > I assume, that with this includes the program won't be able to be compiled 
> > without OpenMP support anymore because it may use some device-specific math 
> > functions explicitly.
> >  Instead, I would like to see some additional, device-scpecific math header 
> > file, that must be included explicitly to support some device-specific math 
> > functions. And we need to provide default implementations for those extra 
> > math functions for all the platforms we're going to support, including 
> > default host implementations.
>
>
> Can you provide an example of a conforming program that can't be compiled 
> without OpenMP support? Regardless of the use of any device-specific 
> functions (which isn't covered by the standard, of course, but might be 
> needed in practice), the code still needs to be compilable by the host in 
> order to generate the host-fallback version. This doesn't change that. Thus, 
> any program that uses anything from this math.h, etc. needs to compile for 
> the host, and thus, likely compiles without OpenMP support. Maybe I'm missing 
> your point, however.


Assume we have something like this:

  #pragma omp target if(cond)
  a = __nv_();

Instead of `__nv_xxx` you can try to use any Cuda-specific function, which is 
not the part of the standard `math.h`/`cmath` files. Will it be compilable even 
with OpenMP?


Repository:
  rC Clang

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

https://reviews.llvm.org/D61399



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


[PATCH] D61407: [MS] Change the metadata for heapallocsite calls when the function return type is cast.

2019-05-02 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm, with a minor tweak




Comment at: clang/lib/CodeGen/CGExprScalar.cpp:2068
+if (llvm::CallInst *CI = dyn_cast(Src))
+  if (CI->getMetadata("heapallocsite") && dyn_cast(CE))
+  CGF.getDebugInfo()->

It's more idiomatic to say `isa(CE)` than to use dyn_cast and 
test for nullness. The casting API actually has reasonably good documentation 
on it if you're curious:
http://llvm.org/docs/ProgrammersManual.html#the-isa-cast-and-dyn-cast-templates


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61407



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


  1   2   >