[PATCH] D62373: [ASTImporter] Store import errors for Decls

2019-06-24 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:7851
+if (!getImportDeclErrorIfAny(FromD)) {
+  // Error encountered for the first time.
+  // After takeError the error is not usable any more in ToDOrErr.

martong wrote:
> a_sidorin wrote:
> > Is it possible to get this error more than once?
> Yes, that can happen in cyclic imports like: ClassTemplateDecl -> 
> TemplatedDecl -> ClassTemplateDecl.
I do not understand this completely, in this branch `setImportDeclError` is 
called so at next time we can not go into this branch again (for the same 
`FromD`). (We can get the error and not go into this branch more than once but 
get no error and go into the branch only once.)



Comment at: clang/unittests/AST/ASTImporterTest.cpp:4697
+DefaultTestValuesForRunOptions, );
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest,

a_sidorin wrote:
> #undef ERRONEOUSSTMT?
Maybe we should not use a macro for this, specially not define the macro inside 
the `struct` block. For the current tests it is sufficient to make a 
std::string that contains something like `void f() { asm(""); }`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62373



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


[PATCH] D63603: [ASTImporter] Propagate error from ImportDeclContext

2019-06-24 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/unittests/AST/ASTImporterTest.cpp:4743
+}
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ErrorHandlingTest,

Maybe add a similar test for namespace and check that the error is not 
propagated?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63603



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


Re: r364080 - [OPENMP]Fix PR42068: Vla type is not captured.

2019-06-24 Thread Alexey Bataev via cfe-commits
Thanks, will fix this ASAP.

Best regards,
Alexey Bataev

> 24 июня 2019 г., в 1:37, Yvan Roux  написал(а):
> 
> Hi Alexey,
> 
> This commit broke ARM bots, logs are availabale here:
> 
> http://lab.llvm.org:8011/builders/clang-cmake-armv8-quick/builds/13627/steps/ninja%20check%201/logs/FAIL%3A%20Clang%3A%3Aparallel_codegen.cpp
> 
> Thanks,
> Yvan
> 
> On Fri, 21 Jun 2019 at 19:25, Alexey Bataev via cfe-commits
>  wrote:
>> 
>> Author: abataev
>> Date: Fri Jun 21 10:28:41 2019
>> New Revision: 364080
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=364080&view=rev
>> Log:
>> [OPENMP]Fix PR42068: Vla type is not captured.
>> 
>> If the variably modified type is declared outside of the captured region
>> and then used in the cast expression along with array subscript
>> expression, the type is not captured and it leads to the compiler crash.
>> 
>> Modified:
>>cfe/trunk/lib/Sema/SemaExpr.cpp
>>cfe/trunk/test/OpenMP/parallel_codegen.cpp
>> 
>> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=364080&r1=364079&r2=364080&view=diff
>> ==
>> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Jun 21 10:28:41 2019
>> @@ -4737,6 +4737,33 @@ Sema::CreateBuiltinArraySubscriptExpr(Ex
>>   assert(VK == VK_RValue || LangOpts.CPlusPlus ||
>>  !ResultType.isCForbiddenLValueType());
>> 
>> +  if (LHSExp->IgnoreParenImpCasts()->getType()->isVariablyModifiedType() &&
>> +  FunctionScopes.size() > 1) {
>> +if (auto *TT =
>> +LHSExp->IgnoreParenImpCasts()->getType()->getAs()) 
>> {
>> +  for (auto I = FunctionScopes.rbegin(),
>> +E = std::prev(FunctionScopes.rend());
>> +   I != E; ++I) {
>> +auto *CSI = dyn_cast(*I);
>> +if (CSI == nullptr)
>> +  break;
>> +DeclContext *DC = nullptr;
>> +if (auto *LSI = dyn_cast(CSI))
>> +  DC = LSI->CallOperator;
>> +else if (auto *CRSI = dyn_cast(CSI))
>> +  DC = CRSI->TheCapturedDecl;
>> +else if (auto *BSI = dyn_cast(CSI))
>> +  DC = BSI->TheDecl;
>> +if (DC) {
>> +  if (DC->containsDecl(TT->getDecl()))
>> +break;
>> +  captureVariablyModifiedType(
>> +  Context, LHSExp->IgnoreParenImpCasts()->getType(), CSI);
>> +}
>> +  }
>> +}
>> +  }
>> +
>>   return new (Context)
>>   ArraySubscriptExpr(LHSExp, RHSExp, ResultType, VK, OK, RLoc);
>> }
>> 
>> Modified: cfe/trunk/test/OpenMP/parallel_codegen.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/parallel_codegen.cpp?rev=364080&r1=364079&r2=364080&view=diff
>> ==
>> --- cfe/trunk/test/OpenMP/parallel_codegen.cpp (original)
>> +++ cfe/trunk/test/OpenMP/parallel_codegen.cpp Fri Jun 21 10:28:41 2019
>> @@ -15,16 +15,20 @@
>> // CHECK-DEBUG-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* }
>> // CHECK-DEBUG-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] 
>> c";unknown;unknown;0;0;;\00"
>> // CHECK-DEBUG-DAG: [[DEF_LOC_2:@.+]] = private unnamed_addr global 
>> %struct.ident_t { i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds 
>> ([23 x i8], [23 x i8]* [[STR]], i32 0, i32 0) }
>> -// CHECK-DEBUG-DAG: [[LOC1:@.+]] = private unnamed_addr constant [{{.+}} x 
>> i8] c";{{.*}}parallel_codegen.cpp;main;[[@LINE+15]];1;;\00"
>> -// CHECK-DEBUG-DAG: [[LOC2:@.+]] = private unnamed_addr constant [{{.+}} x 
>> i8] c";{{.*}}parallel_codegen.cpp;tmain;[[@LINE+7]];1;;\00"
>> +// CHECK-DEBUG-DAG: [[LOC1:@.+]] = private unnamed_addr constant [{{.+}} x 
>> i8] c";{{.*}}parallel_codegen.cpp;main;[[@LINE+19]];1;;\00"
>> +// CHECK-DEBUG-DAG: [[LOC2:@.+]] = private unnamed_addr constant [{{.+}} x 
>> i8] c";{{.*}}parallel_codegen.cpp;tmain;[[@LINE+8]];1;;\00"
>> 
>> template 
>> void foo(T argc) {}
>> 
>> template 
>> int tmain(T argc) {
>> +  typedef double (*chunk_t)[argc[0][0]];
>> #pragma omp parallel
>> +  {
>>   foo(argc);
>> +  chunk_t var;(void)var[0][0];
>> +  }
>>   return 0;
>> }
>> 
>> @@ -90,7 +94,7 @@ int main (int argc, char **argv) {
>> 
>> // CHECK:   define linkonce_odr {{[a-z\_\b]*[ ]?i32}} [[TMAIN]](i8** 
>> %argc)
>> // CHECK:   store i8** %argc, i8*** [[ARGC_ADDR:%.+]],
>> -// CHECK-NEXT:  call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, 
>> ...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC_2]], i32 1, void 
>> (i32*, i32*, ...)* bitcast (void (i32*, i32*, i8***)* [[OMP_OUTLINED:@.+]] 
>> to void (i32*, i32*, ...)*), i8*** [[ARGC_ADDR]])
>> +// CHECK:   call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, 
>> ...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC_2]], i32 2, void 
>> (i32*, i32*, ...)* bitcast (void (i32*, i32*, i8***, i64)* 
>> [[OMP_OUTLINED:@.+]] to void (i32*, i32*, ...)*),

[PATCH] D63607: [DO NOT SUBMIT] [clang][driver] Prototype --driver-mode=fortran support for new flang

2019-06-24 Thread Peter Waller via Phabricator via cfe-commits
peterwaller-arm updated this revision to Diff 206172.
peterwaller-arm added a comment.

Include full context.


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

https://reviews.llvm.org/D63607

Files:
  clang/include/clang/Driver/Driver.h
  clang/include/clang/Driver/ToolChain.h
  clang/include/clang/Driver/Types.h
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/lib/Driver/ToolChains/Flang.h
  clang/lib/Driver/Types.cpp
  clang/tools/driver/CMakeLists.txt
  clang/tools/driver/driver.cpp

Index: clang/tools/driver/driver.cpp
===
--- clang/tools/driver/driver.cpp
+++ clang/tools/driver/driver.cpp
@@ -305,12 +305,24 @@
 
 static int ExecuteCC1Tool(ArrayRef argv, StringRef Tool) {
   void *GetExecutablePathVP = (void *)(intptr_t) GetExecutablePath;
-  if (Tool == "")
+  // DONOTSUBMIT(peterwaller-arm): Please note that changes to this logic are
+  // only to facilitate demonstrating that -fc1 is being invoked, and will not
+  // be submitted in a future implementation.
+  if (Tool == "-cc1")
 return cc1_main(argv.slice(2), argv[0], GetExecutablePathVP);
-  if (Tool == "as")
+  if (Tool == "-cc1as")
 return cc1as_main(argv.slice(2), argv[0], GetExecutablePathVP);
-  if (Tool == "gen-reproducer")
+  if (Tool == "-cc1gen-reproducer")
 return cc1gen_reproducer_main(argv.slice(2), argv[0], GetExecutablePathVP);
+  if (Tool == "-fc1") {
+llvm::errs() << "invoked flang frontend: ";
+for (auto arg : argv) {
+  llvm::errs() << arg << " ";
+}
+llvm::errs() << "\n";
+return 1;
+  }
+
 
   // Reject unknown tools.
   llvm::errs() << "error: unknown integrated tool '" << Tool << "'. "
@@ -372,13 +384,18 @@
   // file.
   auto FirstArg = std::find_if(argv.begin() + 1, argv.end(),
[](const char *A) { return A != nullptr; });
-  if (FirstArg != argv.end() && StringRef(*FirstArg).startswith("-cc1")) {
+  // DONOTSUBMIT(peterwaller-arm): Please note that changes to this logic are
+  // only to facilitate demonstrating that -fc1 is being invoked, and will not
+  // be submitted in a future implementation.
+  if (FirstArg != argv.end() && (
+StringRef(*FirstArg).startswith("-cc1") || StringRef(*FirstArg).startswith("-fc1")
+)) {
 // If -cc1 came from a response file, remove the EOL sentinels.
 if (MarkEOLs) {
   auto newEnd = std::remove(argv.begin(), argv.end(), nullptr);
   argv.resize(newEnd - argv.begin());
 }
-return ExecuteCC1Tool(argv, argv[1] + 4);
+return ExecuteCC1Tool(argv, argv[1]);
   }
 
   bool CanonicalPrefixes = true;
Index: clang/tools/driver/CMakeLists.txt
===
--- clang/tools/driver/CMakeLists.txt
+++ clang/tools/driver/CMakeLists.txt
@@ -63,7 +63,7 @@
 add_dependencies(clang clang-resource-headers)
 
 if(NOT CLANG_LINKS_TO_CREATE)
-  set(CLANG_LINKS_TO_CREATE clang++ clang-cl clang-cpp)
+  set(CLANG_LINKS_TO_CREATE clang++ clang-cl clang-cpp flang)
 endif()
 
 foreach(link ${CLANG_LINKS_TO_CREATE})
Index: clang/lib/Driver/Types.cpp
===
--- clang/lib/Driver/Types.cpp
+++ clang/lib/Driver/Types.cpp
@@ -187,6 +187,16 @@
   }
 }
 
+bool types::isFortran(ID Id) {
+  switch (Id) {
+  default:
+return false;
+
+  case TY_Fortran: case TY_PP_Fortran:
+return true;
+  }
+}
+
 bool types::isSrcFile(ID Id) {
   return Id != TY_Object && getPreprocessedType(Id) != TY_INVALID;
 }
