[clang] [clang] Enable the -Wdangling-assignment-gsl diagnostic by default. (PR #100708)

2024-07-26 Thread Utkarsh Saxena via cfe-commits

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

Thanks. Looks good since we are past the branch cut.

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


[clang] Fix lifetimebound for field access (PR #100197)

2024-07-24 Thread Utkarsh Saxena via cfe-commits

usx95 wrote:

Makes sense to me. Added cherrypick in 
https://github.com/llvm/llvm-project/issues/81589

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


[clang] Fix lifetimebound for field access (PR #100197)

2024-07-24 Thread Utkarsh Saxena via cfe-commits

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


[clang] Fix lifetimebound for field access (PR #100197)

2024-07-24 Thread Utkarsh Saxena via cfe-commits


@@ -47,6 +47,26 @@ namespace usage_ok {
 q = A(); // expected-warning {{object backing the pointer q will be 
destroyed at the end of the full-expression}}
 r = A(1); // expected-warning {{object backing the pointer r will be 
destroyed at the end of the full-expression}}
   }
+
+  struct FieldCheck {
+struct Set {
+  int a;
+};
+struct Pair {
+  const int& a;
+  int b;
+  Set c;
+};
+Pair p;  
+FieldCheck(const int a): p(a){}
+Pair& getPairR() [[clang::lifetimebound]] { return p; }
+Pair* getPairP() [[clang::lifetimebound]] { return  }
+  };
+  void test_field_access() {
+const int& a = FieldCheck{0}.getPairR().a; // expected-warning {{temporary 
bound to local reference 'a' will be destroyed at the end of the 
full-expression}}
+const int& b = FieldCheck{0}.getPairP()->b; // expected-warning 
{{temporary bound to local reference 'b' will be destroyed at the end of the 
full-expression}}
+const int& c = FieldCheck{0}.getPairP()->c.a; // expected-warning 
{{temporary bound to local reference 'c' will be destroyed at the end of the 
full-expression}}

usx95 wrote:

Done.

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


[clang] Fix lifetimebound for field access (PR #100197)

2024-07-24 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated 
https://github.com/llvm/llvm-project/pull/100197

>From b76d65484c3195f27e8d01208ccc6e6f8ab55273 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 23 Jul 2024 19:41:44 +
Subject: [PATCH 1/5] Fix lifetimebound for field access

---
 clang/lib/Sema/CheckExprLifetime.cpp  |  8 
 clang/test/SemaCXX/attr-lifetimebound.cpp | 21 +
 2 files changed, 29 insertions(+)

diff --git a/clang/lib/Sema/CheckExprLifetime.cpp 
b/clang/lib/Sema/CheckExprLifetime.cpp
index 5c8ef564f30aa..4d26a2e0f50c6 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "CheckExprLifetime.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/Expr.h"
 #include "clang/Basic/DiagnosticSema.h"
 #include "clang/Sema/Initialization.h"
@@ -548,6 +549,13 @@ static void 
visitLocalsRetainedByReferenceBinding(IndirectLocalPath ,
EnableLifetimeWarnings);
   }
 
+  if (auto* M = dyn_cast(Init)) {
+// Lifetime of a field is the lifetime of the base object.
+if (isa(M->getMemberDecl()))
+  visitLocalsRetainedByInitializer(Path, M->getBase(), Visit, true,
+   EnableLifetimeWarnings);
+  }
+
   if (isa(Init)) {
 if (EnableLifetimeWarnings)
   handleGslAnnotatedTypes(Path, Init, Visit);
diff --git a/clang/test/SemaCXX/attr-lifetimebound.cpp 
b/clang/test/SemaCXX/attr-lifetimebound.cpp
index 70bc545c07bd9..b43c43bb21699 100644
--- a/clang/test/SemaCXX/attr-lifetimebound.cpp
+++ b/clang/test/SemaCXX/attr-lifetimebound.cpp
@@ -47,6 +47,26 @@ namespace usage_ok {
 q = A(); // expected-warning {{object backing the pointer q will be 
destroyed at the end of the full-expression}}
 r = A(1); // expected-warning {{object backing the pointer r will be 
destroyed at the end of the full-expression}}
   }
+
+  struct FieldCheck {
+struct Set {
+  int a;
+};
+struct Pair {
+  const int& a;
+  int b;
+  Set c;
+};
+Pair p;  
+FieldCheck(const int a): p(a){}
+Pair& getPairR() [[clang::lifetimebound]] { return p; }
+Pair* getPairP() [[clang::lifetimebound]] { return  }
+  };
+  void test_field_access() {
+const int& a = FieldCheck{0}.getPairR().a; // expected-warning {{temporary 
bound to local reference 'a' will be destroyed at the end of the 
full-expression}}
+const int& b = FieldCheck{0}.getPairP()->b; // expected-warning 
{{temporary bound to local reference 'b' will be destroyed at the end of the 
full-expression}}
+const int& c = FieldCheck{0}.getPairP()->c.a; // expected-warning 
{{temporary bound to local reference 'c' will be destroyed at the end of the 
full-expression}}
+  }
 }
 
 # 1 "" 1 3
@@ -239,3 +259,4 @@ namespace move_forward_et_al_examples {
   S X;
   S *AddressOfOk = std::addressof(X);
 } // namespace move_forward_et_al_examples
+

>From 247f986b7a4b4743826a53e9317c4a65ebe289fe Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 23 Jul 2024 20:32:33 +
Subject: [PATCH 2/5] release notes

---
 clang/docs/ReleaseNotes.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7ac6ed934290d..fdad9202c0ea9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -744,6 +744,8 @@ Improvements to Clang's diagnostics
 - Clang now diagnoses dangling assignments for pointer-like objects (annotated 
with `[[gsl::Pointer]]`) under `-Wdangling-assignment-gsl` (off by default)
   Fixes #GH63310.
 
+- Clang now diagnoses dangling references to fields of temporary objects. 
Fixes #GH81589.
+
 Improvements to Clang's time-trace
 --
 

>From 3825954a382d6bedd79f7ad332cd6937c74fe5fa Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 23 Jul 2024 20:33:18 +
Subject: [PATCH 3/5] format

---
 clang/lib/Sema/CheckExprLifetime.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/CheckExprLifetime.cpp 
b/clang/lib/Sema/CheckExprLifetime.cpp
index 4d26a2e0f50c6..66b61fbbbeda7 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -549,7 +549,7 @@ static void 
visitLocalsRetainedByReferenceBinding(IndirectLocalPath ,
EnableLifetimeWarnings);
   }
 
-  if (auto* M = dyn_cast(Init)) {
+  if (auto *M = dyn_cast(Init)) {
 // Lifetime of a field is the lifetime of the base object.
 if (isa(M->getMemberDecl()))
   visitLocalsRetainedByInitializer(Path, M->getBase(), Visit, true,

>From dcfd225abfa0bcbd6e00f3c30c7c490982974fee Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 24 Jul 2024 08:46:06 +
Subject: [PATCH 4/5] Lifetime of reference type field is unknown. skip it

---
 clang/lib/Sema/CheckExprLifetime.cpp  | 5 +++--
 

[clang] Fix lifetimebound for field access (PR #100197)

2024-07-24 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated 
https://github.com/llvm/llvm-project/pull/100197

>From b76d65484c3195f27e8d01208ccc6e6f8ab55273 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 23 Jul 2024 19:41:44 +
Subject: [PATCH 1/4] Fix lifetimebound for field access

---
 clang/lib/Sema/CheckExprLifetime.cpp  |  8 
 clang/test/SemaCXX/attr-lifetimebound.cpp | 21 +
 2 files changed, 29 insertions(+)

diff --git a/clang/lib/Sema/CheckExprLifetime.cpp 
b/clang/lib/Sema/CheckExprLifetime.cpp
index 5c8ef564f30aa..4d26a2e0f50c6 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "CheckExprLifetime.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/Expr.h"
 #include "clang/Basic/DiagnosticSema.h"
 #include "clang/Sema/Initialization.h"
@@ -548,6 +549,13 @@ static void 
visitLocalsRetainedByReferenceBinding(IndirectLocalPath ,
EnableLifetimeWarnings);
   }
 
+  if (auto* M = dyn_cast(Init)) {
+// Lifetime of a field is the lifetime of the base object.
+if (isa(M->getMemberDecl()))
+  visitLocalsRetainedByInitializer(Path, M->getBase(), Visit, true,
+   EnableLifetimeWarnings);
+  }
+
   if (isa(Init)) {
 if (EnableLifetimeWarnings)
   handleGslAnnotatedTypes(Path, Init, Visit);
diff --git a/clang/test/SemaCXX/attr-lifetimebound.cpp 
b/clang/test/SemaCXX/attr-lifetimebound.cpp
index 70bc545c07bd9..b43c43bb21699 100644
--- a/clang/test/SemaCXX/attr-lifetimebound.cpp
+++ b/clang/test/SemaCXX/attr-lifetimebound.cpp
@@ -47,6 +47,26 @@ namespace usage_ok {
 q = A(); // expected-warning {{object backing the pointer q will be 
destroyed at the end of the full-expression}}
 r = A(1); // expected-warning {{object backing the pointer r will be 
destroyed at the end of the full-expression}}
   }
+
+  struct FieldCheck {
+struct Set {
+  int a;
+};
+struct Pair {
+  const int& a;
+  int b;
+  Set c;
+};
+Pair p;  
+FieldCheck(const int a): p(a){}
+Pair& getPairR() [[clang::lifetimebound]] { return p; }
+Pair* getPairP() [[clang::lifetimebound]] { return  }
+  };
+  void test_field_access() {
+const int& a = FieldCheck{0}.getPairR().a; // expected-warning {{temporary 
bound to local reference 'a' will be destroyed at the end of the 
full-expression}}
+const int& b = FieldCheck{0}.getPairP()->b; // expected-warning 
{{temporary bound to local reference 'b' will be destroyed at the end of the 
full-expression}}
+const int& c = FieldCheck{0}.getPairP()->c.a; // expected-warning 
{{temporary bound to local reference 'c' will be destroyed at the end of the 
full-expression}}
+  }
 }
 
 # 1 "" 1 3
@@ -239,3 +259,4 @@ namespace move_forward_et_al_examples {
   S X;
   S *AddressOfOk = std::addressof(X);
 } // namespace move_forward_et_al_examples
+

>From 247f986b7a4b4743826a53e9317c4a65ebe289fe Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 23 Jul 2024 20:32:33 +
Subject: [PATCH 2/4] release notes

---
 clang/docs/ReleaseNotes.rst | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7ac6ed934290d..fdad9202c0ea9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -744,6 +744,8 @@ Improvements to Clang's diagnostics
 - Clang now diagnoses dangling assignments for pointer-like objects (annotated 
with `[[gsl::Pointer]]`) under `-Wdangling-assignment-gsl` (off by default)
   Fixes #GH63310.
 
+- Clang now diagnoses dangling references to fields of temporary objects. 
Fixes #GH81589.
+
 Improvements to Clang's time-trace
 --
 

>From 3825954a382d6bedd79f7ad332cd6937c74fe5fa Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 23 Jul 2024 20:33:18 +
Subject: [PATCH 3/4] format

---
 clang/lib/Sema/CheckExprLifetime.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Sema/CheckExprLifetime.cpp 
b/clang/lib/Sema/CheckExprLifetime.cpp
index 4d26a2e0f50c6..66b61fbbbeda7 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -549,7 +549,7 @@ static void 
visitLocalsRetainedByReferenceBinding(IndirectLocalPath ,
EnableLifetimeWarnings);
   }
 
-  if (auto* M = dyn_cast(Init)) {
+  if (auto *M = dyn_cast(Init)) {
 // Lifetime of a field is the lifetime of the base object.
 if (isa(M->getMemberDecl()))
   visitLocalsRetainedByInitializer(Path, M->getBase(), Visit, true,

>From dcfd225abfa0bcbd6e00f3c30c7c490982974fee Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 24 Jul 2024 08:46:06 +
Subject: [PATCH 4/4] Lifetime of reference type field is unknown. skip it

---
 clang/lib/Sema/CheckExprLifetime.cpp  | 5 +++--
 

[clang] Fix lifetimebound for field access (PR #100197)

2024-07-23 Thread Utkarsh Saxena via cfe-commits

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


[clang] Fix lifetimebound for field access (PR #100197)

2024-07-23 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 created 
https://github.com/llvm/llvm-project/pull/100197

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

>From b76d65484c3195f27e8d01208ccc6e6f8ab55273 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Tue, 23 Jul 2024 19:41:44 +
Subject: [PATCH] Fix lifetimebound for field access

---
 clang/lib/Sema/CheckExprLifetime.cpp  |  8 
 clang/test/SemaCXX/attr-lifetimebound.cpp | 21 +
 2 files changed, 29 insertions(+)

diff --git a/clang/lib/Sema/CheckExprLifetime.cpp 
b/clang/lib/Sema/CheckExprLifetime.cpp
index 5c8ef564f30aa..4d26a2e0f50c6 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "CheckExprLifetime.h"
+#include "clang/AST/Decl.h"
 #include "clang/AST/Expr.h"
 #include "clang/Basic/DiagnosticSema.h"
 #include "clang/Sema/Initialization.h"
@@ -548,6 +549,13 @@ static void 
visitLocalsRetainedByReferenceBinding(IndirectLocalPath ,
EnableLifetimeWarnings);
   }
 
+  if (auto* M = dyn_cast(Init)) {
+// Lifetime of a field is the lifetime of the base object.
+if (isa(M->getMemberDecl()))
+  visitLocalsRetainedByInitializer(Path, M->getBase(), Visit, true,
+   EnableLifetimeWarnings);
+  }
+
   if (isa(Init)) {
 if (EnableLifetimeWarnings)
   handleGslAnnotatedTypes(Path, Init, Visit);
diff --git a/clang/test/SemaCXX/attr-lifetimebound.cpp 
b/clang/test/SemaCXX/attr-lifetimebound.cpp
index 70bc545c07bd9..b43c43bb21699 100644
--- a/clang/test/SemaCXX/attr-lifetimebound.cpp
+++ b/clang/test/SemaCXX/attr-lifetimebound.cpp
@@ -47,6 +47,26 @@ namespace usage_ok {
 q = A(); // expected-warning {{object backing the pointer q will be 
destroyed at the end of the full-expression}}
 r = A(1); // expected-warning {{object backing the pointer r will be 
destroyed at the end of the full-expression}}
   }
+
+  struct FieldCheck {
+struct Set {
+  int a;
+};
+struct Pair {
+  const int& a;
+  int b;
+  Set c;
+};
+Pair p;  
+FieldCheck(const int a): p(a){}
+Pair& getPairR() [[clang::lifetimebound]] { return p; }
+Pair* getPairP() [[clang::lifetimebound]] { return  }
+  };
+  void test_field_access() {
+const int& a = FieldCheck{0}.getPairR().a; // expected-warning {{temporary 
bound to local reference 'a' will be destroyed at the end of the 
full-expression}}
+const int& b = FieldCheck{0}.getPairP()->b; // expected-warning 
{{temporary bound to local reference 'b' will be destroyed at the end of the 
full-expression}}
+const int& c = FieldCheck{0}.getPairP()->c.a; // expected-warning 
{{temporary bound to local reference 'c' will be destroyed at the end of the 
full-expression}}
+  }
 }
 
 # 1 "" 1 3
@@ -239,3 +259,4 @@ namespace move_forward_et_al_examples {
   S X;
   S *AddressOfOk = std::addressof(X);
 } // namespace move_forward_et_al_examples
+

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


