[PATCH] D148496: [compiler-rt] [test] Mark dfsan tests XFAIL on glibc-2.37

2023-04-16 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: browneee, vitalybuka, MaskRay, thesamesam, jianzhou.zh.
Herald added subscribers: Enna1, dberris.
Herald added a project: All.
mgorny requested review of this revision.

Mark the two dfsan tests that are known to be broken on glibc-2.37
as XFAIL, to make the test suite start passing on Gentoo again.

Bug: https://github.com/llvm/llvm-project/issues/60678


https://reviews.llvm.org/D148496

Files:
  compiler-rt/test/dfsan/custom.cpp
  compiler-rt/test/dfsan/release_shadow_space.c
  compiler-rt/test/lit.common.cfg.py


Index: compiler-rt/test/lit.common.cfg.py
===
--- compiler-rt/test/lit.common.cfg.py
+++ compiler-rt/test/lit.common.cfg.py
@@ -518,7 +518,7 @@
   if not config.android and len(ver_lines) and ver_lines[0].startswith(b"ldd 
"):
 from distutils.version import LooseVersion
 ver = LooseVersion(ver_lines[0].split()[-1].decode())
-for required in ["2.27", "2.30", "2.34"]:
+for required in ["2.27", "2.30", "2.34", "2.37"]:
   if ver >= LooseVersion(required):
 config.available_features.add("glibc-" + required)
 
Index: compiler-rt/test/dfsan/release_shadow_space.c
===
--- compiler-rt/test/dfsan/release_shadow_space.c
+++ compiler-rt/test/dfsan/release_shadow_space.c
@@ -1,3 +1,6 @@
+// https://github.com/llvm/llvm-project/issues/60678
+// XFAIL: glibc-2.37
+
 // DFSAN_OPTIONS=no_huge_pages_for_shadow=false RUN: %clang_dfsan %s -o %t && 
%run %t
 // DFSAN_OPTIONS=no_huge_pages_for_shadow=true RUN: %clang_dfsan %s -o %t && 
%run %t
 // DFSAN_OPTIONS=no_huge_pages_for_shadow=false RUN: %clang_dfsan %s 
-DORIGIN_TRACKING -mllvm -dfsan-track-origins=1 -o %t && %run %t
Index: compiler-rt/test/dfsan/custom.cpp
===
--- compiler-rt/test/dfsan/custom.cpp
+++ compiler-rt/test/dfsan/custom.cpp
@@ -1,3 +1,6 @@
+// https://github.com/llvm/llvm-project/issues/60678
+// XFAIL: glibc-2.37
+
 // RUN: %clang_dfsan %s -o %t && DFSAN_OPTIONS="strict_data_dependencies=0" 
%run %t
 // RUN: %clang_dfsan -DSTRICT_DATA_DEPENDENCIES %s -o %t && %run %t
 // RUN: %clang_dfsan -DORIGIN_TRACKING -mllvm -dfsan-track-origins=1 -mllvm 
-dfsan-combine-pointer-labels-on-load=false -DSTRICT_DATA_DEPENDENCIES %s -o %t 
&& %run %t


Index: compiler-rt/test/lit.common.cfg.py
===
--- compiler-rt/test/lit.common.cfg.py
+++ compiler-rt/test/lit.common.cfg.py
@@ -518,7 +518,7 @@
   if not config.android and len(ver_lines) and ver_lines[0].startswith(b"ldd "):
 from distutils.version import LooseVersion
 ver = LooseVersion(ver_lines[0].split()[-1].decode())
-for required in ["2.27", "2.30", "2.34"]:
+for required in ["2.27", "2.30", "2.34", "2.37"]:
   if ver >= LooseVersion(required):
 config.available_features.add("glibc-" + required)
 
Index: compiler-rt/test/dfsan/release_shadow_space.c
===
--- compiler-rt/test/dfsan/release_shadow_space.c
+++ compiler-rt/test/dfsan/release_shadow_space.c
@@ -1,3 +1,6 @@
+// https://github.com/llvm/llvm-project/issues/60678
+// XFAIL: glibc-2.37
+
 // DFSAN_OPTIONS=no_huge_pages_for_shadow=false RUN: %clang_dfsan %s -o %t && %run %t
 // DFSAN_OPTIONS=no_huge_pages_for_shadow=true RUN: %clang_dfsan %s -o %t && %run %t
 // DFSAN_OPTIONS=no_huge_pages_for_shadow=false RUN: %clang_dfsan %s -DORIGIN_TRACKING -mllvm -dfsan-track-origins=1 -o %t && %run %t
Index: compiler-rt/test/dfsan/custom.cpp
===
--- compiler-rt/test/dfsan/custom.cpp
+++ compiler-rt/test/dfsan/custom.cpp
@@ -1,3 +1,6 @@
+// https://github.com/llvm/llvm-project/issues/60678
+// XFAIL: glibc-2.37
+
 // RUN: %clang_dfsan %s -o %t && DFSAN_OPTIONS="strict_data_dependencies=0" %run %t
 // RUN: %clang_dfsan -DSTRICT_DATA_DEPENDENCIES %s -o %t && %run %t
 // RUN: %clang_dfsan -DORIGIN_TRACKING -mllvm -dfsan-track-origins=1 -mllvm -dfsan-combine-pointer-labels-on-load=false -DSTRICT_DATA_DEPENDENCIES %s -o %t && %run %t
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144634: [Clang][OpenMP] Support for Code Generation of loop bind clause

2023-04-16 Thread Sunil K via Phabricator via cfe-commits
koops updated this revision to Diff 514096.
koops added a comment.

1. Adding semantic test clang/test/OpenMP/loop_bind_messages.cpp.
2. Changes suggested by Alexey.
3. >Why need to drop bind clause here? The new Directives to which loop 
directive is being mapped to, do not contain the bind clause. a) omp loop 
bind(parallel)  > omp for b) omp loop bind(teams)  ->  omp distribute 
c) omp loop bind(thread)  --> omp simd


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

https://reviews.llvm.org/D144634

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/loop_bind_codegen.cpp
  clang/test/OpenMP/loop_bind_messages.cpp

Index: clang/test/OpenMP/loop_bind_messages.cpp
===
--- /dev/null
+++ clang/test/OpenMP/loop_bind_messages.cpp
@@ -0,0 +1,76 @@
+#ifndef HEADER
+#define HEADER
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fopenmp -fopenmp-version=50 -verify %s
+
+#define NNN 50
+int aaa[NNN];
+
+void parallel_loop() {
+  #pragma omp parallel
+  {
+ #pragma omp loop
+ for (int j = 0 ; j < NNN ; j++) {
+   aaa[j] = j*NNN;
+ }
+   }
+}
+
+void teams_loop() {
+  int var1, var2;
+
+  #pragma omp teams
+  {
+ #pragma omp loop bind(teams)
+ for (int j = 0 ; j < NNN ; j++) {
+   aaa[j] = j*NNN;
+ }
+
+ #pragma omp loop bind(teams) collapse(2) private(var1)
+ for (int i = 0 ; i < 3 ; i++) {
+   for (int j = 0 ; j < NNN ; j++) {
+ var1 += aaa[j];
+   }
+ }
+   }
+}
+
+void orphan_loop_with_bind() {
+  #pragma omp loop bind(parallel) 
+  for (int j = 0 ; j < NNN ; j++) {
+aaa[j] = j*NNN;
+  }
+}
+
+void orphan_loop_no_bind() {
+  #pragma omp loop  // expected-error{{expected 'bind' clause for loop construct without an enclosing OpenMP construct}}
+  for (int j = 0 ; j < NNN ; j++) {
+aaa[j] = j*NNN;
+  }
+}
+
+void teams_loop_reduction() {
+  int total = 0;
+
+  #pragma omp teams
+  {
+ #pragma omp loop bind(teams)
+ for (int j = 0 ; j < NNN ; j++) {
+   aaa[j] = j*NNN;
+ }
+
+ #pragma omp loop bind(teams) reduction(+:total) // expected-error{{reduction clause not handled with '#pragma omp loop bind(teams)'}}
+ for (int j = 0 ; j < NNN ; j++) {
+   total+=aaa[j];
+ }
+   }
+}
+
+int main(int argc, char *argv[]) {
+  parallel_loop();
+  teams_loop();
+  orphan_loop_with_bind();
+  orphan_loop_no_bind();
+  teams_loop_reduction();
+}
+
+#endif
Index: clang/test/OpenMP/loop_bind_codegen.cpp
===
--- /dev/null
+++ clang/test/OpenMP/loop_bind_codegen.cpp
@@ -0,0 +1,151 @@
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+// RUN: %clang_cc1 -DCK1 -verify -fopenmp -x c++ %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown -emit-llvm %s -o - | FileCheck %s
+
+
+/*
+#include 
+#include 
+#include 
+#include 
+*/
+
+#define NNN 50
+int aaa[NNN];
+
+void parallel_loop() {
+  #pragma omp parallel
+  {
+#pragma omp loop bind(parallel)
+for (int j = 0 ; j < NNN ; j++) {
+  aaa[j] = j*NNN;
+}
+  }
+}
+
+void parallel_loop_orphan() {
+  #pragma omp loop bind(parallel)
+  for (int j = 0 ; j < NNN ; j++) {
+ aaa[j] = j*NNN;
+  }
+}
+
+
+void teams_loop() {
+  #pragma omp teams
+  {
+ #pragma omp loop bind(teams)
+ for (int j = 0 ; j < NNN ; j++) {
+   aaa[j] = j*NNN;
+ }
+   }
+}
+
+void thread_loop() {
+  #pragma omp parallel
+  {
+ #pragma omp loop bind(thread)
+ for (int j = 0 ; j < NNN ; j++) {
+   aaa[j] = j*NNN;
+ }
+   }
+}
+
+void thread_loop_orphan() {
+  #pragma omp loop bind(thread)
+  for (int j = 0 ; j < NNN ; j++) {
+aaa[j] = j*NNN;
+  }
+}
+
+int main() {
+  parallel_loop();
+  parallel_loop_orphan();
+  teams_loop();
+  thread_loop();
+  thread_loop_orphan();
+
+  return 0;
+}
+#endif
+// CHECK-LABEL: define {{[^@]+}}@_Z13parallel_loopv
+// CHECK-NEXT: entry:
+// CHECK-NEXT: call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @3, i32 0, ptr @.omp_outlined.)
+// CHECK-LABEL: define {{[^@]+}}@.omp_outlined
+// CHECK-NEXT: entry:
+// CHECK-NEXT:[[DOTGLOBAL_TID__ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[DOTBOUND_TID__ADDR:%.*]] = alloca ptr, align 8
+// CHECK-NEXT:[[DOTOMP_IV:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[TMP:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[DOTOMP_LB:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[DOTOMP_UB:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[DOTOMP_STRIDE:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[DOTOMP_IS_LAST:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[J:%.*]] = alloca i32, align 4
+// CHECK:   call void @__kmpc_for_static_init_4(ptr @1, i32 %1, i32 34, ptr [[DOTOMP_IS_LAST]], ptr [[DOTOMP_LB]], ptr [[DOTOMP_UB]], ptr [[DOTOMP_STRIDE]], i32 1, i32 1)
+// CHECK-LABEL: cond.true:
+// CHECK-NEXT:

[PATCH] D146178: [Clang][Sema] Fix comparison of constraint expressions

2023-04-16 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexander-shaposhnikov added a comment.

https://github.com/llvm/llvm-project/issues/62110 is still a blocker for this 
diff though (haven't investigated it yet)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146178

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


[PATCH] D146178: [Clang][Sema] Fix comparison of constraint expressions

2023-04-16 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexander-shaposhnikov updated this revision to Diff 514095.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146178

Files:
  clang/include/clang/Sema/Template.h
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/SemaTemplate/concepts-out-of-line-def.cpp
  clang/test/SemaTemplate/concepts.cpp

Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -816,3 +816,62 @@
 static_assert(Parent::TakesBinary::i == 0);
 }
 
+namespace TemplateInsideNonTemplateClass {
+template concept C = true;
+
+template auto L = [] U>() {};
+
+struct Q {
+  template U> friend constexpr auto decltype(L)::operator()() const;
+};
+} // namespace TemplateInsideNonTemplateClass
+
+namespace GH61959 {
+template 
+concept C = (sizeof(T0) >= 4);
+
+template
+struct Orig { };
+
+template
+struct Orig {
+  template requires C
+  void f() { }
+
+  template requires true
+  void f() { }
+};
+
+template  struct Mod {};
+
+template 
+struct Mod {
+  template  requires C
+  constexpr static int f() { return 1; }
+
+  template  requires C
+  constexpr static int f() { return 2; }
+};
+
+static_assert(Mod::f() == 1);
+static_assert(Mod::f() == 2);
+
+template
+struct Outer {
+  template
+  struct Inner {};
+
+  template
+  struct Inner {
+template
+void foo()  requires C && C && C{}
+template
+void foo()  requires true{}
+  };
+};
+
+void bar() {
+  Outer::Inner I;
+  I.foo();
+}
+}
Index: clang/test/SemaTemplate/concepts-out-of-line-def.cpp
===
--- clang/test/SemaTemplate/concepts-out-of-line-def.cpp
+++ clang/test/SemaTemplate/concepts-out-of-line-def.cpp
@@ -127,3 +127,220 @@
 static_assert(S::specialization("str") == SPECIALIZATION_REQUIRES);
 
 } // namespace multiple_template_parameter_lists
+
+static constexpr int CONSTRAINED_METHOD_1 = 1;
+static constexpr int CONSTRAINED_METHOD_2 = 2;
+
+namespace constrained_members {
+
+template 
+struct S {
+  template 
+  static constexpr int constrained_method();
+};
+
+template <>
+template 
+constexpr int S<1>::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template <>
+template 
+constexpr int S<2>::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S<1>::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S<2>::constrained_method() == CONSTRAINED_METHOD_2);
+
+
+template 
+concept ConceptT1T2 = true;
+
+template
+struct S12 {
+  template T4>
+  static constexpr int constrained_method();
+};
+
+template<>
+template T5>
+constexpr int S12::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template<>
+template T5>
+constexpr int S12::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S12::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S12::constrained_method() == CONSTRAINED_METHOD_2);
+
+} // namespace constrained members
+
+namespace constrained_members_of_nested_types {
+
+template 
+struct S {
+  struct Inner0 {
+struct Inner1 {
+  template 
+  static constexpr int constrained_method();
+};
+  };
+};
+
+template <>
+template 
+constexpr int S<1>::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template <>
+template 
+constexpr int S<2>::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S<1>::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S<2>::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_2);
+
+
+template 
+concept ConceptT1T2 = true;
+
+template
+struct S12 {
+  struct Inner0 {
+struct Inner1 {
+  template T4>
+  static constexpr int constrained_method();
+};
+  };
+};
+
+template<>
+template T5>
+constexpr int S12::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_1; }
+
+template<>
+template T5>
+constexpr int S12::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_2; }
+
+static_assert(S12::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_1);
+static_assert(S12::Inner0::Inner1::constrained_method() == CONSTRAINED_METHOD_2);
+
+} // namespace constrained_members_of_nested_types
+
+namespace constrained_member_sfinae {
+
+template struct S {
+  template
+  static constexpr int constrained_method() requires (sizeof(int[N * 1073741824 + 4]) == 16) {
+return CONSTRAINED_METHOD_1;
+  }
+
+  template
+  static constexpr int constrained_method() requires (sizeof(int[N]) == 16);
+};
+
+template<>
+template
+constexpr int S<4>::constrained_method() requires (sizeof(int[4]) == 16) {
+  return CONSTRAINED_METHOD_2;
+}
+
+// Verify that there is no amiguity in this case.

[PATCH] D148439: [clang-rename] Exit gracefully when no input provided

2023-04-16 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added a comment.

In D148439#4272813 , @dyung wrote:

> This change is also causing 33 test failures on a build bot 
> https://lab.llvm.org/buildbot/#/builders/139/builds/39267

Yes, checking for the reason, and honestly I never tried to run clang-rename 
for its uses.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148439

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


[PATCH] D148439: [clang-rename] Exit gracefully when no input provided

2023-04-16 Thread Douglas Yung via Phabricator via cfe-commits
dyung added a comment.

This change is also causing 33 test failures on a build bot 
https://lab.llvm.org/buildbot/#/builders/139/builds/39267


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148439

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


[PATCH] D148439: [clang-rename] Exit gracefully when no input provided

2023-04-16 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added a comment.

In D148439#4272810 , @dyung wrote:

> Is there a reason a test was not added with this change?

Sorry, I missed that. Adding.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148439

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


[clang] 06387f9 - Revert "[clang-rename] Exit gracefully when no input provided"

2023-04-16 Thread Shivam Gupta via cfe-commits

Author: Shivam Gupta
Date: 2023-04-17T10:31:40+05:30
New Revision: 06387f94cfdf6bbd37ac3b925a50410e11a1fc9d

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

LOG: Revert "[clang-rename] Exit gracefully when no input provided"

This reverts commit 726199146a0bb53315ade042e759c65e6d96d556.

This broke the buildbot -
https://lab.llvm.org/buildbot#builders/139/builds/39267

Added: 


Modified: 
clang/tools/clang-rename/ClangRename.cpp

Removed: 




diff  --git a/clang/tools/clang-rename/ClangRename.cpp 
b/clang/tools/clang-rename/ClangRename.cpp
index 7ba1978f0774..e7ceac7dbf30 100644
--- a/clang/tools/clang-rename/ClangRename.cpp
+++ b/clang/tools/clang-rename/ClangRename.cpp
@@ -126,9 +126,6 @@ int main(int argc, const char **argv) {
 SymbolOffsets.push_back(Info.Offset);
   NewNames.push_back(Info.NewName);
 }
-  } else {
-errs() << "clang-rename: input must be provided.\n";
-return 1;
   }
 
   // Check the arguments for correctness.



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


[PATCH] D148439: [clang-rename] Exit gracefully when no input provided

2023-04-16 Thread Douglas Yung via Phabricator via cfe-commits
dyung added a comment.

Is there a reason a test was not added with this change?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148439

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


[PATCH] D148439: [clang-rename] Exit gracefully when no input provided

2023-04-16 Thread Shivam Gupta via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
xgupta marked an inline comment as done.
Closed by commit rG726199146a0b: [clang-rename] Exit gracefully when no input 
provided (authored by xgupta).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148439

Files:
  clang/tools/clang-rename/ClangRename.cpp


Index: clang/tools/clang-rename/ClangRename.cpp
===
--- clang/tools/clang-rename/ClangRename.cpp
+++ clang/tools/clang-rename/ClangRename.cpp
@@ -126,6 +126,9 @@
 SymbolOffsets.push_back(Info.Offset);
   NewNames.push_back(Info.NewName);
 }
+  } else {
+errs() << "clang-rename: input must be provided.\n";
+return 1;
   }
 
   // Check the arguments for correctness.


Index: clang/tools/clang-rename/ClangRename.cpp
===
--- clang/tools/clang-rename/ClangRename.cpp
+++ clang/tools/clang-rename/ClangRename.cpp
@@ -126,6 +126,9 @@
 SymbolOffsets.push_back(Info.Offset);
   NewNames.push_back(Info.NewName);
 }
+  } else {
+errs() << "clang-rename: input must be provided.\n";
+return 1;
   }
 
   // Check the arguments for correctness.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7261991 - [clang-rename] Exit gracefully when no input provided

2023-04-16 Thread Shivam Gupta via cfe-commits

Author: Shivam Gupta
Date: 2023-04-17T10:23:53+05:30
New Revision: 726199146a0bb53315ade042e759c65e6d96d556

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

LOG: [clang-rename] Exit gracefully when no input provided

clang-rename on a non existing file segfaults

Command to run -
$ clang-rename -offset=0 -new-name=plop asdasd

Error while processing llvm-project/asdasd.
clang-rename: llvm-project/llvm/include/llvm/Support/ErrorOr.h:237:
llvm::ErrorOr::storage_type* llvm::ErrorOr::getStorage()
[with T = const clang::FileEntry*; llvm::ErrorOr::storage_type = const 
clang::FileEntry*]:
Assertion `!HasError && "Cannot get value when an error exists!"' failed.

[1]827497 IOT instruction  clang-rename -offset=0 -new-name=plop asdasd

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

Added: 


Modified: 
clang/tools/clang-rename/ClangRename.cpp

Removed: 




diff  --git a/clang/tools/clang-rename/ClangRename.cpp 
b/clang/tools/clang-rename/ClangRename.cpp
index e7ceac7dbf30..7ba1978f0774 100644
--- a/clang/tools/clang-rename/ClangRename.cpp
+++ b/clang/tools/clang-rename/ClangRename.cpp
@@ -126,6 +126,9 @@ int main(int argc, const char **argv) {
 SymbolOffsets.push_back(Info.Offset);
   NewNames.push_back(Info.NewName);
 }
+  } else {
+errs() << "clang-rename: input must be provided.\n";
+return 1;
   }
 
   // Check the arguments for correctness.



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


[PATCH] D148439: [clang-rename] Exit gracefully when no input provided

2023-04-16 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta marked an inline comment as done.
xgupta added inline comments.



Comment at: clang/tools/clang-rename/ClangRename.cpp:130
+  } else {
+errs() << "clang-rename: No input provided.\n";
+return 1;

kbobyrev wrote:
> Probably something like "input must be provided" would be more understandable 
> by the user, but this is also fine.
Thanks for the suggestion!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148439

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


[PATCH] D148439: [clang-rename] Exit gracefully when no input provided

2023-04-16 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta updated this revision to Diff 514093.
xgupta added a comment.

address comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148439

Files:
  clang/tools/clang-rename/ClangRename.cpp


Index: clang/tools/clang-rename/ClangRename.cpp
===
--- clang/tools/clang-rename/ClangRename.cpp
+++ clang/tools/clang-rename/ClangRename.cpp
@@ -126,6 +126,9 @@
 SymbolOffsets.push_back(Info.Offset);
   NewNames.push_back(Info.NewName);
 }
+  } else {
+errs() << "clang-rename: input must be provided.\n";
+return 1;
   }
 
   // Check the arguments for correctness.


Index: clang/tools/clang-rename/ClangRename.cpp
===
--- clang/tools/clang-rename/ClangRename.cpp
+++ clang/tools/clang-rename/ClangRename.cpp
@@ -126,6 +126,9 @@
 SymbolOffsets.push_back(Info.Offset);
   NewNames.push_back(Info.NewName);
 }
+  } else {
+errs() << "clang-rename: input must be provided.\n";
+return 1;
   }
 
   // Check the arguments for correctness.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148474: [Clang] Fix ResolveConstructorOverload to not select a conversion function if we are going use copy elision

2023-04-16 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:746
+ diag::note_template_class_instantiation_here)
+<< CTD << Active->InstantiationRange;
   } else {

rsmith wrote:
> This diagnostic won't include the template arguments that we're using to 
> instantiate, which seems like important information.
> 
> Do you know where we're creating the `InstantiatingTemplate` instance 
> corresponding to this diagnostic? Usually we pass in the declaration whose 
> definition we're instantiating for a `TemplateInstantiation` record; I wonder 
> if we could do the same for this case.
This is happening in `Sema::ActOnCallExpr` here:

```cpp
 // Diagnose uses of the C++20 "ADL-only template-id call" feature in earlier
  // language modes.
  if (auto *ULE = dyn_cast(Fn)) {
if (ULE->hasExplicitTemplateArgs() &&
ULE->decls_begin() == ULE->decls_end()) {
  Diag(Fn->getExprLoc(), getLangOpts().CPlusPlus20
 ? diag::warn_cxx17_compat_adl_only_template_id
 : diag::ext_adl_only_template_id)
  << ULE->getName();
}
  }
