[PATCH] D83914: [clangd] Plan features for FoldingRanges

2020-07-15 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 278329.
kbobyrev added a comment.

Add some missing ranges.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83914

Files:
  clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticSelectionTests.cpp
@@ -234,6 +234,510 @@
   }
 }
 
+TEST(FoldingRanges, ControlFlow) {
+  const char *Tests[] = {
+  // If.
+  R"cpp(
+int main() {[[
+  bool B = true;
+  int I = 0;
+  char C = 'z';
+
+  if ([[B && I > 42 || ~([[++I]])]]) {[[
+++I;
+  ]]} else {[[
+B = false;
+  ]]}
+
+  if ([[B && ([[!B]]) || !([[([[C == 'a']])]])]]) {[[
+++I;
+  ]]} else if ([[!B]]) {[[
+--I;
+  ]]} else {[[
+C = 'a';
+  ]]}
+]]}
+  )cpp",
+  // While.
+  R"cpp(
+int main() {[[
+  bool B;
+  while ([[B]]) {[[
+B = !B;
+  ]]}
+
+  do {[[
+B = !B;
+  ]]} while ([[B]]);
+]]}
+  )cpp",
+  // For.
+  R"cpp(
+int main() {[[
+  for (int I = 0]];[[I < 42]];[[++I) {[[
+--I;
+  ]]}
+]]}
+  )cpp",
+  // Switch.
+  R"cpp(
+void noop();
+
+int main() {[[
+  int i = 2;
+  switch ([[i]]) {[[
+  case 1:[[ noop();]]
+  case 2:[[ noop(); //[[execution starts at this case label
+  case 3:[[ noop();]]
+  case 4:
+  case 5:[[ noop();
+  break;  //[[execution of subsequent statements is terminated
+  case 6:[[ noop();]]
+  ]]}
+]]}
+  )cpp",
+  };
+  for (const char *Test : Tests) {
+auto T = Annotations(Test);
+auto AST = TestTU::withCode(T.code()).build();
+EXPECT_THAT(gatherFoldingRanges(llvm::cantFail(getFoldingRanges(AST))),
+UnorderedElementsAreArray(T.ranges()))
+<< Test;
+  }
+}
+
+TEST(FoldingRanges, Misc) {
+  const char *Tests[] = {
+  // Statement groups.
+  R"cpp(
+int main() {[[
+  [[int X = 5;
+  int Y = 42;
+  bool B = 15;]]
+  if ([[B]]) {[[ ++X; ]]}
+  unsigned U = 9000;
+]]}
+  )cpp",
+  // Enum.
+  R"cpp(
+enum Color {[[
+  Green = 0,
+  YInMn,
+  Orange,
+]]};
+  )cpp",
+  // Argument lists.
+  R"cpp(
+int foo([[char C, bool B]]) {[[ return static_cast(C); ]]}
+
+foo([['z', true]]);
+
+struct Foo {
+  Foo([[int I, unsigned U, bool B=true]]) {}
+};
+
+Foo F = Foo([[/*[[I=]]*/1, /*[[U=]]*/2, /*[[B=]]false]]);
+F = Foo([[1, 2]]);
+  )cpp",
+  // Namespace.
+  R"cpp(
+namespace ns {[[
+int Variable = 42;
+namespace nested {[[
+int NestedVariable = 50;
+]]}
+]]}
+
+namespace a {[[
+namespace b {[[
+namespace c {[[
+
+]]} //[[ namespacee c]]
+]]} //[[ namespacee b]]
+]]} //[[ namespacee a]]
+
+namespace modern::ns::syntax {[[
+]]} //[[ namespace modern::ns::syntax]]
+
+namespace {[[
+]]} //[[ namespace]]
+  )cpp",
+  // Strings.
+  R"cpp(
+std::string String = "[[ShortString]]";
+String = "[[Super Long String]]";
+String = u8"[[Super Long String]]";
+
+String = R"raw([[Super Looong String]])raw";
+
+const char *text =
+  "[[This"
+  "is a multiline"
+  "string]]";
+
+const char *text2 =
+  "[[Here is another \
+string \
+also \
+multilinee]]";
+  )cpp",
+  // Arrays.
+  R"cpp(
+char Array[] = {[[ 'F', 'o', 'o', 'b', 'a', 'r', '\0' ]};
+
+Array = {[[ 'F', 'o', 'o', 'b', 'a', 'r', 'F', 'o', 'o', 'b',
+ 'a', 'r', '\0' ]]};
+
+int Nested[3][4] = {[[{[[0,1,2,3]]}, {[[4,5,6,7]]}, {[[8,9,10,11]]}};
+  )cpp",
+  // Templates.
+  R"cpp(
+template <[[typename T, typename U, typename V, int X, char C, bool B]]>
+class Foo {};
+
+template <[[bool B]]>
+class Foo<[[unsigned, unsigned, unsigned, -42, 'z', B]]> {
+  int Specialization;
+};
+
+template <>
+class Foo<[[unsigned, unsigned, unsigned, -42, 'z', false]]> {
+  int Specialization;
+};
+
+Foo<[[char, int, bool, 42, 'x', false]]> F;
+
+   

[PATCH] D83360: [InstSimplify] Remove select ?, undef, X -> X and select ?, X, undef -> X

2020-07-15 Thread Eric Christopher via Phabricator via cfe-commits
echristo added a comment.

This seems like something that we should then revert until we know that 
instsimplify can be updated with a fix?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83360



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


[PATCH] D83360: [InstSimplify] Remove select ?, undef, X -> X and select ?, X, undef -> X

2020-07-15 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D83360#2154540 , @echristo wrote:

> This seems like something that we should then revert until we know that 
> instsimplify can be updated with a fix?


Possibility for a miscompile sounds much worse to me than a false-positive 
diag..


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83360



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


[PATCH] D83360: [InstSimplify] Remove select ?, undef, X -> X and select ?, X, undef -> X

2020-07-15 Thread Eric Christopher via Phabricator via cfe-commits
echristo added a comment.

We're starting to see miscompiles as we do more testing as well, just nothing 
smaller at the moment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83360



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


[PATCH] D83360: [InstSimplify] Remove select ?, undef, X -> X and select ?, X, undef -> X

2020-07-15 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D83360#2154545 , @echristo wrote:

> We're starting to see miscompiles as we do more testing as well, just nothing 
> smaller at the moment.


Could you clarify, do you mean that this fix is causing (new) miscompiles?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83360



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


[PATCH] D83893: [CUDA][HIP] Always defer diagnostics for wrong-sided reference

2020-07-15 Thread Justin Lebar via Phabricator via cfe-commits
jlebar added a comment.

tra and I talked offline and I...think this makes sense.


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

https://reviews.llvm.org/D83893



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


[PATCH] D83360: [InstSimplify] Remove select ?, undef, X -> X and select ?, X, undef -> X

2020-07-15 Thread Eric Christopher via Phabricator via cfe-commits
echristo added a comment.

It's that even before the msan instrumentation the IR doesn't look correct - 
thus a miscompile.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83360



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


[PATCH] D83494: [libFuzzer] Link libFuzzer's own interceptors when other compiler runtimes are not linked.

2020-07-15 Thread Dokyung Song via Phabricator via cfe-commits
dokyungs updated this revision to Diff 278341.
dokyungs added a comment.

Ensure the fuzzer RT module is initialized at the beginning of the interceptors.

Interceptors can be called before __fuzzer_init is called. So I added a check 
at the beginning of the interceptors, which ensures that __fuzzer_init has been 
called before proceeding.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83494

Files:
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  compiler-rt/lib/fuzzer/CMakeLists.txt
  compiler-rt/lib/fuzzer/FuzzerInterceptors.cpp
  compiler-rt/test/fuzzer/memcmp.test
  compiler-rt/test/fuzzer/memcmp64.test
  compiler-rt/test/fuzzer/strcmp.test
  compiler-rt/test/fuzzer/strncmp.test
  compiler-rt/test/fuzzer/strstr.test

Index: compiler-rt/test/fuzzer/strstr.test
===
--- compiler-rt/test/fuzzer/strstr.test
+++ compiler-rt/test/fuzzer/strstr.test
@@ -1,5 +1,8 @@
 UNSUPPORTED: freebsd
 RUN: %cpp_compiler %S/StrstrTest.cpp -o %t-StrstrTest
 RUN: not %run %t-StrstrTest   -seed=1 -runs=200   2>&1 | FileCheck %s
-CHECK: BINGO
 
+RUN: %cpp_compiler -fno-sanitize=address -fno-builtin-strstr %S/StrstrTest.cpp -o %t-NoAsanStrstrTest
+RUN: not %run %t-StrstrTest   -seed=1 -runs=200   2>&1 | FileCheck %s
+
+CHECK: BINGO
Index: compiler-rt/test/fuzzer/strncmp.test
===
--- compiler-rt/test/fuzzer/strncmp.test
+++ compiler-rt/test/fuzzer/strncmp.test
@@ -1,5 +1,8 @@
 UNSUPPORTED: freebsd
 RUN: %cpp_compiler %S/StrncmpTest.cpp -o %t-StrncmpTest
 RUN: not %run %t-StrncmpTest  -seed=2 -runs=1000   2>&1 | FileCheck %s
-CHECK: BINGO
 
+RUN: %cpp_compiler -fno-sanitize=address -fno-builtin-strncmp %S/StrncmpTest.cpp -o %t-NoAsanStrncmpTest
+RUN: not %run %t-StrncmpTest  -seed=2 -runs=1000   2>&1 | FileCheck %s
+
+CHECK: BINGO
Index: compiler-rt/test/fuzzer/strcmp.test
===
--- compiler-rt/test/fuzzer/strcmp.test
+++ compiler-rt/test/fuzzer/strcmp.test
@@ -1,5 +1,8 @@
 UNSUPPORTED: freebsd
 RUN: %cpp_compiler %S/StrcmpTest.cpp -o %t-StrcmpTest
 RUN: not %run %t-StrcmpTest   -seed=1 -runs=200   2>&1 | FileCheck %s
-CHECK: BINGO
 
+RUN: %cpp_compiler -fno-sanitize=address -fno-builtin-strcmp %S/StrcmpTest.cpp -o %t-NoAsanStrcmpTest
+RUN: not %run %t-StrcmpTest   -seed=1 -runs=200   2>&1 | FileCheck %s
+
+CHECK: BINGO
Index: compiler-rt/test/fuzzer/memcmp64.test
===
--- compiler-rt/test/fuzzer/memcmp64.test
+++ compiler-rt/test/fuzzer/memcmp64.test
@@ -1,4 +1,8 @@
 UNSUPPORTED: freebsd
 RUN: %cpp_compiler %S/Memcmp64BytesTest.cpp -o %t-Memcmp64BytesTest
 RUN: not %run %t-Memcmp64BytesTest-seed=1 -runs=100   2>&1 | FileCheck %s
+
+RUN: %cpp_compiler -fno-sanitize=address -fno-builtin-memcmp %S/Memcmp64BytesTest.cpp -o %t-NoAsanMemcmp64BytesTest
+RUN: not %run %t-Memcmp64BytesTest-seed=1 -runs=100   2>&1 | FileCheck %s
+
 CHECK: BINGO
Index: compiler-rt/test/fuzzer/memcmp.test
===
--- compiler-rt/test/fuzzer/memcmp.test
+++ compiler-rt/test/fuzzer/memcmp.test
@@ -1,4 +1,8 @@
 UNSUPPORTED: freebsd
 RUN: %cpp_compiler %S/MemcmpTest.cpp -o %t-MemcmpTest
 RUN: not %run %t-MemcmpTest   -seed=1 -runs=1000   2>&1 | FileCheck %s
+
+RUN: %cpp_compiler -fno-sanitize=address -fno-builtin-memcmp %S/MemcmpTest.cpp -o %t-NoAsanMemcmpTest
+RUN: not %run %t-MemcmpTest   -seed=1 -runs=1000   2>&1 | FileCheck %s
+
 CHECK: BINGO
Index: compiler-rt/lib/fuzzer/FuzzerInterceptors.cpp
===
--- /dev/null
+++ compiler-rt/lib/fuzzer/FuzzerInterceptors.cpp
@@ -0,0 +1,171 @@
+//===-- FuzzerInterceptors.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
+//
+//===--===//
+// Intercept certain libc functions to aid fuzzing.
+// Linked only when other RTs that define their own interceptors are not linked.
+//===--===//
+
+#include "FuzzerPlatform.h"
+#include 
+#include 
+#include 
+
+#define GET_CALLER_PC() __builtin_return_address(0)
+
+#if LIBFUZZER_LINUX
+
+#define PTR_TO_REAL(x) real_##x
+#define REAL(x) __interception::PTR_TO_REAL(x)
+#define FUNC_TYPE(x) x##_type
+#define DEFINE_REAL(ret_type, func, ...) 

[PATCH] D83360: [InstSimplify] Remove select ?, undef, X -> X and select ?, X, undef -> X

2020-07-15 Thread Juneyoung Lee via Phabricator via cfe-commits
aqjune added a comment.

In D83360#2154584 , @echristo wrote:

> It's that even before the msan instrumentation the IR doesn't look correct - 
> thus a miscompile.


I'll share a prototype of the InstSimplify patch on Phabricator, in a day or 
two; it would be great if the miscompilation is fixed with the patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83360



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


[PATCH] D67833: [OpenMP 5.0] Codegen support to pass user-defined mapper functions to runtime

2020-07-15 Thread Lingda Li via Phabricator via cfe-commits
lildmh updated this revision to Diff 278344.
lildmh added a comment.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Include the llvm part


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

https://reviews.llvm.org/D67833

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/capturing_in_templates.cpp
  clang/test/OpenMP/declare_mapper_codegen.cpp
  clang/test/OpenMP/declare_target_link_codegen.cpp
  clang/test/OpenMP/distribute_codegen.cpp
  clang/test/OpenMP/distribute_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_if_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_num_threads_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_private_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_proc_bind_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_reduction_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_if_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_num_threads_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_private_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_proc_bind_codegen.cpp
  clang/test/OpenMP/distribute_private_codegen.cpp
  clang/test/OpenMP/distribute_simd_codegen.cpp
  clang/test/OpenMP/distribute_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_simd_private_codegen.cpp
  clang/test/OpenMP/distribute_simd_reduction_codegen.cpp
  clang/test/OpenMP/nvptx_lambda_capturing.cpp
  clang/test/OpenMP/nvptx_lambda_pointer_capturing.cpp
  clang/test/OpenMP/nvptx_target_requires_unified_shared_memory.cpp
  clang/test/OpenMP/openmp_offload_codegen.cpp
  clang/test/OpenMP/target_codegen.cpp
  clang/test/OpenMP/target_data_codegen.cpp
  clang/test/OpenMP/target_data_use_device_addr_codegen.cpp
  clang/test/OpenMP/target_defaultmap_codegen.cpp
  clang/test/OpenMP/target_depend_codegen.cpp
  clang/test/OpenMP/target_device_codegen.cpp
  clang/test/OpenMP/target_enter_data_codegen.cpp
  clang/test/OpenMP/target_enter_data_depend_codegen.cpp
  clang/test/OpenMP/target_exit_data_codegen.cpp
  clang/test/OpenMP/target_exit_data_depend_codegen.cpp
  clang/test/OpenMP/target_firstprivate_codegen.cpp
  clang/test/OpenMP/target_is_device_ptr_codegen.cpp
  clang/test/OpenMP/target_map_codegen.cpp
  clang/test/OpenMP/target_map_member_expr_array_section_codegen.cpp
  clang/test/OpenMP/target_parallel_codegen.cpp
  clang/test/OpenMP/target_parallel_depend_codegen.cpp
  clang/test/OpenMP/target_parallel_for_codegen.cpp
  clang/test/OpenMP/target_parallel_for_depend_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_depend_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_parallel_for_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_parallel_if_codegen.cpp
  clang/test/OpenMP/target_parallel_num_threads_codegen.cpp
  clang/test/OpenMP/target_parallel_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_simd_codegen.cpp
  clang/test/OpenMP/target_simd_depend_codegen.cpp
  clang/test/OpenMP/target_simd_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_teams_codegen.cpp
  clang/test/OpenMP/target_teams_depend_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_collapse_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_depend_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_dist_schedule_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_firstprivate_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_lastprivate_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_collapse_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_depend_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_dist_schedule_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_firstprivate_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_if_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_lastprivate_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_order_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for

[PATCH] D67833: [OpenMP 5.0] Codegen support to pass user-defined mapper functions to runtime

2020-07-15 Thread Lingda Li via Phabricator via cfe-commits
lildmh added a comment.

In D67833#2154312 , @grokos wrote:

> I tried to build clang with this patch and I get errors like:
>
>   CGOpenMPRuntime.cpp:9463:38: error: 
> ‘OMPRTL___tgt_target_teams_nowait_mapper’ was not declared in this scope
>   ? 
> OMPRTL___tgt_target_teams_nowait_mapper
>
>
> Where are these `OMPRTL___tgt_` symbols defined?


Sorry I forgot to include the llvm part. Please try again


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

https://reviews.llvm.org/D67833



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


[PATCH] D83922: [OpenMP] Fix map clause for unused var: don't ignore it

2020-07-15 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added reviewers: ABataev, jdoerfert, hfinkel, Meinersbur, kkwli0, 
grokos, sfantao, gtbercea, Hahnfeld.
Herald added subscribers: cfe-commits, sstefan1, guansong, yaxunl.
Herald added a project: clang.

For example, without this patch:

  $ cat test.c
  int main() {
int x[3];
#pragma omp target map(tofrom:x[0:3])
  #ifdef USE 
x[0] = 1 
  #endif
;   
return 0;
  }
  $ clang -fopenmp -fopenmp-targets=nvptx64-nvida-cuda -S -emit-llvm test.c
  $ grep '^@.offload_maptypes' test.ll
  $ echo $?
  1
  $ clang -fopenmp -fopenmp-targets=nvptx64-nvida-cuda -S -emit-llvm test.c \
  -DUSE
  $ grep '^@.offload_maptypes' test.ll
  @.offload_maptypes = private unnamed_addr constant [1 x i64] [i64 35] 

With this patch, both greps produce the same result.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83922

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_map_codegen.cpp
  clang/test/OpenMP/target_teams_map_codegen.cpp

Index: clang/test/OpenMP/target_teams_map_codegen.cpp
===
--- clang/test/OpenMP/target_teams_map_codegen.cpp
+++ clang/test/OpenMP/target_teams_map_codegen.cpp
@@ -20,15 +20,16 @@
 #ifndef HEADER
 #define HEADER
 
+// HOST: @[[MAPTYPES_PRIVATE:.offload_maptypes[0-9.]*]] = private {{.*}}constant [2 x i64] [i64 35, i64 35]
 // HOST: @[[MAPTYPES_FIRSTPRIVATE:.offload_maptypes[0-9.]*]] = private {{.*}}constant [2 x i64] [i64 35, i64 35]
 // HOST: @[[MAPTYPES_REDUCTION:.offload_maptypes[0-9.]*]] = private {{.*}}constant [2 x i64] [i64 35, i64 35]
 // HOST: @[[MAPTYPES_FROM:.offload_maptypes[0-9.]*]] = private {{.*}}constant [1 x i64] [i64 34]
 // HOST: @[[MAPTYPES_TO:.offload_maptypes[0-9.]*]] = private {{.*}}constant [1 x i64] [i64 33]
 // HOST: @[[MAPTYPES_ALLOC:.offload_maptypes[0-9.]*]] = private {{.*}}constant [1 x i64] [i64 32]
-// HOST: @[[MAPTYPES_ARRAY_R0:.offload_maptypes[0-9.]*]] = private {{.*}}constant [2 x i64] [i64 35, i64 35]
-// HOST: @[[MAPTYPES_ARRAY_R1:.offload_maptypes[0-9.]*]] = private {{.*}}constant [2 x i64] [i64 33, i64 33]
-// HOST-INT128: @[[MAPTYPES_INT128_R0:.offload_maptypes[0-9.]*]] = private {{.*}}constant [2 x i64] [i64 35, i64 35]
-// HOST-INT128: @[[MAPTYPES_INT128_R1:.offload_maptypes[0-9.]*]] = private {{.*}}constant [2 x i64] [i64 34, i64 34]
+// HOST: @[[MAPTYPES_ARRAY_R0:.offload_maptypes[0-9.]*]] = private {{.*}}constant [3 x i64] [i64 35, i64 35, i64 35]
+// HOST: @[[MAPTYPES_ARRAY_R1:.offload_maptypes[0-9.]*]] = private {{.*}}constant [3 x i64] [i64 33, i64 33, i64 33]
+// HOST-INT128: @[[MAPTYPES_INT128_R0:.offload_maptypes[0-9.]*]] = private {{.*}}constant [3 x i64] [i64 35, i64 35, i64 35]
+// HOST-INT128: @[[MAPTYPES_INT128_R1:.offload_maptypes[0-9.]*]] = private {{.*}}constant [3 x i64] [i64 34, i64 34, i64 34]
 //
 // CHECK: @.omp_offloading.entry_name{{[0-9.]*}} = {{.*}} c"[[OFFLOAD_PRIVATE:__omp_offloading_[^"\\]*mapWithPrivate[^"\\]*]]\00"
 // CHECK: @.omp_offloading.entry_name{{[0-9.]*}} = {{.*}} c"[[OFFLOAD_FIRSTPRIVATE:__omp_offloading_[^"\\]*mapWithFirstprivate[^"\\]*]]\00"
@@ -42,9 +43,7 @@
 // INT128: @.omp_offloading.entry_name{{[0-9.]*}} = {{.*}} c"[[OFFLOAD_INT128_R1:__omp_offloading_[^"\\]*mapInt128[^"\\]*]]\00"
 
 // HOST: define {{.*}}mapWithPrivate
-// HOST: call {{.*}} @.[[OFFLOAD_PRIVATE]].region_id
-// HOST-NOT: offload_maptypes
-// HOST-SAME: {{$}}
+// HOST: call {{.*}} @.[[OFFLOAD_PRIVATE]].region_id{{.*}} @[[MAPTYPES_PRIVATE]]
 //
 // CHECK: define {{.*}} void @[[OFFLOAD_PRIVATE]]()
 // CHECK: call void ({{.*}}@[[OUTLINE_PRIVATE:.omp_outlined.[.0-9]*]]
Index: clang/test/OpenMP/target_map_codegen.cpp
===
--- clang/test/OpenMP/target_map_codegen.cpp
+++ clang/test/OpenMP/target_map_codegen.cpp
@@ -1307,12 +1307,26 @@
 
 #endif
 ///==///
-// RUN: %clang_cc1 -DCK19 -verify -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  %s --check-prefix CK19 --check-prefix CK19-64
+// RUN: %clang_cc1 -DUSE -DCK19 -verify -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  %s --check-prefixes=CK19,CK19-64,CK19-USE
+// RUN: %clang_cc1 -DUSE -DCK19 -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -DUSE -fopenmp -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck -allow-deprecated-dag-overlap  %s  --check-prefixes=CK19,CK19-64,CK19-USE
+// RUN: %clang_cc1 -DUSE -DCK19 -verify -fopenmp -fopenmp-targets=i386-pc-linux-gnu -x c++ -triple i386-unknown-unknown -e

[PATCH] D83061: [OpenMP] Implement TR8 `present` map type modifier in Clang (1/2)

2020-07-15 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 278343.
jdenny edited the summary of this revision.
jdenny set the repository for this revision to rG LLVM Github Monorepo.
jdenny added a comment.

Rebased, and extracted D83922  as discussed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83061

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/OpenMPKinds.def
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/target_ast_print.cpp
  clang/test/OpenMP/target_data_ast_print.cpp
  clang/test/OpenMP/target_data_codegen.cpp
  clang/test/OpenMP/target_defaultmap_codegen.cpp
  clang/test/OpenMP/target_enter_data_codegen.cpp
  clang/test/OpenMP/target_map_codegen.cpp
  clang/test/OpenMP/target_map_messages.cpp
  clang/test/OpenMP/target_parallel_for_map_messages.cpp
  clang/test/OpenMP/target_parallel_for_simd_map_messages.cpp
  clang/test/OpenMP/target_parallel_map_messages.cpp
  clang/test/OpenMP/target_simd_map_messages.cpp
  clang/test/OpenMP/target_teams_distribute_map_messages.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_map_messages.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_simd_map_messages.cpp
  clang/test/OpenMP/target_teams_distribute_simd_map_messages.cpp
  clang/test/OpenMP/target_teams_map_messages.cpp

Index: clang/test/OpenMP/target_teams_map_messages.cpp
===
--- clang/test/OpenMP/target_teams_map_messages.cpp
+++ clang/test/OpenMP/target_teams_map_messages.cpp
@@ -468,7 +468,7 @@
 
 #pragma omp target data map(always, tofrom: x)
 #pragma omp target data map(always: x) // expected-error {{missing map type}}
-#pragma omp target data map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always', 'close', or 'mapper'}} expected-error {{missing map type}}
+#pragma omp target data map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always', 'close', 'mapper', or 'present'}} expected-error {{missing map type}}
 #pragma omp target data map(always, tofrom: always, tofrom, x)
 #pragma omp target teams map(tofrom j) // expected-error {{expected ',' or ')' in 'map' clause}}
   foo();
@@ -543,7 +543,7 @@
 
 #pragma omp target data map(always, tofrom: x)
 #pragma omp target data map(always: x) // expected-error {{missing map type}}
-#pragma omp target data map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always', 'close', or 'mapper'}} expected-error {{missing map type}}
+#pragma omp target data map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always', 'close', 'mapper', or 'present'}} expected-error {{missing map type}}
 #pragma omp target data map(always, tofrom: always, tofrom, x)
 #pragma omp target teams map(tofrom j) // expected-error {{expected ',' or ')' in 'map' clause}}
   foo();
Index: clang/test/OpenMP/target_teams_distribute_simd_map_messages.cpp
===
--- clang/test/OpenMP/target_teams_distribute_simd_map_messages.cpp
+++ clang/test/OpenMP/target_teams_distribute_simd_map_messages.cpp
@@ -175,7 +175,7 @@
   for (i = 0; i < argc; ++i) foo();
 #pragma omp target teams distribute simd map(always: x) // expected-error {{missing map type}}
   for (i = 0; i < argc; ++i) foo();
-#pragma omp target teams distribute simd map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always', 'close', or 'mapper'}} expected-error {{missing map type}}
+#pragma omp target teams distribute simd map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always', 'close', 'mapper', or 'present'}} expected-error {{missing map type}}
   for (i = 0; i < argc; ++i) foo();
 #pragma omp target teams distribute simd map(always, tofrom: always, tofrom, x)
   for (i = 0; i < argc; ++i) foo();
@@ -287,7 +287,7 @@
   for (i = 0; i < argc; ++i) foo();
 #pragma omp target teams distribute simd map(always: x) // expected-error {{missing map type}}
   for (i = 0; i < argc; ++i) foo();
-#pragma omp target teams distribute simd map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always', 'close', or 'mapper'}} expected-error {{missing map type}}
+#pragma omp target teams distribute simd map(tofrom, always: x) // expected-error {{incorrect map type modifier, expected 'always', 'close', 'mapper', or 'present'}} expected-error {{missing map type}}
   for (i = 0; i < argc; ++i) foo();
 #pragma omp target teams distribute simd map(always, tofrom: always, tofrom, x)
   for (i = 0; i < argc; ++i) foo();
Index: clang/test/OpenMP/target_teams_distribute_parallel_for_simd_map_messages.cpp
=

[PATCH] D83360: [InstSimplify] Remove select ?, undef, X -> X and select ?, X, undef -> X

2020-07-15 Thread Eric Christopher via Phabricator via cfe-commits
echristo added a comment.

In D83360#2154637 , @aqjune wrote:

> In D83360#2154584 , @echristo wrote:
>
> > It's that even before the msan instrumentation the IR doesn't look correct 
> > - thus a miscompile.
>
>
> I'll share a prototype of the InstSimplify patch on Phabricator, in a day or 
> two; it would be great if the miscompilation is fixed with the patch.


Would it be reasonable to revert this in the meantime?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83360



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


[PATCH] D67833: [OpenMP 5.0] Codegen support to pass user-defined mapper functions to runtime

2020-07-15 Thread George Rokos via Phabricator via cfe-commits
grokos added a comment.

OK, now it works. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67833



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


[PATCH] D67833: [OpenMP 5.0] Codegen support to pass user-defined mapper functions to runtime

2020-07-15 Thread George Rokos via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG537b16e9b8da: [OpenMP 5.0] Codegen support to pass 
user-defined mapper functions to runtime (authored by grokos).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67833

Files:
  clang/include/clang/AST/OpenMPClause.h
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/OpenMP/capturing_in_templates.cpp
  clang/test/OpenMP/declare_mapper_codegen.cpp
  clang/test/OpenMP/declare_target_link_codegen.cpp
  clang/test/OpenMP/distribute_codegen.cpp
  clang/test/OpenMP/distribute_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_if_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_num_threads_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_private_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_proc_bind_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_reduction_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_if_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_num_threads_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_private_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_proc_bind_codegen.cpp
  clang/test/OpenMP/distribute_private_codegen.cpp
  clang/test/OpenMP/distribute_simd_codegen.cpp
  clang/test/OpenMP/distribute_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_simd_private_codegen.cpp
  clang/test/OpenMP/distribute_simd_reduction_codegen.cpp
  clang/test/OpenMP/nvptx_lambda_capturing.cpp
  clang/test/OpenMP/nvptx_lambda_pointer_capturing.cpp
  clang/test/OpenMP/nvptx_target_requires_unified_shared_memory.cpp
  clang/test/OpenMP/openmp_offload_codegen.cpp
  clang/test/OpenMP/target_codegen.cpp
  clang/test/OpenMP/target_data_codegen.cpp
  clang/test/OpenMP/target_data_use_device_addr_codegen.cpp
  clang/test/OpenMP/target_defaultmap_codegen.cpp
  clang/test/OpenMP/target_depend_codegen.cpp
  clang/test/OpenMP/target_device_codegen.cpp
  clang/test/OpenMP/target_enter_data_codegen.cpp
  clang/test/OpenMP/target_enter_data_depend_codegen.cpp
  clang/test/OpenMP/target_exit_data_codegen.cpp
  clang/test/OpenMP/target_exit_data_depend_codegen.cpp
  clang/test/OpenMP/target_firstprivate_codegen.cpp
  clang/test/OpenMP/target_is_device_ptr_codegen.cpp
  clang/test/OpenMP/target_map_codegen.cpp
  clang/test/OpenMP/target_map_member_expr_array_section_codegen.cpp
  clang/test/OpenMP/target_parallel_codegen.cpp
  clang/test/OpenMP/target_parallel_depend_codegen.cpp
  clang/test/OpenMP/target_parallel_for_codegen.cpp
  clang/test/OpenMP/target_parallel_for_depend_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_depend_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_parallel_for_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_parallel_if_codegen.cpp
  clang/test/OpenMP/target_parallel_num_threads_codegen.cpp
  clang/test/OpenMP/target_parallel_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_simd_codegen.cpp
  clang/test/OpenMP/target_simd_depend_codegen.cpp
  clang/test/OpenMP/target_simd_uses_allocators_codegen.cpp
  clang/test/OpenMP/target_teams_codegen.cpp
  clang/test/OpenMP/target_teams_depend_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_collapse_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_depend_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_dist_schedule_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_firstprivate_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_lastprivate_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_collapse_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_depend_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_dist_schedule_codegen.cpp
  
clang/test/OpenMP/target_teams_distribute_parallel_for_firstprivate_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_if_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_lastprivate_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_para

[libunwind] fd802cc - [libunwind] Fix getSLEB128 on large values

2020-07-15 Thread Ryan Prichard via cfe-commits

Author: Ryan Prichard
Date: 2020-07-15T19:12:56-07:00
New Revision: fd802cc4dea4ed1a233ff725f98c686dc2836bf3

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

LOG: [libunwind] Fix getSLEB128 on large values

Previously, for large-enough values, getSLEB128 would attempt to shift
a signed int in the range [0..0x7f] by 28, 35, 42... bits, which is
undefined behavior and likely to fail.

Avoid shifting (-1ULL) by 70 for large values. e.g. For INT64_MAX, the
last two bytes will be:
 - 0x7f [bit==56]
 - 0x00 [bit==63]

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

Added: 


Modified: 
libunwind/src/AddressSpace.hpp

Removed: 




diff  --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp
index a4564cb67328..764aaa3489f2 100644
--- a/libunwind/src/AddressSpace.hpp
+++ b/libunwind/src/AddressSpace.hpp
@@ -290,11 +290,11 @@ inline int64_t LocalAddressSpace::getSLEB128(pint_t 
&addr, pint_t end) {
 if (p == pend)
   _LIBUNWIND_ABORT("truncated sleb128 expression");
 byte = *p++;
-result |= ((byte & 0x7f) << bit);
+result |= (uint64_t)(byte & 0x7f) << bit;
 bit += 7;
   } while (byte & 0x80);
   // sign extend negative numbers
-  if ((byte & 0x40) != 0)
+  if ((byte & 0x40) != 0 && bit < 64)
 result |= (-1ULL) << bit;
   addr = (pint_t) p;
   return result;



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


[libunwind] 52d0a78 - [libunwind] Fix CIE v1 return address parsing

2020-07-15 Thread Ryan Prichard via cfe-commits

Author: Ryan Prichard
Date: 2020-07-15T19:12:55-07:00
New Revision: 52d0a78b831584c46eda78b7cf349ab93ce13df0

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

LOG: [libunwind] Fix CIE v1 return address parsing

 - For CIE version 1 (e.g. in DWARF 2.0.0), the return_address_register
   field is a ubyte [0..255].

 - For CIE version 3 (e.g. in DWARF 3), the field is instead a ULEB128
   constant.

Previously, libunwind accepted a CIE version of 1 or 3, but always
parsed the field as ULEB128.

Clang always outputs CIE version 1 into .eh_frame. (It can output CIE
version 3 or 4, but only into .debug_frame.)

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

Added: 


Modified: 
libunwind/src/DwarfParser.hpp

Removed: 




diff  --git a/libunwind/src/DwarfParser.hpp b/libunwind/src/DwarfParser.hpp
index d05ac468367f..c98c4f92a6ad 100644
--- a/libunwind/src/DwarfParser.hpp
+++ b/libunwind/src/DwarfParser.hpp
@@ -336,7 +336,8 @@ const char *CFI_Parser::parseCIE(A &addressSpace, pint_t 
cie,
   // parse data alignment factor
   cieInfo->dataAlignFactor = (int)addressSpace.getSLEB128(p, cieContentEnd);
   // parse return address register
-  uint64_t raReg = addressSpace.getULEB128(p, cieContentEnd);
+  uint64_t raReg = (version == 1) ? addressSpace.get8(p++)
+  : addressSpace.getULEB128(p, cieContentEnd);
   assert(raReg < 255 && "return address register too large");
   cieInfo->returnAddressRegister = (uint8_t)raReg;
   // parse augmentation data based on augmentation string



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


[PATCH] D83648: [Driver] Fix integrated_as definition by setting it as a DriverOption

2020-07-15 Thread Pengxuan Zheng via Phabricator via cfe-commits
pzheng marked 2 inline comments as done.
pzheng added a comment.

In D83648#2146606 , @MaskRay wrote:

> Created http://lists.llvm.org/pipermail/cfe-dev/2020-July/066245.html 
> [cfe-dev] Usage of clang::driver::options::DriverOption (-Xarch_ & gcc 
> toolchain)
>  to ask about the use case.
>
> When I get time, I'll work on a patch fixing the whole class of options 
> instead of just -fintegrated-as. I will use `OPT_Link_Group` and add some 
> extra options in the new group:  `GCCLinkOption`.


Sounds like I should remove the test from this patch since you will fix a class 
of options later?




Comment at: clang/test/Driver/integrated-as.c:10
 
+// RUN: %clang -### -fintegrated-as %s 2>&1 | FileCheck %s -check-prefix 
FIAS-LINK
+

MaskRay wrote:
> MaskRay wrote:
> > This test is incorrect. You need a specific target triple to select 
> > bare-metal like GCC driver.
> There are so many clang specific options. I think we just need a centralized 
> test file to test options in patch, instead of adding random `-NOT` check 
> lines to random files.
Thanks for pointing this out. Will update the triple.



Comment at: clang/test/Driver/integrated-as.c:10
 
+// RUN: %clang -### -fintegrated-as %s 2>&1 | FileCheck %s -check-prefix 
FIAS-LINK
+

pzheng wrote:
> MaskRay wrote:
> > MaskRay wrote:
> > > This test is incorrect. You need a specific target triple to select 
> > > bare-metal like GCC driver.
> > There are so many clang specific options. I think we just need a 
> > centralized test file to test options in patch, instead of adding random 
> > `-NOT` check lines to random files.
> Thanks for pointing this out. Will update the triple.
Can you suggest a file to add the test?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83648



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


[PATCH] D83648: [Driver] Fix integrated_as definition by setting it as a DriverOption

2020-07-15 Thread Pengxuan Zheng via Phabricator via cfe-commits
pzheng updated this revision to Diff 278361.
pzheng added a comment.

Add target triple used in test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83648

Files:
  clang/include/clang/Driver/Options.td
  clang/test/Driver/integrated-as.c


Index: clang/test/Driver/integrated-as.c
===
--- clang/test/Driver/integrated-as.c
+++ clang/test/Driver/integrated-as.c
@@ -1,3 +1,4 @@
+// REQUIRES: x86-registered-target
 // RUN: %clang -### -c -save-temps -integrated-as %s 2>&1 | FileCheck %s
 
 // CHECK: cc1as
@@ -7,6 +8,10 @@
 
 // FIAS: cc1as
 
+// RUN: %clang -target x86_64 -### -fintegrated-as %s 2>&1 | FileCheck %s 
-check-prefix FIAS-LINK
+
+// FIAS-LINK-NOT: -fintegrated-as
+
 // RUN: %clang -target none -### -fno-integrated-as -S %s 2>&1 \
 // RUN: | FileCheck %s -check-prefix NOFIAS
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2887,7 +2887,7 @@
   MetaVarName<"">;
 def y : Joined<["-"], "y">;
 
-defm integrated_as : OptOutFFlag<"integrated-as", "Enable the integrated 
assembler", "Disable the integrated assembler">;
+defm integrated_as : OptOutFFlag<"integrated-as", "Enable", "Disable", " the 
integrated assembler", [DriverOption]>;
 
 def fintegrated_cc1 : Flag<["-"], "fintegrated-cc1">,
   Flags<[CoreOption, DriverOption]>, Group,


Index: clang/test/Driver/integrated-as.c
===
--- clang/test/Driver/integrated-as.c
+++ clang/test/Driver/integrated-as.c
@@ -1,3 +1,4 @@
+// REQUIRES: x86-registered-target
 // RUN: %clang -### -c -save-temps -integrated-as %s 2>&1 | FileCheck %s
 
 // CHECK: cc1as
@@ -7,6 +8,10 @@
 
 // FIAS: cc1as
 
+// RUN: %clang -target x86_64 -### -fintegrated-as %s 2>&1 | FileCheck %s -check-prefix FIAS-LINK
+
+// FIAS-LINK-NOT: -fintegrated-as
+
 // RUN: %clang -target none -### -fno-integrated-as -S %s 2>&1 \
 // RUN: | FileCheck %s -check-prefix NOFIAS
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2887,7 +2887,7 @@
   MetaVarName<"">;
 def y : Joined<["-"], "y">;
 
-defm integrated_as : OptOutFFlag<"integrated-as", "Enable the integrated assembler", "Disable the integrated assembler">;
+defm integrated_as : OptOutFFlag<"integrated-as", "Enable", "Disable", " the integrated assembler", [DriverOption]>;
 
 def fintegrated_cc1 : Flag<["-"], "fintegrated-cc1">,
   Flags<[CoreOption, DriverOption]>, Group,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D70411: [analyzer] CERT STR rule checkers: STR31-C

2020-07-15 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 278368.
Charusso marked 18 inline comments as done.
Charusso edited the summary of this revision.
Charusso added a comment.

- Resolve most of the review comments.
- We really need to specify the design of future checkers.


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

https://reviews.llvm.org/D70411

Files:
  clang/docs/analyzer/checkers.rst
  clang/include/clang/AST/FormatStringParsing.h
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/AST/FormatString.cpp
  clang/lib/AST/FormatStringParsing.h
  clang/lib/AST/PrintfFormatString.cpp
  clang/lib/AST/ScanfFormatString.cpp
  clang/lib/StaticAnalyzer/Checkers/AllocationState.h
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  clang/lib/StaticAnalyzer/Checkers/cert/StrChecker.cpp
  clang/test/Analysis/Inputs/system-header-simulator.h
  clang/test/Analysis/cert/str31-c-extras.cpp
  clang/test/Analysis/cert/str31-c-notes.cpp
  clang/test/Analysis/cert/str31-c.cpp

Index: clang/test/Analysis/cert/str31-c.cpp
===
--- /dev/null
+++ clang/test/Analysis/cert/str31-c.cpp
@@ -0,0 +1,184 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,unix,alpha.security.cert.str.31c \
+// RUN:  -verify %s
+
+// See the examples on the page of STR31-C:
+// https://wiki.sei.cmu.edu/confluence/x/sNUxBQ
+
+#include "../Inputs/system-header-simulator.h"
+
+typedef __SIZE_TYPE__ size_t;
+
+void free(void *memblock);
+void *malloc(size_t size);
+
+namespace test_gets_bad {
+#define BUFFER_SIZE 1024
+
+void func(void) {
+  char buf[BUFFER_SIZE];
+  if (gets(buf)) {
+// expected-warning@-1 {{'gets' could write outside of 'buf'}}
+  }
+}
+} // namespace test_gets_bad
+
+namespace test_gets_good {
+enum { BUFFERSIZE = 32 };
+
+void func(void) {
+  char buff[BUFFERSIZE];
+
+  if (fgets(buff, sizeof(buff), stdin)) {
+  }
+}
+} // namespace test_gets_good
+
+namespace test_sprintf_bad {
+void func(const char *name) {
+  char buf[128];
+  sprintf(buf, "%s.txt", name);
+  // expected-warning@-1 {{'sprintf' could write outside of 'buf'}}
+}
+} // namespace test_sprintf_bad
+
+namespace test_sprintf_good {
+void func(const char *name) {
+  char buff[128];
+  snprintf(buff, sizeof(buff), "%s.txt", name);
+}
+} // namespace test_sprintf_good
+
+namespace test_fscanf_bad {
+enum { BUF_LENGTH = 1024 };
+
+void get_data(void) {
+  char buf[BUF_LENGTH];
+  fscanf(stdin, "%s", buf);
+  // expected-warning@-1 {{'fscanf' could write outside of 'buf'}}
+}
+} // namespace test_fscanf_bad
+
+namespace test_fscanf_good {
+enum { BUF_LENGTH = 1024 };
+
+void get_data(void) {
+  char buff[BUF_LENGTH];
+  fscanf(stdin, "%1023s", buff);
+}
+} // namespace test_fscanf_good
+
+namespace test_strcpy_bad {
+int main(int argc, char *argv[]) {
+  const char *const name = (argc && argv[0]) ? argv[0] : "";
+  char prog_name[128];
+  strcpy(prog_name, name);
+  // expected-warning@-1 {{'strcpy' could write outside of 'prog_name'}}
+  return 0;
+}
+
+void func(void) {
+  char buff[256];
+  char *editor = getenv("EDITOR");
+  if (editor != NULL) {
+strcpy(buff, editor);
+// expected-warning@-1 {{'strcpy' could write outside of 'buff'}}
+  }
+}
+} // namespace test_strcpy_bad
+
+namespace test_strcpy_good {
+int main(int argc, char *argv[]) {
+  const char *const name = (argc && argv[0]) ? argv[0] : "";
+  char *prog_name2 = (char *)malloc(strlen(name) + 1);
+  if (prog_name2 != NULL) {
+strcpy(prog_name2, name);
+  }
+
+  free(prog_name2);
+  return 0;
+}
+
+void func(void) {
+  char *buff2;
+  char *editor = getenv("EDITOR");
+  if (editor != NULL) {
+size_t len = strlen(editor) + 1;
+buff2 = (char *)malloc(len);
+if (buff2 != NULL) {
+  strcpy(buff2, editor);
+}
+
+free(buff2);
+  }
+}
+} // namespace test_strcpy_good
+
+//===--===//
+// The following are from the rule's page which we do not handle yet.
+//===--===//
+
+namespace test_loop_index_bad {
+void copy(size_t n, char src[n], char dest[n]) {
+  size_t i;
+
+  for (i = 0; src[i] && (i < n); ++i) {
+dest[i] = src[i];
+  }
+  dest[i] = '\0';
+}
+} // namespace test_loop_index_bad
+
+namespace test_loop_index_good {
+void copy(size_t n, char src[n], char dest[n]) {
+  size_t i;
+
+  for (i = 0; src[i] && (i < n - 1); ++i) {
+dest[i] = src[i];
+  }
+  dest[i] = '\0';
+}
+} // namespace test_loop_index_good
+
+namespace test_getchar_bad {
+enum { BUFFERSIZE = 32 };
+
+void func(void) {
+  char buf[BUFFERSIZE];
+  char *p;
+  int ch;
+  p = buf;
+  while ((ch = getchar()) != '\n' && ch != EOF) {
+*p++ = (char)ch;
+  }
+  *p++ = 0;
+  if (ch == EOF) {
+/* Handle EOF or error */
+  }
+}
+} // namespace test_getchar_bad
+
+namespace test_getchar_good {
+enum { BUFFERSIZE = 32

[PATCH] D70411: [analyzer] CERT STR rule checkers: STR31-C

2020-07-15 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

Thanks for the reviews!

In D70411#2153562 , @Szelethus wrote:

> Please do not bypass the previous comments that hadn't reached a conclusion 
> -- littering inlines about miscellaneous stuff at this stage does more harm 
> then good, and derails the discussion.


Ugh, it is a long story. I really wanted to create the best and trendiest 
checker of all time with Artem so all the comments are made for him at first. 
We have had the exact opposite sense what we are trying to achieve here, that 
is why we left the project dead.

Hopefully I get your suggestion right and you want to make sure I have 
addressed all the comments. Let me begin with a suggestion as well:

> If you are interested in the solution, please do not care about the problem, 
> but the solution.

- non-literal advice from //It's Not About the Shark: How to Solve Unsolvable 
Problems//

-

Let me rewind / summarize what problems happened in chunks if you would Ctrl+F5 
for certain quotes and what we did in chronological order:

> You're bringing in a completely brand-new machinery here, could you explain 
> how it works and why do you need it?

I have attached multiple bug reports to the program state (by registering a 
map) and invalidated all the non-fatal reports in chain on the bug-path to a 
given fatal-report to support two functionality of the checker.

That two functionality was a complete stupidity it turned out, I have left only 
the necessary one.

> I think it would really help if you draw a state machine for the checker

Because I have removed the complexity of the checker now it is easy to 
understand and it does not require an appendix.

> But it doesn't necessarily mean that static analysis tools can be built by 
> generalizing over the examples from the CERT wiki.

Artem refuse the usefulness of the CERT rules from the static analysis 
perspective, which I agree with.

> "if string length metadata is tainted (in particular, if the string itself is 
> tainted) and is potentially larger than the destination buffer size (eg., 
> unconstrained), warn"

Artem suggests to develop taint analysis, which I do not want to develop, but 
his concerns are real.

> Traditionally checkers either warn immediately when they can detect an error, 
> or assume that the error has not happened.

That was the near the point when I have realized we need to warn on the 
function calls immediately. The buffer overflow is immediately a security 
issue, but I was dumb to realize.

> I took a look at first 5 and in all of them the code does in fact ensure that 
> the buffer space is sufficient, but in 5 different ways.

Artem believes the arrays are cool because they cannot overflow. For example we 
obtain an IP address, which has enough space as `char[64]` our mental model 
suggests. I believe any overflow is not cool in a security point of view: 
https://twitter.com/TwitterSupport/status/1283526400146837511

Now I have accepted Artem's suggestion and I do not care about arrays because 
the Analyzer cannot model the constraints of the array size yet / taintness. If 
someone working with a plain char array that could be easy to detect and 
measure. For the security problems we want to catch allocations.

> The known size does not mean that the string is going to be null-terminated.
>  The problem is not the size, but the missing '\0' (which you can have 
> multiple of at any point).

I still wanted to care about null-termination, however the entire checker 
should be about overflow.

> - "The checker warns every time it finds an execution path on which 
> unintended behavior occurs"
> - "The checker enforces a certain coding guideline on the user": (say, "don't 
> pass the string by pointer anywhere before you null-terminate it")
> - If you rely on the existing taint analysis infrastructure and make a good 
> check, that'll be wonderful and would further encourage us to move taint 
> analysis out of alpha.

Artem tried to create a direction for the checker, it was pretty complex. I 
have refused again, because all the people null terminate by hand.

> This text may be hard to understand.

Balazs get confused by the second behavior, like Artem did for a while. I have 
tried to rephrase the documentation. With Balazs' help we made the 
documentation cool (Thanks again!).

> Get rid of the secondary behavior for now.

That was the time when I have learnt complexity is a huge issue and people will 
get confused. I have removed the entire secondary behavior of null termination 
checking and moved some logic to STR32-C.

-

The conclusion: Now this checker is very strict and hopefully enough simple. I 
hope we could design the future of checker-writing.




Comment at: clang/include/clang/StaticAnalyzer/Checkers/Checkers.td:859
+
+def Str31cChecker : Checker<"31c">,
+  HelpText<"SEI CERT checker of rules defined in STR31-C">,

baloghada

[PATCH] D83360: [InstSimplify] Remove select ?, undef, X -> X and select ?, X, undef -> X

2020-07-15 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

I'm going to revert this as Eric requested. And I'll ask to merge the revert to 
the 11 branch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83360



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


[clang] 00f3579 - Revert "[InstSimplify] Remove select ?, undef, X -> X and select ?, X, undef -> X transforms" and subsequent patches

2020-07-15 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2020-07-15T22:02:33-07:00
New Revision: 00f3579aea6e3d4a4b7464c3db47294f71cef9e4

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

LOG: Revert "[InstSimplify] Remove select ?, undef, X -> X and select ?, X, 
undef -> X transforms" and subsequent patches

This reverts most of the following patches due to reports of miscompiles.
I've left the added test cases with comments updated to be FIXMEs.

1cf6f210a2e [IR] Disable select ? C : undef -> C fold in 
ConstantFoldSelectInstruction unless we know C isn't poison.
469da663f2d [InstSimplify] Re-enable select ?, undef, X -> X transform when X 
is provably not poison
122b0640fc9 [InstSimplify] Don't fold vectors of partial undef in 
SimplifySelectInst if the non-undef element value might produce poison
ac0af12ed2f [InstSimplify] Add test cases for opportunities to fold select ?, 
X, undef -> X when we can prove X isn't poison
9b1e95329af [InstSimplify] Remove select ?, undef, X -> X and select ?, X, 
undef -> X transforms

Added: 


Modified: 
clang/test/CodeGen/arm-mve-intrinsics/dup.c
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/lib/IR/ConstantFold.cpp
llvm/test/Transforms/InferAddressSpaces/AMDGPU/select.ll
llvm/test/Transforms/InstCombine/select.ll
llvm/test/Transforms/InstSimplify/select.ll

Removed: 




diff  --git a/clang/test/CodeGen/arm-mve-intrinsics/dup.c 
b/clang/test/CodeGen/arm-mve-intrinsics/dup.c
index b443917cb258..283c08257005 100644
--- a/clang/test/CodeGen/arm-mve-intrinsics/dup.c
+++ b/clang/test/CodeGen/arm-mve-intrinsics/dup.c
@@ -242,8 +242,7 @@ uint32x4_t test_vdupq_m_n_u32(uint32x4_t inactive, uint32_t 
a, mve_pred16_t p)
 // CHECK-NEXT:[[TMP1:%.*]] = call <8 x i1> @llvm.arm.mve.pred.i2v.v8i1(i32 
[[TMP0]])
 // CHECK-NEXT:[[DOTSPLATINSERT:%.*]] = insertelement <8 x half> undef, 
half [[A:%.*]], i32 0
 // CHECK-NEXT:[[DOTSPLAT:%.*]] = shufflevector <8 x half> 
[[DOTSPLATINSERT]], <8 x half> undef, <8 x i32> zeroinitializer
-// CHECK-NEXT:[[TMP2:%.*]] = select <8 x i1> [[TMP1]], <8 x half> 
[[DOTSPLAT]], <8 x half> undef
-// CHECK-NEXT:ret <8 x half> [[TMP2]]
+// CHECK-NEXT:ret <8 x half> [[DOTSPLAT]]
 //
 float16x8_t test_vdupq_x_n_f16(float16_t a, mve_pred16_t p)
 {
@@ -256,8 +255,7 @@ float16x8_t test_vdupq_x_n_f16(float16_t a, mve_pred16_t p)
 // CHECK-NEXT:[[TMP1:%.*]] = call <4 x i1> @llvm.arm.mve.pred.i2v.v4i1(i32 
[[TMP0]])
 // CHECK-NEXT:[[DOTSPLATINSERT:%.*]] = insertelement <4 x float> undef, 
float [[A:%.*]], i32 0
 // CHECK-NEXT:[[DOTSPLAT:%.*]] = shufflevector <4 x float> 
[[DOTSPLATINSERT]], <4 x float> undef, <4 x i32> zeroinitializer
-// CHECK-NEXT:[[TMP2:%.*]] = select <4 x i1> [[TMP1]], <4 x float> 
[[DOTSPLAT]], <4 x float> undef
-// CHECK-NEXT:ret <4 x float> [[TMP2]]
+// CHECK-NEXT:ret <4 x float> [[DOTSPLAT]]
 //
 float32x4_t test_vdupq_x_n_f32(float32_t a, mve_pred16_t p)
 {
@@ -270,8 +268,7 @@ float32x4_t test_vdupq_x_n_f32(float32_t a, mve_pred16_t p)
 // CHECK-NEXT:[[TMP1:%.*]] = call <16 x i1> 
@llvm.arm.mve.pred.i2v.v16i1(i32 [[TMP0]])
 // CHECK-NEXT:[[DOTSPLATINSERT:%.*]] = insertelement <16 x i8> undef, i8 
[[A:%.*]], i32 0
 // CHECK-NEXT:[[DOTSPLAT:%.*]] = shufflevector <16 x i8> 
[[DOTSPLATINSERT]], <16 x i8> undef, <16 x i32> zeroinitializer
-// CHECK-NEXT:[[TMP2:%.*]] = select <16 x i1> [[TMP1]], <16 x i8> 
[[DOTSPLAT]], <16 x i8> undef
-// CHECK-NEXT:ret <16 x i8> [[TMP2]]
+// CHECK-NEXT:ret <16 x i8> [[DOTSPLAT]]
 //
 int8x16_t test_vdupq_x_n_s8(int8_t a, mve_pred16_t p)
 {
@@ -284,8 +281,7 @@ int8x16_t test_vdupq_x_n_s8(int8_t a, mve_pred16_t p)
 // CHECK-NEXT:[[TMP1:%.*]] = call <8 x i1> @llvm.arm.mve.pred.i2v.v8i1(i32 
[[TMP0]])
 // CHECK-NEXT:[[DOTSPLATINSERT:%.*]] = insertelement <8 x i16> undef, i16 
[[A:%.*]], i32 0
 // CHECK-NEXT:[[DOTSPLAT:%.*]] = shufflevector <8 x i16> 
[[DOTSPLATINSERT]], <8 x i16> undef, <8 x i32> zeroinitializer
-// CHECK-NEXT:[[TMP2:%.*]] = select <8 x i1> [[TMP1]], <8 x i16> 
[[DOTSPLAT]], <8 x i16> undef
-// CHECK-NEXT:ret <8 x i16> [[TMP2]]
+// CHECK-NEXT:ret <8 x i16> [[DOTSPLAT]]
 //
 int16x8_t test_vdupq_x_n_s16(int16_t a, mve_pred16_t p)
 {
@@ -298,8 +294,7 @@ int16x8_t test_vdupq_x_n_s16(int16_t a, mve_pred16_t p)
 // CHECK-NEXT:[[TMP1:%.*]] = call <4 x i1> @llvm.arm.mve.pred.i2v.v4i1(i32 
[[TMP0]])
 // CHECK-NEXT:[[DOTSPLATINSERT:%.*]] = insertelement <4 x i32> undef, i32 
[[A:%.*]], i32 0
 // CHECK-NEXT:[[DOTSPLAT:%.*]] = shufflevector <4 x i32> 
[[DOTSPLATINSERT]], <4 x i32> undef, <4 x i32> zeroinitializer
-// CHECK-NEXT:[[TMP2:%.*]] = select <4 x i1> [[TMP1]], <4 x i32> 
[[DOTSPLAT]], <4 x i32> undef
-// CHECK-NEXT:ret <4 x i32> [[TMP2]]
+// CHECK-NEXT:ret <4 x i3

[PATCH] D83360: [InstSimplify] Remove select ?, undef, X -> X and select ?, X, undef -> X

2020-07-15 Thread Craig Topper via Phabricator via cfe-commits
craig.topper reopened this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

Reverted in 00f3579aea6e3d4a4b7464c3db47294f71cef9e4 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83360



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


[PATCH] D83360: [InstSimplify] Remove select ?, undef, X -> X and select ?, X, undef -> X

2020-07-15 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Merge request for 11.0 https://bugs.llvm.org/show_bug.cgi?id=46740


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83360



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


[PATCH] D83497: [PowerPC][Power10] Fix VINS* (vector insert byte/half/word) instructions to have i32 arguments.

2020-07-15 Thread Amy Kwan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfc5530862870: [PowerPC][Power10] Fix VINS* (vector insert 
byte/half/word) instructions to… (authored by amyk).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83497

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/test/CodeGen/builtins-ppc-p10vector.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCInstrPrefix.td
  llvm/test/CodeGen/PowerPC/builtins-ppc-p10permute.ll

Index: llvm/test/CodeGen/PowerPC/builtins-ppc-p10permute.ll
===
--- llvm/test/CodeGen/PowerPC/builtins-ppc-p10permute.ll
+++ llvm/test/CodeGen/PowerPC/builtins-ppc-p10permute.ll
@@ -82,71 +82,71 @@
 }
 declare <2 x i64> @llvm.ppc.vsx.xxblendvd(<2 x i64>, <2 x i64>, <2 x i64>)
 
-define <16 x i8> @testVINSBLX(<16 x i8> %a, i64 %b, i64 %c) {
+define <16 x i8> @testVINSBLX(<16 x i8> %a, i32 %b, i32 %c) {
 ; CHECK-LABEL: testVINSBLX:
 ; CHECK:   # %bb.0: # %entry
 ; CHECK-NEXT:vinsblx v2, r5, r6
 ; CHECK-NEXT:blr
 entry:
-  %0 = tail call <16 x i8> @llvm.ppc.altivec.vinsblx(<16 x i8> %a, i64 %b, i64 %c)
+  %0 = tail call <16 x i8> @llvm.ppc.altivec.vinsblx(<16 x i8> %a, i32 %b, i32 %c)
   ret <16 x i8> %0
 }
-declare <16 x i8> @llvm.ppc.altivec.vinsblx(<16 x i8>, i64, i64)
+declare <16 x i8> @llvm.ppc.altivec.vinsblx(<16 x i8>, i32, i32)
 
-define <16 x i8> @testVINSBRX(<16 x i8> %a, i64 %b, i64 %c) {
+define <16 x i8> @testVINSBRX(<16 x i8> %a, i32 %b, i32 %c) {
 ; CHECK-LABEL: testVINSBRX:
 ; CHECK:   # %bb.0: # %entry
 ; CHECK-NEXT:vinsbrx v2, r5, r6
 ; CHECK-NEXT:blr
 entry:
-  %0 = tail call <16 x i8> @llvm.ppc.altivec.vinsbrx(<16 x i8> %a, i64 %b, i64 %c)
+  %0 = tail call <16 x i8> @llvm.ppc.altivec.vinsbrx(<16 x i8> %a, i32 %b, i32 %c)
   ret <16 x i8> %0
 }
-declare <16 x i8> @llvm.ppc.altivec.vinsbrx(<16 x i8>, i64, i64)
+declare <16 x i8> @llvm.ppc.altivec.vinsbrx(<16 x i8>, i32, i32)
 
-define <8 x i16> @testVINSHLX(<8 x i16> %a, i64 %b, i64 %c) {
+define <8 x i16> @testVINSHLX(<8 x i16> %a, i32 %b, i32 %c) {
 ; CHECK-LABEL: testVINSHLX:
 ; CHECK:   # %bb.0: # %entry
 ; CHECK-NEXT:vinshlx v2, r5, r6
 ; CHECK-NEXT:blr
 entry:
-  %0 = tail call <8 x i16> @llvm.ppc.altivec.vinshlx(<8 x i16> %a, i64 %b, i64 %c)
+  %0 = tail call <8 x i16> @llvm.ppc.altivec.vinshlx(<8 x i16> %a, i32 %b, i32 %c)
   ret <8 x i16> %0
 }
-declare <8 x i16> @llvm.ppc.altivec.vinshlx(<8 x i16>, i64, i64)
+declare <8 x i16> @llvm.ppc.altivec.vinshlx(<8 x i16>, i32, i32)
 
-define <8 x i16> @testVINSHRX(<8 x i16> %a, i64 %b, i64 %c) {
+define <8 x i16> @testVINSHRX(<8 x i16> %a, i32 %b, i32 %c) {
 ; CHECK-LABEL: testVINSHRX:
 ; CHECK:   # %bb.0: # %entry
 ; CHECK-NEXT:vinshrx v2, r5, r6
 ; CHECK-NEXT:blr
 entry:
-  %0 = tail call <8 x i16> @llvm.ppc.altivec.vinshrx(<8 x i16> %a, i64 %b, i64 %c)
+  %0 = tail call <8 x i16> @llvm.ppc.altivec.vinshrx(<8 x i16> %a, i32 %b, i32 %c)
   ret <8 x i16> %0
 }
-declare <8 x i16> @llvm.ppc.altivec.vinshrx(<8 x i16>, i64, i64)
+declare <8 x i16> @llvm.ppc.altivec.vinshrx(<8 x i16>, i32, i32)
 
-define <4 x i32> @testVINSWLX(<4 x i32> %a, i64 %b, i64 %c) {
+define <4 x i32> @testVINSWLX(<4 x i32> %a, i32 %b, i32 %c) {
 ; CHECK-LABEL: testVINSWLX:
 ; CHECK:   # %bb.0: # %entry
 ; CHECK-NEXT:vinswlx v2, r5, r6
 ; CHECK-NEXT:blr
 entry:
-  %0 = tail call <4 x i32> @llvm.ppc.altivec.vinswlx(<4 x i32> %a, i64 %b, i64 %c)
+  %0 = tail call <4 x i32> @llvm.ppc.altivec.vinswlx(<4 x i32> %a, i32 %b, i32 %c)
   ret <4 x i32> %0
 }
-declare <4 x i32> @llvm.ppc.altivec.vinswlx(<4 x i32>, i64, i64)
+declare <4 x i32> @llvm.ppc.altivec.vinswlx(<4 x i32>, i32, i32)
 
-define <4 x i32> @testVINSWRX(<4 x i32> %a, i64 %b, i64 %c) {
+define <4 x i32> @testVINSWRX(<4 x i32> %a, i32 %b, i32 %c) {
 ; CHECK-LABEL: testVINSWRX:
 ; CHECK:   # %bb.0: # %entry
 ; CHECK-NEXT:vinswrx v2, r5, r6
 ; CHECK-NEXT:blr
 entry:
-  %0 = tail call <4 x i32> @llvm.ppc.altivec.vinswrx(<4 x i32> %a, i64 %b, i64 %c)
+  %0 = tail call <4 x i32> @llvm.ppc.altivec.vinswrx(<4 x i32> %a, i32 %b, i32 %c)
   ret <4 x i32> %0
 }
-declare <4 x i32> @llvm.ppc.altivec.vinswrx(<4 x i32>, i64, i64)
+declare <4 x i32> @llvm.ppc.altivec.vinswrx(<4 x i32>, i32, i32)
 
 define <2 x i64> @testVINSDLX(<2 x i64> %a, i64 %b, i64 %c) {
 ; CHECK-LABEL: testVINSDLX:
@@ -232,16 +232,16 @@
 }
 declare <4 x i32> @llvm.ppc.altivec.vinswvrx(<4 x i32>, i64, <4 x i32>)
 
-define <4 x i32> @testVINSW(<4 x i32> %a, i64 %b) {
+define <4 x i32> @testVINSW(<4 x i32> %a, i32 %b) {
 ; CHECK-LABEL: testVINSW:
 ; CHECK:   # %bb.0: # %entry
 ; CHECK-NEXT:vinsw v2, r5, 1
 ; CHECK-NEXT:blr
 entry:
-  %0 = tail call <4 x i32> @llvm.ppc.altivec.vinsw(<4 x i32> %a, i64 %b, i32 1)
+  %0 = tail call <4 x i32> @llvm.ppc.altivec.vinsw(<4 x i32> %a, i32 %b, i32 1)

[clang] fc55308 - [PowerPC][Power10] Fix VINS* (vector insert byte/half/word) instructions to have i32 arguments.

2020-07-15 Thread Amy Kwan via cfe-commits

Author: Amy Kwan
Date: 2020-07-16T00:30:24-05:00
New Revision: fc55308628709bfc64b100dadf9a030fbb2afaee

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

LOG: [PowerPC][Power10] Fix VINS* (vector insert byte/half/word) instructions 
to have i32 arguments.

Previously, the vins* intrinsic was incorrectly defined to have its second and
third argument arguments as an i64. This patch fixes the second and third
argument of the vins* instruction and intrinsic to have i32s instead.

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsPPC.def
clang/test/CodeGen/builtins-ppc-p10vector.c
llvm/include/llvm/IR/IntrinsicsPowerPC.td
llvm/lib/Target/PowerPC/PPCInstrPrefix.td
llvm/test/CodeGen/PowerPC/builtins-ppc-p10permute.ll

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsPPC.def 
b/clang/include/clang/Basic/BuiltinsPPC.def
index 6b291e6b0806..5d445c253a85 100644
--- a/clang/include/clang/Basic/BuiltinsPPC.def
+++ b/clang/include/clang/Basic/BuiltinsPPC.def
@@ -321,12 +321,12 @@ BUILTIN(__builtin_altivec_vsldbi, "V16UcV16UcV16UcIi", "")
 BUILTIN(__builtin_altivec_vsrdbi, "V16UcV16UcV16UcIi", "")
 
 // P10 Vector Insert built-ins.
-BUILTIN(__builtin_altivec_vinsblx, "V16UcV16UcULLiULLi", "")
-BUILTIN(__builtin_altivec_vinsbrx, "V16UcV16UcULLiULLi", "")
-BUILTIN(__builtin_altivec_vinshlx, "V8UsV8UsULLiULLi", "")
-BUILTIN(__builtin_altivec_vinshrx, "V8UsV8UsULLiULLi", "")
-BUILTIN(__builtin_altivec_vinswlx, "V4UiV4UiULLiULLi", "")
-BUILTIN(__builtin_altivec_vinswrx, "V4UiV4UiULLiULLi", "")
+BUILTIN(__builtin_altivec_vinsblx, "V16UcV16UcUiUi", "")
+BUILTIN(__builtin_altivec_vinsbrx, "V16UcV16UcUiUi", "")
+BUILTIN(__builtin_altivec_vinshlx, "V8UsV8UsUiUi", "")
+BUILTIN(__builtin_altivec_vinshrx, "V8UsV8UsUiUi", "")
+BUILTIN(__builtin_altivec_vinswlx, "V4UiV4UiUiUi", "")
+BUILTIN(__builtin_altivec_vinswrx, "V4UiV4UiUiUi", "")
 BUILTIN(__builtin_altivec_vinsdlx, "V2ULLiV2ULLiULLiULLi", "")
 BUILTIN(__builtin_altivec_vinsdrx, "V2ULLiV2ULLiULLiULLi", "")
 BUILTIN(__builtin_altivec_vinsbvlx, "V16UcV16UcULLiV16Uc", "")

diff  --git a/clang/test/CodeGen/builtins-ppc-p10vector.c 
b/clang/test/CodeGen/builtins-ppc-p10vector.c
index c51c24f25986..4e804fbafb30 100644
--- a/clang/test/CodeGen/builtins-ppc-p10vector.c
+++ b/clang/test/CodeGen/builtins-ppc-p10vector.c
@@ -402,25 +402,25 @@ vector double test_vec_blend_d(void) {
 }
 
 vector unsigned char test_vec_insertl_uc(void) {
-  // CHECK-BE: @llvm.ppc.altivec.vinsblx(<16 x i8> %{{.+}}, i64 %{{.+}}, i64
+  // CHECK-BE: @llvm.ppc.altivec.vinsblx(<16 x i8> %{{.+}}, i32 %{{.+}}, i32
   // CHECK-BE-NEXT: ret <16 x i8>
-  // CHECK-LE: @llvm.ppc.altivec.vinsbrx(<16 x i8> %{{.+}}, i64 %{{.+}}, i64
+  // CHECK-LE: @llvm.ppc.altivec.vinsbrx(<16 x i8> %{{.+}}, i32 %{{.+}}, i32
   // CHECK-LE-NEXT: ret <16 x i8>
   return vec_insertl(uca, vuca, uia);
 }
 
 vector unsigned short test_vec_insertl_us(void) {
-  // CHECK-BE: @llvm.ppc.altivec.vinshlx(<8 x i16> %{{.+}}, i64 %{{.+}}, i64
+  // CHECK-BE: @llvm.ppc.altivec.vinshlx(<8 x i16> %{{.+}}, i32 %{{.+}}, i32
   // CHECK-BE-NEXT: ret <8 x i16>
-  // CHECK-LE: @llvm.ppc.altivec.vinshrx(<8 x i16> %{{.+}}, i64 %{{.+}}, i64
+  // CHECK-LE: @llvm.ppc.altivec.vinshrx(<8 x i16> %{{.+}}, i32 %{{.+}}, i32
   // CHECK-LE-NEXT: ret <8 x i16>
   return vec_insertl(usa, vusa, uia);
 }
 
 vector unsigned int test_vec_insertl_ui(void) {
-  // CHECK-BE: @llvm.ppc.altivec.vinswlx(<4 x i32> %{{.+}}, i64 %{{.+}}, i64
+  // CHECK-BE: @llvm.ppc.altivec.vinswlx(<4 x i32> %{{.+}}, i32 %{{.+}}, i32
   // CHECK-BE-NEXT: ret <4 x i32>
-  // CHECK-LE: @llvm.ppc.altivec.vinswrx(<4 x i32> %{{.+}}, i64 %{{.+}}, i64
+  // CHECK-LE: @llvm.ppc.altivec.vinswrx(<4 x i32> %{{.+}}, i32 %{{.+}}, i32
   // CHECK-LE-NEXT: ret <4 x i32>
   return vec_insertl(uib, vuia, uia);
 }
@@ -458,25 +458,25 @@ vector unsigned int test_vec_insertl_uiv(void) {
 }
 
 vector unsigned char test_vec_inserth_uc(void) {
-  // CHECK-BE: @llvm.ppc.altivec.vinsbrx(<16 x i8> %{{.+}}, i64 %{{.+}}, i64
+  // CHECK-BE: @llvm.ppc.altivec.vinsbrx(<16 x i8> %{{.+}}, i32 %{{.+}}, i32
   // CHECK-BE-NEXT: ret <16 x i8>
-  // CHECK-LE: @llvm.ppc.altivec.vinsblx(<16 x i8> %{{.+}}, i64 %{{.+}}, i64
+  // CHECK-LE: @llvm.ppc.altivec.vinsblx(<16 x i8> %{{.+}}, i32 %{{.+}}, i32
   // CHECK-LE-NEXT: ret <16 x i8>
   return vec_inserth(uca, vuca, uia);
 }
 
 vector unsigned short test_vec_inserth_us(void) {
-  // CHECK-BE: @llvm.ppc.altivec.vinshrx(<8 x i16> %{{.+}}, i64 %{{.+}}, i64
+  // CHECK-BE: @llvm.ppc.altivec.vinshrx(<8 x i16> %{{.+}}, i32 %{{.+}}, i32
   // CHECK-BE-NEXT: ret <8 x i16>
-  // CHECK-LE: @llvm.ppc.altivec.vinshlx(<8 x i16> %{{.+}}, i64 %{{.+}}, i64
+  // CHECK-LE: @llvm.ppc.altivec.v

[PATCH] D83826: [clangd] Don't send invalid messages from remote index

2020-07-15 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 278086.
kbobyrev added a comment.

Don't allow empty paths.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83826

Files:
  clang-tools-extra/clangd/index/remote/Client.cpp
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
  clang-tools-extra/clangd/index/remote/server/Server.cpp
  clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp

Index: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
===
--- clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -46,10 +46,11 @@
   Strings);
   auto Serialized =
   toProtobuf(Original, testPath("remote/machine/projects/llvm-project/"));
-  EXPECT_EQ(Serialized.location().file_path(),
+  EXPECT_TRUE(Serialized);
+  EXPECT_EQ(Serialized->location().file_path(),
 "clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp");
   const std::string LocalIndexPrefix = testPath("local/machine/project/");
-  auto Deserialized = fromProtobuf(Serialized, &Strings,
+  auto Deserialized = fromProtobuf(*Serialized, &Strings,
testPath("home/my-projects/llvm-project/"));
   EXPECT_TRUE(Deserialized);
   EXPECT_EQ(Deserialized->Location.FileURI,
@@ -57,11 +58,16 @@
 "clangd/unittests/remote/MarshallingTests.cpp",
 Strings));
 
+  // Can't have empty paths.
+  *Serialized->mutable_location()->mutable_file_path() = std::string();
+  Deserialized = fromProtobuf(*Serialized, &Strings, LocalIndexPrefix);
+  EXPECT_FALSE(Deserialized);
+
   clangd::Ref WithInvalidURI;
-  // Invalid URI results in empty path.
+  // Invalid URI results in serialization failure.
   WithInvalidURI.Location.FileURI = "This is not a URI";
   Serialized = toProtobuf(WithInvalidURI, testPath("home/"));
-  EXPECT_EQ(Serialized.location().file_path(), "");
+  EXPECT_FALSE(Serialized);
 
   // Can not use URIs with scheme different from "file".
   auto UnittestURI =
@@ -70,7 +76,7 @@
   WithInvalidURI.Location.FileURI =
   Strings.save(UnittestURI->toString()).begin();
   Serialized = toProtobuf(WithInvalidURI, testPath("project/lib/"));
-  EXPECT_EQ(Serialized.location().file_path(), "");
+  EXPECT_FALSE(Serialized);
 
   Ref WithAbsolutePath;
   *WithAbsolutePath.mutable_location()->mutable_file_path() =
@@ -131,22 +137,28 @@
   // Check that symbols are exactly the same if the path to indexed project is
   // the same on indexing machine and the client.
   auto Serialized = toProtobuf(Sym, testPath("home/"));
-  auto Deserialized = fromProtobuf(Serialized, &Strings, testPath("home/"));
+  EXPECT_TRUE(Serialized);
+  auto Deserialized = fromProtobuf(*Serialized, &Strings, testPath("home/"));
   EXPECT_TRUE(Deserialized);
   EXPECT_EQ(toYAML(Sym), toYAML(*Deserialized));
   // Serialized paths are relative and have UNIX slashes.
-  EXPECT_EQ(convert_to_slash(Serialized.definition().file_path(),
+  EXPECT_EQ(convert_to_slash(Serialized->definition().file_path(),
  llvm::sys::path::Style::posix),
-Serialized.definition().file_path());
+Serialized->definition().file_path());
   EXPECT_TRUE(
-  llvm::sys::path::is_relative(Serialized.definition().file_path()));
+  llvm::sys::path::is_relative(Serialized->definition().file_path()));
+
+  // Relative path is absolute.
+  *Serialized->mutable_canonical_declaration()->mutable_file_path() =
+  convert_to_slash("/path/to/Declaration.h");
+  Deserialized = fromProtobuf(*Serialized, &Strings, testPath("home/"));
+  EXPECT_FALSE(Deserialized);
 
   // Fail with an invalid URI.
   Location.FileURI = "Not A URI";
   Sym.Definition = Location;
   Serialized = toProtobuf(Sym, testPath("home/"));
-  Deserialized = fromProtobuf(Serialized, &Strings, testPath("home/"));
-  EXPECT_FALSE(Deserialized);
+  EXPECT_FALSE(Serialized);
 
   // Schemes other than "file" can not be used.
   auto UnittestURI = URI::create(testPath("home/SomePath.h"), "unittest");
@@ -154,22 +166,21 @@
   Location.FileURI = Strings.save(UnittestURI->toString()).begin();
   Sym.Definition = Location;
   Serialized = toProtobuf(Sym, testPath("home/"));
-  Deserialized = fromProtobuf(Serialized, &Strings, testPath("home/"));
-  EXPECT_FALSE(Deserialized);
+  EXPECT_FALSE(Serialized);
 
   // Passing root that is not prefix of the original file path.
   Location.FileURI = testPathURI("home/File.h", Strings);
   Sym.Definition = Location;
   // Check that the symbol is valid and passing the correct path works.
   Serialized = toProtobuf(Sym, testPath("home/"));
-  Deserialized = fromProtobuf(Serialized, &Strings, testPath("home/"));
+  EXPECT_TRUE(Serialized);
+  Des

[PATCH] D83855: [clang] fix printing of lambdas with capture expressions

2020-07-15 Thread Ilya Golovenko via Phabricator via cfe-commits
walrus created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83855

Files:
  clang/lib/AST/StmtPrinter.cpp
  clang/test/AST/ast-printer-lambda.cpp


Index: clang/test/AST/ast-printer-lambda.cpp
===
--- clang/test/AST/ast-printer-lambda.cpp
+++ clang/test/AST/ast-printer-lambda.cpp
@@ -15,6 +15,22 @@
   auto lambda = [&]{};
   //CHECK: [&] {
 }
+{
+  auto lambda = [k{i}] {};
+  //CHECK: [k{i}] {
+}
+{
+  auto lambda = [k(i)] {};
+  //CHECK: [k(i)] {
+}
+{
+  auto lambda = [k = i] {};
+  //CHECK: [k = i] {
+}
+{
+  auto lambda = [&k = i] {};
+  //CHECK: [&k = i] {
+}
 {
   auto lambda = [t..., i]{};
   //CHECK: [t..., i] {
Index: clang/lib/AST/StmtPrinter.cpp
===
--- clang/lib/AST/StmtPrinter.cpp
+++ clang/lib/AST/StmtPrinter.cpp
@@ -2005,8 +2005,17 @@
 if (C->isPackExpansion())
   OS << "...";
 
-if (Node->isInitCapture(C))
-  PrintExpr(C->getCapturedVar()->getInit());
+if (Node->isInitCapture(C)) {
+  VarDecl *D = C->getCapturedVar();
+  Expr *Init = D->getInit();
+  if (D->getInitStyle() == VarDecl::CallInit && !isa(Init))
+OS << "(";
+  else if (D->getInitStyle() == VarDecl::CInit)
+OS << " = ";
+  PrintExpr(Init);
+  if (D->getInitStyle() == VarDecl::CallInit && !isa(Init))
+OS << ")";
+}
   }
   OS << ']';
 


Index: clang/test/AST/ast-printer-lambda.cpp
===
--- clang/test/AST/ast-printer-lambda.cpp
+++ clang/test/AST/ast-printer-lambda.cpp
@@ -15,6 +15,22 @@
   auto lambda = [&]{};
   //CHECK: [&] {
 }
+{
+  auto lambda = [k{i}] {};
+  //CHECK: [k{i}] {
+}
+{
+  auto lambda = [k(i)] {};
+  //CHECK: [k(i)] {
+}
+{
+  auto lambda = [k = i] {};
+  //CHECK: [k = i] {
+}
+{
+  auto lambda = [&k = i] {};
+  //CHECK: [&k = i] {
+}
 {
   auto lambda = [t..., i]{};
   //CHECK: [t..., i] {
Index: clang/lib/AST/StmtPrinter.cpp
===
--- clang/lib/AST/StmtPrinter.cpp
+++ clang/lib/AST/StmtPrinter.cpp
@@ -2005,8 +2005,17 @@
 if (C->isPackExpansion())
   OS << "...";
 
-if (Node->isInitCapture(C))
-  PrintExpr(C->getCapturedVar()->getInit());
+if (Node->isInitCapture(C)) {
+  VarDecl *D = C->getCapturedVar();
+  Expr *Init = D->getInit();
+  if (D->getInitStyle() == VarDecl::CallInit && !isa(Init))
+OS << "(";
+  else if (D->getInitStyle() == VarDecl::CInit)
+OS << " = ";
+  PrintExpr(Init);
+  if (D->getInitStyle() == VarDecl::CallInit && !isa(Init))
+OS << ")";
+}
   }
   OS << ']';
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82767: clang-format: Explicitly use python3

2020-07-15 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.



>> My understanding is that explicitly requiring python3 may make sense if the 
>> script is not backward-compatible with python2, while requiring python means 
>> the version is not important.
>>  At the end-of-year, we should be able to harmonize shebangs to 
>> #!/usr/bin/env python3 or #!/usr/bin/env python
> 
> Fixing this to be consistent would be an improvement

Change proposed in https://reviews.llvm.org/D83857


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

https://reviews.llvm.org/D82767



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


[PATCH] D83621: [clang][Tooling] Try to avoid file system access if there is no record for the file in compile_commads.json

2020-07-15 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX added a comment.

In D83621#2151716 , @sammccall wrote:

> In D83621#2146750 , @ArcsinX wrote:
>
> > > - don't scan for equivalences if the set of candidates exceeds some size 
> > > threshold (10 or so)
> > > - don't scan for equivalences if the node we'd scan under is the root
> >
> > After such fixes `JSONCompilationDatabase::getCompileCommands()` will 
> > return other results than before in some cases.
>
>
> Can you elaborate on this - do you think there are reasonable cases where it 
> will give the wrong answer?
>  I can certainly imagine cases where this changes behaviour, e.g. 
> project/foo.cc is a symlink to project/bar.cc, compile_commands contains an 
> entry for foo.cc, we query for bar.cc.
>  But I don't think this was ever really intended to handle arbitrary symlinks 
> that change the names of files, and I do think this is OK to break.


If breaking `project/foo.cc <=> project/bar.cc` is OK, then could we also break 
`some/path/here/foo.cc <=> some/other/path/bar.cc`?

In that case we can just prevent `Comparator.equivalent(FileA,FileB)` calls 
when `llvm::sys::path::filename(FileA) != llvm::sys::path::filename(FileB)`.
I tried this locally:

- it works fast.
- does not break tests.
- easy to add unit test for `FileMatchTrie`.

What do you think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83621



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


[PATCH] D83120: [Analyzer][StreamChecker] Using BugType::SuppressOnSink at resource leak report.

2020-07-15 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked an inline comment as done.
balazske added a comment.

The problems with bug reporting should be fixed in another patch.




Comment at: clang/test/Analysis/stream.c:274-284
 // Check that "location uniqueing" works.
 // This results in reporting only one occurence of resource leak for a stream.
 void check_leak_noreturn_2() {
   FILE *F1 = tmpfile();
   if (!F1)
 return;
   if (Test == 1) {

NoQ wrote:
> balazske wrote:
> > NoQ wrote:
> > > balazske wrote:
> > > > Szelethus wrote:
> > > > > Szelethus wrote:
> > > > > > balazske wrote:
> > > > > > > NoQ wrote:
> > > > > > > > balazske wrote:
> > > > > > > > > Szelethus wrote:
> > > > > > > > > > Why did this change? Is there a sink in the return branch?
> > > > > > > > > The change is probably because D83115. Because the 
> > > > > > > > > "uniqueing" one resource leak is reported from the two 
> > > > > > > > > possible, and the order changes somehow (probably not the 
> > > > > > > > > shortest is found first).
> > > > > > > > The shortest should still be found first. I strongly suggest 
> > > > > > > > debugging this. Looks like a bug in suppress-on-sink.
> > > > > > > There is no code that ensures that the shortest path is reported. 
> > > > > > > In this case one equivalence class is created with both bug 
> > > > > > > reports. If `SuppressOnSink` is false the last one is returned 
> > > > > > > from the list, otherwise the first one 
> > > > > > > (`PathSensitiveBugReporter::findReportInEquivalenceClass`), this 
> > > > > > > causes the difference (seems to be unrelated to D83115).
> > > > > > > There is no code that ensures that the shortest path is reported.
> > > > > > 
> > > > > > There absolutely should be -- See the summary of D65379 for more 
> > > > > > info, CTRL+F "shortest" helps quite a bit as well. For each bug 
> > > > > > report, we create a bug path (a path in the exploded graph from the 
> > > > > > root to the sepcific bug reports error node), and sort them by 
> > > > > > length.
> > > > > > 
> > > > > > It all feels super awkward -- 
> > > > > > `PathSensitiveBugReporter::findReportInEquivalenceClass` picks out 
> > > > > > a bug report from an equivalence class as you described, but that 
> > > > > > will only be reported if it is a `BasicBugReport` (as implemented 
> > > > > > by `PathSensitiveBugReporter::generateDiagnosticForConsumerMap`), 
> > > > > > otherwise it should go through the graph cutting process etc.
> > > > > > 
> > > > > > So at the end of the day, the shortest path should appear still? 
> > > > > > 
> > > > > @balazske I spent a lot of my GSoC rewriting some especially 
> > > > > miserable code in `BugReporter.cpp`, please hunt me down if you need 
> > > > > any help there.
> > > > Can we say that the one path in this case is shorter than the other? 
> > > > The difference is only at the "taking true/false branch" at the `if` in 
> > > > line 280. Maybe both have equal length. The notes are taken always from 
> > > > the single picked report that is returned from 
> > > > `findReportInEquivalenceClass` and these notes can contain different 
> > > > source locations (reports in a single equivalence class can have 
> > > > different locations, really this makes the difference between them?).  
> > > > There is no code that ensures that the shortest path is reported.
> > > 
> > > We would have been soo screwed if this was so. In fact, 
> > > grepping for "shortest" in the entire clang sources immediately points 
> > > you to the right line of code.
> > > 
> > > > the last one is returned from the list, otherwise the first one
> > > 
> > > The example report is not actually used later for purposes other than 
> > > extracting information common to all reports in the path. The array of 
> > > valid reports is used instead, and it's supposed to be sorted.
> > > 
> > > > Can we say that the one path in this case is shorter than the other?
> > > 
> > > Dump the graph and see for yourself. I expect a call with an argument and 
> > > an implicit lvalue-to-rvalue conversion of that argument to take a lot 
> > > more nodes than an empty return statement.
> > I found the sorting code, it revealed that the problem has other reason: It 
> > happens only if //-analyzer-output text// is not passed to clang. It looks 
> > like that in this case the path in `PathDiagnostic` is not collected, so 
> > `BugReporter::FlushReport` will use the one report instance from the bug 
> > report class (that is different if `SuppressOnSink` is set or not).
> Ok, this sounds pretty bad, as if a lot of our lit tests actually have 
> warnings misplaced. I.e., we report different bug instances depending on the 
> consumer, even within the same analysis! Looks like this entire big for-loop 
> in `BugReporter::FlushReport` is potentially dealing with the wrong report(?)
> 
> Would you have the honor of fixing this mess that you've uncovered? Or i can 
> take it up if you're not into it^

[clang] de7bf72 - [RISCV] Add error checking for extensions missing separating underscores

2020-07-15 Thread Simon Cook via cfe-commits

Author: Simon Cook
Date: 2020-07-15T09:23:35+01:00
New Revision: de7bf722c23a1ab006bd306165c094669071577f

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

LOG: [RISCV] Add error checking for extensions missing separating underscores

Currently if two multi-letter extensions are provided in a -march=
string, the verification code checks the version of the first and
consumes the second, resulting in that part of the architecture
string being ignored. This adds a test that when a version number has
been parsed for an extension, there are no subsequent characters.

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Arch/RISCV.cpp
clang/test/Driver/riscv-arch.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 8659ebf17a72..80d12e5aa8da 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -89,7 +89,7 @@ static bool getExtensionVersion(const Driver &D, const 
ArgList &Args,
 
   if (Major.size() && In.consume_front("p")) {
 Minor = std::string(In.take_while(isDigit));
-In = In.substr(Major.size());
+In = In.substr(Major.size() + 1);
 
 // Expected 'p' to be followed by minor version number.
 if (Minor.empty()) {
@@ -101,6 +101,16 @@ static bool getExtensionVersion(const Driver &D, const 
ArgList &Args,
 }
   }
 
+  // Expected multi-character extension with version number to have no
+  // subsequent characters (i.e. must either end string or be followed by
+  // an underscore).
+  if (Ext.size() > 1 && In.size()) {
+std::string Error =
+"multi-character extensions must be separated by underscores";
+D.Diag(diag::err_drv_invalid_riscv_ext_arch_name) << MArch << Error << In;
+return false;
+  }
+
   // If experimental extension, require use of current version number number
   if (auto ExperimentalExtension = isExperimentalExtension(Ext)) {
 if (!Args.hasArg(options::OPT_menable_experimental_extensions)) {

diff  --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c
index e3062feb7dee..13d0748a967a 100644
--- a/clang/test/Driver/riscv-arch.c
+++ b/clang/test/Driver/riscv-arch.c
@@ -361,6 +361,10 @@
 // RV32-EXPERIMENTAL-ZBB-ZBP: "-target-feature" "+experimental-zbb"
 // RV32-EXPERIMENTAL-ZBB-ZBP: "-target-feature" "+experimental-zbp"
 
+// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb0p92zbp0p92 
-menable-experimental-extensions -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck 
-check-prefix=RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE %s
+// RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE: error: invalid arch name 
'rv32izbb0p92zbp0p92', multi-character extensions must be separated by 
underscores
+
 // RUN: %clang -target riscv32-unknown-elf -march=rv32iv -### %s -c 2>&1 | \
 // RUN:   FileCheck -check-prefix=RV32-EXPERIMENTAL-V-NOFLAG %s
 // RV32-EXPERIMENTAL-V-NOFLAG: error: invalid arch name 'rv32iv'



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


[PATCH] D83819: [RISCV] Add error checking for extensions missing separating underscores

2020-07-15 Thread Simon Cook via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGde7bf722c23a: [RISCV] Add error checking for extensions 
missing separating underscores (authored by simoncook).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83819

Files:
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-arch.c


Index: clang/test/Driver/riscv-arch.c
===
--- clang/test/Driver/riscv-arch.c
+++ clang/test/Driver/riscv-arch.c
@@ -361,6 +361,10 @@
 // RV32-EXPERIMENTAL-ZBB-ZBP: "-target-feature" "+experimental-zbb"
 // RV32-EXPERIMENTAL-ZBB-ZBP: "-target-feature" "+experimental-zbp"
 
+// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb0p92zbp0p92 
-menable-experimental-extensions -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck 
-check-prefix=RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE %s
+// RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE: error: invalid arch name 
'rv32izbb0p92zbp0p92', multi-character extensions must be separated by 
underscores
+
 // RUN: %clang -target riscv32-unknown-elf -march=rv32iv -### %s -c 2>&1 | \
 // RUN:   FileCheck -check-prefix=RV32-EXPERIMENTAL-V-NOFLAG %s
 // RV32-EXPERIMENTAL-V-NOFLAG: error: invalid arch name 'rv32iv'
Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -89,7 +89,7 @@
 
   if (Major.size() && In.consume_front("p")) {
 Minor = std::string(In.take_while(isDigit));
-In = In.substr(Major.size());
+In = In.substr(Major.size() + 1);
 
 // Expected 'p' to be followed by minor version number.
 if (Minor.empty()) {
@@ -101,6 +101,16 @@
 }
   }
 
+  // Expected multi-character extension with version number to have no
+  // subsequent characters (i.e. must either end string or be followed by
+  // an underscore).
+  if (Ext.size() > 1 && In.size()) {
+std::string Error =
+"multi-character extensions must be separated by underscores";
+D.Diag(diag::err_drv_invalid_riscv_ext_arch_name) << MArch << Error << In;
+return false;
+  }
+
   // If experimental extension, require use of current version number number
   if (auto ExperimentalExtension = isExperimentalExtension(Ext)) {
 if (!Args.hasArg(options::OPT_menable_experimental_extensions)) {


Index: clang/test/Driver/riscv-arch.c
===
--- clang/test/Driver/riscv-arch.c
+++ clang/test/Driver/riscv-arch.c
@@ -361,6 +361,10 @@
 // RV32-EXPERIMENTAL-ZBB-ZBP: "-target-feature" "+experimental-zbb"
 // RV32-EXPERIMENTAL-ZBB-ZBP: "-target-feature" "+experimental-zbp"
 
+// RUN: %clang -target riscv32-unknown-elf -march=rv32izbb0p92zbp0p92 -menable-experimental-extensions -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE %s
+// RV32-EXPERIMENTAL-ZBB-ZBP-UNDERSCORE: error: invalid arch name 'rv32izbb0p92zbp0p92', multi-character extensions must be separated by underscores
+
 // RUN: %clang -target riscv32-unknown-elf -march=rv32iv -### %s -c 2>&1 | \
 // RUN:   FileCheck -check-prefix=RV32-EXPERIMENTAL-V-NOFLAG %s
 // RV32-EXPERIMENTAL-V-NOFLAG: error: invalid arch name 'rv32iv'
Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -89,7 +89,7 @@
 
   if (Major.size() && In.consume_front("p")) {
 Minor = std::string(In.take_while(isDigit));
-In = In.substr(Major.size());
+In = In.substr(Major.size() + 1);
 
 // Expected 'p' to be followed by minor version number.
 if (Minor.empty()) {
@@ -101,6 +101,16 @@
 }
   }
 
+  // Expected multi-character extension with version number to have no
+  // subsequent characters (i.e. must either end string or be followed by
+  // an underscore).
+  if (Ext.size() > 1 && In.size()) {
+std::string Error =
+"multi-character extensions must be separated by underscores";
+D.Diag(diag::err_drv_invalid_riscv_ext_arch_name) << MArch << Error << In;
+return false;
+  }
+
   // If experimental extension, require use of current version number number
   if (auto ExperimentalExtension = isExperimentalExtension(Ext)) {
 if (!Args.hasArg(options::OPT_menable_experimental_extensions)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83055: [clang][Driver] Fix tool path priority test failures

2020-07-15 Thread David Spickett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
DavidSpickett marked an inline comment as done.
Closed by commit rGfe5912249efa: [clang][Driver] Fix tool path priority test 
failures (authored by DavidSpickett).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83055

Files:
  clang/test/Driver/program-path-priority.c
  clang/test/lit.cfg.py

Index: clang/test/lit.cfg.py
===
--- clang/test/lit.cfg.py
+++ clang/test/lit.cfg.py
@@ -46,6 +46,8 @@
 config.substitutions.append(
 ('%src_include_dir', config.clang_src_dir + '/include'))
 
+config.substitutions.append(
+('%target_triple', config.target_triple))
 
 # Propagate path to symbolizer for ASan/MSan.
 llvm_config.with_system_environment(
Index: clang/test/Driver/program-path-priority.c
===
--- clang/test/Driver/program-path-priority.c
+++ clang/test/Driver/program-path-priority.c
@@ -13,6 +13,11 @@
 /// so only name priority is accounted for, unless we fail to find
 /// anything at all in the prefix.
 
+/// Note: All matches are expected to be at the end of file paths.
+/// So we match " on the end to account for build systems that
+/// put the name of the compiler in the build path.
+/// E.g. /build/gcc_X.Y.Z/0/...
+
 /// Symlink clang to a new dir which will be its
 /// "program path" for these tests
 // RUN: rm -rf %t && mkdir -p %t
@@ -21,14 +26,18 @@
 /// No gccs at all, nothing is found
 // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=NO_NOTREAL_GCC %s
-// NO_NOTREAL_GCC-NOT: notreal-none-elf-gcc
-// NO_NOTREAL_GCC-NOT: /gcc
+// NO_NOTREAL_GCC-NOT: notreal-none-elf-gcc"
+/// Some systems will have "gcc-x.y.z" so for this first check
+/// make sure we don't find "gcc" or "gcc-x.y.z". If we do find either
+/// then there is no point continuing as this copy of clang is not
+/// isolated as we expected.
+// NO_NOTREAL_GCC-NOT: {{/gcc[^/]*"}}
 
 /// -gcc in program path is found
 // RUN: touch %t/notreal-none-elf-gcc && chmod +x %t/notreal-none-elf-gcc
 // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=PROG_PATH_NOTREAL_GCC %s
-// PROG_PATH_NOTREAL_GCC: notreal-none-elf-gcc
+// PROG_PATH_NOTREAL_GCC: notreal-none-elf-gcc"
 
 /// -gcc on the PATH is found
 // RUN: mkdir -p %t/env
@@ -36,74 +45,89 @@
 // RUN: touch %t/env/notreal-none-elf-gcc && chmod +x %t/env/notreal-none-elf-gcc
 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=ENV_PATH_NOTREAL_GCC %s
-// ENV_PATH_NOTREAL_GCC: env/notreal-none-elf-gcc
+// ENV_PATH_NOTREAL_GCC: env/notreal-none-elf-gcc"
 
 /// -gcc in program path is preferred to one on the PATH
 // RUN: touch %t/notreal-none-elf-gcc && chmod +x %t/notreal-none-elf-gcc
 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=BOTH_NOTREAL_GCC %s
-// BOTH_NOTREAL_GCC: notreal-none-elf-gcc
-// BOTH_NOTREAL_GCC-NOT: env/notreal-none-elf-gcc
+// BOTH_NOTREAL_GCC: notreal-none-elf-gcc"
+// BOTH_NOTREAL_GCC-NOT: env/notreal-none-elf-gcc"
 
 /// On program path, -gcc is preferred to plain gcc
 // RUN: touch %t/gcc && chmod +x %t/gcc
 // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=NOTREAL_GCC_PREFERRED %s
-// NOTREAL_GCC_PREFERRED: notreal-none-elf-gcc
-// NOTREAL_GCC_PREFERRED-NOT: /gcc
+// NOTREAL_GCC_PREFERRED: notreal-none-elf-gcc"
+// NOTREAL_GCC_PREFERRED-NOT: /gcc"
 
 /// -gcc on the PATH is preferred to gcc in program path
 // RUN: rm %t/notreal-none-elf-gcc
 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=NOTREAL_PATH_OVER_GCC_PROG %s
-// NOTREAL_PATH_OVER_GCC_PROG: env/notreal-none-elf-gcc
-// NOTREAL_PATH_OVER_GCC_PROG-NOT: /gcc
+// NOTREAL_PATH_OVER_GCC_PROG: env/notreal-none-elf-gcc"
+// NOTREAL_PATH_OVER_GCC_PROG-NOT: /gcc"
 
 /// -gcc on the PATH is preferred to gcc on the PATH
 // RUN: rm %t/gcc
 // RUN: touch %t/env/gcc && chmod +x %t/env/gcc
 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=NOTREAL_PATH_OVER_GCC_PATH %s
-// NOTREAL_PATH_OVER_GCC_PATH: env/notreal-none-elf-gcc
-// NOTREAL_PATH_OVER_GCC_PATH-NOT: /gcc
+// NOTREAL_PATH_OVER_GCC_PATH: env/notreal-none-elf-gcc"
+// NOTREAL_PATH_OVER_GCC_PATH-NOT: /gcc"
+
+/// We cannot trust clang --version, or cmake's LLVM_DEFAULT_TARGET_TRIPLE
+/// to give us the one and only default triple.
+/// Can't trust cmake because on Darwin, triples have a verison appended to them.
+/// (and clang uses the versioned string to search)
+/// Can't trust --version because it will pad 3 item triples to 4 e.g.
+/// powerpc64le-linux-gn

[clang] fe59122 - [clang][Driver] Fix tool path priority test failures

2020-07-15 Thread David Spickett via cfe-commits

Author: David Spickett
Date: 2020-07-15T09:37:09+01:00
New Revision: fe5912249efa1ec5e6aa6e565f722dd4d33d1e54

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

LOG: [clang][Driver] Fix tool path priority test failures

Summary:
Failure type 1:
This test can fail when the path of the build includes the strings
we're checking for. E.g "/gcc" is found in ".../gcc_7.3.0/..."

To correct this look for '"' on the end of all matches. So that we
only match the end of paths printed by clang -###.
(which would be ".../gcc_7.3.0/.../gcc" for the example)

Also look for other gcc names like gcc-x.y.z in the first check.
This confirms that the copy of clang we made is isolated as expected.

Failure type 2:
If you use a triple like "powerpc64le-linux-gnu" clang actually reports
"powerpc64le-unknown-linux-gnu". Then it searches for the
former.

That combined with Mac OS adding a version number to cmake's triple
means we can't trust cmake or clang to give us the one default triple.
To fix the test, write to both names. As they don't overlap with our
fake triple, we're still showing that the lookup works.

Reviewers: MaskRay, stevewan

Reviewed By: stevewan

Subscribers: miyuki, JDevlieghere, steven.zhang, stevewan, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/test/Driver/program-path-priority.c
clang/test/lit.cfg.py

Removed: 




diff  --git a/clang/test/Driver/program-path-priority.c 
b/clang/test/Driver/program-path-priority.c
index ba893e7e2e2c..9f1109f530c6 100644
--- a/clang/test/Driver/program-path-priority.c
+++ b/clang/test/Driver/program-path-priority.c
@@ -13,6 +13,11 @@
 /// so only name priority is accounted for, unless we fail to find
 /// anything at all in the prefix.
 
+/// Note: All matches are expected to be at the end of file paths.
+/// So we match " on the end to account for build systems that
+/// put the name of the compiler in the build path.
+/// E.g. /build/gcc_X.Y.Z/0/...
+
 /// Symlink clang to a new dir which will be its
 /// "program path" for these tests
 // RUN: rm -rf %t && mkdir -p %t
@@ -21,14 +26,18 @@
 /// No gccs at all, nothing is found
 // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=NO_NOTREAL_GCC %s
-// NO_NOTREAL_GCC-NOT: notreal-none-elf-gcc
-// NO_NOTREAL_GCC-NOT: /gcc
+// NO_NOTREAL_GCC-NOT: notreal-none-elf-gcc"
+/// Some systems will have "gcc-x.y.z" so for this first check
+/// make sure we don't find "gcc" or "gcc-x.y.z". If we do find either
+/// then there is no point continuing as this copy of clang is not
+/// isolated as we expected.
+// NO_NOTREAL_GCC-NOT: {{/gcc[^/]*"}}
 
 /// -gcc in program path is found
 // RUN: touch %t/notreal-none-elf-gcc && chmod +x %t/notreal-none-elf-gcc
 // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=PROG_PATH_NOTREAL_GCC %s
-// PROG_PATH_NOTREAL_GCC: notreal-none-elf-gcc
+// PROG_PATH_NOTREAL_GCC: notreal-none-elf-gcc"
 
 /// -gcc on the PATH is found
 // RUN: mkdir -p %t/env
@@ -36,74 +45,89 @@
 // RUN: touch %t/env/notreal-none-elf-gcc && chmod +x 
%t/env/notreal-none-elf-gcc
 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=ENV_PATH_NOTREAL_GCC %s
-// ENV_PATH_NOTREAL_GCC: env/notreal-none-elf-gcc
+// ENV_PATH_NOTREAL_GCC: env/notreal-none-elf-gcc"
 
 /// -gcc in program path is preferred to one on the PATH
 // RUN: touch %t/notreal-none-elf-gcc && chmod +x %t/notreal-none-elf-gcc
 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=BOTH_NOTREAL_GCC %s
-// BOTH_NOTREAL_GCC: notreal-none-elf-gcc
-// BOTH_NOTREAL_GCC-NOT: env/notreal-none-elf-gcc
+// BOTH_NOTREAL_GCC: notreal-none-elf-gcc"
+// BOTH_NOTREAL_GCC-NOT: env/notreal-none-elf-gcc"
 
 /// On program path, -gcc is preferred to plain gcc
 // RUN: touch %t/gcc && chmod +x %t/gcc
 // RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=NOTREAL_GCC_PREFERRED %s
-// NOTREAL_GCC_PREFERRED: notreal-none-elf-gcc
-// NOTREAL_GCC_PREFERRED-NOT: /gcc
+// NOTREAL_GCC_PREFERRED: notreal-none-elf-gcc"
+// NOTREAL_GCC_PREFERRED-NOT: /gcc"
 
 /// -gcc on the PATH is preferred to gcc in program path
 // RUN: rm %t/notreal-none-elf-gcc
 // RUN: env "PATH=%t/env/" %t/clang -### -target notreal-none-elf %s 2>&1 | \
 // RUN:   FileCheck --check-prefix=NOTREAL_PATH_OVER_GCC_PROG %s
-// NOTREAL_PATH_OVER_GCC_PROG: env/notreal-none-elf-gcc
-// NOTREAL_PATH_OVER_GCC_PROG-NOT: /gcc
+// NOTREAL_PATH_OVER_GCC_PROG: env/notreal-none-elf-gcc"
+// NOTREAL_PATH_OVER_GCC_PROG-NOT: /gcc"
 
 /// -gcc on the PATH is preferred 

[PATCH] D71124: [RISCV] support clang driver to select cpu

2020-07-15 Thread Kuan Hsu Chen (Zakk) via Phabricator via cfe-commits
khchen updated this revision to Diff 278106.
khchen marked 8 inline comments as done.
khchen added a comment.

address @asb's comment. thanks.

Thanks for @lenary bug report.
I cannot reproduce the crash in local,
but I though the problem is cause by removing "Choose a default based on the 
triple" logic in `getRISCVABI`
The `MArch` value is "unknown" and there is no return value which can match any 
conditionin.
so I add it back and also update the "invalid arch name" test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71124

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/riscv-arch.c
  clang/test/Driver/riscv-cpus.c
  llvm/include/llvm/Support/RISCVTargetParser.def
  llvm/include/llvm/Support/TargetParser.h
  llvm/lib/Support/TargetParser.cpp
  llvm/lib/Target/RISCV/RISCV.td

Index: llvm/lib/Target/RISCV/RISCV.td
===
--- llvm/lib/Target/RISCV/RISCV.td
+++ llvm/lib/Target/RISCV/RISCV.td
@@ -215,6 +215,16 @@
 
 def : ProcessorModel<"rocket-rv64", Rocket64Model, [Feature64Bit]>;
 
+def : ProcessorModel<"sifive-e31", Rocket32Model, [FeatureStdExtM,
+   FeatureStdExtA,
+   FeatureStdExtC]>;
+
+def : ProcessorModel<"sifive-u54", Rocket64Model, [Feature64Bit,
+   FeatureStdExtM,
+   FeatureStdExtA,
+   FeatureStdExtF,
+   FeatureStdExtD,
+   FeatureStdExtC]>;
 
 //===--===//
 // Define the RISC-V target.
Index: llvm/lib/Support/TargetParser.cpp
===
--- llvm/lib/Support/TargetParser.cpp
+++ llvm/lib/Support/TargetParser.cpp
@@ -13,6 +13,7 @@
 
 #include "llvm/Support/ARMBuildAttributes.h"
 #include "llvm/Support/TargetParser.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Twine.h"
@@ -208,3 +209,64 @@
   default: return {0, 0, 0};
   }
 }
+
+namespace llvm {
+namespace RISCV {
+
+struct CPUInfo {
+  StringLiteral Name;
+  CPUKind Kind;
+  unsigned Features;
+  StringLiteral DefaultMarch;
+  bool Is64Bit() const { return (Features & FK_64BIT); }
+};
+
+constexpr CPUInfo RISCVCPUInfo[] = {
+#define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH)  \
+  {NAME, CK_##ENUM, FEATURES, DEFAULT_MARCH},
+#include "llvm/Support/RISCVTargetParser.def"
+};
+
+bool checkCPUKind(CPUKind Kind, bool IsRV64) {
+  if (Kind == CK_INVALID)
+return false;
+  return RISCVCPUInfo[static_cast(Kind)].Is64Bit() == IsRV64;
+}
+
+CPUKind parseCPUKind(StringRef CPU) {
+  return llvm::StringSwitch(CPU)
+#define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH) .Case(NAME, CK_##ENUM)
+#include "llvm/Support/RISCVTargetParser.def"
+  .Default(CK_INVALID);
+}
+
+StringRef getMArchFromMcpu(StringRef CPU) {
+  CPUKind Kind = parseCPUKind(CPU);
+  return RISCVCPUInfo[static_cast(Kind)].DefaultMarch;
+}
+
+void fillValidCPUArchList(SmallVectorImpl &Values, bool IsRV64) {
+  for (const auto &C : RISCVCPUInfo) {
+if (IsRV64 == C.Is64Bit())
+  Values.emplace_back(C.Name);
+  }
+}
+
+// Get all features except standard extension feature
+bool getCPUFeaturesExceptStdExt(CPUKind Kind,
+std::vector &Features) {
+  unsigned features = RISCVCPUInfo[static_cast(Kind)].Features;
+
+  if (features == FK_INVALID)
+return false;
+
+  if (features & FK_64BIT)
+Features.push_back("+64bit");
+  else
+Features.push_back("-64bit");
+
+  return true;
+}
+
+} // namespace RISCV
+} // namespace llvm
Index: llvm/include/llvm/Support/TargetParser.h
===
--- llvm/include/llvm/Support/TargetParser.h
+++ llvm/include/llvm/Support/TargetParser.h
@@ -130,6 +130,32 @@
 
 } // namespace AMDGPU
 
+namespace RISCV {
+
+enum CPUKind : unsigned {
+#define PROC(ENUM, NAME, FEATURES, DEFAULT_MARCH) CK_##ENUM,
+#include "RISCVTargetParser.def"
+};
+
+enum FeatureKind : unsigned {
+  FK_INVALID = 0,
+  FK_NONE = 1,
+  FK_STDEXTM = 1 << 2,
+  FK_STDEXTA = 1 << 3,
+  FK_STDEXTF = 1 << 4,
+  FK_STDEXTD = 1 << 5,
+  FK_STDEXTC = 1 << 6,
+  FK_64BIT = 1 << 7,
+};
+
+bool checkCPUKind(CPUKind kind, bool IsRV64);
+CPUKind parseCPUKind(StringRef CPU);
+StringRef getMArchFromMcpu(StringRef CPU);
+void fillValidCPUArchList(SmallVectorImpl &Values, bool IsRV64);
+bool getCPUFeaturesExceptStdExt(CPUKind kind, std::vector &Features);
+
+}

[PATCH] D83802: [clangd] Config: also propagate in sync (testing) mode

2020-07-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks, lgtm.




Comment at: clang-tools-extra/clangd/TUScheduler.cpp:1241
+  // Avoid null checks everywhere.
+  if (!Opts.ContextProvider)
+this->Opts.ContextProvider = [](llvm::StringRef) {

nit: braces


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83802



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


[clang] 5165b2b - AArch64+ARM: make LLVM consider system registers volatile.

2020-07-15 Thread Tim Northover via cfe-commits

Author: Tim Northover
Date: 2020-07-15T09:47:36+01:00
New Revision: 5165b2b5fd5fd62c5a34970be81c79231844804c

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

LOG: AArch64+ARM: make LLVM consider system registers volatile.

Some of the system registers readable on AArch64 and ARM platforms
return different values with each read (for example a timer counter),
these shouldn't be hoisted outside loops or otherwise interfered with,
but the normal @llvm.read_register intrinsic is only considered to read
memory.

This introduces a separate @llvm.read_volatile_register intrinsic and
maps all system-registers on ARM platforms to use it for the
__builtin_arm_rsr calls. Registers declared with asm("r9") or similar
are unaffected.

Added: 
llvm/test/Transforms/LICM/read-volatile-register.ll

Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/builtins-arm.c
clang/test/CodeGen/builtins-arm64.c
llvm/docs/LangRef.rst
llvm/include/llvm/IR/Intrinsics.td
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 35a93a7889f4..34f4f21746f7 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -6361,6 +6361,12 @@ Value *CodeGenFunction::GetValueForARMHint(unsigned 
BuiltinID) {
 llvm::ConstantInt::get(Int32Ty, Value));
 }
 
+enum SpecialRegisterAccessKind {
+  NormalRead,
+  VolatileRead,
+  Write,
+};
+
 // Generates the IR for the read/write special register builtin,
 // ValueType is the type of the value that is to be written or read,
 // RegisterType is the type of the register being written to or read from.
@@ -6368,7 +6374,7 @@ static Value *EmitSpecialRegisterBuiltin(CodeGenFunction 
&CGF,
  const CallExpr *E,
  llvm::Type *RegisterType,
  llvm::Type *ValueType,
- bool IsRead,
+ SpecialRegisterAccessKind AccessKind,
  StringRef SysReg = "") {
   // write and register intrinsics only support 32 and 64 bit operations.
   assert((RegisterType->isIntegerTy(32) || RegisterType->isIntegerTy(64))
@@ -6393,8 +6399,12 @@ static Value *EmitSpecialRegisterBuiltin(CodeGenFunction 
&CGF,
   assert(!(RegisterType->isIntegerTy(32) && ValueType->isIntegerTy(64))
 && "Can't fit 64-bit value in 32-bit register");
 
-  if (IsRead) {
-llvm::Function *F = CGM.getIntrinsic(llvm::Intrinsic::read_register, 
Types);
+  if (AccessKind != Write) {
+assert(AccesKind == NormalRead || AccessKind == VolatileRead);
+llvm::Function *F = CGM.getIntrinsic(
+AccessKind == VolatileRead ? llvm::Intrinsic::read_volatile_register
+   : llvm::Intrinsic::read_register,
+Types);
 llvm::Value *Call = Builder.CreateCall(F, Metadata);
 
 if (MixedTypes)
@@ -6773,9 +6783,11 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned 
BuiltinID,
   BuiltinID == ARM::BI__builtin_arm_wsr64 ||
   BuiltinID == ARM::BI__builtin_arm_wsrp) {
 
-bool IsRead = BuiltinID == ARM::BI__builtin_arm_rsr ||
-  BuiltinID == ARM::BI__builtin_arm_rsr64 ||
-  BuiltinID == ARM::BI__builtin_arm_rsrp;
+SpecialRegisterAccessKind AccessKind = Write;
+if (BuiltinID == ARM::BI__builtin_arm_rsr ||
+BuiltinID == ARM::BI__builtin_arm_rsr64 ||
+BuiltinID == ARM::BI__builtin_arm_rsrp)
+  AccessKind = VolatileRead;
 
 bool IsPointerBuiltin = BuiltinID == ARM::BI__builtin_arm_rsrp ||
 BuiltinID == ARM::BI__builtin_arm_wsrp;
@@ -6794,7 +6806,8 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned 
BuiltinID,
   ValueType = RegisterType = Int32Ty;
 }
 
-return EmitSpecialRegisterBuiltin(*this, E, RegisterType, ValueType, 
IsRead);
+return EmitSpecialRegisterBuiltin(*this, E, RegisterType, ValueType,
+  AccessKind);
   }
 
   // Deal with MVE builtins
@@ -8834,9 +8847,11 @@ Value *CodeGenFunction::EmitAArch64BuiltinExpr(unsigned 
BuiltinID,
   BuiltinID == AArch64::BI__builtin_arm_wsr64 ||
   BuiltinID == AArch64::BI__builtin_arm_wsrp) {
 
-bool IsRead = BuiltinID == AArch64::BI__builtin_arm_rsr ||
-  BuiltinID == AArch64::BI__builtin_arm_rsr64 ||
-  BuiltinID == AArch64::BI__builtin_arm_rsrp;
+SpecialRegisterAccessKind AccessKind = Write;
+if (BuiltinID == AArch64::BI__builtin_arm_rsr ||
+BuiltinID == AArch64::BI__built

[PATCH] D80911: AArch64+ARM: make LLVM consider system registers volatile to prevent unsound optimizations.

2020-07-15 Thread Tim Northover via Phabricator via cfe-commits
t.p.northover closed this revision.
t.p.northover added a comment.

Thanks. Pushed to master as 5165b2b5fd5 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80911



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


[PATCH] D83621: [clang][Tooling] Try to avoid file system access if there is no record for the file in compile_commads.json

2020-07-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a subscriber: chandlerc.
sammccall added a comment.

In D83621#2152618 , @ArcsinX wrote:

> In D83621#2151716 , @sammccall wrote:
>
> > In D83621#2146750 , @ArcsinX wrote:
> >
> > > > - don't scan for equivalences if the set of candidates exceeds some 
> > > > size threshold (10 or so)
> > > > - don't scan for equivalences if the node we'd scan under is the root
> > >
> > > After such fixes `JSONCompilationDatabase::getCompileCommands()` will 
> > > return other results than before in some cases.
> >
> >
> > Can you elaborate on this - do you think there are reasonable cases where 
> > it will give the wrong answer?
> >  I can certainly imagine cases where this changes behaviour, e.g. 
> > project/foo.cc is a symlink to project/bar.cc, compile_commands contains an 
> > entry for foo.cc, we query for bar.cc.
> >  But I don't think this was ever really intended to handle arbitrary 
> > symlinks that change the names of files, and I do think this is OK to break.
>
>
> If breaking `project/foo.cc <=> project/bar.cc` is OK, then could we also 
> break `some/path/here/foo.cc <=> some/other/path/bar.cc`?


Yes. We discussed offline a bit with @chandlerc who doesn't think identifying 
cases where symlinked files have different names was a motivating case or 
likely to be important.

> In that case we can just prevent `Comparator.equivalent(FileA,FileB)` calls 
> when `llvm::sys::path::filename(FileA) != llvm::sys::path::filename(FileB)`.

You can - but this is equivalent to not doing the `getAll()` path when the node 
is the root (i.e. when ConsumedLength == 0).
So I think `if (ConsumedLength == 0) return {}` around line 124 in 
FileMatchTrie with an appropriate comment would also do the trick, and avoid 
pointless traversal/copy/string comparisons (much cheaper than IO but not free).

> I tried this locally:
> 
> - it works fast.
> - does not break tests.
> - easy to add unit test for `FileMatchTrie`.
> 
>   What do you think?

+1, happy with this behavior.
I think we should try the implementation that skips the traversal first - it's 
no more code and should be a bit more efficient.
But either way works, really.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83621



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


[PATCH] D83120: [Analyzer][StreamChecker] Use BugType::SuppressOnSink at resource leak report.

2020-07-15 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 278110.
balazske added a comment.

Fixed commit message and added FIXME about bug report location problem.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83120

Files:
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
  clang/test/Analysis/stream.c


Index: clang/test/Analysis/stream.c
===
--- clang/test/Analysis/stream.c
+++ clang/test/Analysis/stream.c
@@ -278,7 +278,9 @@
   if (!F1)
 return;
   if (Test == 1) {
-return; // expected-warning {{Opened stream never closed. Potential 
resource leak}}
+return; // no warning
   }
   rewind(F1);
-} // no warning
+} // expected-warning {{Opened stream never closed. Potential resource leak}}
+// FIXME: This warning should be placed at the `return` above.
+// See https://reviews.llvm.org/D83120 about details.
Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -204,7 +204,8 @@
   BugType BT_IllegalWhence{this, "Illegal whence argument",
"Stream handling error"};
   BugType BT_StreamEof{this, "Stream already in EOF", "Stream handling error"};
-  BugType BT_ResourceLeak{this, "Resource leak", "Stream handling error"};
+  BugType BT_ResourceLeak{this, "Resource leak", "Stream handling error",
+  /*SuppressOnSink =*/true};
 
 public:
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
@@ -965,11 +966,6 @@
 ExplodedNode *
 StreamChecker::reportLeaks(const SmallVector &LeakedSyms,
CheckerContext &C, ExplodedNode *Pred) const {
-  // Do not warn for non-closed stream at program exit.
-  // FIXME: Use BugType::SuppressOnSink instead.
-  if (Pred && Pred->getCFGBlock() && Pred->getCFGBlock()->hasNoReturnElement())
-return Pred;
-
   ExplodedNode *Err = C.generateNonFatalErrorNode(C.getState(), Pred);
   if (!Err)
 return Pred;


Index: clang/test/Analysis/stream.c
===
--- clang/test/Analysis/stream.c
+++ clang/test/Analysis/stream.c
@@ -278,7 +278,9 @@
   if (!F1)
 return;
   if (Test == 1) {
-return; // expected-warning {{Opened stream never closed. Potential resource leak}}
+return; // no warning
   }
   rewind(F1);
-} // no warning
+} // expected-warning {{Opened stream never closed. Potential resource leak}}
+// FIXME: This warning should be placed at the `return` above.
+// See https://reviews.llvm.org/D83120 about details.
Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -204,7 +204,8 @@
   BugType BT_IllegalWhence{this, "Illegal whence argument",
"Stream handling error"};
   BugType BT_StreamEof{this, "Stream already in EOF", "Stream handling error"};
-  BugType BT_ResourceLeak{this, "Resource leak", "Stream handling error"};
+  BugType BT_ResourceLeak{this, "Resource leak", "Stream handling error",
+  /*SuppressOnSink =*/true};
 
 public:
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
@@ -965,11 +966,6 @@
 ExplodedNode *
 StreamChecker::reportLeaks(const SmallVector &LeakedSyms,
CheckerContext &C, ExplodedNode *Pred) const {
-  // Do not warn for non-closed stream at program exit.
-  // FIXME: Use BugType::SuppressOnSink instead.
-  if (Pred && Pred->getCFGBlock() && Pred->getCFGBlock()->hasNoReturnElement())
-return Pred;
-
   ExplodedNode *Err = C.generateNonFatalErrorNode(C.getState(), Pred);
   if (!Err)
 return Pred;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 9697a9e - Fix typo in identifier in assert.

2020-07-15 Thread Tim Northover via cfe-commits

Author: Tim Northover
Date: 2020-07-15T09:57:53+01:00
New Revision: 9697a9e2d316f0d9d588f4de536b0a6bbef2810f

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

LOG: Fix typo in identifier in assert.

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 34f4f21746f7..8994b939093e 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -6400,7 +6400,7 @@ static Value *EmitSpecialRegisterBuiltin(CodeGenFunction 
&CGF,
 && "Can't fit 64-bit value in 32-bit register");
 
   if (AccessKind != Write) {
-assert(AccesKind == NormalRead || AccessKind == VolatileRead);
+assert(AccessKind == NormalRead || AccessKind == VolatileRead);
 llvm::Function *F = CGM.getIntrinsic(
 AccessKind == VolatileRead ? llvm::Intrinsic::read_volatile_register
: llvm::Intrinsic::read_register,



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


[clang-tools-extra] f782d9c - [clangd] Fix use-after-free in ArgStripper

2020-07-15 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-07-15T11:03:11+02:00
New Revision: f782d9c7002edaaf56c06a6cc1775f8f67713a29

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

LOG: [clangd] Fix use-after-free in ArgStripper

Added: 


Modified: 
clang-tools-extra/clangd/CompileCommands.h

Removed: 




diff  --git a/clang-tools-extra/clangd/CompileCommands.h 
b/clang-tools-extra/clangd/CompileCommands.h
index 84c4c2a26a87..3efd80026cf6 100644
--- a/clang-tools-extra/clangd/CompileCommands.h
+++ b/clang-tools-extra/clangd/CompileCommands.h
@@ -12,6 +12,7 @@
 #include "clang/Tooling/ArgumentsAdjusters.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "llvm/ADT/StringMap.h"
+#include 
 #include 
 #include 
 
@@ -92,7 +93,7 @@ class ArgStripper {
   const Rule *matchingRule(llvm::StringRef Arg, unsigned Mode,
unsigned &ArgCount) const;
   llvm::SmallVector Rules;
-  std::vector Storage; // Store strings not found in option table.
+  std::deque Storage; // Store strings not found in option table.
 };
 
 } // namespace clangd



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


[PATCH] D83695: Port Diagnostic option flags to new option parsing system

2020-07-15 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 278112.
dang added a comment.

Add back -pg option that was accidentaly removed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83695

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp

Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1632,16 +1632,11 @@
   if (Arg *A =
   Args.getLastArg(OPT_diagnostic_serialized_file, OPT__serialize_diags))
 Opts.DiagnosticSerializationFile = A->getValue();
-  Opts.IgnoreWarnings = Args.hasArg(OPT_w);
-  Opts.NoRewriteMacros = Args.hasArg(OPT_Wno_rewrite_macros);
-  Opts.Pedantic = Args.hasArg(OPT_pedantic);
-  Opts.PedanticErrors = Args.hasArg(OPT_pedantic_errors);
   Opts.ShowCarets = !Args.hasArg(OPT_fno_caret_diagnostics);
   Opts.ShowColors = parseShowColorsArgs(Args, DefaultDiagColor);
   Opts.ShowColumn = !Args.hasArg(OPT_fno_show_column);
   Opts.ShowFixits = !Args.hasArg(OPT_fno_diagnostics_fixit_info);
   Opts.ShowLocation = !Args.hasArg(OPT_fno_show_source_location);
-  Opts.AbsolutePath = Args.hasArg(OPT_fdiagnostics_absolute_paths);
   Opts.ShowOptionNames = !Args.hasArg(OPT_fno_diagnostics_show_option);
 
   // Default behavior is to not to show note include stacks.
@@ -1700,9 +1695,6 @@
   << Format;
   }
 
-  Opts.ShowSourceRanges = Args.hasArg(OPT_fdiagnostics_print_source_range_info);
-  Opts.ShowParseableFixits = Args.hasArg(OPT_fdiagnostics_parseable_fixits);
-  Opts.ShowPresumedLoc = !Args.hasArg(OPT_fno_diagnostics_use_presumed_location);
   Opts.VerifyDiagnostics = Args.hasArg(OPT_verify) || Args.hasArg(OPT_verify_EQ);
   Opts.VerifyPrefixes = Args.getAllArgValues(OPT_verify_EQ);
   if (Args.hasArg(OPT_verify))
@@ -1722,8 +1714,6 @@
   if (Args.hasArg(OPT_verify_ignore_unexpected))
 DiagMask = DiagnosticLevelMask::All;
   Opts.setVerifyIgnoreUnexpected(DiagMask);
-  Opts.ElideType = !Args.hasArg(OPT_fno_elide_type);
-  Opts.ShowTemplateTree = Args.hasArg(OPT_fdiagnostics_show_template_tree);
   Opts.ErrorLimit = getLastArgIntValue(Args, OPT_ferror_limit, 0, Diags);
   Opts.MacroBacktraceLimit =
   getLastArgIntValue(Args, OPT_fmacro_backtrace_limit,
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -417,6 +417,47 @@
 
 } // Flags = [CC1Option, NoDriverOption]
 
+// Diagnostic Options
+
+def fdiagnostics_parseable_fixits : Flag<["-"], "fdiagnostics-parseable-fixits">, Group,
+Flags<[CoreOption, CC1Option]>, HelpText<"Print fix-its in machine parseable form">,
+MarshallingInfoFlag<"DiagnosticOpts->ShowParseableFixits", "false">;
+def fansi_escape_codes : Flag<["-"], "fansi-escape-codes">, Group,
+  Flags<[CoreOption, CC1Option]>, HelpText<"Use ANSI escape codes for diagnostics">,
+  MarshallingInfoFlag<"DiagnosticOpts->UseANSIEscapeCodes", "false">;
+def fdiagnostics_print_source_range_info : Flag<["-"], "fdiagnostics-print-source-range-info">,
+Group,  Flags<[CC1Option]>,
+HelpText<"Print source range spans in numeric form">,
+MarshallingInfoFlag<"DiagnosticOpts->ShowSourceRanges", "false">;
+def fdiagnostics_show_template_tree : Flag<["-"], "fdiagnostics-show-template-tree">,
+Group, Flags<[CC1Option]>,
+HelpText<"Print a template comparison tree for differing templates">,
+MarshallingInfoFlag<"DiagnosticOpts->ShowTemplateTree", "false">;
+def fno_elide_type : Flag<["-"], "fno-elide-type">, Group,
+Flags<[CC1Option]>,
+HelpText<"Do not elide types when printing diagnostics">,
+MarshallingInfoFlag<"DiagnosticOpts->ElideType", "true">, IsNegative;
+def fdiagnostics_absolute_paths : Flag<["-"], "fdiagnostics-absolute-paths">, Group,
+  Flags<[CC1Option, CoreOption]>, HelpText<"Print absolute paths in diagnostics">,
+  MarshallingInfoFlag<"DiagnosticOpts->AbsolutePath", "false">;
+def pedantic_errors : Flag<["-", "--"], "pedantic-errors">, Group, Flags<[CC1Option]>,
+  MarshallingInfoFlag<"DiagnosticOpts->PedanticErrors", "false">;
+def pedantic : Flag<["-", "--"], "pedantic">, Group, Flags<[CC1Option]>,
+  MarshallingInfoFlag<"DiagnosticOpts->Pedantic", "false">;
+def w : Flag<["-"], "w">, HelpText<"Suppress all warnings">, Flags<[CC1Option]>,
+  MarshallingInfoFlag<"DiagnosticOpts->IgnoreWarnings", "false">;
+
+let Flags = [CC1Option, NoDriverOption] in {
+
+def fno_diagnostics_use_presumed_location : Flag<["-"], "fno-diagnostics-use-presumed-location">,
+  HelpText<"Ignore #line directives when displaying diagnostic locations">,
+  MarshallingInfoFlag<"DiagnosticOpts->ShowPresumedLoc", "true">, IsNegative;
+def Wno_rewrite_macros : Flag<["-"], "Wno-rewrite-macros">,
+  HelpText<"Silence ObjC rewriting warnings">,
+ 

[PATCH] D83717: [clang-tidy] Add check fo SEI CERT item ENV32-C

2020-07-15 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 278116.
gamesh411 marked 2 inline comments as done.
gamesh411 added a comment.

use move instead of copy
fix documentation issues
fix tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83717

Files:
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/clang-tidy/cert/CMakeLists.txt
  clang-tools-extra/clang-tidy/cert/ExitHandlerCheck.cpp
  clang-tools-extra/clang-tidy/cert/ExitHandlerCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-env32-c.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/cert-env32-c.c
  llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/cert/BUILD.gn

Index: llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/cert/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/cert/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/clang-tidy/cert/BUILD.gn
@@ -19,6 +19,7 @@
 "CommandProcessorCheck.cpp",
 "DefaultOperatorNewAlignmentCheck.cpp",
 "DontModifyStdNamespaceCheck.cpp",
+"ExitHandlerCheck.cpp",
 "FloatLoopCounter.cpp",
 "LimitedRandomnessCheck.cpp",
 "MutatingCopyCheck.cpp",
Index: clang-tools-extra/test/clang-tidy/checkers/cert-env32-c.c
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cert-env32-c.c
@@ -0,0 +1,324 @@
+// RUN: %check_clang_tidy %s cert-env32-c %t
+
+// --
+// EXIT FUNCTIONS
+// --
+
+// No handlers are invoked when _Exit is called.
+void _Exit(int __status);
+
+// Handlers registered by atexit are invoked in reverse order when exit is
+// called.
+void exit(int __status);
+
+// Handlers registered by at_quick_exit are invoked in reverse order when
+// quick_exit is called.
+void quick_exit(int __status);
+
+// 
+// HANDLER REGISTRATION
+// 
+
+// Register handlers to run when exit is called.
+int atexit(void (*__func)(void));
+
+// Register handlers to run when exit is called.
+int at_quick_exit(void (*__func)(void));
+
+// --
+// Setjmp/longjmp
+// --
+// C99 requires jmp_buf to be an array type.
+typedef int jmp_buf[1];
+int setjmp(jmp_buf);
+void longjmp(jmp_buf, int);
+
+// Compliant solutions
+
+void cleanup1() {
+  // do cleanup
+}
+
+void cleanup2() {
+  // do cleanup
+}
+
+void test_atexit_single_compliant() {
+  (void)atexit(cleanup1);
+}
+
+void test_atexit_multiple_compliant() {
+  (void)atexit(cleanup1);
+  (void)atexit(cleanup2);
+}
+
+void test_at_quick_exit_single_compliant() {
+  (void)at_quick_exit(cleanup1);
+}
+
+void test_at_quick_exit_multiple_compliant() {
+  (void)at_quick_exit(cleanup1);
+  (void)at_quick_exit(cleanup2);
+}
+
+// Non-compliant solutions calling _Exit
+
+void call__Exit() {
+  _Exit(0);
+}
+
+void call_call__Exit() {
+  call__Exit();
+}
+
+extern int unknown__Exit_flag;
+
+void call__Exit_conditionally() {
+  if (unknown__Exit_flag)
+call__Exit();
+}
+
+void call_call__Exit_conditionally() {
+  call__Exit_conditionally();
+}
+
+void test__Exit_called_directly() {
+  (void)atexit(call__Exit);
+  // CHECK-NOTES: :[[@LINE-1]]:9: warning: exit-handler potentially calls an exit function. Handlers should terminate by returning [cert-env32-c]
+  // CHECK-NOTES: :[[@LINE-22]]:1: note: handler function declared here
+  // CHECK-NOTES: :[[@LINE-22]]:3: note: exit function called here
+  (void)at_quick_exit(call__Exit);
+  // CHECK-NOTES: :[[@LINE-1]]:9: warning: exit-handler potentially calls an exit function. Handlers should terminate by returning [cert-env32-c]
+  // CHECK-NOTES: :[[@LINE-26]]:1: note: handler function declared here
+  // CHECK-NOTES: :[[@LINE-26]]:3: note: exit function called here
+};
+
+void test__Exit_called_indirectly() {
+  (void)atexit(call_call__Exit);
+  // CHECK-NOTES: :[[@LINE-1]]:9: warning: exit-handler potentially calls an exit function. Handlers should terminate by returning [cert-env32-c]
+  // CHECK-NOTES: :[[@LINE-29]]:1: note: handler function declared here
+  // CHECK-NOTES: :[[@LINE-33]]:3: note: exit function called here
+  (void)at_quick_exit(call_call__Exit);
+  // CHECK-NOTES: :[[@LINE-1]]:9: warning: exit-handler potentially calls an exit function. Handlers should terminate by returning [cert-env32-c]
+  // CHECK-NOTES: :[[@LINE-33]]:1: note: handler function declared here
+  // CHECK-NOTES: :[[@LINE-37]]:3: note: exit function called here
+};
+
+void test_conditional__Exit_called_directly() {
+  (void)atexit(call__Exit_conditionally);
+  // CHECK-NOTES: :[[@LINE-1]]:9: warning: exit-handler potentially calls an exit function. Handlers should terminate by returning [cert-env32-c]
+  // CHECK-NOTES: :[[@LINE-34]]:1: note: handler function declared here
+  // CHECK-NOTES: 

[PATCH] D79219: [CMake] Simplify CMake handling for zlib

2020-07-15 Thread Pavel Labath via Phabricator via cfe-commits
labath added a comment.

I wouldn't mind separate (internal) cache variable, though I am somewhat 
surprised by this problem. A (non-cache) variable set in one of the parent 
scopes should still take precedence over a cache variable with the same name. 
And since config-ix.cmake is included from the top CMakeLists.txt, the value it 
defines should be available everywhere. Was this a problem for the regular 
build, or only for some of the more exotic build setups that don't start with 
llvm/CMakeLists.txt ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79219



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


[PATCH] D83772: [Windows] Fix limit on command line size

2020-07-15 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 278117.
sepavloff added a comment.

Addressed reviewer's notes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83772

Files:
  llvm/include/llvm/Support/Program.h
  llvm/lib/Support/Windows/Program.inc
  llvm/unittests/Support/CommandLineTest.cpp

Index: llvm/unittests/Support/CommandLineTest.cpp
===
--- llvm/unittests/Support/CommandLineTest.cpp
+++ llvm/unittests/Support/CommandLineTest.cpp
@@ -763,6 +763,17 @@
 TEST(CommandLineTest, ArgumentLimit) {
   std::string args(32 * 4096, 'a');
   EXPECT_FALSE(llvm::sys::commandLineFitsWithinSystemLimits("cl", args.data()));
+  std::string args2(256, 'a');
+  EXPECT_TRUE(llvm::sys::commandLineFitsWithinSystemLimits("cl", args.data()));
+  if (Triple(sys::getProcessTriple()).isOSWindows()) {
+// We use 32000 as a limit for command line length.
+std::string long_arg(32000, 'b');
+EXPECT_TRUE(
+llvm::sys::commandLineFitsWithinSystemLimits("cl", long_arg.data()));
+long_arg += 'b';
+EXPECT_FALSE(
+llvm::sys::commandLineFitsWithinSystemLimits("cl", long_arg.data()));
+  }
 }
 
 TEST(CommandLineTest, ResponseFileWindows) {
Index: llvm/lib/Support/Windows/Program.inc
===
--- llvm/lib/Support/Windows/Program.inc
+++ llvm/lib/Support/Windows/Program.inc
@@ -189,7 +189,14 @@
   // Windows wants a command line, not an array of args, to pass to the new
   // process.  We have to concatenate them all, while quoting the args that
   // have embedded spaces (or are empty).
-  std::string Command = flattenWindowsCommandLine(Args);
+  auto Result = flattenWindowsCommandLine(Args);
+  if (std::error_code ec = Result.getError()) {
+SetLastError(ec.value());
+MakeErrMsg(ErrMsg,
+   std::string("Unable to convert command-line to UTF-16"));
+return false;
+  }
+  std::wstring Command = *Result;
 
   // The pointer to the environment block for the new process.
   std::vector EnvBlock;
@@ -271,14 +278,8 @@
 return false;
   }
 
-  SmallVector CommandUtf16;
-  if (std::error_code ec = windows::UTF8ToUTF16(Command, CommandUtf16)) {
-SetLastError(ec.value());
-MakeErrMsg(ErrMsg,
-   std::string("Unable to convert command-line to UTF-16"));
-return false;
-  }
-
+  std::vector CommandUtf16(Command.size() + 1, 0);
+  std::copy(Command.begin(), Command.end(), CommandUtf16.begin());
   BOOL rc = CreateProcessW(ProgramUtf16.data(), CommandUtf16.data(), 0, 0,
TRUE, CREATE_UNICODE_ENVIRONMENT,
EnvBlock.empty() ? 0 : EnvBlock.data(), 0, &si,
@@ -376,7 +377,7 @@
 }
 
 namespace llvm {
-std::string sys::flattenWindowsCommandLine(ArrayRef Args) {
+ErrorOr sys::flattenWindowsCommandLine(ArrayRef Args) {
   std::string Command;
   for (StringRef Arg : Args) {
 if (argNeedsQuotes(Arg))
@@ -387,7 +388,11 @@
 Command.push_back(' ');
   }
 
-  return Command;
+  SmallVector CommandUtf16;
+  if (std::error_code ec = windows::UTF8ToUTF16(Command, CommandUtf16))
+return ec;
+
+  return std::wstring(CommandUtf16.begin(), CommandUtf16.end());
 }
 
 ProcessInfo sys::Wait(const ProcessInfo &PI, unsigned SecondsToWait,
@@ -532,12 +537,16 @@
 
 bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program,
   ArrayRef Args) {
-  // The documented max length of the command line passed to CreateProcess.
-  static const size_t MaxCommandStringLength = 32768;
+  // The documentation on CreateProcessW states that the size of the argument
+  // lpCommandLine must not be greater than 32767 characters, including the
+  // Unicode terminating null character. We use smaller value to reduce risk
+  // of getting invalid command line due to unaccounted factors.
+  static const size_t MaxCommandStringLength = 32000;
   SmallVector FullArgs;
   FullArgs.push_back(Program);
   FullArgs.append(Args.begin(), Args.end());
-  std::string Result = flattenWindowsCommandLine(FullArgs);
-  return (Result.size() + 1) <= MaxCommandStringLength;
+  auto Result = flattenWindowsCommandLine(FullArgs);
+  assert(!Result.getError());
+  return (Result->size() + 1) <= MaxCommandStringLength;
 }
 }
Index: llvm/include/llvm/Support/Program.h
===
--- llvm/include/llvm/Support/Program.h
+++ llvm/include/llvm/Support/Program.h
@@ -218,7 +218,7 @@
   /// to build a single flat command line appropriate for calling CreateProcess
   /// on
   /// Windows.
-  std::string flattenWindowsCommandLine(ArrayRef Args);
+  ErrorOr flattenWindowsCommandLine(ArrayRef Args);
 #endif
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83717: [clang-tidy] Add check fo SEI CERT item ENV32-C

2020-07-15 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 marked 12 inline comments as done.
gamesh411 added inline comments.



Comment at: clang-tools-extra/clang-tidy/cert/ExitHandlerCheck.cpp:132
+   "terminate by returning");
+  break;
+}

steakhal wrote:
> Why don't we `return` here?
> Same for the next `break`.
I use `break`, because it is more local to the concept of finishing the loop 
(ie the visitation algorithm), and that is what I want the reader of the code 
to receive after reading the line. In this particular case, `return` is 
equivalent to break but I would still keep it this way, because that is what I 
want to say, and if someone were to extend the code later, that early `return` 
inside the loop could surprise them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83717



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


[PATCH] D83772: [Windows] Fix limit on command line size

2020-07-15 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

Thank you for your detailed feedback!

> Round down to 32,000 to leave us wiggle room.

As there is no requirement to use response files as rarely as possible, the 
choice of the limit is an implementation detail. Having some wiggle room is a 
good idea in this case.

> Have flattenWindowsCommandLine return a wstring rather than a string. This 
> will reduce the chance of the proxy string we measure differing from the 
> actual command string we're issuing, and it's already a Windows-specific 
> function.

Agree, this is more robust solution.

> Add a short command to the test for commandLineFitsWithinSystemLimits.

Now the patch is more than a change of a constant, so a test is necessary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83772



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


[PATCH] D83717: [clang-tidy] Add check fo SEI CERT item ENV32-C

2020-07-15 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 marked an inline comment as done.
gamesh411 added a comment.

In D83717#2150977 , @njames93 wrote:

> Alternatively you could do something like this, though it would be a pain 
> https://github.com/llvm/llvm-project/blob/master/clang-tools-extra/test/clang-tidy/checkers/bugprone-argument-comment-gmock.cpp#L86


I have bitten the bullet, and have gone down this route. With relative 
numbering, the sections themselves are at least translation-invariant. Not the 
prettiest sight, tho.
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83717



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


[PATCH] D83717: [clang-tidy] Add check fo SEI CERT item ENV32-C

2020-07-15 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 added a comment.

@steakhal @Eugene.Zelenko Thanks for checking this patch! I have tried my best 
to adhere to your suggestions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83717



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


[clang] c872e80 - [Matrix] Only pass vector arg as overloaded type in MatrixBuilder.

2020-07-15 Thread Florian Hahn via cfe-commits

Author: Florian Hahn
Date: 2020-07-15T10:42:24+01:00
New Revision: c872e809d1ac4aa405ae510e271f93d7662e26dd

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

LOG: [Matrix] Only pass vector arg as overloaded type in MatrixBuilder.

In 2b3c505, the pointer arguments for the matrix load and store
intrinsics was changed to always be the element type of the vector
argument.

This patch updates the MatrixBuilder to not add the pointer type to the
overloaded types and adjusts the clang/mlir tests.

This should fix a few build failures on GreenDragon, including
 
http://green.lab.llvm.org/green/job/test-suite-verify-machineinstrs-x86_64-O0-g/7891/

Added: 


Modified: 
clang/test/CodeGen/matrix-type-builtins.c
clang/test/CodeGenCXX/matrix-type-builtins.cpp
clang/test/CodeGenObjC/matrix-type-builtins.m
llvm/include/llvm/IR/MatrixBuilder.h
mlir/test/Target/llvmir-intrinsics.mlir

Removed: 




diff  --git a/clang/test/CodeGen/matrix-type-builtins.c 
b/clang/test/CodeGen/matrix-type-builtins.c
index 58fde6f01cc3..f7e9587def60 100644
--- a/clang/test/CodeGen/matrix-type-builtins.c
+++ b/clang/test/CodeGen/matrix-type-builtins.c
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -fenable-matrix -triple x86_64-apple-darwin %s -emit-llvm 
-disable-llvm-passes -o - | FileCheck %s
 
+// Also check we do not crash when running some middle-end passes. Most
+// importantly this includes the IR verifier, to ensure we emit valid IR.
+// RUN: %clang_cc1 -fenable-matrix -emit-llvm -triple x86_64-apple-darwin %s 
-o %t
+
 // Tests for the matrix type builtins.
 
 typedef double dx5x5_t __attribute__((matrix_type(5, 5)));
@@ -100,7 +104,7 @@ void transpose_global() {
 void column_major_load_with_const_stride_double(double *Ptr) {
   // CHECK-LABEL: define void 
@column_major_load_with_const_stride_double(double* %Ptr)
   // CHECK: [[PTR:%.*]] = load double*, double** %Ptr.addr, align 8
-  // CHECK-NEXT:call <25 x double> 
@llvm.matrix.column.major.load.v25f64.p0f64(double* align 8 [[PTR]], i64 5, i1 
false, i32 5, i32 5)
+  // CHECK-NEXT:call <25 x double> 
@llvm.matrix.column.major.load.v25f64(double* align 8 [[PTR]], i64 5, i1 false, 
i32 5, i32 5)
 
   dx5x5_t m_a1 = __builtin_matrix_column_major_load(Ptr, 5, 5, 5);
 }
@@ -108,7 +112,7 @@ void column_major_load_with_const_stride_double(double 
*Ptr) {
 void column_major_load_with_const_stride2_double(double *Ptr) {
   // CHECK-LABEL: define void 
@column_major_load_with_const_stride2_double(double* %Ptr)
   // CHECK: [[PTR:%.*]] = load double*, double** %Ptr.addr, align 8
-  // CHECK-NEXT:call <25 x double> 
@llvm.matrix.column.major.load.v25f64.p0f64(double* align 8 [[PTR]], i64 15, i1 
false, i32 5, i32 5)
+  // CHECK-NEXT:call <25 x double> 
@llvm.matrix.column.major.load.v25f64(double* align 8 [[PTR]], i64 15, i1 
false, i32 5, i32 5)
 
   dx5x5_t m_a2 = __builtin_matrix_column_major_load(Ptr, 5, 5, 2 * 3 + 9);
 }
@@ -117,7 +121,7 @@ void column_major_load_with_variable_stride_ull_float(float 
*Ptr, unsigned long
   // CHECK-LABEL: define void 
@column_major_load_with_variable_stride_ull_float(float* %Ptr, i64 %S)
   // CHECK: [[S:%.*]] = load i64, i64* %S.addr, align 8
   // CHECK-NEXT:[[PTR:%.*]] = load float*, float** %Ptr.addr, align 8
-  // CHECK-NEXT:call <6 x float> 
@llvm.matrix.column.major.load.v6f32.p0f32(float* align 4 [[PTR]], i64 [[S]], 
i1 false, i32 2, i32 3)
+  // CHECK-NEXT:call <6 x float> 
@llvm.matrix.column.major.load.v6f32(float* align 4 [[PTR]], i64 [[S]], i1 
false, i32 2, i32 3)
 
   fx2x3_t m_b = __builtin_matrix_column_major_load(Ptr, 2, 3, S);
 }
@@ -128,7 +132,7 @@ void column_major_load_with_stride_math_int(int *Ptr, int 
S) {
   // CHECK-NEXT:[[STRIDE:%.*]] = add nsw i32 [[S]], 32
   // CHECK-NEXT:[[STRIDE_EXT:%.*]] = sext i32 [[STRIDE]] to i64
   // CHECK-NEXT:[[PTR:%.*]] = load i32*, i32** %Ptr.addr, align 8
-  // CHECK-NEXT:call <80 x i32> 
@llvm.matrix.column.major.load.v80i32.p0i32(i32* align 4 [[PTR]], i64 
[[STRIDE_EXT]], i1 false, i32 4, i32 20)
+  // CHECK-NEXT:call <80 x i32> @llvm.matrix.column.major.load.v80i32(i32* 
align 4 [[PTR]], i64 [[STRIDE_EXT]], i1 false, i32 4, i32 20)
 
   ix4x20_t m_c = __builtin_matrix_column_major_load(Ptr, 4, 20, S + 32);
 }
@@ -140,7 +144,7 @@ void column_major_load_with_stride_math_s_int(int *Ptr, 
short S) {
   // CHECK-NEXT:[[STRIDE:%.*]] = add nsw i32 [[S_EXT]], 32
   // CHECK-NEXT:[[STRIDE_EXT:%.*]] = sext i32 [[STRIDE]] to i64
   // CHECK-NEXT:[[PTR:%.*]] = load i32*, i32** %Ptr.addr, align 8
-  // CHECK-NEXT:%matrix = call <80 x i32> 
@llvm.matrix.column.major.load.v80i32.p0i32(i32* align 4 [[PTR]], i64 
[[STRIDE_EXT]], i1 false, i32 4, i32 20)
+  // CHECK-NEXT:%matrix = ca

[clang-tools-extra] 7ab7b97 - Bump the trunk major version to 12

2020-07-15 Thread Hans Wennborg via cfe-commits

Author: Hans Wennborg
Date: 2020-07-15T12:05:05+02:00
New Revision: 7ab7b979d29e1e43701cf690f5cf1903740f50e3

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

LOG: Bump the trunk major version to 12

and clear the release notes.

Added: 


Modified: 
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/conf.py
clang/docs/ReleaseNotes.rst
clang/docs/analyzer/conf.py
clang/docs/conf.py
libcxx/CMakeLists.txt
libcxx/docs/ReleaseNotes.rst
libcxx/docs/conf.py
libcxx/include/__config
libcxx/include/__libcpp_version
libunwind/CMakeLists.txt
libunwind/docs/conf.py
lld/docs/ReleaseNotes.rst
lld/docs/conf.py
llvm/CMakeLists.txt
llvm/docs/ReleaseNotes.rst
llvm/utils/gn/secondary/llvm/version.gni
llvm/utils/lit/lit/__init__.py
llvm/utils/release/build_llvm_package.bat
polly/docs/ReleaseNotes.rst
polly/docs/conf.py
pstl/docs/ReleaseNotes.rst
pstl/include/pstl/internal/pstl_config.h
pstl/test/pstl/version.pass.cpp

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index c08fd45c2f96..1d447938eae0 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -1,5 +1,5 @@
 
-Extra Clang Tools 11.0.0 (In-Progress) Release Notes
+Extra Clang Tools 12.0.0 (In-Progress) Release Notes
 
 
 .. contents::
@@ -10,7 +10,7 @@ Written by the `LLVM Team `_
 
 .. warning::
 
-   These are in-progress notes for the upcoming Extra Clang Tools 11 release.
+   These are in-progress notes for the upcoming Extra Clang Tools 12 release.
Release notes for previous releases can be found on
`the Download Page `_.
 
@@ -18,7 +18,7 @@ Introduction
 
 
 This document contains the release notes for the Extra Clang Tools, part of the
-Clang release 11.0.0. Here we describe the status of the Extra Clang Tools in
+Clang release 12.0.0. Here we describe the status of the Extra Clang Tools in
 some detail, including major improvements from the previous release and new
 feature work. All LLVM releases may be downloaded from the `LLVM releases web
 site `_.
@@ -32,7 +32,7 @@ main Clang web page, this document applies to the *next* 
release, not
 the current one. To see the release notes for a specific release, please
 see the `releases page `_.
 
-What's New in Extra Clang Tools 11.0.0?
+What's New in Extra Clang Tools 12.0.0?
 ===
 
 Some of the major new features and improvements to Extra Clang Tools are listed
@@ -67,187 +67,7 @@ The improvements are...
 Improvements to clang-tidy
 --
 
-New module
-^^
-- New module `llvmlibc`.
-
-  This module contains checks related to the LLVM-libc coding standards.
-
-New checks
-^^
-
-- New :doc:`abseil-string-find-str-contains
-  ` check.
-
-  Finds ``s.find(...) == string::npos`` comparisons (for various string-like 
types)
-  and suggests replacing with ``absl::StrContains()``.
-
-- New :doc:`cppcoreguidelines-avoid-non-const-global-variables
-  ` 
check.
-  Finds non-const global variables as described in check I.2 of C++ Core
-  Guidelines.
-
-- New :doc:`bugprone-misplaced-pointer-arithmetic-in-alloc
-  ` check.
-
-  Finds cases where an integer expression is added to or subtracted from the
-  result of a memory allocation function (``malloc()``, ``calloc()``,
-  ``realloc()``, ``alloca()``) instead of its argument.
-
-- New :doc:`bugprone-no-escape
-  ` check.
-
-  Finds pointers with the ``noescape`` attribute that are captured by an
-  asynchronously-executed block.
-
-- New :doc:`bugprone-spuriously-wake-up-functions
-  ` check.
-
-  Finds ``cnd_wait``, ``cnd_timedwait``, ``wait``, ``wait_for``, or
-  ``wait_until`` function calls when the function is not invoked from a loop
-  that checks whether a condition predicate holds or the function has a
-  condition parameter.
-
-- New :doc:`bugprone-reserved-identifier
-  ` check.
-
-  Checks for usages of identifiers reserved for use by the implementation.
-
-- New :doc:`bugprone-suspicious-include
-  ` check.
-
-  Finds cases where an include refers to what appears to be an implementation
-  file, which often leads to hard-to-track-down ODR violations, and diagnoses
-  them.
-
-- New :doc:`cert-oop57-cpp
-  ` check.
-
-  Flags use of the `C` standard library functions ``memset``, ``memcpy`` and
-  ``memcmp`` and similar derivatives on non-trivial types.
-
-- New :doc:`llvmlibc-callee-namespace
-  ` check.
-
-  Checks all 

[PATCH] D82381: [analyzer] Introduce small improvements to the solver infra

2020-07-15 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:734
   //expressions which we currently do not know how to negate.
-  const RangeSet *getRangeForMinusSymbol(ProgramStateRef State, SymbolRef Sym) 
{
+  Optional getRangeForInvertedSub(SymbolRef Sym) {
 if (const SymSymExpr *SSE = dyn_cast(Sym)) {

NoQ wrote:
> vsavchenko wrote:
> > ASDenysPetrov wrote:
> > > vsavchenko wrote:
> > > > ASDenysPetrov wrote:
> > > > > As for me, I'd call this like `getRangeForNegatedSymSymExpr`, since 
> > > > > you do Negate operation inside.
> > > > I'm not super happy about my name either, but I feel like it describes 
> > > > it better than the previous name and your version.  That function 
> > > > doesn't work for any `SymSymExpr` and it doesn't simply negate whatever 
> > > > we gave it.  It works specifically for symbolic subtractions and this 
> > > > is the information I want to be reflected in the name.
> > > Oh, I just assumed //...Sub// at the end as a //subexpression// but you 
> > > mean //subtraction//. What I'm trying to say is that we can rename it 
> > > like `getRangeFor...`//the expression which this function can handle//. 
> > > E.g. `getRangeForNegatedSubtractionSymSymExpr`. My point is in a speaking 
> > > name.
> > > 
> > > I think //invertion// is not something appropriate in terms of applying 
> > > minus operator. I think invertion of zero should be something opposite 
> > > but not a zero. Because when you would like to implement the function 
> > > which turns [A, B] into [MIN, A)U(B, MAX], what would be the name of it? 
> > > I think this is an //invertion//.
> > > 
> > > But this is not a big deal, it's just my thoughts.
> > My thought process here was that we are trying to get range for `A - B` and 
> > there is also information on `B - A`, so we can get something for `A - B` 
> > based on that.  So, it doesn't really matter what it does under the hood 
> > with ranges, it matters what its semantics are.  Here I called `B - A` //an 
> > inverted subtraction//.
> > I don't really know what would be the best name, but I thought that this 
> > one makes more sense.
> > Because when you would like to implement the function which turns [A, B] 
> > into [MIN, A)U(B, MAX], what would be the name of it? I think this is an 
> > //invertion//.
> 
> https://en.wikipedia.org/wiki/Complement_(set_theory)
> https://en.wikipedia.org/wiki/Inverse_function
> 
> "Negated subtraction" is definitely my favorite so far. "Mirrored" might be a 
> good layman term as well.
>https://en.wikipedia.org/wiki/Complement_(set_theory)
>https://en.wikipedia.org/wiki/Inverse_function
Thanks for the links, @NoQ. That's much definite now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82381



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


[PATCH] D77062: [analyzer] Improved zero assumption in CStringChecke::assumeZero

2020-07-15 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

One more :-)


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

https://reviews.llvm.org/D77062



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


[clang] 22a084c - [Analyzer] Report every bug if only uniqueing location differs.

2020-07-15 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2020-07-15T12:19:25+02:00
New Revision: 22a084cfa337d5e5ea90eba5261f7937e28d250b

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

LOG: [Analyzer] Report every bug if only uniqueing location differs.

Summary:
Two CSA bug reports where only the uniqueing location is different
should be treated as different problems. The role of uniqueing location
is to differentiate bug reports.

Reviewers: Szelethus, baloghadamsoftware, NoQ, vsavchenko, xazax.hun, martong

Reviewed By: NoQ

Subscribers: NoQ, rnkovacs, xazax.hun, baloghadamsoftware, szepet, a.sidorin, 
mikhail.ramalho, Szelethus, donat.nagy, dkrupp, gamesh411, Charusso, martong, 
ASDenysPetrov, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/Analysis/PathDiagnostic.cpp
clang/test/Analysis/malloc.c
clang/test/Analysis/pr22954.c

Removed: 




diff  --git a/clang/lib/Analysis/PathDiagnostic.cpp 
b/clang/lib/Analysis/PathDiagnostic.cpp
index c88e6c1e1535..9aa3386129d7 100644
--- a/clang/lib/Analysis/PathDiagnostic.cpp
+++ b/clang/lib/Analysis/PathDiagnostic.cpp
@@ -327,6 +327,10 @@ static Optional comparePath(const PathPieces &X, 
const PathPieces &Y) {
 }
 
 static bool compareCrossTUSourceLocs(FullSourceLoc XL, FullSourceLoc YL) {
+  if (XL.isInvalid() && YL.isValid())
+return true;
+  if (XL.isValid() && YL.isInvalid())
+return false;
   std::pair XOffs = XL.getDecomposedLoc();
   std::pair YOffs = YL.getDecomposedLoc();
   const SourceManager &SM = XL.getManager();
@@ -349,6 +353,10 @@ static bool compare(const PathDiagnostic &X, const 
PathDiagnostic &Y) {
   FullSourceLoc YL = Y.getLocation().asLocation();
   if (XL != YL)
 return compareCrossTUSourceLocs(XL, YL);
+  FullSourceLoc XUL = X.getUniqueingLoc().asLocation();
+  FullSourceLoc YUL = Y.getUniqueingLoc().asLocation();
+  if (XUL != YUL)
+return compareCrossTUSourceLocs(XUL, YUL);
   if (X.getBugType() != Y.getBugType())
 return X.getBugType() < Y.getBugType();
   if (X.getCategory() != Y.getCategory())
@@ -357,20 +365,27 @@ static bool compare(const PathDiagnostic &X, const 
PathDiagnostic &Y) {
 return X.getVerboseDescription() < Y.getVerboseDescription();
   if (X.getShortDescription() != Y.getShortDescription())
 return X.getShortDescription() < Y.getShortDescription();
-  if (X.getDeclWithIssue() != Y.getDeclWithIssue()) {
-const Decl *XD = X.getDeclWithIssue();
-if (!XD)
+  auto CompareDecls = [&XL](const Decl *D1, const Decl *D2) -> Optional {
+if (D1 == D2)
+  return None;
+if (!D1)
   return true;
-const Decl *YD = Y.getDeclWithIssue();
-if (!YD)
+if (!D2)
   return false;
-SourceLocation XDL = XD->getLocation();
-SourceLocation YDL = YD->getLocation();
-if (XDL != YDL) {
+SourceLocation D1L = D1->getLocation();
+SourceLocation D2L = D2->getLocation();
+if (D1L != D2L) {
   const SourceManager &SM = XL.getManager();
-  return compareCrossTUSourceLocs(FullSourceLoc(XDL, SM),
-  FullSourceLoc(YDL, SM));
+  return compareCrossTUSourceLocs(FullSourceLoc(D1L, SM),
+  FullSourceLoc(D2L, SM));
 }
+return None;
+  };
+  if (auto Result = CompareDecls(X.getDeclWithIssue(), Y.getDeclWithIssue()))
+return *Result;
+  if (XUL.isValid()) {
+if (auto Result = CompareDecls(X.getUniqueingDecl(), Y.getUniqueingDecl()))
+  return *Result;
   }
   PathDiagnostic::meta_iterator XI = X.meta_begin(), XE = X.meta_end();
   PathDiagnostic::meta_iterator YI = Y.meta_begin(), YE = Y.meta_end();
@@ -1118,6 +1133,8 @@ void 
PathDiagnosticPopUpPiece::Profile(llvm::FoldingSetNodeID &ID) const {
 
 void PathDiagnostic::Profile(llvm::FoldingSetNodeID &ID) const {
   ID.Add(getLocation());
+  ID.Add(getUniqueingLoc());
+  ID.AddPointer(getUniqueingLoc().isValid() ? getUniqueingDecl() : nullptr);
   ID.AddString(BugType);
   ID.AddString(VerboseDesc);
   ID.AddString(Category);

diff  --git a/clang/test/Analysis/malloc.c b/clang/test/Analysis/malloc.c
index 714c73c3c793..a26b51196781 100644
--- a/clang/test/Analysis/malloc.c
+++ b/clang/test/Analysis/malloc.c
@@ -791,7 +791,8 @@ void mallocEscapeMalloc() {
 void mallocMalloc() {
   int *p = malloc(12);
   p = malloc(12);
-} // expected-warning {{Potential leak of memory pointed to by}}
+} // expected-warning {{Potential leak of memory pointed to by}}\
+  // expected-warning {{Potential leak of memory pointed to by}}
 
 void mallocFreeMalloc() {
   int *p = malloc(12);

diff  --git a/clang/test/Analysis/pr22954.c b/clang/test/Analysis/pr22954.c
index e88acdc29d39..093f6311a505 100644
--- a/clang/test/Analysis/pr22954.c
+++ b/clang/test/Analysis/pr22954.

[PATCH] D83115: [Analyzer] Report every bug if only uniqueing location differs.

2020-07-15 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG22a084cfa337: [Analyzer] Report every bug if only uniqueing 
location differs. (authored by balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83115

Files:
  clang/lib/Analysis/PathDiagnostic.cpp
  clang/test/Analysis/malloc.c
  clang/test/Analysis/pr22954.c


Index: clang/test/Analysis/pr22954.c
===
--- clang/test/Analysis/pr22954.c
+++ clang/test/Analysis/pr22954.c
@@ -352,6 +352,8 @@
   memcpy(J0.s1[i].s1, input, 2);
   clang_analyzer_eval(J0.s1[0].s1[0] == 1); // expected-warning{{UNKNOWN}}\
   expected-warning{{Potential leak of memory pointed to by field 's2'}}\
+  expected-warning{{Potential leak of memory pointed to by field 's2'}}\
+  expected-warning{{Potential leak of memory pointed to by field 's2'}}\
   expected-warning{{Potential leak of memory pointed to by 'J0.s2'}}
   clang_analyzer_eval(J0.s1[0].s1[1] == 2); // expected-warning{{UNKNOWN}}
   clang_analyzer_eval(J0.s1[1].s1[0] == 3); // expected-warning{{UNKNOWN}}
Index: clang/test/Analysis/malloc.c
===
--- clang/test/Analysis/malloc.c
+++ clang/test/Analysis/malloc.c
@@ -791,7 +791,8 @@
 void mallocMalloc() {
   int *p = malloc(12);
   p = malloc(12);
-} // expected-warning {{Potential leak of memory pointed to by}}
+} // expected-warning {{Potential leak of memory pointed to by}}\
+  // expected-warning {{Potential leak of memory pointed to by}}
 
 void mallocFreeMalloc() {
   int *p = malloc(12);
Index: clang/lib/Analysis/PathDiagnostic.cpp
===
--- clang/lib/Analysis/PathDiagnostic.cpp
+++ clang/lib/Analysis/PathDiagnostic.cpp
@@ -327,6 +327,10 @@
 }
 
 static bool compareCrossTUSourceLocs(FullSourceLoc XL, FullSourceLoc YL) {
+  if (XL.isInvalid() && YL.isValid())
+return true;
+  if (XL.isValid() && YL.isInvalid())
+return false;
   std::pair XOffs = XL.getDecomposedLoc();
   std::pair YOffs = YL.getDecomposedLoc();
   const SourceManager &SM = XL.getManager();
@@ -349,6 +353,10 @@
   FullSourceLoc YL = Y.getLocation().asLocation();
   if (XL != YL)
 return compareCrossTUSourceLocs(XL, YL);
+  FullSourceLoc XUL = X.getUniqueingLoc().asLocation();
+  FullSourceLoc YUL = Y.getUniqueingLoc().asLocation();
+  if (XUL != YUL)
+return compareCrossTUSourceLocs(XUL, YUL);
   if (X.getBugType() != Y.getBugType())
 return X.getBugType() < Y.getBugType();
   if (X.getCategory() != Y.getCategory())
@@ -357,20 +365,27 @@
 return X.getVerboseDescription() < Y.getVerboseDescription();
   if (X.getShortDescription() != Y.getShortDescription())
 return X.getShortDescription() < Y.getShortDescription();
-  if (X.getDeclWithIssue() != Y.getDeclWithIssue()) {
-const Decl *XD = X.getDeclWithIssue();
-if (!XD)
+  auto CompareDecls = [&XL](const Decl *D1, const Decl *D2) -> Optional {
+if (D1 == D2)
+  return None;
+if (!D1)
   return true;
-const Decl *YD = Y.getDeclWithIssue();
-if (!YD)
+if (!D2)
   return false;
-SourceLocation XDL = XD->getLocation();
-SourceLocation YDL = YD->getLocation();
-if (XDL != YDL) {
+SourceLocation D1L = D1->getLocation();
+SourceLocation D2L = D2->getLocation();
+if (D1L != D2L) {
   const SourceManager &SM = XL.getManager();
-  return compareCrossTUSourceLocs(FullSourceLoc(XDL, SM),
-  FullSourceLoc(YDL, SM));
+  return compareCrossTUSourceLocs(FullSourceLoc(D1L, SM),
+  FullSourceLoc(D2L, SM));
 }
+return None;
+  };
+  if (auto Result = CompareDecls(X.getDeclWithIssue(), Y.getDeclWithIssue()))
+return *Result;
+  if (XUL.isValid()) {
+if (auto Result = CompareDecls(X.getUniqueingDecl(), Y.getUniqueingDecl()))
+  return *Result;
   }
   PathDiagnostic::meta_iterator XI = X.meta_begin(), XE = X.meta_end();
   PathDiagnostic::meta_iterator YI = Y.meta_begin(), YE = Y.meta_end();
@@ -1118,6 +1133,8 @@
 
 void PathDiagnostic::Profile(llvm::FoldingSetNodeID &ID) const {
   ID.Add(getLocation());
+  ID.Add(getUniqueingLoc());
+  ID.AddPointer(getUniqueingLoc().isValid() ? getUniqueingDecl() : nullptr);
   ID.AddString(BugType);
   ID.AddString(VerboseDesc);
   ID.AddString(Category);


Index: clang/test/Analysis/pr22954.c
===
--- clang/test/Analysis/pr22954.c
+++ clang/test/Analysis/pr22954.c
@@ -352,6 +352,8 @@
   memcpy(J0.s1[i].s1, input, 2);
   clang_analyzer_eval(J0.s1[0].s1[0] == 1); // expected-warning{{UNKNOWN}}\
   expected-warning{{Potential leak of memory pointed to by field 's2'}}\
+  expected-warning{{Potential leak of memory pointed to by field 's2'}}\
+  expected-warning{{Potential leak 

[PATCH] D83822: [clangd] Support config over LSP.

2020-07-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/ClangdLSPServer.cpp:1220
   CDB->setCompileCommand(File, std::move(New));
   ModifiedFiles.insert(File);
 }

nit: maybe just set `ReparseAllFiles` in here too, and change the condition 
below to only `return ReparseAllFiles`



Comment at: clang-tools-extra/clangd/Protocol.h:494
+  // Each value is an Object or null, and replaces any fragment with that key.
+  // Fragments are used in key order ("!foo" is low-priority, "~foo" is high).
+  std::map fragments;

it feels like clients will only be using two types of keys, a "global" one for 
sending over (likely project-specific) user preferences and another for 
directory/file specific configs. The latter is likely to have the path as a 
key, whereas the former will likely be a special identifier. I am glad that `!` 
comes before both `/` and any capital letters(letter drives).

I think it is only important to have a distinction between these two types (a 
subset of what you describe here). Current design makes it really easy on our 
side, I am just afraid of confusing clients. Maybe we should just have an 
enum/boolean tag saying if the fragment is global or not instead of relying on 
the key orderings ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83822



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


[PATCH] D83802: [clangd] Config: also propagate in sync (testing) mode

2020-07-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked an inline comment as done.
sammccall added a comment.

Also added one direct test for this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83802



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


[clang-tools-extra] cf7160c - [clangd] Config: also propagate in sync (testing) mode

2020-07-15 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2020-07-15T12:30:08+02:00
New Revision: cf7160c0b0c1250596cc9b2ba0e41423ac465a8f

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

LOG: [clangd] Config: also propagate in sync (testing) mode

Summary:
I hit this while trying to add a config-over-LSP lit test, which I think
is an appropriate way to test this feature.

That needs a few more changes though...

Reviewers: kadircet

Subscribers: ilya-biryukov, javed.absar, MaskRay, jkorous, arphaman, usaxena95, 
cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/TUScheduler.cpp
clang-tools-extra/clangd/TUScheduler.h
clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/TUScheduler.cpp 
b/clang-tools-extra/clangd/TUScheduler.cpp
index 5454b1c92c8a..ed367005177b 100644
--- a/clang-tools-extra/clangd/TUScheduler.cpp
+++ b/clang-tools-extra/clangd/TUScheduler.cpp
@@ -965,6 +965,7 @@ void ASTWorker::startTask(llvm::StringRef Name,
   if (RunSync) {
 assert(!Done && "running a task after stop()");
 trace::Span Tracer(Name + ":" + llvm::sys::path::filename(FileName));
+WithContext WithProvidedContext(ContextProvider(FileName));
 Task();
 return;
   }
@@ -1062,9 +1063,7 @@ void ASTWorker::run() {
 Status.ASTActivity.K = ASTAction::RunningAction;
 Status.ASTActivity.Name = CurrentRequest->Name;
   });
-  llvm::Optional WithProvidedContext;
-  if (ContextProvider)
-WithProvidedContext.emplace(ContextProvider(FileName));
+  WithContext WithProvidedContext(ContextProvider(FileName));
   CurrentRequest->Action();
 }
 
@@ -1238,6 +1237,12 @@ TUScheduler::TUScheduler(const GlobalCompilationDatabase 
&CDB,
   Barrier(Opts.AsyncThreadsCount),
   IdleASTs(
   std::make_unique(Opts.RetentionPolicy.MaxRetainedASTs)) {
+  // Avoid null checks everywhere.
+  if (!Opts.ContextProvider) {
+this->Opts.ContextProvider = [](llvm::StringRef) {
+  return Context::current().clone();
+};
+  }
   if (0 < Opts.AsyncThreadsCount) {
 PreambleTasks.emplace();
 WorkerThreads.emplace();
@@ -1300,16 +1305,16 @@ llvm::StringMap 
TUScheduler::getAllFileContents() const {
 
 void TUScheduler::run(llvm::StringRef Name, llvm::StringRef Path,
   llvm::unique_function Action) {
-  if (!PreambleTasks)
+  if (!PreambleTasks) {
+WithContext WithProvidedContext(Opts.ContextProvider(Path));
 return Action();
+  }
   PreambleTasks->runAsync(Name, [this, Ctx = Context::current().clone(),
  Path(Path.str()),
  Action = std::move(Action)]() mutable {
 std::lock_guard BarrierLock(Barrier);
 WithContext WC(std::move(Ctx));
-llvm::Optional WithProvidedContext;
-if (Opts.ContextProvider)
-  WithProvidedContext.emplace(Opts.ContextProvider(Path));
+WithContext WithProvidedContext(Opts.ContextProvider(Path));
 Action();
   });
 }
@@ -1344,6 +1349,7 @@ void TUScheduler::runWithPreamble(llvm::StringRef Name, 
PathRef File,
 SPAN_ATTACH(Tracer, "file", File);
 std::shared_ptr Preamble =
 It->second->Worker->getPossiblyStalePreamble();
+WithContext WithProvidedContext(Opts.ContextProvider(File));
 Action(InputsAndPreamble{It->second->Contents,
  It->second->Worker->getCurrentCompileCommand(),
  Preamble.get()});
@@ -1370,9 +1376,7 @@ void TUScheduler::runWithPreamble(llvm::StringRef Name, 
PathRef File,
 WithContext Guard(std::move(Ctx));
 trace::Span Tracer(Name);
 SPAN_ATTACH(Tracer, "file", File);
-llvm::Optional WithProvidedContext;
-if (Opts.ContextProvider)
-  WithProvidedContext.emplace(Opts.ContextProvider(File));
+WithContext WithProvidedContext(Opts.ContextProvider(File));
 Action(InputsAndPreamble{Contents, Command, Preamble.get()});
   };
 

diff  --git a/clang-tools-extra/clangd/TUScheduler.h 
b/clang-tools-extra/clangd/TUScheduler.h
index 05c06da13380..5d545b366ec3 100644
--- a/clang-tools-extra/clangd/TUScheduler.h
+++ b/clang-tools-extra/clangd/TUScheduler.h
@@ -313,7 +313,7 @@ class TUScheduler {
 
 private:
   const GlobalCompilationDatabase &CDB;
-  const Options Opts;
+  Options Opts;
   std::unique_ptr Callbacks; // not nullptr
   Semaphore Barrier;
   llvm::StringMap> Files;

diff  --git a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp 
b/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
index f40377fd5d85..61ac4f7a27a4 100644
--- a/clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ b/clang-tools-extra/clangd/unittests/TUS

[PATCH] D83802: [clangd] Config: also propagate in sync (testing) mode

2020-07-15 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcf7160c0b0c1: [clangd] Config: also propagate in sync 
(testing) mode (authored by sammccall).
Herald added a subscriber: jfb.

Changed prior to commit:
  https://reviews.llvm.org/D83802?vs=277920&id=278130#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83802

Files:
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h
  clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp

Index: clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
===
--- clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
+++ clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
@@ -864,25 +864,28 @@
 }
 
 TEST_F(TUSchedulerTests, Run) {
-  auto Opts = optsForTest();
-  Opts.ContextProvider = bindPath;
-  TUScheduler S(CDB, Opts);
-  std::atomic Counter(0);
-  S.run("add 1", /*Path=*/"", [&] { ++Counter; });
-  S.run("add 2", /*Path=*/"", [&] { Counter += 2; });
-  ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
-  EXPECT_EQ(Counter.load(), 3);
-
-  Notification TaskRun;
-  Key TestKey;
-  WithContextValue CtxWithKey(TestKey, 10);
-  const char *Path = "somepath";
-  S.run("props context", Path, [&] {
-EXPECT_EQ(Context::current().getExisting(TestKey), 10);
-EXPECT_EQ(Path, boundPath());
-TaskRun.notify();
-  });
-  TaskRun.wait();
+  for (bool Sync : {false, true}) {
+auto Opts = optsForTest();
+if (Sync)
+  Opts.AsyncThreadsCount = 0;
+TUScheduler S(CDB, Opts);
+std::atomic Counter(0);
+S.run("add 1", /*Path=*/"", [&] { ++Counter; });
+S.run("add 2", /*Path=*/"", [&] { Counter += 2; });
+ASSERT_TRUE(S.blockUntilIdle(timeoutSeconds(10)));
+EXPECT_EQ(Counter.load(), 3);
+
+Notification TaskRun;
+Key TestKey;
+WithContextValue CtxWithKey(TestKey, 10);
+const char *Path = "somepath";
+S.run("props context", Path, [&] {
+  EXPECT_EQ(Context::current().getExisting(TestKey), 10);
+  EXPECT_EQ(Path, boundPath());
+  TaskRun.notify();
+});
+TaskRun.wait();
+  }
 }
 
 TEST_F(TUSchedulerTests, TUStatus) {
Index: clang-tools-extra/clangd/TUScheduler.h
===
--- clang-tools-extra/clangd/TUScheduler.h
+++ clang-tools-extra/clangd/TUScheduler.h
@@ -313,7 +313,7 @@
 
 private:
   const GlobalCompilationDatabase &CDB;
-  const Options Opts;
+  Options Opts;
   std::unique_ptr Callbacks; // not nullptr
   Semaphore Barrier;
   llvm::StringMap> Files;
Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -965,6 +965,7 @@
   if (RunSync) {
 assert(!Done && "running a task after stop()");
 trace::Span Tracer(Name + ":" + llvm::sys::path::filename(FileName));
+WithContext WithProvidedContext(ContextProvider(FileName));
 Task();
 return;
   }
@@ -1062,9 +1063,7 @@
 Status.ASTActivity.K = ASTAction::RunningAction;
 Status.ASTActivity.Name = CurrentRequest->Name;
   });
-  llvm::Optional WithProvidedContext;
-  if (ContextProvider)
-WithProvidedContext.emplace(ContextProvider(FileName));
+  WithContext WithProvidedContext(ContextProvider(FileName));
   CurrentRequest->Action();
 }
 
@@ -1238,6 +1237,12 @@
   Barrier(Opts.AsyncThreadsCount),
   IdleASTs(
   std::make_unique(Opts.RetentionPolicy.MaxRetainedASTs)) {
+  // Avoid null checks everywhere.
+  if (!Opts.ContextProvider) {
+this->Opts.ContextProvider = [](llvm::StringRef) {
+  return Context::current().clone();
+};
+  }
   if (0 < Opts.AsyncThreadsCount) {
 PreambleTasks.emplace();
 WorkerThreads.emplace();
@@ -1300,16 +1305,16 @@
 
 void TUScheduler::run(llvm::StringRef Name, llvm::StringRef Path,
   llvm::unique_function Action) {
-  if (!PreambleTasks)
+  if (!PreambleTasks) {
+WithContext WithProvidedContext(Opts.ContextProvider(Path));
 return Action();
+  }
   PreambleTasks->runAsync(Name, [this, Ctx = Context::current().clone(),
  Path(Path.str()),
  Action = std::move(Action)]() mutable {
 std::lock_guard BarrierLock(Barrier);
 WithContext WC(std::move(Ctx));
-llvm::Optional WithProvidedContext;
-if (Opts.ContextProvider)
-  WithProvidedContext.emplace(Opts.ContextProvider(Path));
+WithContext WithProvidedContext(Opts.ContextProvider(Path));
 Action();
   });
 }
@@ -1344,6 +1349,7 @@
 SPAN_ATTACH(Tracer, "file", File);
 std::shared_ptr Preamble =
 It->second->Worker->getPossiblyStalePreamble();
+WithContext WithProvidedContext(Opts.ContextProvider(File));
 Action(In

[PATCH] D83772: [Windows] Fix limit on command line size

2020-07-15 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 278132.
sepavloff added a comment.

Fixed typo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83772

Files:
  llvm/include/llvm/Support/Program.h
  llvm/lib/Support/Windows/Program.inc
  llvm/unittests/Support/CommandLineTest.cpp

Index: llvm/unittests/Support/CommandLineTest.cpp
===
--- llvm/unittests/Support/CommandLineTest.cpp
+++ llvm/unittests/Support/CommandLineTest.cpp
@@ -763,6 +763,17 @@
 TEST(CommandLineTest, ArgumentLimit) {
   std::string args(32 * 4096, 'a');
   EXPECT_FALSE(llvm::sys::commandLineFitsWithinSystemLimits("cl", args.data()));
+  std::string args2(256, 'a');
+  EXPECT_TRUE(llvm::sys::commandLineFitsWithinSystemLimits("cl", args2.data()));
+  if (Triple(sys::getProcessTriple()).isOSWindows()) {
+// We use 32000 as a limit for command line length.
+std::string long_arg(32000, 'b');
+EXPECT_TRUE(
+llvm::sys::commandLineFitsWithinSystemLimits("cl", long_arg.data()));
+long_arg += 'b';
+EXPECT_FALSE(
+llvm::sys::commandLineFitsWithinSystemLimits("cl", long_arg.data()));
+  }
 }
 
 TEST(CommandLineTest, ResponseFileWindows) {
Index: llvm/lib/Support/Windows/Program.inc
===
--- llvm/lib/Support/Windows/Program.inc
+++ llvm/lib/Support/Windows/Program.inc
@@ -189,7 +189,13 @@
   // Windows wants a command line, not an array of args, to pass to the new
   // process.  We have to concatenate them all, while quoting the args that
   // have embedded spaces (or are empty).
-  std::string Command = flattenWindowsCommandLine(Args);
+  auto Result = flattenWindowsCommandLine(Args);
+  if (std::error_code ec = Result.getError()) {
+SetLastError(ec.value());
+MakeErrMsg(ErrMsg, std::string("Unable to convert command-line to UTF-16"));
+return false;
+  }
+  std::wstring Command = *Result;
 
   // The pointer to the environment block for the new process.
   std::vector EnvBlock;
@@ -271,14 +277,8 @@
 return false;
   }
 
-  SmallVector CommandUtf16;
-  if (std::error_code ec = windows::UTF8ToUTF16(Command, CommandUtf16)) {
-SetLastError(ec.value());
-MakeErrMsg(ErrMsg,
-   std::string("Unable to convert command-line to UTF-16"));
-return false;
-  }
-
+  std::vector CommandUtf16(Command.size() + 1, 0);
+  std::copy(Command.begin(), Command.end(), CommandUtf16.begin());
   BOOL rc = CreateProcessW(ProgramUtf16.data(), CommandUtf16.data(), 0, 0,
TRUE, CREATE_UNICODE_ENVIRONMENT,
EnvBlock.empty() ? 0 : EnvBlock.data(), 0, &si,
@@ -376,7 +376,7 @@
 }
 
 namespace llvm {
-std::string sys::flattenWindowsCommandLine(ArrayRef Args) {
+ErrorOr sys::flattenWindowsCommandLine(ArrayRef Args) {
   std::string Command;
   for (StringRef Arg : Args) {
 if (argNeedsQuotes(Arg))
@@ -387,7 +387,11 @@
 Command.push_back(' ');
   }
 
-  return Command;
+  SmallVector CommandUtf16;
+  if (std::error_code ec = windows::UTF8ToUTF16(Command, CommandUtf16))
+return ec;
+
+  return std::wstring(CommandUtf16.begin(), CommandUtf16.end());
 }
 
 ProcessInfo sys::Wait(const ProcessInfo &PI, unsigned SecondsToWait,
@@ -532,12 +536,16 @@
 
 bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program,
   ArrayRef Args) {
-  // The documented max length of the command line passed to CreateProcess.
-  static const size_t MaxCommandStringLength = 32768;
+  // The documentation on CreateProcessW states that the size of the argument
+  // lpCommandLine must not be greater than 32767 characters, including the
+  // Unicode terminating null character. We use smaller value to reduce risk
+  // of getting invalid command line due to unaccounted factors.
+  static const size_t MaxCommandStringLength = 32000;
   SmallVector FullArgs;
   FullArgs.push_back(Program);
   FullArgs.append(Args.begin(), Args.end());
-  std::string Result = flattenWindowsCommandLine(FullArgs);
-  return (Result.size() + 1) <= MaxCommandStringLength;
+  auto Result = flattenWindowsCommandLine(FullArgs);
+  assert(!Result.getError());
+  return (Result->size() + 1) <= MaxCommandStringLength;
 }
 }
Index: llvm/include/llvm/Support/Program.h
===
--- llvm/include/llvm/Support/Program.h
+++ llvm/include/llvm/Support/Program.h
@@ -218,7 +218,7 @@
   /// to build a single flat command line appropriate for calling CreateProcess
   /// on
   /// Windows.
-  std::string flattenWindowsCommandLine(ArrayRef Args);
+  ErrorOr flattenWindowsCommandLine(ArrayRef Args);
 #endif
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83831: [clangd] Add more logs and attach tracers to remote index server routines

2020-07-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Server-side tracing looks nice, but you'll need some flags to allow actually 
extracting a trace, right?




Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:62
   grpc::ServerWriter *Reply) override {
+trace::Span Tracer("Remote index server Lookup");
+SPAN_ATTACH(Tracer, "LookupRequest", Request->ShortDebugString());

Nit: this is "LookupRequest" on the client side. I'd suggest just the same on 
the server, or "Recv.LookupRequest" or so? to make it easier to correspond them



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:63
+trace::Span Tracer("Remote index server Lookup");
+SPAN_ATTACH(Tracer, "LookupRequest", Request->ShortDebugString());
 clangd::LookupRequest Req;

you don't do this on the client side, but could



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:63
+trace::Span Tracer("Remote index server Lookup");
+SPAN_ATTACH(Tracer, "LookupRequest", Request->ShortDebugString());
 clangd::LookupRequest Req;

sammccall wrote:
> you don't do this on the client side, but could
prefer DebugString over ShortDebugString, the missing newlines can make it hard 
to follow



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:98
+trace::Span Tracer("Remote index server FuzzyFind");
+SPAN_ATTACH(Tracer, "FuzzyFindRequest", Request->ShortDebugString());
 const auto Req = fromProtobuf(Request, IndexedProjectRoot);

you don't do this on the client side, but should


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83831



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


[PATCH] D83826: [clangd] Don't send invalid messages from remote index

2020-07-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

> Also add more error messages and logs.

I'm not sure about the error-handling strategy here:

- it's very verbose in the marshalling code. Are we sure it pays for itself? 
For comparison, the marshalling code for LSP itself silently returns `false` on 
error, which is handled at the top level. It's been fine so far.
- some errors are being logged that are not errors. e.g. it's not an error to 
drop a symbol because its declaration is in a file outside the index root, 
that's just expected behavior
- it's not clear which levels are responsible for logging errors, leaving the 
possibility that some errors will be logged twice or not at all
- it's not easy to change if we want a slightly different strategy

I'd suggest leaving out detailed error reporting for now, and reporting at the 
top level. You may need some mechanism to distinguish invalid vs filtered-out 
data.
It could be something like a "filtered out" flag that causes the error 
reporting to be suppressed. There are more design options here if marshalling 
is a class I think.




Comment at: 
clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp:151
   !Message.has_canonical_declaration()) {
-elog("Cannot convert Symbol from Protobuf: {0}",
+elog("Cannot convert Symbol from Protobuf (missing info, definition or "
+ "declaration): {1}",

aren't all these placeholders incorrect? first is {0}



Comment at: 
clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp:167
   Result.Scope = Message.scope();
   auto Definition = fromProtobuf(Message.definition(), Strings, IndexRoot);
+  if (!Definition) {

missing definition is perfectly valid, so both the old and new code look wrong 
here



Comment at: 
clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp:310
+  if (!Location) {
+elog("Can not convet Reference to Potobuf (invalid location) {1}: {2}",
+ From, From.Location);

convert, protobuf



Comment at: 
clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp:333
   }
   if (llvm::sys::path::is_relative(IndexRoot)) {
+elog("Remote index client got a relative path as index root: {1}",

we shouldn't be checking this every time, IndexRoot is fixed for the lifetime 
of the index so it should be checked once and asserted here.

(Wrapping the marshalling in a class is a nice clean way to do this)



Comment at: 
clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp:349
   assert(!IndexRoot.empty());
   if (llvm::sys::path::is_relative(IndexRoot)) {
+elog("Index root {1} is not absolute path", IndexRoot);

and here... IndexRoot shouldn't be checked every time


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83826



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


[PATCH] D83826: [clangd] Don't send invalid messages from remote index

2020-07-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D83826#2151979 , @kbobyrev wrote:

> Use the same style for elog messages (1-based indexing, message format).


As far as I can tell, 1-based indexing isn't an option that's available. Where 
do you see that it is?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83826



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


[PATCH] D83551: [PATCH 2/4][Sema][AArch64] Add semantics for arm_sve_vector_bits attribute

2020-07-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:1541
 
+def ArmSveVectorBits128 : TypeAttr {
+  let Spellings = [];

c-rhodes wrote:
> sdesmalen wrote:
> > aaron.ballman wrote:
> > > sdesmalen wrote:
> > > > nit: Can you add a comment saying why these are undocumented (and have 
> > > > no spellings)
> > > Also, I think these are all missing `let SemaHandler = 0;` and `let 
> > > ASTNode = 0;`
> > > 
> > > Is there a reason why we need N different type attributes instead of 
> > > having a single type attribute which encodes the N as an argument? I 
> > > think this may simplify the patch somewhat as you no longer need to 
> > > switch over N as much.
> > > Is there a reason why we need N different type attributes instead of 
> > > having a single type attribute which encodes the N as an argument?
> > AIUI this was a workaround for getting the value of N from an 
> > AttributedType, because this only has `getAttrKind` to return the attribute 
> > kind, but no way to get the corresponding argument/value. This seemed like 
> > a simple way to do that without having to create a new subclass for Type 
> > and having to support that in various places. Is the latter the approach 
> > you were thinking of? (or is there perhaps a simpler way?)
> > Also, I think these are all missing let SemaHandler = 0; and let ASTNode = 
> > 0;
> 
> Good to know. In SemaType I'm doing `CurType = State.getAttributedType(A, 
> CurType, CurType);` which gives an `AttributedType` in the AST, should I 
> still set `let ASTNode = 0;` in this case?
> 
> > Is there a reason why we need N different type attributes instead of having 
> > a single type attribute which encodes the N as an argument?
> 
> As Sander mentioned, it seemed like the easiest solution, interested to know 
> if there's a better approach however
I was thinking specifically of creating a new `Type` subclass and supporting it 
rather than adding 5 new attributes that only vary by a bit-width (which means 
there's likely to be a 6th someday). It's not immediately clear to me whether 
that's a really big ask for little gain or not, though.



Comment at: clang/include/clang/Basic/Attr.td:1541
 
+def ArmSveVectorBits128 : TypeAttr {
+  let Spellings = [];

aaron.ballman wrote:
> c-rhodes wrote:
> > sdesmalen wrote:
> > > aaron.ballman wrote:
> > > > sdesmalen wrote:
> > > > > nit: Can you add a comment saying why these are undocumented (and 
> > > > > have no spellings)
> > > > Also, I think these are all missing `let SemaHandler = 0;` and `let 
> > > > ASTNode = 0;`
> > > > 
> > > > Is there a reason why we need N different type attributes instead of 
> > > > having a single type attribute which encodes the N as an argument? I 
> > > > think this may simplify the patch somewhat as you no longer need to 
> > > > switch over N as much.
> > > > Is there a reason why we need N different type attributes instead of 
> > > > having a single type attribute which encodes the N as an argument?
> > > AIUI this was a workaround for getting the value of N from an 
> > > AttributedType, because this only has `getAttrKind` to return the 
> > > attribute kind, but no way to get the corresponding argument/value. This 
> > > seemed like a simple way to do that without having to create a new 
> > > subclass for Type and having to support that in various places. Is the 
> > > latter the approach you were thinking of? (or is there perhaps a simpler 
> > > way?)
> > > Also, I think these are all missing let SemaHandler = 0; and let ASTNode 
> > > = 0;
> > 
> > Good to know. In SemaType I'm doing `CurType = State.getAttributedType(A, 
> > CurType, CurType);` which gives an `AttributedType` in the AST, should I 
> > still set `let ASTNode = 0;` in this case?
> > 
> > > Is there a reason why we need N different type attributes instead of 
> > > having a single type attribute which encodes the N as an argument?
> > 
> > As Sander mentioned, it seemed like the easiest solution, interested to 
> > know if there's a better approach however
> I was thinking specifically of creating a new `Type` subclass and supporting 
> it rather than adding 5 new attributes that only vary by a bit-width (which 
> means there's likely to be a 6th someday). It's not immediately clear to me 
> whether that's a really big ask for little gain or not, though.
Ah, you're right, we may still need `ASTNode` to be kept around for that, good 
call.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83551



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


[PATCH] D83120: [Analyzer][StreamChecker] Use BugType::SuppressOnSink at resource leak report.

2020-07-15 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added a comment.

Now that we found the answer to the only lingering question this revision 
raised, I think you can safely land it while we start looking into fixing this 
newfound bug. LGTM.




Comment at: clang/test/Analysis/stream.c:274-284
 // Check that "location uniqueing" works.
 // This results in reporting only one occurence of resource leak for a stream.
 void check_leak_noreturn_2() {
   FILE *F1 = tmpfile();
   if (!F1)
 return;
   if (Test == 1) {

balazske wrote:
> NoQ wrote:
> > balazske wrote:
> > > NoQ wrote:
> > > > balazske wrote:
> > > > > Szelethus wrote:
> > > > > > Szelethus wrote:
> > > > > > > balazske wrote:
> > > > > > > > NoQ wrote:
> > > > > > > > > balazske wrote:
> > > > > > > > > > Szelethus wrote:
> > > > > > > > > > > Why did this change? Is there a sink in the return branch?
> > > > > > > > > > The change is probably because D83115. Because the 
> > > > > > > > > > "uniqueing" one resource leak is reported from the two 
> > > > > > > > > > possible, and the order changes somehow (probably not the 
> > > > > > > > > > shortest is found first).
> > > > > > > > > The shortest should still be found first. I strongly suggest 
> > > > > > > > > debugging this. Looks like a bug in suppress-on-sink.
> > > > > > > > There is no code that ensures that the shortest path is 
> > > > > > > > reported. In this case one equivalence class is created with 
> > > > > > > > both bug reports. If `SuppressOnSink` is false the last one is 
> > > > > > > > returned from the list, otherwise the first one 
> > > > > > > > (`PathSensitiveBugReporter::findReportInEquivalenceClass`), 
> > > > > > > > this causes the difference (seems to be unrelated to D83115).
> > > > > > > > There is no code that ensures that the shortest path is 
> > > > > > > > reported.
> > > > > > > 
> > > > > > > There absolutely should be -- See the summary of D65379 for more 
> > > > > > > info, CTRL+F "shortest" helps quite a bit as well. For each bug 
> > > > > > > report, we create a bug path (a path in the exploded graph from 
> > > > > > > the root to the sepcific bug reports error node), and sort them 
> > > > > > > by length.
> > > > > > > 
> > > > > > > It all feels super awkward -- 
> > > > > > > `PathSensitiveBugReporter::findReportInEquivalenceClass` picks 
> > > > > > > out a bug report from an equivalence class as you described, but 
> > > > > > > that will only be reported if it is a `BasicBugReport` (as 
> > > > > > > implemented by 
> > > > > > > `PathSensitiveBugReporter::generateDiagnosticForConsumerMap`), 
> > > > > > > otherwise it should go through the graph cutting process etc.
> > > > > > > 
> > > > > > > So at the end of the day, the shortest path should appear still? 
> > > > > > > 
> > > > > > @balazske I spent a lot of my GSoC rewriting some especially 
> > > > > > miserable code in `BugReporter.cpp`, please hunt me down if you 
> > > > > > need any help there.
> > > > > Can we say that the one path in this case is shorter than the other? 
> > > > > The difference is only at the "taking true/false branch" at the `if` 
> > > > > in line 280. Maybe both have equal length. The notes are taken always 
> > > > > from the single picked report that is returned from 
> > > > > `findReportInEquivalenceClass` and these notes can contain different 
> > > > > source locations (reports in a single equivalence class can have 
> > > > > different locations, really this makes the difference between them?). 
> > > > >  
> > > > > There is no code that ensures that the shortest path is reported.
> > > > 
> > > > We would have been soo screwed if this was so. In fact, 
> > > > grepping for "shortest" in the entire clang sources immediately points 
> > > > you to the right line of code.
> > > > 
> > > > > the last one is returned from the list, otherwise the first one
> > > > 
> > > > The example report is not actually used later for purposes other than 
> > > > extracting information common to all reports in the path. The array of 
> > > > valid reports is used instead, and it's supposed to be sorted.
> > > > 
> > > > > Can we say that the one path in this case is shorter than the other?
> > > > 
> > > > Dump the graph and see for yourself. I expect a call with an argument 
> > > > and an implicit lvalue-to-rvalue conversion of that argument to take a 
> > > > lot more nodes than an empty return statement.
> > > I found the sorting code, it revealed that the problem has other reason: 
> > > It happens only if //-analyzer-output text// is not passed to clang. It 
> > > looks like that in this case the path in `PathDiagnostic` is not 
> > > collected, so `BugReporter::FlushReport` will use the one report instance 
> > > from the bug report class (that is different if `SuppressOnSink` is set 
> > > or not).
> > Ok, this sounds pretty bad, as if a lot of our lit tests actually have 
> > warnings misplaced. I.e., we report diffe

[PATCH] D83120: [Analyzer][StreamChecker] Use BugType::SuppressOnSink at resource leak report.

2020-07-15 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

Unless @NoQ has anything else to add :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83120



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


[PATCH] D83820: Change metadata to deferred evalutaion in Clang Transformer.

2020-07-15 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/include/clang/Tooling/Transformer/RewriteRule.h:268
 
-inline ASTEdit withMetadata(ASTEdit edit, llvm::Any Metadata) {
-  edit.Metadata = std::move(Metadata);
-  return edit;
+// TODO(asoffer): If this returns an llvm::Expected, should we unwrap?
+template 

What is "this" who is "we"? Should this be an implementation comment instead 
(in the function body next to the relevant line)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83820



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


[PATCH] D82081: [z/OS] Add binary format goff and operating system zos to the triple

2020-07-15 Thread Kai Nacke via Phabricator via cfe-commits
Kai added a comment.

Is there a comment on the clang part?


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

https://reviews.llvm.org/D82081



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


[PATCH] D83550: [PATCH 1/4][Sema][AArch64] Add parsing support for arm_sve_vector_bits attribute

2020-07-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/Sema/arm-feature-sve-bits-macro.c:24
+#define __ARM_FEATURE_SVE_BITS N
+typedef svint8_t macro_non_int_size2 __attribute__((arm_sve_vector_bits(N))); 
// expected-error {{'__ARM_FEATURE_SVE_BITS' must expand to an integer 
constant}}
+#undef __ARM_FEATURE_SVE_BITS

This is a case where I would have expected no diagnostic specifically because 
`N` does expand to an integer constant. Is there a reason to not support that?



Comment at: clang/test/Sema/arm-feature-sve-bits-macro.c:3
+
+#include 
+

c-rhodes wrote:
> aaron.ballman wrote:
> > This should not be using a system include (unless you control the include 
> > path from the RUN line so this doesn't depend on the system running the 
> > test).
> Good spot, I missed `// REQUIRES: aarch64-registered-target` which we use in 
> the other ACLE tests.
That makes me uncomfortable as this means you won't get any testing on 
platforms that may have odd behaviors, like Windows when in MS compatibility 
mode. I'm not keen on adding attributes that can only be tested under certain 
circumstances as we want to ensure behavior on all platforms.

We typically handle this by requiring the test to replicate the system header 
in an Inputs folder that then gets set on the RUN line so that the test can be 
reproduced on any platform. Was that approach considered and rejected for some 
reason?



Comment at: clang/test/Sema/arm-feature-sve-bits-macro.c:4
+#include 
+
+#define N 512

c-rhodes wrote:
> aaron.ballman wrote:
> > You should have a test that the attribute works at this location due to the 
> > macro being defined on the command line.
> I think that's covered by `clang/test/Sema/attr-arm-sve-vector-bits.c`
So it is!



Comment at: clang/test/Sema/arm-feature-sve-bits-macro.c:22
+// SVE vector bits must equal __ARM_FEATURE_SVE_BITS
+#define __ARM_FEATURE_SVE_BITS 512
+typedef svint8_t badsize __attribute__((arm_sve_vector_bits(256))); // 
expected-error {{inconsistent SVE vector size '256', must match 
__ARM_FEATURE_SVE_BITS feature macro set by -msve-vector-bits}}

c-rhodes wrote:
> aaron.ballman wrote:
> > I'd also appreciate test cases like:
> > ```
> > #define __ARM_FEATURE_SVE_BITS(x)  512
> > #define __ARM_FEATURE_SVE_BITS N
> > ```
> > 
> > #define __ARM_FEATURE_SVE_BITS N
> Good point, I've added a test for this which I think covers the 
> `isValueDependent` check.
> 
> > #define __ARM_FEATURE_SVE_BITS(x)  512
> I did try this but no diagnostic is emitted, were you thinking this would 
> cover `isTypeDependent`? To be honest I copied that from 
> `HandleNeonVectorTypeAttr` and I'm not sure if it's necessary or what a test 
> would look like for it. The tests for `neon_vector_type` only cover non-ICE 
> "2.0".
> Good point, I've added a test for this which I think covers the 
> isValueDependent check.
FWIW, I don't think this covers the value dependent case -- that's more to do 
with nontype template parameters (I don't believe macros can be type or value 
dependent; but constant expressions can be).

> I did try this but no diagnostic is emitted, were you thinking this would 
> cover isTypeDependent?
Nope, I don't think type dependence factors in (I consider that dependency code 
to be sanity-checking more than anything; it can probably be assertions if we 
prefer).

I was under the impression that you only want to support object-like macros and 
not function-like macros, even if the function-like macro results in an integer 
constant. If that matters, you can use `MacroInfo::isObjectLike()` or 
`MacroInfo::isFunctionLike()` to test for it.


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

https://reviews.llvm.org/D83550



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


[PATCH] D83863: [OpenMP] Change version 4.5 hardcoded clang tests to default OpenMP version

2020-07-15 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam added a comment.

[Work in progress]
Among all the test files in clang/test/OpenMP which were running only for 
version 4.5, I am yet to fix following files (rest all are given in this patch):

1. clang/test/OpenMP/distribute_parallel_for_codegen.cpp
2. clang/test/OpenMP/distribute_parallel_for_simd_codegen.cpp
3. clang/test/OpenMP/distribute_parallel_for_simd_if_messages.cpp
4. clang/test/OpenMP/for_reduction_messages.cpp
5. clang/test/OpenMP/parallel_for_simd_if_messages.cpp




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83863



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


[PATCH] D83855: [clang] Fix printing of lambdas with capture expressions

2020-07-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang/lib/AST/StmtPrinter.cpp:2011
+  Expr *Init = D->getInit();
+  if (D->getInitStyle() == VarDecl::CallInit && !isa(Init))
+OS << "(";

what about having a `Pre` and `Post` print blocks, set to `"(" and ")"` or `" = 
` and ""` respectively?

that way we could get rid of the second if block below.


also i don't follow why blacklisting for parenlistexpr is needed here (i can 
see that it will end up printing double parens, but so is `ParenExpr`s, and I 
think both of them shouldn't be showing up as initializer exprs of captured 
variables), could you elaborate with a comment and a test case?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83855



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


[PATCH] D83681: [clang] Provide a more specific diagnostic for a misplaced lambda capture-default.

2020-07-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Parse/ParseExprCXX.cpp:937
+  return Invalid([&] {
+Diag(Tok.getLocation(), diag::err_capture_default_first);
+  });

Would it make sense to provide a fix-it to move the capture default to the 
start of the list automatically, or is that a pain?



Comment at: clang/test/Parser/lambda-misplaced-capture-default.cpp:11
+
+  [i, &] {}; // expected-error {{capture default must be first}}
+  [i, = ] {}; // expected-error {{capture default must be first}}

Can you also add a test showing that `[=, &i]` continues to behave properly (to 
test the `&]` checking logic)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83681



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


[PATCH] D83681: [clang] Provide a more specific diagnostic for a misplaced lambda capture-default.

2020-07-15 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno updated this revision to Diff 278150.
riccibruno added a comment.

clang-format again, sigh...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83681

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseExprCXX.cpp
  clang/test/Parser/lambda-misplaced-capture-default.cpp


Index: clang/test/Parser/lambda-misplaced-capture-default.cpp
===
--- /dev/null
+++ clang/test/Parser/lambda-misplaced-capture-default.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -std=c++17 -Wno-unused-value -fsyntax-only -verify %s
+
+namespace misplaced_capture_default {
+void Test() {
+  int i = 0;
+  [&, i, &] {};   // expected-error {{expected variable name or 'this' in 
lambda capture list}}
+  [&, i, = ] {};  // expected-error {{expected variable name or 'this' in 
lambda capture list}}
+  [=, &i, &] {};  // expected-error {{expected variable name or 'this' in 
lambda capture list}}
+  [=, &i, = ] {}; // expected-error {{expected variable name or 'this' in 
lambda capture list}}
+
+  [i, &] {};   // expected-error {{capture default must be first}}
+  [i, = ] {};  // expected-error {{capture default must be first}}
+  [i, = x] {}; // expected-error {{expected variable name or 'this' in lambda 
capture list}}
+
+  [i, &, x = 2] {}; // expected-error {{capture default must be first}}
+  [i, =, x = 2] {}; // expected-error {{capture default must be first}}
+}
+} // namespace misplaced_capture_default
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -926,6 +926,15 @@
 } else if (Tok.is(tok::kw_this)) {
   Kind = LCK_This;
   Loc = ConsumeToken();
+} else if (Tok.isOneOf(tok::amp, tok::equal) &&
+   NextToken().isOneOf(tok::comma, tok::r_square) &&
+   Intro.Default == LCD_None) {
+  // We have a lone "&" or "=" which is either a misplaced capture-default
+  // or the start of a capture (in the "&" case) with the rest of the
+  // capture missing. Both are an error but a misplaced capture-default
+  // is more likely if we don't already have a capture default.
+  return Invalid(
+  [&] { Diag(Tok.getLocation(), diag::err_capture_default_first); });
 } else {
   TryConsumeToken(tok::ellipsis, EllipsisLocs[0]);
 
Index: clang/include/clang/Basic/DiagnosticParseKinds.td
===
--- clang/include/clang/Basic/DiagnosticParseKinds.td
+++ clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -934,6 +934,8 @@
   "the name of the capture">;
 def err_lambda_capture_multiple_ellipses : Error<
   "multiple ellipses in pack capture">;
+def err_capture_default_first : Error<
+  "capture default must be first">;
 // C++17 lambda expressions
 def err_expected_star_this_capture : Error<
   "expected 'this' following '*' in lambda capture list">;


Index: clang/test/Parser/lambda-misplaced-capture-default.cpp
===
--- /dev/null
+++ clang/test/Parser/lambda-misplaced-capture-default.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -std=c++17 -Wno-unused-value -fsyntax-only -verify %s
+
+namespace misplaced_capture_default {
+void Test() {
+  int i = 0;
+  [&, i, &] {};   // expected-error {{expected variable name or 'this' in lambda capture list}}
+  [&, i, = ] {};  // expected-error {{expected variable name or 'this' in lambda capture list}}
+  [=, &i, &] {};  // expected-error {{expected variable name or 'this' in lambda capture list}}
+  [=, &i, = ] {}; // expected-error {{expected variable name or 'this' in lambda capture list}}
+
+  [i, &] {};   // expected-error {{capture default must be first}}
+  [i, = ] {};  // expected-error {{capture default must be first}}
+  [i, = x] {}; // expected-error {{expected variable name or 'this' in lambda capture list}}
+
+  [i, &, x = 2] {}; // expected-error {{capture default must be first}}
+  [i, =, x = 2] {}; // expected-error {{capture default must be first}}
+}
+} // namespace misplaced_capture_default
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -926,6 +926,15 @@
 } else if (Tok.is(tok::kw_this)) {
   Kind = LCK_This;
   Loc = ConsumeToken();
+} else if (Tok.isOneOf(tok::amp, tok::equal) &&
+   NextToken().isOneOf(tok::comma, tok::r_square) &&
+   Intro.Default == LCD_None) {
+  // We have a lone "&" or "=" which is either a misplaced capture-default
+  // or the start of a capture (in the "&" case) with the rest of the
+  // capture missing. Both are an error but a misplaced capture-default
+  // is more likely 

[PATCH] D83864: [ClangTidy] Fix false positives of readability-non-const-parameters check

2020-07-15 Thread Jacques Lucke via Phabricator via cfe-commits
JacquesLucke created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We recently started using Clang Tidy on the Blender source. We found a 
couple of false positives of the `readability-non-const-parameters` check. 
One of those is fixed by this patch.

  struct MyStruct {
float *values;
  };
  
  void myfunc(float *values) {
MyStruct mystruct = {values};
  }

Without this patch, Clang Tidy reports that the `values` parameter of
`myfunc` can be const. It does not recognize that it is assigned to
a non-const data member of `MyStruct`.

Note, this is the first time I'm working with the LLVM source code.
So please let me know if I'm doing something wrong.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83864

Files:
  clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp


Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -99,7 +99,6 @@
 for (const auto *F : D->fields()) {
   if (InitNr >= ILE->getNumInits())
 break;
-
   const auto *Init = ILE->getInit(InitNr++);
   if (!F->getType().isConstQualified())
 markCanNotBeConst(Init, true);


Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -99,7 +99,6 @@
 for (const auto *F : D->fields()) {
   if (InitNr >= ILE->getNumInits())
 break;
-
   const auto *Init = ILE->getInit(InitNr++);
   if (!F->getType().isConstQualified())
 markCanNotBeConst(Init, true);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83864: [ClangTidy] Fix false positives of readability-non-const-parameters check

2020-07-15 Thread Jacques Lucke via Phabricator via cfe-commits
JacquesLucke updated this revision to Diff 278154.
JacquesLucke added a comment.

For some reason `arc` did not upload all the changes. Maybe because I cloned 
from github, will check. Anyway, here is the patch.


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

https://reviews.llvm.org/D83864

Files:
  clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-non-const-parameter.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability-non-const-parameter.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability-non-const-parameter.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability-non-const-parameter.cpp
@@ -217,11 +217,20 @@
 // Don't warn about nonconst record pointers that can be const.
 struct XY {
   int *x;
-  int *y;
+  const int *y;
 };
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+// CHECK-MESSAGES: :[[@LINE+1]]:21: warning: pointer parameter 'y' can be
+void initlist1(int *y) {
+  // CHECK-FIXES: {{^}}void initlist1(const int *y) {{{$}}
+  XY xy = {nullptr, y};
+}
+// Don't warn when pointer is assigned to non-const struct member.
+void initlist2(int *x) {
+  XY xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -92,6 +92,19 @@
 }
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
+if (T->isRecordType()) {
+  if (const auto *ILE = dyn_cast_or_null(VD->getInit())) {
+const auto *D = T->getAs()->getDecl();
+unsigned InitNr = 0U;
+for (const auto *F : D->fields()) {
+  if (InitNr >= ILE->getNumInits())
+break;
+  const auto *Init = ILE->getInit(InitNr++);
+  if (!F->getType().isConstQualified())
+markCanNotBeConst(Init, true);
+}
+  }
+}
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
 T->isArrayType())
   markCanNotBeConst(VD->getInit(), true);


Index: clang-tools-extra/test/clang-tidy/checkers/readability-non-const-parameter.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-non-const-parameter.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-non-const-parameter.cpp
@@ -217,11 +217,20 @@
 // Don't warn about nonconst record pointers that can be const.
 struct XY {
   int *x;
-  int *y;
+  const int *y;
 };
 void recordpointer(struct XY *xy) {
   *(xy->x) = 0;
 }
+// CHECK-MESSAGES: :[[@LINE+1]]:21: warning: pointer parameter 'y' can be
+void initlist1(int *y) {
+  // CHECK-FIXES: {{^}}void initlist1(const int *y) {{{$}}
+  XY xy = {nullptr, y};
+}
+// Don't warn when pointer is assigned to non-const struct member.
+void initlist2(int *x) {
+  XY xy = {x};
+}
 
 class C {
 public:
Index: clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -92,6 +92,19 @@
 }
   } else if (const auto *VD = Result.Nodes.getNodeAs("Mark")) {
 const QualType T = VD->getType();
+if (T->isRecordType()) {
+  if (const auto *ILE = dyn_cast_or_null(VD->getInit())) {
+const auto *D = T->getAs()->getDecl();
+unsigned InitNr = 0U;
+for (const auto *F : D->fields()) {
+  if (InitNr >= ILE->getNumInits())
+break;
+  const auto *Init = ILE->getInit(InitNr++);
+  if (!F->getType().isConstQualified())
+markCanNotBeConst(Init, true);
+}
+  }
+}
 if ((T->isPointerType() && !T->getPointeeType().isConstQualified()) ||
 T->isArrayType())
   markCanNotBeConst(VD->getInit(), true);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D82575: [OpenMP] OpenMP Clang tests without 50 version string after upgrading to 5.0

2020-07-15 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

Check that default tests have additional -fopenmp-version=45 flag since they 
are expected to be executed in OpenMP 4.5 mode.




Comment at: clang/test/OpenMP/declare_target_ast_print.cpp:5-7
+// RUN: %clang_cc1 -verify -fopenmp -I %S/Inputs -ast-print %s | FileCheck %s 
--check-prefix=CHECK --check-prefix=OMP50
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -I %S/Inputs -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -I 
%S/Inputs -verify %s -ast-print | FileCheck %s --check-prefix=CHECK 
--check-prefix=OMP50

Previous RUN lines miss -fopenmp-version=45



Comment at: clang/test/OpenMP/distribute_codegen.cpp:14
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple i386-unknown-unknown 
-fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -x c++ -triple i386-unknown-unknown 
-fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s 
-emit-llvm -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32 
--check-prefix HCHECK
 

Previous RUN lines miss -fopenmp-version=45



Comment at: clang/test/OpenMP/distribute_codegen.cpp:24-29
+// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple powerpc64le-unknown-unknown 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify 
%s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple i386-unknown-unknown 
-fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck 
--check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple 
i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple i386-unknown-unknown 
-fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s 
-emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s

Previous RUN lines miss -fopenmp-version=45



Comment at: clang/test/OpenMP/distribute_simd_codegen.cpp:2-7
 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s 
--check-prefix CHECK --check-prefix CHECK-64 --check-prefix OMP45
 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -x c++ -triple powerpc64le-unknown-unknown 
-fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify 
%s -emit-llvm -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64  
--check-prefix HCHECK --check-prefix OMP45
 // RUN: %clang_cc1 -verify -fopenmp -x c++ -triple i386-unknown-unknown 
-fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s 
--check-prefix CHECK --check-prefix CHECK-32  --check-prefix HCHECK 
--check-prefix OMP45
 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple i386-unknown-unknown 
-fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -x c++ -triple i386-unknown-unknown 
-fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s 
-emit-llvm -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32 
--check-prefix HCHECK --check-prefix OMP45

Missed -fopenmp-version=45


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82575



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


[clang-tools-extra] c11c78a - [clangd] Use llvm::errs() instead of outs() for errors

2020-07-15 Thread Kirill Bobyrev via cfe-commits

Author: Kirill Bobyrev
Date: 2020-07-15T14:34:29+02:00
New Revision: c11c78a1bd0b3275bf845604aae3c94e97acceed

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

LOG: [clangd] Use llvm::errs() instead of outs() for errors

Summary: errs() is more appropriate for error messages in dexp and 
clangd-index-server.

Reviewers: sammccall

Reviewed By: sammccall

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

Tags: #clang

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

Added: 


Modified: 
clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
clang-tools-extra/clangd/index/remote/server/Server.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp 
b/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
index 6fc844c18931..80d87aa3f9f5 100644
--- a/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
+++ b/clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
@@ -181,7 +181,7 @@ class Lookup : public Command {
 
   void run() override {
 if (ID.getNumOccurrences() == 0 && Name.getNumOccurrences() == 0) {
-  llvm::outs()
+  llvm::errs()
   << "Missing required argument: please provide id or -name.\n";
   return;
 }
@@ -189,7 +189,7 @@ class Lookup : public Command {
 if (ID.getNumOccurrences()) {
   auto SID = SymbolID::fromStr(ID);
   if (!SID) {
-llvm::outs() << llvm::toString(SID.takeError()) << "\n";
+llvm::errs() << llvm::toString(SID.takeError()) << "\n";
 return;
   }
   IDs.push_back(*SID);
@@ -205,7 +205,7 @@ class Lookup : public Command {
   llvm::outs() << toYAML(Sym);
 });
 if (!FoundSymbol)
-  llvm::outs() << "not found\n";
+  llvm::errs() << "not found\n";
   }
 };
 
@@ -228,7 +228,7 @@ class Refs : public Command {
 
   void run() override {
 if (ID.getNumOccurrences() == 0 && Name.getNumOccurrences() == 0) {
-  llvm::outs()
+  llvm::errs()
   << "Missing required argument: please provide id or -name.\n";
   return;
 }
@@ -236,14 +236,14 @@ class Refs : public Command {
 if (ID.getNumOccurrences()) {
   auto SID = SymbolID::fromStr(ID);
   if (!SID) {
-llvm::outs() << llvm::toString(SID.takeError()) << "\n";
+llvm::errs() << llvm::toString(SID.takeError()) << "\n";
 return;
   }
   IDs.push_back(*SID);
 } else {
   IDs = getSymbolIDsFromIndex(Name, Index);
   if (IDs.size() > 1) {
-llvm::outs() << llvm::formatv(
+llvm::errs() << llvm::formatv(
 "The name {0} is ambiguous, found {1} 
diff erent "
 "symbols. Please use id flag to disambiguate.\n",
 Name, IDs.size());
@@ -256,7 +256,7 @@ class Refs : public Command {
 Index->refs(RefRequest, [&RegexFilter](const Ref &R) {
   auto U = URI::parse(R.Location.FileURI);
   if (!U) {
-llvm::outs() << U.takeError();
+llvm::errs() << U.takeError();
 return;
   }
   if (RegexFilter.match(U->body()))
@@ -358,7 +358,7 @@ bool runCommand(std::string Request, const SymbolIndex 
&Index) {
   return Cmd.Implementation()->parseAndRun(FakeArgv, Cmd.Description,
Index);
   }
-  llvm::outs() << "Unknown command. Try 'help'.\n";
+  llvm::errs() << "Unknown command. Try 'help'.\n";
   return false;
 }
 
@@ -380,7 +380,7 @@ int main(int argc, const char *argv[]) {
  [&]() { Index = openIndex(IndexLocation); });
 
   if (!Index) {
-llvm::outs() << "Failed to open the index.\n";
+llvm::errs() << "Failed to open the index.\n";
 return -1;
   }
 

diff  --git a/clang-tools-extra/clangd/index/remote/server/Server.cpp 
b/clang-tools-extra/clangd/index/remote/server/Server.cpp
index 718d623a4845..fecd72806cbc 100644
--- a/clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ b/clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -141,14 +141,14 @@ int main(int argc, char *argv[]) {
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
 
   if (!llvm::sys::path::is_absolute(IndexRoot)) {
-llvm::outs() << "Index root should be an absolute path.\n";
+llvm::errs() << "Index root should be an absolute path.\n";
 return -1;
   }
 
   std::unique_ptr Index = openIndex(IndexPath);
 
   if (!Index) {
-llvm::outs() << "Failed to open the index.\n";
+llvm::errs() << "Failed to open the index.\n";
 return -1;
   }
 



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


[PATCH] D83827: [clangd] Use llvm::errs() instead of outs() for errors

2020-07-15 Thread Kirill Bobyrev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc11c78a1bd0b: [clangd] Use llvm::errs() instead of outs() 
for errors (authored by kbobyrev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83827

Files:
  clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
  clang-tools-extra/clangd/index/remote/server/Server.cpp

Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -141,14 +141,14 @@
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
 
   if (!llvm::sys::path::is_absolute(IndexRoot)) {
-llvm::outs() << "Index root should be an absolute path.\n";
+llvm::errs() << "Index root should be an absolute path.\n";
 return -1;
   }
 
   std::unique_ptr Index = openIndex(IndexPath);
 
   if (!Index) {
-llvm::outs() << "Failed to open the index.\n";
+llvm::errs() << "Failed to open the index.\n";
 return -1;
   }
 
Index: clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
===
--- clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
+++ clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
@@ -181,7 +181,7 @@
 
   void run() override {
 if (ID.getNumOccurrences() == 0 && Name.getNumOccurrences() == 0) {
-  llvm::outs()
+  llvm::errs()
   << "Missing required argument: please provide id or -name.\n";
   return;
 }
@@ -189,7 +189,7 @@
 if (ID.getNumOccurrences()) {
   auto SID = SymbolID::fromStr(ID);
   if (!SID) {
-llvm::outs() << llvm::toString(SID.takeError()) << "\n";
+llvm::errs() << llvm::toString(SID.takeError()) << "\n";
 return;
   }
   IDs.push_back(*SID);
@@ -205,7 +205,7 @@
   llvm::outs() << toYAML(Sym);
 });
 if (!FoundSymbol)
-  llvm::outs() << "not found\n";
+  llvm::errs() << "not found\n";
   }
 };
 
@@ -228,7 +228,7 @@
 
   void run() override {
 if (ID.getNumOccurrences() == 0 && Name.getNumOccurrences() == 0) {
-  llvm::outs()
+  llvm::errs()
   << "Missing required argument: please provide id or -name.\n";
   return;
 }
@@ -236,14 +236,14 @@
 if (ID.getNumOccurrences()) {
   auto SID = SymbolID::fromStr(ID);
   if (!SID) {
-llvm::outs() << llvm::toString(SID.takeError()) << "\n";
+llvm::errs() << llvm::toString(SID.takeError()) << "\n";
 return;
   }
   IDs.push_back(*SID);
 } else {
   IDs = getSymbolIDsFromIndex(Name, Index);
   if (IDs.size() > 1) {
-llvm::outs() << llvm::formatv(
+llvm::errs() << llvm::formatv(
 "The name {0} is ambiguous, found {1} different "
 "symbols. Please use id flag to disambiguate.\n",
 Name, IDs.size());
@@ -256,7 +256,7 @@
 Index->refs(RefRequest, [&RegexFilter](const Ref &R) {
   auto U = URI::parse(R.Location.FileURI);
   if (!U) {
-llvm::outs() << U.takeError();
+llvm::errs() << U.takeError();
 return;
   }
   if (RegexFilter.match(U->body()))
@@ -358,7 +358,7 @@
   return Cmd.Implementation()->parseAndRun(FakeArgv, Cmd.Description,
Index);
   }
-  llvm::outs() << "Unknown command. Try 'help'.\n";
+  llvm::errs() << "Unknown command. Try 'help'.\n";
   return false;
 }
 
@@ -380,7 +380,7 @@
  [&]() { Index = openIndex(IndexLocation); });
 
   if (!Index) {
-llvm::outs() << "Failed to open the index.\n";
+llvm::errs() << "Failed to open the index.\n";
 return -1;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83863: [OpenMP] Change version 4.5 hardcoded clang tests to default OpenMP version

2020-07-15 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

Not sure that this is really required. If we want to check for the default 
version, it would be good to check that it still works for 4.5. It means, need 
to add additional RUN lines. But I don't think it is profitable to test the 
same functionality several times without actual effect


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83863



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


[PATCH] D83863: [OpenMP] Change version 4.5 hardcoded clang tests to default OpenMP version

2020-07-15 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam added a comment.

In D83863#2153008 , @ABataev wrote:

> Not sure that this is really required. If we want to check for the default 
> version, it would be good to check that it still works for 4.5. It means, 
> need to add additional RUN lines. But I don't think it is profitable to test 
> the same functionality several times without actual effect


These 67 files were testing only for version 4.5. As the default version is now 
5.0, isn't it expected that the tests run against it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83863



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


[PATCH] D71124: [RISCV] support clang driver to select cpu

2020-07-15 Thread Sam Elliott via Phabricator via cfe-commits
lenary added a comment.

Thanks for the fix!

Please can you also update `clang/test/Misc/target-invalid-cpu-note.c` for 
riscv32 and riscv64 - it's likely you'll need the fix in the inline note below.

Also, there are a bunch of clang-tidy issues, which I think we can fix now 
rather than later.




Comment at: llvm/lib/Support/TargetParser.cpp:250
+  for (const auto &C : RISCVCPUInfo) {
+if (IsRV64 == C.Is64Bit())
+  Values.emplace_back(C.Name);

This line should be `if (C.Kind != CK_INVALID && IsRV64 == C.Is64Bit())` so 
that when clang prints out valid CPUs, 'invalid' is not included in the list. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71124



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


[PATCH] D83863: [OpenMP] Change version 4.5 hardcoded clang tests to default OpenMP version

2020-07-15 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D83863#2153021 , @saiislam wrote:

> In D83863#2153008 , @ABataev wrote:
>
> > Not sure that this is really required. If we want to check for the default 
> > version, it would be good to check that it still works for 4.5. It means, 
> > need to add additional RUN lines. But I don't think it is profitable to 
> > test the same functionality several times without actual effect
>
>
> These 67 files were testing only for version 4.5. As the default version is 
> now 5.0, isn't it expected that the tests run against it?


It just means that there are no changes in functionality between 4.5 and 5.0. 
Sure, you can switch to the default version instead but I don't see real profit 
here. Anyway, it is up to you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83863



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


[PATCH] D83863: [OpenMP] Change version 4.5 hardcoded clang tests to default OpenMP version

2020-07-15 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam added a comment.

In D83863#2153031 , @ABataev wrote:

> In D83863#2153021 , @saiislam wrote:
>
> > In D83863#2153008 , @ABataev wrote:
> >
> > > Not sure that this is really required. If we want to check for the 
> > > default version, it would be good to check that it still works for 4.5. 
> > > It means, need to add additional RUN lines. But I don't think it is 
> > > profitable to test the same functionality several times without actual 
> > > effect
> >
> >
> > These 67 files were testing only for version 4.5. As the default version is 
> > now 5.0, isn't it expected that the tests run against it?
>
>
> It just means that there are no changes in functionality between 4.5 and 5.0. 
> Sure, you can switch to the default version instead but I don't see real 
> profit here. Anyway, it is up to you.


I was considering a scenario where there is a divergent behavior between 4.5 
and a future version X. If we don't remove these version specific strings from 
the test files which are only testing for 4.5, user won't be notified about the 
divergent behavior of version X. If these tests fail there, then specific 
divergent behavior can be annotated with version specific tags, like in most of 
the other test cases. Does it make sense?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83863



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


[PATCH] D83863: [OpenMP] Change version 4.5 hardcoded clang tests to default OpenMP version

2020-07-15 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/test/OpenMP/parallel_default_messages.cpp:7-8
 // RUN: %clang_cc1 -verify -fopenmp-version=30 -fopenmp -ferror-limit 100 -o - 
%s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,ge40 -fopenmp -ferror-limit 100 -o - %s 
-Wuninitialized
+// RUN: %clang_cc1 -verify=expected,ge40 -fopenmp -ferror-limit 100 -o - %s 
-Wuninitialized
 // RUN: %clang_cc1 -verify=expected,ge40 -fopenmp-version=51 -fopenmp -DOMP51 
-ferror-limit 100 -o - %s -Wuninitialized

Same as first 2 lines



Comment at: clang/test/OpenMP/target_ast_print.cpp:5-11
+// RUN: %clang_cc1 -DOMP45 -verify -fopenmp -ast-print %s | FileCheck %s 
--check-prefix=OMP45
+// RUN: %clang_cc1 -DOMP45 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
+// RUN: %clang_cc1 -DOMP45 -fopenmp -std=c++11 -include-pch %t -fsyntax-only 
-verify %s -ast-print | FileCheck %s --check-prefix=OMP45
 
-// RUN: %clang_cc1 -DOMP45 -verify -fopenmp-simd -fopenmp-version=45 
-ast-print %s | FileCheck %s --check-prefix=OMP45
-// RUN: %clang_cc1 -DOMP45 -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 
-emit-pch -o %t %s
-// RUN: %clang_cc1 -DOMP45 -fopenmp-simd -fopenmp-version=45 -std=c++11 
-include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s 
--check-prefix=OMP45
+// RUN: %clang_cc1 -DOMP45 -verify -fopenmp-simd -ast-print %s | FileCheck %s 
--check-prefix=OMP45
+// RUN: %clang_cc1 -DOMP45 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s
+// RUN: %clang_cc1 -DOMP45 -fopenmp-simd -std=c++11 -include-pch %t 
-fsyntax-only -verify %s -ast-print | FileCheck %s --check-prefix=OMP45

Better to remove -fopenmp-version from the tests for OpenMP 5.0


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83863



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


[PATCH] D83621: [clang][Tooling] Try to avoid file system access if there is no record for the file in compile_commads.json

2020-07-15 Thread Aleksandr Platonov via Phabricator via cfe-commits
ArcsinX updated this revision to Diff 278161.
ArcsinX added a comment.

Support only directory simlinks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83621

Files:
  clang/lib/Tooling/FileMatchTrie.cpp
  clang/unittests/Tooling/CompilationDatabaseTest.cpp


Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -281,6 +281,15 @@
   EXPECT_EQ("Cannot resolve relative paths", Error);
 }
 
+TEST_F(FileMatchTrieTest, SingleFile) {
+  Trie.insert("/root/RootFile.cc");
+  EXPECT_EQ("", find("/root/rootfile.cc"));
+  // Add subpath to avoid `if (Children.empty())` special case
+  // which we hit at previous `find()`.
+  Trie.insert("/root/otherpath/OtherFile.cc");
+  EXPECT_EQ("", find("/root/rootfile.cc"));
+}
+
 TEST(findCompileArgsInJsonDatabase, FindsNothingIfEmpty) {
   std::string ErrorMessage;
   CompileCommand NotFound = findCompileArgsInJsonDatabase(
Index: clang/lib/Tooling/FileMatchTrie.cpp
===
--- clang/lib/Tooling/FileMatchTrie.cpp
+++ clang/lib/Tooling/FileMatchTrie.cpp
@@ -105,8 +105,13 @@
StringRef FileName,
bool &IsAmbiguous,
unsigned ConsumedLength = 0) const {
+// Note: we support only directory symlinks for performance reasons.
 if (Children.empty()) {
-  if (Comparator.equivalent(StringRef(Path), FileName))
+  // As far as we do not support file symlinks we compare
+  // basenames here to avoid expensive request to file system.
+  if (llvm::sys::path::filename(Path) ==
+  llvm::sys::path::filename(FileName) &&
+  Comparator.equivalent(StringRef(Path), FileName))
 return StringRef(Path);
   return {};
 }
@@ -121,6 +126,15 @@
   if (!Result.empty() || IsAmbiguous)
 return Result;
 }
+
+// We failed to find the file with `Children.find()`.
+// If `ConsumedLength` is equal to 0 then we have tried to find the file
+// with it's basename. Thus, we do not have files with the same
+// basename and could return empty result here as far as we
+// do not support file symlinks.
+if (ConsumedLength == 0)
+  return {};
+
 std::vector AllChildren;
 getAll(AllChildren, MatchingChild);
 StringRef Result;


Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -281,6 +281,15 @@
   EXPECT_EQ("Cannot resolve relative paths", Error);
 }
 
+TEST_F(FileMatchTrieTest, SingleFile) {
+  Trie.insert("/root/RootFile.cc");
+  EXPECT_EQ("", find("/root/rootfile.cc"));
+  // Add subpath to avoid `if (Children.empty())` special case
+  // which we hit at previous `find()`.
+  Trie.insert("/root/otherpath/OtherFile.cc");
+  EXPECT_EQ("", find("/root/rootfile.cc"));
+}
+
 TEST(findCompileArgsInJsonDatabase, FindsNothingIfEmpty) {
   std::string ErrorMessage;
   CompileCommand NotFound = findCompileArgsInJsonDatabase(
Index: clang/lib/Tooling/FileMatchTrie.cpp
===
--- clang/lib/Tooling/FileMatchTrie.cpp
+++ clang/lib/Tooling/FileMatchTrie.cpp
@@ -105,8 +105,13 @@
StringRef FileName,
bool &IsAmbiguous,
unsigned ConsumedLength = 0) const {
+// Note: we support only directory symlinks for performance reasons.
 if (Children.empty()) {
-  if (Comparator.equivalent(StringRef(Path), FileName))
+  // As far as we do not support file symlinks we compare
+  // basenames here to avoid expensive request to file system.
+  if (llvm::sys::path::filename(Path) ==
+  llvm::sys::path::filename(FileName) &&
+  Comparator.equivalent(StringRef(Path), FileName))
 return StringRef(Path);
   return {};
 }
@@ -121,6 +126,15 @@
   if (!Result.empty() || IsAmbiguous)
 return Result;
 }
+
+// We failed to find the file with `Children.find()`.
+// If `ConsumedLength` is equal to 0 then we have tried to find the file
+// with it's basename. Thus, we do not have files with the same
+// basename and could return empty result here as far as we
+// do not support file symlinks.
+if (ConsumedLength == 0)
+  return {};
+
 std::vector AllChildren;
 getAll(AllChildren, MatchingChild);
 StringRef Result;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D83826: [clangd] Don't send invalid messages from remote index

2020-07-15 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev marked 4 inline comments as done.
kbobyrev added a comment.

In D83826#2152857 , @sammccall wrote:

> > Also add more error messages and logs.
>
> I'm not sure about the error-handling strategy here:
>
> - it's very verbose in the marshalling code. Are we sure it pays for itself? 
> For comparison, the marshalling code for LSP itself silently returns `false` 
> on error, which is handled at the top level. It's been fine so far.
> - some errors are being logged that are not errors. e.g. it's not an error to 
> drop a symbol because its declaration is in a file outside the index root, 
> that's just expected behavior


Can you give an example of this? Missing d

> - it's not clear which levels are responsible for logging errors, leaving the 
> possibility that some errors will be logged twice or not at all
> - it's not easy to change if we want a slightly different strategy
> 
>   I'd suggest leaving out detailed error reporting for now, and reporting at 
> the top level. You may need some mechanism to distinguish invalid vs 
> filtered-out data. It could be something like a "filtered out" flag that 
> causes the error reporting to be suppressed. There are more design options 
> here if marshalling is a class I think.

Fair enough, will do. Thanks!




Comment at: 
clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp:151
   !Message.has_canonical_declaration()) {
-elog("Cannot convert Symbol from Protobuf: {0}",
+elog("Cannot convert Symbol from Protobuf (missing info, definition or "
+ "declaration): {1}",

sammccall wrote:
> aren't all these placeholders incorrect? first is {0}
I think they still work for some reason. Anyway, starting with `{0}` is OK, I 
think they're just off in some places.



Comment at: 
clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp:167
   Result.Scope = Message.scope();
   auto Definition = fromProtobuf(Message.definition(), Strings, IndexRoot);
+  if (!Definition) {

sammccall wrote:
> missing definition is perfectly valid, so both the old and new code look 
> wrong here
Oh, you're right missing definition is indeed OK, but having an invalid one 
should still be invalid. I guess I should check if it's empty.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83826



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


[PATCH] D83826: [clangd] Don't send invalid messages from remote index

2020-07-15 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 278162.
kbobyrev marked an inline comment as done.
kbobyrev added a comment.

Small update: resolve a couple of comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83826

Files:
  clang-tools-extra/clangd/index/remote/Client.cpp
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
  clang-tools-extra/clangd/index/remote/server/Server.cpp
  clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp

Index: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
===
--- clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -46,10 +46,11 @@
   Strings);
   auto Serialized =
   toProtobuf(Original, testPath("remote/machine/projects/llvm-project/"));
-  EXPECT_EQ(Serialized.location().file_path(),
+  EXPECT_TRUE(Serialized);
+  EXPECT_EQ(Serialized->location().file_path(),
 "clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp");
   const std::string LocalIndexPrefix = testPath("local/machine/project/");
-  auto Deserialized = fromProtobuf(Serialized, &Strings,
+  auto Deserialized = fromProtobuf(*Serialized, &Strings,
testPath("home/my-projects/llvm-project/"));
   EXPECT_TRUE(Deserialized);
   EXPECT_EQ(Deserialized->Location.FileURI,
@@ -57,11 +58,16 @@
 "clangd/unittests/remote/MarshallingTests.cpp",
 Strings));
 
+  // Can't have empty paths.
+  *Serialized->mutable_location()->mutable_file_path() = std::string();
+  Deserialized = fromProtobuf(*Serialized, &Strings, LocalIndexPrefix);
+  EXPECT_FALSE(Deserialized);
+
   clangd::Ref WithInvalidURI;
-  // Invalid URI results in empty path.
+  // Invalid URI results in serialization failure.
   WithInvalidURI.Location.FileURI = "This is not a URI";
   Serialized = toProtobuf(WithInvalidURI, testPath("home/"));
-  EXPECT_EQ(Serialized.location().file_path(), "");
+  EXPECT_FALSE(Serialized);
 
   // Can not use URIs with scheme different from "file".
   auto UnittestURI =
@@ -70,7 +76,7 @@
   WithInvalidURI.Location.FileURI =
   Strings.save(UnittestURI->toString()).begin();
   Serialized = toProtobuf(WithInvalidURI, testPath("project/lib/"));
-  EXPECT_EQ(Serialized.location().file_path(), "");
+  EXPECT_FALSE(Serialized);
 
   Ref WithAbsolutePath;
   *WithAbsolutePath.mutable_location()->mutable_file_path() =
@@ -131,22 +137,28 @@
   // Check that symbols are exactly the same if the path to indexed project is
   // the same on indexing machine and the client.
   auto Serialized = toProtobuf(Sym, testPath("home/"));
-  auto Deserialized = fromProtobuf(Serialized, &Strings, testPath("home/"));
+  EXPECT_TRUE(Serialized);
+  auto Deserialized = fromProtobuf(*Serialized, &Strings, testPath("home/"));
   EXPECT_TRUE(Deserialized);
   EXPECT_EQ(toYAML(Sym), toYAML(*Deserialized));
   // Serialized paths are relative and have UNIX slashes.
-  EXPECT_EQ(convert_to_slash(Serialized.definition().file_path(),
+  EXPECT_EQ(convert_to_slash(Serialized->definition().file_path(),
  llvm::sys::path::Style::posix),
-Serialized.definition().file_path());
+Serialized->definition().file_path());
   EXPECT_TRUE(
-  llvm::sys::path::is_relative(Serialized.definition().file_path()));
+  llvm::sys::path::is_relative(Serialized->definition().file_path()));
+
+  // Relative path is absolute.
+  *Serialized->mutable_canonical_declaration()->mutable_file_path() =
+  convert_to_slash("/path/to/Declaration.h");
+  Deserialized = fromProtobuf(*Serialized, &Strings, testPath("home/"));
+  EXPECT_FALSE(Deserialized);
 
   // Fail with an invalid URI.
   Location.FileURI = "Not A URI";
   Sym.Definition = Location;
   Serialized = toProtobuf(Sym, testPath("home/"));
-  Deserialized = fromProtobuf(Serialized, &Strings, testPath("home/"));
-  EXPECT_FALSE(Deserialized);
+  EXPECT_FALSE(Serialized);
 
   // Schemes other than "file" can not be used.
   auto UnittestURI = URI::create(testPath("home/SomePath.h"), "unittest");
@@ -154,22 +166,21 @@
   Location.FileURI = Strings.save(UnittestURI->toString()).begin();
   Sym.Definition = Location;
   Serialized = toProtobuf(Sym, testPath("home/"));
-  Deserialized = fromProtobuf(Serialized, &Strings, testPath("home/"));
-  EXPECT_FALSE(Deserialized);
+  EXPECT_FALSE(Serialized);
 
   // Passing root that is not prefix of the original file path.
   Location.FileURI = testPathURI("home/File.h", Strings);
   Sym.Definition = Location;
   // Check that the symbol is valid and passing the correct path works.
   Serialized = toProtobuf(Sym, testPath("home/"));
-  Deserialized = fromProtobuf(Serialized, &S

[PATCH] D72932: [ARM] Follow AACPS standard for volatile bit-fields access width

2020-07-15 Thread Diogo N. Sampaio via Phabricator via cfe-commits
dnsampaio added a comment.
Herald added a subscriber: dang.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72932



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


[PATCH] D83868: Use TestClangConfig in AST Matchers tests and run them in more configurations

2020-07-15 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I am changing tests for AST Matchers to run in multiple language standards
versions, and under multiple triples that have different behavior with regards
to templates. This change is similar to https://reviews.llvm.org/D82179.

To keep the size of the patch manageable, in this patch I'm only migrating one
file to get the process started and get feedback on this approach.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83868

Files:
  clang/include/clang/Testing/TestClangConfig.h
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTest.h

Index: clang/unittests/ASTMatchers/ASTMatchersTest.h
===
--- clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ clang/unittests/ASTMatchers/ASTMatchersTest.h
@@ -183,11 +183,6 @@
   "input.c");
 }
 
-template 
-testing::AssertionResult notMatchesC(const Twine &Code, const T &AMatcher) {
-  return matchesConditionally(Code, AMatcher, false, {Lang_C89});
-}
-
 template 
 testing::AssertionResult notMatchesObjC(const Twine &Code, const T &AMatcher) {
   return matchesObjC(Code, AMatcher, false);
Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -18,7 +18,7 @@
 namespace clang {
 namespace ast_matchers {
 
-TEST(IsExpandedFromMacro, ShouldMatchInFile) {
+TEST_P(ASTMatchersTest, IsExpandedFromMacro_MatchesInFile) {
   StringRef input = R"cc(
 #define MY_MACRO(a) (4 + (a))
 void Test() { MY_MACRO(4); }
@@ -26,7 +26,7 @@
   EXPECT_TRUE(matches(input, binaryOperator(isExpandedFromMacro("MY_MACRO";
 }
 
-TEST(IsExpandedFromMacro, ShouldMatchNested) {
+TEST_P(ASTMatchersTest, IsExpandedFromMacro_MatchesNested) {
   StringRef input = R"cc(
 #define MY_MACRO(a) (4 + (a))
 #define WRAPPER(a) MY_MACRO(a)
@@ -35,7 +35,7 @@
   EXPECT_TRUE(matches(input, binaryOperator(isExpandedFromMacro("MY_MACRO";
 }
 
-TEST(IsExpandedFromMacro, ShouldMatchIntermediate) {
+TEST_P(ASTMatchersTest, IsExpandedFromMacro_MatchesIntermediate) {
   StringRef input = R"cc(
 #define IMPL(a) (4 + (a))
 #define MY_MACRO(a) IMPL(a)
@@ -45,7 +45,7 @@
   EXPECT_TRUE(matches(input, binaryOperator(isExpandedFromMacro("MY_MACRO";
 }
 
-TEST(IsExpandedFromMacro, ShouldMatchTransitive) {
+TEST_P(ASTMatchersTest, IsExpandedFromMacro_MatchesTransitive) {
   StringRef input = R"cc(
 #define MY_MACRO(a) (4 + (a))
 #define WRAPPER(a) MY_MACRO(a)
@@ -54,7 +54,7 @@
   EXPECT_TRUE(matches(input, binaryOperator(isExpandedFromMacro("WRAPPER";
 }
 
-TEST(IsExpandedFromMacro, ShouldMatchArgument) {
+TEST_P(ASTMatchersTest, IsExpandedFromMacro_MatchesArgument) {
   StringRef input = R"cc(
 #define MY_MACRO(a) (4 + (a))
 void Test() {
@@ -65,9 +65,9 @@
   EXPECT_TRUE(matches(input, declRefExpr(isExpandedFromMacro("MY_MACRO";
 }
 
-// Like IsExpandedFromMacroShouldMatchArgumentMacro, but the argument is itself
-// a macro.
-TEST(IsExpandedFromMacro, ShouldMatchArgumentMacroExpansion) {
+// Like IsExpandedFromMacro_MatchesArgument, but the argument is itself a
+// macro.
+TEST_P(ASTMatchersTest, IsExpandedFromMacro_MatchesArgumentMacroExpansion) {
   StringRef input = R"cc(
 #define MY_MACRO(a) (4 + (a))
 #define IDENTITY(a) (a)
@@ -78,7 +78,7 @@
   EXPECT_TRUE(matches(input, binaryOperator(isExpandedFromMacro("IDENTITY";
 }
 
-TEST(IsExpandedFromMacro, ShouldMatchWhenInArgument) {
+TEST_P(ASTMatchersTest, IsExpandedFromMacro_MatchesWhenInArgument) {
   StringRef input = R"cc(
 #define MY_MACRO(a) (4 + (a))
 #define IDENTITY(a) (a)
@@ -89,7 +89,7 @@
   EXPECT_TRUE(matches(input, binaryOperator(isExpandedFromMacro("MY_MACRO";
 }
 
-TEST(IsExpandedFromMacro, ShouldMatchObjectMacro) {
+TEST_P(ASTMatchersTest, IsExpandedFromMacro_MatchesObjectMacro) {
   StringRef input = R"cc(
 #define PLUS (2 + 2)
 void Test() {
@@ -99,7 +99,7 @@
   EXPECT_TRUE(matches(input, binaryOperator(isExpandedFromMacro("PLUS";
 }
 
-TEST(IsExpandedFromMacro, ShouldMatchFromCommandLine) {
+TEST(IsExpandedFromMacro, MatchesFromCommandLine) {
   StringRef input = R"cc(
 void Test() { FOUR_PLUS_FOUR; }
   )cc";
@@ -108,7 +108,7 @@
   {"-std=c++11", "-DFOUR_PLUS_FOUR=4+4"}));
 }
 
-TEST(IsExpandedFromMacro, ShouldNotMatchBeginOnly) {
+TEST_P(ASTMatchersTest, IsExpandedFromMacro_NotMatchesBeginOnly) {
   StringRef input = R"cc(
 #define ONE_PLUS 1+
   void Test() { ONE_PLUS 4; }
@@ -117,7 +117,7 @@
   notMatches(input, binaryOperator(isExpandedFromMacro("ONE_PLUS";
 }
 
-TEST(IsExpandedFromMacro, ShouldNotMatchEndOnly) {
+TEST_P(ASTMatchersTest, IsExpandedFromMacro_NotMatchesEndOnly) {
   StringRef input = R"cc(
 #define PLUS_ONE +1
   void Test() { 4

[PATCH] D83863: [OpenMP] Change version 4.5 hardcoded clang tests to default OpenMP version

2020-07-15 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam marked an inline comment as done.
saiislam added inline comments.



Comment at: clang/test/OpenMP/target_ast_print.cpp:5-11
+// RUN: %clang_cc1 -DOMP45 -verify -fopenmp -ast-print %s | FileCheck %s 
--check-prefix=OMP45
+// RUN: %clang_cc1 -DOMP45 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
+// RUN: %clang_cc1 -DOMP45 -fopenmp -std=c++11 -include-pch %t -fsyntax-only 
-verify %s -ast-print | FileCheck %s --check-prefix=OMP45
 
-// RUN: %clang_cc1 -DOMP45 -verify -fopenmp-simd -fopenmp-version=45 
-ast-print %s | FileCheck %s --check-prefix=OMP45
-// RUN: %clang_cc1 -DOMP45 -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 
-emit-pch -o %t %s
-// RUN: %clang_cc1 -DOMP45 -fopenmp-simd -fopenmp-version=45 -std=c++11 
-include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s 
--check-prefix=OMP45
+// RUN: %clang_cc1 -DOMP45 -verify -fopenmp-simd -ast-print %s | FileCheck %s 
--check-prefix=OMP45
+// RUN: %clang_cc1 -DOMP45 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s
+// RUN: %clang_cc1 -DOMP45 -fopenmp-simd -std=c++11 -include-pch %t 
-fsyntax-only -verify %s -ast-print | FileCheck %s --check-prefix=OMP45

ABataev wrote:
> Better to remove -fopenmp-version from the tests for OpenMP 5.0
Yes, that's the plan. D82575 is supposed to remove -fopenmp-version=50 from 
everywhere. And this patch is supposed to ensure that all tests are testing at 
least for the default version.

Plan is to keep version strings only at places where there is specific 
divergent behaviors between different versions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83863



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


[PATCH] D83681: [clang] Provide a more specific diagnostic for a misplaced lambda capture-default.

2020-07-15 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno updated this revision to Diff 278164.
riccibruno marked 3 inline comments as done.
riccibruno added a comment.

Add some tests showing that a by-ref capture is still parsed properly, 
including some tests with a capture containing a pack expansion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83681

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseExprCXX.cpp
  clang/test/Parser/lambda-misplaced-capture-default.cpp


Index: clang/test/Parser/lambda-misplaced-capture-default.cpp
===
--- /dev/null
+++ clang/test/Parser/lambda-misplaced-capture-default.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -std=c++20 -Wno-unused-value -fsyntax-only -verify %s
+
+namespace misplaced_capture_default {
+void Test() {
+  int i = 0;
+  [&, i, &] {};   // expected-error {{expected variable name or 'this' in 
lambda capture list}}
+  [&, i, = ] {};  // expected-error {{expected variable name or 'this' in 
lambda capture list}}
+  [=, &i, &] {};  // expected-error {{expected variable name or 'this' in 
lambda capture list}}
+  [=, &i, = ] {}; // expected-error {{expected variable name or 'this' in 
lambda capture list}}
+
+  [i, &] {};   // expected-error {{capture default must be first}}
+  [i, = ] {};  // expected-error {{capture default must be first}}
+  [i, = x] {}; // expected-error {{expected variable name or 'this' in lambda 
capture list}}
+  [=, &i] {};  // ok
+  [&, &i] {};  // expected-error {{'&' cannot precede a capture when the 
capture default is '&'}}
+  [&x = i] {}; // ok
+  [=, &x = i] {};  // ok
+  [x = &i] {}; // ok
+  [=, &x = &i] {}; // expected-error {{non-const lvalue reference to type 'int 
*' cannot bind to a temporary of type 'int *'}}
+  [&, this] {}; // expected-error {{'this' cannot be captured in this context}}
+
+  [i, &, x = 2] {}; // expected-error {{capture default must be first}}
+  [i, =, x = 2] {}; // expected-error {{capture default must be first}}
+}
+} // namespace misplaced_capture_default
+
+namespace misplaced_capture_default_pack {
+template  void Test(Args... args) {
+  [&, args...] {}; // ok
+  [args..., &] {}; // expected-error {{capture default must be first}}
+  [=, &args...] {};// ok
+  [&, ... xs = &args] {};  // ok
+  [&, ... xs = &] {};  // expected-error {{expected expression}}
+  [... xs = &] {}; // expected-error {{expected expression}}
+  [... xs = &args, = ] {}; // expected-error {{capture default must be first}}
+  [... xs = &args, &] {};  // expected-error {{capture default must be first}}
+}
+} // namespace misplaced_capture_default_pack
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -926,6 +926,15 @@
 } else if (Tok.is(tok::kw_this)) {
   Kind = LCK_This;
   Loc = ConsumeToken();
+} else if (Tok.isOneOf(tok::amp, tok::equal) &&
+   NextToken().isOneOf(tok::comma, tok::r_square) &&
+   Intro.Default == LCD_None) {
+  // We have a lone "&" or "=" which is either a misplaced capture-default
+  // or the start of a capture (in the "&" case) with the rest of the
+  // capture missing. Both are an error but a misplaced capture-default
+  // is more likely if we don't already have a capture default.
+  return Invalid(
+  [&] { Diag(Tok.getLocation(), diag::err_capture_default_first); });
 } else {
   TryConsumeToken(tok::ellipsis, EllipsisLocs[0]);
 
Index: clang/include/clang/Basic/DiagnosticParseKinds.td
===
--- clang/include/clang/Basic/DiagnosticParseKinds.td
+++ clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -934,6 +934,8 @@
   "the name of the capture">;
 def err_lambda_capture_multiple_ellipses : Error<
   "multiple ellipses in pack capture">;
+def err_capture_default_first : Error<
+  "capture default must be first">;
 // C++17 lambda expressions
 def err_expected_star_this_capture : Error<
   "expected 'this' following '*' in lambda capture list">;


Index: clang/test/Parser/lambda-misplaced-capture-default.cpp
===
--- /dev/null
+++ clang/test/Parser/lambda-misplaced-capture-default.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -std=c++20 -Wno-unused-value -fsyntax-only -verify %s
+
+namespace misplaced_capture_default {
+void Test() {
+  int i = 0;
+  [&, i, &] {};   // expected-error {{expected variable name or 'this' in lambda capture list}}
+  [&, i, = ] {};  // expected-error {{expected variable name or 'this' in lambda capture list}}
+  [=, &i, &] {};  // expected-error {{expected variable name or 'this' in lambda capture list}}
+  [=, &i, = ] {}; // expected-error {{expected variable name or

[PATCH] D83697: Port Frontend option flags to new option parsing system

2020-07-15 Thread Daniel Grumberg via Phabricator via cfe-commits
dang updated this revision to Diff 278167.
dang added a comment.

Make sure that ast_dump_* are correctly labelled as belonging to Action_Group.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83697

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Frontend/CompilerInvocation.cpp

Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -289,9 +289,11 @@
   LangOptions &LangOpts = *Invocation.getLangOpts();
   DiagnosticOptions &DiagOpts = Invocation.getDiagnosticOpts();
   CodeGenOptions &CodeGenOpts = Invocation.getCodeGenOpts();
+  FrontendOptions &FrontendOpts = Invocation.getFrontendOpts();
   CodeGenOpts.XRayInstrumentFunctions = LangOpts.XRayInstrument;
   CodeGenOpts.XRayAlwaysEmitCustomEvents = LangOpts.XRayAlwaysEmitCustomEvents;
   CodeGenOpts.XRayAlwaysEmitTypedEvents = LangOpts.XRayAlwaysEmitTypedEvents;
+  FrontendOpts.GenerateGlobalModuleIndex = FrontendOpts.UseGlobalModuleIndex;
 
   llvm::sys::Process::UseANSIEscapeCodes(DiagOpts.UseANSIEscapeCodes);
 }
@@ -1941,32 +1943,16 @@
   Diags.Report(diag::err_drv_invalid_value)
 << A->getAsString(Args) << A->getValue();
   }
-  Opts.DisableFree = Args.hasArg(OPT_disable_free);
 
   Opts.OutputFile = std::string(Args.getLastArgValue(OPT_o));
   Opts.Plugins = Args.getAllArgValues(OPT_load);
-  Opts.RelocatablePCH = Args.hasArg(OPT_relocatable_pch);
-  Opts.ShowHelp = Args.hasArg(OPT_help);
-  Opts.ShowStats = Args.hasArg(OPT_print_stats);
-  Opts.ShowTimers = Args.hasArg(OPT_ftime_report);
-  Opts.PrintSupportedCPUs = Args.hasArg(OPT_print_supported_cpus);
-  Opts.TimeTrace = Args.hasArg(OPT_ftime_trace);
   Opts.TimeTraceGranularity = getLastArgIntValue(
   Args, OPT_ftime_trace_granularity_EQ, Opts.TimeTraceGranularity, Diags);
-  Opts.ShowVersion = Args.hasArg(OPT_version);
   Opts.ASTMergeFiles = Args.getAllArgValues(OPT_ast_merge);
   Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);
-  Opts.FixWhatYouCan = Args.hasArg(OPT_fix_what_you_can);
-  Opts.FixOnlyWarnings = Args.hasArg(OPT_fix_only_warnings);
-  Opts.FixAndRecompile = Args.hasArg(OPT_fixit_recompile);
-  Opts.FixToTemporaries = Args.hasArg(OPT_fixit_to_temp);
   Opts.ASTDumpDecls = Args.hasArg(OPT_ast_dump, OPT_ast_dump_EQ);
   Opts.ASTDumpAll = Args.hasArg(OPT_ast_dump_all, OPT_ast_dump_all_EQ);
   Opts.ASTDumpFilter = std::string(Args.getLastArgValue(OPT_ast_dump_filter));
-  Opts.ASTDumpLookups = Args.hasArg(OPT_ast_dump_lookups);
-  Opts.ASTDumpDeclTypes = Args.hasArg(OPT_ast_dump_decl_types);
-  Opts.UseGlobalModuleIndex = !Args.hasArg(OPT_fno_modules_global_index);
-  Opts.GenerateGlobalModuleIndex = Opts.UseGlobalModuleIndex;
   Opts.ModuleMapFiles = Args.getAllArgValues(OPT_fmodule_map_file);
   // Only the -fmodule-file= form.
   for (const auto *A : Args.filtered(OPT_fmodule_file)) {
@@ -1975,28 +1961,11 @@
   Opts.ModuleFiles.push_back(std::string(Val));
   }
   Opts.ModulesEmbedFiles = Args.getAllArgValues(OPT_fmodules_embed_file_EQ);
-  Opts.ModulesEmbedAllFiles = Args.hasArg(OPT_fmodules_embed_all_files);
-  Opts.IncludeTimestamps = !Args.hasArg(OPT_fno_pch_timestamp);
-  Opts.UseTemporary = !Args.hasArg(OPT_fno_temp_file);
-  Opts.IsSystemModule = Args.hasArg(OPT_fsystem_module);
 
   if (Opts.ProgramAction != frontend::GenerateModule && Opts.IsSystemModule)
 Diags.Report(diag::err_drv_argument_only_allowed_with) << "-fsystem-module"
<< "-emit-module";
 
-  Opts.CodeCompleteOpts.IncludeMacros
-= Args.hasArg(OPT_code_completion_macros);
-  Opts.CodeCompleteOpts.IncludeCodePatterns
-= Args.hasArg(OPT_code_completion_patterns);
-  Opts.CodeCompleteOpts.IncludeGlobals
-= !Args.hasArg(OPT_no_code_completion_globals);
-  Opts.CodeCompleteOpts.IncludeNamespaceLevelDecls
-= !Args.hasArg(OPT_no_code_completion_ns_level_decls);
-  Opts.CodeCompleteOpts.IncludeBriefComments
-= Args.hasArg(OPT_code_completion_brief_comments);
-  Opts.CodeCompleteOpts.IncludeFixIts
-= Args.hasArg(OPT_code_completion_with_fixits);
-
   Opts.OverrideRecordLayoutsFile =
   std::string(Args.getLastArgValue(OPT_foverride_record_layout_EQ));
   Opts.AuxTriple = std::string(Args.getLastArgValue(OPT_aux_triple));
@@ -2010,8 +1979,6 @@
   std::string(Args.getLastArgValue(OPT_mt_migrate_directory));
   Opts.ARCMTMigrateReportOut =
   std::string(Args.getLastArgValue(OPT_arcmt_migrate_report_output));
-  Opts.ARCMTMigrateEmitARCErrors
-= Args.hasArg(OPT_arcmt_migrate_emit_arc_errors);
 
   Opts.ObjCMTWhiteListPath =
   std::string(Args.getLastArgValue(OPT_objcmt_whitelist_dir_path));
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
++

[PATCH] D83826: [clangd] Don't send invalid messages from remote index

2020-07-15 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 278170.
kbobyrev added a comment.

Use DebugStrings instead of ShortDebugStrings.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83826

Files:
  clang-tools-extra/clangd/index/remote/Client.cpp
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.cpp
  clang-tools-extra/clangd/index/remote/marshalling/Marshalling.h
  clang-tools-extra/clangd/index/remote/server/Server.cpp
  clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp

Index: clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
===
--- clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
+++ clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp
@@ -13,6 +13,7 @@
 #include "index/Serialization.h"
 #include "index/Symbol.h"
 #include "index/SymbolID.h"
+#include "index/SymbolLocation.h"
 #include "index/remote/marshalling/Marshalling.h"
 #include "clang/Index/IndexSymbol.h"
 #include "llvm/ADT/SmallString.h"
@@ -46,10 +47,11 @@
   Strings);
   auto Serialized =
   toProtobuf(Original, testPath("remote/machine/projects/llvm-project/"));
-  EXPECT_EQ(Serialized.location().file_path(),
+  EXPECT_TRUE(Serialized);
+  EXPECT_EQ(Serialized->location().file_path(),
 "clang-tools-extra/clangd/unittests/remote/MarshallingTests.cpp");
   const std::string LocalIndexPrefix = testPath("local/machine/project/");
-  auto Deserialized = fromProtobuf(Serialized, &Strings,
+  auto Deserialized = fromProtobuf(*Serialized, &Strings,
testPath("home/my-projects/llvm-project/"));
   EXPECT_TRUE(Deserialized);
   EXPECT_EQ(Deserialized->Location.FileURI,
@@ -57,11 +59,16 @@
 "clangd/unittests/remote/MarshallingTests.cpp",
 Strings));
 
+  // Can't have empty paths.
+  *Serialized->mutable_location()->mutable_file_path() = std::string();
+  Deserialized = fromProtobuf(*Serialized, &Strings, LocalIndexPrefix);
+  EXPECT_FALSE(Deserialized);
+
   clangd::Ref WithInvalidURI;
-  // Invalid URI results in empty path.
+  // Invalid URI results in serialization failure.
   WithInvalidURI.Location.FileURI = "This is not a URI";
   Serialized = toProtobuf(WithInvalidURI, testPath("home/"));
-  EXPECT_EQ(Serialized.location().file_path(), "");
+  EXPECT_FALSE(Serialized);
 
   // Can not use URIs with scheme different from "file".
   auto UnittestURI =
@@ -70,7 +77,7 @@
   WithInvalidURI.Location.FileURI =
   Strings.save(UnittestURI->toString()).begin();
   Serialized = toProtobuf(WithInvalidURI, testPath("project/lib/"));
-  EXPECT_EQ(Serialized.location().file_path(), "");
+  EXPECT_FALSE(Serialized);
 
   Ref WithAbsolutePath;
   *WithAbsolutePath.mutable_location()->mutable_file_path() =
@@ -131,22 +138,35 @@
   // Check that symbols are exactly the same if the path to indexed project is
   // the same on indexing machine and the client.
   auto Serialized = toProtobuf(Sym, testPath("home/"));
-  auto Deserialized = fromProtobuf(Serialized, &Strings, testPath("home/"));
+  EXPECT_TRUE(Serialized);
+  auto Deserialized = fromProtobuf(*Serialized, &Strings, testPath("home/"));
   EXPECT_TRUE(Deserialized);
   EXPECT_EQ(toYAML(Sym), toYAML(*Deserialized));
   // Serialized paths are relative and have UNIX slashes.
-  EXPECT_EQ(convert_to_slash(Serialized.definition().file_path(),
+  EXPECT_EQ(convert_to_slash(Serialized->definition().file_path(),
  llvm::sys::path::Style::posix),
-Serialized.definition().file_path());
+Serialized->definition().file_path());
   EXPECT_TRUE(
-  llvm::sys::path::is_relative(Serialized.definition().file_path()));
+  llvm::sys::path::is_relative(Serialized->definition().file_path()));
+
+  // Missing definition is OK.
+  Sym.Definition = clangd::SymbolLocation();
+  Serialized = toProtobuf(Sym, testPath("home/"));
+  EXPECT_TRUE(Serialized);
+  Deserialized = fromProtobuf(*Serialized, &Strings, testPath("home/"));
+  EXPECT_TRUE(Deserialized);
+
+  // Relative path is absolute.
+  *Serialized->mutable_canonical_declaration()->mutable_file_path() =
+  convert_to_slash("/path/to/Declaration.h");
+  Deserialized = fromProtobuf(*Serialized, &Strings, testPath("home/"));
+  EXPECT_FALSE(Deserialized);
 
   // Fail with an invalid URI.
   Location.FileURI = "Not A URI";
   Sym.Definition = Location;
   Serialized = toProtobuf(Sym, testPath("home/"));
-  Deserialized = fromProtobuf(Serialized, &Strings, testPath("home/"));
-  EXPECT_FALSE(Deserialized);
+  EXPECT_FALSE(Serialized);
 
   // Schemes other than "file" can not be used.
   auto UnittestURI = URI::create(testPath("home/SomePath.h"), "unittest");
@@ -154,22 +174,21 @@
   Location.FileURI = Strings.save(UnittestURI->toString()).begin();
   Sym.Definition = Location;
   Serialized = toPr

[PATCH] D83717: [clang-tidy] Add check fo SEI CERT item ENV32-C

2020-07-15 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/clang-tidy/checks/cert-env32-c.rst:6
+
+This check implements SEI CERT rule ENV32-C by finding functions registered by
+``atexit`` and ``at_quick_exit`` that are calling exit functions ``_Exit``,

Please synchronize with statement in Release Notes. Please omit //This check//.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83717



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


[PATCH] D83681: [clang] Provide a more specific diagnostic for a misplaced lambda capture-default.

2020-07-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thanks for the additional tests. This LGTM, though I still wonder about the 
fix-it (not certain if you saw the comment).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83681



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


[PATCH] D83717: [clang-tidy] Add check fo SEI CERT item ENV32-C

2020-07-15 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 marked 2 inline comments as done.
gamesh411 added inline comments.



Comment at: clang-tools-extra/docs/clang-tidy/checks/cert-env32-c.rst:6
+
+This check implements SEI CERT rule ENV32-C by finding functions registered by
+``atexit`` and ``at_quick_exit`` that are calling exit functions ``_Exit``,

Eugene.Zelenko wrote:
> Please synchronize with statement in Release Notes. Please omit //This 
> check//.
Thanks! Fixed :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83717



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


  1   2   3   >