[clang] [clang] Distinguish unresolved templates in UnresolvedLookupExpr (PR #89019)

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


@@ -186,3 +186,74 @@ class E {
 #endif
 template using D = int; // expected-note {{declared here}} 
 E ed; // expected-note {{instantiation of}}
+
+namespace non_functions {
+
+#if __cplusplus >= 201103L
+namespace PR88832 {
+template  struct O {
+  static const T v = 0;
+};
+
+struct P {
+  template  using I = typename O::v; // #TypeAlias
+};
+
+struct Q {
+  template  int foo() {
+return T::template I; // expected-error {{'P::I' is expected to be a 
non-type template, but instantiated to a type alias template}}
+// expected-note@#TypeAlias {{type alias template declared here}}
+  }
+};
+
+int bar() {
+  return Q().foo(); // expected-note-re {{function template specialization 
{{.*}} requested here}}
+}
+
+} // namespace PR88832
+#endif
+
+namespace PR63243 {
+
+namespace std {
+template  struct add_pointer { // #add_pointer
+};
+} // namespace std
+
+class A {};
+
+int main() {
+  std::__add_pointer::type ptr; // #ill-formed-decl
+  // expected-error@#ill-formed-decl {{no template named '__add_pointer'}}
+  // expected-note@#add_pointer {{'add_pointer' declared here}}
+  // expected-error@#ill-formed-decl {{expected ';' after expression}}
+  // expected-error@#ill-formed-decl {{no type named 'type' in the global 
namespace}}
+  // expected-error@#ill-formed-decl {{'std::add_pointer' is expected to be a 
non-type template, but instantiated to a class template}}

zyn0217 wrote:

@cor3ntin do you have any thoughts here? thanks!

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


