[PATCH] D59566: [X86] Correct the value of MaxAtomicInlineWidth for pre-586 cpus

2019-03-21 Thread Craig Topper via Phabricator via cfe-commits
craig.topper updated this revision to Diff 191643.
craig.topper added a comment.
Herald added subscribers: cfe-commits, jdoerfert.
Herald added a project: clang.

Rewrite to use a "cx8" feature flag that is set for all i586 and greater CPUs 
as well as generic. This assumes generic is never passed in a run of clang 
through the driver. And anyone using -cc1 directly is unlikely to be using an 
i486.

I've updated the init.c test to use i486 for the NETBSD test since I think 
that's what the driver defaults to. This is used as the test for i486. I've 
added command lines with -malign-double set which should force 64-bit types to 
have 64 bit alignment instead of the default 32 bit alignment. This is needed 
to get the LLONG_LOCK_FREE macro to be 2 on i586 and greater.


Repository:
  rC Clang

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

https://reviews.llvm.org/D59566

Files:
  lib/Basic/Targets/X86.cpp
  lib/Basic/Targets/X86.h
  test/CodeGen/attr-cpuspecific.c
  test/CodeGen/attr-target-x86-mmx.c
  test/CodeGen/attr-target-x86.c
  test/CodeGen/attr-target-x87-softfp.c
  test/Preprocessor/init.c

Index: test/Preprocessor/init.c
===
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -2845,8 +2845,9 @@
 // I386:#define __i386__ 1
 // I386:#define i386 1
 //
-// RUN: %clang_cc1 -E -dM -ffreestanding -triple=i386-pc-linux-gnu -target-cpu pentium4 < /dev/null | FileCheck -match-full-lines -check-prefix I386-LINUX %s
-// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=i386-pc-linux-gnu -target-cpu pentium4 < /dev/null | FileCheck -match-full-lines -check-prefix I386-LINUX -check-prefix I386-LINUX-CXX %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=i386-pc-linux-gnu -target-cpu pentium4 < /dev/null | FileCheck -match-full-lines -check-prefix I386-LINUX -check-prefix I386-LINUX-ALIGN32 %s
+// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=i386-pc-linux-gnu -target-cpu pentium4 < /dev/null | FileCheck -match-full-lines -check-prefix I386-LINUX -check-prefix I386-LINUX-CXX -check-prefix I386-LINUX-ALIGN32 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=i386-pc-linux-gnu -target-cpu pentium4 -malign-double < /dev/null | FileCheck -match-full-lines -check-prefix I386-LINUX -check-prefix I386-LINUX-ALIGN64 %s
 //
 // I386-LINUX-NOT:#define _LP64
 // I386-LINUX:#define __BIGGEST_ALIGNMENT__ 16
@@ -2883,6 +2884,18 @@
 // I386-LINUX:#define __FLT_MIN_EXP__ (-125)
 // I386-LINUX:#define __FLT_MIN__ 1.17549435e-38F
 // I386-LINUX:#define __FLT_RADIX__ 2
+// I386-LINUX:#define __GCC_ATOMIC_BOOL_LOCK_FREE 2
+// I386-LINUX:#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2
+// I386-LINUX:#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2
+// I386-LINUX:#define __GCC_ATOMIC_CHAR_LOCK_FREE 2
+// I386-LINUX:#define __GCC_ATOMIC_INT_LOCK_FREE 2
+// I386-LINUX-ALIGN32:#define __GCC_ATOMIC_LLONG_LOCK_FREE 1
+// I386-LINUX-ALIGN64:#define __GCC_ATOMIC_LLONG_LOCK_FREE 2
+// I386-LINUX:#define __GCC_ATOMIC_LONG_LOCK_FREE 2
+// I386-LINUX:#define __GCC_ATOMIC_POINTER_LOCK_FREE 2
+// I386-LINUX:#define __GCC_ATOMIC_SHORT_LOCK_FREE 2
+// I386-LINUX:#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1
+// I386-LINUX:#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2
 // I386-LINUX:#define __INT16_C_SUFFIX__
 // I386-LINUX:#define __INT16_FMTd__ "hd"
 // I386-LINUX:#define __INT16_FMTi__ "hi"
@@ -3034,8 +3047,10 @@
 // I386-LINUX:#define __i386__ 1
 // I386-LINUX:#define i386 1
 //
-// RUN: %clang_cc1 -E -dM -ffreestanding -triple=i386-netbsd < /dev/null | FileCheck -match-full-lines -check-prefix I386-NETBSD %s
-// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=i386-netbsd < /dev/null | FileCheck -match-full-lines -check-prefix I386-NETBSD -check-prefix I386-NETBSD-CXX %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=i386-netbsd -target-cpu i486 < /dev/null | FileCheck -match-full-lines -check-prefix I386-NETBSD %s
+// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=i386-netbsd -target-cpu i486 < /dev/null | FileCheck -match-full-lines -check-prefix I386-NETBSD -check-prefix I386-NETBSD-CXX %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=i386-netbsd -target-cpu i486 -malign-double < /dev/null | FileCheck -match-full-lines -check-prefix I386-NETBSD %s
+//
 //
 // I386-NETBSD-NOT:#define _LP64
 // I386-NETBSD:#define __BIGGEST_ALIGNMENT__ 16
@@ -3072,6 +3087,17 @@
 // I386-NETBSD:#define __FLT_MIN_EXP__ (-125)
 // I386-NETBSD:#define __FLT_MIN__ 1.17549435e-38F
 // I386-NETBSD:#define __FLT_RADIX__ 2
+// I386-NETBSD:#define __GCC_ATOMIC_BOOL_LOCK_FREE 2
+// I386-NETBSD:#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2
+// I386-NETBSD:#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2
+// I386-NETBSD:#define __GCC_ATOMIC_CHAR_LOCK_FREE 2
+// I386-NETBSD:#define __GCC_ATOMIC_INT_LOCK_FREE 2
+// I386-NETBSD:#define __GCC_ATOMIC_LLONG_LOCK_FREE 1
+// I386-NETBSD:#define __GCC_ATOMIC_LONG_LOCK_FREE 2
+// I386-NETBSD:#define __GCC_ATOMIC_POINTER_LOCK_FREE 2
+// I386

[clang-tools-extra] r356649 - Reland r356547 after fixing the YAML module missing issue.

2019-03-21 Thread Zinovy Nis via cfe-commits
Author: zinovy.nis
Date: Thu Mar 21 01:32:07 2019
New Revision: 356649

URL: http://llvm.org/viewvc/llvm-project?rev=356649&view=rev
Log:
Reland r356547 after fixing the YAML module missing issue.

[clang-tidy] Parallelize clang-tidy-diff.py

This patch has 2 rationales:

- large patches lead to long command lines and often cause max command line 
length restrictions imposed by OS;
- clang-tidy runs on modified files are independent and can be done in 
parallel, the same as done for run-clang-tidy.

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

Modified:
clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py

