[PATCH] D148437: [clang-format] Dont interpret variable named interface as keyword for C++

2023-04-16 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo updated this revision to Diff 513969.
sousajo added a comment.

- rebased


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

https://reviews.llvm.org/D148437

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25429,6 +25429,13 @@
   verifyFormat("auto x = 5s .count() == 5;");
 }
 
+TEST_F(FormatTest, InterfaceAsClassMemberName) {
+  verifyFormat("class Foo {\n"
+   "  int interface;\n"
+   "  Foo::Foo(int iface) : interface{iface} {}\n"
+   "}");
+}
+
 } // namespace
 } // namespace test
 } // namespace format
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1881,7 +1881,7 @@
 }
   }
 
-  if (FormatTok->is(Keywords.kw_interface)) {
+  if (!Style.isCpp() && FormatTok->is(Keywords.kw_interface)) {
 if (parseStructLike())
   return;
 break;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25429,6 +25429,13 @@
   verifyFormat("auto x = 5s .count() == 5;");
 }
 
+TEST_F(FormatTest, InterfaceAsClassMemberName) {
+  verifyFormat("class Foo {\n"
+   "  int interface;\n"
+   "  Foo::Foo(int iface) : interface{iface} {}\n"
+   "}");
+}
+
 } // namespace
 } // namespace test
 } // namespace format
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1881,7 +1881,7 @@
 }
   }
 
