[clang] 8af8602 - [NFC] [Serialization] Unify how LocalDeclID can be created

2024-06-19 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2024-06-19T15:18:01+08:00
New Revision: 8af86025af2456c70c84aec309cca9a069124671

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

LOG: [NFC] [Serialization] Unify how LocalDeclID can be created

Now we can create a LocalDeclID directly with an integer without
verifying. It may be hard to refactor if we want to change the way we
serialize DeclIDs (See https://github.com/llvm/llvm-project/pull/95897).
Also it is hard for us to debug if someday someone construct a
LocalDeclID with an incorrect value.

So in this patch, I tried to unify the way we can construct a
LocalDeclID in ASTReader, where we will construct the LocalDeclID from
the serialized data. Also, now we can verify the constructed LocalDeclID
sooner in the new interface.

Added: 


Modified: 
clang/include/clang/AST/ASTUnresolvedSet.h
clang/include/clang/AST/DeclID.h
clang/include/clang/Serialization/ASTBitCodes.h
clang/include/clang/Serialization/ASTReader.h
clang/include/clang/Serialization/ASTWriter.h
clang/lib/AST/DeclBase.cpp
clang/lib/AST/DeclTemplate.cpp
clang/lib/Frontend/ASTUnit.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTUnresolvedSet.h 
b/clang/include/clang/AST/ASTUnresolvedSet.h
index dcce3bc63df25..3838dcb61ee0e 100644
--- a/clang/include/clang/AST/ASTUnresolvedSet.h
+++ b/clang/include/clang/AST/ASTUnresolvedSet.h
@@ -58,7 +58,7 @@ class ASTUnresolvedSet {
   }
 
   void addLazyDecl(ASTContext &C, GlobalDeclID ID, AccessSpecifier AS) {
-Decls.push_back(DeclAccessPair::makeLazy(ID.get(), AS), C);
+Decls.push_back(DeclAccessPair::makeLazy(ID.getRawValue(), AS), C);
   }
 
   /// Replaces the given declaration with the new one, once.

diff  --git a/clang/include/clang/AST/DeclID.h 
b/clang/include/clang/AST/DeclID.h
index 8ee645ec0ecdd..e8f4860e13f1f 100644
--- a/clang/include/clang/AST/DeclID.h
+++ b/clang/include/clang/AST/DeclID.h
@@ -116,12 +116,8 @@ class DeclIDBase {
   DeclIDBase() : ID(PREDEF_DECL_NULL_ID) {}
   explicit DeclIDBase(DeclID ID) : ID(ID) {}
 
-  explicit DeclIDBase(unsigned LocalID, unsigned ModuleFileIndex) {
-ID = (DeclID)LocalID | ((DeclID)ModuleFileIndex << 32);
-  }
-
 public:
-  DeclID get() const { return ID; }
+  DeclID getRawValue() const { return ID; }
 
   explicit operator DeclID() const { return ID; }
 
@@ -135,12 +131,33 @@ class DeclIDBase {
 
   unsigned getLocalDeclIndex() const;
 
+  // The DeclID may be compared with predefined decl ID.
+  friend bool operator==(const DeclIDBase &LHS, const DeclID &RHS) {
+return LHS.ID == RHS;
+  }
+  friend bool operator!=(const DeclIDBase &LHS, const DeclID &RHS) {
+return !operator==(LHS, RHS);
+  }
+  friend bool operator<(const DeclIDBase &LHS, const DeclID &RHS) {
+return LHS.ID < RHS;
+  }
+  friend bool operator<=(const DeclIDBase &LHS, const DeclID &RHS) {
+return LHS.ID <= RHS;
+  }
+  friend bool operator>(const DeclIDBase &LHS, const DeclID &RHS) {
+return LHS.ID > RHS;
+  }
+  friend bool operator>=(const DeclIDBase &LHS, const DeclID &RHS) {
+return LHS.ID >= RHS;
+  }
+
   friend bool operator==(const DeclIDBase &LHS, const DeclIDBase &RHS) {
 return LHS.ID == RHS.ID;
   }
   friend bool operator!=(const DeclIDBase &LHS, const DeclIDBase &RHS) {
 return LHS.ID != RHS.ID;
   }
+
   // We may sort the decl ID.
   friend bool operator<(const DeclIDBase &LHS, const DeclIDBase &RHS) {
 return LHS.ID < RHS.ID;
@@ -159,16 +176,27 @@ class DeclIDBase {
   DeclID ID;
 };
 
+class ASTWriter;
+class ASTReader;
+namespace serialization {
+class ModuleFile;
+} // namespace serialization
+
 class LocalDeclID : public DeclIDBase {
   using Base = DeclIDBase;
 
-public:
-  LocalDeclID() : Base() {}
   LocalDeclID(PredefinedDeclIDs ID) : Base(ID) {}
   explicit LocalDeclID(DeclID ID) : Base(ID) {}
 
-  explicit LocalDeclID(unsigned LocalID, unsigned ModuleFileIndex)
-  : Base(LocalID, ModuleFileIndex) {}
+  // Every Decl ID is a local decl ID to the module being writing in ASTWriter.
+  friend class ASTWriter;
+  friend class GlobalDeclID;
+
+public:
+  LocalDeclID() : Base() {}
+
+  static LocalDeclID get(ASTReader &Reader, serialization::ModuleFile &MF,
+ DeclID ID);
 
   LocalDeclID &operator++() {
 ++ID;
@@ -189,8 +217,8 @@ class GlobalDeclID : public DeclIDBase {
   GlobalDeclID() : Base() {}
   explicit GlobalDeclID(DeclID ID) : Base(ID) {}
 
-  explicit GlobalDeclID(unsigned LocalID, unsigned ModuleFileIndex)
-  : Base(LocalID, ModuleFileIndex) {}
+  explicit 

[clang] [llvm] Split fmv and extensions (PR #92882)

2024-06-19 Thread Tomas Matheson via cfe-commits

https://github.com/tmatheson-arm updated 
https://github.com/llvm/llvm-project/pull/92882

>From b3e9e2f313d3c3a51b7b6690a5cca67a3ec87dd6 Mon Sep 17 00:00:00 2001
From: Tomas Matheson 
Date: Tue, 18 Jun 2024 22:23:11 +0100
Subject: [PATCH 1/2] [AArch64][TargetParser] Split FMV and extensions

---
 clang/include/clang/Basic/TargetInfo.h|   5 -
 clang/lib/AST/ASTContext.cpp  |   4 +-
 clang/lib/Basic/Targets/AArch64.cpp   |  20 +-
 clang/lib/Basic/Targets/AArch64.h |   1 -
 clang/lib/CodeGen/CGBuiltin.cpp   |   2 +-
 clang/lib/CodeGen/Targets/AArch64.cpp |   2 +-
 clang/test/CodeGen/aarch64-fmv-dependencies.c |  92 
 .../llvm/TargetParser/AArch64TargetParser.h   |  32 ++-
 llvm/lib/Target/AArch64/AArch64.td|   1 +
 llvm/lib/Target/AArch64/AArch64FMV.td |  99 +
 llvm/lib/Target/AArch64/AArch64Features.td| 206 --
 llvm/lib/TargetParser/AArch64TargetParser.cpp |  30 ++-
 llvm/utils/TableGen/ARMTargetDefEmitter.cpp   |  36 ++-
 13 files changed, 281 insertions(+), 249 deletions(-)
 create mode 100644 llvm/lib/Target/AArch64/AArch64FMV.td

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 8a6511b9ced83..9b0ae2102e098 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1400,11 +1400,6 @@ class TargetInfo : public TransferrableTargetInfo,
 return true;
   }
 
-  /// For given feature return dependent ones.
-  virtual StringRef getFeatureDependencies(StringRef Feature) const {
-return StringRef();
-  }
-
   struct BranchProtectionInfo {
 LangOptions::SignReturnAddressScopeKind SignReturnAddr;
 LangOptions::SignReturnAddressKeyKind SignKey;
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index aa22825602a40..5329fb6bf22f5 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -13683,9 +13683,9 @@ static std::vector 
getFMVBackendFeaturesFor(
 const llvm::SmallVectorImpl &FMVFeatStrings) {
   std::vector BackendFeats;
   for (StringRef F : FMVFeatStrings) {
-if (auto FMVExt = llvm::AArch64::parseArchExtension(F)) {
+if (auto FMVExt = llvm::AArch64::parseFMVExtension(F)) {
   SmallVector Feats;
-  FMVExt->DependentFeatures.split(Feats, ',', -1, false);
+  FMVExt->Features.split(Feats, ',', -1, false);
   for (StringRef F : Feats)
 BackendFeats.push_back(F.str());
 }
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index fba2ad00df96d..31d8121b91d10 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -673,34 +673,30 @@ AArch64TargetInfo::getVScaleRange(const LangOptions 
&LangOpts) const {
 unsigned AArch64TargetInfo::multiVersionSortPriority(StringRef Name) const {
   if (Name == "default")
 return 0;
-  if (auto Ext = llvm::AArch64::parseArchExtension(Name))
-return Ext->FmvPriority;
+  if (auto Ext = llvm::AArch64::parseFMVExtension(Name))
+return Ext->Priority;
   return 0;
 }
 
 unsigned AArch64TargetInfo::multiVersionFeatureCost() const {
   // Take the maximum priority as per feature cost, so more features win.
-  return llvm::AArch64::ExtensionInfo::MaxFMVPriority;
+  constexpr unsigned MaxFMVPriority = 1000;
+  return MaxFMVPriority;
 }
 
 bool AArch64TargetInfo::doesFeatureAffectCodeGen(StringRef Name) const {
-  if (auto Ext = llvm::AArch64::parseArchExtension(Name))
-return !Ext->DependentFeatures.empty();
+  // FMV extensions which imply no backend features do not affect codegen.
+  if (auto Ext = llvm::AArch64::parseFMVExtension(Name))
+return !Ext->Features.empty();
   return false;
 }
 
-StringRef AArch64TargetInfo::getFeatureDependencies(StringRef Name) const {
-  if (auto Ext = llvm::AArch64::parseArchExtension(Name))
-return Ext->DependentFeatures;
-  return StringRef();
-}
-
 bool AArch64TargetInfo::validateCpuSupports(StringRef FeatureStr) const {
   // CPU features might be separated by '+', extract them and check
   llvm::SmallVector Features;
   FeatureStr.split(Features, "+");
   for (auto &Feature : Features)
-if (!llvm::AArch64::parseArchExtension(Feature.trim()).has_value())
+if (!llvm::AArch64::parseFMVExtension(Feature.trim()).has_value())
   return false;
   return true;
 }
diff --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index c0a6bd2de6b04..71510fe289510 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -151,7 +151,6 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   std::optional>
   getVScaleRange(const LangOptions &LangOpts) const override;
   bool doesFeatureAffectCodeGen(StringRef Name) const override;
-  StringRef getFeatureDependencies(StringRef Name) const override;
   bool validateCpuSupports(StringRef FeatureStr) const override;
   bool hasFeat

[clang] [llvm] [AArch64][TargetParser] Split FMV and extensions (PR #92882)

2024-06-19 Thread Tomas Matheson via cfe-commits

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


[clang] [llvm] [AArch64][TargetParser] Split FMV and extensions (PR #92882)

2024-06-19 Thread Alexandros Lamprineas via cfe-commits


@@ -13683,9 +13683,9 @@ static std::vector 
getFMVBackendFeaturesFor(
 const llvm::SmallVectorImpl &FMVFeatStrings) {
   std::vector BackendFeats;
   for (StringRef F : FMVFeatStrings) {
-if (auto FMVExt = llvm::AArch64::parseArchExtension(F)) {
+if (auto FMVExt = llvm::AArch64::parseFMVExtension(F)) {
   SmallVector Feats;
-  FMVExt->DependentFeatures.split(Feats, ',', -1, false);
+  FMVExt->Features.split(Feats, ',', -1, false);

labrinea wrote:

You can use getImpliedFeatures() here.

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


[clang] [clang][Interp] Implement dynamic memory allocation handling (PR #70306)

2024-06-19 Thread Timm Baeder via cfe-commits

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


[clang] [Serialization] Storing DeclID separately (PR #95897)

2024-06-19 Thread Chuanqi Xu via cfe-commits

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

>From b6d1326fdee4f31c6f6e32783c690b7ae2a4dedb Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Tue, 18 Jun 2024 11:28:03 +0800
Subject: [PATCH] Draft

---
 clang/include/clang/AST/DeclID.h  |   2 +
 .../include/clang/Serialization/ASTBitCodes.h |   3 +
 clang/include/clang/Serialization/ASTReader.h |   5 +-
 .../clang/Serialization/ASTRecordReader.h |  14 ++
 .../clang/Serialization/ASTRecordWriter.h |  27 +++
 clang/lib/Serialization/ASTReader.cpp |  84 -
 clang/lib/Serialization/ASTReaderDecl.cpp |  18 +-
 clang/lib/Serialization/ASTReaderStmt.cpp |   6 +-
 clang/lib/Serialization/ASTWriter.cpp |  28 ++-
 clang/lib/Serialization/ASTWriterDecl.cpp | 173 +++---
 10 files changed, 233 insertions(+), 127 deletions(-)

diff --git a/clang/include/clang/AST/DeclID.h b/clang/include/clang/AST/DeclID.h
index e8f4860e13f1f..5f7c362c6701a 100644
--- a/clang/include/clang/AST/DeclID.h
+++ b/clang/include/clang/AST/DeclID.h
@@ -197,6 +197,8 @@ class LocalDeclID : public DeclIDBase {
 
   static LocalDeclID get(ASTReader &Reader, serialization::ModuleFile &MF,
  DeclID ID);
+  static LocalDeclID get(ASTReader &Reader, serialization::ModuleFile &MF,
+ unsigned ModuleFileIndex, unsigned LocalDeclID);
 
   LocalDeclID &operator++() {
 ++ID;
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 9f0f900a02914..8d789683b3164 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -261,6 +261,9 @@ using unaligned_decl_id_t =
 serialization::DeclID, llvm::endianness::native,
 llvm::support::unaligned>;
 
+/// The number of slots needed to record a DeclID in bitstreams.
+const unsigned int DeclIDRefSize = 2;
+
 /// The number of predefined preprocessed entity IDs.
 const unsigned int NUM_PREDEF_PP_ENTITY_IDS = 1;
 
diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 480f852e3bf07..980c43c7db2cb 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -600,7 +600,7 @@ class ASTReader
 
   /// An array of lexical contents of a declaration context, as a sequence of
   /// Decl::Kind, DeclID pairs.
-  using LexicalContents = ArrayRef;
+  using LexicalContents = ArrayRef;
 
   /// Map from a DeclContext to its lexical contents.
   llvm::DenseMap>
@@ -961,8 +961,7 @@ class ASTReader
   SmallVector DelayedDeleteExprs;
 
   // A list of late parsed template function data with their module files.
-  SmallVector>, 4>
-  LateParsedTemplates;
+  SmallVector, 4> LateParsedTemplates;
 
   /// The IDs of all decls to be checked for deferred diags.
   ///
diff --git a/clang/include/clang/Serialization/ASTRecordReader.h 
b/clang/include/clang/Serialization/ASTRecordReader.h
index d00fb182f05f4..003bb592d188b 100644
--- a/clang/include/clang/Serialization/ASTRecordReader.h
+++ b/clang/include/clang/Serialization/ASTRecordReader.h
@@ -187,12 +187,26 @@ class ASTRecordReader
   /// Reads a declaration from the given position in a record in the
   /// given module, advancing Idx.
   Decl *readDecl() {
+#ifndef NDEBUG
+unsigned OldIdx = Idx;
+Decl *D = Reader->ReadDecl(*F, Record, Idx);
+assert(Idx - OldIdx == serialization::DeclIDRefSize);
+return D;
+#endif
 return Reader->ReadDecl(*F, Record, Idx);
   }
   Decl *readDeclRef() {
 return readDecl();
   }
 
+  template  void readDeclArray(Func &&ConsumeFunc) 
{
+unsigned LengthOfArray = readInt();
+unsigned End = Idx + LengthOfArray;
+
+while (Idx < End)
+  ConsumeFunc(readDeclAs());
+  }
+
   /// Reads a declaration from the given position in the record,
   /// advancing Idx.
   ///
diff --git a/clang/include/clang/Serialization/ASTRecordWriter.h 
b/clang/include/clang/Serialization/ASTRecordWriter.h
index 0c8ac75fc40f4..ed96fbc310096 100644
--- a/clang/include/clang/Serialization/ASTRecordWriter.h
+++ b/clang/include/clang/Serialization/ASTRecordWriter.h
@@ -234,12 +234,39 @@ class ASTRecordWriter
 
   /// Emit a reference to a declaration.
   void AddDeclRef(const Decl *D) {
+#ifndef NDEBUG
+unsigned OldSize = size();
+Writer->AddDeclRef(D, *Record);
+assert(size() - OldSize == serialization::DeclIDRefSize);
+return;
+#endif
 return Writer->AddDeclRef(D, *Record);
   }
   void writeDeclRef(const Decl *D) {
 AddDeclRef(D);
   }
 
+  void writeNullDeclRef() {
+#ifndef NDEBUG
+unsigned OldSize = size();
+#endif
+
+push_back(0);
+push_back(0);
+
+#ifndef NDEBUG
+assert(size() - OldSize == serialization::DeclIDRefSize);
+#endif
+  }
+
+  template  void writeDeclArray(ArrayRef Array) {
+unsigned ElementNum = Array.size();
+push_back(ElementNum * ser

[clang] [clang] Fix `static_cast` to array of unknown bound (PR #96041)

2024-06-19 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon created 
https://github.com/llvm/llvm-project/pull/96041

Per P1975R0 an expression like static_cast(...) defines the type of the 
expression as U[1].

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

>From df58be94be017265b16999525bed8eb75d4d94d8 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Wed, 19 Jun 2024 01:27:18 -0700
Subject: [PATCH] [clang] Fix `static_cast` to array of unknown bound

Per P1975R0 an expression like static_cast(...) defines the type
of the expression as U[1].

Fixes https://github.com/llvm/llvm-project/issues/62863
---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaType.cpp| 14 ++
 clang/test/SemaCXX/paren-list-agg-init.cpp | 21 +
 3 files changed, 37 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7112d1f889fef..d0e5e67651364 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -695,6 +695,8 @@ Bug Fixes in This Version
 - Correctly reject declarations where a statement is required in C.
   Fixes #GH92775
 
+- Fixed `static_cast` to array of unknown bound. Fixes (#GH62863).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 441fdcca0758f..9bb12c6aa7b12 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8771,6 +8771,20 @@ void Sema::completeExprArrayBound(Expr *E) {
   }
 }
   }
+  if (const auto CastE = dyn_cast(E)) {
+QualType DestType = CastE->getTypeAsWritten();
+if (const auto *IAT = Context.getAsIncompleteArrayType(DestType)) {
+  // C++20 [expr.static.cast]p.4: ... If T is array of unknown bound,
+  // this direct-initialization defines the type of the expression
+  // as U[1]
+  QualType ResultType = Context.getConstantArrayType(
+  IAT->getElementType(),
+  llvm::APInt(Context.getTypeSize(Context.getSizeType()), 1),
+  /*SizeExpr=*/nullptr, ArraySizeModifier::Normal,
+  /*IndexTypeQuals=*/0);
+  E->setType(ResultType);
+}
+  }
 }
 
 QualType Sema::getCompletedType(Expr *E) {
diff --git a/clang/test/SemaCXX/paren-list-agg-init.cpp 
b/clang/test/SemaCXX/paren-list-agg-init.cpp
index c1964a5a9eb00..efc1e955d4ed8 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -313,3 +313,24 @@ namespace GH63903 {
   constexpr S s(0); // beforecxx20-warning {{aggregate initialization of type 
'const S' from a parenthesized list of values is a C++20 extension}} \
 // expected-error {{constexpr variable 's' must be 
initialized by a constant expression}}
 }
+
+
+namespace gh62863 {
+int (&&arr)[] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&&arr1)[1] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&&arr2)[2] = static_cast(42); // expected-error {{reference to 
type 'int[2]' could not bind to an rvalue of type 'int[1]'}}
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&&arr3)[3] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[3]' from a 
parenthesized list of values is a C++20 extension}}
+
+int (&&arr4)[] = (int[])(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&&arr5)[1] = (int[])(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&&arr6)[2] = (int[])(42); // expected-error {{reference to type 'int[2]' 
could not bind to an rvalue of type 'int[1]'}}
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&&arr7)[3] = (int[3])(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[3]' from a 
parenthesized list of values is a C++20 extension}}
+}

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


[clang] [clang] Fix `static_cast` to array of unknown bound (PR #96041)

2024-06-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Mariya Podchishchaeva (Fznamznon)


Changes

Per P1975R0 an expression like static_cast(...) defines the type of 
the expression as U[1].

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

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/Sema/SemaType.cpp (+14) 
- (modified) clang/test/SemaCXX/paren-list-agg-init.cpp (+21) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7112d1f889fef..d0e5e67651364 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -695,6 +695,8 @@ Bug Fixes in This Version
 - Correctly reject declarations where a statement is required in C.
   Fixes #GH92775
 
+- Fixed `static_cast` to array of unknown bound. Fixes (#GH62863).
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 441fdcca0758f..9bb12c6aa7b12 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8771,6 +8771,20 @@ void Sema::completeExprArrayBound(Expr *E) {
   }
 }
   }
+  if (const auto CastE = dyn_cast(E)) {
+QualType DestType = CastE->getTypeAsWritten();
+if (const auto *IAT = Context.getAsIncompleteArrayType(DestType)) {
+  // C++20 [expr.static.cast]p.4: ... If T is array of unknown bound,
+  // this direct-initialization defines the type of the expression
+  // as U[1]
+  QualType ResultType = Context.getConstantArrayType(
+  IAT->getElementType(),
+  llvm::APInt(Context.getTypeSize(Context.getSizeType()), 1),
+  /*SizeExpr=*/nullptr, ArraySizeModifier::Normal,
+  /*IndexTypeQuals=*/0);
+  E->setType(ResultType);
+}
+  }
 }
 
 QualType Sema::getCompletedType(Expr *E) {
diff --git a/clang/test/SemaCXX/paren-list-agg-init.cpp 
b/clang/test/SemaCXX/paren-list-agg-init.cpp
index c1964a5a9eb00..efc1e955d4ed8 100644
--- a/clang/test/SemaCXX/paren-list-agg-init.cpp
+++ b/clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -313,3 +313,24 @@ namespace GH63903 {
   constexpr S s(0); // beforecxx20-warning {{aggregate initialization of type 
'const S' from a parenthesized list of values is a C++20 extension}} \
 // expected-error {{constexpr variable 's' must be 
initialized by a constant expression}}
 }
+
+
+namespace gh62863 {
+int (&&arr)[] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&&arr1)[1] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&&arr2)[2] = static_cast(42); // expected-error {{reference to 
type 'int[2]' could not bind to an rvalue of type 'int[1]'}}
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&&arr3)[3] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[3]' from a 
parenthesized list of values is a C++20 extension}}
+
+int (&&arr4)[] = (int[])(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&&arr5)[1] = (int[])(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&&arr6)[2] = (int[])(42); // expected-error {{reference to type 'int[2]' 
could not bind to an rvalue of type 'int[1]'}}
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&&arr7)[3] = (int[3])(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[3]' from a 
parenthesized list of values is a C++20 extension}}
+}