Modified: clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py?rev=356649&r1=356648&r2=356649&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/clang-tidy-diff.py Thu Mar 21 
01:32:07 2019
@@ -24,10 +24,95 @@ Example usage for git/svn users:
 """
 
 import argparse
+import glob
 import json
+import multiprocessing
+import os
 import re
+import shutil
 import subprocess
 import sys
+import tempfile
+import threading
+import traceback
+
+yaml_imported = True
+try:
+  import yaml
+except ImportError:
+  yaml_imported = False
+
+is_py2 = sys.version[0] == '2'
+
+if is_py2:
+import Queue as queue
+else:
+import queue as queue
+
+
+def run_tidy(task_queue, lock, timeout):
+  watchdog = None
+  while True:
+command = task_queue.get()
+try:
+  proc = subprocess.Popen(command,
+  stdout=subprocess.PIPE,
+  stderr=subprocess.PIPE)
+
+  if timeout is not None:
+watchdog = threading.Timer(timeout, proc.kill)
+watchdog.start()
+
+  stdout, stderr = proc.communicate()
+
+  with lock:
+sys.stdout.write(stdout.decode('utf-8') + '\n')
+sys.stdout.flush()
+if stderr:
+  sys.stderr.write(stderr.decode('utf-8') + '\n')
+  sys.stderr.flush()
+except Exception as e:
+  with lock:
+sys.stderr.write('Failed: ' + str(e) + ': '.join(command) + '\n')
+finally:
+  with lock:
+if (not timeout is None) and (not watchdog is None):
+  if not watchdog.is_alive():
+  sys.stderr.write('Terminated by timeout: ' +
+   ' '.join(command) + '\n')
+  watchdog.cancel()
+  task_queue.task_done()
+
+
+def start_workers(max_tasks, tidy_caller, task_queue, lock, timeout):
+  for _ in range(max_tasks):
+t = threading.Thread(target=tidy_caller, args=(task_queue, lock, timeout))
+t.daemon = True
+t.start()
+
+def merge_replacement_files(tmpdir, mergefile):
+  """Merge all replacement files in a directory into a single file"""
+  # The fixes suggested by clang-tidy >= 4.0.0 are given under
+  # the top level key 'Diagnostics' in the output yaml files
+  mergekey = "Diagnostics"
+  merged = []
+  for replacefile in glob.iglob(os.path.join(tmpdir, '*.yaml')):
+content = yaml.safe_load(open(replacefile, 'r'))
+if not content:
+  continue # Skip empty files.
+merged.extend(content.get(mergekey, []))
+
+  if merged:
+# MainSourceFile: The key is required by the definition inside
+# include/clang/Tooling/ReplacementsYaml.h, but the value
+# is actually never used inside clang-apply-replacements,
+# so we set it to '' here.
+output = { 'MainSourceFile': '', mergekey: merged }
+with open(mergefile, 'w') as out:
+  yaml.safe_dump(output, out)
+  else:
+# Empty the file:
+open(mergefile, 'w').close()
 
 
 def main():
@@ -47,7 +132,10 @@ def main():
   r'.*\.(cpp|cc|c\+\+|cxx|c|cl|h|hpp|m|mm|inc)',
   help='custom pattern selecting file paths to check '
   '(case insensitive, overridden by -regex)')
-
+  parser.add_argument('-j', type=int, default=1,
+  help='number of tidy instances to be run in parallel.')
+  parser.add_argument('-timeout', type=int, default=None,
+  help='timeout per each file in seconds.')
   parser.add_argument('-fix', action='store_true', default=False,
   help='apply suggested fixes')
   parser.add_argument('-checks',
@@ -56,9 +144,10 @@ def main():
   default='')
   parser.add_argument('-path', dest='build_path',
   help='Path used to read a compile command database.')
-  parser.add_argument('-export-fixes', metavar='FILE', dest='export_fixes',
-  help='Create a yaml file to store suggested fixes in, '
-  'which can be applied with clang-apply-replacements.')
+  if yaml_imported:
+parser.add_argument('-export-fixes', metavar='FILE', dest='export_fixes',
+

[PATCH] D42034: [clang-format] In tests, expected code should be format-stable

2019-03-21 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.
Herald added a project: LLVM.



Comment at: cfe/trunk/unittests/Format/FormatTest.cpp:78
 EXPECT_EQ(Expected.str(), format(Code, Style));
 if (Style.Language == FormatStyle::LK_Cpp) {
   // Objective-C++ is a superset of C++, so everything checked for C++

@ mzeren-vmw just a minor comment related to a change you made last year.

When FormatTest  fails, all we are told is that it fails on line 75,or 77 
(currently in trunk its 48,49) for every failure, with so many test cases 
written as "foo()" or "aa()" it can often be hard to pinpoint the exact 
test failure.

If verifyFormat was given an additional default argument of `int line`

Then verifyFormat could be used via a macro

```
#define VERIFYFORMAT(expected,code,style)
 verifyFormat(expected,code,style,__LINE__);
```

The line numbers could then be passed as an additional failure message to gtest 
by passing the __LINE__ of the test location down.

```
void verifyFormat(llvm::StringRef Expected, llvm::StringRef Code,
const FormatStyle &Style = getLLVMStyle(),int 
line=__LINE__) {
EXPECT_EQ(Expected.str(), format(Expected, Style))
<< "Expected code is not stable at " << line;
EXPECT_EQ(Expected.str(), format(Code, Style) << " at " << line;
}
```

When the test fails we'd know the exact line of the test case that failed.

Also because of this, we get 2 failures for every failure, the second will 
almost always fail as well if the first case does (from what I can tell), is 
there anyway we can query the first failed result and not bother doing the 
second if the first one failed?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D42034



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


[PATCH] D42034: [clang-format] In tests, expected code should be format-stable

2019-03-21 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

Great idea! LG from my side after addressing MyDeveloperDay's comments.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D42034



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


[PATCH] D59440: add steps to preprocess file and reduce command line args

2019-03-21 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson added a comment.

@akhuang Thanks for getting this committed. Since it seems like a lot of this 
is taken from my script, could you please add me as a reviewer for the next 
patch so that I know which bits still need to be upstreamed?


Repository:
  rC Clang

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

https://reviews.llvm.org/D59440



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


[PATCH] D58404: [clang-format] Add basic support for formatting C# files

2019-03-21 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 191649.
MyDeveloperDay added a comment.

Addressing Review Comments

- Remove all non Format only code (i.e. changes to clang/Basic and clang/Lexer 
to support verbatim interpolated strings C# 6)
- For the most part the need to for them is removed by merging of tokens during 
the FormatLexer phase
- There is one obscure failure scenario, but for a first pass I think it can be 
ignored (tests commented out) where a `\` is used unescaped just before a `"` 
(because of paths can be more common than you think)
  - `string s = @"ABC\" + ToString("B");";`

In this case, the string `@"ABC\"` is seen as `@"ABC\" + ToString("`, 
clang-format then gets confused about where it should put spaces and we end up 
with
  - `string s = @"ABC\" + ToString(" B ");";`

  AnnotatedTokens(L=0):
   M=0 C=0 T=Unknown S=1 B=0 BK=0 P=0 Name=identifier L=6 PPK=2 FakeLParens=2/ 
FakeRParens=0 II=0x252fbe52028 Text='string'
   M=0 C=1 T=StartOfName S=1 B=0 BK=0 P=220 Name=identifier L=8 PPK=2 
FakeLParens= FakeRParens=0 II=0x252fbe522d0 Text='s'
   M=0 C=0 T=BinaryOperator S=1 B=0 BK=0 P=22 Name=equal L=10 PPK=2 
FakeLParens= FakeRParens=0 II=0x0 Text='='
   M=0 C=1 T=Unknown S=1 B=0 BK=0 P=22 Name=string_literal L=31 PPK=2 
FakeLParens= FakeRParens=0 II=0x0 Text='@"ABC\" + ToString("'
   M=0 C=0 T=Unknown S=1 B=0 BK=0 P=23 Name=identifier L=33 PPK=2 FakeLParens= 
FakeRParens=0 II=0x252fbe52300 Text='B'
   M=0 C=1 T=Unknown S=1 B=0 BK=0 P=23 Name=string_literal L=38 PPK=2 
FakeLParens= FakeRParens=1 II=0x0 Text='");"'
   M=0 C=0 T=Unknown S=0 B=0 BK=0 P=23 Name=semi L=39 PPK=2 FakeLParens= 
FakeRParens=0 II=0x0 Text=';'



 


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

https://reviews.llvm.org/D58404

Files:
  clang/docs/ClangFormat.rst
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/FormatTokenLexer.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/tools/clang-format/ClangFormat.cpp
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/FormatTestCSharp.cpp

Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- /dev/null
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -0,0 +1,184 @@
+//===- unittest/Format/FormatTestCSharp.cpp - Formatting tests for CSharp -===//
+//
+// 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 "FormatTestUtils.h"
+#include "clang/Format/Format.h"
+#include "llvm/Support/Debug.h"
+#include "gtest/gtest.h"
+
+#define DEBUG_TYPE "format-test"
+
+namespace clang {
+namespace format {
+
+class FormatTestCSharp : public ::testing::Test {
+protected:
+  static std::string format(llvm::StringRef Code, unsigned Offset,
+unsigned Length, const FormatStyle &Style) {
+LLVM_DEBUG(llvm::errs() << "---\n");
+LLVM_DEBUG(llvm::errs() << Code << "\n\n");
+std::vector Ranges(1, tooling::Range(Offset, Length));
+tooling::Replacements Replaces = reformat(Style, Code, Ranges);
+auto Result = applyAllReplacements(Code, Replaces);
+EXPECT_TRUE(static_cast(Result));
+LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+return *Result;
+  }
+
+  static std::string
+  format(llvm::StringRef Code,
+ const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_CSharp)) {
+return format(Code, 0, Code.size(), Style);
+  }
+
+  static FormatStyle getStyleWithColumns(unsigned ColumnLimit) {
+FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+Style.ColumnLimit = ColumnLimit;
+return Style;
+  }
+
+  static void verifyFormat(
+  llvm::StringRef Code,
+  const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_CSharp)) {
+EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable";
+EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
+  }
+};
+
+TEST_F(FormatTestCSharp, CSharpClass) {
+  verifyFormat("public class SomeClass {\n"
+   "  void f() {}\n"
+   "  int g() { return 0; }\n"
+   "  void h() {\n"
+   "while (true) f();\n"
+   "for (;;) f();\n"
+   "if (true) f();\n"
+   "  }\n"
+   "}");
+}
+
+TEST_F(FormatTestCSharp, AccessModifiers) {
+  verifyFormat("public String toString() {}");
+  verifyFormat("private String toString() {}");
+  verifyFormat("protected String toString() {}");
+  verifyFor

[PATCH] D59629: [clang-format] correctly format protobuf fields named "enum".

2019-03-21 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rC Clang

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

https://reviews.llvm.org/D59629



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


[PATCH] D59627: [clang-format] Keep protobuf "package" statement on one line

2019-03-21 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: lib/Format/TokenAnnotator.cpp:1079
 if (Style.Language == FormatStyle::LK_Proto && Line.Level == 0 &&
-CurrentToken->is(Keywords.kw_option)) {
+(CurrentToken->is(Keywords.kw_option) ||
+ CurrentToken->is(Keywords.kw_package))) {

Nit:

could we use
```
CurrentToken->isOneOf(Keywords.kw_option,Keyswords.kw_package)
```


Repository:
  rC Clang

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

https://reviews.llvm.org/D59627



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


[PATCH] D58404: [clang-format] Add basic support for formatting C# files

2019-03-21 Thread Manuel Klimek via Phabricator via cfe-commits
klimek accepted this revision.
klimek added a comment.
This revision is now accepted and ready to land.

LG. This looks pretty sharp (scnr).




Comment at: clang/lib/Format/FormatTokenLexer.cpp:177
+if (Dollar->TokenText == "$") {
+  // this looks like $@"a" so we need to combine all 3
+  Dollar->Tok.setKind(tok::string_literal);

Tiny nit: please try to keep comments formatted as sentence (upper-case first 
letter, "." in the end).



Comment at: clang/unittests/Format/FormatTestCSharp.cpp:19
+
+class FormatTestCSharp : public ::testing::Test {
+protected:

If everything's static, you don't need a test fixture at all, you can just make 
it plain functions and use TEST() instead of TEST_F().


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

https://reviews.llvm.org/D58404



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


[PATCH] D58404: [clang-format] Add basic support for formatting C# files

2019-03-21 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 191654.
MyDeveloperDay marked 3 inline comments as done.
MyDeveloperDay added a comment.

Address comment nits


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

https://reviews.llvm.org/D58404

Files:
  clang/docs/ClangFormat.rst
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/FormatTokenLexer.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/tools/clang-format/ClangFormat.cpp
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/FormatTestCSharp.cpp

Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- /dev/null
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -0,0 +1,184 @@
+//===- unittest/Format/FormatTestCSharp.cpp - Formatting tests for CSharp -===//
+//
+// 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 "FormatTestUtils.h"
+#include "clang/Format/Format.h"
+#include "llvm/Support/Debug.h"
+#include "gtest/gtest.h"
+
+#define DEBUG_TYPE "format-test"
+
+namespace clang {
+namespace format {
+
+class FormatTestCSharp : public ::testing::Test {
+protected:
+  static std::string format(llvm::StringRef Code, unsigned Offset,
+unsigned Length, const FormatStyle &Style) {
+LLVM_DEBUG(llvm::errs() << "---\n");
+LLVM_DEBUG(llvm::errs() << Code << "\n\n");
+std::vector Ranges(1, tooling::Range(Offset, Length));
+tooling::Replacements Replaces = reformat(Style, Code, Ranges);
+auto Result = applyAllReplacements(Code, Replaces);
+EXPECT_TRUE(static_cast(Result));
+LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+return *Result;
+  }
+
+  static std::string
+  format(llvm::StringRef Code,
+ const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_CSharp)) {
+return format(Code, 0, Code.size(), Style);
+  }
+
+  static FormatStyle getStyleWithColumns(unsigned ColumnLimit) {
+FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+Style.ColumnLimit = ColumnLimit;
+return Style;
+  }
+
+  static void verifyFormat(
+  llvm::StringRef Code,
+  const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_CSharp)) {
+EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable";
+EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
+  }
+};
+
+TEST_F(FormatTestCSharp, CSharpClass) {
+  verifyFormat("public class SomeClass {\n"
+   "  void f() {}\n"
+   "  int g() { return 0; }\n"
+   "  void h() {\n"
+   "while (true) f();\n"
+   "for (;;) f();\n"
+   "if (true) f();\n"
+   "  }\n"
+   "}");
+}
+
+TEST_F(FormatTestCSharp, AccessModifiers) {
+  verifyFormat("public String toString() {}");
+  verifyFormat("private String toString() {}");
+  verifyFormat("protected String toString() {}");
+  verifyFormat("internal String toString() {}");
+
+  verifyFormat("public override String toString() {}");
+  verifyFormat("private override String toString() {}");
+  verifyFormat("protected override String toString() {}");
+  verifyFormat("internal override String toString() {}");
+
+  verifyFormat("internal static String toString() {}");
+}
+
+TEST_F(FormatTestCSharp, NoStringLiteralBreaks) {
+  verifyFormat("foo("
+   "\"a"
+   "aa\");");
+}
+
+TEST_F(FormatTestCSharp, CSharpVerbatiumStringLiterals) {
+  verifyFormat("foo(@\"\\abc\\\");");
+  // @"ABC\" + ToString("B") - handle embedded \ in literal string at
+  // the end
+  //
+  /*
+   * After removal of Lexer change we are currently not able
+   * To handle these cases
+   verifyFormat("string s = @\"ABC\\\" + ToString(\"B\");");
+   verifyFormat("string s = @\"ABC\"\"DEF\"\"GHI\"");
+   verifyFormat("string s = @\"ABC\"\"DEF\"\"\"");
+   verifyFormat("string s = @\"ABC\"\"DEF\"\"\" + abc");
+  */
+}
+
+TEST_F(FormatTestCSharp, CSharpInterpolatedStringLiterals) {
+  verifyFormat("foo($\"{aaa}\");");
+  verifyFormat("foo($\"{A}\");");
+  verifyFormat(
+  "foo($\"{A}"
+  "a\");");
+  verifyFormat("Name = $\"{firstName} {lastName}\";");
+
+  // $"ABC\" + ToString("B") - handle embedded \ in literal string at
+  // the end
+  verifyFormat("string s = $\"A{abc}BC\" + T

[PATCH] D58404: [clang-format] Add basic support for formatting C# files

2019-03-21 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/unittests/Format/FormatTestCSharp.cpp:19
+
+class FormatTestCSharp : public ::testing::Test {
+protected:

klimek wrote:
> If everything's static, you don't need a test fixture at all, you can just 
> make it plain functions and use TEST() instead of TEST_F().
I was actually just following the existing style of the other tests, but 
looking into what you said it seems we could almost do this in the other tests 
too.



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

https://reviews.llvm.org/D58404



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


[PATCH] D58278: Prepare ground for re-lexing modular headers.

2019-03-21 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh abandoned this revision.
alexfh added a comment.

I've found an alternative way to deal with PPCallbacks when analyzing code in 
modular mode. See https://reviews.llvm.org/D59528. Abandoning this revision.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58278



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


[PATCH] D58121: [analyzer][WIP] Attempt to fix traversing bindings of non-base regions in ClusterAnalysis

2019-03-21 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

First of all, sorry for the inactivity regarding this patch.

In D58121#1437433 , @NoQ wrote:

> Ok, got it! Yeah, this sounds like a valid way of supporting 
> non-base-region-based worklist items, i'm seeing no problems with it and i 
> don't immediately see a solution that'd be better than gradually supporting 
> non-base-regions in more and more places.
>
> Here's the slight modification of the original test case (D57230#1389766 
> ) that my problem finally boiled 
> down to:
>
>   typedef __typeof(sizeof(int)) size_t;
>   void *malloc(size_t);
>  
>   struct S {
> int x; // Make sure ptr has a non-zero offset within baseR.
> int *ptr;
>   };
>  
>   struct T {
> struct S s; // This is baseR.
>   };
>  
>   void escape(struct S *);
>  
>   void foo() {
> struct T t; // This is realBaseR.
> t.s.ptr = malloc(sizeof(int));
> escape(&t.s);
>   }
>
>
> This happens because in this patch you're pin-pointing the value by trying to 
> look it up via an exact binding key (up to default/direct), however it may 
> also reside at a non-zero offset within `baseR`. In my case the offset was 
> also symbolic - which kept me confused for a while because i was thinking 
> that symbolic offsets are the root of all evil. I think you may be able to 
> generalize the patch to cover this scenario by replacing the exact offset 
> lookup with a `collectSubRegionBindings()` (it might be cute to make some 
> sort of `iterSubRegionBindings()` that takes a lambda, and/or combine it with 
> `iterBindings()`).


Oh, I see. Thank you for tracking this down! Your proposed solution sounds 
reasonable to me. I hope there will be no significant performance hit.

> I'm still worried about D57230#1434161 
>  though. It kinda sounds like a good 
> idea to suppress store invalidation but not escaping, but it's a very 
> annoying thing to implement because our invalidation traits are very 
> inflexible. In order to express complex requirements like "please don't 
> invalidate this region, except this sub-region", the whole data structure has 
> to be changed. This is slightly similar to this problem we have in:
> 
>   void escape(int *x, const int *y);
>   // ...
>   escape(&a, &a);
> 
> 
> where the value of `a` would not be invalidated because `y` is a const 
> pointer, even though it is passed through a non-const pointer `x`. 
> @xazax.hun, do you have enough time/inspiration to dig that deeply into this 
> stuff?

I totally agree that invalidation and escaping are orthogonal. I really glad 
you found this example, I think you are right, the current data structure is 
not flexible enough. Unfortunately, I have some unrelated deadlines coming up, 
so it is very likely that I can only start working on this problem around early 
May. If you have some time to work on these problems feel free to commandeer 
this patch and I will definitely try to find time to review your patches.


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

https://reviews.llvm.org/D58121



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


[PATCH] D59603: [PR40707][PR41011][OpenCL] Allow addr space spelling without double underscore in C++ mode

2019-03-21 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia updated this revision to Diff 191665.
Anastasia added a comment.

Updated test to use root namespace (commented by Ronan).


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

https://reviews.llvm.org/D59603

Files:
  include/clang/Basic/TokenKinds.def
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseDeclCXX.cpp
  lib/Parse/ParseTentative.cpp
  test/Parser/opencl-cxx-keywords.cl

Index: test/Parser/opencl-cxx-keywords.cl
===
--- test/Parser/opencl-cxx-keywords.cl
+++ test/Parser/opencl-cxx-keywords.cl
@@ -19,32 +19,34 @@
 // Test that only __-prefixed address space qualifiers are accepted.
 struct test_address_space_qualifiers {
   global int *g;
-  // expected-error@-1 {{unknown type name 'global'}}
-  // expected-error@-2 {{expected member name or ';' after declaration specifiers}}
   __global int *uug;
-  int global; // should be fine in OpenCL C++
+  int global; // expected-warning{{declaration does not declare anything}}
 
   local int *l;
-  // expected-error@-1 {{unknown type name 'local'}}
-  // expected-error@-2 {{expected member name or ';' after declaration specifiers}}
   __local int *uul;
-  int local; // should be fine in OpenCL C++
+  int local; // expected-warning{{declaration does not declare anything}}
 
   private int *p;
-  // expected-error@-1 {{expected ':'}}
   __private int *uup;
-  int private; // 'private' is a keyword in C++14 and thus in OpenCL C++
-  // expected-error@-1 {{expected member name or ';' after declaration specifiers}}
+  int private; // expected-warning{{declaration does not declare anything}}
 
   constant int *c;
-  // expected-error@-1 {{unknown type name 'constant'}}
-  // expected-error@-2 {{expected member name or ';' after declaration specifiers}}
   __constant int *uuc;
-  int constant; // should be fine in OpenCL C++
+  int constant; // expected-warning{{declaration does not declare anything}}
 
   generic int *ge;
-  // expected-error@-1 {{unknown type name 'generic'}}
-  // expected-error@-2 {{expected member name or ';' after declaration specifiers}}
   __generic int *uuge;
-  int generic; // should be fine in OpenCL C++
+  int generic; // expected-warning{{declaration does not declare anything}}
 };
+
+// Test that 'private' can be parsed as an access qualifier and an address space too.
+class A{
+  private:
+  private int i; //expected-error{{field may not be qualified with an address space}}
+};
+
+private ::A i; //expected-error{{program scope variable must reside in global or constant address space}}
+
+void foo(private int i);
+
+private int bar(); //expected-error{{return value cannot be qualified with address space}}
Index: lib/Parse/ParseTentative.cpp
===
--- lib/Parse/ParseTentative.cpp
+++ lib/Parse/ParseTentative.cpp
@@ -1411,6 +1411,7 @@
   case tok::kw_const:
   case tok::kw_volatile:
 // OpenCL address space qualifiers
+  case tok::kw_private:
   case tok::kw___private:
   case tok::kw___local:
   case tok::kw___global:
Index: lib/Parse/ParseDeclCXX.cpp
===
--- lib/Parse/ParseDeclCXX.cpp
+++ lib/Parse/ParseDeclCXX.cpp
@@ -3047,9 +3047,14 @@
 DiagnoseUnexpectedNamespace(cast(TagDecl));
 return nullptr;
 
+  case tok::kw_private:
+// FIXME: We don't accept GNU attributes on access specifiers in OpenCL mode
+// yet.
+if (getLangOpts().OpenCL && !NextToken().is(tok::colon))
+  return ParseCXXClassMemberDeclaration(AS, AccessAttrs);
+LLVM_FALLTHROUGH;
   case tok::kw_public:
-  case tok::kw_protected:
-  case tok::kw_private: {
+  case tok::kw_protected: {
 AccessSpecifier NewAS = getAccessSpecifierIfPresent();
 assert(NewAS != AS_none);
 // Current token is a C++ access specifier.
Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -3824,6 +3824,7 @@
 break;
   };
   LLVM_FALLTHROUGH;
+case tok::kw_private:
 case tok::kw___private:
 case tok::kw___global:
 case tok::kw___local:
@@ -4790,6 +4791,7 @@
 
   case tok::kw___kindof:
 
+  case tok::kw_private:
   case tok::kw___private:
   case tok::kw___local:
   case tok::kw___global:
@@ -4980,6 +4982,7 @@
 
   case tok::kw___kindof:
 
+  case tok::kw_private:
   case tok::kw___private:
   case tok::kw___local:
   case tok::kw___global:
@@ -5192,6 +5195,7 @@
   break;
 
 // OpenCL qualifiers:
+case tok::kw_private:
 case tok::kw___private:
 case tok::kw___global:
 case tok::kw___local:
Index: include/clang/Basic/TokenKinds.def
===
--- include/clang/Basic/TokenKinds.def
+++ include/clang/Basic/TokenKinds.def
@@ -537,11 +537,11 @@
 KEYWORD(__constant  , KEYOPENCLC | KEYOPENCLCXX)
 KEYWORD(__private  

[PATCH] D59603: [PR40707][PR41011][OpenCL] Allow addr space spelling without double underscore in C++ mode

2019-03-21 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D59603#1436794 , @keryell wrote:

> I was a little bit worried about
>
>   struct top_level { int i; };
>  
>   private ::top_level a;
>  
>
>
> but it should be fine because in that case we have a `tok::coloncolon`


Yes, indeed. It parses correctly. I updated the test to demonstrate. :)


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

https://reviews.llvm.org/D59603



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


[PATCH] D58236: Make address space conversions a bit stricter.

2019-03-21 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added a comment.

Any more input on this?

I could redo the patch to simply fix the bug and not make the conversions 
stricter, if that's preferable.


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

https://reviews.llvm.org/D58236



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


[PATCH] D59523: Thread Safety: also look at ObjC methods

2019-03-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: delesley.
aaron.ballman added a comment.

Adding Delesley in case he has input on design.




Comment at: lib/Analysis/ThreadSafetyCommon.cpp:280
 unsigned I = PV->getFunctionScopeIndex();
-
-if (Ctx && Ctx->FunArgs && FD == Ctx->AttrDecl->getCanonicalDecl()) {
-  // Substitute call arguments for references to function parameters
-  assert(I < Ctx->NumArgs);
-  return translate(Ctx->FunArgs[I], Ctx->Prev);
+const auto *D = PV->getDeclContext();
+if (Ctx && Ctx->FunArgs) {

Please don't use `auto` when the type is not explicitly spelled out in the 
initialization.



Comment at: lib/Analysis/ThreadSafetyCommon.cpp:282
+if (Ctx && Ctx->FunArgs) {
+  const auto *Canonical = Ctx->AttrDecl->getCanonicalDecl();
+  if (isa(D)

Same.



Comment at: lib/Analysis/ThreadSafetyCommon.cpp:283-285
+  if (isa(D)
+  ? (cast(D)->getCanonicalDecl() == Canonical)
+  : (cast(D)->getCanonicalDecl() == Canonical)) {

Also somewhat orthogonal to your changes, but... ugh, the lack of any common 
base between `FunctionDecl` and `ObjcMethodDecl` strikes again. I sort of wish 
we would introduce a CallableDecl base class that these two (and BlockDecl) 
could all inherit from to take care of this sort of ugly hack.


Repository:
  rC Clang

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

https://reviews.llvm.org/D59523



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


[PATCH] D58841: [Diagnostics] Support -Wtype-limits for GCC compatibility

2019-03-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I worry a little bit about our -Wtype-limits getting out of sync from GCC's due 
to making it a synonym for -Wtautological-constant-in-range-compare, but I'm 
also at a loss for why these two should ever have different functionality.

I think I'm okay with this, but I'd like @rsmith to weigh in as well.




Comment at: clang/include/clang/Basic/DiagnosticGroups.td:485
+// For compatibility with GCC; -Wtype-limits = 
-Wtautological-constant-in-range-compare
+def TypeLimits : DiagGroup<"type-limits", [TautologicalInRangeCompare]>;
 def TautologicalOutOfRangeCompare : 
DiagGroup<"tautological-constant-out-of-range-compare">;

xbolva00 wrote:
> lebedev.ri wrote:
> > xbolva00 wrote:
> > > lebedev.ri wrote:
> > > > Is gcc's `-Wtype-limits` *just* 
> > > > `-Wtautological-constant-in-range-compare`, or is something else should 
> > > > be there?
> > > -Wtautological-constant-in-range-compare is enough to diagnose 99% cases 
> > > from:
> > > 
> > > https://github.com/gcc-mirror/gcc/blob/41d6b10e96a1de98e90a7c0378437c3255814b16/gcc/testsuite/g%2B%2B.dg/warn/Wtype-limits.C
> > > 
> > > One missed case is:
> > > int test (int x) 
> > > {
> > >   if ((long long)x <= 0x123456789ABCLL)
> > > return 1;
> > >   else 
> > > return 0;
> > > }
> > > 
> > > Tried -Weverything, no help. We miss this case. I will open PR for that.
> > > 
> > > But anyway, this missed case should not block this patch.
> > > -Wtautological-constant-in-range-compare is enough to diagnose 99% cases 
> > > from:
> > 
> > That doesn't really answer the question.
> > I'm sure that *adding* `-Wtautological-constant-in-range-compare` helps.
> > But what about the other way around?
> > Does passing `-Wno-type-limits` silence *all* the expected diags in that 
> > file?
> Yes, silences it correctly.
Thoughts about why we behave differently here: 
https://github.com/gcc-mirror/gcc/blob/41d6b10e96a1de98e90a7c0378437c3255814b16/gcc/testsuite/g%2B%2B.dg/warn/Wtype-limits2.C


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

https://reviews.llvm.org/D58841



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


[PATCH] D59637: [analyzer] Use the custom propagation rules and sinks in GenericTaintChecker

2019-03-21 Thread Borsik Gábor via Phabricator via cfe-commits
boga95 created this revision.
boga95 added reviewers: NoQ, Szelethus, xazax.hun, dkrupp.
Herald added subscribers: cfe-commits, Charusso, donat.nagy, mikhail.ramalho, 
a.sidorin, rnkovacs, szepet, baloghadamsoftware, whisperity.
Herald added a project: clang.

The `TaintPropagationRule` deduction uses the custom rules from the config.
Check custom sinks when looking for errors. Give an error when at least one of 
the specified arguments is tainted.
Emit error message and omit a parameter if it's out of bound.


Repository:
  rC Clang

https://reviews.llvm.org/D59637

Files:
  lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
  test/Analysis/Inputs/taint-generic-config.yaml
  test/Analysis/taint-generic.c

Index: test/Analysis/taint-generic.c
===
--- test/Analysis/taint-generic.c
+++ test/Analysis/taint-generic.c
@@ -1,5 +1,5 @@
-// RUN: %clang_analyze_cc1  -analyzer-checker=alpha.security.taint,core,alpha.security.ArrayBoundV2 -Wno-format-security -verify %s
-// RUN: %clang_analyze_cc1  -DFILE_IS_STRUCT -analyzer-checker=alpha.security.taint,core,alpha.security.ArrayBoundV2 -Wno-format-security -verify %s
+// RUN: %clang_analyze_cc1  -analyzer-checker=alpha.security.taint,core,alpha.security.ArrayBoundV2 -analyzer-config alpha.security.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config.yaml -Wno-format-security -verify %s
+// RUN: %clang_analyze_cc1  -DFILE_IS_STRUCT -analyzer-checker=alpha.security.taint,core,alpha.security.ArrayBoundV2 -analyzer-config alpha.security.taint.TaintPropagation:Config=%S/Inputs/taint-generic-config.yaml -Wno-format-security -verify %s
 
 int scanf(const char *restrict format, ...);
 char *gets(char *str);
@@ -295,3 +295,43 @@
   if (i < rhs)
 *(volatile int *) 0; // no-warning
 }
+
+
+// Test configuration
+int mySource1();
+void mySource2(int*);
+void myScanf(const char*, ...);
+int myPropagator(int, int*);
+int mySnprintf(char*, size_t, const char*, ...);
+void mySink(int, int, int);
+
+void testConfigurationSources1() {
+  int x = mySource1();
+  Buffer[x] = 1; // expected-warning {{Out of bound memory access }}
+}
+
+void testConfigurationSources2() {
+  int x;
+  mySource2(&x);
+  Buffer[x] = 1; // expected-warning {{Out of bound memory access }}
+}
+
+void testConfigurationSources3() {
+  int x, y;
+  myScanf("%d %d", &x, &y);
+  Buffer[y] = 1; // expected-warning {{Out of bound memory access }}
+}
+
+void testConfigurationPropagation() {
+  int x = mySource1();
+  int y;
+  myPropagator(x, &y);
+  Buffer[y] = 1; // expected-warning {{Out of bound memory access }}
+}
+
+void testConfigurationSinks() {
+  int x = mySource1();
+  mySink(x, 1, 2); // expected-warning {{Untrusted data is passed to a user defined sink}}
+  mySink(1, x, 2); // no-warning
+  mySink(1, 2, x); // expected-warning {{Untrusted data is passed to a user defined sink}}
+}
Index: test/Analysis/Inputs/taint-generic-config.yaml
===
--- /dev/null
+++ test/Analysis/Inputs/taint-generic-config.yaml
@@ -0,0 +1,51 @@
+# A list of source/propagation function
+Propagations:
+  # int x = mySource1(); // x is tainted
+  - Name: mySource1
+DstArgs:  [4294967294] # Index for return value
+
+  # int x;
+  # mySource2(&x); // x is tainted
+  - Name: mySource2
+DstArgs:  [0]
+
+  # int x, y;
+  # myScanf("%d %d", &x, &y); // x and y are tainted
+  - Name: myScanf
+VarType:  Dst
+VarIndex: 1
+
+  # int x; // x is tainted
+  # int y;
+  # myPropagator(x, &y); // y is tainted
+  - Name: myPropagator
+SrcArgs:  [0]
+DstArgs:  [1]
+
+  # const unsigned size = 100;
+  # char buf[size];
+  # int x, y;
+  # int n = mySprintf(buf, size, "%d %d", x, y); // If size, x or y is tainted
+  # // the return value and the buf will be tainted
+  - Name: mySnprintf
+SrcArgs:  [1]
+DstArgs:  [0, 4294967294]
+VarType:  Src
+VarIndex: 3
+
+# A list of filter functions
+Filters:
+  # int x; // x is tainted
+  # myFilter(&x); // x is not tainted anymore
+  - Name: myFilter
+Args: [0]
+
+# A list of sink functions
+Sinks:
+  # int x, y; // x and y are tainted
+  # mySink(x, 0, 1); // It will warn
+  # mySink(0, 1, y); // It will warn
+  # mySink(0, x, 1); // It won't warn
+  - Name: mySink
+Args: [0, 2]
+
Index: lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
+++ lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
@@ -116,6 +116,11 @@
   bool checkTaintedBufferSize(const CallExpr *CE, const FunctionDecl *FDecl,
   CheckerContext &C) const;
 
+  /// Check if tainted data is used as a custom sink's parameter.
+  static const char MsgCustomSink[];
+  bool checkCustomSinks(const CallExpr *CE, StringRef Name,
+CheckerContext &C) const;
+
   /// Generate a report

[PATCH] D59628: Add support for __attribute__((objc_class_stub))

2019-03-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

You should also add Sema tests that ensure the attribute applies to the 
expected AST nodes, is diagnosed appropriately when applied to something it 
shouldn't be applied to, accepts no args, etc. Basically, all of the semantic 
places we could warn on should have test coverage, as well as demonstrations of 
correct usage.




Comment at: include/clang/Basic/Attr.td:1798
 
+def ObjCClassStub: Attr {
+  let Spellings = [Clang<"objc_class_stub">];

Formatting is a smidge off here -- should be `ObjCClassStub : Attr` with the 
extra whitespace.



Comment at: include/clang/Basic/Attr.td:1802
+  let Documentation = [ObjCClassStubDocs];
+}
+

Does this attribute make sense outside of ObjC? e.g., should it require an ObjC 
compiland? If it should only be used in ObjC, then it should have a `LangOpts` 
field.



Comment at: include/clang/Basic/AttrDocs.td:1116
+def ObjCClassStubDocs : Documentation {
+let Category = DocCatFunction;
+let Content = [{

This seems like the wrong category -- the attribute doesn't apply to functions.



Comment at: include/clang/Basic/AttrDocs.td:1118
+let Content = [{
+This attribute specifies that the Objective-C class to which it applies has 
dynamically-allocated metadata. Classes annotated with this attribute cannot be 
subclassed.
+}];

rjmccall wrote:
> You should probably check that the user doesn't try to subclass classes 
> annotated with this attribute, then. :)
Try to keep the docs wrapped to the usual 80-col limit.

I think this could use a bit more exposition, or links to explain stuff. Based 
on the small amount here, I still have no idea why I would use this attribute.


Repository:
  rC Clang

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

https://reviews.llvm.org/D59628



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


[PATCH] D59631: [AArch64] Support selecting TPIDR_EL[1-3] as the thread base

2019-03-21 Thread Oliver Stannard via Phabricator via cfe-commits
olista01 added a reviewer: olista01.
olista01 added a comment.

Is there an existing compiler which this option is trying to be compatible 
with? GCC for AArch64 doesn't currently have an option for this, so we don't 
have to worry about compatibility with that. If possible, I'd prefer for the 
option to be "-mtp=", to match the option accepted by clang and GCC for AArch32.


Repository:
  rC Clang

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

https://reviews.llvm.org/D59631



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


[PATCH] D59516: [analyzer] Add custom filter functions for GenericTaintChecker

2019-03-21 Thread Borsik Gábor via Phabricator via cfe-commits
boga95 updated this revision to Diff 191668.
boga95 retitled this revision from "[analyzer] Make GenericTaintChecker 
configurable" to "[analyzer] Add custom filter functions for 
GenericTaintChecker".

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

https://reviews.llvm.org/D59516

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
  include/clang/StaticAnalyzer/Core/PathSensitive/TaintTag.h
  lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
  lib/StaticAnalyzer/Core/ProgramState.cpp
  test/Analysis/taint-generic.c

Index: test/Analysis/taint-generic.c
===
--- test/Analysis/taint-generic.c
+++ test/Analysis/taint-generic.c
@@ -296,13 +296,13 @@
 *(volatile int *) 0; // no-warning
 }
 
-
 // Test configuration
 int mySource1();
 void mySource2(int*);
 void myScanf(const char*, ...);
 int myPropagator(int, int*);
 int mySnprintf(char*, size_t, const char*, ...);
+void myFilter(int*);
 void mySink(int, int, int);
 
 void testConfigurationSources1() {
@@ -329,6 +329,12 @@
   Buffer[y] = 1; // expected-warning {{Out of bound memory access }}
 }
 
+void testConfigurationFilter() {
+  int x = mySource1();
+  myFilter(&x);
+  Buffer[x] = 1; // no-warning
+}
+
 void testConfigurationSinks() {
   int x = mySource1();
   mySink(x, 1, 2); // expected-warning {{Untrusted data is passed to a user defined sink}}
Index: lib/StaticAnalyzer/Core/ProgramState.cpp
===
--- lib/StaticAnalyzer/Core/ProgramState.cpp
+++ lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -658,20 +658,20 @@
   return true;
 }
 
-ProgramStateRef ProgramState::addTaint(const Stmt *S,
+ProgramStateRef ProgramState::setTaint(const Stmt *S,
const LocationContext *LCtx,
TaintTagType Kind) const {
   if (const Expr *E = dyn_cast_or_null(S))
 S = E->IgnoreParens();
 
-  return addTaint(getSVal(S, LCtx), Kind);
+  return setTaint(getSVal(S, LCtx), Kind);
 }
 
-ProgramStateRef ProgramState::addTaint(SVal V,
+ProgramStateRef ProgramState::setTaint(SVal V,
TaintTagType Kind) const {
   SymbolRef Sym = V.getAsSymbol();
   if (Sym)
-return addTaint(Sym, Kind);
+return setTaint(Sym, Kind);
 
   // If the SVal represents a structure, try to mass-taint all values within the
   // structure. For now it only works efficiently on lazy compound values that
@@ -685,22 +685,22 @@
   if (auto LCV = V.getAs()) {
 if (Optional binding = getStateManager().StoreMgr->getDefaultBinding(*LCV)) {
   if (SymbolRef Sym = binding->getAsSymbol())
-return addPartialTaint(Sym, LCV->getRegion(), Kind);
+return setPartialTaint(Sym, LCV->getRegion(), Kind);
 }
   }
 
   const MemRegion *R = V.getAsRegion();
-  return addTaint(R, Kind);
+  return setTaint(R, Kind);
 }
 
-ProgramStateRef ProgramState::addTaint(const MemRegion *R,
+ProgramStateRef ProgramState::setTaint(const MemRegion *R,
TaintTagType Kind) const {
   if (const SymbolicRegion *SR = dyn_cast_or_null(R))
-return addTaint(SR->getSymbol(), Kind);
+return setTaint(SR->getSymbol(), Kind);
   return this;
 }
 
-ProgramStateRef ProgramState::addTaint(SymbolRef Sym,
+ProgramStateRef ProgramState::setTaint(SymbolRef Sym,
TaintTagType Kind) const {
   // If this is a symbol cast, remove the cast before adding the taint. Taint
   // is cast agnostic.
@@ -712,7 +712,7 @@
   return NewState;
 }
 
-ProgramStateRef ProgramState::addPartialTaint(SymbolRef ParentSym,
+ProgramStateRef ProgramState::setPartialTaint(SymbolRef ParentSym,
   const SubRegion *SubRegion,
   TaintTagType Kind) const {
   // Ignore partial taint if the entire parent symbol is already tainted.
@@ -721,7 +721,7 @@
 
   // Partial taint applies if only a portion of the symbol is tainted.
   if (SubRegion == SubRegion->getBaseRegion())
-return addTaint(ParentSym, Kind);
+return setTaint(ParentSym, Kind);
 
   const TaintedSubRegions *SavedRegs = get(ParentSym);
   TaintedSubRegions Regs =
@@ -779,7 +779,7 @@
   continue;
 
 if (const TaintTagType *Tag = get(*SI)) {
-  if (*Tag == Kind)
+  if (*Tag != TaintTagNotTainted && *Tag == Kind)
 return true;
 }
 
Index: lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
+++ lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
@@ -31,6 +31,28 @@
 using namespace ento;
 
 namespace {
+/// A struct to store tainted argument and taint type as a pair in the program
+/// state.
+struct TaintArgTypePair {
+  unsigned Arg;
+  TaintTagType TagType;
+
+  bool operator==(co

[PATCH] D58573: [analyzer] Move UninitializedObject out of alpha

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

Ping, @NoQ, if we settled on `optin.cplusplus`, would you be fine with this 
patch?


Repository:
  rC Clang

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

https://reviews.llvm.org/D58573



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


r356662 - [clang-format] Add basic support for formatting C# files

2019-03-21 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Thu Mar 21 06:09:22 2019
New Revision: 356662

URL: http://llvm.org/viewvc/llvm-project?rev=356662&view=rev
Log:
[clang-format] Add basic support for formatting C# files

Summary:

This revision adds basic support for formatting C# files with clang-format, I 
know the barrier to entry is high here  so I'm sending this revision in to test 
the water as to whether this might be something we'd consider landing.

Tracking in Bugzilla as:
https://bugs.llvm.org/show_bug.cgi?id=40850

Justification:
C# code just looks ugly in comparison to the C++ code in our source tree which 
is clang-formatted.

I've struggled with Visual Studio reformatting to get a clean and consistent 
style, I want to format our C# code on saving like I do now for C++ and i want 
it to have the same style as defined in our .clang-format file, so it 
consistent as it can be with C++.  (Braces/Breaking/Spaces/Indent etc..)

Using clang format without this patch leaves the code in a bad state, sometimes 
when the BreakStringLiterals is set, it  fails to compile.

Mostly the C# is similar to Java, except instead of JavaAnnotations I try to 
reuse the TT_AttributeSquare.

Almost the most valuable portion is to have a new Language in order to 
partition the configuration for C# within a common .clang-format file, with the 
auto detection on the .cs extension. But there are other C# specific styles 
that could be added later if this is accepted. in particular how  `{ set;get }` 
is formatted.

Reviewers: djasper, klimek, krasimir, benhamilton, JonasToth

Reviewed By: klimek

Subscribers: llvm-commits, mgorny, jdoerfert, cfe-commits

Tags: #clang, #clang-tools-extra

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

Added:
cfe/trunk/unittests/Format/FormatTestCSharp.cpp
Modified:
cfe/trunk/docs/ClangFormat.rst
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/docs/ReleaseNotes.rst
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/lib/Format/FormatTokenLexer.cpp
cfe/trunk/lib/Format/FormatTokenLexer.h
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/tools/clang-format/ClangFormat.cpp
cfe/trunk/unittests/Format/CMakeLists.txt

Modified: cfe/trunk/docs/ClangFormat.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormat.rst?rev=356662&r1=356661&r2=356662&view=diff
==
--- cfe/trunk/docs/ClangFormat.rst (original)
+++ cfe/trunk/docs/ClangFormat.rst Thu Mar 21 06:09:22 2019
@@ -11,12 +11,12 @@ Standalone Tool
 ===
 
 :program:`clang-format` is located in `clang/tools/clang-format` and can be 
used
-to format C/C++/Java/JavaScript/Objective-C/Protobuf code.
+to format C/C++/Java/JavaScript/Objective-C/Protobuf/C# code.
 
 .. code-block:: console
 
   $ clang-format -help
-  OVERVIEW: A tool to format C/C++/Java/JavaScript/Objective-C/Protobuf code.
+  OVERVIEW: A tool to format C/C++/Java/JavaScript/Objective-C/Protobuf/C# 
code.
 
   If no arguments are specified, it formats the code from standard input
   and writes the result to the standard output.

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=356662&r1=356661&r2=356662&view=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Thu Mar 21 06:09:22 2019
@@ -7,8 +7,8 @@ supported by :doc:`LibFormat` and :doc:`
 
 When using :program:`clang-format` command line utility or
 ``clang::format::reformat(...)`` functions from code, one can either use one of
-the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit) or create a
-custom style by configuring specific style options.
+the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft) or
+create a custom style by configuring specific style options.
 
 
 Configuring Style with clang-format
@@ -68,6 +68,10 @@ An example of a configuration file for m
   Language: Proto
   # Don't format .proto files.
   DisableFormat: true
+  ---
+  Language: CSharp
+  # Use 100 columns for C#.
+  ColumnLimit: 100
   ...
 
 An easy way to get a valid ``.clang-format`` file containing all configuration
@@ -144,6 +148,9 @@ the configuration (without a prefix: ``A
   * ``WebKit``
 A style complying with `WebKit's style guide
 `_
+  * ``Microsoft``
+A style complying with `Microsoft's style guide
+
`_
 
 .. START_FORMAT_STYLE_OPTIONS
 
@@ -1552,6 +1559,9 @@ the confi

[PATCH] D58404: [clang-format] Add basic support for formatting C# files

2019-03-21 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC356662: [clang-format] Add basic support for formatting C# 
files (authored by paulhoad, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D58404?vs=191654&id=191669#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D58404

Files:
  docs/ClangFormat.rst
  docs/ClangFormatStyleOptions.rst
  docs/ReleaseNotes.rst
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/FormatToken.h
  lib/Format/FormatTokenLexer.cpp
  lib/Format/FormatTokenLexer.h
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineFormatter.cpp
  lib/Format/UnwrappedLineParser.cpp
  tools/clang-format/ClangFormat.cpp
  unittests/Format/CMakeLists.txt
  unittests/Format/FormatTestCSharp.cpp

Index: docs/ClangFormat.rst
===
--- docs/ClangFormat.rst
+++ docs/ClangFormat.rst
@@ -11,12 +11,12 @@
 ===
 
 :program:`clang-format` is located in `clang/tools/clang-format` and can be used
-to format C/C++/Java/JavaScript/Objective-C/Protobuf code.
+to format C/C++/Java/JavaScript/Objective-C/Protobuf/C# code.
 
 .. code-block:: console
 
   $ clang-format -help
-  OVERVIEW: A tool to format C/C++/Java/JavaScript/Objective-C/Protobuf code.
+  OVERVIEW: A tool to format C/C++/Java/JavaScript/Objective-C/Protobuf/C# code.
 
   If no arguments are specified, it formats the code from standard input
   and writes the result to the standard output.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -165,7 +165,8 @@
 AST Matchers
 
 
-- ...
+- Add language support for clang-formatting C# files
+- Add Microsoft coding style to encapsulate default C# formatting style
 
 clang-format
 
Index: docs/ClangFormatStyleOptions.rst
===
--- docs/ClangFormatStyleOptions.rst
+++ docs/ClangFormatStyleOptions.rst
@@ -7,8 +7,8 @@
 
 When using :program:`clang-format` command line utility or
 ``clang::format::reformat(...)`` functions from code, one can either use one of
-the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit) or create a
-custom style by configuring specific style options.
+the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft) or
+create a custom style by configuring specific style options.
 
 
 Configuring Style with clang-format
@@ -68,6 +68,10 @@
   Language: Proto
   # Don't format .proto files.
   DisableFormat: true
+  ---
+  Language: CSharp
+  # Use 100 columns for C#.
+  ColumnLimit: 100
   ...
 
 An easy way to get a valid ``.clang-format`` file containing all configuration
@@ -144,6 +148,9 @@
   * ``WebKit``
 A style complying with `WebKit's style guide
 `_
+  * ``Microsoft``
+A style complying with `Microsoft's style guide
+`_
 
 .. START_FORMAT_STYLE_OPTIONS
 
@@ -1552,6 +1559,9 @@
   * ``LK_Cpp`` (in configuration: ``Cpp``)
 Should be used for C, C++.
 
+  * ``LK_CSharp`` (in configuration: ``CSharp``)
+Should be used for C#.
+
   * ``LK_Java`` (in configuration: ``Java``)
 Should be used for Java.
 
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -1258,6 +1258,8 @@
 LK_None,
 /// Should be used for C, C++.
 LK_Cpp,
+/// Should be used for C#.
+LK_CSharp,
 /// Should be used for Java.
 LK_Java,
 /// Should be used for JavaScript.
@@ -1274,6 +1276,7 @@
 LK_TextProto
   };
   bool isCpp() const { return Language == LK_Cpp || Language == LK_ObjC; }
+  bool isCSharp() const { return Language == LK_CSharp; }
 
   /// Language, this format style is targeted at.
   LanguageKind Language;
@@ -2090,6 +2093,8 @@
   switch (Language) {
   case FormatStyle::LK_Cpp:
 return "C++";
+  case FormatStyle::LK_CSharp:
+return "CSharp";
   case FormatStyle::LK_ObjC:
 return "Objective-C";
   case FormatStyle::LK_Java:
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -298,6 +298,8 @@
   CurrentToken->Type = TT_JavaAnnotation;
 if (Left->Previous && Left->Previous->is(TT_LeadingJavaAnnotation))
   CurrentToken->Type = TT_LeadingJavaAnnotation;
+if (Left->Previous && Left->Previous->is(TT_AttributeSquare))
+  CurrentToken->Type = TT_AttributeSquare;
 
 if (!HasMultipleLines)
   Left->PackingKind = PPK_Inconclusiv

[PATCH] D59528: [clang-tidy] Expand modular headers for PPCallbacks

2019-03-21 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr added inline comments.



Comment at: clang-tools-extra/clang-tidy/ClangTidy.h:156
+  virtual void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
+   Preprocessor *ModuleExpanderPP) {}
+

Please document that `ModuleExpanderPP` also provides events from the main file 
(until I read the implementation in the check, I thought the check should 
subscribe to both preprocessors).



Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp:19
+public:
+  // Stores FileEntry for which contents are to be recorded later.
+  void addFileToRecord(const FileEntry *File) { FilesToRecord.insert(File); }

Three slashes in doc comments (everywhere in the patch).



Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp:20
+  // Stores FileEntry for which contents are to be recorded later.
+  void addFileToRecord(const FileEntry *File) { FilesToRecord.insert(File); }
+

"Records that a given file entry is needed for replaying callbacks."

"addNecessaryFile"?



Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp:23
+  // Records content for a file and adds it to the FileSystem.
+  void recordContent(const FileEntry *File,
+ const SrcMgr::ContentCache *ContentCache,

"recordFileContent"?



Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp:24
+  void recordContent(const FileEntry *File,
+ const SrcMgr::ContentCache *ContentCache,
+ llvm::vfs::InMemoryFileSystem &InMemoryFs) {

`const &` for `File` and `ContentCache` ?



Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp:38
+   ContentCache->getRawBuffer()->getBuffer()));
+// Remove file since we have successfully recorded its contents.
+FilesToRecord.erase(File);

"remove the file from the set of necessary files..."



Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp:71
+
+  // Switch of header modules in the new preprocessor.
+  LangOpts.Modules = false;

of => off

However I don't see value in a comment that repeats the source code.



Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp:115
+auto *F = IF.getFile();
+Recorder->addFileToRecord(F);
+  });

`Recorder->addFileToRecord(IF.getFile())`

The intermediate variable doesn't add anything...



Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp:171
+// Just parse to the corresponding location to generate the same callback for
+// the target_callbacks_.
+void ExpandModularHeadersPPCallbacks::Ident(SourceLocation Loc, StringRef) {

What's `target_callbacks_`?  It is only mentioned in comments.



Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h:9
+//
+// Defines the ExpandModularHeadersPPCallbacks class that handles #includes of
+// modular headers, traverses all transitively included headers in non-modular

This looks like a documentation comment for the class itself, I think it should 
be moved there.



Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h:43
+
+  /// \brief Users can get expanded PPCallbacks by registering their callback
+  /// handlers in the preprocessor instance returned by this method.

"Returns the preprocessor that provides callbacks for contents of modular 
headers.

This preprocessor is separate from the one used by the rest of the compiler."




Comment at: 
clang-tools-extra/test/clang-tidy/expand-modular-headers-ppcallbacks.cpp:31
+// CHECK-MESSAGES: c.h:2:9: warning: invalid case style for macro definition 
'c' [readability-identifier-naming]
+// CHECK-MESSAGES: c.h:2:9: note: FIX-IT applied suggested code changes

Please also add a check for a diagnostic coming from the main file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59528



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


r356663 - Permit redeclarations of a builtin to specify calling convention.

2019-03-21 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Thu Mar 21 06:30:56 2019
New Revision: 356663

URL: http://llvm.org/viewvc/llvm-project?rev=356663&view=rev
Log:
Permit redeclarations of a builtin to specify calling convention.

After https://reviews.llvm.org/rL355317 we noticed that quite a decent
amount of code redeclares builtins (memcpy in particular, I believe
reduced from an MSVC header) with a calling convention specified.
This gets particularly troublesome when the user specifies a new
'default' calling convention on the command line.

When looking to add a diagnostic for this case, it was noticed that we
had 3 other diagnostics that differed only slightly.  This patch ALSO
unifies those under a 'select'.  Unfortunately, the order of words in
ONE of these diagnostics was reversed ("'thiscall' calling convention"
vs "calling convention 'thiscall'"), so this patch also standardizes on
the former.

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

Change-Id: I79f99fe7c2301640755ffdd774b46eb44526bb22

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/CodeGen/aarch64-vpcs.c
cfe/trunk/test/Sema/callingconv-iamcu.c
cfe/trunk/test/Sema/callingconv.c
cfe/trunk/test/Sema/pr25786.c
cfe/trunk/test/Sema/stdcall-fastcall-x64.c
cfe/trunk/test/SemaCUDA/cuda-inherits-calling-conv.cu
cfe/trunk/test/SemaCXX/borland-extensions.cpp
cfe/trunk/test/SemaCXX/cxx11-gnu-attrs.cpp
cfe/trunk/test/SemaCXX/virtual-override-x64.cpp
cfe/trunk/test/SemaTemplate/instantiate-function-params.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=356663&r1=356662&r2=356663&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Mar 21 06:30:56 
2019
@@ -2923,7 +2923,14 @@ def err_cconv_change : Error<
   "function declared '%0' here was previously declared "
   "%select{'%2'|without calling convention}1">;
 def warn_cconv_ignored : Warning<
-  "calling convention %0 ignored for this target">, InGroup;
+  "%0 calling convention ignored %select{"
+  // Use CallingConventionIgnoredReason Enum to specify these.
+  "for this target"
+  "|on variadic function"
+  "|on constructor/destructor"
+  "|on builtin function"
+  "}1">,
+  InGroup;
 def err_cconv_knr : Error<
   "function with no prototype cannot use the %0 calling convention">;
 def warn_cconv_knr : Warning<
@@ -2931,12 +2938,6 @@ def warn_cconv_knr : Warning<
   InGroup>;
 def err_cconv_varargs : Error<
   "variadic function cannot use %0 calling convention">;
-def warn_cconv_varargs : Warning<
-  "%0 calling convention ignored on variadic function">,
-  InGroup;
-def warn_cconv_structors : Warning<
-  "%0 calling convention ignored on constructor/destructor">,
-  InGroup;
 def err_regparm_mismatch : Error<"function declared with regparm(%0) "
   "attribute was previously declared "
   "%plural{0:without the regparm|:with the regparm(%1)}1 attribute">;

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=356663&r1=356662&r2=356663&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Mar 21 06:30:56 2019
@@ -11017,6 +11017,15 @@ public:
   Expr *E,
   llvm::function_ref
   Action);
+
+  /// Describes the reason a calling convention specification was ignored, used
+  /// for diagnostics.
+  enum class CallingConventionIgnoredReason {
+ForThisTarget = 0,
+VariadicFunction,
+ConstructorDestructor,
+BuiltinFunction
+  };
 };
 
 /// RAII object that enters a new expression evaluation context.

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=356663&r1=356662&r2=356663&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Mar 21 06:30:56 2019
@@ -3136,6 +3136,15 @@ bool Sema::MergeFunctionDecl(FunctionDec
   // there but not here.
   NewTypeInfo = NewTypeInfo.withCallingConv(OldTypeInfo.getCC());
   RequiresAdjustment = true;
+} else if (New->getBuiltinID()) {
+  // Calling Conventions on a Builtin aren't really useful and setting a
+  // default calling convention and cdecl'ing some builtin redeclarations 
is
+  // common, so warn and ignore the calling convention on the 
redeclaration.
+  Diag(New->getLocation(), diag::warn_cconv_ignored)
+  << FunctionT

[PATCH] D59560: Permit redeclarations of a builtin to specify calling convention.

2019-03-21 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC356663: Permit redeclarations of a builtin to specify 
calling convention. (authored by erichkeane, committed by ).
Herald added a subscriber: kristina.
Herald added a project: clang.

Repository:
  rC Clang

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

https://reviews.llvm.org/D59560

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  test/CodeGen/aarch64-vpcs.c
  test/Sema/callingconv-iamcu.c
  test/Sema/callingconv.c
  test/Sema/pr25786.c
  test/Sema/stdcall-fastcall-x64.c
  test/SemaCUDA/cuda-inherits-calling-conv.cu
  test/SemaCXX/borland-extensions.cpp
  test/SemaCXX/cxx11-gnu-attrs.cpp
  test/SemaCXX/virtual-override-x64.cpp
  test/SemaTemplate/instantiate-function-params.cpp

Index: test/Sema/callingconv-iamcu.c
===
--- test/Sema/callingconv-iamcu.c
+++ test/Sema/callingconv-iamcu.c
@@ -1,35 +1,35 @@
 // RUN: %clang_cc1 %s -fsyntax-only -triple i686-intel-elfiamcu -verify
 
-void __attribute__((fastcall)) foo(float *a) { // expected-warning {{calling convention 'fastcall' ignored for this target}}
+void __attribute__((fastcall)) foo(float *a) { // expected-warning {{'fastcall' calling convention ignored for this target}}
 }
 
-void __attribute__((stdcall)) bar(float *a) { // expected-warning {{calling convention 'stdcall' ignored for this target}}
+void __attribute__((stdcall)) bar(float *a) { // expected-warning {{'stdcall' calling convention ignored for this target}}
 }
 
 void __attribute__((fastcall(1))) baz(float *a) { // expected-error {{'fastcall' attribute takes no arguments}}
 }
 
-void __attribute__((fastcall)) test2(int a, ...) { // expected-warning {{calling convention 'fastcall' ignored for this target}}
+void __attribute__((fastcall)) test2(int a, ...) { // expected-warning {{'fastcall' calling convention ignored for this target}}
 }
-void __attribute__((stdcall)) test3(int a, ...) { // expected-warning {{calling convention 'stdcall' ignored for this target}}
+void __attribute__((stdcall)) test3(int a, ...) { // expected-warning {{'stdcall' calling convention ignored for this target}}
 }
-void __attribute__((thiscall)) test4(int a, ...) { // expected-warning {{calling convention 'thiscall' ignored for this target}}
+void __attribute__((thiscall)) test4(int a, ...) { // expected-warning {{'thiscall' calling convention ignored for this target}}
 }
 
 void __attribute__((cdecl)) ctest0() {}
 
 void __attribute__((cdecl(1))) ctest1(float x) {} // expected-error {{'cdecl' attribute takes no arguments}}
 
-void (__attribute__((fastcall)) *pfoo)(float*) = foo; // expected-warning {{calling convention 'fastcall' ignored for this target}}
+void (__attribute__((fastcall)) *pfoo)(float*) = foo; // expected-warning {{'fastcall' calling convention ignored for this target}}
 
-void (__attribute__((stdcall)) *pbar)(float*) = bar; // expected-warning {{calling convention 'stdcall' ignored for this target}}
+void (__attribute__((stdcall)) *pbar)(float*) = bar; // expected-warning {{'stdcall' calling convention ignored for this target}}
 
 void (*pctest0)() = ctest0;
 
 void ctest2() {}
 void (__attribute__((cdecl)) *pctest2)() = ctest2;
 
-typedef void (__attribute__((fastcall)) *Handler) (float *); // expected-warning {{calling convention 'fastcall' ignored for this target}}
+typedef void (__attribute__((fastcall)) *Handler) (float *); // expected-warning {{'fastcall' calling convention ignored for this target}}
 Handler H = foo;
 
 int __attribute__((pcs("aapcs", "aapcs"))) pcs1(void); // expected-error {{'pcs' attribute takes one argument}}
@@ -38,16 +38,16 @@
// expected-error {{invalid PCS type}}
 int __attribute__((pcs(0))) pcs4(void); // expected-error {{'pcs' attribute requires a string}}
 /* These are ignored because the target is i386 and not ARM */
-int __attribute__((pcs("aapcs"))) pcs5(void); // expected-warning {{calling convention 'pcs' ignored for this target}}
-int __attribute__((pcs("aapcs-vfp"))) pcs6(void); // expected-warning {{calling convention 'pcs' ignored for this target}}
+int __attribute__((pcs("aapcs"))) pcs5(void); // expected-warning {{'pcs' calling convention ignored for this target}}
+int __attribute__((pcs("aapcs-vfp"))) pcs6(void); // expected-warning {{'pcs' calling convention ignored for this target}}
 int __attribute__((pcs("foo"))) pcs7(void); // expected-error {{invalid PCS type}}
 
 void ctest3();
 void __attribute__((cdecl)) ctest3() {}
 
-typedef __attribute__((stdcall)) void (*PROC)(); // expected-warning {{calling convention 'stdcall' ignored for this target}}
+typedef __attribute__((stdcall)) void (*PROC)(); // expected-warning {{'stdcall' calling convention ignored for this target}}
 PROC __attribute__((cdecl)) ctest4(const char *x)

[PATCH] D59639: [clangd] Print template arguments helper

2019-03-21 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added reviewers: ioeric, ilya-biryukov.
Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay, mgorny.
Herald added a project: clang.

Prepares ground for printing template arguments as written in the
source code, part of re-landing rC356541  
with D59599  applied.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D59639

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/AST.h
  clang-tools-extra/unittests/clangd/ASTUtilsTests.cpp
  clang-tools-extra/unittests/clangd/CMakeLists.txt
  clang/lib/AST/TypePrinter.cpp

Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1632,6 +1632,21 @@
   return A.getArgument();
 }
 
+static void printArgument(const TemplateArgument &A, const PrintingPolicy &PP,
+  llvm::raw_ostream &OS) {
+  A.print(PP, OS);
+}
+
+static void printArgument(const TemplateArgumentLoc &A,
+  const PrintingPolicy &PP, llvm::raw_ostream &OS) {
+  const auto &Kind = A.getArgument().getKind();
+  assert(Kind != TemplateArgument::Null &&
+ "TemplateArgumentKind can not be null!");
+  if (Kind == TemplateArgument::ArgKind::Type)
+return A.getTypeSourceInfo()->getType().print(OS, PP);
+  return A.getArgument().print(PP, OS);
+}
+
 template
 static void printTo(raw_ostream &OS, ArrayRef Args,
 const PrintingPolicy &Policy, bool SkipBrackets) {
@@ -1653,7 +1668,7 @@
 } else {
   if (!FirstArg)
 OS << Comma;
-  Argument.print(Policy, ArgOS);
+  printArgument(Arg, Policy, ArgOS);
 }
 StringRef ArgString = ArgOS.str();
 
Index: clang-tools-extra/unittests/clangd/CMakeLists.txt
===
--- clang-tools-extra/unittests/clangd/CMakeLists.txt
+++ clang-tools-extra/unittests/clangd/CMakeLists.txt
@@ -10,6 +10,7 @@
 
 add_extra_unittest(ClangdTests
   Annotations.cpp
+  ASTUtilsTests.cpp
   BackgroundIndexTests.cpp
   CancellationTests.cpp
   ClangdTests.cpp
Index: clang-tools-extra/unittests/clangd/ASTUtilsTests.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clangd/ASTUtilsTests.cpp
@@ -0,0 +1,63 @@
+#include "AST.h"
+#include "Annotations.h"
+#include "Protocol.h"
+#include "SourceCode.h"
+#include "TestTU.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+using testing::ElementsAre;
+
+TEST(ASTUtils, PrintTemplateArgs) {
+  Annotations Test(R"cpp(
+  template  class Bar {};
+  template <> class ^Bar {};
+
+  template  class Z, int Q> struct Foo {};
+  template struct ^Foo;
+  template  struct ^Foo {};
+
+  template  class Baz {};
+  template <> class ^Baz {};
+  template  class ^Baz {};
+
+  template  void Foz() {};
+  template <> void ^Foz<3, 5, 8>() {};
+
+  template  class ...> class Aux {};
+  template <> class ^Aux {};
+  template  T> class ^Aux {};
+
+  template  T var = 1234;
+  template <> int ^var = 1;
+  )cpp");
+  auto AST = TestTU::withCode(Test.code()).build();
+  struct Visitor : RecursiveASTVisitor {
+Visitor(std::vector Points) : Points(std::move(Points)) {}
+bool VisitNamedDecl(const NamedDecl *ND) {
+  auto Pos = sourceLocToPosition(ND->getASTContext().getSourceManager(),
+ ND->getLocation());
+  if (Pos != Points[TemplateArgs.size()])
+return true;
+  TemplateArgs.push_back(printTemplateArgsAsWritten(*ND));
+  return true;
+}
+std::vector TemplateArgs;
+const std::vector Points;
+  };
+  Visitor V(Test.points());
+  V.TraverseDecl(AST.getASTContext().getTranslationUnitDecl());
+  EXPECT_THAT(V.TemplateArgs,
+  ElementsAre("", "", "",
+  "", "", "<3, 5, 8>", "",
+  "", ""));
+}
+
+} // namespace
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/AST.h
===
--- clang-tools-extra/clangd/AST.h
+++ clang-tools-extra/clangd/AST.h
@@ -47,6 +47,12 @@
 /// "(anonymous struct)" or "(anonymous namespace)".
 std::string printName(const ASTContext &Ctx, const NamedDecl &ND);
 
+/// Prints template arguments of a decl including enclosing '<' and '>', e.g for
+/// a partial specialization like: template  struct Foo will
+/// return ''.
+/// Returns an empty string if type is not a template specialization.
+std::string printTemplateArgsAsWritten(const NamedDecl &ND);
+
 /// Gets the symbol ID for a declaration, if possible.
 llvm::Optional getSymbolID(const Decl *D);
 
Index: clang-tools-extra/clangd/AST.cpp
=

[PATCH] D59528: [clang-tidy] Expand modular headers for PPCallbacks

2019-03-21 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr added inline comments.



Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h:32
+
+/// \brief Handles PPCallbacks and replays preprocessing with modules disabled.
+///

replays => re-runs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59528



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


[PATCH] D59453: [ASTMatchers][OpenMP] Add base ompExecutableDirective() matcher.

2019-03-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 191674.
lebedev.ri added a comment.

Rebased, addressed nits.


Repository:
  rC Clang

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

https://reviews.llvm.org/D59453

Files:
  docs/LibASTMatchersReference.html
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/ASTMatchersInternal.cpp
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/AST/OMPStructuredBlockTest.cpp
  unittests/ASTMatchers/ASTMatchersNodeTest.cpp
  unittests/ASTMatchers/ASTMatchersTest.h

Index: unittests/ASTMatchers/ASTMatchersTest.h
===
--- unittests/ASTMatchers/ASTMatchersTest.h
+++ unittests/ASTMatchers/ASTMatchersTest.h
@@ -234,6 +234,18 @@
   return matchesConditionallyWithCuda(Code, AMatcher, false, "-std=c++11");
 }
 
+template 
+testing::AssertionResult matchesWithOpenMP(const std::string &Code,
+   const T &AMatcher) {
+  return matchesConditionally(Code, AMatcher, true, "-fopenmp");
+}
+
+template 
+testing::AssertionResult notMatchesWithOpenMP(const std::string &Code,
+  const T &AMatcher) {
+  return matchesConditionally(Code, AMatcher, false, "-fopenmp");
+}
+
 template 
 testing::AssertionResult
 matchAndVerifyResultConditionally(const std::string &Code, const T &AMatcher,
Index: unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1765,5 +1765,29 @@
   EXPECT_FALSE(matchesObjC(ObjCStringNoPool, autoreleasePoolStmt()));
 }
 
+TEST(OMPExecutableDirective, Matches) {
+  auto Matcher = stmt(ompExecutableDirective());
+
+  const std::string Source0 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source0, Matcher));
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp taskyield
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source1, Matcher));
+
+  const std::string Source2 = R"(
+void x() {
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source2, Matcher));
+}
+
 } // namespace ast_matchers
 } // namespace clang
Index: unittests/AST/OMPStructuredBlockTest.cpp
===
--- unittests/AST/OMPStructuredBlockTest.cpp
+++ unittests/AST/OMPStructuredBlockTest.cpp
@@ -27,10 +27,6 @@
 
 AST_MATCHER(Stmt, isOMPStructuredBlock) { return Node.isOMPStructuredBlock(); }
 
-const ast_matchers::internal::VariadicDynCastAllOfMatcher<
-Stmt, OMPExecutableDirective>
-ompExecutableDirective;
-
 const ast_matchers::internal::VariadicDynCastAllOfMatcher<
 OMPExecutableDirective, OMPTargetDirective>
 ompTargetDirective;
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -434,6 +434,7 @@
   REGISTER_MATCHER(objcThrowStmt);
   REGISTER_MATCHER(objcTryStmt);
   REGISTER_MATCHER(ofClass);
+  REGISTER_MATCHER(ompExecutableDirective);
   REGISTER_MATCHER(on);
   REGISTER_MATCHER(onImplicitObjectArgument);
   REGISTER_MATCHER(opaqueValueExpr);
Index: lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- lib/ASTMatchers/ASTMatchersInternal.cpp
+++ lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -845,5 +845,8 @@
 AST_POLYMORPHIC_SUPPORTED_TYPES(BlockPointerType, MemberPointerType,
 PointerType, ReferenceType));
 
+const internal::VariadicDynCastAllOfMatcher
+ompExecutableDirective;
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -60,6 +60,7 @@
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
+#include "clang/AST/StmtOpenMP.h"
 #include "clang/AST/TemplateBase.h"
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
@@ -6369,6 +6370,29 @@
   return false;
 }
 
+////
+// OpenMP handling.
+////
+
+/// Matches any ``#pragma omp`` executable directive.
+///
+/// Given
+///
+/// \code
+///   #pragma omp parallel
+///   #pragma omp parallel default(none)
+///   #pragma omp taskyield
+/// \endcode
+///
+/// ``ompExecutableDirective()`` matches ``omp parallel``,
+/// ``omp parallel default(none)`` and ``omp taskyield``.
+extern const internal::VariadicDynCastAllOfMatcher
+ompExecutableDirective;
+
+////
+// End OpenMP handling.
+//

[PATCH] D59463: [ASTMatchers][OpenMP] OpenMP Structured-block-related matchers

2019-03-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 191676.
lebedev.ri marked 6 inline comments as done.
lebedev.ri added a comment.

Rebased, addressed all(?) nits.


Repository:
  rC Clang

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

https://reviews.llvm.org/D59463

Files:
  docs/LibASTMatchersReference.html
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2274,6 +2274,71 @@
 notMatches("int main2() {}", functionDecl(isMain(;
 }
 
+TEST(OMPExecutableDirective, isStandaloneDirective) {
+  auto Matcher = ompExecutableDirective(isStandaloneDirective());
+
+  const std::string Source0 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp taskyield
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source1, Matcher));
+}
+
+TEST(Stmt, isOMPStructuredBlock) {
+  const std::string Source0 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+  EXPECT_TRUE(
+  matchesWithOpenMP(Source0, stmt(nullStmt(), isOMPStructuredBlock(;
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp parallel
+{;}
+})";
+  EXPECT_TRUE(
+  notMatchesWithOpenMP(Source1, stmt(nullStmt(), isOMPStructuredBlock(;
+  EXPECT_TRUE(
+  matchesWithOpenMP(Source1, stmt(compoundStmt(), isOMPStructuredBlock(;
+}
+
+TEST(OMPExecutableDirective, hasStructuredBlock) {
+  const std::string Source0 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(
+  Source0, ompExecutableDirective(hasStructuredBlock(nullStmt();
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp parallel
+{;}
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(
+  Source1, ompExecutableDirective(hasStructuredBlock(nullStmt();
+  EXPECT_TRUE(matchesWithOpenMP(
+  Source1, ompExecutableDirective(hasStructuredBlock(compoundStmt();
+
+  const std::string Source2 = R"(
+void x() {
+#pragma omp taskyield
+{;}
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(
+  Source2, ompExecutableDirective(hasStructuredBlock(anything();
+}
+
 TEST(OMPExecutableDirective, hasClause) {
   auto Matcher = ompExecutableDirective(hasAnyClause(anything()));
 
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -304,6 +304,7 @@
   REGISTER_MATCHER(hasSourceExpression);
   REGISTER_MATCHER(hasSpecializedTemplate);
   REGISTER_MATCHER(hasStaticStorageDuration);
+  REGISTER_MATCHER(hasStructuredBlock);
   REGISTER_MATCHER(hasSyntacticForm);
   REGISTER_MATCHER(hasTargetDecl);
   REGISTER_MATCHER(hasTemplateArgument);
@@ -379,6 +380,7 @@
   REGISTER_MATCHER(isNoReturn);
   REGISTER_MATCHER(isNoThrow);
   REGISTER_MATCHER(isNoneKind);
+  REGISTER_MATCHER(isOMPStructuredBlock);
   REGISTER_MATCHER(isOverride);
   REGISTER_MATCHER(isPrivate);
   REGISTER_MATCHER(isProtected);
@@ -387,6 +389,7 @@
   REGISTER_MATCHER(isScoped);
   REGISTER_MATCHER(isSharedKind);
   REGISTER_MATCHER(isSignedInteger);
+  REGISTER_MATCHER(isStandaloneDirective);
   REGISTER_MATCHER(isStaticLocal);
   REGISTER_MATCHER(isStaticStorageClass);
   REGISTER_MATCHER(isStruct);
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -6394,6 +6394,58 @@
 extern const internal::VariadicDynCastAllOfMatcher
 ompExecutableDirective;
 
+/// Matches standalone OpenMP directives,
+/// i.e., directives that can't have a structured block.
+///
+/// Given
+///
+/// \code
+///   #pragma omp parallel
+///   {}
+///   #pragma omp taskyield
+/// \endcode
+///
+/// ``ompExecutableDirective(isStandaloneDirective()))`` matches
+/// ``omp taskyield``.
+AST_MATCHER(OMPExecutableDirective, isStandaloneDirective) {
+  return Node.isStandaloneDirective();
+}
+
+/// Matches the Stmt AST node that is marked as being the structured-block
+/// of an OpenMP executable directive.
+///
+/// Given
+///
+/// \code
+///#pragma omp parallel
+///{}
+/// \endcode
+///
+/// ``stmt(isOMPStructuredBlock()))`` matches ``{}``.
+AST_MATCHER(Stmt, isOMPStructuredBlock) { return Node.isOMPStructuredBlock(); }
+
+/// Matches the structured-block of the OpenMP executable directive
+///
+/// Prerequisite: the executable directive must not be standalone directive.
+/// If it is, it will never match.
+///
+/// Given
+///
+/// \code
+///#pragma omp parallel
+///;
+///#pragma omp parallel
+///{}
+/// \endcode
+///
+/// ``ompExecutableDirective(hasStructuredBlo

[PATCH] D57112: [ASTTypeTraits][ASTMatchers][OpenMP] OMPClause handling

2019-03-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: include/clang/ASTMatchers/ASTMatchers.h:6456
+  // Note that we have recieved a *matcher* for the clause, not the
+  // OpenMPClauseKind. We now need to extract the 'return' type of said 
matcher,
+  // and convert it to the OpenMPClauseKind, so we can finally use that.

aaron.ballman wrote:
> gribozavr wrote:
> > lebedev.ri wrote:
> > > gribozavr wrote:
> > > > lebedev.ri wrote:
> > > > > gribozavr wrote:
> > > > > > lebedev.ri wrote:
> > > > > > > gribozavr wrote:
> > > > > > > > Why not make `isAllowedToContainClause` take an 
> > > > > > > > `OpenMPClauseKind` enum value?
> > > > > > > > 
> > > > > > > > I don't see right now advantages for taking a matcher.  (For 
> > > > > > > > example, it can't be a more complex matcher with inner 
> > > > > > > > matchers, it can't be a disjunction of matchers etc.)
> > > > > > > I don't feel like it, it's uglier.
> > > > > > > The matcher is documented, `OpenMPClauseKind` is not documented.
> > > > > > > Also, how will passing some random enum work with e.g. 
> > > > > > > clang-query?
> > > > > > > 
> > > > > > There are dozens of clauses in `OpenMPClauseKind`.  We would have 
> > > > > > to replicate them all as matchers to provide a useful API.
> > > > > > 
> > > > > > > Also, how will passing some random enum work with e.g. 
> > > > > > > clang-query?
> > > > > > 
> > > > > > See `llvm/tools/clang/lib/ASTMatchers/Dynamic/Marshallers.h`.
> > > > > True. Also, but there's dosens of Stmt types, and there is no 
> > > > > overload that takes `StmtClass` enum.
> > > > For Stmts, we do have dozens of individual matchers for them.
> > > > 
> > > > The point of your work is to add ASTMatchers for OpenMP, right?  
> > > > However, if there are no matchers for a reasonable amount of AST 
> > > > surface, it is as good as if the matchers are not there, because 
> > > > prospective users won't be able to use them.
> > > > 
> > > > I don't particularly care how exactly this is achieved, through 
> > > > individual matchers or through a matcher that takes an enum.  However, 
> > > > I want to make sure that if you're going through all this trouble to 
> > > > add matchers, the resulting API should cover a good amount of AST.
> > > > 
> > > > The reason why I suggested to pass the enum to the matcher is simply 
> > > > because it is less code duplication, less work, and more reliable code 
> > > > (since there will be only one matcher to review, test, and maintain, 
> > > > instead of combinations of matchers).
> > > > 
> > > > Another reason to not use an inner matcher here is the peculiar 
> > > > semantics of this function -- it does not evaluate the matcher, and it 
> > > > does not accept a matcher expression of any shape.
> > > > The point of your work is to add ASTMatchers for OpenMP, right?
> > > 
> > > Absolutely not.
> > > D57113 + D59466 is the one and only point, to address the bugs i have 
> > > personally encountered.
> > > The whole reason why i have started off with NOT adding these matchers to 
> > > the `ASTMatchers.h`,
> > > but keeping them at least initially internal to the checks was to avoid 
> > > all this bikeshedding.
> > However, I do care about the AST matchers being usable by other clients.
> > 
> > I also care about the API following existing patterns:
> > 
> > > Another reason to not use an inner matcher here is the peculiar semantics 
> > > of this function -- it does not evaluate the matcher, and it does not 
> > > accept a matcher expression of any shape.
> > 
> > 
> >> Also, how will passing some random enum work with e.g. clang-query?
> > See llvm/tools/clang/lib/ASTMatchers/Dynamic/Marshallers.h.
> 
> That doesn't mean it works super well, though. String literals more easily 
> contain silent typos, don't have autocomplete support, etc. I can definitely 
> sympathize with not wanting to use an enum here.
> 
> However, I see that there are 50+ enumerations in this list -- that seems 
> like too many matchers to want to expose. I think an enum will be the better, 
> more maintainable option. The current approach won't scale well.
Okay, but apparently clang-query will needs to be fixed too:
```
clang-query> match 
stmt(ompExecutableDirective(isAllowedToContainClause(OMPC_default)))
1:1: Error parsing argument 1 for matcher stmt.
1:6: Error parsing argument 1 for matcher ompExecutableDirective.
1:29: Error parsing argument 1 for matcher isAllowedToContainClause.
1:58: Error parsing matcher. Found token <_> while looking for '('.

```
https://bugs.llvm.org/show_bug.cgi?id=41176



Comment at: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp:2283
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+

aaron.ballman wrote:
> gribozavr wrote:
> > lebedev.ri wrote:
> > > gribozavr wrote:
> > > > lebedev.ri wrote:
> > > > > gribozavr wrote:
> > > > > > I'm not sure if breaking out the source code into the "SourceX" 
> > > > >

[PATCH] D57112: [ASTTypeTraits][ASTMatchers][OpenMP] OMPClause handling

2019-03-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 191678.
lebedev.ri marked 18 inline comments as done.
lebedev.ri added a comment.

Rebased, addressed all(?) nits.


Repository:
  rC Clang

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

https://reviews.llvm.org/D57112

Files:
  docs/LibASTMatchersReference.html
  include/clang/AST/ASTTypeTraits.h
  include/clang/ASTMatchers/ASTMatchers.h
  lib/AST/ASTTypeTraits.cpp
  lib/ASTMatchers/ASTMatchersInternal.cpp
  lib/ASTMatchers/Dynamic/Marshallers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1789,5 +1789,43 @@
   EXPECT_TRUE(notMatchesWithOpenMP(Source2, Matcher));
 }
 
+TEST(OMPDefaultClause, Matches) {
+  auto Matcher = ompExecutableDirective(hasAnyClause(ompDefaultClause()));
+
+  const std::string Source0 = R"(
+void x() {
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source1, Matcher));
+
+  const std::string Source2 = R"(
+void x() {
+#pragma omp parallel default(none)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source2, Matcher));
+
+  const std::string Source3 = R"(
+void x() {
+#pragma omp parallel default(shared)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source3, Matcher));
+
+  const std::string Source4 = R"(
+void x(int x) {
+#pragma omp parallel num_threads(x)
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source4, Matcher));
+}
+
 } // namespace ast_matchers
 } // namespace clang
Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2274,5 +2274,173 @@
 notMatches("int main2() {}", functionDecl(isMain(;
 }
 
+TEST(OMPExecutableDirective, hasClause) {
+  auto Matcher = ompExecutableDirective(hasAnyClause(anything()));
+
+  const std::string Source0 = R"(
+void x() {
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source1, Matcher));
+
+  const std::string Source2 = R"(
+void x() {
+#pragma omp parallel default(none)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source2, Matcher));
+
+  const std::string Source3 = R"(
+void x() {
+#pragma omp parallel default(shared)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source3, Matcher));
+
+  const std::string Source4 = R"(
+void x(int x) {
+#pragma omp parallel num_threads(x)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source4, Matcher));
+}
+
+TEST(OMPDefaultClause, isNoneKind) {
+  auto Matcher =
+  ompExecutableDirective(hasAnyClause(ompDefaultClause(isNoneKind(;
+
+  const std::string Source0 = R"(
+void x() {
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source1, Matcher));
+
+  const std::string Source2 = R"(
+void x() {
+#pragma omp parallel default(none)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source2, Matcher));
+
+  const std::string Source3 = R"(
+void x() {
+#pragma omp parallel default(shared)
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source3, Matcher));
+
+  const std::string Source4 = R"(
+void x(int x) {
+#pragma omp parallel num_threads(x)
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source4, Matcher));
+}
+
+TEST(OMPDefaultClause, isSharedKind) {
+  auto Matcher =
+  ompExecutableDirective(hasAnyClause(ompDefaultClause(isSharedKind(;
+
+  const std::string Source0 = R"(
+void x() {
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source1, Matcher));
+
+  const std::string Source2 = R"(
+void x() {
+#pragma omp parallel default(shared)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source2, Matcher));
+
+  const std::string Source3 = R"(
+void x() {
+#pragma omp parallel default(none)
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source3, Matcher));
+
+  const std::string Source4 = R"(
+void x(int x) {
+#pragma omp parallel num_threads(x)
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source4, Matcher));
+}
+
+TEST(OMPExecutableDirective, isAllowedToContainClauseKind) {
+  auto Matcher =
+  ompExecutableDirective(isAllowedToContainClauseKind(OMPC_default));
+
+  const std::string Source0 = R"(
+void x() {
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp parallel
+;

[PATCH] D59640: [clangd] Add TemplateArgumentList into Symbol

2019-03-21 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added reviewers: ioeric, ilya-biryukov, gribozavr.
Herald added subscribers: cfe-commits, jdoerfert, arphaman, jkorous, MaskRay.
Herald added a project: clang.

Part of re-landing rC356541  with D59599 
. Changes the way we store
template arguments, previous patch was storing them inside Name field of Symbol.
Which was violating the assumption:

  Symbol::Scope+Symbol::Name == clang::clangd::printQualifiedName

which was made in multiple places inside codebase. This patch instead moves
those arguments into their own field. Currently the field is meant to be
human-readable, can be made structured if need be.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D59640

Files:
  clang-tools-extra/clangd/index/Serialization.cpp
  clang-tools-extra/clangd/index/Symbol.h
  clang-tools-extra/clangd/index/SymbolCollector.cpp
  clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp

Index: clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp
===
--- clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp
+++ clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp
@@ -51,6 +51,9 @@
   return (arg.Name + arg.CompletionSnippetSuffix).str() == S;
 }
 MATCHER_P(QName, Name, "") { return (arg.Scope + arg.Name).str() == Name; }
+MATCHER_P(TemplateArgs, TemplArgs, "") {
+  return arg.TemplateArgumentList == TemplArgs;
+}
 MATCHER_P(DeclURI, P, "") {
   return StringRef(arg.CanonicalDeclaration.FileURI) == P;
 }
@@ -394,23 +397,80 @@
   Annotations Header(R"(
 // Primary template and explicit specialization are indexed, instantiation
 // is not.
-template  struct [[Tmpl]] {T $xdecl[[x]] = 0;};
-template <> struct $specdecl[[Tmpl]] {};
-template  struct $partspecdecl[[Tmpl]] {};
-extern template struct Tmpl;
-template struct Tmpl;
+template  class $barclasstemp[[Bar]] {};
+template  class Z, int Q>
+struct [[Tmpl]] { T $xdecl[[x]] = 0; };
+
+// template-template, non-type and type full spec
+template <> struct $specdecl[[Tmpl]] {};
+
+// template-template, non-type and type partial spec
+template  struct $partspecdecl[[Tmpl]] {};
+// instantiation
+extern template struct Tmpl;
+// instantiation
+template struct Tmpl;
+
+template  class $fooclasstemp[[Foo]] {};
+// parameter-packs full spec
+template<> class $parampack[[Foo]], int, double> {};
+// parameter-packs partial spec
+template class $parampackpartial[[Foo]] {};
+
+template  class $bazclasstemp[[Baz]] {};
+// non-type parameter-packs full spec
+template<> class $parampacknontype[[Baz]]<3, 5, 8> {};
+// non-type parameter-packs partial spec
+template class $parampacknontypepartial[[Baz]] {};
+
+template  class ...> class $fozclasstemp[[Foz]] {};
+// template-template parameter-packs full spec
+template<> class $parampacktempltempl[[Foz]] {};
+// template-template parameter-packs partial spec
+template class T>
+class $parampacktempltemplpartial[[Foz]] {};
   )");
   runSymbolCollector(Header.code(), /*Main=*/"");
-  EXPECT_THAT(Symbols,
-  UnorderedElementsAre(
-  AllOf(QName("Tmpl"), DeclRange(Header.range()),
-ForCodeCompletion(true)),
-  AllOf(QName("Tmpl"), DeclRange(Header.range("specdecl")),
-ForCodeCompletion(false)),
-  AllOf(QName("Tmpl"), DeclRange(Header.range("partspecdecl")),
-ForCodeCompletion(false)),
-  AllOf(QName("Tmpl::x"), DeclRange(Header.range("xdecl")),
-ForCodeCompletion(false;
+  EXPECT_THAT(Symbols.size(), 14U);
+  EXPECT_THAT(
+  Symbols,
+  AllOf(
+  Contains(AllOf(QName("Tmpl"), DeclRange(Header.range()),
+ ForCodeCompletion(true))),
+  Contains(AllOf(QName("Bar"), DeclRange(Header.range("barclasstemp")),
+ ForCodeCompletion(true))),
+  Contains(AllOf(QName("Foo"), DeclRange(Header.range("fooclasstemp")),
+ ForCodeCompletion(true))),
+  Contains(AllOf(QName("Baz"), DeclRange(Header.range("bazclasstemp")),
+ ForCodeCompletion(true))),
+  Contains(AllOf(QName("Foz"), DeclRange(Header.range("fozclasstemp")),
+ ForCodeCompletion(true))),
+  Contains(AllOf(QName("Tmpl"), TemplateArgs(""),
+ DeclRange(Header.range("specdecl")),
+ ForCodeCompletion(false))),
+  Contains(AllOf(QName("Tmpl"), TemplateArgs(""),
+ DeclRange(Header.range("partspecdecl")),
+ ForCodeCompletion(false))),
+  Contains(AllOf(QName("Foo"), TemplateArgs(", int, double>"),
+ 

[PATCH] D59641: [clangd] Show template argument list in workspacesymbols and documentsymbols responses

2019-03-21 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added reviewers: ioeric, ilya-biryukov.
Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay.
Herald added a project: clang.
kadircet added a parent revision: D59640: [clangd] Add TemplateArgumentList 
into Symbol.
kadircet added a subscriber: nridge.

Last part of re-landing rC356541 . Puts 
TemplateArgumentsList into
responses of the above mentioned two requests.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D59641

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/FindSymbols.cpp
  clang-tools-extra/clangd/index/MemIndex.cpp
  clang-tools-extra/clangd/index/dex/Dex.cpp
  clang-tools-extra/unittests/clangd/DexTests.cpp
  clang-tools-extra/unittests/clangd/FindSymbolsTests.cpp
  clang-tools-extra/unittests/clangd/IndexTests.cpp
  clang-tools-extra/unittests/clangd/TestIndex.cpp

Index: clang-tools-extra/unittests/clangd/TestIndex.cpp
===
--- clang-tools-extra/unittests/clangd/TestIndex.cpp
+++ clang-tools-extra/unittests/clangd/TestIndex.cpp
@@ -94,7 +94,7 @@
 }
 
 std::string getQualifiedName(const Symbol &Sym) {
-  return (Sym.Scope + Sym.Name).str();
+  return (Sym.Scope + Sym.Name + Sym.TemplateArgumentList).str();
 }
 
 std::vector match(const SymbolIndex &I,
Index: clang-tools-extra/unittests/clangd/IndexTests.cpp
===
--- clang-tools-extra/unittests/clangd/IndexTests.cpp
+++ clang-tools-extra/unittests/clangd/IndexTests.cpp
@@ -22,6 +22,7 @@
 using testing::AllOf;
 using testing::AnyOf;
 using testing::ElementsAre;
+using testing::IsEmpty;
 using testing::Pair;
 using testing::Pointee;
 using testing::UnorderedElementsAre;
@@ -187,35 +188,35 @@
   SymbolSlab::Builder B;
 
   Symbol S = symbol("TempSpec");
-  S.ID = SymbolID("0");
+  S.ID = SymbolID("1");
   B.insert(S);
 
   S = symbol("TempSpec");
-  S.ID = SymbolID("1");
+  S.ID = SymbolID("2");
+  S.TemplateArgumentList = "";
   S.SymInfo.Properties = static_cast(
   index::SymbolProperty::TemplateSpecialization);
   B.insert(S);
 
   S = symbol("TempSpec");
-  S.ID = SymbolID("2");
+  S.ID = SymbolID("3");
+  S.TemplateArgumentList = "";
   S.SymInfo.Properties = static_cast(
   index::SymbolProperty::TemplatePartialSpecialization);
   B.insert(S);
 
   auto I = MemIndex::build(std::move(B).build(), RefSlab());
   FuzzyFindRequest Req;
-  Req.Query = "TempSpec";
   Req.AnyScope = true;
 
-  std::vector Symbols;
-  I->fuzzyFind(Req, [&Symbols](const Symbol &Sym) { Symbols.push_back(Sym); });
-  EXPECT_EQ(Symbols.size(), 1U);
-  EXPECT_FALSE(Symbols.front().SymInfo.Properties &
-   static_cast(
-   index::SymbolProperty::TemplateSpecialization));
-  EXPECT_FALSE(Symbols.front().SymInfo.Properties &
-   static_cast(
-   index::SymbolProperty::TemplatePartialSpecialization));
+  Req.Query = "TempSpec";
+  EXPECT_THAT(match(*I, Req),
+  UnorderedElementsAre("TempSpec", "TempSpec",
+   "TempSpec"));
+
+  // FIXME: Add filtering for template argument list.
+  Req.Query = "TempSpec class Foo {};
+  template  class Foo {};
+  template <> class Foo {};
+  template <> class Foo {};
+  )cpp");
+  // Foo is higher ranked because of exact name match.
+  EXPECT_THAT(
+  getSymbols("Foo"),
+  UnorderedElementsAre(
+  AllOf(QName("Foo"), WithKind(SymbolKind::Class)),
+  AllOf(QName("Foo"), WithKind(SymbolKind::Class)),
+  AllOf(QName("Foo"), WithKind(SymbolKind::Class)),
+  AllOf(QName("Foo"), WithKind(SymbolKind::Class;
+}
+
 namespace {
 class DocumentSymbolsTest : public ::testing::Test {
 public:
@@ -525,11 +541,9 @@
   AllOf(WithName("Tmpl"), WithKind(SymbolKind::Struct),
 Children()),
   AllOf(WithName("funcTmpl"), Children()),
-  // FIXME(ibiryukov): template args should be  to match the code.
-  AllOf(WithName("funcTmpl"), Children()),
+  AllOf(WithName("funcTmpl"), Children()),
   AllOf(WithName("varTmpl"), Children()),
-  // FIXME(ibiryukov): template args should be  to match the code.
-  AllOf(WithName("varTmpl"), Children(;
+  AllOf(WithName("varTmpl"), Children(;
 }
 
 TEST_F(DocumentSymbolsTest, Namespaces) {
@@ -653,5 +667,22 @@
   WithName("using namespace ns_alias")));
 }
 
+TEST_F(DocumentSymbolsTest, TempSpecs) {
+  addFile("foo.cpp", R"cpp(
+  template  class Foo {};
+  template  class Foo {};
+  template <> class Foo {};
+  template <> class Foo {};
+  )cpp");
+  // Foo is higher ranked because of exact name match.
+  EXPECT_THAT(
+  getSymbols("foo.cpp"),
+  UnorderedElementsAre(
+  AllOf(WithName("Foo"), WithKind(SymbolKind::Class)),
+  AllOf(WithName("Foo"), Wit

Re: r356222 - [analyzer] Support C++17 aggregates with bases without constructors.

2019-03-21 Thread Alexander Kornienko via cfe-commits
Thanks for the fix! Meanwhile, I found a couple of code samples that
trigger this assertion with a slightly different stack trace. Not sure if
they are substantially different though.

#1:
$ cat t.cc
inline namespace a {
class b typedef c;
}
class A {};
namespace a {
class b : A {};
}  // namespace a
class d {
 public:
  operator c();
};
d e() { c f{e()}; }
$ clang-tidy -checks="-*,clang-analyzer*" t.cc -- -std=c++17
assert.h assertion failed at
llvm/tools/clang/lib/StaticAnalyzer/Core/RegionStore.cpp:2362 in (anonymous
namespace)::RegionBindingsRef (anonymous
namespace)::RegionStoreManager::bindStruct(RegionBindingsConstRef, const
clang::ento::TypedValueRegion *, clang::ento::SVal): CRD->isAggregate() &&
"Non-aggregates are constructed with a constructor!"
@ 0x5605d5ca35c6  __assert_fail
@ 0x5605d44064e4  (anonymous
namespace)::RegionStoreManager::bindStruct()
@ 0x5605d43fb058  (anonymous namespace)::RegionStoreManager::Bind()
@ 0x5605d43e5d2f  clang::ento::ProgramState::bindLoc()
@ 0x5605d43975c5
clang::ento::ExprEngine::processPointerEscapedOnBind()
@ 0x5605d438f143  clang::ento::ExprEngine::evalBind()
@ 0x5605d43a46d3  clang::ento::ExprEngine::VisitDeclStmt()
@ 0x5605d438ddff  clang::ento::ExprEngine::Visit()
@ 0x5605d438a7af  clang::ento::ExprEngine::ProcessStmt()
@ 0x5605d438a498  clang::ento::ExprEngine::processCFGElement()
@ 0x5605d437e7f5  clang::ento::CoreEngine::HandlePostStmt()
@ 0x5605d437dbec  clang::ento::CoreEngine::ExecuteWorkList()
@ 0x5605d40e7feb  (anonymous
namespace)::AnalysisConsumer::HandleCode()
@ 0x5605d40d1dc5  (anonymous
namespace)::AnalysisConsumer::HandleTranslationUnit()
@ 0x5605d46ea43c  clang::MultiplexConsumer::HandleTranslationUnit()
@ 0x5605d4854e54  clang::ParseAST()
@ 0x5605d46cb203  clang::FrontendAction::Execute()
@ 0x5605d4664451  clang::CompilerInstance::ExecuteAction()
@ 0x5605d45cef61
clang::tooling::FrontendActionFactory::runInvocation()
@ 0x5605d3d3e997
clang::tidy::runClangTidy()::ActionFactory::runInvocation()
@ 0x5605d45cecca  clang::tooling::ToolInvocation::runInvocation()
@ 0x5605d45ce646  clang::tooling::ToolInvocation::run()
@ 0x5605d45d0f22  clang::tooling::ClangTool::run()
@ 0x5605d3d39c5f  clang::tidy::runClangTidy()
@ 0x5605d0860c45  main

#2 is still being reduced.


On Wed, Mar 20, 2019 at 2:37 AM Artem Dergachev  wrote:

> On 3/19/19 11:10 AM, Richard Smith wrote:
> > It sounds like there might be a missing check for
> > InitListExpr::isTransparent somewhere. (A transparent InitListExpr
> > should be treated as equivalent to its one and only subexpression.)
> > Either that, or the static analyzer isn't aware that an object of
> > class type can be initialized directly from a function call, not via a
> > constructor.
>
> Indeed, thanks! And, as usual, more bugs on top of that.
> (https://reviews.llvm.org/D59573)
>
> On 3/19/19 11:00 AM, Alexander Kornienko wrote:
> > just adding -std=c++17 on existing code (LLVM, for example ;) could
> > help uncover some of the issues
>
> Hmm, fair enough :D I'm glad i asked :)
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D57112: [ASTTypeTraits][ASTMatchers][OpenMP] OMPClause handling

2019-03-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

@gribozavr thank you for the review!
@aaron.ballman any further comments?


Repository:
  rC Clang

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

https://reviews.llvm.org/D57112



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


[PATCH] D59453: [ASTMatchers][OpenMP] Add base ompExecutableDirective() matcher.

2019-03-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

@aaron.ballman @gribozavr thank you for the review!


Repository:
  rC Clang

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

https://reviews.llvm.org/D59453



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


[PATCH] D59463: [ASTMatchers][OpenMP] OpenMP Structured-block-related matchers

2019-03-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

@gribozavr thank you for the review!
@aaron.ballman any comments?


Repository:
  rC Clang

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

https://reviews.llvm.org/D59463



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


[PATCH] D59605: [clangd] Introduce background-indexer

2019-03-21 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 191684.
kadircet marked 11 inline comments as done.
kadircet added a comment.
Herald added a subscriber: jfb.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59605

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/background-indexer/BackgroundIndexer.cpp
  clang-tools-extra/clangd/background-indexer/CMakeLists.txt
  clang-tools-extra/clangd/index/Background.cpp
  clang-tools-extra/clangd/index/Background.h

Index: clang-tools-extra/clangd/index/Background.h
===
--- clang-tools-extra/clangd/index/Background.h
+++ clang-tools-extra/clangd/index/Background.h
@@ -144,6 +144,10 @@
   std::deque> Queue;
   std::vector ThreadPool; // FIXME: Abstract this away.
   GlobalCompilationDatabase::CommandChanged::Subscription CommandsChanged;
+
+  // For logging
+  std::atomic EnqueuedTUs{0};
+  std::atomic IndexedTUs{0};
 };
 
 } // namespace clangd
Index: clang-tools-extra/clangd/index/Background.cpp
===
--- clang-tools-extra/clangd/index/Background.cpp
+++ clang-tools-extra/clangd/index/Background.cpp
@@ -29,6 +29,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -215,6 +216,7 @@
 // We're doing this asynchronously, because we'll read shards here too.
 log("Enqueueing {0} commands for indexing", ChangedFiles.size());
 SPAN_ATTACH(Tracer, "files", int64_t(ChangedFiles.size()));
+EnqueuedTUs += ChangedFiles.size();
 
 auto NeedsReIndexing = loadShards(std::move(ChangedFiles));
 // Run indexing for files that need to be updated.
@@ -447,8 +449,9 @@
   assert(Index.Symbols && Index.Refs && Index.Sources &&
  "Symbols, Refs and Sources must be set.");
 
-  log("Indexed {0} ({1} symbols, {2} refs, {3} files)",
-  Inputs.CompileCommand.Filename, Index.Symbols->size(),
+  ++IndexedTUs;
+  log("[{0}/{1}] Indexed {2} ({3} symbols, {4} refs, {5} files)", IndexedTUs,
+  EnqueuedTUs, Inputs.CompileCommand.Filename, Index.Symbols->size(),
   Index.Refs->numRefs(), Index.Sources->size());
   SPAN_ATTACH(Tracer, "symbols", int(Index.Symbols->size()));
   SPAN_ATTACH(Tracer, "refs", int(Index.Refs->numRefs()));
@@ -581,12 +584,14 @@
   // Keeps track of the loaded shards to make sure we don't perform redundant
   // disk IO. Keys are absolute paths.
   llvm::StringSet<> LoadedShards;
+  size_t UpToDateTUs = 0;
   for (const auto &File : ChangedFiles) {
 ProjectInfo PI;
 auto Cmd = CDB.getCompileCommand(File, &PI);
 if (!Cmd)
   continue;
 BackgroundIndexStorage *IndexStorage = IndexStorageFactory(PI.SourceRoot);
+++UpToDateTUs;
 auto Dependencies = loadShard(*Cmd, IndexStorage, LoadedShards);
 for (const auto &Dependency : Dependencies) {
   if (!Dependency.NeedsReIndexing || FilesToIndex.count(Dependency.Path))
@@ -594,17 +599,19 @@
   // FIXME: Currently, we simply schedule indexing on a TU whenever any of
   // its dependencies needs re-indexing. We might do it smarter by figuring
   // out a minimal set of TUs that will cover all the stale dependencies.
-  vlog("Enqueueing TU {0} because its dependency {1} needs re-indexing.",
+  dlog("Enqueueing TU {0} because its dependency {1} needs re-indexing.",
Cmd->Filename, Dependency.Path);
   NeedsReIndexing.push_back({std::move(*Cmd), IndexStorage});
   // Mark all of this TU's dependencies as to-be-indexed so that we won't
   // try to re-index those.
   for (const auto &Dependency : Dependencies)
 FilesToIndex.insert(Dependency.Path);
+  --UpToDateTUs;
   break;
 }
   }
-  vlog("Loaded all shards");
+  IndexedTUs += UpToDateTUs;
+  log("[{0}/{1}] Loaded shards from storage", IndexedTUs, EnqueuedTUs);
   reset(IndexedSymbols.buildIndex(IndexType::Heavy, DuplicateHandling::Merge));
   vlog("BackgroundIndex: built symbol index with estimated memory {0} "
"bytes.",
Index: clang-tools-extra/clangd/background-indexer/CMakeLists.txt
===
--- /dev/null
+++ clang-tools-extra/clangd/background-indexer/CMakeLists.txt
@@ -0,0 +1,20 @@
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../)
+
+set(LLVM_LINK_COMPONENTS
+Support
+)
+
+add_clang_executable(clangd-background-indexer
+  BackgroundIndexer.cpp
+)
+
+target_link_libraries(clangd-background-indexer
+  PRIVATE
+  clangAST
+  clangIndex
+  clangDaemon
+  clangBasic
+  clangFrontend
+  clangLex
+  clangTooling
+)
Index: clang-tools-extra/clangd/background-indexer/BackgroundIndexer.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/background-indexer/BackgroundIndexer.cpp
@@ -0,0 +1,70 @@
+//===--- BackgroundIndexer.c

[PATCH] D57112: [ASTTypeTraits][ASTMatchers][OpenMP] OMPClause handling

2019-03-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: include/clang/ASTMatchers/ASTMatchers.h:6456
+  // Note that we have recieved a *matcher* for the clause, not the
+  // OpenMPClauseKind. We now need to extract the 'return' type of said 
matcher,
+  // and convert it to the OpenMPClauseKind, so we can finally use that.

lebedev.ri wrote:
> aaron.ballman wrote:
> > gribozavr wrote:
> > > lebedev.ri wrote:
> > > > gribozavr wrote:
> > > > > lebedev.ri wrote:
> > > > > > gribozavr wrote:
> > > > > > > lebedev.ri wrote:
> > > > > > > > gribozavr wrote:
> > > > > > > > > Why not make `isAllowedToContainClause` take an 
> > > > > > > > > `OpenMPClauseKind` enum value?
> > > > > > > > > 
> > > > > > > > > I don't see right now advantages for taking a matcher.  (For 
> > > > > > > > > example, it can't be a more complex matcher with inner 
> > > > > > > > > matchers, it can't be a disjunction of matchers etc.)
> > > > > > > > I don't feel like it, it's uglier.
> > > > > > > > The matcher is documented, `OpenMPClauseKind` is not documented.
> > > > > > > > Also, how will passing some random enum work with e.g. 
> > > > > > > > clang-query?
> > > > > > > > 
> > > > > > > There are dozens of clauses in `OpenMPClauseKind`.  We would have 
> > > > > > > to replicate them all as matchers to provide a useful API.
> > > > > > > 
> > > > > > > > Also, how will passing some random enum work with e.g. 
> > > > > > > > clang-query?
> > > > > > > 
> > > > > > > See `llvm/tools/clang/lib/ASTMatchers/Dynamic/Marshallers.h`.
> > > > > > True. Also, but there's dosens of Stmt types, and there is no 
> > > > > > overload that takes `StmtClass` enum.
> > > > > For Stmts, we do have dozens of individual matchers for them.
> > > > > 
> > > > > The point of your work is to add ASTMatchers for OpenMP, right?  
> > > > > However, if there are no matchers for a reasonable amount of AST 
> > > > > surface, it is as good as if the matchers are not there, because 
> > > > > prospective users won't be able to use them.
> > > > > 
> > > > > I don't particularly care how exactly this is achieved, through 
> > > > > individual matchers or through a matcher that takes an enum.  
> > > > > However, I want to make sure that if you're going through all this 
> > > > > trouble to add matchers, the resulting API should cover a good amount 
> > > > > of AST.
> > > > > 
> > > > > The reason why I suggested to pass the enum to the matcher is simply 
> > > > > because it is less code duplication, less work, and more reliable 
> > > > > code (since there will be only one matcher to review, test, and 
> > > > > maintain, instead of combinations of matchers).
> > > > > 
> > > > > Another reason to not use an inner matcher here is the peculiar 
> > > > > semantics of this function -- it does not evaluate the matcher, and 
> > > > > it does not accept a matcher expression of any shape.
> > > > > The point of your work is to add ASTMatchers for OpenMP, right?
> > > > 
> > > > Absolutely not.
> > > > D57113 + D59466 is the one and only point, to address the bugs i have 
> > > > personally encountered.
> > > > The whole reason why i have started off with NOT adding these matchers 
> > > > to the `ASTMatchers.h`,
> > > > but keeping them at least initially internal to the checks was to avoid 
> > > > all this bikeshedding.
> > > However, I do care about the AST matchers being usable by other clients.
> > > 
> > > I also care about the API following existing patterns:
> > > 
> > > > Another reason to not use an inner matcher here is the peculiar 
> > > > semantics of this function -- it does not evaluate the matcher, and it 
> > > > does not accept a matcher expression of any shape.
> > > 
> > > 
> > >> Also, how will passing some random enum work with e.g. clang-query?
> > > See llvm/tools/clang/lib/ASTMatchers/Dynamic/Marshallers.h.
> > 
> > That doesn't mean it works super well, though. String literals more easily 
> > contain silent typos, don't have autocomplete support, etc. I can 
> > definitely sympathize with not wanting to use an enum here.
> > 
> > However, I see that there are 50+ enumerations in this list -- that seems 
> > like too many matchers to want to expose. I think an enum will be the 
> > better, more maintainable option. The current approach won't scale well.
> Okay, but apparently clang-query will needs to be fixed too:
> ```
> clang-query> match 
> stmt(ompExecutableDirective(isAllowedToContainClause(OMPC_default)))
> 1:1: Error parsing argument 1 for matcher stmt.
> 1:6: Error parsing argument 1 for matcher ompExecutableDirective.
> 1:29: Error parsing argument 1 for matcher isAllowedToContainClause.
> 1:58: Error parsing matcher. Found token <_> while looking for '('.
> 
> ```
> https://bugs.llvm.org/show_bug.cgi?id=41176
clang-query requires enumerations to be quoted string literals. If you switch 
to that in your test, does it work for you? I was spotting some odd behavior 
with a different matcher (the

[PATCH] D59605: [clangd] Introduce background-indexer

2019-03-21 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/background-indexer/BackgroundIndexer.cpp:13
+
+#include 
"/usr/local/google/home/kadircet/repos/llvm/clang-tools-extra/clangd/Context.h"
+#include 
"/usr/local/google/home/kadircet/repos/llvm/clang-tools-extra/clangd/Logger.h"

ilya-biryukov wrote:
> Eugene.Zelenko wrote:
> > Please use relative path. Same below.
> Heh, where do these come from?
> Does our include insertion prefer to add global paths in some cases? Dynamic 
> index?
ah interesting, my guess is static index without any "-I" flags to direct path 
shortening.



Comment at: clang-tools-extra/clangd/background-indexer/BackgroundIndexer.cpp:56
+  // non-interactive tools like this one.
+  24 * 60 * 60 * 1000);
+  llvm::SmallString<128> DummyFile(CompileCommandsDir);

jkorous wrote:
> Nit: maybe we should give this constant a name? Or maybe create a command 
> line option for this?
It is the period for building index data structures which helps making queries 
fast, as I mentioned in the comment we definitely don't need this to happen 
until we've indexed every file, and BackgroundIndex should in my opinion work 
in this mode if period was set to zero. So I don't see any point in giving it a 
name.

Btw, the reason we want to build index data structures in the end is to just 
see how long it takes.



Comment at: clang-tools-extra/clangd/index/Background.cpp:29
 #include "llvm/Support/SHA1.h"
 
 #include 

Eugene.Zelenko wrote:
> Unnecessary empty line.
not introduced by this change



Comment at: clang-tools-extra/clangd/index/Background.cpp:605
 continue;
+  --UpToDateTUs;
   // FIXME: Currently, we simply schedule indexing on a TU whenever any of

jkorous wrote:
> It's not obvious to me that we don't underflow here given we are using 
> `size_t`. Maybe add an `assert` or some other sanity check?
that line is executed at most once per each increment above, if you follow the 
flow you can see the break below, but good point moving it next to break to 
better illustrate that.



Comment at: clang-tools-extra/clangd/index/Background.cpp:622
+IndexedTUs += UpToDateTUs;
+log("[{0}/{1}] Loaded shards from storage", IndexedTUs, EnqueuedTUs);
+  }

ilya-biryukov wrote:
> Everything else is `vlog` (or even `dlog`), what's the rationale of using 
> `log` here?
It was to print output mentioned in the summary. What would you rather suggest? 
Other possibilities I had in mind:
- Poll from client for current status
- Pass an option to background index to dump these logs conditionally


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59605



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


[PATCH] D59567: [X86] Add __popcntd and __popcntq to ia32intrin.h to match gcc and icc. Remove popcnt feature flag from _popcnt32/_popcnt64 and move to ia32intrin.h to match gcc

2019-03-21 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon accepted this revision.
RKSimon added a comment.
This revision is now accepted and ready to land.

LGTM with some minor typos




Comment at: lib/Headers/ia32intrin.h:36
+ *  This intrinsic corresponds to the  POPCNT  instruction or a
+ *  a sequence of arithmetic and logic ops to calcute it.
+ *

calculate



Comment at: lib/Headers/ia32intrin.h:57
+ *  This intrinsic corresponds to the  POPCNT  instruction or a
+ *  a sequence of arithmetic and logic ops to calcute it.
+ *

calculate


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

https://reviews.llvm.org/D59567



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


[PATCH] D57112: [ASTTypeTraits][ASTMatchers][OpenMP] OMPClause handling

2019-03-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 191685.
lebedev.ri marked an inline comment as done.
lebedev.ri added a comment.

Address @aaron.ballman comment nit.


Repository:
  rC Clang

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

https://reviews.llvm.org/D57112

Files:
  docs/LibASTMatchersReference.html
  include/clang/AST/ASTTypeTraits.h
  include/clang/ASTMatchers/ASTMatchers.h
  lib/AST/ASTTypeTraits.cpp
  lib/ASTMatchers/ASTMatchersInternal.cpp
  lib/ASTMatchers/Dynamic/Marshallers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1789,5 +1789,43 @@
   EXPECT_TRUE(notMatchesWithOpenMP(Source2, Matcher));
 }
 
+TEST(OMPDefaultClause, Matches) {
+  auto Matcher = ompExecutableDirective(hasAnyClause(ompDefaultClause()));
+
+  const std::string Source0 = R"(
+void x() {
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source1, Matcher));
+
+  const std::string Source2 = R"(
+void x() {
+#pragma omp parallel default(none)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source2, Matcher));
+
+  const std::string Source3 = R"(
+void x() {
+#pragma omp parallel default(shared)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source3, Matcher));
+
+  const std::string Source4 = R"(
+void x(int x) {
+#pragma omp parallel num_threads(x)
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source4, Matcher));
+}
+
 } // namespace ast_matchers
 } // namespace clang
Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2274,5 +2274,173 @@
 notMatches("int main2() {}", functionDecl(isMain(;
 }
 
+TEST(OMPExecutableDirective, hasClause) {
+  auto Matcher = ompExecutableDirective(hasAnyClause(anything()));
+
+  const std::string Source0 = R"(
+void x() {
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source1, Matcher));
+
+  const std::string Source2 = R"(
+void x() {
+#pragma omp parallel default(none)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source2, Matcher));
+
+  const std::string Source3 = R"(
+void x() {
+#pragma omp parallel default(shared)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source3, Matcher));
+
+  const std::string Source4 = R"(
+void x(int x) {
+#pragma omp parallel num_threads(x)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source4, Matcher));
+}
+
+TEST(OMPDefaultClause, isNoneKind) {
+  auto Matcher =
+  ompExecutableDirective(hasAnyClause(ompDefaultClause(isNoneKind(;
+
+  const std::string Source0 = R"(
+void x() {
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source1, Matcher));
+
+  const std::string Source2 = R"(
+void x() {
+#pragma omp parallel default(none)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source2, Matcher));
+
+  const std::string Source3 = R"(
+void x() {
+#pragma omp parallel default(shared)
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source3, Matcher));
+
+  const std::string Source4 = R"(
+void x(int x) {
+#pragma omp parallel num_threads(x)
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source4, Matcher));
+}
+
+TEST(OMPDefaultClause, isSharedKind) {
+  auto Matcher =
+  ompExecutableDirective(hasAnyClause(ompDefaultClause(isSharedKind(;
+
+  const std::string Source0 = R"(
+void x() {
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source1, Matcher));
+
+  const std::string Source2 = R"(
+void x() {
+#pragma omp parallel default(shared)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source2, Matcher));
+
+  const std::string Source3 = R"(
+void x() {
+#pragma omp parallel default(none)
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source3, Matcher));
+
+  const std::string Source4 = R"(
+void x(int x) {
+#pragma omp parallel num_threads(x)
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source4, Matcher));
+}
+
+TEST(OMPExecutableDirective, isAllowedToContainClauseKind) {
+  auto Matcher =
+  ompExecutableDirective(isAllowedToContainClauseKind(OMPC_default));
+
+  const std::string Source0 = R"(
+void x() {
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp parallel

[PATCH] D57112: [ASTTypeTraits][ASTMatchers][OpenMP] OMPClause handling

2019-03-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM aside from a small docs nit (be sure to regenerate the docs after you fix 
it).




Comment at: include/clang/ASTMatchers/ASTMatchers.h:6402
+///
+/// ``ompExecutableDirective(hasClause(anything()))`` matches
+/// ``omp parallel default(none)``.

hasAnyClause()


Repository:
  rC Clang

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

https://reviews.llvm.org/D57112



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


[PATCH] D59463: [ASTMatchers][OpenMP] OpenMP Structured-block-related matchers

2019-03-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM aside from a NFC change




Comment at: include/clang/ASTMatchers/ASTMatchers.h:6444-6445
+  internal::Matcher, InnerMatcher) {
+  if (isStandaloneDirective().matches(Node, Finder, Builder))
+return false; // Standalone directives have no structured blocks.
+  return InnerMatcher.matches(*Node.getStructuredBlock(), Finder, Builder);

Rather than call the matcher (which is a heavy-handed solution), I'd prefer to 
just check `Node.isOMPStructuredBlock()` directly.


Repository:
  rC Clang

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

https://reviews.llvm.org/D59463



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


[PATCH] D57112: [ASTTypeTraits][ASTMatchers][OpenMP] OMPClause handling

2019-03-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 191697.
lebedev.ri marked 2 inline comments as done.
lebedev.ri added a comment.

Comment nit.


Repository:
  rC Clang

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

https://reviews.llvm.org/D57112

Files:
  docs/LibASTMatchersReference.html
  include/clang/AST/ASTTypeTraits.h
  include/clang/ASTMatchers/ASTMatchers.h
  lib/AST/ASTTypeTraits.cpp
  lib/ASTMatchers/ASTMatchersInternal.cpp
  lib/ASTMatchers/Dynamic/Marshallers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1789,5 +1789,43 @@
   EXPECT_TRUE(notMatchesWithOpenMP(Source2, Matcher));
 }
 
+TEST(OMPDefaultClause, Matches) {
+  auto Matcher = ompExecutableDirective(hasAnyClause(ompDefaultClause()));
+
+  const std::string Source0 = R"(
+void x() {
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source1, Matcher));
+
+  const std::string Source2 = R"(
+void x() {
+#pragma omp parallel default(none)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source2, Matcher));
+
+  const std::string Source3 = R"(
+void x() {
+#pragma omp parallel default(shared)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source3, Matcher));
+
+  const std::string Source4 = R"(
+void x(int x) {
+#pragma omp parallel num_threads(x)
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source4, Matcher));
+}
+
 } // namespace ast_matchers
 } // namespace clang
Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2274,5 +2274,173 @@
 notMatches("int main2() {}", functionDecl(isMain(;
 }
 
+TEST(OMPExecutableDirective, hasClause) {
+  auto Matcher = ompExecutableDirective(hasAnyClause(anything()));
+
+  const std::string Source0 = R"(
+void x() {
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source1, Matcher));
+
+  const std::string Source2 = R"(
+void x() {
+#pragma omp parallel default(none)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source2, Matcher));
+
+  const std::string Source3 = R"(
+void x() {
+#pragma omp parallel default(shared)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source3, Matcher));
+
+  const std::string Source4 = R"(
+void x(int x) {
+#pragma omp parallel num_threads(x)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source4, Matcher));
+}
+
+TEST(OMPDefaultClause, isNoneKind) {
+  auto Matcher =
+  ompExecutableDirective(hasAnyClause(ompDefaultClause(isNoneKind(;
+
+  const std::string Source0 = R"(
+void x() {
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source1, Matcher));
+
+  const std::string Source2 = R"(
+void x() {
+#pragma omp parallel default(none)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source2, Matcher));
+
+  const std::string Source3 = R"(
+void x() {
+#pragma omp parallel default(shared)
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source3, Matcher));
+
+  const std::string Source4 = R"(
+void x(int x) {
+#pragma omp parallel num_threads(x)
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source4, Matcher));
+}
+
+TEST(OMPDefaultClause, isSharedKind) {
+  auto Matcher =
+  ompExecutableDirective(hasAnyClause(ompDefaultClause(isSharedKind(;
+
+  const std::string Source0 = R"(
+void x() {
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source1, Matcher));
+
+  const std::string Source2 = R"(
+void x() {
+#pragma omp parallel default(shared)
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source2, Matcher));
+
+  const std::string Source3 = R"(
+void x() {
+#pragma omp parallel default(none)
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source3, Matcher));
+
+  const std::string Source4 = R"(
+void x(int x) {
+#pragma omp parallel num_threads(x)
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source4, Matcher));
+}
+
+TEST(OMPExecutableDirective, isAllowedToContainClauseKind) {
+  auto Matcher =
+  ompExecutableDirective(isAllowedToContainClauseKind(OMPC_default));
+
+  const std::string Source0 = R"(
+void x() {
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+  EXPECT_TRU

[PATCH] D57112: [ASTTypeTraits][ASTMatchers][OpenMP] OMPClause handling

2019-03-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: include/clang/ASTMatchers/ASTMatchers.h:6402
+///
+/// ``ompExecutableDirective(hasClause(anything()))`` matches
+/// ``omp parallel default(none)``.

aaron.ballman wrote:
> hasAnyClause()
whoops, thanks.


Repository:
  rC Clang

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

https://reviews.llvm.org/D57112



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


[PATCH] D57112: [ASTTypeTraits][ASTMatchers][OpenMP] OMPClause handling

2019-03-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D57112#1437954 , @aaron.ballman 
wrote:

> LGTM


Great, thank you for the review!


Repository:
  rC Clang

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

https://reviews.llvm.org/D57112



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


[PATCH] D59463: [ASTMatchers][OpenMP] OpenMP Structured-block-related matchers

2019-03-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: include/clang/ASTMatchers/ASTMatchers.h:6444-6445
+  internal::Matcher, InnerMatcher) {
+  if (isStandaloneDirective().matches(Node, Finder, Builder))
+return false; // Standalone directives have no structured blocks.
+  return InnerMatcher.matches(*Node.getStructuredBlock(), Finder, Builder);

aaron.ballman wrote:
> Rather than call the matcher (which is a heavy-handed solution), I'd prefer 
> to just check `Node.isOMPStructuredBlock()` directly.
Hmm, k.


Repository:
  rC Clang

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

https://reviews.llvm.org/D59463



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


[PATCH] D59463: [ASTMatchers][OpenMP] OpenMP Structured-block-related matchers

2019-03-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 191701.
lebedev.ri marked 2 inline comments as done.
lebedev.ri added a comment.

Last nit.


Repository:
  rC Clang

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

https://reviews.llvm.org/D59463

Files:
  docs/LibASTMatchersReference.html
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -2274,6 +2274,71 @@
 notMatches("int main2() {}", functionDecl(isMain(;
 }
 
+TEST(OMPExecutableDirective, isStandaloneDirective) {
+  auto Matcher = ompExecutableDirective(isStandaloneDirective());
+
+  const std::string Source0 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source0, Matcher));
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp taskyield
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source1, Matcher));
+}
+
+TEST(Stmt, isOMPStructuredBlock) {
+  const std::string Source0 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+  EXPECT_TRUE(
+  matchesWithOpenMP(Source0, stmt(nullStmt(), isOMPStructuredBlock(;
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp parallel
+{;}
+})";
+  EXPECT_TRUE(
+  notMatchesWithOpenMP(Source1, stmt(nullStmt(), isOMPStructuredBlock(;
+  EXPECT_TRUE(
+  matchesWithOpenMP(Source1, stmt(compoundStmt(), isOMPStructuredBlock(;
+}
+
+TEST(OMPExecutableDirective, hasStructuredBlock) {
+  const std::string Source0 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(
+  Source0, ompExecutableDirective(hasStructuredBlock(nullStmt();
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp parallel
+{;}
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(
+  Source1, ompExecutableDirective(hasStructuredBlock(nullStmt();
+  EXPECT_TRUE(matchesWithOpenMP(
+  Source1, ompExecutableDirective(hasStructuredBlock(compoundStmt();
+
+  const std::string Source2 = R"(
+void x() {
+#pragma omp taskyield
+{;}
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(
+  Source2, ompExecutableDirective(hasStructuredBlock(anything();
+}
+
 TEST(OMPExecutableDirective, hasClause) {
   auto Matcher = ompExecutableDirective(hasAnyClause(anything()));
 
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -304,6 +304,7 @@
   REGISTER_MATCHER(hasSourceExpression);
   REGISTER_MATCHER(hasSpecializedTemplate);
   REGISTER_MATCHER(hasStaticStorageDuration);
+  REGISTER_MATCHER(hasStructuredBlock);
   REGISTER_MATCHER(hasSyntacticForm);
   REGISTER_MATCHER(hasTargetDecl);
   REGISTER_MATCHER(hasTemplateArgument);
@@ -379,6 +380,7 @@
   REGISTER_MATCHER(isNoReturn);
   REGISTER_MATCHER(isNoThrow);
   REGISTER_MATCHER(isNoneKind);
+  REGISTER_MATCHER(isOMPStructuredBlock);
   REGISTER_MATCHER(isOverride);
   REGISTER_MATCHER(isPrivate);
   REGISTER_MATCHER(isProtected);
@@ -387,6 +389,7 @@
   REGISTER_MATCHER(isScoped);
   REGISTER_MATCHER(isSharedKind);
   REGISTER_MATCHER(isSignedInteger);
+  REGISTER_MATCHER(isStandaloneDirective);
   REGISTER_MATCHER(isStaticLocal);
   REGISTER_MATCHER(isStaticStorageClass);
   REGISTER_MATCHER(isStruct);
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -6390,6 +6390,58 @@
 extern const internal::VariadicDynCastAllOfMatcher
 ompExecutableDirective;
 
+/// Matches standalone OpenMP directives,
+/// i.e., directives that can't have a structured block.
+///
+/// Given
+///
+/// \code
+///   #pragma omp parallel
+///   {}
+///   #pragma omp taskyield
+/// \endcode
+///
+/// ``ompExecutableDirective(isStandaloneDirective()))`` matches
+/// ``omp taskyield``.
+AST_MATCHER(OMPExecutableDirective, isStandaloneDirective) {
+  return Node.isStandaloneDirective();
+}
+
+/// Matches the Stmt AST node that is marked as being the structured-block
+/// of an OpenMP executable directive.
+///
+/// Given
+///
+/// \code
+///#pragma omp parallel
+///{}
+/// \endcode
+///
+/// ``stmt(isOMPStructuredBlock()))`` matches ``{}``.
+AST_MATCHER(Stmt, isOMPStructuredBlock) { return Node.isOMPStructuredBlock(); }
+
+/// Matches the structured-block of the OpenMP executable directive
+///
+/// Prerequisite: the executable directive must not be standalone directive.
+/// If it is, it will never match.
+///
+/// Given
+///
+/// \code
+///#pragma omp parallel
+///;
+///#pragma omp parallel
+///{}
+/// \endcode
+///
+/// ``ompExecutableDirective(hasStructuredBlock(nullStmt()))`` will

[PATCH] D59646: [PR40778][PR41157][OpenCL] Prevent implicit initialization of local address space objects

2019-03-21 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia created this revision.
Anastasia added reviewers: rjmccall, bader.
Herald added a subscriber: ebevhan.
Anastasia retitled this revision from "[PR40778][PR41157] Prevent implicit 
initialization of local address space objects" to "[PR40778][PR41157][OpenCL] 
Prevent implicit initialization of local address space objects".
Herald added a subscriber: yaxunl.

In OpenCL C variables in local address space can't be initialized (s6.5.2). 
However in C++ default initialization can be performed even then there is no 
initializer explicitly provided. This won't work for local address space 
objects because they are not the same as regular global or local variables.

Current solution is to disable implicit default initialization. We still need 
some work to be done on user defined initialization and also construction of 
objects in local address space.


https://reviews.llvm.org/D59646

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


Index: test/CodeGenOpenCLCXX/local_addrspace_init.cl
===
--- /dev/null
+++ test/CodeGenOpenCLCXX/local_addrspace_init.cl
@@ -0,0 +1,19 @@
+// 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
+class C {
+  int i;
+};
+
+kernel void test() {
+  __local int i;
+  __local C ii;
+  //FIXME: In OpenCL C we don't accept initializers for local address space 
variables.
+  //User defined initialization could make sense, but would it mean that all 
work
+  //items need to execute it? Potentially disallowing any initialization would 
make
+  //things easier and assingments can be used to set specific values. This 
rules should
+  // make it consistent with OpenCL C.
+  //__local C c();
+}
Index: test/CodeGenOpenCLCXX/addrspace-of-this.cl
===
--- test/CodeGenOpenCLCXX/addrspace-of-this.cl
+++ test/CodeGenOpenCLCXX/addrspace-of-this.cl
@@ -150,15 +150,13 @@
 TEST(__local)
 
 // COMMON-LABEL: _Z11test__localv
-// EXPL: @__cxa_guard_acquire
 
-// Test the address space of 'this' when invoking a constructor for an object 
in non-default address space
-// EXPL: call void @_ZNU3AS41CC1Ev(%class.C addrspace(4)* addrspacecast 
(%class.C addrspace(3)* @_ZZ11test__localvE1c to %class.C addrspace(4)*))
+// Test that we don't initialize an onbject 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)*))
 
 // 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)*))
 
-
 // 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)*))
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -11645,7 +11645,10 @@
   setFunctionHasBranchProtectedScope();
   }
 }
-
+// In OpenCL we don't allow to initialize objects in local address space.
+if (getLangOpts().OpenCL &&
+Var->getType().getAddressSpace() == LangAS::opencl_local)
+  return;
 // C++03 [dcl.init]p9:
 //   If no initializer is specified for an object, and the
 //   object is of (possibly cv-qualified) non-POD class type (or


Index: test/CodeGenOpenCLCXX/local_addrspace_init.cl
===
--- /dev/null
+++ test/CodeGenOpenCLCXX/local_addrspace_init.cl
@@ -0,0 +1,19 @@
+// 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
+class C {
+  int i;
+};
+
+kernel void test() {
+  __local int i;
+  __local C ii;
+  //FIXME: In OpenCL C we don't accept initializers for local address space variables.
+  //User defined initialization could make sense, but would it mean that all work
+  //items need to execute it? Potentially disallowing any initialization would make
+  //things easier and assingments can be used to set specific values. This rules should
+  // make it consistent with OpenCL C.
+  //__local C c();
+}
Index: test/CodeGenOpenCL

[PATCH] D59528: [clang-tidy] Expand modular headers for PPCallbacks

2019-03-21 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp:24
+  void recordContent(const FileEntry *File,
+ const SrcMgr::ContentCache *ContentCache,
+ llvm::vfs::InMemoryFileSystem &InMemoryFs) {

gribozavr wrote:
> `const &` for `File` and `ContentCache` ?
Done for `ContentCache`. The `File` is stored into a `DenseSet`, thus a pointer 
makes sense here.



Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp:171
+// Just parse to the corresponding location to generate the same callback for
+// the target_callbacks_.
+void ExpandModularHeadersPPCallbacks::Ident(SourceLocation Loc, StringRef) {

gribozavr wrote:
> What's `target_callbacks_`?  It is only mentioned in comments.
It's an artifact of an older version. Removed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59528



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


[PATCH] D59528: [clang-tidy] Expand modular headers for PPCallbacks

2019-03-21 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh updated this revision to Diff 191703.
alexfh marked 15 inline comments as done.
alexfh added a comment.

- Addressed review comments. Parse code to the end (seems right to do this, but 
no specific test that would fail otherwise).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59528

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clang-tidy/ClangTidy.h
  clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
  clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
  clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/test/CMakeLists.txt
  
clang-tools-extra/test/clang-tidy/Inputs/expand-modular-headers-ppcallbacks/a.h
  
clang-tools-extra/test/clang-tidy/Inputs/expand-modular-headers-ppcallbacks/b.h
  
clang-tools-extra/test/clang-tidy/Inputs/expand-modular-headers-ppcallbacks/c.h
  
clang-tools-extra/test/clang-tidy/Inputs/expand-modular-headers-ppcallbacks/module.modulemap
  clang-tools-extra/test/clang-tidy/expand-modular-headers-ppcallbacks.cpp

Index: clang-tools-extra/test/clang-tidy/expand-modular-headers-ppcallbacks.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/expand-modular-headers-ppcallbacks.cpp
@@ -0,0 +1,35 @@
+// Sanity-check. Run without modules:
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: cp %S/Inputs/expand-modular-headers-ppcallbacks/* %t/
+// RUN: %check_clang_tidy %s readability-identifier-naming %t/without-modules -- \
+// RUN:   -config="CheckOptions: [{ \
+// RUN:  key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE }]" \
+// RUN:   -header-filter=.* \
+// RUN:   -- -x c++ -std=c++11 -I%t/
+//
+// Run clang-tidy on a file with modular includes:
+//
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: cp %S/Inputs/expand-modular-headers-ppcallbacks/* %t/
+// RUN: %check_clang_tidy %s readability-identifier-naming %t/with-modules -- \
+// RUN:   -config="CheckOptions: [{ \
+// RUN:  key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE }]" \
+// RUN:   -header-filter=.* \
+// RUN:   -- -x c++ -std=c++11 -I%t/ \
+// RUN:   -fmodules -fimplicit-modules -fno-implicit-module-maps \
+// RUN:   -fmodule-map-file=%t/module.modulemap \
+// RUN:   -fmodules-cache-path=%t/module-cache/
+#include "c.h"
+
+// CHECK-MESSAGES: a.h:1:9: warning: invalid case style for macro definition 'a' [readability-identifier-naming]
+// CHECK-MESSAGES: a.h:1:9: note: FIX-IT applied suggested code changes
+// CHECK-MESSAGES: b.h:2:9: warning: invalid case style for macro definition 'b'
+// CHECK-MESSAGES: b.h:2:9: note: FIX-IT applied suggested code changes
+// CHECK-MESSAGES: c.h:2:9: warning: invalid case style for macro definition 'c'
+// CHECK-MESSAGES: c.h:2:9: note: FIX-IT applied suggested code changes
+
+#define m
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: invalid case style for macro definition 'm'
+// CHECK-MESSAGES: :[[@LINE-2]]:9: note: FIX-IT applied suggested code changes
Index: clang-tools-extra/test/clang-tidy/Inputs/expand-modular-headers-ppcallbacks/module.modulemap
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/Inputs/expand-modular-headers-ppcallbacks/module.modulemap
@@ -0,0 +1,3 @@
+module a { header "a.h" export * }
+module b { header "b.h" export * use a }
+module c { header "c.h" export * use b }
Index: clang-tools-extra/test/clang-tidy/Inputs/expand-modular-headers-ppcallbacks/c.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/Inputs/expand-modular-headers-ppcallbacks/c.h
@@ -0,0 +1,2 @@
+#include "b.h"
+#define c
Index: clang-tools-extra/test/clang-tidy/Inputs/expand-modular-headers-ppcallbacks/b.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/Inputs/expand-modular-headers-ppcallbacks/b.h
@@ -0,0 +1,2 @@
+#include "a.h"
+#define b
Index: clang-tools-extra/test/clang-tidy/Inputs/expand-modular-headers-ppcallbacks/a.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/Inputs/expand-modular-headers-ppcallbacks/a.h
@@ -0,0 +1 @@
+#define a
Index: clang-tools-extra/test/CMakeLists.txt
===
--- clang-tools-extra/test/CMakeLists.txt
+++ clang-tools-extra/test/CMakeLists.txt
@@ -62,6 +62,8 @@
   clang-resource-headers
 
   clang-tidy
+  # Clang-tidy tests need clang for building modules.
+  clang
 )
 
 if(CLANGD_BUILD_XPC_SUPPORT)
Index: clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
==

[PATCH] D59528: [clang-tidy] Expand modular headers for PPCallbacks

2019-03-21 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

Thank you for the review! I hope I covered all the points.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59528



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


r356674 - [ASTMatchers][OpenMP] Add base ompExecutableDirective() matcher.

2019-03-21 Thread Roman Lebedev via cfe-commits
Author: lebedevri
Date: Thu Mar 21 08:33:10 2019
New Revision: 356674

URL: http://llvm.org/viewvc/llvm-project?rev=356674&view=rev
Log:
[ASTMatchers][OpenMP] Add base ompExecutableDirective() matcher.

Summary:
A simple matcher for `OMPExecutableDirective` Stmt type.
Split off from D57113.

Reviewers: gribozavr, aaron.ballman, JonasToth, george.karpenkov

Reviewed By: gribozavr, aaron.ballman

Subscribers: guansong, jdoerfert, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/AST/OMPStructuredBlockTest.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=356674&r1=356673&r2=356674&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Thu Mar 21 08:33:10 2019
@@ -1375,6 +1375,20 @@ Example matches @try
 
 
 
+MatcherStmt>ompExecutableDirectiveMatcherOMPExecutableDirective>...
+Matches any 
``#pragma omp`` executable directive.
+
+Given
+
+  #pragma omp parallel
+  #pragma omp parallel default(none)
+  #pragma omp taskyield
+
+``ompExecutableDirective()`` matches ``omp parallel``,
+``omp parallel default(none)`` and ``omp taskyield``.
+
+
+
 MatcherStmt>opaqueValueExprMatcherOpaqueValueExpr>...
 Matches opaque 
value expressions. They are used as helpers
 to reference another expressions and can be met

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=356674&r1=356673&r2=356674&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Thu Mar 21 08:33:10 2019
@@ -60,6 +60,7 @@
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
+#include "clang/AST/StmtOpenMP.h"
 #include "clang/AST/TemplateBase.h"
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
@@ -6369,6 +6370,29 @@ AST_MATCHER(FunctionDecl, hasTrailingRet
   return false;
 }
 
+////
+// OpenMP handling.
+////
+
+/// Matches any ``#pragma omp`` executable directive.
+///
+/// Given
+///
+/// \code
+///   #pragma omp parallel
+///   #pragma omp parallel default(none)
+///   #pragma omp taskyield
+/// \endcode
+///
+/// ``ompExecutableDirective()`` matches ``omp parallel``,
+/// ``omp parallel default(none)`` and ``omp taskyield``.
+extern const internal::VariadicDynCastAllOfMatcher
+ompExecutableDirective;
+
+////
+// End OpenMP handling.
+////
+
 } // namespace ast_matchers
 } // namespace clang
 

Modified: cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp?rev=356674&r1=356673&r2=356674&view=diff
==
--- cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp Thu Mar 21 08:33:10 2019
@@ -845,5 +845,8 @@ AST_TYPELOC_TRAVERSE_MATCHER_DEF(
 AST_POLYMORPHIC_SUPPORTED_TYPES(BlockPointerType, MemberPointerType,
 PointerType, ReferenceType));
 
+const internal::VariadicDynCastAllOfMatcher
+ompExecutableDirective;
+
 } // end namespace ast_matchers
 } // end namespace clang

Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=356674&r1=356673&r2=356674&view=diff
==
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Thu Mar 21 08:33:10 2019
@@ -434,6 +434,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(objcThrowStmt);
   REGISTER_MATCHER(objcTryStmt);
   REGISTER_MATCHER(ofCla

r356675 - [ASTTypeTraits][ASTMatchers][OpenMP] OMPClause handling

2019-03-21 Thread Roman Lebedev via cfe-commits
Author: lebedevri
Date: Thu Mar 21 08:33:24 2019
New Revision: 356675

URL: http://llvm.org/viewvc/llvm-project?rev=356675&view=rev
Log:
[ASTTypeTraits][ASTMatchers][OpenMP] OMPClause handling

Summary:
`OMPClause` is the base class, it is not descendant from **any**
other class, therefore for it to work with e.g.
`VariadicDynCastAllOfMatcher<>`, it needs to be handled here.

Reviewers: sbenza, bkramer, pcc, klimek, hokein, gribozavr, aaron.ballman, 
george.karpenkov

Reviewed By: gribozavr, aaron.ballman

Subscribers: guansong, jdoerfert, alexfh, ABataev, cfe-commits

Tags: #openmp, #clang

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

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/AST/ASTTypeTraits.h
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/AST/ASTTypeTraits.cpp
cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=356675&r1=356674&r2=356675&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Thu Mar 21 08:33:24 2019
@@ -645,6 +645,19 @@ nestedNameSpecifier()
 
 
 
+MatcherOMPClause>ompDefaultClauseMatcherOMPDefaultClause>...
+Matches OpenMP 
``default`` clause.
+
+Given
+
+  #pragma omp parallel default(none)
+  #pragma omp parallel default(shared)
+  #pragma omp parallel
+
+``ompDefaultClause()`` matches ``default(none)`` and ``default(shared)``.
+
+
+
 MatcherQualType>qualTypeMatcherQualType>...
 Matches QualTypes in the 
clang AST.
 
@@ -3439,6 +3452,51 @@ namespaceDecl(isInline()) will match n::
 
 
 
+MatcherOMPDefaultClause>isNoneKind
+Matches if the OpenMP 
``default`` clause has ``none`` kind specified.
+
+Given
+
+  #pragma omp parallel
+  #pragma omp parallel default(none)
+  #pragma omp parallel default(shared)
+
+``ompDefaultClause(isNoneKind())`` matches only ``default(none)``.
+
+
+
+MatcherOMPDefaultClause>isSharedKind
+Matches if the OpenMP 
``default`` clause has ``shared`` kind specified.
+
+Given
+
+  #pragma omp parallel
+  #pragma omp parallel default(none)
+  #pragma omp parallel default(shared)
+
+``ompDefaultClause(isSharedKind())`` matches only ``default(shared)``.
+
+
+
+MatcherOMPExecutableDirective>isAllowedToContainClauseKindOpenMPClauseKind
 CKind
+Matches if the OpenMP directive is 
allowed to contain the specified OpenMP
+clause kind.
+
+Given
+
+  #pragma omp parallel
+  #pragma omp parallel for
+  #pragma omp  for
+
+`ompExecutableDirective(isAllowedToContainClause(OMPC_default))`` matches
+``omp parallel`` and ``omp parallel for``.
+
+If the matcher is use from clang-query, ``OpenMPClauseKind`` parameter
+should be passed as a quoted string. e.g.,
+``isAllowedToContainClauseKind("OMPC_default").``
+
+
+
 MatcherObjCMessageExpr>argumentCountIsunsigned N
 Checks that a call 
expression or a constructor call expression has
 a specific number of arguments (including absent default arguments).
@@ -6163,6 +6221,19 @@ nestedNameSpecifier(specifiesType(
 
 
 
+MatcherOMPExecutableDirective>hasAnyClauseMatcherOMPClause>
 InnerMatcher
+Matches any clause in 
an OpenMP directive.
+
+Given
+
+  #pragma omp parallel
+  #pragma omp parallel default(none)
+
+``ompExecutableDirective(hasAnyClause(anything()))`` matches
+``omp parallel default(none)``.
+
+
+
 MatcherObjCMessageExpr>hasAnyArgumentMatcherExpr> 
InnerMatcher
 Matches any argument 
of a call expression or a constructor call
 expression, or an ObjC-message-send expression.

Modified: cfe/trunk/include/clang/AST/ASTTypeTraits.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTTypeTraits.h?rev=356675&r1=356674&r2=356675&view=diff
==
--- cfe/t

r356676 - [ASTMatchers][OpenMP] OpenMP Structured-block-related matchers

2019-03-21 Thread Roman Lebedev via cfe-commits
Author: lebedevri
Date: Thu Mar 21 08:33:35 2019
New Revision: 356676

URL: http://llvm.org/viewvc/llvm-project?rev=356676&view=rev
Log:
[ASTMatchers][OpenMP] OpenMP Structured-block-related matchers

Summary: Exposes to the  for ASTMatchers the interface/modelling
of OpenMP structured-block.

Reviewers: gribozavr, aaron.ballman, JonasToth, george.karpenkov

Reviewed By: gribozavr, aaron.ballman

Subscribers: guansong, jdoerfert, cfe-commits

Tags: #clang, #openmp

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

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=356676&r1=356675&r2=356676&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Thu Mar 21 08:33:35 2019
@@ -3497,6 +3497,21 @@ should be passed as a quoted string. e.g
 
 
 
+MatcherOMPExecutableDirective>isStandaloneDirective
+Matches 
standalone OpenMP directives,
+i.e., directives that can't have a structured block.
+
+Given
+
+  #pragma omp parallel
+  {}
+  #pragma omp taskyield
+
+``ompExecutableDirective(isStandaloneDirective()))`` matches
+``omp taskyield``.
+
+
+
 MatcherObjCMessageExpr>argumentCountIsunsigned N
 Checks that a call 
expression or a constructor call expression has
 a specific number of arguments (including absent default arguments).
@@ -3867,6 +3882,19 @@ Usable as: MatcherStmt>isOMPStructuredBlock
+Matches the 
Stmt AST node that is marked as being the structured-block
+of an OpenMP executable directive.
+
+Given
+
+   #pragma omp parallel
+   {}
+
+``stmt(isOMPStructuredBlock()))`` matches ``{}``.
+
+
+
 MatcherStringLiteral>hasSizeunsigned N
 Matches nodes that have the 
specified size.
 
@@ -6234,6 +6262,23 @@ Given
 
 
 
+MatcherOMPExecutableDirective>hasStructuredBlockMatcherStmt> 
InnerMatcher
+Matches the 
structured-block of the OpenMP executable directive
+
+Prerequisite: the executable directive must not be standalone directive.
+If it is, it will never match.
+
+Given
+
+   #pragma omp parallel
+   ;
+   #pragma omp parallel
+   {}
+
+``ompExecutableDirective(hasStructuredBlock(nullStmt()))`` will match ``;``
+
+
+
 MatcherObjCMessageExpr>hasAnyArgumentMatcherExpr> 
InnerMatcher
 Matches any argument 
of a call expression or a constructor call
 expression, or an ObjC-message-send expression.

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=356676&r1=356675&r2=356676&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Thu Mar 21 08:33:35 2019
@@ -6390,6 +6390,58 @@ AST_MATCHER(FunctionDecl, hasTrailingRet
 extern const internal::VariadicDynCastAllOfMatcher
 ompExecutableDirective;
 
+/// Matches standalone OpenMP directives,
+/// i.e., directives that can't have a structured block.
+///
+/// Given
+///
+/// \code
+///   #pragma omp parallel
+///   {}
+///   #pragma omp taskyield
+/// \endcode
+///
+/// ``ompExecutableDirective(isStandaloneDirective()))`` matches
+/// ``omp taskyield``.
+AST_MATCHER(OMPExecutableDirective, isStandaloneDirective) {
+  return Node.isStandaloneDirective();
+}
+
+/// Matches the Stmt AST node that is marked as being the structured-block
+/// of an OpenMP executable directive.
+///
+/// Given
+///
+/// \code
+///#pragma omp parallel
+///{}
+/// \endcode
+///
+/// ``stmt(isOMPStructuredBlock()))`` matches ``{}``.
+AST_MATCHER(Stmt, isOMPStructuredBlock) { return Node.isOMPStructuredBlock(); }
+
+/// Matches the structured-block of the OpenMP executable directive
+///
+/// Prerequisite: the executable directive must not be standalone directive.
+/// If it is, it will never match.
+///
+/// Given
+///
+/// \code
+///#pragma omp parallel
+///;
+///#pragma omp parallel
+///{}
+/// \endcode
+///
+/// ``ompExecutableDirective(hasStructuredBlock(nullStmt()))`` will match ``;``
+AST_MATCHER_P(OMPExecutableDirective, hasStr

r356677 - [ASTMatcher] Add clang-query disclaimer to two more matchers that take enum

2019-03-21 Thread Roman Lebedev via cfe-commits
Author: lebedevri
Date: Thu Mar 21 08:33:43 2019
New Revision: 356677

URL: http://llvm.org/viewvc/llvm-project?rev=356677&view=rev
Log:
[ASTMatcher] Add clang-query disclaimer to two more matchers that take enum

As we have figured out in
https://reviews.llvm.org/D57112
and
https://bugs.llvm.org/show_bug.cgi?id=41176

this kind-of works, but needs special care.

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=356677&r1=356676&r2=356677&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Thu Mar 21 08:33:43 2019
@@ -2640,6 +2640,9 @@ Example matches y(x) but not y(42) or NS
 Example: matches the implicit cast around 0
 (matcher = castExpr(hasCastKind(CK_NullToPointer)))
   int *p = 0;
+
+If the matcher is use from clang-query, CastKind parameter
+should be passed as a quoted string. e.g., ofKind("CK_NullToPointer").
 
 
 
@@ -4086,6 +4089,9 @@ Given
   int s = sizeof(x) + alignof(x)
 unaryExprOrTypeTraitExpr(ofKind(UETT_SizeOf))
   matches sizeof(x)
+
+If the matcher is use from clang-query, UnaryExprOrTypeTrait parameter
+should be passed as a quoted string. e.g., ofKind("UETT_SizeOf").
 
 
 

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=356677&r1=356676&r2=356677&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Thu Mar 21 08:33:43 2019
@@ -2492,6 +2492,9 @@ AST_MATCHER_P(UnaryExprOrTypeTraitExpr,
 /// \endcode
 /// unaryExprOrTypeTraitExpr(ofKind(UETT_SizeOf))
 ///   matches \c sizeof(x)
+///
+/// If the matcher is use from clang-query, UnaryExprOrTypeTrait parameter
+/// should be passed as a quoted string. e.g., ofKind("UETT_SizeOf").
 AST_MATCHER_P(UnaryExprOrTypeTraitExpr, ofKind, UnaryExprOrTypeTrait, Kind) {
   return Node.getKind() == Kind;
 }
@@ -4483,6 +4486,9 @@ AST_POLYMORPHIC_MATCHER_P(hasSourceExpre
 /// \code
 ///   int *p = 0;
 /// \endcode
+///
+/// If the matcher is use from clang-query, CastKind parameter
+/// should be passed as a quoted string. e.g., ofKind("CK_NullToPointer").
 AST_MATCHER_P(CastExpr, hasCastKind, CastKind, Kind) {
   return Node.getCastKind() == Kind;
 }


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


[PATCH] D59453: [ASTMatchers][OpenMP] Add base ompExecutableDirective() matcher.

2019-03-21 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL356674: [ASTMatchers][OpenMP] Add base 
ompExecutableDirective() matcher. (authored by lebedevri, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D59453?vs=191674&id=191705#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D59453

Files:
  cfe/trunk/docs/LibASTMatchersReference.html
  cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
  cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
  cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
  cfe/trunk/unittests/AST/OMPStructuredBlockTest.cpp
  cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
  cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h

Index: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
===
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
@@ -60,6 +60,7 @@
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
+#include "clang/AST/StmtOpenMP.h"
 #include "clang/AST/TemplateBase.h"
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
@@ -6369,6 +6370,29 @@
   return false;
 }
 
+////
+// OpenMP handling.
+////
+
+/// Matches any ``#pragma omp`` executable directive.
+///
+/// Given
+///
+/// \code
+///   #pragma omp parallel
+///   #pragma omp parallel default(none)
+///   #pragma omp taskyield
+/// \endcode
+///
+/// ``ompExecutableDirective()`` matches ``omp parallel``,
+/// ``omp parallel default(none)`` and ``omp taskyield``.
+extern const internal::VariadicDynCastAllOfMatcher
+ompExecutableDirective;
+
+////
+// End OpenMP handling.
+////
+
 } // namespace ast_matchers
 } // namespace clang
 
Index: cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -845,5 +845,8 @@
 AST_POLYMORPHIC_SUPPORTED_TYPES(BlockPointerType, MemberPointerType,
 PointerType, ReferenceType));
 
+const internal::VariadicDynCastAllOfMatcher
+ompExecutableDirective;
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -434,6 +434,7 @@
   REGISTER_MATCHER(objcThrowStmt);
   REGISTER_MATCHER(objcTryStmt);
   REGISTER_MATCHER(ofClass);
+  REGISTER_MATCHER(ompExecutableDirective);
   REGISTER_MATCHER(on);
   REGISTER_MATCHER(onImplicitObjectArgument);
   REGISTER_MATCHER(opaqueValueExpr);
Index: cfe/trunk/unittests/AST/OMPStructuredBlockTest.cpp
===
--- cfe/trunk/unittests/AST/OMPStructuredBlockTest.cpp
+++ cfe/trunk/unittests/AST/OMPStructuredBlockTest.cpp
@@ -28,10 +28,6 @@
 AST_MATCHER(Stmt, isOMPStructuredBlock) { return Node.isOMPStructuredBlock(); }
 
 const ast_matchers::internal::VariadicDynCastAllOfMatcher<
-Stmt, OMPExecutableDirective>
-ompExecutableDirective;
-
-const ast_matchers::internal::VariadicDynCastAllOfMatcher<
 OMPExecutableDirective, OMPTargetDirective>
 ompTargetDirective;
 
Index: cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
===
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -1765,5 +1765,29 @@
   EXPECT_FALSE(matchesObjC(ObjCStringNoPool, autoreleasePoolStmt()));
 }
 
+TEST(OMPExecutableDirective, Matches) {
+  auto Matcher = stmt(ompExecutableDirective());
+
+  const std::string Source0 = R"(
+void x() {
+#pragma omp parallel
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source0, Matcher));
+
+  const std::string Source1 = R"(
+void x() {
+#pragma omp taskyield
+;
+})";
+  EXPECT_TRUE(matchesWithOpenMP(Source1, Matcher));
+
+  const std::string Source2 = R"(
+void x() {
+;
+})";
+  EXPECT_TRUE(notMatchesWithOpenMP(Source2, Matcher));
+}
+
 } // namespace ast_matchers
 } // namespace clang
Index: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h
===
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h
@@ -235,6 +235,18 @@
 }
 
 template 

[PATCH] D57112: [ASTTypeTraits][ASTMatchers][OpenMP] OMPClause handling

2019-03-21 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL356675: [ASTTypeTraits][ASTMatchers][OpenMP] OMPClause 
handling (authored by lebedevri, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D57112?vs=191697&id=191706#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D57112

Files:
  cfe/trunk/docs/LibASTMatchersReference.html
  cfe/trunk/include/clang/AST/ASTTypeTraits.h
  cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
  cfe/trunk/lib/AST/ASTTypeTraits.cpp
  cfe/trunk/lib/ASTMatchers/ASTMatchersInternal.cpp
  cfe/trunk/lib/ASTMatchers/Dynamic/Marshallers.h
  cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
  cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  cfe/trunk/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Index: cfe/trunk/docs/LibASTMatchersReference.html
===
--- cfe/trunk/docs/LibASTMatchersReference.html
+++ cfe/trunk/docs/LibASTMatchersReference.html
@@ -645,6 +645,19 @@
 
 
 
+MatcherOMPClause>ompDefaultClauseMatcherOMPDefaultClause>...
+Matches OpenMP ``default`` clause.
+
+Given
+
+  #pragma omp parallel default(none)
+  #pragma omp parallel default(shared)
+  #pragma omp parallel
+
+``ompDefaultClause()`` matches ``default(none)`` and ``default(shared)``.
+
+
+
 MatcherQualType>qualTypeMatcherQualType>...
 Matches QualTypes in the clang AST.
 
@@ -3439,6 +3452,51 @@
 
 
 
+MatcherOMPDefaultClause>isNoneKind
+Matches if the OpenMP ``default`` clause has ``none`` kind specified.
+
+Given
+
+  #pragma omp parallel
+  #pragma omp parallel default(none)
+  #pragma omp parallel default(shared)
+
+``ompDefaultClause(isNoneKind())`` matches only ``default(none)``.
+
+
+
+MatcherOMPDefaultClause>isSharedKind
+Matches if the OpenMP ``default`` clause has ``shared`` kind specified.
+
+Given
+
+  #pragma omp parallel
+  #pragma omp parallel default(none)
+  #pragma omp parallel default(shared)
+
+``ompDefaultClause(isSharedKind())`` matches only ``default(shared)``.
+
+
+
+MatcherOMPExecutableDirective>isAllowedToContainClauseKindOpenMPClauseKind CKind
+Matches if the OpenMP directive is allowed to contain the specified OpenMP
+clause kind.
+
+Given
+
+  #pragma omp parallel
+  #pragma omp parallel for
+  #pragma omp  for
+
+`ompExecutableDirective(isAllowedToContainClause(OMPC_default))`` matches
+``omp parallel`` and ``omp parallel for``.
+
+If the matcher is use from clang-query, ``OpenMPClauseKind`` parameter
+should be passed as a quoted string. e.g.,
+``isAllowedToContainClauseKind("OMPC_default").``
+
+
+
 MatcherObjCMessageExpr>argumentCountIsunsigned N
 Checks that a call expression or a constructor call expression has
 a specific number of arguments (including absent default arguments).
@@ -6163,6 +6221,19 @@
 
 
 
+MatcherOMPExecutableDirective>hasAnyClauseMatcherOMPClause> InnerMatcher
+Matches any clause in an OpenMP directive.
+
+Given
+
+  #pragma omp parallel
+  #pragma omp parallel default(none)
+
+``ompExecutableDirective(hasAnyClause(anything()))`` matches
+``omp parallel default(none)``.
+
+
+
 MatcherObjCMessageExpr>hasAnyArgumentMatcherExpr> InnerMatcher
 Matches any argument of a call expression or a constructor call
 expression, or an ObjC-message-send expression.
Index: cfe/trunk/include/clang/AST/ASTTypeTraits.h
===
--- cfe/trunk/include/clang/AST/ASTTypeTraits.h
+++ cfe/trunk/include/clang/AST/ASTTypeTraits.h
@@ -18,6 +18,7 @@
 #include "clang/AST/ASTFwd.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/NestedNameSpecifier.h"
+#include "clang/AST/OpenMPClause.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/TemplateBase.h"
 #include "clang/AST/TypeLoc.h"
@@ -58,6 +59,7 @@
   static ASTNodeKind getFromNode(const Decl &D);
   static ASTNodeKind getFromNode(const Stmt &S);
   static ASTNodeKind getFromNode(const Type &T);
+  static ASTNodeKind getFromNode(const OMPClause &C);
   /// \}
 
   /// Returns \c true if \c this and \c Other re

[PATCH] D59463: [ASTMatchers][OpenMP] OpenMP Structured-block-related matchers

2019-03-21 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL356676: [ASTMatchers][OpenMP] OpenMP 
Structured-block-related matchers (authored by lebedevri, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D59463?vs=191701&id=191707#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D59463

Files:
  cfe/trunk/docs/LibASTMatchersReference.html
  cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
  cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
  cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Index: cfe/trunk/docs/LibASTMatchersReference.html
===
--- cfe/trunk/docs/LibASTMatchersReference.html
+++ cfe/trunk/docs/LibASTMatchersReference.html
@@ -3497,6 +3497,21 @@
 
 
 
+MatcherOMPExecutableDirective>isStandaloneDirective
+Matches standalone OpenMP directives,
+i.e., directives that can't have a structured block.
+
+Given
+
+  #pragma omp parallel
+  {}
+  #pragma omp taskyield
+
+``ompExecutableDirective(isStandaloneDirective()))`` matches
+``omp taskyield``.
+
+
+
 MatcherObjCMessageExpr>argumentCountIsunsigned N
 Checks that a call expression or a constructor call expression has
 a specific number of arguments (including absent default arguments).
@@ -3867,6 +3882,19 @@
 
 
 
+MatcherStmt>isOMPStructuredBlock
+Matches the Stmt AST node that is marked as being the structured-block
+of an OpenMP executable directive.
+
+Given
+
+   #pragma omp parallel
+   {}
+
+``stmt(isOMPStructuredBlock()))`` matches ``{}``.
+
+
+
 MatcherStringLiteral>hasSizeunsigned N
 Matches nodes that have the specified size.
 
@@ -6234,6 +6262,23 @@
 
 
 
+MatcherOMPExecutableDirective>hasStructuredBlockMatcherStmt> InnerMatcher
+Matches the structured-block of the OpenMP executable directive
+
+Prerequisite: the executable directive must not be standalone directive.
+If it is, it will never match.
+
+Given
+
+   #pragma omp parallel
+   ;
+   #pragma omp parallel
+   {}
+
+``ompExecutableDirective(hasStructuredBlock(nullStmt()))`` will match ``;``
+
+
+
 MatcherObjCMessageExpr>hasAnyArgumentMatcherExpr> InnerMatcher
 Matches any argument of a call expression or a constructor call
 expression, or an ObjC-message-send expression.
Index: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
===
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
@@ -6390,6 +6390,58 @@
 extern const internal::VariadicDynCastAllOfMatcher
 ompExecutableDirective;
 
+/// Matches standalone OpenMP directives,
+/// i.e., directives that can't have a structured block.
+///
+/// Given
+///
+/// \code
+///   #pragma omp parallel
+///   {}
+///   #pragma omp taskyield
+/// \endcode
+///
+/// ``ompExecutableDirective(isStandaloneDirective()))`` matches
+/// ``omp taskyield``.
+AST_MATCHER(OMPExecutableDirective, isStandaloneDirective) {
+  return Node.isStandaloneDirective();
+}
+
+/// Matches the Stmt AST node that is marked as being the structured-block
+/// of an OpenMP executable directive.
+///
+/// Given
+///
+/// \code
+///#pragma omp parallel
+///{}
+/// \endcode
+///
+/// ``stmt(isOMPStructuredBlock()))`` matches ``{}``.
+AST_MATCHER(Stmt, isOMPStructuredBlock) { return Node.isOMPStructuredBlock(); }
+
+/// Matches the structured-block of the OpenMP executable directive
+///
+/// Prerequisite: the executable directive must not be standalone directive.
+/// If it is, it will never match.
+///
+/// Given
+///
+/// \code
+///#pragma omp parallel
+///;
+///#pragma omp parallel
+///{}
+/// \endcode
+///
+/// ``ompExecutableDirective(hasStructuredBlock(nullStmt()))`` will match ``;``
+AST_MATCHER_P(OMPExecutableDirective, hasStructuredBlock,
+  internal::Matcher, InnerMatcher) {
+  if (Node.isStandaloneDirective())
+return false; // Standalone directives have no structured blocks.
+  return InnerMatcher.matches(*Node.getStructuredBlock(), Finder, Builder);
+}
+
 /// Matches any clause in an OpenMP directive.
 ///
 /// Given
Index: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
+++ cfe/trunk/lib/ASTMat

[PATCH] D59639: [clangd] Print template arguments helper

2019-03-21 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/clangd/AST.cpp:26
+llvm::Optional>
+getTemplateSpecializationArgLocs(const NamedDecl &ND) {
+  if (auto *Func = llvm::dyn_cast(&ND)) {

Functions should be static, not in anonymous namespace. See LLVM Coding 
Guidelines.



Comment at: clang-tools-extra/clangd/AST.cpp:28
+  if (auto *Func = llvm::dyn_cast(&ND)) {
+if (auto *Args = Func->getTemplateSpecializationArgsAsWritten())
+  return Args->arguments();

Return type is not obvious, so auto should not be used.



Comment at: clang-tools-extra/clangd/AST.cpp:131
+  PrintingPolicy Policy(ND.getASTContext().getLangOpts());
+  if (auto Args = getTemplateSpecializationArgLocs(ND))
+printTemplateArgumentList(OS, *Args, Policy);

Return type is not obvious, so auto should not be used.



Comment at: clang/lib/AST/TypePrinter.cpp:1642
+  const PrintingPolicy &PP, llvm::raw_ostream &OS) {
+  const auto &Kind = A.getArgument().getKind();
+  assert(Kind != TemplateArgument::Null &&

Return type is not obvious, so auto should not be used.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59639



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


[PATCH] D59647: [CUDA][HIP] Warn shared var initialization

2019-03-21 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: tra.
Herald added a project: clang.

In many cases the default constructor of a class contains initializer of data
members, which allows concise code. The class may be instantiated as
global or automatic variables in device code, which is totally legal. However
when such a class is instantiated as a shared variable in device code, clang
will emit an error saying shared variables cannot be initialized.

Usually, users would like to just add explicit initialization for the shared 
variable,
instead of remove the initializer of data members from the default constructor,
since that would requires adding explicit initialization to all instances of 
the class,
even as global or automatic variables.

This requires the diagnostic of initialization of shared variable to be a 
warning,
instead of an error.

nvcc emits an warning for such situation, e.g.

  $ cat a.cu
  
  struct A {
int a;
__device__ A():a(0){}
  };
  
  
  __global__ void foo() {
__shared__ A a;
  }
  
  $nvcc -c a.cu
  a.cu(10): warning: __shared__ memory variable with non-empty constructor or 
destructor (potential race between threads)

This patch turns the diagnostic of initialization of shared varibles into a 
warning.
By default it is still treated as error, therefore no behavior change of clang. 
However,
user can turn it into a warning by -Wno-error=cuda-shared-init.


Repository:
  rC Clang

https://reviews.llvm.org/D59647

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaCUDA.cpp


Index: lib/Sema/SemaCUDA.cpp
===
--- lib/Sema/SemaCUDA.cpp
+++ lib/Sema/SemaCUDA.cpp
@@ -499,7 +499,7 @@
 
 if (!AllowedInit) {
   Diag(VD->getLocation(), VD->hasAttr()
-  ? diag::err_shared_var_init
+  ? diag::warn_shared_var_init
   : diag::err_dynamic_var_init)
   << Init->getSourceRange();
   VD->setInvalidDecl();
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -7194,8 +7194,9 @@
 def err_dynamic_var_init : Error<
 "dynamic initialization is not supported for "
 "__device__, __constant__, and __shared__ variables.">;
-def err_shared_var_init : Error<
-"initialization is not supported for __shared__ variables.">;
+def warn_shared_var_init : Warning<
+"initialization is not supported for __shared__ variables.">,
+InGroup>, DefaultError;
 def err_device_static_local_var : Error<
 "within a %select{__device__|__global__|__host__|__host__ __device__}0 "
 "function, only __shared__ variables or const variables without device "


Index: lib/Sema/SemaCUDA.cpp
===
--- lib/Sema/SemaCUDA.cpp
+++ lib/Sema/SemaCUDA.cpp
@@ -499,7 +499,7 @@
 
 if (!AllowedInit) {
   Diag(VD->getLocation(), VD->hasAttr()
-  ? diag::err_shared_var_init
+  ? diag::warn_shared_var_init
   : diag::err_dynamic_var_init)
   << Init->getSourceRange();
   VD->setInvalidDecl();
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -7194,8 +7194,9 @@
 def err_dynamic_var_init : Error<
 "dynamic initialization is not supported for "
 "__device__, __constant__, and __shared__ variables.">;
-def err_shared_var_init : Error<
-"initialization is not supported for __shared__ variables.">;
+def warn_shared_var_init : Warning<
+"initialization is not supported for __shared__ variables.">,
+InGroup>, DefaultError;
 def err_device_static_local_var : Error<
 "within a %select{__device__|__global__|__host__|__host__ __device__}0 "
 "function, only __shared__ variables or const variables without device "
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r356679 - [AST] OMPStructuredBlockTest: two matchers were promoted into ASTMatchers.h

2019-03-21 Thread Roman Lebedev via cfe-commits
Author: lebedevri
Date: Thu Mar 21 08:50:54 2019
New Revision: 356679

URL: http://llvm.org/viewvc/llvm-project?rev=356679&view=rev
Log:
[AST] OMPStructuredBlockTest: two matchers were promoted into ASTMatchers.h

Modified:
cfe/trunk/unittests/AST/OMPStructuredBlockTest.cpp

Modified: cfe/trunk/unittests/AST/OMPStructuredBlockTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/OMPStructuredBlockTest.cpp?rev=356679&r1=356678&r2=356679&view=diff
==
--- cfe/trunk/unittests/AST/OMPStructuredBlockTest.cpp (original)
+++ cfe/trunk/unittests/AST/OMPStructuredBlockTest.cpp Thu Mar 21 08:50:54 2019
@@ -14,6 +14,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/StmtOpenMP.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/SmallString.h"
 #include "gmock/gmock.h"
@@ -25,8 +26,6 @@ using namespace tooling;
 
 namespace {
 
-AST_MATCHER(Stmt, isOMPStructuredBlock) { return Node.isOMPStructuredBlock(); }
-
 const ast_matchers::internal::VariadicDynCastAllOfMatcher<
 OMPExecutableDirective, OMPTargetDirective>
 ompTargetDirective;
@@ -37,10 +36,6 @@ StatementMatcher OMPInnermostStructuredB
   .bind("id");
 }
 
-AST_MATCHER(OMPExecutableDirective, isStandaloneDirective) {
-  return Node.isStandaloneDirective();
-}
-
 StatementMatcher OMPStandaloneDirectiveMatcher() {
   return stmt(ompExecutableDirective(isStandaloneDirective())).bind("id");
 }


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


[PATCH] D59440: add steps to preprocess file and reduce command line args

2019-03-21 Thread Amy Huang via Phabricator via cfe-commits
akhuang added a comment.

@arichardson Will add you next time, sorry I didn't do so on this one!


Repository:
  rC Clang

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

https://reviews.llvm.org/D59440



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


[PATCH] D59650: [NFC] ExceptionEscapeCheck: small refactoring

2019-03-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri created this revision.
lebedev.ri added reviewers: baloghadamsoftware, JonasToth, gribozavr.
lebedev.ri added a project: clang-tools-extra.
Herald added a subscriber: rnkovacs.
Herald added a project: clang.

D59466  wants to analyse the `Stmt`, and 
`ExceptionEscapeCheck` does not
have that as a possible entry point.
This simplifies addition of `Stmt` analysis entry point.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D59650

Files:
  clang-tidy/utils/ExceptionAnalyzer.cpp
  clang-tidy/utils/ExceptionAnalyzer.h


Index: clang-tidy/utils/ExceptionAnalyzer.h
===
--- clang-tidy/utils/ExceptionAnalyzer.h
+++ clang-tidy/utils/ExceptionAnalyzer.h
@@ -128,7 +128,7 @@
 IgnoredExceptions = std::move(ExceptionNames);
   }
 
-  ExceptionInfo analyze(const FunctionDecl *Func);
+  template  ExceptionInfo analyze(const T *Node);
 
 private:
   ExceptionInfo
@@ -138,10 +138,17 @@
   throwsException(const Stmt *St, const ExceptionInfo::Throwables &Caught,
   llvm::SmallSet &CallStack);
 
+  template 
+  void analyze(const T *Node, ExceptionInfo &ExceptionList);
+
   bool IgnoreBadAlloc = true;
   llvm::StringSet<> IgnoredExceptions;
   std::map FunctionCache;
 };
+
+extern template ExceptionAnalyzer::ExceptionInfo
+ExceptionAnalyzer::analyze(const FunctionDecl *Func);
+
 } // namespace utils
 } // namespace tidy
 } // namespace clang
Index: clang-tidy/utils/ExceptionAnalyzer.cpp
===
--- clang-tidy/utils/ExceptionAnalyzer.cpp
+++ clang-tidy/utils/ExceptionAnalyzer.cpp
@@ -204,10 +204,9 @@
   return Results;
 }
 
-ExceptionAnalyzer::ExceptionInfo
-ExceptionAnalyzer::analyze(const FunctionDecl *Func) {
-  ExceptionInfo ExceptionList;
-
+template <>
+void ExceptionAnalyzer::analyze(const FunctionDecl *Func,
+ExceptionInfo &ExceptionList) {
   // Check if the function has already been analyzed and reuse that result.
   if (FunctionCache.count(Func) == 0) {
 llvm::SmallSet CallStack;
@@ -220,6 +219,13 @@
 FunctionCache.insert(std::make_pair(Func, ExceptionList));
   } else
 ExceptionList = FunctionCache[Func];
+}
+
+template 
+ExceptionAnalyzer::ExceptionInfo ExceptionAnalyzer::analyze(const T *Node) {
+  ExceptionInfo ExceptionList;
+
+  analyze(Node, ExceptionList);
 
   if (ExceptionList.getBehaviour() == State::NotThrowing ||
   ExceptionList.getBehaviour() == State::Unknown)
@@ -231,6 +237,10 @@
 
   return ExceptionList;
 }
+
+template ExceptionAnalyzer::ExceptionInfo
+ExceptionAnalyzer::analyze(const FunctionDecl *Func);
+
 } // namespace utils
 } // namespace tidy
 


Index: clang-tidy/utils/ExceptionAnalyzer.h
===
--- clang-tidy/utils/ExceptionAnalyzer.h
+++ clang-tidy/utils/ExceptionAnalyzer.h
@@ -128,7 +128,7 @@
 IgnoredExceptions = std::move(ExceptionNames);
   }
 
-  ExceptionInfo analyze(const FunctionDecl *Func);
+  template  ExceptionInfo analyze(const T *Node);
 
 private:
   ExceptionInfo
@@ -138,10 +138,17 @@
   throwsException(const Stmt *St, const ExceptionInfo::Throwables &Caught,
   llvm::SmallSet &CallStack);
 
+  template 
+  void analyze(const T *Node, ExceptionInfo &ExceptionList);
+
   bool IgnoreBadAlloc = true;
   llvm::StringSet<> IgnoredExceptions;
   std::map FunctionCache;
 };
+
+extern template ExceptionAnalyzer::ExceptionInfo
+ExceptionAnalyzer::analyze(const FunctionDecl *Func);
+
 } // namespace utils
 } // namespace tidy
 } // namespace clang
Index: clang-tidy/utils/ExceptionAnalyzer.cpp
===
--- clang-tidy/utils/ExceptionAnalyzer.cpp
+++ clang-tidy/utils/ExceptionAnalyzer.cpp
@@ -204,10 +204,9 @@
   return Results;
 }
 
-ExceptionAnalyzer::ExceptionInfo
-ExceptionAnalyzer::analyze(const FunctionDecl *Func) {
-  ExceptionInfo ExceptionList;
-
+template <>
+void ExceptionAnalyzer::analyze(const FunctionDecl *Func,
+ExceptionInfo &ExceptionList) {
   // Check if the function has already been analyzed and reuse that result.
   if (FunctionCache.count(Func) == 0) {
 llvm::SmallSet CallStack;
@@ -220,6 +219,13 @@
 FunctionCache.insert(std::make_pair(Func, ExceptionList));
   } else
 ExceptionList = FunctionCache[Func];
+}
+
+template 
+ExceptionAnalyzer::ExceptionInfo ExceptionAnalyzer::analyze(const T *Node) {
+  ExceptionInfo ExceptionList;
+
+  analyze(Node, ExceptionList);
 
   if (ExceptionList.getBehaviour() == State::NotThrowing ||
   ExceptionList.getBehaviour() == State::Unknown)
@@ -231,6 +237,10 @@
 
   return ExceptionList;
 }
+
+template ExceptionAnalyzer::ExceptionInfo
+ExceptionAnalyzer::analyze(const FunctionDecl *Func);
+
 } // namespace utils
 } // namespace tidy
 
___
cfe-commits mailin

[PATCH] D57571: [clang-tidy] A new OpenMP module

2019-03-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 191724.
lebedev.ri added a comment.

Rebased, NFC.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D57571

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/ClangTidyForceLinker.h
  clang-tidy/openmp/CMakeLists.txt
  clang-tidy/openmp/OpenMPTidyModule.cpp
  clang-tidy/plugin/CMakeLists.txt
  clang-tidy/tool/CMakeLists.txt
  docs/ReleaseNotes.rst
  docs/clang-tidy/index.rst

Index: docs/clang-tidy/index.rst
===
--- docs/clang-tidy/index.rst
+++ docs/clang-tidy/index.rst
@@ -73,6 +73,7 @@
means "C++11") language constructs.
 ``mpi-``   Checks related to MPI (Message Passing Interface).
 ``objc-``  Checks related to Objective-C coding conventions.
+``openmp-``Checks related to OpenMP API.
 ``performance-``   Checks that target performance-related issues.
 ``portability-``   Checks that target portability-related issues that don't
relate to any particular coding style.
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -67,6 +67,10 @@
 Improvements to clang-tidy
 --
 
+- New OpenMP module.
+
+  For checks specific to `OpenMP `_ API.
+
 - New :doc:`abseil-duration-addition
   ` check.
 
Index: clang-tidy/tool/CMakeLists.txt
===
--- clang-tidy/tool/CMakeLists.txt
+++ clang-tidy/tool/CMakeLists.txt
@@ -30,6 +30,7 @@
   clangTidyMiscModule
   clangTidyModernizeModule
   clangTidyObjCModule
+  clangTidyOpenMPModule
   clangTidyPerformanceModule
   clangTidyPortabilityModule
   clangTidyReadabilityModule
Index: clang-tidy/plugin/CMakeLists.txt
===
--- clang-tidy/plugin/CMakeLists.txt
+++ clang-tidy/plugin/CMakeLists.txt
@@ -21,6 +21,7 @@
   clangTidyMiscModule
   clangTidyModernizeModule
   clangTidyObjCModule
+  clangTidyOpenMPModule
   clangTidyPerformanceModule
   clangTidyPortabilityModule
   clangTidyReadabilityModule
Index: clang-tidy/openmp/OpenMPTidyModule.cpp
===
--- /dev/null
+++ clang-tidy/openmp/OpenMPTidyModule.cpp
@@ -0,0 +1,35 @@
+//===--- OpenMPTidyModule.cpp - clang-tidy===//
+//
+// 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 "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+
+namespace clang {
+namespace tidy {
+namespace openmp {
+
+/// This module is for OpenMP-specific checks.
+class OpenMPModule : public ClangTidyModule {
+public:
+  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+  }
+};
+
+// Register the OpenMPTidyModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add
+X("openmp-module", "Adds OpenMP-specific checks.");
+
+} // namespace openmp
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the OpenMPModule.
+volatile int OpenMPModuleAnchorSource = 0;
+
+} // namespace tidy
+} // namespace clang
Index: clang-tidy/openmp/CMakeLists.txt
===
--- /dev/null
+++ clang-tidy/openmp/CMakeLists.txt
@@ -0,0 +1,11 @@
+set(LLVM_LINK_COMPONENTS support)
+
+add_clang_library(clangTidyOpenMPModule
+  OpenMPTidyModule.cpp
+
+  LINK_LIBS
+  clangAST
+  clangASTMatchers
+  clangBasic
+  clangTidy
+  )
Index: clang-tidy/ClangTidyForceLinker.h
===
--- clang-tidy/ClangTidyForceLinker.h
+++ clang-tidy/ClangTidyForceLinker.h
@@ -77,6 +77,11 @@
 MPIModuleAnchorSource;
 #endif
 
+// This anchor is used to force the linker to link the OpenMPModule.
+extern volatile int OpenMPModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED OpenMPModuleAnchorDestination =
+OpenMPModuleAnchorSource;
+
 // This anchor is used to force the linker to link the PerformanceModule.
 extern volatile int PerformanceModuleAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination =
Index: clang-tidy/CMakeLists.txt
===
--- clang-tidy/CMakeLists.txt
+++ clang-tidy/CMakeLists.txt
@@ -49,6 +49,7 @@
   add_subdirectory(mpi)
 endif()
 add_subdirectory(objc)
+add_subdirectory(openmp)
 add_subdirectory(performance)
 add_subdirectory(plugin)
 add_subdirectory(portability)
___

[PATCH] D59466: [clang-tidy] openmp-exception-escape - a new check

2019-03-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 191727.
lebedev.ri added a reviewer: gribozavr.
lebedev.ri added a comment.

Rebased, NFC.
Split base ExceptionEscapeCheck refactoring into D59650 
.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D59466

Files:
  clang-tidy/openmp/CMakeLists.txt
  clang-tidy/openmp/ExceptionEscapeCheck.cpp
  clang-tidy/openmp/ExceptionEscapeCheck.h
  clang-tidy/openmp/OpenMPTidyModule.cpp
  clang-tidy/utils/ExceptionAnalyzer.cpp
  clang-tidy/utils/ExceptionAnalyzer.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/openmp-exception-escape.rst
  test/clang-tidy/bugprone-exception-escape-openmp.cpp
  test/clang-tidy/openmp-exception-escape.cpp

Index: test/clang-tidy/openmp-exception-escape.cpp
===
--- /dev/null
+++ test/clang-tidy/openmp-exception-escape.cpp
@@ -0,0 +1,126 @@
+// RUN: %check_clang_tidy %s openmp-exception-escape %t -- -extra-arg=-fopenmp -extra-arg=-fexceptions -config="{CheckOptions: [{key: openmp-exception-escape.IgnoredExceptions, value: 'ignored'}]}" --
+
+int thrower() {
+  throw 42;
+}
+
+class ignored {};
+namespace std {
+class bad_alloc {};
+} // namespace std
+
+void parallel() {
+#pragma omp parallel
+  thrower();
+  // CHECK-MESSAGES: :[[@LINE-2]]:9: warning: An exception thrown inside of the OpenMP 'parallel' region is not caught in that same region.
+}
+
+void ignore() {
+#pragma omp parallel
+  throw ignored();
+}
+
+void standalone_directive() {
+#pragma omp taskwait
+  throw ignored(); // not structured block
+}
+
+void ignore_alloc() {
+#pragma omp parallel
+  throw std::bad_alloc();
+}
+
+void parallel_caught() {
+#pragma omp parallel
+  {
+try {
+  thrower();
+} catch (...) {
+}
+  }
+}
+
+void for_header(const int a) {
+  // Only the body of the loop counts.
+#pragma omp for
+  for (int i = 0; i < thrower(); i++)
+;
+}
+
+void forloop(const int a) {
+#pragma omp for
+  for (int i = 0; i < a; i++)
+thrower();
+  // CHECK-MESSAGES: :[[@LINE-3]]:9: warning: An exception thrown inside of the OpenMP 'for' region is not caught in that same region.
+}
+
+void parallel_forloop(const int a) {
+#pragma omp parallel
+  {
+#pragma omp for
+for (int i = 0; i < a; i++)
+  thrower();
+thrower();
+// CHECK-MESSAGES: :[[@LINE-6]]:9: warning: An exception thrown inside of the OpenMP 'parallel' region is not caught in that same region.
+// CHECK-MESSAGES: :[[@LINE-5]]:9: warning: An exception thrown inside of the OpenMP 'for' region is not caught in that same region.
+  }
+}
+
+void parallel_forloop_caught(const int a) {
+#pragma omp parallel
+  {
+#pragma omp for
+for (int i = 0; i < a; i++) {
+  try {
+thrower();
+  } catch (...) {
+  }
+}
+thrower();
+// CHECK-MESSAGES: :[[@LINE-10]]:9: warning: An exception thrown inside of the OpenMP 'parallel' region is not caught in that same region.
+  }
+}
+
+void parallel_caught_forloop(const int a) {
+#pragma omp parallel
+  {
+#pragma omp for
+for (int i = 0; i < a; i++)
+  thrower();
+try {
+  thrower();
+} catch (...) {
+}
+// CHECK-MESSAGES: :[[@LINE-7]]:9: warning: An exception thrown inside of the OpenMP 'for' region is not caught in that same region.
+  }
+}
+
+void parallel_outercaught_forloop(const int a) {
+#pragma omp parallel
+  {
+try {
+#pragma omp for
+  for (int i = 0; i < a; i++)
+thrower();
+  thrower();
+} catch (...) {
+}
+// CHECK-MESSAGES: :[[@LINE-6]]:9: warning: An exception thrown inside of the OpenMP 'for' region is not caught in that same region.
+  }
+}
+
+void parallel_outercaught_forloop_caught(const int a) {
+#pragma omp parallel
+  {
+try {
+#pragma omp for
+  for (int i = 0; i < a; i++) {
+try {
+  thrower();
+} catch (...) {
+}
+  }
+} catch (...) {
+}
+  }
+}
Index: test/clang-tidy/bugprone-exception-escape-openmp.cpp
===
--- /dev/null
+++ test/clang-tidy/bugprone-exception-escape-openmp.cpp
@@ -0,0 +1,29 @@
+// RUN: %check_clang_tidy %s bugprone-exception-escape %t -- -extra-arg=-fopenmp -extra-arg=-fexceptions --
+
+int thrower() {
+  throw 42;
+}
+
+void ok_parallel() {
+#pragma omp parallel
+  thrower();
+}
+
+void bad_for_header_XFAIL(const int a) {
+#pragma omp for
+  for (int i = 0; i < thrower(); i++)
+;
+  // FIXME: this really should be caught by bugprone-exception-escape.
+  // https://bugs.llvm.org/show_bug.cgi?id=41102
+}
+
+void ok_forloop(const int a) {
+#pragma omp for
+  for (int i = 0; i < a; i++)
+thrower();
+}
+
+void some_exception_just_so_that_check_clang_tidy_shuts_up() noexcept {
+  thrower();
+}
+// CHECK-MESSAGES: :[[@LINE-3]]:6: warning: an exception may be thrown in function 'some_excepti

[PATCH] D57113: [clang-tidy] openmp-use-default-none - a new check

2019-03-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri updated this revision to Diff 191726.
lebedev.ri marked 4 inline comments as done.
lebedev.ri edited the summary of this revision.
lebedev.ri added a reviewer: gribozavr.
lebedev.ri added a comment.

Rebased, NFC.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D57113

Files:
  clang-tidy/openmp/CMakeLists.txt
  clang-tidy/openmp/OpenMPTidyModule.cpp
  clang-tidy/openmp/UseDefaultNoneCheck.cpp
  clang-tidy/openmp/UseDefaultNoneCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/openmp-use-default-none.rst
  test/clang-tidy/openmp-use-default-none.cpp

Index: test/clang-tidy/openmp-use-default-none.cpp
===
--- /dev/null
+++ test/clang-tidy/openmp-use-default-none.cpp
@@ -0,0 +1,160 @@
+// RUN: %check_clang_tidy %s openmp-use-default-none %t -- -- -x c++ -fopenmp -fopenmp-version=40
+// RUN: %check_clang_tidy %s openmp-use-default-none %t -- -- -x c   -fopenmp -fopenmp-version=40
+
+////
+// Null cases.
+////
+
+// 'for' directive can not have 'default' clause, no diagnostics.
+void n0(const int a) {
+#pragma omp for
+  for (int b = 0; b < a; b++)
+;
+}
+
+////
+// Single-directive positive cases.
+////
+
+// 'parallel' directive.
+
+// 'parallel' directive can have 'default' clause, but said clause is not
+// specified, diagnosed.
+void p0_0() {
+#pragma omp parallel
+  ;
+  // CHECK-NOTES: :[[@LINE-2]]:9: warning: OpenMP directive 'parallel' does not specify 'default' clause. Consider specifying 'default(none)' clause.
+}
+
+// 'parallel' directive can have 'default' clause, and said clause is specified,
+// with 'none' kind, all good.
+void p0_1() {
+#pragma omp parallel default(none)
+  ;
+}
+
+// 'parallel' directive can have 'default' clause, and said clause is specified,
+// but with 'shared' kind, which is not 'none', diagnose.
+void p0_2() {
+#pragma omp parallel default(shared)
+  ;
+  // CHECK-NOTES: :[[@LINE-2]]:9: warning: OpenMP directive 'parallel' specifies 'default(shared)' clause. Consider using 'default(none)' clause instead.
+  // CHECK-NOTES: :[[@LINE-3]]:22: note: Existing 'default' clause is specified here.
+}
+
+// 'task' directive.
+
+// 'task' directive can have 'default' clause, but said clause is not
+// specified, diagnosed.
+void p1_0() {
+#pragma omp task
+  ;
+  // CHECK-NOTES: :[[@LINE-2]]:9: warning: OpenMP directive 'task' does not specify 'default' clause. Consider specifying 'default(none)' clause.
+}
+
+// 'task' directive can have 'default' clause, and said clause is specified,
+// with 'none' kind, all good.
+void p1_1() {
+#pragma omp task default(none)
+  ;
+}
+
+// 'task' directive can have 'default' clause, and said clause is specified,
+// but with 'shared' kind, which is not 'none', diagnose.
+void p1_2() {
+#pragma omp task default(shared)
+  ;
+  // CHECK-NOTES: :[[@LINE-2]]:9: warning: OpenMP directive 'task' specifies 'default(shared)' clause. Consider using 'default(none)' clause instead.
+  // CHECK-NOTES: :[[@LINE-3]]:18: note: Existing 'default' clause is specified here.
+}
+
+// 'teams' directive. (has to be inside of 'target' directive)
+
+// 'teams' directive can have 'default' clause, but said clause is not
+// specified, diagnosed.
+void p2_0() {
+#pragma omp target
+#pragma omp teams
+  ;
+  // CHECK-NOTES: :[[@LINE-2]]:9: warning: OpenMP directive 'teams' does not specify 'default' clause. Consider specifying 'default(none)' clause.
+}
+
+// 'teams' directive can have 'default' clause, and said clause is specified,
+// with 'none' kind, all good.
+void p2_1() {
+#pragma omp target
+#pragma omp teams default(none)
+  ;
+}
+
+// 'teams' directive can have 'default' clause, and said clause is specified,
+// but with 'shared' kind, which is not 'none', diagnose.
+void p2_2() {
+#pragma omp target
+#pragma omp teams default(shared)
+  ;
+  // CHECK-NOTES: :[[@LINE-2]]:9: warning: OpenMP directive 'teams' specifies 'default(shared)' clause. Consider using 'default(none)' clause instead.
+  // CHECK-NOTES: :[[@LINE-3]]:19: note: Existing 'default' clause is specified here.
+}
+
+// 'taskloop' directive.
+
+// 'taskloop' directive can have 'default' clause, but said clause is not
+// specified, diagnosed.
+void p3_0(const int a) {
+#pragma omp taskloop
+  for (int b = 0; b < a; b++)
+;
+  // CHECK-NOTES: :[[@LINE-3]]:9: warning: OpenMP directive 'taskloop' does not specify 'default' clause. Consider specifying 'default(none)' clause.
+}
+
+// 'taskloop' directive can have 'default' clause, and said clause is specified,
+// with 'none' kind, all good.
+void 

[PATCH] D59627: [clang-format] Keep protobuf "package" statement on one line

2019-03-21 Thread Donald Chai via Phabricator via cfe-commits
dchai updated this revision to Diff 191734.
dchai added a comment.

Use "isOneOf" instead of two calls to "is".


Repository:
  rC Clang

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

https://reviews.llvm.org/D59627

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestProto.cpp


Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -387,6 +387,12 @@
"};");
 }
 
+TEST_F(FormatTestProto, DoesntWrapPackageStatements) {
+  verifyFormat(
+  "package"
+  " some.really.long.package.that.exceeds.the.column.limit;");
+}
+
 TEST_F(FormatTestProto, FormatsService) {
   verifyFormat("service SearchService {\n"
"  rpc Search(SearchRequest) returns (SearchResponse) {\n"
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1073,10 +1073,10 @@
   return LT_ImportStatement;
 }
 
-// In .proto files, top-level options are very similar to import statements
-// and should not be line-wrapped.
+// In .proto files, top-level options and package statements are very
+// similar to import statements and should not be line-wrapped.
 if (Style.Language == FormatStyle::LK_Proto && Line.Level == 0 &&
-CurrentToken->is(Keywords.kw_option)) {
+CurrentToken->isOneOf(Keywords.kw_option, Keywords.kw_package)) {
   next();
   if (CurrentToken && CurrentToken->is(tok::identifier))
 return LT_ImportStatement;


Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -387,6 +387,12 @@
"};");
 }
 
+TEST_F(FormatTestProto, DoesntWrapPackageStatements) {
+  verifyFormat(
+  "package"
+  " some.really.long.package.that.exceeds.the.column.limit;");
+}
+
 TEST_F(FormatTestProto, FormatsService) {
   verifyFormat("service SearchService {\n"
"  rpc Search(SearchRequest) returns (SearchResponse) {\n"
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1073,10 +1073,10 @@
   return LT_ImportStatement;
 }
 
-// In .proto files, top-level options are very similar to import statements
-// and should not be line-wrapped.
+// In .proto files, top-level options and package statements are very
+// similar to import statements and should not be line-wrapped.
 if (Style.Language == FormatStyle::LK_Proto && Line.Level == 0 &&
-CurrentToken->is(Keywords.kw_option)) {
+CurrentToken->isOneOf(Keywords.kw_option, Keywords.kw_package)) {
   next();
   if (CurrentToken && CurrentToken->is(tok::identifier))
 return LT_ImportStatement;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58236: Make address space conversions a bit stricter.

2019-03-21 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D58236#1437690 , @ebevhan wrote:

> Any more input on this?
>
> I could redo the patch to simply fix the bug and not make the conversions 
> stricter, if that's preferable.


I was playing a bit with some examples of enum with pointer field of various 
address spaces and I couldn't find any case where successfully converting 
nested pointers was useful. Instead it could easily result in execution of 
incorrect code. So I am sticking to the opinion to be more strict.

Similarly, C++ is more strict with similar conversions i.e. nested pointers 
between Derived and Base. I still think since we are implementing new rules it 
is good to be more helpful rather than inheriting older logic of permitting 
everything like in C.

Also of course if we find later any issue we could fix them and modify the 
behavior.


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

https://reviews.llvm.org/D58236



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


r356686 - [X86] Use the CPUKind enum from PROC_ALIAS to directly get the CPUKind in fillValidCPUList.

2019-03-21 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Thu Mar 21 10:33:20 2019
New Revision: 356686

URL: http://llvm.org/viewvc/llvm-project?rev=356686&view=rev
Log:
[X86] Use the CPUKind enum from PROC_ALIAS to directly get the CPUKind in 
fillValidCPUList.

We were using getCPUKind which translates the string to the enum also using 
PROC_ALIAS. This just cuts out the string compares.

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

Modified: cfe/trunk/lib/Basic/Targets/X86.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/X86.cpp?rev=356686&r1=356685&r2=356686&view=diff
==
--- cfe/trunk/lib/Basic/Targets/X86.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/X86.cpp Thu Mar 21 10:33:20 2019
@@ -1819,10 +1819,9 @@ void X86TargetInfo::fillValidCPUList(Sma
 #define PROC(ENUM, STRING, IS64BIT)
\
   if (IS64BIT || getTriple().getArch() == llvm::Triple::x86)   
\
 Values.emplace_back(STRING);
-  // Go through CPUKind checking to ensure that the alias is de-aliased and
-  // 64 bit-ness is checked.
+  // For aliases we need to lookup the CPUKind to check get the 64-bit ness.
 #define PROC_ALIAS(ENUM, ALIAS)
\
-  if (checkCPUKind(getCPUKind(ALIAS))) 
\
+  if (checkCPUKind(CK_##ENUM)) 
 \
 Values.emplace_back(ALIAS);
 #include "clang/Basic/X86Target.def"
 }


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


[PATCH] D57464: Generalize method overloading on addr spaces to C++

2019-03-21 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.



> I think I would lean towards the latter since it means less fudging around 
> with a whole bunch of unrelated methods. Do @rjmccall or @rsmith have any 
> further opinions on this?

Ok, I can change the patch to prototype this approach. I might need some 
example test cases though.


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

https://reviews.llvm.org/D57464



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


[PATCH] D59639: [clangd] Print template arguments helper

2019-03-21 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: clang-tools-extra/clangd/AST.cpp:88
 static const TemplateArgumentList *
 getTemplateSpecializationArgs(const NamedDecl &ND) {
   if (auto *Func = llvm::dyn_cast(&ND))

can we unify this with `getTemplateSpecializationArgLocs` somehow? 

it seems that args as written would also be favorable here (see FIXME in line 
112)



Comment at: clang-tools-extra/clangd/AST.cpp:131
+  PrintingPolicy Policy(ND.getASTContext().getLangOpts());
+  if (auto Args = getTemplateSpecializationArgLocs(ND))
+printTemplateArgumentList(OS, *Args, Policy);

Eugene.Zelenko wrote:
> Return type is not obvious, so auto should not be used.
nit: I'd suggest keeping `{}` for symmetry.



Comment at: clang-tools-extra/clangd/AST.cpp:133
+printTemplateArgumentList(OS, *Args, Policy);
+  else if (auto *Cls = llvm::dyn_cast(&ND)) {
+if (const TypeSourceInfo *TSI = Cls->getTypeAsWritten()) {

why isn't this handled in `getTemplateSpecializationArgLocs`? Add a comment?



Comment at: clang-tools-extra/clangd/AST.cpp:134
+  else if (auto *Cls = llvm::dyn_cast(&ND)) {
+if (const TypeSourceInfo *TSI = Cls->getTypeAsWritten()) {
+  auto STL = TSI->getTypeLoc().getAs();

could you add comment/example explaining what's special about this case?



Comment at: clang-tools-extra/clangd/AST.h:54
+/// Returns an empty string if type is not a template specialization.
+std::string printTemplateArgsAsWritten(const NamedDecl &ND);
+

Maybe `printTemplateSpecializationArgs` since we are only handling template 
specialization? 

I think we could drop `AsWritten` from the name. It should be clear to just 
explain in the comment.  



Comment at: clang-tools-extra/unittests/clangd/ASTUtilsTests.cpp:16
+
+TEST(ASTUtils, PrintTemplateArgs) {
+  Annotations Test(R"cpp(

I think this kind of tests would be more readable using `TEST_P` [1] with code 
and expected arguments as parameters.

Up to you though.

[1] 
https://github.com/google/googletest/blob/master/googletest/docs/advanced.md#specifying-names-for-value-parameterized-test-parameters



Comment at: clang/lib/AST/TypePrinter.cpp:1635
 
+static void printArgument(const TemplateArgument &A, const PrintingPolicy &PP,
+  llvm::raw_ostream &OS) {

could you add clang tests for these changes?



Comment at: clang/lib/AST/TypePrinter.cpp:1643
+  const auto &Kind = A.getArgument().getKind();
+  assert(Kind != TemplateArgument::Null &&
+ "TemplateArgumentKind can not be null!");

why? 

```
/// Represents an empty template argument, e.g., one that has not
/// been deduced.
```
It seems legitimate. 

Since this hot code path, we would want to avoid hard assertion if possible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59639



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


[PATCH] D59640: [clangd] Add TemplateArgumentList into Symbol

2019-03-21 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

should we update YAML?




Comment at: clang-tools-extra/clangd/index/Symbol.h:48
+  /// non-specializations. Example: ""
+  llvm::StringRef TemplateArgumentList;
   /// The location of the symbol's definition, if one was found.

How about  `TemplateSpecializationArgs`? 

Could you also put this field near `ReturnType` or `Signature`? 



Comment at: clang-tools-extra/clangd/index/SymbolCollector.cpp:526
   S.ID = std::move(ID);
+  std::string TemplateArgumentList = printTemplateArgsAsWritten(ND);
+  S.TemplateArgumentList = TemplateArgumentList;

put this near `ReturnType` initialization.



Comment at: clang-tools-extra/unittests/clangd/SymbolCollectorTests.cpp:396
 
 TEST_F(SymbolCollectorTest, Template) {
   Annotations Header(R"(

this test is getting hard to read. could you only make minimum change to the 
existing test and add a new case for the new behavior?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59640



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


r356689 - [X86] Add __popcntd and __popcntq to ia32intrin.h to match gcc and icc. Remove popcnt feature flag from _popcnt32/_popcnt64 and move to ia32intrin.h to match gcc

2019-03-21 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Thu Mar 21 10:43:53 2019
New Revision: 356689

URL: http://llvm.org/viewvc/llvm-project?rev=356689&view=rev
Log:
[X86] Add __popcntd and __popcntq to ia32intrin.h to match gcc and icc. Remove 
popcnt feature flag from _popcnt32/_popcnt64 and move to ia32intrin.h to match 
gcc

gcc and icc both implement popcntd and popcntq which we did not. gcc doesn't 
seem to require a feature flag for the _popcnt32/_popcnt64 spelling and will 
use a libcall if its not supported.

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

Modified:
cfe/trunk/lib/Headers/ia32intrin.h
cfe/trunk/lib/Headers/popcntintrin.h
cfe/trunk/test/CodeGen/popcnt-builtins.c

Modified: cfe/trunk/lib/Headers/ia32intrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/ia32intrin.h?rev=356689&r1=356688&r2=356689&view=diff
==
--- cfe/trunk/lib/Headers/ia32intrin.h (original)
+++ cfe/trunk/lib/Headers/ia32intrin.h Thu Mar 21 10:43:53 2019
@@ -28,6 +28,48 @@
 #ifndef __IA32INTRIN_H
 #define __IA32INTRIN_H
 
+/** Counts the number of bits in the source operand having a value of 1.
+ *
+ *  \headerfile 
+ *
+ *  This intrinsic corresponds to the  POPCNT  instruction or a
+ *  a sequence of arithmetic and logic ops to calculate it.
+ *
+ *  \param __A
+ * An unsigned 32-bit integer operand.
+ *  \returns A 32-bit integer containing the number of bits with value 1 in the
+ * source operand.
+ */
+static __inline__ int __attribute__((__always_inline__, __nodebug__))
+__popcntd(unsigned int __A)
+{
+  return __builtin_popcount(__A);
+}
+
+#define _popcnt32(A) __popcntd((A))
+
+#ifdef __x86_64__
+/** Counts the number of bits in the source operand having a value of 1.
+ *
+ *  \headerfile 
+ *
+ *  This intrinsic corresponds to the  POPCNT  instruction or a
+ *  a sequence of arithmetic and logic ops to calculate it.
+ *
+ *  \param __A
+ * An unsigned 64-bit integer operand.
+ *  \returns A 64-bit integer containing the number of bits with value 1 in the
+ * source operand.
+ */
+static __inline__ long long __attribute__((__always_inline__, __nodebug__))
+__popcntq(unsigned long long __A)
+{
+  return __builtin_popcountll(__A);
+}
+
+#define _popcnt64(A) __popcntq((A))
+#endif /* __x86_64__ */
+
 #ifdef __x86_64__
 static __inline__ unsigned long long __attribute__((__always_inline__, 
__nodebug__))
 __readeflags(void)

Modified: cfe/trunk/lib/Headers/popcntintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/popcntintrin.h?rev=356689&r1=356688&r2=356689&view=diff
==
--- cfe/trunk/lib/Headers/popcntintrin.h (original)
+++ cfe/trunk/lib/Headers/popcntintrin.h Thu Mar 21 10:43:53 2019
@@ -43,22 +43,6 @@ _mm_popcnt_u32(unsigned int __A)
   return __builtin_popcount(__A);
 }
 
-/// Counts the number of bits in the source operand having a value of 1.
-///
-/// \headerfile 
-///
-/// This intrinsic corresponds to the  POPCNT  instruction.
-///
-/// \param __A
-///A signed 32-bit integer operand.
-/// \returns A 32-bit integer containing the number of bits with value 1 in the
-///source operand.
-static __inline__ int __DEFAULT_FN_ATTRS
-_popcnt32(int __A)
-{
-  return __builtin_popcount(__A);
-}
-
 #ifdef __x86_64__
 /// Counts the number of bits in the source operand having a value of 1.
 ///
@@ -75,22 +59,6 @@ _mm_popcnt_u64(unsigned long long __A)
 {
   return __builtin_popcountll(__A);
 }
-
-/// Counts the number of bits in the source operand having a value of 1.
-///
-/// \headerfile 
-///
-/// This intrinsic corresponds to the  POPCNT  instruction.
-///
-/// \param __A
-///A signed 64-bit integer operand.
-/// \returns A 64-bit integer containing the number of bits with value 1 in the
-///source operand.
-static __inline__ long long __DEFAULT_FN_ATTRS
-_popcnt64(long long __A)
-{
-  return __builtin_popcountll(__A);
-}
 #endif /* __x86_64__ */
 
 #undef __DEFAULT_FN_ATTRS

Modified: cfe/trunk/test/CodeGen/popcnt-builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/popcnt-builtins.c?rev=356689&r1=356688&r2=356689&view=diff
==
--- cfe/trunk/test/CodeGen/popcnt-builtins.c (original)
+++ cfe/trunk/test/CodeGen/popcnt-builtins.c Thu Mar 21 10:43:53 2019
@@ -1,24 +1,39 @@
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +popcnt -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +popcnt -emit-llvm -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-POPCNT
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o 
- | FileCheck %s
 
 
-#include 
+#include 
 
-unsigned int test_mm_popcnt_u32(unsigned int __X) {
-  //CHECK: call i32 @llvm.ctpop.i32
+#ifdef __POPCNT__
+int test_mm_popcnt_u32(unsigned

[PATCH] D59567: [X86] Add __popcntd and __popcntq to ia32intrin.h to match gcc and icc. Remove popcnt feature flag from _popcnt32/_popcnt64 and move to ia32intrin.h to match gcc

2019-03-21 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC356689: [X86] Add __popcntd and __popcntq to ia32intrin.h to 
match gcc and icc. Remove… (authored by ctopper, committed by ).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D59567?vs=191625&id=191742#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D59567

Files:
  lib/Headers/ia32intrin.h
  lib/Headers/popcntintrin.h
  test/CodeGen/popcnt-builtins.c

Index: test/CodeGen/popcnt-builtins.c
===
--- test/CodeGen/popcnt-builtins.c
+++ test/CodeGen/popcnt-builtins.c
@@ -1,24 +1,39 @@
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +popcnt -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +popcnt -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-POPCNT
+// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
 
 
-#include 
+#include 
 
-unsigned int test_mm_popcnt_u32(unsigned int __X) {
-  //CHECK: call i32 @llvm.ctpop.i32
+#ifdef __POPCNT__
+int test_mm_popcnt_u32(unsigned int __X) {
+  //CHECK-POPCNT: call i32 @llvm.ctpop.i32
   return _mm_popcnt_u32(__X);
 }
+#endif
 
-unsigned int test_popcnt_32(int __X) {
+int test_popcnt32(unsigned int __X) {
   //CHECK: call i32 @llvm.ctpop.i32
   return _popcnt32(__X);
 }
 
-unsigned long long test_mm_popcnt_u64(unsigned long long __X) {
-  //CHECK: call i64 @llvm.ctpop.i64
+int test__popcntd(unsigned int __X) {
+  //CHECK: call i32 @llvm.ctpop.i32
+  return __popcntd(__X);
+}
+
+#ifdef __POPCNT__
+long long test_mm_popcnt_u64(unsigned long long __X) {
+  //CHECK-POPCNT: call i64 @llvm.ctpop.i64
   return _mm_popcnt_u64(__X);
 }
+#endif
 
-unsigned long long test_popcnt_64(long long __X) {
+long long test_popcnt64(unsigned long long __X) {
   //CHECK: call i64 @llvm.ctpop.i64
   return _popcnt64(__X);
 }
+
+long long test__popcntq(unsigned long long __X) {
+  //CHECK: call i64 @llvm.ctpop.i64
+  return __popcntq(__X);
+}
Index: lib/Headers/popcntintrin.h
===
--- lib/Headers/popcntintrin.h
+++ lib/Headers/popcntintrin.h
@@ -43,22 +43,6 @@
   return __builtin_popcount(__A);
 }
 
-/// Counts the number of bits in the source operand having a value of 1.
-///
-/// \headerfile 
-///
-/// This intrinsic corresponds to the  POPCNT  instruction.
-///
-/// \param __A
-///A signed 32-bit integer operand.
-/// \returns A 32-bit integer containing the number of bits with value 1 in the
-///source operand.
-static __inline__ int __DEFAULT_FN_ATTRS
-_popcnt32(int __A)
-{
-  return __builtin_popcount(__A);
-}
-
 #ifdef __x86_64__
 /// Counts the number of bits in the source operand having a value of 1.
 ///
@@ -75,22 +59,6 @@
 {
   return __builtin_popcountll(__A);
 }
-
-/// Counts the number of bits in the source operand having a value of 1.
-///
-/// \headerfile 
-///
-/// This intrinsic corresponds to the  POPCNT  instruction.
-///
-/// \param __A
-///A signed 64-bit integer operand.
-/// \returns A 64-bit integer containing the number of bits with value 1 in the
-///source operand.
-static __inline__ long long __DEFAULT_FN_ATTRS
-_popcnt64(long long __A)
-{
-  return __builtin_popcountll(__A);
-}
 #endif /* __x86_64__ */
 
 #undef __DEFAULT_FN_ATTRS
Index: lib/Headers/ia32intrin.h
===
--- lib/Headers/ia32intrin.h
+++ lib/Headers/ia32intrin.h
@@ -28,6 +28,48 @@
 #ifndef __IA32INTRIN_H
 #define __IA32INTRIN_H
 
+/** Counts the number of bits in the source operand having a value of 1.
+ *
+ *  \headerfile 
+ *
+ *  This intrinsic corresponds to the  POPCNT  instruction or a
+ *  a sequence of arithmetic and logic ops to calculate it.
+ *
+ *  \param __A
+ * An unsigned 32-bit integer operand.
+ *  \returns A 32-bit integer containing the number of bits with value 1 in the
+ * source operand.
+ */
+static __inline__ int __attribute__((__always_inline__, __nodebug__))
+__popcntd(unsigned int __A)
+{
+  return __builtin_popcount(__A);
+}
+
+#define _popcnt32(A) __popcntd((A))
+
+#ifdef __x86_64__
+/** Counts the number of bits in the source operand having a value of 1.
+ *
+ *  \headerfile 
+ *
+ *  This intrinsic corresponds to the  POPCNT  instruction or a
+ *  a sequence of arithmetic and logic ops to calculate it.
+ *
+ *  \param __A
+ * An unsigned 64-bit integer operand.
+ *  \returns A 64-bit integer containing the number of bits with value 1 in the
+ * source operand.
+ */
+static __inline__ long long __attribute__((__always_inline__, __nodebug__))
+__popcntq(unsigned long long __A)
+{
+  return __builtin_popcountll(__A);
+}
+
+#define _popcnt64(A) __popcntq((A))
+#endif /* __x86_64__ */
+
 #ifdef __x86_64__
 static _

[PATCH] D59639: [clangd] Print template arguments helper

2019-03-21 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: clang/lib/AST/TypePrinter.cpp:1640
+
+static void printArgument(const TemplateArgumentLoc &A,
+  const PrintingPolicy &PP, llvm::raw_ostream &OS) {

It's unclear to me what the new behavior is with changes in this file. Could 
you add comment?

It might make sense to split the clang change into a separate patch and get 
folks who are more familiar to take a look.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59639



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


[PATCH] D59655: [AArch64] Split the neon.addp intrinsic into integer and fp variants

2019-03-21 Thread Amara Emerson via Phabricator via cfe-commits
aemerson created this revision.
aemerson added reviewers: paquette, eli.friedman, t.p.northover.
aemerson added projects: LLVM, clang.
Herald added subscribers: Petar.Avramovic, hiraditya, kristof.beyls, 
javed.absar.

This is the result of discussions on the list about how to deal with intrinsics 
which require codegen to disambiguate them via only the integer/fp overloads. 
It causes problems for GlobalISel as some of that information is lost during 
translation, while with other operations like IR instructions the information 
is encoded into the instruction opcode.

This patch changes clang to emit the new faddp intrinsic if the vector operands 
to the builtin have FP element types. LLVM IR AutoUpgrade has been taught to 
upgrade existing calls to aarch64.neon.addp with fp vector arguments, and we 
remove the workarounds introduced for GlobalISel in r355865.

This is a more permanent solution to PR40968.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D59655

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-neon-intrinsics.c
  clang/test/CodeGen/aarch64-v8.2a-neon-intrinsics.c
  llvm/include/llvm/IR/IntrinsicsAArch64.td
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/lib/Target/AArch64/AArch64LegalizerInfo.cpp
  llvm/lib/Target/AArch64/AArch64LegalizerInfo.h
  llvm/test/CodeGen/AArch64/GlobalISel/fallback-ambiguous-addp-intrinsic.mir
  llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir
  llvm/test/CodeGen/AArch64/arm64-neon-add-pairwise.ll
  llvm/test/CodeGen/AArch64/arm64-vadd.ll
  llvm/test/CodeGen/AArch64/autoupgrade-aarch64-neon-addp-float.ll

Index: llvm/test/CodeGen/AArch64/autoupgrade-aarch64-neon-addp-float.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/autoupgrade-aarch64-neon-addp-float.ll
@@ -0,0 +1,10 @@
+; RUN: opt -S < %s -mtriple=arm64 | FileCheck %s
+declare <4 x float> @llvm.aarch64.neon.addp.v4f32(<4 x float>, <4 x float>)
+declare <4 x float> @llvm.aarch64.neon.faddp.v4f32(<4 x float>, <4 x float>)
+
+; CHECK: @llvm.aarch64.neon.faddp.v4f32
+define <4 x float> @upgrade_aarch64_neon_addp_float(<4 x float> %a, <4 x float> %b) {
+  %res = call <4 x float> @llvm.aarch64.neon.addp.v4f32(<4 x float> %a, <4 x float> %b)
+  ret <4 x float> %res
+}
+
Index: llvm/test/CodeGen/AArch64/arm64-vadd.ll
===
--- llvm/test/CodeGen/AArch64/arm64-vadd.ll
+++ llvm/test/CodeGen/AArch64/arm64-vadd.ll
@@ -712,7 +712,7 @@
 ;CHECK: faddp.2s
 %tmp1 = load <2 x float>, <2 x float>* %A
 %tmp2 = load <2 x float>, <2 x float>* %B
-%tmp3 = call <2 x float> @llvm.aarch64.neon.addp.v2f32(<2 x float> %tmp1, <2 x float> %tmp2)
+%tmp3 = call <2 x float> @llvm.aarch64.neon.faddp.v2f32(<2 x float> %tmp1, <2 x float> %tmp2)
 ret <2 x float> %tmp3
 }
 
@@ -721,7 +721,7 @@
 ;CHECK: faddp.4s
 %tmp1 = load <4 x float>, <4 x float>* %A
 %tmp2 = load <4 x float>, <4 x float>* %B
-%tmp3 = call <4 x float> @llvm.aarch64.neon.addp.v4f32(<4 x float> %tmp1, <4 x float> %tmp2)
+%tmp3 = call <4 x float> @llvm.aarch64.neon.faddp.v4f32(<4 x float> %tmp1, <4 x float> %tmp2)
 ret <4 x float> %tmp3
 }
 
@@ -730,13 +730,13 @@
 ;CHECK: faddp.2d
 %tmp1 = load <2 x double>, <2 x double>* %A
 %tmp2 = load <2 x double>, <2 x double>* %B
-%tmp3 = call <2 x double> @llvm.aarch64.neon.addp.v2f64(<2 x double> %tmp1, <2 x double> %tmp2)
+%tmp3 = call <2 x double> @llvm.aarch64.neon.faddp.v2f64(<2 x double> %tmp1, <2 x double> %tmp2)
 ret <2 x double> %tmp3
 }
 
-declare <2 x float> @llvm.aarch64.neon.addp.v2f32(<2 x float>, <2 x float>) nounwind readnone
-declare <4 x float> @llvm.aarch64.neon.addp.v4f32(<4 x float>, <4 x float>) nounwind readnone
-declare <2 x double> @llvm.aarch64.neon.addp.v2f64(<2 x double>, <2 x double>) nounwind readnone
+declare <2 x float> @llvm.aarch64.neon.faddp.v2f32(<2 x float>, <2 x float>) nounwind readnone
+declare <4 x float> @llvm.aarch64.neon.faddp.v4f32(<4 x float>, <4 x float>) nounwind readnone
+declare <2 x double> @llvm.aarch64.neon.faddp.v2f64(<2 x double>, <2 x double>) nounwind readnone
 
 define <2 x i64> @uaddl_duprhs(<4 x i32> %lhs, i32 %rhs) {
 ; CHECK-LABEL: uaddl_duprhs
Index: llvm/test/CodeGen/AArch64/arm64-neon-add-pairwise.ll
===
--- llvm/test/CodeGen/AArch64/arm64-neon-add-pairwise.ll
+++ llvm/test/CodeGen/AArch64/arm64-neon-add-pairwise.ll
@@ -65,27 +65,27 @@
 ret <2 x i64> %val
 }
 
-declare <2 x float> @llvm.aarch64.neon.addp.v2f32(<2 x float>, <2 x float>)
-declare <4 x float> @llvm.aarch64.neon.addp.v4f32(<4 x float>, <4 x float>)
-declare <2 x double> @llvm.aarch64.neon.addp.v2f64(<2 x double>, <2 x double>)
+declare <2 x float> @llvm.aarch64.neon.faddp.v2f32(<2 x float>, <2 x float>)
+d

[PATCH] D59624: [Driver] Pass -malign-double from the driver to the cc1 command line

2019-03-21 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


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

https://reviews.llvm.org/D59624



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


[PATCH] D59655: [AArch64] Split the neon.addp intrinsic into integer and fp variants

2019-03-21 Thread Amara Emerson via Phabricator via cfe-commits
aemerson updated this revision to Diff 191745.
aemerson added a comment.

Minor test tweak.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59655

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-neon-intrinsics.c
  clang/test/CodeGen/aarch64-v8.2a-neon-intrinsics.c
  llvm/include/llvm/IR/IntrinsicsAArch64.td
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/lib/Target/AArch64/AArch64LegalizerInfo.cpp
  llvm/lib/Target/AArch64/AArch64LegalizerInfo.h
  llvm/test/CodeGen/AArch64/GlobalISel/fallback-ambiguous-addp-intrinsic.mir
  llvm/test/CodeGen/AArch64/GlobalISel/legalizer-info-validation.mir
  llvm/test/CodeGen/AArch64/arm64-neon-add-pairwise.ll
  llvm/test/CodeGen/AArch64/arm64-vadd.ll
  llvm/test/CodeGen/AArch64/autoupgrade-aarch64-neon-addp-float.ll

Index: llvm/test/CodeGen/AArch64/autoupgrade-aarch64-neon-addp-float.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/autoupgrade-aarch64-neon-addp-float.ll
@@ -0,0 +1,9 @@
+; RUN: opt -S < %s -mtriple=arm64 | FileCheck %s
+declare <4 x float> @llvm.aarch64.neon.addp.v4f32(<4 x float>, <4 x float>)
+
+; CHECK: call <4 x float> @llvm.aarch64.neon.faddp.v4f32
+define <4 x float> @upgrade_aarch64_neon_addp_float(<4 x float> %a, <4 x float> %b) {
+  %res = call <4 x float> @llvm.aarch64.neon.addp.v4f32(<4 x float> %a, <4 x float> %b)
+  ret <4 x float> %res
+}
+
Index: llvm/test/CodeGen/AArch64/arm64-vadd.ll
===
--- llvm/test/CodeGen/AArch64/arm64-vadd.ll
+++ llvm/test/CodeGen/AArch64/arm64-vadd.ll
@@ -712,7 +712,7 @@
 ;CHECK: faddp.2s
 %tmp1 = load <2 x float>, <2 x float>* %A
 %tmp2 = load <2 x float>, <2 x float>* %B
-%tmp3 = call <2 x float> @llvm.aarch64.neon.addp.v2f32(<2 x float> %tmp1, <2 x float> %tmp2)
+%tmp3 = call <2 x float> @llvm.aarch64.neon.faddp.v2f32(<2 x float> %tmp1, <2 x float> %tmp2)
 ret <2 x float> %tmp3
 }
 
@@ -721,7 +721,7 @@
 ;CHECK: faddp.4s
 %tmp1 = load <4 x float>, <4 x float>* %A
 %tmp2 = load <4 x float>, <4 x float>* %B
-%tmp3 = call <4 x float> @llvm.aarch64.neon.addp.v4f32(<4 x float> %tmp1, <4 x float> %tmp2)
+%tmp3 = call <4 x float> @llvm.aarch64.neon.faddp.v4f32(<4 x float> %tmp1, <4 x float> %tmp2)
 ret <4 x float> %tmp3
 }
 
@@ -730,13 +730,13 @@
 ;CHECK: faddp.2d
 %tmp1 = load <2 x double>, <2 x double>* %A
 %tmp2 = load <2 x double>, <2 x double>* %B
-%tmp3 = call <2 x double> @llvm.aarch64.neon.addp.v2f64(<2 x double> %tmp1, <2 x double> %tmp2)
+%tmp3 = call <2 x double> @llvm.aarch64.neon.faddp.v2f64(<2 x double> %tmp1, <2 x double> %tmp2)
 ret <2 x double> %tmp3
 }
 
-declare <2 x float> @llvm.aarch64.neon.addp.v2f32(<2 x float>, <2 x float>) nounwind readnone
-declare <4 x float> @llvm.aarch64.neon.addp.v4f32(<4 x float>, <4 x float>) nounwind readnone
-declare <2 x double> @llvm.aarch64.neon.addp.v2f64(<2 x double>, <2 x double>) nounwind readnone
+declare <2 x float> @llvm.aarch64.neon.faddp.v2f32(<2 x float>, <2 x float>) nounwind readnone
+declare <4 x float> @llvm.aarch64.neon.faddp.v4f32(<4 x float>, <4 x float>) nounwind readnone
+declare <2 x double> @llvm.aarch64.neon.faddp.v2f64(<2 x double>, <2 x double>) nounwind readnone
 
 define <2 x i64> @uaddl_duprhs(<4 x i32> %lhs, i32 %rhs) {
 ; CHECK-LABEL: uaddl_duprhs
Index: llvm/test/CodeGen/AArch64/arm64-neon-add-pairwise.ll
===
--- llvm/test/CodeGen/AArch64/arm64-neon-add-pairwise.ll
+++ llvm/test/CodeGen/AArch64/arm64-neon-add-pairwise.ll
@@ -65,27 +65,27 @@
 ret <2 x i64> %val
 }
 
-declare <2 x float> @llvm.aarch64.neon.addp.v2f32(<2 x float>, <2 x float>)
-declare <4 x float> @llvm.aarch64.neon.addp.v4f32(<4 x float>, <4 x float>)
-declare <2 x double> @llvm.aarch64.neon.addp.v2f64(<2 x double>, <2 x double>)
+declare <2 x float> @llvm.aarch64.neon.faddp.v2f32(<2 x float>, <2 x float>)
+declare <4 x float> @llvm.aarch64.neon.faddp.v4f32(<4 x float>, <4 x float>)
+declare <2 x double> @llvm.aarch64.neon.faddp.v2f64(<2 x double>, <2 x double>)
 
 define <2 x float> @test_faddp_v2f32(<2 x float> %lhs, <2 x float> %rhs) {
 ; CHECK: test_faddp_v2f32:
-%val = call <2 x float> @llvm.aarch64.neon.addp.v2f32(<2 x float> %lhs, <2 x float> %rhs)
+%val = call <2 x float> @llvm.aarch64.neon.faddp.v2f32(<2 x float> %lhs, <2 x float> %rhs)
 ; CHECK: faddp v0.2s, v0.2s, v1.2s
 ret <2 x float> %val
 }
 
 define <4 x float> @test_faddp_v4f32(<4 x float> %lhs, <4 x float> %rhs) {
 ; CHECK: test_faddp_v4f32:
-%val = call <4 x float> @llvm.aarch64.neon.addp.v4f32(<4 x float> %lhs, <4 x float> %rhs)
+%val = call <4 x float> @llvm.aarch64.neon.faddp.v4f32(<4 x float> %lhs, <4 x flo

[PATCH] D59603: [PR40707][PR41011][OpenCL] Allow addr space spelling without double underscore in C++ mode

2019-03-21 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM.


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

https://reviews.llvm.org/D59603



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


[PATCH] D59656: [CodeGen][ObjC] Annotate calls to objc_retainAutoreleasedReturnValue with notail on x86-64

2019-03-21 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak created this revision.
ahatanak added reviewers: rjmccall, erik.pilkington.
ahatanak added a project: clang.
Herald added subscribers: dexonsmith, jkorous.

On x86-64, the epilogue code inserted before the tail jump blocks the 
autoreleased return optimization.

ARC optimizer unconditionally turns calls to 
`objc_retainAutoreleasedReturnValue` to tail calls. I plan to fix that too 
after this patch lands.

rdar://problem/38675807


Repository:
  rC Clang

https://reviews.llvm.org/D59656

Files:
  lib/CodeGen/CGObjC.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/CodeGen/TargetInfo.h
  test/CodeGenObjC/arc-blocks.m
  test/CodeGenObjC/arc-foreach.m
  test/CodeGenObjC/arc-literals.m
  test/CodeGenObjC/arc-precise-lifetime.m
  test/CodeGenObjC/arc-property.m
  test/CodeGenObjC/arc-related-result-type.m
  test/CodeGenObjC/arc-ternary-op.m
  test/CodeGenObjC/arc-unsafeclaim.m
  test/CodeGenObjC/arc-with-atthrow.m
  test/CodeGenObjC/arc.m
  test/CodeGenObjC/objc-arc-container-subscripting.m
  test/CodeGenObjC/os_log.m
  test/CodeGenObjCXX/arc-forwarded-lambda-call.mm
  test/CodeGenObjCXX/arc.mm
  test/CodeGenObjCXX/inheriting-constructor-cleanup.mm
  test/CodeGenObjCXX/literals.mm

Index: test/CodeGenObjCXX/literals.mm
===
--- test/CodeGenObjCXX/literals.mm
+++ test/CodeGenObjCXX/literals.mm
@@ -29,7 +29,7 @@
   // CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 1, i8* [[TMP_CAST]])
   // CHECK-NEXT: call void @_ZN1XC1Ev({{.*}} [[TMPX]])
   // CHECK-NEXT: [[OBJECT0:%[a-zA-Z0-9.]+]] = invoke i8* @_ZNK1XcvP11objc_objectEv
-  // CHECK: [[RET0:%[a-zA-Z0-9.]+]] = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[OBJECT0]])
+  // CHECK: [[RET0:%[a-zA-Z0-9.]+]] = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[OBJECT0]])
   // CHECK: store i8* [[RET0]], i8** [[ELEMENT0]]
   
   // Initializing the second element
@@ -38,7 +38,7 @@
   // CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 1, i8* [[TMP_CAST]])
   // CHECK-NEXT: invoke void @_ZN1YC1Ev({{.*}} [[TMPY]])
   // CHECK: [[OBJECT1:%[a-zA-Z0-9.]+]] = invoke i8* @_ZNK1YcvP11objc_objectEv
-  // CHECK: [[RET1:%[a-zA-Z0-9.]+]] = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[OBJECT1]])
+  // CHECK: [[RET1:%[a-zA-Z0-9.]+]] = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[OBJECT1]])
   // CHECK: store i8* [[RET1]], i8** [[ELEMENT1]]
 
   // Build the array
@@ -83,14 +83,14 @@
   // CHECK: [[ELEMENT0:%[a-zA-Z0-9.]+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS]], i64 0, i64 0
   // CHECK: call void @_ZN1XC1Ev
   // CHECK-NEXT: [[OBJECT0:%[a-zA-Z0-9.]+]] = invoke i8* @_ZNK1XcvP11objc_objectEv
-  // CHECK: [[RET0:%[a-zA-Z0-9.]+]] = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[OBJECT0]])
+  // CHECK: [[RET0:%[a-zA-Z0-9.]+]] = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[OBJECT0]])
   // CHECK: store i8* [[RET0]], i8** [[ELEMENT0]]
   
   // Initializing the second element
   // CHECK: [[ELEMENT1:%[a-zA-Z0-9.]+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS]], i64 0, i64 1
   // CHECK: invoke void @_ZN1YC1Ev
   // CHECK: [[OBJECT1:%[a-zA-Z0-9.]+]] = invoke i8* @_ZNK1YcvP11objc_objectEv
-  // CHECK: [[RET1:%[a-zA-Z0-9.]+]] = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[OBJECT1]])
+  // CHECK: [[RET1:%[a-zA-Z0-9.]+]] = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[OBJECT1]])
   // CHECK: store i8* [[RET1]], i8** [[ELEMENT1]]
 
   // Build the array
Index: test/CodeGenObjCXX/inheriting-constructor-cleanup.mm
===
--- test/CodeGenObjCXX/inheriting-constructor-cleanup.mm
+++ test/CodeGenObjCXX/inheriting-constructor-cleanup.mm
@@ -23,7 +23,7 @@
 }
 // CHECK-LABEL: define void @_Z1fv
 // CHECK:   %[[TMP:.*]] = call i8* @_Z1gv()
-// CHECK:   {{.*}} = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %[[TMP]])
+// CHECK:   {{.*}} = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %[[TMP]])
 // CHECK:   call void (%struct.Base*, i8*, ...) @_ZN4BaseC2E6Strongz(%struct.Base* {{.*}}, i8* {{.*}})
 // CHECK-NEXT:  call void @_ZN9InheritorD1Ev(%struct.Inheritor* {{.*}})
 
Index: test/CodeGenObjCXX/arc.mm
===
--- test/CodeGenObjCXX/arc.mm
+++ test/CodeGenObjCXX/arc.mm
@@ -20,7 +20,7 @@
   // TODO: in the non-volatile case, we do not need to be reloading.
 
   // CHECK:  [[T0:%.*]] = call i8* @_Z12test0_helperv()
-  // CHECK-NEXT: [[T1:%.*]] = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[T0]])
+  // CHECK-NEXT: [[T1:%.*]] = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[T0]])
   // CHECK-NEXT: [[T2:%.*]] = load i8**, i8*** {{%.*}}, align 8
   // CHECK-NEXT: [[T3:%.*]] = call i8* @llvm.objc.storeWeak(i8** [[T2]], i8* [[T1]])
   // CHECK-NEXT: [[T4:%.*]] = call i8* @llvm.objc.retain(i8* [[T3]])
@@ -29,7 +29,7 @@
   

[PATCH] D59656: [CodeGen][ObjC] Annotate calls to objc_retainAutoreleasedReturnValue with notail on x86-64

2019-03-21 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

There are existing test cases that test notail isn't added to calls on targets 
that aren't x86-64 (for example, test/CodeGenObjC/arc-arm.m), so I didn't write 
a new one.


Repository:
  rC Clang

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

https://reviews.llvm.org/D59656



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


[PATCH] D59647: [CUDA][HIP] Warn shared var initialization

2019-03-21 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

This looks like one of the things we should *not* do as it affects correctness 
-- non-trivial constructor may be arbitrarily complex and the per-TU flag to 
enable this behavior is way too coarse, IMO.
On the other hand, I can believe that someone somewhere did write the code and 
relies to NVCC accepting it.

Is there a specific use case for this, other than matching nvcc bug-for-bug?

I've added Justin and Richard as reviewers for the language-lawyering input.


Repository:
  rC Clang

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

https://reviews.llvm.org/D59647



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


[PATCH] D59647: [CUDA][HIP] Warn shared var initialization

2019-03-21 Thread Justin Lebar via Phabricator via cfe-commits
jlebar requested changes to this revision.
jlebar added a comment.
This revision now requires changes to proceed.

I agree with Art.  The fact that nvcc allows this is broken.

If you want a flag that makes this error a warning, that might work for me.  
The flag should probably say "unsafe" or "I promise I will not complain when 
this breaks me" or something to that effect.


Repository:
  rC Clang

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

https://reviews.llvm.org/D59647



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


[PATCH] D59647: [CUDA][HIP] Warn shared var initialization

2019-03-21 Thread Justin Lebar via Phabricator via cfe-commits
jlebar added a comment.

> By default it is still treated as error, therefore no behavior change of 
> clang.

Oh, I see, you already did what I'd suggested.  :)

That's better.  I think this needs to be made *much scarier* though.  "Maybe 
race condition" doesn't capture the danger here -- you can very quickly get UB.

Maybe Richard has thoughts on whether we should allow broken things like this.


Repository:
  rC Clang

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

https://reviews.llvm.org/D59647



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


[PATCH] D59655: [AArch64] Split the neon.addp intrinsic into integer and fp variants

2019-03-21 Thread Amara Emerson via Phabricator via cfe-commits
aemerson added a comment.

I've put up a langref change as a separate review: D59657 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59655



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


[PATCH] D59656: [CodeGen][ObjC] Annotate calls to objc_retainAutoreleasedReturnValue with notail on x86-64

2019-03-21 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/TargetInfo.h:161
+  /// marked as 'notail'.
+  virtual bool noTailCallARCRetainRV() const {
+return false;

`shouldSuppressTailCallsOfRetainAutoreleasedReturnValue()`?


Repository:
  rC Clang

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

https://reviews.llvm.org/D59656



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


r356699 - [OPENMP]Simplify the check for the predefined allocators, NFC.

2019-03-21 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Mar 21 12:05:07 2019
New Revision: 356699

URL: http://llvm.org/viewvc/llvm-project?rev=356699&view=rev
Log:
[OPENMP]Simplify the check for the predefined allocators, NFC.

Previously implemented check required the reevaluation of the already
evaluated predefined allocator kind for the global variables. Patch
simplifies this evaluation and removes extra code.

Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=356699&r1=356698&r2=356699&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Thu Mar 21 12:05:07 2019
@@ -2219,35 +2219,22 @@ getAllocatorKind(Sema &S, DSAStackTy *St
 return OMPAllocateDeclAttr::OMPDefaultMemAlloc;
   if (Allocator->isTypeDependent() || Allocator->isValueDependent() ||
   Allocator->isInstantiationDependent() ||
-  Allocator->containsUnexpandedParameterPack() ||
-  !Allocator->isEvaluatable(S.getASTContext()))
+  Allocator->containsUnexpandedParameterPack())
 return OMPAllocateDeclAttr::OMPUserDefinedMemAlloc;
-  bool Suppress = S.getDiagnostics().getSuppressAllDiagnostics();
-  S.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true);
   auto AllocatorKindRes = OMPAllocateDeclAttr::OMPUserDefinedMemAlloc;
   for (int I = OMPAllocateDeclAttr::OMPDefaultMemAlloc;
I < OMPAllocateDeclAttr::OMPUserDefinedMemAlloc; ++I) {
 auto AllocatorKind = static_cast(I);
 Expr *DefAllocator = Stack->getAllocator(AllocatorKind);
-// Compare allocator with the predefined allocator and if true - return
-// predefined allocator kind.
-ExprResult DefAllocRes = S.DefaultLvalueConversion(DefAllocator);
-ExprResult AllocRes = S.DefaultLvalueConversion(Allocator);
-ExprResult CompareRes = S.CreateBuiltinBinOp(
-Allocator->getExprLoc(), BO_EQ, DefAllocRes.get(), AllocRes.get());
-if (!CompareRes.isUsable())
-  continue;
-bool Result;
-if (!CompareRes.get()->EvaluateAsBooleanCondition(Result,
-  S.getASTContext()))
-  continue;
-if (Result) {
+const Expr *AE = Allocator->IgnoreParenImpCasts();
+llvm::FoldingSetNodeID AEId, DAEId;
+AE->Profile(AEId, S.getASTContext(), /*Canonical=*/true);
+DefAllocator->Profile(DAEId, S.getASTContext(), /*Canonical=*/true);
+if (AEId == DAEId) {
   AllocatorKindRes = AllocatorKind;
   break;
 }
-
   }
-  S.getDiagnostics().setSuppressAllDiagnostics(Suppress);
   return AllocatorKindRes;
 }
 
@@ -2325,26 +2312,7 @@ Sema::DeclGroupPtrTy Sema::ActOnOpenMPAl
 // allocator clause must be a constant expression that evaluates to one of
 // the predefined memory allocator values.
 if (Allocator && VD->hasGlobalStorage()) {
-  bool IsPredefinedAllocator = false;
-  if (const auto *DRE =
-  dyn_cast(Allocator->IgnoreParenImpCasts())) {
-if (DRE->getType().isConstant(getASTContext())) {
-  DeclarationName DN = DRE->getDecl()->getDeclName();
-  if (DN.isIdentifier()) {
-StringRef PredefinedAllocators[] = {
-"omp_default_mem_alloc", "omp_large_cap_mem_alloc",
-"omp_const_mem_alloc",   "omp_high_bw_mem_alloc",
-"omp_low_lat_mem_alloc", "omp_cgroup_mem_alloc",
-"omp_pteam_mem_alloc",   "omp_thread_mem_alloc",
-};
-IsPredefinedAllocator =
-llvm::any_of(PredefinedAllocators, [&DN](StringRef S) {
-  return DN.getAsIdentifierInfo()->isStr(S);
-});
-  }
-}
-  }
-  if (!IsPredefinedAllocator) {
+  if (AllocatorKind == OMPAllocateDeclAttr::OMPUserDefinedMemAlloc) {
 Diag(Allocator->getExprLoc(),
  diag::err_omp_expected_predefined_allocator)
 << Allocator->getSourceRange();


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


r356700 - [clang][OpenMP] Fix another test when using libgomp.

2019-03-21 Thread Jordan Rupprecht via cfe-commits
Author: rupprecht
Date: Thu Mar 21 12:13:22 2019
New Revision: 356700

URL: http://llvm.org/viewvc/llvm-project?rev=356700&view=rev
Log:
[clang][OpenMP] Fix another test when using libgomp.

Similarly to r356614, -fopenmp=libomp needs to be used for some omp-related AST 
matching.

Modified:
cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h

Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h?rev=356700&r1=356699&r2=356700&view=diff
==
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h Thu Mar 21 12:13:22 2019
@@ -237,13 +237,13 @@ testing::AssertionResult notMatchesWithC
 template 
 testing::AssertionResult matchesWithOpenMP(const std::string &Code,
const T &AMatcher) {
-  return matchesConditionally(Code, AMatcher, true, "-fopenmp");
+  return matchesConditionally(Code, AMatcher, true, "-fopenmp=libomp");
 }
 
 template 
 testing::AssertionResult notMatchesWithOpenMP(const std::string &Code,
   const T &AMatcher) {
-  return matchesConditionally(Code, AMatcher, false, "-fopenmp");
+  return matchesConditionally(Code, AMatcher, false, "-fopenmp=libomp");
 }
 
 template 


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


[PATCH] D59656: [CodeGen][ObjC] Annotate calls to objc_retainAutoreleasedReturnValue with notail on x86-64

2019-03-21 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 191761.
ahatanak marked an inline comment as done.
ahatanak added a comment.

Rename function.


Repository:
  rC Clang

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

https://reviews.llvm.org/D59656

Files:
  lib/CodeGen/CGObjC.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/CodeGen/TargetInfo.h
  test/CodeGenObjC/arc-blocks.m
  test/CodeGenObjC/arc-foreach.m
  test/CodeGenObjC/arc-literals.m
  test/CodeGenObjC/arc-precise-lifetime.m
  test/CodeGenObjC/arc-property.m
  test/CodeGenObjC/arc-related-result-type.m
  test/CodeGenObjC/arc-ternary-op.m
  test/CodeGenObjC/arc-unsafeclaim.m
  test/CodeGenObjC/arc-with-atthrow.m
  test/CodeGenObjC/arc.m
  test/CodeGenObjC/objc-arc-container-subscripting.m
  test/CodeGenObjC/os_log.m
  test/CodeGenObjCXX/arc-forwarded-lambda-call.mm
  test/CodeGenObjCXX/arc.mm
  test/CodeGenObjCXX/inheriting-constructor-cleanup.mm
  test/CodeGenObjCXX/literals.mm

Index: test/CodeGenObjCXX/literals.mm
===
--- test/CodeGenObjCXX/literals.mm
+++ test/CodeGenObjCXX/literals.mm
@@ -29,7 +29,7 @@
   // CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 1, i8* [[TMP_CAST]])
   // CHECK-NEXT: call void @_ZN1XC1Ev({{.*}} [[TMPX]])
   // CHECK-NEXT: [[OBJECT0:%[a-zA-Z0-9.]+]] = invoke i8* @_ZNK1XcvP11objc_objectEv
-  // CHECK: [[RET0:%[a-zA-Z0-9.]+]] = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[OBJECT0]])
+  // CHECK: [[RET0:%[a-zA-Z0-9.]+]] = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[OBJECT0]])
   // CHECK: store i8* [[RET0]], i8** [[ELEMENT0]]
   
   // Initializing the second element
@@ -38,7 +38,7 @@
   // CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 1, i8* [[TMP_CAST]])
   // CHECK-NEXT: invoke void @_ZN1YC1Ev({{.*}} [[TMPY]])
   // CHECK: [[OBJECT1:%[a-zA-Z0-9.]+]] = invoke i8* @_ZNK1YcvP11objc_objectEv
-  // CHECK: [[RET1:%[a-zA-Z0-9.]+]] = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[OBJECT1]])
+  // CHECK: [[RET1:%[a-zA-Z0-9.]+]] = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[OBJECT1]])
   // CHECK: store i8* [[RET1]], i8** [[ELEMENT1]]
 
   // Build the array
@@ -83,14 +83,14 @@
   // CHECK: [[ELEMENT0:%[a-zA-Z0-9.]+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS]], i64 0, i64 0
   // CHECK: call void @_ZN1XC1Ev
   // CHECK-NEXT: [[OBJECT0:%[a-zA-Z0-9.]+]] = invoke i8* @_ZNK1XcvP11objc_objectEv
-  // CHECK: [[RET0:%[a-zA-Z0-9.]+]] = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[OBJECT0]])
+  // CHECK: [[RET0:%[a-zA-Z0-9.]+]] = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[OBJECT0]])
   // CHECK: store i8* [[RET0]], i8** [[ELEMENT0]]
   
   // Initializing the second element
   // CHECK: [[ELEMENT1:%[a-zA-Z0-9.]+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[OBJECTS]], i64 0, i64 1
   // CHECK: invoke void @_ZN1YC1Ev
   // CHECK: [[OBJECT1:%[a-zA-Z0-9.]+]] = invoke i8* @_ZNK1YcvP11objc_objectEv
-  // CHECK: [[RET1:%[a-zA-Z0-9.]+]] = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[OBJECT1]])
+  // CHECK: [[RET1:%[a-zA-Z0-9.]+]] = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[OBJECT1]])
   // CHECK: store i8* [[RET1]], i8** [[ELEMENT1]]
 
   // Build the array
Index: test/CodeGenObjCXX/inheriting-constructor-cleanup.mm
===
--- test/CodeGenObjCXX/inheriting-constructor-cleanup.mm
+++ test/CodeGenObjCXX/inheriting-constructor-cleanup.mm
@@ -23,7 +23,7 @@
 }
 // CHECK-LABEL: define void @_Z1fv
 // CHECK:   %[[TMP:.*]] = call i8* @_Z1gv()
-// CHECK:   {{.*}} = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %[[TMP]])
+// CHECK:   {{.*}} = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %[[TMP]])
 // CHECK:   call void (%struct.Base*, i8*, ...) @_ZN4BaseC2E6Strongz(%struct.Base* {{.*}}, i8* {{.*}})
 // CHECK-NEXT:  call void @_ZN9InheritorD1Ev(%struct.Inheritor* {{.*}})
 
Index: test/CodeGenObjCXX/arc.mm
===
--- test/CodeGenObjCXX/arc.mm
+++ test/CodeGenObjCXX/arc.mm
@@ -20,7 +20,7 @@
   // TODO: in the non-volatile case, we do not need to be reloading.
 
   // CHECK:  [[T0:%.*]] = call i8* @_Z12test0_helperv()
-  // CHECK-NEXT: [[T1:%.*]] = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[T0]])
+  // CHECK-NEXT: [[T1:%.*]] = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[T0]])
   // CHECK-NEXT: [[T2:%.*]] = load i8**, i8*** {{%.*}}, align 8
   // CHECK-NEXT: [[T3:%.*]] = call i8* @llvm.objc.storeWeak(i8** [[T2]], i8* [[T1]])
   // CHECK-NEXT: [[T4:%.*]] = call i8* @llvm.objc.retain(i8* [[T3]])
@@ -29,7 +29,7 @@
   id x = *wp = test0_helper();
 
   // CHECK:  [[T0:%.*]] = call i8* @_Z12test0_helperv()
-  // CHECK-NEXT: [[T1:%.*]] = call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* [[T0]])
+  // CHECK-NEXT: [[T1:%.*]] = notail call i8* @llvm.objc.

[PATCH] D59655: [AArch64] Split the neon.addp intrinsic into integer and fp variants

2019-03-21 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: llvm/lib/IR/AutoUpgrade.cpp:574
+  if (ArgTy->getElementType()->isFloatingPointTy()) {
+auto fArgs = F->getFunctionType()->params();
+Type *Tys[] = {fArgs[0], fArgs[1]};

This code is weird... you're computing the types in two different ways.  Also, 
missing a check for F->arg_size() (so we don't crash on invalid IR).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59655



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


Re: r356700 - [clang][OpenMP] Fix another test when using libgomp.

2019-03-21 Thread Roman Lebedev via cfe-commits
Thank you for the fix.

I remembered of the yesterday's fix, but either forgot about it here,
or incorrectly recalled this code would be relying on the yesterday's code
(as in, no fix would be needed.)

Roman.

On Thu, Mar 21, 2019 at 10:11 PM Jordan Rupprecht via cfe-commits
 wrote:
>
> Author: rupprecht
> Date: Thu Mar 21 12:13:22 2019
> New Revision: 356700
>
> URL: http://llvm.org/viewvc/llvm-project?rev=356700&view=rev
> Log:
> [clang][OpenMP] Fix another test when using libgomp.
>
> Similarly to r356614, -fopenmp=libomp needs to be used for some omp-related 
> AST matching.
>
> Modified:
> cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h
>
> Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h?rev=356700&r1=356699&r2=356700&view=diff
> ==
> --- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h (original)
> +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h Thu Mar 21 12:13:22 2019
> @@ -237,13 +237,13 @@ testing::AssertionResult notMatchesWithC
>  template 
>  testing::AssertionResult matchesWithOpenMP(const std::string &Code,
> const T &AMatcher) {
> -  return matchesConditionally(Code, AMatcher, true, "-fopenmp");
> +  return matchesConditionally(Code, AMatcher, true, "-fopenmp=libomp");
>  }
>
>  template 
>  testing::AssertionResult notMatchesWithOpenMP(const std::string &Code,
>const T &AMatcher) {
> -  return matchesConditionally(Code, AMatcher, false, "-fopenmp");
> +  return matchesConditionally(Code, AMatcher, false, "-fopenmp=libomp");
>  }
>
>  template 
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59566: [X86] Correct the value of MaxAtomicInlineWidth for pre-586 cpus

2019-03-21 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

LGTM

> This is needed to get the LLONG_LOCK_FREE macro to be 2 on i586 and greater.

Not sure these tests are really valuable, given we plan to change that 
immediately after this is merged, but fine, I guess.


Repository:
  rC Clang

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

https://reviews.llvm.org/D59566



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


r356702 - [OPENMP]Codegen support for allocate directive on global variables.

2019-03-21 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Mar 21 12:35:27 2019
New Revision: 356702

URL: http://llvm.org/viewvc/llvm-project?rev=356702&view=rev
Log:
[OPENMP]Codegen support for allocate directive on global variables.

For the global variables the allocate directive must specify only the
predefined allocator. This allocator must be translated into the correct
form of the address space for the targets that support different address
spaces.

Added:
cfe/trunk/test/OpenMP/nvptx_allocate_codegen.cpp
Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
cfe/trunk/lib/CodeGen/CodeGenModule.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=356702&r1=356701&r2=356702&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Thu Mar 21 12:35:27 2019
@@ -8928,6 +8928,30 @@ void CGOpenMPRuntime::adjustTargetSpecif
  " Expected target-based directive.");
 }
 
+bool CGOpenMPRuntime::hasAllocateAttributeForGlobalVar(const VarDecl *VD,
+   LangAS &AS) {
+  if (!VD || !VD->hasAttr())
+return false;
+  const auto *A = VD->getAttr();
+  switch(A->getAllocatorType()) {
+  case OMPAllocateDeclAttr::OMPDefaultMemAlloc:
+  // Not supported, fallback to the default mem space.
+  case OMPAllocateDeclAttr::OMPLargeCapMemAlloc:
+  case OMPAllocateDeclAttr::OMPCGroupMemAlloc:
+  case OMPAllocateDeclAttr::OMPHighBWMemAlloc:
+  case OMPAllocateDeclAttr::OMPLowLatMemAlloc:
+  case OMPAllocateDeclAttr::OMPThreadMemAlloc:
+  case OMPAllocateDeclAttr::OMPConstMemAlloc:
+  case OMPAllocateDeclAttr::OMPPTeamMemAlloc:
+AS = LangAS::Default;
+return true;
+  case OMPAllocateDeclAttr::OMPUserDefinedMemAlloc:
+llvm_unreachable("Expected predefined allocator for the variables with the 
"
+ "static storage.");
+  }
+  return false;
+}
+
 CGOpenMPRuntime::DisableAutoDeclareTargetRAII::DisableAutoDeclareTargetRAII(
 CodeGenModule &CGM)
 : CGM(CGM) {

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h?rev=356702&r1=356701&r2=356702&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h Thu Mar 21 12:35:27 2019
@@ -1598,6 +1598,11 @@ public:
   /// Perform check on requires decl to ensure that target architecture
   /// supports unified addressing
   virtual void checkArchForUnifiedAddressing(const OMPRequiresDecl *D) const {}
+
+  /// Checks if the variable has associated OMPAllocateDeclAttr attribute with
+  /// the predefined allocator and translates it into the corresponding address
+  /// space.
+  virtual bool hasAllocateAttributeForGlobalVar(const VarDecl *VD, LangAS &AS);
 };
 
 /// Class supports emissionof SIMD-only code.

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp?rev=356702&r1=356701&r2=356702&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp Thu Mar 21 12:35:27 2019
@@ -4840,6 +4840,34 @@ unsigned CGOpenMPRuntimeNVPTX::getDefaul
   return CGM.getContext().getTargetAddressSpace(LangAS::cuda_constant);
 }
 
+bool CGOpenMPRuntimeNVPTX::hasAllocateAttributeForGlobalVar(const VarDecl *VD,
+LangAS &AS) {
+  if (!VD || !VD->hasAttr())
+return false;
+  const auto *A = VD->getAttr();
+  switch(A->getAllocatorType()) {
+  case OMPAllocateDeclAttr::OMPDefaultMemAlloc:
+  // Not supported, fallback to the default mem space.
+  case OMPAllocateDeclAttr::OMPThreadMemAlloc:
+  case OMPAllocateDeclAttr::OMPLargeCapMemAlloc:
+  case OMPAllocateDeclAttr::OMPCGroupMemAlloc:
+  case OMPAllocateDeclAttr::OMPHighBWMemAlloc:
+  case OMPAllocateDeclAttr::OMPLowLatMemAlloc:
+AS = LangAS::Default;
+return true;
+  case OMPAllocateDeclAttr::OMPConstMemAlloc:
+AS = LangAS::cuda_constant;
+return true;
+  case OMPAllocateDeclAttr::OMPPTeamMemAlloc:
+AS = LangAS::cuda_shared;
+return true;
+  case OMPAllocateDeclAttr::OMPUserDefinedMemAlloc:
+llvm_unreachable("Expected predefined allocator for the variables with the 
"
+ "static storage.");
+  }
+  return false;
+}
+
 // Get current CudaArch and ignore any unknown values
 static CudaArch getCudaArch(CodeGenModule &CGM) {
   if (!CGM.getTarget().hasFeature("ptx"))

Modified: cfe/trunk/

[PATCH] D59656: [CodeGen][ObjC] Annotate calls to objc_retainAutoreleasedReturnValue with notail on x86-64

2019-03-21 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rC Clang

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

https://reviews.llvm.org/D59656



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


r356704 - Refactor handling of #include directives to cleanly separate the

2019-03-21 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Mar 21 12:44:17 2019
New Revision: 356704

URL: http://llvm.org/viewvc/llvm-project?rev=356704&view=rev
Log:
Refactor handling of #include directives to cleanly separate the
"skipped header because it should be imported as a module" cases from
the "skipped header because of some other reason" cases.

Modified:
cfe/trunk/lib/Lex/PPDirectives.cpp

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=356704&r1=356703&r2=356704&view=diff
==
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Thu Mar 21 12:44:17 2019
@@ -1813,26 +1813,26 @@ void Preprocessor::HandleIncludeDirectiv
 return;
   }
 
-  // Should we enter the source file? Set to false if either the source file is
+  // Should we enter the source file? Set to Skip if either the source file is
   // known to have no effect beyond its effect on module visibility -- that is,
-  // if it's got an include guard that is already defined or is a modular 
header
-  // we've imported or already built.
-  bool ShouldEnter = true;
+  // if it's got an include guard that is already defined, set to Import if it
+  // is a modular header we've already built and should import.
+  enum { Enter, Import, Skip, IncludeLimitReached } Action = Enter;
 
   if (PPOpts->SingleFileParseMode)
-ShouldEnter = false;
+Action = IncludeLimitReached;
 
   // If we've reached the max allowed include depth, it is usually due to an
   // include cycle. Don't enter already processed files again as it can lead to
   // reaching the max allowed include depth again.
-  if (ShouldEnter && HasReachedMaxIncludeDepth && File &&
+  if (Action == Enter && HasReachedMaxIncludeDepth && File &&
   HeaderInfo.getFileInfo(File).NumIncludes)
-ShouldEnter = false;
+Action = IncludeLimitReached;
 
   // Determine whether we should try to import the module for this #include, if
   // there is one. Don't do so if precompiled module support is disabled or we
   // are processing this module textually (because we're building the module).
-  if (ShouldEnter && File && SuggestedModule && getLangOpts().Modules &&
+  if (Action == Enter && File && SuggestedModule && getLangOpts().Modules &&
   !isForModuleBuilding(SuggestedModule.getModule(),
getLangOpts().CurrentModule,
getLangOpts().ModuleName)) {
@@ -1872,9 +1872,9 @@ void Preprocessor::HandleIncludeDirectiv
 assert((Imported == nullptr || Imported == SuggestedModule.getModule()) &&
"the imported module is different than the suggested one");
 
-if (Imported)
-  ShouldEnter = false;
-else if (Imported.isMissingExpected()) {
+if (Imported) {
+  Action = Import;
+} else if (Imported.isMissingExpected()) {
   // We failed to find a submodule that we assumed would exist (because it
   // was in the directory of an umbrella header, for instance), but no
   // actual module containing it exists (because the umbrella header is
@@ -1907,13 +1907,18 @@ void Preprocessor::HandleIncludeDirectiv
 
   // Ask HeaderInfo if we should enter this #include file.  If not, #including
   // this file will have no effect.
-  bool SkipHeader = false;
-  if (ShouldEnter && File &&
+  if (Action == Enter && File &&
   !HeaderInfo.ShouldEnterIncludeFile(*this, File, isImport,
  getLangOpts().Modules,
  SuggestedModule.getModule())) {
-ShouldEnter = false;
-SkipHeader = true;
+// Even if we've already preprocessed this header once and know that we
+// don't need to see its contents again, we still need to import it if it's
+// modular because we might not have imported it from this submodule 
before.
+//
+// FIXME: We don't do this when compiling a PCH because the AST
+// serialization layer can't cope with it. This means we get local
+// submodule visibility semantics wrong in that case.
+Action = (SuggestedModule && !getLangOpts().CompilingPCH) ? Import : Skip;
   }
 
   if (Callbacks) {
@@ -1922,8 +1927,9 @@ void Preprocessor::HandleIncludeDirectiv
 HashLoc, IncludeTok,
 LangOpts.MSVCCompat ? NormalizedPath.c_str() : Filename, isAngled,
 FilenameRange, File, SearchPath, RelativePath,
-ShouldEnter ? nullptr : SuggestedModule.getModule(), FileCharacter);
-if (SkipHeader && !SuggestedModule.getModule())
+Action == Import ? SuggestedModule.getModule() : nullptr,
+FileCharacter);
+if (Action == Skip)
   Callbacks->FileSkipped(*File, FilenameTok, FileCharacter);
   }
 
@@ -1968,28 +1974,33 @@ void Preprocessor::HandleIncludeDirectiv
 }
   }
 
-  // If we don't need to enter the file, stop now.
-  if (!ShouldEnter) {
+  switch (Action) {
+  case Skip:
+// 

  1   2   >