-  if (FormatTok->is(Keywords.kw_interface)) {
+  if (!Style.isCpp() && FormatTok->is(Keywords.kw_interface)) {
 if (parseStructLike())
   return;
 break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146809: [WIP][clang-repl] Implement Value pretty printing

2023-04-16 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 513971.
junaire added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146809

Files:
  clang/include/clang/Interpreter/Interpreter.h
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/__clang_interpreter_runtime_printvalue.h
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalExecutor.cpp
  clang/lib/Interpreter/IncrementalExecutor.h
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/InterpreterUtils.cpp
  clang/lib/Interpreter/InterpreterUtils.h
  clang/lib/Interpreter/Value.cpp
  clang/lib/Interpreter/ValuePrinter.cpp
  clang/test/Interpreter/pretty-print.cpp

Index: clang/test/Interpreter/pretty-print.cpp
===
--- /dev/null
+++ clang/test/Interpreter/pretty-print.cpp
@@ -0,0 +1,51 @@
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+char c = 'a';
+c
+// CHECK: (char) 'a'
+
+int x = 42;
+x
+// CHECK-NEXT: (int) 42
+
+x - 2
+// CHECK-NEXT: (int) 40
+
+float f = 4.2f;
+f
+// CHECK-NEXT: (float) 4.2f
+
+double d = 4.21;
+d
+// CHECK-NEXT: (double) 4.210
+
+struct S{};
+S s;
+s
+// CHECK-NEXT: (S &) [[Addr:@0x.*]]
+
+S{}
+// CHECK-NEXT: (S) [[Addr:@0x.*]]
+
+struct SS { int* p; SS() { p = new int(42); } ~SS() { delete p; } };
+SS{}
+// CHECK-NEXT: (SS) [[Addr:@0x.*]]
+SS ss;
+ss
+// CHECK-NEXT: (SS &) [[Addr:@0x.*]]
+
+int arr[3] = {1,2,3};
+arr
+// CHECK-NEXT: (int[3]) { 1, 2, 3 }
+
+#include 
+
+auto p1 = std::make_shared(42);
+p1
+// CHECK-NEXT: (shared_ptr &) std::shared_ptr -> [[Addr:@0x.*]]
+
+%quit
+
Index: clang/lib/Interpreter/ValuePrinter.cpp
===
--- /dev/null
+++ clang/lib/Interpreter/ValuePrinter.cpp
@@ -0,0 +1,506 @@
+#include "InterpreterUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/PrettyPrinter.h"
+#include "clang/AST/Type.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Interpreter/Interpreter.h"
+#include "clang/Interpreter/Value.h"
+#include "clang/Parse/Parser.h"
+#include "clang/Sema/Lookup.h"
+#include "clang/Sema/Sema.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+#include 
+
+using namespace clang;
+
+namespace rep_runtime_internal {
+REPL_EXTERNAL_VISIBILITY
+extern const char *const kEmptyCollection = "{}";
+} // namespace rep_runtime_internal
+
+static std::string PrintDeclType(const QualType &QT, NamedDecl *D) {
+  std::string Str;
+  llvm::raw_string_ostream SS(Str);
+  if (QT.hasQualifiers())
+SS << QT.getQualifiers().getAsString() << " ";
+  SS << D->getQualifiedNameAsString();
+  return Str;
+}
+
+static std::string PrintQualType(ASTContext &Ctx, QualType QT) {
+  std::string Str;
+  llvm::raw_string_ostream SS(Str);
+  PrintingPolicy Policy(Ctx.getPrintingPolicy());
+  // Print the Allocator in STL containers, for instance.
+  Policy.SuppressDefaultTemplateArgs = false;
+  Policy.SuppressUnwrittenScope = true;
+  // Print 'a >' rather than 'a>'.
+  Policy.SplitTemplateClosers = true;
+
+  struct LocalPrintingPolicyRAII {
+ASTContext &Context;
+PrintingPolicy Policy;
+
+LocalPrintingPolicyRAII(ASTContext &Ctx, PrintingPolicy &PP)
+: Context(Ctx), Policy(Ctx.getPrintingPolicy()) {
+  Context.setPrintingPolicy(PP);
+}
+~LocalPrintingPolicyRAII() { Context.setPrintingPolicy(Policy); }
+  } X(Ctx, Policy);
+
+  const QualType NonRefTy = QT.getNonReferenceType();
+
+  if (const auto *TTy = llvm::dyn_cast(NonRefTy))
+SS << PrintDeclType(NonRefTy, TTy->getDecl());
+  else if (const auto *TRy = dyn_cast(NonRefTy))
+SS << PrintDeclType(NonRefTy, TRy->getDecl());
+  else {
+const QualType Canon = NonRefTy.getCanonicalType();
+if (Canon->isBuiltinType() && !NonRefTy->isFunctionPointerType() &&
+!NonRefTy->isMemberPointerType()) {
+  SS << Canon.getAsString(Ctx.getPrintingPolicy());
+} else if (const auto *TDTy = dyn_cast(NonRefTy)) {
+  // FIXME: TemplateSpecializationType & SubstTemplateTypeParmType checks
+  // are predominately to get STL containers to print nicer and might be
+  // better handled in GetFullyQualifiedName.
+  //
+  // std::vector::iterator is a TemplateSpecializationType
+  // std::vector::value_type is a SubstTemplateTypeParmType
+  //
+  QualType SSDesugar = TDTy->getLocallyUnqualifiedSingleStepDesugaredType();
+  if (llvm::isa(SSDesugar))
+SS << GetFullTypeName(Ctx, Canon);
+  else if (llvm::isa(SSDesugar))
+SS << GetFullTypeName(Ctx, NonRefTy);
+  else
+SS << PrintDeclType(NonRe

[PATCH] D144036: [clang-tidy] Add bugprone-non-zero-enum-to-bool-conversion check

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

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144036

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone/non-zero-enum-to-bool-conversion.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion-cpp11.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion.cpp
@@ -0,0 +1,107 @@
+// RUN: %check_clang_tidy -std=c++98-or-later %s bugprone-non-zero-enum-to-bool-conversion %t -- \
+// RUN:   -config="{CheckOptions: [{key: bugprone-non-zero-enum-to-bool-conversion.EnumIgnoreList, value: '::without::issue::IgnoredEnum;IgnoredSecondEnum'}]}"
+
+namespace with::issue {
+
+typedef enum EStatus {
+  SUCCESS   = 1,
+  FAILURE   = 2,
+  INVALID_PARAM = 3,
+  UNKNOWN   = 4
+} Status;
+
+bool testEnumConversion(EStatus value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  return value;
+}
+
+bool testTypedefConversion(Status value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  return value;
+}
+
+bool testExplicitConversion(EStatus value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:28: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  return static_cast(value);
+}
+
+bool testInIfConversion(EStatus value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:7: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  if (value) {
+return false;
+  }
+  return true;
+}
+
+bool testWithNegation(EStatus value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:14: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  return not value;
+}
+
+}
+
+namespace without::issue {
+
+enum StatusWithZero {
+  UNK  = 0,
+  OK   = 1,
+  NOT_OK = 2
+};
+
+bool testEnumConversion(StatusWithZero value) {
+  return value;
+}
+
+enum WithDefault {
+  Value0,
+  Value1
+};
+
+bool testEnumConversion(WithDefault value) {
+  return value;
+}
+
+enum WithNegative : int {
+  Nen2 = -2,
+  Nen1,
+  Nen0
+};
+
+bool testEnumConversion(WithNegative value) {
+  return value;
+}
+
+enum EStatus {
+  SUCCESS = 1,
+  FAILURE,
+  INVALID_PARAM,
+  UNKNOWN
+};
+
+bool explicitCompare(EStatus value) {
+  return value == SUCCESS;
+}
+
+bool testEnumeratorCompare() {
+  return SUCCESS;
+}
+
+enum IgnoredEnum {
+  IGNORED_VALUE_1 = 1,
+  IGNORED_VALUE_2
+};
+
+enum IgnoredSecondEnum {
+  IGNORED_SECOND_VALUE_1 = 1,
+  IGNORED_SECOND_VALUE_2
+};
+
+bool testIgnored(IgnoredEnum value) {
+  return value;
+}
+
+bool testIgnored(IgnoredSecondEnum value) {
+  return value;
+}
+
+}
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion-cpp11.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion-cpp11.cpp
@@ -0,0 +1,110 @@
+// RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-non-zero-enum-to-bool-conversion %t
+
+namespace with::issue {
+
+enum class EStatusC : char {
+  SUCCESS   = 1,
+  FAILURE   = 2,
+  INVALID_PARAM = 3,
+  UNKNOWN   = 4
+};
+
+bool testEnumConversion(EStatusC value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EStatusC' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  return static_cast(value);
+}
+
+enum class EStatusS : short {
+  SUCCESS   = 1,
+  FAILURE   = 2,
+  INVALID_PARAM = 3,
+  UNKNOWN   = 4
+};
+
+bool testEnumConversion(EStatusS value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EStatusS' into 'bool' will always return 'true', enum doesn't have a zero-value enum

[clang-tools-extra] 4bac5f8 - Apply fixes from performance-faster-string-find (NFC)

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

Author: Kazu Hirata
Date: 2023-04-16T00:51:27-07:00
New Revision: 4bac5f8344ea6405e3964141c8f591c68eefd373

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

LOG: Apply fixes from performance-faster-string-find (NFC)

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
flang/lib/Semantics/check-io.cpp
lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp
llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index eeb0642baa100..9561b2b00904f 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -337,10 +337,10 @@ std::string 
IdentifierNamingCheck::HungarianNotation::getDeclTypeName(
 Type.replace(Pos, Kw.size(), "");
   }
 }
-TypeName = Type.erase(0, Type.find_first_not_of(" "));
+TypeName = Type.erase(0, Type.find_first_not_of(' '));
 
 // Remove template parameters
-const size_t Pos = Type.find("<");
+const size_t Pos = Type.find('<');
 if (Pos != std::string::npos) {
   TypeName = Type.erase(Pos, Type.size() - Pos);
 }
@@ -377,14 +377,14 @@ std::string 
IdentifierNamingCheck::HungarianNotation::getDeclTypeName(
   }
 }
 
-TypeName = Type.erase(0, Type.find_first_not_of(" "));
+TypeName = Type.erase(0, Type.find_first_not_of(' '));
 if (!RedundantRemoved) {
-  std::size_t FoundSpace = Type.find(" ");
+  std::size_t FoundSpace = Type.find(' ');
   if (FoundSpace != std::string::npos)
 Type = Type.substr(0, FoundSpace);
 }
 
-TypeName = Type.erase(0, Type.find_first_not_of(" "));
+TypeName = Type.erase(0, Type.find_first_not_of(' '));
 
 QualType QT = VD->getType();
 if (!QT.isNull() && QT->isArrayType())
@@ -586,7 +586,7 @@ std::string 
IdentifierNamingCheck::HungarianNotation::getDataTypePrefix(
   if (PrefixStr.empty())
 PrefixStr = HNOption.DerivedType.lookup("Array");
 } else if (QT->isReferenceType()) {
-  size_t Pos = ModifiedTypeName.find_last_of("&");
+  size_t Pos = ModifiedTypeName.find_last_of('&');
   if (Pos != std::string::npos)
 ModifiedTypeName = ModifiedTypeName.substr(0, Pos);
 }
@@ -653,7 +653,7 @@ std::string 
IdentifierNamingCheck::HungarianNotation::getEnumPrefix(
   std::string Name = ED->getName().str();
   if (std::string::npos != Name.find("enum")) {
 Name = Name.substr(strlen("enum"), Name.length() - strlen("enum"));
-Name = Name.erase(0, Name.find_first_not_of(" "));
+Name = Name.erase(0, Name.find_first_not_of(' '));
   }
 
   static llvm::Regex Splitter(

diff  --git a/flang/lib/Semantics/check-io.cpp 
b/flang/lib/Semantics/check-io.cpp
index 6df5eadc8ae62..1c1b07c422bac 100644
--- a/flang/lib/Semantics/check-io.cpp
+++ b/flang/lib/Semantics/check-io.cpp
@@ -101,7 +101,7 @@ void IoChecker::Enter(const parser::ConnectSpec &spec) {
 // Ignore trailing spaces (12.5.6.2 p1) and convert to upper case
 static std::string Normalize(const std::string &value) {
   auto upper{parser::ToUpperCaseLetters(value)};
-  std::size_t lastNonBlank{upper.find_last_not_of(" ")};
+  std::size_t lastNonBlank{upper.find_last_not_of(' ')};
   upper.resize(lastNonBlank == std::string::npos ? 0 : lastNonBlank + 1);
   return upper;
 }

diff  --git a/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp 
b/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp
index 277fec9f7116e..a38b75c9e615f 100644
--- a/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp
+++ b/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp
@@ -81,7 +81,7 @@ static std::optional GetCGroupFileDescriptor(lldb::pid_t 
pid) {
 if (line.find("0:") != 0)
   continue;
 
-std::string slice = line.substr(line.find_first_of("/"));
+std::string slice = line.substr(line.find_first_of('/'));
 if (slice.empty())
   return std::nullopt;
 std::string cgroup_file = formatv("/sys/fs/cgroup/{0}", slice);

diff  --git a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp 
b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
index bfa748e7a6950..ccb7a37c83d54 100644
--- a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
@@ -1256,7 +1256,7 @@ void DataFlowSanitizer::addGlobalNameSuffix(GlobalValue 
*GV) {
   size_t Pos = Asm.find(SearchStr);
   if (Pos != std::string::npos) {
 Asm.replace(Pos, SearchStr.size(), ".symver " + GVName + Suffix + ",");
-Pos = Asm.find("@");
+Pos = Asm.find('@');
 
 if (Pos == std::strin

[clang-tools-extra] 3bf322e - [clang-tidy] Add bugprone-non-zero-enum-to-bool-conversion check

2023-04-16 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-04-16T08:51:00Z
New Revision: 3bf322e69d5cb8c74c71d55d00caad7c95c5270b

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

LOG: [clang-tidy] Add bugprone-non-zero-enum-to-bool-conversion check

Detect implicit and explicit conversions of enum to bool,
when enum doesn't have a enumerator with value equal to 0.
In theory such conversion should always return TRUE.

Reviewed By: carlosgalvezp

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

Added: 
clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp
clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.h

clang-tools-extra/docs/clang-tidy/checks/bugprone/non-zero-enum-to-bool-conversion.rst

clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion-cpp11.cpp

clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion.cpp

Modified: 
clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 11b4051668cef..60666287cf307 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -38,6 +38,7 @@
 #include "MoveForwardingReferenceCheck.h"
 #include "MultipleStatementMacroCheck.h"
 #include "NoEscapeCheck.h"
+#include "NonZeroEnumToBoolConversionCheck.h"
 #include "NotNullTerminatedResultCheck.h"
 #include "ParentVirtualCallCheck.h"
 #include "PosixReturnCheck.h"
@@ -139,6 +140,8 @@ class BugproneModule : public ClangTidyModule {
 CheckFactories.registerCheck(
 "bugprone-narrowing-conversions");
 CheckFactories.registerCheck("bugprone-no-escape");
+CheckFactories.registerCheck(
+"bugprone-non-zero-enum-to-bool-conversion");
 CheckFactories.registerCheck(
 "bugprone-not-null-terminated-result");
 CheckFactories.registerCheck(

diff  --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index a975c86fc3970..5af5a59e5340f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -33,17 +33,18 @@ add_clang_library(clangTidyBugproneModule
   MoveForwardingReferenceCheck.cpp
   MultipleStatementMacroCheck.cpp
   NoEscapeCheck.cpp
+  NonZeroEnumToBoolConversionCheck.cpp
   NotNullTerminatedResultCheck.cpp
   ParentVirtualCallCheck.cpp
   PosixReturnCheck.cpp
   RedundantBranchConditionCheck.cpp
   ReservedIdentifierCheck.cpp
   SharedPtrArrayMismatchCheck.cpp
-  SmartPtrArrayMismatchCheck.cpp
   SignalHandlerCheck.cpp
   SignedCharMisuseCheck.cpp
   SizeofContainerCheck.cpp
   SizeofExpressionCheck.cpp
+  SmartPtrArrayMismatchCheck.cpp
   SpuriouslyWakeUpFunctionsCheck.cpp
   StandaloneEmptyCheck.cpp
   StringConstructorCheck.cpp

diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp
new file mode 100644
index 0..a59c4fc47c0b4
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp
@@ -0,0 +1,78 @@
+//===--- NonZeroEnumToBoolConversionCheck.cpp - clang-tidy 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "NonZeroEnumToBoolConversionCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+
+AST_MATCHER(EnumDecl, isCompleteAndHasNoZeroValue) {
+  const EnumDecl *Definition = Node.getDefinition();
+  return Definition && Node.isComplete() &&
+ std::none_of(Definition->enumerator_begin(),
+  Definition->enumerator_end(),
+  [](const EnumConstantDecl *Value) {
+return Value->getInitVal().isZero();
+  });
+}
+
+} // namespace
+
+NonZeroEnumToBoolConversionCheck::NonZeroEnumToBoolConversionCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  EnumIgnoreList(
+

[PATCH] D144036: [clang-tidy] Add bugprone-non-zero-enum-to-bool-conversion check

2023-04-16 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3bf322e69d5c: [clang-tidy] Add 
bugprone-non-zero-enum-to-bool-conversion check (authored by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144036

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/bugprone/non-zero-enum-to-bool-conversion.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion-cpp11.cpp
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion.cpp
@@ -0,0 +1,107 @@
+// RUN: %check_clang_tidy -std=c++98-or-later %s bugprone-non-zero-enum-to-bool-conversion %t -- \
+// RUN:   -config="{CheckOptions: [{key: bugprone-non-zero-enum-to-bool-conversion.EnumIgnoreList, value: '::without::issue::IgnoredEnum;IgnoredSecondEnum'}]}"
+
+namespace with::issue {
+
+typedef enum EStatus {
+  SUCCESS   = 1,
+  FAILURE   = 2,
+  INVALID_PARAM = 3,
+  UNKNOWN   = 4
+} Status;
+
+bool testEnumConversion(EStatus value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  return value;
+}
+
+bool testTypedefConversion(Status value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  return value;
+}
+
+bool testExplicitConversion(EStatus value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:28: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  return static_cast(value);
+}
+
+bool testInIfConversion(EStatus value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:7: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  if (value) {
+return false;
+  }
+  return true;
+}
+
+bool testWithNegation(EStatus value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:14: warning: conversion of 'EStatus' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  return not value;
+}
+
+}
+
+namespace without::issue {
+
+enum StatusWithZero {
+  UNK  = 0,
+  OK   = 1,
+  NOT_OK = 2
+};
+
+bool testEnumConversion(StatusWithZero value) {
+  return value;
+}
+
+enum WithDefault {
+  Value0,
+  Value1
+};
+
+bool testEnumConversion(WithDefault value) {
+  return value;
+}
+
+enum WithNegative : int {
+  Nen2 = -2,
+  Nen1,
+  Nen0
+};
+
+bool testEnumConversion(WithNegative value) {
+  return value;
+}
+
+enum EStatus {
+  SUCCESS = 1,
+  FAILURE,
+  INVALID_PARAM,
+  UNKNOWN
+};
+
+bool explicitCompare(EStatus value) {
+  return value == SUCCESS;
+}
+
+bool testEnumeratorCompare() {
+  return SUCCESS;
+}
+
+enum IgnoredEnum {
+  IGNORED_VALUE_1 = 1,
+  IGNORED_VALUE_2
+};
+
+enum IgnoredSecondEnum {
+  IGNORED_SECOND_VALUE_1 = 1,
+  IGNORED_SECOND_VALUE_2
+};
+
+bool testIgnored(IgnoredEnum value) {
+  return value;
+}
+
+bool testIgnored(IgnoredSecondEnum value) {
+  return value;
+}
+
+}
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion-cpp11.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion-cpp11.cpp
@@ -0,0 +1,110 @@
+// RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-non-zero-enum-to-bool-conversion %t
+
+namespace with::issue {
+
+enum class EStatusC : char {
+  SUCCESS   = 1,
+  FAILURE   = 2,
+  INVALID_PARAM = 3,
+  UNKNOWN   = 4
+};
+
+bool testEnumConversion(EStatusC value) {
+  // CHECK-MESSAGES: :[[@LINE+1]]:10: warning: conversion of 'EStatusC' into 'bool' will always return 'true', enum doesn't have a zero-value enumerator [bugprone-non-zero-enum-to-bool-conversion]
+  return static_cast(value);
+}
+
+enum class EStatusS : short {
+  SUCCESS   = 1,
+  FAILURE   = 2,
+  INVALID_PARAM = 3,
+  UNKNOWN   = 4
+};
+
+bool testEnumConversion(EStatusS value) {
+  // CHECK-MESSAGES: :[[@LINE+1

[PATCH] D147929: [clang-tidy] Fix handling of UseAssignment option in cppcoreguidelines-prefer-member-initializer

2023-04-16 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added a subscriber: aaron.ballman.
carlosgalvezp added inline comments.
This revision is now accepted and ready to land.



Comment at: 
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp:134
+  Options.get("UseAssignment",
+  OptionsView("modernize-use-default-member-init",
+  Context->getOptions().CheckOptions, Context)

PiotrZSL wrote:
> carlosgalvezp wrote:
> > This is very strange, feels like it's done to ensure the checks are in sync 
> > but IMO it creates more harm than good and makes the check harder to 
> > maintain. The checks are independent anyway (not aliases), so I believe it 
> > makes sense to keep being independent also in the options.
> > 
> > There are similar checks (e.g. magic numbers) where the user needs to 
> > either only enable one of the checks, or enter the same configuration 
> > settings twice.
> > 
> > I would vote for just treating this like an independent argument like all 
> > other checks, to avoid bugs like these.
> So remove dependency on modernize-use-default-member-init completly, or just 
> on modernize-use-default-member-init options ?
I had a look at the original patch:

https://reviews.llvm.org/D71199

There's quite some discussion about the topic, and reviewers like 
@aaron.ballman weren't very happy about introducing this coupling. Seems like 
the problem is non-trivial so I vote for leaving your patch as is, which fixes 
a Github ticket and brings value, and think about completely removing the 
dependency to modernize-use-default-member-init on a separate patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147929

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


[PATCH] D148437: [clang-format] Dont interpret variable named interface as keyword for C++

2023-04-16 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo added a comment.

cannot reproduce the build failure locally. if this looks fine can someone land 
it for me? or should we wait until we have a green build after rebase?


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

https://reviews.llvm.org/D148437

___
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 created this revision.
Herald added subscribers: carlosgalvezp, 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.

Split tests files into noexcept and throw().
This is preparation for a C++20 support in this check.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148458

Files:
  clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-throw.cpp
  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
@@ -32,11 +32,6 @@
   throw 1;
 }
 
-void throwing_throw_nothing() throw() {
-// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throwing_throw_nothing' which should not throw exceptions
-  throw 1;
-}
-
 void throw_and_catch() noexcept {
   // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_and_catch' which should not throw exceptions
   try {
@@ -157,7 +152,7 @@
 }
 
 // FIXME: In this case 'a' is convertible to the handler and should be caught
-// but in reality it's thrown. Note that clang doesn't report a warning for 
+// but in reality it's thrown. Note that clang doesn't report a warning for
 // this either.
 void throw_catch_multi_ptr_5() noexcept {
   try {
@@ -254,7 +249,7 @@
 void throw_derived_catch_base_ptr_c() noexcept {
   try {
 derived d;
-throw &d; 
+throw &d;
   } catch(const base *) {
   }
 }
@@ -264,7 +259,7 @@
   try {
 derived d;
 const derived *p = &d;
-throw p; 
+throw p;
   } catch(base *) {
   }
 }
@@ -287,7 +282,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_private' which should not throw exceptions
   try {
 B b;
-throw b; 
+throw b;
   } catch(A) {
   }
 }
@@ -296,7 +291,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_private_ptr' which should not throw exceptions
   try {
 B b;
-throw &b; 
+throw &b;
   } catch(A *) {
   }
 }
@@ -305,7 +300,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_protected' which should not throw exceptions
   try {
 C c;
-throw c; 
+throw c;
   } catch(A) {
   }
 }
@@ -314,7 +309,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_protected_ptr' which should not throw exceptions
   try {
 C c;
-throw &c; 
+throw &c;
   } catch(A *) {
   }
 }
@@ -323,7 +318,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_ambiguous' which should not throw exceptions
   try {
 E e;
-throw e; 
+throw e;
   } catch(A) {
   }
 }
@@ -332,7 +327,7 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_ambiguous_ptr' which should not throw exceptions
   try {
 E e;
-throw e; 
+throw e;
   } catch(A) {
   }
 }
@@ -557,7 +552,9 @@
   throw 1;
 }
 
-void explicit_int_thrower() throw(int);
+void explicit_int_thrower() noexcept(false) {
+  throw 1;
+}
 
 void indirect_implicit() noexcept {
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'indirect_implicit' which should not throw exceptions
@@ -677,15 +674,6 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: an exception may be thrown in function 'sub_throws' which should not throw exceptions
 };
 
-struct super_throws_again {
-  super_throws_again() throw(int);
-};
-
-struct sub_throws_again : super_throws_again {
-  sub_throws_again() noexcept : super_throws_again() {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: an exception may be thrown in function 'sub_throws_again' which should not throw exceptions
-};
-
 struct init_member_throws {
   super_throws s;
 
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-throw.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-throw.cpp
@@ -0,0 +1,31 @@
+// RUN: %check_clang_tidy -std=c++11,c++14 %s bugprone-exception-escape %t -- -- -fexceptions
+
+void throwing_throw_nothing() throw() {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throwing_throw_nothing' which should not throw exceptions
+  throw 1;
+}
+
+void explicit_int_thrower() throw(int);
+
+void implicit_int_thrower() {
+throw 5;
+}
+
+void indirect_implicit() throw() {
+// CHECK-MESSA

[clang] 9db2a04 - [clang-format] Dont interpret variable named interface as keyword for C++

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

Author: Jorge Pinto Sousa
Date: 2023-04-16T03:23:53-07:00
New Revision: 9db2a0454815979bc8e0f65e830ab9051b4ff5d2

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

LOG: [clang-format] Dont interpret variable named interface as keyword for C++

Fixes #53173.

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index e47d6342357cb..9158333911ae2 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1881,7 +1881,7 @@ void UnwrappedLineParser::parseStructuralElement(
 }
   }
 
-  if (FormatTok->is(Keywords.kw_interface)) {
+  if (!Style.isCpp() && FormatTok->is(Keywords.kw_interface)) {
 if (parseStructLike())
   return;
 break;

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 4b7fdddfdf7a0..c5c1f2150d3b1 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -25429,6 +25429,13 @@ TEST_F(FormatTest, SpaceAfterUDL) {
   verifyFormat("auto x = 5s .count() == 5;");
 }
 
+TEST_F(FormatTest, InterfaceAsClassMemberName) {
+  verifyFormat("class Foo {\n"
+   "  int interface;\n"
+   "  Foo::Foo(int iface) : interface{iface} {}\n"
+   "}");
+}
+
 } // namespace
 } // namespace test
 } // namespace format



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


[PATCH] D148437: [clang-format] Dont interpret variable named interface as keyword for C++

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 rG9db2a0454815: [clang-format] Dont interpret variable named 
interface as keyword for C++ (authored by sousajo, committed by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148437

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25429,6 +25429,13 @@
   verifyFormat("auto x = 5s .count() == 5;");
 }
 
+TEST_F(FormatTest, InterfaceAsClassMemberName) {
+  verifyFormat("class Foo {\n"
+   "  int interface;\n"
+   "  Foo::Foo(int iface) : interface{iface} {}\n"
+   "}");
+}
+
 } // namespace
 } // namespace test
 } // namespace format
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1881,7 +1881,7 @@
 }
   }
 
-  if (FormatTok->is(Keywords.kw_interface)) {
+  if (!Style.isCpp() && FormatTok->is(Keywords.kw_interface)) {
 if (parseStructLike())
   return;
 break;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25429,6 +25429,13 @@
   verifyFormat("auto x = 5s .count() == 5;");
 }
 
+TEST_F(FormatTest, InterfaceAsClassMemberName) {
+  verifyFormat("class Foo {\n"
+   "  int interface;\n"
+   "  Foo::Foo(int iface) : interface{iface} {}\n"
+   "}");
+}
+
 } // namespace
 } // namespace test
 } // namespace format
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1881,7 +1881,7 @@
 }
   }
 
-  if (FormatTok->is(Keywords.kw_interface)) {
+  if (!Style.isCpp() && FormatTok->is(Keywords.kw_interface)) {
 if (parseStructLike())
   return;
 break;
___
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 created this revision.
Herald added subscribers: PiotrZSL, jeroen.dobbelaere, shchenz, kbarton, 
xazax.hun, nemanjai.
Herald added a reviewer: njames93.
Herald added a project: All.
carlosgalvezp requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

And remove identical functionality from
cppcoreguidelines-prefer-member-initializer, which had too many
responsibilities and a tight coupling to the
modernize-use-default-member-init check.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148460

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.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
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-prefer-member-initializer,modernize-use-default-member-init %t
-
-class Simple1 {
-  int n;
-  // CHECK-FIXES: int n{0};
-  double x;
-  // CHECK-FIXES: double x{0.0};
-
-public:
-  Simple1() {
-n = 0;
-// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in an in-class default member initializer [cppcoreguidelines-prefer-member-initializer]
-// CHECK-FIXES: {{^\ *$}}
-x = 0.0;
-// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in an in-class default member initializer [cppcoreguidelines-prefer-member-initializer]
-// CHECK-FIXES: {{^\ *$}}
-  }
-
-  Simple1(int nn, double xx) {
-// CHECK-FIXES: Simple1(int nn, double xx) : n(nn), x(xx) {
-n = nn;
-// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
-// CHECK-FIXES: {{^\ *$}}
-x = xx;
-// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
-// CHECK-FIXES: {{^\ *$}}
-  }
-
-  ~Simple1() = default;
-};
Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init-assignment.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init-assignment.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-prefer-member-initializer,modernize-use-default-member-init %t -- \
-// RUN: -config="{CheckOptions: [{key: modernize-use-default-member-init.UseAssignment, value: true}]}"
-
-class Simple1 {
-  int n;
-  // CHECK-FIXES: int n = 0;
-  double x;
-  // CHECK-FIXES: double x = 0.0;
-
-public:
-  Simple1() {
-n = 0;
-// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in an in-class default member initializer [cppcoreguidelines-prefer-member-initializer]
-// CHECK-FIXES: {{^\ *$}}
-x = 0.0;
-// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in an in-class default member initializer [cppcoreguidelines-prefer-member-initializer]
-// CHECK-FIXES: {{^\ *$}}
-  }
-
-  Simple1(int nn, double xx) {
-// CHECK-FIXES: Simple1(int nn, double xx) : n(nn), x(xx) {
-n = nn;
-// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'n' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
-// CHECK-FIXES: {{^\ *$}}
-x = xx;
-// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 'x' should be initialized in a member initializer of the constructor [cppcoreguidelines-prefer-member-initializer]
-// CHECK-FIXES: {{^\ *$}}
-  }
-
-  ~Simple1() = default;
-};
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 `_,
`c

[clang-tools-extra] b34ca08 - [clang-tidy] Fix handling of UseAssignment option in cppcoreguidelines-prefer-member-initializer

2023-04-16 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-04-16T10:34:48Z
New Revision: b34ca0851a5209a10c0ca285c000a18073677891

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

LOG: [clang-tidy] Fix handling of UseAssignment option in 
cppcoreguidelines-prefer-member-initializer

>From now on check will use value from 
>cppcoreguidelines-prefer-member-initializer
and fallback to modernize-use-default-member-init.UseAssignment if not 
specified.

Fixes: #55616.

Reviewed By: carlosgalvezp

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

Added: 


Modified: 

clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init-assignment.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
index 68697dbff3cfa..80b8c9211792a 100644
--- 
a/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -129,9 +129,11 @@ PreferMemberInitializerCheck::PreferMemberInitializerCheck(
 : ClangTidyCheck(Name, Context),
   IsUseDefaultMemberInitEnabled(
   Context->isCheckEnabled("modernize-use-default-member-init")),
-  UseAssignment(OptionsView("modernize-use-default-member-init",
-Context->getOptions().CheckOptions, Context)
-.get("UseAssignment", false)) {}
+  UseAssignment(
+  Options.get("UseAssignment",
+  OptionsView("modernize-use-default-member-init",
+  Context->getOptions().CheckOptions, Context)
+  .get("UseAssignment", false))) {}
 
 void PreferMemberInitializerCheck::storeOptions(
 ClangTidyOptions::OptionMap &Opts) {

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
index 1d47c03350003..dea9450b86fd3 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
@@ -85,9 +85,11 @@ Here ``n`` can be initialized in the constructor 
initialization list, unlike
 
 .. option:: UseAssignment
 
-   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:
+   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),
+   the check will initialize members with an assignment.
+   In this case the fix of the first example looks like this:
 
 .. code-block:: c++
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init-assignment.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init-assignment.cpp
index 7240f03f78fed..17600b82fb592 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init-assignment.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init-assignment.cpp
@@ -1,5 +1,8 @@
 // RUN: %check_clang_tidy %s 
cppcoreguidelines-prefer-member-initializer,modernize-use-default-member-init 
%t -- \
 // RUN: -config="{CheckOptions: [{key: 
modernize-use-default-member-init.UseAssignment, value: true}]}"
+// RUN: %check_clang_tidy %s 
cppcoreguidelines-prefer-member-initializer,modernize-use-default-member-init 
%t -- \
+// RUN: -config="{CheckOptions: [{key: 
modernize-use-default-member-init.UseAssignment, value: false}, \
+// RUN:  {key: 
cppcoreguidelines-prefer-member-initializer.UseAssignment, value: true}]}"
 
 class Simple1 {
   int n;

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init.cp

[PATCH] D147929: [clang-tidy] Fix handling of UseAssignment option in cppcoreguidelines-prefer-member-initializer

2023-04-16 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb34ca0851a52: [clang-tidy] Fix handling of UseAssignment 
option in cppcoreguidelines-prefer… (authored by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147929

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/prefer-member-initializer.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init-assignment.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init.cpp
@@ -1,4 +1,7 @@
 // RUN: %check_clang_tidy %s 
cppcoreguidelines-prefer-member-initializer,modernize-use-default-member-init %t
+// RUN: %check_clang_tidy %s 
cppcoreguidelines-prefer-member-initializer,modernize-use-default-member-init 
%t -- \
+// RUN: -config="{CheckOptions: [{key: 
modernize-use-default-member-init.UseAssignment, value: true}, \
+// RUN:  {key: 
cppcoreguidelines-prefer-member-initializer.UseAssignment, value: false}]}"
 
 class Simple1 {
   int n;
Index: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init-assignment.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init-assignment.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init-assignment.cpp
@@ -1,5 +1,8 @@
 // RUN: %check_clang_tidy %s 
cppcoreguidelines-prefer-member-initializer,modernize-use-default-member-init 
%t -- \
 // RUN: -config="{CheckOptions: [{key: 
modernize-use-default-member-init.UseAssignment, value: true}]}"
+// RUN: %check_clang_tidy %s 
cppcoreguidelines-prefer-member-initializer,modernize-use-default-member-init 
%t -- \
+// RUN: -config="{CheckOptions: [{key: 
modernize-use-default-member-init.UseAssignment, value: false}, \
+// RUN:  {key: 
cppcoreguidelines-prefer-member-initializer.UseAssignment, value: true}]}"
 
 class Simple1 {
   int n;
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
@@ -85,9 +85,11 @@
 
 .. option:: UseAssignment
 
-   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:
+   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),
+   the check will initialize members with an assignment.
+   In this case the fix of the first example looks like this:
 
 .. code-block:: c++
 
