[llvm] [clang-tools-extra] [clang] [libcxx] [libc] [lldb] [compiler-rt] [flang] [lld] [Legalizer] Expand fmaximum and fminimum (PR #67301)

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


@@ -8310,6 +8310,64 @@ SDValue TargetLowering::expandFMINNUM_FMAXNUM(SDNode 
*Node,
   return SDValue();
 }
 
+SDValue TargetLowering::expandFMINIMUM_FMAXIMUM(SDNode *N,
+SelectionDAG ) const {
+  SDLoc DL(N);
+  SDValue LHS = N->getOperand(0);
+  SDValue RHS = N->getOperand(1);
+  unsigned Opc = N->getOpcode();
+  EVT VT = N->getValueType(0);
+  EVT CCVT = getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT);
+  bool IsMax = Opc == ISD::FMAXIMUM;
+
+  if (VT.isVector() &&
+  isOperationLegalOrCustomOrPromote(Opc, VT.getScalarType()))
+return SDValue();
+
+  // First, implement comparison not propagating NaN. If no native fmin or fmax
+  // available, use plain select with setcc instead.
+  SDValue MinMax;
+  unsigned CompOpcIeee = IsMax ? ISD::FMAXNUM_IEEE : ISD::FMINNUM_IEEE;
+  unsigned CompOpc = IsMax ? ISD::FMAXNUM : ISD::FMINNUM;
+  if (isOperationLegalOrCustom(CompOpcIeee, VT)) {
+MinMax = DAG.getNode(CompOpcIeee, DL, VT, LHS, RHS);
+  } else if (isOperationLegalOrCustom(CompOpc, VT)) {
+MinMax = DAG.getNode(CompOpc, DL, VT, LHS, RHS);
+  } else {
+// NaN (if exists) will be propagated later, so orderness doesn't matter.
+SDValue Compare =
+DAG.getSetCC(DL, CCVT, LHS, RHS, IsMax ? ISD::SETGT : ISD::SETLT);
+MinMax = DAG.getSelect(DL, VT, Compare, LHS, RHS);
+  }
+
+  // Propagate any NaN of both operands
+  if (!N->getFlags().hasNoNaNs() &&
+  (!DAG.isKnownNeverNaN(LHS) || !DAG.isKnownNeverNaN(RHS))) {
+ConstantFP *FPNaN = ConstantFP::get(
+*DAG.getContext(), APFloat::getNaN(DAG.EVTToAPFloatSemantics(VT)));
+MinMax = DAG.getSelect(DL, VT, DAG.getSetCC(DL, CCVT, LHS, RHS, 
ISD::SETUO),
+   DAG.getConstantFP(*FPNaN, DL, VT), MinMax);
+  }
+
+  // fminimum/fmaximum requires -0.0 less than +0.0
+  if (!N->getFlags().hasNoSignedZeros() && !DAG.isKnownNeverZeroFloat(LHS) &&
+  !DAG.isKnownNeverZeroFloat(RHS)) {

arsenm wrote:

Ditto, check RHS first 

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


[lldb] [clang] [libcxx] [lld] [compiler-rt] [libc] [clang-tools-extra] [llvm] [flang] [Legalizer] Expand fmaximum and fminimum (PR #67301)

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


@@ -8262,6 +8262,64 @@ SDValue TargetLowering::expandFMINNUM_FMAXNUM(SDNode 
*Node,
   return SDValue();
 }
 
+SDValue TargetLowering::expandFMINIMUM_FMAXIMUM(SDNode *N,
+SelectionDAG ) const {
+  SDLoc DL(N);
+  SDValue LHS = N->getOperand(0);
+  SDValue RHS = N->getOperand(1);
+  unsigned Opc = N->getOpcode();
+  EVT VT = N->getValueType(0);
+  EVT CCVT = getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT);
+  bool IsMax = Opc == ISD::FMAXIMUM;
+
+  if (VT.isVector() &&
+  isOperationLegalOrCustomOrPromote(Opc, VT.getScalarType()))
+return SDValue();
+
+  // First, implement comparison not propagating NaN. If no native fmin or fmax
+  // available, use plain select with setcc instead.
+  SDValue MinMax;
+  if (isOperationLegalOrCustom(IsMax ? ISD::FMAXNUM_IEEE : ISD::FMINNUM_IEEE,
+   VT)) {
+MinMax = DAG.getNode(IsMax ? ISD::FMAXNUM_IEEE : ISD::FMINNUM_IEEE, DL, VT,
+ LHS, RHS);
+  } else if (isOperationLegalOrCustom(IsMax ? ISD::FMAXNUM : ISD::FMINNUM,
+  VT)) {
+MinMax = DAG.getNode(IsMax ? ISD::FMAXNUM : ISD::FMINNUM, DL, VT, LHS, 
RHS);
+  } else {
+SDValue Compare =
+DAG.getSetCC(DL, CCVT, LHS, RHS, IsMax ? ISD::SETGT : ISD::SETLT);
+MinMax = DAG.getSelect(DL, VT, Compare, LHS, RHS);
+  }
+
+  // Propagate any NaN of both operands
+  if (!N->getFlags().hasNoNaNs() &&
+  (!DAG.isKnownNeverNaN(LHS) || !DAG.isKnownNeverNaN(RHS))) {
+ConstantFP *FPNaN = ConstantFP::get(
+*DAG.getContext(), APFloat::getNaN(DAG.EVTToAPFloatSemantics(VT)));
+MinMax = DAG.getSelect(DL, VT, DAG.getSetCC(DL, CCVT, LHS, RHS, 
ISD::SETUO),
+   DAG.getConstantFP(*FPNaN, DL, VT), MinMax);
+  }
+
+  // fminimum/fmaximum requires -0.0 less than +0.0
+  if (!N->getFlags().hasNoSignedZeros() && !DAG.isKnownNeverZeroFloat(LHS) &&
+  !DAG.isKnownNeverZeroFloat(RHS)) {
+SDValue IsZero = DAG.getSetCC(DL, CCVT, MinMax,
+  DAG.getConstantFP(0.0, DL, VT), ISD::SETEQ);
+SDValue TestZero =
+DAG.getTargetConstant(IsMax ? fcPosZero : fcNegZero, DL, MVT::i32);
+SDValue LCmp = DAG.getSelect(
+DL, VT, DAG.getNode(ISD::IS_FPCLASS, DL, CCVT, LHS, TestZero), LHS,
+MinMax);
+SDValue RCmp = DAG.getSelect(
+DL, VT, DAG.getNode(ISD::IS_FPCLASS, DL, CCVT, RHS, TestZero), RHS,
+LCmp);
+MinMax = DAG.getSelect(DL, VT, IsZero, RCmp, MinMax);

arsenm wrote:

I think we should try to avoid using is_fpclass here. Additionally, I think we 
have under-defined the internally used IEEE nodes. As currently defined, 
minnum_ieee/maxnum_ieee have unspecified signed 0 order. However for AMDGPU at 
least, the actual hardware instructions have always appropriately ordered 0s. 
We could either refine the _IEEE node definitions to be IEEE -2019 and require 
ordered 0 behavior which doesn't require this fixup. 

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


[libcxx] [llvm] [clang-tools-extra] [flang] [lld] [compiler-rt] [lldb] [libc] [clang] [Legalizer] Expand fmaximum and fminimum (PR #67301)

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


@@ -8310,6 +8310,64 @@ SDValue TargetLowering::expandFMINNUM_FMAXNUM(SDNode 
*Node,
   return SDValue();
 }
 
+SDValue TargetLowering::expandFMINIMUM_FMAXIMUM(SDNode *N,
+SelectionDAG ) const {
+  SDLoc DL(N);
+  SDValue LHS = N->getOperand(0);
+  SDValue RHS = N->getOperand(1);
+  unsigned Opc = N->getOpcode();
+  EVT VT = N->getValueType(0);
+  EVT CCVT = getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT);
+  bool IsMax = Opc == ISD::FMAXIMUM;
+
+  if (VT.isVector() &&
+  isOperationLegalOrCustomOrPromote(Opc, VT.getScalarType()))
+return SDValue();
+
+  // First, implement comparison not propagating NaN. If no native fmin or fmax
+  // available, use plain select with setcc instead.
+  SDValue MinMax;
+  unsigned CompOpcIeee = IsMax ? ISD::FMAXNUM_IEEE : ISD::FMINNUM_IEEE;
+  unsigned CompOpc = IsMax ? ISD::FMAXNUM : ISD::FMINNUM;
+  if (isOperationLegalOrCustom(CompOpcIeee, VT)) {
+MinMax = DAG.getNode(CompOpcIeee, DL, VT, LHS, RHS);
+  } else if (isOperationLegalOrCustom(CompOpc, VT)) {
+MinMax = DAG.getNode(CompOpc, DL, VT, LHS, RHS);
+  } else {
+// NaN (if exists) will be propagated later, so orderness doesn't matter.
+SDValue Compare =
+DAG.getSetCC(DL, CCVT, LHS, RHS, IsMax ? ISD::SETGT : ISD::SETLT);
+MinMax = DAG.getSelect(DL, VT, Compare, LHS, RHS);
+  }
+
+  // Propagate any NaN of both operands
+  if (!N->getFlags().hasNoNaNs() &&
+  (!DAG.isKnownNeverNaN(LHS) || !DAG.isKnownNeverNaN(RHS))) {

arsenm wrote:

Should invert the order of these checks. RHS is canonically simpler / cheaper 
to inspect 

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


[clang] [Serialization] Load Specializations Lazily (1/2) (PR #76774)

2024-01-08 Thread Vassil Vassilev via cfe-commits

https://github.com/vgvassilev updated 
https://github.com/llvm/llvm-project/pull/76774

>From 50fd47f2bfda527807f8cc5e46425050246868aa Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Wed, 3 Jan 2024 11:33:17 +0800
Subject: [PATCH 1/2] Load Specializations Lazily

---
 clang/include/clang/AST/DeclTemplate.h|  35 ++--
 clang/include/clang/AST/ExternalASTSource.h   |   6 +
 clang/include/clang/AST/ODRHash.h |   3 +
 .../clang/Sema/MultiplexExternalSemaSource.h  |   6 +
 .../include/clang/Serialization/ASTBitCodes.h |   3 +
 clang/include/clang/Serialization/ASTReader.h |  28 +++
 clang/include/clang/Serialization/ASTWriter.h |   6 +
 clang/lib/AST/DeclTemplate.cpp|  67 +---
 clang/lib/AST/ExternalASTSource.cpp   |   5 +
 clang/lib/AST/ODRHash.cpp |   2 +
 .../lib/Sema/MultiplexExternalSemaSource.cpp  |   6 +
 clang/lib/Serialization/ASTReader.cpp | 125 +-
 clang/lib/Serialization/ASTReaderDecl.cpp |  35 +++-
 clang/lib/Serialization/ASTReaderInternals.h  |  80 +
 clang/lib/Serialization/ASTWriter.cpp | 144 +++-
 clang/lib/Serialization/ASTWriterDecl.cpp |  78 ++---
 clang/test/Modules/odr_hash.cpp   |   4 +-
 clang/unittests/Serialization/CMakeLists.txt  |   1 +
 .../Serialization/LoadSpecLazily.cpp  | 159 ++
 19 files changed, 728 insertions(+), 65 deletions(-)
 create mode 100644 clang/unittests/Serialization/LoadSpecLazily.cpp

diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 832ad2de6b08a8..4699dd17bc182c 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -525,8 +525,11 @@ class FunctionTemplateSpecializationInfo final
 return Function.getInt();
   }
 
+  void loadExternalRedecls();
+
 public:
   friend TrailingObjects;
+  friend class ASTReader;
 
   static FunctionTemplateSpecializationInfo *
   Create(ASTContext , FunctionDecl *FD, FunctionTemplateDecl *Template,
@@ -789,13 +792,15 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 return SpecIterator(isEnd ? Specs.end() : Specs.begin());
   }
 
-  void loadLazySpecializationsImpl() const;
+  void loadExternalSpecializations() const;
 
   template 
   typename SpecEntryTraits::DeclType*
   findSpecializationImpl(llvm::FoldingSetVector ,
  void *, ProfileArguments &&...ProfileArgs);
 
+  void loadLazySpecializationsWithArgs(ArrayRef 
TemplateArgs);
+
   template 
   void addSpecializationImpl(llvm::FoldingSetVector ,
  EntryType *Entry, void *InsertPos);
@@ -814,9 +819,13 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 /// If non-null, points to an array of specializations (including
 /// partial specializations) known only by their external declaration IDs.
 ///
+/// These specializations needs to be loaded at once in
+/// loadExternalSpecializations to complete the redecl chain or be 
preparing
+/// for template resolution.
+///
 /// The first value in the array is the number of specializations/partial
 /// specializations that follow.
-uint32_t *LazySpecializations = nullptr;
+uint32_t *ExternalSpecializations = nullptr;
 
 /// The set of "injected" template arguments used within this
 /// template.
@@ -850,6 +859,8 @@ class RedeclarableTemplateDecl : public TemplateDecl,
   friend class ASTDeclWriter;
   friend class ASTReader;
   template  friend class RedeclarableTemplate;
+  friend class ClassTemplateSpecializationDecl;
+  friend class VarTemplateSpecializationDecl;
 
   /// Retrieves the canonical declaration of this template.
   RedeclarableTemplateDecl *getCanonicalDecl() override {
@@ -977,6 +988,7 @@ SpecEntryTraits {
 class FunctionTemplateDecl : public RedeclarableTemplateDecl {
 protected:
   friend class FunctionDecl;
+  friend class FunctionTemplateSpecializationInfo;
 
   /// Data that is common to all of the declarations of a given
   /// function template.
@@ -1012,13 +1024,13 @@ class FunctionTemplateDecl : public 
RedeclarableTemplateDecl {
   void addSpecialization(FunctionTemplateSpecializationInfo* Info,
  void *InsertPos);
 
+  /// Load any lazily-loaded specializations from the external source.
+  void LoadLazySpecializations() const;
+
 public:
   friend class ASTDeclReader;
   friend class ASTDeclWriter;
 
-  /// Load any lazily-loaded specializations from the external source.
-  void LoadLazySpecializations() const;
-
   /// Get the underlying function declaration of the template.
   FunctionDecl *getTemplatedDecl() const {
 return static_cast(TemplatedDecl);
@@ -1839,6 +1851,8 @@ class ClassTemplateSpecializationDecl
   LLVM_PREFERRED_TYPE(TemplateSpecializationKind)
   unsigned SpecializationKind : 3;
 
+  void loadExternalRedecls();
+
 protected:
   ClassTemplateSpecializationDecl(ASTContext , Kind DK, 

[clang] [clang]use correct this scope to evaluate noexcept expr (PR #77416)

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


@@ -6192,6 +6192,12 @@ bool TreeTransform::TransformExceptionSpec(
 
   // Instantiate a dynamic noexcept expression, if any.
   if (isComputedNoexcept(ESI.Type)) {
+// Update this scrope because ContextDecl in Sema will be used in 
TransformExpr.
+auto *Method = dyn_cast_or_null(ESI.SourceTemplate);

tbaederr wrote:

```suggestion
auto *Method = dyn_cast_if_present(ESI.SourceTemplate);
```

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


[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-01-08 Thread Abhin P Jose via cfe-commits


@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wextra -verify

Abhinkop wrote:

Ok. sounds good I will do that.

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


[clang] [Serialization] Load Specializations Lazily (1/2) (PR #76774)

2024-01-08 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> I failed to use spr to create stacked review... So I just create the stacked 
> PR manually: #77417. Luckily the context are remained. I heard the current 
> context may be lost if we change to use spr now.



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


[llvm] [clang] [clang-tools-extra] [X86] Emit Warnings for frontend options to enable knl/knm specific ISAs. (PR #75580)

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

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

LGTM.

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


[clang] [clang]use correct this scope to evaluate noexcept expr (PR #77416)

2024-01-08 Thread via cfe-commits

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

LGTM

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


[clang] [Serialization] Load Specializations Lazily (1/2) (PR #76774)

2024-01-08 Thread Chuanqi Xu via cfe-commits


@@ -527,6 +527,10 @@ class ASTWriter : public ASTDeserializationListener,
   bool isLookupResultExternal(StoredDeclsList , DeclContext *DC);
   bool isLookupResultEntirelyExternal(StoredDeclsList , DeclContext 
*DC);
 
+  uint64_t
+  WriteSpecsLookupTable(NamedDecl *D,

ChuanqiXu9 wrote:

Done

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


[clang] [Serialization] Load Specializations Lazily (1/2) (PR #76774)

2024-01-08 Thread Chuanqi Xu via cfe-commits


@@ -1249,3 +1249,5 @@ void ODRHash::AddQualType(QualType T) {
 void ODRHash::AddBoolean(bool Value) {
   Bools.push_back(Value);
 }
+
+void ODRHash::AddInteger(unsigned Value) { ID.AddInteger(Value); }

ChuanqiXu9 wrote:

Done

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


[clang] [Serialization] Load Specializations Lazily (1/2) (PR #76774)

2024-01-08 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

I failed to use spr to create stacked review... So I just create the stacked PR 
manually: https://github.com/llvm/llvm-project/pull/77417

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


[llvm] [compiler-rt] [clang-tools-extra] [clang] fix wrong links in documentation (PR #76502)

2024-01-08 Thread via cfe-commits

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


[clang] [clang]use correct this scope to evaluate noexcept expr (PR #77416)

2024-01-08 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 0930f62cf600d9e2e9a45fef1b3a422d50be89d5 
0637a482c881f5ce31fd1debbc8dcc40a05c66ba -- clang/lib/Sema/TreeTransform.h 
clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index fb7e15b5bc..9dc0c55518 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -6192,7 +6192,8 @@ bool TreeTransform::TransformExceptionSpec(
 
   // Instantiate a dynamic noexcept expression, if any.
   if (isComputedNoexcept(ESI.Type)) {
-// Update this scrope because ContextDecl in Sema will be used in 
TransformExpr.
+// Update this scrope because ContextDecl in Sema will be used in
+// TransformExpr.
 auto *Method = dyn_cast_or_null(ESI.SourceTemplate);
 Sema::CXXThisScopeRAII ThisScope(
 SemaRef, Method ? Method->getParent() : nullptr,

``




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


[clang] [Serialization] Load Specializations Lazily (1/2) (PR #76774)

2024-01-08 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/76774

>From 50fd47f2bfda527807f8cc5e46425050246868aa Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Wed, 3 Jan 2024 11:33:17 +0800
Subject: [PATCH] Load Specializations Lazily

---
 clang/include/clang/AST/DeclTemplate.h|  35 ++--
 clang/include/clang/AST/ExternalASTSource.h   |   6 +
 clang/include/clang/AST/ODRHash.h |   3 +
 .../clang/Sema/MultiplexExternalSemaSource.h  |   6 +
 .../include/clang/Serialization/ASTBitCodes.h |   3 +
 clang/include/clang/Serialization/ASTReader.h |  28 +++
 clang/include/clang/Serialization/ASTWriter.h |   6 +
 clang/lib/AST/DeclTemplate.cpp|  67 +---
 clang/lib/AST/ExternalASTSource.cpp   |   5 +
 clang/lib/AST/ODRHash.cpp |   2 +
 .../lib/Sema/MultiplexExternalSemaSource.cpp  |   6 +
 clang/lib/Serialization/ASTReader.cpp | 125 +-
 clang/lib/Serialization/ASTReaderDecl.cpp |  35 +++-
 clang/lib/Serialization/ASTReaderInternals.h  |  80 +
 clang/lib/Serialization/ASTWriter.cpp | 144 +++-
 clang/lib/Serialization/ASTWriterDecl.cpp |  78 ++---
 clang/test/Modules/odr_hash.cpp   |   4 +-
 clang/unittests/Serialization/CMakeLists.txt  |   1 +
 .../Serialization/LoadSpecLazily.cpp  | 159 ++
 19 files changed, 728 insertions(+), 65 deletions(-)
 create mode 100644 clang/unittests/Serialization/LoadSpecLazily.cpp

diff --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index 832ad2de6b08a8..4699dd17bc182c 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -525,8 +525,11 @@ class FunctionTemplateSpecializationInfo final
 return Function.getInt();
   }
 
+  void loadExternalRedecls();
+
 public:
   friend TrailingObjects;
+  friend class ASTReader;
 
   static FunctionTemplateSpecializationInfo *
   Create(ASTContext , FunctionDecl *FD, FunctionTemplateDecl *Template,
@@ -789,13 +792,15 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 return SpecIterator(isEnd ? Specs.end() : Specs.begin());
   }
 
-  void loadLazySpecializationsImpl() const;
+  void loadExternalSpecializations() const;
 
   template 
   typename SpecEntryTraits::DeclType*
   findSpecializationImpl(llvm::FoldingSetVector ,
  void *, ProfileArguments &&...ProfileArgs);
 
+  void loadLazySpecializationsWithArgs(ArrayRef 
TemplateArgs);
+
   template 
   void addSpecializationImpl(llvm::FoldingSetVector ,
  EntryType *Entry, void *InsertPos);
@@ -814,9 +819,13 @@ class RedeclarableTemplateDecl : public TemplateDecl,
 /// If non-null, points to an array of specializations (including
 /// partial specializations) known only by their external declaration IDs.
 ///
+/// These specializations needs to be loaded at once in
+/// loadExternalSpecializations to complete the redecl chain or be 
preparing
+/// for template resolution.
+///
 /// The first value in the array is the number of specializations/partial
 /// specializations that follow.
-uint32_t *LazySpecializations = nullptr;
+uint32_t *ExternalSpecializations = nullptr;
 
 /// The set of "injected" template arguments used within this
 /// template.
@@ -850,6 +859,8 @@ class RedeclarableTemplateDecl : public TemplateDecl,
   friend class ASTDeclWriter;
   friend class ASTReader;
   template  friend class RedeclarableTemplate;
+  friend class ClassTemplateSpecializationDecl;
+  friend class VarTemplateSpecializationDecl;
 
   /// Retrieves the canonical declaration of this template.
   RedeclarableTemplateDecl *getCanonicalDecl() override {
@@ -977,6 +988,7 @@ SpecEntryTraits {
 class FunctionTemplateDecl : public RedeclarableTemplateDecl {
 protected:
   friend class FunctionDecl;
+  friend class FunctionTemplateSpecializationInfo;
 
   /// Data that is common to all of the declarations of a given
   /// function template.
@@ -1012,13 +1024,13 @@ class FunctionTemplateDecl : public 
RedeclarableTemplateDecl {
   void addSpecialization(FunctionTemplateSpecializationInfo* Info,
  void *InsertPos);
 
+  /// Load any lazily-loaded specializations from the external source.
+  void LoadLazySpecializations() const;
+
 public:
   friend class ASTDeclReader;
   friend class ASTDeclWriter;
 
-  /// Load any lazily-loaded specializations from the external source.
-  void LoadLazySpecializations() const;
-
   /// Get the underlying function declaration of the template.
   FunctionDecl *getTemplatedDecl() const {
 return static_cast(TemplatedDecl);
@@ -1839,6 +1851,8 @@ class ClassTemplateSpecializationDecl
   LLVM_PREFERRED_TYPE(TemplateSpecializationKind)
   unsigned SpecializationKind : 3;
 
+  void loadExternalRedecls();
+
 protected:
   ClassTemplateSpecializationDecl(ASTContext , Kind DK, 

[clang] [clang]use correct this scope to evaluate noexcept expr (PR #77416)

2024-01-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Congcong Cai (HerrCai0907)


Changes

Fixes: #77411
When substituting deduced type, noexcept expr in method should be instantiated 
and evaluated.
ThisScrope should be switched to method context instead of origin sema context

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2-1) 
- (modified) clang/lib/Sema/TreeTransform.h (+6) 
- (modified) clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp (+15) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 803eb2f7c74cf6..2695a0e30f58e0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -610,7 +610,8 @@ Bug Fixes in This Version
   of template classes. Fixes
   (`#68543 `_,
   `#42496 `_,
-  `#77071 `_)
+  `#77071 `_,
+  `#77411 `_)
 - Fixed an issue when a shift count larger than ``__INT64_MAX__``, in a right
   shift operation, could result in missing warnings about
   ``shift count >= width of type`` or internal compiler error.
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index c8c5a51bf9f94e..fb7e15b5bcbb02 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -6192,6 +6192,12 @@ bool TreeTransform::TransformExceptionSpec(
 
   // Instantiate a dynamic noexcept expression, if any.
   if (isComputedNoexcept(ESI.Type)) {
+// Update this scrope because ContextDecl in Sema will be used in 
TransformExpr.
+auto *Method = dyn_cast_or_null(ESI.SourceTemplate);
+Sema::CXXThisScopeRAII ThisScope(
+SemaRef, Method ? Method->getParent() : nullptr,
+Method ? Method->getMethodQualifiers() : Qualifiers{},
+Method != nullptr);
 EnterExpressionEvaluationContext Unevaluated(
 getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated);
 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
diff --git a/clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp 
b/clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp
index 11b1093f9064f6..5e56f19477d6ca 100644
--- a/clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp
+++ b/clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp
@@ -64,6 +64,21 @@ namespace DependentDefaultCtorExceptionSpec {
   struct A { multimap Map; } a;
 
   static_assert(noexcept(A()));
+
+  template  struct NoexceptWithThis {
+int ca;
+template  auto foo(T) noexcept(ca) { return true; }
+// expected-error@-1 {{noexcept specifier argument is not a constant 
expression}}
+// expected-note@-2 {{in instantiation of exception specification}}
+// expected-note@-3 {{implicit use of 'this' pointer is only allowed 
within the evaluation of a call to a 'constexpr' member function}}
+  };
+  struct InstantiateFromAnotherClass {
+template (::foo))> // expected-note {{in instantiation of function 
template specialization}}
+InstantiateFromAnotherClass(B *) {} // expected-note {{in instantiation of 
default argument}}
+  };
+  NoexceptWithThis f{};
+  // Don't crash here.
+  InstantiateFromAnotherClass b{}; // expected-note {{while substituting 
deduced template arguments into function template}}
 }
 
 #endif

``




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


[clang] [clang]use correct this scope to evaluate noexcept expr (PR #77416)

2024-01-08 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 created 
https://github.com/llvm/llvm-project/pull/77416

Fixes: #77411
When substituting deduced type, noexcept expr in method should be instantiated 
and evaluated.
ThisScrope should be switched to method context instead of origin sema context

>From 0637a482c881f5ce31fd1debbc8dcc40a05c66ba Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Tue, 9 Jan 2024 14:53:25 +0800
Subject: [PATCH] [clang]use correct this scope to evaluate noexcept expr when
 deduce template

Fixes: #77411
When substituting deduced type, noexcept expr in function decl should be 
instantiated and evaluated.
ThisScrope should be switched to method context
---
 clang/docs/ReleaseNotes.rst   |  3 ++-
 clang/lib/Sema/TreeTransform.h|  6 ++
 .../test/SemaCXX/cxx1z-noexcept-function-type.cpp | 15 +++
 3 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 803eb2f7c74cf6..2695a0e30f58e0 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -610,7 +610,8 @@ Bug Fixes in This Version
   of template classes. Fixes
   (`#68543 `_,
   `#42496 `_,
-  `#77071 `_)
+  `#77071 `_,
+  `#77411 `_)
 - Fixed an issue when a shift count larger than ``__INT64_MAX__``, in a right
   shift operation, could result in missing warnings about
   ``shift count >= width of type`` or internal compiler error.
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index c8c5a51bf9f94e..fb7e15b5bcbb02 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -6192,6 +6192,12 @@ bool TreeTransform::TransformExceptionSpec(
 
   // Instantiate a dynamic noexcept expression, if any.
   if (isComputedNoexcept(ESI.Type)) {
+// Update this scrope because ContextDecl in Sema will be used in 
TransformExpr.
+auto *Method = dyn_cast_or_null(ESI.SourceTemplate);
+Sema::CXXThisScopeRAII ThisScope(
+SemaRef, Method ? Method->getParent() : nullptr,
+Method ? Method->getMethodQualifiers() : Qualifiers{},
+Method != nullptr);
 EnterExpressionEvaluationContext Unevaluated(
 getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated);
 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
diff --git a/clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp 
b/clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp
index 11b1093f9064f6..5e56f19477d6ca 100644
--- a/clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp
+++ b/clang/test/SemaCXX/cxx1z-noexcept-function-type.cpp
@@ -64,6 +64,21 @@ namespace DependentDefaultCtorExceptionSpec {
   struct A { multimap Map; } a;
 
   static_assert(noexcept(A()));
+
+  template  struct NoexceptWithThis {
+int ca;
+template  auto foo(T) noexcept(ca) { return true; }
+// expected-error@-1 {{noexcept specifier argument is not a constant 
expression}}
+// expected-note@-2 {{in instantiation of exception specification}}
+// expected-note@-3 {{implicit use of 'this' pointer is only allowed 
within the evaluation of a call to a 'constexpr' member function}}
+  };
+  struct InstantiateFromAnotherClass {
+template (::foo))> // expected-note {{in instantiation of function 
template specialization}}
+InstantiateFromAnotherClass(B *) {} // expected-note {{in instantiation of 
default argument}}
+  };
+  NoexceptWithThis f{};
+  // Don't crash here.
+  InstantiateFromAnotherClass b{}; // expected-note {{while substituting 
deduced template arguments into function template}}
 }
 
 #endif

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


[clang] [llvm] [RISCV] Deduplicate RISCVISAInfo::toFeatures/toFeatureVector. NFC (PR #76942)

2024-01-08 Thread Luke Lau via cfe-commits

https://github.com/lukel97 updated 
https://github.com/llvm/llvm-project/pull/76942

>From e0b653a5f81d18155583f6dfd669003b6664a517 Mon Sep 17 00:00:00 2001
From: Luke Lau 
Date: Thu, 4 Jan 2024 14:02:39 +0900
Subject: [PATCH 1/6] [RISCV] Deduplicate
 RISCVISAInfo::toFeatures/toFeatureVector. NFC

toFeatures and toFeatureVector both output a list of target feature flags, just
with a slightly different interface. toFeatures keeps any unsupported
extensions, and also provides a way to append negative extensions
(AddAllExtensions=true).

This patch combines them into one function, so that a later patch will be be
able to get a std::vector of features that includes all the negative
extensions, which was previously only possible through the StrAlloc interface.
---
 clang/lib/Basic/Targets/RISCV.cpp   |  4 +--
 clang/lib/Driver/ToolChains/Arch/RISCV.cpp  |  6 ++--
 llvm/include/llvm/Support/RISCVISAInfo.h|  6 ++--
 llvm/lib/Object/ELFObjectFile.cpp   |  2 +-
 llvm/lib/Support/RISCVISAInfo.cpp   | 38 +++--
 llvm/unittests/Support/RISCVISAInfoTest.cpp | 30 +---
 6 files changed, 45 insertions(+), 41 deletions(-)

diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 59ae12eed94014..daaa8639ae8358 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -296,7 +296,7 @@ bool RISCVTargetInfo::initFeatureMap(
   }
 
   // RISCVISAInfo makes implications for ISA features
-  std::vector ImpliedFeatures = (*ParseResult)->toFeatureVector();
+  std::vector ImpliedFeatures = (*ParseResult)->toFeatures();
 
   // parseFeatures normalizes the feature set by dropping any explicit
   // negatives, and non-extension features.  We need to preserve the later
@@ -413,7 +413,7 @@ static void handleFullArchString(StringRef FullArchStr,
 // Forward the invalid FullArchStr.
 Features.push_back("+" + FullArchStr.str());
   } else {
-std::vector FeatStrings = (*RII)->toFeatureVector();
+std::vector FeatStrings = (*RII)->toFeatures();
 Features.insert(Features.end(), FeatStrings.begin(), FeatStrings.end());
   }
 }
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 0717e3b813e1e2..b97224426b916a 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -42,9 +42,9 @@ static bool getArchFeatures(const Driver , StringRef Arch,
 return false;
   }
 
-  (*ISAInfo)->toFeatures(
-  Features, [](const Twine ) { return Args.MakeArgString(Str); },
-  /*AddAllExtensions=*/true);
+  for (std::string  : (*ISAInfo)->toFeatures(/*AddAllExtension=*/true,
+ /*IgnoreUnknown=*/false))
+Features.push_back(Args.MakeArgString(Str));
 
   if (EnableExperimentalExtensions)
 Features.push_back(Args.MakeArgString("+experimental"));
diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 09c4edd6df60e9..c539448683d368 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -68,9 +68,8 @@ class RISCVISAInfo {
   parseFeatures(unsigned XLen, const std::vector );
 
   /// Convert RISC-V ISA info to a feature vector.
-  void toFeatures(std::vector ,
-  llvm::function_ref StrAlloc,
-  bool AddAllExtensions) const;
+  std::vector toFeatures(bool AddAllExtensions = false,
+  bool IgnoreUnknown = true) const;
 
   const OrderedExtensionMap () const { return Exts; };
 
@@ -83,7 +82,6 @@ class RISCVISAInfo {
 
   bool hasExtension(StringRef Ext) const;
   std::string toString() const;
-  std::vector toFeatureVector() const;
   StringRef computeDefaultABI() const;
 
   static bool isSupportedExtensionFeature(StringRef Ext);
diff --git a/llvm/lib/Object/ELFObjectFile.cpp 
b/llvm/lib/Object/ELFObjectFile.cpp
index 95c4f9f8545db2..ae21b81c10c82a 100644
--- a/llvm/lib/Object/ELFObjectFile.cpp
+++ b/llvm/lib/Object/ELFObjectFile.cpp
@@ -315,7 +315,7 @@ Expected 
ELFObjectFileBase::getRISCVFeatures() const {
 else
   llvm_unreachable("XLEN should be 32 or 64.");
 
-Features.addFeaturesVector(ISAInfo->toFeatureVector());
+Features.addFeaturesVector(ISAInfo->toFeatures());
   }
 
   return Features;
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index a9b7e209915a13..6d267fae5a5dc6 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -466,35 +466,37 @@ bool RISCVISAInfo::compareExtension(const std::string 
,
   return LHS < RHS;
 }
 
-void RISCVISAInfo::toFeatures(
-std::vector ,
-llvm::function_ref StrAlloc,
-bool AddAllExtensions) const {
+std::vector RISCVISAInfo::toFeatures(bool AddAllExtensions,
+  bool IgnoreUnknown) const {
+  std::vector Features;
   

[libunwind] [libunwind] fix dynamic .eh_frame registration (PR #77185)

2024-01-08 Thread via cfe-commits

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


[libunwind] [libunwind] Add length info for dynamic .eh_frame registration (PR #77185)

2024-01-08 Thread via cfe-commits

https://github.com/SihangZhu updated 
https://github.com/llvm/llvm-project/pull/77185

>From 98c824926af0b42d267b76f1c2416173b55138c4 Mon Sep 17 00:00:00 2001
From: SihangZhu 
Date: Sat, 6 Jan 2024 15:43:41 +0800
Subject: [PATCH] [libunwind] fix dynamic .eh_frame registration

---
 libunwind/src/libunwind.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp
index cd610377b63de8..723c8ceb5c8c94 100644
--- a/libunwind/src/libunwind.cpp
+++ b/libunwind/src/libunwind.cpp
@@ -324,7 +324,7 @@ void __unw_add_dynamic_eh_frame_section(unw_word_t 
eh_frame_start) {
   CFI_Parser::CIE_Info cieInfo;
   CFI_Parser::FDE_Info fdeInfo;
   auto p = (LocalAddressSpace::pint_t)eh_frame_start;
-  while (true) {
+  while (LocalAddressSpace::sThisAddressSpace.get32(p)) {
 if (CFI_Parser::decodeFDE(
 LocalAddressSpace::sThisAddressSpace, p, , ,
 true) == NULL) {

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


[lldb] [compiler-rt] [clang-tools-extra] [libcxxabi] [flang] [libc] [lld] [llvm] [libcxx] [clang] [RISCV] Support Global Dynamic TLSDESC in the RISC-V backend (PR #66915)

2024-01-08 Thread Fangrui Song via cfe-commits


@@ -71,6 +71,18 @@ enum Fixups {
   // Used to generate an R_RISCV_ALIGN relocation, which indicates the linker
   // should fixup the alignment after linker relaxation.
   fixup_riscv_align,
+  // 20-bit fixup corresponding to %tlsdesc_hi(foo) for instructions like
+  // auipc
+  fixup_riscv_tlsdesc_hi20,

MaskRay wrote:

I wonder whether we can just use `MCFixupKind(FirstLiteralRelocationKind + 
ELF::R_RISCV_TLSDESC_CALL)`

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


[libc] [libcxxabi] [lldb] [compiler-rt] [clang-tools-extra] [clang] [llvm] [flang] [lld] [libcxx] [RISCV] Support Global Dynamic TLSDESC in the RISC-V backend (PR #66915)

2024-01-08 Thread Fangrui Song via cfe-commits

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


[lldb] [compiler-rt] [clang-tools-extra] [libcxxabi] [flang] [libc] [lld] [llvm] [libcxx] [clang] [RISCV] Support Global Dynamic TLSDESC in the RISC-V backend (PR #66915)

2024-01-08 Thread Fangrui Song via cfe-commits


@@ -188,3 +188,8 @@ addi a2, ft0, 24 # CHECK: :[[@LINE]]:10: error: invalid 
operand for instruction
 
 # fence.tso accepts no operands
 fence.tso rw, rw # CHECK: :[[@LINE]]:11: error: invalid operand for instruction
+
+.Ltlsdesc_hi0:
+jalr   x5, 0(a1), %tlsdesc_hi(.Ltlsdesc_hi0) # CHECK: :[[@LINE]]:17: error: 
operand must be a symbol with %tlsdesc_call modifier
+jalr   x1, 0(a1), %tlsdesc_call(.Ltlsdesc_hi0) # CHECK: :[[@LINE]]:12: error: 
the output operand must be t0/x5 when using %tlsdesc_call modifier

MaskRay wrote:

I think it's clearer to place these negative tests in a test named `tlsdesc*.s`

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


[libunwind] [libunwind] Add length info for dynamic .eh_frame registration (PR #77185)

2024-01-08 Thread via cfe-commits

https://github.com/SihangZhu updated 
https://github.com/llvm/llvm-project/pull/77185

>From 8d718a7deee63482091f96c5b10bc085d66b2f1a Mon Sep 17 00:00:00 2001
From: SihangZhu 
Date: Sat, 6 Jan 2024 15:43:41 +0800
Subject: [PATCH] [libunwind] Add length info for .eh_frame registration

---
 libunwind/src/libunwind.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp
index cd610377b63de8..723c8ceb5c8c94 100644
--- a/libunwind/src/libunwind.cpp
+++ b/libunwind/src/libunwind.cpp
@@ -324,7 +324,7 @@ void __unw_add_dynamic_eh_frame_section(unw_word_t 
eh_frame_start) {
   CFI_Parser::CIE_Info cieInfo;
   CFI_Parser::FDE_Info fdeInfo;
   auto p = (LocalAddressSpace::pint_t)eh_frame_start;
-  while (true) {
+  while (LocalAddressSpace::sThisAddressSpace.get32(p)) {
 if (CFI_Parser::decodeFDE(
 LocalAddressSpace::sThisAddressSpace, p, , ,
 true) == NULL) {

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


[flang] [lldb] [clang-tools-extra] [libcxx] [compiler-rt] [lld] [openmp] [clang] [libc] [llvm] [PGO][OpenMP] Instrumentation for GPU devices (PR #76587)

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

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


[flang] [lldb] [clang-tools-extra] [libcxx] [compiler-rt] [lld] [openmp] [clang] [libc] [llvm] [PGO][OpenMP] Instrumentation for GPU devices (PR #76587)

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


@@ -959,8 +959,12 @@ void CodeGenPGO::emitCounterIncrement(CGBuilderTy 
, const Stmt *S,
 
   unsigned Counter = (*RegionCounterMap)[S];
 
-  llvm::Value *Args[] = {FuncNameVar,
- Builder.getInt64(FunctionHash),
+  // Make sure that pointer to global is passed in with zero addrspace
+  // This is relevant during GPU profiling
+  auto *NormalizedPtr = llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(
+  FuncNameVar, llvm::PointerType::getUnqual(CGM.getLLVMContext()));

arsenm wrote:

Avoid using getUnqual. I'm sure there's a proper address space to query 
somewhere here 

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


[lldb] [compiler-rt] [clang-tools-extra] [openmp] [flang] [libc] [lld] [llvm] [libcxx] [clang] [PGO][OpenMP] Instrumentation for GPU devices (PR #76587)

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


@@ -448,8 +456,12 @@ GlobalVariable *createPGOFuncNameVar(Module ,
   new GlobalVariable(M, Value->getType(), true, Linkage, Value,
  getPGOFuncNameVarName(PGOFuncName, Linkage));
 
+  // If the target is a GPU, make the symbol protected so it can
+  // be read from the host device
+  if (isGPUProfTarget(M))
+FuncNameVar->setVisibility(GlobalValue::ProtectedVisibility);
   // Hide the symbol so that we correctly get a copy for each executable.
-  if (!GlobalValue::isLocalLinkage(FuncNameVar->getLinkage()))
+  else if (!GlobalValue::isLocalLinkage(FuncNameVar->getLinkage()))
 FuncNameVar->setVisibility(GlobalValue::HiddenVisibility);

arsenm wrote:

Can you spot this into some kind of function-to-visibility to use function? 
This doesn't feel like the right way to control it, so might as well cleanly 
separate it out 

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


[flang] [libcxxabi] [lldb] [clang-tools-extra] [libcxx] [compiler-rt] [lld] [clang] [libc] [llvm] [RISCV] Support Global Dynamic TLSDESC in the RISC-V backend (PR #66915)

2024-01-08 Thread Fangrui Song via cfe-commits

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


[llvm] [clang-tools-extra] [clang] [X86] Use plain load/store instead of cmpxchg16b for atomics with AVX (PR #74275)

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

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

I don't know anything about x86 but this seems plausible 

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


[flang] [libcxxabi] [lldb] [clang-tools-extra] [libcxx] [compiler-rt] [lld] [clang] [libc] [llvm] [RISCV] Support Global Dynamic TLSDESC in the RISC-V backend (PR #66915)

2024-01-08 Thread Fangrui Song via cfe-commits


@@ -71,6 +71,18 @@ enum Fixups {
   // Used to generate an R_RISCV_ALIGN relocation, which indicates the linker
   // should fixup the alignment after linker relaxation.
   fixup_riscv_align,
+  // 20-bit fixup corresponding to %tlsdesc_hi(foo) for instructions like
+  // auipc
+  fixup_riscv_tlsdesc_hi20,

MaskRay wrote:

> instructions like auipc

It seems that tlsdesc is auipc-style only, instead of lui-style. You can say 
that this is for auipc.

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


[llvm] [clang] [RISCV] Deduplicate RISCVISAInfo::toFeatures/toFeatureVector. NFC (PR #76942)

2024-01-08 Thread Luke Lau via cfe-commits

https://github.com/lukel97 updated 
https://github.com/llvm/llvm-project/pull/76942

>From caa25a73dd69268490c89d5e9e91b8d545bce760 Mon Sep 17 00:00:00 2001
From: Luke Lau 
Date: Thu, 4 Jan 2024 14:02:39 +0900
Subject: [PATCH 1/6] [RISCV] Deduplicate
 RISCVISAInfo::toFeatures/toFeatureVector. NFC

toFeatures and toFeatureVector both output a list of target feature flags, just
with a slightly different interface. toFeatures keeps any unsupported
extensions, and also provides a way to append negative extensions
(AddAllExtensions=true).

This patch combines them into one function, so that a later patch will be be
able to get a std::vector of features that includes all the negative
extensions, which was previously only possible through the StrAlloc interface.
---
 clang/lib/Basic/Targets/RISCV.cpp   |  6 ++--
 clang/lib/Driver/ToolChains/Arch/RISCV.cpp  |  6 ++--
 llvm/include/llvm/Support/RISCVISAInfo.h|  6 ++--
 llvm/lib/Object/ELFObjectFile.cpp   |  2 +-
 llvm/lib/Support/RISCVISAInfo.cpp   | 38 +++--
 llvm/unittests/Support/RISCVISAInfoTest.cpp | 30 +---
 6 files changed, 46 insertions(+), 42 deletions(-)

diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 6bc57a83a2d5ae..64f5f9e9215dcb 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -245,7 +245,7 @@ collectNonISAExtFeature(ArrayRef 
FeaturesNeedOverride, int XLen) {
 return std::vector();
   }
 
-  std::vector ImpliedFeatures = (*ParseResult)->toFeatureVector();
+  std::vector ImpliedFeatures = (*ParseResult)->toFeatures();
 
   std::vector NonISAExtFeatureVec;
 
@@ -303,7 +303,7 @@ bool RISCVTargetInfo::initFeatureMap(
   }
 
   // RISCVISAInfo makes implications for ISA features
-  std::vector ImpliedFeatures = (*ParseResult)->toFeatureVector();
+  std::vector ImpliedFeatures = (*ParseResult)->toFeatures();
 
   // parseFeatures normalizes the feature set by dropping any explicit
   // negatives, and non-extension features.  We need to preserve the later
@@ -420,7 +420,7 @@ static void handleFullArchString(StringRef FullArchStr,
 // Forward the invalid FullArchStr.
 Features.push_back("+" + FullArchStr.str());
   } else {
-std::vector FeatStrings = (*RII)->toFeatureVector();
+std::vector FeatStrings = (*RII)->toFeatures();
 Features.insert(Features.end(), FeatStrings.begin(), FeatStrings.end());
   }
 }
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 0717e3b813e1e2..b97224426b916a 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -42,9 +42,9 @@ static bool getArchFeatures(const Driver , StringRef Arch,
 return false;
   }
 
-  (*ISAInfo)->toFeatures(
-  Features, [](const Twine ) { return Args.MakeArgString(Str); },
-  /*AddAllExtensions=*/true);
+  for (std::string  : (*ISAInfo)->toFeatures(/*AddAllExtension=*/true,
+ /*IgnoreUnknown=*/false))
+Features.push_back(Args.MakeArgString(Str));
 
   if (EnableExperimentalExtensions)
 Features.push_back(Args.MakeArgString("+experimental"));
diff --git a/llvm/include/llvm/Support/RISCVISAInfo.h 
b/llvm/include/llvm/Support/RISCVISAInfo.h
index 09c4edd6df60e9..c539448683d368 100644
--- a/llvm/include/llvm/Support/RISCVISAInfo.h
+++ b/llvm/include/llvm/Support/RISCVISAInfo.h
@@ -68,9 +68,8 @@ class RISCVISAInfo {
   parseFeatures(unsigned XLen, const std::vector );
 
   /// Convert RISC-V ISA info to a feature vector.
-  void toFeatures(std::vector ,
-  llvm::function_ref StrAlloc,
-  bool AddAllExtensions) const;
+  std::vector toFeatures(bool AddAllExtensions = false,
+  bool IgnoreUnknown = true) const;
 
   const OrderedExtensionMap () const { return Exts; };
 
@@ -83,7 +82,6 @@ class RISCVISAInfo {
 
   bool hasExtension(StringRef Ext) const;
   std::string toString() const;
-  std::vector toFeatureVector() const;
   StringRef computeDefaultABI() const;
 
   static bool isSupportedExtensionFeature(StringRef Ext);
diff --git a/llvm/lib/Object/ELFObjectFile.cpp 
b/llvm/lib/Object/ELFObjectFile.cpp
index 95c4f9f8545db2..ae21b81c10c82a 100644
--- a/llvm/lib/Object/ELFObjectFile.cpp
+++ b/llvm/lib/Object/ELFObjectFile.cpp
@@ -315,7 +315,7 @@ Expected 
ELFObjectFileBase::getRISCVFeatures() const {
 else
   llvm_unreachable("XLEN should be 32 or 64.");
 
-Features.addFeaturesVector(ISAInfo->toFeatureVector());
+Features.addFeaturesVector(ISAInfo->toFeatures());
   }
 
   return Features;
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index a9b7e209915a13..6d267fae5a5dc6 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -466,35 +466,37 @@ bool RISCVISAInfo::compareExtension(const std::string 
,
   return LHS < RHS;

[lldb] [compiler-rt] [clang-tools-extra] [libcxxabi] [flang] [libc] [lld] [llvm] [libcxx] [clang] [RISCV] Support Global Dynamic TLSDESC in the RISC-V backend (PR #66915)

2024-01-08 Thread Fangrui Song via cfe-commits

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


[lld] [clang] [llvm] Support .note.gnu.property for enable Zicfiss and Zicfilp extension (PR #77414)

2024-01-08 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 2bc93584f5193d78177273c45c82ea69675f44e7 
478e5c7c91e7d28448f1e64affcfcc3c28db9106 -- 
clang/test/Preprocessor/riscv-target-features.c lld/ELF/Config.h 
lld/ELF/Driver.cpp lld/ELF/InputFiles.cpp lld/ELF/SyntheticSections.cpp 
llvm/include/llvm/BinaryFormat/ELF.h llvm/lib/Support/RISCVISAInfo.cpp 
llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp 
llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp 
llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.h 
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp 
llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp 
llvm/tools/llvm-readobj/ELFDumper.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 324e0704f78..3a6513b6aca 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -2653,7 +2653,7 @@ static uint32_t getAndFeatures() {
   features |= GNU_PROPERTY_RISCV_FEATURE_1_ZICFILP;
   if (config->zZicfilpReport == "none")
 warn(toString(f) + ": -z force-zicfilp: file does not have "
- "GNU_PROPERTY_RISCV_FEATURE_1_ZICFILP property");
+   "GNU_PROPERTY_RISCV_FEATURE_1_ZICFILP property");
 }
 
 if (config->zForceZicfiss &&
@@ -2661,7 +2661,7 @@ static uint32_t getAndFeatures() {
   features |= GNU_PROPERTY_RISCV_FEATURE_1_ZICFISS;
   if (config->zZicfissReport == "none")
 warn(toString(f) + ": -z force-zicfiss: file does not have "
- "GNU_PROPERTY_RISCV_FEATURE_1_ZICFISS property");
+   "GNU_PROPERTY_RISCV_FEATURE_1_ZICFISS property");
 }
 
 if (config->zPacPlt && !(features & GNU_PROPERTY_AARCH64_FEATURE_1_PAC)) {
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 93c623919e4..e55810ead5d 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -315,16 +315,16 @@ GnuPropertySection::GnuPropertySection()
 
 void GnuPropertySection::writeTo(uint8_t *buf) {
   uint32_t featureAndType = 0;
-  switch(config->emachine) {
-default:
-  featureAndType = GNU_PROPERTY_X86_FEATURE_1_AND;
-  break;
-case EM_AARCH64:
-  featureAndType = GNU_PROPERTY_AARCH64_FEATURE_1_AND;
-  break;
-case EM_RISCV:
-  featureAndType = GNU_PROPERTY_RISCV_FEATURE_1_AND;
-  break;
+  switch (config->emachine) {
+  default:
+featureAndType = GNU_PROPERTY_X86_FEATURE_1_AND;
+break;
+  case EM_AARCH64:
+featureAndType = GNU_PROPERTY_AARCH64_FEATURE_1_AND;
+break;
+  case EM_RISCV:
+featureAndType = GNU_PROPERTY_RISCV_FEATURE_1_AND;
+break;
   }
 
   write32(buf, 4);   // Name size
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp 
b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
index c82b62bbd77..28477aaf240 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVELFStreamer.cpp
@@ -83,7 +83,8 @@ void RISCVTargetELFStreamer::emitNoteSection(unsigned Flags) {
 
   MCStreamer  = getStreamer();
   MCContext  = OutStreamer.getContext();
-  MCSectionELF *Nt = Context.getELFSection(".note.gnu.property", 
ELF::SHT_NOTE, ELF::SHF_ALLOC);
+  MCSectionELF *Nt = Context.getELFSection(".note.gnu.property", ELF::SHT_NOTE,
+   ELF::SHF_ALLOC);
   MCSection *Cur = OutStreamer.getCurrentSectionOnly();
   OutStreamer.switchSection(Nt);
 
@@ -92,10 +93,11 @@ void RISCVTargetELFStreamer::emitNoteSection(unsigned 
Flags) {
   OutStreamer.emitIntValue(4, 4); // data size for note name
   OutStreamer.emitIntValue(4 * 4, 4); // data size
   OutStreamer.emitIntValue(ELF::NT_GNU_PROPERTY_TYPE_0, 4); // note type
-  OutStreamer.emitBytes(StringRef("GNU", 4)); // note name
+  OutStreamer.emitBytes(StringRef("GNU", 4));   // note name
 
   // Emit the CFI(ZICFILP/ZICFISS) properties.
-  OutStreamer.emitIntValue(ELF::GNU_PROPERTY_RISCV_FEATURE_1_AND, 4); // and 
property
+  OutStreamer.emitIntValue(ELF::GNU_PROPERTY_RISCV_FEATURE_1_AND,
+   4);// and property
   OutStreamer.emitIntValue(4, 4); // data size
   OutStreamer.emitIntValue(Flags, 4); // data
   OutStreamer.emitIntValue(0, 4); // pad
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp 
b/llvm/tools/llvm-readobj/ELFDumper.cpp
index a20f836b6ce..212db3b03db 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -5241,7 +5241,8 @@ static std::string getGNUProperty(uint32_t Type, uint32_t 
DataSize,
 }
 
 template 
-static SmallVector getGNUPropertyList(ArrayRef Arr, 
uint16_t Target) {
+static SmallVector getGNUPropertyList(ArrayRef Arr,
+  

[lld] [clang] [llvm] Support .note.gnu.property for enable Zicfiss and Zicfilp extension (PR #77414)

2024-01-08 Thread via cfe-commits

github-actions[bot] wrote:

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

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

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

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

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

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

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

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


[lld] [clang] [llvm] Support .note.gnu.property for enable Zicfiss and Zicfilp extension (PR #77414)

2024-01-08 Thread via cfe-commits

https://github.com/SuHo-llrr created 
https://github.com/llvm/llvm-project/pull/77414

Emit Zicfiss/Zicfilp to .note.gnu.property sections

1. for spec v0.4.0 Zicifss/Zicfilp is AND feature means that all objects need 
to have this feature.
2. Emit note section when Zicifss/Zicfilp extension is enabled.
3. Checking all objects enable Zicifss/Zicfilp when linking.
4. Add -zforce-zicfilp/-zforce-zicfiss options to force emit Zicifss/Zicfilp 
flags on in .note.gnu.property

>From 11c09a29e2774300b03052ecff4286fd15a0daf9 Mon Sep 17 00:00:00 2001
From: Yeting Kuo 
Date: Tue, 12 Sep 2023 12:28:00 +0800
Subject: [PATCH 01/10] [RISCV] Add MC layer support for Zicfiss.

The patch adds the instructions in Zicfiss extension. Zicfiss extension is
to support shadow stack for control flow integrity.

Differential Revision: https://reviews.llvm.org/D152793
---
 .../test/Preprocessor/riscv-target-features.c |   9 ++
 llvm/docs/RISCVUsage.rst  |   3 +
 llvm/lib/Support/RISCVISAInfo.cpp |   2 +
 .../RISCV/Disassembler/RISCVDisassembler.cpp  |  29 +
 llvm/lib/Target/RISCV/RISCVFeatures.td|   7 ++
 llvm/lib/Target/RISCV/RISCVInstrInfo.td   |   9 +-
 .../lib/Target/RISCV/RISCVInstrInfoZicfiss.td |  86 +++
 llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp   |   3 +
 llvm/lib/Target/RISCV/RISCVRegisterInfo.td|   9 ++
 llvm/test/MC/RISCV/attribute-arch.s   |   3 +
 llvm/test/MC/RISCV/rv32zicfiss-invalid.s  |  20 
 llvm/test/MC/RISCV/rv32zicfiss-valid.s| 103 ++
 llvm/test/MC/RISCV/rv64zicfiss-invalid.s  |  20 
 llvm/test/MC/RISCV/rv64zicfiss-valid.s| 103 ++
 14 files changed, 402 insertions(+), 4 deletions(-)
 create mode 100644 llvm/lib/Target/RISCV/RISCVInstrInfoZicfiss.td
 create mode 100644 llvm/test/MC/RISCV/rv32zicfiss-invalid.s
 create mode 100644 llvm/test/MC/RISCV/rv32zicfiss-valid.s
 create mode 100644 llvm/test/MC/RISCV/rv64zicfiss-invalid.s
 create mode 100644 llvm/test/MC/RISCV/rv64zicfiss-valid.s

diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index ffdec34ca615fe..1f2e957e9eb3ad 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -115,6 +115,7 @@
 // CHECK-NOT: __riscv_zfa {{.*$}}
 // CHECK-NOT: __riscv_zfbfmin {{.*$}}
 // CHECK-NOT: __riscv_zicfilp {{.*$}}
+// CHECK-NOT: __riscv_zicfiss {{.*$}}
 // CHECK-NOT: __riscv_zicond {{.*$}}
 // CHECK-NOT: __riscv_ztso {{.*$}}
 // CHECK-NOT: __riscv_zvbb {{.*$}}
@@ -1246,3 +1247,11 @@
 // RUN: -march=rv64i_zve32x_zvkt1p0 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZVKT-EXT %s
 // CHECK-ZVKT-EXT: __riscv_zvkt 100{{$}}
+
+// RUN: %clang -target riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32izicfiss0p3 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZICFISS-EXT %s
+// RUN: %clang -target riscv64 -menable-experimental-extensions \
+// RUN: -march=rv64izicfiss0p3 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZICFISS-EXT %s
+// CHECK-ZICFISS-EXT: __riscv_zicfiss 3000{{$}}
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 6812efaeb36e0c..617786c4e6c522 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -203,6 +203,9 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``experimental-zicfilp``
   LLVM implements the `0.2 draft specification 
`__.
 
+``experimental-zicfiss``
+  LLVM implements the `0.3.1 draft specification 
`__.
+
 ``experimental-zicond``
   LLVM implements the `1.0-rc1 draft specification 
`__.
 
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 22208e2e0c2950..0e3c4f7af181fd 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -172,6 +172,8 @@ static const RISCVSupportedExtension 
SupportedExperimentalExtensions[] = {
 {"zfbfmin", RISCVExtensionVersion{0, 8}},
 
 {"zicfilp", RISCVExtensionVersion{0, 2}},
+{"zicfiss", RISCVExtensionVersion{0, 3}},
+
 {"zicond", RISCVExtensionVersion{1, 0}},
 
 {"ztso", RISCVExtensionVersion{0, 1}},
diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp 
b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index e5ce029449a8c6..f7f81896f33ba5 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -74,6 +74,17 @@ static DecodeStatus DecodeGPRRegisterClass(MCInst , 
uint32_t RegNo,
   return MCDisassembler::Success;
 }
 
+static DecodeStatus DecodeGPRRARegisterClass(MCInst , uint32_t RegNo,
+ uint64_t Address,
+  

[clang] [clang][coverage] fixing "if constexpr" and "if consteval" coverage report (PR #77214)

2024-01-08 Thread Jessica Paquette via cfe-commits
Hana =?utf-8?q?Dusi=CC=81kova=CC=81?= 
Message-ID:
In-Reply-To: 


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


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


[clang] [clang][coverage] fixing "if constexpr" and "if consteval" coverage report (PR #77214)

2024-01-08 Thread Jessica Paquette via cfe-commits
Hana =?utf-8?q?Dusi=CC=81kova=CC=81?= 
Message-ID:
In-Reply-To: 


ornata wrote:

LGTM

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


[compiler-rt] [lld] [llvm] [mlir] [clang] [sanitizer] Select non-internal frames in ReportErrorSummary (PR #77406)

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

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/77406

>From 5ac8056f36abb37a251f3696800d52a57e24c758 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Mon, 8 Jan 2024 19:45:51 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 .../sanitizer_symbolizer_report.cpp   | 28 ++-
 .../Linux/aligned_alloc-alignment.cpp |  2 +-
 .../TestCases/Linux/pvalloc-overflow.cpp  |  2 +-
 .../Posix/posix_memalign-alignment.cpp|  2 +-
 .../TestCases/allocator_returns_null.cpp  | 16 +--
 .../test/hwasan/TestCases/halt-on-error.cpp   |  6 ++--
 .../test/hwasan/TestCases/report-unmapped.cpp |  2 +-
 .../test/hwasan/TestCases/use-after-free.c|  2 +-
 .../TestCases/allocator_returns_null.cpp  | 16 +--
 .../TestCases/max_allocation_size.cpp | 16 +--
 10 files changed, 53 insertions(+), 39 deletions(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp 
b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp
index 0cf250f7212943..4e5c55a8f85b22 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_report.cpp
@@ -95,17 +95,31 @@ void ReportErrorSummary(const char *error_type, const 
StackTrace *stack,
 #if !SANITIZER_GO
   if (!common_flags()->print_summary)
 return;
-  if (stack->size == 0) {
-ReportErrorSummary(error_type);
-return;
+
+  // Find first non-internal stack frame.
+  for (uptr i = 0; i < stack->size; ++i) {
+uptr pc = StackTrace::GetPreviousInstructionPc(stack->trace[i]);
+SymbolizedStackHolder symbolized_stack(
+Symbolizer::GetOrInit()->SymbolizePC(pc));
+if (const SymbolizedStack *frame = symbolized_stack.get()) {
+  if (const SymbolizedStack *summary_frame = SkipInternalFrames(frame)) {
+ReportErrorSummary(error_type, summary_frame->info, alt_tool_name);
+return;
+  }
+}
   }
-  // Currently, we include the first stack frame into the report summary.
-  // Maybe sometimes we need to choose another frame (e.g. skip memcpy/etc).
+
+  // Fallback to the top one.
   uptr pc = StackTrace::GetPreviousInstructionPc(stack->trace[0]);
   SymbolizedStackHolder symbolized_stack(
   Symbolizer::GetOrInit()->SymbolizePC(pc));
-  const SymbolizedStack *frame = symbolized_stack.get();
-  ReportErrorSummary(error_type, frame->info, alt_tool_name);
+  if (const SymbolizedStack *frame = symbolized_stack.get()) {
+ReportErrorSummary(error_type, frame->info, alt_tool_name);
+return;
+  }
+
+  // Fallback to a summary without location.
+  ReportErrorSummary(error_type);
 #endif
 }
 
diff --git 
a/compiler-rt/test/hwasan/TestCases/Linux/aligned_alloc-alignment.cpp 
b/compiler-rt/test/hwasan/TestCases/Linux/aligned_alloc-alignment.cpp
index ad5b7616e8a7fb..35e29e8cc83435 100644
--- a/compiler-rt/test/hwasan/TestCases/Linux/aligned_alloc-alignment.cpp
+++ b/compiler-rt/test/hwasan/TestCases/Linux/aligned_alloc-alignment.cpp
@@ -14,7 +14,7 @@ int main() {
   // CHECK: ERROR: HWAddressSanitizer: invalid alignment requested in 
aligned_alloc: 17
   // CHECK: {{#0 0x.* in .*}}{{aligned_alloc|memalign}}
   // CHECK: {{#1 0x.* in main .*aligned_alloc-alignment.cpp:}}[[@LINE-3]]
-  // CHECK: SUMMARY: HWAddressSanitizer: invalid-aligned-alloc-alignment 
{{.*}} in aligned_alloc
+  // CHECK: SUMMARY: HWAddressSanitizer: invalid-aligned-alloc-alignment 
{{.*}} in main
 
   printf("pointer after failed aligned_alloc: %zd\n", (size_t)p);
   // CHECK-NULL: pointer after failed aligned_alloc: 0
diff --git a/compiler-rt/test/hwasan/TestCases/Linux/pvalloc-overflow.cpp 
b/compiler-rt/test/hwasan/TestCases/Linux/pvalloc-overflow.cpp
index bd9f34a0dac921..6b4410449a838a 100644
--- a/compiler-rt/test/hwasan/TestCases/Linux/pvalloc-overflow.cpp
+++ b/compiler-rt/test/hwasan/TestCases/Linux/pvalloc-overflow.cpp
@@ -39,6 +39,6 @@ int main(int argc, char *argv[]) {
 // CHECK: {{ERROR: HWAddressSanitizer: pvalloc parameters overflow: size .* 
rounded up to system page size .* cannot be represented in type size_t}}
 // CHECK: {{#0 0x.* in .*pvalloc}}
 // CHECK: {{#1 0x.* in main .*pvalloc-overflow.cpp:}}
-// CHECK: SUMMARY: HWAddressSanitizer: pvalloc-overflow {{.*}} in pvalloc
+// CHECK: SUMMARY: HWAddressSanitizer: pvalloc-overflow {{.*}} in main
 
 // CHECK-NULL: errno: 12
diff --git 
a/compiler-rt/test/hwasan/TestCases/Posix/posix_memalign-alignment.cpp 
b/compiler-rt/test/hwasan/TestCases/Posix/posix_memalign-alignment.cpp
index 029e086f99ada2..5841ca42ceb033 100644
--- a/compiler-rt/test/hwasan/TestCases/Posix/posix_memalign-alignment.cpp
+++ b/compiler-rt/test/hwasan/TestCases/Posix/posix_memalign-alignment.cpp
@@ -11,7 +11,7 @@ int main() {
   // CHECK: ERROR: 

[clang] [clang][coverage] fixing "if constexpr" and "if consteval" coverage report (PR #77214)

2024-01-08 Thread Hana Dusíková via cfe-commits


@@ -7732,7 +7732,11 @@ TreeTransform::TransformIfStmt(IfStmt *S) {
 if (Then.isInvalid())
   return StmtError();
   } else {
-Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc());
+// Discarded branch is replaced with empty CompoundStmt so we can keep
+// proper source location for start and end of original branch, so
+// subsequent transformations like CoverageMapping work properly

hanickadot wrote:

IMHO There is nothing to fix later. This will stay, it replaces former using of 
NullStmt in  branch and NULL in  branch.

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


[clang] [clang][coverage] fixing "if constexpr" and "if consteval" coverage report (PR #77214)

2024-01-08 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot updated 
https://github.com/llvm/llvm-project/pull/77214

From 413517b2a1d4e45b6c58ab282c7990e83f429ab9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Mon, 8 Jan 2024 11:54:45 +0100
Subject: [PATCH 1/2] [coverage] fix incorrect coverage reporting for "if
 constexpr" and "if consteval"

---
 clang/docs/ReleaseNotes.rst  |  3 +
 clang/include/clang/AST/Stmt.h   |  6 +-
 clang/lib/CodeGen/CoverageMappingGen.cpp | 13 +++-
 clang/lib/Sema/TreeTransform.h   | 10 ++-
 clang/test/CoverageMapping/if.cpp| 86 +++-
 5 files changed, 96 insertions(+), 22 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c9b577bd549b1e..c36e051d055b72 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -696,6 +696,9 @@ Bug Fixes in This Version
 - Clang now accepts recursive non-dependent calls to functions with deduced
   return type.
   Fixes (`#71015 `_)
+- Clang now emits correct source location for code-coverage regions in `if 
constexpr`
+  and `if consteval` branches.
+  Fixes (`#54419 `_)
 
 
 Bug Fixes to Compiler Builtins
diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index da7b37ce0e1211..e1fde24e647789 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -1631,8 +1631,10 @@ class CompoundStmt final
   SourceLocation RB);
 
   // Build an empty compound statement with a location.
-  explicit CompoundStmt(SourceLocation Loc)
-  : Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(Loc) {
+  explicit CompoundStmt(SourceLocation Loc) : CompoundStmt(Loc, Loc) {}
+
+  CompoundStmt(SourceLocation Loc, SourceLocation EndLoc)
+  : Stmt(CompoundStmtClass), LBraceLoc(Loc), RBraceLoc(EndLoc) {
 CompoundStmtBits.NumStmts = 0;
 CompoundStmtBits.HasFPFeatures = 0;
   }
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp 
b/clang/lib/CodeGen/CoverageMappingGen.cpp
index bf227386a71b78..b245abd16c3f4a 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -1712,7 +1712,11 @@ struct CounterCoverageMappingBuilder
   extendRegion(S->getCond());
 
 Counter ParentCount = getRegion().getCounter();
-Counter ThenCount = getRegionCounter(S);
+
+// If this is "if !consteval" the then-branch will never be taken, we don't
+// need to change counter
+Counter ThenCount =
+S->isNegatedConsteval() ? ParentCount : getRegionCounter(S);
 
 if (!S->isConsteval()) {
   // Emitting a counter for the condition makes it easier to interpret the
@@ -1729,7 +1733,12 @@ struct CounterCoverageMappingBuilder
 extendRegion(S->getThen());
 Counter OutCount = propagateCounts(ThenCount, S->getThen());
 
-Counter ElseCount = subtractCounters(ParentCount, ThenCount);
+// If this is "if consteval" the else-branch will never be taken, we don't
+// need to change counter
+Counter ElseCount = S->isNonNegatedConsteval()
+? ParentCount
+: subtractCounters(ParentCount, ThenCount);
+
 if (const Stmt *Else = S->getElse()) {
   bool ThenHasTerminateStmt = HasTerminateStmt;
   HasTerminateStmt = false;
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index c8c5a51bf9f94e..19266a7ffa2fe0 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -7732,7 +7732,11 @@ TreeTransform::TransformIfStmt(IfStmt *S) {
 if (Then.isInvalid())
   return StmtError();
   } else {
-Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc());
+// Discarded branch is replaced with empty CompoundStmt so we can keep
+// proper source location for start and end of original branch, so
+// subsequent transformations like CoverageMapping work properly
+Then = new (getSema().Context)
+CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc());
   }
 
   // Transform the "else" branch.
@@ -7741,6 +7745,10 @@ TreeTransform::TransformIfStmt(IfStmt *S) {
 Else = getDerived().TransformStmt(S->getElse());
 if (Else.isInvalid())
   return StmtError();
+  } else if (S->getElse() && ConstexprConditionValue &&
+ *ConstexprConditionValue) {
+Else = new (getSema().Context)
+CompoundStmt(S->getElse()->getBeginLoc(), S->getElse()->getEndLoc());
   }
 
   if (!getDerived().AlwaysRebuild() &&
diff --git a/clang/test/CoverageMapping/if.cpp 
b/clang/test/CoverageMapping/if.cpp
index 65e3d62df79db4..cc18f791c2f79e 100644
--- a/clang/test/CoverageMapping/if.cpp
+++ b/clang/test/CoverageMapping/if.cpp
@@ -23,19 +23,29 @@ void foo() {// CHECK-NEXT: Gap,File 0, 
[[@LINE+1]]:21 -> [[@
 }  

[polly] [lldb] [compiler-rt] [clang-tools-extra] [libcxxabi] [flang] [libc] [openmp] [llvm] [mlir] [libcxx] [clang] [OpenMP] Patch for Support to loop bind clause : Checking Parent Region (PR #76938)

2024-01-08 Thread Sandeep Kosuri via cfe-commits

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


[clang] 782c525 - [OpenMP] Patch for Support to loop bind clause : Checking Parent Region (#76938)

2024-01-08 Thread via cfe-commits

Author: SunilKuravinakop
Date: 2024-01-09T11:14:56+05:30
New Revision: 782c5250077cf472941f0ab7555f87ff22d6e724

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

LOG: [OpenMP] Patch for Support to loop bind clause : Checking Parent Region 
(#76938)

Changes uploaded to the phabricator on Dec 16th are lost because the
phabricator is down. Hence re-uploading it to the github.com.

  Changes to be committed:
modified:   clang/include/clang/Sema/Sema.h
modified:   clang/lib/Sema/SemaOpenMP.cpp
modified:   clang/test/OpenMP/generic_loop_ast_print.cpp
modified:   clang/test/OpenMP/loop_bind_messages.cpp
modified:   clang/test/PCH/pragma-loop.cpp

-

Co-authored-by: Sunil Kuravinakop

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/loop_bind_messages.cpp
clang/test/PCH/pragma-loop.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 8f44adef38159e..4c464a1ae4c67f 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11346,9 +11346,12 @@ class Sema final {
   /// rigorous semantic checking in the new mapped directives.
   bool mapLoopConstruct(llvm::SmallVector ,
 ArrayRef Clauses,
-OpenMPBindClauseKind BindKind,
+OpenMPBindClauseKind ,
 OpenMPDirectiveKind ,
-OpenMPDirectiveKind );
+OpenMPDirectiveKind ,
+SourceLocation StartLoc, SourceLocation EndLoc,
+const DeclarationNameInfo ,
+OpenMPDirectiveKind CancelRegion);
 
 public:
   /// The declarator \p D defines a function in the scope \p S which is nested

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index f34d2959dc6191..365032c9642123 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -5072,6 +5072,18 @@ static bool checkNestingOfRegions(Sema , const 
DSAStackTy *Stack,
 CurrentRegion != OMPD_cancellation_point &&
 CurrentRegion != OMPD_cancel && CurrentRegion != OMPD_scan)
   return false;
+// Checks needed for mapping "loop" construct. Please check 
mapLoopConstruct
+// for a detailed explanation
+if (SemaRef.LangOpts.OpenMP >= 50 && CurrentRegion == OMPD_loop &&
+(BindKind == OMPC_BIND_parallel || BindKind == OMPC_BIND_teams) &&
+(isOpenMPWorksharingDirective(ParentRegion) ||
+ ParentRegion == OMPD_loop)) {
+  int ErrorMsgNumber = (BindKind == OMPC_BIND_parallel) ? 1 : 4;
+  SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region)
+  << true << getOpenMPDirectiveName(ParentRegion) << ErrorMsgNumber
+  << getOpenMPDirectiveName(CurrentRegion);
+  return true;
+}
 if (CurrentRegion == OMPD_cancellation_point ||
 CurrentRegion == OMPD_cancel) {
   // OpenMP [2.16, Nesting of Regions]
@@ -6124,21 +6136,25 @@ processImplicitMapsWithDefaultMappers(Sema , 
DSAStackTy *Stack,
 
 bool Sema::mapLoopConstruct(llvm::SmallVector ,
 ArrayRef Clauses,
-OpenMPBindClauseKind BindKind,
+OpenMPBindClauseKind ,
 OpenMPDirectiveKind ,
-OpenMPDirectiveKind ) {
+OpenMPDirectiveKind ,
+SourceLocation StartLoc, SourceLocation EndLoc,
+const DeclarationNameInfo ,
+OpenMPDirectiveKind CancelRegion) {
 
   bool UseClausesWithoutBind = false;
 
   // Restricting to "#pragma omp loop bind"
   if (getLangOpts().OpenMP >= 50 && Kind == OMPD_loop) {
+
+const OpenMPDirectiveKind ParentDirective = DSAStack->getParentDirective();
+
 if (BindKind == OMPC_BIND_unknown) {
   // Setting the enclosing teams or parallel construct for the loop
   // directive without bind clause.
   BindKind = OMPC_BIND_thread; // Default bind(thread) if binding is 
unknown
 
-  const OpenMPDirectiveKind ParentDirective =
-  DSAStack->getParentDirective();
   if (ParentDirective == OMPD_unknown) {
 Diag(DSAStack->getDefaultDSALocation(),
  diag::err_omp_bind_required_on_loop);
@@ -6150,9 +6166,10 @@ bool Sema::mapLoopConstruct(llvm::SmallVector ,
 BindKind = OMPC_BIND_teams;
   }
 } else {
-  // bind clause is present, so we should set flag indicating to only
-  // use the clauses that aren't the bind clause for the new directive that
-  // loop is lowered to.
+  // bind clause is 

[clang] [clang-format] Fix crash involving array designators and dangling comma (PR #77045)

2024-01-08 Thread via cfe-commits

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


[clang] [clang-format] Fix crash involving array designators and dangling comma (PR #77045)

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


@@ -1444,16 +1444,26 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
   } else if (C.Tok->is(tok::comma)) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
-if (C.Tok->getNextNonComment()->isNot(tok::r_brace)) // dangling comma
+
+if (const auto *Next = C.Tok->getNextNonComment();
+Next && Next->isNot(tok::r_brace)) { // Dangling comma.
   ++Cell;
+}
   }
 } else if (Depth == 1) {
   if (C.Tok == MatchingParen) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
 Cells.push_back(CellDescription{i, ++Cell, i + 1, false, nullptr});
-CellCounts.push_back(C.Tok->Previous->isNot(tok::comma) ? Cell + 1
-: Cell);
+CellCounts.push_back(
+C.Tok->Previous->isNot(tok::comma) &&
+// When dealing with C array designators. There is a
+// possibility of some nested array not having an `=`.
+// When this happens we make the cells non rectangular,
+// avoiding an access out of bound later on.
+MatchingParen->MatchingParen->Previous->isNot(tok::equal)

owenca wrote:

Yep, so we should fix that instead. :)

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


[lld] [lldb] [llvm] [polly] [libcxxabi] [openmp] [libcxx] [libc] [mlir] [flang] [compiler-rt] [libunwind] [clang] [clang-tools-extra] Make clang report invalid target versions. (PR #75373)

2024-01-08 Thread via cfe-commits

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


[clang] f6dbd4c - Make clang report invalid target versions. (#75373)

2024-01-08 Thread via cfe-commits

Author: ZijunZhaoCCK
Date: 2024-01-08T20:46:05-08:00
New Revision: f6dbd4cc5f52b6d40f98cf09af22b276b8e1f289

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

LOG: Make clang report invalid target versions. (#75373)

Clang always silently ignores garbage target versions and this makes
debug harder. So clang will report when target versions are invalid.

Added: 
clang/test/Driver/android-version.cpp

Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/Driver.cpp
clang/test/CodeGen/aarch64-fix-cortex-a53-835769.c
clang/test/Driver/aarch64-fix-cortex-a53-835769.c
llvm/include/llvm/TargetParser/Triple.h
llvm/lib/TargetParser/Triple.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 676f1a62b49dd0..0a8a77fadbeb1b 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -786,4 +786,7 @@ def warn_android_unversioned_fallback : Warning<
   " directories will not be used in Clang 19. Provide a versioned directory"
   " for the target version or lower instead.">,
   InGroup>;
+
+def err_drv_triple_version_invalid : Error<
+  "version '%0' in target triple '%1' is invalid">;
 }

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 9b2f2a37480983..1889ea28079df1 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1430,6 +1430,17 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   const ToolChain  = getToolChain(
   *UArgs, computeTargetTriple(*this, TargetTriple, *UArgs));
 
+  if (TC.getTriple().isAndroid()) {
+llvm::Triple Triple = TC.getTriple();
+StringRef TripleVersionName = Triple.getEnvironmentVersionString();
+
+if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "") {
+  Diags.Report(diag::err_drv_triple_version_invalid)
+  << TripleVersionName << TC.getTripleString();
+  ContainsError = true;
+}
+  }
+
   // Report warning when arm64EC option is overridden by specified target
   if ((TC.getTriple().getArch() != llvm::Triple::aarch64 ||
TC.getTriple().getSubArch() != llvm::Triple::AArch64SubArch_arm64ec) &&

diff  --git a/clang/test/CodeGen/aarch64-fix-cortex-a53-835769.c 
b/clang/test/CodeGen/aarch64-fix-cortex-a53-835769.c
index 3d1a2c7aceb1f1..e5d70564d57b30 100644
--- a/clang/test/CodeGen/aarch64-fix-cortex-a53-835769.c
+++ b/clang/test/CodeGen/aarch64-fix-cortex-a53-835769.c
@@ -5,13 +5,13 @@
 // RUN: %clang -O3 -target aarch64-linux-eabi -mno-fix-cortex-a53-835769 %s -S 
-o- 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO --check-prefix=CHECK %s
 
-// RUN: %clang -O3 -target aarch64-android-eabi %s -S -o- \
+// RUN: %clang -O3 --target=aarch64-linux-androideabi %s -S -o- \
 // RUN:   | FileCheck --check-prefix=CHECK-YES --check-prefix=CHECK %s
 // RUN: %clang -O3 -target aarch64-linux-ohos %s -S -o- \
 // RUN:   | FileCheck --check-prefix=CHECK-YES --check-prefix=CHECK %s
-// RUN: %clang -O3 -target aarch64-android-eabi -mfix-cortex-a53-835769 %s -S 
-o- \
+// RUN: %clang -O3 --target=aarch64-linux-androideabi -mfix-cortex-a53-835769 
%s -S -o- \
 // RUN:   | FileCheck --check-prefix=CHECK-YES --check-prefix=CHECK %s
-// RUN: %clang -O3 -target aarch64-android-eabi -mno-fix-cortex-a53-835769 %s 
-S -o- \
+// RUN: %clang -O3 --target=aarch64-linux-androideabi 
-mno-fix-cortex-a53-835769 %s -S -o- \
 // RUN:   | FileCheck --check-prefix=CHECK-NO --check-prefix=CHECK %s
 
 // REQUIRES: aarch64-registered-target

diff  --git a/clang/test/Driver/aarch64-fix-cortex-a53-835769.c 
b/clang/test/Driver/aarch64-fix-cortex-a53-835769.c
index a854920f3e6ef3..d7a2ad9112611b 100644
--- a/clang/test/Driver/aarch64-fix-cortex-a53-835769.c
+++ b/clang/test/Driver/aarch64-fix-cortex-a53-835769.c
@@ -5,7 +5,7 @@
 // RUN: %clang --target=aarch64-linux-eabi -mno-fix-cortex-a53-835769 %s -### 
2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO %s
 
-// RUN: %clang --target=aarch64-android-eabi %s -### 2>&1 \
+// RUN: %clang --target=aarch64-linux-androideabi %s -### 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-YES %s
 
 // RUN: %clang --target=aarch64-fuchsia %s -### 2>&1 \

diff  --git a/clang/test/Driver/android-version.cpp 
b/clang/test/Driver/android-version.cpp
new file mode 100644
index 00..d365b701c0223b
--- /dev/null
+++ b/clang/test/Driver/android-version.cpp
@@ -0,0 +1,16 @@
+// Check that we get the right Android version.
+
+// RUN: not %clang --target=aarch64-linux-androidS -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-ERROR %s
+
+// CHECK-ERROR: error: version 'S' in target triple 
'aarch64-unknown-linux-androidS' is 

[clang] [clang-format] Fix crash involving array designators and dangling comma (PR #77045)

2024-01-08 Thread via cfe-commits


@@ -1444,16 +1444,26 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
   } else if (C.Tok->is(tok::comma)) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
-if (C.Tok->getNextNonComment()->isNot(tok::r_brace)) // dangling comma
+
+if (const auto *Next = C.Tok->getNextNonComment();
+Next && Next->isNot(tok::r_brace)) { // Dangling comma.
   ++Cell;
+}
   }
 } else if (Depth == 1) {
   if (C.Tok == MatchingParen) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
 Cells.push_back(CellDescription{i, ++Cell, i + 1, false, nullptr});
-CellCounts.push_back(C.Tok->Previous->isNot(tok::comma) ? Cell + 1
-: Cell);
+CellCounts.push_back(
+C.Tok->Previous->isNot(tok::comma) &&
+// When dealing with C array designators. There is a
+// possibility of some nested array not having an `=`.
+// When this happens we make the cells non rectangular,
+// avoiding an access out of bound later on.
+MatchingParen->MatchingParen->Previous->isNot(tok::equal)

XDeme wrote:

I've investigated a bit more, and I found that we were actually parsing
`[0] {};` as a lambda, instead of a designated initializer

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


[clang] [clang-format] Fix crash involving array designators and dangling comma (PR #77045)

2024-01-08 Thread via cfe-commits

https://github.com/XDeme updated https://github.com/llvm/llvm-project/pull/77045

>From d9cbbe48b96d27bff3fc926b60d039ed05f00489 Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Fri, 5 Jan 2024 01:23:16 -0300
Subject: [PATCH 1/5] [clang-format] Fix crash involving array designators and
 dangling comma Fixes llvm/llvm-project#76716 Added a check to prevent null
 deferencing

---
 clang/lib/Format/WhitespaceManager.cpp | 3 ++-
 clang/unittests/Format/FormatTest.cpp  | 6 ++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 3bc6915b8df0a7..95693f4588c631 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1444,7 +1444,8 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
   } else if (C.Tok->is(tok::comma)) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
-if (C.Tok->getNextNonComment()->isNot(tok::r_brace)) // dangling comma
+const FormatToken *Next = C.Tok->getNextNonComment();
+if (Next && Next->isNot(tok::r_brace)) // dangling comma
   ++Cell;
   }
 } else if (Depth == 1) {
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 881993ede17c3d..c9f91953c13f52 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -21084,6 +21084,12 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresLeftAlignment) {
   "};",
   Style);
 
+  verifyNoCrash("Foo f[] = {\n"
+"[0] = { 1, },\n"
+"[1] { 1, },\n"
+"};",
+Style);
+
   verifyFormat("return GradForUnaryCwise(g, {\n"
"{{\"sign\"}, \"Sign\", {\"x\", 
"
"\"dy\"}   },\n"

>From 78e006de352cb801f6c07ac7f6bd0ab881560406 Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Fri, 5 Jan 2024 11:32:37 -0300
Subject: [PATCH 2/5] Addresses comments

---
 clang/lib/Format/WhitespaceManager.cpp | 6 --
 clang/unittests/Format/FormatTest.cpp  | 6 ++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 95693f4588c631..aeac0ba0c6d03c 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1444,9 +1444,11 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
   } else if (C.Tok->is(tok::comma)) {
 if (!Cells.empty())
   Cells.back().EndIndex = i;
-const FormatToken *Next = C.Tok->getNextNonComment();
-if (Next && Next->isNot(tok::r_brace)) // dangling comma
+
+if (const auto *Next = C.Tok->getNextNonComment();
+Next && Next->isNot(tok::r_brace)) { // dangling comma
   ++Cell;
+}
   }
 } else if (Depth == 1) {
   if (C.Tok == MatchingParen) {
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index c9f91953c13f52..d6f561e822d08a 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -20842,6 +20842,12 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresRightAlignment) {
   "};",
   Style);
 
+  verifyNoCrash("Foo f[] = {\n"
+"[0] = { 1, },\n"
+"[1] { 1, },\n"
+"};",
+Style);
+
   verifyFormat("return GradForUnaryCwise(g, {\n"
"{{\"sign\"}, \"Sign\",  "
"  {\"x\", \"dy\"}},\n"

>From 3f82d6664de1ea06589393ff27aced4e4177a72c Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Fri, 5 Jan 2024 16:21:33 -0300
Subject: [PATCH 3/5] Fix real problem

---
 clang/lib/Format/WhitespaceManager.cpp |  7 +--
 clang/unittests/Format/FormatTest.cpp  | 10 ++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index aeac0ba0c6d03c..e91ec6afec74af 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1455,8 +1455,11 @@ WhitespaceManager::CellDescriptions 
WhitespaceManager::getCells(unsigned Start,
 if (!Cells.empty())
   Cells.back().EndIndex = i;
 Cells.push_back(CellDescription{i, ++Cell, i + 1, false, nullptr});
-CellCounts.push_back(C.Tok->Previous->isNot(tok::comma) ? Cell + 1
-: Cell);
+CellCounts.push_back(
+C.Tok->Previous->isNot(tok::comma) &&
+!MatchingParen->MatchingParen->Previous->is(tok::equal)
+? Cell + 1
+: Cell);
 // Go to the next non-comment and ensure there is a break in front
 const auto *NextNonComment = 

[clang] 49c35f6 - [CMake] Add support for building on illumos (#74930)

2024-01-08 Thread via cfe-commits

Author: Brad Smith
Date: 2024-01-08T23:28:04-05:00
New Revision: 49c35f69ac6884a07f07e7c09ca7b79282707f49

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

LOG: [CMake] Add support for building on illumos (#74930)

illumos has an older version of the Solaris linker that does not
support the GNU version script compat nor version scripts and does
not support -Bsymbolic-functions. Treat illumos linker separately.

The libclang/CMakeLists part lifted from NetBSD's pkgsrc.

Build tested on Solaris 11.4 and OpenIndiana 2023.10.

/usr/bin/ld --version

ld: Software Generation Utilities - Solaris Link Editors: 5.11-1.3260

ld: Software Generation Utilities - Solaris Link Editors: 5.11-1.1790 (illumos)

Added: 


Modified: 
clang/tools/clang-shlib/CMakeLists.txt
clang/tools/libclang/CMakeLists.txt
llvm/cmake/modules/AddLLVM.cmake
llvm/tools/llvm-shlib/CMakeLists.txt

Removed: 




diff  --git a/clang/tools/clang-shlib/CMakeLists.txt 
b/clang/tools/clang-shlib/CMakeLists.txt
index aa7fcd1efed45b..298d3a9d18fec8 100644
--- a/clang/tools/clang-shlib/CMakeLists.txt
+++ b/clang/tools/clang-shlib/CMakeLists.txt
@@ -50,7 +50,7 @@ add_clang_library(clang-cpp
   ${_DEPS})
 # Optimize function calls for default visibility definitions to avoid PLT and
 # reduce dynamic relocations.
-if (NOT APPLE AND NOT MINGW)
+if (NOT APPLE AND NOT MINGW AND NOT LLVM_LINKER_IS_SOLARISLD_ILLUMOS)
   target_link_options(clang-cpp PRIVATE LINKER:-Bsymbolic-functions)
 endif()
 if (MINGW OR CYGWIN)

diff  --git a/clang/tools/libclang/CMakeLists.txt 
b/clang/tools/libclang/CMakeLists.txt
index 4f23065a247274..1cfc46eb1a52f6 100644
--- a/clang/tools/libclang/CMakeLists.txt
+++ b/clang/tools/libclang/CMakeLists.txt
@@ -185,11 +185,22 @@ if(ENABLE_SHARED)
 endif()
   endif()
   if (USE_VERSION_SCRIPT)
-target_link_options(libclang PRIVATE 
"-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
-# The Solaris 11.4 linker supports a subset of GNU ld version scripts,
-# but requires a special option to enable it.
 if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
-  target_link_options(libclang PRIVATE "-Wl,-z,gnu-version-script-compat")
+  include(CheckLinkerFlag)
+  # The Solaris 11.4 linker supports a subset of GNU ld version scripts,
+  # but requires a special option to enable it.
+  llvm_check_linker_flag(CXX "-Wl,-z,gnu-version-script-compat"
+ LINKER_SUPPORTS_Z_GNU_VERSION_SCRIPT_COMPAT)
+  # Older Solaris (and illumos) linker does not support GNU ld version 
scripts
+  # and does not support GNU version script compat.
+  if (LINKER_SUPPORTS_Z_GNU_VERSION_SCRIPT_COMPAT)
+target_link_options(libclang PRIVATE 
"-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
+target_link_options(libclang PRIVATE 
"-Wl,-z,gnu-version-script-compat")
+  else()
+target_link_options(libclang PRIVATE 
"-Wl,-M,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
+  endif()
+else()
+  target_link_options(libclang PRIVATE 
"-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
 endif()
 # Ensure that libclang.so gets rebuilt when the linker script changes.
 set_property(SOURCE ARCMigrate.cpp APPEND PROPERTY

diff  --git a/llvm/cmake/modules/AddLLVM.cmake 
b/llvm/cmake/modules/AddLLVM.cmake
index c9bca30c8f33d1..14c0837c35964d 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -241,6 +241,12 @@ if (NOT DEFINED LLVM_LINKER_DETECTED AND NOT WIN32)
   set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
   set(LLVM_LINKER_IS_GNULD YES CACHE INTERNAL "")
   message(STATUS "Linker detection: GNU ld")
+elseif("${stderr}" MATCHES "(illumos)" OR
+   "${stdout}" MATCHES "(illumos)")
+  set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
+  set(LLVM_LINKER_IS_SOLARISLD YES CACHE INTERNAL "")
+  set(LLVM_LINKER_IS_SOLARISLD_ILLUMOS YES CACHE INTERNAL "")
+  message(STATUS "Linker detection: Solaris ld (illumos)")
 elseif("${stderr}" MATCHES "Solaris Link Editors" OR
"${stdout}" MATCHES "Solaris Link Editors")
   set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")

diff  --git a/llvm/tools/llvm-shlib/CMakeLists.txt 
b/llvm/tools/llvm-shlib/CMakeLists.txt
index 64d6f631ffadd5..a47a0ec84c625c 100644
--- a/llvm/tools/llvm-shlib/CMakeLists.txt
+++ b/llvm/tools/llvm-shlib/CMakeLists.txt
@@ -49,7 +49,7 @@ if(LLVM_BUILD_LLVM_DYLIB)
   # Solaris ld does not accept global: *; so there is no way to version 
*all* global symbols
   set(LIB_NAMES 
-Wl,--version-script,${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map
 ${LIB_NAMES})
 endif()
-if (NOT MINGW)
+if (NOT MINGW AND 

[llvm] [clang] [CMake] Add support for building on illumos (PR #74930)

2024-01-08 Thread Brad Smith via cfe-commits

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


[llvm] [clang] [CMake] Add support for building on illumos (PR #74930)

2024-01-08 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/74930

>From b63009251c8098b40b3a999ce7622c0dfd14f127 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Sat, 9 Dec 2023 01:43:09 -0500
Subject: [PATCH] [CMake] Add support for building on illumos

illumos has an older version of the Solaris linker that does not
support the GNU version script compat nor version scripts and does
not support -Bsymbolic-functions. Treat illumos linker separately.

The libclang/CMakeLists part lifted from NetBSD's pkgsrc.
---
 clang/tools/clang-shlib/CMakeLists.txt |  2 +-
 clang/tools/libclang/CMakeLists.txt| 19 +++
 llvm/cmake/modules/AddLLVM.cmake   |  6 ++
 llvm/tools/llvm-shlib/CMakeLists.txt   |  2 +-
 4 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/clang/tools/clang-shlib/CMakeLists.txt 
b/clang/tools/clang-shlib/CMakeLists.txt
index aa7fcd1efed45b..298d3a9d18fec8 100644
--- a/clang/tools/clang-shlib/CMakeLists.txt
+++ b/clang/tools/clang-shlib/CMakeLists.txt
@@ -50,7 +50,7 @@ add_clang_library(clang-cpp
   ${_DEPS})
 # Optimize function calls for default visibility definitions to avoid PLT and
 # reduce dynamic relocations.
-if (NOT APPLE AND NOT MINGW)
+if (NOT APPLE AND NOT MINGW AND NOT LLVM_LINKER_IS_SOLARISLD_ILLUMOS)
   target_link_options(clang-cpp PRIVATE LINKER:-Bsymbolic-functions)
 endif()
 if (MINGW OR CYGWIN)
diff --git a/clang/tools/libclang/CMakeLists.txt 
b/clang/tools/libclang/CMakeLists.txt
index 4f23065a247274..1cfc46eb1a52f6 100644
--- a/clang/tools/libclang/CMakeLists.txt
+++ b/clang/tools/libclang/CMakeLists.txt
@@ -185,11 +185,22 @@ if(ENABLE_SHARED)
 endif()
   endif()
   if (USE_VERSION_SCRIPT)
-target_link_options(libclang PRIVATE 
"-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
-# The Solaris 11.4 linker supports a subset of GNU ld version scripts,
-# but requires a special option to enable it.
 if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
-  target_link_options(libclang PRIVATE "-Wl,-z,gnu-version-script-compat")
+  include(CheckLinkerFlag)
+  # The Solaris 11.4 linker supports a subset of GNU ld version scripts,
+  # but requires a special option to enable it.
+  llvm_check_linker_flag(CXX "-Wl,-z,gnu-version-script-compat"
+ LINKER_SUPPORTS_Z_GNU_VERSION_SCRIPT_COMPAT)
+  # Older Solaris (and illumos) linker does not support GNU ld version 
scripts
+  # and does not support GNU version script compat.
+  if (LINKER_SUPPORTS_Z_GNU_VERSION_SCRIPT_COMPAT)
+target_link_options(libclang PRIVATE 
"-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
+target_link_options(libclang PRIVATE 
"-Wl,-z,gnu-version-script-compat")
+  else()
+target_link_options(libclang PRIVATE 
"-Wl,-M,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
+  endif()
+else()
+  target_link_options(libclang PRIVATE 
"-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
 endif()
 # Ensure that libclang.so gets rebuilt when the linker script changes.
 set_property(SOURCE ARCMigrate.cpp APPEND PROPERTY
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index c9bca30c8f33d1..14c0837c35964d 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -241,6 +241,12 @@ if (NOT DEFINED LLVM_LINKER_DETECTED AND NOT WIN32)
   set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
   set(LLVM_LINKER_IS_GNULD YES CACHE INTERNAL "")
   message(STATUS "Linker detection: GNU ld")
+elseif("${stderr}" MATCHES "(illumos)" OR
+   "${stdout}" MATCHES "(illumos)")
+  set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
+  set(LLVM_LINKER_IS_SOLARISLD YES CACHE INTERNAL "")
+  set(LLVM_LINKER_IS_SOLARISLD_ILLUMOS YES CACHE INTERNAL "")
+  message(STATUS "Linker detection: Solaris ld (illumos)")
 elseif("${stderr}" MATCHES "Solaris Link Editors" OR
"${stdout}" MATCHES "Solaris Link Editors")
   set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
diff --git a/llvm/tools/llvm-shlib/CMakeLists.txt 
b/llvm/tools/llvm-shlib/CMakeLists.txt
index 64d6f631ffadd5..a47a0ec84c625c 100644
--- a/llvm/tools/llvm-shlib/CMakeLists.txt
+++ b/llvm/tools/llvm-shlib/CMakeLists.txt
@@ -49,7 +49,7 @@ if(LLVM_BUILD_LLVM_DYLIB)
   # Solaris ld does not accept global: *; so there is no way to version 
*all* global symbols
   set(LIB_NAMES 
-Wl,--version-script,${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map
 ${LIB_NAMES})
 endif()
-if (NOT MINGW)
+if (NOT MINGW AND NOT LLVM_LINKER_IS_SOLARISLD_ILLUMOS)
   # Optimize function calls for default visibility definitions to avoid 
PLT and
   # reduce dynamic relocations.
   # Note: for -fno-pic default, the address of a function may be different 
from

___
cfe-commits mailing list

[clang-tools-extra] [flang] [libcxx] [lld] [compiler-rt] [lldb] [clang] [llvm] [libc] [openmp] [PGO][OpenMP] Instrumentation for GPU devices (PR #76587)

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


@@ -58,6 +60,22 @@ class GlobalTy {
   void setPtr(void *P) { Ptr = P; }
 };
 
+typedef void *IntPtrT;
+struct __llvm_profile_data {
+#define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) Type Name;
+#include "llvm/ProfileData/InstrProfData.inc"
+};
+
+/// PGO profiling data extracted from a GPU device
+struct GPUProfGlobals {
+  std::string names;
+  std::vector> counts;
+  std::vector<__llvm_profile_data> data;
+  Triple targetTriple;
+

jhuber6 wrote:

That's confusing, how would using a `std::vector` not have that problem as 
well? I'll need to look into that.

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


[llvm] [clang] [CMake] Add support for building on illumos (PR #74930)

2024-01-08 Thread Brad Smith via cfe-commits

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


[llvm] [clang] [llvm] Add support for building on illumos (PR #74930)

2024-01-08 Thread Brad Smith via cfe-commits

brad0 wrote:

> Are they aware of the issue and is there a tracking feature request/issue? It 
> seems that this patch adds code to hard code the implementation properties 
> which may become stale.

Searching via their bug tracker I can't find anything open or closed. But I 
have a hard time believing they are not aware of this.

We run into -Bsymbolic-functions on OpenBSD enough as it is with our BFD 2.17 
linker.

Not sure about how frequently we run into version scripts in the wild.

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


[clang] [llvm] [clang-tools-extra] [X86] Use plain load/store instead of cmpxchg16b for atomics with AVX (PR #74275)

2024-01-08 Thread James Y Knight via cfe-commits


@@ -30113,32 +30120,40 @@ TargetLoweringBase::AtomicExpansionKind
 X86TargetLowering::shouldExpandAtomicStoreInIR(StoreInst *SI) const {
   Type *MemType = SI->getValueOperand()->getType();
 
-  bool NoImplicitFloatOps =
-  SI->getFunction()->hasFnAttribute(Attribute::NoImplicitFloat);
-  if (MemType->getPrimitiveSizeInBits() == 64 && !Subtarget.is64Bit() &&
-  !Subtarget.useSoftFloat() && !NoImplicitFloatOps &&
-  (Subtarget.hasSSE1() || Subtarget.hasX87()))
-return AtomicExpansionKind::None;
+  if (!SI->getFunction()->hasFnAttribute(Attribute::NoImplicitFloat) &&
+  !Subtarget.useSoftFloat()) {
+if (MemType->getPrimitiveSizeInBits() == 64 && !Subtarget.is64Bit() &&
+(Subtarget.hasSSE1() || Subtarget.hasX87()))
+  return AtomicExpansionKind::None;
+
+if (MemType->getPrimitiveSizeInBits() == 128 && Subtarget.is64Bit() &&
+Subtarget.hasAVX())
+  return AtomicExpansionKind::None;
+  }
 
   return needsCmpXchgNb(MemType) ? AtomicExpansionKind::Expand
  : AtomicExpansionKind::None;
 }
 
 // Note: this turns large loads into lock cmpxchg8b/16b.
-// TODO: In 32-bit mode, use MOVLPS when SSE1 is available?
 TargetLowering::AtomicExpansionKind
 X86TargetLowering::shouldExpandAtomicLoadInIR(LoadInst *LI) const {
   Type *MemType = LI->getType();
 
-  // If this a 64 bit atomic load on a 32-bit target and SSE2 is enabled, we
-  // can use movq to do the load. If we have X87 we can load into an 80-bit
-  // X87 register and store it to a stack temporary.
-  bool NoImplicitFloatOps =
-  LI->getFunction()->hasFnAttribute(Attribute::NoImplicitFloat);
-  if (MemType->getPrimitiveSizeInBits() == 64 && !Subtarget.is64Bit() &&
-  !Subtarget.useSoftFloat() && !NoImplicitFloatOps &&
-  (Subtarget.hasSSE1() || Subtarget.hasX87()))
-return AtomicExpansionKind::None;
+  if (!LI->getFunction()->hasFnAttribute(Attribute::NoImplicitFloat) &&
+  !Subtarget.useSoftFloat()) {
+// If this a 64 bit atomic load on a 32-bit target and SSE2 is enabled, we
+// can use movq to do the load. If we have X87 we can load into an 80-bit
+// X87 register and store it to a stack temporary.
+if (MemType->getPrimitiveSizeInBits() == 64 && !Subtarget.is64Bit() &&

jyknight wrote:

Yikes, that's a nasty footgun -- obvious once you think about it, but I never 
would've looked out for that issue! The API of `getPrimitiveSizeInBits` is just 
_asking_ for mistakes like this. It ought to either assert when called on a 
non-primitive, or else return an optional, rather than simply returning 0 on 
failure.

But, looking through this code and the rest of the related atomics support on 
X86, I believe there is actually _not_ a correctness impact, because (not 
coincidentally!) atomics always work "normally" on pointer-sized values. That 
is, here, getPrimitiveSizeInBits() will return 0 rather than the 
perhaps-expected `is64Bit() ? 64 : 32`. Despite being unexpected, though, the 
logic still works out fine in that case.

So, given that this is a longstanding pre-existing issue -- which appears not 
to be a correctness issue -- I'd like to leave it alone in this patch.

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


[clang] [clang][coverage] fixing "if constexpr" and "if consteval" coverage report (PR #77214)

2024-01-08 Thread Jessica Paquette via cfe-commits


@@ -98,3 +104,49 @@ int main() {// CHECK: File 0, 
[[@LINE]]:12 -> {{[0-9]+}}:2 =
 void ternary() {
   true ? FOO : FOO; // CHECK-NOT: Gap,{{.*}}, [[@LINE]]:8 ->
 }
+
+// FIXME: Do not generate coverage for discarded branches in if consteval
+// GH-57377
+// CHECK-LABEL: _Z16check_constevalAi:
+constexpr int check_constevalA(int i) { // CHECK-NEXT: [[@LINE]]:39 -> 
{{[0-9]+}}:2 = #0

ornata wrote:

Maybe `check_if_consteval_with_discarded_branch` would be a better name?

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


[clang] [clang][coverage] fixing "if constexpr" and "if consteval" coverage report (PR #77214)

2024-01-08 Thread Jessica Paquette via cfe-commits


@@ -98,3 +104,49 @@ int main() {// CHECK: File 0, 
[[@LINE]]:12 -> {{[0-9]+}}:2 =
 void ternary() {
   true ? FOO : FOO; // CHECK-NOT: Gap,{{.*}}, [[@LINE]]:8 ->
 }
+
+// FIXME: Do not generate coverage for discarded branches in if consteval
+// GH-57377
+// CHECK-LABEL: _Z16check_constevalAi:
+constexpr int check_constevalA(int i) { // CHECK-NEXT: [[@LINE]]:39 -> 
{{[0-9]+}}:2 = #0
+  if consteval {
+i *= 3; // CHECK-NEXT: [[@LINE-1]]:16 -> 
[[@LINE+1]]:4 = #1
+  } else {  // CHECK-NEXT: Gap,File 0, [[@LINE]]:4 
-> [[@LINE]]:10 = #0
+i *= 5; // CHECK-NEXT: [[@LINE-1]]:10 -> 
[[@LINE+1]]:4 = #0
+  }
+  return i; // CHECK-NEXT: [[@LINE]]:3 -> 
[[@LINE]]:11 = (#0 + #1)
+}
+
+// CHECK-LABEL: _Z16check_constevalBi:
+constexpr int check_constevalB(int i) { // CHECK-NEXT: [[@LINE]]:39 -> 
{{[0-9]+}}:2 = #0
+  if !consteval {
+i *= 3; // CHECK-NEXT: [[@LINE-1]]:17 -> 
[[@LINE+1]]:4 = #0
+  } else {  // CHECK-NEXT: Gap,File 0, [[@LINE]]:4 
-> [[@LINE]]:10 = 0
+i *= 5; // CHECK-NEXT: [[@LINE-1]]:10 -> 
[[@LINE+1]]:4 = 0
+  }
+  return i;
+}
+
+// CHECK-LABEL: _Z16check_constevalCi:
+constexpr int check_constevalC(int i) { // CHECK-NEXT: [[@LINE]]:39 -> 
{{[0-9]+}}:2 = #0

ornata wrote:

Similarly, this test and the below one could just be called 
`check_if_consteval` and `check_if_not_consteval`

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


[clang] [clang][coverage] fixing "if constexpr" and "if consteval" coverage report (PR #77214)

2024-01-08 Thread Jessica Paquette via cfe-commits


@@ -23,19 +23,29 @@ void foo() {// CHECK-NEXT: Gap,File 0, 
[[@LINE+1]]:21 -> [[@
 }   // CHECK-NEXT: [[@LINE-2]]:9 -> [[@LINE-1]]:5 
= #1
 // CHECK-NEXT: [[@LINE-2]]:5 -> [[@LINE-2]]:8 
= #1
 
-// FIXME: Do not generate coverage for discarded branches in if consteval and 
if constexpr statements
-constexpr int check_consteval(int i) {
-if consteval {
-  i++;
-}
-if !consteval {
-  i++;
-}
-if consteval {
-return 42;
-} else {
-return i;
-}
+// FIXME: Do not generate coverage for discarded branches in if constexpr
+// CHECK-LABEL: _Z16check_constexprAi:
+int check_constexprA(int i) {   // CHECK-NEXT: [[@LINE]]:29 -> {{[0-9]+}}:2 = 
#0
+// CHECK-NEXT: [[@LINE+2]]:16 -> 
[[@LINE+2]]:20 = #0
+// CHECK-NEXT: Branch,File 0, [[@LINE+1]]:16 
-> [[@LINE+1]]:20 = 0, 0
+  if constexpr(true) {  // CHECK-NEXT: Gap,File 0, [[@LINE]]:21 -> 
[[@LINE]]:22 = #1
+i *= 3; // CHECK-NEXT: [[@LINE-1]]:22 -> [[@LINE+1]]:4 
= #1
+  } else {  // CHECK-NEXT: Gap,File 0, [[@LINE]]:4 -> 
[[@LINE]]:10 = (#0 - #1)
+i *= 5; // CHECK-NEXT: [[@LINE-1]]:10 -> [[@LINE+1]]:4 
= (#0 - #1)
+  }
+  return i;
+}
+
+// CHECK-LABEL: _Z16check_constexprBi:
+int check_constexprB(int i) {   // CHECK-NEXT: [[@LINE]]:29 -> {{[0-9]+}}:2 = 
#0

ornata wrote:

Similarly, this would be better-named something like `check_if_constexpr_false`

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


[clang] [clang][coverage] fixing "if constexpr" and "if consteval" coverage report (PR #77214)

2024-01-08 Thread Jessica Paquette via cfe-commits


@@ -98,3 +104,49 @@ int main() {// CHECK: File 0, 
[[@LINE]]:12 -> {{[0-9]+}}:2 =
 void ternary() {
   true ? FOO : FOO; // CHECK-NOT: Gap,{{.*}}, [[@LINE]]:8 ->
 }
+
+// FIXME: Do not generate coverage for discarded branches in if consteval
+// GH-57377
+// CHECK-LABEL: _Z16check_constevalAi:
+constexpr int check_constevalA(int i) { // CHECK-NEXT: [[@LINE]]:39 -> 
{{[0-9]+}}:2 = #0
+  if consteval {
+i *= 3; // CHECK-NEXT: [[@LINE-1]]:16 -> 
[[@LINE+1]]:4 = #1
+  } else {  // CHECK-NEXT: Gap,File 0, [[@LINE]]:4 
-> [[@LINE]]:10 = #0
+i *= 5; // CHECK-NEXT: [[@LINE-1]]:10 -> 
[[@LINE+1]]:4 = #0
+  }
+  return i; // CHECK-NEXT: [[@LINE]]:3 -> 
[[@LINE]]:11 = (#0 + #1)
+}
+
+// CHECK-LABEL: _Z16check_constevalBi:
+constexpr int check_constevalB(int i) { // CHECK-NEXT: [[@LINE]]:39 -> 
{{[0-9]+}}:2 = #0

ornata wrote:

Also does this one need a FIXME like in the above test?

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


[clang] [clang][coverage] fixing "if constexpr" and "if consteval" coverage report (PR #77214)

2024-01-08 Thread Jessica Paquette via cfe-commits


@@ -7741,6 +7745,10 @@ TreeTransform::TransformIfStmt(IfStmt *S) {
 Else = getDerived().TransformStmt(S->getElse());
 if (Else.isInvalid())
   return StmtError();
+  } else if (S->getElse() && ConstexprConditionValue &&

ornata wrote:

Could you add a comment similar to the one in the `else` above?

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


[clang] [clang][coverage] fixing "if constexpr" and "if consteval" coverage report (PR #77214)

2024-01-08 Thread Jessica Paquette via cfe-commits


@@ -23,19 +23,29 @@ void foo() {// CHECK-NEXT: Gap,File 0, 
[[@LINE+1]]:21 -> [[@
 }   // CHECK-NEXT: [[@LINE-2]]:9 -> [[@LINE-1]]:5 
= #1
 // CHECK-NEXT: [[@LINE-2]]:5 -> [[@LINE-2]]:8 
= #1
 
-// FIXME: Do not generate coverage for discarded branches in if consteval and 
if constexpr statements
-constexpr int check_consteval(int i) {
-if consteval {
-  i++;
-}
-if !consteval {
-  i++;
-}
-if consteval {
-return 42;
-} else {
-return i;
-}
+// FIXME: Do not generate coverage for discarded branches in if constexpr
+// CHECK-LABEL: _Z16check_constexprAi:
+int check_constexprA(int i) {   // CHECK-NEXT: [[@LINE]]:29 -> {{[0-9]+}}:2 = 
#0

ornata wrote:

I think this test should be named `check_if_constexpr_true` or something similar

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


[clang] [clang][coverage] fixing "if constexpr" and "if consteval" coverage report (PR #77214)

2024-01-08 Thread Jessica Paquette via cfe-commits


@@ -98,3 +104,49 @@ int main() {// CHECK: File 0, 
[[@LINE]]:12 -> {{[0-9]+}}:2 =
 void ternary() {
   true ? FOO : FOO; // CHECK-NOT: Gap,{{.*}}, [[@LINE]]:8 ->
 }
+
+// FIXME: Do not generate coverage for discarded branches in if consteval
+// GH-57377
+// CHECK-LABEL: _Z16check_constevalAi:
+constexpr int check_constevalA(int i) { // CHECK-NEXT: [[@LINE]]:39 -> 
{{[0-9]+}}:2 = #0
+  if consteval {
+i *= 3; // CHECK-NEXT: [[@LINE-1]]:16 -> 
[[@LINE+1]]:4 = #1
+  } else {  // CHECK-NEXT: Gap,File 0, [[@LINE]]:4 
-> [[@LINE]]:10 = #0
+i *= 5; // CHECK-NEXT: [[@LINE-1]]:10 -> 
[[@LINE+1]]:4 = #0

ornata wrote:

Specifically, it's the `else` region that shouldn't generate any coverage 
mapping data, right?

It'd be good to mention that in the `FIXME`; something like

> FIXME: Do not generate coverage for discarded branches in if consteval. The 
> else case is discarded and should not be covered.

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


[clang] [clang][coverage] fixing "if constexpr" and "if consteval" coverage report (PR #77214)

2024-01-08 Thread Jessica Paquette via cfe-commits

https://github.com/ornata commented:

Added some comments, mostly nits on the test.

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


[clang] [clang][coverage] fixing "if constexpr" and "if consteval" coverage report (PR #77214)

2024-01-08 Thread Jessica Paquette via cfe-commits


@@ -7732,7 +7732,11 @@ TreeTransform::TransformIfStmt(IfStmt *S) {
 if (Then.isInvalid())
   return StmtError();
   } else {
-Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc());
+// Discarded branch is replaced with empty CompoundStmt so we can keep
+// proper source location for start and end of original branch, so
+// subsequent transformations like CoverageMapping work properly

ornata wrote:

In the test, you mention that we're generating coverage for the discarded 
regions. Is the reason that we're generating a `CompoundStmt` here? Could this 
use a `FIXME`?

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


[clang] [clang][coverage] fixing "if constexpr" and "if consteval" coverage report (PR #77214)

2024-01-08 Thread Jessica Paquette via cfe-commits


@@ -98,3 +104,49 @@ int main() {// CHECK: File 0, 
[[@LINE]]:12 -> {{[0-9]+}}:2 =
 void ternary() {
   true ? FOO : FOO; // CHECK-NOT: Gap,{{.*}}, [[@LINE]]:8 ->
 }
+
+// FIXME: Do not generate coverage for discarded branches in if consteval
+// GH-57377
+// CHECK-LABEL: _Z16check_constevalAi:
+constexpr int check_constevalA(int i) { // CHECK-NEXT: [[@LINE]]:39 -> 
{{[0-9]+}}:2 = #0
+  if consteval {
+i *= 3; // CHECK-NEXT: [[@LINE-1]]:16 -> 
[[@LINE+1]]:4 = #1
+  } else {  // CHECK-NEXT: Gap,File 0, [[@LINE]]:4 
-> [[@LINE]]:10 = #0
+i *= 5; // CHECK-NEXT: [[@LINE-1]]:10 -> 
[[@LINE+1]]:4 = #0
+  }
+  return i; // CHECK-NEXT: [[@LINE]]:3 -> 
[[@LINE]]:11 = (#0 + #1)
+}
+
+// CHECK-LABEL: _Z16check_constevalBi:
+constexpr int check_constevalB(int i) { // CHECK-NEXT: [[@LINE]]:39 -> 
{{[0-9]+}}:2 = #0

ornata wrote:

Maybe `check_if_not_consteval_with_discarded_branch` would be a more 
descriptive name?

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


[clang] [clang][coverage] fixing "if constexpr" and "if consteval" coverage report (PR #77214)

2024-01-08 Thread Jessica Paquette via cfe-commits

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


[clang] [clang] pop explicitly to keep context stack balance (PR #77312)

2024-01-08 Thread Qizhi Hu via cfe-commits

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


[clang] [clang] pop explicit to keep context stack balance (PR #77312)

2024-01-08 Thread Qizhi Hu via cfe-commits

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

>From 1579c73d40a285caad1c51a74a1324d6476d633c Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Mon, 8 Jan 2024 22:15:09 +0800
Subject: [PATCH] [clang] pop explicit to keep context stack balance

---
 clang/lib/Parse/ParseDecl.cpp |  1 +
 .../cxx-static-member-init-no-crash.cpp   | 20 +++
 2 files changed, 21 insertions(+)
 create mode 100644 clang/test/Parser/cxx-static-member-init-no-crash.cpp

diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index b60ae293ef8c20..6b16320f86721b 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -2669,6 +2669,7 @@ Decl 
*Parser::ParseDeclarationAfterDeclaratorAndAttributes(
 /*Braced=*/false);
 CalledSignatureHelp = true;
   }
+  InitScope.pop();
   Actions.ActOnInitializerError(ThisDecl);
   SkipUntil(tok::r_paren, StopAtSemi);
 } else {
diff --git a/clang/test/Parser/cxx-static-member-init-no-crash.cpp 
b/clang/test/Parser/cxx-static-member-init-no-crash.cpp
new file mode 100644
index 00..a1956500c55c2d
--- /dev/null
+++ b/clang/test/Parser/cxx-static-member-init-no-crash.cpp
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+template  class EngineClassTypeInfo; // 
expected-note {{template is declared here}}
+template  struct _ConcreteClassBase {};
+
+struct _GLOBALSCOPE {};
+template  struct _SCOPE {};
+
+class Zone {
+private:
+  typedef _ConcreteClassBase _ClassBase;
+  static EngineClassTypeInfo _smTypeInfo;
+  static EngineExportScope &__engineExportScope(); // expected-error {{unknown 
type name 'EngineExportScope'}}
+};
+
+EngineClassTypeInfo
+Zone::_smTypeInfo("Zone", &_SCOPE<__DeclScope>()(), 0); /* expected-error 
{{use of undeclared identifier '__DeclScope'}} \
+  expected-error 
{{implicit instantiation of undefined template 'EngineClassTypeInfo>'}} */
+EngineExportScope ::__engineExportScope() { return Zone::_smTypeInfo; } 
// expected-error {{unknown type name 'EngineExportScope'}}

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


[clang] [clang] pop explicit to keep context stack balance (PR #77312)

2024-01-08 Thread Qizhi Hu via cfe-commits

jcsxky wrote:

> Can you explain why this change is needed, and provide a test case? (in 
> `clang/test/Parser`) Thanks

Test case has been added and update description.

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


[clang] [clang] pop explicit to keep context stack balance (PR #77312)

2024-01-08 Thread Qizhi Hu via cfe-commits

jcsxky wrote:

> Reference in new issue
> Edit
> Hide
> Delete
> Report conte

Test case has been added and update description.

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


[clang] [clang] pop explicit to keep context stack balance (PR #77312)

2024-01-08 Thread Qizhi Hu via cfe-commits

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


[clang-tools-extra] [libc] [libcxxabi] [mlir] [lldb] [libcxx] [llvm] [flang] [lld] [compiler-rt] [clang] [Mips] Fix unable to handle inline assembly ends with compat-branch o… (PR #77291)

2024-01-08 Thread via cfe-commits

https://github.com/yingopq updated 
https://github.com/llvm/llvm-project/pull/77291

>From 7689da7ccdfc9ce255339d8ee1e2ab3d41c9f3ee Mon Sep 17 00:00:00 2001
From: Ying Huang 
Date: Mon, 8 Jan 2024 17:50:15 +0800
Subject: [PATCH] [Mips] Fix unable to handle inline assembly ends with
 compat-branch on MIPS

Modify:
Add a global variable 'CurForbiddenSlotAttr' to save current
instruction`s forbidden slot and whether set reorder.
This is the judgment condition for whether to add nop.
We would add a couple of '.set noreorder' and '.set reorder' to wrap
the current instruction and the next instruction.
Then we can get previous instruction`s forbidden slot attribute and
whether set reorder by 'CurForbiddenSlotAttr'.
If previous instruction has forbidden slot and .set reorder is active
and current instruction is CTI. Then emit a NOP after it.

Fix https://github.com/llvm/llvm-project/issues/61045.

Because https://reviews.llvm.org/D158589 was 'Needs Review' state, not
ending, so we commit pull request again.
---
 lld/test/ELF/mips-pc-relocs.s | 18 +++--
 .../Target/Mips/AsmParser/MipsAsmParser.cpp   | 79 ++-
 .../CodeGen/Mips/llvm-ir/forbidden-slot-ir.ll | 46 +++
 llvm/test/MC/Mips/forbidden-slot.s| 16 
 llvm/test/MC/Mips/mips32r6/relocations.s  | 22 +++---
 llvm/test/MC/Mips/mips64r6/relocations.s  | 26 +++---
 llvm/test/MC/Mips/relocation.s|  4 +-
 7 files changed, 176 insertions(+), 35 deletions(-)
 create mode 100644 llvm/test/CodeGen/Mips/llvm-ir/forbidden-slot-ir.ll
 create mode 100644 llvm/test/MC/Mips/forbidden-slot.s

diff --git a/lld/test/ELF/mips-pc-relocs.s b/lld/test/ELF/mips-pc-relocs.s
index 5e7dbed94ca7c4..7d23f9d7469a48 100644
--- a/lld/test/ELF/mips-pc-relocs.s
+++ b/lld/test/ELF/mips-pc-relocs.s
@@ -40,11 +40,13 @@ __start:
 # ^-- (0x20020-0x2)>>2
 # CHECK-NEXT:20004:   beqc$5, $6, 0x20020
 # ^-- (0x20020-4-0x20004)>>2
-# CHECK-NEXT:20008:   beqzc   $9, 0x20020
-# ^-- (0x20020-4-0x20008)>>2
-# CHECK-NEXT:2000c:   bc  0x20020
-# ^-- (0x20020-4-0x2000c)>>2
-# CHECK-NEXT:20010:   aluipc  $2, 0
-# ^-- %hi(0x20020-0x20010)
-# CHECK-NEXT:20014:   addiu   $2, $2, 12
-# ^-- %lo(0x20020-0x20014)
+# CHECK-NEXT:20008:   nop
+# CHECK-NEXT:2000c:   beqzc   $9, 0x20020
+# ^-- (0x20020-4-0x2000c)>>2
+# CHECK-NEXT:20010:   nop
+# CHECK-NEXT:20014:   bc  0x20020
+# ^-- (0x20020-4-0x200014)>>2
+# CHECK-NEXT:20018:   aluipc  $2, 0
+# ^-- %hi(0x20020-0x20018)
+# CHECK-NEXT:2001c:   addiu   $2, $2, 4
+# ^-- %lo(0x20020-0x2001c)
diff --git a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp 
b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
index 3c673ae938fdec..9725c6f9f6183a 100644
--- a/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
+++ b/llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
@@ -150,6 +150,7 @@ class MipsAsmParser : public MCTargetAsmParser {
   bool IsLittleEndian;
   bool IsPicEnabled;
   bool IsCpRestoreSet;
+  bool CurForbiddenSlotAttr;
   int CpRestoreOffset;
   unsigned GPReg;
   unsigned CpSaveLocation;
@@ -552,6 +553,7 @@ class MipsAsmParser : public MCTargetAsmParser {
 
 CurrentFn = nullptr;
 
+CurForbiddenSlotAttr = false;
 IsPicEnabled = getContext().getObjectFileInfo()->isPositionIndependent();
 
 IsCpRestoreSet = false;
@@ -723,6 +725,16 @@ class MipsAsmParser : public MCTargetAsmParser {
 return getSTI().hasFeature(Mips::FeatureGINV);
   }
 
+  bool hasForbiddenSlot(const MCInstrDesc ) const {
+return !inMicroMipsMode() && (MCID.TSFlags & MipsII::HasForbiddenSlot);
+  }
+
+  bool SafeInForbiddenSlot(const MCInstrDesc ) const {
+return !(MCID.TSFlags & MipsII::IsCTI);
+  }
+
+  void onEndOfFile() override;
+
   /// Warn if RegIndex is the same as the current AT.
   void warnIfRegIndexIsAT(unsigned RegIndex, SMLoc Loc);
 
@@ -2307,7 +2319,42 @@ bool MipsAsmParser::processInstruction(MCInst , 
SMLoc IDLoc,
 
   bool FillDelaySlot =
   MCID.hasDelaySlot() && AssemblerOptions.back()->isReorder();
-  if (FillDelaySlot)
+
+  // Get previous instruction`s forbidden slot attribute and
+  // whether set reorder.
+  // This 'CurForbiddenSlotAttr' is a global variable.
+  bool PrevForbiddenSlotAttr = CurForbiddenSlotAttr;
+
+  // Flag represents we set reorder after nop.
+  bool SetReorderAfterNop = false;
+
+  // If previous instruction has forbidden slot and .set reorder
+  // is active and current instruction is CTI.
+  // Then emit a NOP after it.
+  if (PrevForbiddenSlotAttr && 

[clang] [clang] pop explicit to keep context stack balance (PR #77312)

2024-01-08 Thread Qizhi Hu via cfe-commits

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

>From f3671079bb27100dd77f9572a20445285c6850dd Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Mon, 8 Jan 2024 22:15:09 +0800
Subject: [PATCH] [clang] pop explicit to keep context stack balance

---
 clang/lib/Parse/ParseDecl.cpp |  1 +
 .../cxx-static-member-init-no-crash.cpp   | 19 +++
 2 files changed, 20 insertions(+)
 create mode 100644 clang/test/Parser/cxx-static-member-init-no-crash.cpp

diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index b60ae293ef8c20..6b16320f86721b 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -2669,6 +2669,7 @@ Decl 
*Parser::ParseDeclarationAfterDeclaratorAndAttributes(
 /*Braced=*/false);
 CalledSignatureHelp = true;
   }
+  InitScope.pop();
   Actions.ActOnInitializerError(ThisDecl);
   SkipUntil(tok::r_paren, StopAtSemi);
 } else {
diff --git a/clang/test/Parser/cxx-static-member-init-no-crash.cpp 
b/clang/test/Parser/cxx-static-member-init-no-crash.cpp
new file mode 100644
index 00..304f2ce7550e4b
--- /dev/null
+++ b/clang/test/Parser/cxx-static-member-init-no-crash.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+template  class EngineClassTypeInfo;
+template  struct _ConcreteClassBase {};
+
+struct _GLOBALSCOPE {};
+template  struct _SCOPE {};
+
+class Zone {
+private:
+  typedef _ConcreteClassBase _ClassBase;
+  static EngineClassTypeInfo _smTypeInfo;
+  static EngineExportScope &__engineExportScope();
+};
+
+EngineClassTypeInfo
+Zone::_smTypeInfo("Zone", &_SCOPE<__DeclScope>()(), 0);
+EngineExportScope ::__engineExportScope() { return Zone::_smTypeInfo; }

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


[clang-tools-extra] [clang] [llvm] [X86] Emit Warnings for frontend options to enable knl/knm specific ISAs. (PR #75580)

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


@@ -933,6 +933,14 @@ X86 Support
 - Support ISA of ``AVX10.1``.
 - ``-march=pantherlake`` and ``-march=clearwaterforest`` are now supported.
 - Added ABI handling for ``__float128`` to match with GCC.
+- Emit warnings for options to enable knl/knm specific ISAs: AVX512PF, AVX512ER
+  and PREFETCHWT1. From next version (LLVM 19), these ISAs' intrinsic supports
+  will be deprecated:
+  * intrinsic series of *_exp2a23_*
+  * intrinsic series of *_rsqrt28_*
+  * intrinsic series of *_rcp28_*
+  * intrinsic series of *_prefetch_i[3|6][2|4]gather_*
+  * intrinsic series of *_prefetch_i[3|6][2|4]scatter_*

phoebewang wrote:

Thanks @topperc ! You are correct, I forgot that.
KNL has a seperate feature called `prefetchwt1`, but the intrinsic/mnemonic is 
the same.

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


[clang] [llvm] [clang-tools-extra] [X86] Emit Warnings for frontend options to enable knl/knm specific ISAs. (PR #75580)

2024-01-08 Thread Craig Topper via cfe-commits


@@ -933,6 +933,14 @@ X86 Support
 - Support ISA of ``AVX10.1``.
 - ``-march=pantherlake`` and ``-march=clearwaterforest`` are now supported.
 - Added ABI handling for ``__float128`` to match with GCC.
+- Emit warnings for options to enable knl/knm specific ISAs: AVX512PF, AVX512ER
+  and PREFETCHWT1. From next version (LLVM 19), these ISAs' intrinsic supports
+  will be deprecated:
+  * intrinsic series of *_exp2a23_*
+  * intrinsic series of *_rsqrt28_*
+  * intrinsic series of *_rcp28_*
+  * intrinsic series of *_prefetch_i[3|6][2|4]gather_*
+  * intrinsic series of *_prefetch_i[3|6][2|4]scatter_*

topperc wrote:

That's not knl specific is it? Wasn't that part of 3dnow? The knl one is for 
prefetchwt1.

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


[compiler-rt] [libcxx] [mlir] [openmp] [lldb] [lld] [clang-tools-extra] [llvm] [clang] [flang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

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

MaxEW707 wrote:

> I would like some measurements so we can compare build times on Windows.

I took some benchmarks with `-ftime-trace` on the parse times with and without 
this change.
Pretty much all the big hitters, string/vector/map/algorithm, includes 
`` which includes `` which includes ``.
The test file used looked as follows to simulate some common stl includes.
```
#include 
#include 
#include 
```

clang-cl 16 frontend took ~190ms to parse those 3 headers. `intrin.h` took 
~32ms to parse.

clang-cl built with this PR frontend took ~1368ms to parse. `intrin.h` took 
~969ms to parse. Most of that time is from `` as expected. 
`intrin0.h` took ~2ms to parse.

It is known that `immintrin.h` and `x86intrin.h` being the everything header 
definitely makes it an **expensive** include.
I don't need to compile any project to know that include time difference will 
be felt by any code that uses STL.

MSVC STL ships with each compiler upgrade. VS has a separate dir for each 
installed msvc, `VC\Tools\MSVC\14.38.33130` for MSVC 1938, and each installed 
compiler has a specific version of msvc stl shipped with it under, 
`VC\Tools\MSVC\[version]\include`.
Only one version of clang-cl is shipped with VS at a time and it will always 
point to the latest `VCToolsDir` via the clang driver unless clang is passed an 
explicit dir on the command line by the user.
For example VS2022 17.7 upgraded from clang-cl 15 to clang-cl 16. From that 
point on-wards only clang-cl 16 exists on disk in your VS install.
That seems to correspond to what was said here, 
https://github.com/microsoft/STL/pull/4282#discussion_r1441191186, every 
shipped version of MSVC STL supports only the latest compilers provided by VS.

We have some options. I am fine with whatever the consensus is as long as I can 
move this over the finish line.
1. Users who upgrade clang-cl before MSVC STL officially supports the new 
version of clang-cl will suffer slower builds.
I would classify this as an unsupported config since once VS ships with 
support for the new clang-cl, intentionally building against an older 
`VCToolsDir` will also incur the include overhead. Up to you guys if view this 
as an unsupported config.
2. Add a config define that users can define to enable the old behaviour in the 
interim. Once MSVC STL supports the new version of clang-cl we can remove this 
config define in the next release.
3.  Release clang with `intrin0.h`. Get a change into MSVC STL. Wait for MSVC 
STL release. Release another clang with `intrin.h` changes. I am not well 
versed on what changes clang allows in patch or minor releases but this feels 
like it would have a long lag time before clang-cl can become usable for us.

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


[clang-tools-extra] [clang] [llvm] [X86] Emit Warnings for frontend options to enable knl/knm specific ISAs. (PR #75580)

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


@@ -933,6 +933,14 @@ X86 Support
 - Support ISA of ``AVX10.1``.
 - ``-march=pantherlake`` and ``-march=clearwaterforest`` are now supported.
 - Added ABI handling for ``__float128`` to match with GCC.
+- Emit warnings for options to enable knl/knm specific ISAs: AVX512PF, AVX512ER
+  and PREFETCHWT1. From next version (LLVM 19), these ISAs' intrinsic supports
+  will be deprecated:
+  * intrinsic series of *_exp2a23_*
+  * intrinsic series of *_rsqrt28_*
+  * intrinsic series of *_rcp28_*
+  * intrinsic series of *_prefetch_i[3|6][2|4]gather_*
+  * intrinsic series of *_prefetch_i[3|6][2|4]scatter_*

phoebewang wrote:

And `_m_prefetchw`

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


[compiler-rt] [openmp] [clang-tools-extra] [llvm] [clang] [flang] [OpenMP][libomptarget] Enable automatic unified shared memory executi… (PR #75999)

2024-01-08 Thread via cfe-commits

carlobertolli wrote:

As noted by a question during the review process, the test for zero-copy does 
not apply to dGPUs, including the gfx906 that runs the bbot. I will add an 
environment variable that allows users to turn on automatic zero-copy on any 
GPU, but that is not necessary if the system detected is an APU. That will make 
the test behave the same across different GPUs and enable users to test this 
even if they don't have any APU (some users are interested in this behavior for 
dGPUs).

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


[llvm] [clang] [clang-tools-extra] [X86] Emit Warnings for frontend options to enable knl/knm specific ISAs. (PR #75580)

2024-01-08 Thread Freddy Ye via cfe-commits

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


[clang] [coroutines][coro_lifetimebound] Detect lifetime issues with lambda captures (PR #77066)

2024-01-08 Thread Chuanqi Xu via cfe-commits


@@ -7575,15 +7577,27 @@ static void 
visitLifetimeBoundArguments(IndirectLocalPath , Expr *Call,
 Path.pop_back();
   };
 
-  if (ObjectArg && implicitObjectParamIsLifetimeBound(Callee))
-VisitLifetimeBoundArg(Callee, ObjectArg);
-
   bool CheckCoroCall = false;
   if (const auto *RD = Callee->getReturnType()->getAsRecordDecl()) {
 CheckCoroCall = RD->hasAttr() &&
 RD->hasAttr() &&
 !Callee->hasAttr();
   }
+
+  if (ObjectArg) {
+bool CheckCoroObjArg = CheckCoroCall;
+// Ignore `__promise.get_return_object()` as it is not lifetimebound.
+if (CheckCoroObjArg && Callee->getDeclName().isIdentifier() &&
+Callee->getName() == "get_return_object")
+  CheckCoroObjArg = false;
+// Coroutine lambda objects with empty capture list are not lifetimebound.
+if (auto *LE = dyn_cast(ObjectArg->IgnoreImplicit());
+LE && LE->captures().empty())
+  CheckCoroObjArg = false;

ChuanqiXu9 wrote:

> It may not result in runtime errors (even in sanitizers), because this is 
> never accessed, but I wonder if it is actually legal or UB in the standard?

I feel it is literally undefined. Since the spec doesn't say a lot about 
resumption/suspension about coroutines. Also the description of 
http://eel.is/c++draft/dcl.fct.def.coroutine#note-3 is vague too. It says it is 
`likely` to be an undefined behavior.

> Which makes me skew in the direction of warning for these cases two

I didn't get the logic here. Why it is not good to warn the undefined things?

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


[flang] [libcxxabi] [libc] [llvm] [clang-tools-extra] [clang] [lld] [lldb] [compiler-rt] [libunwind] [mlir] [libcxx] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)

2024-01-08 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/66963

>From 647f5fe641b30c874bab770fced9fcec9b601161 Mon Sep 17 00:00:00 2001
From: Zijun Zhao 
Date: Wed, 13 Sep 2023 14:26:01 -0700
Subject: [PATCH 1/9] [libc++] Implement ranges::contains_subrange

---
 libcxx/include/CMakeLists.txt |   1 +
 .../__algorithm/ranges_contains_subrange.h| 145 +
 libcxx/include/algorithm  |  14 +
 ...obust_against_copying_projections.pass.cpp |   2 +
 .../ranges.contains_subrange.pass.cpp | 293 ++
 .../niebloid.compile.pass.cpp |   1 +
 6 files changed, 456 insertions(+)
 create mode 100644 libcxx/include/__algorithm/ranges_contains_subrange.h
 create mode 100644 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 0fe3ab44d2466e..dd3ff541fbc7ba 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -110,6 +110,7 @@ set(files
   __algorithm/ranges_binary_search.h
   __algorithm/ranges_clamp.h
   __algorithm/ranges_contains.h
+  __algorithm/ranges_contains_subrange.h
   __algorithm/ranges_copy.h
   __algorithm/ranges_copy_backward.h
   __algorithm/ranges_copy_if.h
diff --git a/libcxx/include/__algorithm/ranges_contains_subrange.h 
b/libcxx/include/__algorithm/ranges_contains_subrange.h
new file mode 100644
index 00..16de6c29cb2a1a
--- /dev/null
+++ b/libcxx/include/__algorithm/ranges_contains_subrange.h
@@ -0,0 +1,145 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+
+#include <__algorithm/ranges_starts_with.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains_subrange {
+struct __fn {
+  template  _Sent1,
+input_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred,
+class _Proj1,
+class _Proj2,
+class _Offset>
+  static _LIBCPP_HIDE_FROM_ABI constexpr bool __contains_subrange_fn_impl(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred& __pred,
+  _Proj1& __proj1,
+  _Proj2& __proj2,
+  _Offset __offset) {
+if (__offset < 0)
+  return false;
+else {
+  for (; __offset >= 0; __offset--, __first1++) {
+auto result = ranges::starts_with(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+std::ref(__pred),
+std::ref(__proj1),
+std::ref(__proj2));
+if (result)
+  return true;
+  }
+  return false;
+}
+  }
+
+  template  _Sent1,
+input_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred  = ranges::equal_to,
+class _Proj1 = identity,
+class _Proj2 = identity>
+requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred __pred   = {},
+  _Proj1 __proj1 = {},
+  _Proj2 __proj2 = {}) const {
+auto __n1 = ranges::distance(__first1, __last1);
+auto __n2 = ranges::distance(__first2, __last2);
+auto __offset = __n1 - __n2;
+
+return __contains_subrange_fn_impl(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+__pred,
+__proj1,
+__proj2,
+std::move(__offset));
+  }
+
+  template 
+requires indirectly_comparable, iterator_t<_Range2>, 
_Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 
__proj1 = {}, _Proj2 __proj2 = {}) const {
+auto __n1 = 0;
+auto __n2 = 0;
+
+if 

[flang] [libcxxabi] [libc] [llvm] [clang-tools-extra] [clang] [lld] [lldb] [compiler-rt] [libunwind] [mlir] [libcxx] [libc++][ranges] Implement ranges::contains_subrange (PR #66963)

2024-01-08 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/66963

>From 647f5fe641b30c874bab770fced9fcec9b601161 Mon Sep 17 00:00:00 2001
From: Zijun Zhao 
Date: Wed, 13 Sep 2023 14:26:01 -0700
Subject: [PATCH 1/8] [libc++] Implement ranges::contains_subrange

---
 libcxx/include/CMakeLists.txt |   1 +
 .../__algorithm/ranges_contains_subrange.h| 145 +
 libcxx/include/algorithm  |  14 +
 ...obust_against_copying_projections.pass.cpp |   2 +
 .../ranges.contains_subrange.pass.cpp | 293 ++
 .../niebloid.compile.pass.cpp |   1 +
 6 files changed, 456 insertions(+)
 create mode 100644 libcxx/include/__algorithm/ranges_contains_subrange.h
 create mode 100644 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 0fe3ab44d2466e..dd3ff541fbc7ba 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -110,6 +110,7 @@ set(files
   __algorithm/ranges_binary_search.h
   __algorithm/ranges_clamp.h
   __algorithm/ranges_contains.h
+  __algorithm/ranges_contains_subrange.h
   __algorithm/ranges_copy.h
   __algorithm/ranges_copy_backward.h
   __algorithm/ranges_copy_if.h
diff --git a/libcxx/include/__algorithm/ranges_contains_subrange.h 
b/libcxx/include/__algorithm/ranges_contains_subrange.h
new file mode 100644
index 00..16de6c29cb2a1a
--- /dev/null
+++ b/libcxx/include/__algorithm/ranges_contains_subrange.h
@@ -0,0 +1,145 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+
+#include <__algorithm/ranges_starts_with.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains_subrange {
+struct __fn {
+  template  _Sent1,
+input_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred,
+class _Proj1,
+class _Proj2,
+class _Offset>
+  static _LIBCPP_HIDE_FROM_ABI constexpr bool __contains_subrange_fn_impl(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred& __pred,
+  _Proj1& __proj1,
+  _Proj2& __proj2,
+  _Offset __offset) {
+if (__offset < 0)
+  return false;
+else {
+  for (; __offset >= 0; __offset--, __first1++) {
+auto result = ranges::starts_with(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+std::ref(__pred),
+std::ref(__proj1),
+std::ref(__proj2));
+if (result)
+  return true;
+  }
+  return false;
+}
+  }
+
+  template  _Sent1,
+input_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred  = ranges::equal_to,
+class _Proj1 = identity,
+class _Proj2 = identity>
+requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred __pred   = {},
+  _Proj1 __proj1 = {},
+  _Proj2 __proj2 = {}) const {
+auto __n1 = ranges::distance(__first1, __last1);
+auto __n2 = ranges::distance(__first2, __last2);
+auto __offset = __n1 - __n2;
+
+return __contains_subrange_fn_impl(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+__pred,
+__proj1,
+__proj2,
+std::move(__offset));
+  }
+
+  template 
+requires indirectly_comparable, iterator_t<_Range2>, 
_Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 
__proj1 = {}, _Proj2 __proj2 = {}) const {
+auto __n1 = 0;
+auto __n2 = 0;
+
+if 

[flang] [libc] [llvm] [clang] [lld] [lldb] [compiler-rt] [clang-tools-extra] [libcxx] [openmp] [PGO][OpenMP] Instrumentation for GPU devices (PR #76587)

2024-01-08 Thread Ethan Luis McDonough via cfe-commits


@@ -58,6 +60,22 @@ class GlobalTy {
   void setPtr(void *P) { Ptr = P; }
 };
 
+typedef void *IntPtrT;
+struct __llvm_profile_data {
+#define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) Type Name;
+#include "llvm/ProfileData/InstrProfData.inc"
+};
+
+/// PGO profiling data extracted from a GPU device
+struct GPUProfGlobals {
+  std::string names;
+  std::vector> counts;
+  std::vector<__llvm_profile_data> data;
+  Triple targetTriple;
+

EthanLuisMcDonough wrote:

I can't seem to use `SmallVector` for `__llvm_profile_data` because many of its 
defined fields are const qualified and it needs an assignment operator 
definition. I'm able to use `std::remove_const`, but that feels kind of hack-y. 
Not sure if the best solution is to use `std::vector`, `std::remove_const`, or 
remove the const qualifiers in 
[InstrProfData.inc](https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/ProfileData/InstrProfData.inc).

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


[flang] [libcxxabi] [llvm] [clang-tools-extra] [clang] [lld] [libcxx] [polly] [lldb] [compiler-rt] [libunwind] [mlir] [libc] [openmp] Make clang report invalid target versions. (PR #75373)

2024-01-08 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/75373

>From 74f256d8a77ee2ba8e0d5bbb6519aa2729cf94d5 Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Wed, 13 Dec 2023 20:07:45 +
Subject: [PATCH 01/16] Make clang report garbage target versions.

Clang always silently ignores garbage target versions and this makes
debug harder. So clang will report when target versions are invalid.
---
 llvm/lib/TargetParser/Triple.cpp | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index c5e9ad43d22588..335253194d1cf8 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -11,6 +11,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/SwapByteOrder.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/ARMTargetParser.h"
@@ -1199,7 +1200,11 @@ StringRef Triple::getOSAndEnvironmentName() const {
 
 static VersionTuple parseVersionFromName(StringRef Name) {
   VersionTuple Version;
-  Version.tryParse(Name);
+  if (Version.tryParse(Name)) {
+errs() << "The input is "<< Name << " and it is invalid. Should pass an "<<
+"integer or integer combination! e.g. 2, 9.5 or 3.4.5\n";
+exit(1);
+  }
   return Version.withoutBuild();
 }
 

>From 0d159b2a9b76e233e020ac0aef15b49b03f4d86c Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Wed, 13 Dec 2023 20:23:54 +
Subject: [PATCH 02/16] rephrase

---
 llvm/lib/TargetParser/Triple.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 335253194d1cf8..713ca447403d50 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -1201,8 +1201,7 @@ StringRef Triple::getOSAndEnvironmentName() const {
 static VersionTuple parseVersionFromName(StringRef Name) {
   VersionTuple Version;
   if (Version.tryParse(Name)) {
-errs() << "The input is "<< Name << " and it is invalid. Should pass an "<<
-"integer or integer combination! e.g. 2, 9.5 or 3.4.5\n";
+errs() << "version "<< Name << " is invalid\n";
 exit(1);
   }
   return Version.withoutBuild();

>From b2dda9ce95804783c59aa1ca4e81a7941aae805d Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Wed, 13 Dec 2023 20:07:45 +
Subject: [PATCH 03/16] Make clang report garbage target versions.

Clang always silently ignores garbage target versions and this makes
debug harder. So clang will report when target versions are invalid.
---
 clang/lib/Basic/Targets/OSTargets.h | 5 +
 llvm/include/llvm/TargetParser/Triple.h | 4 
 llvm/lib/TargetParser/Triple.cpp| 8 
 3 files changed, 17 insertions(+)

diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 342af4bbc42b7b..bc28066019971c 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -323,6 +323,11 @@ class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo : public 
OSTargetInfo {
 // This historical but ambiguous name for the minSdkVersion macro. Keep
 // defined for compatibility.
 Builder.defineMacro("__ANDROID_API__", "__ANDROID_MIN_SDK_VERSION__");
+  } else {
+llvm::errs() << "version "<< Triple.getVersionName() <<
+" in triple " << Triple.getArchName() << "-" << Triple.getVendorName()
+<< "-" << Triple.getOSAndEnvironmentName() << " is invalid\n";
+exit(1);
   }
 } else {
 Builder.defineMacro("__gnu_linux__");
diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index 47904621c0967f..05df1c489ad06e 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -434,6 +434,10 @@ class Triple {
   /// string (separated by a '-' if the environment component is present).
   StringRef getOSAndEnvironmentName() const;
 
+  /// Get the version component of the environment component as a single
+  /// string (the version after the environment).
+  StringRef getVersionName() const;
+
   /// @}
   /// @name Convenience Predicates
   /// @{
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 49bc24ffbfae6c..db4ba7100781bc 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -1199,6 +1199,14 @@ StringRef Triple::getOSAndEnvironmentName() const {
   return Tmp.split('-').second;  // Strip second component
 }
 
+StringRef Triple::getVersionName() const {
+  StringRef VersionName = getEnvironmentName();
+  StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment());
+  if (VersionName.startswith(EnvironmentTypeName))
+return VersionName.substr(EnvironmentTypeName.size());
+  return VersionName;
+}
+
 static 

[llvm] [clang] [clang-tools-extra] [X86] Emit Warnings for frontend options to enable knl/knm specific ISAs. (PR #75580)

2024-01-08 Thread Freddy Ye via cfe-commits

https://github.com/FreddyLeaf updated 
https://github.com/llvm/llvm-project/pull/75580

>From e16afbdc9f0c04bad0e8f80f90c0eb26c13d3326 Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Fri, 15 Dec 2023 16:50:23 +0800
Subject: [PATCH 1/9] [X86] Emit Warnings for frontend options to enable
 knl/knm.

Since Knight Landing and Knight Mill microarchitectures are EOL, we
would like to remove its support in LLVM 19. In LLVM 18, we will first
emit a warning for the usage.
---
 clang/include/clang/Basic/DiagnosticCommonKinds.td |  2 ++
 clang/lib/Basic/Targets/X86.cpp|  3 +++
 clang/test/CodeGen/X86/avx512er-builtins.c |  2 +-
 clang/test/CodeGen/X86/avx512pf-builtins.c |  2 +-
 clang/test/Driver/cl-x86-flags.c   | 10 --
 clang/test/Frontend/x86-target-cpu.c   | 10 --
 clang/test/Misc/warning-flags.c|  3 ++-
 7 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index 65a33f61a6948a..40841e9df547bc 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -349,6 +349,8 @@ def warn_invalid_feature_combination : Warning<
 def warn_target_unrecognized_env : Warning<
   "mismatch between architecture and environment in target triple '%0'; did 
you mean '%1'?">,
   InGroup;
+def warn_knl_knm_target_supports_remove : Warning<
+  "KNL/KNM's feature support will be removed in LLVM 19.">;
 
 // Source manager
 def err_cannot_open_file : Error<"cannot open file '%0': %1">, DefaultFatal;
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index b97f88647fa49f..dc56524d378104 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -295,11 +295,13 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasAVX512BF16 = true;
 } else if (Feature == "+avx512er") {
   HasAVX512ER = true;
+  Diags.Report(diag::warn_knl_knm_target_supports_remove);
 } else if (Feature == "+avx512fp16") {
   HasAVX512FP16 = true;
   HasLegalHalfType = true;
 } else if (Feature == "+avx512pf") {
   HasAVX512PF = true;
+  Diags.Report(diag::warn_knl_knm_target_supports_remove);
 } else if (Feature == "+avx512dq") {
   HasAVX512DQ = true;
 } else if (Feature == "+avx512bitalg") {
@@ -358,6 +360,7 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasPREFETCHI = true;
 } else if (Feature == "+prefetchwt1") {
   HasPREFETCHWT1 = true;
+  Diags.Report(diag::warn_knl_knm_target_supports_remove);
 } else if (Feature == "+clzero") {
   HasCLZERO = true;
 } else if (Feature == "+cldemote") {
diff --git a/clang/test/CodeGen/X86/avx512er-builtins.c 
b/clang/test/CodeGen/X86/avx512er-builtins.c
index ee31236a3c01aa..11ec6aabec1e3f 100644
--- a/clang/test/CodeGen/X86/avx512er-builtins.c
+++ b/clang/test/CodeGen/X86/avx512er-builtins.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512f -target-feature +avx512er 
-emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512f -target-feature +avx512er 
-emit-llvm -o - -Wall | FileCheck %s
 
 
 #include 
diff --git a/clang/test/CodeGen/X86/avx512pf-builtins.c 
b/clang/test/CodeGen/X86/avx512pf-builtins.c
index 4ca70f5787968b..3a117ed6a9460e 100644
--- a/clang/test/CodeGen/X86/avx512pf-builtins.c
+++ b/clang/test/CodeGen/X86/avx512pf-builtins.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512pf -emit-llvm -o - -Wall 
-Werror | FileCheck %s
+// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512pf -emit-llvm -o - -Wall | 
FileCheck %s
 
 
 #include 
diff --git a/clang/test/Driver/cl-x86-flags.c b/clang/test/Driver/cl-x86-flags.c
index 51b16f0ce35463..ae35a312fe8a4b 100644
--- a/clang/test/Driver/cl-x86-flags.c
+++ b/clang/test/Driver/cl-x86-flags.c
@@ -69,7 +69,10 @@
 // RUN: %clang_cl -m32 -arch:avx2 --target=i386-pc-windows -### -- 2>&1 %s | 
FileCheck -check-prefix=avx2 %s
 // avx2: invalid /arch: argument
 
-// RUN: %clang_cl -m32 -arch:AVX512F --target=i386-pc-windows /c /Fo%t.obj 
-Xclang -verify -DTEST_32_ARCH_AVX512F -- %s
+// RUN: %clang_cl -m32 -arch:AVX512F --target=i386-pc-windows /c /Fo%t.obj 
-Xclang -verify=KNL1 -DTEST_32_ARCH_AVX512F -- %s
+// KNL1-warning@*:* {{KNL/KNM's feature support will be removed in LLVM 19.}}
+// KNL1-warning@*:* {{KNL/KNM's feature support will be removed in LLVM 19.}}
+// KNL1-warning@*:* {{KNL/KNM's feature support will be removed in LLVM 19.}}
 #if defined(TEST_32_ARCH_AVX512F)
 #if _M_IX86_FP != 2 || !__AVX__ || 

[polly] [libunwind] [flang] [compiler-rt] [clang] [libc] [mlir] [libcxx] [libcxxabi] [openmp] [lld] [llvm] [lldb] [clang-tools-extra] Make clang report invalid target versions. (PR #75373)

2024-01-08 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/75373

>From 74f256d8a77ee2ba8e0d5bbb6519aa2729cf94d5 Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Wed, 13 Dec 2023 20:07:45 +
Subject: [PATCH 01/15] Make clang report garbage target versions.

Clang always silently ignores garbage target versions and this makes
debug harder. So clang will report when target versions are invalid.
---
 llvm/lib/TargetParser/Triple.cpp | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index c5e9ad43d22588..335253194d1cf8 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -11,6 +11,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/SwapByteOrder.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/ARMTargetParser.h"
@@ -1199,7 +1200,11 @@ StringRef Triple::getOSAndEnvironmentName() const {
 
 static VersionTuple parseVersionFromName(StringRef Name) {
   VersionTuple Version;
-  Version.tryParse(Name);
+  if (Version.tryParse(Name)) {
+errs() << "The input is "<< Name << " and it is invalid. Should pass an "<<
+"integer or integer combination! e.g. 2, 9.5 or 3.4.5\n";
+exit(1);
+  }
   return Version.withoutBuild();
 }
 

>From 0d159b2a9b76e233e020ac0aef15b49b03f4d86c Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Wed, 13 Dec 2023 20:23:54 +
Subject: [PATCH 02/15] rephrase

---
 llvm/lib/TargetParser/Triple.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 335253194d1cf8..713ca447403d50 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -1201,8 +1201,7 @@ StringRef Triple::getOSAndEnvironmentName() const {
 static VersionTuple parseVersionFromName(StringRef Name) {
   VersionTuple Version;
   if (Version.tryParse(Name)) {
-errs() << "The input is "<< Name << " and it is invalid. Should pass an "<<
-"integer or integer combination! e.g. 2, 9.5 or 3.4.5\n";
+errs() << "version "<< Name << " is invalid\n";
 exit(1);
   }
   return Version.withoutBuild();

>From b2dda9ce95804783c59aa1ca4e81a7941aae805d Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Wed, 13 Dec 2023 20:07:45 +
Subject: [PATCH 03/15] Make clang report garbage target versions.

Clang always silently ignores garbage target versions and this makes
debug harder. So clang will report when target versions are invalid.
---
 clang/lib/Basic/Targets/OSTargets.h | 5 +
 llvm/include/llvm/TargetParser/Triple.h | 4 
 llvm/lib/TargetParser/Triple.cpp| 8 
 3 files changed, 17 insertions(+)

diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 342af4bbc42b7b..bc28066019971c 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -323,6 +323,11 @@ class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo : public 
OSTargetInfo {
 // This historical but ambiguous name for the minSdkVersion macro. Keep
 // defined for compatibility.
 Builder.defineMacro("__ANDROID_API__", "__ANDROID_MIN_SDK_VERSION__");
+  } else {
+llvm::errs() << "version "<< Triple.getVersionName() <<
+" in triple " << Triple.getArchName() << "-" << Triple.getVendorName()
+<< "-" << Triple.getOSAndEnvironmentName() << " is invalid\n";
+exit(1);
   }
 } else {
 Builder.defineMacro("__gnu_linux__");
diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index 47904621c0967f..05df1c489ad06e 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -434,6 +434,10 @@ class Triple {
   /// string (separated by a '-' if the environment component is present).
   StringRef getOSAndEnvironmentName() const;
 
+  /// Get the version component of the environment component as a single
+  /// string (the version after the environment).
+  StringRef getVersionName() const;
+
   /// @}
   /// @name Convenience Predicates
   /// @{
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 49bc24ffbfae6c..db4ba7100781bc 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -1199,6 +1199,14 @@ StringRef Triple::getOSAndEnvironmentName() const {
   return Tmp.split('-').second;  // Strip second component
 }
 
+StringRef Triple::getVersionName() const {
+  StringRef VersionName = getEnvironmentName();
+  StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment());
+  if (VersionName.startswith(EnvironmentTypeName))
+return VersionName.substr(EnvironmentTypeName.size());
+  return VersionName;
+}
+
 static 

[llvm] [clang] [clang-tools-extra] [X86] Emit Warnings for frontend options to enable knl/knm specific ISAs. (PR #75580)

2024-01-08 Thread Freddy Ye via cfe-commits


@@ -69,7 +69,10 @@
 // RUN: %clang_cl -m32 -arch:avx2 --target=i386-pc-windows -### -- 2>&1 %s | 
FileCheck -check-prefix=avx2 %s
 // avx2: invalid /arch: argument
 
-// RUN: %clang_cl -m32 -arch:AVX512F --target=i386-pc-windows /c /Fo%t.obj 
-Xclang -verify -DTEST_32_ARCH_AVX512F -- %s
+// RUN: %clang_cl -m32 -arch:AVX512F --target=i386-pc-windows /c /Fo%t.obj 
-Xclang -verify=KNL1 -DTEST_32_ARCH_AVX512F -- %s

FreddyLeaf wrote:

https://github.com/llvm/llvm-project/blob/87d15d7ad6141d7492e9579928839408d60e8152/clang/lib/Driver/ToolChains/Arch/X86.cpp#L45

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


[llvm] [clang] [clang-tools-extra] [X86] Emit Warnings for frontend options to enable knl/knm specific ISAs. (PR #75580)

2024-01-08 Thread Freddy Ye via cfe-commits


@@ -933,6 +933,9 @@ X86 Support
 - Support ISA of ``AVX10.1``.
 - ``-march=pantherlake`` and ``-march=clearwaterforest`` are now supported.
 - Added ABI handling for ``__float128`` to match with GCC.
+- Emit Warnings for clang options to enable knl/knm. From next version
+  (LLVM 19), all-end supports on knl/knm and other Xeon Phi targets will be
+  removed.

FreddyLeaf wrote:

addressed fef605e95d2ec8f5a3c2a339e014cb700d5b8a27

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


[llvm] [clang] [clang-tools-extra] [X86] Emit Warnings for frontend options to enable knl/knm specific ISAs. (PR #75580)

2024-01-08 Thread Freddy Ye via cfe-commits

https://github.com/FreddyLeaf updated 
https://github.com/llvm/llvm-project/pull/75580

>From e16afbdc9f0c04bad0e8f80f90c0eb26c13d3326 Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Fri, 15 Dec 2023 16:50:23 +0800
Subject: [PATCH 1/8] [X86] Emit Warnings for frontend options to enable
 knl/knm.

Since Knight Landing and Knight Mill microarchitectures are EOL, we
would like to remove its support in LLVM 19. In LLVM 18, we will first
emit a warning for the usage.
---
 clang/include/clang/Basic/DiagnosticCommonKinds.td |  2 ++
 clang/lib/Basic/Targets/X86.cpp|  3 +++
 clang/test/CodeGen/X86/avx512er-builtins.c |  2 +-
 clang/test/CodeGen/X86/avx512pf-builtins.c |  2 +-
 clang/test/Driver/cl-x86-flags.c   | 10 --
 clang/test/Frontend/x86-target-cpu.c   | 10 --
 clang/test/Misc/warning-flags.c|  3 ++-
 7 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index 65a33f61a6948a..40841e9df547bc 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -349,6 +349,8 @@ def warn_invalid_feature_combination : Warning<
 def warn_target_unrecognized_env : Warning<
   "mismatch between architecture and environment in target triple '%0'; did 
you mean '%1'?">,
   InGroup;
+def warn_knl_knm_target_supports_remove : Warning<
+  "KNL/KNM's feature support will be removed in LLVM 19.">;
 
 // Source manager
 def err_cannot_open_file : Error<"cannot open file '%0': %1">, DefaultFatal;
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index b97f88647fa49f..dc56524d378104 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -295,11 +295,13 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasAVX512BF16 = true;
 } else if (Feature == "+avx512er") {
   HasAVX512ER = true;
+  Diags.Report(diag::warn_knl_knm_target_supports_remove);
 } else if (Feature == "+avx512fp16") {
   HasAVX512FP16 = true;
   HasLegalHalfType = true;
 } else if (Feature == "+avx512pf") {
   HasAVX512PF = true;
+  Diags.Report(diag::warn_knl_knm_target_supports_remove);
 } else if (Feature == "+avx512dq") {
   HasAVX512DQ = true;
 } else if (Feature == "+avx512bitalg") {
@@ -358,6 +360,7 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector ,
   HasPREFETCHI = true;
 } else if (Feature == "+prefetchwt1") {
   HasPREFETCHWT1 = true;
+  Diags.Report(diag::warn_knl_knm_target_supports_remove);
 } else if (Feature == "+clzero") {
   HasCLZERO = true;
 } else if (Feature == "+cldemote") {
diff --git a/clang/test/CodeGen/X86/avx512er-builtins.c 
b/clang/test/CodeGen/X86/avx512er-builtins.c
index ee31236a3c01aa..11ec6aabec1e3f 100644
--- a/clang/test/CodeGen/X86/avx512er-builtins.c
+++ b/clang/test/CodeGen/X86/avx512er-builtins.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512f -target-feature +avx512er 
-emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512f -target-feature +avx512er 
-emit-llvm -o - -Wall | FileCheck %s
 
 
 #include 
diff --git a/clang/test/CodeGen/X86/avx512pf-builtins.c 
b/clang/test/CodeGen/X86/avx512pf-builtins.c
index 4ca70f5787968b..3a117ed6a9460e 100644
--- a/clang/test/CodeGen/X86/avx512pf-builtins.c
+++ b/clang/test/CodeGen/X86/avx512pf-builtins.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512pf -emit-llvm -o - -Wall 
-Werror | FileCheck %s
+// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512pf -emit-llvm -o - -Wall | 
FileCheck %s
 
 
 #include 
diff --git a/clang/test/Driver/cl-x86-flags.c b/clang/test/Driver/cl-x86-flags.c
index 51b16f0ce35463..ae35a312fe8a4b 100644
--- a/clang/test/Driver/cl-x86-flags.c
+++ b/clang/test/Driver/cl-x86-flags.c
@@ -69,7 +69,10 @@
 // RUN: %clang_cl -m32 -arch:avx2 --target=i386-pc-windows -### -- 2>&1 %s | 
FileCheck -check-prefix=avx2 %s
 // avx2: invalid /arch: argument
 
-// RUN: %clang_cl -m32 -arch:AVX512F --target=i386-pc-windows /c /Fo%t.obj 
-Xclang -verify -DTEST_32_ARCH_AVX512F -- %s
+// RUN: %clang_cl -m32 -arch:AVX512F --target=i386-pc-windows /c /Fo%t.obj 
-Xclang -verify=KNL1 -DTEST_32_ARCH_AVX512F -- %s
+// KNL1-warning@*:* {{KNL/KNM's feature support will be removed in LLVM 19.}}
+// KNL1-warning@*:* {{KNL/KNM's feature support will be removed in LLVM 19.}}
+// KNL1-warning@*:* {{KNL/KNM's feature support will be removed in LLVM 19.}}
 #if defined(TEST_32_ARCH_AVX512F)
 #if _M_IX86_FP != 2 || !__AVX__ || 

[llvm] [clang] [RISCV] Deduplicate RISCVISAInfo::toFeatures/toFeatureVector. NFC (PR #76942)

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


@@ -466,35 +466,35 @@ bool RISCVISAInfo::compareExtension(const std::string 
,
   return LHS < RHS;
 }
 
-void RISCVISAInfo::toFeatures(
-std::vector ,
-llvm::function_ref StrAlloc,
-bool AddAllExtensions) const {
-  for (auto const  : Exts) {
-StringRef ExtName = Ext.first;
-
-if (ExtName == "i")
+std::vector RISCVISAInfo::toFeatures(bool AddAllExtensions,
+  bool IgnoreUnknown) const {
+  std::vector Features;
+  for (const auto &[ExtName, _] : Exts) {
+if (ExtName == "i") // i is not recognized in clang -cc1

compnerd wrote:

Yeah, sometimes changes do require looking at other architectures.

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


[clang] Improve modeling of 'getcwd' in the StdLibraryFunctionsChecker (PR #77040)

2024-01-08 Thread Ben Shi via cfe-commits

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


[clang] 7dd2063 - Improve modeling of 'getcwd' in the StdLibraryFunctionsChecker (#77040)

2024-01-08 Thread via cfe-commits

Author: Ben Shi
Date: 2024-01-09T09:27:57+08:00
New Revision: 7dd20637c801b429f2dd1040941d00141459d64e

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

LOG: Improve modeling of 'getcwd' in the StdLibraryFunctionsChecker (#77040)

1. Improve the 'errno' modeling.
2. Improve constraints of the arguments.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
clang/test/Analysis/errno-stdlibraryfunctions.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c9b577bd549b1e..803eb2f7c74cf6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1150,9 +1150,10 @@ Improvements
 
 
 - Improved the ``unix.StdCLibraryFunctions`` checker by modeling more
-  functions like ``send``, ``recv``, ``readlink``, ``fflush``, ``mkdtemp`` and
-  ``errno`` behavior.
+  functions like ``send``, ``recv``, ``readlink``, ``fflush``, ``mkdtemp``,
+  ``getcwd`` and ``errno`` behavior.
   (`52ac71f92d38 
`_,
+  `#77040 `_,
   `#76671 `_,
   `#71373 `_,
   `#76557 `_,

diff  --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 20068653d530a3..034825d88a44de 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2516,10 +2516,21 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 .ArgConstraint(NotNull(ArgNo(0;
 
 // char *getcwd(char *buf, size_t size);
-// FIXME: Improve for errno modeling.
 addToFunctionSummaryMap(
 "getcwd", Signature(ArgTypes{CharPtrTy, SizeTy}, RetType{CharPtrTy}),
 Summary(NoEvalCall)
+.Case({ArgumentCondition(1, WithinRange, Range(1, SizeMax)),
+   ReturnValueCondition(BO_EQ, ArgNo(0))},
+  ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({ArgumentCondition(1, WithinRange, SingleValue(0)),
+   IsNull(Ret)},
+  ErrnoNEZeroIrrelevant, "Assuming that argument 'size' is 0")
+.Case({ArgumentCondition(1, WithinRange, Range(1, SizeMax)),
+   IsNull(Ret)},
+  ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0)))
+.ArgConstraint(
+BufferSize(/*Buffer*/ ArgNo(0), /*BufSize*/ ArgNo(1)))
 .ArgConstraint(
 ArgumentCondition(1, WithinRange, Range(0, SizeMax;
 

diff  --git a/clang/test/Analysis/errno-stdlibraryfunctions.c 
b/clang/test/Analysis/errno-stdlibraryfunctions.c
index 80e14c4e2923ca..9e3d07e7aa88a0 100644
--- a/clang/test/Analysis/errno-stdlibraryfunctions.c
+++ b/clang/test/Analysis/errno-stdlibraryfunctions.c
@@ -74,3 +74,18 @@ void errno_mkdtemp(char *template) {
 if (errno) {} // expected-warning{{An undefined 
value may be read from 'errno'}}
   }
 }
+
+void errno_getcwd(char *Buf, size_t Sz) {
+  char *Path = getcwd(Buf, Sz);
+  if (Sz == 0) {
+clang_analyzer_eval(errno != 0);   // expected-warning{{TRUE}}
+clang_analyzer_eval(Path == NULL); // expected-warning{{TRUE}}
+if (errno) {}  // no warning
+  } else if (Path == NULL) {
+clang_analyzer_eval(errno != 0);   // expected-warning{{TRUE}}
+if (errno) {}  // no warning
+  } else {
+clang_analyzer_eval(Path == Buf);  // expected-warning{{TRUE}}
+if (errno) {}  // expected-warning{{An undefined value 
may be read from 'errno'}}
+  }
+}



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


[clang] 2b3baff - [Analysis] Use StringRef::rtrim (NFC)

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

Author: Kazu Hirata
Date: 2024-01-08T17:24:47-08:00
New Revision: 2b3baffb4720d4ddc7ddd7080f5ea624230b9324

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

LOG: [Analysis] Use StringRef::rtrim (NFC)

Added: 


Modified: 
clang/lib/Analysis/PathDiagnostic.cpp

Removed: 




diff  --git a/clang/lib/Analysis/PathDiagnostic.cpp 
b/clang/lib/Analysis/PathDiagnostic.cpp
index 0cb03943c547c3..79f337a91ec8fa 100644
--- a/clang/lib/Analysis/PathDiagnostic.cpp
+++ b/clang/lib/Analysis/PathDiagnostic.cpp
@@ -50,12 +50,7 @@
 using namespace clang;
 using namespace ento;
 
-static StringRef StripTrailingDots(StringRef s) {
-  for (StringRef::size_type i = s.size(); i != 0; --i)
-if (s[i - 1] != '.')
-  return s.substr(0, i);
-  return {};
-}
+static StringRef StripTrailingDots(StringRef s) { return s.rtrim('.'); }
 
 PathDiagnosticPiece::PathDiagnosticPiece(StringRef s,
  Kind k, DisplayHint hint)



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


[llvm] [clang] [SPARC] Consume `tune-cpu` directive in the backend (PR #77195)

2024-01-08 Thread Sergei Barannikov via cfe-commits


@@ -5119,7 +5119,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
-  HelpText<"Only supported on AArch64, PowerPC, RISC-V, SystemZ, and X86">;
+  HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;

s-barannikov wrote:

Never mind. I tested an older compiler. It seems to have been fixed in upstream.


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


[clang] [Format] Fix isStartOfName to recognize attributes (PR #76804)

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


@@ -8498,9 +8498,6 @@ TEST_F(FormatTest, 
BreaksFunctionDeclarationsWithTrailingTokens) {
"__attribute__((unused));");
 
   Style = getGoogleStyle();
-  ASSERT_THAT(Style.AttributeMacros,

owenca wrote:

Please also delete line 10:
```
#include "gmock/gmock.h"
```

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


[clang] [Format] Fix isStartOfName to recognize attributes (PR #76804)

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


@@ -2209,7 +2209,8 @@ class AnnotatingParser {
 (!NextNonComment && !Line.InMacroBody) ||
 (NextNonComment &&
  (NextNonComment->isPointerOrReference() ||
-  NextNonComment->isOneOf(tok::identifier, tok::string_literal {
+  (Line.InPragmaDirective &&
+   NextNonComment->isOneOf(tok::identifier, tok::string_literal) {

owenca wrote:

```suggestion
  NextNonComment->is(tok::string_literal) ||
  (Line.InPragmaDirective && NextNonComment->is(tok::identifier) {
```

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


[clang] [Format] Fix isStartOfName to recognize attributes (PR #76804)

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

owenca wrote:

> > can you also add a test to clang/unittests/Format/TokenAnnotatorTest.cpp 
> > that ensures trailing attribute-like macros receive `StartOfName` 
> > annotation to make sure we don't regress the signal in the future?
> 
> ok, that opened a whole can of worms.
> 
> ```
>  Tokens = annotate("void foo GUARDED_BY(x)");
> ```
> 
> gets annotated as
> 
> ```
> {(void, "void" , Unknown),
>   (identifier, "foo" , StartOfName),
>   (identifier, "GUARDED_BY" , FunctionDeclarationName),
>   (l_paren, "(" , Unknown),
>   (identifier, "x" , Unknown),
>   (r_paren, ")" , Unknown),
>   (eof, "" , Unknown)}
> ```
> 
> I expected to get some heuristics for attributes, but instead `GUARDED_BY` 
> gets annotated as a function declaration name. It feels that the current 
> behavior is a result of two mistakes cancelling each other out. I don't think 
> adding a unit test like this is warranted, even if formatting behavior is 
> actually correct.
> 
> @owenca what are your thoughts on this change and whether we should add a 
> test here?

We usually add a FIXME test wrapped in a `#if 0` block:
```
// FIXME: ...
#if 0
Tokens = annotate("void foo GUARDED_BY(x);");
...
Tokens = annotate("void foo GUARDED_BY(x) {}");
...
#endif
```

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


[clang] [Format] Fix isStartOfName to recognize attributes (PR #76804)

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

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


[clang] [llvm] [SPARC] Consume `tune-cpu` directive in the backend (PR #77195)

2024-01-08 Thread Sergei Barannikov via cfe-commits


@@ -5119,7 +5119,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
-  HelpText<"Only supported on AArch64, PowerPC, RISC-V, SystemZ, and X86">;
+  HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;

s-barannikov wrote:

I mean that something like `--target=sparc -mtune=i386` should fail and there 
should be a test for that.
Currently (without this patch) it succeeds on Sparc and fails on e.g. AArch64.
```
$ clang --target=aarch64 -mtune=i386 -xc - https://github.com/llvm/llvm-project/pull/77195
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [libcxx] [mlir] [clang] [clang-tools-extra] [lld] [libcxxabi] [lldb] [libc] [openmp] [llvm] [msan] Unwind stack before fatal reports (PR #77168)

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

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


  1   2   3   4   5   >