```

if I check:

```console
expr CodeSynthesisContexts->rbegin()->Entity
```

That is indeed the `ClassTemplateDecl` and we do have `MultiExprArg ArgExprs` 
there as well.

The call right before this `TemplateInstantiator::RebuildCallExpr`



Comment at: clang/test/SemaCXX/cxx1z-copy-omission.cpp:193
+template
+class B3 : A3 // expected-error {{expected '{' after base class list}}
+  template()> // expected-warning 2{{use of function template 
name with no prior declaration in function call with explicit}}

rsmith wrote:
> Do you need to omit the `{` here as part of this test? This will cause 
> problems for people editing the file due to mismatched braces, and makes this 
> test fragile if our error recovery changes. It's best for the test case to be 
> free of errors other than the one(s) being exercised. (Same for missing `;` 
> errors below.)
> 
> If these errors are necessary to trigger the bug you found, I wonder if 
> there's a problem with our error recovery. (Maybe we create a "bad" 
> `InstantiatingTemplate` record during error recovery, for example.)
They are not needed to trigger the issue, I removed them. I was torn about how 
faithful to remain to the original test case.


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

https://reviews.llvm.org/D148474

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


[PATCH] D148474: [Clang] Fix ResolveConstructorOverload to not select a conversion function if we are going use copy elision

2023-04-16 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik updated this revision to Diff 514091.
shafik marked 3 inline comments as done.
shafik added a comment.

- Fix up A3 test to be less malformed
- Fix other test so we confirm we are attempting to call the right contructor


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

https://reviews.llvm.org/D148474

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaCXX/cxx1z-copy-omission.cpp

Index: clang/test/SemaCXX/cxx1z-copy-omission.cpp
===
--- clang/test/SemaCXX/cxx1z-copy-omission.cpp
+++ clang/test/SemaCXX/cxx1z-copy-omission.cpp
@@ -171,3 +171,30 @@
   Foo f(Derived d) { return d; } // expected-error {{invokes a deleted function}}
   Foo g(Derived d) { return Foo(d); } // ok, calls constructor
 }
+
+// Make sure we don't consider conversion functions for guaranteed copy elision
+namespace GH39319 {
+struct A {
+  A();
+  A(const A&) = delete; // expected-note {{'A' has been explicitly marked deleted here}}
+};
+struct B {
+  operator A();
+} C;
+A::A() : A(C) {} // expected-error {{call to deleted constructor of}}
+
+struct A2 {
+  struct B2 {
+operator A2();
+  };
+  A2() : A2(B2()) {}  // expected-error {{call to deleted constructor of}}
+  A2(const A2&) = delete; // expected-note {{'A2' has been explicitly marked deleted here}}
+};
+
+template
+class B3 : A3 {
+  template()> // expected-warning 2{{use of function template name with no prior declaration in function call with explicit}}
+  B3();
+}; B3(); // expected-error {{deduction guide declaration without trailing return type}} \
+ // expected-note {{in instantiation of template class}}
+}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -740,6 +740,10 @@
 Diags.Report(Active->PointOfInstantiation,
  diag::note_template_nsdmi_here)
 << FD << Active->InstantiationRange;
+  } else if (ClassTemplateDecl *CTD = dyn_cast(D)) {
+Diags.Report(Active->PointOfInstantiation,
+ diag::note_template_class_instantiation_here)
+<< CTD << Active->InstantiationRange;
   } else {
 Diags.Report(Active->PointOfInstantiation,
  diag::note_template_type_alias_instantiation_here)
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -3981,16 +3981,13 @@
   return Ctx.hasSameUnqualifiedType(ParmT, ClassT);
 }
 
-static OverloadingResult
-ResolveConstructorOverload(Sema , SourceLocation DeclLoc,
-   MultiExprArg Args,
-   OverloadCandidateSet ,
-   QualType DestType,
-   DeclContext::lookup_result Ctors,
-   OverloadCandidateSet::iterator ,
-   bool CopyInitializing, bool AllowExplicit,
-   bool OnlyListConstructors, bool IsListInit,
-   bool SecondStepOfCopyInit = false) {
+static OverloadingResult ResolveConstructorOverload(
+Sema , SourceLocation DeclLoc, MultiExprArg Args,
+OverloadCandidateSet , QualType DestType,
+DeclContext::lookup_result Ctors, OverloadCandidateSet::iterator ,
+bool CopyInitializing, bool AllowExplicit, bool OnlyListConstructors,
+bool IsListInit, bool RequireActualConstructor,
+bool SecondStepOfCopyInit = false) {
   CandidateSet.clear(OverloadCandidateSet::CSK_InitByConstructor);
   CandidateSet.setDestAS(DestType.getQualifiers().getAddressSpace());
 
@@ -4053,7 +4050,7 @@
   // Note: SecondStepOfCopyInit is only ever true in this case when
   // evaluating whether to produce a C++98 compatibility warning.
   if (S.getLangOpts().CPlusPlus17 && Args.size() == 1 &&
-  !SecondStepOfCopyInit) {
+  !RequireActualConstructor && !SecondStepOfCopyInit) {
 Expr *Initializer = Args[0];
 auto *SourceRD = Initializer->getType()->getAsCXXRecordDecl();
 if (SourceRD && S.isCompleteType(DeclLoc, Initializer->getType())) {
@@ -4121,6 +4118,12 @@
 return;
   }
 
+  bool RequireActualConstructor =
+  !(Entity.getKind() != InitializedEntity::EK_Base &&
+Entity.getKind() != InitializedEntity::EK_Delegating &&
+Entity.getKind() !=
+InitializedEntity::EK_LambdaToBlockConversionBlockElement);
+
   // C++17 [dcl.init]p17:
   // - If the initializer expression is a prvalue and the cv-unqualified
   //   version of the source type is the same class as the class of the
@@ -4130,11 +4133,7 @@
   // class or delegating to another constructor from a mem-initializer.
   // ObjC++: Lambda captured by the block in the lambda to block conversion
   // should avoid copy 

[PATCH] D148489: [clangd] Implement configs to stop clangd produce a certain semantic tokens

2023-04-16 Thread Qingyuan Zheng via Phabricator via cfe-commits
daiyousei-qz added inline comments.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:1281
 }
+std::optional
+highlightingKindFromString(llvm::StringRef Name) {

I'm not sure if we should parse the enums here or in parsing configs using 
`EnumSwitch`. The problem is that I don't want to introduce dependencies to 
"SemanticHighlighting.h" in "ConfigCompile.cpp".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148489

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


[PATCH] D148489: [clangd] Implement configs to stop clangd produce a certain semantic tokens

2023-04-16 Thread Qingyuan Zheng via Phabricator via cfe-commits
daiyousei-qz updated this revision to Diff 514088.
daiyousei-qz added a comment.

Fix an issue where the previous change is lost.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148489

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/SemanticHighlighting.h
  clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "Annotations.h"
+#include "Config.h"
 #include "Protocol.h"
 #include "SemanticHighlighting.h"
 #include "SourceCode.h"
@@ -1260,6 +1261,17 @@
   EXPECT_EQ(Toks[3].deltaStart, 2u);
   EXPECT_EQ(Toks[3].length, 3u);
 }
+
+TEST(SemanticHighlighting, WithHighlightingFilter) {
+  llvm::StringRef AnnotatedCode = R"cpp(
+int *$Variable[[x]] = new int;
+)cpp";
+  Config Cfg;
+  Cfg.SemanticTokens.DisabledKinds = { "Operator" };
+  Cfg.SemanticTokens.DisabledModifiers = { "Declaration", "Definition" };
+  WithContextValue WithCfg(Config::Key, std::move(Cfg));
+  checkHighlightings(AnnotatedCode, {}, ~ScopeModifierMask);
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
@@ -246,6 +246,23 @@
   EXPECT_EQ(Results[0].InlayHints.DeducedTypes, std::nullopt);
 }
 
+TEST(ParseYAML, SemanticTokens) {
+  CapturedDiags Diags;
+  Annotations YAML(R"yaml(
+SemanticTokens:
+  DisabledKinds: [ Operator, InactiveCode]
+  DisabledModifiers: Readonly
+  )yaml");
+  auto Results =
+  Fragment::parseYAML(YAML.code(), "config.yaml", Diags.callback());
+  ASSERT_THAT(Diags.Diagnostics, IsEmpty());
+  ASSERT_EQ(Results.size(), 1u);
+  EXPECT_THAT(Results[0].SemanticTokens.DisabledKinds,
+  ElementsAre(val("Operator"), val("InactiveCode")));
+  EXPECT_THAT(Results[0].SemanticTokens.DisabledModifiers,
+  ElementsAre(val("Readonly")));
+}
+
 TEST(ParseYAML, IncludesIgnoreHeader) {
   CapturedDiags Diags;
   Annotations YAML(R"yaml(
Index: clang-tools-extra/clangd/SemanticHighlighting.h
===
--- clang-tools-extra/clangd/SemanticHighlighting.h
+++ clang-tools-extra/clangd/SemanticHighlighting.h
@@ -61,6 +61,8 @@
 };
 
 llvm::raw_ostream <<(llvm::raw_ostream , HighlightingKind K);
+std::optional
+highlightingKindFromString(llvm::StringRef Name);
 
 enum class HighlightingModifier {
   Declaration,
@@ -88,6 +90,8 @@
 static_assert(static_cast(HighlightingModifier::LastModifier) < 32,
   "Increase width of modifiers bitfield!");
 llvm::raw_ostream <<(llvm::raw_ostream , HighlightingModifier K);
+std::optional
+highlightingModifierFromString(llvm::StringRef Name);
 
 // Contains all information needed for the highlighting a token.
 struct HighlightingToken {
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "SemanticHighlighting.h"
+#include "Config.h"
 #include "FindTarget.h"
 #include "HeuristicResolver.h"
 #include "ParsedAST.h"
@@ -354,12 +355,58 @@
   return Winner;
 }
 
+/// Filter to remove particular kinds of highlighting tokens and modifiers from
+/// the output.
+class HighlightingFilter {
+public:
+  HighlightingFilter() {
+for (auto  : ActiveKindLookup)
+  Active = true;
+
+ActiveModifiersMask = ~0;
+  }
+
+  void disableKind(HighlightingKind Kind) {
+ActiveKindLookup[static_cast(Kind)] = false;
+  }
+
+  void disableModifier(HighlightingModifier Modifier) {
+ActiveModifiersMask &= ~(1 << static_cast(Modifier));
+  }
+
+  bool isHighlightKindActive(HighlightingKind Kind) const {
+return ActiveKindLookup[static_cast(Kind)];
+  }
+
+  uint32_t maskModifiers(uint32_t Modifiers) const {
+return Modifiers & ActiveModifiersMask;
+  }
+
+  static HighlightingFilter fromCurrentConfig() {
+const Config  = Config::current();
+HighlightingFilter Filter;
+for (const auto  : C.SemanticTokens.DisabledKinds)
+  if 

[PATCH] D148489: [clangd] Implement configs to stop clangd produce a certain semantic tokens

2023-04-16 Thread Qingyuan Zheng via Phabricator via cfe-commits
daiyousei-qz updated this revision to Diff 514087.
daiyousei-qz added a comment.

Add a test in SemanticHighlightingTests.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148489

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


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "Annotations.h"
+#include "Config.h"
 #include "Protocol.h"
 #include "SemanticHighlighting.h"
 #include "SourceCode.h"
@@ -1260,6 +1261,17 @@
   EXPECT_EQ(Toks[3].deltaStart, 2u);
   EXPECT_EQ(Toks[3].length, 3u);
 }
+
+TEST(SemanticHighlighting, WithHighlightingFilter) {
+  llvm::StringRef AnnotatedCode = R"cpp(
+int *$Variable[[x]] = new int;
+)cpp";
+  Config Cfg;
+  Cfg.SemanticTokens.DisabledKinds = { "Operator" };
+  Cfg.SemanticTokens.DisabledModifiers = { "Declaration", "Definition" };
+  WithContextValue WithCfg(Config::Key, std::move(Cfg));
+  checkHighlightings(AnnotatedCode, {}, ~ScopeModifierMask);
+}
 } // namespace
 } // namespace clangd
 } // namespace clang


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "Annotations.h"
+#include "Config.h"
 #include "Protocol.h"
 #include "SemanticHighlighting.h"
 #include "SourceCode.h"
@@ -1260,6 +1261,17 @@
   EXPECT_EQ(Toks[3].deltaStart, 2u);
   EXPECT_EQ(Toks[3].length, 3u);
 }
+
+TEST(SemanticHighlighting, WithHighlightingFilter) {
+  llvm::StringRef AnnotatedCode = R"cpp(
+int *$Variable[[x]] = new int;
+)cpp";
+  Config Cfg;
+  Cfg.SemanticTokens.DisabledKinds = { "Operator" };
+  Cfg.SemanticTokens.DisabledModifiers = { "Declaration", "Definition" };
+  WithContextValue WithCfg(Config::Key, std::move(Cfg));
+  checkHighlightings(AnnotatedCode, {}, ~ScopeModifierMask);
+}
 } // namespace
 } // namespace clangd
 } // namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148489: [clangd] Implement configs to stop clangd produce a certain semantic tokens

2023-04-16 Thread Qingyuan Zheng via Phabricator via cfe-commits
daiyousei-qz updated this revision to Diff 514086.
daiyousei-qz added a comment.

Fix unittest


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148489

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/SemanticHighlighting.h
  clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp

Index: clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
@@ -246,6 +246,23 @@
   EXPECT_EQ(Results[0].InlayHints.DeducedTypes, std::nullopt);
 }
 
+TEST(ParseYAML, SemanticTokens) {
+  CapturedDiags Diags;
+  Annotations YAML(R"yaml(
+SemanticTokens:
+  DisabledKinds: [ Operator, InactiveCode]
+  DisabledModifiers: Readonly
+  )yaml");
+  auto Results =
+  Fragment::parseYAML(YAML.code(), "config.yaml", Diags.callback());
+  ASSERT_THAT(Diags.Diagnostics, IsEmpty());
+  ASSERT_EQ(Results.size(), 1u);
+  EXPECT_THAT(Results[0].SemanticTokens.DisabledKinds,
+  ElementsAre(val("Operator"), val("InactiveCode")));
+  EXPECT_THAT(Results[0].SemanticTokens.DisabledModifiers,
+  ElementsAre(val("Readonly")));
+}
+
 TEST(ParseYAML, IncludesIgnoreHeader) {
   CapturedDiags Diags;
   Annotations YAML(R"yaml(
Index: clang-tools-extra/clangd/SemanticHighlighting.h
===
--- clang-tools-extra/clangd/SemanticHighlighting.h
+++ clang-tools-extra/clangd/SemanticHighlighting.h
@@ -61,6 +61,8 @@
 };
 
 llvm::raw_ostream <<(llvm::raw_ostream , HighlightingKind K);
+std::optional
+highlightingKindFromString(llvm::StringRef Name);
 
 enum class HighlightingModifier {
   Declaration,
@@ -88,6 +90,8 @@
 static_assert(static_cast(HighlightingModifier::LastModifier) < 32,
   "Increase width of modifiers bitfield!");
 llvm::raw_ostream <<(llvm::raw_ostream , HighlightingModifier K);
+std::optional
+highlightingModifierFromString(llvm::StringRef Name);
 
 // Contains all information needed for the highlighting a token.
 struct HighlightingToken {
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "SemanticHighlighting.h"
+#include "Config.h"
 #include "FindTarget.h"
 #include "HeuristicResolver.h"
 #include "ParsedAST.h"
@@ -354,12 +355,58 @@
   return Winner;
 }
 
+/// Filter to remove particular kinds of highlighting tokens and modifiers from
+/// the output.
+class HighlightingFilter {
+public:
+  HighlightingFilter() {
+for (auto  : ActiveKindLookup)
+  Active = true;
+
+ActiveModifiersMask = ~0;
+  }
+
+  void disableKind(HighlightingKind Kind) {
+ActiveKindLookup[static_cast(Kind)] = false;
+  }
+
+  void disableModifier(HighlightingModifier Modifier) {
+ActiveModifiersMask &= ~(1 << static_cast(Modifier));
+  }
+
+  bool isHighlightKindActive(HighlightingKind Kind) const {
+return ActiveKindLookup[static_cast(Kind)];
+  }
+
+  uint32_t maskModifiers(uint32_t Modifiers) const {
+return Modifiers & ActiveModifiersMask;
+  }
+
+  static HighlightingFilter fromCurrentConfig() {
+const Config  = Config::current();
+HighlightingFilter Filter;
+for (const auto  : C.SemanticTokens.DisabledKinds)
+  if (auto K = highlightingKindFromString(Kind))
+Filter.disableKind(*K);
+for (const auto  : C.SemanticTokens.DisabledModifiers)
+  if (auto M = highlightingModifierFromString(Modifier))
+Filter.disableModifier(*M);
+
+return Filter;
+  }
+
+private:
+  bool ActiveKindLookup[static_cast(HighlightingKind::LastKind) + 1];
+  uint32_t ActiveModifiersMask;
+};
+
 /// Consumes source locations and maps them to text ranges for highlightings.
 class HighlightingsBuilder {
 public:
-  HighlightingsBuilder(const ParsedAST , bool IncludeInactiveRegionTokens)
+  HighlightingsBuilder(const ParsedAST , const HighlightingFilter ,
+   bool IncludeInactiveRegionTokens)
   : TB(AST.getTokens()), SourceMgr(AST.getSourceManager()),
-LangOpts(AST.getLangOpts()),
+LangOpts(AST.getLangOpts()), Filter(Filter),
 IncludeInactiveRegionTokens(IncludeInactiveRegionTokens) {}
 
   HighlightingToken (SourceLocation Loc, HighlightingKind Kind) {
@@ -412,6 +459,9 @@
   }
 
   HighlightingToken (Range R, HighlightingKind Kind) {
+if (!Filter.isHighlightKindActive(Kind))
+  return InvalidHighlightingToken;
+
 

[PATCH] D148490: [AIX] use system assembler for assembly files

2023-04-16 Thread ChenZheng via Phabricator via cfe-commits
shchenz created this revision.
shchenz added reviewers: hubert.reinterpretcast, nemanjai, PowerPC.
shchenz added a project: LLVM.
Herald added a project: All.
shchenz requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Change to system assembler to compile assembly files even `-fintegrated-as` is 
specified.
We don't have a good Clang as for now for assembly files on AIX.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148490

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/AIX.h
  clang/test/Driver/aix-assembler.s


Index: clang/test/Driver/aix-assembler.s
===
--- /dev/null
+++ clang/test/Driver/aix-assembler.s
@@ -0,0 +1,31 @@
+
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit.
+// RUN: %clang %s -### -c -fintegrated-as 2>&1 \
+// RUN: --target=powerpc64-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefixes=AS64,CHECK %s
+
+// RUN: %clang %s -### -c 2>&1 \
+// RUN: --target=powerpc64-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefixes=AS64,CHECK %s
+
+// RUN: %clang %s -### -c -fno-integrated-as 2>&1 \
+// RUN: --target=powerpc64-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefixes=AS64,CHECK %s
+
+// Check powerpc-ibm-aix7.1.0.0, 32-bit.
+// RUN: %clang %s -### -c -fintegrated-as 2>&1 \
+// RUN: --target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefixes=AS32,CHECK %s
+
+// RUN: %clang %s -### -c 2>&1 \
+// RUN: --target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefixes=AS32,CHECK %s
+
+// RUN: %clang %s -### -c 2>&1 -fno-integrated-as \
+// RUN: --target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefixes=AS32,CHECK %s
+
+// CHECK: "{{.*}}as{{(.exe)?}}"
+// AS32: "-a32"
+// AS64: "-a64"
+// CHECK: "-many"
Index: clang/lib/Driver/ToolChains/AIX.h
===
--- clang/lib/Driver/ToolChains/AIX.h
+++ clang/lib/Driver/ToolChains/AIX.h
@@ -97,8 +97,10 @@
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;
+  Tool *getTool(Action::ActionClass AC) const override;
 
 private:
+  mutable std::unique_ptr Assembler;
   llvm::StringRef GetHeaderSysroot(const llvm::opt::ArgList ) const;
   bool ParseInlineAsmUsingAsmParser;
 };
Index: clang/lib/Driver/ToolChains/AIX.cpp
===
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -416,6 +416,19 @@
   return ToolChain::RLT_CompilerRT;
 }
 
+Tool *AIX::getTool(Action::ActionClass AC) const {
+  switch (AC) {
+  default:
+break;
+  // AIX always uses system assembler to compile assembly files.
+  case Action::AssembleJobClass:
+if (!Assembler)
+  Assembler.reset(buildAssembler());
+return Assembler.get();
+  }
+  return ToolChain::getTool(AC);
+}
+
 auto AIX::buildAssembler() const -> Tool * { return new aix::Assembler(*this); 
}
 
 auto AIX::buildLinker() const -> Tool * { return new aix::Linker(*this); }
Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -662,7 +662,8 @@
   if (D.IsFlangMode() && getDriver().ShouldUseFlangCompiler(JA)) return 
getFlang();
   if (getDriver().ShouldUseClangCompiler(JA)) return getClang();
   Action::ActionClass AC = JA.getKind();
-  if (AC == Action::AssembleJobClass && useIntegratedAs())
+  if (AC == Action::AssembleJobClass && useIntegratedAs() &&
+  !getTriple().isOSAIX())
 return getClangAs();
   return getTool(AC);
 }


Index: clang/test/Driver/aix-assembler.s
===
--- /dev/null
+++ clang/test/Driver/aix-assembler.s
@@ -0,0 +1,31 @@
+
+// Check powerpc64-ibm-aix7.1.0.0, 64-bit.
+// RUN: %clang %s -### -c -fintegrated-as 2>&1 \
+// RUN: --target=powerpc64-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefixes=AS64,CHECK %s
+
+// RUN: %clang %s -### -c 2>&1 \
+// RUN: --target=powerpc64-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefixes=AS64,CHECK %s
+
+// RUN: %clang %s -### -c -fno-integrated-as 2>&1 \
+// RUN: --target=powerpc64-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefixes=AS64,CHECK %s
+
+// Check powerpc-ibm-aix7.1.0.0, 32-bit.
+// RUN: %clang %s -### -c -fintegrated-as 2>&1 \
+// RUN: --target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefixes=AS32,CHECK %s
+
+// RUN: %clang %s -### -c 2>&1 \
+// RUN: --target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefixes=AS32,CHECK %s
+
+// RUN: %clang %s -### -c 2>&1 -fno-integrated-as \
+// RUN: --target=powerpc-ibm-aix7.1.0.0 \
+// RUN:   | FileCheck --check-prefixes=AS32,CHECK %s
+
+// CHECK: 

[PATCH] D148489: [clangd] Implement configs to stop clangd produce a certain semantic tokens

2023-04-16 Thread Qingyuan Zheng via Phabricator via cfe-commits
daiyousei-qz added a comment.

Please hold off from reviewing this. I have been figuring out how arc tools 
work and the unittest of the current version is broken.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148489

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


[PATCH] D148489: Implement configs to stop clangd produce a certain semantic tokens

2023-04-16 Thread Qingyuan Zheng via Phabricator via cfe-commits
daiyousei-qz created this revision.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
daiyousei-qz requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148489

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/SemanticHighlighting.h
  clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp

Index: clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
@@ -246,6 +246,24 @@
   EXPECT_EQ(Results[0].InlayHints.DeducedTypes, std::nullopt);
 }
 
+TEST(ParseYAML, SemanticTokens) {
+  CapturedDiags Diags;
+  Annotations YAML(R"yaml(
+SemanticTokens:
+  DisabledKinds: [ Operator, InactiveCode]
+  DisabledModifiers: Readonly
+  )yaml");
+  auto Results =
+  Fragment::parseYAML(YAML.code(), "config.yaml", Diags.callback());
+  ASSERT_THAT(Diags.Diagnostics, IsEmpty());
+  ASSERT_EQ(Results.size(), 1u);
+  EXPECT_THAT(
+  Results[0].SemanticTokens.DisabledKinds,
+  llvm::ValueIs(val(std::vector{"Operator", "InactiveCode"})));
+  EXPECT_THAT(Results[0].SemanticTokens.DisabledModifiers,
+  llvm::ValueIs(val(std::vector{"Readonly"})));
+}
+
 TEST(ParseYAML, IncludesIgnoreHeader) {
   CapturedDiags Diags;
   Annotations YAML(R"yaml(
Index: clang-tools-extra/clangd/SemanticHighlighting.h
===
--- clang-tools-extra/clangd/SemanticHighlighting.h
+++ clang-tools-extra/clangd/SemanticHighlighting.h
@@ -61,6 +61,8 @@
 };
 
 llvm::raw_ostream <<(llvm::raw_ostream , HighlightingKind K);
+std::optional
+highlightingKindFromString(llvm::StringRef Name);
 
 enum class HighlightingModifier {
   Declaration,
@@ -88,6 +90,8 @@
 static_assert(static_cast(HighlightingModifier::LastModifier) < 32,
   "Increase width of modifiers bitfield!");
 llvm::raw_ostream <<(llvm::raw_ostream , HighlightingModifier K);
+std::optional
+highlightingModifierFromString(llvm::StringRef Name);
 
 // Contains all information needed for the highlighting a token.
 struct HighlightingToken {
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -7,6 +7,7 @@
 //===--===//
 
 #include "SemanticHighlighting.h"
+#include "Config.h"
 #include "FindTarget.h"
 #include "HeuristicResolver.h"
 #include "ParsedAST.h"
@@ -354,12 +355,58 @@
   return Winner;
 }
 
+/// Filter to remove particular kinds of highlighting tokens and modifiers from
+/// the output.
+class HighlightingFilter {
+public:
+  HighlightingFilter() {
+for (auto  : ActiveKindLookup)
+  Active = true;
+
+ActiveModifiersMask = ~0;
+  }
+
+  void disableKind(HighlightingKind Kind) {
+ActiveKindLookup[static_cast(Kind)] = false;
+  }
+
+  void disableModifier(HighlightingModifier Modifier) {
+ActiveModifiersMask &= ~(1 << static_cast(Modifier));
+  }
+
+  bool isHighlightKindActive(HighlightingKind Kind) const {
+return ActiveKindLookup[static_cast(Kind)];
+  }
+
+  uint32_t maskModifiers(uint32_t Modifiers) const {
+return Modifiers & ActiveModifiersMask;
+  }
+
+  static HighlightingFilter fromCurrentConfig() {
+const Config  = Config::current();
+HighlightingFilter Filter;
+for (const auto  : C.SemanticTokens.DisabledKinds)
+  if (auto K = highlightingKindFromString(Kind))
+Filter.disableKind(*K);
+for (const auto  : C.SemanticTokens.DisabledModifiers)
+  if (auto M = highlightingModifierFromString(Modifier))
+Filter.disableModifier(*M);
+
+return Filter;
+  }
+
+private:
+  bool ActiveKindLookup[static_cast(HighlightingKind::LastKind) + 1];
+  uint32_t ActiveModifiersMask;
+};
+
 /// Consumes source locations and maps them to text ranges for highlightings.
 class HighlightingsBuilder {
 public:
-  HighlightingsBuilder(const ParsedAST , bool IncludeInactiveRegionTokens)
+  HighlightingsBuilder(const ParsedAST , const HighlightingFilter ,
+   bool IncludeInactiveRegionTokens)
   : TB(AST.getTokens()), SourceMgr(AST.getSourceManager()),
-LangOpts(AST.getLangOpts()),
+LangOpts(AST.getLangOpts()), Filter(Filter),
 IncludeInactiveRegionTokens(IncludeInactiveRegionTokens) {}
 
   HighlightingToken (SourceLocation Loc, HighlightingKind Kind) {
@@ -412,6 +459,9 @@
   }
 
   HighlightingToken 

[PATCH] D148021: [Headers][doc] Add FMA intrinsic descriptions

2023-04-16 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei accepted this revision.
pengfei added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Headers/fmaintrin.h:22
+/// Computes a multiply-add of 128-bit vectors of [4 x float].
+///For each element, computes  (__A * __B) + __C .
+///

probinson wrote:
> pengfei wrote:
> > We are using a special format to describute the function in a pseudo code 
> > to share it with the intrinsic guide, e.g.,
> > https://github.com/llvm/llvm-project/blob/main/clang/lib/Headers/avx512fintrin.h#L9604-L9610
> > https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm512_i32logather_pd_expand=4077
> > 
> > There's no strong requirement to follow it, but it would be better to adopt 
> > a uniform format.
> Is a FOR loop with computed bit offsets really clearer than "For each 
> element" ? Is it valuable to repeat information that can be found in the 
> instruction reference? 
> I can accept answers of "yes" and "yes" because I am not someone who ever 
> deals with vector data, but I would be a little surprised by those answers.
> 
We have internal tools to verify them according to these offsets (but of course 
not for 100% intrinsics), which means we can trust such information in most 
time.

The suggestion is based on:
1. Correctness. It's easy to be errorprone for tedious documentations and we 
don't have other verifications but eyes;
2. Unity. Using the same format is not only better for clean code but also 
distinct for future developers to follow;

As I said before, I'm not forcing this way. You decide it.



Comment at: clang/lib/Headers/fmaintrin.h:26
+///
+/// This intrinsic corresponds to the  VFMADD213PS  instruction.
+///

probinson wrote:
> pengfei wrote:
> > It would be odd to user given this is just 1/3 instructions the intrinsic 
> > may generate, but I don't have a good idea here.
> I listed the 213 version because that's the one that multiplies the first two 
> operands, and the intrinsic multiplies the first two operands. So it's the 
> instruction that most closely corresponds to the intrinsic.
> We don't guarantee that the "corresponding" instruction is what is actually 
> generated, in general. I know this point has come up before regarding 
> intrinsic descriptions. My thinking is that the "corresponding instruction" 
> gives the reader a place to look in the instruction reference manual, so 
> listing only one is again okay.
Note, intrinsics are force inlined. It's rare user will wrap it in a simple 
function with the same arguments order. In reality, each version may be 
generated. https://godbolt.org/z/q7j8Wxrnb

However, I'm not against this approach if we don't have any better way to 
describe it.


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

https://reviews.llvm.org/D148021

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


[PATCH] D148472: [clang-format] CSharp don't allow there not to be a space between `is` and `[`

2023-04-16 Thread Owen Pan via Phabricator via cfe-commits
owenpan accepted this revision.
owenpan added inline comments.



Comment at: clang/unittests/Format/FormatTestCSharp.cpp:1182-1186
+  verifyFormat("return a is [1, 2, 3]", Style);
+  verifyFormat("return a is [..]", Style);
+  Style.SpaceBeforeSquareBrackets = false;
+  verifyFormat("return a is [1, 2, 3]", Style);
+  verifyFormat("return a is [..]", Style);

Should we end the return statements with a semicolon?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148472

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


[PATCH] D148447: [clang-format] Fix regression with AlignTrailingComments set to true

2023-04-16 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D148447#4271942 , @MyDeveloperDay 
wrote:

> If this was the functionality pre 16 then LGTM

Yep.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148447

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


[PATCH] D148447: [clang-format] Fix regression with AlignTrailingComments set to true

2023-04-16 Thread Owen Pan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2bcfff6708d2: [clang-format] Fix regression with 
AlignTrailingComments set to true (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148447

Files:
  clang/lib/Format/Format.cpp
  clang/unittests/Format/ConfigParseTest.cpp


Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -472,20 +472,20 @@
 
   CHECK_PARSE("AlignTrailingComments: Leave", AlignTrailingComments,
   FormatStyle::TrailingCommentsAlignmentStyle(
-  {FormatStyle::TCAS_Leave, 1}));
+  {FormatStyle::TCAS_Leave, 0}));
   CHECK_PARSE("AlignTrailingComments: Always", AlignTrailingComments,
   FormatStyle::TrailingCommentsAlignmentStyle(
-  {FormatStyle::TCAS_Always, 1}));
+  {FormatStyle::TCAS_Always, 0}));
   CHECK_PARSE("AlignTrailingComments: Never", AlignTrailingComments,
   FormatStyle::TrailingCommentsAlignmentStyle(
-  {FormatStyle::TCAS_Never, 1}));
+  {FormatStyle::TCAS_Never, 0}));
   // For backwards compatibility
   CHECK_PARSE("AlignTrailingComments: true", AlignTrailingComments,
   FormatStyle::TrailingCommentsAlignmentStyle(
-  {FormatStyle::TCAS_Always, 1}));
+  {FormatStyle::TCAS_Always, 0}));
   CHECK_PARSE("AlignTrailingComments: false", AlignTrailingComments,
   FormatStyle::TrailingCommentsAlignmentStyle(
-  {FormatStyle::TCAS_Never, 1}));
+  {FormatStyle::TCAS_Never, 0}));
   CHECK_PARSE_NESTED_VALUE("Kind: Always", AlignTrailingComments, Kind,
FormatStyle::TCAS_Always);
   CHECK_PARSE_NESTED_VALUE("Kind: Never", AlignTrailingComments, Kind,
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -722,23 +722,23 @@
 FormatStyle::TrailingCommentsAlignmentStyle ) {
 IO.enumCase(Value, "Leave",
 FormatStyle::TrailingCommentsAlignmentStyle(
-{FormatStyle::TCAS_Leave, 1}));
+{FormatStyle::TCAS_Leave, 0}));
 
 IO.enumCase(Value, "Always",
 FormatStyle::TrailingCommentsAlignmentStyle(
-{FormatStyle::TCAS_Always, 1}));
+{FormatStyle::TCAS_Always, 0}));
 
 IO.enumCase(Value, "Never",
 FormatStyle::TrailingCommentsAlignmentStyle(
-{FormatStyle::TCAS_Never, 1}));
+{FormatStyle::TCAS_Never, 0}));
 
 // For backwards compatibility
 IO.enumCase(Value, "true",
 FormatStyle::TrailingCommentsAlignmentStyle(
-{FormatStyle::TCAS_Always, 1}));
+{FormatStyle::TCAS_Always, 0}));
 IO.enumCase(Value, "false",
 FormatStyle::TrailingCommentsAlignmentStyle(
-{FormatStyle::TCAS_Never, 1}));
+{FormatStyle::TCAS_Never, 0}));
   }
 
   static void mapping(IO ,


Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -472,20 +472,20 @@
 
   CHECK_PARSE("AlignTrailingComments: Leave", AlignTrailingComments,
   FormatStyle::TrailingCommentsAlignmentStyle(
-  {FormatStyle::TCAS_Leave, 1}));
+  {FormatStyle::TCAS_Leave, 0}));
   CHECK_PARSE("AlignTrailingComments: Always", AlignTrailingComments,
   FormatStyle::TrailingCommentsAlignmentStyle(
-  {FormatStyle::TCAS_Always, 1}));
+  {FormatStyle::TCAS_Always, 0}));
   CHECK_PARSE("AlignTrailingComments: Never", AlignTrailingComments,
   FormatStyle::TrailingCommentsAlignmentStyle(
-  {FormatStyle::TCAS_Never, 1}));
+  {FormatStyle::TCAS_Never, 0}));
   // For backwards compatibility
   CHECK_PARSE("AlignTrailingComments: true", AlignTrailingComments,
   FormatStyle::TrailingCommentsAlignmentStyle(
-  {FormatStyle::TCAS_Always, 1}));
+  {FormatStyle::TCAS_Always, 0}));
   CHECK_PARSE("AlignTrailingComments: false", AlignTrailingComments,
   FormatStyle::TrailingCommentsAlignmentStyle(
-  {FormatStyle::TCAS_Never, 1}));
+  {FormatStyle::TCAS_Never, 0}));
   CHECK_PARSE_NESTED_VALUE("Kind: Always", AlignTrailingComments, Kind,
   

[clang] 2bcfff6 - [clang-format] Fix regression with AlignTrailingComments set to true

2023-04-16 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-04-16T18:52:17-07:00
New Revision: 2bcfff6708d293abab87a4d5a1dff25950d55d91

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

LOG: [clang-format] Fix regression with AlignTrailingComments set to true

Fixes #62161.

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

Added: 


Modified: 
clang/lib/Format/Format.cpp
clang/unittests/Format/ConfigParseTest.cpp

Removed: 




diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 6f377bb28e520..43054ec5f5d38 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -722,23 +722,23 @@ template <> struct 
MappingTraits {
 FormatStyle::TrailingCommentsAlignmentStyle ) {
 IO.enumCase(Value, "Leave",
 FormatStyle::TrailingCommentsAlignmentStyle(
-{FormatStyle::TCAS_Leave, 1}));
+{FormatStyle::TCAS_Leave, 0}));
 
 IO.enumCase(Value, "Always",
 FormatStyle::TrailingCommentsAlignmentStyle(
-{FormatStyle::TCAS_Always, 1}));
+{FormatStyle::TCAS_Always, 0}));
 
 IO.enumCase(Value, "Never",
 FormatStyle::TrailingCommentsAlignmentStyle(
-{FormatStyle::TCAS_Never, 1}));
+{FormatStyle::TCAS_Never, 0}));
 
 // For backwards compatibility
 IO.enumCase(Value, "true",
 FormatStyle::TrailingCommentsAlignmentStyle(
-{FormatStyle::TCAS_Always, 1}));
+{FormatStyle::TCAS_Always, 0}));
 IO.enumCase(Value, "false",
 FormatStyle::TrailingCommentsAlignmentStyle(
-{FormatStyle::TCAS_Never, 1}));
+{FormatStyle::TCAS_Never, 0}));
   }
 
   static void mapping(IO ,

diff  --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index 3d5e41776fca0..b2d79f4ca11e6 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -472,20 +472,20 @@ TEST(ConfigParseTest, ParsesConfiguration) {
 
   CHECK_PARSE("AlignTrailingComments: Leave", AlignTrailingComments,
   FormatStyle::TrailingCommentsAlignmentStyle(
-  {FormatStyle::TCAS_Leave, 1}));
+  {FormatStyle::TCAS_Leave, 0}));
   CHECK_PARSE("AlignTrailingComments: Always", AlignTrailingComments,
   FormatStyle::TrailingCommentsAlignmentStyle(
-  {FormatStyle::TCAS_Always, 1}));
+  {FormatStyle::TCAS_Always, 0}));
   CHECK_PARSE("AlignTrailingComments: Never", AlignTrailingComments,
   FormatStyle::TrailingCommentsAlignmentStyle(
-  {FormatStyle::TCAS_Never, 1}));
+  {FormatStyle::TCAS_Never, 0}));
   // For backwards compatibility
   CHECK_PARSE("AlignTrailingComments: true", AlignTrailingComments,
   FormatStyle::TrailingCommentsAlignmentStyle(
-  {FormatStyle::TCAS_Always, 1}));
+  {FormatStyle::TCAS_Always, 0}));
   CHECK_PARSE("AlignTrailingComments: false", AlignTrailingComments,
   FormatStyle::TrailingCommentsAlignmentStyle(
-  {FormatStyle::TCAS_Never, 1}));
+  {FormatStyle::TCAS_Never, 0}));
   CHECK_PARSE_NESTED_VALUE("Kind: Always", AlignTrailingComments, Kind,
FormatStyle::TCAS_Always);
   CHECK_PARSE_NESTED_VALUE("Kind: Never", AlignTrailingComments, Kind,



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


[PATCH] D148457: [clangd] Support macro evaluation on hover

2023-04-16 Thread Younan Zhang via Phabricator via cfe-commits
zyounan created this revision.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
zyounan updated this revision to Diff 513979.
zyounan added a comment.
zyounan updated this revision to Diff 514019.
zyounan updated this revision to Diff 514028.
zyounan added reviewers: nridge, sammccall, kadircet.
zyounan published this revision for review.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

~~Fix tests on Windows~~


zyounan added a comment.

unsigned long isn't 8 bytes on windows


zyounan added a comment.

Do not validate type of builtin operators


Creating a SelectionTree at the location where macro expands allows
us to obtain the associated expression, which might then be used to
evaluate compile-time values if possible.

Closes clangd/clangd#1595.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148457

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/unittests/HoverTests.cpp

Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -529,6 +529,8 @@
[](HoverInfo ) {
  HI.Name = "MACRO";
  HI.Kind = index::SymbolKind::Macro;
+ HI.Value = "41 (0x29)";
+ HI.Type = "int";
  HI.Definition = "#define MACRO 41\n\n"
  "// Expands to\n"
  "41";
@@ -1792,6 +1794,8 @@
   )cpp",
   [](HoverInfo ) {
 HI.Name = "MACRO";
+HI.Value = "0";
+HI.Type = "int";
 HI.Kind = index::SymbolKind::Macro;
 HI.Definition = "#define MACRO 0\n\n"
 "// Expands to\n"
@@ -3746,6 +3750,132 @@
   EXPECT_EQ(H->Type->Type, "int");
   EXPECT_EQ(H->Definition, "using foo = type");
 }
+
+TEST(Hover, EvaluateMacros) {
+  Annotations CXX(R"cpp(
+  #define X 42
+  #define SizeOf sizeof
+  #define AlignOf alignof
+
+  using u64 = unsigned long long;
+  // calculate (a ** b) % p
+  constexpr u64 pow_with_mod(u64 a, u64 b, u64 p) {
+u64 ret = 1;
+while (b) {
+  if (b & 1)
+ret = (ret * a) % p;
+  a = (a * a) % p;
+  b >>= 1;
+}
+return ret;
+  }
+  #define last_n_digit(x, y, n)  \
+pow_with_mod(x, y, pow_with_mod(10, n, 2147483647))
+  #define declare_struct(X, name, value) \
+struct X {   \
+  constexpr auto name() { return value; }\
+}
+  #define gnu_statement_expression(value)\
+({   \
+  declare_struct(Widget, getter, value); \
+  Widget().getter(); \
+})
+  #define define_lambda_begin(lambda, ...)   \
+[&](__VA_ARGS__) {
+  #define define_lambda_end() }
+
+void check() {
+  X$1^;
+  Size$2^Of(int);
+  struct Y {
+int y;
+double z;
+  };
+  Alig$3^nOf(Y);
+  // 2**32 == 4294967296
+  last_n_di$4^git(2, 32, 6);
+  gnu_statement_exp$5^ression(42);
+
+  constexpr auto value = define_lamb$6^da_begin(lambda, int, char)
+// Check if the expansion range is right.
+return $7^last_n_digit(10, 3, 3)$8^;
+  define_lam$9^bda_end();
+}
+  )cpp");
+
+  Config Cfg;
+  Cfg.Hover.ShowAKA = false;
+  WithContextValue WithCfg(Config::Key, std::move(Cfg));
+
+  auto TU = TestTU::withCode(CXX.code());
+  TU.ExtraArgs.push_back("-std=c++17");
+  auto GetHoverAt = [AST(TU.build()), CXX](llvm::StringRef Point) mutable {
+return getHover(AST, CXX.point(Point), format::getLLVMStyle(), nullptr);
+  };
+
+  std::optional H;
+
+  H = GetHoverAt("1");
+  ASSERT_TRUE(H);
+  EXPECT_EQ(H->Value, "42 (0x2a)");
+  EXPECT_EQ(H->Type, HoverInfo::PrintedType("int"));
+
+  H = GetHoverAt("2");
+  ASSERT_TRUE(H);
+  EXPECT_EQ(H->Value, "4");
+  // Don't validate type of `sizeof` and `alignof` as we're getting different
+  // desugared types on different platforms. Same as below.
+
+  H = GetHoverAt("3");
+  ASSERT_TRUE(H);
+  EXPECT_EQ(H->Value, "8");
+
+  H = GetHoverAt("4");
+  ASSERT_TRUE(H);
+  EXPECT_EQ(H->Value, "967296 (0xec280)");
+  EXPECT_EQ(H->Type, HoverInfo::PrintedType("u64"));
+
+  H = GetHoverAt("5");
+  ASSERT_TRUE(H);
+  EXPECT_EQ(H->Value, "42 (0x2a)");
+  EXPECT_EQ(H->Type, HoverInfo::PrintedType("int"));
+
+  H = GetHoverAt("6");
+  ASSERT_TRUE(H);
+  EXPECT_FALSE(H->Value) << H->Value;
+  EXPECT_EQ(H->Type, HoverInfo::PrintedType("class (lambda)")) << H->Type;
+
+  H = GetHoverAt("7");
+  

[PATCH] D148439: [clang-rename] Exit gracefully when no input provided

2023-04-16 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev accepted this revision.
kbobyrev added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/tools/clang-rename/ClangRename.cpp:130
+  } else {
+errs() << "clang-rename: No input provided.\n";
+return 1;

Probably something like "input must be provided" would be more understandable 
by the user, but this is also fine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148439

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


[PATCH] D148482: [clang-format][NFC] Output tokens on test assert

2023-04-16 Thread sstwcw via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb6301a018d58: [clang-format][NFC] Output tokens on test 
assert (authored by sstwcw).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148482

Files:
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -841,7 +841,7 @@
 "  [[nodiscard]] constexpr operator T() const { "
 "return number_zero_v; }\n"
 "};");
-  ASSERT_EQ(Tokens.size(), 44u);
+  ASSERT_EQ(Tokens.size(), 44u) << Tokens;
   EXPECT_TOKEN(Tokens[13], tok::kw_requires, TT_RequiresClause);
   EXPECT_TOKEN(Tokens[14], tok::kw_requires, TT_RequiresExpression);
   EXPECT_TOKEN(Tokens[15], tok::l_brace, TT_RequiresExpressionLBrace);
@@ -1605,7 +1605,7 @@
   // Test for block label colons.
   Tokens = Annotate("begin : x\n"
 "end : x");
-  ASSERT_EQ(Tokens.size(), 7u);
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::colon, TT_VerilogBlockLabelColon);
   EXPECT_TOKEN(Tokens[4], tok::colon, TT_VerilogBlockLabelColon);
   // Test that the dimension colon is annotated correctly.
@@ -1632,15 +1632,15 @@
   EXPECT_TOKEN(Tokens[9], tok::colon, TT_GotoLabelColon);
   // Non-blocking assignments.
   Tokens = Annotate("a <= b;");
-  ASSERT_EQ(Tokens.size(), 5u);
+  ASSERT_EQ(Tokens.size(), 5u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::lessequal, TT_BinaryOperator);
   EXPECT_TOKEN_PRECEDENCE(Tokens[1], prec::Assignment);
   Tokens = Annotate("if (a <= b) break;");
-  ASSERT_EQ(Tokens.size(), 9u);
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::lessequal, TT_BinaryOperator);
   EXPECT_TOKEN_PRECEDENCE(Tokens[3], prec::Relational);
   Tokens = Annotate("a <= b <= a;");
-  ASSERT_EQ(Tokens.size(), 7u);
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::lessequal, TT_BinaryOperator);
   EXPECT_TOKEN_PRECEDENCE(Tokens[1], prec::Assignment);
   EXPECT_TOKEN(Tokens[3], tok::lessequal, TT_BinaryOperator);
@@ -1648,12 +1648,12 @@
 
   // Port lists in module instantiation.
   Tokens = Annotate("module_x instance_1(port_1), instance_2(port_2);");
-  ASSERT_EQ(Tokens.size(), 12u);
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_VerilogInstancePortLParen);
   EXPECT_TOKEN(Tokens[7], tok::l_paren, TT_VerilogInstancePortLParen);
   Tokens = Annotate("module_x #(parameter) instance_1(port_1), "
 "instance_2(port_2);");
-  ASSERT_EQ(Tokens.size(), 16u);
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_VerilogInstancePortLParen);
   EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_VerilogInstancePortLParen);
   EXPECT_TOKEN(Tokens[11], tok::l_paren, TT_VerilogInstancePortLParen);


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -841,7 +841,7 @@
 "  [[nodiscard]] constexpr operator T() const { "
 "return number_zero_v; }\n"
 "};");
-  ASSERT_EQ(Tokens.size(), 44u);
+  ASSERT_EQ(Tokens.size(), 44u) << Tokens;
   EXPECT_TOKEN(Tokens[13], tok::kw_requires, TT_RequiresClause);
   EXPECT_TOKEN(Tokens[14], tok::kw_requires, TT_RequiresExpression);
   EXPECT_TOKEN(Tokens[15], tok::l_brace, TT_RequiresExpressionLBrace);
@@ -1605,7 +1605,7 @@
   // Test for block label colons.
   Tokens = Annotate("begin : x\n"
 "end : x");
-  ASSERT_EQ(Tokens.size(), 7u);
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::colon, TT_VerilogBlockLabelColon);
   EXPECT_TOKEN(Tokens[4], tok::colon, TT_VerilogBlockLabelColon);
   // Test that the dimension colon is annotated correctly.
@@ -1632,15 +1632,15 @@
   EXPECT_TOKEN(Tokens[9], tok::colon, TT_GotoLabelColon);
   // Non-blocking assignments.
   Tokens = Annotate("a <= b;");
-  ASSERT_EQ(Tokens.size(), 5u);
+  ASSERT_EQ(Tokens.size(), 5u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::lessequal, TT_BinaryOperator);
   EXPECT_TOKEN_PRECEDENCE(Tokens[1], prec::Assignment);
   Tokens = Annotate("if (a <= b) break;");
-  ASSERT_EQ(Tokens.size(), 9u);
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::lessequal, TT_BinaryOperator);
   EXPECT_TOKEN_PRECEDENCE(Tokens[3], prec::Relational);
   Tokens = Annotate("a <= b <= a;");
-  ASSERT_EQ(Tokens.size(), 7u);
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::lessequal, TT_BinaryOperator);
   

[clang] b6301a0 - [clang-format][NFC] Output tokens on test assert

2023-04-16 Thread via cfe-commits

Author: sstwcw
Date: 2023-04-16T23:48:07Z
New Revision: b6301a018d585723610c9718b0a4d1bd9e696b17

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

LOG: [clang-format][NFC] Output tokens on test assert

Reviewed By: rymiel

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

Added: 


Modified: 
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index ce37abed595d..c49c4182807e 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -841,7 +841,7 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresClausesAndConcepts) {
 "  [[nodiscard]] constexpr operator T() const { "
 "return number_zero_v; }\n"
 "};");
-  ASSERT_EQ(Tokens.size(), 44u);
+  ASSERT_EQ(Tokens.size(), 44u) << Tokens;
   EXPECT_TOKEN(Tokens[13], tok::kw_requires, TT_RequiresClause);
   EXPECT_TOKEN(Tokens[14], tok::kw_requires, TT_RequiresExpression);
   EXPECT_TOKEN(Tokens[15], tok::l_brace, TT_RequiresExpressionLBrace);
@@ -1605,7 +1605,7 @@ TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) {
   // Test for block label colons.
   Tokens = Annotate("begin : x\n"
 "end : x");
-  ASSERT_EQ(Tokens.size(), 7u);
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::colon, TT_VerilogBlockLabelColon);
   EXPECT_TOKEN(Tokens[4], tok::colon, TT_VerilogBlockLabelColon);
   // Test that the dimension colon is annotated correctly.
@@ -1632,15 +1632,15 @@ TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) 
{
   EXPECT_TOKEN(Tokens[9], tok::colon, TT_GotoLabelColon);
   // Non-blocking assignments.
   Tokens = Annotate("a <= b;");
-  ASSERT_EQ(Tokens.size(), 5u);
+  ASSERT_EQ(Tokens.size(), 5u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::lessequal, TT_BinaryOperator);
   EXPECT_TOKEN_PRECEDENCE(Tokens[1], prec::Assignment);
   Tokens = Annotate("if (a <= b) break;");
-  ASSERT_EQ(Tokens.size(), 9u);
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::lessequal, TT_BinaryOperator);
   EXPECT_TOKEN_PRECEDENCE(Tokens[3], prec::Relational);
   Tokens = Annotate("a <= b <= a;");
-  ASSERT_EQ(Tokens.size(), 7u);
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::lessequal, TT_BinaryOperator);
   EXPECT_TOKEN_PRECEDENCE(Tokens[1], prec::Assignment);
   EXPECT_TOKEN(Tokens[3], tok::lessequal, TT_BinaryOperator);
@@ -1648,12 +1648,12 @@ TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) 
{
 
   // Port lists in module instantiation.
   Tokens = Annotate("module_x instance_1(port_1), instance_2(port_2);");
-  ASSERT_EQ(Tokens.size(), 12u);
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_VerilogInstancePortLParen);
   EXPECT_TOKEN(Tokens[7], tok::l_paren, TT_VerilogInstancePortLParen);
   Tokens = Annotate("module_x #(parameter) instance_1(port_1), "
 "instance_2(port_2);");
-  ASSERT_EQ(Tokens.size(), 16u);
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_VerilogInstancePortLParen);
   EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_VerilogInstancePortLParen);
   EXPECT_TOKEN(Tokens[11], tok::l_paren, TT_VerilogInstancePortLParen);



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


[PATCH] D148484: [clang-format] Correctly format goto labels followed by blocks

2023-04-16 Thread sstwcw via Phabricator via cfe-commits
sstwcw added inline comments.



Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:714
 // are in a control flow statements as well as several style flags.
-if (Line.First->is(tok::kw_case) ||
+if (Line.First->is(tok::kw_case) || Line.Last->is(TT_GotoLabelColon) ||
+Line.Last->endsSequence(tok::l_brace, TT_GotoLabelColon) ||

Should I make this change?

Without it:

```
label: { break; }
```

With it:

```
label: {
  break;
}
```

Without the entire patch:

```
label : { break; }
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148484

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


[PATCH] D148484: [clang-format] Correctly format goto labels followed by blocks

2023-04-16 Thread sstwcw via Phabricator via cfe-commits
sstwcw created this revision.
sstwcw added reviewers: HazardyKnusperkeks, MyDeveloperDay, owenpan, rymiel.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
sstwcw requested review of this revision.

There doesn't seem to be an issue on GitHub.  But previously, a space
would be inserted before the goto colon in the code below.

  switch (x) {
  case 0:
  goto_0: {
action();
break;
  }
  }

Previously, the colon following a goto label would be annotated as
`TT_InheritanceColon`.  A goto label followed by an opening brace
wasn't recognized.  It is easy to add another line to have
`spaceRequiredBefore` function recognize the case, but I believed it
is more proper to avoid doing the same thing in `UnwrappedLineParser`
and `TokenAnnotator`.  So now the label colons would be labeled in
`UnwrappedLineParser`, and `spaceRequiredBefore` would rely on that.

Previously we had the type `TT_GotoLabelColon` intended for both goto
labels and case labels.  But since handling of goto labels and case
labels differ somewhat, I split it into separate types for goto and
case labels.

This patch doesn't change the behavior for case labels.  I added the
lines annotating case labels because they would previously be
mistakenly annotated as `TT_InheritanceColon` just like goto labels.
And since I added the annotations, the checks for the `case` and
`default` keywords in `spaceRequiredBefore` are not necessary anymore.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148484

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1621,7 +1621,7 @@
 "x;\n"
 "endcase\n");
   ASSERT_EQ(Tokens.size(), 10u) << Tokens;
-  EXPECT_TOKEN(Tokens[5], tok::colon, TT_GotoLabelColon);
+  EXPECT_TOKEN(Tokens[5], tok::colon, TT_CaseLabelColon);
   Tokens = Annotate("case (x)\n"
 "  x ? x : x:\n"
 "x;\n"
@@ -1629,7 +1629,7 @@
   ASSERT_EQ(Tokens.size(), 14u) << Tokens;
   EXPECT_TOKEN(Tokens[5], tok::question, TT_ConditionalExpr);
   EXPECT_TOKEN(Tokens[7], tok::colon, TT_ConditionalExpr);
-  EXPECT_TOKEN(Tokens[9], tok::colon, TT_GotoLabelColon);
+  EXPECT_TOKEN(Tokens[9], tok::colon, TT_CaseLabelColon);
   // Non-blocking assignments.
   Tokens = Annotate("a <= b;");
   ASSERT_EQ(Tokens.size(), 5u);
@@ -1708,6 +1708,7 @@
   EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace);
 }
 