Index: 
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
===
--- 
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
+++ 
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
@@ -129,9 +129,11 @@
 : ClangTidyCheck(Name, Context),
   IsUseDefaultMemberInitEnabled(
   Context->isCheckEnabled("modernize-use-default-member-init")),
-  UseAssignment(OptionsView("modernize-use-default-member-init",
-Context->getOptions().CheckOptions, Context)
-.get("UseAssignment", false)) {}
+  UseAssignment(
+  Options.get("UseAssignment",
+  OptionsView("modernize-use-default-member-init",
+  Context->getOptions().CheckOptions, Context)
+  .get("UseAssignment", false))) {}
 
 void PreferMemberInitializerCheck::storeOptions(
 ClangTidyOptions::OptionMap &Opts) {


Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/prefer-member-initializer-modernize-use-default-member-init.cpp
=

[PATCH] D148461: [clang-tidy] Support C++17/20 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.

Added support for C++17 or later in tests
Pointers to member functions are now handled correctly in C++20

Depends on D148458 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148461

Files:
  clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
  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
@@ -1,10 +1,9 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s bugprone-exception-escape %t -- \
+// RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-exception-escape %t 
-- \
 // RUN: -config="{CheckOptions: [ \
 // RUN: {key: bugprone-exception-escape.IgnoredExceptions, value: 
'ignored1,ignored2'}, \
 // RUN: {key: bugprone-exception-escape.FunctionsThatShouldNotThrow, 