[clang] Record mainfile name in the Frontend time trace (PR #99866)

2024-07-22 Thread Utkarsh Saxena via cfe-commits

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


[clang] Record mainfile name in the Frontend time trace (PR #99866)

2024-07-22 Thread Utkarsh Saxena via cfe-commits


@@ -209,7 +208,7 @@ constexpr int slow_init_list[] = {1, 1, 2, 3, 5, 8, 13, 
21}; // 25th line
   ASSERT_TRUE(compileFromString(Code, "-std=c++20", "test.cc"));
   std::string Json = teardownProfiler();
   ASSERT_EQ(R"(
-Frontend
+Frontend (, test.cc)

usx95 wrote:

Removed extraneous ` ,`

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


[clang] Record mainfile name in the Frontend time trace (PR #99866)

2024-07-22 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/99866

>From e0d76b97e386421ac2e653c206f49f827b24e65b Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Mon, 22 Jul 2024 12:16:48 +
Subject: [PATCH 1/2] Record mainfile name in the Frontend time trace

---
 clang/lib/Parse/ParseAST.cpp | 8 +++-
 clang/unittests/Support/TimeProfilerTest.cpp | 7 +++
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Parse/ParseAST.cpp b/clang/lib/Parse/ParseAST.cpp
index 77ab3b556da58..53b0785b3e181 100644
--- a/clang/lib/Parse/ParseAST.cpp
+++ b/clang/lib/Parse/ParseAST.cpp
@@ -152,7 +152,13 @@ void clang::ParseAST(Sema , bool PrintStats, bool 
SkipFunctionBodies) {
   bool HaveLexer = S.getPreprocessor().getCurrentLexer();
 
   if (HaveLexer) {
-llvm::TimeTraceScope TimeScope("Frontend");
+llvm::TimeTraceScope TimeScope("Frontend", [&]() {
+  llvm::TimeTraceMetadata M;
+  const SourceManager  = S.getSourceManager();
+  if (const auto *FE = SM.getFileEntryForID(SM.getMainFileID()))
+M.File = FE->tryGetRealPathName();
+  return M;
+});
 P.Initialize();
 Parser::DeclGroupPtrTy ADecl;
 Sema::ModuleImportState ImportState;
diff --git a/clang/unittests/Support/TimeProfilerTest.cpp 
b/clang/unittests/Support/TimeProfilerTest.cpp
index 56d880cffde61..9e2494da2bf35 100644
--- a/clang/unittests/Support/TimeProfilerTest.cpp
+++ b/clang/unittests/Support/TimeProfilerTest.cpp
@@ -81,7 +81,6 @@ std::string GetMetadata(json::Object *Event) {
   if (json::Object *Args = Event->getObject("args")) {
 if (auto Detail = Args->getString("detail"))
   OS << Detail;
-// Use only filename to not include os-specific path separators.
 if (auto File = Args->getString("file"))
   OS << ", " << llvm::sys::path::filename(*File);
 if (auto Line = Args->getInteger("line"))
@@ -209,7 +208,7 @@ constexpr int slow_init_list[] = {1, 1, 2, 3, 5, 8, 13, 
21}; // 25th line
   ASSERT_TRUE(compileFromString(Code, "-std=c++20", "test.cc"));
   std::string Json = teardownProfiler();
   ASSERT_EQ(R"(
-Frontend
+Frontend (, test.cc)
 | ParseDeclarationOrFunctionDefinition (test.cc:2:1)
 | ParseDeclarationOrFunctionDefinition (test.cc:6:1)
 | | ParseFunctionDefinition (slow_func)
@@ -266,7 +265,7 @@ TEST(TimeProfilerTest, TemplateInstantiations) {
 /*Headers=*/{{"a.h", A_H}, {"b.h", B_H}}));
   std::string Json = teardownProfiler();
   ASSERT_EQ(R"(
-Frontend
+Frontend (, test.cc)
 | ParseFunctionDefinition (fooB)
 | ParseFunctionDefinition (fooMTA)
 | ParseFunctionDefinition (fooA)
@@ -291,7 +290,7 @@ struct {
   ASSERT_TRUE(compileFromString(Code, "-std=c99", "test.c"));
   std::string Json = teardownProfiler();
   ASSERT_EQ(R"(
-Frontend
+Frontend (, test.c)
 | ParseDeclarationOrFunctionDefinition (test.c:2:1)
 | | isIntegerConstantExpr ()
 | | EvaluateKnownConstIntCheckOverflow ()

>From 18851b286297edb8ccc7bbadc2ec1c1dde1ab856 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Mon, 22 Jul 2024 14:50:18 +
Subject: [PATCH 2/2] address comments

---
 clang/lib/Parse/ParseAST.cpp |  8 +---
 clang/unittests/Support/TimeProfilerTest.cpp | 15 ---
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Parse/ParseAST.cpp b/clang/lib/Parse/ParseAST.cpp
index 53b0785b3e181..e008cc0e38ced 100644
--- a/clang/lib/Parse/ParseAST.cpp
+++ b/clang/lib/Parse/ParseAST.cpp
@@ -154,9 +154,11 @@ void clang::ParseAST(Sema , bool PrintStats, bool 
SkipFunctionBodies) {
   if (HaveLexer) {
 llvm::TimeTraceScope TimeScope("Frontend", [&]() {
   llvm::TimeTraceMetadata M;
-  const SourceManager  = S.getSourceManager();
-  if (const auto *FE = SM.getFileEntryForID(SM.getMainFileID()))
-M.File = FE->tryGetRealPathName();
+  if (llvm::isTimeTraceVerbose()) {
+const SourceManager  = S.getSourceManager();
+if (const auto *FE = SM.getFileEntryForID(SM.getMainFileID()))
+  M.File = FE->tryGetRealPathName();
+  }
   return M;
 });
 P.Initialize();
diff --git a/clang/unittests/Support/TimeProfilerTest.cpp 
b/clang/unittests/Support/TimeProfilerTest.cpp
index 9e2494da2bf35..f53fe71d630bf 100644
--- a/clang/unittests/Support/TimeProfilerTest.cpp
+++ b/clang/unittests/Support/TimeProfilerTest.cpp
@@ -76,17 +76,18 @@ bool compileFromString(StringRef Code, StringRef Standard, 
StringRef File,
 }
 
 std::string GetMetadata(json::Object *Event) {
-  std::string Metadata;
-  llvm::raw_string_ostream OS(Metadata);
+  std::string M;
+  llvm::raw_string_ostream OS(M);
   if (json::Object *Args = Event->getObject("args")) {
 if (auto Detail = Args->getString("detail"))
   OS << Detail;
+// Use only filename to not include os-specific path separators.
 if (auto File = Args->getString("file"))
-  OS << ", " << llvm::sys::path::filename(*File);
+  OS << (M.empty() ? "" : ", ") << 

[clang] Record mainfile name in the Frontend time trace (PR #99866)

2024-07-22 Thread Utkarsh Saxena via cfe-commits


@@ -81,7 +81,6 @@ std::string GetMetadata(json::Object *Event) {
   if (json::Object *Args = Event->getObject("args")) {
 if (auto Detail = Args->getString("detail"))
   OS << Detail;
-// Use only filename to not include os-specific path separators.

usx95 wrote:

Reverted.

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


[clang] Record mainfile name in the Frontend time trace (PR #99866)

2024-07-22 Thread Utkarsh Saxena via cfe-commits


@@ -152,7 +152,13 @@ void clang::ParseAST(Sema , bool PrintStats, bool 
SkipFunctionBodies) {
   bool HaveLexer = S.getPreprocessor().getCurrentLexer();
 
   if (HaveLexer) {
-llvm::TimeTraceScope TimeScope("Frontend");
+llvm::TimeTraceScope TimeScope("Frontend", [&]() {
+  llvm::TimeTraceMetadata M;
+  const SourceManager  = S.getSourceManager();
+  if (const auto *FE = SM.getFileEntryForID(SM.getMainFileID()))
+M.File = FE->tryGetRealPathName();

usx95 wrote:

Done.

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


[clang] Record mainfile name in the Frontend time trace (PR #99866)

2024-07-22 Thread Utkarsh Saxena via cfe-commits

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


[clang] Record mainfile name in the Frontend time trace (PR #99866)

2024-07-22 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 created https://github.com/llvm/llvm-project/pull/99866

None

>From e0d76b97e386421ac2e653c206f49f827b24e65b Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Mon, 22 Jul 2024 12:16:48 +
Subject: [PATCH] Record mainfile name in the Frontend time trace

---
 clang/lib/Parse/ParseAST.cpp | 8 +++-
 clang/unittests/Support/TimeProfilerTest.cpp | 7 +++
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Parse/ParseAST.cpp b/clang/lib/Parse/ParseAST.cpp
index 77ab3b556da58..53b0785b3e181 100644
--- a/clang/lib/Parse/ParseAST.cpp
+++ b/clang/lib/Parse/ParseAST.cpp
@@ -152,7 +152,13 @@ void clang::ParseAST(Sema , bool PrintStats, bool 
SkipFunctionBodies) {
   bool HaveLexer = S.getPreprocessor().getCurrentLexer();
 
   if (HaveLexer) {
-llvm::TimeTraceScope TimeScope("Frontend");
+llvm::TimeTraceScope TimeScope("Frontend", [&]() {
+  llvm::TimeTraceMetadata M;
+  const SourceManager  = S.getSourceManager();
+  if (const auto *FE = SM.getFileEntryForID(SM.getMainFileID()))
+M.File = FE->tryGetRealPathName();
+  return M;
+});
 P.Initialize();
 Parser::DeclGroupPtrTy ADecl;
 Sema::ModuleImportState ImportState;
diff --git a/clang/unittests/Support/TimeProfilerTest.cpp 
b/clang/unittests/Support/TimeProfilerTest.cpp
index 56d880cffde61..9e2494da2bf35 100644
--- a/clang/unittests/Support/TimeProfilerTest.cpp
+++ b/clang/unittests/Support/TimeProfilerTest.cpp
@@ -81,7 +81,6 @@ std::string GetMetadata(json::Object *Event) {
   if (json::Object *Args = Event->getObject("args")) {
 if (auto Detail = Args->getString("detail"))
   OS << Detail;
-// Use only filename to not include os-specific path separators.
 if (auto File = Args->getString("file"))
   OS << ", " << llvm::sys::path::filename(*File);
 if (auto Line = Args->getInteger("line"))
@@ -209,7 +208,7 @@ constexpr int slow_init_list[] = {1, 1, 2, 3, 5, 8, 13, 
21}; // 25th line
   ASSERT_TRUE(compileFromString(Code, "-std=c++20", "test.cc"));
   std::string Json = teardownProfiler();
   ASSERT_EQ(R"(
-Frontend
+Frontend (, test.cc)
 | ParseDeclarationOrFunctionDefinition (test.cc:2:1)
 | ParseDeclarationOrFunctionDefinition (test.cc:6:1)
 | | ParseFunctionDefinition (slow_func)
@@ -266,7 +265,7 @@ TEST(TimeProfilerTest, TemplateInstantiations) {
 /*Headers=*/{{"a.h", A_H}, {"b.h", B_H}}));
   std::string Json = teardownProfiler();
   ASSERT_EQ(R"(
-Frontend
+Frontend (, test.cc)
 | ParseFunctionDefinition (fooB)
 | ParseFunctionDefinition (fooMTA)
 | ParseFunctionDefinition (fooA)
@@ -291,7 +290,7 @@ struct {
   ASSERT_TRUE(compileFromString(Code, "-std=c99", "test.c"));
   std::string Json = teardownProfiler();
   ASSERT_EQ(R"(
-Frontend
+Frontend (, test.c)
 | ParseDeclarationOrFunctionDefinition (test.c:2:1)
 | | isIntegerConstantExpr ()
 | | EvaluateKnownConstIntCheckOverflow ()

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


[clang] [llvm] Reapply "Add source file name for template instantiations in -ftime-trace" (PR #99757)

2024-07-21 Thread Utkarsh Saxena via cfe-commits

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


[clang] [llvm] Revert "Add source file name for template instantiations in -ftime-trace" (PR #99534)

2024-07-21 Thread Utkarsh Saxena via cfe-commits

usx95 wrote:

Acknowledged. I will use the`skip-precommit-approval` label from now on. 

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


[clang] [llvm] Reapply "Add source file name for template instantiations in -ftime-trace" (PR #99757)

2024-07-20 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 created https://github.com/llvm/llvm-project/pull/99757

Reverts https://github.com/llvm/llvm-project/pull/99731

Remove accidentally added temporary file.
Also fix uninitialized read of line number.

>From 2c43d8b557192df6999437485cdbdc2e030f4fe5 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Sat, 20 Jul 2024 06:11:40 +
Subject: [PATCH 1/2] Reapply "Reapply "Add source file name for template
 instantiations in -ftime-trace"" (#99731)

This reverts commit abaf13ad589d72b356a8788a5095f869d9d038d0.
---
 a-abfdec1d.o.tmp  |   0
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/Driver/Options.td |   4 +
 .../include/clang/Frontend/FrontendOptions.h  |   8 +-
 clang/lib/Driver/ToolChains/Clang.cpp |   1 +
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  11 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  11 +-
 clang/test/Driver/ftime-trace-sections.cpp|   2 +-
 clang/test/Driver/ftime-trace.cpp |  39 +++---
 clang/tools/driver/cc1_main.cpp   |   3 +-
 clang/unittests/Support/TimeProfilerTest.cpp  | 123 ++
 llvm/include/llvm/Support/TimeProfiler.h  |  23 +++-
 llvm/lib/Support/TimeProfiler.cpp |  61 +++--
 13 files changed, 225 insertions(+), 64 deletions(-)
 create mode 100644 a-abfdec1d.o.tmp

diff --git a/a-abfdec1d.o.tmp b/a-abfdec1d.o.tmp
new file mode 100644
index 0..e69de29bb2d1d
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index aa91663260755..7ac6ed934290d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -750,6 +750,9 @@ Improvements to Clang's time-trace
 - Clang now specifies that using ``auto`` in a lambda parameter is a C++14 
extension when
   appropriate. (`#46059: 
`_).
 
+- Clang now adds source file infomation for template instantiations as 
``event["args"]["filename"]``. This
+  added behind an option ``-ftime-trace-verbose``. This is expected to 
increase the size of trace by 2-3 times.
+
 Improvements to Coverage Mapping
 
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 8707e71f2a319..9c6cebd77ff0a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3998,6 +3998,10 @@ def ftime_trace_granularity_EQ : Joined<["-"], 
"ftime-trace-granularity=">, Grou
   HelpText<"Minimum time granularity (in microseconds) traced by time 
profiler">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoInt, "500u">;
+def ftime_trace_verbose : Joined<["-"], "ftime-trace-verbose">, Group,
+  HelpText<"Make time trace capture verbose event details (e.g. source 
filenames). This can increase the size of the output by 2-3 times">,
+  Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
+  MarshallingInfoFlag>;
 def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 5e5034fe01eb5..8241925c98476 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -580,6 +580,11 @@ class FrontendOptions {
   /// Minimum time granularity (in microseconds) traced by time profiler.
   unsigned TimeTraceGranularity;
 
+  /// Make time trace capture verbose event details (e.g. source filenames).
+  /// This can increase the size of the output by 2-3 times.
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned TimeTraceVerbose : 1;
+
   /// Path which stores the output files for -ftime-trace
   std::string TimeTracePath;
 
@@ -601,7 +606,8 @@ class FrontendOptions {
 EmitSymbolGraph(false), EmitExtensionSymbolGraphs(false),
 EmitSymbolGraphSymbolLabelsForTesting(false),
 EmitPrettySymbolGraphs(false), GenReducedBMI(false),
-UseClangIRPipeline(false), TimeTraceGranularity(500) {}
+UseClangIRPipeline(false), TimeTraceGranularity(500),
+TimeTraceVerbose(false) {}
 
   /// getInputKindForExtension - Return the appropriate input kind for a file
   /// extension. For example, "c" would return Language::C.
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index c9f0fe0a3d60f..f7b987bf810c1 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6757,6 +6757,7 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
   if (const char *Name = C.getTimeTraceFile()) {
 CmdArgs.push_back(Args.MakeArgString("-ftime-trace=" + Twine(Name)));
 Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_granularity_EQ);
+

[clang] [llvm] Reapply "Add source file name for template instantiations in -ftime-trace" (PR #99545)

2024-07-19 Thread Utkarsh Saxena via cfe-commits

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


[clang] [llvm] Reapply "Add source file name for template instantiations in -ftime-trace" (PR #99545)

2024-07-19 Thread Utkarsh Saxena via cfe-commits


@@ -60,13 +75,29 @@ bool compileFromString(StringRef Code, StringRef Standard, 
StringRef FileName) {
   return Compiler.ExecuteAction(Action);
 }
 
+std::string GetMetadata(json::Object *Event) {
+  std::string Metadata;
+  llvm::raw_string_ostream OS(Metadata);
+  if (json::Object *Args = Event->getObject("args")) {
+if (auto Detail = Args->getString("detail"))
+  OS << Detail;
+if (auto File = Args->getString("file"))
+  OS << ", "
+ << llvm::sys::path::filename(File->str(),

usx95 wrote:

Done.

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


[clang] [llvm] Reapply "Add source file name for template instantiations in -ftime-trace" (PR #99545)

2024-07-19 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/99545

>From 1047bd2fad795c33c6d228ed117b75025422ddb9 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Thu, 18 Jul 2024 17:52:10 +
Subject: [PATCH 1/3] Reapply "Add source file name for template instantiations
 in -ftime-trace" (#99534)

This reverts commit 04bcd74df73af6fed16bfd0d6784fc0aec582bc0.
---
 a-abfdec1d.o.tmp  |   0
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/Driver/Options.td |   4 +
 .../include/clang/Frontend/FrontendOptions.h  |   8 +-
 clang/lib/Driver/ToolChains/Clang.cpp |   1 +
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  11 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  11 +-
 clang/test/Driver/ftime-trace-sections.cpp|   2 +-
 clang/test/Driver/ftime-trace.cpp |  39 +++---
 clang/tools/driver/cc1_main.cpp   |   3 +-
 clang/unittests/Support/TimeProfilerTest.cpp  | 121 ++
 llvm/include/llvm/Support/TimeProfiler.h  |  23 +++-
 llvm/lib/Support/TimeProfiler.cpp |  61 +++--
 13 files changed, 223 insertions(+), 64 deletions(-)
 create mode 100644 a-abfdec1d.o.tmp

diff --git a/a-abfdec1d.o.tmp b/a-abfdec1d.o.tmp
new file mode 100644
index 0..e69de29bb2d1d
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e0e86af257a19..971df672b6ca1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -736,6 +736,9 @@ Improvements to Clang's time-trace
 - Clang now specifies that using ``auto`` in a lambda parameter is a C++14 
extension when
   appropriate. (`#46059: 
`_).
 
+- Clang now adds source file infomation for template instantiations as 
``event["args"]["filename"]``. This
+  added behind an option ``-ftime-trace-verbose``. This is expected to 
increase the size of trace by 2-3 times.
+
 Improvements to Coverage Mapping
 
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1675e435d210c..d3068c1b30a7a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3988,6 +3988,10 @@ def ftime_trace_granularity_EQ : Joined<["-"], 
"ftime-trace-granularity=">, Grou
   HelpText<"Minimum time granularity (in microseconds) traced by time 
profiler">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoInt, "500u">;
+def ftime_trace_verbose : Joined<["-"], "ftime-trace-verbose">, Group,
+  HelpText<"Make time trace capture verbose event details (e.g. source 
filenames). This can increase the size of the output by 2-3 times">,
+  Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
+  MarshallingInfoFlag>;
 def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 5e5034fe01eb5..8241925c98476 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -580,6 +580,11 @@ class FrontendOptions {
   /// Minimum time granularity (in microseconds) traced by time profiler.
   unsigned TimeTraceGranularity;
 
+  /// Make time trace capture verbose event details (e.g. source filenames).
+  /// This can increase the size of the output by 2-3 times.
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned TimeTraceVerbose : 1;
+
   /// Path which stores the output files for -ftime-trace
   std::string TimeTracePath;
 
@@ -601,7 +606,8 @@ class FrontendOptions {
 EmitSymbolGraph(false), EmitExtensionSymbolGraphs(false),
 EmitSymbolGraphSymbolLabelsForTesting(false),
 EmitPrettySymbolGraphs(false), GenReducedBMI(false),
-UseClangIRPipeline(false), TimeTraceGranularity(500) {}
+UseClangIRPipeline(false), TimeTraceGranularity(500),
+TimeTraceVerbose(false) {}
 
   /// getInputKindForExtension - Return the appropriate input kind for a file
   /// extension. For example, "c" would return Language::C.
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 1fd6fba210042..6b33301d36401 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6754,6 +6754,7 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
   if (const char *Name = C.getTimeTraceFile()) {
 CmdArgs.push_back(Args.MakeArgString("-ftime-trace=" + Twine(Name)));
 Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_granularity_EQ);
+Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_verbose);
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_ftrapv_handler_EQ)) {
diff --git 

[clang] [llvm] Reapply "Add source file name for template instantiations in -ftime-trace" (PR #99545)

2024-07-18 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 created https://github.com/llvm/llvm-project/pull/99545

Fix the Windows test.

>From 1047bd2fad795c33c6d228ed117b75025422ddb9 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Thu, 18 Jul 2024 17:52:10 +
Subject: [PATCH 1/2] Reapply "Add source file name for template instantiations
 in -ftime-trace" (#99534)

This reverts commit 04bcd74df73af6fed16bfd0d6784fc0aec582bc0.
---
 a-abfdec1d.o.tmp  |   0
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/Driver/Options.td |   4 +
 .../include/clang/Frontend/FrontendOptions.h  |   8 +-
 clang/lib/Driver/ToolChains/Clang.cpp |   1 +
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  11 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  11 +-
 clang/test/Driver/ftime-trace-sections.cpp|   2 +-
 clang/test/Driver/ftime-trace.cpp |  39 +++---
 clang/tools/driver/cc1_main.cpp   |   3 +-
 clang/unittests/Support/TimeProfilerTest.cpp  | 121 ++
 llvm/include/llvm/Support/TimeProfiler.h  |  23 +++-
 llvm/lib/Support/TimeProfiler.cpp |  61 +++--
 13 files changed, 223 insertions(+), 64 deletions(-)
 create mode 100644 a-abfdec1d.o.tmp

diff --git a/a-abfdec1d.o.tmp b/a-abfdec1d.o.tmp
new file mode 100644
index 0..e69de29bb2d1d
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e0e86af257a19..971df672b6ca1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -736,6 +736,9 @@ Improvements to Clang's time-trace
 - Clang now specifies that using ``auto`` in a lambda parameter is a C++14 
extension when
   appropriate. (`#46059: 
`_).
 
+- Clang now adds source file infomation for template instantiations as 
``event["args"]["filename"]``. This
+  added behind an option ``-ftime-trace-verbose``. This is expected to 
increase the size of trace by 2-3 times.
+
 Improvements to Coverage Mapping
 
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1675e435d210c..d3068c1b30a7a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3988,6 +3988,10 @@ def ftime_trace_granularity_EQ : Joined<["-"], 
"ftime-trace-granularity=">, Grou
   HelpText<"Minimum time granularity (in microseconds) traced by time 
profiler">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoInt, "500u">;
+def ftime_trace_verbose : Joined<["-"], "ftime-trace-verbose">, Group,
+  HelpText<"Make time trace capture verbose event details (e.g. source 
filenames). This can increase the size of the output by 2-3 times">,
+  Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
+  MarshallingInfoFlag>;
 def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 5e5034fe01eb5..8241925c98476 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -580,6 +580,11 @@ class FrontendOptions {
   /// Minimum time granularity (in microseconds) traced by time profiler.
   unsigned TimeTraceGranularity;
 
+  /// Make time trace capture verbose event details (e.g. source filenames).
+  /// This can increase the size of the output by 2-3 times.
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned TimeTraceVerbose : 1;
+
   /// Path which stores the output files for -ftime-trace
   std::string TimeTracePath;
 
@@ -601,7 +606,8 @@ class FrontendOptions {
 EmitSymbolGraph(false), EmitExtensionSymbolGraphs(false),
 EmitSymbolGraphSymbolLabelsForTesting(false),
 EmitPrettySymbolGraphs(false), GenReducedBMI(false),
-UseClangIRPipeline(false), TimeTraceGranularity(500) {}
+UseClangIRPipeline(false), TimeTraceGranularity(500),
+TimeTraceVerbose(false) {}
 
   /// getInputKindForExtension - Return the appropriate input kind for a file
   /// extension. For example, "c" would return Language::C.
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 1fd6fba210042..6b33301d36401 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6754,6 +6754,7 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
   if (const char *Name = C.getTimeTraceFile()) {
 CmdArgs.push_back(Args.MakeArgString("-ftime-trace=" + Twine(Name)));
 Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_granularity_EQ);
+Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_verbose);
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_ftrapv_handler_EQ)) {
diff 

[clang] [llvm] Revert "Add source file name for template instantiations in -ftime-trace" (PR #99534)

2024-07-18 Thread Utkarsh Saxena via cfe-commits

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


[clang] [llvm] Revert "Add source file name for template instantiations in -ftime-trace" (PR #99534)

2024-07-18 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 created https://github.com/llvm/llvm-project/pull/99534

Reverts llvm/llvm-project#98320

Breaks windows tests:

```
Step 8 (test-build-unified-tree-check-clang-unit) failure: test (failure)
 TEST 'Clang-Unit :: Support/./ClangSupportTests.exe/1/3' 
FAILED 
Script(shard):
--
GTEST_OUTPUT=json:C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\build\tools\clang\unittests\Support\.\ClangSupportTests.exe-Clang-Unit-4296-1-3.json
 GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=3 GTEST_SHARD_INDEX=1 
C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\build\tools\clang\unittests\Support\.\ClangSupportTests.exe
--

Script:
--
C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\build\tools\clang\unittests\Support\.\ClangSupportTests.exe
 --gtest_filter=TimeProfilerTest.TemplateInstantiations
--
C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\llvm-project\clang\unittests\Support\TimeProfilerTest.cpp(278):
 error: Expected equality of these values:
  R"(
Frontend
| ParseFunctionDefinition (fooB)
| ParseFunctionDefinition (fooMTA)
| ParseFunctionDefinition (fooA)
| ParseDeclarationOrFunctionDefinition (test.cc:3:5)
| | ParseFunctionDefinition (user)
| PerformPendingInstantiations
| | InstantiateFunction (fooA, ./a.h:7)
| | | InstantiateFunction (fooB, ./b.h:3)
| | | InstantiateFunction (fooMTA, ./a.h:4)
)"
Which is: "\nFrontend\n| ParseFunctionDefinition (fooB)\n| 
ParseFunctionDefinition (fooMTA)\n| ParseFunctionDefinition (fooA)\n| 
ParseDeclarationOrFunctionDefinition (test.cc:3:5)\n| | ParseFunctionDefinition 
(user)\n| PerformPendingInstantiations\n| | InstantiateFunction (fooA, 
./a.h:7)\n| | | InstantiateFunction (fooB, ./b.h:3)\n| | | 
InstantiateFunction (fooMTA, ./a.h:4)\n"
  buildTraceGraph(Json)
Which is: "\nFrontend\n| ParseFunctionDefinition (fooB)\n| 
ParseFunctionDefinition (fooMTA)\n| ParseFunctionDefinition (fooA)\n| 
ParseDeclarationOrFunctionDefinition (test.cc:3:5)\n| | ParseFunctionDefinition 
(user)\n| PerformPendingInstantiations\n| | InstantiateFunction (fooA, 
.\\a.h:7)\n| | | InstantiateFunction (fooB, .\\b.h:3)\n| | | 
InstantiateFunction (fooMTA, .\\a.h:4)\n"
With diff:
@@ -7,5 +7,5 @@
 | | ParseFunctionDefinition (user)
 | PerformPendingInstantiations
-| | InstantiateFunction (fooA, ./a.h:7)
-| | | InstantiateFunction (fooB, ./b.h:3)
-| | | InstantiateFunction (fooMTA, ./a.h:4)\n
+| | InstantiateFunction (fooA, .\\a.h:7)
+| | | InstantiateFunction (fooB, .\\b.h:3)
+| | | InstantiateFunction (fooMTA, .\\a.h:4)\n



C:\buildbot\as-builder-3\llvm-clang-x86_64-win-fast\llvm-project\clang\unittests\Support\TimeProfilerTest.cpp:278
Expected equality of these values:
  R"(
Frontend
| ParseFunctionDefinition (fooB)
| ParseFunctionDefinition (fooMTA)
| ParseFunctionDefinition (fooA)
| ParseDeclarationOrFunctionDefinition (test.cc:3:5)
| | ParseFunctionDefinition (user)
| PerformPendingInstantiations
| | InstantiateFunction (fooA, ./a.h:7)

```

>From 532a2f4a7405a37413fac10f772aa2d83c8d57a3 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Thu, 18 Jul 2024 19:47:06 +0200
Subject: [PATCH] =?UTF-8?q?Revert=20"Add=20source=20file=20name=20for=20te?=
 =?UTF-8?q?mplate=20instantiations=20in=20-ftime-trace=20(#98=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit cd495d2cdd84a22026a115c7e9923c27b196732e.
---
 a-abfdec1d.o.tmp  |   0
 clang/docs/ReleaseNotes.rst   |   3 -
 clang/include/clang/Driver/Options.td |   4 -
 .../include/clang/Frontend/FrontendOptions.h  |   8 +-
 clang/lib/Driver/ToolChains/Clang.cpp |   1 -
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  11 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  11 +-
 clang/test/Driver/ftime-trace-sections.cpp|   2 +-
 clang/test/Driver/ftime-trace.cpp |  39 +++---
 clang/tools/driver/cc1_main.cpp   |   3 +-
 clang/unittests/Support/TimeProfilerTest.cpp  | 121 --
 llvm/include/llvm/Support/TimeProfiler.h  |  23 +---
 llvm/lib/Support/TimeProfiler.cpp |  61 ++---
 13 files changed, 64 insertions(+), 223 deletions(-)
 delete mode 100644 a-abfdec1d.o.tmp

diff --git a/a-abfdec1d.o.tmp b/a-abfdec1d.o.tmp
deleted file mode 100644
index e69de29bb2d1d..0
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 971df672b6ca1..e0e86af257a19 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -736,9 +736,6 @@ Improvements to Clang's time-trace
 - Clang now specifies that using ``auto`` in a lambda parameter is a C++14 
extension when
   appropriate. (`#46059: 
`_).
 
-- Clang now adds source file infomation for template instantiations as 
``event["args"]["filename"]``. This
-  added behind an option ``-ftime-trace-verbose``. This is expected to 
increase the size of trace by 2-3 

[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-18 Thread Utkarsh Saxena via cfe-commits

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


[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-18 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/98320

>From 03cc5fbebaf0c0c737e9304b8b3310ab4908fcaa Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 13:52:46 +
Subject: [PATCH 01/15] Add an option to add source file info to -ftime-trace

---
 clang/include/clang/Driver/Options.td  | 4 
 clang/include/clang/Frontend/FrontendOptions.h | 3 +++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 2 ++
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 ++
 4 files changed, 11 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index be7c3b60c20f1..c15f1b57bafc9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,6 +3989,10 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
+def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
+  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
+  Visibility<[ClangOption, CLOption, DXCOption]>;
+  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 5e5034fe01eb5..019a6737f8129 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -583,6 +583,9 @@ class FrontendOptions {
   /// Path which stores the output files for -ftime-trace
   std::string TimeTracePath;
 
+  /// Adds filename to event details wherever supported
+  bool TimeTraceAddFilename = false;
+
   /// Output Path for module output file.
   std::string ModuleOutputPath;
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index a7bc6749c5852..f0fa7fd427906 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3430,6 +3430,8 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
 /*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Instantiation->getLocation());
 return Name;
   });
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 88f6af80cbc55..ba55db4117c34 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4966,6 +4966,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Function->getNameForDiagnostic(OS, getPrintingPolicy(),
/*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Function->getLocation());
 return Name;
   });
 

>From ae991f8c88c21a0872a5fa63219b3cb9b2787d9a Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 15:52:55 +
Subject: [PATCH 02/15] Add tests

---
 clang/include/clang/Driver/Options.td  |  4 
 clang/include/clang/Frontend/FrontendOptions.h |  3 ---
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  3 +--
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp |  3 +--
 clang/test/Driver/ftime-trace-sections.py  | 16 +++-
 5 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c15f1b57bafc9..be7c3b60c20f1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,10 +3989,6 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
-def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
-  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
-  Visibility<[ClangOption, CLOption, DXCOption]>;
-  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 

[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-18 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/98320

>From 03cc5fbebaf0c0c737e9304b8b3310ab4908fcaa Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 13:52:46 +
Subject: [PATCH 01/14] Add an option to add source file info to -ftime-trace

---
 clang/include/clang/Driver/Options.td  | 4 
 clang/include/clang/Frontend/FrontendOptions.h | 3 +++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 2 ++
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 ++
 4 files changed, 11 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index be7c3b60c20f1..c15f1b57bafc9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,6 +3989,10 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
+def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
+  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
+  Visibility<[ClangOption, CLOption, DXCOption]>;
+  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 5e5034fe01eb5..019a6737f8129 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -583,6 +583,9 @@ class FrontendOptions {
   /// Path which stores the output files for -ftime-trace
   std::string TimeTracePath;
 
+  /// Adds filename to event details wherever supported
+  bool TimeTraceAddFilename = false;
+
   /// Output Path for module output file.
   std::string ModuleOutputPath;
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index a7bc6749c5852..f0fa7fd427906 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3430,6 +3430,8 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
 /*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Instantiation->getLocation());
 return Name;
   });
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 88f6af80cbc55..ba55db4117c34 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4966,6 +4966,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Function->getNameForDiagnostic(OS, getPrintingPolicy(),
/*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Function->getLocation());
 return Name;
   });
 

>From ae991f8c88c21a0872a5fa63219b3cb9b2787d9a Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 15:52:55 +
Subject: [PATCH 02/14] Add tests

---
 clang/include/clang/Driver/Options.td  |  4 
 clang/include/clang/Frontend/FrontendOptions.h |  3 ---
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  3 +--
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp |  3 +--
 clang/test/Driver/ftime-trace-sections.py  | 16 +++-
 5 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c15f1b57bafc9..be7c3b60c20f1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,10 +3989,6 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
-def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
-  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
-  Visibility<[ClangOption, CLOption, DXCOption]>;
-  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 

[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-18 Thread Utkarsh Saxena via cfe-commits


@@ -3426,11 +3426,16 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 return true;
 
   llvm::TimeTraceScope TimeScope("InstantiateClass", [&]() {
-std::string Name;
-llvm::raw_string_ostream OS(Name);
+llvm::TimeTraceMetadata M;
+llvm::raw_string_ostream OS(M.Detail);
 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
 /*Qualified=*/true);
-return Name;
+if (llvm::isTimeTraceVerbose()) {

usx95 wrote:

Resolving duplicate comment.

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


[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-18 Thread Utkarsh Saxena via cfe-commits


@@ -38,14 +42,24 @@ std::string teardownProfiler() {
 
 // Returns true if code compiles successfully.
 // We only parse AST here. This is enough for constexpr evaluation.
-bool compileFromString(StringRef Code, StringRef Standard, StringRef FileName) 
{
+bool compileFromString(StringRef Code, StringRef Standard, StringRef File,
+   llvm::StringMap Headers = {}) {

usx95 wrote:

Done.

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


[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-18 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/98320

>From 03cc5fbebaf0c0c737e9304b8b3310ab4908fcaa Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 13:52:46 +
Subject: [PATCH 01/12] Add an option to add source file info to -ftime-trace

---
 clang/include/clang/Driver/Options.td  | 4 
 clang/include/clang/Frontend/FrontendOptions.h | 3 +++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 2 ++
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 ++
 4 files changed, 11 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index be7c3b60c20f1..c15f1b57bafc9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,6 +3989,10 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
+def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
+  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
+  Visibility<[ClangOption, CLOption, DXCOption]>;
+  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 5e5034fe01eb5..019a6737f8129 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -583,6 +583,9 @@ class FrontendOptions {
   /// Path which stores the output files for -ftime-trace
   std::string TimeTracePath;
 
+  /// Adds filename to event details wherever supported
+  bool TimeTraceAddFilename = false;
+
   /// Output Path for module output file.
   std::string ModuleOutputPath;
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index a7bc6749c5852..f0fa7fd427906 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3430,6 +3430,8 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
 /*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Instantiation->getLocation());
 return Name;
   });
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 88f6af80cbc55..ba55db4117c34 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4966,6 +4966,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Function->getNameForDiagnostic(OS, getPrintingPolicy(),
/*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Function->getLocation());
 return Name;
   });
 

>From ae991f8c88c21a0872a5fa63219b3cb9b2787d9a Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 15:52:55 +
Subject: [PATCH 02/12] Add tests

---
 clang/include/clang/Driver/Options.td  |  4 
 clang/include/clang/Frontend/FrontendOptions.h |  3 ---
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  3 +--
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp |  3 +--
 clang/test/Driver/ftime-trace-sections.py  | 16 +++-
 5 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c15f1b57bafc9..be7c3b60c20f1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,10 +3989,6 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
-def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
-  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
-  Visibility<[ClangOption, CLOption, DXCOption]>;
-  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 

[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-18 Thread Utkarsh Saxena via cfe-commits


@@ -60,39 +74,65 @@ bool compileFromString(StringRef Code, StringRef Standard, 
StringRef FileName) {
   return Compiler.ExecuteAction(Action);
 }
 
+std::string GetMetadata(json::Object *Event) {
+  std::string Metadata = "";
+  if (json::Object *Args = Event->getObject("args")) {
+if (StringRef Detail = Args->getString("detail").value_or("");
+!Detail.empty())
+  Metadata += Detail.str();
+if (StringRef File = Args->getString("filename").value_or("");
+!File.empty())
+  Metadata += ", " + File.str();
+  }
+  return Metadata;
+}
+
 // Returns pretty-printed trace graph.
 std::string buildTraceGraph(StringRef Json) {
   struct EventRecord {
 int64_t TimestampBegin;
 int64_t TimestampEnd;
-StringRef Name;
-StringRef Detail;
+std::string Name;
+std::string Metadata;
   };
   std::vector Events;
 
   // Parse `EventRecord`s from JSON dump.
   Expected Root = json::parse(Json);
   if (!Root)
 return "";
+  std::stack SourceEvents;
   for (json::Value  :
*Root->getAsObject()->getArray("traceEvents")) {
 json::Object *TraceEventObj = TraceEventValue.getAsObject();
 
 int64_t TimestampBegin = TraceEventObj->getInteger("ts").value_or(0);
 int64_t TimestampEnd =
 TimestampBegin + TraceEventObj->getInteger("dur").value_or(0);
-StringRef Name = TraceEventObj->getString("name").value_or("");
-StringRef Detail = "";
-if (json::Object *Args = TraceEventObj->getObject("args"))
-  Detail = Args->getString("detail").value_or("");
+std::string Name = TraceEventObj->getString("name").value_or("").str();
+std::string Metadata = GetMetadata(TraceEventObj);
+
+if (Name == "Source") {

usx95 wrote:

As discussed offline, these are due to new headers which are added to the 
tests. 
Decided to ignore Source events as they are not 100% accurate because of being 
async.

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


[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-17 Thread Utkarsh Saxena via cfe-commits


@@ -83,16 +83,27 @@ namespace llvm {
 
 class raw_pwrite_stream;
 
+struct TimeTraceMetadata {

usx95 wrote:

Done.

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


[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-17 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/98320

>From 03cc5fbebaf0c0c737e9304b8b3310ab4908fcaa Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 13:52:46 +
Subject: [PATCH 01/11] Add an option to add source file info to -ftime-trace

---
 clang/include/clang/Driver/Options.td  | 4 
 clang/include/clang/Frontend/FrontendOptions.h | 3 +++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 2 ++
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 ++
 4 files changed, 11 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index be7c3b60c20f1..c15f1b57bafc9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,6 +3989,10 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
+def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
+  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
+  Visibility<[ClangOption, CLOption, DXCOption]>;
+  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 5e5034fe01eb5..019a6737f8129 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -583,6 +583,9 @@ class FrontendOptions {
   /// Path which stores the output files for -ftime-trace
   std::string TimeTracePath;
 
+  /// Adds filename to event details wherever supported
+  bool TimeTraceAddFilename = false;
+
   /// Output Path for module output file.
   std::string ModuleOutputPath;
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index a7bc6749c5852..f0fa7fd427906 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3430,6 +3430,8 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
 /*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Instantiation->getLocation());
 return Name;
   });
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 88f6af80cbc55..ba55db4117c34 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4966,6 +4966,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Function->getNameForDiagnostic(OS, getPrintingPolicy(),
/*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Function->getLocation());
 return Name;
   });
 

>From ae991f8c88c21a0872a5fa63219b3cb9b2787d9a Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 15:52:55 +
Subject: [PATCH 02/11] Add tests

---
 clang/include/clang/Driver/Options.td  |  4 
 clang/include/clang/Frontend/FrontendOptions.h |  3 ---
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  3 +--
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp |  3 +--
 clang/test/Driver/ftime-trace-sections.py  | 16 +++-
 5 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c15f1b57bafc9..be7c3b60c20f1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,10 +3989,6 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
-def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
-  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
-  Visibility<[ClangOption, CLOption, DXCOption]>;
-  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 

[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-17 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/98320

>From 03cc5fbebaf0c0c737e9304b8b3310ab4908fcaa Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 13:52:46 +
Subject: [PATCH 01/10] Add an option to add source file info to -ftime-trace

---
 clang/include/clang/Driver/Options.td  | 4 
 clang/include/clang/Frontend/FrontendOptions.h | 3 +++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 2 ++
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 ++
 4 files changed, 11 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index be7c3b60c20f1..c15f1b57bafc9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,6 +3989,10 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
+def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
+  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
+  Visibility<[ClangOption, CLOption, DXCOption]>;
+  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 5e5034fe01eb5..019a6737f8129 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -583,6 +583,9 @@ class FrontendOptions {
   /// Path which stores the output files for -ftime-trace
   std::string TimeTracePath;
 
+  /// Adds filename to event details wherever supported
+  bool TimeTraceAddFilename = false;
+
   /// Output Path for module output file.
   std::string ModuleOutputPath;
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index a7bc6749c5852..f0fa7fd427906 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3430,6 +3430,8 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
 /*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Instantiation->getLocation());
 return Name;
   });
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 88f6af80cbc55..ba55db4117c34 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4966,6 +4966,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Function->getNameForDiagnostic(OS, getPrintingPolicy(),
/*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Function->getLocation());
 return Name;
   });
 

>From ae991f8c88c21a0872a5fa63219b3cb9b2787d9a Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 15:52:55 +
Subject: [PATCH 02/10] Add tests

---
 clang/include/clang/Driver/Options.td  |  4 
 clang/include/clang/Frontend/FrontendOptions.h |  3 ---
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  3 +--
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp |  3 +--
 clang/test/Driver/ftime-trace-sections.py  | 16 +++-
 5 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c15f1b57bafc9..be7c3b60c20f1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,10 +3989,6 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
-def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
-  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
-  Visibility<[ClangOption, CLOption, DXCOption]>;
-  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 

[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-17 Thread Utkarsh Saxena via cfe-commits


@@ -83,16 +83,27 @@ namespace llvm {
 
 class raw_pwrite_stream;
 
+struct TimeTraceMetadata {
+  std::string Detail;
+  // Source file information for the event.
+  std::string Filename;

usx95 wrote:

Done.

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


[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-17 Thread Utkarsh Saxena via cfe-commits


@@ -60,39 +74,65 @@ bool compileFromString(StringRef Code, StringRef Standard, 
StringRef FileName) {
   return Compiler.ExecuteAction(Action);
 }
 
+std::string GetMetadata(json::Object *Event) {
+  std::string Metadata = "";
+  if (json::Object *Args = Event->getObject("args")) {
+if (StringRef Detail = Args->getString("detail").value_or("");
+!Detail.empty())
+  Metadata += Detail.str();
+if (StringRef File = Args->getString("filename").value_or("");
+!File.empty())
+  Metadata += ", " + File.str();
+  }
+  return Metadata;
+}
+
 // Returns pretty-printed trace graph.
 std::string buildTraceGraph(StringRef Json) {
   struct EventRecord {
 int64_t TimestampBegin;
 int64_t TimestampEnd;
-StringRef Name;
-StringRef Detail;
+std::string Name;
+std::string Metadata;
   };
   std::vector Events;
 
   // Parse `EventRecord`s from JSON dump.
   Expected Root = json::parse(Json);
   if (!Root)
 return "";
+  std::stack SourceEvents;
   for (json::Value  :
*Root->getAsObject()->getArray("traceEvents")) {
 json::Object *TraceEventObj = TraceEventValue.getAsObject();
 
 int64_t TimestampBegin = TraceEventObj->getInteger("ts").value_or(0);
 int64_t TimestampEnd =
 TimestampBegin + TraceEventObj->getInteger("dur").value_or(0);
-StringRef Name = TraceEventObj->getString("name").value_or("");
-StringRef Detail = "";
-if (json::Object *Args = TraceEventObj->getObject("args"))
-  Detail = Args->getString("detail").value_or("");
+std::string Name = TraceEventObj->getString("name").value_or("").str();
+std::string Metadata = GetMetadata(TraceEventObj);
+
+if (Name == "Source") {

usx95 wrote:

"Source" events are async "b", "e" events and do not have a duration attached. 
So we need to compute that separately.

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


[clang] [clang] Extend lifetime analysis to support assignments for pointer-like objects. (PR #99032)

2024-07-17 Thread Utkarsh Saxena via cfe-commits

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

LGTM. Thanks.

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


[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-17 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/98320

>From 03cc5fbebaf0c0c737e9304b8b3310ab4908fcaa Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 13:52:46 +
Subject: [PATCH 1/9] Add an option to add source file info to -ftime-trace

---
 clang/include/clang/Driver/Options.td  | 4 
 clang/include/clang/Frontend/FrontendOptions.h | 3 +++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 2 ++
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 ++
 4 files changed, 11 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index be7c3b60c20f1..c15f1b57bafc9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,6 +3989,10 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
+def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
+  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
+  Visibility<[ClangOption, CLOption, DXCOption]>;
+  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 5e5034fe01eb5..019a6737f8129 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -583,6 +583,9 @@ class FrontendOptions {
   /// Path which stores the output files for -ftime-trace
   std::string TimeTracePath;
 
+  /// Adds filename to event details wherever supported
+  bool TimeTraceAddFilename = false;
+
   /// Output Path for module output file.
   std::string ModuleOutputPath;
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index a7bc6749c5852..f0fa7fd427906 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3430,6 +3430,8 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
 /*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Instantiation->getLocation());
 return Name;
   });
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 88f6af80cbc55..ba55db4117c34 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4966,6 +4966,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Function->getNameForDiagnostic(OS, getPrintingPolicy(),
/*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Function->getLocation());
 return Name;
   });
 

>From ae991f8c88c21a0872a5fa63219b3cb9b2787d9a Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 15:52:55 +
Subject: [PATCH 2/9] Add tests

---
 clang/include/clang/Driver/Options.td  |  4 
 clang/include/clang/Frontend/FrontendOptions.h |  3 ---
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  3 +--
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp |  3 +--
 clang/test/Driver/ftime-trace-sections.py  | 16 +++-
 5 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c15f1b57bafc9..be7c3b60c20f1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,10 +3989,6 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
-def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
-  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
-  Visibility<[ClangOption, CLOption, DXCOption]>;
-  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 

[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-17 Thread Utkarsh Saxena via cfe-commits


@@ -3430,6 +3430,7 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
 /*Qualified=*/true);
+OS << ", file:" << SourceMgr.getFilename(Instantiation->getLocation());

usx95 wrote:

Done.

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


[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-17 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/98320

>From 03cc5fbebaf0c0c737e9304b8b3310ab4908fcaa Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 13:52:46 +
Subject: [PATCH 1/8] Add an option to add source file info to -ftime-trace

---
 clang/include/clang/Driver/Options.td  | 4 
 clang/include/clang/Frontend/FrontendOptions.h | 3 +++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 2 ++
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 ++
 4 files changed, 11 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index be7c3b60c20f1..c15f1b57bafc9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,6 +3989,10 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
+def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
+  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
+  Visibility<[ClangOption, CLOption, DXCOption]>;
+  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 5e5034fe01eb5..019a6737f8129 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -583,6 +583,9 @@ class FrontendOptions {
   /// Path which stores the output files for -ftime-trace
   std::string TimeTracePath;
 
+  /// Adds filename to event details wherever supported
+  bool TimeTraceAddFilename = false;
+
   /// Output Path for module output file.
   std::string ModuleOutputPath;
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index a7bc6749c5852..f0fa7fd427906 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3430,6 +3430,8 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
 /*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Instantiation->getLocation());
 return Name;
   });
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 88f6af80cbc55..ba55db4117c34 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4966,6 +4966,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Function->getNameForDiagnostic(OS, getPrintingPolicy(),
/*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Function->getLocation());
 return Name;
   });
 

>From ae991f8c88c21a0872a5fa63219b3cb9b2787d9a Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 15:52:55 +
Subject: [PATCH 2/8] Add tests

---
 clang/include/clang/Driver/Options.td  |  4 
 clang/include/clang/Frontend/FrontendOptions.h |  3 ---
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  3 +--
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp |  3 +--
 clang/test/Driver/ftime-trace-sections.py  | 16 +++-
 5 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c15f1b57bafc9..be7c3b60c20f1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,10 +3989,6 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
-def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
-  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
-  Visibility<[ClangOption, CLOption, DXCOption]>;
-  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 

[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-17 Thread Utkarsh Saxena via cfe-commits


@@ -3430,6 +3430,7 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);

usx95 wrote:

I think we can do this on a need basis. Most source actions (like Parse*) 
already have this information (although not structured). See the unit test for 
examples.

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


[clang] [clang] Extend lifetime analysis to support assignments for pointer-like objects. (PR #99032)

2024-07-16 Thread Utkarsh Saxena via cfe-commits


@@ -966,7 +969,8 @@ static bool pathOnlyInitializesGslPointer(IndirectLocalPath 
) {
 if (It.Kind == IndirectLocalPathEntry::LifetimeBoundCall)
   continue;
 return It.Kind == IndirectLocalPathEntry::GslPointerInit ||
-   It.Kind == IndirectLocalPathEntry::GslReferenceInit;
+   It.Kind == IndirectLocalPathEntry::GslReferenceInit ||

usx95 wrote:

nit: rename this function to `pathOnlyHandlesGslPointer` as it is not specific 
to initialisation.

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


[clang] [clang] Extend lifetime analysis to support assignments for pointer-like objects. (PR #99032)

2024-07-16 Thread Utkarsh Saxena via cfe-commits


@@ -966,7 +969,8 @@ static bool pathOnlyInitializesGslPointer(IndirectLocalPath 
) {
 if (It.Kind == IndirectLocalPathEntry::LifetimeBoundCall)

usx95 wrote:

nit: merge the first 3 `if` into a single one.  I feel it makes it clear that 
outcome is same for them.

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


[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-16 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/98320

>From 03cc5fbebaf0c0c737e9304b8b3310ab4908fcaa Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 13:52:46 +
Subject: [PATCH 1/7] Add an option to add source file info to -ftime-trace

---
 clang/include/clang/Driver/Options.td  | 4 
 clang/include/clang/Frontend/FrontendOptions.h | 3 +++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 2 ++
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 ++
 4 files changed, 11 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index be7c3b60c20f1..c15f1b57bafc9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,6 +3989,10 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
+def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
+  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
+  Visibility<[ClangOption, CLOption, DXCOption]>;
+  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 5e5034fe01eb5..019a6737f8129 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -583,6 +583,9 @@ class FrontendOptions {
   /// Path which stores the output files for -ftime-trace
   std::string TimeTracePath;
 
+  /// Adds filename to event details wherever supported
+  bool TimeTraceAddFilename = false;
+
   /// Output Path for module output file.
   std::string ModuleOutputPath;
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index a7bc6749c5852..f0fa7fd427906 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3430,6 +3430,8 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
 /*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Instantiation->getLocation());
 return Name;
   });
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 88f6af80cbc55..ba55db4117c34 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4966,6 +4966,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Function->getNameForDiagnostic(OS, getPrintingPolicy(),
/*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Function->getLocation());
 return Name;
   });
 

>From ae991f8c88c21a0872a5fa63219b3cb9b2787d9a Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 15:52:55 +
Subject: [PATCH 2/7] Add tests

---
 clang/include/clang/Driver/Options.td  |  4 
 clang/include/clang/Frontend/FrontendOptions.h |  3 ---
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  3 +--
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp |  3 +--
 clang/test/Driver/ftime-trace-sections.py  | 16 +++-
 5 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c15f1b57bafc9..be7c3b60c20f1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,10 +3989,6 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
-def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
-  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
-  Visibility<[ClangOption, CLOption, DXCOption]>;
-  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 

[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-16 Thread Utkarsh Saxena via cfe-commits


@@ -3430,6 +3430,7 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
 /*Qualified=*/true);
+OS << ", file:" << SourceMgr.getFilename(Instantiation->getLocation());

usx95 wrote:

Added it as a json parameter.

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


[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-16 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/98320

>From 03cc5fbebaf0c0c737e9304b8b3310ab4908fcaa Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 13:52:46 +
Subject: [PATCH 1/6] Add an option to add source file info to -ftime-trace

---
 clang/include/clang/Driver/Options.td  | 4 
 clang/include/clang/Frontend/FrontendOptions.h | 3 +++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 2 ++
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 ++
 4 files changed, 11 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index be7c3b60c20f1..c15f1b57bafc9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,6 +3989,10 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
+def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
+  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
+  Visibility<[ClangOption, CLOption, DXCOption]>;
+  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 5e5034fe01eb5..019a6737f8129 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -583,6 +583,9 @@ class FrontendOptions {
   /// Path which stores the output files for -ftime-trace
   std::string TimeTracePath;
 
+  /// Adds filename to event details wherever supported
+  bool TimeTraceAddFilename = false;
+
   /// Output Path for module output file.
   std::string ModuleOutputPath;
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index a7bc6749c5852..f0fa7fd427906 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3430,6 +3430,8 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
 /*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Instantiation->getLocation());
 return Name;
   });
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 88f6af80cbc55..ba55db4117c34 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4966,6 +4966,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Function->getNameForDiagnostic(OS, getPrintingPolicy(),
/*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Function->getLocation());
 return Name;
   });
 

>From ae991f8c88c21a0872a5fa63219b3cb9b2787d9a Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 15:52:55 +
Subject: [PATCH 2/6] Add tests

---
 clang/include/clang/Driver/Options.td  |  4 
 clang/include/clang/Frontend/FrontendOptions.h |  3 ---
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  3 +--
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp |  3 +--
 clang/test/Driver/ftime-trace-sections.py  | 16 +++-
 5 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c15f1b57bafc9..be7c3b60c20f1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,10 +3989,6 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
-def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
-  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
-  Visibility<[ClangOption, CLOption, DXCOption]>;
-  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 

[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-16 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/98320

>From 03cc5fbebaf0c0c737e9304b8b3310ab4908fcaa Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 13:52:46 +
Subject: [PATCH 1/6] Add an option to add source file info to -ftime-trace

---
 clang/include/clang/Driver/Options.td  | 4 
 clang/include/clang/Frontend/FrontendOptions.h | 3 +++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 2 ++
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 ++
 4 files changed, 11 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index be7c3b60c20f1..c15f1b57bafc9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,6 +3989,10 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
+def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
+  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
+  Visibility<[ClangOption, CLOption, DXCOption]>;
+  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 5e5034fe01eb5..019a6737f8129 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -583,6 +583,9 @@ class FrontendOptions {
   /// Path which stores the output files for -ftime-trace
   std::string TimeTracePath;
 
+  /// Adds filename to event details wherever supported
+  bool TimeTraceAddFilename = false;
+
   /// Output Path for module output file.
   std::string ModuleOutputPath;
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index a7bc6749c5852..f0fa7fd427906 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3430,6 +3430,8 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
 /*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Instantiation->getLocation());
 return Name;
   });
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 88f6af80cbc55..ba55db4117c34 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4966,6 +4966,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Function->getNameForDiagnostic(OS, getPrintingPolicy(),
/*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Function->getLocation());
 return Name;
   });
 

>From ae991f8c88c21a0872a5fa63219b3cb9b2787d9a Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 15:52:55 +
Subject: [PATCH 2/6] Add tests

---
 clang/include/clang/Driver/Options.td  |  4 
 clang/include/clang/Frontend/FrontendOptions.h |  3 ---
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  3 +--
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp |  3 +--
 clang/test/Driver/ftime-trace-sections.py  | 16 +++-
 5 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c15f1b57bafc9..be7c3b60c20f1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,10 +3989,6 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
-def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
-  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
-  Visibility<[ClangOption, CLOption, DXCOption]>;
-  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 

[clang] [llvm] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-16 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/98320

>From 03cc5fbebaf0c0c737e9304b8b3310ab4908fcaa Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 13:52:46 +
Subject: [PATCH 1/5] Add an option to add source file info to -ftime-trace

---
 clang/include/clang/Driver/Options.td  | 4 
 clang/include/clang/Frontend/FrontendOptions.h | 3 +++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 2 ++
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 ++
 4 files changed, 11 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index be7c3b60c20f1..c15f1b57bafc9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,6 +3989,10 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
+def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
+  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
+  Visibility<[ClangOption, CLOption, DXCOption]>;
+  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 5e5034fe01eb5..019a6737f8129 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -583,6 +583,9 @@ class FrontendOptions {
   /// Path which stores the output files for -ftime-trace
   std::string TimeTracePath;
 
+  /// Adds filename to event details wherever supported
+  bool TimeTraceAddFilename = false;
+
   /// Output Path for module output file.
   std::string ModuleOutputPath;
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index a7bc6749c5852..f0fa7fd427906 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3430,6 +3430,8 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
 /*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Instantiation->getLocation());
 return Name;
   });
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 88f6af80cbc55..ba55db4117c34 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4966,6 +4966,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Function->getNameForDiagnostic(OS, getPrintingPolicy(),
/*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Function->getLocation());
 return Name;
   });
 

>From ae991f8c88c21a0872a5fa63219b3cb9b2787d9a Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 15:52:55 +
Subject: [PATCH 2/5] Add tests

---
 clang/include/clang/Driver/Options.td  |  4 
 clang/include/clang/Frontend/FrontendOptions.h |  3 ---
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  3 +--
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp |  3 +--
 clang/test/Driver/ftime-trace-sections.py  | 16 +++-
 5 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c15f1b57bafc9..be7c3b60c20f1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,10 +3989,6 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
-def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
-  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
-  Visibility<[ClangOption, CLOption, DXCOption]>;
-  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 

[clang] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-10 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/98320

>From 03cc5fbebaf0c0c737e9304b8b3310ab4908fcaa Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 13:52:46 +
Subject: [PATCH 1/4] Add an option to add source file info to -ftime-trace

---
 clang/include/clang/Driver/Options.td  | 4 
 clang/include/clang/Frontend/FrontendOptions.h | 3 +++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 2 ++
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 ++
 4 files changed, 11 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index be7c3b60c20f1..c15f1b57bafc9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,6 +3989,10 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
+def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
+  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
+  Visibility<[ClangOption, CLOption, DXCOption]>;
+  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 5e5034fe01eb5..019a6737f8129 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -583,6 +583,9 @@ class FrontendOptions {
   /// Path which stores the output files for -ftime-trace
   std::string TimeTracePath;
 
+  /// Adds filename to event details wherever supported
+  bool TimeTraceAddFilename = false;
+
   /// Output Path for module output file.
   std::string ModuleOutputPath;
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index a7bc6749c5852..f0fa7fd427906 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3430,6 +3430,8 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
 /*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Instantiation->getLocation());
 return Name;
   });
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 88f6af80cbc55..ba55db4117c34 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4966,6 +4966,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Function->getNameForDiagnostic(OS, getPrintingPolicy(),
/*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Function->getLocation());
 return Name;
   });
 

>From ae991f8c88c21a0872a5fa63219b3cb9b2787d9a Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 15:52:55 +
Subject: [PATCH 2/4] Add tests

---
 clang/include/clang/Driver/Options.td  |  4 
 clang/include/clang/Frontend/FrontendOptions.h |  3 ---
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  3 +--
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp |  3 +--
 clang/test/Driver/ftime-trace-sections.py  | 16 +++-
 5 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c15f1b57bafc9..be7c3b60c20f1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,10 +3989,6 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
-def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
-  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
-  Visibility<[ClangOption, CLOption, DXCOption]>;
-  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 

[clang] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-10 Thread Utkarsh Saxena via cfe-commits

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


[clang] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-10 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/98320

>From 03cc5fbebaf0c0c737e9304b8b3310ab4908fcaa Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 13:52:46 +
Subject: [PATCH 1/3] Add an option to add source file info to -ftime-trace

---
 clang/include/clang/Driver/Options.td  | 4 
 clang/include/clang/Frontend/FrontendOptions.h | 3 +++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 2 ++
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 ++
 4 files changed, 11 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index be7c3b60c20f1..c15f1b57bafc9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,6 +3989,10 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
+def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
+  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
+  Visibility<[ClangOption, CLOption, DXCOption]>;
+  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 5e5034fe01eb5..019a6737f8129 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -583,6 +583,9 @@ class FrontendOptions {
   /// Path which stores the output files for -ftime-trace
   std::string TimeTracePath;
 
+  /// Adds filename to event details wherever supported
+  bool TimeTraceAddFilename = false;
+
   /// Output Path for module output file.
   std::string ModuleOutputPath;
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index a7bc6749c5852..f0fa7fd427906 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3430,6 +3430,8 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
 /*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Instantiation->getLocation());
 return Name;
   });
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 88f6af80cbc55..ba55db4117c34 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4966,6 +4966,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Function->getNameForDiagnostic(OS, getPrintingPolicy(),
/*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Function->getLocation());
 return Name;
   });
 

>From ae991f8c88c21a0872a5fa63219b3cb9b2787d9a Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 15:52:55 +
Subject: [PATCH 2/3] Add tests

---
 clang/include/clang/Driver/Options.td  |  4 
 clang/include/clang/Frontend/FrontendOptions.h |  3 ---
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  3 +--
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp |  3 +--
 clang/test/Driver/ftime-trace-sections.py  | 16 +++-
 5 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c15f1b57bafc9..be7c3b60c20f1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,10 +3989,6 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
-def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
-  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
-  Visibility<[ClangOption, CLOption, DXCOption]>;
-  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 

[clang] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-10 Thread Utkarsh Saxena via cfe-commits

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


[clang] Add source file name for template instantiations in -ftime-trace (PR #98320)

2024-07-10 Thread Utkarsh Saxena via cfe-commits

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


[clang] Add an option to add source file info to -ftime-trace (PR #98320)

2024-07-10 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/98320

>From 03cc5fbebaf0c0c737e9304b8b3310ab4908fcaa Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 13:52:46 +
Subject: [PATCH 1/2] Add an option to add source file info to -ftime-trace

---
 clang/include/clang/Driver/Options.td  | 4 
 clang/include/clang/Frontend/FrontendOptions.h | 3 +++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 2 ++
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 ++
 4 files changed, 11 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index be7c3b60c20f1..c15f1b57bafc9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,6 +3989,10 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
+def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
+  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
+  Visibility<[ClangOption, CLOption, DXCOption]>;
+  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 5e5034fe01eb5..019a6737f8129 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -583,6 +583,9 @@ class FrontendOptions {
   /// Path which stores the output files for -ftime-trace
   std::string TimeTracePath;
 
+  /// Adds filename to event details wherever supported
+  bool TimeTraceAddFilename = false;
+
   /// Output Path for module output file.
   std::string ModuleOutputPath;
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index a7bc6749c5852..f0fa7fd427906 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3430,6 +3430,8 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
 /*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Instantiation->getLocation());
 return Name;
   });
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 88f6af80cbc55..ba55db4117c34 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4966,6 +4966,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Function->getNameForDiagnostic(OS, getPrintingPolicy(),
/*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Function->getLocation());
 return Name;
   });
 

>From ae991f8c88c21a0872a5fa63219b3cb9b2787d9a Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 15:52:55 +
Subject: [PATCH 2/2] Add tests

---
 clang/include/clang/Driver/Options.td  |  4 
 clang/include/clang/Frontend/FrontendOptions.h |  3 ---
 clang/lib/Sema/SemaTemplateInstantiate.cpp |  3 +--
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp |  3 +--
 clang/test/Driver/ftime-trace-sections.py  | 16 +++-
 5 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c15f1b57bafc9..be7c3b60c20f1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,10 +3989,6 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
-def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
-  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
-  Visibility<[ClangOption, CLOption, DXCOption]>;
-  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 

[clang] Add an option to add source file info to -ftime-trace (PR #98320)

2024-07-10 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 created https://github.com/llvm/llvm-project/pull/98320

None

>From 03cc5fbebaf0c0c737e9304b8b3310ab4908fcaa Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 10 Jul 2024 13:52:46 +
Subject: [PATCH] Add an option to add source file info to -ftime-trace

---
 clang/include/clang/Driver/Options.td  | 4 
 clang/include/clang/Frontend/FrontendOptions.h | 3 +++
 clang/lib/Sema/SemaTemplateInstantiate.cpp | 2 ++
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 ++
 4 files changed, 11 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index be7c3b60c20f1..c15f1b57bafc9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3989,6 +3989,10 @@ def ftime_trace_EQ : Joined<["-"], "ftime-trace=">, 
Group,
   HelpText<"Similar to -ftime-trace. Specify the JSON file or a directory 
which will contain the JSON file">,
   Visibility<[ClangOption, CC1Option, CLOption, DXCOption]>,
   MarshallingInfoString>;
+def ftime_trace_add_filename : Flag<["-"], "ftime-trace-add-filename">, 
Group,
+  HelpText<"Adds filename to event details wherever supported. Eg: For 
template instantiation A, details would include A@source_file.h.">,
+  Visibility<[ClangOption, CLOption, DXCOption]>;
+  MarshallingInfoString>;
 def fproc_stat_report : Joined<["-"], "fproc-stat-report">, Group,
   HelpText<"Print subprocess statistics">;
 def fproc_stat_report_EQ : Joined<["-"], "fproc-stat-report=">, Group,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 5e5034fe01eb5..019a6737f8129 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -583,6 +583,9 @@ class FrontendOptions {
   /// Path which stores the output files for -ftime-trace
   std::string TimeTracePath;
 
+  /// Adds filename to event details wherever supported
+  bool TimeTraceAddFilename = false;
+
   /// Output Path for module output file.
   std::string ModuleOutputPath;
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index a7bc6749c5852..f0fa7fd427906 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3430,6 +3430,8 @@ Sema::InstantiateClass(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Instantiation->getNameForDiagnostic(OS, getPrintingPolicy(),
 /*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Instantiation->getLocation());
 return Name;
   });
 
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 88f6af80cbc55..ba55db4117c34 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4966,6 +4966,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
 llvm::raw_string_ostream OS(Name);
 Function->getNameForDiagnostic(OS, getPrintingPolicy(),
/*Qualified=*/true);
+if (llvm::timeTraceAddFilename())
+  OS << "@" << SourceMgr.getFilename(Function->getLocation());
 return Name;
   });
 

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


[clang] [clang] Don't emit the warn_dangling_lifetime_pointer diagnostic for the assignment case. (PR #97408)

2024-07-02 Thread Utkarsh Saxena via cfe-commits

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

Thanks. LGTM.

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


[clang] [clang] Don't emit the warn_dangling_lifetime_pointer diagnostic for the assignment case. (PR #97408)

2024-07-02 Thread Utkarsh Saxena via cfe-commits


@@ -0,0 +1,15 @@
+
+// RUN: %clang_cc1 -std=c++20 -verify -Wno-dangling-assignment %s

usx95 wrote:

I would suggest dropping `-Wno-dangling-assignment` and ensuring that we get 
"only" the dangling assignment and not GSL ones.
This would also not need a new file.

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


[clang] [clang] Don't emit the warn_dangling_lifetime_pointer diagnostic for the assignment case. (PR #97408)

2024-07-02 Thread Utkarsh Saxena via cfe-commits


@@ -1023,7 +1023,7 @@ static void checkExprLifetimeImpl(Sema ,
 return false;
   }
 
-  if (IsGslPtrInitWithGslTempOwner && DiagLoc.isValid()) {
+  if (InitEntity && IsGslPtrInitWithGslTempOwner && DiagLoc.isValid()) {

usx95 wrote:

I think it would be simpler to just handle `AEntity` before:
```cpp
if(AEntity) {
  assert(shouldLifetimeExtendThroughPath(Path) == PathLifetimeKind::NoExtend);
  assert(LK == LK_Extended);
  if (!pathContainsInit(path)) {
SemaRef.Diag(DiagLoc, diag::warn_dangling_pointer_assignment)
  << AEntity->LHS << DiagRange;
  }
  return;
}
assert(InitEntity);
switch (LK) {
...

```

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


[clang] [Clang] Extend lifetime bound analysis to support assignments (PR #96475)

2024-06-28 Thread Utkarsh Saxena via cfe-commits

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

Thanks. LGTM.

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


[clang] [Clang] Extend lifetime bound analysis to support assignments (PR #96475)

2024-06-28 Thread Utkarsh Saxena via cfe-commits


@@ -1028,6 +1045,7 @@ void checkExprLifetime(Sema , const 
InitializedEntity ,
 
   switch (shouldLifetimeExtendThroughPath(Path)) {
   case PathLifetimeKind::Extend:
+assert(InitEntity && "Expect only on initializing the entity");

usx95 wrote:

Maybe make it clearer that we do not expect lifetime extension for assignment:
 "Lifetime extension should happen only for initialization and not assigment". 
Same below.

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


[clang] [Clang] Extend lifetime bound analysis to support assignments (PR #96475)

2024-06-28 Thread Utkarsh Saxena via cfe-commits

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


[clang] [Clang] Extend lifetime bound analysis to support assignments (PR #96475)

2024-06-28 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 commented:

You can also add "Fixes: https://github.com/llvm/llvm-project/issues/54492; to 
description to close this bug as this only asks for pointer type support

Please also add release notes.

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


[clang] [Clang] Extend lifetime bound analysis to support assignments (PR #96475)

2024-06-27 Thread Utkarsh Saxena via cfe-commits


@@ -964,11 +966,26 @@ static bool 
pathOnlyInitializesGslPointer(IndirectLocalPath ) {
   return false;
 }
 
-void checkExprLifetime(Sema , const InitializedEntity ,
+void checkExprLifetime(Sema , const CheckingEntity ,
Expr *Init) {
-  LifetimeResult LR = getEntityLifetime();
-  LifetimeKind LK = LR.getInt();
-  const InitializedEntity *ExtendingEntity = LR.getPointer();
+  LifetimeKind LK = LK_FullExpression;
+
+  const AssignedEntity *AEntity = nullptr;
+  // Local variables for initialized entity.
+  const InitializedEntity *InitEntity = nullptr;
+  const InitializedEntity *ExtendingEntity = nullptr;
+  if (auto IEntityP = std::get_if()) {
+InitEntity = *IEntityP;
+auto LTResult = getEntityLifetime(InitEntity);
+LK = LTResult.getInt();
+ExtendingEntity = LTResult.getPointer();
+  } else if (auto AEntityP = std::get_if()) {
+AEntity = *AEntityP;
+if (AEntity->LHS->getType()->isPointerType()) // builtin pointer type
+  LK = LK_Extended;
+  } else {
+llvm_unreachable("unexpected kind");
+  }
 
   // If this entity doesn't have an interesting lifetime, don't bother looking
   // for temporaries within its initializer.

usx95 wrote:

Another good refactoring would be to make `TemporaryVisitor`, 
`visitLocalsRetainedByReferenceBinding`, `visitLocalsRetainedByInitializer` as 
member functions of a separate class, say, `CheckLifetimeVisitor`. There share 
a lot of data like `IndirectLocalPath `, `LocalVisitor Visit`. `Path` and 
`LocalVisitor` could be member var and member function respectively.

(This is again not relevant and could be a separate patch).

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


[clang] [Clang] Extend lifetime bound analysis to support assignments (PR #96475)

2024-06-27 Thread Utkarsh Saxena via cfe-commits


@@ -1053,16 +1072,23 @@ void checkExprLifetime(Sema , const 
InitializedEntity ,
 if (pathContainsInit(Path))
   return false;
 
-SemaRef.Diag(DiagLoc, diag::warn_dangling_variable)
-<< RK << !Entity.getParent()
-<< ExtendingEntity->getDecl()->isImplicit()
-<< ExtendingEntity->getDecl() << Init->isGLValue() << DiagRange;
+if (InitEntity) {
+  SemaRef.Diag(DiagLoc, diag::warn_dangling_variable)
+  << RK << !InitEntity->getParent()
+  << ExtendingEntity->getDecl()->isImplicit()
+  << ExtendingEntity->getDecl() << Init->isGLValue() << DiagRange;
+} else {
+  SemaRef.Diag(DiagLoc, diag::warn_dangling_pointer_assignment)
+  << AEntity->LHS << DiagRange;
+}
 break;
   }
   break;
 }
 
 case LK_MemInitializer: {
+  assert(InitEntity && "Expect only on initializing the entity");
+

usx95 wrote:

nit: Replace uses of `isa(L)` with already computed 
`MTE`.
Feel free to do this in a separate patch since this is not related.

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


[clang] [Clang] Extend lifetime bound analysis to support assignments (PR #96475)

2024-06-27 Thread Utkarsh Saxena via cfe-commits


@@ -40,6 +40,12 @@ namespace usage_ok {
   int *p = A().class_member(); // expected-warning {{temporary whose address 
is used as value of local variable 'p' will be destroyed at the end of the 
full-expression}}
   int *q = A(); // expected-warning {{temporary whose address is used as value 
of local variable 'q' will be destroyed at the end of the full-expression}}
   int *r = A(1); // expected-warning {{temporary whose address is used as 
value of local variable 'r' will be destroyed at the end of the 
full-expression}}
+
+  void test_assignment() {

usx95 wrote:

I found a minor case where this does not mirror initialization
```cpp
int *get(const int  [[clang::lifetimebound]]);
void foo() {
  int *y = {get(1)}; // warning as expected.
  y = {get(1)}; // no warning.
}
```
This does not look like a commonly occurring pattern but I would be curious why 
this misbehaves. 

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


[clang] [SourceManager] Expose max usage of source location space as a Statistic (PR #96292)

2024-06-24 Thread Utkarsh Saxena via cfe-commits

usx95 wrote:

This is a simple enough patch, so I agree we can deal with concerns post-commit 
as well. Let's go ahead with landing this then.

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


[clang] [SourceManager] Expose max usage of source location space as a Statistic (PR #96292)

2024-06-24 Thread Utkarsh Saxena via cfe-commits


@@ -46,6 +47,12 @@ using namespace clang;
 using namespace SrcMgr;
 using llvm::MemoryBuffer;
 
+#define DEBUG_TYPE "source-manager"
+
+STATISTIC(
+MaxUsedSLocBytes,
+"Maximum number of bytes used by source locations (both loaded and 
local)");

usx95 wrote:

nit: It may also be helpful to add some background on why this is important to 
track.

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


[clang] [SourceManager] Expose max usage of source location space as a Statistic (PR #96292)

2024-06-24 Thread Utkarsh Saxena via cfe-commits

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


[clang] [SourceManager] Expose max usage of source location space as a Statistic (PR #96292)

2024-06-24 Thread Utkarsh Saxena via cfe-commits

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

LGTM. 
Please wait a couple of days before landing to give a chance to other folks for 
reviewing.

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


[clang] [clang-tools-extra] [clangd] Fix crash with null check for Token at Loc (PR #94528)

2024-06-07 Thread Utkarsh Saxena via cfe-commits

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


[clang] [clang-tools-extra] [clangd] Fix crash with null check for Token at Loc (PR #94528)

2024-06-07 Thread Utkarsh Saxena via cfe-commits


@@ -447,7 +447,7 @@ class HighlightingsBuilder {
 if (!RLoc.isValid())
   return;
 
-const auto *RTok = TB.spelledTokenAt(RLoc);
+const auto *RTok = TB.spelledTokenContaining(RLoc);

usx95 wrote:

Done.

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


[clang] [clang-tools-extra] [clangd] Fix crash with null check for Token at Loc (PR #94528)

2024-06-07 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/94528

>From b13a663ae347649a3bcf9d6e381a5fbbfdc9ea4b Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 5 Jun 2024 19:48:48 +
Subject: [PATCH 1/6] [clangd] Fix crash with null check for Token at Loc

---
 clang-tools-extra/clangd/XRefs.cpp| 32 +++
 .../clangd/unittests/XRefsTests.cpp   | 14 +++-
 2 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/clang-tools-extra/clangd/XRefs.cpp 
b/clang-tools-extra/clangd/XRefs.cpp
index cd909266489a8..f52228e599591 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -1354,6 +1354,8 @@ maybeFindIncludeReferences(ParsedAST , Position Pos,
 
 ReferencesResult::Reference Result;
 const auto *Token = AST.getTokens().spelledTokenAt(Loc);
+if (!Token)
+  return;
 Result.Loc.range = Range{sourceLocToPosition(SM, Token->location()),
  sourceLocToPosition(SM, 
Token->endLocation())};
 Result.Loc.uri = URIMainFile;
@@ -2012,15 +2014,15 @@ static QualType typeForNode(const SelectionTree::Node 
*N) {
   return QualType();
 }
 
-// Given a type targeted by the cursor, return one or more types that are more 
interesting
-// to target.
-static void unwrapFindType(
-QualType T, const HeuristicResolver* H, llvm::SmallVector& Out) {
+// Given a type targeted by the cursor, return one or more types that are more
+// interesting to target.
+static void unwrapFindType(QualType T, const HeuristicResolver *H,
+   llvm::SmallVector ) {
   if (T.isNull())
 return;
 
   // If there's a specific type alias, point at that rather than unwrapping.
-  if (const auto* TDT = T->getAs())
+  if (const auto *TDT = T->getAs())
 return Out.push_back(QualType(TDT, 0));
 
   // Pointers etc => pointee type.
@@ -2044,17 +2046,18 @@ static void unwrapFindType(
 
   // For smart pointer types, add the underlying type
   if (H)
-if (const auto* PointeeType = 
H->getPointeeType(T.getNonReferenceType().getTypePtr())) {
-unwrapFindType(QualType(PointeeType, 0), H, Out);
-return Out.push_back(T);
+if (const auto *PointeeType =
+H->getPointeeType(T.getNonReferenceType().getTypePtr())) {
+  unwrapFindType(QualType(PointeeType, 0), H, Out);
+  return Out.push_back(T);
 }
 
   return Out.push_back(T);
 }
 
 // Convenience overload, to allow calling this without the out-parameter
-static llvm::SmallVector unwrapFindType(
-QualType T, const HeuristicResolver* H) {
+static llvm::SmallVector unwrapFindType(QualType T,
+  const HeuristicResolver *H) {
   llvm::SmallVector Result;
   unwrapFindType(T, H, Result);
   return Result;
@@ -2076,10 +2079,11 @@ std::vector findType(ParsedAST , 
Position Pos,
 std::vector LocatedSymbols;
 
 // NOTE: unwrapFindType might return duplicates for something like
-// unique_ptr>. Let's *not* remove them, because it gives 
you some
-// information about the type you may have not known before
-// (since unique_ptr> != unique_ptr).
-for (const QualType& Type : unwrapFindType(typeForNode(N), 
AST.getHeuristicResolver()))
+// unique_ptr>. Let's *not* remove them, because it gives you
+// some information about the type you may have not known before (since
+// unique_ptr> != unique_ptr).
+for (const QualType  :
+ unwrapFindType(typeForNode(N), AST.getHeuristicResolver()))
   llvm::copy(locateSymbolForType(AST, Type, Index),
  std::back_inserter(LocatedSymbols));
 
diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp 
b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index f53cbf01b7992..c4def624a2fcc 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -2358,7 +2358,14 @@ TEST(FindReferences, UsedSymbolsFromInclude) {
 
   R"cpp([[#in^clude ]]
 std::[[vector]] vec;
-  )cpp"};
+  )cpp",
+
+  R"cpp(
+[[#include ^"operator_qoutes.h"]]
+using ::operator_qoutes::[[operator]]"" _b;
+auto x = 1_b;
+  )cpp",
+  };
   for (const char *Test : Tests) {
 Annotations T(Test);
 auto TU = TestTU::withCode(T.code());
@@ -2375,6 +2382,11 @@ TEST(FindReferences, UsedSymbolsFromInclude) {
 class vector{};
   }
 )cpp");
+TU.AdditionalFiles["operator_qoutes.h"] = guard(R"cpp(
+  namespace operator_qoutes {
+bool operator"" _b(unsigned long long value);
+  }
+)cpp");
 TU.ExtraArgs.push_back("-isystem" + testPath("system"));
 
 auto AST = TU.build();

>From 3fe19589a332342abb069316224bdf9a6150c660 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 5 Jun 2024 19:59:44 +
Subject: [PATCH 2/6] remove unintentional format

---
 clang-tools-extra/clangd/XRefs.cpp | 30 

[clang] [clang-tools-extra] [clangd] Fix crash with null check for Token at Loc (PR #94528)

2024-06-06 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/94528

>From b13a663ae347649a3bcf9d6e381a5fbbfdc9ea4b Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 5 Jun 2024 19:48:48 +
Subject: [PATCH 1/5] [clangd] Fix crash with null check for Token at Loc

---
 clang-tools-extra/clangd/XRefs.cpp| 32 +++
 .../clangd/unittests/XRefsTests.cpp   | 14 +++-
 2 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/clang-tools-extra/clangd/XRefs.cpp 
b/clang-tools-extra/clangd/XRefs.cpp
index cd909266489a8..f52228e599591 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -1354,6 +1354,8 @@ maybeFindIncludeReferences(ParsedAST , Position Pos,
 
 ReferencesResult::Reference Result;
 const auto *Token = AST.getTokens().spelledTokenAt(Loc);
+if (!Token)
+  return;
 Result.Loc.range = Range{sourceLocToPosition(SM, Token->location()),
  sourceLocToPosition(SM, 
Token->endLocation())};
 Result.Loc.uri = URIMainFile;
@@ -2012,15 +2014,15 @@ static QualType typeForNode(const SelectionTree::Node 
*N) {
   return QualType();
 }
 
-// Given a type targeted by the cursor, return one or more types that are more 
interesting
-// to target.
-static void unwrapFindType(
-QualType T, const HeuristicResolver* H, llvm::SmallVector& Out) {
+// Given a type targeted by the cursor, return one or more types that are more
+// interesting to target.
+static void unwrapFindType(QualType T, const HeuristicResolver *H,
+   llvm::SmallVector ) {
   if (T.isNull())
 return;
 
   // If there's a specific type alias, point at that rather than unwrapping.
-  if (const auto* TDT = T->getAs())
+  if (const auto *TDT = T->getAs())
 return Out.push_back(QualType(TDT, 0));
 
   // Pointers etc => pointee type.
@@ -2044,17 +2046,18 @@ static void unwrapFindType(
 
   // For smart pointer types, add the underlying type
   if (H)
-if (const auto* PointeeType = 
H->getPointeeType(T.getNonReferenceType().getTypePtr())) {
-unwrapFindType(QualType(PointeeType, 0), H, Out);
-return Out.push_back(T);
+if (const auto *PointeeType =
+H->getPointeeType(T.getNonReferenceType().getTypePtr())) {
+  unwrapFindType(QualType(PointeeType, 0), H, Out);
+  return Out.push_back(T);
 }
 
   return Out.push_back(T);
 }
 
 // Convenience overload, to allow calling this without the out-parameter
-static llvm::SmallVector unwrapFindType(
-QualType T, const HeuristicResolver* H) {
+static llvm::SmallVector unwrapFindType(QualType T,
+  const HeuristicResolver *H) {
   llvm::SmallVector Result;
   unwrapFindType(T, H, Result);
   return Result;
@@ -2076,10 +2079,11 @@ std::vector findType(ParsedAST , 
Position Pos,
 std::vector LocatedSymbols;
 
 // NOTE: unwrapFindType might return duplicates for something like
-// unique_ptr>. Let's *not* remove them, because it gives 
you some
-// information about the type you may have not known before
-// (since unique_ptr> != unique_ptr).
-for (const QualType& Type : unwrapFindType(typeForNode(N), 
AST.getHeuristicResolver()))
+// unique_ptr>. Let's *not* remove them, because it gives you
+// some information about the type you may have not known before (since
+// unique_ptr> != unique_ptr).
+for (const QualType  :
+ unwrapFindType(typeForNode(N), AST.getHeuristicResolver()))
   llvm::copy(locateSymbolForType(AST, Type, Index),
  std::back_inserter(LocatedSymbols));
 
diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp 
b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index f53cbf01b7992..c4def624a2fcc 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -2358,7 +2358,14 @@ TEST(FindReferences, UsedSymbolsFromInclude) {
 
   R"cpp([[#in^clude ]]
 std::[[vector]] vec;
-  )cpp"};
+  )cpp",
+
+  R"cpp(
+[[#include ^"operator_qoutes.h"]]
+using ::operator_qoutes::[[operator]]"" _b;
+auto x = 1_b;
+  )cpp",
+  };
   for (const char *Test : Tests) {
 Annotations T(Test);
 auto TU = TestTU::withCode(T.code());
@@ -2375,6 +2382,11 @@ TEST(FindReferences, UsedSymbolsFromInclude) {
 class vector{};
   }
 )cpp");
+TU.AdditionalFiles["operator_qoutes.h"] = guard(R"cpp(
+  namespace operator_qoutes {
+bool operator"" _b(unsigned long long value);
+  }
+)cpp");
 TU.ExtraArgs.push_back("-isystem" + testPath("system"));
 
 auto AST = TU.build();

>From 3fe19589a332342abb069316224bdf9a6150c660 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 5 Jun 2024 19:59:44 +
Subject: [PATCH 2/5] remove unintentional format

---
 clang-tools-extra/clangd/XRefs.cpp | 30 

[clang] [clang-tools-extra] [clangd] Fix crash with null check for Token at Loc (PR #94528)

2024-06-06 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/94528

>From b13a663ae347649a3bcf9d6e381a5fbbfdc9ea4b Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 5 Jun 2024 19:48:48 +
Subject: [PATCH 1/4] [clangd] Fix crash with null check for Token at Loc

---
 clang-tools-extra/clangd/XRefs.cpp| 32 +++
 .../clangd/unittests/XRefsTests.cpp   | 14 +++-
 2 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/clang-tools-extra/clangd/XRefs.cpp 
b/clang-tools-extra/clangd/XRefs.cpp
index cd909266489a8..f52228e599591 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -1354,6 +1354,8 @@ maybeFindIncludeReferences(ParsedAST , Position Pos,
 
 ReferencesResult::Reference Result;
 const auto *Token = AST.getTokens().spelledTokenAt(Loc);
+if (!Token)
+  return;
 Result.Loc.range = Range{sourceLocToPosition(SM, Token->location()),
  sourceLocToPosition(SM, 
Token->endLocation())};
 Result.Loc.uri = URIMainFile;
@@ -2012,15 +2014,15 @@ static QualType typeForNode(const SelectionTree::Node 
*N) {
   return QualType();
 }
 
-// Given a type targeted by the cursor, return one or more types that are more 
interesting
-// to target.
-static void unwrapFindType(
-QualType T, const HeuristicResolver* H, llvm::SmallVector& Out) {
+// Given a type targeted by the cursor, return one or more types that are more
+// interesting to target.
+static void unwrapFindType(QualType T, const HeuristicResolver *H,
+   llvm::SmallVector ) {
   if (T.isNull())
 return;
 
   // If there's a specific type alias, point at that rather than unwrapping.
-  if (const auto* TDT = T->getAs())
+  if (const auto *TDT = T->getAs())
 return Out.push_back(QualType(TDT, 0));
 
   // Pointers etc => pointee type.
@@ -2044,17 +2046,18 @@ static void unwrapFindType(
 
   // For smart pointer types, add the underlying type
   if (H)
-if (const auto* PointeeType = 
H->getPointeeType(T.getNonReferenceType().getTypePtr())) {
-unwrapFindType(QualType(PointeeType, 0), H, Out);
-return Out.push_back(T);
+if (const auto *PointeeType =
+H->getPointeeType(T.getNonReferenceType().getTypePtr())) {
+  unwrapFindType(QualType(PointeeType, 0), H, Out);
+  return Out.push_back(T);
 }
 
   return Out.push_back(T);
 }
 
 // Convenience overload, to allow calling this without the out-parameter
-static llvm::SmallVector unwrapFindType(
-QualType T, const HeuristicResolver* H) {
+static llvm::SmallVector unwrapFindType(QualType T,
+  const HeuristicResolver *H) {
   llvm::SmallVector Result;
   unwrapFindType(T, H, Result);
   return Result;
@@ -2076,10 +2079,11 @@ std::vector findType(ParsedAST , 
Position Pos,
 std::vector LocatedSymbols;
 
 // NOTE: unwrapFindType might return duplicates for something like
-// unique_ptr>. Let's *not* remove them, because it gives 
you some
-// information about the type you may have not known before
-// (since unique_ptr> != unique_ptr).
-for (const QualType& Type : unwrapFindType(typeForNode(N), 
AST.getHeuristicResolver()))
+// unique_ptr>. Let's *not* remove them, because it gives you
+// some information about the type you may have not known before (since
+// unique_ptr> != unique_ptr).
+for (const QualType  :
+ unwrapFindType(typeForNode(N), AST.getHeuristicResolver()))
   llvm::copy(locateSymbolForType(AST, Type, Index),
  std::back_inserter(LocatedSymbols));
 
diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp 
b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index f53cbf01b7992..c4def624a2fcc 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -2358,7 +2358,14 @@ TEST(FindReferences, UsedSymbolsFromInclude) {
 
   R"cpp([[#in^clude ]]
 std::[[vector]] vec;
-  )cpp"};
+  )cpp",
+
+  R"cpp(
+[[#include ^"operator_qoutes.h"]]
+using ::operator_qoutes::[[operator]]"" _b;
+auto x = 1_b;
+  )cpp",
+  };
   for (const char *Test : Tests) {
 Annotations T(Test);
 auto TU = TestTU::withCode(T.code());
@@ -2375,6 +2382,11 @@ TEST(FindReferences, UsedSymbolsFromInclude) {
 class vector{};
   }
 )cpp");
+TU.AdditionalFiles["operator_qoutes.h"] = guard(R"cpp(
+  namespace operator_qoutes {
+bool operator"" _b(unsigned long long value);
+  }
+)cpp");
 TU.ExtraArgs.push_back("-isystem" + testPath("system"));
 
 auto AST = TU.build();

>From 3fe19589a332342abb069316224bdf9a6150c660 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 5 Jun 2024 19:59:44 +
Subject: [PATCH 2/4] remove unintentional format

---
 clang-tools-extra/clangd/XRefs.cpp | 30 

[clang] [clang-tools-extra] [clangd] Fix crash with null check for Token at Loc (PR #94528)

2024-06-06 Thread Utkarsh Saxena via cfe-commits


@@ -1354,6 +1354,8 @@ maybeFindIncludeReferences(ParsedAST , Position Pos,
 
 ReferencesResult::Reference Result;
 const auto *Token = AST.getTokens().spelledTokenAt(Loc);
+if (!Token)

usx95 wrote:

Done.
> also, what's the conclusion of investigation around don't really rely on 
> spelledTokenAt failing when it's called with a random offset into the token?

I relied on the tests here. Also, the usages of `spelledTokenCotaining` does 
not seem to relying on getting a `nullptr` if the location is inside a token, 
as compared to strictly at the beginning of tok.

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


[clang] [clang-tools-extra] [clangd] Fix crash with null check for Token at Loc (PR #94528)

2024-06-06 Thread Utkarsh Saxena via cfe-commits

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


[clang] [clang-tools-extra] [clangd] Fix crash with null check for Token at Loc (PR #94528)

2024-06-06 Thread Utkarsh Saxena via cfe-commits


@@ -1354,6 +1354,8 @@ maybeFindIncludeReferences(ParsedAST , Position Pos,
 
 ReferencesResult::Reference Result;
 const auto *Token = AST.getTokens().spelledTokenAt(Loc);
+if (!Token)

usx95 wrote:

Modified `spelledTokenAt`.

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


[clang] [clang-tools-extra] [clangd] Fix crash with null check for Token at Loc (PR #94528)

2024-06-06 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/94528

>From b13a663ae347649a3bcf9d6e381a5fbbfdc9ea4b Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 5 Jun 2024 19:48:48 +
Subject: [PATCH 1/3] [clangd] Fix crash with null check for Token at Loc

---
 clang-tools-extra/clangd/XRefs.cpp| 32 +++
 .../clangd/unittests/XRefsTests.cpp   | 14 +++-
 2 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/clang-tools-extra/clangd/XRefs.cpp 
b/clang-tools-extra/clangd/XRefs.cpp
index cd909266489a8..f52228e599591 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -1354,6 +1354,8 @@ maybeFindIncludeReferences(ParsedAST , Position Pos,
 
 ReferencesResult::Reference Result;
 const auto *Token = AST.getTokens().spelledTokenAt(Loc);
+if (!Token)
+  return;
 Result.Loc.range = Range{sourceLocToPosition(SM, Token->location()),
  sourceLocToPosition(SM, 
Token->endLocation())};
 Result.Loc.uri = URIMainFile;
@@ -2012,15 +2014,15 @@ static QualType typeForNode(const SelectionTree::Node 
*N) {
   return QualType();
 }
 
-// Given a type targeted by the cursor, return one or more types that are more 
interesting
-// to target.
-static void unwrapFindType(
-QualType T, const HeuristicResolver* H, llvm::SmallVector& Out) {
+// Given a type targeted by the cursor, return one or more types that are more
+// interesting to target.
+static void unwrapFindType(QualType T, const HeuristicResolver *H,
+   llvm::SmallVector ) {
   if (T.isNull())
 return;
 
   // If there's a specific type alias, point at that rather than unwrapping.
-  if (const auto* TDT = T->getAs())
+  if (const auto *TDT = T->getAs())
 return Out.push_back(QualType(TDT, 0));
 
   // Pointers etc => pointee type.
@@ -2044,17 +2046,18 @@ static void unwrapFindType(
 
   // For smart pointer types, add the underlying type
   if (H)
-if (const auto* PointeeType = 
H->getPointeeType(T.getNonReferenceType().getTypePtr())) {
-unwrapFindType(QualType(PointeeType, 0), H, Out);
-return Out.push_back(T);
+if (const auto *PointeeType =
+H->getPointeeType(T.getNonReferenceType().getTypePtr())) {
+  unwrapFindType(QualType(PointeeType, 0), H, Out);
+  return Out.push_back(T);
 }
 
   return Out.push_back(T);
 }
 
 // Convenience overload, to allow calling this without the out-parameter
-static llvm::SmallVector unwrapFindType(
-QualType T, const HeuristicResolver* H) {
+static llvm::SmallVector unwrapFindType(QualType T,
+  const HeuristicResolver *H) {
   llvm::SmallVector Result;
   unwrapFindType(T, H, Result);
   return Result;
@@ -2076,10 +2079,11 @@ std::vector findType(ParsedAST , 
Position Pos,
 std::vector LocatedSymbols;
 
 // NOTE: unwrapFindType might return duplicates for something like
-// unique_ptr>. Let's *not* remove them, because it gives 
you some
-// information about the type you may have not known before
-// (since unique_ptr> != unique_ptr).
-for (const QualType& Type : unwrapFindType(typeForNode(N), 
AST.getHeuristicResolver()))
+// unique_ptr>. Let's *not* remove them, because it gives you
+// some information about the type you may have not known before (since
+// unique_ptr> != unique_ptr).
+for (const QualType  :
+ unwrapFindType(typeForNode(N), AST.getHeuristicResolver()))
   llvm::copy(locateSymbolForType(AST, Type, Index),
  std::back_inserter(LocatedSymbols));
 
diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp 
b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index f53cbf01b7992..c4def624a2fcc 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -2358,7 +2358,14 @@ TEST(FindReferences, UsedSymbolsFromInclude) {
 
   R"cpp([[#in^clude ]]
 std::[[vector]] vec;
-  )cpp"};
+  )cpp",
+
+  R"cpp(
+[[#include ^"operator_qoutes.h"]]
+using ::operator_qoutes::[[operator]]"" _b;
+auto x = 1_b;
+  )cpp",
+  };
   for (const char *Test : Tests) {
 Annotations T(Test);
 auto TU = TestTU::withCode(T.code());
@@ -2375,6 +2382,11 @@ TEST(FindReferences, UsedSymbolsFromInclude) {
 class vector{};
   }
 )cpp");
+TU.AdditionalFiles["operator_qoutes.h"] = guard(R"cpp(
+  namespace operator_qoutes {
+bool operator"" _b(unsigned long long value);
+  }
+)cpp");
 TU.ExtraArgs.push_back("-isystem" + testPath("system"));
 
 auto AST = TU.build();

>From 3fe19589a332342abb069316224bdf9a6150c660 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 5 Jun 2024 19:59:44 +
Subject: [PATCH 2/3] remove unintentional format

---
 clang-tools-extra/clangd/XRefs.cpp | 30 

[clang-tools-extra] [clangd] Fix crash with null check for Token at Loc (PR #94528)

2024-06-05 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/94528

>From b13a663ae347649a3bcf9d6e381a5fbbfdc9ea4b Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 5 Jun 2024 19:48:48 +
Subject: [PATCH 1/2] [clangd] Fix crash with null check for Token at Loc

---
 clang-tools-extra/clangd/XRefs.cpp| 32 +++
 .../clangd/unittests/XRefsTests.cpp   | 14 +++-
 2 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/clang-tools-extra/clangd/XRefs.cpp 
b/clang-tools-extra/clangd/XRefs.cpp
index cd909266489a8..f52228e599591 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -1354,6 +1354,8 @@ maybeFindIncludeReferences(ParsedAST , Position Pos,
 
 ReferencesResult::Reference Result;
 const auto *Token = AST.getTokens().spelledTokenAt(Loc);
+if (!Token)
+  return;
 Result.Loc.range = Range{sourceLocToPosition(SM, Token->location()),
  sourceLocToPosition(SM, 
Token->endLocation())};
 Result.Loc.uri = URIMainFile;
@@ -2012,15 +2014,15 @@ static QualType typeForNode(const SelectionTree::Node 
*N) {
   return QualType();
 }
 
-// Given a type targeted by the cursor, return one or more types that are more 
interesting
-// to target.
-static void unwrapFindType(
-QualType T, const HeuristicResolver* H, llvm::SmallVector& Out) {
+// Given a type targeted by the cursor, return one or more types that are more
+// interesting to target.
+static void unwrapFindType(QualType T, const HeuristicResolver *H,
+   llvm::SmallVector ) {
   if (T.isNull())
 return;
 
   // If there's a specific type alias, point at that rather than unwrapping.
-  if (const auto* TDT = T->getAs())
+  if (const auto *TDT = T->getAs())
 return Out.push_back(QualType(TDT, 0));
 
   // Pointers etc => pointee type.
@@ -2044,17 +2046,18 @@ static void unwrapFindType(
 
   // For smart pointer types, add the underlying type
   if (H)
-if (const auto* PointeeType = 
H->getPointeeType(T.getNonReferenceType().getTypePtr())) {
-unwrapFindType(QualType(PointeeType, 0), H, Out);
-return Out.push_back(T);
+if (const auto *PointeeType =
+H->getPointeeType(T.getNonReferenceType().getTypePtr())) {
+  unwrapFindType(QualType(PointeeType, 0), H, Out);
+  return Out.push_back(T);
 }
 
   return Out.push_back(T);
 }
 
 // Convenience overload, to allow calling this without the out-parameter
-static llvm::SmallVector unwrapFindType(
-QualType T, const HeuristicResolver* H) {
+static llvm::SmallVector unwrapFindType(QualType T,
+  const HeuristicResolver *H) {
   llvm::SmallVector Result;
   unwrapFindType(T, H, Result);
   return Result;
@@ -2076,10 +2079,11 @@ std::vector findType(ParsedAST , 
Position Pos,
 std::vector LocatedSymbols;
 
 // NOTE: unwrapFindType might return duplicates for something like
-// unique_ptr>. Let's *not* remove them, because it gives 
you some
-// information about the type you may have not known before
-// (since unique_ptr> != unique_ptr).
-for (const QualType& Type : unwrapFindType(typeForNode(N), 
AST.getHeuristicResolver()))
+// unique_ptr>. Let's *not* remove them, because it gives you
+// some information about the type you may have not known before (since
+// unique_ptr> != unique_ptr).
+for (const QualType  :
+ unwrapFindType(typeForNode(N), AST.getHeuristicResolver()))
   llvm::copy(locateSymbolForType(AST, Type, Index),
  std::back_inserter(LocatedSymbols));
 
diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp 
b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index f53cbf01b7992..c4def624a2fcc 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -2358,7 +2358,14 @@ TEST(FindReferences, UsedSymbolsFromInclude) {
 
   R"cpp([[#in^clude ]]
 std::[[vector]] vec;
-  )cpp"};
+  )cpp",
+
+  R"cpp(
+[[#include ^"operator_qoutes.h"]]
+using ::operator_qoutes::[[operator]]"" _b;
+auto x = 1_b;
+  )cpp",
+  };
   for (const char *Test : Tests) {
 Annotations T(Test);
 auto TU = TestTU::withCode(T.code());
@@ -2375,6 +2382,11 @@ TEST(FindReferences, UsedSymbolsFromInclude) {
 class vector{};
   }
 )cpp");
+TU.AdditionalFiles["operator_qoutes.h"] = guard(R"cpp(
+  namespace operator_qoutes {
+bool operator"" _b(unsigned long long value);
+  }
+)cpp");
 TU.ExtraArgs.push_back("-isystem" + testPath("system"));
 
 auto AST = TU.build();

>From 3fe19589a332342abb069316224bdf9a6150c660 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 5 Jun 2024 19:59:44 +
Subject: [PATCH 2/2] remove unintentional format

---
 clang-tools-extra/clangd/XRefs.cpp | 30 

[clang-tools-extra] [clangd] Fix crash with null check for Token at Loc (PR #94528)

2024-06-05 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 created https://github.com/llvm/llvm-project/pull/94528

None

>From b13a663ae347649a3bcf9d6e381a5fbbfdc9ea4b Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 5 Jun 2024 19:48:48 +
Subject: [PATCH] [clangd] Fix crash with null check for Token at Loc

---
 clang-tools-extra/clangd/XRefs.cpp| 32 +++
 .../clangd/unittests/XRefsTests.cpp   | 14 +++-
 2 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/clang-tools-extra/clangd/XRefs.cpp 
b/clang-tools-extra/clangd/XRefs.cpp
index cd909266489a8..f52228e599591 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -1354,6 +1354,8 @@ maybeFindIncludeReferences(ParsedAST , Position Pos,
 
 ReferencesResult::Reference Result;
 const auto *Token = AST.getTokens().spelledTokenAt(Loc);
+if (!Token)
+  return;
 Result.Loc.range = Range{sourceLocToPosition(SM, Token->location()),
  sourceLocToPosition(SM, 
Token->endLocation())};
 Result.Loc.uri = URIMainFile;
@@ -2012,15 +2014,15 @@ static QualType typeForNode(const SelectionTree::Node 
*N) {
   return QualType();
 }
 
-// Given a type targeted by the cursor, return one or more types that are more 
interesting
-// to target.
-static void unwrapFindType(
-QualType T, const HeuristicResolver* H, llvm::SmallVector& Out) {
+// Given a type targeted by the cursor, return one or more types that are more
+// interesting to target.
+static void unwrapFindType(QualType T, const HeuristicResolver *H,
+   llvm::SmallVector ) {
   if (T.isNull())
 return;
 
   // If there's a specific type alias, point at that rather than unwrapping.
-  if (const auto* TDT = T->getAs())
+  if (const auto *TDT = T->getAs())
 return Out.push_back(QualType(TDT, 0));
 
   // Pointers etc => pointee type.
@@ -2044,17 +2046,18 @@ static void unwrapFindType(
 
   // For smart pointer types, add the underlying type
   if (H)
-if (const auto* PointeeType = 
H->getPointeeType(T.getNonReferenceType().getTypePtr())) {
-unwrapFindType(QualType(PointeeType, 0), H, Out);
-return Out.push_back(T);
+if (const auto *PointeeType =
+H->getPointeeType(T.getNonReferenceType().getTypePtr())) {
+  unwrapFindType(QualType(PointeeType, 0), H, Out);
+  return Out.push_back(T);
 }
 
   return Out.push_back(T);
 }
 
 // Convenience overload, to allow calling this without the out-parameter
-static llvm::SmallVector unwrapFindType(
-QualType T, const HeuristicResolver* H) {
+static llvm::SmallVector unwrapFindType(QualType T,
+  const HeuristicResolver *H) {
   llvm::SmallVector Result;
   unwrapFindType(T, H, Result);
   return Result;
@@ -2076,10 +2079,11 @@ std::vector findType(ParsedAST , 
Position Pos,
 std::vector LocatedSymbols;
 
 // NOTE: unwrapFindType might return duplicates for something like
-// unique_ptr>. Let's *not* remove them, because it gives 
you some
-// information about the type you may have not known before
-// (since unique_ptr> != unique_ptr).
-for (const QualType& Type : unwrapFindType(typeForNode(N), 
AST.getHeuristicResolver()))
+// unique_ptr>. Let's *not* remove them, because it gives you
+// some information about the type you may have not known before (since
+// unique_ptr> != unique_ptr).
+for (const QualType  :
+ unwrapFindType(typeForNode(N), AST.getHeuristicResolver()))
   llvm::copy(locateSymbolForType(AST, Type, Index),
  std::back_inserter(LocatedSymbols));
 
diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp 
b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index f53cbf01b7992..c4def624a2fcc 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -2358,7 +2358,14 @@ TEST(FindReferences, UsedSymbolsFromInclude) {
 
   R"cpp([[#in^clude ]]
 std::[[vector]] vec;
-  )cpp"};
+  )cpp",
+
+  R"cpp(
+[[#include ^"operator_qoutes.h"]]
+using ::operator_qoutes::[[operator]]"" _b;
+auto x = 1_b;
+  )cpp",
+  };
   for (const char *Test : Tests) {
 Annotations T(Test);
 auto TU = TestTU::withCode(T.code());
@@ -2375,6 +2382,11 @@ TEST(FindReferences, UsedSymbolsFromInclude) {
 class vector{};
   }
 )cpp");
+TU.AdditionalFiles["operator_qoutes.h"] = guard(R"cpp(
+  namespace operator_qoutes {
+bool operator"" _b(unsigned long long value);
+  }
+)cpp");
 TU.ExtraArgs.push_back("-isystem" + testPath("system"));
 
 auto AST = TU.build();

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


[clang] Re-apply "Emit missing cleanups for stmt-expr" and other commits (PR #89154)

2024-04-29 Thread Utkarsh Saxena via cfe-commits

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


[clang] Re-apply "Emit missing cleanups for stmt-expr" and other commits (PR #89154)

2024-04-29 Thread Utkarsh Saxena via cfe-commits

usx95 wrote:

I have built a very large corpus with a clang built with these changes and run 
its tests. No compilation or test failures were reported. The corpus was built 
with exceptions disabled.
I am fairly confident in the correctness of this and will proceed with landing 
this patch for now.

That said, a breakage with missing destructors or double-free can likely be 
associated with this patch. Please report any breakages, especially with 
exceptions enabled.

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


[clang] Re-apply "Emit missing cleanups for stmt-expr" and other commits (PR #89154)

2024-04-29 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/89154

>From f1ab4c2677394bbfc985d9680d5eecd7b2e6a882 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 17 Apr 2024 22:47:36 +
Subject: [PATCH 1/5] Reapply "[codegen] Emit missing cleanups for stmt-expr
 and coro suspensions" and related commits (#4)

This reverts commit 9d8be2408768912dc113a342050049231e4fc8d1.
---
 clang/lib/CodeGen/CGCall.cpp  |  13 +-
 clang/lib/CodeGen/CGCleanup.cpp   |  49 ++-
 clang/lib/CodeGen/CGCleanup.h |  57 ++-
 clang/lib/CodeGen/CGDecl.cpp  |  61 ++-
 clang/lib/CodeGen/CGExpr.cpp  |  12 +-
 clang/lib/CodeGen/CGExprAgg.cpp   |  87 ++--
 clang/lib/CodeGen/CGExprCXX.cpp   |  38 +-
 clang/lib/CodeGen/CodeGenFunction.cpp |   6 +
 clang/lib/CodeGen/CodeGenFunction.h   |  99 -
 .../CodeGenCXX/control-flow-in-stmt-expr.cpp  | 409 ++
 .../coro-suspend-cleanups.cpp |  93 
 11 files changed, 796 insertions(+), 128 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/control-flow-in-stmt-expr.cpp
 create mode 100644 clang/test/CodeGenCoroutines/coro-suspend-cleanups.cpp

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 3f5463a9a70e9d..9004e96bc1a0cf 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4693,11 +4693,11 @@ void CodeGenFunction::EmitCallArg(CallArgList , 
const Expr *E,
 AggValueSlot Slot = args.isUsingInAlloca()
 ? createPlaceholderSlot(*this, type) : CreateAggTemp(type, "agg.tmp");
 
-bool DestroyedInCallee = true, NeedsEHCleanup = true;
+bool DestroyedInCallee = true, NeedsCleanup = true;
 if (const auto *RD = type->getAsCXXRecordDecl())
   DestroyedInCallee = RD->hasNonTrivialDestructor();
 else
-  NeedsEHCleanup = needsEHCleanup(type.isDestructedType());
+  NeedsCleanup = type.isDestructedType();
 
 if (DestroyedInCallee)
   Slot.setExternallyDestructed();
@@ -4706,14 +4706,15 @@ void CodeGenFunction::EmitCallArg(CallArgList , 
const Expr *E,
 RValue RV = Slot.asRValue();
 args.add(RV, type);
 
-if (DestroyedInCallee && NeedsEHCleanup) {
+if (DestroyedInCallee && NeedsCleanup) {
   // Create a no-op GEP between the placeholder and the cleanup so we can
   // RAUW it successfully.  It also serves as a marker of the first
   // instruction where the cleanup is active.
-  pushFullExprCleanup(EHCleanup, Slot.getAddress(),
-  type);
+  pushFullExprCleanup(NormalAndEHCleanup,
+  Slot.getAddress(), type);
   // This unreachable is a temporary marker which will be removed later.
-  llvm::Instruction *IsActive = Builder.CreateUnreachable();
+  llvm::Instruction *IsActive =
+  Builder.CreateFlagLoad(llvm::Constant::getNullValue(Int8PtrTy));
   args.addArgCleanupDeactivation(EHStack.stable_begin(), IsActive);
 }
 return;
diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index e6f8e6873004f2..8683f19d9da28e 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -634,12 +634,19 @@ static void destroyOptimisticNormalEntry(CodeGenFunction 
,
 /// Pops a cleanup block.  If the block includes a normal cleanup, the
 /// current insertion point is threaded through the cleanup, as are
 /// any branch fixups on the cleanup.
-void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) {
+void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough,
+  bool ForDeactivation) {
   assert(!EHStack.empty() && "cleanup stack is empty!");
   assert(isa(*EHStack.begin()) && "top not a cleanup!");
   EHCleanupScope  = cast(*EHStack.begin());
   assert(Scope.getFixupDepth() <= EHStack.getNumBranchFixups());
 
+  // If we are deactivating a normal cleanup, we need to pretend that the
+  // fallthrough is unreachable. We restore this IP before returning.
+  CGBuilderTy::InsertPoint NormalDeactivateOrigIP;
+  if (ForDeactivation && (Scope.isNormalCleanup() || !getLangOpts().EHAsynch)) 
{
+NormalDeactivateOrigIP = Builder.saveAndClearIP();
+  }
   // Remember activation information.
   bool IsActive = Scope.isActive();
   Address NormalActiveFlag =
@@ -667,7 +674,8 @@ void CodeGenFunction::PopCleanupBlock(bool 
FallthroughIsBranchThrough) {
 
   // - whether there's a fallthrough
   llvm::BasicBlock *FallthroughSource = Builder.GetInsertBlock();
-  bool HasFallthrough = (FallthroughSource != nullptr && IsActive);
+  bool HasFallthrough =
+  FallthroughSource != nullptr && (IsActive || HasExistingBranches);
 
   // Branch-through fall-throughs leave the insertion point set to the
   // end of the last cleanup, which points to the current scope.  The
@@ -692,7 +700,11 @@ void 

[clang] Re-apply "Emit missing cleanups for stmt-expr" and other commits (PR #89154)

2024-04-29 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/89154

>From f1ab4c2677394bbfc985d9680d5eecd7b2e6a882 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 17 Apr 2024 22:47:36 +
Subject: [PATCH 1/4] Reapply "[codegen] Emit missing cleanups for stmt-expr
 and coro suspensions" and related commits (#4)

This reverts commit 9d8be2408768912dc113a342050049231e4fc8d1.
---
 clang/lib/CodeGen/CGCall.cpp  |  13 +-
 clang/lib/CodeGen/CGCleanup.cpp   |  49 ++-
 clang/lib/CodeGen/CGCleanup.h |  57 ++-
 clang/lib/CodeGen/CGDecl.cpp  |  61 ++-
 clang/lib/CodeGen/CGExpr.cpp  |  12 +-
 clang/lib/CodeGen/CGExprAgg.cpp   |  87 ++--
 clang/lib/CodeGen/CGExprCXX.cpp   |  38 +-
 clang/lib/CodeGen/CodeGenFunction.cpp |   6 +
 clang/lib/CodeGen/CodeGenFunction.h   |  99 -
 .../CodeGenCXX/control-flow-in-stmt-expr.cpp  | 409 ++
 .../coro-suspend-cleanups.cpp |  93 
 11 files changed, 796 insertions(+), 128 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/control-flow-in-stmt-expr.cpp
 create mode 100644 clang/test/CodeGenCoroutines/coro-suspend-cleanups.cpp

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 3f5463a9a70e9d..9004e96bc1a0cf 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4693,11 +4693,11 @@ void CodeGenFunction::EmitCallArg(CallArgList , 
const Expr *E,
 AggValueSlot Slot = args.isUsingInAlloca()
 ? createPlaceholderSlot(*this, type) : CreateAggTemp(type, "agg.tmp");
 
-bool DestroyedInCallee = true, NeedsEHCleanup = true;
+bool DestroyedInCallee = true, NeedsCleanup = true;
 if (const auto *RD = type->getAsCXXRecordDecl())
   DestroyedInCallee = RD->hasNonTrivialDestructor();
 else
-  NeedsEHCleanup = needsEHCleanup(type.isDestructedType());
+  NeedsCleanup = type.isDestructedType();
 
 if (DestroyedInCallee)
   Slot.setExternallyDestructed();
@@ -4706,14 +4706,15 @@ void CodeGenFunction::EmitCallArg(CallArgList , 
const Expr *E,
 RValue RV = Slot.asRValue();
 args.add(RV, type);
 
-if (DestroyedInCallee && NeedsEHCleanup) {
+if (DestroyedInCallee && NeedsCleanup) {
   // Create a no-op GEP between the placeholder and the cleanup so we can
   // RAUW it successfully.  It also serves as a marker of the first
   // instruction where the cleanup is active.
-  pushFullExprCleanup(EHCleanup, Slot.getAddress(),
-  type);
+  pushFullExprCleanup(NormalAndEHCleanup,
+  Slot.getAddress(), type);
   // This unreachable is a temporary marker which will be removed later.
-  llvm::Instruction *IsActive = Builder.CreateUnreachable();
+  llvm::Instruction *IsActive =
+  Builder.CreateFlagLoad(llvm::Constant::getNullValue(Int8PtrTy));
   args.addArgCleanupDeactivation(EHStack.stable_begin(), IsActive);
 }
 return;
diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index e6f8e6873004f2..8683f19d9da28e 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -634,12 +634,19 @@ static void destroyOptimisticNormalEntry(CodeGenFunction 
,
 /// Pops a cleanup block.  If the block includes a normal cleanup, the
 /// current insertion point is threaded through the cleanup, as are
 /// any branch fixups on the cleanup.
-void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) {
+void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough,
+  bool ForDeactivation) {
   assert(!EHStack.empty() && "cleanup stack is empty!");
   assert(isa(*EHStack.begin()) && "top not a cleanup!");
   EHCleanupScope  = cast(*EHStack.begin());
   assert(Scope.getFixupDepth() <= EHStack.getNumBranchFixups());
 
+  // If we are deactivating a normal cleanup, we need to pretend that the
+  // fallthrough is unreachable. We restore this IP before returning.
+  CGBuilderTy::InsertPoint NormalDeactivateOrigIP;
+  if (ForDeactivation && (Scope.isNormalCleanup() || !getLangOpts().EHAsynch)) 
{
+NormalDeactivateOrigIP = Builder.saveAndClearIP();
+  }
   // Remember activation information.
   bool IsActive = Scope.isActive();
   Address NormalActiveFlag =
@@ -667,7 +674,8 @@ void CodeGenFunction::PopCleanupBlock(bool 
FallthroughIsBranchThrough) {
 
   // - whether there's a fallthrough
   llvm::BasicBlock *FallthroughSource = Builder.GetInsertBlock();
-  bool HasFallthrough = (FallthroughSource != nullptr && IsActive);
+  bool HasFallthrough =
+  FallthroughSource != nullptr && (IsActive || HasExistingBranches);
 
   // Branch-through fall-throughs leave the insertion point set to the
   // end of the last cleanup, which points to the current scope.  The
@@ -692,7 +700,11 @@ void 

[clang] Re-apply "Emit missing cleanups for stmt-expr" and other commits (PR #89154)

2024-04-29 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/89154

>From f1ab4c2677394bbfc985d9680d5eecd7b2e6a882 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 17 Apr 2024 22:47:36 +
Subject: [PATCH 1/4] Reapply "[codegen] Emit missing cleanups for stmt-expr
 and coro suspensions" and related commits (#4)

This reverts commit 9d8be2408768912dc113a342050049231e4fc8d1.
---
 clang/lib/CodeGen/CGCall.cpp  |  13 +-
 clang/lib/CodeGen/CGCleanup.cpp   |  49 ++-
 clang/lib/CodeGen/CGCleanup.h |  57 ++-
 clang/lib/CodeGen/CGDecl.cpp  |  61 ++-
 clang/lib/CodeGen/CGExpr.cpp  |  12 +-
 clang/lib/CodeGen/CGExprAgg.cpp   |  87 ++--
 clang/lib/CodeGen/CGExprCXX.cpp   |  38 +-
 clang/lib/CodeGen/CodeGenFunction.cpp |   6 +
 clang/lib/CodeGen/CodeGenFunction.h   |  99 -
 .../CodeGenCXX/control-flow-in-stmt-expr.cpp  | 409 ++
 .../coro-suspend-cleanups.cpp |  93 
 11 files changed, 796 insertions(+), 128 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/control-flow-in-stmt-expr.cpp
 create mode 100644 clang/test/CodeGenCoroutines/coro-suspend-cleanups.cpp

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 3f5463a9a70e9d..9004e96bc1a0cf 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4693,11 +4693,11 @@ void CodeGenFunction::EmitCallArg(CallArgList , 
const Expr *E,
 AggValueSlot Slot = args.isUsingInAlloca()
 ? createPlaceholderSlot(*this, type) : CreateAggTemp(type, "agg.tmp");
 
-bool DestroyedInCallee = true, NeedsEHCleanup = true;
+bool DestroyedInCallee = true, NeedsCleanup = true;
 if (const auto *RD = type->getAsCXXRecordDecl())
   DestroyedInCallee = RD->hasNonTrivialDestructor();
 else
-  NeedsEHCleanup = needsEHCleanup(type.isDestructedType());
+  NeedsCleanup = type.isDestructedType();
 
 if (DestroyedInCallee)
   Slot.setExternallyDestructed();
@@ -4706,14 +4706,15 @@ void CodeGenFunction::EmitCallArg(CallArgList , 
const Expr *E,
 RValue RV = Slot.asRValue();
 args.add(RV, type);
 
-if (DestroyedInCallee && NeedsEHCleanup) {
+if (DestroyedInCallee && NeedsCleanup) {
   // Create a no-op GEP between the placeholder and the cleanup so we can
   // RAUW it successfully.  It also serves as a marker of the first
   // instruction where the cleanup is active.
-  pushFullExprCleanup(EHCleanup, Slot.getAddress(),
-  type);
+  pushFullExprCleanup(NormalAndEHCleanup,
+  Slot.getAddress(), type);
   // This unreachable is a temporary marker which will be removed later.
-  llvm::Instruction *IsActive = Builder.CreateUnreachable();
+  llvm::Instruction *IsActive =
+  Builder.CreateFlagLoad(llvm::Constant::getNullValue(Int8PtrTy));
   args.addArgCleanupDeactivation(EHStack.stable_begin(), IsActive);
 }
 return;
diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index e6f8e6873004f2..8683f19d9da28e 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -634,12 +634,19 @@ static void destroyOptimisticNormalEntry(CodeGenFunction 
,
 /// Pops a cleanup block.  If the block includes a normal cleanup, the
 /// current insertion point is threaded through the cleanup, as are
 /// any branch fixups on the cleanup.
-void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) {
+void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough,
+  bool ForDeactivation) {
   assert(!EHStack.empty() && "cleanup stack is empty!");
   assert(isa(*EHStack.begin()) && "top not a cleanup!");
   EHCleanupScope  = cast(*EHStack.begin());
   assert(Scope.getFixupDepth() <= EHStack.getNumBranchFixups());
 
+  // If we are deactivating a normal cleanup, we need to pretend that the
+  // fallthrough is unreachable. We restore this IP before returning.
+  CGBuilderTy::InsertPoint NormalDeactivateOrigIP;
+  if (ForDeactivation && (Scope.isNormalCleanup() || !getLangOpts().EHAsynch)) 
{
+NormalDeactivateOrigIP = Builder.saveAndClearIP();
+  }
   // Remember activation information.
   bool IsActive = Scope.isActive();
   Address NormalActiveFlag =
@@ -667,7 +674,8 @@ void CodeGenFunction::PopCleanupBlock(bool 
FallthroughIsBranchThrough) {
 
   // - whether there's a fallthrough
   llvm::BasicBlock *FallthroughSource = Builder.GetInsertBlock();
-  bool HasFallthrough = (FallthroughSource != nullptr && IsActive);
+  bool HasFallthrough =
+  FallthroughSource != nullptr && (IsActive || HasExistingBranches);
 
   // Branch-through fall-throughs leave the insertion point set to the
   // end of the last cleanup, which points to the current scope.  The
@@ -692,7 +700,11 @@ void 

[clang] Re-apply "Emit missing cleanups for stmt-expr" and other commits (PR #89154)

2024-04-25 Thread Utkarsh Saxena via cfe-commits

usx95 wrote:

@efriedma-quic Ping!

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


[clang] Re-apply "Emit missing cleanups for stmt-expr" and other commits (PR #89154)

2024-04-21 Thread Utkarsh Saxena via cfe-commits

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


[clang] Re-apply "Emit missing cleanups for stmt-expr" and other commits (PR #89154)

2024-04-21 Thread Utkarsh Saxena via cfe-commits

usx95 wrote:

(addressed one more problem with conditional lifetime extension.)

> What, if anything, about the scenario you're describing is specific to 
> "normal" cleanups?

We do not see this with `EHCleanup`s because `EmitBranchThroughCleanup` does 
not consider `EHCleanup`. It branches through all the "Normal" cleanups in the 
`EHStack`.

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


[clang] Re-apply "Emit missing cleanups for stmt-expr" and other commits (PR #89154)

2024-04-21 Thread Utkarsh Saxena via cfe-commits

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


[clang] Re-apply "Emit missing cleanups for stmt-expr" and other commits (PR #89154)

2024-04-21 Thread Utkarsh Saxena via cfe-commits

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


[clang] Re-apply "Emit missing cleanups for stmt-expr" and other commits (PR #89154)

2024-04-21 Thread Utkarsh Saxena via cfe-commits

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


[clang] Re-apply "Emit missing cleanups for stmt-expr" and other commits (PR #89154)

2024-04-21 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated https://github.com/llvm/llvm-project/pull/89154

>From f1ab4c2677394bbfc985d9680d5eecd7b2e6a882 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Wed, 17 Apr 2024 22:47:36 +
Subject: [PATCH 1/3] Reapply "[codegen] Emit missing cleanups for stmt-expr
 and coro suspensions" and related commits (#4)

This reverts commit 9d8be2408768912dc113a342050049231e4fc8d1.
---
 clang/lib/CodeGen/CGCall.cpp  |  13 +-
 clang/lib/CodeGen/CGCleanup.cpp   |  49 ++-
 clang/lib/CodeGen/CGCleanup.h |  57 ++-
 clang/lib/CodeGen/CGDecl.cpp  |  61 ++-
 clang/lib/CodeGen/CGExpr.cpp  |  12 +-
 clang/lib/CodeGen/CGExprAgg.cpp   |  87 ++--
 clang/lib/CodeGen/CGExprCXX.cpp   |  38 +-
 clang/lib/CodeGen/CodeGenFunction.cpp |   6 +
 clang/lib/CodeGen/CodeGenFunction.h   |  99 -
 .../CodeGenCXX/control-flow-in-stmt-expr.cpp  | 409 ++
 .../coro-suspend-cleanups.cpp |  93 
 11 files changed, 796 insertions(+), 128 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/control-flow-in-stmt-expr.cpp
 create mode 100644 clang/test/CodeGenCoroutines/coro-suspend-cleanups.cpp

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 3f5463a9a70e9d..9004e96bc1a0cf 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4693,11 +4693,11 @@ void CodeGenFunction::EmitCallArg(CallArgList , 
const Expr *E,
 AggValueSlot Slot = args.isUsingInAlloca()
 ? createPlaceholderSlot(*this, type) : CreateAggTemp(type, "agg.tmp");
 
-bool DestroyedInCallee = true, NeedsEHCleanup = true;
+bool DestroyedInCallee = true, NeedsCleanup = true;
 if (const auto *RD = type->getAsCXXRecordDecl())
   DestroyedInCallee = RD->hasNonTrivialDestructor();
 else
-  NeedsEHCleanup = needsEHCleanup(type.isDestructedType());
+  NeedsCleanup = type.isDestructedType();
 
 if (DestroyedInCallee)
   Slot.setExternallyDestructed();
@@ -4706,14 +4706,15 @@ void CodeGenFunction::EmitCallArg(CallArgList , 
const Expr *E,
 RValue RV = Slot.asRValue();
 args.add(RV, type);
 
-if (DestroyedInCallee && NeedsEHCleanup) {
+if (DestroyedInCallee && NeedsCleanup) {
   // Create a no-op GEP between the placeholder and the cleanup so we can
   // RAUW it successfully.  It also serves as a marker of the first
   // instruction where the cleanup is active.
-  pushFullExprCleanup(EHCleanup, Slot.getAddress(),
-  type);
+  pushFullExprCleanup(NormalAndEHCleanup,
+  Slot.getAddress(), type);
   // This unreachable is a temporary marker which will be removed later.
-  llvm::Instruction *IsActive = Builder.CreateUnreachable();
+  llvm::Instruction *IsActive =
+  Builder.CreateFlagLoad(llvm::Constant::getNullValue(Int8PtrTy));
   args.addArgCleanupDeactivation(EHStack.stable_begin(), IsActive);
 }
 return;
diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index e6f8e6873004f2..8683f19d9da28e 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -634,12 +634,19 @@ static void destroyOptimisticNormalEntry(CodeGenFunction 
,
 /// Pops a cleanup block.  If the block includes a normal cleanup, the
 /// current insertion point is threaded through the cleanup, as are
 /// any branch fixups on the cleanup.
-void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough) {
+void CodeGenFunction::PopCleanupBlock(bool FallthroughIsBranchThrough,
+  bool ForDeactivation) {
   assert(!EHStack.empty() && "cleanup stack is empty!");
   assert(isa(*EHStack.begin()) && "top not a cleanup!");
   EHCleanupScope  = cast(*EHStack.begin());
   assert(Scope.getFixupDepth() <= EHStack.getNumBranchFixups());
 
+  // If we are deactivating a normal cleanup, we need to pretend that the
+  // fallthrough is unreachable. We restore this IP before returning.
+  CGBuilderTy::InsertPoint NormalDeactivateOrigIP;
+  if (ForDeactivation && (Scope.isNormalCleanup() || !getLangOpts().EHAsynch)) 
{
+NormalDeactivateOrigIP = Builder.saveAndClearIP();
+  }
   // Remember activation information.
   bool IsActive = Scope.isActive();
   Address NormalActiveFlag =
@@ -667,7 +674,8 @@ void CodeGenFunction::PopCleanupBlock(bool 
FallthroughIsBranchThrough) {
 
   // - whether there's a fallthrough
   llvm::BasicBlock *FallthroughSource = Builder.GetInsertBlock();
-  bool HasFallthrough = (FallthroughSource != nullptr && IsActive);
+  bool HasFallthrough =
+  FallthroughSource != nullptr && (IsActive || HasExistingBranches);
 
   // Branch-through fall-throughs leave the insertion point set to the
   // end of the last cleanup, which points to the current scope.  The
@@ -692,7 +700,11 @@ void 

[clang] Re-apply "Emit missing cleanups for stmt-expr" and other commits (PR #89154)

2024-04-17 Thread Utkarsh Saxena via cfe-commits

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


[clang] Re-apply "Emit missing cleanups for stmt-expr" and other commits (PR #89154)

2024-04-17 Thread Utkarsh Saxena via cfe-commits

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


[clang] Re-apply "Emit missing cleanups for stmt-expr" and other commits (PR #89154)

2024-04-17 Thread Utkarsh Saxena via cfe-commits

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


[clang] Re-apply "Emit missing cleanups for stmt-expr" and other commits (PR #89154)

2024-04-17 Thread Utkarsh Saxena via cfe-commits

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


[clang] Re-apply "Emit missing cleanups for stmt-expr" and other commits (PR #89154)

2024-04-17 Thread Utkarsh Saxena via cfe-commits

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


[clang] Re-apply "Emit missing cleanups for stmt-expr" and other commits (PR #89154)

2024-04-17 Thread Utkarsh Saxena via cfe-commits

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


[clang] Re-apply "Emit missing cleanups for stmt-expr" and other commits (PR #89154)

2024-04-17 Thread Utkarsh Saxena via cfe-commits

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


[clang] Re-apply "Emit missing cleanups for stmt-expr" and other commits (PR #89154)

2024-04-17 Thread Utkarsh Saxena via cfe-commits

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


  1   2   3   4   5   6   >