[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-11-13 Thread via cfe-commits

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


[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-11-13 Thread via cfe-commits


@@ -697,6 +697,8 @@ Miscellaneous Clang Crashes Fixed
   `Issue 64564 `_
 - Fixed a crash when an ObjC ivar has an invalid type. See
   (`#68001 `_)
+- Fixed a crash when ``-ast-dump=json`` was used for code using template
+  deduction guides.

elizabethandrews wrote:

Done!

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


[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-11-13 Thread via cfe-commits

https://github.com/elizabethandrews updated 
https://github.com/llvm/llvm-project/pull/70224

>From 4ea6d62dab962eba6e52a9fdf7e61b6aac0714fa Mon Sep 17 00:00:00 2001
From: Elizabeth Andrews 
Date: Mon, 30 Oct 2023 13:07:48 -0700
Subject: [PATCH] [Clang] Fix a crash when using ast-dump=json

CXXDeductionGuideDecl inherits from FunctionDecl. For FunctionDecls,
the JSONVisitor includes a call to visit NamedDecl in order to
provide mangled names in the dump. This did not correctly exclude
CXXDeductionGuideDecl, which resulted in an assert being hit.
---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/lib/AST/JSONNodeDumper.cpp  |   4 +
 .../test/AST/ast-dump-template-decls-json.cpp | 425 ++
 3 files changed, 431 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 66f82de69099533c..ed1a978b5382d719 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -726,6 +726,8 @@ Miscellaneous Clang Crashes Fixed
   (`#68001 `_)
 - Fixed a crash in C when redefined struct is another nested redefinition.
   `Issue 41302 `_
+- Fixed a crash when ``-ast-dump=json`` was used for code using class
+  template deduction guides.
 
 Target Specific Changes
 ---
diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp
index ace5178bf6258289..637d06cee78c8525 100644
--- a/clang/lib/AST/JSONNodeDumper.cpp
+++ b/clang/lib/AST/JSONNodeDumper.cpp
@@ -823,6 +823,10 @@ void JSONNodeDumper::VisitNamedDecl(const NamedDecl *ND) {
 if (VD && VD->hasLocalStorage())
   return;
 
+// Do not mangle template deduction guides.
+if (isa(ND))
+  return;
+
 std::string MangledName = ASTNameGen.getName(ND);
 if (!MangledName.empty())
   JOS.attribute("mangledName", MangledName);
diff --git a/clang/test/AST/ast-dump-template-decls-json.cpp 
b/clang/test/AST/ast-dump-template-decls-json.cpp
index 00a656cd059178dd..70f1d3b55f3ee988 100644
--- a/clang/test/AST/ast-dump-template-decls-json.cpp
+++ b/clang/test/AST/ast-dump-template-decls-json.cpp
@@ -58,6 +58,10 @@ void V::f() {}
 template  class = R>
 void i();
 
+template  class W{
+};
+W(int)->W<1>;
+
 // NOTE: CHECK lines have been autogenerated by gen_ast_dump_json_test.py
 
 
@@ -2702,6 +2706,427 @@ void i();
 // CHECK-NEXT:  }
 // CHECK-NEXT: }
 // CHECK-NEXT:]
+// CHECK-NEXT:   },
+// CHECK-NEXT:   {
+// CHECK-NEXT:"id": "0x{{.*}}",
+// CHECK-NEXT:"kind": "ClassTemplateDecl",
+// CHECK-NEXT:"loc": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "line": 61,
+// CHECK-NEXT: "col": 24,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT:},
+// CHECK-NEXT:"range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT:  "offset": {{[0-9]+}},
+// CHECK-NEXT:  "col": 1,
+// CHECK-NEXT:  "tokLen": 8
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT:  "offset": {{[0-9]+}},
+// CHECK-NEXT:  "line": 62,
+// CHECK-NEXT:  "col": 1,
+// CHECK-NEXT:  "tokLen": 1
+// CHECK-NEXT: }
+// CHECK-NEXT:},
+// CHECK-NEXT:"name": "W",
+// CHECK-NEXT:"inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT:  "id": "0x{{.*}}",
+// CHECK-NEXT:  "kind": "NonTypeTemplateParmDecl",
+// CHECK-NEXT:  "loc": {
+// CHECK-NEXT:   "offset": {{[0-9]+}},
+// CHECK-NEXT:   "line": 61,
+// CHECK-NEXT:   "col": 15,
+// CHECK-NEXT:   "tokLen": 1
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "range": {
+// CHECK-NEXT:   "begin": {
+// CHECK-NEXT:"offset": {{[0-9]+}},
+// CHECK-NEXT:"col": 11,
+// CHECK-NEXT:"tokLen": 3
+// CHECK-NEXT:   },
+// CHECK-NEXT:   "end": {
+// CHECK-NEXT:"offset": {{[0-9]+}},
+// CHECK-NEXT:"col": 15,
+// CHECK-NEXT:"tokLen": 1
+// CHECK-NEXT:   }
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "name": "A",
+// CHECK-NEXT:  "type": {
+// CHECK-NEXT:   "qualType": "int"
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "depth": 0,
+// CHECK-NEXT:  "index": 0
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT:  "id": "0x{{.*}}",
+// CHECK-NEXT:  "kind": "CXXRecordDecl",
+// CHECK-NEXT:  "loc": {
+// CHECK-NEXT:   "offset": {{[0-9]+}},
+// CHECK-NEXT:   "col": 24,
+// CHECK-NEXT:   "tokLen": 1
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "range": {
+// CHECK-NEXT:   "begin": {
+// CHECK-NEXT:"offset": {{[0-9]+}},
+// CHECK-NEXT:"col": 18,
+// CHECK-NEXT:"tokLen": 5
+// CHECK-NEXT:   },
+// CHECK-NEXT:   "end": {
+// CHECK-NEXT:"offset": {{[0-9]+}},
+// CHECK-NEXT:"line": 62,
+// CHECK-NEXT:"col": 1,
+// CHECK-NEXT:"tokLen": 1
+// CHECK-NEXT:   }
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "name": "W",
+// CHECK-NEXT:  "tagUsed": "class",
+// 

[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-11-08 Thread Tom Honermann via cfe-commits


@@ -697,6 +697,8 @@ Miscellaneous Clang Crashes Fixed
   `Issue 64564 `_
 - Fixed a crash when an ObjC ivar has an invalid type. See
   (`#68001 `_)
+- Fixed a crash when ``-ast-dump=json`` was used for code using template
+  deduction guides.

tahonermann wrote:

```suggestion
- Fixed a crash when ``-ast-dump=json`` was used for code using class
  template deduction guides.
```

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


[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-11-08 Thread Tom Honermann via cfe-commits

https://github.com/tahonermann approved this pull request.

I added a minor suggested change for the release note, but this otherwise looks 
good to me.

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


[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-11-08 Thread Tom Honermann via cfe-commits

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


[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-11-06 Thread via cfe-commits

elizabethandrews wrote:

@tahonermann @AaronBallman does that sound ok to you ? Can I merge this (after 
a rebase)?

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


[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-11-01 Thread Chris B via cfe-commits

llvm-beanz wrote:

@elizabethandrews ignore the clang-format failure. The action isn't fetching 
enough commits from git in some cases which leads to this failure.

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


[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-10-30 Thread via cfe-commits

elizabethandrews wrote:

I've applied all the review comments. I'm not sure what to do about the failing 
code format bot though. Should I open a new PR or  can I ignore that bot since 
I've run clang-format locally?

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


[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-10-30 Thread via cfe-commits

elizabethandrews wrote:

I apologize for the force push. I had a strange Git error I was trying to get 
rid of.  I also squashed my commits for the same reason. It doesn't look like 
it has helped though. I see the first test bot checking formatting fails with

```
Run python llvm/utils/git/code-format-helper.py \
Running: git-clang-format --diff 
aa30018e66105b4a8bd0947e35d1946d[24](https://github.com/llvm/llvm-project/actions/runs/6698182261/job/18199674028?pr=70224#step:8:25)2cd99c
 f4559a402d92fd6ab394b586b1c5f3f6d740c3a8 -- clang/lib/AST/JSONNodeDumper.cpp 
clang/test/AST/ast-dump-template-decls-json.cpp
error: 'aa30018e66105b4a8bd0947e35d1946d242cd99c' is not a commit
error: clang-format exited with code 2
error: some formatters failed: clang-format
Error: Process completed with exit code 1.
```

I have no idea why this is happening.

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


[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-10-30 Thread via cfe-commits

https://github.com/elizabethandrews updated 
https://github.com/llvm/llvm-project/pull/70224

>From f4559a402d92fd6ab394b586b1c5f3f6d740c3a8 Mon Sep 17 00:00:00 2001
From: Elizabeth Andrews 
Date: Mon, 30 Oct 2023 13:07:48 -0700
Subject: [PATCH] [Clang] Fix a crash when using ast-dump=json

CXXDeductionGuideDecl inherits from FunctionDecl. For FunctionDecls,
the JSONVisitor includes a call to visit NamedDecl in order to
provide mangled names in the dump. This did not correctly exclude
CXXDeductionGuideDecl, which resulted in an assert being hit.
---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/lib/AST/JSONNodeDumper.cpp  |   4 +
 .../test/AST/ast-dump-template-decls-json.cpp | 425 ++
 3 files changed, 431 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bc28bb567f6932a..ad68a6406eb03f1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -697,6 +697,8 @@ Miscellaneous Clang Crashes Fixed
   `Issue 64564 `_
 - Fixed a crash when an ObjC ivar has an invalid type. See
   (`#68001 `_)
+- Fixed a crash when ``-ast-dump=json`` was used for code using template
+  deduction guides.
 
 Target Specific Changes
 ---
diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp
index 25b94ec5616b19c..438d87b6813c518 100644
--- a/clang/lib/AST/JSONNodeDumper.cpp
+++ b/clang/lib/AST/JSONNodeDumper.cpp
@@ -823,6 +823,10 @@ void JSONNodeDumper::VisitNamedDecl(const NamedDecl *ND) {
 if (VD && VD->hasLocalStorage())
   return;
 
+// Do not mangle template deduction guides.
+if (isa(ND))
+  return;
+
 std::string MangledName = ASTNameGen.getName(ND);
 if (!MangledName.empty())
   JOS.attribute("mangledName", MangledName);
diff --git a/clang/test/AST/ast-dump-template-decls-json.cpp 
b/clang/test/AST/ast-dump-template-decls-json.cpp
index 00a656cd059178d..70f1d3b55f3ee98 100644
--- a/clang/test/AST/ast-dump-template-decls-json.cpp
+++ b/clang/test/AST/ast-dump-template-decls-json.cpp
@@ -58,6 +58,10 @@ void V::f() {}
 template  class = R>
 void i();
 
+template  class W{
+};
+W(int)->W<1>;
+
 // NOTE: CHECK lines have been autogenerated by gen_ast_dump_json_test.py
 
 
@@ -2702,6 +2706,427 @@ void i();
 // CHECK-NEXT:  }
 // CHECK-NEXT: }
 // CHECK-NEXT:]
+// CHECK-NEXT:   },
+// CHECK-NEXT:   {
+// CHECK-NEXT:"id": "0x{{.*}}",
+// CHECK-NEXT:"kind": "ClassTemplateDecl",
+// CHECK-NEXT:"loc": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "line": 61,
+// CHECK-NEXT: "col": 24,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT:},
+// CHECK-NEXT:"range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT:  "offset": {{[0-9]+}},
+// CHECK-NEXT:  "col": 1,
+// CHECK-NEXT:  "tokLen": 8
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT:  "offset": {{[0-9]+}},
+// CHECK-NEXT:  "line": 62,
+// CHECK-NEXT:  "col": 1,
+// CHECK-NEXT:  "tokLen": 1
+// CHECK-NEXT: }
+// CHECK-NEXT:},
+// CHECK-NEXT:"name": "W",
+// CHECK-NEXT:"inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT:  "id": "0x{{.*}}",
+// CHECK-NEXT:  "kind": "NonTypeTemplateParmDecl",
+// CHECK-NEXT:  "loc": {
+// CHECK-NEXT:   "offset": {{[0-9]+}},
+// CHECK-NEXT:   "line": 61,
+// CHECK-NEXT:   "col": 15,
+// CHECK-NEXT:   "tokLen": 1
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "range": {
+// CHECK-NEXT:   "begin": {
+// CHECK-NEXT:"offset": {{[0-9]+}},
+// CHECK-NEXT:"col": 11,
+// CHECK-NEXT:"tokLen": 3
+// CHECK-NEXT:   },
+// CHECK-NEXT:   "end": {
+// CHECK-NEXT:"offset": {{[0-9]+}},
+// CHECK-NEXT:"col": 15,
+// CHECK-NEXT:"tokLen": 1
+// CHECK-NEXT:   }
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "name": "A",
+// CHECK-NEXT:  "type": {
+// CHECK-NEXT:   "qualType": "int"
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "depth": 0,
+// CHECK-NEXT:  "index": 0
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT:  "id": "0x{{.*}}",
+// CHECK-NEXT:  "kind": "CXXRecordDecl",
+// CHECK-NEXT:  "loc": {
+// CHECK-NEXT:   "offset": {{[0-9]+}},
+// CHECK-NEXT:   "col": 24,
+// CHECK-NEXT:   "tokLen": 1
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "range": {
+// CHECK-NEXT:   "begin": {
+// CHECK-NEXT:"offset": {{[0-9]+}},
+// CHECK-NEXT:"col": 18,
+// CHECK-NEXT:"tokLen": 5
+// CHECK-NEXT:   },
+// CHECK-NEXT:   "end": {
+// CHECK-NEXT:"offset": {{[0-9]+}},
+// CHECK-NEXT:"line": 62,
+// CHECK-NEXT:"col": 1,
+// CHECK-NEXT:"tokLen": 1
+// CHECK-NEXT:   }
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "name": "W",
+// CHECK-NEXT:  "tagUsed": "class",
+// CHECK-NEXT:  

[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-10-30 Thread via cfe-commits

https://github.com/agozillon updated 
https://github.com/llvm/llvm-project/pull/70224

>From f4559a402d92fd6ab394b586b1c5f3f6d740c3a8 Mon Sep 17 00:00:00 2001
From: Elizabeth Andrews 
Date: Mon, 30 Oct 2023 13:07:48 -0700
Subject: [PATCH] [Clang] Fix a crash when using ast-dump=json

CXXDeductionGuideDecl inherits from FunctionDecl. For FunctionDecls,
the JSONVisitor includes a call to visit NamedDecl in order to
provide mangled names in the dump. This did not correctly exclude
CXXDeductionGuideDecl, which resulted in an assert being hit.
---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/lib/AST/JSONNodeDumper.cpp  |   4 +
 .../test/AST/ast-dump-template-decls-json.cpp | 425 ++
 3 files changed, 431 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index bc28bb567f6932a..ad68a6406eb03f1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -697,6 +697,8 @@ Miscellaneous Clang Crashes Fixed
   `Issue 64564 `_
 - Fixed a crash when an ObjC ivar has an invalid type. See
   (`#68001 `_)
+- Fixed a crash when ``-ast-dump=json`` was used for code using template
+  deduction guides.
 
 Target Specific Changes
 ---
diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp
index 25b94ec5616b19c..438d87b6813c518 100644
--- a/clang/lib/AST/JSONNodeDumper.cpp
+++ b/clang/lib/AST/JSONNodeDumper.cpp
@@ -823,6 +823,10 @@ void JSONNodeDumper::VisitNamedDecl(const NamedDecl *ND) {
 if (VD && VD->hasLocalStorage())
   return;
 
+// Do not mangle template deduction guides.
+if (isa(ND))
+  return;
+
 std::string MangledName = ASTNameGen.getName(ND);
 if (!MangledName.empty())
   JOS.attribute("mangledName", MangledName);
diff --git a/clang/test/AST/ast-dump-template-decls-json.cpp 
b/clang/test/AST/ast-dump-template-decls-json.cpp
index 00a656cd059178d..70f1d3b55f3ee98 100644
--- a/clang/test/AST/ast-dump-template-decls-json.cpp
+++ b/clang/test/AST/ast-dump-template-decls-json.cpp
@@ -58,6 +58,10 @@ void V::f() {}
 template  class = R>
 void i();
 
+template  class W{
+};
+W(int)->W<1>;
+
 // NOTE: CHECK lines have been autogenerated by gen_ast_dump_json_test.py
 
 
@@ -2702,6 +2706,427 @@ void i();
 // CHECK-NEXT:  }
 // CHECK-NEXT: }
 // CHECK-NEXT:]
+// CHECK-NEXT:   },
+// CHECK-NEXT:   {
+// CHECK-NEXT:"id": "0x{{.*}}",
+// CHECK-NEXT:"kind": "ClassTemplateDecl",
+// CHECK-NEXT:"loc": {
+// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "line": 61,
+// CHECK-NEXT: "col": 24,
+// CHECK-NEXT: "tokLen": 1
+// CHECK-NEXT:},
+// CHECK-NEXT:"range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT:  "offset": {{[0-9]+}},
+// CHECK-NEXT:  "col": 1,
+// CHECK-NEXT:  "tokLen": 8
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT:  "offset": {{[0-9]+}},
+// CHECK-NEXT:  "line": 62,
+// CHECK-NEXT:  "col": 1,
+// CHECK-NEXT:  "tokLen": 1
+// CHECK-NEXT: }
+// CHECK-NEXT:},
+// CHECK-NEXT:"name": "W",
+// CHECK-NEXT:"inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT:  "id": "0x{{.*}}",
+// CHECK-NEXT:  "kind": "NonTypeTemplateParmDecl",
+// CHECK-NEXT:  "loc": {
+// CHECK-NEXT:   "offset": {{[0-9]+}},
+// CHECK-NEXT:   "line": 61,
+// CHECK-NEXT:   "col": 15,
+// CHECK-NEXT:   "tokLen": 1
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "range": {
+// CHECK-NEXT:   "begin": {
+// CHECK-NEXT:"offset": {{[0-9]+}},
+// CHECK-NEXT:"col": 11,
+// CHECK-NEXT:"tokLen": 3
+// CHECK-NEXT:   },
+// CHECK-NEXT:   "end": {
+// CHECK-NEXT:"offset": {{[0-9]+}},
+// CHECK-NEXT:"col": 15,
+// CHECK-NEXT:"tokLen": 1
+// CHECK-NEXT:   }
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "name": "A",
+// CHECK-NEXT:  "type": {
+// CHECK-NEXT:   "qualType": "int"
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "depth": 0,
+// CHECK-NEXT:  "index": 0
+// CHECK-NEXT: },
+// CHECK-NEXT: {
+// CHECK-NEXT:  "id": "0x{{.*}}",
+// CHECK-NEXT:  "kind": "CXXRecordDecl",
+// CHECK-NEXT:  "loc": {
+// CHECK-NEXT:   "offset": {{[0-9]+}},
+// CHECK-NEXT:   "col": 24,
+// CHECK-NEXT:   "tokLen": 1
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "range": {
+// CHECK-NEXT:   "begin": {
+// CHECK-NEXT:"offset": {{[0-9]+}},
+// CHECK-NEXT:"col": 18,
+// CHECK-NEXT:"tokLen": 5
+// CHECK-NEXT:   },
+// CHECK-NEXT:   "end": {
+// CHECK-NEXT:"offset": {{[0-9]+}},
+// CHECK-NEXT:"line": 62,
+// CHECK-NEXT:"col": 1,
+// CHECK-NEXT:"tokLen": 1
+// CHECK-NEXT:   }
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "name": "W",
+// CHECK-NEXT:  "tagUsed": "class",
+// CHECK-NEXT:  "completeDefinition": 

[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-10-27 Thread Tom Honermann via cfe-commits


@@ -217,21 +221,21 @@ void i();
 // CHECK-NEXT:"id": "0x{{.*}}",
 // CHECK-NEXT:"kind": "FunctionTemplateDecl",
 // CHECK-NEXT:"loc": {
-// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "offset": 142,

tahonermann wrote:

Reverting the undesired changes suffices for me. My Python experience is years 
out of date too :)

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


[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-10-26 Thread Chris B via cfe-commits


@@ -217,21 +221,21 @@ void i();
 // CHECK-NEXT:"id": "0x{{.*}}",
 // CHECK-NEXT:"kind": "FunctionTemplateDecl",
 // CHECK-NEXT:"loc": {
-// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "offset": 142,

llvm-beanz wrote:

To add a bit of context on the change to using regex matches. These tests are 
fragile to your system’s native line-endings. I changed these to regex matches 
in an effort to get clang’s tests to pass under a git checkout with autocrlf 
enabled.

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


[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-10-26 Thread Chris B via cfe-commits

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


[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-10-26 Thread Aaron Ballman via cfe-commits


@@ -819,6 +819,10 @@ void JSONNodeDumper::VisitNamedDecl(const NamedDecl *ND) {
 if (VD && VD->hasLocalStorage())
   return;
 
+// Do not mangle template deduction guides.
+if (const auto DG = dyn_cast(ND))

AaronBallman wrote:

```suggestion
if (isa(ND))
```

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


[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-10-26 Thread Aaron Ballman via cfe-commits


@@ -377,6 +377,8 @@ Miscellaneous Clang Crashes Fixed
   `Issue 64065 `_
 - Fixed a crash when check array access on zero-length element.
   `Issue 64564 `_
+- Fixed a crash when -ast-dump=json was used for code using template

AaronBallman wrote:

```suggestion
- Fixed a crash when ``-ast-dump=json`` was used for code using template
```

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


[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-10-26 Thread Aaron Ballman via cfe-commits


@@ -217,21 +221,21 @@ void i();
 // CHECK-NEXT:"id": "0x{{.*}}",
 // CHECK-NEXT:"kind": "FunctionTemplateDecl",
 // CHECK-NEXT:"loc": {
-// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "offset": 142,

AaronBallman wrote:

I think we just forgot to update that script to produce regexes here; I think 
it's fine to revert back to the regex and fix the script in a follow-up 
(doesn't have to be @elizabethandrews doing the follow-up either).

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


[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-10-26 Thread via cfe-commits


@@ -217,21 +221,21 @@ void i();
 // CHECK-NEXT:"id": "0x{{.*}}",
 // CHECK-NEXT:"kind": "FunctionTemplateDecl",
 // CHECK-NEXT:"loc": {
-// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "offset": 142,

elizabethandrews wrote:

It looks like all the script does is dump the output of `-ast-dump=json` 
without really checking the string. Theoretically I guess it would be possible 
to check for "offset" in this string and modifying what is generated, but I 
haven't worked with Python in years and so might not be the best person to do 
this update. I think this should also be done in a separate patch since it 
falls outside the scope of this patch. 

For now I can revert the offset changes the script made and just keep the new 
CHECK lines with offsets modified? Would you be ok with that? Tagging 
@llvm-beanz for any input as well.

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


[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-10-26 Thread Tom Honermann via cfe-commits


@@ -217,21 +221,21 @@ void i();
 // CHECK-NEXT:"id": "0x{{.*}}",
 // CHECK-NEXT:"kind": "FunctionTemplateDecl",
 // CHECK-NEXT:"loc": {
-// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "offset": 142,

tahonermann wrote:

Hmm, the regex changes were made in 
https://github.com/llvm/llvm-project/commit/6d8e5c968538eff2c024d46d5715de0828a69407
 by Chris Bieneman and reviewed by Aaron in https://reviews.llvm.org/D119362. 
It looks like those regex changes need to be preserved. It seems that script 
could use an update. Perhaps follow up with Chris?

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


[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-10-25 Thread via cfe-commits


@@ -217,21 +221,21 @@ void i();
 // CHECK-NEXT:"id": "0x{{.*}}",
 // CHECK-NEXT:"kind": "FunctionTemplateDecl",
 // CHECK-NEXT:"loc": {
-// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "offset": 142,

elizabethandrews wrote:

Yes I did. All changes in this file where made by the script.  

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


[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-10-25 Thread Tom Honermann via cfe-commits


@@ -217,21 +221,21 @@ void i();
 // CHECK-NEXT:"id": "0x{{.*}}",
 // CHECK-NEXT:"kind": "FunctionTemplateDecl",
 // CHECK-NEXT:"loc": {
-// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "offset": 142,

tahonermann wrote:

It looks like a regular expression was previously used to avoid sensitivity to 
the `offset` values. I'm not familiar with this test, but I see the comment 
above regarding using `gen_ast_dump_json_test.py` to generate the `CHECK` 
lines. Did you use that script?

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


[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-10-25 Thread via cfe-commits

https://github.com/elizabethandrews updated 
https://github.com/llvm/llvm-project/pull/70224

>From 21ecdfb97ff2e8152cec7b4fa3c2fd8913244889 Mon Sep 17 00:00:00 2001
From: Elizabeth Andrews 
Date: Wed, 25 Oct 2023 09:17:09 -0700
Subject: [PATCH 1/2] [Clang] Fix a crash when using ast-dump=json

CXXDeductionGuideDecl inherits from FunctionDecl. For FunctionDecls,
the JSONVisitor includes a call to visit NamedDecl in order to
provide mangled names in the dump. This did not correctly exclude
CXXDeductionGuideDecl, which resulted in an assert being hit.
---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/lib/AST/JSONNodeDumper.cpp  |   4 +
 .../test/AST/ast-dump-template-decls-json.cpp | 875 +-
 3 files changed, 656 insertions(+), 225 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 688454d6b562ec3..223f172883277df 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -377,6 +377,8 @@ Miscellaneous Clang Crashes Fixed
   `Issue 64065 `_
 - Fixed a crash when check array access on zero-length element.
   `Issue 64564 `_
+- Fixed a crash when -ast-dump=json was used for code using template
+  deduction guides.
 
 Target Specific Changes
 ---
diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp
index e67c2c7e216dcea..e2bb34c68cb7e92 100644
--- a/clang/lib/AST/JSONNodeDumper.cpp
+++ b/clang/lib/AST/JSONNodeDumper.cpp
@@ -819,6 +819,10 @@ void JSONNodeDumper::VisitNamedDecl(const NamedDecl *ND) {
 if (VD && VD->hasLocalStorage())
   return;
 
+// Do not mangle template deduction guides.
+if(const auto DG = dyn_cast(ND))
+  return;
+
 std::string MangledName = ASTNameGen.getName(ND);
 if (!MangledName.empty())
   JOS.attribute("mangledName", MangledName);
diff --git a/clang/test/AST/ast-dump-template-decls-json.cpp 
b/clang/test/AST/ast-dump-template-decls-json.cpp
index f51ef937d91dbd3..8a8262d3e665fc3 100644
--- a/clang/test/AST/ast-dump-template-decls-json.cpp
+++ b/clang/test/AST/ast-dump-template-decls-json.cpp
@@ -58,6 +58,10 @@ void V::f() {}
 template  class = R>
 void i();
 
+template  class W{
+};
+W(int)->W<1>;
+
 // NOTE: CHECK lines have been autogenerated by gen_ast_dump_json_test.py
 
 
@@ -217,7 +221,7 @@ void i();
 // CHECK-NEXT:"id": "0x{{.*}}",
 // CHECK-NEXT:"kind": "FunctionTemplateDecl",
 // CHECK-NEXT:"loc": {
-// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "offset": 142,
 // CHECK-NEXT: "file": "{{.*}}",
 // CHECK-NEXT: "line": 4,
 // CHECK-NEXT: "col": 6,
@@ -225,13 +229,13 @@ void i();
 // CHECK-NEXT:},
 // CHECK-NEXT:"range": {
 // CHECK-NEXT: "begin": {
-// CHECK-NEXT:  "offset": {{[0-9]+}},
+// CHECK-NEXT:  "offset": 114,
 // CHECK-NEXT:  "line": 3,
 // CHECK-NEXT:  "col": 1,
 // CHECK-NEXT:  "tokLen": 8
 // CHECK-NEXT: },
 // CHECK-NEXT: "end": {
-// CHECK-NEXT:  "offset": {{[0-9]+}},
+// CHECK-NEXT:  "offset": 146,
 // CHECK-NEXT:  "line": 4,
 // CHECK-NEXT:  "col": 10,
 // CHECK-NEXT:  "tokLen": 1
@@ -243,19 +247,19 @@ void i();
 // CHECK-NEXT:  "id": "0x{{.*}}",
 // CHECK-NEXT:  "kind": "TemplateTypeParmDecl",
 // CHECK-NEXT:  "loc": {
-// CHECK-NEXT:   "offset": {{[0-9]+}},
+// CHECK-NEXT:   "offset": 133,
 // CHECK-NEXT:   "line": 3,
 // CHECK-NEXT:   "col": 20,
 // CHECK-NEXT:   "tokLen": 2
 // CHECK-NEXT:  },
 // CHECK-NEXT:  "range": {
 // CHECK-NEXT:   "begin": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
+// CHECK-NEXT:"offset": 124,
 // CHECK-NEXT:"col": 11,
 // CHECK-NEXT:"tokLen": 8
 // CHECK-NEXT:   },
 // CHECK-NEXT:   "end": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
+// CHECK-NEXT:"offset": 133,
 // CHECK-NEXT:"col": 20,
 // CHECK-NEXT:"tokLen": 2
 // CHECK-NEXT:   }
@@ -270,19 +274,19 @@ void i();
 // CHECK-NEXT:  "id": "0x{{.*}}",
 // CHECK-NEXT:  "kind": "FunctionDecl",
 // CHECK-NEXT:  "loc": {
-// CHECK-NEXT:   "offset": {{[0-9]+}},
+// CHECK-NEXT:   "offset": 142,
 // CHECK-NEXT:   "line": 4,
 // CHECK-NEXT:   "col": 6,
 // CHECK-NEXT:   "tokLen": 1
 // CHECK-NEXT:  },
 // CHECK-NEXT:  "range": {
 // CHECK-NEXT:   "begin": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
+// CHECK-NEXT:"offset": 137,
 // CHECK-NEXT:"col": 1,
 // CHECK-NEXT:"tokLen": 4
 // CHECK-NEXT:   },
 // CHECK-NEXT:   "end": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
+// CHECK-NEXT:"offset": 146,
 // CHECK-NEXT:"col": 10,
 // CHECK-NEXT:"tokLen": 1
 // CHECK-NEXT:   }
@@ -296,18 +300,18 @@ void i();
 // CHECK-NEXT:"id": "0x{{.*}}",
 // CHECK-NEXT:"kind": "ParmVarDecl",
 // 

[clang] [Clang] Fix a crash when using ast-dump=json (PR #70224)

2023-10-25 Thread via cfe-commits

https://github.com/elizabethandrews created 
https://github.com/llvm/llvm-project/pull/70224

CXXDeductionGuideDecl inherits from FunctionDecl. For FunctionDecls, the 
JSONVisitor
includes a call to visit NamedDecl in order to provide mangled names in the 
dump. This did
not correctly exclude CXXDeductionGuideDecl, which resulted in an assert being 
hit.

>From 21ecdfb97ff2e8152cec7b4fa3c2fd8913244889 Mon Sep 17 00:00:00 2001
From: Elizabeth Andrews 
Date: Wed, 25 Oct 2023 09:17:09 -0700
Subject: [PATCH] [Clang] Fix a crash when using ast-dump=json

CXXDeductionGuideDecl inherits from FunctionDecl. For FunctionDecls,
the JSONVisitor includes a call to visit NamedDecl in order to
provide mangled names in the dump. This did not correctly exclude
CXXDeductionGuideDecl, which resulted in an assert being hit.
---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/lib/AST/JSONNodeDumper.cpp  |   4 +
 .../test/AST/ast-dump-template-decls-json.cpp | 875 +-
 3 files changed, 656 insertions(+), 225 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 688454d6b562ec3..223f172883277df 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -377,6 +377,8 @@ Miscellaneous Clang Crashes Fixed
   `Issue 64065 `_
 - Fixed a crash when check array access on zero-length element.
   `Issue 64564 `_
+- Fixed a crash when -ast-dump=json was used for code using template
+  deduction guides.
 
 Target Specific Changes
 ---
diff --git a/clang/lib/AST/JSONNodeDumper.cpp b/clang/lib/AST/JSONNodeDumper.cpp
index e67c2c7e216dcea..e2bb34c68cb7e92 100644
--- a/clang/lib/AST/JSONNodeDumper.cpp
+++ b/clang/lib/AST/JSONNodeDumper.cpp
@@ -819,6 +819,10 @@ void JSONNodeDumper::VisitNamedDecl(const NamedDecl *ND) {
 if (VD && VD->hasLocalStorage())
   return;
 
+// Do not mangle template deduction guides.
+if(const auto DG = dyn_cast(ND))
+  return;
+
 std::string MangledName = ASTNameGen.getName(ND);
 if (!MangledName.empty())
   JOS.attribute("mangledName", MangledName);
diff --git a/clang/test/AST/ast-dump-template-decls-json.cpp 
b/clang/test/AST/ast-dump-template-decls-json.cpp
index f51ef937d91dbd3..8a8262d3e665fc3 100644
--- a/clang/test/AST/ast-dump-template-decls-json.cpp
+++ b/clang/test/AST/ast-dump-template-decls-json.cpp
@@ -58,6 +58,10 @@ void V::f() {}
 template  class = R>
 void i();
 
+template  class W{
+};
+W(int)->W<1>;
+
 // NOTE: CHECK lines have been autogenerated by gen_ast_dump_json_test.py
 
 
@@ -217,7 +221,7 @@ void i();
 // CHECK-NEXT:"id": "0x{{.*}}",
 // CHECK-NEXT:"kind": "FunctionTemplateDecl",
 // CHECK-NEXT:"loc": {
-// CHECK-NEXT: "offset": {{[0-9]+}},
+// CHECK-NEXT: "offset": 142,
 // CHECK-NEXT: "file": "{{.*}}",
 // CHECK-NEXT: "line": 4,
 // CHECK-NEXT: "col": 6,
@@ -225,13 +229,13 @@ void i();
 // CHECK-NEXT:},
 // CHECK-NEXT:"range": {
 // CHECK-NEXT: "begin": {
-// CHECK-NEXT:  "offset": {{[0-9]+}},
+// CHECK-NEXT:  "offset": 114,
 // CHECK-NEXT:  "line": 3,
 // CHECK-NEXT:  "col": 1,
 // CHECK-NEXT:  "tokLen": 8
 // CHECK-NEXT: },
 // CHECK-NEXT: "end": {
-// CHECK-NEXT:  "offset": {{[0-9]+}},
+// CHECK-NEXT:  "offset": 146,
 // CHECK-NEXT:  "line": 4,
 // CHECK-NEXT:  "col": 10,
 // CHECK-NEXT:  "tokLen": 1
@@ -243,19 +247,19 @@ void i();
 // CHECK-NEXT:  "id": "0x{{.*}}",
 // CHECK-NEXT:  "kind": "TemplateTypeParmDecl",
 // CHECK-NEXT:  "loc": {
-// CHECK-NEXT:   "offset": {{[0-9]+}},
+// CHECK-NEXT:   "offset": 133,
 // CHECK-NEXT:   "line": 3,
 // CHECK-NEXT:   "col": 20,
 // CHECK-NEXT:   "tokLen": 2
 // CHECK-NEXT:  },
 // CHECK-NEXT:  "range": {
 // CHECK-NEXT:   "begin": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
+// CHECK-NEXT:"offset": 124,
 // CHECK-NEXT:"col": 11,
 // CHECK-NEXT:"tokLen": 8
 // CHECK-NEXT:   },
 // CHECK-NEXT:   "end": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
+// CHECK-NEXT:"offset": 133,
 // CHECK-NEXT:"col": 20,
 // CHECK-NEXT:"tokLen": 2
 // CHECK-NEXT:   }
@@ -270,19 +274,19 @@ void i();
 // CHECK-NEXT:  "id": "0x{{.*}}",
 // CHECK-NEXT:  "kind": "FunctionDecl",
 // CHECK-NEXT:  "loc": {
-// CHECK-NEXT:   "offset": {{[0-9]+}},
+// CHECK-NEXT:   "offset": 142,
 // CHECK-NEXT:   "line": 4,
 // CHECK-NEXT:   "col": 6,
 // CHECK-NEXT:   "tokLen": 1
 // CHECK-NEXT:  },
 // CHECK-NEXT:  "range": {
 // CHECK-NEXT:   "begin": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
+// CHECK-NEXT:"offset": 137,
 // CHECK-NEXT:"col": 1,
 // CHECK-NEXT:"tokLen": 4
 // CHECK-NEXT:   },
 // CHECK-NEXT:   "end": {
-// CHECK-NEXT:"offset": {{[0-9]+}},
+//