value: 'enabled1,enabled2,enabled3'} \
 // RUN: ]}" \
 // RUN: -- -fexceptions
-// FIXME: Fix the checker to work in C++17 or later mode.
 
 struct throwing_destructor {
   ~throwing_destructor() {
@@ -412,7 +411,7 @@
   void throw_noexcept_catch_regular() noexcept {
 try {
   throw &foo;
-} catch(int (*)()) {
+} catch(int (*)() noexcept) {
 }
   }
 }
Index: clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
===
--- clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
+++ clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
@@ -157,6 +157,9 @@
 return false;
 
   if (To->isFunctionPointerType()) {
+// 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*.
 if (From->isFunctionPointerType())
   return To->getPointeeType() == From->getPointeeType();
 
@@ -278,16 +281,17 @@
   return false;
 
 if (!isSameP_i(From, To)) {
-  if (LangOpts.CPlusPlus20) {
-if (From->isConstantArrayType() && !To->isIncompleteArrayType())
-  return false;
+  if (!LangOpts.CPlusPlus20)
+return false;
 
-if (From->isIncompleteArrayType() && !To->isIncompleteArrayType())
-  return false;
+  if (From->isConstantArrayType() && !To->isIncompleteArrayType())
+return false;
 
-  } else {
+  if (From->isIncompleteArrayType() && !To->isIncompleteArrayType())
+return false;
+
+  if (From->isMemberPointerType() || To->isMemberPointerType())
 return false;
-  }
 }
 
 ++I;


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
@@ -1,10 +1,9 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s bugprone-exception-escape %t -- \
+// RUN: %check_clang_tidy -std=c++11-or-later %s bugprone-exception-escape %t -- \
 // RUN: -config="{CheckOptions: [ \
 // RUN: {key: bugprone-exception-escape.IgnoredExceptions, value: 'ignored1,ignored2'}, \
 // RUN: {key: bugprone-exception-escape.FunctionsThatShouldNotThrow, value: 'enabled1,enabled2,enabled3'} \
 // RUN: ]}" \
 // RUN: -- -fexceptions
-// FIXME: Fix the checker to work in C++17 or later mode.
 
 struct throwing_destructor {
   ~throwing_destructor() {
@@ -412,7 +411,7 @@
   void throw_noexcept_catch_regular() noexcept {
 try {
   throw &foo;
-} catch(int (*)()) {
+} catch(int (*)() noexcept) {
 }
   }
 }
Index: clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
===
--- clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
+++ clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
@@ -157,6 +157,9 @@
 return false;
 
   if (To->isFunctionPointerType()) {
+// 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*.
 if (From->isFunctionPointerType())
   return To->getPointeeType() == From->getPointeeType();
 
@@ -278,16 +281,17 @@
   return false;
 
 if (!isSameP_i(From, To)) {
-  if (LangOpts.CPlusPlus20) {
-if (From->isConstantArrayType() && !To->isIncompleteArrayType())
-  return false;
+  if 

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

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

If this was the functionality pre 16 then LGTM


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] 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


[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] 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] 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 "../modernize/UseOverrideChec

[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 "../readability/MagicNu

[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 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
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyMod

[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 = &d;
-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] 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 = &d;
-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] 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] 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 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] 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 &Result) {
+  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] 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] 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] 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] 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 &Result) {
+  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] 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 &Result) {
+  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] 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] 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 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] 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] 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 cycl