Index: clang/lib/Driver/ToolChains/Flang.h
===
--- /dev/null
+++ clang/lib/Driver/ToolChains/Flang.h
@@ -0,0 +1,48 @@
+//===--- Flang.h - Flang Tool and ToolChain Implementations -*- C++ -*-===//
+//
+// 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
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_FLANG_H
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_FLANG_H
+
+#include "MSVC.h"
+#include "clang/Basic/DebugInfoOptions.h"
+#include "clang/Driver/Driver.h"
+#include "clang/Driver/Tool.h"
+#include "clang/Driver/Types.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/Option/Option.h"
+#include "llvm/Support/raw_ostream.h"
+
+namespace clang {
+namespace driver {
+
+namespace tools {
+
+/// Flang compiler tool.
+class LLVM_LIBRARY_VISIBILITY Flang : public Tool {
+public:
+  Flang(const ToolChain &TC);
+  ~Flang() override;
+
+  bool hasGoodDiagnostics() const override { return true; }
+  bool hasIntegratedAssembler() const override { return true; }
+  bool hasIntegratedCPP() const override { return true; }
+  bool canEmitIR() const override { retur

[PATCH] D62804: [clangd] Enable extraction of system includes from custom toolchains

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



Comment at: clang-tools-extra/clangd/ClangdLSPServer.cpp:345
 CompileCommandsDir);
+if (!ClangdServerOpts.QueryDriverGlobs.empty())
+  BaseCDB = getSystemIncludeExtractorDatabase(

if statement is not needed I think, as you return base if empty



Comment at: clang-tools-extra/clangd/SystemIncludeExtractor.cpp:1
+//===--- SystemIncludeExtractor.cpp --*- 
C++-*-===//
+//

This name is a little limiting (e.g. if we want to pull more info from the 
driver).

Not a big problem, but especially if you anticipate pulling out more 
properties, query-driver or similar might be clearer.



Comment at: clang-tools-extra/clangd/SystemIncludeExtractor.cpp:66
+  if (StartIt == Lines.end()) {
+elog("System include extraction: start marker not found.");
+return {};

also log output here?



Comment at: clang-tools-extra/clangd/SystemIncludeExtractor.cpp:91
+  if (!QueryDriverRegex.match(Driver)) {
+elog("System include extraction: not whitelisted driver {0}", Driver);
+return {};

This isn't an error - probably vlog, *maybe* log



Comment at: clang-tools-extra/clangd/SystemIncludeExtractor.cpp:143
+  }
+  log("System include extractor: succesfully executed {0}", Driver);
+

also include extracted includes - the info for this weird setup is important to 
preserve in the logs I think



Comment at: clang-tools-extra/clangd/SystemIncludeExtractor.cpp:152
+  for (llvm::StringRef Include : SystemIncludes) {
+Cmd.CommandLine.push_back("-isystem");
+Cmd.CommandLine.push_back(Include.str());

Technically this doesn't work if the command is `clang --driver-mode=cl ...` - 
you'll be able to query the info from clang using the default gcc-compatible 
syntax, but the actual command-line won't support the -isystem flag.

Not worth fixing I think but a comment?



Comment at: clang-tools-extra/clangd/SystemIncludeExtractor.cpp:254
+  assert(Base && "Null base to SystemIncludeExtractor");
+  return llvm::make_unique(QueryDriverGlobs,
+   std::move(Base));

docs says it returns base if globs are empty?



Comment at: clang-tools-extra/clangd/test/system-include-extractor.test:1
+# RUN: rm -rf %t.dir && mkdir -p %t.dir
+

Wow, I'm impressed you managed to test this :-)

Test needs quite a lot of comments to explain what it's doing though, I think.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62804



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


[PATCH] D63497: Add support for openSUSE RISC-V triple

2019-06-24 Thread Andreas Schwab via Phabricator via cfe-commits
schwab updated this revision to Diff 206173.

Repository:
  rC Clang

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

https://reviews.llvm.org/D63497

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  llvm/unittests/ADT/TripleTest.cpp


Index: llvm/unittests/ADT/TripleTest.cpp
===
--- llvm/unittests/ADT/TripleTest.cpp
+++ llvm/unittests/ADT/TripleTest.cpp
@@ -330,6 +330,12 @@
   EXPECT_EQ(Triple::FreeBSD, T.getOS());
   EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
 
+  T = Triple("riscv64-suse-linux");
+  EXPECT_EQ(Triple::riscv64, T.getArch());
+  EXPECT_EQ(Triple::SUSE, T.getVendor());
+  EXPECT_EQ(Triple::Linux, T.getOS());
+  EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
+
   T = Triple("armv7hl-suse-linux-gnueabi");
   EXPECT_EQ(Triple::arm, T.getArch());
   EXPECT_EQ(Triple::SUSE, T.getVendor());
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2021,7 +2021,8 @@
   static const char *const RISCV64LibDirs[] = {"/lib64", "/lib"};
   static const char *const RISCV64Triples[] = {"riscv64-unknown-linux-gnu",
"riscv64-linux-gnu",
-   "riscv64-unknown-elf"};
+   "riscv64-unknown-elf",
+   "riscv64-suse-linux"};
 
   static const char *const SPARCv8LibDirs[] = {"/lib32", "/lib"};
   static const char *const SPARCv8Triples[] = {"sparc-linux-gnu",


Index: llvm/unittests/ADT/TripleTest.cpp
===
--- llvm/unittests/ADT/TripleTest.cpp
+++ llvm/unittests/ADT/TripleTest.cpp
@@ -330,6 +330,12 @@
   EXPECT_EQ(Triple::FreeBSD, T.getOS());
   EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
 
+  T = Triple("riscv64-suse-linux");
+  EXPECT_EQ(Triple::riscv64, T.getArch());
+  EXPECT_EQ(Triple::SUSE, T.getVendor());
+  EXPECT_EQ(Triple::Linux, T.getOS());
+  EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
+
   T = Triple("armv7hl-suse-linux-gnueabi");
   EXPECT_EQ(Triple::arm, T.getArch());
   EXPECT_EQ(Triple::SUSE, T.getVendor());
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2021,7 +2021,8 @@
   static const char *const RISCV64LibDirs[] = {"/lib64", "/lib"};
   static const char *const RISCV64Triples[] = {"riscv64-unknown-linux-gnu",
"riscv64-linux-gnu",
-   "riscv64-unknown-elf"};
+   "riscv64-unknown-elf",
+   "riscv64-suse-linux"};
 
   static const char *const SPARCv8LibDirs[] = {"/lib32", "/lib"};
   static const char *const SPARCv8Triples[] = {"sparc-linux-gnu",
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62375: [ASTImporter] Mark erroneous nodes in from ctx

2019-06-24 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

Alexei,

I think I still owe you some explanation about this patch.
I do consider this patch as one of the most intricate patches regarding 
ASTImporter.
I'd like to answer the following questions in this comment:
What is an ImportPath and why do we need to track it?
What does it mean if we have a cycle in the import path?
How do we use these cycles during the error handling?

An ImportPath is the list of the AST nodes which we visit during an Import call.
If node `A` depends on node `B` then the path contains an `A`->`B` edge.
From the call stack of the import functions we can read the very same path.

Now imagine the following AST, where the `->` represents dependency in therms 
of the import.

  A->B->C->D
 `->E

We would like to import A.
The import behaves like a DFS, so we will visit the nodes in this order: ABCDE.
During the visitation we will have the following ImportPaths:

  A
  AB
  ABC
  ABCD
  ABC
  AB
  ABE
  AB
  A

If during the visit of E there is an error then we set an error for E, then as 
the call stack shrinks for B, then for A:

  A
  AB
  ABC
  ABCD
  ABC
  AB
  ABE // Error! Set an error to E
  AB  // Set an error to B
  A   // Set an error to A

However, during the import we could import C and D without any error and they 
are independent from A,B and E.
We must not set up an error for C and D.
So, at the end of the import we have an entry in `ImportDeclErrors` for A,B,E 
but not for C,D.

Now what happens if there is a cycle in the import path?
Let's consider this AST:

  A->B->C->A
 `->E

During the visitation we will have the below ImportPaths and if during the 
visit of E there is an error then we will set up an error for E,B,A.
But what's up with C?

  A
  AB
  ABC
  ABCA
  ABC
  AB
  ABE // Error! Set an error to E
  AB  // Set an error to B
  A   // Set an error to A

This time we know that both B and C are dependent on A.
This means we must set up an error for C too.
As the call stack reverses back we get to A and we must set up an error to all 
nodes which depend on A (this includes C).
But C is no longer on the import path, it just had been previously.
Such situation can happen only if during the visitation we had a cycle.
If we didn't have any cycle, then the normal way of passing an Error object 
through the call stack could handle the situation.
This is why we must track cycles during the import process for each visited 
declaration.

I hope this explanation makes it even cleaner than the tests and thanks again 
for the review!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62375



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


[PATCH] D63559: [clang-tidy] Added functionality for getting semantic highlights for variable and function declarations

2019-06-24 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom updated this revision to Diff 206178.
jvikstrom marked 18 inline comments as done.
jvikstrom added a comment.

Removed LSP specific stuff. Changed a bunch of types and names. Added fixme for 
macro expansion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63559

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/SemanticHighlight.cpp
  clang-tools-extra/clangd/SemanticHighlight.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/SemanticHighlightTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticHighlightTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/SemanticHighlightTests.cpp
@@ -0,0 +1,55 @@
+//===- SemanticHighlightTest.cpp - SemanticHighlightTest tests-*- C++ -* -===//
+//
+// 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 "Annotations.h"
+#include "ClangdUnit.h"
+#include "Protocol.h"
+#include "SemanticHighlight.h"
+#include "SourceCode.h"
+#include "TestTU.h"
+#include "llvm/Support/ScopedPrinter.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+using ::testing::ElementsAreArray;
+
+TEST(SemanticSymbolASTCollector, GetBeginningOfIdentifier) {
+  std::string Preamble = R"cpp(
+struct A {
+  double SomeMember;
+};
+void $foo[[foo]](int $a[[a]]) {
+  auto $vlvn[[VeryLongVariableName]] = 12312;
+  A $aa[[aa]];
+}
+  )cpp";
+
+  Annotations Test(Preamble);
+  auto Foo = Test.range("foo");
+  auto A = Test.range("a");
+  auto VeryLong = Test.range("vlvn");
+  auto AA = Test.range("aa");
+  std::vector CorrectTokens = std::vector{
+  SemanticToken(SemanticHighlightKind::Function, Foo),
+  SemanticToken(SemanticHighlightKind::Variable, A),
+  SemanticToken(SemanticHighlightKind::Variable, VeryLong),
+  SemanticToken(SemanticHighlightKind::Variable, AA)};
+
+  auto AST = TestTU::withCode(Test.code()).build();
+  auto Tokens = getSemanticHighlights(AST);
+
+  EXPECT_THAT(Tokens, ElementsAreArray(CorrectTokens));
+}
+
+} // namespace
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -53,6 +53,7 @@
   RenameTests.cpp
   RIFFTests.cpp
   SelectionTests.cpp
+  SemanticHighlightTests.cpp
   SerializationTests.cpp
   SourceCodeTests.cpp
   SymbolCollectorTests.cpp
Index: clang-tools-extra/clangd/SemanticHighlight.h
===
--- /dev/null
+++ clang-tools-extra/clangd/SemanticHighlight.h
@@ -0,0 +1,46 @@
+//==-- SemanticHighlight.h - Generating highlights from the AST--*- C++ -*-==//
+//
+// 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
+//
+//===--===//
+//
+// Code for collecting semantic symbols from the C++ AST using the
+// RecursiveASTVisitor
+//
+//===--===//
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SEMANTICHIGHLIGHT_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SEMANTICHIGHLIGHT_H
+
+#include "ClangdUnit.h"
+#include "Protocol.h"
+
+namespace clang {
+namespace clangd {
+
+enum class SemanticHighlightKind : int {
+  Variable = 0,
+  Function = 1,
+};
+
+// Contains all information needed for the highlighting a symbol.
+struct SemanticToken {
+  SemanticToken() = default;
+  SemanticToken(SemanticHighlightKind Kind, Range R) : Kind(Kind), R(R) {}
+  SemanticHighlightKind Kind;
+  Range R;
+};
+
+bool operator==(const SemanticToken &Lhs, const SemanticToken &Rhs);
+bool operator!=(const SemanticToken &Lhs, const SemanticToken &Rhs);
+
+// Returns semantic highlights for the AST. The vector is ordered in ascending
+// order by the line number. Every symbol in LineHighlight is ordered in
+// ascending order by their coumn number.
+std::vector getSemanticHighlights(ParsedAST &AST);
+
+} // namespace clangd
+} // namespace clang
+
+#endif
Index: clang-tools-extra/clangd/SemanticHighlight.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/SemanticHighlight.cpp
@@ -0,0 +1,79 @@
+#include "SemanticHighlight.h"
+#include "SourceCode.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/

[PATCH] D63559: [clang-tidy] Added functionality for getting semantic highlights for variable and function declarations

2019-06-24 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom marked 2 inline comments as done.
jvikstrom added inline comments.



Comment at: clang-tools-extra/clangd/SemanticHighlight.cpp:129
+std::vector> getSemanticScopes() {
+  return {{"variable"}, {"entity.name.function"}};
+}

hokein wrote:
> This is Textmate-specific, I think we should lift it to a new File 
> (TextMate.cpp). We can do it in a separate patch.
> 
> I'd use a map to explicitly express the relationship between `SemanticScope` 
> and TextMate scope, the current implementation is not obvious.
> 
> ```
> {SemanticScope::Function, "entity.name.function"},
> {SemanticScope::Variable, "variable.other"},
> ```
Will do this in CL when adding C++ ClangdServer api calls


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63559



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


[PATCH] D63426: [clangd] Narrow rename to local symbols.

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



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:69
+
+// Query the index to get other file where the Decl is referenced.
+llvm::Optional getOtherRefFile(const NamedDecl &Decl,

...to find some other file...



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:98
+
+// Check the symbol Decl is renameable, details are:
+//   1. symbol declared in the main file (not a header) => allow

Can we move these steps next to the associated code? The separate lists can be 
hard to maintain.

e.g. 
```
// If the symbol is in the main file (which is not a header), we can rename it
if (DeclaredInMainFile && !MainFileIsHeader)
  ...
```



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:99
+// Check the symbol Decl is renameable, details are:
+//   1. symbol declared in the main file (not a header) => allow
+//   2. symbol declared in the header

(which is not a header)



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:107
+llvm::Optional
+renamable(const NamedDecl &Decl, StringRef MainFile, const SymbolIndex *Index) 
{
+  auto &ASTCtx = Decl.getASTContext();

renamableWithinFile



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:110
+  const auto &SM = ASTCtx.getSourceManager();
+  bool MainFileIsHeader = llvm::sys::path::extension(MainFile) == ".h";
+  bool DeclaredInMainFile =

this isn't the right check - LangOpts::IsHeaderFile



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:115
+  bool DeclaredInHeader =
+  !DeclaredInMainFile || (DeclaredInMainFile && MainFileIsHeader);
+  if (!DeclaredInHeader)

can we avoid the double negative here? maybe just inline into the if



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:129
+return ReasonToReject::NonIndexable; // Case 2.2
+  // query index for xrefs. (not support for now)
+  auto OtherFile = getOtherRefFile(Decl, MainFile, *Index);

I can't parse "not support for now" - not sure this comment is necessary, the 
whole point of this function (with its current signature) is to reject this.



Comment at: clang-tools-extra/clangd/refactor/Rename.cpp:167
+return llvm::make_error(
+llvm::formatv("reject to rename: {0}", Message(*Reject)),
+llvm::inconvertibleErrorCode());

this is a user-visible error message, right?

- "reject to rename" doesn't have any obvious meaning to me. Maybe "Cannot 
rename symbol" ?
- "no index is provided" -> "symbol may be used in other files (no index 
available)"
- "the symbol is not indexable" -> "symbol may be used in other files (not 
eligible for indexing)"



Comment at: clang-tools-extra/clangd/refactor/Rename.h:21
 /// Occurrences outside the current file are not modified.
-llvm::Expected renameWithinFile(ParsedAST &AST,
-   llvm::StringRef File,
-   Position Pos,
-   llvm::StringRef 
NewName);
+/// Only support renaming symbols not being used outside the file.
+llvm::Expected

It's uncler what "only support" means here.
"Renaming a symbol that's used in another file (per the index) returns an error"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63426



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


r364174 - [OpenCL] Restore ATOMIC_VAR_INIT

2019-06-24 Thread Sven van Haastregt via cfe-commits
Author: svenvh
Date: Mon Jun 24 03:06:40 2019
New Revision: 364174

URL: http://llvm.org/viewvc/llvm-project?rev=364174&view=rev
Log:
[OpenCL] Restore ATOMIC_VAR_INIT

We accidentally lost the ATOMIC_VAR_INIT and ATOMIC_FLAG_INIT macros
in r363794.

Also put the `memory_order` typedef back inside a `>= CL2.0` guard.

Modified:
cfe/trunk/lib/Headers/opencl-c-base.h
cfe/trunk/test/Headers/opencl-c-header.cl

Modified: cfe/trunk/lib/Headers/opencl-c-base.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/opencl-c-base.h?rev=364174&r1=364173&r2=364174&view=diff
==
--- cfe/trunk/lib/Headers/opencl-c-base.h (original)
+++ cfe/trunk/lib/Headers/opencl-c-base.h Mon Jun 24 03:06:40 2019
@@ -297,8 +297,11 @@ typedef enum memory_scope {
  * image memory.
  */
 #define CLK_IMAGE_MEM_FENCE  0x04
-#endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0
 
+#ifndef ATOMIC_VAR_INIT
+#define ATOMIC_VAR_INIT(x) (x)
+#endif //ATOMIC_VAR_INIT
+#define ATOMIC_FLAG_INIT 0
 
 // enum values aligned with what clang uses in EmitAtomicExpr()
 typedef enum memory_order
@@ -310,6 +313,8 @@ typedef enum memory_order
   memory_order_seq_cst = __ATOMIC_SEQ_CST
 } memory_order;
 
+#endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0
+
 // OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14 - Image Read and Write 
Functions
 
 // These values need to match the runtime equivalent

Modified: cfe/trunk/test/Headers/opencl-c-header.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/opencl-c-header.cl?rev=364174&r1=364173&r2=364174&view=diff
==
--- cfe/trunk/test/Headers/opencl-c-header.cl (original)
+++ cfe/trunk/test/Headers/opencl-c-header.cl Mon Jun 24 03:06:40 2019
@@ -80,6 +80,10 @@ void test_atomics(__generic volatile uns
 }
 #endif
 
+// Verify that ATOMIC_VAR_INIT is defined.
+#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
+global atomic_int z = ATOMIC_VAR_INIT(99);
+#endif //__OPENCL_C_VERSION__
 
 // Verify that non-builtin cl_intel_planar_yuv extension is defined from
 // OpenCL 1.2 onwards.


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


r364173 - [OpenCL] Remove more duplicates from opencl-c.h

2019-06-24 Thread Sven van Haastregt via cfe-commits
Author: svenvh
Date: Mon Jun 24 03:06:34 2019
New Revision: 364173

URL: http://llvm.org/viewvc/llvm-project?rev=364173&view=rev
Log:
[OpenCL] Remove more duplicates from opencl-c.h

Identified the duplicate declarations using

  sort lib/Headers/opencl-c.h | uniq -c | grep '  2'

Modified:
cfe/trunk/lib/Headers/opencl-c.h

Modified: cfe/trunk/lib/Headers/opencl-c.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/opencl-c.h?rev=364173&r1=364172&r2=364173&view=diff
==
--- cfe/trunk/lib/Headers/opencl-c.h (original)
+++ cfe/trunk/lib/Headers/opencl-c.h Mon Jun 24 03:06:34 2019
@@ -9347,8 +9347,6 @@ long8 __ovld __cnfn clamp(long8 x, long8
 ulong8 __ovld __cnfn clamp(ulong8 x, ulong8 minval, ulong8 maxval);
 long16 __ovld __cnfn clamp(long16 x, long16 minval, long16 maxval);
 ulong16 __ovld __cnfn clamp(ulong16 x, ulong16 minval, ulong16 maxval);
-char __ovld __cnfn clamp(char x, char minval, char maxval);
-uchar __ovld __cnfn clamp(uchar x, uchar minval, uchar maxval);
 char2 __ovld __cnfn clamp(char2 x, char minval, char maxval);
 uchar2 __ovld __cnfn clamp(uchar2 x, uchar minval, uchar maxval);
 char3 __ovld __cnfn clamp(char3 x, char minval, char maxval);
@@ -9359,8 +9357,6 @@ char8 __ovld __cnfn clamp(char8 x, char
 uchar8 __ovld __cnfn clamp(uchar8 x, uchar minval, uchar maxval);
 char16 __ovld __cnfn clamp(char16 x, char minval, char maxval);
 uchar16 __ovld __cnfn clamp(uchar16 x, uchar minval, uchar maxval);
-short __ovld __cnfn clamp(short x, short minval, short maxval);
-ushort __ovld __cnfn clamp(ushort x, ushort minval, ushort maxval);
 short2 __ovld __cnfn clamp(short2 x, short minval, short maxval);
 ushort2 __ovld __cnfn clamp(ushort2 x, ushort minval, ushort maxval);
 short3 __ovld __cnfn clamp(short3 x, short minval, short maxval);
@@ -9371,8 +9367,6 @@ short8 __ovld __cnfn clamp(short8 x, sho
 ushort8 __ovld __cnfn clamp(ushort8 x, ushort minval, ushort maxval);
 short16 __ovld __cnfn clamp(short16 x, short minval, short maxval);
 ushort16 __ovld __cnfn clamp(ushort16 x, ushort minval, ushort maxval);
-int __ovld __cnfn clamp(int x, int minval, int maxval);
-uint __ovld __cnfn clamp(uint x, uint minval, uint maxval);
 int2 __ovld __cnfn clamp(int2 x, int minval, int maxval);
 uint2 __ovld __cnfn clamp(uint2 x, uint minval, uint maxval);
 int3 __ovld __cnfn clamp(int3 x, int minval, int maxval);
@@ -9383,8 +9377,6 @@ int8 __ovld __cnfn clamp(int8 x, int min
 uint8 __ovld __cnfn clamp(uint8 x, uint minval, uint maxval);
 int16 __ovld __cnfn clamp(int16 x, int minval, int maxval);
 uint16 __ovld __cnfn clamp(uint16 x, uint minval, uint maxval);
-long __ovld __cnfn clamp(long x, long minval, long maxval);
-ulong __ovld __cnfn clamp(ulong x, ulong minval, ulong maxval);
 long2 __ovld __cnfn clamp(long2 x, long minval, long maxval);
 ulong2 __ovld __cnfn clamp(ulong2 x, ulong minval, ulong maxval);
 long3 __ovld __cnfn clamp(long3 x, long minval, long maxval);
@@ -9660,8 +9652,6 @@ long8 __ovld __cnfn max(long8 x, long8 y
 ulong8 __ovld __cnfn max(ulong8 x, ulong8 y);
 long16 __ovld __cnfn max(long16 x, long16 y);
 ulong16 __ovld __cnfn max(ulong16 x, ulong16 y);
-char __ovld __cnfn max(char x, char y);
-uchar __ovld __cnfn max(uchar x, uchar y);
 char2 __ovld __cnfn max(char2 x, char y);
 uchar2 __ovld __cnfn max(uchar2 x, uchar y);
 char3 __ovld __cnfn max(char3 x, char y);
@@ -9672,8 +9662,6 @@ char8 __ovld __cnfn max(char8 x, char y)
 uchar8 __ovld __cnfn max(uchar8 x, uchar y);
 char16 __ovld __cnfn max(char16 x, char y);
 uchar16 __ovld __cnfn max(uchar16 x, uchar y);
-short __ovld __cnfn max(short x, short y);
-ushort __ovld __cnfn max(ushort x, ushort y);
 short2 __ovld __cnfn max(short2 x, short y);
 ushort2 __ovld __cnfn max(ushort2 x, ushort y);
 short3 __ovld __cnfn max(short3 x, short y);
@@ -9684,8 +9672,6 @@ short8 __ovld __cnfn max(short8 x, short
 ushort8 __ovld __cnfn max(ushort8 x, ushort y);
 short16 __ovld __cnfn max(short16 x, short y);
 ushort16 __ovld __cnfn max(ushort16 x, ushort y);
-int __ovld __cnfn max(int x, int y);
-uint __ovld __cnfn max(uint x, uint y);
 int2 __ovld __cnfn max(int2 x, int y);
 uint2 __ovld __cnfn max(uint2 x, uint y);
 int3 __ovld __cnfn max(int3 x, int y);
@@ -9696,8 +9682,6 @@ int8 __ovld __cnfn max(int8 x, int y);
 uint8 __ovld __cnfn max(uint8 x, uint y);
 int16 __ovld __cnfn max(int16 x, int y);
 uint16 __ovld __cnfn max(uint16 x, uint y);
-long __ovld __cnfn max(long x, long y);
-ulong __ovld __cnfn max(ulong x, ulong y);
 long2 __ovld __cnfn max(long2 x, long y);
 ulong2 __ovld __cnfn max(ulong2 x, ulong y);
 long3 __ovld __cnfn max(long3 x, long y);
@@ -9760,8 +9744,6 @@ long8 __ovld __cnfn min(long8 x, long8 y
 ulong8 __ovld __cnfn min(ulong8 x, ulong8 y);
 long16 __ovld __cnfn min(long16 x, long16 y);
 ulong16 __ovld __cnfn min(ulong16 x, ulong16 y);
-char __ovld __cnfn min(char x, char y);
-uchar __ovld __cnfn min(uchar x, uchar y);
 char

[PATCH] D63256: [OpenCL] Split type and macro definitions into opencl-c-base.h

2019-06-24 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh marked 3 inline comments as done.
svenvh added inline comments.



Comment at: cfe/trunk/lib/Headers/opencl-c.h:13638-13640
-#ifndef ATOMIC_VAR_INIT
-#define ATOMIC_VAR_INIT(x) (x)
-#endif //ATOMIC_VAR_INIT

yaxunl wrote:
> kzhuravl wrote:
> > Any reason this piece of code got completely removed?
> Removing ATOMIC_VAR_INIT caused regression in our compiler.
> 
> Could you please put it back?
> 
> Thanks.
Apologies, that was not intended; thanks for reporting!  Restored the macro in 
r364174 together with a test.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63256



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


[PATCH] D62373: [ASTImporter] Store import errors for Decls

2019-06-24 Thread Gabor Marton via Phabricator via cfe-commits
martong marked 4 inline comments as done.
martong added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:7851
+if (!getImportDeclErrorIfAny(FromD)) {
+  // Error encountered for the first time.
+  // After takeError the error is not usable any more in ToDOrErr.

balazske wrote:
> martong wrote:
> > a_sidorin wrote:
> > > Is it possible to get this error more than once?
> > Yes, that can happen in cyclic imports like: ClassTemplateDecl -> 
> > TemplatedDecl -> ClassTemplateDecl.
> I do not understand this completely, in this branch `setImportDeclError` is 
> called so at next time we can not go into this branch again (for the same 
> `FromD`). (We can get the error and not go into this branch more than once 
> but get no error and go into the branch only once.)
Yes, I missed that.
So, perhaps we can remove the condition `if (!getImportDeclErrorIfAny(FromD))` ?



Comment at: clang/unittests/AST/ASTImporterTest.cpp:4697
+DefaultTestValuesForRunOptions, );
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest,

balazske wrote:
> a_sidorin wrote:
> > #undef ERRONEOUSSTMT?
> Maybe we should not use a macro for this, specially not define the macro 
> inside the `struct` block. For the current tests it is sufficient to make a 
> std::string that contains something like `void f() { asm(""); }`.
My first attempt was to use std::string for the errouneous Stmt and then to use 
llvm::formatv to easily concatenate the test code examples.
However, it tunred out that formatv actively forbids the use of the braces in 
the source string.
So I decided to use a macro because that way we can build up the test code most 
easily.
What is the problem by defining the macro in a struct block? There are no 
blocks for the preprocessor, just directives. I'd like to indicate that the 
macro is used only by the test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62373



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


[PATCH] D63330: [clangd] Add Value field to HoverInfo

2019-06-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Implementation LG though please do check that the new test results look useful 
and not too duplicative




Comment at: clang-tools-extra/clangd/XRefs.cpp:723
+  // Fill in value with evaluated initializer if possible.
+  if (const auto *Var = dyn_cast(D)) {
+if (const Expr *Init = Var->getInit()) {

Maybe add a FIXME about doing this for arbitrary expressions (like sizeof and 
function calls), not just VarDecl?



Comment at: clang-tools-extra/clangd/XRefs.h:106
   llvm::Optional> TemplateParameters;
+  /// Contains the evaluated value of the symbol if exists.
+  llvm::Optional Value;

if exists -> if available?



Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:956
+   }},
+  // FIXME: We should use TypeLoc instead of Decl to extract the concrete
+  // value.

kadircet wrote:
> sammccall wrote:
> > Hmm, actually I'm not sure whether this is TypeLoc vs Decl here. Rather 
> > this should be a DeclRefExpr to the VarDecl (result) in the *expanded* 
> > CXXRecordDecl.
> > 
> > This suggests that maybe the isValueDependent check isn't quite right - the 
> > initializer expression is value dependent as spelled, but in the 
> > instantiation it's resolved. Not sure if this is fixable. What happens if 
> > you comment out the check?
> yes, and the problem lies in the IndexingAPI, inside `handleDeclOccurence` 
> implicit instantiations are resolved into templated decls. therefore we lose 
> the template params :/
> 
> we can't call expression evaluator on value dependent expressions, there is 
> an assertion in the beginning of EvaluateAsRvalue.
OK, let's leave this to later. Can you change the FIXME comment? I think it's 
misleading as it stands



Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:981
+ HI.NamespaceScope = "";
+ HI.Value = "&\"1234\"[0]";
+   }},

kadircet wrote:
> sammccall wrote:
> > whoa, that's... weird. But fine, I think.
> > 
> > (It would be nice to elide the `&[]` if the index is zero, or maybe print 
> > as `"1234" + 2` etc)
> do you think it is worth changing that in printpretty (either the defaults or 
> via some `PrintingPolicy` option)?
Let's leave it for now and see if it actually proves annoying.



Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:673
  HI.Type = "Foo";
+ HI.Value = "Foo(5)";
}},

are these actually still emitted, or tests not updated?

Some of them (e.g. the lambda below!) don't seem useful


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63330



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


[PATCH] D62375: [ASTImporter] Mark erroneous nodes in from ctx

2019-06-24 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:7840
+  // Push FromD to the stack, and remove that when we return.
+  ImportPathBuilder PathRAII(ImportPath, FromD);
 

It is possible to use the `make_scope_exit` instead, this results in less 
written code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62375



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


[PATCH] D63426: [clangd] Narrow rename to local symbols.

2019-06-24 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 206185.
hokein added a comment.

More cleanups.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63426

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/refactor/Rename.h
  clang-tools-extra/clangd/unittests/RenameTests.cpp
  clang/include/clang/Tooling/Refactoring/Rename/RenamingAction.h
  clang/lib/Tooling/Refactoring/Rename/RenamingAction.cpp

Index: clang/lib/Tooling/Refactoring/Rename/RenamingAction.cpp
===
--- clang/lib/Tooling/Refactoring/Rename/RenamingAction.cpp
+++ clang/lib/Tooling/Refactoring/Rename/RenamingAction.cpp
@@ -74,6 +74,8 @@
std::move(NewName));
 }
 
+const NamedDecl *RenameOccurrences::getRenameDecl() const { return ND; }
+
 Expected
 RenameOccurrences::createSourceReplacements(RefactoringRuleContext &Context) {
   Expected Occurrences = findSymbolOccurrences(ND, Context);
Index: clang/include/clang/Tooling/Refactoring/Rename/RenamingAction.h
===
--- clang/include/clang/Tooling/Refactoring/Rename/RenamingAction.h
+++ clang/include/clang/Tooling/Refactoring/Rename/RenamingAction.h
@@ -54,6 +54,8 @@
 
   static const RefactoringDescriptor &describe();
 
+  const NamedDecl *getRenameDecl() const;
+
 private:
   RenameOccurrences(const NamedDecl *ND, std::string NewName)
   : ND(ND), NewName(std::move(NewName)) {}
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -18,6 +18,10 @@
 namespace clangd {
 namespace {
 
+MATCHER_P2(RenameRange, Code, Range, "") {
+  return replacementToEdit(Code, arg).range == Range;
+}
+
 TEST(RenameTest, SingleFile) {
   struct Test {
 const char* Before;
@@ -87,6 +91,67 @@
   }
 }
 
+TEST(RenameTest, Renameable) {
+  // Test cases where the symbol is declared in header.
+  const char *Headers[] = {
+  R"cpp(// allow -- function-local
+void f(int [[Lo^cal]]) {
+  [[Local]] = 2;
+}
+  )cpp",
+
+  R"cpp(// allow -- symbol is indexable and has no refs in index.
+void [[On^lyInThisFile]]();
+  )cpp",
+
+  R"cpp(// disallow -- symbol is indexable and has other refs in index.
+void f() {
+  Out^side s;
+}
+  )cpp",
+
+  R"cpp(// disallow -- symbol is not indexable.
+namespace {
+class Unin^dexable {};
+}
+  )cpp",
+  };
+  const char *CommonHeader = "class Outside {};";
+  TestTU OtherFile = TestTU::withCode("Outside s;");
+  OtherFile.HeaderCode = CommonHeader;
+  OtherFile.Filename = "other.cc";
+  // The index has a "Outside" reference.
+  auto OtherFileIndex = OtherFile.index();
+
+  for (const char *Header : Headers) {
+Annotations T(Header);
+// We open the .h file as the main file.
+TestTU TU = TestTU::withCode(T.code());
+TU.Filename = "test.h";
+TU.HeaderCode = CommonHeader;
+TU.ExtraArgs.push_back("-xc++");
+auto AST = TU.build();
+
+auto Results = renameWithinFile(AST, testPath(TU.Filename), T.point(),
+"dummyNewName", OtherFileIndex.get());
+bool WantRename = true;
+if (T.ranges().empty())
+  WantRename = false;
+if (!WantRename) {
+  EXPECT_FALSE(Results) << "expected renameWithinFile returned an error: "
+<< T.code();
+  llvm::consumeError(Results.takeError());
+} else {
+  EXPECT_TRUE(bool(Results)) << "renameWithinFile returned an error: "
+ << llvm::toString(Results.takeError());
+  std::vector> Expected;
+  for (const auto &R : T.ranges())
+Expected.push_back(RenameRange(TU.Code, R));
+  EXPECT_THAT(*Results, UnorderedElementsAreArray(Expected));
+}
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/refactor/Rename.h
===
--- clang-tools-extra/clangd/refactor/Rename.h
+++ clang-tools-extra/clangd/refactor/Rename.h
@@ -18,10 +18,11 @@
 
 /// Renames all occurrences of the symbol at \p Pos to \p NewName.
 /// Occurrences outside the current file are not modified.
-llvm::Expected renameWithinFile(ParsedAST &AST,
-   llvm::StringRef File,
-   Position Pos,
-   llvm::StringRef NewName);
+/// Returns an error if rename a symbol that's used in another file (per the
+/// index).
+llvm::Expected
+renameWithinFile(ParsedAST &AST, llvm::StringRef File, Position 

[PATCH] D63426: [clangd] Narrow rename to local symbols.

2019-06-24 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 206184.
hokein marked 11 inline comments as done.
hokein added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63426

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/refactor/Rename.h
  clang-tools-extra/clangd/unittests/RenameTests.cpp
  clang/include/clang/Tooling/Refactoring/Rename/RenamingAction.h
  clang/lib/Tooling/Refactoring/Rename/RenamingAction.cpp

Index: clang/lib/Tooling/Refactoring/Rename/RenamingAction.cpp
===
--- clang/lib/Tooling/Refactoring/Rename/RenamingAction.cpp
+++ clang/lib/Tooling/Refactoring/Rename/RenamingAction.cpp
@@ -74,6 +74,8 @@
std::move(NewName));
 }
 
+const NamedDecl *RenameOccurrences::getRenameDecl() const { return ND; }
+
 Expected
 RenameOccurrences::createSourceReplacements(RefactoringRuleContext &Context) {
   Expected Occurrences = findSymbolOccurrences(ND, Context);
Index: clang/include/clang/Tooling/Refactoring/Rename/RenamingAction.h
===
--- clang/include/clang/Tooling/Refactoring/Rename/RenamingAction.h
+++ clang/include/clang/Tooling/Refactoring/Rename/RenamingAction.h
@@ -54,6 +54,8 @@
 
   static const RefactoringDescriptor &describe();
 
+  const NamedDecl *getRenameDecl() const;
+
 private:
   RenameOccurrences(const NamedDecl *ND, std::string NewName)
   : ND(ND), NewName(std::move(NewName)) {}
Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -18,6 +18,10 @@
 namespace clangd {
 namespace {
 
+MATCHER_P2(RenameRange, Code, Range, "") {
+  return replacementToEdit(Code, arg).range == Range;
+}
+
 TEST(RenameTest, SingleFile) {
   struct Test {
 const char* Before;
@@ -87,6 +91,67 @@
   }
 }
 
+TEST(RenameTest, Renameable) {
+  // Test cases where the symbol is declared in header.
+  const char *Headers[] = {
+  R"cpp(// allow -- function-local
+void f(int [[Lo^cal]]) {
+  [[Local]] = 2;
+}
+  )cpp",
+
+  R"cpp(// allow -- symbol is indexable and has no refs in index.
+void [[On^lyInThisFile]]();
+  )cpp",
+
+  R"cpp(// disallow -- symbol is indexable and has other refs in index.
+void f() {
+  Out^side s;
+}
+  )cpp",
+
+  R"cpp(// disallow -- symbol is not indexable.
+namespace {
+class Unin^dexable {};
+}
+  )cpp",
+  };
+  const char *CommonHeader = "class Outside {};";
+  TestTU OtherFile = TestTU::withCode("Outside s;");
+  OtherFile.HeaderCode = CommonHeader;
+  OtherFile.Filename = "other.cc";
+  // The index has a "Outside" reference.
+  auto OtherFileIndex = OtherFile.index();
+
+  for (const char *Header : Headers) {
+Annotations T(Header);
+// We open the .h file as the main file.
+TestTU TU = TestTU::withCode(T.code());
+TU.Filename = "test.h";
+TU.HeaderCode = CommonHeader;
+TU.ExtraArgs.push_back("-xc++");
+auto AST = TU.build();
+
+auto Results = renameWithinFile(AST, testPath(TU.Filename), T.point(),
+"dummyNewName", OtherFileIndex.get());
+bool WantRename = true;
+if (T.ranges().empty())
+  WantRename = false;
+if (!WantRename) {
+  EXPECT_FALSE(Results) << "expected renameWithinFile returned an error: "
+<< T.code();
+  llvm::consumeError(Results.takeError());
+} else {
+  EXPECT_TRUE(bool(Results)) << "renameWithinFile returned an error: "
+ << llvm::toString(Results.takeError());
+  std::vector> Expected;
+  for (const auto &R : T.ranges())
+Expected.push_back(RenameRange(TU.Code, R));
+  EXPECT_THAT(*Results, UnorderedElementsAreArray(Expected));
+}
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/refactor/Rename.h
===
--- clang-tools-extra/clangd/refactor/Rename.h
+++ clang-tools-extra/clangd/refactor/Rename.h
@@ -18,10 +18,11 @@
 
 /// Renames all occurrences of the symbol at \p Pos to \p NewName.
 /// Occurrences outside the current file are not modified.
-llvm::Expected renameWithinFile(ParsedAST &AST,
-   llvm::StringRef File,
-   Position Pos,
-   llvm::StringRef NewName);
+/// Returns an error if rename a symbol that's used in another file (per the
+/// index).
+llvm::Expected
+renameWithin

[PATCH] D63325: [Support][Time profiler] Make FE codegen blocks to be inside frontend blocks

2019-06-24 Thread Russell Gallop via Phabricator via cfe-commits
russell.gallop added inline comments.



Comment at: llvm/lib/Support/TimeProfiler.cpp:67
 
 // Only include sections longer than TimeTraceGranularity msec.
-if (duration_cast(E.Duration).count() > TimeTraceGranularity)

This comment looks wrong since this change. Please can you update or reword it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63325



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


[PATCH] D62373: [ASTImporter] Store import errors for Decls

2019-06-24 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:7851
+if (!getImportDeclErrorIfAny(FromD)) {
+  // Error encountered for the first time.
+  // After takeError the error is not usable any more in ToDOrErr.

martong wrote:
> balazske wrote:
> > martong wrote:
> > > a_sidorin wrote:
> > > > Is it possible to get this error more than once?
> > > Yes, that can happen in cyclic imports like: ClassTemplateDecl -> 
> > > TemplatedDecl -> ClassTemplateDecl.
> > I do not understand this completely, in this branch `setImportDeclError` is 
> > called so at next time we can not go into this branch again (for the same 
> > `FromD`). (We can get the error and not go into this branch more than once 
> > but get no error and go into the branch only once.)
> Yes, I missed that.
> So, perhaps we can remove the condition `if 
> (!getImportDeclErrorIfAny(FromD))` ?
I think yes: If `!ToDOrErr` is true we have an error that was newly created in 
`ImportImpl`. But I am not totally sure, and the ImportImpl can be overridden, 
so it is better to not remove the condition. Or make an assert out of it: 
`assert(!getImportDeclErrorIfAny(FromD) && "Import error already set for 
decl.")`.



Comment at: clang/unittests/AST/ASTImporterTest.cpp:4697
+DefaultTestValuesForRunOptions, );
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest,

martong wrote:
> balazske wrote:
> > a_sidorin wrote:
> > > #undef ERRONEOUSSTMT?
> > Maybe we should not use a macro for this, specially not define the macro 
> > inside the `struct` block. For the current tests it is sufficient to make a 
> > std::string that contains something like `void f() { asm(""); }`.
> My first attempt was to use std::string for the errouneous Stmt and then to 
> use llvm::formatv to easily concatenate the test code examples.
> However, it tunred out that formatv actively forbids the use of the braces in 
> the source string.
> So I decided to use a macro because that way we can build up the test code 
> most easily.
> What is the problem by defining the macro in a struct block? There are no 
> blocks for the preprocessor, just directives. I'd like to indicate that the 
> macro is used only by the test.
The problem was that it looks like that macro is an internal thing (to the 
struct) but in reality it is not. Probably `std::string::append` can be used if 
possible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62373



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


[PATCH] D63325: [Support][Time profiler] Make FE codegen blocks to be inside frontend blocks

2019-06-24 Thread Anton Afanasyev via Phabricator via cfe-commits
anton-afanasyev updated this revision to Diff 206187.
anton-afanasyev added a comment.

Changed comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63325

Files:
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/Driver/check-time-trace-sections.cpp
  clang/test/Driver/check-time-trace-sections.py
  llvm/lib/Support/TimeProfiler.cpp


Index: llvm/lib/Support/TimeProfiler.cpp
===
--- llvm/lib/Support/TimeProfiler.cpp
+++ llvm/lib/Support/TimeProfiler.cpp
@@ -64,8 +64,8 @@
 auto &E = Stack.back();
 E.Duration = steady_clock::now() - E.Start;
 
-// Only include sections longer than TimeTraceGranularity msec.
-if (duration_cast(E.Duration).count() > TimeTraceGranularity)
+// Only include sections longer or equal to TimeTraceGranularity msec.
+if (duration_cast(E.Duration).count() >= 
TimeTraceGranularity)
   Entries.emplace_back(E);
 
 // Track total time taken by each "name", but only the topmost levels of
Index: clang/test/Driver/check-time-trace-sections.py
===
--- /dev/null
+++ clang/test/Driver/check-time-trace-sections.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+
+import json, sys
+
+def is_inside(range1, range2):
+a = range1["ts"]; b = a + range1["dur"]
+c = range2["ts"]; d = c + range2["dur"]
+return (a >= c and a <= d) and (b >= c and b <= d)
+
+def is_before(range1, range2):
+b = range1["ts"] + range1["dur"]; c = range2["ts"]
+return b <= c
+
+events = json.loads(sys.stdin.read())["traceEvents"]
+codegens = filter(lambda x: x["name"] == "CodeGen Function", events)
+frontends = filter(lambda x: x["name"] == "Frontend", events)
+backends = filter(lambda x: x["name"] == "Backend", events)
+
+if not all([any([is_inside(codegen, frontend) for frontend in frontends])
+for codegen in codegens]):
+sys.exit("Not all CodeGen sections are inside any Frontend section!")
+
+if not all([all([is_before(frontend, backend) for frontend in frontends])
+for backend in backends]):
+sys.exit("Not all Frontend section are before all Backend sections!")
Index: clang/test/Driver/check-time-trace-sections.cpp
===
--- /dev/null
+++ clang/test/Driver/check-time-trace-sections.cpp
@@ -0,0 +1,7 @@
+// REQUIRES: shell
+// RUN: %clangxx -S -ftime-trace -mllvm --time-trace-granularity=0 -o 
%T/check-time-trace-sections %s
+// RUN: cat %T/check-time-trace-sections.json | %python 
%S/check-time-trace-sections.py
+
+template 
+void foo(T) {}
+void bar() { foo(0); }
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -37,6 +37,7 @@
 #include "llvm/Pass.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SourceMgr.h"
+#include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/ToolOutputFile.h"
 #include "llvm/Support/YAMLTraits.h"
@@ -228,6 +229,7 @@
 
 void HandleTranslationUnit(ASTContext &C) override {
   {
+llvm::TimeTraceScope TimeScope("Frontend", StringRef(""));
 PrettyStackTraceString CrashInfo("Per-file LLVM IR generation");
 if (FrontendTimesIsEnabled) {
   LLVMIRGenerationRefCount += 1;


Index: llvm/lib/Support/TimeProfiler.cpp
===
--- llvm/lib/Support/TimeProfiler.cpp
+++ llvm/lib/Support/TimeProfiler.cpp
@@ -64,8 +64,8 @@
 auto &E = Stack.back();
 E.Duration = steady_clock::now() - E.Start;
 
-// Only include sections longer than TimeTraceGranularity msec.
-if (duration_cast(E.Duration).count() > TimeTraceGranularity)
+// Only include sections longer or equal to TimeTraceGranularity msec.
+if (duration_cast(E.Duration).count() >= TimeTraceGranularity)
   Entries.emplace_back(E);
 
 // Track total time taken by each "name", but only the topmost levels of
Index: clang/test/Driver/check-time-trace-sections.py
===
--- /dev/null
+++ clang/test/Driver/check-time-trace-sections.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+
+import json, sys
+
+def is_inside(range1, range2):
+a = range1["ts"]; b = a + range1["dur"]
+c = range2["ts"]; d = c + range2["dur"]
+return (a >= c and a <= d) and (b >= c and b <= d)
+
+def is_before(range1, range2):
+b = range1["ts"] + range1["dur"]; c = range2["ts"]
+return b <= c
+
+events = json.loads(sys.stdin.read())["traceEvents"]
+codegens = filter(lambda x: x["name"] == "CodeGen Function", events)
+frontends = filter(lambda x: x["name"] == "Frontend", events)
+backends = filter(lambda x: x["name"] == "Backend", e

[PATCH] D63325: [Support][Time profiler] Make FE codegen blocks to be inside frontend blocks

2019-06-24 Thread Anton Afanasyev via Phabricator via cfe-commits
anton-afanasyev marked 2 inline comments as done.
anton-afanasyev added inline comments.



Comment at: llvm/lib/Support/TimeProfiler.cpp:67
 
 // Only include sections longer than TimeTraceGranularity msec.
-if (duration_cast(E.Duration).count() > TimeTraceGranularity)

russell.gallop wrote:
> This comment looks wrong since this change. Please can you update or reword 
> it?
Ok, updated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63325



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


[PATCH] D33841: [clang-tidy] redundant 'extern' keyword check

2019-06-24 Thread Daniel Kolozsvari via Phabricator via cfe-commits
koldaniel updated this revision to Diff 206190.

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

https://reviews.llvm.org/D33841

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/RedundantExternCheck.cpp
  clang-tidy/readability/RedundantExternCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/readability-redundant-extern.rst
  test/clang-tidy/readability-redundant-extern.cpp

Index: test/clang-tidy/readability-redundant-extern.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-redundant-extern.cpp
@@ -0,0 +1,74 @@
+// RUN: %check_clang_tidy %s readability-redundant-extern %t
+
+extern int f();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant 'extern' keyword [readability-redundant-extern]
+// CHECK-FIXES: int f();
+
+int extern f() { return 0; }
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant 'extern' keyword [readability-redundant-extern]
+// CHECK-FIXES: int f() { return 0; }
+
+extern "C" int g();
+// CHECK-FIXES: extern "C" int g();
+
+extern "C" int g() { return 0; }
+// CHECK-FIXES: extern "C" int g() { return 0; }
+
+extern "C++" int h();
+// CHECK-FIXES: extern "C++" int h();
+
+extern "C++" int h() { return 0; }
+// CHECK-FIXES: extern "C++" int h() { return 0; }
+
+inline extern void foo_inline();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant 'extern' keyword [readability-redundant-extern]
+// CHECK-FIXES: inline void foo_inline();
+
+#define FOO_EXTERN extern
+FOO_EXTERN void foo_macro_1();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant 'extern' keyword [readability-redundant-extern]
+// CHECK-FIXES: FOO_EXTERN void foo_macro_1();
+
+#define FOO_INLINE inline
+FOO_INLINE extern void foo_macro_2();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant 'extern' keyword [readability-redundant-extern]
+// CHECK-FIXES: FOO_INLINE extern void foo_macro_2();
+
+#define FOO_EXTERN_INLINE inline extern
+FOO_EXTERN_INLINE void foo_macro_3();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant 'extern' keyword [readability-redundant-extern]
+// CHECK-FIXES: FOO_EXTERN_INLINE void foo_macro_3();
+
+void file_scope();
+// CHECK-FIXES: void file_scope();
+
+void another_file_scope(int _extern);
+// CHECK-FIXES: void another_file_scope(int _extern);
+
+namespace {
+extern void namespace_1();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'extern' keyword has no effect [readability-redundant-extern]
+// CHECK-FIXES: void namespace_1();
+}
+
+namespace a {
+namespace {
+namespace b {
+extern void namespace_2();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: 'extern' keyword has no effect [readability-redundant-extern]
+// CHECK-FIXES: void namespace_2();
+}
+}
+}
+
+namespace {
+extern "C" void namespace_3();
+// CHECK-FIXES: extern "C" void namespace_3();
+}
+
+#define FOO_EXTERN extern
+typedef int extern_int;
+
+extern_int FOO_EXTERN typedef_extern_foo();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: redundant 'extern' keyword [readability-redundant-extern]
+// CHECK-FIXES: extern_int FOO_EXTERN typedef_extern_foo();
Index: docs/clang-tidy/checks/readability-redundant-extern.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-redundant-extern.rst
@@ -0,0 +1,30 @@
+.. title:: clang-tidy - readability-redundant-extern
+
+readability-redundant-extern
+
+
+Removes the redundant or unnecessary ``extern`` keywords from code.
+
+``extern`` is redundant in function declarations, and has no effect in
+namespaces
+
+The default language linkage is C++, so without any additional parameters
+it is redundant (extern "C++" can also be redundant, but it depends on
+the context). In C context (extern "C") the situation is the same, extern
+keyword is redundant for function declarations
+
+.. code-block:: c++
+
+  extern void h();
+
+  namespace {
+extern void namespace_1();  
+  }
+
+  #define FOO_EXTERN extern
+  FOO_EXTERN void foo_macro_1();
+
+  #define FOO_EXTERN extern
+  typedef int extern_int;
+  extern_int FOO_EXTERN typedef_extern_foo();
+
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -240,6 +240,11 @@
   but either don't specify it or the clause is specified but with the kind
   other than ``none``, and suggests to use the ``default(none)`` clause.
 
+- New :doc:`readability-redundant-extern
+  ` check.
+
+  Removes the redundant ``extern`` keywords.
+
 Improvements to clang-include-fixer
 ---
 
Index: clang-tidy/readability/RedundantExternCheck.h
===
--- /dev/null
+++ clang-tidy/readability/RedundantExternCheck.h
@@ -0,0 +1,34 @@
+//===--- RedundantExternCheck.h - clang-tidy *- C++ -*-===//
+//
+// Pa

[PATCH] D62953: [Syntax] Do not glue multiple empty PP expansions to a single mapping

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



Comment at: clang/include/clang/Tooling/Syntax/Tokens.h:315
 private:
+  /// Maps from a start location to an end location of transformations 
performed
+  /// by the preprocessor. These include:

*spelled* locations!



Comment at: clang/include/clang/Tooling/Syntax/Tokens.h:319
+  ///   2. macro name and arguments for macro expansions.
+  using PPExpansions = llvm::DenseMap;
   class Builder;

do I understand right that this is logically a stack, but it's hard to know 
when to pop or just less hassle to do this way?
if so, maybe worth mentioning



Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:262
+
+  /// Disabled instance will stop reporting anything to TokenCollector.
+  void disable() { Collector = nullptr; }

add a comment for *why* this is needed?



Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:269
+  return;
+// Do not record recursive expansions.
+if (!MacroNameTok.getLocation().isFileID() ||

This doesn't seem like a particularly standard use of the word "recursive", and 
the code isn't totally obvious either.

Could this be "only record top-level expansions, not those where:
 - the macro use is inside a macro body
 - the macro appears in an argument to another macro

Because the top level macros are treated as opaque atoms. (We probably need a 
FIXME for tracking arg locations somewhere)



Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:522
   llvm::DenseMap NextSpelled;
+  PPExpansions Expansions;
   const SourceManager &SM;

maybe RecordedExpansions? to make the link with the recorder



Comment at: clang/unittests/Tooling/Syntax/TokensTest.cpp:431
   mappings:
-['#'_0, ''_18) => [''_0, ''_0)
+['#'_0, 'EMPTY'_9) => [''_0, ''_0)
+['EMPTY'_9, 'EMPTY_FUNC'_10) => [''_0, ''_0)

the two #define statements are still merged into a single mapping.
Do we have a FIXME somewhere to cover this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62953



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


[PATCH] D63194: [clangd] Link in target infos and pass target and mode while invoking driver

2019-06-24 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 206193.
kadircet added a comment.

- Introduce a new wrapper CDB that adds target and mode info to returned 
compile commands


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63194

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/test/target_info.test
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang/include/clang/Tooling/CompilationDatabase.h
  clang/lib/Tooling/CMakeLists.txt
  clang/lib/Tooling/JSONCompilationDatabase.cpp
  clang/lib/Tooling/TargetAndModeAdderDatabase.cpp
  clang/unittests/Tooling/CompilationDatabaseTest.cpp

Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -9,10 +9,12 @@
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclGroup.h"
 #include "clang/Frontend/FrontendAction.h"
+#include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/FileMatchTrie.h"
 #include "clang/Tooling/JSONCompilationDatabase.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/TargetSelect.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -632,7 +634,7 @@
   }
 };
 
-class InterpolateTest : public ::testing::Test {
+class MemDBTest : public ::testing::Test {
 protected:
   // Adds an entry to the underlying compilation database.
   // A flag is injected: -D , so the command used can be identified.
@@ -658,6 +660,11 @@
 return Result.str();
   }
 
+  MemCDB::EntryMap Entries;
+};
+
+class InterpolateTest : public MemDBTest {
+protected:
   // Look up the command from a relative path, and return it in string form.
   // The input file is not included in the returned command.
   std::string getCommand(llvm::StringRef F) {
@@ -693,8 +700,6 @@
 llvm::sys::path::native(Result, llvm::sys::path::Style::posix);
 return Result.str();
   }
-
-  MemCDB::EntryMap Entries;
 };
 
 TEST_F(InterpolateTest, Nearby) {
@@ -804,5 +809,31 @@
   EXPECT_TRUE(CCRef != CCTest);
 }
 
+class TargetAndModeTest : public MemDBTest {
+public:
+  TargetAndModeTest() { llvm::InitializeAllTargetInfos(); }
+
+protected:
+  // Look up the command from a relative path, and return it in string form.
+  std::string getCommand(llvm::StringRef F) {
+auto Results =
+getTargetAndModeAdderDatabase(llvm::make_unique(Entries))
+->getCompileCommands(path(F));
+if (Results.empty())
+  return "none";
+return llvm::join(Results[0].CommandLine, " ");
+  }
+};
+
+TEST_F(TargetAndModeTest, TargetAndMode) {
+  add("foo.cpp", "clang-cl", "");
+  add("bar.cpp", "x86_64-linux-clang", "");
+
+  EXPECT_EQ(getCommand("foo.cpp"),
+"clang-cl --driver-mode=cl foo.cpp -D foo.cpp");
+  EXPECT_EQ(getCommand("bar.cpp"),
+"x86_64-linux-clang -target x86_64-linux bar.cpp -D bar.cpp");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: clang/lib/Tooling/TargetAndModeAdderDatabase.cpp
===
--- /dev/null
+++ clang/lib/Tooling/TargetAndModeAdderDatabase.cpp
@@ -0,0 +1,57 @@
+//===- TargetAndModeAdderDatabase.cpp -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Tooling/Tooling.h"
+#include 
+
+namespace clang {
+namespace tooling {
+
+namespace {
+class TargetAndModeAdderDatabase : public CompilationDatabase {
+public:
+  TargetAndModeAdderDatabase(std::unique_ptr Base)
+  : Base(std::move(Base)) {
+assert(this->Base != nullptr);
+  }
+
+  std::vector getAllFiles() const override {
+return Base->getAllFiles();
+  }
+
+  std::vector getAllCompileCommands() const override {
+return addTargetAndMode(Base->getAllCompileCommands());
+  }
+
+  std::vector
+  getCompileCommands(StringRef FilePath) const override {
+return addTargetAndMode(Base->getCompileCommands(FilePath));
+  }
+
+private:
+  std::vector
+  addTargetAndMode(std::vector &&Cmds) const {
+for (auto &Cmd : Cmds) {
+  if (Cmd.CommandLine.empty())
+continue;
+  addTargetAndModeForProgramName(Cmd.CommandLine, Cmd.CommandLine.front());
+}
+return std::move(Cmds);
+  }
+  std::unique_ptr Base;
+};
+} // namespace
+
+std::unique_ptr
+getTargetAndModeAdderDatabase(std::unique_ptr Base) {
+  return llvm::make_unique(std::move(Base));
+}
+
+} // namespace tooling
+} // namespace clang
Index: clang/lib/Tooling/JSONCompilationData

[PATCH] D63708: [clangd] Fix NestedNameSpecifierLoc in SelectionTree

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

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D63708

Files:
  clangd/Selection.cpp
  clangd/unittests/SelectionTests.cpp


Index: clangd/unittests/SelectionTests.cpp
===
--- clangd/unittests/SelectionTests.cpp
+++ clangd/unittests/SelectionTests.cpp
@@ -90,6 +90,13 @@
 const char *CommonAncestorKind;
   };
   Case Cases[] = {
+  {
+  R"cpp(
+template 
+int x = [[T::^U::]]ccc();
+  )cpp",
+  "NestedNameSpecifierLoc",
+  },
   {
   R"cpp(
 struct AAA { struct BBB { static int ccc(); };};
@@ -184,8 +191,7 @@
 template <[[template class /*cursor here*/^U]]>
  struct Foo*> {};
   )cpp",
-  "TemplateTemplateParmDecl"
-  },
+  "TemplateTemplateParmDecl"},
   };
   for (const Case &C : Cases) {
 Annotations Test(C.Code);
Index: clangd/Selection.cpp
===
--- clangd/Selection.cpp
+++ clangd/Selection.cpp
@@ -61,7 +61,7 @@
   bool TraverseTypeLoc(TypeLoc X) {
 return traverseNode(&X, [&] { return Base::TraverseTypeLoc(X); });
   }
-  bool TraverseTypeNestedNameSpecifierLoc(NestedNameSpecifierLoc X) {
+  bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc X) {
 return traverseNode(
 &X, [&] { return Base::TraverseNestedNameSpecifierLoc(X); });
   }


Index: clangd/unittests/SelectionTests.cpp
===
--- clangd/unittests/SelectionTests.cpp
+++ clangd/unittests/SelectionTests.cpp
@@ -90,6 +90,13 @@
 const char *CommonAncestorKind;
   };
   Case Cases[] = {
+  {
+  R"cpp(
+template 
+int x = [[T::^U::]]ccc();
+  )cpp",
+  "NestedNameSpecifierLoc",
+  },
   {
   R"cpp(
 struct AAA { struct BBB { static int ccc(); };};
@@ -184,8 +191,7 @@
 template <[[template class /*cursor here*/^U]]>
  struct Foo*> {};
   )cpp",
-  "TemplateTemplateParmDecl"
-  },
+  "TemplateTemplateParmDecl"},
   };
   for (const Case &C : Cases) {
 Annotations Test(C.Code);
Index: clangd/Selection.cpp
===
--- clangd/Selection.cpp
+++ clangd/Selection.cpp
@@ -61,7 +61,7 @@
   bool TraverseTypeLoc(TypeLoc X) {
 return traverseNode(&X, [&] { return Base::TraverseTypeLoc(X); });
   }
-  bool TraverseTypeNestedNameSpecifierLoc(NestedNameSpecifierLoc X) {
+  bool TraverseNestedNameSpecifierLoc(NestedNameSpecifierLoc X) {
 return traverseNode(
 &X, [&] { return Base::TraverseNestedNameSpecifierLoc(X); });
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63194: [clangd] Link in target infos and pass target and mode while invoking driver

2019-06-24 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

In D63194#1553649 , @ilya-biryukov 
wrote:

> The only suggestion from me would be maybe try moving this to a layer that 
> would also make also benefit other compilation-db-based things like 
> `clang-tidy`, etc?
>  Any ideas on how to do this? Would this potentially break anything?


I've made it a wrapper for JSON-based compilation database(as inferring cdb 
does), there were no breakages in tests.
Hopefully all clang-based tools can benefit from it by linking in target infos 
and enabling them at startup.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63194



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


[PATCH] D63710: [SYCL] Re-use OpenCL sampler in SYCL device mode

2019-06-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added subscribers: cfe-commits, Anastasia, ebevhan, yaxunl.
Herald added a project: clang.
Fznamznon added reviewers: bader, Anastasia.

sampler_t type name is replaced with __ocl_sampler_t to avoid
potential collisions with user types.
Selectively enabled a few OpenCL diagnostics for sampler type as some
diagnostics trigger on SYCL use cases.

For instance, OpenCL kernel in SYCL mode initializes lambda captures with
the kernel argument values. This initialization code for sampler emits
errors because OpenCL disallows sampler on the right hand side of the
binary operators - these are supposed to be used only by built-in
functions.

Another potential issue is the lambda object itself -
captured sampler is a member of the lambda object and OpenCL doesn't
allow composite types with samplers. SPIR-V produced from SYCL should be
okay as lambda object can be removed by standard LLVM transformation
passes.

Patch by Alexey Bader 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63710

Files:
  clang/lib/AST/ASTContext.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenSYCL/ocl_sampler.cpp
  clang/test/SemaSYCL/ocl_sampler.cpp

Index: clang/test/SemaSYCL/ocl_sampler.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/ocl_sampler.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -std=c++11 -fsycl-is-device -fsyntax-only -verify %s
+
+#define CLK_ADDRESS_CLAMP_TO_EDGE   2
+#define CLK_NORMALIZED_COORDS_TRUE  1
+#define CLK_FILTER_NEAREST  0x10
+#define CLK_FILTER_LINEAR   0x20
+
+__ocl_sampler_t global_nonconst_smp = 0; // expected-error {{global sampler requires a const or constant address space qualifier}}
+const __ocl_sampler_t glb_smp = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR;
+
+void foo(__ocl_sampler_t argsmp) {
+  __ocl_sampler_t smp1 = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_LINEAR;
+  __ocl_sampler_t smp2 = CLK_ADDRESS_CLAMP_TO_EDGE | CLK_NORMALIZED_COORDS_TRUE | CLK_FILTER_NEAREST;
+  &smp1; //expected-error{{invalid argument type '__ocl_sampler_t' (aka 'sampler_t') to unary expression}}
+  *smp2; //expected-error{{invalid argument type '__ocl_sampler_t' (aka 'sampler_t') to unary expression}}
+
+  const __ocl_sampler_t const_smp6 = 0x1LL; // expected-error{{sampler_t initialization requires 32-bit integer, not 'long long'}}
+
+  __ocl_sampler_t sa[] = {argsmp, glb_smp}; // expected-error {{array of '__ocl_sampler_t' (aka 'sampler_t') type is invalid in OpenCL}}
+}
+
+void foo_smplr_ptr(__ocl_sampler_t*); // expected-error{{pointer to type '__ocl_sampler_t' (aka 'sampler_t') is invalid in OpenCL}}
Index: clang/test/CodeGenSYCL/ocl_sampler.cpp
===
--- /dev/null
+++ clang/test/CodeGenSYCL/ocl_sampler.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple spir64-unknown-unknown -std=c++11 -fsycl-is-device -S -emit-llvm %s -o - | FileCheck %s
+
+// CHECK: %opencl.sampler_t = type opaque
+
+void foo(__ocl_sampler_t s) {}
+// CHECK: define spir_func void @{{.*}}foo{{.*}}(%opencl.sampler_t addrspace(2)*
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2320,7 +2320,7 @@
   // OpenCL v2.0 s6.12.5 - Arrays of blocks are not supported.
   // OpenCL v2.0 s6.16.13.1 - Arrays of pipe type are not supported.
   // OpenCL v2.0 s6.9.b - Arrays of image/sampler type are not supported.
-  if (getLangOpts().OpenCL) {
+  if (getLangOpts().OpenCL || getLangOpts().SYCLIsDevice) {
 const QualType ArrType = Context.getBaseElementType(T);
 if (ArrType->isBlockPointerType() || ArrType->isPipeType() ||
 ArrType->isSamplerT() || ArrType->isImageType()) {
@@ -4407,7 +4407,7 @@
   // OpenCL v2.0 s6.9b - Pointer to image/sampler cannot be used.
   // OpenCL v2.0 s6.13.16.1 - Pointer to pipe cannot be used.
   // OpenCL v2.0 s6.12.5 - Pointers to Blocks are not allowed.
-  if (LangOpts.OpenCL) {
+  if (LangOpts.OpenCL || LangOpts.SYCLIsDevice) {
 if (T->isImageType() || T->isSamplerT() || T->isPipeType() ||
 T->isBlockPointerType()) {
   S.Diag(D.getIdentifierLoc(), diag::err_opencl_pointer_to_type) << T;
@@ -4605,7 +4605,7 @@
 }
   }
 
-  if (LangOpts.OpenCL) {
+  if (LangOpts.OpenCL || LangOpts.SYCLIsDevice) {
 // OpenCL v2.0 s6.12.5 - A block cannot be the return value of a
 // function.
 if (T->isBlockPointerType() || T->isImageType() || T->isSamplerT() ||
@@ -4617,7 +4617,9 @@
 // OpenCL doesn't support variadic functions and blocks
 // (s6.9.e and s6.12.5 OpenCL v2.0) except 

[PATCH] D63194: [clangd] Link in target infos and pass target and mode while invoking driver

2019-06-24 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Thanks, this looks very good!
Leaving a few nitpicky comments, but nothing important really.

Two more general NITs:

- could we update the title and description of this revision to mirror that it 
focuses on code in tooling rather than in clangd?
- maybe land the clangd parts into a separate change for nicer VCS history?




Comment at: clang/include/clang/Tooling/CompilationDatabase.h:220
+std::unique_ptr
+getTargetAndModeAdderDatabase(std::unique_ptr Base);
+

NIT: in the spirit of a previous name, we could shorten the name 
`inferTargetAndDriverMode(…)`



Comment at: clang/lib/Tooling/CMakeLists.txt:25
   StandaloneExecution.cpp
+  TargetAndModeAdderDatabase.cpp
   Tooling.cpp

NIT: `GuessTargetAndDriverModeCompilationDatabase` would align better with the 
names of other files that define compilation databases.

It looks a little long, though, maybe there's a better word to capture 
`TargetAndMode`



Comment at: clang/lib/Tooling/TargetAndModeAdderDatabase.cpp:39
+  std::vector
+  addTargetAndMode(std::vector &&Cmds) const {
+for (auto &Cmd : Cmds) {

NIT: maybe accept by value to simplify the code?
A cost of an extra move constructor here is negligible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63194



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


[clang-tools-extra] r364180 - [clangd] Improve SelectionTree string representation

2019-06-24 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Mon Jun 24 06:01:28 2019
New Revision: 364180

URL: http://llvm.org/viewvc/llvm-project?rev=364180&view=rev
Log:
[clangd] Improve SelectionTree string representation

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

Modified: clang-tools-extra/trunk/clangd/Selection.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Selection.cpp?rev=364180&r1=364179&r2=364180&view=diff
==
--- clang-tools-extra/trunk/clangd/Selection.cpp (original)
+++ clang-tools-extra/trunk/clangd/Selection.cpp Mon Jun 24 06:01:28 2019
@@ -246,7 +246,17 @@ void SelectionTree::print(llvm::raw_ostr
 : '.');
   else
 OS.indent(Indent);
-  OS << N.ASTNode.getNodeKind().asStringRef() << " ";
+  if (const TypeLoc *TL = N.ASTNode.get()) {
+// TypeLoc is a hierarchy, but has only a single ASTNodeKind.
+// Synthesize the name from the Type subclass (except for 
QualifiedTypeLoc).
+if (TL->getTypeLocClass() == TypeLoc::Qualified)
+  OS << "QualifiedTypeLoc";
+else
+  OS << TL->getType()->getTypeClassName() << "TypeLoc";
+  } else {
+OS << N.ASTNode.getNodeKind().asStringRef();
+  }
+  OS << " ";
   N.ASTNode.print(OS, PrintPolicy);
   OS << "\n";
   for (const Node *Child : N.Children)
@@ -280,6 +290,7 @@ SelectionTree::SelectionTree(ASTContext
   if (Begin == End)
 std::tie(Begin, End) = pointBounds(Begin, FID, AST);
   PrintPolicy.TerseOutput = true;
+  PrintPolicy.IncludeNewlines = false;
 
   Nodes = SelectionVisitor::collect(AST, Begin, End, FID);
   Root = Nodes.empty() ? nullptr : &Nodes.front();


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


[PATCH] D63714: [clangd] Cleanup the duplicated getTokenRange.

2019-06-24 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added subscribers: arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.

Also lift it to SourceCode.h, so that it can be used in other places
(semantic code highlighting).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63714

Files:
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/XRefs.cpp

Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -260,14 +260,6 @@
   return {DeclMacrosFinder.getFoundDecls(), DeclMacrosFinder.takeMacroInfos()};
 }
 
-Range getTokenRange(ASTContext &AST, SourceLocation TokLoc) {
-  const SourceManager &SourceMgr = AST.getSourceManager();
-  SourceLocation LocEnd =
-  Lexer::getLocForEndOfToken(TokLoc, 0, SourceMgr, AST.getLangOpts());
-  return {sourceLocToPosition(SourceMgr, TokLoc),
-  sourceLocToPosition(SourceMgr, LocEnd)};
-}
-
 llvm::Optional makeLocation(ASTContext &AST, SourceLocation TokLoc,
   llvm::StringRef TUPath) {
   const SourceManager &SourceMgr = AST.getSourceManager();
@@ -279,10 +271,14 @@
 log("failed to get path!");
 return None;
   }
-  Location L;
-  L.uri = URIForFile::canonicalize(*FilePath, TUPath);
-  L.range = getTokenRange(AST, TokLoc);
-  return L;
+  if (auto Range =
+  getTokenRange(AST.getSourceManager(), AST.getLangOpts(), TokLoc)) {
+Location L;
+L.uri = URIForFile::canonicalize(*FilePath, TUPath);
+L.range = *Range;
+return L;
+  }
+  return None;
 }
 
 } // namespace
@@ -472,14 +468,18 @@
   std::vector Result;
   for (const auto &Ref : References) {
 DocumentHighlight DH;
-DH.range = getTokenRange(AST.getASTContext(), Ref.Loc);
-if (Ref.Role & index::SymbolRoleSet(index::SymbolRole::Write))
-  DH.kind = DocumentHighlightKind::Write;
-else if (Ref.Role & index::SymbolRoleSet(index::SymbolRole::Read))
-  DH.kind = DocumentHighlightKind::Read;
-else
-  DH.kind = DocumentHighlightKind::Text;
-Result.push_back(std::move(DH));
+if (auto Range =
+getTokenRange(AST.getASTContext().getSourceManager(),
+  AST.getASTContext().getLangOpts(), Ref.Loc)) {
+  DH.range = *Range;
+  if (Ref.Role & index::SymbolRoleSet(index::SymbolRole::Write))
+DH.kind = DocumentHighlightKind::Write;
+  else if (Ref.Role & index::SymbolRoleSet(index::SymbolRole::Read))
+DH.kind = DocumentHighlightKind::Read;
+  else
+DH.kind = DocumentHighlightKind::Text;
+  Result.push_back(std::move(DH));
+}
   }
   return Result;
 }
@@ -610,18 +610,6 @@
   return TempParameters;
 }
 
-static llvm::Optional getTokenRange(SourceLocation Loc,
-   const ASTContext &Ctx) {
-  if (!Loc.isValid())
-return llvm::None;
-  SourceLocation End = Lexer::getLocForEndOfToken(
-  Loc, 0, Ctx.getSourceManager(), Ctx.getLangOpts());
-  if (!End.isValid())
-return llvm::None;
-  return halfOpenToRange(Ctx.getSourceManager(),
- CharSourceRange::getCharRange(Loc, End));
-}
-
 static const FunctionDecl *getUnderlyingFunction(const Decl *D) {
   // Extract lambda from variables.
   if (const VarDecl *VD = llvm::dyn_cast(D)) {
@@ -910,7 +898,9 @@
   tooling::applyAllReplacements(HI->Definition, Replacements))
 HI->Definition = *Formatted;
 
-  HI->SymRange = getTokenRange(SourceLocationBeg, AST.getASTContext());
+  HI->SymRange =
+  getTokenRange(AST.getASTContext().getSourceManager(),
+AST.getASTContext().getLangOpts(), SourceLocationBeg);
   return HI;
 }
 
@@ -934,9 +924,13 @@
   auto MainFileRefs = findRefs(Symbols.Decls, AST);
   for (const auto &Ref : MainFileRefs) {
 Location Result;
-Result.range = getTokenRange(AST.getASTContext(), Ref.Loc);
-Result.uri = URIForFile::canonicalize(*MainFilePath, *MainFilePath);
-Results.push_back(std::move(Result));
+if (auto Range =
+getTokenRange(AST.getASTContext().getSourceManager(),
+  AST.getASTContext().getLangOpts(), Ref.Loc)) {
+  Result.range = *Range;
+  Result.uri = URIForFile::canonicalize(*MainFilePath, *MainFilePath);
+  Results.push_back(std::move(Result));
+}
   }
 
   // Now query the index for references from other files.
Index: clang-tools-extra/clangd/SourceCode.h
===
--- clang-tools-extra/clangd/SourceCode.h
+++ clang-tools-extra/clangd/SourceCode.h
@@ -65,6 +65,11 @@
 /// FIXME: This should return an error if the location is invalid.
 Position sourceLocToPosition(const SourceManager &SM, SourceLocation Loc);
 
+/// Returns the taken range at \p TokLoc.
+llvm::Optional getTokenRange(const SourceMan

[PATCH] D63330: [clangd] Add Value field to HoverInfo

2019-06-24 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 206210.
kadircet marked 9 inline comments as done and an inline comment as not done.
kadircet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63330

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

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -661,14 +661,14 @@
}},
   // Variable with template type
   {R"cpp(
-  template  class Foo {};
-  Foo [[fo^o]];
+  template  class Foo { public: Foo(int); };
+  Foo [[fo^o]] = Foo(5);
   )cpp",
[](HoverInfo &HI) {
  HI.NamespaceScope = "";
  HI.Name = "foo";
  HI.Kind = SymbolKind::Variable;
- HI.Definition = "Foo foo";
+ HI.Definition = "Foo foo = Foo(5)";
  HI.Type = "Foo";
}},
   // Implicit template instantiation
@@ -911,6 +911,72 @@
  HI.Name = "MACRO", HI.Kind = SymbolKind::String,
  HI.Definition = "#define MACRO(x, y, z) void foo(x, y, z);";
}},
+
+  // constexprs
+  {R"cpp(
+constexpr int add(int a, int b) { return a + b; }
+int [[b^ar]] = add(1, 2);
+)cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "bar";
+ HI.Definition = "int bar = add(1, 2)";
+ HI.Kind = SymbolKind::Variable;
+ HI.Type = "int";
+ HI.NamespaceScope = "";
+ HI.Value = "3";
+   }},
+  {R"cpp(
+int [[b^ar]] = sizeof(char);
+)cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "bar";
+ HI.Definition = "int bar = sizeof(char)";
+ HI.Kind = SymbolKind::Variable;
+ HI.Type = "int";
+ HI.NamespaceScope = "";
+ HI.Value = "1";
+   }},
+  {R"cpp(
+template struct Add {
+  static constexpr int result = a + b;
+};
+int [[ba^r]] = Add<1, 2>::result;
+)cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "bar";
+ HI.Definition = "int bar = Add<1, 2>::result";
+ HI.Kind = SymbolKind::Variable;
+ HI.Type = "int";
+ HI.NamespaceScope = "";
+ HI.Value = "3";
+   }},
+  // FIXME: We should use the Decl referenced, even if it comes from an
+  // implicit instantiation.
+  {R"cpp(
+template struct Add {
+  static constexpr int result = a + b;
+};
+int bar = Add<1, 2>::[[resu^lt]];
+)cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "result";
+ HI.Definition = "static constexpr int result = a + b";
+ HI.Kind = SymbolKind::Property;
+ HI.Type = "const int";
+ HI.NamespaceScope = "";
+ HI.LocalScope = "Add::";
+   }},
+  {R"cpp(
+const char *[[ba^r]] = "1234";
+)cpp",
+   [](HoverInfo &HI) {
+ HI.Name = "bar";
+ HI.Definition = "const char *bar = \"1234\"";
+ HI.Kind = SymbolKind::Variable;
+ HI.Type = "const char *";
+ HI.NamespaceScope = "";
+ HI.Value = "&\"1234\"[0]";
+   }},
   };
   for (const auto &Case : Cases) {
 SCOPED_TRACE(Case.Code);
@@ -938,6 +1004,7 @@
 EXPECT_EQ(H->Parameters, Expected.Parameters);
 EXPECT_EQ(H->TemplateParameters, Expected.TemplateParameters);
 EXPECT_EQ(H->SymRange, Expected.SymRange);
+EXPECT_EQ(H->Value, Expected.Value);
   }
 } // namespace clang
 
