[clang] [Clang] Reduce the size of Decl and classes derived from it (PR #87361)

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

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

>From b8a626116b0719c1acf75e9e7300df8e2bf82f99 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Tue, 2 Apr 2024 18:00:05 +0200
Subject: [PATCH 1/3] [Clang] Reduce the size of Decl and classes derived from
 it

---
 clang/include/clang/AST/DeclBase.h| 66 ++-
 clang/lib/AST/DeclBase.cpp| 29 ++
 clang/lib/Serialization/ASTReaderDecl.cpp |  2 +-
 3 files changed, 62 insertions(+), 35 deletions(-)

diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 47ed6d0d1db0df..172bd581b527c8 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -268,17 +268,34 @@ class alignas(8) Decl {
   ///   }
   ///   void A::f(); // SemanticDC == namespace 'A'
   ///// LexicalDC == global namespace
-  llvm::PointerUnion DeclCtx;
+  llvm::PointerIntPair<
+  llvm::PointerIntPair, 1,
+   bool>,
+  1, bool>
+  DeclCtxWithInvalidDeclAndHasAttrs;
 
-  bool isInSemaDC() const { return DeclCtx.is(); }
-  bool isOutOfSemaDC() const { return DeclCtx.is(); }
+  bool isInSemaDC() const {
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.is();
+  }
+
+  bool isOutOfSemaDC() const {
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.is();
+  }
 
   MultipleDC *getMultipleDC() const {
-return DeclCtx.get();
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.get();
   }
 
   DeclContext *getSemanticDC() const {
-return DeclCtx.get();
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.get();
   }
 
   /// Loc - The location of this decl.
@@ -288,14 +305,6 @@ class alignas(8) Decl {
   LLVM_PREFERRED_TYPE(Kind)
   unsigned DeclKind : 7;
 
-  /// InvalidDecl - This indicates a semantic error occurred.
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned InvalidDecl :  1;
-
-  /// HasAttrs - This indicates whether the decl has attributes or not.
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned HasAttrs : 1;
-
   /// Implicit - Whether this declaration was implicitly generated by
   /// the implementation rather than explicitly written by the user.
   LLVM_PREFERRED_TYPE(bool)
@@ -393,21 +402,22 @@ class alignas(8) Decl {
 protected:
   Decl(Kind DK, DeclContext *DC, SourceLocation L)
   : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),
-DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false),
-Implicit(false), Used(false), Referenced(false),
+DeclCtxWithInvalidDeclAndHasAttrs({DC, false}, false), Loc(L),
+DeclKind(DK), Implicit(false), Used(false), Referenced(false),
 TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled) add(DK);
+if (StatisticsEnabled)
+  add(DK);
   }
 
   Decl(Kind DK, EmptyShell Empty)
-  : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false),
-Used(false), Referenced(false), TopLevelDeclInObjCContainer(false),
-Access(AS_none), FromASTFile(0),
+  : DeclKind(DK), Implicit(false), Used(false), Referenced(false),
+TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled) add(DK);
+if (StatisticsEnabled)
+  add(DK);
   }
 
   virtual ~Decl();
@@ -520,7 +530,7 @@ class alignas(8) Decl {
 return AccessSpecifier(Access);
   }
 