[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] 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] 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 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] 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] 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 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 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


[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 @@ add_

[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 @@ add_

[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-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 &Result) {
 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


[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&id=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


[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] 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 @@
 /*IndentBraces=*/fa

[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 &LSquareTok, const FormatStyle &Style) {
 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 &LSquareTok, const FormatStyle &Style) {
 return Style.SpacesInContainerLiterals ||
___
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] 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 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] 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] 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 -DSYSROOT=%S/Inputs/basic_darwin_sdk_us

[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 &S, SourceLocation DeclLoc,
-   MultiExprArg Args,
-   OverloadCandidateSet &CandidateSet,
-   QualType DestType,
-   DeclContext::lookup_result Ctors,
-   OverloadCandidateSet::iterator &Best,
-   bool CopyInitializing, bool AllowExplicit,
-   bool OnlyListConstructors, bool IsListInit,
-   bool SecondStepOfCopyInit = false) {
+static OverloadingResult ResolveConstructorOverload(
+Sema &S, SourceLocation DeclLoc, MultiExprArg Args,
+OverloadCandidateSet &CandidateSet, QualType DestType,
+DeclContext::lookup_result Ctors, OverloadCandidateSet::iterator &Best,
+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++: Lamb

[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 &R) 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 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] 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] 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 &foo;
-} 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] 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] 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 = &array;
+}
+
+void test_qualifiers(const int y) {
+  const auto a = 12;
+  auto b = y;
+  static auto c = 1UL;
+  int *pa = &a; // expected-warning {{initializing 'int *' with an expression of
+// type 'const int *' discards qualifiers}}
+  const int *pb = &b;
+  int *pc = &c; // 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 = &a;
+  auto *str = "this is a string";
+  const auto *str2 = "this is a string";
+  auto *b = &a;
+  *b = &a; // 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,
+ 

[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


[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


[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 *)&llvm_orc_registerJITLoaderGDBWrapper
+   << (void *)&llvm_orc_registerJITLoaderGDBAllocAction;
+}
+
 namespace clang {
 
 IncrementalExecutor::IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC,
@@ -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 *)&llvm_orc_registerJITLoaderGDBWrapper
+   << (void *)&llvm_orc_registerJITLoaderGDBAllocAction;
+}
+
 namespace clang {
 
 IncrementalExecutor::IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC,
@@ -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


[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


[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] 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 &foo;
-} 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] 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] 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] 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


