[PATCH] D146897: [clang:diagnostics] Turning off warn_self_assignment_overloaded for user-defined compound assignments

2023-03-25 Thread Xiang Li via Phabricator via cfe-commits
python3kgae created this revision.
python3kgae added reviewers: rjmccall, Quuxplusone, riccibruno.
Herald added a project: All.
python3kgae requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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

Only check self assignment on BO_Assign when BuildOverloadedBinOp.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146897

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/warn-self-assign-overloaded.cpp


Index: clang/test/SemaCXX/warn-self-assign-overloaded.cpp
===
--- clang/test/SemaCXX/warn-self-assign-overloaded.cpp
+++ clang/test/SemaCXX/warn-self-assign-overloaded.cpp
@@ -53,15 +53,15 @@
 
 #ifndef DUMMY
   a *= a;
-  a /= a; // expected-warning {{explicitly assigning}}
-  a %= a; // expected-warning {{explicitly assigning}}
+  a /= a;
+  a %= a;
   a += a;
-  a -= a; // expected-warning {{explicitly assigning}}
+  a -= a;
   a <<= a;
   a >>= a;
-  a &= a; // expected-warning {{explicitly assigning}}
-  a |= a; // expected-warning {{explicitly assigning}}
-  a ^= a; // expected-warning {{explicitly assigning}}
+  a &= a;
+  a |= a;
+  a ^= a;
 #endif
 }
 
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -15644,13 +15644,15 @@
Expr *LHS, Expr *RHS) {
   switch (Opc) {
   case BO_Assign:
+// Skip diagnose on compound assignment.
+DiagnoseSelfAssignment(S, LHS, RHS, OpLoc, false);
+[[fallthrough]];
   case BO_DivAssign:
   case BO_RemAssign:
   case BO_SubAssign:
   case BO_AndAssign:
   case BO_OrAssign:
   case BO_XorAssign:
-DiagnoseSelfAssignment(S, LHS, RHS, OpLoc, false);
 CheckIdentityFieldAssignment(LHS, RHS, OpLoc, S);
 break;
   default:


Index: clang/test/SemaCXX/warn-self-assign-overloaded.cpp
===
--- clang/test/SemaCXX/warn-self-assign-overloaded.cpp
+++ clang/test/SemaCXX/warn-self-assign-overloaded.cpp
@@ -53,15 +53,15 @@
 
 #ifndef DUMMY
   a *= a;
-  a /= a; // expected-warning {{explicitly assigning}}
-  a %= a; // expected-warning {{explicitly assigning}}
+  a /= a;
+  a %= a;
   a += a;
-  a -= a; // expected-warning {{explicitly assigning}}
+  a -= a;
   a <<= a;
   a >>= a;
-  a &= a; // expected-warning {{explicitly assigning}}
-  a |= a; // expected-warning {{explicitly assigning}}
-  a ^= a; // expected-warning {{explicitly assigning}}
+  a &= a;
+  a |= a;
+  a ^= a;
 #endif
 }
 
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -15644,13 +15644,15 @@
Expr *LHS, Expr *RHS) {
   switch (Opc) {
   case BO_Assign:
+// Skip diagnose on compound assignment.
+DiagnoseSelfAssignment(S, LHS, RHS, OpLoc, false);
+[[fallthrough]];
   case BO_DivAssign:
   case BO_RemAssign:
   case BO_SubAssign:
   case BO_AndAssign:
   case BO_OrAssign:
   case BO_XorAssign:
-DiagnoseSelfAssignment(S, LHS, RHS, OpLoc, false);
 CheckIdentityFieldAssignment(LHS, RHS, OpLoc, S);
 break;
   default:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146385: [clang][ExtractAPI] Complete declaration fragments for TagDecl types defined in a typedef

2023-03-25 Thread R4444 via Phabricator via cfe-commits
Ruturaj4 marked 2 inline comments as done.
Ruturaj4 added inline comments.



Comment at: clang/lib/ExtractAPI/ExtractAPIVisitor.cpp:347
+if (TagTy->getDecl()->isStruct()) {
+  for (const auto  : API.getStructs()) {
+if (Decl->getName() == Struct.second.get()->Name) {

dang wrote:
> What happens if the visitation hasn't already encountered the definition of 
> the struct? We wouldn't find it in the the APISet and this doesn't work. The 
> approach I would suggest here is to generate the fragments for the underlying 
> Decl directly. For example what happens for the following code:
> 
> ```c
> struct Foo;
> typedef struct Foo TypedefedFoo;
> struct Foo {
> int bar;
> };
> ```
Actually added an example for this. Our code works fine. Please take a look.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146385

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


[PATCH] D146891: [Driver][NetBSD] Simplify NetBSD version handling

2023-03-25 Thread Brad Smith via Phabricator via cfe-commits
brad updated this revision to Diff 508376.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146891

Files:
  clang/lib/Driver/ToolChains/NetBSD.cpp
  clang/test/Driver/netbsd.c
  clang/test/Driver/netbsd.cpp

Index: clang/test/Driver/netbsd.cpp
===
--- clang/test/Driver/netbsd.cpp
+++ clang/test/Driver/netbsd.cpp
@@ -4,12 +4,6 @@
 // RUN: %clangxx --target=x86_64-unknown-netbsd7.0.0 \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=X86_64-7 %s
-// RUN: %clangxx --target=x86_64-unknown-netbsd6.0.0 \
-// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=X86_64-6 %s
-// RUN: %clangxx --target=arm-unknown-netbsd6.0.0-eabi \
-// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=ARM %s
 // RUN: %clangxx --target=arm-unknown-netbsd7.0.0-eabi \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=ARM-7 %s
@@ -28,18 +22,12 @@
 // RUN: %clangxx --target=sparc-unknown-netbsd \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=SPARC %s
-// RUN: %clangxx --target=sparc-unknown-netbsd6.0.0 \
-// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=SPARC-6 %s
 // RUN: %clangxx --target=sparc-unknown-netbsd7.0.0 \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=SPARC-7 %s
 // RUN: %clangxx --target=sparc64-unknown-netbsd \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=SPARC64 %s
-// RUN: %clangxx --target=sparc64-unknown-netbsd6.0.0 \
-// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=SPARC64-6 %s
 // RUN: %clangxx --target=sparc64-unknown-netbsd7.0.0 \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=SPARC64-7 %s
@@ -56,12 +44,6 @@
 // RUN: %clangxx --target=x86_64-unknown-netbsd7.0.0 -static \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=S-X86_64-7 %s
-// RUN: %clangxx --target=x86_64-unknown-netbsd6.0.0 -static \
-// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=S-X86_64-6 %s
-// RUN: %clangxx --target=arm-unknown-netbsd6.0.0-eabi -static \
-// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=S-ARM %s
 // RUN: %clangxx --target=arm-unknown-netbsd7.0.0-eabi -static \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=S-ARM-7 %s
@@ -80,18 +62,12 @@
 // RUN: %clangxx --target=sparc-unknown-netbsd -static \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=S-SPARC %s
-// RUN: %clangxx --target=sparc-unknown-netbsd6.0.0 -static \
-// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=S-SPARC-6 %s
 // RUN: %clangxx --target=sparc-unknown-netbsd7.0.0 -static \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=S-SPARC-7 %s
 // RUN: %clangxx --target=sparc64-unknown-netbsd -static \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=S-SPARC64 %s
-// RUN: %clangxx --target=sparc64-unknown-netbsd6.0.0 -static \
-// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=S-SPARC64-6 %s
 // RUN: %clangxx --target=sparc64-unknown-netbsd7.0.0 -static \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=S-SPARC64-7 %s
@@ -114,20 +90,6 @@
 // X86_64-7: "{{.*}}/usr/lib{{/|}}crtbegin.o" "{{.*}}.o" "-lc++"
 // X86_64-7: "-lm" "-lc" "{{.*}}/usr/lib{{/|}}crtend.o" "{{.*}}/usr/lib{{/|}}crtn.o"
 
-// X86_64-6: "-cc1" "-triple" "x86_64-unknown-netbsd6.0.0"
-// X86_64-6: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld.elf_so"
-// X86_64-6: "-o" "a.out" "{{.*}}/usr/lib{{/|}}crt0.o" "{{.*}}/usr/lib{{/|}}crti.o"
-// X86_64-6: "{{.*}}/usr/lib{{/|}}crtbegin.o" "{{.*}}.o" "-lstdc++"
-// X86_64-6: "-lm" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed"
-// X86_64-6: "{{.*}}/usr/lib{{/|}}crtend.o" "{{.*}}/usr/lib{{/|}}crtn.o"
-
-// ARM: "-cc1" "-triple" "armv5e-unknown-netbsd6.0.0-eabi"
-// ARM: ld{{.*}}" "--eh-frame-hdr" 

[PATCH] D146385: [clang][ExtractAPI] Complete declaration fragments for TagDecl types defined in a typedef

2023-03-25 Thread R4444 via Phabricator via cfe-commits
Ruturaj4 updated this revision to Diff 508375.
Ruturaj4 added a comment.



1. Updating D146385 : [clang][ExtractAPI] 
Complete declaration fragments for TagDecl types defined in a typedef #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create

Made all updates as you requested, though I didn't need to generate fragments 
for the underlying Decl. I added an example as you have recommended.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146385

Files:
  clang/include/clang/ExtractAPI/DeclarationFragments.h
  clang/lib/ExtractAPI/ExtractAPIVisitor.cpp
  clang/test/ExtractAPI/typedef_struct_enum.c

Index: clang/test/ExtractAPI/typedef_struct_enum.c
===
--- clang/test/ExtractAPI/typedef_struct_enum.c
+++ clang/test/ExtractAPI/typedef_struct_enum.c
@@ -21,6 +21,12 @@
   simple
 } Test2;
 
+struct Foo;
+typedef struct Foo TypedefedFoo;
+struct Foo {
+int bar;
+};
+
 //--- reference.output.json.in
 {
   "metadata": {
@@ -36,6 +42,11 @@
 "platform": {
   "architecture": "arm64",
   "operatingSystem": {
+"minimumVersion": {
+  "major": 11,
+  "minor": 0,
+  "patch": 0
+},
 "name": "macosx"
   },
   "vendor": "apple"
@@ -47,6 +58,12 @@
   "source": "c:@E@Test2@simple",
   "target": "c:@E@Test2",
   "targetFallback": "Test2"
+},
+{
+  "kind": "memberOf",
+  "source": "c:@S@Foo@FI@bar",
+  "target": "c:@S@Foo",
+  "targetFallback": "Foo"
 }
   ],
   "symbols": [
@@ -82,6 +99,14 @@
   "preciseIdentifier": "c:i",
   "spelling": "unsigned int"
 },
+{
+  "kind": "text",
+  "spelling": " { ... } "
+},
+{
+  "kind": "identifier",
+  "spelling": "Test2"
+},
 {
   "kind": "text",
   "spelling": ";"
@@ -187,6 +212,14 @@
   "kind": "identifier",
   "spelling": "Test"
 },
+{
+  "kind": "text",
+  "spelling": " { ... } "
+},
+{
+  "kind": "identifier",
+  "spelling": "Test"
+},
 {
   "kind": "text",
   "spelling": ";"
@@ -225,6 +258,184 @@
   "pathComponents": [
 "Test"
   ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "struct"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "Foo"
+},
+{
+  "kind": "text",
+  "spelling": ";"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@S@Foo"
+  },
+  "kind": {
+"displayName": "Structure",
+"identifier": "c.struct"
+  },
+  "location": {
+"position": {
+  "character": 8,
+  "line": 10
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "Foo"
+  }
+],
+"title": "Foo"
+  },
+  "pathComponents": [
+"Foo"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:I",
+  "spelling": "int"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "bar"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "c",
+"precise": "c:@S@Foo@FI@bar"
+  },
+  "kind": {
+"displayName": "Instance Property",
+"identifier": "c.property"
+  },
+  "location": {
+"position": {
+  "character": 9,
+  "line": 11
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "bar"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "bar"
+  }
+],
+"title": "bar"
+  },
+  "pathComponents": [
+"Foo",
+"bar"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "typedef"
+},
+

[PATCH] D146891: [Driver][NetBSD] Simplify NetBSD version handling

2023-03-25 Thread Brad Smith via Phabricator via cfe-commits
brad updated this revision to Diff 508373.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146891

Files:
  clang/lib/Driver/ToolChains/NetBSD.cpp
  clang/test/Driver/netbsd.c
  clang/test/Driver/netbsd.cpp

Index: clang/test/Driver/netbsd.cpp
===
--- clang/test/Driver/netbsd.cpp
+++ clang/test/Driver/netbsd.cpp
@@ -4,12 +4,6 @@
 // RUN: %clangxx --target=x86_64-unknown-netbsd7.0.0 \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=X86_64-7 %s
-// RUN: %clangxx --target=x86_64-unknown-netbsd6.0.0 \
-// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=X86_64-6 %s
-// RUN: %clangxx --target=arm-unknown-netbsd6.0.0-eabi \
-// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=ARM %s
 // RUN: %clangxx --target=arm-unknown-netbsd7.0.0-eabi \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=ARM-7 %s
@@ -28,18 +22,12 @@
 // RUN: %clangxx --target=sparc-unknown-netbsd \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=SPARC %s
-// RUN: %clangxx --target=sparc-unknown-netbsd6.0.0 \
-// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=SPARC-6 %s
 // RUN: %clangxx --target=sparc-unknown-netbsd7.0.0 \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=SPARC-7 %s
 // RUN: %clangxx --target=sparc64-unknown-netbsd \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=SPARC64 %s
-// RUN: %clangxx --target=sparc64-unknown-netbsd6.0.0 \
-// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=SPARC64-6 %s
 // RUN: %clangxx --target=sparc64-unknown-netbsd7.0.0 \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=SPARC64-7 %s
@@ -56,12 +44,6 @@
 // RUN: %clangxx --target=x86_64-unknown-netbsd7.0.0 -static \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=S-X86_64-7 %s
-// RUN: %clangxx --target=x86_64-unknown-netbsd6.0.0 -static \
-// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=S-X86_64-6 %s
-// RUN: %clangxx --target=arm-unknown-netbsd6.0.0-eabi -static \
-// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=S-ARM %s
 // RUN: %clangxx --target=arm-unknown-netbsd7.0.0-eabi -static \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=S-ARM-7 %s
@@ -80,18 +62,12 @@
 // RUN: %clangxx --target=sparc-unknown-netbsd -static \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=S-SPARC %s
-// RUN: %clangxx --target=sparc-unknown-netbsd6.0.0 -static \
-// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=S-SPARC-6 %s
 // RUN: %clangxx --target=sparc-unknown-netbsd7.0.0 -static \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=S-SPARC-7 %s
 // RUN: %clangxx --target=sparc64-unknown-netbsd -static \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=S-SPARC64 %s
-// RUN: %clangxx --target=sparc64-unknown-netbsd6.0.0 -static \
-// RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
-// RUN: | FileCheck -check-prefix=S-SPARC64-6 %s
 // RUN: %clangxx --target=sparc64-unknown-netbsd7.0.0 -static \
 // RUN: -stdlib=platform --sysroot=%S/Inputs/basic_netbsd_tree -### %s 2>&1 \
 // RUN: | FileCheck -check-prefix=S-SPARC64-7 %s
@@ -114,13 +90,6 @@
 // X86_64-7: "{{.*}}/usr/lib{{/|}}crtbegin.o" "{{.*}}.o" "-lc++"
 // X86_64-7: "-lm" "-lc" "{{.*}}/usr/lib{{/|}}crtend.o" "{{.*}}/usr/lib{{/|}}crtn.o"
 
-// X86_64-6: "-cc1" "-triple" "x86_64-unknown-netbsd6.0.0"
-// X86_64-6: ld{{.*}}" "--eh-frame-hdr" "-dynamic-linker" "/libexec/ld.elf_so"
-// X86_64-6: "-o" "a.out" "{{.*}}/usr/lib{{/|}}crt0.o" "{{.*}}/usr/lib{{/|}}crti.o"
-// X86_64-6: "{{.*}}/usr/lib{{/|}}crtbegin.o" "{{.*}}.o" "-lstdc++"
-// X86_64-6: "-lm" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed"
-// X86_64-6: "{{.*}}/usr/lib{{/|}}crtend.o" "{{.*}}/usr/lib{{/|}}crtn.o"
-
 // ARM: "-cc1" "-triple" "armv5e-unknown-netbsd6.0.0-eabi"
 // ARM: ld{{.*}}" "--eh-frame-hdr" 

[PATCH] D146895: [clang-format] Don't annotate left brace of struct as FunctionLBrace

2023-03-25 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
owenpan added reviewers: MyDeveloperDay, HazardyKnusperkeks, rymiel.
owenpan added a project: clang-format.
Herald added a project: All.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Related to a02c3af9f19d 
. Fixes 
https://github.com/llvm/llvm-project/issues/61700.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146895

Files:
  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
@@ -366,6 +366,10 @@
   auto Tokens = annotate("struct S {};");
   EXPECT_EQ(Tokens.size(), 6u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::l_brace, TT_StructLBrace);
+
+  Tokens = annotate("struct EXPORT_MACRO [[nodiscard]] C { int i; };");
+  EXPECT_EQ(Tokens.size(), 15u) << Tokens;
+  EXPECT_TOKEN(Tokens[8], tok::l_brace, TT_StructLBrace);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUnions) {
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25275,6 +25275,11 @@
"};",
Style);
 
+  verifyFormat("struct EXPORT_MACRO [[nodiscard]] C {\n"
+   "  int i;\n"
+   "};",
+   Style);
+
   verifyIncompleteFormat("class C final [[deprecated(l]] {});", Style);
 
   // These tests are here to show a problem that may not be easily
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2596,16 +2596,17 @@
   // Handle AttributeMacro, e.g. `if (x) UNLIKELY`.
   if (FormatTok->is(TT_AttributeMacro))
 nextToken();
-  handleCppAttributes();
+  if (FormatTok->is(tok::l_square))
+handleCppAttributes();
 }
 
 bool UnwrappedLineParser::handleCppAttributes() {
   // Handle [[likely]] / [[unlikely]] attributes.
-  if (FormatTok->is(tok::l_square) && tryToParseSimpleAttribute()) {
-parseSquare();
-return true;
-  }
-  return false;
+  assert(FormatTok->is(tok::l_square));
+  if (!tryToParseSimpleAttribute())
+return false;
+  parseSquare();
+  return true;
 }
 
 /// Returns whether \c Tok begins a block.
@@ -3704,13 +3705,13 @@
 void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   const FormatToken  = *FormatTok;
   nextToken();
-  handleAttributes();
 
   // The actual identifier can be a nested name specifier, and in macros
   // it is often token-pasted.
+  // An [[attribute]] can be before the identifier.
   while (FormatTok->isOneOf(tok::identifier, tok::coloncolon, tok::hashhash,
 tok::kw___attribute, tok::kw___declspec,
-tok::kw_alignas) ||
+tok::kw_alignas, tok::l_square) ||
  ((Style.Language == FormatStyle::LK_Java || Style.isJavaScript()) &&
   FormatTok->isOneOf(tok::period, tok::comma))) {
 if (Style.isJavaScript() &&
@@ -3724,16 +3725,15 @@
 continue;
   }
 }
+if (FormatTok->is(tok::l_square))
+  handleCppAttributes();
 bool IsNonMacroIdentifier =
 FormatTok->is(tok::identifier) &&
 FormatTok->TokenText != FormatTok->TokenText.upper();
 nextToken();
 // We can have macros in between 'class' and the class name.
-if (!IsNonMacroIdentifier) {
-  if (FormatTok->is(tok::l_paren)) {
-parseParens();
-  }
-}
+if (!IsNonMacroIdentifier && FormatTok->is(tok::l_paren))
+  parseParens();
   }
 
   // Note that parsing away template declarations here leads to incorrectly


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -366,6 +366,10 @@
   auto Tokens = annotate("struct S {};");
   EXPECT_EQ(Tokens.size(), 6u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::l_brace, TT_StructLBrace);
+
+  Tokens = annotate("struct EXPORT_MACRO [[nodiscard]] C { int i; };");
+  EXPECT_EQ(Tokens.size(), 15u) << Tokens;
+  EXPECT_TOKEN(Tokens[8], tok::l_brace, TT_StructLBrace);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUnions) {
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25275,6 +25275,11 @@
"};",
Style);
 
+  verifyFormat("struct EXPORT_MACRO [[nodiscard]] 

[PATCH] D146760: [clang-format] Treat NTTP default values as expressions

2023-03-25 Thread Emilia Dreamer 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 rGbb4f6c4dca98: [clang-format] Treat NTTP default values as 
expressions (authored by rymiel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146760

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
@@ -253,6 +253,14 @@
 "};");
   ASSERT_EQ(Tokens.size(), 30u) << Tokens;
   EXPECT_TOKEN(Tokens[14], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("template  struct S {};");
+  ASSERT_EQ(Tokens.size(), 15u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("template  struct S {};");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_BinaryOperator);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1722,6 +1722,11 @@
   return false;
 }
 
+// This is the default value of a non-template type parameter, so treat
+// it as an expression.
+if (Contexts.back().ContextKind == tok::less)
+  return true;
+
 Tok = Tok->MatchingParen;
 if (!Tok)
   return false;


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -253,6 +253,14 @@
 "};");
   ASSERT_EQ(Tokens.size(), 30u) << Tokens;
   EXPECT_TOKEN(Tokens[14], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("template  struct S {};");
+  ASSERT_EQ(Tokens.size(), 15u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("template  struct S {};");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_BinaryOperator);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1722,6 +1722,11 @@
   return false;
 }
 
+// This is the default value of a non-template type parameter, so treat
+// it as an expression.
+if (Contexts.back().ContextKind == tok::less)
+  return true;
+
 Tok = Tok->MatchingParen;
 if (!Tok)
   return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146281: [clang-format] Don't wrap struct return types as structs

2023-03-25 Thread Emilia Dreamer 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 rGa8d2bff290e1: [clang-format] Dont wrap struct return 
types as structs (authored by rymiel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146281

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -3205,10 +3205,13 @@
 format("try{foo();}catch(...){baz();}", Style));
 
   Style.BraceWrapping.AfterFunction = true;
+  Style.BraceWrapping.AfterStruct = false;
   Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_MultiLine;
   Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All;
   Style.ColumnLimit = 80;
   verifyFormat("void shortfunction() { bar(); }", Style);
+  verifyFormat("struct T shortfunction() { return bar(); }", Style);
+  verifyFormat("struct T {};", Style);
 
   Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
   verifyFormat("void shortfunction()\n"
@@ -3216,6 +3219,36 @@
"  bar();\n"
"}",
Style);
+  verifyFormat("struct T shortfunction()\n"
+   "{\n"
+   "  return bar();\n"
+   "}",
+   Style);
+  verifyFormat("struct T {};", Style);
+
+  Style.BraceWrapping.AfterFunction = false;
+  Style.BraceWrapping.AfterStruct = true;
+  Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All;
+  verifyFormat("void shortfunction() { bar(); }", Style);
+  verifyFormat("struct T shortfunction() { return bar(); }", Style);
+  verifyFormat("struct T\n"
+   "{\n"
+   "};",
+   Style);
+
+  Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
+  verifyFormat("void shortfunction() {\n"
+   "  bar();\n"
+   "}",
+   Style);
+  verifyFormat("struct T shortfunction() {\n"
+   "  return bar();\n"
+   "}",
+   Style);
+  verifyFormat("struct T\n"
+   "{\n"
+   "};",
+   Style);
 }
 
 TEST_F(FormatTest, BeforeWhile) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -4916,8 +4916,13 @@
   return true;
 }
 
-return (Line.startsWith(tok::kw_class) && Style.BraceWrapping.AfterClass) 
||
-   (Line.startsWith(tok::kw_struct) && 
Style.BraceWrapping.AfterStruct);
+// Don't attempt to interpret struct return types as structs.
+if (Right.isNot(TT_FunctionLBrace)) {
+  return (Line.startsWith(tok::kw_class) &&
+  Style.BraceWrapping.AfterClass) ||
+ (Line.startsWith(tok::kw_struct) &&
+  Style.BraceWrapping.AfterStruct);
+}
   }
 
   if (Left.is(TT_ObjCBlockLBrace) &&


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -3205,10 +3205,13 @@
 format("try{foo();}catch(...){baz();}", Style));
 
   Style.BraceWrapping.AfterFunction = true;
+  Style.BraceWrapping.AfterStruct = false;
   Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_MultiLine;
   Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All;
   Style.ColumnLimit = 80;
   verifyFormat("void shortfunction() { bar(); }", Style);
+  verifyFormat("struct T shortfunction() { return bar(); }", Style);
+  verifyFormat("struct T {};", Style);
 
   Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
   verifyFormat("void shortfunction()\n"
@@ -3216,6 +3219,36 @@
"  bar();\n"
"}",
Style);
+  verifyFormat("struct T shortfunction()\n"
+   "{\n"
+   "  return bar();\n"
+   "}",
+   Style);
+  verifyFormat("struct T {};", Style);
+
+  Style.BraceWrapping.AfterFunction = false;
+  Style.BraceWrapping.AfterStruct = true;
+  Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All;
+  verifyFormat("void shortfunction() { bar(); }", Style);
+  verifyFormat("struct T shortfunction() { return bar(); }", Style);
+  verifyFormat("struct T\n"
+   "{\n"
+   "};",
+   Style);
+
+  Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
+  verifyFormat("void shortfunction() {\n"
+   "  bar();\n"
+   "}",
+   Style);
+  verifyFormat("struct T shortfunction() {\n"
+   "  return bar();\n"
+   "}",
+   Style);
+  

[clang] bb4f6c4 - [clang-format] Treat NTTP default values as expressions

2023-03-25 Thread Emilia Dreamer via cfe-commits

Author: Emilia Dreamer
Date: 2023-03-26T04:39:10+03:00
New Revision: bb4f6c4dca98a47054117708015bb2724256ee83

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

LOG: [clang-format] Treat NTTP default values as expressions

clang-format already has logic to threat the right-hand side of an
equals sign. This patch applies that logic to template defaults,
which are likely to be non-template type parameters in which case the
default value should be annotated as an expression.
This should mostly only ever apply to bool and &&.

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

Reviewed By: MyDeveloperDay, owenpan

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index dfde6e4e0163..91f9d5719b5a 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1722,6 +1722,11 @@ class AnnotatingParser {
   return false;
 }
 
