[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-08-16 Thread via cfe-commits

https://github.com/MichelleCDjunaidi updated 
https://github.com/llvm/llvm-project/pull/102299

>From 75306bd83eb43d0606630f9f059fc04ad1b20b06 Mon Sep 17 00:00:00 2001
From: Michelle C Djunaidi 
Date: Wed, 7 Aug 2024 13:10:02 +0800
Subject: [PATCH 01/12] [clang-tidy] Add
 bugprone-public-enable-shared-from-this check

This check identifies classes deriving from std::enable_shared_from_this that 
does not inherit with the public keyword,
which may cause problems when std::make_shared is called for that class.
---
 .../bugprone/BugproneTidyModule.cpp   |  3 +
 .../clang-tidy/bugprone/CMakeLists.txt|  1 +
 .../PublicEnableSharedFromThisCheck.cpp   | 45 +++
 .../PublicEnableSharedFromThisCheck.h | 33 +++
 clang-tools-extra/docs/ReleaseNotes.rst   |  5 ++
 .../bugprone/public-enable-shared-from-this   |  6 ++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../public-enable-shared-from-this.cpp| 56 +++
 8 files changed, 150 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/PublicEnableSharedFromThisCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/PublicEnableSharedFromThisCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/public-enable-shared-from-this
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/public-enable-shared-from-this.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 689eb92a3d8d17..f12f0cd1c47da3 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -53,6 +53,7 @@
 #include "ParentVirtualCallCheck.h"
 #include "PointerArithmeticOnPolymorphicObjectCheck.h"
 #include "PosixReturnCheck.h"
+#include "PublicEnableSharedFromThisCheck.h"
 #include "RedundantBranchConditionCheck.h"
 #include "ReservedIdentifierCheck.h"
 #include "ReturnConstRefFromParameterCheck.h"
@@ -139,6 +140,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-inaccurate-erase");
 CheckFactories.registerCheck(
 "bugprone-incorrect-enable-if");
+CheckFactories.registerCheck(
+"bugprone-public-enable-shared-from-this");
 CheckFactories.registerCheck(
 "bugprone-return-const-ref-from-parameter");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index cb0d8ae98bac58..c9bea094241edc 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -26,6 +26,7 @@ add_clang_library(clangTidyBugproneModule
   ImplicitWideningOfMultiplicationResultCheck.cpp
   InaccurateEraseCheck.cpp
   IncorrectEnableIfCheck.cpp
+  PublicEnableSharedFromThisCheck.cpp
   ReturnConstRefFromParameterCheck.cpp
   SuspiciousStringviewDataUsageCheck.cpp
   SwitchMissingDefaultCaseCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/bugprone/PublicEnableSharedFromThisCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/PublicEnableSharedFromThisCheck.cpp
new file mode 100644
index 00..dab3e0ac596fe7
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/PublicEnableSharedFromThisCheck.cpp
@@ -0,0 +1,45 @@
+//===--- PublicEnableSharedFromThisCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "PublicEnableSharedFromThisCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+  void PublicEnableSharedFromThisCheck::registerMatchers(MatchFinder 
*match_finder) {
+  match_finder->addMatcher(
+  cxxRecordDecl(
+  hasAnyBase(
+  cxxBaseSpecifier(unless(isPublic()), 
+  hasType(
+  cxxRecordDecl(
+  hasName("::std::enable_shared_from_this"
+  )
+  )
+  .bind("not-public-enable-shared"), this);
+  }
+
+  void PublicEnableSharedFromThisCheck::check(const MatchFinder::MatchResult 
&result) {
+  const auto *EnableSharedClassDecl =
+  result.Nodes.getNodeAs("not-public-enable-shared");
+
+  for (const auto &Base : EnableSharedClassDecl->bases()) {
+  const auto *BaseType = Base.getType()->getAsCXXRecordDecl();
+  if (BaseType && BaseType->getQualifiedNameAsString() == 
"std::enable_shared_from_this") {
+  SourceLocation InsertLoc = Base.getBeginLoc();
+  FixItHint Hint = F

[clang] [clang] Emit -Wdangling diagnoses for cases where a gsl-pointer is construct from a gsl-owner object in a container. (PR #104556)

2024-08-16 Thread Haojian Wu via cfe-commits

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

The warning is not emitted for the case `string_view c = 
std::vector({""}).at(0);` because we bail out during the visit of 
the LHS at [this 
point](https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/CheckExprLifetime.cpp#L341-L343)
 in the code.

This bailout was introduced in [this 
commit](https://github.com/llvm/llvm-project/commit/bcd0798c47ca865f95226859893016a17402441e)
 to address a false positive with `vector({""}).at(0);`. This 
PR refines that fix by ensuring that, for initialization involving a 
gsl-pointer, we only consider constructor calls that take the gsl-owner object.

Fixes #100384.

>From ff4d763596e1497e8ad0ede730aea517fefaf3ef Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Fri, 16 Aug 2024 08:25:14 +0200
Subject: [PATCH] [clang] Emit -Wdangling diagnoses for cases where a
 gsl-pointer is construct from a gsl-owner object in a container.

---
 clang/docs/ReleaseNotes.rst   |  2 +
 clang/lib/Sema/CheckExprLifetime.cpp  | 37 +--
 .../Sema/warn-lifetime-analysis-nocfg.cpp | 12 ++
 3 files changed, 24 insertions(+), 27 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ffdd063ec99037..c9864abc593e5e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -214,6 +214,8 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses the use of ``main`` in an ``extern`` context as invalid 
according to [basic.start.main] p3. Fixes #GH101512.
 
+- Clang now diagnoses dangling cases where a gsl-pointer is constructed from a 
gsl-owner object inside a container (#GH100384).
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Sema/CheckExprLifetime.cpp 
b/clang/lib/Sema/CheckExprLifetime.cpp
index 7389046eaddde1..b543c5e67f9550 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -191,7 +191,6 @@ struct IndirectLocalPathEntry {
 LifetimeBoundCall,
 TemporaryCopy,
 LambdaCaptureInit,
-GslReferenceInit,
 GslPointerInit,
 GslPointerAssignment,
   } Kind;
@@ -328,25 +327,13 @@ static bool shouldTrackFirstArgument(const FunctionDecl 
*FD) {
 
 static void handleGslAnnotatedTypes(IndirectLocalPath &Path, Expr *Call,
 LocalVisitor Visit) {
-  auto VisitPointerArg = [&](const Decl *D, Expr *Arg, bool Value) {
+  auto VisitPointerArg = [&](const Decl *D, Expr *Arg) {
 // We are not interested in the temporary base objects of gsl Pointers:
 //   Temp().ptr; // Here ptr might not dangle.
 if (isa(Arg->IgnoreImpCasts()))
   return;
-// Once we initialized a value with a reference, it can no longer dangle.
-if (!Value) {
-  for (const IndirectLocalPathEntry &PE : llvm::reverse(Path)) {
-if (PE.Kind == IndirectLocalPathEntry::GslReferenceInit)
-  continue;
-if (PE.Kind == IndirectLocalPathEntry::GslPointerInit ||
-PE.Kind == IndirectLocalPathEntry::GslPointerAssignment)
-  return;
-break;
-  }
-}
-Path.push_back({Value ? IndirectLocalPathEntry::GslPointerInit
-  : IndirectLocalPathEntry::GslReferenceInit,
-Arg, D});
+
+Path.push_back({IndirectLocalPathEntry::GslPointerInit, Arg, D});
 if (Arg->isGLValue())
   visitLocalsRetainedByReferenceBinding(Path, Arg, RK_ReferenceBinding,
 Visit,
@@ -360,29 +347,28 @@ static void handleGslAnnotatedTypes(IndirectLocalPath 
&Path, Expr *Call,
   if (auto *MCE = dyn_cast(Call)) {
 const auto *MD = cast_or_null(MCE->getDirectCallee());
 if (MD && shouldTrackImplicitObjectArg(MD))
-  VisitPointerArg(MD, MCE->getImplicitObjectArgument(),
-  !MD->getReturnType()->isReferenceType());
+  VisitPointerArg(MD, MCE->getImplicitObjectArgument());
 return;
   } else if (auto *OCE = dyn_cast(Call)) {
 FunctionDecl *Callee = OCE->getDirectCallee();
 if (Callee && Callee->isCXXInstanceMember() &&
 shouldTrackImplicitObjectArg(cast(Callee)))
-  VisitPointerArg(Callee, OCE->getArg(0),
-  !Callee->getReturnType()->isReferenceType());
+  VisitPointerArg(Callee, OCE->getArg(0));
 return;
   } else if (auto *CE = dyn_cast(Call)) {
 FunctionDecl *Callee = CE->getDirectCallee();
 if (Callee && shouldTrackFirstArgument(Callee))
-  VisitPointerArg(Callee, CE->getArg(0),
-  !Callee->getReturnType()->isReferenceType());
+  VisitPointerArg(Callee, CE->getArg(0));
 return;
   }
 
   if (auto *CCE = dyn_cast(Call)) {
 const auto *Ctor = CCE->getConstructor();
 const CXXRecordDecl *RD = Ctor->getParent();
-if (CCE->getNumArgs() > 0 && RD->hasAttr())
-  VisitPointerArg(Ctor->getParamDecl(0), CCE->getArgs()[0], true);
+

[clang] [clang] Emit -Wdangling diagnoses for cases where a gsl-pointer is construct from a gsl-owner object in a container. (PR #104556)

2024-08-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Haojian Wu (hokein)


Changes

The warning is not emitted for the case `string_view c = 
std::vector({""}).at(0);` because we bail out during the 
visit of the LHS at [this 
point](https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/CheckExprLifetime.cpp#L341-L343)
 in the code.

This bailout was introduced in [this 
commit](https://github.com/llvm/llvm-project/commit/bcd0798c47ca865f95226859893016a17402441e)
 to address a false positive with 
`vector({""}).at(0);`. This PR refines that fix by 
ensuring that, for initialization involving a gsl-pointer, we only consider 
constructor calls that take the gsl-owner object.

Fixes #100384.

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/Sema/CheckExprLifetime.cpp (+10-27) 
- (modified) clang/test/Sema/warn-lifetime-analysis-nocfg.cpp (+12) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ffdd063ec99037..c9864abc593e5e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -214,6 +214,8 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses the use of ``main`` in an ``extern`` context as invalid 
according to [basic.start.main] p3. Fixes #GH101512.
 
+- Clang now diagnoses dangling cases where a gsl-pointer is constructed from a 
gsl-owner object inside a container (#GH100384).
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Sema/CheckExprLifetime.cpp 
b/clang/lib/Sema/CheckExprLifetime.cpp
index 7389046eaddde1..b543c5e67f9550 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -191,7 +191,6 @@ struct IndirectLocalPathEntry {
 LifetimeBoundCall,
 TemporaryCopy,
 LambdaCaptureInit,
-GslReferenceInit,
 GslPointerInit,
 GslPointerAssignment,
   } Kind;
@@ -328,25 +327,13 @@ static bool shouldTrackFirstArgument(const FunctionDecl 
*FD) {
 
 static void handleGslAnnotatedTypes(IndirectLocalPath &Path, Expr *Call,
 LocalVisitor Visit) {
-  auto VisitPointerArg = [&](const Decl *D, Expr *Arg, bool Value) {
+  auto VisitPointerArg = [&](const Decl *D, Expr *Arg) {
 // We are not interested in the temporary base objects of gsl Pointers:
 //   Temp().ptr; // Here ptr might not dangle.
 if (isa(Arg->IgnoreImpCasts()))
   return;
-// Once we initialized a value with a reference, it can no longer dangle.
-if (!Value) {
-  for (const IndirectLocalPathEntry &PE : llvm::reverse(Path)) {
-if (PE.Kind == IndirectLocalPathEntry::GslReferenceInit)
-  continue;
-if (PE.Kind == IndirectLocalPathEntry::GslPointerInit ||
-PE.Kind == IndirectLocalPathEntry::GslPointerAssignment)
-  return;
-break;
-  }
-}
-Path.push_back({Value ? IndirectLocalPathEntry::GslPointerInit
-  : IndirectLocalPathEntry::GslReferenceInit,
-Arg, D});
+
+Path.push_back({IndirectLocalPathEntry::GslPointerInit, Arg, D});
 if (Arg->isGLValue())
   visitLocalsRetainedByReferenceBinding(Path, Arg, RK_ReferenceBinding,
 Visit,
@@ -360,29 +347,28 @@ static void handleGslAnnotatedTypes(IndirectLocalPath 
&Path, Expr *Call,
   if (auto *MCE = dyn_cast(Call)) {
 const auto *MD = cast_or_null(MCE->getDirectCallee());
 if (MD && shouldTrackImplicitObjectArg(MD))
-  VisitPointerArg(MD, MCE->getImplicitObjectArgument(),
-  !MD->getReturnType()->isReferenceType());
+  VisitPointerArg(MD, MCE->getImplicitObjectArgument());
 return;
   } else if (auto *OCE = dyn_cast(Call)) {
 FunctionDecl *Callee = OCE->getDirectCallee();
 if (Callee && Callee->isCXXInstanceMember() &&
 shouldTrackImplicitObjectArg(cast(Callee)))
-  VisitPointerArg(Callee, OCE->getArg(0),
-  !Callee->getReturnType()->isReferenceType());
+  VisitPointerArg(Callee, OCE->getArg(0));
 return;
   } else if (auto *CE = dyn_cast(Call)) {
 FunctionDecl *Callee = CE->getDirectCallee();
 if (Callee && shouldTrackFirstArgument(Callee))
-  VisitPointerArg(Callee, CE->getArg(0),
-  !Callee->getReturnType()->isReferenceType());
+  VisitPointerArg(Callee, CE->getArg(0));
 return;
   }
 
   if (auto *CCE = dyn_cast(Call)) {
 const auto *Ctor = CCE->getConstructor();
 const CXXRecordDecl *RD = Ctor->getParent();
-if (CCE->getNumArgs() > 0 && RD->hasAttr())
-  VisitPointerArg(Ctor->getParamDecl(0), CCE->getArgs()[0], true);
+if (CCE->getNumArgs() > 0 && RD->hasAttr() &&
+isRecordWithAttr(
+CCE->getArg(0)->IgnoreImpCasts()->getType()))
+  VisitPointerArg(Ctor->getParamDecl(0), CCE->getArgs

[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-08-16 Thread via cfe-commits


@@ -0,0 +1,120 @@
+//===--- IncorrectEnableSharedFromThisCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "IncorrectEnableSharedFromThisCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Basic/Specifiers.h"
+#include "llvm/ADT/SmallPtrSet.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void IncorrectEnableSharedFromThisCheck::registerMatchers(MatchFinder *Finder) 
{
+  Finder->addMatcher(translationUnitDecl(), this);
+}
+
+void IncorrectEnableSharedFromThisCheck::check(
+const MatchFinder::MatchResult &Result) {
+
+  class Visitor : public RecursiveASTVisitor {
+IncorrectEnableSharedFromThisCheck &Check;
+llvm::SmallPtrSet EnableSharedClassSet;
+
+  public:
+explicit Visitor(IncorrectEnableSharedFromThisCheck &Check)
+: Check(Check) {}
+
+bool VisitCXXRecordDecl(CXXRecordDecl *RDecl) {
+  for (const auto &Base : RDecl->bases()) {
+VisitCXXBaseSpecifier(Base, RDecl);
+  }
+  for (const auto &Base : RDecl->bases()) {
+const CXXRecordDecl *BaseType = Base.getType()->getAsCXXRecordDecl();
+if (BaseType && BaseType->getQualifiedNameAsString() ==
+"std::enable_shared_from_this") {
+  EnableSharedClassSet.insert(RDecl->getCanonicalDecl());
+  return true;
+}
+  }
+  return true;
+}
+
+bool VisitCXXBaseSpecifier(const CXXBaseSpecifier &Base,
+   CXXRecordDecl *RDecl) {
+  const CXXRecordDecl *BaseType = Base.getType()->getAsCXXRecordDecl();
+  const clang::AccessSpecifier AccessSpec = Base.getAccessSpecifier();
+
+  if (BaseType &&
+  BaseType->getQualifiedNameAsString() == "enable_shared_from_this") {
+if (AccessSpec == clang::AS_public) {
+  const SourceLocation InsertLocation = Base.getBaseTypeLoc();
+  const FixItHint Hint = FixItHint::CreateInsertion(InsertLocation, 
"std::");
+  Check.diag(RDecl->getLocation(),
+ "Should be std::enable_shared_from_this",
+ DiagnosticIDs::Warning)
+  << Hint;
+
+} else {
+  const SourceRange ReplacementRange = Base.getSourceRange();
+  const std::string ReplacementString =
+  "public std::" + Base.getType().getAsString();
+  const FixItHint Hint =
+  FixItHint::CreateReplacement(ReplacementRange, 
ReplacementString);
+  Check.diag(
+  RDecl->getLocation(),
+  "Should be std::enable_shared_from_this and "
+  "inheritance from std::enable_shared_from_this should be public "
+  "inheritance, otherwise the internal weak_ptr won't be "

MichelleCDjunaidi wrote:

changed to "this is not publicly inheriting from std::enable_shared_from_this, 
will cause unintended behaviour on shared_from_this. fix this by making it 
public inheritance".

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


[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-08-16 Thread via cfe-commits


@@ -0,0 +1,120 @@
+//===--- IncorrectEnableSharedFromThisCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "IncorrectEnableSharedFromThisCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Basic/Specifiers.h"
+#include "llvm/ADT/SmallPtrSet.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void IncorrectEnableSharedFromThisCheck::registerMatchers(MatchFinder *Finder) 
{
+  Finder->addMatcher(translationUnitDecl(), this);
+}
+
+void IncorrectEnableSharedFromThisCheck::check(
+const MatchFinder::MatchResult &Result) {
+
+  class Visitor : public RecursiveASTVisitor {
+IncorrectEnableSharedFromThisCheck &Check;
+llvm::SmallPtrSet EnableSharedClassSet;
+
+  public:
+explicit Visitor(IncorrectEnableSharedFromThisCheck &Check)
+: Check(Check) {}
+
+bool VisitCXXRecordDecl(CXXRecordDecl *RDecl) {
+  for (const auto &Base : RDecl->bases()) {
+VisitCXXBaseSpecifier(Base, RDecl);
+  }
+  for (const auto &Base : RDecl->bases()) {
+const CXXRecordDecl *BaseType = Base.getType()->getAsCXXRecordDecl();
+if (BaseType && BaseType->getQualifiedNameAsString() ==

MichelleCDjunaidi wrote:

updated.

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


[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-08-16 Thread via cfe-commits


@@ -0,0 +1,120 @@
+//===--- IncorrectEnableSharedFromThisCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "IncorrectEnableSharedFromThisCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Basic/Specifiers.h"
+#include "llvm/ADT/SmallPtrSet.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void IncorrectEnableSharedFromThisCheck::registerMatchers(MatchFinder *Finder) 
{
+  Finder->addMatcher(translationUnitDecl(), this);
+}
+
+void IncorrectEnableSharedFromThisCheck::check(
+const MatchFinder::MatchResult &Result) {
+
+  class Visitor : public RecursiveASTVisitor {
+IncorrectEnableSharedFromThisCheck &Check;
+llvm::SmallPtrSet EnableSharedClassSet;
+
+  public:
+explicit Visitor(IncorrectEnableSharedFromThisCheck &Check)
+: Check(Check) {}
+
+bool VisitCXXRecordDecl(CXXRecordDecl *RDecl) {
+  for (const auto &Base : RDecl->bases()) {
+VisitCXXBaseSpecifier(Base, RDecl);
+  }
+  for (const auto &Base : RDecl->bases()) {
+const CXXRecordDecl *BaseType = Base.getType()->getAsCXXRecordDecl();
+if (BaseType && BaseType->getQualifiedNameAsString() ==
+"std::enable_shared_from_this") {
+  EnableSharedClassSet.insert(RDecl->getCanonicalDecl());
+  return true;
+}
+  }
+  return true;
+}
+
+bool VisitCXXBaseSpecifier(const CXXBaseSpecifier &Base,
+   CXXRecordDecl *RDecl) {
+  const CXXRecordDecl *BaseType = Base.getType()->getAsCXXRecordDecl();
+  const clang::AccessSpecifier AccessSpec = Base.getAccessSpecifier();
+
+  if (BaseType &&
+  BaseType->getQualifiedNameAsString() == "enable_shared_from_this") {

MichelleCDjunaidi wrote:

this part was removed in accordance to 
https://github.com/llvm/llvm-project/pull/102299#discussion_r1719046306

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


[clang] [clang][driver] Fix -print-target-triple OS version for apple targets (PR #104037)

2024-08-16 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

This broke things for non-darwin targets.

`clang --print-target-triple` is used to evaluate the arch to use for e.g. 
compiler-rt builtins, and for getting the right subdirectory for per-target 
runtime directories.

Previously, `clang -target armv7-windows-gnu --print-target-triple` used to 
output `armv7-unknown-windows-gnu`, while it now outputs 
`thumbv7-unknown-windows-gnu`. (The `--print-effective-triple` option has 
printed `thumbv7-unknown-windows-gnu` consistently all the time though.) Making 
`--print-target-triple` print a `thumbv7` triple makes compiler-rt not build 
any builtins/runtimes for that, since that arch name is unrecognized there. (I 
also remember looking into making compiler-rt support `thumbv7` as architecture 
name, when some normalization attempted to use `--print-effective-triple` at 
some point, but iirc it wasn't a clear cut thing to do.)

Additionally, having `--print-target-triple` output 
`thumbv7-unknown-windows-gnu` is wrong when the driver in fact will look for 
per-target runtimes in a subdirectory named `armv7-unknown-windows-gnu` (this 
is what the driver printed as path when it failed to find runtimes after this 
change).

Darwin targets don't use the per-target runtime directory, but if they would 
do, I doubt that having the OS version appended on those directories would be 
the right thing to do...

---

Thus, I request we revert this (and will push a revert later today unless we 
agree on something else) - this breaks things way outside of what was intended 
in the change itself.

(I don't have a strong opinion on whether the initialization should be kept 
only for darwin targets, or if a different option than `--print-target-triple` 
should be used for conveying such things. In one sense, 
`--print-effective-triple` maybe would be more appropriate? For the arm vs 
thumb case, that does print the actual `thumbv7` arch already, but for the 
darwin targets, it doesn't include the OS version right now.)

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


[clang] Add "clang-format-on-save-mode" minor mode to clang-format.el (PR #104533)

2024-08-16 Thread via cfe-commits

mydeveloperday wrote:

I'm not an emacs user and I'm unsure if the other maintainers are. If you are 
happy to address any issues that might arise I'd be happy for this to land.

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


[clang] Add "clang-format-on-save-mode" minor mode to clang-format.el (PR #104533)

2024-08-16 Thread via cfe-commits

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


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


[clang] [clang-format] Adjust requires clause wrapping (#101550) (PR #102078)

2024-08-16 Thread via cfe-commits

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


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


[clang] [clang] Implement gcc_struct attribute on Itanium targets (PR #71148)

2024-08-16 Thread Martin Storsjö via cfe-commits

https://github.com/mstorsjo commented:

I had a brief look over this, and it looks reasonable to me, although I'm not 
anywhere near competent enough to properly review it from the Clang perspective 
and approve it.

I don't see any added test that actually exercises the new `gcc_struct` 
attribute anywhere though - I'd like to see that, in a test that runs with 
`-mms-bitfields` or similar, and shows what effect the attribute has in that 
context.

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


[clang] [clang][ASTImporter] New fix for default template parameter values. (PR #101836)

2024-08-16 Thread Balázs Kéri via cfe-commits

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

From 2e98fc222566c5e746ade4ccaba23de3b59e0a5d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Sat, 3 Aug 2024 18:10:34 +0200
Subject: [PATCH 1/2] [clang][ASTImporter] New fix for default template
 parameter values.

Commit e4440b8 added a change that introduced new crash in an
incorrectly handled case. This is fixed here.
---
 clang/lib/AST/ASTImporter.cpp   | 12 ++-
 clang/unittests/AST/ASTImporterTest.cpp | 97 +
 2 files changed, 106 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 103235547f482e..7e4a92ccbe40f7 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -5972,7 +5972,11 @@ 
ASTNodeImporter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
 import(D->getDefaultArgument());
 if (!ToDefaultArgOrErr)
   return ToDefaultArgOrErr.takeError();
-ToD->setDefaultArgument(ToD->getASTContext(), *ToDefaultArgOrErr);
+// The import process can trigger import of the parent template which can
+// set the default argument value (to "inherited").
+// In this case do nothing here.
+if (!ToD->hasDefaultArgument())
+  ToD->setDefaultArgument(ToD->getASTContext(), *ToDefaultArgOrErr);
   }
 
   return ToD;
@@ -6004,7 +6008,8 @@ 
ASTNodeImporter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
 import(D->getDefaultArgument());
 if (!ToDefaultArgOrErr)
   return ToDefaultArgOrErr.takeError();
-ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr);
+if (!ToD->hasDefaultArgument())
+  ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr);
   }
 
   return ToD;
@@ -6041,7 +6046,8 @@ 
ASTNodeImporter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
 import(D->getDefaultArgument());
 if (!ToDefaultArgOrErr)
   return ToDefaultArgOrErr.takeError();
-ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr);
+if (!ToD->hasDefaultArgument())
+  ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr);
   }
 
   return ToD;
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 57242ff49fe3b8..4c41171deec46a 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -9919,6 +9919,103 @@ TEST_P(ImportTemplateParmDeclDefaultValue, 
ImportExistingVarTemplate) {
   testImport(FromLastD);
 }
 
+TEST_P(ImportTemplateParmDeclDefaultValue,
+   ImportParentTemplateDuringNonTypeTemplateParmDecl) {
+  // This wants to provoke that during import of 'Y' in "typename T = Y"
+  // (before this import returns) the later definition of 'X' is imported 
fully.
+  const char *Code =
+  R"(
+  struct Z;
+
+  struct Y {
+Z *z;
+static const int x = 1;
+  };
+
+  template 
+  struct X;
+
+  template 
+  struct X {
+static const int A = 1;
+  };
+
+  struct Z {
+template
+void f(int A = X::A);
+  };
+  )";
+
+  Decl *FromTU = getTuDecl(Code, Lang_CXX14);
+  auto *FromD = FirstDeclMatcher().match(
+  FromTU, nonTypeTemplateParmDecl(hasName("P")));
+  auto *ToD = Import(FromD, Lang_CXX14);
+  EXPECT_TRUE(ToD);
+}
+
+TEST_P(ImportTemplateParmDeclDefaultValue,
+   ImportParentTemplateDuringTemplateTypeParmDecl) {
+  const char *Code =
+  R"(
+  struct Z;
+
+  struct Y {
+Z *z;
+  };
+
+  template 
+  struct X;
+
+  template 
+  struct X {
+static const int A = 1;
+  };
+
+  struct Z {
+template
+void f(int A = X::A);
+  };
+  )";
+
+  Decl *FromTU = getTuDecl(Code, Lang_CXX14);
+  auto *FromD = FirstDeclMatcher().match(
+  FromTU, templateTypeParmDecl(hasName("T")));
+  auto *ToD = Import(FromD, Lang_CXX14);
+  EXPECT_TRUE(ToD);
+}
+
+TEST_P(ImportTemplateParmDeclDefaultValue,
+   ImportParentTemplateDuringTemplateTemplateParmDecl) {
+  const char *Code =
+  R"(
+  struct Z;
+
+  template 
+  struct Y {
+Z *z;
+  };
+
+  template  class T = Y>
+  struct X;
+
+  template  class T>
+  struct X {
+static const int A = 1;
+  };
+
+  struct Z {
+template  class T>
+void f(int A = X::A);
+  };
+  )";
+
+  Decl *FromTU = getTuDecl(Code, Lang_CXX14);
+  auto *FromD = FirstDeclMatcher().match(
+  FromTU, templateTemplateParmDecl(hasName("T")));
+  auto *ToD = Import(FromD, Lang_CXX14);
+  EXPECT_TRUE(ToD);
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 

From 70ef4f2579bbb91f7babdf62feef0e5c9173fa31 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Fri, 16 Aug 2024 09:58:49 +0200
Su

[clang] [analyzer] Model overflow builtins (PR #102602)

2024-08-16 Thread Pavel Skripkin via cfe-commits

pskrgag wrote:

Could you, please, check the lattest vestion, if you have time? 

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


[clang] clang/AMDGPU: Emit atomicrmw from {global|flat}_atomic_fadd_v2f16 builtins (PR #96873)

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

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/96873

>From 5d0d09c00b837186a4d40a38c474f32461bac034 Mon Sep 17 00:00:00 2001
From: Matt Arsenault 
Date: Wed, 26 Jun 2024 19:12:59 +0200
Subject: [PATCH] clang/AMDGPU: Emit atomicrmw from
 {global|flat}_atomic_fadd_v2f16 builtins

---
 clang/lib/CodeGen/CGBuiltin.cpp   | 20 ++-
 .../builtins-fp-atomics-gfx12.cl  |  9 ++---
 .../builtins-fp-atomics-gfx90a.cl |  2 +-
 .../builtins-fp-atomics-gfx940.cl |  3 ++-
 4 files changed, 15 insertions(+), 19 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f424ddaa175400..77c652573cae42 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18920,22 +18920,15 @@ Value 
*CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
 Function *F = CGM.getIntrinsic(Intrin, { Src0->getType() });
 return Builder.CreateCall(F, { Src0, Builder.getFalse() });
   }
-  case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_v2f16:
   case AMDGPU::BI__builtin_amdgcn_global_atomic_fmin_f64:
   case AMDGPU::BI__builtin_amdgcn_global_atomic_fmax_f64:
   case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_f64:
   case AMDGPU::BI__builtin_amdgcn_flat_atomic_fmin_f64:
   case AMDGPU::BI__builtin_amdgcn_flat_atomic_fmax_f64:
-  case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_f32:
-  case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_v2f16: {
+  case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_f32: {
 Intrinsic::ID IID;
 llvm::Type *ArgTy = llvm::Type::getDoubleTy(getLLVMContext());
 switch (BuiltinID) {
-case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_v2f16:
-  ArgTy = llvm::FixedVectorType::get(
-  llvm::Type::getHalfTy(getLLVMContext()), 2);
-  IID = Intrinsic::amdgcn_global_atomic_fadd;
-  break;
 case AMDGPU::BI__builtin_amdgcn_global_atomic_fmin_f64:
   IID = Intrinsic::amdgcn_global_atomic_fmin;
   break;
@@ -18955,11 +18948,6 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
   ArgTy = llvm::Type::getFloatTy(getLLVMContext());
   IID = Intrinsic::amdgcn_flat_atomic_fadd;
   break;
-case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_v2f16:
-  ArgTy = llvm::FixedVectorType::get(
-  llvm::Type::getHalfTy(getLLVMContext()), 2);
-  IID = Intrinsic::amdgcn_flat_atomic_fadd;
-  break;
 }
 llvm::Value *Addr = EmitScalarExpr(E->getArg(0));
 llvm::Value *Val = EmitScalarExpr(E->getArg(1));
@@ -19360,7 +19348,9 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
   case AMDGPU::BI__builtin_amdgcn_ds_fminf:
   case AMDGPU::BI__builtin_amdgcn_ds_fmaxf:
   case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_f32:
-  case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_f64: {
+  case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_f64:
+  case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_v2f16:
+  case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_v2f16: {
 llvm::AtomicRMWInst::BinOp BinOp;
 switch (BuiltinID) {
 case AMDGPU::BI__builtin_amdgcn_atomic_inc32:
@@ -19378,6 +19368,8 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_v2bf16:
 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_f32:
 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_f64:
+case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_v2f16:
+case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_v2f16:
   BinOp = llvm::AtomicRMWInst::FAdd;
   break;
 case AMDGPU::BI__builtin_amdgcn_ds_fminf:
diff --git a/clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx12.cl 
b/clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx12.cl
index 6b8a6d14575db8..df88c707a19882 100644
--- a/clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx12.cl
+++ b/clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx12.cl
@@ -48,7 +48,8 @@ void test_local_add_2f16_noret(__local half2 *addr, half2 x) {
 }
 
 // CHECK-LABEL: test_flat_add_2f16
-// CHECK: call <2 x half> @llvm.amdgcn.flat.atomic.fadd.v2f16.p0.v2f16(ptr 
%{{.*}}, <2 x half> %{{.*}})
+// CHECK: [[RMW:%.+]] = atomicrmw fadd ptr %{{.+}}, <2 x half> %{{.+}} 
syncscope("agent") monotonic, align 4, !amdgpu.no.fine.grained.memory 
!{{[0-9]+$}}
+
 // GFX12-LABEL:  test_flat_add_2f16
 // GFX12: flat_atomic_pk_add_f16
 half2 test_flat_add_2f16(__generic half2 *addr, half2 x) {
@@ -64,7 +65,8 @@ short2 test_flat_add_2bf16(__generic short2 *addr, short2 x) {
 }
 
 // CHECK-LABEL: test_global_add_half2
-// CHECK: call <2 x half> @llvm.amdgcn.global.atomic.fadd.v2f16.p1.v2f16(ptr 
addrspace(1) %{{.*}}, <2 x half> %{{.*}})
+// CHECK: [[RMW:%.+]] = atomicrmw fadd ptr addrspace(1) %{{.+}}, <2 x half> 
%{{.+}} syncscope("agent") monotonic, align 4, !amdgpu.no.fine.grained.memory 
!{{[0-9]+$}}
+
 // GFX12-LABEL:  test_global_add_half2
 // GFX12:  global_atomic_pk_add_f16 v2, v[0:1]

[clang] clang/AMDGPU: Emit atomicrmw from {global|flat}_atomic_fadd_v2f16 builtins (PR #96873)

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

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


[clang] clang/AMDGPU: Emit atomicrmw from {global|flat}_atomic_fadd_v2f16 builtins (PR #96873)

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

https://github.com/arsenm commented:

ping

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


[clang] [llvm] [BPF] introduce `__attribute__((bpf_fastcall))` (PR #101228)

2024-08-16 Thread via cfe-commits

https://github.com/eddyz87 updated 
https://github.com/llvm/llvm-project/pull/101228

>From 6a3b5c79d148863f39b84ce3da4e4794829c1c56 Mon Sep 17 00:00:00 2001
From: Eduard Zingerman 
Date: Wed, 8 May 2024 15:29:47 -0700
Subject: [PATCH 1/6] [BPF] introduce __attribute__((bpf_fastcall))

This commit introduces attribute bpf_fastcall to declare BPF functions
that do not clobber some of the caller saved registers (R0-R5).

The idea is to generate the code complying with generic BPF ABI,
but allow compatible Linux Kernel to remove unnecessary spills and
fills of non-scratched registers (given some compiler assistance).

For such functions do register allocation as-if caller saved registers
are not clobbered, but later wrap the calls with spill and fill
patterns that are simple to recognize in kernel.

For example for the following C code:

   #define __bpf_fastcall __attribute__((bpf_fastcall))

   void bar(void) __bpf_fastcall;
   void buz(long i, long j, long k);

   void foo(long i, long j, long k) {
 bar();
 buz(i, j, k);
   }

First allocate registers as if:

   foo:
 call bar# note: no spills for i,j,k (r1,r2,r3)
 call buz
 exit

And later insert spills fills on the peephole phase:

   foo:
 *(u64 *)(r10 - 8) = r1;  # Such call pattern is
 *(u64 *)(r10 - 16) = r2; # correct when used with
 *(u64 *)(r10 - 24) = r3; # old kernels.
 call bar
 r3 = *(u64 *)(r10 - 24); # But also allows new
 r2 = *(u64 *)(r10 - 16); # kernels to recognize the
 r1 = *(u64 *)(r10 - 8);  # pattern and remove spills/fills.
 call buz
 exit

The offsets for generated spills/fills are picked as minimal stack
offsets for the function. Allocated stack slots are not used for any
other purposes, in order to simplify in-kernel analysis.
---
 clang/include/clang/Basic/Attr.td |   8 ++
 clang/include/clang/Basic/AttrDocs.td |  19 +++
 clang/lib/CodeGen/CGCall.cpp  |   2 +
 clang/test/CodeGen/bpf-attr-bpf-fastcall-1.c  |  24 
 ...a-attribute-supported-attributes-list.test |   1 +
 clang/test/Sema/bpf-attr-bpf-fastcall.c   |   7 ++
 llvm/lib/Target/BPF/BPFCallingConv.td |   1 +
 llvm/lib/Target/BPF/BPFISelLowering.cpp   |  31 +
 llvm/lib/Target/BPF/BPFInstrInfo.td   |   4 +-
 llvm/lib/Target/BPF/BPFMIPeephole.cpp |  88 ++
 llvm/lib/Target/BPF/BPFRegisterInfo.cpp   |  11 ++
 llvm/lib/Target/BPF/BPFRegisterInfo.h |   3 +
 llvm/test/CodeGen/BPF/bpf-fastcall-1.ll   |  46 
 llvm/test/CodeGen/BPF/bpf-fastcall-2.ll   |  68 +++
 llvm/test/CodeGen/BPF/bpf-fastcall-3.ll   |  62 ++
 .../CodeGen/BPF/bpf-fastcall-regmask-1.ll | 110 ++
 16 files changed, 482 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGen/bpf-attr-bpf-fastcall-1.c
 create mode 100644 clang/test/Sema/bpf-attr-bpf-fastcall.c
 create mode 100644 llvm/test/CodeGen/BPF/bpf-fastcall-1.ll
 create mode 100644 llvm/test/CodeGen/BPF/bpf-fastcall-2.ll
 create mode 100644 llvm/test/CodeGen/BPF/bpf-fastcall-3.ll
 create mode 100644 llvm/test/CodeGen/BPF/bpf-fastcall-regmask-1.ll

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 46d0a66d59c375..437cf3999bc365 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2189,6 +2189,14 @@ def BTFTypeTag : TypeAttr {
   let LangOpts = [COnly];
 }
 
+def BPFFastCall : InheritableAttr,
+  TargetSpecificAttr {
+  let Spellings = [GCC<"bpf_fastcall">];
+  let Subjects = SubjectList<[FunctionLike]>;
+  let Documentation = [BPFFastCallDocs];
+  let SimpleHandler = 1;
+}
+
 def WebAssemblyExportName : InheritableAttr,
 TargetSpecificAttr {
   let Spellings = [Clang<"export_name">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 4b8d520d73893d..6f0f659f064d95 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -2317,6 +2317,25 @@ section.
   }];
 }
 
+def BPFFastCallDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+Functions annotated with this attribute are likely to be inlined by BPF JIT.
+It is assumed that inlined implementation uses less caller saved registers,
+than a regular function.
+Specifically, the following registers are likely to be preserved:
+- ``R0`` if function return value is ``void``;
+- ``R2-R5` if function takes 1 argument;
+- ``R3-R5` if function takes 2 arguments;
+- ``R4-R5` if function takes 3 arguments;
+- ``R5`` if function takes 4 arguments;
+
+For such functions Clang generates code pattern that allows BPF JIT
+to recognize and remove unnecessary spills and fills of the preserved
+registers.
+  }];
+}
+
 def MipsInterruptDocs : Documentation {
   let Category = DocCatFunction;
   let Heading = "interrupt (MIPS)";
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/Co

[clang] [llvm] [BPF] introduce `__attribute__((bpf_fastcall))` (PR #101228)

2024-08-16 Thread via cfe-commits


@@ -2189,6 +2189,14 @@ def BTFTypeTag : TypeAttr {
   let LangOpts = [COnly];
 }
 
+def BPFFastCall : InheritableAttr,
+  TargetSpecificAttr {
+  let Spellings = [Clang<"bpf_fastcall">];
+  let Subjects = SubjectList<[FunctionLike]>;
+  let Documentation = [BPFFastCallDocs];
+  let SimpleHandler = 1;
+}

eddyz87 wrote:

done

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


[clang] [clang] Emit -Wdangling diagnoses for cases where a gsl-pointer is construct from a gsl-owner object in a container. (PR #104556)

2024-08-16 Thread Haojian Wu via cfe-commits

hokein wrote:

Testing it a bit more, unfortunately, it has a false positive on the following 
case:

```
const char* kk() {
std::optional k;
return k.value().data(); // dangling warning, but we should not diagnose it.
}
```

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


[clang] [clang][driver] Fix -print-target-triple OS version for apple targets (PR #104037)

2024-08-16 Thread Gábor Horváth via cfe-commits

Xazax-hun wrote:

Hey, thanks for letting me know. Feel free to revert this for now! 

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


[clang] Revert "[clang][driver] Fix -print-target-triple OS version for apple targets" (PR #104563)

2024-08-16 Thread Martin Storsjö via cfe-commits

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

This reverts llvm/llvm-project#104037 / 
7227b44f928a87b5d7fb05bd1539fdfb6d4958dc.

This change had the unintended consequence of making e.g. `clang -target 
armv7-windows-gnu --print-target-triple` output `thumbv7-unknown-windows-gnu` 
rather than `armv7-unknown-windows-gnu`.

From d39fff2a6c7c77d6046a075e6119a4126d955b1a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= 
Date: Fri, 16 Aug 2024 11:34:18 +0300
Subject: [PATCH] =?UTF-8?q?Revert=20"[clang][driver]=20Fix=20-print-target?=
 =?UTF-8?q?-triple=20OS=20version=20for=20apple=20targets=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit 7227b44f928a87b5d7fb05bd1539fdfb6d4958dc.
---
 clang/lib/Driver/Driver.cpp   | 13 ++
 .../test/Driver/darwin-print-target-triple.c  | 42 ---
 2 files changed, 3 insertions(+), 52 deletions(-)
 delete mode 100644 clang/test/Driver/darwin-print-target-triple.c

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 5b95019c25cab6..e12416e51f8d24 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2271,7 +2271,8 @@ bool Driver::HandleImmediateArgs(Compilation &C) {
 return false;
   }
 
-  auto initializeTargets = [&]() {
+  if (C.getArgs().hasArg(options::OPT_print_libgcc_file_name)) {
+ToolChain::RuntimeLibType RLT = TC.GetRuntimeLibType(C.getArgs());
 const llvm::Triple Triple(TC.ComputeEffectiveClangTriple(C.getArgs()));
 // The 'Darwin' toolchain is initialized only when its arguments are
 // computed. Get the default arguments for OFK_None to ensure that
@@ -2281,12 +2282,6 @@ bool Driver::HandleImmediateArgs(Compilation &C) {
 // FIXME: For some more esoteric targets the default toolchain is not the
 //correct one.
 C.getArgsForToolChain(&TC, Triple.getArchName(), Action::OFK_None);
-return Triple;
-  };
-
-  if (C.getArgs().hasArg(options::OPT_print_libgcc_file_name)) {
-ToolChain::RuntimeLibType RLT = TC.GetRuntimeLibType(C.getArgs());
-const llvm::Triple Triple = initializeTargets();
 RegisterEffectiveTriple TripleRAII(TC, Triple);
 switch (RLT) {
 case ToolChain::RLT_CompilerRT:
@@ -2330,9 +2325,7 @@ bool Driver::HandleImmediateArgs(Compilation &C) {
   }
 
   if (C.getArgs().hasArg(options::OPT_print_target_triple)) {
-initializeTargets();
-llvm::Triple Triple(TC.ComputeEffectiveClangTriple(C.getArgs()));
-llvm::outs() << Triple.getTriple() << "\n";
+llvm::outs() << TC.getTripleString() << "\n";
 return false;
   }
 
diff --git a/clang/test/Driver/darwin-print-target-triple.c 
b/clang/test/Driver/darwin-print-target-triple.c
deleted file mode 100644
index 4f5fdfe9d0db34..00
--- a/clang/test/Driver/darwin-print-target-triple.c
+++ /dev/null
@@ -1,42 +0,0 @@
-// Test the output of -print-target-triple on Darwin.
-// See https://github.com/llvm/llvm-project/issues/61762
-
-//
-// All platforms
-//
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=x86_64-apple-macos -mmacos-version-min=15 \
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-MACOS %s
-// CHECK-CLANGRT-MACOS: x86_64-apple-macosx15.0.0
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=arm64-apple-ios -mios-version-min=9 \
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-IOS %s
-// CHECK-CLANGRT-IOS: arm64-apple-ios9.0.0
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=arm64-apple-watchos -mwatchos-version-min=3 \
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-WATCHOS %s
-// CHECK-CLANGRT-WATCHOS: arm64-apple-watchos3.0.0
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=armv7k-apple-watchos -mwatchos-version-min=3 \
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-WATCHOS-ARMV7K %s
-// CHECK-CLANGRT-WATCHOS-ARMV7K: thumbv7-apple-watchos3.0.0
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=arm64-apple-tvos -mtvos-version-min=1\
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-TVOS %s
-// CHECK-CLANGRT-TVOS: arm64-apple-tvos1.0.0
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=arm64-apple-driverkit \
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-DRIVERKIT %s
-// CHECK-CLANGRT-DRIVERKIT: arm64-apple-driverkit19.0.0

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


[clang] Revert "[clang][driver] Fix -print-target-triple OS version for apple targets" (PR #104563)

2024-08-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Martin Storsjö (mstorsjo)


Changes

This reverts llvm/llvm-project#104037 / 
7227b44f928a87b5d7fb05bd1539fdfb6d4958dc.

This change had the unintended consequence of making e.g. `clang -target 
armv7-windows-gnu --print-target-triple` output `thumbv7-unknown-windows-gnu` 
rather than `armv7-unknown-windows-gnu`.

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


2 Files Affected:

- (modified) clang/lib/Driver/Driver.cpp (+3-10) 
- (removed) clang/test/Driver/darwin-print-target-triple.c (-42) 


``diff
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 5b95019c25cab6..e12416e51f8d24 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2271,7 +2271,8 @@ bool Driver::HandleImmediateArgs(Compilation &C) {
 return false;
   }
 
-  auto initializeTargets = [&]() {
+  if (C.getArgs().hasArg(options::OPT_print_libgcc_file_name)) {
+ToolChain::RuntimeLibType RLT = TC.GetRuntimeLibType(C.getArgs());
 const llvm::Triple Triple(TC.ComputeEffectiveClangTriple(C.getArgs()));
 // The 'Darwin' toolchain is initialized only when its arguments are
 // computed. Get the default arguments for OFK_None to ensure that
@@ -2281,12 +2282,6 @@ bool Driver::HandleImmediateArgs(Compilation &C) {
 // FIXME: For some more esoteric targets the default toolchain is not the
 //correct one.
 C.getArgsForToolChain(&TC, Triple.getArchName(), Action::OFK_None);
-return Triple;
-  };
-
-  if (C.getArgs().hasArg(options::OPT_print_libgcc_file_name)) {
-ToolChain::RuntimeLibType RLT = TC.GetRuntimeLibType(C.getArgs());
-const llvm::Triple Triple = initializeTargets();
 RegisterEffectiveTriple TripleRAII(TC, Triple);
 switch (RLT) {
 case ToolChain::RLT_CompilerRT:
@@ -2330,9 +2325,7 @@ bool Driver::HandleImmediateArgs(Compilation &C) {
   }
 
   if (C.getArgs().hasArg(options::OPT_print_target_triple)) {
-initializeTargets();
-llvm::Triple Triple(TC.ComputeEffectiveClangTriple(C.getArgs()));
-llvm::outs() << Triple.getTriple() << "\n";
+llvm::outs() << TC.getTripleString() << "\n";
 return false;
   }
 
diff --git a/clang/test/Driver/darwin-print-target-triple.c 
b/clang/test/Driver/darwin-print-target-triple.c
deleted file mode 100644
index 4f5fdfe9d0db34..00
--- a/clang/test/Driver/darwin-print-target-triple.c
+++ /dev/null
@@ -1,42 +0,0 @@
-// Test the output of -print-target-triple on Darwin.
-// See https://github.com/llvm/llvm-project/issues/61762
-
-//
-// All platforms
-//
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=x86_64-apple-macos -mmacos-version-min=15 \
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-MACOS %s
-// CHECK-CLANGRT-MACOS: x86_64-apple-macosx15.0.0
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=arm64-apple-ios -mios-version-min=9 \
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-IOS %s
-// CHECK-CLANGRT-IOS: arm64-apple-ios9.0.0
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=arm64-apple-watchos -mwatchos-version-min=3 \
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-WATCHOS %s
-// CHECK-CLANGRT-WATCHOS: arm64-apple-watchos3.0.0
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=armv7k-apple-watchos -mwatchos-version-min=3 \
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-WATCHOS-ARMV7K %s
-// CHECK-CLANGRT-WATCHOS-ARMV7K: thumbv7-apple-watchos3.0.0
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=arm64-apple-tvos -mtvos-version-min=1\
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-TVOS %s
-// CHECK-CLANGRT-TVOS: arm64-apple-tvos1.0.0
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=arm64-apple-driverkit \
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-DRIVERKIT %s
-// CHECK-CLANGRT-DRIVERKIT: arm64-apple-driverkit19.0.0

``




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


[clang] Revert "[clang][driver] Fix -print-target-triple OS version for apple targets" (PR #104563)

2024-08-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Martin Storsjö (mstorsjo)


Changes

This reverts llvm/llvm-project#104037 / 
7227b44f928a87b5d7fb05bd1539fdfb6d4958dc.

This change had the unintended consequence of making e.g. `clang -target 
armv7-windows-gnu --print-target-triple` output `thumbv7-unknown-windows-gnu` 
rather than `armv7-unknown-windows-gnu`.

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


2 Files Affected:

- (modified) clang/lib/Driver/Driver.cpp (+3-10) 
- (removed) clang/test/Driver/darwin-print-target-triple.c (-42) 


``diff
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 5b95019c25cab6..e12416e51f8d24 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2271,7 +2271,8 @@ bool Driver::HandleImmediateArgs(Compilation &C) {
 return false;
   }
 
-  auto initializeTargets = [&]() {
+  if (C.getArgs().hasArg(options::OPT_print_libgcc_file_name)) {
+ToolChain::RuntimeLibType RLT = TC.GetRuntimeLibType(C.getArgs());
 const llvm::Triple Triple(TC.ComputeEffectiveClangTriple(C.getArgs()));
 // The 'Darwin' toolchain is initialized only when its arguments are
 // computed. Get the default arguments for OFK_None to ensure that
@@ -2281,12 +2282,6 @@ bool Driver::HandleImmediateArgs(Compilation &C) {
 // FIXME: For some more esoteric targets the default toolchain is not the
 //correct one.
 C.getArgsForToolChain(&TC, Triple.getArchName(), Action::OFK_None);
-return Triple;
-  };
-
-  if (C.getArgs().hasArg(options::OPT_print_libgcc_file_name)) {
-ToolChain::RuntimeLibType RLT = TC.GetRuntimeLibType(C.getArgs());
-const llvm::Triple Triple = initializeTargets();
 RegisterEffectiveTriple TripleRAII(TC, Triple);
 switch (RLT) {
 case ToolChain::RLT_CompilerRT:
@@ -2330,9 +2325,7 @@ bool Driver::HandleImmediateArgs(Compilation &C) {
   }
 
   if (C.getArgs().hasArg(options::OPT_print_target_triple)) {
-initializeTargets();
-llvm::Triple Triple(TC.ComputeEffectiveClangTriple(C.getArgs()));
-llvm::outs() << Triple.getTriple() << "\n";
+llvm::outs() << TC.getTripleString() << "\n";
 return false;
   }
 
diff --git a/clang/test/Driver/darwin-print-target-triple.c 
b/clang/test/Driver/darwin-print-target-triple.c
deleted file mode 100644
index 4f5fdfe9d0db34..00
--- a/clang/test/Driver/darwin-print-target-triple.c
+++ /dev/null
@@ -1,42 +0,0 @@
-// Test the output of -print-target-triple on Darwin.
-// See https://github.com/llvm/llvm-project/issues/61762
-
-//
-// All platforms
-//
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=x86_64-apple-macos -mmacos-version-min=15 \
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-MACOS %s
-// CHECK-CLANGRT-MACOS: x86_64-apple-macosx15.0.0
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=arm64-apple-ios -mios-version-min=9 \
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-IOS %s
-// CHECK-CLANGRT-IOS: arm64-apple-ios9.0.0
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=arm64-apple-watchos -mwatchos-version-min=3 \
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-WATCHOS %s
-// CHECK-CLANGRT-WATCHOS: arm64-apple-watchos3.0.0
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=armv7k-apple-watchos -mwatchos-version-min=3 \
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-WATCHOS-ARMV7K %s
-// CHECK-CLANGRT-WATCHOS-ARMV7K: thumbv7-apple-watchos3.0.0
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=arm64-apple-tvos -mtvos-version-min=1\
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-TVOS %s
-// CHECK-CLANGRT-TVOS: arm64-apple-tvos1.0.0
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=arm64-apple-driverkit \
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-DRIVERKIT %s
-// CHECK-CLANGRT-DRIVERKIT: arm64-apple-driverkit19.0.0

``




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


[clang] Revert "[clang][driver] Fix -print-target-triple OS version for apple targets" (PR #104563)

2024-08-16 Thread Gábor Horváth via cfe-commits

https://github.com/Xazax-hun approved this pull request.

LGTM!

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


[clang] 8ca5ff2 - Revert "[clang][driver] Fix -print-target-triple OS version for apple targets" (#104563)

2024-08-16 Thread via cfe-commits

Author: Martin Storsjö
Date: 2024-08-16T11:38:22+03:00
New Revision: 8ca5ff2743f6020e29ee923114e2762b53bd32b1

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

LOG: Revert "[clang][driver] Fix -print-target-triple OS version for apple 
targets" (#104563)

This reverts llvm/llvm-project#104037 /
7227b44f928a87b5d7fb05bd1539fdfb6d4958dc.

This change had the unintended consequence of making e.g. `clang -target
armv7-windows-gnu --print-target-triple` output
`thumbv7-unknown-windows-gnu` rather than `armv7-unknown-windows-gnu`.

Added: 


Modified: 
clang/lib/Driver/Driver.cpp

Removed: 
clang/test/Driver/darwin-print-target-triple.c



diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 5b95019c25cab..e12416e51f8d2 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2271,7 +2271,8 @@ bool Driver::HandleImmediateArgs(Compilation &C) {
 return false;
   }
 
-  auto initializeTargets = [&]() {
+  if (C.getArgs().hasArg(options::OPT_print_libgcc_file_name)) {
+ToolChain::RuntimeLibType RLT = TC.GetRuntimeLibType(C.getArgs());
 const llvm::Triple Triple(TC.ComputeEffectiveClangTriple(C.getArgs()));
 // The 'Darwin' toolchain is initialized only when its arguments are
 // computed. Get the default arguments for OFK_None to ensure that
@@ -2281,12 +2282,6 @@ bool Driver::HandleImmediateArgs(Compilation &C) {
 // FIXME: For some more esoteric targets the default toolchain is not the
 //correct one.
 C.getArgsForToolChain(&TC, Triple.getArchName(), Action::OFK_None);
-return Triple;
-  };
-
-  if (C.getArgs().hasArg(options::OPT_print_libgcc_file_name)) {
-ToolChain::RuntimeLibType RLT = TC.GetRuntimeLibType(C.getArgs());
-const llvm::Triple Triple = initializeTargets();
 RegisterEffectiveTriple TripleRAII(TC, Triple);
 switch (RLT) {
 case ToolChain::RLT_CompilerRT:
@@ -2330,9 +2325,7 @@ bool Driver::HandleImmediateArgs(Compilation &C) {
   }
 
   if (C.getArgs().hasArg(options::OPT_print_target_triple)) {
-initializeTargets();
-llvm::Triple Triple(TC.ComputeEffectiveClangTriple(C.getArgs()));
-llvm::outs() << Triple.getTriple() << "\n";
+llvm::outs() << TC.getTripleString() << "\n";
 return false;
   }
 

diff  --git a/clang/test/Driver/darwin-print-target-triple.c 
b/clang/test/Driver/darwin-print-target-triple.c
deleted file mode 100644
index 4f5fdfe9d0db3..0
--- a/clang/test/Driver/darwin-print-target-triple.c
+++ /dev/null
@@ -1,42 +0,0 @@
-// Test the output of -print-target-triple on Darwin.
-// See https://github.com/llvm/llvm-project/issues/61762
-
-//
-// All platforms
-//
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=x86_64-apple-macos -mmacos-version-min=15 \
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-MACOS %s
-// CHECK-CLANGRT-MACOS: x86_64-apple-macosx15.0.0
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=arm64-apple-ios -mios-version-min=9 \
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-IOS %s
-// CHECK-CLANGRT-IOS: arm64-apple-ios9.0.0
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=arm64-apple-watchos -mwatchos-version-min=3 \
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-WATCHOS %s
-// CHECK-CLANGRT-WATCHOS: arm64-apple-watchos3.0.0
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=armv7k-apple-watchos -mwatchos-version-min=3 \
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-WATCHOS-ARMV7K %s
-// CHECK-CLANGRT-WATCHOS-ARMV7K: thumbv7-apple-watchos3.0.0
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=arm64-apple-tvos -mtvos-version-min=1\
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-TVOS %s
-// CHECK-CLANGRT-TVOS: arm64-apple-tvos1.0.0
-
-// RUN: %clang -print-target-triple \
-// RUN: --target=arm64-apple-driverkit \
-// RUN: -resource-dir=%S/Inputs/resource_dir 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-DRIVERKIT %s
-// CHECK-CLANGRT-DRIVERKIT: arm64-apple-driverkit19.0.0



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


[clang] Revert "[clang][driver] Fix -print-target-triple OS version for apple targets" (PR #104563)

2024-08-16 Thread Martin Storsjö via cfe-commits

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


[clang] [analyzer] Model overflow builtins (PR #102602)

2024-08-16 Thread Balazs Benics via cfe-commits

steakhal wrote:

I'm on vacation for some time now.
Maybe others can chim in. Should I ping someone?

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


[clang] [Matrix] Preserve signedness when extending matrix index expression. (PR #103044)

2024-08-16 Thread Florian Hahn via cfe-commits

https://github.com/fhahn updated 
https://github.com/llvm/llvm-project/pull/103044

>From 3fc96327079c04e9bcac9488d0ee03e61bb5a3fb Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Tue, 13 Aug 2024 12:28:34 +0100
Subject: [PATCH 1/3] [Matrix] Preserve signedness when extending matrix index
 expression.

As per [1] the indices for a matrix element access operator shall have integral
or unscoped enumeration types and be non-negative. At the moment, the
index expression is converted to SizeType irrespective of the signedness
of the index expression. This causes implicit sign conversion warnings
if any of the indices is signed.

As per the spec, using signed types as indices is allowed and should not
cause any warnings. If the index expression is signed, extend to
SignedSizeType to avoid the warning.

[1] 
https://clang.llvm.org/docs/MatrixTypes.html#matrix-type-element-access-operator
---
 clang/lib/Sema/SemaExpr.cpp| 6 --
 .../test/SemaCXX/matrix-index-operator-sign-conversion.cpp | 7 ++-
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 0f58eb2840211d..258e931ef592e5 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5025,8 +5025,10 @@ ExprResult Sema::CreateBuiltinMatrixSubscriptExpr(Expr 
*Base, Expr *RowIdx,
   }
 }
 
-ExprResult ConvExpr =
-tryConvertExprToType(IndexExpr, Context.getSizeType());
+ExprResult ConvExpr = tryConvertExprToType(
+IndexExpr, IndexExpr->getType()->isSignedIntegerType()
+   ? Context.getSignedSizeType()
+   : Context.getSizeType());
 assert(!ConvExpr.isInvalid() &&
"should be able to convert any integer type to size type");
 return ConvExpr.get();
diff --git a/clang/test/SemaCXX/matrix-index-operator-sign-conversion.cpp 
b/clang/test/SemaCXX/matrix-index-operator-sign-conversion.cpp
index 4254780651c5f5..e6fe4a6c57ff22 100644
--- a/clang/test/SemaCXX/matrix-index-operator-sign-conversion.cpp
+++ b/clang/test/SemaCXX/matrix-index-operator-sign-conversion.cpp
@@ -2,19 +2,16 @@
 
 template  using m 
__attribute__((__matrix_type__(R,C))) = T;
 
-// FIXME: should not warn here.
 double index1(m X, int  i) { return X[i][0]; }
-// expected-warning@-1 {{implicit conversion changes signedness: 'int' to 
'unsigned long'}}
 
 double index2(m X, unsigned i) { return X[i][0]; }
 
 double index3(m X, char i) { return X[i][0]; }
-// expected-warning@-1 {{implicit conversion changes signedness: 'char' to 
'unsigned long'}}
 
 double index4(m X, int  i) { return X[0][i]; }
-// expected-warning@-1 {{implicit conversion changes signedness: 'int' to 
'unsigned long'}}
 
 double index5(m X, unsigned i) { return X[0][i]; }
 
 double index6(m X, char i) { return X[0][i]; }
-// expected-warning@-1 {{implicit conversion changes signedness: 'char' to 
'unsigned long'}}
+
+// expected-no-diagnostics

>From 4efcce858df40edb0fbe70b296bfb0b4e0cd78d3 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Thu, 15 Aug 2024 17:29:42 +0100
Subject: [PATCH 2/3] !fixup move extends to CG.

---
 clang/lib/CodeGen/CGExpr.cpp   | 14 --
 clang/lib/CodeGen/CGExprScalar.cpp | 11 +--
 clang/lib/Sema/SemaExpr.cpp|  5 +
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 48d9a3b8a5acb3..866c6f5be36c42 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -4397,8 +4397,18 @@ LValue CodeGenFunction::EmitMatrixSubscriptExpr(const 
MatrixSubscriptExpr *E) {
   !E->isIncomplete() &&
   "incomplete matrix subscript expressions should be rejected during 
Sema");
   LValue Base = EmitLValue(E->getBase());
-  llvm::Value *RowIdx = EmitScalarExpr(E->getRowIdx());
-  llvm::Value *ColIdx = EmitScalarExpr(E->getColumnIdx());
+
+  // Extend or truncate the index type to 32 or 64-bits.
+  auto EmitIndex = [this](const Expr *E) {
+llvm::Value *Idx = EmitScalarExpr(E);
+bool IsSigned = E->getType()->isSignedIntegerOrEnumerationType();
+if (Idx->getType() != IntPtrTy)
+  Idx = Builder.CreateIntCast(Idx, IntPtrTy, IsSigned);
+return Idx;
+  };
+  llvm::Value *RowIdx = EmitIndex(E->getRowIdx());
+  llvm::Value *ColIdx = EmitIndex(E->getColumnIdx());
+
   llvm::Value *NumRows = Builder.getIntN(
   RowIdx->getType()->getScalarSizeInBits(),
   E->getBase()->getType()->castAs()->getNumRows());
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 84392745ea6144..200d385103d593 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -1995,8 +1995,15 @@ Value 
*ScalarExprEmitter::VisitMatrixSubscriptExpr(MatrixSubscriptExpr *E) {
 
   // Handle the vector case.  The base must be a vector, the index must be an
   // integer value.
-  Value *RowIdx = Visit(E

[clang] [Matrix] Preserve signedness when extending matrix index expression. (PR #103044)

2024-08-16 Thread Florian Hahn via cfe-commits


@@ -4348,8 +4348,18 @@ LValue CodeGenFunction::EmitMatrixSubscriptExpr(const 
MatrixSubscriptExpr *E) {
   !E->isIncomplete() &&
   "incomplete matrix subscript expressions should be rejected during 
Sema");
   LValue Base = EmitLValue(E->getBase());
-  llvm::Value *RowIdx = EmitScalarExpr(E->getRowIdx());
-  llvm::Value *ColIdx = EmitScalarExpr(E->getColumnIdx());
+
+  // Extend or truncate the index type to 32 or 64-bits.
+  auto EmitIndex = [this](const Expr *E) {
+llvm::Value *Idx = EmitScalarExpr(E);
+bool IsSigned = E->getType()->isSignedIntegerOrEnumerationType();

fhahn wrote:

Done, thanks!

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


[clang] [analyzer] Model overflow builtins (PR #102602)

2024-08-16 Thread Pavel Skripkin via cfe-commits

pskrgag wrote:

Oh, sorry for ping then. PR is not urgent at all.

Have a fun vacation! =)

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


[clang] [llvm] [X86][AVX10.2] Support AVX10.2-CONVERT new instructions. (PR #101600)

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


@@ -2217,6 +2217,50 @@ TARGET_BUILTIN(__builtin_ia32_vcvttps2ibs512_mask, 
"V16UiV16fV16UiUsIi", "nV:512
 TARGET_BUILTIN(__builtin_ia32_vcvttps2iubs128_mask, "V4UiV4fV4UiUc", 
"nV:128:", "avx10.2-256")
 TARGET_BUILTIN(__builtin_ia32_vcvttps2iubs256_mask, "V8UiV8fV8UiUcIi", 
"nV:256:", "avx10.2-256")
 TARGET_BUILTIN(__builtin_ia32_vcvttps2iubs512_mask, "V16UiV16fV16UiUsIi", 
"nV:512:", "avx10.2-512")
+
+// AVX10.2 CONVERT
+TARGET_BUILTIN(__builtin_ia32_vcvt2ps2phx128_mask, "V8xV4fV4fV8xUc", 
"ncV:128:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvt2ps2phx256_mask, "V16xV8fV8fV16xUsIi", 
"ncV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvt2ps2phx512_mask, "V32xV16fV16fV32xUiIi", 
"ncV:512:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvtbiasph2bf8_128_mask, "V16cV16cV8xV16cUc", 
"nV:128:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtbiasph2bf8_256_mask, "V16cV32cV16xV16cUs", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtbiasph2bf8_512_mask, "V32cV64cV32xV32cUi", 
"nV:512:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvtbiasph2bf8s_128_mask, "V16cV16cV8xV16cUc", 
"nV:128:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtbiasph2bf8s_256_mask, "V16cV32cV16xV16cUs", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtbiasph2bf8s_512_mask, "V32cV64cV32xV32cUi", 
"nV:512:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvtbiasph2hf8_128_mask, "V16cV16cV8xV16cUc", 
"nV:128:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtbiasph2hf8_256_mask, "V16cV32cV16xV16cUs", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtbiasph2hf8_512_mask, "V32cV64cV32xV32cUi", 
"nV:512:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvtbiasph2hf8s_128_mask, "V16cV16cV8xV16cUc", 
"nV:128:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtbiasph2hf8s_256_mask, "V16cV32cV16xV16cUs", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtbiasph2hf8s_512_mask, "V32cV64cV32xV32cUi", 
"nV:512:", "avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvtne2ph2bf8_128, "V16cV8xV8x", "nV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtne2ph2bf8_256, "V32cV16xV16x", "nV:256:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtne2ph2bf8_512, "V64cV32xV32x", "nV:512:", 
"avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvtne2ph2bf8s_128, "V16cV8xV8x", "nV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtne2ph2bf8s_256, "V32cV16xV16x", "nV:256:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtne2ph2bf8s_512, "V64cV32xV32x", "nV:512:", 
"avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvtne2ph2hf8_128, "V16cV8xV8x", "nV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtne2ph2hf8_256, "V32cV16xV16x", "nV:256:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtne2ph2hf8_512, "V64cV32xV32x", "nV:512:", 
"avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvtne2ph2hf8s_128, "V16cV8xV8x", "nV:128:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtne2ph2hf8s_256, "V32cV16xV16x", "nV:256:", 
"avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtne2ph2hf8s_512, "V64cV32xV32x", "nV:512:", 
"avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vcvtnehf8_2ph128_mask, "V8xV16cV8xUc", 
"nV:128:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtnehf8_2ph256_mask, "V16xV16cV16xUs", 
"nV:256:", "avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vcvtnehf8_2ph512_mask, "V32xV32cV32xUi", 
"nV:512:", "avx10.2-512")

FreddyLeaf wrote:

Done in latest.

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


[clang] [llvm] [X86][AVX10.2] Support AVX10.2-CONVERT new instructions. (PR #101600)

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


@@ -0,0 +1,286 @@
+/*===- avx10_2_512convertintrin.h - AVX10_2_512CONVERT -===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+#ifndef __IMMINTRIN_H
+#error 
\
+"Never use  directly; include  
instead."
+#endif // __IMMINTRIN_H
+
+#ifdef __SSE2__
+
+#ifndef __AVX10_2_512CONVERTINTRIN_H
+#define __AVX10_2_512CONVERTINTRIN_H
+
+/* Define the default attributes for the functions in this file. */
+#define __DEFAULT_FN_ATTRS512  
\
+  __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-512"),
\
+ __min_vector_width__(512)))
+
+static __inline__ __m512h __DEFAULT_FN_ATTRS512 _mm512_cvtx2ps_ph(__m512 __A,
+  __m512 __B) {
+  return (__m512h)__builtin_ia32_vcvt2ps2phx512_mask(
+  (__v16sf)__A, (__v16sf)__B, (__v32hf)_mm512_setzero_ph(), 
(__mmask32)(-1),
+  _MM_FROUND_CUR_DIRECTION);
+}
+
+static __inline__ __m512h __DEFAULT_FN_ATTRS512
+_mm512_mask_cvtx2ps_ph(__m512h __W, __mmask32 __U, __m512 __A, __m512 __B) {
+  return (__m512h)__builtin_ia32_vcvt2ps2phx512_mask(
+  (__v16sf)__A, (__v16sf)__B, (__v32hf)__W, (__mmask32)__U,
+  _MM_FROUND_CUR_DIRECTION);
+}
+
+#define _mm512_cvtx_round2ps_ph(A, B, R)   
\
+  ((__m512h)__builtin_ia32_vcvt2ps2phx512_mask(
\
+  (__v16sf)(A), (__v16sf)(B), (__v32hf)_mm512_undefined_ph(),  
\
+  (__mmask32)(-1), (const int)(R)))
+
+#define _mm512_mask_cvtx_round2ps_ph(W, U, A, B, R)
\
+  ((__m512h)__builtin_ia32_vcvt2ps2phx512_mask((__v16sf)(A), (__v16sf)(B), 
\
+   (__v32hf)(W), (__mmask32)(U),   
\
+   (const int)(R)))
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512
+_mm512_cvtbiasph_pbf8(__m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2bf8_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)_mm256_undefined_si256(),
+  (__mmask32)-1);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512 _mm512_mask_cvtbiasph_pbf8(
+__m256i __W, __mmask32 __U, __m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2bf8_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)(__m256i)__W, (__mmask32)__U);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512
+_mm512_maskz_cvtbiasph_pbf8(__mmask32 __U, __m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2bf8_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)(__m256i)_mm256_setzero_si256(),
+  (__mmask32)__U);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512
+_mm512_cvtbiassph_pbf8(__m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2bf8s_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)_mm256_undefined_si256(),
+  (__mmask32)-1);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512 _mm512_mask_cvtbiassph_pbf8(
+__m256i __W, __mmask32 __U, __m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2bf8s_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)(__m256i)__W, (__mmask32)__U);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512
+_mm512_maskz_cvtbiassph_pbf8(__mmask32 __U, __m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2bf8s_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)(__m256i)_mm256_setzero_si256(),
+  (__mmask32)__U);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512
+_mm512_cvtbiasph_phf8(__m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2hf8_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)_mm256_undefined_si256(),
+  (__mmask32)-1);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512 _mm512_mask_cvtbiasph_phf8(
+__m256i __W, __mmask32 __U, __m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2hf8_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)(__m256i)__W, (__mmask32)__U);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512
+_mm512_maskz_cvtbiasph_phf8(__mmask32 __U, __m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2hf8_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)(__m256i)_mm256_setzero_si256(),
+  (__mmask32)__U);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512
+_mm512_cvtbiassph_phf8(__m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2hf8s_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)_mm256_undefined_si256(),
+  (__mmask32)-1);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512 _mm512_mask_cvtbia

[clang] [llvm] [X86][AVX10.2] Support AVX10.2-CONVERT new instructions. (PR #101600)

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


@@ -0,0 +1,286 @@
+/*===- avx10_2_512convertintrin.h - AVX10_2_512CONVERT -===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+#ifndef __IMMINTRIN_H
+#error 
\
+"Never use  directly; include  
instead."
+#endif // __IMMINTRIN_H
+
+#ifdef __SSE2__
+
+#ifndef __AVX10_2_512CONVERTINTRIN_H
+#define __AVX10_2_512CONVERTINTRIN_H
+
+/* Define the default attributes for the functions in this file. */
+#define __DEFAULT_FN_ATTRS512  
\
+  __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-512"),
\
+ __min_vector_width__(512)))
+
+static __inline__ __m512h __DEFAULT_FN_ATTRS512 _mm512_cvtx2ps_ph(__m512 __A,
+  __m512 __B) {
+  return (__m512h)__builtin_ia32_vcvt2ps2phx512_mask(
+  (__v16sf)__A, (__v16sf)__B, (__v32hf)_mm512_setzero_ph(), 
(__mmask32)(-1),
+  _MM_FROUND_CUR_DIRECTION);
+}
+
+static __inline__ __m512h __DEFAULT_FN_ATTRS512
+_mm512_mask_cvtx2ps_ph(__m512h __W, __mmask32 __U, __m512 __A, __m512 __B) {
+  return (__m512h)__builtin_ia32_vcvt2ps2phx512_mask(
+  (__v16sf)__A, (__v16sf)__B, (__v32hf)__W, (__mmask32)__U,
+  _MM_FROUND_CUR_DIRECTION);
+}
+
+#define _mm512_cvtx_round2ps_ph(A, B, R)   
\
+  ((__m512h)__builtin_ia32_vcvt2ps2phx512_mask(
\
+  (__v16sf)(A), (__v16sf)(B), (__v32hf)_mm512_undefined_ph(),  
\
+  (__mmask32)(-1), (const int)(R)))
+
+#define _mm512_mask_cvtx_round2ps_ph(W, U, A, B, R)
\
+  ((__m512h)__builtin_ia32_vcvt2ps2phx512_mask((__v16sf)(A), (__v16sf)(B), 
\
+   (__v32hf)(W), (__mmask32)(U),   
\
+   (const int)(R)))
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512
+_mm512_cvtbiasph_pbf8(__m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2bf8_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)_mm256_undefined_si256(),
+  (__mmask32)-1);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512 _mm512_mask_cvtbiasph_pbf8(
+__m256i __W, __mmask32 __U, __m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2bf8_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)(__m256i)__W, (__mmask32)__U);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512
+_mm512_maskz_cvtbiasph_pbf8(__mmask32 __U, __m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2bf8_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)(__m256i)_mm256_setzero_si256(),
+  (__mmask32)__U);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512
+_mm512_cvtbiassph_pbf8(__m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2bf8s_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)_mm256_undefined_si256(),
+  (__mmask32)-1);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512 _mm512_mask_cvtbiassph_pbf8(
+__m256i __W, __mmask32 __U, __m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2bf8s_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)(__m256i)__W, (__mmask32)__U);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512
+_mm512_maskz_cvtbiassph_pbf8(__mmask32 __U, __m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2bf8s_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)(__m256i)_mm256_setzero_si256(),
+  (__mmask32)__U);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512
+_mm512_cvtbiasph_phf8(__m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2hf8_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)_mm256_undefined_si256(),
+  (__mmask32)-1);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512 _mm512_mask_cvtbiasph_phf8(
+__m256i __W, __mmask32 __U, __m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2hf8_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)(__m256i)__W, (__mmask32)__U);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512
+_mm512_maskz_cvtbiasph_phf8(__mmask32 __U, __m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2hf8_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)(__m256i)_mm256_setzero_si256(),
+  (__mmask32)__U);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512
+_mm512_cvtbiassph_phf8(__m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2hf8s_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)_mm256_undefined_si256(),
+  (__mmask32)-1);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512 _mm512_mask_cvtbia

[clang] [llvm] [X86][AVX10.2] Support AVX10.2-CONVERT new instructions. (PR #101600)

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


@@ -0,0 +1,286 @@
+/*===- avx10_2_512convertintrin.h - AVX10_2_512CONVERT -===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+#ifndef __IMMINTRIN_H
+#error 
\
+"Never use  directly; include  
instead."
+#endif // __IMMINTRIN_H
+
+#ifdef __SSE2__
+
+#ifndef __AVX10_2_512CONVERTINTRIN_H
+#define __AVX10_2_512CONVERTINTRIN_H
+
+/* Define the default attributes for the functions in this file. */
+#define __DEFAULT_FN_ATTRS512  
\
+  __attribute__((__always_inline__, __nodebug__, __target__("avx10.2-512"),
\
+ __min_vector_width__(512)))
+
+static __inline__ __m512h __DEFAULT_FN_ATTRS512 _mm512_cvtx2ps_ph(__m512 __A,
+  __m512 __B) {
+  return (__m512h)__builtin_ia32_vcvt2ps2phx512_mask(
+  (__v16sf)__A, (__v16sf)__B, (__v32hf)_mm512_setzero_ph(), 
(__mmask32)(-1),
+  _MM_FROUND_CUR_DIRECTION);
+}
+
+static __inline__ __m512h __DEFAULT_FN_ATTRS512
+_mm512_mask_cvtx2ps_ph(__m512h __W, __mmask32 __U, __m512 __A, __m512 __B) {
+  return (__m512h)__builtin_ia32_vcvt2ps2phx512_mask(
+  (__v16sf)__A, (__v16sf)__B, (__v32hf)__W, (__mmask32)__U,
+  _MM_FROUND_CUR_DIRECTION);
+}
+
+#define _mm512_cvtx_round2ps_ph(A, B, R)   
\
+  ((__m512h)__builtin_ia32_vcvt2ps2phx512_mask(
\
+  (__v16sf)(A), (__v16sf)(B), (__v32hf)_mm512_undefined_ph(),  
\
+  (__mmask32)(-1), (const int)(R)))
+
+#define _mm512_mask_cvtx_round2ps_ph(W, U, A, B, R)
\
+  ((__m512h)__builtin_ia32_vcvt2ps2phx512_mask((__v16sf)(A), (__v16sf)(B), 
\
+   (__v32hf)(W), (__mmask32)(U),   
\
+   (const int)(R)))
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512
+_mm512_cvtbiasph_pbf8(__m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2bf8_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)_mm256_undefined_si256(),
+  (__mmask32)-1);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512 _mm512_mask_cvtbiasph_pbf8(
+__m256i __W, __mmask32 __U, __m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2bf8_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)(__m256i)__W, (__mmask32)__U);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512
+_mm512_maskz_cvtbiasph_pbf8(__mmask32 __U, __m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2bf8_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)(__m256i)_mm256_setzero_si256(),
+  (__mmask32)__U);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512
+_mm512_cvtbiassph_pbf8(__m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2bf8s_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)_mm256_undefined_si256(),
+  (__mmask32)-1);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512 _mm512_mask_cvtbiassph_pbf8(
+__m256i __W, __mmask32 __U, __m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2bf8s_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)(__m256i)__W, (__mmask32)__U);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512
+_mm512_maskz_cvtbiassph_pbf8(__mmask32 __U, __m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2bf8s_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)(__m256i)_mm256_setzero_si256(),
+  (__mmask32)__U);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512
+_mm512_cvtbiasph_phf8(__m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2hf8_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)_mm256_undefined_si256(),
+  (__mmask32)-1);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512 _mm512_mask_cvtbiasph_phf8(
+__m256i __W, __mmask32 __U, __m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2hf8_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)(__m256i)__W, (__mmask32)__U);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512
+_mm512_maskz_cvtbiasph_phf8(__mmask32 __U, __m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2hf8_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)(__m256i)_mm256_setzero_si256(),
+  (__mmask32)__U);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512
+_mm512_cvtbiassph_phf8(__m512i __A, __m512h __B) {
+  return (__m256i)__builtin_ia32_vcvtbiasph2hf8s_512_mask(
+  (__v64qi)__A, (__v32hf)__B, (__v32qi)_mm256_undefined_si256(),
+  (__mmask32)-1);
+}
+
+static __inline__ __m256i __DEFAULT_FN_ATTRS512 _mm512_mask_cvtbia

[clang] [llvm] [X86][AVX10.2] Support AVX10.2-CONVERT new instructions. (PR #101600)

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


@@ -624,3 +624,440 @@ defm VCVTTPS2IUBS : avx10_sat_cvt_base<0x6a, 
"vcvttps2iubs", SchedWriteVecIMul,
   avx512vl_i32_info, avx512vl_f32_info,
   X86vcvttp2iubsSAE>,
 AVX512PDIi8Base, T_MAP5, EVEX_CD8<32, CD8VF>;
+
+//-
+// AVX10 CONVERT instructions
+//-
+
+multiclass avx10_cvt2ps2ph_rc opc, string OpcodeStr, 
X86FoldableSchedWrite sched,
+  X86VectorVTInfo _Src, X86VectorVTInfo _,
+  SDNode OpNodeRnd> {
+  let Uses = [MXCSR] in
+defm rrb : AVX512_maskable,
+  EVEX, , EVEX_B, EVEX_RC, PD, Sched<[sched]>;
+}
+
+multiclass avx10_cvt2ps2ph opc, string OpcodeStr,
+ X86SchedWriteWidths sched,
+ AVX512VLVectorVTInfo _SrcVTInfo,
+ AVX512VLVectorVTInfo _DstVTInfo,
+ SDNode OpNode, SDNode OpNodeRnd> {

FreddyLeaf wrote:

Done in latest.

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


[clang] [llvm] [X86][AVX10.2] Support AVX10.2-CONVERT new instructions. (PR #101600)

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


@@ -624,3 +624,440 @@ defm VCVTTPS2IUBS : avx10_sat_cvt_base<0x6a, 
"vcvttps2iubs", SchedWriteVecIMul,
   avx512vl_i32_info, avx512vl_f32_info,
   X86vcvttp2iubsSAE>,
 AVX512PDIi8Base, T_MAP5, EVEX_CD8<32, CD8VF>;
+
+//-
+// AVX10 CONVERT instructions
+//-
+
+multiclass avx10_cvt2ps2ph_rc opc, string OpcodeStr, 
X86FoldableSchedWrite sched,
+  X86VectorVTInfo _Src, X86VectorVTInfo _,
+  SDNode OpNodeRnd> {
+  let Uses = [MXCSR] in
+defm rrb : AVX512_maskable,
+  EVEX, , EVEX_B, EVEX_RC, PD, Sched<[sched]>;
+}
+
+multiclass avx10_cvt2ps2ph opc, string OpcodeStr,
+ X86SchedWriteWidths sched,
+ AVX512VLVectorVTInfo _SrcVTInfo,
+ AVX512VLVectorVTInfo _DstVTInfo,
+ SDNode OpNode, SDNode OpNodeRnd> {
+  let Predicates = [HasAVX10_2_512], Uses = [MXCSR] in {
+defm Z : avx512_binop_rm2,
+ avx10_cvt2ps2ph_rc,
+ EVEX_V512, EVEX_CD8<32, CD8VF>;
+  }
+  let Predicates = [HasAVX10_2] in {
+defm Z256 : avx512_binop_rm2,
+EVEX_V256, EVEX_CD8<32, CD8VF>;
+defm Z128 : avx512_binop_rm2,
+EVEX_V128, EVEX_CD8<32, CD8VF>;
+  }
+
+  let Predicates = [HasAVX10_2], hasEVEX_U = 1 in {
+defm Z256 : avx10_cvt2ps2ph_rc;
+  }
+}
+
+defm VCVT2PS2PHX : avx10_cvt2ps2ph<0x67, "vcvt2ps2phx",
+   SchedWriteCvtPD2PS,
+   avx512vl_f32_info, avx512vl_f16_info,
+   X86vcvt2ps2phx, X86vcvt2ps2phxRnd>, T8;
+
+multiclass avx10_binop_all opc, string OpcodeStr,
+   X86SchedWriteWidths sched,
+   AVX512VLVectorVTInfo _SrcVTInfo,
+   AVX512VLVectorVTInfo _DstVTInfo,
+   SDNode OpNode,
+   bit IsCommutable = 0> {
+  let Predicates = [HasAVX10_2_512] in
+defm NAME#Z : avx512_binop_rm2,
+  EVEX_V512;
+  let Predicates = [HasAVX10_2] in {
+defm NAME#Z256 : avx512_binop_rm2,
+ EVEX_V256;
+defm NAME#Z128 : avx512_binop_rm2,
+ EVEX_V128;
+  }
+}
+
+defm VCVTNE2PH2BF8 : avx10_binop_all<0x74, "vcvtne2ph2bf8", SchedWriteCvtPD2PS,
+ avx512vl_f16_info, avx512vl_i8_info,
+ X86vcvtne2ph2bf8, 0>,
+EVEX_CD8<16, CD8VF>, T8, XD;
+defm VCVTNE2PH2BF8S : avx10_binop_all<0x74, "vcvtne2ph2bf8s", 
SchedWriteCvtPD2PS,
+  avx512vl_f16_info, avx512vl_i8_info,
+  X86vcvtne2ph2bf8s, 0>,
+ EVEX_CD8<16, CD8VF>, T_MAP5, XD;
+defm VCVTNE2PH2HF8 : avx10_binop_all<0x18, "vcvtne2ph2hf8", SchedWriteCvtPD2PS,
+ avx512vl_f16_info, avx512vl_i8_info,
+ X86vcvtne2ph2hf8, 0>,
+EVEX_CD8<16, CD8VF>, T_MAP5, XD;
+defm VCVTNE2PH2HF8S : avx10_binop_all<0x1b, "vcvtne2ph2hf8s", 
SchedWriteCvtPD2PS,
+  avx512vl_f16_info, avx512vl_i8_info,
+  X86vcvtne2ph2hf8s, 0>,
+ EVEX_CD8<16, CD8VF>, T_MAP5, XD;
+
+multiclass avx10_convert_3op_packed OpCode, string OpcodeStr,
+   X86VectorVTInfo vt_dst, X86VectorVTInfo vt_src1,
+   X86VectorVTInfo vt_src2, SDPatternOperator OpNode,
+   SDPatternOperator MaskOpNode, X86FoldableSchedWrite sched,
+   string Broadcast = vt_src2.BroadcastStr,
+   X86MemOperand MemOp = vt_src2.MemOp,
+   RegisterClass MaskRC = vt_src2.KRCWM,
+   dag LdDAG = (vt_dst.VT (OpNode (vt_src1.VT vt_src1.RC:$src1),
+  (vt_src2.VT (vt_src2.LdFrag addr:$src2,
+   dag MaskLdDAG = (vt_dst.VT (MaskOpNode (vt_src1.VT 
vt_src1.RC:$src1),
+  (vt_src2.VT (vt_src2.LdFrag 
addr:$src2> {

FreddyLeaf wrote:

Done in latest.

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


[clang] [llvm] [X86][AVX10.2] Support AVX10.2-CONVERT new instructions. (PR #101600)

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


@@ -624,3 +624,440 @@ defm VCVTTPS2IUBS : avx10_sat_cvt_base<0x6a, 
"vcvttps2iubs", SchedWriteVecIMul,
   avx512vl_i32_info, avx512vl_f32_info,
   X86vcvttp2iubsSAE>,
 AVX512PDIi8Base, T_MAP5, EVEX_CD8<32, CD8VF>;
+
+//-
+// AVX10 CONVERT instructions
+//-
+
+multiclass avx10_cvt2ps2ph_rc opc, string OpcodeStr, 
X86FoldableSchedWrite sched,

FreddyLeaf wrote:

Done in latest.

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


[clang] [Clang] strengthen checks for 'main' function to meet [basic.start.main] p3 requirements (PR #101853)

2024-08-16 Thread Mital Ashok via cfe-commits


@@ -12210,7 +12220,18 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
   return Redeclaration;
 }
 
-void Sema::CheckMain(FunctionDecl* FD, const DeclSpec& DS) {
+void Sema::CheckMain(FunctionDecl *FD, const DeclSpec &DS) {
+  // [basic.start.main]p3
+  //The main function shall not be declared with a linkage-specification.
+  if (FD->isExternCContext() ||
+  (FD->isExternCXXContext() &&
+   FD->getDeclContext()->getRedeclContext()->isTranslationUnit())) {
+Diag(FD->getLocation(), diag::ext_main_invalid_linkage_specification)
+<< FD->getLanguageLinkage();
+FD->setInvalidDecl();
+return;

MitalAshok wrote:

```suggestion
```

@alexfh I think these lines are probably what's causing the crash (if it's 
allowed as an extension, it should not be marked invalid, and we need to 
diagnose/check the other stuff if we have `-Wno-main`).

Either way, could you open a new GitHub issue for visibility?


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


[clang] [clang] Rename all AST/Interp stuff to AST/ByteCode (PR #104552)

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

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

>From c140ef583e6bdff8c7ac829be1ede32460663564 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 16 Aug 2024 08:42:16 +0200
Subject: [PATCH] [clang] Rename all AST/Interp stuff to AST/ByteCode

"Interp" clashes with the clang interpreter and people often confuse
this.
---
 clang/docs/ClangFormattedStatus.rst   |  2 +-
 clang/docs/tools/clang-formatted-files.txt| 36 ++---
 clang/lib/AST/ASTContext.cpp  |  2 +-
 clang/lib/AST/{Interp => ByteCode}/Boolean.h  |  0
 .../{Interp => ByteCode}/ByteCodeEmitter.cpp  |  0
 .../{Interp => ByteCode}/ByteCodeEmitter.h|  0
 .../lib/AST/{Interp => ByteCode}/Compiler.cpp |  0
 clang/lib/AST/{Interp => ByteCode}/Compiler.h |  0
 .../lib/AST/{Interp => ByteCode}/Context.cpp  |  0
 clang/lib/AST/{Interp => ByteCode}/Context.h  |  0
 .../AST/{Interp => ByteCode}/Descriptor.cpp   |  0
 .../lib/AST/{Interp => ByteCode}/Descriptor.h |  0
 clang/lib/AST/{Interp => ByteCode}/Disasm.cpp |  0
 .../{Interp => ByteCode}/DynamicAllocator.cpp |  0
 .../{Interp => ByteCode}/DynamicAllocator.h   |  0
 .../AST/{Interp => ByteCode}/EvalEmitter.cpp  |  0
 .../AST/{Interp => ByteCode}/EvalEmitter.h|  0
 .../{Interp => ByteCode}/EvaluationResult.cpp |  0
 .../{Interp => ByteCode}/EvaluationResult.h   |  0
 .../lib/AST/{Interp => ByteCode}/Floating.cpp |  0
 clang/lib/AST/{Interp => ByteCode}/Floating.h |  0
 clang/lib/AST/{Interp => ByteCode}/Frame.cpp  |  0
 clang/lib/AST/{Interp => ByteCode}/Frame.h|  0
 .../lib/AST/{Interp => ByteCode}/Function.cpp |  0
 clang/lib/AST/{Interp => ByteCode}/Function.h |  0
 .../{Interp => ByteCode}/FunctionPointer.h|  0
 clang/lib/AST/{Interp => ByteCode}/Integral.h |  0
 .../lib/AST/{Interp => ByteCode}/IntegralAP.h |  0
 clang/lib/AST/{Interp => ByteCode}/Interp.cpp |  0
 clang/lib/AST/{Interp => ByteCode}/Interp.h   |  0
 .../AST/{Interp => ByteCode}/InterpBlock.cpp  |  0
 .../AST/{Interp => ByteCode}/InterpBlock.h|  0
 .../{Interp => ByteCode}/InterpBuiltin.cpp|  0
 .../AST/{Interp => ByteCode}/InterpFrame.cpp  |  0
 .../AST/{Interp => ByteCode}/InterpFrame.h|  0
 .../AST/{Interp => ByteCode}/InterpShared.cpp |  0
 .../AST/{Interp => ByteCode}/InterpShared.h   |  0
 .../AST/{Interp => ByteCode}/InterpStack.cpp  |  0
 .../AST/{Interp => ByteCode}/InterpStack.h|  0
 .../AST/{Interp => ByteCode}/InterpState.cpp  |  0
 .../AST/{Interp => ByteCode}/InterpState.h|  0
 .../{Interp => ByteCode}/MemberPointer.cpp|  0
 .../AST/{Interp => ByteCode}/MemberPointer.h  |  0
 clang/lib/AST/{Interp => ByteCode}/Opcode.h   |  0
 clang/lib/AST/{Interp => ByteCode}/Opcodes.td |  0
 .../lib/AST/{Interp => ByteCode}/Pointer.cpp  |  0
 clang/lib/AST/{Interp => ByteCode}/Pointer.h  |  0
 .../lib/AST/{Interp => ByteCode}/PrimType.cpp |  0
 clang/lib/AST/{Interp => ByteCode}/PrimType.h |  0
 .../lib/AST/{Interp => ByteCode}/Primitives.h |  0
 .../lib/AST/{Interp => ByteCode}/Program.cpp  |  0
 clang/lib/AST/{Interp => ByteCode}/Program.h  |  0
 clang/lib/AST/{Interp => ByteCode}/Record.cpp |  0
 clang/lib/AST/{Interp => ByteCode}/Record.h   |  0
 clang/lib/AST/{Interp => ByteCode}/Source.cpp |  0
 clang/lib/AST/{Interp => ByteCode}/Source.h   |  0
 clang/lib/AST/{Interp => ByteCode}/State.cpp  |  0
 clang/lib/AST/{Interp => ByteCode}/State.h|  0
 clang/lib/AST/CMakeLists.txt  | 52 +--
 clang/lib/AST/ExprConstShared.h   |  2 +-
 clang/lib/AST/ExprConstant.cpp|  6 +--
 .../test/AST/{Interp => ByteCode}/arrays.cpp  |  0
 clang/test/AST/{Interp => ByteCode}/atomic.c  |  0
 .../test/AST/{Interp => ByteCode}/atomic.cpp  |  0
 .../AST/{Interp => ByteCode}/bitfields.cpp|  0
 .../builtin-align-cxx.cpp |  0
 .../builtin-constant-p.cpp|  0
 .../builtin-functions.cpp |  0
 .../AST/{Interp => ByteCode}/builtins.cpp |  0
 clang/test/AST/{Interp => ByteCode}/c.c   |  0
 clang/test/AST/{Interp => ByteCode}/c23.c |  0
 .../test/AST/{Interp => ByteCode}/codegen.cpp |  0
 clang/test/AST/{Interp => ByteCode}/comma.cpp |  0
 clang/test/AST/{Interp => ByteCode}/complex.c |  0
 .../test/AST/{Interp => ByteCode}/complex.cpp |  0
 clang/test/AST/{Interp => ByteCode}/cond.cpp  |  0
 .../AST/{Interp => ByteCode}/const-eval.c |  0
 .../{Interp => ByteCode}/const-fpfeatures.cpp |  0
 .../const-temporaries.cpp |  0
 .../constexpr-frame-describe.cpp  |  0
 .../constexpr-nqueens.cpp |  0
 .../constexpr-subobj-initialization.cpp   |  0
 .../{Interp => ByteCode}/crash-GH49103-2.cpp  |  0
 clang/test/AST/{Interp => ByteCode}/cxx03.cpp |  0
 clang/test/AST/{Interp => ByteCode}/cxx11.cpp |  0
 clang/test/AST/{Interp => ByteCode}/cxx17.cpp |  0
 clang/test/AST/{Interp => ByteCode}/cxx20.cpp |  0
 clang/test/AST/{Interp => ByteCode}/cxx23.c

[clang] [Clang] strengthen checks for 'main' function to meet [basic.start.main] p3 requirements (PR #101853)

2024-08-16 Thread Oleksandr T. via cfe-commits


@@ -12210,7 +12220,18 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
   return Redeclaration;
 }
 
-void Sema::CheckMain(FunctionDecl* FD, const DeclSpec& DS) {
+void Sema::CheckMain(FunctionDecl *FD, const DeclSpec &DS) {
+  // [basic.start.main]p3
+  //The main function shall not be declared with a linkage-specification.
+  if (FD->isExternCContext() ||
+  (FD->isExternCXXContext() &&
+   FD->getDeclContext()->getRedeclContext()->isTranslationUnit())) {
+Diag(FD->getLocation(), diag::ext_main_invalid_linkage_specification)
+<< FD->getLanguageLinkage();
+FD->setInvalidDecl();
+return;

a-tarasyuk wrote:

@alexfh I’ll look into it today. Thanks for bringing this additional case to my 
attention.

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


[clang] [clang] Rename all AST/Interp stuff to AST/ByteCode (PR #104552)

2024-08-16 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 22219873987587d8b5d793ab5dea982a0887ac7c 
c140ef583e6bdff8c7ac829be1ede32460663564 --extensions c,cpp,h -- 
clang/lib/AST/ASTContext.cpp clang/lib/AST/ExprConstShared.h 
clang/lib/AST/ExprConstant.cpp clang/lib/AST/ByteCode/Boolean.h 
clang/lib/AST/ByteCode/ByteCodeEmitter.cpp 
clang/lib/AST/ByteCode/ByteCodeEmitter.h clang/lib/AST/ByteCode/Compiler.cpp 
clang/lib/AST/ByteCode/Compiler.h clang/lib/AST/ByteCode/Context.cpp 
clang/lib/AST/ByteCode/Context.h clang/lib/AST/ByteCode/Descriptor.cpp 
clang/lib/AST/ByteCode/Descriptor.h clang/lib/AST/ByteCode/Disasm.cpp 
clang/lib/AST/ByteCode/DynamicAllocator.cpp 
clang/lib/AST/ByteCode/DynamicAllocator.h 
clang/lib/AST/ByteCode/EvalEmitter.cpp clang/lib/AST/ByteCode/EvalEmitter.h 
clang/lib/AST/ByteCode/EvaluationResult.cpp 
clang/lib/AST/ByteCode/EvaluationResult.h clang/lib/AST/ByteCode/Floating.cpp 
clang/lib/AST/ByteCode/Floating.h clang/lib/AST/ByteCode/Frame.cpp 
clang/lib/AST/ByteCode/Frame.h clang/lib/AST/ByteCode/Function.cpp 
clang/lib/AST/ByteCode/Function.h clang/lib/AST/ByteCode/FunctionPointer.h 
clang/lib/AST/ByteCode/Integral.h clang/lib/AST/ByteCode/IntegralAP.h 
clang/lib/AST/ByteCode/Interp.cpp clang/lib/AST/ByteCode/Interp.h 
clang/lib/AST/ByteCode/InterpBlock.cpp clang/lib/AST/ByteCode/InterpBlock.h 
clang/lib/AST/ByteCode/InterpBuiltin.cpp clang/lib/AST/ByteCode/InterpFrame.cpp 
clang/lib/AST/ByteCode/InterpFrame.h clang/lib/AST/ByteCode/InterpShared.cpp 
clang/lib/AST/ByteCode/InterpShared.h clang/lib/AST/ByteCode/InterpStack.cpp 
clang/lib/AST/ByteCode/InterpStack.h clang/lib/AST/ByteCode/InterpState.cpp 
clang/lib/AST/ByteCode/InterpState.h clang/lib/AST/ByteCode/MemberPointer.cpp 
clang/lib/AST/ByteCode/MemberPointer.h clang/lib/AST/ByteCode/Opcode.h 
clang/lib/AST/ByteCode/Pointer.cpp clang/lib/AST/ByteCode/Pointer.h 
clang/lib/AST/ByteCode/PrimType.cpp clang/lib/AST/ByteCode/PrimType.h 
clang/lib/AST/ByteCode/Primitives.h clang/lib/AST/ByteCode/Program.cpp 
clang/lib/AST/ByteCode/Program.h clang/lib/AST/ByteCode/Record.cpp 
clang/lib/AST/ByteCode/Record.h clang/lib/AST/ByteCode/Source.cpp 
clang/lib/AST/ByteCode/Source.h clang/lib/AST/ByteCode/State.cpp 
clang/lib/AST/ByteCode/State.h clang/test/AST/ByteCode/arrays.cpp 
clang/test/AST/ByteCode/atomic.c clang/test/AST/ByteCode/atomic.cpp 
clang/test/AST/ByteCode/bitfields.cpp 
clang/test/AST/ByteCode/builtin-align-cxx.cpp 
clang/test/AST/ByteCode/builtin-constant-p.cpp 
clang/test/AST/ByteCode/builtin-functions.cpp 
clang/test/AST/ByteCode/builtins.cpp clang/test/AST/ByteCode/c.c 
clang/test/AST/ByteCode/c23.c clang/test/AST/ByteCode/codegen.cpp 
clang/test/AST/ByteCode/comma.cpp clang/test/AST/ByteCode/complex.c 
clang/test/AST/ByteCode/complex.cpp clang/test/AST/ByteCode/cond.cpp 
clang/test/AST/ByteCode/const-eval.c 
clang/test/AST/ByteCode/const-fpfeatures.cpp 
clang/test/AST/ByteCode/const-temporaries.cpp 
clang/test/AST/ByteCode/constexpr-frame-describe.cpp 
clang/test/AST/ByteCode/constexpr-nqueens.cpp 
clang/test/AST/ByteCode/constexpr-subobj-initialization.cpp 
clang/test/AST/ByteCode/crash-GH49103-2.cpp clang/test/AST/ByteCode/cxx03.cpp 
clang/test/AST/ByteCode/cxx11.cpp clang/test/AST/ByteCode/cxx17.cpp 
clang/test/AST/ByteCode/cxx20.cpp clang/test/AST/ByteCode/cxx23.cpp 
clang/test/AST/ByteCode/cxx26.cpp clang/test/AST/ByteCode/cxx2a.cpp 
clang/test/AST/ByteCode/cxx98.cpp clang/test/AST/ByteCode/depth-limit.cpp 
clang/test/AST/ByteCode/depth-limit2.cpp 
clang/test/AST/ByteCode/enums-targets.cpp clang/test/AST/ByteCode/enums.cpp 
clang/test/AST/ByteCode/eval-order.cpp clang/test/AST/ByteCode/floats.cpp 
clang/test/AST/ByteCode/functions.cpp clang/test/AST/ByteCode/if.cpp 
clang/test/AST/ByteCode/intap.cpp clang/test/AST/ByteCode/invalid.cpp 
clang/test/AST/ByteCode/lambda.cpp clang/test/AST/ByteCode/lifetimes.cpp 
clang/test/AST/ByteCode/literals.cpp clang/test/AST/ByteCode/loops.cpp 
clang/test/AST/ByteCode/memberpointers.cpp clang/test/AST/ByteCode/ms.cpp 
clang/test/AST/ByteCode/mutable.cpp clang/test/AST/ByteCode/new-delete.cpp 
clang/test/AST/ByteCode/nullable.cpp clang/test/AST/ByteCode/pointer-addition.c 
clang/test/AST/ByteCode/records.cpp clang/test/AST/ByteCode/references.cpp 
clang/test/AST/ByteCode/shifts.cpp clang/test/AST/ByteCode/spaceship.cpp 
clang/test/AST/ByteCode/switch.cpp clang/test/AST/ByteCode/sycl.cpp 
clang/test/AST/ByteCode/unions.cpp clang/test/AST/ByteCode/vectors.cpp 
clang/test/AST/ByteCode/weak.cpp clang/unittests/AST/ByteCode/Descriptor.cpp 
clang/unittests/AST/ByteCode/toAPValue.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index e92bd4ed80..f35a025fc8 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -

[clang] [Matrix] Preserve signedness when extending matrix index expression. (PR #103044)

2024-08-16 Thread Florian Hahn via cfe-commits


@@ -4348,8 +4348,18 @@ LValue CodeGenFunction::EmitMatrixSubscriptExpr(const 
MatrixSubscriptExpr *E) {
   !E->isIncomplete() &&
   "incomplete matrix subscript expressions should be rejected during 
Sema");
   LValue Base = EmitLValue(E->getBase());
-  llvm::Value *RowIdx = EmitScalarExpr(E->getRowIdx());
-  llvm::Value *ColIdx = EmitScalarExpr(E->getColumnIdx());
+
+  // Extend or truncate the index type to 32 or 64-bits.
+  auto EmitIndex = [this](const Expr *E) {

fhahn wrote:

> Can you just pull this out as a helper function on CGF and then call it in 
> both places?

Done, thanks

> It looks like EmitArraySubscriptExpr does something similar, but it wouldn't 
> be easy to share the logic because it also potentially emits a sanitizer 
> check. On the other hand, is that something we should also be doing here? I 
> assume this is UB if it's out-of-bounds. We always have static bounds on 
> matrix types, right?

yes we have static bounds, so it would probably make sense to extend to logic 
to also support sanitizer checks for matrix subscript expressions. But probably 
better done separately?

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


[clang] [llvm] [RISCV] Add Hazard3 CPU (PR #102452)

2024-08-16 Thread Luke Wren via cfe-commits

Wren6991 wrote:

I think we are really compressing a three-tuple of something like 
`--`. For a two-tuple I prefer `rp2350-hazard3` over 
`raspberrypi-rp2350` because:

* RP2350 is a SoC, not a CPU, so doesn't belong at the end of the tuple
* RP2350 also has Cortex-M33s, so leaving `hazard3` out of the tuple is 
slightly confusing
* Raspberry Pi is the vendor of RP2350 but not the designer of the core
* This is specifically for the as-taped-out RP2350 variant of Hazard3

I think `rp2350-hazard3` captures this nicely

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


[clang] [Clang] strengthen checks for 'main' function to meet [basic.start.main] p3 requirements (PR #101853)

2024-08-16 Thread Mital Ashok via cfe-commits

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


[clang] 61abc15 - [clang][NFC] Update `cxx_dr_status.html`

2024-08-16 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-08-16T12:19:27+03:00
New Revision: 61abc15a9f94b081cced18277de8ae571e4d853d

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

LOG: [clang][NFC] Update `cxx_dr_status.html`

Added: 


Modified: 
clang/www/cxx_dr_status.html

Removed: 




diff  --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 34ca6f76bb2ce6..c901e1ce0e15b3 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -7302,7 +7302,7 @@ C++ defect report implementation 
status
   
 https://cplusplus.github.io/CWG/issues/1248.html";>1248
 open
-Updating Annex C to C99
+Updating Annex C to C99 and C23
 Not resolved
   
   
@@ -17325,6 +17325,30 @@ C++ defect report implementation 
status
 open
 Consideration of constraints for address of overloaded function
 Not resolved
+  
+  
+https://cplusplus.github.io/CWG/issues/2919.html";>2919
+open
+Conversion function candidates for initialization of const lvalue 
reference
+Not resolved
+  
+  
+https://cplusplus.github.io/CWG/issues/2920.html";>2920
+open
+The template keyword for base classes
+Not resolved
+  
+  
+https://cplusplus.github.io/CWG/issues/2921.html";>2921
+open
+Exporting redeclarations of entities not attached to a named 
module
+Not resolved
+  
+  
+https://cplusplus.github.io/CWG/issues/2922.html";>2922
+open
+constexpr placement-new is too permissive
+Not resolved
   
 
 



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


[clang] [Clang] Check explicit object parameter for defaulted operators properly (PR #100419)

2024-08-16 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

@marco-antognini-sonarsource 
: It's before 
RC3 and this isn't a regression (this just never worked), and I don't think 
#100329 is a critical bug, so this probably shouldn't go in the 19.x branch. 
Especially considering this PR was opened after it branched off.


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


[clang] dc3b029 - [clang][Interp][NFC] Remove Function::Loc

2024-08-16 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-08-16T11:25:23+02:00
New Revision: dc3b029dc744730e69abac987c38b2d08b465fba

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

LOG: [clang][Interp][NFC] Remove Function::Loc

Unused.

Added: 


Modified: 
clang/lib/AST/Interp/Function.cpp
clang/lib/AST/Interp/Function.h

Removed: 




diff  --git a/clang/lib/AST/Interp/Function.cpp 
b/clang/lib/AST/Interp/Function.cpp
index 00f5a1fced531a..fc3345cbe123f8 100644
--- a/clang/lib/AST/Interp/Function.cpp
+++ b/clang/lib/AST/Interp/Function.cpp
@@ -21,10 +21,9 @@ Function::Function(Program &P, const FunctionDecl *F, 
unsigned ArgSize,
llvm::DenseMap &&Params,
llvm::SmallVectorImpl &&ParamOffsets,
bool HasThisPointer, bool HasRVO, bool UnevaluatedBuiltin)
-: P(P), Loc(F->getBeginLoc()), F(F), ArgSize(ArgSize),
-  ParamTypes(std::move(ParamTypes)), Params(std::move(Params)),
-  ParamOffsets(std::move(ParamOffsets)), HasThisPointer(HasThisPointer),
-  HasRVO(HasRVO), Variadic(F->isVariadic()),
+: P(P), F(F), ArgSize(ArgSize), ParamTypes(std::move(ParamTypes)),
+  Params(std::move(Params)), ParamOffsets(std::move(ParamOffsets)),
+  HasThisPointer(HasThisPointer), HasRVO(HasRVO), 
Variadic(F->isVariadic()),
   IsUnevaluatedBuiltin(UnevaluatedBuiltin) {}
 
 Function::ParamDescriptor Function::getParamDescriptor(unsigned Offset) const {

diff  --git a/clang/lib/AST/Interp/Function.h b/clang/lib/AST/Interp/Function.h
index 92bcd96927912d..625d5af0407a72 100644
--- a/clang/lib/AST/Interp/Function.h
+++ b/clang/lib/AST/Interp/Function.h
@@ -100,9 +100,6 @@ class Function final {
 return F->getQualifiedNameAsString();
   }
 
-  /// Returns the location.
-  SourceLocation getLoc() const { return Loc; }
-
   /// Returns a parameter descriptor.
   ParamDescriptor getParamDescriptor(unsigned Offset) const;
 
@@ -235,8 +232,6 @@ class Function final {
 
   /// Program reference.
   Program &P;
-  /// Location of the executed code.
-  SourceLocation Loc;
   /// Declaration this function was compiled from.
   const FunctionDecl *F;
   /// Local area size: storage + metadata.



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


[clang] [Clang] strengthen checks for 'main' function to meet [basic.start.main] p3 requirements (PR #101853)

2024-08-16 Thread Alexander Kornienko via cfe-commits


@@ -12210,7 +12220,18 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
   return Redeclaration;
 }
 
-void Sema::CheckMain(FunctionDecl* FD, const DeclSpec& DS) {
+void Sema::CheckMain(FunctionDecl *FD, const DeclSpec &DS) {
+  // [basic.start.main]p3
+  //The main function shall not be declared with a linkage-specification.
+  if (FD->isExternCContext() ||
+  (FD->isExternCXXContext() &&
+   FD->getDeclContext()->getRedeclContext()->isTranslationUnit())) {
+Diag(FD->getLocation(), diag::ext_main_invalid_linkage_specification)
+<< FD->getLanguageLinkage();
+FD->setInvalidDecl();
+return;

alexfh wrote:

Filed https://github.com/llvm/llvm-project/issues/104570

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


[clang] [clang] Add a new test for CWG2091 (PR #104573)

2024-08-16 Thread Vlad Serebrennikov via cfe-commits

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

This patch adds a test from https://github.com/llvm/llvm-project/issues/42233, 
and updated CWG2091 status from `2.7` to `10`.

>From 80e7ad78ba1c1f213ab514edfb81ced1c8363606 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Fri, 16 Aug 2024 12:33:04 +0300
Subject: [PATCH] [clang] Add a new test for CWG2091

---
 clang/test/CXX/drs/cwg20xx.cpp | 25 -
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/clang/test/CXX/drs/cwg20xx.cpp b/clang/test/CXX/drs/cwg20xx.cpp
index cd2f26360d4021..7509d83e3dea63 100644
--- a/clang/test/CXX/drs/cwg20xx.cpp
+++ b/clang/test/CXX/drs/cwg20xx.cpp
@@ -401,11 +401,34 @@ namespace cwg2083 { // cwg2083: partial
 #endif
 }
 
-namespace cwg2091 { // cwg2091: 2.7
+namespace cwg2091 { // cwg2091: 10
 template struct X;
 template void f(X&);
 int n;
 void g(X &x) { f(x); }
+
+namespace GH42233 {
+enum E { I };
+
+class AA { };
+E EV[1] = {I};
+
+template
+struct S
+{
+   template< class E, const E* const V>
+   friend AA& operator<<( AA& os, const S& e );
+};
+
+int f()
+{
+   S< E, EV > x;
+
+   AA a;
+   a << x;
+   return 0;
+}
+} // namespace GH42233
 } // namespace cwg2091 
 
 namespace cwg2094 { // cwg2094: 5

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


[clang] [clang] Add a new test for CWG2091 (PR #104573)

2024-08-16 Thread Vlad Serebrennikov via cfe-commits

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

>From 80e7ad78ba1c1f213ab514edfb81ced1c8363606 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Fri, 16 Aug 2024 12:33:04 +0300
Subject: [PATCH 1/2] [clang] Add a new test for CWG2091

---
 clang/test/CXX/drs/cwg20xx.cpp | 25 -
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/clang/test/CXX/drs/cwg20xx.cpp b/clang/test/CXX/drs/cwg20xx.cpp
index cd2f26360d4021..7509d83e3dea63 100644
--- a/clang/test/CXX/drs/cwg20xx.cpp
+++ b/clang/test/CXX/drs/cwg20xx.cpp
@@ -401,11 +401,34 @@ namespace cwg2083 { // cwg2083: partial
 #endif
 }
 
-namespace cwg2091 { // cwg2091: 2.7
+namespace cwg2091 { // cwg2091: 10
 template struct X;
 template void f(X&);
 int n;
 void g(X &x) { f(x); }
+
+namespace GH42233 {
+enum E { I };
+
+class AA { };
+E EV[1] = {I};
+
+template
+struct S
+{
+   template< class E, const E* const V>
+   friend AA& operator<<( AA& os, const S& e );
+};
+
+int f()
+{
+   S< E, EV > x;
+
+   AA a;
+   a << x;
+   return 0;
+}
+} // namespace GH42233
 } // namespace cwg2091 
 
 namespace cwg2094 { // cwg2094: 5

>From d9fba44f81807e90d56e48423817bc85f5c99bf3 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Fri, 16 Aug 2024 12:34:59 +0300
Subject: [PATCH 2/2] Update `cxx_dr_status.html`

---
 clang/www/cxx_dr_status.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index c901e1ce0e15b3..23657431233860 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -12361,7 +12361,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2091.html";>2091
 CD4
 Deducing reference non-type template arguments
-Clang 2.7
+Clang 10
   
   
 https://cplusplus.github.io/CWG/issues/2092.html";>2092

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


[clang] [clang] Add a new test for CWG2091 (PR #104573)

2024-08-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vlad Serebrennikov (Endilll)


Changes

This patch adds a test from https://github.com/llvm/llvm-project/issues/42233, 
and updated CWG2091 status from `2.7` to `10`.

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


2 Files Affected:

- (modified) clang/test/CXX/drs/cwg20xx.cpp (+24-1) 
- (modified) clang/www/cxx_dr_status.html (+1-1) 


``diff
diff --git a/clang/test/CXX/drs/cwg20xx.cpp b/clang/test/CXX/drs/cwg20xx.cpp
index cd2f26360d4021..7509d83e3dea63 100644
--- a/clang/test/CXX/drs/cwg20xx.cpp
+++ b/clang/test/CXX/drs/cwg20xx.cpp
@@ -401,11 +401,34 @@ namespace cwg2083 { // cwg2083: partial
 #endif
 }
 
-namespace cwg2091 { // cwg2091: 2.7
+namespace cwg2091 { // cwg2091: 10
 template struct X;
 template void f(X&);
 int n;
 void g(X &x) { f(x); }
+
+namespace GH42233 {
+enum E { I };
+
+class AA { };
+E EV[1] = {I};
+
+template
+struct S
+{
+   template< class E, const E* const V>
+   friend AA& operator<<( AA& os, const S& e );
+};
+
+int f()
+{
+   S< E, EV > x;
+
+   AA a;
+   a << x;
+   return 0;
+}
+} // namespace GH42233
 } // namespace cwg2091 
 
 namespace cwg2094 { // cwg2094: 5
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index c901e1ce0e15b3..23657431233860 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -12361,7 +12361,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2091.html";>2091
 CD4
 Deducing reference non-type template arguments
-Clang 2.7
+Clang 10
   
   
 https://cplusplus.github.io/CWG/issues/2092.html";>2092

``




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


[clang] [clang] Add a new test for CWG2091 (PR #104573)

2024-08-16 Thread Vlad Serebrennikov via cfe-commits

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

>From 80e7ad78ba1c1f213ab514edfb81ced1c8363606 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Fri, 16 Aug 2024 12:33:04 +0300
Subject: [PATCH 1/3] [clang] Add a new test for CWG2091

---
 clang/test/CXX/drs/cwg20xx.cpp | 25 -
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/clang/test/CXX/drs/cwg20xx.cpp b/clang/test/CXX/drs/cwg20xx.cpp
index cd2f26360d4021..7509d83e3dea63 100644
--- a/clang/test/CXX/drs/cwg20xx.cpp
+++ b/clang/test/CXX/drs/cwg20xx.cpp
@@ -401,11 +401,34 @@ namespace cwg2083 { // cwg2083: partial
 #endif
 }
 
-namespace cwg2091 { // cwg2091: 2.7
+namespace cwg2091 { // cwg2091: 10
 template struct X;
 template void f(X&);
 int n;
 void g(X &x) { f(x); }
+
+namespace GH42233 {
+enum E { I };
+
+class AA { };
+E EV[1] = {I};
+
+template
+struct S
+{
+   template< class E, const E* const V>
+   friend AA& operator<<( AA& os, const S& e );
+};
+
+int f()
+{
+   S< E, EV > x;
+
+   AA a;
+   a << x;
+   return 0;
+}
+} // namespace GH42233
 } // namespace cwg2091 
 
 namespace cwg2094 { // cwg2094: 5

>From d9fba44f81807e90d56e48423817bc85f5c99bf3 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Fri, 16 Aug 2024 12:34:59 +0300
Subject: [PATCH 2/3] Update `cxx_dr_status.html`

---
 clang/www/cxx_dr_status.html | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index c901e1ce0e15b3..23657431233860 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -12361,7 +12361,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2091.html";>2091
 CD4
 Deducing reference non-type template arguments
-Clang 2.7
+Clang 10
   
   
 https://cplusplus.github.io/CWG/issues/2092.html";>2092

>From 4944abbd7b0d4fee8886161895b630b47d6ac0b4 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Fri, 16 Aug 2024 12:36:14 +0300
Subject: [PATCH 3/3] Replace tabs with spaces

---
 clang/test/CXX/drs/cwg20xx.cpp | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/clang/test/CXX/drs/cwg20xx.cpp b/clang/test/CXX/drs/cwg20xx.cpp
index 7509d83e3dea63..b2dc5a9865e382 100644
--- a/clang/test/CXX/drs/cwg20xx.cpp
+++ b/clang/test/CXX/drs/cwg20xx.cpp
@@ -416,17 +416,17 @@ E EV[1] = {I};
 template
 struct S
 {
-   template< class E, const E* const V>
-   friend AA& operator<<( AA& os, const S& e );
+  template< class E, const E* const V>
+friend AA& operator<<( AA& os, const S& e );
 };
 
 int f()
 {
-   S< E, EV > x;
+  S< E, EV > x;
 
-   AA a;
-   a << x;
-   return 0;
+  AA a;
+  a << x;
+  return 0;
 }
 } // namespace GH42233
 } // namespace cwg2091 

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


[clang] [clang][Interp] Support ObjC blocks (PR #104551)

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

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

>From fdf77974e37a8b38d2ab3e184371417fdec1e952 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Thu, 15 Aug 2024 20:31:38 +0200
Subject: [PATCH] [clang][Interp] Support blocks

---
 clang/lib/AST/Interp/ByteCodeEmitter.cpp | 42 
 clang/lib/AST/Interp/ByteCodeEmitter.h   |  1 +
 clang/lib/AST/Interp/Compiler.cpp| 15 ++--
 clang/lib/AST/Interp/Compiler.h  |  1 +
 clang/lib/AST/Interp/Context.cpp |  2 +-
 clang/lib/AST/Interp/Function.cpp| 14 ---
 clang/lib/AST/Interp/Function.h  | 49 +---
 clang/lib/AST/Interp/FunctionPointer.h   |  5 ++-
 clang/lib/AST/Interp/Interp.h|  2 +-
 clang/test/Sema/block-misc.c |  1 +
 clang/test/Sema/block-return.c   |  1 +
 clang/test/SemaCXX/consteval-cleanup.cpp |  1 +
 12 files changed, 109 insertions(+), 25 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp 
b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index a01fa15dc0b7dc..9aec46767eb822 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -195,6 +195,48 @@ Function *ByteCodeEmitter::compileFunc(const FunctionDecl 
*FuncDecl) {
   return Func;
 }
 
+/// Compile an ObjC block, i.e. ^(){}, that thing.
+///
+/// We do not support calling the block though, so we create a function
+/// here but do not compile any code for it.
+Function *ByteCodeEmitter::compileObjCBlock(const BlockExpr *BE) {
+  const BlockDecl *BD = BE->getBlockDecl();
+  // Set up argument indices.
+  unsigned ParamOffset = 0;
+  SmallVector ParamTypes;
+  SmallVector ParamOffsets;
+  llvm::DenseMap ParamDescriptors;
+
+  // Assign descriptors to all parameters.
+  // Composite objects are lowered to pointers.
+  for (const ParmVarDecl *PD : BD->parameters()) {
+std::optional T = Ctx.classify(PD->getType());
+PrimType PT = T.value_or(PT_Ptr);
+Descriptor *Desc = P.createDescriptor(PD, PT);
+ParamDescriptors.insert({ParamOffset, {PT, Desc}});
+Params.insert({PD, {ParamOffset, T != std::nullopt}});
+ParamOffsets.push_back(ParamOffset);
+ParamOffset += align(primSize(PT));
+ParamTypes.push_back(PT);
+  }
+
+  if (BD->hasCaptures())
+return nullptr;
+
+  // Create a handle over the emitted code.
+  Function *Func =
+  P.createFunction(BE, ParamOffset, std::move(ParamTypes),
+   std::move(ParamDescriptors), std::move(ParamOffsets),
+   /*HasThisPointer=*/false, /*HasRVO=*/false,
+   /*IsUnevaluatedBuiltin=*/false);
+
+  assert(Func);
+  Func->setDefined(true);
+  // We don't compile the BlockDecl code at all right now.
+  Func->setIsFullyCompiled(true);
+  return Func;
+}
+
 Scope::Local ByteCodeEmitter::createLocal(Descriptor *D) {
   NextLocalOffset += sizeof(Block);
   unsigned Location = NextLocalOffset;
diff --git a/clang/lib/AST/Interp/ByteCodeEmitter.h 
b/clang/lib/AST/Interp/ByteCodeEmitter.h
index a19a25c2f9e8ec..915960cb515ce6 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.h
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.h
@@ -32,6 +32,7 @@ class ByteCodeEmitter {
 public:
   /// Compiles the function into the module.
   Function *compileFunc(const FunctionDecl *FuncDecl);
+  Function *compileObjCBlock(const BlockExpr *BE);
 
 protected:
   ByteCodeEmitter(Context &Ctx, Program &P) : Ctx(Ctx), P(P) {}
diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index 5e1f507ca2b178..ece4b039df8e54 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -389,8 +389,6 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
   return this->emitPop(T, CE);
 
 QualType PtrType = CE->getType();
-assert(PtrType->isPointerType());
-
 const Descriptor *Desc;
 if (std::optional T = classify(PtrType->getPointeeType()))
   Desc = P.createDescriptor(SubExpr, *T);
@@ -2240,8 +2238,6 @@ bool Compiler::VisitExprWithCleanups(const 
ExprWithCleanups *E) {
   LocalScope ES(this);
   const Expr *SubExpr = E->getSubExpr();
 
-  assert(E->getNumObjects() == 0 && "TODO: Implement cleanups");
-
   return this->delegate(SubExpr) && ES.destroyLocals(E);
 }
 
@@ -2911,6 +2907,17 @@ bool Compiler::VisitCXXDeleteExpr(const 
CXXDeleteExpr *E) {
   return this->emitFree(E->isArrayForm(), E);
 }
 
+template 
+bool Compiler::VisitBlockExpr(const BlockExpr *E) {
+  const Function *Func = nullptr;
+  if (auto F = Compiler(Ctx, P).compileObjCBlock(E))
+Func = F;
+
+  if (!Func)
+return false;
+  return this->emitGetFnPtr(Func, E);
+}
+
 template 
 bool Compiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *E) 
{
   assert(Ctx.getLangOpts().CPlusPlus);
diff --git a/clang/lib/AST/Interp/Compiler.h b/clang/lib/AST/Interp/Compiler.h
index 74bfce5f241f28..5acfe3c41796c4 100644
--- a/clang/lib/AST/Interp/Compiler.h
+++ 

[clang] [compiler-rt] [ubsan] Display correct runtime messages for negative _BitInt (PR #96240)

2024-08-16 Thread Nikita Popov via cfe-commits

nikic wrote:

The clang test also fails on s390x (big endian):
```
RUN: at line 2: 
/builddir/build/BUILD/llvm-project-ec29660c44e5e73d3b78f4884f9178036563fb25/llvm/s390x-redhat-linux-gnu/bin/clang
 -cc1 -internal-isystem 
/builddir/build/BUILD/llvm-project-ec29660c44e5e73d3b78f4884f9178036563fb25/llvm/s390x-redhat-linux-gnu/bin/../lib/clang/20/include
 -nostdsysteminc -Wno-constant-conversion -Wno-array-bounds 
-Wno-division-by-zero -Wno-shift-negative-value -Wno-shift-count-negative 
-Wno-int-to-pointer-cast 
-fsanitize=array-bounds,enum,float-cast-overflow,integer-divide-by-zero,implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change,unsigned-integer-overflow,signed-integer-overflow,shift-base,shift-exponent
 -O0 -emit-llvm -o - 
/builddir/build/BUILD/llvm-project-ec29660c44e5e73d3b78f4884f9178036563fb25/clang/test/CodeGen/bit-int-ubsan.c
 | 
/builddir/build/BUILD/llvm-project-ec29660c44e5e73d3b78f4884f9178036563fb25/llvm/s390x-redhat-linux-gnu/bin/FileCheck
 
/builddir/build/BUILD/llvm-project-ec29660c44e5e73d3b78f4884f9178036563fb25/clang/test/CodeGen/bit-int-ubsan.c
+ 
/builddir/build/BUILD/llvm-project-ec29660c44e5e73d3b78f4884f9178036563fb25/llvm/s390x-redhat-linux-gnu/bin/clang
 -cc1 -internal-isystem 
/builddir/build/BUILD/llvm-project-ec29660c44e5e73d3b78f4884f9178036563fb25/llvm/s390x-redhat-linux-gnu/bin/../lib/clang/20/include
 -nostdsysteminc -Wno-constant-conversion -Wno-array-bounds 
-Wno-division-by-zero -Wno-shift-negative-value -Wno-shift-count-negative 
-Wno-int-to-pointer-cast 
-fsanitize=array-bounds,enum,float-cast-overflow,integer-divide-by-zero,implicit-unsigned-integer-truncation,implicit-signed-integer-truncation,implicit-integer-sign-change,unsigned-integer-overflow,signed-integer-overflow,shift-base,shift-exponent
 -O0 -emit-llvm -o - 
/builddir/build/BUILD/llvm-project-ec29660c44e5e73d3b78f4884f9178036563fb25/clang/test/CodeGen/bit-int-ubsan.c
+ 
/builddir/build/BUILD/llvm-project-ec29660c44e5e73d3b78f4884f9178036563fb25/llvm/s390x-redhat-linux-gnu/bin/FileCheck
 
/builddir/build/BUILD/llvm-project-ec29660c44e5e73d3b78f4884f9178036563fb25/clang/test/CodeGen/bit-int-ubsan.c
/builddir/build/BUILD/llvm-project-ec29660c44e5e73d3b78f4884f9178036563fb25/clang/test/CodeGen/bit-int-ubsan.c:11:12:
 error: CHECK: expected string not found in input
 // CHECK: constant { i16, i16, [20 x i8] } { i16 2, i16 13, [20 x i8] 
c"'_BitInt(37)'\00%\00\00\00\00\00" }
   ^
:7:100: note: scanning from here
@0 = private unnamed_addr constant { i16, i16, [8 x i8] } { i16 1, i16 32, [8 x 
i8] c"'float'\00" }

   ^
:8:27: note: possible intended match here
@1 = private unnamed_addr constant { i16, i16, [20 x i8] } { i16 2, i16 13, [20 
x i8] c"'_BitInt(37)'\00\00\00\00%\00\00" }
  ^

Input file: 
Check file: 
/builddir/build/BUILD/llvm-project-ec29660c44e5e73d3b78f4884f9178036563fb25/clang/test/CodeGen/bit-int-ubsan.c

-dump-input=help explains the following input dump.

Input was:
<<
1: ; ModuleID = 
'/builddir/build/BUILD/llvm-project-ec29660c44e5e73d3b78f4884f9178036563fb25/clang/test/CodeGen/bit-int-ubsan.c'
 
2: source_filename = 
"/builddir/build/BUILD/llvm-project-ec29660c44e5e73d3b78f4884f9178036563fb25/clang/test/CodeGen/bit-int-ubsan.c"
 
3: target datalayout = 
"E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64" 
4: target triple = "s390x-redhat-linux-gnu" 
5:  
6: @.src = private unnamed_addr constant [111 x i8] 
c"/builddir/build/BUILD/llvm-project-ec29660c44e5e73d3b78f4884f9178036563fb25/clang/test/CodeGen/bit-int-ubsan.c\00",
 align 2 
7: @0 = private unnamed_addr constant { i16, i16, [8 x i8] } { i16 
1, i16 32, [8 x i8] c"'float'\00" } 
check:11'0  
  X error: no match found
8: @1 = private unnamed_addr constant { i16, i16, [20 x i8] } { i16 
2, i16 13, [20 x i8] c"'_BitInt(37)'\00\00\00\00%\00\00" } 
check:11'0 

check:11'1   ?  
possible intended 
match
9: @2 = private unnamed_addr global { { ptr, i32, i32 }, ptr, ptr } 
{ { ptr, i32, i32 } { ptr @.src, i32 10, i32 19 }, ptr @0, ptr @1 } 
check:11'0 
~
   10: @3 = private unnamed_addr constant { i16, i16, [32 x i8] } { i16 
0, i16 10, [32 x i8] c"'uint32_t' (aka 'unsigned int')\00" } 
check:11'0 
~~~

[clang] [clang][ASTImporter] New fix for default template parameter values. (PR #101836)

2024-08-16 Thread Donát Nagy via cfe-commits

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

Feel free to merge this if you're not planning more changes.

The commit seems to be reasonable, I like that your comments explain the logic 
behind this very technical logic. I don't understand enough to recognize an 
unhandled corner case (if there was one), but I'm confident that this change is 
a good step forward.

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


[clang] [llvm] [HLSL][DXIL][SPIRV] Create llvm dot intrinsic and use for HLSL (PR #102872)

2024-08-16 Thread Greg Roth via cfe-commits

https://github.com/pow2clk updated 
https://github.com/llvm/llvm-project/pull/102872

>From 6fde4bc98d0156024cf7acc27e2e986b9bec3993 Mon Sep 17 00:00:00 2001
From: Greg Roth 
Date: Fri, 2 Aug 2024 20:10:04 -0600
Subject: [PATCH 1/6] Create llvm dot intrinsic

Per https://discourse.llvm.org/t/rfc-all-the-math-intrinsics/78294
`dot` should be an LLVM intrinsic. This adds the llvm intrinsics
and updates HLSL builtin codegen to emit them.

Removed some stale comments that gave the obsolete impression that
type conversions should be expected to match overloads.

With dot moving into an LLVM intrinsic, the lowering to dx-specific
operations doesn't take place until DXIL intrinsic expansion. This
moves the introduction of arity-specific DX opcodes to DXIL
intrinsic expansion.

Part of #88056
---
 clang/lib/CodeGen/CGBuiltin.cpp   |  47 +++--
 .../CodeGenHLSL/builtins/dot-builtin.hlsl |  12 +-
 clang/test/CodeGenHLSL/builtins/dot.hlsl  | 160 +-
 llvm/include/llvm/IR/Intrinsics.td|   9 +
 .../Target/DirectX/DXILIntrinsicExpansion.cpp |  61 +--
 5 files changed, 159 insertions(+), 130 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 7fe80b0cbdfbfa..67148e32014ed2 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18470,22 +18470,14 @@ llvm::Value 
*CodeGenFunction::EmitScalarOrConstFoldImmArg(unsigned ICEArguments,
   return Arg;
 }
 
-Intrinsic::ID getDotProductIntrinsic(QualType QT, int elementCount) {
-  if (QT->hasFloatingRepresentation()) {
-switch (elementCount) {
-case 2:
-  return Intrinsic::dx_dot2;
-case 3:
-  return Intrinsic::dx_dot3;
-case 4:
-  return Intrinsic::dx_dot4;
-}
-  }
-  if (QT->hasSignedIntegerRepresentation())
-return Intrinsic::dx_sdot;
-
-  assert(QT->hasUnsignedIntegerRepresentation());
-  return Intrinsic::dx_udot;
+// Return dot product intrinsic that corresponds to the QT scalar type
+Intrinsic::ID getDotProductIntrinsic(QualType QT) {
+  if (QT->isFloatingType())
+return Intrinsic::fdot;
+  if (QT->isSignedIntegerType())
+return Intrinsic::sdot;
+  assert(QT->isUnsignedIntegerType());
+  return Intrinsic::udot;
 }
 
 Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
@@ -18528,37 +18520,38 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 Value *Op1 = EmitScalarExpr(E->getArg(1));
 llvm::Type *T0 = Op0->getType();
 llvm::Type *T1 = Op1->getType();
+
+// If the arguments are scalars, just emit a multiply
 if (!T0->isVectorTy() && !T1->isVectorTy()) {
   if (T0->isFloatingPointTy())
-return Builder.CreateFMul(Op0, Op1, "dx.dot");
+return Builder.CreateFMul(Op0, Op1, "dot");
 
   if (T0->isIntegerTy())
-return Builder.CreateMul(Op0, Op1, "dx.dot");
+return Builder.CreateMul(Op0, Op1, "dot");
 
-  // Bools should have been promoted
   llvm_unreachable(
   "Scalar dot product is only supported on ints and floats.");
 }
+// For vectors, validate types and emit the appropriate intrinsic
+
 // A VectorSplat should have happened
 assert(T0->isVectorTy() && T1->isVectorTy() &&
"Dot product of vector and scalar is not supported.");
 
-// A vector sext or sitofp should have happened
-assert(T0->getScalarType() == T1->getScalarType() &&
-   "Dot product of vectors need the same element types.");
-
 auto *VecTy0 = E->getArg(0)->getType()->getAs();
 [[maybe_unused]] auto *VecTy1 =
 E->getArg(1)->getType()->getAs();
-// A HLSLVectorTruncation should have happend
+
+assert(VecTy0->getElementType() == VecTy1->getElementType() &&
+   "Dot product of vectors need the same element types.");
+
 assert(VecTy0->getNumElements() == VecTy1->getNumElements() &&
"Dot product requires vectors to be of the same size.");
 
 return Builder.CreateIntrinsic(
 /*ReturnType=*/T0->getScalarType(),
-getDotProductIntrinsic(E->getArg(0)->getType(),
-   VecTy0->getNumElements()),
-ArrayRef{Op0, Op1}, nullptr, "dx.dot");
+getDotProductIntrinsic(VecTy0->getElementType()),
+ArrayRef{Op0, Op1}, nullptr, "dot");
   } break;
   case Builtin::BI__builtin_hlsl_lerp: {
 Value *X = EmitScalarExpr(E->getArg(0));
diff --git a/clang/test/CodeGenHLSL/builtins/dot-builtin.hlsl 
b/clang/test/CodeGenHLSL/builtins/dot-builtin.hlsl
index b0b95074c972d5..6036f9430db4f0 100644
--- a/clang/test/CodeGenHLSL/builtins/dot-builtin.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/dot-builtin.hlsl
@@ -2,8 +2,8 @@
 
 // CHECK-LABEL: builtin_bool_to_float_type_promotion
 // CHECK: %conv1 = uitofp i1 %loadedv to double
-// CHECK: %dx.dot = fmul double %conv, %conv1
-// CHECK: %conv2 = fptrunc double %dx.dot to float
+// CHECK: %dot = fmul double %conv, %conv1
+// CHECK: %conv2 = fptrunc double %dot to float
 

[clang] [clang] Rename all AST/Interp stuff to AST/ByteCode (PR #104552)

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

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

>From 42c79911d0138d45c425e42cc19bef5e84a67e84 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 16 Aug 2024 08:42:16 +0200
Subject: [PATCH] [clang] Rename all AST/Interp stuff to AST/ByteCode

"Interp" clashes with the clang interpreter and people often confuse
this.
---
 clang/docs/ClangFormattedStatus.rst   |  2 +-
 clang/docs/tools/clang-formatted-files.txt| 36 ++--
 clang/lib/AST/ASTContext.cpp  |  2 +-
 clang/lib/AST/{Interp => ByteCode}/Boolean.h  | 15 +++--
 .../{Interp => ByteCode}/ByteCodeEmitter.cpp  |  9 ++-
 .../{Interp => ByteCode}/ByteCodeEmitter.h|  2 +-
 .../lib/AST/{Interp => ByteCode}/Compiler.cpp |  5 +-
 clang/lib/AST/{Interp => ByteCode}/Compiler.h |  0
 .../lib/AST/{Interp => ByteCode}/Context.cpp  |  0
 clang/lib/AST/{Interp => ByteCode}/Context.h  |  0
 .../AST/{Interp => ByteCode}/Descriptor.cpp   |  0
 .../lib/AST/{Interp => ByteCode}/Descriptor.h |  2 +-
 clang/lib/AST/{Interp => ByteCode}/Disasm.cpp |  0
 .../{Interp => ByteCode}/DynamicAllocator.cpp |  0
 .../{Interp => ByteCode}/DynamicAllocator.h   |  0
 .../AST/{Interp => ByteCode}/EvalEmitter.cpp  |  4 +-
 .../AST/{Interp => ByteCode}/EvalEmitter.h|  0
 .../{Interp => ByteCode}/EvaluationResult.cpp |  0
 .../{Interp => ByteCode}/EvaluationResult.h   |  0
 .../lib/AST/{Interp => ByteCode}/Floating.cpp |  0
 clang/lib/AST/{Interp => ByteCode}/Floating.h |  0
 clang/lib/AST/{Interp => ByteCode}/Frame.cpp  |  0
 clang/lib/AST/{Interp => ByteCode}/Frame.h|  0
 .../lib/AST/{Interp => ByteCode}/Function.cpp |  0
 clang/lib/AST/{Interp => ByteCode}/Function.h |  0
 .../{Interp => ByteCode}/FunctionPointer.h|  0
 clang/lib/AST/{Interp => ByteCode}/Integral.h | 42 +-
 .../lib/AST/{Interp => ByteCode}/IntegralAP.h |  0
 clang/lib/AST/{Interp => ByteCode}/Interp.cpp |  0
 clang/lib/AST/{Interp => ByteCode}/Interp.h   | 15 ++---
 .../AST/{Interp => ByteCode}/InterpBlock.cpp  |  0
 .../AST/{Interp => ByteCode}/InterpBlock.h|  2 +-
 .../{Interp => ByteCode}/InterpBuiltin.cpp|  0
 .../AST/{Interp => ByteCode}/InterpFrame.cpp  |  2 +-
 .../AST/{Interp => ByteCode}/InterpFrame.h|  2 +-
 .../AST/{Interp => ByteCode}/InterpShared.cpp |  0
 .../AST/{Interp => ByteCode}/InterpShared.h   |  0
 .../AST/{Interp => ByteCode}/InterpStack.cpp  |  4 +-
 .../AST/{Interp => ByteCode}/InterpStack.h|  5 +-
 .../AST/{Interp => ByteCode}/InterpState.cpp  |  0
 .../AST/{Interp => ByteCode}/InterpState.h|  0
 .../{Interp => ByteCode}/MemberPointer.cpp|  0
 .../AST/{Interp => ByteCode}/MemberPointer.h  |  0
 clang/lib/AST/{Interp => ByteCode}/Opcode.h   |  0
 clang/lib/AST/{Interp => ByteCode}/Opcodes.td |  0
 .../lib/AST/{Interp => ByteCode}/Pointer.cpp  |  0
 clang/lib/AST/{Interp => ByteCode}/Pointer.h  |  2 +-
 .../lib/AST/{Interp => ByteCode}/PrimType.cpp |  0
 clang/lib/AST/{Interp => ByteCode}/PrimType.h | 57 ++-
 .../lib/AST/{Interp => ByteCode}/Primitives.h |  0
 .../lib/AST/{Interp => ByteCode}/Program.cpp  | 43 +++---
 clang/lib/AST/{Interp => ByteCode}/Program.h  | 16 ++
 clang/lib/AST/{Interp => ByteCode}/Record.cpp |  2 +-
 clang/lib/AST/{Interp => ByteCode}/Record.h   |  0
 clang/lib/AST/{Interp => ByteCode}/Source.cpp |  0
 clang/lib/AST/{Interp => ByteCode}/Source.h   |  0
 clang/lib/AST/{Interp => ByteCode}/State.cpp  |  0
 clang/lib/AST/{Interp => ByteCode}/State.h|  0
 clang/lib/AST/CMakeLists.txt  | 52 -
 clang/lib/AST/ExprConstShared.h   |  2 +-
 clang/lib/AST/ExprConstant.cpp|  6 +-
 .../test/AST/{Interp => ByteCode}/arrays.cpp  |  0
 clang/test/AST/{Interp => ByteCode}/atomic.c  |  0
 .../test/AST/{Interp => ByteCode}/atomic.cpp  |  0
 .../AST/{Interp => ByteCode}/bitfields.cpp|  0
 .../builtin-align-cxx.cpp |  0
 .../builtin-constant-p.cpp|  0
 .../builtin-functions.cpp |  0
 .../AST/{Interp => ByteCode}/builtins.cpp |  0
 clang/test/AST/{Interp => ByteCode}/c.c   |  0
 clang/test/AST/{Interp => ByteCode}/c23.c |  0
 .../test/AST/{Interp => ByteCode}/codegen.cpp |  0
 clang/test/AST/{Interp => ByteCode}/comma.cpp |  0
 clang/test/AST/{Interp => ByteCode}/complex.c |  0
 .../test/AST/{Interp => ByteCode}/complex.cpp |  0
 clang/test/AST/{Interp => ByteCode}/cond.cpp  |  0
 .../AST/{Interp => ByteCode}/const-eval.c |  0
 .../{Interp => ByteCode}/const-fpfeatures.cpp |  0
 .../const-temporaries.cpp |  0
 .../constexpr-frame-describe.cpp  |  0
 .../constexpr-nqueens.cpp |  0
 .../constexpr-subobj-initialization.cpp   |  0
 .../{Interp => ByteCode}/crash-GH49103-2.cpp  |  0
 clang/test/AST/{Interp => ByteCode}/cxx03.cpp |  0
 clang/test/AST/{Interp => ByteCode}/cxx11.cpp |  0
 clang/test/AST/{Interp => ByteCode}/cxx17.cpp

[clang] [Clang] Check explicit object parameter for defaulted operators properly (PR #100419)

2024-08-16 Thread Marco Borgeaud via cfe-commits

marco-antognini-sonarsource wrote:

@MitalAshok, I see -- that's fair enough. Thanks for digging up the process.

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


[clang] [clang] Rename all AST/Interp stuff to AST/ByteCode (PR #104552)

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

tbaederr wrote:

Code formatting is clean locally :shrug: 

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


[clang] [clang][Interp] Support ObjC blocks (PR #104551)

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

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

>From 24a00c98538038c5fd7f01789b8b819c3c562a46 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Thu, 15 Aug 2024 20:31:38 +0200
Subject: [PATCH] [clang][Interp] Support blocks

---
 clang/lib/AST/Interp/ByteCodeEmitter.cpp | 42 
 clang/lib/AST/Interp/ByteCodeEmitter.h   |  1 +
 clang/lib/AST/Interp/Compiler.cpp| 15 ++--
 clang/lib/AST/Interp/Compiler.h  |  1 +
 clang/lib/AST/Interp/Context.cpp |  2 +-
 clang/lib/AST/Interp/Function.cpp| 14 ---
 clang/lib/AST/Interp/Function.h  | 49 +---
 clang/lib/AST/Interp/FunctionPointer.h   |  7 +++-
 clang/lib/AST/Interp/Interp.h|  2 +-
 clang/test/Sema/block-misc.c |  1 +
 clang/test/Sema/block-return.c   |  1 +
 clang/test/SemaCXX/consteval-cleanup.cpp |  1 +
 12 files changed, 110 insertions(+), 26 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp 
b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index a01fa15dc0b7dc..9aec46767eb822 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -195,6 +195,48 @@ Function *ByteCodeEmitter::compileFunc(const FunctionDecl 
*FuncDecl) {
   return Func;
 }
 
+/// Compile an ObjC block, i.e. ^(){}, that thing.
+///
+/// We do not support calling the block though, so we create a function
+/// here but do not compile any code for it.
+Function *ByteCodeEmitter::compileObjCBlock(const BlockExpr *BE) {
+  const BlockDecl *BD = BE->getBlockDecl();
+  // Set up argument indices.
+  unsigned ParamOffset = 0;
+  SmallVector ParamTypes;
+  SmallVector ParamOffsets;
+  llvm::DenseMap ParamDescriptors;
+
+  // Assign descriptors to all parameters.
+  // Composite objects are lowered to pointers.
+  for (const ParmVarDecl *PD : BD->parameters()) {
+std::optional T = Ctx.classify(PD->getType());
+PrimType PT = T.value_or(PT_Ptr);
+Descriptor *Desc = P.createDescriptor(PD, PT);
+ParamDescriptors.insert({ParamOffset, {PT, Desc}});
+Params.insert({PD, {ParamOffset, T != std::nullopt}});
+ParamOffsets.push_back(ParamOffset);
+ParamOffset += align(primSize(PT));
+ParamTypes.push_back(PT);
+  }
+
+  if (BD->hasCaptures())
+return nullptr;
+
+  // Create a handle over the emitted code.
+  Function *Func =
+  P.createFunction(BE, ParamOffset, std::move(ParamTypes),
+   std::move(ParamDescriptors), std::move(ParamOffsets),
+   /*HasThisPointer=*/false, /*HasRVO=*/false,
+   /*IsUnevaluatedBuiltin=*/false);
+
+  assert(Func);
+  Func->setDefined(true);
+  // We don't compile the BlockDecl code at all right now.
+  Func->setIsFullyCompiled(true);
+  return Func;
+}
+
 Scope::Local ByteCodeEmitter::createLocal(Descriptor *D) {
   NextLocalOffset += sizeof(Block);
   unsigned Location = NextLocalOffset;
diff --git a/clang/lib/AST/Interp/ByteCodeEmitter.h 
b/clang/lib/AST/Interp/ByteCodeEmitter.h
index a19a25c2f9e8ec..915960cb515ce6 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.h
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.h
@@ -32,6 +32,7 @@ class ByteCodeEmitter {
 public:
   /// Compiles the function into the module.
   Function *compileFunc(const FunctionDecl *FuncDecl);
+  Function *compileObjCBlock(const BlockExpr *BE);
 
 protected:
   ByteCodeEmitter(Context &Ctx, Program &P) : Ctx(Ctx), P(P) {}
diff --git a/clang/lib/AST/Interp/Compiler.cpp 
b/clang/lib/AST/Interp/Compiler.cpp
index 5e1f507ca2b178..ece4b039df8e54 100644
--- a/clang/lib/AST/Interp/Compiler.cpp
+++ b/clang/lib/AST/Interp/Compiler.cpp
@@ -389,8 +389,6 @@ bool Compiler::VisitCastExpr(const CastExpr *CE) {
   return this->emitPop(T, CE);
 
 QualType PtrType = CE->getType();
-assert(PtrType->isPointerType());
-
 const Descriptor *Desc;
 if (std::optional T = classify(PtrType->getPointeeType()))
   Desc = P.createDescriptor(SubExpr, *T);
@@ -2240,8 +2238,6 @@ bool Compiler::VisitExprWithCleanups(const 
ExprWithCleanups *E) {
   LocalScope ES(this);
   const Expr *SubExpr = E->getSubExpr();
 
-  assert(E->getNumObjects() == 0 && "TODO: Implement cleanups");
-
   return this->delegate(SubExpr) && ES.destroyLocals(E);
 }
 
@@ -2911,6 +2907,17 @@ bool Compiler::VisitCXXDeleteExpr(const 
CXXDeleteExpr *E) {
   return this->emitFree(E->isArrayForm(), E);
 }
 
+template 
+bool Compiler::VisitBlockExpr(const BlockExpr *E) {
+  const Function *Func = nullptr;
+  if (auto F = Compiler(Ctx, P).compileObjCBlock(E))
+Func = F;
+
+  if (!Func)
+return false;
+  return this->emitGetFnPtr(Func, E);
+}
+
 template 
 bool Compiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *E) 
{
   assert(Ctx.getLangOpts().CPlusPlus);
diff --git a/clang/lib/AST/Interp/Compiler.h b/clang/lib/AST/Interp/Compiler.h
index 74bfce5f241f28..5acfe3c41796c4 100644
--- a/clang/lib/AST/Interp/Compiler.h
+++

[clang] [llvm] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-08-16 Thread via cfe-commits


@@ -369,12 +372,13 @@ class Intrinsic {
 public:
   Intrinsic(Record *R, StringRef Name, StringRef Proto, TypeSpec OutTS,
 TypeSpec InTS, ClassKind CK, ListInit *Body, NeonEmitter &Emitter,
-StringRef ArchGuard, StringRef TargetGuard, bool IsUnavailable, 
bool BigEndianSafe)
+StringRef ArchGuard, StringRef TargetGuard, bool IsUnavailable,
+bool BigEndianSafe)
   : R(R), Name(Name.str()), OutTS(OutTS), InTS(InTS), CK(CK), Body(Body),
-ArchGuard(ArchGuard.str()), TargetGuard(TargetGuard.str()), 
IsUnavailable(IsUnavailable),
-BigEndianSafe(BigEndianSafe), PolymorphicKeyType(0), 
NeededEarly(false),
-UseMacro(false), BaseType(OutTS, "."), InBaseType(InTS, "."),
-Emitter(Emitter) {
+ArchGuard(ArchGuard.str()), TargetGuard(TargetGuard.str()),

Lukacma wrote:

No need to reformat this

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


[clang] [llvm] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-08-16 Thread via cfe-commits


@@ -369,12 +372,13 @@ class Intrinsic {
 public:
   Intrinsic(Record *R, StringRef Name, StringRef Proto, TypeSpec OutTS,
 TypeSpec InTS, ClassKind CK, ListInit *Body, NeonEmitter &Emitter,
-StringRef ArchGuard, StringRef TargetGuard, bool IsUnavailable, 
bool BigEndianSafe)

Lukacma wrote:

No need for line break

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


[clang] [llvm] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-08-16 Thread via cfe-commits


@@ -1952,6 +1974,7 @@ void NeonEmitter::createIntrinsic(Record *R,
   bool BigEndianSafe  = R->getValueAsBit("BigEndianSafe");
   std::string ArchGuard = std::string(R->getValueAsString("ArchGuard"));
   std::string TargetGuard = std::string(R->getValueAsString("TargetGuard"));
+

Lukacma wrote:

unnecessary extra line

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


[clang] [llvm] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-08-16 Thread via cfe-commits


@@ -0,0 +1,202 @@
+// RUN: %clang_cc1 -triple aarch64-linux-gnu -target-feature +neon 
-target-feature +v8.3a -ffreestanding -fsyntax-only -verify %s

Lukacma wrote:

Why isn't this test under this path ? 
clang/test/Sema/aarch64-neon-immediate-ranges

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


[clang] [llvm] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-08-16 Thread via cfe-commits


@@ -234,6 +235,9 @@ cl::opt Action(
"Generate ARM NEON sema support for clang"),
 clEnumValN(GenArmNeonTest, "gen-arm-neon-test",
"Generate ARM NEON tests for clang"),
+clEnumValN(GenArmImmCheckTypes, "gen-arm-immcheck-types",
+   "Generate arm_immchecktypes.h (immediate range check types)"

Lukacma wrote:

it should be arm_immcheck_types.inc

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


[clang] [llvm] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-08-16 Thread via cfe-commits


@@ -1959,9 +2064,12 @@ multiclass VCMLA_ROTS {
 
 let isLaneQ = 1 in  {
   // vcmla{ROT}_laneq
+  // ACLE specifies that the fp16 vcmla_#ROT_laneq variant has an 
immedaite range of 0 <= lane <= 1.
+  // fp16 is the only variant for which these two differ.
+  // https://developer.arm.com/documentation/ihi0073/latest/ 
+  defvar getlanety = !if(!eq(type, "h"), lanety, laneqty);
   def : SOpInst<"vcmla" # ROT # "_laneq", "...QI", type,  Op<(call "vcmla" 
# ROT, $p0, $p1,
-  (bitcast $p0, (dup_typed lanety, (call "vget_lane", (bitcast 
laneqty, $p2), $p3>>;
-
+(bitcast $p0, (dup_typed lanety, (call "vget_lane", (bitcast 
getlanety, $p2), $p3>>;

Lukacma wrote:

I did take a look into  [ACLE 
release](https://github.com/ARM-software/acle/releases/tag/r2024Q2) and I think 
the website you linked might have a mistake there. Looking at advsimd-2023Q2 I 
see `vcmla[_rot]_laneq_f16` defined like this :
https://github.com/user-attachments/assets/2a446a5c-a3bf-40fc-9950-6caee95d81a2";>

It also makes sense for all of them to have the same imm. range, as the range 
is only dependant on size and datatype of the 3 operand and not on the sizes 
and datatypes of the other operands. 

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


[clang] [llvm] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-08-16 Thread via cfe-commits


@@ -2142,84 +2165,28 @@ void NeonEmitter::genOverloadTypeCheckCode(raw_ostream 
&OS,
   OS << "#endif\n\n";
 }
 
-void NeonEmitter::genIntrinsicRangeCheckCode(raw_ostream &OS,

Lukacma wrote:

I don't think this change in format is necessary

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


[clang] [llvm] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-08-16 Thread via cfe-commits


@@ -0,0 +1,39 @@
+class ImmCheckType {
+  int Value = val;
+}
+
+// These must be kept in sync with the flags in 
include/clang/Basic/TargetBuiltins.h
+def ImmCheck0_31: ImmCheckType<0>;  // 0..31 (used for e.g. 
predicate patterns)
+def ImmCheck1_16: ImmCheckType<1>;  // 1..16
+def ImmCheckExtract : ImmCheckType<2>;  // 
0..(2048/sizeinbits(elt) - 1)
+def ImmCheckShiftRight  : ImmCheckType<3>;  // 1..sizeinbits(elt)
+def ImmCheckShiftRightNarrow: ImmCheckType<4>;  // 1..sizeinbits(elt)/2
+def ImmCheckShiftLeft   : ImmCheckType<5>;  // 0..(sizeinbits(elt) - 1)
+def ImmCheck0_7 : ImmCheckType<6>;  // 0..7
+def ImmCheckLaneIndex   : ImmCheckType<7>;  // 
0..(128/(1*sizeinbits(elt)) - 1)
+def ImmCheckCvt : ImmCheckType<8>;  // 1..sizeinbits(elt) 
(same as ShiftRight)
+def ImmCheckLaneIndexCompRotate : ImmCheckType<9>;  // 
0..(128/(2*sizeinbits(elt)) - 1)
+def ImmCheckLaneIndexDot: ImmCheckType<10>; // 
0..(128/(4*sizeinbits(elt)) - 1)

Lukacma wrote:

all `128/` should be replaced by smth like `vecwidth`

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


[clang] [llvm] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-08-16 Thread via cfe-commits


@@ -1,444 +1,596 @@
-// RUN: %clang_cc1 -triple arm64-apple-ios -target-feature +neon \
-// RUN:-target-feature +v8.3a \
-// RUN:-target-feature +fullfp16 \
-// RUN:-disable-O0-optnone -emit-llvm -o - %s | opt -S -O1 | FileCheck 
%s
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -triple arm64-linux-gnu -target-feature +neon  \

Lukacma wrote:

Why was the run line changed here ?

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


[clang] [llvm] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-08-16 Thread via cfe-commits


@@ -388,6 +372,9 @@ class SVEEmitter {
   /// Emit all the range checks for the immediates.
   void createRangeChecks(raw_ostream &o);
 
+  // Emit all the ImmCheckTypes to arm_immcheck_types.h

Lukacma wrote:

it should be arm_immcheck_types.inc

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


[clang] [llvm] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-08-16 Thread via cfe-commits


@@ -403,142 +368,183 @@ enum ArmSMEState : unsigned {
   ArmZT0Mask = 0b11 << 2
 };
 
+bool SemaARM::CheckImmediateArg(CallExpr *TheCall, unsigned CheckTy,
+unsigned ArgIdx, unsigned EltBitWidth,
+unsigned VecBitWidth) {
+
+  typedef bool (*OptionSetCheckFnTy)(int64_t Value);
+
+  // Function that checks whether the operand (ArgIdx) is an immediate
+  // that is one of the predefined values.
+  auto CheckImmediateInSet = [&](OptionSetCheckFnTy CheckImm,
+ int ErrDiag) -> bool {
+// We can't check the value of a dependent argument.
+Expr *Arg = TheCall->getArg(ArgIdx);
+if (Arg->isTypeDependent() || Arg->isValueDependent())
+  return false;
+
+// Check constant-ness first.
+llvm::APSInt Imm;
+if (SemaRef.BuiltinConstantArg(TheCall, ArgIdx, Imm))
+  return true;
+
+if (!CheckImm(Imm.getSExtValue()))
+  return Diag(TheCall->getBeginLoc(), ErrDiag) << Arg->getSourceRange();
+return false;
+  };
+
+  switch ((ImmCheckType)CheckTy) {
+  case ImmCheckType::ImmCheck0_31:
+if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 0, 31))
+  return true;
+break;
+  case ImmCheckType::ImmCheck0_13:
+if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 0, 13))
+  return true;
+break;
+  case ImmCheckType::ImmCheck0_63:
+if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 0, 63))
+  return true;
+break;
+  case ImmCheckType::ImmCheck1_16:
+if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 1, 16))
+  return true;
+break;
+  case ImmCheckType::ImmCheck0_7:
+if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 0, 7))
+  return true;
+break;
+  case ImmCheckType::ImmCheck1_1:
+if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 1, 1))
+  return true;
+break;
+  case ImmCheckType::ImmCheck1_3:
+if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 1, 3))
+  return true;
+break;
+  case ImmCheckType::ImmCheck1_7:
+if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 1, 7))
+  return true;
+break;
+  case ImmCheckType::ImmCheckExtract:
+if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 0,
+(2048 / EltBitWidth) - 1))
+  return true;
+break;
+  case ImmCheckType::ImmCheckCvt:
+  case ImmCheckType::ImmCheckShiftRight:

Lukacma wrote:

I don't think there is any point in having 2 ImmCheckTypes which do the same 
thing. Best to rename one of them using operation-neutral name and remove the 
other

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


[clang] [llvm] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-08-16 Thread via cfe-commits


@@ -76,17 +76,22 @@ let ArchGuard = "defined(__aarch64__) || 
defined(__arm64ec__)", TargetGuard = "f
   def SCALAR_FCVTPUH  : SInst<"vcvtp_u16", "(1U)1", "Sh">;
   def SCALAR_FCVTPUH1 : SInst<"vcvtp_u32", "(1U>)1", "Sh">;
   def SCALAR_FCVTPUH2 : SInst<"vcvtp_u64", "(1U>>)1", "Sh">;
-  let isVCVT_N = 1 in {
+  let isVCVT_N = 1, ImmChecks = [ImmCheck<1, ImmCheck1_16>] in {
 def SCALAR_SCVTFSHO : SInst<"vcvth_n_f16", "(1F)(1!)I", "sUs">;
 def SCALAR_SCVTFSH1O: SInst<"vcvth_n_f16", "(1F<)(1!)I", "iUi">;
 def SCALAR_SCVTFSH2O: SInst<"vcvth_n_f16", "(1F<<)(1!)I", "lUl">;
 def SCALAR_FCVTZSHO : SInst<"vcvt_n_s16", "(1S)1I", "Sh">;

Lukacma wrote:

This should be with others vcvt_n intrinsics

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


[clang] [llvm] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-08-16 Thread via cfe-commits


@@ -0,0 +1,39 @@
+class ImmCheckType {
+  int Value = val;
+}
+
+// These must be kept in sync with the flags in 
include/clang/Basic/TargetBuiltins.h
+def ImmCheck0_31: ImmCheckType<0>;  // 0..31 (used for e.g. 
predicate patterns)
+def ImmCheck1_16: ImmCheckType<1>;  // 1..16
+def ImmCheckExtract : ImmCheckType<2>;  // 
0..(2048/sizeinbits(elt) - 1)
+def ImmCheckShiftRight  : ImmCheckType<3>;  // 1..sizeinbits(elt)
+def ImmCheckShiftRightNarrow: ImmCheckType<4>;  // 1..sizeinbits(elt)/2
+def ImmCheckShiftLeft   : ImmCheckType<5>;  // 0..(sizeinbits(elt) - 1)
+def ImmCheck0_7 : ImmCheckType<6>;  // 0..7
+def ImmCheckLaneIndex   : ImmCheckType<7>;  // 
0..(128/(1*sizeinbits(elt)) - 1)

Lukacma wrote:

`1*` unnecessary

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


[clang] [llvm] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-08-16 Thread via cfe-commits


@@ -15,6 +15,7 @@
 
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/Expr.h"
+#include "clang/Basic/TargetBuiltins.h"

Lukacma wrote:

I don't think moving this include is necessary

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


[clang] [llvm] [Clang][AArch64] Add customisable immediate range checking to NEON (PR #100278)

2024-08-16 Thread via cfe-commits


@@ -403,142 +368,183 @@ enum ArmSMEState : unsigned {
   ArmZT0Mask = 0b11 << 2
 };
 
+bool SemaARM::CheckImmediateArg(CallExpr *TheCall, unsigned CheckTy,
+unsigned ArgIdx, unsigned EltBitWidth,
+unsigned VecBitWidth) {
+
+  typedef bool (*OptionSetCheckFnTy)(int64_t Value);
+
+  // Function that checks whether the operand (ArgIdx) is an immediate
+  // that is one of the predefined values.
+  auto CheckImmediateInSet = [&](OptionSetCheckFnTy CheckImm,
+ int ErrDiag) -> bool {
+// We can't check the value of a dependent argument.
+Expr *Arg = TheCall->getArg(ArgIdx);
+if (Arg->isTypeDependent() || Arg->isValueDependent())
+  return false;
+
+// Check constant-ness first.
+llvm::APSInt Imm;
+if (SemaRef.BuiltinConstantArg(TheCall, ArgIdx, Imm))
+  return true;
+
+if (!CheckImm(Imm.getSExtValue()))
+  return Diag(TheCall->getBeginLoc(), ErrDiag) << Arg->getSourceRange();
+return false;
+  };
+
+  switch ((ImmCheckType)CheckTy) {
+  case ImmCheckType::ImmCheck0_31:
+if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 0, 31))
+  return true;
+break;
+  case ImmCheckType::ImmCheck0_13:
+if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 0, 13))
+  return true;
+break;
+  case ImmCheckType::ImmCheck0_63:
+if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 0, 63))
+  return true;
+break;
+  case ImmCheckType::ImmCheck1_16:
+if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 1, 16))
+  return true;
+break;
+  case ImmCheckType::ImmCheck0_7:
+if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 0, 7))
+  return true;
+break;
+  case ImmCheckType::ImmCheck1_1:
+if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 1, 1))
+  return true;
+break;
+  case ImmCheckType::ImmCheck1_3:
+if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 1, 3))
+  return true;
+break;
+  case ImmCheckType::ImmCheck1_7:
+if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 1, 7))
+  return true;
+break;
+  case ImmCheckType::ImmCheckExtract:
+if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 0,
+(2048 / EltBitWidth) - 1))
+  return true;
+break;
+  case ImmCheckType::ImmCheckCvt:
+  case ImmCheckType::ImmCheckShiftRight:
+if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 1, EltBitWidth))
+  return true;
+break;
+  case ImmCheckType::ImmCheckShiftRightNarrow:
+if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 1, EltBitWidth / 2))
+  return true;
+break;
+  case ImmCheckType::ImmCheckShiftLeft:
+if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 0, EltBitWidth - 1))
+  return true;
+break;
+  case ImmCheckType::ImmCheckLaneIndex:
+if (SemaRef.BuiltinConstantArgRange(TheCall, ArgIdx, 0,
+(VecBitWidth / (1 * EltBitWidth)) - 1))

Lukacma wrote:

`1 *` is unnecessary

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


[clang] [llvm] [AArch64] Add a check for invalid default features (PR #104435)

2024-08-16 Thread Tomas Matheson via cfe-commits

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

>From f79eb28441491f1625691886cc92bd05d3b3cb6a Mon Sep 17 00:00:00 2001
From: Tomas Matheson 
Date: Thu, 15 Aug 2024 13:41:31 +0100
Subject: [PATCH 1/9] [AArch64] Add a check for invalid default features

This adds a check that all ExtensionWithMArch which are marked as
implied features for an architecture are also present in the list of
default features. It doesn't make sense to have something mandatory but
not on by default.

There were a number of existing cases that violated this rule, and some
changes to which features are mandatory (indicated by the Implies
field):

> FEAT_SPECRES is mandatory from Armv8.5.
FeaturePredRes is added to the HasV8_5aOps.DefaultExts.

> FEAT_DIT is mandatory from Armv8.4.
FeatureDIT is added to the HasV8_4aOps.DefaultExts.

FEAT_SSBS is not mandatory for any architecture.
https://reviews.llvm.org/D54629 says it is mandatory for 8.5-a but I can't see 
that in the Arm ARM.
FeatureSSBS is removed from Implied and added to HasV8_5aOps.DefaultExts.
Cortex-A710 does not appear to have SSBS
https://developer.arm.com/documentation/101800/0201/The-Cortex-A710--core/Cortex-A710--core-features?lang=en
Removed from the Cortex-A710 and Oryon print-supported-extensions tests.
https://developer.apple.com/download/apple-silicon-cpu-optimization-guide/
Added to Apple A15/A16/A17 and (presumably?) M4 processor features.

> FEAT_BTI is mandatory from Armv8.5.
FeatureBranchTargetId is added to the DefaultExts

> FEAT_FlagM is mandatory from Armv8.4.
FeatureFlagM is added to the DefaultExts

> In an Armv8.4 implementation, if FEAT_AdvSIMD is implemented, FEAT_DotProd is 
> implemented.
FeatureDotProd is added to the HasV8_4aOps.DefaultExts.
FIXME what about nofp here?

> FEAT_SB is mandatory from Armv8.5.
FeatureSB is added to HasV8_5aOps.DefaultExts.
Therefore it appears on the `-cc1` command line for `-march=armv8.5a+nosb`.

> FEAT_WFxT is mandatory from Armv8.7.
FeatureWFxT is added to HasV8_7aOps.DefaultExts and HasV9_2aOps.DefaultExts.

> FEAT_CCIDX is OPTIONAL from Armv8.2.
Removed from Implies and added to HasV8_3aOps.DefaultExts and 
HasV8_0rOps.DefaultExts.

For v8-R, FEAT_CCIDX is not mandatory, removed.
 - Not implemented by cortex-r82, removed:
   https://developer.arm.com/documentation/102670/0300/?lang=en
 - Ditto cortex-r82ae
---
 clang/test/CodeGen/aarch64-targetattr.c   | 12 +++
 clang/test/Driver/arm-sb.c|  2 +-
 .../aarch64-cortex-a710.c |  1 -
 .../aarch64-cortex-r82.c  |  1 -
 .../aarch64-cortex-r82ae.c|  1 -
 .../aarch64-oryon-1.c |  1 -
 .../Preprocessor/aarch64-target-features.c|  4 +--
 llvm/lib/Target/AArch64/AArch64Features.td| 16 +-
 llvm/lib/Target/AArch64/AArch64Processors.td  | 11 ---
 llvm/test/MC/AArch64/armv8.5a-ssbs-error.s|  2 +-
 llvm/test/MC/AArch64/armv8.5a-ssbs.s  |  2 +-
 .../MC/Disassembler/AArch64/armv8.5a-ssbs.txt |  2 +-
 .../TargetParser/TargetParserTest.cpp | 21 ++--
 llvm/utils/TableGen/ARMTargetDefEmitter.cpp   | 32 +--
 14 files changed, 67 insertions(+), 41 deletions(-)

diff --git a/clang/test/CodeGen/aarch64-targetattr.c 
b/clang/test/CodeGen/aarch64-targetattr.c
index 4f891f938b6186..d6227be2ebef83 100644
--- a/clang/test/CodeGen/aarch64-targetattr.c
+++ b/clang/test/CodeGen/aarch64-targetattr.c
@@ -195,19 +195,19 @@ void minusarch() {}
 // CHECK: attributes #[[ATTR0]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+crc,+fp-armv8,+lse,+neon,+ras,+rdm,+v8.1a,+v8.2a,+v8a" }
 // CHECK: attributes #[[ATTR1]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+v8.1a,+v8.2a,+v8a"
 }
 // CHECK: attributes #[[ATTR2]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8a"
 }
-// CHECK: attributes #[[ATTR3]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+neon,+pauth,+ras,+rcpc,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 }
-// CHECK: attributes #[[ATTR4]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-cpu"="cortex-a710" 
"target-features"="+bf16,+complxnum,+crc,+dotprod,+ete,+flagm,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+mte,+neon,+pauth,+perfmon,+ras,+rcpc,+rdm,+sb,+sve,+sve2,+sve2-bitperm,+trbe,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8a,+v9a"
 }
+// CHECK: attributes #[[ATTR3]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"

[clang] [RFC][C++20][Modules] Fix crash when function and lambda inside loaded from different modules (PR #104512)

2024-08-16 Thread Dmitry Polukhin via cfe-commits

dmpolukhin wrote:

> I feel the change is somewhat odd to me. Since the description is about the 
> lambda but the change is about VarDecls. I feel there is a mismatch and I 
> feel this may not solve the underlying problem fundamentally. I feel it'll be 
> better to make it more straight forward. e.g., load the context when loading 
> the lambda (or only make it if there is captures.)

It was my initial approach to make sure that clang loads function and its 
lambdas from the same module. But I haven't found examples in clang how to make 
that canonical decls for two related things are always loaded from the same 
module. Clang starts loading function `tryTo` from `thrift_cpp2_base.h` module 
it follow links and via `declval` function specialization it discovers the 
lambda from `folly-conv.h` module that becomes canonical so by the time when it 
recursively returns to the lambda inside `thrift_cpp2_base.h` it just merged it 
to already known decl from `folly-conv.h`. I don't know how to make sure that 
deserialization won't intermix. As far as I understand code, clang solves this 
issue by merging identical decls so I implemented merging for VarDecls that 
cause this issue. But if there is a way to synchronize loading for a function 
and it's lambda, it should be more reliable but I failed to find the way. Help 
with solving this issue is very appreciated, clang seems to have other issues 
with merging lambdas too but I was not able to create small reproducers in 
other cases yet.

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


[clang] [llvm] [AArch64] Add a check for invalid default features (PR #104435)

2024-08-16 Thread Tomas Matheson via cfe-commits

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

>From f79eb28441491f1625691886cc92bd05d3b3cb6a Mon Sep 17 00:00:00 2001
From: Tomas Matheson 
Date: Thu, 15 Aug 2024 13:41:31 +0100
Subject: [PATCH 01/10] [AArch64] Add a check for invalid default features

This adds a check that all ExtensionWithMArch which are marked as
implied features for an architecture are also present in the list of
default features. It doesn't make sense to have something mandatory but
not on by default.

There were a number of existing cases that violated this rule, and some
changes to which features are mandatory (indicated by the Implies
field):

> FEAT_SPECRES is mandatory from Armv8.5.
FeaturePredRes is added to the HasV8_5aOps.DefaultExts.

> FEAT_DIT is mandatory from Armv8.4.
FeatureDIT is added to the HasV8_4aOps.DefaultExts.

FEAT_SSBS is not mandatory for any architecture.
https://reviews.llvm.org/D54629 says it is mandatory for 8.5-a but I can't see 
that in the Arm ARM.
FeatureSSBS is removed from Implied and added to HasV8_5aOps.DefaultExts.
Cortex-A710 does not appear to have SSBS
https://developer.arm.com/documentation/101800/0201/The-Cortex-A710--core/Cortex-A710--core-features?lang=en
Removed from the Cortex-A710 and Oryon print-supported-extensions tests.
https://developer.apple.com/download/apple-silicon-cpu-optimization-guide/
Added to Apple A15/A16/A17 and (presumably?) M4 processor features.

> FEAT_BTI is mandatory from Armv8.5.
FeatureBranchTargetId is added to the DefaultExts

> FEAT_FlagM is mandatory from Armv8.4.
FeatureFlagM is added to the DefaultExts

> In an Armv8.4 implementation, if FEAT_AdvSIMD is implemented, FEAT_DotProd is 
> implemented.
FeatureDotProd is added to the HasV8_4aOps.DefaultExts.
FIXME what about nofp here?

> FEAT_SB is mandatory from Armv8.5.
FeatureSB is added to HasV8_5aOps.DefaultExts.
Therefore it appears on the `-cc1` command line for `-march=armv8.5a+nosb`.

> FEAT_WFxT is mandatory from Armv8.7.
FeatureWFxT is added to HasV8_7aOps.DefaultExts and HasV9_2aOps.DefaultExts.

> FEAT_CCIDX is OPTIONAL from Armv8.2.
Removed from Implies and added to HasV8_3aOps.DefaultExts and 
HasV8_0rOps.DefaultExts.

For v8-R, FEAT_CCIDX is not mandatory, removed.
 - Not implemented by cortex-r82, removed:
   https://developer.arm.com/documentation/102670/0300/?lang=en
 - Ditto cortex-r82ae
---
 clang/test/CodeGen/aarch64-targetattr.c   | 12 +++
 clang/test/Driver/arm-sb.c|  2 +-
 .../aarch64-cortex-a710.c |  1 -
 .../aarch64-cortex-r82.c  |  1 -
 .../aarch64-cortex-r82ae.c|  1 -
 .../aarch64-oryon-1.c |  1 -
 .../Preprocessor/aarch64-target-features.c|  4 +--
 llvm/lib/Target/AArch64/AArch64Features.td| 16 +-
 llvm/lib/Target/AArch64/AArch64Processors.td  | 11 ---
 llvm/test/MC/AArch64/armv8.5a-ssbs-error.s|  2 +-
 llvm/test/MC/AArch64/armv8.5a-ssbs.s  |  2 +-
 .../MC/Disassembler/AArch64/armv8.5a-ssbs.txt |  2 +-
 .../TargetParser/TargetParserTest.cpp | 21 ++--
 llvm/utils/TableGen/ARMTargetDefEmitter.cpp   | 32 +--
 14 files changed, 67 insertions(+), 41 deletions(-)

diff --git a/clang/test/CodeGen/aarch64-targetattr.c 
b/clang/test/CodeGen/aarch64-targetattr.c
index 4f891f938b6186..d6227be2ebef83 100644
--- a/clang/test/CodeGen/aarch64-targetattr.c
+++ b/clang/test/CodeGen/aarch64-targetattr.c
@@ -195,19 +195,19 @@ void minusarch() {}
 // CHECK: attributes #[[ATTR0]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+crc,+fp-armv8,+lse,+neon,+ras,+rdm,+v8.1a,+v8.2a,+v8a" }
 // CHECK: attributes #[[ATTR1]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+v8.1a,+v8.2a,+v8a"
 }
 // CHECK: attributes #[[ATTR2]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8a"
 }
-// CHECK: attributes #[[ATTR3]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+neon,+pauth,+ras,+rcpc,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 }
-// CHECK: attributes #[[ATTR4]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-cpu"="cortex-a710" 
"target-features"="+bf16,+complxnum,+crc,+dotprod,+ete,+flagm,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+mte,+neon,+pauth,+perfmon,+ras,+rcpc,+rdm,+sb,+sve,+sve2,+sve2-bitperm,+trbe,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8a,+v9a"
 }
+// CHECK: attributes #[[ATTR3]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-siz

[clang] [Clang] Do not allow `[[clang::lifetimebound]]` on explicit object member functions (PR #96113)

2024-08-16 Thread Mital Ashok via cfe-commits

https://github.com/MitalAshok updated 
https://github.com/llvm/llvm-project/pull/96113

>From 453fea9fee85aef61c449761f24b0accecf03d29 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Wed, 19 Jun 2024 21:03:34 +0100
Subject: [PATCH] [Clang] Do not allow `[[clang::lifetimebound]]` on explicit
 object member functions

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  5 +++--
 clang/lib/Sema/SemaDecl.cpp  | 11 +--
 clang/test/SemaCXX/attr-lifetimebound.cpp|  3 ++-
 3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8a92973236ddbd..94be9c874afe97 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -10066,8 +10066,9 @@ def warn_null_ret : Warning<
   InGroup;
 
 def err_lifetimebound_no_object_param : Error<
-  "'lifetimebound' attribute cannot be applied; %select{static |non-}0member "
-  "function has no implicit object parameter">;
+  "'lifetimebound' attribute cannot be applied; "
+  "%select{non-|static |explicit object }0"
+  "member function has no implicit object parameter">;
 def err_lifetimebound_ctor_dtor : Error<
   "'lifetimebound' attribute cannot be applied to a "
   "%select{constructor|destructor}0">;
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index d19a16cf2ba150..61a465ca55c5c7 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6938,9 +6938,16 @@ static void checkAttributesAfterMerging(Sema &S, 
NamedDecl &ND) {
   // by applying it to the function type.
   if (const auto *A = ATL.getAttrAs()) {
 const auto *MD = dyn_cast(FD);
-if (!MD || MD->isStatic()) {
+int NoImplicitObjectError = -1;
+if (!MD)
+  NoImplicitObjectError = 0;
+else if (MD->isStatic())
+  NoImplicitObjectError = 1;
+else if (MD->isExplicitObjectMemberFunction())
+  NoImplicitObjectError = 2;
+if (NoImplicitObjectError != -1) {
   S.Diag(A->getLocation(), diag::err_lifetimebound_no_object_param)
-  << !MD << A->getRange();
+  << NoImplicitObjectError << A->getRange();
 } else if (isa(MD) || isa(MD)) {
   S.Diag(A->getLocation(), diag::err_lifetimebound_ctor_dtor)
   << isa(MD) << A->getRange();
diff --git a/clang/test/SemaCXX/attr-lifetimebound.cpp 
b/clang/test/SemaCXX/attr-lifetimebound.cpp
index 7db0a4d64d2596..f4ca840cb276f9 100644
--- a/clang/test/SemaCXX/attr-lifetimebound.cpp
+++ b/clang/test/SemaCXX/attr-lifetimebound.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++2a -verify %s
+// RUN: %clang_cc1 -std=c++23 -verify %s
 
 namespace usage_invalid {
   // FIXME: Should we diagnose a void return type?
@@ -9,6 +9,7 @@ namespace usage_invalid {
 A() [[clang::lifetimebound]]; // expected-error {{cannot be applied to a 
constructor}}
 ~A() [[clang::lifetimebound]]; // expected-error {{cannot be applied to a 
destructor}}
 static int *static_class_member() [[clang::lifetimebound]]; // 
expected-error {{static member function has no implicit object parameter}}
+int *explicit_object(this A&) [[clang::lifetimebound]]; // expected-error 
{{explicit object member function has no implicit object parameter}}
 int not_function [[clang::lifetimebound]]; // expected-error {{only 
applies to parameters and implicit object parameters}}
 int [[clang::lifetimebound]] also_not_function; // expected-error {{cannot 
be applied to types}}
   };

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


[clang] [Clang] Do not allow `[[clang::lifetimebound]]` on explicit object member functions (PR #96113)

2024-08-16 Thread Mital Ashok via cfe-commits

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


[clang] [Clang] Do not allow `[[clang::lifetimebound]]` on explicit object member functions (PR #96113)

2024-08-16 Thread Mital Ashok via cfe-commits

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


[clang] [llvm] [AArch64] Add a check for invalid default features (PR #104435)

2024-08-16 Thread Tomas Matheson via cfe-commits

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


[clang] [llvm] [AArch64] Add a check for invalid default features (PR #104435)

2024-08-16 Thread Tomas Matheson via cfe-commits

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


[clang] [llvm] [AArch64] Add a check for invalid default features (PR #104435)

2024-08-16 Thread Tomas Matheson via cfe-commits

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


[clang-tools-extra] a426ffd - [include-cleaner] Add handling for new/delete expressions (#104033)

2024-08-16 Thread via cfe-commits

Author: kadir çetinkaya
Date: 2024-08-16T13:17:58+02:00
New Revision: a426ffdee1ca7814f2684b6104c48f5669815aad

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

LOG: [include-cleaner] Add handling for new/delete expressions (#104033)

Added: 


Modified: 
clang-tools-extra/include-cleaner/lib/WalkAST.cpp
clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp 
b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
index b15d428326ac12..a5ac3760a3be2a 100644
--- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -23,7 +23,6 @@
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Specifiers.h"
-#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Casting.h"
@@ -350,6 +349,15 @@ class ASTWalker : public RecursiveASTVisitor {
RefType::Implicit);
 return true;
   }
+
+  bool VisitCXXNewExpr(CXXNewExpr *E) {
+report(E->getExprLoc(), E->getOperatorNew());
+return true;
+  }
+  bool VisitCXXDeleteExpr(CXXDeleteExpr *E) {
+report(E->getExprLoc(), E->getOperatorDelete());
+return true;
+  }
 };
 
 } // namespace

diff  --git a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
index 282abce3246ca3..79371f5978fc33 100644
--- a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -555,5 +555,12 @@ TEST(WalkAST, FriendDecl) {
   testWalk("void $explicit^foo();", "struct Bar { friend void ^foo(); };");
   testWalk("struct $explicit^Foo {};", "struct Bar { friend struct ^Foo; };");
 }
+
+TEST(WalkAST, OperatorNewDelete) {
+  testWalk("void* $explicit^operator new(unsigned long, void*);",
+   "struct Bar { void foo() { Bar b; ^new (&b) Bar; } };");
+  testWalk("struct A { static void $explicit^operator delete(void*); };",
+   "void foo() { A a; ^delete &a; }");
+}
 } // namespace
 } // namespace clang::include_cleaner



___
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 handling for new/delete expressions (PR #104033)

2024-08-16 Thread kadir çetinkaya via cfe-commits

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


[clang] [llvm] [AArch64] Add a check for invalid default features (PR #104435)

2024-08-16 Thread Tomas Matheson via cfe-commits

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

>From f79eb28441491f1625691886cc92bd05d3b3cb6a Mon Sep 17 00:00:00 2001
From: Tomas Matheson 
Date: Thu, 15 Aug 2024 13:41:31 +0100
Subject: [PATCH 01/11] [AArch64] Add a check for invalid default features

This adds a check that all ExtensionWithMArch which are marked as
implied features for an architecture are also present in the list of
default features. It doesn't make sense to have something mandatory but
not on by default.

There were a number of existing cases that violated this rule, and some
changes to which features are mandatory (indicated by the Implies
field):

> FEAT_SPECRES is mandatory from Armv8.5.
FeaturePredRes is added to the HasV8_5aOps.DefaultExts.

> FEAT_DIT is mandatory from Armv8.4.
FeatureDIT is added to the HasV8_4aOps.DefaultExts.

FEAT_SSBS is not mandatory for any architecture.
https://reviews.llvm.org/D54629 says it is mandatory for 8.5-a but I can't see 
that in the Arm ARM.
FeatureSSBS is removed from Implied and added to HasV8_5aOps.DefaultExts.
Cortex-A710 does not appear to have SSBS
https://developer.arm.com/documentation/101800/0201/The-Cortex-A710--core/Cortex-A710--core-features?lang=en
Removed from the Cortex-A710 and Oryon print-supported-extensions tests.
https://developer.apple.com/download/apple-silicon-cpu-optimization-guide/
Added to Apple A15/A16/A17 and (presumably?) M4 processor features.

> FEAT_BTI is mandatory from Armv8.5.
FeatureBranchTargetId is added to the DefaultExts

> FEAT_FlagM is mandatory from Armv8.4.
FeatureFlagM is added to the DefaultExts

> In an Armv8.4 implementation, if FEAT_AdvSIMD is implemented, FEAT_DotProd is 
> implemented.
FeatureDotProd is added to the HasV8_4aOps.DefaultExts.
FIXME what about nofp here?

> FEAT_SB is mandatory from Armv8.5.
FeatureSB is added to HasV8_5aOps.DefaultExts.
Therefore it appears on the `-cc1` command line for `-march=armv8.5a+nosb`.

> FEAT_WFxT is mandatory from Armv8.7.
FeatureWFxT is added to HasV8_7aOps.DefaultExts and HasV9_2aOps.DefaultExts.

> FEAT_CCIDX is OPTIONAL from Armv8.2.
Removed from Implies and added to HasV8_3aOps.DefaultExts and 
HasV8_0rOps.DefaultExts.

For v8-R, FEAT_CCIDX is not mandatory, removed.
 - Not implemented by cortex-r82, removed:
   https://developer.arm.com/documentation/102670/0300/?lang=en
 - Ditto cortex-r82ae
---
 clang/test/CodeGen/aarch64-targetattr.c   | 12 +++
 clang/test/Driver/arm-sb.c|  2 +-
 .../aarch64-cortex-a710.c |  1 -
 .../aarch64-cortex-r82.c  |  1 -
 .../aarch64-cortex-r82ae.c|  1 -
 .../aarch64-oryon-1.c |  1 -
 .../Preprocessor/aarch64-target-features.c|  4 +--
 llvm/lib/Target/AArch64/AArch64Features.td| 16 +-
 llvm/lib/Target/AArch64/AArch64Processors.td  | 11 ---
 llvm/test/MC/AArch64/armv8.5a-ssbs-error.s|  2 +-
 llvm/test/MC/AArch64/armv8.5a-ssbs.s  |  2 +-
 .../MC/Disassembler/AArch64/armv8.5a-ssbs.txt |  2 +-
 .../TargetParser/TargetParserTest.cpp | 21 ++--
 llvm/utils/TableGen/ARMTargetDefEmitter.cpp   | 32 +--
 14 files changed, 67 insertions(+), 41 deletions(-)

diff --git a/clang/test/CodeGen/aarch64-targetattr.c 
b/clang/test/CodeGen/aarch64-targetattr.c
index 4f891f938b6186..d6227be2ebef83 100644
--- a/clang/test/CodeGen/aarch64-targetattr.c
+++ b/clang/test/CodeGen/aarch64-targetattr.c
@@ -195,19 +195,19 @@ void minusarch() {}
 // CHECK: attributes #[[ATTR0]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+crc,+fp-armv8,+lse,+neon,+ras,+rdm,+v8.1a,+v8.2a,+v8a" }
 // CHECK: attributes #[[ATTR1]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+v8.1a,+v8.2a,+v8a"
 }
 // CHECK: attributes #[[ATTR2]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8a"
 }
-// CHECK: attributes #[[ATTR3]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+neon,+pauth,+ras,+rcpc,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 }
-// CHECK: attributes #[[ATTR4]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-cpu"="cortex-a710" 
"target-features"="+bf16,+complxnum,+crc,+dotprod,+ete,+flagm,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+mte,+neon,+pauth,+perfmon,+ras,+rcpc,+rdm,+sb,+sve,+sve2,+sve2-bitperm,+trbe,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8a,+v9a"
 }
+// CHECK: attributes #[[ATTR3]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-siz

[clang] [llvm] [AArch64] Add a check for invalid default features (PR #104435)

2024-08-16 Thread Tomas Matheson via cfe-commits

tmatheson-arm wrote:

Fixed SSBS and CCIDX.

> Does this also fix the "+nossbs" issue we saw earlier this week?

Yes, added a test 
https://github.com/llvm/llvm-project/pull/104435/files#diff-e355e3951d191d3a32265d9bdeb101e4f49ddfa6049ef058cf9e1dfdf7c19ef3

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


[clang] [RISCV] Allow YAML file to control multilib selection (PR #98856)

2024-08-16 Thread via cfe-commits

ArcaneNibble wrote:

ping?

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


[clang] Add "clang-format-on-save-mode" minor mode to clang-format.el (PR #104533)

2024-08-16 Thread Campbell Barton via cfe-commits

ideasman42 wrote:

> I'm not an emacs user and I'm unsure if the other maintainers are. If you are 
> happy to address any issues that might arise I'd be happy for this to land.

Yes, I'm happy to resolve any issues - for some context, I've been using a 
version of this for some years.
Originally from this answer https://emacs.stackexchange.com/q/48500/2418

The minor mode just makes it convenient to enable/disable - I find it 
especially when working on some projects that don't use clang-format to 
optionally check for `.clang-format` and only format-on-save in this case (that 
behavior can be configured too).


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


[clang] Add "clang-format-on-save-mode" minor mode to clang-format.el (PR #104533)

2024-08-16 Thread Campbell Barton via cfe-commits

https://github.com/ideasman42 updated 
https://github.com/llvm/llvm-project/pull/104533

>From d53cf4f059cacadbbb6e32349a26580e7ea1a55b Mon Sep 17 00:00:00 2001
From: Campbell Barton 
Date: Fri, 16 Aug 2024 11:28:19 +1000
Subject: [PATCH 1/3] Add "clang-format-on-save-mode" minor mode to
 clang-format.el

Add a minor mode to run clang-format on save.
---
 clang/tools/clang-format/clang-format.el | 59 
 1 file changed, 59 insertions(+)

diff --git a/clang/tools/clang-format/clang-format.el 
b/clang/tools/clang-format/clang-format.el
index f43bf063c62970..25a5865efdebd2 100644
--- a/clang/tools/clang-format/clang-format.el
+++ b/clang/tools/clang-format/clang-format.el
@@ -70,6 +70,20 @@ in such buffers."
   :safe #'stringp)
 (make-variable-buffer-local 'clang-format-fallback-style)
 
+(defcustom clang-format-on-save-p 'clang-format-on-save-check-config-exists
+  "Only reformat on save if this function returns non-nil.
+
+You may wish to choose one of the following options:
+- `always': To always format on save.
+- `clang-format-on-save-check-config-exists':
+  Only reformat when \".clang-format\" exists.
+
+Otherwise you can set this to a user defined function."
+  :group 'clang-format
+  :type 'function
+  :risky t)
+(make-variable-buffer-local 'clang-format-on-save-p)
+
 (defun clang-format--extract (xml-node)
   "Extract replacements and cursor information from XML-NODE."
   (unless (and (listp xml-node) (eq (xml-node-name xml-node) 'replacements))
@@ -217,5 +231,50 @@ the function `buffer-file-name'."
 ;;;###autoload
 (defalias 'clang-format 'clang-format-region)
 
+;; Format on save minor mode.
+;;
+;; Optional minor mode for formatting on save.
+
+(defun clang-format--on-save-buffer-hook ()
+  "The hook to run on buffer saving to format the buffer."
+  ;; Demote errors as this is user configurable, we can't be sure it wont 
error.
+  (when (with-demoted-errors "clang-format-on-save: Error %S"
+  (funcall clang-format-on-save-p))
+(clang-format-buffer))
+  ;; Continue to save.
+  nil)
+
+(defun clang-format--on-save-enable ()
+  "Disable the minor mode."
+  (add-hook 'before-save-hook #'clang-format--on-save-buffer-hook nil t))
+
+(defun clang-format--on-save-disable ()
+  "Enable the minor mode."
+  (remove-hook 'before-save-hook #'clang-format--on-save-buffer-hook t))
+
+;; Default value for `clang-format-on-save-p'.
+(defun clang-format-on-save-check-config-exists ()
+  "Return non-nil when `.clang-format' is found in a parent directory."
+  ;; Unlikely but possible this is nil.
+  (let ((filepath buffer-file-name))
+(cond
+ (filepath
+  (null (null (locate-dominating-file (file-name-directory filepath) 
".clang-format"
+ (t
+  nil
+
+;;;###autoload
+(define-minor-mode clang-format-on-save-mode
+  "Clang-format on save minor mode."
+  :global nil
+  :lighter ""
+  :keymap nil
+
+  (cond
+   (clang-format-on-save-mode
+(clang-format--on-save-enable))
+   (t
+(clang-format--on-save-disable
+
 (provide 'clang-format)
 ;;; clang-format.el ends here

>From a3e87f43933a80cca51bc002ed9d4801b18b6b22 Mon Sep 17 00:00:00 2001
From: Campbell Barton 
Date: Fri, 16 Aug 2024 11:47:59 +1000
Subject: [PATCH 2/3] Minor cleanup.

---
 clang/tools/clang-format/clang-format.el | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang/tools/clang-format/clang-format.el 
b/clang/tools/clang-format/clang-format.el
index 25a5865efdebd2..64d1d3f5789c72 100644
--- a/clang/tools/clang-format/clang-format.el
+++ b/clang/tools/clang-format/clang-format.el
@@ -232,8 +232,6 @@ the function `buffer-file-name'."
 (defalias 'clang-format 'clang-format-region)
 
 ;; Format on save minor mode.
-;;
-;; Optional minor mode for formatting on save.
 
 (defun clang-format--on-save-buffer-hook ()
   "The hook to run on buffer saving to format the buffer."
@@ -259,7 +257,7 @@ the function `buffer-file-name'."
   (let ((filepath buffer-file-name))
 (cond
  (filepath
-  (null (null (locate-dominating-file (file-name-directory filepath) 
".clang-format"
+  (not (null (locate-dominating-file (file-name-directory filepath) 
".clang-format"
  (t
   nil
 

>From df069cc028cb0eff6910836c4270335b11c3ec0f Mon Sep 17 00:00:00 2001
From: Campbell Barton 
Date: Fri, 16 Aug 2024 21:26:20 +1000
Subject: [PATCH 3/3] Shorten overly verbose message

---
 clang/tools/clang-format/clang-format.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/tools/clang-format/clang-format.el 
b/clang/tools/clang-format/clang-format.el
index 64d1d3f5789c72..5cdd984c531ec4 100644
--- a/clang/tools/clang-format/clang-format.el
+++ b/clang/tools/clang-format/clang-format.el
@@ -236,7 +236,7 @@ the function `buffer-file-name'."
 (defun clang-format--on-save-buffer-hook ()
   "The hook to run on buffer saving to format the buffer."
   ;; Demote errors as this is user configurable, we can't be sure it wont 
error.
-  (when (wi

[clang-tools-extra] [include-cleaner] Add handling for new/delete expressions (PR #104033)

2024-08-16 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-armv8-quick` running 
on `linaro-clang-armv8-quick` while building `clang-tools-extra` at step 5 
"ninja check 1".

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

Here is the relevant piece of the build log for the reference:
```
Step 5 (ninja check 1) failure: stage 1 checked (failure)
 TEST 'clangIncludeCleaner Unit Tests :: 
./ClangIncludeCleanerTests/87/88' FAILED 
Script(shard):
--
GTEST_OUTPUT=json:/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/include-cleaner/unittests/./ClangIncludeCleanerTests-clangIncludeCleaner
 Unit Tests-4106719-87-88.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=88 
GTEST_SHARD_INDEX=87 
/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/include-cleaner/unittests/./ClangIncludeCleanerTests
--

Script:
--
/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/include-cleaner/unittests/./ClangIncludeCleanerTests
 --gtest_filter=WalkAST.OperatorNewDelete
--
../llvm/clang/lib/Testing/TestAST.cpp:49: Failure
Failed
In file included from :475:
./target.h:1:7: error: 'operator new' takes type size_t ('unsigned int') as 
first parameter
1 | void* operator new(unsigned long, void*);
  |   ^


../llvm/clang/lib/Testing/TestAST.cpp:49: Failure
Failed
input.mm:1:34: error: no matching 'operator new' function for non-allocating 
placement new expression; include 
1 | struct Bar { void foo() { Bar b; new (&b) Bar; } };
  |  ^   


../llvm/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp:109: Failure
Failed
./target.h:1:7: location not marked used with type explicit
1 | void* operator new(unsigned long, void*);
  |   ^

from code:
struct Bar { void foo() { Bar b; ^new (&b) Bar; } };


../llvm/clang/lib/Testing/TestAST.cpp:49
Failed
In file included from :475:
./target.h:1:7: error: 'operator new' takes type size_t ('unsigned int') as 
first parameter
1 | void* operator new(unsigned long, void*);
  |   ^


../llvm/clang/lib/Testing/TestAST.cpp:49
Failed
input.mm:1:34: error: no matching 'operator new' function for non-allocating 
placement new expression; include 
1 | struct Bar { void foo() { Bar b; new (&b) Bar; } };
  |  ^   


...

```

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


[clang] [llvm] [AArch64] Implement NEON vscale intrinsics (PR #100347)

2024-08-16 Thread via cfe-commits

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

>From 4cbec87032166083624251f868ab1c60a7a266b4 Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Wed, 24 Jul 2024 11:16:20 +
Subject: [PATCH 1/2] [AArch64] Implement NEON vscale intrinsics

---
 clang/include/clang/Basic/arm_neon.td |  6 ++
 clang/lib/CodeGen/CGBuiltin.cpp   |  8 +++
 .../acle_neon_fscale.c| 58 +++
 llvm/include/llvm/IR/IntrinsicsAArch64.td |  7 +++
 .../lib/Target/AArch64/AArch64InstrFormats.td | 21 +++
 llvm/lib/Target/AArch64/AArch64InstrInfo.td   |  2 +-
 llvm/test/CodeGen/AArch64/neon-fp8-fscale.ll  | 54 +
 7 files changed, 155 insertions(+), 1 deletion(-)
 create mode 100644 
clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c
 create mode 100644 llvm/test/CodeGen/AArch64/neon-fp8-fscale.ll

diff --git a/clang/include/clang/Basic/arm_neon.td 
b/clang/include/clang/Basic/arm_neon.td
index 3098fa67e6a512..f930c62a79280f 100644
--- a/clang/include/clang/Basic/arm_neon.td
+++ b/clang/include/clang/Basic/arm_neon.td
@@ -2096,3 +2096,9 @@ let ArchGuard = "defined(__aarch64__) || 
defined(__arm64ec__)", TargetGuard = "r
   def VLDAP1_LANE : WInst<"vldap1_lane", ".(c*!).I", "QUlQlUlldQdPlQPl">;
   def VSTL1_LANE  : WInst<"vstl1_lane", "v*(.!)I", "QUlQlUlldQdPlQPl">;
 }
+
+let ArchGuard = "defined(__aarch64__)", TargetGuard = "fp8" in {
+  // fscale
+  def FSCALE_V128 : WInst<"vscale", "..(.S)", "QdQfQh">;
+  def FSCALE_V64 : WInst<"vscale", "(.q)(.q)(.qS)", "fh">;
+}
\ No newline at end of file
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 5639239359ab82..816899e5c11e38 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -13491,6 +13491,14 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 Int = Intrinsic::aarch64_neon_suqadd;
 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vuqadd");
   }
+  case NEON::BI__builtin_neon_vscale_f16:
+  case NEON::BI__builtin_neon_vscaleq_f16:
+  case NEON::BI__builtin_neon_vscale_f32:
+  case NEON::BI__builtin_neon_vscaleq_f32:
+  case NEON::BI__builtin_neon_vscaleq_f64: {
+Int = Intrinsic::aarch64_neon_fp8_fscale;
+return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "fscale");
+  }
   }
 }
 
diff --git a/clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c 
b/clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c
new file mode 100644
index 00..b50d30876a7c51
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-neon-fp8-intrinsics/acle_neon_fscale.c
@@ -0,0 +1,58 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+#include 
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +neon 
-target-feature +fp8 -O3 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +neon 
-target-feature +fp8 -S -O3 -o /dev/null %s
+
+// CHECK-LABEL: define dso_local <4 x half> @test_vscale_f16(
+// CHECK-SAME: <4 x half> noundef [[VN:%.*]], <4 x i16> noundef [[VM:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[FSCALE2_I:%.*]] = tail call <4 x half> 
@llvm.aarch64.neon.fp8.fscale.v4f16(<4 x half> [[VN]], <4 x i16> [[VM]])
+// CHECK-NEXT:ret <4 x half> [[FSCALE2_I]]
+//
+float16x4_t test_vscale_f16(float16x4_t vn, int16x4_t vm) {
+  return vscale_f16(vn, vm);
+}
+
+// CHECK-LABEL: define dso_local <8 x half> @test_vscaleq_f16(
+// CHECK-SAME: <8 x half> noundef [[VN:%.*]], <8 x i16> noundef [[VM:%.*]]) 
local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[FSCALE2_I:%.*]] = tail call <8 x half> 
@llvm.aarch64.neon.fp8.fscale.v8f16(<8 x half> [[VN]], <8 x i16> [[VM]])
+// CHECK-NEXT:ret <8 x half> [[FSCALE2_I]]
+//
+float16x8_t test_vscaleq_f16(float16x8_t vn, int16x8_t vm) {
+  return vscaleq_f16(vn, vm);
+
+}
+
+// CHECK-LABEL: define dso_local <2 x float> @test_vscale_f32(
+// CHECK-SAME: <2 x float> noundef [[VN:%.*]], <2 x i32> noundef [[VM:%.*]]) 
local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[FSCALE2_I:%.*]] = tail call <2 x float> 
@llvm.aarch64.neon.fp8.fscale.v2f32(<2 x float> [[VN]], <2 x i32> [[VM]])
+// CHECK-NEXT:ret <2 x float> [[FSCALE2_I]]
+//
+float32x2_t test_vscale_f32(float32x2_t vn, int32x2_t vm) {
+  return vscale_f32(vn, vm);
+
+}
+
+// CHECK-LABEL: define dso_local <4 x float> @test_vscaleq_f32(
+// CHECK-SAME: <4 x float> noundef [[VN:%.*]], <4 x i32> noundef [[VM:%.*]]) 
local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[FSCALE2_I:%.*]] = tail call <4 x float> 
@llvm.aarch64.neon.fp8.fscale.v4f32(<4 x float> [[VN]], <4 x i32> [[VM]])
+// CHECK-NEXT:ret <4 x float> [[FSCALE2_I]]
+//
+float32x4_t test_vscaleq_f32(float32x4_t vn, int32x4_t vm) {
+  return vscaleq_f32(vn, vm);
+
+

[clang] [analyzer] Moving TaintPropagation checker out of alpha (PR #67352)

2024-08-16 Thread Daniel Krupp via cfe-commits

https://github.com/dkrupp updated 
https://github.com/llvm/llvm-project/pull/67352

>From 11b85a494bfc844d9474efd2c9679cc5c0f4f889 Mon Sep 17 00:00:00 2001
From: Daniel Krupp 
Date: Thu, 15 Aug 2024 14:24:35 +0200
Subject: [PATCH] [analyzer] Moving TaintPropagation and GenericTaint checkers
 out of alpha

alpha.security.taint.TaintPropagation
modeling checker is renamed to optin.taint.TaintPropagation.

alpha.security.taint.GenericTaint
user facing checker is renamed to optin.taint.genericTaint

These checkers were stabilized and improved by recent commits,
thus it's ready for (optional) production use.

The checker is placed in the optin package as it implements
an optional security analysis.
---
 clang/docs/analyzer/checkers.rst  | 472 +-
 .../user-docs/TaintAnalysisConfiguration.rst  |   4 +-
 .../clang/StaticAnalyzer/Checkers/Checkers.td |  43 +-
 clang/test/Analysis/analyzer-config.c |   2 +-
 .../Analysis/assume-controlled-environment.c  |   4 +-
 clang/test/Analysis/bool-assignment.c |   4 +-
 clang/test/Analysis/cxx-method-names.cpp  |   2 +-
 .../Analysis/debug-exprinspection-istainted.c |   2 +-
 .../sarif-diagnostics-taint-test.c.sarif  |   2 +-
 .../sarif-multi-diagnostic-test.c.sarif   |   2 +-
 .../sarif-diagnostics-taint-test.c|   2 +-
 .../diagnostics/sarif-multi-diagnostic-test.c |   3 +-
 clang/test/Analysis/fread.c   |   2 +-
 .../global-region-invalidation-errno.c|   4 +-
 .../Analysis/global-region-invalidation.c |   2 +-
 clang/test/Analysis/malloc.c  |   2 +-
 clang/test/Analysis/malloc.cpp|   8 +-
 .../test/Analysis/out-of-bounds-diagnostics.c |   2 +-
 clang/test/Analysis/out-of-bounds-notes.c |   2 +-
 clang/test/Analysis/redefined_system.c|   2 +-
 clang/test/Analysis/string.c  |   2 +-
 ...nt-checker-callback-order-has-definition.c |   2 +-
 ...hecker-callback-order-without-definition.c |   2 +-
 .../test/Analysis/taint-diagnostic-visitor.c  |   2 +-
 clang/test/Analysis/taint-dumps.c |   2 +-
 clang/test/Analysis/taint-generic.c   |  26 +-
 clang/test/Analysis/taint-generic.cpp |   2 +-
 clang/test/Analysis/taint-tester.c|   2 +-
 clang/test/Analysis/taint-tester.cpp  |   3 +-
 clang/test/Analysis/taint-tester.m|   6 +-
 clang/utils/analyzer/SATestBuild.py   |   2 +-
 31 files changed, 305 insertions(+), 312 deletions(-)

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index 0bfbc995579d41..7310f1be623438 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -992,6 +992,241 @@ optin.portability.UnixAPI
 "
 Finds implementation-defined behavior in UNIX/Posix functions.
 
+
+optin.taint
+
+
+Checkers implementing
+`taint analysis `_.
+
+.. _optin-taint-GenericTaint:
+
+optin.taint.GenericTaint (C, C++)
+""
+
+Taint analysis identifies potential security vulnerabilities where the
+attacker can inject malicious data to the program to execute an attack
+(privilege escalation, command injection, SQL injection etc.).
+
+The malicious data is injected at the taint source (e.g. ``getenv()`` call)
+which is then propagated through function calls and being used as arguments of
+sensitive operations, also called as taint sinks (e.g. ``system()`` call).
+
+One can defend against this type of vulnerability by always checking and
+sanitizing the potentially malicious, untrusted user input.
+
+The goal of the checker is to discover and show to the user these potential
+taint source-sink pairs and the propagation call chain.
+
+The most notable examples of taint sources are:
+
+  - data from network
+  - files or standard input
+  - environment variables
+  - data from databases
+
+Let us examine a practical example of a Command Injection attack.
+
+.. code-block:: c
+
+  // Command Injection Vulnerability Example
+  int main(int argc, char** argv) {
+char cmd[2048] = "/bin/cat ";
+char filename[1024];
+printf("Filename:");
+scanf (" %1023[^\n]", filename); // The attacker can inject a shell escape 
here
+strcat(cmd, filename);
+system(cmd); // Warning: Untrusted data is passed to a system call
+  }
+
+The program prints the content of any user specified file.
+Unfortunately the attacker can execute arbitrary commands
+with shell escapes. For example with the following input the `ls` command is 
also
+executed after the contents of `/etc/shadow` is printed.
+`Input: /etc/shadow ; ls /`
+
+The analysis implemented in this checker points out this problem.
+
+One can protect against such attack by for example checking if the provided
+input refers to a valid file and removing any invalid user input.
+
+.. code-block:: c
+
+  // No vulnerability anymore, but we

[clang] [clang][Interp] Fix classifying enum types (PR #104582)

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

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

We used to always return PT_IntAP(s) for them.

>From b838d2c2c71868ef48b8357c744e5b8d41ba5d14 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 16 Aug 2024 13:48:44 +0200
Subject: [PATCH] [clang][Interp] Fix classifying enum types

We used to always return PT_IntAP(s) for them.
---
 clang/lib/AST/Interp/Context.cpp | 3 +++
 clang/test/AST/Interp/enums.cpp  | 5 +
 2 files changed, 8 insertions(+)

diff --git a/clang/lib/AST/Interp/Context.cpp b/clang/lib/AST/Interp/Context.cpp
index 92ac28137fdb45..e9c1fd1b8dc9f9 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -135,6 +135,9 @@ std::optional Context::classify(QualType T) const 
{
   if (T->isAnyComplexType() || T->isVectorType())
 return std::nullopt;
 
+  if (const auto *ET = T->getAs())
+return classify(ET->getDecl()->getIntegerType());
+
   if (T->isSignedIntegerOrEnumerationType()) {
 switch (Ctx.getIntWidth(T)) {
 case 64:
diff --git a/clang/test/AST/Interp/enums.cpp b/clang/test/AST/Interp/enums.cpp
index c4db7875451677..459cf3a0c83d54 100644
--- a/clang/test/AST/Interp/enums.cpp
+++ b/clang/test/AST/Interp/enums.cpp
@@ -48,3 +48,8 @@ constexpr EC getB() {
 
 
 static_assert(getB() == EC::B, "");
+
+namespace B {
+  enum E : bool { Zero, One };
+  static_assert((int)(E)2 == 1, "");
+} // namespace B

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


[clang] [clang][Interp] Fix classifying enum types (PR #104582)

2024-08-16 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

We used to always return PT_IntAP(s) for them.

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


2 Files Affected:

- (modified) clang/lib/AST/Interp/Context.cpp (+3) 
- (modified) clang/test/AST/Interp/enums.cpp (+5) 


``diff
diff --git a/clang/lib/AST/Interp/Context.cpp b/clang/lib/AST/Interp/Context.cpp
index 92ac28137fdb45..e9c1fd1b8dc9f9 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -135,6 +135,9 @@ std::optional Context::classify(QualType T) const 
{
   if (T->isAnyComplexType() || T->isVectorType())
 return std::nullopt;
 
+  if (const auto *ET = T->getAs())
+return classify(ET->getDecl()->getIntegerType());
+
   if (T->isSignedIntegerOrEnumerationType()) {
 switch (Ctx.getIntWidth(T)) {
 case 64:
diff --git a/clang/test/AST/Interp/enums.cpp b/clang/test/AST/Interp/enums.cpp
index c4db7875451677..459cf3a0c83d54 100644
--- a/clang/test/AST/Interp/enums.cpp
+++ b/clang/test/AST/Interp/enums.cpp
@@ -48,3 +48,8 @@ constexpr EC getB() {
 
 
 static_assert(getB() == EC::B, "");
+
+namespace B {
+  enum E : bool { Zero, One };
+  static_assert((int)(E)2 == 1, "");
+} // namespace B

``




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


[clang] [llvm] [AArch64] Add a check for invalid default features (PR #104435)

2024-08-16 Thread Tomas Matheson via cfe-commits

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

>From f79eb28441491f1625691886cc92bd05d3b3cb6a Mon Sep 17 00:00:00 2001
From: Tomas Matheson 
Date: Thu, 15 Aug 2024 13:41:31 +0100
Subject: [PATCH 01/12] [AArch64] Add a check for invalid default features

This adds a check that all ExtensionWithMArch which are marked as
implied features for an architecture are also present in the list of
default features. It doesn't make sense to have something mandatory but
not on by default.

There were a number of existing cases that violated this rule, and some
changes to which features are mandatory (indicated by the Implies
field):

> FEAT_SPECRES is mandatory from Armv8.5.
FeaturePredRes is added to the HasV8_5aOps.DefaultExts.

> FEAT_DIT is mandatory from Armv8.4.
FeatureDIT is added to the HasV8_4aOps.DefaultExts.

FEAT_SSBS is not mandatory for any architecture.
https://reviews.llvm.org/D54629 says it is mandatory for 8.5-a but I can't see 
that in the Arm ARM.
FeatureSSBS is removed from Implied and added to HasV8_5aOps.DefaultExts.
Cortex-A710 does not appear to have SSBS
https://developer.arm.com/documentation/101800/0201/The-Cortex-A710--core/Cortex-A710--core-features?lang=en
Removed from the Cortex-A710 and Oryon print-supported-extensions tests.
https://developer.apple.com/download/apple-silicon-cpu-optimization-guide/
Added to Apple A15/A16/A17 and (presumably?) M4 processor features.

> FEAT_BTI is mandatory from Armv8.5.
FeatureBranchTargetId is added to the DefaultExts

> FEAT_FlagM is mandatory from Armv8.4.
FeatureFlagM is added to the DefaultExts

> In an Armv8.4 implementation, if FEAT_AdvSIMD is implemented, FEAT_DotProd is 
> implemented.
FeatureDotProd is added to the HasV8_4aOps.DefaultExts.
FIXME what about nofp here?

> FEAT_SB is mandatory from Armv8.5.
FeatureSB is added to HasV8_5aOps.DefaultExts.
Therefore it appears on the `-cc1` command line for `-march=armv8.5a+nosb`.

> FEAT_WFxT is mandatory from Armv8.7.
FeatureWFxT is added to HasV8_7aOps.DefaultExts and HasV9_2aOps.DefaultExts.

> FEAT_CCIDX is OPTIONAL from Armv8.2.
Removed from Implies and added to HasV8_3aOps.DefaultExts and 
HasV8_0rOps.DefaultExts.

For v8-R, FEAT_CCIDX is not mandatory, removed.
 - Not implemented by cortex-r82, removed:
   https://developer.arm.com/documentation/102670/0300/?lang=en
 - Ditto cortex-r82ae
---
 clang/test/CodeGen/aarch64-targetattr.c   | 12 +++
 clang/test/Driver/arm-sb.c|  2 +-
 .../aarch64-cortex-a710.c |  1 -
 .../aarch64-cortex-r82.c  |  1 -
 .../aarch64-cortex-r82ae.c|  1 -
 .../aarch64-oryon-1.c |  1 -
 .../Preprocessor/aarch64-target-features.c|  4 +--
 llvm/lib/Target/AArch64/AArch64Features.td| 16 +-
 llvm/lib/Target/AArch64/AArch64Processors.td  | 11 ---
 llvm/test/MC/AArch64/armv8.5a-ssbs-error.s|  2 +-
 llvm/test/MC/AArch64/armv8.5a-ssbs.s  |  2 +-
 .../MC/Disassembler/AArch64/armv8.5a-ssbs.txt |  2 +-
 .../TargetParser/TargetParserTest.cpp | 21 ++--
 llvm/utils/TableGen/ARMTargetDefEmitter.cpp   | 32 +--
 14 files changed, 67 insertions(+), 41 deletions(-)

diff --git a/clang/test/CodeGen/aarch64-targetattr.c 
b/clang/test/CodeGen/aarch64-targetattr.c
index 4f891f938b6186..d6227be2ebef83 100644
--- a/clang/test/CodeGen/aarch64-targetattr.c
+++ b/clang/test/CodeGen/aarch64-targetattr.c
@@ -195,19 +195,19 @@ void minusarch() {}
 // CHECK: attributes #[[ATTR0]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+crc,+fp-armv8,+lse,+neon,+ras,+rdm,+v8.1a,+v8.2a,+v8a" }
 // CHECK: attributes #[[ATTR1]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+v8.1a,+v8.2a,+v8a"
 }
 // CHECK: attributes #[[ATTR2]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+crc,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8a"
 }
-// CHECK: attributes #[[ATTR3]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+bf16,+complxnum,+crc,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+neon,+pauth,+ras,+rcpc,+rdm,+sve,+sve2,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8.6a,+v8a"
 }
-// CHECK: attributes #[[ATTR4]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-cpu"="cortex-a710" 
"target-features"="+bf16,+complxnum,+crc,+dotprod,+ete,+flagm,+fp-armv8,+fp16fml,+fullfp16,+i8mm,+jsconv,+lse,+mte,+neon,+pauth,+perfmon,+ras,+rcpc,+rdm,+sb,+sve,+sve2,+sve2-bitperm,+trbe,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8a,+v9a"
 }
+// CHECK: attributes #[[ATTR3]] = { noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-siz

[clang] [llvm] [AArch64] Add a check for invalid default features (PR #104435)

2024-08-16 Thread Tomas Matheson via cfe-commits


@@ -283,9 +311,7 @@ static void EmitARMTargetDef(RecordKeeper &RK, raw_ostream 
&OS) {
 auto Profile = Arch->getValueAsString("Profile");
 auto ArchInfo = ArchInfoName(Major, Minor, Profile);
 
-// The apple-latest alias is backend only, do not expose it to -mcpu.
-if (Name == "apple-latest")
-  continue;

tmatheson-arm wrote:

This check is duplicated at line 260, unrelated to this change.

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


[clang] [clang] Add a new test for CWG2091 (PR #104573)

2024-08-16 Thread via cfe-commits

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

LGTM

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


[clang] [clang] Add a new test for CWG2091 (PR #104573)

2024-08-16 Thread Vlad Serebrennikov via cfe-commits

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


  1   2   3   4   >