[clang] [clang-tools-extra] [llvm] [clang-format] Add support for BasedOnStyle referencing an arbitrary file (PR #107312)

2024-09-05 Thread via cfe-commits

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

I'm with @HazardyKnusperkeks  you are changing too much in one go, get this 
established in clang-format first and then look to rolling out to other tools 
that use lib/format

YAML changes should be separate and agreed with that code owner we don't own 
that

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


[clang] [clang-tools-extra] [llvm] [clang-format] Add support for BasedOnStyle referencing an arbitrary file (PR #107312)

2024-09-05 Thread via cfe-commits

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


[clang] [clang-tools-extra] [llvm] [clang-format] Add support for BasedOnStyle referencing an arbitrary file (PR #107312)

2024-09-05 Thread via cfe-commits


@@ -39,6 +39,10 @@ IO::IO(void *Context) : Ctxt(Context) {}
 
 IO::~IO() = default;
 
+SourceMgr& IO::getSourceMgr() {

mydeveloperday wrote:

This feels like an unrelated changes or change that could be done in isolation 
first

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


[clang] [CGOpenMPRuntime] Avoid repeated hash lookups (NFC) (PR #107358)

2024-09-05 Thread Kazu Hirata via cfe-commits

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

None

>From 7d9d7495ab3ea573e8c0a6c087296b6c43c95a65 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Wed, 4 Sep 2024 23:52:55 -0700
Subject: [PATCH] [CGOpenMPRuntime] Avoid repeated hash lookups (NFC)

---
 clang/lib/CodeGen/CGOpenMPRuntime.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 3d392d869ee39c..9cf597a65be043 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -11674,9 +11674,7 @@ 
CGOpenMPRuntime::LastprivateConditionalRAII::~LastprivateConditionalRAII() {
 Address CGOpenMPRuntime::emitLastprivateConditionalInit(CodeGenFunction &CGF,
 const VarDecl *VD) {
   ASTContext &C = CGM.getContext();
-  auto I = LastprivateConditionalToTypes.find(CGF.CurFn);
-  if (I == LastprivateConditionalToTypes.end())
-I = LastprivateConditionalToTypes.try_emplace(CGF.CurFn).first;
+  auto I = LastprivateConditionalToTypes.try_emplace(CGF.CurFn).first;
   QualType NewType;
   const FieldDecl *VDField;
   const FieldDecl *FiredField;

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


[clang] [clang-tools-extra] [llvm] [clang-format] Add support for BasedOnStyle referencing an arbitrary file (PR #107312)

2024-09-05 Thread via cfe-commits


@@ -5274,9 +5274,17 @@ struct FormatStyle {
 
   friend std::error_code
   parseConfiguration(llvm::MemoryBufferRef Config, FormatStyle *Style,
+ const std::vector &StyleSearchPaths,

mydeveloperday wrote:

by putting your argument 3rd you made every instance of this function need to 
change..

you could have added it last and used a default argument, or made an overloaded 
function and a wrapper for the old one to call the new with the empty argument 
this would cut down the flux

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


[clang] [CGOpenMPRuntime] Avoid repeated hash lookups (NFC) (PR #107358)

2024-09-05 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: Kazu Hirata (kazutakahirata)


Changes



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


1 Files Affected:

- (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+1-3) 


``diff
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 3d392d869ee39c..9cf597a65be043 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -11674,9 +11674,7 @@ 
CGOpenMPRuntime::LastprivateConditionalRAII::~LastprivateConditionalRAII() {
 Address CGOpenMPRuntime::emitLastprivateConditionalInit(CodeGenFunction &CGF,
 const VarDecl *VD) {
   ASTContext &C = CGM.getContext();
-  auto I = LastprivateConditionalToTypes.find(CGF.CurFn);
-  if (I == LastprivateConditionalToTypes.end())
-I = LastprivateConditionalToTypes.try_emplace(CGF.CurFn).first;
+  auto I = LastprivateConditionalToTypes.try_emplace(CGF.CurFn).first;
   QualType NewType;
   const FieldDecl *VDField;
   const FieldDecl *FiredField;

``




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


[clang] [clang-tools-extra] [llvm] [clang-format] Add support for BasedOnStyle referencing an arbitrary file (PR #107312)

2024-09-05 Thread via cfe-commits

mydeveloperday wrote:

> You are touching a lot of projects. I don't know how others feel about that, 
> but my preference would be to tackle one project per PR.

+1

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


[clang] [clang-format] Add new option: WrapNamespaceBodyWithNewlines (PR #106145)

2024-09-05 Thread via cfe-commits


@@ -28104,6 +28104,251 @@ TEST_F(FormatTest, BreakBinaryOperations) {
Style);
 }
 
+TEST_F(FormatTest, WrapNamespaceBodyWithEmptyLinesNever) {
+  FormatStyle Style = getLLVMStyle();
+  Style.FixNamespaceComments = false;
+  Style.ShortNamespaceLines = 0;
+  Style.MaxEmptyLinesToKeep = 2;
+  Style.WrapNamespaceBodyWithEmptyLines = FormatStyle::WNBWELS_Never;
+  Style.CompactNamespaces = false;
+
+  // Empty namespace
+  verifyNoChange("namespace N {};", Style);
+
+  // Single namespace
+  verifyNoChange("namespace N {\n"
+ "int f1(int a) { return 2 * a; }\n"
+ "};",
+ Style);
+
+  // Nested namespace
+  verifyNoChange("namespace N1 {\n"

mydeveloperday wrote:

Ok, but the idea is that it messes with code as if the person was editing a 
file and this was the first clang-format, I've never needed to use 
`verifyNoChange` tests failing often meant I wasn't doing the correct thing

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


[clang] [clang-format] Add new option: WrapNamespaceBodyWithNewlines (PR #106145)

2024-09-05 Thread via cfe-commits


@@ -32,6 +32,26 @@ bool isRecordLBrace(const FormatToken &Tok) {
  TT_StructLBrace, TT_UnionLBrace);
 }
 
+bool LineStartsNamespaceScope(const AnnotatedLine *Line,
+  const AnnotatedLine *PreviousLine,
+  const AnnotatedLine *PrevPrevLine) {
+  return PreviousLine &&
+ ((PreviousLine->Last->is(tok::l_brace) &&

mydeveloperday wrote:

Ok, just trying to remind myself

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


[clang] [clang-format] Add options to set number of empty lines after includes (PR #78957)

2024-09-05 Thread via cfe-commits

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


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


[clang] [clang-format] Add options to set number of empty lines after includes (PR #78957)

2024-09-05 Thread via cfe-commits


@@ -3220,6 +3220,25 @@ the configuration (without a prefix: ``Auto``).
 
 
 
+.. _EmptyLinesAfterIncludes:
+
+**EmptyLinesAfterIncludes** (``Unsigned``) :versionbadge:`clang-format 18` 
:ref:`¶ `

mydeveloperday wrote:

18 is now wrong it should be 20

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


[clang] clang-format: Add "AllowShortNamespacesOnASingleLine" option (PR #105597)

2024-09-05 Thread via cfe-commits

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


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


[clang] clang-format: Add "AllowShortNamespacesOnASingleLine" option (PR #105597)

2024-09-05 Thread via cfe-commits


@@ -972,6 +972,11 @@ struct FormatStyle {
   /// \version 3.7
   bool AllowShortLoopsOnASingleLine;
 
+  /// If ``true``, ``namespace a { class b; }`` can be put on a single a single
+  /// line.
+  /// \version 19

mydeveloperday wrote:

19 is now wrong it should be 20

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


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-09-05 Thread via cfe-commits

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


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


[clang] [clang-format] add an option to insert a space only for non-code block empty braces, not for empty parentheses (PR #93634)

2024-09-05 Thread via cfe-commits


@@ -6036,12 +6036,106 @@ the configuration (without a prefix: ``Auto``).
 
 **SpaceInEmptyBlock** (``Boolean``) :versionbadge:`clang-format 10` :ref:`¶ 
`
   If ``true``, spaces will be inserted into ``{}``.
+  This option is **deprecated**. The previous behavior is preserved by using
+  ``SpaceInEmptyBraces`` with ``Custom`` and by setting ``Block`` in
+  ``SpaceInEmptyBracesOptions`` to ``true``.
+
+.. _SpaceInEmptyBraces:
+
+**SpaceInEmptyBraces** (``SpaceInEmptyBracesStyle``) 
:versionbadge:`clang-format 19` :ref:`¶ `

mydeveloperday wrote:

19 is now wrong it should be 20

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


[clang] [CGOpenMPRuntime] Avoid repeated hash lookups (NFC) (PR #107358)

2024-09-05 Thread Nikita Popov via cfe-commits

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

LGTM

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


[clang] [Analysis] Avoid repeated hash lookups (NFC) (PR #107357)

2024-09-05 Thread Nikita Popov via cfe-commits

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

LGTM

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


[clang] [Clang][SemaCXX] Preserve qualifiers in derived-to-base cast in defaulted comparison operators (PR #102619)

2024-09-05 Thread via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/102619

>From fc436186e37ff9852269599c750f8e836aee5e99 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Fri, 9 Aug 2024 15:03:38 +0100
Subject: [PATCH] [Clang][SemaCXX] Preserve qualifiers in derived-to-base cast
 in defaulted comparison operators

---
 clang/docs/ReleaseNotes.rst  |  1 +
 clang/lib/Sema/SemaDeclCXX.cpp   | 10 ++--
 clang/test/SemaCXX/cxx20-default-compare.cpp | 50 
 3 files changed, 57 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7a05ccf3184111..30bc36bd0d6cd7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -216,6 +216,7 @@ Bug Fixes to C++ Support
 - Clang now preserves the unexpanded flag in a lambda transform used for pack 
expansion. (#GH56852), (#GH85667),
   (#GH99877).
 - Fixed a bug when diagnosing ambiguous explicit specializations of 
constrained member functions.
+- Fixed a bug where defaulted comparison operators would remove ``const`` from 
base classes. (#GH102588)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index b07e555afcaccf..08c4cb8e144f6d 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -8414,10 +8414,12 @@ class DefaultedComparisonSynthesizer
 if (Obj.first.isInvalid() || Obj.second.isInvalid())
   return {ExprError(), ExprError()};
 CXXCastPath Path = {Base};
-return {S.ImpCastExprToType(Obj.first.get(), Base->getType(),
-CK_DerivedToBase, VK_LValue, &Path),
-S.ImpCastExprToType(Obj.second.get(), Base->getType(),
-CK_DerivedToBase, VK_LValue, &Path)};
+const auto CastToBase = [&](Expr *E) {
+  QualType ToType = S.Context.getQualifiedType(
+  Base->getType(), E->getType().getQualifiers());
+  return S.ImpCastExprToType(E, ToType, CK_DerivedToBase, VK_LValue, 
&Path);
+};
+return {CastToBase(Obj.first.get()), CastToBase(Obj.second.get())};
   }
 
   ExprPair getField(FieldDecl *Field) {
diff --git a/clang/test/SemaCXX/cxx20-default-compare.cpp 
b/clang/test/SemaCXX/cxx20-default-compare.cpp
index 7074ee885ac4a2..3e4673c31e4890 100644
--- a/clang/test/SemaCXX/cxx20-default-compare.cpp
+++ b/clang/test/SemaCXX/cxx20-default-compare.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 %s -std=c++23 -verify -Wfloat-equal
 
+#include "Inputs/std-compare.h"
+
 struct Foo {
   float val;
   bool operator==(const Foo &) const;
@@ -15,3 +17,51 @@ bool operator==(const Foo &, const Foo &) = default;  // 
expected-warning {{comp
 
 // Declare the defaulted comparison function as a non-member function. 
Arguments are passed by value.
 bool operator==(Foo, Foo) = default;  // expected-warning {{comparing floating 
point with == or != is unsafe}} expected-note {{in defaulted equality 
comparison operator for 'Foo' first required here}}
+
+namespace GH102588 {
+struct A {
+  int i = 0;
+  constexpr operator int() const { return i; }
+  constexpr operator int&() { return ++i; }
+};
+
+struct B : A {
+  bool operator==(const B &) const = default;
+};
+
+constexpr bool f() {
+  B x;
+  return x == x;
+}
+
+static_assert(f());
+
+struct ConstOnly {
+  std::strong_ordering operator<=>(const ConstOnly&) const;
+  std::strong_ordering operator<=>(ConstOnly&) = delete;
+  friend bool operator==(const ConstOnly&, const ConstOnly&);
+  friend bool operator==(ConstOnly&, ConstOnly&) = delete;
+};
+
+struct MutOnly {
+  std::strong_ordering operator<=>(const MutOnly&) const = delete;;
+  std::strong_ordering operator<=>(MutOnly&);
+  friend bool operator==(const MutOnly&, const MutOnly&) = delete;;
+  friend bool operator==(MutOnly&, MutOnly&);
+};
+
+struct ConstCheck : ConstOnly {
+  friend std::strong_ordering operator<=>(const ConstCheck&, const 
ConstCheck&) = default;
+  std::strong_ordering operator<=>(ConstCheck const& __restrict) const 
__restrict = default;
+  friend bool operator==(const ConstCheck&, const ConstCheck&) = default;
+  bool operator==(this const ConstCheck&, const ConstCheck&) = default;
+};
+
+// FIXME: Non-reference explicit object parameter are rejected
+struct MutCheck : MutOnly {
+  friend bool operator==(MutCheck, MutCheck) = default;
+  // std::strong_ordering operator<=>(this MutCheck, MutCheck) = default;
+  friend std::strong_ordering operator<=>(MutCheck, MutCheck) = default;
+  // bool operator==(this MutCheck, MutCheck) = default;
+};
+}

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


[clang] [Clang][SemaCXX] Preserve qualifiers in derived-to-base cast in defaulted comparison operators (PR #102619)

2024-09-05 Thread via cfe-commits

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


[clang] f1ac334 - [Clang][SemaCXX] Preserve qualifiers in derived-to-base cast in defaulted comparison operators (#102619)

2024-09-05 Thread via cfe-commits

Author: Mital Ashok
Date: 2024-09-05T09:41:39+02:00
New Revision: f1ac334b13c2ed5c71bad04ed8345b2be135

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

LOG: [Clang][SemaCXX] Preserve qualifiers in derived-to-base cast in defaulted 
comparison operators (#102619)

Fixes #102588

Co-authored-by: cor3ntin 

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaCXX/cxx20-default-compare.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1520f7a2916aae..44ffad94ef41fc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -355,6 +355,8 @@ Bug Fixes to C++ Support
 - Fix an issue with dependent source location expressions (#GH106428), 
(#GH81155), (#GH80210), (#GH85373)
 - Fixed a bug in the substitution of empty pack indexing types. (#GH105903)
 - Clang no longer tries to capture non-odr used default arguments of template 
parameters of generic lambdas (#GH107048)
+- Fixed a bug where defaulted comparison operators would remove ``const`` from 
base classes. (#GH102588)
+
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 3044f1218f5b23..f90f16c2923d03 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -8450,10 +8450,12 @@ class DefaultedComparisonSynthesizer
 if (Obj.first.isInvalid() || Obj.second.isInvalid())
   return {ExprError(), ExprError()};
 CXXCastPath Path = {Base};
-return {S.ImpCastExprToType(Obj.first.get(), Base->getType(),
-CK_DerivedToBase, VK_LValue, &Path),
-S.ImpCastExprToType(Obj.second.get(), Base->getType(),
-CK_DerivedToBase, VK_LValue, &Path)};
+const auto CastToBase = [&](Expr *E) {
+  QualType ToType = S.Context.getQualifiedType(
+  Base->getType(), E->getType().getQualifiers());
+  return S.ImpCastExprToType(E, ToType, CK_DerivedToBase, VK_LValue, 
&Path);
+};
+return {CastToBase(Obj.first.get()), CastToBase(Obj.second.get())};
   }
 
   ExprPair getField(FieldDecl *Field) {

diff  --git a/clang/test/SemaCXX/cxx20-default-compare.cpp 
b/clang/test/SemaCXX/cxx20-default-compare.cpp
index 7074ee885ac4a2..3e4673c31e4890 100644
--- a/clang/test/SemaCXX/cxx20-default-compare.cpp
+++ b/clang/test/SemaCXX/cxx20-default-compare.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 %s -std=c++23 -verify -Wfloat-equal
 
+#include "Inputs/std-compare.h"
+
 struct Foo {
   float val;
   bool operator==(const Foo &) const;
@@ -15,3 +17,51 @@ bool operator==(const Foo &, const Foo &) = default;  // 
expected-warning {{comp
 
 // Declare the defaulted comparison function as a non-member function. 
Arguments are passed by value.
 bool operator==(Foo, Foo) = default;  // expected-warning {{comparing floating 
point with == or != is unsafe}} expected-note {{in defaulted equality 
comparison operator for 'Foo' first required here}}
+
+namespace GH102588 {
+struct A {
+  int i = 0;
+  constexpr operator int() const { return i; }
+  constexpr operator int&() { return ++i; }
+};
+
+struct B : A {
+  bool operator==(const B &) const = default;
+};
+
+constexpr bool f() {
+  B x;
+  return x == x;
+}
+
+static_assert(f());
+
+struct ConstOnly {
+  std::strong_ordering operator<=>(const ConstOnly&) const;
+  std::strong_ordering operator<=>(ConstOnly&) = delete;
+  friend bool operator==(const ConstOnly&, const ConstOnly&);
+  friend bool operator==(ConstOnly&, ConstOnly&) = delete;
+};
+
+struct MutOnly {
+  std::strong_ordering operator<=>(const MutOnly&) const = delete;;
+  std::strong_ordering operator<=>(MutOnly&);
+  friend bool operator==(const MutOnly&, const MutOnly&) = delete;;
+  friend bool operator==(MutOnly&, MutOnly&);
+};
+
+struct ConstCheck : ConstOnly {
+  friend std::strong_ordering operator<=>(const ConstCheck&, const 
ConstCheck&) = default;
+  std::strong_ordering operator<=>(ConstCheck const& __restrict) const 
__restrict = default;
+  friend bool operator==(const ConstCheck&, const ConstCheck&) = default;
+  bool operator==(this const ConstCheck&, const ConstCheck&) = default;
+};
+
+// FIXME: Non-reference explicit object parameter are rejected
+struct MutCheck : MutOnly {
+  friend bool operator==(MutCheck, MutCheck) = default;
+  // std::strong_ordering operator<=>(this MutCheck, MutCheck) = default;
+  friend std::strong_ordering operator<=>(MutCheck, MutCheck) = default;
+  // bool operator==(this MutCheck, MutCheck) = default;
+};
+}



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


[clang] [Clang] Add __builtin_is_within_lifetime to implement P2641R4's std::is_within_lifetime (PR #91895)

2024-09-05 Thread via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/91895

>From f602189e20d15d7805b40f60b9383c83117b7d04 Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Tue, 20 Aug 2024 13:23:52 +0100
Subject: [PATCH 1/4] [Clang] Add __builtin_is_within_lifetime to implement
 P2641R4's std::is_within_lifetime

Squashed all previous commits (no longer in draft)
---
 clang/include/clang/Basic/Builtins.td |   6 +
 .../include/clang/Basic/DiagnosticASTKinds.td |  12 +-
 .../clang/Basic/DiagnosticSemaKinds.td|   3 +
 clang/lib/AST/ByteCode/State.h|   1 +
 clang/lib/AST/ExprConstant.cpp| 108 -
 clang/lib/CodeGen/CGBuiltin.cpp   |   3 +
 clang/lib/Sema/SemaChecking.cpp   |  36 ++
 clang/lib/Sema/SemaExpr.cpp   |   3 +-
 .../SemaCXX/builtin-is-within-lifetime.cpp| 435 ++
 clang/test/SemaCXX/consteval-builtin.cpp  |  93 
 10 files changed, 693 insertions(+), 7 deletions(-)
 create mode 100644 clang/test/SemaCXX/builtin-is-within-lifetime.cpp
 create mode 100644 clang/test/SemaCXX/consteval-builtin.cpp

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 036366cdadf4aa..e2cbf2ac69107d 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -934,6 +934,12 @@ def IsConstantEvaluated : LangBuiltin<"CXX_LANG"> {
   let Prototype = "bool()";
 }
 
+def IsWithinLifetime : LangBuiltin<"CXX_LANG"> {
+  let Spellings = ["__builtin_is_within_lifetime"];
+  let Attributes = [NoThrow, CustomTypeChecking, Consteval];
+  let Prototype = "bool(void*)";
+}
+
 // GCC exception builtins
 def EHReturn : Builtin {
   let Spellings = ["__builtin_eh_return"];
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index f317c5ac44f32b..581640b433568d 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -169,14 +169,14 @@ def note_constexpr_this : Note<
 def access_kind : TextSubstitution<
   "%select{read of|read of|assignment to|increment of|decrement of|"
   "member call on|dynamic_cast of|typeid applied to|construction of|"
-  "destruction of}0">;
+  "destruction of|read of}0">;
 def access_kind_subobject : TextSubstitution<
   "%select{read of|read of|assignment to|increment of|decrement of|"
   "member call on|dynamic_cast of|typeid applied to|"
-  "construction of subobject of|destruction of}0">;
+  "construction of subobject of|destruction of|read of}0">;
 def access_kind_volatile : TextSubstitution<
   "%select{read of|read of|assignment to|increment of|decrement of|"
-  "}0">;
+  "|}0">;
 def note_constexpr_lifetime_ended : Note<
   "%sub{access_kind}0 %select{temporary|variable}1 whose "
   "%plural{8:storage duration|:lifetime}0 has ended">;
@@ -408,6 +408,12 @@ def warn_is_constant_evaluated_always_true_constexpr : 
Warning<
   "'%0' will always evaluate to 'true' in a manifestly constant-evaluated 
expression">,
   InGroup>;
 
+def err_invalid_is_within_lifetime : Note<
+  "'%0' cannot be called with "
+  "%select{a null pointer|a function pointer|a one-past-the-end pointer|"
+  "a pointer to an object whose lifetime has not yet begun}1"
+>;
+
 // inline asm related.
 let CategoryName = "Inline Assembly Issue" in {
   def err_asm_invalid_escape : Error<
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 4b6aadd635786a..e50ea9bf20763c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -12190,6 +12190,9 @@ def err_builtin_launder_invalid_arg : Error<
   "%select{non-pointer|function pointer|void pointer}0 argument to "
   "'__builtin_launder' is not allowed">;
 
+def err_builtin_is_within_lifetime_invalid_arg : Error<
+  "non-pointer argument to '__builtin_is_within_lifetime' is not allowed">;
+
 def err_builtin_invalid_arg_type: Error <
   "%ordinal0 argument must be "
   "%select{a vector, integer or floating point type|a matrix|"
diff --git a/clang/lib/AST/ByteCode/State.h b/clang/lib/AST/ByteCode/State.h
index 44d6c037c5ad95..c163fd2952 100644
--- a/clang/lib/AST/ByteCode/State.h
+++ b/clang/lib/AST/ByteCode/State.h
@@ -34,6 +34,7 @@ enum AccessKinds {
   AK_TypeId,
   AK_Construct,
   AK_Destroy,
+  AK_IsWithinLifetime,
 };
 
 /// The order of this enum is important for diagnostics.
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 5540f58b526705..9f12fcf9ad7dce 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -1522,7 +1522,8 @@ CallStackFrame::~CallStackFrame() {
 }
 
 static bool isRead(AccessKinds AK) {
-  return AK == AK_Read || AK == AK_ReadObjectRepresentation;
+  return AK == AK_Read || AK == AK_ReadObjectRepresentation ||
+ AK == AK_IsWithinLifetime;
 }
 

[clang] [clang] Diagnose dangling issues for the "Container" case. (PR #107213)

2024-09-05 Thread Haojian Wu via cfe-commits

https://github.com/hokein updated 
https://github.com/llvm/llvm-project/pull/107213

>From 0d9a5971121bf66608625de3514db346876d9091 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Wed, 28 Aug 2024 09:59:41 +0200
Subject: [PATCH 1/2] [clang] Diagnose dangling issues for
 "Container" case.

We teach the GSL lifetime analysis to handle this code path, particuly
when constructing the container object from a GSLOwner.
---
 clang/lib/Sema/CheckExprLifetime.cpp  | 29 +---
 .../Sema/warn-lifetime-analysis-nocfg.cpp | 44 +++
 2 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Sema/CheckExprLifetime.cpp 
b/clang/lib/Sema/CheckExprLifetime.cpp
index 1482711cc2839e..70d1de27fa086e 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -361,10 +361,14 @@ static bool implicitObjectParamIsLifetimeBound(const 
FunctionDecl *FD) {
 if (ATL.getAttrAs())
   return true;
   }
-
   return isNormalAsisgnmentOperator(FD);
 }
 
+bool isFirstTemplateArgumentGSLPointer(const TemplateArgumentList &TAs) {
+  return TAs.size() > 0 && TAs[0].getKind() == TemplateArgument::Type &&
+ isRecordWithAttr(TAs[0].getAsType());
+}
+
 // Visit lifetimebound or gsl-pointer arguments.
 static void visitFunctionCallArguments(IndirectLocalPath &Path, Expr *Call,
LocalVisitor Visit) {
@@ -465,14 +469,27 @@ static void visitFunctionCallArguments(IndirectLocalPath 
&Path, Expr *Call,
   if (shouldTrackFirstArgument(Callee)) {
 VisitGSLPointerArg(Callee, Args[0],
!Callee->getReturnType()->isReferenceType());
-  } else if (auto *CCE = dyn_cast(Call);
- CCE &&
- CCE->getConstructor()->getParent()->hasAttr()) {
-VisitGSLPointerArg(CCE->getConstructor()->getParamDecl(0), Args[0],
-   true);
+  } else if (auto *Ctor = dyn_cast(Call)) {
+const auto *ClassD = Ctor->getConstructor()->getParent();
+// Constructing the Container case (e.g.
+// std::optional) case.
+if (const auto *CTSD =
+dyn_cast(ClassD)) {
+  if (isFirstTemplateArgumentGSLPointer(CTSD->getTemplateArgs()) &&
+  CTSD->hasAttr()) {
+VisitGSLPointerArg(Ctor->getConstructor()->getParamDecl(0), 
Args[0],
+   true);
+return;
+  }
+}
+// Constructing the GSLPointer (e.g. std::string_view) case.
+if (ClassD->hasAttr())
+  VisitGSLPointerArg(Ctor->getConstructor()->getParamDecl(0), Args[0],
+ true);
   }
 }
   }
+  }
 }
 
 /// Visit the locals that would be reachable through a reference bound to the
diff --git a/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp 
b/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
index 67d1ceaa02d039..91756e80ef9e8b 100644
--- a/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
+++ b/clang/test/Sema/warn-lifetime-analysis-nocfg.cpp
@@ -158,17 +158,26 @@ auto begin(C &c) -> decltype(c.begin());
 template
 T *begin(T (&array)[N]);
 
+using size_t = decltype(sizeof(0));
+
+template
+struct initializer_list {
+  const T* ptr; size_t sz;
+};
 template 
 struct vector {
   typedef __gnu_cxx::basic_iterator iterator;
   iterator begin();
   iterator end();
   const T *data() const;
+  vector();
+  vector(initializer_list __l);
   T &at(int n);
 };
 
 template
 struct basic_string_view {
+  basic_string_view();
   basic_string_view(const T *);
   const T *begin() const;
 };
@@ -203,11 +212,21 @@ template
 struct optional {
   optional();
   optional(const T&);
+
+  template
+   optional(U&& t);
+
+  template
+   optional(optional&& __t);
+
   T &operator*() &;
   T &&operator*() &&;
   T &value() &;
   T &&value() &&;
 };
+template
+optional make_optional(T&&);
+
 
 template
 struct stack {
@@ -525,3 +544,28 @@ void test() {
   std::string_view svjkk1 = ReturnStringView(StrCat("bar", "x")); // 
expected-warning {{object backing the pointer will be destroyed at the end of 
the full-expression}}
 }
 } // namespace GH100549
+
+namespace GH100526 {
+void test() {
+  std::vector t1 = {std::string()}; // expected-warning 
{{object backing the pointer will be destroyed at the end}}
+  std::optional t2 = std::string(); // expected-warning 
{{object backing the pointer}}
+
+  std::string s;
+  // This is a tricky use-after-free case, what it does:
+  //   1. make_optional creates a temporary "optional"" object
+  //   2. the temporary object owns the underlying string which is copied from 
s.
+  //   3. the t3 object holds the view to the underlying string of the 
temporary object.
+  std::optional t3 = std::make_optional(s); // 
expected-warning {{object backing the pointer}}
+
+  // FIXME: should work for assignment cases
+  t1 = {std::string()};
+  t2 = std::string();
+
+  // no warning on copying pointers.
+  std::vector 

[clang] [clang][bytecode] Implement comparsion operators for vector type (PR #107258)

2024-09-05 Thread Timm Baeder via cfe-commits


@@ -1222,6 +1224,117 @@ bool Compiler::VisitComplexBinOp(const 
BinaryOperator *E) {
   return true;
 }
 
+template 
+bool Compiler::VisitVectorBinOp(const BinaryOperator *E) {
+  assert(E->getType()->isVectorType());
+
+  // FIXME: Current only support comparison binary operator, add support for
+  // other binary operator.
+  if (!E->isComparisonOp())
+return this->emitInvalid(E);
+  // Prepare storage for result.
+  if (!Initializing) {
+unsigned LocalIndex = allocateTemporary(E);
+if (!this->emitGetPtrLocal(LocalIndex, E))
+  return false;
+  }
+
+  const Expr *LHS = E->getLHS();
+  const Expr *RHS = E->getRHS();
+  const auto *VecTy = E->getType()->getAs();
+
+  // The LHS and RHS of a comparison operator must have the same type. So we

tbaederr wrote:

Add an assertion if that's the case.

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


[clang] [clang][bytecode] Implement comparsion operators for vector type (PR #107258)

2024-09-05 Thread Timm Baeder via cfe-commits


@@ -1222,6 +1224,117 @@ bool Compiler::VisitComplexBinOp(const 
BinaryOperator *E) {
   return true;
 }
 
+template 
+bool Compiler::VisitVectorBinOp(const BinaryOperator *E) {
+  assert(E->getType()->isVectorType());
+
+  // FIXME: Current only support comparison binary operator, add support for
+  // other binary operator.
+  if (!E->isComparisonOp())
+return this->emitInvalid(E);
+  // Prepare storage for result.
+  if (!Initializing) {
+unsigned LocalIndex = allocateTemporary(E);
+if (!this->emitGetPtrLocal(LocalIndex, E))
+  return false;
+  }
+
+  const Expr *LHS = E->getLHS();
+  const Expr *RHS = E->getRHS();
+  const auto *VecTy = E->getType()->getAs();
+
+  // The LHS and RHS of a comparison operator must have the same type. So we
+  // just use LHS vector element type here.
+  PrimType ElemT = this->classifyVectorElementType(LHS->getType());
+  PrimType ResultElemT = this->classifyVectorElementType(E->getType());
+
+  // Evaluate LHS and save value to LHSOffset.
+  unsigned LHSOffset = this->allocateLocalPrimitive(LHS, PT_Ptr, true, false);
+  if (!this->visit(LHS))
+return false;
+  if (!this->emitSetLocal(PT_Ptr, LHSOffset, E))
+return false;
+
+  // Evaluate RHS and save value to RHSOffset.
+  unsigned RHSOffset = this->allocateLocalPrimitive(RHS, PT_Ptr, true, false);
+  if (!this->visit(RHS))
+return false;
+  if (!this->emitSetLocal(PT_Ptr, RHSOffset, E))
+return false;
+
+  auto getElem = [=](unsigned Offset, unsigned Index, PrimType ElemT) -> bool {
+if (!this->emitGetLocal(PT_Ptr, Offset, E))
+  return false;
+return this->emitArrayElemPop(ElemT, Index, E);
+  };
+
+  for (unsigned I = 0; I != VecTy->getNumElements(); ++I) {
+if (!getElem(LHSOffset, I, ElemT))
+  return false;
+if (!getElem(RHSOffset, I, ElemT))
+  return false;
+if (E->isComparisonOp()) {
+  if (!this->emitVectorComparison(E))
+return false;
+} else {
+  llvm_unreachable("Unsupported binary operator");
+}
+if (!this->emitInitElem(ResultElemT, I, E))
+  return false;
+  }
+  return true;
+}
+
+template 
+bool Compiler::emitVectorComparison(const BinaryOperator *E) {

tbaederr wrote:

I don't think we're going to use this anywhere else, so a separate function 
shouldn't be necessary

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


[clang] [clang][bytecode] Implement comparsion operators for vector type (PR #107258)

2024-09-05 Thread Timm Baeder via cfe-commits


@@ -1222,6 +1224,117 @@ bool Compiler::VisitComplexBinOp(const 
BinaryOperator *E) {
   return true;
 }
 
+template 
+bool Compiler::VisitVectorBinOp(const BinaryOperator *E) {
+  assert(E->getType()->isVectorType());

tbaederr wrote:

Add an assertion that both LHS and RHS are also of vector type.

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


[clang-tools-extra] [clang-tidy] Add user-defined functions to `bugprone-unsafe-functions` check (PR #106350)

2024-09-05 Thread Kristóf Umann via cfe-commits

Szelethus wrote:

> `CustomAnnexKFunctions` exists because the checker has two different internal 
> matching modes for whether AnnexK is enabled or not. This both depends on 
> `__STDC_LIB_EXT1__` (defined by system) `__STDC_WANT_LIB_EXT1__` (defined by 
> the user), so it's reasonable to expect that a project could have differing 
> availability of AnnexK.
> 
> I could rename CustomNormalFunctions to CustomFunctions or something to make 
> it clearer that it's always available.

I'm still not sure why we need both `CustomNormalFunctions` and 
`CustomAnnexKFunctions`. From what I understand, this is due  to something 
specific in implementation, but why is it the user that needs to bear that 
burden? Can we eliminate one of these options?

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


[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-09-05 Thread via cfe-commits

cor3ntin wrote:

@MitalAshok can you fix the conflicts and ping me so i can merge?

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


[clang] cf1ad28 - [clang][ExtractAPI] Handle AttributedType fragments transparently (#107262)

2024-09-05 Thread via cfe-commits

Author: Daniel Grumberg
Date: 2024-09-05T09:15:09+01:00
New Revision: cf1ad28169be5d026ec95f351b56b0c090b3e682

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

LOG: [clang][ExtractAPI] Handle AttributedType fragments transparently (#107262)

rdar://131958623

Added: 
clang/test/ExtractAPI/attributed-typedef.m

Modified: 
clang/lib/ExtractAPI/DeclarationFragments.cpp

Removed: 




diff  --git a/clang/lib/ExtractAPI/DeclarationFragments.cpp 
b/clang/lib/ExtractAPI/DeclarationFragments.cpp
index d77bb1d424f7cf..06ce5ed6a64756 100644
--- a/clang/lib/ExtractAPI/DeclarationFragments.cpp
+++ b/clang/lib/ExtractAPI/DeclarationFragments.cpp
@@ -276,6 +276,19 @@ DeclarationFragments 
DeclarationFragmentsBuilder::getFragmentsForType(
 
   DeclarationFragments Fragments;
 
+  if (const MacroQualifiedType *MQT = dyn_cast(T)) {
+Fragments.append(
+getFragmentsForType(MQT->getUnderlyingType(), Context, After));
+return Fragments;
+  }
+
+  if (const AttributedType *AT = dyn_cast(T)) {
+// FIXME: Serialize Attributes correctly
+Fragments.append(
+getFragmentsForType(AT->getModifiedType(), Context, After));
+return Fragments;
+  }
+
   // An ElaboratedType is a sugar for types that are referred to using an
   // elaborated keyword, e.g., `struct S`, `enum E`, or (in C++) via a
   // qualified name, e.g., `N::M::type`, or both.

diff  --git a/clang/test/ExtractAPI/attributed-typedef.m 
b/clang/test/ExtractAPI/attributed-typedef.m
new file mode 100644
index 00..c948c873ab759c
--- /dev/null
+++ b/clang/test/ExtractAPI/attributed-typedef.m
@@ -0,0 +1,24 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -extract-api --pretty-sgf 
--emit-sgf-symbol-labels-for-testing \
+// RUN:   -triple arm64-apple-macosx -x objective-c-header %s -o 
%t/output.symbols.json
+
+_Pragma("clang assume_nonnull begin")
+
+struct Foo { int a; };
+typedef struct Foo *Bar;
+// RUN: FileCheck %s -input-file %t/output.symbols.json --check-prefix FUNC
+void func(Bar b);
+// FUNC-LABEL: "!testLabel": "c:@F@func",
+// CHECK-NOT: Foo
+// CHECK: "pathComponents"
+
+// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix THING
+#define SWIFT_NAME(_name) __attribute__((swift_name(#_name)))
+extern Bar const thing SWIFT_NAME(swiftThing);
+// THING-LABEL: "!testLabel": "c:@thing"
+// THING-NOT: Foo
+// THING: "pathComponents"
+
+_Pragma("clang assume_nonnull end")
+
+// expected-no-diagnostics



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


[clang] [clang][ExtractAPI] Handle AttributedType fragments transparently (PR #107262)

2024-09-05 Thread Daniel Grumberg via cfe-commits

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


[clang] 4137309 - [Clang] Warn with -Wpre-c23-compat instead of -Wpre-c++17-compat for u8 character literals in C23 (#97210)

2024-09-05 Thread via cfe-commits

Author: Mital Ashok
Date: 2024-09-05T10:15:54+02:00
New Revision: 41373098421f2aa551a0879537864c87d797a102

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

LOG: [Clang] Warn with -Wpre-c23-compat instead of -Wpre-c++17-compat for u8 
character literals in C23 (#97210)

Co-authored-by: cor3ntin 

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/Lexer.cpp
clang/test/Sema/pre-c2x-compat.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 44ffad94ef41fc..bd84a2e40fb8bd 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -278,6 +278,8 @@ Improvements to Clang's diagnostics
 - The lifetimebound and GSL analysis in clang are coherent, allowing clang to
   detect more use-after-free bugs. (#GH100549).
 
+- Clang now warns for u8 character literals used in C23 with 
``-Wpre-c23-compat`` instead of ``-Wpre-c++17-compat``.
+
 Improvements to Clang's time-trace
 --
 

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 12d7b8c0205ee9..fc14bb6aa21651 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -283,6 +283,9 @@ def warn_cxx98_compat_unicode_literal : Warning<
 def warn_cxx14_compat_u8_character_literal : Warning<
   "unicode literals are incompatible with C++ standards before C++17">,
   InGroup, DefaultIgnore;
+def warn_c17_compat_u8_character_literal : Warning<
+  "unicode literals are incompatible with C standards before C23">,
+  InGroup, DefaultIgnore;
 def warn_cxx11_compat_user_defined_literal : Warning<
   "identifier after literal will be treated as a user-defined literal suffix "
   "in C++11">, InGroup, DefaultIgnore;

diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index ef1e1f4bd9aeb4..8647e9f2f27c3d 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2428,7 +2428,9 @@ bool Lexer::LexCharConstant(Token &Result, const char 
*CurPtr,
   ? diag::warn_cxx98_compat_unicode_literal
   : diag::warn_c99_compat_unicode_literal);
 else if (Kind == tok::utf8_char_constant)
-  Diag(BufferPtr, diag::warn_cxx14_compat_u8_character_literal);
+  Diag(BufferPtr, LangOpts.CPlusPlus
+  ? diag::warn_cxx14_compat_u8_character_literal
+  : diag::warn_c17_compat_u8_character_literal);
   }
 
   char C = getAndAdvanceChar(CurPtr, Result);

diff  --git a/clang/test/Sema/pre-c2x-compat.c 
b/clang/test/Sema/pre-c2x-compat.c
index fad472f1f72d54..15bb9b58349fad 100644
--- a/clang/test/Sema/pre-c2x-compat.c
+++ b/clang/test/Sema/pre-c2x-compat.c
@@ -1,3 +1,4 @@
 // RUN: %clang_cc1 %s -std=c2x -Wpre-c2x-compat -pedantic -fsyntax-only -verify
 
 int digit_seps = 123'456; // expected-warning {{digit separators are 
incompatible with C standards before C23}}
+unsigned char u8_char = u8'x'; // expected-warning {{unicode literals are 
incompatible with C standards before C23}}



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


[clang] [Clang] Warn with -Wpre-c23-compat instead of -Wpre-c++17-compat for u8 character literals in C23 (PR #97210)

2024-09-05 Thread via cfe-commits

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


[clang] 3e47883 - Recover performance loss after PagedVector introduction (#67972)

2024-09-05 Thread via cfe-commits

Author: Giulio Eulisse
Date: 2024-09-05T10:16:51+02:00
New Revision: 3e4788377bb29ed389b46521fcba0d06aa985bcf

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

LOG: Recover performance loss after PagedVector introduction (#67972)

Added: 


Modified: 
clang/include/clang/Basic/SourceManager.h
llvm/include/llvm/ADT/PagedVector.h

Removed: 




diff  --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index d3ccc7ef81c079..e0f1ea435d54e4 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -724,7 +724,7 @@ class SourceManager : public RefCountedBase {
   ///
   /// Negative FileIDs are indexes into this table. To get from ID to an index,
   /// use (-ID - 2).
-  llvm::PagedVector LoadedSLocEntryTable;
+  llvm::PagedVector LoadedSLocEntryTable;
 
   /// For each allocation in LoadedSLocEntryTable, we keep the first FileID.
   /// We assume exactly one allocation per AST file, and use that to determine

diff  --git a/llvm/include/llvm/ADT/PagedVector.h 
b/llvm/include/llvm/ADT/PagedVector.h
index 3fcca6d82cb33a..52ecd0bb0ba118 100644
--- a/llvm/include/llvm/ADT/PagedVector.h
+++ b/llvm/include/llvm/ADT/PagedVector.h
@@ -84,7 +84,7 @@ template  
class PagedVector {
 assert(Index / PageSize < PageToDataPtrs.size());
 T *&PagePtr = PageToDataPtrs[Index / PageSize];
 // If the page was not yet allocated, allocate it.
-if (!PagePtr) {
+if (LLVM_UNLIKELY(!PagePtr)) {
   PagePtr = Allocator.getPointer()->template Allocate(PageSize);
   // We need to invoke the default constructor on all the elements of the
   // page.



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


[clang] [llvm] Recover performance loss after PagedVector introduction (PR #67972)

2024-09-05 Thread via cfe-commits

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


[clang] [clang] Diagnose dangling issues for the "Container" case. (PR #107213)

2024-09-05 Thread Utkarsh Saxena via cfe-commits


@@ -499,3 +518,28 @@ std::string_view test2(int i, 
std::optional a) {
   return std::move(a.value());
 }
 }
+
+namespace GH100526 {
+void test() {
+  std::vector t1 = {std::string()}; // expected-warning 
{{object backing the pointer will be destroyed at the end}}

usx95 wrote:

Great. Thanks.

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


[clang] [flang] [flang][driver] Add pre-processing type for Fortran pre-processed files (PR #104664)

2024-09-05 Thread Andrzej Warzyński via cfe-commits

https://github.com/banach-space approved this pull request.

LGTM, thanks!

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


[clang] [flang] [flang][driver] Add pre-processing type for Fortran pre-processed files (PR #104664)

2024-09-05 Thread Andrzej Warzyński via cfe-commits

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


[clang] [flang] [flang][driver] Add pre-processing type for Fortran pre-processed files (PR #104664)

2024-09-05 Thread Andrzej Warzyński via cfe-commits


@@ -79,7 +79,17 @@ TYPE("c++-module-cpp-output",PP_CXXModule, INVALID,  
   "iim",phases
 TYPE("ada",  Ada,  INVALID, nullptr,  
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 TYPE("assembler",PP_Asm,   INVALID, "s",  
phases::Assemble, phases::Link)
 TYPE("assembler-with-cpp",   Asm,  PP_Asm,  "S",  
phases::Preprocess, phases::Assemble, phases::Link)
-TYPE("f95",  PP_Fortran,   INVALID, "i",  
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+
+// Note: The `phases::Preprocess` phase is added to ".i" (i.e. Fortran
+// pre-processed) files. The reason is that the pre-processor "phase" has to be
+// re-run to make sure that e.g. the include flags (i.e. `-I `) are
+// preserved. That's because these include paths will contain module files and,
+// unlike C header files, these module files wouldn't be included in the
+// pre-processed file. In particular, we need to add the search paths for these
+// modules when flang needs to emits pre-processed files. Therefore, the
+// `PP_TYPE` is set to `PP_Fortran` so that the driver is fine with
+// "pre-processing a pre-processed file".

banach-space wrote:

[nits]

```suggestion
// Note: The `phases::Preprocess` phase is added to ".i" (i.e. Fortran
// pre-processed) files. The reason is that the pre-processor "phase" has to be
// re-run to make sure that e.g. the include flags (i.e. `-I `) are
// preserved. That's because these include paths will contain module files and,
// unlike C header files, these module files wouldn't be included in the
// pre-processed file. In particular, we need to add the search paths for these
// modules when Flang needs to emit pre-processed files. Therefore, the
// `PP_TYPE` is set to `PP_Fortran` so that the driver is fine with
// "pre-processing a pre-processed file".
```

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


[clang] [clang-tools-extra] [Clang] Implement CWG2813: Class member access with prvalues (PR #95112)

2024-09-05 Thread via cfe-commits


@@ -222,17 +222,17 @@ static bool DiagnoseNoDiscard(Sema &S, const 
WarnUnusedResultAttr *A,
   return S.Diag(Loc, diag::warn_unused_result_msg) << A << Msg << R1 << R2;
 }
 
-void Sema::DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID) {
-  if (const LabelStmt *Label = dyn_cast_or_null(S))
-return DiagnoseUnusedExprResult(Label->getSubStmt(), DiagID);
-
-  const Expr *E = dyn_cast_or_null(S);
-  if (!E)
-return;
+static void DiagnoseUnused(Sema &S, const Expr *E,
+   std::optional DiagID) {
+  // When called from Sema::DiagnoseUnusedExprResult, DiagID is a diagnostic 
for
+  // where this expression is not used. When called from
+  // Sema::DiagnoseDiscardedNodiscard, DiagID is std::nullopt and this function
+  // will only diagnose [[nodiscard]], [[gnu::warn_unused_result]] and similar

cor3ntin wrote:

@MitalAshok ping :)

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


[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-09-05 Thread Mital Ashok via cfe-commits

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

>From e1172958f43af7490b5b6e3752a9070265ad17ca Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Wed, 22 May 2024 16:01:13 +0100
Subject: [PATCH 1/4] [Clang] CWG2749: relational operators involving pointers
 to void

https://cplusplus.github.io/CWG/issues/2749.html

This DR's effects are backported to C++98.

Does not affect C where integral constant expressions cannot involve pointers.
---
 clang/docs/ReleaseNotes.rst   |  4 ++
 .../include/clang/Basic/DiagnosticASTKinds.td |  2 -
 clang/lib/AST/ExprConstant.cpp| 10 
 clang/test/AST/Interp/literals.cpp|  8 +---
 clang/test/CXX/drs/cwg27xx.cpp| 46 ++-
 clang/test/CXX/expr/expr.const/p2-0x.cpp  | 11 +++--
 clang/www/cxx_dr_status.html  |  2 +-
 7 files changed, 58 insertions(+), 25 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2899bc5ed35ad0..4d9313f4c7ca57 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -237,6 +237,10 @@ Resolutions to C++ Defect Reports
 - P0522 implementation is enabled by default in all language versions, and
   provisional wording for CWG2398 is implemented.
 
+- Clang now allows comparing unequal object pointers that have been cast to 
``void *``
+  in constant expressions. These comparisons always worked in non-constant 
expressions.
+  (`CWG2749: Treatment of "pointer to void" for relational comparisons 
`_).
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index a024f9b2a9f8c0..b7aae9395e6357 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -148,8 +148,6 @@ def note_constexpr_var_init_weak : Note<
 def note_constexpr_typeid_polymorphic : Note<
   "typeid applied to expression of polymorphic type %0 is "
   "not allowed in a constant expression in C++ standards before C++20">;
-def note_constexpr_void_comparison : Note<
-  "comparison between unequal pointers to void has unspecified result">;
 def note_constexpr_temporary_here : Note<"temporary created here">;
 def note_constexpr_dynamic_alloc_here : Note<"heap allocation performed here">;
 def note_constexpr_conditional_never_const : Note<
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f1aa19e4409e15..d5a47a071e2cd7 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13627,16 +13627,6 @@ EvaluateComparisonBinaryOperator(EvalInfo &Info, const 
BinaryOperator *E,
 SubobjectDesignator &LHSDesignator = LHSValue.getLValueDesignator();
 SubobjectDesignator &RHSDesignator = RHSValue.getLValueDesignator();
 
-// C++11 [expr.rel]p3:
-//   Pointers to void (after pointer conversions) can be compared, with a
-//   result defined as follows: If both pointers represent the same
-//   address or are both the null pointer value, the result is true if the
-//   operator is <= or >= and false otherwise; otherwise the result is
-//   unspecified.
-// We interpret this as applying to pointers to *cv* void.
-if (LHSTy->isVoidPointerType() && LHSOffset != RHSOffset && IsRelational)
-  Info.CCEDiag(E, diag::note_constexpr_void_comparison);
-
 // C++11 [expr.rel]p2:
 // - If two pointers point to non-static data members of the same object,
 //   or to subobjects or array elements fo such members, recursively, the
diff --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index c160be06dd241c..ae7942aca39e63 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -191,12 +191,8 @@ namespace PointerComparison {
   constexpr bool v3 = null == pv; // ok
   constexpr bool v4 = qv == pv; // ok
 
-  /// FIXME: These two are rejected by the current interpreter, but
-  ///   accepted by GCC.
-  constexpr bool v5 = qv >= pv; // ref-error {{constant expression}} \
-// ref-note {{unequal pointers to void}}
-  constexpr bool v8 = qv > (void*)&s.a; // ref-error {{constant expression}} \
-// ref-note {{unequal pointers to 
void}}
+  constexpr bool v5 = qv >= pv;
+  constexpr bool v8 = qv > (void*)&s.a;
   constexpr bool v6 = qv > null; // both-error {{must be initialized by a 
constant expression}} \
  // both-note {{comparison between '&s.b' and 
'nullptr' has unspecified value}}
 
diff --git a/clang/test/CXX/drs/cwg27xx.cpp b/clang/test/CXX/drs/cwg27xx.cpp
index 53ddd566b7dbf9..f0c3c6dbdf97b0 100644
--- a/clang/test/CXX/drs/cwg27xx.cpp
+++ b/clang/test/CXX/drs/cwg27xx.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++98 -verify

[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-09-05 Thread Mital Ashok via cfe-commits

MitalAshok wrote:

@cor3ntin Done!

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


[clang] [clang][transformer] Add `join` stencil. (PR #107366)

2024-09-05 Thread Clement Courbet via cfe-commits

https://github.com/legrosbuffle created 
https://github.com/llvm/llvm-project/pull/107366

`join(",", a, b, c)` is the same as `cat(a, ",", b, ",", c)`.

>From 0c9d87c0e25e598f40ecf3f4977cd5ed2e205636 Mon Sep 17 00:00:00 2001
From: Clement Courbet 
Date: Thu, 5 Sep 2024 06:53:07 +
Subject: [PATCH] [clang][transformer] Add `join` stencil.

`join(",", a, b, c)` is the same as `cat(a, ",", b, ",", c)`.
---
 clang/include/clang/Tooling/Transformer/Stencil.h |  9 +
 clang/lib/Tooling/Transformer/Stencil.cpp | 15 +++
 clang/unittests/Tooling/StencilTest.cpp   |  5 +
 3 files changed, 29 insertions(+)

diff --git a/clang/include/clang/Tooling/Transformer/Stencil.h 
b/clang/include/clang/Tooling/Transformer/Stencil.h
index 249f95b7391dfe..461b8ee6b77ae1 100644
--- a/clang/include/clang/Tooling/Transformer/Stencil.h
+++ b/clang/include/clang/Tooling/Transformer/Stencil.h
@@ -65,6 +65,15 @@ template  Stencil cat(Ts &&... Parts) {
   return catVector({detail::makeStencil(std::forward(Parts))...});
 }
 
+// Constructs the string representing the concatenation of the given \p
+// Parts, separated using \p Sep.
+Stencil joinVector(StringRef Sep, std::vector Parts);
+
+// Same as `cat(Parts[0], Sep, Parts[1], Sep, ...,)`.
+template  Stencil join(StringRef Sep, Ts &&...Parts) {
+  return joinVector(Sep, {detail::makeStencil(std::forward(Parts))...});
+}
+
 //
 // Functions for conveniently building stencils.
 //
diff --git a/clang/lib/Tooling/Transformer/Stencil.cpp 
b/clang/lib/Tooling/Transformer/Stencil.cpp
index bc4fa6e36057c1..15eec577c71659 100644
--- a/clang/lib/Tooling/Transformer/Stencil.cpp
+++ b/clang/lib/Tooling/Transformer/Stencil.cpp
@@ -492,3 +492,18 @@ Stencil transformer::catVector(std::vector Parts) 
{
 return std::move(Parts[0]);
   return std::make_shared(std::move(Parts));
 }
+
+Stencil transformer::joinVector(StringRef Sep, std::vector Parts) {
+  if (Parts.size() == 1)
+return std::move(Parts[0]);
+
+  Stencil SepStencil = detail::makeStencil(Sep);
+  std::vector SeparatedParts;
+  SeparatedParts.reserve(2 * Parts.size() - 1);
+  SeparatedParts.push_back(std::move(Parts[0]));
+  for (size_t I = 1, E = Parts.size(); I < E; ++I) {
+SeparatedParts.emplace_back(SepStencil);
+SeparatedParts.push_back(std::move(Parts[I]));
+  }
+  return std::make_shared(std::move(SeparatedParts));
+}
diff --git a/clang/unittests/Tooling/StencilTest.cpp 
b/clang/unittests/Tooling/StencilTest.cpp
index 26257cf2ca3a5f..db6cbe3d120bbd 100644
--- a/clang/unittests/Tooling/StencilTest.cpp
+++ b/clang/unittests/Tooling/StencilTest.cpp
@@ -769,4 +769,9 @@ TEST(StencilToStringTest, SequenceFromVector) {
R"repr(ifBound("x", "t", access("e", "f"repr";
   EXPECT_EQ(S->toString(), Expected);
 }
+
+TEST(StencilToStringTest, Join) {
+  auto S = join(" sep ", cat("a"), cat("b"), cat("c"));
+  EXPECT_EQ(S->toString(), R"repr(seq("a", " sep ", "b", " sep ", "c"))repr");
+}
 } // namespace

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


[clang] [clang][transformer] Add `join` stencil. (PR #107366)

2024-09-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Clement Courbet (legrosbuffle)


Changes

`join(",", a, b, c)` is the same as `cat(a, ",", b, ",", c)`.

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


3 Files Affected:

- (modified) clang/include/clang/Tooling/Transformer/Stencil.h (+9) 
- (modified) clang/lib/Tooling/Transformer/Stencil.cpp (+15) 
- (modified) clang/unittests/Tooling/StencilTest.cpp (+5) 


``diff
diff --git a/clang/include/clang/Tooling/Transformer/Stencil.h 
b/clang/include/clang/Tooling/Transformer/Stencil.h
index 249f95b7391dfe..461b8ee6b77ae1 100644
--- a/clang/include/clang/Tooling/Transformer/Stencil.h
+++ b/clang/include/clang/Tooling/Transformer/Stencil.h
@@ -65,6 +65,15 @@ template  Stencil cat(Ts &&... Parts) {
   return catVector({detail::makeStencil(std::forward(Parts))...});
 }
 
+// Constructs the string representing the concatenation of the given \p
+// Parts, separated using \p Sep.
+Stencil joinVector(StringRef Sep, std::vector Parts);
+
+// Same as `cat(Parts[0], Sep, Parts[1], Sep, ...,)`.
+template  Stencil join(StringRef Sep, Ts &&...Parts) {
+  return joinVector(Sep, {detail::makeStencil(std::forward(Parts))...});
+}
+
 //
 // Functions for conveniently building stencils.
 //
diff --git a/clang/lib/Tooling/Transformer/Stencil.cpp 
b/clang/lib/Tooling/Transformer/Stencil.cpp
index bc4fa6e36057c1..15eec577c71659 100644
--- a/clang/lib/Tooling/Transformer/Stencil.cpp
+++ b/clang/lib/Tooling/Transformer/Stencil.cpp
@@ -492,3 +492,18 @@ Stencil transformer::catVector(std::vector Parts) 
{
 return std::move(Parts[0]);
   return std::make_shared(std::move(Parts));
 }
+
+Stencil transformer::joinVector(StringRef Sep, std::vector Parts) {
+  if (Parts.size() == 1)
+return std::move(Parts[0]);
+
+  Stencil SepStencil = detail::makeStencil(Sep);
+  std::vector SeparatedParts;
+  SeparatedParts.reserve(2 * Parts.size() - 1);
+  SeparatedParts.push_back(std::move(Parts[0]));
+  for (size_t I = 1, E = Parts.size(); I < E; ++I) {
+SeparatedParts.emplace_back(SepStencil);
+SeparatedParts.push_back(std::move(Parts[I]));
+  }
+  return std::make_shared(std::move(SeparatedParts));
+}
diff --git a/clang/unittests/Tooling/StencilTest.cpp 
b/clang/unittests/Tooling/StencilTest.cpp
index 26257cf2ca3a5f..db6cbe3d120bbd 100644
--- a/clang/unittests/Tooling/StencilTest.cpp
+++ b/clang/unittests/Tooling/StencilTest.cpp
@@ -769,4 +769,9 @@ TEST(StencilToStringTest, SequenceFromVector) {
R"repr(ifBound("x", "t", access("e", "f"repr";
   EXPECT_EQ(S->toString(), Expected);
 }
+
+TEST(StencilToStringTest, Join) {
+  auto S = join(" sep ", cat("a"), cat("b"), cat("c"));
+  EXPECT_EQ(S->toString(), R"repr(seq("a", " sep ", "b", " sep ", "c"))repr");
+}
 } // namespace

``




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


[clang] [clang][Driver] Add a custom error option in multilib.yaml. (PR #105684)

2024-09-05 Thread Simon Tatham via cfe-commits

statham-arm wrote:

To be clear, are you asking _me_ to make a followup PR to change that 
identifier in this already-landed patch, or are you going to do it?

(Just to avoid the situation where both of us do it, or both of us think the 
other is going to)

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


[clang] b206bf0 - Fix CLANG_BOOTSTRAP_TARGETS in Release.cmake (#106407)

2024-09-05 Thread via cfe-commits

Author: Konrad Kleine
Date: 2024-09-05T10:41:18+02:00
New Revision: b206bf0952796cb93f1aca9e47d5764e474e1998

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

LOG: Fix CLANG_BOOTSTRAP_TARGETS in Release.cmake (#106407)

# Problem

Before this patch you could not build the `stage2-LLVM` for example
because you first had to manually add it to `CLANG_BOOTSTRAP_TARGETS` in
the `Release.cmake` and also add it to
`LLVM_RELEASE_FINAL_STAGE_TARGETS` in the cmake configure run. Now you
can just use `-DLLVM_RELEASE_FINAL_STAGE_TARGETS="LLVM;clang"` on the
cmake CLI and be able to build the targets `stage2-LLVM` and
`stage2-clang` without further changes to the cache file.

# Solution

Take all `LLVM_RELEASE_FINAL_STAGE_TARGETS` elements and append them
prefixed with `stage2-` to `CLANG_BOOTSTRAP_TARGETS`. Afterwards all
duplicates are removed.

Added: 


Modified: 
clang/cmake/caches/Release.cmake

Removed: 




diff  --git a/clang/cmake/caches/Release.cmake 
b/clang/cmake/caches/Release.cmake
index 6d5f75ca0074ee..c93ff40ff3ee48 100644
--- a/clang/cmake/caches/Release.cmake
+++ b/clang/cmake/caches/Release.cmake
@@ -55,14 +55,22 @@ set(STAGE1_RUNTIMES "compiler-rt")
 
 if (LLVM_RELEASE_ENABLE_PGO)
   list(APPEND STAGE1_PROJECTS "lld")
-  set(CLANG_BOOTSTRAP_TARGETS
+  set(tmp_targets
 generate-profdata
 stage2-package
 stage2-clang
+stage2
 stage2-install
 stage2-check-all
 stage2-check-llvm
-stage2-check-clang CACHE STRING "")
+stage2-check-clang)
+
+  foreach(X IN LISTS LLVM_RELEASE_FINAL_STAGE_TARGETS)
+list(APPEND tmp_targets "stage2-${X}")
+  endforeach()
+  list(REMOVE_DUPLICATES tmp_targets)
+
+  set(CLANG_BOOTSTRAP_TARGETS "${tmp_targets}" CACHE STRING "")
 
   # Configuration for stage2-instrumented
   set(BOOTSTRAP_CLANG_ENABLE_BOOTSTRAP ON CACHE STRING "")



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


[clang] Fix CLANG_BOOTSTRAP_TARGETS in Release.cmake (PR #106407)

2024-09-05 Thread Konrad Kleine via cfe-commits

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


[clang-tools-extra] [clang-tidy] Add user-defined functions to `bugprone-unsafe-functions` check (PR #106350)

2024-09-05 Thread via cfe-commits


@@ -19,6 +19,9 @@ The check implements the following rules from the CERT C 
Coding Standard:
 Unsafe functions
 
 
+The following functions are reported if `ReportDefaultFunctions
+`_ is enabled.
+

whisperity wrote:

Referring to the `.html` directly is definitely not good because rst can be 
lowered to different markup syntaxes.

You need to create (or check if `opt::` automatically does?) a referable 
entity, and then `:ref:` can be used to make the link clickable. So you will 
use the ID or "label" you allocated in the document instead of relying on the 
automatically generated, HTML-specific anchor.

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


[clang] [clang] Diagnose dangling issues for the "Container" case. (PR #107213)

2024-09-05 Thread Haojian Wu via cfe-commits

hokein wrote:

After further testing, this change introduces a new false positive -- we emit a 
return-stack-address warning for the following case, this is not correct.

```
std::vector kk() {
  std::vector s;
  return s;
}
```

Looking now.

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


[clang] [llvm] [AArch64] Implement NEON vamin/vamax intrinsics (PR #99041)

2024-09-05 Thread via cfe-commits


@@ -2115,3 +2115,8 @@ let ArchGuard = "defined(__aarch64__)", TargetGuard = 
"lut" in {
 def VLUTI4_BF_X2_Q   : SInst<"vluti4_laneq_x2", ".2(;
   }
 }
+
+let ArchGuard = "defined(__aarch64__)", TargetGuard = "faminmax" in {

SpencerAbson wrote:

Should this target guard not be `"neon,faminmax"`? We are currently testing the 
use of these intrinsics under `+neon,+faminmax` and `FeatureFAMINMAX` does not 
include `FeatureNEON` as a dependency.

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


[clang] [llvm] [mlir] [TableGen] Add const variants of accessors for backend (PR #106658)

2024-09-05 Thread Matthias Springer via cfe-commits

https://github.com/matthias-springer approved this pull request.


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


[clang] [clang-format] Add options to set number of empty lines after includes (PR #78957)

2024-09-05 Thread Jonas Gollenz via cfe-commits

jgollenz wrote:

@seranu if I have a look at this issue may I continue working from your commit 
or do you want me to start from scratch?

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


[clang] [llvm] [DLCov 3/5] Implement DebugLoc origin-tracking (PR #107369)

2024-09-05 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer created 
https://github.com/llvm/llvm-project/pull/107369

This is part of a series of patches that tries to improve DILocation bug 
detection in Debugify; see below for more details. This patch adds an 
origin-tracking feature, which collects a stack trace at the point that 
unintentionally empty DebugLocs are created (e.g. in the Instruction 
constructor), and storing that trace in the DebugLoc so that Debugify can 
symbolize it and print it as part of the generated JSON/HTML report for each 
reported bug. This is obviously very expensive; for the builds I used this with 
locally, it resulted in compile times around 9x slower. This is not necessarily 
a problem however, as the goal of this feature is to enable very fast diagnosis 
of DebugLoc errors by developers on their own machines, not to be part of any 
automated test environment.

Most DebugLoc errors occur when we create an instruction and forget to assign 
it a DILocation. These errors are trivial to fix once the responsible code has 
been identified, but finding them can be tedious and time consuming. Sometimes 
knowing the pass and instruction type makes it obvious, but in other cases it 
can take a more thorough reading of the pass to identify the source of the 
error. Since the root of the error always exists at the point where an empty 
DebugLoc is constructed however, seeing the call stack at that point can either 
provide an immediate fix or otherwise cut through the initial stages of 
investigation.

As far as I'm aware we don't currently use any introspection similar to this in 
LLVM; I've therefore kept all functionality inside of conditionally-compiled 
blocks and made it an error to enable it in `NDEBUG` builds. The intention is 
that this is kept as a specialized tool for fixing complex or numerous debug 
line bugs, trading some compute time for developer time. The implementation 
also just uses the libc `backtrace` for now, since it's the simplest way to get 
the feature implemented.



This series of patches adds a "DebugLoc coverage tracking" feature, that 
inserts conditionally-compiled tracking information into DebugLocs (and by 
extension, to Instructions), which is used by Debugify to provide more accurate 
and detailed coverage reports. When enabled, this features tracks whether and 
why we have intentionally dropped a DebugLoc, allowing Debugify to ignore false 
positives. An optional additional feature allows also storing a stack trace of 
the point where a DebugLoc was unintentionally dropped/not generated, which is 
used to make fixing detected errors significantly easier. The goal of these 
features is to provide useful tools for developers to fix existing DebugLoc 
errors and allow reliable detection of regressions by either manual inspection 
or an automated script. 


>From e45d7e68a371a09ea766c4accf8edc6c030fd7fd Mon Sep 17 00:00:00 2001
From: Stephen Tozer 
Date: Wed, 4 Sep 2024 12:09:50 +0100
Subject: [PATCH 1/3] Add CMake option to enable expensive line number origin
 tracking

---
 llvm/CMakeLists.txt|  4 
 llvm/cmake/modules/HandleLLVMOptions.cmake | 12 
 llvm/docs/CMake.rst| 11 +++
 llvm/include/llvm/Config/config.h.cmake|  4 
 4 files changed, 31 insertions(+)

diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 12618966c4adfd..3e2e90f5adad2e 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -524,6 +524,10 @@ endif()
 
 option(LLVM_ENABLE_CRASH_DUMPS "Turn on memory dumps on crashes. Currently 
only implemented on Windows." OFF)
 
+set(LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING "DISABLED" CACHE STRING
+  "Enhance debugify's line number coverage tracking; enabling this is 
abi-breaking. Can be DISABLED, COVERAGE, or COVERAGE_AND_ORIGIN.")
+set_property(CACHE LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING PROPERTY STRINGS 
DISABLED COVERAGE COVERAGE_AND_ORIGIN)
+
 set(WINDOWS_PREFER_FORWARD_SLASH_DEFAULT OFF)
 if (MINGW)
   # Cygwin doesn't identify itself as Windows, and thus gets path::Style::posix
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 5ca580fbb59c59..a4b11c149da9de 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -196,6 +196,18 @@ else()
   message(FATAL_ERROR "Unknown value for LLVM_ABI_BREAKING_CHECKS: 
\"${LLVM_ABI_BREAKING_CHECKS}\"!")
 endif()
 
+string(TOUPPER "${LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING}" 
uppercase_LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING)
+
+if( uppercase_LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING STREQUAL "COVERAGE" )
+  set( ENABLE_DEBUGLOC_COVERAGE_TRACKING 1 )
+elseif( uppercase_LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING STREQUAL 
"COVERAGE_AND_ORIGIN" )
+  message(FATAL_ERROR "\"COVERAGE_AND_ORIGIN\" setting for 
LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING currently unimplemented.")
+elseif( uppercase_LLVM_ENABLE_DEBUGLOC_COVERAGE_TRAC

[clang] [llvm] [DLCov 3/5] Implement DebugLoc origin-tracking (PR #107369)

2024-09-05 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-debuginfo

@llvm/pr-subscribers-platform-windows

Author: Stephen Tozer (SLTozer)


Changes

This is part of a series of patches that tries to improve DILocation bug 
detection in Debugify; see below for more details. This patch adds an 
origin-tracking feature, which collects a stack trace at the point that 
unintentionally empty DebugLocs are created (e.g. in the Instruction 
constructor), and storing that trace in the DebugLoc so that Debugify can 
symbolize it and print it as part of the generated JSON/HTML report for each 
reported bug. This is obviously very expensive; for the builds I used this with 
locally, it resulted in compile times around 9x slower. This is not necessarily 
a problem however, as the goal of this feature is to enable very fast diagnosis 
of DebugLoc errors by developers on their own machines, not to be part of any 
automated test environment.

Most DebugLoc errors occur when we create an instruction and forget to assign 
it a DILocation. These errors are trivial to fix once the responsible code has 
been identified, but finding them can be tedious and time consuming. Sometimes 
knowing the pass and instruction type makes it obvious, but in other cases it 
can take a more thorough reading of the pass to identify the source of the 
error. Since the root of the error always exists at the point where an empty 
DebugLoc is constructed however, seeing the call stack at that point can either 
provide an immediate fix or otherwise cut through the initial stages of 
investigation.

As far as I'm aware we don't currently use any introspection similar to this in 
LLVM; I've therefore kept all functionality inside of conditionally-compiled 
blocks and made it an error to enable it in `NDEBUG` builds. The intention is 
that this is kept as a specialized tool for fixing complex or numerous debug 
line bugs, trading some compute time for developer time. The implementation 
also just uses the libc `backtrace` for now, since it's the simplest way to get 
the feature implemented.



This series of patches adds a "DebugLoc coverage tracking" feature, that 
inserts conditionally-compiled tracking information into DebugLocs (and by 
extension, to Instructions), which is used by Debugify to provide more accurate 
and detailed coverage reports. When enabled, this features tracks whether and 
why we have intentionally dropped a DebugLoc, allowing Debugify to ignore false 
positives. An optional additional feature allows also storing a stack trace of 
the point where a DebugLoc was unintentionally dropped/not generated, which is 
used to make fixing detected errors significantly easier. The goal of these 
features is to provide useful tools for developers to fix existing DebugLoc 
errors and allow reliable detection of regressions by either manual inspection 
or an automated script. 


---

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


18 Files Affected:

- (modified) clang/lib/CodeGen/BackendUtil.cpp (+16) 
- (modified) llvm/CMakeLists.txt (+4) 
- (modified) llvm/cmake/modules/HandleLLVMOptions.cmake (+13) 
- (modified) llvm/docs/CMake.rst (+11) 
- (modified) llvm/include/llvm/Config/config.h.cmake (+8) 
- (modified) llvm/include/llvm/IR/DebugLoc.h (+110-1) 
- (modified) llvm/include/llvm/Support/Signals.h (+40) 
- (modified) llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (+5) 
- (modified) llvm/lib/CodeGen/BranchFolding.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/BranchFolding.h (+8-4) 
- (modified) llvm/lib/IR/DebugInfo.cpp (+2-2) 
- (modified) llvm/lib/IR/DebugLoc.cpp (+36) 
- (modified) llvm/lib/IR/Instruction.cpp (+4-2) 
- (modified) llvm/lib/Support/Signals.cpp (+116) 
- (modified) llvm/lib/Support/Unix/Signals.inc (+15) 
- (modified) llvm/lib/Support/Windows/Signals.inc (+5) 
- (modified) llvm/lib/Transforms/Utils/Debugify.cpp (+82-17) 
- (modified) llvm/utils/llvm-original-di-preservation.py (+13-9) 


``diff
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index e765bbf637a661..20653daff7d4ae 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -911,6 +911,22 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
   Debugify.setOrigDIVerifyBugsReportFilePath(
   CodeGenOpts.DIBugsReportFilePath);
 Debugify.registerCallbacks(PIC, MAM);
+
+#if ENABLE_DEBUGLOC_COVERAGE_TRACKING
+// If we're using debug location coverage tracking, mark all the
+// instructions coming out of the frontend without a DebugLoc as being
+// intentional line-zero locations, to prevent both those instructions and
+// new instructions that inherit their location from being treated as
+// incorrectly empty locations.
+for (Function &F : *TheModule) {
+  if (!F.getSubprogram())
+continue;
+  for (BasicBlock &BB : F)
+for (Instruction &I : BB)
+  if (

[clang] [llvm] [DLCov 3/5] Implement DebugLoc origin-tracking (PR #107369)

2024-09-05 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Stephen Tozer (SLTozer)


Changes

This is part of a series of patches that tries to improve DILocation bug 
detection in Debugify; see below for more details. This patch adds an 
origin-tracking feature, which collects a stack trace at the point that 
unintentionally empty DebugLocs are created (e.g. in the Instruction 
constructor), and storing that trace in the DebugLoc so that Debugify can 
symbolize it and print it as part of the generated JSON/HTML report for each 
reported bug. This is obviously very expensive; for the builds I used this with 
locally, it resulted in compile times around 9x slower. This is not necessarily 
a problem however, as the goal of this feature is to enable very fast diagnosis 
of DebugLoc errors by developers on their own machines, not to be part of any 
automated test environment.

Most DebugLoc errors occur when we create an instruction and forget to assign 
it a DILocation. These errors are trivial to fix once the responsible code has 
been identified, but finding them can be tedious and time consuming. Sometimes 
knowing the pass and instruction type makes it obvious, but in other cases it 
can take a more thorough reading of the pass to identify the source of the 
error. Since the root of the error always exists at the point where an empty 
DebugLoc is constructed however, seeing the call stack at that point can either 
provide an immediate fix or otherwise cut through the initial stages of 
investigation.

As far as I'm aware we don't currently use any introspection similar to this in 
LLVM; I've therefore kept all functionality inside of conditionally-compiled 
blocks and made it an error to enable it in `NDEBUG` builds. The intention is 
that this is kept as a specialized tool for fixing complex or numerous debug 
line bugs, trading some compute time for developer time. The implementation 
also just uses the libc `backtrace` for now, since it's the simplest way to get 
the feature implemented.



This series of patches adds a "DebugLoc coverage tracking" feature, that 
inserts conditionally-compiled tracking information into DebugLocs (and by 
extension, to Instructions), which is used by Debugify to provide more accurate 
and detailed coverage reports. When enabled, this features tracks whether and 
why we have intentionally dropped a DebugLoc, allowing Debugify to ignore false 
positives. An optional additional feature allows also storing a stack trace of 
the point where a DebugLoc was unintentionally dropped/not generated, which is 
used to make fixing detected errors significantly easier. The goal of these 
features is to provide useful tools for developers to fix existing DebugLoc 
errors and allow reliable detection of regressions by either manual inspection 
or an automated script. 


---

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


18 Files Affected:

- (modified) clang/lib/CodeGen/BackendUtil.cpp (+16) 
- (modified) llvm/CMakeLists.txt (+4) 
- (modified) llvm/cmake/modules/HandleLLVMOptions.cmake (+13) 
- (modified) llvm/docs/CMake.rst (+11) 
- (modified) llvm/include/llvm/Config/config.h.cmake (+8) 
- (modified) llvm/include/llvm/IR/DebugLoc.h (+110-1) 
- (modified) llvm/include/llvm/Support/Signals.h (+40) 
- (modified) llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (+5) 
- (modified) llvm/lib/CodeGen/BranchFolding.cpp (+1-1) 
- (modified) llvm/lib/CodeGen/BranchFolding.h (+8-4) 
- (modified) llvm/lib/IR/DebugInfo.cpp (+2-2) 
- (modified) llvm/lib/IR/DebugLoc.cpp (+36) 
- (modified) llvm/lib/IR/Instruction.cpp (+4-2) 
- (modified) llvm/lib/Support/Signals.cpp (+116) 
- (modified) llvm/lib/Support/Unix/Signals.inc (+15) 
- (modified) llvm/lib/Support/Windows/Signals.inc (+5) 
- (modified) llvm/lib/Transforms/Utils/Debugify.cpp (+82-17) 
- (modified) llvm/utils/llvm-original-di-preservation.py (+13-9) 


``diff
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index e765bbf637a661..20653daff7d4ae 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -911,6 +911,22 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
   Debugify.setOrigDIVerifyBugsReportFilePath(
   CodeGenOpts.DIBugsReportFilePath);
 Debugify.registerCallbacks(PIC, MAM);
+
+#if ENABLE_DEBUGLOC_COVERAGE_TRACKING
+// If we're using debug location coverage tracking, mark all the
+// instructions coming out of the frontend without a DebugLoc as being
+// intentional line-zero locations, to prevent both those instructions and
+// new instructions that inherit their location from being treated as
+// incorrectly empty locations.
+for (Function &F : *TheModule) {
+  if (!F.getSubprogram())
+continue;
+  for (BasicBlock &BB : F)
+for (Instruction &I : BB)
+  if (!I.getDebugLoc())
+I.setDebugL

[clang] [clang-tools-extra] [llvm] [clang-format] Add support for BasedOnStyle referencing an arbitrary file (PR #107312)

2024-09-05 Thread kadir çetinkaya via cfe-commits

kadircet wrote:

I am not sure if it's best to push a new command line flag to all other tools 
that use clang-format as a library.

Have you considered any other alternatives that can self-contain this in 
clang-format? e.g can we just treat paths as relative to current 
`.clang-format` file ?

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


[clang] [clang] Diagnose dangling issues for the "Container" case. (PR #107213)

2024-09-05 Thread Utkarsh Saxena via cfe-commits

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


[clang] [clang] Diagnose dangling issues for the "Container" case. (PR #107213)

2024-09-05 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 commented:

Thanks. LG. Some comments on adding more tests.

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


[clang] [clang] Diagnose dangling issues for the "Container" case. (PR #107213)

2024-09-05 Thread Utkarsh Saxena via cfe-commits


@@ -525,3 +544,31 @@ void test() {
   std::string_view svjkk1 = ReturnStringView(StrCat("bar", "x")); // 
expected-warning {{object backing the pointer will be destroyed at the end of 
the full-expression}}
 }
 } // namespace GH100549
+
+namespace GH100526 {
+void test() {
+  std::vector v1({std::string()}); // expected-warning 
{{object backing the pointer will be destroyed at the end}}
+  std::vector v2({std::string(), std::string_view()}); // 
expected-warning {{object backing the pointer will be destroyed at the end}}
+  std::vector v3({std::string_view(), std::string()}); // 
expected-warning {{object backing the pointer will be destroyed at the end}}
+
+  std::optional o1 = std::string(); // expected-warning 
{{object backing the pointer}}
+
+  std::string s;
+  // This is a tricky use-after-free case, what it does:
+  //   1. make_optional creates a temporary "optional"" object
+  //   2. the temporary object owns the underlying string which is copied from 
s.
+  //   3. the t3 object holds the view to the underlying string of the 
temporary object.
+  std::optional o2 = std::make_optional(s); // 
expected-warning {{object backing the pointer}}

usx95 wrote:

IIUC this is catching the case when a `Container` is constructed from 
temporary `Container`
Can you also add a more intuitive case like `std::optional o2 
= std::optional(s);`

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


[clang] [clang] Diagnose dangling issues for the "Container" case. (PR #107213)

2024-09-05 Thread Utkarsh Saxena via cfe-commits


@@ -6690,6 +6690,20 @@ When the Owner's lifetime ends, it will consider the 
Pointer to be dangling.
 P.getInt(); // P is dangling
   }
 
+If a template class is annotated with [[gsl::Owner]], and the first 
instantiated
+template argument is a [[gsl::Pointer]] type, the analysis will consider the
+instantiated class as a container of the pointer. When constructing such an
+object from a GSL owner object, the analysis will assume that the container
+holds a pointer to the owner object. Consequently, when the owner object is
+destroyed, the pointer will be considered dangling.
+
+.. code-block:: c++
+
+   int f() {
+ std::vector v = {std::string();}; // v holds a dangling 
pointer.

usx95 wrote:

nit: remove `;` after `std::string()`

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


[clang] [clang] Diagnose dangling issues for the "Container" case. (PR #107213)

2024-09-05 Thread Utkarsh Saxena via cfe-commits


@@ -278,6 +278,8 @@ Improvements to Clang's diagnostics
 - The lifetimebound and GSL analysis in clang are coherent, allowing clang to
   detect more use-after-free bugs. (#GH100549).
 
+- Clang now diagnoses cases where a dangling `GSLOwner`` object is 
constructed, e.g. `std::vector v = {std::string}` (#GH100526).

usx95 wrote:

```suggestion
- Clang now diagnoses cases where a dangling ``GSLOwner`` object is 
constructed, e.g. ``std::vector v = {std::string()}`` (#GH100526).
```

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


[clang] [clang] Diagnose dangling issues for the "Container" case. (PR #107213)

2024-09-05 Thread Utkarsh Saxena via cfe-commits


@@ -525,3 +544,31 @@ void test() {
   std::string_view svjkk1 = ReturnStringView(StrCat("bar", "x")); // 
expected-warning {{object backing the pointer will be destroyed at the end of 
the full-expression}}
 }
 } // namespace GH100549
+
+namespace GH100526 {
+void test() {
+  std::vector v1({std::string()}); // expected-warning 
{{object backing the pointer will be destroyed at the end}}
+  std::vector v2({std::string(), std::string_view()}); // 
expected-warning {{object backing the pointer will be destroyed at the end}}
+  std::vector v3({std::string_view(), std::string()}); // 
expected-warning {{object backing the pointer will be destroyed at the end}}
+
+  std::optional o1 = std::string(); // expected-warning 
{{object backing the pointer}}
+
+  std::string s;
+  // This is a tricky use-after-free case, what it does:
+  //   1. make_optional creates a temporary "optional"" object
+  //   2. the temporary object owns the underlying string which is copied from 
s.
+  //   3. the t3 object holds the view to the underlying string of the 
temporary object.
+  std::optional o2 = std::make_optional(s); // 
expected-warning {{object backing the pointer}}
+
+  // FIXME: should work for assignment cases
+  v1 = {std::string()};
+  o1 = std::string();
+
+  // no warning on copying pointers.
+  std::vector n1 = {std::string_view()};
+  std::optional n2 = {std::string_view()};

usx95 wrote:

Can you add also `std::optional n4 = std::string_view();`, 
i.e., without initializer list.

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


[clang] [clang] Diagnose dangling issues for the "Container" case. (PR #107213)

2024-09-05 Thread Utkarsh Saxena via cfe-commits


@@ -6690,6 +6690,20 @@ When the Owner's lifetime ends, it will consider the 
Pointer to be dangling.
 P.getInt(); // P is dangling
   }
 
+If a template class is annotated with [[gsl::Owner]], and the first 
instantiated
+template argument is a [[gsl::Pointer]] type, the analysis will consider the

usx95 wrote:

nit: To be consistent with rest of the documentation use 
\`\`[[gsl::Pointer]]\`\`. Similar for other mentions of the Owner.

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


[clang] [clang] Diagnose dangling issues for the "Container" case. (PR #107213)

2024-09-05 Thread Utkarsh Saxena via cfe-commits


@@ -525,3 +544,31 @@ void test() {
   std::string_view svjkk1 = ReturnStringView(StrCat("bar", "x")); // 
expected-warning {{object backing the pointer will be destroyed at the end of 
the full-expression}}
 }
 } // namespace GH100549
+
+namespace GH100526 {
+void test() {
+  std::vector v1({std::string()}); // expected-warning 
{{object backing the pointer will be destroyed at the end}}
+  std::vector v2({std::string(), std::string_view()}); // 
expected-warning {{object backing the pointer will be destroyed at the end}}
+  std::vector v3({std::string_view(), std::string()}); // 
expected-warning {{object backing the pointer will be destroyed at the end}}

usx95 wrote:

Can you write each of the args on separate lines. This will ensure we are 
flagging the correct arg.
something like: 
```cpp
std::vector v2({
  std::string(),
  std::string_view()
});
```


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


[clang] [clang] Diagnose dangling issues for the "Container" case. (PR #107213)

2024-09-05 Thread Utkarsh Saxena via cfe-commits


@@ -525,3 +544,31 @@ void test() {
   std::string_view svjkk1 = ReturnStringView(StrCat("bar", "x")); // 
expected-warning {{object backing the pointer will be destroyed at the end of 
the full-expression}}
 }
 } // namespace GH100549
+
+namespace GH100526 {

usx95 wrote:

Can you also add a use-after-return case:

```cpp
std::optional uar() {
  std::string s;
  return s;
}
```

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


[clang] [clang] Diagnose dangling issues for the "Container" case. (PR #107213)

2024-09-05 Thread Utkarsh Saxena via cfe-commits


@@ -470,10 +474,24 @@ static void visitFunctionCallArguments(IndirectLocalPath 
&Path, Expr *Call,
 VisitGSLPointerArg(Callee, Args[0],
!Callee->getReturnType()->isReferenceType());
   } else {
-if (auto *CCE = dyn_cast(Call);
-CCE && CCE->getConstructor()->getParent()->hasAttr())
-  VisitGSLPointerArg(CCE->getConstructor()->getParamDecl(0), Args[0],
- true);
+if (auto *Ctor = dyn_cast(Call)) {
+  const auto *ClassD = Ctor->getConstructor()->getParent();
+  // Constructing the Container case (e.g.
+  // std::optional) case.
+  if (const auto *CTSD =
+  dyn_cast(ClassD)) {
+if (isFirstTemplateArgumentGSLPointer(CTSD->getTemplateArgs()) &&
+CTSD->hasAttr()) {
+  VisitGSLPointerArg(Ctor->getConstructor()->getParamDecl(0),
+ Args[0], true);
+  return;
+}
+  }
+  // Constructing the GSLPointer (e.g. std::string_view) case.
+  if (ClassD->hasAttr())
+VisitGSLPointerArg(Ctor->getConstructor()->getParamDecl(0), 
Args[0],
+   true);
+}

usx95 wrote:

Isn't `bool PerformGSLAnalysisForFirstArg = EnableLifetimeWarnings && 
!CheckCoroCall && !Callee->getParamDecl(0)->hasAttr()` the 
sufficient condition ?

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


[clang] Reland "[clang] Add nuw attribute to GEPs (#105496)" (PR #107257)

2024-09-05 Thread Hari Limaye via cfe-commits

hazzlim wrote:

Nice - CI seems happy, so I plan to land this later today if no objections.

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


[clang] [llvm] [DLCov 3/5] Implement DebugLoc origin-tracking (PR #107369)

2024-09-05 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 5f05d5ec8f9bb15c0ac29fce843a2c73165ac414 
194069a26418fc4dbb27cee13d5b4263588320b7 --extensions inc,h,cpp -- 
clang/lib/CodeGen/BackendUtil.cpp llvm/include/llvm/IR/DebugLoc.h 
llvm/include/llvm/Support/Signals.h llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp 
llvm/lib/CodeGen/BranchFolding.cpp llvm/lib/CodeGen/BranchFolding.h 
llvm/lib/IR/DebugInfo.cpp llvm/lib/IR/DebugLoc.cpp llvm/lib/IR/Instruction.cpp 
llvm/lib/Support/Signals.cpp llvm/lib/Support/Unix/Signals.inc 
llvm/lib/Support/Windows/Signals.inc llvm/lib/Transforms/Utils/Debugify.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/include/llvm/IR/DebugLoc.h b/llvm/include/llvm/IR/DebugLoc.h
index 5f45d853a9..1812cf4205 100644
--- a/llvm/include/llvm/IR/DebugLoc.h
+++ b/llvm/include/llvm/IR/DebugLoc.h
@@ -70,12 +70,14 @@ namespace llvm {
   // Currently we only need to track the Origin of this DILoc when using a
   // DebugLoc that is Normal and empty, so only collect the origin stacktrace 
in
   // those cases.
-  class DILocAndCoverageTracking : public TrackingMDNodeRef, public 
DbgLocOrigin {
+  class DILocAndCoverageTracking : public TrackingMDNodeRef,
+   public DbgLocOrigin {
   public:
 DebugLocKind Kind;
 // Default constructor for empty DebugLocs.
 DILocAndCoverageTracking()
-: TrackingMDNodeRef(nullptr), DbgLocOrigin(true), 
Kind(DebugLocKind::Normal) {}
+: TrackingMDNodeRef(nullptr), DbgLocOrigin(true),
+  Kind(DebugLocKind::Normal) {}
 // Valid or nullptr MDNode*, normal DebugLocKind
 DILocAndCoverageTracking(const MDNode *Loc)
 : TrackingMDNodeRef(const_cast(Loc)), DbgLocOrigin(!Loc),
@@ -83,7 +85,8 @@ namespace llvm {
 DILocAndCoverageTracking(const DILocation *Loc);
 // Always nullptr MDNode*, any DebugLocKind
 DILocAndCoverageTracking(DebugLocKind Kind)
-: TrackingMDNodeRef(nullptr), DbgLocOrigin(Kind == 
DebugLocKind::Normal), Kind(Kind) {}
+: TrackingMDNodeRef(nullptr),
+  DbgLocOrigin(Kind == DebugLocKind::Normal), Kind(Kind) {}
   };
   template <> struct simplify_type {
 using SimpleType = MDNode *;
@@ -137,7 +140,7 @@ namespace llvm {
 
 #if ENABLE_DEBUGLOC_ORIGIN_TRACKING
 #if !ENABLE_DEBUGLOC_COVERAGE_TRACKING
-  #error Cannot enable DebugLoc origin-tracking without coverage-tracking!
+#error Cannot enable DebugLoc origin-tracking without coverage-tracking!
 #endif
 
 const DbgLocOrigin::StackTracesTy &getOriginStackTraces() const {
diff --git a/llvm/lib/IR/DebugLoc.cpp b/llvm/lib/IR/DebugLoc.cpp
index 9ad1d58dc5..ad02cd078d 100644
--- a/llvm/lib/IR/DebugLoc.cpp
+++ b/llvm/lib/IR/DebugLoc.cpp
@@ -26,7 +26,7 @@ void DbgLocOrigin::addTrace() {
   auto &[Depth, StackTrace] = StackTraces.emplace_back();
   Depth = sys::getStackTrace(StackTrace);
 }
-}
+} // namespace llvm
 #endif
 
 using namespace llvm;
diff --git a/llvm/lib/Transforms/Utils/Debugify.cpp 
b/llvm/lib/Transforms/Utils/Debugify.cpp
index 00a6c92f88..5b358cae1d 100644
--- a/llvm/lib/Transforms/Utils/Debugify.cpp
+++ b/llvm/lib/Transforms/Utils/Debugify.cpp
@@ -503,14 +503,14 @@ static bool checkInstructions(const DebugInstMap 
&DILocsBefore,
 auto InstName = Instruction::getOpcodeName(Instr->getOpcode());
 
 auto CreateJSONBugEntry = [&](const char *Action) {
-  Bugs.push_back(
-  llvm::json::Object({{"metadata", "DILocation"},
-  {"fn-name", FnName.str()},
-  {"bb-name", BBName.str()},
-  {"instr", InstName},
-  {"action", Action},
+  Bugs.push_back(llvm::json::Object({
+  {"metadata", "DILocation"},
+  {"fn-name", FnName.str()},
+  {"bb-name", BBName.str()},
+  {"instr", InstName},
+  {"action", Action},
 #if ENABLE_DEBUGLOC_ORIGIN_TRACKING
-  {"origin", symbolizeStackTrace(Instr)},
+  {"origin", symbolizeStackTrace(Instr)},
 #endif
   }));
 };

``




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


[clang] [llvm] [DLCov 3/5] Implement DebugLoc origin-tracking (PR #107369)

2024-09-05 Thread via cfe-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r 
5f05d5ec8f9bb15c0ac29fce843a2c73165ac414...194069a26418fc4dbb27cee13d5b4263588320b7
 llvm/utils/llvm-original-di-preservation.py
``





View the diff from darker here.


``diff
--- llvm-original-di-preservation.py2024-09-04 18:19:22.00 +
+++ llvm-original-di-preservation.py2024-09-05 09:14:40.387275 +
@@ -112,11 +112,13 @@
 row.append(llvm_pass)
 row.append(x.instr)
 row.append(x.fn_name)
 row.append(x.bb_name)
 row.append(x.action)
-row.append(f"View Origin 
StackTrace{x.origin}")
+row.append(
+f"View Origin 
StackTrace{x.origin}"
+)
 row.append("\n")
 # Dump the bugs info into the table.
 for column in row:
 # The same file-pass pair can have multiple bugs.
 if column == "\n" or column == "\n":

``




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


[clang] [clang] Diagnose dangling issues for the "Container" case. (PR #107213)

2024-09-05 Thread Utkarsh Saxena via cfe-commits

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


[clang] [clang] Diagnose dangling issues for the "Container" case. (PR #107213)

2024-09-05 Thread Utkarsh Saxena via cfe-commits

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


[clang] [clang] Diagnose dangling issues for the "Container" case. (PR #107213)

2024-09-05 Thread Utkarsh Saxena via cfe-commits

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


[clang] [clang-format] Add options to set number of empty lines after includes (PR #78957)

2024-09-05 Thread via cfe-commits

seranu wrote:

@jgollenz feel free use those commits

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


[clang] [clang] check deduction consistency when partial ordering function templates (PR #100692)

2024-09-05 Thread Luke Lau via cfe-commits

lukel97 wrote:

Here's the version without the rename pass
```c++
template  class DoFHandler;
template  class FiniteElement;
class FETools {
  template 
  void back_interpolate(const DoFHandler &, const InVector &,
const FiniteElement &, OutVector &);
  template  class DH, class InVector, class OutVector,
int spacedim>
  void back_interpolate(const DH &, InVector,
const FiniteElement &, OutVector);
};
template  class DoFHandler;
template  class FiniteElement;
template 
void FETools::back_interpolate(const DoFHandler &,
   const InVector &,
   const FiniteElement &,
   OutVector &) {}
template void FETools::back_interpolate(const DoFHandler<3> &, const double &,
const FiniteElement<3> &, double &);

```

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


[clang] [llvm] [DLCov 3/5] Implement DebugLoc origin-tracking (PR #107369)

2024-09-05 Thread Stephen Tozer via cfe-commits

https://github.com/SLTozer updated 
https://github.com/llvm/llvm-project/pull/107369

>From e45d7e68a371a09ea766c4accf8edc6c030fd7fd Mon Sep 17 00:00:00 2001
From: Stephen Tozer 
Date: Wed, 4 Sep 2024 12:09:50 +0100
Subject: [PATCH 1/3] Add CMake option to enable expensive line number origin
 tracking

---
 llvm/CMakeLists.txt|  4 
 llvm/cmake/modules/HandleLLVMOptions.cmake | 12 
 llvm/docs/CMake.rst| 11 +++
 llvm/include/llvm/Config/config.h.cmake|  4 
 4 files changed, 31 insertions(+)

diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 12618966c4adfd..3e2e90f5adad2e 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -524,6 +524,10 @@ endif()
 
 option(LLVM_ENABLE_CRASH_DUMPS "Turn on memory dumps on crashes. Currently 
only implemented on Windows." OFF)
 
+set(LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING "DISABLED" CACHE STRING
+  "Enhance debugify's line number coverage tracking; enabling this is 
abi-breaking. Can be DISABLED, COVERAGE, or COVERAGE_AND_ORIGIN.")
+set_property(CACHE LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING PROPERTY STRINGS 
DISABLED COVERAGE COVERAGE_AND_ORIGIN)
+
 set(WINDOWS_PREFER_FORWARD_SLASH_DEFAULT OFF)
 if (MINGW)
   # Cygwin doesn't identify itself as Windows, and thus gets path::Style::posix
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 5ca580fbb59c59..a4b11c149da9de 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -196,6 +196,18 @@ else()
   message(FATAL_ERROR "Unknown value for LLVM_ABI_BREAKING_CHECKS: 
\"${LLVM_ABI_BREAKING_CHECKS}\"!")
 endif()
 
+string(TOUPPER "${LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING}" 
uppercase_LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING)
+
+if( uppercase_LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING STREQUAL "COVERAGE" )
+  set( ENABLE_DEBUGLOC_COVERAGE_TRACKING 1 )
+elseif( uppercase_LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING STREQUAL 
"COVERAGE_AND_ORIGIN" )
+  message(FATAL_ERROR "\"COVERAGE_AND_ORIGIN\" setting for 
LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING currently unimplemented.")
+elseif( uppercase_LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING STREQUAL "DISABLED" 
OR NOT DEFINED LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING )
+  # The DISABLED setting is default and requires no additional defines.
+else()
+  message(FATAL_ERROR "Unknown value for 
LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING: 
\"${LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING}\"!")
+endif()
+
 if( LLVM_REVERSE_ITERATION )
   set( LLVM_ENABLE_REVERSE_ITERATION 1 )
 endif()
diff --git a/llvm/docs/CMake.rst b/llvm/docs/CMake.rst
index 2a80813999ea1e..304e22759770d9 100644
--- a/llvm/docs/CMake.rst
+++ b/llvm/docs/CMake.rst
@@ -475,6 +475,17 @@ enabled sub-projects. Nearly all of these variable names 
begin with
 **LLVM_ENABLE_BINDINGS**:BOOL
   If disabled, do not try to build the OCaml bindings.
 
+**LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING**:STRING
+  Enhances Debugify's ability to detect line number errors by storing extra
+  information inside Instructions, removing false positives from Debugify's
+  results at the cost of performance. Allowed values are `DISABLED` (default),
+  `COVERAGE`, and `COVERAGE_AND_ORIGIN`. `COVERAGE` tracks whether and why a
+  line number was intentionally dropped or not generated for an instruction,
+  allowing Debugify to avoid reporting these as errors. `COVERAGE_AND_ORIGIN`
+  additionally stores a stacktrace of the point where each DebugLoc is
+  unintentionally dropped, allowing for much easier bug triaging at the cost of
+  a ~10x performance slowdown.
+
 **LLVM_ENABLE_DIA_SDK**:BOOL
   Enable building with MSVC DIA SDK for PDB debugging support. Available
   only with MSVC. Defaults to ON.
diff --git a/llvm/include/llvm/Config/config.h.cmake 
b/llvm/include/llvm/Config/config.h.cmake
index ff30741c8f360a..388ce1e8f74e3e 100644
--- a/llvm/include/llvm/Config/config.h.cmake
+++ b/llvm/include/llvm/Config/config.h.cmake
@@ -19,6 +19,10 @@
 /* Define to 1 to enable crash memory dumps, and to 0 otherwise. */
 #cmakedefine01 LLVM_ENABLE_CRASH_DUMPS
 
+/* Define to 1 to enable expensive checks for debug location coverage checking,
+   and to 0 otherwise. */
+#cmakedefine01 ENABLE_DEBUGLOC_COVERAGE_TRACKING
+
 /* Define to 1 to prefer forward slashes on Windows, and to 0 prefer
backslashes. */
 #cmakedefine01 LLVM_WINDOWS_PREFER_FORWARD_SLASH

>From abab69ae42bf5650d6a8fff5a22341ff32effe57 Mon Sep 17 00:00:00 2001
From: Stephen Tozer 
Date: Wed, 4 Sep 2024 12:23:52 +0100
Subject: [PATCH 2/3] Add conditionally-enabled DebugLocKinds

---
 clang/lib/CodeGen/BackendUtil.cpp  | 16 +
 llvm/include/llvm/IR/DebugLoc.h| 74 +-
 llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp |  5 ++
 llvm/lib/IR/DebugInfo.cpp  |  4 +-
 llvm/lib/IR/DebugLoc.cpp   | 16 +
 llvm/lib/Transforms/Utils/Debugify.cpp | 19 --
 6 

[clang] [llvm] [DLCov 2/5] Implement DebugLoc coverage tracking (PR #107279)

2024-09-05 Thread Stephen Tozer via cfe-commits

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


[clang] [llvm] [DLCov 3/5] Implement DebugLoc origin-tracking (PR #107369)

2024-09-05 Thread Stephen Tozer via cfe-commits

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


[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-09-05 Thread via cfe-commits

cor3ntin wrote:

@MitalAshok there is a test failure!

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


[clang] [llvm] [RISCV][VCIX] Add vcix_state to GNU inline assembly register set (PR #106914)

2024-09-05 Thread Kito Cheng via cfe-commits


@@ -44,7 +44,7 @@ ArrayRef RISCVTargetInfo::getGCCRegNames() 
const {
   "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
 
   // CSRs
-  "fflags", "frm", "vtype", "vl", "vxsat", "vxrm"
+  "fflags", "frm", "vtype", "vl", "vxsat", "vxrm", "sf_vcix_state"

kito-cheng wrote:

`sf.vcix_state`?

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


[clang] [CGOpenMPRuntime] Avoid repeated hash lookups (NFC) (PR #107358)

2024-09-05 Thread Alexey Bataev via cfe-commits

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


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


[clang] [clang-format] Add new option: WrapNamespaceBodyWithNewlines (PR #106145)

2024-09-05 Thread via cfe-commits


@@ -28104,6 +28104,251 @@ TEST_F(FormatTest, BreakBinaryOperations) {
Style);
 }
 
+TEST_F(FormatTest, WrapNamespaceBodyWithEmptyLinesNever) {
+  FormatStyle Style = getLLVMStyle();
+  Style.FixNamespaceComments = false;
+  Style.ShortNamespaceLines = 0;
+  Style.MaxEmptyLinesToKeep = 2;
+  Style.WrapNamespaceBodyWithEmptyLines = FormatStyle::WNBWELS_Never;
+  Style.CompactNamespaces = false;
+
+  // Empty namespace
+  verifyNoChange("namespace N {};", Style);
+
+  // Single namespace
+  verifyNoChange("namespace N {\n"
+ "int f1(int a) { return 2 * a; }\n"
+ "};",
+ Style);
+
+  // Nested namespace
+  verifyNoChange("namespace N1 {\n"

dmasloff wrote:

But are there any differences between using `verifyNoChange` and `verifyFormat` 
with one string argument?

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


[clang] [clang-format] Add new option: WrapNamespaceBodyWithNewlines (PR #106145)

2024-09-05 Thread via cfe-commits

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


[clang] [flang] [flang][Driver] Preliminary support for -ftime-report (PR #107270)

2024-09-05 Thread Tom Eccles via cfe-commits


@@ -254,6 +276,43 @@ class CompilerInstance {
   /// Produces the string which represents target feature
   std::string getTargetFeatures();
 
+  /// {
+  /// @name Timing
+  /// @{
+  bool isTimingEnabled() { return timingMgr.isEnabled(); }

tblah wrote:

nit: Do we really need this overload in addition to the `const` version?

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


[clang] [flang] [flang][Driver] Preliminary support for -ftime-report (PR #107270)

2024-09-05 Thread Tom Eccles via cfe-commits

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


[clang] [flang] [flang][Driver] Preliminary support for -ftime-report (PR #107270)

2024-09-05 Thread Tom Eccles via cfe-commits

https://github.com/tblah commented:

Thanks for working on this

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


[clang] [flang] [flang][Driver] Preliminary support for -ftime-report (PR #107270)

2024-09-05 Thread Tom Eccles via cfe-commits


@@ -0,0 +1,18 @@
+! Check that -ftime-report flag is passed as-is to fc1. The value of the flag
+! is only checked there. This behavior intentionally mirrors that of clang.
+!
+! -ftime-report= is currently not supported because we do not support detailed
+! timing information on the LLVM IR optimization and code generation passes.
+! When that is supported, these can be re-enabled.
+!
+! XFAIL: *

tblah wrote:

Maybe we should save this test for a PR enabling -ftime-report=?

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


[clang] [flang] [flang][Driver] Preliminary support for -ftime-report (PR #107270)

2024-09-05 Thread Tom Eccles via cfe-commits


@@ -143,6 +144,14 @@ class CompilerInvocation : public CompilerInvocationBase {
   },
   };
 
+  /// Whether to time the invocation. Set when -ftime-report or -ftime-report=
+  /// is enabled.
+  bool enableTimers;
+
+  /// Whether to report the timing of each run of an LLVM pass. Set when
+  /// -ftime-report=per-pass-run is enabled.
+  bool timeLLVMPassesPerRun;

tblah wrote:

I wonder if it would be better not to support `-ftime-report=` because we can't 
(currently) provide equivalent functionality for the MLIR passes, and these 
will all be dead untested code at the moment.

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


[clang] [flang] [flang][Driver] Preliminary support for -ftime-report (PR #107270)

2024-09-05 Thread Tom Eccles via cfe-commits


@@ -4,6 +4,7 @@ add_subdirectory(Decimal)
 add_subdirectory(Lower)
 add_subdirectory(Parser)
 add_subdirectory(Semantics)
+add_subdirectory(Support)

tblah wrote:

Why did you decide to put this in a new subdirectory and not just part of 
Frontend? Is there a plan to use this in other places in the future?

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


[clang] [flang] [flang][Driver] Preliminary support for -ftime-report (PR #107270)

2024-09-05 Thread Tom Eccles via cfe-commits


@@ -176,6 +205,26 @@ bool CompilerInstance::executeAction(FrontendAction &act) {
   act.endSourceFile();
 }
   }
+
+  if (timingMgr.isEnabled()) {
+timingScopeRoot.stop();
+
+// Write the timings to the associated output stream and clear all timers.
+// We need to provide another stream because the TimingManager will attempt
+// to print in its destructor even if it has been cleared. By the time that
+// destructor runs, the output streams will have been destroyed, so give it
+// a null stream.
+timingMgr.print();
+timingMgr.setOutput(
+
Fortran::support::createTimingFormatterText(mlir::thread_safe_nulls()));
+
+// This is deliberately done in "reverse" order and does not match the
+// behavior of clang.

tblah wrote:

What is the reason for diverging from clang here?

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


[clang] [Clang] CWG2749: relational operators involving pointers to void (PR #93046)

2024-09-05 Thread Mital Ashok via cfe-commits

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

>From e1172958f43af7490b5b6e3752a9070265ad17ca Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Wed, 22 May 2024 16:01:13 +0100
Subject: [PATCH 1/5] [Clang] CWG2749: relational operators involving pointers
 to void

https://cplusplus.github.io/CWG/issues/2749.html

This DR's effects are backported to C++98.

Does not affect C where integral constant expressions cannot involve pointers.
---
 clang/docs/ReleaseNotes.rst   |  4 ++
 .../include/clang/Basic/DiagnosticASTKinds.td |  2 -
 clang/lib/AST/ExprConstant.cpp| 10 
 clang/test/AST/Interp/literals.cpp|  8 +---
 clang/test/CXX/drs/cwg27xx.cpp| 46 ++-
 clang/test/CXX/expr/expr.const/p2-0x.cpp  | 11 +++--
 clang/www/cxx_dr_status.html  |  2 +-
 7 files changed, 58 insertions(+), 25 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2899bc5ed35ad0..4d9313f4c7ca57 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -237,6 +237,10 @@ Resolutions to C++ Defect Reports
 - P0522 implementation is enabled by default in all language versions, and
   provisional wording for CWG2398 is implemented.
 
+- Clang now allows comparing unequal object pointers that have been cast to 
``void *``
+  in constant expressions. These comparisons always worked in non-constant 
expressions.
+  (`CWG2749: Treatment of "pointer to void" for relational comparisons 
`_).
+
 C Language Changes
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index a024f9b2a9f8c0..b7aae9395e6357 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -148,8 +148,6 @@ def note_constexpr_var_init_weak : Note<
 def note_constexpr_typeid_polymorphic : Note<
   "typeid applied to expression of polymorphic type %0 is "
   "not allowed in a constant expression in C++ standards before C++20">;
-def note_constexpr_void_comparison : Note<
-  "comparison between unequal pointers to void has unspecified result">;
 def note_constexpr_temporary_here : Note<"temporary created here">;
 def note_constexpr_dynamic_alloc_here : Note<"heap allocation performed here">;
 def note_constexpr_conditional_never_const : Note<
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f1aa19e4409e15..d5a47a071e2cd7 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13627,16 +13627,6 @@ EvaluateComparisonBinaryOperator(EvalInfo &Info, const 
BinaryOperator *E,
 SubobjectDesignator &LHSDesignator = LHSValue.getLValueDesignator();
 SubobjectDesignator &RHSDesignator = RHSValue.getLValueDesignator();
 
-// C++11 [expr.rel]p3:
-//   Pointers to void (after pointer conversions) can be compared, with a
-//   result defined as follows: If both pointers represent the same
-//   address or are both the null pointer value, the result is true if the
-//   operator is <= or >= and false otherwise; otherwise the result is
-//   unspecified.
-// We interpret this as applying to pointers to *cv* void.
-if (LHSTy->isVoidPointerType() && LHSOffset != RHSOffset && IsRelational)
-  Info.CCEDiag(E, diag::note_constexpr_void_comparison);
-
 // C++11 [expr.rel]p2:
 // - If two pointers point to non-static data members of the same object,
 //   or to subobjects or array elements fo such members, recursively, the
diff --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index c160be06dd241c..ae7942aca39e63 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -191,12 +191,8 @@ namespace PointerComparison {
   constexpr bool v3 = null == pv; // ok
   constexpr bool v4 = qv == pv; // ok
 
-  /// FIXME: These two are rejected by the current interpreter, but
-  ///   accepted by GCC.
-  constexpr bool v5 = qv >= pv; // ref-error {{constant expression}} \
-// ref-note {{unequal pointers to void}}
-  constexpr bool v8 = qv > (void*)&s.a; // ref-error {{constant expression}} \
-// ref-note {{unequal pointers to 
void}}
+  constexpr bool v5 = qv >= pv;
+  constexpr bool v8 = qv > (void*)&s.a;
   constexpr bool v6 = qv > null; // both-error {{must be initialized by a 
constant expression}} \
  // both-note {{comparison between '&s.b' and 
'nullptr' has unspecified value}}
 
diff --git a/clang/test/CXX/drs/cwg27xx.cpp b/clang/test/CXX/drs/cwg27xx.cpp
index 53ddd566b7dbf9..f0c3c6dbdf97b0 100644
--- a/clang/test/CXX/drs/cwg27xx.cpp
+++ b/clang/test/CXX/drs/cwg27xx.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++98 -verify

[clang] [llvm] [AArch64] Implement NEON vamin/vamax intrinsics (PR #99041)

2024-09-05 Thread Momchil Velikov via cfe-commits

https://github.com/momchil-velikov updated 
https://github.com/llvm/llvm-project/pull/99041

>From 886c48dd7efa227f8605bfafef4204cefbb75d6e Mon Sep 17 00:00:00 2001
From: Momchil Velikov 
Date: Mon, 15 Jul 2024 17:50:43 +0100
Subject: [PATCH 1/4] [AArch64] Implement NEON vamin/vamax intrinsics

This patch implements the intrinsics of the form

floatNxM_t vamin[q]_fN(floatNxM_t vn, floatNxM_t vm);
floatNxM_t vamax[q]_fN(floatNxM_t vn, floatNxM_t vm);

as defined in https://github.com/ARM-software/acle/pull/324

Co-authored-by: Hassnaa Hamdi 
---
 clang/include/clang/Basic/arm_neon.td |   5 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  17 +++
 .../aarch64-neon-faminmax-intrinsics.c| 112 ++
 llvm/include/llvm/IR/IntrinsicsAArch64.td |   3 +
 .../lib/Target/AArch64/AArch64InstrFormats.td |  20 
 llvm/lib/Target/AArch64/AArch64InstrInfo.td   |   6 +-
 llvm/test/CodeGen/AArch64/neon-famin-famax.ll |  96 +++
 7 files changed, 257 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGen/aarch64-neon-faminmax-intrinsics.c
 create mode 100644 llvm/test/CodeGen/AArch64/neon-famin-famax.ll

diff --git a/clang/include/clang/Basic/arm_neon.td 
b/clang/include/clang/Basic/arm_neon.td
index 536c0652280b9d..d35fc6c449de0a 100644
--- a/clang/include/clang/Basic/arm_neon.td
+++ b/clang/include/clang/Basic/arm_neon.td
@@ -2115,3 +2115,8 @@ let ArchGuard = "defined(__aarch64__)", TargetGuard = 
"lut" in {
 def VLUTI4_BF_X2_Q   : SInst<"vluti4_laneq_x2", ".2(;
   }
 }
+
+let ArchGuard = "defined(__aarch64__)", TargetGuard = "faminmax" in {
+  def FAMIN : WInst<"vamin", "...", "fhQdQfQh">;
+  def FAMAX : WInst<"vamax", "...", "fhQdQfQh">;
+}
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e826c1c6fbbd23..3625d783acdaf1 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -13570,6 +13570,23 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 Int = Intrinsic::aarch64_neon_vluti4q_laneq_x2;
 return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "vluti4q_laneq_x2");
   }
+
+  case NEON::BI__builtin_neon_vamin_f16:
+  case NEON::BI__builtin_neon_vaminq_f16:
+  case NEON::BI__builtin_neon_vamin_f32:
+  case NEON::BI__builtin_neon_vaminq_f32:
+  case NEON::BI__builtin_neon_vaminq_f64: {
+Int = Intrinsic::aarch64_neon_famin;
+return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "famin");
+  }
+  case NEON::BI__builtin_neon_vamax_f16:
+  case NEON::BI__builtin_neon_vamaxq_f16:
+  case NEON::BI__builtin_neon_vamax_f32:
+  case NEON::BI__builtin_neon_vamaxq_f32:
+  case NEON::BI__builtin_neon_vamaxq_f64: {
+Int = Intrinsic::aarch64_neon_famax;
+return EmitNeonCall(CGM.getIntrinsic(Int, Ty), Ops, "famax");
+  }
   }
 }
 
diff --git a/clang/test/CodeGen/aarch64-neon-faminmax-intrinsics.c 
b/clang/test/CodeGen/aarch64-neon-faminmax-intrinsics.c
new file mode 100644
index 00..631e9738b85c5f
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-neon-faminmax-intrinsics.c
@@ -0,0 +1,112 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+#include 
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +neon 
-target-feature +faminmax -O3 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +neon 
-target-feature +faminmax -S -O3 -Werror -Wall -o /dev/null %s
+
+// CHECK-LABEL: define dso_local <4 x half> @test_vamin_f16(
+// CHECK-SAME: <4 x half> noundef [[VN:%.*]], <4 x half> noundef [[VM:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[FAMIN2_I:%.*]] = tail call <4 x half> 
@llvm.aarch64.neon.famin.v4f16(<4 x half> [[VN]], <4 x half> [[VM]])
+// CHECK-NEXT:ret <4 x half> [[FAMIN2_I]]
+//
+float16x4_t test_vamin_f16(float16x4_t vn, float16x4_t vm) {
+  return vamin_f16(vn, vm);
+}
+
+// CHECK-LABEL: define dso_local <8 x half> @test_vaminq_f16(
+// CHECK-SAME: <8 x half> noundef [[VN:%.*]], <8 x half> noundef [[VM:%.*]]) 
local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[FAMIN2_I:%.*]] = tail call <8 x half> 
@llvm.aarch64.neon.famin.v8f16(<8 x half> [[VN]], <8 x half> [[VM]])
+// CHECK-NEXT:ret <8 x half> [[FAMIN2_I]]
+//
+float16x8_t test_vaminq_f16(float16x8_t vn, float16x8_t vm) {
+  return vaminq_f16(vn, vm);
+
+}
+
+// CHECK-LABEL: define dso_local <2 x float> @test_vamin_f32(
+// CHECK-SAME: <2 x float> noundef [[VN:%.*]], <2 x float> noundef [[VM:%.*]]) 
local_unnamed_addr #[[ATTR0]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[FAMIN2_I:%.*]] = tail call <2 x float> 
@llvm.aarch64.neon.famin.v2f32(<2 x float> [[VN]], <2 x float> [[VM]])
+// CHECK-NEXT:ret <2 x float> [[FAMIN2_I]]
+//
+float32x2_t test_vamin_f32(float32x2_t vn, float32x2_t vm) {
+  return vamin_f32(vn, vm);
+
+}
+
+// CHECK-LABEL: define dso_local <4 x float

[clang] [llvm] [AArch64] Implement NEON vamin/vamax intrinsics (PR #99041)

2024-09-05 Thread Momchil Velikov via cfe-commits


@@ -2115,3 +2115,8 @@ let ArchGuard = "defined(__aarch64__)", TargetGuard = 
"lut" in {
 def VLUTI4_BF_X2_Q   : SInst<"vluti4_laneq_x2", ".2(;
   }
 }
+
+let ArchGuard = "defined(__aarch64__)", TargetGuard = "faminmax" in {

momchil-velikov wrote:

Done

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


[clang] 87b4b64 - Fix a typo in CheckExprLifetime.cpp, NFC

2024-09-05 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2024-09-05T13:18:39+02:00
New Revision: 87b4b648585f69a2ea148e86543aa31474e59acd

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

LOG: Fix a typo in CheckExprLifetime.cpp, NFC

Added: 


Modified: 
clang/lib/Sema/CheckExprLifetime.cpp

Removed: 




diff  --git a/clang/lib/Sema/CheckExprLifetime.cpp 
b/clang/lib/Sema/CheckExprLifetime.cpp
index 1482711cc2839e..6ed6b8aaa70400 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -328,7 +328,7 @@ static bool shouldTrackFirstArgument(const FunctionDecl 
*FD) {
 // We assuments that a normal assingment operator always returns *this, that 
is,
 // an lvalue reference that is the same type as the implicit object parameter
 // (or the LHS for a non-member operator$=).
-static bool isNormalAsisgnmentOperator(const FunctionDecl *FD) {
+static bool isNormalAssignmentOperator(const FunctionDecl *FD) {
   OverloadedOperatorKind OO = FD->getDeclName().getCXXOverloadedOperator();
   if (OO == OO_Equal || isCompoundAssignmentOperator(OO)) {
 QualType RetT = FD->getReturnType();
@@ -362,7 +362,7 @@ static bool implicitObjectParamIsLifetimeBound(const 
FunctionDecl *FD) {
   return true;
   }
 
-  return isNormalAsisgnmentOperator(FD);
+  return isNormalAssignmentOperator(FD);
 }
 
 // Visit lifetimebound or gsl-pointer arguments.
@@ -940,10 +940,10 @@ static bool pathOnlyHandlesGslPointer(IndirectLocalPath 
&Path) {
   return false;
 }
 
-static bool isAssginmentOperatorLifetimeBound(CXXMethodDecl *CMD) {
+static bool isAssignmentOperatorLifetimeBound(CXXMethodDecl *CMD) {
   if (!CMD)
 return false;
-  return isNormalAsisgnmentOperator(CMD) && CMD->param_size() == 1 &&
+  return isNormalAssignmentOperator(CMD) && CMD->param_size() == 1 &&
  CMD->getParamDecl(0)->hasAttr();
 }
 
@@ -953,7 +953,7 @@ static bool shouldRunGSLAssignmentAnalysis(const Sema 
&SemaRef,
   diag::warn_dangling_lifetime_pointer_assignment, SourceLocation());
   return (EnableGSLAssignmentWarnings &&
   (isRecordWithAttr(Entity.LHS->getType()) ||
-   isAssginmentOperatorLifetimeBound(Entity.AssignmentOperator)));
+   isAssignmentOperatorLifetimeBound(Entity.AssignmentOperator)));
 }
 
 static void checkExprLifetimeImpl(Sema &SemaRef,



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


[clang] 3e07090 - Fix llvm-else-after-return clang-tidy warning in CheckExprLifetime.cpp, NFC

2024-09-05 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2024-09-05T13:24:38+02:00
New Revision: 3e070906eff720dc44aee86e533e12aafc8bb14b

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

LOG: Fix llvm-else-after-return clang-tidy warning in CheckExprLifetime.cpp, NFC

Added: 


Modified: 
clang/lib/Sema/CheckExprLifetime.cpp

Removed: 




diff  --git a/clang/lib/Sema/CheckExprLifetime.cpp 
b/clang/lib/Sema/CheckExprLifetime.cpp
index 6ed6b8aaa70400..8f4d5d50669f14 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -288,7 +288,8 @@ static bool shouldTrackImplicitObjectArg(const 
CXXMethodDecl *Callee) {
 // Map and set types.
 .Cases("find", "equal_range", "lower_bound", "upper_bound", true)
 .Default(false);
-  } else if (Callee->getReturnType()->isReferenceType()) {
+  }
+  if (Callee->getReturnType()->isReferenceType()) {
 if (!Callee->getIdentifier()) {
   auto OO = Callee->getOverloadedOperator();
   return OO == OverloadedOperatorKind::OO_Subscript ||
@@ -316,7 +317,8 @@ static bool shouldTrackFirstArgument(const FunctionDecl 
*FD) {
 .Cases("end", "rend", "cend", "crend", true)
 .Case("data", true)
 .Default(false);
-  } else if (FD->getReturnType()->isReferenceType()) {
+  }
+  if (FD->getReturnType()->isReferenceType()) {
 return llvm::StringSwitch(FD->getName())
 .Cases("get", "any_cast", true)
 .Default(false);



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


[clang] [analyzer] Prevent crash due to missing EventDispatch in corner case (PR #107294)

2024-09-05 Thread Donát Nagy via cfe-commits

https://github.com/NagyDonat commented:

I investigated this situation and I found that this crash is not limited to 
empty source files -- I'd guess that the analyzer would crash on any input if 
it's executed as
```
// RUN: %clang_analyze_cc1 -w -analyzer-checker=nullability \
// RUN:   -analyzer-output=text -verify %s
```

The real reason why this crash is rare is that two core checkers 
(`core.NullDereference` and `core.NonNullParamChecker`) are derived from 
`EventDispatcher` so the assertion is not triggered in 
the "normal" case when the core checkers are enabled.

Note that the documentation of core checkers says that _"These checkers must be 
always switched on as other checker rely on them."_; however we should still 
eliminate this assertion failure because it's ugly.

Registering `NullabilityChecker` as an `EventDispatcher` (which happens to 
never dispatch any events) definitely works, but I think it would be more 
elegant to simply remove the assertion that caused the crash. Registering a 
handler for an event which cannot be emitted (under the current unusual config) 
is not an error, it should not trigger an assertion failure.

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


[clang] [compiler-rt] [libcxx] [lldb] [llvm] Rename Sanitizer Coverage => Coverage Sanitizer (PR #106505)

2024-09-05 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

Precommit CI test failures look related:
```
_bk;t=1725284334938 TEST 'LLVM :: 
tools/sancov/symbolize.test' FAILED 

_bk;t=1725284334938Exit Code: 1

_bk;t=1725284334938

_bk;t=1725284334938Command Output (stderr):

_bk;t=1725284334938--

_bk;t=1725284334938RUN: at line 2: 
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-c4bpt-1/llvm-project/github-pull-requests/build/bin/sancov
 -symbolize -strip_path_prefix="llvm/" 
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-c4bpt-1/llvm-project/github-pull-requests/llvm/test/tools/sancov/Inputs/test-linux_x86_64
 
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-c4bpt-1/llvm-project/github-pull-requests/llvm/test/tools/sancov/Inputs/test-linux_x86_64.0.sancov
 | 
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-c4bpt-1/llvm-project/github-pull-requests/build/bin/FileCheck
 
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-c4bpt-1/llvm-project/github-pull-requests/llvm/test/tools/sancov/symbolize.test
 --check-prefixes=CHECK,STRIP

_bk;t=1725284334938+ 
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-c4bpt-1/llvm-project/github-pull-requests/build/bin/sancov
 -symbolize -strip_path_prefix=llvm/ 
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-c4bpt-1/llvm-project/github-pull-requests/llvm/test/tools/sancov/Inputs/test-linux_x86_64
 
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-c4bpt-1/llvm-project/github-pull-requests/llvm/test/tools/sancov/Inputs/test-linux_x86_64.0.sancov

_bk;t=1725284334938+ 
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-c4bpt-1/llvm-project/github-pull-requests/build/bin/FileCheck
 
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-c4bpt-1/llvm-project/github-pull-requests/llvm/test/tools/sancov/symbolize.test
 --check-prefixes=CHECK,STRIP

_bk;t=1725284334938/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-c4bpt-1/llvm-project/github-pull-requests/llvm/test/tools/sancov/symbolize.test:13:13:
 error: CHECK-NEXT: expected string not found in input

_bk;t=1725284334938CHECK-NEXT: "binary-hash": 
"BB3CDD5045AED83906F6ADCC1C4DAF7E2596A6B5",

_bk;t=1725284334938^

_bk;t=1725284334938:8:4: note: scanning from here

_bk;t=1725284334938 ],

_bk;t=1725284334938   ^

_bk;t=1725284334938:9:2: note: possible intended match here

_bk;t=1725284334938 "binary-hash": "A13A863C18DD4DA9E926DB113A369DA45AE33134",

_bk;t=1725284334938 ^

_bk;t=1725284334938

_bk;t=1725284334938Input file: 

_bk;t=1725284334938Check file: 
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-c4bpt-1/llvm-project/github-pull-requests/llvm/test/tools/sancov/symbolize.test

_bk;t=1725284334938

_bk;t=1725284334938-dump-input=help explains the following input dump.

_bk;t=1725284334938

_bk;t=1725284334938Input was:

_bk;t=1725284334938<<

_bk;t=1725284334938   1: { 

_bk;t=1725284334938   2:  "covered-points": [ 

_bk;t=1725284334938   3:  "4e132b", 

_bk;t=1725284334938   4:  "4e1472", 

_bk;t=1725284334938   5:  "4e1520", 

_bk;t=1725284334938   6:  "4e1553", 

_bk;t=1725284334938   7:  "4e1586" 

_bk;t=1725284334938   8:  ], 

_bk;t=1725284334938next:13'0X error: no match found

_bk;t=1725284334938   9:  "binary-hash": 
"A13A863C18DD4DA9E926DB113A369DA45AE33134", 

_bk;t=1725284334938next:13'0 


_bk;t=1725284334938next:13'1  ?   
possible intended match

_bk;t=1725284334938  10:  "point-symbol-info": { 

_bk;t=1725284334938next:13'0 

_bk;t=1725284334938  11:  "test/tools/sancov/Inputs/test.cpp": { 

_bk;t=1725284334938next:13'0 

_bk;t=1725284334938  12:  "bar(std::string)": { 

_bk;t=1725284334938next:13'0 ~~~

_bk;t=1725284334938  13:  "4e132b": "12:0" 

_bk;t=1725284334938next:13'0 ~~

_bk;t=1725284334938  14:  }, 

_bk;t=1725284334938next:13'0 

_bk;t=1725284334938   .

_bk;t=1725284334938   .

_bk;t=1725284334938   .

_bk;t=1725284334938>>

_bk;t=1725284334938

_bk;t=1725284334938--

_bk;t=1725284334938

_bk;t=1725284334938

_bk;t=1725284334939FAIL: LLVM :: 
tools/sancov/symbolize_noskip_dead_files.test (86063 of 96817)

_bk;t=1725284334939 TEST 'LLVM :: 
tools/sancov/symbolize_noskip_dead_files.test' FAILED 

_bk;t=1725284334939Exit Code: 1

_bk;t=1725284334939

_bk;t=1725284334939Command Output (stderr):

_bk;t=1725284334939--

_bk;t=1725284334939RUN: at line 2: 
/var/lib/buildkite-agent/builds/linux-56-59b8f5d88-c4bpt-1/llvm-project/github-pull-requests/build/bin/sancov
 -symbolize -skip-dead-fil

[clang] [libc] [libc][c11] implement ctime (PR #107285)

2024-09-05 Thread Зишан Мирза via cfe-commits

https://github.com/zimirza updated 
https://github.com/llvm/llvm-project/pull/107285

From b982621407a1ab1746a023809aae5c6a2b983679 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=97=D0=B8=D1=88=D0=B0=D0=BD=20=D0=9C=D0=B8=D1=80=D0=B7?=
 =?UTF-8?q?=D0=B0?= <149377404+zimi...@users.noreply.github.com>
Date: Tue, 3 Sep 2024 22:47:30 +0200
Subject: [PATCH 01/17] [libc][c11] implement ctime (#86567)

---
 libc/src/time/CMakeLists.txt  |  11 ++
 libc/src/time/ctime.cpp   |  23 
 libc/src/time/ctime.h |  21 +++
 libc/src/time/time_utils.h|  46 +++
 libc/test/src/time/ctime_test.cpp | 215 ++
 5 files changed, 316 insertions(+)
 create mode 100644 libc/src/time/ctime.cpp
 create mode 100644 libc/src/time/ctime.h
 create mode 100644 libc/test/src/time/ctime_test.cpp

diff --git a/libc/src/time/CMakeLists.txt b/libc/src/time/CMakeLists.txt
index 5680718715974e..befe67677f3ec7 100644
--- a/libc/src/time/CMakeLists.txt
+++ b/libc/src/time/CMakeLists.txt
@@ -36,6 +36,17 @@ add_entrypoint_object(
 libc.include.time
 )
 
+add_entrypoint_object(
+  ctime
+  SRCS
+ctime.cpp
+  HDRS
+ctime.h
+  DEPENDS
+.time_utils
+libc.include.time
+)
+
 add_entrypoint_object(
   difftime
   SRCS
diff --git a/libc/src/time/ctime.cpp b/libc/src/time/ctime.cpp
new file mode 100644
index 00..f3181816ad9ab1
--- /dev/null
+++ b/libc/src/time/ctime.cpp
@@ -0,0 +1,23 @@
+//===-- Implementation of asctime function 
===//
+//
+// 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 "src/time/ctime.h"
+#include "src/__support/common.h"
+#include "src/__support/macros/config.h"
+#include "src/time/time_utils.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+using LIBC_NAMESPACE::time_utils::TimeConstants;
+
+LLVM_LIBC_FUNCTION(char *, ctime, (const struct tm *timeptr)) {
+  static char buffer[TimeConstants::CTIME_BUFFER_SIZE];
+  return time_utils::ctime(timeptr, buffer, TimeConstants::CTIME_MAX_BYTES);
+}
+
+} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/time/ctime.h b/libc/src/time/ctime.h
new file mode 100644
index 00..ec5530ffb5bc71
--- /dev/null
+++ b/libc/src/time/ctime.h
@@ -0,0 +1,21 @@
+//===-- Implementation header of ctime *- C++ -*-===//
+//
+// 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 LLVM_LIBC_SRC_TIME_CTIME_H
+#define LLVM_LIBC_SRC_TIME_CTIME_H
+
+#include "src/__support/macros/config.h"
+#include 
+
+namespace LIBC_NAMESPACE_DECL {
+
+char *ctime(const struct tm *timeptr);
+
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_SRC_TIME_CTIME_H
diff --git a/libc/src/time/time_utils.h b/libc/src/time/time_utils.h
index 47f55f7d389122..6fa590fefac8d0 100644
--- a/libc/src/time/time_utils.h
+++ b/libc/src/time/time_utils.h
@@ -62,6 +62,9 @@ struct TimeConstants {
   static constexpr int ASCTIME_BUFFER_SIZE = 256;
   static constexpr int ASCTIME_MAX_BYTES = 26;
 
+  static constexpr int CTIME_BUFFER_SIZE = 256;
+  static constexpr int CTIME_MAX_BYTES = 26;
+
   /* 2000-03-01 (mod 400 year, immediately after feb29 */
   static constexpr int64_t SECONDS_UNTIL2000_MARCH_FIRST =
   (946684800LL + SECONDS_PER_DAY * (31 + 29));
@@ -145,6 +148,49 @@ LIBC_INLINE char *asctime(const struct tm *timeptr, char 
*buffer,
   return buffer;
 }
 
+LIBC_INLINE char *ctime(const struct tm *timeptr, char *buffer,
+size_t bufferLength) {
+  if (timeptr == nullptr || buffer == nullptr) {
+invalid_value();
+return nullptr;
+  }
+  if (timeptr->tm_wday < 0 ||
+  timeptr->tm_wday > (TimeConstants::DAYS_PER_WEEK - 1)) {
+invalid_value();
+return nullptr;
+  }
+  if (timeptr->tm_mon < 0 ||
+  timeptr->tm_mon > (TimeConstants::MONTHS_PER_YEAR - 1)) {
+invalid_value();
+return nullptr;
+  }
+
+  // TODO(rtenneti): i18n the following strings.
+  static const char *week_days_name[TimeConstants::DAYS_PER_WEEK] = {
+  "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
+
+  static const char *months_name[TimeConstants::MONTHS_PER_YEAR] = {
+  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
+
+  // TODO(michaelr): look into removing this call to __builtin_snprintf that 
may
+  // be emitted as a call to snprintf. Alternatively, look into using our
+  // internal printf machinery.
+  int written_size = __builtin_snprintf(
+  buffer, bufferLength, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
+  week_days

[clang] [clang][C23] Support N3029 Improved Normal Enumerations (PR #103917)

2024-09-05 Thread Aaron Ballman via cfe-commits


@@ -169,13 +169,19 @@ enum class GH42372_2 {
   One
 };
 
+enum IncOverflow {
+  V2 = __INT_MAX__,
+  V3 // c99-warning {{incremented enumerator value that is exceeding range of 
'int' is a C23 extension}}
+#if __STDC_VERSION__ >= 202311L

AaronBallman wrote:

You can give the C23 RUN line its own `-verify` prefix rather than using `#if`

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


[clang] [clang][C23] Support N3029 Improved Normal Enumerations (PR #103917)

2024-09-05 Thread Aaron Ballman via cfe-commits

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


[clang] [clang][C23] Support N3029 Improved Normal Enumerations (PR #103917)

2024-09-05 Thread Aaron Ballman via cfe-commits


@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -verify -triple x86_64-unknown-linux-gnu -fsyntax-only 
--embed-dir=%S/Inputs -std=c23 %s -pedantic -Wpre-c23-compat

AaronBallman wrote:

```suggestion
// RUN: %clang_cc1 -verify -triple x86_64-unknown-linux-gnu -fsyntax-only 
-std=c23 %s -pedantic -Wpre-c23-compat
```

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


[clang] [clang][C23] Support N3029 Improved Normal Enumerations (PR #103917)

2024-09-05 Thread Aaron Ballman via cfe-commits


@@ -6194,9 +6195,12 @@ def err_misplaced_ivar : Error<
 def warn_ivars_in_interface : Warning<
   "declaration of instance variables in the interface is deprecated">,
   InGroup>, DefaultIgnore;
-def ext_enum_value_not_int : Extension<
-  "ISO C restricts enumerator values to range of 'int' (%0 is too "
-  "%select{small|large}1)">;
+def ext_c23_enum_value_not_int : Extension<
+  "enumerator values exceeding range of 'int' are a C23 extension (%0 is too "
+  "%select{small|large}1)">, InGroup;
+def warn_c17_compat_enum_value_not_int : Warning<
+  "enumerator values exceeding range of 'int' are incompatible with C 
standards before C23 (%0 is too "
+  "%select{small|large}1)">, DefaultIgnore, InGroup;

AaronBallman wrote:

We could add another `%select` in here:
```
def ext_c23_enum_value_not_int : Extension<
  "%select{|incremented }0enumerator value which exceeds the range of 'int' is 
a C23 extension (%1 is too "
  "%select{small|large}2)">, InGroup;
```
WDYT?

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


[clang] [clang][C23] Support N3029 Improved Normal Enumerations (PR #103917)

2024-09-05 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

Thank you for working on this!

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


  1   2   3   4   5   >