[clang] [Clang][Sema] Add special handling of mfloat8 in initializer lists (PR #125097)

2025-01-31 Thread Timm Baeder via cfe-commits

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


[clang] [Clang][Sema] Add special handling of mfloat8 in initializer lists (PR #125097)

2025-01-31 Thread Timm Baeder via cfe-commits

tbaederr wrote:

Changes seem fine once the code formatting is fixed.

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


[clang-tools-extra] [clangd] Allow specifying what headers are always included via "" or <> (PR #67749)

2025-01-31 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

> Did this already land in 19.1.7?

No, it will appear in clangd 20.

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


[clang] [ARM] Empty structs are 1-byte for C++ ABI (PR #124762)

2025-01-31 Thread Oliver Stannard via cfe-commits

https://github.com/ostannard updated 
https://github.com/llvm/llvm-project/pull/124762

>From 4d883f068c5061e60e90e51d149a361920b431d2 Mon Sep 17 00:00:00 2001
From: Oliver Stannard 
Date: Thu, 12 Dec 2024 15:29:31 +
Subject: [PATCH 1/7] [ARM] Empty structs are 1-byte for C++ ABI

For C++ (but not C), empty structs should be passed to functions as if
they are a 1 byte object with 1 byte alignment.

This is defined in Arm's CPPABI32:
  https://github.com/ARM-software/abi-aa/blob/main/cppabi32/cppabi32.rst
  For the purposes of parameter passing in AAPCS32, a parameter whose
  type is an empty class shall be treated as if its type were an
  aggregate with a single member of type unsigned byte.

The AArch64 equivalent of this has an exception for structs containing
an array of size zero, I've kept that logic for ARM. I've not found a
reason for this exception, but I've checked that GCC does have the same
behaviour for ARM as it does for AArch64.

The AArch64 version has an Apple ABI with different rules, which ignores
empty structs in both C and C++. This is documented at
https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms.
The ARM equivalent of that appears to be AAPCS16_VFP, used for WatchOS,
but I can't find any documentation for that ABI, so I'm not sure what
rules it should follow. For now I've left it following the AArch64 Apple
rules.
---
 clang/lib/CodeGen/Targets/ARM.cpp |  43 --
 clang/test/CodeGen/arm-empty-args.cpp | 119 ++
 2 files changed, 156 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/CodeGen/arm-empty-args.cpp

diff --git a/clang/lib/CodeGen/Targets/ARM.cpp 
b/clang/lib/CodeGen/Targets/ARM.cpp
index 2d858fa2f3c3a3..b243ccacc2155d 100644
--- a/clang/lib/CodeGen/Targets/ARM.cpp
+++ b/clang/lib/CodeGen/Targets/ARM.cpp
@@ -71,6 +71,7 @@ class ARMABIInfo : public ABIInfo {
   unsigned functionCallConv) const;
   ABIArgInfo classifyHomogeneousAggregate(QualType Ty, const Type *Base,
   uint64_t Members) const;
+  bool shouldIgnoreEmptyArg(QualType Ty) const;
   ABIArgInfo coerceIllegalVector(QualType Ty) const;
   bool isIllegalVectorType(QualType Ty) const;
   bool containsAnyFP16Vectors(QualType Ty) const;
@@ -328,6 +329,26 @@ ABIArgInfo 
ARMABIInfo::classifyHomogeneousAggregate(QualType Ty,
   return ABIArgInfo::getDirect(nullptr, 0, nullptr, false, Align);
 }
 
+bool ARMABIInfo::shouldIgnoreEmptyArg(QualType Ty) const {
+  uint64_t Size = getContext().getTypeSize(Ty);
+  assert((isEmptyRecord(getContext(), Ty, true) || Size == 0) &&
+ "Arg is not empty");
+
+  // Empty records are ignored in C mode, and in C++ on WatchOS.
+  if (!getContext().getLangOpts().CPlusPlus ||
+  getABIKind() == ARMABIKind::AAPCS16_VFP)
+return true;
+
+  // In C++ mode, arguments which have sizeof() == 0 are ignored. This is not a
+  // situation which is defined by any C++ standard or ABI, but this matches
+  // GCC's de facto ABI.
+  if (Size == 0)
+return true;
+
+  // Otherwise, they are passed as if they have a size of 1 byte.
+  return false;
+}
+
 ABIArgInfo ARMABIInfo::classifyArgumentType(QualType Ty, bool isVariadic,
 unsigned functionCallConv) const {
   // 6.1.2.1 The following argument types are VFP CPRCs:
@@ -366,9 +387,15 @@ ABIArgInfo ARMABIInfo::classifyArgumentType(QualType Ty, 
bool isVariadic,
 return getNaturalAlignIndirect(Ty, RAA == CGCXXABI::RAA_DirectInMemory);
   }
 
-  // Ignore empty records.
-  if (isEmptyRecord(getContext(), Ty, true))
-return ABIArgInfo::getIgnore();
+  // Empty records are either ignored completely or passed as if they were a
+  // 1-byte object, depending on the ABI and language standard.
+  if (isEmptyRecord(getContext(), Ty, true) ||
+  getContext().getTypeSize(Ty) == 0) {
+if (shouldIgnoreEmptyArg(Ty))
+  return ABIArgInfo::getIgnore();
+else
+  return ABIArgInfo::getDirect(llvm::Type::getInt8Ty(getVMContext()));
+  }
 
   if (IsAAPCS_VFP) {
 // Homogeneous Aggregates need to be expanded when we can fit the aggregate
@@ -588,7 +615,8 @@ ABIArgInfo ARMABIInfo::classifyReturnType(QualType RetTy, 
bool isVariadic,
 
   // Otherwise this is an AAPCS variant.
 
-  if (isEmptyRecord(getContext(), RetTy, true))
+  if (isEmptyRecord(getContext(), RetTy, true) ||
+  getContext().getTypeSize(RetTy) == 0)
 return ABIArgInfo::getIgnore();
 
   // Check for homogeneous aggregates with AAPCS-VFP.
@@ -752,10 +780,13 @@ RValue ARMABIInfo::EmitVAArg(CodeGenFunction &CGF, 
Address VAListAddr,
   CharUnits SlotSize = CharUnits::fromQuantity(4);
 
   // Empty records are ignored for parameter passing purposes.
-  if (isEmptyRecord(getContext(), Ty, true))
+  uint64_t Size = getContext().getTypeSize(Ty);
+  bool IsEmpty = isEmptyRecord(getContext(), Ty, true);
+  if ((IsEmpty || Size == 0) && shouldIgnoreEmptyArg(Ty))

[clang] [ARM] Empty structs are 1-byte for C++ ABI (PR #124762)

2025-01-31 Thread Oliver Stannard via cfe-commits

ostannard wrote:

The release notes have now been cleared on main, so I'll re-add them in the 
llvm-20 cherry pick.

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


[clang] 97b066f - [ARM] Empty structs are 1-byte for C++ ABI (#124762)

2025-01-31 Thread via cfe-commits

Author: Oliver Stannard
Date: 2025-01-31T09:03:01Z
New Revision: 97b066f4e92a0df46b9d10721e988210f0d1afb6

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

LOG: [ARM] Empty structs are 1-byte for C++ ABI (#124762)

For C++ (but not C), empty structs should be passed to functions as if
they are a 1 byte object with 1 byte alignment.

This is defined in Arm's CPPABI32:
  https://github.com/ARM-software/abi-aa/blob/main/cppabi32/cppabi32.rst
  For the purposes of parameter passing in AAPCS32, a parameter whose
  type is an empty class shall be treated as if its type were an
  aggregate with a single member of type unsigned byte.

The AArch64 equivalent of this has an exception for structs containing
an array of size zero, I've kept that logic for ARM. I've not found a
reason for this exception, but I've checked that GCC does have the same
behaviour for ARM as it does for AArch64.

The AArch64 version has an Apple ABI with different rules, which ignores
empty structs in both C and C++. This is documented at
https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms.
The ARM equivalent of that appears to be AAPCS16_VFP, used for WatchOS,
but I can't find any documentation for that ABI, so I'm not sure what
rules it should follow. For now I've left it following the AArch64 Apple
rules.

Added: 
clang/test/CodeGen/arm-empty-args.cpp

Modified: 
clang/include/clang/Basic/LangOptions.h
clang/lib/CodeGen/Targets/ARM.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 114a5d34a008bd7..16c35bcf49339c6 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -246,6 +246,8 @@ class LangOptionsBase {
 ///   construction vtable because it hasn't added 'type' as a substitution.
 ///   - Skip mangling enclosing class templates of member-like friend
 ///   function templates.
+///   - Ignore empty struct arguments in C++ mode for ARM, instead of
+///   passing them as if they had a size of 1 byte.
 Ver19,
 
 /// Conform to the underlying platform's C and C++ ABIs as closely

diff  --git a/clang/lib/CodeGen/Targets/ARM.cpp 
b/clang/lib/CodeGen/Targets/ARM.cpp
index 2d858fa2f3c3a35..47e31ceeaf29431 100644
--- a/clang/lib/CodeGen/Targets/ARM.cpp
+++ b/clang/lib/CodeGen/Targets/ARM.cpp
@@ -71,6 +71,7 @@ class ARMABIInfo : public ABIInfo {
   unsigned functionCallConv) const;
   ABIArgInfo classifyHomogeneousAggregate(QualType Ty, const Type *Base,
   uint64_t Members) const;
+  bool shouldIgnoreEmptyArg(QualType Ty) const;
   ABIArgInfo coerceIllegalVector(QualType Ty) const;
   bool isIllegalVectorType(QualType Ty) const;
   bool containsAnyFP16Vectors(QualType Ty) const;
@@ -328,6 +329,31 @@ ABIArgInfo 
ARMABIInfo::classifyHomogeneousAggregate(QualType Ty,
   return ABIArgInfo::getDirect(nullptr, 0, nullptr, false, Align);
 }
 
+bool ARMABIInfo::shouldIgnoreEmptyArg(QualType Ty) const {
+  uint64_t Size = getContext().getTypeSize(Ty);
+  assert((isEmptyRecord(getContext(), Ty, true) || Size == 0) &&
+ "Arg is not empty");
+
+  // Empty records are ignored in C mode, and in C++ on WatchOS.
+  if (!getContext().getLangOpts().CPlusPlus ||
+  getABIKind() == ARMABIKind::AAPCS16_VFP)
+return true;
+
+  // In C++ mode, arguments which have sizeof() == 0 are ignored. This is not a
+  // situation which is defined by any C++ standard or ABI, but this matches
+  // GCC's de facto ABI.
+  if (Size == 0)
+return true;
+
+  // Clang 19.0 and earlier always ignored empty struct arguments in C++ mode.
+  if (getContext().getLangOpts().getClangABICompat() <=
+  LangOptions::ClangABI::Ver19)
+return true;
+
+  // Otherwise, they are passed as if they have a size of 1 byte.
+  return false;
+}
+
 ABIArgInfo ARMABIInfo::classifyArgumentType(QualType Ty, bool isVariadic,
 unsigned functionCallConv) const {
   // 6.1.2.1 The following argument types are VFP CPRCs:
@@ -366,9 +392,15 @@ ABIArgInfo ARMABIInfo::classifyArgumentType(QualType Ty, 
bool isVariadic,
 return getNaturalAlignIndirect(Ty, RAA == CGCXXABI::RAA_DirectInMemory);
   }
 
-  // Ignore empty records.
-  if (isEmptyRecord(getContext(), Ty, true))
-return ABIArgInfo::getIgnore();
+  // Empty records are either ignored completely or passed as if they were a
+  // 1-byte object, depending on the ABI and language standard.
+  if (isEmptyRecord(getContext(), Ty, true) ||
+  getContext().getTypeSize(Ty) == 0) {
+if (shouldIgnoreEmptyArg(Ty))
+  return ABIArgInfo::getIgnore();
+else
+  return ABIArgInfo::getDirect(llvm::

[clang] [ARM] Empty structs are 1-byte for C++ ABI (PR #124762)

2025-01-31 Thread Oliver Stannard via cfe-commits

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


[clang] Warn when unique objects might be duplicated in shared libraries (PR #117622)

2025-01-31 Thread Hans Wennborg via cfe-commits

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

lgtm

Unless there are any further comments, I'll push the Merge button on Monday.

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


[clang] [clangd] Add code completion for if constexpr (PR #124315)

2025-01-31 Thread via cfe-commits

https://github.com/FantasqueX updated 
https://github.com/llvm/llvm-project/pull/124315

>From 0715933267a45b43d3c36bd63d59a00497ff5231 Mon Sep 17 00:00:00 2001
From: Letu Ren 
Date: Sat, 25 Jan 2025 01:23:52 +0800
Subject: [PATCH] [Sema] Add code completion for if constexpr

C++17 supports `if constexpr` statement. This patch implements this in
code completion.
---
 clang/include/clang/Sema/SemaCodeCompletion.h |  1 +
 clang/lib/Parse/ParseStmt.cpp |  8 
 clang/lib/Sema/SemaCodeComplete.cpp   | 15 +++
 3 files changed, 24 insertions(+)

diff --git a/clang/include/clang/Sema/SemaCodeCompletion.h 
b/clang/include/clang/Sema/SemaCodeCompletion.h
index e931596c215d31..af44745d5d1239 100644
--- a/clang/include/clang/Sema/SemaCodeCompletion.h
+++ b/clang/include/clang/Sema/SemaCodeCompletion.h
@@ -152,6 +152,7 @@ class SemaCodeCompletion : public SemaBase {
   void CodeCompleteDesignator(const QualType BaseType,
   llvm::ArrayRef InitExprs,
   const Designation &D);
+  void CodeCompleteIfConstExpr(Scope *S) const;
   void CodeCompleteAfterIf(Scope *S, bool IsBracedThen);
 
   void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, bool 
EnteringContext,
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index cd4504630f8719..3f9900dd997ada 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -1553,6 +1553,14 @@ StmtResult Parser::ParseIfStatement(SourceLocation 
*TrailingElseLoc) {
   IsConsteval = true;
   ConstevalLoc = ConsumeToken();
 }
+
+if (Tok.is(tok::code_completion)) {
+  if (getLangOpts().CPlusPlus17) {
+cutOffParsing();
+Actions.CodeCompletion().CodeCompleteIfConstExpr(getCurScope());
+return StmtError();
+  }
+}
   }
   if (!IsConsteval && (NotLocation.isValid() || Tok.isNot(tok::l_paren))) {
 Diag(Tok, diag::err_expected_lparen_after) << "if";
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp 
b/clang/lib/Sema/SemaCodeComplete.cpp
index 58f3efbe0daf89..b159fd26a45208 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -6762,6 +6762,21 @@ void SemaCodeCompletion::CodeCompleteInitializer(Scope 
*S, Decl *D) {
   CodeCompleteExpression(S, Data);
 }
 
+void SemaCodeCompletion::CodeCompleteIfConstExpr(Scope *S) const {
+  ResultBuilder Results(SemaRef, CodeCompleter->getAllocator(),
+CodeCompleter->getCodeCompletionTUInfo(),
+CodeCompletionContext::CCC_SymbolOrNewName);
+  Results.EnterNewScope();
+
+  Results.AddResult(CodeCompletionResult("constexpr"));
+
+  Results.ExitScope();
+
+  HandleCodeCompleteResults(&SemaRef, CodeCompleter,
+Results.getCompletionContext(), Results.data(),
+Results.size());
+}
+
 void SemaCodeCompletion::CodeCompleteAfterIf(Scope *S, bool IsBracedThen) {
   ResultBuilder Results(SemaRef, CodeCompleter->getAllocator(),
 CodeCompleter->getCodeCompletionTUInfo(),

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


[clang] [Sema] Add code completion for if constexpr (PR #124315)

2025-01-31 Thread via cfe-commits

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


[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-31 Thread Ivana Ivanovska via cfe-commits


@@ -68,32 +70,60 @@ static std::string getDREAncestorString(const DeclRefExpr 
*DRE,
 
 if (StParents.size() > 1)
   return "unavailable due to multiple parents";
-if (StParents.size() == 0)
+if (StParents.empty())
   break;
 St = StParents.begin()->get();
 if (St)
   SS << " ==> ";
   } while (St);
   return SS.str();
 }
+
 } // namespace
 #endif /* NDEBUG */
 
-namespace clang::ast_matchers {
+namespace {
+// Using a custom matcher instead of ASTMatchers to achieve better performance.
+class FastMatcher {
+public:
+  virtual bool matches(const DynTypedNode &DynNode, ASTContext &Ctx,
+   const UnsafeBufferUsageHandler &Handler) = 0;
+  virtual ~FastMatcher() = default;
+};
+
+class MatchResult {
+
+public:
+  template  const T *getNodeAs(StringRef ID) const {
+auto It = Nodes.find(std::string(ID));
+if (It == Nodes.end()) {
+  return nullptr;
+}
+return It->second.get();
+  }
+
+  void addNode(StringRef ID, const DynTypedNode &Node) {
+Nodes[std::string(ID)] = Node;
+  }
+
+private:
+  llvm::StringMap
+  Nodes; // DynTypedNode needed to store different types of Nodes, not
+ // necessarily sharing the same base.
+};
+} // namespace
+
 // A `RecursiveASTVisitor` that traverses all descendants of a given node "n"
 // except for those belonging to a different callable of "n".
 class MatchDescendantVisitor : public DynamicRecursiveASTVisitor {
 public:
   // Creates an AST visitor that matches `Matcher` on all
   // descendants of a given node "n" except for the ones
   // belonging to a different callable of "n".
-  MatchDescendantVisitor(const internal::DynTypedMatcher *Matcher,
- internal::ASTMatchFinder *Finder,
- internal::BoundNodesTreeBuilder *Builder,
- internal::ASTMatchFinder::BindKind Bind,
+  MatchDescendantVisitor(FastMatcher &Matcher, bool FindAll,
  const bool ignoreUnevaluatedContext)
-  : Matcher(Matcher), Finder(Finder), Builder(Builder), Bind(Bind),
-Matches(false), ignoreUnevaluatedContext(ignoreUnevaluatedContext) {
+  : Matcher(&Matcher), FindAll(FindAll), Matches(false),
+ignoreUnevaluatedContext(ignoreUnevaluatedContext) {

ivanaivanovska wrote:

Done.

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


[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-31 Thread Ivana Ivanovska via cfe-commits


@@ -68,32 +70,60 @@ static std::string getDREAncestorString(const DeclRefExpr 
*DRE,
 
 if (StParents.size() > 1)
   return "unavailable due to multiple parents";
-if (StParents.size() == 0)
+if (StParents.empty())
   break;
 St = StParents.begin()->get();
 if (St)
   SS << " ==> ";
   } while (St);
   return SS.str();
 }
+
 } // namespace
 #endif /* NDEBUG */
 
-namespace clang::ast_matchers {
+namespace {
+// Using a custom matcher instead of ASTMatchers to achieve better performance.
+class FastMatcher {
+public:
+  virtual bool matches(const DynTypedNode &DynNode, ASTContext &Ctx,
+   const UnsafeBufferUsageHandler &Handler) = 0;
+  virtual ~FastMatcher() = default;
+};
+
+class MatchResult {
+
+public:
+  template  const T *getNodeAs(StringRef ID) const {
+auto It = Nodes.find(std::string(ID));
+if (It == Nodes.end()) {
+  return nullptr;
+}
+return It->second.get();
+  }
+
+  void addNode(StringRef ID, const DynTypedNode &Node) {
+Nodes[std::string(ID)] = Node;
+  }
+
+private:
+  llvm::StringMap
+  Nodes; // DynTypedNode needed to store different types of Nodes, not

ivanaivanovska wrote:

Done.

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


[clang-tools-extra] [include-cleaner] Dont report explicit refs for global operator new/delete (PR #125199)

2025-01-31 Thread kadir çetinkaya via cfe-commits

https://github.com/kadircet created 
https://github.com/llvm/llvm-project/pull/125199

These are available for all translations implicitly. We shouldn't report
explicit refs and enforce includes.


From 4d6967a12f6793a27ed39fd7a7c1cc32fa001a09 Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya 
Date: Fri, 31 Jan 2025 11:17:27 +0100
Subject: [PATCH] [include-cleaner] Dont report explicit refs for global
 operator new/delete

These are available for all translations implicitly. We shouldn't report
explicit refs and enforce includes.
---
 .../include-cleaner/lib/WalkAST.cpp   | 16 ++-
 .../unittests/AnalysisTest.cpp| 46 +++
 2 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp 
b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
index aae3eda519ffdc..e3686a29d4367d 100644
--- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -22,6 +22,7 @@
 #include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/IdentifierTable.h"
+#include "clang/Basic/OperatorKinds.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Specifiers.h"
 #include "llvm/ADT/STLExtras.h"
@@ -32,6 +33,11 @@
 
 namespace clang::include_cleaner {
 namespace {
+bool isImplicitOperatorNewDelete(OverloadedOperatorKind OpKind) {
+  return OpKind == OO_New || OpKind == OO_Delete || OpKind == OO_Array_New ||
+ OpKind == OO_Array_Delete;
+}
+
 using DeclCallback =
 llvm::function_ref;
 
@@ -158,7 +164,15 @@ class ASTWalker : public RecursiveASTVisitor {
 // the container decl instead, which is preferred as it'll handle
 // aliases/exports properly.
 if (!FD->isCXXClassMember() && !llvm::isa(FD)) {
-  report(DRE->getLocation(), FD);
+  // Global operator new/delete [] is available implicitly in every
+  // translation unit, even without including any explicit headers. So 
treat
+  // those as ambigious to not force inclusion in TUs that transitively
+  // depend on those.
+  RefType RT = isImplicitOperatorNewDelete(
+   FD->getDeclName().getCXXOverloadedOperator())
+   ? RefType::Ambiguous
+   : RefType::Explicit;
+  report(DRE->getLocation(), FD, RT);
   return true;
 }
 // If the ref is without a qualifier, and is a member, ignore it. As it is
diff --git a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
index d2d137a0dfb42a..21797e1c6825ac 100644
--- a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -397,6 +397,52 @@ TEST_F(AnalyzeTest, SpellingIncludesWithSymlinks) {
   }
 }
 
+// Make sure that the references to implicit operator new/delete are reported 
as
+// ambigious.
+TEST_F(AnalyzeTest, ImplicitOperatorNewDelete) {
+  ExtraFS = llvm::makeIntrusiveRefCnt();
+  ExtraFS->addFile("header.h",
+   /*ModificationTime=*/{},
+   llvm::MemoryBuffer::getMemBufferCopy(guard(R"cpp(
+  void* operator new(decltype(sizeof(int)));
+  )cpp")));
+  ExtraFS->addFile("wrapper.h",
+   /*ModificationTime=*/{},
+   llvm::MemoryBuffer::getMemBufferCopy(guard(R"cpp(
+  #include "header.h"
+  )cpp")));
+
+  // Check that header.h is not reported as missing.
+  {
+Inputs.Code = R"cpp(
+  #include "wrapper.h"
+  void bar() {
+operator new(3);
+  })cpp";
+TestAST AST(Inputs);
+std::vector DeclsInTU;
+for (auto *D : AST.context().getTranslationUnitDecl()->decls())
+  DeclsInTU.push_back(D);
+auto Results = analyze(DeclsInTU, {}, PP.Includes, &PI, 
AST.preprocessor());
+EXPECT_THAT(Results.Missing, testing::IsEmpty());
+  }
+
+  // Check that header.h is not reported as unused.
+  {
+Inputs.Code = R"cpp(
+  #include "header.h"
+  void bar() {
+operator new(3);
+  })cpp";
+TestAST AST(Inputs);
+std::vector DeclsInTU;
+for (auto *D : AST.context().getTranslationUnitDecl()->decls())
+  DeclsInTU.push_back(D);
+auto Results = analyze(DeclsInTU, {}, PP.Includes, &PI, 
AST.preprocessor());
+EXPECT_THAT(Results.Unused, Not(testing::IsEmpty()));
+  }
+}
+
 TEST(FixIncludes, Basic) {
   llvm::StringRef Code = R"cpp(#include "d.h"
 #include "a.h"

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


[clang-tools-extra] [include-cleaner] Dont report explicit refs for global operator new/delete (PR #125199)

2025-01-31 Thread kadir çetinkaya via cfe-commits

kadircet wrote:

so this is the alternative to https://github.com/llvm/llvm-project/pull/123027. 
as discussed offline that change would break translation units that depend on a 
user-provided declaration for new/delete operators.

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


[clang-tools-extra] [include-cleaner] Dont report explicit refs for global operator new/delete (PR #125199)

2025-01-31 Thread via cfe-commits

llvmbot wrote:




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

Author: kadir çetinkaya (kadircet)


Changes

These are available for all translations implicitly. We shouldn't report
explicit refs and enforce includes.


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


2 Files Affected:

- (modified) clang-tools-extra/include-cleaner/lib/WalkAST.cpp (+15-1) 
- (modified) clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp (+46) 


``diff
diff --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp 
b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
index aae3eda519ffdc..e3686a29d4367d 100644
--- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -22,6 +22,7 @@
 #include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/IdentifierTable.h"
+#include "clang/Basic/OperatorKinds.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Specifiers.h"
 #include "llvm/ADT/STLExtras.h"
@@ -32,6 +33,11 @@
 
 namespace clang::include_cleaner {
 namespace {
+bool isImplicitOperatorNewDelete(OverloadedOperatorKind OpKind) {
+  return OpKind == OO_New || OpKind == OO_Delete || OpKind == OO_Array_New ||
+ OpKind == OO_Array_Delete;
+}
+
 using DeclCallback =
 llvm::function_ref;
 
@@ -158,7 +164,15 @@ class ASTWalker : public RecursiveASTVisitor {
 // the container decl instead, which is preferred as it'll handle
 // aliases/exports properly.
 if (!FD->isCXXClassMember() && !llvm::isa(FD)) {
-  report(DRE->getLocation(), FD);
+  // Global operator new/delete [] is available implicitly in every
+  // translation unit, even without including any explicit headers. So 
treat
+  // those as ambigious to not force inclusion in TUs that transitively
+  // depend on those.
+  RefType RT = isImplicitOperatorNewDelete(
+   FD->getDeclName().getCXXOverloadedOperator())
+   ? RefType::Ambiguous
+   : RefType::Explicit;
+  report(DRE->getLocation(), FD, RT);
   return true;
 }
 // If the ref is without a qualifier, and is a member, ignore it. As it is
diff --git a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
index d2d137a0dfb42a..21797e1c6825ac 100644
--- a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -397,6 +397,52 @@ TEST_F(AnalyzeTest, SpellingIncludesWithSymlinks) {
   }
 }
 
+// Make sure that the references to implicit operator new/delete are reported 
as
+// ambigious.
+TEST_F(AnalyzeTest, ImplicitOperatorNewDelete) {
+  ExtraFS = llvm::makeIntrusiveRefCnt();
+  ExtraFS->addFile("header.h",
+   /*ModificationTime=*/{},
+   llvm::MemoryBuffer::getMemBufferCopy(guard(R"cpp(
+  void* operator new(decltype(sizeof(int)));
+  )cpp")));
+  ExtraFS->addFile("wrapper.h",
+   /*ModificationTime=*/{},
+   llvm::MemoryBuffer::getMemBufferCopy(guard(R"cpp(
+  #include "header.h"
+  )cpp")));
+
+  // Check that header.h is not reported as missing.
+  {
+Inputs.Code = R"cpp(
+  #include "wrapper.h"
+  void bar() {
+operator new(3);
+  })cpp";
+TestAST AST(Inputs);
+std::vector DeclsInTU;
+for (auto *D : AST.context().getTranslationUnitDecl()->decls())
+  DeclsInTU.push_back(D);
+auto Results = analyze(DeclsInTU, {}, PP.Includes, &PI, 
AST.preprocessor());
+EXPECT_THAT(Results.Missing, testing::IsEmpty());
+  }
+
+  // Check that header.h is not reported as unused.
+  {
+Inputs.Code = R"cpp(
+  #include "header.h"
+  void bar() {
+operator new(3);
+  })cpp";
+TestAST AST(Inputs);
+std::vector DeclsInTU;
+for (auto *D : AST.context().getTranslationUnitDecl()->decls())
+  DeclsInTU.push_back(D);
+auto Results = analyze(DeclsInTU, {}, PP.Includes, &PI, 
AST.preprocessor());
+EXPECT_THAT(Results.Unused, Not(testing::IsEmpty()));
+  }
+}
+
 TEST(FixIncludes, Basic) {
   llvm::StringRef Code = R"cpp(#include "d.h"
 #include "a.h"

``




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


[clang-tools-extra] [include-cleaner] Add special mappings for operator new/delete (PR #123027)

2025-01-31 Thread kadir çetinkaya via cfe-commits

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


[clang-tools-extra] [clangd] Allow specifying what headers are always included via "" or <> (PR #67749)

2025-01-31 Thread Chiller Dragon via cfe-commits

ChillerDragon wrote:

Did this already land in 19.1.7? I am having trouble getting it to work.

My ``~/.clangd`` looks like this just to be sure I also put it in 
``~/Desktop/git/ddnet/.clangd`` the repo root.

```yaml
CompileFlags:
  Add: -I.
Diagnostics:
  MissingIncludes: Strict
Style:
  AngledHeaders: ["base/.*", "engine/.*", "game/.*"]
```

:LspInfo in neovim confirms I am running clang 19.1.7

```
LSP configs active in this buffer (bufnr: 2) ~
- Language client log: ~/.local/state/nvim/lsp.log
- Detected filetype: `cpp`
- 1 client(s) attached to this buffer
- Client: `clangd` (id: 2, bufnr: [2])
  root directory:~/Desktop/git/ddnet/
  filetypes: c, cpp, objc, objcpp, cuda, proto
  cmd:   ~/.local/share/nvim/mason/bin/clangd
  version:   `clangd version 19.1.7`
  executable:true
  autostart: true
```

When I start to call functions from system.h it automatically included it in 
quotes ._.
I was expecting all base/.* to be angled.

```C++
#include "base/system.h"
```


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


[clang] [ARM] Empty structs are 1-byte for C++ ABI (PR #124762)

2025-01-31 Thread Oliver Stannard via cfe-commits

ostannard wrote:

/cherry-pick 97b066f4e92a0df46b9d10721e988210f0d1afb6

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


[clang-tools-extra] [include-cleaner] Add special mappings for operator new/delete (PR #123027)

2025-01-31 Thread kadir çetinkaya via cfe-commits

kadircet wrote:

abandoning in favor of https://github.com/llvm/llvm-project/pull/125199 

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


[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-31 Thread Ivana Ivanovska via cfe-commits

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


[clang] [clang][bytecode][NFC] Use RetPC in InterpFrame::getExpr() as well (PR #125200)

2025-01-31 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/125200

Both getLocation() and getRange() use the RetPC if the current function doesn't 
have a usable body. Using PC here was just a typo.

>From 07af7276f1bebc995d26d0c2c24d22e7554a734d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 31 Jan 2025 12:11:13 +0100
Subject: [PATCH] [clang][bytecode][NFC] Use RetPC in InterpFrame::getExpr() as
 well

Both getLocation() and getRange() use the RetPC if the current
function doesn't have a usable body. Using PC here was just a typo.
---
 clang/lib/AST/ByteCode/InterpFrame.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp 
b/clang/lib/AST/ByteCode/InterpFrame.cpp
index 20f67d9b1fd425..48a3db055c6c9b 100644
--- a/clang/lib/AST/ByteCode/InterpFrame.cpp
+++ b/clang/lib/AST/ByteCode/InterpFrame.cpp
@@ -244,7 +244,7 @@ SourceInfo InterpFrame::getSource(CodePtr PC) const {
 
 const Expr *InterpFrame::getExpr(CodePtr PC) const {
   if (Func && !funcHasUsableBody(Func) && Caller)
-return Caller->getExpr(PC);
+return Caller->getExpr(RetPC);
 
   return S.getExpr(Func, PC);
 }

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


[clang] [clang][bytecode][NFC] Use RetPC in InterpFrame::getExpr() as well (PR #125200)

2025-01-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

Both getLocation() and getRange() use the RetPC if the current function doesn't 
have a usable body. Using PC here was just a typo.

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


1 Files Affected:

- (modified) clang/lib/AST/ByteCode/InterpFrame.cpp (+1-1) 


``diff
diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp 
b/clang/lib/AST/ByteCode/InterpFrame.cpp
index 20f67d9b1fd425..48a3db055c6c9b 100644
--- a/clang/lib/AST/ByteCode/InterpFrame.cpp
+++ b/clang/lib/AST/ByteCode/InterpFrame.cpp
@@ -244,7 +244,7 @@ SourceInfo InterpFrame::getSource(CodePtr PC) const {
 
 const Expr *InterpFrame::getExpr(CodePtr PC) const {
   if (Func && !funcHasUsableBody(Func) && Caller)
-return Caller->getExpr(PC);
+return Caller->getExpr(RetPC);
 
   return S.getExpr(Func, PC);
 }

``




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


[clang] [clang][bytecode][NFC] Remove unused function (PR #125201)

2025-01-31 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/125201

... and an unused include.

>From 082aa4251b59288275dc08e69ab70024fa9726c6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 31 Jan 2025 12:20:22 +0100
Subject: [PATCH] [clang][bytecode][NFC] Remove unused function

... and an unused include.
---
 clang/lib/AST/ByteCode/EvalEmitter.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/clang/lib/AST/ByteCode/EvalEmitter.h 
b/clang/lib/AST/ByteCode/EvalEmitter.h
index e7c9e80d75d934..2cac2ba2ef2212 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.h
+++ b/clang/lib/AST/ByteCode/EvalEmitter.h
@@ -17,7 +17,6 @@
 #include "InterpState.h"
 #include "PrimType.h"
 #include "Source.h"
-#include "llvm/Support/Error.h"
 
 namespace clang {
 namespace interp {
@@ -42,8 +41,6 @@ class EvalEmitter : public SourceMapper {
   /// Clean up all resources.
   void cleanup();
 
-  InterpState &getState() { return S; }
-
 protected:
   EvalEmitter(Context &Ctx, Program &P, State &Parent, InterpStack &Stk);
 

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


[clang] [clang] Support member function poiners in Decl::getFunctionType() (PR #125077)

2025-01-31 Thread Benjamin Maxwell via cfe-commits

https://github.com/MacDue updated 
https://github.com/llvm/llvm-project/pull/125077

>From 620bb22d1b44f3c60e15d2847fdcfd3dd9aafa51 Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell 
Date: Thu, 30 Jan 2025 15:08:24 +
Subject: [PATCH 1/2] [clang] Support member function poiners in
 Decl::getFunctionType()

This seems consistent with the documentation which claims it:

```
/// Looks through the Decl's underlying type to extract a FunctionType
/// when possible. Will return null if the type underlying the Decl does not
/// have a FunctionType.
const FunctionType *getFunctionType(bool BlocksToo = true) const;
```

Without this, attaching attributes (which use `HasFunctionProto`) to
member function pointers errors with:

```
error: '' only applies to non-K&R-style functions
```

...which does not really make sense, since member functions are not
K&C functions.

With this change the Arm SME TypeAttrs work correctly on member function
pointers.

Note, however, that not all attributes work correctly when applied to
function pointers or member function pointers. For example,
`alloc_align` crashes when applied to a function pointer (on truck):
https://godbolt.org/z/YvMhnhKfx (as it only expects a `FunctionDecl`
not a `ParmVarDecl`). The same crash applies to member function pointers
(for the same reason).
---
 clang/include/clang/Basic/Attr.td |  2 +-
 clang/lib/AST/DeclBase.cpp|  2 +
 clang/test/AST/attr-print-emit.cpp|  5 +++
 ...sme-attributes-member-function-pointer.cpp | 37 +++
 .../CodeGen/xfail-alloc-align-fn-pointers.cpp | 10 +
 5 files changed, 55 insertions(+), 1 deletion(-)
 create mode 100644 
clang/test/CodeGen/AArch64/sme-attributes-member-function-pointer.cpp
 create mode 100644 clang/test/CodeGen/xfail-alloc-align-fn-pointers.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index f4ba2bc3c6de31..2a3a29bd2ee1cf 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -198,7 +198,7 @@ def OpenCLKernelFunction
 // inclusive nature of subject testing).
 def HasFunctionProto : SubsetSubjectgetFunctionType(true) != nullptr &&
-  isa(S->getFunctionType())) ||
+   
isa(S->getFunctionType())) ||
isa(S) ||
isa(S)}],
  "non-K&R-style functions">;
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index c0a331d18cab8d..fc16448cf9e905 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -1203,6 +1203,8 @@ const FunctionType *Decl::getFunctionType(bool BlocksToo) 
const {
 
   if (Ty->isFunctionPointerType())
 Ty = Ty->castAs()->getPointeeType();
+  else if (Ty->isMemberFunctionPointerType())
+Ty = Ty->castAs()->getPointeeType();
   else if (Ty->isFunctionReferenceType())
 Ty = Ty->castAs()->getPointeeType();
   else if (BlocksToo && Ty->isBlockPointerType())
diff --git a/clang/test/AST/attr-print-emit.cpp 
b/clang/test/AST/attr-print-emit.cpp
index a9bca6778d0f1a..77826f8f9af098 100644
--- a/clang/test/AST/attr-print-emit.cpp
+++ b/clang/test/AST/attr-print-emit.cpp
@@ -91,3 +91,8 @@ ANNOTATE_ATTR NONNULL_ATTR void 
fn_non_null_annotated_attr(int *) __attribute__(
 
 [[gnu::nonnull(1)]] [[gnu::always_inline]] void cxx11_attr(int*) ANNOTATE_ATTR;
 // CHECK: {{\[\[}}gnu::nonnull(1)]] {{\[\[}}gnu::always_inline]] void 
cxx11_attr(int *) __attribute__((annotate("Annotated")));
+
+struct Foo;
+
+// CHECK: void as_member_fn_ptr(int *(Foo::*member)(int) 
__attribute__((alloc_size(1;
+void as_member_fn_ptr(int* (Foo::*member)(int)  
__attribute__((alloc_size(1;
diff --git 
a/clang/test/CodeGen/AArch64/sme-attributes-member-function-pointer.cpp 
b/clang/test/CodeGen/AArch64/sme-attributes-member-function-pointer.cpp
new file mode 100644
index 00..ee784c816a0606
--- /dev/null
+++ b/clang/test/CodeGen/AArch64/sme-attributes-member-function-pointer.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -triple aarch64 -target-feature +sme -target-feature +sme2 
-x c++ -std=c++20  -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK
+
+struct TestStruct;
+
+__arm_new("za", "zt0") void test(TestStruct& TS,
+  void (TestStruct::*streaming_member_ptr)() __arm_streaming,
+  void (TestStruct::*streaming_compat_member)() __arm_streaming_compatible,
+  void (TestStruct::*arm_in_member)() __arm_in("za", "zt0"),
+  void (TestStruct::*arm_inout_member)() __arm_inout("za", "zt0"),
+  void (TestStruct::*arm_preserves_member)() __arm_preserves("za", "zt0"),
+  void (TestStruct::*arm_agnostic_member)() __arm_agnostic("sme_za_state")) {
+
+  // CHECK: call void %{{.*}} [[STREAMING_MEMBER_CALL_ATTRS:#.+]]
+  (TS.*streaming_member_ptr)();
+
+  // CHECK: call void %{{.*}} [[STREAMING_COMPAT_MEMBER_CALL_ATTRS:#.+]]
+  (TS.*streaming_compat_member)();
+
+  // CHECK: cal

[clang] [clang][bytecode][NFC] Remove unused function (PR #125201)

2025-01-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

... and an unused include.

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


1 Files Affected:

- (modified) clang/lib/AST/ByteCode/EvalEmitter.h (-3) 


``diff
diff --git a/clang/lib/AST/ByteCode/EvalEmitter.h 
b/clang/lib/AST/ByteCode/EvalEmitter.h
index e7c9e80d75d9345..2cac2ba2ef22129 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.h
+++ b/clang/lib/AST/ByteCode/EvalEmitter.h
@@ -17,7 +17,6 @@
 #include "InterpState.h"
 #include "PrimType.h"
 #include "Source.h"
-#include "llvm/Support/Error.h"
 
 namespace clang {
 namespace interp {
@@ -42,8 +41,6 @@ class EvalEmitter : public SourceMapper {
   /// Clean up all resources.
   void cleanup();
 
-  InterpState &getState() { return S; }
-
 protected:
   EvalEmitter(Context &Ctx, Program &P, State &Parent, InterpStack &Stk);
 

``




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


[clang] [clang] Support member function poiners in Decl::getFunctionType() (PR #125077)

2025-01-31 Thread Benjamin Maxwell via cfe-commits

MacDue wrote:

> Maybe the description here should more explicitly state that it looks for 
> function pointers as well as functions...
> 
> >

Good idea :+1: I've attempted to clarify what this function does now (in the 
doc comment).


> Probably we should fix the error message not to mention K&R unless we 
> actually find a K&R-style function type.


I agree, but I think that can be done it a later patch.

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


[clang] [OpenMP][ASan] Enable ASan Instrumentation for AMDGPUOpenMPToolChain. (PR #124754)

2025-01-31 Thread Amit Kumar Pandey via cfe-commits

https://github.com/ampandey-1995 updated 
https://github.com/llvm/llvm-project/pull/124754

>From 741fcf90830c6a30be851c43924e9ab95c40b8a7 Mon Sep 17 00:00:00 2001
From: Amit Pandey 
Date: Tue, 28 Jan 2025 15:15:01 +0530
Subject: [PATCH 1/3] [OpenMP][ASan] Enable ASan Instrumentation for
 AMDGPUOpenMPToolChain.

Enable device code ASan instrumentation for openmp offload applications
using option '-fsanitize=address'.
---
 clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp  | 16 -
 .../Driver/amdgpu-openmp-sanitize-options.c   | 58 +++
 2 files changed, 72 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Driver/amdgpu-openmp-sanitize-options.c

diff --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp 
b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
index 2b8917106afc14..243d9aac019498 100644
--- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -37,6 +37,16 @@ AMDGPUOpenMPToolChain::AMDGPUOpenMPToolChain(const Driver &D,
   // Lookup binaries into the driver directory, this is used to
   // discover the 'amdgpu-arch' executable.
   getProgramPaths().push_back(getDriver().Dir);
+  // Diagnose unsupported sanitizer options only once.
+  if (!Args.hasFlag(options::OPT_fgpu_sanitize, options::OPT_fno_gpu_sanitize,
+true))
+return;
+  for (auto *A : Args.filtered(options::OPT_fsanitize_EQ)) {
+SanitizerMask K = parseSanitizerValue(A->getValue(), 
/*AllowGroups=*/false);
+if (K != SanitizerKind::Address)
+  D.getDiags().Report(clang::diag::warn_drv_unsupported_option_for_target)
+  << A->getAsString(Args) << getTriple().str();
+  }
 }
 
 void AMDGPUOpenMPToolChain::addClangTargetOptions(
@@ -72,9 +82,11 @@ llvm::opt::DerivedArgList 
*AMDGPUOpenMPToolChain::TranslateArgs(
   const OptTable &Opts = getDriver().getOpts();
 
   if (DeviceOffloadKind == Action::OFK_OpenMP) {
-for (Arg *A : Args)
-  if (!llvm::is_contained(*DAL, A))
+for (Arg *A : Args) {
+  if (!shouldSkipSanitizeOption(*this, Args, BoundArch, A) &&
+  !llvm::is_contained(*DAL, A))
 DAL->append(A);
+}
 
 if (!DAL->hasArg(options::OPT_march_EQ)) {
   StringRef Arch = BoundArch;
diff --git a/clang/test/Driver/amdgpu-openmp-sanitize-options.c 
b/clang/test/Driver/amdgpu-openmp-sanitize-options.c
new file mode 100644
index 00..03adeb8e6a7833
--- /dev/null
+++ b/clang/test/Driver/amdgpu-openmp-sanitize-options.c
@@ -0,0 +1,58 @@
+// REQUIRES: x86-registered-target, amdgpu-registered-target
+
+// Fail on invalid ROCm Path.
+// RUN:   not %clang -### -fopenmp --offload-arch=gfx908:xnack+ 
-fsanitize=address -fgpu-sanitize -nogpuinc --rocm-path=%S/Inputs/rocm-invalid  
%s 2>&1 \
+// RUN:   | FileCheck --check-prefix=FAIL %s
+
+// Enable multiple sanitizer's apart from ASan with invalid rocm-path.
+// RUN:   not %clang -### -fopenmp --offload-arch=gfx908:xnack+ 
-fsanitize=address -fsanitize=leak -fgpu-sanitize 
--rocm-path=%S/Inputs/rocm-invalid -nogpuinc  %s 2>&1 \
+// RUN:   | FileCheck --check-prefixes=UNSUPPORTED,FAIL %s
+
+// Memory, Leak, UndefinedBehaviour and Thread Sanitizer are not supported.
+// RUN:   %clang -### -fopenmp --offload-arch=gfx908:xnack+ -fsanitize=address 
-fsanitize=leak -fgpu-sanitize --rocm-path=%S/Inputs/rocm -nogpuinc  %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=UNSUPPORTED %s
+
+
+// ASan Enabled Test Cases
+// ASan enabled for amdgpu-arch [gfx908]
+// RUN:   %clang -### -fopenmp --offload-arch=gfx908 -fsanitize=address 
-fgpu-sanitize --rocm-path=%S/Inputs/rocm %s 2>&1 \
+// RUN:   | FileCheck -check-prefixes=NOXNACK,GPUSAN %s
+
+// ASan enabled for amdgpu-arch [gfx908:xnack-]
+// RUN:   %clang -### -fopenmp --offload-arch=gfx908:xnack- -fsanitize=address 
-fgpu-sanitize --rocm-path=%S/Inputs/rocm %s 2>&1 \
+// RUN:   | FileCheck -check-prefixes=XNACKNEG,GPUSAN %s
+
+// ASan enabled for amdgpu-arch [gfx908:xnack+]
+// RUN:   %clang -### -fopenmp --offload-arch=gfx908:xnack+ -fsanitize=address 
-fgpu-sanitize --rocm-path=%S/Inputs/rocm %s 2>&1 \
+// RUN:   | FileCheck -check-prefixes=GPUSAN %s
+
+// ASan Disabled Test Cases
+// ASan disabled for amdgpu-arch [gfx908]
+// RUN:   %clang -### -fopenmp --offload-arch=gfx908 -fsanitize=address 
-fno-gpu-sanitize --rocm-path=%S/Inputs/rocm %s 2>&1 \
+// RUN:   | FileCheck -check-prefixes=NOGPUSAN %s
+
+// ASan disabled for amdgpu-arch [gfx908:xnack-]
+// RUN:   %clang -### -fopenmp --offload-arch=gfx908:xnack- -fsanitize=address 
-fno-gpu-sanitize --rocm-path=%S/Inputs/rocm %s 2>&1 \
+// RUN:   | FileCheck -check-prefixes=NOGPUSAN %s
+
+// ASan disabled for amdgpu-arch [gfx908:xnack+]
+// RUN:   %clang -### -fopenmp --offload-arch=gfx908:xnack+ -fsanitize=address 
-fno-gpu-sanitize --rocm-path=%S/Inputs/rocm %s 2>&1 \
+// RUN:   | FileCheck -check-prefixes=NOGPUSAN %s
+
+// FAIL-DAG: error: cannot find ROCm device library for ABI version 5; provide 
its path via '--rocm-path' or '--rocm-device-lib-path', o

[clang] [clang:frontend] Move helper functions to common location for SemaSPIRV (PR #125045)

2025-01-31 Thread via cfe-commits

Sirraide wrote:

Yup, looking at the logs, there’s definitely an error somewhere in this pr 
(don’t really have the time to take a closer look at it at the moment 
unfortunately)

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


[clang] [ARM] Empty structs are 1-byte for C++ ABI (PR #124762)

2025-01-31 Thread Oliver Stannard via cfe-commits

ostannard wrote:

/cherry-pick 97b066f4e92a0df46b9d10721e988210f0d1afb6

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


[clang] [ARM] Empty structs are 1-byte for C++ ABI (PR #124762)

2025-01-31 Thread Oliver Stannard via cfe-commits

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


[clang] [ARM] Empty structs are 1-byte for C++ ABI (PR #124762)

2025-01-31 Thread via cfe-commits

llvmbot wrote:


>/cherry-pick 97b066f4e92a0df46b9d10721e988210f0d1afb6

Error: Command failed due to missing milestone.

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


[clang] [ARM] Empty structs are 1-byte for C++ ABI (PR #124762)

2025-01-31 Thread via cfe-commits

llvmbot wrote:

/pull-request llvm/llvm-project#125191

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


[clang] [Clang] Add GCC's __builtin_stack_address() to Clang. (PR #121332)

2025-01-31 Thread via cfe-commits


@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple i686-unknown-unknown -emit-llvm -o - %s | FileCheck 
-check-prefix=X86 %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | 
FileCheck -check-prefix=X86_64 %s
+// RUN: %clang_cc1 -triple riscv32-unknown-unknown -emit-llvm -o - %s | 
FileCheck -check-prefix=RISCV_ARM_32 %s
+// RUN: %clang_cc1 -triple riscv64-unknown-unknown -emit-llvm -o - %s | 
FileCheck -check-prefix=RISCV_ARM_64 %s
+// RUN: %clang_cc1 -triple arm-unknown-unknown -emit-llvm -o - %s | FileCheck 
-check-prefix=RISCV_ARM_32 %s
+// RUN: %clang_cc1 -triple arm64-unknown-unknown -emit-llvm -o - %s | 
FileCheck -check-prefix=RISCV_ARM_64 %s
+
+void* a() {
+  // X86_64: [[INT_SP:%.*]] = call i64 @llvm.read_register.i64(metadata 
[[SPREG:![0-9]+]])
+  // X86_64: inttoptr i64 [[INT_SP]]
+  // X86_64: [[SPREG]] = !{!"rsp"}
+  //
+  // X86: [[INT_SP:%.*]] = call i32 @llvm.read_register.i32(metadata 
[[SPREG:![0-9]+]])
+  // X86: inttoptr i32 [[INT_SP]]
+  // X86: [[SPREG]] = !{!"esp"}
+  //
+  // RISCV_ARM_32: [[INT_SP:%.*]] = call i32 @llvm.read_register.i32(metadata 
[[SPREG:![0-9]+]])
+  // RISCV_ARM_32: inttoptr i32 [[INT_SP]]
+  // RISCV_ARM_32: [[SPREG]] = !{!"sp"}
+  //
+  // RISCV_ARM_64: [[INT_SP:%.*]] = call i64 @llvm.read_register.i64(metadata 
[[SPREG:![0-9]+]])
+  // RISCV_ARM_64: inttoptr i64 [[INT_SP]]
+  // RISCV_ARM_64: [[SPREG]] = !{!"sp"}
+  return __builtin_stack_address();

aalhwc wrote:

Noted! Thanks.

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


[clang] [Clang] Add GCC's __builtin_stack_address() to Clang. (PR #121332)

2025-01-31 Thread via cfe-commits


@@ -899,6 +899,12 @@ def FrameAddress : Builtin {
   let Prototype = "void*(_Constant unsigned int)";
 }
 
+def StackAddress : Builtin {
+  let Spellings = ["__builtin_stack_address"];
+  let Attributes = [NoThrow];

aalhwc wrote:

I may be wrong here but I am not sure if this is an instance of a `Const` or 
even `Pure` function. Two consecutive calls to `__builtin_stack_address` can 
return different values which makes it im`Pure`. Since `Const` functions are a 
subset of `Pure` functions, it also can't be `Const`. This is based on 
[GCC](https://gcc.gnu.org/onlinedocs/gcc-4.0.0/gcc/Function-Attributes.html)'s 
documentation regarding function attributes. 

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


[clang] [ARM] Empty structs are 1-byte for C++ ABI (PR #124762)

2025-01-31 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-offload-amdgpu-runtime` running on `omp-vega20-0` while building 
`clang` at step 7 "Add check check-offload".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/30/builds/14992


Here is the relevant piece of the build log for the reference

```
Step 7 (Add check check-offload) failure: test (failure)
...
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug53727.cpp 
(999 of 1008)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug50022.cpp 
(1000 of 1008)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/test_libc.cpp 
(1001 of 1008)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/wtime.c (1002 
of 1008)
PASS: libomptarget :: x86_64-unknown-linux-gnu :: offloading/bug49021.cpp (1003 
of 1008)
PASS: libomptarget :: x86_64-unknown-linux-gnu :: 
offloading/std_complex_arithmetic.cpp (1004 of 1008)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: 
offloading/complex_reduction.cpp (1005 of 1008)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: offloading/bug49021.cpp 
(1006 of 1008)
PASS: libomptarget :: x86_64-unknown-linux-gnu-LTO :: 
offloading/std_complex_arithmetic.cpp (1007 of 1008)
TIMEOUT: libomptarget :: amdgcn-amd-amdhsa :: offloading/ctor_dtor.cpp (1008 of 
1008)
 TEST 'libomptarget :: amdgcn-amd-amdhsa :: 
offloading/ctor_dtor.cpp' FAILED 
Exit Code: -9
Timeout: Reached timeout of 100 seconds

Command Output (stdout):
--
# RUN: at line 1
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang++ 
-fopenmp-I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
  -nogpulib 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib 
 -fopenmp-targets=amdgcn-amd-amdhsa 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/offloading/ctor_dtor.cpp
 -o 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/ctor_dtor.cpp.tmp
 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
 && 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/ctor_dtor.cpp.tmp
 | 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/offloading/ctor_dtor.cpp
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang++ 
-fopenmp -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -nogpulib 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload
 
-Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib 
-fopenmp-targets=amdgcn-amd-amdhsa 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/offloading/ctor_dtor.cpp
 -o 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/ctor_dtor.cpp.tmp
 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
# note: command had no output on stdout or stderr
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/offloading/Output/ctor_dtor.cpp.tmp
# note: command had no output on stdout or stderr
# executed command: 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck 
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/offloading/ctor_dtor.cpp
# note: command had no output on stdout or stderr
# RUN: at line 2
/home/ompworke

[clang] [TableGen] Migrate away from PointerUnion::dyn_cast (NFC) (PR #125158)

2025-01-31 Thread Nikita Popov via cfe-commits

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


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


[clang] [Clang] Add GCC's __builtin_stack_address() to Clang. (PR #121332)

2025-01-31 Thread via cfe-commits


@@ -4782,6 +4857,34 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 Function *F = CGM.getIntrinsic(Intrinsic::frameaddress, AllocaInt8PtrTy);
 return RValue::get(Builder.CreateCall(F, Depth));
   }
+  case Builtin::BI__builtin_stack_address: {
+switch (getTarget().getTriple().getArch()) {
+case Triple::x86:
+  return RValue::get(EmitSpecialRegisterBuiltin(
+  *this, E, Int32Ty, VoidPtrTy, NormalRead, "esp"));
+case Triple::x86_64:
+  return RValue::get(EmitSpecialRegisterBuiltin(
+  *this, E, Int64Ty, VoidPtrTy, NormalRead, "rsp"));
+case Triple::arm:
+case Triple::armeb:
+case Triple::thumb:
+case Triple::thumbeb:
+case Triple::aarch64:
+case Triple::aarch64_be:
+case Triple::aarch64_32:
+case Triple::riscv32:
+case Triple::riscv64: {
+  llvm::IntegerType *SPRegIntTy =
+  getTarget().getTriple().getArchPointerBitWidth() == 64 ? Int64Ty
+ : Int32Ty;
+  return RValue::get(EmitSpecialRegisterBuiltin(
+  *this, E, SPRegIntTy, VoidPtrTy, NormalRead, "sp"));
+}
+default:
+  ErrorUnsupported(E, "__builtin_stack_address");

aalhwc wrote:

Noted! Thanks!

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


[clang] [clang:frontend] Move helper functions to common location for SemaSPIRV (PR #125045)

2025-01-31 Thread via cfe-commits

Sirraide wrote:

Well, I’ve encountered a bunch of failing tests lately, but the fact that SPIRV 
and HLSL tests are failing is a bit suspicious

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


[clang] [Clang] Add GCC's __builtin_stack_address() to Clang. (PR #121332)

2025-01-31 Thread via cfe-commits

aalhwc wrote:

Thanks for all the comments!

> Should we be supporting STACK_ADDRESS_OFFSET similar to what GCC does?

Apologies for missing that. I'll have it ready before the next patch update.

> Other builtins [...] map onto an llvm intrinsic [...] What's the reason for 
> not following this design for __builtin_stack_address?

> it feels like something that should be expressed portably as an IR intrinsic 
> and then get lowered in the backend [...]

I wasn't aware of the direct mapping between the front end intrinsics and the 
llvm intrinsics. Implementing the llvm intrinsic `llvm.stackaddress` makes 
perfect sense. I'll try to have it ready before the next patch update. Thanks!

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


[clang] [clang] Support member function poiners in Decl::getFunctionType() (PR #125077)

2025-01-31 Thread Benjamin Maxwell via cfe-commits

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


[clang] [TBAA] Don't emit pointer-tbaa for void pointers. (PR #122116)

2025-01-31 Thread Florian Hahn via cfe-commits

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


[clang] 77d3f8a - [TBAA] Don't emit pointer-tbaa for void pointers. (#122116)

2025-01-31 Thread via cfe-commits

Author: Florian Hahn
Date: 2025-01-31T11:38:14Z
New Revision: 77d3f8a92564b533a3c60a8c8e0657c38fd88ba1

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

LOG: [TBAA] Don't emit pointer-tbaa for void pointers. (#122116)

While there are no special rules in the standards regarding void
pointers and strict aliasing, emitting distinct tags for void pointers
break some common idioms and there is no good alternative to re-write
the code without strict-aliasing violations. An example is to count the
entries in an array of pointers:

int count_elements(void * values) {
  void **seq = values;
  int count;
  for (count = 0; seq && seq[count]; count++);
  return count;
}

https://clang.godbolt.org/z/8dTv51v8W

An example in the wild is from
https://github.com/llvm/llvm-project/issues/119099

This patch avoids emitting distinct tags for void pointers, to avoid
those idioms causing mis-compiles for now.

Fixes https://github.com/llvm/llvm-project/issues/119099.
Fixes https://github.com/llvm/llvm-project/issues/122537.

PR: https://github.com/llvm/llvm-project/pull/122116

Added: 


Modified: 
clang/docs/UsersManual.rst
clang/lib/CodeGen/CodeGenTBAA.cpp
clang/test/CodeGen/tbaa-pointers.c
clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
clang/unittests/CodeGen/TBAAMetadataTest.cpp

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index a56c9425ebb757..943a9218ccbc25 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2489,6 +2489,82 @@ are listed below.
 
 $ clang -fuse-ld=lld -Oz -Wl,--icf=safe -fcodegen-data-use code.cc
 
+.. _strict_aliasing:
+
+Strict Aliasing
+---
+
+The C and C++ standards require accesses to objects in memory to use l-values 
of
+an appropriate type for the object. This is called *strict aliasing* or
+*type-based alias analysis*. Strict aliasing enhances a variety of powerful
+memory optimizations, including reordering, combining, and eliminating memory
+accesses. These optimizations can lead to unexpected behavior in code that
+violates the strict aliasing rules. For example:
+
+.. code-block:: c++
+
+void advance(size_t *index, double *data) {
+  double value = data[*index];
+  /* Clang may assume that this store does not change the contents of 
`data`. */
+  *index += 1;
+  /* Clang may assume that this store does not change the contents of 
`index`. */
+  data[*index] = value;
+  /* Either of these facts may create significant optimization 
opportunities
+   if Clang is able to inline this function. */
+  }
+
+Strict aliasing can be explicitly enabled with ``-fstrict-aliasing`` and
+disabled with ``-fno-strict-aliasing``. ``clang-cl`` defaults to
+``-fno-strict-aliasing``; see . Otherwise, Clang defaults to 
``-fstrict-aliasing``.
+
+C and C++ specify slightly 
diff erent rules for strict aliasing. To improve
+language interoperability, Clang allows two types to alias if either language
+would permit it. This includes applying the C++ similar types rule to C,
+allowing ``int **`` to alias ``int const * const *``. Clang also relaxes the
+standard aliasing rules in the following ways:
+
+* All integer types of the same size are permitted to alias each other,
+  including signed and unsigned types.
+* ``void*`` is permitted to alias any pointer type, ``void**`` is permitted to
+  alias any pointer to pointer type, and so on.
+
+Code which violates strict aliasing has undefined behavior. A program that
+works in one version of Clang may not work in another because of changes to the
+optimizer. Clang provides a :doc:`TypeSanitizer` to help detect
+violations of the strict aliasing rules, but it is currently still 
experimental.
+Code that is known to violate strict aliasing should generally be built with
+``-fno-strict-aliasing`` if the violation cannot be fixed.
+
+Clang supports several ways to fix a violation of strict aliasing:
+
+* L-values of the character types ``char`` and ``unsigned char`` (as well as
+  other types, depending on the standard) are permitted to access objects of
+  any type.
+
+* Library functions such as ``memcpy`` and ``memset`` are specified as treating
+  memory as characters and therefore are not limited by strict aliasing. If a
+  value of one type must be reinterpreted as another (e.g. to read the bits of 
a
+  floating-point number), use ``memcpy`` to copy the representation to an 
object
+  of the destination type. This has no overhead over a direct l-value access
+  because Clang should reliably optimize calls to these functions to use simple
+  loads and stores when they are used with small constant sizes.
+
+* The attribute ``may_alias`` can be added to a ``typedef`` to give l-values of
+

[clang] [TBAA] Don't emit pointer-tbaa for void pointers. (PR #122116)

2025-01-31 Thread Florian Hahn via cfe-commits

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


[clang] [Clang][Sema] Add special handling of mfloat8 in initializer lists (PR #125097)

2025-01-31 Thread via cfe-commits

https://github.com/Lukacma updated 
https://github.com/llvm/llvm-project/pull/125097

>From 021481832a31f7d6c01f6faec5140498641eb37b Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Thu, 30 Jan 2025 17:29:48 +
Subject: [PATCH 1/2] [Clang][NFC] Add special handling of mfloat8 in
 initializer lists

---
 clang/lib/AST/ExprConstant.cpp |  5 ++
 clang/lib/Sema/SemaInit.cpp|  2 +-
 clang/test/CodeGen/AArch64/fp8-init-list.c | 59 ++
 3 files changed, 65 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/AArch64/fp8-init-list.c

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 0e41e3dbc8a32a..e11b92956b411d 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11172,6 +11172,11 @@ VectorExprEvaluator::VisitInitListExpr(const 
InitListExpr *E) {
   QualType EltTy = VT->getElementType();
   SmallVector Elements;
 
+  // MFloat8 type doesn't have constants and thus constant folding 
+  // is impossible.
+  if (EltTy->isMFloat8Type())
+return false;
+
   // The number of initializers can be less than the number of
   // vector elements. For OpenCL, this can be due to nested vector
   // initialization. For GCC compatibility, missing trailing elements
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index b95cbbf4222056..505d9df8d44feb 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -1589,7 +1589,7 @@ void InitListChecker::CheckSubElementType(const 
InitializedEntity &Entity,
 
   } else {
 assert((ElemType->isRecordType() || ElemType->isVectorType() ||
-ElemType->isOpenCLSpecificType()) && "Unexpected type");
+ElemType->isOpenCLSpecificType() || ElemType->isMFloat8Type()) && 
"Unexpected type");
 
 // C99 6.7.8p13:
 //
diff --git a/clang/test/CodeGen/AArch64/fp8-init-list.c 
b/clang/test/CodeGen/AArch64/fp8-init-list.c
new file mode 100644
index 00..8b4b31a71c46a2
--- /dev/null
+++ b/clang/test/CodeGen/AArch64/fp8-init-list.c
@@ -0,0 +1,59 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+
+// RUN: %clang_cc1-triple aarch64-none-linux-gnu -target-feature +neon 
-O2 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -x c++ -triple aarch64-none-linux-gnu -target-feature +neon 
-O2 -Werror -Wall -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK-CXX
+
+// RUN: %clang_cc1-triple aarch64-none-linux-gnu -target-feature +neon 
-O2 -Werror -Wall -S -o /dev/null %s
+
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+// CHECK-LABEL: define dso_local <8 x i8> @vector_init_test(
+// CHECK-SAME: <1 x i8> [[X:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[VECINIT14:%.*]] = shufflevector <1 x i8> [[X]], <1 x i8> 
poison, <8 x i32> zeroinitializer
+// CHECK-NEXT:ret <8 x i8> [[VECINIT14]]
+//
+// CHECK-CXX-LABEL: define dso_local <8 x i8> @_Z16vector_init_testu6__mfp8(
+// CHECK-CXX-SAME: <1 x i8> [[X:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-CXX-NEXT:  [[ENTRY:.*:]]
+// CHECK-CXX-NEXT:[[VECINIT14:%.*]] = shufflevector <1 x i8> [[X]], <1 x 
i8> poison, <8 x i32> zeroinitializer
+// CHECK-CXX-NEXT:ret <8 x i8> [[VECINIT14]]
+//
+mfloat8x8_t vector_init_test(__mfp8 x) {
+   return (mfloat8x8_t) {x, x, x, x, x, x, x, x};
+}
+
+struct S {
+__mfp8 x;
+};
+
+struct S s;
+
+// CHECK-LABEL: define dso_local void @f(
+// CHECK-SAME: <1 x i8> [[X:%.*]]) local_unnamed_addr #[[ATTR1:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:store <1 x i8> [[X]], ptr @s, align 1, !tbaa 
[[TBAA2:![0-9]+]]
+// CHECK-NEXT:ret void
+//
+// CHECK-CXX-LABEL: define dso_local void @_Z1fu6__mfp8(
+// CHECK-CXX-SAME: <1 x i8> [[X:%.*]]) local_unnamed_addr #[[ATTR1:[0-9]+]] {
+// CHECK-CXX-NEXT:  [[ENTRY:.*:]]
+// CHECK-CXX-NEXT:store <1 x i8> [[X]], ptr @s, align 1, !tbaa 
[[TBAA2:![0-9]+]]
+// CHECK-CXX-NEXT:ret void
+//
+void f(__mfp8 x) {
+s = (struct S){x};
+}
+//.
+// CHECK: [[TBAA2]] = !{[[META3:![0-9]+]], [[META3]], i64 0}
+// CHECK: [[META3]] = !{!"__mfp8", [[META4:![0-9]+]], i64 0}
+// CHECK: [[META4]] = !{!"omnipotent char", [[META5:![0-9]+]], i64 0}
+// CHECK: [[META5]] = !{!"Simple C/C++ TBAA"}
+//.
+// CHECK-CXX: [[TBAA2]] = !{[[META3:![0-9]+]], [[META3]], i64 0}
+// CHECK-CXX: [[META3]] = !{!"__mfp8", [[META4:![0-9]+]], i64 0}
+// CHECK-CXX: [[META4]] = !{!"omnipotent char", [[META5:![0-9]+]], i64 0}
+// CHECK-CXX: [[META5]] = !{!"Simple C++ TBAA"}
+//.

>From b36fcc5e312cbef5988720a9f90b2433746a3ce8 Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Fri, 31 Jan 2025 11:38:09 +
Subject: [PATCH 2/2] Fix formatting

---
 clang/lib/AST/ExprConstant.cpp | 2 +-
 clang/lib/Sema/SemaInit.cpp| 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/Ex

[clang] [Clang] Add GCC's __builtin_stack_address() to Clang. (PR #121332)

2025-01-31 Thread Aaron Ballman via cfe-commits


@@ -899,6 +899,12 @@ def FrameAddress : Builtin {
   let Prototype = "void*(_Constant unsigned int)";
 }
 
+def StackAddress : Builtin {
+  let Spellings = ["__builtin_stack_address"];
+  let Attributes = [NoThrow];

AaronBallman wrote:

I wasn't 100% sure; I thought it meant two consecutive calls from the same 
context, but I can never remember that detail. I'm fine leaving it off though 
-- we can easily add it later if we find there's a benefit. Thanks!

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


[clang] [CIR] Fix some clang-tidy problems in CIR (PR #125128)

2025-01-31 Thread Aaron Ballman via cfe-commits

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

LGTM

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


[clang] [llvm] [NVPTX] Add tcgen05 alloc/dealloc intrinsics (PR #124961)

2025-01-31 Thread Durgadoss R via cfe-commits

https://github.com/durga4github updated 
https://github.com/llvm/llvm-project/pull/124961

>From 467c3a41badb66b9187864a040c9eeccef1b583c Mon Sep 17 00:00:00 2001
From: Durgadoss R 
Date: Wed, 29 Jan 2025 16:31:06 +0530
Subject: [PATCH] [NVPTX] Add tcgen05 alloc/dealloc intrinsics

This patch adds intrinsics for the tcgen05
alloc/dealloc family of PTX instructions.

This patch also adds addrspace 6 for tensor memory
which is used by these intrinsics.

lit tests are added and verified with a ptxas-12.8
executable.

Documentation for these additions is also added in
NVPTXUsage.rst.

Signed-off-by: Durgadoss R 
---
 clang/lib/Basic/Targets/NVPTX.cpp|   9 +-
 clang/test/CodeGen/target-data.c |   4 +-
 llvm/docs/NVPTXUsage.rst |  98 ++
 llvm/include/llvm/IR/IntrinsicsNVVM.td   |  30 +
 llvm/include/llvm/Support/NVPTXAddrSpace.h   |   1 +
 llvm/lib/Target/NVPTX/NVPTXInstrInfo.td  |   1 +
 llvm/lib/Target/NVPTX/NVPTXIntrinsics.td |  41 ++
 llvm/lib/Target/NVPTX/NVPTXSubtarget.h   |  15 +++
 llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp |   3 +
 llvm/test/CodeGen/NVPTX/tcgen05-alloc.ll | 131 +++
 10 files changed, 327 insertions(+), 6 deletions(-)
 create mode 100644 llvm/test/CodeGen/NVPTX/tcgen05-alloc.ll

diff --git a/clang/lib/Basic/Targets/NVPTX.cpp 
b/clang/lib/Basic/Targets/NVPTX.cpp
index a03f4983b9d0384..017146a9ada14a3 100644
--- a/clang/lib/Basic/Targets/NVPTX.cpp
+++ b/clang/lib/Basic/Targets/NVPTX.cpp
@@ -62,12 +62,13 @@ NVPTXTargetInfo::NVPTXTargetInfo(const llvm::Triple &Triple,
   HasFloat16 = true;
 
   if (TargetPointerWidth == 32)
-resetDataLayout("e-p:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64");
-  else if (Opts.NVPTXUseShortPointers)
 resetDataLayout(
-
"e-p3:32:32-p4:32:32-p5:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64");
+"e-p:32:32-p6:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64");
+  else if (Opts.NVPTXUseShortPointers)
+
resetDataLayout("e-p3:32:32-p4:32:32-p5:32:32-p6:32:32-i64:64-i128:128-v16:"
+"16-v32:32-n16:32:64");
   else
-resetDataLayout("e-i64:64-i128:128-v16:16-v32:32-n16:32:64");
+resetDataLayout("e-p6:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64");
 
   // If possible, get a TargetInfo for our host triple, so we can match its
   // types.
diff --git a/clang/test/CodeGen/target-data.c b/clang/test/CodeGen/target-data.c
index 71eb849433ed40d..fe29aadb1dd532f 100644
--- a/clang/test/CodeGen/target-data.c
+++ b/clang/test/CodeGen/target-data.c
@@ -160,11 +160,11 @@
 
 // RUN: %clang_cc1 -triple nvptx-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=NVPTX
-// NVPTX: target datalayout = 
"e-p:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64"
+// NVPTX: target datalayout = 
"e-p:32:32-p6:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64"
 
 // RUN: %clang_cc1 -triple nvptx64-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=NVPTX64
-// NVPTX64: target datalayout = "e-i64:64-i128:128-v16:16-v32:32-n16:32:64"
+// NVPTX64: target datalayout = 
"e-p6:32:32-i64:64-i128:128-v16:16-v32:32-n16:32:64"
 
 // RUN: %clang_cc1 -triple r600-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=R600
diff --git a/llvm/docs/NVPTXUsage.rst b/llvm/docs/NVPTXUsage.rst
index 64dd2b84a1763e7..dec6ad4e541152a 100644
--- a/llvm/docs/NVPTXUsage.rst
+++ b/llvm/docs/NVPTXUsage.rst
@@ -962,6 +962,104 @@ The ``griddepcontrol`` intrinsics allows the dependent 
grids and prerequisite gr
 For more information, refer 
 `PTX ISA 
`__.
 
+TCGEN05 family of Intrinsics
+
+
+The llvm.nvvm.tcgen05.* intrinsics model the TCGEN05 family of instructions
+exposed by PTX. These intrinsics use 'Tensor Memory' (henceforth ``tmem``).
+NVPTX represents this memory using ``addrspace(6)`` and is always 32-bits.
+
+For more information, refer to the PTX ISA
+``_.
+
+The tensor-memory pointers may only be used with the tcgen05 intrinsics.
+There are specialized load/store instructions provided (tcgen05.ld/st) to
+work with tensor-memory.
+
+See the PTX ISA for more information on tensor-memory load/store instructions
+``_.
+
+'``llvm.nvvm.tcgen05.alloc``'
+^
+
+Syntax:
+"""
+
+.. code-block:: llvm
+
+  declare void @llvm.nvvm.tcgen05.alloc.cg1(ptr %dst, i32 %ncols)
+  declare void @llvm.nvvm.tcgen05.alloc.cg2(ptr %dst, i32 %ncols)
+  declare void @llvm.nvvm.tcgen05.alloc.shared.cg1(ptr addrspace(3) %dst, i32 
%ncols)
+  declare void @llvm.nvvm.tcgen05.alloc.shared.cg2(ptr addrspace(3) %dst, i32 
%ncols)
+
+Overview:
+"
+
+The '``@llvm.nvvm.tcgen05.alloc.*``' intrins

[clang] [StaticAnalyzer] Fix state update in VisitObjCForCollectionStmt (PR #124477)

2025-01-31 Thread Donát Nagy via cfe-commits


@@ -124,24 +124,26 @@ void ExprEngine::VisitObjCForCollectionStmt(const 
ObjCForCollectionStmt *S,
 
   bool isContainerNull = state->isNull(collectionV).isConstrainedTrue();
 
-  ExplodedNodeSet dstLocation;
-  evalLocation(dstLocation, S, elem, Pred, state, elementV, false);
+  ExplodedNodeSet NewPreds; // evalLocation may alter `Pred`
+  evalLocation(NewPreds, S, elem, Pred, state, elementV, false);
 
-  ExplodedNodeSet Tmp;
-  StmtNodeBuilder Bldr(Pred, Tmp, *currBldrCtx);
+  for (ExplodedNode *Pred : NewPreds) {
+ExplodedNodeSet PredSingleton{Pred}, Tmp;
+StmtNodeBuilder Bldr(Pred, Tmp, *currBldrCtx);
 
-  if (!isContainerNull)
-populateObjCForDestinationSet(dstLocation, svalBuilder, S, elem, elementV,
-  SymMgr, currBldrCtx, Bldr,
-  /*hasElements=*/true);
+if (!isContainerNull)
+  populateObjCForDestinationSet(PredSingleton, svalBuilder, S, elem,
+elementV, SymMgr, currBldrCtx, Bldr,
+/*hasElements=*/true);
 
-  populateObjCForDestinationSet(dstLocation, svalBuilder, S, elem, elementV,
-SymMgr, currBldrCtx, Bldr,
-/*hasElements=*/false);
+populateObjCForDestinationSet(PredSingleton, svalBuilder, S, elem, 
elementV,
+  SymMgr, currBldrCtx, Bldr,
+  /*hasElements=*/false);

NagyDonat wrote:

> Can we do this in a separate NFC PR?

Of course, that's completely fine. Thanks in advance for implementing it! 

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


[clang] [Clang] allow restrict qualifier for array types with pointer types as element types (PR #120896)

2025-01-31 Thread Oleksandr T. via cfe-commits

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

>From 295df258043ef5a87ae603eedd308b863bad7b59 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Sun, 22 Dec 2024 15:14:30 +0200
Subject: [PATCH] [Clang] allow restrict qualifier for array types with pointer
 types as element types

---
 clang/docs/ReleaseNotes.rst |  1 +
 clang/lib/Sema/SemaType.cpp |  4 +++-
 clang/test/Sema/types.c | 10 +-
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6b9e1109f3906e..52daea9b8eb2b6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -332,6 +332,7 @@ C Language Changes
 --
 
 - Extend clang's  to define ``LONG_LONG_*`` macros for Android's 
bionic.
+- Clang now allows ``restrict`` qualifier for array types with pointer 
elements (#GH92847).
 
 C2y Feature Support
 ^^^
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 83464c50b4b238..e84daeee679a57 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1595,12 +1595,14 @@ QualType Sema::BuildQualifiedType(QualType T, 
SourceLocation Loc,
 QualType ProblemTy;
 
 if (T->isAnyPointerType() || T->isReferenceType() ||
-T->isMemberPointerType()) {
+T->isMemberPointerType() || T->isArrayType()) {
   QualType EltTy;
   if (T->isObjCObjectPointerType())
 EltTy = T;
   else if (const MemberPointerType *PTy = T->getAs())
 EltTy = PTy->getPointeeType();
+  else if (T->isArrayType())
+EltTy = Context.getBaseElementType(T);
   else
 EltTy = T->getPointeeType();
 
diff --git a/clang/test/Sema/types.c b/clang/test/Sema/types.c
index e0a6ba4f0691b9..4c90634b7ce284 100644
--- a/clang/test/Sema/types.c
+++ b/clang/test/Sema/types.c
@@ -9,20 +9,20 @@ typedef int (*T)[2];
 restrict T x;
 
 typedef int *S[2];
-restrict S y; // expected-error {{restrict requires a pointer or reference 
('S' (aka 'int *[2]') is invalid)}}
-
-
+restrict S y;
 
 // int128_t is available.
 int a(void) {
   __int128_t s;
   __uint128_t t;
-}
+} // expected-warning {{non-void function does not return a value}}
+
 // but not a keyword
 int b(void) {
   int __int128_t;
   int __uint128_t;
-}
+} // expected-warning {{non-void function does not return a value}}
+
 // __int128 is a keyword
 int c(void) {
   __int128 i;

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


[clang] [Clang] disallow attributes on void parameters (PR #124920)

2025-01-31 Thread Aaron Ballman via cfe-commits


@@ -50,8 +50,8 @@ struct testRecoverStrictnessStruct { };
 
 #pragma clang attribute pop
 
-#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = 
any(function, record(unless(is_union)), variable, enum))
-// expected-error@-1 {{attribute 'abi_tag' cannot be applied to 'enum'}}
+#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = 
any(function, record(unless(is_union)), variable, enum)) // expected-warning 
{{attribute 'abi_tag' cannot be applied to a 'void' parameter}}
+   
  // expected-error@-1 
{{attribute 'abi_tag' cannot be applied to 'enum'}}

AaronBallman wrote:

```suggestion
#pragma clang attribute push (__attribute__((abi_tag("a"))), apply_to = 
any(function, record(unless(is_union)), variable, enum))
// expected-warning@-1 {{attribute 'abi_tag' cannot be applied to a 'void' 
parameter}}
// expected-error@-2 {{attribute 'abi_tag' cannot be applied to 'enum'}}
```
I *think* this is actually a bug with the way `clang attribute push` works. A 
`void` parameter is not a variable because it doesn't really declare a 
parameter (there's no object backing the parameter like there is for other 
cases). WDYT @erichkeane?

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


[clang] [Win/X86] Make _m_prefetch[w] builtins to avoid winnt.h conflicts (PR #115099)

2025-01-31 Thread Phoebe Wang via cfe-commits


@@ -146,8 +146,13 @@ let Attributes = [Const, NoThrow, 
RequiredVectorWidth<256>], Features = "avx" in
 // current formulation is based on what was easiest to recognize from the
 // pre-TableGen version.
 
-let Features = "mmx", Attributes = [NoThrow, Const] in {
-  def _mm_prefetch : X86NoPrefixBuiltin<"void(char const *, int)">;
+let Features = "mmx", Header = "immintrin.h", Attributes = [NoThrow, Const] in 
{
+  def _mm_prefetch : X86LibBuiltin<"void(void const *, int)">;
+}
+
+let Features = "mmx", Header = "intrin.h", Attributes = [NoThrow, Const] in {
+  def _m_prefetch : X86LibBuiltin<"void(void *)">;
+  def _m_prefetchw : X86LibBuiltin<"void(void volatile const *)">;

phoebewang wrote:

prefetchw should map to feature prfchw?

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


[clang] [Clang] disallow attributes on void parameters (PR #124920)

2025-01-31 Thread Aaron Ballman via cfe-commits


@@ -10326,6 +10326,15 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
   }
 }
 
+if (FTIHasSingleVoidParameter(FTI)) {
+  ParmVarDecl *Param = cast(FTI.Params[0].Param);
+  if (Param->hasAttrs()) {
+for (const auto *A : Param->attrs())
+  Diag(A->getLoc(), diag::warn_attribute_on_void_param)
+  << A << A->getRange();
+  }

AaronBallman wrote:

```suggestion
  for (const auto *A : Param->attrs())
Diag(A->getLoc(), diag::warn_attribute_on_void_param)
<< A << A->getRange();
```
I forgot that `attrs()` handles the no-attributes case gracefully (it's 
`getAttrs()` that doesn't), so we don't need the extra check.

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


[clang] [Clang] disallow attributes on void parameters (PR #124920)

2025-01-31 Thread Aaron Ballman via cfe-commits


@@ -107,6 +107,8 @@ Removed Compiler Flags
 Attribute Changes in Clang
 --
 
+- Clang now disallows the use of attributes on void parameters. (#GH108819)

AaronBallman wrote:

```suggestion
- Clang now diagnoses use of declaration attributes on void parameters. 
(#GH108819)
```

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


[clang] [clang][bytecode][NFC] Remove unused function (PR #125201)

2025-01-31 Thread Timm Baeder via cfe-commits

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


[clang] [clang][bytecode][NFC] Remove unused function (PR #125201)

2025-01-31 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `flang-aarch64-dylib` 
running on `linaro-flang-aarch64-dylib` while building `clang` at step 5 
"build-unified-tree".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/50/builds/9695


Here is the relevant piece of the build log for the reference

```
Step 5 (build-unified-tree) failure: build (failure)
...
180.361 [1626/1/5173] Building CXX object 
tools/mlir/lib/Dialect/Linalg/IR/CMakeFiles/obj.MLIRLinalgDialect.dir/LinalgOps.cpp.o
180.521 [1625/1/5174] Building CXX object 
tools/mlir/lib/Dialect/Linalg/TransformOps/CMakeFiles/obj.MLIRLinalgTransformOps.dir/DialectExtension.cpp.o
180.710 [1624/1/5175] Building CXX object 
tools/mlir/lib/Dialect/Linalg/IR/CMakeFiles/obj.MLIRLinalgDialect.dir/LinalgDialect.cpp.o
180.813 [1623/1/5176] Building CXX object 
tools/mlir/lib/Dialect/Linalg/TransformOps/CMakeFiles/obj.MLIRLinalgTransformOps.dir/Syntax.cpp.o
180.965 [1622/1/5177] Building CXX object 
tools/mlir/lib/Dialect/Linalg/Transforms/CMakeFiles/obj.MLIRLinalgTransforms.dir/BubbleUpExtractSlice.cpp.o
181.124 [1621/1/5178] Building CXX object 
tools/mlir/lib/Dialect/Linalg/TransformOps/CMakeFiles/obj.MLIRLinalgTransformOps.dir/GPUHeuristics.cpp.o
181.755 [1620/1/5179] Building CXX object 
tools/mlir/lib/Dialect/Linalg/Transforms/CMakeFiles/obj.MLIRLinalgTransforms.dir/DecomposeLinalgOps.cpp.o
181.994 [1619/1/5180] Building CXX object 
tools/mlir/lib/Dialect/Linalg/Transforms/CMakeFiles/obj.MLIRLinalgTransforms.dir/Detensorize.cpp.o
182.101 [1618/1/5181] Building CXX object 
tools/mlir/test/lib/Pass/CMakeFiles/MLIRTestPass.dir/TestDynamicPipeline.cpp.o
194.282 [1617/1/5182] Building CXX object 
tools/mlir/test/lib/Pass/CMakeFiles/MLIRTestPass.dir/TestPassManager.cpp.o
FAILED: 
tools/mlir/test/lib/Pass/CMakeFiles/MLIRTestPass.dir/TestPassManager.cpp.o 
/usr/local/bin/c++ -DGTEST_HAS_RTTI=0 -DMLIR_INCLUDE_TESTS -D_DEBUG 
-D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/tcwg-buildbot/worker/flang-aarch64-dylib/build/tools/mlir/test/lib/Pass 
-I/home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/mlir/test/lib/Pass
 -I/home/tcwg-buildbot/worker/flang-aarch64-dylib/build/tools/mlir/include 
-I/home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/mlir/include 
-I/home/tcwg-buildbot/worker/flang-aarch64-dylib/build/include 
-I/home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/llvm/include 
-I/home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/mlir/test/lib/Pass/../Dialect/Test
 
-I/home/tcwg-buildbot/worker/flang-aarch64-dylib/build/tools/mlir/test/lib/Pass/../Dialect/Test
 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden 
-Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra 
-Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers 
-pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -Wundef -Werror=mismatched-tags -O3 
-DNDEBUG -std=c++17  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT 
tools/mlir/test/lib/Pass/CMakeFiles/MLIRTestPass.dir/TestPassManager.cpp.o -MF 
tools/mlir/test/lib/Pass/CMakeFiles/MLIRTestPass.dir/TestPassManager.cpp.o.d -o 
tools/mlir/test/lib/Pass/CMakeFiles/MLIRTestPass.dir/TestPassManager.cpp.o -c 
/home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/mlir/test/lib/Pass/TestPassManager.cpp
In file included from 
/home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/mlir/test/lib/Pass/TestPassManager.cpp:10:
/home/tcwg-buildbot/worker/flang-aarch64-dylib/llvm-project/mlir/test/lib/Pass/../Dialect/Test/TestOps.h:148:10:
 fatal error: 'TestOps.h.inc' file not found
  148 | #include "TestOps.h.inc"
  |  ^~~
1 error generated.
ninja: build stopped: subcommand failed.

```



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


[clang] [Clang] disallow attributes on void parameters (PR #124920)

2025-01-31 Thread Oleksandr T. via cfe-commits

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

>From bd731e4be65fc9c1746aa6a8f63d206eb54bb2be Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Wed, 29 Jan 2025 15:17:06 +0200
Subject: [PATCH 1/8] [Clang] disallow attributes on void parameters

---
 clang/docs/ReleaseNotes.rst| 2 ++
 clang/lib/Parse/ParseDecl.cpp  | 7 +++
 clang/test/Parser/cxx0x-attributes.cpp | 9 +
 3 files changed, 18 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fafe2807bd388..0c87e52007d546 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -100,6 +100,8 @@ Removed Compiler Flags
 Attribute Changes in Clang
 --
 
+- Clang now disallows the use of attributes on void parameters. (#GH108819)
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index f136d5007e8a5f..0b88dd4449b1e2 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -7986,6 +7986,13 @@ void Parser::ParseParameterDeclarationClause(
 if (getLangOpts().HLSL)
   MaybeParseHLSLAnnotations(DS.getAttributes());
 
+if (ParmDeclarator.getIdentifier() == nullptr &&
+ParmDeclarator.getDeclarationAttributes().size() &&
+ParmDeclarator.getDeclSpec().getTypeSpecType() == DeclSpec::TST_void) {
+  SourceRange AttrRange = ParmDeclarator.getDeclarationAttributes().Range;
+  Diag(AttrRange.getBegin(), diag::err_attributes_not_allowed) << 
AttrRange;
+}
+
 if (Tok.is(tok::kw_requires)) {
   // User tried to define a requires clause in a parameter declaration,
   // which is surely not a function declaration.
diff --git a/clang/test/Parser/cxx0x-attributes.cpp 
b/clang/test/Parser/cxx0x-attributes.cpp
index fad3010c98b9c2..13fcdd142fa841 100644
--- a/clang/test/Parser/cxx0x-attributes.cpp
+++ b/clang/test/Parser/cxx0x-attributes.cpp
@@ -453,3 +453,12 @@ namespace P2361 {
 }
 
 alignas(int) struct AlignAsAttribute {}; // expected-error {{misplaced 
attributes; expected attributes here}}
+
+namespace GH108819 {
+void a([[maybe_unused]] void) {} // expected-error {{an 
attribute list cannot appear here}} \
+ // expected-warning {{use of 
the 'maybe_unused' attribute is a C++17 extension}}
+void b([[deprecated]] void) {}   // expected-error {{an 
attribute list cannot appear here}} \
+ // expected-warning {{use of 
the 'deprecated' attribute is a C++14 extension}}
+void c([[clang::lifetimebound]] void) {} // expected-error {{an 
attribute list cannot appear here}}
+void d([[clang::annotate("a", "b", 1)]] void) {} // expected-error {{an 
attribute list cannot appear here}}
+}

>From 063f76730ebfd289f5340d0d8477a43a5ea965c2 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Wed, 29 Jan 2025 15:54:48 +0200
Subject: [PATCH 2/8] remove unnecessary name check

---
 clang/lib/Parse/ParseDecl.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 0b88dd4449b1e2..934c16c9591520 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -7986,8 +7986,7 @@ void Parser::ParseParameterDeclarationClause(
 if (getLangOpts().HLSL)
   MaybeParseHLSLAnnotations(DS.getAttributes());
 
-if (ParmDeclarator.getIdentifier() == nullptr &&
-ParmDeclarator.getDeclarationAttributes().size() &&
+if (ParmDeclarator.getDeclarationAttributes().size() &&
 ParmDeclarator.getDeclSpec().getTypeSpecType() == DeclSpec::TST_void) {
   SourceRange AttrRange = ParmDeclarator.getDeclarationAttributes().Range;
   Diag(AttrRange.getBegin(), diag::err_attributes_not_allowed) << 
AttrRange;

>From 3f3431513ad59111794953d27e64608b3ce2e6e1 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Wed, 29 Jan 2025 16:07:18 +0200
Subject: [PATCH 3/8] use empty instead of size

---
 clang/lib/Parse/ParseDecl.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 934c16c9591520..963b59565953d4 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -7986,7 +7986,7 @@ void Parser::ParseParameterDeclarationClause(
 if (getLangOpts().HLSL)
   MaybeParseHLSLAnnotations(DS.getAttributes());
 
-if (ParmDeclarator.getDeclarationAttributes().size() &&
+if (!ParmDeclarator.getDeclarationAttributes().empty() &&
 ParmDeclarator.getDeclSpec().getTypeSpecType() == DeclSpec::TST_void) {
   SourceRange AttrRange = ParmDeclarator.getDeclarationAttributes().Range;
   Diag(AttrRange.getBegin(), diag::err_attributes_not_allowed) << 
AttrRange;

>From 9919006df9ec32023b2bf179b72f9ebaf977bd08 Mon Sep 17 00:0

[clang] [Clang] disallow attributes on void parameters (PR #124920)

2025-01-31 Thread Oleksandr T. via cfe-commits

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

>From bd731e4be65fc9c1746aa6a8f63d206eb54bb2be Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Wed, 29 Jan 2025 15:17:06 +0200
Subject: [PATCH 1/7] [Clang] disallow attributes on void parameters

---
 clang/docs/ReleaseNotes.rst| 2 ++
 clang/lib/Parse/ParseDecl.cpp  | 7 +++
 clang/test/Parser/cxx0x-attributes.cpp | 9 +
 3 files changed, 18 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7fafe2807bd388..0c87e52007d546 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -100,6 +100,8 @@ Removed Compiler Flags
 Attribute Changes in Clang
 --
 
+- Clang now disallows the use of attributes on void parameters. (#GH108819)
+
 Improvements to Clang's diagnostics
 ---
 
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index f136d5007e8a5f..0b88dd4449b1e2 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -7986,6 +7986,13 @@ void Parser::ParseParameterDeclarationClause(
 if (getLangOpts().HLSL)
   MaybeParseHLSLAnnotations(DS.getAttributes());
 
+if (ParmDeclarator.getIdentifier() == nullptr &&
+ParmDeclarator.getDeclarationAttributes().size() &&
+ParmDeclarator.getDeclSpec().getTypeSpecType() == DeclSpec::TST_void) {
+  SourceRange AttrRange = ParmDeclarator.getDeclarationAttributes().Range;
+  Diag(AttrRange.getBegin(), diag::err_attributes_not_allowed) << 
AttrRange;
+}
+
 if (Tok.is(tok::kw_requires)) {
   // User tried to define a requires clause in a parameter declaration,
   // which is surely not a function declaration.
diff --git a/clang/test/Parser/cxx0x-attributes.cpp 
b/clang/test/Parser/cxx0x-attributes.cpp
index fad3010c98b9c2..13fcdd142fa841 100644
--- a/clang/test/Parser/cxx0x-attributes.cpp
+++ b/clang/test/Parser/cxx0x-attributes.cpp
@@ -453,3 +453,12 @@ namespace P2361 {
 }
 
 alignas(int) struct AlignAsAttribute {}; // expected-error {{misplaced 
attributes; expected attributes here}}
+
+namespace GH108819 {
+void a([[maybe_unused]] void) {} // expected-error {{an 
attribute list cannot appear here}} \
+ // expected-warning {{use of 
the 'maybe_unused' attribute is a C++17 extension}}
+void b([[deprecated]] void) {}   // expected-error {{an 
attribute list cannot appear here}} \
+ // expected-warning {{use of 
the 'deprecated' attribute is a C++14 extension}}
+void c([[clang::lifetimebound]] void) {} // expected-error {{an 
attribute list cannot appear here}}
+void d([[clang::annotate("a", "b", 1)]] void) {} // expected-error {{an 
attribute list cannot appear here}}
+}

>From 063f76730ebfd289f5340d0d8477a43a5ea965c2 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Wed, 29 Jan 2025 15:54:48 +0200
Subject: [PATCH 2/7] remove unnecessary name check

---
 clang/lib/Parse/ParseDecl.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 0b88dd4449b1e2..934c16c9591520 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -7986,8 +7986,7 @@ void Parser::ParseParameterDeclarationClause(
 if (getLangOpts().HLSL)
   MaybeParseHLSLAnnotations(DS.getAttributes());
 
-if (ParmDeclarator.getIdentifier() == nullptr &&
-ParmDeclarator.getDeclarationAttributes().size() &&
+if (ParmDeclarator.getDeclarationAttributes().size() &&
 ParmDeclarator.getDeclSpec().getTypeSpecType() == DeclSpec::TST_void) {
   SourceRange AttrRange = ParmDeclarator.getDeclarationAttributes().Range;
   Diag(AttrRange.getBegin(), diag::err_attributes_not_allowed) << 
AttrRange;

>From 3f3431513ad59111794953d27e64608b3ce2e6e1 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Wed, 29 Jan 2025 16:07:18 +0200
Subject: [PATCH 3/7] use empty instead of size

---
 clang/lib/Parse/ParseDecl.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 934c16c9591520..963b59565953d4 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -7986,7 +7986,7 @@ void Parser::ParseParameterDeclarationClause(
 if (getLangOpts().HLSL)
   MaybeParseHLSLAnnotations(DS.getAttributes());
 
-if (ParmDeclarator.getDeclarationAttributes().size() &&
+if (!ParmDeclarator.getDeclarationAttributes().empty() &&
 ParmDeclarator.getDeclSpec().getTypeSpecType() == DeclSpec::TST_void) {
   SourceRange AttrRange = ParmDeclarator.getDeclarationAttributes().Range;
   Diag(AttrRange.getBegin(), diag::err_attributes_not_allowed) << 
AttrRange;

>From 9919006df9ec32023b2bf179b72f9ebaf977bd08 Mon Sep 17 00:0

[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-31 Thread Ilya Biryukov via cfe-commits


@@ -1986,112 +2362,117 @@ class DerefSimplePtrArithFixableGadget : public 
FixableGadget {
   }
 };
 
-/// Scan the function and return a list of gadgets found with provided kits.
-static void findGadgets(const Stmt *S, ASTContext &Ctx,
-const UnsafeBufferUsageHandler &Handler,
-bool EmitSuggestions, FixableGadgetList 
&FixableGadgets,
-WarningGadgetList &WarningGadgets,
-DeclUseTracker &Tracker) {
+class EvaluatedStmtMatcher : public FastMatcher {
 
-  struct GadgetFinderCallback : MatchFinder::MatchCallback {
-GadgetFinderCallback(FixableGadgetList &FixableGadgets,
- WarningGadgetList &WarningGadgets,
- DeclUseTracker &Tracker)
-: FixableGadgets(FixableGadgets), WarningGadgets(WarningGadgets),
-  Tracker(Tracker) {}
-
-void run(const MatchFinder::MatchResult &Result) override {
-  // In debug mode, assert that we've found exactly one gadget.
-  // This helps us avoid conflicts in .bind() tags.
-#if NDEBUG
-#define NEXT return
-#else
-  [[maybe_unused]] int numFound = 0;
-#define NEXT ++numFound
-#endif
+public:
+  WarningGadgetList &WarningGadgets;
 
-  if (const auto *DRE = Result.Nodes.getNodeAs("any_dre")) {
-Tracker.discoverUse(DRE);
-NEXT;
-  }
+  EvaluatedStmtMatcher(WarningGadgetList &WarningGadgets)
+  : WarningGadgets(WarningGadgets) {}
 
-  if (const auto *DS = Result.Nodes.getNodeAs("any_ds")) {
-Tracker.discoverDecl(DS);
-NEXT;
-  }
+  bool matches(const DynTypedNode &DynNode, ASTContext &Ctx,
+   const UnsafeBufferUsageHandler &Handler) override {
+const Stmt *S = DynNode.get();
+if (!S)
+  return false;
 
-  // Figure out which matcher we've found, and call the appropriate
-  // subclass constructor.
-  // FIXME: Can we do this more logarithmically?
-#define FIXABLE_GADGET(name)   
\
-  if (Result.Nodes.getNodeAs(#name)) {   
\
-FixableGadgets.push_back(std::make_unique(Result));  
\
-NEXT;  
\
-  }
-#include "clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def"
+MatchResult Result;
 #define WARNING_GADGET(name)   
\
-  if (Result.Nodes.getNodeAs(#name)) {   
\
+  if (name##Gadget::matches(S, Ctx, Result) && 
\
+  notInSafeBufferOptOut(*S, &Handler)) {   
\
 WarningGadgets.push_back(std::make_unique(Result));  
\
-NEXT;  
\
+return true;   
\
+  }
+#define WARNING_OPTIONAL_GADGET(name)  
\
+  if (name##Gadget::matches(S, Ctx, &Handler, Result) &&   
\
+  notInSafeBufferOptOut(*S, &Handler)) {   
\
+WarningGadgets.push_back(std::make_unique(Result));  
\
+return true;   
\
   }
 #include "clang/Analysis/Analyses/UnsafeBufferUsageGadgets.def"
+return false;
+  }
+};
 
-  assert(numFound >= 1 && "Gadgets not found in match result!");
-  assert(numFound <= 1 && "Conflicting bind tags in gadgets!");
-}
+class StmtMatcher : public FastMatcher {
 
-FixableGadgetList &FixableGadgets;
-WarningGadgetList &WarningGadgets;
-DeclUseTracker &Tracker;
-  };
+public:
+  FixableGadgetList &FixableGadgets;

ilya-biryukov wrote:

Is it really necessary to make these members public?
They only seem to be used for reporting results internally, or am I missing 
something?

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


[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-31 Thread Ilya Biryukov via cfe-commits

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


[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #124554)

2025-01-31 Thread Ilya Biryukov via cfe-commits

https://github.com/ilya-biryukov commented:

This generally looks good, just one more minor comment from me.
Could we put this out of the draft state and send to upstream owners of the 
check to start a discussion about landing it?

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


[clang] [Clang] disallow attributes on void parameters (PR #124920)

2025-01-31 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 b3458fdec5e183b49c634b72b828630bb6972400 
afe40bf1b7095c3758f98327205ea39a1740f48d --extensions cpp,c -- 
clang/lib/Sema/SemaDecl.cpp clang/test/Misc/pragma-attribute-strict-subjects.c 
clang/test/SemaCXX/attr-cxx0x.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 9d269f2e4d..63f176f44e 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -10331,8 +10331,8 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, 
DeclContext *DC,
   for (const auto *A : Param->attrs())
 Diag(A->getLoc(), diag::warn_attribute_on_void_param)
 << A << A->getRange();
-  }
 }
+  }
 
 if (!getLangOpts().CPlusPlus) {
   // In C, find all the tag declarations from the prototype and move them

``




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


[clang] [CIR] Fix some clang-tidy problems in CIR (PR #125128)

2025-01-31 Thread Erich Keane via cfe-commits

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


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


[clang] Allow 'inline' on some declarations in MS compatibility mode (PR #125250)

2025-01-31 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman created 
https://github.com/llvm/llvm-project/pull/125250

Microsoft allows the 'inline' specifier on a typedef of a function type
in C modes. This is used by a system header (ufxclient.h), so instead
of giving a hard error, we diagnose with a warning. C++ mode and non-
Microsoft compatibility modes are not impacted.

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

>From 247afa8e1311fd270875551196b3df1bffe5ea9d Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Fri, 31 Jan 2025 11:54:49 -0500
Subject: [PATCH] Allow 'inline' on some declarations in MS compatibility mode

Microsoft allows the 'inline' specifier on a typedef of a function type
in C modes. This is used by a system header (ufxclient.h), so instead
of giving a hard error, we diagnose with a warning. C++ mode and non-
Microsoft compatibility modes are not impacted.

Fixes #124869
---
 clang/docs/ReleaseNotes.rst  |  3 +++
 clang/include/clang/Basic/DiagnosticGroups.td|  4 +++-
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  2 ++
 clang/lib/Sema/SemaDecl.cpp  |  5 -
 clang/test/Sema/MicrosoftCompatibility.c | 16 ++--
 clang/test/Sema/MicrosoftCompatibility.cpp   |  7 +++
 6 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8c290437fe16fe1..a220e57d0b32229 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -83,6 +83,9 @@ Resolutions to C++ Defect Reports
 C Language Changes
 --
 
+- Clang now allows an ``inline`` specifier on a typedef declaration of a
+  function type in Microsoft compatibility mode. #GH124869
+
 C2y Feature Support
 ^^^
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 527e588d46a049b..abb575002e11820 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1304,6 +1304,8 @@ def MicrosoftStaticAssert : 
DiagGroup<"microsoft-static-assert">;
 def MicrosoftInitFromPredefined : DiagGroup<"microsoft-init-from-predefined">;
 def MicrosoftStringLiteralFromPredefined : DiagGroup<
 "microsoft-string-literal-from-predefined">;
+def MicrosoftInlineOnNonFunction : DiagGroup<
+"microsoft-inline-on-non-function">;
 
 // Aliases.
 def : DiagGroup<"msvc-include", [MicrosoftInclude]>;
@@ -1322,7 +1324,7 @@ def Microsoft : DiagGroup<"microsoft",
  MicrosoftConstInit, MicrosoftVoidPseudoDtor, MicrosoftAnonTag,
  MicrosoftCommentPaste, MicrosoftEndOfFile, MicrosoftStaticAssert,
  MicrosoftInitFromPredefined, MicrosoftStringLiteralFromPredefined,
- MicrosoftInconsistentDllImport]>;
+ MicrosoftInconsistentDllImport, MicrosoftInlineOnNonFunction]>;
 
 def ClangClPch : DiagGroup<"clang-cl-pch">;
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 2ac3879a4caabca..00a94eb7a303671 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -482,6 +482,8 @@ def ext_use_out_of_scope_declaration : ExtWarn<
   InGroup>;
 def err_inline_non_function : Error<
   "'inline' can only appear on functions%select{| and non-local variables}0">;
+def warn_ms_inline_non_function : ExtWarn,
+  InGroup;
 def err_noreturn_non_function : Error<
   "'_Noreturn' can only appear on functions">;
 def warn_qual_return_type : Warning<
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index f7b8b192a206c37..1755b37fc8f2950 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6681,7 +6681,10 @@ Sema::ActOnTypedefDeclarator(Scope* S, Declarator& D, 
DeclContext* DC,
   DiagnoseFunctionSpecifiers(D.getDeclSpec());
 
   if (D.getDeclSpec().isInlineSpecified())
-Diag(D.getDeclSpec().getInlineSpecLoc(), diag::err_inline_non_function)
+Diag(D.getDeclSpec().getInlineSpecLoc(),
+ (getLangOpts().MSVCCompat && !getLangOpts().CPlusPlus)
+ ? diag::warn_ms_inline_non_function
+ : diag::err_inline_non_function)
 << getLangOpts().CPlusPlus17;
   if (D.getDeclSpec().hasConstexprSpecifier())
 Diag(D.getDeclSpec().getConstexprSpecLoc(), diag::err_invalid_constexpr)
diff --git a/clang/test/Sema/MicrosoftCompatibility.c 
b/clang/test/Sema/MicrosoftCompatibility.c
index 9a1f050747f9d47..8d402d53e004d6f 100644
--- a/clang/test/Sema/MicrosoftCompatibility.c
+++ b/clang/test/Sema/MicrosoftCompatibility.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify 
-fms-compatibility -DMSVCCOMPAT -triple i686-pc-win32
-// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify 
-fms-extensions -triple i686-pc-win32
+// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wmicrosoft 
-verify=expected,compat -fms-compatibility -DMSVCC

[clang] [NFC][analyzer][docs] Improve Annotations.rst (PR #122749)

2025-01-31 Thread Donát Nagy via cfe-commits

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


[clang] b9207ae - [NFC][analyzer][docs] Improve Annotations.rst (#122749)

2025-01-31 Thread via cfe-commits

Author: Donát Nagy
Date: 2025-01-31T18:01:08+01:00
New Revision: b9207aef09387342837069d2c0857e6d331a516c

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

LOG: [NFC][analyzer][docs] Improve Annotations.rst (#122749)

This commit fixes three issues within the documentation file
`Annotations.rst` which was recently created by my earlier commit
https://github.com/llvm/llvm-project/pull/122246 .

(1) The section title "Annotations to Enhance Generic Checks" is changed
to "General Purpose Annotations" because it was a bit too verbose and it
used the obsolete name "checks" for what we now call "checkers" in the
static analyzer.

(2) Several code blocks were missing from the generated html because I
accidentally used `.. code-block: c` instead of `.. code-block:: c` and
so Sphinx parsed them as comment blocks. (Without printing any error or
warning...)

(3) The `ownership_*` attributes (which are used by `MallocChecker`)
were missing from this document, so I wrote a section that briefly
describes them and links to their full documentation.

Added: 


Modified: 
clang/docs/analyzer/user-docs/Annotations.rst

Removed: 




diff  --git a/clang/docs/analyzer/user-docs/Annotations.rst 
b/clang/docs/analyzer/user-docs/Annotations.rst
index d87e8f4df99c31..11f15939ecfaf0 100644
--- a/clang/docs/analyzer/user-docs/Annotations.rst
+++ b/clang/docs/analyzer/user-docs/Annotations.rst
@@ -23,8 +23,8 @@ recognized by GCC. Their use can be conditioned using 
preprocessor macros
 .. contents::
:local:
 
-Annotations to Enhance Generic Checks
-_
+General Purpose Annotations
+___
 
 Null Pointer Checking
 #
@@ -79,7 +79,7 @@ implemented with a macro, with the macro performing a check 
for the assertion
 condition and, when the check fails, calling an assertion handler.  For
 example, consider the following code fragment:
 
-.. code-block: c
+.. code-block:: c
 
   void foo(int *p) {
 assert(p != NULL);
@@ -87,7 +87,7 @@ example, consider the following code fragment:
 
 When this code is preprocessed on Mac OS X it expands to the following:
 
-.. code-block: c
+.. code-block:: c
 
   void foo(int *p) {
 (__builtin_expect(!(p != NULL), 0) ? __assert_rtn(__func__, "t.c", 4, "p 
!= NULL") : (void)0);
@@ -131,7 +131,7 @@ return.
 On Mac OS X, the function prototype for ``__assert_rtn`` (declared in
 ``assert.h``) is specifically annotated with the 'noreturn' attribute:
 
-.. code-block: c
+.. code-block:: c
 
   void __assert_rtn(const char *, const char *, int, const char *) 
__attribute__((__noreturn__));
 
@@ -151,7 +151,7 @@ the use of preprocessor macros.
 
 **Example**
 
-.. code-block: c
+.. code-block:: c
 
   #ifndef CLANG_ANALYZER_NORETURN
   #if __has_feature(attribute_analyzer_noreturn)
@@ -163,6 +163,43 @@ the use of preprocessor macros.
 
   void my_assert_rtn(const char *, const char *, int, const char *) 
CLANG_ANALYZER_NORETURN;
 
+Dynamic Memory Modeling Annotations
+###
+
+If a project uses custom functions for dynamic memory management (that e.g. 
act as wrappers around ``malloc``/``free`` or ``new``/``delete`` in C++) and 
the analyzer cannot "see" the _definitions_ of these functions, it's possible 
to annotate their declarations to let the analyzer model their behavior. 
(Otherwise the analyzer cannot know that the opaque ``my_free()`` is basically 
equivalent to a standard ``free()`` call.)
+
+.. note::
+  **This page only provides a brief list of these annotations.** For a full 
documentation, see the main `Attributes in Clang 
<../../AttributeReference.html#ownership-holds-ownership-returns-ownership-takes-clang-static-analyzer>`_
 page.
+
+Attribute 'ownership_returns' (Clang-specific)
+--
+
+Use this attribute to mark functions that return dynamically allocated memory. 
Takes a single argument, the type of the allocation (e.g. ``malloc`` or 
``new``).
+
+.. code-block:: c
+
+  void __attribute((ownership_returns(malloc))) *my_malloc(size_t);
+
+Attribute 'ownership_takes' (Clang-specific)
+
+
+Use this attribute to mark functions that deallocate memory. Takes two 
arguments: the type of the allocation (e.g. ``malloc`` or ``new``) and the 
index of the parameter that is being deallocated (counting from 1).
+
+.. code-block:: c
+
+  void __attribute((ownership_takes(malloc, 1))) my_free(void *);
+
+Attribute 'ownership_holds' (Clang-specific)
+
+
+Use this attribute to mark functions that take ownership of memory and will 
deallocate it at some unspecified point in the future. Takes two arguments: the 
type of the allocation (e.

[clang] [flang] [flang] Add support for -fimplicit-none-ext option (PR #125248)

2025-01-31 Thread Peter Klausler via cfe-commits

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


[clang] [flang] [flang] Add support for -fimplicit-none-ext option (PR #125248)

2025-01-31 Thread Peter Klausler via cfe-commits

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

Well done!  Thank you.

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


[clang] [clang][bytecode] Stack-allocate bottom function frame (PR #125253)

2025-01-31 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/125253

Instead of heap-allocating it. This is similar to what the current interpeter 
does. In C, we have no function calls, so the extra heap allocation never makes 
sense.

>From 26c07a4b0b5c85de8fa3ab394ece750dac905eed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 31 Jan 2025 09:34:32 +0100
Subject: [PATCH] [clang][bytecode] Stack-allocate bottom function frame

Instead of heap-allocating it. This is similar to what the current
interpeter does. In C, we have no function calls, so the extra heap
allocation never makes sense.
---
 clang/lib/AST/ByteCode/EvalEmitter.cpp |  7 +++
 clang/lib/AST/ByteCode/EvalEmitter.h   |  2 ++
 clang/lib/AST/ByteCode/Interp.h|  4 ++--
 clang/lib/AST/ByteCode/InterpFrame.cpp |  4 
 clang/lib/AST/ByteCode/InterpFrame.h   | 12 
 clang/lib/AST/ByteCode/InterpState.cpp |  2 +-
 6 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp 
b/clang/lib/AST/ByteCode/EvalEmitter.cpp
index 9763fe89b73742..3f64aea4183f64 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.cpp
+++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp
@@ -17,10 +17,9 @@ using namespace clang::interp;
 
 EvalEmitter::EvalEmitter(Context &Ctx, Program &P, State &Parent,
  InterpStack &Stk)
-: Ctx(Ctx), P(P), S(Parent, P, Stk, Ctx, this), EvalResult(&Ctx) {
-  // Create a dummy frame for the interpreter which does not have locals.
-  S.Current =
-  new InterpFrame(S, /*Func=*/nullptr, /*Caller=*/nullptr, CodePtr(), 0);
+: Ctx(Ctx), P(P), S(Parent, P, Stk, Ctx, this), EvalResult(&Ctx),
+  BottomFrame(S) {
+  S.Current = &BottomFrame;
 }
 
 EvalEmitter::~EvalEmitter() {
diff --git a/clang/lib/AST/ByteCode/EvalEmitter.h 
b/clang/lib/AST/ByteCode/EvalEmitter.h
index e7c9e80d75d934..0b58b100f85fad 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.h
+++ b/clang/lib/AST/ByteCode/EvalEmitter.h
@@ -125,6 +125,8 @@ class EvalEmitter : public SourceMapper {
   /// Active block which should be executed.
   LabelTy ActiveLabel = 0;
 
+  InterpFrame BottomFrame;
+
 protected:
 #define GET_EVAL_PROTO
 #include "Opcodes.inc"
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 063970afec9e35..91a82a25944fb5 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -325,11 +325,11 @@ bool Ret(InterpState &S, CodePtr &PC) {
 
   if (InterpFrame *Caller = S.Current->Caller) {
 PC = S.Current->getRetPC();
-delete S.Current;
+InterpFrame::free(S.Current);
 S.Current = Caller;
 S.Stk.push(Ret);
   } else {
-delete S.Current;
+InterpFrame::free(S.Current);
 S.Current = nullptr;
 // The topmost frame should come from an EvalEmitter,
 // which has its own implementation of the Ret<> instruction.
diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp 
b/clang/lib/AST/ByteCode/InterpFrame.cpp
index 20f67d9b1fd425..cfcc9dc80d5353 100644
--- a/clang/lib/AST/ByteCode/InterpFrame.cpp
+++ b/clang/lib/AST/ByteCode/InterpFrame.cpp
@@ -23,6 +23,10 @@
 using namespace clang;
 using namespace clang::interp;
 
+InterpFrame::InterpFrame(InterpState &S)
+: Caller(nullptr), S(S), Depth(0), Func(nullptr), RetPC(CodePtr()),
+  ArgSize(0), Args(nullptr), FrameOffset(0), IsBottom(true) {}
+
 InterpFrame::InterpFrame(InterpState &S, const Function *Func,
  InterpFrame *Caller, CodePtr RetPC, unsigned ArgSize)
 : Caller(Caller), S(S), Depth(Caller ? Caller->Depth + 1 : 0), Func(Func),
diff --git a/clang/lib/AST/ByteCode/InterpFrame.h 
b/clang/lib/AST/ByteCode/InterpFrame.h
index 7cfc3ac68b4f3e..426dbb0e396d35 100644
--- a/clang/lib/AST/ByteCode/InterpFrame.h
+++ b/clang/lib/AST/ByteCode/InterpFrame.h
@@ -28,6 +28,9 @@ class InterpFrame final : public Frame {
   /// The frame of the previous function.
   InterpFrame *Caller;
 
+  /// Bottom Frame.
+  InterpFrame(InterpState &S);
+
   /// Creates a new frame for a method call.
   InterpFrame(InterpState &S, const Function *Func, InterpFrame *Caller,
   CodePtr RetPC, unsigned ArgSize);
@@ -42,6 +45,12 @@ class InterpFrame final : public Frame {
   /// Destroys the frame, killing all live pointers to stack slots.
   ~InterpFrame();
 
+  static void free(InterpFrame *F) {
+if (F->isBottomFrame())
+  return;
+delete F;
+  }
+
   /// Invokes the destructors for a scope.
   void destroy(unsigned Idx);
   void initScope(unsigned Idx);
@@ -119,6 +128,8 @@ class InterpFrame final : public Frame {
 
   bool isStdFunction() const;
 
+  bool isBottomFrame() const { return IsBottom; }
+
   void dump() const { dump(llvm::errs(), 0); }
   void dump(llvm::raw_ostream &OS, unsigned Indent = 0) const;
 
@@ -167,6 +178,7 @@ class InterpFrame final : public Frame {
   const size_t FrameOffset;
   /// Mapping from arg offsets to their argument blocks.
   llvm::DenseMap> Para

[clang] Allow 'inline' on some declarations in MS compatibility mode (PR #125250)

2025-01-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-platform-windows

Author: Aaron Ballman (AaronBallman)


Changes

Microsoft allows the 'inline' specifier on a typedef of a function type
in C modes. This is used by a system header (ufxclient.h), so instead
of giving a hard error, we diagnose with a warning. C++ mode and non-
Microsoft compatibility modes are not impacted.

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

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


6 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/include/clang/Basic/DiagnosticGroups.td (+3-1) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+2) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+4-1) 
- (modified) clang/test/Sema/MicrosoftCompatibility.c (+14-2) 
- (modified) clang/test/Sema/MicrosoftCompatibility.cpp (+7) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8c290437fe16fe..a220e57d0b3222 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -83,6 +83,9 @@ Resolutions to C++ Defect Reports
 C Language Changes
 --
 
+- Clang now allows an ``inline`` specifier on a typedef declaration of a
+  function type in Microsoft compatibility mode. #GH124869
+
 C2y Feature Support
 ^^^
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 527e588d46a049..abb575002e1182 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1304,6 +1304,8 @@ def MicrosoftStaticAssert : 
DiagGroup<"microsoft-static-assert">;
 def MicrosoftInitFromPredefined : DiagGroup<"microsoft-init-from-predefined">;
 def MicrosoftStringLiteralFromPredefined : DiagGroup<
 "microsoft-string-literal-from-predefined">;
+def MicrosoftInlineOnNonFunction : DiagGroup<
+"microsoft-inline-on-non-function">;
 
 // Aliases.
 def : DiagGroup<"msvc-include", [MicrosoftInclude]>;
@@ -1322,7 +1324,7 @@ def Microsoft : DiagGroup<"microsoft",
  MicrosoftConstInit, MicrosoftVoidPseudoDtor, MicrosoftAnonTag,
  MicrosoftCommentPaste, MicrosoftEndOfFile, MicrosoftStaticAssert,
  MicrosoftInitFromPredefined, MicrosoftStringLiteralFromPredefined,
- MicrosoftInconsistentDllImport]>;
+ MicrosoftInconsistentDllImport, MicrosoftInlineOnNonFunction]>;
 
 def ClangClPch : DiagGroup<"clang-cl-pch">;
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 2ac3879a4caabc..00a94eb7a30367 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -482,6 +482,8 @@ def ext_use_out_of_scope_declaration : ExtWarn<
   InGroup>;
 def err_inline_non_function : Error<
   "'inline' can only appear on functions%select{| and non-local variables}0">;
+def warn_ms_inline_non_function : ExtWarn,
+  InGroup;
 def err_noreturn_non_function : Error<
   "'_Noreturn' can only appear on functions">;
 def warn_qual_return_type : Warning<
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index f7b8b192a206c3..1755b37fc8f295 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6681,7 +6681,10 @@ Sema::ActOnTypedefDeclarator(Scope* S, Declarator& D, 
DeclContext* DC,
   DiagnoseFunctionSpecifiers(D.getDeclSpec());
 
   if (D.getDeclSpec().isInlineSpecified())
-Diag(D.getDeclSpec().getInlineSpecLoc(), diag::err_inline_non_function)
+Diag(D.getDeclSpec().getInlineSpecLoc(),
+ (getLangOpts().MSVCCompat && !getLangOpts().CPlusPlus)
+ ? diag::warn_ms_inline_non_function
+ : diag::err_inline_non_function)
 << getLangOpts().CPlusPlus17;
   if (D.getDeclSpec().hasConstexprSpecifier())
 Diag(D.getDeclSpec().getConstexprSpecLoc(), diag::err_invalid_constexpr)
diff --git a/clang/test/Sema/MicrosoftCompatibility.c 
b/clang/test/Sema/MicrosoftCompatibility.c
index 9a1f050747f9d4..8d402d53e004d6 100644
--- a/clang/test/Sema/MicrosoftCompatibility.c
+++ b/clang/test/Sema/MicrosoftCompatibility.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify 
-fms-compatibility -DMSVCCOMPAT -triple i686-pc-win32
-// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify 
-fms-extensions -triple i686-pc-win32
+// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wmicrosoft 
-verify=expected,compat -fms-compatibility -DMSVCCOMPAT -triple i686-pc-win32
+// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wmicrosoft 
-verify=expected,ext -fms-extensions -triple i686-pc-win32
 
 #ifdef MSVCCOMPAT
 enum ENUM1; // expected-warning {{forward references to 'enum' types are a 
Microsoft extension}}
@@ -35,3 +35,15 @@ size_t x;
 #else
 size_t x; // expected-error {{unknown type name 'size_t'}}
 #endif
+
+/* Microsoft allows inline, __inline, and __forceinline to appea

[clang] [flang] [flang] Add support for -fimplicit-none-ext option (PR #125248)

2025-01-31 Thread Eugene Epshteyn via cfe-commits

https://github.com/eugeneepshteyn updated 
https://github.com/llvm/llvm-project/pull/125248

>From 11cb96c5dcb911a24596c646fbbc3cc6f3fd10a4 Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn 
Date: Fri, 31 Jan 2025 10:52:00 -0500
Subject: [PATCH 1/5] [flang] Add support for -fimplicit-none-ext option

When enabled, flang behaves as if "implicit none(external)" was specified for
all relevant constructs in Fortran source file.

Signed-off-by: Eugene Epshteyn 
---
 clang/include/clang/Driver/Options.td | 1 +
 clang/lib/Driver/ToolChains/Flang.cpp | 1 +
 flang/include/flang/Common/Fortran-features.h | 2 +-
 flang/lib/Common/Fortran-features.cpp | 1 +
 flang/lib/Frontend/CompilerInvocation.cpp | 7 +++
 flang/lib/Semantics/resolve-names.cpp | 2 +-
 6 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d8123cc39fdc95..c33fdb6a1c163d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6876,6 +6876,7 @@ defm backslash : OptInFC1FFlag<"backslash", "Specify that 
backslash in string in
 defm xor_operator : OptInFC1FFlag<"xor-operator", "Enable .XOR. as a synonym 
of .NEQV.">;
 defm logical_abbreviations : OptInFC1FFlag<"logical-abbreviations", "Enable 
logical abbreviations">;
 defm implicit_none : OptInFC1FFlag<"implicit-none", "No implicit typing 
allowed unless overridden by IMPLICIT statements">;
+defm implicit_none_ext : OptInFC1FFlag<"implicit-none-ext", "No implicit 
externals allowed">;
 defm underscoring : OptInFC1FFlag<"underscoring", "Appends one trailing 
underscore to external names">;
 defm ppc_native_vec_elem_order: BoolOptionWithoutMarshalling<"f", 
"ppc-native-vector-element-order",
   PosFlag,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 1ae865f379110b..e4019c43496874 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -42,6 +42,7 @@ void Flang::addFortranDialectOptions(const ArgList &Args,
 options::OPT_fopenacc,
 options::OPT_finput_charset_EQ,
 options::OPT_fimplicit_none,
+options::OPT_fimplicit_none_ext,
 options::OPT_fno_implicit_none,
 options::OPT_fbackslash,
 options::OPT_fno_backslash,
diff --git a/flang/include/flang/Common/Fortran-features.h 
b/flang/include/flang/Common/Fortran-features.h
index 9549e8bfbbef0b..23c7afe9eec2bb 100644
--- a/flang/include/flang/Common/Fortran-features.h
+++ b/flang/include/flang/Common/Fortran-features.h
@@ -54,7 +54,7 @@ ENUM_CLASS(LanguageFeature, BackslashEscapes, OldDebugLines,
 PolymorphicActualAllocatableOrPointerToMonomorphicDummy, RelaxedPureDummy,
 UndefinableAsynchronousOrVolatileActual, AutomaticInMainProgram, PrintCptr,
 SavedLocalInSpecExpr, PrintNamelist, AssumedRankPassedToNonAssumedRank,
-IgnoreIrrelevantAttributes, Unsigned)
+IgnoreIrrelevantAttributes, Unsigned, ImplicitNoneExternal)
 
 // Portability and suspicious usage warnings
 ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable,
diff --git a/flang/lib/Common/Fortran-features.cpp 
b/flang/lib/Common/Fortran-features.cpp
index 3565275915a312..678e2274960ac4 100644
--- a/flang/lib/Common/Fortran-features.cpp
+++ b/flang/lib/Common/Fortran-features.cpp
@@ -22,6 +22,7 @@ LanguageFeatureControl::LanguageFeatureControl() {
   disable_.set(LanguageFeature::CudaUnified);
   disable_.set(LanguageFeature::ImplicitNoneTypeNever);
   disable_.set(LanguageFeature::ImplicitNoneTypeAlways);
+  disable_.set(LanguageFeature::ImplicitNoneExternal);
   disable_.set(LanguageFeature::DefaultSave);
   disable_.set(LanguageFeature::SaveMainProgram);
   // These features, if enabled, conflict with valid standard usage,
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 68b5950d3a51b7..e9ef308e987941 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -740,6 +740,13 @@ static bool parseFrontendArgs(FrontendOptions &opts, 
llvm::opt::ArgList &args,
   args.hasFlag(clang::driver::options::OPT_fimplicit_none,
clang::driver::options::OPT_fno_implicit_none, false));
 
+  // -f{no-}implicit-none-ext
+  opts.features.Enable(
+  Fortran::common::LanguageFeature::ImplicitNoneExternal,
+  args.hasFlag(clang::driver::options::OPT_fimplicit_none_ext,
+   clang::driver::options::OPT_fno_implicit_none_ext, false));
+
+
   // -f{no-}backslash
   opts.features.Enable(Fortran::common::LanguageFeature::BackslashEscapes,
args.hasFlag(clang::driver::options::OPT_fbackslash,
diff --git a/flang/lib/Semantics/resolve-names.cpp 
b/flang/lib/Semantics/resolve-names.

[clang] [clang][bytecode] Stack-allocate bottom function frame (PR #125253)

2025-01-31 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/125253

>From 797ce103eb62d6b41882d8659bc2e7a700d846d1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 31 Jan 2025 09:34:32 +0100
Subject: [PATCH] [clang][bytecode] Stack-allocate bottom function frame

Instead of heap-allocating it. This is similar to what the current
interpeter does. In C, we have no function calls, so the extra heap
allocation never makes sense.
---
 clang/lib/AST/ByteCode/EvalEmitter.cpp |  7 +++
 clang/lib/AST/ByteCode/EvalEmitter.h   |  2 ++
 clang/lib/AST/ByteCode/Interp.h|  4 ++--
 clang/lib/AST/ByteCode/InterpFrame.cpp |  4 
 clang/lib/AST/ByteCode/InterpFrame.h   | 11 +++
 clang/lib/AST/ByteCode/InterpState.cpp |  2 +-
 6 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp 
b/clang/lib/AST/ByteCode/EvalEmitter.cpp
index 9763fe89b73742..3f64aea4183f64 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.cpp
+++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp
@@ -17,10 +17,9 @@ using namespace clang::interp;
 
 EvalEmitter::EvalEmitter(Context &Ctx, Program &P, State &Parent,
  InterpStack &Stk)
-: Ctx(Ctx), P(P), S(Parent, P, Stk, Ctx, this), EvalResult(&Ctx) {
-  // Create a dummy frame for the interpreter which does not have locals.
-  S.Current =
-  new InterpFrame(S, /*Func=*/nullptr, /*Caller=*/nullptr, CodePtr(), 0);
+: Ctx(Ctx), P(P), S(Parent, P, Stk, Ctx, this), EvalResult(&Ctx),
+  BottomFrame(S) {
+  S.Current = &BottomFrame;
 }
 
 EvalEmitter::~EvalEmitter() {
diff --git a/clang/lib/AST/ByteCode/EvalEmitter.h 
b/clang/lib/AST/ByteCode/EvalEmitter.h
index e7c9e80d75d934..0b58b100f85fad 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.h
+++ b/clang/lib/AST/ByteCode/EvalEmitter.h
@@ -125,6 +125,8 @@ class EvalEmitter : public SourceMapper {
   /// Active block which should be executed.
   LabelTy ActiveLabel = 0;
 
+  InterpFrame BottomFrame;
+
 protected:
 #define GET_EVAL_PROTO
 #include "Opcodes.inc"
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 063970afec9e35..91a82a25944fb5 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -325,11 +325,11 @@ bool Ret(InterpState &S, CodePtr &PC) {
 
   if (InterpFrame *Caller = S.Current->Caller) {
 PC = S.Current->getRetPC();
-delete S.Current;
+InterpFrame::free(S.Current);
 S.Current = Caller;
 S.Stk.push(Ret);
   } else {
-delete S.Current;
+InterpFrame::free(S.Current);
 S.Current = nullptr;
 // The topmost frame should come from an EvalEmitter,
 // which has its own implementation of the Ret<> instruction.
diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp 
b/clang/lib/AST/ByteCode/InterpFrame.cpp
index 20f67d9b1fd425..cfcc9dc80d5353 100644
--- a/clang/lib/AST/ByteCode/InterpFrame.cpp
+++ b/clang/lib/AST/ByteCode/InterpFrame.cpp
@@ -23,6 +23,10 @@
 using namespace clang;
 using namespace clang::interp;
 
+InterpFrame::InterpFrame(InterpState &S)
+: Caller(nullptr), S(S), Depth(0), Func(nullptr), RetPC(CodePtr()),
+  ArgSize(0), Args(nullptr), FrameOffset(0), IsBottom(true) {}
+
 InterpFrame::InterpFrame(InterpState &S, const Function *Func,
  InterpFrame *Caller, CodePtr RetPC, unsigned ArgSize)
 : Caller(Caller), S(S), Depth(Caller ? Caller->Depth + 1 : 0), Func(Func),
diff --git a/clang/lib/AST/ByteCode/InterpFrame.h 
b/clang/lib/AST/ByteCode/InterpFrame.h
index 7cfc3ac68b4f3e..8cabb9cd06fac0 100644
--- a/clang/lib/AST/ByteCode/InterpFrame.h
+++ b/clang/lib/AST/ByteCode/InterpFrame.h
@@ -28,6 +28,9 @@ class InterpFrame final : public Frame {
   /// The frame of the previous function.
   InterpFrame *Caller;
 
+  /// Bottom Frame.
+  InterpFrame(InterpState &S);
+
   /// Creates a new frame for a method call.
   InterpFrame(InterpState &S, const Function *Func, InterpFrame *Caller,
   CodePtr RetPC, unsigned ArgSize);
@@ -42,6 +45,11 @@ class InterpFrame final : public Frame {
   /// Destroys the frame, killing all live pointers to stack slots.
   ~InterpFrame();
 
+  static void free(InterpFrame *F) {
+if (!F->isBottomFrame())
+  delete F;
+  }
+
   /// Invokes the destructors for a scope.
   void destroy(unsigned Idx);
   void initScope(unsigned Idx);
@@ -119,6 +127,8 @@ class InterpFrame final : public Frame {
 
   bool isStdFunction() const;
 
+  bool isBottomFrame() const { return IsBottom; }
+
   void dump() const { dump(llvm::errs(), 0); }
   void dump(llvm::raw_ostream &OS, unsigned Indent = 0) const;
 
@@ -167,6 +177,7 @@ class InterpFrame final : public Frame {
   const size_t FrameOffset;
   /// Mapping from arg offsets to their argument blocks.
   llvm::DenseMap> Params;
+  bool IsBottom = false;
 };
 
 } // namespace interp
diff --git a/clang/lib/AST/ByteCode/InterpState.cpp 
b/clang/lib/AST/ByteCode/InterpState.cpp
index 287c3bd3bca3a5..8aa44e

[clang] [clang][bytecode] Stack-allocate bottom function frame (PR #125253)

2025-01-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

Instead of heap-allocating it. This is similar to what the current interpeter 
does. In C, we have no function calls, so the extra heap allocation never makes 
sense.

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


6 Files Affected:

- (modified) clang/lib/AST/ByteCode/EvalEmitter.cpp (+3-4) 
- (modified) clang/lib/AST/ByteCode/EvalEmitter.h (+2) 
- (modified) clang/lib/AST/ByteCode/Interp.h (+2-2) 
- (modified) clang/lib/AST/ByteCode/InterpFrame.cpp (+4) 
- (modified) clang/lib/AST/ByteCode/InterpFrame.h (+11) 
- (modified) clang/lib/AST/ByteCode/InterpState.cpp (+1-1) 


``diff
diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp 
b/clang/lib/AST/ByteCode/EvalEmitter.cpp
index 9763fe89b73742..3f64aea4183f64 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.cpp
+++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp
@@ -17,10 +17,9 @@ using namespace clang::interp;
 
 EvalEmitter::EvalEmitter(Context &Ctx, Program &P, State &Parent,
  InterpStack &Stk)
-: Ctx(Ctx), P(P), S(Parent, P, Stk, Ctx, this), EvalResult(&Ctx) {
-  // Create a dummy frame for the interpreter which does not have locals.
-  S.Current =
-  new InterpFrame(S, /*Func=*/nullptr, /*Caller=*/nullptr, CodePtr(), 0);
+: Ctx(Ctx), P(P), S(Parent, P, Stk, Ctx, this), EvalResult(&Ctx),
+  BottomFrame(S) {
+  S.Current = &BottomFrame;
 }
 
 EvalEmitter::~EvalEmitter() {
diff --git a/clang/lib/AST/ByteCode/EvalEmitter.h 
b/clang/lib/AST/ByteCode/EvalEmitter.h
index e7c9e80d75d934..0b58b100f85fad 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.h
+++ b/clang/lib/AST/ByteCode/EvalEmitter.h
@@ -125,6 +125,8 @@ class EvalEmitter : public SourceMapper {
   /// Active block which should be executed.
   LabelTy ActiveLabel = 0;
 
+  InterpFrame BottomFrame;
+
 protected:
 #define GET_EVAL_PROTO
 #include "Opcodes.inc"
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 063970afec9e35..91a82a25944fb5 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -325,11 +325,11 @@ bool Ret(InterpState &S, CodePtr &PC) {
 
   if (InterpFrame *Caller = S.Current->Caller) {
 PC = S.Current->getRetPC();
-delete S.Current;
+InterpFrame::free(S.Current);
 S.Current = Caller;
 S.Stk.push(Ret);
   } else {
-delete S.Current;
+InterpFrame::free(S.Current);
 S.Current = nullptr;
 // The topmost frame should come from an EvalEmitter,
 // which has its own implementation of the Ret<> instruction.
diff --git a/clang/lib/AST/ByteCode/InterpFrame.cpp 
b/clang/lib/AST/ByteCode/InterpFrame.cpp
index 20f67d9b1fd425..cfcc9dc80d5353 100644
--- a/clang/lib/AST/ByteCode/InterpFrame.cpp
+++ b/clang/lib/AST/ByteCode/InterpFrame.cpp
@@ -23,6 +23,10 @@
 using namespace clang;
 using namespace clang::interp;
 
+InterpFrame::InterpFrame(InterpState &S)
+: Caller(nullptr), S(S), Depth(0), Func(nullptr), RetPC(CodePtr()),
+  ArgSize(0), Args(nullptr), FrameOffset(0), IsBottom(true) {}
+
 InterpFrame::InterpFrame(InterpState &S, const Function *Func,
  InterpFrame *Caller, CodePtr RetPC, unsigned ArgSize)
 : Caller(Caller), S(S), Depth(Caller ? Caller->Depth + 1 : 0), Func(Func),
diff --git a/clang/lib/AST/ByteCode/InterpFrame.h 
b/clang/lib/AST/ByteCode/InterpFrame.h
index 7cfc3ac68b4f3e..8cabb9cd06fac0 100644
--- a/clang/lib/AST/ByteCode/InterpFrame.h
+++ b/clang/lib/AST/ByteCode/InterpFrame.h
@@ -28,6 +28,9 @@ class InterpFrame final : public Frame {
   /// The frame of the previous function.
   InterpFrame *Caller;
 
+  /// Bottom Frame.
+  InterpFrame(InterpState &S);
+
   /// Creates a new frame for a method call.
   InterpFrame(InterpState &S, const Function *Func, InterpFrame *Caller,
   CodePtr RetPC, unsigned ArgSize);
@@ -42,6 +45,11 @@ class InterpFrame final : public Frame {
   /// Destroys the frame, killing all live pointers to stack slots.
   ~InterpFrame();
 
+  static void free(InterpFrame *F) {
+if (!F->isBottomFrame())
+  delete F;
+  }
+
   /// Invokes the destructors for a scope.
   void destroy(unsigned Idx);
   void initScope(unsigned Idx);
@@ -119,6 +127,8 @@ class InterpFrame final : public Frame {
 
   bool isStdFunction() const;
 
+  bool isBottomFrame() const { return IsBottom; }
+
   void dump() const { dump(llvm::errs(), 0); }
   void dump(llvm::raw_ostream &OS, unsigned Indent = 0) const;
 
@@ -167,6 +177,7 @@ class InterpFrame final : public Frame {
   const size_t FrameOffset;
   /// Mapping from arg offsets to their argument blocks.
   llvm::DenseMap> Params;
+  bool IsBottom = false;
 };
 
 } // namespace interp
diff --git a/clang/lib/AST/ByteCode/InterpState.cpp 
b/clang/lib/AST/ByteCode/InterpState.cpp
index 287c3bd3bca3a5..8aa44e48842e96 100644
--- a/clang/lib/AST/ByteCode/InterpState.cpp
+++ b/clang/lib/AST/ByteCode/InterpState.cpp
@@ -27,7 +27,7 @@ bo

[clang] [flang] [flang] Add support for -fimplicit-none-ext option (PR #125248)

2025-01-31 Thread Eugene Epshteyn via cfe-commits


@@ -34,13 +34,13 @@ ENUM_CLASS(LanguageFeature, BackslashEscapes, OldDebugLines,
 EquivalenceSameNonSequence, AdditionalIntrinsics, AnonymousParents,
 OldLabelDoEndStatements, LogicalIntegerAssignment, EmptySourceFile,
 ProgramReturn, ImplicitNoneTypeNever, ImplicitNoneTypeAlways,
-ForwardRefImplicitNone, OpenAccessAppend, BOZAsDefaultInteger,
-DistinguishableSpecifics, DefaultSave, PointerInSeqType, 
NonCharacterFormat,
-SaveMainProgram, SaveBigMainProgramVariables,
-DistinctArrayConstructorLengths, PPCVector, RelaxedIntentInChecking,
-ForwardRefImplicitNoneData, NullActualForAllocatable,
-ActualIntegerConvertedToSmallerKind, HollerithOrCharacterAsBOZ,
-BindingAsProcedure, StatementFunctionExtensions,
+ImplicitNoneExternal, ForwardRefImplicitNone, OpenAccessAppend,

eugeneepshteyn wrote:

As requested, I moved `ImplicitNoneExternal` to after `ImplicitNoneTypeAlways`. 
The other changes below are due to `clang-format`.

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


[clang] Allow 'inline' on some declarations in MS compatibility mode (PR #125250)

2025-01-31 Thread via cfe-commits

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


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


[clang] Diagnose the code with trailing comma in the function call. (PR #125232)

2025-01-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Haojian Wu (hokein)


Changes

Fixes #125225 

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


3 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+2) 
- (modified) clang/lib/Parse/ParseExpr.cpp (+3) 
- (modified) clang/test/Parser/recovery.cpp (+7) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f5..f116ef114bb361 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -703,6 +703,8 @@ def ext_consteval_if : ExtWarn<
 def warn_cxx20_compat_consteval_if : Warning<
   "consteval if is incompatible with C++ standards before C++23">,
   InGroup, DefaultIgnore;
+def err_extraneous_trailing_comma : Error<
+  "extraneous trailing comma">;
 
 def ext_init_statement : ExtWarn<
   "'%select{if|switch}0' initialization statements are a C++17 extension">,
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index aa8b3870a188c6..e31ef7d404a222 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -2237,6 +2237,9 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
   RunSignatureHelp();
 LHS = ExprError();
+  } else if (!HasError && HasTrailingComma) {
+// FIXME: add a FIXIT to remove the trailing comma.
+Diag(Tok, diag::err_extraneous_trailing_comma);
   } else if (LHS.isInvalid()) {
 for (auto &E : ArgExprs)
   Actions.CorrectDelayedTyposInExpr(E);
diff --git a/clang/test/Parser/recovery.cpp b/clang/test/Parser/recovery.cpp
index 4e2811c4cac926..e318461e1961da 100644
--- a/clang/test/Parser/recovery.cpp
+++ b/clang/test/Parser/recovery.cpp
@@ -215,3 +215,10 @@ struct ::template foo, struct ::template bar; // 
expected-error 2 {{expected ide
 struct ::foo struct::; // expected-error {{no struct named 'foo' in the global 
namespace}} expected-error {{expected identifier}}
 class :: : {} a;  // expected-error {{expected identifier}} expected-error 
{{expected class name}}
 }
+
+namespace GH125225 {
+void func(int);
+void k() {
+  func(1, ); // expected-error {{extraneous trailing comma}}
+}
+}

``




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


[clang] Diagnose the code with trailing comma in the function call. (PR #125232)

2025-01-31 Thread Haojian Wu via cfe-commits

https://github.com/hokein created 
https://github.com/llvm/llvm-project/pull/125232

Fixes #125225 

>From 5ecb2de4ba92619dc0bee89e06db5203e256ea42 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Fri, 31 Jan 2025 14:59:39 +0100
Subject: [PATCH] Diagnose the code with trailing comma in the function call.

---
 clang/include/clang/Basic/DiagnosticParseKinds.td | 2 ++
 clang/lib/Parse/ParseExpr.cpp | 3 +++
 clang/test/Parser/recovery.cpp| 7 +++
 3 files changed, 12 insertions(+)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index c513dab810d1f53..f116ef114bb3619 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -703,6 +703,8 @@ def ext_consteval_if : ExtWarn<
 def warn_cxx20_compat_consteval_if : Warning<
   "consteval if is incompatible with C++ standards before C++23">,
   InGroup, DefaultIgnore;
+def err_extraneous_trailing_comma : Error<
+  "extraneous trailing comma">;
 
 def ext_init_statement : ExtWarn<
   "'%select{if|switch}0' initialization statements are a C++17 extension">,
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index aa8b3870a188c66..e31ef7d404a2224 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -2237,6 +2237,9 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
 if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
   RunSignatureHelp();
 LHS = ExprError();
+  } else if (!HasError && HasTrailingComma) {
+// FIXME: add a FIXIT to remove the trailing comma.
+Diag(Tok, diag::err_extraneous_trailing_comma);
   } else if (LHS.isInvalid()) {
 for (auto &E : ArgExprs)
   Actions.CorrectDelayedTyposInExpr(E);
diff --git a/clang/test/Parser/recovery.cpp b/clang/test/Parser/recovery.cpp
index 4e2811c4cac926e..e318461e1961da4 100644
--- a/clang/test/Parser/recovery.cpp
+++ b/clang/test/Parser/recovery.cpp
@@ -215,3 +215,10 @@ struct ::template foo, struct ::template bar; // 
expected-error 2 {{expected ide
 struct ::foo struct::; // expected-error {{no struct named 'foo' in the global 
namespace}} expected-error {{expected identifier}}
 class :: : {} a;  // expected-error {{expected identifier}} expected-error 
{{expected class name}}
 }
+
+namespace GH125225 {
+void func(int);
+void k() {
+  func(1, ); // expected-error {{extraneous trailing comma}}
+}
+}

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


[clang] [clang] Catch missing format attributes (PR #105479)

2025-01-31 Thread Budimir Aranđelović via cfe-commits

https://github.com/budimirarandjelovichtec updated 
https://github.com/llvm/llvm-project/pull/105479

From 2571d6fb3fcb039b22ae79dde08dd79e277f8910 Mon Sep 17 00:00:00 2001
From: budimirarandjelovicsyrmia 
Date: Fri, 5 Apr 2024 15:20:37 +0200
Subject: [PATCH] [clang] Catch missing format attributes

---
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/Basic/DiagnosticGroups.td |   1 -
 .../clang/Basic/DiagnosticSemaKinds.td|   4 +
 clang/include/clang/Sema/Attr.h   |   7 +
 clang/include/clang/Sema/Sema.h   |   5 +
 clang/lib/Sema/SemaChecking.cpp   |   4 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +
 clang/lib/Sema/SemaDeclAttr.cpp   | 179 +++-
 clang/test/Sema/attr-format-missing.c | 259 ++
 clang/test/Sema/attr-format-missing.cpp   | 189 +
 10 files changed, 649 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/Sema/attr-format-missing.c
 create mode 100644 clang/test/Sema/attr-format-missing.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8c290437fe16fe..4508444dd65471 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -110,6 +110,9 @@ Attribute Changes in Clang
 Improvements to Clang's diagnostics
 ---
 
+- Clang now diagnoses missing format attributes for non-template functions
+  and class/struct/union members. (#GH60718)
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 527e588d46a049..3399db10927f4f 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -534,7 +534,6 @@ def MainReturnType : DiagGroup<"main-return-type">;
 def MaxUnsignedZero : DiagGroup<"max-unsigned-zero">;
 def MissingBraces : DiagGroup<"missing-braces">;
 def MissingDeclarations: DiagGroup<"missing-declarations">;
-def : DiagGroup<"missing-format-attribute">;
 def MissingIncludeDirs : DiagGroup<"missing-include-dirs">;
 def MissingNoreturn : DiagGroup<"missing-noreturn">;
 def MultiChar : DiagGroup<"multichar">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 2ac3879a4caabc..d7e24d943139ba 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1061,6 +1061,10 @@ def err_opencl_invalid_param : Error<
   "declaring function parameter of type %0 is not allowed%select{; did you 
forget * ?|}1">;
 def err_opencl_invalid_return : Error<
   "declaring function return value of type %0 is not allowed %select{; did you 
forget * ?|}1">;
+def warn_missing_format_attribute : Warning<
+  "diagnostic behavior may be improved by adding the %0 format attribute to 
the declaration of %1">,
+  InGroup>, DefaultIgnore;
+def note_format_function : Note<"%0 format function">;
 def warn_pragma_options_align_reset_failed : Warning<
   "#pragma options align=reset failed: %0">,
   InGroup;
diff --git a/clang/include/clang/Sema/Attr.h b/clang/include/clang/Sema/Attr.h
index 3f0b10212789a4..37c124ca7b454a 100644
--- a/clang/include/clang/Sema/Attr.h
+++ b/clang/include/clang/Sema/Attr.h
@@ -123,6 +123,13 @@ inline bool isInstanceMethod(const Decl *D) {
   return false;
 }
 
+inline bool checkIfMethodHasImplicitObjectParameter(const Decl *D) {
+  if (const auto *MethodDecl = dyn_cast(D))
+return MethodDecl->isInstance() &&
+   !MethodDecl->hasCXXExplicitFunctionObjectParameter();
+  return false;
+}
+
 /// Diagnose mutually exclusive attributes when present on a given
 /// declaration. Returns true if diagnosed.
 template 
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 472a0e25adc975..9e2c5785414a58 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4613,6 +4613,11 @@ class Sema final : public SemaBase {
 
   enum class RetainOwnershipKind { NS, CF, OS };
 
+  void DetectMissingFormatAttributes(const FunctionDecl *Callee,
+ ArrayRef Args,
+ SourceLocation Loc);
+  void EmitMissingFormatAttributesDiagnostic(const FunctionDecl *Caller);
+
   UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI,
   StringRef UuidAsWritten, MSGuidDecl *GuidDecl);
 
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 61b2c8cf1cad72..edca3c7c8339a8 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -3455,8 +3455,10 @@ void Sema::checkCall(NamedDecl *FDecl, const 
FunctionProtoType *Proto,
 }
   }
 
-  if (FD)
+  if (FD) {
 diagnoseArgDependentDiagnoseIfAttrs(FD, ThisArg, Args, Loc);
+DetectMissingFormatAttributes(FD, Args, Loc);
+  }
 }

[clang] Pass -offload-lto instead of -lto for cuda/hip kernels (PR #125243)

2025-01-31 Thread Omar Ahmed via cfe-commits

https://github.com/omarahmed updated 
https://github.com/llvm/llvm-project/pull/125243

>From fcfe4fafa937b6320e779f56c2ba42327df143d4 Mon Sep 17 00:00:00 2001
From: omarahmed 
Date: Fri, 31 Jan 2025 15:42:11 +
Subject: [PATCH] Pass -offload-lto instead of -lto for cuda/hip kernels

---
 clang/test/Driver/linker-wrapper.c | 18 +-
 .../ClangLinkerWrapper.cpp |  7 ++-
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/clang/test/Driver/linker-wrapper.c 
b/clang/test/Driver/linker-wrapper.c
index f416ee5f4463bcc..0a2bc16a15ae492 100644
--- a/clang/test/Driver/linker-wrapper.c
+++ b/clang/test/Driver/linker-wrapper.c
@@ -21,7 +21,7 @@ __attribute__((visibility("protected"), used)) int x;
 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
 // RUN:   --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s 
--check-prefix=NVPTX-LINK
 
-// NVPTX-LINK: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda 
-march=sm_70 -O2 -flto {{.*}}.o {{.*}}.o
+// NVPTX-LINK: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda 
-march=sm_70 -O2 -foffload-lto {{.*}}.o {{.*}}.o
 
 // RUN: clang-offload-packager -o %t.out \
 // RUN:   
--image=file=%t.elf.o,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70 \
@@ -30,7 +30,7 @@ __attribute__((visibility("protected"), used)) int x;
 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run 
--device-debug -O0 \
 // RUN:   --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s 
--check-prefix=NVPTX-LINK-DEBUG
 
-// NVPTX-LINK-DEBUG: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda 
-march=sm_70 -O2 -flto {{.*}}.o {{.*}}.o -g
+// NVPTX-LINK-DEBUG: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda 
-march=sm_70 -O2 -foffload-lto {{.*}}.o {{.*}}.o -g
 
 // RUN: clang-offload-packager -o %t.out \
 // RUN:   
--image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx908 \
@@ -39,7 +39,7 @@ __attribute__((visibility("protected"), used)) int x;
 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
 // RUN:   --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s 
--check-prefix=AMDGPU-LINK
 
-// AMDGPU-LINK: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa 
-mcpu=gfx908 -O2 -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o
+// AMDGPU-LINK: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa 
-mcpu=gfx908 -O2 -foffload-lto -Wl,--no-undefined {{.*}}.o {{.*}}.o
 
 // RUN: clang-offload-packager -o %t.out \
 // RUN:   
--image=file=%t.amdgpu.bc,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx1030 \
@@ -48,7 +48,7 @@ __attribute__((visibility("protected"), used)) int x;
 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run 
--save-temps -O2 \
 // RUN:   --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s 
--check-prefix=AMDGPU-LTO-TEMPS
 
-// AMDGPU-LTO-TEMPS: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa 
-mcpu=gfx1030 -O2 -flto -Wl,--no-undefined {{.*}}.o -save-temps
+// AMDGPU-LTO-TEMPS: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa 
-mcpu=gfx1030 -O2 -foffload-lto -Wl,--no-undefined {{.*}}.o -save-temps
 
 // RUN: clang-offload-packager -o %t.out \
 // RUN:   --image=file=%t.elf.o,kind=openmp,triple=x86_64-unknown-linux-gnu \
@@ -148,7 +148,7 @@ __attribute__((visibility("protected"), used)) int x;
 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run 
--clang-backend \
 // RUN:   --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s 
--check-prefix=CLANG-BACKEND
 
-// CLANG-BACKEND: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa 
-mcpu=gfx908 -O2 -flto -Wl,--no-undefined {{.*}}.o
+// CLANG-BACKEND: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa 
-mcpu=gfx908 -O2 -foffload-lto -Wl,--no-undefined {{.*}}.o
 
 // RUN: clang-offload-packager -o %t.out \
 // RUN:   
--image=file=%t.elf.o,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70
@@ -171,8 +171,8 @@ __attribute__((visibility("protected"), used)) int x;
 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
 // RUN:   --linker-path=/usr/bin/ld %t-on.o %t-off.o %t.a -o a.out 2>&1 | 
FileCheck %s --check-prefix=AMD-TARGET-ID
 
-// AMD-TARGET-ID: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa 
-mcpu=gfx90a:xnack+ -O2 -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o
-// AMD-TARGET-ID: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa 
-mcpu=gfx90a:xnack- -O2 -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o
+// AMD-TARGET-ID: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa 
-mcpu=gfx90a:xnack+ -O2 -foffload-lto -Wl,--no-undefined {{.*}}.o {{.*}}.o
+// AMD-TARGET-ID: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa 
-mcpu=gfx90a:xnack- -O2 -foffload-lto -Wl,--no-undefined {{.*}}.o {{.*}}.o
 
 // RUN: clang-offload-packager -o %t-lib.out \
 // RUN:   
--image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=generic
@@ -187,8 +187,8 @@ _

[clang] Pass -offload-lto instead of -lto for cuda/hip kernels (PR #125243)

2025-01-31 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 6dd07b17c7ff8e61073a7732e09fa828a64f7bec 
b771905671c80912aceeec414a49fe4581c9b796 --extensions cpp,c -- 
clang/test/Driver/linker-wrapper.c 
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index ff516f2e69..dd87eeff6a 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -502,7 +502,7 @@ Expected clang(ArrayRef InputFiles, 
const ArgList &Args) {
 CmdArgs.append(
 {"-Xlinker",
  Args.MakeArgString("--plugin-opt=" + StringRef(Arg->getValue()))});
-  
+
   if (Triple.isNVPTX() || Triple.isAMDGPU()) {
 CmdArgs.push_back("-foffload-lto");
   } else {

``




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


[clang] [llvm] [Hexagon] Set the default compilation target to V68 (PR #125239)

2025-01-31 Thread Ikhlas Ajbar via cfe-commits

https://github.com/iajbar created 
https://github.com/llvm/llvm-project/pull/125239

Set the default compilation target to V68 if no Hexagon processor is specified 
at the command-line.
Add the elf header changes for v81/v83/v85 architectures.

>From 041813a5de078adaf8d86bbeb2c92f19ce5828eb Mon Sep 17 00:00:00 2001
From: Ikhlas Ajbar 
Date: Thu, 30 Jan 2025 15:35:51 -0800
Subject: [PATCH] [Hexagon] Set the default compilation target to V68

Set the default compilation target to V68 if no Hexagon processor is specified
at the command-line.
Add the elf header changes for v81/v83/v85 architectures.
---
 clang/lib/Driver/ToolChains/Hexagon.cpp |  2 +-
 clang/test/Driver/hexagon-cpu-default.c |  4 
 llvm/include/llvm/BinaryFormat/ELF.h| 10 ++
 3 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Driver/hexagon-cpu-default.c

diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp 
b/clang/lib/Driver/ToolChains/Hexagon.cpp
index 76cedf312d68a1..91dd582eb05a00 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -803,7 +803,7 @@ bool HexagonToolChain::isAutoHVXEnabled(const 
llvm::opt::ArgList &Args) {
 // if no Hexagon processor is selected at the command-line.
 //
 StringRef HexagonToolChain::GetDefaultCPU() {
-  return "hexagonv60";
+  return "hexagonv68";
 }
 
 StringRef HexagonToolChain::GetTargetCPUVersion(const ArgList &Args) {
diff --git a/clang/test/Driver/hexagon-cpu-default.c 
b/clang/test/Driver/hexagon-cpu-default.c
new file mode 100644
index 00..31fb839f216569
--- /dev/null
+++ b/clang/test/Driver/hexagon-cpu-default.c
@@ -0,0 +1,4 @@
+// CHECK: "-target-cpu" "hexagonv68"
+
+// RUN: %clang -c %s -### --target=hexagon-unknown-elf \
+// RUN:  2>&1 | FileCheck  %s
diff --git a/llvm/include/llvm/BinaryFormat/ELF.h 
b/llvm/include/llvm/BinaryFormat/ELF.h
index 48ae0db80f43ee..8853c4a88b0b59 100644
--- a/llvm/include/llvm/BinaryFormat/ELF.h
+++ b/llvm/include/llvm/BinaryFormat/ELF.h
@@ -619,6 +619,7 @@ enum {
   EF_HEXAGON_MACH_V5 = 0x0004,   // Hexagon V5
   EF_HEXAGON_MACH_V55 = 0x0005,  // Hexagon V55
   EF_HEXAGON_MACH_V60 = 0x0060,  // Hexagon V60
+  EF_HEXAGON_MACH_V61 = 0x0061,  // Hexagon V61
   EF_HEXAGON_MACH_V62 = 0x0062,  // Hexagon V62
   EF_HEXAGON_MACH_V65 = 0x0065,  // Hexagon V65
   EF_HEXAGON_MACH_V66 = 0x0066,  // Hexagon V66
@@ -630,7 +631,11 @@ enum {
   EF_HEXAGON_MACH_V71T = 0x8071, // Hexagon V71T
   EF_HEXAGON_MACH_V73 = 0x0073,  // Hexagon V73
   EF_HEXAGON_MACH_V75 = 0x0075,  // Hexagon V75
+  EF_HEXAGON_MACH_V77 = 0x0077,  // Hexagon V77
   EF_HEXAGON_MACH_V79 = 0x0079,  // Hexagon V79
+  EF_HEXAGON_MACH_V81 = 0x0081,  // Hexagon V81
+  EF_HEXAGON_MACH_V83 = 0x0083,  // Hexagon V83
+  EF_HEXAGON_MACH_V85 = 0x0085,  // Hexagon V85
   EF_HEXAGON_MACH = 0x03ff,  // Hexagon V..
 
   // Highest ISA version flags
@@ -642,6 +647,7 @@ enum {
   EF_HEXAGON_ISA_V5 = 0x0040,   // Hexagon V5 ISA
   EF_HEXAGON_ISA_V55 = 0x0050,  // Hexagon V55 ISA
   EF_HEXAGON_ISA_V60 = 0x0060,  // Hexagon V60 ISA
+  EF_HEXAGON_ISA_V61 = 0x0061,  // Hexagon V61 ISA
   EF_HEXAGON_ISA_V62 = 0x0062,  // Hexagon V62 ISA
   EF_HEXAGON_ISA_V65 = 0x0065,  // Hexagon V65 ISA
   EF_HEXAGON_ISA_V66 = 0x0066,  // Hexagon V66 ISA
@@ -651,7 +657,11 @@ enum {
   EF_HEXAGON_ISA_V71 = 0x0071,  // Hexagon V71 ISA
   EF_HEXAGON_ISA_V73 = 0x0073,  // Hexagon V73 ISA
   EF_HEXAGON_ISA_V75 = 0x0075,  // Hexagon V75 ISA
+  EF_HEXAGON_ISA_V77 = 0x0077,  // Hexagon V77 ISA
   EF_HEXAGON_ISA_V79 = 0x0079,  // Hexagon V79 ISA
+  EF_HEXAGON_ISA_V81 = 0x0081,  // Hexagon V81 ISA
+  EF_HEXAGON_ISA_V83 = 0x0083,  // Hexagon V83 ISA
+  EF_HEXAGON_ISA_V85 = 0x0085,  // Hexagon V85 ISA
   EF_HEXAGON_ISA = 0x03ff,  // Hexagon V.. ISA
 };
 

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


[clang] Pass -offload-lto instead of -lto for cuda/hip kernels (PR #125243)

2025-01-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Omar Ahmed (omarahmed)


Changes

ClangLinkerWrapper tool in one of its clang commands to generate ptx kernel 
binary from llvm bitcode kernel was using -flto option which should be only 
used for cpu code not gpu kernel code. This PR fixes that by changing that to 
-foffload-lto for cuda/hip kernels.

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


2 Files Affected:

- (modified) clang/test/Driver/linker-wrapper.c (+9-9) 
- (modified) clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp (+6-1) 


``diff
diff --git a/clang/test/Driver/linker-wrapper.c 
b/clang/test/Driver/linker-wrapper.c
index f416ee5f4463bc..0a2bc16a15ae49 100644
--- a/clang/test/Driver/linker-wrapper.c
+++ b/clang/test/Driver/linker-wrapper.c
@@ -21,7 +21,7 @@ __attribute__((visibility("protected"), used)) int x;
 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
 // RUN:   --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s 
--check-prefix=NVPTX-LINK
 
-// NVPTX-LINK: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda 
-march=sm_70 -O2 -flto {{.*}}.o {{.*}}.o
+// NVPTX-LINK: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda 
-march=sm_70 -O2 -foffload-lto {{.*}}.o {{.*}}.o
 
 // RUN: clang-offload-packager -o %t.out \
 // RUN:   
--image=file=%t.elf.o,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70 \
@@ -30,7 +30,7 @@ __attribute__((visibility("protected"), used)) int x;
 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run 
--device-debug -O0 \
 // RUN:   --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s 
--check-prefix=NVPTX-LINK-DEBUG
 
-// NVPTX-LINK-DEBUG: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda 
-march=sm_70 -O2 -flto {{.*}}.o {{.*}}.o -g
+// NVPTX-LINK-DEBUG: clang{{.*}} -o {{.*}}.img --target=nvptx64-nvidia-cuda 
-march=sm_70 -O2 -foffload-lto {{.*}}.o {{.*}}.o -g
 
 // RUN: clang-offload-packager -o %t.out \
 // RUN:   
--image=file=%t.elf.o,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx908 \
@@ -39,7 +39,7 @@ __attribute__((visibility("protected"), used)) int x;
 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
 // RUN:   --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s 
--check-prefix=AMDGPU-LINK
 
-// AMDGPU-LINK: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa 
-mcpu=gfx908 -O2 -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o
+// AMDGPU-LINK: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa 
-mcpu=gfx908 -O2 -foffload-lto -Wl,--no-undefined {{.*}}.o {{.*}}.o
 
 // RUN: clang-offload-packager -o %t.out \
 // RUN:   
--image=file=%t.amdgpu.bc,kind=openmp,triple=amdgcn-amd-amdhsa,arch=gfx1030 \
@@ -48,7 +48,7 @@ __attribute__((visibility("protected"), used)) int x;
 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run 
--save-temps -O2 \
 // RUN:   --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s 
--check-prefix=AMDGPU-LTO-TEMPS
 
-// AMDGPU-LTO-TEMPS: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa 
-mcpu=gfx1030 -O2 -flto -Wl,--no-undefined {{.*}}.o -save-temps
+// AMDGPU-LTO-TEMPS: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa 
-mcpu=gfx1030 -O2 -foffload-lto -Wl,--no-undefined {{.*}}.o -save-temps
 
 // RUN: clang-offload-packager -o %t.out \
 // RUN:   --image=file=%t.elf.o,kind=openmp,triple=x86_64-unknown-linux-gnu \
@@ -148,7 +148,7 @@ __attribute__((visibility("protected"), used)) int x;
 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run 
--clang-backend \
 // RUN:   --linker-path=/usr/bin/ld %t.o -o a.out 2>&1 | FileCheck %s 
--check-prefix=CLANG-BACKEND
 
-// CLANG-BACKEND: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa 
-mcpu=gfx908 -O2 -flto -Wl,--no-undefined {{.*}}.o
+// CLANG-BACKEND: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa 
-mcpu=gfx908 -O2 -foffload-lto -Wl,--no-undefined {{.*}}.o
 
 // RUN: clang-offload-packager -o %t.out \
 // RUN:   
--image=file=%t.elf.o,kind=openmp,triple=nvptx64-nvidia-cuda,arch=sm_70
@@ -171,8 +171,8 @@ __attribute__((visibility("protected"), used)) int x;
 // RUN: clang-linker-wrapper --host-triple=x86_64-unknown-linux-gnu --dry-run \
 // RUN:   --linker-path=/usr/bin/ld %t-on.o %t-off.o %t.a -o a.out 2>&1 | 
FileCheck %s --check-prefix=AMD-TARGET-ID
 
-// AMD-TARGET-ID: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa 
-mcpu=gfx90a:xnack+ -O2 -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o
-// AMD-TARGET-ID: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa 
-mcpu=gfx90a:xnack- -O2 -flto -Wl,--no-undefined {{.*}}.o {{.*}}.o
+// AMD-TARGET-ID: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa 
-mcpu=gfx90a:xnack+ -O2 -foffload-lto -Wl,--no-undefined {{.*}}.o {{.*}}.o
+// AMD-TARGET-ID: clang{{.*}} -o {{.*}}.img --target=amdgcn-amd-amdhsa 
-mcpu=gfx90a:xnack- -O2 -foffload-lto -Wl,--no-undefined {{.*}}.o {{.*}}.o
 
 // RUN: clang-offload-packager

[clang] [llvm] [Hexagon] Set the default compilation target to V68 (PR #125239)

2025-01-31 Thread Ikhlas Ajbar via cfe-commits

https://github.com/iajbar updated 
https://github.com/llvm/llvm-project/pull/125239

>From 31d9cadd9c14e703af6eafa20a5c6e4a69b9c526 Mon Sep 17 00:00:00 2001
From: Ikhlas Ajbar 
Date: Thu, 30 Jan 2025 15:35:51 -0800
Subject: [PATCH] [Hexagon] Set the default compilation target to V68

Set the default compilation target to V68 if no Hexagon processor is specified
at the command-line.
Add the elf header changes for v81/v83/v85 architectures.
---
 clang/lib/Driver/ToolChains/Hexagon.cpp |  4 +---
 clang/test/Driver/hexagon-cpu-default.c |  4 
 llvm/include/llvm/BinaryFormat/ELF.h| 10 ++
 3 files changed, 15 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Driver/hexagon-cpu-default.c

diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp 
b/clang/lib/Driver/ToolChains/Hexagon.cpp
index 76cedf312d68a1..7ca5ab9af88106 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -802,9 +802,7 @@ bool HexagonToolChain::isAutoHVXEnabled(const 
llvm::opt::ArgList &Args) {
 // Returns the default CPU for Hexagon. This is the default compilation target
 // if no Hexagon processor is selected at the command-line.
 //
-StringRef HexagonToolChain::GetDefaultCPU() {
-  return "hexagonv60";
-}
+StringRef HexagonToolChain::GetDefaultCPU() { return "hexagonv68"; }
 
 StringRef HexagonToolChain::GetTargetCPUVersion(const ArgList &Args) {
   Arg *CpuArg = nullptr;
diff --git a/clang/test/Driver/hexagon-cpu-default.c 
b/clang/test/Driver/hexagon-cpu-default.c
new file mode 100644
index 00..31fb839f216569
--- /dev/null
+++ b/clang/test/Driver/hexagon-cpu-default.c
@@ -0,0 +1,4 @@
+// CHECK: "-target-cpu" "hexagonv68"
+
+// RUN: %clang -c %s -### --target=hexagon-unknown-elf \
+// RUN:  2>&1 | FileCheck  %s
diff --git a/llvm/include/llvm/BinaryFormat/ELF.h 
b/llvm/include/llvm/BinaryFormat/ELF.h
index 48ae0db80f43ee..8853c4a88b0b59 100644
--- a/llvm/include/llvm/BinaryFormat/ELF.h
+++ b/llvm/include/llvm/BinaryFormat/ELF.h
@@ -619,6 +619,7 @@ enum {
   EF_HEXAGON_MACH_V5 = 0x0004,   // Hexagon V5
   EF_HEXAGON_MACH_V55 = 0x0005,  // Hexagon V55
   EF_HEXAGON_MACH_V60 = 0x0060,  // Hexagon V60
+  EF_HEXAGON_MACH_V61 = 0x0061,  // Hexagon V61
   EF_HEXAGON_MACH_V62 = 0x0062,  // Hexagon V62
   EF_HEXAGON_MACH_V65 = 0x0065,  // Hexagon V65
   EF_HEXAGON_MACH_V66 = 0x0066,  // Hexagon V66
@@ -630,7 +631,11 @@ enum {
   EF_HEXAGON_MACH_V71T = 0x8071, // Hexagon V71T
   EF_HEXAGON_MACH_V73 = 0x0073,  // Hexagon V73
   EF_HEXAGON_MACH_V75 = 0x0075,  // Hexagon V75
+  EF_HEXAGON_MACH_V77 = 0x0077,  // Hexagon V77
   EF_HEXAGON_MACH_V79 = 0x0079,  // Hexagon V79
+  EF_HEXAGON_MACH_V81 = 0x0081,  // Hexagon V81
+  EF_HEXAGON_MACH_V83 = 0x0083,  // Hexagon V83
+  EF_HEXAGON_MACH_V85 = 0x0085,  // Hexagon V85
   EF_HEXAGON_MACH = 0x03ff,  // Hexagon V..
 
   // Highest ISA version flags
@@ -642,6 +647,7 @@ enum {
   EF_HEXAGON_ISA_V5 = 0x0040,   // Hexagon V5 ISA
   EF_HEXAGON_ISA_V55 = 0x0050,  // Hexagon V55 ISA
   EF_HEXAGON_ISA_V60 = 0x0060,  // Hexagon V60 ISA
+  EF_HEXAGON_ISA_V61 = 0x0061,  // Hexagon V61 ISA
   EF_HEXAGON_ISA_V62 = 0x0062,  // Hexagon V62 ISA
   EF_HEXAGON_ISA_V65 = 0x0065,  // Hexagon V65 ISA
   EF_HEXAGON_ISA_V66 = 0x0066,  // Hexagon V66 ISA
@@ -651,7 +657,11 @@ enum {
   EF_HEXAGON_ISA_V71 = 0x0071,  // Hexagon V71 ISA
   EF_HEXAGON_ISA_V73 = 0x0073,  // Hexagon V73 ISA
   EF_HEXAGON_ISA_V75 = 0x0075,  // Hexagon V75 ISA
+  EF_HEXAGON_ISA_V77 = 0x0077,  // Hexagon V77 ISA
   EF_HEXAGON_ISA_V79 = 0x0079,  // Hexagon V79 ISA
+  EF_HEXAGON_ISA_V81 = 0x0081,  // Hexagon V81 ISA
+  EF_HEXAGON_ISA_V83 = 0x0083,  // Hexagon V83 ISA
+  EF_HEXAGON_ISA_V85 = 0x0085,  // Hexagon V85 ISA
   EF_HEXAGON_ISA = 0x03ff,  // Hexagon V.. ISA
 };
 

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


[clang] [llvm] [mlir] [clang][CodeGen][AA] Add `!llvm.errno.tbaa` gathering int-compatible TBAA nodes (PR #125258)

2025-01-31 Thread Antonio Frighetto via cfe-commits

antoniofrighetto wrote:

@nikic Mind glancing over the draft quickly? !llvm.errno.tbaa is being attached 
to individual load/store accessing errno, although I just realized that this 
information is already embedded in TBAA, so IIUC !llvm.errno.tbaa should just 
be a module-level list of int-compatible TBAA nodes. Is my latest understanding 
correct? That would make it much simpler than I thought. Sorry if I’m missing 
something!

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


[clang] [AArch64] Simplify definitions of SVE/SME intrinsics which set FPMR (PR #123796)

2025-01-31 Thread via cfe-commits

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

LGTM

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


[clang] 759ef58 - [Hexagon] Set the default compilation target to V68 (#125239)

2025-01-31 Thread via cfe-commits

Author: Ikhlas Ajbar
Date: 2025-01-31T11:59:39-06:00
New Revision: 759ef5811e2297f2cbe7578f7c118668e3467c6a

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

LOG: [Hexagon] Set the default compilation target to V68 (#125239)

Set the default compilation target to V68 if no Hexagon processor is
specified at the command-line.
Add the elf header changes for v81/v83/v85 architectures.

Added: 
clang/test/Driver/hexagon-cpu-default.c

Modified: 
clang/lib/Driver/ToolChains/Hexagon.cpp
llvm/include/llvm/BinaryFormat/ELF.h

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Hexagon.cpp 
b/clang/lib/Driver/ToolChains/Hexagon.cpp
index 76cedf312d68a1e..7ca5ab9af881064 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -802,9 +802,7 @@ bool HexagonToolChain::isAutoHVXEnabled(const 
llvm::opt::ArgList &Args) {
 // Returns the default CPU for Hexagon. This is the default compilation target
 // if no Hexagon processor is selected at the command-line.
 //
-StringRef HexagonToolChain::GetDefaultCPU() {
-  return "hexagonv60";
-}
+StringRef HexagonToolChain::GetDefaultCPU() { return "hexagonv68"; }
 
 StringRef HexagonToolChain::GetTargetCPUVersion(const ArgList &Args) {
   Arg *CpuArg = nullptr;

diff  --git a/clang/test/Driver/hexagon-cpu-default.c 
b/clang/test/Driver/hexagon-cpu-default.c
new file mode 100644
index 000..31fb839f216569d
--- /dev/null
+++ b/clang/test/Driver/hexagon-cpu-default.c
@@ -0,0 +1,4 @@
+// CHECK: "-target-cpu" "hexagonv68"
+
+// RUN: %clang -c %s -### --target=hexagon-unknown-elf \
+// RUN:  2>&1 | FileCheck  %s

diff  --git a/llvm/include/llvm/BinaryFormat/ELF.h 
b/llvm/include/llvm/BinaryFormat/ELF.h
index 48ae0db80f43ee7..8853c4a88b0b593 100644
--- a/llvm/include/llvm/BinaryFormat/ELF.h
+++ b/llvm/include/llvm/BinaryFormat/ELF.h
@@ -619,6 +619,7 @@ enum {
   EF_HEXAGON_MACH_V5 = 0x0004,   // Hexagon V5
   EF_HEXAGON_MACH_V55 = 0x0005,  // Hexagon V55
   EF_HEXAGON_MACH_V60 = 0x0060,  // Hexagon V60
+  EF_HEXAGON_MACH_V61 = 0x0061,  // Hexagon V61
   EF_HEXAGON_MACH_V62 = 0x0062,  // Hexagon V62
   EF_HEXAGON_MACH_V65 = 0x0065,  // Hexagon V65
   EF_HEXAGON_MACH_V66 = 0x0066,  // Hexagon V66
@@ -630,7 +631,11 @@ enum {
   EF_HEXAGON_MACH_V71T = 0x8071, // Hexagon V71T
   EF_HEXAGON_MACH_V73 = 0x0073,  // Hexagon V73
   EF_HEXAGON_MACH_V75 = 0x0075,  // Hexagon V75
+  EF_HEXAGON_MACH_V77 = 0x0077,  // Hexagon V77
   EF_HEXAGON_MACH_V79 = 0x0079,  // Hexagon V79
+  EF_HEXAGON_MACH_V81 = 0x0081,  // Hexagon V81
+  EF_HEXAGON_MACH_V83 = 0x0083,  // Hexagon V83
+  EF_HEXAGON_MACH_V85 = 0x0085,  // Hexagon V85
   EF_HEXAGON_MACH = 0x03ff,  // Hexagon V..
 
   // Highest ISA version flags
@@ -642,6 +647,7 @@ enum {
   EF_HEXAGON_ISA_V5 = 0x0040,   // Hexagon V5 ISA
   EF_HEXAGON_ISA_V55 = 0x0050,  // Hexagon V55 ISA
   EF_HEXAGON_ISA_V60 = 0x0060,  // Hexagon V60 ISA
+  EF_HEXAGON_ISA_V61 = 0x0061,  // Hexagon V61 ISA
   EF_HEXAGON_ISA_V62 = 0x0062,  // Hexagon V62 ISA
   EF_HEXAGON_ISA_V65 = 0x0065,  // Hexagon V65 ISA
   EF_HEXAGON_ISA_V66 = 0x0066,  // Hexagon V66 ISA
@@ -651,7 +657,11 @@ enum {
   EF_HEXAGON_ISA_V71 = 0x0071,  // Hexagon V71 ISA
   EF_HEXAGON_ISA_V73 = 0x0073,  // Hexagon V73 ISA
   EF_HEXAGON_ISA_V75 = 0x0075,  // Hexagon V75 ISA
+  EF_HEXAGON_ISA_V77 = 0x0077,  // Hexagon V77 ISA
   EF_HEXAGON_ISA_V79 = 0x0079,  // Hexagon V79 ISA
+  EF_HEXAGON_ISA_V81 = 0x0081,  // Hexagon V81 ISA
+  EF_HEXAGON_ISA_V83 = 0x0083,  // Hexagon V83 ISA
+  EF_HEXAGON_ISA_V85 = 0x0085,  // Hexagon V85 ISA
   EF_HEXAGON_ISA = 0x03ff,  // Hexagon V.. ISA
 };
 



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


[clang] [llvm] [Hexagon] Set the default compilation target to V68 (PR #125239)

2025-01-31 Thread Ikhlas Ajbar via cfe-commits

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


[clang] [CIR] Initial implementation of CIR-to-LLVM IR lowering pass (PR #125260)

2025-01-31 Thread Erich Keane via cfe-commits


@@ -22,13 +34,127 @@ using namespace llvm;
 namespace cir {
 namespace direct {
 
+struct ConvertCIRToLLVMPass
+: public mlir::PassWrapper> {
+  void getDependentDialects(mlir::DialectRegistry ®istry) const override {
+registry.insert();
+  }
+  void runOnOperation() final;
+
+  StringRef getDescription() const override {
+return "Convert the prepared CIR dialect module to LLVM dialect";
+  }
+
+  StringRef getArgument() const override { return "cir-flat-to-llvm"; }
+};
+
+mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite(
+cir::GlobalOp op, OpAdaptor adaptor,
+mlir::ConversionPatternRewriter &rewriter) const {
+
+  // Fetch required values to create LLVM op.
+  const mlir::Type cirSymType = op.getSymType();
+
+  // This is the LLVM dialect type

erichkeane wrote:

```suggestion
  // This is the LLVM dialect type.
```

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


[clang] [CIR] Initial implementation of CIR-to-LLVM IR lowering pass (PR #125260)

2025-01-31 Thread Erich Keane via cfe-commits


@@ -1,8 +1,10 @@
 // Smoke test for ClangIR-to-LLVM IR code generation
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o 
-  | FileCheck %s
 
-// TODO: Add checks when proper lowering is implemented.
-//   For now, we're just creating an empty module.
-// CHECK: ModuleID
+int a;
 
-void foo() {}

erichkeane wrote:

What happened to the function?  Can we put that here even though it doesn't 
result in anything? Or perhaps catch the error for now?

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


[clang] [CIR] Initial implementation of CIR-to-LLVM IR lowering pass (PR #125260)

2025-01-31 Thread Erich Keane via cfe-commits


@@ -22,13 +34,127 @@ using namespace llvm;
 namespace cir {
 namespace direct {
 
+struct ConvertCIRToLLVMPass
+: public mlir::PassWrapper> {
+  void getDependentDialects(mlir::DialectRegistry ®istry) const override {
+registry.insert();
+  }
+  void runOnOperation() final;
+
+  StringRef getDescription() const override {
+return "Convert the prepared CIR dialect module to LLVM dialect";
+  }
+
+  StringRef getArgument() const override { return "cir-flat-to-llvm"; }
+};
+
+mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite(
+cir::GlobalOp op, OpAdaptor adaptor,
+mlir::ConversionPatternRewriter &rewriter) const {
+
+  // Fetch required values to create LLVM op.
+  const mlir::Type cirSymType = op.getSymType();
+
+  // This is the LLVM dialect type
+  const mlir::Type llvmType = getTypeConverter()->convertType(cirSymType);
+  // These defaults are just here until the equivalent attributes are
+  // available on cir.global ops.
+  const bool isConst = false;
+  const bool isDsoLocal = true;
+  const mlir::LLVM::Linkage linkage = mlir::LLVM::Linkage::External;
+  const StringRef symbol = op.getSymName();
+  std::optional init = op.getInitialValue();
+
+  SmallVector attributes;
+
+  // Check for missing funcionalities.
+  if (!init.has_value()) {
+rewriter.replaceOpWithNewOp(
+op, llvmType, isConst, linkage, symbol, mlir::Attribute(),
+/*alignment*/ 0, /*addrSpace*/ 0, /*dsoLocal*/ isDsoLocal,
+/*threadLocal*/ false, /*comdat*/ mlir::SymbolRefAttr(), attributes);
+return mlir::success();
+  }
+
+  // Initializer is a constant array: convert it to a compatible llvm init.
+  if (auto intAttr = mlir::dyn_cast(init.value())) {

erichkeane wrote:

We already have 'float' types implemented in the Clang->CIR bit, could we 
perhaps add float here too if it is only a handful of lines?  Would be nice to 
see what this is going to look like some day.

Also, I find myself wondering if this should be some sort of visitor pattern 
instead.

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


[clang] [CIR] Initial implementation of CIR-to-LLVM IR lowering pass (PR #125260)

2025-01-31 Thread Erich Keane via cfe-commits


@@ -22,13 +34,127 @@ using namespace llvm;
 namespace cir {
 namespace direct {
 
+struct ConvertCIRToLLVMPass
+: public mlir::PassWrapper> {
+  void getDependentDialects(mlir::DialectRegistry ®istry) const override {
+registry.insert();
+  }
+  void runOnOperation() final;
+
+  StringRef getDescription() const override {
+return "Convert the prepared CIR dialect module to LLVM dialect";
+  }
+
+  StringRef getArgument() const override { return "cir-flat-to-llvm"; }
+};
+
+mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite(
+cir::GlobalOp op, OpAdaptor adaptor,
+mlir::ConversionPatternRewriter &rewriter) const {
+
+  // Fetch required values to create LLVM op.
+  const mlir::Type cirSymType = op.getSymType();
+
+  // This is the LLVM dialect type
+  const mlir::Type llvmType = getTypeConverter()->convertType(cirSymType);
+  // These defaults are just here until the equivalent attributes are
+  // available on cir.global ops.
+  const bool isConst = false;
+  const bool isDsoLocal = true;
+  const mlir::LLVM::Linkage linkage = mlir::LLVM::Linkage::External;
+  const StringRef symbol = op.getSymName();
+  std::optional init = op.getInitialValue();
+
+  SmallVector attributes;
+
+  // Check for missing funcionalities.
+  if (!init.has_value()) {
+rewriter.replaceOpWithNewOp(
+op, llvmType, isConst, linkage, symbol, mlir::Attribute(),
+/*alignment*/ 0, /*addrSpace*/ 0, /*dsoLocal*/ isDsoLocal,

erichkeane wrote:

```suggestion
/*alignment=*/ 0, /*addrSpace=*/ 0, isDsoLocal,
```

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


[clang] [CIR] Initial implementation of CIR-to-LLVM IR lowering pass (PR #125260)

2025-01-31 Thread Erich Keane via cfe-commits


@@ -22,13 +34,127 @@ using namespace llvm;
 namespace cir {
 namespace direct {
 
+struct ConvertCIRToLLVMPass
+: public mlir::PassWrapper> {
+  void getDependentDialects(mlir::DialectRegistry ®istry) const override {
+registry.insert();
+  }
+  void runOnOperation() final;
+
+  StringRef getDescription() const override {
+return "Convert the prepared CIR dialect module to LLVM dialect";
+  }
+
+  StringRef getArgument() const override { return "cir-flat-to-llvm"; }
+};
+
+mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite(
+cir::GlobalOp op, OpAdaptor adaptor,
+mlir::ConversionPatternRewriter &rewriter) const {
+
+  // Fetch required values to create LLVM op.
+  const mlir::Type cirSymType = op.getSymType();
+
+  // This is the LLVM dialect type
+  const mlir::Type llvmType = getTypeConverter()->convertType(cirSymType);
+  // These defaults are just here until the equivalent attributes are
+  // available on cir.global ops.
+  const bool isConst = false;
+  const bool isDsoLocal = true;
+  const mlir::LLVM::Linkage linkage = mlir::LLVM::Linkage::External;
+  const StringRef symbol = op.getSymName();
+  std::optional init = op.getInitialValue();
+
+  SmallVector attributes;
+
+  // Check for missing funcionalities.
+  if (!init.has_value()) {
+rewriter.replaceOpWithNewOp(
+op, llvmType, isConst, linkage, symbol, mlir::Attribute(),
+/*alignment*/ 0, /*addrSpace*/ 0, /*dsoLocal*/ isDsoLocal,
+/*threadLocal*/ false, /*comdat*/ mlir::SymbolRefAttr(), attributes);
+return mlir::success();
+  }
+
+  // Initializer is a constant array: convert it to a compatible llvm init.
+  if (auto intAttr = mlir::dyn_cast(init.value())) {

erichkeane wrote:

```suggestion
  if (const auto *intAttr = mlir::dyn_cast(init.value())) {
```

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


[clang] [CIR] Initial implementation of CIR-to-LLVM IR lowering pass (PR #125260)

2025-01-31 Thread Erich Keane via cfe-commits


@@ -22,13 +34,127 @@ using namespace llvm;
 namespace cir {
 namespace direct {
 
+struct ConvertCIRToLLVMPass
+: public mlir::PassWrapper> {
+  void getDependentDialects(mlir::DialectRegistry ®istry) const override {
+registry.insert();
+  }
+  void runOnOperation() final;
+
+  StringRef getDescription() const override {
+return "Convert the prepared CIR dialect module to LLVM dialect";
+  }
+
+  StringRef getArgument() const override { return "cir-flat-to-llvm"; }
+};
+
+mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite(
+cir::GlobalOp op, OpAdaptor adaptor,
+mlir::ConversionPatternRewriter &rewriter) const {
+
+  // Fetch required values to create LLVM op.
+  const mlir::Type cirSymType = op.getSymType();
+
+  // This is the LLVM dialect type
+  const mlir::Type llvmType = getTypeConverter()->convertType(cirSymType);
+  // These defaults are just here until the equivalent attributes are
+  // available on cir.global ops.
+  const bool isConst = false;
+  const bool isDsoLocal = true;

erichkeane wrote:

Perhaps extract alignment, addrspace, and threadlocal here too?

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


[clang] [clang][Sema] Improve template argument deduction diagnostic (PR #122754)

2025-01-31 Thread Matheus Izvekov via cfe-commits


@@ -4870,14 +4870,16 @@ def note_ovl_candidate_inconsistent_deduction_types : 
Note<
 "candidate template ignored: deduced values %diff{"
 "of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
 "%1 and %3 of conflicting types for parameter %0}2,4">;
-def note_ovl_candidate_explicit_arg_mismatch_named : Note<
+def note_ovl_candidate_explicit_arg_mismatch : Note<
 "candidate template ignored: invalid explicitly-specified argument "
-"for template parameter %0">;
+"for %ordinal0 template parameter">;
+def note_ovl_candidate_explicit_arg_mismatch_detail : Note<
+"%select{"
+"|: expected a type, but got value '%1'"
+"|: expected constant of type %3 but got type %1"
+"|: could not convert '%1' from %2 to %3}0">;

mizvekov wrote:

Thanks, that sounds like an improvement.

Do we produce additional notes explaining why it's not a constant expression?

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


[clang] [CIR] Initial implementation of CIR-to-LLVM IR lowering pass (PR #125260)

2025-01-31 Thread Erich Keane via cfe-commits


@@ -22,13 +34,127 @@ using namespace llvm;
 namespace cir {
 namespace direct {
 
+struct ConvertCIRToLLVMPass
+: public mlir::PassWrapper> {
+  void getDependentDialects(mlir::DialectRegistry ®istry) const override {
+registry.insert();
+  }
+  void runOnOperation() final;
+
+  StringRef getDescription() const override {
+return "Convert the prepared CIR dialect module to LLVM dialect";
+  }
+
+  StringRef getArgument() const override { return "cir-flat-to-llvm"; }
+};
+
+mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite(
+cir::GlobalOp op, OpAdaptor adaptor,
+mlir::ConversionPatternRewriter &rewriter) const {
+
+  // Fetch required values to create LLVM op.
+  const mlir::Type cirSymType = op.getSymType();
+
+  // This is the LLVM dialect type
+  const mlir::Type llvmType = getTypeConverter()->convertType(cirSymType);
+  // These defaults are just here until the equivalent attributes are
+  // available on cir.global ops.
+  const bool isConst = false;
+  const bool isDsoLocal = true;
+  const mlir::LLVM::Linkage linkage = mlir::LLVM::Linkage::External;
+  const StringRef symbol = op.getSymName();
+  std::optional init = op.getInitialValue();
+
+  SmallVector attributes;
+
+  // Check for missing funcionalities.
+  if (!init.has_value()) {
+rewriter.replaceOpWithNewOp(
+op, llvmType, isConst, linkage, symbol, mlir::Attribute(),
+/*alignment*/ 0, /*addrSpace*/ 0, /*dsoLocal*/ isDsoLocal,
+/*threadLocal*/ false, /*comdat*/ mlir::SymbolRefAttr(), attributes);
+return mlir::success();
+  }
+
+  // Initializer is a constant array: convert it to a compatible llvm init.
+  if (auto intAttr = mlir::dyn_cast(init.value())) {
+init = rewriter.getIntegerAttr(llvmType, intAttr.getValue());
+  } else {
+op.emitError() << "unsupported initializer '" << init.value() << "'";
+return mlir::failure();
+  }
+
+  // Rewrite op.
+  rewriter.replaceOpWithNewOp(
+  op, llvmType, isConst, linkage, symbol, init.value(), /*alignment*/ 0,
+  /*addrSpace*/ 0, /*dsoLocal*/ isDsoLocal, /*threadLocal*/ false,
+  /*comdat*/ mlir::SymbolRefAttr(), attributes);
+
+  return mlir::success();
+}
+
+static void prepareTypeConverter(mlir::LLVMTypeConverter &converter,
+ mlir::DataLayout &dataLayout) {
+  converter.addConversion([&](cir::IntType type) -> mlir::Type {
+// LLVM doesn't work with signed types, so we drop the CIR signs here.
+return mlir::IntegerType::get(type.getContext(), type.getWidth());
+  });
+}
+
+void ConvertCIRToLLVMPass::runOnOperation() {
+  llvm::TimeTraceScope scope("Convert CIR to LLVM Pass");
+
+  mlir::ModuleOp module = getOperation();

erichkeane wrote:

how big is this thing?  Should it be a reference?

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


[clang] [CIR] Initial implementation of CIR-to-LLVM IR lowering pass (PR #125260)

2025-01-31 Thread Erich Keane via cfe-commits


@@ -22,13 +34,127 @@ using namespace llvm;
 namespace cir {
 namespace direct {
 
+struct ConvertCIRToLLVMPass
+: public mlir::PassWrapper> {
+  void getDependentDialects(mlir::DialectRegistry ®istry) const override {
+registry.insert();
+  }
+  void runOnOperation() final;
+
+  StringRef getDescription() const override {
+return "Convert the prepared CIR dialect module to LLVM dialect";
+  }
+
+  StringRef getArgument() const override { return "cir-flat-to-llvm"; }
+};
+
+mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite(
+cir::GlobalOp op, OpAdaptor adaptor,
+mlir::ConversionPatternRewriter &rewriter) const {
+
+  // Fetch required values to create LLVM op.
+  const mlir::Type cirSymType = op.getSymType();
+
+  // This is the LLVM dialect type
+  const mlir::Type llvmType = getTypeConverter()->convertType(cirSymType);
+  // These defaults are just here until the equivalent attributes are

erichkeane wrote:

```suggestion
  // FIXME: These default values are placeholders until the the equivalent 
attributes are available on cir.global ops.
```
^^ Plus word-wrap.

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


[clang] [CIR] Initial implementation of CIR-to-LLVM IR lowering pass (PR #125260)

2025-01-31 Thread Erich Keane via cfe-commits


@@ -22,13 +34,127 @@ using namespace llvm;
 namespace cir {
 namespace direct {
 
+struct ConvertCIRToLLVMPass
+: public mlir::PassWrapper> {
+  void getDependentDialects(mlir::DialectRegistry ®istry) const override {
+registry.insert();
+  }
+  void runOnOperation() final;
+
+  StringRef getDescription() const override {
+return "Convert the prepared CIR dialect module to LLVM dialect";
+  }
+
+  StringRef getArgument() const override { return "cir-flat-to-llvm"; }
+};
+
+mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite(
+cir::GlobalOp op, OpAdaptor adaptor,
+mlir::ConversionPatternRewriter &rewriter) const {
+
+  // Fetch required values to create LLVM op.
+  const mlir::Type cirSymType = op.getSymType();
+
+  // This is the LLVM dialect type
+  const mlir::Type llvmType = getTypeConverter()->convertType(cirSymType);
+  // These defaults are just here until the equivalent attributes are
+  // available on cir.global ops.
+  const bool isConst = false;
+  const bool isDsoLocal = true;
+  const mlir::LLVM::Linkage linkage = mlir::LLVM::Linkage::External;
+  const StringRef symbol = op.getSymName();
+  std::optional init = op.getInitialValue();
+
+  SmallVector attributes;
+
+  // Check for missing funcionalities.
+  if (!init.has_value()) {
+rewriter.replaceOpWithNewOp(
+op, llvmType, isConst, linkage, symbol, mlir::Attribute(),
+/*alignment*/ 0, /*addrSpace*/ 0, /*dsoLocal*/ isDsoLocal,
+/*threadLocal*/ false, /*comdat*/ mlir::SymbolRefAttr(), attributes);
+return mlir::success();
+  }
+
+  // Initializer is a constant array: convert it to a compatible llvm init.
+  if (auto intAttr = mlir::dyn_cast(init.value())) {
+init = rewriter.getIntegerAttr(llvmType, intAttr.getValue());
+  } else {
+op.emitError() << "unsupported initializer '" << init.value() << "'";
+return mlir::failure();
+  }
+
+  // Rewrite op.
+  rewriter.replaceOpWithNewOp(
+  op, llvmType, isConst, linkage, symbol, init.value(), /*alignment*/ 0,
+  /*addrSpace*/ 0, /*dsoLocal*/ isDsoLocal, /*threadLocal*/ false,

erichkeane wrote:

Same other suggestions on comments.

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


[clang] [CIR] Initial implementation of CIR-to-LLVM IR lowering pass (PR #125260)

2025-01-31 Thread Erich Keane via cfe-commits


@@ -22,13 +34,127 @@ using namespace llvm;
 namespace cir {
 namespace direct {
 
+struct ConvertCIRToLLVMPass
+: public mlir::PassWrapper> {
+  void getDependentDialects(mlir::DialectRegistry ®istry) const override {
+registry.insert();
+  }
+  void runOnOperation() final;
+
+  StringRef getDescription() const override {
+return "Convert the prepared CIR dialect module to LLVM dialect";
+  }
+
+  StringRef getArgument() const override { return "cir-flat-to-llvm"; }
+};
+
+mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite(
+cir::GlobalOp op, OpAdaptor adaptor,
+mlir::ConversionPatternRewriter &rewriter) const {
+
+  // Fetch required values to create LLVM op.
+  const mlir::Type cirSymType = op.getSymType();
+
+  // This is the LLVM dialect type
+  const mlir::Type llvmType = getTypeConverter()->convertType(cirSymType);
+  // These defaults are just here until the equivalent attributes are
+  // available on cir.global ops.
+  const bool isConst = false;
+  const bool isDsoLocal = true;
+  const mlir::LLVM::Linkage linkage = mlir::LLVM::Linkage::External;
+  const StringRef symbol = op.getSymName();
+  std::optional init = op.getInitialValue();
+
+  SmallVector attributes;
+
+  // Check for missing funcionalities.
+  if (!init.has_value()) {
+rewriter.replaceOpWithNewOp(
+op, llvmType, isConst, linkage, symbol, mlir::Attribute(),
+/*alignment*/ 0, /*addrSpace*/ 0, /*dsoLocal*/ isDsoLocal,
+/*threadLocal*/ false, /*comdat*/ mlir::SymbolRefAttr(), attributes);
+return mlir::success();
+  }
+
+  // Initializer is a constant array: convert it to a compatible llvm init.
+  if (auto intAttr = mlir::dyn_cast(init.value())) {
+init = rewriter.getIntegerAttr(llvmType, intAttr.getValue());
+  } else {
+op.emitError() << "unsupported initializer '" << init.value() << "'";
+return mlir::failure();
+  }
+
+  // Rewrite op.
+  rewriter.replaceOpWithNewOp(
+  op, llvmType, isConst, linkage, symbol, init.value(), /*alignment*/ 0,
+  /*addrSpace*/ 0, /*dsoLocal*/ isDsoLocal, /*threadLocal*/ false,

erichkeane wrote:

```suggestion
  /*addrSpace*/ 0, isDsoLocal, /*threadLocal*/ false,
```

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


[clang] [CIR] Initial implementation of CIR-to-LLVM IR lowering pass (PR #125260)

2025-01-31 Thread Erich Keane via cfe-commits


@@ -22,13 +34,127 @@ using namespace llvm;
 namespace cir {
 namespace direct {
 
+struct ConvertCIRToLLVMPass
+: public mlir::PassWrapper> {
+  void getDependentDialects(mlir::DialectRegistry ®istry) const override {
+registry.insert();
+  }
+  void runOnOperation() final;
+
+  StringRef getDescription() const override {
+return "Convert the prepared CIR dialect module to LLVM dialect";
+  }
+
+  StringRef getArgument() const override { return "cir-flat-to-llvm"; }
+};
+
+mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite(
+cir::GlobalOp op, OpAdaptor adaptor,
+mlir::ConversionPatternRewriter &rewriter) const {
+
+  // Fetch required values to create LLVM op.
+  const mlir::Type cirSymType = op.getSymType();
+
+  // This is the LLVM dialect type
+  const mlir::Type llvmType = getTypeConverter()->convertType(cirSymType);
+  // These defaults are just here until the equivalent attributes are
+  // available on cir.global ops.
+  const bool isConst = false;
+  const bool isDsoLocal = true;
+  const mlir::LLVM::Linkage linkage = mlir::LLVM::Linkage::External;
+  const StringRef symbol = op.getSymName();
+  std::optional init = op.getInitialValue();
+
+  SmallVector attributes;
+
+  // Check for missing funcionalities.
+  if (!init.has_value()) {
+rewriter.replaceOpWithNewOp(
+op, llvmType, isConst, linkage, symbol, mlir::Attribute(),
+/*alignment*/ 0, /*addrSpace*/ 0, /*dsoLocal*/ isDsoLocal,
+/*threadLocal*/ false, /*comdat*/ mlir::SymbolRefAttr(), attributes);
+return mlir::success();
+  }
+
+  // Initializer is a constant array: convert it to a compatible llvm init.
+  if (auto intAttr = mlir::dyn_cast(init.value())) {
+init = rewriter.getIntegerAttr(llvmType, intAttr.getValue());
+  } else {
+op.emitError() << "unsupported initializer '" << init.value() << "'";
+return mlir::failure();
+  }
+
+  // Rewrite op.
+  rewriter.replaceOpWithNewOp(
+  op, llvmType, isConst, linkage, symbol, init.value(), /*alignment*/ 0,
+  /*addrSpace*/ 0, /*dsoLocal*/ isDsoLocal, /*threadLocal*/ false,
+  /*comdat*/ mlir::SymbolRefAttr(), attributes);
+
+  return mlir::success();
+}
+
+static void prepareTypeConverter(mlir::LLVMTypeConverter &converter,
+ mlir::DataLayout &dataLayout) {
+  converter.addConversion([&](cir::IntType type) -> mlir::Type {
+// LLVM doesn't work with signed types, so we drop the CIR signs here.
+return mlir::IntegerType::get(type.getContext(), type.getWidth());
+  });
+}
+
+void ConvertCIRToLLVMPass::runOnOperation() {
+  llvm::TimeTraceScope scope("Convert CIR to LLVM Pass");
+
+  mlir::ModuleOp module = getOperation();
+  mlir::DataLayout dl(module);
+  mlir::LLVMTypeConverter converter(&getContext());
+  prepareTypeConverter(converter, dl); // , lowerModule.get());
+
+  mlir::RewritePatternSet patterns(&getContext());
+
+  patterns.add(converter, patterns.getContext(), 
dl);
+
+  mlir::ConversionTarget target(getContext());
+  target.addLegalOp();
+  target.addLegalDialect();
+  target.addIllegalDialect();
+
+  if (failed(applyPartialConversion(module, target, std::move(patterns
+signalPassFailure();
+}
+
+static std::unique_ptr createConvertCIRToLLVMPass() {
+  return std::make_unique();
+}
+
+static void populateCIRToLLVMPasses(mlir::OpPassManager &pm) {
+  pm.addPass(createConvertCIRToLLVMPass());
+}
+
 std::unique_ptr
 lowerDirectlyFromCIRToLLVMIR(mlir::ModuleOp mlirModule, LLVMContext &llvmCtx) {
   llvm::TimeTraceScope scope("lower from CIR to LLVM directly");
 
+  mlir::MLIRContext *mlirCtx = mlirModule.getContext();
+
+  mlir::PassManager pm(mlirCtx);
+  populateCIRToLLVMPasses(pm);
+
+  bool result = !mlir::failed(pm.run(mlirModule));
+  if (!result)
+report_fatal_error(
+"The pass manager failed to lower CIR to LLVMIR dialect!");
+
+  mlir::registerBuiltinDialectTranslation(*mlirCtx);
+  mlir::registerLLVMDialectTranslation(*mlirCtx);
+
+  llvm::TimeTraceScope translateScope("translateModuleToLLVMIR");
+
   std::optional moduleName = mlirModule.getName();
-  auto llvmModule = std::make_unique(
-  moduleName ? *moduleName : "CIRToLLVMModule", llvmCtx);
+  std::unique_ptr llvmModule = mlir::translateModuleToLLVMIR(
+  mlirModule, llvmCtx, moduleName ? *moduleName : "CIRToLLVMModule");

erichkeane wrote:

```suggestion
  mlirModule, llvmCtx, moduleName.value_or("CIRToLLVMModule"));
```

Better yet, make `moduleName` above a `StringRef`, and just do 
`mlirModule.getName().value_or("CIRToLLVMModule"));`

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


[clang] [CIR] Initial implementation of CIR-to-LLVM IR lowering pass (PR #125260)

2025-01-31 Thread Erich Keane via cfe-commits


@@ -31,6 +33,24 @@ namespace direct {
 std::unique_ptr
 lowerDirectlyFromCIRToLLVMIR(mlir::ModuleOp mlirModule,
  llvm::LLVMContext &llvmCtx);
+
+class CIRToLLVMGlobalOpLowering
+: public mlir::OpConversionPattern {
+  mlir::DataLayout const &dataLayout;

erichkeane wrote:

curious why `east const` for only this type?

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


[clang] [CIR] Initial implementation of CIR-to-LLVM IR lowering pass (PR #125260)

2025-01-31 Thread Erich Keane via cfe-commits


@@ -22,13 +34,127 @@ using namespace llvm;
 namespace cir {
 namespace direct {
 
+struct ConvertCIRToLLVMPass
+: public mlir::PassWrapper> {
+  void getDependentDialects(mlir::DialectRegistry ®istry) const override {
+registry.insert();
+  }
+  void runOnOperation() final;
+
+  StringRef getDescription() const override {
+return "Convert the prepared CIR dialect module to LLVM dialect";
+  }
+
+  StringRef getArgument() const override { return "cir-flat-to-llvm"; }

erichkeane wrote:

what does 'flat' mean here?  

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


  1   2   3   4   5   >