[clang] [clang] constexpr built-in elementwise add_sat function. (PR #119082)

2024-12-08 Thread via cfe-commits

https://github.com/c8ef updated https://github.com/llvm/llvm-project/pull/119082

>From 2af0eb663a106b712a3c9eb2028dc35014884708 Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Sun, 8 Dec 2024 01:11:51 +0800
Subject: [PATCH 1/2] constexpr elementwise add_sat

---
 clang/docs/LanguageExtensions.rst |  3 +-
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/Basic/Builtins.td |  2 +-
 clang/lib/AST/ExprConstant.cpp| 35 +++
 .../test/CodeGen/builtins-elementwise-math.c  |  2 +-
 clang/test/Sema/constant_builtins_vector.cpp  |  8 +
 6 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 6b950d05fb9bf9..40c0a0e5f1161c 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -648,7 +648,8 @@ elementwise to the input.
 Unless specified otherwise operation(±0) = ±0 and operation(±infinity) = 
±infinity
 
 The integer elementwise intrinsics, including 
``__builtin_elementwise_popcount``,
-``__builtin_elementwise_bitreverse``, can be called in a ``constexpr`` context.
+``__builtin_elementwise_bitreverse``, ``__builtin_elementwise_add_sat``, can be
+called in a ``constexpr`` context.
 
 == 
== 
=
  Name   Operation  
   Supported element types
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 59e3a6609123d2..5aeda3ade7573a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -414,6 +414,7 @@ Non-comprehensive list of changes in this release
 - ``__builtin_reduce_or`` and ``__builtin_reduce_xor`` functions can now be 
used in constant expressions.
 - ``__builtin_elementwise_popcount`` function can now be used in constant 
expressions.
 - ``__builtin_elementwise_bitreverse`` function can now be used in constant 
expressions.
+- ``__builtin_elementwise_add_sat`` function can now be used in constant 
expressions.
 
 New Compiler Flags
 --
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index e2c3d3c535571c..1186ece419fdd2 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1450,7 +1450,7 @@ def ElementwiseFma : Builtin {
 
 def ElementwiseAddSat : Builtin {
   let Spellings = ["__builtin_elementwise_add_sat"];
-  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6b5b95aee35522..001773dc28dedc 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11339,6 +11339,31 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
 
 return Success(APValue(ResultElements.data(), ResultElements.size()), E);
   }
+  case Builtin::BI__builtin_elementwise_add_sat: {
+APValue SourceLHS, SourceRHS;
+if (!EvaluateAsRValue(Info, E->getArg(0), SourceLHS) ||
+!EvaluateAsRValue(Info, E->getArg(1), SourceRHS))
+  return false;
+
+QualType DestEltTy = E->getType()->castAs()->getElementType();
+unsigned SourceLen = SourceLHS.getVectorLength();
+SmallVector ResultElements;
+ResultElements.reserve(SourceLen);
+
+for (unsigned EltNum = 0; EltNum < SourceLen; ++EltNum) {
+  APSInt LHS = SourceLHS.getVectorElt(EltNum).getInt();
+  APSInt RHS = SourceRHS.getVectorElt(EltNum).getInt();
+  switch (E->getBuiltinCallee()) {
+  case Builtin::BI__builtin_elementwise_add_sat:
+ResultElements.push_back(APValue(
+APSInt(LHS.isSigned() ? LHS.sadd_sat(RHS) : RHS.uadd_sat(RHS),
+   DestEltTy->isUnsignedIntegerOrEnumerationType(;
+break;
+  }
+}
+
+return Success(APValue(ResultElements.data(), ResultElements.size()), E);
+  }
   }
 }
 
@@ -13204,6 +13229,16 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 return Success(Val.rotr(Amt.urem(Val.getBitWidth())), E);
   }
 
+  case Builtin::BI__builtin_elementwise_add_sat: {
+APSInt LHS, RHS;
+if (!EvaluateInteger(E->getArg(0), LHS, Info) ||
+!EvaluateInteger(E->getArg(1), RHS, Info))
+  return false;
+
+APInt Result = LHS.isSigned() ? LHS.sadd_sat(RHS) : LHS.uadd_sat(RHS);
+return Success(APSInt(Result, !LHS.isSigned()), E);
+  }
+
   case Builtin::BIstrlen:
   case Builtin::BIwcslen:
 // A call to strlen is not a constant expression.
diff --git a/clang/test/CodeGen/builtins-elementwise-math.c 
b/clang/test/CodeGen/builtins-elementwise-math.c
index 82f82dd1ed7944..832691a55e52a1 100644
--- a/clang/test/CodeGen/builtins-elementwis

[clang] [clang] constexpr built-in elementwise add_sat function. (PR #119082)

2024-12-08 Thread via cfe-commits


@@ -414,6 +414,7 @@ Non-comprehensive list of changes in this release
 - ``__builtin_reduce_or`` and ``__builtin_reduce_xor`` functions can now be 
used in constant expressions.
 - ``__builtin_elementwise_popcount`` function can now be used in constant 
expressions.
 - ``__builtin_elementwise_bitreverse`` function can now be used in constant 
expressions.
+- ``__builtin_elementwise_add_sat`` function can now be used in constant 
expressions.

c8ef wrote:

Done.

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


[clang] [clang] Fix cast for injected types in case name lookup for dependent bases (PR #119024)

2024-12-08 Thread Vladislav Belov via cfe-commits

https://github.com/vbe-sc updated 
https://github.com/llvm/llvm-project/pull/119024

>From ce758d5e8cf958edbfffeee8fe4c978011554b53 Mon Sep 17 00:00:00 2001
From: vb-sc 
Date: Fri, 6 Dec 2024 23:06:01 +0300
Subject: [PATCH] [clang][NFC] Fix cast for injected types in case name lookup
 for dependent bases

---
 clang/lib/AST/CXXInheritance.cpp | 12 ++--
 clang/test/CXX/drs/cwg5xx.cpp|  9 +
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp
index 10b8d524ff8978..ee5775837d5355 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -368,8 +368,8 @@ bool CXXRecordDecl::FindBaseClass(const CXXBaseSpecifier 
*Specifier,
   const CXXRecordDecl *BaseRecord) {
   assert(BaseRecord->getCanonicalDecl() == BaseRecord &&
  "User data for FindBaseClass is not canonical!");
-  return Specifier->getType()->castAs()->getDecl()
-->getCanonicalDecl() == BaseRecord;
+  return cast(Specifier->getType()->getAsRecordDecl())
+ ->getCanonicalDecl() == BaseRecord;
 }
 
 bool CXXRecordDecl::FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
@@ -378,8 +378,8 @@ bool CXXRecordDecl::FindVirtualBaseClass(const 
CXXBaseSpecifier *Specifier,
   assert(BaseRecord->getCanonicalDecl() == BaseRecord &&
  "User data for FindBaseClass is not canonical!");
   return Specifier->isVirtual() &&
- Specifier->getType()->castAs()->getDecl()
-->getCanonicalDecl() == BaseRecord;
+ cast(Specifier->getType()->getAsRecordDecl())
+ ->getCanonicalDecl() == BaseRecord;
 }
 
 static bool isOrdinaryMember(const NamedDecl *ND) {
@@ -692,7 +692,7 @@ AddIndirectPrimaryBases(const CXXRecordDecl *RD, ASTContext 
&Context,
"Cannot get indirect primary bases for class with dependent 
bases.");
 
 const CXXRecordDecl *BaseDecl =
-  cast(I.getType()->castAs()->getDecl());
+cast(I.getType()->getAsRecordDecl());
 
 // Only bases with virtual bases participate in computing the
 // indirect primary virtual base classes.
@@ -714,7 +714,7 @@ 
CXXRecordDecl::getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const {
"Cannot get indirect primary bases for class with dependent 
bases.");
 
 const CXXRecordDecl *BaseDecl =
-  cast(I.getType()->castAs()->getDecl());
+cast(I.getType()->getAsRecordDecl());
 
 // Only bases with virtual bases participate in computing the
 // indirect primary virtual base classes.
diff --git a/clang/test/CXX/drs/cwg5xx.cpp b/clang/test/CXX/drs/cwg5xx.cpp
index 91a76fd2adbb6a..9a5a2f49db66b2 100644
--- a/clang/test/CXX/drs/cwg5xx.cpp
+++ b/clang/test/CXX/drs/cwg5xx.cpp
@@ -1209,6 +1209,11 @@ namespace cwg591 { // cwg591: 20
 };
   };
 
+  template  struct M {
+class P;
+int M;
+  };
+
   template struct A::B::C : A {
 M m;
   };
@@ -1224,6 +1229,10 @@ namespace cwg591 { // cwg591: 20
 M m;
   };
 
+  template class M::P : M {
+int foo() { (void) M; }
+  };
+
   template struct A::B::D : A {
 M m;
 // expected-error@-1 {{field has incomplete type 'M' (aka 'void'}}

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


[clang] [clang] Fix cast for injected types in case name lookup for dependent bases (PR #119024)

2024-12-08 Thread Vladislav Belov via cfe-commits


@@ -368,8 +368,8 @@ bool CXXRecordDecl::FindBaseClass(const CXXBaseSpecifier 
*Specifier,
   const CXXRecordDecl *BaseRecord) {
   assert(BaseRecord->getCanonicalDecl() == BaseRecord &&
  "User data for FindBaseClass is not canonical!");
-  return Specifier->getType()->castAs()->getDecl()
-->getCanonicalDecl() == BaseRecord;
+  return (cast(Specifier->getType()->getAsRecordDecl())
+  ->getCanonicalDecl()) == BaseRecord;

vbe-sc wrote:

Fixed.

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


[clang] [Clang] Recurse into parsing when using pack-indexing as a specifier (PR #119123)

2024-12-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Younan Zhang (zyn0217)


Changes

Closes #119072

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/lib/Parse/ParseExpr.cpp (+1-1) 
- (modified) clang/test/Parser/cxx2c-pack-indexing.cpp (+9) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 20bd27ad52f577..57fcca04fc53ca 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -763,6 +763,7 @@ Bug Fixes to C++ Support
 - Fixed a bug where bounds of partially expanded pack indexing expressions 
were checked too early. (#GH116105)
 - Fixed an assertion failure caused by using ``consteval`` in condition in 
consumed analyses. (#GH117385)
 - Fix a crash caused by incorrect argument position in merging deduced 
template arguments. (#GH113659)
+- Fixed a parser crash when using pack indexing as a nested name specifier. 
(#GH119072) 
 - Fixed an assertion failure caused by mangled names with invalid identifiers. 
(#GH112205)
 
 Bug Fixes to AST Handling
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 736484ded8383c..8dd72db8f5b4a2 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1199,7 +1199,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
 // If the token is not annotated, then it might be an expression pack
 // indexing
 if (!TryAnnotateTypeOrScopeToken() &&
-Tok.is(tok::annot_pack_indexing_type))
+Tok.isOneOf(tok::annot_pack_indexing_type, tok::annot_cxxscope))
   return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast,
  isVectorLiteral, NotPrimaryExpression);
   }
diff --git a/clang/test/Parser/cxx2c-pack-indexing.cpp 
b/clang/test/Parser/cxx2c-pack-indexing.cpp
index c279bdd7af8c44..99347a2f8f1571 100644
--- a/clang/test/Parser/cxx2c-pack-indexing.cpp
+++ b/clang/test/Parser/cxx2c-pack-indexing.cpp
@@ -74,3 +74,12 @@ struct SS {
 }
 };
 }
+
+namespace GH119072 {
+
+template
+void foo() {
+  decltype(Ts...[0]::t) value;
+}
+
+}

``




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


[clang] [Clang] Recurse into parsing when using pack-indexing as a specifier (PR #119123)

2024-12-08 Thread Younan Zhang via cfe-commits

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


[clang] [Clang] Recurse into parsing when using pack-indexing as a specifier (PR #119123)

2024-12-08 Thread via cfe-commits

https://github.com/cor3ntin commented:

the commit message could use more details, otherwise LGTM.
Thanks for fixing that

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


[clang] [Clang] Recurse into parsing when using pack-indexing as a specifier (PR #119123)

2024-12-08 Thread via cfe-commits

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


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


[clang] [clang] Fix cast for injected types in case name lookup for dependent bases (PR #119024)

2024-12-08 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

> Can you confirm this is a fix for #118003 ? In which case we do not need 
> changelog entry

Yes, you are right

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


[clang] [clang] constexpr built-in elementwise add_sat function. (PR #119082)

2024-12-08 Thread via cfe-commits


@@ -11339,6 +11339,31 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
 
 return Success(APValue(ResultElements.data(), ResultElements.size()), E);
   }
+  case Builtin::BI__builtin_elementwise_add_sat: {
+APValue SourceLHS, SourceRHS;
+if (!EvaluateAsRValue(Info, E->getArg(0), SourceLHS) ||
+!EvaluateAsRValue(Info, E->getArg(1), SourceRHS))
+  return false;
+
+QualType DestEltTy = E->getType()->castAs()->getElementType();
+unsigned SourceLen = SourceLHS.getVectorLength();
+SmallVector ResultElements;
+ResultElements.reserve(SourceLen);
+
+for (unsigned EltNum = 0; EltNum < SourceLen; ++EltNum) {
+  APSInt LHS = SourceLHS.getVectorElt(EltNum).getInt();
+  APSInt RHS = SourceRHS.getVectorElt(EltNum).getInt();
+  switch (E->getBuiltinCallee()) {
+  case Builtin::BI__builtin_elementwise_add_sat:

c8ef wrote:

`__builtin_elementwise_sub_sat` will be added in a future patch.

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


[clang] [Clang] Recurse into parsing when using pack-indexing as a specifier (PR #119123)

2024-12-08 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 created 
https://github.com/llvm/llvm-project/pull/119123

Closes #119072

>From 7ea2b4c5a9042aeb77982e3f5bb03af36de23c96 Mon Sep 17 00:00:00 2001
From: Younan Zhang 
Date: Sun, 8 Dec 2024 18:17:46 +0800
Subject: [PATCH] [Clang] Recurse into parsing when using pack-indexing as a
 specifier

---
 clang/docs/ReleaseNotes.rst   | 1 +
 clang/lib/Parse/ParseExpr.cpp | 2 +-
 clang/test/Parser/cxx2c-pack-indexing.cpp | 9 +
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 20bd27ad52f577..57fcca04fc53ca 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -763,6 +763,7 @@ Bug Fixes to C++ Support
 - Fixed a bug where bounds of partially expanded pack indexing expressions 
were checked too early. (#GH116105)
 - Fixed an assertion failure caused by using ``consteval`` in condition in 
consumed analyses. (#GH117385)
 - Fix a crash caused by incorrect argument position in merging deduced 
template arguments. (#GH113659)
+- Fixed a parser crash when using pack indexing as a nested name specifier. 
(#GH119072) 
 - Fixed an assertion failure caused by mangled names with invalid identifiers. 
(#GH112205)
 
 Bug Fixes to AST Handling
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 736484ded8383c..8dd72db8f5b4a2 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1199,7 +1199,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
 // If the token is not annotated, then it might be an expression pack
 // indexing
 if (!TryAnnotateTypeOrScopeToken() &&
-Tok.is(tok::annot_pack_indexing_type))
+Tok.isOneOf(tok::annot_pack_indexing_type, tok::annot_cxxscope))
   return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast,
  isVectorLiteral, NotPrimaryExpression);
   }
diff --git a/clang/test/Parser/cxx2c-pack-indexing.cpp 
b/clang/test/Parser/cxx2c-pack-indexing.cpp
index c279bdd7af8c44..99347a2f8f1571 100644
--- a/clang/test/Parser/cxx2c-pack-indexing.cpp
+++ b/clang/test/Parser/cxx2c-pack-indexing.cpp
@@ -74,3 +74,12 @@ struct SS {
 }
 };
 }
+
+namespace GH119072 {
+
+template
+void foo() {
+  decltype(Ts...[0]::t) value;
+}
+
+}

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


[clang] [clang] constexpr built-in elementwise add_sat function. (PR #119082)

2024-12-08 Thread Simon Pilgrim via cfe-commits


@@ -11339,6 +11339,31 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
 
 return Success(APValue(ResultElements.data(), ResultElements.size()), E);
   }
+  case Builtin::BI__builtin_elementwise_add_sat: {
+APValue SourceLHS, SourceRHS;
+if (!EvaluateAsRValue(Info, E->getArg(0), SourceLHS) ||
+!EvaluateAsRValue(Info, E->getArg(1), SourceRHS))
+  return false;
+
+QualType DestEltTy = E->getType()->castAs()->getElementType();
+unsigned SourceLen = SourceLHS.getVectorLength();
+SmallVector ResultElements;
+ResultElements.reserve(SourceLen);
+
+for (unsigned EltNum = 0; EltNum < SourceLen; ++EltNum) {
+  APSInt LHS = SourceLHS.getVectorElt(EltNum).getInt();
+  APSInt RHS = SourceRHS.getVectorElt(EltNum).getInt();
+  switch (E->getBuiltinCallee()) {
+  case Builtin::BI__builtin_elementwise_add_sat:

RKSimon wrote:

It'd be great if you could handle subsat in this patch as well. Same when you 
come to max/min - better to handle the instruction pairs together.

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


[clang] [clang] constexpr built-in elementwise add_sat function. (PR #119082)

2024-12-08 Thread via cfe-commits

https://github.com/c8ef updated https://github.com/llvm/llvm-project/pull/119082

>From 2af0eb663a106b712a3c9eb2028dc35014884708 Mon Sep 17 00:00:00 2001
From: c8ef 
Date: Sun, 8 Dec 2024 01:11:51 +0800
Subject: [PATCH 1/3] constexpr elementwise add_sat

---
 clang/docs/LanguageExtensions.rst |  3 +-
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/Basic/Builtins.td |  2 +-
 clang/lib/AST/ExprConstant.cpp| 35 +++
 .../test/CodeGen/builtins-elementwise-math.c  |  2 +-
 clang/test/Sema/constant_builtins_vector.cpp  |  8 +
 6 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 6b950d05fb9bf9..40c0a0e5f1161c 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -648,7 +648,8 @@ elementwise to the input.
 Unless specified otherwise operation(±0) = ±0 and operation(±infinity) = 
±infinity
 
 The integer elementwise intrinsics, including 
``__builtin_elementwise_popcount``,
-``__builtin_elementwise_bitreverse``, can be called in a ``constexpr`` context.
+``__builtin_elementwise_bitreverse``, ``__builtin_elementwise_add_sat``, can be
+called in a ``constexpr`` context.
 
 == 
== 
=
  Name   Operation  
   Supported element types
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 59e3a6609123d2..5aeda3ade7573a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -414,6 +414,7 @@ Non-comprehensive list of changes in this release
 - ``__builtin_reduce_or`` and ``__builtin_reduce_xor`` functions can now be 
used in constant expressions.
 - ``__builtin_elementwise_popcount`` function can now be used in constant 
expressions.
 - ``__builtin_elementwise_bitreverse`` function can now be used in constant 
expressions.
+- ``__builtin_elementwise_add_sat`` function can now be used in constant 
expressions.
 
 New Compiler Flags
 --
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index e2c3d3c535571c..1186ece419fdd2 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1450,7 +1450,7 @@ def ElementwiseFma : Builtin {
 
 def ElementwiseAddSat : Builtin {
   let Spellings = ["__builtin_elementwise_add_sat"];
-  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6b5b95aee35522..001773dc28dedc 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11339,6 +11339,31 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
 
 return Success(APValue(ResultElements.data(), ResultElements.size()), E);
   }
+  case Builtin::BI__builtin_elementwise_add_sat: {
+APValue SourceLHS, SourceRHS;
+if (!EvaluateAsRValue(Info, E->getArg(0), SourceLHS) ||
+!EvaluateAsRValue(Info, E->getArg(1), SourceRHS))
+  return false;
+
+QualType DestEltTy = E->getType()->castAs()->getElementType();
+unsigned SourceLen = SourceLHS.getVectorLength();
+SmallVector ResultElements;
+ResultElements.reserve(SourceLen);
+
+for (unsigned EltNum = 0; EltNum < SourceLen; ++EltNum) {
+  APSInt LHS = SourceLHS.getVectorElt(EltNum).getInt();
+  APSInt RHS = SourceRHS.getVectorElt(EltNum).getInt();
+  switch (E->getBuiltinCallee()) {
+  case Builtin::BI__builtin_elementwise_add_sat:
+ResultElements.push_back(APValue(
+APSInt(LHS.isSigned() ? LHS.sadd_sat(RHS) : RHS.uadd_sat(RHS),
+   DestEltTy->isUnsignedIntegerOrEnumerationType(;
+break;
+  }
+}
+
+return Success(APValue(ResultElements.data(), ResultElements.size()), E);
+  }
   }
 }
 
@@ -13204,6 +13229,16 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 return Success(Val.rotr(Amt.urem(Val.getBitWidth())), E);
   }
 
+  case Builtin::BI__builtin_elementwise_add_sat: {
+APSInt LHS, RHS;
+if (!EvaluateInteger(E->getArg(0), LHS, Info) ||
+!EvaluateInteger(E->getArg(1), RHS, Info))
+  return false;
+
+APInt Result = LHS.isSigned() ? LHS.sadd_sat(RHS) : LHS.uadd_sat(RHS);
+return Success(APSInt(Result, !LHS.isSigned()), E);
+  }
+
   case Builtin::BIstrlen:
   case Builtin::BIwcslen:
 // A call to strlen is not a constant expression.
diff --git a/clang/test/CodeGen/builtins-elementwise-math.c 
b/clang/test/CodeGen/builtins-elementwise-math.c
index 82f82dd1ed7944..832691a55e52a1 100644
--- a/clang/test/CodeGen/builtins-elementwis

[clang] eeadd01 - [clang-format] Also check ClangFormat.rst is up to date in docs_updated.test

2024-12-08 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2024-12-08T01:15:45-08:00
New Revision: eeadd0128df848eb858ae718984a13fa2c923775

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

LOG: [clang-format] Also check ClangFormat.rst is up to date in 
docs_updated.test

Added: 


Modified: 
clang/docs/tools/dump_format_help.py
clang/test/Format/docs_updated.test

Removed: 




diff  --git a/clang/docs/tools/dump_format_help.py 
b/clang/docs/tools/dump_format_help.py
index a9893b3f91457a..baf90048ee1352 100755
--- a/clang/docs/tools/dump_format_help.py
+++ b/clang/docs/tools/dump_format_help.py
@@ -57,6 +57,7 @@ def validate(text, columns):
 
 p = argparse.ArgumentParser()
 p.add_argument("-d", "--directory", help="directory of clang-format")
+p.add_argument("-o", "--output", help="path of output file")
 opts = p.parse_args()
 
 binary = "clang-format"
@@ -66,10 +67,10 @@ def validate(text, columns):
 help_text = get_help_text()
 validate(help_text, 100)
 
-with open(DOC_FILE) as f:
+with open(DOC_FILE, encoding="utf-8") as f:
 contents = f.read()
 
 contents = substitute(contents, "FORMAT_HELP", help_text)
 
-with open(DOC_FILE, "wb") as output:
+with open(opts.output if opts.output else DOC_FILE, "wb") as output:
 output.write(contents.encode())

diff  --git a/clang/test/Format/docs_updated.test 
b/clang/test/Format/docs_updated.test
index fe2e4f1bd13a1b..56ca4d13eb375c 100644
--- a/clang/test/Format/docs_updated.test
+++ b/clang/test/Format/docs_updated.test
@@ -1,2 +1,5 @@
-// RUN: %python %S/../../docs/tools/dump_format_style.py %t
-// RUN: 
diff  %t %S/../../docs/ClangFormatStyleOptions.rst
+// RUN: %python %S/../../docs/tools/dump_format_style.py %t.style
+// RUN: 
diff  %t.style %S/../../docs/ClangFormatStyleOptions.rst
+
+// RUN: %python %S/../../docs/tools/dump_format_help.py -o %t.help
+// RUN: 
diff  %t.help %S/../../docs/ClangFormat.rst



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


[clang-tools-extra] fix parse windows driver and wsl path (PR #119085)

2024-12-08 Thread via cfe-commits

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


[clang] Reland [Clang] skip default argument instantiation for non-defining friend declarations to meet [dcl.fct.default] p4 (PR #115487)

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

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

>From 5e24d212f797b5fa1b6da1526c807046373d3c21 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 8 Nov 2024 16:13:17 +0200
Subject: [PATCH 1/6] [Clang] skip default argument instantiation for
 non-defining friend declarations to meet [dcl.fct.default] p4

---
 clang/docs/ReleaseNotes.rst   |  2 +
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  4 ++
 clang/test/CXX/temp/temp.res/p4.cpp   | 43 +++
 3 files changed, 49 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d0c43ff11f7bae..e8cf6fc50a1290 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -636,6 +636,8 @@ Bug Fixes to C++ Support
   an implicitly instantiated class template specialization. (#GH51051)
 - Fixed an assertion failure caused by invalid enum forward declarations. 
(#GH112208)
 - Name independent data members were not correctly initialized from default 
member initializers. (#GH114069)
+- Fixed an assertion failure caused by invalid default argument substitutions 
in non-defining
+  friend declarations. (#GH113324).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 5a001843e2ba46..200519c71c57ab 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4694,6 +4694,10 @@ bool Sema::InstantiateDefaultArgument(SourceLocation 
CallLoc, FunctionDecl *FD,
   ParmVarDecl *Param) {
   assert(Param->hasUninstantiatedDefaultArg());
 
+  if (FD->getFriendObjectKind() != Decl::FOK_None &&
+  !FD->getTemplateInstantiationPattern())
+return true;
+
   // Instantiate the expression.
   //
   // FIXME: Pass in a correct Pattern argument, otherwise
diff --git a/clang/test/CXX/temp/temp.res/p4.cpp 
b/clang/test/CXX/temp/temp.res/p4.cpp
index f54d8649f5da88..cf6c45b4c351c5 100644
--- a/clang/test/CXX/temp/temp.res/p4.cpp
+++ b/clang/test/CXX/temp/temp.res/p4.cpp
@@ -185,3 +185,46 @@ template struct S {
   friend void X::f(T::type);
 };
 }
+
+namespace GH113324 {
+template  struct S1 {
+  friend void f1(S1, int = 0); // expected-error {{friend declaration 
specifying a default argument must be a definition}}
+  friend void f2(S1 a, S1 = decltype(a){}); // expected-error {{friend 
declaration specifying a default argument must be a definition}}
+};
+
+template  using alias = int;
+template  struct S2 {
+  // FIXME: We miss diagnosing the default argument instantiation failure
+  // (forming reference to void)
+  friend void f3(S2, int a = alias(1)); // expected-error {{friend 
declaration specifying a default argument must be a definition}}
+};
+
+struct S3 {
+  friend void f4(S3, int = 42) { }
+};
+
+template  using __enable_if_t = int;
+template  struct S4 {
+  static const int value = v;
+};
+struct S5 {
+  template <__enable_if_t::value, int> = 0>
+  S5(const char *);
+};
+struct S6 {
+  template 
+  friend void f5(int, S6, a, b, S5 = "") { }
+};
+
+void test() {
+  f1(S1<>{});
+  f2(S1<>{});
+  f3(S2());
+
+  S3 s3;
+  f4(s3);
+
+  S6 s6;
+  auto result = f5(0, s6, [] {}, [] {}); // expected-error {{variable has 
incomplete type 'void}}
+}
+} // namespace GH113324

>From 3ad3b6c5f35730be32f4f6ba2dc8d19f53be0442 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 8 Nov 2024 16:53:39 +0200
Subject: [PATCH 2/6] update comments

---
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 200519c71c57ab..0bbab95001ad8e 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4694,6 +4694,13 @@ bool Sema::InstantiateDefaultArgument(SourceLocation 
CallLoc, FunctionDecl *FD,
   ParmVarDecl *Param) {
   assert(Param->hasUninstantiatedDefaultArg());
 
+  // FIXME: We don't track member specialization info for non-defining
+  // friend declarations, so we will not be able to later find the function
+  // pattern. As a workaround, don't instantiate the default argument in this
+  // case. This is correct per wording and only an error recovery issue, as per
+  // [dcl.fct.default]p4:
+  //   if a friend declaration D specifies a default argument expression,
+  //   that declaration shall be a definition.
   if (FD->getFriendObjectKind() != Decl::FOK_None &&
   !FD->getTemplateInstantiationPattern())
 return true;

>From 09215dea0212368ef54956d8464788cc4b88cc02 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 21 Nov 2024 16:56:11 +0200
Subject: [PATCH 3/6] move cases that cause code generation failures to the
 appropriate folder

---
 clang/test/CXX/temp/temp.res/p4.cpp | 23

[clang] [clang-tools-extra] [clang] Compute accurate begin location for CallExpr with explicit object parameter (PR #117841)

2024-12-08 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

> I didn't check if any tests fail but here's a version where `CallExpr` saves 
> its `BeginLoc` explicitly: 
> http://llvm-compile-time-tracker.com/compare.php?from=416e4cd332c7421b187844ac9aaf6fe28b575a7d&to=0b6e36fe460409aa59958b79766b4f64a31c97e6&stat=instructions:u

Yeah, this is another alternative, though I wonder if the memory tradeoff it 
makes (increasing the size of `CallExpr` by 4 bytes) is worth it.

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


[clang] [clang][bytecode] Pass (float) BitWidth to DoBitCast (PR #119119)

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

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

>From efb64b914ab2c3cb5c40f1cdf93c34f7c976a554 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 8 Dec 2024 08:00:14 +0100
Subject: [PATCH] [clang][bytecode] Pass (float) BitWidth to DoBitCast

In certain cases (i.e. long double on x86), the bit with we get from
the floating point semantics is different than the type size we
compute for the BitCast instruction. Pass this along to DoBitCast,
so in there we can check only the relevant bits for being initialized.

This also fixes a weirdness we still had in DoBitCast.
---
 clang/lib/AST/ByteCode/BitcastBuffer.h|  1 +
 clang/lib/AST/ByteCode/Interp.h   | 23 ++-
 .../lib/AST/ByteCode/InterpBuiltinBitCast.cpp | 19 +--
 clang/lib/AST/ByteCode/InterpBuiltinBitCast.h |  4 +++-
 .../ByteCode/builtin-bit-cast-long-double.cpp |  7 ++
 5 files changed, 35 insertions(+), 19 deletions(-)

diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.h 
b/clang/lib/AST/ByteCode/BitcastBuffer.h
index 2a0d8a0cd9a81f..b1b6b9e5173a7c 100644
--- a/clang/lib/AST/ByteCode/BitcastBuffer.h
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.h
@@ -45,6 +45,7 @@ struct Bits {
   bool operator>=(Bits Other) const { return N >= Other.N; }
   bool operator<=(Bits Other) const { return N <= Other.N; }
   bool operator==(Bits Other) const { return N == Other.N; }
+  bool operator!=(Bits Other) const { return N != Other.N; }
 };
 
 /// A quantity in bytes.
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index c5c2a5ef19cc4d..cdf05e36304acb 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -14,6 +14,7 @@
 #define LLVM_CLANG_AST_INTERP_INTERP_H
 
 #include "../ExprConstShared.h"
+#include "BitcastBuffer.h"
 #include "Boolean.h"
 #include "DynamicAllocator.h"
 #include "FixedPoint.h"
@@ -3050,7 +3051,16 @@ inline bool BitCast(InterpState &S, CodePtr OpPC, bool 
TargetIsUCharOrByte,
   llvm::SmallVector Buff(BuffSize);
   bool HasIndeterminateBits = false;
 
-  if (!DoBitCast(S, OpPC, FromPtr, Buff.data(), BuffSize, 
HasIndeterminateBits))
+  Bits FullBitWidth(ResultBitWidth);
+  Bits BitWidth = FullBitWidth;
+
+  if constexpr (std::is_same_v) {
+assert(Sem);
+BitWidth = Bits(llvm::APFloatBase::getSizeInBits(*Sem));
+  }
+
+  if (!DoBitCast(S, OpPC, FromPtr, Buff.data(), BitWidth, FullBitWidth,
+ HasIndeterminateBits))
 return false;
 
   if (!CheckBitCast(S, OpPC, HasIndeterminateBits, TargetIsUCharOrByte))
@@ -3058,16 +3068,7 @@ inline bool BitCast(InterpState &S, CodePtr OpPC, bool 
TargetIsUCharOrByte,
 
   if constexpr (std::is_same_v) {
 assert(Sem);
-ptrdiff_t Offset = 0;
-
-if (llvm::sys::IsBigEndianHost) {
-  unsigned NumBits = llvm::APFloatBase::getSizeInBits(*Sem);
-  assert(NumBits % 8 == 0);
-  assert(NumBits <= ResultBitWidth);
-  Offset = (ResultBitWidth - NumBits) / 8;
-}
-
-S.Stk.push(T::bitcastFromMemory(Buff.data() + Offset, *Sem));
+S.Stk.push(T::bitcastFromMemory(Buff.data(), *Sem));
   } else {
 assert(!Sem);
 S.Stk.push(T::bitcastFromMemory(Buff.data(), ResultBitWidth));
diff --git a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
index e12babc162ce3c..c9cd113287557b 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
@@ -278,44 +278,49 @@ static bool readPointerToBuffer(const Context &Ctx, const 
Pointer &FromPtr,
   if (llvm::sys::IsBigEndianHost)
 swapBytes(Buff.get(), NumBits.roundToBytes());
 
+  Buffer.markInitialized(BitOffset, NumBits);
 } else {
   BITCAST_TYPE_SWITCH(T, { P.deref().bitcastToMemory(Buff.get()); 
});
 
   if (llvm::sys::IsBigEndianHost)
 swapBytes(Buff.get(), FullBitWidth.roundToBytes());
+  Buffer.markInitialized(BitOffset, BitWidth);
 }
 
 Buffer.pushData(Buff.get(), BitOffset, BitWidth, TargetEndianness);
-Buffer.markInitialized(BitOffset, BitWidth);
 return true;
   });
 }
 
 bool clang::interp::DoBitCast(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
-  std::byte *Buff, size_t BuffSize,
+  std::byte *Buff, Bits BitWidth, Bits 
FullBitWidth,
   bool &HasIndeterminateBits) {
   assert(Ptr.isLive());
   assert(Ptr.isBlockPointer());
   assert(Buff);
+  assert(BitWidth <= FullBitWidth);
+  assert(FullBitWidth.isFullByte());
+  assert(BitWidth.isFullByte());
 
-  Bits BitSize = Bytes(BuffSize).toBits();
-  BitcastBuffer Buffer(BitSize);
+  BitcastBuffer Buffer(FullBitWidth);
+  size_t BuffSize = FullBitWidth.roundToBytes();
   if (!CheckBitcastType(S, OpPC, Ptr.getType(), /*IsToType=*/false))
 return false;
 
   bool Success = readPointerToBuffer(S.getContext

[libunwind] [libunwind][Haiku] Improve support (PR #115462)

2024-12-08 Thread Brad Smith via cfe-commits
=?utf-8?q?J=C3=A9r=C3=B4me?= Duval ,
=?utf-8?q?J=C3=A9r=C3=B4me?= Duval 
Message-ID:
In-Reply-To: 


brad0 wrote:

@X547 Please look at adding the RISCV64 support.

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


[clang] [clang][bytecode] Pass (float) BitWidth to DoBitCast (PR #119119)

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

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

>From 3f041d0338c51d3c279f004220b575c913dd1442 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 8 Dec 2024 08:00:14 +0100
Subject: [PATCH] [clang][bytecode] Pass (float) BitWidth to DoBitCast

In certain cases (i.e. long double on x86), the bit with we get from
the floating point semantics is different than the type size we
compute for the BitCast instruction. Pass this along to DoBitCast,
so in there we can check only the relevant bits for being initialized.

This also fixes a weirdness we still had in DoBitCast.
---
 clang/lib/AST/ByteCode/BitcastBuffer.h|  1 +
 clang/lib/AST/ByteCode/Interp.h   | 23 ++-
 .../lib/AST/ByteCode/InterpBuiltinBitCast.cpp | 19 +--
 clang/lib/AST/ByteCode/InterpBuiltinBitCast.h |  4 +++-
 .../ByteCode/builtin-bit-cast-long-double.cpp | 19 +++
 5 files changed, 42 insertions(+), 24 deletions(-)

diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.h 
b/clang/lib/AST/ByteCode/BitcastBuffer.h
index 2a0d8a0cd9a81f..b1b6b9e5173a7c 100644
--- a/clang/lib/AST/ByteCode/BitcastBuffer.h
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.h
@@ -45,6 +45,7 @@ struct Bits {
   bool operator>=(Bits Other) const { return N >= Other.N; }
   bool operator<=(Bits Other) const { return N <= Other.N; }
   bool operator==(Bits Other) const { return N == Other.N; }
+  bool operator!=(Bits Other) const { return N != Other.N; }
 };
 
 /// A quantity in bytes.
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index c5c2a5ef19cc4d..cdf05e36304acb 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -14,6 +14,7 @@
 #define LLVM_CLANG_AST_INTERP_INTERP_H
 
 #include "../ExprConstShared.h"
+#include "BitcastBuffer.h"
 #include "Boolean.h"
 #include "DynamicAllocator.h"
 #include "FixedPoint.h"
@@ -3050,7 +3051,16 @@ inline bool BitCast(InterpState &S, CodePtr OpPC, bool 
TargetIsUCharOrByte,
   llvm::SmallVector Buff(BuffSize);
   bool HasIndeterminateBits = false;
 
-  if (!DoBitCast(S, OpPC, FromPtr, Buff.data(), BuffSize, 
HasIndeterminateBits))
+  Bits FullBitWidth(ResultBitWidth);
+  Bits BitWidth = FullBitWidth;
+
+  if constexpr (std::is_same_v) {
+assert(Sem);
+BitWidth = Bits(llvm::APFloatBase::getSizeInBits(*Sem));
+  }
+
+  if (!DoBitCast(S, OpPC, FromPtr, Buff.data(), BitWidth, FullBitWidth,
+ HasIndeterminateBits))
 return false;
 
   if (!CheckBitCast(S, OpPC, HasIndeterminateBits, TargetIsUCharOrByte))
@@ -3058,16 +3068,7 @@ inline bool BitCast(InterpState &S, CodePtr OpPC, bool 
TargetIsUCharOrByte,
 
   if constexpr (std::is_same_v) {
 assert(Sem);
-ptrdiff_t Offset = 0;
-
-if (llvm::sys::IsBigEndianHost) {
-  unsigned NumBits = llvm::APFloatBase::getSizeInBits(*Sem);
-  assert(NumBits % 8 == 0);
-  assert(NumBits <= ResultBitWidth);
-  Offset = (ResultBitWidth - NumBits) / 8;
-}
-
-S.Stk.push(T::bitcastFromMemory(Buff.data() + Offset, *Sem));
+S.Stk.push(T::bitcastFromMemory(Buff.data(), *Sem));
   } else {
 assert(!Sem);
 S.Stk.push(T::bitcastFromMemory(Buff.data(), ResultBitWidth));
diff --git a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
index e12babc162ce3c..c9cd113287557b 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
@@ -278,44 +278,49 @@ static bool readPointerToBuffer(const Context &Ctx, const 
Pointer &FromPtr,
   if (llvm::sys::IsBigEndianHost)
 swapBytes(Buff.get(), NumBits.roundToBytes());
 
+  Buffer.markInitialized(BitOffset, NumBits);
 } else {
   BITCAST_TYPE_SWITCH(T, { P.deref().bitcastToMemory(Buff.get()); 
});
 
   if (llvm::sys::IsBigEndianHost)
 swapBytes(Buff.get(), FullBitWidth.roundToBytes());
+  Buffer.markInitialized(BitOffset, BitWidth);
 }
 
 Buffer.pushData(Buff.get(), BitOffset, BitWidth, TargetEndianness);
-Buffer.markInitialized(BitOffset, BitWidth);
 return true;
   });
 }
 
 bool clang::interp::DoBitCast(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
-  std::byte *Buff, size_t BuffSize,
+  std::byte *Buff, Bits BitWidth, Bits 
FullBitWidth,
   bool &HasIndeterminateBits) {
   assert(Ptr.isLive());
   assert(Ptr.isBlockPointer());
   assert(Buff);
+  assert(BitWidth <= FullBitWidth);
+  assert(FullBitWidth.isFullByte());
+  assert(BitWidth.isFullByte());
 
-  Bits BitSize = Bytes(BuffSize).toBits();
-  BitcastBuffer Buffer(BitSize);
+  BitcastBuffer Buffer(FullBitWidth);
+  size_t BuffSize = FullBitWidth.roundToBytes();
   if (!CheckBitcastType(S, OpPC, Ptr.getType(), /*IsToType=*/false))
 return false;
 
   bool Success = readPointerToBuffer(S.g

[clang] [clang] constexpr built-in elementwise add_sat function. (PR #119082)

2024-12-08 Thread via cfe-commits


@@ -414,6 +414,7 @@ Non-comprehensive list of changes in this release
 - ``__builtin_reduce_or`` and ``__builtin_reduce_xor`` functions can now be 
used in constant expressions.
 - ``__builtin_elementwise_popcount`` function can now be used in constant 
expressions.
 - ``__builtin_elementwise_bitreverse`` function can now be used in constant 
expressions.
+- ``__builtin_elementwise_add_sat`` function can now be used in constant 
expressions.

cor3ntin wrote:

Can we merge all of these?
"The following builtins can now be used in constant expressions < nested 
bulleted list>"

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


[clang] [clang] constexpr built-in elementwise add_sat function. (PR #119082)

2024-12-08 Thread via cfe-commits


@@ -11339,6 +11339,31 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
 
 return Success(APValue(ResultElements.data(), ResultElements.size()), E);
   }
+  case Builtin::BI__builtin_elementwise_add_sat: {
+APValue SourceLHS, SourceRHS;
+if (!EvaluateAsRValue(Info, E->getArg(0), SourceLHS) ||
+!EvaluateAsRValue(Info, E->getArg(1), SourceRHS))
+  return false;
+
+QualType DestEltTy = E->getType()->castAs()->getElementType();
+unsigned SourceLen = SourceLHS.getVectorLength();
+SmallVector ResultElements;
+ResultElements.reserve(SourceLen);
+
+for (unsigned EltNum = 0; EltNum < SourceLen; ++EltNum) {
+  APSInt LHS = SourceLHS.getVectorElt(EltNum).getInt();
+  APSInt RHS = SourceRHS.getVectorElt(EltNum).getInt();
+  switch (E->getBuiltinCallee()) {
+  case Builtin::BI__builtin_elementwise_add_sat:

cor3ntin wrote:

Can that be anything else here? Shouldn't we just assert or remove the test 
entirely? 

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


[clang] [clang][bytecode] Pass (float) BitWidth to DoBitCast (PR #119119)

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

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


[clang] 1fbbf4c - [clang][bytecode] Pass (float) BitWidth to DoBitCast (#119119)

2024-12-08 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-12-08T18:54:08+01:00
New Revision: 1fbbf4c418bc4945839a70fe2849cbe6fbcc3d66

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

LOG: [clang][bytecode] Pass (float) BitWidth to DoBitCast (#119119)

In certain cases (i.e. long double on x86), the bit with we get from the
floating point semantics is different than the type size we compute for
the BitCast instruction. Pass this along to DoBitCast, so in there we
can check only the relevant bits for being initialized.

This also fixes a weirdness we still had in DoBitCast.

Added: 


Modified: 
clang/lib/AST/ByteCode/BitcastBuffer.h
clang/lib/AST/ByteCode/Interp.h
clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
clang/lib/AST/ByteCode/InterpBuiltinBitCast.h
clang/test/AST/ByteCode/builtin-bit-cast-long-double.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/BitcastBuffer.h 
b/clang/lib/AST/ByteCode/BitcastBuffer.h
index 2a0d8a0cd9a81f..b1b6b9e5173a7c 100644
--- a/clang/lib/AST/ByteCode/BitcastBuffer.h
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.h
@@ -45,6 +45,7 @@ struct Bits {
   bool operator>=(Bits Other) const { return N >= Other.N; }
   bool operator<=(Bits Other) const { return N <= Other.N; }
   bool operator==(Bits Other) const { return N == Other.N; }
+  bool operator!=(Bits Other) const { return N != Other.N; }
 };
 
 /// A quantity in bytes.

diff  --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index c5c2a5ef19cc4d..cdf05e36304acb 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -14,6 +14,7 @@
 #define LLVM_CLANG_AST_INTERP_INTERP_H
 
 #include "../ExprConstShared.h"
+#include "BitcastBuffer.h"
 #include "Boolean.h"
 #include "DynamicAllocator.h"
 #include "FixedPoint.h"
@@ -3050,7 +3051,16 @@ inline bool BitCast(InterpState &S, CodePtr OpPC, bool 
TargetIsUCharOrByte,
   llvm::SmallVector Buff(BuffSize);
   bool HasIndeterminateBits = false;
 
-  if (!DoBitCast(S, OpPC, FromPtr, Buff.data(), BuffSize, 
HasIndeterminateBits))
+  Bits FullBitWidth(ResultBitWidth);
+  Bits BitWidth = FullBitWidth;
+
+  if constexpr (std::is_same_v) {
+assert(Sem);
+BitWidth = Bits(llvm::APFloatBase::getSizeInBits(*Sem));
+  }
+
+  if (!DoBitCast(S, OpPC, FromPtr, Buff.data(), BitWidth, FullBitWidth,
+ HasIndeterminateBits))
 return false;
 
   if (!CheckBitCast(S, OpPC, HasIndeterminateBits, TargetIsUCharOrByte))
@@ -3058,16 +3068,7 @@ inline bool BitCast(InterpState &S, CodePtr OpPC, bool 
TargetIsUCharOrByte,
 
   if constexpr (std::is_same_v) {
 assert(Sem);
-ptr
diff _t Offset = 0;
-
-if (llvm::sys::IsBigEndianHost) {
-  unsigned NumBits = llvm::APFloatBase::getSizeInBits(*Sem);
-  assert(NumBits % 8 == 0);
-  assert(NumBits <= ResultBitWidth);
-  Offset = (ResultBitWidth - NumBits) / 8;
-}
-
-S.Stk.push(T::bitcastFromMemory(Buff.data() + Offset, *Sem));
+S.Stk.push(T::bitcastFromMemory(Buff.data(), *Sem));
   } else {
 assert(!Sem);
 S.Stk.push(T::bitcastFromMemory(Buff.data(), ResultBitWidth));

diff  --git a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
index e12babc162ce3c..c9cd113287557b 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
@@ -278,44 +278,49 @@ static bool readPointerToBuffer(const Context &Ctx, const 
Pointer &FromPtr,
   if (llvm::sys::IsBigEndianHost)
 swapBytes(Buff.get(), NumBits.roundToBytes());
 
+  Buffer.markInitialized(BitOffset, NumBits);
 } else {
   BITCAST_TYPE_SWITCH(T, { P.deref().bitcastToMemory(Buff.get()); 
});
 
   if (llvm::sys::IsBigEndianHost)
 swapBytes(Buff.get(), FullBitWidth.roundToBytes());
+  Buffer.markInitialized(BitOffset, BitWidth);
 }
 
 Buffer.pushData(Buff.get(), BitOffset, BitWidth, TargetEndianness);
-Buffer.markInitialized(BitOffset, BitWidth);
 return true;
   });
 }
 
 bool clang::interp::DoBitCast(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
-  std::byte *Buff, size_t BuffSize,
+  std::byte *Buff, Bits BitWidth, Bits 
FullBitWidth,
   bool &HasIndeterminateBits) {
   assert(Ptr.isLive());
   assert(Ptr.isBlockPointer());
   assert(Buff);
+  assert(BitWidth <= FullBitWidth);
+  assert(FullBitWidth.isFullByte());
+  assert(BitWidth.isFullByte());
 
-  Bits BitSize = Bytes(BuffSize).toBits();
-  BitcastBuffer Buffer(BitSize);
+  BitcastBuffer Buffer(FullBitWidth);
+  size_t BuffSize = FullBitWidth.roundToBytes();
   if (!CheckBitcastType(S, OpPC, Ptr.getType(), /*IsToType=*/false))
  

[clang] [Clang] Change placeholders from `undef` to `poison` (PR #119141)

2024-12-08 Thread Pedro Lobo via cfe-commits

https://github.com/pedroclobo created 
https://github.com/llvm/llvm-project/pull/119141

- Use `poison `instead of `undef` as a phi operand from an unreachable block.
- Call `@llvm.vector.insert` with a `poison` subvec when performing a `bitcast` 
from a fixed vector to a scalable vector.

>From c275e549ecf6159bdebbfa58d377d3f1971cdf6a Mon Sep 17 00:00:00 2001
From: Pedro Lobo 
Date: Sun, 8 Dec 2024 18:34:14 +
Subject: [PATCH] [Clang] Change placeholders from `undef` to `poison`

- Use `poison `instead of `undef` as a phi operand from an unreachable
  block.
- Call `@llvm.vector.insert` with a `poison` subvec when performing a
  `bitcast` from a fixed vector to a scalable vector.
---
 clang/lib/CodeGen/CGCall.cpp  |  2 +-
 clang/lib/CodeGen/CGExprScalar.cpp|  4 ++--
 ...-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c |  4 ++--
 .../RISCV/attr-rvv-vector-bits-bitcast.c  | 18 +++---
 .../CodeGen/RISCV/attr-rvv-vector-bits-cast.c |  2 +-
 .../RISCV/attr-rvv-vector-bits-codegen.c  | 14 +--
 .../RISCV/attr-rvv-vector-bits-globals.c  | 12 +-
 .../attr-arm-sve-vector-bits-bitcast.c| 24 +--
 .../CodeGen/attr-arm-sve-vector-bits-cast.c   |  2 +-
 .../attr-arm-sve-vector-bits-codegen.c| 12 +-
 .../attr-arm-sve-vector-bits-globals.c| 12 +-
 clang/test/CodeGenObjC/arc-ternary-op.m   |  2 +-
 clang/test/CodeGenObjCXX/arc.mm   |  2 +-
 13 files changed, 55 insertions(+), 55 deletions(-)

diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 3cefc9da66ddb8..50b9dfbbab083a 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4379,7 +4379,7 @@ static void emitWritebackArg(CodeGenFunction &CGF, 
CallArgList &args,
   llvm::PHINode *phiToUse = CGF.Builder.CreatePHI(valueToUse->getType(), 2,
   "icr.to-use");
   phiToUse->addIncoming(valueToUse, copyBB);
-  phiToUse->addIncoming(llvm::UndefValue::get(valueToUse->getType()),
+  phiToUse->addIncoming(llvm::PoisonValue::get(valueToUse->getType()),
 originBB);
   valueToUse = phiToUse;
 }
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index bbf68a4c66192a..4b71bd730ce12c 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2370,10 +2370,10 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
   ScalableDstTy->getElementCount().getKnownMinValue() / 8);
 }
 if (FixedSrcTy->getElementType() == ScalableDstTy->getElementType()) {
-  llvm::Value *UndefVec = llvm::UndefValue::get(ScalableDstTy);
+  llvm::Value *PoisonVec = llvm::PoisonValue::get(ScalableDstTy);
   llvm::Value *Zero = llvm::Constant::getNullValue(CGF.CGM.Int64Ty);
   llvm::Value *Result = Builder.CreateInsertVector(
-  ScalableDstTy, UndefVec, Src, Zero, "cast.scalable");
+  ScalableDstTy, PoisonVec, Src, Zero, "cast.scalable");
   if (Result->getType() != DstTy)
 Result = Builder.CreateBitCast(Result, DstTy);
   return Result;
diff --git 
a/clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c 
b/clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c
index 54e90223a31de0..28d69d52c9ae73 100644
--- a/clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c
+++ b/clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c
@@ -53,7 +53,7 @@ typedef int8_t vec_int8 __attribute__((vector_size(N / 8)));
 // CHECK128-LABEL: define{{.*}} <16 x i8> @f2(<16 x i8> noundef %x)
 // CHECK128-NEXT:  entry:
 // CHECK128-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.ptrue.nxv16i1(i32 31)
-// CHECK128-NEXT:[[CASTSCALABLESVE:%.*]] = tail call  
@llvm.vector.insert.nxv16i8.v16i8( undef, <16 x i8> 
[[X:%.*]], i64 0)
+// CHECK128-NEXT:[[CASTSCALABLESVE:%.*]] = tail call  
@llvm.vector.insert.nxv16i8.v16i8( poison, <16 x i8> 
[[X:%.*]], i64 0)
 // CHECK128-NEXT:[[TMP1:%.*]] = tail call  
@llvm.aarch64.sve.asrd.nxv16i8( [[TMP0]],  
[[CASTSCALABLESVE]], i32 1)
 // CHECK128-NEXT:[[CASTFIXEDSVE:%.*]] = tail call <16 x i8> 
@llvm.vector.extract.v16i8.nxv16i8( [[TMP1]], i64 0)
 // CHECK128-NEXT:ret <16 x i8> [[CASTFIXEDSVE]]
@@ -63,7 +63,7 @@ typedef int8_t vec_int8 __attribute__((vector_size(N / 8)));
 // CHECK-NEXT: entry:
 // CHECK-NEXT:   [[X:%.*]] = load <[[#div(VBITS,8)]] x i8>, ptr [[TMP0:%.*]], 
align 16, [[TBAA6:!tbaa !.*]]
 // CHECK-NEXT:   [[TMP1:%.*]] = tail call  
@llvm.aarch64.sve.ptrue.nxv16i1(i32 31)
-// CHECK-NEXT:   [[CASTSCALABLESVE:%.*]] = tail call  
@llvm.vector.insert.nxv16i8.v[[#div(VBITS,8)]]i8( undef, 
<[[#div(VBITS,8)]] x i8> [[X]], i64 0)
+// CHECK-NEXT:   [[CASTSCALABLESVE:%.*]] = tail call  
@llvm.vector.insert.nxv16i8.v[[#div(VBITS,8)]]i8( poiso

[clang] [Clang] Change placeholders from `undef` to `poison` (PR #119141)

2024-12-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Pedro Lobo (pedroclobo)


Changes

- Use `poison `instead of `undef` as a phi operand from an unreachable block.
- Call `@llvm.vector.insert` with a `poison` subvec when performing a 
`bitcast` from a fixed vector to a scalable vector.

---

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


13 Files Affected:

- (modified) clang/lib/CodeGen/CGCall.cpp (+1-1) 
- (modified) clang/lib/CodeGen/CGExprScalar.cpp (+2-2) 
- (modified) 
clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c (+2-2) 
- (modified) clang/test/CodeGen/RISCV/attr-rvv-vector-bits-bitcast.c (+9-9) 
- (modified) clang/test/CodeGen/RISCV/attr-rvv-vector-bits-cast.c (+1-1) 
- (modified) clang/test/CodeGen/RISCV/attr-rvv-vector-bits-codegen.c (+7-7) 
- (modified) clang/test/CodeGen/RISCV/attr-rvv-vector-bits-globals.c (+6-6) 
- (modified) clang/test/CodeGen/attr-arm-sve-vector-bits-bitcast.c (+12-12) 
- (modified) clang/test/CodeGen/attr-arm-sve-vector-bits-cast.c (+1-1) 
- (modified) clang/test/CodeGen/attr-arm-sve-vector-bits-codegen.c (+6-6) 
- (modified) clang/test/CodeGen/attr-arm-sve-vector-bits-globals.c (+6-6) 
- (modified) clang/test/CodeGenObjC/arc-ternary-op.m (+1-1) 
- (modified) clang/test/CodeGenObjCXX/arc.mm (+1-1) 


``diff
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 3cefc9da66ddb8..50b9dfbbab083a 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4379,7 +4379,7 @@ static void emitWritebackArg(CodeGenFunction &CGF, 
CallArgList &args,
   llvm::PHINode *phiToUse = CGF.Builder.CreatePHI(valueToUse->getType(), 2,
   "icr.to-use");
   phiToUse->addIncoming(valueToUse, copyBB);
-  phiToUse->addIncoming(llvm::UndefValue::get(valueToUse->getType()),
+  phiToUse->addIncoming(llvm::PoisonValue::get(valueToUse->getType()),
 originBB);
   valueToUse = phiToUse;
 }
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index bbf68a4c66192a..4b71bd730ce12c 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2370,10 +2370,10 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
   ScalableDstTy->getElementCount().getKnownMinValue() / 8);
 }
 if (FixedSrcTy->getElementType() == ScalableDstTy->getElementType()) {
-  llvm::Value *UndefVec = llvm::UndefValue::get(ScalableDstTy);
+  llvm::Value *PoisonVec = llvm::PoisonValue::get(ScalableDstTy);
   llvm::Value *Zero = llvm::Constant::getNullValue(CGF.CGM.Int64Ty);
   llvm::Value *Result = Builder.CreateInsertVector(
-  ScalableDstTy, UndefVec, Src, Zero, "cast.scalable");
+  ScalableDstTy, PoisonVec, Src, Zero, "cast.scalable");
   if (Result->getType() != DstTy)
 Result = Builder.CreateBitCast(Result, DstTy);
   return Result;
diff --git 
a/clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c 
b/clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c
index 54e90223a31de0..28d69d52c9ae73 100644
--- a/clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c
+++ b/clang/test/CodeGen/AArch64/sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c
@@ -53,7 +53,7 @@ typedef int8_t vec_int8 __attribute__((vector_size(N / 8)));
 // CHECK128-LABEL: define{{.*}} <16 x i8> @f2(<16 x i8> noundef %x)
 // CHECK128-NEXT:  entry:
 // CHECK128-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.ptrue.nxv16i1(i32 31)
-// CHECK128-NEXT:[[CASTSCALABLESVE:%.*]] = tail call  
@llvm.vector.insert.nxv16i8.v16i8( undef, <16 x i8> 
[[X:%.*]], i64 0)
+// CHECK128-NEXT:[[CASTSCALABLESVE:%.*]] = tail call  
@llvm.vector.insert.nxv16i8.v16i8( poison, <16 x i8> 
[[X:%.*]], i64 0)
 // CHECK128-NEXT:[[TMP1:%.*]] = tail call  
@llvm.aarch64.sve.asrd.nxv16i8( [[TMP0]],  
[[CASTSCALABLESVE]], i32 1)
 // CHECK128-NEXT:[[CASTFIXEDSVE:%.*]] = tail call <16 x i8> 
@llvm.vector.extract.v16i8.nxv16i8( [[TMP1]], i64 0)
 // CHECK128-NEXT:ret <16 x i8> [[CASTFIXEDSVE]]
@@ -63,7 +63,7 @@ typedef int8_t vec_int8 __attribute__((vector_size(N / 8)));
 // CHECK-NEXT: entry:
 // CHECK-NEXT:   [[X:%.*]] = load <[[#div(VBITS,8)]] x i8>, ptr [[TMP0:%.*]], 
align 16, [[TBAA6:!tbaa !.*]]
 // CHECK-NEXT:   [[TMP1:%.*]] = tail call  
@llvm.aarch64.sve.ptrue.nxv16i1(i32 31)
-// CHECK-NEXT:   [[CASTSCALABLESVE:%.*]] = tail call  
@llvm.vector.insert.nxv16i8.v[[#div(VBITS,8)]]i8( undef, 
<[[#div(VBITS,8)]] x i8> [[X]], i64 0)
+// CHECK-NEXT:   [[CASTSCALABLESVE:%.*]] = tail call  
@llvm.vector.insert.nxv16i8.v[[#div(VBITS,8)]]i8( poison, 
<[[#div(VBITS,8)]] x i8> [[X]], i64 0)
 // CHECK-NEXT:   [[TMP2:%.*]] = tail call  
@llvm.aarch64.sve.asrd.nxv16i8( [[TMP1]],  
[[CASTSCALABLESVE]], i32 1

[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-08 Thread Nikita Popov via cfe-commits

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


[clang] [docs] Add a more detailed description in CXString.h. (PR #119090)

2024-12-08 Thread Saleem Abdulrasool via cfe-commits


@@ -46,6 +46,9 @@ typedef struct {
 
 /**
  * Retrieve the character data associated with the given string.
+ *
+ * The caller shouldn't free the returned string data, and the returned string
+ * data shouldn't be accessed after the \c CXString disposed.

compnerd wrote:

Whoops! That's my mistake - I meant to say `not`, not `now`. The data is the 
inner pointer like `c_str` is, and not meant to be modified by the user.

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


[clang] [docs] Add a more detailed description in CXString.h. (PR #119090)

2024-12-08 Thread Saleem Abdulrasool via cfe-commits

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


[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-08 Thread Nikita Popov via cfe-commits

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

Confirmed that this works on GCC now. I'd suggest to replace the use of 
StringLiteral::size with plain sizeof(). The build time overhead of going 
through StringLiteral here is substantial.

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


[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-08 Thread Nikita Popov via cfe-commits


@@ -68,23 +69,156 @@ enum ID {
   FirstTSBuiltin
 };
 
+// The info used to represent each builtin.
 struct Info {
-  llvm::StringLiteral Name;
-  const char *Type, *Attributes;
-  const char *Features;
+  // Rather than store pointers to the string literals describing these four
+  // aspects of builtins, we store offsets into a common string table.
+  struct StrOffsets {
+int Name;
+int Type;
+int Attributes;
+int Features;
+  } Offsets;
+
   HeaderDesc Header;
   LanguageID Langs;
 };
 
+// The storage for `N` builtins. This contains a single pointer to the string
+// table used for these builtins and an array of metadata for each builtin.
+template  struct Storage {
+  const char *StringTable;
+
+  std::array Infos;
+
+  // A constexpr function to construct the storage for a a given string table 
in
+  // the first argument and an array in the second argument. This is *only*
+  // expected to be used at compile time, we should mark it `consteval` when
+  // available.
+  //
+  // The `Infos` array is particularly special. This function expects an array
+  // of `Info` structs, where the string offsets of each entry refer to the
+  // *sizes* of those strings rather than their offsets, and for the target
+  // string to be in the provided string table at an offset the sum of all
+  // previous string sizes. This function walks the `Infos` array computing the
+  // running sum and replacing the sizes with the actual offsets in the string
+  // table that should be used. This arrangement is designed to make it easy to
+  // expand `.def` and `.inc` files with X-macros to construct both the string
+  // table and the `Info` structs in the arguments to this function.
+  static constexpr Storage Make(const char *Strings,
+   std::array Infos) {
+// Translate lengths to offsets.
+int Offset = 0;
+for (auto &I : Infos) {
+  Info::StrOffsets NewOffsets = {};
+  NewOffsets.Name = Offset;
+  Offset += I.Offsets.Name;
+  NewOffsets.Type = Offset;
+  Offset += I.Offsets.Type;
+  NewOffsets.Attributes = Offset;
+  Offset += I.Offsets.Attributes;
+  NewOffsets.Features = Offset;
+  Offset += I.Offsets.Features;
+  I.Offsets = NewOffsets;
+}
+return {Strings, Infos};
+  }
+};
+
+// A detail macro used below to emit a string literal that, after string 
literal
+// concatenation, ends up triggering the `-Woverlength-strings` warning. While
+// the warning is useful in general to catch accidentally excessive strings,
+// here we are creating them intentionally.
+//
+// This relies on a subtle aspect of `_Pragma`: that the *diagnostic* ones 
don't
+// turn into actual tokens that would disrupt string literal concatenation.
+#ifdef __clang__
+#define CLANG_BUILTIN_DETAIL_STR_TABLE(S)  
\
+  _Pragma("clang diagnostic push") 
\
+  _Pragma("clang diagnostic ignored \"-Woverlength-strings\"") 
\
+  S _Pragma("clang diagnostic pop")
+#else
+#define CLANG_BUILTIN_DETAIL_STR_TABLE(S) S
+#endif
+
+// A macro that can be used with `Builtins.def` and similar files as an X-macro
+// to add the string arguments to a builtin string table. This is typically the
+// target for the `BUILTIN`, `LANGBUILTIN`, or `LIBBUILTIN` macros in those
+// files.
+#define CLANG_BUILTIN_STR_TABLE(ID, TYPE, ATTRS)   
\
+  CLANG_BUILTIN_DETAIL_STR_TABLE(#ID "\0" TYPE "\0" ATTRS "\0" /*FEATURE*/ 
"\0")
+
+// A macro that can be used with target builtin `.def` and `.inc` files as an
+// X-macro to add the string arguments to a builtin string table. this is
+// typically the target for the `TARGET_BUILTIN` macro.
+#define CLANG_TARGET_BUILTIN_STR_TABLE(ID, TYPE, ATTRS, FEATURE)   
\
+  CLANG_BUILTIN_DETAIL_STR_TABLE(#ID "\0" TYPE "\0" ATTRS "\0" FEATURE "\0")
+
+// A macro that can be used with target builtin `.def` and `.inc` files as an
+// X-macro to add the string arguments to a builtin string table. this is
+// typically the target for the `TARGET_HEADER_BUILTIN` macro. We can't 
delegate
+// to `TARGET_BUILTIN` because the `FEATURE` string changes position.
+#define CLANG_TARGET_HEADER_BUILTIN_STR_TABLE(ID, TYPE, ATTRS, HEADER, LANGS,  
\
+  FEATURE) 
\
+  CLANG_BUILTIN_DETAIL_STR_TABLE(#ID "\0" TYPE "\0" ATTRS "\0" FEATURE "\0")
+
+// A detail macro used internally to compute the desired string table
+// `StrOffsets` struct for arguments to `Storage::Make`.
+#define CLANG_BUILTIN_DETAIL_STR_OFFSETS(ID, TYPE, ATTRS)  
\
+  Builtin::Info::StrOffsets {  
\
+llvm::StringLiteral(#ID).size() + 1, llvm::StringLiteral(TYPE).size() + 1, 
\
+llvm::StringLiteral(ATTRS).size() + 1, 
\
+llvm::StringLiteral("").size

[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-08 Thread Nikita Popov via cfe-commits


@@ -68,23 +69,156 @@ enum ID {
   FirstTSBuiltin
 };
 
+// The info used to represent each builtin.
 struct Info {
-  llvm::StringLiteral Name;
-  const char *Type, *Attributes;
-  const char *Features;
+  // Rather than store pointers to the string literals describing these four
+  // aspects of builtins, we store offsets into a common string table.
+  struct StrOffsets {
+int Name;
+int Type;
+int Attributes;
+int Features;
+  } Offsets;
+
   HeaderDesc Header;
   LanguageID Langs;
 };
 
+// The storage for `N` builtins. This contains a single pointer to the string
+// table used for these builtins and an array of metadata for each builtin.
+template  struct Storage {
+  const char *StringTable;
+
+  std::array Infos;
+
+  // A constexpr function to construct the storage for a a given string table 
in
+  // the first argument and an array in the second argument. This is *only*
+  // expected to be used at compile time, we should mark it `consteval` when
+  // available.
+  //
+  // The `Infos` array is particularly special. This function expects an array
+  // of `Info` structs, where the string offsets of each entry refer to the
+  // *sizes* of those strings rather than their offsets, and for the target
+  // string to be in the provided string table at an offset the sum of all
+  // previous string sizes. This function walks the `Infos` array computing the
+  // running sum and replacing the sizes with the actual offsets in the string
+  // table that should be used. This arrangement is designed to make it easy to
+  // expand `.def` and `.inc` files with X-macros to construct both the string
+  // table and the `Info` structs in the arguments to this function.
+  static constexpr Storage Make(const char *Strings,
+   std::array Infos) {
+// Translate lengths to offsets.
+int Offset = 0;
+for (auto &I : Infos) {
+  Info::StrOffsets NewOffsets = {};
+  NewOffsets.Name = Offset;
+  Offset += I.Offsets.Name;
+  NewOffsets.Type = Offset;
+  Offset += I.Offsets.Type;
+  NewOffsets.Attributes = Offset;
+  Offset += I.Offsets.Attributes;
+  NewOffsets.Features = Offset;
+  Offset += I.Offsets.Features;
+  I.Offsets = NewOffsets;
+}
+return {Strings, Infos};
+  }
+};
+
+// A detail macro used below to emit a string literal that, after string 
literal
+// concatenation, ends up triggering the `-Woverlength-strings` warning. While
+// the warning is useful in general to catch accidentally excessive strings,
+// here we are creating them intentionally.
+//
+// This relies on a subtle aspect of `_Pragma`: that the *diagnostic* ones 
don't
+// turn into actual tokens that would disrupt string literal concatenation.
+#ifdef __clang__
+#define CLANG_BUILTIN_DETAIL_STR_TABLE(S)  
\
+  _Pragma("clang diagnostic push") 
\
+  _Pragma("clang diagnostic ignored \"-Woverlength-strings\"") 
\
+  S _Pragma("clang diagnostic pop")
+#else
+#define CLANG_BUILTIN_DETAIL_STR_TABLE(S) S
+#endif
+
+// A macro that can be used with `Builtins.def` and similar files as an X-macro
+// to add the string arguments to a builtin string table. This is typically the
+// target for the `BUILTIN`, `LANGBUILTIN`, or `LIBBUILTIN` macros in those
+// files.
+#define CLANG_BUILTIN_STR_TABLE(ID, TYPE, ATTRS)   
\
+  CLANG_BUILTIN_DETAIL_STR_TABLE(#ID "\0" TYPE "\0" ATTRS "\0" /*FEATURE*/ 
"\0")
+
+// A macro that can be used with target builtin `.def` and `.inc` files as an
+// X-macro to add the string arguments to a builtin string table. this is
+// typically the target for the `TARGET_BUILTIN` macro.
+#define CLANG_TARGET_BUILTIN_STR_TABLE(ID, TYPE, ATTRS, FEATURE)   
\
+  CLANG_BUILTIN_DETAIL_STR_TABLE(#ID "\0" TYPE "\0" ATTRS "\0" FEATURE "\0")
+
+// A macro that can be used with target builtin `.def` and `.inc` files as an
+// X-macro to add the string arguments to a builtin string table. this is
+// typically the target for the `TARGET_HEADER_BUILTIN` macro. We can't 
delegate
+// to `TARGET_BUILTIN` because the `FEATURE` string changes position.
+#define CLANG_TARGET_HEADER_BUILTIN_STR_TABLE(ID, TYPE, ATTRS, HEADER, LANGS,  
\
+  FEATURE) 
\
+  CLANG_BUILTIN_DETAIL_STR_TABLE(#ID "\0" TYPE "\0" ATTRS "\0" FEATURE "\0")
+
+// A detail macro used internally to compute the desired string table
+// `StrOffsets` struct for arguments to `Storage::Make`.
+#define CLANG_BUILTIN_DETAIL_STR_OFFSETS(ID, TYPE, ATTRS)  
\
+  Builtin::Info::StrOffsets {  
\
+llvm::StringLiteral(#ID).size() + 1, llvm::StringLiteral(TYPE).size() + 1, 
\
+llvm::StringLiteral(ATTRS).size() + 1, 
\
+llvm::StringLiteral("").size

[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-08 Thread Peng Huang via cfe-commits

phuang wrote:

Thanks for reviewing it.


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


[clang] b0f0676 - [AArch64] Implement intrinsics for SME FP8 F1CVT/F2CVT and BF1CVT/BF2CVT (#118027)

2024-12-08 Thread via cfe-commits

Author: SpencerAbson
Date: 2024-12-08T19:34:01Z
New Revision: b0f06769e6e2ea2bc4ce3554ebf66384a1236106

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

LOG: [AArch64] Implement intrinsics for SME FP8 F1CVT/F2CVT and BF1CVT/BF2CVT 
(#118027)

This patch implements the following intrinsics:

8-bit floating-point convert to half-precision or BFloat16 (in-order).
``` c
  // Variant is also available for: _bf16[_mf8]_x2
  svfloat16x2_t svcvt1_f16[_mf8]_x2_fpm(svmfloat8_t zn, fpm_t fpm) 
__arm_streaming;
  svfloat16x2_t svcvt2_f16[_mf8]_x2_fpm(svmfloat8_t zn, fpm_t fpm) 
__arm_streaming;
```

In accordance with https://github.com/ARM-software/acle/pull/323.

Co-authored-by: Marin Lukac marian.lu...@arm.com
Co-authored-by: Caroline Concatto caroline.conca...@arm.com

Added: 


Modified: 
clang/include/clang/Basic/arm_sve.td
clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_cvt.c
clang/test/Sema/aarch64-fp8-intrinsics/acle_sme2_fp8_cvt.c
llvm/include/llvm/IR/IntrinsicsAArch64.td
llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
llvm/test/CodeGen/AArch64/sme2-fp8-intrinsics-cvt.ll

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index e551d6e46b8f33..9b8a8546b072c0 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2429,6 +2429,10 @@ let SVETargetGuard = InvalidMode, SMETargetGuard = 
"sme2,fp8" in {
   def FSCALE_X2 : Inst<"svscale[_{d}_x2]", "222.x", "fhd", MergeNone, 
"aarch64_sme_fp8_scale_x2", [IsStreaming],[]>;
   def FSCALE_X4 : Inst<"svscale[_{d}_x4]", "444.x", "fhd", MergeNone, 
"aarch64_sme_fp8_scale_x4", [IsStreaming],[]>;
 
+  // Convert from FP8 to half-precision/BFloat16 multi-vector
+  def SVF1CVT : Inst<"svcvt1_{d}[_mf8]_x2_fpm", "2~>", "bh", MergeNone, 
"aarch64_sve_fp8_cvt1_x2", [IsStreaming, SetsFPMR], []>;
+  def SVF2CVT : Inst<"svcvt2_{d}[_mf8]_x2_fpm", "2~>", "bh", MergeNone, 
"aarch64_sve_fp8_cvt2_x2", [IsStreaming, SetsFPMR], []>;
+
   // Convert from FP8 to deinterleaved half-precision/BFloat16 multi-vector
   def SVF1CVTL : Inst<"svcvtl1_{d}[_mf8]_x2_fpm",  "2~>", "bh", MergeNone, 
"aarch64_sve_fp8_cvtl1_x2",  [IsStreaming, SetsFPMR], []>;
   def SVF2CVTL : Inst<"svcvtl2_{d}[_mf8]_x2_fpm",  "2~>", "bh", MergeNone, 
"aarch64_sve_fp8_cvtl2_x2",  [IsStreaming, SetsFPMR], []>;

diff  --git a/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_cvt.c 
b/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_cvt.c
index 5ba76671ff5d5b..13609f034da336 100644
--- a/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_cvt.c
+++ b/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_cvt.c
@@ -16,6 +16,70 @@
 #define SVE_ACLE_FUNC(A1,A2,A3) A1##A2##A3
 #endif
 
+// CHECK-LABEL: @test_cvt1_f16_x2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.set.fpmr(i64 [[FPMR:%.*]])
+// CHECK-NEXT:[[TMP0:%.*]] = tail call { ,  } @llvm.aarch64.sve.fp8.cvt1.x2.nxv8f16( [[ZN:%.*]])
+// CHECK-NEXT:ret { ,  } [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z16test_cvt1_f16_x2u13__SVMfloat8_tm(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:tail call void @llvm.aarch64.set.fpmr(i64 [[FPMR:%.*]])
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call { ,  } @llvm.aarch64.sve.fp8.cvt1.x2.nxv8f16( 
[[ZN:%.*]])
+// CPP-CHECK-NEXT:ret { ,  } [[TMP0]]
+//
+svfloat16x2_t test_cvt1_f16_x2(svmfloat8_t zn, fpm_t fpmr)  __arm_streaming {
+  return SVE_ACLE_FUNC(svcvt1_f16,_mf8,_x2_fpm)(zn, fpmr);
+}
+
+// CHECK-LABEL: @test_cvt2_f16_x2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.set.fpmr(i64 [[FPMR:%.*]])
+// CHECK-NEXT:[[TMP0:%.*]] = tail call { ,  } @llvm.aarch64.sve.fp8.cvt2.x2.nxv8f16( [[ZN:%.*]])
+// CHECK-NEXT:ret { ,  } [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z16test_cvt2_f16_x2u13__SVMfloat8_tm(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:tail call void @llvm.aarch64.set.fpmr(i64 [[FPMR:%.*]])
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call { ,  } @llvm.aarch64.sve.fp8.cvt2.x2.nxv8f16( 
[[ZN:%.*]])
+// CPP-CHECK-NEXT:ret { ,  } [[TMP0]]
+//
+svfloat16x2_t test_cvt2_f16_x2(svmfloat8_t zn, fpm_t fpmr)  __arm_streaming {
+  return SVE_ACLE_FUNC(svcvt2_f16,_mf8,_x2_fpm)(zn, fpmr);
+}
+
+// CHECK-LABEL: @test_cvt1_bf16_x2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.set.fpmr(i64 [[FPMR:%.*]])
+// CHECK-NEXT:[[TMP0:%.*]] = tail call { ,  } @llvm.aarch64.sve.fp8.cvt1.x2.nxv8bf16( 
[[ZN:%.*]])
+// CHECK-NEXT:ret { ,  } [[TMP0]]
+//
+// CPP-CHECK-LABEL: @_Z17test_cvt1_bf16_x2u13__SVMfloat8_tm(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:tail call void @llvm.aarch64.set.fpmr(i64 [[FPMR:%.*]])
+// CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call { , 
 } @llvm.aarch64.

[clang] [llvm] [AArch64] Implement intrinsics for SME FP8 F1CVT/F2CVT and BF1CVT/BF2CVT (PR #118027)

2024-12-08 Thread via cfe-commits

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


[clang] [llvm] [AArch64] Implement intrinsics for SME FP8 FMOPA (PR #118115)

2024-12-08 Thread via cfe-commits

https://github.com/SpencerAbson updated 
https://github.com/llvm/llvm-project/pull/118115

>From e1181dd6dab09b20be8077d1f4e70ef4da7ab437 Mon Sep 17 00:00:00 2001
From: Spencer Abson 
Date: Mon, 25 Nov 2024 21:47:20 +
Subject: [PATCH 1/2] [AArch64] Implement intrinsics for SME FP8 FMOPA

---
 clang/include/clang/Basic/arm_sme.td  | 10 
 clang/lib/CodeGen/CGBuiltin.cpp   |  6 ++
 .../fp8-intrinsics/acle_sme2_fp8_fmopa.c  | 55 +++
 .../acle_sme2_fp8_imm.c   | 18 ++
 .../acle_sme2_fp8_mopa.c  | 13 +
 llvm/include/llvm/IR/IntrinsicsAArch64.td | 11 
 .../lib/Target/AArch64/AArch64SMEInstrInfo.td | 17 +++---
 llvm/lib/Target/AArch64/SMEInstrFormats.td| 26 -
 .../AArch64/sme2-fp8-intrinsics-fmopa.ll  | 22 
 9 files changed, 166 insertions(+), 12 deletions(-)
 create mode 100644 
clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_fmopa.c
 create mode 100644 clang/test/Sema/aarch64-fp8-intrinsics/acle_sme2_fp8_imm.c
 create mode 100644 clang/test/Sema/aarch64-fp8-intrinsics/acle_sme2_fp8_mopa.c
 create mode 100644 llvm/test/CodeGen/AArch64/sme2-fp8-intrinsics-fmopa.ll

diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 0f689e82bdb742..71b2c7cdd04f93 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -824,4 +824,14 @@ let SMETargetGuard = "sme-lutv2" in {
   def SVLUTI4_ZT_X4 : SInst<"svluti4_zt_{d}_x4", "4i2.u", "cUc", MergeNone, 
"aarch64_sme_luti4_zt_x4", [IsStreaming, IsInZT0], [ImmCheck<0, ImmCheck0_0>]>;
 }
 
+let SMETargetGuard = "sme-f8f32" in {
+  def SVMOPA_FP8_ZA32 : Inst<"svmopa_za32[_mf8]_m_fpm", "viPPdd>", "m", 
MergeNone, "aarch64_sme_fp8_fmopa_za32",
+ [IsStreaming, IsInOutZA, SetsFPMR, 
IsOverloadNone], [ImmCheck<0, ImmCheck0_3>]>;
+}
+
+let SMETargetGuard = "sme-f8f16" in {
+  def SVMOPA_FP8_ZA16 : Inst<"svmopa_za16[_mf8]_m_fpm", "viPPdd>", "m", 
MergeNone, "aarch64_sme_fp8_fmopa_za16",
+ [IsStreaming, IsInOutZA, SetsFPMR, 
IsOverloadNone], [ImmCheck<0, ImmCheck0_1>]>;
+}
+
 } // let SVETargetGuard = InvalidMode
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 41c632ead6aa3c..c2e983eebebc10 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -10201,6 +10201,8 @@ CodeGenFunction::getSVEType(const SVETypeFlags 
&TypeFlags) {
   case SVETypeFlags::EltTyInt64:
 return llvm::ScalableVectorType::get(Builder.getInt64Ty(), 2);
 
+  case SVETypeFlags::EltTyMFloat8:
+return llvm::ScalableVectorType::get(Builder.getInt8Ty(), 16);
   case SVETypeFlags::EltTyFloat16:
 return llvm::ScalableVectorType::get(Builder.getHalfTy(), 8);
   case SVETypeFlags::EltTyBFloat16:
@@ -11255,6 +11257,10 @@ Value 
*CodeGenFunction::EmitAArch64SMEBuiltinExpr(unsigned BuiltinID,
BuiltinID == SME::BI__builtin_sme_svstr_za)
 return EmitSMELdrStr(TypeFlags, Ops, Builtin->LLVMIntrinsic);
 
+  // Emit set FPMR for intrinsics that require it
+  if (TypeFlags.setsFPMR())
+Builder.CreateCall(CGM.getIntrinsic(Intrinsic::aarch64_set_fpmr),
+   Ops.pop_back_val());
   // Handle builtins which require their multi-vector operands to be swapped
   swapCommutativeSMEOperands(BuiltinID, Ops);
 
diff --git a/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_fmopa.c 
b/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_fmopa.c
new file mode 100644
index 00..95d6383ab30efe
--- /dev/null
+++ b/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_fmopa.c
@@ -0,0 +1,55 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sme-f8f16 -target-feature +sme-f8f32 -disable-O0-optnone 
-Werror -Wall -emit-llvm -o - %s | opt -S -passes=mem2reg,tailcallelim | 
FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sme-f8f16 -target-feature +sme-f8f32 -disable-O0-optnone 
-Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -passes=mem2reg,tailcallelim | 
FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme -target-feature +sme-f8f16 -target-feature +sme-f8f32 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S 
-passes=mem2reg,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme -target-feature +sme-f8f16 -target-feature +sme-f8f32 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S 
-passes=mem2reg,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sme

[clang] Resolving issue #119101 (PR #119143)

2024-12-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Rounaq Khan (rkmaxhero)


Changes

CLANG parser previously allowed for invalid C/C++ auto classes declaration due 
to a lack of logic addressing this case. Logic comparing with a valid case was 
added to the ParseDeclarationOrFunctionDefinition() function to account for 
this. Test cases where added to address possible scenarios of auto class 
declaration. the parser diagnostic file will now detect invalid auto class 
definitions and output appropriately. 

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


3 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+2) 
- (modified) clang/lib/Parse/Parser.cpp (+12) 
- (added) clang/test/SemaCXX/invalid-storage-class.cpp (+7) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 0da509280068ad..99d698f57982fc 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -449,6 +449,8 @@ def err_typename_invalid_constexpr : Error<
   "to be specified">;
 def err_typename_identifiers_only : Error<
   "typename is allowed for identifiers only">;
+def err_storage_class_before_class_decl : Error<
+  "'%0' is not allowed before a class declaration">;
 
 def err_friend_invalid_in_context : Error<
   "'friend' used outside of class">;
diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 04c2f1d380bc48..2145f78f4b2749 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -1254,6 +1254,18 @@ Parser::DeclGroupPtrTy 
Parser::ParseDeclarationOrFunctionDefinition(
 Actions.getASTContext().getSourceManager());
   });
 
+  if (DS->getStorageClassSpec() != DeclSpec::SCS_unspecified) {
+  // Check if the next token starts a class/struct/union/enum declaration
+if (Tok.isOneOf(tok::kw_class, tok::kw_struct, tok::kw_union, 
tok::kw_enum)) {
+  // Emit an error: storage class specifiers are not allowed before class 
declarations
+  Diag(DS->getStorageClassSpecLoc(), 
diag::err_storage_class_before_class_decl)
+  << DeclSpec::getSpecifierName(DS->getStorageClassSpec());
+
+  // Optionally, consume the storage class specifier to continue parsing
+  DS->ClearStorageClassSpecs();
+}
+  }
+
   if (DS) {
 return ParseDeclOrFunctionDefInternal(Attrs, DeclSpecAttrs, *DS, AS);
   } else {
diff --git a/clang/test/SemaCXX/invalid-storage-class.cpp 
b/clang/test/SemaCXX/invalid-storage-class.cpp
new file mode 100644
index 00..ce0dee3711ac03
--- /dev/null
+++ b/clang/test/SemaCXX/invalid-storage-class.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+auto class X1 {}; // expected-error {{'auto' is not allowed before a class 
declaration}}
+
+static struct X2 {}; // expected-error {{'static' is not allowed before a 
class declaration}}
+
+register union X3 {}; // expected-error {{'register' is not allowed before a 
class declaration}}
\ No newline at end of file

``




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


[clang] Resolving issue #119101 (PR #119143)

2024-12-08 Thread Rounaq Khan via cfe-commits

https://github.com/rkmaxhero created 
https://github.com/llvm/llvm-project/pull/119143

CLANG parser previously allowed for invalid C/C++ auto classes declaration due 
to a lack of logic addressing this case. Logic comparing with a valid case was 
added to the ParseDeclarationOrFunctionDefinition() function to account for 
this. Test cases where added to address possible scenarios of auto class 
declaration. the parser diagnostic file will now detect invalid auto class 
definitions and output appropriately. 

>From ab8c853a3bfda20beb82bc2d27859b6dcf3cdc7e Mon Sep 17 00:00:00 2001
From: Rounaq Khan 
Date: Sun, 8 Dec 2024 13:49:06 -0500
Subject: [PATCH 1/4] add check logic for auto class type

---
 clang/lib/Parse/Parser.cpp | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp
index 04c2f1d380bc48..2145f78f4b2749 100644
--- a/clang/lib/Parse/Parser.cpp
+++ b/clang/lib/Parse/Parser.cpp
@@ -1254,6 +1254,18 @@ Parser::DeclGroupPtrTy 
Parser::ParseDeclarationOrFunctionDefinition(
 Actions.getASTContext().getSourceManager());
   });
 
+  if (DS->getStorageClassSpec() != DeclSpec::SCS_unspecified) {
+  // Check if the next token starts a class/struct/union/enum declaration
+if (Tok.isOneOf(tok::kw_class, tok::kw_struct, tok::kw_union, 
tok::kw_enum)) {
+  // Emit an error: storage class specifiers are not allowed before class 
declarations
+  Diag(DS->getStorageClassSpecLoc(), 
diag::err_storage_class_before_class_decl)
+  << DeclSpec::getSpecifierName(DS->getStorageClassSpec());
+
+  // Optionally, consume the storage class specifier to continue parsing
+  DS->ClearStorageClassSpecs();
+}
+  }
+
   if (DS) {
 return ParseDeclOrFunctionDefInternal(Attrs, DeclSpecAttrs, *DS, AS);
   } else {

>From e9d9b5aa24a775e7cd99fc7c1391859d8ff61dd8 Mon Sep 17 00:00:00 2001
From: Rounaq Khan 
Date: Sun, 8 Dec 2024 13:50:40 -0500
Subject: [PATCH 2/4] add diagnostic message for parser issue auto class
 declaration for CLANG

---
 clang/include/clang/Basic/DiagnosticParseKinds.td | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 0da509280068ad..99d698f57982fc 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -449,6 +449,8 @@ def err_typename_invalid_constexpr : Error<
   "to be specified">;
 def err_typename_identifiers_only : Error<
   "typename is allowed for identifiers only">;
+def err_storage_class_before_class_decl : Error<
+  "'%0' is not allowed before a class declaration">;
 
 def err_friend_invalid_in_context : Error<
   "'friend' used outside of class">;

>From 8680d99633bbf72dddfc3b9d4718a4d7e3fae91e Mon Sep 17 00:00:00 2001
From: Rounaq Khan <45477562+rkmaxh...@users.noreply.github.com>
Date: Sun, 8 Dec 2024 14:05:25 -0500
Subject: [PATCH 3/4] Update DiagnosticParseKinds.td in accordance to error
 related to auto class declarations

---
 clang/include/clang/Basic/DiagnosticParseKinds.td | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 0da509280068ad..99d698f57982fc 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -449,6 +449,8 @@ def err_typename_invalid_constexpr : Error<
   "to be specified">;
 def err_typename_identifiers_only : Error<
   "typename is allowed for identifiers only">;
+def err_storage_class_before_class_decl : Error<
+  "'%0' is not allowed before a class declaration">;
 
 def err_friend_invalid_in_context : Error<
   "'friend' used outside of class">;

>From 871187e20647c54f7265b9b71fdfcf4b8c5daecc Mon Sep 17 00:00:00 2001
From: Rounaq Khan 
Date: Sun, 8 Dec 2024 14:38:04 -0500
Subject: [PATCH 4/4] add test cases for invalid auto storage declaration

---
 clang/test/SemaCXX/invalid-storage-class.cpp | 7 +++
 1 file changed, 7 insertions(+)
 create mode 100644 clang/test/SemaCXX/invalid-storage-class.cpp

diff --git a/clang/test/SemaCXX/invalid-storage-class.cpp 
b/clang/test/SemaCXX/invalid-storage-class.cpp
new file mode 100644
index 00..ce0dee3711ac03
--- /dev/null
+++ b/clang/test/SemaCXX/invalid-storage-class.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+auto class X1 {}; // expected-error {{'auto' is not allowed before a class 
declaration}}
+
+static struct X2 {}; // expected-error {{'static' is not allowed before a 
class declaration}}
+
+register union X3 {}; // expected-error {{'register' is not allowed before a 
class declaration}}
\ No newline at end of file

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


[clang] Resolving issue #119101 (PR #119143)

2024-12-08 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/119143
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix lld link issue for OHOS (PR #118192)

2024-12-08 Thread Pavel Kosov via cfe-commits

kpdev wrote:

LGTM

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


[clang] Resolving issue #119101 (PR #119143)

2024-12-08 Thread Richard Smith via cfe-commits

zygoloid wrote:

Did you mean a different issue than #119101? It's not clear to me what 
connection this PR has to that issue.

It's not clear to me that there's an issue to be solved here. Under 
`-pedantic-errors`, clang [already produces an 
error](https://godbolt.org/z/h6oKarex9) on examples like the ones here, and by 
default clang produces a warning on such cases, so we are already diagnosing 
this. And we need to continue to accept things like `static struct A {} a;`, 
which are valid but would be rejected by this change.

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


[clang] [llvm] [openmp] [OpenMP] Use generic IR for the OpenMP DeviceRTL (PR #119091)

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

shiltian wrote:

> The IR is a representation of what goes on a final .o. It is not really 
> intended to enable new features or make the program portable.

My .02 is, it depends on how to think about it. If we eliminate the "unwanted" 
part (especially those that could potentially affect ABI) at the very beginning 
of the middle end, it will not have optimization effects.

In addition, the compiler backend lowering is essentially doing something like:

```
if (target == A)
  lower Inst to I1
else if (has_feature_that_only_compiler_can_call("..."))
  lower Inst to I2
...
```

If speaking from "portability", the compiler is "portable". The reflection is 
just to give end user an interface to do similar things:

```
if (__builtin_get_target() == A)
  do something in one way
else if (has_feature_that_user_can_call("..."))
  do something in another way
...
```

Of course the interface(s) have to be carefully designed and all the queried 
information can't be changed during optimization.

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


[clang] [clang] constexpr built-in elementwise add_sat/sub_sat functions. (PR #119082)

2024-12-08 Thread via cfe-commits

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

I am happy if @RKSimon is

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


[clang] [llvm] [AArch64] Implement intrinsics for SME FP8 FMLAL/FMLALL (Indexed) (PR #118549)

2024-12-08 Thread via cfe-commits

https://github.com/SpencerAbson updated 
https://github.com/llvm/llvm-project/pull/118549

>From 298e1372cb8e6b2f7707f42448521d3014bc Mon Sep 17 00:00:00 2001
From: Spencer Abson 
Date: Mon, 25 Nov 2024 21:47:20 +
Subject: [PATCH 1/3] [AArch64] Implement intrinsics for SME FP8 FMOPA

---
 clang/include/clang/Basic/arm_sme.td  | 10 
 clang/lib/CodeGen/CGBuiltin.cpp   |  6 ++
 .../fp8-intrinsics/acle_sme2_fp8_fmopa.c  | 55 +++
 .../acle_sme2_fp8_imm.c   | 18 ++
 .../acle_sme2_fp8_mopa.c  | 13 +
 llvm/include/llvm/IR/IntrinsicsAArch64.td | 11 
 .../lib/Target/AArch64/AArch64SMEInstrInfo.td | 17 +++---
 llvm/lib/Target/AArch64/SMEInstrFormats.td| 26 -
 .../AArch64/sme2-fp8-intrinsics-fmopa.ll  | 22 
 9 files changed, 166 insertions(+), 12 deletions(-)
 create mode 100644 
clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_fmopa.c
 create mode 100644 clang/test/Sema/aarch64-fp8-intrinsics/acle_sme2_fp8_imm.c
 create mode 100644 clang/test/Sema/aarch64-fp8-intrinsics/acle_sme2_fp8_mopa.c
 create mode 100644 llvm/test/CodeGen/AArch64/sme2-fp8-intrinsics-fmopa.ll

diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 0f689e82bdb742..71b2c7cdd04f93 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -824,4 +824,14 @@ let SMETargetGuard = "sme-lutv2" in {
   def SVLUTI4_ZT_X4 : SInst<"svluti4_zt_{d}_x4", "4i2.u", "cUc", MergeNone, 
"aarch64_sme_luti4_zt_x4", [IsStreaming, IsInZT0], [ImmCheck<0, ImmCheck0_0>]>;
 }
 
+let SMETargetGuard = "sme-f8f32" in {
+  def SVMOPA_FP8_ZA32 : Inst<"svmopa_za32[_mf8]_m_fpm", "viPPdd>", "m", 
MergeNone, "aarch64_sme_fp8_fmopa_za32",
+ [IsStreaming, IsInOutZA, SetsFPMR, 
IsOverloadNone], [ImmCheck<0, ImmCheck0_3>]>;
+}
+
+let SMETargetGuard = "sme-f8f16" in {
+  def SVMOPA_FP8_ZA16 : Inst<"svmopa_za16[_mf8]_m_fpm", "viPPdd>", "m", 
MergeNone, "aarch64_sme_fp8_fmopa_za16",
+ [IsStreaming, IsInOutZA, SetsFPMR, 
IsOverloadNone], [ImmCheck<0, ImmCheck0_1>]>;
+}
+
 } // let SVETargetGuard = InvalidMode
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 41c632ead6aa3c..c2e983eebebc10 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -10201,6 +10201,8 @@ CodeGenFunction::getSVEType(const SVETypeFlags 
&TypeFlags) {
   case SVETypeFlags::EltTyInt64:
 return llvm::ScalableVectorType::get(Builder.getInt64Ty(), 2);
 
+  case SVETypeFlags::EltTyMFloat8:
+return llvm::ScalableVectorType::get(Builder.getInt8Ty(), 16);
   case SVETypeFlags::EltTyFloat16:
 return llvm::ScalableVectorType::get(Builder.getHalfTy(), 8);
   case SVETypeFlags::EltTyBFloat16:
@@ -11255,6 +11257,10 @@ Value 
*CodeGenFunction::EmitAArch64SMEBuiltinExpr(unsigned BuiltinID,
BuiltinID == SME::BI__builtin_sme_svstr_za)
 return EmitSMELdrStr(TypeFlags, Ops, Builtin->LLVMIntrinsic);
 
+  // Emit set FPMR for intrinsics that require it
+  if (TypeFlags.setsFPMR())
+Builder.CreateCall(CGM.getIntrinsic(Intrinsic::aarch64_set_fpmr),
+   Ops.pop_back_val());
   // Handle builtins which require their multi-vector operands to be swapped
   swapCommutativeSMEOperands(BuiltinID, Ops);
 
diff --git a/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_fmopa.c 
b/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_fmopa.c
new file mode 100644
index 00..95d6383ab30efe
--- /dev/null
+++ b/clang/test/CodeGen/AArch64/fp8-intrinsics/acle_sme2_fp8_fmopa.c
@@ -0,0 +1,55 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sme-f8f16 -target-feature +sme-f8f32 -disable-O0-optnone 
-Werror -Wall -emit-llvm -o - %s | opt -S -passes=mem2reg,tailcallelim | 
FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sme-f8f16 -target-feature +sme-f8f32 -disable-O0-optnone 
-Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -passes=mem2reg,tailcallelim | 
FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme -target-feature +sme-f8f16 -target-feature +sme-f8f32 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S 
-passes=mem2reg,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme -target-feature +sme-f8f16 -target-feature +sme-f8f32 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S 
-passes=mem2reg,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sme

[clang] [llvm] [openmp] [OpenMP] Use generic IR for the OpenMP DeviceRTL (PR #119091)

2024-12-08 Thread Matt Arsenault via cfe-commits

arsenm wrote:

> Does wave32/wave64 affect the lowering from front end source code to middle 
> end IR, if we don't use certain functions, such as wave level primitives?

Yes. This is a fixed ABI setting that can change the binary function signature 
(which then has knock on optimization effects). The IR is a representation of 
what goes on a final .o. It is not really intended to enable new features or 
make the program portable. 

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


[clang] [Clang] allow [[msvc::constexpr]] usage outside the std namespace (PR #119153)

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

https://github.com/a-tarasyuk created 
https://github.com/llvm/llvm-project/pull/119153

Fixes #74924

>From f19ea82bbe5c00af6a6e261f989c9a89ef4c78ca Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 9 Dec 2024 01:46:46 +0200
Subject: [PATCH] [Clang] allow [[msvc::constexpr]] usage outside the std
 namespace

---
 clang/docs/ReleaseNotes.rst |  2 ++
 clang/lib/AST/ExprConstant.cpp  |  4 +++-
 clang/test/AST/ms-constexpr-new.cpp | 13 +
 3 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/AST/ms-constexpr-new.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3f58e64cf0ccbc..71666e26146e92 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -525,6 +525,8 @@ Attribute Changes in Clang
 
 - The ``target_version`` attribute is now only supported for AArch64 and 
RISC-V architectures.
 
+- Clang now permits ``[[msvc::constexpr]]`` usage outside of the std 
namespace. (#GH74924)
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6b5b95aee35522..9dbb350be59091 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -10172,7 +10172,9 @@ bool PointerExprEvaluator::VisitCXXNewExpr(const 
CXXNewExpr *E) {
   return false;
 IsNothrow = true;
   } else if (OperatorNew->isReservedGlobalPlacementOperator()) {
-if (Info.CurrentCall->isStdFunction() || Info.getLangOpts().CPlusPlus26) {
+if (Info.CurrentCall->isStdFunction() || Info.getLangOpts().CPlusPlus26 ||
+(Info.CurrentCall->CanEvalMSConstexpr &&
+ OperatorNew->hasAttr())) {
   if (!EvaluatePointer(E->getPlacementArg(0), Result, Info))
 return false;
   if (Result.Designator.Invalid)
diff --git a/clang/test/AST/ms-constexpr-new.cpp 
b/clang/test/AST/ms-constexpr-new.cpp
new file mode 100644
index 00..4b534cf0207644
--- /dev/null
+++ b/clang/test/AST/ms-constexpr-new.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fms-compatibility -fms-compatibility-version=19.33 
-std=c++20 -ast-dump %s | FileCheck %s
+
+// CHECK: used operator new
+// CHECK: MSConstexprAttr 0x{{[0-9a-f]+}} 
+[[nodiscard]] [[msvc::constexpr]] inline void* __cdecl operator 
new(decltype(sizeof(void*)), void* p) noexcept { return p; }
+
+// CHECK: used constexpr construct_at
+// CHECK: AttributedStmt 0x{{[0-9a-f]+}} 
+// CHECK-NEXT: MSConstexprAttr 0x{{[0-9a-f]+}} 
+// CHECK-NEXT: ReturnStmt 0x{{[0-9a-f]+}} 
+constexpr int* construct_at(int* p, int v) { [[msvc::constexpr]] return ::new 
(p) int(v); }
+constexpr bool check_construct_at() { int x; return *construct_at(&x, 42) == 
42; }
+static_assert(check_construct_at());

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


[clang] [Clang] allow [[msvc::constexpr]] usage outside the std namespace (PR #119153)

2024-12-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Oleksandr T. (a-tarasyuk)


Changes

Fixes #74924

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/AST/ExprConstant.cpp (+3-1) 
- (added) clang/test/AST/ms-constexpr-new.cpp (+13) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3f58e64cf0ccbc..71666e26146e92 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -525,6 +525,8 @@ Attribute Changes in Clang
 
 - The ``target_version`` attribute is now only supported for AArch64 and 
RISC-V architectures.
 
+- Clang now permits ``[[msvc::constexpr]]`` usage outside of the std 
namespace. (#GH74924)
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6b5b95aee35522..9dbb350be59091 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -10172,7 +10172,9 @@ bool PointerExprEvaluator::VisitCXXNewExpr(const 
CXXNewExpr *E) {
   return false;
 IsNothrow = true;
   } else if (OperatorNew->isReservedGlobalPlacementOperator()) {
-if (Info.CurrentCall->isStdFunction() || Info.getLangOpts().CPlusPlus26) {
+if (Info.CurrentCall->isStdFunction() || Info.getLangOpts().CPlusPlus26 ||
+(Info.CurrentCall->CanEvalMSConstexpr &&
+ OperatorNew->hasAttr())) {
   if (!EvaluatePointer(E->getPlacementArg(0), Result, Info))
 return false;
   if (Result.Designator.Invalid)
diff --git a/clang/test/AST/ms-constexpr-new.cpp 
b/clang/test/AST/ms-constexpr-new.cpp
new file mode 100644
index 00..4b534cf0207644
--- /dev/null
+++ b/clang/test/AST/ms-constexpr-new.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fms-compatibility -fms-compatibility-version=19.33 
-std=c++20 -ast-dump %s | FileCheck %s
+
+// CHECK: used operator new
+// CHECK: MSConstexprAttr 0x{{[0-9a-f]+}} 
+[[nodiscard]] [[msvc::constexpr]] inline void* __cdecl operator 
new(decltype(sizeof(void*)), void* p) noexcept { return p; }
+
+// CHECK: used constexpr construct_at
+// CHECK: AttributedStmt 0x{{[0-9a-f]+}} 
+// CHECK-NEXT: MSConstexprAttr 0x{{[0-9a-f]+}} 
+// CHECK-NEXT: ReturnStmt 0x{{[0-9a-f]+}} 
+constexpr int* construct_at(int* p, int v) { [[msvc::constexpr]] return ::new 
(p) int(v); }
+constexpr bool check_construct_at() { int x; return *construct_at(&x, 42) == 
42; }
+static_assert(check_construct_at());

``




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


[clang] 8843d2b - [rtsan] Add `verify_interceptors` flag to docs (#119074)

2024-12-08 Thread via cfe-commits

Author: Chris Apple
Date: 2024-12-08T09:34:40-08:00
New Revision: 8843d2b4695419caa774b40582146446f350a504

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

LOG: [rtsan] Add `verify_interceptors` flag to docs (#119074)

Added: 


Modified: 
clang/docs/RealtimeSanitizer.rst

Removed: 




diff  --git a/clang/docs/RealtimeSanitizer.rst 
b/clang/docs/RealtimeSanitizer.rst
index 2aec728cfed583..f5d29af2bef3c5 100644
--- a/clang/docs/RealtimeSanitizer.rst
+++ b/clang/docs/RealtimeSanitizer.rst
@@ -196,7 +196,10 @@ A **partial** list of flags RealtimeSanitizer respects:
  - ``""``
  - path
  - If set to a valid suppressions file, will suppress issue reporting. See 
details in `Disabling and Suppressing`_.
-
+   * - ``verify_interceptors``
+ - ``true``
+ - boolean
+ - If true, verifies interceptors are working at initialization. The 
program will abort with error ``==ERROR: Interceptors are not working. This may 
be because RealtimeSanitizer is loaded too late (e.g. via dlopen)`` if an issue 
is detected.
 
 Some issues with flags can be debugged using the ``verbosity=$NUM`` flag:
 



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


[clang] [rtsan] Add `verify_interceptors` flag to docs (PR #119074)

2024-12-08 Thread Chris Apple via cfe-commits

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


[clang] be2df95 - Switch builtin strings to use string tables (#118734)

2024-12-08 Thread via cfe-commits

Author: Chandler Carruth
Date: 2024-12-08T19:00:14-08:00
New Revision: be2df95e9281985b61270bb6420ea0eeeffbbe59

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

LOG: Switch builtin strings to use string tables (#118734)

The Clang binary (and any binary linking Clang as a library), when built
using PIE, ends up with a pretty shocking number of dynamic relocations
to apply to the executable image: roughly 400k.

Each of these takes up binary space in the executable, and perhaps most
interestingly takes start-up time to apply the relocations.

The largest pattern I identified were the strings used to describe
target builtins. The addresses of these string literals were stored into
huge arrays, each one requiring a dynamic relocation. The way to avoid
this is to design the target builtins to use a single large table of
strings and offsets within the table for the individual strings. This
switches the builtin management to such a scheme.

This saves over 100k dynamic relocations by my measurement, an over 25%
reduction. Just looking at byte size improvements, using the `bloaty`
tool to compare a newly built `clang` binary to an old one:

```
FILE SIZEVM SIZE
 --  --
  +1.4%  +653Ki  +1.4%  +653Ki.rodata
  +0.0%+960  +0.0%+960.text
  +0.0%+197  +0.0%+197.dynstr
  +0.0%+184  +0.0%+184.eh_frame
  +0.0% +96  +0.0% +96.dynsym
  +0.0% +40  +0.0% +40.eh_frame_hdr
  +114% +32  [ = ]   0[Unmapped]
  +0.0% +20  +0.0% +20.gnu.hash
  +0.0%  +8  +0.0%  +8.gnu.version
  +0.9%  +7  +0.9%  +7[LOAD #2 [R]]
  [ = ]   0 -75.4% -3.00Ki.relro_padding
 -16.1%  -802Ki -16.1%  -802Ki.data.rel.ro
 -27.3% -2.52Mi -27.3% -2.52Mi.rela.dyn
  -1.6% -2.66Mi  -1.6% -2.66MiTOTAL
```

We get a 16% reduction in the `.data.rel.ro` section, and nearly 30%
reduction in `.rela.dyn` where those reloctaions are stored.

This is also visible in my benchmarking of binary start-up overhead at
least:

```
Benchmark 1: ./old_clang --version
  Time (mean ± σ):  17.6 ms ±   1.5 ms[User: 4.1 ms, System: 13.3 ms]
  Range (min … max):14.2 ms …  22.8 ms162 runs

Benchmark 2: ./new_clang --version
  Time (mean ± σ):  15.5 ms ±   1.4 ms[User: 3.6 ms, System: 11.8 ms]
  Range (min … max):12.4 ms …  20.3 ms216 runs

Summary
  './new_clang --version' ran
1.13 ± 0.14 times faster than './old_clang --version'
```

We get about 2ms faster `--version` runs. While there is a lot of noise
in binary execution time, this delta is pretty consistent, and
represents over 10% improvement. This is particularly interesting to me
because for very short source files, repeatedly starting the `clang`
binary is actually the dominant cost. For example, `configure` scripts
running against the `clang` compiler are slow in large part because of
binary start up time, not the time to process the actual inputs to the
compiler.



This PR implements the string tables using `constexpr` code and the
existing macro system. I understand that the builtins are moving towards
a TableGen model, and if complete that would provide more options for
modeling this. Unfortunately, that migration isn't complete, and even
the parts that are migrated still rely on the ability to break out of
the TableGen model and directly expand an X-macro style `BUILTIN(...)`
textually. I looked at trying to complete the move to TableGen, but it
would both require the difficult migration of the remaining targets, and
solving some tricky problems with how to move away from any macro-based
expansion.

I was also able to find a reasonably clean and effective way of doing
this with the existing macros and some `constexpr` code that I think is
clean enough to be a pretty good intermediate state, and maybe give a
good target for the eventual TableGen solution. I was also able to
factor the macros into set of consistent patterns that avoids a
significant regression in overall boilerplate.

Added: 


Modified: 
clang/include/clang/Basic/Builtins.h
clang/include/clang/Basic/BuiltinsPPC.def
clang/include/clang/Basic/TargetInfo.h
clang/lib/Basic/Builtins.cpp
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
clang/lib/Basic/Targets/AMDGPU.cpp
clang/lib/Basic/Targets/AMDGPU.h
clang/lib/Basic/Targets/ARC.h
clang/lib/Basic/Targets/ARM.cpp
clang/lib/Basic/Targets/ARM.h
clang/lib/Basic/Targets/AVR.h
clang/lib/Basic/Targets/BPF.cpp
clang/lib/Basic/Targets/BPF.h
clang/lib/Basic/Targets/CSKY.cpp
clang/lib/Basic/Targets/CSKY.h
clang/lib/Basic/Targets/DirectX.h
clang/lib/Basic/Targets/Hexagon.cpp
clang/lib/Basic/Targets/Hexagon.h
clang/lib/Basic/Targets/Lanai.h
clang/lib/Basic/Targets/LoongArch.c

[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-08 Thread Chandler Carruth via cfe-commits

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


[clang] [docs] Add a more detailed description in CXString.h. (PR #119090)

2024-12-08 Thread via cfe-commits


@@ -46,6 +46,9 @@ typedef struct {
 
 /**
  * Retrieve the character data associated with the given string.
+ *
+ * The caller shouldn't free the returned string data, and the returned string
+ * data shouldn't be accessed after the \c CXString disposed.

iseki0 wrote:

Sounds great, but in your sentence, you may have to define what is "valid". 
(You said "while the `CXString` is valid.") 
@compnerd 

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


[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-08 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `llvm-clang-x86_64-sie-win` 
running on `sie-win-worker` while building `clang` at step 7 
"test-build-unified-tree-check-all".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/46/builds/9169


Here is the relevant piece of the build log for the reference

```
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'Clang :: AST/builtins-arm-strex-rettype.c' FAILED 

Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
z:\b\llvm-clang-x86_64-sie-win\build\bin\clang.exe -cc1 -internal-isystem 
Z:\b\llvm-clang-x86_64-sie-win\build\lib\clang\20\include -nostdsysteminc 
-triple thumbv7m-apple-darwin-eabi -ast-dump 
Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\AST\builtins-arm-strex-rettype.c
 | z:\b\llvm-clang-x86_64-sie-win\build\bin\filecheck.exe 
Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\AST\builtins-arm-strex-rettype.c
# executed command: 'z:\b\llvm-clang-x86_64-sie-win\build\bin\clang.exe' -cc1 
-internal-isystem 'Z:\b\llvm-clang-x86_64-sie-win\build\lib\clang\20\include' 
-nostdsysteminc -triple thumbv7m-apple-darwin-eabi -ast-dump 
'Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\AST\builtins-arm-strex-rettype.c'
# .---command stderr
# | 
Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\AST\builtins-arm-strex-rettype.c:7:12:
 error: use of unknown builtin '__builtin_arm_strex' 
[-Wimplicit-function-declaration]
# | 7 |   } while (__builtin_arm_strex(a, b));
# |   |^
# | 1 error generated.
# `-
# error: command failed with exit status: 1
# executed command: 'z:\b\llvm-clang-x86_64-sie-win\build\bin\filecheck.exe' 
'Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\test\AST\builtins-arm-strex-rettype.c'

--




```



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


[clang] [compiler-rt] Move interceptors for libresolv functions to MSan (PR #119071)

2024-12-08 Thread Vitaly Buka via cfe-commits


@@ -1410,7 +1410,7 @@ void tools::linkSanitizerRuntimeDeps(const ToolChain &TC,
   // libresolv.a, even if exists, is an empty archive to satisfy POSIX -lresolv
   // requirement.
   if (TC.getTriple().isOSLinux() && !TC.getTriple().isAndroid() &&
-  !TC.getTriple().isMusl())
+  !TC.getTriple().isMusl() && TC.getSanitizerArgs(Args).needsMsanRt())

vitalybuka wrote:

I propose do not change this part at all, or in a separate PR

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


[clang-tools-extra] [clangd] Do not show `aParam` parameter hint for argument spelled `param` (PR #119162)

2024-12-08 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 created 
https://github.com/llvm/llvm-project/pull/119162

Fixes https://github.com/clangd/clangd/issues/2248

>From c207c5d0d651b564acec0a0b6ef257fb89752ba0 Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Mon, 21 Oct 2024 02:34:15 -0400
Subject: [PATCH] [clangd] Do not show `aParam` parameter hint for argument
 spelled `param`

Fixes https://github.com/clangd/clangd/issues/2248
---
 clang-tools-extra/clangd/InlayHints.cpp | 17 -
 .../clangd/unittests/InlayHintTests.cpp |  9 +
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index fefffeb4efc1a2..0ad0ffd86bd4c8 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -867,13 +867,28 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
 }
   }
 
+  static bool argumentMatchesParamName(StringRef ArgName, StringRef ParamName) 
{
+// Exact match.
+if (ParamName == ArgName)
+  return true;
+
+// Parameter name uses "a" prefix (e.g. "aParam").
+if (ParamName.size() > 1 && ParamName[0] == 'a' &&
+std::isupper(ParamName[1])) {
+  return ArgName.size() > 0 && ArgName[0] == std::tolower(ParamName[1]) &&
+ ArgName.drop_front() == ParamName.drop_front(2);
+}
+
+return false;
+  }
+
   bool shouldHintName(const Expr *Arg, StringRef ParamName) {
 if (ParamName.empty())
   return false;
 
 // If the argument expression is a single name and it matches the
 // parameter name exactly, omit the name hint.
-if (ParamName == getSpelledIdentifier(Arg))
+if (argumentMatchesParamName(getSpelledIdentifier(Arg), ParamName))
   return false;
 
 // Exclude argument expressions preceded by a /*paramName*/.
diff --git a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp 
b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
index 77d78b8777fe30..3f9795c2330b85 100644
--- a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1011,6 +1011,7 @@ TEST(ParameterHints, FunctionPointer) {
 TEST(ParameterHints, ArgMatchesParam) {
   assertParameterHints(R"cpp(
 void foo(int param);
+void prefixConvention(int aParam);
 struct S {
   static const int param = 42;
 };
@@ -1018,6 +1019,12 @@ TEST(ParameterHints, ArgMatchesParam) {
   int param = 42;
   // Do not show redundant "param: param".
   foo(param);
+  // Some codebases have a naming convention of prefixing
+  // parameter names with "a", e.g. "aParam". (The "a"
+  // stands for "argument", used as an (imprecise) synonym
+  // for "parameter".)
+  // Do not show "aParam: param" either.
+  prefixConvention(param);
   // But show it if the argument is qualified.
   foo($param[[S::param]]);
 }
@@ -1026,6 +1033,8 @@ TEST(ParameterHints, ArgMatchesParam) {
   void bar() {
 // Do not show "param: param" for member-expr.
 foo(param);
+// Nor "aParam: param"
+prefixConvention(param);
   }
 };
   )cpp",

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


[clang-tools-extra] [clangd] Do not show `aParam` parameter hint for argument spelled `param` (PR #119162)

2024-12-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangd

Author: Nathan Ridge (HighCommander4)


Changes

Fixes https://github.com/clangd/clangd/issues/2248

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


2 Files Affected:

- (modified) clang-tools-extra/clangd/InlayHints.cpp (+16-1) 
- (modified) clang-tools-extra/clangd/unittests/InlayHintTests.cpp (+9) 


``diff
diff --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index fefffeb4efc1a2..0ad0ffd86bd4c8 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -867,13 +867,28 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
 }
   }
 
+  static bool argumentMatchesParamName(StringRef ArgName, StringRef ParamName) 
{
+// Exact match.
+if (ParamName == ArgName)
+  return true;
+
+// Parameter name uses "a" prefix (e.g. "aParam").
+if (ParamName.size() > 1 && ParamName[0] == 'a' &&
+std::isupper(ParamName[1])) {
+  return ArgName.size() > 0 && ArgName[0] == std::tolower(ParamName[1]) &&
+ ArgName.drop_front() == ParamName.drop_front(2);
+}
+
+return false;
+  }
+
   bool shouldHintName(const Expr *Arg, StringRef ParamName) {
 if (ParamName.empty())
   return false;
 
 // If the argument expression is a single name and it matches the
 // parameter name exactly, omit the name hint.
-if (ParamName == getSpelledIdentifier(Arg))
+if (argumentMatchesParamName(getSpelledIdentifier(Arg), ParamName))
   return false;
 
 // Exclude argument expressions preceded by a /*paramName*/.
diff --git a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp 
b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
index 77d78b8777fe30..3f9795c2330b85 100644
--- a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1011,6 +1011,7 @@ TEST(ParameterHints, FunctionPointer) {
 TEST(ParameterHints, ArgMatchesParam) {
   assertParameterHints(R"cpp(
 void foo(int param);
+void prefixConvention(int aParam);
 struct S {
   static const int param = 42;
 };
@@ -1018,6 +1019,12 @@ TEST(ParameterHints, ArgMatchesParam) {
   int param = 42;
   // Do not show redundant "param: param".
   foo(param);
+  // Some codebases have a naming convention of prefixing
+  // parameter names with "a", e.g. "aParam". (The "a"
+  // stands for "argument", used as an (imprecise) synonym
+  // for "parameter".)
+  // Do not show "aParam: param" either.
+  prefixConvention(param);
   // But show it if the argument is qualified.
   foo($param[[S::param]]);
 }
@@ -1026,6 +1033,8 @@ TEST(ParameterHints, ArgMatchesParam) {
   void bar() {
 // Do not show "param: param" for member-expr.
 foo(param);
+// Nor "aParam: param"
+prefixConvention(param);
   }
 };
   )cpp",

``




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


[clang-tools-extra] [clangd] Do not show `aParam` parameter hint for argument spelled `param` (PR #119162)

2024-12-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: Nathan Ridge (HighCommander4)


Changes

Fixes https://github.com/clangd/clangd/issues/2248

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


2 Files Affected:

- (modified) clang-tools-extra/clangd/InlayHints.cpp (+16-1) 
- (modified) clang-tools-extra/clangd/unittests/InlayHintTests.cpp (+9) 


``diff
diff --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index fefffeb4efc1a2..0ad0ffd86bd4c8 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -867,13 +867,28 @@ class InlayHintVisitor : public 
RecursiveASTVisitor {
 }
   }
 
+  static bool argumentMatchesParamName(StringRef ArgName, StringRef ParamName) 
{
+// Exact match.
+if (ParamName == ArgName)
+  return true;
+
+// Parameter name uses "a" prefix (e.g. "aParam").
+if (ParamName.size() > 1 && ParamName[0] == 'a' &&
+std::isupper(ParamName[1])) {
+  return ArgName.size() > 0 && ArgName[0] == std::tolower(ParamName[1]) &&
+ ArgName.drop_front() == ParamName.drop_front(2);
+}
+
+return false;
+  }
+
   bool shouldHintName(const Expr *Arg, StringRef ParamName) {
 if (ParamName.empty())
   return false;
 
 // If the argument expression is a single name and it matches the
 // parameter name exactly, omit the name hint.
-if (ParamName == getSpelledIdentifier(Arg))
+if (argumentMatchesParamName(getSpelledIdentifier(Arg), ParamName))
   return false;
 
 // Exclude argument expressions preceded by a /*paramName*/.
diff --git a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp 
b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
index 77d78b8777fe30..3f9795c2330b85 100644
--- a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -1011,6 +1011,7 @@ TEST(ParameterHints, FunctionPointer) {
 TEST(ParameterHints, ArgMatchesParam) {
   assertParameterHints(R"cpp(
 void foo(int param);
+void prefixConvention(int aParam);
 struct S {
   static const int param = 42;
 };
@@ -1018,6 +1019,12 @@ TEST(ParameterHints, ArgMatchesParam) {
   int param = 42;
   // Do not show redundant "param: param".
   foo(param);
+  // Some codebases have a naming convention of prefixing
+  // parameter names with "a", e.g. "aParam". (The "a"
+  // stands for "argument", used as an (imprecise) synonym
+  // for "parameter".)
+  // Do not show "aParam: param" either.
+  prefixConvention(param);
   // But show it if the argument is qualified.
   foo($param[[S::param]]);
 }
@@ -1026,6 +1033,8 @@ TEST(ParameterHints, ArgMatchesParam) {
   void bar() {
 // Do not show "param: param" for member-expr.
 foo(param);
+// Nor "aParam: param"
+prefixConvention(param);
   }
 };
   )cpp",

``




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


[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-08 Thread Chandler Carruth via cfe-commits

chandlerc wrote:

> LLVM Buildbot has detected a new failure on builder 
> `llvm-clang-x86_64-sie-win` running on `sie-win-worker` while building 
> `clang` at step 7 "test-build-unified-tree-check-all".
> 
> Full details are available at: 
> [lab.llvm.org/buildbot#/builders/46/builds/9169](https://lab.llvm.org/buildbot/#/builders/46/builds/9169)

This is a Windows build bot with a version of MSVC '19.28.29924.0' -- that's 
not even one of the numbers listed here: 
https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B#Internal_version_numbering

Looks like it might be a pre-release of 16.9.0, but the first listed version of 
that is '19.28.29910' at least on the Wikipedia page. Not sure what to do debug 
this... @zmodem maybe has some idea?

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


[clang] [compiler-rt] Move interceptors for libresolv functions to MSan (PR #119071)

2024-12-08 Thread Vitaly Buka via cfe-commits

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


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


[clang] [clang] constexpr built-in elementwise add_sat/sub_sat functions. (PR #119082)

2024-12-08 Thread via cfe-commits

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


[clang-tools-extra] [clangd] Consider expression statements in ExtractVariable tweak (PR #112525)

2024-12-08 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

@ckandeler Could you elaborate on the motivation for this change?

In my mind, the value proposition of the "extract variable" refactoring is that 
it saves you the work of moving the expression from one location to another, 
and typing the name of the variable twice (once at the declaration and once at 
the use).

In the expression-statement case, the expression isn't moving to a new 
location, and the variable name is only mentioned in one place. In essence, the 
refactoring amounts to prepending `auto placeholder = ` to the expression. 
Given that you're going to be (very likely) renaming `placeholder` anyways, 
does this really add anything meaningful over just typing `auto 
VariableNameYouWant = ` "manually"?

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


[clang] [Clang] Recurse into parsing when using pack-indexing as a specifier (PR #119123)

2024-12-08 Thread Younan Zhang via cfe-commits

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


[clang] [Clang] Recurse into parsing when using pack-indexing as a specifier (PR #119123)

2024-12-08 Thread Younan Zhang via cfe-commits

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


[clang] [clang-tools-extra] [clangd][clang-tidy] Make clangd run `format::cleanupAroundReplacements()` for all code actions just as clang-tidy does (PR #118569)

2024-12-08 Thread Richard Li via cfe-commits

https://github.com/chomosuke updated 
https://github.com/llvm/llvm-project/pull/118569

>From efc17a803c9c22543de7d5f9e960a7267ade1f2e Mon Sep 17 00:00:00 2001
From: chomosuke 
Date: Wed, 4 Dec 2024 14:42:24 +
Subject: [PATCH 1/2] [clangd][clang-tidy] Make clangd run
 `format::cleanupAroundReplacements()` for all code actions just as clang-tidy
 does

---
 clang-tools-extra/clang-tidy/ClangTidy.cpp| 22 ++--
 clang-tools-extra/clangd/Diagnostics.cpp  | 35 -
 .../clangd/unittests/DiagnosticsTests.cpp | 51 ---
 .../include/clang/Tooling/Core/Replacement.h  |  4 ++
 clang/lib/Tooling/Core/Replacement.cpp| 16 +-
 5 files changed, 99 insertions(+), 29 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp 
b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 9c8c93c5d16c72..82331c724eaaf2 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -149,26 +149,12 @@ class ErrorReporter {
Repl.getLength(), 
Repl.getReplacementText());
 auto &Entry = FileReplacements[R.getFilePath()];
 Replacements &Replacements = Entry.Replaces;
-llvm::Error Err = Replacements.add(R);
+llvm::Error Err = Replacements.addOrMerge(R);
 if (Err) {
   // FIXME: Implement better conflict handling.
-  llvm::errs() << "Trying to resolve conflict: "
-   << llvm::toString(std::move(Err)) << "\n";
-  unsigned NewOffset =
-  Replacements.getShiftedCodePosition(R.getOffset());
-  unsigned NewLength = Replacements.getShiftedCodePosition(
-   R.getOffset() + R.getLength()) -
-   NewOffset;
-  if (NewLength == R.getLength()) {
-R = Replacement(R.getFilePath(), NewOffset, NewLength,
-R.getReplacementText());
-Replacements = Replacements.merge(tooling::Replacements(R));
-CanBeApplied = true;
-++AppliedFixes;
-  } else {
-llvm::errs()
-<< "Can't resolve conflict, skipping the replacement.\n";
-  }
+  llvm::errs()
+  << "Can't resolve conflict, skipping the replacement: "
+  << llvm::toString(std::move(Err)) << '\n';
 } else {
   CanBeApplied = true;
   ++AppliedFixes;
diff --git a/clang-tools-extra/clangd/Diagnostics.cpp 
b/clang-tools-extra/clangd/Diagnostics.cpp
index a59d1e7ac84096..60c6ac7256b58c 100644
--- a/clang-tools-extra/clangd/Diagnostics.cpp
+++ b/clang-tools-extra/clangd/Diagnostics.cpp
@@ -19,6 +19,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TokenKinds.h"
+#include "clang/Format/Format.h"
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/Token.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -741,7 +742,7 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level 
DiagLevel,
   return false;
 // Copy as we may modify the ranges.
 auto FixIts = Info.getFixItHints().vec();
-llvm::SmallVector Edits;
+auto Replacements = std::make_optional();
 for (auto &FixIt : FixIts) {
   // Allow fixits within a single macro-arg expansion to be applied.
   // This can be incorrect if the argument is expanded multiple times in
@@ -761,7 +762,37 @@ void StoreDiags::HandleDiagnostic(DiagnosticsEngine::Level 
DiagLevel,
 return false;
   if (!isInsideMainFile(FixIt.RemoveRange.getBegin(), SM))
 return false;
-  Edits.push_back(toTextEdit(FixIt, SM, *LangOpts));
+
+  auto R = tooling::Replacement(SM, FixIt.RemoveRange, FixIt.CodeToInsert,
+*LangOpts);
+  auto Err = Replacements->addOrMerge(R);
+  if (Err) {
+log("Skipping formatting the replacement due to conflict: {0}",
+llvm::toString(std::move(Err)));
+Replacements = std::nullopt;
+break;
+  }
+}
+
+llvm::SmallVector Edits;
+
+if (Replacements) {
+  StringRef Code = SM.getBufferData(SM.getMainFileID());
+  auto Repl = format::cleanupAroundReplacements(Code, *Replacements,
+format::getNoStyle());
+  if (!Repl) {
+log("Skipping formatting the replacement due to conflict: {0}",
+llvm::toString(std::move(Repl.takeError(;
+Replacements = std::nullopt;
+  } else {
+auto Es = replacementsToEdits(Code, *Repl);
+Edits.append(Es.begin(), Es.end());
+  }
+}
+if (!Replacements) {
+  for (auto &FixIt : FixIts) {
+Edits.push_back(toTextEdit(FixIt, SM, *LangOpts));
+  }
 }
 
 llvm::SmallString<64> Message;
diff --git a/clang-tools-extra/clangd/unitte

[clang] a4506bb - [Clang] Recurse into parsing when using pack-indexing as a specifier (#119123)

2024-12-08 Thread via cfe-commits

Author: Younan Zhang
Date: 2024-12-09T09:58:37+08:00
New Revision: a4506bb340c36d48d89afe5bd76a1a2f28f76fd9

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

LOG: [Clang] Recurse into parsing when using pack-indexing as a specifier 
(#119123)

Pack indexing type that introduces a scope, e.g. `T...[0]::value` would
be annotated as `annot_cxxscope`. This is something we didn't handle in
`ParseCastExpression`, causing it to mistakely fall through to the logic
for `raw_identifier`.

We should recurse into parsing the following specifiers for such cases.

Closes #119072

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Parse/ParseExpr.cpp
clang/test/Parser/cxx2c-pack-indexing.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 52b03c023b84d4..95007f357b766f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -795,6 +795,7 @@ Bug Fixes to C++ Support
 - Fixed a bug where bounds of partially expanded pack indexing expressions 
were checked too early. (#GH116105)
 - Fixed an assertion failure caused by using ``consteval`` in condition in 
consumed analyses. (#GH117385)
 - Fix a crash caused by incorrect argument position in merging deduced 
template arguments. (#GH113659)
+- Fixed a parser crash when using pack indexing as a nested name specifier. 
(#GH119072) 
 - Fixed an assertion failure caused by mangled names with invalid identifiers. 
(#GH112205)
 - Fixed an incorrect lambda scope of generic lambdas that caused Clang to 
crash when computing potential lambda
   captures at the end of a full expression. (#GH115931)

diff  --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 736484ded8383c..8dd72db8f5b4a2 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1199,7 +1199,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
 // If the token is not annotated, then it might be an expression pack
 // indexing
 if (!TryAnnotateTypeOrScopeToken() &&
-Tok.is(tok::annot_pack_indexing_type))
+Tok.isOneOf(tok::annot_pack_indexing_type, tok::annot_cxxscope))
   return ParseCastExpression(ParseKind, isAddressOfOperand, isTypeCast,
  isVectorLiteral, NotPrimaryExpression);
   }

diff  --git a/clang/test/Parser/cxx2c-pack-indexing.cpp 
b/clang/test/Parser/cxx2c-pack-indexing.cpp
index c279bdd7af8c44..99347a2f8f1571 100644
--- a/clang/test/Parser/cxx2c-pack-indexing.cpp
+++ b/clang/test/Parser/cxx2c-pack-indexing.cpp
@@ -74,3 +74,12 @@ struct SS {
 }
 };
 }
+
+namespace GH119072 {
+
+template
+void foo() {
+  decltype(Ts...[0]::t) value;
+}
+
+}



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


[clang] Reland [Clang] skip default argument instantiation for non-defining friend declarations to meet [dcl.fct.default] p4 (PR #115487)

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


@@ -4692,6 +4692,17 @@ bool Sema::InstantiateDefaultArgument(SourceLocation 
CallLoc, FunctionDecl *FD,
   ParmVarDecl *Param) {
   assert(Param->hasUninstantiatedDefaultArg());
 
+  // FIXME: We don't track member specialization info for non-defining
+  // friend declarations, so we will not be able to later find the function
+  // pattern. As a workaround, don't instantiate the default argument in this
+  // case. This is correct per wording and only an error recovery issue, as per

a-tarasyuk wrote:

@erichkeane okay, thanks. As far as I remember, this case isn't processed with 
recovery; however, I'll check it anyway.

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


[clang] [llvm] [AArch64] Add initial support for FUJITSU-MONAKA (PR #118432)

2024-12-08 Thread Yuta Mukai via cfe-commits

ytmukai wrote:

Thank you for your reviews and help! Delayed due to holidays, but I will submit 
it.

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


[clang] a1197a2 - [AArch64] Add initial support for FUJITSU-MONAKA (#118432)

2024-12-08 Thread via cfe-commits

Author: Kinoshita Kotaro
Date: 2024-12-09T09:56:02+09:00
New Revision: a1197a2ca8a77c08a36445401a063a1c4efec6a9

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

LOG: [AArch64]  Add initial support for FUJITSU-MONAKA (#118432)

This patch adds initial support for FUJITSU-MONAKA CPU (-mcpu=fujitsu-monaka).

The scheduling model will be corrected in the future.

Added: 
clang/test/Driver/aarch64-fujitsu-monaka.c
clang/test/Driver/print-enabled-extensions/aarch64-fujitsu-monaka.c

Modified: 
clang/test/Misc/target-invalid-cpu-note/aarch64.c
llvm/lib/Target/AArch64/AArch64Processors.td
llvm/lib/Target/AArch64/AArch64Subtarget.cpp
llvm/lib/TargetParser/Host.cpp
llvm/test/CodeGen/AArch64/cpus.ll
llvm/unittests/TargetParser/Host.cpp
llvm/unittests/TargetParser/TargetParserTest.cpp

Removed: 




diff  --git a/clang/test/Driver/aarch64-fujitsu-monaka.c 
b/clang/test/Driver/aarch64-fujitsu-monaka.c
new file mode 100644
index 00..df96b36bace681
--- /dev/null
+++ b/clang/test/Driver/aarch64-fujitsu-monaka.c
@@ -0,0 +1,13 @@
+// RUN: %clang --target=aarch64 -mcpu=fujitsu-monaka -### -c %s 2>&1 | 
FileCheck -check-prefix=fujitsu-monaka %s
+// RUN: %clang --target=aarch64 -mlittle-endian -mcpu=fujitsu-monaka -### -c 
%s 2>&1 | FileCheck -check-prefix=fujitsu-monaka %s
+// RUN: %clang --target=aarch64 -mtune=fujitsu-monaka -### -c %s 2>&1 | 
FileCheck -check-prefix=fujitsu-monaka-TUNE %s
+// RUN: %clang --target=aarch64 -mlittle-endian -mtune=fujitsu-monaka -### -c 
%s 2>&1 | FileCheck -check-prefix=fujitsu-monaka-TUNE %s
+// fujitsu-monaka: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"fujitsu-monaka"
+// fujitsu-monaka-TUNE: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"generic"
+
+// RUN: %clang --target=arm64 -mcpu=fujitsu-monaka -### -c %s 2>&1 | FileCheck 
-check-prefix=ARM64-fujitsu-monaka %s
+// RUN: %clang --target=arm64 -mlittle-endian -mcpu=fujitsu-monaka -### -c %s 
2>&1 | FileCheck -check-prefix=ARM64-fujitsu-monaka %s
+// RUN: %clang --target=arm64 -mtune=fujitsu-monaka -### -c %s 2>&1 | 
FileCheck -check-prefix=ARM64-fujitsu-monaka-TUNE %s
+// RUN: %clang --target=arm64 -mlittle-endian -mtune=fujitsu-monaka -### -c %s 
2>&1 | FileCheck -check-prefix=ARM64-fujitsu-monaka-TUNE %s
+// ARM64-fujitsu-monaka: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" 
"fujitsu-monaka"
+// ARM64-fujitsu-monaka-TUNE: "-cc1"{{.*}} "-triple" "arm64{{.*}}" 
"-target-cpu" "generic"

diff  --git 
a/clang/test/Driver/print-enabled-extensions/aarch64-fujitsu-monaka.c 
b/clang/test/Driver/print-enabled-extensions/aarch64-fujitsu-monaka.c
new file mode 100644
index 00..3c74e3620df034
--- /dev/null
+++ b/clang/test/Driver/print-enabled-extensions/aarch64-fujitsu-monaka.c
@@ -0,0 +1,82 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang --target=aarch64 --print-enabled-extensions 
-mcpu=fujitsu-monaka | FileCheck --strict-whitespace --implicit-check-not=FEAT_ 
%s
+
+// CHECK: Extensions enabled for the given AArch64 target
+// CHECK-EMPTY:
+// CHECK-NEXT: Architecture Feature(s)
Description
+// CHECK-NEXT: FEAT_AES, FEAT_PMULL   
Enable AES support
+// CHECK-NEXT: FEAT_AMUv1 
Enable Armv8.4-A Activity Monitors extension
+// CHECK-NEXT: FEAT_AMUv1p1   
Enable Armv8.6-A Activity Monitors Virtualization support
+// CHECK-NEXT: FEAT_AdvSIMD   
Enable Advanced SIMD instructions
+// CHECK-NEXT: FEAT_BF16  
Enable BFloat16 Extension
+// CHECK-NEXT: FEAT_BTI   
Enable Branch Target Identification
+// CHECK-NEXT: FEAT_CCIDX 
Enable Armv8.3-A Extend of the CCSIDR number of sets
+// CHECK-NEXT: FEAT_CLRBHB
Enable Clear BHB instruction
+// CHECK-NEXT: FEAT_CRC32 
Enable Armv8.0-A CRC-32 checksum instructions
+// CHECK-NEXT: FEAT_CSV2_2
Enable architectural speculation restriction
+// CHECK-NEXT: FEAT_DIT   
Enable Armv8.4-A Data Independent Timing instructions
+// CHECK-NEXT: FEAT_DPB   
Enable Armv8.2-A data Cache Clean to Point of Persistence
+// CHECK-NEXT: FEAT_DPB2  
Enable Armv8.5-A Cache Clean to Point of Deep Persistence
+// CHECK-NEXT: FEAT_DotProd   
Enable do

[clang] [llvm] [AArch64] Add initial support for FUJITSU-MONAKA (PR #118432)

2024-12-08 Thread Yuta Mukai via cfe-commits

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


[clang] [llvm] [AArch64] Add initial support for FUJITSU-MONAKA (PR #118432)

2024-12-08 Thread via cfe-commits

github-actions[bot] wrote:



@kinoshita-fj Congratulations on having your first Pull Request (PR) merged 
into the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a 
problem with a build, you may receive a report in an email or a comment on this 
PR.

Please check whether problems have been caused by your change specifically, as 
the builds can include changes from many authors. It is not uncommon for your 
change to be included in a build that fails due to someone else's changes, or 
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself. This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-08 Thread Chandler Carruth via cfe-commits

https://github.com/chandlerc updated 
https://github.com/llvm/llvm-project/pull/118734

>From 9553557e87ec5d9ae5ce5636f6227150fcd080bc Mon Sep 17 00:00:00 2001
From: Chandler Carruth 
Date: Thu, 28 Nov 2024 09:56:40 +
Subject: [PATCH 1/6] Switch builtin strings to use string tables
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The Clang binary (and any binary linking Clang as a library), when built
using PIE, ends up with a pretty shocking number of dynamic relocations
to apply to the executable image: roughly 400k.

Each of these takes up binary space in the executable, and perhaps most
interestingly takes start-up time to apply the relocations.

The largest pattern I identified were the strings used to describe
target builtins. The addresses of these string literals were stored into
huge arrays, each one requiring a dynamic relocation. The way to avoid
this is to design the target builtins to use a single large table of
strings and offsets within the table for the individual strings. This
switches the builtin management to such a scheme.

This saves over 100k dynamic relocations by my measurement, an over 25%
reduction. Just looking at byte size improvements, using the `bloaty`
tool to compare a newly built `clang` binary to an old one:

```
FILE SIZEVM SIZE
 --  --
  +1.4%  +653Ki  +1.4%  +653Ki.rodata
  +0.0%+960  +0.0%+960.text
  +0.0%+197  +0.0%+197.dynstr
  +0.0%+184  +0.0%+184.eh_frame
  +0.0% +96  +0.0% +96.dynsym
  +0.0% +40  +0.0% +40.eh_frame_hdr
  +114% +32  [ = ]   0[Unmapped]
  +0.0% +20  +0.0% +20.gnu.hash
  +0.0%  +8  +0.0%  +8.gnu.version
  +0.9%  +7  +0.9%  +7[LOAD #2 [R]]
  [ = ]   0 -75.4% -3.00Ki.relro_padding
 -16.1%  -802Ki -16.1%  -802Ki.data.rel.ro
 -27.3% -2.52Mi -27.3% -2.52Mi.rela.dyn
  -1.6% -2.66Mi  -1.6% -2.66MiTOTAL
```

We get a 16% reduction in the `.data.rel.ro` section, and nearly 30%
reduction in `.rela.dyn` where those reloctaions are stored.

This is also visible in my benchmarking of binary start-up overhead at
least:

```
Benchmark 1: ./old_clang --version
  Time (mean ± σ):  17.6 ms ±   1.5 ms[User: 4.1 ms, System: 13.3 ms]
  Range (min … max):14.2 ms …  22.8 ms162 runs

Benchmark 2: ./new_clang --version
  Time (mean ± σ):  15.5 ms ±   1.4 ms[User: 3.6 ms, System: 11.8 ms]
  Range (min … max):12.4 ms …  20.3 ms216 runs

Summary
  './new_clang --version' ran
1.13 ± 0.14 times faster than './old_clang --version'
```

We get about 2ms faster `--version` runs. While there is a lot of noise
in binary execution time, this delta is pretty consistent, and
represents over 10% improvement. This is particularly interesting to me
because for very short source files, repeatedly starting the `clang`
binary is actually the dominant cost. For example, `configure` scripts
running against the `clang` compiler are slow in large part because of
binary start up time, not the time to process the actual inputs to the
compiler.



This PR implements the string tables using `constexpr` code and the
existing macro system. I understand that the builtins are moving towards
a TableGen model, and if complete that would provide more options for
modeling this. Unfortunately, that migration isn't complete, and even
the parts that are migrated still rely on the ability to break out of
the TableGen model and directly expand an X-macro style `BUILTIN(...)`
textually. I looked at trying to complete the move to TableGen, but it
would both require the difficult migration of the remaining targets, and
solving some tricky problems with how to move away from any macro-based
expansion.

I was also able to find a reasonably clean and effective way of doing
this with the existing macros and some `constexpr` code that I think is
clean enough to be a pretty good intermediate state, and maybe give
a good target for the eventual TableGen solution. I was also able to
factor the macros into set of consistent patterns that avoids
a significant regression in overall boilerplate.

There is one challenge with this approach: it requires the host compiler
to support (very) long string literals, a bit over half a meg. =/ The
current minimum MSVC version rejects these, but the very next patch
release (16.8) removed that restriction. I'm going to send out
a separate PR / RFC to raise the minimum version by one patch release,
which I hope is acceptable as the current version was set years ago.

FWIW, there are a few more low-hanging fruit sources of excessive
dynamic relocations, maybe as many as 50k to 100k more that I'll take
a look at to see if I can identify easy fixes. Beyond that, it seems to
get quite difficult. It might be worth adding some guidance to developer
documentation to try to avoid creating global data structures that
_repeatedly_ store pointers to oth

[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-08 Thread Chandler Carruth via cfe-commits

chandlerc wrote:

> Confirmed that this works on GCC now. I'd suggest to replace the use of 
> StringLiteral::size with plain sizeof(). The build time overhead of going 
> through StringLiteral here is substantial.

Sure. I was initially worried about the subtlety of this use of `sizeof`, but 
that was before everything got nicely factored into macros. And yeah, the 
compile time cost is unfortunate.

Will merge once updated (including this fix) and builds passing.

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


[clang] f145ff3 - [clang] constexpr built-in elementwise add_sat/sub_sat functions. (#119082)

2024-12-08 Thread via cfe-commits

Author: c8ef
Date: 2024-12-09T09:28:12+08:00
New Revision: f145ff3f70d0c1a71d08613f692376003ab398b9

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

LOG: [clang] constexpr built-in elementwise add_sat/sub_sat functions.  
(#119082)

Part of #51787.

This patch adds constexpr support for the built-in elementwise add_sat
and sub_sat functions.

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Builtins.td
clang/lib/AST/ExprConstant.cpp
clang/test/CodeGen/builtins-elementwise-math.c
clang/test/Sema/constant_builtins_vector.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 6b950d05fb9bf9..6a886a49ea0762 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -648,7 +648,8 @@ elementwise to the input.
 Unless specified otherwise operation(±0) = ±0 and operation(±infinity) = 
±infinity
 
 The integer elementwise intrinsics, including 
``__builtin_elementwise_popcount``,
-``__builtin_elementwise_bitreverse``, can be called in a ``constexpr`` context.
+``__builtin_elementwise_bitreverse``, ``__builtin_elementwise_add_sat``,
+``__builtin_elementwise_sub_sat`` can be called in a ``constexpr`` context.
 
 == 
== 
=
  Name   Operation  
   Supported element types

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 12d8ebf3251bc0..52b03c023b84d4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -408,12 +408,11 @@ Non-comprehensive list of changes in this release
   The flexible array member (FAM) can now be accessed immediately without 
causing
   issues with the sanitizer because the counter is automatically set.
 
-- ``__builtin_reduce_add`` function can now be used in constant expressions.
-- ``__builtin_reduce_mul`` function can now be used in constant expressions.
-- ``__builtin_reduce_and`` function can now be used in constant expressions.
-- ``__builtin_reduce_or`` and ``__builtin_reduce_xor`` functions can now be 
used in constant expressions.
-- ``__builtin_elementwise_popcount`` function can now be used in constant 
expressions.
-- ``__builtin_elementwise_bitreverse`` function can now be used in constant 
expressions.
+- The following builtins can now be used in constant expressions: 
``__builtin_reduce_add``,
+  ``__builtin_reduce_mul``, ``__builtin_reduce_and``, ``__builtin_reduce_or``,
+  ``__builtin_reduce_xor``, ``__builtin_elementwise_popcount``,
+  ``__builtin_elementwise_bitreverse``, ``__builtin_elementwise_add_sat``,
+  ``__builtin_elementwise_sub_sat``.
 
 New Compiler Flags
 --

diff  --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index e2c3d3c535571c..32a09e2ceb3857 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1450,13 +1450,13 @@ def ElementwiseFma : Builtin {
 
 def ElementwiseAddSat : Builtin {
   let Spellings = ["__builtin_elementwise_add_sat"];
-  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 
 def ElementwiseSubSat : Builtin {
   let Spellings = ["__builtin_elementwise_sub_sat"];
-  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Attributes = [NoThrow, Const, CustomTypeChecking, Constexpr];
   let Prototype = "void(...)";
 }
 

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6b5b95aee35522..86313fbde0b4a7 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11339,6 +11339,37 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
 
 return Success(APValue(ResultElements.data(), ResultElements.size()), E);
   }
+  case Builtin::BI__builtin_elementwise_add_sat:
+  case Builtin::BI__builtin_elementwise_sub_sat: {
+APValue SourceLHS, SourceRHS;
+if (!EvaluateAsRValue(Info, E->getArg(0), SourceLHS) ||
+!EvaluateAsRValue(Info, E->getArg(1), SourceRHS))
+  return false;
+
+QualType DestEltTy = E->getType()->castAs()->getElementType();
+unsigned SourceLen = SourceLHS.getVectorLength();
+SmallVector ResultElements;
+ResultElements.reserve(SourceLen);
+
+for (unsigned EltNum = 0; EltNum < SourceLen; ++EltNum) {
+  APSInt LHS = SourceLHS.getVectorElt(EltNum).getInt();
+  APSInt RHS = SourceRHS.getVectorElt(EltNum).getInt();
+  switch (E->get

[clang] [Clang] Deleting an incomplete enum type is not an error (PR #119077)

2024-12-08 Thread Alexander Kornienko via cfe-commits

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

Thanks for the fix! LGTM

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


[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-08 Thread Brian Cain via cfe-commits

androm3da wrote:

cc @llvm/pr-subscribers-backend-hexagon and @iajbar 

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


[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-08 Thread Chandler Carruth via cfe-commits

chandlerc wrote:

> > > > > LLVM Buildbot has detected a new failure on builder 
> > > > > `llvm-clang-x86_64-sie-win` running on `sie-win-worker` while 
> > > > > building `clang` at step 7 "test-build-unified-tree-check-all".
> > > > > Full details are available at: 
> > > > > [lab.llvm.org/buildbot#/builders/46/builds/9169](https://lab.llvm.org/buildbot/#/builders/46/builds/9169)
> > > > 
> > > > 
> > > > This is a Windows build bot with a version of MSVC '19.28.29924.0' -- 
> > > > that's not even one of the numbers listed here: 
> > > > [en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B#Internal_version_numbering](https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B#Internal_version_numbering)
> > > > (edit because I can't count)
> > > > Looks like it might be a build after 16.9.19 which is listed as 
> > > > 19.28.29923. Not sure what to do debug this... @zmodem maybe has some 
> > > > idea?
> > > > It doesn't seem to be the issue I know about on older versions of MSVC 
> > > > as there are no errors on the long string literal. But somehow it seems 
> > > > to be miscompiling the string literals?
> > > 
> > > 
> > > I manage this build bot, is there anything I can do to help you debug 
> > > this problem? We use this build as our "blessed" build internally for 
> > > building on Windows.
> > 
> > 
> > Some indication of what's causing this? Or maybe whether there are any 
> > other versions of MSVC available with different results?
> > I don't have a Windows machine to debug on at all, but the premerge windows 
> > build was successful, so it seems to work on some builders but not others. 
> > So far I don't have any other failures to look at to cross-compare...
> 
> I'll pull the machine offline and try to take a look. There appear to be two 
> types of problems, 1 is an assertion failure in the pch related tests, the 
> other use of an "unknown" builtin.

I'm guessing they're the same issue, just a difference of whether hitting 
assert or a diagnostic first. Some strings for builtin names aren't coming back 
out of the tables correctly -- we fail to recognize it in one place, and hit an 
assert in the other.

My best guess is something going wrong with the string literals generated by 
the macros in this PR, or something going wrong with `sizeof` computing 
offsets... I'll do some experiments with compiler explorer, and see if I can 
get lucky...

If we need to revert the PR, totally understand, just a bit odd given only one 
compiler seems to be hitting the issue here.

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


[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-08 Thread via cfe-commits

dyung wrote:

> > LLVM Buildbot has detected a new failure on builder 
> > `llvm-clang-x86_64-sie-win` running on `sie-win-worker` while building 
> > `clang` at step 7 "test-build-unified-tree-check-all".
> > Full details are available at: 
> > [lab.llvm.org/buildbot#/builders/46/builds/9169](https://lab.llvm.org/buildbot/#/builders/46/builds/9169)
> 
> This is a Windows build bot with a version of MSVC '19.28.29924.0' -- that's 
> not even one of the numbers listed here: 
> https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B#Internal_version_numbering
> 
> (edit because I can't count)
> 
> Looks like it might be a build after 16.9.19 which is listed as 19.28.29923. 
> Not sure what to do debug this... @zmodem maybe has some idea?
> 
> It doesn't seem to be the issue I know about on older versions of MSVC as 
> there are no errors on the long string literal. But somehow it seems to be 
> miscompiling the string literals?

I manage this build bot, is there anything I can do to help you debug this 
problem? We use this build as our "blessed" build internally for building on 
Windows.

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


[clang] [clang][ARM] disable frame pointers by default for bare metal ARM targets (PR #117140)

2024-12-08 Thread Alex Bradbury via cfe-commits

asb wrote:

I think this change in behaviour deserves an entry in 
clang/docs/ReleaseNotes.rst

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


[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-08 Thread Chandler Carruth via cfe-commits

chandlerc wrote:

> > > LLVM Buildbot has detected a new failure on builder 
> > > `llvm-clang-x86_64-sie-win` running on `sie-win-worker` while building 
> > > `clang` at step 7 "test-build-unified-tree-check-all".
> > > Full details are available at: 
> > > [lab.llvm.org/buildbot#/builders/46/builds/9169](https://lab.llvm.org/buildbot/#/builders/46/builds/9169)
> > 
> > 
> > This is a Windows build bot with a version of MSVC '19.28.29924.0' -- 
> > that's not even one of the numbers listed here: 
> > [en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B#Internal_version_numbering](https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B#Internal_version_numbering)
> > (edit because I can't count)
> > Looks like it might be a build after 16.9.19 which is listed as 
> > 19.28.29923. Not sure what to do debug this... @zmodem maybe has some idea?
> > It doesn't seem to be the issue I know about on older versions of MSVC as 
> > there are no errors on the long string literal. But somehow it seems to be 
> > miscompiling the string literals?
> 
> I manage this build bot, is there anything I can do to help you debug this 
> problem? We use this build as our "blessed" build internally for building on 
> Windows.

Some indication of what's causing this? Or maybe whether there are any other 
versions of MSVC available with different results?

I don't have a Windows machine to debug on at all, but the premerge windows 
build was successful, so it seems to work on some builders but not others. So 
far I don't have any other failures to look at to cross-compare...

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


[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-08 Thread via cfe-commits

dyung wrote:

> > > > LLVM Buildbot has detected a new failure on builder 
> > > > `llvm-clang-x86_64-sie-win` running on `sie-win-worker` while building 
> > > > `clang` at step 7 "test-build-unified-tree-check-all".
> > > > Full details are available at: 
> > > > [lab.llvm.org/buildbot#/builders/46/builds/9169](https://lab.llvm.org/buildbot/#/builders/46/builds/9169)
> > > 
> > > 
> > > This is a Windows build bot with a version of MSVC '19.28.29924.0' -- 
> > > that's not even one of the numbers listed here: 
> > > [en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B#Internal_version_numbering](https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B#Internal_version_numbering)
> > > (edit because I can't count)
> > > Looks like it might be a build after 16.9.19 which is listed as 
> > > 19.28.29923. Not sure what to do debug this... @zmodem maybe has some 
> > > idea?
> > > It doesn't seem to be the issue I know about on older versions of MSVC as 
> > > there are no errors on the long string literal. But somehow it seems to 
> > > be miscompiling the string literals?
> > 
> > 
> > I manage this build bot, is there anything I can do to help you debug this 
> > problem? We use this build as our "blessed" build internally for building 
> > on Windows.
> 
> Some indication of what's causing this? Or maybe whether there are any other 
> versions of MSVC available with different results?
> 
> I don't have a Windows machine to debug on at all, but the premerge windows 
> build was successful, so it seems to work on some builders but not others. So 
> far I don't have any other failures to look at to cross-compare...

I'll pull the machine offline and try to take a look. There appear to be two 
types of problems, 1 is an assertion failure in the pch related tests, the 
other use of an "unknown" builtin.

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


[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-08 Thread via cfe-commits

dyung wrote:

> > > > > > LLVM Buildbot has detected a new failure on builder 
> > > > > > `llvm-clang-x86_64-sie-win` running on `sie-win-worker` while 
> > > > > > building `clang` at step 7 "test-build-unified-tree-check-all".
> > > > > > Full details are available at: 
> > > > > > [lab.llvm.org/buildbot#/builders/46/builds/9169](https://lab.llvm.org/buildbot/#/builders/46/builds/9169)
> > > > > 
> > > > > 
> > > > > This is a Windows build bot with a version of MSVC '19.28.29924.0' -- 
> > > > > that's not even one of the numbers listed here: 
> > > > > [en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B#Internal_version_numbering](https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B#Internal_version_numbering)
> > > > > (edit because I can't count)
> > > > > Looks like it might be a build after 16.9.19 which is listed as 
> > > > > 19.28.29923. Not sure what to do debug this... @zmodem maybe has some 
> > > > > idea?
> > > > > It doesn't seem to be the issue I know about on older versions of 
> > > > > MSVC as there are no errors on the long string literal. But somehow 
> > > > > it seems to be miscompiling the string literals?
> > > > 
> > > > 
> > > > I manage this build bot, is there anything I can do to help you debug 
> > > > this problem? We use this build as our "blessed" build internally for 
> > > > building on Windows.
> > > 
> > > 
> > > Some indication of what's causing this? Or maybe whether there are any 
> > > other versions of MSVC available with different results?
> > > I don't have a Windows machine to debug on at all, but the premerge 
> > > windows build was successful, so it seems to work on some builders but 
> > > not others. So far I don't have any other failures to look at to 
> > > cross-compare...
> > 
> > 
> > I'll pull the machine offline and try to take a look. There appear to be 
> > two types of problems, 1 is an assertion failure in the pch related tests, 
> > the other use of an "unknown" builtin.
> 
> I'm guessing they're the same issue, just a difference of whether hitting 
> assert or a diagnostic first. Some strings for builtin names aren't coming 
> back out of the tables correctly -- we fail to recognize it in one place, and 
> hit an assert in the other.
> 
> My best guess is something going wrong with the string literals generated by 
> the macros in this PR, or something going wrong with `sizeof` computing 
> offsets... I'll do some experiments with compiler explorer, and see if I can 
> get lucky...
> 
> If we need to revert the PR, totally understand, just a bit odd given only 
> one compiler seems to be hitting the issue here.

Could the version of VC that we are using possibly have the issue with long 
strings that you mention? Is there a simple way to check that?

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


[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-08 Thread Chandler Carruth via cfe-commits

chandlerc wrote:

> Could the version of VC that we are using possibly have the issue with long 
> strings that you mention? Is there a simple way to check that?

It's a compile time error, so no, that'd be really clear cut.

The only other thing I've seen is running out of heap, but that seems likely 
exclusively a compiler explorer thing.

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


[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)

2024-12-08 Thread via cfe-commits

https://github.com/leijurv updated 
https://github.com/llvm/llvm-project/pull/118046

>From 1caf823165b16f6701993d586df51d5cdbf0885e Mon Sep 17 00:00:00 2001
From: Leijurv 
Date: Fri, 29 Nov 2024 21:54:36 -0600
Subject: [PATCH 1/3] [clang-format] Add BreakBeforeTemplateClose option

---
 clang/docs/ClangFormatStyleOptions.rst |  21 
 clang/docs/ReleaseNotes.rst|   1 +
 clang/include/clang/Format/Format.h|  20 
 clang/lib/Format/ContinuationIndenter.cpp  |  11 ++
 clang/lib/Format/ContinuationIndenter.h|  26 ++--
 clang/lib/Format/Format.cpp|   2 +
 clang/lib/Format/TokenAnnotator.cpp|   2 +-
 clang/unittests/Format/ConfigParseTest.cpp |   1 +
 clang/unittests/Format/FormatTest.cpp  | 131 +
 9 files changed, 206 insertions(+), 9 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 4be448171699ca..84ab1b0a2eff61 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3416,6 +3416,27 @@ the configuration (without a prefix: ``Auto``).
 
 
 
+.. _BreakBeforeTemplateClose:
+
+**BreakBeforeTemplateClose** (``Boolean``) :versionbadge:`clang-format 20` 
:ref:`¶ `
+  If ``true``, a line break will be placed before the ``>`` in a multiline
+  template declaration.
+
+  .. code-block:: c++
+
+ true:
+ template <
+ typename Foo,
+ typename Bar,
+ typename Baz
+ >
+
+ false:
+ template <
+ typename Foo,
+ typename Bar,
+ typename Baz>
+
 .. _BreakBeforeTernaryOperators:
 
 **BreakBeforeTernaryOperators** (``Boolean``) :versionbadge:`clang-format 3.7` 
:ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e44aefa90ab386..867d4b5d8c3f18 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -976,6 +976,7 @@ clang-format
   ``Never``, and ``true`` to ``Always``.
 - Adds ``RemoveEmptyLinesInUnwrappedLines`` option.
 - Adds ``KeepFormFeed`` option and set it to ``true`` for ``GNU`` style.
+- Adds ``BreakBeforeTemplateClose`` option.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 6383934afa2c40..bffd964f6aa8aa 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2248,6 +2248,25 @@ struct FormatStyle {
   /// \version 16
   BreakBeforeInlineASMColonStyle BreakBeforeInlineASMColon;
 
+  /// If ``true``, a line break will be placed before the ``>`` in a multiline
+  /// template declaration.
+  /// \code
+  ///true:
+  ///template <
+  ///typename Foo,
+  ///typename Bar,
+  ///typename Baz
+  ///>
+  ///
+  ///false:
+  ///template <
+  ///typename Foo,
+  ///typename Bar,
+  ///typename Baz>
+  /// \endcode
+  /// \version 20
+  bool BreakBeforeTemplateClose;
+
   /// If ``true``, ternary operators will be placed after line breaks.
   /// \code
   ///true:
@@ -5184,6 +5203,7 @@ struct FormatStyle {
BreakBeforeBraces == R.BreakBeforeBraces &&
BreakBeforeConceptDeclarations == R.BreakBeforeConceptDeclarations 
&&
BreakBeforeInlineASMColon == R.BreakBeforeInlineASMColon &&
+   BreakBeforeTemplateClose == R.BreakBeforeTemplateClose &&
BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
BreakBinaryOperations == R.BreakBinaryOperations &&
BreakConstructorInitializers == R.BreakConstructorInitializers &&
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index aed86c1fb99551..4c783623afc535 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -406,6 +406,10 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
   }
   if (CurrentState.BreakBeforeClosingParen && Current.is(tok::r_paren))
 return true;
+  if (CurrentState.BreakBeforeClosingAngle &&
+  Current.ClosesTemplateDeclaration && Style.BreakBeforeTemplateClose) {
+return true;
+  }
   if (Style.Language == FormatStyle::LK_ObjC &&
   Style.ObjCBreakBeforeNestedBlockParam &&
   Current.ObjCSelectorNameParts > 1 &&
@@ -1234,6 +1238,9 @@ unsigned 
ContinuationIndenter::addTokenOnNewLine(LineState &State,
 Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent;
   }
 
+  if (PreviousNonComment && PreviousNonComment->is(tok::less))
+CurrentState.BreakBeforeClosingAngle = true;
+
   if (CurrentState.AvoidBinPacking) {
 // If we are breaking after '(', '{', '<', or this is the break after a ':'
 // to start a member initializer list in a constructor, this should not
@@ -1370,6 +1377,10 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
   State.Stack.size() > 1) {
 return State.Stack[State.Stack.size() - 2].Last

[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)

2024-12-08 Thread via cfe-commits

https://github.com/leijurv updated 
https://github.com/llvm/llvm-project/pull/118046

>From 1caf823165b16f6701993d586df51d5cdbf0885e Mon Sep 17 00:00:00 2001
From: Leijurv 
Date: Fri, 29 Nov 2024 21:54:36 -0600
Subject: [PATCH 1/3] [clang-format] Add BreakBeforeTemplateClose option

---
 clang/docs/ClangFormatStyleOptions.rst |  21 
 clang/docs/ReleaseNotes.rst|   1 +
 clang/include/clang/Format/Format.h|  20 
 clang/lib/Format/ContinuationIndenter.cpp  |  11 ++
 clang/lib/Format/ContinuationIndenter.h|  26 ++--
 clang/lib/Format/Format.cpp|   2 +
 clang/lib/Format/TokenAnnotator.cpp|   2 +-
 clang/unittests/Format/ConfigParseTest.cpp |   1 +
 clang/unittests/Format/FormatTest.cpp  | 131 +
 9 files changed, 206 insertions(+), 9 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 4be448171699ca..84ab1b0a2eff61 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3416,6 +3416,27 @@ the configuration (without a prefix: ``Auto``).
 
 
 
+.. _BreakBeforeTemplateClose:
+
+**BreakBeforeTemplateClose** (``Boolean``) :versionbadge:`clang-format 20` 
:ref:`¶ `
+  If ``true``, a line break will be placed before the ``>`` in a multiline
+  template declaration.
+
+  .. code-block:: c++
+
+ true:
+ template <
+ typename Foo,
+ typename Bar,
+ typename Baz
+ >
+
+ false:
+ template <
+ typename Foo,
+ typename Bar,
+ typename Baz>
+
 .. _BreakBeforeTernaryOperators:
 
 **BreakBeforeTernaryOperators** (``Boolean``) :versionbadge:`clang-format 3.7` 
:ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e44aefa90ab386..867d4b5d8c3f18 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -976,6 +976,7 @@ clang-format
   ``Never``, and ``true`` to ``Always``.
 - Adds ``RemoveEmptyLinesInUnwrappedLines`` option.
 - Adds ``KeepFormFeed`` option and set it to ``true`` for ``GNU`` style.
+- Adds ``BreakBeforeTemplateClose`` option.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 6383934afa2c40..bffd964f6aa8aa 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2248,6 +2248,25 @@ struct FormatStyle {
   /// \version 16
   BreakBeforeInlineASMColonStyle BreakBeforeInlineASMColon;
 
+  /// If ``true``, a line break will be placed before the ``>`` in a multiline
+  /// template declaration.
+  /// \code
+  ///true:
+  ///template <
+  ///typename Foo,
+  ///typename Bar,
+  ///typename Baz
+  ///>
+  ///
+  ///false:
+  ///template <
+  ///typename Foo,
+  ///typename Bar,
+  ///typename Baz>
+  /// \endcode
+  /// \version 20
+  bool BreakBeforeTemplateClose;
+
   /// If ``true``, ternary operators will be placed after line breaks.
   /// \code
   ///true:
@@ -5184,6 +5203,7 @@ struct FormatStyle {
BreakBeforeBraces == R.BreakBeforeBraces &&
BreakBeforeConceptDeclarations == R.BreakBeforeConceptDeclarations 
&&
BreakBeforeInlineASMColon == R.BreakBeforeInlineASMColon &&
+   BreakBeforeTemplateClose == R.BreakBeforeTemplateClose &&
BreakBeforeTernaryOperators == R.BreakBeforeTernaryOperators &&
BreakBinaryOperations == R.BreakBinaryOperations &&
BreakConstructorInitializers == R.BreakConstructorInitializers &&
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index aed86c1fb99551..4c783623afc535 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -406,6 +406,10 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
   }
   if (CurrentState.BreakBeforeClosingParen && Current.is(tok::r_paren))
 return true;
+  if (CurrentState.BreakBeforeClosingAngle &&
+  Current.ClosesTemplateDeclaration && Style.BreakBeforeTemplateClose) {
+return true;
+  }
   if (Style.Language == FormatStyle::LK_ObjC &&
   Style.ObjCBreakBeforeNestedBlockParam &&
   Current.ObjCSelectorNameParts > 1 &&
@@ -1234,6 +1238,9 @@ unsigned 
ContinuationIndenter::addTokenOnNewLine(LineState &State,
 Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent;
   }
 
+  if (PreviousNonComment && PreviousNonComment->is(tok::less))
+CurrentState.BreakBeforeClosingAngle = true;
+
   if (CurrentState.AvoidBinPacking) {
 // If we are breaking after '(', '{', '<', or this is the break after a ':'
 // to start a member initializer list in a constructor, this should not
@@ -1370,6 +1377,10 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState &State) {
   State.Stack.size() > 1) {
 return State.Stack[State.Stack.size() - 2].Last

[clang] [clang] [Sema] Add assertion about expected type classes when building MemberPointerType (PR #119105)

2024-12-08 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

(This was meant as a follow-up to 
https://github.com/llvm/llvm-project/pull/118236 to add the assertion discussed 
in [this 
comment](https://github.com/llvm/llvm-project/pull/118236#discussion_r1865179512),
 but I'm not proceeding with it because the assertion is tripped in more cases 
than hypothesized.)

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


[clang] [clang] [Sema] Add assertion about expected type classes when building MemberPointerType (PR #119105)

2024-12-08 Thread Nathan Ridge via cfe-commits

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


[clang] [clang-format] Add BreakBeforeTemplateClose option (PR #118046)

2024-12-08 Thread via cfe-commits


@@ -11077,6 +11077,157 @@ TEST_F(FormatTest, 
WrapsTemplateDeclarationsWithComments) {
   Style);
 }
 
+TEST_F(FormatTest, BreakBeforeTemplateClose) {

leijurv wrote:

Good suggestion! I have added tests in this commit: 
https://github.com/llvm/llvm-project/pull/118046/commits/3927d411eeece27521e1a4034d01012c84beaf4b

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


[clang] [clang-cl] [Sema] Support MSVC non-const lvalue to user-defined temporary reference (PR #99833)

2024-12-08 Thread Max Winkler via cfe-commits

https://github.com/MaxEW707 updated 
https://github.com/llvm/llvm-project/pull/99833

>From c66fee7969fc4bd8b5ce79085f0fc09cbc4147da Mon Sep 17 00:00:00 2001
From: MaxEW707 
Date: Fri, 21 Jun 2024 20:37:40 -0700
Subject: [PATCH 01/13] Support MSVC lvalue to temporary reference binding

---
 clang/docs/ReleaseNotes.rst |   4 +
 clang/include/clang/Basic/LangOptions.def   |   1 +
 clang/include/clang/Driver/Options.td   |  12 +++
 clang/include/clang/Sema/Sema.h |   2 +
 clang/lib/Driver/ToolChains/Clang.cpp   |   5 +
 clang/lib/Driver/ToolChains/MSVC.cpp|   1 +
 clang/lib/Sema/SemaInit.cpp |  22 +++--
 clang/lib/Sema/SemaOverload.cpp |  16 ++-
 clang/test/Driver/cl-permissive.c   |   7 ++
 clang/test/Driver/cl-zc.cpp |   2 +
 clang/test/SemaCXX/ms-reference-binding.cpp | 102 
 11 files changed, 165 insertions(+), 9 deletions(-)
 create mode 100644 clang/test/SemaCXX/ms-reference-binding.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3c2e0282d1c72d..becf12fa62ec00 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -104,6 +104,10 @@ C23 Feature Support
 New Compiler Flags
 --
 
+- ``-fms-reference-binding`` and its clang-cl counterpart 
``/Zc:referenceBinding``.
+  Implements the MSVC extension where expressions that bind a user-defined 
type temporary
+  to a non-const lvalue reference are allowed.
+
 Deprecated Compiler Flags
 -
 
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 0035092ce0d863..ff350410d598a0 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -307,6 +307,7 @@ LANGOPT(HIPStdParInterposeAlloc, 1, 0, "Replace allocations 
/ deallocations with
 LANGOPT(OpenACC   , 1, 0, "OpenACC Enabled")
 
 LANGOPT(MSVCEnableStdcMacro , 1, 0, "Define __STDC__ with 
'-fms-compatibility'")
+LANGOPT(MSVCReferenceBinding , 1, 0, "Accept expressions that bind a non-const 
lvalue reference to a temporary")
 LANGOPT(SizedDeallocation , 1, 0, "sized deallocation")
 LANGOPT(AlignedAllocation , 1, 0, "aligned allocation")
 LANGOPT(AlignedAllocationUnavailable, 1, 0, "aligned allocation functions are 
unavailable")
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c8c56dbb51b28a..53a356d120e3a6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3034,6 +3034,12 @@ def fms_extensions : Flag<["-"], "fms-extensions">, 
Group,
   Visibility<[ClangOption, CC1Option, CLOption]>,
   HelpText<"Accept some non-standard constructs supported by the Microsoft 
compiler">,
   MarshallingInfoFlag>, 
ImpliedByAnyOf<[fms_compatibility.KeyPath]>;
+def fms_reference_binding : Flag<["-"], "fms-reference-binding">, 
Group,
+  Visibility<[ClangOption, CC1Option, CLOption]>,
+  HelpText<"Accept expressions that bind a non-const lvalue reference to a 
user-defined type temporary as supported by the Microsoft Compiler">,
+  MarshallingInfoFlag>;
+def fno_ms_reference_binding : Flag<["-"], "fno-ms-reference-binding">, 
Group,
+  Visibility<[ClangOption, CLOption]>;
 defm asm_blocks : BoolFOption<"asm-blocks",
   LangOpts<"AsmBlocks">, Default,
   PosFlag,
@@ -8492,6 +8498,12 @@ def _SLASH_Zc_wchar_t : CLFlag<"Zc:wchar_t">,
   HelpText<"Enable C++ builtin type wchar_t (default)">;
 def _SLASH_Zc_wchar_t_ : CLFlag<"Zc:wchar_t-">,
   HelpText<"Disable C++ builtin type wchar_t">;
+def _SLASH_Zc_referenceBinding : CLFlag<"Zc:referenceBinding">,
+  HelpText<"Do not accept expressions that bind a non-const lvalue reference 
to a user-defined type temporary">,
+  Alias;
+def _SLASH_Zc_referenceBinding_ : CLFlag<"Zc:referenceBinding-">,
+  HelpText<"Accept expressions that bind a non-const lvalue reference to a 
user-defined type temporary">,
+  Alias;
 def _SLASH_Z7 : CLFlag<"Z7">, Alias,
   HelpText<"Enable CodeView debug information in object files">;
 def _SLASH_ZH_MD5 : CLFlag<"ZH:MD5">,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2ec6367eccea01..6bd575d105675b 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10161,6 +10161,8 @@ class Sema final : public SemaBase {
   CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2,
ReferenceConversions *Conv = nullptr);
 
+  bool AllowMSLValueReferenceBinding(Qualifiers Quals, QualType QT);
+
   /// AddOverloadCandidate - Adds the given function to the set of
   /// candidate functions, using the given function call arguments.  If
   /// @p SuppressUserConversions, then don't allow user-defined
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 843d68c85bc592..13867181b21c07 100644
--- a/clang/lib/Driver/Tool

[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-08 Thread via cfe-commits

dyung wrote:

I’m still looking into the failure, but may be a bit slow as the machine isn’t 
really setup for debugging, and I’m traveling today. 

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


[clang-tools-extra] [clangd] Add clarifying comment about when Dex::IdxContents is populated (PR #118906)

2024-12-08 Thread Nathan Ridge via cfe-commits

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


[clang-tools-extra] [clangd] Add clarifying comment about when Dex::IdxContents is populated (PR #118906)

2024-12-08 Thread kadir çetinkaya via cfe-commits


@@ -121,6 +121,8 @@ class Dex : public SymbolIndex {
   llvm::DenseMap, std::vector> 
Relations;
   std::shared_ptr KeepAlive; // poor man's move-only std::any
   // Set of files which were used during this index build.
+  // Files and IdxContents are only populated for dynamic and background
+  // indexes, not static indexes.

kadircet wrote:

thanks, that LGTM!

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


[clang-tools-extra] [clangd] Add clarifying comment about when Dex::IdxContents is populated (PR #118906)

2024-12-08 Thread kadir çetinkaya via cfe-commits

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


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


[clang-tools-extra] [clangd] Add clarifying comment about when Dex::IdxContents is populated (PR #118906)

2024-12-08 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 updated 
https://github.com/llvm/llvm-project/pull/118906

>From 45311dbceed8d438f2ac0db5019719a7fa32c0bf Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Thu, 5 Dec 2024 19:45:25 -0500
Subject: [PATCH] [clangd] Add clarifying comment about when Dex::IdxContents
 is populated

---
 clang-tools-extra/clangd/index/dex/Dex.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang-tools-extra/clangd/index/dex/Dex.h 
b/clang-tools-extra/clangd/index/dex/Dex.h
index 69e161d51135b6..dc8c5b44c418f9 100644
--- a/clang-tools-extra/clangd/index/dex/Dex.h
+++ b/clang-tools-extra/clangd/index/dex/Dex.h
@@ -123,6 +123,8 @@ class Dex : public SymbolIndex {
   // Set of files which were used during this index build.
   llvm::StringSet<> Files;
   // Contents of the index (symbols, references, etc.)
+  // This is only populated if `Files` is, which applies to some but not all
+  // consumers of this class.
   IndexContents IdxContents;
   // Size of memory retained by KeepAlive.
   size_t BackingDataSize = 0;

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


[clang-tools-extra] 26760c7 - [clangd] Add clarifying comment about when Dex::IdxContents is populated (#118906)

2024-12-08 Thread via cfe-commits

Author: Nathan Ridge
Date: 2024-12-09T02:23:11-05:00
New Revision: 26760c7b907c1012c44d15959319bfa06848e5cd

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

LOG: [clangd] Add clarifying comment about when Dex::IdxContents is populated 
(#118906)

Added: 


Modified: 
clang-tools-extra/clangd/index/dex/Dex.h

Removed: 




diff  --git a/clang-tools-extra/clangd/index/dex/Dex.h 
b/clang-tools-extra/clangd/index/dex/Dex.h
index 46efbc6c699cab..502f597d81ef07 100644
--- a/clang-tools-extra/clangd/index/dex/Dex.h
+++ b/clang-tools-extra/clangd/index/dex/Dex.h
@@ -146,6 +146,8 @@ class Dex : public SymbolIndex {
   // Set of files which were used during this index build.
   llvm::StringSet<> Files;
   // Contents of the index (symbols, references, etc.)
+  // This is only populated if `Files` is, which applies to some but not all
+  // consumers of this class.
   IndexContents IdxContents = IndexContents::None;
   // Size of memory retained by KeepAlive.
   size_t BackingDataSize = 0;



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


[clang] [clang] constexpr built-in elementwise add_sat function. (PR #119082)

2024-12-08 Thread via cfe-commits


@@ -11339,6 +11339,31 @@ bool VectorExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
 
 return Success(APValue(ResultElements.data(), ResultElements.size()), E);
   }
+  case Builtin::BI__builtin_elementwise_add_sat: {
+APValue SourceLHS, SourceRHS;
+if (!EvaluateAsRValue(Info, E->getArg(0), SourceLHS) ||
+!EvaluateAsRValue(Info, E->getArg(1), SourceRHS))
+  return false;
+
+QualType DestEltTy = E->getType()->castAs()->getElementType();
+unsigned SourceLen = SourceLHS.getVectorLength();
+SmallVector ResultElements;
+ResultElements.reserve(SourceLen);
+
+for (unsigned EltNum = 0; EltNum < SourceLen; ++EltNum) {
+  APSInt LHS = SourceLHS.getVectorElt(EltNum).getInt();
+  APSInt RHS = SourceRHS.getVectorElt(EltNum).getInt();
+  switch (E->getBuiltinCallee()) {
+  case Builtin::BI__builtin_elementwise_add_sat:

c8ef wrote:

Done.

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


[clang] [llvm] [openmp] [OpenMP] Use generic IR for the OpenMP DeviceRTL (PR #119091)

2024-12-08 Thread Joseph Huber via cfe-commits


@@ -288,18 +258,11 @@ function(compileDeviceRTLLibrary target_cpu target_name 
target_triple)
   endif()
 endfunction()
 
-# Generate a Bitcode library for all the gpu architectures the user requested.
-add_custom_target(omptarget.devicertl.nvptx)
 add_custom_target(omptarget.devicertl.amdgpu)
-foreach(gpu_arch ${LIBOMPTARGET_DEVICE_ARCHITECTURES})
-  if("${gpu_arch}" IN_LIST all_amdgpu_architectures)
-compileDeviceRTLLibrary(${gpu_arch} amdgpu amdgcn-amd-amdhsa -Xclang 
-mcode-object-version=none)
-  elseif("${gpu_arch}" IN_LIST all_nvptx_architectures)
-compileDeviceRTLLibrary(${gpu_arch} nvptx nvptx64-nvidia-cuda 
--cuda-feature=+ptx63)
-  else()
-message(FATAL_ERROR "Unknown GPU architecture '${gpu_arch}'")
-  endif()
-endforeach()
+compileDeviceRTLLibrary(amdgpu amdgcn-amd-amdhsa -Xclang 
-mcode-object-version=none)
+
+add_custom_target(omptarget.devicertl.nvptx)
+compileDeviceRTLLibrary(nvptx nvptx64-nvidia-cuda --cuda-feature=+ptx63)

jhuber6 wrote:

I didn't feel like it was strictly necessary since if you can build one you can 
build the other. The only thing you save is disk space, but if you feel like 
it's really needed I can re-use the architectures thing or something.

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


[clang] [llvm] [openmp] [OpenMP] Use generic IR for the OpenMP DeviceRTL (PR #119091)

2024-12-08 Thread Michał Górny via cfe-commits


@@ -288,18 +258,11 @@ function(compileDeviceRTLLibrary target_cpu target_name 
target_triple)
   endif()
 endfunction()
 
-# Generate a Bitcode library for all the gpu architectures the user requested.
-add_custom_target(omptarget.devicertl.nvptx)
 add_custom_target(omptarget.devicertl.amdgpu)
-foreach(gpu_arch ${LIBOMPTARGET_DEVICE_ARCHITECTURES})
-  if("${gpu_arch}" IN_LIST all_amdgpu_architectures)
-compileDeviceRTLLibrary(${gpu_arch} amdgpu amdgcn-amd-amdhsa -Xclang 
-mcode-object-version=none)
-  elseif("${gpu_arch}" IN_LIST all_nvptx_architectures)
-compileDeviceRTLLibrary(${gpu_arch} nvptx nvptx64-nvidia-cuda 
--cuda-feature=+ptx63)
-  else()
-message(FATAL_ERROR "Unknown GPU architecture '${gpu_arch}'")
-  endif()
-endforeach()
+compileDeviceRTLLibrary(amdgpu amdgcn-amd-amdhsa -Xclang 
-mcode-object-version=none)
+
+add_custom_target(omptarget.devicertl.nvptx)
+compileDeviceRTLLibrary(nvptx nvptx64-nvidia-cuda --cuda-feature=+ptx63)

mgorny wrote:

I don't exactly feel strongly about it. It's just that we already provide a 
switch for amdgpu/nvptx in Gentoo, so it only feels natural for this to respect 
it.

Also, on a semi-related matter: is there a reason we're installing both 
separate `.bc` files and `libomptarget.devicertl.a`?

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


[clang] [llvm] [openmp] [OpenMP] Use generic IR for the OpenMP DeviceRTL (PR #119091)

2024-12-08 Thread Michał Górny via cfe-commits


@@ -288,18 +258,11 @@ function(compileDeviceRTLLibrary target_cpu target_name 
target_triple)
   endif()
 endfunction()
 
-# Generate a Bitcode library for all the gpu architectures the user requested.
-add_custom_target(omptarget.devicertl.nvptx)
 add_custom_target(omptarget.devicertl.amdgpu)
-foreach(gpu_arch ${LIBOMPTARGET_DEVICE_ARCHITECTURES})
-  if("${gpu_arch}" IN_LIST all_amdgpu_architectures)
-compileDeviceRTLLibrary(${gpu_arch} amdgpu amdgcn-amd-amdhsa -Xclang 
-mcode-object-version=none)
-  elseif("${gpu_arch}" IN_LIST all_nvptx_architectures)
-compileDeviceRTLLibrary(${gpu_arch} nvptx nvptx64-nvidia-cuda 
--cuda-feature=+ptx63)
-  else()
-message(FATAL_ERROR "Unknown GPU architecture '${gpu_arch}'")
-  endif()
-endforeach()
+compileDeviceRTLLibrary(amdgpu amdgcn-amd-amdhsa -Xclang 
-mcode-object-version=none)
+
+add_custom_target(omptarget.devicertl.nvptx)
+compileDeviceRTLLibrary(nvptx nvptx64-nvidia-cuda --cuda-feature=+ptx63)

mgorny wrote:

Can we have an option to disable either of amdgpu/nvptx specifically? If 
anything, because it feels weird having a choice between amdgpu and nvptx 
plugins, but no choice between devicertl variants.

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


[clang] [llvm] [openmp] [OpenMP] Use generic IR for the OpenMP DeviceRTL (PR #119091)

2024-12-08 Thread Joseph Huber via cfe-commits


@@ -288,18 +258,11 @@ function(compileDeviceRTLLibrary target_cpu target_name 
target_triple)
   endif()
 endfunction()
 
-# Generate a Bitcode library for all the gpu architectures the user requested.
-add_custom_target(omptarget.devicertl.nvptx)
 add_custom_target(omptarget.devicertl.amdgpu)
-foreach(gpu_arch ${LIBOMPTARGET_DEVICE_ARCHITECTURES})
-  if("${gpu_arch}" IN_LIST all_amdgpu_architectures)
-compileDeviceRTLLibrary(${gpu_arch} amdgpu amdgcn-amd-amdhsa -Xclang 
-mcode-object-version=none)
-  elseif("${gpu_arch}" IN_LIST all_nvptx_architectures)
-compileDeviceRTLLibrary(${gpu_arch} nvptx nvptx64-nvidia-cuda 
--cuda-feature=+ptx63)
-  else()
-message(FATAL_ERROR "Unknown GPU architecture '${gpu_arch}'")
-  endif()
-endforeach()
+compileDeviceRTLLibrary(amdgpu amdgcn-amd-amdhsa -Xclang 
-mcode-object-version=none)
+
+add_custom_target(omptarget.devicertl.nvptx)
+compileDeviceRTLLibrary(nvptx nvptx64-nvidia-cuda --cuda-feature=+ptx63)

jhuber6 wrote:

This is really over-complicated, but right now we only use the `.bc` file for 
non-LTO NVPTX compilations which get put through each TU in a broken way via 
`-mlink-builtin-bitcode`. This is because it would get really slow if we didn't 
optimize out calls to the runtime.

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


[clang] [llvm] [openmp] [OpenMP] Use generic IR for the OpenMP DeviceRTL (PR #119091)

2024-12-08 Thread Joseph Huber via cfe-commits


@@ -288,18 +258,11 @@ function(compileDeviceRTLLibrary target_cpu target_name 
target_triple)
   endif()
 endfunction()
 
-# Generate a Bitcode library for all the gpu architectures the user requested.
-add_custom_target(omptarget.devicertl.nvptx)
 add_custom_target(omptarget.devicertl.amdgpu)
-foreach(gpu_arch ${LIBOMPTARGET_DEVICE_ARCHITECTURES})
-  if("${gpu_arch}" IN_LIST all_amdgpu_architectures)
-compileDeviceRTLLibrary(${gpu_arch} amdgpu amdgcn-amd-amdhsa -Xclang 
-mcode-object-version=none)
-  elseif("${gpu_arch}" IN_LIST all_nvptx_architectures)
-compileDeviceRTLLibrary(${gpu_arch} nvptx nvptx64-nvidia-cuda 
--cuda-feature=+ptx63)
-  else()
-message(FATAL_ERROR "Unknown GPU architecture '${gpu_arch}'")
-  endif()
-endforeach()
+compileDeviceRTLLibrary(amdgpu amdgcn-amd-amdhsa -Xclang 
-mcode-object-version=none)
+
+add_custom_target(omptarget.devicertl.nvptx)
+compileDeviceRTLLibrary(nvptx nvptx64-nvidia-cuda --cuda-feature=+ptx63)

jhuber6 wrote:

I suppose that happens for the CPU  targets? Those aren't really used anywhere 
real, they're just for testing, but even so we probably shouldn't leave them 
broken. We link the device RTL unconditionally because the link step shouldn't 
need to know the architectures that were used to compile it. Because these are 
static libraries they're not extracted if they aren't needed, so it doesn't 
hurt anything if they're unused. But I guess you can have a situation where the 
user doesn't build this intentionally, but that's non-default behavior so I've 
never given it much thought.

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


  1   2   >