-  bool hasAttrs() const { return HasAttrs; }
+  bool hasAttrs() const { return 
DeclCtxWithInvalidDeclAndHasAttrs.getPointer().getInt(); }
 
   void setAttrs(const AttrVec& Attrs) {
 return setAttrsImpl(Attrs, getASTContext());
@@ -549,13 +559,16 @@ class alignas(8) Decl {
   }
 
   template  void dropAttrs() {
-if (!HasAttrs) return;
+if (!hasAttrs()) return;
 
 AttrVec &Vec = getAttrs();
 llvm::erase_if(Vec, [](Attr *A) { return isa(A); });
 
-if (Vec.empty())
-  HasAttrs = false;
+if (Vec.empty()) {
+  auto InnerPtr = DeclCtxWithInvalidDeclAndHasAttrs.getPointer();
+  InnerPtr.setInt(false);
+  DeclCtxWithInvalidDeclAndHasAttrs.setPointer(InnerPtr);
+}
   }
 
   template  void dropAttr() { dropAttrs(); }
@@ -590,7 +603,10 @@ class alignas(8) Decl {
   /// setInvalidDecl - Indicates the Decl had a semantic error. This
   /// allows for graceful error recovery.
   void setInvalidDecl(bool Invalid = true);
-  bool isInvalidDecl() const { return (bool) InvalidDecl; }
+
+  bool isInvalidDecl() const {
+return DeclCtxWithInvalidDeclAndHasAttrs.getInt();
+

[clang] [Clang][Sema] Fix issue on requires expression with templated base class member function (PR #85198)

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

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


[clang] [clang] Fix high memory consumption during pack deduction (PR #88637)

2024-04-14 Thread via cfe-commits

term-est wrote:

Thank you for your feedback! Will add a reproducible example and update the 
`ReleaseNotes.rst`
I will also try to add a test if I can~

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


[clang] [llvm] [ARM] Armv8-R does not require fp64 or neon. (PR #88287)

2024-04-14 Thread Chris Copeland via cfe-commits

https://github.com/chrisnc updated 
https://github.com/llvm/llvm-project/pull/88287

>From f707f292a6153f9d23734e490720db3abb5c00ac Mon Sep 17 00:00:00 2001
From: Chris Copeland 
Date: Fri, 5 Apr 2024 22:40:46 -0700
Subject: [PATCH] [ARM] Armv8-R does not require fp64 or neon.

---
 clang/test/Preprocessor/arm-target-features.c  | 2 +-
 llvm/include/llvm/TargetParser/ARMTargetParser.def | 2 +-
 llvm/lib/Target/ARM/ARM.td | 6 +++---
 llvm/test/Analysis/CostModel/ARM/arith.ll  | 2 +-
 llvm/test/Analysis/CostModel/ARM/cast.ll   | 4 ++--
 llvm/test/Analysis/CostModel/ARM/cast_ldst.ll  | 4 ++--
 llvm/test/Analysis/CostModel/ARM/cmps.ll   | 4 ++--
 llvm/test/Analysis/CostModel/ARM/divrem.ll | 2 +-
 llvm/test/CodeGen/ARM/build-attributes.ll  | 4 ++--
 llvm/test/CodeGen/ARM/cortex-a57-misched-basic.ll  | 2 +-
 llvm/test/CodeGen/ARM/fpconv.ll| 4 ++--
 llvm/test/CodeGen/ARM/half.ll  | 4 ++--
 llvm/test/CodeGen/ARM/misched-fp-basic.ll  | 2 +-
 llvm/test/CodeGen/ARM/pr42638-VMOVRRDCombine.ll| 2 +-
 llvm/test/CodeGen/ARM/useaa.ll | 4 ++--
 llvm/unittests/TargetParser/TargetParserTest.cpp   | 2 +-
 16 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/clang/test/Preprocessor/arm-target-features.c 
b/clang/test/Preprocessor/arm-target-features.c
index 236c9f2479b705..ad418bf6bcdcbf 100644
--- a/clang/test/Preprocessor/arm-target-features.c
+++ b/clang/test/Preprocessor/arm-target-features.c
@@ -96,7 +96,7 @@
 // CHECK-V8R-ALLOW-FP-INSTR: #define __ARM_FEATURE_CRC32 1
 // CHECK-V8R-ALLOW-FP-INSTR: #define __ARM_FEATURE_DIRECTED_ROUNDING 1
 // CHECK-V8R-ALLOW-FP-INSTR: #define __ARM_FEATURE_NUMERIC_MAXMIN 1
-// CHECK-V8R-ALLOW-FP-INSTR: #define __ARM_FP 0xe
+// CHECK-V8R-ALLOW-FP-INSTR: #define __ARM_FP 0x6
 
 // RUN: %clang -target armv7a-none-linux-gnu -x c -E -dM %s -o - | FileCheck 
-match-full-lines --check-prefix=CHECK-V7 %s
 // CHECK-V7: #define __ARMEL__ 1
diff --git a/llvm/include/llvm/TargetParser/ARMTargetParser.def 
b/llvm/include/llvm/TargetParser/ARMTargetParser.def
index b821d224d7a82c..dee0f383b4b234 100644
--- a/llvm/include/llvm/TargetParser/ARMTargetParser.def
+++ b/llvm/include/llvm/TargetParser/ARMTargetParser.def
@@ -329,7 +329,7 @@ ARM_CPU_NAME("cortex-r7", ARMV7R, FK_VFPV3_D16_FP16, false,
  (ARM::AEK_MP | ARM::AEK_HWDIVARM))
 ARM_CPU_NAME("cortex-r8", ARMV7R, FK_VFPV3_D16_FP16, false,
  (ARM::AEK_MP | ARM::AEK_HWDIVARM))
-ARM_CPU_NAME("cortex-r52", ARMV8R, FK_NEON_FP_ARMV8, true, ARM::AEK_NONE)
+ARM_CPU_NAME("cortex-r52", ARMV8R, FK_FPV5_SP_D16, true, ARM::AEK_NONE)
 ARM_CPU_NAME("sc300", ARMV7M, FK_NONE, false, ARM::AEK_NONE)
 ARM_CPU_NAME("cortex-m3", ARMV7M, FK_NONE, true, ARM::AEK_NONE)
 ARM_CPU_NAME("cortex-m4", ARMV7EM, FK_FPV4_SP_D16, true, ARM::AEK_NONE)
diff --git a/llvm/lib/Target/ARM/ARM.td b/llvm/lib/Target/ARM/ARM.td
index 66596dbda83c95..6ee8c0540e6488 100644
--- a/llvm/lib/Target/ARM/ARM.td
+++ b/llvm/lib/Target/ARM/ARM.td
@@ -1167,9 +1167,7 @@ def ARMv8r: Architecture<"armv8-r",   "ARMv8r",   
[HasV8Ops,
FeatureDSP,
FeatureCRC,
FeatureMP,
-   FeatureVirtualization,
-   FeatureFPARMv8,
-   FeatureNEON]>;
+   FeatureVirtualization]>;
 
 def ARMv8mBaseline : Architecture<"armv8-m.base", "ARMv8mBaseline",
   [HasV8MBaselineOps,
@@ -1726,6 +1724,8 @@ def : ProcNoItin<"kryo",
[ARMv8a, ProcKryo,
  FeatureCRC]>;
 
 def : ProcessorModel<"cortex-r52", CortexR52Model,  [ARMv8r, ProcR52,
+ FeatureFPARMv8_D16_SP,
+ FeatureFP16,
  FeatureUseMISched,
  FeatureFPAO]>;
 
diff --git a/llvm/test/Analysis/CostModel/ARM/arith.ll 
b/llvm/test/Analysis/CostModel/ARM/arith.ll
index 3a137a5af36664..8f173596c3b9a0 100644
--- a/llvm/test/Analysis/CostModel/ARM/arith.ll
+++ b/llvm/test/Analysis/CostModel/ARM/arith.ll
@@ -4,7 +4,7 @@
 ; RUN: opt -passes="print" 2>&1 -disable-output 
-mtriple=thumbv8.1m.main-none-eabi -mattr=+mve,+mve4beat < %s | FileCheck %s 
--check-prefix=CHECK --check-prefix=CHECK-MVE4
 ; RUN: opt -passes="print" 2>&1 -disable-output 
-mtriple=thumbv8m.main-none-eabi < %s | FileCheck %s 
--check-prefix=CHECK-V8M-MAIN
 ; RUN: opt -passes="print" 2>&1 -disable-output 
-mtriple=thumb

[clang] [Clang][Sema] Fix issue on requires expression with templated base class member function (PR #85198)

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

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


[clang] [clang][NFC] Factor out VLA check in type traits (PR #88646)

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

https://github.com/Endilll created 
https://github.com/llvm/llvm-project/pull/88646

This is a follow-up to #88473 suggested by @cor3ntin in 
https://github.com/llvm/llvm-project/pull/88473#discussion_r1562198117.

>From 34d735b2f85e3c24cbf725f6a519afec6c916820 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sun, 14 Apr 2024 10:41:53 +0300
Subject: [PATCH] [clang][NFC] Factor out VLA check in type traits

---
 clang/lib/Sema/SemaExprCXX.cpp | 59 ++
 1 file changed, 31 insertions(+), 28 deletions(-)

diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 1cfd3e56a583eb..d2f18d4aa9b980 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5012,6 +5012,20 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
   return From;
 }
 
+/// Checks that type T is not a VLA.
+///
+/// @returns @c true if @p T is VLA and a diagnostic was emitted,
+/// @c false otherwise.
+static bool DiagnoseVLAInCXXTypeTrait(Sema &S, const TypeSourceInfo *T,
+  clang::tok::TokenKind TypeTraitID) {
+  if (!T->getType()->isVariableArrayType())
+return false;
+
+  S.Diag(T->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
+  << 1 << TypeTraitID;
+  return true;
+}
+
 /// Check the completeness of a type in a unary type trait.
 ///
 /// If the particular type trait requires a complete type, tries to complete
@@ -5188,7 +5202,9 @@ static bool HasNoThrowOperator(const RecordType *RT, 
OverloadedOperatorKind Op,
 }
 
 static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait UTT,
-   SourceLocation KeyLoc, QualType T) {
+   SourceLocation KeyLoc,
+   TypeSourceInfo *TInfo) {
+  QualType T = TInfo->getType();
   assert(!T->isDependentType() && "Cannot evaluate traits of dependent type");
 
   ASTContext &C = Self.Context;
@@ -5205,21 +5221,13 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, 
TypeTrait UTT,
   case UTT_IsArray:
 return T->isArrayType();
   case UTT_IsBoundedArray:
-if (!T->isVariableArrayType()) {
-  return T->isArrayType() && !T->isIncompleteArrayType();
-}
-
-Self.Diag(KeyLoc, diag::err_vla_unsupported)
-<< 1 << tok::kw___is_bounded_array;
-return false;
+if (DiagnoseVLAInCXXTypeTrait(Self, TInfo, tok::kw___is_bounded_array))
+  return false;
+return T->isArrayType() && !T->isIncompleteArrayType();
   case UTT_IsUnboundedArray:
-if (!T->isVariableArrayType()) {
-  return T->isIncompleteArrayType();
-}
-
-Self.Diag(KeyLoc, diag::err_vla_unsupported)
-<< 1 << tok::kw___is_unbounded_array;
-return false;
+if (DiagnoseVLAInCXXTypeTrait(Self, TInfo, tok::kw___is_unbounded_array))
+  return false;
+return T->isIncompleteArrayType();
   case UTT_IsPointer:
 return T->isAnyPointerType();
   case UTT_IsNullPointer:
@@ -5631,7 +5639,7 @@ static bool EvaluateBooleanTypeTrait(Sema &S, TypeTrait 
Kind,
 return false;
 
   if (Kind <= UTT_Last)
-return EvaluateUnaryTypeTrait(S, Kind, KWLoc, Args[0]->getType());
+return EvaluateUnaryTypeTrait(S, Kind, KWLoc, Args[0]);
 
   // Evaluate ReferenceBindsToTemporary and ReferenceConstructsFromTemporary
   // alongside the IsConstructible traits to avoid duplication.
@@ -6093,12 +6101,9 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, 
TypeTrait BTT, const TypeSourceI
   Self.RequireCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT,
diag::err_incomplete_type);
 
-if (LhsT->isVariableArrayType())
-  Self.Diag(Lhs->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
-  << 1 << tok::kw___is_layout_compatible;
-if (RhsT->isVariableArrayType())
-  Self.Diag(Rhs->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
-  << 1 << tok::kw___is_layout_compatible;
+DiagnoseVLAInCXXTypeTrait(Self, Lhs, tok::kw___is_layout_compatible);
+DiagnoseVLAInCXXTypeTrait(Self, Rhs, tok::kw___is_layout_compatible);
+
 return Self.IsLayoutCompatible(LhsT, RhsT);
   }
   case BTT_IsPointerInterconvertibleBaseOf: {
@@ -6108,12 +6113,10 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, 
TypeTrait BTT, const TypeSourceI
diag::err_incomplete_type);
 }
 
-if (LhsT->isVariableArrayType())
-  Self.Diag(Lhs->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
-  << 1 << tok::kw___is_pointer_interconvertible_base_of;
-if (RhsT->isVariableArrayType())
-  Self.Diag(Rhs->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
-  << 1 << tok::kw___is_pointer_interconvertible_base_of;
+DiagnoseVLAInCXXTypeTrait(Self, Lhs,
+  tok::kw___is_pointer_interconvertible_base_of);
+DiagnoseVLAInCXXTypeTrait(Self, Rhs,
+  tok::kw___is_pointer_interconvertible_base_of);
 
 

[clang] [clang][NFC] Factor out VLA check in type traits (PR #88646)

2024-04-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)


Changes

This is a follow-up to #88473 suggested by @cor3ntin in 
https://github.com/llvm/llvm-project/pull/88473#discussion_r1562198117.

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


1 Files Affected:

- (modified) clang/lib/Sema/SemaExprCXX.cpp (+31-28) 


``diff
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 1cfd3e56a583eb..d2f18d4aa9b980 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5012,6 +5012,20 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
   return From;
 }
 
+/// Checks that type T is not a VLA.
+///
+/// @returns @c true if @p T is VLA and a diagnostic was emitted,
+/// @c false otherwise.
+static bool DiagnoseVLAInCXXTypeTrait(Sema &S, const TypeSourceInfo *T,
+  clang::tok::TokenKind TypeTraitID) {
+  if (!T->getType()->isVariableArrayType())
+return false;
+
+  S.Diag(T->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
+  << 1 << TypeTraitID;
+  return true;
+}
+
 /// Check the completeness of a type in a unary type trait.
 ///
 /// If the particular type trait requires a complete type, tries to complete
@@ -5188,7 +5202,9 @@ static bool HasNoThrowOperator(const RecordType *RT, 
OverloadedOperatorKind Op,
 }
 
 static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait UTT,
-   SourceLocation KeyLoc, QualType T) {
+   SourceLocation KeyLoc,
+   TypeSourceInfo *TInfo) {
+  QualType T = TInfo->getType();
   assert(!T->isDependentType() && "Cannot evaluate traits of dependent type");
 
   ASTContext &C = Self.Context;
@@ -5205,21 +5221,13 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, 
TypeTrait UTT,
   case UTT_IsArray:
 return T->isArrayType();
   case UTT_IsBoundedArray:
-if (!T->isVariableArrayType()) {
-  return T->isArrayType() && !T->isIncompleteArrayType();
-}
-
-Self.Diag(KeyLoc, diag::err_vla_unsupported)
-<< 1 << tok::kw___is_bounded_array;
-return false;
+if (DiagnoseVLAInCXXTypeTrait(Self, TInfo, tok::kw___is_bounded_array))
+  return false;
+return T->isArrayType() && !T->isIncompleteArrayType();
   case UTT_IsUnboundedArray:
-if (!T->isVariableArrayType()) {
-  return T->isIncompleteArrayType();
-}
-
-Self.Diag(KeyLoc, diag::err_vla_unsupported)
-<< 1 << tok::kw___is_unbounded_array;
-return false;
+if (DiagnoseVLAInCXXTypeTrait(Self, TInfo, tok::kw___is_unbounded_array))
+  return false;
+return T->isIncompleteArrayType();
   case UTT_IsPointer:
 return T->isAnyPointerType();
   case UTT_IsNullPointer:
@@ -5631,7 +5639,7 @@ static bool EvaluateBooleanTypeTrait(Sema &S, TypeTrait 
Kind,
 return false;
 
   if (Kind <= UTT_Last)
-return EvaluateUnaryTypeTrait(S, Kind, KWLoc, Args[0]->getType());
+return EvaluateUnaryTypeTrait(S, Kind, KWLoc, Args[0]);
 
   // Evaluate ReferenceBindsToTemporary and ReferenceConstructsFromTemporary
   // alongside the IsConstructible traits to avoid duplication.
@@ -6093,12 +6101,9 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, 
TypeTrait BTT, const TypeSourceI
   Self.RequireCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT,
diag::err_incomplete_type);
 
-if (LhsT->isVariableArrayType())
-  Self.Diag(Lhs->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
-  << 1 << tok::kw___is_layout_compatible;
-if (RhsT->isVariableArrayType())
-  Self.Diag(Rhs->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
-  << 1 << tok::kw___is_layout_compatible;
+DiagnoseVLAInCXXTypeTrait(Self, Lhs, tok::kw___is_layout_compatible);
+DiagnoseVLAInCXXTypeTrait(Self, Rhs, tok::kw___is_layout_compatible);
+
 return Self.IsLayoutCompatible(LhsT, RhsT);
   }
   case BTT_IsPointerInterconvertibleBaseOf: {
@@ -6108,12 +6113,10 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, 
TypeTrait BTT, const TypeSourceI
diag::err_incomplete_type);
 }
 
-if (LhsT->isVariableArrayType())
-  Self.Diag(Lhs->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
-  << 1 << tok::kw___is_pointer_interconvertible_base_of;
-if (RhsT->isVariableArrayType())
-  Self.Diag(Rhs->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
-  << 1 << tok::kw___is_pointer_interconvertible_base_of;
+DiagnoseVLAInCXXTypeTrait(Self, Lhs,
+  tok::kw___is_pointer_interconvertible_base_of);
+DiagnoseVLAInCXXTypeTrait(Self, Rhs,
+  tok::kw___is_pointer_interconvertible_base_of);
 
 return Self.IsPointerInterconvertibleBaseOf(Lhs, Rhs);
   }

``




https://github.com/llvm/llvm-project/pull/88646
_

[clang] [Clang][Sema] Fix issue on requires expression with templated base class member function (PR #85198)

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

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


[clang] [clang][NFC] Factor out VLA checks in type traits (PR #88646)

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

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


[clang] [clang][NFC] Factor out VLA checks in type traits (PR #88646)

2024-04-14 Thread via cfe-commits

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


[clang] [clang][NFC] Factor out VLA checks in type traits (PR #88646)

2024-04-14 Thread via cfe-commits

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

Just one nit, but LGTM otherwise.

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


[clang] [clang][NFC] Factor out VLA checks in type traits (PR #88646)

2024-04-14 Thread via cfe-commits


@@ -5012,6 +5012,20 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
   return From;
 }
 
+/// Checks that type T is not a VLA.
+///
+/// @returns @c true if @p T is VLA and a diagnostic was emitted,
+/// @c false otherwise.
+static bool DiagnoseVLAInCXXTypeTrait(Sema &S, const TypeSourceInfo *T,

Sirraide wrote:

nit: do we need the `CXX` in the function name here?

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


[clang] [clang][NFC] Factor out VLA checks in type traits (PR #88646)

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


@@ -5012,6 +5012,20 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
   return From;
 }
 
+/// Checks that type T is not a VLA.
+///
+/// @returns @c true if @p T is VLA and a diagnostic was emitted,
+/// @c false otherwise.
+static bool DiagnoseVLAInCXXTypeTrait(Sema &S, const TypeSourceInfo *T,

Endilll wrote:

I don't have a strong opinion on this. Just followed what Corentin suggested.

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


[clang] [clang][NFC] Factor out VLA checks in type traits (PR #88646)

2024-04-14 Thread via cfe-commits


@@ -5012,6 +5012,20 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
   return From;
 }
 
+/// Checks that type T is not a VLA.
+///
+/// @returns @c true if @p T is VLA and a diagnostic was emitted,
+/// @c false otherwise.
+static bool DiagnoseVLAInCXXTypeTrait(Sema &S, const TypeSourceInfo *T,

Sirraide wrote:

Ah, I see; the main reason I commented on this is because I thought it was a 
bit odd that none of the `EvaluateXYTypeTrait` functions have `CXX` in them, 
but this is one does (I know we don’t really have fixed ‘rules’ as to when to 
include `CXX` in the name, but it just wanted to suggest maybe being consistent 
about it at least). I don’t feel strongly about this either.

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


[clang] [clang][NFC] Factor out VLA checks in type traits (PR #88646)

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


@@ -5012,6 +5012,20 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
   return From;
 }
 
+/// Checks that type T is not a VLA.
+///
+/// @returns @c true if @p T is VLA and a diagnostic was emitted,
+/// @c false otherwise.
+static bool DiagnoseVLAInCXXTypeTrait(Sema &S, const TypeSourceInfo *T,

Endilll wrote:

One reason might be the fact that current use case for this function is C++ 
traits specifically, since VLA is clearly an extension for them. I'll keep the 
`CXX` then.

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


[clang] [clang][NFC] Factor out VLA checks in type traits (PR #88646)

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

https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/88646

>From 34d735b2f85e3c24cbf725f6a519afec6c916820 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sun, 14 Apr 2024 10:41:53 +0300
Subject: [PATCH] [clang][NFC] Factor out VLA check in type traits

---
 clang/lib/Sema/SemaExprCXX.cpp | 59 ++
 1 file changed, 31 insertions(+), 28 deletions(-)

diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 1cfd3e56a583eb..d2f18d4aa9b980 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5012,6 +5012,20 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
   return From;
 }
 
+/// Checks that type T is not a VLA.
+///
+/// @returns @c true if @p T is VLA and a diagnostic was emitted,
+/// @c false otherwise.
+static bool DiagnoseVLAInCXXTypeTrait(Sema &S, const TypeSourceInfo *T,
+  clang::tok::TokenKind TypeTraitID) {
+  if (!T->getType()->isVariableArrayType())
+return false;
+
+  S.Diag(T->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
+  << 1 << TypeTraitID;
+  return true;
+}
+
 /// Check the completeness of a type in a unary type trait.
 ///
 /// If the particular type trait requires a complete type, tries to complete
@@ -5188,7 +5202,9 @@ static bool HasNoThrowOperator(const RecordType *RT, 
OverloadedOperatorKind Op,
 }
 
 static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait UTT,
-   SourceLocation KeyLoc, QualType T) {
+   SourceLocation KeyLoc,
+   TypeSourceInfo *TInfo) {
+  QualType T = TInfo->getType();
   assert(!T->isDependentType() && "Cannot evaluate traits of dependent type");
 
   ASTContext &C = Self.Context;
@@ -5205,21 +5221,13 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, 
TypeTrait UTT,
   case UTT_IsArray:
 return T->isArrayType();
   case UTT_IsBoundedArray:
-if (!T->isVariableArrayType()) {
-  return T->isArrayType() && !T->isIncompleteArrayType();
-}
-
-Self.Diag(KeyLoc, diag::err_vla_unsupported)
-<< 1 << tok::kw___is_bounded_array;
-return false;
+if (DiagnoseVLAInCXXTypeTrait(Self, TInfo, tok::kw___is_bounded_array))
+  return false;
+return T->isArrayType() && !T->isIncompleteArrayType();
   case UTT_IsUnboundedArray:
-if (!T->isVariableArrayType()) {
-  return T->isIncompleteArrayType();
-}
-
-Self.Diag(KeyLoc, diag::err_vla_unsupported)
-<< 1 << tok::kw___is_unbounded_array;
-return false;
+if (DiagnoseVLAInCXXTypeTrait(Self, TInfo, tok::kw___is_unbounded_array))
+  return false;
+return T->isIncompleteArrayType();
   case UTT_IsPointer:
 return T->isAnyPointerType();
   case UTT_IsNullPointer:
@@ -5631,7 +5639,7 @@ static bool EvaluateBooleanTypeTrait(Sema &S, TypeTrait 
Kind,
 return false;
 
   if (Kind <= UTT_Last)
-return EvaluateUnaryTypeTrait(S, Kind, KWLoc, Args[0]->getType());
+return EvaluateUnaryTypeTrait(S, Kind, KWLoc, Args[0]);
 
   // Evaluate ReferenceBindsToTemporary and ReferenceConstructsFromTemporary
   // alongside the IsConstructible traits to avoid duplication.
@@ -6093,12 +6101,9 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, 
TypeTrait BTT, const TypeSourceI
   Self.RequireCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT,
diag::err_incomplete_type);
 
-if (LhsT->isVariableArrayType())
-  Self.Diag(Lhs->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
-  << 1 << tok::kw___is_layout_compatible;
-if (RhsT->isVariableArrayType())
-  Self.Diag(Rhs->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
-  << 1 << tok::kw___is_layout_compatible;
+DiagnoseVLAInCXXTypeTrait(Self, Lhs, tok::kw___is_layout_compatible);
+DiagnoseVLAInCXXTypeTrait(Self, Rhs, tok::kw___is_layout_compatible);
+
 return Self.IsLayoutCompatible(LhsT, RhsT);
   }
   case BTT_IsPointerInterconvertibleBaseOf: {
@@ -6108,12 +6113,10 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, 
TypeTrait BTT, const TypeSourceI
diag::err_incomplete_type);
 }
 
-if (LhsT->isVariableArrayType())
-  Self.Diag(Lhs->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
-  << 1 << tok::kw___is_pointer_interconvertible_base_of;
-if (RhsT->isVariableArrayType())
-  Self.Diag(Rhs->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
-  << 1 << tok::kw___is_pointer_interconvertible_base_of;
+DiagnoseVLAInCXXTypeTrait(Self, Lhs,
+  tok::kw___is_pointer_interconvertible_base_of);
+DiagnoseVLAInCXXTypeTrait(Self, Rhs,
+  tok::kw___is_pointer_interconvertible_base_of);
 
 return Self.IsPointerInterconvertibleBaseOf(Lhs, Rhs);
   }

___
cfe-commits mailing l

[clang] c6f9c84 - [Clang] Reduce the size of Decl and classes derived from it (#87361)

2024-04-14 Thread via cfe-commits

Author: Nikolas Klauser
Date: 2024-04-14T12:08:30+02:00
New Revision: c6f9c84e498ee05a812511ae969773ff166fd25e

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

LOG: [Clang] Reduce the size of Decl and classes derived from it (#87361)

Class | Old size (in bytes) | New size (in bytes)

--|-|
Decl  | 40  | 32
AccessSpecDecl| 40  | 40
BlockDecl | 128 | 120
CapturedDecl  | 88  | 80
EmptyDecl | 40  | 32
ExportDecl| 80  | 72
ExternCContextDecl| 72  | 64
FileScopeAsmDecl  | 56  | 48
FriendDecl| 64  | 56
FriendTemplateDecl| 64  | 64
ImplicitConceptSpecializationDecl | 40  | 40
ImportDecl| 56  | 48
LifetimeExtendedTemporaryDecl | 72  | 64
LinkageSpecDecl   | 80  | 72
NamedDecl | 48  | 40
ObjCPropertyImplDecl  | 96  | 88
PragmaCommentDecl | 40  | 40
PragmaDetectMismatchDecl  | 48  | 40
RequiresExprBodyDecl  | 72  | 64
StaticAssertDecl  | 64  | 56
TopLevelStmtDecl  | 88  | 80
TranslationUnitDecl   | 104 | 96
BaseUsingDecl | 56  | 48
UsingDecl | 88  | 80
UsingEnumDecl | 72  | 64
HLSLBufferDecl| 96  | 88
LabelDecl | 80  | 72
NamespaceAliasDecl| 96  | 88
NamespaceDecl | 112 | 104
ObjCCompatibleAliasDecl   | 56  | 48
ObjCContainerDecl | 88  | 80
ObjCMethodDecl| 136 | 128
ObjCPropertyDecl  | 128 | 120
TemplateDecl  | 64  | 56
BuiltinTemplateDecl   | 72  | 64
TypeDecl  | 64  | 56
UnresolvedUsingIfExistsDecl   | 48  | 40
UsingDirectiveDecl| 88  | 80
UsingPackDecl | 64  | 56
UsingShadowDecl   | 80  | 72
ValueDecl | 56  | 48

When parsing libc++'s `` header the used memory is reduced from
42.8MB to 42.5MB.

Added: 


Modified: 
clang/include/clang/AST/DeclBase.h
clang/lib/AST/DeclBase.cpp
clang/lib/Serialization/ASTReaderDecl.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 858450926455c6..4bee18767dd11b 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -268,17 +268,37 @@ class alignas(8) Decl {
   ///   }
   ///   void A::f(); // SemanticDC == namespace 'A'
   ///// LexicalDC == global namespace
-  llvm::PointerUnion DeclCtx;
 
-  bool isInSemaDC() const { return DeclCtx.is(); }
-  bool isOutOfSemaDC() const { return DeclCtx.is(); }
+  // Compress the InvalidDecl and HasAttrs bits into DeclCtx to keep Decl below
+  // 32 bytes in size
+  llvm::PointerIntPair<
+  llvm::PointerIntPair, 1,
+   bool>,
+  1, bool>
+  DeclCtxWithInvalidDeclAndHasAttrs;
+
+  bool isInSemaDC() const {
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.is();
+  }
+
+  bool isOutOfSemaDC() const {
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.is();
+  }
 
   MultipleDC *getMultipleDC() const {
-return DeclCtx.get();
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.get();
   }
 
   DeclContext *getSemanticDC() const {
-return DeclCtx.get();
+return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
+.getPointer()
+.get();
   }
 
   /// Loc - The location of this decl.
@@ -288,14 +308,6 @@ class alignas(8) Decl {
   LLVM_PREFERRED_TYPE(Kind)
   unsigned DeclKind : 7;
 
-  /// InvalidDecl - This indicates a semantic error occurred.
-  LLVM_PREFERRED_TYPE(bool)
-  unsigned InvalidDecl :  1;
-
-  /// H

[clang] [Clang] Reduce the size of Decl and classes derived from it (PR #87361)

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

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


[clang] [clang][NFC] Factor out VLA checks in type traits (PR #88646)

2024-04-14 Thread via cfe-commits

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


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


[clang] d48d6ba - [clang][NFC] Factor out VLA checks in type traits (#88646)

2024-04-14 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-04-14T14:14:37+04:00
New Revision: d48d6ba9477aa380cd5a71f899d3cb6d629f175b

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

LOG: [clang][NFC] Factor out VLA checks in type traits (#88646)

This is a follow-up to #88473 suggested by @cor3ntin in
https://github.com/llvm/llvm-project/pull/88473#discussion_r1562198117.

Added: 


Modified: 
clang/lib/Sema/SemaExprCXX.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 1cfd3e56a583eb..d2f18d4aa9b980 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -5012,6 +5012,20 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
   return From;
 }
 
+/// Checks that type T is not a VLA.
+///
+/// @returns @c true if @p T is VLA and a diagnostic was emitted,
+/// @c false otherwise.
+static bool DiagnoseVLAInCXXTypeTrait(Sema &S, const TypeSourceInfo *T,
+  clang::tok::TokenKind TypeTraitID) {
+  if (!T->getType()->isVariableArrayType())
+return false;
+
+  S.Diag(T->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
+  << 1 << TypeTraitID;
+  return true;
+}
+
 /// Check the completeness of a type in a unary type trait.
 ///
 /// If the particular type trait requires a complete type, tries to complete
@@ -5188,7 +5202,9 @@ static bool HasNoThrowOperator(const RecordType *RT, 
OverloadedOperatorKind Op,
 }
 
 static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait UTT,
-   SourceLocation KeyLoc, QualType T) {
+   SourceLocation KeyLoc,
+   TypeSourceInfo *TInfo) {
+  QualType T = TInfo->getType();
   assert(!T->isDependentType() && "Cannot evaluate traits of dependent type");
 
   ASTContext &C = Self.Context;
@@ -5205,21 +5221,13 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, 
TypeTrait UTT,
   case UTT_IsArray:
 return T->isArrayType();
   case UTT_IsBoundedArray:
-if (!T->isVariableArrayType()) {
-  return T->isArrayType() && !T->isIncompleteArrayType();
-}
-
-Self.Diag(KeyLoc, diag::err_vla_unsupported)
-<< 1 << tok::kw___is_bounded_array;
-return false;
+if (DiagnoseVLAInCXXTypeTrait(Self, TInfo, tok::kw___is_bounded_array))
+  return false;
+return T->isArrayType() && !T->isIncompleteArrayType();
   case UTT_IsUnboundedArray:
-if (!T->isVariableArrayType()) {
-  return T->isIncompleteArrayType();
-}
-
-Self.Diag(KeyLoc, diag::err_vla_unsupported)
-<< 1 << tok::kw___is_unbounded_array;
-return false;
+if (DiagnoseVLAInCXXTypeTrait(Self, TInfo, tok::kw___is_unbounded_array))
+  return false;
+return T->isIncompleteArrayType();
   case UTT_IsPointer:
 return T->isAnyPointerType();
   case UTT_IsNullPointer:
@@ -5631,7 +5639,7 @@ static bool EvaluateBooleanTypeTrait(Sema &S, TypeTrait 
Kind,
 return false;
 
   if (Kind <= UTT_Last)
-return EvaluateUnaryTypeTrait(S, Kind, KWLoc, Args[0]->getType());
+return EvaluateUnaryTypeTrait(S, Kind, KWLoc, Args[0]);
 
   // Evaluate ReferenceBindsToTemporary and ReferenceConstructsFromTemporary
   // alongside the IsConstructible traits to avoid duplication.
@@ -6093,12 +6101,9 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, 
TypeTrait BTT, const TypeSourceI
   Self.RequireCompleteType(Rhs->getTypeLoc().getBeginLoc(), RhsT,
diag::err_incomplete_type);
 
-if (LhsT->isVariableArrayType())
-  Self.Diag(Lhs->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
-  << 1 << tok::kw___is_layout_compatible;
-if (RhsT->isVariableArrayType())
-  Self.Diag(Rhs->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
-  << 1 << tok::kw___is_layout_compatible;
+DiagnoseVLAInCXXTypeTrait(Self, Lhs, tok::kw___is_layout_compatible);
+DiagnoseVLAInCXXTypeTrait(Self, Rhs, tok::kw___is_layout_compatible);
+
 return Self.IsLayoutCompatible(LhsT, RhsT);
   }
   case BTT_IsPointerInterconvertibleBaseOf: {
@@ -6108,12 +6113,10 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, 
TypeTrait BTT, const TypeSourceI
diag::err_incomplete_type);
 }
 
-if (LhsT->isVariableArrayType())
-  Self.Diag(Lhs->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
-  << 1 << tok::kw___is_pointer_interconvertible_base_of;
-if (RhsT->isVariableArrayType())
-  Self.Diag(Rhs->getTypeLoc().getBeginLoc(), diag::err_vla_unsupported)
-  << 1 << tok::kw___is_pointer_interconvertible_base_of;
+DiagnoseVLAInCXXTypeTrait(Self, Lhs,
+  tok::kw___is_pointer_interconvertible_base_of);
+DiagnoseVLA

[clang] [clang][NFC] Factor out VLA checks in type traits (PR #88646)

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

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


[clang] [clang] Fix name conflict with `sys/mac.h` on AIX (PR #88644)

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

https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/88644

>From 9d46b1ed31d2acbb772f9bb4b139fa1ec36a65ab Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sun, 14 Apr 2024 08:46:27 +0300
Subject: [PATCH] [clang] Fix name conflict with `sys/mac.h` on AIX

Fixes clang-ppc64-aix bot failure after #88559 
(0a6f6df5b0c3d0f2a42f013bf5cafb9b5020dcac) 
https://lab.llvm.org/buildbot/#/builders/214/builds/11887
---
 clang/include/clang/Basic/Cuda.h | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/include/clang/Basic/Cuda.h b/clang/include/clang/Basic/Cuda.h
index acc6bb6581d857..3908e10bc61061 100644
--- a/clang/include/clang/Basic/Cuda.h
+++ b/clang/include/clang/Basic/Cuda.h
@@ -50,6 +50,11 @@ const char *CudaVersionToString(CudaVersion V);
 // Input is "Major.Minor"
 CudaVersion CudaStringToVersion(const llvm::Twine &S);
 
+// We have a name conflict with sys/mac.h on AIX
+#ifdef _AIX
+#undef SM_32
+#endif
+
 enum class CudaArch {
   UNUSED,
   UNKNOWN,

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


[clang] Revert "[Clang] Reduce the size of Decl and classes derived from it" (PR #88654)

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

https://github.com/philnik777 created 
https://github.com/llvm/llvm-project/pull/88654

Reverts llvm/llvm-project#87361

On 32 bit platforms there is only a single bit available in the `DeclCtx`, 
resulting in an assertion failure.


>From b243ca1d3616d1dd61b81e3a112707e27cd4c865 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Sun, 14 Apr 2024 12:23:21 +0200
Subject: [PATCH] Revert "[Clang] Reduce the size of Decl and classes derived
 from it (#87361)"

This reverts commit c6f9c84e498ee05a812511ae969773ff166fd25e.
---
 clang/include/clang/AST/DeclBase.h| 72 ---
 clang/lib/AST/DeclBase.cpp| 31 +++---
 clang/lib/Serialization/ASTReaderDecl.cpp |  2 +-
 3 files changed, 35 insertions(+), 70 deletions(-)

diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 4bee18767dd11b..858450926455c6 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -268,37 +268,17 @@ class alignas(8) Decl {
   ///   }
   ///   void A::f(); // SemanticDC == namespace 'A'
   ///// LexicalDC == global namespace
+  llvm::PointerUnion DeclCtx;
 
-  // Compress the InvalidDecl and HasAttrs bits into DeclCtx to keep Decl below
-  // 32 bytes in size
-  llvm::PointerIntPair<
-  llvm::PointerIntPair, 1,
-   bool>,
-  1, bool>
-  DeclCtxWithInvalidDeclAndHasAttrs;
-
-  bool isInSemaDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.is();
-  }
-
-  bool isOutOfSemaDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.is();
-  }
+  bool isInSemaDC() const { return DeclCtx.is(); }
+  bool isOutOfSemaDC() const { return DeclCtx.is(); }
 
   MultipleDC *getMultipleDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.get();
+return DeclCtx.get();
   }
 
   DeclContext *getSemanticDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.get();
+return DeclCtx.get();
   }
 
   /// Loc - The location of this decl.
@@ -308,6 +288,14 @@ class alignas(8) Decl {
   LLVM_PREFERRED_TYPE(Kind)
   unsigned DeclKind : 7;
 
+  /// InvalidDecl - This indicates a semantic error occurred.
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned InvalidDecl :  1;
+
+  /// HasAttrs - This indicates whether the decl has attributes or not.
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned HasAttrs : 1;
+
   /// Implicit - Whether this declaration was implicitly generated by
   /// the implementation rather than explicitly written by the user.
   LLVM_PREFERRED_TYPE(bool)
@@ -405,22 +393,21 @@ class alignas(8) Decl {
 protected:
   Decl(Kind DK, DeclContext *DC, SourceLocation L)
   : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),
-DeclCtxWithInvalidDeclAndHasAttrs({DC, false}, false), Loc(L),
-DeclKind(DK), Implicit(false), Used(false), Referenced(false),
+DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false),
+Implicit(false), Used(false), Referenced(false),
 TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled)
-  add(DK);
+if (StatisticsEnabled) add(DK);
   }
 
   Decl(Kind DK, EmptyShell Empty)
-  : DeclKind(DK), Implicit(false), Used(false), Referenced(false),
-TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
+  : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false),
+Used(false), Referenced(false), TopLevelDeclInObjCContainer(false),
+Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled)
-  add(DK);
+if (StatisticsEnabled) add(DK);
   }
 
   virtual ~Decl();
@@ -533,9 +520,7 @@ class alignas(8) Decl {
 return AccessSpecifier(Access);
   }
 
-  bool hasAttrs() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer().getInt();
-  }
+  bool hasAttrs() const { return HasAttrs; }
 
   void setAttrs(const AttrVec& Attrs) {
 return setAttrsImpl(Attrs, getASTContext());
@@ -564,17 +549,13 @@ class alignas(8) Decl {
   }
 
   template  void dropAttrs() {
-if (!hasAttrs())
-  return;
+if (!HasAttrs) return;
 
 AttrVec &Vec = getAttrs();
 llvm::erase_if(Vec, [](Attr *A) { return isa(A); });
 
-if (Vec.empty()) {
-  auto InnerPtr = DeclCtxWithInvalidDeclAndHasAttrs.getPointer();
-  InnerPtr.setInt(false);
-  DeclCtxWithInvalidDeclAndHasAttrs.setPointer(InnerPtr);
-}
+if (Vec.empty())
+  HasAttrs = false;
   }
 
   template  void dropAttr() { dropAttrs(); }
@@ -609,10 +

[clang] ed06b84 - Revert "[Clang] Reduce the size of Decl and classes derived from it" (#88654)

2024-04-14 Thread via cfe-commits

Author: Nikolas Klauser
Date: 2024-04-14T12:25:49+02:00
New Revision: ed06b847d4e77d0b81fa6b095366bb070db57846

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

LOG: Revert "[Clang] Reduce the size of Decl and classes derived from it" 
(#88654)

Reverts llvm/llvm-project#87361

On 32 bit platforms there is only a single bit available in the
`DeclCtx`, resulting in an assertion failure.

Added: 


Modified: 
clang/include/clang/AST/DeclBase.h
clang/lib/AST/DeclBase.cpp
clang/lib/Serialization/ASTReaderDecl.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 4bee18767dd11b..858450926455c6 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -268,37 +268,17 @@ class alignas(8) Decl {
   ///   }
   ///   void A::f(); // SemanticDC == namespace 'A'
   ///// LexicalDC == global namespace
+  llvm::PointerUnion DeclCtx;
 
-  // Compress the InvalidDecl and HasAttrs bits into DeclCtx to keep Decl below
-  // 32 bytes in size
-  llvm::PointerIntPair<
-  llvm::PointerIntPair, 1,
-   bool>,
-  1, bool>
-  DeclCtxWithInvalidDeclAndHasAttrs;
-
-  bool isInSemaDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.is();
-  }
-
-  bool isOutOfSemaDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.is();
-  }
+  bool isInSemaDC() const { return DeclCtx.is(); }
+  bool isOutOfSemaDC() const { return DeclCtx.is(); }
 
   MultipleDC *getMultipleDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.get();
+return DeclCtx.get();
   }
 
   DeclContext *getSemanticDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.get();
+return DeclCtx.get();
   }
 
   /// Loc - The location of this decl.
@@ -308,6 +288,14 @@ class alignas(8) Decl {
   LLVM_PREFERRED_TYPE(Kind)
   unsigned DeclKind : 7;
 
+  /// InvalidDecl - This indicates a semantic error occurred.
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned InvalidDecl :  1;
+
+  /// HasAttrs - This indicates whether the decl has attributes or not.
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned HasAttrs : 1;
+
   /// Implicit - Whether this declaration was implicitly generated by
   /// the implementation rather than explicitly written by the user.
   LLVM_PREFERRED_TYPE(bool)
@@ -405,22 +393,21 @@ class alignas(8) Decl {
 protected:
   Decl(Kind DK, DeclContext *DC, SourceLocation L)
   : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),
-DeclCtxWithInvalidDeclAndHasAttrs({DC, false}, false), Loc(L),
-DeclKind(DK), Implicit(false), Used(false), Referenced(false),
+DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false),
+Implicit(false), Used(false), Referenced(false),
 TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled)
-  add(DK);
+if (StatisticsEnabled) add(DK);
   }
 
   Decl(Kind DK, EmptyShell Empty)
-  : DeclKind(DK), Implicit(false), Used(false), Referenced(false),
-TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
+  : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false),
+Used(false), Referenced(false), TopLevelDeclInObjCContainer(false),
+Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled)
-  add(DK);
+if (StatisticsEnabled) add(DK);
   }
 
   virtual ~Decl();
@@ -533,9 +520,7 @@ class alignas(8) Decl {
 return AccessSpecifier(Access);
   }
 
-  bool hasAttrs() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer().getInt();
-  }
+  bool hasAttrs() const { return HasAttrs; }
 
   void setAttrs(const AttrVec& Attrs) {
 return setAttrsImpl(Attrs, getASTContext());
@@ -564,17 +549,13 @@ class alignas(8) Decl {
   }
 
   template  void dropAttrs() {
-if (!hasAttrs())
-  return;
+if (!HasAttrs) return;
 
 AttrVec &Vec = getAttrs();
 llvm::erase_if(Vec, [](Attr *A) { return isa(A); });
 
-if (Vec.empty()) {
-  auto InnerPtr = DeclCtxWithInvalidDeclAndHasAttrs.getPointer();
-  InnerPtr.setInt(false);
-  DeclCtxWithInvalidDeclAndHasAttrs.setPointer(InnerPtr);
-}
+if (Vec.empty())
+  HasAttrs = false;
   }
 
   template  void dropAttr() { dropAttrs(); }
@@ -60

[clang] Revert "[Clang] Reduce the size of Decl and classes derived from it" (PR #88654)

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

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


[clang] Revert "[Clang] Reduce the size of Decl and classes derived from it" (PR #88654)

2024-04-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Nikolas Klauser (philnik777)


Changes

Reverts llvm/llvm-project#87361

On 32 bit platforms there is only a single bit available in the `DeclCtx`, 
resulting in an assertion failure.


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


3 Files Affected:

- (modified) clang/include/clang/AST/DeclBase.h (+25-47) 
- (modified) clang/lib/AST/DeclBase.cpp (+9-22) 
- (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 4bee18767dd11b..858450926455c6 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -268,37 +268,17 @@ class alignas(8) Decl {
   ///   }
   ///   void A::f(); // SemanticDC == namespace 'A'
   ///// LexicalDC == global namespace
+  llvm::PointerUnion DeclCtx;
 
-  // Compress the InvalidDecl and HasAttrs bits into DeclCtx to keep Decl below
-  // 32 bytes in size
-  llvm::PointerIntPair<
-  llvm::PointerIntPair, 1,
-   bool>,
-  1, bool>
-  DeclCtxWithInvalidDeclAndHasAttrs;
-
-  bool isInSemaDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.is();
-  }
-
-  bool isOutOfSemaDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.is();
-  }
+  bool isInSemaDC() const { return DeclCtx.is(); }
+  bool isOutOfSemaDC() const { return DeclCtx.is(); }
 
   MultipleDC *getMultipleDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.get();
+return DeclCtx.get();
   }
 
   DeclContext *getSemanticDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.get();
+return DeclCtx.get();
   }
 
   /// Loc - The location of this decl.
@@ -308,6 +288,14 @@ class alignas(8) Decl {
   LLVM_PREFERRED_TYPE(Kind)
   unsigned DeclKind : 7;
 
+  /// InvalidDecl - This indicates a semantic error occurred.
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned InvalidDecl :  1;
+
+  /// HasAttrs - This indicates whether the decl has attributes or not.
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned HasAttrs : 1;
+
   /// Implicit - Whether this declaration was implicitly generated by
   /// the implementation rather than explicitly written by the user.
   LLVM_PREFERRED_TYPE(bool)
@@ -405,22 +393,21 @@ class alignas(8) Decl {
 protected:
   Decl(Kind DK, DeclContext *DC, SourceLocation L)
   : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),
-DeclCtxWithInvalidDeclAndHasAttrs({DC, false}, false), Loc(L),
-DeclKind(DK), Implicit(false), Used(false), Referenced(false),
+DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false),
+Implicit(false), Used(false), Referenced(false),
 TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled)
-  add(DK);
+if (StatisticsEnabled) add(DK);
   }
 
   Decl(Kind DK, EmptyShell Empty)
-  : DeclKind(DK), Implicit(false), Used(false), Referenced(false),
-TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
+  : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false),
+Used(false), Referenced(false), TopLevelDeclInObjCContainer(false),
+Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled)
-  add(DK);
+if (StatisticsEnabled) add(DK);
   }
 
   virtual ~Decl();
@@ -533,9 +520,7 @@ class alignas(8) Decl {
 return AccessSpecifier(Access);
   }
 
-  bool hasAttrs() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer().getInt();
-  }
+  bool hasAttrs() const { return HasAttrs; }
 
   void setAttrs(const AttrVec& Attrs) {
 return setAttrsImpl(Attrs, getASTContext());
@@ -564,17 +549,13 @@ class alignas(8) Decl {
   }
 
   template  void dropAttrs() {
-if (!hasAttrs())
-  return;
+if (!HasAttrs) return;
 
 AttrVec &Vec = getAttrs();
 llvm::erase_if(Vec, [](Attr *A) { return isa(A); });
 
-if (Vec.empty()) {
-  auto InnerPtr = DeclCtxWithInvalidDeclAndHasAttrs.getPointer();
-  InnerPtr.setInt(false);
-  DeclCtxWithInvalidDeclAndHasAttrs.setPointer(InnerPtr);
-}
+if (Vec.empty())
+  HasAttrs = false;
   }
 
   template  void dropAttr() { dropAttrs(); }
@@ -609,10 +590,7 @@ class alignas(8) Decl {
   /// setInvalidDecl - Indicates the Decl had a semantic error. This
   /// allows for graceful error recovery.
   void setInvalidDecl(bool Invalid = true);
-
-  bool isInvalidDecl() const {
-return DeclCtxWith

[clang] Revert "[Clang] Reduce the size of Decl and classes derived from it" (PR #88654)

2024-04-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Nikolas Klauser (philnik777)


Changes

Reverts llvm/llvm-project#87361

On 32 bit platforms there is only a single bit available in the `DeclCtx`, 
resulting in an assertion failure.


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


3 Files Affected:

- (modified) clang/include/clang/AST/DeclBase.h (+25-47) 
- (modified) clang/lib/AST/DeclBase.cpp (+9-22) 
- (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/clang/AST/DeclBase.h
index 4bee18767dd11b..858450926455c6 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -268,37 +268,17 @@ class alignas(8) Decl {
   ///   }
   ///   void A::f(); // SemanticDC == namespace 'A'
   ///// LexicalDC == global namespace
+  llvm::PointerUnion DeclCtx;
 
-  // Compress the InvalidDecl and HasAttrs bits into DeclCtx to keep Decl below
-  // 32 bytes in size
-  llvm::PointerIntPair<
-  llvm::PointerIntPair, 1,
-   bool>,
-  1, bool>
-  DeclCtxWithInvalidDeclAndHasAttrs;
-
-  bool isInSemaDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.is();
-  }
-
-  bool isOutOfSemaDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.is();
-  }
+  bool isInSemaDC() const { return DeclCtx.is(); }
+  bool isOutOfSemaDC() const { return DeclCtx.is(); }
 
   MultipleDC *getMultipleDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.get();
+return DeclCtx.get();
   }
 
   DeclContext *getSemanticDC() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer()
-.getPointer()
-.get();
+return DeclCtx.get();
   }
 
   /// Loc - The location of this decl.
@@ -308,6 +288,14 @@ class alignas(8) Decl {
   LLVM_PREFERRED_TYPE(Kind)
   unsigned DeclKind : 7;
 
+  /// InvalidDecl - This indicates a semantic error occurred.
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned InvalidDecl :  1;
+
+  /// HasAttrs - This indicates whether the decl has attributes or not.
+  LLVM_PREFERRED_TYPE(bool)
+  unsigned HasAttrs : 1;
+
   /// Implicit - Whether this declaration was implicitly generated by
   /// the implementation rather than explicitly written by the user.
   LLVM_PREFERRED_TYPE(bool)
@@ -405,22 +393,21 @@ class alignas(8) Decl {
 protected:
   Decl(Kind DK, DeclContext *DC, SourceLocation L)
   : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),
-DeclCtxWithInvalidDeclAndHasAttrs({DC, false}, false), Loc(L),
-DeclKind(DK), Implicit(false), Used(false), Referenced(false),
+DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false),
+Implicit(false), Used(false), Referenced(false),
 TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled)
-  add(DK);
+if (StatisticsEnabled) add(DK);
   }
 
   Decl(Kind DK, EmptyShell Empty)
-  : DeclKind(DK), Implicit(false), Used(false), Referenced(false),
-TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
+  : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false),
+Used(false), Referenced(false), TopLevelDeclInObjCContainer(false),
+Access(AS_none), FromASTFile(0),
 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
-if (StatisticsEnabled)
-  add(DK);
+if (StatisticsEnabled) add(DK);
   }
 
   virtual ~Decl();
@@ -533,9 +520,7 @@ class alignas(8) Decl {
 return AccessSpecifier(Access);
   }
 
-  bool hasAttrs() const {
-return DeclCtxWithInvalidDeclAndHasAttrs.getPointer().getInt();
-  }
+  bool hasAttrs() const { return HasAttrs; }
 
   void setAttrs(const AttrVec& Attrs) {
 return setAttrsImpl(Attrs, getASTContext());
@@ -564,17 +549,13 @@ class alignas(8) Decl {
   }
 
   template  void dropAttrs() {
-if (!hasAttrs())
-  return;
+if (!HasAttrs) return;
 
 AttrVec &Vec = getAttrs();
 llvm::erase_if(Vec, [](Attr *A) { return isa(A); });
 
-if (Vec.empty()) {
-  auto InnerPtr = DeclCtxWithInvalidDeclAndHasAttrs.getPointer();
-  InnerPtr.setInt(false);
-  DeclCtxWithInvalidDeclAndHasAttrs.setPointer(InnerPtr);
-}
+if (Vec.empty())
+  HasAttrs = false;
   }
 
   template  void dropAttr() { dropAttrs(); }
@@ -609,10 +590,7 @@ class alignas(8) Decl {
   /// setInvalidDecl - Indicates the Decl had a semantic error. This
   /// allows for graceful error recovery.
   void setInvalidDecl(bool Invalid = true);
-
-  bool isInvalidDecl() const {
-return Dec

[clang] ef164ce - [Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` (#86526)

2024-04-14 Thread via cfe-commits

Author: Sirraide
Date: 2024-04-14T12:30:01+02:00
New Revision: ef164cee90477e294ff692209b4cf97a0e1958ed

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

LOG: [Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` 
(#86526)

This implements support for the `= delete("message")` syntax that was
only just added to C++26
([P2573R2](https://isocpp.org/files/papers/P2573R2.html#proposal-scope)).

Added: 
clang/test/AST/ast-dump-cxx2c-delete-with-message.cpp
clang/test/AST/ast-print-cxx2c-delete-with-message.cpp
clang/test/Parser/cxx2c-delete-with-message.cpp
clang/test/SemaCXX/cxx2c-delete-with-message.cpp

Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/Decl.h
clang/include/clang/AST/DeclBase.h
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclPrinter.cpp
clang/lib/AST/JSONNodeDumper.cpp
clang/lib/AST/ODRHash.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Parse/ParseCXXInlineMethods.cpp
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Parse/Parser.cpp
clang/lib/Sema/SemaCast.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
clang/test/Lexer/cxx-features.cpp
clang/test/PCH/cxx2a-defaulted-comparison.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 96691b45d63a37..05c8f765b55695 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
+``= delete ("should have a reason");``   __cpp_deleted_function   
C++26 C++03
   
- -
 Designated initializers (N494)
C99   C89
 Array & element qualification (N2607) 
C23   C89

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 399d5ba796d15c..ade8f4e93d5a0c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -129,6 +129,8 @@ C++2c Feature Support
 
 - Implemented `P2662R3 Pack Indexing `_.
 
+- Implemented `P2573R2: = delete("should have a reason"); 
`_
+
 
 Resolutions to C++ Defect Reports
 ^

diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index ed6790acdfc7cc..01af50ca694fdd 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -1993,21 +1993,35 @@ class FunctionDecl : public DeclaratorDecl,
 
   };
 
-  /// Stashed information about a defaulted function definition whose body has
-  /// not yet been lazily generated.
-  class DefaultedFunctionInfo final
-  : llvm::TrailingObjects {
+  /// Stashed information about a defaulted/deleted function body.
+  class DefaultedOrDeletedFunctionInfo final
+  : llvm::TrailingObjects {
 friend TrailingObjects;
 unsigned NumLookups;
+bool HasDeletedMessage;
+
+size_t numTrailingObjects(OverloadToken) const {
+  return NumLookups;
+}
 
   public:
-static DefaultedFunctionInfo *Create(ASTContext &Context,
- ArrayRef Lookups);
+static DefaultedOrDeletedFunctionInfo *
+Create(ASTContext &Context, ArrayRef Lookups,
+   StringLiteral *DeletedMessage = nullptr);
+
 /// Get the unqualified lookup results that should be used in this
 /// defaulted function definition.
 ArrayRef getUnqualifiedLookups() const {
   return {getTrailingObjects(), NumLookups};
 }
+
+StringLiteral *getDeletedMessage() const {
+  return HasDeletedMessage ? *getTrailingObjects()
+   

[clang] [Clang] [C++26] Implement P2573R2: `= delete("should have a reason");` (PR #86526)

2024-04-14 Thread via cfe-commits

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


[clang-tools-extra] [clang-tidy][NFC] Fix `linuxkernel-must-check-errs` documentation file name (PR #88655)

2024-04-14 Thread via cfe-commits

https://github.com/whisperity created 
https://github.com/llvm/llvm-project/pull/88655

The check was originally introduced in commit 
fc8c65b2e11d21b1c0ce070cc0a4ee031a542dae with conflicting names, likely as a 
result of a partial rename, with the name in the documentation 
(`linuxkernel-must-use-errs`) not matching the name of the check as configured 
by users.

>From 3d42376ed3ac6d73cd6d6152d5029e439e9c2bf1 Mon Sep 17 00:00:00 2001
From: Whisperity 
Date: Sun, 14 Apr 2024 12:37:58 +0200
Subject: [PATCH] [clang-tidy] Fix `linuxkernel-must-check-errs` documentation
 file name

The check was originally introduced with conflicting names, likely as a
result of a partial rename, with the name in the documentation
(`linuxkernel-must-use-errs`) not matching the name of the check as
configured by users.
---
 .../clang-tidy/linuxkernel/MustCheckErrsCheck.h  | 9 +
 clang-tools-extra/docs/ReleaseNotes.rst  | 4 
 .../{must-use-errs.rst => must-check-errs.rst}   | 6 +++---
 clang-tools-extra/docs/clang-tidy/checks/list.rst| 2 +-
 4 files changed, 9 insertions(+), 12 deletions(-)
 rename clang-tools-extra/docs/clang-tidy/checks/linuxkernel/{must-use-errs.rst 
=> must-check-errs.rst} (88%)

diff --git a/clang-tools-extra/clang-tidy/linuxkernel/MustCheckErrsCheck.h 
b/clang-tools-extra/clang-tidy/linuxkernel/MustCheckErrsCheck.h
index f08fed47983924..7406aaead836e0 100644
--- a/clang-tools-extra/clang-tidy/linuxkernel/MustCheckErrsCheck.h
+++ b/clang-tools-extra/clang-tidy/linuxkernel/MustCheckErrsCheck.h
@@ -17,15 +17,8 @@ namespace clang::tidy::linuxkernel {
 /// linux/err.h. Also checks to see if code uses the results from functions 
that
 /// directly return a value from one of these error functions.
 ///
-/// This is important in the Linux kernel because ERR_PTR, PTR_ERR, IS_ERR,
-/// IS_ERR_OR_NULL, ERR_CAST, and PTR_ERR_OR_ZERO return values must be 
checked,
-/// since positive pointers and negative error codes are being used in the same
-/// context. These functions are marked with
-/// __attribute__((warn_unused_result)), but some kernel versions do not have
-/// this warning enabled for clang.
-///
 /// For the user-facing documentation see:
-/// 
http://clang.llvm.org/extra/clang-tidy/checks/linuxkernel/must-use-errs.html
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/linuxkernel/must-check-errs.html
 class MustCheckErrsCheck : public ClangTidyCheck {
 public:
   MustCheckErrsCheck(StringRef Name, ClangTidyContext *Context)
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 1405fb0df1f8dd..4dfbd8ca49ab9b 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -299,6 +299,10 @@ Miscellaneous
   ``--format`` option is specified. Now :program:`clang-apply-replacements`
   applies formatting only with the option.
 
+- Fixed the :doc:`linuxkernel-must-check-errs
+  ` documentation to 
consistently
+  use the check's proper name.
+
 Improvements to include-fixer
 -
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/linuxkernel/must-use-errs.rst 
b/clang-tools-extra/docs/clang-tidy/checks/linuxkernel/must-check-errs.rst
similarity index 88%
rename from 
clang-tools-extra/docs/clang-tidy/checks/linuxkernel/must-use-errs.rst
rename to 
clang-tools-extra/docs/clang-tidy/checks/linuxkernel/must-check-errs.rst
index 8a85426880987e..cef5a70db309e1 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/linuxkernel/must-use-errs.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/linuxkernel/must-check-errs.rst
@@ -1,7 +1,7 @@
-.. title:: clang-tidy - linuxkernel-must-use-errs
+.. title:: clang-tidy - linuxkernel-must-check-errs
 
-linuxkernel-must-use-errs
-=
+linuxkernel-must-check-errs
+===
 
 Checks Linux kernel code to see if it uses the results from the functions in
 ``linux/err.h``. Also checks to see if code uses the results from functions 
that
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst 
b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 188a42bfddd383..8bc46acad56c84 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -233,7 +233,7 @@ Clang-Tidy Checks
:doc:`hicpp-multiway-paths-covered `,
:doc:`hicpp-no-assembler `,
:doc:`hicpp-signed-bitwise `,
-   :doc:`linuxkernel-must-use-errs `,
+   :doc:`linuxkernel-must-check-errs `,
:doc:`llvm-header-guard `,
:doc:`llvm-include-order `, "Yes"
:doc:`llvm-namespace-comment `,

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


[clang-tools-extra] [clang-tidy][NFC] Fix `linuxkernel-must-check-errs` documentation file name (PR #88655)

2024-04-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: None (whisperity)


Changes

The check was originally introduced in commit 
fc8c65b2e11d21b1c0ce070cc0a4ee031a542dae with conflicting names, likely as a 
result of a partial rename, with the name in the documentation 
(`linuxkernel-must-use-errs`) not matching the name of the check as configured 
by users.

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


4 Files Affected:

- (modified) clang-tools-extra/clang-tidy/linuxkernel/MustCheckErrsCheck.h 
(+1-8) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4) 
- (renamed) 
clang-tools-extra/docs/clang-tidy/checks/linuxkernel/must-check-errs.rst (+3-3) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+1-1) 


``diff
diff --git a/clang-tools-extra/clang-tidy/linuxkernel/MustCheckErrsCheck.h 
b/clang-tools-extra/clang-tidy/linuxkernel/MustCheckErrsCheck.h
index f08fed47983924..7406aaead836e0 100644
--- a/clang-tools-extra/clang-tidy/linuxkernel/MustCheckErrsCheck.h
+++ b/clang-tools-extra/clang-tidy/linuxkernel/MustCheckErrsCheck.h
@@ -17,15 +17,8 @@ namespace clang::tidy::linuxkernel {
 /// linux/err.h. Also checks to see if code uses the results from functions 
that
 /// directly return a value from one of these error functions.
 ///
-/// This is important in the Linux kernel because ERR_PTR, PTR_ERR, IS_ERR,
-/// IS_ERR_OR_NULL, ERR_CAST, and PTR_ERR_OR_ZERO return values must be 
checked,
-/// since positive pointers and negative error codes are being used in the same
-/// context. These functions are marked with
-/// __attribute__((warn_unused_result)), but some kernel versions do not have
-/// this warning enabled for clang.
-///
 /// For the user-facing documentation see:
-/// 
http://clang.llvm.org/extra/clang-tidy/checks/linuxkernel/must-use-errs.html
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/linuxkernel/must-check-errs.html
 class MustCheckErrsCheck : public ClangTidyCheck {
 public:
   MustCheckErrsCheck(StringRef Name, ClangTidyContext *Context)
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 1405fb0df1f8dd..4dfbd8ca49ab9b 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -299,6 +299,10 @@ Miscellaneous
   ``--format`` option is specified. Now :program:`clang-apply-replacements`
   applies formatting only with the option.
 
+- Fixed the :doc:`linuxkernel-must-check-errs
+  ` documentation to 
consistently
+  use the check's proper name.
+
 Improvements to include-fixer
 -
 
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/linuxkernel/must-use-errs.rst 
b/clang-tools-extra/docs/clang-tidy/checks/linuxkernel/must-check-errs.rst
similarity index 88%
rename from 
clang-tools-extra/docs/clang-tidy/checks/linuxkernel/must-use-errs.rst
rename to 
clang-tools-extra/docs/clang-tidy/checks/linuxkernel/must-check-errs.rst
index 8a85426880987e..cef5a70db309e1 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/linuxkernel/must-use-errs.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/linuxkernel/must-check-errs.rst
@@ -1,7 +1,7 @@
-.. title:: clang-tidy - linuxkernel-must-use-errs
+.. title:: clang-tidy - linuxkernel-must-check-errs
 
-linuxkernel-must-use-errs
-=
+linuxkernel-must-check-errs
+===
 
 Checks Linux kernel code to see if it uses the results from the functions in
 ``linux/err.h``. Also checks to see if code uses the results from functions 
that
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst 
b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 188a42bfddd383..8bc46acad56c84 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -233,7 +233,7 @@ Clang-Tidy Checks
:doc:`hicpp-multiway-paths-covered `,
:doc:`hicpp-no-assembler `,
:doc:`hicpp-signed-bitwise `,
-   :doc:`linuxkernel-must-use-errs `,
+   :doc:`linuxkernel-must-check-errs `,
:doc:`llvm-header-guard `,
:doc:`llvm-include-order `, "Yes"
:doc:`llvm-namespace-comment `,

``




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


[clang-tools-extra] [clang-tidy][NFC] Fix `linuxkernel-must-check-errs` documentation file name (PR #88655)

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

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


[clang-tools-extra] [clang-tidy][NFC] Fix `linuxkernel-must-check-errs` documentation file name (PR #88655)

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

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


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


[clang-tools-extra] [clang-tidy][NFC] Fix `linuxkernel-must-check-errs` documentation file name (PR #88655)

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


@@ -299,6 +299,10 @@ Miscellaneous
   ``--format`` option is specified. Now :program:`clang-apply-replacements`
   applies formatting only with the option.
 
+- Fixed the :doc:`linuxkernel-must-check-errs
+  ` documentation to 
consistently
+  use the check's proper name.

PiotrZSL wrote:

No release notes needed for documentation changes.

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


[clang] 6e934b7 - [clang] Fix -Wunused-variable in SemaCast.cpp (NFC)

2024-04-14 Thread Jie Fu via cfe-commits

Author: Jie Fu
Date: 2024-04-14T20:34:26+08:00
New Revision: 6e934b7cfba8e0c167d2b287a30dfc1b720397c1

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

LOG: [clang] Fix -Wunused-variable in SemaCast.cpp (NFC)

llvm-project/clang/lib/Sema/SemaCast.cpp:503:23:
error: unused variable 'Res' [-Werror,-Wunused-variable]
OverloadingResult Res =
  ^
1 error generated.

Added: 


Modified: 
clang/lib/Sema/SemaCast.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index aac43e2cad603f..b0c28531fe8738 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -500,7 +500,7 @@ static bool tryDiagnoseOverloadedCast(Sema &S, CastType CT,
 
   case OR_Deleted: {
 OverloadCandidateSet::iterator Best;
-OverloadingResult Res =
+[[maybe_unused]] OverloadingResult Res =
 candidates.BestViableFunction(S, range.getBegin(), Best);
 assert(Res == OR_Deleted && "Inconsistent overload resolution");
 



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


[clang] [clang] Fix name conflict with `sys/mac.h` on AIX (PR #88644)

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


@@ -50,6 +50,11 @@ const char *CudaVersionToString(CudaVersion V);
 // Input is "Major.Minor"
 CudaVersion CudaStringToVersion(const llvm::Twine &S);
 
+// We have a name conflict with sys/mac.h on AIX
+#ifdef _AIX
+#undef SM_32
+#endif
+

jhuber6 wrote:

```suggestion
// We have a name conflict with sys/mac.h on AIX
#ifdef SM_32
#undef SM_32
#endif
```

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


[clang] [clang] Fix name conflict with `sys/mac.h` on AIX (PR #88644)

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

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


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


[clang] [clang] Fix name conflict with `sys/mac.h` on AIX (PR #88644)

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

jhuber6 wrote:

I can't really think of anything more clever here unfortunately and we should 
probably unbreak the bot. Maybe someone more familiar with PowerPC knows if 
it's possible to simply not include this header somewhere.

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


[clang] [clang] Fix high memory consumption during pack deduction (PR #88637)

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


@@ -831,7 +831,7 @@ class PackDeductionScope {
 if (IsPartiallyExpanded)
   PackElements += NumPartialPackArgs;
 else if (IsExpanded)
-  PackElements += *FixedNumExpansions;
+  PackElements += FixedNumExpansions.value_or(1);

tschuett wrote:

Could you add an assert:
```
assert(FixedNumExpansions && "unexpected nullopt");
```

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


[clang] [clang] Introduce `SemaOpenMP` (PR #88642)

2024-04-14 Thread Alexey Bataev via cfe-commits


@@ -997,6 +987,11 @@ class Sema final : public SemaBase {
 return *OpenACCPtr;
   }
 
+  SemaOpenMP &OpenMP() {

alexey-bataev wrote:

```suggestion
  SemaOpenMP &getOpenMP() {
```


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


[clang] [clang] Introduce `SemaOpenMP` (PR #88642)

2024-04-14 Thread Alexey Bataev via cfe-commits


@@ -11,6 +11,7 @@
 ///
 
//===--===//
 
+#include "clang/Sema/SemaOpenMP.h"

alexey-bataev wrote:

Sort it properly?

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


[clang] [clang] Introduce `SemaOpenMP` (PR #88642)

2024-04-14 Thread Alexey Bataev via cfe-commits


@@ -997,6 +987,11 @@ class Sema final : public SemaBase {
 return *OpenACCPtr;
   }
 
+  SemaOpenMP &OpenMP() {
+assert(OpenMPPtr);

alexey-bataev wrote:

Add assertion message

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


[clang] [clang] Introduce `SemaOpenMP` (PR #88642)

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


@@ -11,6 +11,7 @@
 ///
 
//===--===//
 
+#include "clang/Sema/SemaOpenMP.h"

Endilll wrote:

Main module header goes first per our coding standard: 
https://llvm.org/docs/CodingStandards.html#include-style

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


[clang] [clang] Introduce `SemaOpenMP` (PR #88642)

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


@@ -997,6 +987,11 @@ class Sema final : public SemaBase {
 return *OpenACCPtr;
   }
 
+  SemaOpenMP &OpenMP() {

Endilll wrote:

This was discussed back when we started splitting `Sema` up: 
https://github.com/llvm/llvm-project/pull/84184#discussion_r1520027821. We can 
reopen the discussion if you insist, otherwise I'd like to keep it consistent 
with CUDA, HLSL, etc.

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


[clang] [clang] Introduce `SemaOpenMP` (PR #88642)

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


@@ -997,6 +987,11 @@ class Sema final : public SemaBase {
 return *OpenACCPtr;
   }
 
+  SemaOpenMP &OpenMP() {
+assert(OpenMPPtr);

Endilll wrote:

Done

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


[clang] [clang] Introduce `SemaOpenMP` (PR #88642)

2024-04-14 Thread Alexey Bataev via cfe-commits

https://github.com/alexey-bataev approved this pull request.

LG

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


[clang] [analyzer] Handle builtin functions in MallocChecker (PR #88416)

2024-04-14 Thread Balazs Benics via cfe-commits
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 


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


[clang] [analyzer] Handle builtin functions in MallocChecker (PR #88416)

2024-04-14 Thread Balazs Benics via cfe-commits
=?utf-8?q?Don=C3=A1t?= Nagy 
Message-ID:
In-Reply-To: 


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

High quality code with descent description.
Really nice work. Nothing really stood out to me that I'd object.

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


[clang] [analyzer] Handle builtin functions in MallocChecker (PR #88416)

2024-04-14 Thread Balazs Benics via cfe-commits
=?utf-8?q?Donát?= Nagy 
Message-ID:
In-Reply-To: 



@@ -214,3 +214,15 @@ void *realloc(void **ptr, size_t size) { realloc(ptr, 
size); } // no-crash
 namespace pr46253_paramty2{
 void *realloc(void *ptr, int size) { realloc(ptr, size); } // no-crash
 } // namespace pr46253_paramty2
+
+namespace pr81597{
+struct S {};
+struct T {
+   void free(const S& s);
+};
+void f(T& t) {
+   S s;
+// This is not the free you are looking for...
+   t.free(s); // no-warning
+}
+} // namespace pr81597

steakhal wrote:

```suggestion
namespace pr81597 {
struct S {};
struct T {
  void free(const S& s);
};
void f(T& t) {
  S s;
  t.free(s); // no-warning: This is not the free you are looking for...
}
} // namespace pr81597
```
Indent by 2 spaces, have a space before the `{` token.

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


[clang] [clang] Fix name conflict with `sys/mac.h` on AIX (PR #88644)

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

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


[clang] 7cfe736 - [clang] Fix name conflict with `sys/mac.h` on AIX (#88644)

2024-04-14 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-04-14T17:51:15+04:00
New Revision: 7cfe73624780010ec81ca11c41ebbf214400abdd

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

LOG: [clang] Fix name conflict with `sys/mac.h` on AIX (#88644)

Fixes clang-ppc64-aix bot failure after #88559
(0a6f6df5b0c3d0f2a42f013bf5cafb9b5020dcac)
https://lab.llvm.org/buildbot/#/builders/214/builds/11887

-

Co-authored-by: Joseph Huber 

Added: 


Modified: 
clang/include/clang/Basic/Cuda.h

Removed: 




diff  --git a/clang/include/clang/Basic/Cuda.h 
b/clang/include/clang/Basic/Cuda.h
index acc6bb6581d857..38f30543a0f662 100644
--- a/clang/include/clang/Basic/Cuda.h
+++ b/clang/include/clang/Basic/Cuda.h
@@ -50,6 +50,10 @@ const char *CudaVersionToString(CudaVersion V);
 // Input is "Major.Minor"
 CudaVersion CudaStringToVersion(const llvm::Twine &S);
 
+// We have a name conflict with sys/mac.h on AIX
+#ifdef SM_32
+#undef SM_32
+#endif
 enum class CudaArch {
   UNUSED,
   UNKNOWN,



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


[clang-tools-extra] [clang-tidy] check `std::string_view` and custom string-like classes in `readability-string-compare` (PR #88636)

2024-04-14 Thread via cfe-commits


@@ -50,5 +52,32 @@ Examples:
   }
 
 The above code examples show the list of if-statements that this check will
-give a warning for. All of them uses ``compare`` to check if equality or
+give a warning for. All of them use ``compare`` to check equality or
 inequality of two strings instead of using the correct operators.
+
+Options
+---
+
+.. option:: StringLikeClasses
+
+   A string containing comma-separated names of string-like classes. Default 
is an empty string.

EugeneZelenko wrote:

Please follow 80 characters limit.

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


[clang-tools-extra] [clang-tidy] check `std::string_view` and custom string-like classes in `readability-string-compare` (PR #88636)

2024-04-14 Thread via cfe-commits


@@ -50,5 +52,32 @@ Examples:
   }
 
 The above code examples show the list of if-statements that this check will
-give a warning for. All of them uses ``compare`` to check if equality or
+give a warning for. All of them use ``compare`` to check equality or
 inequality of two strings instead of using the correct operators.
+
+Options
+---
+
+.. option:: StringLikeClasses
+
+   A string containing comma-separated names of string-like classes. Default 
is an empty string.
+   If a class from this list has a ``compare`` method similar to 
``std::string``, it will be checked in the same way.
+
+Example
+^^^
+
+.. code-block:: c++
+
+  struct CustomString {
+  public:
+int compare (const CustomString& other) const;
+  }
+
+  CustomString str1;
+  CustomString str2;
+
+  // use str1 != str2 instead.
+  if (str1.compare(str2)) {
+  }
+
+If `StringLikeClasses` contains ``CustomString``, the check will suggest 
replacing ``compare`` with equality operator.

EugeneZelenko wrote:

What is default value?

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


[clang-tools-extra] [clang-tidy] check `std::string_view` and custom string-like classes in `readability-string-compare` (PR #88636)

2024-04-14 Thread Vadim D. via cfe-commits


@@ -50,5 +52,32 @@ Examples:
   }
 
 The above code examples show the list of if-statements that this check will
-give a warning for. All of them uses ``compare`` to check if equality or
+give a warning for. All of them use ``compare`` to check equality or
 inequality of two strings instead of using the correct operators.
+
+Options
+---
+
+.. option:: StringLikeClasses
+
+   A string containing comma-separated names of string-like classes. Default 
is an empty string.
+   If a class from this list has a ``compare`` method similar to 
``std::string``, it will be checked in the same way.
+
+Example
+^^^
+
+.. code-block:: c++
+
+  struct CustomString {
+  public:
+int compare (const CustomString& other) const;
+  }
+
+  CustomString str1;
+  CustomString str2;
+
+  // use str1 != str2 instead.
+  if (str1.compare(str2)) {
+  }
+
+If `StringLikeClasses` contains ``CustomString``, the check will suggest 
replacing ``compare`` with equality operator.

vvd170501 wrote:

Default value of what? If you mean `StringLikeClasses`, it is empty by default 
(see line 63)

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


[clang-tools-extra] [clang-tidy] check `std::string_view` and custom string-like classes in `readability-string-compare` (PR #88636)

2024-04-14 Thread Vadim D. via cfe-commits

https://github.com/vvd170501 updated 
https://github.com/llvm/llvm-project/pull/88636

>From 0db24a6806e9429b5e7b9cd9d0777315b3e6d87e Mon Sep 17 00:00:00 2001
From: Vadim Dudkin 
Date: Sat, 13 Apr 2024 23:36:12 +0300
Subject: [PATCH 1/2] readability-string-compare: check std::string_view, allow
 custom string-like classes

---
 .../readability/StringCompareCheck.cpp| 74 +--
 .../readability/StringCompareCheck.h  |  9 ++-
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../checks/readability/string-compare.rst | 33 -
 .../clang-tidy/checkers/Inputs/Headers/string | 10 +++
 .../string-compare-custom-string-classes.cpp  | 38 ++
 .../checkers/readability/string-compare.cpp   | 23 ++
 7 files changed, 165 insertions(+), 27 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/string-compare-custom-string-classes.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/StringCompareCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/StringCompareCheck.cpp
index 3b5d89c8c64719..905e5b156ef864 100644
--- a/clang-tools-extra/clang-tidy/readability/StringCompareCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/StringCompareCheck.cpp
@@ -7,12 +7,16 @@
 
//===--===//
 
 #include "StringCompareCheck.h"
-#include "../utils/FixItHintUtils.h"
+#include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Tooling/FixIt.h"
+#include "llvm/ADT/StringRef.h"
+#include 
 
 using namespace clang::ast_matchers;
+namespace optutils = clang::tidy::utils::options;
 
 namespace clang::tidy::readability {
 
@@ -20,29 +24,53 @@ static const StringRef CompareMessage = "do not use 
'compare' to test equality "
 "of strings; use the string equality "
 "operator instead";
 
+static const std::vector StringClasses = {
+"::std::basic_string", "::std::basic_string_view"};
+
+StringCompareCheck::StringCompareCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StringLikeClasses(
+  optutils::parseStringList(Options.get("StringLikeClasses", ""))) {}
+
 void StringCompareCheck::registerMatchers(MatchFinder *Finder) {
-  const auto StrCompare = cxxMemberCallExpr(
-  callee(cxxMethodDecl(hasName("compare"),
-   ofClass(classTemplateSpecializationDecl(
-   hasName("::std::basic_string"),
-  hasArgument(0, expr().bind("str2")), argumentCountIs(1),
-  callee(memberExpr().bind("str1")));
-
-  // First and second case: cast str.compare(str) to boolean.
-  Finder->addMatcher(
-  traverse(TK_AsIs,
-   implicitCastExpr(hasImplicitDestinationType(booleanType()),
-has(StrCompare))
-   .bind("match1")),
-  this);
-
-  // Third and fourth case: str.compare(str) == 0 and str.compare(str) != 0.
-  Finder->addMatcher(
-  binaryOperator(hasAnyOperatorName("==", "!="),
- hasOperands(StrCompare.bind("compare"),
- integerLiteral(equals(0)).bind("zero")))
-  .bind("match2"),
-  this);
+  const auto RegisterForClasses = [&, this](const auto &StringClassMatcher) {
+const auto StrCompare = cxxMemberCallExpr(
+callee(cxxMethodDecl(hasName("compare"), ofClass(StringClassMatcher))),
+hasArgument(0, expr().bind("str2")), argumentCountIs(1),
+callee(memberExpr().bind("str1")));
+
+// First and second case: cast str.compare(str) to boolean.
+Finder->addMatcher(
+traverse(TK_AsIs,
+ implicitCastExpr(hasImplicitDestinationType(booleanType()),
+  has(StrCompare))
+ .bind("match1")),
+this);
+
+// Third and fourth case: str.compare(str) == 0
+// and str.compare(str) !=  0.
+Finder->addMatcher(
+binaryOperator(hasAnyOperatorName("==", "!="),
+   hasOperands(StrCompare.bind("compare"),
+   integerLiteral(equals(0)).bind("zero")))
+.bind("match2"),
+this);
+  };
+  if (StringLikeClasses.empty()) {
+RegisterForClasses(
+classTemplateSpecializationDecl(hasAnyName(StringClasses)));
+  } else {
+// StringLikeClasses may or may not be templates, so we need to match both
+// template and non-template classes.
+std::vector PossiblyTemplateClasses = StringClasses;
+PossiblyTemplateClasses.insert(PossiblyTemplateClasses.end(),
+   StringLikeClasses.begin(),
+   StringLikeClasses.end());
+RegisterForClasses(anyOf(
+classTem

[clang-tools-extra] [clang-tidy] check `std::string_view` and custom string-like classes in `readability-string-compare` (PR #88636)

2024-04-14 Thread Vadim D. via cfe-commits

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


[clang] [clang] Fix high memory consumption during pack deduction (PR #88637)

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


@@ -831,7 +831,7 @@ class PackDeductionScope {
 if (IsPartiallyExpanded)
   PackElements += NumPartialPackArgs;
 else if (IsExpanded)
-  PackElements += *FixedNumExpansions;
+  PackElements += FixedNumExpansions.value_or(1);

tschuett wrote:

```
.value_or(1)
```
cannot be the solution. `FixedNumExpansions` is nullopt. Why is `1` an 
improvement over nullopt?

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


[clang-tools-extra] [clang-tidy] check `std::string_view` and custom string-like classes in `readability-string-compare` (PR #88636)

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

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


[clang-tools-extra] [clang-tidy] check `std::string_view` and custom string-like classes in `readability-string-compare` (PR #88636)

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


@@ -7,42 +7,70 @@
 
//===--===//
 
 #include "StringCompareCheck.h"
-#include "../utils/FixItHintUtils.h"
+#include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Tooling/FixIt.h"
+#include "llvm/ADT/StringRef.h"
+#include 
 
 using namespace clang::ast_matchers;
+namespace optutils = clang::tidy::utils::options;
 
 namespace clang::tidy::readability {
 
 static const StringRef CompareMessage = "do not use 'compare' to test equality 
"
 "of strings; use the string equality "
 "operator instead";
 
+static const std::vector StringClasses = {
+"::std::basic_string", "::std::basic_string_view"};
+
+StringCompareCheck::StringCompareCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StringLikeClasses(
+  optutils::parseStringList(Options.get("StringLikeClasses", ""))) {}
+
 void StringCompareCheck::registerMatchers(MatchFinder *Finder) {
-  const auto StrCompare = cxxMemberCallExpr(
-  callee(cxxMethodDecl(hasName("compare"),
-   ofClass(classTemplateSpecializationDecl(
-   hasName("::std::basic_string"),
-  hasArgument(0, expr().bind("str2")), argumentCountIs(1),
-  callee(memberExpr().bind("str1")));
-
-  // First and second case: cast str.compare(str) to boolean.
-  Finder->addMatcher(
-  traverse(TK_AsIs,
-   implicitCastExpr(hasImplicitDestinationType(booleanType()),
-has(StrCompare))
-   .bind("match1")),
-  this);
-
-  // Third and fourth case: str.compare(str) == 0 and str.compare(str) != 0.
-  Finder->addMatcher(
-  binaryOperator(hasAnyOperatorName("==", "!="),
- hasOperands(StrCompare.bind("compare"),
- integerLiteral(equals(0)).bind("zero")))
-  .bind("match2"),
-  this);
+  const auto RegisterForClasses = [&, this](const auto &StringClassMatcher) {
+const auto StrCompare = cxxMemberCallExpr(
+callee(cxxMethodDecl(hasName("compare"), ofClass(StringClassMatcher))),
+hasArgument(0, expr().bind("str2")), argumentCountIs(1),
+callee(memberExpr().bind("str1")));
+
+// First and second case: cast str.compare(str) to boolean.
+Finder->addMatcher(
+traverse(TK_AsIs,
+ implicitCastExpr(hasImplicitDestinationType(booleanType()),
+  has(StrCompare))
+ .bind("match1")),
+this);
+
+// Third and fourth case: str.compare(str) == 0
+// and str.compare(str) !=  0.
+Finder->addMatcher(
+binaryOperator(hasAnyOperatorName("==", "!="),
+   hasOperands(StrCompare.bind("compare"),
+   integerLiteral(equals(0)).bind("zero")))
+.bind("match2"),
+this);
+  };
+  if (StringLikeClasses.empty()) {
+RegisterForClasses(
+classTemplateSpecializationDecl(hasAnyName(StringClasses)));
+  } else {
+// StringLikeClasses may or may not be templates, so we need to match both
+// template and non-template classes.
+std::vector PossiblyTemplateClasses = StringClasses;
+PossiblyTemplateClasses.insert(PossiblyTemplateClasses.end(),
+   StringLikeClasses.begin(),
+   StringLikeClasses.end());
+RegisterForClasses(anyOf(
+classTemplateSpecializationDecl(hasAnyName(PossiblyTemplateClasses)),
+cxxRecordDecl(hasAnyName(StringLikeClasses;

PiotrZSL wrote:

consider using matchesAnyListedName instead of hasAnyName, to support regex.

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


[clang-tools-extra] [clang-tidy] check `std::string_view` and custom string-like classes in `readability-string-compare` (PR #88636)

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


@@ -7,42 +7,70 @@
 
//===--===//
 
 #include "StringCompareCheck.h"
-#include "../utils/FixItHintUtils.h"
+#include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Tooling/FixIt.h"
+#include "llvm/ADT/StringRef.h"
+#include 
 
 using namespace clang::ast_matchers;
+namespace optutils = clang::tidy::utils::options;
 
 namespace clang::tidy::readability {
 
 static const StringRef CompareMessage = "do not use 'compare' to test equality 
"
 "of strings; use the string equality "
 "operator instead";
 
+static const std::vector StringClasses = {
+"::std::basic_string", "::std::basic_string_view"};
+
+StringCompareCheck::StringCompareCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StringLikeClasses(
+  optutils::parseStringList(Options.get("StringLikeClasses", ""))) {}

PiotrZSL wrote:

put StringClasses  as default

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


[clang-tools-extra] [clang-tidy] check `std::string_view` and custom string-like classes in `readability-string-compare` (PR #88636)

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

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

- Missing storeOptions
- Some other tiny nits.
Would be nice to get rid of lambda RegisterForClasses as it's not needed, and 
have common handling.

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


[clang-tools-extra] [clang-tidy] check `std::string_view` and custom string-like classes in `readability-string-compare` (PR #88636)

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


@@ -20,13 +21,17 @@ namespace clang::tidy::readability {
 /// 
http://clang.llvm.org/extra/clang-tidy/checks/readability/string-compare.html
 class StringCompareCheck : public ClangTidyCheck {
 public:
-  StringCompareCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  StringCompareCheck(StringRef Name, ClangTidyContext *Context);
+
   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
 return LangOpts.CPlusPlus;
   }
+

PiotrZSL wrote:

missing method storeOptions

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


[clang-tools-extra] [clang-tidy] check `std::string_view` and custom string-like classes in `readability-string-compare` (PR #88636)

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


@@ -7,42 +7,70 @@
 
//===--===//
 
 #include "StringCompareCheck.h"
-#include "../utils/FixItHintUtils.h"
+#include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Tooling/FixIt.h"
+#include "llvm/ADT/StringRef.h"
+#include 
 
 using namespace clang::ast_matchers;
+namespace optutils = clang::tidy::utils::options;
 
 namespace clang::tidy::readability {
 
 static const StringRef CompareMessage = "do not use 'compare' to test equality 
"
 "of strings; use the string equality "
 "operator instead";
 
+static const std::vector StringClasses = {
+"::std::basic_string", "::std::basic_string_view"};
+
+StringCompareCheck::StringCompareCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StringLikeClasses(
+  optutils::parseStringList(Options.get("StringLikeClasses", ""))) {}

PiotrZSL wrote:

Or call it like "AdditionalStringLikeClasses", but still have common handling.

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


[clang] [flang] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #88661)

2024-04-14 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa created 
https://github.com/llvm/llvm-project/pull/88661

Follow-up to #81037.

ToolChain::LibraryPaths holds the new compiler-rt library directory (e.g. 
`/tmp/Debug/lib/clang/19/lib/x86_64-unknown-linux-gnu`). However, it might be 
empty when the directory does not exist (due to the `if (getVFS().exists(P))` 
change in https://reviews.llvm.org/D158475).

If neither the old/new compiler-rt library directories exists, we would suggest 
the undesired old compiler-rt file name:

```
% /tmp/Debug/bin/clang++ a.cc -fsanitize=memory -o a
ld.lld: error: cannot open 
/tmp/Debug/lib/clang/19/lib/linux/libclang_rt.msan-x86_64.a: No such file or 
directory
clang++: error: linker command failed with exit code 1 (use -v to see 
invocation)
```

With this change, we will correctly suggest the new compiler-rt file name.

Fix #87150

Pull Request: https://github.com/llvm/llvm-project/pull/87866

>From b8b5c72fefe3e9cbd9782727df75c8bb6eaeec2f Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Mon, 8 Apr 2024 16:51:34 -0700
Subject: [PATCH] Ensure ToolChain::LibraryPaths is not empty for non-Darwin

Follow-up to #81037.

ToolChain::LibraryPaths holds the new compiler-rt library directory
(e.g. `/tmp/Debug/lib/clang/19/lib/x86_64-unknown-linux-gnu`). However,
it might be empty when the directory does not exist (due to the `if
(getVFS().exists(P))` change in https://reviews.llvm.org/D158475).

If neither the old/new compiler-rt library directories exists, we would
suggest the undesired old compiler-rt file name:

```
% /tmp/Debug/bin/clang++ a.cc -fsanitize=memory -o a
ld.lld: error: cannot open 
/tmp/Debug/lib/clang/19/lib/linux/libclang_rt.msan-x86_64.a: No such file or 
directory
clang++: error: linker command failed with exit code 1 (use -v to see 
invocation)
```

With this change, we will correctly suggest the new compiler-rt file name.

Fix #87150

Pull Request: https://github.com/llvm/llvm-project/pull/87866
---
 clang/lib/Driver/ToolChain.cpp|  8 -
 clang/test/Driver/arm-compiler-rt.c   | 14 
 clang/test/Driver/cl-link.c   | 16 -
 clang/test/Driver/compiler-rt-unwind.c|  6 ++--
 clang/test/Driver/coverage-ld.c   |  8 ++---
 clang/test/Driver/instrprof-ld.c  | 16 -
 clang/test/Driver/linux-ld.c  |  8 +++--
 clang/test/Driver/mingw-sanitizers.c  | 16 -
 clang/test/Driver/msp430-toolchain.c  |  4 +--
 .../Driver/print-libgcc-file-name-clangrt.c   | 12 +++
 clang/test/Driver/print-runtime-dir.c |  6 
 clang/test/Driver/riscv32-toolchain-extra.c   |  6 ++--
 clang/test/Driver/riscv32-toolchain.c |  6 ++--
 clang/test/Driver/riscv64-toolchain-extra.c   |  6 ++--
 clang/test/Driver/riscv64-toolchain.c |  6 ++--
 clang/test/Driver/sanitizer-ld.c  | 36 +++
 clang/test/Driver/wasm-toolchain.c| 18 +-
 clang/test/Driver/wasm-toolchain.cpp  | 16 -
 clang/test/Driver/windows-cross.c | 18 +-
 clang/test/Driver/zos-ld.c| 12 +++
 .../test/Driver/msvc-dependent-lib-flags.f90  |  8 ++---
 21 files changed, 127 insertions(+), 119 deletions(-)

diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 03450fc0f57b93..237092ed07e5dc 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -796,7 +796,13 @@ ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
 std::optional ToolChain::getRuntimePath() const {
   SmallString<128> P(D.ResourceDir);
   llvm::sys::path::append(P, "lib");
-  return getTargetSubDirPath(P);
+  if (auto Ret = getTargetSubDirPath(P))
+return Ret;
+  // Darwin does not use per-target runtime directory.
+  if (Triple.isOSDarwin())
+return {};
+  llvm::sys::path::append(P, Triple.str());
+  return std::string(P);
 }
 
 std::optional ToolChain::getStdlibPath() const {
diff --git a/clang/test/Driver/arm-compiler-rt.c 
b/clang/test/Driver/arm-compiler-rt.c
index 5e9e528400d08e..cb6c29f48a7814 100644
--- a/clang/test/Driver/arm-compiler-rt.c
+++ b/clang/test/Driver/arm-compiler-rt.c
@@ -10,47 +10,47 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-GNUEABI
-// ARM-GNUEABI: "{{.*[/\\]}}libclang_rt.builtins-arm.a"
+// ARM-GNUEABI: "{{.*[/\\]}}libclang_rt.builtins.a"
 
 // RUN: %clang -target arm-linux-gnueabi \
 // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -mfloat-abi=hard -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-GNUEABI-ABI
-// ARM-GNUEABI-ABI: "{{.*[/\\]}}libclang_rt.builtins-armhf.a"
+// ARM-GNUEABI-ABI: "{{.*[/\\]}}libclang_rt.builtins.a"
 
 // RUN: %clang -target arm-linux-gnueabihf \
 // RUN: --sysroo

[clang] [flang] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #88661)

2024-04-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: YunQiang Su (wzssyqa)


Changes

Follow-up to #81037.

ToolChain::LibraryPaths holds the new compiler-rt library directory (e.g. 
`/tmp/Debug/lib/clang/19/lib/x86_64-unknown-linux-gnu`). However, it might be 
empty when the directory does not exist (due to the `if (getVFS().exists(P))` 
change in https://reviews.llvm.org/D158475).

If neither the old/new compiler-rt library directories exists, we would suggest 
the undesired old compiler-rt file name:

```
% /tmp/Debug/bin/clang++ a.cc -fsanitize=memory -o a
ld.lld: error: cannot open 
/tmp/Debug/lib/clang/19/lib/linux/libclang_rt.msan-x86_64.a: No such file or 
directory
clang++: error: linker command failed with exit code 1 (use -v to see 
invocation)
```

With this change, we will correctly suggest the new compiler-rt file name.

Fix #87150

Pull Request: https://github.com/llvm/llvm-project/pull/87866

---

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


21 Files Affected:

- (modified) clang/lib/Driver/ToolChain.cpp (+7-1) 
- (modified) clang/test/Driver/arm-compiler-rt.c (+7-7) 
- (modified) clang/test/Driver/cl-link.c (+8-8) 
- (modified) clang/test/Driver/compiler-rt-unwind.c (+3-3) 
- (modified) clang/test/Driver/coverage-ld.c (+4-4) 
- (modified) clang/test/Driver/instrprof-ld.c (+8-8) 
- (modified) clang/test/Driver/linux-ld.c (+5-3) 
- (modified) clang/test/Driver/mingw-sanitizers.c (+8-8) 
- (modified) clang/test/Driver/msp430-toolchain.c (+2-2) 
- (modified) clang/test/Driver/print-libgcc-file-name-clangrt.c (+6-6) 
- (modified) clang/test/Driver/print-runtime-dir.c (-6) 
- (modified) clang/test/Driver/riscv32-toolchain-extra.c (+3-3) 
- (modified) clang/test/Driver/riscv32-toolchain.c (+3-3) 
- (modified) clang/test/Driver/riscv64-toolchain-extra.c (+3-3) 
- (modified) clang/test/Driver/riscv64-toolchain.c (+3-3) 
- (modified) clang/test/Driver/sanitizer-ld.c (+21-15) 
- (modified) clang/test/Driver/wasm-toolchain.c (+9-9) 
- (modified) clang/test/Driver/wasm-toolchain.cpp (+8-8) 
- (modified) clang/test/Driver/windows-cross.c (+9-9) 
- (modified) clang/test/Driver/zos-ld.c (+6-6) 
- (modified) flang/test/Driver/msvc-dependent-lib-flags.f90 (+4-4) 


``diff
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 03450fc0f57b93..237092ed07e5dc 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -796,7 +796,13 @@ ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
 std::optional ToolChain::getRuntimePath() const {
   SmallString<128> P(D.ResourceDir);
   llvm::sys::path::append(P, "lib");
-  return getTargetSubDirPath(P);
+  if (auto Ret = getTargetSubDirPath(P))
+return Ret;
+  // Darwin does not use per-target runtime directory.
+  if (Triple.isOSDarwin())
+return {};
+  llvm::sys::path::append(P, Triple.str());
+  return std::string(P);
 }
 
 std::optional ToolChain::getStdlibPath() const {
diff --git a/clang/test/Driver/arm-compiler-rt.c 
b/clang/test/Driver/arm-compiler-rt.c
index 5e9e528400d08e..cb6c29f48a7814 100644
--- a/clang/test/Driver/arm-compiler-rt.c
+++ b/clang/test/Driver/arm-compiler-rt.c
@@ -10,47 +10,47 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-GNUEABI
-// ARM-GNUEABI: "{{.*[/\\]}}libclang_rt.builtins-arm.a"
+// ARM-GNUEABI: "{{.*[/\\]}}libclang_rt.builtins.a"
 
 // RUN: %clang -target arm-linux-gnueabi \
 // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -mfloat-abi=hard -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-GNUEABI-ABI
-// ARM-GNUEABI-ABI: "{{.*[/\\]}}libclang_rt.builtins-armhf.a"
+// ARM-GNUEABI-ABI: "{{.*[/\\]}}libclang_rt.builtins.a"
 
 // RUN: %clang -target arm-linux-gnueabihf \
 // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-GNUEABIHF
-// ARM-GNUEABIHF: "{{.*[/\\]}}libclang_rt.builtins-armhf.a"
+// ARM-GNUEABIHF: "{{.*[/\\]}}libclang_rt.builtins.a"
 
 // RUN: %clang -target arm-linux-gnueabihf \
 // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -mfloat-abi=soft -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-GNUEABIHF-ABI
-// ARM-GNUEABIHF-ABI: "{{.*[/\\]}}libclang_rt.builtins-arm.a"
+// ARM-GNUEABIHF-ABI: "{{.*[/\\]}}libclang_rt.builtins.a"
 
 // RUN: %clang -target arm-windows-itanium \
 // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -### %s 2>

[clang] [flang] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #88661)

2024-04-14 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-flang-driver

@llvm/pr-subscribers-backend-risc-v

Author: YunQiang Su (wzssyqa)


Changes

Follow-up to #81037.

ToolChain::LibraryPaths holds the new compiler-rt library directory (e.g. 
`/tmp/Debug/lib/clang/19/lib/x86_64-unknown-linux-gnu`). However, it might be 
empty when the directory does not exist (due to the `if (getVFS().exists(P))` 
change in https://reviews.llvm.org/D158475).

If neither the old/new compiler-rt library directories exists, we would suggest 
the undesired old compiler-rt file name:

```
% /tmp/Debug/bin/clang++ a.cc -fsanitize=memory -o a
ld.lld: error: cannot open 
/tmp/Debug/lib/clang/19/lib/linux/libclang_rt.msan-x86_64.a: No such file or 
directory
clang++: error: linker command failed with exit code 1 (use -v to see 
invocation)
```

With this change, we will correctly suggest the new compiler-rt file name.

Fix #87150

Pull Request: https://github.com/llvm/llvm-project/pull/87866

---

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


21 Files Affected:

- (modified) clang/lib/Driver/ToolChain.cpp (+7-1) 
- (modified) clang/test/Driver/arm-compiler-rt.c (+7-7) 
- (modified) clang/test/Driver/cl-link.c (+8-8) 
- (modified) clang/test/Driver/compiler-rt-unwind.c (+3-3) 
- (modified) clang/test/Driver/coverage-ld.c (+4-4) 
- (modified) clang/test/Driver/instrprof-ld.c (+8-8) 
- (modified) clang/test/Driver/linux-ld.c (+5-3) 
- (modified) clang/test/Driver/mingw-sanitizers.c (+8-8) 
- (modified) clang/test/Driver/msp430-toolchain.c (+2-2) 
- (modified) clang/test/Driver/print-libgcc-file-name-clangrt.c (+6-6) 
- (modified) clang/test/Driver/print-runtime-dir.c (-6) 
- (modified) clang/test/Driver/riscv32-toolchain-extra.c (+3-3) 
- (modified) clang/test/Driver/riscv32-toolchain.c (+3-3) 
- (modified) clang/test/Driver/riscv64-toolchain-extra.c (+3-3) 
- (modified) clang/test/Driver/riscv64-toolchain.c (+3-3) 
- (modified) clang/test/Driver/sanitizer-ld.c (+21-15) 
- (modified) clang/test/Driver/wasm-toolchain.c (+9-9) 
- (modified) clang/test/Driver/wasm-toolchain.cpp (+8-8) 
- (modified) clang/test/Driver/windows-cross.c (+9-9) 
- (modified) clang/test/Driver/zos-ld.c (+6-6) 
- (modified) flang/test/Driver/msvc-dependent-lib-flags.f90 (+4-4) 


``diff
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 03450fc0f57b93..237092ed07e5dc 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -796,7 +796,13 @@ ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
 std::optional ToolChain::getRuntimePath() const {
   SmallString<128> P(D.ResourceDir);
   llvm::sys::path::append(P, "lib");
-  return getTargetSubDirPath(P);
+  if (auto Ret = getTargetSubDirPath(P))
+return Ret;
+  // Darwin does not use per-target runtime directory.
+  if (Triple.isOSDarwin())
+return {};
+  llvm::sys::path::append(P, Triple.str());
+  return std::string(P);
 }
 
 std::optional ToolChain::getStdlibPath() const {
diff --git a/clang/test/Driver/arm-compiler-rt.c 
b/clang/test/Driver/arm-compiler-rt.c
index 5e9e528400d08e..cb6c29f48a7814 100644
--- a/clang/test/Driver/arm-compiler-rt.c
+++ b/clang/test/Driver/arm-compiler-rt.c
@@ -10,47 +10,47 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-GNUEABI
-// ARM-GNUEABI: "{{.*[/\\]}}libclang_rt.builtins-arm.a"
+// ARM-GNUEABI: "{{.*[/\\]}}libclang_rt.builtins.a"
 
 // RUN: %clang -target arm-linux-gnueabi \
 // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -mfloat-abi=hard -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-GNUEABI-ABI
-// ARM-GNUEABI-ABI: "{{.*[/\\]}}libclang_rt.builtins-armhf.a"
+// ARM-GNUEABI-ABI: "{{.*[/\\]}}libclang_rt.builtins.a"
 
 // RUN: %clang -target arm-linux-gnueabihf \
 // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-GNUEABIHF
-// ARM-GNUEABIHF: "{{.*[/\\]}}libclang_rt.builtins-armhf.a"
+// ARM-GNUEABIHF: "{{.*[/\\]}}libclang_rt.builtins.a"
 
 // RUN: %clang -target arm-linux-gnueabihf \
 // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -mfloat-abi=soft -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-GNUEABIHF-ABI
-// ARM-GNUEABIHF-ABI: "{{.*[/\\]}}libclang_rt.builtins-arm.a"
+// ARM-GNUEABIHF-ABI: "{{.*[/\\]}}libclang_rt.builtins.a"
 
 // RUN: %clang -target arm-windows-itanium \
 // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \

[clang] [flang] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #88661)

2024-04-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: YunQiang Su (wzssyqa)


Changes

Follow-up to #81037.

ToolChain::LibraryPaths holds the new compiler-rt library directory (e.g. 
`/tmp/Debug/lib/clang/19/lib/x86_64-unknown-linux-gnu`). However, it might be 
empty when the directory does not exist (due to the `if (getVFS().exists(P))` 
change in https://reviews.llvm.org/D158475).

If neither the old/new compiler-rt library directories exists, we would suggest 
the undesired old compiler-rt file name:

```
% /tmp/Debug/bin/clang++ a.cc -fsanitize=memory -o a
ld.lld: error: cannot open 
/tmp/Debug/lib/clang/19/lib/linux/libclang_rt.msan-x86_64.a: No such file or 
directory
clang++: error: linker command failed with exit code 1 (use -v to see 
invocation)
```

With this change, we will correctly suggest the new compiler-rt file name.

Fix #87150

Pull Request: https://github.com/llvm/llvm-project/pull/87866

---

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


21 Files Affected:

- (modified) clang/lib/Driver/ToolChain.cpp (+7-1) 
- (modified) clang/test/Driver/arm-compiler-rt.c (+7-7) 
- (modified) clang/test/Driver/cl-link.c (+8-8) 
- (modified) clang/test/Driver/compiler-rt-unwind.c (+3-3) 
- (modified) clang/test/Driver/coverage-ld.c (+4-4) 
- (modified) clang/test/Driver/instrprof-ld.c (+8-8) 
- (modified) clang/test/Driver/linux-ld.c (+5-3) 
- (modified) clang/test/Driver/mingw-sanitizers.c (+8-8) 
- (modified) clang/test/Driver/msp430-toolchain.c (+2-2) 
- (modified) clang/test/Driver/print-libgcc-file-name-clangrt.c (+6-6) 
- (modified) clang/test/Driver/print-runtime-dir.c (-6) 
- (modified) clang/test/Driver/riscv32-toolchain-extra.c (+3-3) 
- (modified) clang/test/Driver/riscv32-toolchain.c (+3-3) 
- (modified) clang/test/Driver/riscv64-toolchain-extra.c (+3-3) 
- (modified) clang/test/Driver/riscv64-toolchain.c (+3-3) 
- (modified) clang/test/Driver/sanitizer-ld.c (+21-15) 
- (modified) clang/test/Driver/wasm-toolchain.c (+9-9) 
- (modified) clang/test/Driver/wasm-toolchain.cpp (+8-8) 
- (modified) clang/test/Driver/windows-cross.c (+9-9) 
- (modified) clang/test/Driver/zos-ld.c (+6-6) 
- (modified) flang/test/Driver/msvc-dependent-lib-flags.f90 (+4-4) 


``diff
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 03450fc0f57b93..237092ed07e5dc 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -796,7 +796,13 @@ ToolChain::getTargetSubDirPath(StringRef BaseDir) const {
 std::optional ToolChain::getRuntimePath() const {
   SmallString<128> P(D.ResourceDir);
   llvm::sys::path::append(P, "lib");
-  return getTargetSubDirPath(P);
+  if (auto Ret = getTargetSubDirPath(P))
+return Ret;
+  // Darwin does not use per-target runtime directory.
+  if (Triple.isOSDarwin())
+return {};
+  llvm::sys::path::append(P, Triple.str());
+  return std::string(P);
 }
 
 std::optional ToolChain::getStdlibPath() const {
diff --git a/clang/test/Driver/arm-compiler-rt.c 
b/clang/test/Driver/arm-compiler-rt.c
index 5e9e528400d08e..cb6c29f48a7814 100644
--- a/clang/test/Driver/arm-compiler-rt.c
+++ b/clang/test/Driver/arm-compiler-rt.c
@@ -10,47 +10,47 @@
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-GNUEABI
-// ARM-GNUEABI: "{{.*[/\\]}}libclang_rt.builtins-arm.a"
+// ARM-GNUEABI: "{{.*[/\\]}}libclang_rt.builtins.a"
 
 // RUN: %clang -target arm-linux-gnueabi \
 // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -mfloat-abi=hard -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-GNUEABI-ABI
-// ARM-GNUEABI-ABI: "{{.*[/\\]}}libclang_rt.builtins-armhf.a"
+// ARM-GNUEABI-ABI: "{{.*[/\\]}}libclang_rt.builtins.a"
 
 // RUN: %clang -target arm-linux-gnueabihf \
 // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-GNUEABIHF
-// ARM-GNUEABIHF: "{{.*[/\\]}}libclang_rt.builtins-armhf.a"
+// ARM-GNUEABIHF: "{{.*[/\\]}}libclang_rt.builtins.a"
 
 // RUN: %clang -target arm-linux-gnueabihf \
 // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -mfloat-abi=soft -### %s 2>&1 \
 // RUN:   | FileCheck %s -check-prefix ARM-GNUEABIHF-ABI
-// ARM-GNUEABIHF-ABI: "{{.*[/\\]}}libclang_rt.builtins-arm.a"
+// ARM-GNUEABIHF-ABI: "{{.*[/\\]}}libclang_rt.builtins.a"
 
 // RUN: %clang -target arm-windows-itanium \
 // RUN: --sysroot=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -resource-dir=%S/Inputs/resource_dir_with_arch_subdir \
 // RUN: -rtlib=compiler-rt -##

[clang] [Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #87866)

2024-04-14 Thread YunQiang Su via cfe-commits

wzssyqa wrote:

New PR with my resource-dir patch: 
https://github.com/llvm/llvm-project/pull/88661

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


[clang] [flang] [Driver] Ensure ToolChain::LibraryPaths is not empty for non-Darwin (PR #88661)

2024-04-14 Thread YunQiang Su via cfe-commits

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


[clang-tools-extra] Include cmath to fix build error on mac os 10.14 (PR #88665)

2024-04-14 Thread via cfe-commits

https://github.com/Zentrik created 
https://github.com/llvm/llvm-project/pull/88665

This should fix #88664.

>From cdd250c837b9f1b2c35fa12b170c342f6d1ce295 Mon Sep 17 00:00:00 2001
From: Zentrik 
Date: Sun, 14 Apr 2024 17:28:18 +0100
Subject: [PATCH] Include cmath to fix build error on mac os 10.14

---
 clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
index b299afd540b9a3..45a8f973486147 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace {
 using namespace clang::ast_matchers;

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


[clang-tools-extra] Include cmath to fix build error on mac os 10.14 (PR #88665)

2024-04-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: None (Zentrik)


Changes

This should fix #88664.

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


1 Files Affected:

- (modified) clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp (+1) 


``diff
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
index b299afd540b9a3..45a8f973486147 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace {
 using namespace clang::ast_matchers;

``




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


[clang-tools-extra] Include cmath to fix build error on mac os 10.14 (PR #88665)

2024-04-14 Thread via cfe-commits

github-actions[bot] wrote:

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

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


[clang-tools-extra] Include cmath to fix build error on mac os 10.14 (PR #88665)

2024-04-14 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 b8d0cba14bcfc5c1c2f7a878ad9eaa12b6a590b6 
cdd250c837b9f1b2c35fa12b170c342f6d1ce295 -- 
clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
index 45a8f97348..1548fc454c 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
@@ -29,13 +29,13 @@
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/MathExtras.h"
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
-#include 
 
 namespace {
 using namespace clang::ast_matchers;

``




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


[clang] [Clang] Allow the value of unroll count to be zero in '#pragma GCC unroll' and '#pragma unroll' (PR #88666)

2024-04-14 Thread via cfe-commits

https://github.com/yronglin created 
https://github.com/llvm/llvm-project/pull/88666

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

GCC allows the value of loop unroll count to be zero, and the values of 0 and 1 
block any unrolling of the loop. This PR aims to make clang keeps the same 
behavior with GCC.
https://gcc.gnu.org/onlinedocs/gcc/Loop-Specific-Pragmas.html

>From c554816d9434ca6d3ca75187d8f1e62c20c7b938 Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Mon, 15 Apr 2024 00:36:06 +0800
Subject: [PATCH] [Clang] Allow the value of unroll count to be zero  in
 '#pragma GCC unroll' and '#pragma unroll'

Signed-off-by: yronglin 
---
 clang/docs/ReleaseNotes.rst |  4 
 clang/include/clang/Sema/Sema.h |  3 ++-
 clang/lib/CodeGen/CGLoopInfo.cpp|  2 ++
 clang/lib/Parse/ParsePragma.cpp |  7 ---
 clang/lib/Sema/SemaExpr.cpp | 12 +--
 clang/lib/Sema/SemaStmtAttr.cpp | 19 +-
 clang/lib/Sema/SemaTemplateInstantiate.cpp  |  3 ++-
 clang/test/CodeGenCXX/pragma-gcc-unroll.cpp | 22 +
 clang/test/Parser/pragma-unroll.cpp |  8 ++--
 9 files changed, 66 insertions(+), 14 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 45a9a79739a4eb..26119e0a788a24 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -420,6 +420,10 @@ Bug Fixes in This Version
 - Fixed a regression in CTAD that a friend declaration that befriends itself 
may cause
   incorrect constraint substitution. (#GH86769).
 
+- Clang now allowed the value of unroll count to be zero in ``#pragma GCC 
unroll`` and ``#pragma unroll``. 
+  The values of 0 and 1 block any unrolling of the loop. This keeps the same 
behavior with GCC.
+  Fixes (`#88624 `_).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c4a603cc5a4a74..d7447470112186 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5449,7 +5449,8 @@ class Sema final : public SemaBase {
   ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind);
   ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val);
 
-  bool CheckLoopHintExpr(Expr *E, SourceLocation Loc);
+  bool CheckLoopHintExpr(Expr *E, SourceLocation Loc,
+ const IdentifierInfo *PragmaNameInfo);
 
   ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = nullptr);
   ExprResult ActOnCharacterConstant(const Token &Tok,
diff --git a/clang/lib/CodeGen/CGLoopInfo.cpp b/clang/lib/CodeGen/CGLoopInfo.cpp
index 0d4800b90a2f26..72d1471021ac02 100644
--- a/clang/lib/CodeGen/CGLoopInfo.cpp
+++ b/clang/lib/CodeGen/CGLoopInfo.cpp
@@ -673,6 +673,8 @@ void LoopInfoStack::push(BasicBlock *Header, 
clang::ASTContext &Ctx,
 setPipelineDisabled(true);
 break;
   case LoopHintAttr::UnrollCount:
+setUnrollState(LoopAttributes::Disable);
+break;
   case LoopHintAttr::UnrollAndJamCount:
   case LoopHintAttr::VectorizeWidth:
   case LoopHintAttr::InterleaveCount:
diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index 0f692e2146a490..ee7ff12a6f3a24 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -1568,7 +1568,8 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) {
   ConsumeToken(); // Consume the constant expression eof terminator.
 
   if (Arg2Error || R.isInvalid() ||
-  Actions.CheckLoopHintExpr(R.get(), Toks[0].getLocation()))
+  Actions.CheckLoopHintExpr(R.get(), Toks[0].getLocation(),
+PragmaNameInfo))
 return false;
 
   // Argument is a constant expression with an integer type.
@@ -1592,8 +1593,8 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) {
 
 ConsumeToken(); // Consume the constant expression eof terminator.
 
-if (R.isInvalid() ||
-Actions.CheckLoopHintExpr(R.get(), Toks[0].getLocation()))
+if (R.isInvalid() || Actions.CheckLoopHintExpr(
+ R.get(), Toks[0].getLocation(), PragmaNameInfo))
   return false;
 
 // Argument is a constant expression with an integer type.
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ec5ca2b9352ed4..8df53cbdaaf1ac 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3880,7 +3880,8 @@ static Expr *BuildFloatingLiteral(Sema &S, 
NumericLiteralParser &Literal,
   return FloatingLiteral::Create(S.Context, Val, isExact, Ty, Loc);
 }
 
-bool Sema::CheckLoopHintExpr(Expr *E, SourceLocation Loc) {
+bool Sema::CheckLoopHintExpr(Expr *E, SourceLocation Loc,
+ const IdentifierInfo *PragmaNameInfo) {
   assert(E && "Invalid expression");
 
   if (E->isVa

[clang] [Clang] Allow the value of unroll count to be zero in '#pragma GCC unroll' and '#pragma unroll' (PR #88666)

2024-04-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (yronglin)


Changes

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

GCC allows the value of loop unroll count to be zero, and the values of 0 and 1 
block any unrolling of the loop. This PR aims to make clang keeps the same 
behavior with GCC.
https://gcc.gnu.org/onlinedocs/gcc/Loop-Specific-Pragmas.html

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


9 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+4) 
- (modified) clang/include/clang/Sema/Sema.h (+2-1) 
- (modified) clang/lib/CodeGen/CGLoopInfo.cpp (+2) 
- (modified) clang/lib/Parse/ParsePragma.cpp (+4-3) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+10-2) 
- (modified) clang/lib/Sema/SemaStmtAttr.cpp (+14-5) 
- (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+2-1) 
- (modified) clang/test/CodeGenCXX/pragma-gcc-unroll.cpp (+22) 
- (modified) clang/test/Parser/pragma-unroll.cpp (+6-2) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 45a9a79739a4eb..26119e0a788a24 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -420,6 +420,10 @@ Bug Fixes in This Version
 - Fixed a regression in CTAD that a friend declaration that befriends itself 
may cause
   incorrect constraint substitution. (#GH86769).
 
+- Clang now allowed the value of unroll count to be zero in ``#pragma GCC 
unroll`` and ``#pragma unroll``. 
+  The values of 0 and 1 block any unrolling of the loop. This keeps the same 
behavior with GCC.
+  Fixes (`#88624 `_).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c4a603cc5a4a74..d7447470112186 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5449,7 +5449,8 @@ class Sema final : public SemaBase {
   ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind);
   ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val);
 
-  bool CheckLoopHintExpr(Expr *E, SourceLocation Loc);
+  bool CheckLoopHintExpr(Expr *E, SourceLocation Loc,
+ const IdentifierInfo *PragmaNameInfo);
 
   ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = nullptr);
   ExprResult ActOnCharacterConstant(const Token &Tok,
diff --git a/clang/lib/CodeGen/CGLoopInfo.cpp b/clang/lib/CodeGen/CGLoopInfo.cpp
index 0d4800b90a2f26..72d1471021ac02 100644
--- a/clang/lib/CodeGen/CGLoopInfo.cpp
+++ b/clang/lib/CodeGen/CGLoopInfo.cpp
@@ -673,6 +673,8 @@ void LoopInfoStack::push(BasicBlock *Header, 
clang::ASTContext &Ctx,
 setPipelineDisabled(true);
 break;
   case LoopHintAttr::UnrollCount:
+setUnrollState(LoopAttributes::Disable);
+break;
   case LoopHintAttr::UnrollAndJamCount:
   case LoopHintAttr::VectorizeWidth:
   case LoopHintAttr::InterleaveCount:
diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index 0f692e2146a490..ee7ff12a6f3a24 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -1568,7 +1568,8 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) {
   ConsumeToken(); // Consume the constant expression eof terminator.
 
   if (Arg2Error || R.isInvalid() ||
-  Actions.CheckLoopHintExpr(R.get(), Toks[0].getLocation()))
+  Actions.CheckLoopHintExpr(R.get(), Toks[0].getLocation(),
+PragmaNameInfo))
 return false;
 
   // Argument is a constant expression with an integer type.
@@ -1592,8 +1593,8 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) {
 
 ConsumeToken(); // Consume the constant expression eof terminator.
 
-if (R.isInvalid() ||
-Actions.CheckLoopHintExpr(R.get(), Toks[0].getLocation()))
+if (R.isInvalid() || Actions.CheckLoopHintExpr(
+ R.get(), Toks[0].getLocation(), PragmaNameInfo))
   return false;
 
 // Argument is a constant expression with an integer type.
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ec5ca2b9352ed4..8df53cbdaaf1ac 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3880,7 +3880,8 @@ static Expr *BuildFloatingLiteral(Sema &S, 
NumericLiteralParser &Literal,
   return FloatingLiteral::Create(S.Context, Val, isExact, Ty, Loc);
 }
 
-bool Sema::CheckLoopHintExpr(Expr *E, SourceLocation Loc) {
+bool Sema::CheckLoopHintExpr(Expr *E, SourceLocation Loc,
+ const IdentifierInfo *PragmaNameInfo) {
   assert(E && "Invalid expression");
 
   if (E->isValueDependent())
@@ -3898,7 +3899,14 @@ bool Sema::CheckLoopHintExpr(Expr *E, SourceLocation 
Loc) {
   if (R.isInvalid())
 return true;
 
-  bool ValueIsPositive = ValueAPS.isStrictlyPositive();
+  // GCC allows the value of unroll count to be 0.
+  // https:/

[clang] [Clang] Allow the value of unroll count to be zero in `#pragma GCC unroll` and `#pragma unroll` (PR #88666)

2024-04-14 Thread via cfe-commits

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


[clang] [Clang] Allow the value of unroll count to be zero in `#pragma GCC unroll` and `#pragma unroll` (PR #88666)

2024-04-14 Thread via cfe-commits

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

>From 8d48a0bd1cf15b9cf00bc294912b674b5f94a11c Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Mon, 15 Apr 2024 00:36:06 +0800
Subject: [PATCH] [Clang] Allow the value of unroll count to be zero  in
 '#pragma GCC unroll' and '#pragma unroll'

Signed-off-by: yronglin 
---
 clang/docs/ReleaseNotes.rst |  4 
 clang/include/clang/Sema/Sema.h |  3 ++-
 clang/lib/CodeGen/CGLoopInfo.cpp|  2 ++
 clang/lib/Parse/ParsePragma.cpp |  7 ---
 clang/lib/Sema/SemaExpr.cpp | 12 +--
 clang/lib/Sema/SemaStmtAttr.cpp | 19 +-
 clang/lib/Sema/SemaTemplateInstantiate.cpp  |  3 ++-
 clang/test/CodeGenCXX/pragma-gcc-unroll.cpp | 22 +
 clang/test/Parser/pragma-unroll.cpp |  8 ++--
 9 files changed, 66 insertions(+), 14 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ade8f4e93d5a0c..5183edcf01b1cc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -423,6 +423,10 @@ Bug Fixes in This Version
 - Fixed a regression in CTAD that a friend declaration that befriends itself 
may cause
   incorrect constraint substitution. (#GH86769).
 
+- Clang now allowed the value of unroll count to be zero in ``#pragma GCC 
unroll`` and ``#pragma unroll``. 
+  The values of 0 and 1 block any unrolling of the loop. This keeps the same 
behavior with GCC.
+  Fixes (`#88624 `_).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c6e0332c3176b3..3b2f3a6d82675c 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5469,7 +5469,8 @@ class Sema final : public SemaBase {
   ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind);
   ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val);
 
-  bool CheckLoopHintExpr(Expr *E, SourceLocation Loc);
+  bool CheckLoopHintExpr(Expr *E, SourceLocation Loc,
+ const IdentifierInfo *PragmaNameInfo);
 
   ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = nullptr);
   ExprResult ActOnCharacterConstant(const Token &Tok,
diff --git a/clang/lib/CodeGen/CGLoopInfo.cpp b/clang/lib/CodeGen/CGLoopInfo.cpp
index 0d4800b90a2f26..72d1471021ac02 100644
--- a/clang/lib/CodeGen/CGLoopInfo.cpp
+++ b/clang/lib/CodeGen/CGLoopInfo.cpp
@@ -673,6 +673,8 @@ void LoopInfoStack::push(BasicBlock *Header, 
clang::ASTContext &Ctx,
 setPipelineDisabled(true);
 break;
   case LoopHintAttr::UnrollCount:
+setUnrollState(LoopAttributes::Disable);
+break;
   case LoopHintAttr::UnrollAndJamCount:
   case LoopHintAttr::VectorizeWidth:
   case LoopHintAttr::InterleaveCount:
diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index 3979f75b6020db..8fed9e70f7a56e 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -1569,7 +1569,8 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) {
   ConsumeToken(); // Consume the constant expression eof terminator.
 
   if (Arg2Error || R.isInvalid() ||
-  Actions.CheckLoopHintExpr(R.get(), Toks[0].getLocation()))
+  Actions.CheckLoopHintExpr(R.get(), Toks[0].getLocation(),
+PragmaNameInfo))
 return false;
 
   // Argument is a constant expression with an integer type.
@@ -1593,8 +1594,8 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) {
 
 ConsumeToken(); // Consume the constant expression eof terminator.
 
-if (R.isInvalid() ||
-Actions.CheckLoopHintExpr(R.get(), Toks[0].getLocation()))
+if (R.isInvalid() || Actions.CheckLoopHintExpr(
+ R.get(), Toks[0].getLocation(), PragmaNameInfo))
   return false;
 
 // Argument is a constant expression with an integer type.
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 505d068ac42ebe..437b31716ed30c 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3885,7 +3885,8 @@ static Expr *BuildFloatingLiteral(Sema &S, 
NumericLiteralParser &Literal,
   return FloatingLiteral::Create(S.Context, Val, isExact, Ty, Loc);
 }
 
-bool Sema::CheckLoopHintExpr(Expr *E, SourceLocation Loc) {
+bool Sema::CheckLoopHintExpr(Expr *E, SourceLocation Loc,
+ const IdentifierInfo *PragmaNameInfo) {
   assert(E && "Invalid expression");
 
   if (E->isValueDependent())
@@ -3903,7 +3904,14 @@ bool Sema::CheckLoopHintExpr(Expr *E, SourceLocation 
Loc) {
   if (R.isInvalid())
 return true;
 
-  bool ValueIsPositive = ValueAPS.isStrictlyPositive();
+  // GCC allows the value of unroll count to be 0.
+  // https://gcc.gnu.org/onlinedocs/gcc/Loop

[clang] [clang] Fix high memory consumption during pack deduction (PR #88637)

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


@@ -831,7 +831,7 @@ class PackDeductionScope {
 if (IsPartiallyExpanded)
   PackElements += NumPartialPackArgs;
 else if (IsExpanded)
-  PackElements += *FixedNumExpansions;
+  PackElements += FixedNumExpansions.value_or(1);

mizvekov wrote:

The assert is not necessary, unless it added explanation.
The `*` operator on the optional here should already assert in that case.

I would advise you run this test case on an llvm build with runtime checks 
enabled. The compiler is going off the rails before this point, so maybe there 
is an earlier assert that could narrow it down.

Otherwise, the change lacks explanation, about what is the problem, and what 
the fix does.

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


[clang-tools-extra] [clang-tidy] check `std::string_view` and custom string-like classes in `readability-string-compare` (PR #88636)

2024-04-14 Thread Vadim D. via cfe-commits


@@ -7,42 +7,70 @@
 
//===--===//
 
 #include "StringCompareCheck.h"
-#include "../utils/FixItHintUtils.h"
+#include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Tooling/FixIt.h"
+#include "llvm/ADT/StringRef.h"
+#include 
 
 using namespace clang::ast_matchers;
+namespace optutils = clang::tidy::utils::options;
 
 namespace clang::tidy::readability {
 
 static const StringRef CompareMessage = "do not use 'compare' to test equality 
"
 "of strings; use the string equality "
 "operator instead";
 
+static const std::vector StringClasses = {
+"::std::basic_string", "::std::basic_string_view"};
+
+StringCompareCheck::StringCompareCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StringLikeClasses(
+  optutils::parseStringList(Options.get("StringLikeClasses", ""))) {}

vvd170501 wrote:

> put StringClasses as default

I thought about implementing the option this way, but it seems to me it'd be a 
bit harder to use than a list of additional classes.
if the user wanted to add custom classes, they'd need to also include 
`std::string` and `std::string_view` in the list to keep the check enabled for 
these classes.
So, I decided to append custom classes to the default list instead of 
overwriting it.

> Or call it like "AdditionalStringLikeClasses"

Ok.

> but still have common handling

Could you elaborate? I'm not sure what you mean by "common handling". Removing 
the lambda?

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


[clang] [Clang] Allow the value of unroll count to be zero in `#pragma GCC unroll` and `#pragma unroll` (PR #88666)

2024-04-14 Thread via cfe-commits

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

>From 8d48a0bd1cf15b9cf00bc294912b674b5f94a11c Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Mon, 15 Apr 2024 00:36:06 +0800
Subject: [PATCH 1/2] [Clang] Allow the value of unroll count to be zero  in
 '#pragma GCC unroll' and '#pragma unroll'

Signed-off-by: yronglin 
---
 clang/docs/ReleaseNotes.rst |  4 
 clang/include/clang/Sema/Sema.h |  3 ++-
 clang/lib/CodeGen/CGLoopInfo.cpp|  2 ++
 clang/lib/Parse/ParsePragma.cpp |  7 ---
 clang/lib/Sema/SemaExpr.cpp | 12 +--
 clang/lib/Sema/SemaStmtAttr.cpp | 19 +-
 clang/lib/Sema/SemaTemplateInstantiate.cpp  |  3 ++-
 clang/test/CodeGenCXX/pragma-gcc-unroll.cpp | 22 +
 clang/test/Parser/pragma-unroll.cpp |  8 ++--
 9 files changed, 66 insertions(+), 14 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ade8f4e93d5a0c..5183edcf01b1cc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -423,6 +423,10 @@ Bug Fixes in This Version
 - Fixed a regression in CTAD that a friend declaration that befriends itself 
may cause
   incorrect constraint substitution. (#GH86769).
 
+- Clang now allowed the value of unroll count to be zero in ``#pragma GCC 
unroll`` and ``#pragma unroll``. 
+  The values of 0 and 1 block any unrolling of the loop. This keeps the same 
behavior with GCC.
+  Fixes (`#88624 `_).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c6e0332c3176b3..3b2f3a6d82675c 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5469,7 +5469,8 @@ class Sema final : public SemaBase {
   ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind);
   ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val);
 
-  bool CheckLoopHintExpr(Expr *E, SourceLocation Loc);
+  bool CheckLoopHintExpr(Expr *E, SourceLocation Loc,
+ const IdentifierInfo *PragmaNameInfo);
 
   ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = nullptr);
   ExprResult ActOnCharacterConstant(const Token &Tok,
diff --git a/clang/lib/CodeGen/CGLoopInfo.cpp b/clang/lib/CodeGen/CGLoopInfo.cpp
index 0d4800b90a2f26..72d1471021ac02 100644
--- a/clang/lib/CodeGen/CGLoopInfo.cpp
+++ b/clang/lib/CodeGen/CGLoopInfo.cpp
@@ -673,6 +673,8 @@ void LoopInfoStack::push(BasicBlock *Header, 
clang::ASTContext &Ctx,
 setPipelineDisabled(true);
 break;
   case LoopHintAttr::UnrollCount:
+setUnrollState(LoopAttributes::Disable);
+break;
   case LoopHintAttr::UnrollAndJamCount:
   case LoopHintAttr::VectorizeWidth:
   case LoopHintAttr::InterleaveCount:
diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index 3979f75b6020db..8fed9e70f7a56e 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -1569,7 +1569,8 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) {
   ConsumeToken(); // Consume the constant expression eof terminator.
 
   if (Arg2Error || R.isInvalid() ||
-  Actions.CheckLoopHintExpr(R.get(), Toks[0].getLocation()))
+  Actions.CheckLoopHintExpr(R.get(), Toks[0].getLocation(),
+PragmaNameInfo))
 return false;
 
   // Argument is a constant expression with an integer type.
@@ -1593,8 +1594,8 @@ bool Parser::HandlePragmaLoopHint(LoopHint &Hint) {
 
 ConsumeToken(); // Consume the constant expression eof terminator.
 
-if (R.isInvalid() ||
-Actions.CheckLoopHintExpr(R.get(), Toks[0].getLocation()))
+if (R.isInvalid() || Actions.CheckLoopHintExpr(
+ R.get(), Toks[0].getLocation(), PragmaNameInfo))
   return false;
 
 // Argument is a constant expression with an integer type.
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 505d068ac42ebe..437b31716ed30c 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -3885,7 +3885,8 @@ static Expr *BuildFloatingLiteral(Sema &S, 
NumericLiteralParser &Literal,
   return FloatingLiteral::Create(S.Context, Val, isExact, Ty, Loc);
 }
 
-bool Sema::CheckLoopHintExpr(Expr *E, SourceLocation Loc) {
+bool Sema::CheckLoopHintExpr(Expr *E, SourceLocation Loc,
+ const IdentifierInfo *PragmaNameInfo) {
   assert(E && "Invalid expression");
 
   if (E->isValueDependent())
@@ -3903,7 +3904,14 @@ bool Sema::CheckLoopHintExpr(Expr *E, SourceLocation 
Loc) {
   if (R.isInvalid())
 return true;
 
-  bool ValueIsPositive = ValueAPS.isStrictlyPositive();
+  // GCC allows the value of unroll count to be 0.
+  // https://gcc.gnu.org/onlinedocs/gcc/

[clang-tools-extra] Include cmath to fix build error on mac os 10.14 (PR #88665)

2024-04-14 Thread via cfe-commits

https://github.com/Zentrik updated 
https://github.com/llvm/llvm-project/pull/88665

>From cdd250c837b9f1b2c35fa12b170c342f6d1ce295 Mon Sep 17 00:00:00 2001
From: Zentrik 
Date: Sun, 14 Apr 2024 17:28:18 +0100
Subject: [PATCH 1/2] Include cmath to fix build error on mac os 10.14

---
 clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
index b299afd540b9a3..45a8f973486147 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include 
 
 namespace {
 using namespace clang::ast_matchers;

>From 8852efd6357ed1b1e5a903b620603f8be9f502af Mon Sep 17 00:00:00 2001
From: Zentrik 
Date: Sun, 14 Apr 2024 18:54:56 +0100
Subject: [PATCH 2/2] Format

---
 clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
index 45a8f973486147..1548fc454cfb37 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
@@ -29,13 +29,13 @@
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/MathExtras.h"
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
-#include 
 
 namespace {
 using namespace clang::ast_matchers;

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


[clang] [clang-format] revert to string << string handling to previous default (PR #88490)

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

owenca wrote:

Please see 
https://github.com/llvm/llvm-project/issues/88483#issuecomment-2053928993 and 
Conversation in #69859, which was the first attempt at adding an option for 
breaking consecutive stream insertion operations. Instead of handling 
everything specified in 
https://github.com/llvm/llvm-project/pull/69859#issuecomment-1776064714 in a 
single patch, we can take a few steps:

1. Handle when to break _before_ `<<`. The current default (since 18.x) is only 
when the left operand is a string literal ending with a newline and the right 
operand is a string literal.
2. Handle whether to indent or align after the break.
3. Do the above for breaking breaking _after_ `<<`.

(Ditto for stream extraction operations if needed.)

For No. 1 above, an `enum` option (e.g. `BreakBeforeStreamInsertionOperator`) 
with `Leave`, `AfterNewline` (LLVM default), `Always`, and `Never` may be 
sufficient. @s1Sharp

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


[clang] [Clang] Allow the value of unroll count to be zero in `#pragma GCC unroll` and `#pragma unroll` (PR #88666)

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

Endilll wrote:

`Sema.h` changes look good.

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


[clang] [Clang][CodeGen] Start migrating away from assuming the Default AS is 0 (PR #88182)

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


@@ -3581,8 +3582,10 @@ ConstantAddress 
CodeGenModule::GetAddrOfTemplateParamObject(
   isExternallyVisible(TPO->getLinkageAndVisibility().getLinkage())
   ? llvm::GlobalValue::LinkOnceODRLinkage
   : llvm::GlobalValue::InternalLinkage;
-  auto *GV = new llvm::GlobalVariable(getModule(), Init->getType(),
-  /*isConstant=*/true, Linkage, Init, 
Name);
+  auto *GV = new llvm::GlobalVariable(
+  getModule(), Init->getType(),
+  /*isConstant=*/true, Linkage, Init, Name, nullptr,
+  llvm::GlobalValue::NotThreadLocal, GlobalsInt8PtrTy->getAddressSpace());

AlexVlx wrote:

I've opened #88455 to fix SPIR & SPIRV, which'll allow simplifying this one in 
the direction you have indicated.

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


[clang-tools-extra] Include cmath to fix build error on mac os 10.14 (PR #88665)

2024-04-14 Thread via cfe-commits

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


[clang] [codegen] Emit missing cleanups for stmt-expr and coro suspensions [take-2] (PR #85398)

2024-04-14 Thread Alexander Yermolovich via cfe-commits

ayermolo wrote:

@usx95 can you repro?
Also is there ETA on a fix, and if not can you revert this?

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


[clang] [clang][Index] Use canonical function parameter types in USRs (PR #68222)

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

mizvekov wrote:

@sdkrystian ping, do you still intend to continue this? Just adding your 
example as a test case would be fine.

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


[clang] [clang][Sema] Preserve the initializer of invalid VarDecls (PR #88645)

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

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


[clang] [clang][Sema] Preserve the initializer of invalid VarDecls (PR #88645)

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


@@ -13435,8 +13435,7 @@ void Sema::checkNonTrivialCUnion(QualType QT, 
SourceLocation Loc,
 void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) {
   // If there is no declaration, there was an error parsing it.  Just ignore
   // the initializer.
-  if (!RealDecl || RealDecl->isInvalidDecl()) {
-CorrectDelayedTyposInExpr(Init, dyn_cast_or_null(RealDecl));
+  if (!RealDecl) {
 return;
   }

mizvekov wrote:

There is an odd change in behavior here, is that intentional?
If there is no declaration, or the declaration is not a VarDecl, then we don't 
try to correct typos in `Init` anymore.

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


[clang] [clang][Sema] Preserve the initializer of invalid VarDecls (PR #88645)

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


@@ -13456,6 +13455,14 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr 
*Init, bool DirectInit) {
 return;
   }
 
+  if (VDecl->isInvalidDecl()) {
+CorrectDelayedTyposInExpr(Init, VDecl);
+VDecl->setInit(
+CreateRecoveryExpr(Init->getBeginLoc(), Init->getEndLoc(), {Init})
+.get());

mizvekov wrote:

`CreateRecoveryExpr` returns an ExprResult, which means it not only returns an 
expression on success, but it can also return an error, and using `get()` in 
that case is UB, you have to check it first.

It can return an error in case we are in an SFINAE context, and also when using 
the frontend flag `-fno-recovery-ast`.

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


[clang] [clang][Sema] Preserve the initializer of invalid VarDecls (PR #88645)

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

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

Thanks for the improvement!

Can you also add a test case?

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


[clang-tools-extra] [clang-tidy] check `std::string_view` and custom string-like classes in `readability-string-compare` (PR #88636)

2024-04-14 Thread Vadim D. via cfe-commits

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


[clang-tools-extra] [clang-tidy] check `std::string_view` and custom string-like classes in `readability-string-compare` (PR #88636)

2024-04-14 Thread Vadim D. via cfe-commits

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


[clang-tools-extra] [clang-tidy] check `std::string_view` and custom string-like classes in `readability-string-compare` (PR #88636)

2024-04-14 Thread Vadim D. via cfe-commits

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


[clang-tools-extra] [clang-tidy] check `std::string_view` and custom string-like classes in `readability-string-compare` (PR #88636)

2024-04-14 Thread Vadim D. via cfe-commits


@@ -7,42 +7,70 @@
 
//===--===//
 
 #include "StringCompareCheck.h"
-#include "../utils/FixItHintUtils.h"
+#include "../utils/OptionsUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Tooling/FixIt.h"
+#include "llvm/ADT/StringRef.h"
+#include 
 
 using namespace clang::ast_matchers;
+namespace optutils = clang::tidy::utils::options;
 
 namespace clang::tidy::readability {
 
 static const StringRef CompareMessage = "do not use 'compare' to test equality 
"
 "of strings; use the string equality "
 "operator instead";
 
+static const std::vector StringClasses = {
+"::std::basic_string", "::std::basic_string_view"};
+
+StringCompareCheck::StringCompareCheck(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  StringLikeClasses(
+  optutils::parseStringList(Options.get("StringLikeClasses", ""))) {}
+
 void StringCompareCheck::registerMatchers(MatchFinder *Finder) {
-  const auto StrCompare = cxxMemberCallExpr(
-  callee(cxxMethodDecl(hasName("compare"),
-   ofClass(classTemplateSpecializationDecl(
-   hasName("::std::basic_string"),
-  hasArgument(0, expr().bind("str2")), argumentCountIs(1),
-  callee(memberExpr().bind("str1")));
-
-  // First and second case: cast str.compare(str) to boolean.
-  Finder->addMatcher(
-  traverse(TK_AsIs,
-   implicitCastExpr(hasImplicitDestinationType(booleanType()),
-has(StrCompare))
-   .bind("match1")),
-  this);
-
-  // Third and fourth case: str.compare(str) == 0 and str.compare(str) != 0.
-  Finder->addMatcher(
-  binaryOperator(hasAnyOperatorName("==", "!="),
- hasOperands(StrCompare.bind("compare"),
- integerLiteral(equals(0)).bind("zero")))
-  .bind("match2"),
-  this);
+  const auto RegisterForClasses = [&, this](const auto &StringClassMatcher) {
+const auto StrCompare = cxxMemberCallExpr(
+callee(cxxMethodDecl(hasName("compare"), ofClass(StringClassMatcher))),
+hasArgument(0, expr().bind("str2")), argumentCountIs(1),
+callee(memberExpr().bind("str1")));
+
+// First and second case: cast str.compare(str) to boolean.
+Finder->addMatcher(
+traverse(TK_AsIs,
+ implicitCastExpr(hasImplicitDestinationType(booleanType()),
+  has(StrCompare))
+ .bind("match1")),
+this);
+
+// Third and fourth case: str.compare(str) == 0
+// and str.compare(str) !=  0.
+Finder->addMatcher(
+binaryOperator(hasAnyOperatorName("==", "!="),
+   hasOperands(StrCompare.bind("compare"),
+   integerLiteral(equals(0)).bind("zero")))
+.bind("match2"),
+this);
+  };
+  if (StringLikeClasses.empty()) {
+RegisterForClasses(
+classTemplateSpecializationDecl(hasAnyName(StringClasses)));
+  } else {
+// StringLikeClasses may or may not be templates, so we need to match both
+// template and non-template classes.
+std::vector PossiblyTemplateClasses = StringClasses;
+PossiblyTemplateClasses.insert(PossiblyTemplateClasses.end(),
+   StringLikeClasses.begin(),
+   StringLikeClasses.end());
+RegisterForClasses(anyOf(
+classTemplateSpecializationDecl(hasAnyName(PossiblyTemplateClasses)),
+cxxRecordDecl(hasAnyName(StringLikeClasses;

vvd170501 wrote:

But would regex be useful here?
- Usually there would be a few (1-2) custom string-like classes, if any, and it 
shouldn't be hard to just put their names into the list.
- The defaults would be less readable (`^::std::string$;^::std::string_view$;` 
or `^::std::string(_view)?$` vs `::std::string;::std::string_view`)

Also, existing checks with a `StringLikeClasses` use `hasAnyName`

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


[clang-tools-extra] [clang-tidy] check `std::string_view` and custom string-like classes in `readability-string-compare` (PR #88636)

2024-04-14 Thread Vadim D. via cfe-commits

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


[clang] Use pushFullExprCleanup for deferred destroy (PR #88670)

2024-04-14 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 created https://github.com/llvm/llvm-project/pull/88670

Instead of directly pushing the `Destroy`, we should use `pushFullExprCleanup` 
which handles conditional branches.
This fixes a backend crash due to 89ba7e183e6e2c64370ed1b963e54c06352211db.

Tested:
```
CLANG_DIR=/usr/local/google/home/usx/build

$CLANG_DIR/bin/clang++ \
  -Itools/clang/tools/extra/clangd \
  -I/usr/local/google/home/usx/src/llvm/llvm-project/clang-tools-extra/clangd \
  
-I/usr/local/google/home/usx/src/llvm/llvm-project/clang-tools-extra/clangd/../include-cleaner/include
 \
  -Itools/clang/tools/extra/clangd/../clang-tidy \
  -I/usr/local/google/home/usx/src/llvm/llvm-project/clang/include \
  -Itools/clang/include \
  -Iinclude \
  -I/usr/local/google/home/usx/src/llvm/llvm-project/llvm/include \
  
-I/usr/local/google/home/usx/src/llvm/llvm-project/clang-tools-extra/pseudo/lib/../include
 \
  -isystem$CLANG_DIR/lib/clang/19/include \
  -o  
/usr/local/google/home/usx/build/bootstrap/tools/clang/tools/extra/clangd/CMakeFiles/obj.clangDaemon.dir/ClangdLSPServer.cpp.o
 \
  -c  
/usr/local/google/home/usx/src/llvm/llvm-project/clang-tools-extra/clangd/ClangdLSPServer.cpp
```

>From 599283c1845a25afe90163a5f0a7a809c622a521 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Sun, 14 Apr 2024 21:21:21 +
Subject: [PATCH] Use pushFullExprCleanup for deferred destroy

---
 clang/lib/CodeGen/CGDecl.cpp | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 8bdafa7c569b08..3f05ebb561da57 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -2216,8 +2216,11 @@ void CodeGenFunction::pushDestroyAndDeferDeactivation(
 void CodeGenFunction::pushDestroyAndDeferDeactivation(
 CleanupKind cleanupKind, Address addr, QualType type, Destroyer *destroyer,
 bool useEHCleanupForArray) {
-  pushCleanupAndDeferDeactivation(
-  cleanupKind, addr, type, destroyer, useEHCleanupForArray);
+  llvm::Instruction *DominatingIP =
+  Builder.CreateFlagLoad(llvm::Constant::getNullValue(Int8PtrTy));
+  pushDestroy(cleanupKind, addr, type, destroyer, useEHCleanupForArray);
+  DeferredDeactivationCleanupStack.push_back(
+  {EHStack.stable_begin(), DominatingIP});
 }
 
 void CodeGenFunction::pushStackRestore(CleanupKind Kind, Address SPMem) {

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


[clang] Use pushFullExprCleanup for deferred destroy (PR #88670)

2024-04-14 Thread Utkarsh Saxena via cfe-commits

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


[clang] Use pushFullExprCleanup for deferred destroy (PR #88670)

2024-04-14 Thread Utkarsh Saxena via cfe-commits

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


[clang] Use pushFullExprCleanup for deferred destroy (PR #88670)

2024-04-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Utkarsh Saxena (usx95)


Changes

Instead of directly pushing the `Destroy`, we should use `pushFullExprCleanup` 
which handles conditional branches.
This fixes a backend crash due to 89ba7e183e6e2c64370ed1b963e54c06352211db.

Tested:
```sh
CLANG_DIR=/usr/local/google/home/usx/build

$CLANG_DIR/bin/clang++ \
  -Itools/clang/tools/extra/clangd \
  -I/usr/local/google/home/usx/src/llvm/llvm-project/clang-tools-extra/clangd \
  
-I/usr/local/google/home/usx/src/llvm/llvm-project/clang-tools-extra/clangd/../include-cleaner/include
 \
  -Itools/clang/tools/extra/clangd/../clang-tidy \
  -I/usr/local/google/home/usx/src/llvm/llvm-project/clang/include \
  -Itools/clang/include \
  -Iinclude \
  -I/usr/local/google/home/usx/src/llvm/llvm-project/llvm/include \
  
-I/usr/local/google/home/usx/src/llvm/llvm-project/clang-tools-extra/pseudo/lib/../include
 \
  -isystem$CLANG_DIR/lib/clang/19/include \
  -o  
/usr/local/google/home/usx/build/bootstrap/tools/clang/tools/extra/clangd/CMakeFiles/obj.clangDaemon.dir/ClangdLSPServer.cpp.o
 \
  -c  
/usr/local/google/home/usx/src/llvm/llvm-project/clang-tools-extra/clangd/ClangdLSPServer.cpp
```

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


1 Files Affected:

- (modified) clang/lib/CodeGen/CGDecl.cpp (+5-2) 


``diff
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 8bdafa7c569b08..3f05ebb561da57 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -2216,8 +2216,11 @@ void CodeGenFunction::pushDestroyAndDeferDeactivation(
 void CodeGenFunction::pushDestroyAndDeferDeactivation(
 CleanupKind cleanupKind, Address addr, QualType type, Destroyer *destroyer,
 bool useEHCleanupForArray) {
-  pushCleanupAndDeferDeactivation(
-  cleanupKind, addr, type, destroyer, useEHCleanupForArray);
+  llvm::Instruction *DominatingIP =
+  Builder.CreateFlagLoad(llvm::Constant::getNullValue(Int8PtrTy));
+  pushDestroy(cleanupKind, addr, type, destroyer, useEHCleanupForArray);
+  DeferredDeactivationCleanupStack.push_back(
+  {EHStack.stable_begin(), DominatingIP});
 }
 
 void CodeGenFunction::pushStackRestore(CleanupKind Kind, Address SPMem) {

``




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


  1   2   >