+
 TEST_F(TokenAnnotatorTest, UnderstandsConditionParens) {
   auto Tokens = annotate("if (x) {}");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
@@ -1724,6 +1725,21 @@
   EXPECT_TOKEN(Tokens[8], tok::l_paren, TT_ConditionLParen);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsLabels) {
+  auto Tokens = annotate("{ x: break; }");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::colon, TT_GotoLabelColon);
+  Tokens = annotate("{ case x: break; }");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::colon, TT_CaseLabelColon);
+  Tokens = annotate("{ x: { break; } }");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::colon, TT_GotoLabelColon);
+  Tokens = annotate("{ case x: { break; } }");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::colon, TT_CaseLabelColon);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -2998,6 +2998,12 @@
"test_label:;\n"
"  int i = 0;\n"
"}");
+  verifyFormat("{\n"
+   "  some_code();\n"
+   "test_label: {\n"
+   "  some_other_code();\n"
+   "}\n"
+   "}");
   FormatStyle Style = getLLVMStyle();
   Style.IndentGotoLabels = false;
   verifyFormat("void f() {\n"
@@ -3019,9 +3025,23 @@
Style);
   verifyFormat("{\n"
"  some_code();\n"
-   "test_label:;\n"
-   "  int i = 0;\n"
-   "}");
+   "test_label: {\n"
+   "  some_other_code();\n"
+   "}\n"
+   "}",
+   Style);
+  // The opening brace may either be on the same unwrapped line as the colon or
+  // on a separate one. The formatter should recognize both.
+  Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BraceBreakingStyle::BS_Allman;
+  verifyFormat("{\n"
+ 

[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-04-16 Thread Lang Hames via Phabricator via cfe-commits
lhames added a comment.

> OTOH it's a challenge to review since the patch is really big. Is there no 
> way to break it up and test in isolation? Or strip away details that could be 
> added in iterations? I had a short look and some comments, but I won't find 
> the time in the coming weeks to give it the attention it deserves.
>
> My biggest conceptual concern is that Value is part of the Interpreter 
> library. This is going to be a showstopper for out-of-process execution. 
> Conceptually, it should move into a runtime library (like the ORC runtime in 
> compiler-rt) and this won't get easier the more it is entangled with the 
> interpreter. I do see that this adds significant complexity and I guess it's 
> ok to keep this for later, but I do wonder what would be the best way to 
> prepare for it. Essentially, all communication with the interpreter will be 
> asynchronous. Is this something we can do already?

Similar thoughts here. In particular, is there a way to break the 
`IsSemiMissing`/ `repl_input_end` parts out from the Value part?

It sounds like it would be helpful for `clang-repl` to land this as-is, but we 
should have a plan to replace this with something compatible with 
out-of-process execution in the longer term. At a guess I think that would mean 
using regular global variable instances to manage the storage on the executor 
side, an extended `MemoryAccess` interface to read/write the value from the 
REPL side when needed (e.g. for printing), and emitting glue functions to pass 
the variable's value in to callers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

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


[PATCH] D148372: [clang] add diagnose when member function contains invalid default argument

2023-04-16 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Parse/ParseDecl.cpp:7385
   if (!ConsumeAndStoreInitializer(*DefArgToks, CIK_DefaultArgument)) {
 DefArgToks.reset();
+Diag(ArgStartLoc, diag::err_expected) << "initializer";

I think we should just remove this `reset` call. That way, the tokens we've 
accumulated will get parsed when we come to later process the default argument, 
and we can produce the proper error at that time, such as diagnosing a missing 
`:`. That's what we do for default member initializers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148372

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


[PATCH] D148474: [Clang] Fix ResolveConstructorOverload to not select a conversion function if we are going use copy elision

2023-04-16 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:746
+ diag::note_template_class_instantiation_here)
+<< CTD << Active->InstantiationRange;
   } else {

This diagnostic won't include the template arguments that we're using to 
instantiate, which seems like important information.

Do you know where we're creating the `InstantiatingTemplate` instance 
corresponding to this diagnostic? Usually we pass in the declaration whose 
definition we're instantiating for a `TemplateInstantiation` record; I wonder 
if we could do the same for this case.



Comment at: clang/test/SemaCXX/cxx1z-copy-omission.cpp:175
+
+// Make sure we don't consider conversion functions for guaranteed copy elision
+namespace GH39319 {

We should also test that the right function is actually being selected and 
called. For example:

```
struct A {
  A();
  A(const A&) = delete;
};
struct B {
  operator A();
} C;
A::A() : A(C) {}
```
... should be rejected because it calls the deleted copy constructor. (Or you 
could test this via constant evaluation or look at the generated code, but this 
is probably the simplest way.)



Comment at: clang/test/SemaCXX/cxx1z-copy-omission.cpp:193
+template
+class B3 : A3 // expected-error {{expected '{' after base class list}}
+  template()> // expected-warning 2{{use of function template 
name with no prior declaration in function call with explicit}}

Do you need to omit the `{` here as part of this test? This will cause problems 
for people editing the file due to mismatched braces, and makes this test 
fragile if our error recovery changes. It's best for the test case to be free 
of errors other than the one(s) being exercised. (Same for missing `;` errors 
below.)

If these errors are necessary to trigger the bug you found, I wonder if there's 
a problem with our error recovery. (Maybe we create a "bad" 
`InstantiatingTemplate` record during error recovery, for example.)


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

https://reviews.llvm.org/D148474

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


[PATCH] D148482: [clang-format][NFC] Output tokens on test assert

2023-04-16 Thread sstwcw via Phabricator via cfe-commits
sstwcw created this revision.
sstwcw added reviewers: HazardyKnusperkeks, MyDeveloperDay, owenpan, rymiel.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
sstwcw requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148482

Files:
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -841,7 +841,7 @@
 "  [[nodiscard]] constexpr operator T() const { "
 "return number_zero_v; }\n"
 "};");
