[clang] 1c91733 - Fix highlighting issue with _complex and initialization list with more than 2 items

2023-03-23 Thread NagaChaitanya Vellanki via cfe-commits

Author: NagaChaitanya Vellanki
Date: 2023-03-23T14:18:02-07:00
New Revision: 1c9173365a932a0d289ec86704ec645a138de03e

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

LOG: Fix highlighting issue with _complex and initialization list with more 
than 2 items

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

Reviewed By: aaron.ballman

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

Added: 
clang/test/Sema/caret-diags-complex-init.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaInit.cpp
clang/test/Sema/complex-init-list.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 005bf99a62457..faac3b17b223f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -225,6 +225,8 @@ Bug Fixes in This Version
   enabling short-circuiting coroutines use cases. This fixes
   (`#56532 `_) in
   antecipation of `CWG2563 
_`.
+- Fix highlighting issue with ``_Complex`` and initialization list with more 
than
+  2 items. (`#61518 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 17d8b6c98207b..46517c9dde06a 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -1536,7 +1536,7 @@ void InitListChecker::CheckComplexType(const 
InitializedEntity &Entity,
   // the element type of the complex type. The first element initializes
   // the real part, and the second element intitializes the imaginary part.
 
-  if (IList->getNumInits() != 2)
+  if (IList->getNumInits() < 2)
 return CheckScalarType(Entity, IList, DeclType, Index, StructuredList,
StructuredIndex);
 

diff  --git a/clang/test/Sema/caret-diags-complex-init.cpp 
b/clang/test/Sema/caret-diags-complex-init.cpp
new file mode 100644
index 0..d8a1b7837a640
--- /dev/null
+++ b/clang/test/Sema/caret-diags-complex-init.cpp
@@ -0,0 +1,39 @@
+// RUN: not %clang_cc1 -std=c++11 -fsyntax-only -fcaret-diagnostics-max-lines 
5 %s 2>&1 | FileCheck %s -strict-whitespace
+
+
+//CHECK: {{.*}}: error: excess elements in scalar initializer
+//CHECK-NEXT: {{^}}_Complex double gz1 = {1, 2, 3};
+//CHECK-NEXT: {{^}} ^{{$}}
+_Complex double gz1 = {1, 2, 3}; 
+
+//CHECK: {{.*}}: error: excess elements in scalar initializer
+//CHECK-NEXT: {{^}}_Complex double dd = {1.0, 2.0, 3.0};
+//CHECK-NEXT: {{^}}^~~{{$}}
+_Complex double dd = {1.0, 2.0, 3.0};
+
+//CHECK: {{.*}}: error: excess elements in scalar initializer
+//CHECK-NEXT: {{^}}_Complex float fd = {1.0, 2.0, 3.0, 4.0, 5.0};
+//CHECK-NEXT: {{^}}   ^~~{{$}}
+_Complex float fd = {1.0, 2.0, 3.0, 4.0, 5.0};
+
+//CHECK: {{.*}}: error: no viable conversion from 'foo' to 'double'
+//CHECK-NEXT: {{^}}_Complex double ds = {f, 1.0, b};
+//CHECK-NEXT: {{^}}  ^{{$}}
+struct foo{};
+struct bar{};
+
+foo f;
+bar b;
+_Complex double ds = {f, 1.0, b};
+
+//CHECK: {{.*}}: error: no viable conversion from 'foo' to 'double'
+//CHECK-NEXT: {{^}}_Complex double fg = {1.0, f};
+//CHECK-NEXT: {{^}}   ^{{$}}
+_Complex double fg = {1.0, f};
+
+
+//CHECK: {{.*}}: error: excess elements in scalar initializer
+//CHECK-NEXT: {{^}}_Complex double gg = {1.0, 2.0, f};
+//CHECK-NEXT: {{^}}^{{$}}
+//CHECK-NEXT: {{^}}6 errors generated.
+_Complex double gg = {1.0, 2.0, f};

diff  --git a/clang/test/Sema/complex-init-list.c 
b/clang/test/Sema/complex-init-list.c
index bfc6899ac235d..b8f87f57f0793 100644
--- a/clang/test/Sema/complex-init-list.c
+++ b/clang/test/Sema/complex-init-list.c
@@ -25,17 +25,21 @@ struct teststruct { _Complex float x; };
 
 
 // Random other valid stuff
-_Complex int valid2 = { 1, 2 }; // expected-warning {{complex integer}} 
expected-warning {{specifying real and imaginary components is an extension}}
+_Complex int valid2 = { 1, 2 }; // expected-warning {{complex integer}} \
+   //  expected-warning {{specifying real and 
imaginary components is an extension}}
 struct teststruct valid3 = { { 1.0f, 2.0f} }; // expected-warning {{specifying 
real and imaginary components is an extension}}
 _Complex float valid4[2] = { {1.0f, 1.0f}, {1.0f, 1.0f} }; // expected-warning 
2 {{specifying real and imaginary components is an extension}}
 // FIXME: We need some sort of warning for valid5
-_Complex float valid5 = {1.0f, 1.0fi}; // expected-warning {{imaginary 
constants}} expected-warning {{specifying real and imaginary components is an

[clang] c13ccf1 - [clang][ExtractAPI]Fix Declaration fragments for instancetype in the type position degrade to id

2023-03-23 Thread NagaChaitanya Vellanki via cfe-commits

Author: NagaChaitanya Vellanki
Date: 2023-03-23T15:10:27-07:00
New Revision: c13ccf1fbabede34ff28461b29d2d14aceb293fd

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

LOG: [clang][ExtractAPI]Fix Declaration fragments for instancetype in the type 
position degrade to id

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

Reviewed By: dang

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

Added: 
clang/test/ExtractAPI/objc_instancetype.m

Modified: 
clang/lib/ExtractAPI/DeclarationFragments.cpp

Removed: 




diff  --git a/clang/lib/ExtractAPI/DeclarationFragments.cpp 
b/clang/lib/ExtractAPI/DeclarationFragments.cpp
index b8de1270b5f02..c42a1de2fd358 100644
--- a/clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ b/clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -243,26 +243,30 @@ DeclarationFragments 
DeclarationFragmentsBuilder::getFragmentsForType(
 return Fragments.append(getFragmentsForType(ET->desugar(), Context, 
After));
   }
 
-  // Everything we care about has been handled now, reduce to the canonical
-  // unqualified base type.
-  QualType Base = T->getCanonicalTypeUnqualified();
-
-  // Render Objective-C `id`/`instancetype` as keywords.
-  if (T->isObjCIdType())
-return Fragments.append(Base.getAsString(),
-DeclarationFragments::FragmentKind::Keyword);
-
   // If the type is a typedefed type, get the underlying TypedefNameDecl for a
   // direct reference to the typedef instead of the wrapped type.
+
+  // 'id' type is a typedef for an ObjCObjectPointerType
+  //  we treat it as a typedef
   if (const TypedefType *TypedefTy = dyn_cast(T)) {
 const TypedefNameDecl *Decl = TypedefTy->getDecl();
 TypedefUnderlyingTypeResolver TypedefResolver(Context);
 std::string USR = TypedefResolver.getUSRForType(QualType(T, 0));
+
+if (T->isObjCIdType()) {
+  return Fragments.append(Decl->getName(),
+  DeclarationFragments::FragmentKind::Keyword);
+}
+
 return Fragments.append(
 Decl->getName(), DeclarationFragments::FragmentKind::TypeIdentifier,
 USR, TypedefResolver.getUnderlyingTypeDecl(QualType(T, 0)));
   }
 
+  // Everything we care about has been handled now, reduce to the canonical
+  // unqualified base type.
+  QualType Base = T->getCanonicalTypeUnqualified();
+
   // If the base type is a TagType (struct/interface/union/class/enum), let's
   // get the underlying Decl for better names and USRs.
   if (const TagType *TagTy = dyn_cast(Base)) {

diff  --git a/clang/test/ExtractAPI/objc_instancetype.m 
b/clang/test/ExtractAPI/objc_instancetype.m
new file mode 100644
index 0..1680fe9336cf3
--- /dev/null
+++ b/clang/test/ExtractAPI/objc_instancetype.m
@@ -0,0 +1,254 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+ // RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx -x 
objective-c-header %t/input.h -o %t/output.json -verify
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+ // RUN: %t/output.json >> %t/output-normalized.json
+// RUN: 
diff  %t/reference.output.json %t/output-normalized.json
+
+
+//--- input.h
+@interface Foo
+- (instancetype) init;
+- (id) reset;
+@end
+// expected-no-diagnostics
+
+
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)Foo(im)init",
+  "target": "c:objc(cs)Foo",
+  "targetFallback": "Foo"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)Foo(im)reset",
+  "target": "c:objc(cs)Foo",
+  "targetFallback": "Foo"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "@interface"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)Foo"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "ob

[clang] a590d86 - [clang][ExtractAPI] Remove extra pointer indirection from declaration fragments for Obj-C lightweight generics on id

2023-03-30 Thread NagaChaitanya Vellanki via cfe-commits

Author: NagaChaitanya Vellanki
Date: 2023-03-30T11:36:16-07:00
New Revision: a590d8634308aadc96e71c8dbbcbd4348f2efd1d

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

LOG: [clang][ExtractAPI] Remove extra pointer indirection from declaration 
fragments for Obj-C lightweight generics on id

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

Reviewed By: dang

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

Added: 
clang/test/ExtractAPI/objc_id_protocol.m

Modified: 
clang/lib/ExtractAPI/DeclarationFragments.cpp

Removed: 




diff  --git a/clang/lib/ExtractAPI/DeclarationFragments.cpp 
b/clang/lib/ExtractAPI/DeclarationFragments.cpp
index 675d4e8dc8638..912e58a0c6e82 100644
--- a/clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ b/clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -160,14 +160,26 @@ DeclarationFragments 
DeclarationFragmentsBuilder::getFragmentsForType(
   DeclarationFragments Fragments;
 
   // Declaration fragments of a pointer type is the declaration fragments of
-  // the pointee type followed by a `*`, except for Objective-C `id` and 
`Class`
-  // pointers, where we do not spell out the `*`.
-  if (T->isPointerType() ||
-  (T->isObjCObjectPointerType() &&
-   !T->getAs()->isObjCIdOrClassType())) {
+  // the pointee type followed by a `*`,
+  if (T->isPointerType())
 return Fragments
 .append(getFragmentsForType(T->getPointeeType(), Context, After))
 .append(" *", DeclarationFragments::FragmentKind::Text);
+
+  // For Objective-C `id` and `Class` pointers
+  // we do not spell out the `*`.
+  if (T->isObjCObjectPointerType() &&
+  !T->getAs()->isObjCIdOrClassType()) {
+
+Fragments.append(getFragmentsForType(T->getPointeeType(), Context, After));
+
+// id is an qualified id type
+// id* is not an qualified id type
+if (!T->getAs()->isObjCQualifiedIdType()) {
+  Fragments.append(" *", DeclarationFragments::FragmentKind::Text);
+}
+
+return Fragments;
   }
 
   // Declaration fragments of a lvalue reference type is the declaration

diff  --git a/clang/test/ExtractAPI/objc_id_protocol.m 
b/clang/test/ExtractAPI/objc_id_protocol.m
new file mode 100644
index 0..551e908ae4fdd
--- /dev/null
+++ b/clang/test/ExtractAPI/objc_id_protocol.m
@@ -0,0 +1,341 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s@INPUT_DIR@%{/t:regex_replacement}@g" \
+// RUN: %t/reference.output.json.in >> %t/reference.output.json
+// RUN: %clang -extract-api -x objective-c-header -target arm64-apple-macosx \
+// RUN: %t/input.h -o %t/output.json | FileCheck -allow-empty %s
+
+// Generator version is not consistent across test runs, normalize it.
+// RUN: sed -e "s@\"generator\": \".*\"@\"generator\": \"?\"@g" \
+// RUN: %t/output.json >> %t/output-normalized.json
+// RUN: 
diff  %t/reference.output.json %t/output-normalized.json
+
+// CHECK-NOT: error:
+// CHECK-NOT: warning:
+
+//--- input.h
+@protocol MyProtocol
+@end
+
+@interface MyInterface
+@property(copy, readwrite) id obj1;
+@property(readwrite) id *obj2;
+@end
+//--- reference.output.json.in
+{
+  "metadata": {
+"formatVersion": {
+  "major": 0,
+  "minor": 5,
+  "patch": 3
+},
+"generator": "?"
+  },
+  "module": {
+"name": "",
+"platform": {
+  "architecture": "arm64",
+  "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
+"name": "macosx"
+  },
+  "vendor": "apple"
+}
+  },
+  "relationships": [
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)MyInterface(py)obj1",
+  "target": "c:objc(cs)MyInterface",
+  "targetFallback": "MyInterface"
+},
+{
+  "kind": "memberOf",
+  "source": "c:objc(cs)MyInterface(py)obj2",
+  "target": "c:objc(cs)MyInterface",
+  "targetFallback": "MyInterface"
+}
+  ],
+  "symbols": [
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "@interface"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "MyInterface"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)MyInterface"
+  },
+  "kind": {
+"displayName": "Class",
+"identifier": "objective-c.class"
+  },
+  "location": {
+"position": {
+  "character": 12,
+  "line": 4
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "MyInterface"
+

[clang-tools-extra] 785b30b - [clang-tidy] Check for specific return types on all functions

2023-05-26 Thread NagaChaitanya Vellanki via cfe-commits

Author: NagaChaitanya Vellanki
Date: 2023-05-26T13:59:18-07:00
New Revision: 785b30b8a33a394a677b1b8ce35c66ba482db169

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

LOG: [clang-tidy] Check for specific return types on all functions

Extend the check to all functions with return types like
 std::error_code, std::expected, boost::system::error_code, 
abseil::Status...

 Resolves issue https://github.com/llvm/llvm-project/issues/62884

Reviewed By: PiotrZSL

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-return-value.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-return-value.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
index 6049569b5f581..f8139381d7e01 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "UnusedReturnValueCheck.h"
+#include "../utils/Matchers.h"
 #include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -27,7 +28,6 @@ AST_MATCHER_P(FunctionDecl, isInstantiatedFrom, 
Matcher,
   return InnerMatcher.matches(InstantiatedFrom ? *InstantiatedFrom : Node,
   Finder, Builder);
 }
-
 } // namespace
 
 UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
@@ -124,19 +124,30 @@ 
UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name,
"::sigismember;"
"::strcasecmp;"
"::strsignal;"
-   "::ttyname")) {}
+   "::ttyname")),
+  CheckedReturnTypes(utils::options::parseStringList(
+  Options.get("CheckedReturnTypes", "::std::error_code;"
+"::std::expected;"
+"::boost::system::error_code;"
+"::abseil::Status"))) {}
 
 void UnusedReturnValueCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "CheckedFunctions", CheckedFunctions);
+  Options.store(Opts, "CheckedReturnTypes",
+utils::options::serializeStringList(CheckedReturnTypes));
 }
 
 void UnusedReturnValueCheck::registerMatchers(MatchFinder *Finder) {
   auto FunVec = utils::options::parseStringList(CheckedFunctions);
+
   auto MatchedCallExpr = expr(ignoringImplicit(ignoringParenImpCasts(
   callExpr(callee(functionDecl(
// Don't match void overloads of checked functions.
unless(returns(voidType())),
-   isInstantiatedFrom(hasAnyName(FunVec)
+   anyOf(isInstantiatedFrom(hasAnyName(FunVec)),
+ returns(hasCanonicalType(hasDeclaration(
+ namedDecl(matchers::matchesAnyListedName(
+ CheckedReturnTypes)
   .bind("match";
 
   auto UnusedInCompoundStmt =

diff  --git a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
index f16815b0f839e..15881e12ca0c3 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.h
@@ -27,6 +27,7 @@ class UnusedReturnValueCheck : public ClangTidyCheck {
 
 private:
   std::string CheckedFunctions;
+  const std::vector CheckedReturnTypes;
 };
 
 } // namespace clang::tidy::bugprone

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 980be4869ead8..1eb8c5ba4b71b 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -248,6 +248,10 @@ Changes in existing checks
   constructor initializers. Correctly handle constructor arguments as being
   sequenced when constructor call is written as list-initialization.
 
+- Extend :doc:`bugprone-unused-return-value
+  ` check to check for all 
functions
+  with specified return types using the ``CheckedReturnTypes`` option.
+
 - Deprecated :doc:`cert-dcl21-cpp
   ` check.
 

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/u

[clang] 14805dc - [clang][ExtractAPI] Add semicolon to function declaration fragments

2023-05-04 Thread NagaChaitanya Vellanki via cfe-commits

Author: NagaChaitanya Vellanki
Date: 2023-05-04T11:46:43-07:00
New Revision: 14805dcb0d8abfd5cd015656313f3f98a22e0a1b

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

LOG: [clang][ExtractAPI] Add semicolon to function declaration fragments

Add missing semicolon at the end of function declarations to fragments

Reviewed By: dang

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

Added: 


Modified: 
clang/lib/ExtractAPI/DeclarationFragments.cpp
clang/test/ExtractAPI/availability.c
clang/test/ExtractAPI/global_record.c
clang/test/ExtractAPI/global_record_multifile.c
clang/test/ExtractAPI/macro_undefined.c

Removed: 




diff  --git a/clang/lib/ExtractAPI/DeclarationFragments.cpp 
b/clang/lib/ExtractAPI/DeclarationFragments.cpp
index da75a701b405e..1e52f221c7982 100644
--- a/clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ b/clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -457,7 +457,7 @@ DeclarationFragmentsBuilder::getFragmentsForFunction(const 
FunctionDecl *Func) {
   Fragments.append(")", DeclarationFragments::FragmentKind::Text);
 
   // FIXME: Handle exception specifiers: throw, noexcept
-  return Fragments;
+  return Fragments.append(";", DeclarationFragments::FragmentKind::Text);
 }
 
 DeclarationFragments DeclarationFragmentsBuilder::getFragmentsForEnumConstant(

diff  --git a/clang/test/ExtractAPI/availability.c 
b/clang/test/ExtractAPI/availability.c
index 7d071909a092e..0c8cd3629f3fd 100644
--- a/clang/test/ExtractAPI/availability.c
+++ b/clang/test/ExtractAPI/availability.c
@@ -76,7 +76,7 @@ void e(void) __attribute__((availability(tvos, unavailable)));
 },
 {
   "kind": "text",
-  "spelling": "()"
+  "spelling": "();"
 }
   ],
   "functionSignature": {
@@ -150,7 +150,7 @@ void e(void) __attribute__((availability(tvos, 
unavailable)));
 },
 {
   "kind": "text",
-  "spelling": "()"
+  "spelling": "();"
 }
   ],
   "functionSignature": {
@@ -234,7 +234,7 @@ void e(void) __attribute__((availability(tvos, 
unavailable)));
 },
 {
   "kind": "text",
-  "spelling": "()"
+  "spelling": "();"
 }
   ],
   "functionSignature": {
@@ -334,7 +334,7 @@ void e(void) __attribute__((availability(tvos, 
unavailable)));
 },
 {
   "kind": "text",
-  "spelling": "()"
+  "spelling": "();"
 }
   ],
   "functionSignature": {
@@ -416,7 +416,7 @@ void e(void) __attribute__((availability(tvos, 
unavailable)));
 },
 {
   "kind": "text",
-  "spelling": "()"
+  "spelling": "();"
 }
   ],
   "functionSignature": {

diff  --git a/clang/test/ExtractAPI/global_record.c 
b/clang/test/ExtractAPI/global_record.c
index 8516ac50be858..7ca89875d66ae 100644
--- a/clang/test/ExtractAPI/global_record.c
+++ b/clang/test/ExtractAPI/global_record.c
@@ -189,7 +189,7 @@ char unavailable __attribute__((unavailable));
 },
 {
   "kind": "text",
-  "spelling": ")"
+  "spelling": ");"
 }
   ],
   "docComment": {

diff  --git a/clang/test/ExtractAPI/global_record_multifile.c 
b/clang/test/ExtractAPI/global_record_multifile.c
index 0eacb8a94b77f..b1e9f9ed21d42 100644
--- a/clang/test/ExtractAPI/global_record_multifile.c
+++ b/clang/test/ExtractAPI/global_record_multifile.c
@@ -191,7 +191,7 @@ char unavailable __attribute__((unavailable));
 },
 {
   "kind": "text",
-  "spelling": ")"
+  "spelling": ");"
 }
   ],
   "docComment": {

diff  --git a/clang/test/ExtractAPI/macro_undefined.c 
b/clang/test/ExtractAPI/macro_undefined.c
index c7d3dd6cfea8c..f150c10fb2ed6 100644
--- a/clang/test/ExtractAPI/macro_undefined.c
+++ b/clang/test/ExtractAPI/macro_undefined.c
@@ -67,7 +67,7 @@ FUNC_GEN(bar, const int *, unsigned);
 },
 {
   "kind": "text",
-  "spelling": "()"
+  "spelling": "();"
 }
   ],
   "functionSignature": {
@@ -173,7 +173,7 @@ FUNC_GEN(bar, const int *, unsigned);
 },
 {
   "kind": "text",
-  "spelling": ")"
+  "spelling": ");"
 }
   ],
   "functionSignature": {



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


[clang-tools-extra] [clang-tidy] Add modernize-use-cpp-style-comments check (PR #99713)

2024-07-24 Thread NagaChaitanya Vellanki via cfe-commits

https://github.com/chaitanyav updated 
https://github.com/llvm/llvm-project/pull/99713

>From a3c7fca28faee679a59afd58c2e814025771ff63 Mon Sep 17 00:00:00 2001
From: NagaChaitanya Vellanki 
Date: Fri, 19 Jul 2024 14:26:23 -0700
Subject: [PATCH] [clang-tidy] Add modernize-use-cpp-style-comments check

  modernize-use-cpp-style-comments check finds C style comments
  and suggests to use C++ style comments

  Fixes #24841
---
 .../clang-tidy/modernize/CMakeLists.txt   |  1 +
 .../modernize/ModernizeTidyModule.cpp |  3 +
 .../modernize/UseCppStyleCommentsCheck.cpp| 64 +
 .../modernize/UseCppStyleCommentsCheck.h  | 40 +
 clang-tools-extra/docs/ReleaseNotes.rst   | 89 +++
 .../modernize/use-cpp-style-comments.rst  |  6 ++
 .../modernize/use-cpp-style-comments.cpp  |  7 ++
 7 files changed, 210 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-cpp-style-comments.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-cpp-style-comments.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 4f68c487cac9d..04a1d04cc333e 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -31,6 +31,7 @@ add_clang_library(clangTidyModernizeModule
   UseAutoCheck.cpp
   UseBoolLiteralsCheck.cpp
   UseConstraintsCheck.cpp
+  UseCppStyleCommentsCheck.cpp
   UseDefaultMemberInitCheck.cpp
   UseDesignatedInitializersCheck.cpp
   UseEmplaceCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 1860759332063..39995a32133b3 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -32,6 +32,7 @@
 #include "UseAutoCheck.h"
 #include "UseBoolLiteralsCheck.h"
 #include "UseConstraintsCheck.h"
+#include "UseCppStyleCommentsCheck.h"
 #include "UseDefaultMemberInitCheck.h"
 #include "UseDesignatedInitializersCheck.h"
 #include "UseEmplaceCheck.h"
@@ -104,6 +105,8 @@ class ModernizeModule : public ClangTidyModule {
 "modernize-use-bool-literals");
 CheckFactories.registerCheck(
 "modernize-use-constraints");
+CheckFactories.registerCheck(
+"modernize-use-cpp-style-comments");
 CheckFactories.registerCheck(
 "modernize-use-default-member-init");
 CheckFactories.registerCheck("modernize-use-emplace");
diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp
new file mode 100644
index 0..4b1c84031e672
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp
@@ -0,0 +1,64 @@
+//===--- UseCppStyleCommentsCheck.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 "UseCppStyleCommentsCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Lex/Preprocessor.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+class UseCppStyleCommentsCheck::CStyleCommentHandler : public CommentHandler {
+public:
+  CStyleCommentHandler(UseCppStyleCommentsCheck &Check)
+  : Check(Check),
+CStyleCommentMatch(
+"^[ \t]*/\\*+[ \t\n]*(.*[ \t\n]*)*[ \t\n]*\\*+/[ \t\n]*$") {}
+
+  bool HandleComment(Preprocessor &PP, SourceRange Range) override {
+if (Range.getBegin().isMacroID() ||
+PP.getSourceManager().isInSystemHeader(Range.getBegin()))
+  return false;
+
+const StringRef Text =
+Lexer::getSourceText(CharSourceRange::getCharRange(Range),
+ PP.getSourceManager(), PP.getLangOpts());
+
+SmallVector Matches;
+if (!CStyleCommentMatch.match(Text, &Matches)) {
+  return false;
+}
+
+Check.diag(
+Range.getBegin(),
+"use C++ style comments '//' instead of C style comments '/*...*/'");
+
+return false;
+  }
+
+private:
+  UseCppStyleCommentsCheck &Check;
+  llvm::Regex CStyleCommentMatch;
+};
+
+UseCppStyleCommentsCheck::UseCppStyleCommentsCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  Handler(std::make_unique(*this)) {}
+
+void UseCppStyleCommentsCheck::registerPPCa

[clang-tools-extra] [clang-tidy] Add modernize-use-cpp-style-comments check (PR #99713)

2024-07-29 Thread NagaChaitanya Vellanki via cfe-commits

chaitanyav wrote:

I am moving this under readability, i will also post some code on how am i 
planning to output a fix. For now i don't have a good way to handle 

```
int a = /*some value */ 5;
```

https://github.com/llvm/llvm-project/pull/99713
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] (PR #99713)

2024-07-19 Thread NagaChaitanya Vellanki via cfe-commits

https://github.com/chaitanyav created 
https://github.com/llvm/llvm-project/pull/99713

  modernize-use-cpp-style-comments check finds C style comments
  and suggests to use C++ style comments

  Fixes #24841



@LegalizeAdulthood @PiotrZSL 


```
~/scratch/llvm_test_ground/test1.cpp:1:1: warning: use C++ style comments '//' 
instead of C style comments '/*...*/' [modernize-use-cpp-style-comments]
1 | /* Hello world
  | ^~
2 |  * this is a line
  |  
3 |  */
  |  ~~
~/scratch/llvm_test_ground/test1.cpp:4:1: warning: use C++ style comments '//' 
instead of C style comments '/*...*/' [modernize-use-cpp-style-comments]
4 | /*!
  | ^~~
5 |  * ... text ...
  |  ~~
6 | */
  | ~~
~/scratch/llvm_test_ground/test1.cpp:7:1: warning: use C++ style comments '//' 
instead of C style comments '/*...*/' [modernize-use-cpp-style-comments]
7 | /*foo bar goo
  | ^
8 |  *foo bar goo
  |  
9 |  */
  |  ~~
~/scratch/llvm_test_ground/test1.cpp:11:1: warning: use C++ style comments '//' 
instead of C style comments '/*...*/' [modernize-use-cpp-style-comments]
   11 | /*#
  | ^~~
   12 |  * Fancy comment goes here
  |  ~
   13 |  *#
  |  ~~
   14 |  */
  |  ~~
~/scratch/llvm_test_ground/test1.cpp:22:34: warning: use C++ style comments 
'//' instead of C style comments '/*...*/' [modernize-use-cpp-style-comments]
   22 |   memcpy(a, b, sizeof(int) * 5); /* Fix me later */
  |  ^~ 
```

>From dc9d737e978093505c7de44b1d29f731d837983c Mon Sep 17 00:00:00 2001
From: NagaChaitanya Vellanki 
Date: Fri, 19 Jul 2024 14:26:23 -0700
Subject: [PATCH] [clang-tidy]

  modernize-use-cpp-style-comments check finds C style comments
  and suggests to use C++ style comments

  Fixes #24841
---
 .../clang-tidy/modernize/CMakeLists.txt   |  1 +
 .../modernize/ModernizeTidyModule.cpp |  3 +
 .../modernize/UseCppStyleCommentsCheck.cpp| 66 +++
 .../modernize/UseCppStyleCommentsCheck.h  | 38 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../modernize/use-cpp-style-comments.rst  | 12 
 .../modernize/use-cpp-style-comments.cpp  | 16 +
 7 files changed, 141 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-cpp-style-comments.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-cpp-style-comments.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 4f68c487cac9d..04a1d04cc333e 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -31,6 +31,7 @@ add_clang_library(clangTidyModernizeModule
   UseAutoCheck.cpp
   UseBoolLiteralsCheck.cpp
   UseConstraintsCheck.cpp
+  UseCppStyleCommentsCheck.cpp
   UseDefaultMemberInitCheck.cpp
   UseDesignatedInitializersCheck.cpp
   UseEmplaceCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 1860759332063..39995a32133b3 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -32,6 +32,7 @@
 #include "UseAutoCheck.h"
 #include "UseBoolLiteralsCheck.h"
 #include "UseConstraintsCheck.h"
+#include "UseCppStyleCommentsCheck.h"
 #include "UseDefaultMemberInitCheck.h"
 #include "UseDesignatedInitializersCheck.h"
 #include "UseEmplaceCheck.h"
@@ -104,6 +105,8 @@ class ModernizeModule : public ClangTidyModule {
 "modernize-use-bool-literals");
 CheckFactories.registerCheck(
 "modernize-use-constraints");
+CheckFactories.registerCheck(
+"modernize-use-cpp-style-comments");
 CheckFactories.registerCheck(
 "modernize-use-default-member-init");
 CheckFactories.registerCheck("modernize-use-emplace");
diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp
new file mode 100644
index 0..f4d3bbce9f121
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp
@@ -0,0 +1,66 @@
+//===--- UseCppStyleCommentsCheck.cpp - clang-tidy---*- 
C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with 

[clang-tools-extra] [clang-tidy] (PR #99713)

2024-07-19 Thread NagaChaitanya Vellanki via cfe-commits

https://github.com/chaitanyav updated 
https://github.com/llvm/llvm-project/pull/99713

>From c8b8a13188cb941e08a6aae604bd79ae3469cf89 Mon Sep 17 00:00:00 2001
From: NagaChaitanya Vellanki 
Date: Fri, 19 Jul 2024 14:26:23 -0700
Subject: [PATCH] [clang-tidy]

  modernize-use-cpp-style-comments check finds C style comments
  and suggests to use C++ style comments

  Fixes #24841
---
 .../clang-tidy/modernize/CMakeLists.txt   |  1 +
 .../modernize/ModernizeTidyModule.cpp |  3 +
 .../modernize/UseCppStyleCommentsCheck.cpp| 71 +++
 .../modernize/UseCppStyleCommentsCheck.h  | 38 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../modernize/use-cpp-style-comments.rst  | 12 
 .../modernize/use-cpp-style-comments.cpp  | 16 +
 7 files changed, 146 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-cpp-style-comments.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-cpp-style-comments.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 4f68c487cac9d..04a1d04cc333e 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -31,6 +31,7 @@ add_clang_library(clangTidyModernizeModule
   UseAutoCheck.cpp
   UseBoolLiteralsCheck.cpp
   UseConstraintsCheck.cpp
+  UseCppStyleCommentsCheck.cpp
   UseDefaultMemberInitCheck.cpp
   UseDesignatedInitializersCheck.cpp
   UseEmplaceCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 1860759332063..39995a32133b3 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -32,6 +32,7 @@
 #include "UseAutoCheck.h"
 #include "UseBoolLiteralsCheck.h"
 #include "UseConstraintsCheck.h"
+#include "UseCppStyleCommentsCheck.h"
 #include "UseDefaultMemberInitCheck.h"
 #include "UseDesignatedInitializersCheck.h"
 #include "UseEmplaceCheck.h"
@@ -104,6 +105,8 @@ class ModernizeModule : public ClangTidyModule {
 "modernize-use-bool-literals");
 CheckFactories.registerCheck(
 "modernize-use-constraints");
+CheckFactories.registerCheck(
+"modernize-use-cpp-style-comments");
 CheckFactories.registerCheck(
 "modernize-use-default-member-init");
 CheckFactories.registerCheck("modernize-use-emplace");
diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp
new file mode 100644
index 0..d93754a8069f8
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp
@@ -0,0 +1,71 @@
+//===--- UseCppStyleCommentsCheck.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 "UseCppStyleCommentsCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Lex/Preprocessor.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+class UseCppStyleCommentsCheck::CStyleCommentHandler : public CommentHandler {
+public:
+  CStyleCommentHandler(UseCppStyleCommentsCheck &Check)
+  : Check(Check),
+CStyleCommentMatch(
+"^[ \t]*/\\*+[ \t\n]*(.*[ \t\n]*)*[ \t\n]*\\*+/[ \t\n]*$") {}
+
+  bool HandleComment(Preprocessor &PP, SourceRange Range) override {
+
+if (Range.getBegin().isMacroID() ||
+PP.getSourceManager().isInSystemHeader(Range.getBegin()))
+  return false;
+
+const StringRef Text =
+Lexer::getSourceText(CharSourceRange::getCharRange(Range),
+ PP.getSourceManager(), PP.getLangOpts());
+
+SmallVector Matches;
+if (!CStyleCommentMatch.match(Text, &Matches)) {
+  return false;
+}
+
+Check.diag(
+Range.getBegin(),
+"use C++ style comments '//' instead of C style comments '/*...*/'")
+<< FixItHint::CreateRemoval(CharSourceRange::getCharRange(Range));
+
+return false;
+  }
+
+private:
+  UseCppStyleCommentsCheck &Check;
+  llvm::Regex CStyleCommentMatch;
+};
+
+UseCppStyleCommentsCheck::UseCppStyleCommentsCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  Handler(std::make_unique(*this)) {}
+
+void UseCppS

[clang-tools-extra] [clang-tidy] (PR #99713)

2024-07-19 Thread NagaChaitanya Vellanki via cfe-commits

https://github.com/chaitanyav updated 
https://github.com/llvm/llvm-project/pull/99713

>From 0bee2b58078e616d7be558dd09db5ca3deef3f4c Mon Sep 17 00:00:00 2001
From: NagaChaitanya Vellanki 
Date: Fri, 19 Jul 2024 14:26:23 -0700
Subject: [PATCH] [clang-tidy]

  modernize-use-cpp-style-comments check finds C style comments
  and suggests to use C++ style comments

  Fixes #24841
---
 .../clang-tidy/modernize/CMakeLists.txt   |  1 +
 .../modernize/ModernizeTidyModule.cpp |  3 +
 .../modernize/UseCppStyleCommentsCheck.cpp| 66 +++
 .../modernize/UseCppStyleCommentsCheck.h  | 38 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../modernize/use-cpp-style-comments.rst  | 12 
 .../modernize/use-cpp-style-comments.cpp  | 16 +
 7 files changed, 141 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-cpp-style-comments.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-cpp-style-comments.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 4f68c487cac9d..04a1d04cc333e 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -31,6 +31,7 @@ add_clang_library(clangTidyModernizeModule
   UseAutoCheck.cpp
   UseBoolLiteralsCheck.cpp
   UseConstraintsCheck.cpp
+  UseCppStyleCommentsCheck.cpp
   UseDefaultMemberInitCheck.cpp
   UseDesignatedInitializersCheck.cpp
   UseEmplaceCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 1860759332063..39995a32133b3 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -32,6 +32,7 @@
 #include "UseAutoCheck.h"
 #include "UseBoolLiteralsCheck.h"
 #include "UseConstraintsCheck.h"
+#include "UseCppStyleCommentsCheck.h"
 #include "UseDefaultMemberInitCheck.h"
 #include "UseDesignatedInitializersCheck.h"
 #include "UseEmplaceCheck.h"
@@ -104,6 +105,8 @@ class ModernizeModule : public ClangTidyModule {
 "modernize-use-bool-literals");
 CheckFactories.registerCheck(
 "modernize-use-constraints");
+CheckFactories.registerCheck(
+"modernize-use-cpp-style-comments");
 CheckFactories.registerCheck(
 "modernize-use-default-member-init");
 CheckFactories.registerCheck("modernize-use-emplace");
diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp
new file mode 100644
index 0..51dfade69b91b
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp
@@ -0,0 +1,66 @@
+//===--- UseCppStyleCommentsCheck.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 "UseCppStyleCommentsCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Lex/Preprocessor.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+class UseCppStyleCommentsCheck::CStyleCommentHandler : public CommentHandler {
+public:
+  CStyleCommentHandler(UseCppStyleCommentsCheck &Check)
+  : Check(Check),
+CStyleCommentMatch(
+"^[ \t]*/\\*+[ \t\n]*(.*[ \t\n]*)*[ \t\n]*\\*+/[ \t\n]*$") {}
+
+  bool HandleComment(Preprocessor &PP, SourceRange Range) override {
+
+if (Range.getBegin().isMacroID() ||
+PP.getSourceManager().isInSystemHeader(Range.getBegin()))
+  return false;
+
+const StringRef Text =
+Lexer::getSourceText(CharSourceRange::getCharRange(Range),
+ PP.getSourceManager(), PP.getLangOpts());
+
+SmallVector Matches;
+if (!CStyleCommentMatch.match(Text, &Matches)) {
+  return false;
+}
+
+Check.diag(
+Range.getBegin(),
+"use C++ style comments '//' instead of C style comments '/*...*/'")
+<< FixItHint::CreateRemoval(CharSourceRange::getCharRange(Range));
+
+return false;
+  }
+
+private:
+  UseCppStyleCommentsCheck &Check;
+  llvm::Regex CStyleCommentMatch;
+};
+
+UseCppStyleCommentsCheck::UseCppStyleCommentsCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  Handler(std::make_unique(*this)) {}
+
+void UseCpp

[clang-tools-extra] [clang-tidy] (PR #99713)

2024-07-19 Thread NagaChaitanya Vellanki via cfe-commits

https://github.com/chaitanyav updated 
https://github.com/llvm/llvm-project/pull/99713

>From 2899eab6f5d9bbed72a20b8da9e01ebccf7b576c Mon Sep 17 00:00:00 2001
From: NagaChaitanya Vellanki 
Date: Fri, 19 Jul 2024 14:26:23 -0700
Subject: [PATCH] [clang-tidy]

  modernize-use-cpp-style-comments check finds C style comments
  and suggests to use C++ style comments

  Fixes #24841
---
 .../clang-tidy/modernize/CMakeLists.txt   |  1 +
 .../modernize/ModernizeTidyModule.cpp |  3 +
 .../modernize/UseCppStyleCommentsCheck.cpp| 67 +++
 .../modernize/UseCppStyleCommentsCheck.h  | 38 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../modernize/use-cpp-style-comments.rst  | 12 
 .../modernize/use-cpp-style-comments.cpp  | 16 +
 7 files changed, 142 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-cpp-style-comments.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-cpp-style-comments.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 4f68c487cac9d..04a1d04cc333e 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -31,6 +31,7 @@ add_clang_library(clangTidyModernizeModule
   UseAutoCheck.cpp
   UseBoolLiteralsCheck.cpp
   UseConstraintsCheck.cpp
+  UseCppStyleCommentsCheck.cpp
   UseDefaultMemberInitCheck.cpp
   UseDesignatedInitializersCheck.cpp
   UseEmplaceCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 1860759332063..39995a32133b3 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -32,6 +32,7 @@
 #include "UseAutoCheck.h"
 #include "UseBoolLiteralsCheck.h"
 #include "UseConstraintsCheck.h"
+#include "UseCppStyleCommentsCheck.h"
 #include "UseDefaultMemberInitCheck.h"
 #include "UseDesignatedInitializersCheck.h"
 #include "UseEmplaceCheck.h"
@@ -104,6 +105,8 @@ class ModernizeModule : public ClangTidyModule {
 "modernize-use-bool-literals");
 CheckFactories.registerCheck(
 "modernize-use-constraints");
+CheckFactories.registerCheck(
+"modernize-use-cpp-style-comments");
 CheckFactories.registerCheck(
 "modernize-use-default-member-init");
 CheckFactories.registerCheck("modernize-use-emplace");
diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp
new file mode 100644
index 0..5b6a9e556bd0f
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp
@@ -0,0 +1,67 @@
+//===--- UseCppStyleCommentsCheck.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 "UseCppStyleCommentsCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Lex/Preprocessor.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+class UseCppStyleCommentsCheck::CStyleCommentHandler : public CommentHandler {
+public:
+  CStyleCommentHandler(UseCppStyleCommentsCheck &Check)
+  : Check(Check),
+CStyleCommentMatch(
+"^[ \t]*/\\*+[ \t\n]*(.*[ \t\n]*)*[ \t\n]*\\*+/[ \t\n]*$") {}
+
+  bool HandleComment(Preprocessor &PP, SourceRange Range) override {
+
+if (Range.getBegin().isMacroID() ||
+PP.getSourceManager().isInSystemHeader(Range.getBegin()))
+  return false;
+
+const StringRef Text =
+Lexer::getSourceText(CharSourceRange::getCharRange(Range),
+ PP.getSourceManager(), PP.getLangOpts());
+
+SmallVector Matches;
+if (!CStyleCommentMatch.match(Text, &Matches)) {
+  return false;
+}
+
+Check.diag(
+Range.getBegin(),
+"use C++ style comments '//' instead of C style comments '/*...*/'")
+<< FixItHint::CreateRemoval(CharSourceRange::getCharRange(Range));
+
+return false;
+  }
+
+private:
+  UseCppStyleCommentsCheck &Check;
+  llvm::Regex CStyleCommentMatch;
+};
+
+UseCppStyleCommentsCheck::UseCppStyleCommentsCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  Handler(std::make_unique(*this)) {}
+
+void UseCppSt

[clang-tools-extra] [clang-tidy] Add modernize-use-cpp-style-comments check (PR #99713)

2024-07-19 Thread NagaChaitanya Vellanki via cfe-commits

https://github.com/chaitanyav edited 
https://github.com/llvm/llvm-project/pull/99713
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add modernize-use-cpp-style-comments check (PR #99713)

2024-07-21 Thread NagaChaitanya Vellanki via cfe-commits

https://github.com/chaitanyav updated 
https://github.com/llvm/llvm-project/pull/99713

>From 2d45f8196e99c3b6f5a75db6e5e3df7ce1fd8aef Mon Sep 17 00:00:00 2001
From: NagaChaitanya Vellanki 
Date: Fri, 19 Jul 2024 14:26:23 -0700
Subject: [PATCH] [clang-tidy] Add modernize-use-cpp-style-comments check

  modernize-use-cpp-style-comments check finds C style comments
  and suggests to use C++ style comments

  Fixes #24841
---
 .../clang-tidy/modernize/CMakeLists.txt   |  1 +
 .../modernize/ModernizeTidyModule.cpp |  3 +
 .../modernize/UseCppStyleCommentsCheck.cpp| 67 +++
 .../modernize/UseCppStyleCommentsCheck.h  | 40 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../modernize/use-cpp-style-comments.rst  |  6 ++
 .../modernize/use-cpp-style-comments.cpp  |  7 ++
 7 files changed, 129 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-cpp-style-comments.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-cpp-style-comments.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 4f68c487cac9d..04a1d04cc333e 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -31,6 +31,7 @@ add_clang_library(clangTidyModernizeModule
   UseAutoCheck.cpp
   UseBoolLiteralsCheck.cpp
   UseConstraintsCheck.cpp
+  UseCppStyleCommentsCheck.cpp
   UseDefaultMemberInitCheck.cpp
   UseDesignatedInitializersCheck.cpp
   UseEmplaceCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 1860759332063..39995a32133b3 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -32,6 +32,7 @@
 #include "UseAutoCheck.h"
 #include "UseBoolLiteralsCheck.h"
 #include "UseConstraintsCheck.h"
+#include "UseCppStyleCommentsCheck.h"
 #include "UseDefaultMemberInitCheck.h"
 #include "UseDesignatedInitializersCheck.h"
 #include "UseEmplaceCheck.h"
@@ -104,6 +105,8 @@ class ModernizeModule : public ClangTidyModule {
 "modernize-use-bool-literals");
 CheckFactories.registerCheck(
 "modernize-use-constraints");
+CheckFactories.registerCheck(
+"modernize-use-cpp-style-comments");
 CheckFactories.registerCheck(
 "modernize-use-default-member-init");
 CheckFactories.registerCheck("modernize-use-emplace");
diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp
new file mode 100644
index 0..ed57d36644fb6
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp
@@ -0,0 +1,67 @@
+//===--- UseCppStyleCommentsCheck.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 "UseCppStyleCommentsCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Lex/Preprocessor.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+  class UseCppStyleCommentsCheck::CStyleCommentHandler : public CommentHandler 
{
+  public:
+CStyleCommentHandler(UseCppStyleCommentsCheck &Check)
+  : Check(Check),
+CStyleCommentMatch(
+  "^[ \t]*/\\*+[ \t\n]*(.*[ \t\n]*)*[ \t\n]*\\*+/[ \t\n]*$") {
+}
+
+bool HandleComment(Preprocessor &PP, SourceRange Range) override {
+  if (Range.getBegin().isMacroID() ||
+  PP.getSourceManager().isInSystemHeader(Range.getBegin()))
+return false;
+
+  const StringRef Text =
+  Lexer::getSourceText(CharSourceRange::getCharRange(Range),
+   PP.getSourceManager(), PP.getLangOpts());
+
+  SmallVector Matches;
+  if (!CStyleCommentMatch.match(Text, &Matches)) {
+return false;
+  }
+
+  Check.diag(
+Range.getBegin(),
+"use C++ style comments '//' instead of C style comments '/*...*/'");
+
+  return false;
+}
+
+  private:
+UseCppStyleCommentsCheck &Check;
+llvm::Regex CStyleCommentMatch;
+  };
+
+  UseCppStyleCommentsCheck::UseCppStyleCommentsCheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  Handler(std::make_unique(*this)) {
+  }

[clang-tools-extra] [clang-tidy] Add modernize-use-cpp-style-comments check (PR #99713)

2024-07-21 Thread NagaChaitanya Vellanki via cfe-commits

https://github.com/chaitanyav updated 
https://github.com/llvm/llvm-project/pull/99713

>From 670bf7aa89e06c2aac03dead4b980a01fe0d9426 Mon Sep 17 00:00:00 2001
From: NagaChaitanya Vellanki 
Date: Fri, 19 Jul 2024 14:26:23 -0700
Subject: [PATCH] [clang-tidy] Add modernize-use-cpp-style-comments check

  modernize-use-cpp-style-comments check finds C style comments
  and suggests to use C++ style comments

  Fixes #24841
---
 .../clang-tidy/modernize/CMakeLists.txt   |  1 +
 .../modernize/ModernizeTidyModule.cpp |  3 +
 .../modernize/UseCppStyleCommentsCheck.cpp| 64 +++
 .../modernize/UseCppStyleCommentsCheck.h  | 40 
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../modernize/use-cpp-style-comments.rst  |  6 ++
 .../modernize/use-cpp-style-comments.cpp  |  7 ++
 7 files changed, 126 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-cpp-style-comments.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-cpp-style-comments.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 4f68c487cac9d..04a1d04cc333e 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -31,6 +31,7 @@ add_clang_library(clangTidyModernizeModule
   UseAutoCheck.cpp
   UseBoolLiteralsCheck.cpp
   UseConstraintsCheck.cpp
+  UseCppStyleCommentsCheck.cpp
   UseDefaultMemberInitCheck.cpp
   UseDesignatedInitializersCheck.cpp
   UseEmplaceCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 1860759332063..39995a32133b3 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -32,6 +32,7 @@
 #include "UseAutoCheck.h"
 #include "UseBoolLiteralsCheck.h"
 #include "UseConstraintsCheck.h"
+#include "UseCppStyleCommentsCheck.h"
 #include "UseDefaultMemberInitCheck.h"
 #include "UseDesignatedInitializersCheck.h"
 #include "UseEmplaceCheck.h"
@@ -104,6 +105,8 @@ class ModernizeModule : public ClangTidyModule {
 "modernize-use-bool-literals");
 CheckFactories.registerCheck(
 "modernize-use-constraints");
+CheckFactories.registerCheck(
+"modernize-use-cpp-style-comments");
 CheckFactories.registerCheck(
 "modernize-use-default-member-init");
 CheckFactories.registerCheck("modernize-use-emplace");
diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp
new file mode 100644
index 0..4b1c84031e672
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseCppStyleCommentsCheck.cpp
@@ -0,0 +1,64 @@
+//===--- UseCppStyleCommentsCheck.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 "UseCppStyleCommentsCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Lex/Preprocessor.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+class UseCppStyleCommentsCheck::CStyleCommentHandler : public CommentHandler {
+public:
+  CStyleCommentHandler(UseCppStyleCommentsCheck &Check)
+  : Check(Check),
+CStyleCommentMatch(
+"^[ \t]*/\\*+[ \t\n]*(.*[ \t\n]*)*[ \t\n]*\\*+/[ \t\n]*$") {}
+
+  bool HandleComment(Preprocessor &PP, SourceRange Range) override {
+if (Range.getBegin().isMacroID() ||
+PP.getSourceManager().isInSystemHeader(Range.getBegin()))
+  return false;
+
+const StringRef Text =
+Lexer::getSourceText(CharSourceRange::getCharRange(Range),
+ PP.getSourceManager(), PP.getLangOpts());
+
+SmallVector Matches;
+if (!CStyleCommentMatch.match(Text, &Matches)) {
+  return false;
+}
+
+Check.diag(
+Range.getBegin(),
+"use C++ style comments '//' instead of C style comments '/*...*/'");
+
+return false;
+  }
+
+private:
+  UseCppStyleCommentsCheck &Check;
+  llvm::Regex CStyleCommentMatch;
+};
+
+UseCppStyleCommentsCheck::UseCppStyleCommentsCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  Handler(std::make_unique(*this)) {}
+
+void UseCppStyleCommentsCheck::registerPPCallbacks(