Index: clang-tools-extra/clangd/XRefs.h
===
--- clang-tools-extra/clangd/XRefs.h
+++ clang-tools-extra/clangd/XRefs.h
@@ -103,6 +103,8 @@
   llvm::Optional> Parameters;
   /// Set for all templates(function, class, variable).
   llvm::Optional> TemplateParameters;
+  /// Contains the evaluated value of the symbol if available.
+  llvm::Optional Value;
 
   /// Produce a user-readable information.
   FormattedString present() const;
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -719,6 +719,21 @@
 VD->getType().print(OS, Policy);
   }
 
+  // Fill in value with evaluated initializer if possible.
+  // FIXME(kadircet): Also set Value field for expressions like "sizeof" and
+  // function calls.
+  if (const auto *Var = dyn_cast(D)) {
+if (const Expr *Init = Var->getInit()) {
+  Expr::EvalResult Result;
+  if (!Init->isValueDependent() && Init->EvaluateAsRValue(Result, Ctx)) {
+HI.Value.emplace();
+llvm::raw_string_ostream ValueOS(*HI.Value);
+Result.Val.printPretty(ValueOS, const_cast(Ctx),
+  

[PATCH] D63330: [clangd] Add Value field to HoverInfo

2019-06-24 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:920
+  {R"cpp(
+constexpr int add(int a, int b) { return a + b; }
+int [[b^ar]] = add(1, 2);

sammccall wrote:
> constexpr may not be required here, I think?
> At least the docs suggest evaluation ignores language semantics like this.
apparently this constexpr is necessary, otherwise evaluation fails.



Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:673
  HI.Type = "Foo";
+ HI.Value = "Foo(5)";
}},

sammccall wrote:
> are these actually still emitted, or tests not updated?
> 
> Some of them (e.g. the lambda below!) don't seem useful
oops, somehow I've deleted the expect line that checks the values :/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63330



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


[PATCH] D63559: [clang-tidy] Added functionality for getting semantic highlights for variable and function declarations

2019-06-24 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/SemanticHighlight.cpp:11
+
+// Collects all semantic symbols in an ASTContext. Symbols on line i are always
+// in front of symbols on line i+1

The comment is out of date now.



Comment at: clang-tools-extra/clangd/SemanticHighlight.cpp:39
+AST.getLangOpts());
+if (Len == 0) {
+  // Don't add symbols that don't have any length.

We can check the name of `NamedDecl` is empty rather than detecting the length. 

Could you add a test for this?



Comment at: clang-tools-extra/clangd/SemanticHighlight.cpp:75
+  SemanticSymbolASTCollector Collector(Ctx);
+  Collector.TraverseAST(Ctx);
+  return Collector.getSymbols();

let's move the above lines into `SemanticSymbolASTCollector`, we can define a 
new method "collectTokens()".



Comment at: clang-tools-extra/clangd/SemanticHighlight.h:9
+//
+// Code for collecting semantic symbols from the C++ AST using the
+// RecursiveASTVisitor

this comment doesn't provide much information IMO, let's remove it.



Comment at: clang-tools-extra/clangd/SemanticHighlight.h:29
+struct SemanticToken {
+  SemanticToken() = default;
+  SemanticToken(SemanticHighlightKind Kind, Range R) : Kind(Kind), R(R) {}

We can get rid of the default constructor and the constructor below.



Comment at: clang-tools-extra/clangd/SemanticHighlight.h:38
+
+// Returns semantic highlights for the AST. The vector is ordered in ascending
+// order by the line number. Every symbol in LineHighlight is ordered in

The comment is out of date.



Comment at: clang-tools-extra/clangd/unittests/SemanticHighlightTests.cpp:31
+void $foo[[foo]](int $a[[a]]) {
+  auto $vlvn[[VeryLongVariableName]] = 12312;
+  A $aa[[aa]];

Thinking more about the test, I think we could improve the test to make it more 
scalable and less verbose code.

How about associating the range name (e.g. $vlan) in the annotation with the 
name in `SemanticHighlightKind`? For example, in this test case, we could use 
annotation like 

```
void $Function[foo](int $Variable[[a]]) {
   auto $Variable[[A]] = 222;
}
```

We have a common function like `checkHighlights` which verifies that all 
`Functions` and `Variable` ranges.

```
void checkHighlights(... annotation) {
  auto ActualHighlights = getHighlights(annotation.code());
  EXPECT_THAT(annotations.ranges('Function'), 
unorderedElemenetsAre(filter(ActualHighlights, 
SemanticHighlightKind::Function));
  EXPECT_THAT(annotations.ranges('Variable'), 
unorderedElemenetsAre(filter(ActualHighlights, 
SemanticHighlightKind::Variable)) 
}
```



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63559



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


[PATCH] D59963: [clang-tidy] Add a module for the Linux kernel.

2019-06-24 Thread Dmitry Vyukov via Phabricator via cfe-commits
dvyukov added a comment.

I assume you tried to run it on the kernel. Please post the current output 
somewhere.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59963



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


[PATCH] D59963: [clang-tidy] Add a module for the Linux kernel.

2019-06-24 Thread Dmitry Vyukov via Phabricator via cfe-commits
dvyukov added a comment.

Re more checks. I guess we can borrow some from the existing checkers:
https://www.kernel.org/doc/html/v4.12/dev-tools/sparse.html
https://bottest.wiki.kernel.org/coccicheck
https://lwn.net/Articles/752408/
https://lwn.net/Articles/691882/

They do some checks very well. But if we could do something better (more true 
positives, less false positives), that may be useful.
Also figuring out which of the existing checks in clang-tidy/analyzer are 
relevant/useful for kernel is another direction.
Also making the thread-safety analysis work for kernel may be a big deal.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59963



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


Re: r363985 - [test][Driver] Fix Clang :: Driver/cl-response-file.c

2019-06-24 Thread Rainer Orth via cfe-commits
Hi Douglas,

> I figured it out. Because you are using printf, you no longer need the
> '\\c'. If I use the following RUN line, the test passes on both
> Windows/linux (I don't have solaris to test unfortunately):
>
> // RUN: printf '%%s\n' '/I%S\Inputs\cl-response-file\ /DFOO=2' > %t.rsp

I've now tested it myself successfully on amd64-pc-solaris2.11.  I'd
figured the \\c -> \c part out already, but had to leave before
understanding the %s problem.

> I can submit this patch for you if you would like.

That would be great, thanks a lot.

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


r364183 - [CUDA][HIP] Don't set comdat attribute for CUDA device stub functions.\nDifferential Revision: https://reviews.llvm.org/D63277

2019-06-24 Thread Konstantin Pyzhov via cfe-commits
Author: kpyzhov
Date: Mon Jun 24 07:40:20 2019
New Revision: 364183

URL: http://llvm.org/viewvc/llvm-project?rev=364183&view=rev
Log:
[CUDA][HIP] Don't set comdat attribute for CUDA device stub 
functions.\nDifferential Revision: https://reviews.llvm.org/D63277

Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=364183&r1=364182&r2=364183&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon Jun 24 07:40:20 2019
@@ -3712,6 +3712,11 @@ static bool shouldBeInCOMDAT(CodeGenModu
   if (!CGM.supportsCOMDAT())
 return false;
 
+  // Do not set COMDAT attribute for CUDA/HIP stub functions to prevent
+  // them being "merged" by the COMDAT Folding linker optimization.
+  if (D.hasAttr())
+return false;
+
   if (D.hasAttr())
 return true;
 


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


[PATCH] D63559: [clang-tidy] Added functionality for getting semantic highlights for variable and function declarations

2019-06-24 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/clangd/SemanticHighlight.cpp:1
+#include "SemanticHighlight.h"
+#include "SourceCode.h"

License header was not added despite comment was marked as done.



Comment at: clang-tools-extra/clangd/SemanticHighlight.h:13
+//===--===//
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SEMANTICHIGHLIGHT_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SEMANTICHIGHLIGHT_H

Separator line was not added despite comment was marked as done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63559



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


[PATCH] D63718: [ADT] Implement llvm::bsearch() with std::partition_point()

2019-06-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: EricWF, sammccall.
Herald added subscribers: llvm-commits, cfe-commits, kadircet, arphaman, 
dexonsmith, jkorous.
Herald added projects: clang, LLVM.

Deprecate the begin-end form because the standard std::partition_point
can be easily used as a replacement.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63718

Files:
  clang-tools-extra/clangd/index/dex/PostingList.cpp
  llvm/include/llvm/ADT/STLExtras.h
  llvm/include/llvm/CodeGen/SlotIndexes.h
  llvm/unittests/ADT/STLExtrasTest.cpp

Index: llvm/unittests/ADT/STLExtrasTest.cpp
===
--- llvm/unittests/ADT/STLExtrasTest.cpp
+++ llvm/unittests/ADT/STLExtrasTest.cpp
@@ -470,11 +470,6 @@
 }
 
 TEST(STLExtrasTest, bsearch) {
-  // Integer version.
-  EXPECT_EQ(7u, bsearch(5, 10, [](unsigned X) { return X >= 7; }));
-  EXPECT_EQ(5u, bsearch(5, 10, [](unsigned X) { return X >= 1; }));
-  EXPECT_EQ(10u, bsearch(5, 10, [](unsigned X) { return X >= 50; }));
-
   // Iterator version.
   std::vector V = {1, 3, 5, 7, 9};
   EXPECT_EQ(V.begin() + 3,
Index: llvm/include/llvm/CodeGen/SlotIndexes.h
===
--- llvm/include/llvm/CodeGen/SlotIndexes.h
+++ llvm/include/llvm/CodeGen/SlotIndexes.h
@@ -492,8 +492,9 @@
 /// Move iterator to the next IdxMBBPair where the SlotIndex is greater or
 /// equal to \p To.
 MBBIndexIterator advanceMBBIndex(MBBIndexIterator I, SlotIndex To) const {
-  return llvm::bsearch(I, idx2MBBMap.end(),
-   [=](const IdxMBBPair &IM) { return To <= IM.first; });
+  return std::partition_point(
+  I, idx2MBBMap.end(),
+  [=](const IdxMBBPair &IM) { return IM.first < To; });
 }
 
 /// Get an iterator pointing to the IdxMBBPair with the biggest SlotIndex
Index: llvm/include/llvm/ADT/STLExtras.h
===
--- llvm/include/llvm/ADT/STLExtras.h
+++ llvm/include/llvm/ADT/STLExtras.h
@@ -1322,44 +1322,22 @@
   std::stable_sort(adl_begin(Range), adl_end(Range), C);
 }
 
-/// Binary search for the first index where a predicate is true.
-/// Returns the first I in [Lo, Hi) where C(I) is true, or Hi if it never is.
-/// Requires that C is always false below some limit, and always true above it.
-///
-/// Example:
-///   size_t DawnModernEra = bsearch(1776, 2050, [](size_t Year){
-/// return Presidents.for(Year).twitterHandle() != None;
-///   });
-///
-/// Note the return value differs from std::binary_search!
-template 
-size_t bsearch(size_t Lo, size_t Hi, Predicate P) {
-  while (Lo != Hi) {
-assert(Hi > Lo);
-size_t Mid = Lo + (Hi - Lo) / 2;
-if (P(Mid))
-  Hi = Mid;
-else
-  Lo = Mid + 1;
-  }
-  return Hi;
-}
-
+/// \deprecated Use std::partition_point.
 /// Binary search for the first iterator where a predicate is true.
 /// Returns the first I in [Lo, Hi) where C(*I) is true, or Hi if it never is.
 /// Requires that C is always false below some limit, and always true above it.
 template ())>
 It bsearch(It Lo, It Hi, Predicate P) {
-  return std::lower_bound(Lo, Hi, 0u,
-  [&](const Val &V, unsigned) { return !P(V); });
+  return std::partition_point(Lo, Hi, [&](const Val &V) { return !P(V); });
 }
 
 /// Binary search for the first iterator in a range where a predicate is true.
 /// Requires that C is always false below some limit, and always true above it.
 template 
 auto bsearch(R &&Range, Predicate P) -> decltype(adl_begin(Range)) {
-  return bsearch(adl_begin(Range), adl_end(Range), P);
+  return llvm::bsearch(adl_begin(Range), adl_end(Range),
+   std::forward(P));
 }
 
 /// Wrapper function around std::equal to detect if all elements
Index: clang-tools-extra/clangd/index/dex/PostingList.cpp
===
--- clang-tools-extra/clangd/index/dex/PostingList.cpp
+++ clang-tools-extra/clangd/index/dex/PostingList.cpp
@@ -50,8 +50,8 @@
   return;
 advanceToChunk(ID);
 // Try to find ID within current chunk.
-CurrentID = llvm::bsearch(CurrentID, DecompressedChunk.end(),
-  [&](const DocID D) { return D >= ID; });
+CurrentID = std::partition_point(CurrentID, DecompressedChunk.end(),
+ [&](const DocID D) { return D < ID; });
 normalizeCursor();
   }
 
@@ -103,8 +103,8 @@
 if ((CurrentChunk != Chunks.end() - 1) &&
 ((CurrentChunk + 1)->Head <= ID)) {
   CurrentChunk =
-  llvm::bsearch(CurrentChunk + 1, Chunks.end(),
-[&](const Chunk &C) { return C.Head >= ID; });
+  std::partition_point(CurrentChunk + 1, Chunks.end(),
+   [&](const Chunk &C) { return C.Head < ID; });
   --CurrentChunk;
   DecompressedChunk = CurrentChunk->decompress();
  

[PATCH] D62373: [ASTImporter] Store import errors for Decls

2019-06-24 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 206218.
martong marked 2 inline comments as done.
martong added a comment.

- Assert that we set the error only once
- Remove the macro and use std::string.op+


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62373

Files:
  clang/include/clang/AST/ASTImporter.h
  clang/lib/AST/ASTImporter.cpp
  clang/test/ASTMerge/class-template-partial-spec/test.cpp
  clang/unittests/AST/ASTImporterFixtures.cpp
  clang/unittests/AST/ASTImporterFixtures.h
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4620,6 +4620,127 @@
   EXPECT_EQ(Imported->getPreviousDecl(), Friend);
 }
 
+struct ASTImporterWithFakeErrors : ASTImporter {
+  using ASTImporter::ASTImporter;
+  bool returnWithErrorInTest() override { return true; }
+};
+
+struct ErrorHandlingTest : ASTImporterOptionSpecificTestBase {
+  ErrorHandlingTest() {
+Creator = [](ASTContext &ToContext, FileManager &ToFileManager,
+ ASTContext &FromContext, FileManager &FromFileManager,
+ bool MinimalImport, ASTImporterLookupTable *LookupTable) {
+  return new ASTImporterWithFakeErrors(ToContext, ToFileManager,
+   FromContext, FromFileManager,
+   MinimalImport, LookupTable);
+};
+  }
+  // In this test we purposely report an error (UnsupportedConstruct) when
+  // importing the below stmt.
+  static constexpr auto* ErroneousStmt = R"( asm(""); )";
+};
+
+// Check a case when no new AST node is created in the AST before encountering
+// the error.
+TEST_P(ErrorHandlingTest, ErrorHappensBeforeCreatingANewNode) {
+  TranslationUnitDecl *ToTU = getToTuDecl(
+  R"(
+  template 
+  class X {};
+  template <>
+  class X { int a; };
+  )",
+  Lang_CXX);
+  TranslationUnitDecl *FromTU = getTuDecl(
+  R"(
+  template 
+  class X {};
+  template <>
+  class X { double b; };
+  )",
+  Lang_CXX);
+  auto *FromSpec = FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl(hasName("X")));
+  ClassTemplateSpecializationDecl *ImportedSpec = Import(FromSpec, Lang_CXX);
+  EXPECT_FALSE(ImportedSpec);
+
+  // The original Decl is kept, no new decl is created.
+  EXPECT_EQ(DeclCounter().match(
+ToTU, classTemplateSpecializationDecl(hasName("X"))),
+1u);
+
+  // But an error is set to the counterpart in the "from" context.
+  ASTImporter *Importer = findFromTU(FromSpec)->Importer.get();
+  Optional OptErr = Importer->getImportDeclErrorIfAny(FromSpec);
+  ASSERT_TRUE(OptErr);
+  EXPECT_EQ(OptErr->Error, ImportError::NameConflict);
+}
+
+// Check a case when a new AST node is created but not linked to the AST before
+// encountering the error.
+TEST_P(ErrorHandlingTest,
+   ErrorHappensAfterCreatingTheNodeButBeforeLinkingThatToTheAST) {
+  TranslationUnitDecl *FromTU = getTuDecl(
+  std::string("void foo() { ") + ErroneousStmt + " }",
+  Lang_CXX);
+  auto *FromFoo = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("foo")));
+
+  FunctionDecl *ImportedFoo = Import(FromFoo, Lang_CXX);
+  EXPECT_FALSE(ImportedFoo);
+
+  TranslationUnitDecl *ToTU = ToAST->getASTContext().getTranslationUnitDecl();
+  // Created, but not linked.
+  EXPECT_EQ(
+  DeclCounter().match(ToTU, functionDecl(hasName("foo"))),
+  0u);
+
+  ASTImporter *Importer = findFromTU(FromFoo)->Importer.get();
+  Optional OptErr = Importer->getImportDeclErrorIfAny(FromFoo);
+  ASSERT_TRUE(OptErr);
+  EXPECT_EQ(OptErr->Error, ImportError::UnsupportedConstruct);
+}
+
+// Check a case when a new AST node is created and linked to the AST before
+// encountering the error. The error is set for the counterpart of the nodes in
+// the "from" context.
+TEST_P(ErrorHandlingTest, ErrorHappensAfterNodeIsCreatedAndLinked) {
+  TranslationUnitDecl *FromTU = getTuDecl(
+  std::string(R"(
+  void f();
+  void f() { )") + ErroneousStmt + R"( }
+  )",
+Lang_CXX);
+  auto *FromProto = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("f")));
+  auto *FromDef =
+  LastDeclMatcher().match(FromTU, functionDecl(hasName("f")));
+  FunctionDecl *ImportedProto = Import(FromProto, Lang_CXX);
+  EXPECT_FALSE(ImportedProto); // Could not import.
+  // However, we created two nodes in the AST. 1) the fwd decl 2) the
+  // definition. The definition is not added to its DC, but the fwd decl is
+  // there.
+  TranslationUnitDecl *ToTU = ToAST->getASTContext().getTranslationUnitDecl();
+  EXPECT_EQ(DeclCounter().match(ToTU, functionDecl(hasName("f"))),
+1u);
+  // Match the fwd decl.
+  auto *ToProto =
+  FirstDeclMatcher().match(ToTU, functionDecl(ha

[PATCH] D62373: [ASTImporter] Store import errors for Decls

2019-06-24 Thread Gabor Marton via Phabricator via cfe-commits
martong marked 4 inline comments as done.
martong added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:7851
+if (!getImportDeclErrorIfAny(FromD)) {
+  // Error encountered for the first time.
+  // After takeError the error is not usable any more in ToDOrErr.

balazske wrote:
> martong wrote:
> > balazske wrote:
> > > martong wrote:
> > > > a_sidorin wrote:
> > > > > Is it possible to get this error more than once?
> > > > Yes, that can happen in cyclic imports like: ClassTemplateDecl -> 
> > > > TemplatedDecl -> ClassTemplateDecl.
> > > I do not understand this completely, in this branch `setImportDeclError` 
> > > is called so at next time we can not go into this branch again (for the 
> > > same `FromD`). (We can get the error and not go into this branch more 
> > > than once but get no error and go into the branch only once.)
> > Yes, I missed that.
> > So, perhaps we can remove the condition `if 
> > (!getImportDeclErrorIfAny(FromD))` ?
> I think yes: If `!ToDOrErr` is true we have an error that was newly created 
> in `ImportImpl`. But I am not totally sure, and the ImportImpl can be 
> overridden, so it is better to not remove the condition. Or make an assert 
> out of it: `assert(!getImportDeclErrorIfAny(FromD) && "Import error already 
> set for decl.")`.
Ok, I changed to have an assertion.



Comment at: clang/unittests/AST/ASTImporterTest.cpp:4697
+DefaultTestValuesForRunOptions, );
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest,

balazske wrote:
> martong wrote:
> > balazske wrote:
> > > a_sidorin wrote:
> > > > #undef ERRONEOUSSTMT?
> > > Maybe we should not use a macro for this, specially not define the macro 
> > > inside the `struct` block. For the current tests it is sufficient to make 
> > > a std::string that contains something like `void f() { asm(""); }`.
> > My first attempt was to use std::string for the errouneous Stmt and then to 
> > use llvm::formatv to easily concatenate the test code examples.
> > However, it tunred out that formatv actively forbids the use of the braces 
> > in the source string.
> > So I decided to use a macro because that way we can build up the test code 
> > most easily.
> > What is the problem by defining the macro in a struct block? There are no 
> > blocks for the preprocessor, just directives. I'd like to indicate that the 
> > macro is used only by the test.
> The problem was that it looks like that macro is an internal thing (to the 
> struct) but in reality it is not. Probably `std::string::append` can be used 
> if possible.
Ok, I removed the macro and use rather std::string.operator+()


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62373



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


[PATCH] D63718: [ADT] Implement llvm::bsearch() with std::partition_point()

2019-06-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 206220.
MaskRay edited the summary of this revision.
MaskRay added a comment.

Delete the begin-end form


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63718

Files:
  clang-tools-extra/clangd/index/dex/PostingList.cpp
  llvm/include/llvm/ADT/STLExtras.h
  llvm/include/llvm/CodeGen/SlotIndexes.h
  llvm/unittests/ADT/STLExtrasTest.cpp

Index: llvm/unittests/ADT/STLExtrasTest.cpp
===
--- llvm/unittests/ADT/STLExtrasTest.cpp
+++ llvm/unittests/ADT/STLExtrasTest.cpp
@@ -470,19 +470,7 @@
 }
 
 TEST(STLExtrasTest, bsearch) {
-  // Integer version.
-  EXPECT_EQ(7u, bsearch(5, 10, [](unsigned X) { return X >= 7; }));
-  EXPECT_EQ(5u, bsearch(5, 10, [](unsigned X) { return X >= 1; }));
-  EXPECT_EQ(10u, bsearch(5, 10, [](unsigned X) { return X >= 50; }));
-
-  // Iterator version.
   std::vector V = {1, 3, 5, 7, 9};
-  EXPECT_EQ(V.begin() + 3,
-bsearch(V.begin(), V.end(), [](unsigned X) { return X >= 7; }));
-  EXPECT_EQ(V.begin(),
-bsearch(V.begin(), V.end(), [](unsigned X) { return X >= 1; }));
-  EXPECT_EQ(V.end(),
-bsearch(V.begin(), V.end(), [](unsigned X) { return X >= 50; }));
 
   // Range version.
   EXPECT_EQ(V.begin() + 3, bsearch(V, [](unsigned X) { return X >= 7; }));
Index: llvm/include/llvm/CodeGen/SlotIndexes.h
===
--- llvm/include/llvm/CodeGen/SlotIndexes.h
+++ llvm/include/llvm/CodeGen/SlotIndexes.h
@@ -492,8 +492,9 @@
 /// Move iterator to the next IdxMBBPair where the SlotIndex is greater or
 /// equal to \p To.
 MBBIndexIterator advanceMBBIndex(MBBIndexIterator I, SlotIndex To) const {
-  return llvm::bsearch(I, idx2MBBMap.end(),
-   [=](const IdxMBBPair &IM) { return To <= IM.first; });
+  return std::partition_point(
+  I, idx2MBBMap.end(),
+  [=](const IdxMBBPair &IM) { return IM.first < To; });
 }
 
 /// Get an iterator pointing to the IdxMBBPair with the biggest SlotIndex
Index: llvm/include/llvm/ADT/STLExtras.h
===
--- llvm/include/llvm/ADT/STLExtras.h
+++ llvm/include/llvm/ADT/STLExtras.h
@@ -1322,44 +1322,13 @@
   std::stable_sort(adl_begin(Range), adl_end(Range), C);
 }
 
-/// Binary search for the first index where a predicate is true.
-/// Returns the first I in [Lo, Hi) where C(I) is true, or Hi if it never is.
-/// Requires that C is always false below some limit, and always true above it.
-///
-/// Example:
-///   size_t DawnModernEra = bsearch(1776, 2050, [](size_t Year){
-/// return Presidents.for(Year).twitterHandle() != None;
-///   });
-///
-/// Note the return value differs from std::binary_search!
-template 
-size_t bsearch(size_t Lo, size_t Hi, Predicate P) {
-  while (Lo != Hi) {
-assert(Hi > Lo);
-size_t Mid = Lo + (Hi - Lo) / 2;
-if (P(Mid))
-  Hi = Mid;
-else
-  Lo = Mid + 1;
-  }
-  return Hi;
-}
-
-/// Binary search for the first iterator where a predicate is true.
-/// Returns the first I in [Lo, Hi) where C(*I) is true, or Hi if it never is.
-/// Requires that C is always false below some limit, and always true above it.
-template ())>
-It bsearch(It Lo, It Hi, Predicate P) {
-  return std::lower_bound(Lo, Hi, 0u,
-  [&](const Val &V, unsigned) { return !P(V); });
-}
-
 /// Binary search for the first iterator in a range where a predicate is true.
 /// Requires that C is always false below some limit, and always true above it.