-  ASSERT_EQ(Tokens.size(), 44u);
+  ASSERT_EQ(Tokens.size(), 44u) << Tokens;
   EXPECT_TOKEN(Tokens[13], tok::kw_requires, TT_RequiresClause);
   EXPECT_TOKEN(Tokens[14], tok::kw_requires, TT_RequiresExpression);
   EXPECT_TOKEN(Tokens[15], tok::l_brace, TT_RequiresExpressionLBrace);
@@ -1605,7 +1605,7 @@
   // Test for block label colons.
   Tokens = Annotate("begin : x\n"
 "end : x");
-  ASSERT_EQ(Tokens.size(), 7u);
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::colon, TT_VerilogBlockLabelColon);
   EXPECT_TOKEN(Tokens[4], tok::colon, TT_VerilogBlockLabelColon);
   // Test that the dimension colon is annotated correctly.
@@ -1632,15 +1632,15 @@
   EXPECT_TOKEN(Tokens[9], tok::colon, TT_GotoLabelColon);
   // Non-blocking assignments.
   Tokens = Annotate("a <= b;");
-  ASSERT_EQ(Tokens.size(), 5u);
+  ASSERT_EQ(Tokens.size(), 5u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::lessequal, TT_BinaryOperator);
   EXPECT_TOKEN_PRECEDENCE(Tokens[1], prec::Assignment);
   Tokens = Annotate("if (a <= b) break;");
-  ASSERT_EQ(Tokens.size(), 9u);
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::lessequal, TT_BinaryOperator);
   EXPECT_TOKEN_PRECEDENCE(Tokens[3], prec::Relational);
   Tokens = Annotate("a <= b <= a;");
-  ASSERT_EQ(Tokens.size(), 7u);
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::lessequal, TT_BinaryOperator);
   EXPECT_TOKEN_PRECEDENCE(Tokens[1], prec::Assignment);
   EXPECT_TOKEN(Tokens[3], tok::lessequal, TT_BinaryOperator);
@@ -1648,12 +1648,12 @@
 
   // Port lists in module instantiation.
   Tokens = Annotate("module_x instance_1(port_1), instance_2(port_2);");
-  ASSERT_EQ(Tokens.size(), 12u);
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_VerilogInstancePortLParen);
   EXPECT_TOKEN(Tokens[7], tok::l_paren, TT_VerilogInstancePortLParen);
   Tokens = Annotate("module_x #(parameter) instance_1(port_1), "
 "instance_2(port_2);");
-  ASSERT_EQ(Tokens.size(), 16u);
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_VerilogInstancePortLParen);
   EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_VerilogInstancePortLParen);
   EXPECT_TOKEN(Tokens[11], tok::l_paren, TT_VerilogInstancePortLParen);


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -841,7 +841,7 @@
 "  [[nodiscard]] constexpr operator T() const { "
 "return number_zero_v; }\n"
 "};");
-  ASSERT_EQ(Tokens.size(), 44u);
+  ASSERT_EQ(Tokens.size(), 44u) << Tokens;
   EXPECT_TOKEN(Tokens[13], tok::kw_requires, TT_RequiresClause);
   EXPECT_TOKEN(Tokens[14], tok::kw_requires, TT_RequiresExpression);
   EXPECT_TOKEN(Tokens[15], tok::l_brace, TT_RequiresExpressionLBrace);
@@ -1605,7 +1605,7 @@
   // Test for block label colons.
   Tokens = Annotate("begin : x\n"
 "end : x");
-  ASSERT_EQ(Tokens.size(), 7u);
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::colon, TT_VerilogBlockLabelColon);
   EXPECT_TOKEN(Tokens[4], tok::colon, TT_VerilogBlockLabelColon);
   // Test that the dimension colon is annotated correctly.
@@ -1632,15 +1632,15 @@
   EXPECT_TOKEN(Tokens[9], tok::colon, TT_GotoLabelColon);
   // Non-blocking assignments.
   Tokens = Annotate("a <= b;");
-  ASSERT_EQ(Tokens.size(), 5u);
+  ASSERT_EQ(Tokens.size(), 5u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::lessequal, TT_BinaryOperator);
   EXPECT_TOKEN_PRECEDENCE(Tokens[1], prec::Assignment);
   Tokens = Annotate("if (a <= b) break;");
-  ASSERT_EQ(Tokens.size(), 9u);
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::lessequal, TT_BinaryOperator);
   EXPECT_TOKEN_PRECEDENCE(Tokens[3], prec::Relational);
   Tokens = Annotate("a <= b <= a;");
-  ASSERT_EQ(Tokens.size(), 7u);
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::lessequal, TT_BinaryOperator);
   EXPECT_TOKEN_PRECEDENCE(Tokens[1], prec::Assignment);
   

[clang] 0571ba8 - [clang-format] Handle Verilog assertions and loops

2023-04-16 Thread via cfe-commits

Author: sstwcw
Date: 2023-04-16T21:55:50Z
New Revision: 0571ba8d1b4dbe72e0856f9b84146cc6e152a4d0

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

LOG: [clang-format] Handle Verilog assertions and loops

Assert statements in Verilog can optionally have an else part.  We
handle them like for `if` statements, except that an `if` statement in
the else part of an `assert` statement doesn't get merged with the
`else` keyword.  Like this:

assert (x)
  $info();
else
  if (y)
$info();
  else if (z)
$info();
  else
$info();

`foreach` and `repeat` are now handled like for or while loops.

We used the type `TT_ConditionLParen` to mark the condition part so
they are handled in the same way as the condition part of an `if`
statement.  When the code being formatted is not in Verilog, it is
only set for `if` statements, not loops.  It's because loop conditions
are currently handled slightly differently, and existing behavior is
not supposed to change.  We formatted all files ending in `.cpp` and
`.h` in the repository with and without this change.  It showed that
setting the type for `if` statements doesn't change existing behavior.

And we noticed that we forgot to make the program print the list of
tokens when the number is not correct in `TokenAnnotatorTest`.  It's
fixed now.

Reviewed By: HazardyKnusperkeks

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

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/UnwrappedLineParser.cpp
clang/lib/Format/UnwrappedLineParser.h
clang/unittests/Format/FormatTestVerilog.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 9060bf76a7f52..28e21f93c14c4 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3700,9 +3700,11 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine ,
   LeftParen = 
 else if (Right.is(tok::r_paren) && Right.MatchingParen)
   LeftParen = Right.MatchingParen;
-if (LeftParen && LeftParen->Previous &&
-isKeywordWithCondition(*LeftParen->Previous)) {
-  return true;
+if (LeftParen) {
+  if (LeftParen->is(TT_ConditionLParen))
+return true;
+  if (LeftParen->Previous && isKeywordWithCondition(*LeftParen->Previous))
+return true;
 }
   }
 

diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 9158333911ae2..5c6816d6df30f 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1393,6 +1393,15 @@ void UnwrappedLineParser::parseStructuralElement(
   parseForOrWhileLoop(/*HasParens=*/false);
   return;
 }
+if (FormatTok->isOneOf(Keywords.kw_foreach, Keywords.kw_repeat)) {
+  parseForOrWhileLoop();
+  return;
+}
+if (FormatTok->isOneOf(tok::kw_restrict, Keywords.kw_assert,
+   Keywords.kw_assume, Keywords.kw_cover)) {
+  parseIfThenElse(IfKind, /*KeepBraces=*/false, /*IsVerilogAssert=*/true);
+  return;
+}
 
 // Skip things that can exist before keywords like 'if' and 'case'.
 while (true) {
@@ -2624,9 +2633,28 @@ bool UnwrappedLineParser::isBlockBegin(const FormatToken 
) const {
 }
 
 FormatToken *UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
-  bool KeepBraces) {
-  assert(FormatTok->is(tok::kw_if) && "'if' expected");
+  bool KeepBraces,
+  bool IsVerilogAssert) {
+  assert((FormatTok->is(tok::kw_if) ||
+  (Style.isVerilog() &&
+   FormatTok->isOneOf(tok::kw_restrict, Keywords.kw_assert,
+  Keywords.kw_assume, Keywords.kw_cover))) &&
+ "'if' expected");
   nextToken();
+
+  if (IsVerilogAssert) {
+// Handle `assert #0` and `assert final`.
+if (FormatTok->is(Keywords.kw_verilogHash)) {
+  nextToken();
+  if (FormatTok->is(tok::numeric_constant))
+nextToken();
+} else if (FormatTok->isOneOf(Keywords.kw_final, Keywords.kw_property,
+  Keywords.kw_sequence)) {
+  nextToken();
+}
+  }
+
+  // Handle `if !consteval`.
   if (FormatTok->is(tok::exclaim))
 nextToken();
 
@@ -2637,10 +2665,18 @@ FormatToken 
*UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
 KeepIfBraces = !Style.RemoveBracesLLVM || KeepBraces;
 if (FormatTok->isOneOf(tok::kw_constexpr, tok::identifier))
   nextToken();
-if (FormatTok->is(tok::l_paren))
+if (FormatTok->is(tok::l_paren)) {
+   

[PATCH] D147895: [clang-format] Handle Verilog assertions and loops

2023-04-16 Thread sstwcw via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0571ba8d1b4d: [clang-format] Handle Verilog assertions and 
loops (authored by sstwcw).

Changed prior to commit:
  https://reviews.llvm.org/D147895?vs=512044=514053#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147895

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTestVerilog.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1657,6 +1657,26 @@
   EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_VerilogInstancePortLParen);
   EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_VerilogInstancePortLParen);
   EXPECT_TOKEN(Tokens[11], tok::l_paren, TT_VerilogInstancePortLParen);