+// This is the default value of a non-template type parameter, so treat
+// it as an expression.
+if (Contexts.back().ContextKind == tok::less)
+  return true;
+
 Tok = Tok->MatchingParen;
 if (!Tok)
   return false;

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 997630d08e2e..94b3a77ed5a0 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -253,6 +253,14 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
 "};");
   ASSERT_EQ(Tokens.size(), 30u) << Tokens;
   EXPECT_TOKEN(Tokens[14], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("template  struct S {};");
+  ASSERT_EQ(Tokens.size(), 15u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("template  struct S {};");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_BinaryOperator);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) {



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


[PATCH] D145642: [clang-format] Annotate lambdas with requires clauses.

2023-03-25 Thread Emilia Dreamer 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 rG5409fb38372d: [clang-format] Annotate lambdas with requires 
clauses. (authored by rymiel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145642

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

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1279,6 +1279,110 @@
   EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
   EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
   EXPECT_TOKEN(Tokens[7], tok::l_brace, TT_LambdaLBrace);
+
+  // Lambdas with a requires-clause
+  Tokens = annotate("[]  (T t) requires Bar {}");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[10], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TRUE(Tokens[14]->ClosesRequiresClause);
+  EXPECT_TOKEN(Tokens[15], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  (T &) requires Bar {}");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[8], tok::ampamp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[11], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TRUE(Tokens[15]->ClosesRequiresClause);
+  EXPECT_TOKEN(Tokens[16], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  (T t) requires Foo || Bar {}");
+  ASSERT_EQ(Tokens.size(), 23u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[10], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TRUE(Tokens[19]->ClosesRequiresClause);
+  EXPECT_TOKEN(Tokens[20], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  (T t) -> T requires Bar {}");
+  ASSERT_EQ(Tokens.size(), 20u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[10], tok::arrow, TT_LambdaArrow);
+  EXPECT_TOKEN(Tokens[12], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TRUE(Tokens[16]->ClosesRequiresClause);
+  EXPECT_TOKEN(Tokens[17], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  requires Bar (T t) {}");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TRUE(Tokens[10]->ClosesRequiresClause);
+  EXPECT_TOKEN(Tokens[15], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  requires Bar (T &) {}");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TRUE(Tokens[10]->ClosesRequiresClause);
+  EXPECT_TOKEN(Tokens[13], tok::ampamp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[16], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  requires Foo || Bar (T t) {}");
+  ASSERT_EQ(Tokens.size(), 23u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TRUE(Tokens[15]->ClosesRequiresClause);
+  EXPECT_TOKEN(Tokens[20], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  requires true (T&& t) {}");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TRUE(Tokens[7]->ClosesRequiresClause);
+  EXPECT_TOKEN(Tokens[10], tok::ampamp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  requires Bar {}");
+  ASSERT_EQ(Tokens.size(), 14u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TRUE(Tokens[10]->ClosesRequiresClause);
+  EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  requires Bar noexcept {}");
+  ASSERT_EQ(Tokens.size(), 15u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[6], tok::kw_requires, 

[clang] 5409fb3 - [clang-format] Annotate lambdas with requires clauses.

2023-03-25 Thread Emilia Dreamer via cfe-commits

Author: Emilia Dreamer
Date: 2023-03-26T04:38:26+03:00
New Revision: 5409fb38372dbf65a94725ccefab2b993fbb7a9b

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

LOG: [clang-format] Annotate lambdas with requires clauses.

The C++ grammar allows lambdas to have a *requires-clause* in two
places, either directly after the *template-parameter-list*, such as:

`[]  requires foo (T t) { ... };`

Or, at the end of the *lambda-declarator* (before the lambda's body):

`[]  (T t) requires foo { ... };`

Previously, these cases weren't handled at all, resulting in weird
results.

Note that this commit only handles token annotation, so the actual
formatting still ends up suboptimal. This is mostly because I do not yet
know how to approach making the requires clause formatting of lambdas
match the formatting for functions.

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

Reviewed By: HazardyKnusperkeks, owenpan

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index f08a51f93e2f..9b17c28280f1 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2134,7 +2134,7 @@ bool UnwrappedLineParser::tryToParseLambda() {
 case tok::l_brace:
   break;
 case tok::l_paren:
-  parseParens();
+  parseParens(/*AmpAmpTokenType=*/TT_PointerOrReference);
   break;
 case tok::l_square:
   parseSquare();
@@ -2211,6 +2211,12 @@ bool UnwrappedLineParser::tryToParseLambda() {
   SeenArrow = true;
   nextToken();
   break;
+case tok::kw_requires: {
+  auto *RequiresToken = FormatTok;
+  nextToken();
+  parseRequiresClause(RequiresToken);
+  break;
+}
 default:
   return true;
 }
@@ -3371,6 +3377,17 @@ void UnwrappedLineParser::parseConstraintExpression() {
   // lambda to be possible.
   // template  requires requires { ... } [[nodiscard]] ...;
   bool LambdaNextTimeAllowed = true;
+
+  // Within lambda declarations, it is permitted to put a requires clause after
+  // its template parameter list, which would place the requires clause right
+  // before the parentheses of the parameters of the lambda declaration. Thus,
+  // we track if we expect to see grouping parentheses at all.
+  // Without this check, `requires foo (T t)` in the below example would be
+  // seen as the whole requires clause, accidentally eating the parameters of
+  // the lambda.
+  // [&] requires foo (T t) { ... };
+  bool TopLevelParensAllowed = true;
+
   do {
 bool LambdaThisTimeAllowed = std::exchange(LambdaNextTimeAllowed, false);
 
@@ -3383,7 +3400,10 @@ void UnwrappedLineParser::parseConstraintExpression() {
 }
 
 case tok::l_paren:
+  if (!TopLevelParensAllowed)
+return;
   parseParens(/*AmpAmpTokenType=*/TT_BinaryOperator);
+  TopLevelParensAllowed = false;
   break;
 
 case tok::l_square:
@@ -3407,6 +3427,7 @@ void UnwrappedLineParser::parseConstraintExpression() {
   FormatTok->setFinalizedType(TT_BinaryOperator);
   nextToken();
   LambdaNextTimeAllowed = true;
+  TopLevelParensAllowed = true;
   break;
 
 case tok::comma:
@@ -3430,6 +3451,7 @@ void UnwrappedLineParser::parseConstraintExpression() {
 case tok::star:
 case tok::slash:
   LambdaNextTimeAllowed = true;
+  TopLevelParensAllowed = true;
   // Just eat them.
   nextToken();
   break;
@@ -3438,6 +3460,7 @@ void UnwrappedLineParser::parseConstraintExpression() {
 case tok::coloncolon:
 case tok::kw_true:
 case tok::kw_false:
+  TopLevelParensAllowed = false;
   // Just eat them.
   nextToken();
   break;
@@ -3486,6 +3509,7 @@ void UnwrappedLineParser::parseConstraintExpression() {
 parseBracedList(/*ContinueOnSemicolons=*/false, /*IsEnum=*/false,
 /*ClosingBraceKind=*/tok::greater);
   }
+  TopLevelParensAllowed = false;
   break;
 }
   } while (!eof());

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 3a6fb0e9e4b3..997630d08e2e 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1279,6 +1279,110 @@ TEST_F(TokenAnnotatorTest, UnderstandsLambdas) {
   EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
   EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
   EXPECT_TOKEN(Tokens[7], tok::l_brace, TT_LambdaLBrace);
+
+  // Lambdas with a requires-clause
+  Tokens = annotate("[]  (T t) requires Bar {}");
+ 

[clang] a8d2bff - [clang-format] Don't wrap struct return types as structs

2023-03-25 Thread Emilia Dreamer via cfe-commits

Author: Emilia Dreamer
Date: 2023-03-26T04:38:52+03:00
New Revision: a8d2bff290e1b86b4bca4007493205b4878c4f68

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

LOG: [clang-format] Don't wrap struct return types as structs

When using BraceWrapping.AfterClass or BraceWrapping.AfterStruct, the
token annotator relies on the first token of the line to determine if
we're dealing with a struct or class, however, this check is faulty if
it's actually a function with an elaborated struct/class return type, as
is common in C.

This patch skips the check if the brace is already annotated as
FunctionLBrace, in which case we already know it's a function and should
be treated as such.

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

Reviewed By: HazardyKnusperkeks, owenpan

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index d7758e7d068d..dfde6e4e0163 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4916,8 +4916,13 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
,
   return true;
 }
 
-return (Line.startsWith(tok::kw_class) && Style.BraceWrapping.AfterClass) 
||
-   (Line.startsWith(tok::kw_struct) && 
Style.BraceWrapping.AfterStruct);
+// Don't attempt to interpret struct return types as structs.
+if (Right.isNot(TT_FunctionLBrace)) {
+  return (Line.startsWith(tok::kw_class) &&
+  Style.BraceWrapping.AfterClass) ||
+ (Line.startsWith(tok::kw_struct) &&
+  Style.BraceWrapping.AfterStruct);
+}
   }
 
   if (Left.is(TT_ObjCBlockLBrace) &&

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index eb1b563b3d2c..80efa8c4babf 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -3205,10 +3205,13 @@ TEST_F(FormatTest, MultiLineControlStatements) {
 format("try{foo();}catch(...){baz();}", Style));
 
   Style.BraceWrapping.AfterFunction = true;
+  Style.BraceWrapping.AfterStruct = false;
   Style.BraceWrapping.AfterControlStatement = FormatStyle::BWACS_MultiLine;
   Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All;
   Style.ColumnLimit = 80;
   verifyFormat("void shortfunction() { bar(); }", Style);
+  verifyFormat("struct T shortfunction() { return bar(); }", Style);
+  verifyFormat("struct T {};", Style);
 
   Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
   verifyFormat("void shortfunction()\n"
@@ -3216,6 +3219,36 @@ TEST_F(FormatTest, MultiLineControlStatements) {
"  bar();\n"
"}",
Style);
+  verifyFormat("struct T shortfunction()\n"
+   "{\n"
+   "  return bar();\n"
+   "}",
+   Style);
+  verifyFormat("struct T {};", Style);
+
+  Style.BraceWrapping.AfterFunction = false;
+  Style.BraceWrapping.AfterStruct = true;
+  Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All;
+  verifyFormat("void shortfunction() { bar(); }", Style);
+  verifyFormat("struct T shortfunction() { return bar(); }", Style);
+  verifyFormat("struct T\n"
+   "{\n"
+   "};",
+   Style);
+
+  Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
+  verifyFormat("void shortfunction() {\n"
+   "  bar();\n"
+   "}",
+   Style);
+  verifyFormat("struct T shortfunction() {\n"
+   "  return bar();\n"
+   "}",
+   Style);
+  verifyFormat("struct T\n"
+   "{\n"
+   "};",
+   Style);
 }
 
 TEST_F(FormatTest, BeforeWhile) {



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


[PATCH] D146892: [documentation]Fixed Random Typo

2023-03-25 Thread Ayushi Shukla via Phabricator via cfe-commits
ayushi-8102 created this revision.
ayushi-8102 added a reviewer: samtebbs.
Herald added a subscriber: dmgreen.
Herald added a reviewer: NoQ.
Herald added a project: All.
ayushi-8102 requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, cfe-commits, jplehr, sstefan1.
Herald added projects: clang, LLVM.

This patch fixes https://github.com/llvm/llvm-project/issues/56747


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146892

Files:
  clang/docs/AutomaticReferenceCounting.rst
  clang/docs/ConstantInterpreter.rst
  clang/docs/CrossCompilation.rst
  clang/docs/DataFlowAnalysisIntro.md
  clang/docs/DebuggingCoroutines.rst
  clang/docs/analyzer/developer-docs/nullability.rst
  clang/include/clang/AST/CXXInheritance.h
  clang/include/clang/AST/CommentSema.h
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/AST/DeclTemplate.h
  clang/include/clang/AST/DeclarationName.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/Analysis/Analyses/CalledOnceCheck.h
  clang/include/clang/Analysis/Analyses/Consumed.h
  llvm/test/CodeGen/Thumb2/mve-tailpred-nonzerostart.ll

Index: llvm/test/CodeGen/Thumb2/mve-tailpred-nonzerostart.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Thumb2/mve-tailpred-nonzerostart.ll
@@ -0,0 +1,291 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
+; RUN: llc -mtriple=thumbv8.1m.main-none-none-eabi -mattr=+mve.fp %s -o - | FileCheck %s
+
+define arm_aapcs_vfpcc void @start12(ptr nocapture readonly %x, ptr nocapture readonly %y, ptr noalias nocapture %z, float %a, i32 %n) {
+; CHECK-LABEL: start12:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:.save {r4, r5, r7, lr}
+; CHECK-NEXT:push {r4, r5, r7, lr}
+; CHECK-NEXT:cmp r3, #1
+; CHECK-NEXT:blt .LBB0_3
+; CHECK-NEXT:  @ %bb.1: @ %vector.ph
+; CHECK-NEXT:vmov r12, s0
+; CHECK-NEXT:adds r4, r3, #3
+; CHECK-NEXT:bic r4, r4, #3
+; CHECK-NEXT:adr r5, .LCPI0_0
+; CHECK-NEXT:sub.w lr, r4, #16
+; CHECK-NEXT:movs r4, #1
+; CHECK-NEXT:adds r0, #48
+; CHECK-NEXT:adds r1, #48
+; CHECK-NEXT:add.w lr, r4, lr, lsr #2
+; CHECK-NEXT:adds r2, #48
+; CHECK-NEXT:vldrw.u32 q0, [r5]
+; CHECK-NEXT:movs r4, #12
+; CHECK-NEXT:vdup.32 q1, r3
+; CHECK-NEXT:  .LBB0_2: @ %vector.body
+; CHECK-NEXT:@ =>This Inner Loop Header: Depth=1
+; CHECK-NEXT:vqadd.u32 q2, q0, r4
+; CHECK-NEXT:adds r4, #4
+; CHECK-NEXT:vptt.u32 hi, q1, q2
+; CHECK-NEXT:vldrwt.u32 q2, [r1], #16
+; CHECK-NEXT:vldrwt.u32 q3, [r0], #16
+; CHECK-NEXT:vfmas.f32 q3, q2, r12
+; CHECK-NEXT:vpst
+; CHECK-NEXT:vstrwt.32 q3, [r2], #16
+; CHECK-NEXT:le lr, .LBB0_2
+; CHECK-NEXT:  .LBB0_3: @ %for.cond.cleanup
+; CHECK-NEXT:pop {r4, r5, r7, pc}
+; CHECK-NEXT:.p2align 4
+; CHECK-NEXT:  @ %bb.4:
+; CHECK-NEXT:  .LCPI0_0:
+; CHECK-NEXT:.long 0 @ 0x0
+; CHECK-NEXT:.long 1 @ 0x1
+; CHECK-NEXT:.long 2 @ 0x2
+; CHECK-NEXT:.long 3 @ 0x3
+entry:
+  %cmp8 = icmp sgt i32 %n, 0
+  br i1 %cmp8, label %vector.ph, label %for.cond.cleanup
+
+vector.ph:; preds = %entry
+  %n.rnd.up = add i32 %n, 3
+  %n.vec = and i32 %n.rnd.up, -4
+  %broadcast.splatinsert13 = insertelement <4 x float> undef, float %a, i32 0
+  %broadcast.splat14 = shufflevector <4 x float> %broadcast.splatinsert13, <4 x float> undef, <4 x i32> zeroinitializer
+  br label %vector.body
+
+vector.body:  ; preds = %vector.body, %vector.ph
+  %index = phi i32 [ 12, %vector.ph ], [ %index.next, %vector.body ]
+  %0 = getelementptr inbounds float, ptr %x, i32 %index
+  %1 = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i32(i32 %index, i32 %n)
+  %wide.masked.load = call <4 x float> @llvm.masked.load.v4f32.p0(ptr %0, i32 4, <4 x i1> %1, <4 x float> undef)
+  %2 = getelementptr inbounds float, ptr %y, i32 %index
+  %wide.masked.load12 = call <4 x float> @llvm.masked.load.v4f32.p0(ptr %2, i32 4, <4 x i1> %1, <4 x float> undef)
+  %3 = call fast <4 x float> @llvm.fma.v4f32(<4 x float> %wide.masked.load, <4 x float> %wide.masked.load12, <4 x float> %broadcast.splat14)
+  %4 = getelementptr inbounds float, ptr %z, i32 %index
+  call void @llvm.masked.store.v4f32.p0(<4 x float> %3, ptr %4, i32 4, <4 x i1> %1)
+  %index.next = add i32 %index, 4
+  %5 = icmp eq i32 %index.next, %n.vec
+  br i1 %5, label %for.cond.cleanup, label %vector.body
+
+for.cond.cleanup: ; preds = %vector.body, %entry
+  ret void
+}
+
+
+define arm_aapcs_vfpcc void @start11(ptr nocapture readonly %x, ptr nocapture readonly %y, ptr noalias nocapture %z, float %a, i32 %n) {
+; CHECK-LABEL: start11:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:.save {r4, r5, r7, lr}
+; CHECK-NEXT:push {r4, r5, r7, lr}
+; CHECK-NEXT:cmp r3, #1
+; 

[PATCH] D146891: [Driver][NetBSD] Simplify NetBSD version handling

2023-03-25 Thread Brad Smith via Phabricator via cfe-commits
brad created this revision.
brad added a reviewer: fcambus.
brad added a project: clang.
Herald added subscribers: fedor.sergeev, krytarowski.
Herald added a project: All.
brad requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.

NetBSD 6.x and older is ancient. Remove now unnecessary version check.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146891

Files:
  clang/lib/Driver/ToolChains/NetBSD.cpp


Index: clang/lib/Driver/ToolChains/NetBSD.cpp
===
--- clang/lib/Driver/ToolChains/NetBSD.cpp
+++ clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -272,28 +272,25 @@
 CmdArgs.push_back(Args.MakeArgString(ToolChain.getCompilerRTPath()));
   }
 
-  VersionTuple OsVersion = Triple.getOSVersion();
   bool useLibgcc = true;
-  if (OsVersion >= VersionTuple(7) || OsVersion.getMajor() == 0) {
-switch (ToolChain.getArch()) {
-case llvm::Triple::aarch64:
-case llvm::Triple::aarch64_be:
-case llvm::Triple::arm:
-case llvm::Triple::armeb:
-case llvm::Triple::thumb:
-case llvm::Triple::thumbeb:
-case llvm::Triple::ppc:
-case llvm::Triple::ppc64:
-case llvm::Triple::ppc64le:
-case llvm::Triple::sparc:
-case llvm::Triple::sparcv9:
-case llvm::Triple::x86:
-case llvm::Triple::x86_64:
-  useLibgcc = false;
-  break;
-default:
-  break;
-}
+  switch (ToolChain.getArch()) {
+  case llvm::Triple::aarch64:
+  case llvm::Triple::aarch64_be:
+  case llvm::Triple::arm:
+  case llvm::Triple::armeb:
+  case llvm::Triple::thumb:
+  case llvm::Triple::thumbeb:
+  case llvm::Triple::ppc:
+  case llvm::Triple::ppc64:
+  case llvm::Triple::ppc64le:
+  case llvm::Triple::sparc:
+  case llvm::Triple::sparcv9:
+  case llvm::Triple::x86:
+  case llvm::Triple::x86_64:
+useLibgcc = false;
+break;
+  default:
+break;
   }
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
@@ -412,26 +409,23 @@
 Tool *NetBSD::buildLinker() const { return new tools::netbsd::Linker(*this); }
 
 ToolChain::CXXStdlibType NetBSD::GetDefaultCXXStdlibType() const {
-  VersionTuple OsVersion = getTriple().getOSVersion();
-  if (OsVersion >= VersionTuple(7) || OsVersion.getMajor() == 0) {
-switch (getArch()) {
-case llvm::Triple::aarch64:
-case llvm::Triple::aarch64_be:
-case llvm::Triple::arm:
-case llvm::Triple::armeb:
-case llvm::Triple::thumb:
-case llvm::Triple::thumbeb:
-case llvm::Triple::ppc:
-case llvm::Triple::ppc64:
-case llvm::Triple::ppc64le:
-case llvm::Triple::sparc:
-case llvm::Triple::sparcv9:
-case llvm::Triple::x86:
-case llvm::Triple::x86_64:
-  return ToolChain::CST_Libcxx;
-default:
-  break;
-}
+  switch (getArch()) {
+  case llvm::Triple::aarch64:
+  case llvm::Triple::aarch64_be:
+  case llvm::Triple::arm:
+  case llvm::Triple::armeb:
+  case llvm::Triple::thumb:
+  case llvm::Triple::thumbeb:
+  case llvm::Triple::ppc:
+  case llvm::Triple::ppc64:
+  case llvm::Triple::ppc64le:
+  case llvm::Triple::sparc:
+  case llvm::Triple::sparcv9:
+  case llvm::Triple::x86:
+  case llvm::Triple::x86_64:
+return ToolChain::CST_Libcxx;
+  default:
+break;
   }
   return ToolChain::CST_Libstdcxx;
 }


Index: clang/lib/Driver/ToolChains/NetBSD.cpp
===
--- clang/lib/Driver/ToolChains/NetBSD.cpp
+++ clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -272,28 +272,25 @@
 CmdArgs.push_back(Args.MakeArgString(ToolChain.getCompilerRTPath()));
   }
 
-  VersionTuple OsVersion = Triple.getOSVersion();
   bool useLibgcc = true;
-  if (OsVersion >= VersionTuple(7) || OsVersion.getMajor() == 0) {
-switch (ToolChain.getArch()) {
-case llvm::Triple::aarch64:
-case llvm::Triple::aarch64_be:
-case llvm::Triple::arm:
-case llvm::Triple::armeb:
-case llvm::Triple::thumb:
-case llvm::Triple::thumbeb:
-case llvm::Triple::ppc:
-case llvm::Triple::ppc64:
-case llvm::Triple::ppc64le:
-case llvm::Triple::sparc:
-case llvm::Triple::sparcv9:
-case llvm::Triple::x86:
-case llvm::Triple::x86_64:
-  useLibgcc = false;
-  break;
-default:
-  break;
-}
+  switch (ToolChain.getArch()) {
+  case llvm::Triple::aarch64:
+  case llvm::Triple::aarch64_be:
+  case llvm::Triple::arm:
+  case llvm::Triple::armeb:
+  case llvm::Triple::thumb:
+  case llvm::Triple::thumbeb:
+  case llvm::Triple::ppc:
+  case llvm::Triple::ppc64:
+  case llvm::Triple::ppc64le:
+  case llvm::Triple::sparc:
+  case llvm::Triple::sparcv9:
+  case llvm::Triple::x86:
+  case llvm::Triple::x86_64:
+useLibgcc = false;
+break;
+  default:
+break;
   }
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
@@ -412,26 +409,23 @@
 Tool *NetBSD::buildLinker() const { return new tools::netbsd::Linker(*this); }
 
 ToolChain::CXXStdlibType NetBSD::GetDefaultCXXStdlibType() 

[PATCH] D146889: [documentation]Fixed Random Typos

2023-03-25 Thread Ayushi Shukla via Phabricator via cfe-commits
ayushi-8102 created this revision.
ayushi-8102 added a reviewer: samtebbs.
Herald added a reviewer: NoQ.
Herald added a project: All.
ayushi-8102 requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, jplehr, sstefan1.
Herald added a project: clang.

This patch fixes https://github.com/llvm/llvm-project/issues/56747


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146889

Files:
  clang/docs/AutomaticReferenceCounting.rst
  clang/docs/ConstantInterpreter.rst
  clang/docs/CrossCompilation.rst
  clang/docs/DataFlowAnalysisIntro.md
  clang/docs/DebuggingCoroutines.rst
  clang/docs/analyzer/developer-docs/nullability.rst
  clang/include/clang/AST/CXXInheritance.h
  clang/include/clang/AST/CommentSema.h
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/AST/DeclTemplate.h
  clang/include/clang/AST/DeclarationName.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/Analysis/Analyses/CalledOnceCheck.h
  clang/include/clang/Analysis/Analyses/Consumed.h
  clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
  clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-deref.cpp

Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-deref.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-deref.cpp
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+
+void basic_dereference() {
+  int tmp;
+  auto p = new int[10];
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span p"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}"
+  tmp = p[5];
+  int val = *p;
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:13-[[@LINE-1]]:14}:""
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:15-[[@LINE-2]]:15}:"[0]"
+}
+
+int return_method() {
+  auto p = new int[10];
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span p"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}"
+  int tmp = p[5];
+  return *p;
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:11}:""
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"[0]"
+}
+
+void foo(int v) {
+}
+
+void method_invocation() {
+  auto p = new int[10];
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span p"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}"
+
+  int tmp = p[5];
+
+  foo(*p);
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:""
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:9-[[@LINE-2]]:9}:"[0]"
+}
+
+void binary_operation() {
+  auto p = new int[10];
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span p"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}"
+
+  int tmp = p[5];
+
+  int k = *p + 20;
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:12}:""
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:13-[[@LINE-2]]:13}:"[0]"
+
+}
+
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -463,6 +463,45 @@
 return {};
   }
 };
+
+class PointerDereferenceGadget : public FixableGadget {
+  static constexpr const char *const BaseDeclRefExprTag = "BaseDRE";
+  static constexpr const char *const OperatorTag = "op";
+
+  const DeclRefExpr *BaseDeclRefExpr = nullptr;
+  const UnaryOperator *Op = nullptr;
+
+public:
+  PointerDereferenceGadget(const MatchFinder::MatchResult )
+  : FixableGadget(Kind::PointerDereference),
+BaseDeclRefExpr(
+Result.Nodes.getNodeAs(BaseDeclRefExprTag)),
+Op(Result.Nodes.getNodeAs(OperatorTag)) {}
+
+  static bool classof(const Gadget *G) {
+return G->getKind() == Kind::PointerDereference;
+  }
+
+  static Matcher matcher() {
+auto Target =
+unaryOperator(
+hasOperatorName("*"),
+has(expr(ignoringParenImpCasts(
+declRefExpr(to(varDecl())).bind(BaseDeclRefExprTag)
+.bind(OperatorTag);
+
+return expr(isInUnspecifiedLvalueContext(Target));
+  }
+
+  DeclUseList getClaimedVarUseSites() const override {
+return {BaseDeclRefExpr};
+  }
+
+  virtual const Stmt *getBaseStmt() const final { return Op; }
+
+  virtual std::optional getFixits(const Strategy ) const override;
+};
+
 } // namespace
 
 namespace {
@@ 

[PATCH] D144157: Add 128-bit integer support to enum element

2023-03-25 Thread zhouyizhou via Phabricator via cfe-commits
zhouyizhou updated this revision to Diff 508350.
zhouyizhou added a comment.

Add 128-bit integer support to enum element like GCC extension do.
Also test coverage around _BitInt which can be arbitrarily large depending on 
the target.
Also leave room for improvements to C2X because C2x made changes in this area 
to how we calculate what type to represent the enumerations in.

Signed-off-by: Zhouyi Zhou 


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

https://reviews.llvm.org/D144157

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/AST/Interp/enums-targets.cpp
  clang/test/CXX/drs/dr3xx.cpp
  clang/test/CodeGen/enum2.c
  clang/test/Sema/enum.c

Index: clang/test/Sema/enum.c
===
--- clang/test/Sema/enum.c
+++ clang/test/Sema/enum.c
@@ -14,7 +14,7 @@
 };
 
 // minll maxull
-enum x  // expected-warning {{enumeration values exceed range of largest integer}}
+enum x  
 { y = -9223372036854775807LL-1,  // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
 z = 9223372036854775808ULL };// expected-warning {{ISO C restricts enumerator values to range of 'int'}}
 
Index: clang/test/CodeGen/enum2.c
===
--- clang/test/CodeGen/enum2.c
+++ clang/test/CodeGen/enum2.c
@@ -1,15 +1,43 @@
-// RUN: %clang_cc1 -triple i386-unknown-unknown %s -debug-info-kind=limited -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu %s -debug-info-kind=limited -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c2x -triple x86_64-linux-gnu %s -debug-info-kind=limited -emit-llvm -o - | FileCheck %s
 
 int v;
 enum e { MAX };
 
+__uint128_t v1;
+enum b {
+   b0 = (__uint128_t)0x123456789abcdef0ULL << 64|0x0fedcba987654321ULL,
+};
+
+#if __STDC_VERSION__ >= 202000L
+_BitInt(256) v2;
+enum c {
+  c0 = 0x''''''''1wb
+  // TODO: check c0's debug inform under c2x
+};
+#endif
+
 void foo (void)
 {
   v = MAX;
+  // CHECK: store i32 0, ptr @v, align 4
+  v1 = b0;
+  // CHECK: store i128 24197857203266734864629346612071973665, ptr @v1, align 16
+#if __STDC_VERSION__ >= 202000L  
+  v2 = c0;
+  // TODO: check how v2's value is changed by the _BitInt enum under c2x
+#endif  
 }
+
 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
 // CHECK-SAME: baseType: ![[LONG:[0-9]+]]
 // CHECK-SAME: elements: ![[ELTS:[0-9]+]]
 // CHECK: ![[LONG]] = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
 // CHECK: ![[ELTS]] = !{![[MAX:[0-9]+]]}
 // CHECK: ![[MAX]] = !DIEnumerator(name: "MAX", value: 0)
+// CHECK: !DICompositeType(tag: DW_TAG_enumeration_type,
+// CHECK-SAME: baseType: ![[BTYPE:[0-9]+]]
+// CHECK-SAME: elements: ![[ELTS:[0-9]+]]
+// CHECK: ![[BTYPE]] = !DIBasicType(name: "unsigned __int128", size: 128, encoding: DW_ATE_unsigned)
+// CHECK: ![[ELTS]] = !{![[E:[0-9]+]]}
+// CHECK: ![[E]] = !DIEnumerator(name: "b0", value: 24197857203266734864629346612071973665, isUnsigned: true)
Index: clang/test/CXX/drs/dr3xx.cpp
===
--- clang/test/CXX/drs/dr3xx.cpp
+++ clang/test/CXX/drs/dr3xx.cpp
@@ -1079,8 +1079,8 @@
 
 namespace dr377 { // dr377: yes
   enum E { // expected-error {{enumeration values exceed range of largest integer}}
-a = -__LONG_LONG_MAX__ - 1, // expected-error 0-1{{extension}}
-b = 2 * (unsigned long long)__LONG_LONG_MAX__ // expected-error 0-2{{extension}}
+a = -((__int128_t)__LONG_LONG_MAX__ << 64|__LONG_LONG_MAX__) - 1, // expected-error 0-2{{extension}}
+b = 2 * ((__uint128_t)__LONG_LONG_MAX__ << 64|__LONG_LONG_MAX__) // expected-error 0-2{{extension}}
   };
 }
 
Index: clang/test/AST/Interp/enums-targets.cpp
===
--- clang/test/AST/Interp/enums-targets.cpp
+++ clang/test/AST/Interp/enums-targets.cpp
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -triple i686-pc-linux -fexperimental-new-constant-interpreter -verify %s
 // RUN: %clang_cc1 -triple i686-pc-linux -verify %s
-// RUN: %clang_cc1 -triple x86_64-pc-linux -fexperimental-new-constant-interpreter -verify=warn %s
-// RUN: %clang_cc1 -triple x86_64-pc-linux -verify=warn %s
+// RUN: %clang_cc1 -triple x86_64-pc-linux -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -triple x86_64-pc-linux -verify %s
 // RUN: %clang_cc1 -triple x86_64-windows-msvc -fexperimental-new-constant-interpreter -verify %s
 // RUN: %clang_cc1 -triple x86_64-windows-msvc -verify %s
 // RUN: %clang_cc1 -triple hexagon -fexperimental-new-constant-interpreter -verify %s
@@ -11,7 +11,7 @@
 
 /// This test is split out from the rest since the output is target dependent.
 
-enum E { // warn-warning {{enumeration values exceed range of largest integer}}
+enum E {
   E1 = -__LONG_MAX__ -1L,
   E2 = __LONG_MAX__ *2UL+1UL
 };
Index: clang/lib/Sema/SemaDecl.cpp

[PATCH] D145138: [clang-tidy] Implement FixIts for C arrays

2023-03-25 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 508351.
ccotter marked 8 inline comments as done.
ccotter added a comment.

- feedback


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145138

Files:
  clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
  clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.h
  clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.h
  clang-tools-extra/clang-tidy/utils/CMakeLists.txt
  clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
  clang-tools-extra/clang-tidy/utils/TypeUtils.cpp
  clang-tools-extra/clang-tidy/utils/TypeUtils.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-arrays.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays-cxx17.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp
@@ -1,4 +1,6 @@
-// RUN: %check_clang_tidy %s modernize-avoid-c-arrays %t
+// RUN: %check_clang_tidy -std=c++11 %s modernize-avoid-c-arrays %t
+
+//CHECK-FIXES: #include 
 
 int a[] = {1, 2};
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: do not declare C-style arrays, use std::array<> instead
@@ -86,3 +88,262 @@
   int j[1];
 };
 }
+
+template  struct TStruct {};
+
+void replacements() {
+  int ar[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar;
+  TStruct ar2[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar2;
+  TStruct< int > ar3[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar3;
+  int * ar4[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar4;
+  int * /*comment*/ar5[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array /*comment*/ar5;
+  volatile const int * ar6[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar6;
+  volatile int ar7[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: volatile std::array ar7;
+  int const * ar8[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar8;
+  int ar9[1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array ar9;
+  static int volatile constexpr ar10[10] = {};
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: static volatile constexpr std::array ar10 = { {} };
+  thread_local int ar11[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: thread_local std::array ar11;
+  thread_local/*a*/int/*b*/ar12[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: thread_local/*a*/std::array/*b*/ar12;
+  /*a*/ int/*b*/ /*c*/*/*d*/ /*e*/ /*f*/ar13[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: /*a*/ std::array/*d*/ /*e*/ /*f*/ar13;
+  TStruct ar14[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar14;
+  volatile TStruct ar15[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: volatile std::array, 10> ar15;
+  TStruct ar16[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar16;
+  TStruct ar17[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: std::array, 10> ar17;
+  volatile int static thread_local * ar18[10];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not declare C-style arrays, use std::array<> instead
+  // CHECK-FIXES: static thread_local std::array ar18;
+
+  // Note, there is a tab '\t' before the semicolon in the declaration below.
+  int ar19[3]	;
+  // 

[PATCH] D146888: [clang-tidy] Flag std::forward on non-forwarding references

2023-03-25 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

First, https://reviews.llvm.org/D144347


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146888

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


[PATCH] D146888: [clang-tidy] Flag std::forward on non-forwarding references

2023-03-25 Thread Chris Cotter via Phabricator via cfe-commits
ccotter created this revision.
Herald added subscribers: PiotrZSL, carlosgalvezp, kbarton, xazax.hun, nemanjai.
Herald added a reviewer: njames93.
Herald added a project: All.
ccotter requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Implement the std::forward specific enforcement of ES.56.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146888

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ForwardNonForwardingParameterCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ForwardNonForwardingParameterCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/forward-non-forwarding-parameter.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/forward-non-forwarding-parameter.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/forward-non-forwarding-parameter.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/forward-non-forwarding-parameter.cpp
@@ -0,0 +1,163 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-forward-non-forwarding-parameter %t
+
+// NOLINTBEGIN
+namespace std {
+
+template  struct remove_reference  { using type = T; };
+template  struct remove_reference  { using type = T; };
+template  struct remove_reference { using type = T; };
+
+template  using remove_reference_t = typename remove_reference::type;
+
+template  constexpr T &(remove_reference_t ) noexcept;
+template  constexpr T &(remove_reference_t &) noexcept;
+
+} // namespace std
+// NOLINTEND
+
+struct Obj {
+  Obj();
+  Obj(const Obj&);
+  Obj(Obj&&) noexcept;
+  Obj& operator=(const Obj&);
+  Obj& operator=(Obj&&) noexcept;
+};
+
+template 
+void consumes_all(Ts&&...);
+
+namespace positive_cases {
+
+void forward_local_object() {
+  Obj obj;
+  Obj& obj_ref = obj;
+
+  Obj obj2 = std::forward(obj);
+  // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: calling std::forward on non-forwarding reference 'obj' [cppcoreguidelines-forward-non-forwarding-parameter]
+
+  Obj obj3 = std::forward(obj_ref);
+  // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: calling std::forward on non-forwarding reference 'obj_ref' [cppcoreguidelines-forward-non-forwarding-parameter]
+}
+
+void forward_value_param(Obj obj) {
+  Obj obj2 = std::forward(obj);
+  // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: calling std::forward on non-forwarding reference 'obj' [cppcoreguidelines-forward-non-forwarding-parameter]
+}
+
+template 
+void forward_pack_of_values(Ts... ts) {
+  consumes_all(std::forward(ts)...);
+  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: calling std::forward on non-forwarding reference 'ts' [cppcoreguidelines-forward-non-forwarding-parameter]
+}
+
+template 
+void forward_pack_of_lvalue_refs(Ts&... ts) {
+  consumes_all(std::forward(ts)...);
+  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: calling std::forward on non-forwarding reference 'ts' [cppcoreguidelines-forward-non-forwarding-parameter]
+}
+
+void forward_lvalue_ref(Obj& obj) {
+  Obj obj2 = std::forward(obj);
+  // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: calling std::forward on non-forwarding reference 'obj' [cppcoreguidelines-forward-non-forwarding-parameter]
+}
+
+void forward_const_lvalue_ref(const Obj& obj) {
+  Obj obj2 = std::forward(obj);
+  // CHECK-MESSAGES: :[[@LINE-1]]:38: warning: calling std::forward on non-forwarding reference 'obj' [cppcoreguidelines-forward-non-forwarding-parameter]
+}
+
+void forward_rvalue_ref(Obj&& obj) {
+  Obj obj2 = std::forward(obj);
+  // CHECK-MESSAGES: :[[@LINE-1]]:32: warning: calling std::forward on rvalue reference 'obj'; use std::move instead [cppcoreguidelines-forward-non-forwarding-parameter]
+  // CHECK-FIXES: Obj obj2 = std::move(obj);
+}
+
+void forward_const_rvalue_ref(const Obj&& obj) {
+  Obj obj2 = std::forward(obj);
+  // CHECK-MESSAGES: :[[@LINE-1]]:38: warning: calling std::forward on non-forwarding reference 'obj' [cppcoreguidelines-forward-non-forwarding-parameter]
+}
+
+template 
+void forward_value_t(T t) {
+  T other = std::forward(t);
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: calling std::forward on non-forwarding reference 't' [cppcoreguidelines-forward-non-forwarding-parameter]
+}
+
+template 
+void forward_lvalue_ref_t(T& t) {
+  T other = std::forward(t);
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: calling std::forward on non-forwarding reference 't' [cppcoreguidelines-forward-non-forwarding-parameter]
+}
+
+template 
+void forward_const_rvalue_ref_t(const T&& t) {
+  T other = std::forward(t);
+  // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: calling std::forward on non-forwarding reference 't' 

[PATCH] D145843: [clangd] Add option to always insert headers with <> instead of ""

2023-03-25 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Thanks for the clarification and suggested formulation.

In D145843#4209750 , @sammccall wrote:

> I'd suggest something like:
>
>   Style:
> QuotedHeaders: "path/to/.*"
> AngledHeaders: "path/sdk/.*"
>
> where the regexes can be single or array, and match any suffix (like 
> Diagnostics.Includes.IgnoreHeader)

@ADKaster are you interested in updating the patch to implement this approach?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145843

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


[PATCH] D146887: [clang-tidy] Fix if-constexpr false-positive in readability-misleading-indentation

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

When  depend on template parameter,
compiler can use NullStmt instead of CompoundStmt.
This causes issues as we losing information about
end location of that Stmt. To avoid this issue
check now ignores ifStmt with NullStmt on true-branch.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146887

Files:
  clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/misleading-indentation.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/misleading-indentation.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/misleading-indentation.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/misleading-indentation.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s readability-misleading-indentation %t -- -- 
-fno-delayed-template-parsing
+// RUN: %check_clang_tidy -std=c++17-or-later %s 
readability-misleading-indentation %t -- -- -fno-delayed-template-parsing
 
 void foo1();
 void foo2();
@@ -195,3 +195,31 @@
   mustFail();
   mustFail();
 }
+
+namespace PR61435 {
+
+template
+constexpr auto lam_correct = []{
+  if constexpr (N == 1) {
+  } else {
+  }
+};
+
+template
+constexpr auto lam_incorrect = []{
+  if constexpr (N == 1) {
+  }
+   else {
+  }
+  // CHECK-MESSAGES: :[[@LINE-2]]:4: warning: different indentation for 'if' 
and corresponding 'else' [readability-misleading-indentation]
+};
+
+void test() {
+  lam_correct<1>();
+  lam_correct<2>();
+
+  lam_incorrect<1>();
+  lam_incorrect<2>();
+}
+
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -225,6 +225,10 @@
   magic numbers in type aliases such as ``using`` and ``typedef`` declarations 
if
   the new ``IgnoreTypeAliases`` option is set to true.
 
+- Fixed a false positive in :doc:`readability-misleading-indentation
+  ` check when warning 
would
+  be unnecessarily emitted for template dependent ``if constexpr``.
+
 - Fixed a false positive in :doc:`cppcoreguidelines-slicing
   ` check when warning would be
   emitted in constructor for virtual base class initialization.
Index: clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
@@ -104,7 +104,8 @@
 }
 
 void MisleadingIndentationCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(ifStmt(hasElse(stmt())).bind("if"), this);
+  Finder->addMatcher(
+  ifStmt(unless(hasThen(nullStmt())), hasElse(stmt())).bind("if"), this);
   Finder->addMatcher(
   compoundStmt(has(stmt(anyOf(ifStmt(), forStmt(), whileStmt()
   .bind("compound"),


Index: clang-tools-extra/test/clang-tidy/checkers/readability/misleading-indentation.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/misleading-indentation.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/misleading-indentation.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s readability-misleading-indentation %t -- -- -fno-delayed-template-parsing
+// RUN: %check_clang_tidy -std=c++17-or-later %s readability-misleading-indentation %t -- -- -fno-delayed-template-parsing
 
 void foo1();
 void foo2();
@@ -195,3 +195,31 @@
   mustFail();
   mustFail();
 }
+
+namespace PR61435 {
+
+template
+constexpr auto lam_correct = []{
+  if constexpr (N == 1) {
+  } else {
+  }
+};
+
+template
+constexpr auto lam_incorrect = []{
+  if constexpr (N == 1) {
+  }
+   else {
+  }
+  // CHECK-MESSAGES: :[[@LINE-2]]:4: warning: different indentation for 'if' and corresponding 'else' [readability-misleading-indentation]
+};
+
+void test() {
+  lam_correct<1>();
+  lam_correct<2>();
+
+  lam_incorrect<1>();
+  lam_incorrect<2>();
+}
+
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -225,6 +225,10 @@
   magic numbers in type aliases such as ``using`` and ``typedef`` declarations if
   the new ``IgnoreTypeAliases`` option is set to true.
 
+- Fixed a false positive in :doc:`readability-misleading-indentation
+  ` check when warning would
+  be unnecessarily 

[PATCH] D143971: [clang-tidy] Flag more buggy string constructor cases

2023-03-25 Thread Chris Cotter via Phabricator via cfe-commits
ccotter marked an inline comment as done.
ccotter added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp:70-74
+  const auto CharExpr = expr(anyOf(
+  ignoringParenImpCasts(characterLiteral()),
+  
declRefExpr(hasDeclaration(varDecl(hasType(qualType(isAnyCharacter()),
+  ignoringParens(callExpr(
+  callee(functionDecl(returns(qualType(isAnyCharacter();

PiotrZSL wrote:
> add a testcase with:
> ```
> char& chRef = ch;
> std::string swapped2(chRef, i);
> 
> char* chPtr = 
> std::string swapped2(*chPtr, i);
> 
> using Character = char;
> Character  c;
> std::string swapped2(c, i);
> ```
> 
> I fear that it may not match those, because here you are trying to match 
> specific use cases, when you should simply match a type of expression. In 
> such case this should be just:
> ```
> const auto CharExpr = 
> expr(hasType(qualType(hasCanonicalType(anyOf(isAnyCharacter(), 
> references(isAnyCharacter()));
> ```
> 
> Only issue would be implicit cast, you can try deal with them by using 
> ignoringImplicit, or in better way just by using:
> 
> ```
> traverse(TK_IgnoreUnlessSpelledInSource,  hasArgument(0, 
> CharExpr.bind("swapped-parameter"))),
> ```
> TK_IgnoreUnlessSpelledInSource will cut of all implicit operations, so you 
> could check if called constructor is actually the wrong one, and check 
> argument types. Because now macher in line 125 may not always work if somehow 
> we would have for example 2 implicit casts, for example from char reference 
> to char, or some other crap.
> 
> It's up to you, but consider more generic approach instead of matching 
> specific use cases like references to variables, or calls.
> 
Thinking about this more, I think we have to keep the "args swapped" case very 
narrow to the existing patterns of the first arg being a char literal, and the 
second being an integer literal. Consider

```
char buffer[] = "abcdef";
char& chRef = ch;
std::string not_swapped(chRef, 4); // Forgot '&' in front of 'chRef'

std::string also_not_swapped(buffer[2], 2); // Forgot '&' in front of 
'buffer[2]'
```

Neither of these are swapped arg bugs, so I don't think we can have the tool 
consider this a swapped arg bug and apply fixits. The `also_not_swapped` is the 
exact bug I wrote a few weeks ago.

I think there are two types of bugs the tool has to be aware of with respect to 
the string fill constructor
 1. swapped args
 2. "confusing" args - where the arguments are both implicitly cast from int to 
char and vice versa.

For swapped args, the existing logic will match when the first arg has 
`isInteger()` type, and the second arg is `characterLiteral()`. At most, I 
think we can only expand the logic to include constructor exprs when the second 
arg is a declRefExpr to a `char`, but not char ref (see the `not_swapped` 
example above), or when the second arg is the result of a function call that 
returns a char. In these cases, we can be sure that the the author did not mean 
to put a `&` in front of the second argument expression.

For "confusing" args, which is not implemented in the existing logic, but I am 
proposing in this change, this is the more general case where I think the logic 
should match any expression as long as both argument expressions are implicitly 
cast. This is "confusing" because int-to-char and char-to-int conversions are 
not obvious to the reader, and it should be rare for both conversions to take 
place when calling the fill constructor (confirmed anecdotally in the codebases 
I've checked). The tool could not offer fixits here since the fix might be to 
swap the args, or to add a `&` in front of the first arg (or even another 
change). At most, we can warn and alert the user to the problem. If this is 
what the author intended, they can use explicit casts to make the intent 
obvious to the reader.



Comment at: clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp:95
+  const auto NonCharacterInteger =
+  qualType(isInteger(), unless(isAnyCharacter()));
+  const auto CharToIntCastExpr = implicitCastExpr(

PiotrZSL wrote:
> what about references to integer, or typedefs to integers ?
I'll add a test for reference to integer, but I'm matching on the type of the 
source expression that is being cast, which will be of integer type, even if 
the expression is `string str(x, y)` and `y` is an `int&` (the source 
expression in the cast will be of type `int`).



Comment at: clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp:213
 }
+  } else if (const auto *E =
+ Result.Nodes.getNodeAs("implicit-cast-both-args")) {

PiotrZSL wrote:
> i thing that this case should be matched by "swapped-parameter", no need to 
> add extra one, just first one should be fixed.
See earlier explanation on why we can't treat these all as swapped parameters 
cases.



[PATCH] D143971: [clang-tidy] Flag more buggy string constructor cases

2023-03-25 Thread Chris Cotter via Phabricator via cfe-commits
ccotter updated this revision to Diff 508345.
ccotter marked 4 inline comments as done.
ccotter added a comment.

- Add more cases to swapped params
- Change message, add more tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143971

Files:
  clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/string-constructor.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone/string-constructor.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/string-constructor.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/string-constructor.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/string-constructor.cpp
@@ -5,12 +5,13 @@
 class allocator {};
 template 
 class char_traits {};
-template , typename A = std::allocator >
+template , typename A = std::allocator>
 struct basic_string {
   basic_string();
-  basic_string(const C*, unsigned int size);
-  basic_string(const C *, const A  = A());
-  basic_string(unsigned int size, C c);
+  basic_string(const basic_string&, unsigned int, unsigned int, const A & = A());
+  basic_string(const C*, unsigned int);
+  basic_string(const C*, const A& = A());
+  basic_string(unsigned int, C);
 };
 typedef basic_string string;
 typedef basic_string wstring;
@@ -18,7 +19,7 @@
 template >
 struct basic_string_view {
   basic_string_view();
-  basic_string_view(const C *, unsigned int size);
+  basic_string_view(const C *, unsigned int);
   basic_string_view(const C *);
 };
 typedef basic_string_view string_view;
@@ -28,20 +29,74 @@
 const char* kText = "";
 const char kText2[] = "";
 extern const char kText3[];
+char getChar();
+const char* getCharPtr();
+
+struct CharLikeObj {
+  operator char() const;
+};
 
 void Test() {
-  std::string str('x', 4);
-  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: string constructor parameters are probably swapped; expecting string(count, character) [bugprone-string-constructor]
-  // CHECK-FIXES: std::string str(4, 'x');
-  std::wstring wstr(L'x', 4);
-  // CHECK-MESSAGES: [[@LINE-1]]:16: warning: string constructor parameters are probably swapped
-  // CHECK-FIXES: std::wstring wstr(4, L'x');
+  short sh;
+  int i;
+  int& ref_i = i;
+  char ch;
+  CharLikeObj char_like_obj;
+
+  std::string swapped('x', 4);
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: string constructor arguments are probably swapped; expecting string(count, character) [bugprone-string-constructor]
+  // CHECK-FIXES: std::string swapped(4, 'x');
+  std::wstring wswapped(L'x', 4);
+  // CHECK-MESSAGES: [[@LINE-1]]:16: warning: string constructor arguments are probably swapped; expecting string(count, character) [bugprone-string-constructor]
+  // CHECK-FIXES: std::wstring wswapped(4, L'x');
+  std::string swapped2('x', i);
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: string constructor arguments are probably swapped; expecting string(count, character) [bugprone-string-constructor]
+  // CHECK-FIXES: std::string swapped2(i, 'x');
+  std::string swapped3(ch, 4);
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: string constructor arguments are probably swapped; expecting string(count, character) [bugprone-string-constructor]
+  // CHECK-FIXES: std::string swapped3(4, ch);
+  std::string swapped4(ch, i);
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: string constructor arguments are probably swapped; expecting string(count, character) [bugprone-string-constructor]
+  // CHECK-FIXES: std::string swapped4(i, ch);
+  std::string swapped5('x', (int)'x');
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: string constructor arguments are probably swapped; expecting string(count, character) [bugprone-string-constructor]
+  // CHECK-FIXES: std::string swapped5((int)'x', 'x');
+  std::string swapped6(getChar(), 10);
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: string constructor arguments are probably swapped; expecting string(count, character) [bugprone-string-constructor]
+  // CHECK-FIXES: std::string swapped6(10, getChar());
+  std::string swapped7((('x')), ( i ));
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: string constructor arguments are probably swapped; expecting string(count, character) [bugprone-string-constructor]
+  // CHECK-FIXES: std::string swapped7(( i ), (('x')));
+  std::string swapped8((ch), (i));
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: string constructor arguments are probably swapped; expecting string(count, character) [bugprone-string-constructor]
+  // CHECK-FIXES: std::string swapped8((i), (ch));
+  std::string swapped9((getChar()), (i));
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: string constructor arguments are probably swapped; expecting string(count, character) [bugprone-string-constructor]
+  // CHECK-FIXES: std::string swapped9((i), (getChar()));
   

[PATCH] D146885: [clang-tidy][NFC] add debug log when clean empty namespace

2023-03-25 Thread Congcong Cai via Phabricator via cfe-commits
HerrCai0907 created this revision.
HerrCai0907 added a reviewer: njames93.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Adding debug log when clean empty namespace can make 
(#60051)[https://github.com/llvm/llvm-project/issues/60051#issuecomment-1383923360]
 more cleaner.
User will not be confused why the whole namespace is deleted after fixing 
modernize-concat-nested-namespaces.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146885

Files:
  clang/lib/Format/Format.cpp


Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2472,10 +2472,13 @@
 
 for (auto Line : DeletedLines) {
   FormatToken *Tok = AnnotatedLines[Line]->First;
+  LLVM_DEBUG(llvm::dbgs() << "clean empty namespace:\"");
   while (Tok) {
+LLVM_DEBUG(llvm::dbgs() << Tok->TokenText << " ");
 deleteToken(Tok);
 Tok = Tok->Next;
   }
+  LLVM_DEBUG(llvm::dbgs() << "\"\n");
 }
   }
 


Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2472,10 +2472,13 @@
 
 for (auto Line : DeletedLines) {
   FormatToken *Tok = AnnotatedLines[Line]->First;
+  LLVM_DEBUG(llvm::dbgs() << "clean empty namespace:\"");
   while (Tok) {
+LLVM_DEBUG(llvm::dbgs() << Tok->TokenText << " ");
 deleteToken(Tok);
 Tok = Tok->Next;
   }
+  LLVM_DEBUG(llvm::dbgs() << "\"\n");
 }
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146403: [clang-format] More work on space around operators in Verilog

2023-03-25 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 rG0e01c3d28217: [clang-format] More work on space around 
operators in Verilog (authored by sstwcw).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146403

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

Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -657,6 +657,14 @@
   verifyFormat("x = ++x;");
   verifyFormat("x = --x;");
 
+  // Test that `*` and `*>` are binary.
+  verifyFormat("x = x * x;");
+  verifyFormat("x = (x * x);");
+  verifyFormat("(opcode *> o1) = 6.1;");
+  verifyFormat("(C, D *> Q) = 18;");
+  // The wildcard import is not a binary operator.
+  verifyFormat("import p::*;");
+
   // Test that operators don't get split.
   verifyFormat("x = x++;");
   verifyFormat("x = x--;");
@@ -697,6 +705,13 @@
   EXPECT_EQ("x = x < -x;", format("x=x<-x;"));
   EXPECT_EQ("x = x << -x;", format("x=x<<-x;"));
   EXPECT_EQ("x = x <<< -x;", format("x=x<<<-x;"));
+
+  // Test that operators that are C++ identifiers get treated as operators.
+  verifyFormat("solve s before d;");   // before
+  verifyFormat("binsof(i) intersect {0};");// intersect
+  verifyFormat("req dist {1};");   // dist
+  verifyFormat("a inside {b, c};");// inside
+  verifyFormat("bus.randomize() with { atype == low; };"); // with
 }
 
 TEST_F(FormatTestVerilog, Preprocessor) {
@@ -849,6 +864,26 @@
"endprimitive");
 }
 
+TEST_F(FormatTestVerilog, Streaming) {
+  verifyFormat("x = {>>{j}};");
+  verifyFormat("x = {>>byte{j}};");
+  verifyFormat("x = {<<{j}};");
+  verifyFormat("x = {<>4{6'b11_0101}};");
+  verifyFormat("x = {<<2{{<<{4'b1101;");
+  verifyFormat("bit [96 : 1] y = {>>{a, b, c}};");
+  verifyFormat("int j = {>>{a, b, c}};");
+  verifyFormat("{>>{a, b, c}} = 23'b1;");
+  verifyFormat("{>>{a, b, c}} = x;");
+  verifyFormat("{>>{j}} = x;");
+  verifyFormat("{>>byte{j}} = x;");
+  verifyFormat("{<<{j}} = x;");
+  verifyFormat("{<` in module path declarations in
+  // specify blocks because merged tokens take the type of the first one by
+  // default.
+  if (Tok.is(tok::star))
+return TT_BinaryOperator;
+  return determineUnaryOperatorByUsage(Tok) ? TT_UnaryOperator
+: TT_BinaryOperator;
+}
+
 const FormatToken *PrevToken = Tok.getPreviousNonComment();
 if (!PrevToken)
   return TT_UnaryOperator;
@@ -3987,7 +3998,12 @@
 return !Left.isOneOf(tok::l_paren, tok::l_square, tok::at) &&
(Left.isNot(tok::colon) || Left.isNot(TT_ObjCMethodExpr));
   }
-  if ((Left.isOneOf(tok::identifier, tok::greater, tok::r_square,
+  // No space between the variable name and the initializer list.
+  // A a1{1};
+  // Verilog doesn't have such syntax, but it has word operators that are C++
+  // identifiers like `a inside {b, c}`. So the rule is not applicable.
+  if (!Style.isVerilog() &&
+  (Left.isOneOf(tok::identifier, tok::greater, tok::r_square,
 tok::r_paren) ||
Left.isSimpleTypeSpecifier()) &&
   Right.is(tok::l_brace) && Right.getNextNonComment() &&
@@ -4373,12 +4389,24 @@
  Keywords.isWordLike(Left))) {
   return false;
 }
+// Don't add spaces in imports like `import foo::*;`.
+if ((Right.is(tok::star) && Left.is(tok::coloncolon)) ||
+(Left.is(tok::star) && Right.is(tok::semi))) {
+  return false;
+}
 // Add space in attribute like `(* ASYNC_REG = "TRUE" *)`.
 if (Left.endsSequence(tok::star, tok::l_paren) && Right.is(tok::identifier))
   return true;
 // Add space before drive strength like in `wire (strong1, pull0)`.
 if (Right.is(tok::l_paren) && Right.is(TT_VerilogStrength))
   return true;
+// Don't add space in a streaming concatenation like `{>>{j}}`.
+if ((Left.is(tok::l_brace) &&
+ Right.isOneOf(tok::lessless, tok::greatergreater)) ||
+(Left.endsSequence(tok::lessless, tok::l_brace) ||
+ Left.endsSequence(tok::greatergreater, tok::l_brace))) {
+  return false;
+}
   }
   if (Left.is(TT_ImplicitStringLiteral))
 return Right.hasWhitespaceBefore();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146402: [clang-format] Handle Verilog assign statements

2023-03-25 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 rGf90668c8ccc5: [clang-format] Handle Verilog assign 
statements (authored by sstwcw).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146402

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


Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -97,6 +97,23 @@
Style);
 }
 
+TEST_F(FormatTestVerilog, Assign) {
+  verifyFormat("assign mynet = enable;");
+  verifyFormat("assign (strong1, pull0) #1 mynet = enable;");
+  verifyFormat("assign #1 mynet = enable;");
+  verifyFormat("assign mynet = enable;");
+  // Test that assignments are on separate lines.
+  verifyFormat("assign mynet = enable,\n"
+   "   mynet1 = enable1;");
+  // Test that `<=` and `,` don't confuse it.
+  verifyFormat("assign mynet = enable1 <= enable2;");
+  verifyFormat("assign mynet = enable1 <= enable2,\n"
+   "   mynet1 = enable3;");
+  verifyFormat("assign mynet = enable,\n"
+   "   mynet1 = enable2 <= enable3;");
+  verifyFormat("assign mynet = enable(enable1, enable2);");
+}
+
 TEST_F(FormatTestVerilog, BasedLiteral) {
   verifyFormat("x = '0;");
   verifyFormat("x = '1;");
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1286,8 +1286,11 @@
 Tok->setType(TT_InheritanceComma);
 break;
   default:
-if (Contexts.back().FirstStartOfName &&
-(Contexts.size() == 1 || startsWithInitStatement(Line))) {
+if (Style.isVerilog() && Contexts.size() == 1 &&
+Line.startsWith(Keywords.kw_assign)) {
+  Tok->setFinalizedType(TT_VerilogAssignComma);
+} else if (Contexts.back().FirstStartOfName &&
+   (Contexts.size() == 1 || startsWithInitStatement(Line))) {
   Contexts.back().FirstStartOfName->PartOfMultiVariableDeclStmt = true;
   Line.IsMultiVariableDeclStmt = true;
 }
@@ -4720,6 +4723,9 @@
   return true;
 }
   } else if (Style.isVerilog()) {
+// Break between assignments.
+if (Left.is(TT_VerilogAssignComma))
+  return true;
 // Break between ports of different types.
 if (Left.is(TT_VerilogTypeComma))
   return true;
Index: clang/lib/Format/FormatToken.h
===
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -144,6 +144,8 @@
   TYPE(UnaryOperator)  
\
   TYPE(UnionLBrace)
\
   TYPE(UntouchableMacroFunc)   
\
+  /* Like in 'assign x = 0, y = 1;' . */   
\
+  TYPE(VerilogAssignComma) 
\
   /* like in begin : block */  
\
   TYPE(VerilogBlockLabelColon) 
\
   /* The square bracket for the dimension part of the type name.   
\


Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -97,6 +97,23 @@
Style);
 }
 
+TEST_F(FormatTestVerilog, Assign) {
+  verifyFormat("assign mynet = enable;");
+  verifyFormat("assign (strong1, pull0) #1 mynet = enable;");
+  verifyFormat("assign #1 mynet = enable;");
+  verifyFormat("assign mynet = enable;");
+  // Test that assignments are on separate lines.
+  verifyFormat("assign mynet = enable,\n"
+   "   mynet1 = enable1;");
+  // Test that `<=` and `,` don't confuse it.
+  verifyFormat("assign mynet = enable1 <= enable2;");
+  verifyFormat("assign mynet = enable1 <= enable2,\n"
+   "   mynet1 = enable3;");
+  verifyFormat("assign mynet = enable,\n"
+   "   mynet1 = enable2 <= enable3;");
+  verifyFormat("assign mynet = enable(enable1, enable2);");
+}
+
 TEST_F(FormatTestVerilog, BasedLiteral) {
   verifyFormat("x = '0;");
   verifyFormat("x = '1;");
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1286,8 +1286,11 @@
 Tok->setType(TT_InheritanceComma);
 break;
   

[clang] f90668c - [clang-format] Handle Verilog assign statements

2023-03-25 Thread via cfe-commits

Author: sstwcw
Date: 2023-03-25T21:13:15Z
New Revision: f90668c8ccc5cd3d8c6521cfc872f3c51f2a02db

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

LOG: [clang-format] Handle Verilog assign statements

Reviewed By: MyDeveloperDay

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 5cac5776a652..5cd3422aed5b 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -144,6 +144,8 @@ namespace format {
   TYPE(UnaryOperator)  
\
   TYPE(UnionLBrace)
\
   TYPE(UntouchableMacroFunc)   
\
+  /* Like in 'assign x = 0, y = 1;' . */   
\
+  TYPE(VerilogAssignComma) 
\
   /* like in begin : block */  
\
   TYPE(VerilogBlockLabelColon) 
\
   /* The square bracket for the dimension part of the type name.   
\

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index a9f3bd0bb06b..d7758e7d068d 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1286,8 +1286,11 @@ class AnnotatingParser {
 Tok->setType(TT_InheritanceComma);
 break;
   default:
-if (Contexts.back().FirstStartOfName &&
-(Contexts.size() == 1 || startsWithInitStatement(Line))) {
+if (Style.isVerilog() && Contexts.size() == 1 &&
+Line.startsWith(Keywords.kw_assign)) {
+  Tok->setFinalizedType(TT_VerilogAssignComma);
+} else if (Contexts.back().FirstStartOfName &&
+   (Contexts.size() == 1 || startsWithInitStatement(Line))) {
   Contexts.back().FirstStartOfName->PartOfMultiVariableDeclStmt = true;
   Line.IsMultiVariableDeclStmt = true;
 }
@@ -4720,6 +4723,9 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
,
   return true;
 }
   } else if (Style.isVerilog()) {
+// Break between assignments.
+if (Left.is(TT_VerilogAssignComma))
+  return true;
 // Break between ports of 
diff erent types.
 if (Left.is(TT_VerilogTypeComma))
   return true;

diff  --git a/clang/unittests/Format/FormatTestVerilog.cpp 
b/clang/unittests/Format/FormatTestVerilog.cpp
index 6192deb3267d..3a03525c2db7 100644
--- a/clang/unittests/Format/FormatTestVerilog.cpp
+++ b/clang/unittests/Format/FormatTestVerilog.cpp
@@ -97,6 +97,23 @@ TEST_F(FormatTestVerilog, Align) {
Style);
 }
 
+TEST_F(FormatTestVerilog, Assign) {
+  verifyFormat("assign mynet = enable;");
+  verifyFormat("assign (strong1, pull0) #1 mynet = enable;");
+  verifyFormat("assign #1 mynet = enable;");
+  verifyFormat("assign mynet = enable;");
+  // Test that assignments are on separate lines.
+  verifyFormat("assign mynet = enable,\n"
+   "   mynet1 = enable1;");
+  // Test that `<=` and `,` don't confuse it.
+  verifyFormat("assign mynet = enable1 <= enable2;");
+  verifyFormat("assign mynet = enable1 <= enable2,\n"
+   "   mynet1 = enable3;");
+  verifyFormat("assign mynet = enable,\n"
+   "   mynet1 = enable2 <= enable3;");
+  verifyFormat("assign mynet = enable(enable1, enable2);");
+}
+
 TEST_F(FormatTestVerilog, BasedLiteral) {
   verifyFormat("x = '0;");
   verifyFormat("x = '1;");



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


[clang] 0e01c3d - [clang-format] More work on space around operators in Verilog

2023-03-25 Thread via cfe-commits

Author: sstwcw
Date: 2023-03-25T21:12:23Z
New Revision: 0e01c3d282179ab11101988e1e1f2763f48f6882

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

LOG: [clang-format] More work on space around operators in Verilog

before:
```
(opcode *>o1) = 6.1;
a inside{b, c};
x = { >> {j}};
```

after:
```
(opcode *> o1) = 6.1;
a inside {b, c};
x = {>>{j}};
```

Reviewed By: MyDeveloperDay

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

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestVerilog.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 5dbda8fbe071..a9f3bd0bb06b 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2392,6 +2392,17 @@ class AnnotatingParser {
 if (Style.isCSharp() && Tok.is(tok::ampamp))
   return TT_BinaryOperator;
 
+if (Style.isVerilog()) {
+  // In Verilog, `*` can only be a binary operator.  `&` can be either 
unary
+  // or binary.  `*` also includes `*>` in module path declarations in
+  // specify blocks because merged tokens take the type of the first one by
+  // default.
+  if (Tok.is(tok::star))
+return TT_BinaryOperator;
+  return determineUnaryOperatorByUsage(Tok) ? TT_UnaryOperator
+: TT_BinaryOperator;
+}
+
 const FormatToken *PrevToken = Tok.getPreviousNonComment();
 if (!PrevToken)
   return TT_UnaryOperator;
@@ -3987,7 +3998,12 @@ bool TokenAnnotator::spaceRequiredBetween(const 
AnnotatedLine ,
 return !Left.isOneOf(tok::l_paren, tok::l_square, tok::at) &&
(Left.isNot(tok::colon) || Left.isNot(TT_ObjCMethodExpr));
   }
-  if ((Left.isOneOf(tok::identifier, tok::greater, tok::r_square,
+  // No space between the variable name and the initializer list.
+  // A a1{1};
+  // Verilog doesn't have such syntax, but it has word operators that are C++
+  // identifiers like `a inside {b, c}`. So the rule is not applicable.
+  if (!Style.isVerilog() &&
+  (Left.isOneOf(tok::identifier, tok::greater, tok::r_square,
 tok::r_paren) ||
Left.isSimpleTypeSpecifier()) &&
   Right.is(tok::l_brace) && Right.getNextNonComment() &&
@@ -4373,12 +4389,24 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
  Keywords.isWordLike(Left))) {
   return false;
 }
+// Don't add spaces in imports like `import foo::*;`.
+if ((Right.is(tok::star) && Left.is(tok::coloncolon)) ||
+(Left.is(tok::star) && Right.is(tok::semi))) {
+  return false;
+}
 // Add space in attribute like `(* ASYNC_REG = "TRUE" *)`.
 if (Left.endsSequence(tok::star, tok::l_paren) && 
Right.is(tok::identifier))
   return true;
 // Add space before drive strength like in `wire (strong1, pull0)`.
 if (Right.is(tok::l_paren) && Right.is(TT_VerilogStrength))
   return true;
+// Don't add space in a streaming concatenation like `{>>{j}}`.
+if ((Left.is(tok::l_brace) &&
+ Right.isOneOf(tok::lessless, tok::greatergreater)) ||
+(Left.endsSequence(tok::lessless, tok::l_brace) ||
+ Left.endsSequence(tok::greatergreater, tok::l_brace))) {
+  return false;
+}
   }
   if (Left.is(TT_ImplicitStringLiteral))
 return Right.hasWhitespaceBefore();

diff  --git a/clang/unittests/Format/FormatTestVerilog.cpp 
b/clang/unittests/Format/FormatTestVerilog.cpp
index a4d6b540bd83..6192deb3267d 100644
--- a/clang/unittests/Format/FormatTestVerilog.cpp
+++ b/clang/unittests/Format/FormatTestVerilog.cpp
@@ -657,6 +657,14 @@ TEST_F(FormatTestVerilog, Operators) {
   verifyFormat("x = ++x;");
   verifyFormat("x = --x;");
 
+  // Test that `*` and `*>` are binary.
+  verifyFormat("x = x * x;");
+  verifyFormat("x = (x * x);");
+  verifyFormat("(opcode *> o1) = 6.1;");
+  verifyFormat("(C, D *> Q) = 18;");
+  // The wildcard import is not a binary operator.
+  verifyFormat("import p::*;");
+
   // Test that operators don't get split.
   verifyFormat("x = x++;");
   verifyFormat("x = x--;");
@@ -697,6 +705,13 @@ TEST_F(FormatTestVerilog, Operators) {
   EXPECT_EQ("x = x < -x;", format("x=x<-x;"));
   EXPECT_EQ("x = x << -x;", format("x=x<<-x;"));
   EXPECT_EQ("x = x <<< -x;", format("x=x<<<-x;"));
+
+  // Test that operators that are C++ identifiers get treated as operators.
+  verifyFormat("solve s before d;");   // before
+  verifyFormat("binsof(i) intersect {0};");// intersect
+  verifyFormat("req dist {1};");   // dist
+  verifyFormat("a inside {b, c};");// inside
+  verifyFormat("bus.randomize() with { atype == low; };"); // 

[PATCH] D145138: [clang-tidy] Implement FixIts for C arrays

2023-03-25 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

To be honest, that's lot of hard to understand code that at start is 
unmaintainable.
I don't see anyone even trying to understand all this and do some fixes in 
future.

Consider some refactoring, to reduce amount of code, split it into some 
functions, add some comments (steps) inside functions.
I hope you will be with us for next 2 years to implement fixes...




Comment at: clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp:54-57
+  anyOf(hasParent(varDecl(hasParent(declStmt().bind("decl")),
+  hasAncestor(functionDecl()))
+  .bind("var")),
+anything()),

use optionally instead of anyOf + anything



Comment at: clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp:250-254
+if (ConsumedStar) {
+  return Token.IsSpecifier;
+} else {
+  return Token.IsSpecifier || Token.IsQualifier;
+}

style:

```
return Token.IsSpecifier || (!ConsumedStar && Token.IsQualifier);
```



Comment at: clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp:400-405
+if (Match.getNodeAs("range-for")) {
+  continue;
+}
+if (Match.getNodeAs("sizeof")) {
+  continue;
+}

style: remove {}



Comment at: clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp:447-449
+} else {
+  return false;
+}

style: else return false;



Comment at: clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp:466-470
+  if (ElemType->isArrayType())
+return {};
+  if (ElemType->isFunctionPointerType() ||
+  ElemType->isMemberFunctionPointerType())
+return {};

style: merge into single if



Comment at: clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp:496
+  const Expr *SpelledExpr = E->IgnoreUnlessSpelledInSource();
+  if (dyn_cast(SpelledExpr))
+return false;

InitListExpr::classof(SpelledExpr)



Comment at: clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp:531
+return {};
+  // TODO: How can I get FileCheck to accept '{{}}' as a non-regex match?
+  FixIts.push_back(FixItHint::CreateInsertion(InitRange.getBegin(), "{ "));

https://www.llvm.org/docs/CommandGuide/FileCheck.html
"In the rare case that you want to match double braces explicitly from the 
input, you can use something ugly like {{[}][}]}} as your pattern."



Comment at: clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp:540
+
+  std::string Replacement;
+  std::optional IncludeFixIt =

unused



Comment at: clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp:544
+ "");
+  if (IncludeFixIt) {
+FixIts.push_back(std::move(*IncludeFixIt));

remove {}



Comment at: clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp:588
+: ClangTidyCheck(Name, Context),
+  IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
+   utils::IncludeSorter::IS_LLVM),

ccotter wrote:
> Eugene.Zelenko wrote:
> > ccotter wrote:
> > > Eugene.Zelenko wrote:
> > > > Should be global option, because it's used in other checks.
> > > Could you clarify this a bit? This is how most other tests consume 
> > > IncludeStyle (`Options.getLocalOrGlobal("IncludeStyle", 
> > > utils::IncludeSorter::IS_LLVM)`.
> > @carlosgalvezp is best person to answer because he recently introduced 
> > global option for source files and headers.
> bump @carlosgalvezp 
```
Local:
  - key: modernize-avoid-c-arrays.IncludeStyle
 value: google

Global:
  - key: IncludeStyle
 value: google
```

Your code is correct, simply if there is local defined, it will be used, if 
there is global defined, then global will be used.




Comment at: clang-tools-extra/clang-tidy/utils/LexerUtils.cpp:94
 
-  while (Loc < Range.getEnd()) {
+  while (SM.isBeforeInTranslationUnit(Loc, Range.getEnd())) {
 if (Loc.isMacroID())

Actually this function is bugged: https://reviews.llvm.org/D146881
I dont think that isBeforeInTranslationUnit is needed here, if you need it then 
there is something wrong with a range.




Comment at: clang-tools-extra/clang-tidy/utils/TypeUtils.cpp:50-51
+
+bool Qual = isCvr(T);
+bool Spec = isSpecifier(T);
+CT.IsQualifier &= Qual;

style: const



Comment at: clang-tools-extra/clang-tidy/utils/TypeUtils.cpp:112-114
+else {
+  return std::nullopt;
+}

Style: no need for {}



Comment at: 

[PATCH] D146882: [clang-tidy] Correct union & macros handling in modernize-use-equals-default

2023-03-25 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexander-shaposhnikov accepted this revision.
alexander-shaposhnikov added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146882

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


[PATCH] D146401: [clang-format] Don't squash Verilog escaped identifiers

2023-03-25 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/unittests/Format/FormatTestVerilog.cpp:19
 protected:
-  static std::string format(llvm::StringRef Code, unsigned Offset,
-unsigned Length, const FormatStyle ) {
-LLVM_DEBUG(llvm::errs() << "---\n");
-LLVM_DEBUG(llvm::errs() << Code << "\n\n");
-std::vector Ranges(1, tooling::Range(Offset, Length));
-tooling::Replacements Replaces = reformat(Style, Code, Ranges);
-auto Result = applyAllReplacements(Code, Replaces);
-EXPECT_TRUE(static_cast(Result));
-LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
-return *Result;
-  }
-
-  static std::string
-  format(llvm::StringRef Code,
- const FormatStyle  = getLLVMStyle(FormatStyle::LK_Verilog)) {
-return format(Code, 0, Code.size(), Style);
+  virtual FormatStyle getDefaultStyle() const override {
+return getLLVMStyle(FormatStyle::LK_Verilog);

Drop that virtual.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146401

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


[PATCH] D146883: [documentation]Fixed Random Typos

2023-03-25 Thread Ayushi Shukla via Phabricator via cfe-commits
ayushi-8102 created this revision.
ayushi-8102 added a reviewer: samtebbs.
Herald added a reviewer: NoQ.
Herald added a project: All.
ayushi-8102 requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, jplehr, sstefan1.
Herald added a project: clang.

This patch fixes https://github.com/llvm/llvm-project/issues/56747


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146883

Files:
  clang/docs/AutomaticReferenceCounting.rst
  clang/docs/ConstantInterpreter.rst
  clang/docs/CrossCompilation.rst
  clang/docs/DataFlowAnalysisIntro.md
  clang/docs/DebuggingCoroutines.rst
  clang/docs/analyzer/developer-docs/nullability.rst
  clang/include/clang/AST/CXXInheritance.h
  clang/include/clang/AST/CommentSema.h
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/AST/DeclTemplate.h
  clang/include/clang/AST/DeclarationName.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/Analysis/Analyses/CalledOnceCheck.h
  clang/include/clang/Analysis/Analyses/Consumed.h
  clang/include/clang/Analysis/Analyses/ThreadSafetyTIL.h
  clang/include/clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-deref.cpp

Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-deref.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-deref.cpp
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+
+void basic_dereference() {
+  int tmp;
+  auto p = new int[10];
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span p"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}"
+  tmp = p[5];
+  int val = *p;
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:13-[[@LINE-1]]:14}:""
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:15-[[@LINE-2]]:15}:"[0]"
+}
+
+int return_method() {
+  auto p = new int[10];
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span p"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}"
+  int tmp = p[5];
+  return *p;
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:11}:""
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"[0]"
+}
+
+void foo(int v) {
+}
+
+void method_invocation() {
+  auto p = new int[10];
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span p"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}"
+
+  int tmp = p[5];
+
+  foo(*p);
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:""
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:9-[[@LINE-2]]:9}:"[0]"
+}
+
+void binary_operation() {
+  auto p = new int[10];
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span p"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}"
+
+  int tmp = p[5];
+
+  int k = *p + 20;
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:12}:""
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-2]]:13-[[@LINE-2]]:13}:"[0]"
+
+}
+
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -463,6 +463,45 @@
 return {};
   }
 };
+
+class PointerDereferenceGadget : public FixableGadget {
+  static constexpr const char *const BaseDeclRefExprTag = "BaseDRE";
+  static constexpr const char *const OperatorTag = "op";
+
+  const DeclRefExpr *BaseDeclRefExpr = nullptr;
+  const UnaryOperator *Op = nullptr;
+
+public:
+  PointerDereferenceGadget(const MatchFinder::MatchResult )
+  : FixableGadget(Kind::PointerDereference),
+BaseDeclRefExpr(
+Result.Nodes.getNodeAs(BaseDeclRefExprTag)),
+Op(Result.Nodes.getNodeAs(OperatorTag)) {}
+
+  static bool classof(const Gadget *G) {
+return G->getKind() == Kind::PointerDereference;
+  }
+
+  static Matcher matcher() {
+auto Target =
+unaryOperator(
+hasOperatorName("*"),
+has(expr(ignoringParenImpCasts(
+declRefExpr(to(varDecl())).bind(BaseDeclRefExprTag)
+.bind(OperatorTag);
+
+return expr(isInUnspecifiedLvalueContext(Target));
+  }
+
+  DeclUseList getClaimedVarUseSites() const override {
+return {BaseDeclRefExpr};
+  }
+
+  virtual const Stmt *getBaseStmt() const final { return Op; }
+
+  virtual std::optional getFixits(const Strategy ) const override;
+};
+
 } // namespace
 
 namespace {
@@ 

[PATCH] D145138: [clang-tidy] Implement FixIts for C arrays

2023-03-25 Thread Chris Cotter via Phabricator via cfe-commits
ccotter added inline comments.
Herald added a subscriber: PiotrZSL.



Comment at: clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp:588
+: ClangTidyCheck(Name, Context),
+  IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
+   utils::IncludeSorter::IS_LLVM),

Eugene.Zelenko wrote:
> ccotter wrote:
> > Eugene.Zelenko wrote:
> > > Should be global option, because it's used in other checks.
> > Could you clarify this a bit? This is how most other tests consume 
> > IncludeStyle (`Options.getLocalOrGlobal("IncludeStyle", 
> > utils::IncludeSorter::IS_LLVM)`.
> @carlosgalvezp is best person to answer because he recently introduced global 
> option for source files and headers.
bump @carlosgalvezp 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145138

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


[PATCH] D146155: [clang][NFC] Fix location of 2>&1 in a few -print tests

2023-03-25 Thread Louis Dionne via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG731264b0c2af: [clang][NFC] Fix location of 21 in a 
few -print tests (authored by ldionne).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146155

Files:
  clang/test/Driver/print-effective-triple.c
  clang/test/Driver/print-file-name.c
  clang/test/Driver/print-libgcc-file-name-clangrt.c
  clang/test/Driver/print-multi-directory.c
  clang/test/Driver/print-target-triple.c

Index: clang/test/Driver/print-target-triple.c
===
--- clang/test/Driver/print-target-triple.c
+++ clang/test/Driver/print-target-triple.c
@@ -1,6 +1,6 @@
 // Test that -print-target-triple prints correct triple.
 
-// RUN: %clang -print-target-triple 2>&1 \
-// RUN: --target=x86_64-linux-gnu \
+// RUN: %clang -print-target-triple \
+// RUN: --target=x86_64-linux-gnu 2>&1 \
 // RUN:   | FileCheck %s
 // CHECK: x86_64-unknown-linux-gnu
Index: clang/test/Driver/print-multi-directory.c
===
--- clang/test/Driver/print-multi-directory.c
+++ clang/test/Driver/print-multi-directory.c
@@ -1,27 +1,27 @@
-// RUN: %clang -### %s 2>/dev/null \
+// RUN: %clang -### %s \
 // RUN: --target=i386-none-linux \
 // RUN: --sysroot=%S/Inputs/multilib_64bit_linux_tree/usr \
-// RUN: -print-multi-directory \
+// RUN: -print-multi-directory 2>/dev/null \
 // RUN:   | FileCheck --match-full-lines --check-prefix=CHECK-X86-MULTILIBS %s
 
 // CHECK-X86-MULTILIBS:  32
 // CHECK-X86-MULTILIBS-NOT:  {{^.+$}}
 
-// RUN: %clang -### %s 2>/dev/null \
+// RUN: %clang -### %s \
 // RUN: --target=i386-none-linux -m64 \
 // RUN: --sysroot=%S/Inputs/multilib_64bit_linux_tree/usr \
-// RUN: -print-multi-directory \
+// RUN: -print-multi-directory 2>/dev/null \
 // RUN:   | FileCheck --match-full-lines --check-prefix=CHECK-X86_64-MULTILIBS %s
 
 // CHECK-X86_64-MULTILIBS:  .
 // CHECK-X86_64-MULTILIBS-NOT:  {{^.+$}}
 
-// RUN: %clang -### %s 2>/dev/null \
+// RUN: %clang -### %s \
 // RUN: --target=arm-linux-androideabi21 \
 // RUN: -mthumb \
 // RUN: --gcc-toolchain=%S/Inputs/basic_android_ndk_tree \
 // RUN: --sysroot=%S/Inputs/basic_android_ndk_tree/sysroot \
-// RUN: -print-multi-directory \
+// RUN: -print-multi-directory 2>/dev/null \
 // RUN:   | FileCheck --match-full-lines --check-prefix=CHECK-ARM-MULTILIBS %s
 
 // CHECK-ARM-MULTILIBS:  thumb
Index: clang/test/Driver/print-libgcc-file-name-clangrt.c
===
--- clang/test/Driver/print-libgcc-file-name-clangrt.c
+++ clang/test/Driver/print-libgcc-file-name-clangrt.c
@@ -1,65 +1,65 @@
 // Test that -print-libgcc-file-name correctly respects -rtlib=compiler-rt.
 
-// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
+// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name \
 // RUN: --target=x86_64-pc-linux \
 // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \
-// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-X8664 %s
 // CHECK-CLANGRT-X8664: libclang_rt.builtins-x86_64.a
 
-// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
+// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name \
 // RUN: --target=i386-pc-linux \
 // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \
-// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-I386 %s
 // CHECK-CLANGRT-I386: libclang_rt.builtins-i386.a
 
 // Check whether alternate arch values map to the correct library.
 //
-// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
+// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name \
 // RUN: --target=i686-pc-linux \
 // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \
-// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-I386 %s
 
-// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
+// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name \
 // RUN: --target=arm-linux-gnueabi \
 // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \
-// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARM %s
 // CHECK-CLANGRT-ARM: libclang_rt.builtins-arm.a
 
-// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
+// RUN: %clang 

[clang] 731264b - [clang][NFC] Fix location of 2>&1 in a few -print tests

2023-03-25 Thread Louis Dionne via cfe-commits

Author: Louis Dionne
Date: 2023-03-25T15:57:20-04:00
New Revision: 731264b0c2af7aa46bd39625202a99e06cfccff9

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

LOG: [clang][NFC] Fix location of 2>&1 in a few -print tests

While it's apparently valid to place Bash redirections anywhere in a
command-line, it is by far most frequently placed last. This changes
a few tests that did not conform to this convention and which I
originally thought were wrong.

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

Added: 


Modified: 
clang/test/Driver/print-effective-triple.c
clang/test/Driver/print-file-name.c
clang/test/Driver/print-libgcc-file-name-clangrt.c
clang/test/Driver/print-multi-directory.c
clang/test/Driver/print-target-triple.c

Removed: 




diff  --git a/clang/test/Driver/print-effective-triple.c 
b/clang/test/Driver/print-effective-triple.c
index 65b38748d6a3..f621f20942bc 100644
--- a/clang/test/Driver/print-effective-triple.c
+++ b/clang/test/Driver/print-effective-triple.c
@@ -1,6 +1,6 @@
 // Test that -print-target-triple prints correct triple.
 
-// RUN: %clang -print-effective-triple 2>&1 \
-// RUN: --target=thumb-linux-gnu \
+// RUN: %clang -print-effective-triple \
+// RUN: --target=thumb-linux-gnu 2>&1 \
 // RUN:   | FileCheck %s
 // CHECK: armv4t-unknown-linux-gnu

diff  --git a/clang/test/Driver/print-file-name.c 
b/clang/test/Driver/print-file-name.c
index d6dd7a8a57c8..fadb99a74143 100644
--- a/clang/test/Driver/print-file-name.c
+++ b/clang/test/Driver/print-file-name.c
@@ -1,19 +1,19 @@
 // Test that -print-file-name finds the correct file.
 
-// RUN: %clang -print-file-name=share/asan_ignorelist.txt 2>&1 \
+// RUN: %clang -print-file-name=share/asan_ignorelist.txt \
 // RUN: -resource-dir=%S/Inputs/resource_dir \
-// RUN: --target=x86_64-unknown-linux-gnu \
+// RUN: --target=x86_64-unknown-linux-gnu 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-RESOURCE-DIR %s
 // CHECK-RESOURCE-DIR: resource_dir{{/|\\}}share{{/|\\}}asan_ignorelist.txt
 
-// RUN: %clang -print-file-name=libclang_rt.builtins.a 2>&1 \
+// RUN: %clang -print-file-name=libclang_rt.builtins.a \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
-// RUN: --target=x86_64-unknown-linux-gnu \
+// RUN: --target=x86_64-unknown-linux-gnu 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-COMPILER-RT %s
 // CHECK-COMPILER-RT: 
resource_dir_with_per_target_subdir{{/|\\}}lib{{/|\\}}x86_64-unknown-linux-gnu{{/|\\}}libclang_rt.builtins.a
 
-// RUN: %clang -print-file-name=include/c++/v1 2>&1 \
+// RUN: %clang -print-file-name=include/c++/v1 \
 // RUN: -ccc-install-dir %S/Inputs/basic_linux_libcxx_tree/usr/bin \
-// RUN: --target=x86_64-unknown-linux-gnu \
+// RUN: --target=x86_64-unknown-linux-gnu 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-INSTALL-DIR %s
 // CHECK-INSTALL-DIR: 
basic_linux_libcxx_tree{{/|\\}}usr{{/|\\}}bin{{/|\\}}..{{/|\\}}include{{/|\\}}c++{{/|\\}}v1

diff  --git a/clang/test/Driver/print-libgcc-file-name-clangrt.c 
b/clang/test/Driver/print-libgcc-file-name-clangrt.c
index d5e7c48dde29..19f9a3c28c31 100644
--- a/clang/test/Driver/print-libgcc-file-name-clangrt.c
+++ b/clang/test/Driver/print-libgcc-file-name-clangrt.c
@@ -1,65 +1,65 @@
 // Test that -print-libgcc-file-name correctly respects -rtlib=compiler-rt.
 
-// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
+// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name \
 // RUN: --target=x86_64-pc-linux \
 // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \
-// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-X8664 %s
 // CHECK-CLANGRT-X8664: libclang_rt.builtins-x86_64.a
 
-// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
+// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name \
 // RUN: --target=i386-pc-linux \
 // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \
-// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-I386 %s
 // CHECK-CLANGRT-I386: libclang_rt.builtins-i386.a
 
 // Check whether alternate arch values map to the correct library.
 //
-// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name 2>&1 \
+// RUN: %clang -rtlib=compiler-rt -print-libgcc-file-name \
 // RUN: --target=i686-pc-linux \
 // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \
-// RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
+// RUN: 

[PATCH] D146882: [clang-tidy] Correct union & macros handling in modernize-use-equals-default

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

To this moment this check were ignoring only inline
union special members, From now also out-of-line
special members going to be ignored. Also extended
support for IgnoreMacros to cover also macros used
inside a body, or used preprocesor directives.

Fixes:

- https://github.com/llvm/llvm-project/issues/28300
- https://github.com/llvm/llvm-project/issues/40554


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146882

Files:
  clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-default.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-equals-default.cpp
@@ -42,6 +42,18 @@
   NE Field;
 };
 
+// Skip unions with out-of-line constructor/destructor.
+union NUO {
+  NUO();
+  ~NUO();
+  NE Field;
+};
+
+NUO::NUO() {}
+// CHECK-FIXES: NUO::NUO() {}
+NUO::~NUO() {}
+// CHECK-FIXES: NUO::~NUO() {}
+
 // Skip structs/classes containing anonymous unions.
 struct SU {
   SU() {}
@@ -266,3 +278,21 @@
   };
 
 STRUCT_WITH_DEFAULT(unsigned char, InMacro)
+
+#define ZERO_VALUE 0
+struct PreprocesorDependentTest
+{
+  void something();
+
+  PreprocesorDependentTest() {
+#if ZERO_VALUE
+something();
+#endif
+  }
+
+  ~PreprocesorDependentTest() {
+#if ZERO_VALUE
+something();
+#endif
+  }
+};
Index: clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-default.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-default.rst
+++ clang-tools-extra/docs/clang-tidy/checks/modernize/use-equals-default.rst
@@ -32,5 +32,6 @@
 
 .. option:: IgnoreMacros
 
-   If set to `true`, the check will not give warnings inside macros. Default
-   is `true`.
+   If set to `true`, the check will not give warnings inside macros and will
+   ignore special members with bodies contain macros or preprocessor directives.
+   Default is `true`.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -196,6 +196,11 @@
   constructors toward hand written constructors so that they are skipped if more
   than one exists.
 
+- Fixed false positive in :doc:`modernize-use-equals-default
+  ` check for special member
+  functions containing macros or preprocessor directives, and out-of-line special
+  member functions in unions.
+
 - Fixed reading `HungarianNotation.CString.*` options in
   :doc:`readability-identifier-naming
   ` check.
Index: clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
@@ -235,19 +235,19 @@
 
   // Destructor.
   Finder->addMatcher(
-  cxxDestructorDecl(unless(hasParent(IsUnionLikeClass)), isDefinition())
+  cxxDestructorDecl(isDefinition(), unless(ofClass(IsUnionLikeClass)))
   .bind(SpecialFunction),
   this);
+  // Constructor.
   Finder->addMatcher(
   cxxConstructorDecl(
-  unless(
-  hasParent(decl(anyOf(IsUnionLikeClass, functionTemplateDecl(),
-  isDefinition(),
+  isDefinition(), unless(ofClass(IsUnionLikeClass)),
+  unless(hasParent(functionTemplateDecl())),
   anyOf(
   // Default constructor.
-  allOf(unless(hasAnyConstructorInitializer(isWritten())),
-unless(isVariadic()), parameterCountIs(0),
-IsPublicOrOutOfLineUntilCPP20),
+  allOf(parameterCountIs(0),
+unless(hasAnyConstructorInitializer(isWritten())),
+unless(isVariadic()), IsPublicOrOutOfLineUntilCPP20),
   // Copy constructor.
   allOf(isCopyConstructor(),
 // Discard constructors that can be used as a copy
@@ -258,9 +258,9 @@
   this);
   // Copy-assignment operator.
   Finder->addMatcher(
-  cxxMethodDecl(unless(hasParent(
-decl(anyOf(IsUnionLikeClass, functionTemplateDecl(),
-isDefinition(), isCopyAssignmentOperator(),
+  cxxMethodDecl(isDefinition(), isCopyAssignmentOperator(),

[PATCH] D146881: [clang-tidy] Fix findNextTokenSkippingComments & rangeContainsExpansionsOrDirectives

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

findNextTokenSkippingComments is actually a endless loop,
implementing it correctly.
rangeContainsExpansionsOrDirectives were skiping every second
token, if there were no whitespaces bettwen tokens.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146881

Files:
  clang-tools-extra/clang-tidy/utils/LexerUtils.cpp


Index: clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
===
--- clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
+++ clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
@@ -78,11 +78,16 @@
 std::optional
 findNextTokenSkippingComments(SourceLocation Start, const SourceManager ,
   const LangOptions ) {
-  std::optional CurrentToken;
-  do {
-CurrentToken = Lexer::findNextToken(Start, SM, LangOpts);
-  } while (CurrentToken && CurrentToken->is(tok::comment));
-  return CurrentToken;
+  while (Start.isValid()) {
+std::optional CurrentToken =
+Lexer::findNextToken(Start, SM, LangOpts);
+if (!CurrentToken || !CurrentToken->is(tok::comment))
+  return CurrentToken;
+
+Start = CurrentToken->getLocation();
+  }
+
+  return std::nullopt;
 }
 
 bool rangeContainsExpansionsOrDirectives(SourceRange Range,
@@ -91,7 +96,7 @@
   assert(Range.isValid() && "Invalid Range for relexing provided");
   SourceLocation Loc = Range.getBegin();
 
-  while (Loc < Range.getEnd()) {
+  while (Loc <= Range.getEnd()) {
 if (Loc.isMacroID())
   return true;
 
@@ -103,7 +108,7 @@
 if (Tok->is(tok::hash))
   return true;
 
-Loc = Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts).getLocWithOffset(1);
+Loc = Tok->getLocation();
   }
 
   return false;


Index: clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
===
--- clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
+++ clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
@@ -78,11 +78,16 @@
 std::optional
 findNextTokenSkippingComments(SourceLocation Start, const SourceManager ,
   const LangOptions ) {
-  std::optional CurrentToken;
-  do {
-CurrentToken = Lexer::findNextToken(Start, SM, LangOpts);
-  } while (CurrentToken && CurrentToken->is(tok::comment));
-  return CurrentToken;
+  while (Start.isValid()) {
+std::optional CurrentToken =
+Lexer::findNextToken(Start, SM, LangOpts);
+if (!CurrentToken || !CurrentToken->is(tok::comment))
+  return CurrentToken;
+
+Start = CurrentToken->getLocation();
+  }
+
+  return std::nullopt;
 }
 
 bool rangeContainsExpansionsOrDirectives(SourceRange Range,
@@ -91,7 +96,7 @@
   assert(Range.isValid() && "Invalid Range for relexing provided");
   SourceLocation Loc = Range.getBegin();
 
-  while (Loc < Range.getEnd()) {
+  while (Loc <= Range.getEnd()) {
 if (Loc.isMacroID())
   return true;
 
@@ -103,7 +108,7 @@
 if (Tok->is(tok::hash))
   return true;
 
-Loc = Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts).getLocWithOffset(1);
+Loc = Tok->getLocation();
   }
 
   return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145726: Fix assembler error when -g and -gdwarf-* is passed with -fno-integrated-as.

2023-03-25 Thread garvit gupta via Phabricator via cfe-commits
garvitgupta08 added inline comments.



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:976-985
+  bool IsInputTyAsm = false;
+  for (const auto  : Inputs) {
+CmdArgs.push_back(II.getFilename());
+StringRef BaseInput = StringRef(II.getBaseInput());
+types::ID InputType = types::lookupTypeForExtension(
+llvm::sys::path::extension(BaseInput).drop_front());
+if (InputType == types::TY_Asm || InputType == types::TY_PP_Asm)

nickdesaulniers wrote:
> Thinking about this more, does the issue still exist if the user passed .c 
> and .s/.S files together?
> 
> i.e. `$ clang ... -fno-integrated-as -gdwarf-4 foo.s main.c`?
Yes, the error will still be thrown for c/cpp files.


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

https://reviews.llvm.org/D145726

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


[PATCH] D145726: Fix assembler error when -g and -gdwarf-* is passed with -fno-integrated-as.

2023-03-25 Thread garvit gupta via Phabricator via cfe-commits
garvitgupta08 updated this revision to Diff 508328.

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

https://reviews.llvm.org/D145726

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/test/Driver/as-options.cpp
  clang/test/Driver/gcc_forward.c


Index: clang/test/Driver/gcc_forward.c
===
--- clang/test/Driver/gcc_forward.c
+++ clang/test/Driver/gcc_forward.c
@@ -34,3 +34,15 @@
 // CHECK-NOT: "-Wall"
 // CHECK-NOT: "-Wdocumentation"
 // CHECK: "-o" "a.out"
+//
+// Test that -g and -gdwarf-* are not passed through to GAS.
+// RUN: %clang --target=arm-linux-gnueabi -fno-integrated-as -g -c %s -### 
2>&1 | \
+// RUN:   FileCheck --check-prefix=DEBUG %s
+// RUN: %clang --target=arm-linux-gnueabi -fno-integrated-as -gdwarf-4 -c %s 
-### 2>&1 | \
+// RUN:   FileCheck --check-prefix=DEBUG %s
+// RUN: %clang --target=arm-linux-gnueabi -fno-integrated-as -gdwarf-4 -g -c 
%s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=DEBUG %s
+// RUN: %clang --target=arm-linux-gnueabi -fno-integrated-as -g \
+// RUN:   -fdebug-default-version=4 -c %s -### 2>&1 | FileCheck 
--check-prefix=DEBUG %s
+// DEBUG-NOT: "-g"
+// DEBUG-NOT: "-gdwarf-4"
\ No newline at end of file
Index: clang/test/Driver/as-options.cpp
===
--- /dev/null
+++ clang/test/Driver/as-options.cpp
@@ -0,0 +1,11 @@
+// Test that -g and -gdwarf-* are not passed through to GAS.
+// RUN: %clang --target=arm-linux-gnueabi -fno-integrated-as -g -c %s -### 
2>&1 | \
+// RUN:   FileCheck --check-prefix=DEBUG %s
+// RUN: %clang --target=arm-linux-gnueabi -fno-integrated-as -gdwarf-4 -c %s 
-### 2>&1 | \
+// RUN:   FileCheck --check-prefix=DEBUG %s
+// RUN: %clang --target=arm-linux-gnueabi -fno-integrated-as -gdwarf-4 -g -c 
%s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=DEBUG %s
+// RUN: %clang --target=arm-linux-gnueabi -fno-integrated-as -g \
+// RUN:   -fdebug-default-version=4 -c %s -### 2>&1 | FileCheck 
--check-prefix=DEBUG %s
+// DEBUG-NOT: "-g"
+// DEBUG-NOT: "-gdwarf-4"
\ No newline at end of file
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -972,19 +972,27 @@
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
 
-  for (const auto  : Inputs)
-CmdArgs.push_back(II.getFilename());
-
-  if (Arg *A = Args.getLastArg(options::OPT_g_Flag, options::OPT_gN_Group,
-   options::OPT_gdwarf_2, options::OPT_gdwarf_3,
-   options::OPT_gdwarf_4, options::OPT_gdwarf_5,
-   options::OPT_gdwarf))
-if (!A->getOption().matches(options::OPT_g0)) {
-  Args.AddLastArg(CmdArgs, options::OPT_g_Flag);
 
-  unsigned DwarfVersion = getDwarfVersion(getToolChain(), Args);
-  CmdArgs.push_back(Args.MakeArgString("-gdwarf-" + Twine(DwarfVersion)));
-}
+  bool IsInputTyAsm = false;
+  for (const auto  : Inputs) {
+CmdArgs.push_back(II.getFilename());
+StringRef BaseInput = StringRef(II.getBaseInput());
+types::ID InputType = types::lookupTypeForExtension(
+llvm::sys::path::extension(BaseInput).drop_front());
+if (InputType == types::TY_Asm || InputType == types::TY_PP_Asm)
+  IsInputTyAsm = true;
+  }
+
+  if (IsInputTyAsm)
+if (Arg *A = Args.getLastArg(options::OPT_g_Flag, options::OPT_gN_Group,
+ options::OPT_gdwarf_2, options::OPT_gdwarf_3,
+ options::OPT_gdwarf_4, options::OPT_gdwarf_5,
+ options::OPT_gdwarf))
+  if (!A->getOption().matches(options::OPT_g0)) {
+Args.AddLastArg(CmdArgs, options::OPT_g_Flag);
+unsigned DwarfVersion = getDwarfVersion(getToolChain(), Args);
+CmdArgs.push_back(Args.MakeArgString("-gdwarf-" + 
Twine(DwarfVersion)));
+  }
 
   const char *Exec =
   Args.MakeArgString(getToolChain().GetProgramPath(DefaultAssembler));


Index: clang/test/Driver/gcc_forward.c
===
--- clang/test/Driver/gcc_forward.c
+++ clang/test/Driver/gcc_forward.c
@@ -34,3 +34,15 @@
 // CHECK-NOT: "-Wall"
 // CHECK-NOT: "-Wdocumentation"
 // CHECK: "-o" "a.out"
+//
+// Test that -g and -gdwarf-* are not passed through to GAS.
+// RUN: %clang --target=arm-linux-gnueabi -fno-integrated-as -g -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=DEBUG %s
+// RUN: %clang --target=arm-linux-gnueabi -fno-integrated-as -gdwarf-4 -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=DEBUG %s
+// RUN: %clang --target=arm-linux-gnueabi -fno-integrated-as -gdwarf-4 -g -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=DEBUG %s
+// RUN: %clang --target=arm-linux-gnueabi -fno-integrated-as -g \
+// RUN:   -fdebug-default-version=4 -c %s -### 2>&1 

[PATCH] D146148: Float_t and double_t types shouldn't be modified by #pragma clang fp eval_method

2023-03-25 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D146148#4220591 , @zahiraam wrote:

> In D146148#4220495 , @aaron.ballman 
> wrote:
>
>> In D146148#4220433 , @zahiraam 
>> wrote:
>>
>>> In D146148#4220268 , @rjmccall 
>>> wrote:
>>>
 Okay, so modifying `math.h` to use this attribute is acceptable?  That's 
 great, that's definitely the best outcome for the compiler.

 Just a minor request about the diagnostic name, but otherwise LGTM.
>>>
>>> Yes. Added the attribute inside the included math.h header file.
>>
>> How does this work for, say, glibc, musl, or MSVC CRT? Won't those math.h 
>> headers lack the attribute and thus run into problems when used with Clang?
>
> Good point! @rjmccall are you thinking of something in particular with the 
> attribute?

Zahira, this is what I was asking you when I asked whether modifying the math.h 
header was acceptable: whether you were prepared to accept that the warning 
would only fire on system math.h headers that we'd modified, or whether you 
cared about making it work with non-cooperative headers.  I wasn't asking if 
you were willing to change the test code.

> If not I guess we will have to rely on string comparison for all the typedef 
> in the TU. Aaron pointed out the compile time overhead.

Well, the compile-time overhead of doing this on every typedef *declaration* is 
way better than the overhead of doing this on every type lookup, at least.

Anyway, there are three possibilities I can see:

- We accept that this needs cooperative system headers.
- We add a math.h compiler header that `#include_next`s the system math.h and 
then adds the attribute.  I believe you can just add an attribute to a typedef 
retroactively with something like `typedef float_t float_t 
__attribute__((whatever))`.
- We do checks on every typedef declaration.  There's a builtin-identifier 
trick that we do with library functions that we should be able to generalize to 
typedefs, so you wouldn't need to actually do string comparisons, you'd just 
check whether the `IdentifierInfo*` was storing a special ID.  We'd set that up 
in `initializeBuiltins` at the start of the translation unit, so the overhead 
would just be that we'd create two extra `IdentifierInfo*`s in every TU.

The builtin ID logic is currently specific to builtin *functions*, and I don't 
think we'd want to hack typedef names into that.  But the same storage in 
`IdentifierInfo*` is also used for identifying the ObjC context-sensitive 
keywords, by just offsetting the builtin IDs by the NUM_OBJC_KEYWORD.  You 
should be able to generalize that by also introducing a concept of a builtin 
*type* name, so that e.g. IDs in [0,NUM_OBJC_KEYWORDS) are ObjCKeywordKinds, 
IDs in [NUM_OBJC_KEYWORDS, NUM_OBJC_KEYWORDS+NUM_BUILTIN_TYPES) are 
BuiltinTypeKinds (when you subtract NUM_OBJC_KEYWORDS), and IDs in 
[NUM_OBJC_KEYWORDS+NUM_BUILTIN_TYPES,∞) are builtin function IDs (when you 
subtract NUM_OBJC_KEYWORDS+NUM_BUILTIN_TYPES).


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

https://reviews.llvm.org/D146148

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


[PATCH] D145617: [clang-tidy] Add readability-avoid-unconditional-preprocessor-if check

2023-03-25 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 508321.
PiotrZSL added a comment.

Fix doc


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145617

Files:
  
clang-tools-extra/clang-tidy/readability/AvoidUnconditionalPreprocessorIfCheck.cpp
  
clang-tools-extra/clang-tidy/readability/AvoidUnconditionalPreprocessorIfCheck.h
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability/avoid-unconditional-preprocessor-if.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/avoid-unconditional-preprocessor-if.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/avoid-unconditional-preprocessor-if.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability/avoid-unconditional-preprocessor-if.cpp
@@ -0,0 +1,94 @@
+// RUN: %check_clang_tidy %s readability-avoid-unconditional-preprocessor-if %t
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'false', consider removing both the condition and its contents [readability-avoid-unconditional-preprocessor-if]
+#if 0
+// some code
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'true', consider removing condition but leaving its contents [readability-avoid-unconditional-preprocessor-if]
+#if 1
+// some code
+#endif
+
+#if test
+
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'true', consider removing condition but leaving its contents [readability-avoid-unconditional-preprocessor-if]
+#if 10>5
+
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'false', consider removing both the condition and its contents [readability-avoid-unconditional-preprocessor-if]
+#if 10<5
+
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'true', consider removing condition but leaving its contents [readability-avoid-unconditional-preprocessor-if]
+#if 10 > 5
+// some code
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'false', consider removing both the condition and its contents [readability-avoid-unconditional-preprocessor-if]
+#if 10 < 5
+// some code
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'false', consider removing both the condition and its contents [readability-avoid-unconditional-preprocessor-if]
+#if !(10 > \
+5)
+// some code
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'true', consider removing condition but leaving its contents [readability-avoid-unconditional-preprocessor-if]
+#if !(10 < \
+5)
+// some code
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'true', consider removing condition but leaving its contents [readability-avoid-unconditional-preprocessor-if]
+#if true
+// some code
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'false', consider removing both the condition and its contents [readability-avoid-unconditional-preprocessor-if]
+#if false
+// some code
+#endif
+
+#define MACRO
+#ifdef MACRO
+// some code
+#endif
+
+#if !SOMETHING
+#endif
+
+#if !( \
+ defined MACRO)
+// some code
+#endif
+
+
+#if __has_include()
+// some code
+#endif
+
+#if __has_include()
+// some code
+#endif
+
+#define DDD 17
+#define EEE 18
+
+#if 10 > DDD
+// some code
+#endif
+
+#if 10 < DDD
+// some code
+#endif
+
+#if EEE > DDD
+// some code
+#endif
Index: clang-tools-extra/docs/clang-tidy/checks/readability/avoid-unconditional-preprocessor-if.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/readability/avoid-unconditional-preprocessor-if.rst
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - readability-avoid-unconditional-preprocessor-if
+
+readability-avoid-unconditional-preprocessor-if
+===
+
+Finds code blocks that are constantly enabled or disabled in preprocessor
+directives by analyzing ``#if`` conditions, such as ``#if 0`` and ``#if 1``,
+etc.
+
+.. code-block:: c++
+
+#if 0
+// some disabled code
+#endif
+
+#if 1
+   // some enabled code that can be disabled manually
+#endif
+
+Unconditional preprocessor directives, such as ``#if 0`` for disabled code
+and #if 1 for enabled code, can lead to dead code and always enabled code,
+respectively. Dead code can make understanding the codebase more difficult,
+hinder readability, and may be a sign of unfinished functionality or abandoned
+features. This can cause maintenance issues, 

[PATCH] D145617: [clang-tidy] Add readability-avoid-unconditional-preprocessor-if check

2023-03-25 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 508320.
PiotrZSL added a comment.

Doc update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145617

Files:
  
clang-tools-extra/clang-tidy/readability/AvoidUnconditionalPreprocessorIfCheck.cpp
  
clang-tools-extra/clang-tidy/readability/AvoidUnconditionalPreprocessorIfCheck.h
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability/avoid-unconditional-preprocessor-if.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/avoid-unconditional-preprocessor-if.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/avoid-unconditional-preprocessor-if.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability/avoid-unconditional-preprocessor-if.cpp
@@ -0,0 +1,94 @@
+// RUN: %check_clang_tidy %s readability-avoid-unconditional-preprocessor-if %t
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'false', consider removing both the condition and its contents [readability-avoid-unconditional-preprocessor-if]
+#if 0
+// some code
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'true', consider removing condition but leaving its contents [readability-avoid-unconditional-preprocessor-if]
+#if 1
+// some code
+#endif
+
+#if test
+
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'true', consider removing condition but leaving its contents [readability-avoid-unconditional-preprocessor-if]
+#if 10>5
+
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'false', consider removing both the condition and its contents [readability-avoid-unconditional-preprocessor-if]
+#if 10<5
+
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'true', consider removing condition but leaving its contents [readability-avoid-unconditional-preprocessor-if]
+#if 10 > 5
+// some code
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'false', consider removing both the condition and its contents [readability-avoid-unconditional-preprocessor-if]
+#if 10 < 5
+// some code
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'false', consider removing both the condition and its contents [readability-avoid-unconditional-preprocessor-if]
+#if !(10 > \
+5)
+// some code
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'true', consider removing condition but leaving its contents [readability-avoid-unconditional-preprocessor-if]
+#if !(10 < \
+5)
+// some code
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'true', consider removing condition but leaving its contents [readability-avoid-unconditional-preprocessor-if]
+#if true
+// some code
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'false', consider removing both the condition and its contents [readability-avoid-unconditional-preprocessor-if]
+#if false
+// some code
+#endif
+
+#define MACRO
+#ifdef MACRO
+// some code
+#endif
+
+#if !SOMETHING
+#endif
+
+#if !( \
+ defined MACRO)
+// some code
+#endif
+
+
+#if __has_include()
+// some code
+#endif
+
+#if __has_include()
+// some code
+#endif
+
+#define DDD 17
+#define EEE 18
+
+#if 10 > DDD
+// some code
+#endif
+
+#if 10 < DDD
+// some code
+#endif
+
+#if EEE > DDD
+// some code
+#endif
Index: clang-tools-extra/docs/clang-tidy/checks/readability/avoid-unconditional-preprocessor-if.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/readability/avoid-unconditional-preprocessor-if.rst
@@ -0,0 +1,31 @@
+.. title:: clang-tidy - readability-avoid-unconditional-preprocessor-if
+
+readability-avoid-unconditional-preprocessor-if
+===
+
+Check flags always enabled or disabled code blocks in preprocessor ``#if``
+conditions, such as ``#if 0`` and ``#if 1`` etc.
+
+.. code-block:: c++
+
+#if 0
+// some disabled code
+#endif
+
+#if 1
+   // some enabled code that can be disabled manually
+#endif
+
+Unconditional preprocessor directives, such as ``#if 0`` for disabled code
+and #if 1 for enabled code, can lead to dead code and always enabled code,
+respectively. Dead code can make understanding the codebase more difficult,
+hinder readability, and may be a sign of unfinished functionality or abandoned
+features. This can cause maintenance issues, confusion for future developers,

[PATCH] D146874: [clangd] Fix a hover crash on unsigned 64bit value

2023-03-25 Thread Younan Zhang via Phabricator via cfe-commits
zyounan updated this revision to Diff 508316.
zyounan added a comment.

Fix comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146874

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
@@ -2947,6 +2947,15 @@
 getHover(AST, P, format::getLLVMStyle(), nullptr);
 }
 
+TEST(Hover, NoCrashAPInt64) {
+  Annotations T(R"cpp(
+constexpr unsigned long value = -1; // wrap around
+void foo() { va$1^lue; }
+  )cpp");
+  auto AST = TestTU::withCode(T.code()).build();
+  getHover(AST, T.point("1"), format::getLLVMStyle(), nullptr);
+}
+
 TEST(Hover, DocsFromMostSpecial) {
   Annotations T(R"cpp(
   // doc1
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -393,9 +393,9 @@
 // 100   => 0x64
 // Negative numbers are sign-extended to 32/64 bits
 // -2=> 0xfffe
-// -2^32 => 0xfffe
+// -2^32 => 0x
 static llvm::FormattedNumber printHex(const llvm::APSInt ) {
-  uint64_t Bits = V.getExtValue();
+  uint64_t Bits = V.getZExtValue();
   if (V.isNegative() && V.getSignificantBits() <= 32)
 return llvm::format_hex(uint32_t(Bits), 0);
   return llvm::format_hex(Bits, 0);


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2947,6 +2947,15 @@
 getHover(AST, P, format::getLLVMStyle(), nullptr);
 }
 
+TEST(Hover, NoCrashAPInt64) {
+  Annotations T(R"cpp(
+constexpr unsigned long value = -1; // wrap around
+void foo() { va$1^lue; }
+  )cpp");
+  auto AST = TestTU::withCode(T.code()).build();
+  getHover(AST, T.point("1"), format::getLLVMStyle(), nullptr);
+}
+
 TEST(Hover, DocsFromMostSpecial) {
   Annotations T(R"cpp(
   // doc1
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -393,9 +393,9 @@
 // 100   => 0x64
 // Negative numbers are sign-extended to 32/64 bits
 // -2=> 0xfffe
-// -2^32 => 0xfffe
+// -2^32 => 0x
 static llvm::FormattedNumber printHex(const llvm::APSInt ) {
-  uint64_t Bits = V.getExtValue();
+  uint64_t Bits = V.getZExtValue();
   if (V.isNegative() && V.getSignificantBits() <= 32)
 return llvm::format_hex(uint32_t(Bits), 0);
   return llvm::format_hex(Bits, 0);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146875: [clang-tidy] Fix example provided by add_new_check.py

2023-03-25 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 508315.
PiotrZSL edited the summary of this revision.
PiotrZSL added a comment.

Added issue reference


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146875

Files:
  clang-tools-extra/clang-tidy/add_new_check.py


Index: clang-tools-extra/clang-tidy/add_new_check.py
===
--- clang-tools-extra/clang-tidy/add_new_check.py
+++ clang-tools-extra/clang-tidy/add_new_check.py
@@ -275,7 +275,7 @@
 module, check_name + '.' + test_extension))
   print('Creating %s...' % filename)
   with io.open(filename, 'w', encoding='utf8', newline='\n') as f:
-f.write("""// RUN: %%check_clang_tidy %%s %(check_name_dashes)s %%t
+f.write("""// RUN: %%check_clang_tidy %%s %(check_name_dashes)s %%t -- 
--fix-notes
 
 // FIXME: Add something that triggers the check here.
 void f();
@@ -293,7 +293,7 @@
 
 
 def get_actual_filename(dirname, filename):
-  if not os.path.isdir(dirname): 
+  if not os.path.isdir(dirname):
 return ''
   name = os.path.join(dirname, filename)
   if (os.path.isfile(name)):


Index: clang-tools-extra/clang-tidy/add_new_check.py
===
--- clang-tools-extra/clang-tidy/add_new_check.py
+++ clang-tools-extra/clang-tidy/add_new_check.py
@@ -275,7 +275,7 @@
 module, check_name + '.' + test_extension))
   print('Creating %s...' % filename)
   with io.open(filename, 'w', encoding='utf8', newline='\n') as f:
-f.write("""// RUN: %%check_clang_tidy %%s %(check_name_dashes)s %%t
+f.write("""// RUN: %%check_clang_tidy %%s %(check_name_dashes)s %%t -- --fix-notes
 
 // FIXME: Add something that triggers the check here.
 void f();
@@ -293,7 +293,7 @@
 
 
 def get_actual_filename(dirname, filename):
-  if not os.path.isdir(dirname): 
+  if not os.path.isdir(dirname):
 return ''
   name = os.path.join(dirname, filename)
   if (os.path.isfile(name)):
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146875: [clang-tidy] Fix example provided by add_new_check.py

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

Currently test for newly added check in clang-tidy fails,
this is because Fix is attached to note, but test is executed
without --fix-notes. This change adding --fix-notes to test.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146875

Files:
  clang-tools-extra/clang-tidy/add_new_check.py


Index: clang-tools-extra/clang-tidy/add_new_check.py
===
--- clang-tools-extra/clang-tidy/add_new_check.py
+++ clang-tools-extra/clang-tidy/add_new_check.py
@@ -275,7 +275,7 @@
 module, check_name + '.' + test_extension))
   print('Creating %s...' % filename)
   with io.open(filename, 'w', encoding='utf8', newline='\n') as f:
-f.write("""// RUN: %%check_clang_tidy %%s %(check_name_dashes)s %%t
+f.write("""// RUN: %%check_clang_tidy %%s %(check_name_dashes)s %%t -- 
--fix-notes
 
 // FIXME: Add something that triggers the check here.
 void f();
@@ -293,7 +293,7 @@
 
 
 def get_actual_filename(dirname, filename):
-  if not os.path.isdir(dirname): 
+  if not os.path.isdir(dirname):
 return ''
   name = os.path.join(dirname, filename)
   if (os.path.isfile(name)):


Index: clang-tools-extra/clang-tidy/add_new_check.py
===
--- clang-tools-extra/clang-tidy/add_new_check.py
+++ clang-tools-extra/clang-tidy/add_new_check.py
@@ -275,7 +275,7 @@
 module, check_name + '.' + test_extension))
   print('Creating %s...' % filename)
   with io.open(filename, 'w', encoding='utf8', newline='\n') as f:
-f.write("""// RUN: %%check_clang_tidy %%s %(check_name_dashes)s %%t
+f.write("""// RUN: %%check_clang_tidy %%s %(check_name_dashes)s %%t -- --fix-notes
 
 // FIXME: Add something that triggers the check here.
 void f();
@@ -293,7 +293,7 @@
 
 
 def get_actual_filename(dirname, filename):
-  if not os.path.isdir(dirname): 
+  if not os.path.isdir(dirname):
 return ''
   name = os.path.join(dirname, filename)
   if (os.path.isfile(name)):
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146686: [Driver] Fix rpath for compiler-rt

2023-03-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 508312.
yaxunl edited the summary of this revision.
yaxunl added a comment.
Herald added a reviewer: jdoerfert.
Herald added subscribers: jplehr, sstefan1.

adds check for both {resource_dir}/lib/{triple} and 
{resource_dir}/lib/{OS}/{arch}


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

https://reviews.llvm.org/D146686

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/OHOS.cpp
  clang/lib/Driver/ToolChains/OHOS.h
  clang/lib/Driver/ToolChains/VEToolchain.cpp
  clang/test/Driver/arch-specific-per-target-libdir-rpath.c

Index: clang/test/Driver/arch-specific-per-target-libdir-rpath.c
===
--- /dev/null
+++ clang/test/Driver/arch-specific-per-target-libdir-rpath.c
@@ -0,0 +1,86 @@
+// Test that the driver adds an per-target arch-specific subdirectory in
+// {RESOURCE_DIR}/lib/{triple} to the linker search path and to '-rpath'
+//
+// Test the default behavior when neither -frtlib-add-rpath nor
+// -fno-rtlib-add-rpath is specified, which is to skip -rpath
+// RUN: %clang %s -### 2>&1 -target x86_64-linux-gnu \
+// RUN: -fsanitize=address -shared-libasan \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
+//
+// Test that -rpath is not added under -fno-rtlib-add-rpath even if other
+// conditions are met.
+// RUN: %clang %s -### 2>&1 -target x86_64-linux-gnu \
+// RUN: -fsanitize=address -shared-libasan \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN: -fno-rtlib-add-rpath \
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
+//
+// Test that -rpath is added only under the right circumstance even if
+// -frtlib-add-rpath is specified.
+//
+// Add LIBPATH but no RPATH for -fsanitizer=address w/o -shared-libasan
+// RUN: %clang %s -### 2>&1 -target x86_64-linux-gnu -fsanitize=undefined \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN: -frtlib-add-rpath \
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
+//
+// Add LIBPATH but no RPATH for -fsanitizer=address w/o -shared-libasan
+// RUN: %clang %s -### 2>&1 -target x86_64-linux-gnu -fsanitize=undefined \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN: -frtlib-add-rpath \
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
+//
+// Add LIBPATH, RPATH for -fsanitize=address -shared-libasan
+// RUN: %clang %s -### 2>&1 -target x86_64-linux-gnu \
+// RUN: -fsanitize=address -shared-libasan \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN: -frtlib-add-rpath \
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,RPATH-X86_64 %s
+//
+// Add LIBPATH, RPATH with -fsanitize=address for Android
+// RUN: %clang %s -### 2>&1 -target aarch64-linux-android -fsanitize=address \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN: -frtlib-add-rpath \
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-AARCH64-ANDROID,RPATH-AARCH64-ANDROID %s
+//
+// Add LIBPATH, RPATH for OpenMP
+// RUN: %clang %s -### 2>&1 -target x86_64-linux-gnu -fopenmp \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN: -frtlib-add-rpath \
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,RPATH-X86_64 %s
+//
+// Add LIBPATH but no RPATH for ubsan (or any other sanitizer)
+// RUN: %clang %s -### 2>&1 -fsanitize=undefined -target x86_64-linux-gnu \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN: -frtlib-add-rpath \
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
+//
+// Add LIBPATH but no RPATH if no sanitizer or runtime is specified
+// RUN: %clang %s -### 2>&1 -target x86_64-linux-gnu \
+// RUN: -resource-dir=%S/Inputs/resource_dir_with_per_target_subdir \
+// RUN: -frtlib-add-rpath \
+// RUN:   | FileCheck --check-prefixes=RESDIR,LIBPATH-X86_64,NO-RPATH-X86_64 %s
+//
+// Do not add LIBPATH or RPATH if arch-specific subdir doesn't exist
+// RUN: %clang %s -### 2>&1 -target x86_64-linux-gnu \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: -frtlib-add-rpath \
+// RUN:   | FileCheck --check-prefixes=RESDIR,NO-LIBPATH,NO-RPATH %s
+
+// RESDIR: "-resource-dir" "[[RESDIR:[^"]*]]"
+//
+// LIBPATH-X86_64: -L[[RESDIR]]{{(/|)lib(/|)x86_64-unknown-linux-gnu}}
+// RPATH-X86_64:   "-rpath" "[[RESDIR]]{{(/|)lib(/|)x86_64-unknown-linux-gnu}}"
+//
+// LIBPATH-AARCH64-ANDROID: -L[[RESDIR]]{{(/|)lib(/|)aarch64-unknown-linux-android}}
+// RPATH-AARCH64-ANDROID:   "-rpath" 

[PATCH] D146874: [clangd] Fix a hover crash on unsigned 64bit value

2023-03-25 Thread Younan Zhang via Phabricator via cfe-commits
zyounan created this revision.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
zyounan requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This patch adapts to D140059 , which makes an 
assumption that the
caller of `APSInt::getExtValue` promises no narrowing conversion
happens, i.e., from signed int64 to unsigned int64.

It also fixes clangd/clangd#1557.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146874

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
@@ -2947,6 +2947,15 @@
 getHover(AST, P, format::getLLVMStyle(), nullptr);
 }
 
+TEST(Hover, NoCrashAPInt64) {
+  Annotations T(R"cpp(
+constexpr unsigned long value = -1; // wrap around
+void foo() { va$1^lue; }
+  )cpp");
+  auto AST = TestTU::withCode(T.code()).build();
+  getHover(AST, T.point("1"), format::getLLVMStyle(), nullptr);
+}
+
 TEST(Hover, DocsFromMostSpecial) {
   Annotations T(R"cpp(
   // doc1
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -395,7 +395,7 @@
 // -2=> 0xfffe
 // -2^32 => 0xfffe
 static llvm::FormattedNumber printHex(const llvm::APSInt ) {
-  uint64_t Bits = V.getExtValue();
+  uint64_t Bits = V.getZExtValue();
   if (V.isNegative() && V.getSignificantBits() <= 32)
 return llvm::format_hex(uint32_t(Bits), 0);
   return llvm::format_hex(Bits, 0);


Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -2947,6 +2947,15 @@
 getHover(AST, P, format::getLLVMStyle(), nullptr);
 }
 
+TEST(Hover, NoCrashAPInt64) {
+  Annotations T(R"cpp(
+constexpr unsigned long value = -1; // wrap around
+void foo() { va$1^lue; }
+  )cpp");
+  auto AST = TestTU::withCode(T.code()).build();
+  getHover(AST, T.point("1"), format::getLLVMStyle(), nullptr);
+}
+
 TEST(Hover, DocsFromMostSpecial) {
   Annotations T(R"cpp(
   // doc1
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -395,7 +395,7 @@
 // -2=> 0xfffe
 // -2^32 => 0xfffe
 static llvm::FormattedNumber printHex(const llvm::APSInt ) {
-  uint64_t Bits = V.getExtValue();
+  uint64_t Bits = V.getZExtValue();
   if (V.isNegative() && V.getSignificantBits() <= 32)
 return llvm::format_hex(uint32_t(Bits), 0);
   return llvm::format_hex(Bits, 0);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145868: [clang][ASTImporter] Fix import of anonymous structures

2023-03-25 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers added a comment.

@balazske , I tested these changes - again - and it all seems to work for me. I 
would have preferred we do not see the build status failures before doing this, 
but maybe we can be sure to avoid this next time (because I'll want to test 
again before our final merge). Please move ahead with your changes and let us 
know when you're ready for final review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145868

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


[PATCH] D140996: [c++20] P1907R1: Support for generalized non-type template arguments of scalar type.

2023-03-25 Thread Andrey Ali Khan Bolshakov via Phabricator via cfe-commits
bolshakov-a updated this revision to Diff 508311.
bolshakov-a added a comment.

Rebased.


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

https://reviews.llvm.org/D140996

Files:
  clang-tools-extra/clangd/DumpAST.cpp
  clang-tools-extra/clangd/FindTarget.cpp
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ODRHash.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/TemplateArgumentVisitor.h
  clang/include/clang/AST/TemplateBase.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp
  clang/test/CodeGenCXX/mangle-ms-templates.cpp
  clang/test/CodeGenCXX/mangle-template.cpp
  clang/test/CodeGenCXX/template-arguments.cpp
  clang/test/Index/USR/structural-value-tpl-arg.cpp
  clang/test/Modules/odr_hash.cpp
  clang/test/SemaCXX/warn-bool-conversion.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp
  clang/www/cxx_status.html
  lldb/include/lldb/lldb-enumerations.h
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -7297,6 +7297,9 @@
 
   case clang::TemplateArgument::Pack:
 return eTemplateArgumentKindPack;
+
+  case clang::TemplateArgument::StructuralValue:
+return eTemplateArgumentKindStructuralValue;
   }
   llvm_unreachable("Unhandled clang::TemplateArgument::ArgKind");
 }
Index: lldb/include/lldb/lldb-enumerations.h
===
--- lldb/include/lldb/lldb-enumerations.h
+++ lldb/include/lldb/lldb-enumerations.h
@@ -834,6 +834,7 @@
   eTemplateArgumentKindExpression,
   eTemplateArgumentKindPack,
   eTemplateArgumentKindNullPtr,
+  eTemplateArgumentKindStructuralValue,
 };
 
 /// Type of match to be performed when looking for a formatter for a data type.
Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1053,13 +1053,21 @@
 
 
 
-  Class types as non-type template parameters
+  Class types as non-type template parameters
   https://wg21.link/p0732r2;>P0732R2
-  Partial
+  Clang 12
+
+ 
+  Generalized non-type template parameters of scalar type
+  https://wg21.link/p1907r1;>P1907R1
+  
+
+  Clang 17 (Partial)
+  Reference type template arguments referring to instantiation-dependent objects and subobjects
+  (i.e. declared inside a template but neither type- nor value-dependent) aren't fully supported.
+
+  
 
-   
-https://wg21.link/p1907r1;>P1907R1
-  
 
   Destroying operator delete
   https://wg21.link/p0722r3;>P0722R3
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -1463,6 +1463,9 @@
 return CXTemplateArgumentKind_NullPtr;
   case TemplateArgument::Integral:
 return CXTemplateArgumentKind_Integral;
+  case TemplateArgument::StructuralValue:
+// FIXME: Expose these values.
+return CXTemplateArgumentKind_Invalid;
   case TemplateArgument::Template:
 return CXTemplateArgumentKind_Template;
   case TemplateArgument::TemplateExpansion:
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -1570,6 +1570,11 @@
   return Visit(MakeCXCursor(E, StmtParent, TU, RegionOfInterest));
 return false;
 
+  case TemplateArgument::StructuralValue:
+if (Expr *E = TAL.getSourceStructuralValueExpression())
+  return Visit(MakeCXCursor(E, StmtParent, TU, RegionOfInterest));
+return false;
+
   case TemplateArgument::NullPtr:
 

[PATCH] D144522: [clang-tidy] Add readability-operators-representation check

2023-03-25 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 508310.
PiotrZSL added a comment.

Fixes in documentation & clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144522

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.cpp
  clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.h
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability/operators-representation.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/operators-representation-to-alternative.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/operators-representation-to-traditional.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/operators-representation-to-traditional.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability/operators-representation-to-traditional.cpp
@@ -0,0 +1,177 @@
+// RUN: %check_clang_tidy %s readability-operators-representation %t -- -config="{CheckOptions: [\
+// RUN: {key: readability-operators-representation.BinaryOperators, value: '&&;&=;&;|;~;!;!=;||;|=;^;^='}, \
+// RUN: {key: readability-operators-representation.OverloadedOperators, value: '&&;&=;&;|;~;!;!=;||;|=;^;^='}]}" --
+
+void testAllTokensToAlternative(int a, int b) {
+  int value = 0;
+
+  value = a or b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'or' is an alternative token spelling, consider using a traditional token '||' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = a || b;{{$}}
+
+  value = a and b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'and' is an alternative token spelling, consider using a traditional token '&&' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = a && b;{{$}}
+
+  value = a bitor b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'bitor' is an alternative token spelling, consider using a traditional token '|' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = a | b;{{$}}
+
+  value = a bitand b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'bitand' is an alternative token spelling, consider using a traditional token '&' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = a & b;{{$}}
+
+  value = not a;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 'not' is an alternative token spelling, consider using a traditional token '!' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = ! a;{{$}}
+
+  value = a xor b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'xor' is an alternative token spelling, consider using a traditional token '^' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = a ^ b;{{$}}
+
+  value = compl b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 'compl' is an alternative token spelling, consider using a traditional token '~' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = ~ b;{{$}}
+
+  value and_eq b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: 'and_eq' is an alternative token spelling, consider using a traditional token '&=' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value &= b;{{$}}
+
+  value or_eq b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: 'or_eq' is an alternative token spelling, consider using a traditional token '|=' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value |= b;{{$}}
+
+  value = a not_eq b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'not_eq' is an alternative token spelling, consider using a traditional token '!=' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = a != b;{{$}}
+
+  value xor_eq a;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: 'xor_eq' is an alternative token spelling, consider using a traditional token '^=' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value ^= a;{{$}}
+}
+
+struct Class {
+  bool operator!() const;
+  Class operator~() const;
+  bool operator&&(const Class&) const;
+  Class operator&(const Class&) const;
+  bool operator||(const Class&) const;
+  Class operator|(const Class&) const;
+  Class operator^(const Class&) const;
+  Class& operator&=(const Class&) const;
+  Class& operator|=(const Class&) const;
+  Class& operator^=(const Class&) const;
+  bool operator!=(const Class&) const;
+};
+
+void testAllTokensToAlternative(Class a, Class b) {
+  int value = 0;
+  Class clval;
+
+  value = a or b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'or' 

[PATCH] D146867: [Diagnostic] printing name of uninitialized subobject instead of its type

2023-03-25 Thread suman meena via Phabricator via cfe-commits
simideveloper added a comment.

can you please tell me if this issue is closed or I can work on making the 
changes you recommended?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146867

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


[PATCH] D146441: [APFloat] Add E4M3B11FNUZ

2023-03-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/MicrosoftMangle.cpp:848
   case APFloat::S_Float8E4M3FNUZ:
+  case APFloat::S_Float8E4M3B11FNUZ:
 llvm_unreachable("Tried to mangle unexpected APFloat semantics");

majnemer wrote:
> aaron.ballman wrote:
> > Why are there no changes needed for the Itanium mangler? And when did we 
> > start adding a bunch of esoteric float formats? Was there an RFC for this 
> > that I missed? (If I did miss something, then sorry for the noise.)
> Hi Aaron,
> 
> The Itanium mangler doesn't depend on the APFloat's semantics, it just 
> depends on:
> - The Clang AST type of the float.
> - The bit pattern of the APFloat.
> 
> The code to handle the bit pattern is written generically, regardless of 
> APFloat semantics.
> Because of this and the lack of a new Clang built-in floating type results in 
> no necessary changes to the Itanium mangler.
> 
> This just comes down to a quirk in how the MSVC and Itanium manglers are 
> written: new APFloat semantics necessarily result in the MSVC mangler 
> "noticing" while they don't for the Itanium mangler.
> 
> As to your question about an RFC, one was posted for some similar but 
> different formats that people are interested in 
> [here](https://discourse.llvm.org/t/rfc-adding-the-amd-graphcore-maybe-others-float8-formats-to-apfloat/67969)
> 
> The general consensus on that RFC was that APFloat should support formats 
> that people use in practice. This format is incorporated as part of real 
> hardware in the real world as well as an [open source compiler 
> framework](https://github.com/openxla/stablehlo/blob/main/rfcs/20230309-e4m3b11.md).
Thank you for the explanation (and IRC discussion)! This all seems reasonable 
to me. I was mostly worried that there were more Clang parts that needed 
attention and discussion, but this is more used for backend work and isn't 
really exposed to the frontend except in these sort of fully covered switch 
cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146441

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


[PATCH] D146873: [POC][Clang][RISCV] Define RVV tuple types

2023-03-25 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 508309.
eopXD added a comment.

Update code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146873

Files:
  clang/include/clang/Basic/RISCVVTypes.def
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-tuple-type-0.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-tuple-type-1.c
  clang/test/Sema/riscv-types.c

Index: clang/test/Sema/riscv-types.c
===
--- clang/test/Sema/riscv-types.c
+++ clang/test/Sema/riscv-types.c
@@ -133,6 +133,9 @@
 
   // CHECK: __rvv_int8mf2_t x43;
   __rvv_int8mf2_t x43;
+
+  // CHECK: __rvv_int32m1x2_t x44;
+  __rvv_int32m1x2_t x44;
 }
 
 typedef __rvv_bool4_t vbool4_t;
Index: clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-tuple-type-1.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-tuple-type-1.c
@@ -0,0 +1,49 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2
+// RUN: %clang_cc1 -triple riscv64 -target-feature +zve32x -disable-O0-optnone \
+// RUN:   -emit-llvm %s -o - | opt -S -passes=mem2reg | FileCheck %s
+
+#include 
+
+// Declare local variable
+// CHECK-LABEL: define dso_local void @foo
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret void
+//
+void foo() {
+  __rvv_int32m1x2_t v_tuple;
+}
+
+// Declare local variable and return
+// CHECK-LABEL: define dso_local { ,  } @bar
+// CHECK-SAME: () #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret { ,  } undef
+//
+__rvv_int32m1x2_t bar() {
+  __rvv_int32m1x2_t v_tuple;
+  return v_tuple;
+}
+
+// Pass as function parameter
+// CHECK-LABEL: define dso_local void @baz
+// CHECK-SAME: ( [[V_TUPLE_COERCE0:%.*]],  [[V_TUPLE_COERCE1:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = insertvalue { ,  } undef,  [[V_TUPLE_COERCE0]], 0
+// CHECK-NEXT:[[TMP1:%.*]] = insertvalue { ,  } [[TMP0]],  [[V_TUPLE_COERCE1]], 1
+// CHECK-NEXT:ret void
+//
+void baz(__rvv_int32m1x2_t v_tuple) {
+}
+
+// Pass as function parameter and return
+// CHECK-LABEL: define dso_local { ,  } @qux
+// CHECK-SAME: ( [[V_TUPLE_COERCE0:%.*]],  [[V_TUPLE_COERCE1:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = insertvalue { ,  } undef,  [[V_TUPLE_COERCE0]], 0
+// CHECK-NEXT:[[TMP1:%.*]] = insertvalue { ,  } [[TMP0]],  [[V_TUPLE_COERCE1]], 1
+// CHECK-NEXT:ret { ,  } [[TMP1]]
+//
+__rvv_int32m1x2_t qux(__rvv_int32m1x2_t v_tuple) {
+  return v_tuple;
+}
Index: clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-tuple-type-0.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-tuple-type-0.c
@@ -0,0 +1,65 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2
+// RUN: %clang_cc1 -triple riscv64 -target-feature +zve32x -O0 \
+// RUN:   -emit-llvm %s -o - | FileCheck %s
+
+#include 
+
+// Declare local variable
+// CHECK-LABEL: define dso_local void @foo
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[V_TUPLE:%.*]] = alloca { ,  }, align 4
+// CHECK-NEXT:ret void
+//
+void foo() {
+  __rvv_int32m1x2_t v_tuple;
+}
+
+// Declare local variable and return
+// CHECK-LABEL: define dso_local { ,  } @bar
+// CHECK-SAME: () #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[V_TUPLE:%.*]] = alloca { ,  }, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load { ,  }, ptr [[V_TUPLE]], align 4
+// CHECK-NEXT:ret { ,  } [[TMP0]]
+//
+__rvv_int32m1x2_t bar() {
+  __rvv_int32m1x2_t v_tuple;
+  return v_tuple;
+}
+
+// Pass as function parameter
+// CHECK-LABEL: define dso_local void @baz
+// CHECK-SAME: ( [[V_TUPLE_COERCE0:%.*]],  [[V_TUPLE_COERCE1:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[V_TUPLE:%.*]] = alloca { ,  }, align 4
+// CHECK-NEXT:[[V_TUPLE_ADDR:%.*]] = alloca { ,  }, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load { ,  }, ptr [[V_TUPLE]], align 4
+// CHECK-NEXT:[[TMP1:%.*]] = insertvalue { ,  } [[TMP0]],  [[V_TUPLE_COERCE0]], 0
+// CHECK-NEXT:[[TMP2:%.*]] = insertvalue { ,  } [[TMP1]],  [[V_TUPLE_COERCE1]], 1
+// CHECK-NEXT:store { ,  } [[TMP2]], ptr [[V_TUPLE]], align 4
+// CHECK-NEXT:[[V_TUPLE1:%.*]] = load { ,  }, ptr [[V_TUPLE]], align 4
+// CHECK-NEXT:store { ,  } [[V_TUPLE1]], ptr [[V_TUPLE_ADDR]], align 4
+// CHECK-NEXT:ret void
+//
+void baz(__rvv_int32m1x2_t v_tuple) {
+}
+
+// Pass as function parameter and return
+// CHECK-LABEL: define dso_local { ,  } @qux
+// CHECK-SAME: ( [[V_TUPLE_COERCE0:%.*]],  [[V_TUPLE_COERCE1:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:

[PATCH] D146873: [POC][Clang][RISCV] Define RVV tuple types

2023-03-25 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD created this revision.
eopXD added reviewers: craig.topper, efriedma, sdesmalen, rogfer01, 
frasercrmck, lebedev.ri, david-arm, jdoerfert, reames, kito-cheng.
Herald added subscribers: jobnoorman, luke, VincentWu, StephenFan, vkmr, 
evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, 
jocewei, PkmX, the_o, brucehoult, MartinMosbeck, edward-jones, zzheng, jrtc27, 
shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, arichardson.
Herald added a project: All.
eopXD requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, MaskRay.
Herald added a project: clang.

Depends on D146872 .

This patch originates from D97264 , it further 
allows local variable
declaration and function parameter passing by adjustment in clang
lowering.

Test cases are provided to demonstrate the LLVM IR generated.

Authored-by: eop Chen 
Co-Authored-by: Hsiangkai Wang 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146873

Files:
  clang/include/clang/Basic/RISCVVTypes.def
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-tuple-type-0.c
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-tuple-type-1.c
  clang/test/Sema/riscv-types.c

Index: clang/test/Sema/riscv-types.c
===
--- clang/test/Sema/riscv-types.c
+++ clang/test/Sema/riscv-types.c
@@ -133,6 +133,9 @@
 
   // CHECK: __rvv_int8mf2_t x43;
   __rvv_int8mf2_t x43;
+
+  // CHECK: __rvv_int32m1x2_t x44;
+  __rvv_int32m1x2_t x44;
 }
 
 typedef __rvv_bool4_t vbool4_t;
Index: clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-tuple-type-1.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-tuple-type-1.c
@@ -0,0 +1,49 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2
+// RUN: %clang_cc1 -triple riscv64 -target-feature +zve32x -disable-O0-optnone \
+// RUN:   -emit-llvm %s -o - | opt -S -passes=mem2reg | FileCheck %s
+
+#include 
+
+// Declare local variable
+// CHECK-LABEL: define dso_local void @foo
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret void
+//
+void foo() {
+  __rvv_int32m1x2_t v_tuple;
+}
+
+// Declare local variable and return
+// CHECK-LABEL: define dso_local { ,  } @bar
+// CHECK-SAME: () #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret { ,  } undef
+//
+__rvv_int32m1x2_t bar() {
+  __rvv_int32m1x2_t v_tuple;
+  return v_tuple;
+}
+
+// Pass as function parameter
+// CHECK-LABEL: define dso_local void @baz
+// CHECK-SAME: ( [[V_TUPLE_COERCE0:%.*]],  [[V_TUPLE_COERCE1:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = insertvalue { ,  } undef,  [[V_TUPLE_COERCE0]], 0
+// CHECK-NEXT:[[TMP1:%.*]] = insertvalue { ,  } [[TMP0]],  [[V_TUPLE_COERCE1]], 1
+// CHECK-NEXT:ret void
+//
+void baz(__rvv_int32m1x2_t v_tuple) {
+}
+
+// Pass as function parameter and return
+// CHECK-LABEL: define dso_local { ,  } @qux
+// CHECK-SAME: ( [[V_TUPLE_COERCE0:%.*]],  [[V_TUPLE_COERCE1:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = insertvalue { ,  } undef,  [[V_TUPLE_COERCE0]], 0
+// CHECK-NEXT:[[TMP1:%.*]] = insertvalue { ,  } [[TMP0]],  [[V_TUPLE_COERCE1]], 1
+// CHECK-NEXT:ret { ,  } [[TMP1]]
+//
+__rvv_int32m1x2_t qux(__rvv_int32m1x2_t v_tuple) {
+  return v_tuple;
+}
Index: clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-tuple-type-0.c
===
--- /dev/null
+++ clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/rvv-tuple-type-0.c
@@ -0,0 +1,65 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2
+// RUN: %clang_cc1 -triple riscv64 -target-feature +zve32x -O0 \
+// RUN:   -emit-llvm %s -o - | FileCheck %s
+
+#include 
+
+// Declare local variable
+// CHECK-LABEL: define dso_local void @foo
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[V_TUPLE:%.*]] = alloca { ,  }, align 4
+// CHECK-NEXT:ret void
+//
+void foo() {
+  __rvv_int32m1x2_t v_tuple;
+}
+
+// Declare local variable and return
+// CHECK-LABEL: define dso_local { ,  } @bar
+// CHECK-SAME: () #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[V_TUPLE:%.*]] = alloca { ,  }, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load { ,  }, ptr [[V_TUPLE]], align 4
+// CHECK-NEXT:ret { ,  } [[TMP0]]
+//
+__rvv_int32m1x2_t bar() {
+  __rvv_int32m1x2_t v_tuple;
+  return v_tuple;
+}
+
+// Pass as function parameter
+// CHECK-LABEL: define dso_local void @baz
+// CHECK-SAME: ( [[V_TUPLE_COERCE0:%.*]],  [[V_TUPLE_COERCE1:%.*]]) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[V_TUPLE:%.*]] = alloca 

[PATCH] D146441: [APFloat] Add E4M3B11FNUZ

2023-03-25 Thread David Majnemer via Phabricator via cfe-commits
majnemer added inline comments.



Comment at: clang/lib/AST/MicrosoftMangle.cpp:848
   case APFloat::S_Float8E4M3FNUZ:
+  case APFloat::S_Float8E4M3B11FNUZ:
 llvm_unreachable("Tried to mangle unexpected APFloat semantics");

aaron.ballman wrote:
> Why are there no changes needed for the Itanium mangler? And when did we 
> start adding a bunch of esoteric float formats? Was there an RFC for this 
> that I missed? (If I did miss something, then sorry for the noise.)
Hi Aaron,

The Itanium mangler doesn't depend on the APFloat's semantics, it just depends 
on:
- The Clang AST type of the float.
- The bit pattern of the APFloat.

The code to handle the bit pattern is written generically, regardless of 
APFloat semantics.
Because of this and the lack of a new Clang built-in floating type results in 
no necessary changes to the Itanium mangler.

This just comes down to a quirk in how the MSVC and Itanium manglers are 
written: new APFloat semantics necessarily result in the MSVC mangler 
"noticing" while they don't for the Itanium mangler.

As to your question about an RFC, one was posted for some similar but different 
formats that people are interested in 
[here](https://discourse.llvm.org/t/rfc-adding-the-amd-graphcore-maybe-others-float8-formats-to-apfloat/67969)

The general consensus on that RFC was that APFloat should support formats that 
people use in practice. This format is incorporated as part of real hardware in 
the real world as well as an [open source compiler 
framework](https://github.com/openxla/stablehlo/blob/main/rfcs/20230309-e4m3b11.md).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146441

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


[PATCH] D145617: [clang-tidy] Add readability-avoid-unconditional-preprocessor-if check

2023-03-25 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:139
+
+  Check flags always enabled or disabled code blocks in preprocessor ``#if``
+  conditions, such as ``#if 0`` and ``#if 1`` etc.

Please omit `Check`.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/readability/avoid-unconditional-preprocessor-if.rst:6
+
+Check flags always enabled or disabled code blocks in preprocessor ``#if``
+conditions, such as ``#if 0`` and ``#if 1`` etc.

Ditto.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145617

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


[PATCH] D144522: [clang-tidy] Add readability-operators-representation check

2023-03-25 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:139
+
+  Check helps enforce consistent token representation for invoked binary,
+  unary and overloaded operators in C++ code.

Please omit `Check`.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/readability/operators-representation.rst:6
+
+Check helps enforce consistent token representation for invoked binary, unary
+and overloaded operators in C++ code. The check supports both traditional and

Ditto.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144522

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


[PATCH] D140996: [c++20] P1907R1: Support for generalized non-type template arguments of scalar type.

2023-03-25 Thread Andrey Ali Khan Bolshakov via Phabricator via cfe-commits
bolshakov-a updated this revision to Diff 508305.
bolshakov-a added a comment.

Add type to USR so as not to get confused with

  template  struct S {};
  struct { int n; } s;
  
  template<>
  struct S<(void*)> {};
  
  template<>
  struct S<> {};

Add test on structural type NTTP USR. Just a couple of cases have been added 
because most of the relevant code should already be covered by `odr_hash.cpp` 
test.


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

https://reviews.llvm.org/D140996

Files:
  clang-tools-extra/clangd/DumpAST.cpp
  clang-tools-extra/clangd/FindTarget.cpp
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ODRHash.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/AST/TemplateArgumentVisitor.h
  clang/include/clang/AST/TemplateBase.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TemplateBase.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp
  clang/test/CodeGenCXX/mangle-ms-templates.cpp
  clang/test/CodeGenCXX/mangle-template.cpp
  clang/test/CodeGenCXX/template-arguments.cpp
  clang/test/Index/USR/structural-value-tpl-arg.cpp
  clang/test/Modules/odr_hash.cpp
  clang/test/SemaCXX/warn-bool-conversion.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp
  clang/www/cxx_status.html
  lldb/include/lldb/lldb-enumerations.h
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -7311,6 +7311,9 @@
 
   case clang::TemplateArgument::Pack:
 return eTemplateArgumentKindPack;
+
+  case clang::TemplateArgument::StructuralValue:
+return eTemplateArgumentKindStructuralValue;
   }
   llvm_unreachable("Unhandled clang::TemplateArgument::ArgKind");
 }
Index: lldb/include/lldb/lldb-enumerations.h
===
--- lldb/include/lldb/lldb-enumerations.h
+++ lldb/include/lldb/lldb-enumerations.h
@@ -834,6 +834,7 @@
   eTemplateArgumentKindExpression,
   eTemplateArgumentKindPack,
   eTemplateArgumentKindNullPtr,
+  eTemplateArgumentKindStructuralValue,
 };
 
 /// Type of match to be performed when looking for a formatter for a data type.
Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1053,13 +1053,21 @@
 
 
 
-  Class types as non-type template parameters
+  Class types as non-type template parameters
   https://wg21.link/p0732r2;>P0732R2
-  Partial
+  Clang 12
+
+ 
+  Generalized non-type template parameters of scalar type
+  https://wg21.link/p1907r1;>P1907R1
+  
+
+  Clang 17 (Partial)
+  Reference type template arguments referring to instantiation-dependent objects and subobjects
+  (i.e. declared inside a template but neither type- nor value-dependent) aren't fully supported.
+
+  
 
-   
-https://wg21.link/p1907r1;>P1907R1
-  
 
   Destroying operator delete
   https://wg21.link/p0722r3;>P0722R3
Index: clang/tools/libclang/CXCursor.cpp
===
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -1463,6 +1463,9 @@
 return CXTemplateArgumentKind_NullPtr;
   case TemplateArgument::Integral:
 return CXTemplateArgumentKind_Integral;
+  case TemplateArgument::StructuralValue:
+// FIXME: Expose these values.
+return CXTemplateArgumentKind_Invalid;
   case TemplateArgument::Template:
 return CXTemplateArgumentKind_Template;
   case TemplateArgument::TemplateExpansion:
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -1570,6 +1570,11 @@
   

[PATCH] D145770: [clang-offload-bundler] Standardize TargetID field for bundler

2023-03-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D145770#4220246 , @mdtoguchi wrote:

> @lamb-j - is it expected for any bundled objects created before your change 
> without the explicit env field to be able to be unbundled?  Newly generated 
> bundles work as expected given similar `-target` values, but older generated 
> binaries fail to unbundle the target given equivalent commands.  Is it 
> possible to provide the ability to do so?

what is the target used by the old bundle? Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145770

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


[PATCH] D146520: [clang-tidy] Fix checks filter with warnings-as-errors

2023-03-25 Thread kiwixz via Phabricator via cfe-commits
kiwixz added a comment.

Your understanding is correct, I'm currently just trying to hide them at the 
end (warnings-as-errors or not).
This is how it worked until 5d12b13b0b26bc58b02ee23c369da8b83240cceb 
 (present 
in LLVM 16) which inadvertently bypass the filters with warnings-as-errors.

Note that I'm just trying to restore the previous behavior, while I'm sure 
PiotrZSL and others will make the whole thing more elegant for next releases.
My hope here is to fix LLVM 16 so we don't have errors that we explicitly 
disabled showing up, and only when enabling warnings-as-errors.

My patch does two things:

- deleting the two lines in ClangTidyDiagnosticConsumer.cpp which introduced 
the new and bad behavior
- adding two lines in ClangTidy.cpp to classify warnings as errors when 
appropriate in the YAML (this was the goal of the aforementioned commit)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146520

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


[PATCH] D146719: [Clang] Improve diagnostics when using a concept as template argument

2023-03-25 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.






Comment at: clang/lib/Parse/Parser.cpp:1886-1889
+  case Sema::NC_Concept:
   case Sema::NC_VarTemplate:
   case Sema::NC_FunctionTemplate:
   case Sema::NC_UndeclaredTemplate: {

aaron.ballman wrote:
> cor3ntin wrote:
> > aaron.ballman wrote:
> > > Would this change make sense, to validate that we're still consuming the 
> > > token in these three cases? I think it was an assumption we made 
> > > previously, but it's not clear to me if the code used to consume 
> > > something other than `<` as well.
> > I'm not sure. You'll notice that using a var template without template 
> > argument does not trigger the assert. That's because `ClassifyName` will 
> > return `NC_NonType` instead of `NC_VarTemplate` in that case. I don't think 
> > that makes sense either, but that require more investigation. I do think 
> > however all template names not followed by arguments should produce a 
> > TemplateIdAnnotation so the change is not not correct :)
> > 
> > If you insist, i can put the assert back, but I'm not sure the assert was 
> > testing the right thing.
> I don't insist on adding the assert, it was more a matter of trying to figure 
> out whether the changes to the non-concept cases have changed parsing 
> behavior in some subtle way. My thinking is that an assert that fails 
> (signaling we are no longer consuming a token when we previously would have) 
> would be easier for us to debug than a mysterious parsing failure. But if 
> that assert would be wrong to add, then it makes me wonder what the test case 
> is for it because then we've changed parsing behavior.
Funnily, the cases 

```
case Sema::NC_VarTemplate:
case Sema::NC_FunctionTemplate:
case Sema::NC_UndeclaredTemplate:```

Are never traversed, We can remove them without breaking tests. the assert 
doesn't do anything then. arguably `ClassifyName` needs further fix but that 
might be more complicated surgery


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146719

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


[PATCH] D146719: [Clang] Improve diagnostics when using a concept as template argument

2023-03-25 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146719

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


[PATCH] D144522: [clang-tidy] Add readability-operators-representation check

2023-03-25 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 508303.
PiotrZSL marked an inline comment as done.
PiotrZSL added a comment.

Rebase + Fix comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144522

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.cpp
  clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.h
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability/operators-representation.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/operators-representation-to-alternative.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/operators-representation-to-traditional.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/operators-representation-to-traditional.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability/operators-representation-to-traditional.cpp
@@ -0,0 +1,177 @@
+// RUN: %check_clang_tidy %s readability-operators-representation %t -- -config="{CheckOptions: [\
+// RUN: {key: readability-operators-representation.BinaryOperators, value: '&&;&=;&;|;~;!;!=;||;|=;^;^='}, \
+// RUN: {key: readability-operators-representation.OverloadedOperators, value: '&&;&=;&;|;~;!;!=;||;|=;^;^='}]}" --
+
+void testAllTokensToAlternative(int a, int b) {
+  int value = 0;
+
+  value = a or b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'or' is an alternative token spelling, consider using a traditional token '||' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = a || b;{{$}}
+
+  value = a and b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'and' is an alternative token spelling, consider using a traditional token '&&' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = a && b;{{$}}
+
+  value = a bitor b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'bitor' is an alternative token spelling, consider using a traditional token '|' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = a | b;{{$}}
+
+  value = a bitand b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'bitand' is an alternative token spelling, consider using a traditional token '&' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = a & b;{{$}}
+
+  value = not a;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 'not' is an alternative token spelling, consider using a traditional token '!' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = ! a;{{$}}
+
+  value = a xor b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'xor' is an alternative token spelling, consider using a traditional token '^' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = a ^ b;{{$}}
+
+  value = compl b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: 'compl' is an alternative token spelling, consider using a traditional token '~' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = ~ b;{{$}}
+
+  value and_eq b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: 'and_eq' is an alternative token spelling, consider using a traditional token '&=' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value &= b;{{$}}
+
+  value or_eq b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: 'or_eq' is an alternative token spelling, consider using a traditional token '|=' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value |= b;{{$}}
+
+  value = a not_eq b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: 'not_eq' is an alternative token spelling, consider using a traditional token '!=' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value = a != b;{{$}}
+
+  value xor_eq a;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: 'xor_eq' is an alternative token spelling, consider using a traditional token '^=' for consistency [readability-operators-representation]
+  // CHECK-FIXES: {{^  }}value ^= a;{{$}}
+}
+
+struct Class {
+  bool operator!() const;
+  Class operator~() const;
+  bool operator&&(const Class&) const;
+  Class operator&(const Class&) const;
+  bool operator||(const Class&) const;
+  Class operator|(const Class&) const;
+  Class operator^(const Class&) const;
+  Class& operator&=(const Class&) const;
+  Class& operator|=(const Class&) const;
+  Class& operator^=(const Class&) const;
+  bool operator!=(const Class&) const;
+};
+
+void testAllTokensToAlternative(Class a, Class b) {
+  int value = 0;
+  Class clval;
+
+  value = a or b;
+  // CHECK-MESSAGES: 

[PATCH] D144522: [clang-tidy] Add readability-operators-representation check

2023-03-25 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL marked 8 inline comments as done.
PiotrZSL added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.cpp:220
+  if (!isAnyOperatorEnabled(OverloadedOperators, OperatorsRepresentation) &&
+  isAnyOperatorEnabled(OverloadedOperators, UnaryRepresentation))
+return;

carlosgalvezp wrote:
> Is this condition intended to be negated too? Also, would it make sense to 
> move this early return to the beginning of the function?
Good catch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144522

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


[PATCH] D146719: [Clang] Improve diagnostics when using a concept as template argument

2023-03-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Parse/Parser.cpp:1886-1889
+  case Sema::NC_Concept:
   case Sema::NC_VarTemplate:
   case Sema::NC_FunctionTemplate:
   case Sema::NC_UndeclaredTemplate: {

cor3ntin wrote:
> aaron.ballman wrote:
> > Would this change make sense, to validate that we're still consuming the 
> > token in these three cases? I think it was an assumption we made 
> > previously, but it's not clear to me if the code used to consume something 
> > other than `<` as well.
> I'm not sure. You'll notice that using a var template without template 
> argument does not trigger the assert. That's because `ClassifyName` will 
> return `NC_NonType` instead of `NC_VarTemplate` in that case. I don't think 
> that makes sense either, but that require more investigation. I do think 
> however all template names not followed by arguments should produce a 
> TemplateIdAnnotation so the change is not not correct :)
> 
> If you insist, i can put the assert back, but I'm not sure the assert was 
> testing the right thing.
I don't insist on adding the assert, it was more a matter of trying to figure 
out whether the changes to the non-concept cases have changed parsing behavior 
in some subtle way. My thinking is that an assert that fails (signaling we are 
no longer consuming a token when we previously would have) would be easier for 
us to debug than a mysterious parsing failure. But if that assert would be 
wrong to add, then it makes me wonder what the test case is for it because then 
we've changed parsing behavior.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146719

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


[PATCH] D145617: [clang-tidy] Add readability-avoid-unconditional-preprocessor-if check

2023-03-25 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 508302.
PiotrZSL added a comment.

Rebase + Shorten documentation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145617

Files:
  
clang-tools-extra/clang-tidy/readability/AvoidUnconditionalPreprocessorIfCheck.cpp
  
clang-tools-extra/clang-tidy/readability/AvoidUnconditionalPreprocessorIfCheck.h
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability/avoid-unconditional-preprocessor-if.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/avoid-unconditional-preprocessor-if.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/avoid-unconditional-preprocessor-if.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability/avoid-unconditional-preprocessor-if.cpp
@@ -0,0 +1,94 @@
+// RUN: %check_clang_tidy %s readability-avoid-unconditional-preprocessor-if %t
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'false', consider removing both the condition and its contents [readability-avoid-unconditional-preprocessor-if]
+#if 0
+// some code
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'true', consider removing condition but leaving its contents [readability-avoid-unconditional-preprocessor-if]
+#if 1
+// some code
+#endif
+
+#if test
+
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'true', consider removing condition but leaving its contents [readability-avoid-unconditional-preprocessor-if]
+#if 10>5
+
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'false', consider removing both the condition and its contents [readability-avoid-unconditional-preprocessor-if]
+#if 10<5
+
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'true', consider removing condition but leaving its contents [readability-avoid-unconditional-preprocessor-if]
+#if 10 > 5
+// some code
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'false', consider removing both the condition and its contents [readability-avoid-unconditional-preprocessor-if]
+#if 10 < 5
+// some code
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'false', consider removing both the condition and its contents [readability-avoid-unconditional-preprocessor-if]
+#if !(10 > \
+5)
+// some code
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'true', consider removing condition but leaving its contents [readability-avoid-unconditional-preprocessor-if]
+#if !(10 < \
+5)
+// some code
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'true', consider removing condition but leaving its contents [readability-avoid-unconditional-preprocessor-if]
+#if true
+// some code
+#endif
+
+// CHECK-MESSAGES: :[[@LINE+1]]:2: warning: preprocessor condition is always 'false', consider removing both the condition and its contents [readability-avoid-unconditional-preprocessor-if]
+#if false
+// some code
+#endif
+
+#define MACRO
+#ifdef MACRO
+// some code
+#endif
+
+#if !SOMETHING
+#endif
+
+#if !( \
+ defined MACRO)
+// some code
+#endif
+
+
+#if __has_include()
+// some code
+#endif
+
+#if __has_include()
+// some code
+#endif
+
+#define DDD 17
+#define EEE 18
+
+#if 10 > DDD
+// some code
+#endif
+
+#if 10 < DDD
+// some code
+#endif
+
+#if EEE > DDD
+// some code
+#endif
Index: clang-tools-extra/docs/clang-tidy/checks/readability/avoid-unconditional-preprocessor-if.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/readability/avoid-unconditional-preprocessor-if.rst
@@ -0,0 +1,31 @@
+.. title:: clang-tidy - readability-avoid-unconditional-preprocessor-if
+
+readability-avoid-unconditional-preprocessor-if
+===
+
+Check flags always enabled or disabled code blocks in preprocessor ``#if``
+conditions, such as ``#if 0`` and ``#if 1`` etc.
+
+.. code-block:: c++
+
+#if 0
+// some disabled code
+#endif
+
+#if 1
+   // some enabled code that can be disabled manually
+#endif
+
+Unconditional preprocessor directives, such as ``#if 0`` for disabled code
+and #if 1 for enabled code, can lead to dead code and always enabled code,
+respectively. Dead code can make understanding the codebase more difficult,
+hinder readability, and may be a sign of unfinished functionality or abandoned
+features. This can cause maintenance issues, confusion for 

[PATCH] D146420: Document the Clang policies on claiming support for a feature

2023-03-25 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.
This revision is now accepted and ready to land.

LGTM. I have some minor reservations about defining feature macros on a 
per-target basis but at the same time, given the current coroutines on 32 bits 
windows situation - which has been lingering - I'm not sure i can come up with 
a more sensible alternative


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

https://reviews.llvm.org/D146420

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


[PATCH] D146420: Document the Clang policies on claiming support for a feature

2023-03-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman updated this revision to Diff 508301.
aaron.ballman added a comment.

Fixing a typo pointed out off-list (missed an "as").


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

https://reviews.llvm.org/D146420

Files:
  clang/docs/InternalsManual.rst


Index: clang/docs/InternalsManual.rst
===
--- clang/docs/InternalsManual.rst
+++ clang/docs/InternalsManual.rst
@@ -3268,3 +3268,39 @@
  proper visitation for your expression, enabling various IDE features such
  as syntax highlighting, cross-referencing, and so on.  The
  ``c-index-test`` helper program can be used to test these features.
+
+Feature Test Macros
+===
+Clang implements several ways to test whether a feature is supported or not.
+Some of these feature tests are standardized, like ``__has_cpp_attribute`` or
+``__cpp_lambdas``, while others are Clang extensions, like ``__has_builtin``.
+The common theme among all the various feature tests is that they are a utility
+to tell users that we think a particular feature is complete. However,
+completeness is a difficult property to define because features may still have
+lingering bugs, may only work on some targets, etc. We use the following
+criteria when deciding whether to expose a feature test macro (or particular
+result value for the feature test):
+
+  * Are there known issues where we reject valid code that should be accepted?
+  * Are there known issues where we accept invalid code that should be 
rejected?
+  * Are there known crashes, failed assertions, or miscompilations?
+  * Are there known issues on a particular relevant target?
+
+If the answer to any of these is "yes", the feature test macro should either
+not be defined or there should be very strong rationale for why the issues
+should not prevent defining it. Note, it is acceptable to define the feature
+test macro on a per-target basis if needed.
+
+When in doubt, being conservative is better than being aggressive. If we don't
+claim support for the feature but it does useful things, users can still use it
+and provide us with useful feedback on what is missing. But if we claim support
+for a feature that has significant bugs, we've eliminated most of the utility
+of having a feature testing macro at all because users are then forced to test
+what compiler version is in use to get a more accurate answer.
+
+The status reported by the feature test macro should always be reflected in the
+language support page for the corresponding feature (`C++
+`_, `C
+`_) if applicable. This page can give
+more nuanced information to the user as well, such as claiming partial support
+for a feature and specifying details as to what remains to be done.


Index: clang/docs/InternalsManual.rst
===
--- clang/docs/InternalsManual.rst
+++ clang/docs/InternalsManual.rst
@@ -3268,3 +3268,39 @@
  proper visitation for your expression, enabling various IDE features such
  as syntax highlighting, cross-referencing, and so on.  The
  ``c-index-test`` helper program can be used to test these features.
+
+Feature Test Macros
+===
+Clang implements several ways to test whether a feature is supported or not.
+Some of these feature tests are standardized, like ``__has_cpp_attribute`` or
+``__cpp_lambdas``, while others are Clang extensions, like ``__has_builtin``.
+The common theme among all the various feature tests is that they are a utility
+to tell users that we think a particular feature is complete. However,
+completeness is a difficult property to define because features may still have
+lingering bugs, may only work on some targets, etc. We use the following
+criteria when deciding whether to expose a feature test macro (or particular
+result value for the feature test):
+
+  * Are there known issues where we reject valid code that should be accepted?
+  * Are there known issues where we accept invalid code that should be rejected?
+  * Are there known crashes, failed assertions, or miscompilations?
+  * Are there known issues on a particular relevant target?
+
+If the answer to any of these is "yes", the feature test macro should either
+not be defined or there should be very strong rationale for why the issues
+should not prevent defining it. Note, it is acceptable to define the feature
+test macro on a per-target basis if needed.
+
+When in doubt, being conservative is better than being aggressive. If we don't
+claim support for the feature but it does useful things, users can still use it
+and provide us with useful feedback on what is missing. But if we claim support
+for a feature that has significant bugs, we've eliminated most of the utility
+of having a feature testing macro at all because users are then forced to test
+what compiler version is in use to get a 

[clang] 254a71b - [Clang] Update DR status page to reflect Core Issues List 111.

2023-03-25 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-03-25T13:20:11+01:00
New Revision: 254a71b6d2ef6a0ee1c1b2b9706ab56a56b7663f

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

LOG: [Clang] Update DR status page to reflect Core Issues List 111.

Added: 


Modified: 
clang/test/CXX/drs/dr25xx.cpp
clang/test/CXX/drs/dr26xx.cpp
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/test/CXX/drs/dr25xx.cpp b/clang/test/CXX/drs/dr25xx.cpp
index c4f7d3ebde413..0800adda63928 100644
--- a/clang/test/CXX/drs/dr25xx.cpp
+++ b/clang/test/CXX/drs/dr25xx.cpp
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify
 
-namespace dr2518 { // dr2518: 17 review
+namespace dr2518 { // dr2518: 17
 
 template 
 void f(T t) {

diff  --git a/clang/test/CXX/drs/dr26xx.cpp b/clang/test/CXX/drs/dr26xx.cpp
index e69a151b9d029..f2ec677297d22 100644
--- a/clang/test/CXX/drs/dr26xx.cpp
+++ b/clang/test/CXX/drs/dr26xx.cpp
@@ -14,7 +14,8 @@ using enum E; // expected-error {{unknown type name E}}
 }
 }
 
-namespace dr2628 { // dr2628: no, this was reverted for the 16.x release
+namespace dr2628 { // dr2628: no open
+   // this was reverted for the 16.x release
// due to regressions, see the issue for more details:
// https://github.com/llvm/llvm-project/issues/60777
 

diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index f57aafcdb3090..0e1101e3d42ca 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -1053,11 +1053,11 @@ C++ defect report implementation 
status
 template-ids in using-declarations
 Yes
   
-  
+  
 https://wg21.link/cwg170;>170
-review
+tentatively ready
 Pointer-to-member conversions
-Not resolved
+Unknown
   
   
 https://wg21.link/cwg171;>171
@@ -4489,11 +4489,11 @@ C++ defect report implementation 
status
 Matching template arguments with template template parameters with 
parameter packs
 Unknown
   
-  
+  
 https://wg21.link/cwg745;>745
-open
+C++23
 Effect of ill-formedness resulting from #error
-Not resolved
+Unknown
   
   
 https://wg21.link/cwg746;>746
@@ -5235,7 +5235,7 @@ C++ defect report implementation 
status
   
   
 https://wg21.link/cwg900;>900
-DR
+DRWP
 Lifetime of temporaries in range-based for
 Unknown
   
@@ -6033,7 +6033,7 @@ C++ defect report implementation 
status
   
   
 https://wg21.link/cwg1038;>1038
-open
+review
 Overload resolution of x.static_func
 Not resolved
   
@@ -6059,7 +6059,7 @@ C++ defect report implementation 
status
 https://wg21.link/cwg1042;>1042
 C++11
 Attributes in alias-declarations
-3.5
+Clang 3.5
   
   
 https://wg21.link/cwg1043;>1043
@@ -7921,11 +7921,11 @@ C++ defect report implementation 
status
 Inconsistent class scope and completeness rules
 Unknown
   
-  
+  
 https://wg21.link/cwg1353;>1353
-drafting
+tentatively ready
 Array and variant members and deleted special member functions
-Not resolved
+Unknown
   
   
 https://wg21.link/cwg1354;>1354
@@ -7963,11 +7963,11 @@ C++ defect report implementation 
status
 constexpr union constructors
 Clang 3.5
   
-  
+  
 https://wg21.link/cwg1360;>1360
-drafting
+CD6
 constexpr defaulted default constructors
-Not resolved
+Unknown
   
   
 https://wg21.link/cwg1361;>1361
@@ -8179,11 +8179,11 @@ C++ defect report implementation 
status
 Partial ordering of variadic templates reconsidered
 Clang 16
   
-  
+  
 https://wg21.link/cwg1396;>1396
-review
+DRWP
 Deferred instantiation and checking of non-static data member 
initializers
-Not resolved
+Unknown
   
   
 https://wg21.link/cwg1397;>1397
@@ -8221,11 +8221,11 @@ C++ defect report implementation 
status
 Move functions too often deleted
 Unknown
   
-  
+  
 https://wg21.link/cwg1403;>1403
-review
+CD6
 Universal-character-names in comments
-Not resolved
+Unknown
   
   
 https://wg21.link/cwg1404;>1404
@@ -9417,7 +9417,7 @@ C++ defect report implementation 
status
   
   
 https://wg21.link/cwg1602;>1602
-open
+review
 Linkage of specialization vs linkage of template arguments
 Not resolved
   
@@ -10537,11 +10537,11 @@ C++ defect report implementation 
status
 Sized deallocation of array of non-class type
 Unknown
   
-  
+  
 https://wg21.link/cwg1789;>1789
-tentatively ready
+open
 Array reference vs array decay in overload resolution
-Unknown
+Not resolved
   
   
 https://wg21.link/cwg1790;>1790
@@ -10897,11 +10897,11 @@ C++ defect report implementation 

[PATCH] D146420: Document the Clang policies on claiming support for a feature

2023-03-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Ping


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

https://reviews.llvm.org/D146420

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


[PATCH] D146441: [APFloat] Add E4M3B11FNUZ

2023-03-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/MicrosoftMangle.cpp:848
   case APFloat::S_Float8E4M3FNUZ:
+  case APFloat::S_Float8E4M3B11FNUZ:
 llvm_unreachable("Tried to mangle unexpected APFloat semantics");

Why are there no changes needed for the Itanium mangler? And when did we start 
adding a bunch of esoteric float formats? Was there an RFC for this that I 
missed? (If I did miss something, then sorry for the noise.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146441

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


[PATCH] D141672: [RISCV] Support vector crypto extension ISA string and assembly

2023-03-25 Thread Brandon Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9795aa042a84: [RISCV] Support vector crypto extension ISA 
string and assembly (authored by 4vtomat).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141672

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
  llvm/lib/Target/RISCV/RISCVFeatures.td
  llvm/lib/Target/RISCV/RISCVInstrFormats.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVInstrInfoV.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZvk.td
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rvv/zvkb.s
  llvm/test/MC/RISCV/rvv/zvkg.s
  llvm/test/MC/RISCV/rvv/zvkned-invalid.s
  llvm/test/MC/RISCV/rvv/zvkned.s
  llvm/test/MC/RISCV/rvv/zvknh.s
  llvm/test/MC/RISCV/rvv/zvksed-invalid.s
  llvm/test/MC/RISCV/rvv/zvksed.s
  llvm/test/MC/RISCV/rvv/zvksh.s

Index: llvm/test/MC/RISCV/rvv/zvksh.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvv/zvksh.s
@@ -0,0 +1,21 @@
+# RUN: llvm-mc -triple=riscv32 -show-encoding --mattr=+zve32x --mattr=+experimental-zvksh %s \
+# RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv32 -show-encoding %s 2>&1 \
+# RUN:| FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv32 -filetype=obj --mattr=+zve32x --mattr=+experimental-zvksh %s \
+# RUN:| llvm-objdump -d --mattr=+zve32x --mattr=+experimental-zvksh  - \
+# RUN:| FileCheck %s --check-prefix=CHECK-INST
+# RUN: llvm-mc -triple=riscv32 -filetype=obj --mattr=+zve32x --mattr=+experimental-zvksh %s \
+# RUN:| llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
+
+vsm3c.vi v10, v9, 7
+# CHECK-INST: vsm3c.vi v10, v9, 7
+# CHECK-ENCODING: [0x77,0xa5,0x93,0xae]
+# CHECK-ERROR: instruction requires the following: 'Zvksh' (SM3 Hash Function Instructions.){{$}}
+# CHECK-UNKNOWN: 77 a5 93 ae   
+
+vsm3me.vv v10, v9, v8
+# CHECK-INST: vsm3me.vv v10, v9, v8
+# CHECK-ENCODING: [0x77,0x25,0x94,0x82]
+# CHECK-ERROR: instruction requires the following: 'Zvksh' (SM3 Hash Function Instructions.){{$}}
+# CHECK-UNKNOWN: 77 25 94 82   
Index: llvm/test/MC/RISCV/rvv/zvksed.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvv/zvksed.s
@@ -0,0 +1,27 @@
+# RUN: llvm-mc -triple=riscv32 -show-encoding --mattr=+zve32x --mattr=+experimental-zvksed %s \
+# RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv32 -show-encoding %s 2>&1 \
+# RUN:| FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv32 -filetype=obj --mattr=+zve32x --mattr=+experimental-zvksed %s \
+# RUN:| llvm-objdump -d --mattr=+zve32x --mattr=+experimental-zvksed  - \
+# RUN:| FileCheck %s --check-prefix=CHECK-INST
+# RUN: llvm-mc -triple=riscv32 -filetype=obj --mattr=+zve32x --mattr=+experimental-zvksed %s \
+# RUN:| llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
+
+vsm4k.vi v10, v9, 7
+# CHECK-INST: vsm4k.vi v10, v9, 7
+# CHECK-ENCODING: [0x77,0xa5,0x93,0x86]
+# CHECK-ERROR: instruction requires the following: 'Zvksed' (SM4 Block Cipher Instructions.){{$}}
+# CHECK-UNKNOWN: 77 a5 93 86   
+
+vsm4r.vv v10, v9
+# CHECK-INST: vsm4r.vv v10, v9
+# CHECK-ENCODING: [0x77,0x25,0x98,0xa2]
+# CHECK-ERROR: instruction requires the following: 'Zvksed' (SM4 Block Cipher Instructions.){{$}}
+# CHECK-UNKNOWN: 77 25 98 a2   
+
+vsm4r.vs v10, v9
+# CHECK-INST: vsm4r.vs v10, v9
+# CHECK-ENCODING: [0x77,0x25,0x98,0xa6]
+# CHECK-ERROR: instruction requires the following: 'Zvksed' (SM4 Block Cipher Instructions.){{$}}
+# CHECK-UNKNOWN: 77 25 98 a6   
Index: llvm/test/MC/RISCV/rvv/zvksed-invalid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvv/zvksed-invalid.s
@@ -0,0 +1,5 @@
+# RUN: not llvm-mc -triple=riscv32 --mattr=+zve32x --mattr=+experimental-zvksed -show-encoding %s 2>&1 \
+# RUN:| FileCheck %s --check-prefix=CHECK-ERROR
+
+vsm4k.vi v10, v9, 8
+# CHECK-ERROR: immediate must be an integer in the range [0, 7]
Index: llvm/test/MC/RISCV/rvv/zvknh.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvv/zvknh.s
@@ -0,0 +1,34 @@
+# RUN: llvm-mc -triple=riscv32 -show-encoding --mattr=+zve32x --mattr=+experimental-zvknha %s \
+# RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: llvm-mc -triple=riscv64 -show-encoding --mattr=+zve64x --mattr=+experimental-zvknhb %s \
+# RUN:| FileCheck %s 

[clang] 9795aa0 - [RISCV] Support vector crypto extension ISA string and assembly

2023-03-25 Thread via cfe-commits

Author: 4vtomat
Date: 2023-03-25T05:15:55-07:00
New Revision: 9795aa042a843811120b1b2ef4f8a6d7f398a369

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

LOG: [RISCV] Support vector crypto extension ISA string and assembly

LLVM implements the 0.3 draft specification:
https://github.com/riscv/riscv-crypto/releases/download/v20230206/riscv-crypto-spec-vector.pdf
, and current vector crypto extension version can be found in:
https://github.com/riscv/riscv-crypto.

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

Added: 
llvm/lib/Target/RISCV/RISCVInstrInfoZvk.td
llvm/test/MC/RISCV/rvv/zvkb.s
llvm/test/MC/RISCV/rvv/zvkg.s
llvm/test/MC/RISCV/rvv/zvkned-invalid.s
llvm/test/MC/RISCV/rvv/zvkned.s
llvm/test/MC/RISCV/rvv/zvknh.s
llvm/test/MC/RISCV/rvv/zvksed-invalid.s
llvm/test/MC/RISCV/rvv/zvksed.s
llvm/test/MC/RISCV/rvv/zvksh.s

Modified: 
clang/test/Preprocessor/riscv-target-features.c
llvm/docs/RISCVUsage.rst
llvm/lib/Support/RISCVISAInfo.cpp
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
llvm/lib/Target/RISCV/RISCVFeatures.td
llvm/lib/Target/RISCV/RISCVInstrFormats.td
llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
llvm/lib/Target/RISCV/RISCVInstrInfo.td
llvm/lib/Target/RISCV/RISCVInstrInfoV.td
llvm/test/CodeGen/RISCV/attributes.ll
llvm/test/MC/RISCV/attribute-arch.s

Removed: 




diff  --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 755248f63edff..e979f967c0fa2 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -49,6 +49,15 @@
 // CHECK-NOT: __riscv_zcd {{.*$}}
 // CHECK-NOT: __riscv_zcf {{.*$}}
 // CHECK-NOT: __riscv_h {{.*$}}
+// CHECK-NOT: __riscv_zvkb {{.*$}}
+// CHECK-NOT: __riscv_zvkg {{.*$}}
+// CHECK-NOT: __riscv_zvkn {{.*$}}
+// CHECK-NOT: __riscv_zvknha {{.*$}}
+// CHECK-NOT: __riscv_zvknhb {{.*$}}
+// CHECK-NOT: __riscv_zvkned {{.*$}}
+// CHECK-NOT: __riscv_zvks {{.*$}}
+// CHECK-NOT: __riscv_zvksed {{.*$}}
+// CHECK-NOT: __riscv_zvksh {{.*$}}
 
 // RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32i -x c -E -dM %s \
 // RUN: -o - | FileCheck %s
@@ -514,3 +523,75 @@
 // RUN: -march=rv64izfa0p1 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZFA-EXT %s
 // CHECK-ZFA-EXT: __riscv_zfa 1000{{$}}
+
+// RUN: %clang -target riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32i_zve64x_zvkb0p3 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKB-EXT %s
+// RUN: %clang -target riscv64 -menable-experimental-extensions \
+// RUN: -march=rv64i_zve64x_zvkb0p3 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKB-EXT %s
+// CHECK-ZVKB-EXT: __riscv_zvkb  3000{{$}}
+
+// RUN: %clang -target riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32i_zve32x_zvkg0p3 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKG-EXT %s
+// RUN: %clang -target riscv64 -menable-experimental-extensions \
+// RUN: -march=rv64i_zve32x_zvkg0p3 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKG-EXT %s
+// CHECK-ZVKG-EXT: __riscv_zvkg  3000{{$}}
+
+// RUN: %clang -target riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32i_zve64x_zvkn0p3 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKN-EXT %s
+// RUN: %clang -target riscv64 -menable-experimental-extensions \
+// RUN: -march=rv64i_zve64x_zvkn0p3 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKN-EXT %s
+// CHECK-ZVKN-EXT: __riscv_zvkn 3000{{$}}
+
+// RUN: %clang -target riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32i_zve32x_zvknha0p3 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKNHA-EXT %s
+// RUN: %clang -target riscv64 -menable-experimental-extensions \
+// RUN: -march=rv64i_zve32x_zvknha0p3 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKNHA-EXT %s
+// CHECK-ZVKNHA-EXT: __riscv_zvknha 3000{{$}}
+
+// RUN: %clang -target riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32i_zve64x_zvknhb0p3 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKNHB-EXT %s
+// RUN: %clang -target riscv64 -menable-experimental-extensions \
+// RUN: -march=rv64i_zve64x_zvknhb0p3 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKNHB-EXT %s
+// CHECK-ZVKNHB-EXT: __riscv_zvknhb  3000{{$}}
+
+// RUN: %clang -target riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32i_zve32x_zvkned0p3 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZVKNED-EXT %s
+// RUN: %clang -target riscv64 -menable-experimental-extensions \
+// RUN: 

[PATCH] D146719: [Clang] Improve diagnostics when using a concept as template argument

2023-03-25 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/Parse/Parser.cpp:1886-1889
+  case Sema::NC_Concept:
   case Sema::NC_VarTemplate:
   case Sema::NC_FunctionTemplate:
   case Sema::NC_UndeclaredTemplate: {

aaron.ballman wrote:
> Would this change make sense, to validate that we're still consuming the 
> token in these three cases? I think it was an assumption we made previously, 
> but it's not clear to me if the code used to consume something other than `<` 
> as well.
I'm not sure. You'll notice that using a var template without template argument 
does not trigger the assert. That's because `ClassifyName` will return 
`NC_NonType` instead of `NC_VarTemplate` in that case. I don't think that makes 
sense either, but that require more investigation. I do think however all 
template names not followed by arguments should produce a TemplateIdAnnotation 
so the change is not not correct :)

If you insist, i can put the assert back, but I'm not sure the assert was 
testing the right thing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146719

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


[PATCH] D146719: [Clang] Improve diagnostics when using a concept as template argument

2023-03-25 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 508299.
cor3ntin added a comment.

- Address Aaron's and Erich's comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146719

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/Parser/cxx-template-template-recovery.cpp

Index: clang/test/Parser/cxx-template-template-recovery.cpp
===
--- /dev/null
+++ clang/test/Parser/cxx-template-template-recovery.cpp
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -std=c++20 -verify -fsyntax-only %s
+
+namespace a {
+  template 
+  concept C1 = true; // #C1
+
+  template 
+  auto V1 = true; // #V1
+
+  namespace b {
+template 
+concept C2 = true; // #C2
+template 
+auto V2 = true; // #V2
+  }
+}
+
+template 
+concept C3 = true; // #C3
+template 
+auto V3 = true; // #V3
+template  typename C>
+constexpr bool test = true;
+
+static_assert(test); // expected-error {{too few template arguments for concept 'C1'}} \
+// expected-note@#C1 {{here}}
+static_assert(test); // expected-error {{too few template arguments for concept 'C2'}} \
+   // expected-note@#C2 {{here}}
+static_assert(test); // expected-error {{too few template arguments for concept 'C3'}} \
+ // expected-note@#C3 {{here}}
+
+static_assert(test); // expected-error {{use of variable template 'V1' requires template arguments}} \
+// expected-note@#V1 {{here}}
+static_assert(test); // expected-error {{use of variable template 'V2' requires template arguments}} \
+// expected-note@#V2 {{here}}
+static_assert(test); // expected-error {{use of variable template 'V3' requires template arguments}} \
+ // expected-note@#V3 {{here}}
+
+
+void f() {
+C3 t1 = 0;  // expected-error {{expected 'auto' or 'decltype(auto)' after concept name}}
+a::C1 t2 = 0; // expected-error {{expected 'auto' or 'decltype(auto)' after concept name}}
+a::b::C2 t3 = 0; // expected-error {{expected 'auto' or 'decltype(auto)' after concept name}}
+}
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -1883,31 +1883,25 @@
   return ANK_TemplateName;
 }
 [[fallthrough]];
+  case Sema::NC_Concept:
   case Sema::NC_VarTemplate:
   case Sema::NC_FunctionTemplate:
   case Sema::NC_UndeclaredTemplate: {
-// We have a type, variable or function template followed by '<'.
-ConsumeToken();
-UnqualifiedId Id;
-Id.setIdentifier(Name, NameLoc);
-if (AnnotateTemplateIdToken(
-TemplateTy::make(Classification.getTemplateName()),
-Classification.getTemplateNameKind(), SS, SourceLocation(), Id))
-  return ANK_Error;
-return ANK_Success;
-  }
-  case Sema::NC_Concept: {
-UnqualifiedId Id;
-Id.setIdentifier(Name, NameLoc);
+bool IsConceptName = Classification.getKind() == Sema::NC_Concept;
+// We have a template name followed by '<'. Consume the identifier token so
+// we reach the '<' and annotate it.
 if (Next.is(tok::less))
-  // We have a concept name followed by '<'. Consume the identifier token so
-  // we reach the '<' and annotate it.
   ConsumeToken();
+UnqualifiedId Id;
+Id.setIdentifier(Name, NameLoc);
 if (AnnotateTemplateIdToken(
 TemplateTy::make(Classification.getTemplateName()),
 Classification.getTemplateNameKind(), SS, SourceLocation(), Id,
-/*AllowTypeAnnotation=*/false, /*TypeConstraint=*/true))
+/*AllowTypeAnnotation=*/!IsConceptName,
+/*TypeConstraint=*/IsConceptName))
   return ANK_Error;
+if (SS.isNotEmpty())
+  AnnotateScopeToken(SS, !WasScopeAnnotation);
 return ANK_Success;
   }
   }
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -3448,12 +3448,12 @@
 continue;
   }
 
-  if (TemplateId && TemplateId->Kind == TNK_Concept_template &&
-  GetLookAheadToken(2).isOneOf(tok::kw_auto, tok::kw_decltype)) {
+  if (TemplateId && TemplateId->Kind == TNK_Concept_template) {
 DS.getTypeSpecScope() = SS;
-// This is a qualified placeholder-specifier, e.g., ::C auto ...
-// Consume the scope annotation and continue to consume the template-id
-// as a placeholder-specifier.
+// This is probably a qualified placeholder-specifier, e.g., ::C
+// auto ... Consume the scope annotation and continue to consume the
+// template-id as a placeholder-specifier. Let the next iteration
+// diagnose a missing auto.
 

[PATCH] D146376: Update static_assert message for redundant cases

2023-03-25 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber updated this revision to Diff 508297.
Krishna-13-cyber added a comment.

Updated with the new test cases and implemented the logic suggested for 
ignoring the BO_LOr operators at the top level. My sincere apologies @tbaeder 
that I could not place this logic at the first instance.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146376

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/static-assert.cpp


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,9 +258,17 @@
   constexpr bool invert(bool b) {
 return !b;
   }
+
+  /// Bools are printed with disjunction.
+  static_assert(invert(true) || invert(true), ""); // expected-error 
{{failed}} \
+
+  /// Bools are printed with an expected note.
   static_assert(invert(true) == invert(false), ""); // expected-error 
{{failed}} \
 // expected-note 
{{evaluates to 'false == true'}}
 
+  /// Bools are printed with conjunction.
+  static_assert(true && false, ""); // expected-error {{failed}} \
+
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
 
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16728,6 +16728,10 @@
 if (!UsefulToPrintExpr(LHS) && !UsefulToPrintExpr(RHS))
   return;
 
+// Ignore BO_LOr operators at the toplevel.
+if (Op->getOpcode() == BO_LOr)
+  return;
+
 struct {
   const clang::Expr *Cond;
   Expr::EvalResult Result;


Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -258,9 +258,17 @@
   constexpr bool invert(bool b) {
 return !b;
   }
+
+  /// Bools are printed with disjunction.
+  static_assert(invert(true) || invert(true), ""); // expected-error {{failed}} \
+
+  /// Bools are printed with an expected note.
   static_assert(invert(true) == invert(false), ""); // expected-error {{failed}} \
 // expected-note {{evaluates to 'false == true'}}
 
+  /// Bools are printed with conjunction.
+  static_assert(true && false, ""); // expected-error {{failed}} \
+
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}
 
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -16728,6 +16728,10 @@
 if (!UsefulToPrintExpr(LHS) && !UsefulToPrintExpr(RHS))
   return;
 
+// Ignore BO_LOr operators at the toplevel.
+if (Op->getOpcode() == BO_LOr)
+  return;
+
 struct {
   const clang::Expr *Cond;
   Expr::EvalResult Result;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146867: [Diagnostic] printing name of uninitialized subobject instead of its type

2023-03-25 Thread suman meena via Phabricator via cfe-commits
simideveloper added a comment.

I am an outreachy applicant and working on this issue for the past some weeks 
for my contribution on the community page till that time this issue was listed 
on the introductory issues list on the outreachy page I thought this issue is 
still open but was not aware of someone working sorry it's my bad if it's 
already solved.




Comment at: clang/include/clang/Basic/DiagnosticASTKinds.td:9
 
-//understanding syntax of diagnostics messages===//
-//keyword after def represents symbolic constant for that diagnostics 

junaire wrote:
> Why delete these? Looks like unrelated changes.
I submitted another review for documentation on diagnostic in which I added 
these comments but it was not relevant so I removed it 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146867

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


[PATCH] D145617: [clang-tidy] Add readability-avoid-unconditional-preprocessor-if check

2023-03-25 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

@carlosgalvezp Do you want me to shorten documentation ? Or we leave it like it 
is ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145617

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


[PATCH] D146867: [Diagnostic] printing name of uninitialized subobject instead of its type

2023-03-25 Thread Jun Zhang via Phabricator via cfe-commits
junaire added a comment.

BTW, does this patch overlaps with https://reviews.llvm.org/D146358?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146867

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


[PATCH] D146867: [Diagnostic] printing name of uninitialized subobject instead of its type

2023-03-25 Thread Jun Zhang via Phabricator via cfe-commits
junaire added reviewers: aaron.ballman, tbaeder, shafik.
junaire added a comment.

I don't have enough context on this patch, but obviously, there's something you 
can improve.

1. You need to add a test, maybe somewhere in `clang/test/Sema/`
2. Please make a detailed summary of your patch so reviewers know what's going 
on here. You can also link the GitHub issue.




Comment at: clang/include/clang/Basic/DiagnosticASTKinds.td:9
 
-//understanding syntax of diagnostics messages===//
-//keyword after def represents symbolic constant for that diagnostics 

Why delete these? Looks like unrelated changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146867

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


[PATCH] D143971: [clang-tidy] Flag more buggy string constructor cases

2023-03-25 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/string-constructor.rst:25
+  std::string str(buf[1], 5); // First arg should be '[1]'?
+  std::string str2((int)buf[1], 5); // Ok - explicitly cast to express intent
 

Should we use C++ casts?



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/string-constructor.rst:25
+  std::string str(buf[1], 5); // First arg should be '[1]'?
+  std::string str2((int)buf[1], 5); // Ok - explicitly cast to express intent
 

carlosgalvezp wrote:
> Should we use C++ casts?
Should this be a char?



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/string-constructor.cpp:141
+  std::string s4((int)kText[1], i);
+  std::string s5(kText[1], (char)i);
 

Shouldn't this fail, since the constructor `std::string(char, char)` does not 
exist?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143971

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


[PATCH] D146520: [clang-tidy] Fix checks filter with warnings-as-errors

2023-03-25 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

Reading through Github I found the associated ticket (it would be good if you 
could mention it in the commit message):
https://github.com/llvm/llvm-project/issues/61520

So if I understand correctly, what you are trying to do is continue to let the 
clang-analyzer-core checks run, and simply ignore the warnings coming from them 
when enabling `warnings_as_errors`. I'm not entirely convinced that's the best 
approach, it's hiding the real problem - that as a user one cannot disable 
clang-analyzer-core checks (which is being fixed in another patch by PiotrZSL). 
I also find strange to move error-handling logic away from the 
DiagnosticConsumer class out to the main ClangTidy class.

Would be good if @njames93  or @aaron.ballman  could comment on this, given 
their experience.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146520

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


[PATCH] D146844: [clang-format] Handle '_' in ud-suffix for IntegerLiteralSeparator

2023-03-25 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 508293.
owenpan added a comment.

Don't format imaginary numbers.


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

https://reviews.llvm.org/D146844

Files:
  clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
  clang/unittests/Format/IntegerLiteralSeparatorTest.cpp


Index: clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
===
--- clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
+++ clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
@@ -51,6 +51,18 @@
"o1 = 07;\n"
"o5 = 012345",
Style);
+
+  verifyFormat("bi = 0b1i;\n"
+   "dif = 1234if;\n"
+   "hil = 0xABCil",
+   Style);
+
+  const StringRef UDL("u = 0xDEAD'BEEF'DE'AD'BEE'F_u64;");
+  verifyFormat("u = 0xDE'AD'BE'EF'DE'AD'BE'EF_u64;", UDL, Style);
+  Style.IntegerLiteralSeparator.Hex = -1;
+  verifyFormat("u = 0xDEADBEEFDEADBEEF_u64;", UDL, Style);
+  Style.IntegerLiteralSeparator.Hex = 0;
+  verifyFormat(UDL, Style);
 }
 
 TEST_F(IntegerLiteralSeparatorTest, UnderscoreAsSeparator) {
Index: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
===
--- clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -44,10 +44,13 @@
 std::pair
 IntegerLiteralSeparatorFixer::process(const Environment ,
   const FormatStyle ) {
+  std::string Suffix("uUlLzZn");
+
   switch (Style.Language) {
   case FormatStyle::LK_Cpp:
   case FormatStyle::LK_ObjC:
 Separator = '\'';
+Suffix.push_back('_');
 break;
   case FormatStyle::LK_CSharp:
   case FormatStyle::LK_Java:
@@ -107,7 +110,8 @@
   continue;
 }
 if ((IsBase10 && Text.find_last_of(".eEfFdDmM") != StringRef::npos) ||
-(IsBase16 && Text.find_last_of(".pP") != StringRef::npos)) {
+(IsBase16 && Text.find_last_of(".pP") != StringRef::npos) ||
+Text.find_last_of('i') != StringRef::npos) {
   continue;
 }
 if (((IsBase2 && Binary < 0) || (IsBase10 && Decimal < 0) ||
@@ -116,7 +120,7 @@
   continue;
 }
 const auto Start = Text[0] == '0' ? 2 : 0;
-auto End = Text.find_first_of("uUlLzZn");
+auto End = Text.find_first_of(Suffix, Start);
 if (End == StringRef::npos)
   End = Length;
 if (Start > 0 || End < Length) {


Index: clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
===
--- clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
+++ clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
@@ -51,6 +51,18 @@
"o1 = 07;\n"
"o5 = 012345",
Style);
+
+  verifyFormat("bi = 0b1i;\n"
+   "dif = 1234if;\n"
+   "hil = 0xABCil",
+   Style);
+
+  const StringRef UDL("u = 0xDEAD'BEEF'DE'AD'BEE'F_u64;");
+  verifyFormat("u = 0xDE'AD'BE'EF'DE'AD'BE'EF_u64;", UDL, Style);
+  Style.IntegerLiteralSeparator.Hex = -1;
+  verifyFormat("u = 0xDEADBEEFDEADBEEF_u64;", UDL, Style);
+  Style.IntegerLiteralSeparator.Hex = 0;
+  verifyFormat(UDL, Style);
 }
 
 TEST_F(IntegerLiteralSeparatorTest, UnderscoreAsSeparator) {
Index: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
===
--- clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -44,10 +44,13 @@
 std::pair
 IntegerLiteralSeparatorFixer::process(const Environment ,
   const FormatStyle ) {
+  std::string Suffix("uUlLzZn");
+
   switch (Style.Language) {
   case FormatStyle::LK_Cpp:
   case FormatStyle::LK_ObjC:
 Separator = '\'';
+Suffix.push_back('_');
 break;
   case FormatStyle::LK_CSharp:
   case FormatStyle::LK_Java:
@@ -107,7 +110,8 @@
   continue;
 }
 if ((IsBase10 && Text.find_last_of(".eEfFdDmM") != StringRef::npos) ||
-(IsBase16 && Text.find_last_of(".pP") != StringRef::npos)) {
+(IsBase16 && Text.find_last_of(".pP") != StringRef::npos) ||
+Text.find_last_of('i') != StringRef::npos) {
   continue;
 }
 if (((IsBase2 && Binary < 0) || (IsBase10 && Decimal < 0) ||
@@ -116,7 +120,7 @@
   continue;
 }
 const auto Start = Text[0] == '0' ? 2 : 0;
-auto End = Text.find_first_of("uUlLzZn");
+auto End = Text.find_first_of(Suffix, Start);
 if (End == StringRef::npos)
   End = Length;
 if (Start > 0 || End < Length) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146520: [clang-tidy] Fix checks filter with warnings-as-errors

2023-03-25 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

Also, regarding clang-analyzer-core checks, I have 2 tickets open:

https://github.com/llvm/llvm-project/issues/59588
https://github.com/llvm/llvm-project/issues/59589


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146520

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


[PATCH] D146520: [clang-tidy] Fix checks filter with warnings-as-errors

2023-03-25 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

I'm not sure I follow - if you enable warnings as error for all checks, then 
the expectation is that you indeed get an error if you violate one of the 
clang-analyzer checks. In what way is this not wanted?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146520

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


[PATCH] D145617: [clang-tidy] Add readability-avoid-unconditional-preprocessor-if check

2023-03-25 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp requested changes to this revision.
carlosgalvezp added a comment.
This revision now requires changes to proceed.

I noticed the pre-merge checks are red, however, would be good to get them 
fixed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145617

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


[PATCH] D145617: [clang-tidy] Add readability-avoid-unconditional-preprocessor-if check

2023-03-25 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp accepted this revision.
carlosgalvezp added a comment.
This revision is now accepted and ready to land.

LGTM thank you! Really useful check! I'm not very expert in the PP callbacks so 
I can't give much feedback, feel free to wait for other more expert reviewers 
if you want.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145617

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


[PATCH] D144522: [clang-tidy] Add readability-operators-representation check

2023-03-25 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

Looks really good, thank you! I have only very minor comments, mostly style 
nits and suggestions for improved readability.




Comment at: 
clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.cpp:25
+
+StringRef getOperatorSpelling(SourceLocation Loc, ASTContext ) {
+  if (Loc.isInvalid())

As per LLVM guidelines this should be static, outside the anonymous namespace.



Comment at: 
clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.cpp:176
+
+  if (isAnyOperatorEnabled(BinaryOperators, OperatorsRepresentation)) {
+Finder->addMatcher(

Nit: would be good to add a one-line comment before each of the code blocks to 
describe at high-level what they do, to get a better birds-eye view of the code 
structure in this large function. At first sight it took me a while to spot the 
difference and understand why it's not exactly duplicated code.

Alternatively creating a function for each of the 3 addMatcher lines could be 
self-documenting and make the "registerMatches" smaller.



Comment at: 
clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.cpp:202
+getRepresentation(BinaryOperators, "^=", "xor_eq"
+.bind("bo"),
+this);

Nit: could get a bit more descriptive name, like "binary_op"



Comment at: 
clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.cpp:220
+  if (!isAnyOperatorEnabled(OverloadedOperators, OperatorsRepresentation) &&
+  isAnyOperatorEnabled(OverloadedOperators, UnaryRepresentation))
+return;

Is this condition intended to be negated too? Also, would it make sense to move 
this early return to the beginning of the function?



Comment at: 
clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.cpp:227
+  anyOf(
+  hasInvalidRepresentationO(
+  OO_AmpAmp,

Nit: would be good to spell this out for better readability.



Comment at: 
clang-tools-extra/clang-tidy/readability/OperatorsRepresentationCheck.h:13
+#include "../ClangTidyCheck.h"
+#include "llvm/ADT/SmallVector.h"
+#include 

 I believe this include is not in use in this header?



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/readability/operators-representation.rst:159
+Configuration can be mixed, for example: `and;||;not`.
+The default value is `and;or;not`.
+

PiotrZSL wrote:
> carlosgalvezp wrote:
> > It's unclear what the default value is for the other operators. From the 
> > code I see that ATR is the default - in that case I think the documentation 
> > should either a) provide the full list of defaults here, or b) simply 
> > mention "ATR style is the default". As a user I would prefer the former, so 
> > I know what keywords I am allowed to type in here, without having to go and 
> > consult cppreference.
> > 
> > Actually, now that I think about it, wouldn't it be better to implement 
> > this as an enum, similar to the readability-identifier-naming checks? Is 
> > there a use case for having `and;||;not`, i.e. a mix of style within the 
> > same category (e.g. BinaryOperators)?
> > 
> > In that case, it could look something like:
> > 
> > ```
> > readability-operators-representation.BinaryOperatorsStyle = Traditional
> > readability-operators-representation.BinaryOperatorsStyle = Alternative
> > ```
> > 
> > This would be easier to use from a user perspective, and IMHO would lead to 
> > a more consistent codebase, where one style or the other is chosen for all 
> > operators in each category.
> I choose this style just because with single option you can define whatever 
> you like.
> You can easily be less or more strict, enforce for example alternative tokens 
> for some, and enforce traditional for other.
> 
> Entire section "Alternative Token Representation" is here so you wouldn't 
> need to go to cppreference, there is an mapping.
> 
> And note that default config don't enforce alternative tokens for all, just 
> for 3 most common.
> Not everyone know about alternative token existence. And cppreference don't 
> describe why they exist. This is why this description with examples were 
> added, about pros and some cons. Not only engineers read checks 
> documentations , quality/product managers do that also.
> And most of checks descriptions basically don't provide any information that 
> would answer a question: "Why I should enable this check, what I will gain".
> 
> I agree, that some additional paragraph about example configurations (less, 
> more strict) and maybe some clarification about options could be added. And 
> some clarification why options are split into two with example, I will think 
> about this.
> 
> As for "Alternative Token Representation" if you wan't I 

[PATCH] D146867: [Diagnostic] printing name of uninitialized subobject instead of its type

2023-03-25 Thread suman meena via Phabricator via cfe-commits
simideveloper created this revision.
Herald added a project: All.
simideveloper requested review of this revision.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146867

Files:
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/Interp/Interp.cpp

Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -369,9 +369,9 @@
 }
 
 static void DiagnoseUninitializedSubobject(InterpState , const SourceInfo ,
-   QualType SubObjType,
+   StringRef SubObjName,
SourceLocation SubObjLoc) {
-  S.FFDiag(SI, diag::note_constexpr_uninitialized) << true << SubObjType;
+  S.FFDiag(SI, diag::note_constexpr_uninitialized) << true << SubObjName;
   if (SubObjLoc.isValid())
 S.Note(SubObjLoc, diag::note_constexpr_subobject_declared_here);
 }
@@ -400,7 +400,7 @@
   } else {
 for (size_t I = 0; I != NumElems; ++I) {
   if (!BasePtr.atIndex(I).isInitialized()) {
-DiagnoseUninitializedSubobject(S, S.Current->getSource(OpPC), ElemType,
+DiagnoseUninitializedSubobject(S, S.Current->getSource(OpPC), BasePtr.getElemRecord()->getName(),
BasePtr.getFieldDesc()->getLocation());
 Result = false;
   }
@@ -427,7 +427,7 @@
   Result &= CheckArrayInitialized(S, OpPC, FieldPtr, CAT);
 } else if (!FieldPtr.isInitialized()) {
   DiagnoseUninitializedSubobject(S, S.Current->getSource(OpPC),
- F.Decl->getType(), F.Decl->getLocation());
+ F.Decl->getName(), F.Decl->getLocation());
   Result = false;
 }
   }
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -2119,7 +2119,7 @@
   EvalInfo , SourceLocation DiagLoc,
   QualType Type, const APValue ,
   ConstantExprKind Kind,
-  SourceLocation SubobjectLoc,
+  const FieldDecl* SubobjectDecl,
   CheckedTemporaries );
 
 /// Check that this reference or pointer core constant expression is a valid
@@ -2267,7 +2267,7 @@
   assert(V && "evasluation result refers to uninitialised temporary");
   if (!CheckEvaluationResult(CheckEvaluationResultKind::ConstantExpression,
  Info, MTE->getExprLoc(), TempType, *V,
- Kind, SourceLocation(), CheckedTemps))
+ Kind,  /*SubobjectDecl=*/nullptr, CheckedTemps))
 return false;
 }
   }
@@ -2350,13 +2350,13 @@
   EvalInfo , SourceLocation DiagLoc,
   QualType Type, const APValue ,
   ConstantExprKind Kind,
-  SourceLocation SubobjectLoc,
+  const FieldDecl* SubobjectDecl,
   CheckedTemporaries ) {
-  if (!Value.hasValue()) {
+  if ((!Value.hasValue())&& SubobjectDecl!=nullptr) {
 Info.FFDiag(DiagLoc, diag::note_constexpr_uninitialized)
-  << true << Type;
-if (SubobjectLoc.isValid())
-  Info.Note(SubobjectLoc, diag::note_constexpr_subobject_declared_here);
+  << true << SubobjectDecl->getName();
+if (SubobjectDecl->getLocation().isValid())
+  Info.Note(SubobjectDecl->getLocation(), diag::note_constexpr_subobject_declared_here);
 return false;
   }
 
@@ -2372,20 +2372,20 @@
 QualType EltTy = Type->castAsArrayTypeUnsafe()->getElementType();
 for (unsigned I = 0, N = Value.getArrayInitializedElts(); I != N; ++I) {
   if (!CheckEvaluationResult(CERK, Info, DiagLoc, EltTy,
- Value.getArrayInitializedElt(I), Kind,
- SubobjectLoc, CheckedTemps))
+ Value.getArrayInitializedElt(I), Kind,SubobjectDecl
+ , CheckedTemps))
 return false;
 }
 if (!Value.hasArrayFiller())
   return true;
 return CheckEvaluationResult(CERK, Info, DiagLoc, EltTy,
- Value.getArrayFiller(), Kind, SubobjectLoc,
+ Value.getArrayFiller(), Kind, SubobjectDecl,
  CheckedTemps);
   }
   if (Value.isUnion() && Value.getUnionField()) {
 return CheckEvaluationResult(
 CERK, Info, DiagLoc, Value.getUnionField()->getType(),
-Value.getUnionValue(), Kind, Value.getUnionField()->getLocation(),

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

2023-03-25 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav created this revision.
chaitanyav added a reviewer: dang.
Herald added a reviewer: ributzka.
Herald added a project: All.
chaitanyav requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146866

Files:
  clang/lib/ExtractAPI/DeclarationFragments.cpp
  clang/test/ExtractAPI/objc_id_protocol.m

Index: clang/test/ExtractAPI/objc_id_protocol.m
===
--- /dev/null
+++ 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"
+  }
+],
+"subHeading": [
+  {
+"kind": "identifier",
+"spelling": "MyInterface"
+  }
+],
+"title": "MyInterface"
+  },
+  "pathComponents": [
+"MyInterface"
+  ]
+},
+{
+  "accessLevel": "public",
+  "declarationFragments": [
+{
+  "kind": "keyword",
+  "spelling": "@property"
+},
+{
+  "kind": "text",
+  "spelling": " ("
+},
+{
+  "kind": "keyword",
+  "spelling": "atomic"
+},
+{
+  "kind": "text",
+  "spelling": ", "
+},
+{
+  "kind": "keyword",
+  "spelling": "copy"
+},
+{
+  "kind": "text",
+  "spelling": ", "
+},
+{
+  "kind": "keyword",
+  "spelling": "readwrite"
+},
+{
+  "kind": "text",
+  "spelling": ") "
+},
+{
+  "kind": "typeIdentifier",
+  "preciseIdentifier": "c:Qoobjc(pl)MyProtocol",
+  "spelling": "id"
+},
+{
+  "kind": "text",
+  "spelling": " "
+},
+{
+  "kind": "identifier",
+  "spelling": "obj1"
+}
+  ],
+  "identifier": {
+"interfaceLanguage": "objective-c",
+"precise": "c:objc(cs)MyInterface(py)obj1"
+  },
+  "kind": {
+"displayName": "Instance Property",
+"identifier": "objective-c.property"
+  },
+  "location": {
+"position": {
+  "character": 43,
+  "line": 5
+},
+"uri": "file://INPUT_DIR/input.h"
+  },
+  "names": {
+"navigator": [
+  {
+"kind": "identifier",
+"spelling": "obj1"
+