-template 
+template ()))>
 auto bsearch(R &&Range, Predicate P) -> decltype(adl_begin(Range)) {
-  return bsearch(adl_begin(Range), adl_end(Range), P);
+  return std::partition_point(adl_begin(Range), adl_end(Range),
+  [&](const Val &V) { return !P(V); });
 }
 
 /// Wrapper function around std::equal to detect if all elements
Index: clang-tools-extra/clangd/index/dex/PostingList.cpp
===
--- clang-tools-extra/clangd/index/dex/PostingList.cpp
+++ clang-tools-extra/clangd/index/dex/PostingList.cpp
@@ -50,8 +50,8 @@
   return;
 advanceToChunk(ID);
 // Try to find ID within current chunk.
-CurrentID = llvm::bsearch(CurrentID, DecompressedChunk.end(),
-  [&](const DocID D) { return D >= ID; });
+CurrentID = std::partition_point(CurrentID, DecompressedChunk.end(),
+ [&](const DocID D) { return D < ID; });
 normalizeCursor();
   }
 
@@ -103,8 +103,8 @@
 if ((CurrentChunk != Chunks.end() - 1) &&
 ((CurrentChunk + 1)->Head <= ID)) {
   CurrentChunk =
-  llvm::bsearch(CurrentChunk + 1, Chunks.end(),
-[&](const Chunk &C) { return C.Head >= ID; });
+  std::pa

r364189 - [OPENMP]Relax the test checks to pacify 32bit buildbots, NFC.

2019-06-24 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Jun 24 08:30:20 2019
New Revision: 364189

URL: http://llvm.org/viewvc/llvm-project?rev=364189&view=rev
Log:
[OPENMP]Relax the test checks to pacify 32bit buildbots, NFC.

Modified:
cfe/trunk/test/OpenMP/parallel_codegen.cpp

Modified: cfe/trunk/test/OpenMP/parallel_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/parallel_codegen.cpp?rev=364189&r1=364188&r2=364189&view=diff
==
--- cfe/trunk/test/OpenMP/parallel_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/parallel_codegen.cpp Mon Jun 24 08:30:20 2019
@@ -94,7 +94,7 @@ int main (int argc, char **argv) {
 
 // CHECK:   define linkonce_odr {{[a-z\_\b]*[ ]?i32}} [[TMAIN]](i8** %argc)
 // CHECK:   store i8** %argc, i8*** [[ARGC_ADDR:%.+]],
-// CHECK:   call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, 
...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC_2]], i32 2, void 
(i32*, i32*, ...)* bitcast (void (i32*, i32*, i8***, i64)* [[OMP_OUTLINED:@.+]] 
to void (i32*, i32*, ...)*), i8*** [[ARGC_ADDR]], i64 %{{.+}})
+// CHECK:   call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, 
...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC_2]], i32 2, void 
(i32*, i32*, ...)* bitcast (void (i32*, i32*, i8***, i{{64|32}})* 
[[OMP_OUTLINED:@.+]] to void (i32*, i32*, ...)*), i8*** [[ARGC_ADDR]], 
i{{64|32}} %{{.+}})
 // CHECK-NEXT:  ret i32 0
 // CHECK-NEXT:  }
 // CHECK-DEBUG:   define linkonce_odr i32 [[TMAIN]](i8** %argc)
@@ -109,7 +109,7 @@ int main (int argc, char **argv) {
 // CHECK-DEBUG-NEXT:  ret i32 0
 // CHECK-DEBUG-NEXT:  }
 
-// CHECK:   define internal {{.*}}void [[OMP_OUTLINED]](i32* noalias 
%.global_tid., i32* noalias %.bound_tid., i8*** dereferenceable({{4|8}}) %argc, 
i64 %{{.+}})
+// CHECK:   define internal {{.*}}void [[OMP_OUTLINED]](i32* noalias 
%.global_tid., i32* noalias %.bound_tid., i8*** dereferenceable({{4|8}}) %argc, 
i{{64|32}} %{{.+}})
 // CHECK:   store i8*** %argc, i8 [[ARGC_PTR_ADDR:%.+]],
 // CHECK:   [[ARGC_REF:%.+]] = load i8***, i8 [[ARGC_PTR_ADDR]]
 // CHECK:   [[ARGC:%.+]] = load i8**, i8*** [[ARGC_REF]]


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


[PATCH] D63603: [ASTImporter] Propagate error from ImportDeclContext

2019-06-24 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 206223.
martong added a comment.

- Remove the macro and use std::string.op+


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63603

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4738,6 +4738,53 @@
   EXPECT_EQ(OptErr->Error, ImportError::UnsupportedConstruct);
 }
 
+// An error should be set for a class if we cannot import one member.
+TEST_P(ErrorHandlingTest, ErrorIsPropagatedFromMemberToClass) {
+  TranslationUnitDecl *FromTU = getTuDecl(
+  std::string(R"(
+  class X {
+void f() { )") + ErroneousStmt + R"( } // This member has the error
+   // during import.
+void ok();// The error should not prevent importing this.
+  };  // An error will be set for X too.
+  )",
+  Lang_CXX);
+  auto *FromX = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("X")));
+  CXXRecordDecl *ImportedX = Import(FromX, Lang_CXX);
+
+  // An error is set for X.
+  EXPECT_FALSE(ImportedX);
+  ASTImporter *Importer = findFromTU(FromX)->Importer.get();
+  Optional OptErr = Importer->getImportDeclErrorIfAny(FromX);
+  ASSERT_TRUE(OptErr);
+  EXPECT_EQ(OptErr->Error, ImportError::UnsupportedConstruct);
+
+  // An error is set for f().
+  auto *FromF = FirstDeclMatcher().match(
+  FromTU, cxxMethodDecl(hasName("f")));
+  OptErr = Importer->getImportDeclErrorIfAny(FromF);
+  ASSERT_TRUE(OptErr);
+  EXPECT_EQ(OptErr->Error, ImportError::UnsupportedConstruct);
+  // And any subsequent import should fail.
+  CXXMethodDecl *ImportedF = Import(FromF, Lang_CXX);
+  EXPECT_FALSE(ImportedF);
+
+  // There is no error set for ok().
+  auto *FromOK = FirstDeclMatcher().match(
+  FromTU, cxxMethodDecl(hasName("ok")));
+  OptErr = Importer->getImportDeclErrorIfAny(FromOK);
+  EXPECT_FALSE(OptErr);
+  // And we should be able to import.
+  CXXMethodDecl *ImportedOK = Import(FromOK, Lang_CXX);
+  EXPECT_TRUE(ImportedOK);
+
+  // Unwary clients may access X even if the error is set, so, at least make
+  // sure the class is set to be complete.
+  CXXRecordDecl *ToX = cast(ImportedOK->getDeclContext());
+  EXPECT_TRUE(ToX->isCompleteDefinition());
+}
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ErrorHandlingTest,
 DefaultTestValuesForRunOptions, );
 
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -1631,16 +1631,32 @@
 auto ToDCOrErr = Importer.ImportContext(FromDC);
 return ToDCOrErr.takeError();
   }
+
+  // We use strict error handling in case of records and enums, but not
+  // with e.g. namespaces.
+  //
+  // FIXME Clients of the ASTImporter should be able to choose an
+  // appropriate error handling strategy for their needs.  For instance,
+  // they may not want to mark an entire namespace as erroneous merely
+  // because there is an ODR error with two typedefs.  As another example,
+  // the client may allow EnumConstantDecls with same names but with
+  // different values in two distinct translation units.
+  bool AccumulateChildErrors = isa(FromDC);
+
+  Error ChildErrors = Error::success();
   llvm::SmallVector ImportedDecls;
   for (auto *From : FromDC->decls()) {
 ExpectedDecl ImportedOrErr = import(From);
-if (!ImportedOrErr)
-  // Ignore the error, continue with next Decl.
-  // FIXME: Handle this case somehow better.
-  consumeError(ImportedOrErr.takeError());
+if (!ImportedOrErr) {
+  if (AccumulateChildErrors)
+ChildErrors =
+joinErrors(std::move(ChildErrors), ImportedOrErr.takeError());
+  else
+consumeError(ImportedOrErr.takeError());
+}
   }
 
-  return Error::success();
+  return ChildErrors;
 }
 
 Error ASTNodeImporter::ImportDeclContext(
@@ -1697,7 +1713,15 @@
 return Error::success();
   }
 
-  To->startDefinition();
+  // Complete the definition even if error is returned.
+  // The RecordDecl may be already part of the AST so it is better to
+  // have it in complete state even if something is wrong with it.
+  struct DefinitionCompleter {
+RecordDecl *To;
+DefinitionCompleter(RecordDecl *To) : To(To) { To->startDefinition(); }
+~DefinitionCompleter() { To->completeDefinition(); }
+  };
+  DefinitionCompleter CompleterRAII(To);
 
   if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
 return Err;
@@ -1822,7 +1846,6 @@
 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
   return Err;
 
-  To->completeDefinition();
   return Error::success();
 }
 
__

[PATCH] D63720: [analyzer] ExprEngine: Escape pointers in bitwise operations

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso created this revision.
Charusso added reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, 
Szelethus.
Charusso added a project: clang.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, mikhail.ramalho, 
a.sidorin, rnkovacs, szepet.

After evaluation it would be an Unknown value and tracking would be lost.


Repository:
  rC Clang

https://reviews.llvm.org/D63720

Files:
  clang/test/Analysis/symbol-escape.cpp


Index: clang/test/Analysis/symbol-escape.cpp
===
--- /dev/null
+++ clang/test/Analysis/symbol-escape.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=cplusplus.NewDeleteLeaks \
+// RUN:  -verify %s
+
+#include 
+
+class C {};
+
+void payload(C *Foo) {
+  C *Bar = new C();
+  Bar = reinterpret_cast((reinterpret_cast(Foo) &
+   ~static_cast(0x1)) |
+  (reinterpret_cast(Bar) & 0x1));
+  (void)Bar;
+  // expected-warning@-1 {{Potential leak of memory pointed to by 'Bar'}}
+
+  delete Bar;
+}


Index: clang/test/Analysis/symbol-escape.cpp
===
--- /dev/null
+++ clang/test/Analysis/symbol-escape.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=cplusplus.NewDeleteLeaks \
+// RUN:  -verify %s
+
+#include 
+
+class C {};
+
+void payload(C *Foo) {
+  C *Bar = new C();
+  Bar = reinterpret_cast((reinterpret_cast(Foo) &
+   ~static_cast(0x1)) |
+  (reinterpret_cast(Bar) & 0x1));
+  (void)Bar;
+  // expected-warning@-1 {{Potential leak of memory pointed to by 'Bar'}}
+
+  delete Bar;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63720: [analyzer] ExprEngine: Escape pointers in bitwise operations

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

- Make the test fail.


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

https://reviews.llvm.org/D63720



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


[PATCH] D63720: [analyzer] ExprEngine: Escape pointers in bitwise operations

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 206227.
Charusso added a comment.

- Make the test pass.


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

https://reviews.llvm.org/D63720

Files:
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/Analysis/symbol-escape.cpp


Index: clang/test/Analysis/symbol-escape.cpp
===
--- clang/test/Analysis/symbol-escape.cpp
+++ clang/test/Analysis/symbol-escape.cpp
@@ -2,6 +2,8 @@
 // RUN:  -analyzer-checker=cplusplus.NewDeleteLeaks \
 // RUN:  -verify %s
 
+// expected-no-diagnostics
+
 #include 
 
 class C {};
@@ -12,7 +14,8 @@
~static_cast(0x1)) |
   (reinterpret_cast(Bar) & 0x1));
   (void)Bar;
-  // expected-warning@-1 {{Potential leak of memory pointed to by 'Bar'}}
+  // no-warning: "Potential leak of memory pointed to by 'Bar'" was here 
because
+  // the pointers are got lost inside the bitwise operations.
 
   delete Bar;
 }
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -95,6 +95,26 @@
   if (B->getOpcode() == BO_PtrMemD)
 state = createTemporaryRegionIfNeeded(state, LCtx, LHS);
 
+  // If we have a bitwise operation (e.g. checking low-bits) of a pointer
+  // we would like to escape that pointer as we do not model this 
operation.
+  if (B->isBitwiseOp()) {
+bool IsLhsPtr = false, IsRhsPtr = false;
+if (const MemRegion *LeftMR = LeftV.getAsRegion())
+  IsLhsPtr = LeftMR->getSymbolicBase();
+if (const MemRegion *RightMR = RightV.getAsRegion())
+  IsRhsPtr = RightMR->getSymbolicBase();
+
+if (IsLhsPtr)
+  state = escapeValue(state, LeftV, PSK_EscapeOther);
+if (IsRhsPtr)
+  state = escapeValue(state, RightV, PSK_EscapeOther);
+
+if (IsLhsPtr || IsRhsPtr) {
+  Bldr.generateNode(B, *it, state);
+  continue;
+}
+  }
+
   // Process non-assignments except commas or short-circuited
   // logical expressions (LAnd and LOr).
   SVal Result = evalBinOp(state, Op, LeftV, RightV, B->getType());


Index: clang/test/Analysis/symbol-escape.cpp
===
--- clang/test/Analysis/symbol-escape.cpp
+++ clang/test/Analysis/symbol-escape.cpp
@@ -2,6 +2,8 @@
 // RUN:  -analyzer-checker=cplusplus.NewDeleteLeaks \
 // RUN:  -verify %s
 
+// expected-no-diagnostics
+
 #include 
 
 class C {};
@@ -12,7 +14,8 @@
~static_cast(0x1)) |
   (reinterpret_cast(Bar) & 0x1));
   (void)Bar;
-  // expected-warning@-1 {{Potential leak of memory pointed to by 'Bar'}}
+  // no-warning: "Potential leak of memory pointed to by 'Bar'" was here because
+  // the pointers are got lost inside the bitwise operations.
 
   delete Bar;
 }
Index: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
@@ -95,6 +95,26 @@
   if (B->getOpcode() == BO_PtrMemD)
 state = createTemporaryRegionIfNeeded(state, LCtx, LHS);
 
+  // If we have a bitwise operation (e.g. checking low-bits) of a pointer
+  // we would like to escape that pointer as we do not model this operation.
+  if (B->isBitwiseOp()) {
+bool IsLhsPtr = false, IsRhsPtr = false;
+if (const MemRegion *LeftMR = LeftV.getAsRegion())
+  IsLhsPtr = LeftMR->getSymbolicBase();
+if (const MemRegion *RightMR = RightV.getAsRegion())
+  IsRhsPtr = RightMR->getSymbolicBase();
+
+if (IsLhsPtr)
+  state = escapeValue(state, LeftV, PSK_EscapeOther);
+if (IsRhsPtr)
+  state = escapeValue(state, RightV, PSK_EscapeOther);
+
+if (IsLhsPtr || IsRhsPtr) {
+  Bldr.generateNode(B, *it, state);
+  continue;
+}
+  }
+
   // Process non-assignments except commas or short-circuited
   // logical expressions (LAnd and LOr).
   SVal Result = evalBinOp(state, Op, LeftV, RightV, B->getType());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63714: [clangd] Cleanup the duplicated getTokenRange.