+
+  // Condition parentheses.
+  Tokens = Annotate("assert (x);");
+  ASSERT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_ConditionLParen);
+  Tokens = Annotate("assert #0 (x);");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_ConditionLParen);
+  Tokens = Annotate("assert final (x);");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_ConditionLParen);
+  Tokens = Annotate("foreach (x[x]) continue;");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_ConditionLParen);
+  Tokens = Annotate("repeat (x[x]) continue;");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_ConditionLParen);
+  Tokens = Annotate("case (x) endcase;");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_ConditionLParen);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandConstructors) {
@@ -1688,6 +1708,22 @@
   EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsConditionParens) {
+  auto Tokens = annotate("if (x) {}");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_ConditionLParen);
+  Tokens = annotate("if constexpr (x) {}");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_ConditionLParen);
+  Tokens = annotate("if CONSTEXPR (x) {}");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::l_paren, TT_ConditionLParen);
+  Tokens = annotate("if (x) {} else if (x) {}");
+  ASSERT_EQ(Tokens.size(), 14u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_ConditionLParen);
+  EXPECT_TOKEN(Tokens[8], tok::l_paren, TT_ConditionLParen);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -671,6 +671,107 @@
"  x = x;");
   verifyFormat("(* x, x = \"x\" *) if (x)\n"
"  x = x;");
+
+  // Assert are treated similar to if.  But the else parts should not be
+  // chained.
+  verifyFormat("assert (x);");
+  verifyFormat("assert (x)\n"
+   "  $info();");
+  verifyFormat("assert (x)\n"
+   "  $info();\n"
+   "else\n"
+   "  $error();");
+  verifyFormat("assert (x)\n"
+   "else\n"
+   "  $error();");
+  verifyFormat("assert (x)\n"
+   "else begin\n"
+   "end");
+  verifyFormat("assert (x)\n"
+   "else\n"
+   "  if (x)\n"
+   "$error();");
+  verifyFormat("assert (x)\n"
+   "  $info();\n"
+   "else\n"
+   "  if (x)\n"
+   "$error();");
+  verifyFormat("assert (x)\n"
+   "  $info();\n"
+   "else\n"
+   "  if (x)\n"
+   "$error();\n"
+   "  else\n"
+   "$error();");
+  verifyFormat("assert (x)\n"
+   "  $info();\n"
+   "else\n"
+   "  if (x)\n"
+   "$error();\n"
+   "  else if (x)\n"
+   "$error();\n"
+   "  else\n"
+   "$error();");
+  // The body is optional for asserts.  The next line should not be indented if
+  // the statement already ended with a semicolon.
+  verifyFormat("assert (x);\n"
+   "x = x;");
+  verifyFormat("if (x)\n"
+   "  assert (x);\n"
+   "else if (x) begin\n"
+   "end else begin\n"
+   "end");
+  verifyFormat("if (x)\n"
+   "  assert (x);\n"

[clang] 872536f - [clang] Modernize ModuleDeclSeq (NFC)

2023-04-16 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-04-16T14:48:18-07:00
New Revision: 872536f09d8c96e5734e2bcabfa384d7dc9b56ab

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

LOG: [clang] Modernize ModuleDeclSeq (NFC)

Identified with modernize-use-default-member-init.

Added: 


Modified: 
clang/include/clang/Lex/Preprocessor.h

Removed: 




diff  --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index a7ba486e0e50f..a34a451f4bad1 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -499,7 +499,7 @@ class Preprocessor {
 };
 
   public:
-ModuleDeclSeq() : State(NotAModuleDecl) {}
+ModuleDeclSeq() = default;
 
 void handleExport() {
   if (State == NotAModuleDecl)
@@ -586,7 +586,7 @@ class Preprocessor {
 }
 
   private:
-ModuleDeclState State;
+ModuleDeclState State = NotAModuleDecl;
 std::string Name;
   };
 



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


[clang] 564ddf9 - [clang] Modernize ReturnAdjustment and ThisAdjustment (NFC)

2023-04-16 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-04-16T14:48:16-07:00
New Revision: 564ddf986c97323bf35284cb2b404d21f42d563b

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

LOG: [clang] Modernize ReturnAdjustment and ThisAdjustment (NFC)

Identified with modernize-use-default-member-init.

Added: 


Modified: 
clang/include/clang/Basic/Thunk.h

Removed: 




diff  --git a/clang/include/clang/Basic/Thunk.h 
b/clang/include/clang/Basic/Thunk.h
index 91088be6ae73..0247e279408f 100644
--- a/clang/include/clang/Basic/Thunk.h
+++ b/clang/include/clang/Basic/Thunk.h
@@ -26,7 +26,7 @@ class CXXMethodDecl;
 struct ReturnAdjustment {
   /// The non-virtual adjustment from the derived object to its
   /// nearest virtual base.
-  int64_t NonVirtual;
+  int64_t NonVirtual = 0;
 
   /// Holds the ABI-specific information about the virtual return
   /// adjustment, if needed.
@@ -64,7 +64,7 @@ struct ReturnAdjustment {
 }
   } Virtual;
 
-  ReturnAdjustment() : NonVirtual(0) {}
+  ReturnAdjustment() = default;
 
   bool isEmpty() const { return !NonVirtual && Virtual.isEmpty(); }
 
@@ -91,7 +91,7 @@ struct ReturnAdjustment {
 struct ThisAdjustment {
   /// The non-virtual adjustment from the derived object to its
   /// nearest virtual base.
-  int64_t NonVirtual;
+  int64_t NonVirtual = 0;
 
   /// Holds the ABI-specific information about the virtual this
   /// adjustment, if needed.
@@ -131,7 +131,7 @@ struct ThisAdjustment {
 }
   } Virtual;
 
-  ThisAdjustment() : NonVirtual(0) {}
+  ThisAdjustment() = default;
 
   bool isEmpty() const { return !NonVirtual && Virtual.isEmpty(); }
 



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


[PATCH] D148462: [clang-tidy] Ignore declarations in bugprone-exception-escape

2023-04-16 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

@isuckatcs
No it were not fine, check function were executed, ExceptionAnalyzer created 
only to bail out due to nullptr getBody for functions with only declaration.
For functions with separate declaration and definition entire analysis is 
executed twice. simply because FunctionDecl::getBody jumps to function 
definition.
And this simply isn't needed, as we analyse definition anyway, so lets just 
emit warning for definition.
Now it forces developer to put NOLINT's into both .cpp and .hpp for same issue.

"The warning was emitted at every occurence of the function. It might be 
confusing if it's only emitted for the definition."
Why ? Issue is in definition, not declaration.

Example with indirectly_recursive & recursion_helper behave in same way, only 
difference is that warning is emitted only for definition.
"We know that indirectly_recursive(int n) throws when it shouldn't and that 
means recursion_helper(int n) will also throw when it shouldn't either."
Well no indirectly_recursive throws when it shouldn't but only because 
`thrower` throws, recursion_helper does not throw, it crashes. This is other 
bug that I'm fixing (not under this patch) related to properly handling 
noexcept keyword.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148462

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


[clang] 79e106f - [clang] Modernize OptRemark (NFC)

2023-04-16 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-04-16T14:24:22-07:00
New Revision: 79e106f6e7627aaf9bda62c05c3e7ac12cf11327

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

LOG: [clang] Modernize OptRemark (NFC)

Identified with modernize-use-default-member-init.

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.h

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 97853799807fc..e1817b990cdf9 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -332,12 +332,12 @@ class CodeGenOptions : public CodeGenOptionsBase {
 
   /// Optimization remark with an optional regular expression pattern.
   struct OptRemark {
-RemarkKind Kind;
+RemarkKind Kind = RK_Missing;
 std::string Pattern;
 std::shared_ptr Regex;
 
 /// By default, optimization remark is missing.
-OptRemark() : Kind(RK_Missing), Regex(nullptr) {}
+OptRemark() = default;
 
 /// Returns true iff the optimization remark holds a valid regular
 /// expression.



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


[PATCH] D148461: [clang-tidy] Support C++17/20 in bugprone-exception-escape

2023-04-16 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp:160-162
+// FIXME: Two function pointers can differ in 'noexcept', but they still
+// should be considered to be same, now this triggers false-positive 
because
+// Type* != Type*.

isuckatcs wrote:
> Are you sure `noexcept` is stored in the type? The test case you modified 
> `throw_noexcept_catch_regular()` tests this scenario and in that case the 
> types seem to be the same even though one of the is noexcept an the other is 
> not.
> 
> If the FIXME is valid the proper way would be to implement it in this patch.
Yes I'm sure.
C++11 - no warning
C++14 - no warning
C++17 - warning
Looks like since C++17 noexcept is part of type.
Initially I wanted only to enable tests under C++17/20.
That's why "FIXME". I will look into this.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp:414
   throw 
-} catch(int (*)()) {
+} catch(int (*)() noexcept) {
 }

isuckatcs wrote:
> The name of the function suggests that we throw a noexcept function pointer 
> and catch a non-noexcept one. Please don't change it.
Ack.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148461

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


[clang] 3993de1 - [clang] Modernize EvalStatus (NFC)

2023-04-16 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-04-16T14:02:34-07:00
New Revision: 3993de129182c3e98a3ab009ed99ad00bc8eff6e

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

LOG: [clang] Modernize EvalStatus (NFC)

Identified with modernize-use-default-member-init.

Added: 


Modified: 
clang/include/clang/AST/Expr.h

Removed: 




diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index e8f5b70f8f73..a9941d9e8af4 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -593,12 +593,12 @@ class Expr : public ValueStmt {
   struct EvalStatus {
 /// Whether the evaluated expression has side effects.
 /// For example, (f() && 0) can be folded, but it still has side effects.
-bool HasSideEffects;
+bool HasSideEffects = false;
 
 /// Whether the evaluation hit undefined behavior.
 /// For example, 1.0 / 0.0 can be folded to Inf, but has undefined 
behavior.
 /// Likewise, INT_MAX + 1 can be folded to INT_MIN, but has UB.
-bool HasUndefinedBehavior;
+bool HasUndefinedBehavior = false;
 
 /// Diag - If this is non-null, it will be filled in with a stack of notes
 /// indicating why evaluation failed (or why it failed to produce a 
constant
@@ -607,10 +607,9 @@ class Expr : public ValueStmt {
 /// foldable. If the expression is foldable, but not a constant expression,
 /// the notes will describes why it isn't a constant expression. If the
 /// expression *is* a constant expression, no notes will be produced.
-SmallVectorImpl *Diag;
+SmallVectorImpl *Diag = nullptr;
 
-EvalStatus()
-: HasSideEffects(false), HasUndefinedBehavior(false), Diag(nullptr) {}
+EvalStatus() = default;
 
 // hasSideEffects - Return true if the evaluated expression has
 // side effects.



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


[PATCH] D148481: [clang-repl] Enable debugging of JIT-ed code.

2023-04-16 Thread Lang Hames via Phabricator via cfe-commits
lhames accepted this revision.
lhames added a comment.
This revision is now accepted and ready to land.

Looks good to me!


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

https://reviews.llvm.org/D148481

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


[PATCH] D148481: [clang-repl] Enable debugging of JIT-ed code.

2023-04-16 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev created this revision.
v.g.vassilev added reviewers: lhames, sgraenitz, junaire.
Herald added a subscriber: pengfei.
Herald added a project: All.
v.g.vassilev requested review of this revision.

This change follows llvm/llvm-project@21b5ebd and makes use of the jitlink 
infrastructure. In order to use this feature inside lldb one needs to run the 
lldb command: settings set plugin.jit-loader.gdb.enable on

This works currently only on Darwin since jitlink is not a default ELF/x86-64 
backend yet.


https://reviews.llvm.org/D148481

Files:
  clang/lib/Interpreter/IncrementalExecutor.cpp


Index: clang/lib/Interpreter/IncrementalExecutor.cpp
===
--- clang/lib/Interpreter/IncrementalExecutor.cpp
+++ clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -21,11 +21,18 @@
 #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
 #include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
+#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
 #include "llvm/ExecutionEngine/SectionMemoryManager.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/TargetSelect.h"
 
+// Force linking some of the runtimes that helps attaching to a debugger.
+LLVM_ATTRIBUTE_USED void linkComponents() {
+  llvm::errs() << (void *)_orc_registerJITLoaderGDBWrapper
+   << (void *)_orc_registerJITLoaderGDBAllocAction;
+}
+
 namespace clang {
 
 IncrementalExecutor::IncrementalExecutor(llvm::orc::ThreadSafeContext ,
@@ -37,7 +44,12 @@
 
   auto JTMB = JITTargetMachineBuilder(TI.getTriple());
   JTMB.addFeatures(TI.getTargetOpts().Features);
-  if (auto JitOrErr = LLJITBuilder().setJITTargetMachineBuilder(JTMB).create())
+  LLJITBuilder Builder;
+  Builder.setJITTargetMachineBuilder(JTMB);
+  // Enable debugging of JIT'd code (only works on JITLink for ELF and MachO).
+  Builder.setEnableDebuggerSupport(true);
+
+  if (auto JitOrErr = Builder.create())
 Jit = std::move(*JitOrErr);
   else {
 Err = JitOrErr.takeError();


Index: clang/lib/Interpreter/IncrementalExecutor.cpp
===
--- clang/lib/Interpreter/IncrementalExecutor.cpp
+++ clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -21,11 +21,18 @@
 #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
 #include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
+#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h"
 #include "llvm/ExecutionEngine/SectionMemoryManager.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/TargetSelect.h"
 
+// Force linking some of the runtimes that helps attaching to a debugger.
+LLVM_ATTRIBUTE_USED void linkComponents() {
+  llvm::errs() << (void *)_orc_registerJITLoaderGDBWrapper
+   << (void *)_orc_registerJITLoaderGDBAllocAction;
+}
+
 namespace clang {
 
 IncrementalExecutor::IncrementalExecutor(llvm::orc::ThreadSafeContext ,
@@ -37,7 +44,12 @@
 
   auto JTMB = JITTargetMachineBuilder(TI.getTriple());
   JTMB.addFeatures(TI.getTargetOpts().Features);
-  if (auto JitOrErr = LLJITBuilder().setJITTargetMachineBuilder(JTMB).create())
+  LLJITBuilder Builder;
+  Builder.setJITTargetMachineBuilder(JTMB);
+  // Enable debugging of JIT'd code (only works on JITLink for ELF and MachO).
+  Builder.setEnableDebuggerSupport(true);
+
+  if (auto JitOrErr = Builder.create())
 Jit = std::move(*JitOrErr);
   else {
 Err = JitOrErr.takeError();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 25c55d2 - [clang] Modernize ASTConsumer (NFC)

2023-04-16 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-04-16T13:46:11-07:00
New Revision: 25c55d2c18b44e115069aba970ae684fbc2227f8

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

LOG: [clang] Modernize ASTConsumer (NFC)

Identified with modernize-use-default-member-init.

Added: 


Modified: 
clang/include/clang/AST/ASTConsumer.h

Removed: 




diff  --git a/clang/include/clang/AST/ASTConsumer.h 
b/clang/include/clang/AST/ASTConsumer.h
index 21850e832ff1..ebcd8059284d 100644
--- a/clang/include/clang/AST/ASTConsumer.h
+++ b/clang/include/clang/AST/ASTConsumer.h
@@ -33,12 +33,12 @@ namespace clang {
 class ASTConsumer {
   /// Whether this AST consumer also requires information about
   /// semantic analysis.
-  bool SemaConsumer;
+  bool SemaConsumer = false;
 
   friend class SemaConsumer;
 
 public:
-  ASTConsumer() : SemaConsumer(false) { }
+  ASTConsumer() = default;
 
   virtual ~ASTConsumer() {}
 



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


[clang] e0f5031 - [clang] Modernize Vec (NFC)

2023-04-16 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-04-16T13:46:09-07:00
New Revision: e0f5031caec31480208a694f26ac4d22243d41ab

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

LOG: [clang] Modernize Vec (NFC)

Identified with modernize-use-default-member-init.

Added: 


Modified: 
clang/include/clang/AST/APValue.h

Removed: 




diff  --git a/clang/include/clang/AST/APValue.h 
b/clang/include/clang/AST/APValue.h
index 4e22d6c8443c5..286c1a1b0941a 100644
--- a/clang/include/clang/AST/APValue.h
+++ b/clang/include/clang/AST/APValue.h
@@ -267,9 +267,9 @@ class APValue {
   };
   struct LV;
   struct Vec {
-APValue *Elts;
-unsigned NumElts;
-Vec() : Elts(nullptr), NumElts(0) {}
+APValue *Elts = nullptr;
+unsigned NumElts = 0;
+Vec() = default;
 ~Vec() { delete[] Elts; }
   };
   struct Arr {



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


[PATCH] D133289: [C2X] N3007 Type inference for object definitions

2023-04-16 Thread Guillot Tony via Phabricator via cfe-commits
to268 updated this revision to Diff 514051.
to268 added a comment.

I have improved some diagnostics and i am now testing `nullptr` with `auto`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133289

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/C/C2x/n3007.c
  clang/test/CodeGen/auto.c
  clang/test/Parser/c2x-auto.c
  clang/test/Sema/c2x-auto.c
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -1195,7 +1195,7 @@
 
   Type inference for object declarations
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3007.htm;>N3007
-  No
+  Clang 17
 
 
   constexpr for object definitions
Index: clang/test/Sema/c2x-auto.c
===
--- /dev/null
+++ clang/test/Sema/c2x-auto.c
@@ -0,0 +1,84 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c2x %s
+
+void test_basic_types(void) {
+  auto undefined; // expected-error {{declaration of variable 'undefined' with
+  // deduced type 'auto' requires an initializer}}
+  auto auto_int = 4;
+  auto auto_long = 4UL;
+}
+
+void test_sizeof_typeof(void) {
+  auto auto_size = sizeof(auto); // expected-error {{expected expression}}
+  typeof(auto) tpof = 4; // expected-error {{expected expression}}
+}
+
+void test_casts(void) {
+  auto int_cast = (int)(4 + 3);
+  auto double_cast = (double)(1 / 3);
+  auto long_cast = (long)(4UL + 3UL);
+  auto auto_cast = (auto)(4 + 3); // expected-error {{expected expression}}
+}
+
+void test_compound_literral(void) {
+  auto int_cl = (int){13};
+  auto double_cl = (double){2.5};
+  auto array[] = {
+  1, 2,
+  3}; // expected-error {{cannot use 'auto' with initializer list in C}}
+
+  // FIXME: This should be accepted per C2x 6.5.2.5p4
+  auto auto_cl = (auto){13}; // expected-error {{expected expression}}
+}
+
+void test_array_pointers(void) {
+  double array[3] = {0};
+  auto a = array;
+  auto b = 
+}
+
+void test_qualifiers(const int y) {
+  const auto a = 12;
+  auto b = y;
+  static auto c = 1UL;
+  int *pa =  // expected-warning {{initializing 'int *' with an expression of
+// type 'const int *' discards qualifiers}}
+  const int *pb = 
+  int *pc =  // expected-warning {{incompatible pointer types initializing
+// 'int *' with an expression of type 'unsigned long *'}}
+}
+
+void test_strings(void) {
+  auto str = "this is a string";
+  // FIXME: This should work for char*
+  auto str2[] =
+  "this is a string"; // expected-error {{variable 'str2' with type 'auto[]'
+  // has incompatible initializer of type 'char[17]'}}
+  auto(str3) = "this is a string";
+  auto(((str4))) = "this is a string";
+}
+
+void test_pointers(void) {
+  auto a = 12;
+  auto *ptr = 
+  auto *str = "this is a string";
+  const auto *str2 = "this is a string";
+  auto *b = 
+  *b =  // expected-error {{incompatible pointer to integer conversion
+   // assigning to 'int' from 'int *'; remove &}}
+  auto nptr = nullptr;
+}
+
+void test_scopes(void) {
+  double a = 7;
+  double b = 9;
+  {
+auto a =
+a *
+a; // expected-error {{variable 'a' declared with deduced type 'auto' cannot appear in its own initializer}} \
+   expected-error {{variable 'a' declared with deduced type 'auto' cannot appear in its own initializer}}
+  }
+  {
+auto b = a * a;
+auto a = b;
+  }
+}
Index: clang/test/Parser/c2x-auto.c
===
--- /dev/null
+++ clang/test/Parser/c2x-auto.c
@@ -0,0 +1,138 @@
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,c2x -std=c2x %s
+// RUN: %clang_cc1 -fsyntax-only -verify=expected,c17 -std=c17 %s
+
+#define AUTO_MACRO(_NAME, ARG, ARG2, ARG3) auto _NAME = ARG + (ARG2 / ARG3);
+
+struct S {
+  int a;
+  auto b; // c2x-error {{'auto' not allowed in struct member}} \
+   c17-error {{type name does not allow storage class to be specified}} \
+   c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
+  union {
+char c;
+auto smth; // c2x-error {{'auto' not allowed in union member}} \
+   c17-error {{type name does not allow storage class to be specified}} \
+   c17-error {{type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int}}
+  } u;
+};
+
+enum E : auto{ // c2x-error {{'auto' not allowed here}} \
+   c17-error {{expected a type}} \
+   c17-error {{type name does not allow storage class to be specified}}
+  One,
+  Two,
+  Tree,
+};
+

[PATCH] D148462: [clang-tidy] Ignore declarations in bugprone-exception-escape

2023-04-16 Thread Domján Dániel via Phabricator via cfe-commits
isuckatcs added a comment.

I think the original behaviour was fine. The warning was emitted at every 
occurence of the function. It might be confusing if it's only emitted for the 
definition.

Also what happens in the following scenario:

  int indirectly_recursive(int n) noexcept;
  
  int recursion_helper(int n) noexcept {
indirectly_recursive(n);
  }

We know that `indirectly_recursive(int n)` throws when it shouldn't and that 
means `recursion_helper(int n)` will also throw when it shouldn't either.

Is it reported properly with this change?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148462

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


[PATCH] D148461: [clang-tidy] Support C++17/20 in bugprone-exception-escape

2023-04-16 Thread Domján Dániel via Phabricator via cfe-commits
isuckatcs added inline comments.



Comment at: clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp:160-162
+// FIXME: Two function pointers can differ in 'noexcept', but they still
+// should be considered to be same, now this triggers false-positive 
because
+// Type* != Type*.

Are you sure `noexcept` is stored in the type? The test case you modified 
`throw_noexcept_catch_regular()` tests this scenario and in that case the types 
seem to be the same even though one of the is noexcept an the other is not.

If the FIXME is valid the proper way would be to implement it in this patch.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp:414
   throw 
-} catch(int (*)()) {
+} catch(int (*)() noexcept) {
 }

The name of the function suggests that we throw a noexcept function pointer and 
catch a non-noexcept one. Please don't change it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148461

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


[PATCH] D148473: [clang-format] C# short ternary operator misinterpreted as a CSharpNullable

2023-04-16 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Format/TokenAnnotator.cpp:1338-1342
+if (!Contexts.back().IsExpression && Line.MustBeDeclaration &&
+!(Tok->Next &&
+  Tok->Next->isOneOf(tok::identifier, tok::string_literal) &&
+  Tok->Next->Next &&
+  Tok->Next->Next->isOneOf(tok::colon, tok::question))) {

Even if there are more negations, I can read this better.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148473

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


[PATCH] D148474: [Clang] Fix ResolveConstructorOverload to not select a conversion function if we are going use copy elision

2023-04-16 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/Sema/SemaTemplateInstantiate.cpp:743
 << FD << Active->InstantiationRange;
+  } else if (ClassTemplateDecl *CTD = dyn_cast(D)) {
+Diags.Report(Active->PointOfInstantiation,

I added this fix because the `B3` test case I added below although was fixed by 
my patch it uncovered a new bug that resulted in the compiler locking up.

It looks like the malformed code results in a us seeing a `ClassTemplateDecl` 
where we would usually not expect it. If this handled better earlier let me 
know.




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

https://reviews.llvm.org/D148474

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


[PATCH] D148467: [clang-format] Add a new AfterCSharpProperty to BraceWrapping

2023-04-16 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

In D148467#4272173 , @MyDeveloperDay 
wrote:

> I'm not convinced `AfterCSharpProperty`  is a good name, open for suggestions

I've not enough domain knowledge to name it.




Comment at: clang/include/clang/Format/Format.h:1220
+/// \endcode
+bool AfterCSharpProperty;
   };

Please sort. :)



Comment at: clang/include/clang/Format/Format.h:4269
 
   bool operator==(const FormatStyle ) const {
 return AccessModifierOffset == R.AccessModifierOffset &&

It's missing in operator==. And I think we should add operator== to 
`BraceWrappingFlags` and use that here.



Comment at: clang/lib/Format/Format.cpp:184
 IO.mapOptional("AfterFunction", Wrapping.AfterFunction);
+IO.mapOptional("AfterCSharpProperty", Wrapping.AfterCSharpProperty);
 IO.mapOptional("AfterNamespace", Wrapping.AfterNamespace);

A bit up.



Comment at: clang/unittests/Format/FormatTestCSharp.cpp:1633
+   "{\n"
+   "string Foo { set; get }\n"
+   "}\n",

MyDeveloperDay wrote:
> Hmm.. maybe this should be 
> 
> ```
> string Foo 
> {
> set;get
> }
> ```
I'm no C# guy, but when we split the lines, I think get and set should be on 
it's own line.


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

https://reviews.llvm.org/D148467

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


[PATCH] D148474: [Clang] Fix ResolveConstructorOverload to not select a conversion function if we are going use copy elision

2023-04-16 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik created this revision.
shafik added reviewers: rsmith, aaron.ballman, erichkeane, dim.
Herald added a project: All.
shafik requested review of this revision.

`ResolveConstructorOverload` needs to check properly if we are going to use 
copy elision we can't use a conversion function.

This fixes:

https://github.com/llvm/llvm-project/issues/39319
https://github.com/llvm/llvm-project/issues/60182
https://github.com/llvm/llvm-project/issues/62157

  


https://reviews.llvm.org/D148474

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaCXX/cxx1z-copy-omission.cpp

Index: clang/test/SemaCXX/cxx1z-copy-omission.cpp
===
--- clang/test/SemaCXX/cxx1z-copy-omission.cpp
+++ clang/test/SemaCXX/cxx1z-copy-omission.cpp
@@ -171,3 +171,29 @@
   Foo f(Derived d) { return d; } // expected-error {{invokes a deleted function}}
   Foo g(Derived d) { return Foo(d); } // ok, calls constructor
 }
+
+// Make sure we don't consider conversion functions for guaranteed copy elision
+namespace GH39319 {
+struct A {
+  A();
+};
+struct B {
+  operator A();
+} C;
+A::A() : A(C) {}
+
+struct A2 {
+  struct B2 {
+operator A2();
+  };
+  A2() : A2(B2()) {}
+};
+
+template
+class B3 : A3 // expected-error {{expected '{' after base class list}}
+  template()> // expected-warning 2{{use of function template name with no prior declaration in function call with explicit}}
+  B3() // expected-error {{expected ';' at end of declaration list}}
+} B3(); // expected-error {{expected ';' after class}} \
+// expected-error {{deduction guide declaration without trailing return type}} \
+	// expected-note {{in instantiation of template class}}
+}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -740,6 +740,10 @@
 Diags.Report(Active->PointOfInstantiation,
  diag::note_template_nsdmi_here)
 << FD << Active->InstantiationRange;
+  } else if (ClassTemplateDecl *CTD = dyn_cast(D)) {
+Diags.Report(Active->PointOfInstantiation,
+ diag::note_template_class_instantiation_here)
+<< CTD << Active->InstantiationRange;
   } else {
 Diags.Report(Active->PointOfInstantiation,
  diag::note_template_type_alias_instantiation_here)
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -3981,16 +3981,13 @@
   return Ctx.hasSameUnqualifiedType(ParmT, ClassT);
 }
 
-static OverloadingResult
-ResolveConstructorOverload(Sema , SourceLocation DeclLoc,
-   MultiExprArg Args,
-   OverloadCandidateSet ,
-   QualType DestType,
-   DeclContext::lookup_result Ctors,
-   OverloadCandidateSet::iterator ,
-   bool CopyInitializing, bool AllowExplicit,
-   bool OnlyListConstructors, bool IsListInit,
-   bool SecondStepOfCopyInit = false) {
+static OverloadingResult ResolveConstructorOverload(
+Sema , SourceLocation DeclLoc, MultiExprArg Args,
+OverloadCandidateSet , QualType DestType,
+DeclContext::lookup_result Ctors, OverloadCandidateSet::iterator ,
+bool CopyInitializing, bool AllowExplicit, bool OnlyListConstructors,
+bool IsListInit, bool RequireActualConstructor,
+bool SecondStepOfCopyInit = false) {
   CandidateSet.clear(OverloadCandidateSet::CSK_InitByConstructor);
   CandidateSet.setDestAS(DestType.getQualifiers().getAddressSpace());
 
@@ -4053,7 +4050,7 @@
   // Note: SecondStepOfCopyInit is only ever true in this case when
   // evaluating whether to produce a C++98 compatibility warning.
   if (S.getLangOpts().CPlusPlus17 && Args.size() == 1 &&
-  !SecondStepOfCopyInit) {
+  !RequireActualConstructor && !SecondStepOfCopyInit) {
 Expr *Initializer = Args[0];
 auto *SourceRD = Initializer->getType()->getAsCXXRecordDecl();
 if (SourceRD && S.isCompleteType(DeclLoc, Initializer->getType())) {
@@ -4121,6 +4118,12 @@
 return;
   }
 
+  bool RequireActualConstructor =
+  !(Entity.getKind() != InitializedEntity::EK_Base &&
+Entity.getKind() != InitializedEntity::EK_Delegating &&
+Entity.getKind() !=
+InitializedEntity::EK_LambdaToBlockConversionBlockElement);
+
   // C++17 [dcl.init]p17:
   // - If the initializer expression is a prvalue and the cv-unqualified
   //   version of the source type is the same class as the class of the
@@ -4130,11 +4133,7 @@
   // class or delegating to another constructor from a mem-initializer.
   // ObjC++: Lambda captured by the block in the lambda 

[PATCH] D148266: [clang][driver] Linking to just-built libc++.dylib when bootstrapping libc++ with clang

2023-04-16 Thread Fahad Nayyar via Phabricator via cfe-commits
fahadnayyar updated this revision to Diff 514037.
fahadnayyar added a comment.
Herald added a subscriber: ormris.

Added test case. Now checking the existence of libc++ headers in the toolchain 
when including the libc++.dylib form toolchain and vice versa. Also checking 
the absence of -nostdinc, -nostdinc++ or -nostdlib 
arguments before linking with libc++.dylib from the toolchain.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148266

Files:
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/test/Driver/Inputs/basic_darwin_toolchain/usr/lib/libc++.dylib
  clang/test/Driver/darwin-header-search-libcxx.cpp
  clang/test/Driver/darwin-link-libcxx-from-toolchain.cpp

Index: clang/test/Driver/darwin-link-libcxx-from-toolchain.cpp
===
--- clang/test/Driver/darwin-link-libcxx-from-toolchain.cpp
+++ clang/test/Driver/darwin-link-libcxx-from-toolchain.cpp
@@ -1,63 +1,49 @@
 // UNSUPPORTED: system-windows
 
-// General tests that the header search paths for libc++ detected by the driver
-// and passed to CC1 are correct on Darwin platforms.
+// Tests to check that we pass -L /bin/../lib/libc++.dylib to link with the toolchain's libc++.dylib 
+// whenever we are including the toolchain's libc++ headers
 
 // Check without a sysroot and without headers alongside the installation
-// (no include path should be added, and no warning or error).
 //
-// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: %clang -### %s 2>&1 \
 // RUN: --target=x86_64-apple-darwin \
 // RUN: -stdlib=libc++ \
 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \
-// RUN:   | FileCheck --check-prefix=CHECK-LIBCXX-NONE %s
-// CHECK-LIBCXX-NONE: "-cc1"
+// RUN:   | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain_no_libcxx --check-prefix=CHECK-TOOLCHAIN-LIBCXX-LINKING-2 %s
 
 // Check with only headers alongside the installation (those should be used).
 //
-// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: %clang -### %s 2>&1 \
 // RUN: --target=x86_64-apple-darwin \
 // RUN: -stdlib=libc++ \
 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \
 // RUN: --sysroot="" \
 // RUN:   | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \
-// RUN:   --check-prefix=CHECK-LIBCXX-TOOLCHAIN-1 %s
-// CHECK-LIBCXX-TOOLCHAIN-1: "-cc1"
-// CHECK-LIBCXX-TOOLCHAIN-1: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
-// CHECK-LIBCXX-TOOLCHAIN-1-NOT: "-internal-isystem" "/usr/include/c++/v1"
+// RUN:   --check-prefix=CHECK-TOOLCHAIN-LIBCXX-LINKING-1 %s
 //
-// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: %clang -### %s 2>&1 \
 // RUN: --target=x86_64-apple-darwin \
 // RUN: -stdlib=libc++ \
 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \
 // RUN: -isysroot %S/Inputs/basic_darwin_sdk_no_libcxx \
 // RUN:   | FileCheck -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain \
 // RUN:   -DSYSROOT=%S/Inputs/basic_darwin_sdk_no_libcxx \
-// RUN:   --check-prefix=CHECK-LIBCXX-TOOLCHAIN-2 %s
-// CHECK-LIBCXX-TOOLCHAIN-2: "-cc1"
-// CHECK-LIBCXX-TOOLCHAIN-2: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
-// CHECK-LIBCXX-TOOLCHAIN-2-NOT: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1"
+// RUN:   --check-prefix=CHECK-TOOLCHAIN-LIBCXX-LINKING-1 %s
 
 // Check with only headers in the sysroot (those should be used).
 //
-// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: %clang -### %s 2>&1 \
 // RUN: --target=x86_64-apple-darwin \
 // RUN: -stdlib=libc++ \
 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain_no_libcxx/usr/bin \
 // RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_cxx_v1 \
 // RUN:   | FileCheck -DSYSROOT=%S/Inputs/basic_darwin_sdk_usr_cxx_v1 \
 // RUN:   -DTOOLCHAIN=%S/Inputs/basic_darwin_toolchain_no_libcxx \
-// RUN:   --check-prefix=CHECK-LIBCXX-SYSROOT-1 %s
-// CHECK-LIBCXX-SYSROOT-1: "-cc1"
-// CHECK-LIBCXX-SYSROOT-1: "-internal-isystem" "[[SYSROOT]]/usr/include/c++/v1"
-// CHECK-LIBCXX-SYSROOT-1-NOT: "-internal-isystem" "[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
+// RUN:   --check-prefix=CHECK-TOOLCHAIN-LIBCXX-LINKING-2 %s
 
 // Check with both headers in the sysroot and headers alongside the installation
-// (the headers in the toolchain should be preferred over the  headers).
-// Ensure that both -isysroot and --sysroot work, and that isysroot has precedence
-// over --sysroot.
 //
-// RUN: %clang -### %s -fsyntax-only 2>&1 \
+// RUN: %clang -### %s 2>&1 \
 // RUN: --target=x86_64-apple-darwin \
 // RUN: -stdlib=libc++ \
 // RUN: -ccc-install-dir %S/Inputs/basic_darwin_toolchain/usr/bin \
@@ -65,9 +51,9 @@
 // RUN: -isysroot %S/Inputs/basic_darwin_sdk_usr_cxx_v1 \
 // RUN:   | FileCheck 

[PATCH] D148439: [clang-rename] Exit gracefully when no input provided

2023-04-16 Thread Miklos Vajna via Phabricator via cfe-commits
vmiklos added subscribers: arphaman, klimek.
vmiklos added a comment.

Looks good to me, but probably you want an approval from @arphaman, @klimek or 
@kbobyrev before committing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148439

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


[PATCH] D148473: [clang-format] C# short ternary operator misinterpreted as a CSharpNullable

2023-04-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

@exv any thoughts on this one?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148473

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


[PATCH] D148473: [clang-format] C# short ternary operator misinterpreted as a CSharpNullable

2023-04-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

The exclusions are not complete for example `cond? foo() : "B";` would still 
fail. but this moves us a little closer


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148473

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


[PATCH] D148473: [clang-format] C# short ternary operator misinterpreted as a CSharpNullable

2023-04-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay created this revision.
MyDeveloperDay added a reviewer: owenpan.
MyDeveloperDay added a project: clang-format.
Herald added projects: All, clang.
Herald added reviewers: rymiel, HazardyKnusperkeks.
MyDeveloperDay requested review of this revision.

Refactor the CSharpNullable assignment code to be a little easier to read 
(Honestly I don't like it when an if expression get really long and 
complicated).
Handle the case where '?' is actually a ternary operator.

Fixes: #58067
https://github.com/llvm/llvm-project/issues/58067


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148473

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1688,6 +1688,34 @@
   EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace);
 }
 
+TEST_F(TokenAnnotatorTest, CSharpNullableTypes) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+
+  auto Tokens = annotate("int? a;\n", Style);
+  EXPECT_EQ(Tokens.size(), 5u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::question, TT_CSharpNullable);
+
+  Tokens = annotate("int? a = 1;\n", Style);
+  EXPECT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::question, TT_CSharpNullable);
+
+  Tokens = annotate("int?)\n", Style);
+  EXPECT_EQ(Tokens.size(), 4u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::question, TT_CSharpNullable);
+
+  Tokens = annotate("int?>\n", Style);
+  EXPECT_EQ(Tokens.size(), 4u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::question, TT_CSharpNullable);
+
+  Tokens = annotate("cond? id : id2\n", Style);
+  EXPECT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::question, TT_ConditionalExpr);
+
+  Tokens = annotate("cond ? cond2 ? : id1 : id2\n", Style);
+  EXPECT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::question, TT_ConditionalExpr);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1312,11 +1312,34 @@
   if (Style.isCSharp()) {
 // `Type?)`, `Type?>`, `Type? name;` and `Type? name =` can only be
 // nullable types.
+
+// `Type?)`, `Type?>`, `Type? name;`
+if (Tok->Next &&
+(Tok->Next->startsSequence(tok::question, tok::r_paren) ||
+ Tok->Next->startsSequence(tok::question, tok::greater) ||
+ Tok->Next->startsSequence(tok::question, tok::identifier,
+   tok::semi))) {
+  Tok->setType(TT_CSharpNullable);
+  break;
+}
+
+// `Type? name =`
+if (Tok->Next && Tok->Next->is(tok::identifier) && Tok->Next->Next &&
+Tok->Next->Next->is(tok::equal)) {
+  Tok->setType(TT_CSharpNullable);
+  break;
+}
+
 // Line.MustBeDeclaration will be true for `Type? name;`.
-if ((!Contexts.back().IsExpression && Line.MustBeDeclaration) ||
-(Tok->Next && Tok->Next->isOneOf(tok::r_paren, tok::greater)) ||
-(Tok->Next && Tok->Next->is(tok::identifier) && Tok->Next->Next &&
- Tok->Next->Next->is(tok::equal))) {
+// But not
+// cond ? "A" : "B";
+// cond ? id : "B";
+// cond ? cond2 ? "A" : "B" : "C";
+if (!Contexts.back().IsExpression && Line.MustBeDeclaration &&
+!(Tok->Next &&
+  Tok->Next->isOneOf(tok::identifier, tok::string_literal) &&
+  Tok->Next->Next &&
+  Tok->Next->Next->isOneOf(tok::colon, tok::question))) {
   Tok->setType(TT_CSharpNullable);
   break;
 }


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1688,6 +1688,34 @@
   EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace);
 }
 
+TEST_F(TokenAnnotatorTest, CSharpNullableTypes) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
+
+  auto Tokens = annotate("int? a;\n", Style);
+  EXPECT_EQ(Tokens.size(), 5u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::question, TT_CSharpNullable);
+
+  Tokens = annotate("int? a = 1;\n", Style);
+  EXPECT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::question, TT_CSharpNullable);
+
+  Tokens = annotate("int?)\n", Style);
+  EXPECT_EQ(Tokens.size(), 4u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::question, TT_CSharpNullable);
+
+  Tokens = annotate("int?>\n", Style);
+  EXPECT_EQ(Tokens.size(), 4u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::question, TT_CSharpNullable);
+
+  Tokens 

[PATCH] D148472: [clang-format] CSharp don't allow there not to be a space between `is` and `[`

2023-04-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay created this revision.
MyDeveloperDay added a reviewer: owenpan.
MyDeveloperDay added a project: clang-format.
Herald added projects: All, clang.
Herald added reviewers: rymiel, HazardyKnusperkeks.
MyDeveloperDay requested review of this revision.

as `is` is a keyword in C# ensure there is always a space before the `[` 
regardless of `SpaceBeforeSquareBrackets` setting

Fixes: #61965

https://github.com/llvm/llvm-project/issues/61965


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148472

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestCSharp.cpp


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -1176,6 +1176,14 @@
   verifyFormat(R"(override (string name, int age) methodTuple() {})", Style);
   verifyFormat(R"(async (string name, int age) methodTuple() {})", Style);
   verifyFormat(R"(unsafe (string name, int age) methodTuple() {})", Style);
+
+  Style.SpacesInSquareBrackets = false;
+  Style.SpaceBeforeSquareBrackets = true;
+  verifyFormat("return a is [1, 2, 3]", Style);
+  verifyFormat("return a is [..]", Style);
+  Style.SpaceBeforeSquareBrackets = false;
+  verifyFormat("return a is [1, 2, 3]", Style);
+  verifyFormat("return a is [..]", Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpNullableTypes) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3915,6 +3915,8 @@
   }
 }
   }
+  if (Style.isCSharp() && Left.is(Keywords.kw_is) && Right.is(tok::l_square))
+return true;
   const auto SpaceRequiredForArrayInitializerLSquare =
   [](const FormatToken , const FormatStyle ) {
 return Style.SpacesInContainerLiterals ||


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -1176,6 +1176,14 @@
   verifyFormat(R"(override (string name, int age) methodTuple() {})", Style);
   verifyFormat(R"(async (string name, int age) methodTuple() {})", Style);
   verifyFormat(R"(unsafe (string name, int age) methodTuple() {})", Style);
+
+  Style.SpacesInSquareBrackets = false;
+  Style.SpaceBeforeSquareBrackets = true;
+  verifyFormat("return a is [1, 2, 3]", Style);
+  verifyFormat("return a is [..]", Style);
+  Style.SpaceBeforeSquareBrackets = false;
+  verifyFormat("return a is [1, 2, 3]", Style);
+  verifyFormat("return a is [..]", Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpNullableTypes) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3915,6 +3915,8 @@
   }
 }
   }
+  if (Style.isCSharp() && Left.is(Keywords.kw_is) && Right.is(tok::l_square))
+return true;
   const auto SpaceRequiredForArrayInitializerLSquare =
   [](const FormatToken , const FormatStyle ) {
 return Style.SpacesInContainerLiterals ||
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148467: [clang-format] Add a new AfterCSharpProperty to BraceWrapping

2023-04-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 514030.
MyDeveloperDay added a comment.

re clang-format


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

https://reviews.llvm.org/D148467

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestCSharp.cpp

Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -1604,5 +1604,81 @@
   EXPECT_NE("", format("int where b <")); // reduced from crasher
 }
 
+TEST_F(FormatTestCSharp, PropertyWrapping) {
+  FormatStyle Style = getMicrosoftStyle(FormatStyle::LK_CSharp);
+
+  Style.BraceWrapping.AfterCSharpProperty = false;
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo { set; get; }\n"
+   "}\n",
+   Style);
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo { get; set; }\n"
+   "}\n",
+   Style);
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo\n"
+   "{\n"
+   "set {\n"
+   "val = value;\n"
+   "}\n"
+   "get {\n"
+   "return value;\n"
+   "}\n"
+   "}\n"
+   "}\n",
+   Style);
+
+  Style.BraceWrapping.AfterCSharpProperty = true;
+
+  verifyFormat("class A\n"
+   "{\n"
+   "string Bar {\n"
+   "set;\n"
+   "get;\n"
+   "}\n"
+   "}\n",
+   Style);
+  verifyFormat("class A\n"
+   "{\n"
+   "string Bar {\n"
+   "get;\n"
+   "set;\n"
+   "}\n"
+   "}\n",
+   Style);
+  verifyFormat("class A\n"
+   "{\n"
+   "string Bar\n"
+   "{\n"
+   "set\n"
+   "{\n"
+   "val = value;\n"
+   "}\n"
+   "get\n"
+   "{\n"
+   "return value;\n"
+   "}\n"
+   "}\n"
+   "}\n",
+   Style);
+  /* TODO fix the indentation of get;
+  verifyFormat("class A\n"
+ "{\n"
+ "string Bar {\n"
+ "get;\n"
+ "set\n"
+ "{\n"
+ "val = value;\n"
+ "}\n"
+ "}\n"
+ "}\n",
+ Style);
+  */
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -4984,6 +4984,13 @@
   return true;
 }
 
+// Handle `string Foo {{set {} get {}}`.
+if (Style.isCSharp() && Style.BraceWrapping.AfterCSharpProperty &&
+(Line.startsWith(Keywords.kw_get) ||
+ Line.startsWith(Keywords.kw_set))) {
+  return true;
+}
+
 // Don't attempt to interpret struct return types as structs.
 if (Right.isNot(TT_FunctionLBrace)) {
   return (Line.startsWith(tok::kw_class) &&
@@ -4993,6 +5000,17 @@
 }
   }
 
+  // Handle default `string Foo {set;get }`.
+  if (Style.isCSharp() && Style.BraceWrapping.AfterCSharpProperty &&
+  ((Left.isOneOf(tok::l_brace, tok::semi) &&
+Right.isOneOf(Keywords.kw_set, Keywords.kw_get)) ||
+   (Left.is(tok::semi) && Left.Previous &&
+Left.Previous->is(Keywords.kw_get) && Right.is(tok::r_brace)) ||
+   (Left.is(tok::semi) && Left.Previous &&
+Left.Previous->is(Keywords.kw_set) && Right.is(tok::r_brace {
+return true;
+  }
+
   if (Left.is(TT_ObjCBlockLBrace) &&
   Style.AllowShortBlocksOnASingleLine == FormatStyle::SBS_Never) {
 return true;
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -181,6 +181,7 @@
 IO.mapOptional("AfterEnum", Wrapping.AfterEnum);
 IO.mapOptional("AfterExternBlock", Wrapping.AfterExternBlock);
 IO.mapOptional("AfterFunction", Wrapping.AfterFunction);
+IO.mapOptional("AfterCSharpProperty", Wrapping.AfterCSharpProperty);
 IO.mapOptional("AfterNamespace", Wrapping.AfterNamespace);
 IO.mapOptional("AfterObjCDeclaration", Wrapping.AfterObjCDeclaration);
 IO.mapOptional("AfterStruct", Wrapping.AfterStruct);
@@ -1188,7 +1189,8 @@
 

[PATCH] D148467: [clang-format] Add a new AfterCSharpProperty to BraceWrapping

2023-04-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 514029.
MyDeveloperDay added a comment.

for default `set;get` or `get;set` for when `AfterCSharpProperty` is true,

  public Foo {
  set;
  get;
  }


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

https://reviews.llvm.org/D148467

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestCSharp.cpp

Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -1604,5 +1604,81 @@
   EXPECT_NE("", format("int where b <")); // reduced from crasher
 }
 
+TEST_F(FormatTestCSharp, PropertyWrapping) {
+  FormatStyle Style = getMicrosoftStyle(FormatStyle::LK_CSharp);
+
+  Style.BraceWrapping.AfterCSharpProperty = false;
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo { set; get; }\n"
+   "}\n",
+   Style);
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo { get; set; }\n"
+   "}\n",
+   Style);
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo\n"
+   "{\n"
+   "set {\n"
+   "val = value;\n"
+   "}\n"
+   "get {\n"
+   "return value;\n"
+   "}\n"
+   "}\n"
+   "}\n",
+   Style);
+
+  Style.BraceWrapping.AfterCSharpProperty = true;
+
+  verifyFormat("class A\n"
+   "{\n"
+   "string Bar {\n"
+   "set;\n"
+   "get;\n"
+   "}\n"
+   "}\n",
+   Style);
+  verifyFormat("class A\n"
+   "{\n"
+   "string Bar {\n"
+   "get;\n"
+   "set;\n"
+   "}\n"
+   "}\n",
+   Style);
+  verifyFormat("class A\n"
+   "{\n"
+   "string Bar\n"
+   "{\n"
+   "set\n"
+   "{\n"
+   "val = value;\n"
+   "}\n"
+   "get\n"
+   "{\n"
+   "return value;\n"
+   "}\n"
+   "}\n"
+   "}\n",
+   Style);
+  /* TODO fix the indentation of get;
+  verifyFormat("class A\n"
+ "{\n"
+ "string Bar {\n"
+ "get;\n"
+ "set\n"
+ "{\n"
+ "val = value;\n"
+ "}\n"
+ "}\n"
+ "}\n",
+ Style);
+  */
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -4984,6 +4984,13 @@
   return true;
 }
 
+// Handle `string Foo {{set {} get {}}`.
+if (Style.isCSharp() && Style.BraceWrapping.AfterCSharpProperty &&
+(Line.startsWith(Keywords.kw_get) ||
+ Line.startsWith(Keywords.kw_set))) {
+  return true;
+}
+
 // Don't attempt to interpret struct return types as structs.
 if (Right.isNot(TT_FunctionLBrace)) {
   return (Line.startsWith(tok::kw_class) &&
@@ -4993,16 +5000,28 @@
 }
   }
 
-  if (Left.is(TT_ObjCBlockLBrace) &&
-  Style.AllowShortBlocksOnASingleLine == FormatStyle::SBS_Never) {
+  // Handle `string Foo {set;get }`.
+  if (Style.isCSharp() && Style.BraceWrapping.AfterCSharpProperty &&
+  (( Left.isOneOf(tok::l_brace,tok::semi) &&
+Right.isOneOf(Keywords.kw_set,Keywords.kw_get)) ||
+   (Left.is(tok::semi) && Left.Previous &&
+Left.Previous->is(Keywords.kw_get) && Right.is(tok::r_brace)) ||
+   (Left.is(tok::semi) && Left.Previous &&
+Left.Previous->is(Keywords.kw_set) && Right.is(tok::r_brace))
+  )) {
 return true;
   }
 
-  // Ensure wrapping after __attribute__((XX)) and @interface etc.
-  if (Left.is(TT_AttributeParen) && Right.is(TT_ObjCDecl))
+if (Left.is(TT_ObjCBlockLBrace) &&
+Style.AllowShortBlocksOnASingleLine == FormatStyle::SBS_Never) {
 return true;
+}
 
-  if (Left.is(TT_LambdaLBrace)) {
+// Ensure wrapping after __attribute__((XX)) and @interface etc.
+if (Left.is(TT_AttributeParen) && Right.is(TT_ObjCDecl))
+  return true;
+
+if (Left.is(TT_LambdaLBrace)) {
 if (IsFunctionArgument(Left) &&
 Style.AllowShortLambdasOnASingleLine == FormatStyle::SLS_Inline) {
   return false;
@@ -5014,54 +5033,54 @@
 

[PATCH] D148444: [clang-tidy] Prevent `llvmlibc-inline-function-decl` triggering on lambdas

2023-04-16 Thread Joseph Huber via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1663016b41d7: [clang-tidy] Prevent 
`llvmlibc-inline-function-decl` triggering on lambdas (authored by jhuber6).

Changed prior to commit:
  https://reviews.llvm.org/D148444?vs=514001=514026#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148444

Files:
  clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
===
--- clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
@@ -60,6 +60,14 @@
   }
 };
 
+LIBC_INLINE void lambda() {
+// CHECK-MESSAGES-NOT: :[[@LINE+4]]:3: warning: '__invoke' must be tagged with 
the LIBC_INLINE macro; the macro should be placed at the beginning of the 
declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+3]]:3: warning: 'operator void (*)()' must be 
tagged with the LIBC_INLINE macro; the macro should be placed at the beginning 
of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+2]]:3: warning: '~(lambda at [[FILENAME:.+]])' 
must be tagged with the LIBC_INLINE macro; the macro should be placed at the 
beginning of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+1]]:6: warning: 'operator()' must be tagged 
with the LIBC_INLINE macro; the macro should be placed at the beginning of the 
declaration [llvmlibc-inline-function-decl]
+  [](){};
+}
+
 } // namespace __llvm_libc
 
 #endif // 
LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_LLVMLIBC_INLINEFUNCTIONDECL_H
Index: clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
===
--- clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
+++ clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
@@ -39,6 +39,12 @@
 HeaderFileExtensions))
 return;
 
+  // Ignore lambda functions as they are internal and implicit.
+  if (const auto *MethodDecl = dyn_cast(FuncDecl)) {
+if (MethodDecl->getParent()->isLambda())
+  return;
+  }
+
   // Check if decl starts with LIBC_INLINE
   auto Loc = FullSourceLoc(Result.SourceManager->getFileLoc(SrcBegin),
*Result.SourceManager);


Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
===
--- clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
@@ -60,6 +60,14 @@
   }
 };
 
+LIBC_INLINE void lambda() {
+// CHECK-MESSAGES-NOT: :[[@LINE+4]]:3: warning: '__invoke' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+3]]:3: warning: 'operator void (*)()' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+2]]:3: warning: '~(lambda at [[FILENAME:.+]])' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+1]]:6: warning: 'operator()' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+  [](){};
+}
+
 } // namespace __llvm_libc
 
 #endif // LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_LLVMLIBC_INLINEFUNCTIONDECL_H
Index: clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
===
--- clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
+++ clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
@@ -39,6 +39,12 @@
 HeaderFileExtensions))
 return;
 
+  // Ignore lambda functions as they are internal and implicit.
+  if (const auto *MethodDecl = dyn_cast(FuncDecl)) {
+if (MethodDecl->getParent()->isLambda())
+  return;
+  }
+
   // Check if decl starts with LIBC_INLINE
   auto Loc = FullSourceLoc(Result.SourceManager->getFileLoc(SrcBegin),
*Result.SourceManager);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 1663016 - [clang-tidy] Prevent `llvmlibc-inline-function-decl` triggering on lambdas

2023-04-16 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2023-04-16T10:58:44-05:00
New Revision: 1663016b41d71a60f3d268607c6fbf16fcf85172

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

LOG: [clang-tidy] Prevent `llvmlibc-inline-function-decl` triggering on lambdas

The `llvmlibc-inline-function-decl` check is intended to be used to
allow declarations in the `libc` project's header to be changed per-TU.
However, it is impossible to place this macro in front of a lambda so
this is not helpful. Additionally, lambdas are always going to have
internal linkage so they will not differ accross TUs.

Fixes https://github.com/llvm/llvm-project/issues/62147

Reviewed By: lntue, PiotrZSL

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp 
b/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
index 803e32da5279..fa643a138792 100644
--- a/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
@@ -39,6 +39,12 @@ void InlineFunctionDeclCheck::check(const 
MatchFinder::MatchResult ) {
 HeaderFileExtensions))
 return;
 
+  // Ignore lambda functions as they are internal and implicit.
+  if (const auto *MethodDecl = dyn_cast(FuncDecl)) {
+if (MethodDecl->getParent()->isLambda())
+  return;
+  }
+
   // Check if decl starts with LIBC_INLINE
   auto Loc = FullSourceLoc(Result.SourceManager->getFileLoc(SrcBegin),
*Result.SourceManager);

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp 
b/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
index b59c2d20be05..24d0441742a7 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
@@ -60,6 +60,14 @@ class  MyClass {
   }
 };
 
+LIBC_INLINE void lambda() {
+// CHECK-MESSAGES-NOT: :[[@LINE+4]]:3: warning: '__invoke' must be tagged with 
the LIBC_INLINE macro; the macro should be placed at the beginning of the 
declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+3]]:3: warning: 'operator void (*)()' must be 
tagged with the LIBC_INLINE macro; the macro should be placed at the beginning 
of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+2]]:3: warning: '~(lambda at [[FILENAME:.+]])' 
must be tagged with the LIBC_INLINE macro; the macro should be placed at the 
beginning of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+1]]:6: warning: 'operator()' must be tagged 
with the LIBC_INLINE macro; the macro should be placed at the beginning of the 
declaration [llvmlibc-inline-function-decl]
+  [](){};
+}
+
 } // namespace __llvm_libc
 
 #endif // 
LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_LLVMLIBC_INLINEFUNCTIONDECL_H



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


[clang] 077a2a4 - [CMake] Cleanup deps

2023-04-16 Thread NAKAMURA Takumi via cfe-commits

Author: NAKAMURA Takumi
Date: 2023-04-17T00:38:49+09:00
New Revision: 077a2a4bcddf62fd002f80f150ef0e5c785ba89b

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

LOG: [CMake] Cleanup deps

Added: 


