[clang] Reapply "[clang analysis][thread-safety] Handle return-by-reference..… (PR #68572)

2023-10-16 Thread Clement Courbet via cfe-commits

https://github.com/legrosbuffle updated 
https://github.com/llvm/llvm-project/pull/68572

>From 2d90dc0547f90c3a217428b2d3b8d2253ae80973 Mon Sep 17 00:00:00 2001
From: Clement Courbet 
Date: Mon, 9 Oct 2023 10:20:12 +0200
Subject: [PATCH] =?UTF-8?q?Reapply=20"[clang=20analysis][thread-safety]=20?=
 =?UTF-8?q?Handle=20return-by-reference..=E2=80=A6=20(#68394)"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The new warnings are now under a separate flag 
`-Wthread-safety-reference-return`. The plan is:

- Start with a period where people can opt into the new warnings with 
`-Wthread-safety-reference-return` or `-Wthread-safety-beta`. This allows 
downstream to test the new warnings without having to roll the implementation 
back and forth.
- Make `-Wthread-safety-reference-return` part of `-Wthread-safety-reference`. 
People can opt out via `-Wthread-safety-reference 
-Wnothread-safety-reference-return`.
- (maybe) delete `-Wthread-safety-reference-return` after some time ?

This reverts commit 859f2d032386632562521a99db20923217d98988.
---
 .../clang/Analysis/Analyses/ThreadSafety.h|  8 +-
 clang/include/clang/Basic/DiagnosticGroups.td | 12 +--
 .../clang/Basic/DiagnosticSemaKinds.td| 10 ++-
 clang/lib/Analysis/ThreadSafety.cpp   | 80 +--
 clang/lib/Sema/AnalysisBasedWarnings.cpp  | 12 +++
 .../SemaCXX/warn-thread-safety-analysis.cpp   | 79 ++
 6 files changed, 168 insertions(+), 33 deletions(-)

diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafety.h 
b/clang/include/clang/Analysis/Analyses/ThreadSafety.h
index 1808d1d71e05d2c..0866b09bab2995e 100644
--- a/clang/include/clang/Analysis/Analyses/ThreadSafety.h
+++ b/clang/include/clang/Analysis/Analyses/ThreadSafety.h
@@ -47,7 +47,13 @@ enum ProtectedOperationKind {
   POK_PassByRef,
 
   /// Passing a pt-guarded variable by reference.
-  POK_PtPassByRef
+  POK_PtPassByRef,
+
+  /// Returning a guarded variable by reference.
+  POK_ReturnByRef,
+
+  /// Returning a pt-guarded variable by reference.
+  POK_PtReturnByRef,
 };
 
 /// This enum distinguishes between different kinds of lock actions. For
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 0b09c002191848a..a71afdd710c3bf4 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1061,11 +1061,13 @@ def Most : DiagGroup<"most", [
  ]>;
 
 // Thread Safety warnings
-def ThreadSafetyAttributes : DiagGroup<"thread-safety-attributes">;
-def ThreadSafetyAnalysis   : DiagGroup<"thread-safety-analysis">;
-def ThreadSafetyPrecise: DiagGroup<"thread-safety-precise">;
-def ThreadSafetyReference  : DiagGroup<"thread-safety-reference">;
-def ThreadSafetyNegative   : DiagGroup<"thread-safety-negative">;
+def ThreadSafetyAttributes   : DiagGroup<"thread-safety-attributes">;
+def ThreadSafetyAnalysis : DiagGroup<"thread-safety-analysis">;
+def ThreadSafetyPrecise  : DiagGroup<"thread-safety-precise">;
+def ThreadSafetyReferenceReturn  : DiagGroup<"thread-safety-reference-return">;
+def ThreadSafetyReference: DiagGroup<"thread-safety-reference",
+ [ThreadSafetyReferenceReturn]>;
+def ThreadSafetyNegative : DiagGroup<"thread-safety-negative">;
 def ThreadSafety : DiagGroup<"thread-safety",
  [ThreadSafetyAttributes,
   ThreadSafetyAnalysis,
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 58a33e2807b7b0a..4c456a5561dc265 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3864,7 +3864,7 @@ def warn_fun_requires_negative_cap : Warning<
   "calling function %0 requires negative capability '%1'">,
   InGroup, DefaultIgnore;
 
-// Thread safety warnings on pass by reference
+// Thread safety warnings on pass/return by reference
 def warn_guarded_pass_by_reference : Warning<
   "passing variable %1 by reference requires holding %0 "
   "%select{'%2'|'%2' exclusively}3">,
@@ -3873,6 +3873,14 @@ def warn_pt_guarded_pass_by_reference : Warning<
   "passing the value that %1 points to by reference requires holding %0 "
   "%select{'%2'|'%2' exclusively}3">,
   InGroup, DefaultIgnore;
+def warn_guarded_return_by_reference : Warning<
+  "returning variable %1 by reference requires holding %0 "
+  "%select{'%2'|'%2' exclusively}3">,
+  InGroup, DefaultIgnore;
+def warn_pt_guarded_return_by_reference : Warning<
+  "returning the value that %1 points to by reference requires holding %0 "
+  "%select{'%2'|'%2' exclusively}3">,
+  InGroup, DefaultIgnore;
 
 // Imprecise thread safety warnings
 def warn_variable_requires_lock : Warning<
diff --git a/clang/lib/Analysis/ThreadSafety.cpp 
b/clang/lib/Analysis/ThreadSafety.cpp
index 58d

[clang] [clang] Improve `_Alignas` on a `struct` declaration diagnostic (PR #65638)

2023-10-16 Thread Jerin Philip via cfe-commits


@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -std=c23 -fsyntax-only -verify %s
+// RUN: not %clang_cc1 -std=c99 -pedantic -fsyntax-only %s 2>&1 | FileCheck 
-check-prefix=CHECK-EXT %s
+
+_Alignas(int) struct c1; // expected-warning {{attribute '_Alignas' before 
"struct" is ignored}}
+alignas(int) struct c1; // expected-warning {{attribute 'alignas' before 
"struct" is ignored}}

jerinphilip wrote:

I tried to add a C23 test carrying over [D141177 
(comment)](https://reviews.llvm.org/D141177#4606499_). The C23 test fails at 
the moment, because a CXX11 path is activated. My understanding is `alignas` 
being present pre C23 only in C++ has parse-paths that take the only C++ 
existence into consideration (from 
[isCXX11AttributeSpecifier](https://github.com/llvm/llvm-project/blob/041a786c78fbcee3537ca636bf796bb18fb6f313/clang/lib/Parse/ParseTentative.cpp#L740)).
 

It ends up at 
https://github.com/llvm/llvm-project/blob/041a786c78fbcee3537ca636bf796bb18fb6f313/clang/include/clang/Parse/Parser.h#L2743
 triggering the error messages to move it outward:
https://github.com/llvm/llvm-project/blob/041a786c78fbcee3537ca636bf796bb18fb6f313/clang/lib/Parse/ParseDecl.cpp#L1791

Is it possible to decouple C23 from this what this PR addresses?

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


[clang] Reapply "[clang analysis][thread-safety] Handle return-by-reference..… (PR #68572)

2023-10-16 Thread Clement Courbet via cfe-commits

https://github.com/legrosbuffle updated 
https://github.com/llvm/llvm-project/pull/68572

>From 11f5286f426d082f7fbcb578c0c6cabcd3660453 Mon Sep 17 00:00:00 2001
From: Clement Courbet 
Date: Mon, 9 Oct 2023 10:20:12 +0200
Subject: [PATCH] =?UTF-8?q?Reapply=20"[clang=20analysis][thread-safety]=20?=
 =?UTF-8?q?Handle=20return-by-reference..=E2=80=A6=20(#68394)"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The new warnings are now under a separate flag 
`-Wthread-safety-reference-return`. The plan is:

- Start with a period where people can opt into the new warnings with 
`-Wthread-safety-reference-return` or `-Wthread-safety-beta`. This allows 
downstream to test the new warnings without having to roll the implementation 
back and forth.
- Make `-Wthread-safety-reference-return` part of `-Wthread-safety-reference`. 
People can opt out via `-Wthread-safety-reference 
-Wnothread-safety-reference-return`.
- (maybe) delete `-Wthread-safety-reference-return` after some time ?

This reverts commit 859f2d032386632562521a99db20923217d98988.
---
 .../clang/Analysis/Analyses/ThreadSafety.h|  8 +-
 clang/include/clang/Basic/DiagnosticGroups.td | 12 +--
 .../clang/Basic/DiagnosticSemaKinds.td| 10 ++-
 clang/lib/Analysis/ThreadSafety.cpp   | 80 +--
 clang/lib/Sema/AnalysisBasedWarnings.cpp  | 12 +++
 .../SemaCXX/warn-thread-safety-analysis.cpp   | 79 ++
 6 files changed, 168 insertions(+), 33 deletions(-)

diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafety.h 
b/clang/include/clang/Analysis/Analyses/ThreadSafety.h
index 1808d1d71e05d2c..0866b09bab2995e 100644
--- a/clang/include/clang/Analysis/Analyses/ThreadSafety.h
+++ b/clang/include/clang/Analysis/Analyses/ThreadSafety.h
@@ -47,7 +47,13 @@ enum ProtectedOperationKind {
   POK_PassByRef,
 
   /// Passing a pt-guarded variable by reference.
-  POK_PtPassByRef
+  POK_PtPassByRef,
+
+  /// Returning a guarded variable by reference.
+  POK_ReturnByRef,
+
+  /// Returning a pt-guarded variable by reference.
+  POK_PtReturnByRef,
 };
 
 /// This enum distinguishes between different kinds of lock actions. For
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 0b09c002191848a..a71afdd710c3bf4 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1061,11 +1061,13 @@ def Most : DiagGroup<"most", [
  ]>;
 
 // Thread Safety warnings
-def ThreadSafetyAttributes : DiagGroup<"thread-safety-attributes">;
-def ThreadSafetyAnalysis   : DiagGroup<"thread-safety-analysis">;
-def ThreadSafetyPrecise: DiagGroup<"thread-safety-precise">;
-def ThreadSafetyReference  : DiagGroup<"thread-safety-reference">;
-def ThreadSafetyNegative   : DiagGroup<"thread-safety-negative">;
+def ThreadSafetyAttributes   : DiagGroup<"thread-safety-attributes">;
+def ThreadSafetyAnalysis : DiagGroup<"thread-safety-analysis">;
+def ThreadSafetyPrecise  : DiagGroup<"thread-safety-precise">;
+def ThreadSafetyReferenceReturn  : DiagGroup<"thread-safety-reference-return">;
+def ThreadSafetyReference: DiagGroup<"thread-safety-reference",
+ [ThreadSafetyReferenceReturn]>;
+def ThreadSafetyNegative : DiagGroup<"thread-safety-negative">;
 def ThreadSafety : DiagGroup<"thread-safety",
  [ThreadSafetyAttributes,
   ThreadSafetyAnalysis,
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b211680a0e9b6e9..c777d73dd4a769b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3864,7 +3864,7 @@ def warn_fun_requires_negative_cap : Warning<
   "calling function %0 requires negative capability '%1'">,
   InGroup, DefaultIgnore;
 
-// Thread safety warnings on pass by reference
+// Thread safety warnings on pass/return by reference
 def warn_guarded_pass_by_reference : Warning<
   "passing variable %1 by reference requires holding %0 "
   "%select{'%2'|'%2' exclusively}3">,
@@ -3873,6 +3873,14 @@ def warn_pt_guarded_pass_by_reference : Warning<
   "passing the value that %1 points to by reference requires holding %0 "
   "%select{'%2'|'%2' exclusively}3">,
   InGroup, DefaultIgnore;
+def warn_guarded_return_by_reference : Warning<
+  "returning variable %1 by reference requires holding %0 "
+  "%select{'%2'|'%2' exclusively}3">,
+  InGroup, DefaultIgnore;
+def warn_pt_guarded_return_by_reference : Warning<
+  "returning the value that %1 points to by reference requires holding %0 "
+  "%select{'%2'|'%2' exclusively}3">,
+  InGroup, DefaultIgnore;
 
 // Imprecise thread safety warnings
 def warn_variable_requires_lock : Warning<
diff --git a/clang/lib/Analysis/ThreadSafety.cpp 
b/clang/lib/Analysis/ThreadSafety.cpp
index 58d

[PATCH] D158414: [LexerTest] Use LexTokensUntilEOF() in StringifyArgs

2023-10-16 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

ping!


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

https://reviews.llvm.org/D158414

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


[clang] [clang] Improve `_Alignas` on a `struct` declaration diagnostic (PR #65638)

2023-10-16 Thread Jerin Philip via cfe-commits

https://github.com/jerinphilip updated 
https://github.com/llvm/llvm-project/pull/65638

>From 941af68ab8dad68ed8df65f6e0559476f137bfe2 Mon Sep 17 00:00:00 2001
From: Jerin Philip 
Date: Sat, 19 Aug 2023 16:43:53 +0530
Subject: [PATCH 01/11] Fix `Form` to recognize `_Alignas` in addition to
 `alignas`

---
 clang/include/clang/Basic/AttributeCommonInfo.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index e57adc4bf5b99a2..36f4eb885cf12f8 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -94,7 +94,7 @@ class AttributeCommonInfo {
   IsRegularKeywordAttribute(IsRegularKeywordAttribute) {}
 constexpr Form(tok::TokenKind Tok)
 : SyntaxUsed(AS_Keyword), SpellingIndex(SpellingNotCalculated),
-  IsAlignas(Tok == tok::kw_alignas),
+  IsAlignas(Tok == tok::kw_alignas || Tok == tok::kw__Alignas),
   IsRegularKeywordAttribute(tok::isRegularKeywordAttribute(Tok)) {}
 
 Syntax getSyntax() const { return Syntax(SyntaxUsed); }

>From 8c0bfe350dfa2d4d24988eb544f5c1a9eb1aec6d Mon Sep 17 00:00:00 2001
From: Jerin Philip 
Date: Thu, 7 Sep 2023 18:53:57 +0530
Subject: [PATCH 02/11] Avoid mixing `isCXX11Attribute` with `isAlignAs`

---
 clang/include/clang/Basic/AttributeCommonInfo.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 36f4eb885cf12f8..669227589dfacd5 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -186,14 +186,14 @@ class AttributeCommonInfo {
   bool isGNUScope() const;
   bool isClangScope() const;
 
-  bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11 || IsAlignas; }
+  bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11; }
 
   bool isC23Attribute() const { return SyntaxUsed == AS_C23; }
 
   /// The attribute is spelled [[]] in either C or C++ mode, including standard
   /// attributes spelled with a keyword, like alignas.
   bool isStandardAttributeSyntax() const {
-return isCXX11Attribute() || isC23Attribute();
+return isCXX11Attribute() || isC23Attribute() || IsAlignas;
   }
 
   bool isGNUAttribute() const { return SyntaxUsed == AS_GNU; }

>From 8f699d5dfe62b2a1eb1f67f37ffa3d4ba1f2bfce Mon Sep 17 00:00:00 2001
From: Jerin Philip 
Date: Thu, 7 Sep 2023 19:15:03 +0530
Subject: [PATCH 03/11] Fix diagnostic warning post `isAlignAs` decoupling

---
 clang/include/clang/Basic/AttributeCommonInfo.h | 2 +-
 clang/lib/Parse/ParseDecl.cpp   | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 669227589dfacd5..f1e3325d44f0e1a 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -186,8 +186,8 @@ class AttributeCommonInfo {
   bool isGNUScope() const;
   bool isClangScope() const;
 
+  bool isAlignas() const { return IsAlignas; }
   bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11; }
-
   bool isC23Attribute() const { return SyntaxUsed == AS_C23; }
 
   /// The attribute is spelled [[]] in either C or C++ mode, including standard
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 4a9f2caf654713e..f91141f7cd39cbf 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -3405,8 +3405,8 @@ void Parser::ParseDeclarationSpecifiers(
   else {
 // Reject C++11 / C23 attributes that aren't type attributes.
 for (const ParsedAttr &PA : attrs) {
-  if (!PA.isCXX11Attribute() && !PA.isC23Attribute() &&
-  !PA.isRegularKeywordAttribute())
+  if (!PA.isAlignas() && !PA.isCXX11Attribute() &&
+  !PA.isC23Attribute() && !PA.isRegularKeywordAttribute())
 continue;
   if (PA.getKind() == ParsedAttr::UnknownAttribute)
 // We will warn about the unknown attribute elsewhere (in

>From e7ddd755f1a873421809a05a4d5d999b7a15f62e Mon Sep 17 00:00:00 2001
From: Jerin Philip 
Date: Sat, 19 Aug 2023 16:44:51 +0530
Subject: [PATCH 04/11] Add attribute-ignored diagnostic warning variant

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0ac4df8edb242f6..f76f872a98288f7 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3491,10 +3491,14 @@ def err_attribute_invalid_on_decl : Error<
 def warn_type_attribute_deprecated_on_decl : Warning<
   "applying attribute %0 to a declaration is de

[clang] [clang] Improve `_Alignas` on a `struct` declaration diagnostic (PR #65638)

2023-10-16 Thread Jerin Philip via cfe-commits

https://github.com/jerinphilip updated 
https://github.com/llvm/llvm-project/pull/65638

>From 941af68ab8dad68ed8df65f6e0559476f137bfe2 Mon Sep 17 00:00:00 2001
From: Jerin Philip 
Date: Sat, 19 Aug 2023 16:43:53 +0530
Subject: [PATCH 01/10] Fix `Form` to recognize `_Alignas` in addition to
 `alignas`

---
 clang/include/clang/Basic/AttributeCommonInfo.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index e57adc4bf5b99a2..36f4eb885cf12f8 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -94,7 +94,7 @@ class AttributeCommonInfo {
   IsRegularKeywordAttribute(IsRegularKeywordAttribute) {}
 constexpr Form(tok::TokenKind Tok)
 : SyntaxUsed(AS_Keyword), SpellingIndex(SpellingNotCalculated),
-  IsAlignas(Tok == tok::kw_alignas),
+  IsAlignas(Tok == tok::kw_alignas || Tok == tok::kw__Alignas),
   IsRegularKeywordAttribute(tok::isRegularKeywordAttribute(Tok)) {}
 
 Syntax getSyntax() const { return Syntax(SyntaxUsed); }

>From 8c0bfe350dfa2d4d24988eb544f5c1a9eb1aec6d Mon Sep 17 00:00:00 2001
From: Jerin Philip 
Date: Thu, 7 Sep 2023 18:53:57 +0530
Subject: [PATCH 02/10] Avoid mixing `isCXX11Attribute` with `isAlignAs`

---
 clang/include/clang/Basic/AttributeCommonInfo.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 36f4eb885cf12f8..669227589dfacd5 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -186,14 +186,14 @@ class AttributeCommonInfo {
   bool isGNUScope() const;
   bool isClangScope() const;
 
-  bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11 || IsAlignas; }
+  bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11; }
 
   bool isC23Attribute() const { return SyntaxUsed == AS_C23; }
 
   /// The attribute is spelled [[]] in either C or C++ mode, including standard
   /// attributes spelled with a keyword, like alignas.
   bool isStandardAttributeSyntax() const {
-return isCXX11Attribute() || isC23Attribute();
+return isCXX11Attribute() || isC23Attribute() || IsAlignas;
   }
 
   bool isGNUAttribute() const { return SyntaxUsed == AS_GNU; }

>From 8f699d5dfe62b2a1eb1f67f37ffa3d4ba1f2bfce Mon Sep 17 00:00:00 2001
From: Jerin Philip 
Date: Thu, 7 Sep 2023 19:15:03 +0530
Subject: [PATCH 03/10] Fix diagnostic warning post `isAlignAs` decoupling

---
 clang/include/clang/Basic/AttributeCommonInfo.h | 2 +-
 clang/lib/Parse/ParseDecl.cpp   | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 669227589dfacd5..f1e3325d44f0e1a 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -186,8 +186,8 @@ class AttributeCommonInfo {
   bool isGNUScope() const;
   bool isClangScope() const;
 
+  bool isAlignas() const { return IsAlignas; }
   bool isCXX11Attribute() const { return SyntaxUsed == AS_CXX11; }
-
   bool isC23Attribute() const { return SyntaxUsed == AS_C23; }
 
   /// The attribute is spelled [[]] in either C or C++ mode, including standard
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 4a9f2caf654713e..f91141f7cd39cbf 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -3405,8 +3405,8 @@ void Parser::ParseDeclarationSpecifiers(
   else {
 // Reject C++11 / C23 attributes that aren't type attributes.
 for (const ParsedAttr &PA : attrs) {
-  if (!PA.isCXX11Attribute() && !PA.isC23Attribute() &&
-  !PA.isRegularKeywordAttribute())
+  if (!PA.isAlignas() && !PA.isCXX11Attribute() &&
+  !PA.isC23Attribute() && !PA.isRegularKeywordAttribute())
 continue;
   if (PA.getKind() == ParsedAttr::UnknownAttribute)
 // We will warn about the unknown attribute elsewhere (in

>From e7ddd755f1a873421809a05a4d5d999b7a15f62e Mon Sep 17 00:00:00 2001
From: Jerin Philip 
Date: Sat, 19 Aug 2023 16:44:51 +0530
Subject: [PATCH 04/10] Add attribute-ignored diagnostic warning variant

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0ac4df8edb242f6..f76f872a98288f7 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3491,10 +3491,14 @@ def err_attribute_invalid_on_decl : Error<
 def warn_type_attribute_deprecated_on_decl : Warning<
   "applying attribute %0 to a declaration is de

[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-10-16 Thread Jonas Hahnfeld via cfe-commits


@@ -0,0 +1,65 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t %t/main.cpp -o %t/main.o
+
+//--- V.h
+#ifndef V_H
+#define V_H
+
+class A {
+public:
+  constexpr A() { }
+  constexpr ~A() { }
+};
+
+template 
+class V {
+public:
+  V() = default;
+
+  constexpr V(int n, const A& a = A()) {}
+};
+
+#endif
+
+//--- inst1.h
+#include "V.h"
+
+static void inst1() {
+  V v;
+}
+
+//--- inst2.h
+#include "V.h"
+
+static void inst2() {
+  V v(100);
+}
+
+//--- module.modulemap
+module "M" {

hahnjo wrote:

`split-file` is how many of the modules tests are written, and I find it very 
handy to reproduce setups with a number of smaller files...

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


[clang] [clang][NFC] Replace TypeAlignment with alignof(T) (PR #69185)

2023-10-16 Thread via cfe-commits

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


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


[clang-tools-extra] [clangd] Correctly identify the next token after the completion point (PR #69153)

2023-10-16 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

I've no idea what the error causing the format check ("Error: Unable to 
determine a difference between 
8592241e29e29f0e7e407e0989489c6e70c91c42..e1ae800faed2fe3f612686edf6fe61f5b16e090d")
 to fail means.

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


[clang] [clang][dataflow] Check for backedges directly (instead of loop statements). (PR #68923)

2023-10-16 Thread via cfe-commits

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


[clang] [clang][dataflow] Check for backedges directly (instead of loop statements). (PR #68923)

2023-10-16 Thread via cfe-commits


@@ -53,19 +52,8 @@ static int blockIndexInPredecessor(const CFGBlock &Pred,
   return BlockPos - Pred.succ_begin();
 }
 
-static bool isLoopHead(const CFGBlock &B) {
-  if (const auto *T = B.getTerminatorStmt())
-switch (T->getStmtClass()) {
-  case Stmt::WhileStmtClass:
-  case Stmt::DoStmtClass:
-  case Stmt::ForStmtClass:
-  case Stmt::CXXForRangeStmtClass:
-return true;
-  default:
-return false;
-}
-
-  return false;
+static bool isBackedgeNode(const CFGBlock &B) {

martinboehme wrote:

Yes, but

* It still requires work (not everyone has an IDE with great cross-linking, so 
this could be multiple clicks), and
* 
* We're introducing a new term here ("backedge node"), and it's not clear 
without an explanation whether a) we intend for this to be a synonym for "has 
loop target" (but then why aren't we reusing that term -- is it because we 
think "backedge node" is clearer?), or b) `getLoopTarget() != nullptr` happens 
to be the right implementation today, but we think it might change in the 
future, so we're wrapping this check in a function?

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


[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2023-10-16 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/66514

>From 11e7ee626abf9edbcdd2cdcd6ee79f7a0792788c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 15 Sep 2023 15:51:39 +0200
Subject: [PATCH 01/19] [clang][Diagnostics] Highlight code snippets

Add some primitive syntax highlighting to our code snippet output.
---
 .../clang/Frontend/CodeSnippetHighlighter.h   |  46 +++
 clang/include/clang/Frontend/TextDiagnostic.h |   2 +
 clang/lib/Frontend/CMakeLists.txt |   1 +
 clang/lib/Frontend/CodeSnippetHighlighter.cpp | 120 ++
 clang/lib/Frontend/TextDiagnostic.cpp |  26 
 5 files changed, 195 insertions(+)
 create mode 100644 clang/include/clang/Frontend/CodeSnippetHighlighter.h
 create mode 100644 clang/lib/Frontend/CodeSnippetHighlighter.cpp

diff --git a/clang/include/clang/Frontend/CodeSnippetHighlighter.h 
b/clang/include/clang/Frontend/CodeSnippetHighlighter.h
new file mode 100644
index 000..776954b59e2e1a8
--- /dev/null
+++ b/clang/include/clang/Frontend/CodeSnippetHighlighter.h
@@ -0,0 +1,46 @@
+//===--- CodeSnippetHighlighter.h - Code snippet highlighting ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_FRONTEND_CODESNIPPETHIGHLIGHTER_H
+#define LLVM_CLANG_FRONTEND_CODESNIPPETHIGHLIGHTER_H
+
+#include "clang/Basic/LangOptions.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+namespace clang {
+
+struct StyleRange {
+  unsigned Start;
+  unsigned End;
+  const enum llvm::raw_ostream::Colors c;
+};
+
+class CodeSnippetHighlighter final {
+public:
+  CodeSnippetHighlighter() = default;
+
+  /// Produce StyleRanges for the given line.
+  /// The returned vector contains non-overlapping style ranges. They are 
sorted
+  /// from beginning of the line to the end.
+  std::vector highlightLine(llvm::StringRef SourceLine,
+const LangOptions &LangOpts);
+
+private:
+  bool Initialized = false;
+  /// Fills Keywords and Literals.
+  void ensureTokenData();
+
+  llvm::SmallSet Keywords;
+  llvm::SmallSet Literals;
+};
+
+} // namespace clang
+
+#endif
diff --git a/clang/include/clang/Frontend/TextDiagnostic.h 
b/clang/include/clang/Frontend/TextDiagnostic.h
index 7eb0ab0cdc9bca8..59fd4d4f9408d48 100644
--- a/clang/include/clang/Frontend/TextDiagnostic.h
+++ b/clang/include/clang/Frontend/TextDiagnostic.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 #define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 
+#include "clang/Frontend/CodeSnippetHighlighter.h"
 #include "clang/Frontend/DiagnosticRenderer.h"
 
 namespace clang {
@@ -33,6 +34,7 @@ namespace clang {
 /// printing coming out of libclang.
 class TextDiagnostic : public DiagnosticRenderer {
   raw_ostream &OS;
+  CodeSnippetHighlighter SnippetHighlighter;
 
 public:
   TextDiagnostic(raw_ostream &OS,
diff --git a/clang/lib/Frontend/CMakeLists.txt 
b/clang/lib/Frontend/CMakeLists.txt
index 1e5f0a859dfd568..f3547f771593093 100644
--- a/clang/lib/Frontend/CMakeLists.txt
+++ b/clang/lib/Frontend/CMakeLists.txt
@@ -42,6 +42,7 @@ add_clang_library(clangFrontend
   TextDiagnosticPrinter.cpp
   VerifyDiagnosticConsumer.cpp
   InterfaceStubFunctionsConsumer.cpp
+  CodeSnippetHighlighter.cpp
 
   DEPENDS
   ClangDriverOptions
diff --git a/clang/lib/Frontend/CodeSnippetHighlighter.cpp 
b/clang/lib/Frontend/CodeSnippetHighlighter.cpp
new file mode 100644
index 000..829a533ad2692e5
--- /dev/null
+++ b/clang/lib/Frontend/CodeSnippetHighlighter.cpp
@@ -0,0 +1,120 @@
+
+#include "clang/Frontend/CodeSnippetHighlighter.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Lexer.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace clang;
+
+void CodeSnippetHighlighter::ensureTokenData() {
+  if (Initialized)
+return;
+
+  // List of keywords, literals and types we want to highlight.
+  // These are best-effort, as is everything we do wrt. highlighting.
+  Keywords.insert("_Static_assert");
+  Keywords.insert("auto");
+  Keywords.insert("concept");
+  Keywords.insert("const");
+  Keywords.insert("consteval");
+  Keywords.insert("constexpr");
+  Keywords.

[clang] [NFC] [Serializer] Pack information in serializer (PR #69287)

2023-10-16 Thread Chuanqi Xu via cfe-commits

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


[clang] [NFC] [Serializer] Pack information in serializer (PR #69287)

2023-10-16 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/69287

>From 5a1f32f156801da271486dbb0fd37007adb4901c Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Mon, 16 Oct 2023 16:41:31 +0800
Subject: [PATCH] [NFC] [Serializer] Pack information in serializer

Previously, the boolean values will occupy spaces that can contain
integers. It wastes the spaces especially if the boolean values are
serialized consecutively. The patch tries to pack such consecutive
boolean values (and enum values) so that we can save more spaces and so
the times.

Before the patch, we need 4.478s (in my machine) to build the std module
(https://libcxx.llvm.org/Modules.html) with 28712 bytes. After the
patch, the time becomes to 4.374s and the size becomes to 27568 bytes.

This is intended to be a NFC patch.

This patch doesn't optimize all such cases. We can do it later after we
have consensus on this.
---
 clang/include/clang/AST/Decl.h|   2 +-
 clang/include/clang/AST/DeclBase.h|   2 +-
 clang/lib/Serialization/ASTReaderDecl.cpp | 229 +-
 clang/lib/Serialization/ASTWriter.cpp |  41 +-
 clang/lib/Serialization/ASTWriterDecl.cpp | 396 +++---
 clang/test/Modules/decl-params-determinisim.m |  16 +-
 6 files changed, 330 insertions(+), 356 deletions(-)

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 7f076cc77ea82cb..cd9a830dbaaf426 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -4073,7 +4073,7 @@ class RecordDecl : public TagDecl {
   /// returned from function calls. This takes into account the target-specific
   /// and version-specific rules along with the rules determined by the
   /// language.
-  enum ArgPassingKind : unsigned {
+  enum ArgPassingKind : unsigned char {
 /// The argument of this type can be passed directly in registers.
 APK_CanPassInRegs,
 
diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index d383e46e22e16f4..7a30529f1f73d74 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -211,7 +211,7 @@ class alignas(8) Decl {
   /// The kind of ownership a declaration has, for visibility purposes.
   /// This enumeration is designed such that higher values represent higher
   /// levels of name hiding.
-  enum class ModuleOwnershipKind : unsigned {
+  enum class ModuleOwnershipKind : unsigned char {
 /// This declaration is not owned by a module.
 Unowned,
 
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index 3a3477c39efae25..2a6f142ec0e87c8 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -617,24 +617,27 @@ void ASTDeclReader::VisitDecl(Decl *D) {
Reader.getContext());
   }
   D->setLocation(ThisDeclLoc);
-  D->InvalidDecl = Record.readInt();
-  if (Record.readInt()) { // hasAttrs
+
+  uint64_t DeclBits = Record.readInt();
+  D->InvalidDecl = DeclBits & 0x1;
+  D->setImplicit(DeclBits & (1 << 2));
+  D->Used = (DeclBits >> 3) & 0x1;
+  IsDeclMarkedUsed |= D->Used;
+  D->setReferenced(DeclBits & (1 << 4));
+  D->setTopLevelDeclInObjCContainer(DeclBits & (1 << 5));
+  D->setAccess((AccessSpecifier)((DeclBits >> 6) & 0x3));
+  D->FromASTFile = true;
+  auto ModuleOwnership = (Decl::ModuleOwnershipKind)((DeclBits >> 8) & 0x7);
+  bool ModulePrivate =
+  (ModuleOwnership == Decl::ModuleOwnershipKind::ModulePrivate);
+
+  if (DeclBits & (0x1 << 1)) { // hasAttrs
 AttrVec Attrs;
 Record.readAttributes(Attrs);
 // Avoid calling setAttrs() directly because it uses Decl::getASTContext()
 // internally which is unsafe during derialization.
 D->setAttrsImpl(Attrs, Reader.getContext());
   }
-  D->setImplicit(Record.readInt());
-  D->Used = Record.readInt();
-  IsDeclMarkedUsed |= D->Used;
-  D->setReferenced(Record.readInt());
-  D->setTopLevelDeclInObjCContainer(Record.readInt());
-  D->setAccess((AccessSpecifier)Record.readInt());
-  D->FromASTFile = true;
-  auto ModuleOwnership = (Decl::ModuleOwnershipKind)Record.readInt();
-  bool ModulePrivate =
-  (ModuleOwnership == Decl::ModuleOwnershipKind::ModulePrivate);
 
   // Determine whether this declaration is part of a (sub)module. If so, it
   // may not yet be visible.
@@ -750,12 +753,14 @@ ASTDeclReader::RedeclarableResult 
ASTDeclReader::VisitTagDecl(TagDecl *TD) {
   VisitTypeDecl(TD);
 
   TD->IdentifierNamespace = Record.readInt();
-  TD->setTagKind((TagDecl::TagKind)Record.readInt());
+
+  uint32_t TagDeclBits = Record.readInt();
+  TD->setTagKind((TagDecl::TagKind)(TagDeclBits & 0x7));
   if (!isa(TD))
-TD->setCompleteDefinition(Record.readInt());
-  TD->setEmbeddedInDeclarator(Record.readInt());
-  TD->setFreeStanding(Record.readInt());
-  TD->setCompleteDefinitionRequired(Record.readInt());
+TD->setCompleteDefinition(TagDeclBits & (0x1 << 3));
+

[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2023-10-16 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/66514

>From 11e7ee626abf9edbcdd2cdcd6ee79f7a0792788c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 15 Sep 2023 15:51:39 +0200
Subject: [PATCH 01/19] [clang][Diagnostics] Highlight code snippets

Add some primitive syntax highlighting to our code snippet output.
---
 .../clang/Frontend/CodeSnippetHighlighter.h   |  46 +++
 clang/include/clang/Frontend/TextDiagnostic.h |   2 +
 clang/lib/Frontend/CMakeLists.txt |   1 +
 clang/lib/Frontend/CodeSnippetHighlighter.cpp | 120 ++
 clang/lib/Frontend/TextDiagnostic.cpp |  26 
 5 files changed, 195 insertions(+)
 create mode 100644 clang/include/clang/Frontend/CodeSnippetHighlighter.h
 create mode 100644 clang/lib/Frontend/CodeSnippetHighlighter.cpp

diff --git a/clang/include/clang/Frontend/CodeSnippetHighlighter.h 
b/clang/include/clang/Frontend/CodeSnippetHighlighter.h
new file mode 100644
index 000..776954b59e2e1a8
--- /dev/null
+++ b/clang/include/clang/Frontend/CodeSnippetHighlighter.h
@@ -0,0 +1,46 @@
+//===--- CodeSnippetHighlighter.h - Code snippet highlighting ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_FRONTEND_CODESNIPPETHIGHLIGHTER_H
+#define LLVM_CLANG_FRONTEND_CODESNIPPETHIGHLIGHTER_H
+
+#include "clang/Basic/LangOptions.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+namespace clang {
+
+struct StyleRange {
+  unsigned Start;
+  unsigned End;
+  const enum llvm::raw_ostream::Colors c;
+};
+
+class CodeSnippetHighlighter final {
+public:
+  CodeSnippetHighlighter() = default;
+
+  /// Produce StyleRanges for the given line.
+  /// The returned vector contains non-overlapping style ranges. They are 
sorted
+  /// from beginning of the line to the end.
+  std::vector highlightLine(llvm::StringRef SourceLine,
+const LangOptions &LangOpts);
+
+private:
+  bool Initialized = false;
+  /// Fills Keywords and Literals.
+  void ensureTokenData();
+
+  llvm::SmallSet Keywords;
+  llvm::SmallSet Literals;
+};
+
+} // namespace clang
+
+#endif
diff --git a/clang/include/clang/Frontend/TextDiagnostic.h 
b/clang/include/clang/Frontend/TextDiagnostic.h
index 7eb0ab0cdc9bca8..59fd4d4f9408d48 100644
--- a/clang/include/clang/Frontend/TextDiagnostic.h
+++ b/clang/include/clang/Frontend/TextDiagnostic.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 #define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 
+#include "clang/Frontend/CodeSnippetHighlighter.h"
 #include "clang/Frontend/DiagnosticRenderer.h"
 
 namespace clang {
@@ -33,6 +34,7 @@ namespace clang {
 /// printing coming out of libclang.
 class TextDiagnostic : public DiagnosticRenderer {
   raw_ostream &OS;
+  CodeSnippetHighlighter SnippetHighlighter;
 
 public:
   TextDiagnostic(raw_ostream &OS,
diff --git a/clang/lib/Frontend/CMakeLists.txt 
b/clang/lib/Frontend/CMakeLists.txt
index 1e5f0a859dfd568..f3547f771593093 100644
--- a/clang/lib/Frontend/CMakeLists.txt
+++ b/clang/lib/Frontend/CMakeLists.txt
@@ -42,6 +42,7 @@ add_clang_library(clangFrontend
   TextDiagnosticPrinter.cpp
   VerifyDiagnosticConsumer.cpp
   InterfaceStubFunctionsConsumer.cpp
+  CodeSnippetHighlighter.cpp
 
   DEPENDS
   ClangDriverOptions
diff --git a/clang/lib/Frontend/CodeSnippetHighlighter.cpp 
b/clang/lib/Frontend/CodeSnippetHighlighter.cpp
new file mode 100644
index 000..829a533ad2692e5
--- /dev/null
+++ b/clang/lib/Frontend/CodeSnippetHighlighter.cpp
@@ -0,0 +1,120 @@
+
+#include "clang/Frontend/CodeSnippetHighlighter.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Lexer.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace clang;
+
+void CodeSnippetHighlighter::ensureTokenData() {
+  if (Initialized)
+return;
+
+  // List of keywords, literals and types we want to highlight.
+  // These are best-effort, as is everything we do wrt. highlighting.
+  Keywords.insert("_Static_assert");
+  Keywords.insert("auto");
+  Keywords.insert("concept");
+  Keywords.insert("const");
+  Keywords.insert("consteval");
+  Keywords.insert("constexpr");
+  Keywords.

[clang] [NFC] [Serializer] Pack information in serializer (PR #69287)

2023-10-16 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 12a731b5a4cfec96ba7c72888a1d76b8e13b043e 
d6a724d38b67f33d97d25459564c3926d72c22dc -- clang/include/clang/AST/Decl.h 
clang/include/clang/AST/DeclBase.h clang/lib/Serialization/ASTReaderDecl.cpp 
clang/lib/Serialization/ASTWriterDecl.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index 62b2665c2..acdebb2dd 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -850,11 +850,13 @@ ASTDeclReader::VisitRecordDeclImpl(RecordDecl *RD) {
   RD->setNonTrivialToPrimitiveDefaultInitialize(RecordDeclBits & (1 << 4));
   RD->setNonTrivialToPrimitiveCopy(RecordDeclBits & (1 << 5));
   RD->setNonTrivialToPrimitiveDestroy(RecordDeclBits & (1 << 6));
-  RD->setHasNonTrivialToPrimitiveDefaultInitializeCUnion(RecordDeclBits & (1 
<< 7));
+  RD->setHasNonTrivialToPrimitiveDefaultInitializeCUnion(RecordDeclBits &
+ (1 << 7));
   RD->setHasNonTrivialToPrimitiveDestructCUnion(RecordDeclBits & (1 << 8));
   RD->setHasNonTrivialToPrimitiveCopyCUnion(RecordDeclBits & (1 << 9));
   RD->setParamDestroyedInCallee(RecordDeclBits & (1 << 10));
-  RD->setArgPassingRestrictions((RecordDecl::ArgPassingKind)((RecordDeclBits 
>> 11) & 0x3));
+  RD->setArgPassingRestrictions(
+  (RecordDecl::ArgPassingKind)((RecordDeclBits >> 11) & 0x3));
   return Redecl;
 }
 
@@ -1074,12 +1076,14 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) 
{
   FD->setExplicitlyDefaulted(FunctionDeclBits & (1 << 13));
   FD->setIneligibleOrNotSelected(FunctionDeclBits & (1 << 14));
   FD->setHasImplicitReturnZero(FunctionDeclBits & (1 << 15));
-  FD->setConstexprKind(static_cast((FunctionDeclBits >> 16) 
& 0x3));
+  FD->setConstexprKind(
+  static_cast((FunctionDeclBits >> 16) & 0x3));
   FD->setUsesSEHTry(FunctionDeclBits & (1 << 18));
   FD->setHasSkippedBody(FunctionDeclBits & (1 << 19));
   FD->setIsMultiVersion(FunctionDeclBits & (1 << 20));
   FD->setLateTemplateParsed(FunctionDeclBits & (1 << 21));
-  FD->setFriendConstraintRefersToEnclosingTemplate(FunctionDeclBits & (1 << 
22));
+  FD->setFriendConstraintRefersToEnclosingTemplate(FunctionDeclBits &
+   (1 << 22));
   FD->setCachedLinkage(static_cast((FunctionDeclBits >> 23) & 0x7));
 
   FD->EndRangeLoc = readSourceLocation();
@@ -1592,16 +1596,18 @@ ASTDeclReader::RedeclarableResult 
ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) {
   bool HasDeducedType = false;
   if (!isa(VD)) {
 VD->NonParmVarDeclBits.IsThisDeclarationADemotedDefinition =
- (bool)(RecordDeclBits & (1 << 8));
+(bool)(RecordDeclBits & (1 << 8));
 VD->NonParmVarDeclBits.ExceptionVar = (bool)(RecordDeclBits & (1 << 9));
 VD->NonParmVarDeclBits.NRVOVariable = (bool)(RecordDeclBits & (1 << 10));
 VD->NonParmVarDeclBits.CXXForRangeDecl = (bool)(RecordDeclBits & (1 << 
11));
 VD->NonParmVarDeclBits.ObjCForDecl = (bool)(RecordDeclBits & (1 << 12));
 VD->NonParmVarDeclBits.IsInline = (bool)(RecordDeclBits & (1 << 13));
-VD->NonParmVarDeclBits.IsInlineSpecified = (bool)(RecordDeclBits & (1 << 
14));
+VD->NonParmVarDeclBits.IsInlineSpecified =
+(bool)(RecordDeclBits & (1 << 14));
 VD->NonParmVarDeclBits.IsConstexpr = (bool)(RecordDeclBits & (1 << 15));
 VD->NonParmVarDeclBits.IsInitCapture = (bool)(RecordDeclBits & (1 << 16));
-VD->NonParmVarDeclBits.PreviousDeclInSameBlockScope = 
(bool)(RecordDeclBits & (1 << 17));
+VD->NonParmVarDeclBits.PreviousDeclInSameBlockScope =
+(bool)(RecordDeclBits & (1 << 17));
 VD->NonParmVarDeclBits.ImplicitParamKind = (RecordDeclBits >> 18) & 0x7;
 VD->NonParmVarDeclBits.EscapingByref = (bool)(RecordDeclBits & (1 << 21));
 HasDeducedType = (bool)(RecordDeclBits & (1 << 22));
@@ -1703,7 +1709,8 @@ void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
 PD->setScopeInfo(scopeDepth, scopeIndex);
   }
   PD->ParmVarDeclBits.IsKNRPromoted = (bool)(ParmVarDeclBits & (1 << 16));
-  PD->ParmVarDeclBits.HasInheritedDefaultArg = (bool)(ParmVarDeclBits & (1 << 
17));
+  PD->ParmVarDeclBits.HasInheritedDefaultArg =
+  (bool)(ParmVarDeclBits & (1 << 17));
   if ((bool)(ParmVarDeclBits & (1 << 18))) // hasUninstantiatedDefaultArg.
 PD->setUninstantiatedDefaultArg(Record.readExpr());
   PD->ExplicitObjectParameterIntroducerLoc = Record.readSourceLocation();
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp 
b/clang/lib/Serialization/ASTWriterDecl.cpp
index 96cdfec14..c48672b0b 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -687,7 +687,8 @@ void ASTDeclWriter::Vis

[clang] [NFC] [Serializer] Pack information in serializer (PR #69287)

2023-10-16 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/69287

>From 326bc3a4a24cfd515f2673e5a01bd30b3b1bf6bc Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Mon, 16 Oct 2023 16:41:31 +0800
Subject: [PATCH] [NFC] [Serializer] Pack information in serializer

Previously, the boolean values will occupy spaces that can contain
integers. It wastes the spaces especially if the boolean values are
serialized consecutively. The patch tries to pack such consecutive
boolean values (and enum values) so that we can save more spaces and so
the times.

Before the patch, we need 4.478s (in my machine) to build the std module
(https://libcxx.llvm.org/Modules.html) with 28712 bytes. After the
patch, the time becomes to 4.374s and the size becomes to 27568 bytes.

This is intended to be a NFC patch.

This patch doesn't optimize all such cases. We can do it later after we
have consensus on this.
---
 clang/include/clang/AST/Decl.h|   2 +-
 clang/include/clang/AST/DeclBase.h|   2 +-
 clang/lib/Serialization/ASTReaderDecl.cpp | 198 +
 clang/lib/Serialization/ASTWriterDecl.cpp | 396 +++---
 clang/test/Modules/decl-params-determinisim.m |  16 +-
 5 files changed, 276 insertions(+), 338 deletions(-)

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 7f076cc77ea82cb..cd9a830dbaaf426 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -4073,7 +4073,7 @@ class RecordDecl : public TagDecl {
   /// returned from function calls. This takes into account the target-specific
   /// and version-specific rules along with the rules determined by the
   /// language.
-  enum ArgPassingKind : unsigned {
+  enum ArgPassingKind : unsigned char {
 /// The argument of this type can be passed directly in registers.
 APK_CanPassInRegs,
 
diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index d383e46e22e16f4..7a30529f1f73d74 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -211,7 +211,7 @@ class alignas(8) Decl {
   /// The kind of ownership a declaration has, for visibility purposes.
   /// This enumeration is designed such that higher values represent higher
   /// levels of name hiding.
-  enum class ModuleOwnershipKind : unsigned {
+  enum class ModuleOwnershipKind : unsigned char {
 /// This declaration is not owned by a module.
 Unowned,
 
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index 3a3477c39efae25..acdebb2dd498cda 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -617,24 +617,27 @@ void ASTDeclReader::VisitDecl(Decl *D) {
Reader.getContext());
   }
   D->setLocation(ThisDeclLoc);
-  D->InvalidDecl = Record.readInt();
-  if (Record.readInt()) { // hasAttrs
+
+  uint64_t DeclBits = Record.readInt();
+  D->InvalidDecl = DeclBits & 0x1;
+  D->setImplicit(DeclBits & (1 << 2));
+  D->Used = (DeclBits >> 3) & 0x1;
+  IsDeclMarkedUsed |= D->Used;
+  D->setReferenced(DeclBits & (1 << 4));
+  D->setTopLevelDeclInObjCContainer(DeclBits & (1 << 5));
+  D->setAccess((AccessSpecifier)((DeclBits >> 6) & 0x3));
+  D->FromASTFile = true;
+  auto ModuleOwnership = (Decl::ModuleOwnershipKind)((DeclBits >> 8) & 0x7);
+  bool ModulePrivate =
+  (ModuleOwnership == Decl::ModuleOwnershipKind::ModulePrivate);
+
+  if (DeclBits & (0x1 << 1)) { // hasAttrs
 AttrVec Attrs;
 Record.readAttributes(Attrs);
 // Avoid calling setAttrs() directly because it uses Decl::getASTContext()
 // internally which is unsafe during derialization.
 D->setAttrsImpl(Attrs, Reader.getContext());
   }
-  D->setImplicit(Record.readInt());
-  D->Used = Record.readInt();
-  IsDeclMarkedUsed |= D->Used;
-  D->setReferenced(Record.readInt());
-  D->setTopLevelDeclInObjCContainer(Record.readInt());
-  D->setAccess((AccessSpecifier)Record.readInt());
-  D->FromASTFile = true;
-  auto ModuleOwnership = (Decl::ModuleOwnershipKind)Record.readInt();
-  bool ModulePrivate =
-  (ModuleOwnership == Decl::ModuleOwnershipKind::ModulePrivate);
 
   // Determine whether this declaration is part of a (sub)module. If so, it
   // may not yet be visible.
@@ -750,12 +753,14 @@ ASTDeclReader::RedeclarableResult 
ASTDeclReader::VisitTagDecl(TagDecl *TD) {
   VisitTypeDecl(TD);
 
   TD->IdentifierNamespace = Record.readInt();
-  TD->setTagKind((TagDecl::TagKind)Record.readInt());
+
+  uint32_t TagDeclBits = Record.readInt();
+  TD->setTagKind((TagDecl::TagKind)(TagDeclBits & 0x7));
   if (!isa(TD))
-TD->setCompleteDefinition(Record.readInt());
-  TD->setEmbeddedInDeclarator(Record.readInt());
-  TD->setFreeStanding(Record.readInt());
-  TD->setCompleteDefinitionRequired(Record.readInt());
+TD->setCompleteDefinition(TagDeclBits & (0x1 << 3));
+  TD->setEmbeddedInDeclarator(TagDeclBits & (0x1 << 4));

[clang] [Clang] Fix dependence handling of nttp for variable templates (PR #69075)

2023-10-16 Thread Fangrui Song via cfe-commits
=?utf-8?b?5YiY6Zuo5Z+5?= 
Message-ID:
In-Reply-To: 


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


[clang] 4b8b70a - [Clang] Fix dependence handling of nttp for variable templates (#69075)

2023-10-16 Thread via cfe-commits

Author: 刘雨培
Date: 2023-10-16T22:23:28-07:00
New Revision: 4b8b70a52fa4d133a19f620c8a9160793ded08b5

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

LOG: [Clang] Fix dependence handling of nttp for variable templates (#69075)

The dependence of a template argument is not only determined by the
argument itself, but also by the type of the template parameter:

> Furthermore, a non-type
[template-argument](https://eel.is/c++draft/temp.names#nt:template-argument)
is dependent if the corresponding non-type
[template-parameter](https://eel.is/c++draft/temp.param#nt:template-parameter)
is of reference or pointer type and the
[template-argument](https://eel.is/c++draft/temp.names#nt:template-argument)
designates or points to a member of the current instantiation or a
member of a dependent
type[.](https://eel.is/c++draft/temp.dep#temp-3.sentence-1)

For example:

```cpp
struct A{};

template 
const A JoinStringViews = T;

template 
class Builder {
public:
static constexpr A Equal{};
static constexpr auto Val = JoinStringViews;
};
```

The constant expression `Equal` is not dependent, but because the type
of the template parameter is a reference type and `Equal` is a member of
the current instantiation, the template argument of
`JoinStringViews` is actually dependent, which makes
`JoinStringViews` dependent.

When a template-id of a variable template is dependent,
`CheckVarTemplateId` will return an `UnresolvedLookupExpr`, but
`UnresolvedLookupExpr` calculates dependence by template arguments only
(the `ConstantExpr` `Equal` here), which is not dependent. This causes
type deduction to think that `JoinStringViews` is `OverloadTy`
and treat it as a function template, which is clearly wrong.

This PR adds a `KnownDependent` parameter to the constructor of
`UnresolvedLookupExpr`. After canonicalization, if `CanonicalConverted`
contains any dependent argument, `KnownDependent` is set to `true`. This
fixes the dependence calculation of `UnresolvedLookupExpr` for dependent
variable templates.

Fixes #65153 .

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ExprCXX.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/ExprCXX.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/SemaTemplate/dependent-expr.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 99525b00239a4ca..81cbfd90155fe0b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -516,6 +516,10 @@ Bug Fixes to C++ Support
   rather than prefer the non-templated constructor as specified in
   [standard.group]p3.
 
+- Fixed a crash caused by incorrect handling of dependence on variable 
templates
+  with non-type template parameters of reference type. Fixes:
+  (`#65153 `_)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.

diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 17dbb5e888ebdd3..798c98cfcf2d4db 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -3191,7 +3191,8 @@ class UnresolvedLookupExpr final
const DeclarationNameInfo &NameInfo, bool RequiresADL,
bool Overloaded,
const TemplateArgumentListInfo *TemplateArgs,
-   UnresolvedSetIterator Begin, UnresolvedSetIterator End);
+   UnresolvedSetIterator Begin, UnresolvedSetIterator End,
+   bool KnownDependent);
 
   UnresolvedLookupExpr(EmptyShell Empty, unsigned NumResults,
bool HasTemplateKWAndArgsInfo);
@@ -3211,12 +3212,15 @@ class UnresolvedLookupExpr final
  const DeclarationNameInfo &NameInfo, bool RequiresADL, bool 
Overloaded,
  UnresolvedSetIterator Begin, UnresolvedSetIterator End);
 
+  // After canonicalization, there may be dependent template arguments in
+  // CanonicalConverted But none of Args is dependent. When any of
+  // CanonicalConverted dependent, KnownDependent is true.
   static UnresolvedLookupExpr *
   Create(const ASTContext &Context, CXXRecordDecl *NamingClass,
  NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
  const DeclarationNameInfo &NameInfo, bool RequiresADL,
  const TemplateArgumentListInfo *Args, UnresolvedSetIterator Begin,
- UnresolvedSetIterator End);
+ UnresolvedSetIterator End, bool KnownDependent);
 
   static UnresolvedLookupExpr *CreateEmpty(const ASTContext &Context,
unsigned NumResults,

diff  --git a/clang/lib/AST/ASTImporter

[clang] [Clang] Fix dependence handling of nttp for variable templates (PR #69075)

2023-10-16 Thread Fangrui Song via cfe-commits
=?utf-8?b?5YiY6Zuo5Z+5?= 
Message-ID:
In-Reply-To: 


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


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


[clang] [NFC] [Serializer] Pack information in serializer (PR #69287)

2023-10-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Chuanqi Xu (ChuanqiXu9)


Changes

Previously, the boolean values will occupy spaces that can contain integers. It 
wastes the spaces especially if the boolean values are serialized 
consecutively. The patch tries to pack such consecutive boolean values (and 
enum values) so that we can save more spaces and so the times.

Before the patch, we need 4.478s (in my machine) to build the std module 
(https://libcxx.llvm.org/Modules.html) with 28712 bytes. After the patch, the 
time becomes to 4.374s and the size becomes to 27568 bytes.

This is intended to be a NFC patch.

This patch doesn't optimize all such cases. We can do it later after we have 
consensus on this.

---

Patch is 45.79 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/69287.diff


5 Files Affected:

- (modified) clang/include/clang/AST/Decl.h (+1-1) 
- (modified) clang/include/clang/AST/DeclBase.h (+1-1) 
- (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+103-88) 
- (modified) clang/lib/Serialization/ASTWriterDecl.cpp (+155-240) 
- (modified) clang/test/Modules/decl-params-determinisim.m (+8-8) 


``diff
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 7f076cc77ea82cb..cd9a830dbaaf426 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -4073,7 +4073,7 @@ class RecordDecl : public TagDecl {
   /// returned from function calls. This takes into account the target-specific
   /// and version-specific rules along with the rules determined by the
   /// language.
-  enum ArgPassingKind : unsigned {
+  enum ArgPassingKind : unsigned char {
 /// The argument of this type can be passed directly in registers.
 APK_CanPassInRegs,
 
diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index d383e46e22e16f4..7a30529f1f73d74 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -211,7 +211,7 @@ class alignas(8) Decl {
   /// The kind of ownership a declaration has, for visibility purposes.
   /// This enumeration is designed such that higher values represent higher
   /// levels of name hiding.
-  enum class ModuleOwnershipKind : unsigned {
+  enum class ModuleOwnershipKind : unsigned char {
 /// This declaration is not owned by a module.
 Unowned,
 
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index 3a3477c39efae25..62b2665c2211029 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -617,24 +617,27 @@ void ASTDeclReader::VisitDecl(Decl *D) {
Reader.getContext());
   }
   D->setLocation(ThisDeclLoc);
-  D->InvalidDecl = Record.readInt();
-  if (Record.readInt()) { // hasAttrs
+
+  uint64_t DeclBits = Record.readInt();
+  D->InvalidDecl = DeclBits & 0x1;
+  D->setImplicit(DeclBits & (1 << 2));
+  D->Used = (DeclBits >> 3) & 0x1;
+  IsDeclMarkedUsed |= D->Used;
+  D->setReferenced(DeclBits & (1 << 4));
+  D->setTopLevelDeclInObjCContainer(DeclBits & (1 << 5));
+  D->setAccess((AccessSpecifier)((DeclBits >> 6) & 0x3));
+  D->FromASTFile = true;
+  auto ModuleOwnership = (Decl::ModuleOwnershipKind)((DeclBits >> 8) & 0x7);
+  bool ModulePrivate =
+  (ModuleOwnership == Decl::ModuleOwnershipKind::ModulePrivate);
+
+  if (DeclBits & (0x1 << 1)) { // hasAttrs
 AttrVec Attrs;
 Record.readAttributes(Attrs);
 // Avoid calling setAttrs() directly because it uses Decl::getASTContext()
 // internally which is unsafe during derialization.
 D->setAttrsImpl(Attrs, Reader.getContext());
   }
-  D->setImplicit(Record.readInt());
-  D->Used = Record.readInt();
-  IsDeclMarkedUsed |= D->Used;
-  D->setReferenced(Record.readInt());
-  D->setTopLevelDeclInObjCContainer(Record.readInt());
-  D->setAccess((AccessSpecifier)Record.readInt());
-  D->FromASTFile = true;
-  auto ModuleOwnership = (Decl::ModuleOwnershipKind)Record.readInt();
-  bool ModulePrivate =
-  (ModuleOwnership == Decl::ModuleOwnershipKind::ModulePrivate);
 
   // Determine whether this declaration is part of a (sub)module. If so, it
   // may not yet be visible.
@@ -750,12 +753,14 @@ ASTDeclReader::RedeclarableResult 
ASTDeclReader::VisitTagDecl(TagDecl *TD) {
   VisitTypeDecl(TD);
 
   TD->IdentifierNamespace = Record.readInt();
-  TD->setTagKind((TagDecl::TagKind)Record.readInt());
+
+  uint32_t TagDeclBits = Record.readInt();
+  TD->setTagKind((TagDecl::TagKind)(TagDeclBits & 0x7));
   if (!isa(TD))
-TD->setCompleteDefinition(Record.readInt());
-  TD->setEmbeddedInDeclarator(Record.readInt());
-  TD->setFreeStanding(Record.readInt());
-  TD->setCompleteDefinitionRequired(Record.readInt());
+TD->setCompleteDefinition(TagDeclBits & (0x1 << 3));
+  TD->setEmbeddedInDeclarator(TagDeclBits & (0x1 << 4));
+  TD->setFreeStanding(TagDeclBits & (0x1 << 5));
+  TD->setCompleteDefi

[clang] [NFC] [Serializer] Pack information in serializer (PR #69287)

2023-10-16 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 created 
https://github.com/llvm/llvm-project/pull/69287

Previously, the boolean values will occupy spaces that can contain integers. It 
wastes the spaces especially if the boolean values are serialized 
consecutively. The patch tries to pack such consecutive boolean values (and 
enum values) so that we can save more spaces and so the times.

Before the patch, we need 4.478s (in my machine) to build the std module 
(https://libcxx.llvm.org/Modules.html) with 28712 bytes. After the patch, the 
time becomes to 4.374s and the size becomes to 27568 bytes.

This is intended to be a NFC patch.

This patch doesn't optimize all such cases. We can do it later after we have 
consensus on this.

>From d6a724d38b67f33d97d25459564c3926d72c22dc Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Mon, 16 Oct 2023 16:41:31 +0800
Subject: [PATCH] [NFC] [Serializer] Pack information in serializer

Previously, the boolean values will occupy spaces that can contain
integers. It wastes the spaces especially if the boolean values are
serialized consecutively. The patch tries to pack such consecutive
boolean values (and enum values) so that we can save more spaces and so
the times.

Before the patch, we need 4.478s (in my machine) to build the std module
(https://libcxx.llvm.org/Modules.html) with 28712 bytes. After the
patch, the time becomes to 4.374s and the size becomes to 27568 bytes.

This is intended to be a NFC patch.

This patch doesn't optimize all such cases. We can do it later after we
have consensus on this.
---
 clang/include/clang/AST/Decl.h|   2 +-
 clang/include/clang/AST/DeclBase.h|   2 +-
 clang/lib/Serialization/ASTReaderDecl.cpp | 191 +
 clang/lib/Serialization/ASTWriterDecl.cpp | 395 +++---
 clang/test/Modules/decl-params-determinisim.m |  16 +-
 5 files changed, 268 insertions(+), 338 deletions(-)

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 7f076cc77ea82cb..cd9a830dbaaf426 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -4073,7 +4073,7 @@ class RecordDecl : public TagDecl {
   /// returned from function calls. This takes into account the target-specific
   /// and version-specific rules along with the rules determined by the
   /// language.
-  enum ArgPassingKind : unsigned {
+  enum ArgPassingKind : unsigned char {
 /// The argument of this type can be passed directly in registers.
 APK_CanPassInRegs,
 
diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index d383e46e22e16f4..7a30529f1f73d74 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -211,7 +211,7 @@ class alignas(8) Decl {
   /// The kind of ownership a declaration has, for visibility purposes.
   /// This enumeration is designed such that higher values represent higher
   /// levels of name hiding.
-  enum class ModuleOwnershipKind : unsigned {
+  enum class ModuleOwnershipKind : unsigned char {
 /// This declaration is not owned by a module.
 Unowned,
 
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index 3a3477c39efae25..62b2665c2211029 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -617,24 +617,27 @@ void ASTDeclReader::VisitDecl(Decl *D) {
Reader.getContext());
   }
   D->setLocation(ThisDeclLoc);
-  D->InvalidDecl = Record.readInt();
-  if (Record.readInt()) { // hasAttrs
+
+  uint64_t DeclBits = Record.readInt();
+  D->InvalidDecl = DeclBits & 0x1;
+  D->setImplicit(DeclBits & (1 << 2));
+  D->Used = (DeclBits >> 3) & 0x1;
+  IsDeclMarkedUsed |= D->Used;
+  D->setReferenced(DeclBits & (1 << 4));
+  D->setTopLevelDeclInObjCContainer(DeclBits & (1 << 5));
+  D->setAccess((AccessSpecifier)((DeclBits >> 6) & 0x3));
+  D->FromASTFile = true;
+  auto ModuleOwnership = (Decl::ModuleOwnershipKind)((DeclBits >> 8) & 0x7);
+  bool ModulePrivate =
+  (ModuleOwnership == Decl::ModuleOwnershipKind::ModulePrivate);
+
+  if (DeclBits & (0x1 << 1)) { // hasAttrs
 AttrVec Attrs;
 Record.readAttributes(Attrs);
 // Avoid calling setAttrs() directly because it uses Decl::getASTContext()
 // internally which is unsafe during derialization.
 D->setAttrsImpl(Attrs, Reader.getContext());
   }
-  D->setImplicit(Record.readInt());
-  D->Used = Record.readInt();
-  IsDeclMarkedUsed |= D->Used;
-  D->setReferenced(Record.readInt());
-  D->setTopLevelDeclInObjCContainer(Record.readInt());
-  D->setAccess((AccessSpecifier)Record.readInt());
-  D->FromASTFile = true;
-  auto ModuleOwnership = (Decl::ModuleOwnershipKind)Record.readInt();
-  bool ModulePrivate =
-  (ModuleOwnership == Decl::ModuleOwnershipKind::ModulePrivate);
 
   // Determine whether this declaration is part of a (sub)module. If so, it
   // may not yet be visible.
@@ -750,12 +753,14 @@ A

[clang] [Driver] Link Flang runtime on Solaris (PR #65644)

2023-10-16 Thread Brad Smith via cfe-commits

brad0 wrote:

> * renaming the current label from `GNU` to e.g. `UNIX` would be correct.

That would be fine with me.

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


[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2023-10-16 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/66514

>From 11e7ee626abf9edbcdd2cdcd6ee79f7a0792788c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 15 Sep 2023 15:51:39 +0200
Subject: [PATCH 01/18] [clang][Diagnostics] Highlight code snippets

Add some primitive syntax highlighting to our code snippet output.
---
 .../clang/Frontend/CodeSnippetHighlighter.h   |  46 +++
 clang/include/clang/Frontend/TextDiagnostic.h |   2 +
 clang/lib/Frontend/CMakeLists.txt |   1 +
 clang/lib/Frontend/CodeSnippetHighlighter.cpp | 120 ++
 clang/lib/Frontend/TextDiagnostic.cpp |  26 
 5 files changed, 195 insertions(+)
 create mode 100644 clang/include/clang/Frontend/CodeSnippetHighlighter.h
 create mode 100644 clang/lib/Frontend/CodeSnippetHighlighter.cpp

diff --git a/clang/include/clang/Frontend/CodeSnippetHighlighter.h 
b/clang/include/clang/Frontend/CodeSnippetHighlighter.h
new file mode 100644
index 000..776954b59e2e1a8
--- /dev/null
+++ b/clang/include/clang/Frontend/CodeSnippetHighlighter.h
@@ -0,0 +1,46 @@
+//===--- CodeSnippetHighlighter.h - Code snippet highlighting ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_FRONTEND_CODESNIPPETHIGHLIGHTER_H
+#define LLVM_CLANG_FRONTEND_CODESNIPPETHIGHLIGHTER_H
+
+#include "clang/Basic/LangOptions.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+namespace clang {
+
+struct StyleRange {
+  unsigned Start;
+  unsigned End;
+  const enum llvm::raw_ostream::Colors c;
+};
+
+class CodeSnippetHighlighter final {
+public:
+  CodeSnippetHighlighter() = default;
+
+  /// Produce StyleRanges for the given line.
+  /// The returned vector contains non-overlapping style ranges. They are 
sorted
+  /// from beginning of the line to the end.
+  std::vector highlightLine(llvm::StringRef SourceLine,
+const LangOptions &LangOpts);
+
+private:
+  bool Initialized = false;
+  /// Fills Keywords and Literals.
+  void ensureTokenData();
+
+  llvm::SmallSet Keywords;
+  llvm::SmallSet Literals;
+};
+
+} // namespace clang
+
+#endif
diff --git a/clang/include/clang/Frontend/TextDiagnostic.h 
b/clang/include/clang/Frontend/TextDiagnostic.h
index 7eb0ab0cdc9bca8..59fd4d4f9408d48 100644
--- a/clang/include/clang/Frontend/TextDiagnostic.h
+++ b/clang/include/clang/Frontend/TextDiagnostic.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 #define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 
+#include "clang/Frontend/CodeSnippetHighlighter.h"
 #include "clang/Frontend/DiagnosticRenderer.h"
 
 namespace clang {
@@ -33,6 +34,7 @@ namespace clang {
 /// printing coming out of libclang.
 class TextDiagnostic : public DiagnosticRenderer {
   raw_ostream &OS;
+  CodeSnippetHighlighter SnippetHighlighter;
 
 public:
   TextDiagnostic(raw_ostream &OS,
diff --git a/clang/lib/Frontend/CMakeLists.txt 
b/clang/lib/Frontend/CMakeLists.txt
index 1e5f0a859dfd568..f3547f771593093 100644
--- a/clang/lib/Frontend/CMakeLists.txt
+++ b/clang/lib/Frontend/CMakeLists.txt
@@ -42,6 +42,7 @@ add_clang_library(clangFrontend
   TextDiagnosticPrinter.cpp
   VerifyDiagnosticConsumer.cpp
   InterfaceStubFunctionsConsumer.cpp
+  CodeSnippetHighlighter.cpp
 
   DEPENDS
   ClangDriverOptions
diff --git a/clang/lib/Frontend/CodeSnippetHighlighter.cpp 
b/clang/lib/Frontend/CodeSnippetHighlighter.cpp
new file mode 100644
index 000..829a533ad2692e5
--- /dev/null
+++ b/clang/lib/Frontend/CodeSnippetHighlighter.cpp
@@ -0,0 +1,120 @@
+
+#include "clang/Frontend/CodeSnippetHighlighter.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Lexer.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace clang;
+
+void CodeSnippetHighlighter::ensureTokenData() {
+  if (Initialized)
+return;
+
+  // List of keywords, literals and types we want to highlight.
+  // These are best-effort, as is everything we do wrt. highlighting.
+  Keywords.insert("_Static_assert");
+  Keywords.insert("auto");
+  Keywords.insert("concept");
+  Keywords.insert("const");
+  Keywords.insert("consteval");
+  Keywords.insert("constexpr");
+  Keywords.insert("delete");
+  Keyw

[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2023-10-16 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 



@@ -887,6 +906,9 @@ void Preprocessor::Lex(Token &Result) {
 switch (CurLexerKind) {
 case CLK_Lexer:
   ReturnedToken = CurLexer->Lex(Result);
+  if (ReturnedToken && CurLexer &&
+  CurLexer->getFileID() == SourceMgr.getMainFileID())
+saveCheckPoint(CurLexer->BufferPtr);

tbaederr wrote:

That would be 
http://llvm-compile-time-tracker.com/compare.php?from=6ade5183232dc1398205d7c9dbe21243b2560837&to=5ad516d39b6706af6fd55eded264aba4ba432ad2&stat=instructions:u

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


[clang] [Driver] Hook up Haiku PowerPC support (PR #69134)

2023-10-16 Thread Brad Smith via cfe-commits

brad0 wrote:

> Does backend have any recognition of Haiku-PPC target?

Can you clarify what it is you're referring to?

I didn't come across anything looking around under llvm/, but I might have 
missed something.

I was looking in clang/lib/Basic/Targets/PPC.cpp, but didn't see anything that 
needed adjusting there.

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


[clang] [clang][Interp] Check pointer inc/dec ops for null (PR #69168)

2023-10-16 Thread Timm Baeder via cfe-commits

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


[clang] 7bc793a - [clang][Interp] Check pointer inc/dec ops for null (#69168)

2023-10-16 Thread via cfe-commits

Author: Timm Baeder
Date: 2023-10-17T06:53:33+02:00
New Revision: 7bc793a6925ccebbe21f1c98a79d6dc89a615c01

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

LOG: [clang][Interp] Check pointer inc/dec ops for null (#69168)

Added: 


Modified: 
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/arrays.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index e3e6a4cec63b194..3d226a40f9cf608 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1488,11 +1488,14 @@ static inline bool IncDecPtrHelper(InterpState &S, 
CodePtr OpPC,
const Pointer &Ptr) {
   using OneT = Integral<8, false>;
 
+  const Pointer &P = Ptr.deref();
+  if (!CheckNull(S, OpPC, P, CSK_ArrayIndex))
+return false;
+
   // Get the current value on the stack.
-  S.Stk.push(Ptr.deref());
+  S.Stk.push(P);
 
   // Now the current Ptr again and a constant 1.
-  Pointer P = Ptr.deref();
   OneT One = OneT::from(1);
   if (!OffsetHelper(S, OpPC, One, P))
 return false;

diff  --git a/clang/test/AST/Interp/arrays.cpp 
b/clang/test/AST/Interp/arrays.cpp
index 281835f828bbd7c..18c4ae4354f54a0 100644
--- a/clang/test/AST/Interp/arrays.cpp
+++ b/clang/test/AST/Interp/arrays.cpp
@@ -333,6 +333,26 @@ namespace IncDec {
// expected-note {{in call to}} \
// ref-error {{not an integral constant 
expression}} \
   // ref-note {{in call to}}
+
+  constexpr int nullptr1(bool Pre) {
+int *a = nullptr;
+if (Pre)
+  ++a; // ref-note {{arithmetic on null pointer}} \
+   // expected-note {{arithmetic on null pointer}}
+else
+  a++; // ref-note {{arithmetic on null pointer}} \
+   // expected-note {{arithmetic on null pointer}}
+return 1;
+  }
+  static_assert(nullptr1(true) == 1, ""); // ref-error {{not an integral 
constant expression}} \
+  // ref-note {{in call to}} \
+  // expected-error {{not an integral 
constant expression}} \
+  // expected-note {{in call to}}
+
+  static_assert(nullptr1(false) == 1, ""); // ref-error {{not an integral 
constant expression}} \
+   // ref-note {{in call to}} \
+   // expected-error {{not an integral 
constant expression}} \
+   // expected-note {{in call to}}
 };
 
 namespace ZeroInit {



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


[clang-tools-extra] `clangd`: support `-stdlib=` flags from `compile_commands.json`. (PR #69283)

2023-10-16 Thread Chris Carlon via cfe-commits

https://github.com/cjc25 created https://github.com/llvm/llvm-project/pull/69283

The `--stdlib` flag can affect the system headers used by `clang` during 
compilation. By default, `clang` will use the platform-installed C++ standard 
headers, but with `--stdlib=libc++`, `clang` can use headers included in the 
distribution for its `libc++` implementation.

Prior to this patch, if `compile_commands.json` specified `-stdlib=libc++` or 
an equivalent form and `--query-driver` took effect, `clangd` would ignore 
`stdlib` and index based on the platform's headers. When these mismatch, e.g. 
due to version differences, `clangd`'s completions and the actual compilation 
can differ.

fixes clangd/clangd#1784

>From f9986bfc0a1202ade8e641e7a1b1e73576070a73 Mon Sep 17 00:00:00 2001
From: Chris Carlon 
Date: Sat, 14 Oct 2023 15:17:44 -0400
Subject: [PATCH] `clangd`: support `-stdlib=` flags from
 `compile_commands.json`.

The `--stdlib` flag can affect the system headers used by `clang` during
compilation. By default, `clang` will use the platform-installed C++ standard
headers, but with `--stdlib=libc++`, `clang` can use headers included in the
distribution for its `libc++` implementation.

Prior to this patch, if `compile_commands.json` specified `-stdlib=libc++` or
an equivalent form and `--query-driver` took effect, `clangd` would ignore it
and index based on the platform's headers. When these mismatch, e.g. due to
version differences, `clangd`'s completions and the actual compilation can
differ.

fixes clangd/clangd#1784
---
 .../clangd/SystemIncludeExtractor.cpp| 16 ++--
 .../clangd/test/system-include-extractor.test|  5 +++--
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp 
b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
index 74bae786425c829..158d4a940dee333 100644
--- a/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
+++ b/clang-tools-extra/clangd/SystemIncludeExtractor.cpp
@@ -88,12 +88,14 @@ struct DriverArgs {
   std::string Sysroot;
   std::string ISysroot;
   std::string Target;
+  std::string Stdlib;
 
   bool operator==(const DriverArgs &RHS) const {
 return std::tie(Driver, StandardIncludes, StandardCXXIncludes, Lang,
-Sysroot, ISysroot, Target) ==
+Sysroot, ISysroot, Target, Stdlib) ==
std::tie(RHS.Driver, RHS.StandardIncludes, RHS.StandardCXXIncludes,
-RHS.Lang, RHS.Sysroot, RHS.ISysroot, RHS.Target);
+RHS.Lang, RHS.Sysroot, RHS.ISysroot, RHS.Target,
+RHS.Stdlib);
   }
 
   DriverArgs(const tooling::CompileCommand &Cmd, llvm::StringRef File) {
@@ -136,6 +138,13 @@ struct DriverArgs {
   } else if (Arg.consume_front("-target")) {
 if (Arg.empty() && I + 1 < E)
   Target = Cmd.CommandLine[I + 1];
+  } else if (Arg.consume_front("--stdlib")) {
+if (Arg.consume_front("="))
+  Stdlib = Arg.str();
+else if (Arg.empty() && I + 1 < E)
+  Stdlib = Cmd.CommandLine[I + 1];
+  } else if (Arg.consume_front("-stdlib=")) {
+Stdlib = Arg.str();
   }
 }
 
@@ -175,6 +184,8 @@ struct DriverArgs {
   Args.append({"-isysroot", ISysroot});
 if (!Target.empty())
   Args.append({"-target", Target});
+if (!Stdlib.empty())
+  Args.append({"--stdlib", Stdlib});
 return Args;
   }
 
@@ -203,6 +214,7 @@ template <> struct DenseMapInfo {
 Val.Driver,
 Val.StandardIncludes,
 Val.StandardCXXIncludes,
+Val.Stdlib,
 Val.Lang,
 Val.Sysroot,
 Val.ISysroot,
diff --git a/clang-tools-extra/clangd/test/system-include-extractor.test 
b/clang-tools-extra/clangd/test/system-include-extractor.test
index 66882e424bb9216..cbb3018b2fa7349 100644
--- a/clang-tools-extra/clangd/test/system-include-extractor.test
+++ b/clang-tools-extra/clangd/test/system-include-extractor.test
@@ -18,6 +18,7 @@
 # RUN: echo '[ -z "${args##*"--sysroot /my/sysroot/path"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo '[ -z "${args##*"-isysroot /isysroot"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo '[ -z "${args##*"-target arm-linux-gnueabihf"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
+# RUN: echo '[ -z "${args##*"--stdlib libc++"*}" ] || exit' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo 'echo line to ignore >&2' >> %t.dir/bin/my_driver.sh
 # RUN: echo 'printf "Target: arm-linux-gnueabihf\r\n" >&2' >> 
%t.dir/bin/my_driver.sh
 # RUN: echo 'printf "#include <...> search starts here:\r\n" >&2' >> 
%t.dir/bin/my_driver.sh
@@ -37,7 +38,7 @@
 
 # Generate a compile_commands.json that will query the mock driver we've
 # created. Which should add a.h and b.h into include search path.
-# RUN: echo '[{"directory": "%/t.dir", "command": "my_driver.sh the-file.cpp 
--target=arm-linux-gnueabihf -nostdinc --sysroot /my/sysroot/path 
-isysroot/isysroot", "file": "the-file.cpp"}]' > %t.dir/co

[clang] [Driver][DragonFly] Fixes for linker path and command-line option handling (PR #69095)

2023-10-16 Thread Fangrui Song via cfe-commits

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


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


[clang] [Driver][DragonFly] Fixes for linker path and command-line option handling (PR #69095)

2023-10-16 Thread Fangrui Song via cfe-commits


@@ -56,7 +56,9 @@ void dragonfly::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
  const InputInfoList &Inputs,
  const ArgList &Args,
  const char *LinkingOutput) const {
-  const Driver &D = getToolChain().getDriver();
+  const toolchains::DragonFly &ToolChain =

MaskRay wrote:

`const auto &` as `static_cast` makes the type clear

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


[clang] [Driver][DragonFly] Fixes for linker path and command-line option handling (PR #69095)

2023-10-16 Thread Fangrui Song via cfe-commits

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


[clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

2023-10-16 Thread via cfe-commits

goldsteinn wrote:

> We should update LangRef and require that the integer arg has the size of the 
> pointer index type 
As in disallow say `ptrmask.p0.i32` on typical systems with 64-bit 
pointer/index?

> (with current GEP semantics implying a 1-extend to pointer type width), 
> implement a Verifier check for that, and add an assert in SDAG lowering that 
> the index type size is the pointer size -- I don't believe we currently have 
> any in-tree SDAG support for pointers with narrow index types, so this is 
> just a breadcrumb for out-of-tree targets to implement a 1-extend at that 
> point.
> 
> I was planning to do this, but never found the time.



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


[clang] [Clang] Check features of tune CPU against target CPU (PR #68861)

2023-10-16 Thread Chen Zheng via cfe-commits


@@ -833,6 +833,22 @@ TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags,
   if (!Target->handleTargetFeatures(Opts->Features, Diags))
 return nullptr;
 
+  // If TuneCPU is set, check if it contains all instruction sets needed by
+  // current feature map.
+  if (!Opts->TuneCPU.empty() && Opts->TuneCPU != Opts->CPU) {

chenzheng1030 wrote:

Can this handle the case that we use default cpu(i.e. no -mcpu set)?

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


[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2023-10-16 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 



@@ -878,6 +878,25 @@ bool Preprocessor::HandleIdentifier(Token &Identifier) {
   return true;
 }
 
+void Preprocessor::saveCheckPoint(const char *P) {
+  static constexpr ptrdiff_t Limit = 1024 * 8;
+  if (CheckPoints.empty()) {
+CheckPoints.push_back(P);
+return;
+  }
+
+  const char *Cur = CheckPoints.back();
+  if (Cur == P)
+return;

tbaederr wrote:

Thinking about this some more, I think this was only happening when I tested 
with `Limit = 1`. I'll re-check.

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


[clang] [Clang] Fix dependence handling of nttp for variable templates (PR #69075)

2023-10-16 Thread via cfe-commits

https://github.com/LYP951018 updated 
https://github.com/llvm/llvm-project/pull/69075

From 92e0cef2941d45bde9e08698ded277f8bf6ac04a Mon Sep 17 00:00:00 2001
From: letrec 
Date: Sun, 8 Oct 2023 00:44:11 +0800
Subject: [PATCH 1/3] Fix dependence handling for variable templates

---
 clang/include/clang/AST/ExprCXX.h  |  8 ++--
 clang/lib/AST/ASTImporter.cpp  |  5 -
 clang/lib/AST/ExprCXX.cpp  | 16 
 clang/lib/Sema/SemaDeclCXX.cpp |  5 +++--
 clang/lib/Sema/SemaTemplate.cpp| 14 ++
 clang/test/SemaTemplate/dependent-expr.cpp | 15 +++
 6 files changed, 42 insertions(+), 21 deletions(-)

diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 17dbb5e888ebdd3..798c98cfcf2d4db 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -3191,7 +3191,8 @@ class UnresolvedLookupExpr final
const DeclarationNameInfo &NameInfo, bool RequiresADL,
bool Overloaded,
const TemplateArgumentListInfo *TemplateArgs,
-   UnresolvedSetIterator Begin, UnresolvedSetIterator End);
+   UnresolvedSetIterator Begin, UnresolvedSetIterator End,
+   bool KnownDependent);
 
   UnresolvedLookupExpr(EmptyShell Empty, unsigned NumResults,
bool HasTemplateKWAndArgsInfo);
@@ -3211,12 +3212,15 @@ class UnresolvedLookupExpr final
  const DeclarationNameInfo &NameInfo, bool RequiresADL, bool 
Overloaded,
  UnresolvedSetIterator Begin, UnresolvedSetIterator End);
 
+  // After canonicalization, there may be dependent template arguments in
+  // CanonicalConverted But none of Args is dependent. When any of
+  // CanonicalConverted dependent, KnownDependent is true.
   static UnresolvedLookupExpr *
   Create(const ASTContext &Context, CXXRecordDecl *NamingClass,
  NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
  const DeclarationNameInfo &NameInfo, bool RequiresADL,
  const TemplateArgumentListInfo *Args, UnresolvedSetIterator Begin,
- UnresolvedSetIterator End);
+ UnresolvedSetIterator End, bool KnownDependent);
 
   static UnresolvedLookupExpr *CreateEmpty(const ASTContext &Context,
unsigned NumResults,
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 628a2b2bbca3986..650ff201e66b72e 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -8395,10 +8395,13 @@ 
ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
 if (!ToTemplateKeywordLocOrErr)
   return ToTemplateKeywordLocOrErr.takeError();
 
+const bool KnownDependent =
+(E->getDependence() & ExprDependence::TypeValue) ==
+ExprDependence::TypeValue;
 return UnresolvedLookupExpr::Create(
 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
 *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
-ToDecls.begin(), ToDecls.end());
+ToDecls.begin(), ToDecls.end(), KnownDependent);
   }
 
   return UnresolvedLookupExpr::Create(
diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp
index 06163255f9b5e54..5fbfa3a78124653 100644
--- a/clang/lib/AST/ExprCXX.cpp
+++ b/clang/lib/AST/ExprCXX.cpp
@@ -354,10 +354,10 @@ UnresolvedLookupExpr::UnresolvedLookupExpr(
 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
 const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded,
 const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin,
-UnresolvedSetIterator End)
+UnresolvedSetIterator End, bool KnownDependent)
 : OverloadExpr(UnresolvedLookupExprClass, Context, QualifierLoc,
-   TemplateKWLoc, NameInfo, TemplateArgs, Begin, End, false,
-   false, false),
+   TemplateKWLoc, NameInfo, TemplateArgs, Begin, End,
+   KnownDependent, false, false),
   NamingClass(NamingClass) {
   UnresolvedLookupExprBits.RequiresADL = RequiresADL;
   UnresolvedLookupExprBits.Overloaded = Overloaded;
@@ -380,7 +380,7 @@ UnresolvedLookupExpr *UnresolvedLookupExpr::Create(
   void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr));
   return new (Mem) UnresolvedLookupExpr(Context, NamingClass, QualifierLoc,
 SourceLocation(), NameInfo, 
RequiresADL,
-Overloaded, nullptr, Begin, End);
+Overloaded, nullptr, Begin, End, 
false);
 }
 
 UnresolvedLookupExpr *UnresolvedLookupExpr::Create(
@@ -388,7 +388,7 @@ UnresolvedLookupExpr *UnresolvedLookupExpr::Create(
 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
 const DeclarationNameInfo &N

[clang] [Clang] Support target attr specifying CPU (PR #68678)

2023-10-16 Thread Qiu Chaofan via cfe-commits


@@ -2420,11 +2420,11 @@ command line.
 
 The current set of options correspond to the existing "subtarget features" for
 the target with or without a "-mno-" in front corresponding to the absence
-of the feature, as well as ``arch="CPU"`` which will change the default "CPU"
-for the function.
+of the feature, as well as ``arch="CPU"`` and ``cpu="CPU"`` which will change
+the default "CPU" for the function.

ecnelises wrote:

Thanks for explanation. Then x86 should be the special one, not aarch64.

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


[clang-tools-extra] [Clang] Support target attr specifying CPU (PR #68678)

2023-10-16 Thread Qiu Chaofan via cfe-commits


@@ -2420,11 +2420,11 @@ command line.
 
 The current set of options correspond to the existing "subtarget features" for
 the target with or without a "-mno-" in front corresponding to the absence
-of the feature, as well as ``arch="CPU"`` which will change the default "CPU"
-for the function.
+of the feature, as well as ``arch="CPU"`` and ``cpu="CPU"`` which will change
+the default "CPU" for the function.

ecnelises wrote:

Thanks for explanation. Then x86 should be the special one, not aarch64.

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-10-16 Thread Vassil Vassilev via cfe-commits


@@ -0,0 +1,65 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t %t/main.cpp -o %t/main.o

vgvassilev wrote:

I thought this is a frontend issue -- do we need `-emit-obj` here?

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-10-16 Thread Vassil Vassilev via cfe-commits


@@ -0,0 +1,65 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t %t/main.cpp -o %t/main.o
+
+//--- V.h
+#ifndef V_H
+#define V_H
+
+class A {
+public:
+  constexpr A() { }
+  constexpr ~A() { }
+};
+
+template 
+class V {
+public:
+  V() = default;
+
+  constexpr V(int n, const A& a = A()) {}
+};
+
+#endif
+
+//--- inst1.h
+#include "V.h"
+
+static void inst1() {
+  V v;
+}
+
+//--- inst2.h
+#include "V.h"
+
+static void inst2() {
+  V v(100);
+}
+
+//--- module.modulemap
+module "M" {

vgvassilev wrote:

Is that the new standard nowadays? Can we use `#pragma clang module build` and 
alike to express the module setup?

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


[clang] [Docs][Clang] Missing DR status for C++23-era papers in cxx_status.html (PR #68846)

2023-10-16 Thread A. Jiang via cfe-commits

https://github.com/frederick-vs-ja edited 
https://github.com/llvm/llvm-project/pull/68846
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Docs][Clang] Missing DR status for C++23-era papers in cxx_status.html (PR #68846)

2023-10-16 Thread A. Jiang via cfe-commits

frederick-vs-ja wrote:

@Endilll Thanks for notification! P2280 was already handled, while P2156 was 
previously missed.
@cor3ntin I've add the DR status to P2156R1 and force-pushed.

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


[clang] [Docs][Clang] Missing DR status for C++23-era papers in cxx_status.html (PR #68846)

2023-10-16 Thread A. Jiang via cfe-commits

https://github.com/frederick-vs-ja updated 
https://github.com/llvm/llvm-project/pull/68846

>From 00dec85aabcbd2e93fa80aed7b21f7ce02aab589 Mon Sep 17 00:00:00 2001
From: "A. Jiang" 
Date: Tue, 17 Oct 2023 10:41:18 +0800
Subject: [PATCH] [Docs][Clang] DR status in cxx_status.html

---
 clang/www/cxx_status.html | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index e2cf9ab25465214..8e2869d3fdf8ac6 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -190,7 +190,7 @@ C++23 implementation status
 
 
   Allow duplicate attributes
-  https://wg21.link/P2156R1";>P2156R1
+  https://wg21.link/P2156R1";>P2156R1 (DR)
   Clang 13
 
 
@@ -210,7 +210,7 @@ C++23 implementation status
 
 
   C++ identifier syntax using UAX 31
-  https://wg21.link/P1949R7";>P1949R7
+  https://wg21.link/P1949R7";>P1949R7 (DR)
   Clang 14
 
 
@@ -230,11 +230,11 @@ C++23 implementation status
 
 
   Change scope of lambda trailing-return-type
-  https://wg21.link/P2036R3";>P2036R3
+  https://wg21.link/P2036R3";>P2036R3 (DR)
   Clang 17
 
 
-  https://wg21.link/P2579R0";>P2579R0
+  https://wg21.link/P2579R0";>P2579R0 (DR)
 
 
   Multidimensional subscript operator
@@ -303,12 +303,12 @@ C++23 implementation status
 
 
   The Equality Operator You Are Looking For
-  https://wg21.link/P2468R2";>P2468R2
+  https://wg21.link/P2468R2";>P2468R2 (DR)
   Clang 16
 
 
   De-deprecating volatile compound operations
-  https://wg21.link/P2327R1";>P2327R1
+  https://wg21.link/P2327R1";>P2327R1 (DR)
   Clang 15
 
 
@@ -380,7 +380,7 @@ C++23 implementation status
 
 
   char8_t Compatibility and Portability Fix
-  https://wg21.link/P2513R3";>P2513R3
+  https://wg21.link/P2513R3";>P2513R3 (DR)
   Clang 16
 
 
@@ -522,7 +522,7 @@ C++20 implementation status
 https://wg21.link/p2103r0";>P2103R0
   

-https://wg21.link/p2493r0";>P2493R0
+https://wg21.link/p2493r0";>P2493R0 (DR)
   
   
 https://wg21.link/p2092r0";>P2092R0

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


[clang] [RISCV] Support Xsfvqmaccdod and Xsfvqmaccqoq extensions (PR #68295)

2023-10-16 Thread Craig Topper via cfe-commits


@@ -476,6 +524,31 @@ class GetFTypeInfo {
   !eq(Scalar, f64) : "FPR64");
 }
 
+multiclass VPatVMACC info_pairs, ValueType vec_m1> {
+  foreach pair = info_pairs in {
+defvar VdInfo = pair.Wti;
+defvar Vs2Info = pair.Vti;
+let Predicates = [HasVInstructions] in
+def : VPatTernaryNoMaskWithPolicy<"int_riscv_sf_" # intrinsic,
+  "Pseudo" # instruction, kind, 
VdInfo.Vector,
+  vec_m1, Vs2Info.Vector,
+  Vs2Info.Log2SEW, Vs2Info.LMul,
+  VdInfo.RegClass, VR, Vs2Info.RegClass>;
+  }
+}
+
+defset list VQMACCInfoPairs = {
+  def : VTypeInfoToWide;
+  def : VTypeInfoToWide;
+  def : VTypeInfoToWide;
+  def : VTypeInfoToWide;
+}
+
+multiclass VPatVQMACC {
+  defm : VPatVMACC;

topperc wrote:

Can we have `VPatVQMACC` inherit from `VPatVMACC`?

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


[clang] [X86] Support -march=pantherlake, clearwaterforest (PR #69277)

2023-10-16 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff ce9eaf0360d9f528ab061bcdbcf81c5b2155f098 
9e673f332b8f7a3cfdeb1a73f6a77aee651f7664 -- clang/lib/Basic/Targets/X86.cpp 
clang/test/CodeGen/attr-cpuspecific-cpus.c clang/test/CodeGen/attr-target-mv.c 
clang/test/CodeGen/target-builtin-noerror.c clang/test/Driver/x86-march.c 
clang/test/Misc/target-invalid-cpu-note.c 
clang/test/Preprocessor/predefined-arch-macros.c 
compiler-rt/lib/builtins/cpu_model.c 
llvm/include/llvm/TargetParser/X86TargetParser.h llvm/lib/TargetParser/Host.cpp 
llvm/lib/TargetParser/X86TargetParser.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/TargetParser/X86TargetParser.cpp 
b/llvm/lib/TargetParser/X86TargetParser.cpp
index a4da99b32..294273e01 100644
--- a/llvm/lib/TargetParser/X86TargetParser.cpp
+++ b/llvm/lib/TargetParser/X86TargetParser.cpp
@@ -166,10 +166,10 @@ constexpr FeatureBitset FeaturesGrandridge =
 FeaturesSierraforest | FeatureRAOINT;
 constexpr FeatureBitset FeaturesArrowlakeS = FeaturesSierraforest |
 FeatureAVXVNNIINT16 | FeatureSHA512 | FeatureSM3 | FeatureSM4;
-constexpr FeatureBitset FeaturesPantherlake = FeaturesArrowlakeS |
-FeaturePREFETCHI;
-constexpr FeatureBitset FeaturesClearwaterforest = FeaturesArrowlakeS |
-FeatureUSERMSR | FeaturePREFETCHI;
+constexpr FeatureBitset FeaturesPantherlake =
+FeaturesArrowlakeS | FeaturePREFETCHI;
+constexpr FeatureBitset FeaturesClearwaterforest =
+FeaturesArrowlakeS | FeatureUSERMSR | FeaturePREFETCHI;
 
 // Geode Processor.
 constexpr FeatureBitset FeaturesGeode =

``




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


[clang] [RISCV] Support Xsfvqmaccdod and Xsfvqmaccqoq extensions (PR #68295)

2023-10-16 Thread Craig Topper via cfe-commits


@@ -558,6 +558,12 @@ DecodeStatus RISCVDisassembler::getInstruction(MCInst &MI, 
uint64_t &Size,
   "XTHeadVdot custom opcode table");
 TRY_TO_DECODE_FEATURE(RISCV::FeatureVendorXSfvcp, DecoderTableXSfvcp32,
   "SiFive VCIX custom opcode table");
+TRY_TO_DECODE_FEATURE(
+RISCV::FeatureVendorXSfvqmaccdod, DecoderTableXSfvqmaccdod32,
+"SiFive Matrix Multiplication Instruction opcode table");
+TRY_TO_DECODE_FEATURE(
+RISCV::FeatureVendorXSfvqmaccqoq, DecoderTableXSfvqmaccqoq32,
+"SiFive Matrix Multiplication Instruction opcode table");

topperc wrote:

This should use a different string than the one above.

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


[clang] ce9eaf0 - Revert "[clang][Sema] Use original template pattern when declaring implicit deduction guides for nested template classes (#68379)"

2023-10-16 Thread Antonio Abbatangelo via cfe-commits

Author: Antonio Abbatangelo
Date: 2023-10-16T22:16:09-04:00
New Revision: ce9eaf0360d9f528ab061bcdbcf81c5b2155f098

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

LOG: Revert "[clang][Sema] Use original template pattern when declaring 
implicit deduction guides for nested template classes (#68379)"

This reverts commit dd0fba11690f9fef304d5f48cde646e5eca8d3c0.

It fails on nested classes that have both an explicit deduction guide and
a constructor that has an argument of the same type as the class (i.e. a copy 
constructor).

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplate.cpp

Removed: 
clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3f83cd71e64cbce..99525b00239a4ca 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -516,11 +516,6 @@ Bug Fixes to C++ Support
   rather than prefer the non-templated constructor as specified in
   [standard.group]p3.
 
-- Fix a bug where implicit deduction guides are not correctly generated for 
nested template
-  classes. Fixes:
-  (`#46200 `_)
-  (`#57812 `_)
-
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index fba5b2213917065..ff370dd1e080b2b 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2250,7 +2250,6 @@ struct ConvertConstructorToDeductionGuideTransform {
 
   Sema &SemaRef;
   ClassTemplateDecl *Template;
-  ClassTemplateDecl *NestedPattern = nullptr;
 
   DeclContext *DC = Template->getDeclContext();
   CXXRecordDecl *Primary = Template->getTemplatedDecl();
@@ -2328,8 +2327,6 @@ struct ConvertConstructorToDeductionGuideTransform {
 if (FTD) {
   Args.addOuterTemplateArguments(SubstArgs);
   Args.addOuterRetainedLevel();
-  if (NestedPattern)
-Args.addOuterRetainedLevels(NestedPattern->getTemplateDepth());
 }
 
 FunctionProtoTypeLoc FPTL = CD->getTypeSourceInfo()->getTypeLoc()
@@ -2441,17 +2438,10 @@ struct ConvertConstructorToDeductionGuideTransform {
 SmallVector ParamTypes;
 const FunctionProtoType *T = TL.getTypePtr();
 
-MultiLevelTemplateArgumentList OuterInstantiationArgs;
-if (NestedPattern)
-  OuterInstantiationArgs = SemaRef.getTemplateInstantiationArgs(Template);
-
 //-- The types of the function parameters are those of the constructor.
 for (auto *OldParam : TL.getParams()) {
   ParmVarDecl *NewParam =
   transformFunctionTypeParam(OldParam, Args, MaterializedTypedefs);
-  if (NestedPattern && NewParam)
-NewParam = transformFunctionTypeParam(NewParam, OuterInstantiationArgs,
-  MaterializedTypedefs);
   if (!NewParam)
 return QualType();
   ParamTypes.push_back(NewParam->getType());
@@ -2657,23 +2647,13 @@ void Sema::DeclareImplicitDeductionGuides(TemplateDecl 
*Template,
   if (BuildingDeductionGuides.isInvalid())
 return;
 
-  // If the template is nested, then we need to use the original
-  // pattern to iterate over the constructors.
-  ClassTemplateDecl *Pattern = Transform.Template;
-  while (Pattern->getInstantiatedFromMemberTemplate()) {
-if (Pattern->isMemberSpecialization())
-  break;
-Pattern = Pattern->getInstantiatedFromMemberTemplate();
-Transform.NestedPattern = Pattern;
-  }
-
   // Convert declared constructors into deduction guide templates.
   // FIXME: Skip constructors for which deduction must necessarily fail (those
   // for which some class template parameter without a default argument never
   // appears in a deduced context).
   llvm::SmallPtrSet ProcessedCtors;
   bool AddedAny = false;
-  for (NamedDecl *D : LookupConstructors(Pattern->getTemplatedDecl())) {
+  for (NamedDecl *D : LookupConstructors(Transform.Primary)) {
 D = D->getUnderlyingDecl();
 if (D->isInvalidDecl() || D->isImplicit())
   continue;

diff  --git a/clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp 
b/clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp
deleted file mode 100644
index 4915c687cf4c4ef..000
--- a/clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-// RUN: %clang_cc1 -std=c++17 -verify %s
-// expected-no-diagnostics
-
-template struct S {
-template struct N {
-N(T) {}
-N(T, U) {}
-template N(V, U) {}
-};
-};
-
-S::N x{"a", 1};



___
cfe-commits

[clang] [RISCV] Support Xsfvqmaccdod and Xsfvqmaccqoq extensions (PR #68295)

2023-10-16 Thread Shao-Ce SUN via cfe-commits

sunshaoce wrote:

LGTM. If no one else has any objections, I think we can merge it.

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


[clang] [Clang] Fix dependence handling of nttp for variable templates (PR #69075)

2023-10-16 Thread via cfe-commits

https://github.com/LYP951018 updated 
https://github.com/llvm/llvm-project/pull/69075

From 177753fe1c81fe2ddeba949788c405f6686ebe51 Mon Sep 17 00:00:00 2001
From: letrec 
Date: Sun, 8 Oct 2023 00:44:11 +0800
Subject: [PATCH 1/3] Fix dependence handling for variable templates

---
 clang/include/clang/AST/ExprCXX.h  |  8 ++--
 clang/lib/AST/ASTImporter.cpp  |  5 -
 clang/lib/AST/ExprCXX.cpp  | 16 
 clang/lib/Sema/SemaDeclCXX.cpp |  5 +++--
 clang/lib/Sema/SemaTemplate.cpp| 14 ++
 clang/test/SemaTemplate/dependent-expr.cpp | 15 +++
 6 files changed, 42 insertions(+), 21 deletions(-)

diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 17dbb5e888ebdd3..798c98cfcf2d4db 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -3191,7 +3191,8 @@ class UnresolvedLookupExpr final
const DeclarationNameInfo &NameInfo, bool RequiresADL,
bool Overloaded,
const TemplateArgumentListInfo *TemplateArgs,
-   UnresolvedSetIterator Begin, UnresolvedSetIterator End);
+   UnresolvedSetIterator Begin, UnresolvedSetIterator End,
+   bool KnownDependent);
 
   UnresolvedLookupExpr(EmptyShell Empty, unsigned NumResults,
bool HasTemplateKWAndArgsInfo);
@@ -3211,12 +3212,15 @@ class UnresolvedLookupExpr final
  const DeclarationNameInfo &NameInfo, bool RequiresADL, bool 
Overloaded,
  UnresolvedSetIterator Begin, UnresolvedSetIterator End);
 
+  // After canonicalization, there may be dependent template arguments in
+  // CanonicalConverted But none of Args is dependent. When any of
+  // CanonicalConverted dependent, KnownDependent is true.
   static UnresolvedLookupExpr *
   Create(const ASTContext &Context, CXXRecordDecl *NamingClass,
  NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
  const DeclarationNameInfo &NameInfo, bool RequiresADL,
  const TemplateArgumentListInfo *Args, UnresolvedSetIterator Begin,
- UnresolvedSetIterator End);
+ UnresolvedSetIterator End, bool KnownDependent);
 
   static UnresolvedLookupExpr *CreateEmpty(const ASTContext &Context,
unsigned NumResults,
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 628a2b2bbca3986..650ff201e66b72e 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -8395,10 +8395,13 @@ 
ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
 if (!ToTemplateKeywordLocOrErr)
   return ToTemplateKeywordLocOrErr.takeError();
 
+const bool KnownDependent =
+(E->getDependence() & ExprDependence::TypeValue) ==
+ExprDependence::TypeValue;
 return UnresolvedLookupExpr::Create(
 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
 *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
-ToDecls.begin(), ToDecls.end());
+ToDecls.begin(), ToDecls.end(), KnownDependent);
   }
 
   return UnresolvedLookupExpr::Create(
diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp
index 06163255f9b5e54..5fbfa3a78124653 100644
--- a/clang/lib/AST/ExprCXX.cpp
+++ b/clang/lib/AST/ExprCXX.cpp
@@ -354,10 +354,10 @@ UnresolvedLookupExpr::UnresolvedLookupExpr(
 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
 const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded,
 const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin,
-UnresolvedSetIterator End)
+UnresolvedSetIterator End, bool KnownDependent)
 : OverloadExpr(UnresolvedLookupExprClass, Context, QualifierLoc,
-   TemplateKWLoc, NameInfo, TemplateArgs, Begin, End, false,
-   false, false),
+   TemplateKWLoc, NameInfo, TemplateArgs, Begin, End,
+   KnownDependent, false, false),
   NamingClass(NamingClass) {
   UnresolvedLookupExprBits.RequiresADL = RequiresADL;
   UnresolvedLookupExprBits.Overloaded = Overloaded;
@@ -380,7 +380,7 @@ UnresolvedLookupExpr *UnresolvedLookupExpr::Create(
   void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr));
   return new (Mem) UnresolvedLookupExpr(Context, NamingClass, QualifierLoc,
 SourceLocation(), NameInfo, 
RequiresADL,
-Overloaded, nullptr, Begin, End);
+Overloaded, nullptr, Begin, End, 
false);
 }
 
 UnresolvedLookupExpr *UnresolvedLookupExpr::Create(
@@ -388,7 +388,7 @@ UnresolvedLookupExpr *UnresolvedLookupExpr::Create(
 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
 const DeclarationNameInfo &N

[clang] [clang][Sema] Use original template pattern when declaring implicit deduction guides for nested template classes (PR #68379)

2023-10-16 Thread via cfe-commits

antangelo wrote:

I've come up with this minimal reproducer:

```cpp
template
struct outer {
template
struct inner {
inner(B b);
inner(const inner &x) = default;
};

template
inner(B b) -> inner;
};

outer::inner i(1);
```

The error seems to be triggered by the inclusion of both the copy constructor 
and the explicit deduction guide. I'll revert the patch now until I can come up 
with a proper fix for it.

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


[clang] [Clang] Fix dependence handling of nttp for variable templates (PR #69075)

2023-10-16 Thread Fangrui Song via cfe-commits


@@ -380,25 +380,25 @@ UnresolvedLookupExpr *UnresolvedLookupExpr::Create(
   void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr));
   return new (Mem) UnresolvedLookupExpr(Context, NamingClass, QualifierLoc,
 SourceLocation(), NameInfo, 
RequiresADL,
-Overloaded, nullptr, Begin, End);
+Overloaded, nullptr, Begin, End, 
false);
 }
 
 UnresolvedLookupExpr *UnresolvedLookupExpr::Create(
 const ASTContext &Context, CXXRecordDecl *NamingClass,
 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
 const DeclarationNameInfo &NameInfo, bool RequiresADL,
 const TemplateArgumentListInfo *Args, UnresolvedSetIterator Begin,
-UnresolvedSetIterator End) {
+UnresolvedSetIterator End, bool KnownDependent) {
   assert(Args || TemplateKWLoc.isValid());
   unsigned NumResults = End - Begin;
   unsigned NumTemplateArgs = Args ? Args->size() : 0;
   unsigned Size =
   totalSizeToAlloc(NumResults, 1, NumTemplateArgs);
   void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr));
-  return new (Mem) UnresolvedLookupExpr(Context, NamingClass, QualifierLoc,
-TemplateKWLoc, NameInfo, RequiresADL,
-/*Overloaded*/ true, Args, Begin, End);
+  return new (Mem) UnresolvedLookupExpr(
+  Context, NamingClass, QualifierLoc, TemplateKWLoc, NameInfo, RequiresADL,
+  /*Overloaded*/ true, Args, Begin, End, KnownDependent);

MaskRay wrote:

While here, change the argument to `/*Overloaded=*/` 
https://clang.llvm.org/extra/clang-tidy/checks/bugprone/argument-comment.html

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


[clang] [Clang] Fix dependence handling of nttp for variable templates (PR #69075)

2023-10-16 Thread via cfe-commits

LYP951018 wrote:

@erichkeane could you help me merge this PR please? I could not merge it by 
myself because I don't have write access to the repo

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


[PATCH] D157331: [clang] Implement C23

2023-10-16 Thread Zijun Zhao via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3694697003bb: [clang] Implement C23  
(authored by ZijunZhao).

Changed prior to commit:
  https://reviews.llvm.org/D157331?vs=557650&id=557720#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157331

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/stdckdint.h
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/C/C2x/n2359.c
  clang/test/C/C2x/n2683.c
  clang/test/C/C2x/n2683_2.c
  clang/test/Headers/stdckdint.c
  clang/test/Sema/builtins-overflow.c
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -887,6 +887,11 @@
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2672.pdf";>N2672
   Yes
 
+
+  Towards Integer Safety
+  https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2683.pdf";>N2683
+  Clang 18
+
 
   Adding Fundamental Type for N-bit Integers
 
Index: clang/test/Sema/builtins-overflow.c
===
--- clang/test/Sema/builtins-overflow.c
+++ clang/test/Sema/builtins-overflow.c
@@ -14,11 +14,11 @@
   __builtin_add_overflow();  // expected-error {{too few arguments to function call, expected 3, have 0}}
   __builtin_add_overflow(1, 1, 1, 1);  // expected-error {{too many arguments to function call, expected 3, have 4}}
 
-  __builtin_add_overflow(c, 1, &r);  // expected-error {{operand argument to overflow builtin must be an integer ('const char *' invalid)}}
-  __builtin_add_overflow(1, c, &r);  // expected-error {{operand argument to overflow builtin must be an integer ('const char *' invalid)}}
-  __builtin_add_overflow(1, 1, 3);  // expected-error {{result argument to overflow builtin must be a pointer to a non-const integer ('int' invalid)}}
-  __builtin_add_overflow(1, 1, &f);  // expected-error {{result argument to overflow builtin must be a pointer to a non-const integer ('float *' invalid)}}
-  __builtin_add_overflow(1, 1, &q);  // expected-error {{result argument to overflow builtin must be a pointer to a non-const integer ('const unsigned int *' invalid)}}
+  __builtin_add_overflow(c, 1, &r);  // expected-error {{operand argument to overflow builtin must be an integer type ('const char *' invalid)}}
+  __builtin_add_overflow(1, c, &r);  // expected-error {{operand argument to overflow builtin must be an integer type ('const char *' invalid)}}
+  __builtin_add_overflow(1, 1, 3);  // expected-error {{result argument to overflow builtin must be a pointer to a non-const integer type ('int' invalid)}}
+  __builtin_add_overflow(1, 1, &f);  // expected-error {{result argument to overflow builtin must be a pointer to a non-const integer type ('float *' invalid)}}
+  __builtin_add_overflow(1, 1, &q);  // expected-error {{result argument to overflow builtin must be a pointer to a non-const integer type ('const unsigned int *' invalid)}}
 
   {
 _BitInt(128) x = 1;
Index: clang/test/Headers/stdckdint.c
===
--- /dev/null
+++ clang/test/Headers/stdckdint.c
@@ -0,0 +1,53 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 3
+// RUN: %clang_cc1 -triple=x86_64 -emit-llvm -verify -std=c23 %s -o - | FileCheck %s
+
+// expected-no-diagnostics
+
+#include 
+
+_Static_assert(__STDC_VERSION_STDCKDINT_H__ == 202311L, "");
+
+// CHECK-LABEL: define dso_local zeroext i1 @test_ckd_add(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RESULT:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 -1073741826, i32 -1073741826)
+// CHECK-NEXT:[[TMP1:%.*]] = extractvalue { i32, i1 } [[TMP0]], 1
+// CHECK-NEXT:[[TMP2:%.*]] = extractvalue { i32, i1 } [[TMP0]], 0
+// CHECK-NEXT:store i32 [[TMP2]], ptr [[RESULT]], align 4
+// CHECK-NEXT:ret i1 [[TMP1]]
+//
+bool test_ckd_add() {
+  int result;
+  return ckd_add(&result, -1073741826, -1073741826);
+}
+
+// CHECK-LABEL: define dso_local zeroext i1 @test_ckd_sub(
+// CHECK-SAME: ) #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RESULT:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[TMP0:%.*]] = call { i32, i1 } @llvm.ssub.with.overflow.i32(i32 -1073741826, i32 1073741826)
+// CHECK-NEXT:[[TMP1:%.*]] = extractvalue { i32, i1 } [[TMP0]], 1
+// CHECK-NEXT:[[TMP2:%.*]] = extractvalue { i32, i1 } [[TMP0]], 0
+// CHECK-NEXT:store i32 [[TMP2]], ptr [[RESULT]], align 4
+// CHECK-NEXT:ret i1 [[TMP1]]
+//
+bool test_ckd_sub() {
+  int result;
+  return ckd_sub(&result, -1073741826, 1073741826);
+}

[clang] 3694697 - [clang] Implement C23

2023-10-16 Thread via cfe-commits

Author: zijunzhao
Date: 2023-10-17T00:51:21Z
New Revision: 3694697003bbf443fd644c6746a1c7c937657fce

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

LOG: [clang] Implement C23 

https://github.com/llvm/llvm-project/issues/62248

Reviewed By: yabinc, aaron.ballman, #clang-language-wg

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

Added: 
clang/lib/Headers/stdckdint.h
clang/test/C/C2x/n2683.c
clang/test/C/C2x/n2683_2.c
clang/test/Headers/stdckdint.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Headers/CMakeLists.txt
clang/lib/Lex/PPDirectives.cpp
clang/lib/Sema/SemaChecking.cpp
clang/test/C/C2x/n2359.c
clang/test/Sema/builtins-overflow.c
clang/www/c_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ff66d2c272098c8..3f83cd71e64cbce 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -176,6 +176,9 @@ C23 Feature Support
 - Clang now supports `requires c23` for module maps.
 - Clang now supports ``N3007 Type inference for object definitions``.
 
+- Clang now supports  which defines several macros for 
performing
+  checked integer arithmetic.
+
 Non-comprehensive list of changes in this release
 -
 

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e85cd4d1a1ddc0d..58a33e2807b7b0a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8690,10 +8690,13 @@ def warn_atomic_implicit_seq_cst : Warning<
   InGroup>, DefaultIgnore;
 
 def err_overflow_builtin_must_be_int : Error<
-  "operand argument to overflow builtin must be an integer (%0 invalid)">;
+  "operand argument to %select{overflow builtin|checked integer operation}0 "
+  "must be an integer type %select{|other than plain 'char', 'bool', 
bit-precise, "
+  "or an enumeration }0(%1 invalid)">;
 def err_overflow_builtin_must_be_ptr_int : Error<
-  "result argument to overflow builtin must be a pointer "
-  "to a non-const integer (%0 invalid)">;
+  "result argument to %select{overflow builtin|checked integer operation}0 "
+  "must be a pointer to a non-const integer type %select{|other than plain 
'char', "
+  "'bool', bit-precise, or an enumeration }0(%1 invalid)">;
 def err_overflow_builtin_bit_int_max_size : Error<
   "__builtin_mul_overflow does not support 'signed _BitInt' operands of more "
   "than %0 bits">;

diff  --git a/clang/lib/Headers/CMakeLists.txt 
b/clang/lib/Headers/CMakeLists.txt
index 3b6fec3da2b16ff..02a0c81644b6c6d 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -17,6 +17,7 @@ set(core_files
   __stdarg_va_list.h
   stdatomic.h
   stdbool.h
+  stdckdint.h
   stddef.h
   __stddef_max_align_t.h
   __stddef_null.h

diff  --git a/clang/lib/Headers/stdckdint.h b/clang/lib/Headers/stdckdint.h
new file mode 100644
index 000..22972d78d9077a4
--- /dev/null
+++ b/clang/lib/Headers/stdckdint.h
@@ -0,0 +1,44 @@
+/*=== stdckdint.h - Standard header for checking integer===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+
+#ifndef __STDCKDINT_H
+#define __STDCKDINT_H
+
+/* If we're hosted, fall back to the system's stdckdint.h. FreeBSD, for
+ * example, already has a Clang-compatible stdckdint.h header.
+ *
+ * The `stdckdint.h` header requires C 23 or newer.
+ */
+#if __STDC_HOSTED__ && __has_include_next()
+#include_next 
+#else
+
+/* C23 7.20.1 Defines several macros for performing checked integer 
arithmetic*/
+
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
+#define __STDC_VERSION_STDCKDINT_H__ 202311L
+
+// Both A and B shall be any integer type other than "plain" char, bool, a bit-
+// precise integer type, or an enumerated type, and they need not be the same.
+
+// R shall be a modifiable lvalue of any integer type other than "plain" char,
+// bool, a bit-precise integer type, or an enumerated type. It shouldn't be
+// short type, either. Otherwise, it may be unable to hold two the result of
+// operating two 'int's.
+
+// A diagnostic message will be produced if A or B are not suitable integer
+// types, or if R is not a modifiable lvalue of a suitable integer type or R
+// is short type.
+#define ckd_add(R, A, B) __builtin_add_overflow((A), (B), (R))
+#define ckd_sub(R, A, B) __builtin_sub_overflow((A), (B), (

[clang] [clang][Sema] Use original template pattern when declaring implicit deduction guides for nested template classes (PR #68379)

2023-10-16 Thread Paul Kirth via cfe-commits

ilovepi wrote:

I think we may be seeing some issues with this patch, when building Fuchsia.

We're seeing the following error.

```
FAILED: host_x64/obj/sdk/lib/ld/test/ld-unittests.filter-view-tests.cc.o
../../prebuilt/third_party/clang/custom/bin/clang++ -MD -MF 
host_x64/obj/sdk/lib/ld/test/ld-unittests.filter-view-tests.cc.o.d 
-DFUCHSIA_API_LEVEL=15 -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS 
-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES -I../.. -Ihost_x64/gen 
-I../../sdk/lib/ld/include -I../../sdk/lib/stdcompat/include 
-I../../zircon/system/public -I../../src/lib/elfldltl/include 
-I../../zircon/system/u...
In file included from ../../sdk/lib/ld/test/filter-view-tests.cc:6:
../../sdk/lib/ld/include/lib/ld/internal/filter-view.h:51:27: error: no member 
'filter_iterator' in 'ld::internal::filter_view, (lambda at 
../../sdk/lib/ld/test/filter-view-tests.cc:20:48)>'; it has not yet been 
instantiated
   51 | filter_iterator(const filter_iterator&) = default;
  |   ^
note: while building implicit deduction guide first needed here
../../sdk/lib/ld/test/filter-view-tests.cc:20:31: note: in instantiation of 
template class 'ld::internal::filter_view, (lambda at 
../../sdk/lib/ld/test/filter-view-tests.cc:20:48)>' requested here
   20 | ld::internal::filter_view filter_view(arr, [](auto) { return true; 
});
  |   ^
../../sdk/lib/ld/include/lib/ld/internal/filter-view.h:40:9: note: 
not-yet-instantiated member is declared here
   40 |   class filter_iterator : public std::iterator_traits {
  | ^
1 error generated.
```

But the code in question is defining a constructor for the nested class. You 
can find the code here: 
https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/lib/ld/include/lib/ld/internal/filter-view.h;l=51?q=filter_iterator&ss=fuchsia%2Ffuchsia

We're tracking this in 
https://bugs.fuchsia.dev/p/fuchsia/issues/detail?id=135353

Do you have any idea why it would be flagging this case. I don't see any 
obvious C++ rules being violated, so I think this is rather surprising.

I've included a reproducer, but I haven't had a chance to reduce it yet, so 
it's likely to be quite large.
[filter-view.zip](https://github.com/llvm/llvm-project/files/12923104/filter-view.zip)


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


[clang] [InstCombine] Refactor matchFunnelShift to allow more pattern (NFC) (PR #68474)

2023-10-16 Thread via cfe-commits

HaohaiWen wrote:

If no objection, I'll merge it tomorrow.

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


[clang-tools-extra] [InstCombine] Refactor matchFunnelShift to allow more pattern (NFC) (PR #68474)

2023-10-16 Thread via cfe-commits

HaohaiWen wrote:

If no objection, I'll merge it tomorrow.

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


[clang] [Clang] Fix dependence handling of nttp for variable templates (PR #69075)

2023-10-16 Thread via cfe-commits

https://github.com/LYP951018 updated 
https://github.com/llvm/llvm-project/pull/69075

From 177753fe1c81fe2ddeba949788c405f6686ebe51 Mon Sep 17 00:00:00 2001
From: letrec 
Date: Sun, 8 Oct 2023 00:44:11 +0800
Subject: [PATCH 1/2] Fix dependence handling for variable templates

---
 clang/include/clang/AST/ExprCXX.h  |  8 ++--
 clang/lib/AST/ASTImporter.cpp  |  5 -
 clang/lib/AST/ExprCXX.cpp  | 16 
 clang/lib/Sema/SemaDeclCXX.cpp |  5 +++--
 clang/lib/Sema/SemaTemplate.cpp| 14 ++
 clang/test/SemaTemplate/dependent-expr.cpp | 15 +++
 6 files changed, 42 insertions(+), 21 deletions(-)

diff --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 17dbb5e888ebdd3..798c98cfcf2d4db 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -3191,7 +3191,8 @@ class UnresolvedLookupExpr final
const DeclarationNameInfo &NameInfo, bool RequiresADL,
bool Overloaded,
const TemplateArgumentListInfo *TemplateArgs,
-   UnresolvedSetIterator Begin, UnresolvedSetIterator End);
+   UnresolvedSetIterator Begin, UnresolvedSetIterator End,
+   bool KnownDependent);
 
   UnresolvedLookupExpr(EmptyShell Empty, unsigned NumResults,
bool HasTemplateKWAndArgsInfo);
@@ -3211,12 +3212,15 @@ class UnresolvedLookupExpr final
  const DeclarationNameInfo &NameInfo, bool RequiresADL, bool 
Overloaded,
  UnresolvedSetIterator Begin, UnresolvedSetIterator End);
 
+  // After canonicalization, there may be dependent template arguments in
+  // CanonicalConverted But none of Args is dependent. When any of
+  // CanonicalConverted dependent, KnownDependent is true.
   static UnresolvedLookupExpr *
   Create(const ASTContext &Context, CXXRecordDecl *NamingClass,
  NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
  const DeclarationNameInfo &NameInfo, bool RequiresADL,
  const TemplateArgumentListInfo *Args, UnresolvedSetIterator Begin,
- UnresolvedSetIterator End);
+ UnresolvedSetIterator End, bool KnownDependent);
 
   static UnresolvedLookupExpr *CreateEmpty(const ASTContext &Context,
unsigned NumResults,
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 628a2b2bbca3986..650ff201e66b72e 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -8395,10 +8395,13 @@ 
ASTNodeImporter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E) {
 if (!ToTemplateKeywordLocOrErr)
   return ToTemplateKeywordLocOrErr.takeError();
 
+const bool KnownDependent =
+(E->getDependence() & ExprDependence::TypeValue) ==
+ExprDependence::TypeValue;
 return UnresolvedLookupExpr::Create(
 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
 *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
-ToDecls.begin(), ToDecls.end());
+ToDecls.begin(), ToDecls.end(), KnownDependent);
   }
 
   return UnresolvedLookupExpr::Create(
diff --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp
index 06163255f9b5e54..5fbfa3a78124653 100644
--- a/clang/lib/AST/ExprCXX.cpp
+++ b/clang/lib/AST/ExprCXX.cpp
@@ -354,10 +354,10 @@ UnresolvedLookupExpr::UnresolvedLookupExpr(
 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
 const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded,
 const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin,
-UnresolvedSetIterator End)
+UnresolvedSetIterator End, bool KnownDependent)
 : OverloadExpr(UnresolvedLookupExprClass, Context, QualifierLoc,
-   TemplateKWLoc, NameInfo, TemplateArgs, Begin, End, false,
-   false, false),
+   TemplateKWLoc, NameInfo, TemplateArgs, Begin, End,
+   KnownDependent, false, false),
   NamingClass(NamingClass) {
   UnresolvedLookupExprBits.RequiresADL = RequiresADL;
   UnresolvedLookupExprBits.Overloaded = Overloaded;
@@ -380,7 +380,7 @@ UnresolvedLookupExpr *UnresolvedLookupExpr::Create(
   void *Mem = Context.Allocate(Size, alignof(UnresolvedLookupExpr));
   return new (Mem) UnresolvedLookupExpr(Context, NamingClass, QualifierLoc,
 SourceLocation(), NameInfo, 
RequiresADL,
-Overloaded, nullptr, Begin, End);
+Overloaded, nullptr, Begin, End, 
false);
 }
 
 UnresolvedLookupExpr *UnresolvedLookupExpr::Create(
@@ -388,7 +388,7 @@ UnresolvedLookupExpr *UnresolvedLookupExpr::Create(
 NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc,
 const DeclarationNameInfo &N

[libunwind] [libunwind][libc++][libc++abi] Add cross-compilation flags to tests (PR #67201)

2023-10-16 Thread Alexander Richardson via cfe-commits

https://github.com/arichardson updated 
https://github.com/llvm/llvm-project/pull/67201

>From bdd5a67168d21fe8218f5f525921cdb9bd056c9b Mon Sep 17 00:00:00 2001
From: Alex Richardson 
Date: Wed, 6 Sep 2023 11:41:56 -0700
Subject: [PATCH 1/2] [libunwind][libc++][libc++abi] Add cross-compilation
 flags to tests

There is currently only limited support for passing target-specific
flags (e.g. -mabi= or -march=) to the testsuites if you don't have a
compiler (or wrapper script) that defaults to the expected flags.
However, some targets (e.g. RISC-V) may require additional flags beyond
the basic --target= that is already added by the current infrastructure.

When cross-compiling with CMake, the recommended approach is to define
a toolchain file that specifies the necessary flags needed to compile for
a given target. There are two interesting variables here that we should
also be passing when building the test binaries:
- CMAKE_CXX_FLAGS_INIT defines the flags we need for compilation jobs
   and will specify flags such as -mabi= and -march=
- CMAKE_EXE_LINKER_FLAGS_INIT defines the linker flags that are needed to
  cross-compile for a given target.
When not cross-compiling these variables will generally be empty.
---
 libcxx/test/configs/apple-libc++-backdeployment.cfg.in| 4 ++--
 libcxx/test/configs/apple-libc++-shared.cfg.in| 4 ++--
 libcxx/test/configs/ibm-libc++-shared.cfg.in  | 4 ++--
 libcxx/test/configs/llvm-libc++-mingw.cfg.in  | 4 ++--
 libcxx/test/configs/llvm-libc++-shared-clangcl.cfg.in | 4 ++--
 libcxx/test/configs/llvm-libc++-shared-gcc.cfg.in | 4 ++--
 .../configs/llvm-libc++-shared-no-vcruntime-clangcl.cfg.in| 4 ++--
 libcxx/test/configs/llvm-libc++-shared.cfg.in | 4 ++--
 libcxx/test/configs/llvm-libc++-static-clangcl.cfg.in | 4 ++--
 libcxx/test/configs/llvm-libc++-static.cfg.in | 4 ++--
 libcxxabi/test/configs/apple-libc++abi-backdeployment.cfg.in  | 4 ++--
 libcxxabi/test/configs/apple-libc++abi-shared.cfg.in  | 4 ++--
 libcxxabi/test/configs/ibm-libc++abi-shared.cfg.in| 4 ++--
 libcxxabi/test/configs/llvm-libc++abi-merged.cfg.in   | 4 ++--
 libcxxabi/test/configs/llvm-libc++abi-mingw.cfg.in| 4 ++--
 libcxxabi/test/configs/llvm-libc++abi-shared-clangcl.cfg.in   | 4 ++--
 libcxxabi/test/configs/llvm-libc++abi-shared.cfg.in   | 4 ++--
 libcxxabi/test/configs/llvm-libc++abi-static-clangcl.cfg.in   | 4 ++--
 libcxxabi/test/configs/llvm-libc++abi-static.cfg.in   | 4 ++--
 libunwind/test/configs/apple-libunwind-backdeployment.cfg.in  | 4 ++--
 libunwind/test/configs/ibm-libunwind-shared.cfg.in| 4 ++--
 libunwind/test/configs/llvm-libunwind-merged.cfg.in   | 4 ++--
 libunwind/test/configs/llvm-libunwind-mingw.cfg.in| 4 ++--
 libunwind/test/configs/llvm-libunwind-shared.cfg.in   | 4 ++--
 libunwind/test/configs/llvm-libunwind-static.cfg.in   | 4 ++--
 25 files changed, 50 insertions(+), 50 deletions(-)

diff --git a/libcxx/test/configs/apple-libc++-backdeployment.cfg.in 
b/libcxx/test/configs/apple-libc++-backdeployment.cfg.in
index b471c02709c060f..374ad38247f9f1f 100644
--- a/libcxx/test/configs/apple-libc++-backdeployment.cfg.in
+++ b/libcxx/test/configs/apple-libc++-backdeployment.cfg.in
@@ -45,10 +45,10 @@ config.substitutions.append(('%{flags}',
 '-isysroot {}'.format('@CMAKE_OSX_SYSROOT@') if '@CMAKE_OSX_SYSROOT@' else 
''
 ))
 config.substitutions.append(('%{compile_flags}',
-'-nostdinc++ -I %{include} -I %{libcxx}/test/support'
+'@CMAKE_CXX_FLAGS_INIT@ -nostdinc++ -I %{include} -I 
%{libcxx}/test/support'
 ))
 config.substitutions.append(('%{link_flags}',
-'-nostdlib++ -L %{lib} -lc++'
+'@CMAKE_EXE_LINKER_FLAGS_INIT@ -nostdlib++ -L %{lib} -lc++'
 ))
 config.substitutions.append(('%{exec}',
 '%{executor} --execdir %T --env 
DYLD_LIBRARY_PATH="%{cxx-runtime-root}:%{abi-runtime-root}:%{unwind-runtime-root}"
 -- '
diff --git a/libcxx/test/configs/apple-libc++-shared.cfg.in 
b/libcxx/test/configs/apple-libc++-shared.cfg.in
index af1926e3859b9e5..0c664ad2cf65fa3 100644
--- a/libcxx/test/configs/apple-libc++-shared.cfg.in
+++ b/libcxx/test/configs/apple-libc++-shared.cfg.in
@@ -13,10 +13,10 @@ config.substitutions.append(('%{flags}',
 '-isysroot {}'.format('@CMAKE_OSX_SYSROOT@') if '@CMAKE_OSX_SYSROOT@' else 
''
 ))
 config.substitutions.append(('%{compile_flags}',
-'-nostdinc++ -I %{include} -I %{libcxx}/test/support'
+'@CMAKE_CXX_FLAGS_INIT@ -nostdinc++ -I %{include} -I 
%{libcxx}/test/support'
 ))
 config.substitutions.append(('%{link_flags}',
-'-nostdlib++ -L %{lib} -lc++'
+'@CMAKE_EXE_LINKER_FLAGS_INIT@ -nostdlib++ -L %{lib} -lc++'
 ))
 config.substitutions.append(('%{exec}',
 '%{executor} --execdir %T --env DYLD_LIBRARY_PATH=%{lib} -- '
diff --git a/libcxx/test/configs/ibm-libc++-shared.cfg.in 
b/libcxx/test/configs/ibm-libc+

[clang] [PowerPC][X86] Make cpu id builtins target independent and lower for PPC (PR #68919)

2023-10-16 Thread Pavel Iliin via cfe-commits


@@ -2110,6 +2110,66 @@ static bool checkFPMathBuiltinElementType(Sema &S, 
SourceLocation Loc,
   return false;
 }
 
+/// SemaBuiltinCpuSupports - Handle __builtin_cpu_supports(char *).
+/// This checks that the target supports __builtin_cpu_supports and
+/// that the string argument is constant and valid.
+static bool SemaBuiltinCpuSupports(Sema &S, const TargetInfo &TI,
+   const TargetInfo *AuxTI, CallExpr *TheCall) 
{
+  Expr *Arg = TheCall->getArg(0);
+
+  const TargetInfo *TheTI = nullptr;
+  if (TI.supportsCpuSupports())
+TheTI = &TI;
+  else if (AuxTI && AuxTI->supportsCpuSupports())
+TheTI = AuxTI;

ilinpv wrote:

If these builtins are needed for auxiliary target ( are they ? ) it would good 
to have tests for that.

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


[clang] [PowerPC][X86] Make cpu id builtins target independent and lower for PPC (PR #68919)

2023-10-16 Thread Pavel Iliin via cfe-commits

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


[clang] [PowerPC][X86] Make cpu id builtins target independent and lower for PPC (PR #68919)

2023-10-16 Thread Pavel Iliin via cfe-commits

https://github.com/ilinpv commented:

Except for the AuxTarget question, target independent part looks good to me. 
Thank you for the patch.

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


[clang] [PGO] Add ability to mark cold functions as optsize/minsize/optnone (PR #69030)

2023-10-16 Thread Ellis Hoag via cfe-commits


@@ -0,0 +1,28 @@
+//===- MarkColdFunctions.h - *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_MARKCOLDFUNCTIONS_H
+#define LLVM_TRANSFORMS_INSTRUMENTATION_MARKCOLDFUNCTIONS_H
+
+#include "llvm/IR/PassManager.h"
+#include "llvm/Support/PGOOptions.h"
+
+namespace llvm {
+
+struct MarkColdFunctionsPass : public PassInfoMixin {

ellishg wrote:

I think this pass could be generalized a bit. It seems that the goal for this 
pr is to reduce the size overhead of `-O2` by forcing cold functions to be 
`optsize`/`minsize`. Another goal could be to improve the performance of `-Oz` 
by forcing very hot functions to be `optsize` (as opposed to `minsize`) or 
remove `optsize`/`minsize` from them entirely. This is actually something we 
explored in [this paper](https://dl.acm.org/doi/10.1145/3497776.3517764) a 
while back and I would eventually like to upstream something similar. I believe 
this could be incorporated into this pass, but the name seems to be too vague. 
I think "PGO" should to be in the name so users know that it is involved. Maybe 
`PGOForceFuncAttrsPass` or `ProfileGuidedFuncAttrsPass`?

CC @kyulee-com 

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


[clang] [PGO] Add ability to mark cold functions as optsize/minsize/optnone (PR #69030)

2023-10-16 Thread Ellis Hoag via cfe-commits


@@ -1127,6 +1134,11 @@ 
PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
   if (EnableSyntheticCounts && !PGOOpt)
 MPM.addPass(SyntheticCountsPropagation());
 
+  if (EnableMarkColdFunctions && PGOOpt &&
+  (PGOOpt->Action == PGOOptions::SampleUse ||
+   PGOOpt->Action == PGOOptions::IRUse))

ellishg wrote:

It seems that this pass isn't enabled for CS profiles. Can they benefit from 
this pass?

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


[clang] Enable v for RISCV64 Android (PR #69261)

2023-10-16 Thread via cfe-commits

https://github.com/enh-google approved this pull request.


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


[clang] [clang][CodeGen] Handle template parameter objects with explicit address spaces (PR #69266)

2023-10-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Alex Voicu (AlexVlx)


Changes

For certain cases (e.g. when their address is observable at run time) it is 
necessary to provide physical backing for non-type template parameter objects. 
Said backing comes in the form of a global variable. For certain targets (e.g. 
AMDGPU), which use a non-default address space for globals, this can lead to an 
issue when referencing said global in address space agnostic languages (such as 
HIP), for example when passing them to a function. 

This patch addresses this issue by inserting an address space cast iff there is 
an address space mismatch between the type of a reference expression and the 
address space of the backing global. A test is also added.

---
Full diff: https://github.com/llvm/llvm-project/pull/69266.diff


2 Files Affected:

- (modified) clang/lib/CodeGen/CGExpr.cpp (+15-3) 
- (added) clang/test/CodeGenCXX/template-param-objects-address-space.cpp (+32) 


``diff
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 54a1d300a9ac738..784d3f7b03909e3 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2992,9 +2992,21 @@ LValue CodeGenFunction::EmitDeclRefLValue(const 
DeclRefExpr *E) {
 return MakeAddrLValue(CGM.GetAddrOfMSGuidDecl(GD), T,
   AlignmentSource::Decl);
 
-  if (const auto *TPO = dyn_cast(ND))
-return MakeAddrLValue(CGM.GetAddrOfTemplateParamObject(TPO), T,
-  AlignmentSource::Decl);
+  if (const auto *TPO = dyn_cast(ND)) {
+auto ATPO = CGM.GetAddrOfTemplateParamObject(TPO);
+auto AS = getLangASFromTargetAS(ATPO.getAddressSpace());
+
+if (AS != T.getAddressSpace()) {
+  auto TargetAS = getContext().getTargetAddressSpace(T.getAddressSpace());
+  auto PtrTy = ATPO.getElementType()->getPointerTo(TargetAS);
+  auto ASC = getTargetHooks().performAddrSpaceCast(CGM, ATPO.getPointer(),
+   AS, T.getAddressSpace(),
+   PtrTy);
+  ATPO = ConstantAddress(ASC, ATPO.getElementType(), ATPO.getAlignment());
+}
+
+return MakeAddrLValue(ATPO, T, AlignmentSource::Decl);
+  }
 
   llvm_unreachable("Unhandled DeclRefExpr");
 }
diff --git a/clang/test/CodeGenCXX/template-param-objects-address-space.cpp 
b/clang/test/CodeGenCXX/template-param-objects-address-space.cpp
new file mode 100644
index 000..b54dcfe77934ee2
--- /dev/null
+++ b/clang/test/CodeGenCXX/template-param-objects-address-space.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -std=c++20 %s -emit-llvm -o - | 
FileCheck %s
+
+struct S { char buf[32]; };
+template constexpr const char *begin() { return s.buf; }
+template constexpr const char *end() { return s.buf + 
__builtin_strlen(s.buf); }
+template constexpr const void *retval() { return &s; }
+extern const void *callee(const S*);
+template constexpr const void* observable_addr() { return callee(&s); }
+
+// CHECK: 
[[HELLO:@_ZTAXtl1StlA32_cLc104ELc101ELc108ELc108ELc111ELc32ELc119ELc111ELc114ELc108ELc100]]
+// CHECK-SAME: = linkonce_odr addrspace(1) constant { <{ [11 x i8], [21 x i8] 
}> } { <{ [11 x i8], [21 x i8] }> <{ [11 x i8] c"hello world", [21 x i8] 
zeroinitializer }> }, comdat
+
+// CHECK: @p
+// CHECK-SAME: addrspace(1) global ptr addrspacecast (ptr addrspace(1) 
[[HELLO]] to ptr)
+const char *p = begin();
+
+// CHECK: @q
+// CHECK-SAME: addrspace(1) global ptr addrspacecast (ptr addrspace(1) 
getelementptr (i8, ptr addrspace(1) [[HELLO]], i64 11) to ptr)
+const char *q = end();
+
+const void *(*r)() = &retval;
+
+// CHECK: @s
+// CHECK-SAME: addrspace(1) global ptr null
+const void *s = observable_addr();
+
+// CHECK: define linkonce_odr noundef ptr 
@_Z6retvalIXtl1StlA32_cLc104ELc101ELc108ELc108ELc111ELc32ELc119ELc111ELc114ELc108ELc100EPKvv()
+// CHECK: ret ptr addrspacecast (ptr addrspace(1) [[HELLO]] to ptr)
+
+// CHECK: define linkonce_odr noundef ptr 
@_Z15observable_addrIXtl1StlA32_cLc104ELc101ELc108ELc108ELc111ELc32ELc119ELc111ELc114ELc108ELc100EPKvv()
+// CHECK: %call = call noundef ptr @_Z6calleePK1S(ptr noundef addrspacecast 
(ptr addrspace(1) [[HELLO]] to ptr))
+// CHECK: declare noundef ptr @_Z6calleePK1S(ptr noundef)

``




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


[clang] [clang][CodeGen] Handle template parameter objects with explicit address spaces (PR #69266)

2023-10-16 Thread Alex Voicu via cfe-commits

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


[clang] Handle template parameter objects with explicit address spaces (PR #69266)

2023-10-16 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx created 
https://github.com/llvm/llvm-project/pull/69266

For certain cases (e.g. when their address is observable at run time) it is 
necessary to provide physical backing for non-type template parameter objects. 
Said backing comes in the form of a global variable. For certain targets (e.g. 
AMDGPU), which use a non-default address space for globals, this can lead to an 
issue when referencing said global in address space agnostic languages (such as 
HIP), for example when passing them to a function. 

This patch addresses this issue by inserting an address space cast iff there is 
an address space mismatch between the type of a reference expression and the 
address space of the backing global. A test is also added.

>From ded7435220d2c3527c4798d1b328a5f2940e279a Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Mon, 16 Oct 2023 22:43:55 +0100
Subject: [PATCH] Handle trying to bind a generic reference to a template
 parameter object value that is in an explicit address space.

---
 clang/lib/CodeGen/CGExpr.cpp  | 18 +--
 .../template-param-objects-address-space.cpp  | 32 +++
 2 files changed, 47 insertions(+), 3 deletions(-)
 create mode 100644 
clang/test/CodeGenCXX/template-param-objects-address-space.cpp

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 54a1d300a9ac738..784d3f7b03909e3 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2992,9 +2992,21 @@ LValue CodeGenFunction::EmitDeclRefLValue(const 
DeclRefExpr *E) {
 return MakeAddrLValue(CGM.GetAddrOfMSGuidDecl(GD), T,
   AlignmentSource::Decl);
 
-  if (const auto *TPO = dyn_cast(ND))
-return MakeAddrLValue(CGM.GetAddrOfTemplateParamObject(TPO), T,
-  AlignmentSource::Decl);
+  if (const auto *TPO = dyn_cast(ND)) {
+auto ATPO = CGM.GetAddrOfTemplateParamObject(TPO);
+auto AS = getLangASFromTargetAS(ATPO.getAddressSpace());
+
+if (AS != T.getAddressSpace()) {
+  auto TargetAS = getContext().getTargetAddressSpace(T.getAddressSpace());
+  auto PtrTy = ATPO.getElementType()->getPointerTo(TargetAS);
+  auto ASC = getTargetHooks().performAddrSpaceCast(CGM, ATPO.getPointer(),
+   AS, T.getAddressSpace(),
+   PtrTy);
+  ATPO = ConstantAddress(ASC, ATPO.getElementType(), ATPO.getAlignment());
+}
+
+return MakeAddrLValue(ATPO, T, AlignmentSource::Decl);
+  }
 
   llvm_unreachable("Unhandled DeclRefExpr");
 }
diff --git a/clang/test/CodeGenCXX/template-param-objects-address-space.cpp 
b/clang/test/CodeGenCXX/template-param-objects-address-space.cpp
new file mode 100644
index 000..b54dcfe77934ee2
--- /dev/null
+++ b/clang/test/CodeGenCXX/template-param-objects-address-space.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -std=c++20 %s -emit-llvm -o - | 
FileCheck %s
+
+struct S { char buf[32]; };
+template constexpr const char *begin() { return s.buf; }
+template constexpr const char *end() { return s.buf + 
__builtin_strlen(s.buf); }
+template constexpr const void *retval() { return &s; }
+extern const void *callee(const S*);
+template constexpr const void* observable_addr() { return callee(&s); }
+
+// CHECK: 
[[HELLO:@_ZTAXtl1StlA32_cLc104ELc101ELc108ELc108ELc111ELc32ELc119ELc111ELc114ELc108ELc100]]
+// CHECK-SAME: = linkonce_odr addrspace(1) constant { <{ [11 x i8], [21 x i8] 
}> } { <{ [11 x i8], [21 x i8] }> <{ [11 x i8] c"hello world", [21 x i8] 
zeroinitializer }> }, comdat
+
+// CHECK: @p
+// CHECK-SAME: addrspace(1) global ptr addrspacecast (ptr addrspace(1) 
[[HELLO]] to ptr)
+const char *p = begin();
+
+// CHECK: @q
+// CHECK-SAME: addrspace(1) global ptr addrspacecast (ptr addrspace(1) 
getelementptr (i8, ptr addrspace(1) [[HELLO]], i64 11) to ptr)
+const char *q = end();
+
+const void *(*r)() = &retval;
+
+// CHECK: @s
+// CHECK-SAME: addrspace(1) global ptr null
+const void *s = observable_addr();
+
+// CHECK: define linkonce_odr noundef ptr 
@_Z6retvalIXtl1StlA32_cLc104ELc101ELc108ELc108ELc111ELc32ELc119ELc111ELc114ELc108ELc100EPKvv()
+// CHECK: ret ptr addrspacecast (ptr addrspace(1) [[HELLO]] to ptr)
+
+// CHECK: define linkonce_odr noundef ptr 
@_Z15observable_addrIXtl1StlA32_cLc104ELc101ELc108ELc108ELc111ELc32ELc119ELc111ELc114ELc108ELc100EPKvv()
+// CHECK: %call = call noundef ptr @_Z6calleePK1S(ptr noundef addrspacecast 
(ptr addrspace(1) [[HELLO]] to ptr))
+// CHECK: declare noundef ptr @_Z6calleePK1S(ptr noundef)

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


[clang] Enable v for RISCV64 Android (PR #69261)

2023-10-16 Thread via cfe-commits

https://github.com/pirama-arumuga-nainar approved this pull request.


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


[clang] [llvm] Use XMACROS for MachO platforms. (PR #69262)

2023-10-16 Thread Saleem Abdulrasool via cfe-commits

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


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


[clang] [llvm] Use XMACROS for MachO platforms. (PR #69262)

2023-10-16 Thread Jonas Devlieghere via cfe-commits

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

I like how this centralizes everything in a single place and the def file 
format seems like a natural fit for the platforms. 

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


[clang] [llvm] Use XMACROS for MachO platforms. (PR #69262)

2023-10-16 Thread Juergen Ributzka via cfe-commits

https://github.com/ributzka updated 
https://github.com/llvm/llvm-project/pull/69262

>From d6a4d1cc70e7d3a13b94ff397bef8a0a75e21257 Mon Sep 17 00:00:00 2001
From: Juergen Ributzka 
Date: Mon, 28 Aug 2023 15:25:48 -0700
Subject: [PATCH 1/2] [llvm] Use XMACROS for MachO platforms.

This change adds the PLATFORM XMACRO to simplify the addition of new MachO
platforms and reduce the number of required changes. Many of the changes needed
for adding a new platform are mechanical, such as adding new cases to a switch
statement. This will help streamline the process by consolidating much of the
necessary information into the MachO.def file.
---
 clang/lib/CodeGen/CGObjC.cpp |  2 +-
 llvm/include/llvm/BinaryFormat/MachO.def | 16 ++
 llvm/include/llvm/BinaryFormat/MachO.h   | 14 ++---
 llvm/include/llvm/Object/MachO.h | 14 +++--
 llvm/lib/MC/MCAsmStreamer.cpp| 16 +++---
 llvm/lib/MC/MCParser/DarwinAsmParser.cpp | 14 -
 llvm/lib/TextAPI/Platform.cpp| 39 +---
 llvm/lib/TextAPI/Target.cpp  | 13 ++--
 llvm/lib/TextAPI/TextStub.cpp| 38 +++
 9 files changed, 49 insertions(+), 117 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 6c594b5db4bca1f..aa3a0ff57003d7c 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -3954,7 +3954,7 @@ static unsigned getBaseMachOPlatformID(const llvm::Triple 
&TT) {
   case llvm::Triple::DriverKit:
 return llvm::MachO::PLATFORM_DRIVERKIT;
   default:
-return /*Unknown platform*/ 0;
+return llvm::MachO::PLATFORM_UNKNOWN;
   }
 }
 
diff --git a/llvm/include/llvm/BinaryFormat/MachO.def 
b/llvm/include/llvm/BinaryFormat/MachO.def
index d841b42ee808b2e..70966952ca7efe1 100644
--- a/llvm/include/llvm/BinaryFormat/MachO.def
+++ b/llvm/include/llvm/BinaryFormat/MachO.def
@@ -120,5 +120,21 @@ LOAD_COMMAND_STRUCT(fileset_entry_command)
 
 #endif
 
+#ifdef PLATFORM
+// PLATFORM(platform, id, name, target, tapi_target, marketing)
+PLATFORM(UNKNOWN, 0, unknown, unknown, unknown, unknown)
+PLATFORM(MACOS, 1, macos, macos, macos, macOS)
+PLATFORM(IOS, 2, ios, ios, ios, iOS)
+PLATFORM(TVOS, 3, tvos, tvos, tvos, tvOS)
+PLATFORM(WATCHOS, 4, watchos, watchos, watchos, watchOS)
+PLATFORM(BRIDGEOS, 5, bridgeos, bridgeos, bridgeos, bridgeOS)
+PLATFORM(MACCATALYST, 6, macCatalyst, ios-macabi, maccatalyst, macCatalyst)
+PLATFORM(IOSSIMULATOR, 7, iossimulator, ios-simulator, ios-simulator, iOS 
Simulator)
+PLATFORM(TVOSSIMULATOR, 8, tvossimulator, tvos-simulator, tvos-simulator, tvOS 
Simulator)
+PLATFORM(WATCHOSSIMULATOR, 9, watchossimulator, watchos-simulator, 
watchos-simulator, watchOS Simulator)
+PLATFORM(DRIVERKIT, 10, driverkit, driverkit, driverkit, DriverKit)
+#endif
+
 #undef HANDLE_LOAD_COMMAND
 #undef LOAD_COMMAND_STRUCT
+#undef PLATFORM
diff --git a/llvm/include/llvm/BinaryFormat/MachO.h 
b/llvm/include/llvm/BinaryFormat/MachO.h
index f59cd14c1b5c055..6dfc115c7e905fc 100644
--- a/llvm/include/llvm/BinaryFormat/MachO.h
+++ b/llvm/include/llvm/BinaryFormat/MachO.h
@@ -497,17 +497,9 @@ enum { VM_PROT_READ = 0x1, VM_PROT_WRITE = 0x2, 
VM_PROT_EXECUTE = 0x4 };
 
 // Values for platform field in build_version_command.
 enum PlatformType {
-  PLATFORM_UNKNOWN = 0,
-  PLATFORM_MACOS = 1,
-  PLATFORM_IOS = 2,
-  PLATFORM_TVOS = 3,
-  PLATFORM_WATCHOS = 4,
-  PLATFORM_BRIDGEOS = 5,
-  PLATFORM_MACCATALYST = 6,
-  PLATFORM_IOSSIMULATOR = 7,
-  PLATFORM_TVOSSIMULATOR = 8,
-  PLATFORM_WATCHOSSIMULATOR = 9,
-  PLATFORM_DRIVERKIT = 10,
+#define PLATFORM(platform, id, name, target, tapi_target, marketing)   
\
+  PLATFORM_##platform = id,
+#include "MachO.def"
 };
 
 // Values for tools enum in build_tool_version.
diff --git a/llvm/include/llvm/Object/MachO.h b/llvm/include/llvm/Object/MachO.h
index 894252db538f9e7..7bb2be76ff5b865 100644
--- a/llvm/include/llvm/Object/MachO.h
+++ b/llvm/include/llvm/Object/MachO.h
@@ -789,16 +789,10 @@ class MachOObjectFile : public ObjectFile {
 
   static std::string getBuildPlatform(uint32_t platform) {
 switch (platform) {
-case MachO::PLATFORM_MACOS: return "macos";
-case MachO::PLATFORM_IOS: return "ios";
-case MachO::PLATFORM_TVOS: return "tvos";
-case MachO::PLATFORM_WATCHOS: return "watchos";
-case MachO::PLATFORM_BRIDGEOS: return "bridgeos";
-case MachO::PLATFORM_MACCATALYST: return "macCatalyst";
-case MachO::PLATFORM_IOSSIMULATOR: return "iossimulator";
-case MachO::PLATFORM_TVOSSIMULATOR: return "tvossimulator";
-case MachO::PLATFORM_WATCHOSSIMULATOR: return "watchossimulator";
-case MachO::PLATFORM_DRIVERKIT: return "driverkit";
+#define PLATFORM(platform, id, name, target, tapi_target, marketing)   
\
+  case MachO::PLATFORM_##platform: 
\
+return #name;
+#include "llvm/BinaryFormat/MachO.def"
 default:
   std::string ret;
   raw_str

[clang] [llvm] Use XMACROS for MachO platforms. (PR #69262)

2023-10-16 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff b225934a4b0d2944958a53269665b00e7eae4875 
d6a4d1cc70e7d3a13b94ff397bef8a0a75e21257 -- clang/lib/CodeGen/CGObjC.cpp 
llvm/include/llvm/BinaryFormat/MachO.h llvm/include/llvm/Object/MachO.h 
llvm/lib/MC/MCAsmStreamer.cpp llvm/lib/MC/MCParser/DarwinAsmParser.cpp 
llvm/lib/TextAPI/Platform.cpp llvm/lib/TextAPI/Target.cpp 
llvm/lib/TextAPI/TextStub.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/MC/MCParser/DarwinAsmParser.cpp 
b/llvm/lib/MC/MCParser/DarwinAsmParser.cpp
index 287af822311c..4a8fc7388ec8 100644
--- a/llvm/lib/MC/MCParser/DarwinAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/DarwinAsmParser.cpp
@@ -1167,11 +1167,11 @@ bool DarwinAsmParser::parseBuildVersion(StringRef 
Directive, SMLoc Loc) {
 return TokError("platform name expected");
 
   unsigned Platform = StringSwitch(PlatformName)
-  #define PLATFORM(platform, id, name, target, tapi_target, marketing) 
  \
-.Case(#name, MachO::PLATFORM_##platform)
-#include "llvm/BinaryFormat/MachO.def"
-.Default(MachO::PLATFORM_UNKNOWN);
-  
+#define PLATFORM(platform, id, name, target, tapi_target, marketing)   
\
+  .Case(#name, MachO::PLATFORM_##platform)
+#include "llvm/BinaryFormat/MachO.def"
+  .Default(MachO::PLATFORM_UNKNOWN);
+
   if (Platform == MachO::PLATFORM_UNKNOWN)
 return Error(PlatformLoc, "unknown platform name");
 

``




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


[clang] [llvm] Use XMACROS for MachO platforms. (PR #69262)

2023-10-16 Thread Davide Italiano via cfe-commits

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

LGTM

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


[clang] Enable v for RISCV64 Android (PR #69261)

2023-10-16 Thread via cfe-commits

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


[clang] [llvm] Use XMACROS for MachO platforms. (PR #69262)

2023-10-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Juergen Ributzka (ributzka)


Changes

This change adds the PLATFORM XMACRO to simplify the addition of new MachO
platforms and reduce the number of required changes. Many of the changes needed
for adding a new platform are mechanical, such as adding new cases to a switch
statement. This will help streamline the process by consolidating much of the
necessary information into the MachO.def file.


---
Full diff: https://github.com/llvm/llvm-project/pull/69262.diff


9 Files Affected:

- (modified) clang/lib/CodeGen/CGObjC.cpp (+1-1) 
- (modified) llvm/include/llvm/BinaryFormat/MachO.def (+16) 
- (modified) llvm/include/llvm/BinaryFormat/MachO.h (+3-11) 
- (modified) llvm/include/llvm/Object/MachO.h (+4-10) 
- (modified) llvm/lib/MC/MCAsmStreamer.cpp (+4-12) 
- (modified) llvm/lib/MC/MCParser/DarwinAsmParser.cpp (+6-8) 
- (modified) llvm/lib/TextAPI/Platform.cpp (+7-32) 
- (modified) llvm/lib/TextAPI/Target.cpp (+3-10) 
- (modified) llvm/lib/TextAPI/TextStub.cpp (+5-33) 


``diff
diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 6c594b5db4bca1f..aa3a0ff57003d7c 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -3954,7 +3954,7 @@ static unsigned getBaseMachOPlatformID(const llvm::Triple 
&TT) {
   case llvm::Triple::DriverKit:
 return llvm::MachO::PLATFORM_DRIVERKIT;
   default:
-return /*Unknown platform*/ 0;
+return llvm::MachO::PLATFORM_UNKNOWN;
   }
 }
 
diff --git a/llvm/include/llvm/BinaryFormat/MachO.def 
b/llvm/include/llvm/BinaryFormat/MachO.def
index d841b42ee808b2e..70966952ca7efe1 100644
--- a/llvm/include/llvm/BinaryFormat/MachO.def
+++ b/llvm/include/llvm/BinaryFormat/MachO.def
@@ -120,5 +120,21 @@ LOAD_COMMAND_STRUCT(fileset_entry_command)
 
 #endif
 
+#ifdef PLATFORM
+// PLATFORM(platform, id, name, target, tapi_target, marketing)
+PLATFORM(UNKNOWN, 0, unknown, unknown, unknown, unknown)
+PLATFORM(MACOS, 1, macos, macos, macos, macOS)
+PLATFORM(IOS, 2, ios, ios, ios, iOS)
+PLATFORM(TVOS, 3, tvos, tvos, tvos, tvOS)
+PLATFORM(WATCHOS, 4, watchos, watchos, watchos, watchOS)
+PLATFORM(BRIDGEOS, 5, bridgeos, bridgeos, bridgeos, bridgeOS)
+PLATFORM(MACCATALYST, 6, macCatalyst, ios-macabi, maccatalyst, macCatalyst)
+PLATFORM(IOSSIMULATOR, 7, iossimulator, ios-simulator, ios-simulator, iOS 
Simulator)
+PLATFORM(TVOSSIMULATOR, 8, tvossimulator, tvos-simulator, tvos-simulator, tvOS 
Simulator)
+PLATFORM(WATCHOSSIMULATOR, 9, watchossimulator, watchos-simulator, 
watchos-simulator, watchOS Simulator)
+PLATFORM(DRIVERKIT, 10, driverkit, driverkit, driverkit, DriverKit)
+#endif
+
 #undef HANDLE_LOAD_COMMAND
 #undef LOAD_COMMAND_STRUCT
+#undef PLATFORM
diff --git a/llvm/include/llvm/BinaryFormat/MachO.h 
b/llvm/include/llvm/BinaryFormat/MachO.h
index f59cd14c1b5c055..6dfc115c7e905fc 100644
--- a/llvm/include/llvm/BinaryFormat/MachO.h
+++ b/llvm/include/llvm/BinaryFormat/MachO.h
@@ -497,17 +497,9 @@ enum { VM_PROT_READ = 0x1, VM_PROT_WRITE = 0x2, 
VM_PROT_EXECUTE = 0x4 };
 
 // Values for platform field in build_version_command.
 enum PlatformType {
-  PLATFORM_UNKNOWN = 0,
-  PLATFORM_MACOS = 1,
-  PLATFORM_IOS = 2,
-  PLATFORM_TVOS = 3,
-  PLATFORM_WATCHOS = 4,
-  PLATFORM_BRIDGEOS = 5,
-  PLATFORM_MACCATALYST = 6,
-  PLATFORM_IOSSIMULATOR = 7,
-  PLATFORM_TVOSSIMULATOR = 8,
-  PLATFORM_WATCHOSSIMULATOR = 9,
-  PLATFORM_DRIVERKIT = 10,
+#define PLATFORM(platform, id, name, target, tapi_target, marketing)   
\
+  PLATFORM_##platform = id,
+#include "MachO.def"
 };
 
 // Values for tools enum in build_tool_version.
diff --git a/llvm/include/llvm/Object/MachO.h b/llvm/include/llvm/Object/MachO.h
index 894252db538f9e7..7bb2be76ff5b865 100644
--- a/llvm/include/llvm/Object/MachO.h
+++ b/llvm/include/llvm/Object/MachO.h
@@ -789,16 +789,10 @@ class MachOObjectFile : public ObjectFile {
 
   static std::string getBuildPlatform(uint32_t platform) {
 switch (platform) {
-case MachO::PLATFORM_MACOS: return "macos";
-case MachO::PLATFORM_IOS: return "ios";
-case MachO::PLATFORM_TVOS: return "tvos";
-case MachO::PLATFORM_WATCHOS: return "watchos";
-case MachO::PLATFORM_BRIDGEOS: return "bridgeos";
-case MachO::PLATFORM_MACCATALYST: return "macCatalyst";
-case MachO::PLATFORM_IOSSIMULATOR: return "iossimulator";
-case MachO::PLATFORM_TVOSSIMULATOR: return "tvossimulator";
-case MachO::PLATFORM_WATCHOSSIMULATOR: return "watchossimulator";
-case MachO::PLATFORM_DRIVERKIT: return "driverkit";
+#define PLATFORM(platform, id, name, target, tapi_target, marketing)   
\
+  case MachO::PLATFORM_##platform: 
\
+return #name;
+#include "llvm/BinaryFormat/MachO.def"
 default:
   std::string ret;
   raw_string_ostream ss(ret);
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index 06de70ad2f395a2..01fc90513daca39 100644
--- a/llvm/lib/MC/MCAsmStream

[clang] [llvm] Use XMACROS for MachO platforms. (PR #69262)

2023-10-16 Thread Juergen Ributzka via cfe-commits

https://github.com/ributzka created 
https://github.com/llvm/llvm-project/pull/69262

This change adds the PLATFORM XMACRO to simplify the addition of new MachO
platforms and reduce the number of required changes. Many of the changes needed
for adding a new platform are mechanical, such as adding new cases to a switch
statement. This will help streamline the process by consolidating much of the
necessary information into the MachO.def file.


>From d6a4d1cc70e7d3a13b94ff397bef8a0a75e21257 Mon Sep 17 00:00:00 2001
From: Juergen Ributzka 
Date: Mon, 28 Aug 2023 15:25:48 -0700
Subject: [PATCH] [llvm] Use XMACROS for MachO platforms.

This change adds the PLATFORM XMACRO to simplify the addition of new MachO
platforms and reduce the number of required changes. Many of the changes needed
for adding a new platform are mechanical, such as adding new cases to a switch
statement. This will help streamline the process by consolidating much of the
necessary information into the MachO.def file.
---
 clang/lib/CodeGen/CGObjC.cpp |  2 +-
 llvm/include/llvm/BinaryFormat/MachO.def | 16 ++
 llvm/include/llvm/BinaryFormat/MachO.h   | 14 ++---
 llvm/include/llvm/Object/MachO.h | 14 +++--
 llvm/lib/MC/MCAsmStreamer.cpp| 16 +++---
 llvm/lib/MC/MCParser/DarwinAsmParser.cpp | 14 -
 llvm/lib/TextAPI/Platform.cpp| 39 +---
 llvm/lib/TextAPI/Target.cpp  | 13 ++--
 llvm/lib/TextAPI/TextStub.cpp| 38 +++
 9 files changed, 49 insertions(+), 117 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 6c594b5db4bca1f..aa3a0ff57003d7c 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -3954,7 +3954,7 @@ static unsigned getBaseMachOPlatformID(const llvm::Triple 
&TT) {
   case llvm::Triple::DriverKit:
 return llvm::MachO::PLATFORM_DRIVERKIT;
   default:
-return /*Unknown platform*/ 0;
+return llvm::MachO::PLATFORM_UNKNOWN;
   }
 }
 
diff --git a/llvm/include/llvm/BinaryFormat/MachO.def 
b/llvm/include/llvm/BinaryFormat/MachO.def
index d841b42ee808b2e..70966952ca7efe1 100644
--- a/llvm/include/llvm/BinaryFormat/MachO.def
+++ b/llvm/include/llvm/BinaryFormat/MachO.def
@@ -120,5 +120,21 @@ LOAD_COMMAND_STRUCT(fileset_entry_command)
 
 #endif
 
+#ifdef PLATFORM
+// PLATFORM(platform, id, name, target, tapi_target, marketing)
+PLATFORM(UNKNOWN, 0, unknown, unknown, unknown, unknown)
+PLATFORM(MACOS, 1, macos, macos, macos, macOS)
+PLATFORM(IOS, 2, ios, ios, ios, iOS)
+PLATFORM(TVOS, 3, tvos, tvos, tvos, tvOS)
+PLATFORM(WATCHOS, 4, watchos, watchos, watchos, watchOS)
+PLATFORM(BRIDGEOS, 5, bridgeos, bridgeos, bridgeos, bridgeOS)
+PLATFORM(MACCATALYST, 6, macCatalyst, ios-macabi, maccatalyst, macCatalyst)
+PLATFORM(IOSSIMULATOR, 7, iossimulator, ios-simulator, ios-simulator, iOS 
Simulator)
+PLATFORM(TVOSSIMULATOR, 8, tvossimulator, tvos-simulator, tvos-simulator, tvOS 
Simulator)
+PLATFORM(WATCHOSSIMULATOR, 9, watchossimulator, watchos-simulator, 
watchos-simulator, watchOS Simulator)
+PLATFORM(DRIVERKIT, 10, driverkit, driverkit, driverkit, DriverKit)
+#endif
+
 #undef HANDLE_LOAD_COMMAND
 #undef LOAD_COMMAND_STRUCT
+#undef PLATFORM
diff --git a/llvm/include/llvm/BinaryFormat/MachO.h 
b/llvm/include/llvm/BinaryFormat/MachO.h
index f59cd14c1b5c055..6dfc115c7e905fc 100644
--- a/llvm/include/llvm/BinaryFormat/MachO.h
+++ b/llvm/include/llvm/BinaryFormat/MachO.h
@@ -497,17 +497,9 @@ enum { VM_PROT_READ = 0x1, VM_PROT_WRITE = 0x2, 
VM_PROT_EXECUTE = 0x4 };
 
 // Values for platform field in build_version_command.
 enum PlatformType {
-  PLATFORM_UNKNOWN = 0,
-  PLATFORM_MACOS = 1,
-  PLATFORM_IOS = 2,
-  PLATFORM_TVOS = 3,
-  PLATFORM_WATCHOS = 4,
-  PLATFORM_BRIDGEOS = 5,
-  PLATFORM_MACCATALYST = 6,
-  PLATFORM_IOSSIMULATOR = 7,
-  PLATFORM_TVOSSIMULATOR = 8,
-  PLATFORM_WATCHOSSIMULATOR = 9,
-  PLATFORM_DRIVERKIT = 10,
+#define PLATFORM(platform, id, name, target, tapi_target, marketing)   
\
+  PLATFORM_##platform = id,
+#include "MachO.def"
 };
 
 // Values for tools enum in build_tool_version.
diff --git a/llvm/include/llvm/Object/MachO.h b/llvm/include/llvm/Object/MachO.h
index 894252db538f9e7..7bb2be76ff5b865 100644
--- a/llvm/include/llvm/Object/MachO.h
+++ b/llvm/include/llvm/Object/MachO.h
@@ -789,16 +789,10 @@ class MachOObjectFile : public ObjectFile {
 
   static std::string getBuildPlatform(uint32_t platform) {
 switch (platform) {
-case MachO::PLATFORM_MACOS: return "macos";
-case MachO::PLATFORM_IOS: return "ios";
-case MachO::PLATFORM_TVOS: return "tvos";
-case MachO::PLATFORM_WATCHOS: return "watchos";
-case MachO::PLATFORM_BRIDGEOS: return "bridgeos";
-case MachO::PLATFORM_MACCATALYST: return "macCatalyst";
-case MachO::PLATFORM_IOSSIMULATOR: return "iossimulator";
-case MachO::PLATFORM_TVOSSIMULATOR: return "tvossimulator";
-case MachO::PLATFORM_WATCHOSSIMULATOR: retu

[clang] Enable v for RISCV64 Android (PR #69261)

2023-10-16 Thread via cfe-commits

https://github.com/hiraditya created 
https://github.com/llvm/llvm-project/pull/69261

None

>From c3203b8f9ee863283c897f9910505e70a6181110 Mon Sep 17 00:00:00 2001
From: AdityaK <1894981+hiradi...@users.noreply.github.com>
Date: Mon, 16 Oct 2023 16:01:53 -0700
Subject: [PATCH] Enable v for RISCV64 Android

---
 clang/lib/Driver/ToolChains/Arch/RISCV.cpp | 4 ++--
 clang/test/Driver/riscv-features.c | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index bb097356d0c1269..a05f4b7ea64b487 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -309,7 +309,7 @@ StringRef riscv::getRISCVArch(const llvm::opt::ArgList 
&Args,
   return "rv32imafdc";
 else if (MABI.starts_with_insensitive("lp64")) {
   if (Triple.isAndroid())
-return "rv64imafdc_zba_zbb_zbs";
+return "rv64imafdcv_zba_zbb_zbs";
 
   return "rv64imafdc";
 }
@@ -329,7 +329,7 @@ StringRef riscv::getRISCVArch(const llvm::opt::ArgList 
&Args,
 if (Triple.getOS() == llvm::Triple::UnknownOS)
   return "rv64imac";
 else if (Triple.isAndroid())
-  return "rv64imafdc_zba_zbb_zbs";
+  return "rv64imafdcv_zba_zbb_zbs";
 else
   return "rv64imafdc";
   }
diff --git a/clang/test/Driver/riscv-features.c 
b/clang/test/Driver/riscv-features.c
index 0039c230ec476fb..851a7c0507eb3a3 100644
--- a/clang/test/Driver/riscv-features.c
+++ b/clang/test/Driver/riscv-features.c
@@ -10,6 +10,7 @@
 // RUN: %clang --target=riscv32-unknown-elf -### %s -mrelax 2>&1 | FileCheck 
%s -check-prefix=RELAX
 // RUN: %clang --target=riscv32-unknown-elf -### %s -mno-relax 2>&1 | 
FileCheck %s -check-prefix=NO-RELAX
 
+// ANDROID: "-target-feature" "+v"
 // ANDROID: "-target-feature" "+zba"
 // ANDROID: "-target-feature" "+zbb"
 // ANDROID: "-target-feature" "+zbs"

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


[clang] [Windows] Add git-clang-format wrapper bat file (PR #69228)

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

owenca wrote:

> This allows git-clang-format to be used on a Windows terminal without 
> manually needing to find the path and invoke the python interpreter. We have 
> a similar script for `scan-build`.

Can you open an issue and link to it from here? It seems `git clang-format` 
works in Command Prompt without this new batch file.

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


[clang-tools-extra] Fix #35272: Don't replace typedefs in extern c scope (PR #69102)

2023-10-16 Thread via cfe-commits

https://github.com/Da-Viper updated 
https://github.com/llvm/llvm-project/pull/69102

>From 21156656433fb8d2dc5a805d97cbd20fa916fff9 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Sun, 15 Oct 2023 11:39:42 +0100
Subject: [PATCH 1/2] Fix #35272: Don't replace typedefs in extern c scope

---
 .../clang-tidy/modernize/UseUsingCheck.cpp   | 16 
 .../clang-tidy/checkers/modernize/use-using.cpp  | 14 ++
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
index e6293ed48bfddbb..841ffb4c9bfe66e 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -11,6 +11,12 @@
 #include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
+namespace {
+
+AST_MATCHER(clang::LinkageSpecDecl, isExternCLinkage) {
+  return Node.getLanguage() == clang::LinkageSpecDecl::lang_c;
+}
+} // namespace
 
 namespace clang::tidy::modernize {
 
@@ -27,10 +33,12 @@ void 
UseUsingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
 }
 
 void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(typedefDecl(unless(isInstantiated()),
- hasParent(decl().bind(ParentDeclName)))
- .bind(TypedefName),
- this);
+  Finder->addMatcher(
+  typedefDecl(unless(anyOf(isInstantiated(), hasAncestor(linkageSpecDecl(
+ isExternCLinkage(),
+  hasParent(decl().bind(ParentDeclName)))
+  .bind(TypedefName),
+  this);
 
   // This matcher is used to find tag declarations in source code within
   // typedefs. They appear in the AST just *prior* to the typedefs.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
index 422abee11a71962..0f8f14502d5ca3c 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
@@ -325,3 +325,17 @@ typedef bool (*ISSUE_65055_2)(int);
 typedef class ISSUE_67529_1 *ISSUE_67529;
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
 // CHECK-FIXES: using ISSUE_67529 = class ISSUE_67529_1 *;
+
+// Some Header
+extern "C" {
+
+typedef int InExternC;
+}
+
+extern "C++" {
+
+typedef int InExternCPP;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 
[modernize-use-using]
+// CHECK-FIXES: using InExternCPP = int;
+
+}

>From 521dec9325285d1e1819a8bee1bd20eadb7c4158 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Mon, 16 Oct 2023 23:26:25 +0100
Subject: [PATCH 2/2] Add: Update docs with the new changes. Update
 ReleaseNotes.rst with the changes made

---
 clang-tools-extra/docs/ReleaseNotes.rst  | 5 +
 .../docs/clang-tidy/checks/modernize/use-using.rst   | 9 +
 2 files changed, 14 insertions(+)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index c1b926b296b055a..af6b20369c9dcff 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -285,6 +285,10 @@ Changes in existing checks
   ` check to fix function pointer and
   forward declared ``typedef`` correctly.
 
+- Improved :doc:`modernize-use-using
+  ` by ignoring ``typedef`` declaration 
in
+  ``extern "C"`` scope.
+
 - Improved :doc:`performance-faster-string-find
   ` check to properly escape
   single quotes.
@@ -325,6 +329,7 @@ Changes in existing checks
   identify calls to static member functions with out-of-class inline 
definitions.
 
 
+
 Removed checks
 ^^
 
diff --git a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst 
b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
index eeddaf8d8d65abe..048fc26617b7b73 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
@@ -28,6 +28,15 @@ After:
   using R_t = struct { int a; };
   using R_p = R_t*;
 
+The checker ignores `typedef` within `extern "C" { ... }` blocks.
+
+.. code-block:: c++
+
+  extern "C" {
+
+typedef int InExternC; // Left intact.
+  }
+
 This check requires using C++11 or higher to run.
 
 Options

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


[clang] [CodeGen] -fsanitize=alignment: add cl::opt sanitize-alignment-builtin to disable memcpy instrumentation (PR #69240)

2023-10-16 Thread Vitaly Buka via cfe-commits

vitalybuka wrote:

> For reference, can you give a couple examples of code where this is 
> triggering?
> 
> If this is triggering in practice, do we want a real driver option to control 
> the sanitizer? The alignment attributes themselves?

I am not sure we need special driver flag for that.

@MaskRay After reading about amount of unique cases you see, maybe ignore list 
is easier?

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


[clang-tools-extra] Fix #35272: Don't replace typedefs in extern c scope (PR #69102)

2023-10-16 Thread via cfe-commits

https://github.com/Da-Viper updated 
https://github.com/llvm/llvm-project/pull/69102

>From 21156656433fb8d2dc5a805d97cbd20fa916fff9 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Sun, 15 Oct 2023 11:39:42 +0100
Subject: [PATCH 1/2] Fix #35272: Don't replace typedefs in extern c scope

---
 .../clang-tidy/modernize/UseUsingCheck.cpp   | 16 
 .../clang-tidy/checkers/modernize/use-using.cpp  | 14 ++
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
index e6293ed48bfddbb..841ffb4c9bfe66e 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -11,6 +11,12 @@
 #include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
+namespace {
+
+AST_MATCHER(clang::LinkageSpecDecl, isExternCLinkage) {
+  return Node.getLanguage() == clang::LinkageSpecDecl::lang_c;
+}
+} // namespace
 
 namespace clang::tidy::modernize {
 
@@ -27,10 +33,12 @@ void 
UseUsingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
 }
 
 void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(typedefDecl(unless(isInstantiated()),
- hasParent(decl().bind(ParentDeclName)))
- .bind(TypedefName),
- this);
+  Finder->addMatcher(
+  typedefDecl(unless(anyOf(isInstantiated(), hasAncestor(linkageSpecDecl(
+ isExternCLinkage(),
+  hasParent(decl().bind(ParentDeclName)))
+  .bind(TypedefName),
+  this);
 
   // This matcher is used to find tag declarations in source code within
   // typedefs. They appear in the AST just *prior* to the typedefs.
diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
index 422abee11a71962..0f8f14502d5ca3c 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp
@@ -325,3 +325,17 @@ typedef bool (*ISSUE_65055_2)(int);
 typedef class ISSUE_67529_1 *ISSUE_67529;
 // CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef'
 // CHECK-FIXES: using ISSUE_67529 = class ISSUE_67529_1 *;
+
+// Some Header
+extern "C" {
+
+typedef int InExternC;
+}
+
+extern "C++" {
+
+typedef int InExternCPP;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use 'using' instead of 'typedef' 
[modernize-use-using]
+// CHECK-FIXES: using InExternCPP = int;
+
+}

>From 37e50e9a56133b96e62cab9b2cab81648e63e154 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Mon, 16 Oct 2023 23:26:25 +0100
Subject: [PATCH 2/2] Add: Update ReleaseNotes.rst with the changes made to
 readability-use-using

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

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index c1b926b296b055a..7d5156a27a69607 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -324,6 +324,10 @@ Changes in existing checks
   ` check to
   identify calls to static member functions with out-of-class inline 
definitions.
 
+- Improved :doc:`readability-use-using
+  ` by ignoring ``typedef`` 
declaration in
+  ``extern "C"`` scope.
+
 
 Removed checks
 ^^

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


[clang-tools-extra] [llvm-profdata] Do not create numerical strings for MD5 function names read from a Sample Profile. (PR #66164)

2023-10-16 Thread David Li via cfe-commits

https://github.com/david-xl approved this pull request.


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


[clang-tools-extra] Fix #68492: point to the correct const location (PR #69103)

2023-10-16 Thread via cfe-commits

https://github.com/Da-Viper updated 
https://github.com/llvm/llvm-project/pull/69103

>From 354a8e4034afd82e6ea854848a86b9011e26269b Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Fri, 13 Oct 2023 19:27:15 +0100
Subject: [PATCH 1/3] Fix #68492: point to the correct const location

---
 .../readability/AvoidConstParamsInDecls.cpp   | 43 ---
 .../avoid-const-params-in-decls.cpp   | 14 +++---
 2 files changed, 34 insertions(+), 23 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp 
b/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
index 6476f1d7fdf2b81..24cbbd8bc60a2b5 100644
--- a/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
+++ b/clang-tools-extra/clang-tidy/readability/AvoidConstParamsInDecls.cpp
@@ -21,6 +21,24 @@ SourceRange getTypeRange(const ParmVarDecl &Param) {
   return {Param.getBeginLoc(), Param.getLocation().getLocWithOffset(-1)};
 }
 
+// Finds the location of the qualifying `const` token in the `ParmValDecl`'s
+// return type. Returns `std::nullopt` when the parm type is not
+// `const`-qualified like when the type is an alias or a macro.
+static std::optional
+findConstToRemove(const ParmVarDecl &Param,
+  const MatchFinder::MatchResult &Result) {
+
+  CharSourceRange FileRange = Lexer::makeFileCharRange(
+  CharSourceRange::getTokenRange(getTypeRange(Param)),
+  *Result.SourceManager, Result.Context->getLangOpts());
+
+  if (FileRange.isInvalid())
+return std::nullopt;
+
+  return tidy::utils::lexer::getQualifyingToken(
+  tok::kw_const, FileRange, *Result.Context, *Result.SourceManager);
+}
+
 } // namespace
 
 void AvoidConstParamsInDecls::storeOptions(ClangTidyOptions::OptionMap &Opts) {
@@ -30,11 +48,10 @@ void 
AvoidConstParamsInDecls::storeOptions(ClangTidyOptions::OptionMap &Opts) {
 void AvoidConstParamsInDecls::registerMatchers(MatchFinder *Finder) {
   const auto ConstParamDecl =
   parmVarDecl(hasType(qualType(isConstQualified(.bind("param");
-  Finder->addMatcher(
-  functionDecl(unless(isDefinition()),
-   has(typeLoc(forEach(ConstParamDecl
-  .bind("func"),
-  this);
+  Finder->addMatcher(functionDecl(unless(isDefinition()),
+  has(typeLoc(forEach(ConstParamDecl
+ .bind("func"),
+ this);
 }
 
 void AvoidConstParamsInDecls::check(const MatchFinder::MatchResult &Result) {
@@ -50,7 +67,10 @@ void AvoidConstParamsInDecls::check(const 
MatchFinder::MatchResult &Result) {
 return;
   }
 
-  auto Diag = diag(Param->getBeginLoc(),
+  const auto Tok = findConstToRemove(*Param, Result);
+  const auto ConstLocation = Tok ? Tok->getLocation() : Param->getBeginLoc();
+
+  auto Diag = diag(ConstLocation,
"parameter %0 is const-qualified in the function "
"declaration; const-qualification of parameters only has an 
"
"effect in function definitions");
@@ -70,18 +90,9 @@ void AvoidConstParamsInDecls::check(const 
MatchFinder::MatchResult &Result) {
 // from a macro.
 return;
   }
-
-  CharSourceRange FileRange = Lexer::makeFileCharRange(
-  CharSourceRange::getTokenRange(getTypeRange(*Param)),
-  *Result.SourceManager, getLangOpts());
-
-  if (!FileRange.isValid())
-return;
-
-  auto Tok = tidy::utils::lexer::getQualifyingToken(
-  tok::kw_const, FileRange, *Result.Context, *Result.SourceManager);
   if (!Tok)
 return;
+
   Diag << FixItHint::CreateRemoval(
   CharSourceRange::getTokenRange(Tok->getLocation(), Tok->getLocation()));
 }
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-const-params-in-decls.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-const-params-in-decls.cpp
index d521fd238b7d521..bc098efe3044a5d 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-const-params-in-decls.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/avoid-const-params-in-decls.cpp
@@ -9,15 +9,15 @@ void F1(const int i);
 // CHECK-FIXES: void F1(int i);
 
 void F2(const int *const i);
-// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'i' is const-qualified
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: parameter 'i' is const-qualified
 // CHECK-FIXES: void F2(const int *i);
 
 void F3(int const i);
-// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'i' is const-qualified
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: parameter 'i' is const-qualified
 // CHECK-FIXES: void F3(int i);
 
 void F4(alias_type const i);
-// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: parameter 'i' is const-qualified
+// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: parameter 'i' is const-qualified
 // CHECK-FIXES: void F4(alias_type i);
 
 void F5(const int);
@@ -25,7 +25,7 @@ void F5(const int);
 // CHECK-FIXES: void F5(int);
 
 void F6(const int *const);
-// CHECK-MESSAGES: :[[@LIN

[clang] [analyzer] Trust base to derived casts for dynamic types (PR #69057)

2023-10-16 Thread Artem Dergachev via cfe-commits

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


[clang] [analyzer] Trust base to derived casts for dynamic types (PR #69057)

2023-10-16 Thread Artem Dergachev via cfe-commits


@@ -492,11 +492,13 @@ void check_required_cast() {
 
 void check_cast_behavior(OSObject *obj) {
   OSArray *arr1 = OSDynamicCast(OSArray, obj);
-  clang_analyzer_eval(arr1 == obj); // expected-warning{{TRUE}}
-// expected-note@-1{{TRUE}}
-// expected-note@-2{{Assuming 'arr1' is 
not equal to 'obj'}}
-// expected-warning@-3{{FALSE}}
-// expected-note@-4   {{FALSE}}
+  clang_analyzer_eval(arr1 == obj); // #check_cast_behavior_1
+  // expected-warning@#check_cast_behavior_1 {{TRUE}}
+  // expected-note@#check_cast_behavior_1{{TRUE}}
+  // expected-note@#check_cast_behavior_1{{Assuming 'arr1' is equal to 'obj'}}

haoNoQ wrote:

Hmm this looks like a regression. In this test, on the "cast succeeds" branch, 
`arr1` should be known to be the same as `obj`.

In this case `OSDynamicCast()` is a macro that implements custom RTTI in XNU. 
It is defined as:
```c++
   13 #define OSDynamicCast(type, inst)   \
   14 ((type *) OSMetaClassBase::safeMetaCast(inst, type::metaClass))
```
where `safeMetaCast()` is a function without visible definition that returns an 
`OSMetaClassBase *` (the most base class in the `OSObject` hierarchy).

Then the checker models `safeMetaCast()` to split the state and either "pass 
through" the value or return 0. But the subsequent C-style cast is technically 
a base-to-derived class (because `safeMetaCast()` doesn't return the actual 
type, but a base type). So it's likely that we've somehow regressed when we 
started actively modeling that cast.

We probably shouldn't have regressed though. Our desired behavior is the same 
as the old behavior: fully trust the cast.

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


[clang-tools-extra] Fix #68492: point to the correct const location (PR #69103)

2023-10-16 Thread via cfe-commits


@@ -293,6 +293,10 @@ Changes in existing checks
   ` check to enforce a stricter
   match with the swap function signature, eliminating false-positives.
 
+- Improved :doc:`readability-const-params-in-decls

EugeneZelenko wrote:

Please keep alphabetical order (by check name) in this list.

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


[clang] [analyzer] Trust base to derived casts for dynamic types (PR #69057)

2023-10-16 Thread Artem Dergachev via cfe-commits


@@ -392,19 +393,26 @@ void DynamicTypePropagation::checkPostCall(const 
CallEvent &Call,
   }
 }
 
-/// TODO: Handle explicit casts.
-///   Handle C++ casts.
-///
-/// Precondition: the cast is between ObjCObjectPointers.
 ExplodedNode *DynamicTypePropagation::dynamicTypePropagationOnCasts(
 const CastExpr *CE, ProgramStateRef &State, CheckerContext &C) const {
   // We only track type info for regions.
   const MemRegion *ToR = C.getSVal(CE).getAsRegion();
   if (!ToR)
 return C.getPredecessor();
 
-  if (isa(CE))
+  if (CE->getCastKind() == CK_BaseToDerived) {
+bool CastSucceeds = true;

haoNoQ wrote:

Yeah looks like `setDynamicTypeAndCastInfo()` is a very low-level primitive 
that blindly sets the state to whatever you think it should be. Judging by 
CastValueChecker's `addCastTransition()`, the caller is supposed to fully 
figure out whether the cast succeeds, judging by the rest of the dynamic type 
map state, the static types in the AST and in regions, and the nature of the 
cast, and there's no reusable utility provided for that.

In our case this means that if we know the cast fails (eg., the dynamic type is 
already incompatible, or a similar cast has failed on the same object 
previously), we should probably sink the analysis. (Ideally we'd emit a warning 
about it.) I'm not sure how urgent such improvement is, but it's quite likely 
that lack of support for failed casts may leave the cast maps in an 
inconsistent state which would produce more weird issues later in the analysis.

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


[clang] [clang-format] Fix a bug in mis-annotating arrows (PR #67780)

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

owenca wrote:

See #69249.

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


[clang] [CodeGen] -fsanitize=alignment: add cl::opt sanitize-alignment-builtin to disable memcpy instrumentation (PR #69240)

2023-10-16 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

For reference, can you give a couple examples of code where this is triggering?

If this is triggering in practice, do we want a real driver option to control 
the sanitizer?  The alignment attributes themselves?

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


[clang] [clang-format] Fix a bug in annotating TrailingReturnArrow (PR #69249)

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

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/69249

>From 25e0a84bd254969fb6930001f6203d4dc56f9871 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Mon, 16 Oct 2023 13:38:09 -0700
Subject: [PATCH 1/2] [clang-format] Fix a bug in annotating
 TrailingReturnArrow

Skip TrailingAnnotation when looking for TrailingReturnArrow.

Fixes #69234.
---
 clang/lib/Format/TokenAnnotator.cpp   | 9 +
 clang/unittests/Format/TokenAnnotatorTest.cpp | 4 
 2 files changed, 13 insertions(+)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 3dd537272e9dad0..9f007125e82c430 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3497,6 +3497,15 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
   Tok->setType(TT_TrailingReturnArrow);
   break;
 }
+if (Tok->isNot(TT_TrailingAnnotation))
+  continue;
+const auto *Next = Tok->Next;
+if (!Next || Next->isNot(tok::l_paren))
+  continue;
+Tok = Next->MatchingParen;
+if (Tok)
+  continue;
+break;
   }
 }
   }
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index e5cc3ed3686b3d3..d386ae9aae4ca61 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1788,6 +1788,10 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsTrailingReturnArrow) {
   ASSERT_EQ(Tokens.size(), 15u) << Tokens;
   EXPECT_TOKEN(Tokens[12], tok::arrow, TT_Unknown);
 
+  Tokens = annotate("void f() FOO(foo->bar);");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[7], tok::arrow, TT_Unknown);
+
   // Mixed
   Tokens = annotate("auto f() -> int { auto a = b()->c; }");
   ASSERT_EQ(Tokens.size(), 18u) << Tokens;

>From c1d6bf4c45482d0eabcf55ea7719366bc0fb8f1c Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Mon, 16 Oct 2023 14:47:57 -0700
Subject: [PATCH 2/2] Simplify the logic at the end of the for loop

---
 clang/lib/Format/TokenAnnotator.cpp | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 9f007125e82c430..293f7286abe4202 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3503,9 +3503,8 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
 if (!Next || Next->isNot(tok::l_paren))
   continue;
 Tok = Next->MatchingParen;
-if (Tok)
-  continue;
-break;
+if (!Tok)
+  break;
   }
 }
   }

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


[clang] [clang-format] Fix a bug in annotating TrailingReturnArrow (PR #69249)

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

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


[clang] [clang-format] Fix a bug in annotating TrailingReturnArrow (PR #69249)

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


@@ -3497,6 +3497,15 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
   Tok->setType(TT_TrailingReturnArrow);
   break;
 }
+if (Tok->isNot(TT_TrailingAnnotation))

owenca wrote:

Because `TT_TrailingAnnotation` is only the known case that needs special 
handling.

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


[clang] [clang-format] Allow default values for template parameters in lambda (PR #69052)

2023-10-16 Thread Emilia Kond via cfe-commits

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


[clang] 5f4ed78 - [clang-format] Allow default values for template parameters in lambda (#69052)

2023-10-16 Thread via cfe-commits

Author: Emilia Kond
Date: 2023-10-17T00:38:33+03:00
New Revision: 5f4ed780d348c810a7d4c1dd9354abf79094364b

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

LOG: [clang-format] Allow default values for template parameters in lambda 
(#69052)

Previously, upon encountering an equals sign while parsing a lambda in
the UnwrappedLineParser, it would fall through and fail. This caused any
lambda template with a default argument for a template parameter to be
annotated as an ArraySubscriptLSquare.

This patch allows equals signs in the UnwrappedLineParser if we're
currently in a template parameter list. This resolved a FIXME that was
in the lambda parsing function.

This patch seems deceptively easy, it's likely it doesn't solve the
FIXME entirely, or causes other issues (the FIXME itself mentions
something about Objective-C, which I cannot comment about). However this
patch is sufficient to fix the below issue.

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

-

Co-authored-by: Owen Pan 

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 82a812fc8bcc610..708b70489a114e3 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2226,9 +2226,6 @@ bool UnwrappedLineParser::tryToParseLambda() {
 // followed by an `a->b` expression, such as:
 // ([obj func:arg] + a->b)
 // Otherwise the code below would parse as a lambda.
-//
-// FIXME: This heuristic is incorrect for C++20 generic lambdas with
-// explicit template lists: [](U &&u){}
 case tok::plus:
 case tok::minus:
 case tok::exclaim:
@@ -2268,6 +2265,11 @@ bool UnwrappedLineParser::tryToParseLambda() {
   parseRequiresClause(RequiresToken);
   break;
 }
+case tok::equal:
+  if (!InTemplateParameterList)
+return true;
+  nextToken();
+  break;
 default:
   return true;
 }

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index e5cc3ed3686b3d3..2d046947996693f 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1620,6 +1620,44 @@ TEST_F(TokenAnnotatorTest, UnderstandsLambdas) {
   EXPECT_TOKEN(Tokens[15], tok::kw_requires, TT_RequiresClause);
   EXPECT_TRUE(Tokens[19]->ClosesRequiresClause);
   EXPECT_TOKEN(Tokens[20], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  (T t) {}");
+  ASSERT_EQ(Tokens.size(), 15u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[7], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  (T t) {}");
+  ASSERT_EQ(Tokens.size(), 15u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[7], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  (T t) {}");
+  ASSERT_EQ(Tokens.size(), 15u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[7], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  (T&& t) {}");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[7], tok::ampamp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[9], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[12], tok::ampamp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[15], tok::l_brace, TT_LambdaLBrace);
+
+  Tokens = annotate("[]  requires Foo (T t) {}");
+  ASSERT_EQ(Tokens.size(), 20u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::l_square, TT_LambdaLSquare);
+  EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
+  EXPECT_TOKEN(Tokens[7], tok::greater, TT_TemplateCloser);
+  EXPECT_TOKEN(Tokens[8], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TOKEN(Tokens[17], tok::l_brace, TT_LambdaLBrace);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsFunctionAnnotations) {



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


[clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-10-16 Thread Fangrui Song via cfe-commits

MaskRay wrote:

These tests just need a `--target=x86_64-linux-gnu`: which is how 
clang/test/Driver tests these stuff. Non-ELF platforms such as Apple, Windows, 
and AIX, may not support some options.

Ideally we should express that the test works for every ELF platform or 
everything except baremetal, but we don't infrastructure for it. Using a 
specific target triple is somewhat a convention at least for newer tests.

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


[clang] [clang-format] Fix a bug in annotating TrailingReturnArrow (PR #69249)

2023-10-16 Thread Björn Schäpers via cfe-commits


@@ -3497,6 +3497,15 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
   Tok->setType(TT_TrailingReturnArrow);
   break;
 }
+if (Tok->isNot(TT_TrailingAnnotation))

HazardyKnusperkeks wrote:

Why do you skip here?

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


[clang] [clang-format] Fix a bug in annotating TrailingReturnArrow (PR #69249)

2023-10-16 Thread Björn Schäpers via cfe-commits


@@ -3497,6 +3497,15 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
   Tok->setType(TT_TrailingReturnArrow);
   break;
 }
+if (Tok->isNot(TT_TrailingAnnotation))
+  continue;
+const auto *Next = Tok->Next;
+if (!Next || Next->isNot(tok::l_paren))
+  continue;
+Tok = Next->MatchingParen;
+if (Tok)
+  continue;
+break;

HazardyKnusperkeks wrote:

I find it rather confusing to have a loop, with a `break` at the end.
```suggestion
if (!Tok)
  break;
```

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


[clang] [Clang] Handle real and imaginary parts of complex lvalue in `APValue::printPretty` (PR #69252)

2023-10-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Yingwei Zheng (dtcxzyw)


Changes

This patch handles formatting of real and imaginary parts of complex lvalue.
Fixes #69218.


---
Full diff: https://github.com/llvm/llvm-project/pull/69252.diff


2 Files Affected:

- (modified) clang/lib/AST/APValue.cpp (+4) 
- (modified) clang/test/CodeGen/complex.c (+5) 


``diff
diff --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
index ef424215182280b..d08c2936b56dd45 100644
--- a/clang/lib/AST/APValue.cpp
+++ b/clang/lib/AST/APValue.cpp
@@ -841,6 +841,10 @@ void APValue::printPretty(raw_ostream &Out, const 
PrintingPolicy &Policy,
   Out << *VD;
   ElemTy = VD->getType();
 }
+  } else if (ElemTy->isAnyComplexType()) {
+// The lvalue refers to a complex type
+Out << (Path[I].getAsArrayIndex() == 0 ? ".real" : ".imag");
+ElemTy = ElemTy->castAs()->getElementType();
   } else {
 // The lvalue must refer to an array.
 Out << '[' << Path[I].getAsArrayIndex() << ']';
diff --git a/clang/test/CodeGen/complex.c b/clang/test/CodeGen/complex.c
index 6233529a18f8b8d..b50d607d00c0167 100644
--- a/clang/test/CodeGen/complex.c
+++ b/clang/test/CodeGen/complex.c
@@ -113,3 +113,8 @@ void t92(void) {
   (0 ? (_Complex double) 2.0f : 2.0f);
 }
 
+// PR69218
+int t10(void) {
+  float _Complex a;
+  return (0 < &__real__ a) && (0 < &__imag__ a);
+}

``




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


[clang] [Clang] Handle real and imaginary parts of complex lvalue in `APValue::printPretty` (PR #69252)

2023-10-16 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw created 
https://github.com/llvm/llvm-project/pull/69252

This patch handles formatting of real and imaginary parts of complex lvalue.
Fixes #69218.


>From 8f0ebe5b5cfed069c8274c0761559d6595d4dea8 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 17 Oct 2023 05:17:17 +0800
Subject: [PATCH 1/2] [Clang] Add pre-commit tests for PR69218. NFC.

---
 clang/test/CodeGen/complex.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/test/CodeGen/complex.c b/clang/test/CodeGen/complex.c
index 6233529a18f8b8d..b50d607d00c0167 100644
--- a/clang/test/CodeGen/complex.c
+++ b/clang/test/CodeGen/complex.c
@@ -113,3 +113,8 @@ void t92(void) {
   (0 ? (_Complex double) 2.0f : 2.0f);
 }
 
+// PR69218
+int t10(void) {
+  float _Complex a;
+  return (0 < &__real__ a) && (0 < &__imag__ a);
+}

>From c76a511cf1ad72eff3725bf24700f00a2f6fc014 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 17 Oct 2023 05:19:11 +0800
Subject: [PATCH 2/2] [Clang] Handle real and imaginary part of complex lvalue
 in `APValue::printPretty`

---
 clang/lib/AST/APValue.cpp | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
index ef424215182280b..d08c2936b56dd45 100644
--- a/clang/lib/AST/APValue.cpp
+++ b/clang/lib/AST/APValue.cpp
@@ -841,6 +841,10 @@ void APValue::printPretty(raw_ostream &Out, const 
PrintingPolicy &Policy,
   Out << *VD;
   ElemTy = VD->getType();
 }
+  } else if (ElemTy->isAnyComplexType()) {
+// The lvalue refers to a complex type
+Out << (Path[I].getAsArrayIndex() == 0 ? ".real" : ".imag");
+ElemTy = ElemTy->castAs()->getElementType();
   } else {
 // The lvalue must refer to an array.
 Out << '[' << Path[I].getAsArrayIndex() << ']';

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


  1   2   3   4   >