2019-06-24 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/XRefs.cpp:926
   for (const auto &Ref : MainFileRefs) {
 Location Result;
+if (auto Range =

nit: move declaration into if body?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63714



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


[PATCH] D62375: [ASTImporter] Mark erroneous nodes in from ctx

2019-06-24 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 206228.
martong added a comment.

- Remove the macro and use std::string.op+
- We may set up an error twice in case of a cycle, thus remove the assert


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62375

Files:
  clang/include/clang/AST/ASTImporter.h
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -358,6 +358,106 @@
   EXPECT_EQ(0U, count);
 }
 
+struct ImportPath : ASTImporterOptionSpecificTestBase {
+  Decl *FromTU;
+  FunctionDecl *D0, *D1, *D2;
+  ImportPath() {
+FromTU = getTuDecl("void f(); void f(); void f();", Lang_CXX);
+auto Pattern = functionDecl(hasName("f"));
+D0 = FirstDeclMatcher().match(FromTU, Pattern);
+D2 = LastDeclMatcher().match(FromTU, Pattern);
+D1 = D2->getPreviousDecl();
+  }
+};
+
+TEST_P(ImportPath, Push) {
+  ASTImporter::ImportPathTy path;
+  path.push(D0);
+  EXPECT_FALSE(path.hasCycleAtBack());
+}
+
+TEST_P(ImportPath, SmallCycle) {
+  ASTImporter::ImportPathTy path;
+  path.push(D0);
+  path.push(D0);
+  EXPECT_TRUE(path.hasCycleAtBack());
+  path.pop();
+  EXPECT_FALSE(path.hasCycleAtBack());
+  path.push(D0);
+  EXPECT_TRUE(path.hasCycleAtBack());
+}
+
+TEST_P(ImportPath, GetSmallCycle) {
+  ASTImporter::ImportPathTy path;
+  path.push(D0);
+  path.push(D0);
+  EXPECT_TRUE(path.hasCycleAtBack());
+  std::array Res;
+  int i = 0;
+  for (Decl *Di : path.getCycleAtBack()) {
+Res[i++] = Di;
+  }
+  ASSERT_EQ(i, 2);
+  EXPECT_EQ(Res[0], D0);
+  EXPECT_EQ(Res[1], D0);
+}
+
+TEST_P(ImportPath, GetCycle) {
+  ASTImporter::ImportPathTy path;
+  path.push(D0);
+  path.push(D1);
+  path.push(D2);
+  path.push(D0);
+  EXPECT_TRUE(path.hasCycleAtBack());
+  std::array Res;
+  int i = 0;
+  for (Decl *Di : path.getCycleAtBack()) {
+Res[i++] = Di;
+  }
+  ASSERT_EQ(i, 4);
+  EXPECT_EQ(Res[0], D0);
+  EXPECT_EQ(Res[1], D2);
+  EXPECT_EQ(Res[2], D1);
+  EXPECT_EQ(Res[3], D0);
+}
+
+TEST_P(ImportPath, CycleAfterCycle) {
+  ASTImporter::ImportPathTy path;
+  path.push(D0);
+  path.push(D1);
+  path.push(D0);
+  path.push(D1);
+  path.push(D2);
+  path.push(D0);
+  EXPECT_TRUE(path.hasCycleAtBack());
+  std::array Res;
+  int i = 0;
+  for (Decl *Di : path.getCycleAtBack()) {
+Res[i++] = Di;
+  }
+  ASSERT_EQ(i, 4);
+  EXPECT_EQ(Res[0], D0);
+  EXPECT_EQ(Res[1], D2);
+  EXPECT_EQ(Res[2], D1);
+  EXPECT_EQ(Res[3], D0);
+
+  path.pop();
+  path.pop();
+  path.pop();
+  EXPECT_TRUE(path.hasCycleAtBack());
+  i = 0;
+  for (Decl *Di : path.getCycleAtBack()) {
+Res[i++] = Di;
+  }
+  ASSERT_EQ(i, 3);
+  EXPECT_EQ(Res[0], D0);
+  EXPECT_EQ(Res[1], D1);
+  EXPECT_EQ(Res[2], D0);
+
+  path.pop();
+  EXPECT_FALSE(path.hasCycleAtBack());
+}
+
 TEST_P(ImportExpr, ImportStringLiteral) {
   MatchVerifier Verifier;
   testImport(
@@ -4547,12 +4647,6 @@
   EXPECT_EQ(*Res.begin(), A);
 }
 
-INSTANTIATE_TEST_CASE_P(ParameterizedTests, DeclContextTest,
-::testing::Values(ArgVector()), );
-
-INSTANTIATE_TEST_CASE_P(
-ParameterizedTests, CanonicalRedeclChain,
-::testing::Values(ArgVector()),);
 
 // FIXME This test is disabled currently, upcoming patches will make it
 // possible to enable.
@@ -4770,27 +4864,116 @@
   CXXMethodDecl *ImportedF = Import(FromF, Lang_CXX);
   EXPECT_FALSE(ImportedF);
 
-  // There is no error set for ok().
+  // There is an error set for the other member too.
   auto *FromOK = FirstDeclMatcher().match(
   FromTU, cxxMethodDecl(hasName("ok")));
   OptErr = Importer->getImportDeclErrorIfAny(FromOK);
-  EXPECT_FALSE(OptErr);
-  // And we should be able to import.
+  EXPECT_TRUE(OptErr);
+  // Cannot import the other member.
   CXXMethodDecl *ImportedOK = Import(FromOK, Lang_CXX);
-  EXPECT_TRUE(ImportedOK);
+  EXPECT_FALSE(ImportedOK);
+}
 
-  // Unwary clients may access X even if the error is set, so, at least make
-  // sure the class is set to be complete.
-  CXXRecordDecl *ToX = cast(ImportedOK->getDeclContext());
-  EXPECT_TRUE(ToX->isCompleteDefinition());
+// Check that an error propagates to the dependent AST nodes.
+// In the below code it means that an error in X should propagate to A.
+// And even to F since the containing A is erroneous.
+// And to all AST nodes which we visit during the import process which finally
+// ends up in a failure (in the error() function).
+TEST_P(ErrorHandlingTest, ErrorPropagatesThroughImportCycles) {
+  Decl *FromTU = getTuDecl(
+  std::string(R"(
+  namespace NS {
+class A {
+  template  class F {};
+  class X {
+template  friend class F;
+void error() { )") + ErroneousStmt + R"( }
+  };
+};
+
+class B {};
+  } // NS
+  )",
+  L

[PATCH] D62804: [clangd] Enable extraction of system includes from custom toolchains

2019-06-24 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 206231.
kadircet marked 9 inline comments as done.
kadircet added a comment.

- Rename SystemIncludeExtractor to QueryDriverDatabase
- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62804

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/GlobalCompilationDatabase.h
  clang-tools-extra/clangd/QueryDriverDatabase.cpp
  clang-tools-extra/clangd/test/system-include-extractor.test
  clang-tools-extra/clangd/tool/ClangdMain.cpp

Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -268,6 +268,15 @@
 "Always used text-based completion")),
 llvm::cl::init(CodeCompleteOptions().RunParser), llvm::cl::Hidden);
 
+static llvm::cl::list QueryDriverGlobs(
+"query-driver",
+llvm::cl::desc(
+"Comma separated list of globs for white-listing gcc-compatible "
+"drivers that are safe to execute. Drivers matching any of these globs "
+"will be used to extract system includes. e.g. "
+"/usr/bin/**/clang-*,/path/to/repo/**/g++-*"),
+llvm::cl::CommaSeparated);
+
 namespace {
 
 /// \brief Supports a test URI scheme with relaxed constraints for lit tests.
@@ -521,6 +530,7 @@
 };
   }
   Opts.SuggestMissingIncludes = SuggestMissingIncludes;
+  Opts.QueryDriverGlobs = std::move(QueryDriverGlobs);
   llvm::Optional OffsetEncodingFromFlag;
   if (ForceOffsetEncoding != OffsetEncoding::UnsupportedEncoding)
 OffsetEncodingFromFlag = ForceOffsetEncoding;
Index: clang-tools-extra/clangd/test/system-include-extractor.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/system-include-extractor.test
@@ -0,0 +1,50 @@
+# RUN: rm -rf %t.dir && mkdir -p %t.dir
+
+# Generate a mock-driver that will print %temp_dir%/my/dir and
+# %temp_dir%/my/dir2 as include search paths.
+# RUN: echo '#!/bin/bash' >> %t.dir/my_driver.sh
+# RUN: echo 'echo line to ignore' >> %t.dir/my_driver.sh
+# RUN: echo 'echo \#include \<...\> search starts here:' >> %t.dir/my_driver.sh
+# RUN: echo 'echo %t.dir/my/dir/' >> %t.dir/my_driver.sh
+# RUN: echo 'echo %t.dir/my/dir2/' >> %t.dir/my_driver.sh
+# RUN: echo 'echo End of search list.' >> %t.dir/my_driver.sh
+# RUN: chmod +x %t.dir/my_driver.sh
+
+# Create header files my/dir/a.h and my/dir2/b.h
+# RUN: mkdir -p %t.dir/my/dir
+# RUN: touch %t.dir/my/dir/a.h
+# RUN: mkdir -p %t.dir/my/dir2
+# RUN: touch %t.dir/my/dir2/b.h
+
+# Generate a compile_commands.json that will query the mock driver we've
+# created. Which should add a.h and b.h into include search path.
+# RUN: echo '[{"directory": "%/t.dir", "command": "%/t.dir/my_driver.sh the-file.cpp", "file": "the-file.cpp"}]' > %t.dir/compile_commands.json
+
+# RUN: sed -e "s|INPUT_DIR|%/t.dir|g" %s > %t.test.1
+# On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..."
+# (with the extra slash in the front), so we add it here.
+# RUN: sed -e "s|file://\([A-Z]\):/|file:///\1:/|g" %t.test.1 > %t.test
+
+# Bless the mock driver we've just created so that clangd can execute it.
+# RUN: clangd -lit-test -query-driver="**.test,**.sh" < %t.test | FileCheck -strict-whitespace %t.test
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{}}
+---
+{
+  "jsonrpc":"2.0",
+  "method":"textDocument/didOpen",
+  "params": {
+"textDocument": {
+  "uri": "file://INPUT_DIR/the-file.cpp",
+  "languageId":"cpp",
+  "version":1,
+  "text":"#include \n#include "
+}
+  }
+}
+# CHECK:   "method": "textDocument/publishDiagnostics",
+# CHECK-NEXT:   "params": {
+# CHECK-NEXT: "diagnostics": [],
+---
+{"jsonrpc":"2.0","id":1,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
Index: clang-tools-extra/clangd/QueryDriverDatabase.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/QueryDriverDatabase.cpp
@@ -0,0 +1,265 @@
+//===--- QueryDriverDatabase.cpp -*- C++-*-===//
+//
+// 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
+//
+//===--===//
+// Some compiler drivers have implicit search mechanism for system headers.
+// This compilation database implementation tries to extract that information by
+// executing the driver in verbose mode. gcc-compatible drivers print something
+// like:
+// 
+// 
+// #include <...> search starts here:
+//  /us

[PATCH] D62375: [ASTImporter] Mark erroneous nodes in from ctx

2019-06-24 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:8647
-  assert(ImportDeclErrors.find(From) == ImportDeclErrors.end() &&
- "Setting import error allowed only once for a Decl.");
   ImportDeclErrors[From] = Error;

We should not remove this assert? (Or check if the error is the same, otherwise 
keep the first or last error? Normally if we set an error multiple times it 
should be the same error otherwise something is wrong with the import.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62375



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


r364193 - [analyzer] Fix JSON dumps for ExplodedNodes

2019-06-24 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Mon Jun 24 09:06:44 2019
New Revision: 364193

URL: http://llvm.org/viewvc/llvm-project?rev=364193&view=rev
Log:
[analyzer] Fix JSON dumps for ExplodedNodes

Summary:
- Now we could see the `has_report` property in `trim-egraph` mode.
- This patch also removes the trailing comma after each node.

Reviewers: NoQ

Reviewed By: NoQ

Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin,
 mikhail.ramalho, Szelethus, donat.nagy, dkrupp, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/test/Analysis/dump_egraph.c

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=364193&r1=364192&r2=364193&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Mon Jun 24 09:06:44 2019
@@ -3009,7 +3009,7 @@ struct DOTGraphTraits :
 
 for (const auto &EQ : EQClasses) {
   for (const BugReport &Report : EQ) {
-if (Report.getErrorNode() == N)
+if (Report.getErrorNode()->getState() == N->getState())
   return true;
   }
 }
@@ -3109,11 +3109,7 @@ struct DOTGraphTraits :
   Indent(Out, Space, IsDot) << "\"program_state\": null";
 }
 
-Out << "\\l}";
-if (!N->succ_empty())
-  Out << ',';
-Out << "\\l";
-
+Out << "\\l}\\l";
 return Out.str();
   }
 };

Modified: cfe/trunk/test/Analysis/dump_egraph.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dump_egraph.c?rev=364193&r1=364192&r2=364193&view=diff
==
--- cfe/trunk/test/Analysis/dump_egraph.c (original)
+++ cfe/trunk/test/Analysis/dump_egraph.c Mon Jun 24 09:06:44 2019
@@ -1,6 +1,12 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-dump-egraph=%t.dot 
%s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:  -analyzer-dump-egraph=%t.dot %s
 // RUN: cat %t.dot | FileCheck %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-dump-egraph=%t.dot 
-trim-egraph %s
+
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:  -analyzer-dump-egraph=%t.dot \
+// RUN:  -trim-egraph %s
+// RUN: cat %t.dot | FileCheck %s
+
 // REQUIRES: asserts
 
 int getJ();
@@ -10,8 +16,6 @@ int foo() {
   return *x + *y;
 }
 
-// CHECK: digraph "Exploded Graph" {
-
 // CHECK: \"program_points\": [\l\{ \"kind\": 
\"Edge\", \"src_id\": 2, \"dst_id\": 1, \"terminator\": null, \"term_kind\": 
null, \"tag\": null \}\l  ],\l  \"program_state\": null
 
 // CHECK: \"program_points\": [\l\{ \"kind\": 
\"BlockEntrance\", \"block_id\": 1


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


[PATCH] D63436: [analyzer] Fix JSON dumps for ExplodedNodes

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Charusso marked an inline comment as done.
Closed by commit rL364193: [analyzer] Fix JSON dumps for ExplodedNodes 
(authored by Charusso, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63436?vs=205208&id=206234#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63436

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
  cfe/trunk/test/Analysis/dump_egraph.c


Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -3009,7 +3009,7 @@
 
 for (const auto &EQ : EQClasses) {
   for (const BugReport &Report : EQ) {
-if (Report.getErrorNode() == N)
+if (Report.getErrorNode()->getState() == N->getState())
   return true;
   }
 }
@@ -3109,11 +3109,7 @@
   Indent(Out, Space, IsDot) << "\"program_state\": null";
 }
 
-Out << "\\l}";
-if (!N->succ_empty())
-  Out << ',';
-Out << "\\l";
-
+Out << "\\l}\\l";
 return Out.str();
   }
 };
Index: cfe/trunk/test/Analysis/dump_egraph.c
===
--- cfe/trunk/test/Analysis/dump_egraph.c
+++ cfe/trunk/test/Analysis/dump_egraph.c
@@ -1,6 +1,12 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-dump-egraph=%t.dot 
%s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:  -analyzer-dump-egraph=%t.dot %s
 // RUN: cat %t.dot | FileCheck %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-dump-egraph=%t.dot 
-trim-egraph %s
+
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:  -analyzer-dump-egraph=%t.dot \
+// RUN:  -trim-egraph %s
+// RUN: cat %t.dot | FileCheck %s
+
 // REQUIRES: asserts
 
 int getJ();
@@ -10,8 +16,6 @@
   return *x + *y;
 }
 
-// CHECK: digraph "Exploded Graph" {
-
 // CHECK: \"program_points\": [\l\{ \"kind\": 
\"Edge\", \"src_id\": 2, \"dst_id\": 1, \"terminator\": null, \"term_kind\": 
null, \"tag\": null \}\l  ],\l  \"program_state\": null
 
 // CHECK: \"program_points\": [\l\{ \"kind\": 
\"BlockEntrance\", \"block_id\": 1


Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -3009,7 +3009,7 @@
 
 for (const auto &EQ : EQClasses) {
   for (const BugReport &Report : EQ) {
-if (Report.getErrorNode() == N)
+if (Report.getErrorNode()->getState() == N->getState())
   return true;
   }
 }
@@ -3109,11 +3109,7 @@
   Indent(Out, Space, IsDot) << "\"program_state\": null";
 }
 
-Out << "\\l}";
-if (!N->succ_empty())
-  Out << ',';
-Out << "\\l";
-
+Out << "\\l}\\l";
 return Out.str();
   }
 };
Index: cfe/trunk/test/Analysis/dump_egraph.c
===
--- cfe/trunk/test/Analysis/dump_egraph.c
+++ cfe/trunk/test/Analysis/dump_egraph.c
@@ -1,6 +1,12 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-dump-egraph=%t.dot %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:  -analyzer-dump-egraph=%t.dot %s
 // RUN: cat %t.dot | FileCheck %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-dump-egraph=%t.dot -trim-egraph %s
+
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:  -analyzer-dump-egraph=%t.dot \
+// RUN:  -trim-egraph %s
+// RUN: cat %t.dot | FileCheck %s
+
 // REQUIRES: asserts
 
 int getJ();
@@ -10,8 +16,6 @@
   return *x + *y;
 }
 
-// CHECK: digraph "Exploded Graph" {
-
 // CHECK: \"program_points\": [\l\{ \"kind\": \"Edge\", \"src_id\": 2, \"dst_id\": 1, \"terminator\": null, \"term_kind\": null, \"tag\": null \}\l  ],\l  \"program_state\": null
 
 // CHECK: \"program_points\": [\l\{ \"kind\": \"BlockEntrance\", \"block_id\": 1
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r364197 - [analyzer] print() JSONify: ProgramPoint revision

2019-06-24 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Mon Jun 24 09:19:39 2019
New Revision: 364197

URL: http://llvm.org/viewvc/llvm-project?rev=364197&view=rev
Log:
[analyzer] print() JSONify: ProgramPoint revision

Summary: Now we also print out the filename with its path.

Reviewers: NoQ

Reviewed By: NoQ

Subscribers: xazax.hun, baloghadamsoftware, szepet, a.sidorin,
 mikhail.ramalho, Szelethus, donat.nagy, dkrupp, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/Analysis/ProgramPoint.cpp
cfe/trunk/test/Analysis/dump_egraph.c

Modified: cfe/trunk/lib/Analysis/ProgramPoint.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/ProgramPoint.cpp?rev=364197&r1=364196&r2=364197&view=diff
==
--- cfe/trunk/lib/Analysis/ProgramPoint.cpp (original)
+++ cfe/trunk/lib/Analysis/ProgramPoint.cpp Mon Jun 24 09:19:39 2019
@@ -55,7 +55,8 @@ static void printLocJson(raw_ostream &Ou
   }
 
   Out << "{ \"line\": " << SM.getExpansionLineNumber(Loc)
-  << ", \"column\": " << SM.getExpansionColumnNumber(Loc) << " }";
+  << ", \"column\": " << SM.getExpansionColumnNumber(Loc)
+  << ", \"file\": \"" << SM.getFilename(Loc) << "\" }";
 }
 
 void ProgramPoint::printJson(llvm::raw_ostream &Out, const char *NL) const {

Modified: cfe/trunk/test/Analysis/dump_egraph.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dump_egraph.c?rev=364197&r1=364196&r2=364197&view=diff
==
--- cfe/trunk/test/Analysis/dump_egraph.c (original)
+++ cfe/trunk/test/Analysis/dump_egraph.c Mon Jun 24 09:19:39 2019
@@ -22,3 +22,5 @@ int foo() {
 
 // CHECK: \"has_report\": true
 
+// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 16, \"column\": 10, 
\"file\": \"{{(.+)}}dump_egraph.c\" \}
+


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


[PATCH] D63438: [analyzer] print() JSONify: ProgramPoint revision

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL364197: [analyzer] print() JSONify: ProgramPoint revision 
(authored by Charusso, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63438?vs=205209&id=206238#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63438

Files:
  cfe/trunk/lib/Analysis/ProgramPoint.cpp
  cfe/trunk/test/Analysis/dump_egraph.c


Index: cfe/trunk/lib/Analysis/ProgramPoint.cpp
===
--- cfe/trunk/lib/Analysis/ProgramPoint.cpp
+++ cfe/trunk/lib/Analysis/ProgramPoint.cpp
@@ -55,7 +55,8 @@
   }
 
   Out << "{ \"line\": " << SM.getExpansionLineNumber(Loc)
-  << ", \"column\": " << SM.getExpansionColumnNumber(Loc) << " }";
+  << ", \"column\": " << SM.getExpansionColumnNumber(Loc)
+  << ", \"file\": \"" << SM.getFilename(Loc) << "\" }";
 }
 
 void ProgramPoint::printJson(llvm::raw_ostream &Out, const char *NL) const {
Index: cfe/trunk/test/Analysis/dump_egraph.c
===
--- cfe/trunk/test/Analysis/dump_egraph.c
+++ cfe/trunk/test/Analysis/dump_egraph.c
@@ -22,3 +22,5 @@
 
 // CHECK: \"has_report\": true
 
+// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 16, \"column\": 10, 
\"file\": \"{{(.+)}}dump_egraph.c\" \}
+


Index: cfe/trunk/lib/Analysis/ProgramPoint.cpp
===
--- cfe/trunk/lib/Analysis/ProgramPoint.cpp
+++ cfe/trunk/lib/Analysis/ProgramPoint.cpp
@@ -55,7 +55,8 @@
   }
 
   Out << "{ \"line\": " << SM.getExpansionLineNumber(Loc)
-  << ", \"column\": " << SM.getExpansionColumnNumber(Loc) << " }";
+  << ", \"column\": " << SM.getExpansionColumnNumber(Loc)
+  << ", \"file\": \"" << SM.getFilename(Loc) << "\" }";
 }
 
 void ProgramPoint::printJson(llvm::raw_ostream &Out, const char *NL) const {
Index: cfe/trunk/test/Analysis/dump_egraph.c
===
--- cfe/trunk/test/Analysis/dump_egraph.c
+++ cfe/trunk/test/Analysis/dump_egraph.c
@@ -22,3 +22,5 @@
 
 // CHECK: \"has_report\": true
 
+// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 16, \"column\": 10, \"file\": \"{{(.+)}}dump_egraph.c\" \}
+
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63256: [OpenCL] Split type and macro definitions into opencl-c-base.h

2019-06-24 Thread Konstantin Zhuravlyov via Phabricator via cfe-commits
kzhuravl added inline comments.



Comment at: cfe/trunk/lib/Headers/opencl-c.h:13638-13640
-#ifndef ATOMIC_VAR_INIT
-#define ATOMIC_VAR_INIT(x) (x)
-#endif //ATOMIC_VAR_INIT

svenvh wrote:
> yaxunl wrote:
> > kzhuravl wrote:
> > > Any reason this piece of code got completely removed?
> > Removing ATOMIC_VAR_INIT caused regression in our compiler.
> > 
> > Could you please put it back?
> > 
> > Thanks.
> Apologies, that was not intended; thanks for reporting!  Restored the macro 
> in r364174 together with a test.
Thanks!


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63256



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


[PATCH] D62375: [ASTImporter] Mark erroneous nodes in from ctx

2019-06-24 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 206244.
martong added a comment.

- Add back an assertion in setImportDeclError(), remove the condition in 
Import()


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62375

Files:
  clang/include/clang/AST/ASTImporter.h
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -358,6 +358,106 @@
   EXPECT_EQ(0U, count);
 }
 
+struct ImportPath : ASTImporterOptionSpecificTestBase {
+  Decl *FromTU;
+  FunctionDecl *D0, *D1, *D2;
+  ImportPath() {
+FromTU = getTuDecl("void f(); void f(); void f();", Lang_CXX);
+auto Pattern = functionDecl(hasName("f"));
+D0 = FirstDeclMatcher().match(FromTU, Pattern);
+D2 = LastDeclMatcher().match(FromTU, Pattern);
+D1 = D2->getPreviousDecl();
+  }
+};
+
+TEST_P(ImportPath, Push) {
+  ASTImporter::ImportPathTy path;
+  path.push(D0);
+  EXPECT_FALSE(path.hasCycleAtBack());
+}
+
+TEST_P(ImportPath, SmallCycle) {
+  ASTImporter::ImportPathTy path;
+  path.push(D0);
+  path.push(D0);
+  EXPECT_TRUE(path.hasCycleAtBack());
+  path.pop();
+  EXPECT_FALSE(path.hasCycleAtBack());
+  path.push(D0);
+  EXPECT_TRUE(path.hasCycleAtBack());
+}
+
+TEST_P(ImportPath, GetSmallCycle) {
+  ASTImporter::ImportPathTy path;
+  path.push(D0);
+  path.push(D0);
+  EXPECT_TRUE(path.hasCycleAtBack());
+  std::array Res;
+  int i = 0;
+  for (Decl *Di : path.getCycleAtBack()) {
+Res[i++] = Di;
+  }
+  ASSERT_EQ(i, 2);
+  EXPECT_EQ(Res[0], D0);
+  EXPECT_EQ(Res[1], D0);
+}
+
+TEST_P(ImportPath, GetCycle) {
+  ASTImporter::ImportPathTy path;
+  path.push(D0);
+  path.push(D1);
+  path.push(D2);
+  path.push(D0);
+  EXPECT_TRUE(path.hasCycleAtBack());
+  std::array Res;
+  int i = 0;
+  for (Decl *Di : path.getCycleAtBack()) {
+Res[i++] = Di;
+  }
+  ASSERT_EQ(i, 4);
+  EXPECT_EQ(Res[0], D0);
+  EXPECT_EQ(Res[1], D2);
+  EXPECT_EQ(Res[2], D1);
+  EXPECT_EQ(Res[3], D0);
+}
+
+TEST_P(ImportPath, CycleAfterCycle) {
+  ASTImporter::ImportPathTy path;
+  path.push(D0);
+  path.push(D1);
+  path.push(D0);
+  path.push(D1);
+  path.push(D2);
+  path.push(D0);
+  EXPECT_TRUE(path.hasCycleAtBack());
+  std::array Res;
+  int i = 0;
+  for (Decl *Di : path.getCycleAtBack()) {
+Res[i++] = Di;
+  }
+  ASSERT_EQ(i, 4);
+  EXPECT_EQ(Res[0], D0);
+  EXPECT_EQ(Res[1], D2);
+  EXPECT_EQ(Res[2], D1);
+  EXPECT_EQ(Res[3], D0);
+
+  path.pop();
+  path.pop();
+  path.pop();
+  EXPECT_TRUE(path.hasCycleAtBack());
+  i = 0;
+  for (Decl *Di : path.getCycleAtBack()) {
+Res[i++] = Di;
+  }
+  ASSERT_EQ(i, 3);
+  EXPECT_EQ(Res[0], D0);
+  EXPECT_EQ(Res[1], D1);
+  EXPECT_EQ(Res[2], D0);
+
+  path.pop();
+  EXPECT_FALSE(path.hasCycleAtBack());
+}
+
 TEST_P(ImportExpr, ImportStringLiteral) {
   MatchVerifier Verifier;
   testImport(
@@ -4547,12 +4647,6 @@
   EXPECT_EQ(*Res.begin(), A);
 }
 
-INSTANTIATE_TEST_CASE_P(ParameterizedTests, DeclContextTest,
-::testing::Values(ArgVector()), );
-
-INSTANTIATE_TEST_CASE_P(
-ParameterizedTests, CanonicalRedeclChain,
-::testing::Values(ArgVector()),);
 
 // FIXME This test is disabled currently, upcoming patches will make it
 // possible to enable.
@@ -4770,27 +4864,116 @@
   CXXMethodDecl *ImportedF = Import(FromF, Lang_CXX);
   EXPECT_FALSE(ImportedF);
 
-  // There is no error set for ok().
+  // There is an error set for the other member too.
   auto *FromOK = FirstDeclMatcher().match(
   FromTU, cxxMethodDecl(hasName("ok")));
   OptErr = Importer->getImportDeclErrorIfAny(FromOK);
-  EXPECT_FALSE(OptErr);
-  // And we should be able to import.
+  EXPECT_TRUE(OptErr);
+  // Cannot import the other member.
   CXXMethodDecl *ImportedOK = Import(FromOK, Lang_CXX);
-  EXPECT_TRUE(ImportedOK);
+  EXPECT_FALSE(ImportedOK);
+}
 
-  // Unwary clients may access X even if the error is set, so, at least make
-  // sure the class is set to be complete.
-  CXXRecordDecl *ToX = cast(ImportedOK->getDeclContext());
-  EXPECT_TRUE(ToX->isCompleteDefinition());
+// Check that an error propagates to the dependent AST nodes.
+// In the below code it means that an error in X should propagate to A.
+// And even to F since the containing A is erroneous.
+// And to all AST nodes which we visit during the import process which finally
+// ends up in a failure (in the error() function).
+TEST_P(ErrorHandlingTest, ErrorPropagatesThroughImportCycles) {
+  Decl *FromTU = getTuDecl(
+  std::string(R"(
+  namespace NS {
+class A {
+  template  class F {};
+  class X {
+template  friend class F;
+void error() { )") + ErroneousStmt + R"( }
+  };
+};
+
+class B {};
+  } // NS
+  )",
+  Lang_CXX, "input0.cc");
+
+  auto *

[PATCH] D63720: [analyzer] ExprEngine: Escape pointers in bitwise operations

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

These bitwise operations only affects the part which we do not analyze. My 
previous approach to solve this problem caused one false positive, so we should 
be that strict. Just in case for the future developments, copy-pasted here:

  // If we have a bitwise operation (e.g. checking low-bits) of a pointer
  // we would like to keep the pointer to work with it later. Otherwise it  
  // would be an Unknown value after evaluation and we would lost tracking.  
  if (B->isBitwiseOp()) {
bool IsLhsPtr = false, IsRhsPtr = false;
const MemRegion *LeftMR = nullptr, *RightMR = nullptr;  
 
if ((LeftMR = LeftV.getAsRegion()))  
  IsLhsPtr = LeftMR->getSymbolicBase();  
if ((RightMR = RightV.getAsRegion()))
  IsRhsPtr = RightMR->getSymbolicBase();
 
// If only one of the operands is a pointer we should keep it.  
if (IsLhsPtr ^ IsRhsPtr) {  
  SVal KeepV = IsLhsPtr ? LeftV : RightV;
  state = state->BindExpr(B, LCtx, KeepV);  
  Bldr.generateNode(B, *it, state);  
  continue;  
}
 
// If both of the operands are pointers we would like to keep the one
// which dominates. Treat the lower-level pointer as a helper to set up  
// some low-bits of the higher-level pointer and keep the latter.
if (IsLhsPtr && IsRhsPtr) {  
  bool IsLhsDominates = false, IsRhsDominates = false;  
 
  if (const MemRegion *LeftBase = LeftMR->getBaseRegion())  
if (const MemSpaceRegion *LeftMS = LeftBase->getMemorySpace())  
  IsLhsDominates = isa(LeftMS);
 
  if (const MemRegion *RightBase = RightMR->getBaseRegion())
if (const MemSpaceRegion *RightMS = RightBase->getMemorySpace())
  IsRhsDominates = isa(RightMS);
 
  if (IsLhsDominates ^ IsRhsDominates) {
SVal KeepDominatorV = IsLhsDominates ? LeftV : RightV;  
state = state->BindExpr(B, LCtx, KeepDominatorV);
Bldr.generateNode(B, *it, state);
continue;
  }  
}
  }


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

https://reviews.llvm.org/D63720



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


[PATCH] D62375: [ASTImporter] Mark erroneous nodes in from ctx

2019-06-24 Thread Gabor Marton via Phabricator via cfe-commits
martong marked 2 inline comments as done.
martong added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:8647
-  assert(ImportDeclErrors.find(From) == ImportDeclErrors.end() &&
- "Setting import error allowed only once for a Decl.");
   ImportDeclErrors[From] = Error;

balazske wrote:
> We should not remove this assert? (Or check if the error is the same, 
> otherwise keep the first or last error? Normally if we set an error multiple 
> times it should be the same error otherwise something is wrong with the 
> import.)
Well, yes that is a good point. I was thinking about a theoretical scenario 
where we could set two different Errors for the same node, but failed to 
fabricate one. So I added an assert that they have the same kind,


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62375



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


r364201 - [clang][NewPM] Remove exception handling before loading pgo sample profile data

2019-06-24 Thread Leonard Chan via cfe-commits
Author: leonardchan
Date: Mon Jun 24 09:44:27 2019
New Revision: 364201

URL: http://llvm.org/viewvc/llvm-project?rev=364201&view=rev
Log:
[clang][NewPM] Remove exception handling before loading pgo sample profile data

This patch ensures that SimplifyCFGPass comes before SampleProfileLoaderPass
on PGO runs in the new PM and fixes clang/test/CodeGen/pgo-sample.c.

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

Modified:
cfe/trunk/test/CodeGen/pgo-sample.c

Modified: cfe/trunk/test/CodeGen/pgo-sample.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/pgo-sample.c?rev=364201&r1=364200&r2=364201&view=diff
==
--- cfe/trunk/test/CodeGen/pgo-sample.c (original)
+++ cfe/trunk/test/CodeGen/pgo-sample.c Mon Jun 24 09:44:27 2019
@@ -1,6 +1,13 @@
 // Test if PGO sample use passes are invoked.
 //
 // Ensure Pass PGOInstrumentationGenPass is invoked.
-// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s 
-mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s
-// CHECK: Remove unused exception handling info
-// CHECK: Sample profile pass
+// RUN: %clang_cc1 -O2 -fno-experimental-new-pass-manager 
-fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure 
-emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=LEGACY
+// RUN: %clang_cc1 -O2 -fexperimental-new-pass-manager 
-fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -fdebug-pass-manager 
-emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=NEWPM
+
+// LEGACY: Remove unused exception handling info
+// LEGACY: Sample profile pass
+
+// NEWPM: SimplifyCFGPass
+// NEWPM: SampleProfileLoaderPass
+
+int func(int a) { return a; }


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


[PATCH] D63626: [clang][NewPM] Remove exception handling before loading pgo sample profile data

2019-06-24 Thread Leonard Chan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL364201: [clang][NewPM] Remove exception handling before 
loading pgo sample profile data (authored by leonardchan, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D63626?vs=206065&id=206245#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63626

Files:
  cfe/trunk/test/CodeGen/pgo-sample.c


Index: cfe/trunk/test/CodeGen/pgo-sample.c
===
--- cfe/trunk/test/CodeGen/pgo-sample.c
+++ cfe/trunk/test/CodeGen/pgo-sample.c
@@ -1,6 +1,13 @@
 // Test if PGO sample use passes are invoked.
 //
 // Ensure Pass PGOInstrumentationGenPass is invoked.
-// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s 
-mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s
-// CHECK: Remove unused exception handling info
-// CHECK: Sample profile pass
+// RUN: %clang_cc1 -O2 -fno-experimental-new-pass-manager 
-fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure 
-emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=LEGACY
+// RUN: %clang_cc1 -O2 -fexperimental-new-pass-manager 
-fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -fdebug-pass-manager 
-emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=NEWPM
+
+// LEGACY: Remove unused exception handling info
+// LEGACY: Sample profile pass
+
+// NEWPM: SimplifyCFGPass
+// NEWPM: SampleProfileLoaderPass
+
+int func(int a) { return a; }


Index: cfe/trunk/test/CodeGen/pgo-sample.c
===
--- cfe/trunk/test/CodeGen/pgo-sample.c
+++ cfe/trunk/test/CodeGen/pgo-sample.c
@@ -1,6 +1,13 @@
 // Test if PGO sample use passes are invoked.
 //
 // Ensure Pass PGOInstrumentationGenPass is invoked.
-// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s
-// CHECK: Remove unused exception handling info
-// CHECK: Sample profile pass
+// RUN: %clang_cc1 -O2 -fno-experimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=LEGACY
+// RUN: %clang_cc1 -O2 -fexperimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -fdebug-pass-manager -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=NEWPM
+
+// LEGACY: Remove unused exception handling info
+// LEGACY: Sample profile pass
+
+// NEWPM: SimplifyCFGPass
+// NEWPM: SampleProfileLoaderPass
+
+int func(int a) { return a; }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62953: [Syntax] Do not glue multiple empty PP expansions to a single mapping

2019-06-24 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 206246.
ilya-biryukov marked 10 inline comments as done.
ilya-biryukov added a comment.

- Address comments, document code.
- s/Expansion/CollectedExpansions.
- Added FIXMEs for macro arguments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62953

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

Index: clang/unittests/Tooling/Syntax/TokensTest.cpp
===
--- clang/unittests/Tooling/Syntax/TokensTest.cpp
+++ clang/unittests/Tooling/Syntax/TokensTest.cpp
@@ -424,6 +424,7 @@
"['#'_0, 'int'_22) => ['int'_0, 'int'_0)\n"
"['ADD'_25, ';'_46) => ['1'_3, ';'_12)\n"},
   // Empty macro replacement.
+  // FIXME: the #define directives should not be glued together.
   {R"cpp(
 #define EMPTY
 #define EMPTY_FUNC(X)
@@ -436,7 +437,9 @@
   spelled tokens:
 # define EMPTY # define EMPTY_FUNC ( X ) EMPTY EMPTY_FUNC ( 1 + 2 + 3 )
   mappings:
-['#'_0, ''_18) => [''_0, ''_0)
+['#'_0, 'EMPTY'_9) => [''_0, ''_0)
+['EMPTY'_9, 'EMPTY_FUNC'_10) => [''_0, ''_0)
+['EMPTY_FUNC'_10, ''_18) => [''_0, ''_0)
 )"},
   // File ends with a macro replacement.
   {R"cpp(
Index: clang/lib/Tooling/Syntax/Tokens.cpp
===
--- clang/lib/Tooling/Syntax/Tokens.cpp
+++ clang/lib/Tooling/Syntax/Tokens.cpp
@@ -14,6 +14,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TokenKinds.h"
+#include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/Token.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -70,8 +71,8 @@
 
 FileRange::FileRange(FileID File, unsigned BeginOffset, unsigned EndOffset)
 : File(File), Begin(BeginOffset), End(EndOffset) {
-  assert(File.isValid());
-  assert(BeginOffset <= EndOffset);
+  assert(File.isValid());
+  assert(BeginOffset <= EndOffset);
 }
 
 FileRange::FileRange(const SourceManager &SM, SourceLocation BeginLoc,
@@ -252,6 +253,39 @@
   return Tokens;
 }
 
+/// Records information reqired to construct mappings for the token buffer that
+/// we are collecting.
+class TokenCollector::CollectPPExpansions : public PPCallbacks {
+public:
+  CollectPPExpansions(TokenCollector &C) : Collector(&C) {}
+
+  /// Disabled instance will stop reporting anything to TokenCollector.
+  /// This ensures that uses of the preprocessor after TokenCollector::consume()
+  /// is called do not access the (possibly invalid) collector instance.
+  void disable() { Collector = nullptr; }
+
+  void MacroExpands(const clang::Token &MacroNameTok, const MacroDefinition &MD,
+SourceRange Range, const MacroArgs *Args) override {
+if (!Collector)
+  return;
+// Only record top-level expansions, not those where:
+//   - the macro use is inside a macro body,
+//   - the macro appears in an argument to another macro.
+if (!MacroNameTok.getLocation().isFileID() ||
+(LastExpansionEnd.isValid() &&
+ Collector->PP.getSourceManager().isBeforeInTranslationUnit(
+ Range.getBegin(), LastExpansionEnd)))
+  return;
+Collector->Expansions[Range.getBegin().getRawEncoding()] = Range.getEnd();
+LastExpansionEnd = Range.getEnd();
+  }
+  // FIXME: handle directives like #pragma, #include, etc.
+private:
+  TokenCollector *Collector;
+  /// Used to detect recursive macro expansions.
+  SourceLocation LastExpansionEnd;
+};
+
 /// Fills in the TokenBuffer by tracing the run of a preprocessor. The
 /// implementation tracks the tokens, macro expansions and directives coming
 /// from the preprocessor and:
@@ -279,15 +313,21 @@
 );
 Expanded.push_back(syntax::Token(T));
   });