Modified: 
clang/lib/Index/CMakeLists.txt
clang/lib/Interpreter/CMakeLists.txt
clang/lib/Tooling/DependencyScanning/CMakeLists.txt
clang/lib/Tooling/Inclusions/CMakeLists.txt
clang/tools/clang-repl/CMakeLists.txt
clang/tools/clang-scan-deps/CMakeLists.txt
clang/unittests/Basic/CMakeLists.txt
llvm/lib/CodeGen/AsmPrinter/CMakeLists.txt
llvm/lib/DWP/CMakeLists.txt
llvm/lib/FuzzMutate/CMakeLists.txt
llvm/tools/dsymutil/CMakeLists.txt
llvm/tools/llc/CMakeLists.txt
llvm/tools/llvm-debuginfo-analyzer/CMakeLists.txt
llvm/tools/llvm-dwarfutil/CMakeLists.txt
llvm/tools/llvm-gsymutil/CMakeLists.txt
llvm/tools/llvm-ifs/CMakeLists.txt
llvm/tools/llvm-modextract/CMakeLists.txt
llvm/tools/llvm-objdump/CMakeLists.txt
llvm/tools/llvm-opt-fuzzer/CMakeLists.txt
llvm/tools/llvm-opt-report/CMakeLists.txt
llvm/tools/llvm-profdata/CMakeLists.txt
llvm/tools/llvm-readobj/CMakeLists.txt
llvm/tools/llvm-remark-size-diff/CMakeLists.txt
llvm/tools/llvm-remarkutil/CMakeLists.txt
llvm/tools/llvm-symbolizer/CMakeLists.txt
llvm/tools/llvm-xray/CMakeLists.txt
llvm/tools/sancov/CMakeLists.txt
llvm/unittests/tools/llvm-mca/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Index/CMakeLists.txt b/clang/lib/Index/CMakeLists.txt
index 68c689b01969e..e6c1721d8c026 100644
--- a/clang/lib/Index/CMakeLists.txt
+++ b/clang/lib/Index/CMakeLists.txt
@@ -23,7 +23,6 @@ add_clang_library(clangIndex
   clangFormat
   clangFrontend
   clangLex
-  clangRewrite
   clangSerialization
   clangToolingCore
 

diff  --git a/clang/lib/Interpreter/CMakeLists.txt 
b/clang/lib/Interpreter/CMakeLists.txt
index 4702c6a7e8221..c9236248dccb2 100644
--- a/clang/lib/Interpreter/CMakeLists.txt
+++ b/clang/lib/Interpreter/CMakeLists.txt
@@ -23,7 +23,6 @@ add_clang_library(clangInterpreter
   clangBasic
   clangCodeGen
   clangDriver
-  clangEdit
   clangFrontend
   clangFrontendTool
   clangLex

diff  --git a/clang/lib/Tooling/DependencyScanning/CMakeLists.txt 
b/clang/lib/Tooling/DependencyScanning/CMakeLists.txt
index ac93f757dc314..a8ff0a2813bcc 100644
--- a/clang/lib/Tooling/DependencyScanning/CMakeLists.txt
+++ b/clang/lib/Tooling/DependencyScanning/CMakeLists.txt
@@ -22,7 +22,6 @@ add_clang_library(clangDependencyScanning
   clangCodeGen
   clangDriver
   clangFrontend
-  clangFrontendTool
   clangLex
   clangParse
   clangSerialization

diff  --git a/clang/lib/Tooling/Inclusions/CMakeLists.txt 
b/clang/lib/Tooling/Inclusions/CMakeLists.txt
index 78b25f4a34862..f9c2e6397ae72 100644
--- a/clang/lib/Tooling/Inclusions/CMakeLists.txt
+++ b/clang/lib/Tooling/Inclusions/CMakeLists.txt
@@ -8,7 +8,6 @@ add_clang_library(clangToolingInclusions
   LINK_LIBS
   clangBasic
   clangLex
-  clangRewrite
   clangToolingCore
   )
 

diff  --git a/clang/tools/clang-repl/CMakeLists.txt 
b/clang/tools/clang-repl/CMakeLists.txt
index b51a18c10cdca..2ea0122a7b795 100644
--- a/clang/tools/clang-repl/CMakeLists.txt
+++ b/clang/tools/clang-repl/CMakeLists.txt
@@ -15,7 +15,6 @@ clang_target_link_libraries(clang-repl PRIVATE
   clangBasic
   clangFrontend
   clangInterpreter
-  clangTooling
   )
 
 # Support plugins.

diff  --git a/clang/tools/clang-scan-deps/CMakeLists.txt 
b/clang/tools/clang-scan-deps/CMakeLists.txt
index c68a98f8449e5..7ffc3f9027829 100644
--- a/clang/tools/clang-scan-deps/CMakeLists.txt
+++ b/clang/tools/clang-scan-deps/CMakeLists.txt
@@ -19,11 +19,9 @@ add_clang_tool(clang-scan-deps
 set(CLANG_SCAN_DEPS_LIB_DEPS
   clangAST
   clangBasic
-  clangCodeGen
   clangDependencyScanning
   clangDriver
   clangFrontend
-  clangFrontendTool
   clangLex
   clangParse
   clangSerialization

diff  --git a/clang/unittests/Basic/CMakeLists.txt 
b/clang/unittests/Basic/CMakeLists.txt
index 6c00f63332af4..3844ba49add8d 100644
--- a/clang/unittests/Basic/CMakeLists.txt
+++ b/clang/unittests/Basic/CMakeLists.txt
@@ -16,7 +16,6 @@ add_clang_unittest(BasicTests
 
 clang_target_link_libraries(BasicTests
   PRIVATE
-  clangAST
   clangBasic
   clangLex
   )

diff  --git a/llvm/lib/CodeGen/AsmPrinter/CMakeLists.txt 
b/llvm/lib/CodeGen/AsmPrinter/CMakeLists.txt
index 410e120d0e1bd..4e0b7a919445b 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CMakeLists.txt
+++ b/llvm/lib/CodeGen/AsmPrinter/CMakeLists.txt
@@ -37,7 +37,6 @@ add_llvm_component_library(LLVMAsmPrinter
   Core
   DebugInfoCodeView
   DebugInfoDWARF
-  DebugInfoMSF
   MC
   MCParser
   Remarks

diff  --git a/llvm/lib/DWP/CMakeLists.txt b/llvm/lib/DWP/CMakeLists.txt
index 228c0f20989c5..777de1978dae3 100644

[clang] 7d5d987 - [CMake] Reorder and reformat deps

2023-04-16 Thread NAKAMURA Takumi via cfe-commits

Author: NAKAMURA Takumi
Date: 2023-04-17T00:32:16+09:00
New Revision: 7d5d987e93bb4650d1dade41f0d5c5025ccb5b5c

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

LOG: [CMake] Reorder and reformat deps

Added: 


Modified: 
clang-tools-extra/clang-tidy/CMakeLists.txt
clang/lib/CodeGen/CMakeLists.txt
clang/lib/Interpreter/CMakeLists.txt
clang/lib/Tooling/DependencyScanning/CMakeLists.txt
clang/tools/clang-scan-deps/CMakeLists.txt
clang/unittests/Analysis/CMakeLists.txt
clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
clang/unittests/DirectoryWatcher/CMakeLists.txt
clang/unittests/Introspection/CMakeLists.txt
clang/unittests/Sema/CMakeLists.txt
llvm/lib/DWARFLinker/CMakeLists.txt
llvm/lib/DWARFLinkerParallel/CMakeLists.txt
llvm/lib/DWP/CMakeLists.txt
llvm/lib/LTO/CMakeLists.txt
llvm/lib/Target/AArch64/CMakeLists.txt
llvm/lib/Target/AArch64/MCTargetDesc/CMakeLists.txt
llvm/lib/Target/AMDGPU/AsmParser/CMakeLists.txt
llvm/lib/Target/AMDGPU/CMakeLists.txt
llvm/lib/Target/AMDGPU/MCA/CMakeLists.txt
llvm/lib/Target/AMDGPU/MCTargetDesc/CMakeLists.txt
llvm/lib/Target/AMDGPU/Utils/CMakeLists.txt
llvm/lib/Target/ARM/AsmParser/CMakeLists.txt
llvm/lib/Target/ARM/CMakeLists.txt
llvm/lib/Target/ARM/Disassembler/CMakeLists.txt
llvm/lib/Target/ARM/MCTargetDesc/CMakeLists.txt
llvm/lib/Target/AVR/AsmParser/CMakeLists.txt
llvm/lib/Target/AVR/CMakeLists.txt
llvm/lib/Target/AVR/Disassembler/CMakeLists.txt
llvm/lib/Target/BPF/CMakeLists.txt
llvm/lib/Target/Hexagon/CMakeLists.txt
llvm/lib/Target/Lanai/AsmParser/CMakeLists.txt
llvm/lib/Target/Lanai/CMakeLists.txt
llvm/lib/Target/LoongArch/CMakeLists.txt
llvm/lib/Target/MSP430/AsmParser/CMakeLists.txt
llvm/lib/Target/Mips/CMakeLists.txt
llvm/lib/Target/NVPTX/CMakeLists.txt
llvm/lib/Target/PowerPC/CMakeLists.txt
llvm/lib/Target/PowerPC/MCTargetDesc/CMakeLists.txt
llvm/lib/Target/RISCV/CMakeLists.txt
llvm/lib/Target/RISCV/MCA/CMakeLists.txt
llvm/lib/Target/VE/AsmParser/CMakeLists.txt
llvm/lib/Target/VE/CMakeLists.txt
llvm/lib/Target/VE/Disassembler/CMakeLists.txt
llvm/lib/Target/VE/MCTargetDesc/CMakeLists.txt
llvm/lib/Target/WebAssembly/AsmParser/CMakeLists.txt
llvm/lib/Target/WebAssembly/CMakeLists.txt
llvm/lib/Target/WebAssembly/Disassembler/CMakeLists.txt
llvm/lib/Target/WebAssembly/MCTargetDesc/CMakeLists.txt
llvm/lib/Target/X86/CMakeLists.txt
llvm/lib/Target/X86/MCA/CMakeLists.txt
llvm/lib/Target/X86/MCTargetDesc/CMakeLists.txt
llvm/lib/Target/XCore/Disassembler/CMakeLists.txt
llvm/tools/dsymutil/CMakeLists.txt
llvm/tools/llvm-debuginfo-analyzer/CMakeLists.txt
llvm/tools/llvm-dwarfutil/CMakeLists.txt
llvm/tools/llvm-exegesis/lib/AArch64/CMakeLists.txt
llvm/tools/llvm-exegesis/lib/Mips/CMakeLists.txt
llvm/tools/llvm-exegesis/lib/PowerPC/CMakeLists.txt
llvm/tools/llvm-exegesis/lib/X86/CMakeLists.txt
llvm/tools/llvm-gsymutil/CMakeLists.txt
llvm/tools/llvm-ifs/CMakeLists.txt
llvm/tools/llvm-modextract/CMakeLists.txt
llvm/tools/llvm-opt-fuzzer/CMakeLists.txt
llvm/tools/llvm-opt-report/CMakeLists.txt
llvm/tools/llvm-profdata/CMakeLists.txt
llvm/tools/llvm-readobj/CMakeLists.txt
llvm/tools/llvm-reduce/CMakeLists.txt
llvm/tools/llvm-remark-size-diff/CMakeLists.txt
llvm/tools/llvm-remarkutil/CMakeLists.txt
llvm/tools/sancov/CMakeLists.txt
llvm/unittests/DWARFLinkerParallel/CMakeLists.txt
llvm/unittests/Frontend/CMakeLists.txt
llvm/unittests/Target/AArch64/CMakeLists.txt
llvm/unittests/Target/ARM/CMakeLists.txt
llvm/unittests/Target/LoongArch/CMakeLists.txt
llvm/unittests/Target/X86/CMakeLists.txt
llvm/unittests/TextAPI/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 8a953eeea2759..12dabc34421fd 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -26,9 +26,9 @@ add_clang_library(clangTidy
 
 clang_target_link_libraries(clangTidy
   PRIVATE
-  clangAnalysis
   clangAST
   clangASTMatchers
+  clangAnalysis
   clangBasic
   clangFormat
   clangFrontend

diff  --git a/clang/lib/CodeGen/CMakeLists.txt 
b/clang/lib/CodeGen/CMakeLists.txt
index 2ce04e3411282..13dd16d93d7af 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -1,4 +1,5 @@
 set(LLVM_LINK_COMPONENTS
+  AggressiveInstCombine
   Analysis
   BitReader
   BitWriter
@@ -12,7 +13,6 @@ set(LLVM_LINK_COMPONENTS
   IPO
   IRPrinter
   IRReader
-  AggressiveInstCombine
   InstCombine
   Instrumentation
   LTO
@@ -93,8 +93,8 @@ 

[clang-tools-extra] 7d5d987 - [CMake] Reorder and reformat deps

2023-04-16 Thread NAKAMURA Takumi via cfe-commits

Author: NAKAMURA Takumi
Date: 2023-04-17T00:32:16+09:00
New Revision: 7d5d987e93bb4650d1dade41f0d5c5025ccb5b5c

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

LOG: [CMake] Reorder and reformat deps

Added: 


Modified: 
clang-tools-extra/clang-tidy/CMakeLists.txt
clang/lib/CodeGen/CMakeLists.txt
clang/lib/Interpreter/CMakeLists.txt
clang/lib/Tooling/DependencyScanning/CMakeLists.txt
clang/tools/clang-scan-deps/CMakeLists.txt
clang/unittests/Analysis/CMakeLists.txt
clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
clang/unittests/DirectoryWatcher/CMakeLists.txt
clang/unittests/Introspection/CMakeLists.txt
clang/unittests/Sema/CMakeLists.txt
llvm/lib/DWARFLinker/CMakeLists.txt
llvm/lib/DWARFLinkerParallel/CMakeLists.txt
llvm/lib/DWP/CMakeLists.txt
llvm/lib/LTO/CMakeLists.txt
llvm/lib/Target/AArch64/CMakeLists.txt
llvm/lib/Target/AArch64/MCTargetDesc/CMakeLists.txt
llvm/lib/Target/AMDGPU/AsmParser/CMakeLists.txt
llvm/lib/Target/AMDGPU/CMakeLists.txt
llvm/lib/Target/AMDGPU/MCA/CMakeLists.txt
llvm/lib/Target/AMDGPU/MCTargetDesc/CMakeLists.txt
llvm/lib/Target/AMDGPU/Utils/CMakeLists.txt
llvm/lib/Target/ARM/AsmParser/CMakeLists.txt
llvm/lib/Target/ARM/CMakeLists.txt
llvm/lib/Target/ARM/Disassembler/CMakeLists.txt
llvm/lib/Target/ARM/MCTargetDesc/CMakeLists.txt
llvm/lib/Target/AVR/AsmParser/CMakeLists.txt
llvm/lib/Target/AVR/CMakeLists.txt
llvm/lib/Target/AVR/Disassembler/CMakeLists.txt
llvm/lib/Target/BPF/CMakeLists.txt
llvm/lib/Target/Hexagon/CMakeLists.txt
llvm/lib/Target/Lanai/AsmParser/CMakeLists.txt
llvm/lib/Target/Lanai/CMakeLists.txt
llvm/lib/Target/LoongArch/CMakeLists.txt
llvm/lib/Target/MSP430/AsmParser/CMakeLists.txt
llvm/lib/Target/Mips/CMakeLists.txt
llvm/lib/Target/NVPTX/CMakeLists.txt
llvm/lib/Target/PowerPC/CMakeLists.txt
llvm/lib/Target/PowerPC/MCTargetDesc/CMakeLists.txt
llvm/lib/Target/RISCV/CMakeLists.txt
llvm/lib/Target/RISCV/MCA/CMakeLists.txt
llvm/lib/Target/VE/AsmParser/CMakeLists.txt
llvm/lib/Target/VE/CMakeLists.txt
llvm/lib/Target/VE/Disassembler/CMakeLists.txt
llvm/lib/Target/VE/MCTargetDesc/CMakeLists.txt
llvm/lib/Target/WebAssembly/AsmParser/CMakeLists.txt
llvm/lib/Target/WebAssembly/CMakeLists.txt
llvm/lib/Target/WebAssembly/Disassembler/CMakeLists.txt
llvm/lib/Target/WebAssembly/MCTargetDesc/CMakeLists.txt
llvm/lib/Target/X86/CMakeLists.txt
llvm/lib/Target/X86/MCA/CMakeLists.txt
llvm/lib/Target/X86/MCTargetDesc/CMakeLists.txt
llvm/lib/Target/XCore/Disassembler/CMakeLists.txt
llvm/tools/dsymutil/CMakeLists.txt
llvm/tools/llvm-debuginfo-analyzer/CMakeLists.txt
llvm/tools/llvm-dwarfutil/CMakeLists.txt
llvm/tools/llvm-exegesis/lib/AArch64/CMakeLists.txt
llvm/tools/llvm-exegesis/lib/Mips/CMakeLists.txt
llvm/tools/llvm-exegesis/lib/PowerPC/CMakeLists.txt
llvm/tools/llvm-exegesis/lib/X86/CMakeLists.txt
llvm/tools/llvm-gsymutil/CMakeLists.txt
llvm/tools/llvm-ifs/CMakeLists.txt
llvm/tools/llvm-modextract/CMakeLists.txt
llvm/tools/llvm-opt-fuzzer/CMakeLists.txt
llvm/tools/llvm-opt-report/CMakeLists.txt
llvm/tools/llvm-profdata/CMakeLists.txt
llvm/tools/llvm-readobj/CMakeLists.txt
llvm/tools/llvm-reduce/CMakeLists.txt
llvm/tools/llvm-remark-size-diff/CMakeLists.txt
llvm/tools/llvm-remarkutil/CMakeLists.txt
llvm/tools/sancov/CMakeLists.txt
llvm/unittests/DWARFLinkerParallel/CMakeLists.txt
llvm/unittests/Frontend/CMakeLists.txt
llvm/unittests/Target/AArch64/CMakeLists.txt
llvm/unittests/Target/ARM/CMakeLists.txt
llvm/unittests/Target/LoongArch/CMakeLists.txt
llvm/unittests/Target/X86/CMakeLists.txt
llvm/unittests/TextAPI/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 8a953eeea2759..12dabc34421fd 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -26,9 +26,9 @@ add_clang_library(clangTidy
 
 clang_target_link_libraries(clangTidy
   PRIVATE
-  clangAnalysis
   clangAST
   clangASTMatchers
+  clangAnalysis
   clangBasic
   clangFormat
   clangFrontend

diff  --git a/clang/lib/CodeGen/CMakeLists.txt 
b/clang/lib/CodeGen/CMakeLists.txt
index 2ce04e3411282..13dd16d93d7af 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -1,4 +1,5 @@
 set(LLVM_LINK_COMPONENTS
+  AggressiveInstCombine
   Analysis
   BitReader
   BitWriter
@@ -12,7 +13,6 @@ set(LLVM_LINK_COMPONENTS
   IPO
   IRPrinter
   IRReader
-  AggressiveInstCombine
   InstCombine
   Instrumentation
   LTO
@@ -93,8 +93,8 @@ 

[PATCH] D148467: [clang-format] Add a new AfterCSharpProperty to BraceWrapping

2023-04-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

I'm not convinced `AfterCSharpProperty`  is a good name, open for suggestions


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

https://reviews.llvm.org/D148467

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


[PATCH] D148467: [clang-format] Add a new AfterCSharpProperty to BraceWrapping

2023-04-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/unittests/Format/FormatTestCSharp.cpp:1633
+   "{\n"
+   "string Foo { set; get }\n"
+   "}\n",

Hmm.. maybe this should be 

```
string Foo 
{
set;get
}
```


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

https://reviews.llvm.org/D148467

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


[PATCH] D148467: [clang-format] Add a new AfterCSharpProperty to BraceWrapping

2023-04-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 514017.

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

https://reviews.llvm.org/D148467

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestCSharp.cpp

Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -1604,5 +1604,51 @@
   EXPECT_NE("", format("int where b <")); // reduced from crasher
 }
 
+TEST_F(FormatTestCSharp, PropertyWrapping) {
+  FormatStyle Style = getMicrosoftStyle(FormatStyle::LK_CSharp);
+
+  Style.BraceWrapping.AfterCSharpProperty = false;
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo { set; get; }\n"
+   "}\n",
+   Style);
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo\n"
+   "{\n"
+   "set {\n"
+   "val = value;\n"
+   "}\n"
+   "get {\n"
+   "return value;\n"
+   "}\n"
+   "}\n"
+   "}\n",
+   Style);
+  Style.BraceWrapping.AfterCSharpProperty = true;
+
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo { set; get }\n"
+   "}\n",
+   Style);
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo\n"
+   "{\n"
+   "set\n"
+   "{\n"
+   "val = value;\n"
+   "}\n"
+   "get\n"
+   "{\n"
+   "return value;\n"
+   "}\n"
+   "}\n"
+   "}\n",
+   Style);
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -4984,6 +4984,12 @@
   return true;
 }
 
+if (Style.isCSharp() && Style.BraceWrapping.AfterCSharpProperty &&
+(Line.startsWith(Keywords.kw_get) ||
+ Line.startsWith(Keywords.kw_set))) {
+  return true;
+}
+
 // Don't attempt to interpret struct return types as structs.
 if (Right.isNot(TT_FunctionLBrace)) {
   return (Line.startsWith(tok::kw_class) &&
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -181,6 +181,7 @@
 IO.mapOptional("AfterEnum", Wrapping.AfterEnum);
 IO.mapOptional("AfterExternBlock", Wrapping.AfterExternBlock);
 IO.mapOptional("AfterFunction", Wrapping.AfterFunction);
+IO.mapOptional("AfterCSharpProperty", Wrapping.AfterCSharpProperty);
 IO.mapOptional("AfterNamespace", Wrapping.AfterNamespace);
 IO.mapOptional("AfterObjCDeclaration", Wrapping.AfterObjCDeclaration);
 IO.mapOptional("AfterStruct", Wrapping.AfterStruct);
@@ -1188,7 +1189,8 @@
 /*IndentBraces=*/false,
 /*SplitEmptyFunction=*/true,
 /*SplitEmptyRecord=*/true,
-/*SplitEmptyNamespace=*/true};
+/*SplitEmptyNamespace=*/true,
+/*AfterCSharpProperty=*/false};
   switch (Expanded.BreakBeforeBraces) {
   case FormatStyle::BS_Linux:
 Expanded.BraceWrapping.AfterClass = true;
@@ -1354,7 +1356,8 @@
  /*IndentBraces=*/false,
  /*SplitEmptyFunction=*/true,
  /*SplitEmptyRecord=*/true,
- /*SplitEmptyNamespace=*/true};
+ /*SplitEmptyNamespace=*/true,
+ /*AfterCSharpProperty=*/false};
   LLVMStyle.BreakAfterAttributes = FormatStyle::ABS_Never;
   LLVMStyle.BreakAfterJavaFieldAnnotations = false;
   LLVMStyle.BreakArrays = true;
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -1205,6 +1205,19 @@
 /// \endcode
 ///
 bool SplitEmptyNamespace;
+/// Wrap C# setter/getter properties.
+/// \code
+///   true:
+///   get
+///   {}
+///   set
+///   {}
+///
+///   false:
+///   get {}
+///   set {}
+/// \endcode
+bool AfterCSharpProperty;
   };
 
   /// Control of individual brace wrapping cases.
Index: clang/docs/ReleaseNotes.rst

[PATCH] D148467: [clang-format] Add a new AfterCSharpProperty to BraceWrapping

2023-04-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: owenpan, HazardyKnusperkeks, rymiel.
MyDeveloperDay added a project: clang-format.
Herald added projects: All, clang.
MyDeveloperDay requested review of this revision.

This change allows always breaking before braces on C# setter and getter 
properties

Fixes #61968

https://github.com/llvm/llvm-project/issues/61968


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148467

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestCSharp.cpp

Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -1604,5 +1604,51 @@
   EXPECT_NE("", format("int where b <")); // reduced from crasher
 }
 
+TEST_F(FormatTestCSharp, PropertyWrapping) {
+  FormatStyle Style = getMicrosoftStyle(FormatStyle::LK_CSharp);
+
+  Style.BraceWrapping.AfterCSharpProperty = false;
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo { set; get; }\n"
+   "}\n",
+   Style);
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo\n"
+   "{\n"
+   "set {\n"
+   "val = value;\n"
+   "}\n"
+   "get {\n"
+   "return value;\n"
+   "}\n"
+   "}\n"
+   "}\n",
+   Style);
+  Style.BraceWrapping.AfterCSharpProperty = true;
+
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo { set; get }\n"
+   "}\n",
+   Style);
+  verifyFormat("class A\n"
+   "{\n"
+   "string Foo\n"
+   "{\n"
+   "set\n"
+   "{\n"
+   "val = value;\n"
+   "}\n"
+   "get\n"
+   "{\n"
+   "return value;\n"
+   "}\n"
+   "}\n"
+   "}\n",
+   Style);
+}
+
 } // namespace format
 } // end namespace clang
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -4984,6 +4984,12 @@
   return true;
 }
 
+if (Style.isCSharp() && Style.BraceWrapping.AfterCSharpProperty &&
+(Line.startsWith(Keywords.kw_get) ||
+ Line.startsWith(Keywords.kw_set))) {
+  return true;
+}
+
 // Don't attempt to interpret struct return types as structs.
 if (Right.isNot(TT_FunctionLBrace)) {
   return (Line.startsWith(tok::kw_class) &&
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -181,6 +181,7 @@
 IO.mapOptional("AfterEnum", Wrapping.AfterEnum);
 IO.mapOptional("AfterExternBlock", Wrapping.AfterExternBlock);
 IO.mapOptional("AfterFunction", Wrapping.AfterFunction);
+IO.mapOptional("AfterCSharpProperty", Wrapping.AfterCSharpProperty);
 IO.mapOptional("AfterNamespace", Wrapping.AfterNamespace);
 IO.mapOptional("AfterObjCDeclaration", Wrapping.AfterObjCDeclaration);
 IO.mapOptional("AfterStruct", Wrapping.AfterStruct);
@@ -1188,7 +1189,8 @@
 /*IndentBraces=*/false,
 /*SplitEmptyFunction=*/true,
 /*SplitEmptyRecord=*/true,
-/*SplitEmptyNamespace=*/true};
+/*SplitEmptyNamespace=*/true,
+/*AfterCSharpProperty=*/false};
   switch (Expanded.BreakBeforeBraces) {
   case FormatStyle::BS_Linux:
 Expanded.BraceWrapping.AfterClass = true;
@@ -1354,7 +1356,8 @@
  /*IndentBraces=*/false,
  /*SplitEmptyFunction=*/true,
  /*SplitEmptyRecord=*/true,
- /*SplitEmptyNamespace=*/true};
+ /*SplitEmptyNamespace=*/true,
+ /*AfterCSharpProperty=*/false};
   LLVMStyle.BreakAfterAttributes = FormatStyle::ABS_Never;
   LLVMStyle.BreakAfterJavaFieldAnnotations = false;
   LLVMStyle.BreakArrays = true;
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -1205,6 +1205,19 @@
 /// \endcode
 ///
 bool SplitEmptyNamespace;
+/// Wrap C# setter/getter definitions.
+   

[PATCH] D148460: [clang-tidy] Add alias cppcoreguidelines-use-default-member-init

2023-04-16 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko accepted this revision.
Eugene.Zelenko added a comment.

Please create issue for deprecation after commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148460

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


[PATCH] D147175: [clang] Add __is_trivially_equality_comparable

2023-04-16 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added a comment.

ping @aaron.ballman


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147175

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


[PATCH] D148460: [clang-tidy] Add alias cppcoreguidelines-use-default-member-init

2023-04-16 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148460

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


[PATCH] D148444: [clang-tidy] Prevent `llvmlibc-inline-function-decl` triggering on lambdas

2023-04-16 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 514001.
jhuber6 added a comment.

Rebasing on main


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148444

Files:
  clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
===
--- clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
@@ -60,6 +60,14 @@
   }
 };
 
+LIBC_INLINE void lambda() {
+// CHECK-MESSAGES-NOT: :[[@LINE+4]]:3: warning: '__invoke' must be tagged with 
the LIBC_INLINE macro; the macro should be placed at the beginning of the 
declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+3]]:3: warning: 'operator void (*)()' must be 
tagged with the LIBC_INLINE macro; the macro should be placed at the beginning 
of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+2]]:3: warning: '~(lambda at [[FILENAME:.+]])' 
must be tagged with the LIBC_INLINE macro; the macro should be placed at the 
beginning of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+1]]:6: warning: 'operator()' must be tagged 
with the LIBC_INLINE macro; the macro should be placed at the beginning of the 
declaration [llvmlibc-inline-function-decl]
+  [](){};
+}
+
 } // namespace __llvm_libc
 
 #endif // 
LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_LLVMLIBC_INLINEFUNCTIONDECL_H
Index: clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
===
--- clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
+++ clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
@@ -39,6 +39,12 @@
 HeaderFileExtensions))
 return;
 
+  // Consider only functions with an external and visible declaration.
+  if (const auto *MethodDecl = dyn_cast(FuncDecl)) {
+if (MethodDecl->getParent()->isLambda())
+  return;
+  }
+
   // Check if decl starts with LIBC_INLINE
   auto Loc = FullSourceLoc(Result.SourceManager->getFileLoc(SrcBegin),
*Result.SourceManager);


Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
===
--- clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
@@ -60,6 +60,14 @@
   }
 };
 
+LIBC_INLINE void lambda() {
+// CHECK-MESSAGES-NOT: :[[@LINE+4]]:3: warning: '__invoke' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+3]]:3: warning: 'operator void (*)()' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+2]]:3: warning: '~(lambda at [[FILENAME:.+]])' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+1]]:6: warning: 'operator()' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+  [](){};
+}
+
 } // namespace __llvm_libc
 
 #endif // LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_LLVMLIBC_INLINEFUNCTIONDECL_H
Index: clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
===
--- clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
+++ clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
@@ -39,6 +39,12 @@
 HeaderFileExtensions))
 return;
 
+  // Consider only functions with an external and visible declaration.
+  if (const auto *MethodDecl = dyn_cast(FuncDecl)) {
+if (MethodDecl->getParent()->isLambda())
+  return;
+  }
+
   // Check if decl starts with LIBC_INLINE
   auto Loc = FullSourceLoc(Result.SourceManager->getFileLoc(SrcBegin),
*Result.SourceManager);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144748: [clang-tidy] Add bugprone-empty-catch check

2023-04-16 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 514000.
PiotrZSL added a comment.

Add getCheckTraversalKind, format tests, fix some review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144748

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp
@@ -0,0 +1,67 @@
+// RUN: %check_clang_tidy -std=c++98-or-later %s bugprone-empty-catch %t -- \
+// RUN: -config="{CheckOptions: [{key: bugprone-empty-catch.AllowEmptyCatchForExceptions, value: '::SafeException;WarnException'}, \
+// RUN:{key: bugprone-empty-catch.IgnoreCatchWithKeywords, value: '@IGNORE;@TODO'}]}"
+
+struct Exception {};
+struct SafeException {};
+struct WarnException : Exception {};
+
+int functionWithThrow() {
+  try {
+throw 5;
+  } catch (const Exception &) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: empty catch statements hide issues; to handle exceptions appropriately, consider re-throwing, handling, or avoiding catch altogether [bugprone-empty-catch]
+  } catch (...) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: empty catch statements hide issues; to handle exceptions appropriately, consider re-throwing, handling, or avoiding catch altogether [bugprone-empty-catch]
+  }
+  return 0;
+}
+
+int functionWithHandling() {
+  try {
+throw 5;
+  } catch (const Exception &) {
+return 2;
+  } catch (...) {
+return 1;
+  }
+  return 0;
+}
+
+int functionWithReThrow() {
+  try {
+throw 5;
+  } catch (...) {
+throw;
+  }
+}
+
+int functionWithNewThrow() {
+  try {
+throw 5;
+  } catch (...) {
+throw Exception();
+  }
+}
+
+void functionWithAllowedException() {
+  try {
+
+  } catch (const SafeException &) {
+  } catch (WarnException) {
+  }
+}
+
+void functionWithComment() {
+  try {
+  } catch (const Exception &) {
+// @todo: implement later, check case insensitive
+  }
+}
+
+void functionWithComment2() {
+  try {
+  } catch (const Exception &) {
+// @IGNORE: relax its safe
+  }
+}
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -86,6 +86,7 @@
`bugprone-dangling-handle `_,
`bugprone-dynamic-static-initializers `_,
`bugprone-easily-swappable-parameters `_,
+   `bugprone-empty-catch `_,
`bugprone-exception-escape `_,
`bugprone-fold-init-type `_,
`bugprone-forward-declaration-namespace `_,
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst
@@ -0,0 +1,149 @@
+.. title:: clang-tidy - bugprone-empty-catch
+
+bugprone-empty-catch
+
+
+Detects and suggests addressing issues with empty catch statements.
+
+.. code-block:: c++
+
+  try {
+// Some code that can throw an exception
+  } catch(const std::exception&) {
+  }
+
+Having empty catch statements in a codebase can be a serious problem that
+developers should be aware of. Catch statements are used to handle exceptions
+that are thrown during program execution. When an exception is thrown, the
+program jumps to the nearest catch statement that matches the type of the
+exception.
+
+Empty catch statements, also known as "swallowing" exceptions, catch the
+exception but do nothing with it. This means that the exception is not handled
+properly, and the program continues to run as if nothing happened. This can
+lead to several issues, such as:
+
+* *Hidden Bugs*: If an exception is caught and ignored, it can lead to hidden
+  bugs that are difficult to diagnose and fix. The root cause of the problem
+  may not be apparent, and the program may continue to behave in unexpected
+  ways.
+
+* *Security Issues*: Ignoring exceptions can lead to security issues, such as
+  buffer overflows or null pointer dereferences. Hackers can exploit these
+  vulnerabilities to gain access to sensitive data or execute malicious code.
+
+* *Poor Code Quality*: Empty catch statements can indicate poor code quality
+  and a lack of attention to detail. This can make the codebase difficult to
+  maintain and update, leading to longer development 

[PATCH] D144748: [clang-tidy] Add bugprone-empty-catch check

2023-04-16 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL marked 4 inline comments as done.
PiotrZSL added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst:147-153
+.. option:: IgnoreCatchWithKeywords
+
+This option can be used to ignore specific catch statements containing
+certain keywords. If a ``catch`` statement body contains (case-insensitive)
+any of the keywords listed in this semicolon-separated option, then the
+catch will be ignored, and no warning will be raised.
+Default value: `@TODO;@FIXME`.

carlosgalvezp wrote:
> I'm not sure this option is worth the added complexity - if people want to 
> allow an empty catch with a comment, they might as well just add a `NOLINT` 
> to suppress the warning? It will be even more clear that it's actually a 
> problem: it's not a regular `TODO` that doesn't necessarily imply a problem, 
> but rather something that a static analyzer considers a problem. 
> 
> 
I added this so people could have ability to ignore some issues without putting 
NOLINT's. This can be also used when developer put some macro into catch block, 
that would be build dependent, like assert or something.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144748

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


[PATCH] D148444: [clang-tidy] Prevent `llvmlibc-inline-function-decl` triggering on lambdas

2023-04-16 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

Rebase code, this will fix a build.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148444

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


[PATCH] D148444: [clang-tidy] Prevent `llvmlibc-inline-function-decl` triggering on lambdas

2023-04-16 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp:66
+// CHECK-MESSAGES-NOT: :[[@LINE+3]]:3: warning: 'operator void (*)()' must be 
tagged with the LIBC_INLINE macro; the macro should be placed at the beginning 
of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+2]]:3: warning: '~(lambda at [[FILENAME:.+]])' 
must be tagged with the LIBC_INLINE macro; the macro should be placed at the 
beginning of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+1]]:6: warning: 'operator()' must be tagged 
with the LIBC_INLINE macro; the macro should be placed at the beginning of the 
declaration [llvmlibc-inline-function-decl]

jhuber6 wrote:
> PiotrZSL wrote:
> > NOTE: If this warning were printed then we got other issue in this check.
> > Implicit functions are checked, would be good to exclude them:
> > `functionDecl(unless(isImplicit()))`.
> That was printed without this patch. Are you saying we should have a separate 
> check for these types of functions?
I'm just telling that this shouldn't be printed in first place because they are 
implicit, so there is no place to add macro.
For me this is another bug in this check that should be addressed (probably in 
separate patch).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148444

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


[PATCH] D148444: [clang-tidy] Prevent `llvmlibc-inline-function-decl` triggering on lambdas

2023-04-16 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D148444#4272036 , @PiotrZSL wrote:

> Fix Linux build before committing & resolve all comments.

The log says that it failed because of the CMake version. I don't think I can 
fix that.




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp:66
+// CHECK-MESSAGES-NOT: :[[@LINE+3]]:3: warning: 'operator void (*)()' must be 
tagged with the LIBC_INLINE macro; the macro should be placed at the beginning 
of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+2]]:3: warning: '~(lambda at [[FILENAME:.+]])' 
must be tagged with the LIBC_INLINE macro; the macro should be placed at the 
beginning of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+1]]:6: warning: 'operator()' must be tagged 
with the LIBC_INLINE macro; the macro should be placed at the beginning of the 
declaration [llvmlibc-inline-function-decl]

PiotrZSL wrote:
> NOTE: If this warning were printed then we got other issue in this check.
> Implicit functions are checked, would be good to exclude them:
> `functionDecl(unless(isImplicit()))`.
That was printed without this patch. Are you saying we should have a separate 
check for these types of functions?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148444

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


[PATCH] D144748: [clang-tidy] Add bugprone-empty-catch check

2023-04-16 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL marked an inline comment as done.
PiotrZSL added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp:100
+void EmptyCatchCheck::check(const MatchFinder::MatchResult ) {
+  const auto *MatchedCatchStmt = Result.Nodes.getNodeAs("catch");
+

PiotrZSL wrote:
> carlosgalvezp wrote:
> > Assert that it's not null, or exit early.
> I cannot be null.
It*


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144748

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


[PATCH] D144748: [clang-tidy] Add bugprone-empty-catch check

2023-04-16 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL marked an inline comment as done.
PiotrZSL added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp:100
+void EmptyCatchCheck::check(const MatchFinder::MatchResult ) {
+  const auto *MatchedCatchStmt = Result.Nodes.getNodeAs("catch");
+

carlosgalvezp wrote:
> Assert that it's not null, or exit early.
I cannot be null.



Comment at: clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp:104
+  MatchedCatchStmt->getCatchLoc(),
+  "empty catch statements hide issues, to handle exceptions appropriately, 
"
+  "consider re-throwing, handling, or avoiding catch altogether");

carlosgalvezp wrote:
> Nit: I believe a semicolon or dot is more appropriate here
I can use semicolon 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144748

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


[PATCH] D148444: [clang-tidy] Prevent `llvmlibc-inline-function-decl` triggering on lambdas

2023-04-16 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

Fix Linux build before committing & resolve all comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148444

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


[PATCH] D148444: [clang-tidy] Prevent `llvmlibc-inline-function-decl` triggering on lambdas

2023-04-16 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added a comment.
This revision is now accepted and ready to land.

From functional point of view it's looking good.




Comment at: clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp:42
 
+  // Consider only functions with an external and visible declaration.
+  if (const auto *MethodDecl = dyn_cast(FuncDecl)) {

NOTE: This comment refers also to inline exclusion in line 33.
I don't think is needed, or you can extract line 33 and 43 into separate 
function like isExternalyVisibleDeclaration, and to be honest for check that 
there are other ways, some checks already do that, because simply then you can 
ask your self, what about coonstexpr functions, what about static functions, 
functions in anonymous namespace In theory they also may be catch here. Even 
that inline keyword could be redundant.




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp:66
+// CHECK-MESSAGES-NOT: :[[@LINE+3]]:3: warning: 'operator void (*)()' must be 
tagged with the LIBC_INLINE macro; the macro should be placed at the beginning 
of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+2]]:3: warning: '~(lambda at [[FILENAME:.+]])' 
must be tagged with the LIBC_INLINE macro; the macro should be placed at the 
beginning of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+1]]:6: warning: 'operator()' must be tagged 
with the LIBC_INLINE macro; the macro should be placed at the beginning of the 
declaration [llvmlibc-inline-function-decl]

NOTE: If this warning were printed then we got other issue in this check.
Implicit functions are checked, would be good to exclude them:
`functionDecl(unless(isImplicit()))`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148444

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


[PATCH] D144748: [clang-tidy] Add bugprone-empty-catch check