[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


[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&id=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);\

[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 &Line,
   LeftParen = &Left;
 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 
&Tok) 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

[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);
   EXPECT_TOKEN(Tok

[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] 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] 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] 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] 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


[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] 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);
   EXPECT_TO

[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] 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) {
  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) {
 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");
+  ASSE

[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 &Value) {
 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 &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] 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 &Value) {
 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 &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,
  

[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] 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] 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&ig_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] 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 &operator<<(llvm::raw_ostream &OS, 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 &operator<<(llvm::raw_ostream &OS, 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 &Active : 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 &C = Config::current();
+HighlightingFilter Filter;
+for (const auto &Kind : C.SemanticTokens.DisabledKinds)
+  if (auto K = highlightingKindFromString(Kind))
+Filter.disableKind(*K);
+for (const auto &Modifier : 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 &AST, bool IncludeInactiveRegionTokens)
+  HighlightingsBuilder(const ParsedAST &AST, const HighlightingFilter &Filter,
+   bool IncludeInactiveRegionTokens)
   : TB(AST.getTokens()), SourceMgr(AST.getSourceManager()),
-LangOpts(AST.getLangOpts()),
+LangOpts(AST.getLangOpts()), Filter(Filter),
 IncludeInactiveRegionTokens(IncludeInactiveRegionTokens) {}
 
   HighlightingToken &addToken(SourceLocation Loc, Highl

[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] 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 &DriverArgs) 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
+
+// 

[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 &operator<<(llvm::raw_ostream &OS, 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 &operator<<(llvm::raw_ostream &OS, 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 &Active : 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 &C = Config::current();
+HighlightingFilter Filter;
+for (const auto &Kind : C.SemanticTokens.DisabledKinds)
+  if (auto K = highlightingKindFromString(Kind))
+Filter.disableKind(*K);
+for (const auto &Modifier : 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 &AST, bool IncludeInactiveRegionTokens)
+  HighlightingsBuilder(const ParsedAST &AST, const HighlightingFilter &Filter,
+   bool IncludeInactiveRegionTokens)
   : TB(AST.getTokens()), SourceMgr(AST.getSourceManager()),
-LangOpts(AST.getLangOpts()),
+LangOpts(AST.getLangOpts()), Filter(Filter),
 IncludeInactiveRegionTokens(IncludeInactiveRegionTokens) {}
 
   HighlightingToken &addToken(SourceLocation Loc, HighlightingKind Kind) {
@@ -412,6 +459,9 @@
   }
 
   HighlightingToken &addToken(Range R, HighlightingKind Kind) {
+if (!Filte

[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 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 &operator<<(llvm::raw_ostream &OS, 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 &operator<<(llvm::raw_ostream &OS, 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 &Active : 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 &C = Config::current();
+HighlightingFilter Filter;
+for (const auto &Kind : C.Semanti

  1   2   >