+  // And locations of macro calls, to properly recover boundaries of those in
+  // case of empty expansions.
+  auto CB = llvm::make_unique(*this);
+  this->Collector = CB.get();
+  PP.addPPCallbacks(std::move(CB));
 }
 
 /// Builds mappings and spelled tokens in the TokenBuffer based on the expanded
 /// token stream.
 class TokenCollector::Builder {
 public:
-  Builder(std::vector Expanded, const SourceManager &SM,
-  const LangOptions &LangOpts)
-  : Result(SM), SM(SM), LangOpts(LangOpts) {
+  Builder(std::vector Expanded, PPExpansions CollectedExpansions,
+  const SourceManager &SM, const LangOptions &LangOpts)
+  : Result(SM), CollectedExpansions(std::move(CollectedExpansions)), SM(SM),
+LangOpts(LangOpts) {
 Result.ExpandedTokens = std::move(Expanded);
   }
 
@@ -296,6 +336,9 @@
 
 // Walk over expanded tokens and spelled tokens in parallel, building the
 // mappings between those using source locations.
+// To correctly recover empty macro expansions, we also ta

[PATCH] D62953: [Syntax] Do not glue multiple empty PP expansions to a single mapping

2019-06-24 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/Tokens.h:319
+  ///   2. macro name and arguments for macro expansions.
+  using PPExpansions = llvm::DenseMap;
   class Builder;

sammccall wrote:
> do I understand right that this is logically a stack, but it's hard to know 
> when to pop or just less hassle to do this way?
> if so, maybe worth mentioning
That's exactly the case, but preprocessor only exposes the point at which we 
push macros to the stack (`PPCallbacks::MacroExpands`, etc) and not points when 
we pop from the stack. This map is an attempt to recover the pop positions 
(e.g. to detect intermediate expansions in the macro arguments).

Added a comment



Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:269
+  return;
+// Do not record recursive expansions.
+if (!MacroNameTok.getLocation().isFileID() ||

sammccall wrote:
> This doesn't seem like a particularly standard use of the word "recursive", 
> and the code isn't totally obvious either.
> 
> Could this be "only record top-level expansions, not those where:
>  - the macro use is inside a macro body
>  - the macro appears in an argument to another macro
> 
> Because the top level macros are treated as opaque atoms. (We probably need a 
> FIXME for tracking arg locations somewhere)
Added a comment and a FIXME at the declaration site of `TokenBuffer`



Comment at: clang/lib/Tooling/Syntax/Tokens.cpp:522
   llvm::DenseMap NextSpelled;
+  PPExpansions Expansions;
   const SourceManager &SM;

sammccall wrote:
> maybe RecordedExpansions? to make the link with the recorder
SG, I've renamed to `CollectedExpansions`. (Assuming 'recorder' stands for 
'collector', happy to update if I misinterpreted your comment)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62953



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


r364202 - [clang][NewPM] Add RUNS for tests that produce slightly different IR under new PM

2019-06-24 Thread Leonard Chan via cfe-commits
Author: leonardchan
Date: Mon Jun 24 09:49:18 2019
New Revision: 364202

URL: http://llvm.org/viewvc/llvm-project?rev=364202&view=rev
Log:
[clang][NewPM] Add RUNS for tests that produce slightly different IR under new 
PM

For CodeGenOpenCL/convergent.cl, the new PM produced a slightly different for
loop, but this still checks for no loop unrolling as intended. This is
committed separately from D63174.

Modified:
cfe/trunk/test/CodeGenOpenCL/convergent.cl

Modified: cfe/trunk/test/CodeGenOpenCL/convergent.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/convergent.cl?rev=364202&r1=364201&r2=364202&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/convergent.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/convergent.cl Mon Jun 24 09:49:18 2019
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm %s -o - | opt 
-instnamer -S | FileCheck -enable-var-scope %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm %s -o - 
-fno-experimental-new-pass-manager | opt -instnamer -S | FileCheck 
-enable-var-scope %s --check-prefixes=CHECK,CHECK-LEGACY
+// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm %s -o - 
-fexperimental-new-pass-manager | opt -instnamer -S | FileCheck 
-enable-var-scope %s --check-prefixes=CHECK,CHECK-NEWPM
 
 // This is initially assumed convergent, but can be deduced to not require it.
 
@@ -117,7 +118,12 @@ void test_unroll() {
 // CHECK: [[for_body]]:
 // CHECK:  tail call spir_func void @nodupfun() #[[attr5:[0-9]+]]
 // CHECK-NOT: call spir_func void @nodupfun()
-// CHECK:  br i1 %{{.+}}, label %[[for_body]], label %[[for_cond_cleanup]]
+
+// The new PM produces a slightly different IR for the loop from the legacy PM,
+// but the test still checks that the loop is not unrolled.
+// CHECK-LEGACY:  br i1 %{{.+}}, label %[[for_body]], label 
%[[for_cond_cleanup]]
+// CHECK-NEW: br i1 %{{.+}}, label %[[for_body_crit_edge:.+]], label 
%[[for_cond_cleanup]]
+// CHECK-NEW: [[for_body_crit_edge]]:
 
 void test_not_unroll() {
   for (int i = 0; i < 10; i++)


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


[PATCH] D63559: [clang-tidy] Added functionality for getting semantic highlights for variable and function declarations

2019-06-24 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom updated this revision to Diff 206247.
jvikstrom marked 7 inline comments as done.
jvikstrom added a comment.

Fixed tests and edge case with function declarations without names for 
parameters.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63559

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/SemanticHighlight.cpp
  clang-tools-extra/clangd/SemanticHighlight.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/SemanticHighlightTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticHighlightTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/SemanticHighlightTests.cpp
@@ -0,0 +1,63 @@
+//===- SemanticHighlightTest.cpp - SemanticHighlightTest tests-*- C++ -* -===//
+//
+// 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 "Annotations.h"
+#include "ClangdUnit.h"
+#include "Protocol.h"
+#include "SemanticHighlight.h"
+#include "SourceCode.h"
+#include "TestTU.h"
+#include "llvm/Support/ScopedPrinter.h"
+#include "gmock/gmock-matchers.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+void checkTokensExists(std::vector Tokens,
+   std::vector ExpectedRanges,
+   SemanticHighlightKind Kind) {
+  std::vector ActualRanges;
+  for (SemanticToken Token : Tokens) {
+if (Token.Kind == Kind) {
+  ActualRanges.push_back(Token.R);
+}
+  }
+
+  EXPECT_THAT(ActualRanges, testing::UnorderedElementsAreArray(ExpectedRanges));
+}
+
+TEST(SemanticSymbolASTCollector, GetBeginningOfIdentifier) {
+  std::string Preamble = R"cpp(
+void $Function[[foo]](int);
+struct A {
+  double SomeMember;
+};
+void $Function[[foo]](int $Variable[[a]]) {
+  SOMEDECL( );
+  auto $Variable[[VeryLongVariableName]] = 12312;
+  A $Variable[[aa]];
+}
+  )cpp";
+
+  Annotations Test(Preamble);
+  auto Variables = Test.ranges("Variable");
+  auto Function = Test.ranges("Function");
+
+  auto AST = TestTU::withCode(Test.code()).build();
+  auto Tokens = getSemanticHighlights(AST);
+
+  checkTokensExists(Tokens, Variables, SemanticHighlightKind::Variable);
+  checkTokensExists(Tokens, Function, SemanticHighlightKind::Function);
+}
+
+} // namespace
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -53,6 +53,7 @@
   RenameTests.cpp
   RIFFTests.cpp
   SelectionTests.cpp
+  SemanticHighlightTests.cpp
   SerializationTests.cpp
   SourceCodeTests.cpp
   SymbolCollectorTests.cpp
Index: clang-tools-extra/clangd/SemanticHighlight.h
===
--- /dev/null
+++ clang-tools-extra/clangd/SemanticHighlight.h
@@ -0,0 +1,37 @@
+//==-- SemanticHighlight.h - Generating highlights from the AST--*- C++ -*-==//
+//
+// 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
+//
+//===--===//
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SEMANTICHIGHLIGHT_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SEMANTICHIGHLIGHT_H
+
+#include "ClangdUnit.h"
+#include "Protocol.h"
+
+namespace clang {
+namespace clangd {
+
+enum class SemanticHighlightKind : int {
+  Variable = 0,
+  Function = 1,
+};
+
+// Contains all information needed for the highlighting a token.
+struct SemanticToken {
+  SemanticHighlightKind Kind;
+  Range R;
+};
+
+bool operator==(const SemanticToken &Lhs, const SemanticToken &Rhs);
+bool operator!=(const SemanticToken &Lhs, const SemanticToken &Rhs);
+
+// Returns semantic highlights for the AST. 
+std::vector getSemanticHighlights(ParsedAST &AST);
+
+} // namespace clangd
+} // namespace clang
+
+#endif
Index: clang-tools-extra/clangd/SemanticHighlight.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/SemanticHighlight.cpp
@@ -0,0 +1,82 @@
+#include "SemanticHighlight.h"
+#include "SourceCode.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Lex/Lexer.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+// Collects all semantic tokens in an ASTContext.
+class SemanticSymbolASTCollector
+: public RecursiveASTVisitor {
+ 

[PATCH] D63559: [clang-tidy] Added functionality for getting semantic highlights for variable and function declarations

2019-06-24 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom added inline comments.



Comment at: clang-tools-extra/clangd/SemanticHighlight.cpp:75
+  SemanticSymbolASTCollector Collector(Ctx);
+  Collector.TraverseAST(Ctx);
+  return Collector.getSymbols();

hokein wrote:
> let's move the above lines into `SemanticSymbolASTCollector`, we can define a 
> new method "collectTokens()".
Should I expose the entire class or keep the getSemanticHighlights function?  
(I'm just thinking that RecursiveASTVisitor contains a lot of public functions 
which makes it not super obvious which function to call to get semantic 
highlight things when looking at autocomplete)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63559



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


[PATCH] D63462: [analyzer] JsonSupport: Escape escapes

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 206248.
Charusso added a comment.

- Test case added.


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

https://reviews.llvm.org/D63462

Files:
  clang/include/clang/Basic/JsonSupport.h
  clang/test/Analysis/dump_egraph.c


Index: clang/test/Analysis/dump_egraph.c
===
--- clang/test/Analysis/dump_egraph.c
+++ clang/test/Analysis/dump_egraph.c
@@ -13,6 +13,8 @@
 
 int foo() {
   int *x = 0, *y = 0;
+  char c = '\x13';
+
   return *x + *y;
 }
 
@@ -22,5 +24,7 @@
 
 // CHECK: \"has_report\": true
 
-// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 16, \"column\": 10, 
\"file\": \"{{(.+)}}dump_egraph.c\" \}
+// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 18, \"column\": 10, 
\"file\": \"{{(.+)}}dump_egraph.c\" \}
+
+// CHECK: \"pretty\": \"'x13'\"
 
Index: clang/include/clang/Basic/JsonSupport.h
===
--- clang/include/clang/Basic/JsonSupport.h
+++ clang/include/clang/Basic/JsonSupport.h
@@ -31,7 +31,26 @@
   std::string Str = RawSR.trim().str();
   size_t Pos = 0;
 
+  // Escape backslashes.
+  while (true) {
+Pos = Str.find('\\', Pos);
+if (Pos == std::string::npos)
+  break;
+
+// Prevent bad conversions.
+size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
+
+// See whether the current backslash is not escaped.
+if (TempPos != Str.find("", Pos)) {
+  Str.insert(Pos, "\\");
+  ++Pos; // As we insert the backslash move plus one.
+}
+
+++Pos;
+  }
+
   // Escape double quotes.
+  Pos = 0;
   while (true) {
 Pos = Str.find('\"', Pos);
 if (Pos == std::string::npos)
@@ -40,8 +59,8 @@
 // Prevent bad conversions.
 size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
 
-// See whether the current double quote is escaped.
-if (TempPos != Str.find("\\\"", TempPos)) {
+// See whether the current double quote is not escaped.
+if (TempPos != Str.find("\\\"", Pos)) {
   Str.insert(Pos, "\\");
   ++Pos; // As we insert the escape-character move plus one.
 }


Index: clang/test/Analysis/dump_egraph.c
===
--- clang/test/Analysis/dump_egraph.c
+++ clang/test/Analysis/dump_egraph.c
@@ -13,6 +13,8 @@
 
 int foo() {
   int *x = 0, *y = 0;
+  char c = '\x13';
+
   return *x + *y;
 }
 
@@ -22,5 +24,7 @@
 
 // CHECK: \"has_report\": true
 
-// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 16, \"column\": 10, \"file\": \"{{(.+)}}dump_egraph.c\" \}
+// CHECK: \"pretty\": \"*x\", \"location\": \{ \"line\": 18, \"column\": 10, \"file\": \"{{(.+)}}dump_egraph.c\" \}
+
+// CHECK: \"pretty\": \"'x13'\"
 
Index: clang/include/clang/Basic/JsonSupport.h
===
--- clang/include/clang/Basic/JsonSupport.h
+++ clang/include/clang/Basic/JsonSupport.h
@@ -31,7 +31,26 @@
   std::string Str = RawSR.trim().str();
   size_t Pos = 0;
 
+  // Escape backslashes.
+  while (true) {
+Pos = Str.find('\\', Pos);
+if (Pos == std::string::npos)
+  break;
+
+// Prevent bad conversions.
+size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
+
+// See whether the current backslash is not escaped.
+if (TempPos != Str.find("", Pos)) {
+  Str.insert(Pos, "\\");
+  ++Pos; // As we insert the backslash move plus one.
+}
+
+++Pos;
+  }
+
   // Escape double quotes.
+  Pos = 0;
   while (true) {
 Pos = Str.find('\"', Pos);
 if (Pos == std::string::npos)
@@ -40,8 +59,8 @@
 // Prevent bad conversions.
 size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
 
-// See whether the current double quote is escaped.
-if (TempPos != Str.find("\\\"", TempPos)) {
+// See whether the current double quote is not escaped.
+if (TempPos != Str.find("\\\"", Pos)) {
   Str.insert(Pos, "\\");
   ++Pos; // As we insert the escape-character move plus one.
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63603: [ASTImporter] Propagate error from ImportDeclContext

2019-06-24 Thread Gabor Marton via Phabricator via cfe-commits
martong marked 4 inline comments as done.
martong added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:1724
+  };
+  DefinitionCompleter CompleterRAII(To);
 

jkorous wrote:
> You might consider using just a lambda with `llvm::make_scope_exit`.
> 
> https://llvm.org/doxygen/namespacellvm.html#a4896534f3c6278be56967444daf38e3f
> 
> For example:
> ```
> To->startDefinition();
> auto DefinitionCompleter = llvm::make_scope_exit( 
> [To](){To->completeDefinition();} );
> ```
Thanks! I have changed to make_scope_exit.



Comment at: clang/unittests/AST/ASTImporterTest.cpp:4743
+}
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ErrorHandlingTest,

balazske wrote:
> Maybe add a similar test for namespace and check that the error is not 
> propagated?
Ok, I have added that test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63603



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


[PATCH] D63603: [ASTImporter] Propagate error from ImportDeclContext

2019-06-24 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 206250.
martong marked 2 inline comments as done.
martong added a comment.

- Use make_scope_exit
- Add test ErrorIsNotPropagatedFromMemberToNamespace


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63603

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4738,6 +4738,93 @@
   EXPECT_EQ(OptErr->Error, ImportError::UnsupportedConstruct);
 }
 
+// An error should be set for a class if we cannot import one member.
+TEST_P(ErrorHandlingTest, ErrorIsPropagatedFromMemberToClass) {
+  TranslationUnitDecl *FromTU = getTuDecl(
+  std::string(R"(
+  class X {
+void f() { )") + ErroneousStmt + R"( } // This member has the error
+   // during import.
+void ok();// The error should not prevent importing this.
+  };  // An error will be set for X too.
+  )",
+  Lang_CXX);
+  auto *FromX = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("X")));
+  CXXRecordDecl *ImportedX = Import(FromX, Lang_CXX);
+
+  // An error is set for X.
+  EXPECT_FALSE(ImportedX);
+  ASTImporter *Importer = findFromTU(FromX)->Importer.get();
+  Optional OptErr = Importer->getImportDeclErrorIfAny(FromX);
+  ASSERT_TRUE(OptErr);
+  EXPECT_EQ(OptErr->Error, ImportError::UnsupportedConstruct);
+
+  // An error is set for f().
+  auto *FromF = FirstDeclMatcher().match(
+  FromTU, cxxMethodDecl(hasName("f")));
+  OptErr = Importer->getImportDeclErrorIfAny(FromF);
+  ASSERT_TRUE(OptErr);
+  EXPECT_EQ(OptErr->Error, ImportError::UnsupportedConstruct);
+  // And any subsequent import should fail.
+  CXXMethodDecl *ImportedF = Import(FromF, Lang_CXX);
+  EXPECT_FALSE(ImportedF);
+
+  // There is no error set for ok().
+  auto *FromOK = FirstDeclMatcher().match(
+  FromTU, cxxMethodDecl(hasName("ok")));
+  OptErr = Importer->getImportDeclErrorIfAny(FromOK);
+  EXPECT_FALSE(OptErr);
+  // And we should be able to import.
+  CXXMethodDecl *ImportedOK = Import(FromOK, Lang_CXX);
+  EXPECT_TRUE(ImportedOK);
+
+  // Unwary clients may access X even if the error is set, so, at least make
+  // sure the class is set to be complete.
+  CXXRecordDecl *ToX = cast(ImportedOK->getDeclContext());
+  EXPECT_TRUE(ToX->isCompleteDefinition());
+}
+
+TEST_P(ErrorHandlingTest, ErrorIsNotPropagatedFromMemberToNamespace) {
+  TranslationUnitDecl *FromTU = getTuDecl(
+  std::string(R"(
+  namespace X {
+void f() { )") + ErroneousStmt + R"( } // This member has the error
+   // during import.
+void ok();// The error should not prevent importing this.
+  };  // An error will be set for X too.
+  )",
+  Lang_CXX);
+  auto *FromX = FirstDeclMatcher().match(
+  FromTU, namespaceDecl(hasName("X")));
+  NamespaceDecl *ImportedX = Import(FromX, Lang_CXX);
+
+  // There is no error set for X.
+  EXPECT_TRUE(ImportedX);
+  ASTImporter *Importer = findFromTU(FromX)->Importer.get();
+  Optional OptErr = Importer->getImportDeclErrorIfAny(FromX);
+  ASSERT_FALSE(OptErr);
+
+  // An error is set for f().
+  auto *FromF = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("f")));
+  OptErr = Importer->getImportDeclErrorIfAny(FromF);
+  ASSERT_TRUE(OptErr);
+  EXPECT_EQ(OptErr->Error, ImportError::UnsupportedConstruct);
+  // And any subsequent import should fail.
+  FunctionDecl *ImportedF = Import(FromF, Lang_CXX);
+  EXPECT_FALSE(ImportedF);
+
+  // There is no error set for ok().
+  auto *FromOK = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("ok")));
+  OptErr = Importer->getImportDeclErrorIfAny(FromOK);
+  EXPECT_FALSE(OptErr);
+  // And we should be able to import.
+  FunctionDecl *ImportedOK = Import(FromOK, Lang_CXX);
+  EXPECT_TRUE(ImportedOK);
+}
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ErrorHandlingTest,
 DefaultTestValuesForRunOptions, );
 
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -57,6 +57,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Casting.h"
@@ -1631,16 +1632,32 @@
 auto ToDCOrErr = Importer.ImportContext(FromDC);
 return ToDCOrErr.takeError();
   }
+
+  // We use strict error handling in case of records and enums, but not
+  // with e.g. namespaces.
+  //
+  // FIXME Clients of the ASTImporter should be able to choose an

[PATCH] D63726: [analyzer] print() JSONify: Create pointers

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso created this revision.
Charusso added a reviewer: NoQ.
Charusso added a project: clang.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Charusso added a parent revision: D63462: [analyzer] JsonSupport: Escape 
escapes.

-


Repository:
  rC Clang

https://reviews.llvm.org/D63726

Files:
  clang/lib/StaticAnalyzer/Core/Environment.cpp
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/test/Analysis/exploded-graph-rewriter/environment.dot
  clang/test/Analysis/exploded-graph-rewriter/environment_diff.dot
  clang/test/Analysis/exploded-graph-rewriter/store.dot
  clang/test/Analysis/exploded-graph-rewriter/store_diff.dot
  clang/test/Analysis/expr-inspection.c
  clang/utils/analyzer/exploded-graph-rewriter.py

Index: clang/utils/analyzer/exploded-graph-rewriter.py
===
--- clang/utils/analyzer/exploded-graph-rewriter.py
+++ clang/utils/analyzer/exploded-graph-rewriter.py
@@ -113,7 +113,8 @@
 class Environment(object):
 def __init__(self, json_e):
 super(Environment, self).__init__()
-self.frames = [EnvironmentFrame(f) for f in json_e]
+self.ptr = json_e['pointer']
+self.frames = [EnvironmentFrame(f) for f in json_e['items']]
 
 def diff_frames(self, prev):
 # TODO: It's difficult to display a good diff when frame numbers shift.
@@ -177,8 +178,9 @@
 class Store(object):
 def __init__(self, json_s):
 super(Store, self).__init__()
+self.ptr = json_s['pointer']
 self.clusters = collections.OrderedDict(
-[(c['pointer'], StoreCluster(c)) for c in json_s])
+[(c['pointer'], StoreCluster(c)) for c in json_s['items']])
 
 def diff_clusters(self, prev):
 removed = [k for k in prev.clusters if k not in self.clusters]
Index: clang/test/Analysis/expr-inspection.c
===
--- clang/test/Analysis/expr-inspection.c
+++ clang/test/Analysis/expr-inspection.c
@@ -24,16 +24,16 @@
 }
 
 // CHECK:  "program_state": {
-// CHECK-NEXT:   "store": [
+// CHECK-NEXT:   "store": { "pointer": "{{0x[0-9a-f]+}}", "items": [
 // CHECK-NEXT: { "cluster": "y", "pointer": "{{0x[0-9a-f]+}}", "items": [
 // CHECK-NEXT:   { "kind": "Direct", "offset": 0, "value": "2 S32b" }
 // CHECK-NEXT: ]}
-// CHECK-NEXT:   ],
-// CHECK-NEXT:   "environment": [
+// CHECK-NEXT:   ]},
+// CHECK-NEXT:   "environment": { "pointer": "{{0x[0-9a-f]+}}", "items": [
 // CHECK-NEXT: { "lctx_id": 1, "location_context": "#0 Call", "calling": "foo", "call_line": null, "items": [
 // CHECK-NEXT:   { "stmt_id": {{[0-9]+}}, "pretty": "clang_analyzer_printState", "value": "&code{clang_analyzer_printState}" }
 // CHECK-NEXT: ]}
-// CHECK-NEXT:   ],
+// CHECK-NEXT:   ]},
 // CHECK-NEXT:   "constraints": [
 // CHECK-NEXT: { "symbol": "reg_$0", "range": "{ [-2147483648, 13] }" }
 // CHECK-NEXT:   ],
Index: clang/test/Analysis/exploded-graph-rewriter/store_diff.dot
===
--- clang/test/Analysis/exploded-graph-rewriter/store_diff.dot
+++ clang/test/Analysis/exploded-graph-rewriter/store_diff.dot
@@ -11,19 +11,22 @@
   "program_points": [],
   "program_state": {
 "environment": null,
-"store": [
-  {
-"cluster": "x",
-"pointer": "0x3",
-"items": [
-  {
-"kind": "Default",
-"offset": 0,
-"value": "Undefined"
-  }
-]
-  }
-]
+"store": {
+  "pointer": "0x2",
+  "items": [
+{
+  "cluster": "x",
+  "pointer": "0x3",
+  "items": [
+{
+  "kind": "Default",
+  "offset": 0,
+  "value": "Undefined"
+}
+  ]
+}
+  ]
+}
   }
 }
 \l}"];
@@ -52,19 +55,22 @@
   "program_points": [],
   "program_state": {
 "environment": null,
-"store": [
-  {
-"cluster": "x",
-"pointer": "0x3",
-"items": [
-  {
-"kind": "Default",
-"offset": 0,
-"value": "Unknown"
-  }
-]
-  }
-]
+"store": {
+  "pointer": "0x5",
+  "items": [
+{
+  "cluster": "x",
+  "pointer": "0x3",
+  "items": [
+{
+  "kind": "Default",
+  "offset": 0,
+  "value": "Unknown"
+}
+  ]
+}
+  ]
+}
   }
 }
 \l}"];
Index: clang/test/Analysis/exploded-graph-rewriter/store.dot
===

[PATCH] D63727: [analyzer] print() JSONify: Stable LocationContext IDs

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso created this revision.
Charusso added a reviewer: NoQ.
Charusso added a project: clang.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.

-


Repository:
  rC Clang

https://reviews.llvm.org/D63727

Files:
  clang/lib/Analysis/AnalysisDeclContext.cpp
  clang/test/Analysis/dump_egraph.cpp
  clang/test/Analysis/expr-inspection.c


Index: clang/test/Analysis/expr-inspection.c
===
--- clang/test/Analysis/expr-inspection.c
+++ clang/test/Analysis/expr-inspection.c
@@ -30,7 +30,7 @@
 // CHECK-NEXT: ]}
 // CHECK-NEXT:   ]},
 // CHECK-NEXT:   "environment": { "pointer": "{{0x[0-9a-f]+}}", "items": [
-// CHECK-NEXT: { "lctx_id": 1, "location_context": "#0 Call", "calling": 
"foo", "call_line": null, "items": [
+// CHECK-NEXT: { "lctx_id": 1, "location_context": "#1 Call", "calling": 
"foo", "call_line": null, "items": [
 // CHECK-NEXT:   { "stmt_id": {{[0-9]+}}, "pretty": 
"clang_analyzer_printState", "value": "&code{clang_analyzer_printState}" }
 // CHECK-NEXT: ]}
 // CHECK-NEXT:   ]},
Index: clang/test/Analysis/dump_egraph.cpp
===
--- clang/test/Analysis/dump_egraph.cpp
+++ clang/test/Analysis/dump_egraph.cpp
@@ -18,9 +18,9 @@
   new S;
 }
 
-// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"foo\", 
\"call_line\": null, \"items\": 
[\l\{ \"stmt_id\": {{[0-9]+}}, 
\"kind\": \"construct into local variable\", \"argument_index\": null, 
\"pretty\": \"T t;\", \"value\": \"&t\"
+// CHECK: \"location_context\": \"#1 Call\", \"calling\": \"foo\", 
\"call_line\": null, \"items\": 
[\l\{ \"stmt_id\": {{[0-9]+}}, 
\"kind\": \"construct into local variable\", \"argument_index\": null, 
\"pretty\": \"T t;\", \"value\": \"&t\"
 
-// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"T::T\", 
\"call_line\": \"16\", \"items\": 
[\l\{ \"init_id\": {{[0-9]+}}, 
\"kind\": \"construct into member variable\", \"argument_index\": null, 
\"pretty\": \"s\", \"value\": \"&t-\>s\"
+// CHECK: \"location_context\": \"#2 Call\", \"calling\": \"T::T\", 
\"call_line\": \"16\", \"items\": 
[\l\{ \"init_id\": {{[0-9]+}}, 
\"kind\": \"construct into member variable\", \"argument_index\": null, 
\"pretty\": \"s\", \"value\": \"&t-\>s\"
 
 // CHECK: \"cluster\": \"t\", \"pointer\": \"{{0x[0-9a-f]+}}\", \"items\": 
[\l\{ \"kind\": \"Default\", 
\"offset\": 0, \"value\": \"conj_$2\{int, LC5, no stmt, #1\}\"
 
Index: clang/lib/Analysis/AnalysisDeclContext.cpp
===
--- clang/lib/Analysis/AnalysisDeclContext.cpp
+++ clang/lib/Analysis/AnalysisDeclContext.cpp
@@ -525,14 +525,17 @@
   const SourceManager &SM =
   getAnalysisDeclContext()->getASTContext().getSourceManager();
 
-  unsigned Frame = 0;
+  unsigned LCtxCount = 0;
+  for (const LocationContext *LCtx = this; LCtx; LCtx = LCtx->getParent())
+++LCtxCount;
+
   for (const LocationContext *LCtx = this; LCtx; LCtx = LCtx->getParent()) {
 Indent(Out, Space, IsDot)
 << "{ \"lctx_id\": " << LCtx->getID() << ", \"location_context\": \"";
 switch (LCtx->getKind()) {
 case StackFrame:
-  Out << '#' << Frame << " Call\", \"calling\": \"";
-  ++Frame;
+  Out << '#' << LCtxCount << " Call\", \"calling\": \"";
+  --LCtxCount;
   if (const auto *D = dyn_cast(LCtx->getDecl()))
 Out << D->getQualifiedNameAsString();
   else


Index: clang/test/Analysis/expr-inspection.c
===
--- clang/test/Analysis/expr-inspection.c
+++ clang/test/Analysis/expr-inspection.c
@@ -30,7 +30,7 @@
 // CHECK-NEXT: ]}
 // CHECK-NEXT:   ]},
 // CHECK-NEXT:   "environment": { "pointer": "{{0x[0-9a-f]+}}", "items": [
-// CHECK-NEXT: { "lctx_id": 1, "location_context": "#0 Call", "calling": "foo", "call_line": null, "items": [
+// CHECK-NEXT: { "lctx_id": 1, "location_context": "#1 Call", "calling": "foo", "call_line": null, "items": [
 // CHECK-NEXT:   { "stmt_id": {{[0-9]+}}, "pretty": "clang_analyzer_printState", "value": "&code{clang_analyzer_printState}" }
 // CHECK-NEXT: ]}
 // CHECK-NEXT:   ]},
Index: clang/test/Analysis/dump_egraph.cpp
===
--- clang/test/Analysis/dump_egraph.cpp
+++ clang/test/Analysis/dump_egraph.cpp
@@ -18,9 +18,9 @@
   new S;
 }
 
-// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"foo\", \"call_line\": null, \"items\": [\l\{ \"stmt_id\": {{[0-9]+}}, \"kind\": \"construct into local variable\", \"argument_index\": null, \"pretty\": \"T t;\", \"value\": \"&t\"
+// CHECK: \"location_context\": \"#1 Call\", \"calling\": \"foo\", \"call_line\": null, \"items\": [\l\{ \"stmt_id\": {{[0-9]+}}, \"kind\": \"construct into local variabl

[PATCH] D63093: [analyzer] WIP: MallocChecker: Release temporary CXXNewExpr

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso abandoned this revision.
Charusso added a comment.

The seen error solved by D63720 .


Repository:
  rC Clang

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

https://reviews.llvm.org/D63093



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


[PATCH] D63288: [clang-tidy] Generalize TransformerClangTidyCheck to take a rule generator.

2019-06-24 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 206253.
ymandel marked an inline comment as done.
ymandel added a comment.

Added tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63288

Files:
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
  clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
@@ -18,16 +18,16 @@
 namespace tidy {
 namespace utils {
 namespace {
+using tooling::change;
 using tooling::RewriteRule;
+using tooling::text;
+using tooling::stencil::cat;
 
 // Invert the code of an if-statement, while maintaining its semantics.
 RewriteRule invertIf() {
   using namespace ::clang::ast_matchers;
-  using tooling::change;
   using tooling::node;
   using tooling::statement;
-  using tooling::text;
-  using tooling::stencil::cat;
 
   StringRef C = "C", T = "T", E = "E";
   RewriteRule Rule = tooling::makeRule(
@@ -65,6 +65,64 @@
   )";
   EXPECT_EQ(Expected, test::runCheckOnCode(Input));
 }
+
+// A trivial rewrite rule generator that requires C99 code to operate.
+Optional needsC99(const LangOptions &LangOpts,
+   const ClangTidyCheck::OptionsView &Options) {
+  if (!LangOpts.C99)
+return None;
+  return tooling::makeRule(clang::ast_matchers::functionDecl(),
+   change(cat("void nothing()")), text("no message"));
+}
+
+class NeedsC99Check : public TransformerClangTidyCheck {
+public:
+  NeedsC99Check(StringRef Name, ClangTidyContext *Context)
+  : TransformerClangTidyCheck(needsC99, Name, Context) {}
+};
+
+// Pass a C++ source file and expect no change, since the check requires `C99`
+// support to fire.
+TEST(TransformerClangTidyCheckTest, DisableByLang) {
+  // FIXME: We should be testing both the positive and negative case. However,
+  // as far as I can tell, all of the LangOpts are always set to false, so I
+  // have been unable to test the positive case (that is, where the
+  // `LangOpts.C99` is true).
+  const std::string Input = "void log(int);";
+  EXPECT_EQ(Input, test::runCheckOnCode(Input));
+}
+
+// A trivial rewrite rule generator that checks config options.
+Optional noSkip(const LangOptions &LangOpts,
+ const ClangTidyCheck::OptionsView &Options) {
+  if (Options.get("Skip", "false") == "true")
+return None;
+  return tooling::makeRule(clang::ast_matchers::functionDecl(),
+   change(cat("void nothing()")), text("no message"));
+}
+
+class ConfigurableCheck : public TransformerClangTidyCheck {
+public:
+  ConfigurableCheck(StringRef Name, ClangTidyContext *Context)
+  : TransformerClangTidyCheck(noSkip, Name, Context) {}
+};
+
+// Pass a C source file and expect no change, since the check requires `Bool`
+// support to fire.
+TEST(TransformerClangTidyCheckTest, DisableByConfig) {
+  const std::string Input = "void log(int);";
+  const std::string Expected = "void nothing();";
+  ClangTidyOptions Options;
+
+  Options.CheckOptions["test-check-0.Skip"] = "true";
+  EXPECT_EQ(Input, test::runCheckOnCode(
+   Input, nullptr, "input.cc", None, Options));
+
+  Options.CheckOptions["test-check-0.Skip"] = "false";
+  EXPECT_EQ(Expected, test::runCheckOnCode(
+  Input, nullptr, "input.cc", None, Options));
+}
+
 } // namespace
 } // namespace utils
 } // namespace tidy
Index: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
===
--- clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
+++ clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
@@ -31,19 +31,32 @@
 // };
 class TransformerClangTidyCheck : public ClangTidyCheck {
 public:
-  // All cases in \p R must have a non-null \c Explanation, even though \c
-  // Explanation is optional for RewriteRule in general. Because the primary
-  // purpose of clang-tidy checks is to provide users with diagnostics, we
-  // assume that a missing explanation is a bug.  If no explanation is desired,
-  // indicate that explicitly (for example, by passing `text("no explanation")`
-  //  to `makeRule` as the `Explanation` argument).
+  // \p MakeRule generates the rewrite rule to be used by the check, based on
+  // the given language and clang-tidy options. It can return \c None to handle
+  // cases where the options disable the check.
+  //
+  // All cases in the rule generated by \p MakeRule must have a non-null \c
+  // Explanation, even though \c Explanation is optional for RewriteRule in
+  // general. Becaus

[PATCH] D62375: [ASTImporter] Mark erroneous nodes in from ctx

2019-06-24 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:8668
+
+bool ASTImporter::ImportPathTy::hasCycleAtBack() {
+  return Aux[Nodes.back()] > 1;

a_sidorin wrote:
> const?
Thanks! I made to be const.



Comment at: clang/lib/AST/ASTImporter.cpp:7840
+  // Push FromD to the stack, and remove that when we return.
+  ImportPathBuilder PathRAII(ImportPath, FromD);
 

balazske wrote:
> It is possible to use the `make_scope_exit` instead, this results in less 
> written code.
Thanks! Changed to use that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62375



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


[PATCH] D62375: [ASTImporter] Mark erroneous nodes in from ctx

2019-06-24 Thread Gabor Marton via Phabricator via cfe-commits
martong marked an inline comment as done.
martong added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:7892
 
-// Error encountered for the first time.
-assert(!getImportDeclErrorIfAny(FromD) &&

We may set up an error multiple times now, but the error should be the same, 
this is handled in `setImportDeclError`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62375



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


[PATCH] D62375: [ASTImporter] Mark erroneous nodes in from ctx

2019-06-24 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 206254.
martong marked 5 inline comments as done.
martong added a comment.

- Use make_scope_exit
- Make hasCycleAtBack const


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62375

Files:
  clang/include/clang/AST/ASTImporter.h
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -358,6 +358,106 @@
   EXPECT_EQ(0U, count);
 }
 
+struct ImportPath : ASTImporterOptionSpecificTestBase {
+  Decl *FromTU;
+  FunctionDecl *D0, *D1, *D2;
+  ImportPath() {
+FromTU = getTuDecl("void f(); void f(); void f();", Lang_CXX);
+auto Pattern = functionDecl(hasName("f"));
+D0 = FirstDeclMatcher().match(FromTU, Pattern);
+D2 = LastDeclMatcher().match(FromTU, Pattern);
+D1 = D2->getPreviousDecl();
+  }
+};
+
+TEST_P(ImportPath, Push) {
+  ASTImporter::ImportPathTy path;
+  path.push(D0);
+  EXPECT_FALSE(path.hasCycleAtBack());
+}
+
+TEST_P(ImportPath, SmallCycle) {
+  ASTImporter::ImportPathTy path;
+  path.push(D0);
+  path.push(D0);
+  EXPECT_TRUE(path.hasCycleAtBack());
+  path.pop();
+  EXPECT_FALSE(path.hasCycleAtBack());
+  path.push(D0);
+  EXPECT_TRUE(path.hasCycleAtBack());
+}
+
+TEST_P(ImportPath, GetSmallCycle) {
+  ASTImporter::ImportPathTy path;
+  path.push(D0);
+  path.push(D0);
+  EXPECT_TRUE(path.hasCycleAtBack());
+  std::array Res;
+  int i = 0;
+  for (Decl *Di : path.getCycleAtBack()) {
+Res[i++] = Di;
+  }
+  ASSERT_EQ(i, 2);
+  EXPECT_EQ(Res[0], D0);
+  EXPECT_EQ(Res[1], D0);
+}
+
+TEST_P(ImportPath, GetCycle) {
+  ASTImporter::ImportPathTy path;
+  path.push(D0);
+  path.push(D1);
+  path.push(D2);
+  path.push(D0);
+  EXPECT_TRUE(path.hasCycleAtBack());
+  std::array Res;
+  int i = 0;
+  for (Decl *Di : path.getCycleAtBack()) {
+Res[i++] = Di;
+  }
+  ASSERT_EQ(i, 4);
+  EXPECT_EQ(Res[0], D0);
+  EXPECT_EQ(Res[1], D2);
+  EXPECT_EQ(Res[2], D1);
+  EXPECT_EQ(Res[3], D0);
+}
+
+TEST_P(ImportPath, CycleAfterCycle) {
+  ASTImporter::ImportPathTy path;
+  path.push(D0);
+  path.push(D1);
+  path.push(D0);
+  path.push(D1);
+  path.push(D2);
+  path.push(D0);
+  EXPECT_TRUE(path.hasCycleAtBack());
+  std::array Res;
+  int i = 0;
+  for (Decl *Di : path.getCycleAtBack()) {
+Res[i++] = Di;
+  }
+  ASSERT_EQ(i, 4);
+  EXPECT_EQ(Res[0], D0);
+  EXPECT_EQ(Res[1], D2);
+  EXPECT_EQ(Res[2], D1);
+  EXPECT_EQ(Res[3], D0);
+
+  path.pop();
+  path.pop();
+  path.pop();
+  EXPECT_TRUE(path.hasCycleAtBack());
+  i = 0;
+  for (Decl *Di : path.getCycleAtBack()) {
+Res[i++] = Di;
+  }
+  ASSERT_EQ(i, 3);
+  EXPECT_EQ(Res[0], D0);
+  EXPECT_EQ(Res[1], D1);
+  EXPECT_EQ(Res[2], D0);
+
+  path.pop();
+  EXPECT_FALSE(path.hasCycleAtBack());
+}
+
 TEST_P(ImportExpr, ImportStringLiteral) {
   MatchVerifier Verifier;
   testImport(
@@ -4547,12 +4647,6 @@
   EXPECT_EQ(*Res.begin(), A);
 }
 
-INSTANTIATE_TEST_CASE_P(ParameterizedTests, DeclContextTest,
-::testing::Values(ArgVector()), );
-
-INSTANTIATE_TEST_CASE_P(
-ParameterizedTests, CanonicalRedeclChain,
-::testing::Values(ArgVector()),);
 
 // FIXME This test is disabled currently, upcoming patches will make it
 // possible to enable.
@@ -4770,19 +4864,99 @@
   CXXMethodDecl *ImportedF = Import(FromF, Lang_CXX);
   EXPECT_FALSE(ImportedF);
 
-  // There is no error set for ok().
+  // There is an error set for the other member too.
   auto *FromOK = FirstDeclMatcher().match(
   FromTU, cxxMethodDecl(hasName("ok")));
   OptErr = Importer->getImportDeclErrorIfAny(FromOK);
-  EXPECT_FALSE(OptErr);
-  // And we should be able to import.
+  EXPECT_TRUE(OptErr);
+  // Cannot import the other member.
   CXXMethodDecl *ImportedOK = Import(FromOK, Lang_CXX);
-  EXPECT_TRUE(ImportedOK);
+  EXPECT_FALSE(ImportedOK);
+}
+
+// Check that an error propagates to the dependent AST nodes.
+// In the below code it means that an error in X should propagate to A.
+// And even to F since the containing A is erroneous.
+// And to all AST nodes which we visit during the import process which finally
+// ends up in a failure (in the error() function).
+TEST_P(ErrorHandlingTest, ErrorPropagatesThroughImportCycles) {
+  Decl *FromTU = getTuDecl(
+  std::string(R"(
+  namespace NS {
+class A {
+  template  class F {};
+  class X {
+template  friend class F;
+void error() { )") + ErroneousStmt + R"( }
+  };
+};
+
+class B {};
+  } // NS
+  )",
+  Lang_CXX, "input0.cc");
+
+  auto *FromFRD = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("F"), isDefinition()));
+  auto *FromA = FirstDeclMatcher().match(
+  FromTU, cxxRecordDecl(hasName("A"), isDefinition()));
+  auto *FromB = F

[PATCH] D63288: [clang-tidy] Generalize TransformerClangTidyCheck to take a rule generator.

2019-06-24 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 206258.
ymandel marked 4 inline comments as done.
ymandel added a comment.

Adjust comments in test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63288

Files:
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
  clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/TransformerClangTidyCheckTest.cpp
@@ -18,16 +18,16 @@
 namespace tidy {
 namespace utils {
 namespace {
+using tooling::change;
 using tooling::RewriteRule;
+using tooling::text;
+using tooling::stencil::cat;
 
 // Invert the code of an if-statement, while maintaining its semantics.
 RewriteRule invertIf() {
   using namespace ::clang::ast_matchers;
-  using tooling::change;
   using tooling::node;
   using tooling::statement;
-  using tooling::text;
-  using tooling::stencil::cat;
 
   StringRef C = "C", T = "T", E = "E";
   RewriteRule Rule = tooling::makeRule(
@@ -65,6 +65,63 @@
   )";
   EXPECT_EQ(Expected, test::runCheckOnCode(Input));
 }
+
+// A trivial rewrite rule generator that requires C99 code to operate.
+Optional needsC99(const LangOptions &LangOpts,
+   const ClangTidyCheck::OptionsView &Options) {
+  if (!LangOpts.C99)
+return None;
+  return tooling::makeRule(clang::ast_matchers::functionDecl(),
+   change(cat("void nothing()")), text("no message"));
+}
+
+class NeedsC99Check : public TransformerClangTidyCheck {
+public:
+  NeedsC99Check(StringRef Name, ClangTidyContext *Context)
+  : TransformerClangTidyCheck(needsC99, Name, Context) {}
+};
+
+// Pass a C++ source file and expect no change, since the check requires `C99`
+// support to fire.
+TEST(TransformerClangTidyCheckTest, DisableByLang) {
+  // FIXME: We should be testing both the positive and negative case. However,
+  // as far as I can tell, all of the LangOpts are always set to false, so I
+  // have been unable to test the positive case (that is, where the
+  // `LangOpts.C99` is true).
+  const std::string Input = "void log(int);";
+  EXPECT_EQ(Input, test::runCheckOnCode(Input));
+}
+
+// A trivial rewrite rule generator that checks config options.
+Optional noSkip(const LangOptions &LangOpts,
+ const ClangTidyCheck::OptionsView &Options) {
+  if (Options.get("Skip", "false") == "true")
+return None;
+  return tooling::makeRule(clang::ast_matchers::functionDecl(),
+   change(cat("void nothing()")), text("no message"));
+}
+
+class ConfigurableCheck : public TransformerClangTidyCheck {
+public:
+  ConfigurableCheck(StringRef Name, ClangTidyContext *Context)
+  : TransformerClangTidyCheck(noSkip, Name, Context) {}
+};
+
+// Tests operation with config option "Skip" set to true and false.
+TEST(TransformerClangTidyCheckTest, DisableByConfig) {
+  const std::string Input = "void log(int);";
+  const std::string Expected = "void nothing();";
+  ClangTidyOptions Options;
+
+  Options.CheckOptions["test-check-0.Skip"] = "true";
+  EXPECT_EQ(Input, test::runCheckOnCode(
+   Input, nullptr, "input.cc", None, Options));
+
+  Options.CheckOptions["test-check-0.Skip"] = "false";
+  EXPECT_EQ(Expected, test::runCheckOnCode(
+  Input, nullptr, "input.cc", None, Options));
+}
+
 } // namespace
 } // namespace utils
 } // namespace tidy
Index: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
===
--- clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
+++ clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
@@ -31,19 +31,32 @@
 // };
 class TransformerClangTidyCheck : public ClangTidyCheck {
 public:
-  // All cases in \p R must have a non-null \c Explanation, even though \c
-  // Explanation is optional for RewriteRule in general. Because the primary
-  // purpose of clang-tidy checks is to provide users with diagnostics, we
-  // assume that a missing explanation is a bug.  If no explanation is desired,
-  // indicate that explicitly (for example, by passing `text("no explanation")`
-  //  to `makeRule` as the `Explanation` argument).
+  // \p MakeRule generates the rewrite rule to be used by the check, based on
+  // the given language and clang-tidy options. It can return \c None to handle
+  // cases where the options disable the check.
+  //
+  // All cases in the rule generated by \p MakeRule must have a non-null \c
+  // Explanation, even though \c Explanation is optional for RewriteRule in
+  // general. Because the primary purpo

[PATCH] D63288: [clang-tidy] Generalize TransformerClangTidyCheck to take a rule generator.

2019-06-24 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added inline comments.



Comment at: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp:33
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), Rule(MakeRule(getLangOpts(), Options)) {
+  assert(llvm::all_of(Rule.Cases, [](const RewriteRule::Case &C) {

gribozavr wrote:
> ymandel wrote:
> > gribozavr wrote:
> > > Can we dispatch to the other constructor?
> > I think not, but please correct me if I'm wrong (and clearly I should add a 
> > comment explaining this): in order to get meaningful results from 
> > `getLangOpts` and `Options`, we need the `ClangTidyCheck()` constructor to 
> > have been called. If we were to dispatch, it would look like:
> > ```
> >  : TransformerClangTidyCheck(MakeRule(getLangOpts(), Options), Name, 
> > Context) {}
> > ```
> > 
> > which, if I understand correctly, means that `MakeRule` will access that 
> > data _before_ the check object is properly initialized.
> > 
> > That said, I can factor out the assertion into a method to avoid the 
> > redundancy.  WDYT?
> You're right. I don't think it is necessary to factor out the assertion -- up 
> to you.
Decided not to factor.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63288



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


[PATCH] D62738: [HIP] Support device_shadow variable

2019-06-24 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: include/clang/Basic/Attr.td:954
 
+def CUDADeviceShadow : InheritableAttr {
+  let Spellings = [GNU<"device_shadow">, Declspec<"__device_shadow__">];

`HIPDeviceShadow` ?



Comment at: include/clang/Basic/Attr.td:955
+def CUDADeviceShadow : InheritableAttr {
+  let Spellings = [GNU<"device_shadow">, Declspec<"__device_shadow__">];
+  let Subjects = SubjectList<[Var]>;

In light of the details you've provided below, perhaps this needs a better 
name. I've suggested `__device_shadow__` without being aware of what exactly 
it's supposed to do in HIP.  
Perhaps something like `__hip_device_shadow__` or `__hip_pinned_shadow` ? 
Naming is hard. :-)



Comment at: include/clang/Basic/Attr.td:957
+  let Subjects = SubjectList<[Var]>;
+  let LangOpts = [CUDA];
+  let Documentation = [DeviceShadowDocs];

Shis should probably be `[HIP]` now, too.



Comment at: include/clang/Basic/AttrDocs.td:4164-4171
+The GNU style attribute __attribute__((device_shadow)) or MSVC style attribute
+__declspec(device_shadow) can be added to the definition of a global variable
+to indicate it is a HIP device shadow variable. A device shadow variable can
+be accessed on both device side and host side. It has external linkage and is
+not initialized on device side. It has internal linkage and is initialized by
+the initializer on host side.
+

yaxunl wrote:
> tra wrote:
> > just `device shadow variable` would do. It's no longer, generally speaking, 
> > HIP-specific. :-)
> > 
> > Only address and size of such variables should be used on device side.
> > 
> > I'd rephrase the use constraint. Currently it's `!(CUDA || !CUDA)` which is 
> > always false.
> > `Currently enabled for HIP only.` would be closer to reality.
> > 
> If only address and size of such variables should be used on device side, 
> such variables will not be very useful.
> 
> To implement texture reference, we need to be able to load the device side 
> shadow variable. In general, it is desirable to load and store device side 
> shadow variables, since users have no other way to synch with the 
> corresponding host variable in device code.
> 
> This is different from host side shadow variable. On host side, users can use 
> hipMemcpyToSymbol and hipMemcpyFromSymbol to force synchronization between 
> the host side shadow variable and the corresponding device variable.
> 
> Therefore the implementation of the device side shadow variable requires 
> special handling in HIP runtime. Basically HIP runtime needs to pin the host 
> variable and use it to resolve the device side shadow variable (as an 
> undefined elf symbol). This way, the host variable and device side shadow 
> variable are sharing the same memory. This is also why it is HIP specific 
> since CUDA runtime may not have such handling.
> 
> 
Thank you for providing the details. This use case is sufficiently different 
from the more general purpose reverse-shadow-var I had in mind.




Comment at: lib/CodeGen/CodeGenModule.cpp:3775
+  // left undefined.
+  bool IsHIPDeviceShadowVar = getLangOpts().HIP && getLangOpts().CUDAIsDevice 
&&
+  D->hasAttr();

yaxunl wrote:
> tra wrote:
> > `IsDeviceShadowVar`. We may want to rename `IsCUDAShadowVar` to 
> > `IsHostShadowVar` to be consistent.
> > 
> > This got me thinking. Conceptually we have two different things going on 
> > here.
> > * where do we place the real variable
> > * whether we need to create a shadow on the other end.
> > 
> > Currently `__device__`, `__constant__` and `__shared__` act as both.
> > This patch implements the same `make a shadow on the other side`, only in 
> > the opposite direction.
> > 
> > Perhaps the right thing to do is to push the patch even further and make it 
> > into a `__shadow_variable__` which will be responsible for creating the 
> > other side shadow and would work in both directions.
> > 
> > We can then assign implicit `__shadow_variable__` attribute to the 
> > device-side vars to preserve current behavior and it will work for your 
> > purposes two. We will also gain ability to create device-side variables w/o 
> > host-side shadows, if we need to.
> > 
> > I guess in the end it would be this patch + a bit of refactoring/collapsing 
> > of `IsCUDAShadowVar` logic.
> Do we really want to introduce a generic `__shadow_variable__` for device 
> variables? It has little use but complicates AST of device variables 
> unnecessarily. First it bring no new functionality since device variables are 
> already shadowed by default. Second since unused shadow variable is 
> eliminated automatically due to their internal linkage, disable shadowing 
> will not save memory in host binary.
There's currently no specific use case for it in CUDA and HIP's use case also 
does not quite fit this, so `__shadow_variab

[PATCH] D63720: [analyzer] ExprEngine: Escape pointers in bitwise operations

2019-06-24 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso marked an inline comment as done.
Charusso added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp:123
 state = state->BindExpr(B, LCtx, Result);
   }
 

I have seen we are producing tons of Unknowns and I am still not sure where 
they go, but even if I remove that condition these Unknowns will not shown up 
in the ExplodedGraph. I believe that should be the correct behavior.


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

https://reviews.llvm.org/D63720



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


[PATCH] D62970: [clang-doc] De-duplicate comments and locations

2019-06-24 Thread Jake Ehrlich via Phabricator via cfe-commits
jakehehrlich added a comment.

LGTM




Comment at: clang-tools-extra/clang-doc/Representation.h:66
+
+  bool operator<(const CommentInfo &Other) const {
+auto FirstCI = std::tie(Kind, Text, Name, Direction, ParamName, CloseName,

We should be explicit about what we intend to happen here. Do we just want a 
total ordering of any kind? Do we want some things to be "more important" than 
others? For instance because the ordering is lexicographical here Kind is more 
important than Text which is more important than Name etc...

If the intent is just to have any total order state so at the top and why we 
need a total ordering (for instance to have an std::set/std::map of these 
things or we need to sort them, etc...)



Comment at: clang-tools-extra/clang-doc/Representation.h:186
 
+  bool operator<(const Location &Other) const {
+return std::tie(LineNumber, Filename) <

Same comment here.


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

https://reviews.llvm.org/D62970



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


[PATCH] D63518: WIP BitStream reader: propagate errors

2019-06-24 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

`check-clang` now passes all tests, so the patch is pretty much ready to 
review. I'll get started on the other parts of LLVM that use this API.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63518



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


[PATCH] D63276: [AST] Add FunctionDecl::getParametersSourceRange()

2019-06-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: aaron.ballman.
aaron.ballman added inline comments.



Comment at: clang/include/clang/AST/Decl.h:2331
+  /// Attempt to compute an informative source range covering the
+  /// function parameters. This omits the ellipsis of a variadic function.
+  SourceRange getParametersSourceRange() const;

Why does this omit the ellipsis? It's part of the parameter list and it seems 
like a strange design decision to leave that out of the source range for the 
parameter list.



Comment at: clang/lib/AST/Decl.cpp:3305
+SourceRange FunctionDecl::getParametersSourceRange() const {
+  auto NP = getNumParams();
+  if (NP == 0)

Please don't use `auto` here (or below); the type is not spelled out in the 
initialization.



Comment at: clang/unittests/AST/SourceLocationTest.cpp:676
+}
+
 TEST(CXXMethodDecl, CXXMethodDeclWithThrowSpecification) {

I'd like to see tests that include an ellipsis, as well as tests that use the 
preprocessor in creative ways. e.g.,
```
#define FOO  int a, int b

void func(FOO);
void bar(float f, FOO, float g);
void baz(FOO, float f);
void quux(float f, FOO);
```
Also, tests for member functions (both static and instance functions) and 
parameters with leading attributes would be useful. e.g.,
```
void func([[]] int *i);
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63276



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


[PATCH] D63623: [clang-tidy] Add a check on expected return values of posix functions (except posix_openpt) in Android module.

2019-06-24 Thread Jian Cai via Phabricator via cfe-commits
jcai19 updated this revision to Diff 206273.
jcai19 added a comment.

Fix typos and formatting issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63623

Files:
  clang-tools-extra/clang-tidy/android/AndroidTidyModule.cpp
  clang-tools-extra/clang-tidy/android/CMakeLists.txt
  clang-tools-extra/clang-tidy/android/PosixReturnCheck.cpp
  clang-tools-extra/clang-tidy/android/PosixReturnCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/android-posix-return.rst
  clang-tools-extra/test/clang-tidy/android-posix-return.cpp

Index: clang-tools-extra/test/clang-tidy/android-posix-return.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/android-posix-return.cpp
@@ -0,0 +1,89 @@
+// RUN: %check_clang_tidy %s android-posix-return %t
+
+#define NULL nullptr
+#define ZERO 0
+#define NEGATIVE_ONE -1
+
+typedef long off_t;
+typedef int size_t;
+typedef int pid_t;
+typedef struct __posix_spawn_file_actions* posix_spawn_file_actions_t;
+typedef struct __posix_spawnattr* posix_spawnattr_t;
+
+extern "C" int posix_fadvise(int fd, off_t offset, off_t len, int advice);
+extern "C" int posix_fallocate(int fd, off_t offset, off_t len);
+extern "C" int posix_madvise(void *addr, size_t len, int advice);
+extern "C" int posix_memalign(void **memptr, size_t alignment, size_t size);
+extern "C" int posix_openpt(int flags);
+extern "C" int posix_spawn(pid_t *pid, const char *path,
+const posix_spawn_file_actions_t *file_actions,
+const posix_spawnattr_t *attrp,
+char *const argv[], char *const envp[]);
+extern "C" int posix_spawnp(pid_t *pid, const char *file,
+ const posix_spawn_file_actions_t *file_actions,
+ const posix_spawnattr_t *attrp,
+ char *const argv[], char *const envp[]);
+
+void warningLtZero() {
+  if (posix_fadvise(0, 0, 0, 0) < 0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning:
+  if (posix_fallocate(0, 0, 0) < 0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:32: warning:
+  if (posix_madvise(NULL, 0, 0) < 0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning:
+  if (posix_memalign(NULL, 0, 0) < 0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning:
+  if (posix_spawn(NULL, NULL, NULL, NULL, {NULL}, {NULL}) < 0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:59: warning:
+  if (posix_spawnp(NULL, NULL, NULL, NULL, {NULL}, {NULL}) < 0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:60: warning:
+}
+
+void warningEqualsNegative() {
+  if (posix_fadvise(0, 0, 0, 0) == -1) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning:
+  if (posix_fallocate(0, 0, 0) == -1) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:32: warning:
+  if (posix_madvise(NULL, 0, 0) == -1) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning:
+  if (posix_memalign(NULL, 0, 0) == -1) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning:
+  if (posix_spawn(NULL, NULL, NULL, NULL, {NULL}, {NULL}) == -1) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:59: warning:
+  if (posix_spawnp(NULL, NULL, NULL, NULL, {NULL}, {NULL}) == -1) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:60: warning:
+}
+
+void WarningWithMacro() {
+  if (posix_fadvise(0, 0, 0, 0) < ZERO) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning:
+  if (posix_fadvise(0, 0, 0, 0) == NEGATIVE_ONE) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning:
+}
+
+void noWarning() {
+  if (posix_openpt(0) < 0) {}
+  if (posix_openpt(0) == -1) {}
+  if (posix_fadvise(0, 0, 0, 0) >= 0) {}
+  if (posix_fadvise(0, 0, 0, 0) == 1) {}
+}
+
+namespace i {
+int posix_fadvise(int fd, off_t offset, off_t len, int advice);
+
+void noWarning() {
+  if (posix_fadvise(0, 0, 0, 0) < 0) {}
+  if (posix_fadvise(0, 0, 0, 0) == -1) {}
+}
+
+} // namespace i
+
+class G {
+ public:
+  int posix_fadvise(int fd, off_t offset, off_t len, int advice);
+
+  void noWarning() {
+if (posix_fadvise(0, 0, 0, 0) < 0) {}
+if (posix_fadvise(0, 0, 0, 0) == -1) {}
+  }
+};
Index: clang-tools-extra/docs/clang-tidy/checks/android-posix-return.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/android-posix-return.rst
@@ -0,0 +1,21 @@
+.. title:: clang-tidy - android-posix-return
+
+android-posix-return
+
+
+Checks if any calls to POSIX functions (except ``posix_openpt``) expect negative
+return values. These functions return either ``0`` on success or an ``errno`` on failure,
+which is positive only.
+
+Example buggy usage looks like:
+
+.. code-block:: c
+
+  if (posix_fadvise(...) < 0) {
+
+This will never happen as the return value is always non-negative. A simple fix could be:
+
+.. code-block:: c
+
+  int ret = posix_fadvise(...);
+  if (ret != 0) ...
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/Rele

[libunwind] r364217 - Merging r360861:

2019-06-24 Thread Tom Stellard via cfe-commits
Author: tstellar
Date: Mon Jun 24 11:40:58 2019
New Revision: 364217

URL: http://llvm.org/viewvc/llvm-project?rev=364217&view=rev
Log:
Merging r360861:


r360861 | mstorsjo | 2019-05-15 23:49:13 -0700 (Wed, 15 May 2019) | 13 lines

[PPC64][libunwind] Fix r2 not properly restored

This change makes each unwind step inspect the instruction at the
return address and, if needed, read r2 from its saved location and
modify the context appropriately.

The unwind logic is able to handle both ELFv1 and ELFv2 stacks.

Reported by Bug 41050

Patch by Leandro Lupori!

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


Modified:
libunwind/branches/release_80/src/DwarfInstructions.hpp
libunwind/branches/release_80/src/assembly.h
libunwind/branches/release_80/test/lit.cfg

Modified: libunwind/branches/release_80/src/DwarfInstructions.hpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/branches/release_80/src/DwarfInstructions.hpp?rev=364217&r1=364216&r2=364217&view=diff
==
--- libunwind/branches/release_80/src/DwarfInstructions.hpp (original)
+++ libunwind/branches/release_80/src/DwarfInstructions.hpp Mon Jun 24 11:40:58 
2019
@@ -234,6 +234,31 @@ int DwarfInstructions::stepWithDwa
   }
 #endif
 
+#if defined(_LIBUNWIND_TARGET_PPC64)
+#define PPC64_ELFV1_R2_LOAD_INST_ENCODING 0xe8410028u // ld r2,40(r1)
+#define PPC64_ELFV1_R2_OFFSET 40
+#define PPC64_ELFV2_R2_LOAD_INST_ENCODING 0xe8410018u // ld r2,24(r1)
+#define PPC64_ELFV2_R2_OFFSET 24
+  // If the instruction at return address is a TOC (r2) restore,
+  // then r2 was saved and needs to be restored.
+  // ELFv2 ABI specifies that the TOC Pointer must be saved at SP + 24,
+  // while in ELFv1 ABI it is saved at SP + 40.
+  if (R::getArch() == REGISTERS_PPC64 && returnAddress != 0) {
+pint_t sp = newRegisters.getRegister(UNW_REG_SP);
+pint_t r2 = 0;
+switch (addressSpace.get32(returnAddress)) {
+case PPC64_ELFV1_R2_LOAD_INST_ENCODING:
+  r2 = addressSpace.get64(sp + PPC64_ELFV1_R2_OFFSET);
+  break;
+case PPC64_ELFV2_R2_LOAD_INST_ENCODING:
+  r2 = addressSpace.get64(sp + PPC64_ELFV2_R2_OFFSET);
+  break;
+}
+if (r2)
+  newRegisters.setRegister(UNW_PPC64_R2, r2);
+  }
+#endif
+
   // Return address is address after call site instruction, so setting IP 
to
   // that does simualates a return.
   newRegisters.setIP(returnAddress);

Modified: libunwind/branches/release_80/src/assembly.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/branches/release_80/src/assembly.h?rev=364217&r1=364216&r2=364217&view=diff
==
--- libunwind/branches/release_80/src/assembly.h (original)
+++ libunwind/branches/release_80/src/assembly.h Mon Jun 24 11:40:58 2019
@@ -35,6 +35,20 @@
 #define SEPARATOR ;
 #endif
 
+#if defined(__powerpc64__) && (!defined(_CALL_ELF) || _CALL_ELF == 1)
+#define PPC64_OPD1 .section .opd,"aw",@progbits SEPARATOR
+#define PPC64_OPD2 SEPARATOR \
+  .p2align 3 SEPARATOR \
+  .quad .Lfunc_begin0 SEPARATOR \
+  .quad .TOC.@tocbase SEPARATOR \
+  .quad 0 SEPARATOR \
+  .text SEPARATOR \
+.Lfunc_begin0:
+#else
+#define PPC64_OPD1
+#define PPC64_OPD2
+#endif
+
 #define GLUE2(a, b) a ## b
 #define GLUE(a, b) GLUE2(a, b)
 #define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
@@ -95,7 +109,9 @@
   .globl SYMBOL_NAME(name) SEPARATOR  \
   EXPORT_SYMBOL(name) SEPARATOR   \
   SYMBOL_IS_FUNC(SYMBOL_NAME(name)) SEPARATOR \
-  SYMBOL_NAME(name):
+  PPC64_OPD1  \
+  SYMBOL_NAME(name):  \
+  PPC64_OPD2
 
 #define DEFINE_LIBUNWIND_PRIVATE_FUNCTION(name)   \
   .globl SYMBOL_NAME(name) SEPARATOR  \

Modified: libunwind/branches/release_80/test/lit.cfg
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/branches/release_80/test/lit.cfg?rev=364217&r1=364216&r2=364217&view=diff
==
--- libunwind/branches/release_80/test/lit.cfg (original)
+++ libunwind/branches/release_80/test/lit.cfg Mon Jun 24 11:40:58 2019
@@ -23,6 +23,9 @@ config.suffixes = ['.cpp', '.s']
 # test_source_root: The root path where tests are located.
 config.test_source_root = os.path.dirname(__file__)
 
+# needed to test libunwind with code that throws exceptions
+config.enable_exceptions = True
+
 # Infer the libcxx_test_source_root for configuration import.
 # If libcxx_source_root isn't specified in the config, assume that the libcxx
 # and libunwind source directories are sibling directories.


___

[PATCH] D63623: [clang-tidy] Add a check on expected return values of posix functions (except posix_openpt) in Android module.

2019-06-24 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D63623#1552716 , @jcai19 wrote:

> In D63623#1552679 , @lebedev.ri 
> wrote:
>
> > Why is this in android module?
> >  Is that android-specific behavior, or posix?
>
>
> I implemented it for Andriod as requested, but it would be completely fine to 
> move it if it is better to place the check at a different location. Where do 
> you suggest we should move this check to? Thanks.


Either `misc` or `bugprone` or a new `posix` module.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63623



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


[PATCH] D63623: [clang-tidy] Add a check on expected return values of posix functions (except posix_openpt) in Android module.

2019-06-24 Thread Jian Cai via Phabricator via cfe-commits
jcai19 marked 10 inline comments as done.
jcai19 added inline comments.



Comment at: clang-tools-extra/clang-tidy/android/PosixReturnCheck.cpp:23
+  binaryOperator(
+  hasOperatorName("<"),
+  hasLHS(callExpr(callee(functionDecl(matchesName("^::posix_"), 
unless(hasName("posix_openpt")),

george.burgess.iv wrote:
> should we also try to catch `<= ${negative_value}` (or `< ${negative_value}`)?
Sounds good. Will update the patch to catch these two cases as well.



Comment at: clang-tools-extra/clang-tidy/android/PosixReturnCheck.cpp:29
+  binaryOperator(
+  hasOperatorName("=="),
+  hasLHS(callExpr(callee(functionDecl(matchesName("^::posix_"), 
unless(hasName("posix_openpt")),

george.burgess.iv wrote:
> similarly, should we complain about `!= ${negative_value}`?
Sounds good. Will update the patch to catch these additional cases as well.



Comment at: clang-tools-extra/clang-tidy/android/PosixReturnCheck.cpp:39
+  const auto &BinOp = *Result.Nodes.getNodeAs("binop");
+  diag(BinOp.getOperatorLoc(), "posix functions (except posix_openpt) never 
return negative values");
+}

george.burgess.iv wrote:
> would it be helpful to add fixits for simple cases? e.g. we can probably 
> offer to replace `posix_whatever() < 0` with `posix_whatever() > 0` or `!= 0`
While this fix is handy, I am not sure whether it will be safe enough under all 
circumstances. For example, is it possible in the code block following the 
check, the program calls another POSIX function and alter the errno before its 
value it checked? In that case, maybe the proper fix should be something as 
follows and fixing it by changing the binary operator may obscure it:

int ret = posix_whatever();
if (ret != 0)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63623



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


[PATCH] D62738: [HIP] Support device_shadow variable

2019-06-24 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added inline comments.



Comment at: include/clang/Basic/Attr.td:955
+def CUDADeviceShadow : InheritableAttr {
+  let Spellings = [GNU<"device_shadow">, Declspec<"__device_shadow__">];
+  let Subjects = SubjectList<[Var]>;

tra wrote:
> In light of the details you've provided below, perhaps this needs a better 
> name. I've suggested `__device_shadow__` without being aware of what exactly 
> it's supposed to do in HIP.  
> Perhaps something like `__hip_device_shadow__` or `__hip_pinned_shadow` ? 
> Naming is hard. :-)
I think `__hip_pinned_shadow__` best describes such variables. I will update 
the patch to adopt it.


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

https://reviews.llvm.org/D62738



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


[PATCH] D61809: [BPF] Preserve debuginfo array/union/struct type/access index

2019-06-24 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song updated this revision to Diff 206274.
yonghong-song added a comment.

do not use ctx.getParents() to check whether a GEP candidate inside a 
preserve_access_index. instead, mark the region upfront. Add the new clang 
intrinsic into the language doc.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61809

Files:
  docs/LanguageExtensions.rst
  include/clang/Basic/Builtins.def
  lib/CodeGen/CGBuilder.h
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Sema/SemaChecking.cpp
  test/CodeGen/bpf-preserve-access-index-2.c
  test/CodeGen/bpf-preserve-access-index.c

Index: test/CodeGen/bpf-preserve-access-index.c
===
--- /dev/null
+++ test/CodeGen/bpf-preserve-access-index.c
@@ -0,0 +1,28 @@
+// RUN: %clang %s -target bpfeb -x c -emit-llvm -S -g -O2 -o - | FileCheck --check-prefix=CHECK %s
+// RUN: %clang %s -target bpfel -x c -emit-llvm -S -g -O2 -o - | FileCheck --check-prefix=CHECK %s
+// RUN: %clang %s -target bpfeb -x c -emit-llvm -S -O2 -o - | FileCheck --check-prefix=CHECK-NODBG %s
+// RUN: %clang %s -target bpfel -x c -emit-llvm -S -O2 -o - | FileCheck --check-prefix=CHECK-NODBG %s
+
+struct t {
+  int i:1;
+  int j:2;
+  union {
+   int a;
+   int b;
+  } c[4];
+};
+
+#define _(x) (__builtin_preserve_access_index(x))
+
+void *test(struct t *arg) {
+  return _(&arg->c[3].b);
+}
+
+// CHECK: llvm.preserve.struct.access.index
+// CHECK: llvm.preserve.array.access.index
+// CHECK: llvm.preserve.union.access.index
+// CHECK-NOT: __builtin_preserve_access_index
+// CHECK-NODBG-NOT: llvm.preserve.struct.access.index
+// CHECK-NODBG-NOT: llvm.preserve.array.access.index
+// CHECK-NODBG-NOT: llvm.preserve.union.access.index
+// CHECK-NODBG-NOT: __builtin_preserve_access_index
Index: test/CodeGen/bpf-preserve-access-index-2.c
===
--- /dev/null
+++ test/CodeGen/bpf-preserve-access-index-2.c
@@ -0,0 +1,22 @@
+// RUN: %clang %s -target bpfeb -x c -emit-llvm -S -g -O2 -o - | FileCheck %s
+// RUN: %clang %s -target bpfel -x c -emit-llvm -S -g -O2 -o - | FileCheck %s
+
+struct t {
+  int i:1;
+  int j:2;
+  union {
+   int a;
+   int b;
+  } c[4];
+};
+
+#define _(x) (x)
+
+void *test(struct t *arg) {
+  return _(&arg->c[3].b);
+}
+
+// CHECK-NOT: llvm.preserve.struct.access.index
+// CHECK-NOT: llvm.preserve.array.access.index
+// CHECK-NOT: llvm.preserve.union.access.index
+// CHECK-NOT: __builtin_preserve_access_index
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -191,6 +191,16 @@
   return false;
 }
 
+/// Check the number of arguments, and set the result type to
+/// the argument type.
+static bool SemaBuiltinPreserveAI(Sema &S, CallExpr *TheCall) {
+  if (checkArgCount(S, TheCall, 1))
+return true;
+
+  TheCall->setType(TheCall->getArg(0)->getType());
+  return false;
+}
+
 static bool SemaBuiltinOverflow(Sema &S, CallExpr *TheCall) {
   if (checkArgCount(S, TheCall, 3))
 return true;
@@ -1409,6 +1419,10 @@
 TheCall->setType(Context.IntTy);
 break;
   }
+  case Builtin::BI__builtin_preserve_access_index:
+if (SemaBuiltinPreserveAI(*this, TheCall))
+  return ExprError();
+break;
   case Builtin::BI__builtin_call_with_static_chain:
 if (SemaBuiltinCallWithStaticChain(*this, TheCall))
   return ExprError();
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -480,6 +480,10 @@
   /// finally block or filter expression.
   bool IsOutlinedSEHHelper = false;
 
+  /// True if CodeGen currently emits code inside presereved access index
+  /// region.
+  bool IsInPreservedAIRegion = false;
+
   const CodeGen::CGBlockInfo *BlockInfo = nullptr;
   llvm::Value *BlockPointer = nullptr;
 
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -25,6 +25,7 @@
 #include "clang/AST/Attr.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/NSAPI.h"
+#include "clang/Basic/Builtins.h"
 #include "clang/Basic/CodeGenOptions.h"
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/StringExtras.h"
@@ -3418,8 +3419,20 @@
   CharUnits eltAlign =
 getArrayElementAlign(addr.getAlignment(), indices.back(), eltSize);
 
-  llvm::Value *eltPtr = emitArraySubscriptGEP(
-  CGF, addr.getPointer(), indices, inbounds, signedIndices, loc, name);
+  llvm::Value *eltPtr;
+  auto LastIndex = dyn_cast(indices.back());
+  if (!CGF.IsInPreservedAIRegion || !LastIndex) {
+eltPtr = emitArraySubscriptGEP(
+CGF, addr.getPointer(), indices, inbounds, signedIndices,
+loc, name);
+  } else {
+// Remember the original

[PATCH] D61809: [BPF] Preserve debuginfo array/union/struct type/access index

2019-06-24 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song marked an inline comment as not done.
yonghong-song added a comment.

@eli.friedman I removed the usage of astcontext getParents() stuff. Instead, I 
mark the region upfront. I also added the intrinsic 
__builtin_preserve_access_index() into clang
lang extention doc. Could you take a look at new patch? Thanks!


Repository:
  rC Clang

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

https://reviews.llvm.org/D61809



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


[PATCH] D63734: Update CODE_OWNERS.txt for clang-doc

2019-06-24 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett created this revision.
juliehockett added a reviewer: klimek.
juliehockett added a project: clang-tools-extra.

https://reviews.llvm.org/D63734

Files:
  clang-tools-extra/CODE_OWNERS.TXT


Index: clang-tools-extra/CODE_OWNERS.TXT
===
--- clang-tools-extra/CODE_OWNERS.TXT
+++ clang-tools-extra/CODE_OWNERS.TXT
@@ -19,3 +19,7 @@
 N: Alexander Kornienko
 E: ale...@google.com
 D: clang-tidy
+
+N: Julie Hockett
+E: juliehock...@google.com
+D: clang-doc


Index: clang-tools-extra/CODE_OWNERS.TXT
===
--- clang-tools-extra/CODE_OWNERS.TXT
+++ clang-tools-extra/CODE_OWNERS.TXT
@@ -19,3 +19,7 @@
 N: Alexander Kornienko
 E: ale...@google.com
 D: clang-tidy
+
+N: Julie Hockett
+E: juliehock...@google.com
+D: clang-doc
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63180: [clang-doc] Adds HTML generator

2019-06-24 Thread Jake Ehrlich via Phabricator via cfe-commits
jakehehrlich added a comment.

I got to the 'genHTML' functions and I decided that this general approach is 
not great.

What if we have a baby internal representation of an HTML tree, generate 
instances of that, and then implement a render method on that (preferably one 
that handles indentation or would have the ability to do so soon).

I also think we could split this up and support only a subset of the comment 
types at first to reduce the review load.




Comment at: clang-tools-extra/clang-doc/Generators.cpp:60-71
+std::string genReferenceList(const llvm::SmallVectorImpl &Refs) {
+  std::string Buffer;
+  llvm::raw_string_ostream Stream(Buffer);
+  bool First = true;
+  for (const auto &R : Refs) {
+if (!First)
+  Stream << ", ";

This seems to be displaying a list in a particular way. Mind adding a comment 
about where this is used?



Comment at: clang-tools-extra/clang-doc/Generators.cpp:65
+  for (const auto &R : Refs) {
+if (!First)
+  Stream << ", ";

You can just use `&R != Refs.begin()` or `&R != &Refs.front()` and then you 
don't have to keep any local state and its clear when that condition would be 
true/false.



Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:25
+
+std::string genTag(const Twine &Text, const Twine &Tag) {
+  return "<" + Tag.str() + ">" + Text.str() + "";

This can also be a Twine



Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:33-35
+void writeLine(const Twine &Text, raw_ostream &OS) {
+  OS << genTag(Text, "p") << "\n";
+}

I'm not familiar with HTML.  What does this '' do?



Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:66
+OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n\n";
+  } else if (I.Kind == "TParamCommandComment") {
+std::string Direction = I.Explicit ? (" " + I.Direction).str() : "";

Instead of repeating code add an "||" case to the above.



Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:67-68
+  } else if (I.Kind == "TParamCommandComment") {
+std::string Direction = I.Explicit ? (" " + I.Direction).str() : "";
+OS << genEmphasis(I.ParamName) << I.Text << Direction << "\n\n";
+  } else if (I.Kind == "VerbatimBlockComment") {

Instead of making a local `std::string` you can first write the emphasis then 
decide wheater or not to output the direction, and then output the newlines 
unconditionally.



Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:72-77
+  } else if (I.Kind == "VerbatimBlockLineComment") {
+OS << I.Text;
+writeNewLine(OS);
+  } else if (I.Kind == "VerbatimLineComment") {
+OS << I.Text;
+writeNewLine(OS);

Dedup these.



Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:81-84
+std::string Buffer;
+llvm::raw_string_ostream Attrs(Buffer);
+for (unsigned Idx = 0; Idx < I.AttrKeys.size(); ++Idx)
+  Attrs << " \"" << I.AttrKeys[Idx] << "=" << I.AttrValues[Idx] << "\"";

I don't see the need for an intermediete ostream. 

```
OS << "<" << I.Name;
for (...)
  OS << ...;
writeLine(I.SelfClosing ? ..., OS);
```

would work fine and be more efficient.



Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:86
+
+std::string CloseTag = I.SelfClosing ? "/>" : ">";
+writeLine("<" + I.Name + Attrs.str() + CloseTag, OS);

This can be a StringRef



Comment at: clang-tools-extra/clang-doc/HTMLGenerator.cpp:106-107
+
+  std::string Buffer;
+  llvm::raw_string_ostream Members(Buffer);
+  if (!I.Members.empty())

This is a generally bad pattern.


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

https://reviews.llvm.org/D63180



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


[clang-tools-extra] r364222 - [clang-doc] Add basic support for templates and typedef

2019-06-24 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Mon Jun 24 12:31:02 2019
New Revision: 364222

URL: http://llvm.org/viewvc/llvm-project?rev=364222&view=rev
Log:
[clang-doc] Add basic support for templates and typedef

In serialize::parseBases(...), when a base record is a template
specialization, the specialization was used as the parent. It should be
the base template so there is only one file generated for this record.
When the specialized template is implicitly declared the reference USR
corresponded to the GlobalNamespace's USR, this will now be the base
template's USR.

More information about templates will be added later.

In serialize::emiInfo(RecorDecl*, ...), typedef records were not handled
and the name was empty. This is now handled and a IsTypeDef attribute is
added to RecordInfo struct.

In serialize::emitInfo(CXXMethodDecl*, ...), template specialization is
handled like in serialize::parseBases(...).

Bitcode writer and reader are modified to handle the new attribute of
RecordInfo.

Submitted on behalf of Diego Astiazarán (diegoaa...@gmail.com)
Differential Revision: https://reviews.llvm.org/D63367

Modified:
clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp
clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
clang-tools-extra/trunk/clang-doc/Representation.h
clang-tools-extra/trunk/clang-doc/Serialize.cpp
clang-tools-extra/trunk/unittests/clang-doc/BitcodeTest.cpp
clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp
clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp

Modified: clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp?rev=364222&r1=364221&r2=364222&view=diff
==
--- clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp Mon Jun 24 12:31:02 2019
@@ -167,6 +167,8 @@ llvm::Error parseRecord(Record R, unsign
 return decodeRecord(R, I->Loc, Blob);
   case RECORD_TAG_TYPE:
 return decodeRecord(R, I->TagType, Blob);
+  case RECORD_IS_TYPE_DEF:
+return decodeRecord(R, I->IsTypeDef, Blob);
   default:
 return llvm::make_error(
 "Invalid field for RecordInfo.\n", llvm::inconvertibleErrorCode());

Modified: clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp?rev=364222&r1=364221&r2=364222&view=diff
==
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp Mon Jun 24 12:31:02 2019
@@ -159,6 +159,7 @@ static const llvm::IndexedMaphttp://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/BitcodeWriter.h?rev=364222&r1=364221&r2=364222&view=diff
==
--- clang-tools-extra/trunk/clang-doc/BitcodeWriter.h (original)
+++ clang-tools-extra/trunk/clang-doc/BitcodeWriter.h Mon Jun 24 12:31:02 2019
@@ -102,6 +102,7 @@ enum RecordId {
   RECORD_DEFLOCATION,
   RECORD_LOCATION,
   RECORD_TAG_TYPE,
+  RECORD_IS_TYPE_DEF,
   REFERENCE_USR,
   REFERENCE_NAME,
   REFERENCE_TYPE,

Modified: clang-tools-extra/trunk/clang-doc/Representation.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Representation.h?rev=364222&r1=364221&r2=364222&view=diff
==
--- clang-tools-extra/trunk/clang-doc/Representation.h (original)
+++ clang-tools-extra/trunk/clang-doc/Representation.h Mon Jun 24 12:31:02 2019
@@ -241,6 +241,7 @@ struct RecordInfo : public SymbolInfo {
   TagTypeKind TagType = TagTypeKind::TTK_Struct; // Type of this record
  // (struct, class, union,
  // interface).
+  bool IsTypeDef = false; // Indicates if record was declared using typedef
   llvm::SmallVector
   Members; // List of info about record 
members.
   llvm::SmallVector Parents; // List of base/parent records

Modified: clang-tools-extra/trunk/clang-doc/Serialize.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/Serialize.cpp?rev=364222&r1=364221&r2=364222&view=diff
==
--- clang-tools-extra/trunk/clang-doc/Serialize.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/Serialize.cpp Mon Jun 24 12:31:02 2019
@@ -179,10 +179,9 @@ static SymbolID getUSRForDecl(const Decl
 }
 
 static RecordDecl *getDeclForType(const QualType &T) {
-  auto *Ty = T->getAs();
-  if (!Ty)
-return nullptr;
-  return Ty->getDecl()->getDefinition();
+  if (const RecordDecl *D = T->getAsRecor

[PATCH] D63367: [clang-doc] Add basic support for templates and typedef

2019-06-24 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL364222: [clang-doc] Add basic support for templates and 
typedef (authored by juliehockett, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63367?vs=205169&id=206282#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63367

Files:
  clang-tools-extra/trunk/clang-doc/BitcodeReader.cpp
  clang-tools-extra/trunk/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/trunk/clang-doc/BitcodeWriter.h
  clang-tools-extra/trunk/clang-doc/Representation.h
  clang-tools-extra/trunk/clang-doc/Serialize.cpp
  clang-tools-extra/trunk/unittests/clang-doc/BitcodeTest.cpp
  clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp
  clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp

Index: clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/ClangDocTest.cpp
@@ -151,6 +151,8 @@
 
   EXPECT_EQ(Expected->TagType, Actual->TagType);
 
+  EXPECT_EQ(Expected->IsTypeDef, Actual->IsTypeDef);
+
   ASSERT_EQ(Expected->Members.size(), Actual->Members.size());
   for (size_t Idx = 0; Idx < Actual->Members.size(); ++Idx)
 EXPECT_EQ(Expected->Members[Idx], Actual->Members[Idx]);
Index: clang-tools-extra/trunk/unittests/clang-doc/BitcodeTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/BitcodeTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/BitcodeTest.cpp
@@ -80,6 +80,7 @@
 
   I.Members.emplace_back("int", "X", AccessSpecifier::AS_private);
   I.TagType = TagTypeKind::TTK_Class;
+  I.IsTypeDef = true;
   I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record);
   I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
 
Index: clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/trunk/unittests/clang-doc/SerializeTest.cpp
@@ -142,7 +142,15 @@
   E() {}
 protected:
   void ProtectedMethod();
-};)raw", 3, /*Public=*/false, Infos);
+};
+template 
+struct F {
+  void TemplateMethod();
+};
+template <>
+void F::TemplateMethod();
+typedef struct {} G;)raw",
+   7, /*Public=*/false, Infos);
 
   RecordInfo *E = InfoAsRecord(Infos[0].get());
   RecordInfo ExpectedE(EmptySID, "E");
@@ -176,6 +184,51 @@
   Method.IsMethod = true;
   ExpectedRecordWithMethod.ChildFunctions.emplace_back(std::move(Method));
   CheckRecordInfo(&ExpectedRecordWithMethod, RecordWithMethod);
+
+  RecordInfo *F = InfoAsRecord(Infos[3].get());
+  RecordInfo ExpectedF(EmptySID, "F");
+  ExpectedF.TagType = TagTypeKind::TTK_Struct;
+  ExpectedF.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
+  CheckRecordInfo(&ExpectedF, F);
+
+  RecordInfo *RecordWithTemplateMethod = InfoAsRecord(Infos[4].get());
+  RecordInfo ExpectedRecordWithTemplateMethod(EmptySID);
+  FunctionInfo TemplateMethod;
+  TemplateMethod.Name = "TemplateMethod";
+  TemplateMethod.Parent = Reference(EmptySID, "F", InfoType::IT_record);
+  TemplateMethod.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
+  TemplateMethod.Loc.emplace_back(0, llvm::SmallString<16>{"test.cpp"});
+  TemplateMethod.Namespace.emplace_back(EmptySID, "F", InfoType::IT_record);
+  TemplateMethod.Access = AccessSpecifier::AS_public;
+  TemplateMethod.IsMethod = true;
+  ExpectedRecordWithTemplateMethod.ChildFunctions.emplace_back(
+  std::move(TemplateMethod));
+  CheckRecordInfo(&ExpectedRecordWithTemplateMethod, RecordWithTemplateMethod);
+
+  RecordInfo *TemplatedRecord = InfoAsRecord(Infos[5].get());
+  RecordInfo ExpectedTemplatedRecord(EmptySID);
+  FunctionInfo SpecializedTemplateMethod;
+  SpecializedTemplateMethod.Name = "TemplateMethod";
+  SpecializedTemplateMethod.Parent =
+  Reference(EmptySID, "F", InfoType::IT_record);
+  SpecializedTemplateMethod.ReturnType =
+  TypeInfo(EmptySID, "void", InfoType::IT_default);
+  SpecializedTemplateMethod.Loc.emplace_back(0,
+ llvm::SmallString<16>{"test.cpp"});
+  SpecializedTemplateMethod.Namespace.emplace_back(EmptySID, "F",
+   InfoType::IT_record);
+  SpecializedTemplateMethod.Access = AccessSpecifier::AS_public;
+  SpecializedTemplateMethod.IsMethod = true;
+  ExpectedTemplatedRecord.ChildFunctions.emplace_back(
+  std::move(SpecializedTemplateMethod));
+  CheckRecordInfo(&ExpectedTemplatedRecord, TemplatedRecord);
+
+  RecordInfo *G = InfoAsRecord(Infos[6].get());
+  RecordInfo ExpectedG(EmptySID, "G");
+  ExpectedG.TagType =

[PATCH] D63678: Fix test Clang :: Driver/cl-response-file.c for Solaris

2019-06-24 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/D63678/new/

https://reviews.llvm.org/D63678



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


[PATCH] D48680: Add missing visibility annotation for __base

2019-06-24 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

@ldionne Does Peter's example answer your questions?


Repository:
  rCXX libc++

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

https://reviews.llvm.org/D48680



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


[PATCH] D60455: [SYCL] Implement SYCL device code outlining

2019-06-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/SemaSYCL/device-attributes.cpp:3
+
+[[clang::sycl_kernel]] int gv2 = 0; // expected-warning {{'sycl_kernel' 
attribute only applies to functions}}
+__attribute((sycl_kernel)) int gv3 = 0; // expected-warning {{'sycl_kernel' 
attribute only applies to functions}}

keryell wrote:
> bader wrote:
> > aaron.ballman wrote:
> > > Fznamznon wrote:
> > > > aaron.ballman wrote:
> > > > > I'd like to see some more tests covering less obvious scenarios. Can 
> > > > > I add this attribute to a lambda? What about a member function? How 
> > > > > does it work with virtual functions? That sort of thing.
> > > > Actually there is no restrictions for adding this attribute to any 
> > > > function to outline device code so I just checked the simplest variant.
> > > > 
> > > > But I'm working on new patch which will put some requirements on 
> > > > function which is marked with `sycl_kernel` attribute. 
> > > > This new patch will add generation of OpenCL kernel from function 
> > > > marked with `sycl_kernel` attribute. The main idea of this approach is 
> > > > described in this [[ 
> > > > https://github.com/intel/llvm/blob/sycl/sycl/doc/SYCL_compiler_and_runtime_design.md#lowering-of-lambda-function-objects-and-named-function-objects
> > > >  | document ]] (in this document generated kernel is called "kernel 
> > > > wrapper").
> > > > And to be able to generate OpenCL kernel using function marked with 
> > > > `sycl_kernel` attribute we put some requirements on this function, for 
> > > > example it must be a template function. You can find these requirements 
> > > > and example of proper function which can be marked with `sycl_kernel` 
> > > > in this [[ https://github.com/intel/llvm/pull/177#discussion_r290451286 
> > > > | comment ]] .
> > > > 
> > > > 
> > > > Actually there is no restrictions for adding this attribute to any 
> > > > function to outline device code so I just checked the simplest variant.
> > > 
> > > So there are no concerns about code like:
> > > ```
> > > struct Base {
> > >   __attribute__((sycl_kernel)) virtual void foo();
> > >   virtual void bar();
> > > };
> > > 
> > > struct Derived : Base {
> > >   void foo() override;
> > >   __attribute__((sycl_kernel)) void bar() override;
> > > };
> > > 
> > > void f(Base *B, Derived *D) {
> > >   // Will all of these "do the right thing"?
> > >   B->foo();
> > >   B->bar();
> > > 
> > >   D->foo();
> > >   D->bar();
> > > }
> > > ```
> > > Actually there is no restrictions for adding this attribute to any 
> > > function to outline device code so I just checked the simplest variant.
> > > But I'm working on new patch which will put some requirements on function 
> > > which is marked with sycl_kernel attribute.
> > 
> > @aaron.ballman, sorry for confusing. The  usage scenarios should have been 
> > articulated more accurately.
> > We have only four uses of this attribute in our implementation:
> > https://github.com/intel/llvm/blob/sycl/sycl/include/CL/sycl/handler.hpp#L538
> >  (lines 538-605).
> > All four uses are applied to member functions of `cl::sycl::handler` class 
> > and all of them have similar prototype (which is mentioned by Mariya in the 
> > previous 
> > [comment](https://github.com/intel/llvm/pull/177#discussion_r290451286):
> > 
> > ```
> > namespace cl { namespace sycl {
> > class handler {
> >   template 
> >   __attribute__((sycl_kernel)) void sycl_kernel_function(KernelType 
> > KernelFuncObj) {
> > KernelFuncObj();
> >   }
> > };
> > }}
> > ```
> > 
> > Here is the list of SYCL device compiler expectations with regard to the 
> > function marked with `sycl_kernel` attribute.
> > - Function template with at least one parameter is expected. The 
> > compiler generates OpenCL kernel and uses first template parameter as 
> > unique name to the generated OpenCL kernel. Host application uses this 
> > unique name to invoke the OpenCL kernel generated for the 
> > `sycl_kernel_function` specialized by this name and KernelType (which might 
> > be a lambda type).
> > - Function must have at least one parameter. First parameter expected 
> > to be a function object type (named or unnamed i.e. lambda). Compiler uses 
> > function object type field to generate OpenCL kernel parameters.
> > 
> > Aaron, I hope it makes more sense now.
> > 
> > We don't plan in any use cases other than in SYCL standard library 
> > implementation mentioned above.
> > If I understand you concerns correctly, you want to be sure that clang 
> > prohibits other uses of this attribute, which are not intended. Right?
> > What is the best way to do this? Add more negative tests cases and make 
> > sure that clang generate error diagnostic messages?
> > 
> > If I understand you concerns correctly, you want to be sure that clang 
> > prohibits other uses of this attribute, which are not intended. Right?
> 
> But since it is an attribute to be used by SYCL run

[PATCH] D62977: [clang-tidy]: Google: new check 'google-upgrade-googletest-case'

2019-06-24 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

Generally this LGTM.
I'll take another pass after the comments are addressed.




Comment at: 
clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp:19
+
+static const llvm::StringRef CheckMessage =
+"Googletest APIs named with 'case' are deprecated; use equivalent APIs "

Could you rename this to better represent what the diagnostic text is saying, 
rather than just being diagnostic text?
I think it'll help readability below.

Why not put this inside the unnamed namespace instead?

Same with the function below.



Comment at: 
clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp:201
+ const MatchFinder::MatchResult &Result) {
+  internal::Matcher IsInsideTemplate =
+  hasAncestor(decl(anyOf(classTemplateDecl(), functionTemplateDecl(;

Instead of walking the tree, can't you ask if the Node is dependent in some way?



Comment at: 
clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp:294
+  } else {
+// This is a match for `TestCase` to `TestSuite` refactoring.
+ReplacementText = "TestSuite";

Maybe add an assertion for this comment?



Comment at: clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.h:23
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/google-upgrade-googletest-case.html
+class UpgradeGoogletestCaseCheck : public ClangTidyCheck {

`https` all the things!



Comment at: 
clang-tools-extra/test/clang-tidy/google-upgrade-googletest-case.cpp:9
+TYPED_TEST_CASE(FooTest, FooTypes);
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: Googletest APIs named with 'case' 
are deprecated; use equivalent APIs named with 'suite'
+// CHECK-FIXES: TYPED_TEST_SUITE(FooTest, FooTypes);

You probably don't have to test for the full message every time. but I don't 
know it matters either way.


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

https://reviews.llvm.org/D62977



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


[PATCH] D62977: [clang-tidy]: Google: new check 'google-upgrade-googletest-case'

2019-06-24 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri requested changes to this revision.
lebedev.ri added a comment.
This revision now requires changes to proceed.

In D62977#1540184 , @lebedev.ri wrote:

> Without seeing the tests - what version checks does this have?
>  It shouldn't fire if the googletest version is the one before that rename.


I don't believe this question was answered.


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

https://reviews.llvm.org/D62977



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


  1   2   >