2023-04-16 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst:103
+{
+try
+{

Use 2 spaces indentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144748

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


[PATCH] D144748: [clang-tidy] Add bugprone-empty-catch check

2023-04-16 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp:100
+void EmptyCatchCheck::check(const MatchFinder::MatchResult ) {
+  const auto *MatchedCatchStmt = Result.Nodes.getNodeAs("catch");
+

Assert that it's not null, or exit early.



Comment at: clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp:104
+  MatchedCatchStmt->getCatchLoc(),
+  "empty catch statements hide issues, to handle exceptions appropriately, 
"
+  "consider re-throwing, handling, or avoiding catch altogether");

Nit: I believe a semicolon or dot is more appropriate here



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/empty-catch.rst:147-153
+.. option:: IgnoreCatchWithKeywords
+
+This option can be used to ignore specific catch statements containing
+certain keywords. If a ``catch`` statement body contains (case-insensitive)
+any of the keywords listed in this semicolon-separated option, then the
+catch will be ignored, and no warning will be raised.
+Default value: `@TODO;@FIXME`.

I'm not sure this option is worth the added complexity - if people want to 
allow an empty catch with a comment, they might as well just add a `NOLINT` to 
suppress the warning? It will be even more clear that it's actually a problem: 
it's not a regular `TODO` that doesn't necessarily imply a problem, but rather 
something that a static analyzer considers a problem. 





Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp:11
+{
+try
+{

Fix indentation to 2 chars.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/empty-catch.cpp:16
+catch(const Exception&)
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: empty catch statements hide 
issues, to handle exceptions appropriately, consider re-throwing, handling, or 
avoiding catch altogether [bugprone-empty-catch]
+{

Align comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144748

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


[PATCH] D148444: [clang-tidy] Prevent `llvmlibc-inline-function-decl` triggering on lambdas

2023-04-16 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp:64-67
+// CHECK-MESSAGES-NOT: :[[@LINE+4]]:3: warning: '__invoke' must be tagged with 
the LIBC_INLINE macro; the macro should be placed at the beginning of the 
declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+3]]:3: warning: 'operator void (*)()' must be 
tagged with the LIBC_INLINE macro; the macro should be placed at the beginning 
of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+2]]:3: warning: '~(lambda at [[FILENAME:.+]])' 
must be tagged with the LIBC_INLINE macro; the macro should be placed at the 
beginning of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+1]]:6: warning: 'operator()' must be tagged 
with the LIBC_INLINE macro; the macro should be placed at the beginning of the 
declaration [llvmlibc-inline-function-decl]

carlosgalvezp wrote:
> Not needed, simply write a plain comment explaining why the check should not 
> warn here.
Since I've already written it I think we should be able to keep it. If really 
you don't like the extra check lines I can remove them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148444

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


[PATCH] D148444: [clang-tidy] Prevent `llvmlibc-inline-function-decl` triggering on lambdas

2023-04-16 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 513997.
jhuber6 added a comment.

Address nit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148444

Files:
  clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
===
--- clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
@@ -60,6 +60,14 @@
   }
 };
 
+LIBC_INLINE void lambda() {
+// CHECK-MESSAGES-NOT: :[[@LINE+4]]:3: warning: '__invoke' must be tagged with 
the LIBC_INLINE macro; the macro should be placed at the beginning of the 
declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+3]]:3: warning: 'operator void (*)()' must be 
tagged with the LIBC_INLINE macro; the macro should be placed at the beginning 
of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+2]]:3: warning: '~(lambda at [[FILENAME:.+]])' 
must be tagged with the LIBC_INLINE macro; the macro should be placed at the 
beginning of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+1]]:6: warning: 'operator()' must be tagged 
with the LIBC_INLINE macro; the macro should be placed at the beginning of the 
declaration [llvmlibc-inline-function-decl]
+  [](){};
+}
+
 } // namespace __llvm_libc
 
 #endif // 
LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_LLVMLIBC_INLINEFUNCTIONDECL_H
Index: clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
===
--- clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
+++ clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
@@ -39,6 +39,12 @@
 HeaderFileExtensions))
 return;
 
+  // Consider only functions with an external and visible declaration.
+  if (const auto *MethodDecl = dyn_cast(FuncDecl)) {
+if (MethodDecl->getParent()->isLambda())
+  return;
+  }
+
   // Check if decl starts with LIBC_INLINE
   auto Loc = FullSourceLoc(Result.SourceManager->getFileLoc(SrcBegin),
*Result.SourceManager);


Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
===
--- clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
@@ -60,6 +60,14 @@
   }
 };
 
+LIBC_INLINE void lambda() {
+// CHECK-MESSAGES-NOT: :[[@LINE+4]]:3: warning: '__invoke' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+3]]:3: warning: 'operator void (*)()' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+2]]:3: warning: '~(lambda at [[FILENAME:.+]])' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+1]]:6: warning: 'operator()' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+  [](){};
+}
+
 } // namespace __llvm_libc
 
 #endif // LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_LLVMLIBC_INLINEFUNCTIONDECL_H
Index: clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
===
--- clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
+++ clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
@@ -39,6 +39,12 @@
 HeaderFileExtensions))
 return;
 
+  // Consider only functions with an external and visible declaration.
+  if (const auto *MethodDecl = dyn_cast(FuncDecl)) {
+if (MethodDecl->getParent()->isLambda())
+  return;
+  }
+
   // Check if decl starts with LIBC_INLINE
   auto Loc = FullSourceLoc(Result.SourceManager->getFileLoc(SrcBegin),
*Result.SourceManager);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148444: [clang-tidy] Prevent `llvmlibc-inline-function-decl` triggering on lambdas

2023-04-16 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added inline comments.



Comment at: clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp:43
+  // Consider only functions with an external and visible declaration.
+  if (const auto *MethodDecl = dyn_cast(FuncDecl))
+if (MethodDecl->getParent()->isLambda())

Since there are 2 lines under this `if`, please add braces for better 
readability.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp:64-67
+// CHECK-MESSAGES-NOT: :[[@LINE+4]]:3: warning: '__invoke' must be tagged with 
the LIBC_INLINE macro; the macro should be placed at the beginning of the 
declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+3]]:3: warning: 'operator void (*)()' must be 
tagged with the LIBC_INLINE macro; the macro should be placed at the beginning 
of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+2]]:3: warning: '~(lambda at [[FILENAME:.+]])' 
must be tagged with the LIBC_INLINE macro; the macro should be placed at the 
beginning of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+1]]:6: warning: 'operator()' must be tagged 
with the LIBC_INLINE macro; the macro should be placed at the beginning of the 
declaration [llvmlibc-inline-function-decl]

Not needed, simply write a plain comment explaining why the check should not 
warn here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148444

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


[PATCH] D148458: [clang-tidy][NFC] Split bugprone-exception-escape tests

2023-04-16 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp:267
 const derived *p = 
-throw p; 
   } catch(base *) {

carlosgalvezp wrote:
> I run into this often as well. If you don't want to get push back during 
> review because of this I advice you to disable the automatic trailing 
> whitespace removal for this project. Regular source code will be fixed via 
> clang-format anyway. Alternatively you will be asked to fix it in (another) 
> NFC patch :) 
> 
> I personally don't mind a couple or two such fixes, but here there's a lot of 
> them and really create noise, distracting from the actual patch.
Excuses...



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp:555-557
+void explicit_int_thrower() noexcept(false) {
+  throw 1;
+}

carlosgalvezp wrote:
> Why this change?
this test file tests only noexcept, not throw.
i added throw 1 just so check would still see as an throw of integer type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148458

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


[PATCH] D148458: [clang-tidy][NFC] Split bugprone-exception-escape tests

2023-04-16 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp:267
 const derived *p = 
-throw p; 
   } catch(base *) {

I run into this often as well. If you don't want to get push back during review 
because of this I advice you to disable the automatic trailing whitespace 
removal for this project. Regular source code will be fixed via clang-format 
anyway. Alternatively you will be asked to fix it in (another) NFC patch :) 

I personally don't mind a couple or two such fixes, but here there's a lot of 
them and really create noise, distracting from the actual patch.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp:555-557
+void explicit_int_thrower() noexcept(false) {
+  throw 1;
+}

Why this change?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148458

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


[PATCH] D148460: [clang-tidy] Add alias cppcoreguidelines-use-default-member-init

2023-04-16 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 513996.
carlosgalvezp added a comment.

Remove check from list of checks, since we do not add 
aliases there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148460

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-default-member-init.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst

Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -477,6 +477,7 @@
`cppcoreguidelines-explicit-virtual-functions `_, `modernize-use-override `_, "Yes"
`cppcoreguidelines-macro-to-enum `_, `modernize-macro-to-enum `_, "Yes"
`cppcoreguidelines-non-private-member-variables-in-classes `_, `misc-non-private-member-variables-in-classes `_,
+   `cppcoreguidelines-use-default-member-init `_, `modernize-use-default-member-init `_,
`fuchsia-header-anon-namespaces `_, `google-build-namespaces `_,
`google-readability-braces-around-statements `_, `readability-braces-around-statements `_, "Yes"
`google-readability-function-size `_, `readability-function-size `_,
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-default-member-init.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-default-member-init.rst
@@ -0,0 +1,12 @@
+.. title:: clang-tidy - cppcoreguidelines-use-default-member-init
+.. meta::
+   :http-equiv=refresh: 5;URL=../modernize/use-default-member-init.html
+
+cppcoreguidelines-use-default-member-init
+=
+
+This check implements `C.48 `_ from the CppCoreGuidelines.
+
+The cppcoreguidelines-use-default-member-init check is an alias, please see
+`modernize-use-default-member-init <../modernize/use-default-member-init.html>`_
+for more information.
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
@@ -23,6 +23,13 @@
 initializations already implemented as member initializers. For that purpose
 see check `modernize-use-default-member-init <../modernize/use-default-member-init.html>`_.
 
+.. note::
+
+  Enforcement of rule C.48 in this check is deprecated, to be removed in
+  :program:`clang-tidy` version 19 (only C.49 will be enforced by this check then).
+  Please use `cppcoreguidelines-use-default-member-init <../cppcoreguidelines/use-default-member-init.html>`_
+  to enfoce rule C.48.
+
 Example 1
 -
 
@@ -85,6 +92,11 @@
 
 .. option:: UseAssignment
 
+   Note: this option is deprecated, to be removed in :program:`clang-tidy`
+   version 19. Please use the `UseAssignment` option from
+   `cppcoreguidelines-use-default-member-init <../cppcoreguidelines/use-default-member-init.html>`_
+   instead.
+
If this option is set to `true` (by default `UseAssignment` from
`modernize-use-default-member-init
<../modernize/use-default-member-init.html>`_ will be used),
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -174,6 +174,11 @@
   ` to :doc:`bugprone-unsafe-functions
   ` was added.
 
+- New alias :doc:`cppcoreguidelines-use-default-member-init
+  ` to
+  :doc:`modernize-use-default-member-init
+  ` was added.
+
 Changes in existing checks
 ^^
 - Improved :doc:`readability-redundant-string-cstr
@@ -215,6 +220,11 @@
 - Deprecated :doc:`cert-dcl21-cpp
   ` check.
 
+- Deprecated C.48 enforcement from :doc:`cppcoreguidelines-prefer-member-initializer
+  `. Please use
+  :doc:`cppcoreguidelines-use-default-member-init
+  ` instead.
+
 - Deprecated check-local options `HeaderFileExtensions`
   in :doc:`google-build-namespaces
   ` check.
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
+++ 

[PATCH] D148460: [clang-tidy] Add alias cppcoreguidelines-use-default-member-init

2023-04-16 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 513995.
carlosgalvezp added a comment.

Add check to list of aliases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148460

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-default-member-init.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst

Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -207,6 +207,7 @@
`cppcoreguidelines-rvalue-reference-param-not-moved `_,
`cppcoreguidelines-slicing `_,
`cppcoreguidelines-special-member-functions `_,
+   `cppcoreguidelines-use-default-member-init `_, "Yes"
`cppcoreguidelines-virtual-class-destructor `_, "Yes"
`darwin-avoid-spinlock `_,
`darwin-dispatch-once-nonstatic `_, "Yes"
@@ -477,6 +478,7 @@
`cppcoreguidelines-explicit-virtual-functions `_, `modernize-use-override `_, "Yes"
`cppcoreguidelines-macro-to-enum `_, `modernize-macro-to-enum `_, "Yes"
`cppcoreguidelines-non-private-member-variables-in-classes `_, `misc-non-private-member-variables-in-classes `_,
+   `cppcoreguidelines-use-default-member-init `_, `modernize-use-default-member-init `_,
`fuchsia-header-anon-namespaces `_, `google-build-namespaces `_,
`google-readability-braces-around-statements `_, `readability-braces-around-statements `_, "Yes"
`google-readability-function-size `_, `readability-function-size `_,
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-default-member-init.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-default-member-init.rst
@@ -0,0 +1,12 @@
+.. title:: clang-tidy - cppcoreguidelines-use-default-member-init
+.. meta::
+   :http-equiv=refresh: 5;URL=../modernize/use-default-member-init.html
+
+cppcoreguidelines-use-default-member-init
+=
+
+This check implements `C.48 `_ from the CppCoreGuidelines.
+
+The cppcoreguidelines-use-default-member-init check is an alias, please see
+`modernize-use-default-member-init <../modernize/use-default-member-init.html>`_
+for more information.
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
@@ -23,6 +23,13 @@
 initializations already implemented as member initializers. For that purpose
 see check `modernize-use-default-member-init <../modernize/use-default-member-init.html>`_.
 
+.. note::
+
+  Enforcement of rule C.48 in this check is deprecated, to be removed in
+  :program:`clang-tidy` version 19 (only C.49 will be enforced by this check then).
+  Please use `cppcoreguidelines-use-default-member-init <../cppcoreguidelines/use-default-member-init.html>`_
+  to enfoce rule C.48.
+
 Example 1
 -
 
@@ -85,6 +92,11 @@
 
 .. option:: UseAssignment
 
+   Note: this option is deprecated, to be removed in :program:`clang-tidy`
+   version 19. Please use the `UseAssignment` option from
+   `cppcoreguidelines-use-default-member-init <../cppcoreguidelines/use-default-member-init.html>`_
+   instead.
+
If this option is set to `true` (by default `UseAssignment` from
`modernize-use-default-member-init
<../modernize/use-default-member-init.html>`_ will be used),
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -174,6 +174,11 @@
   ` to :doc:`bugprone-unsafe-functions
   ` was added.
 
+- New alias :doc:`cppcoreguidelines-use-default-member-init
+  ` to
+  :doc:`modernize-use-default-member-init
+  ` was added.
+
 Changes in existing checks
 ^^
 - Improved :doc:`readability-redundant-string-cstr
@@ -215,6 +220,11 @@
 - Deprecated :doc:`cert-dcl21-cpp
   ` check.
 
+- Deprecated C.48 enforcement from :doc:`cppcoreguidelines-prefer-member-initializer
+  `. Please use
+  :doc:`cppcoreguidelines-use-default-member-init
+  ` instead.
+
 - Deprecated check-local options `HeaderFileExtensions`
   in :doc:`google-build-namespaces
   ` 

[PATCH] D148460: [clang-tidy] Add alias cppcoreguidelines-use-default-member-init

2023-04-16 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 513994.
carlosgalvezp added a comment.

Rebase and fix conflicts.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148460

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-default-member-init.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst

Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -207,6 +207,7 @@
`cppcoreguidelines-rvalue-reference-param-not-moved `_,
`cppcoreguidelines-slicing `_,
`cppcoreguidelines-special-member-functions `_,
+   `cppcoreguidelines-use-default-member-init `_, "Yes"
`cppcoreguidelines-virtual-class-destructor `_, "Yes"
`darwin-avoid-spinlock `_,
`darwin-dispatch-once-nonstatic `_, "Yes"
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-default-member-init.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-default-member-init.rst
@@ -0,0 +1,12 @@
+.. title:: clang-tidy - cppcoreguidelines-use-default-member-init
+.. meta::
+   :http-equiv=refresh: 5;URL=../modernize/use-default-member-init.html
+
+cppcoreguidelines-use-default-member-init
+=
+
+This check implements `C.48 `_ from the CppCoreGuidelines.
+
+The cppcoreguidelines-use-default-member-init check is an alias, please see
+`modernize-use-default-member-init <../modernize/use-default-member-init.html>`_
+for more information.
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
@@ -23,6 +23,13 @@
 initializations already implemented as member initializers. For that purpose
 see check `modernize-use-default-member-init <../modernize/use-default-member-init.html>`_.
 
+.. note::
+
+  Enforcement of rule C.48 in this check is deprecated, to be removed in
+  :program:`clang-tidy` version 19 (only C.49 will be enforced by this check then).
+  Please use `cppcoreguidelines-use-default-member-init <../cppcoreguidelines/use-default-member-init.html>`_
+  to enfoce rule C.48.
+
 Example 1
 -
 
@@ -85,6 +92,11 @@
 
 .. option:: UseAssignment
 
+   Note: this option is deprecated, to be removed in :program:`clang-tidy`
+   version 19. Please use the `UseAssignment` option from
+   `cppcoreguidelines-use-default-member-init <../cppcoreguidelines/use-default-member-init.html>`_
+   instead.
+
If this option is set to `true` (by default `UseAssignment` from
`modernize-use-default-member-init
<../modernize/use-default-member-init.html>`_ will be used),
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -174,6 +174,11 @@
   ` to :doc:`bugprone-unsafe-functions
   ` was added.
 
+- New alias :doc:`cppcoreguidelines-use-default-member-init
+  ` to
+  :doc:`modernize-use-default-member-init
+  ` was added.
+
 Changes in existing checks
 ^^
 - Improved :doc:`readability-redundant-string-cstr
@@ -215,6 +220,11 @@
 - Deprecated :doc:`cert-dcl21-cpp
   ` check.
 
+- Deprecated C.48 enforcement from :doc:`cppcoreguidelines-prefer-member-initializer
+  `. Please use
+  :doc:`cppcoreguidelines-use-default-member-init
+  ` instead.
+
 - Deprecated check-local options `HeaderFileExtensions`
   in :doc:`google-build-namespaces
   ` check.
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
@@ -12,6 +12,7 @@
 #include "../misc/NonPrivateMemberVariablesInClassesCheck.h"
 #include "../misc/UnconventionalAssignOperatorCheck.h"
 #include "../modernize/AvoidCArraysCheck.h"
+#include "../modernize/UseDefaultMemberInitCheck.h"
 #include "../modernize/UseOverrideCheck.h"
 #include 

[PATCH] D148460: [clang-tidy] Add alias cppcoreguidelines-use-default-member-init

2023-04-16 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 513992.
carlosgalvezp added a comment.

Revert code removal, document deprecation notice instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148460

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-default-member-init.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst

Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -207,6 +207,7 @@
`cppcoreguidelines-rvalue-reference-param-not-moved `_,
`cppcoreguidelines-slicing `_,
`cppcoreguidelines-special-member-functions `_,
+   `cppcoreguidelines-use-default-member-init `_, "Yes"
`cppcoreguidelines-virtual-class-destructor `_, "Yes"
`darwin-avoid-spinlock `_,
`darwin-dispatch-once-nonstatic `_, "Yes"
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-default-member-init.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/use-default-member-init.rst
@@ -0,0 +1,12 @@
+.. title:: clang-tidy - cppcoreguidelines-use-default-member-init
+.. meta::
+   :http-equiv=refresh: 5;URL=../modernize/use-default-member-init.html
+
+cppcoreguidelines-use-default-member-init
+=
+
+This check implements `C.48 `_ from the CppCoreGuidelines.
+
+The cppcoreguidelines-use-default-member-init check is an alias, please see
+`modernize-use-default-member-init <../modernize/use-default-member-init.html>`_
+for more information.
Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
@@ -23,6 +23,13 @@
 initializations already implemented as member initializers. For that purpose
 see check `modernize-use-default-member-init <../modernize/use-default-member-init.html>`_.
 
+.. note::
+
+  Enforcement of rule C.48 in this check is deprecated, to be removed in
+  :program:`clang-tidy` version 19 (only C.49 will be enforced by this check then).
+  Please use `cppcoreguidelines-use-default-member-init <../cppcoreguidelines/use-default-member-init.html>`_
+  to enfoce rule C.48.
+
 Example 1
 -
 
@@ -85,6 +92,11 @@
 
 .. option:: UseAssignment
 
+   Note: this option is deprecated, to be removed in :program:`clang-tidy`
+   version 19. Please use the `UseAssignment` option from
+   `cppcoreguidelines-use-default-member-init <../cppcoreguidelines/use-default-member-init.html>`_
+   instead.
+
If this option is set to `true` (default is `false`), the check will initialize
members with an assignment. In this case the fix of the first example looks
like this:
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -174,6 +174,11 @@
   ` to :doc:`bugprone-unsafe-functions
   ` was added.
 
+- New alias :doc:`cppcoreguidelines-use-default-member-init
+  ` to
+  :doc:`modernize-use-default-member-init
+  ` was added.
+
 Changes in existing checks
 ^^
 - Improved :doc:`readability-redundant-string-cstr
@@ -215,6 +220,11 @@
 - Deprecated :doc:`cert-dcl21-cpp
   ` check.
 
+- Deprecated C.48 enforcement from :doc:`cppcoreguidelines-prefer-member-initializer
+  `. Please use
+  :doc:`cppcoreguidelines-use-default-member-init
+  ` instead.
+
 - Deprecated check-local options `HeaderFileExtensions`
   in :doc:`google-build-namespaces
   ` check.
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
@@ -12,6 +12,7 @@
 #include "../misc/NonPrivateMemberVariablesInClassesCheck.h"
 #include "../misc/UnconventionalAssignOperatorCheck.h"
 #include "../modernize/AvoidCArraysCheck.h"
+#include "../modernize/UseDefaultMemberInitCheck.h"
 #include 

[PATCH] D148444: [clang-tidy] Prevent `llvmlibc-inline-function-decl` triggering on lambdas

2023-04-16 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 513990.
jhuber6 added a comment.

Add test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148444

Files:
  clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
===
--- clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
@@ -60,6 +60,14 @@
   }
 };
 
+LIBC_INLINE void lambda() {
+// CHECK-MESSAGES-NOT: :[[@LINE+4]]:3: warning: '__invoke' must be tagged with 
the LIBC_INLINE macro; the macro should be placed at the beginning of the 
declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+3]]:3: warning: 'operator void (*)()' must be 
tagged with the LIBC_INLINE macro; the macro should be placed at the beginning 
of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+2]]:3: warning: '~(lambda at [[FILENAME:.+]])' 
must be tagged with the LIBC_INLINE macro; the macro should be placed at the 
beginning of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+1]]:6: warning: 'operator()' must be tagged 
with the LIBC_INLINE macro; the macro should be placed at the beginning of the 
declaration [llvmlibc-inline-function-decl]
+  [](){};
+}
+
 } // namespace __llvm_libc
 
 #endif // 
LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_LLVMLIBC_INLINEFUNCTIONDECL_H
Index: clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
===
--- clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
+++ clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
@@ -39,6 +39,11 @@
 HeaderFileExtensions))
 return;
 
+  // Consider only functions with an external and visible declaration.
+  if (const auto *MethodDecl = dyn_cast(FuncDecl))
+if (MethodDecl->getParent()->isLambda())
+  return;
+
   // Check if decl starts with LIBC_INLINE
   auto Loc = FullSourceLoc(Result.SourceManager->getFileLoc(SrcBegin),
*Result.SourceManager);


Index: clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
===
--- clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
+++ clang-tools-extra/test/clang-tidy/checkers/llvmlibc/inline-function-decl.hpp
@@ -60,6 +60,14 @@
   }
 };
 
+LIBC_INLINE void lambda() {
+// CHECK-MESSAGES-NOT: :[[@LINE+4]]:3: warning: '__invoke' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+3]]:3: warning: 'operator void (*)()' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+2]]:3: warning: '~(lambda at [[FILENAME:.+]])' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+// CHECK-MESSAGES-NOT: :[[@LINE+1]]:6: warning: 'operator()' must be tagged with the LIBC_INLINE macro; the macro should be placed at the beginning of the declaration [llvmlibc-inline-function-decl]
+  [](){};
+}
+
 } // namespace __llvm_libc
 
 #endif // LLVM_CLANG_TOOLS_EXTRA_TEST_CLANG_TIDY_CHECKERS_LLVMLIBC_INLINEFUNCTIONDECL_H
Index: clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
===
--- clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
+++ clang-tools-extra/clang-tidy/llvmlibc/InlineFunctionDeclCheck.cpp
@@ -39,6 +39,11 @@
 HeaderFileExtensions))
 return;
 
+  // Consider only functions with an external and visible declaration.
+  if (const auto *MethodDecl = dyn_cast(FuncDecl))
+if (MethodDecl->getParent()->isLambda())
+  return;
+
   // Check if decl starts with LIBC_INLINE
   auto Loc = FullSourceLoc(Result.SourceManager->getFileLoc(SrcBegin),
*Result.SourceManager);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148410: [Parse] Remove TimeTraceScope for "ParseTemplate"

2023-04-16 Thread Anton Afanasyev via Phabricator via cfe-commits
anton-afanasyev accepted this revision.
anton-afanasyev added a comment.
This revision is now accepted and ready to land.

Ok, let's remove it for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148410

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


[PATCH] D148462: [clang-tidy] Ignore declarations in bugprone-exception-escape

2023-04-16 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL created this revision.
PiotrZSL added reviewers: njames93, carlosgalvezp.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Warnings will now only be printed for function definitions, not declarations


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148462

Files:
  clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
@@ -651,7 +651,6 @@
 }
 
 int indirectly_recursive(int n) noexcept;
-  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: an exception may be thrown in 
function 'indirectly_recursive' which should not throw exceptions
 
 int recursion_helper(int n) {
   indirectly_recursive(n);
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -191,6 +191,10 @@
   ` check.
   Global options of the same name should be used instead.
 
+- Improved :doc:`bugprone-exception-escape
+  ` to not emit warnings for
+  forward declarations of functions.
+
 - Improved :doc:`bugprone-fold-init-type
   ` to handle iterators that do not
   define `value_type` type aliases.
Index: clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
@@ -52,7 +52,8 @@
 
 void ExceptionEscapeCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  functionDecl(anyOf(isNoThrow(), cxxDestructorDecl(),
+  functionDecl(isDefinition(),
+   anyOf(isNoThrow(), cxxDestructorDecl(),
  cxxConstructorDecl(isMoveConstructor()),
  cxxMethodDecl(isMoveAssignmentOperator()),
  hasName("main"), hasName("swap"),


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
@@ -651,7 +651,6 @@
 }
 
 int indirectly_recursive(int n) noexcept;
-  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: an exception may be thrown in function 'indirectly_recursive' which should not throw exceptions
 
 int recursion_helper(int n) {
   indirectly_recursive(n);
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -191,6 +191,10 @@
   ` check.
   Global options of the same name should be used instead.
 
+- Improved :doc:`bugprone-exception-escape
+  ` to not emit warnings for
+  forward declarations of functions.
+
 - Improved :doc:`bugprone-fold-init-type
   ` to handle iterators that do not
   define `value_type` type aliases.
Index: clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
@@ -52,7 +52,8 @@
 
 void ExceptionEscapeCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  functionDecl(anyOf(isNoThrow(), cxxDestructorDecl(),
+  functionDecl(isDefinition(),
+   anyOf(isNoThrow(), cxxDestructorDecl(),
  cxxConstructorDecl(isMoveConstructor()),
  cxxMethodDecl(isMoveAssignmentOperator()),
  hasName("main"), hasName("swap"),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >