[clang] 4aff3f6 - [clang][Interp] Fix assignment operator call eval order (#101845)

2024-08-04 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-08-04T09:23:58+02:00
New Revision: 4aff3f6967eba11aced705e2772f3ad86f2adeef

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

LOG: [clang][Interp] Fix assignment operator call eval order (#101845)

Added: 


Modified: 
clang/lib/AST/Interp/Compiler.cpp
clang/test/AST/Interp/eval-order.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index d9db1c788314c..bd2b0f74b34c5 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -3977,7 +3977,19 @@ bool Compiler::VisitCallExpr(const CallExpr *E) 
{
 }
   }
 
-  auto Args = llvm::ArrayRef(E->getArgs(), E->getNumArgs());
+  SmallVector Args(
+  llvm::ArrayRef(E->getArgs(), E->getNumArgs()));
+
+  bool IsAssignmentOperatorCall = false;
+  if (const auto *OCE = dyn_cast(E);
+  OCE && OCE->isAssignmentOp()) {
+// Just like with regular assignments, we need to special-case assignment
+// operators here and evaluate the RHS (the second arg) before the LHS (the
+// first arg. We fix this by using a Flip op later.
+assert(Args.size() == 2);
+IsAssignmentOperatorCall = true;
+std::reverse(Args.begin(), Args.end());
+  }
   // Calling a static operator will still
   // pass the instance, but we don't need it.
   // Discard it here.
@@ -3986,7 +3998,8 @@ bool Compiler::VisitCallExpr(const CallExpr *E) {
 MD && MD->isStatic()) {
   if (!this->discard(E->getArg(0)))
 return false;
-  Args = Args.drop_front();
+  // Drop first arg.
+  Args.erase(Args.begin());
 }
   }
 
@@ -4038,6 +4051,15 @@ bool Compiler::VisitCallExpr(const CallExpr *E) 
{
 ++ArgIndex;
   }
 
+  // Undo the argument reversal we did earlier.
+  if (IsAssignmentOperatorCall) {
+assert(Args.size() == 2);
+PrimType Arg1T = classify(Args[0]).value_or(PT_Ptr);
+PrimType Arg2T = classify(Args[1]).value_or(PT_Ptr);
+if (!this->emitFlip(Arg2T, Arg1T, E))
+  return false;
+  }
+
   if (FuncDecl) {
 const Function *Func = getFunction(FuncDecl);
 if (!Func)

diff  --git a/clang/test/AST/Interp/eval-order.cpp 
b/clang/test/AST/Interp/eval-order.cpp
index c78c5061a08f2..213ef209a1c04 100644
--- a/clang/test/AST/Interp/eval-order.cpp
+++ b/clang/test/AST/Interp/eval-order.cpp
@@ -1,13 +1,7 @@
 // RUN: %clang_cc1 -std=c++1z -verify=ref,both %s -fcxx-exceptions 
-triple=x86_64-linux-gnu
 // RUN: %clang_cc1 -std=c++1z -verify=expected,both %s -fcxx-exceptions 
-triple=x86_64-linux-gnu -fexperimental-new-constant-interpreter
 
-// ref-no-diagnostics
-
-/// Check that assignment operators evaluate their operands right-to-left.
-/// Copied from test/SemaCXX/constant-expression-cxx1z.cpp
-///
-/// As you can see from the FIXME comments, some of these are not yet working 
correctly
-/// in the new interpreter.
+// both-no-diagnostics
 namespace EvalOrder {
   template struct lvalue {
 T t;
@@ -45,7 +39,7 @@ namespace EvalOrder {
 }
 template  constexpr T &&b(T &&v) {
   if (!done_a)
-throw "wrong"; // expected-note 3{{not valid}}
+throw "wrong";
   done_b = true;
   return (T &&)v;
 }
@@ -79,15 +73,10 @@ namespace EvalOrder {
 
   // Rule 5: b = a, b @= a
   SEQ(B(lvalue().get()) = A(0));
-  SEQ(B(lvalue().get()) = A(ud)); // expected-error {{not an 
integral constant expression}} FIXME \
-   // expected-note 2{{in call to}}
+  SEQ(B(lvalue().get()) = A(ud));
   SEQ(B(lvalue().get()) += A(0));
-  SEQ(B(lvalue().get()) += A(ud)); // expected-error {{not an 
integral constant expression}} FIXME \
-// expected-note 2{{in call 
to}}
-
-  SEQ(B(lvalue().get()) += A(nm)); // expected-error {{not an 
integral constant expression}} FIXME \
-  // expected-note 2{{in call to}}
-
+  SEQ(B(lvalue().get()) += A(ud));
+  SEQ(B(lvalue().get()) += A(nm));
 
   // Rule 6: a[b]
   constexpr int arr[3] = {};



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


[clang] [clang][Interp] Fix assignment operator call eval order (PR #101845)

2024-08-04 Thread Timm Baeder via cfe-commits

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


[clang] [clang][Interp] Fix assignment operator call eval order (PR #101845)

2024-08-04 Thread Thorsten Schütt via cfe-commits

tschuett wrote:

No review?

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


[clang] [Clang][CodeGen] Add `[[clang::asm_dialect]]` attribute (PR #101871)

2024-08-04 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok created 
https://github.com/llvm/llvm-project/pull/101871

This attribute applies to `GCCAsmStmt` statements or functions. If a function 
is declared with this, it is effectively the default for all `GCCAsmStmt`s 
contained in the function.

Takes one string argument: `"intel"`, `"att"` or `"reset"`. If `"reset"`, the 
dialect used will be the one specified on the command line.

Resolves #101328

>From 2e544ca9628cdaa4ef8875494f2b5948c7623d21 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 4 Aug 2024 09:09:19 +0100
Subject: [PATCH] [Clang][CodeGen][Sema] Add [[clang::asm_dialect]] attribute

---
 clang/include/clang/Basic/Attr.td |  7 ++
 clang/lib/CodeGen/CGStmt.cpp  | 51 --
 clang/lib/CodeGen/CodeGenFunction.h   |  4 ++
 clang/lib/Parse/ParseStmt.cpp | 12 ++--
 clang/lib/Sema/SemaDeclAttr.cpp   | 19 ++
 clang/lib/Sema/SemaStmtAttr.cpp   | 22 +++
 clang/test/CodeGen/inline-asm-mixed-dialect.c | 66 +++
 7 files changed, 167 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/CodeGen/inline-asm-mixed-dialect.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 8ac2079099c85..1249f68e8e645 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4730,3 +4730,10 @@ def ClspvLibclcBuiltin: InheritableAttr {
   let Documentation = [ClspvLibclcBuiltinDoc];
   let SimpleHandler = 1;
 }
+
+def AsmDialect: DeclOrStmtAttr {
+  let Spellings = [Clang<"asm_dialect">];
+  let Subjects = SubjectList<[GCCAsmStmt, Function], ErrorDiag, "'asm' inline 
assembly statements or functions">;
+  let Args = [EnumArgument<"Dialect", "Kind", /*is_string=*/true, ["intel", 
"att", "reset", ""], ["Intel", "ATT", "Global", "Local"]>];
+  let Documentation = [Undocumented];
+}
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 30b6fce5d016a..c7dd72f57b52a 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -724,6 +724,8 @@ void CodeGenFunction::EmitAttributedStmt(const 
AttributedStmt &S) {
   bool noinline = false;
   bool alwaysinline = false;
   bool noconvergent = false;
+  AsmDialectAttr::Kind asmdialect = AsmDialectAttr::Kind::Local;
+
   const CallExpr *musttail = nullptr;
 
   for (const auto *A : S.getAttrs()) {
@@ -755,6 +757,9 @@ void CodeGenFunction::EmitAttributedStmt(const 
AttributedStmt &S) {
 Builder.CreateAssumption(AssumptionVal);
   }
 } break;
+case attr::AsmDialect: {
+  asmdialect = cast(A)->getDialect();
+} break;
 }
   }
   SaveAndRestore save_nomerge(InNoMergeAttributedStmt, nomerge);
@@ -762,6 +767,7 @@ void CodeGenFunction::EmitAttributedStmt(const 
AttributedStmt &S) {
   SaveAndRestore save_alwaysinline(InAlwaysInlineAttributedStmt, alwaysinline);
   SaveAndRestore save_noconvergent(InNoConvergentAttributedStmt, noconvergent);
   SaveAndRestore save_musttail(MustTailCall, musttail);
+  SaveAndRestore save_asmdialect(AsmDialect, asmdialect);
   EmitStmt(S.getSubStmt(), S.getAttrs());
 }
 
@@ -3029,12 +3035,45 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
 
   bool HasSideEffect = S.isVolatile() || S.getNumOutputs() == 0;
 
-  llvm::InlineAsm::AsmDialect GnuAsmDialect =
-  CGM.getCodeGenOpts().getInlineAsmDialect() == CodeGenOptions::IAD_ATT
-  ? llvm::InlineAsm::AD_ATT
-  : llvm::InlineAsm::AD_Intel;
-  llvm::InlineAsm::AsmDialect AsmDialect = isa(&S) ?
-llvm::InlineAsm::AD_Intel : GnuAsmDialect;
+  llvm::InlineAsm::AsmDialect AsmDialect;
+  auto GlobalAsmDialect = [&]{
+return CGM.getCodeGenOpts().getInlineAsmDialect() == 
CodeGenOptions::IAD_ATT ? llvm::InlineAsm::AD_ATT : llvm::InlineAsm::AD_Intel;
+  };
+  if (auto *GS = dyn_cast(&S)) {
+switch (this->AsmDialect) {  // Fixme: rename member
+case AsmDialectAttr::Intel:
+  AsmDialect = llvm::InlineAsm::AsmDialect::AD_Intel;
+  break;
+case AsmDialectAttr::ATT:
+  AsmDialect = llvm::InlineAsm::AsmDialect::AD_ATT;
+  break;
+case AsmDialectAttr::Local:
+  if (CurFuncDecl) {
+if (auto *DialectAttr = CurFuncDecl->getAttr()) {
+  switch (DialectAttr->getDialect()) {
+  case AsmDialectAttr::Intel:
+AsmDialect = llvm::InlineAsm::AsmDialect::AD_Intel;
+break;
+  case AsmDialectAttr::ATT:
+AsmDialect = llvm::InlineAsm::AsmDialect::AD_ATT;
+break;
+  case AsmDialectAttr::Global:
+  case AsmDialectAttr::Local:
+AsmDialect = GlobalAsmDialect();
+break;
+  }
+  break;
+}
+  }
+  [[fallthrough]];
+case AsmDialectAttr::Global:
+  AsmDialect = GlobalAsmDialect();
+  break;
+}
+  } else {
+assert(isa(&S));
+AsmDialect = llvm::InlineAsm::AD_Intel;
+  }
 
   llvm::InlineAsm *IA = llvm::InlineAsm::get(
   FTy,

[clang] [Clang][CodeGen] Add `[[clang::asm_dialect]]` attribute (PR #101871)

2024-08-04 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 d07fdf9779f7dead2828cfb18bafbd9a2c085920 
2e544ca9628cdaa4ef8875494f2b5948c7623d21 --extensions cpp,c,h -- 
clang/test/CodeGen/inline-asm-mixed-dialect.c clang/lib/CodeGen/CGStmt.cpp 
clang/lib/CodeGen/CodeGenFunction.h clang/lib/Parse/ParseStmt.cpp 
clang/lib/Sema/SemaDeclAttr.cpp clang/lib/Sema/SemaStmtAttr.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index c7dd72f57b..b4b5efa575 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -3036,11 +3036,13 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
   bool HasSideEffect = S.isVolatile() || S.getNumOutputs() == 0;
 
   llvm::InlineAsm::AsmDialect AsmDialect;
-  auto GlobalAsmDialect = [&]{
-return CGM.getCodeGenOpts().getInlineAsmDialect() == 
CodeGenOptions::IAD_ATT ? llvm::InlineAsm::AD_ATT : llvm::InlineAsm::AD_Intel;
+  auto GlobalAsmDialect = [&] {
+return CGM.getCodeGenOpts().getInlineAsmDialect() == 
CodeGenOptions::IAD_ATT
+   ? llvm::InlineAsm::AD_ATT
+   : llvm::InlineAsm::AD_Intel;
   };
   if (auto *GS = dyn_cast(&S)) {
-switch (this->AsmDialect) {  // Fixme: rename member
+switch (this->AsmDialect) { // Fixme: rename member
 case AsmDialectAttr::Intel:
   AsmDialect = llvm::InlineAsm::AsmDialect::AD_Intel;
   break;
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index d5bc3d47ed..af8b9be9d8 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -360,7 +360,7 @@ Retry:
   // Could be relaxed if asm-related regular keyword attributes are
   // added later.
   if (AL.isRegularKeywordAttribute())
- Diag(AL.getRange().getBegin(), diag::err_keyword_not_allowed) << AL;
+Diag(AL.getRange().getBegin(), diag::err_keyword_not_allowed) << AL;
 }
 bool msAsm = false;
 Res = ParseAsmStatement(msAsm);
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index ff14256afb..733edcd43e 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5607,8 +5607,7 @@ static void handleAsmDialectAttr(Sema &S, Decl *D, const 
ParsedAttr &A) {
 
   AsmDialectAttr::Kind Kind;
   if (Name.empty() || !AsmDialectAttr::ConvertStrToKind(Name, Kind)) {
-S.Diag(LiteralLoc, diag::warn_attribute_type_not_supported)
-<< A << Name;
+S.Diag(LiteralLoc, diag::warn_attribute_type_not_supported) << A << Name;
 return;
   }
 
diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index d47257f7a9..48e4fcc4ce 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -635,8 +635,7 @@ static Attr *handleAsmDialectAttr(Sema &S, Stmt *St, const 
ParsedAttr &A,
 
   AsmDialectAttr::Kind Kind;
   if (Name.empty() || !AsmDialectAttr::ConvertStrToKind(Name, Kind)) {
-S.Diag(LiteralLoc, diag::warn_attribute_type_not_supported)
-<< A << Name;
+S.Diag(LiteralLoc, diag::warn_attribute_type_not_supported) << A << Name;
 return nullptr;
   }
 

``




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


[clang] [Clang][CodeGen] Add `[[clang::asm_dialect]]` attribute (PR #101871)

2024-08-04 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/101871

>From 321934e1fc59908cbcd7fac4992e2b85357899d4 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 4 Aug 2024 09:09:19 +0100
Subject: [PATCH] [Clang][CodeGen] Add `[[clang::asm_dialect]]` attribute

---
 clang/include/clang/Basic/Attr.td |  7 ++
 clang/lib/CodeGen/CGStmt.cpp  | 53 +--
 clang/lib/CodeGen/CodeGenFunction.h   |  4 ++
 clang/lib/Parse/ParseStmt.cpp | 12 ++--
 clang/lib/Sema/SemaDeclAttr.cpp   | 18 +
 clang/lib/Sema/SemaStmtAttr.cpp   | 21 ++
 clang/test/CodeGen/inline-asm-mixed-dialect.c | 66 +++
 7 files changed, 167 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/CodeGen/inline-asm-mixed-dialect.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 8ac2079099c85..1249f68e8e645 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4730,3 +4730,10 @@ def ClspvLibclcBuiltin: InheritableAttr {
   let Documentation = [ClspvLibclcBuiltinDoc];
   let SimpleHandler = 1;
 }
+
+def AsmDialect: DeclOrStmtAttr {
+  let Spellings = [Clang<"asm_dialect">];
+  let Subjects = SubjectList<[GCCAsmStmt, Function], ErrorDiag, "'asm' inline 
assembly statements or functions">;
+  let Args = [EnumArgument<"Dialect", "Kind", /*is_string=*/true, ["intel", 
"att", "reset", ""], ["Intel", "ATT", "Global", "Local"]>];
+  let Documentation = [Undocumented];
+}
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 30b6fce5d016a..b4b5efa575230 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -724,6 +724,8 @@ void CodeGenFunction::EmitAttributedStmt(const 
AttributedStmt &S) {
   bool noinline = false;
   bool alwaysinline = false;
   bool noconvergent = false;
+  AsmDialectAttr::Kind asmdialect = AsmDialectAttr::Kind::Local;
+
   const CallExpr *musttail = nullptr;
 
   for (const auto *A : S.getAttrs()) {
@@ -755,6 +757,9 @@ void CodeGenFunction::EmitAttributedStmt(const 
AttributedStmt &S) {
 Builder.CreateAssumption(AssumptionVal);
   }
 } break;
+case attr::AsmDialect: {
+  asmdialect = cast(A)->getDialect();
+} break;
 }
   }
   SaveAndRestore save_nomerge(InNoMergeAttributedStmt, nomerge);
@@ -762,6 +767,7 @@ void CodeGenFunction::EmitAttributedStmt(const 
AttributedStmt &S) {
   SaveAndRestore save_alwaysinline(InAlwaysInlineAttributedStmt, alwaysinline);
   SaveAndRestore save_noconvergent(InNoConvergentAttributedStmt, noconvergent);
   SaveAndRestore save_musttail(MustTailCall, musttail);
+  SaveAndRestore save_asmdialect(AsmDialect, asmdialect);
   EmitStmt(S.getSubStmt(), S.getAttrs());
 }
 
@@ -3029,12 +3035,47 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
 
   bool HasSideEffect = S.isVolatile() || S.getNumOutputs() == 0;
 
-  llvm::InlineAsm::AsmDialect GnuAsmDialect =
-  CGM.getCodeGenOpts().getInlineAsmDialect() == CodeGenOptions::IAD_ATT
-  ? llvm::InlineAsm::AD_ATT
-  : llvm::InlineAsm::AD_Intel;
-  llvm::InlineAsm::AsmDialect AsmDialect = isa(&S) ?
-llvm::InlineAsm::AD_Intel : GnuAsmDialect;
+  llvm::InlineAsm::AsmDialect AsmDialect;
+  auto GlobalAsmDialect = [&] {
+return CGM.getCodeGenOpts().getInlineAsmDialect() == 
CodeGenOptions::IAD_ATT
+   ? llvm::InlineAsm::AD_ATT
+   : llvm::InlineAsm::AD_Intel;
+  };
+  if (auto *GS = dyn_cast(&S)) {
+switch (this->AsmDialect) { // Fixme: rename member
+case AsmDialectAttr::Intel:
+  AsmDialect = llvm::InlineAsm::AsmDialect::AD_Intel;
+  break;
+case AsmDialectAttr::ATT:
+  AsmDialect = llvm::InlineAsm::AsmDialect::AD_ATT;
+  break;
+case AsmDialectAttr::Local:
+  if (CurFuncDecl) {
+if (auto *DialectAttr = CurFuncDecl->getAttr()) {
+  switch (DialectAttr->getDialect()) {
+  case AsmDialectAttr::Intel:
+AsmDialect = llvm::InlineAsm::AsmDialect::AD_Intel;
+break;
+  case AsmDialectAttr::ATT:
+AsmDialect = llvm::InlineAsm::AsmDialect::AD_ATT;
+break;
+  case AsmDialectAttr::Global:
+  case AsmDialectAttr::Local:
+AsmDialect = GlobalAsmDialect();
+break;
+  }
+  break;
+}
+  }
+  [[fallthrough]];
+case AsmDialectAttr::Global:
+  AsmDialect = GlobalAsmDialect();
+  break;
+}
+  } else {
+assert(isa(&S));
+AsmDialect = llvm::InlineAsm::AD_Intel;
+  }
 
   llvm::InlineAsm *IA = llvm::InlineAsm::get(
   FTy, AsmString, Constraints, HasSideEffect,
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 6a5faa1e8f343..d8af9285f6d22 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -615,6 +615,10 @@ class CodeGenFunction : public CodeGenT

[clang] [Clang] Remove __is_nullptr (PR #99038)

2024-08-04 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/99038

>From fbc9ebb3900e69f2485111cfdc6b7a7dfd3e6ebe Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 16 Jul 2024 14:53:30 +0200
Subject: [PATCH 1/2] [Clang] Remove __is_nullptr

---
 clang/docs/LanguageExtensions.rst  |  4 
 clang/lib/Parse/ParseDeclCXX.cpp   |  5 ++---
 clang/lib/Parse/ParseExpr.cpp  |  1 -
 clang/lib/Sema/SemaExprCXX.cpp |  3 ---
 clang/test/SemaCXX/type-traits.cpp | 36 --
 5 files changed, 2 insertions(+), 47 deletions(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 81784c75081ba..cfd7d29fb9eac 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1614,10 +1614,6 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_nothrow_assignable`` (C++, MSVC 2013)
 * ``__is_nothrow_constructible`` (C++, MSVC 2013)
 * ``__is_nothrow_destructible`` (C++, MSVC 2013)
-* ``__is_nullptr`` (C++, GNU, Microsoft, Embarcadero):
-  Returns true for ``std::nullptr_t`` and false for everything else. The
-  corresponding standard library feature is ``std::is_null_pointer``, but
-  ``__is_null_pointer`` is already in use by some implementations.
 * ``__is_object`` (C++, Embarcadero)
 * ``__is_pod`` (C++, GNU, Microsoft, Embarcadero):
   Note, the corresponding standard trait was deprecated in C++20.
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index ce827c689beb7..2c201d346328b 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -447,9 +447,9 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, 
DeclaratorContext Context) {
 ///
 /// HLSL: Parse export function declaration.
 ///
-///  export-function-declaration: 
+///  export-function-declaration:
 /// 'export' function-declaration
-/// 
+///
 ///  export-declaration-group:
 /// 'export' '{' function-declaration-seq[opt] '}'
 ///
@@ -1799,7 +1799,6 @@ void Parser::ParseClassSpecifier(tok::TokenKind 
TagTokKind,
   tok::kw___is_nothrow_constructible,
   tok::kw___is_nothrow_convertible,
   tok::kw___is_nothrow_destructible,
-  tok::kw___is_nullptr,
   tok::kw___is_object,
   tok::kw___is_pod,
   tok::kw___is_pointer,
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 3d7c58e5b3c3c..b3df9cfbc8b9a 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -800,7 +800,6 @@ bool Parser::isRevertibleTypeTrait(const IdentifierInfo *II,
 REVERTIBLE_TYPE_TRAIT(__is_nothrow_assignable);
 REVERTIBLE_TYPE_TRAIT(__is_nothrow_constructible);
 REVERTIBLE_TYPE_TRAIT(__is_nothrow_destructible);
-REVERTIBLE_TYPE_TRAIT(__is_nullptr);
 REVERTIBLE_TYPE_TRAIT(__is_object);
 REVERTIBLE_TYPE_TRAIT(__is_pod);
 REVERTIBLE_TYPE_TRAIT(__is_pointer);
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index bef7da239e6e5..a41b938531cab 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4979,7 +4979,6 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, 
TypeTrait UTT,
   case UTT_IsArray:
   case UTT_IsBoundedArray:
   case UTT_IsPointer:
-  case UTT_IsNullPointer:
   case UTT_IsReferenceable:
   case UTT_IsLvalueReference:
   case UTT_IsRvalueReference:
@@ -5235,8 +5234,6 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return T->isIncompleteArrayType();
   case UTT_IsPointer:
 return T->isAnyPointerType();
-  case UTT_IsNullPointer:
-return T->isNullPtrType();
   case UTT_IsLvalueReference:
 return T->isLValueReferenceType();
   case UTT_IsRvalueReference:
diff --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 7adbf4aad7afe..b38e8989cb559 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -1041,42 +1041,6 @@ void is_pointer()
   static_assert(!__is_pointer(void (StructWithMembers::*) ()));
 }
 
-void is_null_pointer() {
-  StructWithMembers x;
-
-  static_assert(__is_nullptr(decltype(nullptr)));
-  static_assert(!__is_nullptr(void *));
-  static_assert(!__is_nullptr(cvoid *));
-  static_assert(!__is_nullptr(cvoid *));
-  static_assert(!__is_nullptr(char *));
-  static_assert(!__is_nullptr(int *));
-  static_assert(!__is_nullptr(int **));
-  static_assert(!__is_nullptr(ClassType *));
-  static_assert(!__is_nullptr(Derives *));
-  static_assert(!__is_nullptr(Enum *));
-  static_assert(!__is_nullptr(IntArNB *));
-  static_assert(!__is_nullptr(Union *));
-  static_assert(!__is_nullptr(UnionAr *));
-  static_assert(!__is_nullptr(StructWithMembers *));
-  static_assert(!__is_nullptr(void (*)()));
-
-  static_assert(!__is_nullptr(void));
-  static_assert(!__is_nullptr(cvoid));
-  static_assert(!__is_nullptr(cvoid));
-  static_assert(!__i

[clang] eccc648 - [Clang] Remove __is_nullptr (#99038)

2024-08-04 Thread via cfe-commits

Author: Nikolas Klauser
Date: 2024-08-04T10:34:04+02:00
New Revision: eccc6487c1fc5925ea2e595b5b07a31976c3232e

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

LOG: [Clang] Remove __is_nullptr (#99038)

`is_null_pointer` can be implemented very efficiently as
`__is_same(__remove_cv(T), decltype(nullptr))`. Since GCC supports both
of these builtins as well, libc++ has no interest in using
`__is_nullptr` instead. Furthermore, I could find only a single use in
the wild
(https://sourcegraph.com/search?q=context:global+__is_nullptr%28+-file:clang&patternType=keyword&sm=0).
Because of these reasons I don't think it's worth keeping this builtin
around.

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/SemaCXX/type-traits.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index a747464582e77..9dcb4ac9b75ca 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1615,10 +1615,6 @@ The following type trait primitives are supported by 
Clang. Those traits marked
 * ``__is_nothrow_assignable`` (C++, MSVC 2013)
 * ``__is_nothrow_constructible`` (C++, MSVC 2013)
 * ``__is_nothrow_destructible`` (C++, MSVC 2013)
-* ``__is_nullptr`` (C++, GNU, Microsoft, Embarcadero):
-  Returns true for ``std::nullptr_t`` and false for everything else. The
-  corresponding standard library feature is ``std::is_null_pointer``, but
-  ``__is_null_pointer`` is already in use by some implementations.
 * ``__is_object`` (C++, Embarcadero)
 * ``__is_pod`` (C++, GNU, Microsoft, Embarcadero):
   Note, the corresponding standard trait was deprecated in C++20.

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4c7bd099420ab..3d76bd3ae272f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -43,6 +43,10 @@ C/C++ Language Potentially Breaking Changes
 C++ Specific Potentially Breaking Changes
 -
 
+- The type trait builtin ``__is_nullptr`` has been removed, since it has very
+  few users and can be written as ``__is_same(__remove_cv(T), 
decltype(nullptr))``,
+  which GCC supports as well.
+
 ABI Changes in This Version
 ---
 

diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp 
b/clang/lib/Parse/ParseDeclCXX.cpp
index ce827c689beb7..aac89d910bbc8 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -447,7 +447,7 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, 
DeclaratorContext Context) {
 ///
 /// HLSL: Parse export function declaration.
 ///
-///  export-function-declaration: 
+///  export-function-declaration:
 /// 'export' function-declaration
 /// 
 ///  export-declaration-group:
@@ -1799,7 +1799,6 @@ void Parser::ParseClassSpecifier(tok::TokenKind 
TagTokKind,
   tok::kw___is_nothrow_constructible,
   tok::kw___is_nothrow_convertible,
   tok::kw___is_nothrow_destructible,
-  tok::kw___is_nullptr,
   tok::kw___is_object,
   tok::kw___is_pod,
   tok::kw___is_pointer,

diff  --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index e501d5e91e77d..826e7b603ee82 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -802,7 +802,6 @@ bool Parser::isRevertibleTypeTrait(const IdentifierInfo *II,
 REVERTIBLE_TYPE_TRAIT(__is_nothrow_assignable);
 REVERTIBLE_TYPE_TRAIT(__is_nothrow_constructible);
 REVERTIBLE_TYPE_TRAIT(__is_nothrow_destructible);
-REVERTIBLE_TYPE_TRAIT(__is_nullptr);
 REVERTIBLE_TYPE_TRAIT(__is_object);
 REVERTIBLE_TYPE_TRAIT(__is_pod);
 REVERTIBLE_TYPE_TRAIT(__is_pointer);

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index c5003d9ac0254..124435330ca10 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -4982,7 +4982,6 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, 
TypeTrait UTT,
   case UTT_IsArray:
   case UTT_IsBoundedArray:
   case UTT_IsPointer:
-  case UTT_IsNullPointer:
   case UTT_IsReferenceable:
   case UTT_IsLvalueReference:
   case UTT_IsRvalueReference:
@@ -5241,8 +5240,6 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return T->isIncompleteArrayType();
   case UTT_IsPointer:
 return T->isAnyPointerType();
-  case UTT_IsNullPointer:
-return T->isNullPtrType();
   case UTT_IsLvalueReference:
 return T->isLValueReferenceType();
   case UTT_IsRvalueReference:

diff  --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp

[clang] [Clang] Remove __is_nullptr (PR #99038)

2024-08-04 Thread Nikolas Klauser via cfe-commits

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


[clang] [libcxx] Reapply "[Clang] Implement resolution for CWG1835 (#92957, #98547)" (PR #100425)

2024-08-04 Thread via cfe-commits

cor3ntin wrote:

There is now https://cplusplus.github.io/CWG/issues/2920.html

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


[clang] [Clang][CodeGen] Add `[[clang::asm_dialect]]` attribute (PR #101871)

2024-08-04 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/101871

>From 7f8c82071c9cc324acd7f2a79539392e74838545 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 4 Aug 2024 09:09:19 +0100
Subject: [PATCH] [Clang][CodeGen] Add `[[clang::asm_dialect]]` attribute

---
 clang/include/clang/Basic/Attr.td |  7 ++
 clang/lib/CodeGen/CGStmt.cpp  | 53 +--
 clang/lib/CodeGen/CodeGenFunction.h   |  4 ++
 clang/lib/Parse/ParseStmt.cpp | 12 ++--
 clang/lib/Sema/SemaDeclAttr.cpp   | 18 +
 clang/lib/Sema/SemaStmtAttr.cpp   | 21 ++
 clang/test/CodeGen/inline-asm-mixed-dialect.c | 66 +++
 ...a-attribute-supported-attributes-list.test |  1 +
 8 files changed, 168 insertions(+), 14 deletions(-)
 create mode 100644 clang/test/CodeGen/inline-asm-mixed-dialect.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 8ac2079099c85..1249f68e8e645 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4730,3 +4730,10 @@ def ClspvLibclcBuiltin: InheritableAttr {
   let Documentation = [ClspvLibclcBuiltinDoc];
   let SimpleHandler = 1;
 }
+
+def AsmDialect: DeclOrStmtAttr {
+  let Spellings = [Clang<"asm_dialect">];
+  let Subjects = SubjectList<[GCCAsmStmt, Function], ErrorDiag, "'asm' inline 
assembly statements or functions">;
+  let Args = [EnumArgument<"Dialect", "Kind", /*is_string=*/true, ["intel", 
"att", "reset", ""], ["Intel", "ATT", "Global", "Local"]>];
+  let Documentation = [Undocumented];
+}
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 30b6fce5d016a..b4b5efa575230 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -724,6 +724,8 @@ void CodeGenFunction::EmitAttributedStmt(const 
AttributedStmt &S) {
   bool noinline = false;
   bool alwaysinline = false;
   bool noconvergent = false;
+  AsmDialectAttr::Kind asmdialect = AsmDialectAttr::Kind::Local;
+
   const CallExpr *musttail = nullptr;
 
   for (const auto *A : S.getAttrs()) {
@@ -755,6 +757,9 @@ void CodeGenFunction::EmitAttributedStmt(const 
AttributedStmt &S) {
 Builder.CreateAssumption(AssumptionVal);
   }
 } break;
+case attr::AsmDialect: {
+  asmdialect = cast(A)->getDialect();
+} break;
 }
   }
   SaveAndRestore save_nomerge(InNoMergeAttributedStmt, nomerge);
@@ -762,6 +767,7 @@ void CodeGenFunction::EmitAttributedStmt(const 
AttributedStmt &S) {
   SaveAndRestore save_alwaysinline(InAlwaysInlineAttributedStmt, alwaysinline);
   SaveAndRestore save_noconvergent(InNoConvergentAttributedStmt, noconvergent);
   SaveAndRestore save_musttail(MustTailCall, musttail);
+  SaveAndRestore save_asmdialect(AsmDialect, asmdialect);
   EmitStmt(S.getSubStmt(), S.getAttrs());
 }
 
@@ -3029,12 +3035,47 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
 
   bool HasSideEffect = S.isVolatile() || S.getNumOutputs() == 0;
 
-  llvm::InlineAsm::AsmDialect GnuAsmDialect =
-  CGM.getCodeGenOpts().getInlineAsmDialect() == CodeGenOptions::IAD_ATT
-  ? llvm::InlineAsm::AD_ATT
-  : llvm::InlineAsm::AD_Intel;
-  llvm::InlineAsm::AsmDialect AsmDialect = isa(&S) ?
-llvm::InlineAsm::AD_Intel : GnuAsmDialect;
+  llvm::InlineAsm::AsmDialect AsmDialect;
+  auto GlobalAsmDialect = [&] {
+return CGM.getCodeGenOpts().getInlineAsmDialect() == 
CodeGenOptions::IAD_ATT
+   ? llvm::InlineAsm::AD_ATT
+   : llvm::InlineAsm::AD_Intel;
+  };
+  if (auto *GS = dyn_cast(&S)) {
+switch (this->AsmDialect) { // Fixme: rename member
+case AsmDialectAttr::Intel:
+  AsmDialect = llvm::InlineAsm::AsmDialect::AD_Intel;
+  break;
+case AsmDialectAttr::ATT:
+  AsmDialect = llvm::InlineAsm::AsmDialect::AD_ATT;
+  break;
+case AsmDialectAttr::Local:
+  if (CurFuncDecl) {
+if (auto *DialectAttr = CurFuncDecl->getAttr()) {
+  switch (DialectAttr->getDialect()) {
+  case AsmDialectAttr::Intel:
+AsmDialect = llvm::InlineAsm::AsmDialect::AD_Intel;
+break;
+  case AsmDialectAttr::ATT:
+AsmDialect = llvm::InlineAsm::AsmDialect::AD_ATT;
+break;
+  case AsmDialectAttr::Global:
+  case AsmDialectAttr::Local:
+AsmDialect = GlobalAsmDialect();
+break;
+  }
+  break;
+}
+  }
+  [[fallthrough]];
+case AsmDialectAttr::Global:
+  AsmDialect = GlobalAsmDialect();
+  break;
+}
+  } else {
+assert(isa(&S));
+AsmDialect = llvm::InlineAsm::AD_Intel;
+  }
 
   llvm::InlineAsm *IA = llvm::InlineAsm::get(
   FTy, AsmString, Constraints, HasSideEffect,
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 6a5faa1e8f343..d8af9285f6d22 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -61

[clang] [llvm] [X86][AVX10.2] Support YMM rounding new instructions (PR #101825)

2024-08-04 Thread Shengchen Kan via cfe-commits

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


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


[clang] [Clang] Implement C++26’s P2893R3 ‘Variadic friends’ (PR #101448)

2024-08-04 Thread via cfe-commits

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


[clang] [Clang] Implement C++26’s P2893R3 ‘Variadic friends’ (PR #101448)

2024-08-04 Thread via cfe-commits

https://github.com/cor3ntin commented:

Looks generally good from a cursory review.
I think we want to add tests for modules / in the test/PCH directory.

We probably want that as an extension indeed, no reason not to

We probably want a separate PR to add the pack indexing macro. I did not add it 
initially because i was concerned the implementation was not mature enough, but 
i think we fond most of the bugs.

I think it's fine to set the feature macro for that now with the assumption 
that we will find all the bugs in the next 6 months.

There seem to be some missing components, like the json node printer.

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


[clang] [Clang] Implement C++26’s P2893R3 ‘Variadic friends’ (PR #101448)

2024-08-04 Thread via cfe-commits


@@ -1442,8 +1442,49 @@ Decl 
*TemplateDeclInstantiator::VisitFriendDecl(FriendDecl *D) {
 if (D->isUnsupportedFriend()) {
   InstTy = Ty;
 } else {
-  InstTy = SemaRef.SubstType(Ty, TemplateArgs,
- D->getLocation(), DeclarationName());
+  if (D->isVariadic()) {
+SmallVector Unexpanded;
+SemaRef.collectUnexpandedParameterPacks(Ty->getTypeLoc(), Unexpanded);
+assert(!Unexpanded.empty() && "Pack expansion without packs");
+
+bool ShouldExpand = true;
+bool RetainExpansion = false;
+std::optional NumExpansions;
+if (SemaRef.CheckParameterPacksForExpansion(
+D->getEllipsisLoc(), D->getSourceRange(), Unexpanded,
+TemplateArgs, ShouldExpand, RetainExpansion, NumExpansions))
+  return nullptr;
+
+assert(!RetainExpansion &&
+   "should never retain an expansion for a FriendPackDecl");
+
+if (ShouldExpand) {
+  SmallVector Decls;
+  for (unsigned I = 0; I != *NumExpansions; I++) {
+Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
+TypeSourceInfo *TSI = SemaRef.SubstType(
+Ty, TemplateArgs, D->getEllipsisLoc(), DeclarationName());
+if (!TSI)
+  return nullptr;
+
+auto FD =
+FriendDecl::Create(SemaRef.Context, Owner, D->getLocation(),
+   TSI, D->getFriendLoc());
+
+FD->setAccess(AS_public);
+Owner->addDecl(FD);

cor3ntin wrote:

Should we call `setObjectOfFriendDecl` here?

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


[libunwind] [libunwind] Add GCS support for AArch64 (PR #99335)

2024-08-04 Thread Tobias Hieta via cfe-commits

tru wrote:

This seems to add a new feature, is it really relevant for a backport?

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


[clang] [Clang][CodeGen] Add `[[clang::asm_dialect]]` attribute (PR #101871)

2024-08-04 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/101871

>From 6dd98b5c255580909a9f38baa1bbdc257e5d60d2 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 4 Aug 2024 09:09:19 +0100
Subject: [PATCH] [Clang][CodeGen] Add `[[clang::asm_dialect]]` attribute

---
 clang/include/clang/Basic/Attr.td |  7 ++
 clang/lib/CodeGen/CGStmt.cpp  | 53 +--
 clang/lib/CodeGen/CodeGenFunction.h   |  4 ++
 clang/lib/Parse/ParseStmt.cpp | 14 ++--
 clang/lib/Sema/SemaDeclAttr.cpp   | 18 +
 clang/lib/Sema/SemaStmtAttr.cpp   | 21 ++
 clang/test/CodeGen/inline-asm-mixed-dialect.c | 66 +++
 ...a-attribute-supported-attributes-list.test |  1 +
 clang/test/Parser/asm.c   |  2 +-
 clang/test/Parser/asm.cpp |  2 +-
 10 files changed, 172 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/CodeGen/inline-asm-mixed-dialect.c

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 8ac2079099c85..1249f68e8e645 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4730,3 +4730,10 @@ def ClspvLibclcBuiltin: InheritableAttr {
   let Documentation = [ClspvLibclcBuiltinDoc];
   let SimpleHandler = 1;
 }
+
+def AsmDialect: DeclOrStmtAttr {
+  let Spellings = [Clang<"asm_dialect">];
+  let Subjects = SubjectList<[GCCAsmStmt, Function], ErrorDiag, "'asm' inline 
assembly statements or functions">;
+  let Args = [EnumArgument<"Dialect", "Kind", /*is_string=*/true, ["intel", 
"att", "reset", ""], ["Intel", "ATT", "Global", "Local"]>];
+  let Documentation = [Undocumented];
+}
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 30b6fce5d016a..b4b5efa575230 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -724,6 +724,8 @@ void CodeGenFunction::EmitAttributedStmt(const 
AttributedStmt &S) {
   bool noinline = false;
   bool alwaysinline = false;
   bool noconvergent = false;
+  AsmDialectAttr::Kind asmdialect = AsmDialectAttr::Kind::Local;
+
   const CallExpr *musttail = nullptr;
 
   for (const auto *A : S.getAttrs()) {
@@ -755,6 +757,9 @@ void CodeGenFunction::EmitAttributedStmt(const 
AttributedStmt &S) {
 Builder.CreateAssumption(AssumptionVal);
   }
 } break;
+case attr::AsmDialect: {
+  asmdialect = cast(A)->getDialect();
+} break;
 }
   }
   SaveAndRestore save_nomerge(InNoMergeAttributedStmt, nomerge);
@@ -762,6 +767,7 @@ void CodeGenFunction::EmitAttributedStmt(const 
AttributedStmt &S) {
   SaveAndRestore save_alwaysinline(InAlwaysInlineAttributedStmt, alwaysinline);
   SaveAndRestore save_noconvergent(InNoConvergentAttributedStmt, noconvergent);
   SaveAndRestore save_musttail(MustTailCall, musttail);
+  SaveAndRestore save_asmdialect(AsmDialect, asmdialect);
   EmitStmt(S.getSubStmt(), S.getAttrs());
 }
 
@@ -3029,12 +3035,47 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
 
   bool HasSideEffect = S.isVolatile() || S.getNumOutputs() == 0;
 
-  llvm::InlineAsm::AsmDialect GnuAsmDialect =
-  CGM.getCodeGenOpts().getInlineAsmDialect() == CodeGenOptions::IAD_ATT
-  ? llvm::InlineAsm::AD_ATT
-  : llvm::InlineAsm::AD_Intel;
-  llvm::InlineAsm::AsmDialect AsmDialect = isa(&S) ?
-llvm::InlineAsm::AD_Intel : GnuAsmDialect;
+  llvm::InlineAsm::AsmDialect AsmDialect;
+  auto GlobalAsmDialect = [&] {
+return CGM.getCodeGenOpts().getInlineAsmDialect() == 
CodeGenOptions::IAD_ATT
+   ? llvm::InlineAsm::AD_ATT
+   : llvm::InlineAsm::AD_Intel;
+  };
+  if (auto *GS = dyn_cast(&S)) {
+switch (this->AsmDialect) { // Fixme: rename member
+case AsmDialectAttr::Intel:
+  AsmDialect = llvm::InlineAsm::AsmDialect::AD_Intel;
+  break;
+case AsmDialectAttr::ATT:
+  AsmDialect = llvm::InlineAsm::AsmDialect::AD_ATT;
+  break;
+case AsmDialectAttr::Local:
+  if (CurFuncDecl) {
+if (auto *DialectAttr = CurFuncDecl->getAttr()) {
+  switch (DialectAttr->getDialect()) {
+  case AsmDialectAttr::Intel:
+AsmDialect = llvm::InlineAsm::AsmDialect::AD_Intel;
+break;
+  case AsmDialectAttr::ATT:
+AsmDialect = llvm::InlineAsm::AsmDialect::AD_ATT;
+break;
+  case AsmDialectAttr::Global:
+  case AsmDialectAttr::Local:
+AsmDialect = GlobalAsmDialect();
+break;
+  }
+  break;
+}
+  }
+  [[fallthrough]];
+case AsmDialectAttr::Global:
+  AsmDialect = GlobalAsmDialect();
+  break;
+}
+  } else {
+assert(isa(&S));
+AsmDialect = llvm::InlineAsm::AD_Intel;
+  }
 
   llvm::InlineAsm *IA = llvm::InlineAsm::get(
   FTy, AsmString, Constraints, HasSideEffect,
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 6a5faa1e8f343..

[clang] [clang] Implement `__builtin_is_implicit_lifetime()` (PR #101807)

2024-08-04 Thread via cfe-commits

https://github.com/cor3ntin commented:

Generally looks good but can you add tests for non aggregate with non elligible 
constructors and destructors ?
(ie a class template with `requires false` on various destructor/constructor?)
(or better yet a class template that takes a bool NTTP aso you can test with 
both a satisfied and unsatisfied condition. Also classes that have both an 
eligible and eligible constructor

Also tests for non-aggregates with an explicitly deleted destructor?


Thanks!

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


[clang] [Clang] strengthen checks for 'main' function to meet [basic.start.main] p2 requirements (PR #101853)

2024-08-04 Thread Mital Ashok via cfe-commits


@@ -990,6 +990,9 @@ def warn_main_redefined : Warning<"variable named 'main' 
with external linkage "
 "has undefined behavior">, InGroup;
 def ext_main_used : Extension<
 "referring to 'main' within an expression is a Clang extension">, 
InGroup;
+def err_invalid_linkage_specification : Extension<
+  "invalid linkage specification "
+  "'extern \"%select{C|C++}0\"'">;

MitalAshok wrote:

This doesn't say why it's invalid. `'main' cannot have linkage specification 
'extern "C(++)"'`?

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


[clang] [Clang] strengthen checks for 'main' function to meet [basic.start.main] p2 requirements (PR #101853)

2024-08-04 Thread Mital Ashok via cfe-commits


@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -pedantic-errors %s
+
+namespace c {
+  extern "C" void main(); // expected-error {{invalid linkage specification 
'extern "C"'}}
+}
+extern "C" {
+  int main(); // expected-error {{invalid linkage specification 'extern "C"'}}
+}
+extern "C" int main(); // expected-error {{invalid linkage specification 
'extern "C"'}}
+extern "C" struct A { int main(); }; // ok
+
+namespace cpp {
+  extern "C++" int main(); // expected-error {{invalid linkage specification 
'extern "C++"'}}

MitalAshok wrote:

This one is allowed, https://eel.is/c++draft/basic.start.main#3.4 only 
disallows `extern "C"` `main`. If you are implementing that, could you add 
tests for functions (`extern "C" { int main(); }`) and variables (`extern "C" { 
void* main; }`) named `main`?

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


[clang] [Clang] SFINAE on mismatching pack length during constraint satisfaction checking (PR #101879)

2024-08-04 Thread via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/101879

If a fold expanded constraint would expand packs of different size, it is not a 
valid pack expansion and it is not satisfied. This should not produce an error.

Fixes #99430

>From 665047d94935c71230322bb4a5951a9a567a64bb Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Sun, 4 Aug 2024 12:14:31 +0200
Subject: [PATCH] [Clang] SFINAE on mismatching pack lenght during constraint
 satisfaction checking

If a fold expanded constraint would expand packs of different size,
it is not a valid pack expansion and it is not satisfied.
This should not produce an error.

Fixes #99430
---
 clang/lib/Sema/SemaConcept.cpp  |  4 
 clang/test/SemaCXX/cxx2c-fold-exprs.cpp | 30 +
 2 files changed, 34 insertions(+)

diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 9e16b67284be4..c34d32002b5ad 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -531,6 +531,10 @@ static ExprResult calculateConstraintSatisfaction(
 
 std::optional
 EvaluateFoldExpandedConstraintSize(const CXXFoldExpr *FE) const {
+
+  // We should ignore errors in the presence of packs of different size.
+  Sema::SFINAETrap Trap(S);
+
   Expr *Pattern = FE->getPattern();
 
   SmallVector Unexpanded;
diff --git a/clang/test/SemaCXX/cxx2c-fold-exprs.cpp 
b/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
index 1e0bc7bcfb4e7..0674135aac483 100644
--- a/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
+++ b/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
@@ -275,3 +275,33 @@ static_assert(S::g() == 2); // expected-error 
{{call to 'g' is ambiguo
 
 
 }
+
+namespace GH99430 {
+
+template 
+using _Synth_three_way_result = int;
+
+template 
+class tuple;
+
+template 
+struct tuple_element;
+
+template 
+struct _Three_way_comparison_result_with_tuple_like {
+  using type = int;
+};
+
+template 
+  requires(requires {
+typename _Synth_three_way_result<_TTypes, tuple_element<_Indices>>;
+  } && ...)
+
+struct _Three_way_comparison_result_with_tuple_like, 
_Indices...>{
+using type = long;
+};
+
+static_assert(__is_same_as(_Three_way_comparison_result_with_tuple_like,
 0, 1>::type, int));
+static_assert(__is_same_as(_Three_way_comparison_result_with_tuple_like,
 0>::type, long));
+
+}

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


[clang] [Clang] SFINAE on mismatching pack length during constraint satisfaction checking (PR #101879)

2024-08-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)


Changes

If a fold expanded constraint would expand packs of different size, it is not a 
valid pack expansion and it is not satisfied. This should not produce an error.

Fixes #99430

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaConcept.cpp (+4) 
- (modified) clang/test/SemaCXX/cxx2c-fold-exprs.cpp (+30) 


``diff
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 9e16b67284be4..c34d32002b5ad 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -531,6 +531,10 @@ static ExprResult calculateConstraintSatisfaction(
 
 std::optional
 EvaluateFoldExpandedConstraintSize(const CXXFoldExpr *FE) const {
+
+  // We should ignore errors in the presence of packs of different size.
+  Sema::SFINAETrap Trap(S);
+
   Expr *Pattern = FE->getPattern();
 
   SmallVector Unexpanded;
diff --git a/clang/test/SemaCXX/cxx2c-fold-exprs.cpp 
b/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
index 1e0bc7bcfb4e7..0674135aac483 100644
--- a/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
+++ b/clang/test/SemaCXX/cxx2c-fold-exprs.cpp
@@ -275,3 +275,33 @@ static_assert(S::g() == 2); // expected-error 
{{call to 'g' is ambiguo
 
 
 }
+
+namespace GH99430 {
+
+template 
+using _Synth_three_way_result = int;
+
+template 
+class tuple;
+
+template 
+struct tuple_element;
+
+template 
+struct _Three_way_comparison_result_with_tuple_like {
+  using type = int;
+};
+
+template 
+  requires(requires {
+typename _Synth_three_way_result<_TTypes, tuple_element<_Indices>>;
+  } && ...)
+
+struct _Three_way_comparison_result_with_tuple_like, 
_Indices...>{
+using type = long;
+};
+
+static_assert(__is_same_as(_Three_way_comparison_result_with_tuple_like,
 0, 1>::type, int));
+static_assert(__is_same_as(_Three_way_comparison_result_with_tuple_like,
 0>::type, long));
+
+}

``




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


[clang] [Clang] SFINAE on mismatching pack length during constraint satisfaction checking (PR #101879)

2024-08-04 Thread via cfe-commits

cor3ntin wrote:

The intent is for this to be backported to 19 (therefore no changelog)

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


[clang] [clang] concepts: perform parameter mapping substitution in correct context (PR #101745)

2024-08-04 Thread via cfe-commits

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

LGTM, thanks!
Do we want to backport to clang 19? that seems reasonable

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


[clang] [clang] Implement `__builtin_is_implicit_lifetime()` (PR #101807)

2024-08-04 Thread Mital Ashok via cfe-commits


@@ -5637,6 +5638,27 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return false;
   case UTT_IsTriviallyEqualityComparable:
 return isTriviallyEqualityComparableType(Self, T, KeyLoc);
+  case UTT_IsImplicitLifetime: {
+DiagnoseVLAInCXXTypeTrait(Self, TInfo,
+  tok::kw___builtin_is_implicit_lifetime);
+QualType UnqualT = T->getCanonicalTypeUnqualified();
+if (UnqualT->isScalarType())
+  return true;
+if (UnqualT->isArrayType())
+  return true;
+
+const CXXRecordDecl *RD = UnqualT->getAsCXXRecordDecl();

MitalAshok wrote:

It would be nice to include the text from https://eel.is/c++draft/class.prop#9 
here

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


[clang] [clang] Implement `__builtin_is_implicit_lifetime()` (PR #101807)

2024-08-04 Thread Mital Ashok via cfe-commits


@@ -5637,6 +5638,27 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return false;
   case UTT_IsTriviallyEqualityComparable:
 return isTriviallyEqualityComparableType(Self, T, KeyLoc);
+  case UTT_IsImplicitLifetime: {
+DiagnoseVLAInCXXTypeTrait(Self, TInfo,
+  tok::kw___builtin_is_implicit_lifetime);
+QualType UnqualT = T->getCanonicalTypeUnqualified();
+if (UnqualT->isScalarType())
+  return true;
+if (UnqualT->isArrayType())
+  return true;
+
+const CXXRecordDecl *RD = UnqualT->getAsCXXRecordDecl();
+if (!RD)
+  return false;
+if (UnqualT->isAggregateType())
+  if (!RD->getDestructor()->isUserProvided())
+return true;
+if (RD->hasTrivialDestructor())

MitalAshok wrote:

You also need to check that it's not deleted too.

Currently the first two assertions fail here:

```c++
struct X { ~X() = delete; };
struct Y { X x; ~Y() = default; };
struct Z { X x; };

static_assert(!__builtin_is_implicit_lifetime(X));
static_assert(!__builtin_is_implicit_lifetime(Y));
static_assert( __builtin_is_implicit_lifetime(Z));
```

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


[clang] [clang] Implement `__builtin_is_implicit_lifetime()` (PR #101807)

2024-08-04 Thread Mital Ashok via cfe-commits


@@ -86,6 +86,9 @@ C++23 Feature Support
 C++2c Feature Support
 ^
 
+- Add ``__builtin_is_implicit_lifetime`` intrinsic, which supports

MitalAshok wrote:

Why is this called `__builtin_is_implicit_lifetime` instead of 
`__is_implicit_lifetime` like all the other unary type traits? I thought 
`__builtin_*` is for functions that return objects

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


[clang] [clang] Implement `__builtin_is_implicit_lifetime()` (PR #101807)

2024-08-04 Thread Mital Ashok via cfe-commits


@@ -5637,6 +5638,27 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait 
UTT,
 return false;
   case UTT_IsTriviallyEqualityComparable:
 return isTriviallyEqualityComparableType(Self, T, KeyLoc);
+  case UTT_IsImplicitLifetime: {
+DiagnoseVLAInCXXTypeTrait(Self, TInfo,
+  tok::kw___builtin_is_implicit_lifetime);
+QualType UnqualT = T->getCanonicalTypeUnqualified();
+if (UnqualT->isScalarType())

MitalAshok wrote:

Are there any extension types that should be implicit lifetime? Like `typedef 
int v4si __attribute__ ((vector_size (16))); 
static_assert(__builtin_is_implicit_lifetime(v4si));`


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


[clang] [clang] Implement `__builtin_is_implicit_lifetime()` (PR #101807)

2024-08-04 Thread via cfe-commits


@@ -86,6 +86,9 @@ C++23 Feature Support
 C++2c Feature Support
 ^
 
+- Add ``__builtin_is_implicit_lifetime`` intrinsic, which supports

cor3ntin wrote:

CF https://github.com/llvm/llvm-project/issues/98310#issuecomment-2248326726

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


[clang] [Clang] SFINAE on mismatching pack length during constraint satisfaction checking (PR #101879)

2024-08-04 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll commented:

LGTM

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


[clang] [Clang] SFINAE on mismatching pack length during constraint satisfaction checking (PR #101879)

2024-08-04 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

> The intent is for this to be backported to 19 (therefore no changelog)

Yes, this is very important to backport.

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


[clang] [clang-tools-extra] [clangd] show lambda name instead of operator() in signature help (PR #101857)

2024-08-04 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll commented:

`Sema.h` changes LGTM

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


[clang] [clang] Implement `__builtin_is_implicit_lifetime()` (PR #101807)

2024-08-04 Thread Vlad Serebrennikov via cfe-commits


@@ -86,6 +86,9 @@ C++23 Feature Support
 C++2c Feature Support
 ^
 
+- Add ``__builtin_is_implicit_lifetime`` intrinsic, which supports

Endilll wrote:

See #98310

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


[clang] [llvm] [LV] Support generating masks for switch terminators. (PR #99808)

2024-08-04 Thread Florian Hahn via cfe-commits


@@ -7842,6 +7853,61 @@ VPValue *VPRecipeBuilder::createEdgeMask(BasicBlock 
*Src, BasicBlock *Dst) {
 
   VPValue *SrcMask = getBlockInMask(Src);
 
+  if (auto *SI = dyn_cast(Src->getTerminator())) {
+assert(!OrigLoop->isLoopExiting(Src) &&
+   all_of(successors(Src),
+  [this](BasicBlock *Succ) {
+return OrigLoop->getHeader() != Succ;
+  }) &&
+   "unsupported switch either exiting loop or continuing to header");
+// Create masks where the terminator in Src is a switch. We create mask for
+// all edges at the same time. This is more efficient, as we can create and
+// collect compares for all cases once.
+VPValue *Cond = getVPValueOrAddLiveIn(SI->getCondition(), Plan);
+BasicBlock *DefaultDst = SI->getDefaultDest();
+MapVector> Map;

fhahn wrote:

Updated to `Dst2Compares`, thanks!

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


[clang] [llvm] [LV] Support generating masks for switch terminators. (PR #99808)

2024-08-04 Thread Florian Hahn via cfe-commits


@@ -7842,6 +7853,61 @@ VPValue *VPRecipeBuilder::createEdgeMask(BasicBlock 
*Src, BasicBlock *Dst) {
 
   VPValue *SrcMask = getBlockInMask(Src);
 
+  if (auto *SI = dyn_cast(Src->getTerminator())) {
+assert(!OrigLoop->isLoopExiting(Src) &&
+   all_of(successors(Src),
+  [this](BasicBlock *Succ) {
+return OrigLoop->getHeader() != Succ;
+  }) &&
+   "unsupported switch either exiting loop or continuing to header");
+// Create masks where the terminator in Src is a switch. We create mask for
+// all edges at the same time. This is more efficient, as we can create and
+// collect compares for all cases once.
+VPValue *Cond = getVPValueOrAddLiveIn(SI->getCondition(), Plan);
+BasicBlock *DefaultDst = SI->getDefaultDest();
+MapVector> Map;
+for (auto &C : SI->cases()) {
+  auto I = Map.insert({C.getCaseSuccessor(), {}});
+  VPValue *V = getVPValueOrAddLiveIn(C.getCaseValue(), Plan);
+  I.first->second.push_back(Builder.createICmp(CmpInst::ICMP_EQ, Cond, V));
+}
+
+// We need to handle 2 separate cases:
+// 1. Dst is not the default destination. Dst is reached if any of the 
cases
+// with destination == Dst are taken. Join the conditions for each case
+// where destination == Dst using a logical OR.

fhahn wrote:

updated, thanks!

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


[clang] [llvm] [LV] Support generating masks for switch terminators. (PR #99808)

2024-08-04 Thread Florian Hahn via cfe-commits


@@ -7842,6 +7853,61 @@ VPValue *VPRecipeBuilder::createEdgeMask(BasicBlock 
*Src, BasicBlock *Dst) {
 
   VPValue *SrcMask = getBlockInMask(Src);
 
+  if (auto *SI = dyn_cast(Src->getTerminator())) {
+assert(!OrigLoop->isLoopExiting(Src) &&
+   all_of(successors(Src),
+  [this](BasicBlock *Succ) {
+return OrigLoop->getHeader() != Succ;
+  }) &&
+   "unsupported switch either exiting loop or continuing to header");
+// Create masks where the terminator in Src is a switch. We create mask for
+// all edges at the same time. This is more efficient, as we can create and
+// collect compares for all cases once.
+VPValue *Cond = getVPValueOrAddLiveIn(SI->getCondition(), Plan);
+BasicBlock *DefaultDst = SI->getDefaultDest();
+MapVector> Map;
+for (auto &C : SI->cases()) {
+  auto I = Map.insert({C.getCaseSuccessor(), {}});
+  VPValue *V = getVPValueOrAddLiveIn(C.getCaseValue(), Plan);
+  I.first->second.push_back(Builder.createICmp(CmpInst::ICMP_EQ, Cond, V));
+}
+
+// We need to handle 2 separate cases:
+// 1. Dst is not the default destination. Dst is reached if any of the 
cases
+// with destination == Dst are taken. Join the conditions for each case
+// where destination == Dst using a logical OR.
+for (const auto &[Dst, Conds] : Map) {

fhahn wrote:

outlined, thanks!

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


[clang] [llvm] [LV] Support generating masks for switch terminators. (PR #99808)

2024-08-04 Thread Florian Hahn via cfe-commits


@@ -7842,6 +7853,61 @@ VPValue *VPRecipeBuilder::createEdgeMask(BasicBlock 
*Src, BasicBlock *Dst) {
 
   VPValue *SrcMask = getBlockInMask(Src);
 
+  if (auto *SI = dyn_cast(Src->getTerminator())) {
+assert(!OrigLoop->isLoopExiting(Src) &&
+   all_of(successors(Src),
+  [this](BasicBlock *Succ) {
+return OrigLoop->getHeader() != Succ;
+  }) &&
+   "unsupported switch either exiting loop or continuing to header");
+// Create masks where the terminator in Src is a switch. We create mask for
+// all edges at the same time. This is more efficient, as we can create and
+// collect compares for all cases once.
+VPValue *Cond = getVPValueOrAddLiveIn(SI->getCondition(), Plan);
+BasicBlock *DefaultDst = SI->getDefaultDest();
+MapVector> Map;
+for (auto &C : SI->cases()) {
+  auto I = Map.insert({C.getCaseSuccessor(), {}});
+  VPValue *V = getVPValueOrAddLiveIn(C.getCaseValue(), Plan);
+  I.first->second.push_back(Builder.createICmp(CmpInst::ICMP_EQ, Cond, V));
+}
+
+// We need to handle 2 separate cases:
+// 1. Dst is not the default destination. Dst is reached if any of the 
cases
+// with destination == Dst are taken. Join the conditions for each case
+// where destination == Dst using a logical OR.
+for (const auto &[Dst, Conds] : Map) {
+  VPValue *Mask = Conds[0];
+  for (VPValue *V : ArrayRef(Conds).drop_front())
+Mask = Builder.createOr(Mask, V);
+  if (SrcMask)
+Mask = Builder.createLogicalAnd(SrcMask, Mask);
+  EdgeMaskCache[{Src, Dst}] = Mask;

fhahn wrote:

Updated, thanks!

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


[clang] [llvm] [LV] Support generating masks for switch terminators. (PR #99808)

2024-08-04 Thread Florian Hahn via cfe-commits


@@ -7842,6 +7853,61 @@ VPValue *VPRecipeBuilder::createEdgeMask(BasicBlock 
*Src, BasicBlock *Dst) {
 
   VPValue *SrcMask = getBlockInMask(Src);
 
+  if (auto *SI = dyn_cast(Src->getTerminator())) {
+assert(!OrigLoop->isLoopExiting(Src) &&
+   all_of(successors(Src),
+  [this](BasicBlock *Succ) {
+return OrigLoop->getHeader() != Succ;
+  }) &&
+   "unsupported switch either exiting loop or continuing to header");
+// Create masks where the terminator in Src is a switch. We create mask for
+// all edges at the same time. This is more efficient, as we can create and
+// collect compares for all cases once.
+VPValue *Cond = getVPValueOrAddLiveIn(SI->getCondition(), Plan);
+BasicBlock *DefaultDst = SI->getDefaultDest();
+MapVector> Map;
+for (auto &C : SI->cases()) {
+  auto I = Map.insert({C.getCaseSuccessor(), {}});
+  VPValue *V = getVPValueOrAddLiveIn(C.getCaseValue(), Plan);
+  I.first->second.push_back(Builder.createICmp(CmpInst::ICMP_EQ, Cond, V));
+}
+
+// We need to handle 2 separate cases:
+// 1. Dst is not the default destination. Dst is reached if any of the 
cases
+// with destination == Dst are taken. Join the conditions for each case
+// where destination == Dst using a logical OR.
+for (const auto &[Dst, Conds] : Map) {
+  VPValue *Mask = Conds[0];
+  for (VPValue *V : ArrayRef(Conds).drop_front())
+Mask = Builder.createOr(Mask, V);
+  if (SrcMask)
+Mask = Builder.createLogicalAnd(SrcMask, Mask);
+  EdgeMaskCache[{Src, Dst}] = Mask;
+}
+
+// 2. Dst is the default destination. Dst is reached if none of the cases
+// with destination != Dst are taken. Join the conditions for each case
+// where the destination is != Dst using a logical OR and negate it.

fhahn wrote:

Thanks, updated

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


[clang] [clang-format] Add PackParameters enum option to replace BinPackParameters. (PR #101882)

2024-08-04 Thread via cfe-commits

https://github.com/VolatileAcorn created 
https://github.com/llvm/llvm-project/pull/101882

Deprecated the BinPackParameters boolean option in favor or PackParameters enum 
option in order to provide a BreakAlways setting.

Related issues that have requested this feature
#51833
#23796 
#53190 Partially solves - this issue requests is for both arguments and 
parameters




>From 6739bb5006bc28e2bdbdb2326eb2c957546634aa Mon Sep 17 00:00:00 2001
From: Tom Pottage 
Date: Fri, 2 Aug 2024 20:26:47 +0100
Subject: [PATCH] [clang-format] Add PackParameters option to replace
 BinPackParameters. The PackParameters option now provides the new BreakAlways
 setting

---
 clang/docs/ClangFormatStyleOptions.rst|  52 --
 clang/include/clang/Format/Format.h   |  48 --
 clang/lib/Format/ContinuationIndenter.cpp |  26 +--
 clang/lib/Format/Format.cpp   |  38 -
 clang/lib/Format/FormatToken.h|  18 +++
 clang/lib/Format/TokenAnnotator.cpp   |   8 +
 clang/unittests/Format/ConfigParseTest.cpp|  16 +-
 clang/unittests/Format/FormatTest.cpp | 153 +++---
 clang/unittests/Format/FormatTestComments.cpp |   4 +-
 clang/unittests/Format/FormatTestObjC.cpp |   2 +-
 10 files changed, 289 insertions(+), 76 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 6c2e6da594847..510b956968dc6 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2068,19 +2068,7 @@ the configuration (without a prefix: ``Auto``).
 .. _BinPackParameters:
 
 **BinPackParameters** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ 
`
-  If ``false``, a function declaration's or function definition's
-  parameters will either all be on the same line or will have one line each.
-
-  .. code-block:: c++
-
-true:
-void f(int , int ,
-   int aaa) {}
-
-false:
-void f(int ,
-   int ,
-   int aaa) {}
+  This option is **deprecated**. See ``PackParameters``.
 
 .. _BitFieldColonSpacing:
 
@@ -4984,6 +4972,44 @@ the configuration (without a prefix: ``Auto``).
 
 
 
+.. _PackParameters:
+
+**PackParameters** (``PackParametersStyle``) :versionbadge:`clang-format 20` 
:ref:`¶ `
+  The pack parameters style to use.
+
+  Possible values:
+
+  * ``PPS_CurrentLine`` (in configuration: ``CurrentLine``)
+Put all parameters on the current line if they fit.
+Otherwise, put each one on its own line.
+
+.. code-block:: c++
+
+   void f(int a, int b, int c);
+
+   void f(int a,
+  int b,
+  int c);
+
+  * ``PPS_BinPack`` (in configuration: ``BinPack``)
+Bin-pack parameters.
+
+.. code-block:: c++
+
+   void f(int a, int ,
+  int ccc);
+
+  * ``PPS_BreakAlways`` (in configuration: ``BreakAlways``)
+Always put each parameter on its own line.
+
+.. code-block:: c++
+
+   void f(int a,
+  int b,
+  int c);
+
+
+
 .. _PenaltyBreakAssignment:
 
 **PenaltyBreakAssignment** (``Unsigned``) :versionbadge:`clang-format 5` 
:ref:`¶ `
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index c454ab2bc0ce2..2991ab18f980d 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1192,20 +1192,9 @@ struct FormatStyle {
   /// \version 3.7
   bool BinPackArguments;
 
-  /// If ``false``, a function declaration's or function definition's
-  /// parameters will either all be on the same line or will have one line 
each.
-  /// \code
-  ///   true:
-  ///   void f(int , int ,
-  ///  int aaa) {}
-  ///
-  ///   false:
-  ///   void f(int ,
-  ///  int ,
-  ///  int aaa) {}
-  /// \endcode
+  /// This option is **deprecated**. See ``PackParameters``.
   /// \version 3.7
-  bool BinPackParameters;
+  // bool BinPackParameters;
 
   /// Styles for adding spacing around ``:`` in bitfield definitions.
   enum BitFieldColonSpacingStyle : int8_t {
@@ -3537,6 +3526,37 @@ struct FormatStyle {
   /// \version 14
   PackConstructorInitializersStyle PackConstructorInitializers;
 
+  /// Different way to try to fit all parameters on a line.
+  enum PackParametersStyle : int8_t {
+/// Put all parameters on the current line if they fit.
+/// Otherwise, put each one on its own line.
+/// \code
+///void f(int a, int b, int c);
+///
+///void f(int a,
+///   int b,
+///   int cc

[clang] [clang-format] Add PackParameters enum option to replace BinPackParameters. (PR #101882)

2024-08-04 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [clang-format] Add PackParameters enum option to replace BinPackParameters. (PR #101882)

2024-08-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (VolatileAcorn)


Changes

Deprecated the BinPackParameters boolean option in favor or PackParameters enum 
option in order to provide a BreakAlways setting.

Related issues that have requested this feature
#51833
#23796 
#53190 Partially solves - this issue requests is for both arguments and 
parameters




---

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


10 Files Affected:

- (modified) clang/docs/ClangFormatStyleOptions.rst (+39-13) 
- (modified) clang/include/clang/Format/Format.h (+34-14) 
- (modified) clang/lib/Format/ContinuationIndenter.cpp (+5-21) 
- (modified) clang/lib/Format/Format.cpp (+34-4) 
- (modified) clang/lib/Format/FormatToken.h (+18) 
- (modified) clang/lib/Format/TokenAnnotator.cpp (+8) 
- (modified) clang/unittests/Format/ConfigParseTest.cpp (+15-1) 
- (modified) clang/unittests/Format/FormatTest.cpp (+133-20) 
- (modified) clang/unittests/Format/FormatTestComments.cpp (+2-2) 
- (modified) clang/unittests/Format/FormatTestObjC.cpp (+1-1) 


``diff
diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 6c2e6da594847..510b956968dc6 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2068,19 +2068,7 @@ the configuration (without a prefix: ``Auto``).
 .. _BinPackParameters:
 
 **BinPackParameters** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ 
`
-  If ``false``, a function declaration's or function definition's
-  parameters will either all be on the same line or will have one line each.
-
-  .. code-block:: c++
-
-true:
-void f(int , int ,
-   int aaa) {}
-
-false:
-void f(int ,
-   int ,
-   int aaa) {}
+  This option is **deprecated**. See ``PackParameters``.
 
 .. _BitFieldColonSpacing:
 
@@ -4984,6 +4972,44 @@ the configuration (without a prefix: ``Auto``).
 
 
 
+.. _PackParameters:
+
+**PackParameters** (``PackParametersStyle``) :versionbadge:`clang-format 20` 
:ref:`¶ `
+  The pack parameters style to use.
+
+  Possible values:
+
+  * ``PPS_CurrentLine`` (in configuration: ``CurrentLine``)
+Put all parameters on the current line if they fit.
+Otherwise, put each one on its own line.
+
+.. code-block:: c++
+
+   void f(int a, int b, int c);
+
+   void f(int a,
+  int b,
+  int c);
+
+  * ``PPS_BinPack`` (in configuration: ``BinPack``)
+Bin-pack parameters.
+
+.. code-block:: c++
+
+   void f(int a, int ,
+  int ccc);
+
+  * ``PPS_BreakAlways`` (in configuration: ``BreakAlways``)
+Always put each parameter on its own line.
+
+.. code-block:: c++
+
+   void f(int a,
+  int b,
+  int c);
+
+
+
 .. _PenaltyBreakAssignment:
 
 **PenaltyBreakAssignment** (``Unsigned``) :versionbadge:`clang-format 5` 
:ref:`¶ `
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index c454ab2bc0ce2..2991ab18f980d 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1192,20 +1192,9 @@ struct FormatStyle {
   /// \version 3.7
   bool BinPackArguments;
 
-  /// If ``false``, a function declaration's or function definition's
-  /// parameters will either all be on the same line or will have one line 
each.
-  /// \code
-  ///   true:
-  ///   void f(int , int ,
-  ///  int aaa) {}
-  ///
-  ///   false:
-  ///   void f(int ,
-  ///  int ,
-  ///  int aaa) {}
-  /// \endcode
+  /// This option is **deprecated**. See ``PackParameters``.
   /// \version 3.7
-  bool BinPackParameters;
+  // bool BinPackParameters;
 
   /// Styles for adding spacing around ``:`` in bitfield definitions.
   enum BitFieldColonSpacingStyle : int8_t {
@@ -3537,6 +3526,37 @@ struct FormatStyle {
   /// \version 14
   PackConstructorInitializersStyle PackConstructorInitializers;
 
+  /// Different way to try to fit all parameters on a line.
+  enum PackParametersStyle : int8_t {
+/// Put all parameters on the current line if they fit.
+/// Otherwise, put each one on its own line.
+/// \code
+///void f(int a, int b, int c);
+///
+///void f(int a,
+///   int b,
+///   int c);
+/// \endcode
+PPS_CurrentLine,
+/// Bin-pack parameters.
+/// \code
+///void f(int a, int ,
+///  

[libunwind] [libunwind] Add GCS support for AArch64 (PR #99335)

2024-08-04 Thread John Brawn via cfe-commits

john-brawn-arm wrote:

> LGTM. Sorry for the delay.
> 
> Q: Is there a way to play with the GCS feature in a VM? Do you have setup 
> instructions?

https://git.yoctoproject.org/meta-arm/log/?h=testing/gcs is a demonstration 
embedded linux that support GCS, including an emulator capable of running it. 
https://git.yoctoproject.org/meta-arm/tree/meta-arm-gcs/README?h=testing/gcs is 
the instructions for building and running it.

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


[libunwind] [libunwind] Add GCS support for AArch64 (PR #99335)

2024-08-04 Thread John Brawn via cfe-commits

https://github.com/john-brawn-arm updated 
https://github.com/llvm/llvm-project/pull/99335

>From e0f71863bd2f797c9208bdfc559bb69ade5a653a Mon Sep 17 00:00:00 2001
From: John Brawn 
Date: Wed, 17 Jul 2024 15:18:46 +0100
Subject: [PATCH 1/4] [libunwind] Add GCS support for AArch64

AArch64 GCS (Guarded Control Stack) is similar enough to CET that we
can re-use the existing code that is guarded by _LIBUNWIND_USE_CET,
so long as we also add defines to locate the GCS stack and pop the
entries from it. We also need the jumpto function to exit using br
instead of ret, to prevent it from popping the GCS stack.

GCS support is enabled using the LIBUNWIND_ENABLE_GCS cmake option.
This enables -mbranch-protection=standard, which enables GCS. For
the places we need to use GCS instructions we use the target
attribute, as there's not a command-line option to enable a specific
architecture extension.
---
 libunwind/CMakeLists.txt  |  8 ++
 libunwind/src/Registers.hpp   |  7 +
 libunwind/src/UnwindLevel1.c  | 28 +++
 libunwind/src/UnwindRegistersRestore.S|  2 +-
 libunwind/src/cet_unwind.h| 19 +
 libunwind/test/CMakeLists.txt |  1 +
 .../test/configs/llvm-libunwind-merged.cfg.in |  3 ++
 .../test/configs/llvm-libunwind-shared.cfg.in |  3 ++
 .../test/configs/llvm-libunwind-static.cfg.in |  3 ++
 9 files changed, 73 insertions(+), 1 deletion(-)

diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index b22ade0a7d71e..28d67b0fef92c 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -37,6 +37,7 @@ if (LIBUNWIND_BUILD_32_BITS)
 endif()
 
 option(LIBUNWIND_ENABLE_CET "Build libunwind with CET enabled." OFF)
+option(LIBUNWIND_ENABLE_GCS "Build libunwind with GCS enabled." OFF)
 option(LIBUNWIND_ENABLE_ASSERTIONS "Enable assertions independent of build 
mode." ON)
 option(LIBUNWIND_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
 option(LIBUNWIND_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
@@ -188,6 +189,13 @@ if (LIBUNWIND_ENABLE_CET)
   endif()
 endif()
 
+if (LIBUNWIND_ENABLE_GCS)
+  add_compile_flags_if_supported(-mbranch-protection=standard)
+  if (NOT CXX_SUPPORTS_MBRANCH_PROTECTION_EQ_STANDARD_FLAG)
+message(SEND_ERROR "Compiler doesn't support GCS -mbranch-protection 
option!")
+  endif()
+endif()
+
 if (WIN32)
   # The headers lack matching dllexport attributes (_LIBUNWIND_EXPORT);
   # silence the warning instead of cluttering the headers (which aren't
diff --git a/libunwind/src/Registers.hpp b/libunwind/src/Registers.hpp
index d11ddb3426d52..0fc2a683a7fa4 100644
--- a/libunwind/src/Registers.hpp
+++ b/libunwind/src/Registers.hpp
@@ -1815,6 +1815,13 @@ inline const char *Registers_ppc64::getRegisterName(int 
regNum) {
 /// process.
 class _LIBUNWIND_HIDDEN Registers_arm64;
 extern "C" void __libunwind_Registers_arm64_jumpto(Registers_arm64 *);
+
+#if defined(_LIBUNWIND_USE_CET)
+extern "C" void *__libunwind_cet_get_jump_target() {
+  return reinterpret_cast(&__libunwind_Registers_arm64_jumpto);
+}
+#endif
+
 class _LIBUNWIND_HIDDEN Registers_arm64 {
 public:
   Registers_arm64();
diff --git a/libunwind/src/UnwindLevel1.c b/libunwind/src/UnwindLevel1.c
index 48e7bc3b9e00e..67a324947cbf1 100644
--- a/libunwind/src/UnwindLevel1.c
+++ b/libunwind/src/UnwindLevel1.c
@@ -72,6 +72,19 @@
 __asm__ volatile("jmpq *%%rdx\n\t" :: "D"(cetRegContext),  
\
  "d"(cetJumpAddress)); 
\
   } while (0)
+#elif defined(_LIBUNWIND_TARGET_AARCH64)
+#define __cet_ss_step_size 8
+#define __unw_phase2_resume(cursor, fn)
\
+  do { 
\
+_LIBUNWIND_POP_CET_SSP((fn));  
\
+void *cetRegContext = __libunwind_cet_get_registers((cursor)); 
\
+void *cetJumpAddress = __libunwind_cet_get_jump_target();  
\
+__asm__ volatile("mov x0, %0\n\t"  
\
+ "br %1\n\t"   
\
+ : 
\
+ : "r"(cetRegContext), "r"(cetJumpAddress) 
\
+ : "x0");  
\
+  } while (0)
 #endif
 
 static _Unwind_Reason_Code
@@ -170,6 +183,10 @@ unwind_phase1(unw_context_t *uc, unw_cursor_t *cursor, 
_Unwind_Exception *except
 }
 extern int __unw_step_stage2(unw_cursor_t *);
 
+#if defined(_LIBUNWIND_USE_CET) && defined(_LIBUNWIND_TARGET_AARCH64)
+// Enable the GCS target feature to permit GCS instructions to be used.
+__attribute__((target("gcs")))
+#endif
 static _Unwind_Reason_Code
 unwind_phase2(unw_context_t *uc, unw_cursor_t *cursor, _Unwind_Exception 

[libunwind] b32aac4 - [libunwind] Add GCS support for AArch64 (#99335)

2024-08-04 Thread via cfe-commits

Author: John Brawn
Date: 2024-08-04T13:27:12+01:00
New Revision: b32aac4358c1f6639de7c453656cd74fbab75d71

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

LOG: [libunwind] Add GCS support for AArch64 (#99335)

AArch64 GCS (Guarded Control Stack) is similar enough to CET that we can
re-use the existing code that is guarded by _LIBUNWIND_USE_CET, so long
as we also add defines to locate the GCS stack and pop the entries from
it. We also need the jumpto function to exit using br instead of ret, to
prevent it from popping the GCS stack.

GCS support is enabled using the LIBUNWIND_ENABLE_GCS cmake option. This
enables -mbranch-protection=standard, which enables GCS. For the places
we need to use GCS instructions we use the target attribute, as there's
not a command-line option to enable a specific architecture extension.

Added: 


Modified: 
libunwind/CMakeLists.txt
libunwind/src/Registers.hpp
libunwind/src/UnwindCursor.hpp
libunwind/src/UnwindLevel1.c
libunwind/src/UnwindRegistersRestore.S
libunwind/src/cet_unwind.h
libunwind/test/CMakeLists.txt
libunwind/test/configs/llvm-libunwind-merged.cfg.in
libunwind/test/configs/llvm-libunwind-shared.cfg.in
libunwind/test/configs/llvm-libunwind-static.cfg.in

Removed: 




diff  --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index b22ade0a7d71e..28d67b0fef92c 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -37,6 +37,7 @@ if (LIBUNWIND_BUILD_32_BITS)
 endif()
 
 option(LIBUNWIND_ENABLE_CET "Build libunwind with CET enabled." OFF)
+option(LIBUNWIND_ENABLE_GCS "Build libunwind with GCS enabled." OFF)
 option(LIBUNWIND_ENABLE_ASSERTIONS "Enable assertions independent of build 
mode." ON)
 option(LIBUNWIND_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
 option(LIBUNWIND_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
@@ -188,6 +189,13 @@ if (LIBUNWIND_ENABLE_CET)
   endif()
 endif()
 
+if (LIBUNWIND_ENABLE_GCS)
+  add_compile_flags_if_supported(-mbranch-protection=standard)
+  if (NOT CXX_SUPPORTS_MBRANCH_PROTECTION_EQ_STANDARD_FLAG)
+message(SEND_ERROR "Compiler doesn't support GCS -mbranch-protection 
option!")
+  endif()
+endif()
+
 if (WIN32)
   # The headers lack matching dllexport attributes (_LIBUNWIND_EXPORT);
   # silence the warning instead of cluttering the headers (which aren't

diff  --git a/libunwind/src/Registers.hpp b/libunwind/src/Registers.hpp
index d11ddb3426d52..861e6b5f6f2c5 100644
--- a/libunwind/src/Registers.hpp
+++ b/libunwind/src/Registers.hpp
@@ -1815,6 +1815,13 @@ inline const char *Registers_ppc64::getRegisterName(int 
regNum) {
 /// process.
 class _LIBUNWIND_HIDDEN Registers_arm64;
 extern "C" void __libunwind_Registers_arm64_jumpto(Registers_arm64 *);
+
+#if defined(_LIBUNWIND_USE_GCS)
+extern "C" void *__libunwind_cet_get_jump_target() {
+  return reinterpret_cast(&__libunwind_Registers_arm64_jumpto);
+}
+#endif
+
 class _LIBUNWIND_HIDDEN Registers_arm64 {
 public:
   Registers_arm64();

diff  --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 758557337899e..06e654197351d 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -471,7 +471,7 @@ class _LIBUNWIND_HIDDEN AbstractUnwindCursor {
   }
 #endif
 
-#if defined(_LIBUNWIND_USE_CET)
+#if defined(_LIBUNWIND_USE_CET) || defined(_LIBUNWIND_USE_GCS)
   virtual void *get_registers() {
 _LIBUNWIND_ABORT("get_registers not implemented");
   }
@@ -954,7 +954,7 @@ class UnwindCursor : public AbstractUnwindCursor{
   virtual uintptr_t getDataRelBase();
 #endif
 
-#if defined(_LIBUNWIND_USE_CET)
+#if defined(_LIBUNWIND_USE_CET) || defined(_LIBUNWIND_USE_GCS)
   virtual void *get_registers() { return &_registers; }
 #endif
 
@@ -3005,7 +3005,7 @@ bool UnwindCursor::isReadableAddr(const pint_t 
addr) const {
 }
 #endif
 
-#if defined(_LIBUNWIND_USE_CET)
+#if defined(_LIBUNWIND_USE_CET) || defined(_LIBUNWIND_USE_GCS)
 extern "C" void *__libunwind_cet_get_registers(unw_cursor_t *cursor) {
   AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor;
   return co->get_registers();

diff  --git a/libunwind/src/UnwindLevel1.c b/libunwind/src/UnwindLevel1.c
index 48e7bc3b9e00e..7e785f4d31e71 100644
--- a/libunwind/src/UnwindLevel1.c
+++ b/libunwind/src/UnwindLevel1.c
@@ -44,7 +44,7 @@
 // _LIBUNWIND_POP_CET_SSP is used to adjust CET shadow stack pointer and we
 // directly jump to __libunwind_Registers_x86/x86_64_jumpto instead of using
 // a regular function call to avoid pushing to CET shadow stack again.
-#if !defined(_LIBUNWIND_USE_CET)
+#if !defined(_LIBUNWIND_USE_CET) && !defined(_LIBUNWIND_USE_GCS)
 #define __unw_phase2_resume(cursor, fn)
\
   do {  

[libunwind] [libunwind] Add GCS support for AArch64 (PR #99335)

2024-08-04 Thread John Brawn via cfe-commits

https://github.com/john-brawn-arm closed 
https://github.com/llvm/llvm-project/pull/99335
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] [libunwind] Add GCS support for AArch64 (PR #99335)

2024-08-04 Thread John Brawn via cfe-commits

john-brawn-arm wrote:

> This seems to add a new feature, is it really relevant for a backport?

This is the last piece of work to enable GCS in the LLVM toolchain (clang and 
lld support went in a while ago), and I was hoping to get everything in to LLVM 
19. It would be rather annoying to have this last part slip to LLVM 20.

The way GCS works is that the `-mbranch-protection=standard` command-line 
option marks generated objects with the GCS property, and lld then sets the GCS 
property on the output if all inputs have it, which then indicates to the 
operating system to enable GCS on that process. Without GCS support in 
libunwind that means it won't have the GCS property so anything that links with 
libunwind will have GCS disabled.

Though having said all this, I marked this for LLVM 19 as my reading of 
https://discourse.llvm.org/t/update-on-llvm-19-x-releases/80511 was that new 
features are still ok before RC2, but re-reading it it's a bit ambiguous: it 
says "New features will have to wait until LLVM 20 at this point" and my 
reading of that was that "this point" means RC2, so new features before RC2 is 
fine, but if "this point" meant "right now" that means new features aren't OK. 
If that's the case the it's reasonable for this to not go in RC2.

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


[clang] [clang] concepts: perform parameter mapping substitution in correct context (PR #101745)

2024-08-04 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

I think this is simple enough that we could backport.

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


[libunwind] [libunwind] Add GCS support for AArch64 (PR #99335)

2024-08-04 Thread John Brawn via cfe-commits

john-brawn-arm wrote:

/cherry-pick b32aac4358c1f6639de7c453656cd74fbab75d71


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


[libunwind] [libunwind] Add GCS support for AArch64 (PR #99335)

2024-08-04 Thread via cfe-commits

llvmbot wrote:

/pull-request llvm/llvm-project#101888

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


[clang] [llvm] [X86][AVX10.2] Support YMM rounding new instructions (PR #101825)

2024-08-04 Thread Phoebe Wang via cfe-commits

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


[clang] [clang][Interp] Fix assignment operator call eval order (PR #101845)

2024-08-04 Thread Timm Baeder via cfe-commits

tbaederr wrote:

I have post-review powers for changes in `Interp/`.

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


[clang] [Clang][Sema][OpenMP] Allow `num_teams` to accept multiple expressions (PR #99732)

2024-08-04 Thread Johannes Doerfert via cfe-commits


@@ -11357,8 +11358,13 @@ void 
OMPClauseReader::VisitOMPAllocateClause(OMPAllocateClause *C) {
 
 void OMPClauseReader::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) {
   VisitOMPClauseWithPreInit(C);
-  C->setNumTeams(Record.readSubExpr());
   C->setLParenLoc(Record.readSourceLocation());
+  unsigned NumVars = C->varlist_size();
+  SmallVector Vars;
+  Vars.reserve(NumVars);
+  for ([[maybe_unused]] unsigned I : llvm::seq(NumVars))

jdoerfert wrote:

Does this work:
```
 for (auto _ : llvm::seq(NumVars))
```

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


[clang] [Clang][Sema][OpenMP] Allow `num_teams` to accept multiple expressions (PR #99732)

2024-08-04 Thread Johannes Doerfert via cfe-commits

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


[clang] [Clang][Sema][OpenMP] Allow `num_teams` to accept multiple expressions (PR #99732)

2024-08-04 Thread Johannes Doerfert via cfe-commits

https://github.com/jdoerfert commented:

I think this is almost ready. Only missing thing is the >3 argument check and 
test.

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


[clang] [Clang][Sema][OpenMP] Allow `num_teams` to accept multiple expressions (PR #99732)

2024-08-04 Thread Johannes Doerfert via cfe-commits


@@ -11639,6 +11639,7 @@ def warn_omp_unterminated_declare_target : Warning<
   InGroup;
 def err_ompx_bare_no_grid : Error<
   "'ompx_bare' clauses requires explicit grid size via 'num_teams' and 
'thread_limit' clauses">;
+def err_omp_multi_expr_not_allowed: Error<"only one expression allowed to '%0' 
clause">;

jdoerfert wrote:

```suggestion
def err_omp_multi_expr_not_allowed: Error<"only one expression allowed in '%0' 
clause">;
```

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


[clang] [Clang][Sema][OpenMP] Allow `num_teams` to accept multiple expressions (PR #99732)

2024-08-04 Thread Johannes Doerfert via cfe-commits


@@ -13004,13 +13004,34 @@ StmtResult 
SemaOpenMP::ActOnOpenMPTargetUpdateDirective(
   Clauses, AStmt);
 }
 
+// This checks whether num_teams clause only has one expression.
+static bool checkNumTeamsClauseSingleExpr(SemaBase &SemaRef,

jdoerfert wrote:

Pass the maximal number of expressions as a parameter since you also need to 
check the ompx_bare version has at most 3. The diagnosis message then needs to 
print the maximum, maybe also mention ompx_bare.

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


[clang] [clang] Construct SmallVector with ArrayRef (NFC) (PR #101898)

2024-08-04 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/101898

None

>From 55a8255278f68b66aa532d2923f7dc3ada28a340 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sun, 4 Aug 2024 10:19:51 -0700
Subject: [PATCH] [clang] Construct SmallVector with ArrayRef (NFC)

---
 clang/include/clang/AST/ASTConcept.h   |  5 ++---
 clang/include/clang/Index/DeclOccurrence.h |  3 +--
 clang/include/clang/Tooling/Refactoring/ASTSelection.h |  2 +-
 clang/lib/CodeGen/CodeGenFunction.h|  2 +-
 clang/lib/Format/AffectedRangeManager.h|  2 +-
 clang/lib/Format/TokenAnalyzer.cpp |  2 +-
 clang/lib/Format/UnwrappedLineParser.h |  2 +-
 clang/lib/Frontend/CreateInvocationFromCommandLine.cpp |  2 +-
 clang/lib/Frontend/DiagnosticRenderer.cpp  |  3 +--
 clang/lib/Lex/PPMacroExpansion.cpp |  2 +-
 clang/lib/Sema/SemaDecl.cpp|  2 +-
 clang/lib/Sema/SemaOpenMP.cpp  | 10 +++---
 clang/lib/Sema/SemaOverload.cpp|  2 +-
 clang/lib/Serialization/ASTWriter.cpp  |  2 +-
 clang/lib/Support/RISCVVIntrinsicUtils.cpp |  3 +--
 clang/unittests/Format/MacroCallReconstructorTest.cpp  |  6 ++
 clang/utils/TableGen/SveEmitter.cpp|  2 +-
 17 files changed, 21 insertions(+), 31 deletions(-)

diff --git a/clang/include/clang/AST/ASTConcept.h 
b/clang/include/clang/AST/ASTConcept.h
index 3c5fdf81d4b1e..00500e214f4ce 100644
--- a/clang/include/clang/AST/ASTConcept.h
+++ b/clang/include/clang/AST/ASTConcept.h
@@ -43,9 +43,8 @@ class ConstraintSatisfaction : public llvm::FoldingSetNode {
   ConstraintSatisfaction() = default;
 
   ConstraintSatisfaction(const NamedDecl *ConstraintOwner,
- ArrayRef TemplateArgs) :
-  ConstraintOwner(ConstraintOwner), TemplateArgs(TemplateArgs.begin(),
- TemplateArgs.end()) { }
+ ArrayRef TemplateArgs)
+  : ConstraintOwner(ConstraintOwner), TemplateArgs(TemplateArgs) {}
 
   using SubstitutionDiagnostic = std::pair;
   using Detail = llvm::PointerUnion;
diff --git a/clang/include/clang/Index/DeclOccurrence.h 
b/clang/include/clang/Index/DeclOccurrence.h
index 72f5799466bd4..9928ca243e8f2 100644
--- a/clang/include/clang/Index/DeclOccurrence.h
+++ b/clang/include/clang/Index/DeclOccurrence.h
@@ -29,8 +29,7 @@ struct DeclOccurrence {
 
   DeclOccurrence(SymbolRoleSet R, unsigned Offset, const Decl *D,
  ArrayRef Relations)
-  : Roles(R), Offset(Offset), DeclOrMacro(D),
-Relations(Relations.begin(), Relations.end()) {}
+  : Roles(R), Offset(Offset), DeclOrMacro(D), Relations(Relations) {}
   DeclOccurrence(SymbolRoleSet R, unsigned Offset, const IdentifierInfo *Name,
  const MacroInfo *MI)
   : Roles(R), Offset(Offset), DeclOrMacro(MI), MacroName(Name) {}
diff --git a/clang/include/clang/Tooling/Refactoring/ASTSelection.h 
b/clang/include/clang/Tooling/Refactoring/ASTSelection.h
index 009437fde03fc..ae778acb5e017 100644
--- a/clang/include/clang/Tooling/Refactoring/ASTSelection.h
+++ b/clang/include/clang/Tooling/Refactoring/ASTSelection.h
@@ -138,7 +138,7 @@ class CodeRangeASTSelection {
   CodeRangeASTSelection(SelectedASTNode::ReferenceType SelectedNode,
 ArrayRef Parents,
 bool AreChildrenSelected)
-  : SelectedNode(SelectedNode), Parents(Parents.begin(), Parents.end()),
+  : SelectedNode(SelectedNode), Parents(Parents),
 AreChildrenSelected(AreChildrenSelected) {}
 
   /// The reference to the selected node (or reference to the selected
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 6a5faa1e8f343..8b9c17a3f4a24 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -5309,7 +5309,7 @@ class CodeGenFunction : public CodeGenTypeCache {
   llvm::SmallVector Features;
 
   Conds(StringRef Arch, ArrayRef Feats)
-  : Architecture(Arch), Features(Feats.begin(), Feats.end()) {}
+  : Architecture(Arch), Features(Feats) {}
 } Conditions;
 
 MultiVersionResolverOption(llvm::Function *F, StringRef Arch,
diff --git a/clang/lib/Format/AffectedRangeManager.h 
b/clang/lib/Format/AffectedRangeManager.h
index 8cf39443fd415..add16bdd7a7c3 100644
--- a/clang/lib/Format/AffectedRangeManager.h
+++ b/clang/lib/Format/AffectedRangeManager.h
@@ -26,7 +26,7 @@ class AffectedRangeManager {
 public:
   AffectedRangeManager(const SourceManager &SourceMgr,
const ArrayRef Ranges)
-  : SourceMgr(SourceMgr), Ranges(Ranges.begin(), Ranges.end()) {}
+  : SourceMgr(SourceMgr), Ranges(Ranges) {}
 
   // Determines which lines are affected by the SourceRanges given as input.
   // Returns \c true if at le

[clang] [clang] Construct SmallVector with ArrayRef (NFC) (PR #101898)

2024-08-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes



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


17 Files Affected:

- (modified) clang/include/clang/AST/ASTConcept.h (+2-3) 
- (modified) clang/include/clang/Index/DeclOccurrence.h (+1-2) 
- (modified) clang/include/clang/Tooling/Refactoring/ASTSelection.h (+1-1) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+1-1) 
- (modified) clang/lib/Format/AffectedRangeManager.h (+1-1) 
- (modified) clang/lib/Format/TokenAnalyzer.cpp (+1-1) 
- (modified) clang/lib/Format/UnwrappedLineParser.h (+1-1) 
- (modified) clang/lib/Frontend/CreateInvocationFromCommandLine.cpp (+1-1) 
- (modified) clang/lib/Frontend/DiagnosticRenderer.cpp (+1-2) 
- (modified) clang/lib/Lex/PPMacroExpansion.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+3-7) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+1-1) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+1-1) 
- (modified) clang/lib/Support/RISCVVIntrinsicUtils.cpp (+1-2) 
- (modified) clang/unittests/Format/MacroCallReconstructorTest.cpp (+2-4) 
- (modified) clang/utils/TableGen/SveEmitter.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/AST/ASTConcept.h 
b/clang/include/clang/AST/ASTConcept.h
index 3c5fdf81d4b1e..00500e214f4ce 100644
--- a/clang/include/clang/AST/ASTConcept.h
+++ b/clang/include/clang/AST/ASTConcept.h
@@ -43,9 +43,8 @@ class ConstraintSatisfaction : public llvm::FoldingSetNode {
   ConstraintSatisfaction() = default;
 
   ConstraintSatisfaction(const NamedDecl *ConstraintOwner,
- ArrayRef TemplateArgs) :
-  ConstraintOwner(ConstraintOwner), TemplateArgs(TemplateArgs.begin(),
- TemplateArgs.end()) { }
+ ArrayRef TemplateArgs)
+  : ConstraintOwner(ConstraintOwner), TemplateArgs(TemplateArgs) {}
 
   using SubstitutionDiagnostic = std::pair;
   using Detail = llvm::PointerUnion;
diff --git a/clang/include/clang/Index/DeclOccurrence.h 
b/clang/include/clang/Index/DeclOccurrence.h
index 72f5799466bd4..9928ca243e8f2 100644
--- a/clang/include/clang/Index/DeclOccurrence.h
+++ b/clang/include/clang/Index/DeclOccurrence.h
@@ -29,8 +29,7 @@ struct DeclOccurrence {
 
   DeclOccurrence(SymbolRoleSet R, unsigned Offset, const Decl *D,
  ArrayRef Relations)
-  : Roles(R), Offset(Offset), DeclOrMacro(D),
-Relations(Relations.begin(), Relations.end()) {}
+  : Roles(R), Offset(Offset), DeclOrMacro(D), Relations(Relations) {}
   DeclOccurrence(SymbolRoleSet R, unsigned Offset, const IdentifierInfo *Name,
  const MacroInfo *MI)
   : Roles(R), Offset(Offset), DeclOrMacro(MI), MacroName(Name) {}
diff --git a/clang/include/clang/Tooling/Refactoring/ASTSelection.h 
b/clang/include/clang/Tooling/Refactoring/ASTSelection.h
index 009437fde03fc..ae778acb5e017 100644
--- a/clang/include/clang/Tooling/Refactoring/ASTSelection.h
+++ b/clang/include/clang/Tooling/Refactoring/ASTSelection.h
@@ -138,7 +138,7 @@ class CodeRangeASTSelection {
   CodeRangeASTSelection(SelectedASTNode::ReferenceType SelectedNode,
 ArrayRef Parents,
 bool AreChildrenSelected)
-  : SelectedNode(SelectedNode), Parents(Parents.begin(), Parents.end()),
+  : SelectedNode(SelectedNode), Parents(Parents),
 AreChildrenSelected(AreChildrenSelected) {}
 
   /// The reference to the selected node (or reference to the selected
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 6a5faa1e8f343..8b9c17a3f4a24 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -5309,7 +5309,7 @@ class CodeGenFunction : public CodeGenTypeCache {
   llvm::SmallVector Features;
 
   Conds(StringRef Arch, ArrayRef Feats)
-  : Architecture(Arch), Features(Feats.begin(), Feats.end()) {}
+  : Architecture(Arch), Features(Feats) {}
 } Conditions;
 
 MultiVersionResolverOption(llvm::Function *F, StringRef Arch,
diff --git a/clang/lib/Format/AffectedRangeManager.h 
b/clang/lib/Format/AffectedRangeManager.h
index 8cf39443fd415..add16bdd7a7c3 100644
--- a/clang/lib/Format/AffectedRangeManager.h
+++ b/clang/lib/Format/AffectedRangeManager.h
@@ -26,7 +26,7 @@ class AffectedRangeManager {
 public:
   AffectedRangeManager(const SourceManager &SourceMgr,
const ArrayRef Ranges)
-  : SourceMgr(SourceMgr), Ranges(Ranges.begin(), Ranges.end()) {}
+  : SourceMgr(SourceMgr), Ranges(Ranges) {}
 
   // Determines which lines are affected by the SourceRanges given as input.
   // Returns \c true if at least one line in \p Lines or one of their
diff --git a/clang/lib/Format/TokenAnalyzer.cpp 
b/clang/lib/Format/TokenAnalyzer.cpp
index 804a2b0f5e8c1..207442fe0c2c0 100644
--- a/clang/lib/Format/TokenAnalyzer.cpp
+++ b/cla

[clang] [clang] Construct SmallVector with ArrayRef (NFC) (PR #101898)

2024-08-04 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-codegen
@llvm/pr-subscribers-clang-modules

@llvm/pr-subscribers-clang-format

Author: Kazu Hirata (kazutakahirata)


Changes



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


17 Files Affected:

- (modified) clang/include/clang/AST/ASTConcept.h (+2-3) 
- (modified) clang/include/clang/Index/DeclOccurrence.h (+1-2) 
- (modified) clang/include/clang/Tooling/Refactoring/ASTSelection.h (+1-1) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+1-1) 
- (modified) clang/lib/Format/AffectedRangeManager.h (+1-1) 
- (modified) clang/lib/Format/TokenAnalyzer.cpp (+1-1) 
- (modified) clang/lib/Format/UnwrappedLineParser.h (+1-1) 
- (modified) clang/lib/Frontend/CreateInvocationFromCommandLine.cpp (+1-1) 
- (modified) clang/lib/Frontend/DiagnosticRenderer.cpp (+1-2) 
- (modified) clang/lib/Lex/PPMacroExpansion.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+3-7) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+1-1) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+1-1) 
- (modified) clang/lib/Support/RISCVVIntrinsicUtils.cpp (+1-2) 
- (modified) clang/unittests/Format/MacroCallReconstructorTest.cpp (+2-4) 
- (modified) clang/utils/TableGen/SveEmitter.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/AST/ASTConcept.h 
b/clang/include/clang/AST/ASTConcept.h
index 3c5fdf81d4b1e..00500e214f4ce 100644
--- a/clang/include/clang/AST/ASTConcept.h
+++ b/clang/include/clang/AST/ASTConcept.h
@@ -43,9 +43,8 @@ class ConstraintSatisfaction : public llvm::FoldingSetNode {
   ConstraintSatisfaction() = default;
 
   ConstraintSatisfaction(const NamedDecl *ConstraintOwner,
- ArrayRef TemplateArgs) :
-  ConstraintOwner(ConstraintOwner), TemplateArgs(TemplateArgs.begin(),
- TemplateArgs.end()) { }
+ ArrayRef TemplateArgs)
+  : ConstraintOwner(ConstraintOwner), TemplateArgs(TemplateArgs) {}
 
   using SubstitutionDiagnostic = std::pair;
   using Detail = llvm::PointerUnion;
diff --git a/clang/include/clang/Index/DeclOccurrence.h 
b/clang/include/clang/Index/DeclOccurrence.h
index 72f5799466bd4..9928ca243e8f2 100644
--- a/clang/include/clang/Index/DeclOccurrence.h
+++ b/clang/include/clang/Index/DeclOccurrence.h
@@ -29,8 +29,7 @@ struct DeclOccurrence {
 
   DeclOccurrence(SymbolRoleSet R, unsigned Offset, const Decl *D,
  ArrayRef Relations)
-  : Roles(R), Offset(Offset), DeclOrMacro(D),
-Relations(Relations.begin(), Relations.end()) {}
+  : Roles(R), Offset(Offset), DeclOrMacro(D), Relations(Relations) {}
   DeclOccurrence(SymbolRoleSet R, unsigned Offset, const IdentifierInfo *Name,
  const MacroInfo *MI)
   : Roles(R), Offset(Offset), DeclOrMacro(MI), MacroName(Name) {}
diff --git a/clang/include/clang/Tooling/Refactoring/ASTSelection.h 
b/clang/include/clang/Tooling/Refactoring/ASTSelection.h
index 009437fde03fc..ae778acb5e017 100644
--- a/clang/include/clang/Tooling/Refactoring/ASTSelection.h
+++ b/clang/include/clang/Tooling/Refactoring/ASTSelection.h
@@ -138,7 +138,7 @@ class CodeRangeASTSelection {
   CodeRangeASTSelection(SelectedASTNode::ReferenceType SelectedNode,
 ArrayRef Parents,
 bool AreChildrenSelected)
-  : SelectedNode(SelectedNode), Parents(Parents.begin(), Parents.end()),
+  : SelectedNode(SelectedNode), Parents(Parents),
 AreChildrenSelected(AreChildrenSelected) {}
 
   /// The reference to the selected node (or reference to the selected
diff --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 6a5faa1e8f343..8b9c17a3f4a24 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -5309,7 +5309,7 @@ class CodeGenFunction : public CodeGenTypeCache {
   llvm::SmallVector Features;
 
   Conds(StringRef Arch, ArrayRef Feats)
-  : Architecture(Arch), Features(Feats.begin(), Feats.end()) {}
+  : Architecture(Arch), Features(Feats) {}
 } Conditions;
 
 MultiVersionResolverOption(llvm::Function *F, StringRef Arch,
diff --git a/clang/lib/Format/AffectedRangeManager.h 
b/clang/lib/Format/AffectedRangeManager.h
index 8cf39443fd415..add16bdd7a7c3 100644
--- a/clang/lib/Format/AffectedRangeManager.h
+++ b/clang/lib/Format/AffectedRangeManager.h
@@ -26,7 +26,7 @@ class AffectedRangeManager {
 public:
   AffectedRangeManager(const SourceManager &SourceMgr,
const ArrayRef Ranges)
-  : SourceMgr(SourceMgr), Ranges(Ranges.begin(), Ranges.end()) {}
+  : SourceMgr(SourceMgr), Ranges(Ranges) {}
 
   // Determines which lines are affected by the SourceRanges given as input.
   // Returns \c true if at least one line in \p Lines or one of their
diff --git a/clang/lib/Format/TokenAnalyzer.cpp 
b/clang/lib/Format/TokenAnalyzer.cpp
index 804a2b0f5

[clang] [RISCV] Allow YAML file to control multilib selection (PR #98856)

2024-08-04 Thread Sam Elliott via cfe-commits


@@ -258,6 +259,13 @@ static void getARMMultilibFlags(const Driver &D,
   }
 }
 
+static void getRISCVMultilibFlags(const Driver &D, const llvm::Triple &Triple,
+  const llvm::opt::ArgList &Args,
+  Multilib::flags_list &Result) {
+  Result.push_back("-march=" + riscv::getRISCVArch(Args, Triple));

lenary wrote:

the discourse thread also contains suggestions about splitting up each 
extension into a different flag - I'm not opposed to an approach like that 
either, and it might make creating a multilib config which matches the existing 
behaviour a lot easier.

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


[clang] [clang-format] Add PackParameters enum option to replace BinPackParameters. (PR #101882)

2024-08-04 Thread Björn Schäpers via cfe-commits


@@ -1918,11 +1901,12 @@ void 
ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
 // for backwards compatibility.
 bool ObjCBinPackProtocolList =
 (Style.ObjCBinPackProtocolList == FormatStyle::BPS_Auto &&
- Style.BinPackParameters) ||
+ (Style.PackParameters == FormatStyle::PPS_BinPack)) ||

HazardyKnusperkeks wrote:

```suggestion
 Style.PackParameters == FormatStyle::PPS_BinPack) ||
```

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


[clang] [clang-format] Add PackParameters enum option to replace BinPackParameters. (PR #101882)

2024-08-04 Thread Björn Schäpers via cfe-commits


@@ -1918,11 +1901,12 @@ void 
ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
 // for backwards compatibility.
 bool ObjCBinPackProtocolList =
 (Style.ObjCBinPackProtocolList == FormatStyle::BPS_Auto &&
- Style.BinPackParameters) ||
+ (Style.PackParameters == FormatStyle::PPS_BinPack)) ||
 Style.ObjCBinPackProtocolList == FormatStyle::BPS_Always;
 
 bool BinPackDeclaration =
-(State.Line->Type != LT_ObjCDecl && Style.BinPackParameters) ||
+(State.Line->Type != LT_ObjCDecl &&
+ (Style.PackParameters == FormatStyle::PPS_BinPack)) ||

HazardyKnusperkeks wrote:

```suggestion
 Style.PackParameters == FormatStyle::PPS_BinPack) ||
```

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


[clang] [clang-format] Add PackParameters enum option to replace BinPackParameters. (PR #101882)

2024-08-04 Thread Björn Schäpers via cfe-commits


@@ -1174,6 +1192,18 @@ template <> struct MappingTraits {
 Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
 }
 
+// If BinPackParameters was specified but PackParameters was not, 
initialize
+// the latter from the former for backwards compatibility.
+if (IsChromiumOrMozilla) {
+  if (BinPackParameters &&
+  (Style.PackParameters == FormatStyle::PPS_CurrentLine)) {

HazardyKnusperkeks wrote:

```suggestion
  Style.PackParameters == FormatStyle::PPS_CurrentLine) {
```

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


[clang] [clang-format] Add PackParameters enum option to replace BinPackParameters. (PR #101882)

2024-08-04 Thread Björn Schäpers via cfe-commits


@@ -5458,6 +5458,14 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine 
&Line,
 return true;
   }
 
+  // Ignores the first parameter as this will be handled separately by
+  // BreakFunctionDefinitionParameters or AlignAfterOpenBracket.
+  if ((FormatStyle::PPS_BreakAlways == Style.PackParameters) &&

HazardyKnusperkeks wrote:

```suggestion
  if (FormatStyle::PPS_BreakAlways == Style.PackParameters &&
```

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


[clang] [clang-format] Add PackParameters enum option to replace BinPackParameters. (PR #101882)

2024-08-04 Thread Björn Schäpers via cfe-commits


@@ -456,6 +455,21 @@ TEST(ConfigParseTest, ParsesConfiguration) {
   "AllowAllConstructorInitializersOnNextLine: false",
   PackConstructorInitializers, FormatStyle::PCIS_CurrentLine);
 
+  Style.PackParameters = FormatStyle::PPS_BinPack;
+  CHECK_PARSE("PackParameters: CurrentLine", PackParameters,
+  FormatStyle::PPS_CurrentLine);
+  CHECK_PARSE("PackParameters: BinPack", PackParameters,
+  FormatStyle::PPS_BinPack);
+  CHECK_PARSE("PackParameters: BreakAlways", PackParameters,
+  FormatStyle::PPS_BreakAlways);
+  // For backward compatibility

HazardyKnusperkeks wrote:

```suggestion
  // For backward compatibility.
```

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


[clang] [clang-format] Add PackParameters enum option to replace BinPackParameters. (PR #101882)

2024-08-04 Thread Björn Schäpers via cfe-commits


@@ -1174,6 +1192,18 @@ template <> struct MappingTraits {
 Style.PackConstructorInitializers = FormatStyle::PCIS_CurrentLine;
 }
 
+// If BinPackParameters was specified but PackParameters was not, 
initialize
+// the latter from the former for backwards compatibility.
+if (IsChromiumOrMozilla) {
+  if (BinPackParameters &&
+  (Style.PackParameters == FormatStyle::PPS_CurrentLine)) {
+Style.PackParameters = FormatStyle::PPS_BinPack;
+  }
+} else if (!BinPackParameters &&
+   (Style.PackParameters == FormatStyle::PPS_BinPack)) {

HazardyKnusperkeks wrote:

```suggestion
   Style.PackParameters == FormatStyle::PPS_BinPack) {
```

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


[clang] [clang-format] Add PackParameters enum option to replace BinPackParameters. (PR #101882)

2024-08-04 Thread Björn Schäpers via cfe-commits


@@ -411,7 +393,8 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
 // sets BreakBeforeParameter to avoid bin packing and this creates a
 // completely unnecessary line break after a template type that isn't
 // line-wrapped.
-(Previous.NestingLevel == 1 || Style.BinPackParameters)) ||
+(Previous.NestingLevel == 1 ||
+ (Style.PackParameters == FormatStyle::PPS_BinPack))) ||

HazardyKnusperkeks wrote:

```suggestion
(Style.PackParameters == FormatStyle::PPS_BinPack)) ||
```

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


[clang] [clang][Interp] reinterpret casts aren't always fatal (PR #101900)

2024-08-04 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/101900

The current interpreter emits the diagnostic and continues, so do the same.

>From c10fedb826c41c2f640814428d996b8bfd3f2867 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 4 Aug 2024 19:50:39 +0200
Subject: [PATCH] [clang][Interp] reinterpret casts aren't always fatal

The current interpreter emits the diagnostic and continues, so do the
same.
---
 clang/lib/AST/Interp/Compiler.cpp |  9 ++---
 clang/lib/AST/Interp/Interp.h |  9 ++---
 clang/lib/AST/Interp/Opcodes.td   |  2 +-
 clang/test/AST/Interp/codegen.cpp | 13 +
 4 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index bd2b0f74b34c5..129f4cf22 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -426,7 +426,7 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
 if (CE->getType()->isAtomicType()) {
   if (!this->discard(SubExpr))
 return false;
-  return this->emitInvalidCast(CastKind::Reinterpret, CE);
+  return this->emitInvalidCast(CastKind::Reinterpret, /*Fatal=*/true, CE);
 }
 
 if (DiscardResult)
@@ -2465,10 +2465,13 @@ bool Compiler::VisitCXXThrowExpr(const 
CXXThrowExpr *E) {
 template 
 bool Compiler::VisitCXXReinterpretCastExpr(
 const CXXReinterpretCastExpr *E) {
-  if (!this->discard(E->getSubExpr()))
+  const Expr *SubExpr = E->getSubExpr();
+
+  bool TypesMatch = classify(E) == classify(SubExpr);
+  if (!this->emitInvalidCast(CastKind::Reinterpret, /*Fatal=*/!TypesMatch, E))
 return false;
 
-  return this->emitInvalidCast(CastKind::Reinterpret, E);
+  return this->delegate(SubExpr);
 }
 
 template 
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index a3f81e2de466b..04f88efdc0acf 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -2787,13 +2787,16 @@ inline bool Unsupported(InterpState &S, CodePtr OpPC) {
 inline bool Error(InterpState &S, CodePtr OpPC) { return false; }
 
 /// Same here, but only for casts.
-inline bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind) {
+inline bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind,
+bool Fatal) {
   const SourceLocation &Loc = S.Current->getLocation(OpPC);
 
   // FIXME: Support diagnosing other invalid cast kinds.
-  if (Kind == CastKind::Reinterpret)
-S.FFDiag(Loc, diag::note_constexpr_invalid_cast)
+  if (Kind == CastKind::Reinterpret) {
+S.CCEDiag(Loc, diag::note_constexpr_invalid_cast)
 << static_cast(Kind) << S.Current->getRange(OpPC);
+return !Fatal;
+  }
   return false;
 }
 
diff --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index 70d06bdfdc21c..220dff0c556b1 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -739,7 +739,7 @@ def Invalid : Opcode {}
 def Unsupported : Opcode {}
 def Error : Opcode {}
 def InvalidCast : Opcode {
-  let Args = [ArgCastKind];
+  let Args = [ArgCastKind, ArgBool];
 }
 
 def InvalidDeclRef : Opcode {
diff --git a/clang/test/AST/Interp/codegen.cpp 
b/clang/test/AST/Interp/codegen.cpp
index a5583d953d234..f1f0a33673a5b 100644
--- a/clang/test/AST/Interp/codegen.cpp
+++ b/clang/test/AST/Interp/codegen.cpp
@@ -31,3 +31,16 @@ namespace BaseClassOffsets {
   // CHECK: @_ZN16BaseClassOffsets1bE = global ptr getelementptr (i8, ptr 
@_ZN16BaseClassOffsets1cE, i64 4), align 8
   B* b = &c;
 }
+
+namespace reinterpretcast {
+  const unsigned int n = 1234;
+  extern const int &s = reinterpret_cast(n);
+  // CHECK: @_ZN15reinterpretcastL1nE = internal constant i32 1234, align 4
+  // CHECK: @_ZN15reinterpretcast1sE = constant ptr @_ZN15reinterpretcastL1nE, 
align 8
+
+  void *f1(unsigned long l) {
+return reinterpret_cast(l);
+  }
+  // CHECK: define {{.*}} ptr @_ZN15reinterpretcast2f1Em
+  // CHECK: inttoptr
+}

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


[clang] [clang][Interp] reinterpret casts aren't always fatal (PR #101900)

2024-08-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

The current interpreter emits the diagnostic and continues, so do the same.

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


4 Files Affected:

- (modified) clang/lib/AST/Interp/Compiler.cpp (+6-3) 
- (modified) clang/lib/AST/Interp/Interp.h (+6-3) 
- (modified) clang/lib/AST/Interp/Opcodes.td (+1-1) 
- (modified) clang/test/AST/Interp/codegen.cpp (+13) 


``diff
diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index bd2b0f74b34c5..129f4cf22 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -426,7 +426,7 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
 if (CE->getType()->isAtomicType()) {
   if (!this->discard(SubExpr))
 return false;
-  return this->emitInvalidCast(CastKind::Reinterpret, CE);
+  return this->emitInvalidCast(CastKind::Reinterpret, /*Fatal=*/true, CE);
 }
 
 if (DiscardResult)
@@ -2465,10 +2465,13 @@ bool Compiler::VisitCXXThrowExpr(const 
CXXThrowExpr *E) {
 template 
 bool Compiler::VisitCXXReinterpretCastExpr(
 const CXXReinterpretCastExpr *E) {
-  if (!this->discard(E->getSubExpr()))
+  const Expr *SubExpr = E->getSubExpr();
+
+  bool TypesMatch = classify(E) == classify(SubExpr);
+  if (!this->emitInvalidCast(CastKind::Reinterpret, /*Fatal=*/!TypesMatch, E))
 return false;
 
-  return this->emitInvalidCast(CastKind::Reinterpret, E);
+  return this->delegate(SubExpr);
 }
 
 template 
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index a3f81e2de466b..04f88efdc0acf 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -2787,13 +2787,16 @@ inline bool Unsupported(InterpState &S, CodePtr OpPC) {
 inline bool Error(InterpState &S, CodePtr OpPC) { return false; }
 
 /// Same here, but only for casts.
-inline bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind) {
+inline bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind,
+bool Fatal) {
   const SourceLocation &Loc = S.Current->getLocation(OpPC);
 
   // FIXME: Support diagnosing other invalid cast kinds.
-  if (Kind == CastKind::Reinterpret)
-S.FFDiag(Loc, diag::note_constexpr_invalid_cast)
+  if (Kind == CastKind::Reinterpret) {
+S.CCEDiag(Loc, diag::note_constexpr_invalid_cast)
 << static_cast(Kind) << S.Current->getRange(OpPC);
+return !Fatal;
+  }
   return false;
 }
 
diff --git a/clang/lib/AST/Interp/Opcodes.td b/clang/lib/AST/Interp/Opcodes.td
index 70d06bdfdc21c..220dff0c556b1 100644
--- a/clang/lib/AST/Interp/Opcodes.td
+++ b/clang/lib/AST/Interp/Opcodes.td
@@ -739,7 +739,7 @@ def Invalid : Opcode {}
 def Unsupported : Opcode {}
 def Error : Opcode {}
 def InvalidCast : Opcode {
-  let Args = [ArgCastKind];
+  let Args = [ArgCastKind, ArgBool];
 }
 
 def InvalidDeclRef : Opcode {
diff --git a/clang/test/AST/Interp/codegen.cpp 
b/clang/test/AST/Interp/codegen.cpp
index a5583d953d234..f1f0a33673a5b 100644
--- a/clang/test/AST/Interp/codegen.cpp
+++ b/clang/test/AST/Interp/codegen.cpp
@@ -31,3 +31,16 @@ namespace BaseClassOffsets {
   // CHECK: @_ZN16BaseClassOffsets1bE = global ptr getelementptr (i8, ptr 
@_ZN16BaseClassOffsets1cE, i64 4), align 8
   B* b = &c;
 }
+
+namespace reinterpretcast {
+  const unsigned int n = 1234;
+  extern const int &s = reinterpret_cast(n);
+  // CHECK: @_ZN15reinterpretcastL1nE = internal constant i32 1234, align 4
+  // CHECK: @_ZN15reinterpretcast1sE = constant ptr @_ZN15reinterpretcastL1nE, 
align 8
+
+  void *f1(unsigned long l) {
+return reinterpret_cast(l);
+  }
+  // CHECK: define {{.*}} ptr @_ZN15reinterpretcast2f1Em
+  // CHECK: inttoptr
+}

``




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


[libunwind] [libunwind] Add GCS support for AArch64 (PR #99335)

2024-08-04 Thread Nico Weber via cfe-commits

nico wrote:

Looks like this breaks building on Android: 
https://ci.chromium.org/ui/p/chromium/builders/try/android-arm64-rel/680348/overview

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


[clang] [llvm] Partialmaptype (PR #101903)

2024-08-04 Thread via cfe-commits

https://github.com/jyu2-git created 
https://github.com/llvm/llvm-project/pull/101903

None

>From 1a1cb6b459688a7e0a7f22c2b4a32dbe8cae77cc Mon Sep 17 00:00:00 2001
From: Jennifer Yu 
Date: Fri, 2 Aug 2024 17:41:24 -0700
Subject: [PATCH 1/2] Test faild with amd.

Add unspport.

This is relate #101101
---
 .../test/mapping/declare_mapper_nested_default_mappers_1.cpp| 2 ++
 1 file changed, 2 insertions(+)

diff --git a/offload/test/mapping/declare_mapper_nested_default_mappers_1.cpp 
b/offload/test/mapping/declare_mapper_nested_default_mappers_1.cpp
index 1658ce5f6070e..e300ae4524749 100644
--- a/offload/test/mapping/declare_mapper_nested_default_mappers_1.cpp
+++ b/offload/test/mapping/declare_mapper_nested_default_mappers_1.cpp
@@ -1,5 +1,7 @@
 // RUN: %libomptarget-compilexx-run-and-check-generic
 
+// UNSUPPORTED: amdgcn-amd-amdhsa
+
 extern "C" int printf(const char *, ...);
 
 typedef struct {

>From 6ed9ae59805d0b9118d10347e8c4ddb92cf23c2c Mon Sep 17 00:00:00 2001
From: Jennifer Yu 
Date: Sun, 4 Aug 2024 10:53:29 -0700
Subject: [PATCH 2/2] [OpenMP][Map][NFC] improve map chain.

This is for mapping structure has data members, which have 'default'
mappers, where needs to map these members individually using
their 'default' mappers.

example map(tofrom: spp[0][0]), look at test case.

currently create 6 maps:
1>&spp, &spp[0],  size 8, maptype TARGET_PARAM | FROM | TO
2>&spp[0], &spp[0][0], size(D)with maptype OMP_MAP_NONE, nullptr
3>&spp[0], &spp[0][0].e, size(e) with maptype MEMBER_OF  | FROM  | TO
4>&spp[0], &spp[0][0].h, size(h) with maptype MEMBER_OF  | FROM  | TO
5>&spp, &spp[0],size(8), maptype MEMBER_OF | IMPLICIT | FROM  | TO
6>&spp[0], &spp[0][0].f size(D) with maptype MEMBER_OF |IMPLICIT |PTR_AND_OBJ, 
@.omp_mapper._ZTS1C.default

maptype with/without OMP_MAP_PTR_AND_OBJ
   For "2" and "5", since it is mapping pointer and pointee pair,
   PTR_AND_OBJ should be set
   But for "6" the PTR_AND_OBJ should not set.
However, "5" is duplicate with "1" can be skip.

To fix "2", during the call to emitCombinEntry with false with NotTargetParams
instead !PartialStruct.PreliminaryMapData.BasePointers.empty(), since
all captures need to be TARGET_PARAM
And inside emitCombineEntry:  check
 !PartialStruct.PreliminaryMapData.BasePointers.empty() to set PTR_AND_OBJ

For "5" and "6": the fix in generateInfoForComponentList:
Add new variable IsPartialMapped set with
!PartialStruct.PreliminaryMapData.BasePointers.empty();

When that is true, skip generate "5" and don"t set IsExpressionFirstInfo
to false,  so that PTR_AND_OBJ would be set.

After fix: will have 5 maps instead 6
1>&spp, &spp[0],  size 8, maptype TARGET_PARAM | FROM | TO
2>&spp[0], &spp[0][0], size(D), maptype PTR_AND_OBJ, nullptr
3>&spp[0], &spp[0][0].e, size(e), maptype MEMBER_OF_2  | FROM  | TO
4>&spp[0], &spp[0][0].h, size(h), maptype MEMBER_OF_2  | FROM  | TO
5>&spp[0], &spp[0][0].f size(32), maptype MEMBER_OF_2 | IMPLICIT, 
@.omp_mapper._ZTS1C.default

For map(sppp[0][0][0]):
after fix: will have 6 maps intead 8.
---
 clang/lib/CodeGen/CGOpenMPRuntime.cpp | 22 +---
 ...get_map_pointer_defalut_mapper_codegen.cpp | 50 +++
 2 files changed, 64 insertions(+), 8 deletions(-)
 create mode 100644 
clang/test/OpenMP/target_map_pointer_defalut_mapper_codegen.cpp

diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index d869aa3322cce..de04b7997ca37 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7125,6 +7125,9 @@ class MappableExprsHandler {
 bool IsNonContiguous = CombinedInfo.NonContigInfo.IsNonContiguous;
 bool IsPrevMemberReference = false;
 
+bool IsPartialMapped =
+!PartialStruct.PreliminaryMapData.BasePointers.empty();
+
 // We need to check if we will be encountering any MEs. If we do not
 // encounter any ME expression it means we will be mapping the whole 
struct.
 // In that case we need to skip adding an entry for the struct to the
@@ -7370,7 +7373,9 @@ class MappableExprsHandler {
 // whole struct is currently being mapped. The struct needs to be added
 // in the first position before any data internal to the struct is 
being
 // mapped.
-if (!IsMemberPointerOrAddr ||
+// Skip adding an entry in the CurInfo of this combined entry if the
+// PartialStruct.PreliminaryMapData.BasePointers has been mapped.
+if ((!IsMemberPointerOrAddr && !IsPartialMapped) ||
 (Next == CE && MapType != OMPC_MAP_unknown)) {
   if (!IsMappingWholeStruct) {
 CombinedInfo.Exprs.emplace_back(MapDecl, MapExpr);
@@ -7486,8 +7491,8 @@ class MappableExprsHandler {
 // The pointer becomes the base for the next element.
 if (Next != CE)
   BP = IsMemberReference ? LowestElem : LB;
-
-IsExpressionFirstInfo = false;
+if (!IsPartialMapped)
+  IsExpressionFirstInfo = false;
 IsCapt

[clang] [clang-format] Add PackParameters enum option to replace BinPackParameters. (PR #101882)

2024-08-04 Thread via cfe-commits

https://github.com/VolatileAcorn updated 
https://github.com/llvm/llvm-project/pull/101882

>From 923a4ef21edf87c004d8940202331f204e8a8d83 Mon Sep 17 00:00:00 2001
From: Tom Pottage 
Date: Fri, 2 Aug 2024 20:26:47 +0100
Subject: [PATCH] [clang-format] Add PackParameters option to replace
 BinPackParameters. The PackParameters option now provides the new BreakAlways
 setting

---
 clang/docs/ClangFormatStyleOptions.rst|  52 --
 clang/include/clang/Format/Format.h   |  48 --
 clang/lib/Format/ContinuationIndenter.cpp |  26 +--
 clang/lib/Format/Format.cpp   |  38 -
 clang/lib/Format/FormatToken.h|  18 +++
 clang/lib/Format/TokenAnnotator.cpp   |   8 +
 clang/unittests/Format/ConfigParseTest.cpp|  16 +-
 clang/unittests/Format/FormatTest.cpp | 153 +++---
 clang/unittests/Format/FormatTestComments.cpp |   4 +-
 clang/unittests/Format/FormatTestObjC.cpp |   2 +-
 10 files changed, 289 insertions(+), 76 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 6c2e6da594847..510b956968dc6 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2068,19 +2068,7 @@ the configuration (without a prefix: ``Auto``).
 .. _BinPackParameters:
 
 **BinPackParameters** (``Boolean``) :versionbadge:`clang-format 3.7` :ref:`¶ 
`
-  If ``false``, a function declaration's or function definition's
-  parameters will either all be on the same line or will have one line each.
-
-  .. code-block:: c++
-
-true:
-void f(int , int ,
-   int aaa) {}
-
-false:
-void f(int ,
-   int ,
-   int aaa) {}
+  This option is **deprecated**. See ``PackParameters``.
 
 .. _BitFieldColonSpacing:
 
@@ -4984,6 +4972,44 @@ the configuration (without a prefix: ``Auto``).
 
 
 
+.. _PackParameters:
+
+**PackParameters** (``PackParametersStyle``) :versionbadge:`clang-format 20` 
:ref:`¶ `
+  The pack parameters style to use.
+
+  Possible values:
+
+  * ``PPS_CurrentLine`` (in configuration: ``CurrentLine``)
+Put all parameters on the current line if they fit.
+Otherwise, put each one on its own line.
+
+.. code-block:: c++
+
+   void f(int a, int b, int c);
+
+   void f(int a,
+  int b,
+  int c);
+
+  * ``PPS_BinPack`` (in configuration: ``BinPack``)
+Bin-pack parameters.
+
+.. code-block:: c++
+
+   void f(int a, int ,
+  int ccc);
+
+  * ``PPS_BreakAlways`` (in configuration: ``BreakAlways``)
+Always put each parameter on its own line.
+
+.. code-block:: c++
+
+   void f(int a,
+  int b,
+  int c);
+
+
+
 .. _PenaltyBreakAssignment:
 
 **PenaltyBreakAssignment** (``Unsigned``) :versionbadge:`clang-format 5` 
:ref:`¶ `
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index c454ab2bc0ce2..2991ab18f980d 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1192,20 +1192,9 @@ struct FormatStyle {
   /// \version 3.7
   bool BinPackArguments;
 
-  /// If ``false``, a function declaration's or function definition's
-  /// parameters will either all be on the same line or will have one line 
each.
-  /// \code
-  ///   true:
-  ///   void f(int , int ,
-  ///  int aaa) {}
-  ///
-  ///   false:
-  ///   void f(int ,
-  ///  int ,
-  ///  int aaa) {}
-  /// \endcode
+  /// This option is **deprecated**. See ``PackParameters``.
   /// \version 3.7
-  bool BinPackParameters;
+  // bool BinPackParameters;
 
   /// Styles for adding spacing around ``:`` in bitfield definitions.
   enum BitFieldColonSpacingStyle : int8_t {
@@ -3537,6 +3526,37 @@ struct FormatStyle {
   /// \version 14
   PackConstructorInitializersStyle PackConstructorInitializers;
 
+  /// Different way to try to fit all parameters on a line.
+  enum PackParametersStyle : int8_t {
+/// Put all parameters on the current line if they fit.
+/// Otherwise, put each one on its own line.
+/// \code
+///void f(int a, int b, int c);
+///
+///void f(int a,
+///   int b,
+///   int c);
+/// \endcode
+PPS_CurrentLine,
+/// Bin-pack parameters.
+/// \code
+///void f(int a, int ,
+///   int ccc);
+/// \endcode
+PPS_BinPack,
+/// Al

[clang] [Clang][Sema][OpenMP] Allow `num_teams` to accept multiple expressions (PR #99732)

2024-08-04 Thread Shilei Tian via cfe-commits


@@ -11357,8 +11358,13 @@ void 
OMPClauseReader::VisitOMPAllocateClause(OMPAllocateClause *C) {
 
 void OMPClauseReader::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) {
   VisitOMPClauseWithPreInit(C);
-  C->setNumTeams(Record.readSubExpr());
   C->setLParenLoc(Record.readSourceLocation());
+  unsigned NumVars = C->varlist_size();
+  SmallVector Vars;
+  Vars.reserve(NumVars);
+  for ([[maybe_unused]] unsigned I : llvm::seq(NumVars))

shiltian wrote:

I thought this is Python syntax for unused variable?

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


[clang] [Clang][Sema][OpenMP] Allow `num_teams` to accept multiple expressions (PR #99732)

2024-08-04 Thread Shilei Tian via cfe-commits


@@ -13004,13 +13004,34 @@ StmtResult 
SemaOpenMP::ActOnOpenMPTargetUpdateDirective(
   Clauses, AStmt);
 }
 
+// This checks whether num_teams clause only has one expression.
+static bool checkNumTeamsClauseSingleExpr(SemaBase &SemaRef,

shiltian wrote:

I'm thinking to emit a warning instead of an error. The warning saying only the 
first three expressions will be used. WDYT?

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


[clang] [Clang][Sema][OpenMP] Allow `num_teams` to accept multiple expressions (PR #99732)

2024-08-04 Thread Shilei Tian via cfe-commits

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


[clang] [Clang] strengthen checks for 'main' function to meet [basic.start.main] p2 requirements (PR #101853)

2024-08-04 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/101853

>From 3f8050482f54138c8a836e67e45131d5e9ccf5cc Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sun, 4 Aug 2024 00:45:49 +0300
Subject: [PATCH] [Clang] strengthen checks for 'main' function to meet
 [basic.start.main] p2 requirements

---
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/include/clang/AST/DeclBase.h|  2 +
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +
 clang/include/clang/Sema/Sema.h   |  3 +-
 clang/lib/AST/Decl.cpp|  8 ++--
 clang/lib/Sema/SemaDecl.cpp   | 42 ++-
 clang/test/SemaCXX/linkage1.cpp   | 22 ++
 clang/test/SemaCXX/linkage3.cpp   |  5 +++
 8 files changed, 69 insertions(+), 17 deletions(-)
 create mode 100644 clang/test/SemaCXX/linkage1.cpp
 create mode 100644 clang/test/SemaCXX/linkage3.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4c7bd099420ab..3303db5a87ace 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -145,6 +145,8 @@ Improvements to Clang's diagnostics
 
 - -Wdangling-assignment-gsl is enabled by default.
 
+- Clang now diagnoses the use of `main` in `extern` context as invalid 
according to [basic.start.main] p2. Fixes #GH101512.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 40f01abf384e9..e28626eabe8e8 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -2156,6 +2156,8 @@ class DeclContext {
 return getDeclKind() == Decl::TranslationUnit;
   }
 
+  bool isLinkageSpec() const { return getDeclKind() == Decl::LinkageSpec; }
+
   bool isRecord() const {
 return getDeclKind() >= Decl::firstRecord &&
getDeclKind() <= Decl::lastRecord;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 581434d33c5c9..e86b391264d2a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -990,6 +990,8 @@ def warn_main_redefined : Warning<"variable named 'main' 
with external linkage "
 "has undefined behavior">, InGroup;
 def ext_main_used : Extension<
 "referring to 'main' within an expression is a Clang extension">, 
InGroup;
+def err_main_invalid_linkage_specification : ExtWarn<
+  "'main' cannot have linkage specification 'extern \"C\"'">, InGroup;
 
 /// parser diagnostics
 def ext_no_declarators : ExtWarn<"declaration does not declare anything">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2ec6367eccea0..d791991fcfd8b 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3585,8 +3585,9 @@ class Sema final : public SemaBase {
   /// \param OldT The portion of the type of the old declaration to check.
   bool canFullyTypeCheckRedeclaration(ValueDecl *NewD, ValueDecl *OldD,
   QualType NewT, QualType OldT);
-  void CheckMain(FunctionDecl *FD, const DeclSpec &D);
+  void CheckMain(FunctionDecl *FD, DeclContext *DC, const DeclSpec &D);
   void CheckMSVCRTEntryPoint(FunctionDecl *FD);
+  bool CheckLinkageSpecification(DeclContext *DC, Decl *D);
 
   /// Returns an implicit CodeSegAttr if a __declspec(code_seg) is found on a
   /// containing class. Otherwise it will return implicit SectionAttr if the
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 490c4a2fc525c..aa2ad1752cc5c 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3292,11 +3292,9 @@ bool FunctionDecl::isImmediateFunction() const {
 }
 
 bool FunctionDecl::isMain() const {
-  const TranslationUnitDecl *tunit =
-dyn_cast(getDeclContext()->getRedeclContext());
-  return tunit &&
- !tunit->getASTContext().getLangOpts().Freestanding &&
- isNamed(this, "main");
+  const DeclContext *DC = getDeclContext();
+  return isNamed(this, "main") && !getLangOpts().Freestanding &&
+ (DC->getRedeclContext()->isTranslationUnit() || DC->isLinkageSpec());
 }
 
 bool FunctionDecl::isMSVCRTEntryPoint() const {
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 4fea38d1b02a9..832082d547bf4 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -7353,6 +7353,15 @@ void emitReadOnlyPlacementAttrWarning(Sema &S, const 
VarDecl *VD) {
   }
 }
 
+static bool isMainVar(DeclarationName Name, VarDecl *VD) {
+  if (Name.getAsIdentifierInfo() && Name.getAsIdentifierInfo()->isStr("main") 
&&
+  !VD->getDescribedVarTemplate()) {
+const DeclContext *DC = VD->getDeclContext();
+return DC->getRedeclContext()->isTranslationUnit() || DC->isLinkageSpec();
+  }
+  return false;
+}
+
 NamedDecl *Sema::ActOnVariableDeclarator(
 Scope *S, Decl

[clang] [clang] concepts: perform parameter mapping substitution in correct context (PR #101745)

2024-08-04 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/101745

>From 56c022ef412d311a82a34ae2add05457e53d31ec Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Fri, 2 Aug 2024 16:53:11 -0300
Subject: [PATCH] [clang] concepts: perform parameter mapping subsitution in
 correct context

Prior to this patch, during constraint normalization we could
forget from which declaration an atomic constraint was normalized
from.

Subsequently when performing parameter mapping substitution for
that atomic constraint with an incorrect context, we couldn't
correctly recognize which declarations are supposed to be visible.

Fixes #60336
---
 clang/docs/ReleaseNotes.rst|  3 ++
 clang/include/clang/Sema/SemaConcept.h |  5 +--
 clang/lib/Sema/SemaConcept.cpp |  6 ++--
 clang/test/Modules/GH60336-2.cpp   | 44 ++
 clang/test/Modules/GH60336.cpp | 13 ++--
 5 files changed, 55 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/Modules/GH60336-2.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3d76bd3ae272f..5bd5dbfce7778 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -179,6 +179,9 @@ Bug Fixes to C++ Support
   with a string literal. (#GH82167)
 - Fix a crash when matching template template parameters with templates which 
have
   parameters of different class type. (#GH101394)
+- Clang now correctly recognizes the correct context for parameter
+  substitutions in concepts, so it doesn't incorrectly complain of missing
+  module imports in those situations. (#GH60336)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Sema/SemaConcept.h 
b/clang/include/clang/Sema/SemaConcept.h
index 03791962b2dc0..4b1abccb7741a 100644
--- a/clang/include/clang/Sema/SemaConcept.h
+++ b/clang/include/clang/Sema/SemaConcept.h
@@ -30,10 +30,11 @@ enum { ConstraintAlignment = 8 };
 
 struct alignas(ConstraintAlignment) AtomicConstraint {
   const Expr *ConstraintExpr;
+  NamedDecl *ConstraintDecl;
   std::optional> ParameterMapping;
 
-  AtomicConstraint(Sema &S, const Expr *ConstraintExpr) :
-  ConstraintExpr(ConstraintExpr) { };
+  AtomicConstraint(const Expr *ConstraintExpr, NamedDecl *ConstraintDecl)
+  : ConstraintExpr(ConstraintExpr), ConstraintDecl(ConstraintDecl) {};
 
   bool hasMatchingParameterMapping(ASTContext &C,
const AtomicConstraint &Other) const {
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 9e16b67284be4..7d7a94e9fd637 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1457,8 +1457,8 @@ substituteParameterMappings(Sema &S, NormalizedConstraint 
&N,
   : ArgsAsWritten->arguments().front().getSourceRange().getEnd();
   Sema::InstantiatingTemplate Inst(
   S, InstLocBegin,
-  Sema::InstantiatingTemplate::ParameterMappingSubstitution{}, Concept,
-  {InstLocBegin, InstLocEnd});
+  Sema::InstantiatingTemplate::ParameterMappingSubstitution{},
+  Atomic.ConstraintDecl, {InstLocBegin, InstLocEnd});
   if (Inst.isInvalid())
 return true;
   if (S.SubstTemplateArguments(*Atomic.ParameterMapping, MLTAL, SubstArgs))
@@ -1632,7 +1632,7 @@ NormalizedConstraint::fromConstraintExpr(Sema &S, 
NamedDecl *D, const Expr *E) {
 Kind, std::move(*Sub), FE->getPattern()}};
   }
 
-  return NormalizedConstraint{new (S.Context) AtomicConstraint(S, E)};
+  return NormalizedConstraint{new (S.Context) AtomicConstraint(E, D)};
 }
 
 bool FoldExpandedConstraint::AreCompatibleForSubsumption(
diff --git a/clang/test/Modules/GH60336-2.cpp b/clang/test/Modules/GH60336-2.cpp
new file mode 100644
index 0..9740c744b7b7b
--- /dev/null
+++ b/clang/test/Modules/GH60336-2.cpp
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -x c++ -std=c++20 %s -verify -fmodules 
-fmodules-cache-path=%t
+// expected-no-diagnostics
+
+#pragma clang module build std
+module std {
+  module concepts {}
+  module functional {}
+}
+#pragma clang module contents
+#pragma clang module begin std
+
+template  struct common_reference {
+  using type = _Tp;
+};
+
+#pragma clang module end
+#pragma clang module begin std.concepts
+#pragma clang module import std
+
+template 
+concept same_as = __is_same(_Tp, _Tp);
+
+template 
+concept common_reference_with =
+same_as::type>;
+
+#pragma clang module end
+#pragma clang module begin std.functional
+#pragma clang module import std.concepts
+
+template 
+concept sentinel_for = common_reference_with<_Ip>;
+
+constexpr bool ntsf_subsumes_sf(sentinel_for auto)
+  requires true
+{
+  return true;
+}
+bool ntsf_subsumes_sf(sentinel_for auto);
+static_assert(ntsf_subsumes_sf(""));
+
+#pragma clang module end
+#pragma clang module endbuild
diff --git a/clang/test/Modules/GH60336.cpp b/clang/test/Modules/GH60336.cpp
index fefbd37b7926c..e181c24904217 100644
--- a/clang/test/Modules/GH60336.c

[clang] [clang-format] Add PackParameters enum option to replace BinPackParameters. (PR #101882)

2024-08-04 Thread via cfe-commits

https://github.com/mydeveloperday commented:

Why change the name?

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


[clang] [Clang] strengthen checks for 'main' function to meet [basic.start.main] p2 requirements (PR #101853)

2024-08-04 Thread Oleksandr T. via cfe-commits

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


[clang] [Clang] strengthen checks for 'main' function to meet [basic.start.main] p2 requirements (PR #101853)

2024-08-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Oleksandr T. (a-tarasyuk)


Changes

Fixes #101512 

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


8 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/AST/DeclBase.h (+2) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+2) 
- (modified) clang/include/clang/Sema/Sema.h (+2-1) 
- (modified) clang/lib/AST/Decl.cpp (+3-5) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+31-11) 
- (added) clang/test/SemaCXX/linkage1.cpp (+22) 
- (added) clang/test/SemaCXX/linkage3.cpp (+5) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 4c7bd099420ab..3303db5a87ace 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -145,6 +145,8 @@ Improvements to Clang's diagnostics
 
 - -Wdangling-assignment-gsl is enabled by default.
 
+- Clang now diagnoses the use of `main` in `extern` context as invalid 
according to [basic.start.main] p2. Fixes #GH101512.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 40f01abf384e9..e28626eabe8e8 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -2156,6 +2156,8 @@ class DeclContext {
 return getDeclKind() == Decl::TranslationUnit;
   }
 
+  bool isLinkageSpec() const { return getDeclKind() == Decl::LinkageSpec; }
+
   bool isRecord() const {
 return getDeclKind() >= Decl::firstRecord &&
getDeclKind() <= Decl::lastRecord;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 581434d33c5c9..e86b391264d2a 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -990,6 +990,8 @@ def warn_main_redefined : Warning<"variable named 'main' 
with external linkage "
 "has undefined behavior">, InGroup;
 def ext_main_used : Extension<
 "referring to 'main' within an expression is a Clang extension">, 
InGroup;
+def err_main_invalid_linkage_specification : ExtWarn<
+  "'main' cannot have linkage specification 'extern \"C\"'">, InGroup;
 
 /// parser diagnostics
 def ext_no_declarators : ExtWarn<"declaration does not declare anything">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2ec6367eccea0..d791991fcfd8b 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3585,8 +3585,9 @@ class Sema final : public SemaBase {
   /// \param OldT The portion of the type of the old declaration to check.
   bool canFullyTypeCheckRedeclaration(ValueDecl *NewD, ValueDecl *OldD,
   QualType NewT, QualType OldT);
-  void CheckMain(FunctionDecl *FD, const DeclSpec &D);
+  void CheckMain(FunctionDecl *FD, DeclContext *DC, const DeclSpec &D);
   void CheckMSVCRTEntryPoint(FunctionDecl *FD);
+  bool CheckLinkageSpecification(DeclContext *DC, Decl *D);
 
   /// Returns an implicit CodeSegAttr if a __declspec(code_seg) is found on a
   /// containing class. Otherwise it will return implicit SectionAttr if the
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 490c4a2fc525c..aa2ad1752cc5c 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -3292,11 +3292,9 @@ bool FunctionDecl::isImmediateFunction() const {
 }
 
 bool FunctionDecl::isMain() const {
-  const TranslationUnitDecl *tunit =
-dyn_cast(getDeclContext()->getRedeclContext());
-  return tunit &&
- !tunit->getASTContext().getLangOpts().Freestanding &&
- isNamed(this, "main");
+  const DeclContext *DC = getDeclContext();
+  return isNamed(this, "main") && !getLangOpts().Freestanding &&
+ (DC->getRedeclContext()->isTranslationUnit() || DC->isLinkageSpec());
 }
 
 bool FunctionDecl::isMSVCRTEntryPoint() const {
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 4fea38d1b02a9..832082d547bf4 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -7353,6 +7353,15 @@ void emitReadOnlyPlacementAttrWarning(Sema &S, const 
VarDecl *VD) {
   }
 }
 
+static bool isMainVar(DeclarationName Name, VarDecl *VD) {
+  if (Name.getAsIdentifierInfo() && Name.getAsIdentifierInfo()->isStr("main") 
&&
+  !VD->getDescribedVarTemplate()) {
+const DeclContext *DC = VD->getDeclContext();
+return DC->getRedeclContext()->isTranslationUnit() || DC->isLinkageSpec();
+  }
+  return false;
+}
+
 NamedDecl *Sema::ActOnVariableDeclarator(
 Scope *S, Declarator &D, DeclContext *DC, TypeSourceInfo *TInfo,
 LookupResult &Previous, MultiTemplateParamsArg TemplateParamLists,
@@ -8052,15 +8061,13 @@ NamedDecl *Sema::ActOnVariableDeclarator(
   }
 
   // Special handling of variable named 'main'.
-  if (Name.getAsIdentifierInfo() && Name.getAsIdentifierInfo()->isStr("main"

[clang] [Clang] strengthen checks for 'main' function to meet [basic.start.main] p2 requirements (PR #101853)

2024-08-04 Thread Oleksandr T. via cfe-commits


@@ -990,6 +990,9 @@ def warn_main_redefined : Warning<"variable named 'main' 
with external linkage "
 "has undefined behavior">, InGroup;
 def ext_main_used : Extension<
 "referring to 'main' within an expression is a Clang extension">, 
InGroup;
+def err_invalid_linkage_specification : Extension<
+  "invalid linkage specification "
+  "'extern \"%select{C|C++}0\"'">;

a-tarasyuk wrote:

@MitalAshok I've updated the diagnostic message

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


[clang] [Clang] strengthen checks for 'main' function to meet [basic.start.main] p2 requirements (PR #101853)

2024-08-04 Thread Oleksandr T. via cfe-commits


@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -pedantic-errors %s
+
+namespace c {
+  extern "C" void main(); // expected-error {{invalid linkage specification 
'extern "C"'}}
+}
+extern "C" {
+  int main(); // expected-error {{invalid linkage specification 'extern "C"'}}
+}
+extern "C" int main(); // expected-error {{invalid linkage specification 
'extern "C"'}}
+extern "C" struct A { int main(); }; // ok
+
+namespace cpp {
+  extern "C++" int main(); // expected-error {{invalid linkage specification 
'extern "C++"'}}

a-tarasyuk wrote:

@MitalAshok Thanks for the feedback. I've added 
[linkage3.cpp](https://github.com/llvm/llvm-project/pull/101853/files#diff-dc2bba9678021106302e8711c2140ad1e575de50b157537e64b37621e97b9ec9)
 to cover this case.

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


[clang] [clang-format] Add PackParameters enum option to replace BinPackParameters. (PR #101882)

2024-08-04 Thread via cfe-commits

VolatileAcorn wrote:

Sorry, I incorrectly assumed that I needed to create a new option if I was 
changing an option from a bool to an enum.
I can change this back to have the same name and add the true / false cases to 
the enumeration parsing function.

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


[clang] [clang] concepts: perform parameter mapping substitution in correct context (PR #101745)

2024-08-04 Thread Matheus Izvekov via cfe-commits

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


[clang] 9e9d98a - [clang] concepts: perform parameter mapping substitution in correct context (#101745)

2024-08-04 Thread via cfe-commits

Author: Matheus Izvekov
Date: 2024-08-04T19:00:54-03:00
New Revision: 9e9d98aaf503171e2cb229e89966ec1c0adf3804

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

LOG: [clang] concepts: perform parameter mapping substitution in correct 
context (#101745)

Prior to this patch, during constraint normalization we could forget
from which declaration an atomic constraint was normalized from.

Subsequently when performing parameter mapping substitution for that
atomic constraint with an incorrect context, we couldn't correctly
recognize which declarations are supposed to be visible.

Fixes #60336

Added: 
clang/test/Modules/GH60336-2.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/SemaConcept.h
clang/lib/Sema/SemaConcept.cpp
clang/test/Modules/GH60336.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3d76bd3ae272f..5bd5dbfce7778 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -179,6 +179,9 @@ Bug Fixes to C++ Support
   with a string literal. (#GH82167)
 - Fix a crash when matching template template parameters with templates which 
have
   parameters of 
diff erent class type. (#GH101394)
+- Clang now correctly recognizes the correct context for parameter
+  substitutions in concepts, so it doesn't incorrectly complain of missing
+  module imports in those situations. (#GH60336)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/include/clang/Sema/SemaConcept.h 
b/clang/include/clang/Sema/SemaConcept.h
index 03791962b2dc0..4b1abccb7741a 100644
--- a/clang/include/clang/Sema/SemaConcept.h
+++ b/clang/include/clang/Sema/SemaConcept.h
@@ -30,10 +30,11 @@ enum { ConstraintAlignment = 8 };
 
 struct alignas(ConstraintAlignment) AtomicConstraint {
   const Expr *ConstraintExpr;
+  NamedDecl *ConstraintDecl;
   std::optional> ParameterMapping;
 
-  AtomicConstraint(Sema &S, const Expr *ConstraintExpr) :
-  ConstraintExpr(ConstraintExpr) { };
+  AtomicConstraint(const Expr *ConstraintExpr, NamedDecl *ConstraintDecl)
+  : ConstraintExpr(ConstraintExpr), ConstraintDecl(ConstraintDecl) {};
 
   bool hasMatchingParameterMapping(ASTContext &C,
const AtomicConstraint &Other) const {

diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 9e16b67284be4..7d7a94e9fd637 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -1457,8 +1457,8 @@ substituteParameterMappings(Sema &S, NormalizedConstraint 
&N,
   : ArgsAsWritten->arguments().front().getSourceRange().getEnd();
   Sema::InstantiatingTemplate Inst(
   S, InstLocBegin,
-  Sema::InstantiatingTemplate::ParameterMappingSubstitution{}, Concept,
-  {InstLocBegin, InstLocEnd});
+  Sema::InstantiatingTemplate::ParameterMappingSubstitution{},
+  Atomic.ConstraintDecl, {InstLocBegin, InstLocEnd});
   if (Inst.isInvalid())
 return true;
   if (S.SubstTemplateArguments(*Atomic.ParameterMapping, MLTAL, SubstArgs))
@@ -1632,7 +1632,7 @@ NormalizedConstraint::fromConstraintExpr(Sema &S, 
NamedDecl *D, const Expr *E) {
 Kind, std::move(*Sub), FE->getPattern()}};
   }
 
-  return NormalizedConstraint{new (S.Context) AtomicConstraint(S, E)};
+  return NormalizedConstraint{new (S.Context) AtomicConstraint(E, D)};
 }
 
 bool FoldExpandedConstraint::AreCompatibleForSubsumption(

diff  --git a/clang/test/Modules/GH60336-2.cpp 
b/clang/test/Modules/GH60336-2.cpp
new file mode 100644
index 0..9740c744b7b7b
--- /dev/null
+++ b/clang/test/Modules/GH60336-2.cpp
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -x c++ -std=c++20 %s -verify -fmodules 
-fmodules-cache-path=%t
+// expected-no-diagnostics
+
+#pragma clang module build std
+module std {
+  module concepts {}
+  module functional {}
+}
+#pragma clang module contents
+#pragma clang module begin std
+
+template  struct common_reference {
+  using type = _Tp;
+};
+
+#pragma clang module end
+#pragma clang module begin std.concepts
+#pragma clang module import std
+
+template 
+concept same_as = __is_same(_Tp, _Tp);
+
+template 
+concept common_reference_with =
+same_as::type>;
+
+#pragma clang module end
+#pragma clang module begin std.functional
+#pragma clang module import std.concepts
+
+template 
+concept sentinel_for = common_reference_with<_Ip>;
+
+constexpr bool ntsf_subsumes_sf(sentinel_for auto)
+  requires true
+{
+  return true;
+}
+bool ntsf_subsumes_sf(sentinel_for auto);
+static_assert(ntsf_subsumes_sf(""));
+
+#pragma clang module end
+#pragma clang module endbuild

diff  --git a/clang/test/Modules/GH60336.cpp b/clang/test/Modules/GH60336.cpp
index fefbd37b7926c..e181c24904217 100644
--- a/clang/test/Modul

[clang] [clang] remove unneeded template deduction canonicalizations (PR #101594)

2024-08-04 Thread Matheus Izvekov via cfe-commits

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


[clang] [clang] remove unneeded template deduction canonicalizations (PR #101594)

2024-08-04 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/101594

>From fd9bdcc17821be3d22e0787759cbdd6b077dbd90 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 1 Aug 2024 19:18:52 -0300
Subject: [PATCH] [clang] remove unneeded template deduction canonicalizations

This is mostly a cleanups patch, with some hard to observe
sugar preservation improvements.

Except for the function template deduction changes
which improve some pre-existing diagnostics a little bit.
---
 clang/lib/Sema/SemaTemplate.cpp   |  4 +-
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 87 +++
 .../cxx1y-generic-lambdas-variadics.cpp   |  8 +-
 clang/test/SemaCXX/cxx1y-generic-lambdas.cpp  |  4 +-
 4 files changed, 40 insertions(+), 63 deletions(-)

diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index c22e329bef2b9..cb16e8caa9a8a 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -4202,7 +4202,7 @@ Sema::CheckVarTemplateId(VarTemplateDecl *Template, 
SourceLocation TemplateLoc,
 TemplateDeductionInfo Info(FailedCandidates.getLocation());
 
 if (TemplateDeductionResult Result =
-DeduceTemplateArguments(Partial, CanonicalConverted, Info);
+DeduceTemplateArguments(Partial, SugaredConverted, Info);
 Result != TemplateDeductionResult::Success) {
   // Store the failed-deduction information for use in diagnostics, later.
   // TODO: Actually use the failed-deduction info?
@@ -4213,7 +4213,7 @@ Sema::CheckVarTemplateId(VarTemplateDecl *Template, 
SourceLocation TemplateLoc,
 } else {
   Matched.push_back(PartialSpecMatchResult());
   Matched.back().Partial = Partial;
-  Matched.back().Args = Info.takeCanonical();
+  Matched.back().Args = Info.takeSugared();
 }
   }
 
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index db7f233dcef73..e9705ec43d86c 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -503,7 +503,6 @@ static TemplateDeductionResult 
DeduceNonTypeTemplateArgument(
 const NonTypeTemplateParmDecl *NTTP, ValueDecl *D, QualType T,
 TemplateDeductionInfo &Info,
 SmallVectorImpl &Deduced) {
-  D = D ? cast(D->getCanonicalDecl()) : nullptr;
   TemplateArgument New(D, T);
   return DeduceNonTypeTemplateArgument(
   S, TemplateParams, NTTP, DeducedTemplateArgument(New), T, Info, Deduced);
@@ -1380,11 +1379,6 @@ static bool isForwardingReference(QualType Param, 
unsigned FirstInnerIndex) {
   return false;
 }
 
-static CXXRecordDecl *getCanonicalRD(QualType T) {
-  return cast(
-  T->castAs()->getDecl()->getCanonicalDecl());
-}
-
 ///  Attempt to deduce the template arguments by checking the base types
 ///  according to (C++20 [temp.deduct.call] p4b3.
 ///
@@ -1439,7 +1433,7 @@ DeduceTemplateBases(Sema &S, const CXXRecordDecl *RD,
 for (const auto &Base : RD->bases()) {
   QualType T = Base.getType();
   assert(T->isRecordType() && "Base class that isn't a record?");
-  if (Visited.insert(::getCanonicalRD(T)).second)
+  if (Visited.insert(T->getAsCXXRecordDecl()).second)
 ToVisit.push_back(T);
 }
   };
@@ -1460,7 +1454,7 @@ DeduceTemplateBases(Sema &S, const CXXRecordDecl *RD,
 
 // If this was a successful deduction, add it to the list of matches,
 // otherwise we need to continue searching its bases.
-const CXXRecordDecl *RD = ::getCanonicalRD(NextT);
+const CXXRecordDecl *RD = NextT->getAsCXXRecordDecl();
 if (BaseResult == TemplateDeductionResult::Success)
   Matches.insert({RD, DeducedCopy});
 else
@@ -1481,7 +1475,7 @@ DeduceTemplateBases(Sema &S, const CXXRecordDecl *RD,
 // We can give up once we have a single item (or have run out of things to
 // search) since cyclical inheritance isn't valid.
 while (Matches.size() > 1 && !ToVisit.empty()) {
-  const CXXRecordDecl *RD = ::getCanonicalRD(ToVisit.pop_back_val());
+  const CXXRecordDecl *RD = ToVisit.pop_back_val()->getAsCXXRecordDecl();
   Matches.erase(RD);
 
   // Always add all bases, since the inheritance tree can contain
@@ -2030,15 +2024,16 @@ static TemplateDeductionResult 
DeduceTemplateArgumentsByTypeMatch(
   if (!S.isCompleteType(Info.getLocation(), A))
 return Result;
 
-  if (getCanonicalRD(A)->isInvalidDecl())
+  const CXXRecordDecl *RD = A->getAsCXXRecordDecl();
+  if (RD->isInvalidDecl())
 return Result;
 
   // Reset the incorrectly deduced argument from above.
   Deduced = DeducedOrig;
 
   // Check bases according to C++14 [temp.deduct.call] p4b3:
-  auto BaseResult = DeduceTemplateBases(S, getCanonicalRD(A),
-TemplateParams, P, Info, Deduced);
+  auto BaseResult =
+  DeduceTemplateBases(S, RD, TemplateParams, P, Info, Deduced);
   return BaseResul

[clang-tools-extra] [clangd] support the zig c++ compiler wrapper (PR #100759)

2024-08-04 Thread via cfe-commits

duk-37 wrote:

This is a simple and nice change. Improving the developer experience and having 
things "just work" is always good.

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


[clang] 8a26c6d - [clang] remove unneeded template deduction canonicalizations (#101594)

2024-08-04 Thread via cfe-commits

Author: Matheus Izvekov
Date: 2024-08-04T19:47:02-03:00
New Revision: 8a26c6d9d4ca18b9906f3ec13d52fc0b2952a5f7

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

LOG: [clang] remove unneeded template deduction canonicalizations (#101594)

This is mostly a cleanups patch, with some hard to observe sugar
preservation improvements.

Except for the function template deduction changes which improve some
pre-existing diagnostics a little bit.

Added: 


Modified: 
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/SemaCXX/cxx1y-generic-lambdas-variadics.cpp
clang/test/SemaCXX/cxx1y-generic-lambdas.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index c22e329bef2b9..cb16e8caa9a8a 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -4202,7 +4202,7 @@ Sema::CheckVarTemplateId(VarTemplateDecl *Template, 
SourceLocation TemplateLoc,
 TemplateDeductionInfo Info(FailedCandidates.getLocation());
 
 if (TemplateDeductionResult Result =
-DeduceTemplateArguments(Partial, CanonicalConverted, Info);
+DeduceTemplateArguments(Partial, SugaredConverted, Info);
 Result != TemplateDeductionResult::Success) {
   // Store the failed-deduction information for use in diagnostics, later.
   // TODO: Actually use the failed-deduction info?
@@ -4213,7 +4213,7 @@ Sema::CheckVarTemplateId(VarTemplateDecl *Template, 
SourceLocation TemplateLoc,
 } else {
   Matched.push_back(PartialSpecMatchResult());
   Matched.back().Partial = Partial;
-  Matched.back().Args = Info.takeCanonical();
+  Matched.back().Args = Info.takeSugared();
 }
   }
 

diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index db7f233dcef73..e9705ec43d86c 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -503,7 +503,6 @@ static TemplateDeductionResult 
DeduceNonTypeTemplateArgument(
 const NonTypeTemplateParmDecl *NTTP, ValueDecl *D, QualType T,
 TemplateDeductionInfo &Info,
 SmallVectorImpl &Deduced) {
-  D = D ? cast(D->getCanonicalDecl()) : nullptr;
   TemplateArgument New(D, T);
   return DeduceNonTypeTemplateArgument(
   S, TemplateParams, NTTP, DeducedTemplateArgument(New), T, Info, Deduced);
@@ -1380,11 +1379,6 @@ static bool isForwardingReference(QualType Param, 
unsigned FirstInnerIndex) {
   return false;
 }
 
-static CXXRecordDecl *getCanonicalRD(QualType T) {
-  return cast(
-  T->castAs()->getDecl()->getCanonicalDecl());
-}
-
 ///  Attempt to deduce the template arguments by checking the base types
 ///  according to (C++20 [temp.deduct.call] p4b3.
 ///
@@ -1439,7 +1433,7 @@ DeduceTemplateBases(Sema &S, const CXXRecordDecl *RD,
 for (const auto &Base : RD->bases()) {
   QualType T = Base.getType();
   assert(T->isRecordType() && "Base class that isn't a record?");
-  if (Visited.insert(::getCanonicalRD(T)).second)
+  if (Visited.insert(T->getAsCXXRecordDecl()).second)
 ToVisit.push_back(T);
 }
   };
@@ -1460,7 +1454,7 @@ DeduceTemplateBases(Sema &S, const CXXRecordDecl *RD,
 
 // If this was a successful deduction, add it to the list of matches,
 // otherwise we need to continue searching its bases.
-const CXXRecordDecl *RD = ::getCanonicalRD(NextT);
+const CXXRecordDecl *RD = NextT->getAsCXXRecordDecl();
 if (BaseResult == TemplateDeductionResult::Success)
   Matches.insert({RD, DeducedCopy});
 else
@@ -1481,7 +1475,7 @@ DeduceTemplateBases(Sema &S, const CXXRecordDecl *RD,
 // We can give up once we have a single item (or have run out of things to
 // search) since cyclical inheritance isn't valid.
 while (Matches.size() > 1 && !ToVisit.empty()) {
-  const CXXRecordDecl *RD = ::getCanonicalRD(ToVisit.pop_back_val());
+  const CXXRecordDecl *RD = ToVisit.pop_back_val()->getAsCXXRecordDecl();
   Matches.erase(RD);
 
   // Always add all bases, since the inheritance tree can contain
@@ -2030,15 +2024,16 @@ static TemplateDeductionResult 
DeduceTemplateArgumentsByTypeMatch(
   if (!S.isCompleteType(Info.getLocation(), A))
 return Result;
 
-  if (getCanonicalRD(A)->isInvalidDecl())
+  const CXXRecordDecl *RD = A->getAsCXXRecordDecl();
+  if (RD->isInvalidDecl())
 return Result;
 
   // Reset the incorrectly deduced argument from above.
   Deduced = DeducedOrig;
 
   // Check bases according to C++14 [temp.deduct.call] p4b3:
-  auto BaseResult = DeduceTemplateBases(S, getCanonicalRD(A),
-TemplateParams, P, Info, Deduced);
+  auto BaseRe

[clang] [clang] remove unneeded template deduction canonicalizations (PR #101594)

2024-08-04 Thread Matheus Izvekov via cfe-commits

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


[clang] [libcxx] [clang] Reland: Instantiate concepts with sugared template arguments (PR #101782)

2024-08-04 Thread Matheus Izvekov via cfe-commits

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


[clang] [libcxx] [clang] Reland: Instantiate concepts with sugared template arguments (PR #101782)

2024-08-04 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/101782

>From 6a172a93121fdbeb0e58b33ec3140f150ecb524a Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Sun, 23 Oct 2022 11:37:20 +0200
Subject: [PATCH] [clang] Reland: Instantiate concepts with sugared template
 arguments

Since we don't unique specializations for concepts, we can just instantiate
them with the sugared template arguments, at negligible cost.

If we don't track their specializations, we can't resugar them later
anyway, and that would be more expensive than just instantiating them
sugared in the first place since it would require an additional pass.

This was a previously reverted patch due to a performance regression,
which was very simple to fix, as we were only missing the
canonicalizations for the key to the satisfcation cache.

Fixes #59271

Differential Revision: https://reviews.llvm.org/D136566
---
 clang/docs/ReleaseNotes.rst  |  1 +
 clang/include/clang/Sema/Template.h  |  6 +++---
 clang/lib/Sema/SemaConcept.cpp   | 11 +++
 clang/lib/Sema/SemaExprCXX.cpp   |  5 ++---
 clang/lib/Sema/SemaTemplate.cpp  | 10 +-
 clang/lib/Sema/SemaTemplateDeduction.cpp | 16 
 clang/lib/Serialization/ASTReaderDecl.cpp|  2 +-
 clang/test/AST/ast-dump-concepts.cpp | 10 ++
 .../expr.prim.req/compound-requirement.cpp   | 10 +-
 .../expr.prim.req/nested-requirement.cpp |  2 +-
 .../expr.prim.req/simple-requirement.cpp |  4 ++--
 .../expr.prim/expr.prim.req/type-requirement.cpp | 12 ++--
 .../temp/temp.constr/temp.constr.normal/p1.cpp   |  2 +-
 clang/test/CXX/temp/temp.param/p10-2a.cpp|  4 ++--
 .../SemaTemplate/concepts-recursive-inst.cpp | 12 ++--
 clang/test/SemaTemplate/concepts.cpp |  4 ++--
 .../SemaTemplate/instantiate-requires-expr.cpp   | 16 +---
 clang/test/SemaTemplate/pr52970.cpp  |  2 +-
 .../cpp17_iterator_concepts.verify.cpp   |  2 +-
 19 files changed, 73 insertions(+), 58 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5bd5dbfce7778..6202597d1aaf1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -148,6 +148,7 @@ Improvements to Clang's diagnostics
 - Clang now diagnoses undefined behavior in constant expressions more 
consistently. This includes invalid shifts, and signed overflow in arithmetic.
 
 - -Wdangling-assignment-gsl is enabled by default.
+- Clang now does a better job preserving the template arguments as written 
when specializing concepts.
 
 Improvements to Clang's time-trace
 --
diff --git a/clang/include/clang/Sema/Template.h 
b/clang/include/clang/Sema/Template.h
index 0340c23fd170d..d616865afe807 100644
--- a/clang/include/clang/Sema/Template.h
+++ b/clang/include/clang/Sema/Template.h
@@ -234,7 +234,8 @@ enum class TemplateSubstitutionKind : char {
 /// Replaces the current 'innermost' level with the provided argument list.
 /// This is useful for type deduction cases where we need to get the entire
 /// list from the AST, but then add the deduced innermost list.
-void replaceInnermostTemplateArguments(Decl *AssociatedDecl, ArgList Args) 
{
+void replaceInnermostTemplateArguments(Decl *AssociatedDecl, ArgList Args,
+   bool Final = false) {
   assert((!TemplateArgumentLists.empty() || NumRetainedOuterLevels) &&
  "Replacing in an empty list?");
 
@@ -246,8 +247,7 @@ enum class TemplateSubstitutionKind : char {
 TemplateArgumentLists[0].Args = Args;
   } else {
 --NumRetainedOuterLevels;
-TemplateArgumentLists.push_back(
-{{AssociatedDecl, /*Final=*/false}, Args});
+TemplateArgumentLists.push_back({{AssociatedDecl, Final}, Args});
   }
 }
 
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 7d7a94e9fd637..75ccefa2a487e 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -414,7 +414,8 @@ DiagRecursiveConstraintEval(Sema &S, llvm::FoldingSetNodeID 
&ID,
   E->Profile(ID, S.Context, /*Canonical=*/true);
   for (const auto &List : MLTAL)
 for (const auto &TemplateArg : List.Args)
-  TemplateArg.Profile(ID, S.Context);
+  S.Context.getCanonicalTemplateArgument(TemplateArg)
+  .Profile(ID, S.Context);
 
   // Note that we have to do this with our own collection, because there are
   // times where a constraint-expression check can cause us to need to evaluate
@@ -638,8 +639,8 @@ bool Sema::CheckConstraintSatisfaction(
   // here.
   llvm::SmallVector FlattenedArgs;
   for (auto List : TemplateArgsLists)
-FlattenedArgs.insert(FlattenedArgs.end(), List.Args.begin(),
- List.Args.end());
+for (const TemplateArg

[clang] [Fuchsia][CMake] Check correct triple to set -mcpu (PR #101910)

2024-08-04 Thread Petr Hosek via cfe-commits

https://github.com/petrhosek created 
https://github.com/llvm/llvm-project/pull/101910

We use armv8m.main-none-eabi now, not armv8m.main-unknown-eabi.

>From e039c097f997cb95f2f3725c4efa6420c8ed48c0 Mon Sep 17 00:00:00 2001
From: Petr Hosek 
Date: Sun, 4 Aug 2024 16:30:35 -0700
Subject: [PATCH] [Fuchsia][CMake] Check correct triple to set -mcpu

We use armv8m.main-none-eabi now, not armv8m.main-unknown-eabi.
---
 clang/cmake/caches/Fuchsia-stage2.cmake | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 7d05940f0d092..fb9ebeeb0031f 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -328,7 +328,7 @@ foreach(target 
armv6m-none-eabi;armv7m-none-eabi;armv8m.main-none-eabi)
 # TODO: The preprocessor defines workaround various issues in libc and 
libc++ integration.
 # These should be addressed and removed over time.
 set(RUNTIMES_${target}_CMAKE_${lang}_local_flags "--target=${target} 
-mthumb -Wno-atomic-alignment \"-Dvfprintf(stream, format, 
vlist)=vprintf(format, vlist)\" \"-Dfprintf(stream, format, 
...)=printf(format)\" \"-Dtimeval=struct timeval{int tv_sec; int tv_usec;}\" 
\"-Dgettimeofday(tv, tz)\" -D_LIBCPP_PRINT=1")
-if(${target} STREQUAL "armv8m.main-unknown-eabi")
+if(${target} STREQUAL "armv8m.main-none-eabi")
   set(RUNTIMES_${target}_CMAKE_${lang}_local_flags 
"${RUNTIMES_${target}_CMAKE_${lang}_local_flags} -mfloat-abi=softfp 
-march=armv8m.main+fp+dsp -mcpu=cortex-m33" CACHE STRING "")
 endif()
 set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS 
"${RUNTIMES_${target}_CMAKE_${lang}_local_flags}" CACHE STRING "")

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


[clang] [Fuchsia][CMake] Check correct triple to set -mcpu (PR #101910)

2024-08-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Petr Hosek (petrhosek)


Changes

We use armv8m.main-none-eabi now, not armv8m.main-unknown-eabi.

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


1 Files Affected:

- (modified) clang/cmake/caches/Fuchsia-stage2.cmake (+1-1) 


``diff
diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 7d05940f0d092..fb9ebeeb0031f 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -328,7 +328,7 @@ foreach(target 
armv6m-none-eabi;armv7m-none-eabi;armv8m.main-none-eabi)
 # TODO: The preprocessor defines workaround various issues in libc and 
libc++ integration.
 # These should be addressed and removed over time.
 set(RUNTIMES_${target}_CMAKE_${lang}_local_flags "--target=${target} 
-mthumb -Wno-atomic-alignment \"-Dvfprintf(stream, format, 
vlist)=vprintf(format, vlist)\" \"-Dfprintf(stream, format, 
...)=printf(format)\" \"-Dtimeval=struct timeval{int tv_sec; int tv_usec;}\" 
\"-Dgettimeofday(tv, tz)\" -D_LIBCPP_PRINT=1")
-if(${target} STREQUAL "armv8m.main-unknown-eabi")
+if(${target} STREQUAL "armv8m.main-none-eabi")
   set(RUNTIMES_${target}_CMAKE_${lang}_local_flags 
"${RUNTIMES_${target}_CMAKE_${lang}_local_flags} -mfloat-abi=softfp 
-march=armv8m.main+fp+dsp -mcpu=cortex-m33" CACHE STRING "")
 endif()
 set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS 
"${RUNTIMES_${target}_CMAKE_${lang}_local_flags}" CACHE STRING "")

``




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


[clang] [Fuchsia][CMake] Check correct triple to set -mcpu (PR #101910)

2024-08-04 Thread via cfe-commits

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


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


[clang] 22c06aa - [Fuchsia][CMake] Check correct triple to set -mcpu (#101910)

2024-08-04 Thread via cfe-commits

Author: Petr Hosek
Date: 2024-08-04T16:35:56-07:00
New Revision: 22c06aa5e94e30fb1333ecaf46ce33c65d148634

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

LOG: [Fuchsia][CMake] Check correct triple to set -mcpu (#101910)

We use armv8m.main-none-eabi now, not armv8m.main-unknown-eabi.

Added: 


Modified: 
clang/cmake/caches/Fuchsia-stage2.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia-stage2.cmake 
b/clang/cmake/caches/Fuchsia-stage2.cmake
index 7d05940f0d092..fb9ebeeb0031f 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -328,7 +328,7 @@ foreach(target 
armv6m-none-eabi;armv7m-none-eabi;armv8m.main-none-eabi)
 # TODO: The preprocessor defines workaround various issues in libc and 
libc++ integration.
 # These should be addressed and removed over time.
 set(RUNTIMES_${target}_CMAKE_${lang}_local_flags "--target=${target} 
-mthumb -Wno-atomic-alignment \"-Dvfprintf(stream, format, 
vlist)=vprintf(format, vlist)\" \"-Dfprintf(stream, format, 
...)=printf(format)\" \"-Dtimeval=struct timeval{int tv_sec; int tv_usec;}\" 
\"-Dgettimeofday(tv, tz)\" -D_LIBCPP_PRINT=1")
-if(${target} STREQUAL "armv8m.main-unknown-eabi")
+if(${target} STREQUAL "armv8m.main-none-eabi")
   set(RUNTIMES_${target}_CMAKE_${lang}_local_flags 
"${RUNTIMES_${target}_CMAKE_${lang}_local_flags} -mfloat-abi=softfp 
-march=armv8m.main+fp+dsp -mcpu=cortex-m33" CACHE STRING "")
 endif()
 set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS 
"${RUNTIMES_${target}_CMAKE_${lang}_local_flags}" CACHE STRING "")



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


[clang] [Fuchsia][CMake] Check correct triple to set -mcpu (PR #101910)

2024-08-04 Thread Petr Hosek via cfe-commits

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


[clang] [libcxx] [clang] Reland: Instantiate concepts with sugared template arguments (PR #101782)

2024-08-04 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

Since this is relanding of patch that has been previously reviewed, with no 
notable changes except rebase and canonicalization when indexing the 
satisfaction cache, I am going to go ahead and merge.

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


[clang] 7483711 - [clang] Reland: Instantiate concepts with sugared template arguments (#101782)

2024-08-04 Thread via cfe-commits

Author: Matheus Izvekov
Date: 2024-08-04T22:11:11-03:00
New Revision: 748371183ae769bfb485f1e7466a864bf1db93d5

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

LOG: [clang] Reland: Instantiate concepts with sugared template arguments 
(#101782)

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Template.h
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/test/AST/ast-dump-concepts.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/simple-requirement.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/type-requirement.cpp
clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp
clang/test/CXX/temp/temp.param/p10-2a.cpp
clang/test/SemaTemplate/concepts-recursive-inst.cpp
clang/test/SemaTemplate/concepts.cpp
clang/test/SemaTemplate/instantiate-requires-expr.cpp
clang/test/SemaTemplate/pr52970.cpp
libcxx/test/libcxx/algorithms/cpp17_iterator_concepts.verify.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5bd5dbfce7778..6202597d1aaf1 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -148,6 +148,7 @@ Improvements to Clang's diagnostics
 - Clang now diagnoses undefined behavior in constant expressions more 
consistently. This includes invalid shifts, and signed overflow in arithmetic.
 
 - -Wdangling-assignment-gsl is enabled by default.
+- Clang now does a better job preserving the template arguments as written 
when specializing concepts.
 
 Improvements to Clang's time-trace
 --

diff  --git a/clang/include/clang/Sema/Template.h 
b/clang/include/clang/Sema/Template.h
index 0340c23fd170d..d616865afe807 100644
--- a/clang/include/clang/Sema/Template.h
+++ b/clang/include/clang/Sema/Template.h
@@ -234,7 +234,8 @@ enum class TemplateSubstitutionKind : char {
 /// Replaces the current 'innermost' level with the provided argument list.
 /// This is useful for type deduction cases where we need to get the entire
 /// list from the AST, but then add the deduced innermost list.
-void replaceInnermostTemplateArguments(Decl *AssociatedDecl, ArgList Args) 
{
+void replaceInnermostTemplateArguments(Decl *AssociatedDecl, ArgList Args,
+   bool Final = false) {
   assert((!TemplateArgumentLists.empty() || NumRetainedOuterLevels) &&
  "Replacing in an empty list?");
 
@@ -246,8 +247,7 @@ enum class TemplateSubstitutionKind : char {
 TemplateArgumentLists[0].Args = Args;
   } else {
 --NumRetainedOuterLevels;
-TemplateArgumentLists.push_back(
-{{AssociatedDecl, /*Final=*/false}, Args});
+TemplateArgumentLists.push_back({{AssociatedDecl, Final}, Args});
   }
 }
 

diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 7d7a94e9fd637..75ccefa2a487e 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -414,7 +414,8 @@ DiagRecursiveConstraintEval(Sema &S, llvm::FoldingSetNodeID 
&ID,
   E->Profile(ID, S.Context, /*Canonical=*/true);
   for (const auto &List : MLTAL)
 for (const auto &TemplateArg : List.Args)
-  TemplateArg.Profile(ID, S.Context);
+  S.Context.getCanonicalTemplateArgument(TemplateArg)
+  .Profile(ID, S.Context);
 
   // Note that we have to do this with our own collection, because there are
   // times where a constraint-expression check can cause us to need to evaluate
@@ -638,8 +639,8 @@ bool Sema::CheckConstraintSatisfaction(
   // here.
   llvm::SmallVector FlattenedArgs;
   for (auto List : TemplateArgsLists)
-FlattenedArgs.insert(FlattenedArgs.end(), List.Args.begin(),
- List.Args.end());
+for (const TemplateArgument &Arg : List.Args)
+  FlattenedArgs.emplace_back(Context.getCanonicalTemplateArgument(Arg));
 
   llvm::FoldingSetNodeID ID;
   ConstraintSatisfaction::Profile(ID, Context, Template, FlattenedArgs);
@@ -823,6 +824,8 @@ Sema::SetupConstraintCheckingTemplateArgumentsAndScope(
/*RelativeToPrimary=*/true,
/*Pattern=*/nullptr,
/*ForConstraintInstantiation=*/true);
+  if (TemplateArgs)
+MLTAL.replaceInnermostTemplateArguments(FD, *TemplateArgs, /*Final=*/true);
   if (SetupConstraintScope(FD, TemplateArgs, MLTAL, Scope))
 return std::nullopt;
 
@@ -1476,7 +14

[clang] [libcxx] [clang] Reland: Instantiate concepts with sugared template arguments (PR #101782)

2024-08-04 Thread Matheus Izvekov via cfe-commits

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


  1   2   >