``




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


[clang] [Clang][AArch64] Use 'uint64_t*' for _arm_get_sme_state builtin. (PR #95982)

2024-06-19 Thread Sander de Smalen via cfe-commits

https://github.com/sdesmalen-arm updated 
https://github.com/llvm/llvm-project/pull/95982

>From a41a740d5e77303febbd4e0cb4d8def2010e32ed Mon Sep 17 00:00:00 2001
From: Sander de Smalen 
Date: Tue, 18 Jun 2024 16:04:08 +
Subject: [PATCH 1/2] [Clang][AArch64] Use 'uint64_t*' for _arm_get_sme_state
 builtin.

Depending on the platform, the parameter for __arm_get_sme_state
requires a `unsigned long long*` instead of a `unsigned long*`.

>From ASTContext.cpp:

  case 'W':
// This modifier represents int64 type.
---
 clang/include/clang/Basic/BuiltinsAArch64.def | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/BuiltinsAArch64.def 
b/clang/include/clang/Basic/BuiltinsAArch64.def
index 5f53c98167dfb..5fb199b1b2b03 100644
--- a/clang/include/clang/Basic/BuiltinsAArch64.def
+++ b/clang/include/clang/Basic/BuiltinsAArch64.def
@@ -72,7 +72,7 @@ TARGET_BUILTIN(__builtin_arm_stg, "vv*", "t", "mte")
 TARGET_BUILTIN(__builtin_arm_subp, "Uiv*v*", "t", "mte")
 
 // SME state function
-BUILTIN(__builtin_arm_get_sme_state, "vULi*ULi*", "n")
+BUILTIN(__builtin_arm_get_sme_state, "vWUi*WUi*", "n")
 
 // Memory Operations
 TARGET_BUILTIN(__builtin_arm_mops_memset_tag, "v*v*iz", "", "mte,mops")

>From 025b780dc05634a99e3a45d54472ae01484c4498 Mon Sep 17 00:00:00 2001
From: Sander de Smalen 
Date: Wed, 19 Jun 2024 07:46:17 +
Subject: [PATCH 2/2] Add test-case.

---
 .../acle_sme_state_builtin.c   | 14 ++
 1 file changed, 14 insertions(+)
 create mode 100644 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_state_builtin.c

diff --git a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_state_builtin.c 
b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_state_builtin.c
new file mode 100644
index 0..f2ef0b3c1a3b5
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_state_builtin.c
@@ -0,0 +1,14 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-linux -S -disable-O0-optnone -Werror -Wall 
-o /dev/null %s
+// RUN: %clang_cc1 -triple aarch64-windows -S -disable-O0-optnone -Werror 
-Wall -o /dev/null %s
+// RUN: %clang_cc1 -triple aarch64-darwin -S -disable-O0-optnone -Werror -Wall 
-o /dev/null %s
+
+#include 
+
+// Ensure that the builtin is defined to take a uint64_t * rather than relying
+// on the size of 'unsigned long' which may have different meanings on 
different
+// targets depending on LP64/LLP64.
+void test_sme_state_builtin(uint64_t *a,
+uint64_t *b) __arm_streaming_compatible {
+  __builtin_arm_get_sme_state(a, b);
+}

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


[clang] [llvm] [AArch64] Add ability to list extensions enabled for a target (PR #95805)

2024-06-19 Thread Lucas Duarte Prates via cfe-commits


@@ -19,3 +19,19 @@
 // RUN: %clang --target=arm64 -mlittle-endian -march=armv8.1a -### -c %s 2>&1 
| FileCheck -check-prefix=ARM64-GENERICV81A %s
 // RUN: %clang --target=arm64 -mlittle-endian -march=armv8.1-a -### -c %s 2>&1 
| FileCheck -check-prefix=ARM64-GENERICV81A %s
 // ARM64-GENERICV81A: "-cc1"{{.*}} "-triple" "arm64{{.*}}" "-target-cpu" 
"generic"{{.*}} "-target-feature" "+v8.1a"{{.*}} "-target-feature" "+neon"
+
+// = Architecture extensions =
+
+// RUN: %clang -target aarch64 -march=armv8.1-a --print-enabled-extensions 
2>&1 | FileCheck -check-prefix=ARCH-EXTENSION --implicit-check-not FEAT_ %s
+// ARCH-EXTENSION: FEAT_ETE
+// ARCH-EXTENSION: FEAT_LOR
+// ARCH-EXTENSION: FEAT_TRBE
+// ARCH-EXTENSION: FEAT_VHE
+// ARCH-EXTENSION: FEAT_PAN
+// ARCH-EXTENSION: FEAT_CRC32
+// FIXME: FEAT_FP is optional from v8.0a
+// ARCH-EXTENSION: FEAT_FP
+// ARCH-EXTENSION: FEAT_LSE
+// ARCH-EXTENSION: FEAT_RDM
+// FIXME: FEAT_AdvSIMD is optional from v8.0a

pratlucas wrote:

Agreed. I'll remove these comments and these can be discussed case-by-case in 
the future.

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


[clang] [clang] Fix `static_cast` to array of unknown bound (PR #96041)

2024-06-19 Thread via cfe-commits

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

LGTM, thanks

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


[clang] [clang][Sema] Refine unused-member-function diagnostic message for constructors (PR #84515)

2024-06-19 Thread via cfe-commits

https://github.com/guillem-bartina-sonarsource updated 
https://github.com/llvm/llvm-project/pull/84515

>From 473e8bbeaa8bcb4fb313a5cc75cc7a5de5367879 Mon Sep 17 00:00:00 2001
From: guillem-bartina-sonarsource 
Date: Fri, 8 Mar 2024 17:16:56 +0100
Subject: [PATCH 1/4] [clang][Sema] Refine unused-member-function diagnostic
 message for constructors

---
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +-
 clang/lib/Sema/Sema.cpp   | 15 
 clang/test/SemaCXX/warn-unused-filescoped.cpp | 23 +++
 3 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 9b5245695153e..703803ad2c121 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -400,7 +400,7 @@ def warn_unused_function : Warning<"unused function %0">,
   InGroup, DefaultIgnore;
 def warn_unused_template : Warning<"unused %select{function|variable}0 
template %1">,
   InGroup, DefaultIgnore;
-def warn_unused_member_function : Warning<"unused member function %0">,
+def warn_unused_member_function : Warning<"unused %select{member 
function|constructor}0 %1">,
   InGroup, DefaultIgnore;
 def warn_used_but_marked_unused: Warning<"%0 was marked unused but was used">,
   InGroup, DefaultIgnore;
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 720d5fd5f0428..163ab48998d5e 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1398,11 +1398,16 @@ void Sema::ActOnEndOfTranslationUnit() {
   if (FD->getDescribedFunctionTemplate())
 Diag(DiagD->getLocation(), diag::warn_unused_template)
 << /*function=*/0 << DiagD << DiagRange;
-  else
-Diag(DiagD->getLocation(), isa(DiagD)
-   ? diag::warn_unused_member_function
-   : diag::warn_unused_function)
-<< DiagD << DiagRange;
+  else {
+if (isa(DiagD))
+  Diag(DiagD->getLocation(), diag::warn_unused_member_function)
+  << (!isa(DiagD) ? /*member function=*/0
+  : /*constructor=*/1)
+  << DiagD << DiagRange;
+else
+  Diag(DiagD->getLocation(), diag::warn_unused_function)
+  << DiagD << DiagRange;
+  }
 }
   } else {
 const VarDecl *DiagD = cast(*I)->getDefinition();
diff --git a/clang/test/SemaCXX/warn-unused-filescoped.cpp 
b/clang/test/SemaCXX/warn-unused-filescoped.cpp
index be8d350855c07..b3d1bb4661a5f 100644
--- a/clang/test/SemaCXX/warn-unused-filescoped.cpp
+++ b/clang/test/SemaCXX/warn-unused-filescoped.cpp
@@ -76,10 +76,33 @@ struct S {
   struct SVS : public VS {
 void vm() { }
   };
+
+  struct CS {
+CS() {}
+CS(bool a) {}
+CS(int b) {} // expected-warning{{unused constructor 'CS'}}
+CS(float c);
+  };
+
+  struct DCS : public CS {
+DCS() = default; // expected-warning{{unused constructor 'DCS'}}
+DCS(bool a) : CS(a) {} // expected-warning{{unused constructor 'DCS'}}
+DCS(const DCS&) {}
+DCS(DCS&&) {} // expected-warning{{unused constructor 'DCS'}}
+  };
+
+  template
+  struct TCS {
+TCS();
+  };
+  template  TCS::TCS() {}
+  template <> TCS::TCS() {} // expected-warning{{unused constructor 
'TCS'}}
 }
 
 void S::m3() {} // expected-warning{{unused member function 'm3'}}
 
+CS::CS(float c) {} // expected-warning{{unused constructor 'CS'}}
+
 static inline void f4() {} // expected-warning{{unused function 'f4'}}
 const unsigned int cx = 0; // expected-warning{{unused variable 'cx'}}
 const unsigned int cy = 0;

>From 0a7349318c816a5ce2d338a55ea0830767fae644 Mon Sep 17 00:00:00 2001
From: guillem-bartina-sonarsource 
Date: Fri, 5 Apr 2024 18:19:46 +0200
Subject: [PATCH 2/4] Remove constructor name from diagnostic

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  2 +-
 clang/lib/Sema/Sema.cpp  |  9 +
 clang/test/SemaCXX/warn-unused-filescoped.cpp| 12 ++--
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 703803ad2c121..98a33f01132d2 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -400,7 +400,7 @@ def warn_unused_function : Warning<"unused function %0">,
   InGroup, DefaultIgnore;
 def warn_unused_template : Warning<"unused %select{function|variable}0 
template %1">,
   InGroup, DefaultIgnore;
-def warn_unused_member_function : Warning<"unused %select{member 
function|constructor}0 %1">,
+def warn_unused_member_function : Warning<"unused %select{constructor|member 
function %1}0">,
   InGroup, DefaultIgnore;
 def warn_used_but_marked_unused:

