[clang] Fix a crash introduced by 3d5e9ab by adding a nullptr check. (PR #90301)

2024-04-28 Thread Balazs Benics via cfe-commits


@@ -54,7 +54,7 @@ class UncountedCallArgsChecker
   bool shouldVisitImplicitCode() const { return false; }
 
   bool TraverseDecl(Decl *D) {
-if (isa(D) && isRefType(safeGetName(D)))
+if (D && isa(D) && isRefType(safeGetName(D)))

steakhal wrote:

Have you considered using "isa_and_nonull"?

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


[clang] [Clang][Sema] Fix a bug on template partial specialization with issue on deduction of nontype tempalte parameter (PR #90376)

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

https://github.com/Endilll commented:

`Sema.h` changes look good to me.

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


[clang] [Clang] Implement C++26 Attributes for Structured Bindings (P0609R3) (PR #89906)

2024-04-28 Thread via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/89906

>From e87546f2bc0c7d213b6c1f2b414e0ce5335b3e47 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Wed, 24 Apr 2024 11:53:28 +0200
Subject: [PATCH 1/5] [Clang] Implement C++26 Attributes for Structured
 Bindings (P0609R3)

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p0609r3.pdf

We support this feature in all language mode.
maybe_unused applied to a binding makes the whole declaration unused.
There maybe something more clever to do here but that can be explored
as a separate PR.
---
 clang/docs/LanguageExtensions.rst |  1 +
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/include/clang/Basic/Attr.td |  2 +-
 .../clang/Basic/DiagnosticParseKinds.td   | 10 +
 clang/include/clang/Sema/DeclSpec.h   | 10 +++--
 clang/include/clang/Sema/ParsedAttr.h |  1 +
 clang/lib/Frontend/InitPreprocessor.cpp   |  2 +-
 clang/lib/Parse/ParseDecl.cpp | 41 ++-
 clang/lib/Sema/DeclSpec.cpp   |  4 +-
 clang/lib/Sema/SemaDecl.cpp   |  2 +-
 clang/lib/Sema/SemaDeclCXX.cpp|  2 +
 clang/test/Lexer/cxx-features.cpp |  2 +-
 clang/test/Parser/cxx1z-decomposition.cpp | 38 +
 clang/test/SemaCXX/unused.cpp | 12 +-
 clang/www/cxx_status.html |  2 +-
 15 files changed, 101 insertions(+), 30 deletions(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 84fc4dee02fa80..49afd6c7f06bdd 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1493,6 +1493,7 @@ Conditional ``explicit`` 
__cpp_conditional_explicit   C+
 ``if consteval`` __cpp_if_consteval   
C++23 C++20
 ``static operator()``__cpp_static_call_operator   
C++23 C++03
 Attributes on Lambda-Expressions  
C++23 C++11
+Attributes on Structured Bindings__cpp_structured_bindings
C++26 C++03
 ``= delete ("should have a reason");``   __cpp_deleted_function   
C++26 C++03
   
- -
 Designated initializers (N494)
C99   C89
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 64526ed6d06f55..8c8ded8cde0837 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -131,6 +131,8 @@ C++2c Feature Support
 
 - Implemented `P2573R2: = delete("should have a reason"); 
`_
 
+- Implemented `P0609R3: Attributes for Structured Bindings 
`_
+
 
 Resolutions to C++ Defect Reports
 ^
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 4408d517e70e58..97e06fe7d2e6aa 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3211,7 +3211,7 @@ def ObjCRequiresPropertyDefs : InheritableAttr {
 def Unused : InheritableAttr {
   let Spellings = [CXX11<"", "maybe_unused", 201603>, GCC<"unused">,
C23<"", "maybe_unused", 202106>];
-  let Subjects = SubjectList<[Var, ObjCIvar, Type, Enum, EnumConstant, Label,
+  let Subjects = SubjectList<[Var, Binding, ObjCIvar, Type, Enum, 
EnumConstant, Label,
   Field, ObjCMethod, FunctionLike]>;
   let Documentation = [WarnMaybeUnusedDocs];
 }
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 38174cf3549f14..74ce0f8b53a48c 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1056,11 +1056,21 @@ def ext_decl_attrs_on_lambda : ExtWarn<
 def ext_lambda_missing_parens : ExtWarn<
   "lambda without a parameter clause is a C++23 extension">,
   InGroup;
+
 def warn_cxx20_compat_decl_attrs_on_lambda : Warning<
   "%select{an attribute specifier sequence|%1}0 in this position "
   "is incompatible with C++ standards before C++23">,
   InGroup, DefaultIgnore;
 
+def ext_decl_attrs_on_binding : ExtWarn<
+  "an attribute specifier sequence attached to a structured binding 
declaration "
+  "is a C++2c extension">, InGroup;
+
+def warn_cxx23_compat_decl_attrs_on_binding : Warning<
+  "an attribute specifier sequence attached to a structured binding 
declaration "
+  "is incompatible with C++ standards before C++2c">,
+  InGroup, DefaultIgnore;
+
 // C++17 lambda expressions
 def err_expected_star_this_capture : Error<
   "expected 'this' following '*' in lambda capture list">;
diff --git a/clang/include/clang/Sema/DeclSpec.h 
b/clang/include/clang/Sema/DeclSpec.h

[clang] [Clang][Sema] Fix a bug on template partial specialization with issue on deduction of nontype tempalte parameter (PR #90376)

2024-04-28 Thread Younan Zhang via cfe-commits


@@ -8508,6 +8507,16 @@ Sema::BuildExpressionFromDeclTemplateArgument(const 
TemplateArgument &Arg,
   } else {
 assert(ParamType->isReferenceType() &&
"unexpected type for decl template argument");
+if (ParamType->isLValueReferenceType())
+  if (NonTypeTemplateParmDecl *NTTP =
+  dyn_cast_if_present(TemplateParam)) {
+QualType TemplateParamType = NTTP->getType();
+const AutoType *AT = TemplateParamType->getAs();
+if (AT && AT->isDecltypeAuto())
+  RefExpr = new (getASTContext())
+  ParenExpr(RefExpr.get()->getBeginLoc(),

zyn0217 wrote:

Did you try to preserve the references using `SubstNonTypeTemplateParmExpr`s 
just like what @cor3ntin said? This looks a bit odd to me...

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


[clang] 487967a - [Modules] Don't replace local declarations with external declaration with lower visibility

2024-04-28 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-04-28T15:23:39+08:00
New Revision: 487967af82053cd08022635a2ff768385d936c80

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

LOG: [Modules] Don't replace local declarations with external declaration with 
lower visibility

Close https://github.com/llvm/llvm-project/issues/88400

For the reproducer:

```
//--- header.h

namespace N {
template
concept X = true;

template
class Y {
public:
template
friend class Y;
};

inline Y x;
}

//--- bar.cppm
module;
export module bar;
namespace N {
// To make sure N::Y won't get elided.
using N::x;
}

//--- foo.cc
// expected-no-diagnostics
import bar;
void y() {
N::Y y{};
};
```

it will crash. The root cause is that in
`StoredDeclsList::replaceExternalDecls`, we will replace the
existing declarations with external declarations.

Then for the reproducer, the redecl chain for Y is like:

```
Y (Local) -> Y (Local, friend) -> Y (Imported) -> Y(Imported, friend)
```

Before the lookup, the stored lookup result is `Y(Local)` then we find
`Y(Imported)`. And now we repalce `Y(Local)` with `Y(Imported)`. But
`Y(Imported)` is not visible. So we tried to find if there is any
redeclarations visible but we find `Y(Local, friend)`, then problem
happens.

The solution is try to avoid the replace to happen if the external
declaration has lower visibility then we can always find the local
declarations. This may help the lookup performance slightly.

Also I found the implementation of
`StoredDeclsList::replaceExternalDecls` is not efficiency. It has an
`O(n*m)` complexities. But let's improve that in the future.

Added: 
clang/test/Modules/pr88400.cppm

Modified: 
clang/include/clang/AST/DeclContextInternals.h

Removed: 




diff  --git a/clang/include/clang/AST/DeclContextInternals.h 
b/clang/include/clang/AST/DeclContextInternals.h
index c4734ab5789538..42cc677f82135e 100644
--- a/clang/include/clang/AST/DeclContextInternals.h
+++ b/clang/include/clang/AST/DeclContextInternals.h
@@ -160,12 +160,16 @@ class StoredDeclsList {
 
   void replaceExternalDecls(ArrayRef Decls) {
 // Remove all declarations that are either external or are replaced with
-// external declarations.
+// external declarations with higher visibilities.
 erase_if([Decls](NamedDecl *ND) {
   if (ND->isFromASTFile())
 return true;
+  // FIXME: Can we get rid of this loop completely?
   for (NamedDecl *D : Decls)
-if (D->declarationReplaces(ND, /*IsKnownNewer=*/false))
+// Only replace the local declaration if the external declaration has
+// higher visibilities.
+if (D->getModuleOwnershipKind() <= ND->getModuleOwnershipKind() &&
+D->declarationReplaces(ND, /*IsKnownNewer=*/false))
   return true;
   return false;
 });

diff  --git a/clang/test/Modules/pr88400.cppm b/clang/test/Modules/pr88400.cppm
new file mode 100644
index 00..ff69137a0b9040
--- /dev/null
+++ b/clang/test/Modules/pr88400.cppm
@@ -0,0 +1,61 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/bar.cppm -emit-module-interface -o %t/bar.pcm
+// RUN: %clang_cc1 -std=c++20 %t/foo.cc -fmodule-file=bar=%t/bar.pcm 
-fsyntax-only -verify
+// RUN: %clang_cc1 -std=c++20 %t/bar.cc -fmodule-file=bar=%t/bar.pcm 
-fsyntax-only -verify
+//
+// RUN: %clang_cc1 -std=c++20 %t/bar.cppm -emit-reduced-module-interface -o 
%t/bar.pcm
+// RUN: %clang_cc1 -std=c++20 %t/foo.cc -fmodule-file=bar=%t/bar.pcm 
-fsyntax-only -verify
+// RUN: %clang_cc1 -std=c++20 %t/bar.cc -fmodule-file=bar=%t/bar.pcm 
-fsyntax-only -verify
+
+//--- header.h
+#pragma once
+
+namespace N {
+template
+concept X = true;
+
+template
+class Y {
+public:
+template
+friend class Y;
+};
+
+inline Y x;
+}
+
+//--- bar.cppm
+module;
+
+#include "header.h"
+
+export module bar;
+
+namespace N {
+// To make sure N::Y won't get elided.
+using N::x;
+}
+
+//--- foo.cc
+// expected-no-diagnostics
+#include "header.h"
+
+import bar;
+
+void y() {
+N::Y y{};
+};
+
+//--- bar.cc
+// expected-no-diagnostics
+import bar;
+
+#include "header.h"
+
+void y() {
+N::Y y{};
+};
+



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


[clang] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin and frexp. (PR #88978)

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


@@ -14638,6 +14649,8 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr 
*E) {
 return true;
   }
 
+  case Builtin::BIfmin:
+  case Builtin::BIfminf:

philnik777 wrote:

These have to be made `constexpr`, at least in C++23. C++ stdlibs can't 
override them to make them call the `__builtin_` versions, so Clang has to 
handle that.


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


[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)

2024-04-28 Thread Kishan Parmar via cfe-commits

https://github.com/Long5hot updated 
https://github.com/llvm/llvm-project/pull/77732

>From cc5fe4a6aa4762040077ab39edb6677f42638673 Mon Sep 17 00:00:00 2001
From: Kishan Parmar 
Date: Sun, 28 Apr 2024 14:18:42 +0530
Subject: [PATCH] [clang][PowerPC] Add flag to enable compatibility with GNU
 for complex arguments

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

https://godbolt.org/z/1bsW1sKMs

newFlag : -fcomplex-ppc-gnu-abi

GNU uses GPRs for complex parameters and return values storing for 
PowerPC-32bit,
which can be enabled which above flag.
Intent of this patch is to make clang compatible with GNU libraries of complex.

Following up with this patch : https://reviews.llvm.org/D146942
---
 clang/include/clang/Basic/CodeGenOptions.def  |   2 +
 clang/include/clang/Basic/CodeGenOptions.h|   6 +
 clang/include/clang/Driver/Options.td |   4 +
 clang/lib/CodeGen/Targets/PPC.cpp |  87 +++-
 clang/lib/Driver/ToolChains/Clang.cpp |   9 +
 clang/lib/Frontend/CompilerInvocation.cpp |   8 +
 .../CodeGen/PowerPC/ppc32-complex-gnu-abi.c   | 394 ++
 .../ppc32-complex-soft-float-gnu-abi.c| 286 +
 .../test/Driver/ppc32-fcomplex-ppc-gnu-abi.c  |  15 +
 9 files changed, 805 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/CodeGen/PowerPC/ppc32-complex-gnu-abi.c
 create mode 100644 
clang/test/CodeGen/PowerPC/ppc32-complex-soft-float-gnu-abi.c
 create mode 100644 clang/test/Driver/ppc32-fcomplex-ppc-gnu-abi.c

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 340b08dd7e2a33..f4845e9e424c67 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -225,6 +225,8 @@ CODEGENOPT(MCDCCoverage , 1, 0) ///< Enable MC/DC code 
coverage criteria.
 
   /// If -fpcc-struct-return or -freg-struct-return is specified.
 ENUM_CODEGENOPT(StructReturnConvention, StructReturnConventionKind, 2, 
SRCK_Default)
+  /// If -fcomplex-ppc-gnu-abi is specified on ppc32.
+ENUM_CODEGENOPT(ComplexInRegABI, ComplexArgumentConventionKind, 2, 
CMPLX_OnStack)
 
 CODEGENOPT(RelaxAll  , 1, 0) ///< Relax all machine code instructions.
 CODEGENOPT(RelaxedAliasing   , 1, 0) ///< Set when -fno-strict-aliasing is 
enabled.
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 9469a424045bb0..1c9424f65623dd 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -78,6 +78,12 @@ class CodeGenOptions : public CodeGenOptionsBase {
 SRCK_InRegs// Small structs in registers (-freg-struct-return).
   };
 
+  enum ComplexArgumentConventionKind {
+CMPLX_OnStack,
+CMPLX_InGPR, // If -fcomplex-ppc-gnu-abi is specified on ppc32
+CMPLX_InFPR
+  };
+
   enum ProfileInstrKind {
 ProfileNone,   // Profile instrumentation is turned off.
 ProfileClangInstr, // Clang instrumentation to generate execution counts
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 086aedefc11878..e35ac8ea36d727 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2601,6 +2601,10 @@ def ffp_contract : Joined<["-"], "ffp-contract=">, 
Group,
   HelpText<"Form fused FP ops (e.g. FMAs)">,
   Values<"fast,on,off,fast-honor-pragmas">;
 
+def fcomplex_ppc_gnu_abi : Flag<["-"], "fcomplex-ppc-gnu-abi">, 
Group, Visibility<[ClangOption, CC1Option]>,
+  DocBrief<"Follow the GNU ABI, pass Complex values in GPRs instead of the 
stack for PowerPC-32">,
+  HelpText<"Pass Complex values in GPR instead of stack for PowerPC-32">;
+
 defm strict_float_cast_overflow : BoolFOption<"strict-float-cast-overflow",
   CodeGenOpts<"StrictFloatCastOverflow">, DefaultTrue,
   NegFlaghttps://reviews.llvm.org/D146942 and the related LLVM pull
+  // request: #77732
+
+  if (TypeSize == 64) {
+ElemTy = llvm::Type::getInt64Ty(getVMContext());
+RegsNeeded = 1;
+  } else {
+ElemTy = llvm::Type::getInt32Ty(getVMContext());
+RegsNeeded = TypeSize >> 5;
+  }
+  return ABIArgInfo::getDirect(llvm::ArrayType::get(ElemTy, RegsNeeded));
+}
+
+ABIArgInfo PPC32_SVR4_ABIInfo::classifyArgumentType(QualType Ty,
+int &ArgGPRsLeft) const {
+  Ty = useFirstFieldIfTransparentUnion(Ty);
+  bool IsComplex = Ty->isAnyComplexType();
+
+  if ((getCodeGenOpts().getComplexInRegABI() != CodeGenOptions::CMPLX_InGPR) ||
+  !ArgGPRsLeft || (!IsComplex && Ty->isFloatingType() && !IsSoftFloatABI))
+return DefaultABIInfo::classifyArgumentType(Ty);
+
+  assert(ArgGPRsLeft >= 0 && "Arg GPR must be large or equal than zero");
+  ASTContext &Context = getContext();
+  uint64_t TypeSize = Context.getTypeSize(Ty);
+
+  // For complex type or any other primitive types.
+  if (IsComplex || !isAggregateTypeForABI(Ty)) {
+// If gr is even set gr = gr + 1

[clang] [clang] Implement CWG2851: floating-point conversions in converted constant expressions (PR #90387)

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

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

https://cplusplus.github.io/CWG/issues/2851.html

The only time the target type for a converted constant expression is a 
floating-point type is in a NTTP, so this only affects C++20+.

>From 3d56657f03ab6824bf6717a89b4b2f757770aad5 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 28 Apr 2024 09:48:47 +0100
Subject: [PATCH] [clang] Implement CWG2851: floating-point conversions in
 converted constant expressions

---
 clang/docs/ReleaseNotes.rst   |  3 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/lib/Sema/SemaOverload.cpp   | 38 +--
 clang/test/CXX/drs/dr28xx.cpp | 35 +
 4 files changed, 77 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a1390d6536b28c..7c8d83bd73613b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -164,6 +164,9 @@ Resolutions to C++ Defect Reports
 - Clang now diagnoses declarative nested-name-specifiers with 
pack-index-specifiers.
   (`CWG2858: Declarative nested-name-specifiers and pack-index-specifiers 
`_).
 
+- Allow floating-point promotions and conversions in converted constant 
expressions.
+  (`CWG2851 Allow floating-point conversions in converted constant expressions 
`_).
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index fdca82934cb4dc..08ebb28ff17b25 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -85,6 +85,10 @@ def err_expr_not_cce : Error<
   "%select{case value|enumerator value|non-type template argument|"
   "array size|explicit specifier argument|noexcept specifier argument|"
   "call to 'size()'|call to 'data()'}0 is not a constant expression">;
+def err_float_conv_cant_represent : Error<
+  "non-type template argument evaluates to %0 which can not be "
+  "represented in type %1"
+>;
 def ext_cce_narrowing : ExtWarn<
   "%select{case value|enumerator value|non-type template argument|"
   "array size|explicit specifier argument|noexcept specifier argument|"
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 04cd9e78739d20..c35517db946b1c 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6072,6 +6072,10 @@ static bool CheckConvertedConstantConversions(Sema &S,
   case ICK_Integral_Promotion:
   case ICK_Integral_Conversion: // Narrowing conversions are checked elsewhere.
   case ICK_Zero_Queue_Conversion:
+  // Per CWG2851, floating-point promotions and conversions are allowed.
+  // The value of a conversion is checked afterwards.
+  case ICK_Floating_Promotion:
+  case ICK_Floating_Conversion:
 return true;
 
   case ICK_Boolean_Conversion:
@@ -6091,9 +6095,7 @@ static bool CheckConvertedConstantConversions(Sema &S,
 // only permitted if the source type is std::nullptr_t.
 return SCS.getFromType()->isNullPtrType();
 
-  case ICK_Floating_Promotion:
   case ICK_Complex_Promotion:
-  case ICK_Floating_Conversion:
   case ICK_Complex_Conversion:
   case ICK_Floating_Integral:
   case ICK_Compatible_Conversion:
@@ -6229,7 +6231,37 @@ static ExprResult BuildConvertedConstantExpression(Sema 
&S, Expr *From,
   if (Result.isInvalid())
 return Result;
 
-  // Check for a narrowing implicit conversion.
+  if (SCS->Second == ICK_Floating_Conversion) {
+// Unlike with narrowing conversions, the value must fit
+// exactly even if it is in range
+assert(CCE == Sema::CCEKind::CCEK_TemplateArg &&
+   "Only non-type template args should use floating-point 
conversions");
+
+// Initializer is From, except it is a full-expression
+const Expr *Initializer =
+IgnoreNarrowingConversion(S.Context, Result.get());
+
+// If it's value-dependent, we can't tell whether it will fit
+if (Initializer->isValueDependent())
+  return Result;
+
+if (!Initializer->isCXX11ConstantExpr(S.Context, &PreNarrowingValue)) {
+  S.Diag(Initializer->getBeginLoc(), diag::err_expr_not_cce) << CCE;
+  return Result;
+}
+
+llvm::APFloat PostNarrowingValue = PreNarrowingValue.getFloat();
+bool LosesInfo = true;
+PostNarrowingValue.convert(S.Context.getFloatTypeSemantics(T),
+   llvm::APFloat::rmNearestTiesToEven, &LosesInfo);
+if (LosesInfo)
+  S.Diag(From->getBeginLoc(), diag::err_float_conv_cant_represent)
+  << PreNarrowingValue.getAsString(S.Context, From->getType()) << T;
+
+return Result;
+  }
+
+  // Check for a narrowing integer conversion.
   bool ReturnPreNarrowingValue = false;
   QualType PreNarrowingType;
   switch (SCS->getNarrowingKind(S.Co

[clang] [clang] Implement CWG2851: floating-point conversions in converted constant expressions (PR #90387)

2024-04-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mital Ashok (MitalAshok)


Changes

https://cplusplus.github.io/CWG/issues/2851.html

The only time the target type for a converted constant expression is a 
floating-point type is in a NTTP, so this only affects C++20+.

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


4 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+4) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+35-3) 
- (modified) clang/test/CXX/drs/dr28xx.cpp (+35) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a1390d6536b28c..7c8d83bd73613b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -164,6 +164,9 @@ Resolutions to C++ Defect Reports
 - Clang now diagnoses declarative nested-name-specifiers with 
pack-index-specifiers.
   (`CWG2858: Declarative nested-name-specifiers and pack-index-specifiers 
`_).
 
+- Allow floating-point promotions and conversions in converted constant 
expressions.
+  (`CWG2851 Allow floating-point conversions in converted constant expressions 
`_).
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index fdca82934cb4dc..08ebb28ff17b25 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -85,6 +85,10 @@ def err_expr_not_cce : Error<
   "%select{case value|enumerator value|non-type template argument|"
   "array size|explicit specifier argument|noexcept specifier argument|"
   "call to 'size()'|call to 'data()'}0 is not a constant expression">;
+def err_float_conv_cant_represent : Error<
+  "non-type template argument evaluates to %0 which can not be "
+  "represented in type %1"
+>;
 def ext_cce_narrowing : ExtWarn<
   "%select{case value|enumerator value|non-type template argument|"
   "array size|explicit specifier argument|noexcept specifier argument|"
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 04cd9e78739d20..c35517db946b1c 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6072,6 +6072,10 @@ static bool CheckConvertedConstantConversions(Sema &S,
   case ICK_Integral_Promotion:
   case ICK_Integral_Conversion: // Narrowing conversions are checked elsewhere.
   case ICK_Zero_Queue_Conversion:
+  // Per CWG2851, floating-point promotions and conversions are allowed.
+  // The value of a conversion is checked afterwards.
+  case ICK_Floating_Promotion:
+  case ICK_Floating_Conversion:
 return true;
 
   case ICK_Boolean_Conversion:
@@ -6091,9 +6095,7 @@ static bool CheckConvertedConstantConversions(Sema &S,
 // only permitted if the source type is std::nullptr_t.
 return SCS.getFromType()->isNullPtrType();
 
-  case ICK_Floating_Promotion:
   case ICK_Complex_Promotion:
-  case ICK_Floating_Conversion:
   case ICK_Complex_Conversion:
   case ICK_Floating_Integral:
   case ICK_Compatible_Conversion:
@@ -6229,7 +6231,37 @@ static ExprResult BuildConvertedConstantExpression(Sema 
&S, Expr *From,
   if (Result.isInvalid())
 return Result;
 
-  // Check for a narrowing implicit conversion.
+  if (SCS->Second == ICK_Floating_Conversion) {
+// Unlike with narrowing conversions, the value must fit
+// exactly even if it is in range
+assert(CCE == Sema::CCEKind::CCEK_TemplateArg &&
+   "Only non-type template args should use floating-point 
conversions");
+
+// Initializer is From, except it is a full-expression
+const Expr *Initializer =
+IgnoreNarrowingConversion(S.Context, Result.get());
+
+// If it's value-dependent, we can't tell whether it will fit
+if (Initializer->isValueDependent())
+  return Result;
+
+if (!Initializer->isCXX11ConstantExpr(S.Context, &PreNarrowingValue)) {
+  S.Diag(Initializer->getBeginLoc(), diag::err_expr_not_cce) << CCE;
+  return Result;
+}
+
+llvm::APFloat PostNarrowingValue = PreNarrowingValue.getFloat();
+bool LosesInfo = true;
+PostNarrowingValue.convert(S.Context.getFloatTypeSemantics(T),
+   llvm::APFloat::rmNearestTiesToEven, &LosesInfo);
+if (LosesInfo)
+  S.Diag(From->getBeginLoc(), diag::err_float_conv_cant_represent)
+  << PreNarrowingValue.getAsString(S.Context, From->getType()) << T;
+
+return Result;
+  }
+
+  // Check for a narrowing integer conversion.
   bool ReturnPreNarrowingValue = false;
   QualType PreNarrowingType;
   switch (SCS->getNarrowingKind(S.Context, Result.get(), PreNarrowingValue,
diff --git a/clang/test/CXX/drs/dr28xx.cpp b/clang/test/CXX/drs/dr28xx.cpp
index 4d9b0c76758d53..cf9676ddb73385 100644
--- a/clang/test/CXX/drs/dr28xx.cpp
+++ b/clang/test/CXX/

[clang] [clang] Implement CWG2851: floating-point conversions in converted constant expressions (PR #90387)

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

https://github.com/Endilll commented:

I'm fine with the way DR test is written, but I'm not qualified to review the 
contents on the test, unfortunately.

I'd like to point to related Core issues 
[CWG2836](https://cplusplus.github.io/CWG/issues/2836.html) and 
[CWG2864](https://cplusplus.github.io/CWG/issues/2864.html).

You also need to run `clang/www/make_cxx_dr_status` to update the DR status 
page.

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


[clang] [Clang][Sema] Fix a bug on template partial specialization with issue on deduction of nontype tempalte parameter (PR #90376)

2024-04-28 Thread Qizhi Hu via cfe-commits


@@ -8508,6 +8507,16 @@ Sema::BuildExpressionFromDeclTemplateArgument(const 
TemplateArgument &Arg,
   } else {
 assert(ParamType->isReferenceType() &&
"unexpected type for decl template argument");
+if (ParamType->isLValueReferenceType())
+  if (NonTypeTemplateParmDecl *NTTP =
+  dyn_cast_if_present(TemplateParam)) {
+QualType TemplateParamType = NTTP->getType();
+const AutoType *AT = TemplateParamType->getAs();
+if (AT && AT->isDecltypeAuto())
+  RefExpr = new (getASTContext())
+  ParenExpr(RefExpr.get()->getBeginLoc(),

jcsxky wrote:

Ah, thanks for your remind! `SubstNonTypeTemplateParmExpr` is more suitable 
here.

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


[clang] [Clang][Sema] Fix a bug on template partial specialization with issue on deduction of nontype tempalte parameter (PR #90376)

2024-04-28 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/90376

>From 641f3e695c4bf7cd67e9aff0e0d345b59ad88685 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Sun, 28 Apr 2024 14:24:30 +0800
Subject: [PATCH] [Clang][Sema] Fix a bug on template partial specialization
 with issue on deduction of nontype tempalte parameter

---
 clang/docs/ReleaseNotes.rst  |  2 ++
 clang/include/clang/Sema/Sema.h  | 10 ++
 clang/lib/Sema/SemaTemplate.cpp  | 18 ++
 clang/lib/Sema/SemaTemplateDeduction.cpp | 10 ++
 clang/test/SemaCXX/PR68885.cpp   | 21 +
 5 files changed, 49 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/SemaCXX/PR68885.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a1390d6536b28c..8c1ba2a50b921b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -588,6 +588,8 @@ Bug Fixes to C++ Support
 - Fixed a use-after-free bug in parsing of type constraints with default 
arguments that involve lambdas. (#GH67235)
 - Fixed bug in which the body of a consteval lambda within a template was not 
parsed as within an
   immediate function context.
+- Fix a bug on template partial specialization with issue on deduction of 
nontype tempalte parameter
+  whose type is `decltype(auto)`. Fixes (#GH68885).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1ca523ec88c2f9..809b9c4498f697 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9249,7 +9249,8 @@ class Sema final : public SemaBase {
   void NoteTemplateParameterLocation(const NamedDecl &Decl);
 
   ExprResult BuildExpressionFromDeclTemplateArgument(
-  const TemplateArgument &Arg, QualType ParamType, SourceLocation Loc);
+  const TemplateArgument &Arg, QualType ParamType, SourceLocation Loc,
+  NamedDecl *TemplateParam = nullptr);
   ExprResult
   BuildExpressionFromNonTypeTemplateArgument(const TemplateArgument &Arg,
  SourceLocation Loc);
@@ -9572,9 +9573,10 @@ class Sema final : public SemaBase {
 
   bool isSameOrCompatibleFunctionType(QualType Param, QualType Arg);
 
-  TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument 
&Arg,
-QualType NTTPType,
-SourceLocation Loc);
+  TemplateArgumentLoc
+  getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, QualType NTTPType,
+SourceLocation Loc,
+NamedDecl *TemplateParam = nullptr);
 
   /// Get a template argument mapping the given template parameter to itself,
   /// e.g. for X in \c template, this would return an expression 
template
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index bbcb7c33a98579..5425d862a06c82 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -8438,10 +8438,9 @@ void Sema::NoteTemplateParameterLocation(const NamedDecl 
&Decl) {
 /// declaration and the type of its corresponding non-type template
 /// parameter, produce an expression that properly refers to that
 /// declaration.
-ExprResult
-Sema::BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg,
-  QualType ParamType,
-  SourceLocation Loc) {
+ExprResult Sema::BuildExpressionFromDeclTemplateArgument(
+const TemplateArgument &Arg, QualType ParamType, SourceLocation Loc,
+NamedDecl *TemplateParam) {
   // C++ [temp.param]p8:
   //
   //   A non-type template-parameter of type "array of T" or
@@ -8508,6 +8507,17 @@ Sema::BuildExpressionFromDeclTemplateArgument(const 
TemplateArgument &Arg,
   } else {
 assert(ParamType->isReferenceType() &&
"unexpected type for decl template argument");
+  if (NonTypeTemplateParmDecl *NTTP =
+  dyn_cast_if_present(TemplateParam)) {
+QualType TemplateParamType = NTTP->getType();
+const AutoType *AT = TemplateParamType->getAs();
+if (AT && AT->isDecltypeAuto()) {
+RefExpr = new (getASTContext()) SubstNonTypeTemplateParmExpr(
+ParamType->getPointeeType(), RefExpr.get()->getValueKind(),
+RefExpr.get()->getExprLoc(), RefExpr.get(), VD, 0, std::nullopt,
+true);
+}
+  }
   }
 
   // At this point we should have the right value category.
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index c3815bca038554..e93f7bd842e444 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2639,7 +2639,8 @@ static bool isSameTemplateArg(ASTContext &Context,
 /// argument.
 TemplateArgumentLoc
 Sema::getTriv

[clang] [Clang][Sema] Fix a bug on template partial specialization with issue on deduction of nontype tempalte parameter (PR #90376)

2024-04-28 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 37eb9c9632fb5e82827d1a0559f2279e9a9f1969 
641f3e695c4bf7cd67e9aff0e0d345b59ad88685 -- clang/test/SemaCXX/PR68885.cpp 
clang/include/clang/Sema/Sema.h clang/lib/Sema/SemaTemplate.cpp 
clang/lib/Sema/SemaTemplateDeduction.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 5425d862a0..6e5f7bd61a 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -8507,17 +8507,17 @@ ExprResult 
Sema::BuildExpressionFromDeclTemplateArgument(
   } else {
 assert(ParamType->isReferenceType() &&
"unexpected type for decl template argument");
-  if (NonTypeTemplateParmDecl *NTTP =
-  dyn_cast_if_present(TemplateParam)) {
-QualType TemplateParamType = NTTP->getType();
-const AutoType *AT = TemplateParamType->getAs();
-if (AT && AT->isDecltypeAuto()) {
+if (NonTypeTemplateParmDecl *NTTP =
+dyn_cast_if_present(TemplateParam)) {
+  QualType TemplateParamType = NTTP->getType();
+  const AutoType *AT = TemplateParamType->getAs();
+  if (AT && AT->isDecltypeAuto()) {
 RefExpr = new (getASTContext()) SubstNonTypeTemplateParmExpr(
 ParamType->getPointeeType(), RefExpr.get()->getValueKind(),
 RefExpr.get()->getExprLoc(), RefExpr.get(), VD, 0, std::nullopt,
 true);
-}
   }
+}
   }
 
   // At this point we should have the right value category.

``




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


[clang] [Clang][Sema] Fix a bug on template partial specialization with issue on deduction of nontype tempalte parameter (PR #90376)

2024-04-28 Thread Qizhi Hu via cfe-commits

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


[clang] [Clang][Sema] Fix a bug on template partial specialization with issue on deduction of nontype tempalte parameter (PR #90376)

2024-04-28 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/90376

>From f28eba548ae942ab3e567e7b2550a461e8fd5eac Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Sun, 28 Apr 2024 14:24:30 +0800
Subject: [PATCH] [Clang][Sema] Fix a bug on template partial specialization
 with issue on deduction of nontype tempalte parameter

---
 clang/docs/ReleaseNotes.rst  |  2 ++
 clang/include/clang/Sema/Sema.h  | 10 ++
 clang/lib/Sema/SemaTemplate.cpp  | 18 ++
 clang/lib/Sema/SemaTemplateDeduction.cpp | 10 ++
 clang/test/SemaCXX/PR68885.cpp   | 21 +
 5 files changed, 49 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/SemaCXX/PR68885.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a1390d6536b28c..8c1ba2a50b921b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -588,6 +588,8 @@ Bug Fixes to C++ Support
 - Fixed a use-after-free bug in parsing of type constraints with default 
arguments that involve lambdas. (#GH67235)
 - Fixed bug in which the body of a consteval lambda within a template was not 
parsed as within an
   immediate function context.
+- Fix a bug on template partial specialization with issue on deduction of 
nontype tempalte parameter
+  whose type is `decltype(auto)`. Fixes (#GH68885).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1ca523ec88c2f9..809b9c4498f697 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9249,7 +9249,8 @@ class Sema final : public SemaBase {
   void NoteTemplateParameterLocation(const NamedDecl &Decl);
 
   ExprResult BuildExpressionFromDeclTemplateArgument(
-  const TemplateArgument &Arg, QualType ParamType, SourceLocation Loc);
+  const TemplateArgument &Arg, QualType ParamType, SourceLocation Loc,
+  NamedDecl *TemplateParam = nullptr);
   ExprResult
   BuildExpressionFromNonTypeTemplateArgument(const TemplateArgument &Arg,
  SourceLocation Loc);
@@ -9572,9 +9573,10 @@ class Sema final : public SemaBase {
 
   bool isSameOrCompatibleFunctionType(QualType Param, QualType Arg);
 
-  TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument 
&Arg,
-QualType NTTPType,
-SourceLocation Loc);
+  TemplateArgumentLoc
+  getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, QualType NTTPType,
+SourceLocation Loc,
+NamedDecl *TemplateParam = nullptr);
 
   /// Get a template argument mapping the given template parameter to itself,
   /// e.g. for X in \c template, this would return an expression 
template
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index bbcb7c33a98579..6e5f7bd61a03a2 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -8438,10 +8438,9 @@ void Sema::NoteTemplateParameterLocation(const NamedDecl 
&Decl) {
 /// declaration and the type of its corresponding non-type template
 /// parameter, produce an expression that properly refers to that
 /// declaration.
-ExprResult
-Sema::BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg,
-  QualType ParamType,
-  SourceLocation Loc) {
+ExprResult Sema::BuildExpressionFromDeclTemplateArgument(
+const TemplateArgument &Arg, QualType ParamType, SourceLocation Loc,
+NamedDecl *TemplateParam) {
   // C++ [temp.param]p8:
   //
   //   A non-type template-parameter of type "array of T" or
@@ -8508,6 +8507,17 @@ Sema::BuildExpressionFromDeclTemplateArgument(const 
TemplateArgument &Arg,
   } else {
 assert(ParamType->isReferenceType() &&
"unexpected type for decl template argument");
+if (NonTypeTemplateParmDecl *NTTP =
+dyn_cast_if_present(TemplateParam)) {
+  QualType TemplateParamType = NTTP->getType();
+  const AutoType *AT = TemplateParamType->getAs();
+  if (AT && AT->isDecltypeAuto()) {
+RefExpr = new (getASTContext()) SubstNonTypeTemplateParmExpr(
+ParamType->getPointeeType(), RefExpr.get()->getValueKind(),
+RefExpr.get()->getExprLoc(), RefExpr.get(), VD, 0, std::nullopt,
+true);
+  }
+}
   }
 
   // At this point we should have the right value category.
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index c3815bca038554..e93f7bd842e444 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2639,7 +2639,8 @@ static bool isSameTemplateArg(ASTContext &Context,
 /// argument.
 TemplateArgumentLoc
 Sema::getTrivialTemplateArg

[clang] [X86_64] Fix empty field error in vaarg of C++. (PR #90389)

2024-04-28 Thread Longsheng Mou via cfe-commits

https://github.com/CoTinker created 
https://github.com/llvm/llvm-project/pull/90389

Such struct types:
```
struct {
  struct{} a;
  long long b;
};

stuct {
  struct{} a;
  double b;
};
```
For such structures, Lo is NoClass and Hi is Integer/SSE. And when this 
structure argument is passed, the high part is passed at offset 8 in memory. So 
we should do special handling for these types in EmitVAArg. Fix #79790 and 
#86371.

>From 59439be8b4111a0295d42305475a0ac7980b44e7 Mon Sep 17 00:00:00 2001
From: Longsheng Mou 
Date: Sun, 28 Apr 2024 17:14:29 +0800
Subject: [PATCH] [X86_64] Fix empty field error in vaarg of C++.

Such struct types:
```
struct {
  struct{} a;
  long long b;
};

stuct {
  struct{} a;
  double b;
};
```
For such structures, Lo is NoClass and Hi is Integer/SSE. And when
this structure argument is passed, the high part is passed at
offset 8 in memory. So we should do special handling for these types
in EmitVAArg.
---
 clang/lib/CodeGen/Targets/X86.cpp  | 36 +--
 clang/test/CodeGenCXX/x86_64-vaarg.cpp | 64 +++---
 2 files changed, 90 insertions(+), 10 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 94cf0d86f9bed7..525e37d5097f58 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -3123,8 +3123,22 @@ Address X86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, 
Address VAListAddr,
 
 RegAddr = Tmp.withElementType(LTy);
   } else if (neededInt) {
-RegAddr = Address(CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, 
gp_offset),
-  LTy, CharUnits::fromQuantity(8));
+if (AI.isDirect() && AI.getDirectOffset() == 8) {
+  Address Tmp = CGF.CreateMemTemp(Ty);
+  llvm::StructType *ST = cast(LTy);
+  Tmp = Tmp.withElementType(ST);
+  llvm::Type *TyHi = ST->getElementType(1);
+  llvm::Value *GPAddr =
+  CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, gp_offset);
+  llvm::Value *V = CGF.Builder.CreateAlignedLoad(
+  TyHi, GPAddr,
+  CharUnits::fromQuantity(getDataLayout().getABITypeAlign(TyHi)));
+  CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 1));
+  RegAddr = Tmp.withElementType(LTy);
+} else
+  RegAddr =
+  Address(CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, gp_offset),
+  LTy, CharUnits::fromQuantity(8));
 
 // Copy to a temporary if necessary to ensure the appropriate alignment.
 auto TInfo = getContext().getTypeInfoInChars(Ty);
@@ -3140,8 +3154,22 @@ Address X86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, 
Address VAListAddr,
 }
 
   } else if (neededSSE == 1) {
-RegAddr = Address(CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, 
fp_offset),
-  LTy, CharUnits::fromQuantity(16));
+if (AI.isDirect() && AI.getDirectOffset() == 8) {
+  Address Tmp = CGF.CreateMemTemp(Ty);
+  llvm::StructType *ST = cast(LTy);
+  Tmp = Tmp.withElementType(ST);
+  llvm::Type *TyHi = ST->getElementType(1);
+  llvm::Value *FPAddr =
+  CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, fp_offset);
+  llvm::Value *V = CGF.Builder.CreateAlignedLoad(
+  TyHi, FPAddr,
+  CharUnits::fromQuantity(getDataLayout().getABITypeAlign(TyHi)));
+  CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 1));
+  RegAddr = Tmp.withElementType(LTy);
+} else
+  RegAddr =
+  Address(CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, fp_offset),
+  LTy, CharUnits::fromQuantity(16));
   } else {
 assert(neededSSE == 2 && "Invalid number of needed registers!");
 // SSE registers are spaced 16 bytes apart in the register save
diff --git a/clang/test/CodeGenCXX/x86_64-vaarg.cpp 
b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
index 985a0cc41a1410..dc6d9f070cf51f 100644
--- a/clang/test/CodeGenCXX/x86_64-vaarg.cpp
+++ b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
@@ -32,6 +32,7 @@ typedef struct {
 // CHECK-NEXT:[[RETVAL:%.*]] = alloca [[STRUCT_S1:%.*]], align 8
 // CHECK-NEXT:[[Z_ADDR:%.*]] = alloca i32, align 4
 // CHECK-NEXT:[[LIST:%.*]] = alloca [1 x %struct.__va_list_tag], align 16
+// CHECK-NEXT:[[TMP:%.*]] = alloca [[STRUCT_S1]], align 8
 // CHECK-NEXT:store i32 [[Z:%.*]], ptr [[Z_ADDR]], align 4
 // CHECK-NEXT:[[ARRAYDECAY:%.*]] = getelementptr inbounds [1 x 
%struct.__va_list_tag], ptr [[LIST]], i64 0, i64 0
 // CHECK-NEXT:call void @llvm.va_start.p0(ptr [[ARRAYDECAY]])
@@ -44,8 +45,11 @@ typedef struct {
 // CHECK-NEXT:[[TMP0:%.*]] = getelementptr inbounds 
[[STRUCT___VA_LIST_TAG]], ptr [[ARRAYDECAY1]], i32 0, i32 3
 // CHECK-NEXT:[[REG_SAVE_AREA:%.*]] = load ptr, ptr [[TMP0]], align 16
 // CHECK-NEXT:[[TMP1:%.*]] = getelementptr i8, ptr [[REG_SAVE_AREA]], i32 
[[FP_OFFSET]]
-// CHECK-NEXT:[[TMP2:%.*]] = add i32 [[FP_OFFSET]], 16
-// CHECK-NEXT:store i32 [[TMP2]], ptr [[FP_OFFSET_P]], align 4
+// CHECK-NEXT:[[TMP2:%.*

[clang] [X86_64] Fix empty field error in vaarg of C++. (PR #90389)

2024-04-28 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-x86

@llvm/pr-subscribers-clang

Author: Longsheng Mou (CoTinker)


Changes

Such struct types:
```
struct {
  struct{} a;
  long long b;
};

stuct {
  struct{} a;
  double b;
};
```
For such structures, Lo is NoClass and Hi is Integer/SSE. And when this 
structure argument is passed, the high part is passed at offset 8 in memory. So 
we should do special handling for these types in EmitVAArg. Fix #79790 
and #86371.

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


2 Files Affected:

- (modified) clang/lib/CodeGen/Targets/X86.cpp (+32-4) 
- (modified) clang/test/CodeGenCXX/x86_64-vaarg.cpp (+58-6) 


``diff
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 94cf0d86f9bed7..525e37d5097f58 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -3123,8 +3123,22 @@ Address X86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, 
Address VAListAddr,
 
 RegAddr = Tmp.withElementType(LTy);
   } else if (neededInt) {
-RegAddr = Address(CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, 
gp_offset),
-  LTy, CharUnits::fromQuantity(8));
+if (AI.isDirect() && AI.getDirectOffset() == 8) {
+  Address Tmp = CGF.CreateMemTemp(Ty);
+  llvm::StructType *ST = cast(LTy);
+  Tmp = Tmp.withElementType(ST);
+  llvm::Type *TyHi = ST->getElementType(1);
+  llvm::Value *GPAddr =
+  CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, gp_offset);
+  llvm::Value *V = CGF.Builder.CreateAlignedLoad(
+  TyHi, GPAddr,
+  CharUnits::fromQuantity(getDataLayout().getABITypeAlign(TyHi)));
+  CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 1));
+  RegAddr = Tmp.withElementType(LTy);
+} else
+  RegAddr =
+  Address(CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, gp_offset),
+  LTy, CharUnits::fromQuantity(8));
 
 // Copy to a temporary if necessary to ensure the appropriate alignment.
 auto TInfo = getContext().getTypeInfoInChars(Ty);
@@ -3140,8 +3154,22 @@ Address X86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, 
Address VAListAddr,
 }
 
   } else if (neededSSE == 1) {
-RegAddr = Address(CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, 
fp_offset),
-  LTy, CharUnits::fromQuantity(16));
+if (AI.isDirect() && AI.getDirectOffset() == 8) {
+  Address Tmp = CGF.CreateMemTemp(Ty);
+  llvm::StructType *ST = cast(LTy);
+  Tmp = Tmp.withElementType(ST);
+  llvm::Type *TyHi = ST->getElementType(1);
+  llvm::Value *FPAddr =
+  CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, fp_offset);
+  llvm::Value *V = CGF.Builder.CreateAlignedLoad(
+  TyHi, FPAddr,
+  CharUnits::fromQuantity(getDataLayout().getABITypeAlign(TyHi)));
+  CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 1));
+  RegAddr = Tmp.withElementType(LTy);
+} else
+  RegAddr =
+  Address(CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, fp_offset),
+  LTy, CharUnits::fromQuantity(16));
   } else {
 assert(neededSSE == 2 && "Invalid number of needed registers!");
 // SSE registers are spaced 16 bytes apart in the register save
diff --git a/clang/test/CodeGenCXX/x86_64-vaarg.cpp 
b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
index 985a0cc41a1410..dc6d9f070cf51f 100644
--- a/clang/test/CodeGenCXX/x86_64-vaarg.cpp
+++ b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
@@ -32,6 +32,7 @@ typedef struct {
 // CHECK-NEXT:[[RETVAL:%.*]] = alloca [[STRUCT_S1:%.*]], align 8
 // CHECK-NEXT:[[Z_ADDR:%.*]] = alloca i32, align 4
 // CHECK-NEXT:[[LIST:%.*]] = alloca [1 x %struct.__va_list_tag], align 16
+// CHECK-NEXT:[[TMP:%.*]] = alloca [[STRUCT_S1]], align 8
 // CHECK-NEXT:store i32 [[Z:%.*]], ptr [[Z_ADDR]], align 4
 // CHECK-NEXT:[[ARRAYDECAY:%.*]] = getelementptr inbounds [1 x 
%struct.__va_list_tag], ptr [[LIST]], i64 0, i64 0
 // CHECK-NEXT:call void @llvm.va_start.p0(ptr [[ARRAYDECAY]])
@@ -44,8 +45,11 @@ typedef struct {
 // CHECK-NEXT:[[TMP0:%.*]] = getelementptr inbounds 
[[STRUCT___VA_LIST_TAG]], ptr [[ARRAYDECAY1]], i32 0, i32 3
 // CHECK-NEXT:[[REG_SAVE_AREA:%.*]] = load ptr, ptr [[TMP0]], align 16
 // CHECK-NEXT:[[TMP1:%.*]] = getelementptr i8, ptr [[REG_SAVE_AREA]], i32 
[[FP_OFFSET]]
-// CHECK-NEXT:[[TMP2:%.*]] = add i32 [[FP_OFFSET]], 16
-// CHECK-NEXT:store i32 [[TMP2]], ptr [[FP_OFFSET_P]], align 4
+// CHECK-NEXT:[[TMP2:%.*]] = load double, ptr [[TMP1]], align 8
+// CHECK-NEXT:[[TMP3:%.*]] = getelementptr inbounds [[STRUCT_S1]], ptr 
[[TMP]], i32 0, i32 1
+// CHECK-NEXT:store double [[TMP2]], ptr [[TMP3]], align 8
+// CHECK-NEXT:[[TMP4:%.*]] = add i32 [[FP_OFFSET]], 16
+// CHECK-NEXT:store i32 [[TMP4]], ptr [[FP_OFFSET_P]], align 4
 // CHECK-NEXT:br label [[VAARG_END:%.*]]
 // CHECK:   vaarg.in_mem:
 // CHECK-NEXT:[[OVERFLOW_ARG_AR

[clang] [clang] Allow constexpr cast from `void*` in more cases (PR #89484)

2024-04-28 Thread via cfe-commits

github-actions[bot] wrote:

⚠️ We detected that you are using a GitHub private e-mail address to contribute 
to the repo. Please turn off [Keep my email addresses 
private](https://github.com/settings/emails) setting in your account. See 
[LLVM 
Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it)
 for more information.

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


[clang] Add new flag -Wpointer-integer-ordered-compare (PR #88489)

2024-04-28 Thread via cfe-commits

https://github.com/vincent-mailhol approved this pull request.

As far as my understanding of the LLVM project goes, this change looks good to 
me. I am not an expert of this project, but regardless and for what it is 
worth, here is my approval (with one nitpick).

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


[clang] Add new flag -Wpointer-integer-ordered-compare (PR #88489)

2024-04-28 Thread via cfe-commits


@@ -245,6 +245,13 @@ Modified Compiler Flags
f3 *c = (f3 *)x;
  }
 
+- Added a new diagnostic flag ``-Wpointer-integer-ordered-compare`` which is
+  grouped under ``-Wpointer-integer-compare`` and moved previously
+  ungrouped diagnostics 
``ext_typecheck_ordered_comparison_of_pointer_integer``,
+  ``ext_typecheck_ordered_comparison_of_pointer_and_zero`` under
+  ``-Wpointer-integer-ordered-compare``.This also resolves false negative

vincent-mailhol wrote:

Nitpick: put a space after the period.
```suggestion
  ``-Wpointer-integer-ordered-compare``. This also resolves false negative
```

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


[clang] Add new flag -Wpointer-integer-ordered-compare (PR #88489)

2024-04-28 Thread via cfe-commits

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


[clang] [compiler-rt] [libc] [libclc] [libcxxabi] [lld] [lldb] [llvm] [mlir] llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:3804: lacking () for c… (PR #90391)

2024-04-28 Thread via cfe-commits

https://github.com/luolent created 
https://github.com/llvm/llvm-project/pull/90391

Hi,

parenthesis were added as requested on ternary operators with non trivial 
conditions.
I used this [precedence 
table](https://en.cppreference.com/w/cpp/language/operator_precedence) to make 
sure we get the expected behavior on each change.

There is also a discussion on the issue, about creating a pass in clang-tidy in 
order to catch these missing parenthesis automatically.
Let me know if the above is desired and I can take it over.

Thanks!

>From f860432b9434c81ab55d5eded9c976edc58c3fab Mon Sep 17 00:00:00 2001
From: luolent 
Date: Sat, 27 Apr 2024 22:17:58 +0300
Subject: [PATCH] llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:3804: lacking
 () for clarity

---
 clang/lib/Basic/Targets/AMDGPU.cpp|  2 +-
 compiler-rt/lib/xray/xray_utils.h |  2 +-
 libc/src/__support/FPUtil/aarch64/FEnvImpl.h  | 20 
 .../FPUtil/aarch64/fenv_darwin_impl.h | 48 +--
 libc/src/__support/FPUtil/arm/FEnvImpl.h  | 40 
 libc/src/__support/FPUtil/riscv/FEnvImpl.h| 20 
 libc/src/__support/FPUtil/x86_64/FEnvImpl.h   | 24 +-
 libclc/generic/lib/math/log_base.h|  2 +-
 libcxxabi/src/cxa_personality.cpp |  2 +-
 lld/ELF/LinkerScript.cpp  |  2 +-
 .../source/MacOSX/MachException.cpp   |  2 +-
 .../AMDGPU/AsmParser/AMDGPUAsmParser.cpp  |  4 +-
 .../Disassembler/AMDGPUDisassembler.cpp   |  4 +-
 llvm/lib/Target/AVR/AVRAsmPrinter.cpp |  2 +-
 llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp  |  4 +-
 .../lib/Target/X86/AsmParser/X86AsmParser.cpp |  2 +-
 .../X86/MCTargetDesc/X86MCCodeEmitter.cpp |  2 +-
 .../Transforms/TosaDecomposeTransposeConv.cpp |  4 +-
 18 files changed, 93 insertions(+), 93 deletions(-)

diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index 5742885df0461b..cc7be64656e5b2 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -232,7 +232,7 @@ AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple 
&Triple,
 
   HasLegalHalfType = true;
   HasFloat16 = true;
-  WavefrontSize = GPUFeatures & llvm::AMDGPU::FEATURE_WAVE32 ? 32 : 64;
+  WavefrontSize = (GPUFeatures & llvm::AMDGPU::FEATURE_WAVE32) ? 32 : 64;
   AllowAMDGPUUnsafeFPAtomics = Opts.AllowAMDGPUUnsafeFPAtomics;
 
   // Set pointer width and alignment for the generic address space.
diff --git a/compiler-rt/lib/xray/xray_utils.h 
b/compiler-rt/lib/xray/xray_utils.h
index 333826168c0db2..5dc73d7fa8cdea 100644
--- a/compiler-rt/lib/xray/xray_utils.h
+++ b/compiler-rt/lib/xray/xray_utils.h
@@ -61,7 +61,7 @@ constexpr size_t gcd(size_t a, size_t b) {
 constexpr size_t lcm(size_t a, size_t b) { return a * b / gcd(a, b); }
 
 constexpr size_t nearest_boundary(size_t number, size_t multiple) {
-  return multiple * ((number / multiple) + (number % multiple ? 1 : 0));
+  return multiple * ((number / multiple) + ((number % multiple) ? 1 : 0));
 }
 
 constexpr size_t next_pow2_helper(size_t num, size_t acc) {
diff --git a/libc/src/__support/FPUtil/aarch64/FEnvImpl.h 
b/libc/src/__support/FPUtil/aarch64/FEnvImpl.h
index d1d92169475d15..cd8a5970edd65a 100644
--- a/libc/src/__support/FPUtil/aarch64/FEnvImpl.h
+++ b/libc/src/__support/FPUtil/aarch64/FEnvImpl.h
@@ -53,19 +53,19 @@ struct FEnv {
   static constexpr uint32_t ExceptionControlFlagsBitPosition = 8;
 
   LIBC_INLINE static uint32_t getStatusValueForExcept(int excepts) {
-return (excepts & FE_INVALID ? INVALID : 0) |
-   (excepts & FE_DIVBYZERO ? DIVBYZERO : 0) |
-   (excepts & FE_OVERFLOW ? OVERFLOW : 0) |
-   (excepts & FE_UNDERFLOW ? UNDERFLOW : 0) |
-   (excepts & FE_INEXACT ? INEXACT : 0);
+return ((excepts & FE_INVALID) ? INVALID : 0) |
+   ((excepts & FE_DIVBYZERO) ? DIVBYZERO : 0) |
+   ((excepts & FE_OVERFLOW) ? OVERFLOW : 0) |
+   ((excepts & FE_UNDERFLOW) ? UNDERFLOW : 0) |
+   ((excepts & FE_INEXACT) ? INEXACT : 0);
   }
 
   LIBC_INLINE static int exceptionStatusToMacro(uint32_t status) {
-return (status & INVALID ? FE_INVALID : 0) |
-   (status & DIVBYZERO ? FE_DIVBYZERO : 0) |
-   (status & OVERFLOW ? FE_OVERFLOW : 0) |
-   (status & UNDERFLOW ? FE_UNDERFLOW : 0) |
-   (status & INEXACT ? FE_INEXACT : 0);
+return ((status & INVALID) ? FE_INVALID : 0) |
+   ((status & DIVBYZERO) ? FE_DIVBYZERO : 0) |
+   ((status & OVERFLOW) ? FE_OVERFLOW : 0) |
+   ((status & UNDERFLOW) ? FE_UNDERFLOW : 0) |
+   ((status & INEXACT) ? FE_INEXACT : 0);
   }
 
   static uint32_t getControlWord() {
diff --git a/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h 
b/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h
index 5b59ba38d67bb6..feb48e3719bf16 100644
--- a/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h
+++ b/libc/src/__support/FPUtil/aarch64/fen

[clang] [compiler-rt] [libc] [libclc] [libcxxabi] [lld] [lldb] [llvm] [mlir] llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:3804: lacking () for c… (PR #90391)

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


[clang] [compiler-rt] [libc] [libclc] [libcxxabi] [lld] [lldb] [llvm] [mlir] llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:3804: lacking () for c… (PR #90391)

2024-04-28 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-systemz
@llvm/pr-subscribers-backend-amdgpu

@llvm/pr-subscribers-clang

Author: None (luolent)


Changes

Hi,

parenthesis were added as requested on ternary operators with non trivial 
conditions.
I used this [precedence 
table](https://en.cppreference.com/w/cpp/language/operator_precedence) to make 
sure we get the expected behavior on each change.

There is also a discussion on the issue, about creating a pass in clang-tidy in 
order to catch these missing parenthesis automatically.
Let me know if the above is desired and I can take it over.

Thanks!

---

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


18 Files Affected:

- (modified) clang/lib/Basic/Targets/AMDGPU.cpp (+1-1) 
- (modified) compiler-rt/lib/xray/xray_utils.h (+1-1) 
- (modified) libc/src/__support/FPUtil/aarch64/FEnvImpl.h (+10-10) 
- (modified) libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h (+24-24) 
- (modified) libc/src/__support/FPUtil/arm/FEnvImpl.h (+20-20) 
- (modified) libc/src/__support/FPUtil/riscv/FEnvImpl.h (+10-10) 
- (modified) libc/src/__support/FPUtil/x86_64/FEnvImpl.h (+12-12) 
- (modified) libclc/generic/lib/math/log_base.h (+1-1) 
- (modified) libcxxabi/src/cxa_personality.cpp (+1-1) 
- (modified) lld/ELF/LinkerScript.cpp (+1-1) 
- (modified) lldb/tools/debugserver/source/MacOSX/MachException.cpp (+1-1) 
- (modified) llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp (+2-2) 
- (modified) llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp (+2-2) 
- (modified) llvm/lib/Target/AVR/AVRAsmPrinter.cpp (+1-1) 
- (modified) llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp (+2-2) 
- (modified) llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp (+1-1) 
- (modified) llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp (+1-1) 
- (modified) mlir/lib/Dialect/Tosa/Transforms/TosaDecomposeTransposeConv.cpp 
(+2-2) 


``diff
diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index 5742885df0461b..cc7be64656e5b2 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -232,7 +232,7 @@ AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple 
&Triple,
 
   HasLegalHalfType = true;
   HasFloat16 = true;
-  WavefrontSize = GPUFeatures & llvm::AMDGPU::FEATURE_WAVE32 ? 32 : 64;
+  WavefrontSize = (GPUFeatures & llvm::AMDGPU::FEATURE_WAVE32) ? 32 : 64;
   AllowAMDGPUUnsafeFPAtomics = Opts.AllowAMDGPUUnsafeFPAtomics;
 
   // Set pointer width and alignment for the generic address space.
diff --git a/compiler-rt/lib/xray/xray_utils.h 
b/compiler-rt/lib/xray/xray_utils.h
index 333826168c0db2..5dc73d7fa8cdea 100644
--- a/compiler-rt/lib/xray/xray_utils.h
+++ b/compiler-rt/lib/xray/xray_utils.h
@@ -61,7 +61,7 @@ constexpr size_t gcd(size_t a, size_t b) {
 constexpr size_t lcm(size_t a, size_t b) { return a * b / gcd(a, b); }
 
 constexpr size_t nearest_boundary(size_t number, size_t multiple) {
-  return multiple * ((number / multiple) + (number % multiple ? 1 : 0));
+  return multiple * ((number / multiple) + ((number % multiple) ? 1 : 0));
 }
 
 constexpr size_t next_pow2_helper(size_t num, size_t acc) {
diff --git a/libc/src/__support/FPUtil/aarch64/FEnvImpl.h 
b/libc/src/__support/FPUtil/aarch64/FEnvImpl.h
index d1d92169475d15..cd8a5970edd65a 100644
--- a/libc/src/__support/FPUtil/aarch64/FEnvImpl.h
+++ b/libc/src/__support/FPUtil/aarch64/FEnvImpl.h
@@ -53,19 +53,19 @@ struct FEnv {
   static constexpr uint32_t ExceptionControlFlagsBitPosition = 8;
 
   LIBC_INLINE static uint32_t getStatusValueForExcept(int excepts) {
-return (excepts & FE_INVALID ? INVALID : 0) |
-   (excepts & FE_DIVBYZERO ? DIVBYZERO : 0) |
-   (excepts & FE_OVERFLOW ? OVERFLOW : 0) |
-   (excepts & FE_UNDERFLOW ? UNDERFLOW : 0) |
-   (excepts & FE_INEXACT ? INEXACT : 0);
+return ((excepts & FE_INVALID) ? INVALID : 0) |
+   ((excepts & FE_DIVBYZERO) ? DIVBYZERO : 0) |
+   ((excepts & FE_OVERFLOW) ? OVERFLOW : 0) |
+   ((excepts & FE_UNDERFLOW) ? UNDERFLOW : 0) |
+   ((excepts & FE_INEXACT) ? INEXACT : 0);
   }
 
   LIBC_INLINE static int exceptionStatusToMacro(uint32_t status) {
-return (status & INVALID ? FE_INVALID : 0) |
-   (status & DIVBYZERO ? FE_DIVBYZERO : 0) |
-   (status & OVERFLOW ? FE_OVERFLOW : 0) |
-   (status & UNDERFLOW ? FE_UNDERFLOW : 0) |
-   (status & INEXACT ? FE_INEXACT : 0);
+return ((status & INVALID) ? FE_INVALID : 0) |
+   ((status & DIVBYZERO) ? FE_DIVBYZERO : 0) |
+   ((status & OVERFLOW) ? FE_OVERFLOW : 0) |
+   ((status & UNDERFLOW) ? FE_UNDERFLOW : 0) |
+   ((status & INEXACT) ? FE_INEXACT : 0);
   }
 
   static uint32_t getControlWord() {
diff --git a/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h 
b/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h
index 5b59ba38d67bb6..feb48e3719bf16 1006

[clang] [llvm] [RISCV] Add processor definition and scheduling model for XiangShan-KunMingHu (PR #90392)

2024-04-28 Thread via cfe-commits
=?utf-8?b?6YOd5bq36L6+?= 
Message-ID:
In-Reply-To: 


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


[clang] [llvm] [RISCV] Add processor definition and scheduling model for XiangShan-KunMingHu (PR #90392)

2024-04-28 Thread via cfe-commits
=?utf-8?b?6YOd5bq36L6+?= 
Message-ID:
In-Reply-To: 


llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (Bhe6669)


Changes

The "XiangShan" is a high-performance open-source RISC-V processor project, and 
The "KunMingHu" architecture is its third generation. Official documentation 
can be found 
at:[documentation](https://xiangshan-doc.readthedocs.io/zh-cn/latest/).

Currently, the KunMingHu core 
supports"RV64IMAFDCV_zba_zbb_zbc_zbs_zbkb_zbkc_zbkx_zknd_zkne_zknh_zksed_zksh_svinval_zicbom_zicboz_zicsr_zifencei".
 The scheduling model encompasses the basic configurations and instruction 
latencies of the KunMingHu core. Other components will be submitted in 
subsequent patches.

Co-authored-by:
Chen Jian
Lv Fang

---

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


8 Files Affected:

- (modified) clang/test/Driver/riscv-cpus.c (+37) 
- (modified) clang/test/Misc/target-invalid-cpu-note.c (+2-2) 
- (modified) llvm/lib/Target/RISCV/RISCV.td (+1) 
- (modified) llvm/lib/Target/RISCV/RISCVProcessors.td (+28) 
- (added) llvm/lib/Target/RISCV/RISCVSchedXiangShanKunMingHu.td (+1489) 
- (added) llvm/test/tools/llvm-mca/RISCV/XiangShan/gpr-bypass-kmh.s (+534) 
- (added) llvm/test/tools/llvm-mca/RISCV/XiangShan/no-sew-fp-8-16.s (+10) 
- (added) llvm/test/tools/llvm-mca/RISCV/XiangShan/vector-integer-arithmetic.s 
(+2271) 


``diff
diff --git a/clang/test/Driver/riscv-cpus.c b/clang/test/Driver/riscv-cpus.c
index ff2bd6f7c8ba34..54c44a35c3e82e 100644
--- a/clang/test/Driver/riscv-cpus.c
+++ b/clang/test/Driver/riscv-cpus.c
@@ -31,6 +31,40 @@
 // MCPU-XIANGSHAN-NANHU-SAME: "-target-feature" "+zks" "-target-feature" 
"+zksed" "-target-feature" "+zksh" "-target-feature" "+svinval"
 // MCPU-XIANGSHAN-NANHU-SAME: "-target-abi" "lp64d"
 
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=xiangshan-kunminghu | 
FileCheck -check-prefix=MCPU-XIANGSHAN-KUNMINGHU %s
+// MCPU-XIANGSHAN-KUNMINGHU: "-nostdsysteminc" "-target-cpu" 
"xiangshan-kunminghu"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+m"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+a"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+f"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+d"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+c"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+v"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicbom" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicboz" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zicsr" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zifencei"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zba" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbb" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbc"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbkb" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbkc" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbkx" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zbs"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zkn" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zknd" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zkne" 
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zknh"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zve32f"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zve32x"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zve64d"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zve64f"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zve64x"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zvl128b"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zvl32b"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-feature" "+zvl64b"
+// MCPU-XIANGSHAN-KUNMINGHU-SAME: "-target-abi" "lp64d"
+
+
 // We cannot check much for -mcpu=native, but it should be replaced by a valid 
CPU string.
 // RUN: %clang --target=riscv64 -### -c %s -mcpu=native 2> %t.err || true
 // RUN: FileCheck --input-file=%t.err -check-prefix=MCPU-NATIVE %s
@@ -76,6 +110,9 @@
 // RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=xiangshan-nanhu | 
FileCheck -check-prefix=MTUNE-XIANGSHAN-NANHU %s
 // MTUNE-XIANGSHAN-NANHU: "-tune-cpu" "xiangshan-nanhu"
 
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=xiangshan-kunminghu | 
FileCheck -check-prefix=MTUNE-XIANGSHAN-KUNMINGHU %s
+// MTUNE-XIANGSHAN-KUNMINGHU: "-tune-cpu" "xiangshan-kunminghu"
+
 // Check mtune alias CPU has resolved to the right CPU according XLEN.
 // RUN: %clang --target=riscv32 -### -c %s 2>&1 -mtune=generic | FileCheck 
-check-prefix=MTUNE-GENERIC-32 %s
 // MTUNE-GENERIC-32: "-tune-cpu" "generic"
diff --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index 21d80b7134508f..a95170aa01abd2 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++

[clang] 367efa0 - [NFC] [Modules] Avoid scanning the stored decl list twice when replace

2024-04-28 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-04-28T18:31:10+08:00
New Revision: 367efa0b0542e6f4171e8c914728946c302ab24b

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

LOG: [NFC] [Modules] Avoid scanning the stored decl list twice when replace
external decls

This patch fixes a FIXME in StoredDeclList::replaceExternalDecls.

StoredDeclList::replaceExternalDecls will iterate the list first to
remove some declarations and iterate the list again to get the tail of
the list.

It should be better to avoid the second iterations.

Added: 


Modified: 
clang/include/clang/AST/DeclContextInternals.h

Removed: 




diff  --git a/clang/include/clang/AST/DeclContextInternals.h 
b/clang/include/clang/AST/DeclContextInternals.h
index 42cc677f82135e..e169c485921929 100644
--- a/clang/include/clang/AST/DeclContextInternals.h
+++ b/clang/include/clang/AST/DeclContextInternals.h
@@ -42,11 +42,12 @@ class StoredDeclsList {
   /// external declarations.
   DeclsAndHasExternalTy Data;
 
-  template
-  void erase_if(Fn ShouldErase) {
+  template  DeclListNode::Decls *erase_if(Fn ShouldErase) {
 Decls List = Data.getPointer();
+
 if (!List)
-  return;
+  return nullptr;
+
 ASTContext &C = getASTContext();
 DeclListNode::Decls NewHead = nullptr;
 DeclListNode::Decls *NewLast = nullptr;
@@ -79,6 +80,17 @@ class StoredDeclsList {
 Data.setPointer(NewHead);
 
 assert(llvm::none_of(getLookupResult(), ShouldErase) && "Still exists!");
+
+if (!Data.getPointer())
+  // All declarations are erased.
+  return nullptr;
+else if (NewHead.is())
+  // The list only contains a declaration, the header itself.
+  return (DeclListNode::Decls *)&Data;
+else {
+  assert(NewLast && NewLast->is() && "Not the tail?");
+  return NewLast;
+}
   }
 
   void erase(NamedDecl *ND) {
@@ -161,7 +173,7 @@ class StoredDeclsList {
   void replaceExternalDecls(ArrayRef Decls) {
 // Remove all declarations that are either external or are replaced with
 // external declarations with higher visibilities.
-erase_if([Decls](NamedDecl *ND) {
+DeclListNode::Decls *Tail = erase_if([Decls](NamedDecl *ND) {
   if (ND->isFromASTFile())
 return true;
   // FIXME: Can we get rid of this loop completely?
@@ -189,24 +201,15 @@ class StoredDeclsList {
   DeclsAsList = Node;
 }
 
-DeclListNode::Decls Head = Data.getPointer();
-if (Head.isNull()) {
+if (!Data.getPointer()) {
   Data.setPointer(DeclsAsList);
   return;
 }
 
-// Find the end of the existing list.
-// FIXME: It would be possible to preserve information from erase_if to
-// avoid this rescan looking for the end of the list.
-DeclListNode::Decls *Tail = &Head;
-while (DeclListNode *Node = Tail->dyn_cast())
-  Tail = &Node->Rest;
-
 // Append the Decls.
 DeclListNode *Node = C.AllocateDeclListNode(Tail->get());
 Node->Rest = DeclsAsList;
 *Tail = Node;
-Data.setPointer(Head);
   }
 
   /// Return the list of all the decls.



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


[clang] [llvm] [RISCV] Add processor definition and scheduling model for XiangShan-KunMingHu (PR #90392)

2024-04-28 Thread Yingwei Zheng via cfe-commits
=?utf-8?b?6YOd5bq36L6+?= 
Message-ID:
In-Reply-To: 



@@ -378,3 +378,31 @@ def XIANGSHAN_NANHU : 
RISCVProcessorModel<"xiangshan-nanhu",
 TuneZExtHFusion,
 TuneZExtWFusion,
 TuneShiftedZExtWFusion]>;
+   
 
+def XIANGSHAN_KUNMINGHU : RISCVProcessorModel<"xiangshan-kunminghu",
+  XiangShanKunMingHuModel,
+  [Feature64Bit,
+   FeatureStdExtI,
+   FeatureStdExtZicsr,
+   FeatureStdExtZifencei,
+   FeatureStdExtM,
+   FeatureStdExtA,
+   FeatureStdExtF,
+   FeatureStdExtD,
+   FeatureStdExtC,
+   FeatureStdExtZba,
+   FeatureStdExtZbb,
+   FeatureStdExtZbc,
+   FeatureStdExtZbs,
+   FeatureStdExtZkn,
+   FeatureStdExtZksed,
+   FeatureStdExtZksh,
+   FeatureStdExtSvinval,
+   FeatureStdExtZicbom,
+   FeatureStdExtZicboz,
+   FeatureStdExtV,
+   FeatureStdExtZvl128b],
+   [TuneNoDefaultUnroll,

dtcxzyw wrote:

See https://github.com/llvm/llvm-project/pull/89359#discussion_r1574366104

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


[clang] [Modules] Process include files changes with -fmodules-validate-input-files-content and -fno-pch-timestamp options (PR #90319)

2024-04-28 Thread Ivan Murashko via cfe-commits

https://github.com/ivanmurashko updated 
https://github.com/llvm/llvm-project/pull/90319

>From 2a07774317c288ebe6cc55fed2fafd2989ba853e Mon Sep 17 00:00:00 2001
From: Ivan Murashko 
Date: Fri, 26 Apr 2024 22:45:26 +0100
Subject: [PATCH] [Modules] Process include files changes with
 -fmodules-validate-input-files-content and -fno-pch-timestamp options

There are two diffs that introduce some options required when you build modules
externally and cannot rely on file modification time as a key for detecting
input file changes.

https://reviews.llvm.org/D67249 introduced the
`-fmodules-validate-input-files-content` option, which allows the use of file
content hash instead of modification time.

https://reviews.llvm.org/D141632 propagated the use of `-fno-pch-timestamps`
with Clang modules.

There is a problem when the size of the input file (header) is not modified but
the content is. In this case, Clang cannot detect the file change when the
-fno-pch-timestamps option is used. The -fmodules-validate-input-files-content
option should help, but there is an issue with its application.

The issue can be fixed using the same trick that was applied during the
processing of ForceCheckCXX20ModulesInputFiles. The patch suggests a solution
and includes a LIT test to verify it.
---
 clang/lib/Serialization/ASTReader.cpp |  8 +
 .../Modules/implicit-module-no-timestamp.cpp  | 34 +++
 2 files changed, 42 insertions(+)
 create mode 100644 clang/test/Modules/implicit-module-no-timestamp.cpp

diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 0ef57a3ea804ef..4609ca3e1428c8 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -2630,6 +2630,14 @@ InputFile ASTReader::getInputFile(ModuleFile &F, 
unsigned ID, bool Complain) {
   F.StandardCXXModule && FileChange.Kind == Change::None)
 FileChange = HasInputContentChanged(FileChange);
 
+  // When we have StoredTime equal to zero and ValidateASTInputFilesContent,
+  // it is better to check the content of the input files because we cannot 
rely
+  // on the file modification time, which will be the same (zero) for these
+  // files.
+  if (!StoredTime && ValidateASTInputFilesContent &&
+  FileChange.Kind == Change::None)
+FileChange = HasInputContentChanged(FileChange);
+
   // For an overridden file, there is nothing to validate.
   if (!Overridden && FileChange.Kind != Change::None) {
 if (Complain && !Diags.isDiagnosticInFlight()) {
diff --git a/clang/test/Modules/implicit-module-no-timestamp.cpp 
b/clang/test/Modules/implicit-module-no-timestamp.cpp
new file mode 100644
index 00..1ead9d172f5c5e
--- /dev/null
+++ b/clang/test/Modules/implicit-module-no-timestamp.cpp
@@ -0,0 +1,34 @@
+// UNSUPPORTED: system-windows
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: cp a1.h a.h
+// RUN: %clang -fmodules -fmodules-validate-input-files-content -Xclang 
-fno-pch-timestamp -fimplicit-modules -fmodule-map-file=module.modulemap 
-fsyntax-only  -fmodules-cache-path=%t test1.cpp
+// RUN: cp a2.h a.h
+// RUN: %clang -fmodules -fmodules-validate-input-files-content -Xclang 
-fno-pch-timestamp -fimplicit-modules -fmodule-map-file=module.modulemap 
-fsyntax-only  -fmodules-cache-path=%t test2.cpp
+
+//--- a1.h
+#define FOO
+
+//--- a2.h
+#define BAR
+
+//--- module.modulemap
+module a {
+  header "a.h"
+}
+
+//--- test1.cpp
+#include "a.h"
+
+#ifndef FOO
+#error foo
+#endif
+
+//--- test2.cpp
+#include "a.h"
+
+#ifndef BAR
+#error bar
+#endif

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


[clang] [llvm] [RISCV] Add processor definition and scheduling model for XiangShan-KunMingHu (PR #90392)

2024-04-28 Thread Yingwei Zheng via cfe-commits
=?utf-8?b?6YOd5bq36L6+?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,1489 @@
+//==- RISCVSchedXiangShanKunMingHu.td - XiangShanKunMingHu Scheduling Defs -*- 
tablegen -*-=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// The XiangShan is a high-performance open-source RISC-V processor project 
+// initiated by the Institute of Computing Technology(ICT), Chinese Academy of 
Sciences(CAS). 
+// The KunMingHu architecture is its third-generation derivative, 
+// developed by the Institute of Computing Technology, Chinese Academy of 
Sciences  
+// and the Beijing Institute of Open Source Chip (BOSC), 
+// with a focus on achieving higher performance.
+// Source: https://github.com/OpenXiangShan/XiangShan
+// Documentation: https://github.com/OpenXiangShan/XiangShan-doc
+
+//===--===//
+// KunMingHu core supports 
"RV64IMAFDCV_zba_zbb_zbc_zbs_zbkb_zbkc_zbkx_zknd_zkne_zknh
+// _zksed_zksh_svinval_zicbom_zicboz_zicsr_zifencei"
+// then floating-point SEW can only be 64 and 32, not 16 and 8.
+class NoZvfhSchedSEWSet_rm8and16 {
+  defvar t = SchedSEWSet.val; 
+  defvar remove8and16 = !if(isF, !listremove(t, [8, 16]), t);
+  list val = remove8and16;
+}
+
+class NoZvfhSmallestSEW {
+  int r = !head(NoZvfhSchedSEWSet_rm8and16.val);
+}
+
+multiclass NoZvfh_LMULSEWReadAdvanceImpl writes = [],
+  list MxList, bit isF = 0,
+  bit isWidening = 0> {
+  if !exists(name # "_WorstCase") then
+def : ReadAdvance(name # "_WorstCase"), val, writes>;
+  foreach mx = MxList in {
+foreach sew = NoZvfhSchedSEWSet_rm8and16.val in
+  if !exists(name # "_" # mx # "_E" # sew) then
+def : ReadAdvance(name # "_" # mx # "_E" # sew), val, 
writes>;
+  }
+}
+
+multiclass LMULSEWReadAdvanceFnoZvfh 
writes = []>
+  : NoZvfh_LMULSEWReadAdvanceImpl;
+
+multiclass LMULSEWReadAdvanceFWnoZvfh 
writes = []>
+: NoZvfh_LMULSEWReadAdvanceImpl;
+
+//===--===//
+// If Zvfhmin and Zvfh are not supported, floating-point SEW can only be 32 or 
64.
+class NoZvfhSchedSEWSet_rm32and64 {
+  defvar t = SchedSEWSet.val;
+  defvar remove32and64 = !if(isF, !listremove(t, [32, 64]), t);
+  list val = remove32and64;
+}
+
+// Write-Impl
+multiclass NoZvfhLMULSEWWriteResImpl 
resources,
+   list MxList, bit isF = 0,
+   bit isWidening = 0> {
+  foreach mx = MxList in {
+foreach sew = NoZvfhSchedSEWSet_rm32and64.val in
+  if !exists(name # "_" # mx # "_E" # sew) then
+def : WriteRes(name # "_" # mx # "_E" # sew), 
resources>;
+  }
+}
+// Read-Impl
+multiclass NoZvfhLMULSEWReadAdvanceImpl 
writes = [],
+  list MxList, bit isF = 0,
+  bit isWidening = 0> {
+  foreach mx = MxList in {
+foreach sew = NoZvfhSchedSEWSet_rm32and64.val in
+  if !exists(name # "_" # mx # "_E" # sew) then
+def : ReadAdvance(name # "_" # mx # "_E" # sew), val, 
writes>;
+  }
+}
+
+// Write
+multiclass NoZvfhLMULSEWWriteResF 
resources>
+: NoZvfhLMULSEWWriteResImpl;
+
+multiclass NoZvfhLMULSEWWriteResFW 
resources>
+: NoZvfhLMULSEWWriteResImpl;
+
+multiclass NoZvfhLMULSEWWriteResFWRed 
resources>
+: NoZvfhLMULSEWWriteResImpl;
+
+// Read
+multiclass NoZvfhLMULSEWReadAdvanceF 
writes = []>
+  : NoZvfhLMULSEWReadAdvanceImpl;
+multiclass
+NoZvfhLMULSEWReadAdvanceFW writes = 
[]>
+: NoZvfhLMULSEWReadAdvanceImpl;
+
+multiclass UnsupportedSchedZvfh {
+let Unsupported = true in {
+// Write 
+// 13. Vector Floating-Point Instructions
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFALUV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFALUF", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWALUV", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWALUF", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMulV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMulF", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFDivV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFDivF", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWMulV", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWMulF", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMulAddV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMulAddF", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWMulAddV", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWMulAddF", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFSqrtV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFRecpV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMinMaxV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMinMaxF", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"Write

[clang] [llvm] [RISCV] Add processor definition and scheduling model for XiangShan-KunMingHu (PR #90392)

2024-04-28 Thread Yingwei Zheng via cfe-commits
=?utf-8?b?6YOd5bq36L6+?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,1489 @@
+//==- RISCVSchedXiangShanKunMingHu.td - XiangShanKunMingHu Scheduling Defs -*- 
tablegen -*-=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// The XiangShan is a high-performance open-source RISC-V processor project 
+// initiated by the Institute of Computing Technology(ICT), Chinese Academy of 
Sciences(CAS). 
+// The KunMingHu architecture is its third-generation derivative, 
+// developed by the Institute of Computing Technology, Chinese Academy of 
Sciences  
+// and the Beijing Institute of Open Source Chip (BOSC), 
+// with a focus on achieving higher performance.
+// Source: https://github.com/OpenXiangShan/XiangShan
+// Documentation: https://github.com/OpenXiangShan/XiangShan-doc
+
+//===--===//
+// KunMingHu core supports 
"RV64IMAFDCV_zba_zbb_zbc_zbs_zbkb_zbkc_zbkx_zknd_zkne_zknh
+// _zksed_zksh_svinval_zicbom_zicboz_zicsr_zifencei"
+// then floating-point SEW can only be 64 and 32, not 16 and 8.
+class NoZvfhSchedSEWSet_rm8and16 {
+  defvar t = SchedSEWSet.val; 
+  defvar remove8and16 = !if(isF, !listremove(t, [8, 16]), t);
+  list val = remove8and16;
+}
+
+class NoZvfhSmallestSEW {
+  int r = !head(NoZvfhSchedSEWSet_rm8and16.val);
+}
+
+multiclass NoZvfh_LMULSEWReadAdvanceImpl writes = [],
+  list MxList, bit isF = 0,
+  bit isWidening = 0> {
+  if !exists(name # "_WorstCase") then
+def : ReadAdvance(name # "_WorstCase"), val, writes>;
+  foreach mx = MxList in {
+foreach sew = NoZvfhSchedSEWSet_rm8and16.val in
+  if !exists(name # "_" # mx # "_E" # sew) then
+def : ReadAdvance(name # "_" # mx # "_E" # sew), val, 
writes>;
+  }
+}
+
+multiclass LMULSEWReadAdvanceFnoZvfh 
writes = []>
+  : NoZvfh_LMULSEWReadAdvanceImpl;
+
+multiclass LMULSEWReadAdvanceFWnoZvfh 
writes = []>
+: NoZvfh_LMULSEWReadAdvanceImpl;
+
+//===--===//
+// If Zvfhmin and Zvfh are not supported, floating-point SEW can only be 32 or 
64.
+class NoZvfhSchedSEWSet_rm32and64 {
+  defvar t = SchedSEWSet.val;
+  defvar remove32and64 = !if(isF, !listremove(t, [32, 64]), t);
+  list val = remove32and64;
+}
+
+// Write-Impl
+multiclass NoZvfhLMULSEWWriteResImpl 
resources,
+   list MxList, bit isF = 0,
+   bit isWidening = 0> {
+  foreach mx = MxList in {
+foreach sew = NoZvfhSchedSEWSet_rm32and64.val in
+  if !exists(name # "_" # mx # "_E" # sew) then
+def : WriteRes(name # "_" # mx # "_E" # sew), 
resources>;
+  }
+}
+// Read-Impl
+multiclass NoZvfhLMULSEWReadAdvanceImpl 
writes = [],
+  list MxList, bit isF = 0,
+  bit isWidening = 0> {
+  foreach mx = MxList in {
+foreach sew = NoZvfhSchedSEWSet_rm32and64.val in
+  if !exists(name # "_" # mx # "_E" # sew) then
+def : ReadAdvance(name # "_" # mx # "_E" # sew), val, 
writes>;
+  }
+}
+
+// Write
+multiclass NoZvfhLMULSEWWriteResF 
resources>
+: NoZvfhLMULSEWWriteResImpl;
+
+multiclass NoZvfhLMULSEWWriteResFW 
resources>
+: NoZvfhLMULSEWWriteResImpl;
+
+multiclass NoZvfhLMULSEWWriteResFWRed 
resources>
+: NoZvfhLMULSEWWriteResImpl;
+
+// Read
+multiclass NoZvfhLMULSEWReadAdvanceF 
writes = []>
+  : NoZvfhLMULSEWReadAdvanceImpl;
+multiclass
+NoZvfhLMULSEWReadAdvanceFW writes = 
[]>
+: NoZvfhLMULSEWReadAdvanceImpl;
+
+multiclass UnsupportedSchedZvfh {
+let Unsupported = true in {
+// Write 
+// 13. Vector Floating-Point Instructions
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFALUV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFALUF", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWALUV", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWALUF", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMulV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMulF", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFDivV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFDivF", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWMulV", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWMulF", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMulAddV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMulAddF", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWMulAddV", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWMulAddF", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFSqrtV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFRecpV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMinMaxV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMinMaxF", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"Write

[clang] [llvm] [RISCV] Add processor definition and scheduling model for XiangShan-KunMingHu (PR #90392)

2024-04-28 Thread Yingwei Zheng via cfe-commits
=?utf-8?b?6YOd5bq36L6+?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,1489 @@
+//==- RISCVSchedXiangShanKunMingHu.td - XiangShanKunMingHu Scheduling Defs -*- 
tablegen -*-=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// The XiangShan is a high-performance open-source RISC-V processor project 
+// initiated by the Institute of Computing Technology(ICT), Chinese Academy of 
Sciences(CAS). 
+// The KunMingHu architecture is its third-generation derivative, 
+// developed by the Institute of Computing Technology, Chinese Academy of 
Sciences  
+// and the Beijing Institute of Open Source Chip (BOSC), 
+// with a focus on achieving higher performance.
+// Source: https://github.com/OpenXiangShan/XiangShan
+// Documentation: https://github.com/OpenXiangShan/XiangShan-doc
+
+//===--===//
+// KunMingHu core supports 
"RV64IMAFDCV_zba_zbb_zbc_zbs_zbkb_zbkc_zbkx_zknd_zkne_zknh
+// _zksed_zksh_svinval_zicbom_zicboz_zicsr_zifencei"
+// then floating-point SEW can only be 64 and 32, not 16 and 8.
+class NoZvfhSchedSEWSet_rm8and16 {
+  defvar t = SchedSEWSet.val; 
+  defvar remove8and16 = !if(isF, !listremove(t, [8, 16]), t);
+  list val = remove8and16;
+}
+
+class NoZvfhSmallestSEW {
+  int r = !head(NoZvfhSchedSEWSet_rm8and16.val);
+}
+
+multiclass NoZvfh_LMULSEWReadAdvanceImpl writes = [],
+  list MxList, bit isF = 0,
+  bit isWidening = 0> {
+  if !exists(name # "_WorstCase") then
+def : ReadAdvance(name # "_WorstCase"), val, writes>;
+  foreach mx = MxList in {
+foreach sew = NoZvfhSchedSEWSet_rm8and16.val in
+  if !exists(name # "_" # mx # "_E" # sew) then
+def : ReadAdvance(name # "_" # mx # "_E" # sew), val, 
writes>;
+  }
+}
+
+multiclass LMULSEWReadAdvanceFnoZvfh 
writes = []>
+  : NoZvfh_LMULSEWReadAdvanceImpl;
+
+multiclass LMULSEWReadAdvanceFWnoZvfh 
writes = []>
+: NoZvfh_LMULSEWReadAdvanceImpl;
+
+//===--===//
+// If Zvfhmin and Zvfh are not supported, floating-point SEW can only be 32 or 
64.
+class NoZvfhSchedSEWSet_rm32and64 {
+  defvar t = SchedSEWSet.val;
+  defvar remove32and64 = !if(isF, !listremove(t, [32, 64]), t);
+  list val = remove32and64;
+}
+
+// Write-Impl
+multiclass NoZvfhLMULSEWWriteResImpl 
resources,
+   list MxList, bit isF = 0,
+   bit isWidening = 0> {
+  foreach mx = MxList in {
+foreach sew = NoZvfhSchedSEWSet_rm32and64.val in
+  if !exists(name # "_" # mx # "_E" # sew) then
+def : WriteRes(name # "_" # mx # "_E" # sew), 
resources>;
+  }
+}
+// Read-Impl
+multiclass NoZvfhLMULSEWReadAdvanceImpl 
writes = [],
+  list MxList, bit isF = 0,
+  bit isWidening = 0> {
+  foreach mx = MxList in {
+foreach sew = NoZvfhSchedSEWSet_rm32and64.val in
+  if !exists(name # "_" # mx # "_E" # sew) then
+def : ReadAdvance(name # "_" # mx # "_E" # sew), val, 
writes>;
+  }
+}
+
+// Write
+multiclass NoZvfhLMULSEWWriteResF 
resources>
+: NoZvfhLMULSEWWriteResImpl;
+
+multiclass NoZvfhLMULSEWWriteResFW 
resources>
+: NoZvfhLMULSEWWriteResImpl;
+
+multiclass NoZvfhLMULSEWWriteResFWRed 
resources>
+: NoZvfhLMULSEWWriteResImpl;
+
+// Read
+multiclass NoZvfhLMULSEWReadAdvanceF 
writes = []>
+  : NoZvfhLMULSEWReadAdvanceImpl;
+multiclass
+NoZvfhLMULSEWReadAdvanceFW writes = 
[]>
+: NoZvfhLMULSEWReadAdvanceImpl;
+
+multiclass UnsupportedSchedZvfh {
+let Unsupported = true in {
+// Write 
+// 13. Vector Floating-Point Instructions
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFALUV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFALUF", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWALUV", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWALUF", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMulV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMulF", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFDivV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFDivF", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWMulV", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWMulF", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMulAddV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMulAddF", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWMulAddV", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWMulAddF", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFSqrtV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFRecpV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMinMaxV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMinMaxF", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"Write

[clang] [llvm] [RISCV] Add processor definition and scheduling model for XiangShan-KunMingHu (PR #90392)

2024-04-28 Thread Yingwei Zheng via cfe-commits
=?utf-8?b?6YOd5bq36L6+?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,1489 @@
+//==- RISCVSchedXiangShanKunMingHu.td - XiangShanKunMingHu Scheduling Defs -*- 
tablegen -*-=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// The XiangShan is a high-performance open-source RISC-V processor project 
+// initiated by the Institute of Computing Technology(ICT), Chinese Academy of 
Sciences(CAS). 
+// The KunMingHu architecture is its third-generation derivative, 
+// developed by the Institute of Computing Technology, Chinese Academy of 
Sciences  
+// and the Beijing Institute of Open Source Chip (BOSC), 
+// with a focus on achieving higher performance.
+// Source: https://github.com/OpenXiangShan/XiangShan
+// Documentation: https://github.com/OpenXiangShan/XiangShan-doc
+
+//===--===//
+// KunMingHu core supports 
"RV64IMAFDCV_zba_zbb_zbc_zbs_zbkb_zbkc_zbkx_zknd_zkne_zknh
+// _zksed_zksh_svinval_zicbom_zicboz_zicsr_zifencei"
+// then floating-point SEW can only be 64 and 32, not 16 and 8.
+class NoZvfhSchedSEWSet_rm8and16 {
+  defvar t = SchedSEWSet.val; 
+  defvar remove8and16 = !if(isF, !listremove(t, [8, 16]), t);
+  list val = remove8and16;
+}
+
+class NoZvfhSmallestSEW {
+  int r = !head(NoZvfhSchedSEWSet_rm8and16.val);
+}
+
+multiclass NoZvfh_LMULSEWReadAdvanceImpl writes = [],
+  list MxList, bit isF = 0,
+  bit isWidening = 0> {
+  if !exists(name # "_WorstCase") then
+def : ReadAdvance(name # "_WorstCase"), val, writes>;
+  foreach mx = MxList in {
+foreach sew = NoZvfhSchedSEWSet_rm8and16.val in
+  if !exists(name # "_" # mx # "_E" # sew) then
+def : ReadAdvance(name # "_" # mx # "_E" # sew), val, 
writes>;
+  }
+}
+
+multiclass LMULSEWReadAdvanceFnoZvfh 
writes = []>
+  : NoZvfh_LMULSEWReadAdvanceImpl;
+
+multiclass LMULSEWReadAdvanceFWnoZvfh 
writes = []>
+: NoZvfh_LMULSEWReadAdvanceImpl;
+
+//===--===//
+// If Zvfhmin and Zvfh are not supported, floating-point SEW can only be 32 or 
64.
+class NoZvfhSchedSEWSet_rm32and64 {
+  defvar t = SchedSEWSet.val;
+  defvar remove32and64 = !if(isF, !listremove(t, [32, 64]), t);
+  list val = remove32and64;
+}
+
+// Write-Impl
+multiclass NoZvfhLMULSEWWriteResImpl 
resources,
+   list MxList, bit isF = 0,
+   bit isWidening = 0> {
+  foreach mx = MxList in {
+foreach sew = NoZvfhSchedSEWSet_rm32and64.val in
+  if !exists(name # "_" # mx # "_E" # sew) then
+def : WriteRes(name # "_" # mx # "_E" # sew), 
resources>;
+  }
+}
+// Read-Impl
+multiclass NoZvfhLMULSEWReadAdvanceImpl 
writes = [],
+  list MxList, bit isF = 0,
+  bit isWidening = 0> {
+  foreach mx = MxList in {
+foreach sew = NoZvfhSchedSEWSet_rm32and64.val in
+  if !exists(name # "_" # mx # "_E" # sew) then
+def : ReadAdvance(name # "_" # mx # "_E" # sew), val, 
writes>;
+  }
+}
+
+// Write
+multiclass NoZvfhLMULSEWWriteResF 
resources>
+: NoZvfhLMULSEWWriteResImpl;
+
+multiclass NoZvfhLMULSEWWriteResFW 
resources>
+: NoZvfhLMULSEWWriteResImpl;
+
+multiclass NoZvfhLMULSEWWriteResFWRed 
resources>
+: NoZvfhLMULSEWWriteResImpl;
+
+// Read
+multiclass NoZvfhLMULSEWReadAdvanceF 
writes = []>
+  : NoZvfhLMULSEWReadAdvanceImpl;
+multiclass
+NoZvfhLMULSEWReadAdvanceFW writes = 
[]>
+: NoZvfhLMULSEWReadAdvanceImpl;
+
+multiclass UnsupportedSchedZvfh {
+let Unsupported = true in {
+// Write 
+// 13. Vector Floating-Point Instructions
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFALUV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFALUF", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWALUV", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWALUF", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMulV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMulF", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFDivV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFDivF", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWMulV", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWMulF", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMulAddV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMulAddF", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWMulAddV", []>;
+defm "" : NoZvfhLMULSEWWriteResFW<"WriteVFWMulAddF", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFSqrtV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFRecpV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMinMaxV", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"WriteVFMinMaxF", []>;
+defm "" : NoZvfhLMULSEWWriteResF<"Write

[clang] [compiler-rt] [libc] [libclc] [libcxxabi] [lld] [lldb] [llvm] [mlir] llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:3804: lacking () for c… (PR #90391)

2024-04-28 Thread Simon Pilgrim via cfe-commits

https://github.com/RKSimon commented:

Please update the PR subject as its a lot more than just X86AsmParser.cpp

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


[clang] [compiler-rt] [libc] [libclc] [libcxxabi] [lld] [lldb] [llvm] [mlir] llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:3804: lacking () for c… (PR #90391)

2024-04-28 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 738c135ee09de66a26805530d314c2f28d1eca02 
f860432b9434c81ab55d5eded9c976edc58c3fab -- clang/lib/Basic/Targets/AMDGPU.cpp 
compiler-rt/lib/xray/xray_utils.h libc/src/__support/FPUtil/aarch64/FEnvImpl.h 
libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h 
libc/src/__support/FPUtil/arm/FEnvImpl.h 
libc/src/__support/FPUtil/riscv/FEnvImpl.h 
libc/src/__support/FPUtil/x86_64/FEnvImpl.h libclc/generic/lib/math/log_base.h 
libcxxabi/src/cxa_personality.cpp lld/ELF/LinkerScript.cpp 
lldb/tools/debugserver/source/MacOSX/MachException.cpp 
llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp 
llvm/lib/Target/AMDGPU/Disassembler/AMDGPUDisassembler.cpp 
llvm/lib/Target/AVR/AVRAsmPrinter.cpp 
llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp 
llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp 
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp 
mlir/lib/Dialect/Tosa/Transforms/TosaDecomposeTransposeConv.cpp
``





View the diff from clang-format here.


``diff
diff --git a/libcxxabi/src/cxa_personality.cpp 
b/libcxxabi/src/cxa_personality.cpp
index 8f7914a8c6..d95d781319 100644
--- a/libcxxabi/src/cxa_personality.cpp
+++ b/libcxxabi/src/cxa_personality.cpp
@@ -717,9 +717,7 @@ static void scan_eh_tab(scan_results &results, 
_Unwind_Action actions,
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = (actions & _UA_SEARCH_PHASE)
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? 
_URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
diff --git a/llvm/lib/Target/AVR/AVRAsmPrinter.cpp 
b/llvm/lib/Target/AVR/AVRAsmPrinter.cpp
index 0c7df65a42..aaec545fc1 100644
--- a/llvm/lib/Target/AVR/AVRAsmPrinter.cpp
+++ b/llvm/lib/Target/AVR/AVRAsmPrinter.cpp
@@ -134,8 +134,8 @@ bool AVRAsmPrinter::PrintAsmOperand(const MachineInstr *MI, 
unsigned OpNum,
 Reg = MI->getOperand(OpNum + RegIdx).getReg();
 
 if (BytesPerReg == 2) {
-  Reg = TRI.getSubReg(Reg,
-  (ByteNumber % BytesPerReg) ? AVR::sub_hi : 
AVR::sub_lo);
+  Reg = TRI.getSubReg(Reg, (ByteNumber % BytesPerReg) ? AVR::sub_hi
+  : AVR::sub_lo);
 }
 
 O << AVRInstPrinter::getPrettyRegisterName(Reg, MRI);

``




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


[clang] [compiler-rt] [libc] [libclc] [libcxxabi] [lld] [lldb] [llvm] [mlir] llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:3804: lacking () for c… (PR #90391)

2024-04-28 Thread Simon Pilgrim via cfe-commits

https://github.com/RKSimon commented:

Please address the clang-format warnings the CI has reported

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


[clang] bfd269d - [AMDGPU] Fix test failing on Windows for `ld.lld.exe`

2024-04-28 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2024-04-28T06:36:09-05:00
New Revision: bfd269d0d0d6cb58235a838eb659eef97e4f2ebf

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

LOG: [AMDGPU] Fix test failing on Windows for `ld.lld.exe`

Added: 


Modified: 
clang/test/Driver/amdgpu-toolchain.c

Removed: 




diff  --git a/clang/test/Driver/amdgpu-toolchain.c 
b/clang/test/Driver/amdgpu-toolchain.c
index faaff05004f6de..8ab6a071314745 100644
--- a/clang/test/Driver/amdgpu-toolchain.c
+++ b/clang/test/Driver/amdgpu-toolchain.c
@@ -27,4 +27,4 @@
 
 // RUN: %clang -### --target=amdgcn-amd-amdhsa -mcpu=gfx906 -nogpulib \
 // RUN:   -fuse-ld=ld %s 2>&1 | FileCheck -check-prefixes=LD %s
-// LD: ld.lld"
+// LD: ld.lld



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


[clang] [clang] Implement CWG2851: floating-point conversions in converted constant expressions (PR #90387)

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

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

>From a87399f8a41bb7d9a61c2d44c75836d86c6b4c38 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 28 Apr 2024 09:48:47 +0100
Subject: [PATCH] [clang] Implement CWG2851: floating-point conversions in
 converted constant expressions

---
 clang/docs/ReleaseNotes.rst   |  3 +
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/lib/Sema/SemaOverload.cpp   | 37 ++-
 clang/test/CXX/drs/dr28xx.cpp | 64 +++
 4 files changed, 105 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a1390d6536b28c..7c8d83bd73613b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -164,6 +164,9 @@ Resolutions to C++ Defect Reports
 - Clang now diagnoses declarative nested-name-specifiers with 
pack-index-specifiers.
   (`CWG2858: Declarative nested-name-specifiers and pack-index-specifiers 
`_).
 
+- Allow floating-point promotions and conversions in converted constant 
expressions.
+  (`CWG2851 Allow floating-point conversions in converted constant expressions 
`_).
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index fdca82934cb4dc..cb248f2ea6374b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -85,6 +85,10 @@ def err_expr_not_cce : Error<
   "%select{case value|enumerator value|non-type template argument|"
   "array size|explicit specifier argument|noexcept specifier argument|"
   "call to 'size()'|call to 'data()'}0 is not a constant expression">;
+def err_float_conv_cant_represent : Error<
+  "non-type template argument evaluates to %0 which cannot be "
+  "exactly represented in type %1"
+>;
 def ext_cce_narrowing : ExtWarn<
   "%select{case value|enumerator value|non-type template argument|"
   "array size|explicit specifier argument|noexcept specifier argument|"
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 04cd9e78739d20..474a8a4b5654cb 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6072,6 +6072,10 @@ static bool CheckConvertedConstantConversions(Sema &S,
   case ICK_Integral_Promotion:
   case ICK_Integral_Conversion: // Narrowing conversions are checked elsewhere.
   case ICK_Zero_Queue_Conversion:
+  // Per CWG2851, floating-point promotions and conversions are allowed.
+  // The value of a conversion is checked afterwards.
+  case ICK_Floating_Promotion:
+  case ICK_Floating_Conversion:
 return true;
 
   case ICK_Boolean_Conversion:
@@ -6091,9 +6095,7 @@ static bool CheckConvertedConstantConversions(Sema &S,
 // only permitted if the source type is std::nullptr_t.
 return SCS.getFromType()->isNullPtrType();
 
-  case ICK_Floating_Promotion:
   case ICK_Complex_Promotion:
-  case ICK_Floating_Conversion:
   case ICK_Complex_Conversion:
   case ICK_Floating_Integral:
   case ICK_Compatible_Conversion:
@@ -6229,7 +6231,36 @@ static ExprResult BuildConvertedConstantExpression(Sema 
&S, Expr *From,
   if (Result.isInvalid())
 return Result;
 
-  // Check for a narrowing implicit conversion.
+  if (SCS->Second == ICK_Floating_Conversion) {
+// Unlike with narrowing conversions, the value must fit
+// exactly even if it is in range
+assert(CCE == Sema::CCEKind::CCEK_TemplateArg &&
+   "Only non-type template args should use floating-point 
conversions");
+
+// Initializer is From, except it is a full-expression
+const Expr *Initializer =
+IgnoreNarrowingConversion(S.Context, Result.get());
+
+// If it's value-dependent, we can't tell whether it will fit
+if (Initializer->isValueDependent())
+  return Result;
+
+// Not-constant diagnosed afterwards
+if (!Initializer->isCXX11ConstantExpr(S.Context, &PreNarrowingValue))
+  return Result;
+
+llvm::APFloat PostNarrowingValue = PreNarrowingValue.getFloat();
+bool LosesInfo = true;
+PostNarrowingValue.convert(S.Context.getFloatTypeSemantics(T), 
llvm::APFloat::rmNearestTiesToEven, &LosesInfo);
+
+if (LosesInfo)
+  S.Diag(From->getBeginLoc(), diag::err_float_conv_cant_represent)
+  << PreNarrowingValue.getAsString(S.Context, From->getType()) << T;
+
+return Result;
+  }
+
+  // Check for a narrowing integer conversion.
   bool ReturnPreNarrowingValue = false;
   QualType PreNarrowingType;
   switch (SCS->getNarrowingKind(S.Context, Result.get(), PreNarrowingValue,
diff --git a/clang/test/CXX/drs/dr28xx.cpp b/clang/test/CXX/drs/dr28xx.cpp
index 4d9b0c76758d53..1626b1a9bf7b5b 100644
--- a/clang/test/CXX/drs/dr28xx.cpp
+++ b/clang/test/CXX/drs/dr28xx.cpp
@@ -3,6 +3,7 @@
 // RUN:

[clang] [clang] Implement CWG2851: floating-point conversions in converted constant expressions (PR #90387)

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

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

>From 13e2943dea677daf8976ab55a673d43982ac8a4c Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Sun, 28 Apr 2024 09:48:47 +0100
Subject: [PATCH] [clang] Implement CWG2851: floating-point conversions in
 converted constant expressions

---
 clang/docs/ReleaseNotes.rst   |  3 +
 .../clang/Basic/DiagnosticSemaKinds.td|  4 ++
 clang/lib/Sema/SemaOverload.cpp   | 38 ++-
 clang/test/CXX/drs/dr28xx.cpp | 64 +++
 4 files changed, 106 insertions(+), 3 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a1390d6536b28c..7c8d83bd73613b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -164,6 +164,9 @@ Resolutions to C++ Defect Reports
 - Clang now diagnoses declarative nested-name-specifiers with 
pack-index-specifiers.
   (`CWG2858: Declarative nested-name-specifiers and pack-index-specifiers 
`_).
 
+- Allow floating-point promotions and conversions in converted constant 
expressions.
+  (`CWG2851 Allow floating-point conversions in converted constant expressions 
`_).
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index fdca82934cb4dc..cb248f2ea6374b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -85,6 +85,10 @@ def err_expr_not_cce : Error<
   "%select{case value|enumerator value|non-type template argument|"
   "array size|explicit specifier argument|noexcept specifier argument|"
   "call to 'size()'|call to 'data()'}0 is not a constant expression">;
+def err_float_conv_cant_represent : Error<
+  "non-type template argument evaluates to %0 which cannot be "
+  "exactly represented in type %1"
+>;
 def ext_cce_narrowing : ExtWarn<
   "%select{case value|enumerator value|non-type template argument|"
   "array size|explicit specifier argument|noexcept specifier argument|"
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 04cd9e78739d20..40d65638e3afc1 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6072,6 +6072,10 @@ static bool CheckConvertedConstantConversions(Sema &S,
   case ICK_Integral_Promotion:
   case ICK_Integral_Conversion: // Narrowing conversions are checked elsewhere.
   case ICK_Zero_Queue_Conversion:
+  // Per CWG2851, floating-point promotions and conversions are allowed.
+  // The value of a conversion is checked afterwards.
+  case ICK_Floating_Promotion:
+  case ICK_Floating_Conversion:
 return true;
 
   case ICK_Boolean_Conversion:
@@ -6091,9 +6095,7 @@ static bool CheckConvertedConstantConversions(Sema &S,
 // only permitted if the source type is std::nullptr_t.
 return SCS.getFromType()->isNullPtrType();
 
-  case ICK_Floating_Promotion:
   case ICK_Complex_Promotion:
-  case ICK_Floating_Conversion:
   case ICK_Complex_Conversion:
   case ICK_Floating_Integral:
   case ICK_Compatible_Conversion:
@@ -6229,7 +6231,37 @@ static ExprResult BuildConvertedConstantExpression(Sema 
&S, Expr *From,
   if (Result.isInvalid())
 return Result;
 
-  // Check for a narrowing implicit conversion.
+  if (SCS->Second == ICK_Floating_Conversion) {
+// Unlike with narrowing conversions, the value must fit
+// exactly even if it is in range
+assert(CCE == Sema::CCEKind::CCEK_TemplateArg &&
+   "Only non-type template args should use floating-point 
conversions");
+
+// Initializer is From, except it is a full-expression
+const Expr *Initializer =
+IgnoreNarrowingConversion(S.Context, Result.get());
+
+// If it's value-dependent, we can't tell whether it will fit
+if (Initializer->isValueDependent())
+  return Result;
+
+// Not-constant diagnosed afterwards
+if (!Initializer->isCXX11ConstantExpr(S.Context, &PreNarrowingValue))
+  return Result;
+
+llvm::APFloat PostNarrowingValue = PreNarrowingValue.getFloat();
+bool LosesInfo = true;
+PostNarrowingValue.convert(S.Context.getFloatTypeSemantics(T),
+   llvm::APFloat::rmNearestTiesToEven, &LosesInfo);
+
+if (LosesInfo)
+  S.Diag(From->getBeginLoc(), diag::err_float_conv_cant_represent)
+  << PreNarrowingValue.getAsString(S.Context, From->getType()) << T;
+
+return Result;
+  }
+
+  // Check for a narrowing integer conversion.
   bool ReturnPreNarrowingValue = false;
   QualType PreNarrowingType;
   switch (SCS->getNarrowingKind(S.Context, Result.get(), PreNarrowingValue,
diff --git a/clang/test/CXX/drs/dr28xx.cpp b/clang/test/CXX/drs/dr28xx.cpp
index 4d9b0c76758d53..1626b1a9bf7b5b 100644
--- a/clang/test/CXX/drs/dr28xx.cpp
+++ b/clang/test/CXX/drs/dr28

[clang] [clang] Implement CWG2851: floating-point conversions in converted constant expressions (PR #90387)

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

MitalAshok wrote:

Waiting on #90352 because it's not on the cxx_dr_status page yet 
(`make_dr_status` doesn't do anything)

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


[clang] [compiler-rt] [libc] [libclc] [libcxxabi] [lld] [lldb] [llvm] [mlir] llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:3804: lacking () for c… (PR #90391)

2024-04-28 Thread via cfe-commits

https://github.com/luolent updated 
https://github.com/llvm/llvm-project/pull/90391

>From 2a6b6a3b160ae49b20da6c8cc9f8d858ddb598eb Mon Sep 17 00:00:00 2001
From: luolent 
Date: Sat, 27 Apr 2024 22:17:58 +0300
Subject: [PATCH] llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:3804: lacking
 () for clarity

---
 clang/lib/Basic/Targets/AMDGPU.cpp|  2 +-
 compiler-rt/lib/xray/xray_utils.h |  2 +-
 libc/src/__support/FPUtil/aarch64/FEnvImpl.h  | 20 
 .../FPUtil/aarch64/fenv_darwin_impl.h | 48 +--
 libc/src/__support/FPUtil/arm/FEnvImpl.h  | 40 
 libc/src/__support/FPUtil/riscv/FEnvImpl.h| 20 
 libc/src/__support/FPUtil/x86_64/FEnvImpl.h   | 24 +-
 libclc/generic/lib/math/log_base.h|  2 +-
 libcxxabi/src/cxa_personality.cpp |  4 +-
 lld/ELF/LinkerScript.cpp  |  2 +-
 .../source/MacOSX/MachException.cpp   |  2 +-
 .../AMDGPU/AsmParser/AMDGPUAsmParser.cpp  |  4 +-
 .../Disassembler/AMDGPUDisassembler.cpp   |  4 +-
 llvm/lib/Target/AVR/AVRAsmPrinter.cpp |  4 +-
 llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp  |  4 +-
 .../lib/Target/X86/AsmParser/X86AsmParser.cpp |  2 +-
 .../X86/MCTargetDesc/X86MCCodeEmitter.cpp |  2 +-
 .../Transforms/TosaDecomposeTransposeConv.cpp |  4 +-
 18 files changed, 94 insertions(+), 96 deletions(-)

diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index 5742885df0461b..cc7be64656e5b2 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -232,7 +232,7 @@ AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple 
&Triple,
 
   HasLegalHalfType = true;
   HasFloat16 = true;
-  WavefrontSize = GPUFeatures & llvm::AMDGPU::FEATURE_WAVE32 ? 32 : 64;
+  WavefrontSize = (GPUFeatures & llvm::AMDGPU::FEATURE_WAVE32) ? 32 : 64;
   AllowAMDGPUUnsafeFPAtomics = Opts.AllowAMDGPUUnsafeFPAtomics;
 
   // Set pointer width and alignment for the generic address space.
diff --git a/compiler-rt/lib/xray/xray_utils.h 
b/compiler-rt/lib/xray/xray_utils.h
index 333826168c0db2..5dc73d7fa8cdea 100644
--- a/compiler-rt/lib/xray/xray_utils.h
+++ b/compiler-rt/lib/xray/xray_utils.h
@@ -61,7 +61,7 @@ constexpr size_t gcd(size_t a, size_t b) {
 constexpr size_t lcm(size_t a, size_t b) { return a * b / gcd(a, b); }
 
 constexpr size_t nearest_boundary(size_t number, size_t multiple) {
-  return multiple * ((number / multiple) + (number % multiple ? 1 : 0));
+  return multiple * ((number / multiple) + ((number % multiple) ? 1 : 0));
 }
 
 constexpr size_t next_pow2_helper(size_t num, size_t acc) {
diff --git a/libc/src/__support/FPUtil/aarch64/FEnvImpl.h 
b/libc/src/__support/FPUtil/aarch64/FEnvImpl.h
index d1d92169475d15..cd8a5970edd65a 100644
--- a/libc/src/__support/FPUtil/aarch64/FEnvImpl.h
+++ b/libc/src/__support/FPUtil/aarch64/FEnvImpl.h
@@ -53,19 +53,19 @@ struct FEnv {
   static constexpr uint32_t ExceptionControlFlagsBitPosition = 8;
 
   LIBC_INLINE static uint32_t getStatusValueForExcept(int excepts) {
-return (excepts & FE_INVALID ? INVALID : 0) |
-   (excepts & FE_DIVBYZERO ? DIVBYZERO : 0) |
-   (excepts & FE_OVERFLOW ? OVERFLOW : 0) |
-   (excepts & FE_UNDERFLOW ? UNDERFLOW : 0) |
-   (excepts & FE_INEXACT ? INEXACT : 0);
+return ((excepts & FE_INVALID) ? INVALID : 0) |
+   ((excepts & FE_DIVBYZERO) ? DIVBYZERO : 0) |
+   ((excepts & FE_OVERFLOW) ? OVERFLOW : 0) |
+   ((excepts & FE_UNDERFLOW) ? UNDERFLOW : 0) |
+   ((excepts & FE_INEXACT) ? INEXACT : 0);
   }
 
   LIBC_INLINE static int exceptionStatusToMacro(uint32_t status) {
-return (status & INVALID ? FE_INVALID : 0) |
-   (status & DIVBYZERO ? FE_DIVBYZERO : 0) |
-   (status & OVERFLOW ? FE_OVERFLOW : 0) |
-   (status & UNDERFLOW ? FE_UNDERFLOW : 0) |
-   (status & INEXACT ? FE_INEXACT : 0);
+return ((status & INVALID) ? FE_INVALID : 0) |
+   ((status & DIVBYZERO) ? FE_DIVBYZERO : 0) |
+   ((status & OVERFLOW) ? FE_OVERFLOW : 0) |
+   ((status & UNDERFLOW) ? FE_UNDERFLOW : 0) |
+   ((status & INEXACT) ? FE_INEXACT : 0);
   }
 
   static uint32_t getControlWord() {
diff --git a/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h 
b/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h
index 5b59ba38d67bb6..feb48e3719bf16 100644
--- a/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h
+++ b/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h
@@ -63,39 +63,39 @@ struct FEnv {
   // located in a different place from FE_FLUSHTOZERO status bit relative to
   // the other exceptions.
   LIBC_INLINE static uint32_t exception_value_from_status(int status) {
-return (status & FE_INVALID ? EX_INVALID : 0) |
-   (status & FE_DIVBYZERO ? EX_DIVBYZERO : 0) |
-   (status & FE_OVERFLOW ? EX_OVERFLOW : 0) |
-   (status & FE_UNDERFLOW ? EX_UNDERFLOW : 0) |
-   

[clang] [compiler-rt] [libc] [libclc] [libcxxabi] [lld] [lldb] [llvm] [mlir] llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:3804: lacking () for c… (PR #90391)

2024-04-28 Thread via cfe-commits

https://github.com/luolent updated 
https://github.com/llvm/llvm-project/pull/90391

>From 54c6c6b7d71f5ff293412f5f91e9f880480284f8 Mon Sep 17 00:00:00 2001
From: luolent 
Date: Sat, 27 Apr 2024 22:17:58 +0300
Subject: [PATCH] llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:3804: lacking
 () for clarity

---
 clang/lib/Basic/Targets/AMDGPU.cpp|  2 +-
 compiler-rt/lib/xray/xray_utils.h |  2 +-
 libc/src/__support/FPUtil/aarch64/FEnvImpl.h  | 20 
 .../FPUtil/aarch64/fenv_darwin_impl.h | 48 +--
 libc/src/__support/FPUtil/arm/FEnvImpl.h  | 40 
 libc/src/__support/FPUtil/riscv/FEnvImpl.h| 20 
 libc/src/__support/FPUtil/x86_64/FEnvImpl.h   | 24 +-
 libclc/generic/lib/math/log_base.h|  2 +-
 libcxxabi/src/cxa_personality.cpp |  4 +-
 lld/ELF/LinkerScript.cpp  |  2 +-
 .../source/MacOSX/MachException.cpp   |  2 +-
 .../AMDGPU/AsmParser/AMDGPUAsmParser.cpp  |  4 +-
 .../Disassembler/AMDGPUDisassembler.cpp   |  4 +-
 llvm/lib/Target/AVR/AVRAsmPrinter.cpp |  4 +-
 llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp  |  4 +-
 .../lib/Target/X86/AsmParser/X86AsmParser.cpp |  2 +-
 .../X86/MCTargetDesc/X86MCCodeEmitter.cpp |  2 +-
 .../Transforms/TosaDecomposeTransposeConv.cpp |  4 +-
 18 files changed, 94 insertions(+), 96 deletions(-)

diff --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index 5742885df0461b..cc7be64656e5b2 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -232,7 +232,7 @@ AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple 
&Triple,
 
   HasLegalHalfType = true;
   HasFloat16 = true;
-  WavefrontSize = GPUFeatures & llvm::AMDGPU::FEATURE_WAVE32 ? 32 : 64;
+  WavefrontSize = (GPUFeatures & llvm::AMDGPU::FEATURE_WAVE32) ? 32 : 64;
   AllowAMDGPUUnsafeFPAtomics = Opts.AllowAMDGPUUnsafeFPAtomics;
 
   // Set pointer width and alignment for the generic address space.
diff --git a/compiler-rt/lib/xray/xray_utils.h 
b/compiler-rt/lib/xray/xray_utils.h
index 333826168c0db2..5dc73d7fa8cdea 100644
--- a/compiler-rt/lib/xray/xray_utils.h
+++ b/compiler-rt/lib/xray/xray_utils.h
@@ -61,7 +61,7 @@ constexpr size_t gcd(size_t a, size_t b) {
 constexpr size_t lcm(size_t a, size_t b) { return a * b / gcd(a, b); }
 
 constexpr size_t nearest_boundary(size_t number, size_t multiple) {
-  return multiple * ((number / multiple) + (number % multiple ? 1 : 0));
+  return multiple * ((number / multiple) + ((number % multiple) ? 1 : 0));
 }
 
 constexpr size_t next_pow2_helper(size_t num, size_t acc) {
diff --git a/libc/src/__support/FPUtil/aarch64/FEnvImpl.h 
b/libc/src/__support/FPUtil/aarch64/FEnvImpl.h
index d1d92169475d15..cd8a5970edd65a 100644
--- a/libc/src/__support/FPUtil/aarch64/FEnvImpl.h
+++ b/libc/src/__support/FPUtil/aarch64/FEnvImpl.h
@@ -53,19 +53,19 @@ struct FEnv {
   static constexpr uint32_t ExceptionControlFlagsBitPosition = 8;
 
   LIBC_INLINE static uint32_t getStatusValueForExcept(int excepts) {
-return (excepts & FE_INVALID ? INVALID : 0) |
-   (excepts & FE_DIVBYZERO ? DIVBYZERO : 0) |
-   (excepts & FE_OVERFLOW ? OVERFLOW : 0) |
-   (excepts & FE_UNDERFLOW ? UNDERFLOW : 0) |
-   (excepts & FE_INEXACT ? INEXACT : 0);
+return ((excepts & FE_INVALID) ? INVALID : 0) |
+   ((excepts & FE_DIVBYZERO) ? DIVBYZERO : 0) |
+   ((excepts & FE_OVERFLOW) ? OVERFLOW : 0) |
+   ((excepts & FE_UNDERFLOW) ? UNDERFLOW : 0) |
+   ((excepts & FE_INEXACT) ? INEXACT : 0);
   }
 
   LIBC_INLINE static int exceptionStatusToMacro(uint32_t status) {
-return (status & INVALID ? FE_INVALID : 0) |
-   (status & DIVBYZERO ? FE_DIVBYZERO : 0) |
-   (status & OVERFLOW ? FE_OVERFLOW : 0) |
-   (status & UNDERFLOW ? FE_UNDERFLOW : 0) |
-   (status & INEXACT ? FE_INEXACT : 0);
+return ((status & INVALID) ? FE_INVALID : 0) |
+   ((status & DIVBYZERO) ? FE_DIVBYZERO : 0) |
+   ((status & OVERFLOW) ? FE_OVERFLOW : 0) |
+   ((status & UNDERFLOW) ? FE_UNDERFLOW : 0) |
+   ((status & INEXACT) ? FE_INEXACT : 0);
   }
 
   static uint32_t getControlWord() {
diff --git a/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h 
b/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h
index 5b59ba38d67bb6..feb48e3719bf16 100644
--- a/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h
+++ b/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h
@@ -63,39 +63,39 @@ struct FEnv {
   // located in a different place from FE_FLUSHTOZERO status bit relative to
   // the other exceptions.
   LIBC_INLINE static uint32_t exception_value_from_status(int status) {
-return (status & FE_INVALID ? EX_INVALID : 0) |
-   (status & FE_DIVBYZERO ? EX_DIVBYZERO : 0) |
-   (status & FE_OVERFLOW ? EX_OVERFLOW : 0) |
-   (status & FE_UNDERFLOW ? EX_UNDERFLOW : 0) |
-   

[clang] [Clang] Fix incorrect handling of #pragma {GCC} unroll N in dependent context (PR #90240)

2024-04-28 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/90240

>From 131783211a23d007b5b6f1d5691306df4dec716b Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Sat, 27 Apr 2024 01:38:34 +0800
Subject: [PATCH 1/5] [Clang] Fix incorrect handling of #pragma {GCC} unroll N
 in dependent context

Signed-off-by: yronglin 
---
 clang/lib/Sema/SemaStmtAttr.cpp | 23 ++
 clang/test/Parser/pragma-unroll.cpp | 37 +
 2 files changed, 50 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index 9d44c22c8ddcc3..4dfdfd7aec425f 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -109,16 +109,19 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const 
ParsedAttr &A,
 SetHints(LoopHintAttr::Unroll, LoopHintAttr::Disable);
   } else if (PragmaName == "unroll") {
 // #pragma unroll N
-if (ValueExpr && !ValueExpr->isValueDependent()) {
-  llvm::APSInt ValueAPS;
-  ExprResult R = S.VerifyIntegerConstantExpression(ValueExpr, &ValueAPS);
-  assert(!R.isInvalid() && "unroll count value must be a valid value, it's 
"
-   "should be checked in Sema::CheckLoopHintExpr");
-  (void)R;
-  // The values of 0 and 1 block any unrolling of the loop.
-  if (ValueAPS.isZero() || ValueAPS.isOne())
-SetHints(LoopHintAttr::UnrollCount, LoopHintAttr::Disable);
-  else
+if (ValueExpr) {
+  if (!ValueExpr->isValueDependent()) {
+llvm::APSInt ValueAPS;
+ExprResult R = S.VerifyIntegerConstantExpression(ValueExpr, &ValueAPS);
+assert(!R.isInvalid() && "unroll count value must be a valid value, 
it's "
+"should be checked in 
Sema::CheckLoopHintExpr");
+(void)R;
+// The values of 0 and 1 block any unrolling of the loop.
+if (ValueAPS.isZero() || ValueAPS.isOne())
+  SetHints(LoopHintAttr::UnrollCount, LoopHintAttr::Disable);
+else
+  SetHints(LoopHintAttr::UnrollCount, LoopHintAttr::Numeric);
+  } else
 SetHints(LoopHintAttr::UnrollCount, LoopHintAttr::Numeric);
 } else
   SetHints(LoopHintAttr::Unroll, LoopHintAttr::Enable);
diff --git a/clang/test/Parser/pragma-unroll.cpp 
b/clang/test/Parser/pragma-unroll.cpp
index f41bd7a18d5a41..e84f6ea9ad1035 100644
--- a/clang/test/Parser/pragma-unroll.cpp
+++ b/clang/test/Parser/pragma-unroll.cpp
@@ -124,3 +124,40 @@ void test(int *List, int Length) {
 
 #pragma unroll
 /* expected-error {{expected statement}} */ }
+
+using size_t = unsigned long long;
+
+template 
+int FailToBuild(int n) {
+  constexpr int N = 100;
+  auto init = [=]() { return Flag ? n : 0UL; };
+  auto cond = [=](size_t ix) { return Flag ? ix != 0 : ix < 10; };
+  auto iter = [=](size_t ix) {
+return Flag ? ix & ~(1ULL << __builtin_clzll(ix)) : ix + 1;
+  };
+#pragma unroll Flag ? 1 : N
+  for (size_t ix = init(); cond(ix); ix = iter(ix)) {
+n *= n;
+  }
+#pragma unroll Flag ? 0 : N
+  for (size_t ix = init(); cond(ix); ix = iter(ix)) {
+n *= n;
+  }
+#pragma GCC unroll Flag ? 1 : N
+  for (size_t ix = init(); cond(ix); ix = iter(ix)) {
+n *= n;
+  }
+#pragma GCC unroll Flag ? 0 : N
+  for (size_t ix = init(); cond(ix); ix = iter(ix)) {
+n *= n;
+  }
+  return n;
+}
+
+int foo(int n) {
+return FailToBuild(n);
+}
+
+int bar(int n) {
+return FailToBuild(n);
+}

>From 3e5ef859c3d55830199a366edf48a8f536dc1208 Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Sat, 27 Apr 2024 01:52:41 +0800
Subject: [PATCH 2/5] Format

Signed-off-by: yronglin 
---
 clang/lib/Sema/SemaStmtAttr.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp
index 4dfdfd7aec425f..d3e76f282974e9 100644
--- a/clang/lib/Sema/SemaStmtAttr.cpp
+++ b/clang/lib/Sema/SemaStmtAttr.cpp
@@ -113,8 +113,9 @@ static Attr *handleLoopHintAttr(Sema &S, Stmt *St, const 
ParsedAttr &A,
   if (!ValueExpr->isValueDependent()) {
 llvm::APSInt ValueAPS;
 ExprResult R = S.VerifyIntegerConstantExpression(ValueExpr, &ValueAPS);
-assert(!R.isInvalid() && "unroll count value must be a valid value, 
it's "
-"should be checked in 
Sema::CheckLoopHintExpr");
+assert(!R.isInvalid() &&
+   "unroll count value must be a valid value, it's "
+   "should be checked in Sema::CheckLoopHintExpr");
 (void)R;
 // The values of 0 and 1 block any unrolling of the loop.
 if (ValueAPS.isZero() || ValueAPS.isOne())

>From 35b63c6df6409a4e9dde07d8c658583614964856 Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Sat, 27 Apr 2024 23:20:55 +0800
Subject: [PATCH 3/5] Address comments and add more test

Signed-off-by: yronglin 
---
 clang/lib/CodeGen/CGLoopInfo.cpp|  2 -
 clang/lib/Sema/SemaStmtAttr.cpp | 19 ++

[clang] [Clang] Implement C++26 P2748R5 "Disallow Binding a Returned Glvalue to a Temporary" (PR #89942)

2024-04-28 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/89942

>From 8c5f1d0f92d77bffec88759c19133a0bac130f32 Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Wed, 24 Apr 2024 23:36:10 +0800
Subject: [PATCH 1/7] [Clang] Implement P2748R5 "Disallow Binding a Returned
 Glvalue to a Temporary"

Signed-off-by: yronglin 
---
 clang/docs/ReleaseNotes.rst|  4 +++-
 .../include/clang/Basic/DiagnosticSemaKinds.td |  2 ++
 clang/lib/Sema/SemaInit.cpp| 13 +++--
 clang/test/CXX/drs/cwg650.cpp  |  2 +-
 clang/test/CXX/stmt.stmt/stmt.return/p6.cpp| 18 ++
 5 files changed, 35 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/CXX/stmt.stmt/stmt.return/p6.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 64526ed6d06f55..5e07000198d63a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -129,7 +129,9 @@ C++2c Feature Support
 
 - Implemented `P2662R3 Pack Indexing `_.
 
-- Implemented `P2573R2: = delete("should have a reason"); 
`_
+- Implemented `P2573R2: = delete("should have a reason"); 
`_.
+
+- Implemented `P2748R5 Disallow Binding a Returned Glvalue to a Temporary 
`_.
 
 
 Resolutions to C++ Defect Reports
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6732a1a98452ad..7342215db9cc3d 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9950,6 +9950,8 @@ def warn_ret_stack_addr_ref : Warning<
 def warn_ret_local_temp_addr_ref : Warning<
   "returning %select{address of|reference to}0 local temporary object">,
   InGroup;
+def err_ret_local_temp_addr_ref : Error<
+  "returning %select{address of|reference to}0 local temporary object">;
 def warn_ret_addr_label : Warning<
   "returning address of label, which is local">,
   InGroup;
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 793e16df178914..003c4c34810e1f 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -8340,8 +8340,17 @@ void Sema::checkInitializerLifetime(const 
InitializedEntity &Entity,
 << Entity.getType()->isReferenceType() << CLE->getInitializer() << 
2
 << DiagRange;
   } else {
-Diag(DiagLoc, diag::warn_ret_local_temp_addr_ref)
- << Entity.getType()->isReferenceType() << DiagRange;
+// P2748R5: Disallow Binding a Returned Glvalue to a Temporary.
+// [stmt.return]/p6: In a function whose return type is a reference,
+// other than an invented function for std::is_convertible 
([meta.rel]),
+// a return statement that binds the returned reference to a temporary
+// expression ([class.temporary]) is ill-formed.
+if (getLangOpts().CPlusPlus26)
+  Diag(DiagLoc, diag::err_ret_local_temp_addr_ref)
+  << Entity.getType()->isReferenceType() << DiagRange;
+else
+  Diag(DiagLoc, diag::warn_ret_local_temp_addr_ref)
+  << Entity.getType()->isReferenceType() << DiagRange;
   }
   break;
 }
diff --git a/clang/test/CXX/drs/cwg650.cpp b/clang/test/CXX/drs/cwg650.cpp
index dcb844095b0598..01a841b04b42d3 100644
--- a/clang/test/CXX/drs/cwg650.cpp
+++ b/clang/test/CXX/drs/cwg650.cpp
@@ -4,7 +4,7 @@
 // RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
 // RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
 // RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
-// RUN: %clang_cc1 -std=c++2c %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK
+// Since C++26, P2748R5 "Disallow Binding a Returned Glvalue to a Temporary". 
Therefore we do not test this issue after C++26.
 
 #if __cplusplus == 199711L
 #define NOTHROW throw()
diff --git a/clang/test/CXX/stmt.stmt/stmt.return/p6.cpp 
b/clang/test/CXX/stmt.stmt/stmt.return/p6.cpp
new file mode 100644
index 00..682d3a8a075d4e
--- /dev/null
+++ b/clang/test/CXX/stmt.stmt/stmt.return/p6.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -std=c++26 -fsyntax-only -verify %s
+
+auto&& f1() {
+  return 42; // expected-error{{returning reference to local temporary object}}
+}
+const double& f2() {
+  static int x = 42;
+  return x; // expected-error{{returning reference to local temporary object}}
+}
+auto&& id(auto&& r) {
+  return static_cast(r);
+}
+a

[clang-tools-extra] [clang-tidy] Add modernize-use-std-format check (PR #90397)

2024-04-28 Thread Mike Crowe via cfe-commits

https://github.com/mikecrowe created 
https://github.com/llvm/llvm-project/pull/90397

Add a new clang-tidy check that converts absl::StrFormat (and similar 
functions) to std::format (and similar functions.)

Split the configuration of FormatStringConverter out to a separate 
Configuration class so that we don't risk confusion by passing two boolean 
configuration parameters into the constructor. Add AllowTrailingNewlineRemoval 
option since we never want to remove trailing newlines in this check.


>From 0d6ede5d59cc70d803bfe2c7997737c1be358c75 Mon Sep 17 00:00:00 2001
From: Mike Crowe 
Date: Sun, 28 Apr 2024 12:41:46 +0100
Subject: [PATCH] [clang-tidy] Add modernize-use-std-format check

Add a new clang-tidy check that converts absl::StrFormat (and similar
functions) to std::format (and similar functions.)

Split the configuration of FormatStringConverter out to a separate
Configuration class so that we don't risk confusion by passing two
boolean configuration parameters into the constructor. Add
AllowTrailingNewlineRemoval option since we never want to remove
trailing newlines in this check.

Differential Revision: https://reviews.llvm.org/D154287
---
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../modernize/ModernizeTidyModule.cpp |   2 +
 .../modernize/UseStdFormatCheck.cpp   | 108 ++
 .../clang-tidy/modernize/UseStdFormatCheck.h  |  50 
 .../clang-tidy/modernize/UseStdPrintCheck.cpp |   5 +-
 .../utils/FormatStringConverter.cpp   |  10 +-
 .../clang-tidy/utils/FormatStringConverter.h  |   9 +-
 clang-tools-extra/docs/ReleaseNotes.rst   |   9 ++
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../checks/modernize/use-std-format.rst   |  84 ++
 .../modernize/use-std-format-custom.cpp   |  76 
 .../checkers/modernize/use-std-format-fmt.cpp |  37 ++
 .../checkers/modernize/use-std-format.cpp |  97 
 13 files changed, 483 insertions(+), 6 deletions(-)
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-fmt.cpp
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 8005d6e91c060c..576805c4c7f181 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -41,6 +41,7 @@ add_clang_library(clangTidyModernizeModule
   UseNullptrCheck.cpp
   UseOverrideCheck.cpp
   UseStartsEndsWithCheck.cpp
+  UseStdFormatCheck.cpp
   UseStdNumbersCheck.cpp
   UseStdPrintCheck.cpp
   UseTrailingReturnTypeCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 776558433c5baa..b9c7a2dc383e88 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -42,6 +42,7 @@
 #include "UseNullptrCheck.h"
 #include "UseOverrideCheck.h"
 #include "UseStartsEndsWithCheck.h"
+#include "UseStdFormatCheck.h"
 #include "UseStdNumbersCheck.h"
 #include "UseStdPrintCheck.h"
 #include "UseTrailingReturnTypeCheck.h"
@@ -76,6 +77,7 @@ class ModernizeModule : public ClangTidyModule {
 "modernize-use-designated-initializers");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");
+
CheckFactories.registerCheck("modernize-use-std-format");
 CheckFactories.registerCheck(
 "modernize-use-std-numbers");
 CheckFactories.registerCheck("modernize-use-std-print");
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
new file mode 100644
index 00..d22ebe857cf415
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
@@ -0,0 +1,108 @@
+//===--- UseStdFormatCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseStdFormatCheck.h"
+#include "../utils/FormatStringConverter.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/FixIt.h"
+

[clang-tools-extra] [clang-tidy] Add modernize-use-std-format check (PR #90397)

2024-04-28 Thread Mike Crowe via cfe-commits

mikecrowe wrote:

This check was originally proposed and reviewed at 
https://reviews.llvm.org/D154287 last year but never landed since I did not 
(and still do not) have commit access. Near the end of that review, @PiotrZSL 
wrote:
> To be honest, I do not see to much use case for this check. But that's fine.

which may mean that it should not land. I've created this pull request for 
discoverability by those looking for such a check since Phabricator is no 
longer used.


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


[clang-tools-extra] [clang-tidy] Add modernize-use-std-format check (PR #90397)

2024-04-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Mike Crowe (mikecrowe)


Changes

Add a new clang-tidy check that converts absl::StrFormat (and similar 
functions) to std::format (and similar functions.)

Split the configuration of FormatStringConverter out to a separate 
Configuration class so that we don't risk confusion by passing two boolean 
configuration parameters into the constructor. Add AllowTrailingNewlineRemoval 
option since we never want to remove trailing newlines in this check.


---

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


13 Files Affected:

- (modified) clang-tools-extra/clang-tidy/modernize/CMakeLists.txt (+1) 
- (modified) clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
(+2) 
- (added) clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp (+108) 
- (added) clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h (+50) 
- (modified) clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp (+4-1) 
- (modified) clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp 
(+6-4) 
- (modified) clang-tools-extra/clang-tidy/utils/FormatStringConverter.h (+8-1) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+9) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+1) 
- (added) clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst 
(+84) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp 
(+76) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-fmt.cpp 
(+37) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp (+97) 


``diff
diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 8005d6e91c060c..576805c4c7f181 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -41,6 +41,7 @@ add_clang_library(clangTidyModernizeModule
   UseNullptrCheck.cpp
   UseOverrideCheck.cpp
   UseStartsEndsWithCheck.cpp
+  UseStdFormatCheck.cpp
   UseStdNumbersCheck.cpp
   UseStdPrintCheck.cpp
   UseTrailingReturnTypeCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 776558433c5baa..b9c7a2dc383e88 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -42,6 +42,7 @@
 #include "UseNullptrCheck.h"
 #include "UseOverrideCheck.h"
 #include "UseStartsEndsWithCheck.h"
+#include "UseStdFormatCheck.h"
 #include "UseStdNumbersCheck.h"
 #include "UseStdPrintCheck.h"
 #include "UseTrailingReturnTypeCheck.h"
@@ -76,6 +77,7 @@ class ModernizeModule : public ClangTidyModule {
 "modernize-use-designated-initializers");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");
+
CheckFactories.registerCheck("modernize-use-std-format");
 CheckFactories.registerCheck(
 "modernize-use-std-numbers");
 CheckFactories.registerCheck("modernize-use-std-print");
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
new file mode 100644
index 00..d22ebe857cf415
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
@@ -0,0 +1,108 @@
+//===--- UseStdFormatCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseStdFormatCheck.h"
+#include "../utils/FormatStringConverter.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/FixIt.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+namespace {
+AST_MATCHER(StringLiteral, isOrdinary) { return Node.isOrdinary(); }
+} // namespace
+
+UseStdFormatCheck::UseStdFormatCheck(StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StrictMode(Options.getLocalOrGlobal("StrictMode", false)),
+  StrFormatLikeFunctions(utils::options::parseStringList(
+  Options.get("StrFormatLikeFunctions", ""))),
+  ReplacementFormatFunction(
+  Options.get("ReplacementFormatFunction", "std::format")),
+  IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
+   utils::IncludeSorter::IS_LLVM),
+  areDiagsSelfContained()),
+  MaybeHeaderToInclude(Options.get("FormatH

[clang-tools-extra] [clang-tidy] Add modernize-use-std-format check (PR #90397)

2024-04-28 Thread via cfe-commits

llvmbot wrote:




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

Author: Mike Crowe (mikecrowe)


Changes

Add a new clang-tidy check that converts absl::StrFormat (and similar 
functions) to std::format (and similar functions.)

Split the configuration of FormatStringConverter out to a separate 
Configuration class so that we don't risk confusion by passing two boolean 
configuration parameters into the constructor. Add AllowTrailingNewlineRemoval 
option since we never want to remove trailing newlines in this check.


---

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


13 Files Affected:

- (modified) clang-tools-extra/clang-tidy/modernize/CMakeLists.txt (+1) 
- (modified) clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
(+2) 
- (added) clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp (+108) 
- (added) clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h (+50) 
- (modified) clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp (+4-1) 
- (modified) clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp 
(+6-4) 
- (modified) clang-tools-extra/clang-tidy/utils/FormatStringConverter.h (+8-1) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+9) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+1) 
- (added) clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst 
(+84) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp 
(+76) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-fmt.cpp 
(+37) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp (+97) 


``diff
diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 8005d6e91c060c..576805c4c7f181 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -41,6 +41,7 @@ add_clang_library(clangTidyModernizeModule
   UseNullptrCheck.cpp
   UseOverrideCheck.cpp
   UseStartsEndsWithCheck.cpp
+  UseStdFormatCheck.cpp
   UseStdNumbersCheck.cpp
   UseStdPrintCheck.cpp
   UseTrailingReturnTypeCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 776558433c5baa..b9c7a2dc383e88 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -42,6 +42,7 @@
 #include "UseNullptrCheck.h"
 #include "UseOverrideCheck.h"
 #include "UseStartsEndsWithCheck.h"
+#include "UseStdFormatCheck.h"
 #include "UseStdNumbersCheck.h"
 #include "UseStdPrintCheck.h"
 #include "UseTrailingReturnTypeCheck.h"
@@ -76,6 +77,7 @@ class ModernizeModule : public ClangTidyModule {
 "modernize-use-designated-initializers");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");
+
CheckFactories.registerCheck("modernize-use-std-format");
 CheckFactories.registerCheck(
 "modernize-use-std-numbers");
 CheckFactories.registerCheck("modernize-use-std-print");
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
new file mode 100644
index 00..d22ebe857cf415
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
@@ -0,0 +1,108 @@
+//===--- UseStdFormatCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseStdFormatCheck.h"
+#include "../utils/FormatStringConverter.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/FixIt.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+namespace {
+AST_MATCHER(StringLiteral, isOrdinary) { return Node.isOrdinary(); }
+} // namespace
+
+UseStdFormatCheck::UseStdFormatCheck(StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StrictMode(Options.getLocalOrGlobal("StrictMode", false)),
+  StrFormatLikeFunctions(utils::options::parseStringList(
+  Options.get("StrFormatLikeFunctions", ""))),
+  ReplacementFormatFunction(
+  Options.get("ReplacementFormatFunction", "std::format")),
+  IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
+   utils::IncludeSorter::IS_LLVM),
+  areDiagsSelfContained()),
+  MaybeHeaderToInclude(Options.get("

[clang-tools-extra] [clang-tidy] Add modernize-use-std-format check (PR #90397)

2024-04-28 Thread via cfe-commits


@@ -0,0 +1,50 @@
+//===--- UseStdFormatCheck.h - clang-tidy ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDFORMATCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDFORMATCHECK_H
+
+#include "../ClangTidyCheck.h"

EugeneZelenko wrote:

Included twice.

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


[clang] [compiler-rt] [libc] [libclc] [libcxxabi] [lld] [lldb] [llvm] [mlir] llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:3804: lacking () for c… (PR #90391)

2024-04-28 Thread via cfe-commits

luolent wrote:

> Please update the PR subject as its a lot more than just X86AsmParser.cpp

Hi @RKSimon 

All the issues mentioned are fixed. The tile of the PR is misleading. 
The title is the same as the issue (#85868) it corresponds to.
Got a look to other PR's and I thought that this is the usual naming convention.
Please refer to the 
[commit](https://github.com/llvm/llvm-project/pull/90391/commits/54c6c6b7d71f5ff293412f5f91e9f880480284f8)
 and you will see all the modified files.

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


[clang-tools-extra] [clang-tidy] Add modernize-use-std-format check (PR #90397)

2024-04-28 Thread Mike Crowe via cfe-commits

https://github.com/mikecrowe updated 
https://github.com/llvm/llvm-project/pull/90397

>From 0d6ede5d59cc70d803bfe2c7997737c1be358c75 Mon Sep 17 00:00:00 2001
From: Mike Crowe 
Date: Sun, 28 Apr 2024 12:41:46 +0100
Subject: [PATCH 1/2] [clang-tidy] Add modernize-use-std-format check

Add a new clang-tidy check that converts absl::StrFormat (and similar
functions) to std::format (and similar functions.)

Split the configuration of FormatStringConverter out to a separate
Configuration class so that we don't risk confusion by passing two
boolean configuration parameters into the constructor. Add
AllowTrailingNewlineRemoval option since we never want to remove
trailing newlines in this check.

Differential Revision: https://reviews.llvm.org/D154287
---
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../modernize/ModernizeTidyModule.cpp |   2 +
 .../modernize/UseStdFormatCheck.cpp   | 108 ++
 .../clang-tidy/modernize/UseStdFormatCheck.h  |  50 
 .../clang-tidy/modernize/UseStdPrintCheck.cpp |   5 +-
 .../utils/FormatStringConverter.cpp   |  10 +-
 .../clang-tidy/utils/FormatStringConverter.h  |   9 +-
 clang-tools-extra/docs/ReleaseNotes.rst   |   9 ++
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../checks/modernize/use-std-format.rst   |  84 ++
 .../modernize/use-std-format-custom.cpp   |  76 
 .../checkers/modernize/use-std-format-fmt.cpp |  37 ++
 .../checkers/modernize/use-std-format.cpp |  97 
 13 files changed, 483 insertions(+), 6 deletions(-)
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-fmt.cpp
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 8005d6e91c060c..576805c4c7f181 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -41,6 +41,7 @@ add_clang_library(clangTidyModernizeModule
   UseNullptrCheck.cpp
   UseOverrideCheck.cpp
   UseStartsEndsWithCheck.cpp
+  UseStdFormatCheck.cpp
   UseStdNumbersCheck.cpp
   UseStdPrintCheck.cpp
   UseTrailingReturnTypeCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 776558433c5baa..b9c7a2dc383e88 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -42,6 +42,7 @@
 #include "UseNullptrCheck.h"
 #include "UseOverrideCheck.h"
 #include "UseStartsEndsWithCheck.h"
+#include "UseStdFormatCheck.h"
 #include "UseStdNumbersCheck.h"
 #include "UseStdPrintCheck.h"
 #include "UseTrailingReturnTypeCheck.h"
@@ -76,6 +77,7 @@ class ModernizeModule : public ClangTidyModule {
 "modernize-use-designated-initializers");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");
+
CheckFactories.registerCheck("modernize-use-std-format");
 CheckFactories.registerCheck(
 "modernize-use-std-numbers");
 CheckFactories.registerCheck("modernize-use-std-print");
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
new file mode 100644
index 00..d22ebe857cf415
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
@@ -0,0 +1,108 @@
+//===--- UseStdFormatCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseStdFormatCheck.h"
+#include "../utils/FormatStringConverter.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/FixIt.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+namespace {
+AST_MATCHER(StringLiteral, isOrdinary) { return Node.isOrdinary(); }
+} // namespace
+
+UseStdFormatCheck::UseStdFormatCheck(StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StrictMode(Options.getLocalOrGlobal("StrictMode", false)),
+  StrFormatLikeFunctions(utils::options::parse

[clang] [compiler-rt] [libc] [libclc] [libcxxabi] [lld] [lldb] [llvm] [mlir] llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp:3804: lacking () for c… (PR #90391)

2024-04-28 Thread Mehdi Amini via cfe-commits

joker-eph wrote:

PR should be named according to what they are actually achieving, I'm not sure 
why the GitHub issue title is relevant?

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


[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-04-28 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx updated 
https://github.com/llvm/llvm-project/pull/89796

>From 662f160418c704f45e57e751168903d774b74303 Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Tue, 23 Apr 2024 17:41:25 +0100
Subject: [PATCH 1/4] Add initial support for AMDGCN flavoured SPIRV.

---
 clang/lib/Basic/Targets.cpp   |   6 +-
 clang/lib/Basic/Targets/SPIR.cpp  | 288 +
 clang/lib/Basic/Targets/SPIR.h|  51 +++
 clang/lib/CodeGen/CGBuiltin.cpp   |   7 +
 clang/test/CodeGen/target-data.c  |   4 +
 .../test/CodeGenCUDA/builtins-spirv-amdgcn.cu | 294 ++
 ...tins-unsafe-atomics-spirv-amdgcn-gfx90a.cu |  31 ++
 clang/test/CodeGenCUDA/long-double.cu |   4 +
 clang/test/CodeGenCUDA/spirv-amdgcn-bf16.cu   | 129 
 .../test/CodeGenCXX/spirv-amdgcn-float16.cpp  |  38 +++
 clang/test/CodeGenHIP/spirv-amdgcn-ballot.cpp |  27 ++
 .../spirv-amdgcn-dpp-const-fold.hip   |  46 +++
 clang/test/CodeGenHIP/spirv-amdgcn-half.hip   |  15 +
 .../predefined-macros-no-warnings.c   |   1 +
 clang/test/Preprocessor/predefined-macros.c   |  10 +
 ...in-spirv-amdgcn-atomic-inc-dec-failure.cpp |  25 ++
 .../Sema/inline-asm-validate-spirv-amdgcn.cl  | 111 +++
 clang/test/SemaCUDA/allow-int128.cu   |   3 +
 clang/test/SemaCUDA/amdgpu-f128.cu|   1 +
 clang/test/SemaCUDA/float16.cu|   1 +
 clang/test/SemaCUDA/fp16-arg-return.cu|   1 +
 .../test/SemaCUDA/spirv-amdgcn-atomic-ops.cu  |  86 +
 22 files changed, 1178 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenCUDA/builtins-spirv-amdgcn.cu
 create mode 100644 
clang/test/CodeGenCUDA/builtins-unsafe-atomics-spirv-amdgcn-gfx90a.cu
 create mode 100644 clang/test/CodeGenCUDA/spirv-amdgcn-bf16.cu
 create mode 100644 clang/test/CodeGenCXX/spirv-amdgcn-float16.cpp
 create mode 100644 clang/test/CodeGenHIP/spirv-amdgcn-ballot.cpp
 create mode 100644 clang/test/CodeGenHIP/spirv-amdgcn-dpp-const-fold.hip
 create mode 100644 clang/test/CodeGenHIP/spirv-amdgcn-half.hip
 create mode 100644 
clang/test/Sema/builtin-spirv-amdgcn-atomic-inc-dec-failure.cpp
 create mode 100644 clang/test/Sema/inline-asm-validate-spirv-amdgcn.cl
 create mode 100644 clang/test/SemaCUDA/spirv-amdgcn-atomic-ops.cu

diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index e3283510c6aac7..04a13e3385d1f6 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -673,8 +673,12 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple &Triple,
   }
   case llvm::Triple::spirv64: {
 if (os != llvm::Triple::UnknownOS ||
-Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
+Triple.getEnvironment() != llvm::Triple::UnknownEnvironment) {
+  if (os == llvm::Triple::OSType::AMDHSA)
+return std::make_unique(Triple, Opts);
+
   return nullptr;
+}
 return std::make_unique(Triple, Opts);
   }
   case llvm::Triple::wasm32:
diff --git a/clang/lib/Basic/Targets/SPIR.cpp b/clang/lib/Basic/Targets/SPIR.cpp
index dc920177d3a910..d7d232ac9484f8 100644
--- a/clang/lib/Basic/Targets/SPIR.cpp
+++ b/clang/lib/Basic/Targets/SPIR.cpp
@@ -12,6 +12,8 @@
 
 #include "SPIR.h"
 #include "Targets.h"
+#include "clang/Basic/Builtins.h"
+#include "clang/Basic/TargetBuiltins.h"
 
 using namespace clang;
 using namespace clang::targets;
@@ -54,3 +56,289 @@ void SPIRV64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   BaseSPIRVTargetInfo::getTargetDefines(Opts, Builder);
   DefineStd(Builder, "SPIRV64", Opts);
 }
+
+static constexpr Builtin::Info BuiltinInfo[] = {
+#define BUILTIN(ID, TYPE, ATTRS)   
\
+  {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
+#define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE)   
\
+  {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
+#include "clang/Basic/BuiltinsAMDGPU.def"
+};
+
+namespace {
+const char *AMDGPUGCCRegNames[] = {
+  "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8",
+  "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17",
+  "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26",
+  "v27", "v28", "v29", "v30", "v31", "v32", "v33", "v34", "v35",
+  "v36", "v37", "v38", "v39", "v40", "v41", "v42", "v43", "v44",
+  "v45", "v46", "v47", "v48", "v49", "v50", "v51", "v52", "v53",
+  "v54", "v55", "v56", "v57", "v58", "v59", "v60", "v61", "v62",
+  "v63", "v64", "v65", "v66", "v67", "v68", "v69", "v70", "v71",
+  "v72", "v73", "v74", "v75", "v76", "v77", "v78", "v79", "v80",
+  "v81", "v82", "v83", "v84", "v85", "v86", "v87", "v88", "v89",
+  "v90", "v91", "v92", "v93", "v94", "v95", "v96", "v97", "v98",
+  "v99", "v100", "v101", "v102", "v103", "v104", "v105", "v106", "v107",
+  "v108", "v109", "v110", "v111", "v112", "v113", "v114", "v115", "v116",
+  "v117", "v118", "v119", "v120", "v121", "v122", "v123", "v124", "v

[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-04-28 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx updated 
https://github.com/llvm/llvm-project/pull/89796

>From 662f160418c704f45e57e751168903d774b74303 Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Tue, 23 Apr 2024 17:41:25 +0100
Subject: [PATCH 1/5] Add initial support for AMDGCN flavoured SPIRV.

---
 clang/lib/Basic/Targets.cpp   |   6 +-
 clang/lib/Basic/Targets/SPIR.cpp  | 288 +
 clang/lib/Basic/Targets/SPIR.h|  51 +++
 clang/lib/CodeGen/CGBuiltin.cpp   |   7 +
 clang/test/CodeGen/target-data.c  |   4 +
 .../test/CodeGenCUDA/builtins-spirv-amdgcn.cu | 294 ++
 ...tins-unsafe-atomics-spirv-amdgcn-gfx90a.cu |  31 ++
 clang/test/CodeGenCUDA/long-double.cu |   4 +
 clang/test/CodeGenCUDA/spirv-amdgcn-bf16.cu   | 129 
 .../test/CodeGenCXX/spirv-amdgcn-float16.cpp  |  38 +++
 clang/test/CodeGenHIP/spirv-amdgcn-ballot.cpp |  27 ++
 .../spirv-amdgcn-dpp-const-fold.hip   |  46 +++
 clang/test/CodeGenHIP/spirv-amdgcn-half.hip   |  15 +
 .../predefined-macros-no-warnings.c   |   1 +
 clang/test/Preprocessor/predefined-macros.c   |  10 +
 ...in-spirv-amdgcn-atomic-inc-dec-failure.cpp |  25 ++
 .../Sema/inline-asm-validate-spirv-amdgcn.cl  | 111 +++
 clang/test/SemaCUDA/allow-int128.cu   |   3 +
 clang/test/SemaCUDA/amdgpu-f128.cu|   1 +
 clang/test/SemaCUDA/float16.cu|   1 +
 clang/test/SemaCUDA/fp16-arg-return.cu|   1 +
 .../test/SemaCUDA/spirv-amdgcn-atomic-ops.cu  |  86 +
 22 files changed, 1178 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenCUDA/builtins-spirv-amdgcn.cu
 create mode 100644 
clang/test/CodeGenCUDA/builtins-unsafe-atomics-spirv-amdgcn-gfx90a.cu
 create mode 100644 clang/test/CodeGenCUDA/spirv-amdgcn-bf16.cu
 create mode 100644 clang/test/CodeGenCXX/spirv-amdgcn-float16.cpp
 create mode 100644 clang/test/CodeGenHIP/spirv-amdgcn-ballot.cpp
 create mode 100644 clang/test/CodeGenHIP/spirv-amdgcn-dpp-const-fold.hip
 create mode 100644 clang/test/CodeGenHIP/spirv-amdgcn-half.hip
 create mode 100644 
clang/test/Sema/builtin-spirv-amdgcn-atomic-inc-dec-failure.cpp
 create mode 100644 clang/test/Sema/inline-asm-validate-spirv-amdgcn.cl
 create mode 100644 clang/test/SemaCUDA/spirv-amdgcn-atomic-ops.cu

diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index e3283510c6aac7..04a13e3385d1f6 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -673,8 +673,12 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple &Triple,
   }
   case llvm::Triple::spirv64: {
 if (os != llvm::Triple::UnknownOS ||
-Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
+Triple.getEnvironment() != llvm::Triple::UnknownEnvironment) {
+  if (os == llvm::Triple::OSType::AMDHSA)
+return std::make_unique(Triple, Opts);
+
   return nullptr;
+}
 return std::make_unique(Triple, Opts);
   }
   case llvm::Triple::wasm32:
diff --git a/clang/lib/Basic/Targets/SPIR.cpp b/clang/lib/Basic/Targets/SPIR.cpp
index dc920177d3a910..d7d232ac9484f8 100644
--- a/clang/lib/Basic/Targets/SPIR.cpp
+++ b/clang/lib/Basic/Targets/SPIR.cpp
@@ -12,6 +12,8 @@
 
 #include "SPIR.h"
 #include "Targets.h"
+#include "clang/Basic/Builtins.h"
+#include "clang/Basic/TargetBuiltins.h"
 
 using namespace clang;
 using namespace clang::targets;
@@ -54,3 +56,289 @@ void SPIRV64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   BaseSPIRVTargetInfo::getTargetDefines(Opts, Builder);
   DefineStd(Builder, "SPIRV64", Opts);
 }
+
+static constexpr Builtin::Info BuiltinInfo[] = {
+#define BUILTIN(ID, TYPE, ATTRS)   
\
+  {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
+#define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE)   
\
+  {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
+#include "clang/Basic/BuiltinsAMDGPU.def"
+};
+
+namespace {
+const char *AMDGPUGCCRegNames[] = {
+  "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8",
+  "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17",
+  "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26",
+  "v27", "v28", "v29", "v30", "v31", "v32", "v33", "v34", "v35",
+  "v36", "v37", "v38", "v39", "v40", "v41", "v42", "v43", "v44",
+  "v45", "v46", "v47", "v48", "v49", "v50", "v51", "v52", "v53",
+  "v54", "v55", "v56", "v57", "v58", "v59", "v60", "v61", "v62",
+  "v63", "v64", "v65", "v66", "v67", "v68", "v69", "v70", "v71",
+  "v72", "v73", "v74", "v75", "v76", "v77", "v78", "v79", "v80",
+  "v81", "v82", "v83", "v84", "v85", "v86", "v87", "v88", "v89",
+  "v90", "v91", "v92", "v93", "v94", "v95", "v96", "v97", "v98",
+  "v99", "v100", "v101", "v102", "v103", "v104", "v105", "v106", "v107",
+  "v108", "v109", "v110", "v111", "v112", "v113", "v114", "v115", "v116",
+  "v117", "v118", "v119", "v120", "v121", "v122", "v123", "v124", "v

[clang] [clang-repl] fix top-level statement declaration context (PR #75547)

2024-04-28 Thread Pavel Kalugin via cfe-commits

p4vook wrote:

Looking for someone with knowledge of Clang AST, because I can't figure out the 
correct context to insert the statement into. Current implementation breaks 
"for" loop.

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


[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-04-28 Thread Joseph Huber via cfe-commits


@@ -673,8 +673,12 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple &Triple,
   }
   case llvm::Triple::spirv64: {
 if (os != llvm::Triple::UnknownOS ||
-Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
+Triple.getEnvironment() != llvm::Triple::UnknownEnvironment) {
+  if (os == llvm::Triple::OSType::AMDHSA)
+return std::make_unique(Triple, Opts);
+

jhuber6 wrote:

```suggestion
```

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


[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-04-28 Thread Joseph Huber via cfe-commits


@@ -54,3 +56,77 @@ void SPIRV64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   BaseSPIRVTargetInfo::getTargetDefines(Opts, Builder);
   DefineStd(Builder, "SPIRV64", Opts);
 }
+
+namespace {
+const AMDGPUTargetInfo AMDGPUTI(llvm::Triple("amdgcn-amd-amdhsa"), {});
+
+} // anonymous namespace
+
+ArrayRef SPIRV64AMDGCNTargetInfo::getGCCRegNames() const {
+  return AMDGPUTI.getGCCRegNames();
+}
+
+bool SPIRV64AMDGCNTargetInfo::initFeatureMap(
+llvm::StringMap &Features, DiagnosticsEngine &Diags, StringRef,
+const std::vector &FeatureVec) const {
+  llvm::AMDGPU::fillAMDGPUFeatureMap({}, getTriple(), Features);
+
+  return TargetInfo::initFeatureMap(Features, Diags, {}, FeatureVec);
+}
+
+bool SPIRV64AMDGCNTargetInfo::validateAsmConstraint(
+const char *&Name, TargetInfo::ConstraintInfo &Info) const {
+  return AMDGPUTI.validateAsmConstraint(Name, Info);
+}
+
+std::string
+SPIRV64AMDGCNTargetInfo::convertConstraint(const char *&Constraint) const {
+  return AMDGPUTI.convertConstraint(Constraint);
+}
+
+ArrayRef SPIRV64AMDGCNTargetInfo::getTargetBuiltins() const {
+  return AMDGPUTI.getTargetBuiltins();
+}
+
+void SPIRV64AMDGCNTargetInfo::getTargetDefines(const LangOptions &Opts,
+   MacroBuilder &Builder) const {
+  BaseSPIRVTargetInfo::getTargetDefines(Opts, Builder);
+  DefineStd(Builder, "SPIRV64", Opts);
+
+  Builder.defineMacro("__AMD__");
+  Builder.defineMacro("__AMDGPU__");
+  Builder.defineMacro("__AMDGCN__");
+}
+
+void SPIRV64AMDGCNTargetInfo::setAuxTarget(const TargetInfo *Aux) {

jhuber6 wrote:

Is `AUX` guaranteed non-null here? I know in the NVPTX target we only have an 
`Aux` when compiling for CUDA and use that to make sure type widths match up. 
However, if you have a direct compilation via `--target=nvptx64-nvidia-cuda` it 
will be null and not used.

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


[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-04-28 Thread Joseph Huber via cfe-commits


@@ -54,3 +56,77 @@ void SPIRV64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   BaseSPIRVTargetInfo::getTargetDefines(Opts, Builder);
   DefineStd(Builder, "SPIRV64", Opts);
 }
+
+namespace {
+const AMDGPUTargetInfo AMDGPUTI(llvm::Triple("amdgcn-amd-amdhsa"), {});
+
+} // anonymous namespace

jhuber6 wrote:

```suggestion
static const AMDGPUTargetInfo AMDGPUTI(llvm::Triple("amdgcn-amd-amdhsa"), {});
```

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


[clang-tools-extra] [clang-tidy] Add modernize-use-std-format check (PR #90397)

2024-04-28 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,108 @@
+//===--- UseStdFormatCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseStdFormatCheck.h"
+#include "../utils/FormatStringConverter.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/FixIt.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+namespace {
+AST_MATCHER(StringLiteral, isOrdinary) { return Node.isOrdinary(); }
+} // namespace
+
+UseStdFormatCheck::UseStdFormatCheck(StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StrictMode(Options.getLocalOrGlobal("StrictMode", false)),
+  StrFormatLikeFunctions(utils::options::parseStringList(
+  Options.get("StrFormatLikeFunctions", ""))),
+  ReplacementFormatFunction(
+  Options.get("ReplacementFormatFunction", "std::format")),
+  IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
+   utils::IncludeSorter::IS_LLVM),
+  areDiagsSelfContained()),
+  MaybeHeaderToInclude(Options.get("FormatHeader")) {
+  if (StrFormatLikeFunctions.empty())
+StrFormatLikeFunctions.push_back("absl::StrFormat");
+
+  if (!MaybeHeaderToInclude && ReplacementFormatFunction == "std::format")
+MaybeHeaderToInclude = "";
+}
+
+void UseStdFormatCheck::registerPPCallbacks(const SourceManager &SM,
+Preprocessor *PP,
+Preprocessor *ModuleExpanderPP) {
+  IncludeInserter.registerPreprocessor(PP);
+}
+
+void UseStdFormatCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(argumentCountAtLeast(1),
+   hasArgument(0, stringLiteral(isOrdinary())),
+   callee(functionDecl(unless(cxxMethodDecl()),
+   matchers::matchesAnyListedName(
+   StrFormatLikeFunctions))
+  .bind("func_decl")))
+  .bind("strformat"),
+  this);
+}
+
+void UseStdFormatCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  using utils::options::serializeStringList;
+  Options.store(Opts, "StrictMode", StrictMode);
+  Options.store(Opts, "StrFormatLikeFunctions",
+serializeStringList(StrFormatLikeFunctions));
+  Options.store(Opts, "ReplacementFormatFunction", ReplacementFormatFunction);
+  Options.store(Opts, "IncludeStyle", IncludeInserter.getStyle());
+  if (MaybeHeaderToInclude)
+Options.store(Opts, "FormatHeader", *MaybeHeaderToInclude);
+}
+
+void UseStdFormatCheck::check(const MatchFinder::MatchResult &Result) {
+  const unsigned FormatArgOffset = 0;
+  const auto *OldFunction = Result.Nodes.getNodeAs("func_decl");
+  const auto *StrFormat = Result.Nodes.getNodeAs("strformat");
+
+  utils::FormatStringConverter::Configuration ConverterConfig;
+  ConverterConfig.StrictMode = StrictMode;
+  utils::FormatStringConverter Converter(Result.Context, StrFormat,
+ FormatArgOffset, ConverterConfig,
+ getLangOpts());
+  const Expr *StrFormatCall = StrFormat->getCallee();
+  if (!Converter.canApply()) {
+DiagnosticBuilder Diag = diag(StrFormat->getBeginLoc(),
+  "unable to use '%0' instead of %1 because 
%2")
+ << ReplacementFormatFunction
+ << OldFunction->getIdentifier()
+ << Converter.conversionNotPossibleReason();
+return;
+  }
+
+  DiagnosticBuilder Diag =
+  diag(StrFormatCall->getBeginLoc(), "use '%0' instead of %1")
+  << ReplacementFormatFunction << OldFunction->getIdentifier();
+  Diag << FixItHint::CreateReplacement(
+  CharSourceRange::getTokenRange(StrFormatCall->getBeginLoc(),

PiotrZSL wrote:

getBeginLoc/getEndLoc could be changed into 
[getSourceRange](https://clang.llvm.org/doxygen/classclang_1_1Stmt.html#a6844392ee6148b5fe821f211b95e5d1b)
 ()

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


[clang-tools-extra] [clang-tidy] Add modernize-use-std-format check (PR #90397)

2024-04-28 Thread Piotr Zegar via cfe-commits

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

To be honest I'm not sure why it wasn't merged, there were some dependences on 
other changes and modernize-use-std-print check, and somehow it fall under 
radar.

Overall looks fine. Please fix pointed out nits that pop up.

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


[clang-tools-extra] [clang-tidy] Add modernize-use-std-format check (PR #90397)

2024-04-28 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] Add modernize-use-std-format check (PR #90397)

2024-04-28 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,108 @@
+//===--- UseStdFormatCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseStdFormatCheck.h"
+#include "../utils/FormatStringConverter.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/FixIt.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+namespace {
+AST_MATCHER(StringLiteral, isOrdinary) { return Node.isOrdinary(); }
+} // namespace
+
+UseStdFormatCheck::UseStdFormatCheck(StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StrictMode(Options.getLocalOrGlobal("StrictMode", false)),
+  StrFormatLikeFunctions(utils::options::parseStringList(
+  Options.get("StrFormatLikeFunctions", ""))),
+  ReplacementFormatFunction(
+  Options.get("ReplacementFormatFunction", "std::format")),
+  IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
+   utils::IncludeSorter::IS_LLVM),
+  areDiagsSelfContained()),
+  MaybeHeaderToInclude(Options.get("FormatHeader")) {
+  if (StrFormatLikeFunctions.empty())
+StrFormatLikeFunctions.push_back("absl::StrFormat");
+
+  if (!MaybeHeaderToInclude && ReplacementFormatFunction == "std::format")
+MaybeHeaderToInclude = "";
+}
+
+void UseStdFormatCheck::registerPPCallbacks(const SourceManager &SM,
+Preprocessor *PP,
+Preprocessor *ModuleExpanderPP) {
+  IncludeInserter.registerPreprocessor(PP);
+}
+
+void UseStdFormatCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(argumentCountAtLeast(1),
+   hasArgument(0, stringLiteral(isOrdinary())),
+   callee(functionDecl(unless(cxxMethodDecl()),
+   matchers::matchesAnyListedName(
+   StrFormatLikeFunctions))
+  .bind("func_decl")))
+  .bind("strformat"),
+  this);
+}
+
+void UseStdFormatCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  using utils::options::serializeStringList;
+  Options.store(Opts, "StrictMode", StrictMode);
+  Options.store(Opts, "StrFormatLikeFunctions",
+serializeStringList(StrFormatLikeFunctions));
+  Options.store(Opts, "ReplacementFormatFunction", ReplacementFormatFunction);
+  Options.store(Opts, "IncludeStyle", IncludeInserter.getStyle());
+  if (MaybeHeaderToInclude)
+Options.store(Opts, "FormatHeader", *MaybeHeaderToInclude);
+}
+
+void UseStdFormatCheck::check(const MatchFinder::MatchResult &Result) {
+  const unsigned FormatArgOffset = 0;
+  const auto *OldFunction = Result.Nodes.getNodeAs("func_decl");
+  const auto *StrFormat = Result.Nodes.getNodeAs("strformat");
+
+  utils::FormatStringConverter::Configuration ConverterConfig;
+  ConverterConfig.StrictMode = StrictMode;
+  utils::FormatStringConverter Converter(Result.Context, StrFormat,
+ FormatArgOffset, ConverterConfig,
+ getLangOpts());
+  const Expr *StrFormatCall = StrFormat->getCallee();
+  if (!Converter.canApply()) {
+DiagnosticBuilder Diag = diag(StrFormat->getBeginLoc(),
+  "unable to use '%0' instead of %1 because 
%2")
+ << ReplacementFormatFunction
+ << OldFunction->getIdentifier()
+ << Converter.conversionNotPossibleReason();
+return;
+  }
+
+  DiagnosticBuilder Diag =
+  diag(StrFormatCall->getBeginLoc(), "use '%0' instead of %1")
+  << ReplacementFormatFunction << OldFunction->getIdentifier();

PiotrZSL wrote:

`<< OldFunction; ` should be sufficient.

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


[clang-tools-extra] [clang-tidy] Add modernize-use-std-format check (PR #90397)

2024-04-28 Thread Piotr Zegar via cfe-commits


@@ -627,7 +628,8 @@ void FormatStringConverter::finalizeFormatText() {
 
   // It's clearer to convert printf("Hello\r\n"); to std::print("Hello\r\n")
   // than to std::println("Hello\r");
-  if (StringRef(StandardFormatString).ends_with("\\n") &&
+  if (Config.AllowTrailingNewlineRemoval &&
+  StringRef(StandardFormatString).ends_with("\\n") &&
   !StringRef(StandardFormatString).ends_with("n") &&
   !StringRef(StandardFormatString).ends_with("\\r\\n")) {

PiotrZSL wrote:

Avoid constructing StringRef multiple times.

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


[clang-tools-extra] [clang-tidy] Add modernize-use-std-format check (PR #90397)

2024-04-28 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,84 @@
+.. title:: clang-tidy - modernize-use-std-format
+
+modernize-use-std-format
+
+
+Converts calls to ``absl::StrFormat``, or other functions via
+configuration options, to C++20's ``std::format``, or another function
+via a configuration option, modifying the format string appropriately and
+removing now-unnecessary calls to ``std::string::c_str()`` and
+``std::string::data()``.
+
+In other words, it turns lines like:
+
+.. code-block:: c++
+
+  return absl::StrFormat("The %s is %3d\n", description.c_str(), value);
+
+into:
+
+.. code-block:: c++
+
+  return std::format("The {} is {:3}", description, value);
+
+The check uses the same format-string-conversion algorithm as
+`modernize-use-std-print <../modernize/use-std-print.html>`_ and its
+shortcomings are described in the documentation for that check.
+
+Options
+---
+
+.. option:: StrictMode
+
+   When `true`, the check will add casts when converting from variadic
+   functions and printing signed or unsigned integer types (including
+   fixed-width integer types from , ``ptrdiff_t``, ``size_t``
+   and ``ssize_t``) as the opposite signedness to ensure that the output
+   would matches that of a simple wrapper for ``std::sprintf`` that
+   accepted a C-style variable argument list. For example, with
+   `StrictMode` enabled:
+
+  .. code-block:: c++
+
+extern std::string strprintf(const char *format, ...);
+int i = -42;
+unsigned int u = 0x;
+return strprintf("%d %u\n", i, u);
+
+  would be converted to:
+
+  .. code-block:: c++
+
+return std::format("{} {}\n", static_cast(i), 
static_cast(u));
+
+  to ensure that the output will continue to be the unsigned representation
+  of -42 and the signed representation of 0x (often 4294967254
+  and -1 respectively.) When `false` (which is the default), these casts

PiotrZSL wrote:

`.)` -> `).`

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


[clang-tools-extra] [clang-tidy] Add modernize-use-std-format check (PR #90397)

2024-04-28 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,48 @@
+//===--- UseStdFormatCheck.h - clang-tidy ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDFORMATCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USESTDFORMATCHECK_H
+
+#include "../ClangTidyCheck.h"
+#include "../utils/IncludeInserter.h"
+
+namespace clang::tidy::modernize {
+
+/// Convert calls to absl::StrFormat-like functions to std::format.

PiotrZSL wrote:

synchronize with release notes

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


[clang-tools-extra] [clang-tidy] Add modernize-use-std-format check (PR #90397)

2024-04-28 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,97 @@
+// RUN: %check_clang_tidy \
+// RUN:   -std=c++20 %s modernize-use-std-format %t -- \
+// RUN:   -config="{CheckOptions: [{key: StrictMode, value: true}]}" \
+// RUN:   -- -isystem %clang_tidy_headers
+// RUN: %check_clang_tidy \
+// RUN:   -std=c++20 %s modernize-use-std-format %t -- \
+// RUN:   -config="{CheckOptions: [{key: StrictMode, value: false}]}" \
+// RUN:   -- -isystem %clang_tidy_headers
+#include 
+// CHECK-FIXES: #include 
+
+namespace absl
+{
+// Use const char * for the format since the real type is hard to mock up.
+template 
+std::string StrFormat(const char *format, const Args&... args);
+} // namespace absl
+
+template 
+struct iterator {
+  T *operator->();
+  T &operator*();
+};
+
+std::string StrFormat_simple() {
+  return absl::StrFormat("Hello");
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 
'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("Hello");
+}
+
+std::string StrFormat_complex(const char *name, double value) {
+  return absl::StrFormat("'%s'='%f'", name, value);
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 
'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("'{}'='{:f}'", name, value);
+}
+
+std::string StrFormat_integer_conversions() {
+  return absl::StrFormat("int:%d int:%d char:%c char:%c", 65, 'A', 66, 'B');
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 
'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("int:{} int:{:d} char:{:c} char:{}", 65, 
'A', 66, 'B');
+}
+
+// FormatConverter is capable of removing newlines from the end of the format
+// string. Ensure that isn't incorrectly happening for std::format.
+std::string StrFormat_no_newline_removal() {
+  return absl::StrFormat("a line\n");
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 
'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("a line\n");
+}
+
+// FormatConverter is capable of removing newlines from the end of the format
+// string. Ensure that isn't incorrectly happening for std::format.
+std::string StrFormat_cstr_removal(const std::string &s1, const std::string 
*s2) {
+  return absl::StrFormat("%s %s %s %s", s1.c_str(), s1.data(), s2->c_str(), 
s2->data());
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 
'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("{} {} {} {}", s1, s1, *s2, *s2);
+}
+
+std::string StrFormat_strict_conversion() {
+  const unsigned char uc = 'A';
+  return absl::StrFormat("Integer %hhd from unsigned char\n", uc);
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 
'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("Integer {} from unsigned char\n", uc);
+}
+
+std::string StrFormat_field_width_and_precision() {
+  auto s1 = absl::StrFormat("width only:%*d width and precision:%*.*f 
precision only:%.*f", 3, 42, 4, 2, 3.14159265358979323846, 5, 2.718);
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use 'std::format' instead of 
'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: std::format("width only:{:{}} width and precision:{:{}.{}f} 
precision only:{:.{}f}", 42, 3, 3.14159265358979323846, 4, 2, 2.718, 5);
+
+  auto s2 = absl::StrFormat("width and precision positional:%1$*2$.*3$f 
after", 3.14159265358979323846, 4, 2);
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use 'std::format' instead of 
'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: std::format("width and precision positional:{0:{1}.{2}f} 
after", 3.14159265358979323846, 4, 2);
+
+  const int width = 10, precision = 3;
+  const unsigned int ui1 = 42, ui2 = 43, ui3 = 44;
+  auto s3 = absl::StrFormat("casts width only:%*d width and precision:%*.*d 
precision only:%.*d\n", 3, ui1, 4, 2, ui2, 5, ui3);
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use 'std::format' instead of 
'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES-NOTSTRICT: std::format("casts width only:{:{}} width and 
precision:{:{}.{}} precision only:{:.{}}", ui1, 3, ui2, 4, 2, ui3, 5);
+  // CHECK-FIXES-STRICT: std::format("casts width only:{:{}} width and 
precision:{:{}.{}} precision only:{:.{}}", static_cast(ui1), 3, 
static_cast(ui2), 4, 2, static_cast(ui3), 5);
+
+  auto s4 = absl::StrFormat("c_str removal width only:%*s width and 
precision:%*.*s precision only:%.*s", 3, s1.c_str(), 4, 2, s2.c_str(), 5, 
s3.c_str());
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use 'std::format' instead of 
'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: std::format("c_str removal width only:{:>{}} width and 
precision:{:>{}.{}} precision only:{:.{}}", s1, 3, s2, 4, 2, s3, 5);
+
+  const std::string *ps1 = &s1, *ps2 = &s2, *ps3 = &s3;
+  auto s5 = absl::StrFormat("c_str() removal pointer width only:%-*s width and 
precision:%-*.*s precision only:%-.*s", 3, ps1->c_str()

[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-04-28 Thread Alex Voicu via cfe-commits


@@ -54,3 +56,77 @@ void SPIRV64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   BaseSPIRVTargetInfo::getTargetDefines(Opts, Builder);
   DefineStd(Builder, "SPIRV64", Opts);
 }
+
+namespace {
+const AMDGPUTargetInfo AMDGPUTI(llvm::Triple("amdgcn-amd-amdhsa"), {});
+
+} // anonymous namespace
+
+ArrayRef SPIRV64AMDGCNTargetInfo::getGCCRegNames() const {
+  return AMDGPUTI.getGCCRegNames();
+}
+
+bool SPIRV64AMDGCNTargetInfo::initFeatureMap(
+llvm::StringMap &Features, DiagnosticsEngine &Diags, StringRef,
+const std::vector &FeatureVec) const {
+  llvm::AMDGPU::fillAMDGPUFeatureMap({}, getTriple(), Features);
+
+  return TargetInfo::initFeatureMap(Features, Diags, {}, FeatureVec);
+}
+
+bool SPIRV64AMDGCNTargetInfo::validateAsmConstraint(
+const char *&Name, TargetInfo::ConstraintInfo &Info) const {
+  return AMDGPUTI.validateAsmConstraint(Name, Info);
+}
+
+std::string
+SPIRV64AMDGCNTargetInfo::convertConstraint(const char *&Constraint) const {
+  return AMDGPUTI.convertConstraint(Constraint);
+}
+
+ArrayRef SPIRV64AMDGCNTargetInfo::getTargetBuiltins() const {
+  return AMDGPUTI.getTargetBuiltins();
+}
+
+void SPIRV64AMDGCNTargetInfo::getTargetDefines(const LangOptions &Opts,
+   MacroBuilder &Builder) const {
+  BaseSPIRVTargetInfo::getTargetDefines(Opts, Builder);
+  DefineStd(Builder, "SPIRV64", Opts);
+
+  Builder.defineMacro("__AMD__");
+  Builder.defineMacro("__AMDGPU__");
+  Builder.defineMacro("__AMDGCN__");
+}
+
+void SPIRV64AMDGCNTargetInfo::setAuxTarget(const TargetInfo *Aux) {

AlexVlx wrote:

As far as I can tell, `setAuxTarget` is only used when compiling for CUDA / 
HIP, and wouldn't get invoked otherwise (I could be wrong though); having said 
that, it probably makes sense to assert that `Aux` is non-null, thanks for 
pointing this out.

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


[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-04-28 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx updated 
https://github.com/llvm/llvm-project/pull/89796

>From 662f160418c704f45e57e751168903d774b74303 Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Tue, 23 Apr 2024 17:41:25 +0100
Subject: [PATCH 1/6] Add initial support for AMDGCN flavoured SPIRV.

---
 clang/lib/Basic/Targets.cpp   |   6 +-
 clang/lib/Basic/Targets/SPIR.cpp  | 288 +
 clang/lib/Basic/Targets/SPIR.h|  51 +++
 clang/lib/CodeGen/CGBuiltin.cpp   |   7 +
 clang/test/CodeGen/target-data.c  |   4 +
 .../test/CodeGenCUDA/builtins-spirv-amdgcn.cu | 294 ++
 ...tins-unsafe-atomics-spirv-amdgcn-gfx90a.cu |  31 ++
 clang/test/CodeGenCUDA/long-double.cu |   4 +
 clang/test/CodeGenCUDA/spirv-amdgcn-bf16.cu   | 129 
 .../test/CodeGenCXX/spirv-amdgcn-float16.cpp  |  38 +++
 clang/test/CodeGenHIP/spirv-amdgcn-ballot.cpp |  27 ++
 .../spirv-amdgcn-dpp-const-fold.hip   |  46 +++
 clang/test/CodeGenHIP/spirv-amdgcn-half.hip   |  15 +
 .../predefined-macros-no-warnings.c   |   1 +
 clang/test/Preprocessor/predefined-macros.c   |  10 +
 ...in-spirv-amdgcn-atomic-inc-dec-failure.cpp |  25 ++
 .../Sema/inline-asm-validate-spirv-amdgcn.cl  | 111 +++
 clang/test/SemaCUDA/allow-int128.cu   |   3 +
 clang/test/SemaCUDA/amdgpu-f128.cu|   1 +
 clang/test/SemaCUDA/float16.cu|   1 +
 clang/test/SemaCUDA/fp16-arg-return.cu|   1 +
 .../test/SemaCUDA/spirv-amdgcn-atomic-ops.cu  |  86 +
 22 files changed, 1178 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenCUDA/builtins-spirv-amdgcn.cu
 create mode 100644 
clang/test/CodeGenCUDA/builtins-unsafe-atomics-spirv-amdgcn-gfx90a.cu
 create mode 100644 clang/test/CodeGenCUDA/spirv-amdgcn-bf16.cu
 create mode 100644 clang/test/CodeGenCXX/spirv-amdgcn-float16.cpp
 create mode 100644 clang/test/CodeGenHIP/spirv-amdgcn-ballot.cpp
 create mode 100644 clang/test/CodeGenHIP/spirv-amdgcn-dpp-const-fold.hip
 create mode 100644 clang/test/CodeGenHIP/spirv-amdgcn-half.hip
 create mode 100644 
clang/test/Sema/builtin-spirv-amdgcn-atomic-inc-dec-failure.cpp
 create mode 100644 clang/test/Sema/inline-asm-validate-spirv-amdgcn.cl
 create mode 100644 clang/test/SemaCUDA/spirv-amdgcn-atomic-ops.cu

diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index e3283510c6aac7..04a13e3385d1f6 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -673,8 +673,12 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple &Triple,
   }
   case llvm::Triple::spirv64: {
 if (os != llvm::Triple::UnknownOS ||
-Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
+Triple.getEnvironment() != llvm::Triple::UnknownEnvironment) {
+  if (os == llvm::Triple::OSType::AMDHSA)
+return std::make_unique(Triple, Opts);
+
   return nullptr;
+}
 return std::make_unique(Triple, Opts);
   }
   case llvm::Triple::wasm32:
diff --git a/clang/lib/Basic/Targets/SPIR.cpp b/clang/lib/Basic/Targets/SPIR.cpp
index dc920177d3a910..d7d232ac9484f8 100644
--- a/clang/lib/Basic/Targets/SPIR.cpp
+++ b/clang/lib/Basic/Targets/SPIR.cpp
@@ -12,6 +12,8 @@
 
 #include "SPIR.h"
 #include "Targets.h"
+#include "clang/Basic/Builtins.h"
+#include "clang/Basic/TargetBuiltins.h"
 
 using namespace clang;
 using namespace clang::targets;
@@ -54,3 +56,289 @@ void SPIRV64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   BaseSPIRVTargetInfo::getTargetDefines(Opts, Builder);
   DefineStd(Builder, "SPIRV64", Opts);
 }
+
+static constexpr Builtin::Info BuiltinInfo[] = {
+#define BUILTIN(ID, TYPE, ATTRS)   
\
+  {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
+#define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE)   
\
+  {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
+#include "clang/Basic/BuiltinsAMDGPU.def"
+};
+
+namespace {
+const char *AMDGPUGCCRegNames[] = {
+  "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8",
+  "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17",
+  "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26",
+  "v27", "v28", "v29", "v30", "v31", "v32", "v33", "v34", "v35",
+  "v36", "v37", "v38", "v39", "v40", "v41", "v42", "v43", "v44",
+  "v45", "v46", "v47", "v48", "v49", "v50", "v51", "v52", "v53",
+  "v54", "v55", "v56", "v57", "v58", "v59", "v60", "v61", "v62",
+  "v63", "v64", "v65", "v66", "v67", "v68", "v69", "v70", "v71",
+  "v72", "v73", "v74", "v75", "v76", "v77", "v78", "v79", "v80",
+  "v81", "v82", "v83", "v84", "v85", "v86", "v87", "v88", "v89",
+  "v90", "v91", "v92", "v93", "v94", "v95", "v96", "v97", "v98",
+  "v99", "v100", "v101", "v102", "v103", "v104", "v105", "v106", "v107",
+  "v108", "v109", "v110", "v111", "v112", "v113", "v114", "v115", "v116",
+  "v117", "v118", "v119", "v120", "v121", "v122", "v123", "v124", "v

[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-04-28 Thread Joseph Huber via cfe-commits


@@ -6088,6 +6088,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   StringRef Prefix =
   llvm::Triple::getArchTypePrefix(getTarget().getTriple().getArch());
   if (!Prefix.empty()) {
+if (Prefix == "spv" &&
+getTarget().getTriple().getOS() == llvm::Triple::OSType::AMDHSA)
+  Prefix = "amdgcn";

jhuber6 wrote:

What is this required for? I'm wondering why we'd need to reset the prefix here 
instead of updating the logic somewhere else.

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


[clang] [lld] [llvm] [MachineOutliner][CGData] Append Content Hash To Outlined Function Name (PR #90400)

2024-04-28 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff b6824c9d459da059e247a60c1ebd1aeb580dacc2 
6186c576e8ebfb80af7a58c6d8d24ca0f7277ade -- clang/test/Driver/codegen-data.c 
llvm/include/llvm/CodeGenData/CodeGenData.h 
llvm/include/llvm/CodeGenData/CodeGenData.inc 
llvm/include/llvm/CodeGenData/CodeGenDataReader.h 
llvm/include/llvm/CodeGenData/CodeGenDataWriter.h 
llvm/include/llvm/CodeGenData/OutlinedHashTree.h 
llvm/include/llvm/CodeGenData/OutlinedHashTreeRecord.h 
llvm/lib/CodeGenData/CodeGenData.cpp llvm/lib/CodeGenData/CodeGenDataReader.cpp 
llvm/lib/CodeGenData/CodeGenDataWriter.cpp 
llvm/lib/CodeGenData/OutlinedHashTree.cpp 
llvm/lib/CodeGenData/OutlinedHashTreeRecord.cpp 
llvm/tools/llvm-cgdata/llvm-cgdata.cpp 
llvm/unittests/CodeGenData/OutlinedHashTreeRecordTest.cpp 
llvm/unittests/CodeGenData/OutlinedHashTreeTest.cpp 
clang/lib/CodeGen/BackendUtil.cpp clang/lib/Driver/ToolChains/CommonArgs.cpp 
clang/lib/Driver/ToolChains/Darwin.cpp lld/MachO/Config.h lld/MachO/Driver.cpp 
lld/MachO/InputSection.h llvm/include/llvm/CodeGen/MachineOutliner.h 
llvm/include/llvm/CodeGen/TargetInstrInfo.h llvm/include/llvm/LTO/LTOBackend.h 
llvm/lib/CodeGen/MachineOutliner.cpp llvm/lib/CodeGen/MachineStableHash.cpp 
llvm/lib/LTO/LTO.cpp llvm/lib/LTO/LTOBackend.cpp 
llvm/lib/Target/AArch64/AArch64InstrInfo.cpp 
llvm/lib/Target/AArch64/AArch64InstrInfo.h
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp 
b/llvm/lib/CodeGen/MachineOutliner.cpp
index 1da93c154d..5d8c54bf27 100644
--- a/llvm/lib/CodeGen/MachineOutliner.cpp
+++ b/llvm/lib/CodeGen/MachineOutliner.cpp
@@ -134,10 +134,12 @@ static cl::opt
 "the codegen data generation or use"),
cl::init(false));
 
-static cl::opt
-AppendContentHashToOutlinedName("append-content-hash-outlined-name", 
cl::Hidden,
-cl::desc("This appends the content hash to the globally outlined function 
name. It's beneficial for enhancing the precision of the stable hash and for 
ordering the outlined functions."),
-   cl::init(false));
+static cl::opt AppendContentHashToOutlinedName(
+"append-content-hash-outlined-name", cl::Hidden,
+cl::desc("This appends the content hash to the globally outlined function "
+ "name. It's beneficial for enhancing the precision of the stable "
+ "hash and for ordering the outlined functions."),
+cl::init(false));
 
 namespace {
 
@@ -862,8 +864,10 @@ void 
MachineOutliner::computeAndPublishHashSequence(MachineFunction &MF,
 
   // Append a unique name based on the non-empty hash sequence.
   if (AppendContentHashToOutlinedName && !OutlinedHashSequence.empty()) {
-auto CombinedHash = 
stable_hash_combine_range(OutlinedHashSequence.begin(), 
OutlinedHashSequence.end());
-auto NewName = MF.getName().str() + ".content." + 
std::to_string(CombinedHash);
+auto CombinedHash = stable_hash_combine_range(OutlinedHashSequence.begin(),
+  OutlinedHashSequence.end());
+auto NewName =
+MF.getName().str() + ".content." + std::to_string(CombinedHash);
 MF.getFunction().setName(NewName);
   }
 

``




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


[clang] [lld] [llvm] Leaf + cgdata (PR #90401)

2024-04-28 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff b6824c9d459da059e247a60c1ebd1aeb580dacc2 
9b99b234ef4edb68fc6d9734595d53685e16927c -- clang/test/Driver/codegen-data.c 
llvm/include/llvm/CodeGenData/CodeGenData.h 
llvm/include/llvm/CodeGenData/CodeGenData.inc 
llvm/include/llvm/CodeGenData/CodeGenDataReader.h 
llvm/include/llvm/CodeGenData/CodeGenDataWriter.h 
llvm/include/llvm/CodeGenData/OutlinedHashTree.h 
llvm/include/llvm/CodeGenData/OutlinedHashTreeRecord.h 
llvm/lib/CodeGenData/CodeGenData.cpp llvm/lib/CodeGenData/CodeGenDataReader.cpp 
llvm/lib/CodeGenData/CodeGenDataWriter.cpp 
llvm/lib/CodeGenData/OutlinedHashTree.cpp 
llvm/lib/CodeGenData/OutlinedHashTreeRecord.cpp 
llvm/tools/llvm-cgdata/llvm-cgdata.cpp 
llvm/unittests/CodeGenData/OutlinedHashTreeRecordTest.cpp 
llvm/unittests/CodeGenData/OutlinedHashTreeTest.cpp 
clang/lib/CodeGen/BackendUtil.cpp clang/lib/Driver/ToolChains/CommonArgs.cpp 
clang/lib/Driver/ToolChains/Darwin.cpp lld/MachO/Config.h lld/MachO/Driver.cpp 
lld/MachO/InputSection.h llvm/include/llvm/CodeGen/MachineOutliner.h 
llvm/include/llvm/CodeGen/TargetInstrInfo.h llvm/include/llvm/LTO/LTOBackend.h 
llvm/include/llvm/Support/SuffixTree.h 
llvm/include/llvm/Support/SuffixTreeNode.h llvm/lib/CodeGen/MachineOutliner.cpp 
llvm/lib/CodeGen/MachineStableHash.cpp llvm/lib/LTO/LTO.cpp 
llvm/lib/LTO/LTOBackend.cpp llvm/lib/Support/SuffixTree.cpp 
llvm/lib/Support/SuffixTreeNode.cpp 
llvm/lib/Target/AArch64/AArch64InstrInfo.cpp 
llvm/lib/Target/AArch64/AArch64InstrInfo.h 
llvm/unittests/Support/SuffixTreeTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp 
b/llvm/lib/CodeGen/MachineOutliner.cpp
index 052a52db79..bc6bbe830b 100644
--- a/llvm/lib/CodeGen/MachineOutliner.cpp
+++ b/llvm/lib/CodeGen/MachineOutliner.cpp
@@ -134,10 +134,12 @@ static cl::opt
 "the codegen data generation or use"),
cl::init(false));
 
-static cl::opt
-AppendContentHashToOutlinedName("append-content-hash-outlined-name", 
cl::Hidden,
-cl::desc("This appends the content hash to the globally outlined function 
name. It's beneficial for enhancing the precision of the stable hash and for 
ordering the outlined functions."),
-   cl::init(false));
+static cl::opt AppendContentHashToOutlinedName(
+"append-content-hash-outlined-name", cl::Hidden,
+cl::desc("This appends the content hash to the globally outlined function "
+ "name. It's beneficial for enhancing the precision of the stable "
+ "hash and for ordering the outlined functions."),
+cl::init(false));
 
 static cl::opt OutlinerLeafDescendants(
 "outliner-leaf-descendants", cl::init(true), cl::Hidden,
@@ -870,8 +872,10 @@ void 
MachineOutliner::computeAndPublishHashSequence(MachineFunction &MF,
 
   // Append a unique name based on the non-empty hash sequence.
   if (AppendContentHashToOutlinedName && !OutlinedHashSequence.empty()) {
-auto CombinedHash = 
stable_hash_combine_range(OutlinedHashSequence.begin(), 
OutlinedHashSequence.end());
-auto NewName = MF.getName().str() + ".content." + 
std::to_string(CombinedHash);
+auto CombinedHash = stable_hash_combine_range(OutlinedHashSequence.begin(),
+  OutlinedHashSequence.end());
+auto NewName =
+MF.getName().str() + ".content." + std::to_string(CombinedHash);
 MF.getFunction().setName(NewName);
   }
 
@@ -1041,9 +1045,9 @@ bool MachineOutliner::outline(
   // The function with highest priority should be outlined first.
   stable_sort(FunctionList, [](const std::unique_ptr &LHS,
const std::unique_ptr &RHS) {
-return LHS->getNotOutlinedCost() * RHS->getOutliningCost() >
-   RHS->getNotOutlinedCost() * LHS->getOutliningCost();
-  });
+return LHS->getNotOutlinedCost() * RHS->getOutliningCost() >
+   RHS->getNotOutlinedCost() * LHS->getOutliningCost();
+  });
 
   // Walk over each function, outlining them as we go along. Functions are
   // outlined greedily, based off the sort above.

``




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


[clang-tools-extra] [clang-tidy] Add modernize-use-std-format check (PR #90397)

2024-04-28 Thread Mike Crowe via cfe-commits

https://github.com/mikecrowe updated 
https://github.com/llvm/llvm-project/pull/90397

>From 0d6ede5d59cc70d803bfe2c7997737c1be358c75 Mon Sep 17 00:00:00 2001
From: Mike Crowe 
Date: Sun, 28 Apr 2024 12:41:46 +0100
Subject: [PATCH 1/8] [clang-tidy] Add modernize-use-std-format check

Add a new clang-tidy check that converts absl::StrFormat (and similar
functions) to std::format (and similar functions.)

Split the configuration of FormatStringConverter out to a separate
Configuration class so that we don't risk confusion by passing two
boolean configuration parameters into the constructor. Add
AllowTrailingNewlineRemoval option since we never want to remove
trailing newlines in this check.

Differential Revision: https://reviews.llvm.org/D154287
---
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../modernize/ModernizeTidyModule.cpp |   2 +
 .../modernize/UseStdFormatCheck.cpp   | 108 ++
 .../clang-tidy/modernize/UseStdFormatCheck.h  |  50 
 .../clang-tidy/modernize/UseStdPrintCheck.cpp |   5 +-
 .../utils/FormatStringConverter.cpp   |  10 +-
 .../clang-tidy/utils/FormatStringConverter.h  |   9 +-
 clang-tools-extra/docs/ReleaseNotes.rst   |   9 ++
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../checks/modernize/use-std-format.rst   |  84 ++
 .../modernize/use-std-format-custom.cpp   |  76 
 .../checkers/modernize/use-std-format-fmt.cpp |  37 ++
 .../checkers/modernize/use-std-format.cpp |  97 
 13 files changed, 483 insertions(+), 6 deletions(-)
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-fmt.cpp
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 8005d6e91c060c..576805c4c7f181 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -41,6 +41,7 @@ add_clang_library(clangTidyModernizeModule
   UseNullptrCheck.cpp
   UseOverrideCheck.cpp
   UseStartsEndsWithCheck.cpp
+  UseStdFormatCheck.cpp
   UseStdNumbersCheck.cpp
   UseStdPrintCheck.cpp
   UseTrailingReturnTypeCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 776558433c5baa..b9c7a2dc383e88 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -42,6 +42,7 @@
 #include "UseNullptrCheck.h"
 #include "UseOverrideCheck.h"
 #include "UseStartsEndsWithCheck.h"
+#include "UseStdFormatCheck.h"
 #include "UseStdNumbersCheck.h"
 #include "UseStdPrintCheck.h"
 #include "UseTrailingReturnTypeCheck.h"
@@ -76,6 +77,7 @@ class ModernizeModule : public ClangTidyModule {
 "modernize-use-designated-initializers");
 CheckFactories.registerCheck(
 "modernize-use-starts-ends-with");
+
CheckFactories.registerCheck("modernize-use-std-format");
 CheckFactories.registerCheck(
 "modernize-use-std-numbers");
 CheckFactories.registerCheck("modernize-use-std-print");
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
new file mode 100644
index 00..d22ebe857cf415
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
@@ -0,0 +1,108 @@
+//===--- UseStdFormatCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseStdFormatCheck.h"
+#include "../utils/FormatStringConverter.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/FixIt.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+namespace {
+AST_MATCHER(StringLiteral, isOrdinary) { return Node.isOrdinary(); }
+} // namespace
+
+UseStdFormatCheck::UseStdFormatCheck(StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StrictMode(Options.getLocalOrGlobal("StrictMode", false)),
+  StrFormatLikeFunctions(utils::options::parse

[clang-tools-extra] [clang-tidy] Add modernize-use-std-format check (PR #90397)

2024-04-28 Thread Mike Crowe via cfe-commits


@@ -0,0 +1,97 @@
+// RUN: %check_clang_tidy \
+// RUN:   -std=c++20 %s modernize-use-std-format %t -- \
+// RUN:   -config="{CheckOptions: [{key: StrictMode, value: true}]}" \
+// RUN:   -- -isystem %clang_tidy_headers
+// RUN: %check_clang_tidy \
+// RUN:   -std=c++20 %s modernize-use-std-format %t -- \
+// RUN:   -config="{CheckOptions: [{key: StrictMode, value: false}]}" \
+// RUN:   -- -isystem %clang_tidy_headers
+#include 
+// CHECK-FIXES: #include 
+
+namespace absl
+{
+// Use const char * for the format since the real type is hard to mock up.
+template 
+std::string StrFormat(const char *format, const Args&... args);
+} // namespace absl
+
+template 
+struct iterator {
+  T *operator->();
+  T &operator*();
+};
+
+std::string StrFormat_simple() {
+  return absl::StrFormat("Hello");
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 
'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("Hello");
+}
+
+std::string StrFormat_complex(const char *name, double value) {
+  return absl::StrFormat("'%s'='%f'", name, value);
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 
'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("'{}'='{:f}'", name, value);
+}
+
+std::string StrFormat_integer_conversions() {
+  return absl::StrFormat("int:%d int:%d char:%c char:%c", 65, 'A', 66, 'B');
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 
'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("int:{} int:{:d} char:{:c} char:{}", 65, 
'A', 66, 'B');
+}
+
+// FormatConverter is capable of removing newlines from the end of the format
+// string. Ensure that isn't incorrectly happening for std::format.
+std::string StrFormat_no_newline_removal() {
+  return absl::StrFormat("a line\n");
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 
'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("a line\n");
+}
+
+// FormatConverter is capable of removing newlines from the end of the format
+// string. Ensure that isn't incorrectly happening for std::format.
+std::string StrFormat_cstr_removal(const std::string &s1, const std::string 
*s2) {
+  return absl::StrFormat("%s %s %s %s", s1.c_str(), s1.data(), s2->c_str(), 
s2->data());
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 
'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("{} {} {} {}", s1, s1, *s2, *s2);
+}
+
+std::string StrFormat_strict_conversion() {
+  const unsigned char uc = 'A';
+  return absl::StrFormat("Integer %hhd from unsigned char\n", uc);
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 
'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("Integer {} from unsigned char\n", uc);
+}
+
+std::string StrFormat_field_width_and_precision() {
+  auto s1 = absl::StrFormat("width only:%*d width and precision:%*.*f 
precision only:%.*f", 3, 42, 4, 2, 3.14159265358979323846, 5, 2.718);
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use 'std::format' instead of 
'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: std::format("width only:{:{}} width and precision:{:{}.{}f} 
precision only:{:.{}f}", 42, 3, 3.14159265358979323846, 4, 2, 2.718, 5);
+
+  auto s2 = absl::StrFormat("width and precision positional:%1$*2$.*3$f 
after", 3.14159265358979323846, 4, 2);
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use 'std::format' instead of 
'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: std::format("width and precision positional:{0:{1}.{2}f} 
after", 3.14159265358979323846, 4, 2);
+
+  const int width = 10, precision = 3;
+  const unsigned int ui1 = 42, ui2 = 43, ui3 = 44;
+  auto s3 = absl::StrFormat("casts width only:%*d width and precision:%*.*d 
precision only:%.*d\n", 3, ui1, 4, 2, ui2, 5, ui3);
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use 'std::format' instead of 
'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES-NOTSTRICT: std::format("casts width only:{:{}} width and 
precision:{:{}.{}} precision only:{:.{}}", ui1, 3, ui2, 4, 2, ui3, 5);
+  // CHECK-FIXES-STRICT: std::format("casts width only:{:{}} width and 
precision:{:{}.{}} precision only:{:.{}}", static_cast(ui1), 3, 
static_cast(ui2), 4, 2, static_cast(ui3), 5);
+
+  auto s4 = absl::StrFormat("c_str removal width only:%*s width and 
precision:%*.*s precision only:%.*s", 3, s1.c_str(), 4, 2, s2.c_str(), 5, 
s3.c_str());
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use 'std::format' instead of 
'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: std::format("c_str removal width only:{:>{}} width and 
precision:{:>{}.{}} precision only:{:.{}}", s1, 3, s2, 4, 2, s3, 5);
+
+  const std::string *ps1 = &s1, *ps2 = &s2, *ps3 = &s3;
+  auto s5 = absl::StrFormat("c_str() removal pointer width only:%-*s width and 
precision:%-*.*s precision only:%-.*s", 3, ps1->c_str()

[clang-tools-extra] [clang-tidy] Add modernize-use-std-format check (PR #90397)

2024-04-28 Thread Mike Crowe via cfe-commits


@@ -0,0 +1,108 @@
+//===--- UseStdFormatCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseStdFormatCheck.h"
+#include "../utils/FormatStringConverter.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/FixIt.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+namespace {
+AST_MATCHER(StringLiteral, isOrdinary) { return Node.isOrdinary(); }
+} // namespace
+
+UseStdFormatCheck::UseStdFormatCheck(StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StrictMode(Options.getLocalOrGlobal("StrictMode", false)),
+  StrFormatLikeFunctions(utils::options::parseStringList(
+  Options.get("StrFormatLikeFunctions", ""))),
+  ReplacementFormatFunction(
+  Options.get("ReplacementFormatFunction", "std::format")),
+  IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
+   utils::IncludeSorter::IS_LLVM),
+  areDiagsSelfContained()),
+  MaybeHeaderToInclude(Options.get("FormatHeader")) {
+  if (StrFormatLikeFunctions.empty())
+StrFormatLikeFunctions.push_back("absl::StrFormat");
+
+  if (!MaybeHeaderToInclude && ReplacementFormatFunction == "std::format")
+MaybeHeaderToInclude = "";
+}
+
+void UseStdFormatCheck::registerPPCallbacks(const SourceManager &SM,
+Preprocessor *PP,
+Preprocessor *ModuleExpanderPP) {
+  IncludeInserter.registerPreprocessor(PP);
+}
+
+void UseStdFormatCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(argumentCountAtLeast(1),
+   hasArgument(0, stringLiteral(isOrdinary())),
+   callee(functionDecl(unless(cxxMethodDecl()),
+   matchers::matchesAnyListedName(
+   StrFormatLikeFunctions))
+  .bind("func_decl")))
+  .bind("strformat"),
+  this);
+}
+
+void UseStdFormatCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  using utils::options::serializeStringList;
+  Options.store(Opts, "StrictMode", StrictMode);
+  Options.store(Opts, "StrFormatLikeFunctions",
+serializeStringList(StrFormatLikeFunctions));
+  Options.store(Opts, "ReplacementFormatFunction", ReplacementFormatFunction);
+  Options.store(Opts, "IncludeStyle", IncludeInserter.getStyle());
+  if (MaybeHeaderToInclude)
+Options.store(Opts, "FormatHeader", *MaybeHeaderToInclude);
+}
+
+void UseStdFormatCheck::check(const MatchFinder::MatchResult &Result) {
+  const unsigned FormatArgOffset = 0;
+  const auto *OldFunction = Result.Nodes.getNodeAs("func_decl");
+  const auto *StrFormat = Result.Nodes.getNodeAs("strformat");
+
+  utils::FormatStringConverter::Configuration ConverterConfig;
+  ConverterConfig.StrictMode = StrictMode;
+  utils::FormatStringConverter Converter(Result.Context, StrFormat,
+ FormatArgOffset, ConverterConfig,
+ getLangOpts());
+  const Expr *StrFormatCall = StrFormat->getCallee();
+  if (!Converter.canApply()) {
+DiagnosticBuilder Diag = diag(StrFormat->getBeginLoc(),
+  "unable to use '%0' instead of %1 because 
%2")
+ << ReplacementFormatFunction
+ << OldFunction->getIdentifier()
+ << Converter.conversionNotPossibleReason();
+return;
+  }
+
+  DiagnosticBuilder Diag =
+  diag(StrFormatCall->getBeginLoc(), "use '%0' instead of %1")
+  << ReplacementFormatFunction << OldFunction->getIdentifier();

mikecrowe wrote:

It's been a while, but I think that was intentional. Just using `OldFunction` 
includes the template arguments which results in unnecessarily-specific warning 
messages like
`warning: use 'fmt::format' instead of 'sprintf' 
[modernize-use-std-format]`
and `warning: use 'std::format' instead of 'StrFormat' 
[modernize-use-std-format]`. Whereas using `OldFunction->getIdentifier()` 
results in the more readable `warning: use 'fmt::format' instead of 'sprintf' 
[modernize-use-std-format]` and `warning: use 'std::format' instead of 
'StrFormat' [modernize-use-std-format]`.

Ideally these messages would say `warning: use 'fmt::format' instead of 
'fmt::sprintf' [modernize-use-std-format]` and `warning: use 'std::format' 
instead of 'absl::StrFormat' [modernize-use-std-format]` (i.e. qualifying 

[clang] 8ad092f - [cc1as] Respect -mrelax-all

2024-04-28 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2024-04-28T09:42:43-07:00
New Revision: 8ad092f126bd1d6f9fe6006eba1e3115a080235e

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

LOG: [cc1as] Respect -mrelax-all

So that `clang -c -mrelax-all a.s` sets MCRelaxAll and assembles JMP/JCC
to a near jump instead of silently ignoring `-mrelax-all`.

Added: 
clang/test/Misc/cc1as-relax-all.s

Modified: 
clang/tools/driver/cc1as_main.cpp

Removed: 




diff  --git a/clang/test/Misc/cc1as-relax-all.s 
b/clang/test/Misc/cc1as-relax-all.s
new file mode 100644
index 00..e76fc6f61babb9
--- /dev/null
+++ b/clang/test/Misc/cc1as-relax-all.s
@@ -0,0 +1,13 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang -cc1as -triple x86_64 -filetype obj -mrelax-all %s -o %t.o
+// RUN: llvm-objdump -d %t.o | FileCheck %s
+
+// CHECK:  <.text>:
+// CHECK-NEXT:   0: e9 06 00 00 00jmp 0xb 
+// CHECK-NEXT:   5: 0f 84 00 00 00 00 je  0xb 
+// CHECK-EMPTY:
+
+jmp foo
+je foo
+
+foo: ret

diff  --git a/clang/tools/driver/cc1as_main.cpp 
b/clang/tools/driver/cc1as_main.cpp
index 5498c3f9d4a20d..86afe22fac24cc 100644
--- a/clang/tools/driver/cc1as_main.cpp
+++ b/clang/tools/driver/cc1as_main.cpp
@@ -426,6 +426,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
   assert(MRI && "Unable to create target register info!");
 
   MCTargetOptions MCOptions;
+  MCOptions.MCRelaxAll = Opts.RelaxAll;
   MCOptions.EmitDwarfUnwind = Opts.EmitDwarfUnwind;
   MCOptions.EmitCompactUnwindNonCanonical = Opts.EmitCompactUnwindNonCanonical;
   MCOptions.X86RelaxRelocations = Opts.RelaxELFRelocations;



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


[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-04-28 Thread Alex Voicu via cfe-commits


@@ -6088,6 +6088,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   StringRef Prefix =
   llvm::Triple::getArchTypePrefix(getTarget().getTriple().getArch());
   if (!Prefix.empty()) {
+if (Prefix == "spv" &&
+getTarget().getTriple().getOS() == llvm::Triple::OSType::AMDHSA)
+  Prefix = "amdgcn";

AlexVlx wrote:

I don't quite see any other point to tweak the logic. We have some `amdgcn` 
builtins that get handled here, as opposed to via `EmitTargetBuiltinExpr`, and 
this is the narrowest scope for adjusting `Prefix`; the information that this 
is coming from AMDGCN flavoured SPIRV is lost past this point. Did you have 
something in mind regarding where to handle this as an alternative?

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


[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-04-28 Thread Joseph Huber via cfe-commits


@@ -6088,6 +6088,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   StringRef Prefix =
   llvm::Triple::getArchTypePrefix(getTarget().getTriple().getArch());
   if (!Prefix.empty()) {
+if (Prefix == "spv" &&
+getTarget().getTriple().getOS() == llvm::Triple::OSType::AMDHSA)
+  Prefix = "amdgcn";

jhuber6 wrote:

So I was just wondering if it would make more sense to put this in 
`Triple::getArchTypePrefix(ArchType Kind)` because I wasn't sure if this logic 
is the expected return value there.

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


[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-04-28 Thread Alex Voicu via cfe-commits


@@ -6088,6 +6088,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   StringRef Prefix =
   llvm::Triple::getArchTypePrefix(getTarget().getTriple().getArch());
   if (!Prefix.empty()) {
+if (Prefix == "spv" &&
+getTarget().getTriple().getOS() == llvm::Triple::OSType::AMDHSA)
+  Prefix = "amdgcn";

AlexVlx wrote:

I don't think we can, with the current signature of that interface / the 
current approach of keeping `spirv64` as the prefix, since we need at least the 
OS type as well to disambiguate. So it'd require either overloading that 
interface, or using a different prefix (this'd ripple elsewhere).

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


[clang-tools-extra] [clang-tidy] Added bugprone-exception-rethrow check (PR #86448)

2024-04-28 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,60 @@
+// RUN: %check_clang_tidy %s bugprone-exception-rethrow %t -- -- -fexceptions
+
+struct exception {};
+
+void correct() {
+  try {
+  throw exception();
+  } catch(const exception &) {
+  throw;
+  }
+}
+
+void correct2() {
+  try {
+  throw exception();
+  } catch(const exception &e) {
+  try {
+throw exception();
+  } catch(...) {}
+  }
+}
+
+void not_correct() {
+  try {
+  throw exception();
+  } catch(const exception &e) {
+  throw e;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: throwing a copy of the caught 
'exception' exception, remove the argument to throw the original exception 
object [bugprone-exception-rethrow]
+  }
+}
+
+void not_correct2() {
+  try {
+  throw 5;
+  } catch(const int &e) {
+  throw e;
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: throwing a copy of the caught 
'int' exception, remove the argument to throw the original exception object 
[bugprone-exception-rethrow]
+  }
+}
+
+void rethrow_not_correct() {
+  throw;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: empty 'throw' outside a catch 
block without an exception can trigger 'std::terminate' 
[bugprone-exception-rethrow]
+}
+
+void rethrow_not_correct2() {
+  try {
+throw;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: empty 'throw' outside a catch 
block without an exception can trigger 'std::terminate' 
[bugprone-exception-rethrow]
+  } catch(...) {
+  }
+}
+
+void rethrow_correct() {
+  try {
+throw 5;
+  } catch(...) {
+throw;
+  }
+}

PiotrZSL wrote:

added handling for some of them, those indirect like ref there is no point to 
handle.

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


[clang-tools-extra] [clang-tidy] Added bugprone-exception-rethrow check (PR #86448)

2024-04-28 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,50 @@
+//===--- ExceptionRethrowCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ExceptionRethrowCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+AST_MATCHER(VarDecl, isExceptionVariable) { return Node.isExceptionVariable(); 
}
+} // namespace
+
+void ExceptionRethrowCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  cxxThrowExpr(unless(isExpansionInSystemHeader()),
+   anyOf(unless(has(expr())),
+ has(declRefExpr(to(varDecl(isExceptionVariable()),
+   optionally(hasAncestor(cxxCatchStmt().bind("catch"
+  .bind("throw"),
+  this);
+}
+
+void ExceptionRethrowCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *MatchedThrow = Result.Nodes.getNodeAs("throw");
+
+  if (const Expr *ThrownObject = MatchedThrow->getSubExpr()) {
+diag(MatchedThrow->getThrowLoc(),
+ "throwing a copy of the caught %0 exception, remove the argument to "
+ "throw the original exception object")
+<< ThrownObject->getType().getNonReferenceType();
+return;
+  }
+
+  const bool HasCatchAnsestor =
+  Result.Nodes.getNodeAs("catch") != nullptr;
+  if (!HasCatchAnsestor) {
+diag(MatchedThrow->getThrowLoc(),
+ "empty 'throw' outside a catch block without an exception can trigger 
"
+ "'std::terminate'");

PiotrZSL wrote:

done

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


[clang-tools-extra] [clang-tidy] Added bugprone-exception-rethrow check (PR #86448)

2024-04-28 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,37 @@
+//===--- ExceptionRethrowCheck.h - clang-tidy ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_EXCEPTIONRETHROWCHECK_H

PiotrZSL wrote:

done

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


[clang-tools-extra] [clang-tidy] Added bugprone-exception-rethrow check (PR #86448)

2024-04-28 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,50 @@
+//===--- ExceptionRethrowCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ExceptionRethrowCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+AST_MATCHER(VarDecl, isExceptionVariable) { return Node.isExceptionVariable(); 
}
+} // namespace
+
+void ExceptionRethrowCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  cxxThrowExpr(unless(isExpansionInSystemHeader()),
+   anyOf(unless(has(expr())),
+ has(declRefExpr(to(varDecl(isExceptionVariable()),
+   optionally(hasAncestor(cxxCatchStmt().bind("catch"
+  .bind("throw"),
+  this);
+}
+
+void ExceptionRethrowCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *MatchedThrow = Result.Nodes.getNodeAs("throw");
+
+  if (const Expr *ThrownObject = MatchedThrow->getSubExpr()) {
+diag(MatchedThrow->getThrowLoc(),
+ "throwing a copy of the caught %0 exception, remove the argument to "
+ "throw the original exception object")
+<< ThrownObject->getType().getNonReferenceType();
+return;
+  }
+
+  const bool HasCatchAnsestor =

PiotrZSL wrote:

done

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


[clang-tools-extra] [clang-tidy] Added bugprone-exception-rethrow check (PR #86448)

2024-04-28 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,50 @@
+//===--- ExceptionRethrowCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ExceptionRethrowCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+AST_MATCHER(VarDecl, isExceptionVariable) { return Node.isExceptionVariable(); 
}
+} // namespace
+
+void ExceptionRethrowCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  cxxThrowExpr(unless(isExpansionInSystemHeader()),
+   anyOf(unless(has(expr())),
+ has(declRefExpr(to(varDecl(isExceptionVariable()),
+   optionally(hasAncestor(cxxCatchStmt().bind("catch"
+  .bind("throw"),
+  this);
+}
+
+void ExceptionRethrowCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *MatchedThrow = Result.Nodes.getNodeAs("throw");
+
+  if (const Expr *ThrownObject = MatchedThrow->getSubExpr()) {
+diag(MatchedThrow->getThrowLoc(),
+ "throwing a copy of the caught %0 exception, remove the argument to "
+ "throw the original exception object")
+<< ThrownObject->getType().getNonReferenceType();
+return;
+  }
+
+  const bool HasCatchAnsestor =
+  Result.Nodes.getNodeAs("catch") != nullptr;
+  if (!HasCatchAnsestor) {
+diag(MatchedThrow->getThrowLoc(),

PiotrZSL wrote:

No fixes possible, user need to decide how to handle this.

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


[clang-tools-extra] [clang-tidy] Added bugprone-exception-rethrow check (PR #86448)

2024-04-28 Thread Piotr Zegar via cfe-commits


@@ -0,0 +1,50 @@
+//===--- ExceptionRethrowCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ExceptionRethrowCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+AST_MATCHER(VarDecl, isExceptionVariable) { return Node.isExceptionVariable(); 
}

PiotrZSL wrote:

done

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


[clang-tools-extra] [clang-tidy] Added bugprone-exception-rethrow check (PR #86448)

2024-04-28 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL updated 
https://github.com/llvm/llvm-project/pull/86448

>From 1b5c351acca7375c577111a4c55506146ef108ef Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Sun, 24 Mar 2024 18:39:54 +
Subject: [PATCH 1/4] [clang-tidy] Added bugprone-exception-rethrow check

Identifies problematic exception rethrowing, especially with caught
exception variables or empty throw statements outside catch blocks.

Closes #71292
---
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../bugprone/ExceptionRethrowCheck.cpp| 50 ++
 .../bugprone/ExceptionRethrowCheck.h  | 37 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../checks/bugprone/exception-rethrow.rst | 68 +++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../checkers/bugprone/exception-rethrow.cpp   | 60 
 8 files changed, 226 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/ExceptionRethrowCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/ExceptionRethrowCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-rethrow.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-rethrow.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 1b92d2e60cc173..7466d3f2e4fc27 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -26,6 +26,7 @@
 #include "EasilySwappableParametersCheck.h"
 #include "EmptyCatchCheck.h"
 #include "ExceptionEscapeCheck.h"
+#include "ExceptionRethrowCheck.h"
 #include "FoldInitTypeCheck.h"
 #include "ForwardDeclarationNamespaceCheck.h"
 #include "ForwardingReferenceOverloadCheck.h"
@@ -127,6 +128,8 @@ class BugproneModule : public ClangTidyModule {
 CheckFactories.registerCheck("bugprone-empty-catch");
 CheckFactories.registerCheck(
 "bugprone-exception-escape");
+CheckFactories.registerCheck(
+"bugprone-exception-rethrow");
 CheckFactories.registerCheck("bugprone-fold-init-type");
 CheckFactories.registerCheck(
 "bugprone-forward-declaration-namespace");
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 2d303191f88650..345ae420398e65 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -20,6 +20,7 @@ add_clang_library(clangTidyBugproneModule
   EasilySwappableParametersCheck.cpp
   EmptyCatchCheck.cpp
   ExceptionEscapeCheck.cpp
+  ExceptionRethrowCheck.cpp
   FoldInitTypeCheck.cpp
   ForwardDeclarationNamespaceCheck.cpp
   ForwardingReferenceOverloadCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/bugprone/ExceptionRethrowCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ExceptionRethrowCheck.cpp
new file mode 100644
index 00..4855ccc2724a92
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/ExceptionRethrowCheck.cpp
@@ -0,0 +1,50 @@
+//===--- ExceptionRethrowCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ExceptionRethrowCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+AST_MATCHER(VarDecl, isExceptionVariable) { return Node.isExceptionVariable(); 
}
+} // namespace
+
+void ExceptionRethrowCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  cxxThrowExpr(unless(isExpansionInSystemHeader()),
+   anyOf(unless(has(expr())),
+ has(declRefExpr(to(varDecl(isExceptionVariable()),
+   optionally(hasAncestor(cxxCatchStmt().bind("catch"
+  .bind("throw"),
+  this);
+}
+
+void ExceptionRethrowCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *MatchedThrow = Result.Nodes.getNodeAs("throw");
+
+  if (const Expr *ThrownObject = MatchedThrow->getSubExpr()) {
+diag(MatchedThrow->getThrowLoc(),
+ "throwing a copy of the caught %0 exception, remove the argument to "
+ "throw the original exception object")
+<< ThrownObject->getType().getNonReferenceType();
+return;
+  }
+
+  const bool HasCatchAnsestor =
+  Result.Nodes.getNodeAs("catch") != nullptr;
+  if (!HasCatchAnsestor) {
+diag(MatchedThrow->getThrowLoc(),
+ "empty 'throw' outside a catch block without an exception can trigger 
"
+ "'std::terminate'");

[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-04-28 Thread Joseph Huber via cfe-commits


@@ -309,7 +309,45 @@ StringRef AMDGPU::getCanonicalArchName(const Triple &T, 
StringRef Arch) {
 void AMDGPU::fillAMDGPUFeatureMap(StringRef GPU, const Triple &T,
   StringMap &Features) {
   // XXX - What does the member GPU mean if device name string passed here?
-  if (T.isAMDGCN()) {
+  if (T.isSPIRV() && T.getOS() == Triple::OSType::AMDHSA) {
+// AMDGCN SPIRV must support the union of all AMDGCN features.
+Features["atomic-ds-pk-add-16-insts"] = true;
+Features["atomic-flat-pk-add-16-insts"] = true;
+Features["atomic-buffer-global-pk-add-f16-insts"] = true;
+Features["atomic-global-pk-add-bf16-inst"] = true;
+Features["atomic-fadd-rtn-insts"] = true;
+Features["ci-insts"] = true;
+Features["dot1-insts"] = true;
+Features["dot2-insts"] = true;
+Features["dot3-insts"] = true;
+Features["dot4-insts"] = true;
+Features["dot5-insts"] = true;
+Features["dot7-insts"] = true;
+Features["dot8-insts"] = true;
+Features["dot9-insts"] = true;
+Features["dot10-insts"] = true;
+Features["dot11-insts"] = true;
+Features["dl-insts"] = true;
+Features["16-bit-insts"] = true;
+Features["dpp"] = true;
+Features["gfx8-insts"] = true;
+Features["gfx9-insts"] = true;
+Features["gfx90a-insts"] = true;
+Features["gfx940-insts"] = true;
+Features["gfx10-insts"] = true;
+Features["gfx10-3-insts"] = true;
+Features["gfx11-insts"] = true;
+Features["gfx12-insts"] = true;

jhuber6 wrote:

What do these features even mean in the context of SPIR-V? It's basically a 
format for JIT, so can we really say stuff like GFX12 is available?

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


[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-04-28 Thread Alex Voicu via cfe-commits


@@ -309,7 +309,45 @@ StringRef AMDGPU::getCanonicalArchName(const Triple &T, 
StringRef Arch) {
 void AMDGPU::fillAMDGPUFeatureMap(StringRef GPU, const Triple &T,
   StringMap &Features) {
   // XXX - What does the member GPU mean if device name string passed here?
-  if (T.isAMDGCN()) {
+  if (T.isSPIRV() && T.getOS() == Triple::OSType::AMDHSA) {
+// AMDGCN SPIRV must support the union of all AMDGCN features.
+Features["atomic-ds-pk-add-16-insts"] = true;
+Features["atomic-flat-pk-add-16-insts"] = true;
+Features["atomic-buffer-global-pk-add-f16-insts"] = true;
+Features["atomic-global-pk-add-bf16-inst"] = true;
+Features["atomic-fadd-rtn-insts"] = true;
+Features["ci-insts"] = true;
+Features["dot1-insts"] = true;
+Features["dot2-insts"] = true;
+Features["dot3-insts"] = true;
+Features["dot4-insts"] = true;
+Features["dot5-insts"] = true;
+Features["dot7-insts"] = true;
+Features["dot8-insts"] = true;
+Features["dot9-insts"] = true;
+Features["dot10-insts"] = true;
+Features["dot11-insts"] = true;
+Features["dl-insts"] = true;
+Features["16-bit-insts"] = true;
+Features["dpp"] = true;
+Features["gfx8-insts"] = true;
+Features["gfx9-insts"] = true;
+Features["gfx90a-insts"] = true;
+Features["gfx940-insts"] = true;
+Features["gfx10-insts"] = true;
+Features["gfx10-3-insts"] = true;
+Features["gfx11-insts"] = true;
+Features["gfx12-insts"] = true;

AlexVlx wrote:

One can neither say it's available nor say it's not, it's undecidable at SPIRV 
generation time (if we knew, we'd not need it in the first place and would've 
just targeted the actual hardware). The idea is that AMDGCN SPIRV will 
"support" the union of AMDGCN features, so that the associated builtins / 
constructs are retained in the generated SPIRV. Afterwards, at JIT time, one 
handles matching to the actual physical target that is present; this is done 
via a piece of paired functionality in the ME which has not yet been submitted.

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


[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-04-28 Thread Joseph Huber via cfe-commits


@@ -309,7 +309,45 @@ StringRef AMDGPU::getCanonicalArchName(const Triple &T, 
StringRef Arch) {
 void AMDGPU::fillAMDGPUFeatureMap(StringRef GPU, const Triple &T,
   StringMap &Features) {
   // XXX - What does the member GPU mean if device name string passed here?
-  if (T.isAMDGCN()) {
+  if (T.isSPIRV() && T.getOS() == Triple::OSType::AMDHSA) {
+// AMDGCN SPIRV must support the union of all AMDGCN features.
+Features["atomic-ds-pk-add-16-insts"] = true;
+Features["atomic-flat-pk-add-16-insts"] = true;
+Features["atomic-buffer-global-pk-add-f16-insts"] = true;
+Features["atomic-global-pk-add-bf16-inst"] = true;
+Features["atomic-fadd-rtn-insts"] = true;
+Features["ci-insts"] = true;
+Features["dot1-insts"] = true;
+Features["dot2-insts"] = true;
+Features["dot3-insts"] = true;
+Features["dot4-insts"] = true;
+Features["dot5-insts"] = true;
+Features["dot7-insts"] = true;
+Features["dot8-insts"] = true;
+Features["dot9-insts"] = true;
+Features["dot10-insts"] = true;
+Features["dot11-insts"] = true;
+Features["dl-insts"] = true;
+Features["16-bit-insts"] = true;
+Features["dpp"] = true;
+Features["gfx8-insts"] = true;
+Features["gfx9-insts"] = true;
+Features["gfx90a-insts"] = true;
+Features["gfx940-insts"] = true;
+Features["gfx10-insts"] = true;
+Features["gfx10-3-insts"] = true;
+Features["gfx11-insts"] = true;
+Features["gfx12-insts"] = true;

jhuber6 wrote:

I see, so it's basically just pushing any target specific errors into when it's 
actually compiled to a binary.

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


[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-04-28 Thread Joseph Huber via cfe-commits


@@ -54,3 +56,76 @@ void SPIRV64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   BaseSPIRVTargetInfo::getTargetDefines(Opts, Builder);
   DefineStd(Builder, "SPIRV64", Opts);
 }
+
+static const AMDGPUTargetInfo AMDGPUTI(llvm::Triple("amdgcn-amd-amdhsa"), {});
+
+ArrayRef SPIRV64AMDGCNTargetInfo::getGCCRegNames() const {
+  return AMDGPUTI.getGCCRegNames();
+}
+
+bool SPIRV64AMDGCNTargetInfo::initFeatureMap(
+llvm::StringMap &Features, DiagnosticsEngine &Diags, StringRef,
+const std::vector &FeatureVec) const {
+  llvm::AMDGPU::fillAMDGPUFeatureMap({}, getTriple(), Features);
+
+  return TargetInfo::initFeatureMap(Features, Diags, {}, FeatureVec);
+}
+
+bool SPIRV64AMDGCNTargetInfo::validateAsmConstraint(
+const char *&Name, TargetInfo::ConstraintInfo &Info) const {
+  return AMDGPUTI.validateAsmConstraint(Name, Info);
+}
+
+std::string
+SPIRV64AMDGCNTargetInfo::convertConstraint(const char *&Constraint) const {
+  return AMDGPUTI.convertConstraint(Constraint);
+}
+
+ArrayRef SPIRV64AMDGCNTargetInfo::getTargetBuiltins() const {
+  return AMDGPUTI.getTargetBuiltins();
+}
+
+void SPIRV64AMDGCNTargetInfo::getTargetDefines(const LangOptions &Opts,
+   MacroBuilder &Builder) const {
+  BaseSPIRVTargetInfo::getTargetDefines(Opts, Builder);
+  DefineStd(Builder, "SPIRV64", Opts);
+
+  Builder.defineMacro("__AMD__");
+  Builder.defineMacro("__AMDGPU__");
+  Builder.defineMacro("__AMDGCN__");

jhuber6 wrote:

Are these defined on both the host and device? I remember having a quite 
annoying time with these macros because HIP was defining stuff like 
`__AMDGCN_WAVEFRONT_SIZE` on the host.

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


[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-04-28 Thread Alex Voicu via cfe-commits


@@ -54,3 +56,76 @@ void SPIRV64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   BaseSPIRVTargetInfo::getTargetDefines(Opts, Builder);
   DefineStd(Builder, "SPIRV64", Opts);
 }
+
+static const AMDGPUTargetInfo AMDGPUTI(llvm::Triple("amdgcn-amd-amdhsa"), {});
+
+ArrayRef SPIRV64AMDGCNTargetInfo::getGCCRegNames() const {
+  return AMDGPUTI.getGCCRegNames();
+}
+
+bool SPIRV64AMDGCNTargetInfo::initFeatureMap(
+llvm::StringMap &Features, DiagnosticsEngine &Diags, StringRef,
+const std::vector &FeatureVec) const {
+  llvm::AMDGPU::fillAMDGPUFeatureMap({}, getTriple(), Features);
+
+  return TargetInfo::initFeatureMap(Features, Diags, {}, FeatureVec);
+}
+
+bool SPIRV64AMDGCNTargetInfo::validateAsmConstraint(
+const char *&Name, TargetInfo::ConstraintInfo &Info) const {
+  return AMDGPUTI.validateAsmConstraint(Name, Info);
+}
+
+std::string
+SPIRV64AMDGCNTargetInfo::convertConstraint(const char *&Constraint) const {
+  return AMDGPUTI.convertConstraint(Constraint);
+}
+
+ArrayRef SPIRV64AMDGCNTargetInfo::getTargetBuiltins() const {
+  return AMDGPUTI.getTargetBuiltins();
+}
+
+void SPIRV64AMDGCNTargetInfo::getTargetDefines(const LangOptions &Opts,
+   MacroBuilder &Builder) const {
+  BaseSPIRVTargetInfo::getTargetDefines(Opts, Builder);
+  DefineStd(Builder, "SPIRV64", Opts);
+
+  Builder.defineMacro("__AMD__");
+  Builder.defineMacro("__AMDGPU__");
+  Builder.defineMacro("__AMDGCN__");

AlexVlx wrote:

`__AMDGCN_WAVEFRONT_SIZE` is a pretty terrible error, which should never have 
been defined on host (not in the least because it's non-uniform across 
targets). These do (should) end up defined on host too, but they are harmless 
because they are uniform i.e. all potential consumers of `spirv64-amd-amdhsa` 
are `__AMD__`, `__AMDGPU__` and `__AMDGCN__`. They're mostly a necessary 
nuisance for getting library code to work.

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


[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-04-28 Thread Joseph Huber via cfe-commits


@@ -54,3 +56,76 @@ void SPIRV64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   BaseSPIRVTargetInfo::getTargetDefines(Opts, Builder);
   DefineStd(Builder, "SPIRV64", Opts);
 }
+
+static const AMDGPUTargetInfo AMDGPUTI(llvm::Triple("amdgcn-amd-amdhsa"), {});
+
+ArrayRef SPIRV64AMDGCNTargetInfo::getGCCRegNames() const {
+  return AMDGPUTI.getGCCRegNames();
+}
+
+bool SPIRV64AMDGCNTargetInfo::initFeatureMap(
+llvm::StringMap &Features, DiagnosticsEngine &Diags, StringRef,
+const std::vector &FeatureVec) const {
+  llvm::AMDGPU::fillAMDGPUFeatureMap({}, getTriple(), Features);
+
+  return TargetInfo::initFeatureMap(Features, Diags, {}, FeatureVec);
+}
+
+bool SPIRV64AMDGCNTargetInfo::validateAsmConstraint(
+const char *&Name, TargetInfo::ConstraintInfo &Info) const {
+  return AMDGPUTI.validateAsmConstraint(Name, Info);
+}
+
+std::string
+SPIRV64AMDGCNTargetInfo::convertConstraint(const char *&Constraint) const {
+  return AMDGPUTI.convertConstraint(Constraint);
+}
+
+ArrayRef SPIRV64AMDGCNTargetInfo::getTargetBuiltins() const {
+  return AMDGPUTI.getTargetBuiltins();
+}
+
+void SPIRV64AMDGCNTargetInfo::getTargetDefines(const LangOptions &Opts,
+   MacroBuilder &Builder) const {
+  BaseSPIRVTargetInfo::getTargetDefines(Opts, Builder);
+  DefineStd(Builder, "SPIRV64", Opts);
+
+  Builder.defineMacro("__AMD__");
+  Builder.defineMacro("__AMDGPU__");
+  Builder.defineMacro("__AMDGCN__");

jhuber6 wrote:

I've always thought defining those for both targets was obtuse, since those 
should act like architecture macros, i.e. (__X86__). But considering this is 
how it's done already, I suppose it's a necessary evil.

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


[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-04-28 Thread Joseph Huber via cfe-commits

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

LG

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


[clang] 6dd9061 - [Clang] Implement C++26 Attributes for Structured Bindings (P0609R3) (#89906)

2024-04-28 Thread via cfe-commits

Author: cor3ntin
Date: 2024-04-28T20:25:44+02:00
New Revision: 6dd90616c477d83c156eed62c880e951bb508cfd

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

LOG: [Clang] Implement C++26 Attributes for Structured Bindings (P0609R3) 
(#89906)

https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p0609r3.pdf

We support this feature in all language mode.

maybe_unused applied to a binding makes the whole declaration unused.

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Sema/DeclSpec.h
clang/include/clang/Sema/ParsedAttr.h
clang/lib/AST/DeclBase.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Parse/ParseDecl.cpp
clang/lib/Sema/DeclSpec.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/Lexer/cxx-features.cpp
clang/test/Parser/cxx1z-decomposition.cpp
clang/test/SemaCXX/unused.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index f18b946efd4bfa1..127d1b6dd48252e 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1493,6 +1493,7 @@ Conditional ``explicit`` 
__cpp_conditional_explicit   C+
 ``if consteval`` __cpp_if_consteval   
C++23 C++20
 ``static operator()``__cpp_static_call_operator   
C++23 C++03
 Attributes on Lambda-Expressions  
C++23 C++11
+Attributes on Structured Bindings__cpp_structured_bindings
C++26 C++03
 ``= delete ("should have a reason");``   __cpp_deleted_function   
C++26 C++03
   
- -
 Designated initializers (N494)
C99   C89

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a1390d6536b28cc..64a523a6f25fc2f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -143,6 +143,8 @@ C++2c Feature Support
 
 - Implemented `P2573R2: = delete("should have a reason"); 
`_
 
+- Implemented `P0609R3: Attributes for Structured Bindings 
`_
+
 
 Resolutions to C++ Defect Reports
 ^

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 4408d517e70e588..97e06fe7d2e6aa5 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3211,7 +3211,7 @@ def ObjCRequiresPropertyDefs : InheritableAttr {
 def Unused : InheritableAttr {
   let Spellings = [CXX11<"", "maybe_unused", 201603>, GCC<"unused">,
C23<"", "maybe_unused", 202106>];
-  let Subjects = SubjectList<[Var, ObjCIvar, Type, Enum, EnumConstant, Label,
+  let Subjects = SubjectList<[Var, Binding, ObjCIvar, Type, Enum, 
EnumConstant, Label,
   Field, ObjCMethod, FunctionLike]>;
   let Documentation = [WarnMaybeUnusedDocs];
 }

diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 38174cf3549f14e..fdffb35ea0d9554 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -478,6 +478,15 @@ def ext_decomp_decl_empty : ExtWarn<
   "ISO C++17 does not allow a decomposition group to be empty">,
   InGroup>;
 
+// C++26 structured bindings
+def ext_decl_attrs_on_binding : ExtWarn<
+  "an attribute specifier sequence attached to a structured binding 
declaration "
+  "is a C++2c extension">, InGroup;
+def warn_cxx23_compat_decl_attrs_on_binding : Warning<
+  "an attribute specifier sequence attached to a structured binding 
declaration "
+  "is incompatible with C++ standards before C++2c">,
+  InGroup, DefaultIgnore;
+
 /// Objective-C parser diagnostics
 def err_expected_minus_or_plus : Error<
   "method type specifier must start with '-' or '+'">;

diff  --git a/clang/include/clang/Sema/DeclSpec.h 
b/clang/include/clang/Sema/DeclSpec.h
index c9eecdafe62c7ce..760c7980be52bd6 100644
--- a/clang/include/clang/Sema/DeclSpec.h
+++ b/clang/include/clang/Sema/DeclSpec.h
@@ -36,6 +36,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
+#include 
 
 namespace clang {
   class ASTContext;
@@ -1790,6 +1791,7 @@ class DecompositionDeclarator {
   struct Binding {
 IdentifierInfo *Name;
 So

[clang] [Clang] Implement C++26 Attributes for Structured Bindings (P0609R3) (PR #89906)

2024-04-28 Thread via cfe-commits

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


[clang] [clang-format][NFC] Return early in isWordLike() for non-Verilog (PR #90363)

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

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


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


[clang] [clang-format] Set Change.TokenLength to ColumnWidth (PR #90378)

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

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


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


[clang-tools-extra] [clang-tidy] Ignore unevaluated context in bugprone-optional-value-conversion (PR #90410)

2024-04-28 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/90410

Ignore optionals in unevaluated context, like static_assert or decltype.

Closes #89593

>From 7dcbe220d74f2be4ade8429e6c0e710d7d7c58a4 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Sun, 28 Apr 2024 19:16:43 +
Subject: [PATCH] [clang-tidy] Ignore unevaluated context in
 bugprone-optional-value-conversion

Ignore optionals in unevaluated context, like static_assert or decltype.

Closes #89593
---
 .../clang-tidy/bugprone/OptionalValueConversionCheck.cpp  | 4 +++-
 clang-tools-extra/docs/ReleaseNotes.rst   | 4 
 .../checkers/bugprone/optional-value-conversion.cpp   | 2 ++
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp
index 9ab59e6b0474f0..600eab37552766 100644
--- a/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp
@@ -71,7 +71,9 @@ void 
OptionalValueConversionCheck::registerMatchers(MatchFinder *Finder) {
   ofClass(matchers::matchesAnyListedName(OptionalTypes,
   hasType(ConstructTypeMatcher),
   hasArgument(0U, ignoringImpCasts(anyOf(OptionalDereferenceMatcher,
- StdMoveCallMatcher
+ StdMoveCallMatcher))),
+  unless(anyOf(hasAncestor(typeLoc()),
+   hasAncestor(expr(matchers::hasUnevaluatedContext())
   .bind("expr"),
   this);
 }
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 3038d2b125f20d..062e619e0fe141 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -190,6 +190,10 @@ Changes in existing checks
   eliminating false positives resulting from direct usage of bitwise operators
   within parentheses.
 
+- Improved :doc:`bugprone-optional-value-conversion
+  ` check by eliminating
+  false positives resulting from use of optionals in unevaluated context.
+
 - Improved :doc:`bugprone-suspicious-include
   ` check by replacing the local
   options `HeaderFileExtensions` and `ImplementationFileExtensions` by the
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/optional-value-conversion.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/optional-value-conversion.cpp
index 72ef35c956d2e8..1228d64bb6909e 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/optional-value-conversion.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/optional-value-conversion.cpp
@@ -210,4 +210,6 @@ void correct(std::optional param)
   std::optional* p2 = &p;
   takeOptionalValue(p2->value_or(5U));
   takeOptionalRef(p2->value_or(5U));
+
+  using Type = decltype(takeOptionalValue(*param));
 }

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


[clang-tools-extra] [clang-tidy] Ignore unevaluated context in bugprone-optional-value-conversion (PR #90410)

2024-04-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Piotr Zegar (PiotrZSL)


Changes

Ignore optionals in unevaluated context, like static_assert or decltype.

Closes #89593

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


3 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp (+3-1) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/optional-value-conversion.cpp
 (+2) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp
index 9ab59e6b0474f0..600eab37552766 100644
--- a/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp
@@ -71,7 +71,9 @@ void 
OptionalValueConversionCheck::registerMatchers(MatchFinder *Finder) {
   ofClass(matchers::matchesAnyListedName(OptionalTypes,
   hasType(ConstructTypeMatcher),
   hasArgument(0U, ignoringImpCasts(anyOf(OptionalDereferenceMatcher,
- StdMoveCallMatcher
+ StdMoveCallMatcher))),
+  unless(anyOf(hasAncestor(typeLoc()),
+   hasAncestor(expr(matchers::hasUnevaluatedContext())
   .bind("expr"),
   this);
 }
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 3038d2b125f20d..062e619e0fe141 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -190,6 +190,10 @@ Changes in existing checks
   eliminating false positives resulting from direct usage of bitwise operators
   within parentheses.
 
+- Improved :doc:`bugprone-optional-value-conversion
+  ` check by eliminating
+  false positives resulting from use of optionals in unevaluated context.
+
 - Improved :doc:`bugprone-suspicious-include
   ` check by replacing the local
   options `HeaderFileExtensions` and `ImplementationFileExtensions` by the
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/optional-value-conversion.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/optional-value-conversion.cpp
index 72ef35c956d2e8..1228d64bb6909e 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/optional-value-conversion.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/optional-value-conversion.cpp
@@ -210,4 +210,6 @@ void correct(std::optional param)
   std::optional* p2 = &p;
   takeOptionalValue(p2->value_or(5U));
   takeOptionalRef(p2->value_or(5U));
+
+  using Type = decltype(takeOptionalValue(*param));
 }

``




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


[clang-tools-extra] [clang-tidy] Add modernize-use-std-format check (PR #90397)

2024-04-28 Thread Danny Mösch via cfe-commits

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

Only a few nits concerning non-functional code/text. Other than that LGTM.

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


[clang-tools-extra] [clang-tidy] Add modernize-use-std-format check (PR #90397)

2024-04-28 Thread Danny Mösch via cfe-commits

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


  1   2   >