[clang] [compiler-rt] [llvm] [ConstantFolding] Canonicalize constexpr GEPs to i8 (PR #89872)

2024-04-28 Thread Nikita Popov via cfe-commits

nikic wrote:

> btw we're still looking into a performance regression caused by #68882 that 
> still repros with LLVM head, even after the SROA enhancements. this patch 
> looks good, but can we hold off a bit on submitting this?

Sure!

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


[clang] [compiler-rt] [llvm] [ConstantFolding] Canonicalize constexpr GEPs to i8 (PR #89872)

2024-04-28 Thread Nikita Popov via cfe-commits


@@ -944,43 +943,18 @@ Constant *SymbolicallyEvaluateGEP(const GEPOperator *GEP,
 return ConstantExpr::getIntToPtr(C, ResTy);
   }
 
-  // Otherwise form a regular getelementptr. Recompute the indices so that
-  // we eliminate over-indexing of the notional static type array bounds.
-  // This makes it easy to determine if the getelementptr is "inbounds".
-
-  // For GEPs of GlobalValues, use the value type, otherwise use an i8 GEP.
-  if (auto *GV = dyn_cast(Ptr))
-SrcElemTy = GV->getValueType();
-  else
-SrcElemTy = Type::getInt8Ty(Ptr->getContext());
-
-  if (!SrcElemTy->isSized())
-return nullptr;
-
-  Type *ElemTy = SrcElemTy;
-  SmallVector Indices = DL.getGEPIndicesForOffset(ElemTy, Offset);
-  if (Offset != 0)
-return nullptr;
-
-  // Try to add additional zero indices to reach the desired result element
-  // type.
-  // TODO: Should we avoid extra zero indices if ResElemTy can't be reached and
-  // we'll have to insert a bitcast anyway?
-  while (ElemTy != ResElemTy) {
-Type *NextTy = GetElementPtrInst::getTypeAtIndex(ElemTy, (uint64_t)0);
-if (!NextTy)
-  break;
-
-Indices.push_back(APInt::getZero(isa(ElemTy) ? 32 : BitWidth));
-ElemTy = NextTy;
+  // Try to infer inbounds for GEPs of globals.
+  if (!InBounds && Offset.isNonNegative()) {

nikic wrote:

https://github.com/llvm/llvm-project/blob/main/llvm/test/Transforms/GlobalOpt/large-element-size.ll
 gets an incorrect inbounds without the check.

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


[clang] [compiler-rt] [llvm] [ConstantFolding] Canonicalize constexpr GEPs to i8 (PR #89872)

2024-04-28 Thread Arthur Eubanks via cfe-commits

aeubanks wrote:

btw we're still looking into a performance regression caused by #68882 that 
still repros with LLVM head, even after the SROA enhancements. this patch looks 
good, but can we hold off a bit on submitting this?

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


[clang] [compiler-rt] [llvm] [ConstantFolding] Canonicalize constexpr GEPs to i8 (PR #89872)

2024-04-28 Thread Arthur Eubanks via cfe-commits


@@ -944,43 +943,18 @@ Constant *SymbolicallyEvaluateGEP(const GEPOperator *GEP,
 return ConstantExpr::getIntToPtr(C, ResTy);
   }
 
-  // Otherwise form a regular getelementptr. Recompute the indices so that
-  // we eliminate over-indexing of the notional static type array bounds.
-  // This makes it easy to determine if the getelementptr is "inbounds".
-
-  // For GEPs of GlobalValues, use the value type, otherwise use an i8 GEP.
-  if (auto *GV = dyn_cast(Ptr))
-SrcElemTy = GV->getValueType();
-  else
-SrcElemTy = Type::getInt8Ty(Ptr->getContext());
-
-  if (!SrcElemTy->isSized())
-return nullptr;
-
-  Type *ElemTy = SrcElemTy;
-  SmallVector Indices = DL.getGEPIndicesForOffset(ElemTy, Offset);
-  if (Offset != 0)
-return nullptr;
-
-  // Try to add additional zero indices to reach the desired result element
-  // type.
-  // TODO: Should we avoid extra zero indices if ResElemTy can't be reached and
-  // we'll have to insert a bitcast anyway?
-  while (ElemTy != ResElemTy) {
-Type *NextTy = GetElementPtrInst::getTypeAtIndex(ElemTy, (uint64_t)0);
-if (!NextTy)
-  break;
-
-Indices.push_back(APInt::getZero(isa(ElemTy) ? 32 : BitWidth));
-ElemTy = NextTy;
+  // Try to infer inbounds for GEPs of globals.
+  if (!InBounds && Offset.isNonNegative()) {

aeubanks wrote:

is there a test for the case where `!Offset.isNonNegative()`?

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


[clang] [clang-tools-extra] [libcxx] Reland "[clang] Enable sized deallocation by default in C++14 onwards" (PR #90373)

2024-04-28 Thread Pengcheng Wang via cfe-commits

wangpc-pp wrote:

> > > @dyung Can you help me to comfirm whether the Windows builder is passing 
> > > now? I don't have such environment. Thanks in advance!
> > 
> > 
> > Sure, I'll try it on our internal builder and see if it passes and let you 
> > know the result.
> 
> I can confirm that this change builds successfully on our Windows 
> configuration.

Thanks a lot, that was quick!
There is another AddressSanitizer issue that may possibly be fixed by 
https://github.com/llvm/llvm-project/pull/90292. cc @vitalybuka

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


[clang] [clang-tools-extra] [libcxx] Reland "[clang] Enable sized deallocation by default in C++14 onwards" (PR #90373)

2024-04-28 Thread via cfe-commits

dyung wrote:

> > @dyung Can you help me to comfirm whether the Windows builder is passing 
> > now? I don't have such environment. Thanks in advance!
> 
> Sure, I'll try it on our internal builder and see if it passes and let you 
> know the result.

I can confirm that this change builds successfully on our Windows configuration.

https://github.com/llvm/llvm-project/pull/90373
___
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 947096950049ac7047a26335a993e48c1fa5c16d 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  | 19 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp | 10 ++
 clang/test/SemaCXX/PR68885.cpp   | 21 +
 5 files changed, 50 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/SemaCXX/PR68885.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 64a523a6f25fc2..64533f94815eb3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -590,6 +590,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 );
 
   ExprResult BuildExpressionFromDeclTemplateArgument(
-  const TemplateArgument , QualType ParamType, SourceLocation Loc);
+  const TemplateArgument , QualType ParamType, SourceLocation Loc,
+  NamedDecl *TemplateParam = nullptr);
   ExprResult
   BuildExpressionFromNonTypeTemplateArgument(const TemplateArgument ,
  SourceLocation Loc);
@@ -9572,9 +9573,10 @@ class Sema final : public SemaBase {
 
   bool isSameOrCompatibleFunctionType(QualType Param, QualType Arg);
 
-  TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument 
,
-QualType NTTPType,
-SourceLocation Loc);
+  TemplateArgumentLoc
+  getTrivialTemplateArgumentLoc(const TemplateArgument , 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..04f87fff550370 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -8438,10 +8438,9 @@ void Sema::NoteTemplateParameterLocation(const NamedDecl 
) {
 /// 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 ,
-  QualType ParamType,
-  SourceLocation Loc) {
+ExprResult Sema::BuildExpressionFromDeclTemplateArgument(
+const TemplateArgument , QualType ParamType, SourceLocation Loc,
+NamedDecl *TemplateParam) {
   // C++ [temp.param]p8:
   //
   //   A non-type template-parameter of type "array of T" or
@@ -8508,6 +8507,18 @@ Sema::BuildExpressionFromDeclTemplateArgument(const 
TemplateArgument ,
   } 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, NTTP->getIndex(),
+/*PackIndex=*/std::nullopt,
+/*RefParam=*/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 ,
 /// argument.
 TemplateArgumentLoc
 

[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 updated 
https://github.com/llvm/llvm-project/pull/90389

>From 3c1aac31d879ebf172d2b9b6c9a351d967f72606 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 , 
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 , 
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 

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

2024-04-28 Thread Hubert Tong via cfe-commits


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

hubert-reinterpretcast wrote:

Makes me wonder how far C++ stdlibs will get if they included the C library 
headers in an inline namespace under the global namespace (and count on `extern 
"C"` to handle the linkage names).

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] Fix a crash introduced by 3d5e9ab by adding a nullptr check. (PR #90301)

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

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


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 Qizhi Hu via cfe-commits

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

>From cb7acd79aea4af3e92b5317e55fb43cabc7ebb40 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  | 19 +++
 clang/lib/Sema/SemaTemplateDeduction.cpp | 10 ++
 clang/test/SemaCXX/PR68885.cpp   | 21 +
 5 files changed, 50 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/SemaCXX/PR68885.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 64a523a6f25fc2..64533f94815eb3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -590,6 +590,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 );
 
   ExprResult BuildExpressionFromDeclTemplateArgument(
-  const TemplateArgument , QualType ParamType, SourceLocation Loc);
+  const TemplateArgument , QualType ParamType, SourceLocation Loc,
+  NamedDecl *TemplateParam = nullptr);
   ExprResult
   BuildExpressionFromNonTypeTemplateArgument(const TemplateArgument ,
  SourceLocation Loc);
@@ -9572,9 +9573,10 @@ class Sema final : public SemaBase {
 
   bool isSameOrCompatibleFunctionType(QualType Param, QualType Arg);
 
-  TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument 
,
-QualType NTTPType,
-SourceLocation Loc);
+  TemplateArgumentLoc
+  getTrivialTemplateArgumentLoc(const TemplateArgument , 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..c91002592781c8 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -8438,10 +8438,9 @@ void Sema::NoteTemplateParameterLocation(const NamedDecl 
) {
 /// 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 ,
-  QualType ParamType,
-  SourceLocation Loc) {
+ExprResult Sema::BuildExpressionFromDeclTemplateArgument(
+const TemplateArgument , QualType ParamType, SourceLocation Loc,
+NamedDecl *TemplateParam) {
   // C++ [temp.param]p8:
   //
   //   A non-type template-parameter of type "array of T" or
@@ -8508,6 +8507,18 @@ Sema::BuildExpressionFromDeclTemplateArgument(const 
TemplateArgument ,
   } 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, /*Index=*/0,
+/*PackIndex=*/std::nullopt,
+/*RefParam=*/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 ,
 /// argument.
 TemplateArgumentLoc
 

[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/7] 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 ,
   }
   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 
,
   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", "v125",
+  

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

2024-04-28 Thread NAKAMURA Takumi via cfe-commits


@@ -1115,7 +1115,9 @@ int64_t Decl::getID() const {
 
 const FunctionType *Decl::getFunctionType(bool BlocksToo) const {
   QualType Ty;
-  if (const auto *D = dyn_cast(this))
+  if (const auto *D = dyn_cast(this))

chapuni wrote:

Seems causes the warning. `[-Wunused-but-set-variable]`

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] 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.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);
+}
+auto&& 

[clang] [clang] fix(85447): clang 18.1.0 crashes in clang::ASTContext::getTypeInfoImpl (PR #89850)

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

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

>From f4e4e7b91e85d12c861063e1461b160b9bd22da6 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 29 Apr 2024 01:53:47 +0300
Subject: [PATCH] fix(85447): refine handling of incomplete anonymous struct
 declarations

---
 clang/lib/Sema/SemaDecl.cpp|  3 +++
 clang/test/Sema/incomplete-struct-decl.cpp | 10 ++
 2 files changed, 13 insertions(+)
 create mode 100644 clang/test/Sema/incomplete-struct-decl.cpp

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 671752b56e01f4..d3871bb7447405 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5789,6 +5789,9 @@ Decl *Sema::BuildAnonymousStructOrUnion(Scope *S, 
DeclSpec ,
 Anon = VarDecl::Create(Context, Owner, DS.getBeginLoc(),
Record->getLocation(), /*IdentifierInfo=*/nullptr,
Context.getTypeDeclType(Record), TInfo, SC);
+if (Invalid)
+  Anon->setInvalidDecl();
+
 ProcessDeclAttributes(S, Anon, Dc);
 
 // Default-initialize the implicit variable. This initialization will be
diff --git a/clang/test/Sema/incomplete-struct-decl.cpp 
b/clang/test/Sema/incomplete-struct-decl.cpp
new file mode 100644
index 00..bc3bd6b2eae2f0
--- /dev/null
+++ b/clang/test/Sema/incomplete-struct-decl.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -x c++ -fsyntax-only -verify=cxx,expected %s
+
+template  using __impl_of = a; // expected-note {{'__impl_of' 
declared here}} \
+   expected-note {{template is 
declared here}}
+struct {// expected-error {{anonymous structs 
and classes must be class members}} \
+   expected-note {{to match this '{'}}
+  __impl_;  // expected-error {{no template named 
'__impl_'; did you mean '__impl_of'?}} \
+   expected-error {{cannot specify 
deduction guide for alias template '__impl_of'}} \
+   expected-error {{expected ';' after 
struct}}
+// expected-error {{expected '}'}}

___
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

jcsxky wrote:

Windows CI failed with an unrelated file.

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] [flang] [Flang] Add support for -w option (PR #90420)

2024-04-28 Thread Kiran Chandramohan via cfe-commits

https://github.com/kiranchandramohan updated 
https://github.com/llvm/llvm-project/pull/90420

>From 6a22c2de281bc04c9f71b7fcc8289e4217b70e08 Mon Sep 17 00:00:00 2001
From: Kiran Chandramohan 
Date: Fri, 26 Apr 2024 09:26:11 +
Subject: [PATCH] [Flang][Driver] Add support for -w option

A quick and dirty implementation of the -w option. Filters
the warning messages generated by the Frontend during emission.

TODO: Add more tests
TODO: Ignore MLIR, LLVM IR and Driver warnings
TODO: Check whether we can avoid generating rather than filtering
the warning options in the frontend.
---
 clang/include/clang/Driver/Options.td  |  2 +-
 clang/lib/Driver/ToolChains/Flang.cpp  |  2 ++
 flang/include/flang/Frontend/FrontendOptions.h |  6 +-
 flang/include/flang/Parser/message.h   |  2 +-
 flang/include/flang/Semantics/semantics.h  |  2 +-
 flang/lib/Frontend/CompilerInvocation.cpp  |  3 +++
 flang/lib/Frontend/FrontendAction.cpp  |  7 +--
 flang/lib/Frontend/FrontendActions.cpp | 11 ---
 flang/lib/Parser/message.cpp   |  8 ++--
 flang/lib/Semantics/semantics.cpp  |  6 --
 flang/test/Driver/w-option.f90 | 14 ++
 11 files changed, 50 insertions(+), 13 deletions(-)
 create mode 100644 flang/test/Driver/w-option.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 086aedefc11878..e73aee3f63fa47 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5680,7 +5680,7 @@ def whatsloaded : Flag<["-"], "whatsloaded">;
 def why_load : Flag<["-"], "why_load">;
 def whyload : Flag<["-"], "whyload">, Alias;
 def w : Flag<["-"], "w">, HelpText<"Suppress all warnings">,
-  Visibility<[ClangOption, CC1Option]>,
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
   MarshallingInfoFlag>;
 def x : JoinedOrSeparate<["-"], "x">,
 Flags<[NoXarchOption]>,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 6d93c1f3d7034a..6d1372152601e5 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -757,6 +757,8 @@ void Flang::ConstructJob(Compilation , const JobAction 
,
   // Add other compile options
   addOtherOptions(Args, CmdArgs);
 
+  Args.AddLastArg(CmdArgs, options::OPT_w);
+
   // Forward flags for OpenMP. We don't do this if the current action is an
   // device offloading action other than OpenMP.
   if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
diff --git a/flang/include/flang/Frontend/FrontendOptions.h 
b/flang/include/flang/Frontend/FrontendOptions.h
index 06b1318f243b08..acbc55a75f9a11 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -232,7 +232,8 @@ class FrontendInputFile {
 struct FrontendOptions {
   FrontendOptions()
   : showHelp(false), showVersion(false), instrumentedParse(false),
-showColors(false), needProvenanceRangeToCharBlockMappings(false) {}
+showColors(false), needProvenanceRangeToCharBlockMappings(false),
+disableWarnings(false) {}
 
   /// Show the -help text.
   unsigned showHelp : 1;
@@ -251,6 +252,9 @@ struct FrontendOptions {
   /// compilation.
   unsigned needProvenanceRangeToCharBlockMappings : 1;
 
+  /// Disable warnings emitted by the Frontend
+  unsigned disableWarnings : 1;
+
   /// Input values from `-fget-definition`
   struct GetDefinitionVals {
 unsigned line;
diff --git a/flang/include/flang/Parser/message.h 
b/flang/include/flang/Parser/message.h
index 668559aeec9478..d1eb6e6f5aa52d 100644
--- a/flang/include/flang/Parser/message.h
+++ b/flang/include/flang/Parser/message.h
@@ -284,7 +284,7 @@ class Messages {
   void Copy(const Messages &);
   void ResolveProvenances(const AllCookedSources &);
   void Emit(llvm::raw_ostream &, const AllCookedSources &,
-  bool echoSourceLines = true) const;
+  bool echoSourceLines = true, bool disableWarnings = false) const;
   void AttachTo(Message &, std::optional = std::nullopt);
   bool AnyFatalError() const;
 
diff --git a/flang/include/flang/Semantics/semantics.h 
b/flang/include/flang/Semantics/semantics.h
index c8ee71945d8bde..456c2928f5b368 100644
--- a/flang/include/flang/Semantics/semantics.h
+++ b/flang/include/flang/Semantics/semantics.h
@@ -312,7 +312,7 @@ class Semantics {
 return context_.FindScope(where);
   }
   bool AnyFatalError() const { return context_.AnyFatalError(); }
-  void EmitMessages(llvm::raw_ostream &) const;
+  void EmitMessages(llvm::raw_ostream &, bool disableWarnings = false) const;
   void DumpSymbols(llvm::raw_ostream &);
   void DumpSymbolsSources(llvm::raw_ostream &) const;
 
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index f1b7b53975398e..4a19592edf6ed8 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ 

[clang] [flang] [Flang] Add support for -w option (PR #90420)

2024-04-28 Thread Kiran Chandramohan via cfe-commits

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


[clang] [flang] [Flang][Driver] Add support for -w option (PR #90420)

2024-04-28 Thread Kiran Chandramohan via cfe-commits

https://github.com/kiranchandramohan created 
https://github.com/llvm/llvm-project/pull/90420

A quick and dirty implementation of the -w option. Filters the warning messages 
generated by the Frontend during emission.

TODO: Add more tests
TODO: Ignore MLIR, LLVM IR and Driver warnings
TODO: Check whether we can avoid generating rather than filtering the warning 
options in the frontend
TODO: Check the clang implementation of -w

>From 6a22c2de281bc04c9f71b7fcc8289e4217b70e08 Mon Sep 17 00:00:00 2001
From: Kiran Chandramohan 
Date: Fri, 26 Apr 2024 09:26:11 +
Subject: [PATCH] [Flang][Driver] Add support for -w option

A quick and dirty implementation of the -w option. Filters
the warning messages generated by the Frontend during emission.

TODO: Add more tests
TODO: Ignore MLIR, LLVM IR and Driver warnings
TODO: Check whether we can avoid generating rather than filtering
the warning options in the frontend.
---
 clang/include/clang/Driver/Options.td  |  2 +-
 clang/lib/Driver/ToolChains/Flang.cpp  |  2 ++
 flang/include/flang/Frontend/FrontendOptions.h |  6 +-
 flang/include/flang/Parser/message.h   |  2 +-
 flang/include/flang/Semantics/semantics.h  |  2 +-
 flang/lib/Frontend/CompilerInvocation.cpp  |  3 +++
 flang/lib/Frontend/FrontendAction.cpp  |  7 +--
 flang/lib/Frontend/FrontendActions.cpp | 11 ---
 flang/lib/Parser/message.cpp   |  8 ++--
 flang/lib/Semantics/semantics.cpp  |  6 --
 flang/test/Driver/w-option.f90 | 14 ++
 11 files changed, 50 insertions(+), 13 deletions(-)
 create mode 100644 flang/test/Driver/w-option.f90

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 086aedefc11878..e73aee3f63fa47 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5680,7 +5680,7 @@ def whatsloaded : Flag<["-"], "whatsloaded">;
 def why_load : Flag<["-"], "why_load">;
 def whyload : Flag<["-"], "whyload">, Alias;
 def w : Flag<["-"], "w">, HelpText<"Suppress all warnings">,
-  Visibility<[ClangOption, CC1Option]>,
+  Visibility<[ClangOption, CC1Option, FlangOption, FC1Option]>,
   MarshallingInfoFlag>;
 def x : JoinedOrSeparate<["-"], "x">,
 Flags<[NoXarchOption]>,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 6d93c1f3d7034a..6d1372152601e5 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -757,6 +757,8 @@ void Flang::ConstructJob(Compilation , const JobAction 
,
   // Add other compile options
   addOtherOptions(Args, CmdArgs);
 
+  Args.AddLastArg(CmdArgs, options::OPT_w);
+
   // Forward flags for OpenMP. We don't do this if the current action is an
   // device offloading action other than OpenMP.
   if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
diff --git a/flang/include/flang/Frontend/FrontendOptions.h 
b/flang/include/flang/Frontend/FrontendOptions.h
index 06b1318f243b08..acbc55a75f9a11 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -232,7 +232,8 @@ class FrontendInputFile {
 struct FrontendOptions {
   FrontendOptions()
   : showHelp(false), showVersion(false), instrumentedParse(false),
-showColors(false), needProvenanceRangeToCharBlockMappings(false) {}
+showColors(false), needProvenanceRangeToCharBlockMappings(false),
+disableWarnings(false) {}
 
   /// Show the -help text.
   unsigned showHelp : 1;
@@ -251,6 +252,9 @@ struct FrontendOptions {
   /// compilation.
   unsigned needProvenanceRangeToCharBlockMappings : 1;
 
+  /// Disable warnings emitted by the Frontend
+  unsigned disableWarnings : 1;
+
   /// Input values from `-fget-definition`
   struct GetDefinitionVals {
 unsigned line;
diff --git a/flang/include/flang/Parser/message.h 
b/flang/include/flang/Parser/message.h
index 668559aeec9478..d1eb6e6f5aa52d 100644
--- a/flang/include/flang/Parser/message.h
+++ b/flang/include/flang/Parser/message.h
@@ -284,7 +284,7 @@ class Messages {
   void Copy(const Messages &);
   void ResolveProvenances(const AllCookedSources &);
   void Emit(llvm::raw_ostream &, const AllCookedSources &,
-  bool echoSourceLines = true) const;
+  bool echoSourceLines = true, bool disableWarnings = false) const;
   void AttachTo(Message &, std::optional = std::nullopt);
   bool AnyFatalError() const;
 
diff --git a/flang/include/flang/Semantics/semantics.h 
b/flang/include/flang/Semantics/semantics.h
index c8ee71945d8bde..456c2928f5b368 100644
--- a/flang/include/flang/Semantics/semantics.h
+++ b/flang/include/flang/Semantics/semantics.h
@@ -312,7 +312,7 @@ class Semantics {
 return context_.FindScope(where);
   }
   bool AnyFatalError() const { return context_.AnyFatalError(); }
-  void EmitMessages(llvm::raw_ostream &) const;
+  void EmitMessages(llvm::raw_ostream 

[clang] [clang] fix(85447): clang 18.1.0 crashes in clang::ASTContext::getTypeInfoImpl (PR #89850)

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

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

>From 484100917d034bc30131ebb95578d09083a2325a Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Wed, 24 Apr 2024 03:27:52 +0300
Subject: [PATCH] fix(85447): refine handling of incomplete anonymous struct
 declarations

---
 clang/lib/Sema/SemaDecl.cpp|  3 +++
 clang/test/Sema/incomplete-struct-decl.cpp | 10 ++
 2 files changed, 13 insertions(+)
 create mode 100644 clang/test/Sema/incomplete-struct-decl.cpp

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 5fed554d9e25c3..debe0d9e865362 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5789,6 +5789,9 @@ Decl *Sema::BuildAnonymousStructOrUnion(Scope *S, 
DeclSpec ,
 Anon = VarDecl::Create(Context, Owner, DS.getBeginLoc(),
Record->getLocation(), /*IdentifierInfo=*/nullptr,
Context.getTypeDeclType(Record), TInfo, SC);
+if (Invalid)
+  Anon->setInvalidDecl();
+
 ProcessDeclAttributes(S, Anon, Dc);
 
 // Default-initialize the implicit variable. This initialization will be
diff --git a/clang/test/Sema/incomplete-struct-decl.cpp 
b/clang/test/Sema/incomplete-struct-decl.cpp
new file mode 100644
index 00..21e445fa170f94
--- /dev/null
+++ b/clang/test/Sema/incomplete-struct-decl.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only
+
+template  using __impl_of = a; // expected-note {{'__impl_of' 
declared here}} \
+   expected-note {{template is 
declared here}}
+struct {// expected-error {{anonymous structs 
and classes must be class members}} \
+   expected-note {{to match this '{'}}
+  __impl_;  // expected-error {{no template named 
'__impl_'; did you mean '__impl_of'?}} \
+   expected-error {{cannot specify 
deduction guide for alias template '__impl_of'}} \
+   expected-error {{expected ';' after 
struct}}
+// expected-error {{expected '}'}}

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


[clang] [clang] Fix `remove{CVR|Fast}Qualifiers` with 64-bit `Qualifiers::Mask` (PR #90329)

2024-04-28 Thread John McCall via cfe-commits

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

LGTM

https://github.com/llvm/llvm-project/pull/90329
___
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 via cfe-commits


@@ -0,0 +1,103 @@
+// RUN: %check_clang_tidy %s bugprone-exception-rethrow %t -- -- -fexceptions
+
+struct exception {};
+
+namespace std {
+  template 
+  T&& move(T ) {
+return static_cast(x);
+  }
+}
+
+void correct() {
+  try {
+  throw exception();
+  } catch(const exception &) {
+  throw;
+  }
+}
+
+void correct2() {
+  try {
+  throw exception();
+  } catch(const exception ) {
+  try {
+throw exception();
+  } catch(...) {}
+  }
+}
+
+void not_correct() {
+  try {
+  throw exception();
+  } catch(const exception ) {
+  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 exception();
+  } catch(const exception ) {
+  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_correct3() {
+  try {
+  throw exception();
+  } catch(const exception ) {
+  throw exception(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_correct4() {
+  try {
+  throw exception();
+  } catch(exception ) {
+  throw std::move(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_correct5() {
+  try {
+  throw 5;
+  } catch(const int ) {
+  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 with no operand triggers 'std::terminate()' [bugprone-exception-rethrow]
+}
+
+void rethrow_not_correct2() {
+  try {
+throw;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: empty 'throw' outside a catch 
block with no operand triggers 'std::terminate()' [bugprone-exception-rethrow]
+  } catch(...) {
+  }
+}
+
+void rethrow_correct() {
+  try {
+throw 5;
+  } catch(...) {
+throw;
+  }
+}
+
+void rethrow_in_lambda() {
+  try {
+throw 5;
+  } catch(...) {
+auto lambda = [] { throw; };
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: empty 'throw' outside a catch 
block with no operand triggers 'std::terminate()' [bugprone-exception-rethrow]

isuckatcs wrote:

This is actually correct if the lambda is called inside the catch block, or not 
called at all.

See the snippet below on [godbolt](https://godbolt.org/z/xPhx4Pfa4).
```c++
void rethrow_in_lambda() {
  try {
throw 5;
  } catch(...) {
auto lambda = [] { throw; };
lambda();
  }
}
```

The issue only happens, if the lambda escapes the `catch` block.

See my original example on [godbolt](https://godbolt.org/z/Yxoxso3ra):
```c++
void foo() {
  std::function fn;

  try {
throw 1;
  } catch (...) {
fn = [] { throw; }; // the lambda and the `throw` escape the catch block
  }

  fn();
}
```
I think besides using a lambda, the only other way this can happen is the one 
below.
```c++
void rethrow_in_lambda() {
std::function fn;

try {
throw 1;
} catch (...) {
struct wrapper {
static void foo() { throw; };
};

fn = wrapper::foo;
}

fn();
}
```
I guess to be 100% accurate in detecting these cases, we need flow sensitive 
analysis*, so I think we should just ignore them and mention it in the docs 
too. Finding these `throw;` statements is something we already do with 
`ASTMatcher`s, so ignoring them will work.

*the `throw;` escaping can happen in any nested function. E.g.:
```c++
#include 

std::function fn;

void escape(std::function ) {
fn = ref;
}

void rethrow_in_lambda() {
try {
throw 1;
} catch (...) {
std::function lambda = [] { throw; };

escape(lambda);
}
}

int main() {
rethrow_in_lambda();
fn();

return 0;
}
```

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 via cfe-commits


@@ -0,0 +1,103 @@
+// RUN: %check_clang_tidy %s bugprone-exception-rethrow %t -- -- -fexceptions
+
+struct exception {};
+
+namespace std {

isuckatcs wrote:

For the static analyzer we have `system-header-simulator-cxx.h`, maybe 
clang-tidy would also benefit from a similar header.

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 via cfe-commits

https://github.com/isuckatcs edited 
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 via cfe-commits


@@ -0,0 +1,67 @@
+.. title:: clang-tidy - bugprone-exception-rethrow
+
+bugprone-exception-rethrow
+==
+
+Identifies problematic exception rethrowing, especially with caught exception
+variables or empty throw statements outside catch blocks.
+
+In C++ exception handling, a common pitfall occurs when developers rethrow
+caught exceptions within catch blocks by directly passing the caught exception
+variable to the ``throw`` statement. While this approach can propagate
+exceptions to higher levels of the program, it often leads to code that is less
+clear and more error-prone. Rethrowing caught exceptions with the same 
exception
+object within catch blocks can obscure the original context of the exception 
and
+make it challenging to trace program flow. Additionally, this method can
+introduce issues such as exception object slicing and performance overhead due
+to the invocation of the copy constructor.
+
+.. code-block:: c++
+
+  try {
+// Code that may throw an exception
+  } catch (const std::exception& e) {
+throw e; // Bad
+  }
+
+To prevent these issues, it is advisable to utilize ``throw;`` statements to
+rethrow the original exception object for currently handled exceptions.
+
+.. code-block:: c++
+
+  try {
+// Code that may throw an exception
+  } catch (const std::exception& e) {
+throw; // Good
+  }
+
+However, when empty throw statement is used outside of a catch block, it
+will result in a call to ``std::terminate()``, which abruptly terminates the
+application. This behavior can lead to abnormal termination of the program and

isuckatcs wrote:

```suggestion
application. This behavior can lead to the abnormal termination of the program 
and
```

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 via cfe-commits


@@ -0,0 +1,67 @@
+.. title:: clang-tidy - bugprone-exception-rethrow
+
+bugprone-exception-rethrow
+==
+
+Identifies problematic exception rethrowing, especially with caught exception
+variables or empty throw statements outside catch blocks.
+
+In C++ exception handling, a common pitfall occurs when developers rethrow
+caught exceptions within catch blocks by directly passing the caught exception
+variable to the ``throw`` statement. While this approach can propagate
+exceptions to higher levels of the program, it often leads to code that is less
+clear and more error-prone. Rethrowing caught exceptions with the same 
exception
+object within catch blocks can obscure the original context of the exception 
and
+make it challenging to trace program flow. Additionally, this method can
+introduce issues such as exception object slicing and performance overhead due
+to the invocation of the copy constructor.
+
+.. code-block:: c++
+
+  try {
+// Code that may throw an exception
+  } catch (const std::exception& e) {
+throw e; // Bad
+  }
+

isuckatcs wrote:

I think showing an example of exception object slicing would also be benefical 
if we mention it as an example, so how about presenting the examples like this:

```suggestion
introduce issues such as exception object slicing and performance overhead due
to the invocation of the copy constructor.

.. code-block:: c++

  try {
// Code that may throw an exception
  } catch (const std::exception& e) {
throw e; // Bad, 'e' is copied
  }

.. code-block:: c++
  class derived_exception : public std::exception { ... };

  void throwDerived() { throw derived_exception{}; }

  try {
throwDerived();
  } catch (const std::exception& e) {
throw e; // Bad, exception slicing occurs as 'derived_exception' is 
rethrown as 'exception' (maybe with better wording ?) 
  }


```

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 via cfe-commits


@@ -0,0 +1,67 @@
+.. title:: clang-tidy - bugprone-exception-rethrow
+
+bugprone-exception-rethrow
+==
+
+Identifies problematic exception rethrowing, especially with caught exception
+variables or empty throw statements outside catch blocks.
+
+In C++ exception handling, a common pitfall occurs when developers rethrow
+caught exceptions within catch blocks by directly passing the caught exception
+variable to the ``throw`` statement. While this approach can propagate
+exceptions to higher levels of the program, it often leads to code that is less
+clear and more error-prone. Rethrowing caught exceptions with the same 
exception
+object within catch blocks can obscure the original context of the exception 
and
+make it challenging to trace program flow. Additionally, this method can
+introduce issues such as exception object slicing and performance overhead due
+to the invocation of the copy constructor.
+
+.. code-block:: c++
+
+  try {
+// Code that may throw an exception
+  } catch (const std::exception& e) {
+throw e; // Bad
+  }
+
+To prevent these issues, it is advisable to utilize ``throw;`` statements to
+rethrow the original exception object for currently handled exceptions.
+
+.. code-block:: c++
+
+  try {
+// Code that may throw an exception
+  } catch (const std::exception& e) {
+throw; // Good
+  }
+
+However, when empty throw statement is used outside of a catch block, it
+will result in a call to ``std::terminate()``, which abruptly terminates the
+application. This behavior can lead to abnormal termination of the program and
+is often unintended. Such occurrences may indicate errors or oversights in the
+exception handling logic, and it is essential to avoid empty throw statements
+outside catch blocks to prevent unintended program termination.
+
+.. code-block:: c++
+
+  void foo() {
+// std::terminate will be called because there is no exception to rethrow
+throw;
+  }
+
+  int main() {
+try {
+  foo();
+} catch(...) {
+  return 1;
+}
+return 0;
+  }
+
+Above program will be terminated with:

isuckatcs wrote:

```suggestion
The above program will be terminated with:
```

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 via cfe-commits

https://github.com/isuckatcs requested changes to this pull request.

Apart from a few typos in the docs and the lambda case, the patch looks good to 
me.

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 via cfe-commits


@@ -0,0 +1,103 @@
+// RUN: %check_clang_tidy %s bugprone-exception-rethrow %t -- -- -fexceptions
+
+struct exception {};
+
+namespace std {
+  template 
+  T&& move(T ) {

isuckatcs wrote:

```suggestion
  T&& move(T &) {
```
The official signature is the one below.
```c++
template< class T >
typename std::remove_reference::type&& move( T&& t ) noexcept;
```

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 via cfe-commits


@@ -0,0 +1,67 @@
+.. title:: clang-tidy - bugprone-exception-rethrow
+
+bugprone-exception-rethrow
+==
+
+Identifies problematic exception rethrowing, especially with caught exception
+variables or empty throw statements outside catch blocks.
+
+In C++ exception handling, a common pitfall occurs when developers rethrow
+caught exceptions within catch blocks by directly passing the caught exception
+variable to the ``throw`` statement. While this approach can propagate
+exceptions to higher levels of the program, it often leads to code that is less
+clear and more error-prone. Rethrowing caught exceptions with the same 
exception
+object within catch blocks can obscure the original context of the exception 
and
+make it challenging to trace program flow. Additionally, this method can
+introduce issues such as exception object slicing and performance overhead due
+to the invocation of the copy constructor.
+
+.. code-block:: c++
+
+  try {
+// Code that may throw an exception
+  } catch (const std::exception& e) {
+throw e; // Bad
+  }
+
+To prevent these issues, it is advisable to utilize ``throw;`` statements to
+rethrow the original exception object for currently handled exceptions.
+
+.. code-block:: c++
+
+  try {
+// Code that may throw an exception
+  } catch (const std::exception& e) {

isuckatcs wrote:

Maybe like this, to prevent an additional warning?
```suggestion
  } catch (const std::exception&) {
```

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 via cfe-commits


@@ -0,0 +1,67 @@
+.. title:: clang-tidy - bugprone-exception-rethrow
+
+bugprone-exception-rethrow
+==
+
+Identifies problematic exception rethrowing, especially with caught exception
+variables or empty throw statements outside catch blocks.
+
+In C++ exception handling, a common pitfall occurs when developers rethrow
+caught exceptions within catch blocks by directly passing the caught exception
+variable to the ``throw`` statement. While this approach can propagate
+exceptions to higher levels of the program, it often leads to code that is less
+clear and more error-prone. Rethrowing caught exceptions with the same 
exception
+object within catch blocks can obscure the original context of the exception 
and
+make it challenging to trace program flow. Additionally, this method can
+introduce issues such as exception object slicing and performance overhead due
+to the invocation of the copy constructor.
+
+.. code-block:: c++
+
+  try {
+// Code that may throw an exception
+  } catch (const std::exception& e) {
+throw e; // Bad
+  }
+
+To prevent these issues, it is advisable to utilize ``throw;`` statements to
+rethrow the original exception object for currently handled exceptions.
+
+.. code-block:: c++
+
+  try {
+// Code that may throw an exception
+  } catch (const std::exception& e) {
+throw; // Good
+  }
+
+However, when empty throw statement is used outside of a catch block, it
+will result in a call to ``std::terminate()``, which abruptly terminates the

isuckatcs wrote:

```suggestion
However, when an empty throw statement is used outside a catch block, it
results in a call to ``std::terminate()``, which abruptly terminates the
```

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] [clang-format] Set Change.TokenLength to ColumnWidth (PR #90378)

2024-04-28 Thread Owen Pan via cfe-commits

https://github.com/owenca closed 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] aa596fa - [clang-format] Set Change.TokenLength to ColumnWidth (#90378)

2024-04-28 Thread via cfe-commits

Author: Owen Pan
Date: 2024-04-28T14:06:12-07:00
New Revision: aa596fa4d974f75ed8d2db3f4880ec0e5be3e176

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

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

Fixes #37705.
Fixes #47333.
Fixes #47624.
Fixes #58850.
Fixes #75929.
Fixes #87885.
Fixes #89916.

Added: 


Modified: 
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index cc9bcce6c414e0..44fd807ec27ea7 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -131,6 +131,7 @@ void WhitespaceManager::calculateLineBreakInformation() {
   for (unsigned I = 1, e = Changes.size(); I != e; ++I) {
 auto  = Changes[I];
 auto  = Changes[I - 1];
+auto  = P.TokenLength;
 SourceLocation OriginalWhitespaceStart =
 C.OriginalWhitespaceRange.getBegin();
 SourceLocation PreviousOriginalWhitespaceEnd =
@@ -169,21 +170,23 @@ void WhitespaceManager::calculateLineBreakInformation() {
 // line of the token.
 auto NewlinePos = Text.find_first_of('\n');
 if (NewlinePos == StringRef::npos) {
-  P.TokenLength = OriginalWhitespaceStartOffset -
+  PrevTokLength = OriginalWhitespaceStartOffset -
   PreviousOriginalWhitespaceEndOffset +
   C.PreviousLinePostfix.size() + 
P.CurrentLinePrefix.size();
+  if (!P.IsInsideToken)
+PrevTokLength = std::min(PrevTokLength, P.Tok->ColumnWidth);
 } else {
-  P.TokenLength = NewlinePos + P.CurrentLinePrefix.size();
+  PrevTokLength = NewlinePos + P.CurrentLinePrefix.size();
 }
 
 // If there are multiple changes in this token, sum up all the changes 
until
 // the end of the line.
 if (P.IsInsideToken && P.NewlinesBefore == 0)
-  LastOutsideTokenChange->TokenLength += P.TokenLength + P.Spaces;
+  LastOutsideTokenChange->TokenLength += PrevTokLength + P.Spaces;
 else
   LastOutsideTokenChange = 
 
-C.PreviousEndOfTokenColumn = P.StartOfTokenColumn + P.TokenLength;
+C.PreviousEndOfTokenColumn = P.StartOfTokenColumn + PrevTokLength;
 
 P.IsTrailingComment =
 (C.NewlinesBefore > 0 || C.Tok->is(tok::eof) ||

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 8ecc1188a127a5..32ba6b6853c799 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -27363,6 +27363,45 @@ TEST_F(FormatTest, BreakAdjacentStringLiterals) {
   verifyFormat(Code, Style);
 }
 
+TEST_F(FormatTest, AlignUTFCommentsAndStringLiterals) {
+  verifyFormat(
+  "int rus;  // А теперь комментарии, например, на русском, 2-байта\n"
+  "int long_rus; // Верхний коммент еще не превысил границу в 80, однако\n"
+  "  // уже отодвинут. Перенос, при этом, отрабатывает верно");
+
+  auto Style = getLLVMStyle();
+  Style.ColumnLimit = 15;
+  verifyNoChange("#define test  \\\n"
+ "  /* 测试 */  \\\n"
+ "  \"aa\"\\\n"
+ "  \"bb\"",
+ Style);
+
+  Style.ColumnLimit = 25;
+  verifyFormat("struct foo {\n"
+   "  int ii; ///< ii\n"
+   "  int b;  ///< ыыы\n"
+   "  int c;  ///< \n"
+   "};",
+   Style);
+
+  Style.ColumnLimit = 35;
+  verifyFormat("#define SENSOR_DESC_1 \\\n"
+   "  \"{\" \\\n"
+   "  \"unit_of_measurement: \\\"°C\\\",\"  \\\n"
+   "  \"}\"",
+   Style);
+
+  Style.ColumnLimit = 80;
+  Style.AlignArrayOfStructures = FormatStyle::AIAS_Left;
+  verifyFormat("Languages languages = {\n"
+   "Language{{'e', 'n'}, U\"Test English\" },\n"
+   "Language{{'l', 'v'}, U\"Test Latviešu\"},\n"
+   "Language{{'r', 'u'}, U\"Test Русский\" },\n"
+   "};",
+   Style);
+}
+
 } // namespace
 } // namespace test
 } // namespace format



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


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

2024-04-28 Thread via cfe-commits

Author: Owen Pan
Date: 2024-04-28T14:05:12-07:00
New Revision: 9c1de620344b2518bb171be51066e1ec9a5be623

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

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

Added: 


Modified: 
clang/lib/Format/FormatToken.h
clang/lib/Format/TokenAnnotator.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index f651e6228c206d..28b6488e54a422 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -1623,10 +1623,10 @@ struct AdditionalKeywords {
   IdentifierInfo *kw_then;
 
   /// Returns \c true if \p Tok is a keyword or an identifier.
-  bool isWordLike(const FormatToken ) const {
+  bool isWordLike(const FormatToken , bool IsVerilog = true) const {
 // getIdentifierinfo returns non-null for keywords as well as identifiers.
 return Tok.Tok.getIdentifierInfo() &&
-   !Tok.isOneOf(kw_verilogHash, kw_verilogHashHash, kw_apostrophe);
+   (!IsVerilog || !isVerilogKeywordSymbol(Tok));
   }
 
   /// Returns \c true if \p Tok is a true JavaScript identifier, returns
@@ -1755,6 +1755,10 @@ struct AdditionalKeywords {
 }
   }
 
+  bool isVerilogKeywordSymbol(const FormatToken ) const {
+return Tok.isOneOf(kw_verilogHash, kw_verilogHashHash, kw_apostrophe);
+  }
+
   bool isVerilogWordOperator(const FormatToken ) const {
 return Tok.isOneOf(kw_before, kw_intersect, kw_dist, kw_iff, kw_inside,
kw_with);

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 63629fa743184e..d366ae2080bc25 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4780,9 +4780,14 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
   if (Left.Finalized)
 return Right.hasWhitespaceBefore();
 
+  const bool IsVerilog = Style.isVerilog();
+  assert(!IsVerilog || !IsCpp);
+
   // Never ever merge two words.
-  if (Keywords.isWordLike(Right) && Keywords.isWordLike(Left))
+  if (Keywords.isWordLike(Right, IsVerilog) &&
+  Keywords.isWordLike(Left, IsVerilog)) {
 return true;
+  }
 
   // Leave a space between * and /* to avoid C4138 `comment end` found outside
   // of comment.
@@ -5063,12 +5068,10 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine ,
 Right.is(TT_TemplateOpener)) {
   return true;
 }
-  } else if (Style.isVerilog()) {
+  } else if (IsVerilog) {
 // An escaped identifier ends with whitespace.
-if (Style.isVerilog() && Left.is(tok::identifier) &&
-Left.TokenText[0] == '\\') {
+if (Left.is(tok::identifier) && Left.TokenText[0] == '\\')
   return true;
-}
 // Add space between things in a primitive's state table unless in a
 // transition like `(0?)`.
 if ((Left.is(TT_VerilogTableItem) &&



___
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 Owen Pan via cfe-commits

https://github.com/owenca closed 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 Owen Pan via cfe-commits

https://github.com/owenca edited 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] [alpha.webkit.UncountedCallArgsChecker] Support more trivial expressions. (PR #90414)

2024-04-28 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/90414

>From ffc4df724e043e8655824bc2b3deb4e2ef632579 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sun, 28 Apr 2024 13:17:48 -0700
Subject: [PATCH] [alpha.webkit.UncountedCallArgsChecker] Support more trivial
 expressions.

Treat a bitwise not ~, compound operator such as |=, array subscription, sizeof,
and non-type template parameter as trivial so long as subexpressions are also 
trivial.

Also treat true/false boolean literal as trivial.
---
 .../Checkers/WebKit/PtrTypesSemantics.cpp | 23 ++-
 .../Checkers/WebKit/uncounted-obj-arg.cpp | 23 +++
 2 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 287f6a52870056..f6dd35c9e59868 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -311,7 +311,7 @@ class TrivialFunctionAnalysisVisitor
   bool VisitUnaryOperator(const UnaryOperator *UO) {
 // Operator '*' and '!' are allowed as long as the operand is trivial.
 auto op = UO->getOpcode();
-if (op == UO_Deref || op == UO_AddrOf || op == UO_LNot)
+if (op == UO_Deref || op == UO_AddrOf || op == UO_LNot || op == UO_Not)
   return Visit(UO->getSubExpr());
 
 if (UO->isIncrementOp() || UO->isDecrementOp()) {
@@ -331,6 +331,16 @@ class TrivialFunctionAnalysisVisitor
 return Visit(BO->getLHS()) && Visit(BO->getRHS());
   }
 
+  bool VisitCompoundAssignOperator(const CompoundAssignOperator *CAO) {
+// Compound assignment operator such as |= is trivial if its
+// subexpresssions are trivial.
+return VisitChildren(CAO);
+  }
+
+  bool VisitArraySubscriptExpr(const ArraySubscriptExpr *ASE) {
+return VisitChildren(ASE);
+  }
+
   bool VisitConditionalOperator(const ConditionalOperator *CO) {
 // Ternary operators are trivial if their conditions & values are trivial.
 return VisitChildren(CO);
@@ -360,6 +370,16 @@ class TrivialFunctionAnalysisVisitor
 return TrivialFunctionAnalysis::isTrivialImpl(Callee, Cache);
   }
 
+  bool
+  VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E) {
+// Non-type template paramter is trivial if the replacement is trivial.
+return Visit(E->getReplacement());
+  }
+
+  bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E) {
+return VisitChildren(E);
+  }
+
   bool VisitPredefinedExpr(const PredefinedExpr *E) {
 // A predefined identifier such as "func" is considered trivial.
 return true;
@@ -463,6 +483,7 @@ class TrivialFunctionAnalysisVisitor
   bool VisitFixedPointLiteral(const FixedPointLiteral *E) { return true; }
   bool VisitCharacterLiteral(const CharacterLiteral *E) { return true; }
   bool VisitStringLiteral(const StringLiteral *E) { return true; }
+  bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) { return true; }
 
   bool VisitConstantExpr(const ConstantExpr *CE) {
 // Constant expressions are trivial.
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index 80a9a263dab140..63a68a994a5c64 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -201,6 +201,13 @@ class RefCounted {
   unsigned trivial25() const { return __c11_atomic_load((volatile 
_Atomic(unsigned) *), __ATOMIC_RELAXED); }
   bool trivial26() { bool hasValue = v; return !hasValue; }
   bool trivial27(int v) { bool value; value = v ? 1 : 0; return value; }
+  bool trivial28() { return true; }
+  bool trivial29() { return false; }
+  unsigned trivial30(unsigned v) { unsigned r = 0xff; r |= v; return r; }
+  int trivial31(int* v) { return v[0]; }
+  unsigned trivial32() { return sizeof(int); }
+  unsigned trivial33() { return ~0xff; }
+  template  unsigned trivial34() { return v; }
 
   static RefCounted& singleton() {
 static RefCounted s_RefCounted;
@@ -273,6 +280,9 @@ class RefCounted {
 return val;
   }
 
+  int nonTrivial13() { return ~otherFunction(); }
+  int nonTrivial14() { int r = 0xff; r |= otherFunction(); return r; }
+
   unsigned v { 0 };
   Number* number { nullptr };
   Enum enumValue { Enum::Value1 };
@@ -322,6 +332,15 @@ class UnrelatedClass {
 getFieldTrivial().trivial25(); // no-warning
 getFieldTrivial().trivial26(); // no-warning
 getFieldTrivial().trivial27(5); // no-warning
+getFieldTrivial().trivial28(); // no-warning
+getFieldTrivial().trivial29(); // no-warning
+getFieldTrivial().trivial30(7); // no-warning
+int a[] = {1, 2};
+getFieldTrivial().trivial31(a); // no-warning
+getFieldTrivial().trivial32(); // no-warning
+getFieldTrivial().trivial33(); // no-warning
+getFieldTrivial().trivial34<7>(); // 

[clang] [alpha.webkit.UncountedCallArgsChecker] Support more trivial expressions. (PR #90414)

2024-04-28 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/90414

>From 44bff2897be7531b33d558b711034aa98755a4cd Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sun, 28 Apr 2024 13:17:48 -0700
Subject: [PATCH] [alpha.webkit.UncountedCallArgsChecker] Support more trivial
 expressions.

Treat a bitwise not ~, compound operator such as |=, array subscription, sizeof,
and non-type template parameter as trivial so long as subexpressions are also 
trivial.

Also treat true/false boolean literal as trivial.
---
 .../Checkers/WebKit/PtrTypesSemantics.cpp | 23 ++-
 .../WebKit/UncountedCallArgsChecker.cpp   |  2 +-
 .../Checkers/WebKit/uncounted-obj-arg.cpp | 23 +++
 3 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 287f6a52870056..f6dd35c9e59868 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -311,7 +311,7 @@ class TrivialFunctionAnalysisVisitor
   bool VisitUnaryOperator(const UnaryOperator *UO) {
 // Operator '*' and '!' are allowed as long as the operand is trivial.
 auto op = UO->getOpcode();
-if (op == UO_Deref || op == UO_AddrOf || op == UO_LNot)
+if (op == UO_Deref || op == UO_AddrOf || op == UO_LNot || op == UO_Not)
   return Visit(UO->getSubExpr());
 
 if (UO->isIncrementOp() || UO->isDecrementOp()) {
@@ -331,6 +331,16 @@ class TrivialFunctionAnalysisVisitor
 return Visit(BO->getLHS()) && Visit(BO->getRHS());
   }
 
+  bool VisitCompoundAssignOperator(const CompoundAssignOperator *CAO) {
+// Compound assignment operator such as |= is trivial if its
+// subexpresssions are trivial.
+return VisitChildren(CAO);
+  }
+
+  bool VisitArraySubscriptExpr(const ArraySubscriptExpr *ASE) {
+return VisitChildren(ASE);
+  }
+
   bool VisitConditionalOperator(const ConditionalOperator *CO) {
 // Ternary operators are trivial if their conditions & values are trivial.
 return VisitChildren(CO);
@@ -360,6 +370,16 @@ class TrivialFunctionAnalysisVisitor
 return TrivialFunctionAnalysis::isTrivialImpl(Callee, Cache);
   }
 
+  bool
+  VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E) {
+// Non-type template paramter is trivial if the replacement is trivial.
+return Visit(E->getReplacement());
+  }
+
+  bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E) {
+return VisitChildren(E);
+  }
+
   bool VisitPredefinedExpr(const PredefinedExpr *E) {
 // A predefined identifier such as "func" is considered trivial.
 return true;
@@ -463,6 +483,7 @@ class TrivialFunctionAnalysisVisitor
   bool VisitFixedPointLiteral(const FixedPointLiteral *E) { return true; }
   bool VisitCharacterLiteral(const CharacterLiteral *E) { return true; }
   bool VisitStringLiteral(const StringLiteral *E) { return true; }
+  bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) { return true; }
 
   bool VisitConstantExpr(const ConstantExpr *CE) {
 // Constant expressions are trivial.
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index 741f336761589f..96bae0de65a5b1 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -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)))
   return true;
 return RecursiveASTVisitor::TraverseDecl(D);
   }
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index 80a9a263dab140..63a68a994a5c64 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -201,6 +201,13 @@ class RefCounted {
   unsigned trivial25() const { return __c11_atomic_load((volatile 
_Atomic(unsigned) *), __ATOMIC_RELAXED); }
   bool trivial26() { bool hasValue = v; return !hasValue; }
   bool trivial27(int v) { bool value; value = v ? 1 : 0; return value; }
+  bool trivial28() { return true; }
+  bool trivial29() { return false; }
+  unsigned trivial30(unsigned v) { unsigned r = 0xff; r |= v; return r; }
+  int trivial31(int* v) { return v[0]; }
+  unsigned trivial32() { return sizeof(int); }
+  unsigned trivial33() { return ~0xff; }
+  template  unsigned trivial34() { return v; }
 
   static RefCounted& singleton() {
 static RefCounted s_RefCounted;
@@ -273,6 +280,9 @@ class RefCounted {
 return val;
   }
 
+  int nonTrivial13() { 

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

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 3ec858bc5d45ee22ca99febd38e1ba188f71022c 
9a39e456a41e415cca62866ca093708412871e00 -- 
clang/test/Analysis/Checkers/WebKit/call-args-regression-traverse-decl-crash.cpp
 clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
``





View the diff from clang-format here.


``diff
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index 6a5abf0c9d..ae494de58d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -56,7 +56,8 @@ public:
   bool TraverseClassTemplateDecl(ClassTemplateDecl *Decl) {
 if (isRefType(safeGetName(Decl)))
   return true;
-return 
RecursiveASTVisitor::TraverseClassTemplateDecl(Decl);
+return RecursiveASTVisitor::TraverseClassTemplateDecl(
+Decl);
   }
 
   bool VisitCallExpr(const CallExpr *CE) {

``




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] Fix a crash introduced by 3d5e9ab by adding a nullptr check. (PR #90301)

2024-04-28 Thread Ryosuke Niwa 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)))
   return true;
 return RecursiveASTVisitor::TraverseDecl(D);
   }

rniwa wrote:

Good point. That would be cleaner.

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] Fix a crash introduced by 3d5e9ab by adding a nullptr check. (PR #90301)

2024-04-28 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa updated https://github.com/llvm/llvm-project/pull/90301

>From 0e9d10029e6d498d3bc5a319ac0945cf23db230d Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Fri, 26 Apr 2024 17:01:35 -0700
Subject: [PATCH 1/3] Fix a crash introduced by 3d5e9ab by adding a nullptr
 check.

---
 .../StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index 741f336761589f..96bae0de65a5b1 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -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)))
   return true;
 return RecursiveASTVisitor::TraverseDecl(D);
   }

>From 37b5f788e903ce3175e4f961389eb5a1f503c884 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sat, 27 Apr 2024 14:03:38 -0700
Subject: [PATCH 2/3] Add a regression test.

---
 .../WebKit/call-args-regression-traverse-decl-crash.cpp| 7 +++
 1 file changed, 7 insertions(+)
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/call-args-regression-traverse-decl-crash.cpp

diff --git 
a/clang/test/Analysis/Checkers/WebKit/call-args-regression-traverse-decl-crash.cpp
 
b/clang/test/Analysis/Checkers/WebKit/call-args-regression-traverse-decl-crash.cpp
new file mode 100644
index 00..3d8e822025f62b
--- /dev/null
+++ 
b/clang/test/Analysis/Checkers/WebKit/call-args-regression-traverse-decl-crash.cpp
@@ -0,0 +1,7 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+// expected-no-diagnostics
+
+template  struct T;
+template  class Class, class Type>
+struct T>
+{ };

>From 9a39e456a41e415cca62866ca093708412871e00 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sun, 28 Apr 2024 13:43:30 -0700
Subject: [PATCH 3/3] Override TraverseClassTemplateDecl instead of
 TraverseDecl.

---
 .../Checkers/WebKit/UncountedCallArgsChecker.cpp| 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index 96bae0de65a5b1..6a5abf0c9d99db 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -53,10 +53,10 @@ class UncountedCallArgsChecker
   bool shouldVisitTemplateInstantiations() const { return true; }
   bool shouldVisitImplicitCode() const { return false; }
 
-  bool TraverseDecl(Decl *D) {
-if (D && isa(D) && isRefType(safeGetName(D)))
+  bool TraverseClassTemplateDecl(ClassTemplateDecl *Decl) {
+if (isRefType(safeGetName(Decl)))
   return true;
-return RecursiveASTVisitor::TraverseDecl(D);
+return 
RecursiveASTVisitor::TraverseClassTemplateDecl(Decl);
   }
 
   bool VisitCallExpr(const CallExpr *CE) {

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


[clang] [alpha.webkit.UncountedCallArgsChecker] Support more trivial expressions. (PR #90414)

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 3ec858bc5d45ee22ca99febd38e1ba188f71022c 
cc3b7f6c4d75aab856a8c31cc7ccfbcb5c6626e8 -- 
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 98ddf02bed..f6dd35c9e5 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -337,7 +337,7 @@ public:
 return VisitChildren(CAO);
   }
 
-  bool VisitArraySubscriptExpr(const ArraySubscriptExpr* ASE) {
+  bool VisitArraySubscriptExpr(const ArraySubscriptExpr *ASE) {
 return VisitChildren(ASE);
   }
 
@@ -370,13 +370,13 @@ public:
 return TrivialFunctionAnalysis::isTrivialImpl(Callee, Cache);
   }
 
-  bool VisitSubstNonTypeTemplateParmExpr(
-  const SubstNonTypeTemplateParmExpr* E) {
+  bool
+  VisitSubstNonTypeTemplateParmExpr(const SubstNonTypeTemplateParmExpr *E) {
 // Non-type template paramter is trivial if the replacement is trivial.
 return Visit(E->getReplacement());
   }
 
-  bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr* E) {
+  bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E) {
 return VisitChildren(E);
   }
 

``




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


[clang] [alpha.webkit.UncountedCallArgsChecker] Support more trivial expressions. (PR #90414)

2024-04-28 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-static-analyzer-1

Author: Ryosuke Niwa (rniwa)


Changes

Treat a compound operator such as |=, array subscription, sizeof, and non-type 
template parameter as trivial so long as subexpressions are also trivial.

Also treat true/false boolean literal as trivial.

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


3 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
(+22-1) 
- (modified) 
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp (+1-1) 
- (modified) clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp (+20) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 287f6a52870056..98ddf02bed9a78 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -311,7 +311,7 @@ class TrivialFunctionAnalysisVisitor
   bool VisitUnaryOperator(const UnaryOperator *UO) {
 // Operator '*' and '!' are allowed as long as the operand is trivial.
 auto op = UO->getOpcode();
-if (op == UO_Deref || op == UO_AddrOf || op == UO_LNot)
+if (op == UO_Deref || op == UO_AddrOf || op == UO_LNot || op == UO_Not)
   return Visit(UO->getSubExpr());
 
 if (UO->isIncrementOp() || UO->isDecrementOp()) {
@@ -331,6 +331,16 @@ class TrivialFunctionAnalysisVisitor
 return Visit(BO->getLHS()) && Visit(BO->getRHS());
   }
 
+  bool VisitCompoundAssignOperator(const CompoundAssignOperator *CAO) {
+// Compound assignment operator such as |= is trivial if its
+// subexpresssions are trivial.
+return VisitChildren(CAO);
+  }
+
+  bool VisitArraySubscriptExpr(const ArraySubscriptExpr* ASE) {
+return VisitChildren(ASE);
+  }
+
   bool VisitConditionalOperator(const ConditionalOperator *CO) {
 // Ternary operators are trivial if their conditions & values are trivial.
 return VisitChildren(CO);
@@ -360,6 +370,16 @@ class TrivialFunctionAnalysisVisitor
 return TrivialFunctionAnalysis::isTrivialImpl(Callee, Cache);
   }
 
+  bool VisitSubstNonTypeTemplateParmExpr(
+  const SubstNonTypeTemplateParmExpr* E) {
+// Non-type template paramter is trivial if the replacement is trivial.
+return Visit(E->getReplacement());
+  }
+
+  bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr* E) {
+return VisitChildren(E);
+  }
+
   bool VisitPredefinedExpr(const PredefinedExpr *E) {
 // A predefined identifier such as "func" is considered trivial.
 return true;
@@ -463,6 +483,7 @@ class TrivialFunctionAnalysisVisitor
   bool VisitFixedPointLiteral(const FixedPointLiteral *E) { return true; }
   bool VisitCharacterLiteral(const CharacterLiteral *E) { return true; }
   bool VisitStringLiteral(const StringLiteral *E) { return true; }
+  bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) { return true; }
 
   bool VisitConstantExpr(const ConstantExpr *CE) {
 // Constant expressions are trivial.
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index 741f336761589f..96bae0de65a5b1 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -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)))
   return true;
 return RecursiveASTVisitor::TraverseDecl(D);
   }
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index 80a9a263dab140..472be2dc2b978a 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -201,6 +201,12 @@ class RefCounted {
   unsigned trivial25() const { return __c11_atomic_load((volatile 
_Atomic(unsigned) *), __ATOMIC_RELAXED); }
   bool trivial26() { bool hasValue = v; return !hasValue; }
   bool trivial27(int v) { bool value; value = v ? 1 : 0; return value; }
+  bool trivial28() { return true; }
+  bool trivial29() { return false; }
+  unsigned trivial30() { return ~0xff; }
+  template  unsigned trivial31() { return v; }
+  unsigned trivial32(unsigned v) { unsigned r = 0xff; r |= v; return r; }
+  unsigned trivial33() { return sizeof(int); }
 
   static RefCounted& singleton() {
 static RefCounted s_RefCounted;
@@ -273,6 +279,9 @@ class RefCounted {
 return val;
   }
 
+  int nonTrivial13() { return ~otherFunction(); }
+  int nonTrivial14() { int r = 0xff; r |= otherFunction(); return r; }
+
   unsigned v { 0 

[clang] [alpha.webkit.UncountedCallArgsChecker] Support more trivial expressions. (PR #90414)

2024-04-28 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa created https://github.com/llvm/llvm-project/pull/90414

Treat a compound operator such as |=, array subscription, sizeof, and non-type 
template parameter as trivial so long as subexpressions are also trivial.

Also treat true/false boolean literal as trivial.

>From cc3b7f6c4d75aab856a8c31cc7ccfbcb5c6626e8 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sun, 28 Apr 2024 13:17:48 -0700
Subject: [PATCH] [alpha.webkit.UncountedCallArgsChecker] Support more trivial
 expressions.

Treat a compound operator such as |=, array subscription, sizeof, and non-type
template parameter as trivial so long as subexpressions are also trivial.

Also treat true/false boolean literal as trivial.
---
 .../Checkers/WebKit/PtrTypesSemantics.cpp | 23 ++-
 .../WebKit/UncountedCallArgsChecker.cpp   |  2 +-
 .../Checkers/WebKit/uncounted-obj-arg.cpp | 20 
 3 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 287f6a52870056..98ddf02bed9a78 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -311,7 +311,7 @@ class TrivialFunctionAnalysisVisitor
   bool VisitUnaryOperator(const UnaryOperator *UO) {
 // Operator '*' and '!' are allowed as long as the operand is trivial.
 auto op = UO->getOpcode();
-if (op == UO_Deref || op == UO_AddrOf || op == UO_LNot)
+if (op == UO_Deref || op == UO_AddrOf || op == UO_LNot || op == UO_Not)
   return Visit(UO->getSubExpr());
 
 if (UO->isIncrementOp() || UO->isDecrementOp()) {
@@ -331,6 +331,16 @@ class TrivialFunctionAnalysisVisitor
 return Visit(BO->getLHS()) && Visit(BO->getRHS());
   }
 
+  bool VisitCompoundAssignOperator(const CompoundAssignOperator *CAO) {
+// Compound assignment operator such as |= is trivial if its
+// subexpresssions are trivial.
+return VisitChildren(CAO);
+  }
+
+  bool VisitArraySubscriptExpr(const ArraySubscriptExpr* ASE) {
+return VisitChildren(ASE);
+  }
+
   bool VisitConditionalOperator(const ConditionalOperator *CO) {
 // Ternary operators are trivial if their conditions & values are trivial.
 return VisitChildren(CO);
@@ -360,6 +370,16 @@ class TrivialFunctionAnalysisVisitor
 return TrivialFunctionAnalysis::isTrivialImpl(Callee, Cache);
   }
 
+  bool VisitSubstNonTypeTemplateParmExpr(
+  const SubstNonTypeTemplateParmExpr* E) {
+// Non-type template paramter is trivial if the replacement is trivial.
+return Visit(E->getReplacement());
+  }
+
+  bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr* E) {
+return VisitChildren(E);
+  }
+
   bool VisitPredefinedExpr(const PredefinedExpr *E) {
 // A predefined identifier such as "func" is considered trivial.
 return true;
@@ -463,6 +483,7 @@ class TrivialFunctionAnalysisVisitor
   bool VisitFixedPointLiteral(const FixedPointLiteral *E) { return true; }
   bool VisitCharacterLiteral(const CharacterLiteral *E) { return true; }
   bool VisitStringLiteral(const StringLiteral *E) { return true; }
+  bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E) { return true; }
 
   bool VisitConstantExpr(const ConstantExpr *CE) {
 // Constant expressions are trivial.
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index 741f336761589f..96bae0de65a5b1 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -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)))
   return true;
 return RecursiveASTVisitor::TraverseDecl(D);
   }
diff --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
index 80a9a263dab140..472be2dc2b978a 100644
--- a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -201,6 +201,12 @@ class RefCounted {
   unsigned trivial25() const { return __c11_atomic_load((volatile 
_Atomic(unsigned) *), __ATOMIC_RELAXED); }
   bool trivial26() { bool hasValue = v; return !hasValue; }
   bool trivial27(int v) { bool value; value = v ? 1 : 0; return value; }
+  bool trivial28() { return true; }
+  bool trivial29() { return false; }
+  unsigned trivial30() { return ~0xff; }
+  template  unsigned trivial31() { return v; }
+  unsigned trivial32(unsigned v) { unsigned r = 0xff; r |= v; return r; }
+  unsigned trivial33() { return sizeof(int); }
 
   static 

[clang] [alpha.webkit.UncountedCallArgsChecker] Treat true/false as trivial (PR #90169)

2024-04-28 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa closed https://github.com/llvm/llvm-project/pull/90169
___
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 , 
StringRef Arch) {
 void AMDGPU::fillAMDGPUFeatureMap(StringRef GPU, const Triple ,
   StringMap ) {
   // 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:

Yes, that is correct; the ME piece I mentioned will deal with avoiding spurious 
errors such as a piece of dead code invoking a `gfx12` instruction when JITing 
to a `gfx9` target, so that we only fail on actual misuses.

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 Danny Mösch 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:

SimplyDanny wrote:

```suggestion
  would be converted to
```

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


@@ -0,0 +1,107 @@
+//===--- 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 ,
+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 ) {
+  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 ) {
+  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")

SimplyDanny wrote:

```suggestion
  "unable to use '%0' instead of '%1' because 
%2")
```

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


@@ -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:

SimplyDanny wrote:

```suggestion
   `StrictMode` enabled,
```

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


@@ -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:

SimplyDanny wrote:

```suggestion
For example, it turns lines like
```

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


@@ -0,0 +1,107 @@
+//===--- 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 ,
+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 ) {
+  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 ) {
+  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")

SimplyDanny wrote:

```suggestion
  diag(StrFormatCall->getBeginLoc(), "use '%0' instead of '%1'")
```

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


[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] 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 = 
   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] 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 = 
   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] [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] [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] 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] 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;
 

[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] [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 
,
   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 , DiagnosticsEngine , StringRef,
+const std::vector ) const {
+  llvm::AMDGPU::fillAMDGPUFeatureMap({}, getTriple(), Features);
+
+  return TargetInfo::initFeatureMap(Features, Diags, {}, FeatureVec);
+}
+
+bool SPIRV64AMDGCNTargetInfo::validateAsmConstraint(
+const char *, TargetInfo::ConstraintInfo ) const {
+  return AMDGPUTI.validateAsmConstraint(Name, Info);
+}
+
+std::string
+SPIRV64AMDGCNTargetInfo::convertConstraint(const char *) const {
+  return AMDGPUTI.convertConstraint(Constraint);
+}
+
+ArrayRef SPIRV64AMDGCNTargetInfo::getTargetBuiltins() const {
+  return AMDGPUTI.getTargetBuiltins();
+}
+
+void SPIRV64AMDGCNTargetInfo::getTargetDefines(const LangOptions ,
+   MacroBuilder ) 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 Alex Voicu via cfe-commits


@@ -54,3 +56,76 @@ void SPIRV64TargetInfo::getTargetDefines(const LangOptions 
,
   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 , DiagnosticsEngine , StringRef,
+const std::vector ) const {
+  llvm::AMDGPU::fillAMDGPUFeatureMap({}, getTriple(), Features);
+
+  return TargetInfo::initFeatureMap(Features, Diags, {}, FeatureVec);
+}
+
+bool SPIRV64AMDGCNTargetInfo::validateAsmConstraint(
+const char *, TargetInfo::ConstraintInfo ) const {
+  return AMDGPUTI.validateAsmConstraint(Name, Info);
+}
+
+std::string
+SPIRV64AMDGCNTargetInfo::convertConstraint(const char *) const {
+  return AMDGPUTI.convertConstraint(Constraint);
+}
+
+ArrayRef SPIRV64AMDGCNTargetInfo::getTargetBuiltins() const {
+  return AMDGPUTI.getTargetBuiltins();
+}
+
+void SPIRV64AMDGCNTargetInfo::getTargetDefines(const LangOptions ,
+   MacroBuilder ) 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 
,
   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 , DiagnosticsEngine , StringRef,
+const std::vector ) const {
+  llvm::AMDGPU::fillAMDGPUFeatureMap({}, getTriple(), Features);
+
+  return TargetInfo::initFeatureMap(Features, Diags, {}, FeatureVec);
+}
+
+bool SPIRV64AMDGCNTargetInfo::validateAsmConstraint(
+const char *, TargetInfo::ConstraintInfo ) const {
+  return AMDGPUTI.validateAsmConstraint(Name, Info);
+}
+
+std::string
+SPIRV64AMDGCNTargetInfo::convertConstraint(const char *) const {
+  return AMDGPUTI.convertConstraint(Constraint);
+}
+
+ArrayRef SPIRV64AMDGCNTargetInfo::getTargetBuiltins() const {
+  return AMDGPUTI.getTargetBuiltins();
+}
+
+void SPIRV64AMDGCNTargetInfo::getTargetDefines(const LangOptions ,
+   MacroBuilder ) 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 Joseph Huber via cfe-commits


@@ -309,7 +309,45 @@ StringRef AMDGPU::getCanonicalArchName(const Triple , 
StringRef Arch) {
 void AMDGPU::fillAMDGPUFeatureMap(StringRef GPU, const Triple ,
   StringMap ) {
   // 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 Alex Voicu via cfe-commits


@@ -309,7 +309,45 @@ StringRef AMDGPU::getCanonicalArchName(const Triple , 
StringRef Arch) {
 void AMDGPU::fillAMDGPUFeatureMap(StringRef GPU, const Triple ,
   StringMap ) {
   // 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 , 
StringRef Arch) {
 void AMDGPU::fillAMDGPUFeatureMap(StringRef GPU, const Triple ,
   StringMap ) {
   // 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-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 ) {
+  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-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


@@ -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 ) {
+  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(); 
}
+} // 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 ) {
+  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,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 ) {
+  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,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 ) {
+  try {
+throw exception();
+  } catch(...) {}
+  }
+}
+
+void not_correct() {
+  try {
+  throw exception();
+  } catch(const exception ) {
+  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 ) {
+  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] [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] [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 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] 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 ,
   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-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 ,
+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 ) {
+  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 ) {
+  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 
`OldFunction` 

[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 *();
+};
+
+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 , 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 = , *ps2 = , *ps3 = 
+  auto s5 = absl::StrFormat("c_str() removal pointer width only:%-*s width and 
precision:%-*.*s precision only:%-.*s", 3, ps1->c_str(), 4, 2, ps2->c_str(), 

[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)),
+  

[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 ,
 
   // 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 ,
const std::unique_ptr ) {
-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] [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 ,
 
   // 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] [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] [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 ,
   }
   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 
,
   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", "v125",
+  

[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 
,
   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 , DiagnosticsEngine , StringRef,
+const std::vector ) const {
+  llvm::AMDGPU::fillAMDGPUFeatureMap({}, getTriple(), Features);
+
+  return TargetInfo::initFeatureMap(Features, Diags, {}, FeatureVec);
+}
+
+bool SPIRV64AMDGCNTargetInfo::validateAsmConstraint(
+const char *, TargetInfo::ConstraintInfo ) const {
+  return AMDGPUTI.validateAsmConstraint(Name, Info);
+}
+
+std::string
+SPIRV64AMDGCNTargetInfo::convertConstraint(const char *) const {
+  return AMDGPUTI.convertConstraint(Constraint);
+}
+
+ArrayRef SPIRV64AMDGCNTargetInfo::getTargetBuiltins() const {
+  return AMDGPUTI.getTargetBuiltins();
+}
+
+void SPIRV64AMDGCNTargetInfo::getTargetDefines(const LangOptions ,
+   MacroBuilder ) 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-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 *();
+};
+
+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 , 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 = , *ps2 = , *ps3 = 
+  auto s5 = absl::StrFormat("c_str() removal pointer width only:%-*s width and 
precision:%-*.*s precision only:%-.*s", 3, ps1->c_str(), 4, 2, ps2->c_str(), 

[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,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


@@ -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,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 ,
+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 ) {
+  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 ) {
+  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

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

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


@@ -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 ,
+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 ) {
+  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 ) {
+  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] [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 
,
   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] [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 
,
   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 , DiagnosticsEngine , StringRef,
+const std::vector ) const {
+  llvm::AMDGPU::fillAMDGPUFeatureMap({}, getTriple(), Features);
+
+  return TargetInfo::initFeatureMap(Features, Diags, {}, FeatureVec);
+}
+
+bool SPIRV64AMDGCNTargetInfo::validateAsmConstraint(
+const char *, TargetInfo::ConstraintInfo ) const {
+  return AMDGPUTI.validateAsmConstraint(Name, Info);
+}
+
+std::string
+SPIRV64AMDGCNTargetInfo::convertConstraint(const char *) const {
+  return AMDGPUTI.convertConstraint(Constraint);
+}
+
+ArrayRef SPIRV64AMDGCNTargetInfo::getTargetBuiltins() const {
+  return AMDGPUTI.getTargetBuiltins();
+}
+
+void SPIRV64AMDGCNTargetInfo::getTargetDefines(const LangOptions ,
+   MacroBuilder ) 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


@@ -673,8 +673,12 @@ std::unique_ptr AllocateTarget(const 
llvm::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] [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 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 ,
   }
   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 
,
   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", "v125",
+  

[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 ,
   }
   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 
,
   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", "v125",
+  

  1   2   >