[clang] [clang][analyzer] Add notes to PointerSubChecker (PR #95899)

2024-06-19 Thread Donát Nagy via cfe-commits

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


[clang] [clang][analyzer] Add notes to PointerSubChecker (PR #95899)

2024-06-19 Thread Donát Nagy via cfe-commits

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

LGTM, thanks for the update. I added two minor edit suggestions, but after that 
the commit can be merged.

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


[clang] [clang][analyzer] Add notes to PointerSubChecker (PR #95899)

2024-06-19 Thread Donát Nagy via cfe-commits


@@ -154,12 +154,14 @@ void PointerSubChecker::checkPreStmt(const BinaryOperator 
*B,
 auto R =
 std::make_unique(BT, Msg_MemRegionDifferent, 
N);
 R->addRange(B->getSourceRange());
-if (DiffDeclL)
-  R->addNote("Array at the left-hand side of subtraction",
- {DiffDeclL, C.getSourceManager()});
-if (DiffDeclR)
-  R->addNote("Array at the right-hand side of subtraction",
- {DiffDeclR, C.getSourceManager()});
+if (DiffDeclL != DiffDeclR) {

NagyDonat wrote:

```suggestion
if (DiffDeclL != DiffDeclR) {
  // The declarations may be identical even if the regions are different,
  // if they are field regions within different objects:
  //   struct { int array[10]; } a, b;
  //   do_something_with(a.array[5] - b.array[5]);
  // In this case the notes would be confusing, so don't emit them.
```
Add a comment that explains this `if (DiffDeclL != DiffDeclR)` check because 
otherwise it would be very surprising.

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


[clang] [clang][analyzer] Add notes to PointerSubChecker (PR #95899)

2024-06-19 Thread Donát Nagy via cfe-commits


@@ -32,3 +32,20 @@ void different_2() {
   int d = p2 - p1; // expected-warning{{Subtraction of two pointers that do 
not point into the same array is undefined behavior}} \
// expected-note{{Subtraction of two pointers that do not 
point into the same array is undefined behavior}}
 }
+
+int different_3() {
+  struct {
+int array[5];
+  } a, b;
+  return &a.array[3] - &b.array[2]; // expected-warning{{Subtraction of two 
pointers that do not point into the same array is undefined behavior}} \
+// expected-note{{Subtraction of two 
pointers that do not point into the same array is undefined behavior}}
+}
+
+int different_5() {

NagyDonat wrote:

```suggestion
int different_4() {
```
Very minor nitpick: `different_3` was followed by `different_5`.

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


[clang] [clang][analyzer] Add notes to PointerSubChecker (PR #95899)

2024-06-19 Thread Donát Nagy via cfe-commits

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


[clang] [llvm] [RISCV] Add Syntacore SCR3 processor definition (PR #95953)

2024-06-19 Thread Anton Sidorenko via cfe-commits

https://github.com/asi-sc updated 
https://github.com/llvm/llvm-project/pull/95953

>From 75c4b0d1deb57fb22f9b2446aa8b368c662c38b8 Mon Sep 17 00:00:00 2001
From: Anton Sidorenko 
Date: Tue, 18 Jun 2024 19:40:54 +0300
Subject: [PATCH 1/2] [RISCV] Add Syntacore SCR3 processor definition

Syntacore SCR3 is a microcontroller-class processor core.
Overview: https://syntacore.com/products/scr3
This PR introduces two CPUs:
  * 'syntacore-scr3-rv32' which is rv32imc
  * 'syntacore-scr3-rv64' which is rv64imac

Co-authored-by: Dmitrii Petrov 
---
 clang/test/Driver/riscv-cpus.c| 18 ++
 clang/test/Misc/target-invalid-cpu-note.c |  8 
 llvm/docs/ReleaseNotes.rst|  1 +
 llvm/lib/Target/RISCV/RISCVProcessors.td  | 21 +
 4 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/clang/test/Driver/riscv-cpus.c b/clang/test/Driver/riscv-cpus.c
index 41c257bc559ed..e809cbb32fea2 100644
--- a/clang/test/Driver/riscv-cpus.c
+++ b/clang/test/Driver/riscv-cpus.c
@@ -358,3 +358,21 @@
 
 // RUN: not %clang --target=riscv32 -### -c %s 2>&1 -mcpu=generic-rv32 
-march=rv64i | FileCheck -check-prefix=MISMATCH-ARCH %s
 // MISMATCH-ARCH: cpu 'generic-rv32' does not support rv64
+
+// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=syntacore-scr3-rv32 | 
FileCheck -check-prefix=MCPU-SYNTACORE-SCR3-RV32 %s
+// MCPU-SYNTACORE-SCR3-RV32: "-target-cpu" "syntacore-scr3-rv32"
+// MCPU-SYNTACORE-SCR3-RV32: "-target-feature" "+m" "-target-feature" "+c"
+// MCPU-SYNTACORE-SCR3-RV32: "-target-feature" "+zicsr" "-target-feature" 
"+zifencei"
+// MCPU-SYNTACORE-SCR3-RV32: "-target-abi" "ilp32"
+
+// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mtune=syntacore-scr3-rv32 | 
FileCheck -check-prefix=MTUNE-SYNTACORE-SCR3-RV32 %s
+// MTUNE-SYNTACORE-SCR3-RV32: "-tune-cpu" "syntacore-scr3-rv32"
+
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mcpu=syntacore-scr3-rv64 | 
FileCheck -check-prefix=MCPU-SYNTACORE-SCR3-RV64 %s
+// MCPU-SYNTACORE-SCR3-RV64: "-target-cpu" "syntacore-scr3-rv64"
+// MCPU-SYNTACORE-SCR3-RV64: "-target-feature" "+m" "-target-feature" "+a" 
"-target-feature" "+c"
+// MCPU-SYNTACORE-SCR3-RV64: "-target-feature" "+zicsr" "-target-feature" 
"+zifencei"
+// MCPU-SYNTACORE-SCR3-RV64: "-target-abi" "lp64"
+
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -mtune=syntacore-scr3-rv64 | 
FileCheck -check-prefix=MTUNE-SYNTACORE-SCR3-RV64 %s
+// MTUNE-SYNTACORE-SCR3-RV64: "-tune-cpu" "syntacore-scr3-rv64"
diff --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index 59d3aaa122dbe..1a9063ee5a257 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -81,16 +81,16 @@
 
 // RUN: not %clang_cc1 -triple riscv32 -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix RISCV32
 // RISCV32: error: unknown target CPU 'not-a-cpu'
-// RISCV32-NEXT: note: valid target CPU values are: generic-rv32, rocket-rv32, 
sifive-e20, sifive-e21, sifive-e24, sifive-e31, sifive-e34, sifive-e76, 
syntacore-scr1-base, syntacore-scr1-max{{$}}
+// RISCV32-NEXT: note: valid target CPU values are: generic-rv32, rocket-rv32, 
sifive-e20, sifive-e21, sifive-e24, sifive-e31, sifive-e34, sifive-e76, 
syntacore-scr1-base, syntacore-scr1-max, syntacore-scr3-rv32{{$}}
 
 // RUN: not %clang_cc1 -triple riscv64 -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix RISCV64
 // RISCV64: error: unknown target CPU 'not-a-cpu'
-// RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, 
sifive-p450, sifive-p670, sifive-s21, sifive-s51, sifive-s54, sifive-s76, 
sifive-u54, sifive-u74, sifive-x280, spacemit-x60, veyron-v1, 
xiangshan-nanhu{{$}}
+// RISCV64-NEXT: note: valid target CPU values are: generic-rv64, rocket-rv64, 
sifive-p450, sifive-p670, sifive-s21, sifive-s51, sifive-s54, sifive-s76, 
sifive-u54, sifive-u74, sifive-x280, spacemit-x60, syntacore-scr3-rv64, 
veyron-v1, xiangshan-nanhu{{$}}
 
 // RUN: not %clang_cc1 -triple riscv32 -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE-RISCV32
 // TUNE-RISCV32: error: unknown target CPU 'not-a-cpu'
-// TUNE-RISCV32-NEXT: note: valid target CPU values are: generic-rv32, 
rocket-rv32, sifive-e20, sifive-e21, sifive-e24, sifive-e31, sifive-e34, 
sifive-e76, syntacore-scr1-base, syntacore-scr1-max, generic, rocket, 
sifive-7-series{{$}}
+// TUNE-RISCV32-NEXT: note: valid target CPU values are: generic-rv32, 
rocket-rv32, sifive-e20, sifive-e21, sifive-e24, sifive-e31, sifive-e34, 
sifive-e76, syntacore-scr1-base, syntacore-scr1-max, syntacore-scr3-rv32, 
generic, rocket, sifive-7-series{{$}}
 
 // RUN: not %clang_cc1 -triple riscv64 -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE-RISCV64
 // TUNE-RISCV64: error: unknown target CPU 'not-a-cpu'
-// TUNE-RISCV64-NEXT: note: valid target CPU values are: generic-rv64, 
rocket-rv64, sifive-p450, sifive-p

[clang] [llvm] [RISCV] Add Syntacore SCR3 processor definition (PR #95953)

2024-06-19 Thread Anton Sidorenko via cfe-commits


@@ -358,3 +358,21 @@
 
 // RUN: not %clang --target=riscv32 -### -c %s 2>&1 -mcpu=generic-rv32 
-march=rv64i | FileCheck -check-prefix=MISMATCH-ARCH %s
 // MISMATCH-ARCH: cpu 'generic-rv32' does not support rv64
+
+// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=syntacore-scr3-rv32 | 
FileCheck -check-prefix=MCPU-SYNTACORE-SCR3-RV32 %s
+// MCPU-SYNTACORE-SCR3-RV32: "-target-cpu" "syntacore-scr3-rv32"
+// MCPU-SYNTACORE-SCR3-RV32: "-target-feature" "+m" "-target-feature" "+c"

asi-sc wrote:

Addressed.

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


[clang] [llvm] [RISCV] Add Syntacore SCR3 processor definition (PR #95953)

2024-06-19 Thread Anton Sidorenko via cfe-commits


@@ -358,3 +358,21 @@
 
 // RUN: not %clang --target=riscv32 -### -c %s 2>&1 -mcpu=generic-rv32 
-march=rv64i | FileCheck -check-prefix=MISMATCH-ARCH %s
 // MISMATCH-ARCH: cpu 'generic-rv32' does not support rv64
+
+// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=syntacore-scr3-rv32 | 
FileCheck -check-prefix=MCPU-SYNTACORE-SCR3-RV32 %s
+// MCPU-SYNTACORE-SCR3-RV32: "-target-cpu" "syntacore-scr3-rv32"
+// MCPU-SYNTACORE-SCR3-RV32: "-target-feature" "+m" "-target-feature" "+c"
+// MCPU-SYNTACORE-SCR3-RV32: "-target-feature" "+zicsr" "-target-feature" 
"+zifencei"
+// MCPU-SYNTACORE-SCR3-RV32: "-target-abi" "ilp32"
+
+// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mtune=syntacore-scr3-rv32 | 
FileCheck -check-prefix=MTUNE-SYNTACORE-SCR3-RV32 %s
+// MTUNE-SYNTACORE-SCR3-RV32: "-tune-cpu" "syntacore-scr3-rv32"

asi-sc wrote:

This just copies the checks many processors do (rocket, veyron, 
xiangshan-nanhu, etc)

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


[clang] [llvm] [RISCV] Add Syntacore SCR3 processor definition (PR #95953)

2024-06-19 Thread Pengcheng Wang via cfe-commits

https://github.com/wangpc-pp approved this pull request.


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


[clang] [llvm] [AArch64][TargetParser] Split FMV and extensions (PR #92882)

2024-06-19 Thread Tomas Matheson via cfe-commits

https://github.com/tmatheson-arm updated 
https://github.com/llvm/llvm-project/pull/92882

>From b3e9e2f313d3c3a51b7b6690a5cca67a3ec87dd6 Mon Sep 17 00:00:00 2001
From: Tomas Matheson 
Date: Tue, 18 Jun 2024 22:23:11 +0100
Subject: [PATCH 1/2] [AArch64][TargetParser] Split FMV and extensions

---
 clang/include/clang/Basic/TargetInfo.h|   5 -
 clang/lib/AST/ASTContext.cpp  |   4 +-
 clang/lib/Basic/Targets/AArch64.cpp   |  20 +-
 clang/lib/Basic/Targets/AArch64.h |   1 -
 clang/lib/CodeGen/CGBuiltin.cpp   |   2 +-
 clang/lib/CodeGen/Targets/AArch64.cpp |   2 +-
 clang/test/CodeGen/aarch64-fmv-dependencies.c |  92 
 .../llvm/TargetParser/AArch64TargetParser.h   |  32 ++-
 llvm/lib/Target/AArch64/AArch64.td|   1 +
 llvm/lib/Target/AArch64/AArch64FMV.td |  99 +
 llvm/lib/Target/AArch64/AArch64Features.td| 206 --
 llvm/lib/TargetParser/AArch64TargetParser.cpp |  30 ++-
 llvm/utils/TableGen/ARMTargetDefEmitter.cpp   |  36 ++-
 13 files changed, 281 insertions(+), 249 deletions(-)
 create mode 100644 llvm/lib/Target/AArch64/AArch64FMV.td

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 8a6511b9ced83..9b0ae2102e098 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1400,11 +1400,6 @@ class TargetInfo : public TransferrableTargetInfo,
 return true;
   }
 
-  /// For given feature return dependent ones.
-  virtual StringRef getFeatureDependencies(StringRef Feature) const {
-return StringRef();
-  }
-
   struct BranchProtectionInfo {
 LangOptions::SignReturnAddressScopeKind SignReturnAddr;
 LangOptions::SignReturnAddressKeyKind SignKey;
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index aa22825602a40..5329fb6bf22f5 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -13683,9 +13683,9 @@ static std::vector 
getFMVBackendFeaturesFor(
 const llvm::SmallVectorImpl &FMVFeatStrings) {
   std::vector BackendFeats;
   for (StringRef F : FMVFeatStrings) {
-if (auto FMVExt = llvm::AArch64::parseArchExtension(F)) {
+if (auto FMVExt = llvm::AArch64::parseFMVExtension(F)) {
   SmallVector Feats;
-  FMVExt->DependentFeatures.split(Feats, ',', -1, false);
+  FMVExt->Features.split(Feats, ',', -1, false);
   for (StringRef F : Feats)
 BackendFeats.push_back(F.str());
 }
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index fba2ad00df96d..31d8121b91d10 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -673,34 +673,30 @@ AArch64TargetInfo::getVScaleRange(const LangOptions 
&LangOpts) const {
 unsigned AArch64TargetInfo::multiVersionSortPriority(StringRef Name) const {
   if (Name == "default")
 return 0;
-  if (auto Ext = llvm::AArch64::parseArchExtension(Name))
-return Ext->FmvPriority;
+  if (auto Ext = llvm::AArch64::parseFMVExtension(Name))
+return Ext->Priority;
   return 0;
 }
 
 unsigned AArch64TargetInfo::multiVersionFeatureCost() const {
   // Take the maximum priority as per feature cost, so more features win.
-  return llvm::AArch64::ExtensionInfo::MaxFMVPriority;
+  constexpr unsigned MaxFMVPriority = 1000;
+  return MaxFMVPriority;
 }
 
 bool AArch64TargetInfo::doesFeatureAffectCodeGen(StringRef Name) const {
-  if (auto Ext = llvm::AArch64::parseArchExtension(Name))
-return !Ext->DependentFeatures.empty();
+  // FMV extensions which imply no backend features do not affect codegen.
+  if (auto Ext = llvm::AArch64::parseFMVExtension(Name))
+return !Ext->Features.empty();
   return false;
 }
 
-StringRef AArch64TargetInfo::getFeatureDependencies(StringRef Name) const {
-  if (auto Ext = llvm::AArch64::parseArchExtension(Name))
-return Ext->DependentFeatures;
-  return StringRef();
-}
-
 bool AArch64TargetInfo::validateCpuSupports(StringRef FeatureStr) const {
   // CPU features might be separated by '+', extract them and check
   llvm::SmallVector Features;
   FeatureStr.split(Features, "+");
   for (auto &Feature : Features)
-if (!llvm::AArch64::parseArchExtension(Feature.trim()).has_value())
+if (!llvm::AArch64::parseFMVExtension(Feature.trim()).has_value())
   return false;
   return true;
 }
diff --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index c0a6bd2de6b04..71510fe289510 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -151,7 +151,6 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   std::optional>
   getVScaleRange(const LangOptions &LangOpts) const override;
   bool doesFeatureAffectCodeGen(StringRef Name) const override;
-  StringRef getFeatureDependencies(StringRef Name) const override;
   bool validateCpuSupports(StringRef FeatureStr) const override;
   bool hasFeat

[clang] [clang-tools-extra] [clang] Implement CWG2398 provisional TTP matching to class templates (PR #94981)

2024-06-19 Thread Vlad Serebrennikov via cfe-commits




Endilll wrote:

Now that you published P3310R0, this test can be moved to DR tests with a 
status `// cwg2398: 19 drafting P3310R0`.

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


[clang] [lldb] [clang][lldb] Don't assert structure layout correctness for layouts provided by LLDB (PR #93809)

2024-06-19 Thread Michael Buch via cfe-commits

Michael137 wrote:

Ah got it, thanks for clarifying.

> so we could instead just check if the field is empty.

Couldn't find an existing API for this on `FieldDecl`. Here "empty" would be 
"field is of a type which is empty"? Which might still cause complications 
because a `CXXRecordDecl::isEmpty` itself depends on `isZeroSize` of its fields.

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


[clang-tools-extra] e7b4b43 - [include-cleaner] Use filename as requested, not resolved path

2024-06-19 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2024-06-19T12:04:42+02:00
New Revision: e7b4b437fbbf087ac4955ed5945c3e2f3dd2b702

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

LOG: [include-cleaner] Use filename as requested, not resolved path

This was an unintended change in d5297b72aa32ad3a69563a1fcc61294282f0b379.
We don't want to resolve symlinks in filenames, as these might lead to
unexpected spellings, compared to requested filenames.

Added: 


Modified: 
clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp 
b/clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp
index 8332eb685d652..d0549825d4c40 100644
--- a/clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp
+++ b/clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp
@@ -37,8 +37,8 @@ class DefaultIncludeSpeller : public IncludeSpeller {
 .getCurrentWorkingDirectory())
 WorkingDir = *WD;
   std::string FinalSpelling = Input.HS.suggestPathToFileForDiagnostics(
-  Input.H.resolvedPath(), WorkingDir, Input.Main->tryGetRealPathName(),
-  &IsAngled);
+  Input.H.physical().getName(), WorkingDir,
+  Input.Main->tryGetRealPathName(), &IsAngled);
   return IsAngled ? "<" + FinalSpelling + ">" : "\"" + FinalSpelling + 
"\"";
 }
 llvm_unreachable("Unknown clang::include_cleaner::Header::Kind enum");



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


[clang] [llvm] [AArch64][TargetParser] Split FMV and extensions (PR #92882)

2024-06-19 Thread Tomas Matheson via cfe-commits

https://github.com/tmatheson-arm updated 
https://github.com/llvm/llvm-project/pull/92882

>From b3e9e2f313d3c3a51b7b6690a5cca67a3ec87dd6 Mon Sep 17 00:00:00 2001
From: Tomas Matheson 
Date: Tue, 18 Jun 2024 22:23:11 +0100
Subject: [PATCH 1/3] [AArch64][TargetParser] Split FMV and extensions

---
 clang/include/clang/Basic/TargetInfo.h|   5 -
 clang/lib/AST/ASTContext.cpp  |   4 +-
 clang/lib/Basic/Targets/AArch64.cpp   |  20 +-
 clang/lib/Basic/Targets/AArch64.h |   1 -
 clang/lib/CodeGen/CGBuiltin.cpp   |   2 +-
 clang/lib/CodeGen/Targets/AArch64.cpp |   2 +-
 clang/test/CodeGen/aarch64-fmv-dependencies.c |  92 
 .../llvm/TargetParser/AArch64TargetParser.h   |  32 ++-
 llvm/lib/Target/AArch64/AArch64.td|   1 +
 llvm/lib/Target/AArch64/AArch64FMV.td |  99 +
 llvm/lib/Target/AArch64/AArch64Features.td| 206 --
 llvm/lib/TargetParser/AArch64TargetParser.cpp |  30 ++-
 llvm/utils/TableGen/ARMTargetDefEmitter.cpp   |  36 ++-
 13 files changed, 281 insertions(+), 249 deletions(-)
 create mode 100644 llvm/lib/Target/AArch64/AArch64FMV.td

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 8a6511b9ced83..9b0ae2102e098 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1400,11 +1400,6 @@ class TargetInfo : public TransferrableTargetInfo,
 return true;
   }
 
-  /// For given feature return dependent ones.
-  virtual StringRef getFeatureDependencies(StringRef Feature) const {
-return StringRef();
-  }
-
   struct BranchProtectionInfo {
 LangOptions::SignReturnAddressScopeKind SignReturnAddr;
 LangOptions::SignReturnAddressKeyKind SignKey;
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index aa22825602a40..5329fb6bf22f5 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -13683,9 +13683,9 @@ static std::vector 
getFMVBackendFeaturesFor(
 const llvm::SmallVectorImpl &FMVFeatStrings) {
   std::vector BackendFeats;
   for (StringRef F : FMVFeatStrings) {
-if (auto FMVExt = llvm::AArch64::parseArchExtension(F)) {
+if (auto FMVExt = llvm::AArch64::parseFMVExtension(F)) {
   SmallVector Feats;
-  FMVExt->DependentFeatures.split(Feats, ',', -1, false);
+  FMVExt->Features.split(Feats, ',', -1, false);
   for (StringRef F : Feats)
 BackendFeats.push_back(F.str());
 }
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index fba2ad00df96d..31d8121b91d10 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -673,34 +673,30 @@ AArch64TargetInfo::getVScaleRange(const LangOptions 
&LangOpts) const {
 unsigned AArch64TargetInfo::multiVersionSortPriority(StringRef Name) const {
   if (Name == "default")
 return 0;
-  if (auto Ext = llvm::AArch64::parseArchExtension(Name))
-return Ext->FmvPriority;
+  if (auto Ext = llvm::AArch64::parseFMVExtension(Name))
+return Ext->Priority;
   return 0;
 }
 
 unsigned AArch64TargetInfo::multiVersionFeatureCost() const {
   // Take the maximum priority as per feature cost, so more features win.
-  return llvm::AArch64::ExtensionInfo::MaxFMVPriority;
+  constexpr unsigned MaxFMVPriority = 1000;
+  return MaxFMVPriority;
 }
 
 bool AArch64TargetInfo::doesFeatureAffectCodeGen(StringRef Name) const {
-  if (auto Ext = llvm::AArch64::parseArchExtension(Name))
-return !Ext->DependentFeatures.empty();
+  // FMV extensions which imply no backend features do not affect codegen.
+  if (auto Ext = llvm::AArch64::parseFMVExtension(Name))
+return !Ext->Features.empty();
   return false;
 }
 
-StringRef AArch64TargetInfo::getFeatureDependencies(StringRef Name) const {
-  if (auto Ext = llvm::AArch64::parseArchExtension(Name))
-return Ext->DependentFeatures;
-  return StringRef();
-}
-
 bool AArch64TargetInfo::validateCpuSupports(StringRef FeatureStr) const {
   // CPU features might be separated by '+', extract them and check
   llvm::SmallVector Features;
   FeatureStr.split(Features, "+");
   for (auto &Feature : Features)
-if (!llvm::AArch64::parseArchExtension(Feature.trim()).has_value())
+if (!llvm::AArch64::parseFMVExtension(Feature.trim()).has_value())
   return false;
   return true;
 }
diff --git a/clang/lib/Basic/Targets/AArch64.h 
b/clang/lib/Basic/Targets/AArch64.h
index c0a6bd2de6b04..71510fe289510 100644
--- a/clang/lib/Basic/Targets/AArch64.h
+++ b/clang/lib/Basic/Targets/AArch64.h
@@ -151,7 +151,6 @@ class LLVM_LIBRARY_VISIBILITY AArch64TargetInfo : public 
TargetInfo {
   std::optional>
   getVScaleRange(const LangOptions &LangOpts) const override;
   bool doesFeatureAffectCodeGen(StringRef Name) const override;
-  StringRef getFeatureDependencies(StringRef Name) const override;
   bool validateCpuSupports(StringRef FeatureStr) const override;
   bool hasFeat

[clang] [flang] [flang] Implement -mcmodel flag (PR #95411)

2024-06-19 Thread Thirumalai Shaktivel via cfe-commits

Thirumalai-Shaktivel wrote:

This seems to introduce a `-mcmodel` flag, thanks for that.
But, when I do `flang-new -mcmodel=medium x.f90`, I get another unknown 
argument issue.
```console
$ flang-new -mcmodel=medium x.f90
error: unknown argument: '-mlarge-data-threshold=65536'
```

What might be issue?

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


[clang] [clang] Change style of superseded issues on C++ DR status page (PR #96051)

2024-06-19 Thread Vlad Serebrennikov via cfe-commits

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

This patch changes how superseded issues inherit the color of the issues that 
superseded them. Now they reduce the opacity of the color from 1.0 to 0.65, to 
make them distinguishable. This was requested during the review of #94876.

That's how it's going to look:
![a1rYVHQ](https://github.com/llvm/llvm-project/assets/12883766/00e624c0-accb-4440-9f9b-4089a157aab2)


>From 30179e044b3266eb85a2841691db6235ea0bed18 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Wed, 19 Jun 2024 13:42:33 +0300
Subject: [PATCH] [clang] Change style of superseded issues on C++ DR status
 page

---
 clang/www/cxx_dr_status.html | 65 
 clang/www/make_cxx_dr_status | 56 +++
 2 files changed, 70 insertions(+), 51 deletions(-)

diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index dac38cedfcb75..7b61f47d834da 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -8,12 +8,19 @@
   
   

[clang] [clang] Change style of superseded issues on C++ DR status page (PR #96051)

2024-06-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)


Changes

This patch changes how superseded issues inherit the color of the issues that 
superseded them. Now they reduce the opacity of the color from 1.0 to 0.65, to 
make them distinguishable. This was requested during the review of #94876.

That's how it's going to look:
![a1rYVHQ](https://github.com/llvm/llvm-project/assets/12883766/00e624c0-accb-4440-9f9b-4089a157aab2)


---

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


2 Files Affected:

- (modified) clang/www/cxx_dr_status.html (+36-29) 
- (modified) clang/www/make_cxx_dr_status (+34-22) 


``diff
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index dac38cedfcb75..7b61f47d834da 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -8,12 +8,19 @@
   
   

[clang] [clang-format][NFC] Add CMake target clang-format-check-format (PR #95873)

2024-06-19 Thread Björn Schäpers via cfe-commits

HazardyKnusperkeks wrote:

I have no idea about cmake files and hopefully never will. So I can't say 
anything on how you did it, I'm fine with what you want to do.

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


[clang] [clang-format] Correctly annotate l_brace after TypenameMacro (PR #96026)

2024-06-19 Thread Björn Schäpers via cfe-commits


@@ -3180,6 +3180,18 @@ TEST_F(TokenAnnotatorTest, FunctionTryBlock) {
   EXPECT_TOKEN(Tokens[36], tok::l_brace, TT_FunctionLBrace);
 }
 
+TEST_F(TokenAnnotatorTest, TypenameMacro) {
+  auto Style = getLLVMStyle();
+  Style.TypenameMacros.push_back("STRUCT");
+
+  auto Tokens = annotate("STRUCT(T, B) { int i; };", Style);
+  ASSERT_EQ(Tokens.size(), 13u);
+  EXPECT_TOKEN(Tokens[0], tok::identifier, TT_TypenameMacro);
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_TypeDeclarationParen);
+  EXPECT_TOKEN(Tokens[5], tok::r_paren, TT_TypeDeclarationParen);
+  EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_Unknown);

HazardyKnusperkeks wrote:

Is `TT_Unknown` the correct type? I know we can't really say if it's a 
`TT_StructLBrace` or `TT_ClassLBrace` (or even `TT_UnionLBrace`), but would it 
harm to just guess one of them?

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


[clang-tools-extra] [clang-tidy] Clarify diagnostics of bugprone-sizeof-expression (PR #95550)

2024-06-19 Thread via cfe-commits


@@ -342,31 +342,33 @@ void SizeofExpressionCheck::check(const 
MatchFinder::MatchResult &Result) {
 
 if (DenominatorSize > CharUnits::Zero() &&
 !NumeratorSize.isMultipleOf(DenominatorSize)) {
-  diag(E->getOperatorLoc(), "suspicious usage of 
'sizeof(...)/sizeof(...)';"
+  diag(E->getOperatorLoc(), "suspicious usage of 
'sizeof(...)/sizeof(...)':"
 " numerator is not a multiple of denominator")
   << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
 } else if (ElementSize > CharUnits::Zero() &&
DenominatorSize > CharUnits::Zero() &&
ElementSize != DenominatorSize) {
-  diag(E->getOperatorLoc(), "suspicious usage of 
'sizeof(...)/sizeof(...)';"
-" numerator is not a multiple of denominator")
+  diag(E->getOperatorLoc(),
+   "suspicious usage of 'sizeof(array)/sizeof(...)':"

whisperity wrote:

```suggestion
   "suspicious usage of 'sizeof(...)/sizeof(...)':"
```

Maybe it would be better to keep the scheme here?

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


[clang-tools-extra] [clang-tidy] Clarify diagnostics of bugprone-sizeof-expression (PR #95550)

2024-06-19 Thread via cfe-commits


@@ -342,31 +342,33 @@ void SizeofExpressionCheck::check(const 
MatchFinder::MatchResult &Result) {
 
 if (DenominatorSize > CharUnits::Zero() &&
 !NumeratorSize.isMultipleOf(DenominatorSize)) {
-  diag(E->getOperatorLoc(), "suspicious usage of 
'sizeof(...)/sizeof(...)';"
+  diag(E->getOperatorLoc(), "suspicious usage of 
'sizeof(...)/sizeof(...)':"

whisperity wrote:

```suggestion
  diag(E->getOperatorLoc(), "suspicious sizeof(...)/sizeof(...):"
```

And then consistently everywhere.

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


[clang-tools-extra] [clang-tidy] Clarify diagnostics of bugprone-sizeof-expression (PR #95550)

2024-06-19 Thread via cfe-commits


@@ -342,31 +342,33 @@ void SizeofExpressionCheck::check(const 
MatchFinder::MatchResult &Result) {
 
 if (DenominatorSize > CharUnits::Zero() &&
 !NumeratorSize.isMultipleOf(DenominatorSize)) {
-  diag(E->getOperatorLoc(), "suspicious usage of 
'sizeof(...)/sizeof(...)';"
+  diag(E->getOperatorLoc(), "suspicious usage of 
'sizeof(...)/sizeof(...)':"
 " numerator is not a multiple of denominator")
   << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
 } else if (ElementSize > CharUnits::Zero() &&
DenominatorSize > CharUnits::Zero() &&
ElementSize != DenominatorSize) {
-  diag(E->getOperatorLoc(), "suspicious usage of 
'sizeof(...)/sizeof(...)';"
-" numerator is not a multiple of denominator")
+  diag(E->getOperatorLoc(),
+   "suspicious usage of 'sizeof(array)/sizeof(...)':"
+   " denominator differs from the size of array elements")

whisperity wrote:

Is the array case the only that can trigger this?

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


[clang-tools-extra] [clang-tidy] Clarify diagnostics of bugprone-sizeof-expression (PR #95550)

2024-06-19 Thread via cfe-commits

whisperity wrote:

Maybe the use of the `:` is indeed problematic, even if that would be the most 
accurate use of English in the present form, because of its use in the normal 
text-diagnostic-printing output. (Speaking from the English side of things, a 
`-` would also be incorrect, you would need a dash (`–`) but then that would 
not be nice on ASCII and whatnot...)

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


[clang] [clang] Implement CWG2877 "Type-only lookup for using-enum-declarator" (PR #95399)

2024-06-19 Thread Vlad Serebrennikov via cfe-commits


@@ -738,16 +738,47 @@ Parser::DeclGroupPtrTy Parser::ParseUsingDeclaration(
   return nullptr;
 }
 
-if (!Tok.is(tok::identifier)) {
+Decl *UED = nullptr;
+
+if (Tok.is(tok::identifier)) {
+  IdentifierInfo *IdentInfo = Tok.getIdentifierInfo();
+  SourceLocation IdentLoc = ConsumeToken();
+
+  ParsedType Type = Actions.getTypeName(
+  *IdentInfo, IdentLoc, getCurScope(), &SS, /*isClassName=*/true,
+  /*HasTrailingDot=*/false,
+  /*ObjectType=*/nullptr, /*IsCtorOrDtorName=*/false,
+  /*WantNontrivialTypeSourceInfo=*/true);
+
+  UED = Actions.ActOnUsingEnumDeclaration(
+  getCurScope(), AS, UsingLoc, UELoc, IdentLoc, *IdentInfo, Type, &SS);
+} else if (Tok.is(tok::annot_template_id)) {
+  TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
+
+  if (TemplateId->mightBeType()) {
+AnnotateTemplateIdTokenAsType(SS, ImplicitTypenameContext::No,
+  /*IsClassName=*/true);
+
+assert(Tok.is(tok::annot_typename) && "template-id -> type failed");
+TypeResult Type = getTypeAnnotation(Tok);
+SourceRange Loc = Tok.getAnnotationRange();
+ConsumeAnnotationToken();
+
+UED = Actions.ActOnUsingEnumDeclaration(getCurScope(), AS, UsingLoc,
+UELoc, Loc, *TemplateId->Name,
+Type.get(), &SS);
+  } else {
+Diag(Tok.getLocation(), diag::err_using_enum_not_enum)
+<< TemplateId->Name->getName()

Endilll wrote:

> maybe by calling `ClassifyName`

Looks like `ClassifyName` doesn't provide more information than I currently 
have.

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


[clang] [analyzer] Check the correct first and last elements in cstring.UninitializedRead (PR #95408)

2024-06-19 Thread Donát Nagy via cfe-commits


@@ -393,6 +401,173 @@ ProgramStateRef 
CStringChecker::checkNonNull(CheckerContext &C,
   return stateNonNull;
 }
 
+static std::optional getIndex(ProgramStateRef State,
+  const ElementRegion *ER, CharKind CK) {
+  SValBuilder &SValBuilder = State->getStateManager().getSValBuilder();
+  ASTContext &Ctx = SValBuilder.getContext();
+
+  if (CK == CharKind::Regular) {
+if (ER->getValueType() != Ctx.CharTy)
+  return {};
+return ER->getIndex();
+  }
+
+  if (ER->getValueType() != Ctx.WideCharTy)
+return {};
+
+  QualType SizeTy = Ctx.getSizeType();
+  NonLoc WideSize =
+  SValBuilder
+  .makeIntVal(Ctx.getTypeSizeInChars(Ctx.WideCharTy).getQuantity(),
+  SizeTy)
+  .castAs();
+  SVal Offset =
+  SValBuilder.evalBinOpNN(State, BO_Mul, ER->getIndex(), WideSize, SizeTy);
+  if (Offset.isUnknown())
+return {};
+  return Offset.castAs();
+}
+
+// Try to get hold of the origin regin (e.g. the actual array region from an
+// element region).
+static const TypedValueRegion *getOriginRegion(const ElementRegion *ER) {
+  const MemRegion *MR = ER->getSuperRegion();
+  const MemRegion *Ret = MR;
+  assert(MR);
+  if (const auto *sym = MR->getAs()) {
+SymbolRef sym2 = sym->getSymbol();
+if (!sym2)
+  return nullptr;
+Ret = sym2->getOriginRegion();
+  }
+  if (const auto *element = MR->getAs()) {
+Ret = element->getBaseRegion();
+  }
+  return dyn_cast_or_null(Ret);
+}
+
+// Basically 1 -> 1st, 12 -> 12th, etc.
+static void printIdxWithOrdinalSuffix(llvm::raw_ostream &Os, unsigned Idx) {
+  Os << Idx << llvm::getOrdinalSuffix(Idx);
+}
+
+ProgramStateRef CStringChecker::checkInit(CheckerContext &C,
+  ProgramStateRef State,
+  AnyArgExpr Buffer, SVal Element,
+  SVal Size) const {
+
+  // If a previous check has failed, propagate the failure.
+  if (!State)
+return nullptr;
+
+  const MemRegion *R = Element.getAsRegion();
+  if (!R)
+return State;
+
+  const auto *ER = dyn_cast(R);
+  if (!ER)
+return State;
+
+  const TypedValueRegion *Orig = getOriginRegion(ER);
+  if (!Orig)
+return State;
+
+  SValBuilder &SValBuilder = State->getStateManager().getSValBuilder();
+  ASTContext &Ctx = SValBuilder.getContext();
+
+  // FIXME: We ought to able to check objects as well. Maybe
+  // UninitializedObjectChecker could help?
+  if (!Orig->getValueType()->isArrayType())
+return State;
+
+  const QualType ElemTy = Ctx.getBaseElementType(Orig->getValueType());
+  const NonLoc Zero = SValBuilder.makeZeroArrayIndex();
+
+  SVal FirstElementVal =
+  State->getLValue(ElemTy, Zero, loc::MemRegionVal(Orig)).castAs();
+  if (!isa(FirstElementVal))
+return State;
+
+  // Ensure that we wouldn't read uninitialized value.
+  if (Filter.CheckCStringUninitializedRead &&
+  State->getSVal(FirstElementVal.castAs()).isUndef()) {
+llvm::SmallString<258> Buf;
+llvm::raw_svector_ostream OS(Buf);
+OS << "The first element of the ";
+printIdxWithOrdinalSuffix(OS, Buffer.ArgumentIndex + 1);
+OS << " argument is undefined";
+emitUninitializedReadBug(C, State, Buffer.Expression, OS.str());
+return nullptr;
+  }
+
+  // We won't check whether the entire region is fully initialized -- lets just
+  // check that the first and the last element is. So, onto checking the last
+  // element:
+  const QualType IdxTy = SValBuilder.getArrayIndexType();
+
+  NonLoc ElemSize =
+  SValBuilder
+  .makeIntVal(Ctx.getTypeSizeInChars(ElemTy).getQuantity(), IdxTy)
+  .castAs();
+
+  // FIXME: Check that the size arg to the cstring function is divisible by
+  // size of the actual element type?
+
+  // The type of the argument to the cstring function is either char or wchar,
+  // but thats not the type of the original array (or memory region).
+  // Suppose the following:
+  //   int t[5];
+  //   memcpy(dst, t, sizeof(t) / sizeof(t[0]));
+  // When checking whether t is fully initialized, we see it as char array of
+  // size sizeof(int)*5. If we check the last element as a character, we read
+  // the last byte of an integer, which will be undefined. But just because
+  // that value is undefined, it doesn't mean that the element is 
uninitialized!
+  // For this reason, we need to retrieve the actual last element with the
+  // correct type.
+
+  // Divide the size argument to the cstring function by the actual element
+  // type. This value will be size of the array, or the index to the
+  // past-the-end element.
+  std::optional Offset =
+  SValBuilder
+  .evalBinOpNN(State, clang::BO_Div, Size.castAs(), ElemSize,
+   IdxTy)
+  .getAs();
+
+  // Retrieve the index of the last element.
+  const NonLoc One = SValBuilder.makeIntVal(1, IdxTy).castAs();
+  SVal LastIdx = SValBuilder.evalBinOpNN(State,

[clang] [Clang] [Sema] Ensure noexcept(typeid(E)) checks if E throws when needed (PR #95846)

2024-06-19 Thread via cfe-commits

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


[clang] [Clang] [Sema] Ensure noexcept(typeid(E)) checks if E throws when needed (PR #95846)

2024-06-19 Thread via cfe-commits


@@ -115,3 +116,39 @@ static_assert(!noexcept(typeid((Polymorphic&&) Polymorphic&) 
Polymorphic{})));
 static_assert(!noexcept(typeid(*&(const Polymorphic&) 
Polymorphic{})));
 static_assert(!noexcept(typeid(*&(const Polymorphic&) 
Polymorphic{})));
+
+template
+struct X {
+  template void f();
+};
+template
+void f1() {
+  X dependent;
+  dependent.f();
+  // expected-error@-1 {{use 'template' keyword to treat 'f' as a dependent 
template name}}

Sirraide wrote:

Perhaps I’m just being a bit slow today, but it took me a few seconds to 
realise that this is testing *whether* the `noexcept(...)` is correctly marked 
as dependent here; imo that deserves a comment so whoever looks at this next 
doesn’t end up as confused as I was just now

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


[clang] [Clang] [Sema] Ensure noexcept(typeid(E)) checks if E throws when needed (PR #95846)

2024-06-19 Thread via cfe-commits

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

Alright, this does look like we’re handling all cases now (that I can think of 
at least).

However, I’d like to see some comments added to `f1`–`f3`, indicating why 
they’re dependent, because it took me a bit of thinking to figure that out just 
now...

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


[clang] [clang] [MinGW] Set a predefined __GXX_TYPEINFO_EQUALITY_INLINE=0 for… (PR #96062)

2024-06-19 Thread Martin Storsjö via cfe-commits

https://github.com/mstorsjo created 
https://github.com/llvm/llvm-project/pull/96062

… MinGW targets

libstdc++ requires this define to match what is predefined in GCC for the ABI 
of this platform; GCC hardcodes this define for all mingw configurations in 
gcc/config/i386/cygming.h.

(It also defines __GXX_MERGED_TYPEINFO_NAMES=0, but that happens to match the 
defaults in libstdc++ headers, so there's no similar need to define it in 
Clang.)

This fixes a Clang/libstdc++ interop issue discussed at 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110572.

From a0dc374a76d68179c2b7475a7d1e0e55f1622401 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= 
Date: Wed, 19 Jun 2024 14:34:12 +0300
Subject: [PATCH] [clang] [MinGW] Set a predefined
 __GXX_TYPEINFO_EQUALITY_INLINE=0 for MinGW targets

libstdc++ requires this define to match what is predefined in
GCC for the ABI of this platform; GCC hardcodes this define
for all mingw configurations in gcc/config/i386/cygming.h.

(It also defines __GXX_MERGED_TYPEINFO_NAMES=0, but that happens
to match the defaults in libstdc++ headers, so there's no similar
need to define it in Clang.)

This fixes a Clang/libstdc++ interop issue discussed at
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110572.
---
 clang/lib/Frontend/InitPreprocessor.cpp |  6 ++
 clang/test/Preprocessor/predefined-win-macros.c | 10 ++
 2 files changed, 16 insertions(+)

diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index e8c8a5175f8f4..2d20b56966186 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -926,6 +926,12 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
   if (LangOpts.GNUCVersion && LangOpts.CPlusPlus11)
 Builder.defineMacro("__GXX_EXPERIMENTAL_CXX0X__");
 
+  if (TI.getTriple().isWindowsGNUEnvironment() && LangOpts.CPlusPlus) {
+// Set ABI defining macros for libstdc++ for MinGW, where the
+// default in libstdc++ differs from the defaults for this target.
+Builder.defineMacro("__GXX_TYPEINFO_EQUALITY_INLINE", "0");
+  }
+
   if (LangOpts.ObjC) {
 if (LangOpts.ObjCRuntime.isNonFragile()) {
   Builder.defineMacro("__OBJC2__");
diff --git a/clang/test/Preprocessor/predefined-win-macros.c 
b/clang/test/Preprocessor/predefined-win-macros.c
index 14e2f584bd093..12e705875b123 100644
--- a/clang/test/Preprocessor/predefined-win-macros.c
+++ b/clang/test/Preprocessor/predefined-win-macros.c
@@ -163,3 +163,13 @@
 // CHECK-ARM64EC-MINGW: #define __arm64ec__ 1
 // CHECK-ARM64EC-MINGW: #define __x86_64 1
 // CHECK-ARM64EC-MINGW: #define __x86_64__ 1
+
+// RUN: %clang_cc1 -triple x86_64-windows-gnu %s -E -dM -o - \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-MINGW-C
+
+// CHECK-MINGW-C-NOT: #define __GXX_TYPEINFO_EQUALITY_INLINE
+
+// RUN: %clang_cc1 -triple x86_64-windows-gnu -x c++ %s -E -dM -o - \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-MINGW-CXX
+
+// CHECK-MINGW-CXX: #define __GXX_TYPEINFO_EQUALITY_INLINE 0

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


[clang] [clang] [MinGW] Set a predefined __GXX_TYPEINFO_EQUALITY_INLINE=0 for… (PR #96062)

2024-06-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Martin Storsjö (mstorsjo)


Changes

… MinGW targets

libstdc++ requires this define to match what is predefined in GCC for the ABI 
of this platform; GCC hardcodes this define for all mingw configurations in 
gcc/config/i386/cygming.h.

(It also defines __GXX_MERGED_TYPEINFO_NAMES=0, but that happens to match the 
defaults in libstdc++ headers, so there's no similar need to define it in 
Clang.)

This fixes a Clang/libstdc++ interop issue discussed at 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110572.

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


2 Files Affected:

- (modified) clang/lib/Frontend/InitPreprocessor.cpp (+6) 
- (modified) clang/test/Preprocessor/predefined-win-macros.c (+10) 


``diff
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index e8c8a5175f8f4..2d20b56966186 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -926,6 +926,12 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
   if (LangOpts.GNUCVersion && LangOpts.CPlusPlus11)
 Builder.defineMacro("__GXX_EXPERIMENTAL_CXX0X__");
 
+  if (TI.getTriple().isWindowsGNUEnvironment() && LangOpts.CPlusPlus) {
+// Set ABI defining macros for libstdc++ for MinGW, where the
+// default in libstdc++ differs from the defaults for this target.
+Builder.defineMacro("__GXX_TYPEINFO_EQUALITY_INLINE", "0");
+  }
+
   if (LangOpts.ObjC) {
 if (LangOpts.ObjCRuntime.isNonFragile()) {
   Builder.defineMacro("__OBJC2__");
diff --git a/clang/test/Preprocessor/predefined-win-macros.c 
b/clang/test/Preprocessor/predefined-win-macros.c
index 14e2f584bd093..12e705875b123 100644
--- a/clang/test/Preprocessor/predefined-win-macros.c
+++ b/clang/test/Preprocessor/predefined-win-macros.c
@@ -163,3 +163,13 @@
 // CHECK-ARM64EC-MINGW: #define __arm64ec__ 1
 // CHECK-ARM64EC-MINGW: #define __x86_64 1
 // CHECK-ARM64EC-MINGW: #define __x86_64__ 1
+
+// RUN: %clang_cc1 -triple x86_64-windows-gnu %s -E -dM -o - \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-MINGW-C
+
+// CHECK-MINGW-C-NOT: #define __GXX_TYPEINFO_EQUALITY_INLINE
+
+// RUN: %clang_cc1 -triple x86_64-windows-gnu -x c++ %s -E -dM -o - \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-MINGW-CXX
+
+// CHECK-MINGW-CXX: #define __GXX_TYPEINFO_EQUALITY_INLINE 0

``




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


[clang] [clang] [MinGW] Set a predefined __GXX_TYPEINFO_EQUALITY_INLINE=0 for… (PR #96062)

2024-06-19 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

CC @jwakely 

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


[clang] [llvm] [FMV] Rectify incomplete ExtensionInfo entries in TargetParser. (PR #89106)

2024-06-19 Thread Alexandros Lamprineas via cfe-commits

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


[clang] [llvm] [FMV] Rectify incomplete ExtensionInfo entries in TargetParser. (PR #89106)

2024-06-19 Thread Alexandros Lamprineas via cfe-commits

labrinea wrote:

This has become outdated after the recent tablegen refactoring. I'll rethink 
about it after https://github.com/llvm/llvm-project/pull/92882 lands

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


[clang] [llvm] [SystemZ][z/OS] __ptr32 support for z/OS in Clang (PR #96063)

2024-06-19 Thread Fanbo Meng via cfe-commits

https://github.com/fanbo-meng created 
https://github.com/llvm/llvm-project/pull/96063

Enabling __ptr32 keyword to support in Clang for z/OS. It is represented by 
addrspace(1) in LLVM IR. Unlike existing implementation, __ptr32 is not mangled 
into symbol names for z/OS.

>From 8852cfa1c035246d970f037866c2a6b290e27d43 Mon Sep 17 00:00:00 2001
From: Fanbo Meng 
Date: Sat, 21 Mar 2020 10:45:04 -0400
Subject: [PATCH] __ptr32 support for z/OS

Enabling __ptr32 support for z/OS in Clang.
---
 clang/include/clang/Basic/LangOptions.def |   1 +
 clang/include/clang/Basic/TokenKinds.def  |   3 +-
 clang/include/clang/Driver/Options.td |   4 +
 clang/lib/AST/ItaniumMangle.cpp   |   8 +-
 clang/lib/Basic/IdentifierTable.cpp   |  16 +-
 clang/lib/Basic/Targets/SystemZ.h |  43 ++-
 clang/lib/Frontend/CompilerInvocation.cpp |  11 +
 clang/lib/Sema/SemaType.cpp   |  11 +-
 clang/test/CodeGen/target-data.c  |   2 +-
 .../CodeGen/zos-mixed-ptr-sizes-definitions.c |  53 
 .../test/CodeGen/zos-mixed-ptr-sizes-malloc.c |  84 +
 .../test/CodeGen/zos-mixed-ptr-sizes-sizeof.c |  94 ++
 clang/test/CodeGen/zos-mixed-ptr-sizes.c  | 298 ++
 .../zos-mangle-ptr-size-address-space.cpp |  17 +
 clang/test/Sema/ZOSExtensions.cpp | 119 +++
 clang/test/Sema/attr-print-zos.c  |  31 ++
 .../Target/SystemZ/SystemZTargetMachine.cpp   |   8 +
 17 files changed, 792 insertions(+), 11 deletions(-)
 create mode 100644 clang/test/CodeGen/zos-mixed-ptr-sizes-definitions.c
 create mode 100644 clang/test/CodeGen/zos-mixed-ptr-sizes-malloc.c
 create mode 100644 clang/test/CodeGen/zos-mixed-ptr-sizes-sizeof.c
 create mode 100644 clang/test/CodeGen/zos-mixed-ptr-sizes.c
 create mode 100644 clang/test/CodeGenCXX/zos-mangle-ptr-size-address-space.cpp
 create mode 100644 clang/test/Sema/ZOSExtensions.cpp
 create mode 100644 clang/test/Sema/attr-print-zos.c

diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 2dea3cd4d795b..9f303b2f549bf 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -90,6 +90,7 @@ LANGOPT(C23   , 1, 0, "C23")
 LANGOPT(MSVCCompat, 1, 0, "Microsoft Visual C++ full compatibility 
mode")
 LANGOPT(Kernel, 1, 0, "Kernel mode")
 LANGOPT(MicrosoftExt  , 1, 0, "Microsoft C++ extensions")
+LANGOPT(ZOSExt, 1, 0, "z/OS extensions")
 LANGOPT(AsmBlocks , 1, 0, "Microsoft inline asm blocks")
 LANGOPT(Borland   , 1, 0, "Borland extensions")
 LANGOPT(CPlusPlus , 1, 0, "C++")
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 9c4b17465e18a..9717ecd6d7d66 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -286,6 +286,7 @@ PUNCTUATOR(caretcaret,"^^")
 //   CHAR8SUPPORT - This is a keyword if 'char8_t' is a built-in type
 //   KEYFIXEDPOINT - This is a keyword according to the N1169 fixed point
 //   extension.
+//   KEYZOS - This is a keyword in C/C++ on z/OS
 //
 KEYWORD(auto, KEYALL)
 KEYWORD(break   , KEYALL)
@@ -708,7 +709,7 @@ KEYWORD(__funcref , KEYALL)
 
 // Microsoft extensions which should be disabled in strict conformance mode
 KEYWORD(__ptr64   , KEYMS)
-KEYWORD(__ptr32   , KEYMS)
+KEYWORD(__ptr32   , KEYMS | KEYZOS)
 KEYWORD(__sptr, KEYMS)
 KEYWORD(__uptr, KEYMS)
 KEYWORD(__w64 , KEYMS)
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..e0ae29f881d9e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3038,6 +3038,10 @@ dll version.}]>;
 def fms_omit_default_lib : Joined<["-"], "fms-omit-default-lib">,
   Group, Flags<[]>,
   Visibility<[ClangOption, CLOption]>;
+def fzos_extensions : Flag<["-"], "fzos-extensions">, Group, 
Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Accept some non-standard constructs supported by the z/OS 
compiler">;
+def fno_zos_extensions : Flag<["-"], "fno-zos-extensions">, Group, 
Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Do not accept non-standard constructs supported by the z/OS 
compiler">;
 defm delayed_template_parsing : BoolFOption<"delayed-template-parsing",
   LangOpts<"DelayedTemplateParsing">, DefaultFalse,
   PosFlag ::= U 
 //::= U 
 
+llvm::Triple Triple = getASTContext().getTargetInfo().getTriple();
+
 SmallString<64> ASString;
 LangAS AS = Quals.getAddressSpace();
 
@@ -2796,7 +2798,11 @@ void CXXNameMangler::mangleQualifiers(Qualifiers Quals, 
const DependentAddressSp
 ASString = "ptr32_sptr";
 break;

[clang] [llvm] [SystemZ][z/OS] __ptr32 support for z/OS in Clang (PR #96063)

2024-06-19 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-systemz

@llvm/pr-subscribers-clang

Author: Fanbo Meng (fanbo-meng)


Changes

Enabling __ptr32 keyword to support in Clang for z/OS. It is represented by 
addrspace(1) in LLVM IR. Unlike existing implementation, __ptr32 is not mangled 
into symbol names for z/OS.

---

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


17 Files Affected:

- (modified) clang/include/clang/Basic/LangOptions.def (+1) 
- (modified) clang/include/clang/Basic/TokenKinds.def (+2-1) 
- (modified) clang/include/clang/Driver/Options.td (+4) 
- (modified) clang/lib/AST/ItaniumMangle.cpp (+7-1) 
- (modified) clang/lib/Basic/IdentifierTable.cpp (+12-4) 
- (modified) clang/lib/Basic/Targets/SystemZ.h (+42-1) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+11) 
- (modified) clang/lib/Sema/SemaType.cpp (+8-3) 
- (modified) clang/test/CodeGen/target-data.c (+1-1) 
- (added) clang/test/CodeGen/zos-mixed-ptr-sizes-definitions.c (+53) 
- (added) clang/test/CodeGen/zos-mixed-ptr-sizes-malloc.c (+84) 
- (added) clang/test/CodeGen/zos-mixed-ptr-sizes-sizeof.c (+94) 
- (added) clang/test/CodeGen/zos-mixed-ptr-sizes.c (+298) 
- (added) clang/test/CodeGenCXX/zos-mangle-ptr-size-address-space.cpp (+17) 
- (added) clang/test/Sema/ZOSExtensions.cpp (+119) 
- (added) clang/test/Sema/attr-print-zos.c (+31) 
- (modified) llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp (+8) 


``diff
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 2dea3cd4d795b..9f303b2f549bf 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -90,6 +90,7 @@ LANGOPT(C23   , 1, 0, "C23")
 LANGOPT(MSVCCompat, 1, 0, "Microsoft Visual C++ full compatibility 
mode")
 LANGOPT(Kernel, 1, 0, "Kernel mode")
 LANGOPT(MicrosoftExt  , 1, 0, "Microsoft C++ extensions")
+LANGOPT(ZOSExt, 1, 0, "z/OS extensions")
 LANGOPT(AsmBlocks , 1, 0, "Microsoft inline asm blocks")
 LANGOPT(Borland   , 1, 0, "Borland extensions")
 LANGOPT(CPlusPlus , 1, 0, "C++")
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 9c4b17465e18a..9717ecd6d7d66 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -286,6 +286,7 @@ PUNCTUATOR(caretcaret,"^^")
 //   CHAR8SUPPORT - This is a keyword if 'char8_t' is a built-in type
 //   KEYFIXEDPOINT - This is a keyword according to the N1169 fixed point
 //   extension.
+//   KEYZOS - This is a keyword in C/C++ on z/OS
 //
 KEYWORD(auto, KEYALL)
 KEYWORD(break   , KEYALL)
@@ -708,7 +709,7 @@ KEYWORD(__funcref , KEYALL)
 
 // Microsoft extensions which should be disabled in strict conformance mode
 KEYWORD(__ptr64   , KEYMS)
-KEYWORD(__ptr32   , KEYMS)
+KEYWORD(__ptr32   , KEYMS | KEYZOS)
 KEYWORD(__sptr, KEYMS)
 KEYWORD(__uptr, KEYMS)
 KEYWORD(__w64 , KEYMS)
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..e0ae29f881d9e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3038,6 +3038,10 @@ dll version.}]>;
 def fms_omit_default_lib : Joined<["-"], "fms-omit-default-lib">,
   Group, Flags<[]>,
   Visibility<[ClangOption, CLOption]>;
+def fzos_extensions : Flag<["-"], "fzos-extensions">, Group, 
Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Accept some non-standard constructs supported by the z/OS 
compiler">;
+def fno_zos_extensions : Flag<["-"], "fno-zos-extensions">, Group, 
Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Do not accept non-standard constructs supported by the z/OS 
compiler">;
 defm delayed_template_parsing : BoolFOption<"delayed-template-parsing",
   LangOpts<"DelayedTemplateParsing">, DefaultFalse,
   PosFlag ::= U 
 //::= U 
 
+llvm::Triple Triple = getASTContext().getTargetInfo().getTriple();
+
 SmallString<64> ASString;
 LangAS AS = Quals.getAddressSpace();
 
@@ -2796,7 +2798,11 @@ void CXXNameMangler::mangleQualifiers(Qualifiers Quals, 
const DependentAddressSp
 ASString = "ptr32_sptr";
 break;
   case LangAS::ptr32_uptr:
-ASString = "ptr32_uptr";
+// For z/OS, there are no special mangling rules applied to the ptr32
+// qualifier. Ex: void foo(int * __ptr32 p) -> _Z3f2Pi. The mangling 
for
+// "p" is treated the same as a regular integer pointer.
+if (!Triple.isOSzOS())
+  ASString = "ptr32_uptr";
 break;
   case LangAS::ptr64:
 ASString = "ptr64";
diff --git a/clang/lib/Basic/IdentifierTable.cpp 
b/clan

[clang] [clang-format] Add a new style for the clang-format source code (PR #69814)

2024-06-19 Thread Alexey Utkin via cfe-commits

alexey-utkin wrote:

Where is the documentation for the value? CLion reports `clang-format`  option 
as an error by the reason. No doc, no schema rule.

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


[clang] [llvm] [SystemZ][z/OS] __ptr32 support for z/OS in Clang (PR #96063)

2024-06-19 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 0c97ac0a46d0c29fbe5168adcd32e1f25336096d 
8852cfa1c035246d970f037866c2a6b290e27d43 --extensions 'h,cpp,c' -- 
clang/test/CodeGen/zos-mixed-ptr-sizes-definitions.c 
clang/test/CodeGen/zos-mixed-ptr-sizes-malloc.c 
clang/test/CodeGen/zos-mixed-ptr-sizes-sizeof.c 
clang/test/CodeGen/zos-mixed-ptr-sizes.c 
clang/test/CodeGenCXX/zos-mangle-ptr-size-address-space.cpp 
clang/test/Sema/ZOSExtensions.cpp clang/test/Sema/attr-print-zos.c 
clang/lib/AST/ItaniumMangle.cpp clang/lib/Basic/IdentifierTable.cpp 
clang/lib/Basic/Targets/SystemZ.h clang/lib/Frontend/CompilerInvocation.cpp 
clang/lib/Sema/SemaType.cpp clang/test/CodeGen/target-data.c 
llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Basic/IdentifierTable.cpp 
b/clang/lib/Basic/IdentifierTable.cpp
index ac7409c9b5..735aac0504 100644
--- a/clang/lib/Basic/IdentifierTable.cpp
+++ b/clang/lib/Basic/IdentifierTable.cpp
@@ -81,51 +81,51 @@ IdentifierTable::IdentifierTable(const LangOptions 
&LangOpts,
 // Constants for TokenKinds.def
 namespace {
 
-  enum TokenKey : unsigned {
-KEYC99= 0x1,
-KEYCXX= 0x2,
-KEYCXX11  = 0x4,
-KEYGNU= 0x8,
-KEYMS = 0x10,
-BOOLSUPPORT   = 0x20,
-KEYALTIVEC= 0x40,
-KEYNOCXX  = 0x80,
-KEYBORLAND= 0x100,
-KEYOPENCLC= 0x200,
-KEYC23= 0x400,
-KEYNOMS18 = 0x800,
-KEYNOOPENCL   = 0x1000,
-WCHARSUPPORT  = 0x2000,
-HALFSUPPORT   = 0x4000,
-CHAR8SUPPORT  = 0x8000,
-KEYOBJC   = 0x1,
-KEYZVECTOR= 0x2,
-KEYCOROUTINES = 0x4,
-KEYMODULES= 0x8,
-KEYCXX20  = 0x10,
-KEYOPENCLCXX  = 0x20,
-KEYMSCOMPAT   = 0x40,
-KEYSYCL   = 0x80,
-KEYCUDA   = 0x100,
-KEYZOS= 0x200,
-KEYNOZOS  = 0x400,
-KEYHLSL   = 0x800,
-KEYFIXEDPOINT = 0x1000,
-KEYMAX= KEYFIXEDPOINT, // The maximum key
-KEYALLCXX = KEYCXX | KEYCXX11 | KEYCXX20,
-KEYALL = (KEYMAX | (KEYMAX-1)) & ~KEYNOMS18 & ~KEYNOOPENCL &
- ~KEYNOZOS // KEYNOMS18, KEYNOOPENCL, KEYNOZOS are used to exclude.
-  };
-
-  /// How a keyword is treated in the selected standard. This enum is ordered
-  /// intentionally so that the value that 'wins' is the most 'permissive'.
-  enum KeywordStatus {
-KS_Unknown, // Not yet calculated. Used when figuring out the status.
-KS_Disabled,// Disabled
-KS_Future,  // Is a keyword in future standard
-KS_Extension,   // Is an extension
-KS_Enabled, // Enabled
-  };
+enum TokenKey : unsigned {
+  KEYC99 = 0x1,
+  KEYCXX = 0x2,
+  KEYCXX11 = 0x4,
+  KEYGNU = 0x8,
+  KEYMS = 0x10,
+  BOOLSUPPORT = 0x20,
+  KEYALTIVEC = 0x40,
+  KEYNOCXX = 0x80,
+  KEYBORLAND = 0x100,
+  KEYOPENCLC = 0x200,
+  KEYC23 = 0x400,
+  KEYNOMS18 = 0x800,
+  KEYNOOPENCL = 0x1000,
+  WCHARSUPPORT = 0x2000,
+  HALFSUPPORT = 0x4000,
+  CHAR8SUPPORT = 0x8000,
+  KEYOBJC = 0x1,
+  KEYZVECTOR = 0x2,
+  KEYCOROUTINES = 0x4,
+  KEYMODULES = 0x8,
+  KEYCXX20 = 0x10,
+  KEYOPENCLCXX = 0x20,
+  KEYMSCOMPAT = 0x40,
+  KEYSYCL = 0x80,
+  KEYCUDA = 0x100,
+  KEYZOS = 0x200,
+  KEYNOZOS = 0x400,
+  KEYHLSL = 0x800,
+  KEYFIXEDPOINT = 0x1000,
+  KEYMAX = KEYFIXEDPOINT, // The maximum key
+  KEYALLCXX = KEYCXX | KEYCXX11 | KEYCXX20,
+  KEYALL = (KEYMAX | (KEYMAX - 1)) & ~KEYNOMS18 & ~KEYNOOPENCL &
+   ~KEYNOZOS // KEYNOMS18, KEYNOOPENCL, KEYNOZOS are used to exclude.
+};
+
+/// How a keyword is treated in the selected standard. This enum is ordered
+/// intentionally so that the value that 'wins' is the most 'permissive'.
+enum KeywordStatus {
+  KS_Unknown,   // Not yet calculated. Used when figuring out the status.
+  KS_Disabled,  // Disabled
+  KS_Future,// Is a keyword in future standard
+  KS_Extension, // Is an extension
+  KS_Enabled,   // Enabled
+};
 
 } // namespace
 
@@ -237,7 +237,8 @@ static KeywordStatus getKeywordStatus(const LangOptions 
&LangOpts,
   if (LangOpts.MSVCCompat && (Flags & KEYNOMS18) &&
   !LangOpts.isCompatibleWithMSVC(LangOptions::MSVC2015))
 return KS_Disabled;
-  if (LangOpts.ZOSExt && (Flags & KEYNOZOS)) return KS_Disabled;
+  if (LangOpts.ZOSExt && (Flags & KEYNOZOS))
+return KS_Disabled;
 
   KeywordStatus CurStatus = KS_Unknown;
 

``




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


[clang] [llvm] [SystemZ][z/OS] __ptr32 support for z/OS in Clang (PR #96063)

2024-06-19 Thread Fanbo Meng via cfe-commits

https://github.com/fanbo-meng updated 
https://github.com/llvm/llvm-project/pull/96063

>From 8852cfa1c035246d970f037866c2a6b290e27d43 Mon Sep 17 00:00:00 2001
From: Fanbo Meng 
Date: Sat, 21 Mar 2020 10:45:04 -0400
Subject: [PATCH 1/2] __ptr32 support for z/OS

Enabling __ptr32 support for z/OS in Clang.
---
 clang/include/clang/Basic/LangOptions.def |   1 +
 clang/include/clang/Basic/TokenKinds.def  |   3 +-
 clang/include/clang/Driver/Options.td |   4 +
 clang/lib/AST/ItaniumMangle.cpp   |   8 +-
 clang/lib/Basic/IdentifierTable.cpp   |  16 +-
 clang/lib/Basic/Targets/SystemZ.h |  43 ++-
 clang/lib/Frontend/CompilerInvocation.cpp |  11 +
 clang/lib/Sema/SemaType.cpp   |  11 +-
 clang/test/CodeGen/target-data.c  |   2 +-
 .../CodeGen/zos-mixed-ptr-sizes-definitions.c |  53 
 .../test/CodeGen/zos-mixed-ptr-sizes-malloc.c |  84 +
 .../test/CodeGen/zos-mixed-ptr-sizes-sizeof.c |  94 ++
 clang/test/CodeGen/zos-mixed-ptr-sizes.c  | 298 ++
 .../zos-mangle-ptr-size-address-space.cpp |  17 +
 clang/test/Sema/ZOSExtensions.cpp | 119 +++
 clang/test/Sema/attr-print-zos.c  |  31 ++
 .../Target/SystemZ/SystemZTargetMachine.cpp   |   8 +
 17 files changed, 792 insertions(+), 11 deletions(-)
 create mode 100644 clang/test/CodeGen/zos-mixed-ptr-sizes-definitions.c
 create mode 100644 clang/test/CodeGen/zos-mixed-ptr-sizes-malloc.c
 create mode 100644 clang/test/CodeGen/zos-mixed-ptr-sizes-sizeof.c
 create mode 100644 clang/test/CodeGen/zos-mixed-ptr-sizes.c
 create mode 100644 clang/test/CodeGenCXX/zos-mangle-ptr-size-address-space.cpp
 create mode 100644 clang/test/Sema/ZOSExtensions.cpp
 create mode 100644 clang/test/Sema/attr-print-zos.c

diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 2dea3cd4d795b..9f303b2f549bf 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -90,6 +90,7 @@ LANGOPT(C23   , 1, 0, "C23")
 LANGOPT(MSVCCompat, 1, 0, "Microsoft Visual C++ full compatibility 
mode")
 LANGOPT(Kernel, 1, 0, "Kernel mode")
 LANGOPT(MicrosoftExt  , 1, 0, "Microsoft C++ extensions")
+LANGOPT(ZOSExt, 1, 0, "z/OS extensions")
 LANGOPT(AsmBlocks , 1, 0, "Microsoft inline asm blocks")
 LANGOPT(Borland   , 1, 0, "Borland extensions")
 LANGOPT(CPlusPlus , 1, 0, "C++")
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 9c4b17465e18a..9717ecd6d7d66 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -286,6 +286,7 @@ PUNCTUATOR(caretcaret,"^^")
 //   CHAR8SUPPORT - This is a keyword if 'char8_t' is a built-in type
 //   KEYFIXEDPOINT - This is a keyword according to the N1169 fixed point
 //   extension.
+//   KEYZOS - This is a keyword in C/C++ on z/OS
 //
 KEYWORD(auto, KEYALL)
 KEYWORD(break   , KEYALL)
@@ -708,7 +709,7 @@ KEYWORD(__funcref , KEYALL)
 
 // Microsoft extensions which should be disabled in strict conformance mode
 KEYWORD(__ptr64   , KEYMS)
-KEYWORD(__ptr32   , KEYMS)
+KEYWORD(__ptr32   , KEYMS | KEYZOS)
 KEYWORD(__sptr, KEYMS)
 KEYWORD(__uptr, KEYMS)
 KEYWORD(__w64 , KEYMS)
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..e0ae29f881d9e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3038,6 +3038,10 @@ dll version.}]>;
 def fms_omit_default_lib : Joined<["-"], "fms-omit-default-lib">,
   Group, Flags<[]>,
   Visibility<[ClangOption, CLOption]>;
+def fzos_extensions : Flag<["-"], "fzos-extensions">, Group, 
Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Accept some non-standard constructs supported by the z/OS 
compiler">;
+def fno_zos_extensions : Flag<["-"], "fno-zos-extensions">, Group, 
Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Do not accept non-standard constructs supported by the z/OS 
compiler">;
 defm delayed_template_parsing : BoolFOption<"delayed-template-parsing",
   LangOpts<"DelayedTemplateParsing">, DefaultFalse,
   PosFlag ::= U 
 //::= U 
 
+llvm::Triple Triple = getASTContext().getTargetInfo().getTriple();
+
 SmallString<64> ASString;
 LangAS AS = Quals.getAddressSpace();
 
@@ -2796,7 +2798,11 @@ void CXXNameMangler::mangleQualifiers(Qualifiers Quals, 
const DependentAddressSp
 ASString = "ptr32_sptr";
 break;
   case LangAS::ptr32_uptr:
-ASString = "ptr32_uptr";
+// For z/OS, there are no special mangling rules applied to the ptr32
+// qualifier. Ex: void foo(in

[clang] [llvm] [SystemZ][z/OS] __ptr32 support for z/OS in Clang (PR #96063)

2024-06-19 Thread Fanbo Meng via cfe-commits

fanbo-meng wrote:

code-formatter is complaining about the entire enum table. To be less 
pervasive, I'll not address that.

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


[clang-tools-extra] [clang][include-cleaner]skip stdlib recogntion only when there are defintion with body in main file. (PR #95797)

2024-06-19 Thread kadir çetinkaya via cfe-commits


@@ -39,20 +40,24 @@ Hints declHints(const Decl *D) {
 }
 
 std::vector> locateDecl(const Decl &D) {
-  std::vector> Result;
-  // FIXME: Should we also provide physical locations?
-  if (auto SS = tooling::stdlib::Recognizer()(&D)) {
-Result.push_back({*SS, Hints::CompleteSymbol});
-if (!D.hasBody())
-  return Result;
-  }
+  SourceManager &SM = D.getASTContext().getSourceManager();
+  bool HasBodyInMainFile = llvm::any_of(D.redecls(), [&](Decl *Redecl) {
+return Redecl->hasBody() && SM.isInMainFile(Redecl->getLocation());
+  });
+  // if decl has body and in main file, we don't need to do further search.
+  if (!HasBodyInMainFile)

kadircet wrote:

glad to hear that we're aligned here!

`decl in user written file > stdlib recognition > other found.` makes sense to 
me in theory, but i don't think it's implementable in practice. moreover i 
don't understand what the 3rd category around "other" means.

telling apart a "physical" stdlib header (e.g. `<__utility/pair.h>`) from a 
user header (e.g. ``) isn't possible. hence when something 
goes wrong, we'll always "insert" the wrong header (implementation detail, 
rather than public header for a stdlib symbol).

Hence I'd suggest going with:

1. "virtual" stdlib header (the one provided by 
`clang::tooling::stdlib::Header`)
2. any other physical location, providing the decl

This means we might do the wrong thing when the user has their own stdlib 
implementation (mixing your own symbols with standard library is a recipe for 
disaster, i don't think we need to care about that state). But we'll at least 
stop complaining once they include the "right" header. Moreover if need be we 
can improve handling for this case by turning of virtual stdlib support 
completely, when we detect we're working in an environment with a custom stdlib 
implementaiton.

WDYT?

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


[clang] Add flag to opt out of wasm-opt (PR #95208)

2024-06-19 Thread Quentin Michaud via cfe-commits

mh4ck-Thales wrote:

Any opinion on whether to implement a warning or not ?   

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


[clang-tools-extra] [clang-tidy] Clarify diagnostics of bugprone-sizeof-expression (PR #95550)

2024-06-19 Thread via cfe-commits

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


[clang-tools-extra] [clang-tidy] Clarify diagnostics of bugprone-sizeof-expression (PR #95550)

2024-06-19 Thread via cfe-commits

whisperity wrote:

(@NagyDonat FYI you have a typo in your commit message, but I think because of 
the squashing policy it will not matter too much.)

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


[clang-tools-extra] [clang-tidy] Clarify diagnostics of bugprone-sizeof-expression (PR #95550)

2024-06-19 Thread via cfe-commits

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


[clang] 6244d87 - Avoid object libraries in the VS IDE (#93519)

2024-06-19 Thread via cfe-commits

Author: Michael Kruse
Date: 2024-06-19T14:30:01+02:00
New Revision: 6244d87f42775e8d49cf758eeb1909f2ce144e3c

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

LOG: Avoid object libraries in the VS IDE (#93519)

As discussed in #89743, when using the Visual Studio solution
generators, object library projects are displayed as a collection of
non-editable *.obj files. To look for the corresponding source files,
one has to browse (or search) to the library's obj.libname project. This
patch tries to avoid this as much as possible.

For Clang, there is already an exception for XCode. We handle MSVC_IDE
the same way.

For MLIR, this is more complicated. There are explicit references to the
obj.libname target that only work when there is an object library. This
patch cleans up the reasons for why an object library is needed:

1. The obj.libname is modified in the calling CMakeLists.txt. Note that
with use-only references, `add_library( ALIAS )` could
have been used.

2. An `libMLIR.so` (mlir-shlib) is also created. This works by adding
linking the object libraries' object files into the libMLIR.so (in
addition to the library's own .so/.a). XCode is handled using the
`-force_load` linker option instead. Windows is not supported. This
mechanism is different from LLVM's llvm-shlib that is created by linking
static libraries with `-Wl,--whole-archive` (and `-Wl,-all_load` on
MacOS).

3. The library might be added to an aggregate library. In-tree, the
seems to be only `libMLIR-C.so` and the standalone example. In XCode, it
uses the object library and `-force_load` mechanism as above. Again,
this is different from `libLLVM-C.so`.

4. Build an object library whenever it was before this patch, except
when generating a Visual Studio solution. This condition could be
removed, but I am trying to avoid build breakages of whatever
configurations others use.

This seems to never have worked with XCode because of the explicit
references to obj.libname (reason 1.). I don't have access to XCode, but
I tried to preserve the current working. IMHO there should be a common
mechanism to build aggregate libraries for all LLVM projects instead of
the 4 that we have now.

As far as I can see, this means for LLVM there are the following changes
on whether object libraries are created:

1. An object library is created even in XCode if FORCE_OBJECT_LIBRARY is
set. I do not know how XCode handles it, but I also know CMake will
abort otherwise.

2. An object library is created even for explicitly SHARED libraries for
building `libMLIR.so`. Again, mlir-shlib does not work otherwise.
`libMLIR.so` itself is created using SHARED so this patch is marking it
as EXCLUDE_FROM_LIBMLIR.

3. For the second condition, it is now sensitive to whether the
mlir-shlib is built at all (LLVM_BUILD_LLVM_DYLIB). However, an object
library is still built using the fourth condition unless using the MSVC
solution generator. That is, except with MSVC_IDE, when an object
library was built before, it will also be an object library now.

Added: 


Modified: 
clang/cmake/modules/AddClang.cmake
clang/lib/Support/CMakeLists.txt
flang/cmake/modules/AddFlang.cmake
mlir/cmake/modules/AddMLIR.cmake
mlir/lib/Dialect/GPU/CMakeLists.txt
mlir/lib/Target/LLVM/CMakeLists.txt
mlir/tools/mlir-shlib/CMakeLists.txt

Removed: 




diff  --git a/clang/cmake/modules/AddClang.cmake 
b/clang/cmake/modules/AddClang.cmake
index a5ef639187d9d..9d09be1936847 100644
--- a/clang/cmake/modules/AddClang.cmake
+++ b/clang/cmake/modules/AddClang.cmake
@@ -96,8 +96,12 @@ macro(add_clang_library name)
 else()
   set(LIBTYPE STATIC)
 endif()
-if(NOT XCODE)
+if(NOT XCODE AND NOT MSVC_IDE)
   # The Xcode generator doesn't handle object libraries correctly.
+  # The Visual Studio CMake generator does handle object libraries
+  # correctly, but it is preferable to list the libraries with their
+  # source files (instead of the object files and the source files in
+  # a separate target in the "Object Libraries" folder)
   list(APPEND LIBTYPE OBJECT)
 endif()
 set_property(GLOBAL APPEND PROPERTY CLANG_STATIC_LIBS ${name})

diff  --git a/clang/lib/Support/CMakeLists.txt 
b/clang/lib/Support/CMakeLists.txt
index 8ea5620052ed8..de06271e914ae 100644
--- a/clang/lib/Support/CMakeLists.txt
+++ b/clang/lib/Support/CMakeLists.txt
@@ -15,7 +15,7 @@ set(clangSupport_sources
 
 add_clang_library(clangSupport ${clangSupport_sources})
 
-if (NOT XCODE)
+if (TARGET obj.clangSupport)
   add_library(clangSupport_tablegen ALIAS obj.clangSupport)
 elseif (NOT LLVM_LINK_LLVM_DYLIB)
   add_library(clangSupport_tablegen ALIAS clangSupport)

diff  --git a/flang/cmake/modules/AddFlang.cmake 
b/flang/cmake/modules/AddFlang.cmake
i

[clang] [flang] [mlir] Avoid object libraries in the VS IDE (PR #93519)

2024-06-19 Thread Michael Kruse via cfe-commits

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


[clang] [clang-tools-extra] [Clang] [Sema] Diagnose unknown std::initializer_list layout in SemaInit (PR #95580)

2024-06-19 Thread via cfe-commits

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


[clang] [clang-tools-extra] [Clang] [Sema] Diagnose unknown std::initializer_list layout in SemaInit (PR #95580)

2024-06-19 Thread via cfe-commits

https://github.com/Sirraide commented:

Moving this into Sema seems like a good idea to me. While we’re at it, we might 
also want to add a few additional checks for things that—from what I can 
tell—are currently not supported anyway.

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


[clang] [clang-tools-extra] [Clang] [Sema] Diagnose unknown std::initializer_list layout in SemaInit (PR #95580)

2024-06-19 Thread via cfe-commits


@@ -9392,6 +9392,57 @@ ExprResult InitializationSequence::Perform(Sema &S,
   // Wrap it in a construction of a std::initializer_list.
   CurInit = new (S.Context) CXXStdInitializerListExpr(Step->Type, MTE);
 
+  if (!Step->Type->isDependentType()) {
+assert(S.isCompleteType(CurInit.get()->getExprLoc(), Step->Type,
+Sema::CompleteTypeKind::Normal) &&
+   "std::initializer_list incomplete when used during "
+   "initialization");
+QualType ElementType;
+[[maybe_unused]] bool IsStdInitializerList =
+S.isStdInitializerList(Step->Type, &ElementType);
+assert(IsStdInitializerList &&
+   "StdInitializerList step to non-std::initializer_list");
+RecordDecl *Record = Step->Type->castAs()->getDecl();
+
+auto InvalidType = [&] {
+  S.Diag(Record->getLocation(),
+ diag::err_std_initializer_list_malformed)
+  << Step->Type.getUnqualifiedType();
+  return ExprError();
+};
+
+// FIXME: What if the initializer_list type has base classes, etc?

Sirraide wrote:

We should check for that here. I don’t think there is a point in allowing 
`std::initializer_list` have bases or be polymorphic.

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


[clang] [clang-tools-extra] [Clang] [Sema] Diagnose unknown std::initializer_list layout in SemaInit (PR #95580)

2024-06-19 Thread via cfe-commits


@@ -10528,48 +10528,37 @@ bool 
RecordExprEvaluator::VisitCXXStdInitializerListExpr(
   // Get a pointer to the first element of the array.
   Array.addArray(Info, E, ArrayType);
 
-  auto InvalidType = [&] {
-Info.FFDiag(E, diag::note_constexpr_unsupported_layout)
-  << E->getType();
-return false;
-  };
-
-  // FIXME: Perform the checks on the field types in SemaInit.
-  RecordDecl *Record = E->getType()->castAs()->getDecl();
-  RecordDecl::field_iterator Field = Record->field_begin();
-  if (Field == Record->field_end())
-return InvalidType();
-
-  // Start pointer.
-  if (!Field->getType()->isPointerType() ||
-  !Info.Ctx.hasSameType(Field->getType()->getPointeeType(),
-ArrayType->getElementType()))
-return InvalidType();
-
   // FIXME: What if the initializer_list type has base classes, etc?

Sirraide wrote:

```suggestion
```
We can remove this FIXME here (see also another comment of mine below).

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


[clang] [clang-tools-extra] [Clang] [Sema] Diagnose unknown std::initializer_list layout in SemaInit (PR #95580)

2024-06-19 Thread via cfe-commits


@@ -9392,6 +9392,57 @@ ExprResult InitializationSequence::Perform(Sema &S,
   // Wrap it in a construction of a std::initializer_list.
   CurInit = new (S.Context) CXXStdInitializerListExpr(Step->Type, MTE);
 
+  if (!Step->Type->isDependentType()) {
+assert(S.isCompleteType(CurInit.get()->getExprLoc(), Step->Type,
+Sema::CompleteTypeKind::Normal) &&
+   "std::initializer_list incomplete when used during "
+   "initialization");
+QualType ElementType;
+[[maybe_unused]] bool IsStdInitializerList =
+S.isStdInitializerList(Step->Type, &ElementType);
+assert(IsStdInitializerList &&
+   "StdInitializerList step to non-std::initializer_list");
+RecordDecl *Record = Step->Type->castAs()->getDecl();
+
+auto InvalidType = [&] {
+  S.Diag(Record->getLocation(),
+ diag::err_std_initializer_list_malformed)
+  << Step->Type.getUnqualifiedType();
+  return ExprError();
+};
+
+// FIXME: What if the initializer_list type has base classes, etc?
+if (Record->isUnion())
+  return InvalidType();
+
+RecordDecl::field_iterator Field = Record->field_begin();
+if (Field == Record->field_end())
+  return InvalidType();
+
+// Start pointer
+if (!Field->getType()->isPointerType() ||
+!S.Context.hasSameType(Field->getType()->getPointeeType(),
+   ElementType.withConst()))
+  return InvalidType();
+
+if (++Field == Record->field_end())
+  return InvalidType();
+
+// Size or end pointer
+if (Field->getType()->isPointerType()) {
+  if (!S.Context.hasSameType(Field->getType()->getPointeeType(),
+ ElementType.withConst()))
+return InvalidType();
+} else {
+  if (Field->isUnnamedBitField() ||

Sirraide wrote:

What about named bitfields? I think we should also be able to disallow 
bitfields outright here.

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


[clang] [clang-tools-extra] [Clang] [Sema] Diagnose unknown std::initializer_list layout in SemaInit (PR #95580)

2024-06-19 Thread via cfe-commits


@@ -9392,6 +9392,57 @@ ExprResult InitializationSequence::Perform(Sema &S,
   // Wrap it in a construction of a std::initializer_list.
   CurInit = new (S.Context) CXXStdInitializerListExpr(Step->Type, MTE);
 
+  if (!Step->Type->isDependentType()) {
+assert(S.isCompleteType(CurInit.get()->getExprLoc(), Step->Type,
+Sema::CompleteTypeKind::Normal) &&
+   "std::initializer_list incomplete when used during "
+   "initialization");

Sirraide wrote:

Not too familiar with SemaInit, but I’m assuming this condition is already 
diagnosed elsewhere?

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


[clang] [clang-tools-extra] [Clang] [Sema] Diagnose unknown std::initializer_list layout in SemaInit (PR #95580)

2024-06-19 Thread via cfe-commits


@@ -12216,6 +12216,9 @@ def err_std_source_location_impl_not_found : Error<
 def err_std_source_location_impl_malformed : Error<
   "'std::source_location::__impl' must be standard-layout and have only two 
'const char *' fields '_M_file_name' and '_M_function_name', and two integral 
fields '_M_line' and '_M_column'">;
 
+def err_std_initializer_list_malformed : Error<
+  "%0 layout not recognized. Must be a struct with two fields, a 'const E *' 
and either another 'const E *' or a 'std::size_t'">;

Sirraide wrote:

```suggestion
  "%0 layout not recognized. Must be a non-polymorphic class type with no bases 
and two fields: a 'const E *' and either another 'const E *' or a 
'std::size_t'">;
```
I do realise that we’re cramming quite a bit of information into this 
diagnostic here, but so does `err_std_source_location_impl_malformed`, and this 
is not a diagnostic anyone except for library implementers should ever see, so 
this is probably fine imo.

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


[clang] [clang-tools-extra] [Clang] [Sema] Diagnose unknown std::initializer_list layout in SemaInit (PR #95580)

2024-06-19 Thread via cfe-commits

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


[clang-tools-extra] [include-cleaner] don't consider the associated header unused (PR #67228)

2024-06-19 Thread Sam McCall via cfe-commits


@@ -227,6 +230,7 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
   IncludedHeader = *File;
 checkForExport(HashFID, HashLine, std::move(IncludedHeader), File);

sam-mccall wrote:

Nice catch, thanks!

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


[clang-tools-extra] [include-cleaner] don't consider the associated header unused (PR #67228)

2024-06-19 Thread Sam McCall via cfe-commits


@@ -379,6 +379,54 @@ TEST_F(PragmaIncludeTest, IWYUKeep) {
   EXPECT_TRUE(PI.shouldKeep(FM.getFile("std/set").get()));
 }
 
+TEST_F(PragmaIncludeTest, AssociatedHeader) {
+  createEmptyFiles({"foo/main.h", "bar/main.h", "bar/other.h", "std/vector"});
+  auto IsKeep = [&](llvm::StringRef Name, TestAST &AST) {
+return PI.shouldKeep(AST.fileManager().getFile(Name).get());
+  };
+
+  Inputs.FileName = "main.cc";
+  Inputs.ExtraArgs.push_back("-isystemstd");
+  {
+Inputs.Code = R"cpp(
+  #include "foo/main.h"
+  #include "bar/main.h"
+)cpp";
+auto AST = build();
+EXPECT_TRUE(IsKeep("foo/main.h", AST));
+EXPECT_FALSE(IsKeep("bar/main.h", AST)) << "not first include";
+  }
+
+  {
+Inputs.Code = R"cpp(
+  #include "bar/other.h"
+  #include "bar/main.h"
+)cpp";
+auto AST = build();
+EXPECT_FALSE(IsKeep("bar/other.h", AST));
+EXPECT_FALSE(IsKeep("bar/main.h", AST)) << "not first include";
+  }
+
+  {
+Inputs.Code = R"cpp(
+  #include "foo/main.h"
+  #include "bar/other.h" // IWYU pragma: associated
+)cpp";
+auto AST = build();
+EXPECT_TRUE(IsKeep("foo/main.h", AST));
+EXPECT_TRUE(IsKeep("bar/other.h", AST));
+  }
+
+  Inputs.FileName = "vector.cc";
+  {
+Inputs.Code = R"cpp(
+  #include 
+)cpp";
+auto AST = build();
+EXPECT_FALSE(IsKeep("std/vector", AST)) << "stdlib is never associated";

sam-mccall wrote:

sure, s/never/not/.

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


[clang] [Sema] Use llvm::erase_if (NFC) (PR #96068)

2024-06-19 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/96068

While I am at it, I'm constructing SmallVector directly from ArrayRef.

>From 85dd4232f6510055a536bd5f7f0ce21a06295dfd Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Wed, 19 Jun 2024 06:06:15 -0700
Subject: [PATCH] [Sema] Use llvm::erase_if (NFC)

While I am at it, I'm constructing SmallVector directly from ArrayRef.
---
 clang/lib/Sema/SemaOpenACC.cpp | 24 
 1 file changed, 8 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp
index 97586a037eee4..cf207be33175c 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -841,14 +841,10 @@ OpenACCClause 
*SemaOpenACCClauseVisitor::VisitAttachClause(
 
   // ActOnVar ensured that everything is a valid variable reference, but we
   // still have to make sure it is a pointer type.
-  llvm::SmallVector VarList{Clause.getVarList().begin(),
-Clause.getVarList().end()};
-  VarList.erase(std::remove_if(VarList.begin(), VarList.end(),
-   [&](Expr *E) {
- return SemaRef.CheckVarIsPointerType(
- OpenACCClauseKind::Attach, E);
-   }),
-VarList.end());
+  llvm::SmallVector VarList{Clause.getVarList()};
+  llvm::erase_if(VarList, [&](Expr *E) {
+return SemaRef.CheckVarIsPointerType(OpenACCClauseKind::Attach, E);
+  });
   Clause.setVarListDetails(VarList,
/*IsReadOnly=*/false, /*IsZero=*/false);
   return OpenACCAttachClause::Create(Ctx, Clause.getBeginLoc(),
@@ -866,14 +862,10 @@ OpenACCClause 
*SemaOpenACCClauseVisitor::VisitDevicePtrClause(
 
   // ActOnVar ensured that everything is a valid variable reference, but we
   // still have to make sure it is a pointer type.
-  llvm::SmallVector VarList{Clause.getVarList().begin(),
-Clause.getVarList().end()};
-  VarList.erase(std::remove_if(VarList.begin(), VarList.end(),
-   [&](Expr *E) {
- return SemaRef.CheckVarIsPointerType(
- OpenACCClauseKind::DevicePtr, E);
-   }),
-VarList.end());
+  llvm::SmallVector VarList{Clause.getVarList()};
+  llvm::erase_if(VarList, [&](Expr *E) {
+return SemaRef.CheckVarIsPointerType(OpenACCClauseKind::DevicePtr, E);
+  });
   Clause.setVarListDetails(VarList,
/*IsReadOnly=*/false, /*IsZero=*/false);
 

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


[clang-tools-extra] [include-cleaner] don't consider the associated header unused (PR #67228)

2024-06-19 Thread Sam McCall via cfe-commits


@@ -379,6 +379,54 @@ TEST_F(PragmaIncludeTest, IWYUKeep) {
   EXPECT_TRUE(PI.shouldKeep(FM.getFile("std/set").get()));
 }
 
+TEST_F(PragmaIncludeTest, AssociatedHeader) {
+  createEmptyFiles({"foo/main.h", "bar/main.h", "bar/other.h", "std/vector"});
+  auto IsKeep = [&](llvm::StringRef Name, TestAST &AST) {
+return PI.shouldKeep(AST.fileManager().getFile(Name).get());
+  };
+
+  Inputs.FileName = "main.cc";
+  Inputs.ExtraArgs.push_back("-isystemstd");
+  {
+Inputs.Code = R"cpp(
+  #include "foo/main.h"
+  #include "bar/main.h"
+)cpp";
+auto AST = build();
+EXPECT_TRUE(IsKeep("foo/main.h", AST));
+EXPECT_FALSE(IsKeep("bar/main.h", AST)) << "not first include";
+  }
+
+  {
+Inputs.Code = R"cpp(
+  #include "bar/other.h"
+  #include "bar/main.h"
+)cpp";
+auto AST = build();
+EXPECT_FALSE(IsKeep("bar/other.h", AST));
+EXPECT_FALSE(IsKeep("bar/main.h", AST)) << "not first include";
+  }
+
+  {
+Inputs.Code = R"cpp(
+  #include "foo/main.h"
+  #include "bar/other.h" // IWYU pragma: associated

sam-mccall wrote:

Sure. Combined this with a test that associated on stdlib headers is honored.

(As a bonus, I found that we were reusing PragmaIncludes across testcases, 
fixed that too!)

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


[clang] [Sema] Use llvm::erase_if (NFC) (PR #96068)

2024-06-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes

While I am at it, I'm constructing SmallVector directly from ArrayRef.

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


1 Files Affected:

- (modified) clang/lib/Sema/SemaOpenACC.cpp (+8-16) 


``diff
diff --git a/clang/lib/Sema/SemaOpenACC.cpp b/clang/lib/Sema/SemaOpenACC.cpp
index 97586a037eee4..cf207be33175c 100644
--- a/clang/lib/Sema/SemaOpenACC.cpp
+++ b/clang/lib/Sema/SemaOpenACC.cpp
@@ -841,14 +841,10 @@ OpenACCClause 
*SemaOpenACCClauseVisitor::VisitAttachClause(
 
   // ActOnVar ensured that everything is a valid variable reference, but we
   // still have to make sure it is a pointer type.
-  llvm::SmallVector VarList{Clause.getVarList().begin(),
-Clause.getVarList().end()};
-  VarList.erase(std::remove_if(VarList.begin(), VarList.end(),
-   [&](Expr *E) {
- return SemaRef.CheckVarIsPointerType(
- OpenACCClauseKind::Attach, E);
-   }),
-VarList.end());
+  llvm::SmallVector VarList{Clause.getVarList()};
+  llvm::erase_if(VarList, [&](Expr *E) {
+return SemaRef.CheckVarIsPointerType(OpenACCClauseKind::Attach, E);
+  });
   Clause.setVarListDetails(VarList,
/*IsReadOnly=*/false, /*IsZero=*/false);
   return OpenACCAttachClause::Create(Ctx, Clause.getBeginLoc(),
@@ -866,14 +862,10 @@ OpenACCClause 
*SemaOpenACCClauseVisitor::VisitDevicePtrClause(
 
   // ActOnVar ensured that everything is a valid variable reference, but we
   // still have to make sure it is a pointer type.
-  llvm::SmallVector VarList{Clause.getVarList().begin(),
-Clause.getVarList().end()};
-  VarList.erase(std::remove_if(VarList.begin(), VarList.end(),
-   [&](Expr *E) {
- return SemaRef.CheckVarIsPointerType(
- OpenACCClauseKind::DevicePtr, E);
-   }),
-VarList.end());
+  llvm::SmallVector VarList{Clause.getVarList()};
+  llvm::erase_if(VarList, [&](Expr *E) {
+return SemaRef.CheckVarIsPointerType(OpenACCClauseKind::DevicePtr, E);
+  });
   Clause.setVarListDetails(VarList,
/*IsReadOnly=*/false, /*IsZero=*/false);
 

``




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


[clang] [clang][analyzer] Add notes to PointerSubChecker (PR #95899)

2024-06-19 Thread Balázs Kéri via cfe-commits

https://github.com/balazske updated 
https://github.com/llvm/llvm-project/pull/95899

From 1eb6e7ebde0e97e1cd077dc27ffd3ebd6ed0e93d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Tue, 18 Jun 2024 10:09:24 +0200
Subject: [PATCH 1/3] [clang][analyzer] Add notes to PointerSubChecker

Notes are added to indicate the array declarations of the
arrays in a found invalid pointer subtraction.
---
 .../Checkers/PointerSubChecker.cpp| 45 ---
 clang/test/Analysis/pointer-sub-notes.c   | 34 ++
 2 files changed, 64 insertions(+), 15 deletions(-)
 create mode 100644 clang/test/Analysis/pointer-sub-notes.c

diff --git a/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp
index b73534136fdf0..a983e66df0818 100644
--- a/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp
@@ -43,8 +43,6 @@ class PointerSubChecker
   bool checkArrayBounds(CheckerContext &C, const Expr *E,
 const ElementRegion *ElemReg,
 const MemRegion *Reg) const;
-  void reportBug(CheckerContext &C, const Expr *E,
- const llvm::StringLiteral &Msg) const;
 
 public:
   void checkPreStmt(const BinaryOperator *B, CheckerContext &C) const;
@@ -57,6 +55,14 @@ bool PointerSubChecker::checkArrayBounds(CheckerContext &C, 
const Expr *E,
   if (!ElemReg)
 return true;
 
+  auto ReportBug = [&](const llvm::StringLiteral &Msg) {
+if (ExplodedNode *N = C.generateNonFatalErrorNode()) {
+  auto R = std::make_unique(BT, Msg, N);
+  R->addRange(E->getSourceRange());
+  C.emitReport(std::move(R));
+}
+  };
+
   ProgramStateRef State = C.getState();
   const MemRegion *SuperReg = ElemReg->getSuperRegion();
   SValBuilder &SVB = C.getSValBuilder();
@@ -64,7 +70,7 @@ bool PointerSubChecker::checkArrayBounds(CheckerContext &C, 
const Expr *E,
   if (SuperReg == Reg) {
 if (const llvm::APSInt *I = SVB.getKnownValue(State, ElemReg->getIndex());
 I && (!I->isOne() && !I->isZero()))
-  reportBug(C, E, Msg_BadVarIndex);
+  ReportBug(Msg_BadVarIndex);
 return false;
   }
 
@@ -77,7 +83,7 @@ bool PointerSubChecker::checkArrayBounds(CheckerContext &C, 
const Expr *E,
 ProgramStateRef S1, S2;
 std::tie(S1, S2) = C.getState()->assume(*IndexTooLarge);
 if (S1 && !S2) {
-  reportBug(C, E, Msg_LargeArrayIndex);
+  ReportBug(Msg_LargeArrayIndex);
   return false;
 }
   }
@@ -89,22 +95,13 @@ bool PointerSubChecker::checkArrayBounds(CheckerContext &C, 
const Expr *E,
 ProgramStateRef S1, S2;
 std::tie(S1, S2) = State->assume(*IndexTooSmall);
 if (S1 && !S2) {
-  reportBug(C, E, Msg_NegativeArrayIndex);
+  ReportBug(Msg_NegativeArrayIndex);
   return false;
 }
   }
   return true;
 }
 
-void PointerSubChecker::reportBug(CheckerContext &C, const Expr *E,
-  const llvm::StringLiteral &Msg) const {
-  if (ExplodedNode *N = C.generateNonFatalErrorNode()) {
-auto R = std::make_unique(BT, Msg, N);
-R->addRange(E->getSourceRange());
-C.emitReport(std::move(R));
-  }
-}
-
 void PointerSubChecker::checkPreStmt(const BinaryOperator *B,
  CheckerContext &C) const {
   // When doing pointer subtraction, if the two pointers do not point to the
@@ -136,6 +133,9 @@ void PointerSubChecker::checkPreStmt(const BinaryOperator 
*B,
   if (!checkArrayBounds(C, B->getRHS(), ElemRR, LR))
 return;
 
+  const ValueDecl *DiffDeclL = nullptr;
+  const ValueDecl *DiffDeclR = nullptr;
+
   if (ElemLR && ElemRR) {
 const MemRegion *SuperLR = ElemLR->getSuperRegion();
 const MemRegion *SuperRR = ElemRR->getSuperRegion();
@@ -144,9 +144,24 @@ void PointerSubChecker::checkPreStmt(const BinaryOperator 
*B,
 // Allow arithmetic on different symbolic regions.
 if (isa(SuperLR) || isa(SuperRR))
   return;
+if (const auto *SuperDLR = dyn_cast(SuperLR))
+  DiffDeclL = SuperDLR->getDecl();
+if (const auto *SuperDRR = dyn_cast(SuperRR))
+  DiffDeclR = SuperDRR->getDecl();
   }
 
-  reportBug(C, B, Msg_MemRegionDifferent);
+  if (ExplodedNode *N = C.generateNonFatalErrorNode()) {
+auto R =
+std::make_unique(BT, Msg_MemRegionDifferent, 
N);
+R->addRange(B->getSourceRange());
+if (DiffDeclL)
+  R->addNote("Array at the left-hand side of subtraction",
+ {DiffDeclL, C.getSourceManager()});
+if (DiffDeclR)
+  R->addNote("Array at the right-hand side of subtraction",
+ {DiffDeclR, C.getSourceManager()});
+C.emitReport(std::move(R));
+  }
 }
 
 void ento::registerPointerSubChecker(CheckerManager &mgr) {
diff --git a/clang/test/Analysis/pointer-sub-notes.c 
b/clang/test/Analysis/pointer-sub-notes.c
new file mode 100644
index 0..dfdace3a58deb
--- /dev/null
+++ b/clang/test/Analysis/poin

[clang] [llvm] [LLVM] Add InsertPosition union-type to remove overloads of Instruction-creation (PR #94226)

2024-06-19 Thread Nikita Popov via cfe-commits

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


[clang] [llvm] [LLVM] Add InsertPosition union-type to remove overloads of Instruction-creation (PR #94226)

2024-06-19 Thread Nikita Popov via cfe-commits

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

Thanks for doing this, LGTM!

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


[clang] [llvm] [LLVM] Add InsertPosition union-type to remove overloads of Instruction-creation (PR #94226)

2024-06-19 Thread Nikita Popov via cfe-commits


@@ -63,10 +63,10 @@ class IRBuilderDefaultInserter {
   virtual ~IRBuilderDefaultInserter();
 
   virtual void InsertHelper(Instruction *I, const Twine &Name,
-BasicBlock *BB,
 BasicBlock::iterator InsertPt) const {
-if (BB)
-  I->insertInto(BB, InsertPt);
+if (InsertPt.isValid()) {
+  I->insertInto(InsertPt.getNodeParent(), InsertPt);

nikic wrote:

We should drop the BasicBlock argument from this API now, but that can be a 
followup...

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


[clang] [llvm] [LLVM] Add InsertPosition union-type to remove overloads of Instruction-creation (PR #94226)

2024-06-19 Thread Nikita Popov via cfe-commits


@@ -1460,56 +1184,29 @@ static Value *getAISize(LLVMContext &Context, Value 
*Amt) {
   return Amt;
 }
 
-static Align computeAllocaDefaultAlign(Type *Ty, BasicBlock *BB) {
-  assert(BB && "Insertion BB cannot be null when alignment not provided!");
+static Align computeAllocaDefaultAlign(Type *Ty, InsertPosition Pos) {
+  assert(Pos.IsValid() &&
+ "Insertion position cannot be null when alignment not provided!");
+  BasicBlock *BB = ((BasicBlock::iterator)Pos).getNodeParent();

nikic wrote:

Maybe add a getParent() method on InsertPosition?

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


[clang] [llvm] [LLVM] Add InsertPosition union-type to remove overloads of Instruction-creation (PR #94226)

2024-06-19 Thread Nikita Popov via cfe-commits


@@ -120,7 +120,8 @@ llvm::AllocaInst 
*CodeGenFunction::CreateTempAlloca(llvm::Type *Ty,
 Alloca = Builder.CreateAlloca(Ty, ArraySize, Name);
   else
 Alloca = new llvm::AllocaInst(Ty, CGM.getDataLayout().getAllocaAddrSpace(),
-  ArraySize, Name, AllocaInsertPt);
+  ArraySize, Name,
+  (llvm::Instruction *)AllocaInsertPt);

nikic wrote:

```suggestion
  &*AllocaInsertPt);
```
Does something like this work instead?

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


[clang] [llvm] [LLVM] Add InsertPosition union-type to remove overloads of Instruction-creation (PR #94226)

2024-06-19 Thread Nikita Popov via cfe-commits


@@ -44,6 +44,23 @@ template <> struct ilist_alloc_traits {
 iterator_range::iterator>
 getDbgRecordRange(DbgMarker *);
 
+class InsertPosition {
+  using InstListType = SymbolTableList,
+   ilist_parent>;
+  InstListType::iterator InsertAt;
+
+public:
+  InsertPosition(std::nullopt_t) : InsertAt() {}
+  InsertPosition(std::nullptr_t) : InsertAt() {}
+  // LLVM_DEPRECATED("Use BasicBlock::iterators for insertion instead",
+  // "BasicBlock::iterator")
+  InsertPosition(Instruction *InsertBefore);
+  InsertPosition(BasicBlock *InsertAtEnd);
+  InsertPosition(InstListType::iterator InsertAt) : InsertAt(InsertAt) {}
+  operator InstListType::iterator() const { return InsertAt; }
+  bool IsValid() const { return InsertAt.getNodePtr(); }

nikic wrote:

I think you added an isValid() method to the iterator itself?

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


[clang] [llvm] [LLVM] Add InsertPosition union-type to remove overloads of Instruction-creation (PR #94226)

2024-06-19 Thread Nikita Popov via cfe-commits


@@ -63,10 +63,10 @@ class IRBuilderDefaultInserter {
   virtual ~IRBuilderDefaultInserter();
 
   virtual void InsertHelper(Instruction *I, const Twine &Name,
-BasicBlock *BB,
 BasicBlock::iterator InsertPt) const {
-if (BB)
-  I->insertInto(BB, InsertPt);
+if (InsertPt.isValid()) {

nikic wrote:

Drop braces.

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


[clang-tools-extra] [include-cleaner] don't consider the associated header unused (PR #67228)

2024-06-19 Thread Sam McCall via cfe-commits

sam-mccall wrote:

Apologies & thanks all for the pings.
I unfortunately won't be active on llvm-project for a while (other work 
commitments), but I can get this landed.

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


[clang] [Clang][AArch64] Expose compatible SVE intrinsics with only +sme (PR #95787)

2024-06-19 Thread Sander de Smalen via cfe-commits


@@ -286,10 +290,13 @@ let TargetGuard = "sve,f64mm,bf16" in {
 }
 
 let TargetGuard = "sve,bf16" in {
+  def SVBFMMLA   : SInst<"svbfmmla[_{0}]",   "MMdd",  "b", MergeNone, 
"aarch64_sve_bfmmla",   [IsOverloadNone]>;
+}
+
+let TargetGuard = "(sve,bf16)|sme" in {

sdesmalen-arm wrote:

> Looking at the specification suggests this should be (sve|sme),bf16?

`+sme` implies `+bf16`, so this is equivalent, although I guess that when 
modelling it with `(sve,bf16)|sme`, Clang would still accept the builtin with 
`+sme,+nobf16`, even though LLVM will fail to select.

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


[clang] [Clang][AArch64] Expose compatible SVE intrinsics with only +sme (PR #95787)

2024-06-19 Thread Sander de Smalen via cfe-commits


@@ -2264,6 +2278,18 @@ let TargetGuard = "sve2p1" in {
   defm SVPMOV_TO_VEC_LANE_D : PMOV_TO_VEC<"svpmov", "lUl", 
"aarch64_sve_pmov_to_vector_lane" ,[], ImmCheck1_7>;
 }
 
+let TargetGuard = "sve2p1|sme2" in {

sdesmalen-arm wrote:

Good spot!

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


[clang] [Clang][AArch64] Expose compatible SVE intrinsics with only +sme (PR #95787)

2024-06-19 Thread Sander de Smalen via cfe-commits


@@ -1781,7 +1781,12 @@ void SVEEmitter::createStreamingAttrs(raw_ostream &OS, 
ACLEKind Kind) {
   uint64_t VerifyRuntimeMode = getEnumValueForFlag("VerifyRuntimeMode");
   uint64_t IsStreamingCompatibleFlag =
   getEnumValueForFlag("IsStreamingCompatible");
+
   for (auto &Def : Defs) {
+assertDef->getGuard().contains("sve") +
+  Def->getGuard().contains("sme")) <= 1) ||
+Def->isFlagSet(VerifyRuntimeMode)) &&

sdesmalen-arm wrote:

Yes that makes sense. Done.

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


[clang] [clang] Change style of superseded issues on C++ DR status page (PR #96051)

2024-06-19 Thread via cfe-commits

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


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


[clang] [llvm] [SystemZ][z/OS] __ptr32 support for z/OS in Clang (PR #96063)

2024-06-19 Thread Zibi Sarbinowski via cfe-commits


@@ -107,12 +107,14 @@ namespace {
 KEYMSCOMPAT   = 0x40,
 KEYSYCL   = 0x80,
 KEYCUDA   = 0x100,
-KEYHLSL   = 0x200,
-KEYFIXEDPOINT = 0x400,
+KEYZOS= 0x200,
+KEYNOZOS  = 0x400,
+KEYHLSL   = 0x800,
+KEYFIXEDPOINT = 0x1000,
 KEYMAX= KEYFIXEDPOINT, // The maximum key
 KEYALLCXX = KEYCXX | KEYCXX11 | KEYCXX20,
-KEYALL = (KEYMAX | (KEYMAX-1)) & ~KEYNOMS18 &
- ~KEYNOOPENCL // KEYNOMS18 and KEYNOOPENCL are used to exclude.
+KEYALL = (KEYMAX | (KEYMAX-1)) & ~KEYNOMS18 & ~KEYNOOPENCL &
+ ~KEYNOZOS // KEYNOMS18, KEYNOOPENCL, KEYNOZOS are used to exclude.

zibi2 wrote:

```suggestion
 ~KEYNOZOS // KEYNOMS18, KEYNOOPENCL, KEYNOZOS are excluded.
```

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


[clang] [clang][analyzer] Add notes to PointerSubChecker (PR #95899)

2024-06-19 Thread Balázs Kéri via cfe-commits


@@ -144,9 +144,24 @@ void PointerSubChecker::checkPreStmt(const BinaryOperator 
*B,
 // Allow arithmetic on different symbolic regions.
 if (isa(SuperLR) || isa(SuperRR))
   return;
+if (const auto *SuperDLR = dyn_cast(SuperLR))
+  DiffDeclL = SuperDLR->getDecl();
+if (const auto *SuperDRR = dyn_cast(SuperRR))
+  DiffDeclR = SuperDRR->getDecl();

balazske wrote:

Warning is now omitted if both would be at the same declaration.

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


[clang-tools-extra] [include-cleaner] don't consider the associated header unused (PR #67228)

2024-06-19 Thread Sam McCall via cfe-commits

https://github.com/sam-mccall updated 
https://github.com/llvm/llvm-project/pull/67228

>From a736ebb34a31fa0fd1c21a4f03c88d63856fb998 Mon Sep 17 00:00:00 2001
From: Sam McCall 
Date: Sat, 23 Sep 2023 10:44:30 +0200
Subject: [PATCH] [include-cleaner] don't consider the associated header unused

Loosely, the "associated header" of `foo.cpp` is `foo.h`.
It should be included, many styles include it first.

So far we haven't special cased it in any way, and require this include
to be justified. e.g. if foo.cpp defines a function declared in foo.h,
then the #include is allowed to check these declarations match.

However this doesn't really align with what users want:
- people reasonably want to include the associated header for the
  side-effect of validating that it compiles.
  In the degenerate case, `lib.cpp`is just `#include "lib.h"` (see bug)
- That `void foo(){}` IWYU-uses `void foo();` is a bit artificial, and
  most users won't internalize this. Instead they'll stick with the
  simpler model "include the header that defines your API".
  In the rare cases where these give different answers[1], our current
  behavior is a puzzling special case from the user POV.
  It is more user-friendly to accept both models.
- even where this diagnostic is a true positive (defs don't match header
  decls) the diagnostic does not communicate this usefully.

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

[1] Example of an associated header that's not IWYU-used:
```
// http.h
inline URL buildHttpURL(string host, int port, string path) {
  return "http://"; + host + ":" + port + "/" + path;
}
// http.cpp
class HTTPURLHandler : URLHandler { ... };
REGISTER_URL_HANDLER("http", HTTPURLHandler);
```
---
 .../include-cleaner/lib/Record.cpp| 36 ++-
 .../include-cleaner/unittests/RecordTest.cpp  | 59 ++-
 2 files changed, 89 insertions(+), 6 deletions(-)

diff --git a/clang-tools-extra/include-cleaner/lib/Record.cpp 
b/clang-tools-extra/include-cleaner/lib/Record.cpp
index 78a4df6cc40ea..6b5be956ec108 100644
--- a/clang-tools-extra/include-cleaner/lib/Record.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -34,6 +34,7 @@
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileSystem/UniqueID.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/StringSaver.h"
 #include 
 #include 
@@ -180,7 +181,9 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
   RecordPragma(const Preprocessor &P, PragmaIncludes *Out)
   : SM(P.getSourceManager()), HeaderInfo(P.getHeaderSearchInfo()), 
Out(Out),
 Arena(std::make_shared()),
-UniqueStrings(*Arena) {}
+UniqueStrings(*Arena),
+MainFileStem(llvm::sys::path::stem(
+SM.getNonBuiltinFilenameForID(SM.getMainFileID()).value_or(""))) {}
 
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
@@ -228,8 +231,9 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
   }
 if (!IncludedHeader && File)
   IncludedHeader = *File;
-checkForExport(HashFID, HashLine, std::move(IncludedHeader), File);
+checkForExport(HashFID, HashLine, IncludedHeader, File);
 checkForKeep(HashLine, File);
+checkForDeducedAssociated(IncludedHeader);
   }
 
   void checkForExport(FileID IncludingFile, int HashLine,
@@ -269,6 +273,27 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
   KeepStack.pop_back(); // Pop immediately for single-line keep pragma.
   }
 
+  // Consider marking H as the "associated header" of the main file.
+  //
+  // Our heuristic:
+  // - it must be the first #include in the main file
+  // - it must have the same name stem as the main file (foo.h and foo.cpp)
+  // (IWYU pragma: associated is also supported, just not by this function).
+  //
+  // We consider the associated header as if it had a keep pragma.
+  // (Unlike IWYU, we don't treat #includes inside the associated header as if
+  // they were written in the main file.)
+  void checkForDeducedAssociated(std::optional H) {
+namespace path = llvm::sys::path;
+if (!InMainFile || SeenAssociatedCandidate)
+  return;
+SeenAssociatedCandidate = true; // Only the first #include is our 
candidate.
+if (!H || H->kind() != Header::Physical)
+  return;
+if (path::stem(H->physical().getName(), path::Style::posix) == 
MainFileStem)
+  Out->ShouldKeep.insert(H->physical().getUniqueID());
+  }
+
   bool HandleComment(Preprocessor &PP, SourceRange Range) override {
 auto &SM = PP.getSourceManager();
 auto Pragma =
@@ -280,7 +305,9 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
 int CommentLine = SM.getLineNumber(CommentFID, CommentOffset);
 
 if (InMainFile) {
-  if (Pragma->starts_with("keep")) {
+  if (Pragma->starts_with

[clang] [clang-format][doc] Add clarification to `PointerAlignment` (PR #96069)

2024-06-19 Thread Eberhard Beilharz via cfe-commits

https://github.com/ermshiperete created 
https://github.com/llvm/llvm-project/pull/96069

Clarify that `PointerAlignment` is not used if `DerivePointerAlignment` is set 
to `true`. So far this was only mentioned under `DerivePointerAlignment` which 
could lead to confusion if someone only looked at `PointerAlignment`.

>From f4e7548b94015854173030a0144f35ba9491757e Mon Sep 17 00:00:00 2001
From: Eberhard Beilharz 
Date: Wed, 19 Jun 2024 15:27:22 +0200
Subject: [PATCH] [clang-format][doc] Add clarification to `PointerAlignment`

Clarify that `PointerAlignment` is not used if `DerivePointerAlignment` is set 
to `true`. So far this was only mentioned under `DerivePointerAlignment` which 
could lead to confusion if someone only looked at `PointerAlignment`.
---
 clang/docs/ClangFormatStyleOptions.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index bb00c20922d36..a58ba93b41bf8 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -5015,7 +5015,7 @@ the configuration (without a prefix: ``Auto``).
 .. _PointerAlignment:
 
 **PointerAlignment** (``PointerAlignmentStyle``) :versionbadge:`clang-format 
3.7` :ref:`¶ `
-  Pointer and reference alignment style.
+  Pointer and reference alignment style. Only used if 
``DerivePointerAlignment`` is not ``true``.
 
   Possible values:
 

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


[clang-tools-extra] [include-cleaner] don't consider the associated header unused (PR #67228)

2024-06-19 Thread Sam McCall via cfe-commits

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


[clang-tools-extra] 5574a58 - [include-cleaner] don't consider the associated header unused (#67228)

2024-06-19 Thread via cfe-commits

Author: Sam McCall
Date: 2024-06-19T15:29:05+02:00
New Revision: 5574a5894fdb7f9a46a4fbe6c8970fd39890dc9b

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

LOG: [include-cleaner] don't consider the associated header unused (#67228)


Loosely, the "associated header" of `foo.cpp` is `foo.h`.
It should be included, many styles include it first.

So far we haven't special cased it in any way, and require this include
to be justified. e.g. if foo.cpp defines a function declared in foo.h,
then the #include is allowed to check these declarations match.

However this doesn't really align with what users want:
- people reasonably want to include the associated header for the
  side-effect of validating that it compiles.
  In the degenerate case, `lib.cpp`is just `#include "lib.h"` (see bug)
- That `void foo(){}` IWYU-uses `void foo();` is a bit artificial, and
  most users won't internalize this. Instead they'll stick with the
  simpler model "include the header that defines your API".
  In the rare cases where these give different answers[1], our current
  behavior is a puzzling special case from the user POV.
  It is more user-friendly to accept both models.
- even where this diagnostic is a true positive (defs don't match header
  decls) the diagnostic does not communicate this usefully.

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

[1] Example of an associated header that's not IWYU-used:
```
// http.h
inline URL buildHttpURL(string host, int port, string path) {
  return "http://"; + host + ":" + port + "/" + path;
}
// http.cpp
class HTTPURLHandler : URLHandler { ... };
REGISTER_URL_HANDLER("http", HTTPURLHandler);
```

Added: 


Modified: 
clang-tools-extra/include-cleaner/lib/Record.cpp
clang-tools-extra/include-cleaner/unittests/RecordTest.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/lib/Record.cpp 
b/clang-tools-extra/include-cleaner/lib/Record.cpp
index 78a4df6cc40ea..6b5be956ec108 100644
--- a/clang-tools-extra/include-cleaner/lib/Record.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -34,6 +34,7 @@
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileSystem/UniqueID.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/StringSaver.h"
 #include 
 #include 
@@ -180,7 +181,9 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
   RecordPragma(const Preprocessor &P, PragmaIncludes *Out)
   : SM(P.getSourceManager()), HeaderInfo(P.getHeaderSearchInfo()), 
Out(Out),
 Arena(std::make_shared()),
-UniqueStrings(*Arena) {}
+UniqueStrings(*Arena),
+MainFileStem(llvm::sys::path::stem(
+SM.getNonBuiltinFilenameForID(SM.getMainFileID()).value_or(""))) {}
 
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
@@ -228,8 +231,9 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
   }
 if (!IncludedHeader && File)
   IncludedHeader = *File;
-checkForExport(HashFID, HashLine, std::move(IncludedHeader), File);
+checkForExport(HashFID, HashLine, IncludedHeader, File);
 checkForKeep(HashLine, File);
+checkForDeducedAssociated(IncludedHeader);
   }
 
   void checkForExport(FileID IncludingFile, int HashLine,
@@ -269,6 +273,27 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
   KeepStack.pop_back(); // Pop immediately for single-line keep pragma.
   }
 
+  // Consider marking H as the "associated header" of the main file.
+  //
+  // Our heuristic:
+  // - it must be the first #include in the main file
+  // - it must have the same name stem as the main file (foo.h and foo.cpp)
+  // (IWYU pragma: associated is also supported, just not by this function).
+  //
+  // We consider the associated header as if it had a keep pragma.
+  // (Unlike IWYU, we don't treat #includes inside the associated header as if
+  // they were written in the main file.)
+  void checkForDeducedAssociated(std::optional H) {
+namespace path = llvm::sys::path;
+if (!InMainFile || SeenAssociatedCandidate)
+  return;
+SeenAssociatedCandidate = true; // Only the first #include is our 
candidate.
+if (!H || H->kind() != Header::Physical)
+  return;
+if (path::stem(H->physical().getName(), path::Style::posix) == 
MainFileStem)
+  Out->ShouldKeep.insert(H->physical().getUniqueID());
+  }
+
   bool HandleComment(Preprocessor &PP, SourceRange Range) override {
 auto &SM = PP.getSourceManager();
 auto Pragma =
@@ -280,7 +305,9 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
 int CommentLine = SM.getLineNumb

[clang-tools-extra] [include-cleaner] don't consider the associated header unused (PR #67228)

2024-06-19 Thread via cfe-commits

llvmbot wrote:




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

Author: Sam McCall (sam-mccall)


Changes

Loosely, the "associated header" of `foo.cpp` is `foo.h`.
It should be included, many styles include it first.

So far we haven't special cased it in any way, and require this include
to be justified. e.g. if foo.cpp defines a function declared in foo.h,
then the #include is allowed to check these declarations match.

However this doesn't really align with what users want:
- people reasonably want to include the associated header for the
  side-effect of validating that it compiles.
  In the degenerate case, `lib.cpp`is just `#include "lib.h"` (see bug)
- That `void foo(){}` IWYU-uses `void foo();` is a bit artificial, and
  most users won't internalize this. Instead they'll stick with the
  simpler model "include the header that defines your API".
  In the rare cases where these give different answers[1], our current
  behavior is a puzzling special case from the user POV.
  It is more user-friendly to accept both models.
- even where this diagnostic is a true positive (defs don't match header
  decls) the diagnostic does not communicate this usefully.

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

[1] Example of an associated header that's not IWYU-used:
```
// http.h
inline URL buildHttpURL(string host, int port, string path) {
  return "http://"; + host + ":" + port + "/" + path;
}
// http.cpp
class HTTPURLHandler : URLHandler { ... };
REGISTER_URL_HANDLER("http", HTTPURLHandler);
```


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


2 Files Affected:

- (modified) clang-tools-extra/include-cleaner/lib/Record.cpp (+33-3) 
- (modified) clang-tools-extra/include-cleaner/unittests/RecordTest.cpp (+56-3) 


``diff
diff --git a/clang-tools-extra/include-cleaner/lib/Record.cpp 
b/clang-tools-extra/include-cleaner/lib/Record.cpp
index 78a4df6cc40ea..6b5be956ec108 100644
--- a/clang-tools-extra/include-cleaner/lib/Record.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -34,6 +34,7 @@
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileSystem/UniqueID.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/StringSaver.h"
 #include 
 #include 
@@ -180,7 +181,9 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
   RecordPragma(const Preprocessor &P, PragmaIncludes *Out)
   : SM(P.getSourceManager()), HeaderInfo(P.getHeaderSearchInfo()), 
Out(Out),
 Arena(std::make_shared()),
-UniqueStrings(*Arena) {}
+UniqueStrings(*Arena),
+MainFileStem(llvm::sys::path::stem(
+SM.getNonBuiltinFilenameForID(SM.getMainFileID()).value_or(""))) {}
 
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
@@ -228,8 +231,9 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
   }
 if (!IncludedHeader && File)
   IncludedHeader = *File;
-checkForExport(HashFID, HashLine, std::move(IncludedHeader), File);
+checkForExport(HashFID, HashLine, IncludedHeader, File);
 checkForKeep(HashLine, File);
+checkForDeducedAssociated(IncludedHeader);
   }
 
   void checkForExport(FileID IncludingFile, int HashLine,
@@ -269,6 +273,27 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
   KeepStack.pop_back(); // Pop immediately for single-line keep pragma.
   }
 
+  // Consider marking H as the "associated header" of the main file.
+  //
+  // Our heuristic:
+  // - it must be the first #include in the main file
+  // - it must have the same name stem as the main file (foo.h and foo.cpp)
+  // (IWYU pragma: associated is also supported, just not by this function).
+  //
+  // We consider the associated header as if it had a keep pragma.
+  // (Unlike IWYU, we don't treat #includes inside the associated header as if
+  // they were written in the main file.)
+  void checkForDeducedAssociated(std::optional H) {
+namespace path = llvm::sys::path;
+if (!InMainFile || SeenAssociatedCandidate)
+  return;
+SeenAssociatedCandidate = true; // Only the first #include is our 
candidate.
+if (!H || H->kind() != Header::Physical)
+  return;
+if (path::stem(H->physical().getName(), path::Style::posix) == 
MainFileStem)
+  Out->ShouldKeep.insert(H->physical().getUniqueID());
+  }
+
   bool HandleComment(Preprocessor &PP, SourceRange Range) override {
 auto &SM = PP.getSourceManager();
 auto Pragma =
@@ -280,7 +305,9 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
 int CommentLine = SM.getLineNumber(CommentFID, CommentOffset);
 
 if (InMainFile) {
-  if (Pragma->starts_with("keep")) {
+  if (Pragma->starts_with("keep") ||
+  // Limited support for associated headers: never consider unused.
+  Pragma->starts_with("assoc

[clang] [clang-format][doc] Add clarification to `PointerAlignment` (PR #96069)

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


[clang] [clang-format][doc] Add clarification to `PointerAlignment` (PR #96069)

2024-06-19 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Eberhard Beilharz (ermshiperete)


Changes

Clarify that `PointerAlignment` is not used if `DerivePointerAlignment` is set 
to `true`. So far this was only mentioned under `DerivePointerAlignment` which 
could lead to confusion if someone only looked at `PointerAlignment`.

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


1 Files Affected:

- (modified) clang/docs/ClangFormatStyleOptions.rst (+1-1) 


``diff
diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index bb00c20922d36..a58ba93b41bf8 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -5015,7 +5015,7 @@ the configuration (without a prefix: ``Auto``).
 .. _PointerAlignment:
 
 **PointerAlignment** (``PointerAlignmentStyle``) :versionbadge:`clang-format 
3.7` :ref:`¶ `
-  Pointer and reference alignment style.
+  Pointer and reference alignment style. Only used if 
``DerivePointerAlignment`` is not ``true``.
 
   Possible values:
 

``




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


[clang] [clang][Interp] Implement dynamic memory allocation handling (PR #70306)

2024-06-19 Thread Timm Baeder via cfe-commits


@@ -2544,6 +2544,85 @@ bool 
ByteCodeExprGen::VisitCXXInheritedCtorInitExpr(
   return this->emitCall(F, 0, E);
 }
 
+template 
+bool ByteCodeExprGen::VisitCXXNewExpr(const CXXNewExpr *E) {
+  assert(classifyPrim(E->getType()) == PT_Ptr);
+  const Expr *Init = E->getInitializer();
+  QualType ElementType = E->getAllocatedType();
+  std::optional ElemT = classify(ElementType);
+
+  const Descriptor *Desc;
+  if (ElemT) {
+if (E->isArray())
+  Desc = nullptr; // We're not going to use it in this case.
+else
+  Desc = P.createDescriptor(E, *ElemT, Descriptor::InlineDescMD,
+/*IsConst=*/false, /*IsTemporary=*/false,
+/*IsMutable=*/false);
+  } else {
+Desc = P.createDescriptor(
+E, ElementType.getTypePtr(),
+E->isArray() ? std::nullopt : Descriptor::InlineDescMD,
+/*IsConst=*/false, /*IsTemporary=*/false, /*IsMutable=*/false, Init);
+  }
+
+  if (E->isArray()) {
+std::optional ArraySizeExpr = E->getArraySize();
+if (!ArraySizeExpr)

tbaederr wrote:

That works, we're getting the size expr from the `CXXNewExpr`.

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


[clang] [clang] Change style of superseded issues on C++ DR status page (PR #96051)

2024-06-19 Thread Matheus Izvekov via cfe-commits

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


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


[clang] [analyzer] Check the correct first and last elements in cstring.UninitializedRead (PR #95408)

2024-06-19 Thread Donát Nagy via cfe-commits

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


[clang] [analyzer] Check the correct first and last elements in cstring.UninitializedRead (PR #95408)

2024-06-19 Thread Donát Nagy via cfe-commits

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

Thanks for the updates!

Unfortunately, as I dug deeper into your function `getOriginRegion()`, I 
realized that it is logically incorrect (see inline comment for explanation). 
(I was a bit suspicious during the earlier reviews as well, but this is a very 
complex area and earlier I didn't spend enough time on it.)

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


[clang] [analyzer] Check the correct first and last elements in cstring.UninitializedRead (PR #95408)

2024-06-19 Thread Donát Nagy via cfe-commits


@@ -393,6 +401,162 @@ ProgramStateRef 
CStringChecker::checkNonNull(CheckerContext &C,
   return stateNonNull;
 }
 
+static std::optional getIndex(ProgramStateRef State,
+  const ElementRegion *ER, CharKind CK) {
+  SValBuilder &SVB = State->getStateManager().getSValBuilder();
+  ASTContext &Ctx = SVB.getContext();
+
+  if (CK == CharKind::Regular) {
+if (ER->getValueType() != Ctx.CharTy)
+  return {};
+return ER->getIndex();
+  }
+
+  if (ER->getValueType() != Ctx.WideCharTy)
+return {};
+
+  QualType SizeTy = Ctx.getSizeType();
+  NonLoc WideSize =
+  SVB.makeIntVal(Ctx.getTypeSizeInChars(Ctx.WideCharTy).getQuantity(),
+ SizeTy)
+  .castAs();
+  SVal Offset =
+  SVB.evalBinOpNN(State, BO_Mul, ER->getIndex(), WideSize, SizeTy);
+  if (Offset.isUnknown())
+return {};
+  return Offset.castAs();
+}
+
+// Try to get hold of the origin region (e.g. the actual array region from an
+// element region).
+static const TypedValueRegion *getOriginRegion(const ElementRegion *ER) {
+  const MemRegion *MR = ER->getSuperRegion();
+  const MemRegion *Ret = MR;
+  assert(MR);
+  if (const auto *sym = MR->getAs()) {
+SymbolRef sym2 = sym->getSymbol();
+if (!sym2)
+  return nullptr;
+Ret = sym2->getOriginRegion();
+  }
+  return dyn_cast_or_null(Ret);
+}

NagyDonat wrote:

I thought several hours about this function, and my TLDR conclusion is that (1) 
this logic is wrong (2) `SymExpr::getOriginRegion()` is a red flag and (3) just 
use a plain `getSuperRegion()` call instead of this function. (Note that the 
branch where SymExpr::getOriginRegion() is used is not exercised in any 
testcase.)

More precisely, the problem is that `SymExpr::getOriginRegion()` is an 
extremely unnatural operation, which extracts a part of the "opaque unique tag" 
of the symbol. The result of `S->getOriginRegion()` is:
- the region _R_ when `S` is a `SymbolRegionValue` which represents "the value 
stored in the memory region _R_ at the start of the analysis of this function"
- the region _R_ when `S` is a `SymbolDerived` which represents "the value 
stored in the memory region _R_ after a certain invalidation"
- nullpointer in other cases (e.g. `SymbolConjured`).

As a concrete example, if you have a function like
```c++
void save_to_logs(int *src, int begin, int count) {
  memcpy(global_log_array, src + begin, count * sizeof(int));
}
```
then the element region representing `src + begin` would be passed to 
`getOriginRegion()`, which would first strip the `ElementRegion` layer to get a 
`SymbolicRegion`, then unwrap that to get a `SymbolRegionValue` and finally 
return the `ParamVarRegion` which represents the pointer-sized memory area of 
the variable `src`.

This won't lead to a crash because this `ParamVarRegion` is immediately 
discarded by the next check, which requires an array type:
```
if (!Orig->getValueType()->isArrayType())
return State;
```
However, there are no situations where `getOriginRegion()` = "region where a 
pointer to this symbolic region was stored at some earlier step" is actually 
useful, so you should just remove the branch using it.

By the way, I see that you need a `TypedValueRegion` after this point to 
continue the calculations -- but if the SuperRegion of your ElementRegion is a 
SymbolicRegion, then the right thing to do is just discarding it. A 
`SymbolicRegion` is not necessarily a real "region", it may just represent a 
pointer that points into the middle of some opaque unknown memory.

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


[clang] [analyzer] Check the correct first and last elements in cstring.UninitializedRead (PR #95408)

2024-06-19 Thread Donát Nagy via cfe-commits


@@ -393,6 +401,162 @@ ProgramStateRef 
CStringChecker::checkNonNull(CheckerContext &C,
   return stateNonNull;
 }
 
+static std::optional getIndex(ProgramStateRef State,
+  const ElementRegion *ER, CharKind CK) {
+  SValBuilder &SVB = State->getStateManager().getSValBuilder();
+  ASTContext &Ctx = SVB.getContext();
+
+  if (CK == CharKind::Regular) {
+if (ER->getValueType() != Ctx.CharTy)
+  return {};
+return ER->getIndex();
+  }
+
+  if (ER->getValueType() != Ctx.WideCharTy)
+return {};
+
+  QualType SizeTy = Ctx.getSizeType();
+  NonLoc WideSize =
+  SVB.makeIntVal(Ctx.getTypeSizeInChars(Ctx.WideCharTy).getQuantity(),
+ SizeTy)
+  .castAs();
+  SVal Offset =
+  SVB.evalBinOpNN(State, BO_Mul, ER->getIndex(), WideSize, SizeTy);
+  if (Offset.isUnknown())
+return {};
+  return Offset.castAs();
+}
+
+// Try to get hold of the origin region (e.g. the actual array region from an
+// element region).
+static const TypedValueRegion *getOriginRegion(const ElementRegion *ER) {
+  const MemRegion *MR = ER->getSuperRegion();
+  const MemRegion *Ret = MR;
+  assert(MR);
+  if (const auto *sym = MR->getAs()) {
+SymbolRef sym2 = sym->getSymbol();
+if (!sym2)
+  return nullptr;
+Ret = sym2->getOriginRegion();
+  }
+  return dyn_cast_or_null(Ret);
+}
+
+// Basically 1 -> 1st, 12 -> 12th, etc.
+static void printIdxWithOrdinalSuffix(llvm::raw_ostream &Os, unsigned Idx) {
+  Os << Idx << llvm::getOrdinalSuffix(Idx);

NagyDonat wrote:

```suggestion
  switch (Idx) {
case 1:
  Os << "first";
  break;
case 2:
  Os << "second";
  break;
case 3:
  Os << "third";
  break;
default:
  Os << Idx << llvm::getOrdinalSuffix(Idx);
  }
```
Consider printing "first", "second" and "third" instead of "1st", "2nd" and 
"3rd" because IMO it makes the diagnostics easier to read -- and this function 
will be used for argument indices in builtin functions, so these cases will be 
very common.

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


[clang] [Clang] Disallow explicit object parameters in more contexts (PR #89078)

2024-06-19 Thread via cfe-commits

https://github.com/Sirraide updated 
https://github.com/llvm/llvm-project/pull/89078

>From c611122688657287e8285edd9a2875e4975d26dd Mon Sep 17 00:00:00 2001
From: Sirraide 
Date: Wed, 17 Apr 2024 16:15:39 +0200
Subject: [PATCH 01/11] [Clang] Disallow explicit object parameters in more
 contexts

---
 .../clang/Basic/DiagnosticSemaKinds.td|  2 ++
 clang/lib/Sema/SemaDeclCXX.cpp|  6 ++--
 clang/lib/Sema/SemaType.cpp   | 30 +++
 clang/test/SemaCXX/cxx2b-deducing-this.cpp| 22 --
 4 files changed, 54 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 5ec0218aedfe8..680638d2e59c6 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7494,6 +7494,8 @@ def err_explicit_object_parameter_mutable: Error<
 def err_invalid_explicit_object_type_in_lambda: Error<
   "invalid explicit object parameter type %0 in lambda with capture; "
   "the type must be the same as, or derived from, the lambda">;
+def err_explicit_object_parameter_invalid: Error<
+  "an explicit object parameter is not allowed here">;
 
 def err_ref_qualifier_overload : Error<
   "cannot overload a member function %select{without a ref-qualifier|with "
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 7669171fea56f..ea634df48e5de 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -11469,10 +11469,8 @@ void 
Sema::CheckExplicitObjectMemberFunction(Declarator &D,
 return;
 
   if (!DC || !DC->isRecord()) {
-Diag(ExplicitObjectParam->getLocation(),
- diag::err_explicit_object_parameter_nonmember)
-<< D.getSourceRange() << /*non-member=*/2 << IsLambda;
-D.setInvalidType();
+assert(D.isInvalidType() && "Explicit object parameter in non-member "
+"should have been diagnosed already");
 return;
   }
 
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 404c4e8e31b55..406065741bf2d 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -5287,6 +5287,36 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
   // Check for auto functions and trailing return type and adjust the
   // return type accordingly.
   if (!D.isInvalidType()) {
+// [dcl.fct]p6:
+//
+// An explicit-object-parameter-declaration is a parameter-declaration
+// with a this specifier. An explicit-object-parameter-declaration 
shall
+// appear only as the first parameter-declaration of a
+// parameter-declaration-list of either:
+//
+//   - a member-declarator that declares a member function 
[class.mem], or
+//   - a lambda-declarator [expr.prim.lambda].
+DeclaratorContext C = D.getContext();
+ParmVarDecl *First =
+FTI.NumParams
+? dyn_cast_if_present(FTI.Params[0].Param)
+: nullptr;
+if (First && First->isExplicitObjectParameter() &&
+C != DeclaratorContext::LambdaExpr &&
+
+// Either not a member or nested declarator in a member.
+(C != DeclaratorContext::Member ||
+ D.getInnermostNonParenChunk() != &DeclType) &&
+
+// Allow out-of-line definitions if we have a scope spec.
+D.getCXXScopeSpec().isEmpty()) {
+  S.Diag(First->getBeginLoc(),
+ diag::err_explicit_object_parameter_invalid)
+  << First->getSourceRange();
+  D.setInvalidType();
+  AreDeclaratorChunksValid = false;
+}
+
 // trailing-return-type is only required if we're declaring a function,
 // and not, for instance, a pointer to a function.
 if (D.getDeclSpec().hasAutoTypeSpec() &&
diff --git a/clang/test/SemaCXX/cxx2b-deducing-this.cpp 
b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
index 5f29a955e053c..ddb770a92db0f 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this.cpp
@@ -5,7 +5,7 @@
 void f(this); // expected-error{{variable has incomplete type 'void'}} \
   // expected-error{{invalid use of 'this' outside of a non-static 
member function}}
 
-void g(this auto); // expected-error{{an explicit object parameter cannot 
appear in a non-member function}}
+void g(this auto); // expected-error{{an explicit object parameter is not 
allowed here}}
 
 auto l1 = [] (this auto) static {}; // expected-error{{an explicit object 
parameter cannot appear in a static lambda}}
 auto l2 = [] (this auto) mutable {}; // expected-error{{a lambda with an 
explicit object parameter cannot be mutable}}
@@ -685,7 +685,7 @@ struct S {
   static void j(this S s); // expected-error {{an explicit object parameter 
cannot appear in a static function}}
 };

  1   2   3   >