[clang] [llvm] [IR] Add getelementptr nusw and nuw flags (PR #90824)

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

https://github.com/nikic updated https://github.com/llvm/llvm-project/pull/90824

>From b74cc982c95f7750a581e93bc0f246786c69ef3d Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Thu, 2 May 2024 12:11:18 +0900
Subject: [PATCH 1/7] Add support for getelementptr nusw and nuw

---
 llvm/docs/LangRef.rst | 57 --
 llvm/docs/ReleaseNotes.rst|  1 +
 llvm/include/llvm/AsmParser/LLToken.h |  1 +
 llvm/include/llvm/Bitcode/LLVMBitCodes.h  |  8 +++
 llvm/include/llvm/IR/Instructions.h   | 14 +
 llvm/include/llvm/IR/Operator.h   | 26 +++-
 llvm/lib/AsmParser/LLLexer.cpp|  1 +
 llvm/lib/AsmParser/LLParser.cpp   | 21 ++-
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 20 +--
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 11 +++-
 llvm/lib/IR/AsmWriter.cpp |  4 ++
 llvm/lib/IR/Instruction.cpp   | 22 +--
 llvm/lib/IR/Instructions.cpp  | 16 +
 llvm/lib/IR/Operator.cpp  |  3 +-
 .../Scalar/SeparateConstOffsetFromGEP.cpp |  8 +++
 .../Transforms/Utils/FunctionComparator.cpp   |  6 ++
 llvm/lib/Transforms/Vectorize/VPlan.h |  5 ++
 llvm/test/Assembler/flags.ll  | 43 +
 llvm/test/Transforms/InstCombine/freeze.ll| 22 +++
 llvm/test/Transforms/SimplifyCFG/HoistCode.ll | 60 +++
 llvm/test/tools/llvm-reduce/reduce-flags.ll   | 18 --
 .../deltas/ReduceInstructionFlags.cpp |  4 ++
 22 files changed, 333 insertions(+), 38 deletions(-)

diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 358eb4b867925..74097343a444d 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -11184,6 +11184,8 @@ Syntax:
 
= getelementptr , ptr {,  }*
= getelementptr inbounds , ptr {,  }*
+   = getelementptr nusw , ptr {,  }*
+   = getelementptr nuw , ptr {,  }*
= getelementptr inrange(S,E) , ptr {,  }*
= getelementptr ,  ,  

 
@@ -11299,27 +11301,46 @@ memory though, even if it happens to point into 
allocated storage. See the
 :ref:`Pointer Aliasing Rules ` section for more
 information.
 
-If the ``inbounds`` keyword is present, the result value of a
-``getelementptr`` with any non-zero indices is a
-:ref:`poison value ` if one of the following rules is violated:
-
-*  The base pointer has an *in bounds* address of an allocated object, which
+The ``getelementptr`` instruction may have a number of attributes that impose
+additional rules. If any of the rules are violated, the result value is a
+:ref:`poison value `. In cases where the base is a vector of
+pointers, the attributes apply to each computation element-wise.
+
+For ``nusw`` (no unsigned signed wrap):
+
+ * If the type of an index is larger than the pointer index type, the
+   truncation to the pointer index type preserves the signed value
+   (``trunc nsw``).
+ * The multiplication of an index by the type size does not wrap the pointer
+   index type in a signed sense (``mul nsw``).
+ * The successive addition of each offset (without adding the base address)
+   does not wrap the pointer index type in a signed sense (``add nsw``).
+ * The successive addition of the current address, truncated to the index type
+   and interpreted as an unsigned number, and each offset, interpreted as
+   a signed number, does not wrap the index type.
+
+For ``nuw`` (no unsigned wrap):
+
+ * If the type of an index is larger than the pointer index type, the
+   truncation to the pointer index type preserves the unsigned value
+   (``trunc nuw``).
+ * The multiplication of an index by the type size does not wrap the pointer
+   index type in an unsigned sense (``mul nuw``).
+ * The successive addition of each offset (without adding the base address)
+   does not wrap the pointer index type in an unsigned sense (``add nuw``).
+ * The successive addition of the current address, truncated to the index type
+   and interpreted as an unsigned number, and each offset, also interpreted as
+   an unsigned number, does not wrap the index type (``add nuw``).
+
+For ``inbounds`` all rules of the ``nusw`` attribute apply. Additionally,
+if the ``getelementptr`` has any non-zero indices, the following rules apply:
+
+ * The base pointer has an *in bounds* address of an allocated object, which
means that it points into an allocated object, or to its end. Note that the
object does not have to be live anymore; being in-bounds of a deallocated
object is sufficient.
-*  If the type of an index is larger than the pointer index type, the
-   truncation to the pointer index type preserves the signed value.
-*  The multiplication of an index by the type size does not wrap the pointer
-   index type in a signed sense (``nsw``).
-*  The successive addition of each offset (without adding the base address) 
does
-   not wrap the pointer index type in a signed sense (``nsw`

[clang] [clang][NFC] Refactor `Sema::TagUseKind` (PR #92689)

2024-05-21 Thread Vlad Serebrennikov via cfe-commits

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

>From 9c89a7b451221d79f96fd1fc1d015c6a22b9f66e Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sun, 19 May 2024 15:00:38 +0300
Subject: [PATCH] [clang][NFC] Refactor `Sema::TagUseKind`

This patch makes `TagUseKind` a scoped enumeration, and moves it outside of 
`Sema` class, making it eligible for forward declaring.
---
 clang/include/clang/Parse/Parser.h |   2 +-
 clang/include/clang/Sema/Sema.h|  14 ++--
 clang/lib/Parse/ParseDecl.cpp  |  33 +
 clang/lib/Parse/ParseDeclCXX.cpp   |  50 +++---
 clang/lib/Sema/SemaDecl.cpp|  91 
 clang/lib/Sema/SemaDeclCXX.cpp |  13 ++--
 clang/lib/Sema/SemaTemplate.cpp| 107 +++--
 7 files changed, 160 insertions(+), 150 deletions(-)

diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index af50164a8f93f..690b1ef66af9f 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -2814,7 +2814,7 @@ class Parser : public CodeCompletionHandler {
SourceLocation CorrectLocation);
 
   void stripTypeAttributesOffDeclSpec(ParsedAttributes &Attrs, DeclSpec &DS,
-  Sema::TagUseKind TUK);
+  TagUseKind TUK);
 
   // FixItLoc = possible correct location for the attributes
   void ProhibitAttributes(ParsedAttributes &Attrs,
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index d4d4a82525a02..071c0f8d9c406 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -445,6 +445,13 @@ enum class CheckedConversionKind {
   ForBuiltinOverloadedOp
 };
 
+enum class TagUseKind {
+  Reference,   // Reference to a tag:  'struct foo *X;'
+  Declaration, // Fwd decl of a tag:   'struct foo;'
+  Definition,  // Definition of a tag: 'struct foo { int X; } Y;'
+  Friend   // Friend declaration:  'friend struct foo;'
+};
+
 /// Sema - This implements semantic analysis and AST building for C.
 /// \nosubgrouping
 class Sema final : public SemaBase {
@@ -3161,13 +3168,6 @@ class Sema final : public SemaBase {
 bool isDefinition, SourceLocation 
NewTagLoc,
 const IdentifierInfo *Name);
 
-  enum TagUseKind {
-TUK_Reference,   // Reference to a tag:  'struct foo *X;'
-TUK_Declaration, // Fwd decl of a tag:   'struct foo;'
-TUK_Definition,  // Definition of a tag: 'struct foo { int X; } Y;'
-TUK_Friend   // Friend declaration:  'friend struct foo;'
-  };
-
   enum OffsetOfKind {
 // Not parsing a type within __builtin_offsetof.
 OOK_Outside,
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 8405b44685ae4..5873a2633fc80 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -1905,9 +1905,8 @@ void 
Parser::DiagnoseCXX11AttributeExtension(ParsedAttributes &Attrs) {
 // variable.
 // This function moves attributes that should apply to the type off DS to 
Attrs.
 void Parser::stripTypeAttributesOffDeclSpec(ParsedAttributes &Attrs,
-DeclSpec &DS,
-Sema::TagUseKind TUK) {
-  if (TUK == Sema::TUK_Reference)
+DeclSpec &DS, TagUseKind TUK) {
+  if (TUK == TagUseKind::Reference)
 return;
 
   llvm::SmallVector ToBeMoved;
@@ -5359,9 +5358,9 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, 
DeclSpec &DS,
   // enum foo {..};  void bar() { enum foo; }<- new foo in bar.
   // enum foo {..};  void bar() { enum foo x; }  <- use of old foo.
   //
-  Sema::TagUseKind TUK;
+  TagUseKind TUK;
   if (AllowEnumSpecifier == AllowDefiningTypeSpec::No)
-TUK = Sema::TUK_Reference;
+TUK = TagUseKind::Reference;
   else if (Tok.is(tok::l_brace)) {
 if (DS.isFriendSpecified()) {
   Diag(Tok.getLocation(), diag::err_friend_decl_defines_type)
@@ -5373,9 +5372,9 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, 
DeclSpec &DS,
   ScopedEnumKWLoc = SourceLocation();
   IsScopedUsingClassTag = false;
   BaseType = TypeResult();
-  TUK = Sema::TUK_Friend;
+  TUK = TagUseKind::Friend;
 } else {
-  TUK = Sema::TUK_Definition;
+  TUK = TagUseKind::Definition;
 }
   } else if (!isTypeSpecifier(DSC) &&
  (Tok.is(tok::semi) ||
@@ -5384,7 +5383,7 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, 
DeclSpec &DS,
 // An opaque-enum-declaration is required to be standalone (no preceding or
 // following tokens in the declaration). Sema enforces this separately by
 // diagnosing anything else in the DeclSpec.
-TUK = DS.isFriendSpecified() ? Sema::TUK_Friend : Sema::TUK_Declaration;
+TUK = DS.isFriendSpecified() ? TagUseKind::Friend 

[clang] [clang][AST] Fix end location of DeclarationNameInfo on instantiated methods (PR #92654)

2024-05-21 Thread Balazs Benics via cfe-commits

https://github.com/steakhal updated 
https://github.com/llvm/llvm-project/pull/92654

>From 58ca4d9be1dbc43ad40b6e26b8a5d79e20be8d93 Mon Sep 17 00:00:00 2001
From: Alejandro _lvarez Ayll_n 
Date: Sat, 18 May 2024 16:53:33 +0200
Subject: [PATCH 1/2] [clang][AST] Fix end location of DeclarationNameInfo on
 instantiated methods

Fixes #71161

[D64087](https://reviews.llvm.org/D64087) updated some locations of the
instantiated method but forgot `DNLoc`.

`FunctionDecl::getNameInfo()` constructs a `DeclarationNameInfo` using
`Decl::Loc` as the beginning of the declaration name, and
`FunctionDecl::DNLoc` to compute the end of the declaration name. The
former was updated, but the latter was not, so
`DeclarationName::getSourceRange()` would return a range where the end
of the declaration name could come before its beginning.

Patch by Alejandro Alvarez Ayllon
Co-authored-by: steakhal

CPP-5166
---
 clang/include/clang/AST/Decl.h|  2 ++
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  1 +
 clang/unittests/AST/DeclTest.cpp  | 31 +++
 3 files changed, 34 insertions(+)

diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 5e485ccb85a13..7fd80b90d1033 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -2188,6 +2188,8 @@ class FunctionDecl : public DeclaratorDecl,
 
   void setRangeEnd(SourceLocation E) { EndRangeLoc = E; }
 
+  void setDeclarationNameLoc(DeclarationNameLoc L) { DNLoc = L; }
+
   /// Returns the location of the ellipsis of a variadic function.
   SourceLocation getEllipsisLoc() const {
 const auto *FPT = getType()->getAs();
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 381d79b2fcd46..6d736d0771eac 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -5055,6 +5055,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation 
PointOfInstantiation,
   Function->setLocation(PatternDecl->getLocation());
   Function->setInnerLocStart(PatternDecl->getInnerLocStart());
   Function->setRangeEnd(PatternDecl->getEndLoc());
+  Function->setDeclarationNameLoc(PatternDecl->getNameInfo().getInfo());
 
   EnterExpressionEvaluationContext EvalContext(
   *this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
diff --git a/clang/unittests/AST/DeclTest.cpp b/clang/unittests/AST/DeclTest.cpp
index 2530ce74eb6a3..16aa2b50b7a06 100644
--- a/clang/unittests/AST/DeclTest.cpp
+++ b/clang/unittests/AST/DeclTest.cpp
@@ -545,3 +545,34 @@ TEST(Decl, TemplateArgumentDefaulted) {
   EXPECT_TRUE(ArgList.get(2).getIsDefaulted());
   EXPECT_TRUE(ArgList.get(3).getIsDefaulted());
 }
+
+TEST(Decl, CXXDestructorDeclsShouldHaveWellFormedNameInfoRanges) {
+  // GH71161
+  llvm::Annotations Code(R"cpp(
+template  struct Resource {
+  ~Resource(); // 1
+};
+template 
+Resource::~Resource() {} // 2,3
+
+void instantiate_template() {
+  Resource x;
+}
+)cpp");
+
+  auto AST = tooling::buildASTFromCode(Code.code());
+  ASTContext &Ctx = AST->getASTContext();
+
+  const auto &SM = Ctx.getSourceManager();
+  auto GetNameInfoRange = [&SM](const BoundNodes &Match) {
+const auto *D = Match.getNodeAs("dtor");
+return D->getNameInfo().getSourceRange().printToString(SM);
+  };
+
+  auto Matches = match(findAll(cxxDestructorDecl().bind("dtor")),
+   *Ctx.getTranslationUnitDecl(), Ctx);
+  ASSERT_EQ(Matches.size(), 3U);
+  EXPECT_EQ(GetNameInfoRange(Matches[0]), "");
+  EXPECT_EQ(GetNameInfoRange(Matches[1]), "");
+  EXPECT_EQ(GetNameInfoRange(Matches[2]), "");
+}

>From ca454ba5c74e7bfdce2a4bfbfa55b0ad7b0c814e Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Tue, 21 May 2024 09:23:40 +0200
Subject: [PATCH 2/2] NFC Add release docs for this fix

---
 clang/docs/ReleaseNotes.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2f83f5c6d54e9..7f4b1d2a00df7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -770,6 +770,7 @@ Miscellaneous Bug Fixes
 
 - Fixed an infinite recursion in ASTImporter, on return type declared inside
   body of C++11 lambda without trailing return (#GH68775).
+- Fixed declaration name source location of instantiated function definitions 
(GH71161).
 
 Miscellaneous Clang Crashes Fixed
 ^

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


[clang] [clang-format] Add space after a word token (PR #92741)

2024-05-21 Thread Owen Pan via cfe-commits

owenca wrote:

> Since I am by no means an expert on Clang, a few questions arose
> 
> * As Clang formats the code correctly (no code changes necessary) when 
> instead of `xor` a different function name e.g. `xooor` is used, I wonder why 
> `xor` is tokenized as Unary operator in the first place in C?
> * Is C and C++ using the same tokenizations?

clang-format formats all C code as C++. Since `xor` is a C++ keyword, it's 
lexed as `tok::caret`, which is then erroneously annotated as 
`TT_UnaryOperator`. This bug was uncovered by #90161.

> * How to properly distinguish between the C and C++ language in Clang Format?

clang-format can't do it properly. @mydeveloperday, @HazardyKnusperkeks, and 
@rymiel may know more about why we didn't add `LK_C` to the 
[`Language`](https://clang.llvm.org/docs/ClangFormatStyleOptions.html#language) 
option.

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


[clang] [llvm] [Clang] Fix definition of layout-compatible to ignore empty classes (PR #92103)

2024-05-21 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [llvm] [Clang] Fix definition of layout-compatible to ignore empty classes (PR #92103)

2024-05-21 Thread Vlad Serebrennikov via cfe-commits


@@ -561,6 +561,42 @@ void CXXRecordDecl::addedClassSubobject(CXXRecordDecl 
*Subobj) {
 data().StructuralIfLiteral = false;
 }
 
+const CXXRecordDecl *CXXRecordDecl::getStandardLayoutBaseWithFields() const {
+#ifndef NDEBUG
+  {
+assert(
+isStandardLayout() &&
+"getStandardLayoutBaseWithFields called on a non-standard-layout 
type");

Endilll wrote:

I think this assert should be on the default code path, not just for expensive 
checks.

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


[clang] [llvm] [Clang] Fix definition of layout-compatible to ignore empty classes (PR #92103)

2024-05-21 Thread Vlad Serebrennikov via cfe-commits


@@ -561,6 +561,42 @@ void CXXRecordDecl::addedClassSubobject(CXXRecordDecl 
*Subobj) {
 data().StructuralIfLiteral = false;
 }
 
+const CXXRecordDecl *CXXRecordDecl::getStandardLayoutBaseWithFields() const {
+#ifndef NDEBUG

Endilll wrote:

We have `EXPENSIVE_CHECKS` macro to guard expensive checks.

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


[clang] [llvm] [Clang] Fix definition of layout-compatible to ignore empty classes (PR #92103)

2024-05-21 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll commented:

Thank you for working on this!

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


[clang] [clang][AST] Fix end location of DeclarationNameInfo on instantiated methods (PR #92654)

2024-05-21 Thread Balazs Benics via cfe-commits

steakhal wrote:

> nit: add a note in `clang/docs/ReleaseNotes.rst`

Thanks. Added. Let me know if it's in the right section. @hokein

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


[clang] [llvm] [Clang] Fix definition of layout-compatible to ignore empty classes (PR #92103)

2024-05-21 Thread Vlad Serebrennikov via cfe-commits


@@ -561,6 +561,42 @@ void CXXRecordDecl::addedClassSubobject(CXXRecordDecl 
*Subobj) {
 data().StructuralIfLiteral = false;
 }
 
+const CXXRecordDecl *CXXRecordDecl::getStandardLayoutBaseWithFields() const {
+#ifndef NDEBUG
+  {
+assert(
+isStandardLayout() &&
+"getStandardLayoutBaseWithFields called on a non-standard-layout 
type");
+unsigned NumberOfBasesWithFields = 0;
+if (!field_empty())
+  ++NumberOfBasesWithFields;
+std::set UniqueBases;

Endilll wrote:

Have you considered `llvm::DenseSet`?

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


[clang] [clang-format] Add space after a word token (PR #92741)

2024-05-21 Thread Owen Pan via cfe-commits


@@ -5280,7 +5280,8 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine &Line,
 // handled.
 if (Left.is(tok::amp) && Right.is(tok::r_square))
   return Style.SpacesInSquareBrackets;
-return Style.SpaceAfterLogicalNot && Left.is(tok::exclaim);
+return (Style.SpaceAfterLogicalNot && Left.is(tok::exclaim)) ||
+   Right.is(TT_BinaryOperator);

owenca wrote:

This line was deleted in #90161. Adding it back will hide the uncovered bug and 
only fix #92688 superficially IMO. For example, 
`SpaceBeforeAssignmentOperators` will have no effect.

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


[clang] [clang-format] Add space after a word token (PR #92741)

2024-05-21 Thread via cfe-commits

mydeveloperday wrote:

Because if this code was in a .h and not a .c you wouldn't know what language 
you were in

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


[clang] [clang-format] Add space after a word token (PR #92741)

2024-05-21 Thread via cfe-commits

mydeveloperday wrote:

I thought we had some code like this around using a variable called "try"

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


[clang] [clang-format] Fix bad spacing of macro after lambda introducer (PR #92673)

2024-05-21 Thread via cfe-commits

https://github.com/mydeveloperday commented:

Can you add an annotator test

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


[clang] [clang-format] Fix a bug in formatting goto labels in macros (PR #92494)

2024-05-21 Thread via cfe-commits

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


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


[clang] [clang] Introduce `SemaAccess` (PR #92674)

2024-05-21 Thread via cfe-commits

cor3ntin wrote:

(I have the same reservation as for the SemaCoroutine patch)

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


[clang] [clang-tools-extra] [clang][CodeComplete] Omit ExplicitObject when completing code (PR #92743)

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

kadircet wrote:

instead of testing this in clangd, can you add tests to 
`clang/test/CodeCompletion/`? (even better if you can extend 
`clang/unittests/Sema/CodeCompleteTest.cpp`). as this is a clang feature, and 
it'd be nice to make sure it doesn't regress at clang-level.

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


[clang] [clang][analyzer] Move checker alpha.security.cert.pos.34c into security.PutenvWithAuto (PR #92424)

2024-05-21 Thread Balázs Kéri via cfe-commits

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

From 769523d392204eac6c48cb80a2282212f3edbbe4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Fri, 10 May 2024 17:30:23 +0200
Subject: [PATCH 1/3] [clang][analyzer] Move checker
 alpha.security.cert.pos.34c into security.PutenvWithAuto .

The "cert" package looks not useful and the checker has not a meaningful name
with the old naming scheme.
Additionally tests and documentation is updated.
The checker looks good enough to be moved into non-alpha package.
---
 clang/docs/analyzer/checkers.rst  | 97 +--
 .../clang/StaticAnalyzer/Checkers/Checkers.td | 10 +-
 .../Analysis/cert/pos34-c-fp-suppression.cpp  | 51 --
 clang/test/Analysis/cert/pos34-c.cpp  | 61 
 clang/test/Analysis/putenv-with-auto.c| 66 +
 5 files changed, 119 insertions(+), 166 deletions(-)
 delete mode 100644 clang/test/Analysis/cert/pos34-c-fp-suppression.cpp
 delete mode 100644 clang/test/Analysis/cert/pos34-c.cpp
 create mode 100644 clang/test/Analysis/putenv-with-auto.c

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index eb8b58323da4d..6ea768d003378 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -1179,6 +1179,54 @@ security.insecureAPI.DeprecatedOrUnsafeBufferHandling (C)
strncpy(buf, "a", 1); // warn
  }
 
+.. _security-putenv-with-auto:
+
+security.PutenvWithAuto
+"""
+Finds calls to the ``putenv`` function which pass a pointer to an automatic 
variable as the argument.
+Function ``putenv`` does not copy the passed string, only a pointer to the 
data is stored.
+Content of an automatic variable is likely to be overwritten after returning 
from the parent function.
+
+The problem can be solved by using a static variable or dynamically allocated
+memory. Even better is to avoid using ``putenv`` (it has other problems
+related to memory leaks) and use ``setenv`` instead.
+
+The check corresponds to CERT rule
+`POS34-C. Do not call putenv() with a pointer to an automatic variable as the 
argument
+`_.
+
+.. code-block:: c
+
+  int f() {
+char[] env = "NAME=value";
+return putenv(env); // putenv function should not be called with auto 
variables
+  }
+
+Limitations:
+
+   - In specific cases one can pass automatic variables to ``putenv``,
+ but one needs to ensure that the given environment key stays
+ alive until it's removed or overwritten.
+ Since the analyzer cannot keep track if and when the string passed to 
``putenv``
+ gets deallocated or overwritten, it needs to be slightly more aggressive
+ and warn for each case, leading in some cases to false-positive reports 
like this:
+
+ .. code-block:: c
+
+void baz() {
+  char env[] = "NAME=value";
+  putenv(env); // false-positive warning: putenv function should not 
be called...
+  // More code...
+  // FIXME: It looks like that if one string was passed to putenv,
+  // it should not be deallocated at all, because when reading the
+  // environment variable a pointer into this string is returned.
+  // In this case, if another (or the same) thread reads variable 
"NAME"
+  // at this point and does not copy the returned string, the data may
+  // become invalid.
+  putenv((char *)"NAME=anothervalue");
+  // This putenv call overwrites the previous entry, thus that can no 
longer dangle.
+} // 'env' array becomes dead only here.
+
 .. _unix-checkers:
 
 unix
@@ -2818,55 +2866,6 @@ alpha.security.cert
 
 SEI CERT checkers which tries to find errors based on their `C coding rules 
`_.
 
-.. _alpha-security-cert-pos-checkers:
-
-alpha.security.cert.pos
-^^^
-
-SEI CERT checkers of `POSIX C coding rules 
`_.
-
-.. _alpha-security-cert-pos-34c:
-
-alpha.security.cert.pos.34c
-"""
-Finds calls to the ``putenv`` function which pass a pointer to an automatic 
variable as the argument.
-
-.. code-block:: c
-
-  int func(const char *var) {
-char env[1024];
-int retval = snprintf(env, sizeof(env),"TEST=%s", var);
-if (retval < 0 || (size_t)retval >= sizeof(env)) {
-/* Handle error */
-}
-
-return putenv(env); // putenv function should not be called with auto 
variables
-  }
-
-Limitations:
-
-   - Technically, one can pass automatic variables to ``putenv``,
- but one needs to ensure that the given environment key stays
- alive until it's removed or overwritten.
- Since the analyzer cannot keep track of which envvars get overwritten
- a

[clang] [ClangFormat] Add DiagHandler for getStyle function (PR #91317)

2024-05-21 Thread via cfe-commits

https://github.com/pointhex updated 
https://github.com/llvm/llvm-project/pull/91317

>From 3a0808ddeb77a1ae8c6a07994343c09462e007fa Mon Sep 17 00:00:00 2001
From: Artem Sokolovskii 
Date: Tue, 7 May 2024 12:27:29 +0200
Subject: [PATCH] [ClangFormat] Add DiagHandler for getStyle function

It allows to control of error output for the function.
---
 clang/include/clang/Format/Format.h | 10 +-
 clang/lib/Format/Format.cpp | 28 +---
 2 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 74893f23210cd..c730fbd84ce8a 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5381,11 +5381,11 @@ extern const char *DefaultFallbackStyle;
 /// \returns FormatStyle as specified by ``StyleName``. If ``StyleName`` is
 /// "file" and no file is found, returns ``FallbackStyle``. If no style could 
be
 /// determined, returns an Error.
-llvm::Expected getStyle(StringRef StyleName, StringRef FileName,
- StringRef FallbackStyle,
- StringRef Code = "",
- llvm::vfs::FileSystem *FS = nullptr,
- bool AllowUnknownOptions = false);
+llvm::Expected
+getStyle(StringRef StyleName, StringRef FileName, StringRef FallbackStyle,
+ StringRef Code = "", llvm::vfs::FileSystem *FS = nullptr,
+ bool AllowUnknownOptions = false,
+ llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr);
 
 // Guesses the language from the ``FileName`` and ``Code`` to be formatted.
 // Defaults to FormatStyle::LK_Cpp.
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 52005a6c881f3..9fb6101c1476d 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3946,20 +3946,23 @@ const char *DefaultFallbackStyle = "LLVM";
 
 llvm::ErrorOr>
 loadAndParseConfigFile(StringRef ConfigFile, llvm::vfs::FileSystem *FS,
-   FormatStyle *Style, bool AllowUnknownOptions) {
+   FormatStyle *Style, bool AllowUnknownOptions,
+   llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr) {
   llvm::ErrorOr> Text =
   FS->getBufferForFile(ConfigFile.str());
   if (auto EC = Text.getError())
 return EC;
-  if (auto EC = parseConfiguration(*Text.get(), Style, AllowUnknownOptions))
+  if (auto EC = parseConfiguration(*Text.get(), Style, AllowUnknownOptions,
+   DiagHandler)) {
 return EC;
+  }
   return Text;
 }
 
-llvm::Expected getStyle(StringRef StyleName, StringRef FileName,
- StringRef FallbackStyleName,
- StringRef Code, llvm::vfs::FileSystem *FS,
- bool AllowUnknownOptions) {
+llvm::Expected
+getStyle(StringRef StyleName, StringRef FileName, StringRef FallbackStyleName,
+ StringRef Code, llvm::vfs::FileSystem *FS, bool AllowUnknownOptions,
+ llvm::SourceMgr::DiagHandlerTy DiagHandler) {
   FormatStyle Style = getLLVMStyle(guessLanguage(FileName, Code));
   FormatStyle FallbackStyle = getNoStyle();
   if (!getPredefinedStyle(FallbackStyleName, Style.Language, &FallbackStyle))
@@ -3973,7 +3976,7 @@ llvm::Expected getStyle(StringRef StyleName, 
StringRef FileName,
 StringRef Source = "";
 if (std::error_code ec =
 parseConfiguration(llvm::MemoryBufferRef(StyleName, Source), 
&Style,
-   AllowUnknownOptions)) {
+   AllowUnknownOptions, DiagHandler)) {
   return make_string_error("Error parsing -style: " + ec.message());
 }
 
@@ -3993,7 +3996,8 @@ llvm::Expected getStyle(StringRef StyleName, 
StringRef FileName,
   StyleName.starts_with_insensitive("file:")) {
 auto ConfigFile = StyleName.substr(5);
 llvm::ErrorOr> Text =
-loadAndParseConfigFile(ConfigFile, FS, &Style, AllowUnknownOptions);
+loadAndParseConfigFile(ConfigFile, FS, &Style, AllowUnknownOptions,
+   DiagHandler);
 if (auto EC = Text.getError()) {
   return make_string_error("Error reading " + ConfigFile + ": " +
EC.message());
@@ -4028,12 +4032,13 @@ llvm::Expected getStyle(StringRef 
StyleName, StringRef FileName,
   // Reset possible inheritance
   Style.InheritsParentConfig = false;
 
-  auto dropDiagnosticHandler = [](const llvm::SMDiagnostic &, void *) {};
+  auto diagHandlerOrDropHandling =
+  DiagHandler ? DiagHandler : [](llvm::SMDiagnostic const &, void *) {};
 
   auto applyChildFormatTexts = [&](FormatStyle *Style) {
 for (const auto &MemBuf : llvm::reverse(ChildFormatTextToApply)) {
   auto EC = parseConfiguration(*MemBuf, Style, AllowUnknownOptions,
-   dropDiagnosticHandler);
+ 

[clang] d89f200 - [clang-format] Fix a bug in formatting goto labels in macros (#92494)

2024-05-21 Thread via cfe-commits

Author: Owen Pan
Date: 2024-05-21T01:35:31-07:00
New Revision: d89f20058b45e3836527e816af7ed7372e1d554d

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

LOG: [clang-format] Fix a bug in formatting goto labels in macros (#92494)

Fixes #92300.

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index b15a87327240b..3dd10f6bd2b31 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1189,12 +1189,6 @@ void UnwrappedLineParser::parsePPDefine() {
 return;
   }
 
-  if (FormatTok->is(tok::identifier) &&
-  Tokens->peekNextToken()->is(tok::colon)) {
-nextToken();
-nextToken();
-  }
-
   // Errors during a preprocessor directive can only affect the layout of the
   // preprocessor directive, and thus we ignore them. An alternative approach
   // would be to use the same approach we use on the file level (no
@@ -1681,7 +1675,8 @@ void UnwrappedLineParser::parseStructuralElement(
 if (!Style.isJavaScript() && !Style.isVerilog() && !Style.isTableGen() &&
 Tokens->peekNextToken()->is(tok::colon) && !Line->MustBeDeclaration) {
   nextToken();
-  Line->Tokens.begin()->Tok->MustBreakBefore = true;
+  if (!Line->InMacroBody || CurrentLines->size() > 1)
+Line->Tokens.begin()->Tok->MustBreakBefore = true;
   FormatTok->setFinalizedType(TT_GotoLabelColon);
   parseLabel(!Style.IndentGotoLabels);
   if (HasLabel)

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 6f57f10e12e88..2f0c0f0266774 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -3124,6 +3124,7 @@ TEST_F(FormatTest, FormatsLabels) {
"g();\n"
"  }\n"
"}");
+
   FormatStyle Style = getLLVMStyle();
   Style.IndentGotoLabels = false;
   verifyFormat("void f() {\n"
@@ -3163,6 +3164,13 @@ TEST_F(FormatTest, FormatsLabels) {
"  }\n"
"}",
Style);
+
+  Style.ColumnLimit = 15;
+  verifyFormat("#define FOO   \\\n"
+   "label:\\\n"
+   "  break;",
+   Style);
+
   // The opening brace may either be on the same unwrapped line as the colon or
   // on a separate one. The formatter should recognize both.
   Style = getLLVMStyle();

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 7528675753047..45c1554308c9b 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -2579,15 +2579,28 @@ TEST_F(TokenAnnotatorTest, UnderstandsLabels) {
   auto Tokens = annotate("{ x: break; }");
   ASSERT_EQ(Tokens.size(), 7u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::colon, TT_GotoLabelColon);
+
   Tokens = annotate("{ case x: break; }");
   ASSERT_EQ(Tokens.size(), 8u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::colon, TT_CaseLabelColon);
+
   Tokens = annotate("{ x: { break; } }");
   ASSERT_EQ(Tokens.size(), 9u) << Tokens;
   EXPECT_TOKEN(Tokens[2], tok::colon, TT_GotoLabelColon);
+
   Tokens = annotate("{ case x: { break; } }");
   ASSERT_EQ(Tokens.size(), 10u) << Tokens;
   EXPECT_TOKEN(Tokens[3], tok::colon, TT_CaseLabelColon);
+
+  Tokens = annotate("#define FOO label:");
+  ASSERT_EQ(Tokens.size(), 6u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::colon, TT_GotoLabelColon);
+
+  Tokens = annotate("#define FOO \\\n"
+"label: \\\n"
+"  break;");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::colon, TT_GotoLabelColon);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsNestedBlocks) {



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


[clang] [clang-format] Fix a bug in formatting goto labels in macros (PR #92494)

2024-05-21 Thread Owen Pan via cfe-commits

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


[clang] [clang] Introduce `SemaRISCV` (PR #92682)

2024-05-21 Thread Vlad Serebrennikov via cfe-commits


@@ -0,0 +1,52 @@
+//===- SemaRISCV.h --- RISC-V target-specific routines 
===//

Endilll wrote:

Fixed

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


[clang] [clang-format] Correctly annotate C++ alternative operators in C (PR #92880)

2024-05-21 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/92880

PR #90161 uncovered a bug that annotates C++ xor as UnaryOperator if followed 
by a binary operator. This patch fixes that and all other C++ alternative 
operator keywords when followed by a binary operator in C.

Fixes #92688.

>From 6d5fc044d8b221ea0643e1df0d511e693b500f07 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Tue, 21 May 2024 01:11:20 -0700
Subject: [PATCH] [clang-format] Correctly annotate C++ alternative operators
 in C

PR #90161 uncovered a bug that annotates C++ xor as UnaryOperator if
followed by a binary operator. This patch fixes that and all other C++
alternative operator keywords when followed by a binary operator in C.

Fixes #92688.
---
 clang/lib/Format/UnwrappedLineParser.cpp  | 21 ++--
 clang/unittests/Format/FormatTest.cpp |  2 +
 clang/unittests/Format/TokenAnnotatorTest.cpp | 54 +++
 3 files changed, 73 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 3dd10f6bd2b31..b6f7567adc140 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1410,6 +1410,13 @@ void UnwrappedLineParser::readTokenWithJavaScriptASI() {
   }
 }
 
+static bool isAltOperator(const FormatToken &Tok) {
+  return isalpha(Tok.TokenText[0]) &&
+ Tok.isOneOf(tok::ampamp, tok::ampequal, tok::amp, tok::pipe,
+ tok::tilde, tok::exclaim, tok::exclaimequal, 
tok::pipepipe,
+ tok::pipeequal, tok::caret, tok::caretequal);
+}
+
 void UnwrappedLineParser::parseStructuralElement(
 const FormatToken *OpeningBrace, IfStmtKind *IfKind,
 FormatToken **IfLeftBrace, bool *HasDoWhile, bool *HasLabel) {
@@ -1689,9 +1696,15 @@ void UnwrappedLineParser::parseStructuralElement(
 break;
   }
 
-  const bool InRequiresExpression =
-  OpeningBrace && OpeningBrace->is(TT_RequiresExpressionLBrace);
-  do {
+  for (const bool InRequiresExpression =
+   OpeningBrace && OpeningBrace->is(TT_RequiresExpressionLBrace);
+   !eof();) {
+if (IsCpp && isAltOperator(*FormatTok)) {
+  if (auto *Next = Tokens->peekNextToken(/*SkipComment=*/true);
+  Next && Next->isBinaryOperator()) {
+FormatTok->Tok.setKind(tok::identifier);
+  }
+}
 const FormatToken *Previous = FormatTok->Previous;
 switch (FormatTok->Tok.getKind()) {
 case tok::at:
@@ -2122,7 +2135,7 @@ void UnwrappedLineParser::parseStructuralElement(
   nextToken();
   break;
 }
-  } while (!eof());
+  }
 }
 
 bool UnwrappedLineParser::tryToParsePropertyAccessor() {
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 2f0c0f0266774..a9df994189f00 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -17340,12 +17340,14 @@ TEST_F(FormatTest, 
ConfigurableSpaceBeforeAssignmentOperators) {
   verifyFormat("int a = 5;");
   verifyFormat("a += 42;");
   verifyFormat("a or_eq 8;");
+  verifyFormat("xor = foo;");
 
   FormatStyle Spaces = getLLVMStyle();
   Spaces.SpaceBeforeAssignmentOperators = false;
   verifyFormat("int a= 5;", Spaces);
   verifyFormat("a+= 42;", Spaces);
   verifyFormat("a or_eq 8;", Spaces);
+  verifyFormat("xor= foo;", Spaces);
 }
 
 TEST_F(FormatTest, ConfigurableSpaceBeforeColon) {
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 45c1554308c9b..6ea9c4a241dc5 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -3015,6 +3015,60 @@ TEST_F(TokenAnnotatorTest, SwitchExpression) {
   EXPECT_TOKEN(Tokens[20], tok::arrow, TT_CaseLabelArrow);
 }
 
+TEST_F(TokenAnnotatorTest, CppAltOperatorKeywords) {
+  auto Tokens = annotate("a = b and c;");
+  ASSERT_EQ(Tokens.size(), 7u);
+  EXPECT_TOKEN(Tokens[3], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("a = b and_eq c;");
+  ASSERT_EQ(Tokens.size(), 7u);
+  EXPECT_TOKEN(Tokens[3], tok::ampequal, TT_BinaryOperator);
+
+  Tokens = annotate("a = b bitand c;");
+  ASSERT_EQ(Tokens.size(), 7u);
+  EXPECT_TOKEN(Tokens[3], tok::amp, TT_BinaryOperator);
+
+  Tokens = annotate("a = b bitor c;");
+  ASSERT_EQ(Tokens.size(), 7u);
+  EXPECT_TOKEN(Tokens[3], tok::pipe, TT_BinaryOperator);
+
+  Tokens = annotate("a = b compl c;");
+  ASSERT_EQ(Tokens.size(), 7u);
+  EXPECT_TOKEN(Tokens[3], tok::tilde, TT_UnaryOperator);
+
+  Tokens = annotate("a = b not c;");
+  ASSERT_EQ(Tokens.size(), 7u);
+  EXPECT_TOKEN(Tokens[3], tok::exclaim, TT_UnaryOperator);
+
+  Tokens = annotate("a = b not_eq c;");
+  ASSERT_EQ(Tokens.size(), 7u);
+  EXPECT_TOKEN(Tokens[3], tok::exclaimequal, TT_BinaryOperator);
+
+  Tokens = annotate("a = b or c;");
+  ASSERT_EQ(Tokens.size(), 7u);
+  EXPECT_TOKEN(Tokens[3], tok::pipepipe, TT_BinaryOperator);
+
+  Tokens = annotate("a = b or_eq

[clang] [clang-format] Correctly annotate C++ alternative operators in C (PR #92880)

2024-05-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

PR #90161 uncovered a bug that annotates C++ xor as UnaryOperator if 
followed by a binary operator. This patch fixes that and all other C++ 
alternative operator keywords when followed by a binary operator in C.

Fixes #92688.

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


3 Files Affected:

- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+17-4) 
- (modified) clang/unittests/Format/FormatTest.cpp (+2) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+54) 


``diff
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 3dd10f6bd2b31..b6f7567adc140 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -1410,6 +1410,13 @@ void UnwrappedLineParser::readTokenWithJavaScriptASI() {
   }
 }
 
+static bool isAltOperator(const FormatToken &Tok) {
+  return isalpha(Tok.TokenText[0]) &&
+ Tok.isOneOf(tok::ampamp, tok::ampequal, tok::amp, tok::pipe,
+ tok::tilde, tok::exclaim, tok::exclaimequal, 
tok::pipepipe,
+ tok::pipeequal, tok::caret, tok::caretequal);
+}
+
 void UnwrappedLineParser::parseStructuralElement(
 const FormatToken *OpeningBrace, IfStmtKind *IfKind,
 FormatToken **IfLeftBrace, bool *HasDoWhile, bool *HasLabel) {
@@ -1689,9 +1696,15 @@ void UnwrappedLineParser::parseStructuralElement(
 break;
   }
 
-  const bool InRequiresExpression =
-  OpeningBrace && OpeningBrace->is(TT_RequiresExpressionLBrace);
-  do {
+  for (const bool InRequiresExpression =
+   OpeningBrace && OpeningBrace->is(TT_RequiresExpressionLBrace);
+   !eof();) {
+if (IsCpp && isAltOperator(*FormatTok)) {
+  if (auto *Next = Tokens->peekNextToken(/*SkipComment=*/true);
+  Next && Next->isBinaryOperator()) {
+FormatTok->Tok.setKind(tok::identifier);
+  }
+}
 const FormatToken *Previous = FormatTok->Previous;
 switch (FormatTok->Tok.getKind()) {
 case tok::at:
@@ -2122,7 +2135,7 @@ void UnwrappedLineParser::parseStructuralElement(
   nextToken();
   break;
 }
-  } while (!eof());
+  }
 }
 
 bool UnwrappedLineParser::tryToParsePropertyAccessor() {
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 2f0c0f0266774..a9df994189f00 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -17340,12 +17340,14 @@ TEST_F(FormatTest, 
ConfigurableSpaceBeforeAssignmentOperators) {
   verifyFormat("int a = 5;");
   verifyFormat("a += 42;");
   verifyFormat("a or_eq 8;");
+  verifyFormat("xor = foo;");
 
   FormatStyle Spaces = getLLVMStyle();
   Spaces.SpaceBeforeAssignmentOperators = false;
   verifyFormat("int a= 5;", Spaces);
   verifyFormat("a+= 42;", Spaces);
   verifyFormat("a or_eq 8;", Spaces);
+  verifyFormat("xor= foo;", Spaces);
 }
 
 TEST_F(FormatTest, ConfigurableSpaceBeforeColon) {
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 45c1554308c9b..6ea9c4a241dc5 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -3015,6 +3015,60 @@ TEST_F(TokenAnnotatorTest, SwitchExpression) {
   EXPECT_TOKEN(Tokens[20], tok::arrow, TT_CaseLabelArrow);
 }
 
+TEST_F(TokenAnnotatorTest, CppAltOperatorKeywords) {
+  auto Tokens = annotate("a = b and c;");
+  ASSERT_EQ(Tokens.size(), 7u);
+  EXPECT_TOKEN(Tokens[3], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("a = b and_eq c;");
+  ASSERT_EQ(Tokens.size(), 7u);
+  EXPECT_TOKEN(Tokens[3], tok::ampequal, TT_BinaryOperator);
+
+  Tokens = annotate("a = b bitand c;");
+  ASSERT_EQ(Tokens.size(), 7u);
+  EXPECT_TOKEN(Tokens[3], tok::amp, TT_BinaryOperator);
+
+  Tokens = annotate("a = b bitor c;");
+  ASSERT_EQ(Tokens.size(), 7u);
+  EXPECT_TOKEN(Tokens[3], tok::pipe, TT_BinaryOperator);
+
+  Tokens = annotate("a = b compl c;");
+  ASSERT_EQ(Tokens.size(), 7u);
+  EXPECT_TOKEN(Tokens[3], tok::tilde, TT_UnaryOperator);
+
+  Tokens = annotate("a = b not c;");
+  ASSERT_EQ(Tokens.size(), 7u);
+  EXPECT_TOKEN(Tokens[3], tok::exclaim, TT_UnaryOperator);
+
+  Tokens = annotate("a = b not_eq c;");
+  ASSERT_EQ(Tokens.size(), 7u);
+  EXPECT_TOKEN(Tokens[3], tok::exclaimequal, TT_BinaryOperator);
+
+  Tokens = annotate("a = b or c;");
+  ASSERT_EQ(Tokens.size(), 7u);
+  EXPECT_TOKEN(Tokens[3], tok::pipepipe, TT_BinaryOperator);
+
+  Tokens = annotate("a = b or_eq c;");
+  ASSERT_EQ(Tokens.size(), 7u);
+  EXPECT_TOKEN(Tokens[3], tok::pipeequal, TT_BinaryOperator);
+
+  Tokens = annotate("a = b xor c;");
+  ASSERT_EQ(Tokens.size(), 7u);
+  EXPECT_TOKEN(Tokens[3], tok::caret, TT_BinaryOperator);
+
+  Tokens = annotate("a = b xor_eq c;");
+  ASSERT_EQ(Tokens.size(), 7u);
+  EXPECT_TOKEN(Tokens[3], tok::caretequal, TT_BinaryOperator);
+
+  

[clang] [clang-format] Correctly annotate C++ alternative operators in C (PR #92880)

2024-05-21 Thread Emilia Kond via cfe-commits

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


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


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

2024-05-21 Thread Tomas Matheson via cfe-commits

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


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

2024-05-21 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 ee76f1e1b7ee4585b8d5ead27c317abbc2cdf4b7 
a41cd9fa5a63fd5dd22735560ca4fae12d178fe6 -- clang/lib/Basic/Targets/AArch64.cpp 
clang/lib/CodeGen/CGBuiltin.cpp clang/lib/CodeGen/Targets/AArch64.cpp 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_fmlas16.c 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mopa_nonwide.c 
clang/test/CodeGen/aarch64-sve2-intrinsics/acle_sve2_revd.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_bfclamp.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_bfmla_lane.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_bfmls_lane.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_bfmlsl.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_bfmul_lane.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_cntp.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_create2_bool.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_create4_bool.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_dot.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_dupq.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_extq.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_fclamp.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_fp_reduce.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_get2_bool.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_get4_bool.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_int_reduce.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_ld1.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_ld1_single.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_ldnt1.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_loads.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pext.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pfalse.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pmov_to_pred.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_pmov_to_vector.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_psel.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_psel_svcount.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_ptrue.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_qcvtn.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_qrshr.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_sclamp.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_set2_bool.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_set4_bool.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_st1.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_st1_single.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_stnt1.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_store.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_tblq.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_tbxq.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_uclamp.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_undef_bool.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_uzpq1.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_uzpq2.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_while_pn.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_while_x2.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_zipq1.c 
clang/test/CodeGen/aarch64-sve2p1-intrinsics/acle_sve2p1_zipq2.c 
clang/test/Sema/aarch64-sme2p1-diagnostics.c 
clang/test/Sema/aarch64-sve2p1-intrinsics/acle_sve2p1_imm.cpp 
llvm/include/llvm/TargetParser/AArch64TargetParser.h 
llvm/lib/TargetParser/AArch64TargetParser.cpp 
llvm/utils/TableGen/ARMTargetDefEmitter.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index 7875f7e166..eef5cf24e5 100644
--- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -125,18 +125,17 @@ struct ExtensionInfo {
 #define EMIT_EXTENSIONS
 #include "llvm/TargetParser/AArch64TargetParserDef.inc"
 
-
 struct FMVInfo {
-  StringRef Name; // The target_version/target_clones spelling.
-  CPUFeatures Bit;// Index of the bit in the FMV feature 
bitset.
-  StringRef Features; // List of SubtargetFeatures to enable.
-  unsigned Priority;  // FMV priority.
+  StringRef Name; // The target_version/target_clones spelling.
+  CPUFeatures Bit;// Index of the bit in the FMV feature bitset.
+  StringRef Features; // List of SubtargetFeatures to enable.
+  unsigned Priority;  // F

[clang] [llvm] [polly] [X86] Remove knl/knm specific ISAs supports (PR #92883)

2024-05-21 Thread Freddy Ye via cfe-commits

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


[clang-tools-extra] [clangd] [C++20] [Modules] Introduce initial support for C++20 Modules (PR #66462)

2024-05-21 Thread via cfe-commits

h-vetinari wrote:

The branch-point for LLVM 19 is about 2 months away ([July 
23rd](https://discourse.llvm.org/t/18-1-6-released/79068)), in case this 
context helps to plan/prioritize reviews here.

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


[clang] [llvm] [polly] [X86] Remove knl/knm specific ISAs supports (PR #92883)

2024-05-21 Thread Freddy Ye via cfe-commits

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


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

2024-05-21 Thread Tomas Matheson via cfe-commits


@@ -0,0 +1,84 @@
+// Function MultiVersioning (FMV) properties
+
+// Something you can add to target_version or target_clones
+class FMVExtension {
+// Name, as spelled in target_version or target_clones. e.g. "memtag"
+string Name = n;
+
+// A C++ expression giving the number of the bit in the FMV ABI.
+// Currently this is given as a value from the enum "CPUFeatures".
+// If this is not set, it indicates that this is not an FMV extension.

tmatheson-arm wrote:

remove

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


[clang] [llvm] [polly] [X86] Remove knl/knm specific ISAs supports (PR #92883)

2024-05-21 Thread Freddy Ye via cfe-commits

FreddyLeaf wrote:

gcc recently formally removed knl/knm supports at trunk: 
https://godbolt.org/z/nKvo1P48d
Per conclusion before in https://github.com/llvm/llvm-project/pull/75580, this 
patch removed specific ISA supports of knl/knm while keep -march/tune support

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


[clang] [llvm] [polly] [X86] Remove knl/knm specific ISAs supports (PR #92883)

2024-05-21 Thread Freddy Ye via cfe-commits

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


[clang] [llvm] [polly] [X86] Remove knl/knm specific ISAs supports (PR #92883)

2024-05-21 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Freddy Ye (FreddyLeaf)


Changes

Cont. patch after https://github.com/llvm/llvm-project/pull/75580


---

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


47 Files Affected:

- (modified) clang/include/clang/Basic/BuiltinsX86.def (-21) 
- (modified) clang/include/clang/Driver/Options.td (-6) 
- (modified) clang/lib/Basic/Targets/X86.cpp (-21) 
- (modified) clang/lib/Basic/Targets/X86.h (-3) 
- (modified) clang/lib/Headers/CMakeLists.txt (-2) 
- (removed) clang/lib/Headers/avx512erintrin.h (-271) 
- (removed) clang/lib/Headers/avx512pfintrin.h (-92) 
- (modified) clang/lib/Headers/immintrin.h (-8) 
- (modified) clang/lib/Sema/SemaChecking.cpp (-30) 
- (removed) clang/test/CodeGen/X86/avx512er-builtins.c (-347) 
- (removed) clang/test/CodeGen/X86/avx512pf-builtins.c (-100) 
- (modified) clang/test/CodeGen/attr-cpuspecific.c (+5-5) 
- (modified) clang/test/CodeGen/attr-target-x86.c (+2-2) 
- (modified) clang/test/CodeGen/function-target-features.c (+2-2) 
- (modified) clang/test/CodeGen/target-builtin-noerror.c (-2) 
- (modified) clang/test/Driver/cl-x86-flags.c (+2-8) 
- (modified) clang/test/Driver/x86-target-features.c (+4-9) 
- (modified) clang/test/Frontend/x86-target-cpu.c (+2-8) 
- (modified) clang/test/Preprocessor/predefined-arch-macros.c (-12) 
- (modified) clang/test/Preprocessor/x86_target_features.c (-50) 
- (modified) clang/test/Sema/builtins-x86.c (-8) 
- (modified) llvm/include/llvm/IR/IntrinsicsX86.td (-84) 
- (modified) llvm/include/llvm/TargetParser/X86TargetParser.def (+3-6) 
- (modified) llvm/lib/Target/X86/X86.td (-12) 
- (modified) llvm/lib/Target/X86/X86Instr3DNow.td (+1-2) 
- (modified) llvm/lib/Target/X86/X86InstrAVX512.td (+65-16) 
- (modified) llvm/lib/Target/X86/X86InstrFragments.td (+1-7) 
- (modified) llvm/lib/Target/X86/X86InstrPredicates.td (-3) 
- (modified) llvm/lib/Target/X86/X86IntrinsicsInfo.h (-27) 
- (modified) llvm/lib/Target/X86/X86Subtarget.h (+3-5) 
- (modified) llvm/lib/TargetParser/Host.cpp (-9) 
- (modified) llvm/lib/TargetParser/X86TargetParser.cpp (+3-3) 
- (modified) llvm/test/CodeGen/X86/avx512-cmp-kor-sequence.ll (+1-1) 
- (modified) llvm/test/CodeGen/X86/avx512-gather-scatter-intrin-deprecated.ll 
(-24) 
- (modified) llvm/test/CodeGen/X86/avx512-gather-scatter-intrin.ll (-24) 
- (removed) llvm/test/CodeGen/X86/avx512er-intrinsics.ll (-306) 
- (modified) llvm/test/CodeGen/X86/crc32-target-feature.ll (+2-2) 
- (modified) llvm/test/CodeGen/X86/insert-prefetch-invalid-instr.ll (-5) 
- (modified) llvm/test/CodeGen/X86/prefetch.ll (-17) 
- (modified) llvm/test/CodeGen/X86/speculative-load-hardening-gather.ll (-22) 
- (modified) llvm/test/CodeGen/X86/unfoldMemoryOperand.mir (+1-1) 
- (modified) llvm/test/Transforms/LoopStrengthReduce/X86/pr40514.ll (+1-1) 
- (modified) llvm/test/Transforms/LoopVectorize/X86/pr23997.ll (+1-1) 
- (modified) llvm/test/Transforms/LoopVectorize/X86/pr54634.ll (+1-1) 
- (modified) llvm/test/Transforms/LoopVectorize/X86/scatter_crash.ll (+1-1) 
- (modified) llvm/test/Transforms/SLPVectorizer/X86/vector_gep.ll (+1-1) 
- (removed) llvm/test/tools/llvm-mca/X86/Generic/resources-avx512er.s (-373) 


``diff
diff --git a/clang/include/clang/Basic/BuiltinsX86.def 
b/clang/include/clang/Basic/BuiltinsX86.def
index eafcc219c1096..7074479786b97 100644
--- a/clang/include/clang/Basic/BuiltinsX86.def
+++ b/clang/include/clang/Basic/BuiltinsX86.def
@@ -832,23 +832,11 @@ TARGET_BUILTIN(__builtin_ia32_rsqrt14ss_mask, 
"V4fV4fV4fV4fUc", "ncV:128:", "avx
 TARGET_BUILTIN(__builtin_ia32_rsqrt14pd512_mask, "V8dV8dV8dUc", "ncV:512:", 
"avx512f,evex512")
 TARGET_BUILTIN(__builtin_ia32_rsqrt14ps512_mask, "V16fV16fV16fUs", "ncV:512:", 
"avx512f,evex512")
 
-TARGET_BUILTIN(__builtin_ia32_rsqrt28sd_round_mask, "V2dV2dV2dV2dUcIi", 
"ncV:128:", "avx512er")
-TARGET_BUILTIN(__builtin_ia32_rsqrt28ss_round_mask, "V4fV4fV4fV4fUcIi", 
"ncV:128:", "avx512er")
-TARGET_BUILTIN(__builtin_ia32_rsqrt28pd_mask, "V8dV8dV8dUcIi", "ncV:512:", 
"avx512er,evex512")
-TARGET_BUILTIN(__builtin_ia32_rsqrt28ps_mask, "V16fV16fV16fUsIi", "ncV:512:", 
"avx512er,evex512")
-
 TARGET_BUILTIN(__builtin_ia32_rcp14sd_mask, "V2dV2dV2dV2dUc", "ncV:128:", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_rcp14ss_mask, "V4fV4fV4fV4fUc", "ncV:128:", 
"avx512f")
 TARGET_BUILTIN(__builtin_ia32_rcp14pd512_mask, "V8dV8dV8dUc", "ncV:512:", 
"avx512f,evex512")
 TARGET_BUILTIN(__builtin_ia32_rcp14ps512_mask, "V16fV16fV16fUs", "ncV:512:", 
"avx512f,evex512")
 
-TARGET_BUILTIN(__builtin_ia32_rcp28sd_round_mask, "V2dV2dV2dV2dUcIi", 
"ncV:128:", "avx512er")
-TARGET_BUILTIN(__builtin_ia32_rcp28ss_round_mask, "V4fV4fV4fV4fUcIi", 
"ncV:128:", "avx512er")
-TARGET_BUILTIN(__builtin_ia32_rcp28pd_mask, "V8dV8dV8dUcIi", "ncV:512:", 
"avx512er,evex512")
-TARGET_BUILTIN(__builtin_ia32_rcp28ps_mask, "V16fV16fV16fUsIi", "ncV:512:", 
"avx512er,evex512")
-TARGET_BU

[clang] [clang][analyzer] Move checker alpha.security.cert.pos.34c into security.PutenvWithAuto (PR #92424)

2024-05-21 Thread Balazs Benics via cfe-commits
=?utf-8?q?Balázs_Kéri?= ,
=?utf-8?q?Balázs_Kéri?= 
Message-ID:
In-Reply-To: 


steakhal wrote:

Make sure you adjust/sync the commit title, content and the PR title before 
merging.

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


[clang] [llvm] [IR] Avoid creating icmp/fcmp constant expressions (PR #92885)

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

https://github.com/nikic created https://github.com/llvm/llvm-project/pull/92885

Do not create icmp/fcmp constant expressions in IRBuilder etc anymore, i.e. 
treat them as "undesirable". This is in preparation for removing them entirely.

Part of: https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179

>From 27f6437864f34aec80ac9fe43d45da6bebcb4765 Mon Sep 17 00:00:00 2001
From: Nikita Popov 
Date: Tue, 21 May 2024 09:40:26 +0200
Subject: [PATCH] [IR] Avoid creating icmp/fcmp constant expressions

Do not create icmp/fcmp constant expressions in IRBuilder etc anymore,
i.e. treat them as "undesirable". This is in preparation for removing
them entirely.

Part of:
https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179
---
 clang/test/Analysis/builtin_signbit.cpp   |  36 +++---
 .../catch-nullptr-and-nonzero-offset.c|  62 +++
 clang/test/CodeGen/constantexpr-fneg.c|   3 +-
 clang/test/CodeGenCXX/cxx11-thread-local.cpp  |  20 ++--
 .../test/CodeGenCXX/ubsan-nullability-arg.cpp |   3 +-
 clang/test/CodeGenCXX/weak-external.cpp   |  15 ++-
 clang/test/Driver/linker-wrapper-image.c  |  98 +
 clang/test/OpenMP/threadprivate_codegen.cpp   | 104 ++
 llvm/include/llvm/Analysis/TargetFolder.h |   2 +-
 llvm/include/llvm/IR/ConstantFolder.h |   2 +-
 llvm/lib/Analysis/ConstantFolding.cpp |   2 +-
 llvm/lib/IR/ConstantFold.cpp  |  13 ++-
 llvm/test/Assembler/ConstantExprFold.ll   |   4 +-
 llvm/test/Assembler/ConstantExprNoFold.ll |   4 +-
 llvm/test/Assembler/vector-cmp.ll |   2 +-
 .../AMDGPU/lower-ctor-dtor-constexpr-alias.ll |   3 +-
 llvm/test/CodeGen/AMDGPU/lower-ctor-dtor.ll   |   3 +-
 .../AMDGPU/lower-multiple-ctor-dtor.ll|   3 +-
 .../MemorySanitizer/check-constant-shadow.ll  |   3 +-
 .../SanitizerBinaryMetadata/atomics.ll|  12 +-
 .../Transforms/Attributor/value-simplify.ll   |   7 +-
 .../binop-select-cast-of-select-cond.ll   |   2 +-
 .../constant-fold-address-space-pointer.ll|   6 +-
 .../Transforms/InstCombine/getelementptr.ll   |   3 +-
 ...hoist-xor-by-constant-from-xor-by-value.ll |   3 +-
 llvm/test/Transforms/InstCombine/pr33453.ll   |   2 +-
 llvm/test/Transforms/InstCombine/pr83947.ll   |   4 +-
 llvm/test/Transforms/InstCombine/rem.ll   |   4 +-
 .../Transforms/InstCombine/select-and-or.ll   |   4 +-
 .../InstCombine/select-safe-transforms.ll |   4 +-
 .../InstSimplify/ConstProp/bitcast.ll |   9 +-
 .../InstSimplify/ConstProp/icmp-global.ll |  54 ++---
 .../InstSimplify/bitcast-vector-fold.ll   |   3 +-
 llvm/test/Transforms/InstSimplify/compare.ll  |   6 +-
 .../Transforms/InstSimplify/past-the-end.ll   |   6 +-
 .../JumpThreading/constant-fold-status.ll |   3 +-
 .../LowerTypeTests/cfi-direct-call1.ll|  10 +-
 .../LowerTypeTests/function-weak.ll   |  74 +++--
 .../test/Transforms/SCCP/conditions-ranges.ll |   9 +-
 .../phi-to-select-constexpr-icmp.ll   |   2 +-
 40 files changed, 353 insertions(+), 256 deletions(-)

diff --git a/clang/test/Analysis/builtin_signbit.cpp 
b/clang/test/Analysis/builtin_signbit.cpp
index 57e6816ce2802..be10f0950f69b 100644
--- a/clang/test/Analysis/builtin_signbit.cpp
+++ b/clang/test/Analysis/builtin_signbit.cpp
@@ -84,28 +84,30 @@ long double ld = -1.0L;
 // CHECK-LE-LABEL: define dso_local void @_Z12test_signbitv(
 // CHECK-LE-SAME: ) #[[ATTR0:[0-9]+]] {
 // CHECK-LE-NEXT:  entry:
-// CHECK-LE-NEXT:[[FROMBOOL:%.*]] = zext i1 icmp slt (i64 trunc (i128 
bitcast (ppc_fp128 0xM3FF0 to i128) to i64), i64 0) 
to i8
+// CHECK-LE-NEXT:[[TMP0:%.*]] = icmp slt i64 trunc (i128 bitcast 
(ppc_fp128 0xM3FF0 to i128) to i64), 0
+// CHECK-LE-NEXT:[[FROMBOOL:%.*]] = zext i1 [[TMP0]] to i8
 // CHECK-LE-NEXT:store i8 [[FROMBOOL]], ptr @b, align 1
-// CHECK-LE-NEXT:[[TMP0:%.*]] = load ppc_fp128, ptr @ld, align 16
-// CHECK-LE-NEXT:[[TMP1:%.*]] = bitcast ppc_fp128 [[TMP0]] to i128
-// CHECK-LE-NEXT:[[TMP2:%.*]] = trunc i128 [[TMP1]] to i64
-// CHECK-LE-NEXT:[[TMP3:%.*]] = icmp slt i64 [[TMP2]], 0
-// CHECK-LE-NEXT:[[FROMBOOL1:%.*]] = zext i1 [[TMP3]] to i8
+// CHECK-LE-NEXT:[[TMP1:%.*]] = load ppc_fp128, ptr @ld, align 16
+// CHECK-LE-NEXT:[[TMP2:%.*]] = bitcast ppc_fp128 [[TMP1]] to i128
+// CHECK-LE-NEXT:[[TMP3:%.*]] = trunc i128 [[TMP2]] to i64
+// CHECK-LE-NEXT:[[TMP4:%.*]] = icmp slt i64 [[TMP3]], 0
+// CHECK-LE-NEXT:[[FROMBOOL1:%.*]] = zext i1 [[TMP4]] to i8
 // CHECK-LE-NEXT:store i8 [[FROMBOOL1]], ptr @b, align 1
 // CHECK-LE-NEXT:store i8 0, ptr @b, align 1
-// CHECK-LE-NEXT:[[TMP4:%.*]] = load double, ptr @d, align 8
-// CHECK-LE-NEXT:[[CONV:%.*]] = fptrunc double [[TMP4]] to float
-// CHECK-LE-NEXT:[[TMP5:%.*]] = bitcast float [[CONV]] to i32
-// CHECK-LE-NEXT:[[TMP6:%.*]] = icmp slt i32 [[TMP5]], 

[clang] [llvm] [IR] Avoid creating icmp/fcmp constant expressions (PR #92885)

2024-05-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-ir

Author: Nikita Popov (nikic)


Changes

Do not create icmp/fcmp constant expressions in IRBuilder etc anymore, i.e. 
treat them as "undesirable". This is in preparation for removing them entirely.

Part of: https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179

---

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


40 Files Affected:

- (modified) clang/test/Analysis/builtin_signbit.cpp (+19-17) 
- (modified) clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c (+40-22) 
- (modified) clang/test/CodeGen/constantexpr-fneg.c (+2-1) 
- (modified) clang/test/CodeGenCXX/cxx11-thread-local.cpp (+12-8) 
- (modified) clang/test/CodeGenCXX/ubsan-nullability-arg.cpp (+2-1) 
- (modified) clang/test/CodeGenCXX/weak-external.cpp (+11-4) 
- (modified) clang/test/Driver/linker-wrapper-image.c (+50-48) 
- (modified) clang/test/OpenMP/threadprivate_codegen.cpp (+56-48) 
- (modified) llvm/include/llvm/Analysis/TargetFolder.h (+1-1) 
- (modified) llvm/include/llvm/IR/ConstantFolder.h (+1-1) 
- (modified) llvm/lib/Analysis/ConstantFolding.cpp (+1-1) 
- (modified) llvm/lib/IR/ConstantFold.cpp (+8-5) 
- (modified) llvm/test/Assembler/ConstantExprFold.ll (+2-2) 
- (modified) llvm/test/Assembler/ConstantExprNoFold.ll (+2-2) 
- (modified) llvm/test/Assembler/vector-cmp.ll (+1-1) 
- (modified) llvm/test/CodeGen/AMDGPU/lower-ctor-dtor-constexpr-alias.ll (+2-1) 
- (modified) llvm/test/CodeGen/AMDGPU/lower-ctor-dtor.ll (+2-1) 
- (modified) llvm/test/CodeGen/AMDGPU/lower-multiple-ctor-dtor.ll (+2-1) 
- (modified) llvm/test/Instrumentation/MemorySanitizer/check-constant-shadow.ll 
(+2-1) 
- (modified) llvm/test/Instrumentation/SanitizerBinaryMetadata/atomics.ll 
(+8-4) 
- (modified) llvm/test/Transforms/Attributor/value-simplify.ll (+1-6) 
- (modified) 
llvm/test/Transforms/InstCombine/binop-select-cast-of-select-cond.ll (+1-1) 
- (modified) 
llvm/test/Transforms/InstCombine/constant-fold-address-space-pointer.ll (+4-2) 
- (modified) llvm/test/Transforms/InstCombine/getelementptr.ll (+2-1) 
- (modified) 
llvm/test/Transforms/InstCombine/hoist-xor-by-constant-from-xor-by-value.ll 
(+2-1) 
- (modified) llvm/test/Transforms/InstCombine/pr33453.ll (+1-1) 
- (modified) llvm/test/Transforms/InstCombine/pr83947.ll (+2-2) 
- (modified) llvm/test/Transforms/InstCombine/rem.ll (+2-2) 
- (modified) llvm/test/Transforms/InstCombine/select-and-or.ll (+2-2) 
- (modified) llvm/test/Transforms/InstCombine/select-safe-transforms.ll (+2-2) 
- (modified) llvm/test/Transforms/InstSimplify/ConstProp/bitcast.ll (+6-3) 
- (modified) llvm/test/Transforms/InstSimplify/ConstProp/icmp-global.ll 
(+36-18) 
- (modified) llvm/test/Transforms/InstSimplify/bitcast-vector-fold.ll (+2-1) 
- (modified) llvm/test/Transforms/InstSimplify/compare.ll (+4-2) 
- (modified) llvm/test/Transforms/InstSimplify/past-the-end.ll (+4-2) 
- (modified) llvm/test/Transforms/JumpThreading/constant-fold-status.ll (+2-1) 
- (modified) llvm/test/Transforms/LowerTypeTests/cfi-direct-call1.ll (+6-4) 
- (modified) llvm/test/Transforms/LowerTypeTests/function-weak.ll (+43-31) 
- (modified) llvm/test/Transforms/SCCP/conditions-ranges.ll (+6-3) 
- (modified) llvm/test/Transforms/SimplifyCFG/phi-to-select-constexpr-icmp.ll 
(+1-1) 


``diff
diff --git a/clang/test/Analysis/builtin_signbit.cpp 
b/clang/test/Analysis/builtin_signbit.cpp
index 57e6816ce2802..be10f0950f69b 100644
--- a/clang/test/Analysis/builtin_signbit.cpp
+++ b/clang/test/Analysis/builtin_signbit.cpp
@@ -84,28 +84,30 @@ long double ld = -1.0L;
 // CHECK-LE-LABEL: define dso_local void @_Z12test_signbitv(
 // CHECK-LE-SAME: ) #[[ATTR0:[0-9]+]] {
 // CHECK-LE-NEXT:  entry:
-// CHECK-LE-NEXT:[[FROMBOOL:%.*]] = zext i1 icmp slt (i64 trunc (i128 
bitcast (ppc_fp128 0xM3FF0 to i128) to i64), i64 0) 
to i8
+// CHECK-LE-NEXT:[[TMP0:%.*]] = icmp slt i64 trunc (i128 bitcast 
(ppc_fp128 0xM3FF0 to i128) to i64), 0
+// CHECK-LE-NEXT:[[FROMBOOL:%.*]] = zext i1 [[TMP0]] to i8
 // CHECK-LE-NEXT:store i8 [[FROMBOOL]], ptr @b, align 1
-// CHECK-LE-NEXT:[[TMP0:%.*]] = load ppc_fp128, ptr @ld, align 16
-// CHECK-LE-NEXT:[[TMP1:%.*]] = bitcast ppc_fp128 [[TMP0]] to i128
-// CHECK-LE-NEXT:[[TMP2:%.*]] = trunc i128 [[TMP1]] to i64
-// CHECK-LE-NEXT:[[TMP3:%.*]] = icmp slt i64 [[TMP2]], 0
-// CHECK-LE-NEXT:[[FROMBOOL1:%.*]] = zext i1 [[TMP3]] to i8
+// CHECK-LE-NEXT:[[TMP1:%.*]] = load ppc_fp128, ptr @ld, align 16
+// CHECK-LE-NEXT:[[TMP2:%.*]] = bitcast ppc_fp128 [[TMP1]] to i128
+// CHECK-LE-NEXT:[[TMP3:%.*]] = trunc i128 [[TMP2]] to i64
+// CHECK-LE-NEXT:[[TMP4:%.*]] = icmp slt i64 [[TMP3]], 0
+// CHECK-LE-NEXT:[[FROMBOOL1:%.*]] = zext i1 [[TMP4]] to i8
 // CHECK-LE-NEXT:store i8 [[FROMBOOL1]], ptr @b, align 1
 // CHECK-LE-NEXT:store i8 0, ptr @b, align 1
-// CHECK-LE-NEXT:[[TMP4:%.*]] =

[clang] [llvm] [IR] Avoid creating icmp/fcmp constant expressions (PR #92885)

2024-05-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-analysis

Author: Nikita Popov (nikic)


Changes

Do not create icmp/fcmp constant expressions in IRBuilder etc anymore, i.e. 
treat them as "undesirable". This is in preparation for removing them entirely.

Part of: https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179

---

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


40 Files Affected:

- (modified) clang/test/Analysis/builtin_signbit.cpp (+19-17) 
- (modified) clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c (+40-22) 
- (modified) clang/test/CodeGen/constantexpr-fneg.c (+2-1) 
- (modified) clang/test/CodeGenCXX/cxx11-thread-local.cpp (+12-8) 
- (modified) clang/test/CodeGenCXX/ubsan-nullability-arg.cpp (+2-1) 
- (modified) clang/test/CodeGenCXX/weak-external.cpp (+11-4) 
- (modified) clang/test/Driver/linker-wrapper-image.c (+50-48) 
- (modified) clang/test/OpenMP/threadprivate_codegen.cpp (+56-48) 
- (modified) llvm/include/llvm/Analysis/TargetFolder.h (+1-1) 
- (modified) llvm/include/llvm/IR/ConstantFolder.h (+1-1) 
- (modified) llvm/lib/Analysis/ConstantFolding.cpp (+1-1) 
- (modified) llvm/lib/IR/ConstantFold.cpp (+8-5) 
- (modified) llvm/test/Assembler/ConstantExprFold.ll (+2-2) 
- (modified) llvm/test/Assembler/ConstantExprNoFold.ll (+2-2) 
- (modified) llvm/test/Assembler/vector-cmp.ll (+1-1) 
- (modified) llvm/test/CodeGen/AMDGPU/lower-ctor-dtor-constexpr-alias.ll (+2-1) 
- (modified) llvm/test/CodeGen/AMDGPU/lower-ctor-dtor.ll (+2-1) 
- (modified) llvm/test/CodeGen/AMDGPU/lower-multiple-ctor-dtor.ll (+2-1) 
- (modified) llvm/test/Instrumentation/MemorySanitizer/check-constant-shadow.ll 
(+2-1) 
- (modified) llvm/test/Instrumentation/SanitizerBinaryMetadata/atomics.ll 
(+8-4) 
- (modified) llvm/test/Transforms/Attributor/value-simplify.ll (+1-6) 
- (modified) 
llvm/test/Transforms/InstCombine/binop-select-cast-of-select-cond.ll (+1-1) 
- (modified) 
llvm/test/Transforms/InstCombine/constant-fold-address-space-pointer.ll (+4-2) 
- (modified) llvm/test/Transforms/InstCombine/getelementptr.ll (+2-1) 
- (modified) 
llvm/test/Transforms/InstCombine/hoist-xor-by-constant-from-xor-by-value.ll 
(+2-1) 
- (modified) llvm/test/Transforms/InstCombine/pr33453.ll (+1-1) 
- (modified) llvm/test/Transforms/InstCombine/pr83947.ll (+2-2) 
- (modified) llvm/test/Transforms/InstCombine/rem.ll (+2-2) 
- (modified) llvm/test/Transforms/InstCombine/select-and-or.ll (+2-2) 
- (modified) llvm/test/Transforms/InstCombine/select-safe-transforms.ll (+2-2) 
- (modified) llvm/test/Transforms/InstSimplify/ConstProp/bitcast.ll (+6-3) 
- (modified) llvm/test/Transforms/InstSimplify/ConstProp/icmp-global.ll 
(+36-18) 
- (modified) llvm/test/Transforms/InstSimplify/bitcast-vector-fold.ll (+2-1) 
- (modified) llvm/test/Transforms/InstSimplify/compare.ll (+4-2) 
- (modified) llvm/test/Transforms/InstSimplify/past-the-end.ll (+4-2) 
- (modified) llvm/test/Transforms/JumpThreading/constant-fold-status.ll (+2-1) 
- (modified) llvm/test/Transforms/LowerTypeTests/cfi-direct-call1.ll (+6-4) 
- (modified) llvm/test/Transforms/LowerTypeTests/function-weak.ll (+43-31) 
- (modified) llvm/test/Transforms/SCCP/conditions-ranges.ll (+6-3) 
- (modified) llvm/test/Transforms/SimplifyCFG/phi-to-select-constexpr-icmp.ll 
(+1-1) 


``diff
diff --git a/clang/test/Analysis/builtin_signbit.cpp 
b/clang/test/Analysis/builtin_signbit.cpp
index 57e6816ce2802..be10f0950f69b 100644
--- a/clang/test/Analysis/builtin_signbit.cpp
+++ b/clang/test/Analysis/builtin_signbit.cpp
@@ -84,28 +84,30 @@ long double ld = -1.0L;
 // CHECK-LE-LABEL: define dso_local void @_Z12test_signbitv(
 // CHECK-LE-SAME: ) #[[ATTR0:[0-9]+]] {
 // CHECK-LE-NEXT:  entry:
-// CHECK-LE-NEXT:[[FROMBOOL:%.*]] = zext i1 icmp slt (i64 trunc (i128 
bitcast (ppc_fp128 0xM3FF0 to i128) to i64), i64 0) 
to i8
+// CHECK-LE-NEXT:[[TMP0:%.*]] = icmp slt i64 trunc (i128 bitcast 
(ppc_fp128 0xM3FF0 to i128) to i64), 0
+// CHECK-LE-NEXT:[[FROMBOOL:%.*]] = zext i1 [[TMP0]] to i8
 // CHECK-LE-NEXT:store i8 [[FROMBOOL]], ptr @b, align 1
-// CHECK-LE-NEXT:[[TMP0:%.*]] = load ppc_fp128, ptr @ld, align 16
-// CHECK-LE-NEXT:[[TMP1:%.*]] = bitcast ppc_fp128 [[TMP0]] to i128
-// CHECK-LE-NEXT:[[TMP2:%.*]] = trunc i128 [[TMP1]] to i64
-// CHECK-LE-NEXT:[[TMP3:%.*]] = icmp slt i64 [[TMP2]], 0
-// CHECK-LE-NEXT:[[FROMBOOL1:%.*]] = zext i1 [[TMP3]] to i8
+// CHECK-LE-NEXT:[[TMP1:%.*]] = load ppc_fp128, ptr @ld, align 16
+// CHECK-LE-NEXT:[[TMP2:%.*]] = bitcast ppc_fp128 [[TMP1]] to i128
+// CHECK-LE-NEXT:[[TMP3:%.*]] = trunc i128 [[TMP2]] to i64
+// CHECK-LE-NEXT:[[TMP4:%.*]] = icmp slt i64 [[TMP3]], 0
+// CHECK-LE-NEXT:[[FROMBOOL1:%.*]] = zext i1 [[TMP4]] to i8
 // CHECK-LE-NEXT:store i8 [[FROMBOOL1]], ptr @b, align 1
 // CHECK-LE-NEXT:store i8 0, ptr @b, align 1
-// CHECK-LE-NEXT:[[TMP4:%

[clang] 37813e0 - [clang][dataflow] Make `CNFFormula` externally accessible. (#92401)

2024-05-21 Thread via cfe-commits

Author: martinboehme
Date: 2024-05-21T11:34:08+02:00
New Revision: 37813e09fa8b67ec858ad3c82dcf72a8ff306b03

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

LOG: [clang][dataflow] Make `CNFFormula` externally accessible. (#92401)

This component can be useful when creating implementations of `Solver`,
as some
SAT solvers require the input to be in 3-CNF.

As part of making `CNFFormula` externally accessible, I have moved some
member
variables out of it that aren't really part of the representation of a
3-CNF
formula and thus live better elsewhere:

*  `WatchedHead` and `NextWatched` have been moved to
`WatchedLiteralsSolverImpl`, as they're part of the specific algorithm
used
   by that SAT solver.

* `Atomics` has become an output parameter of `buildCNF()` because it
has to do
with the relationship between a `CNFFormula` and the set of `Formula`s
it is
derived from rather than being an integral part of the representation of
a
   3-CNF formula.

I have also made all member variables private and added appropriate
accessors.

Added: 
clang/include/clang/Analysis/FlowSensitive/CNFFormula.h
clang/lib/Analysis/FlowSensitive/CNFFormula.cpp

Modified: 
clang/docs/tools/clang-formatted-files.txt
clang/include/clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h
clang/lib/Analysis/FlowSensitive/CMakeLists.txt
clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
llvm/utils/gn/secondary/clang/lib/Analysis/FlowSensitive/BUILD.gn

Removed: 




diff  --git a/clang/docs/tools/clang-formatted-files.txt 
b/clang/docs/tools/clang-formatted-files.txt
index b747adfb6992e..dee51e402b687 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -124,6 +124,7 @@ 
clang/include/clang/Analysis/Analyses/CFGReachabilityAnalysis.h
 clang/include/clang/Analysis/Analyses/ExprMutationAnalyzer.h
 clang/include/clang/Analysis/FlowSensitive/AdornedCFG.h
 clang/include/clang/Analysis/FlowSensitive/ASTOps.h
+clang/include/clang/Analysis/FlowSensitive/CNFFormula.h
 clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
 clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
 clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -621,6 +622,7 @@ clang/tools/libclang/CXCursor.h
 clang/tools/scan-build-py/tests/functional/src/include/clean-one.h
 clang/unittests/Analysis/CFGBuildResult.h
 clang/unittests/Analysis/MacroExpansionContextTest.cpp
+clang/unittests/Analysis/FlowSensitive/CNFFormula.cpp
 clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
 clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
 clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp
@@ -632,6 +634,7 @@ clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp
 clang/unittests/Analysis/FlowSensitive/TestingSupport.h
 clang/unittests/Analysis/FlowSensitive/TestingSupportTest.cpp
 clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+clang/unittests/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
 clang/unittests/Analysis/FlowSensitive/WatchedLiteralsSolverTest.cpp
 clang/unittests/AST/ASTImporterFixtures.cpp
 clang/unittests/AST/ASTImporterFixtures.h

diff  --git a/clang/include/clang/Analysis/FlowSensitive/CNFFormula.h 
b/clang/include/clang/Analysis/FlowSensitive/CNFFormula.h
new file mode 100644
index 0..fb13e774c67fe
--- /dev/null
+++ b/clang/include/clang/Analysis/FlowSensitive/CNFFormula.h
@@ -0,0 +1,179 @@
+//===- CNFFormula.h -*- 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
+//
+//===--===//
+//
+//  A representation of a boolean formula in 3-CNF.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CNFFORMULA_H
+#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CNFFORMULA_H
+
+#include 
+#include 
+
+#include "clang/Analysis/FlowSensitive/Formula.h"
+
+namespace clang {
+namespace dataflow {
+
+/// Boolean variables are represented as positive integers.
+using Variable = uint32_t;
+
+/// A null boolean variable is used as a placeholder in various data structures
+/// and algorithms.
+constexpr Variable NullVar = 0;
+
+/// Literals are represented as positive integers. Specifically, for a boolean
+/// variable `V` that is represented as the positive integer `I`, the positive
+/// literal `V` is represented as the integer `2*I` and the negative literal
+/// `!V` is represented as the integer `2*I+1`.
+usin

[clang] [llvm] [clang][dataflow] Make `CNFFormula` externally accessible. (PR #92401)

2024-05-21 Thread via cfe-commits

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


[clang] [llvm] [IR] Avoid creating icmp/fcmp constant expressions (PR #92885)

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


@@ -43,9 +43,9 @@
 ; CHECK: @mul = global ptr null
 ; CHECK: @xor = global ptr @A
 ; CHECK: @B = external global %Ty
-; CHECK: @icmp_ult1 = global i1 icmp ugt (ptr getelementptr inbounds (i64, ptr 
@A, i64 1), ptr @A)
+; CHECK: @icmp_ult1 = global i1 icmp ult (ptr @A, ptr getelementptr inbounds 
(i64, ptr @A, i64 1))

nikic wrote:

There are a few cases like this where we don't canonicalize constant 
expressions involving icmp anymore. This is because we also refuse to create 
new icmp expressions even if we already had one originally.

This is fine because it only happens if there was an icmp const expr in the 
first place, which will be removed shortly after this lands.

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


[clang] 9d70975 - [clang][Interp][NFC] Remove an assertion that's too strong

2024-05-21 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-05-21T11:38:45+02:00
New Revision: 9d70975c7a72f3fa58d2d63090b92886dbf8a32b

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

LOG: [clang][Interp][NFC] Remove an assertion that's too strong

Both types need to boil down to a vector type with the same length
and their element types need to match, but we still can't compare
them with == since they might be sugared, etc.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 70328c1f52af3..ee83947196c6e 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2538,8 +2538,6 @@ bool ByteCodeExprGen::VisitShuffleVectorExpr(
   assert(E->getNumSubExprs() > 2);
 
   const Expr *Vecs[] = {E->getExpr(0), E->getExpr(1)};
-  assert(Vecs[0]->getType() == Vecs[1]->getType());
-
   const VectorType *VT = Vecs[0]->getType()->castAs();
   PrimType ElemT = classifyPrim(VT->getElementType());
   unsigned NumInputElems = VT->getNumElements();



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


[clang] [clang] Report erroneous floating point results in _Complex math (PR #90588)

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

tbaederr wrote:

Ping @jcranmer-intel, @hubert-reinterpretcast

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


[clang-tools-extra] [clangd] Reduce instantiation depth in `infinite-instantiations.test` (PR #92888)

2024-05-21 Thread Vlad Serebrennikov via cfe-commits

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

This patch reduces template instantiation depth in 
`infinite-instantiations.test`, because it doesn't seem to be concerned with 
the default instantiation depth in particular, but has a very material impact 
on testing times of clangd. Which subsequently affects CI run times for all 
Clang changes.

The following numbers are taken from 
https://buildkite.com/llvm-project/github-pull-requests/builds/65299, but they 
are the same for any CI run with clangd:
Linux:
```
Slowest Tests:
--
35.19s: Clangd :: infinite-instantiation.test
5.53s: Clangd :: protocol.test
1.48s: Clang Tools :: clang-tidy/checkers/modernize/use-emplace.cpp
1.40s: Clang Tools :: 
clang-tidy/checkers/misc/non-private-member-variables-in-classes.cpp
1.17s: Clang Tools :: clang-tidy/checkers/google/upgrade-googletest-case.cpp
1.15s: Clang Tools :: clang-tidy/checkers/bugprone/unsafe-functions.c
1.10s: Clang Tools :: clang-tidy/infrastructure/check_clang_tidy.cpp
1.07s: Clang Tools :: clang-tidy/checkers/readability/redundant-casting.cpp
1.06s: Clang Tools :: clang-tidy/checkers/misc/const-correctness-values.cpp
1.02s: Clang Tools :: 
clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-char.cpp
1.00s: Clang Tools :: clang-tidy/checkers/modernize/loop-convert-reverse.cpp
0.97s: Clang Tools :: clang-tidy/checkers/modernize/loop-convert-basic.cpp
0.95s: Clang Tools :: clang-tidy/checkers/modernize/use-std-print.cpp
0.93s: Clang Tools :: clang-tidy/checkers/modernize/loop-convert-extra.cpp
0.92s: Clang Tools :: clang-tidy/checkers/altera/single-work-item-barrier.cpp
0.90s: Clang Tools :: 
clang-tidy/checkers/readability/identifier-naming-hungarian-notation-lower-case-prefix.cpp
0.90s: Clang Tools :: 
clang-tidy/checkers/modernize/use-auto-min-type-name-length.cpp
0.89s: Clang Tools :: 
clang-tidy/checkers/readability/identifier-naming-hungarian-notation-cfgfile.cpp
0.88s: Clang Tools :: 
clang-tidy/checkers/readability/identifier-naming-hungarian-notation.cpp
0.85s: Clangd Unit Tests :: ./ClangdTests/Hover/All
```
Windows:
```
Slowest Tests:
--
244.74s: Clangd :: infinite-instantiation.test
11.42s: Clangd :: protocol.test
8.97s: Clang Tools :: 
clang-tidy/checkers/misc/non-private-member-variables-in-classes.cpp
7.44s: Clang Tools :: clang-tidy/checkers/altera/single-work-item-barrier.cpp
6.71s: Clang Tools :: clang-tidy/checkers/bugprone/unsafe-functions.c
6.61s: Clang Tools :: 
clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-char.cpp
6.42s: Clang Tools :: clang-tidy/infrastructure/check_clang_tidy.cpp
6.32s: Clang Tools :: clang-tidy/checkers/modernize/loop-convert-reverse.cpp
6.01s: Clang Tools :: clang-tidy/checkers/readability/redundant-casting.cpp
5.62s: Clang Tools :: 
clang-tidy/checkers/modernize/use-auto-min-type-name-length.cpp
5.58s: Clang Tools :: 
clang-tidy/checkers/modernize/replace-disallow-copy-and-assign-macro.cpp
5.46s: Clang Tools :: 
clang-tidy/checkers/readability/function-cognitive-complexity-flags.cpp
5.08s: Clang Tools :: 
clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
5.07s: Clang Tools :: clang-tidy/checkers/readability/redundant-declaration.cpp
4.99s: Clang Tools :: 
clang-tidy/checkers/readability/identifier-naming-hungarian-notation-lower-case-prefix.cpp
4.91s: Clang Tools :: 
clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-pointer-offset.cpp
4.87s: Clang Tools :: 
clang-tidy/checkers/readability/identifier-naming-hungarian-notation-cfgfile.cpp
4.79s: Clang Tools :: clang-tidy/checkers/google/upgrade-googletest-case.cpp
4.78s: Clang Tools :: clang-tidy/infrastructure/clean-up-code.cpp
4.76s: Clang Tools :: 
clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-int.cpp
```

>From 3a75e820f83f500a5ef438e6f61dc3bf0f39ea7d Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Tue, 21 May 2024 12:45:36 +0300
Subject: [PATCH] [clangd] Reduce instantiation depth in
 `infinite-instantiations.test`

---
 clang-tools-extra/clangd/test/infinite-instantiation.test | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clangd/test/infinite-instantiation.test 
b/clang-tools-extra/clangd/test/infinite-instantiation.test
index 85a1b656f4908..98260c075d240 100644
--- a/clang-tools-extra/clangd/test/infinite-instantiation.test
+++ b/clang-tools-extra/clangd/test/infinite-instantiation.test
@@ -1,5 +1,6 @@
-// RUN: cp %s %t.cpp
-// RUN: not clangd -check=%t.cpp 2>&1 | FileCheck -strict-whitespace %s
+// RUN: rm -rf %t.dir && mkdir -p %t.dir
+// RUN: echo '[{"directory": "%/t.dir", "command": "clang -ftemplate-depth=100 
-x c++ %s", "file": "%s"}]' > %t.dir/compile_commands.json
+// RUN: not clangd --compile-commands-dir=%t.dir -check=%s 2>&1 | FileCheck 
-strict-whit

[clang-tools-extra] [clangd] Reduce instantiation depth in `infinite-instantiations.test` (PR #92888)

2024-05-21 Thread Vlad Serebrennikov via cfe-commits

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


[clang-tools-extra] [clangd] Reduce instantiation depth in `infinite-instantiations.test` (PR #92888)

2024-05-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangd

Author: Vlad Serebrennikov (Endilll)


Changes

This patch reduces template instantiation depth in 
`infinite-instantiations.test`, because it doesn't seem to be concerned with 
the default instantiation depth in particular, but has a very material impact 
on testing times of clangd. Which subsequently affects CI run times for all 
Clang changes.

The following numbers are taken from 
https://buildkite.com/llvm-project/github-pull-requests/builds/65299, but they 
are the same for any CI run with clangd:
Linux:
```
Slowest Tests:
--
35.19s: Clangd :: infinite-instantiation.test
5.53s: Clangd :: protocol.test
1.48s: Clang Tools :: clang-tidy/checkers/modernize/use-emplace.cpp
1.40s: Clang Tools :: 
clang-tidy/checkers/misc/non-private-member-variables-in-classes.cpp
1.17s: Clang Tools :: clang-tidy/checkers/google/upgrade-googletest-case.cpp
1.15s: Clang Tools :: clang-tidy/checkers/bugprone/unsafe-functions.c
1.10s: Clang Tools :: clang-tidy/infrastructure/check_clang_tidy.cpp
1.07s: Clang Tools :: clang-tidy/checkers/readability/redundant-casting.cpp
1.06s: Clang Tools :: clang-tidy/checkers/misc/const-correctness-values.cpp
1.02s: Clang Tools :: 
clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-char.cpp
1.00s: Clang Tools :: clang-tidy/checkers/modernize/loop-convert-reverse.cpp
0.97s: Clang Tools :: clang-tidy/checkers/modernize/loop-convert-basic.cpp
0.95s: Clang Tools :: clang-tidy/checkers/modernize/use-std-print.cpp
0.93s: Clang Tools :: clang-tidy/checkers/modernize/loop-convert-extra.cpp
0.92s: Clang Tools :: clang-tidy/checkers/altera/single-work-item-barrier.cpp
0.90s: Clang Tools :: 
clang-tidy/checkers/readability/identifier-naming-hungarian-notation-lower-case-prefix.cpp
0.90s: Clang Tools :: 
clang-tidy/checkers/modernize/use-auto-min-type-name-length.cpp
0.89s: Clang Tools :: 
clang-tidy/checkers/readability/identifier-naming-hungarian-notation-cfgfile.cpp
0.88s: Clang Tools :: 
clang-tidy/checkers/readability/identifier-naming-hungarian-notation.cpp
0.85s: Clangd Unit Tests :: ./ClangdTests/Hover/All
```
Windows:
```
Slowest Tests:
--
244.74s: Clangd :: infinite-instantiation.test
11.42s: Clangd :: protocol.test
8.97s: Clang Tools :: 
clang-tidy/checkers/misc/non-private-member-variables-in-classes.cpp
7.44s: Clang Tools :: clang-tidy/checkers/altera/single-work-item-barrier.cpp
6.71s: Clang Tools :: clang-tidy/checkers/bugprone/unsafe-functions.c
6.61s: Clang Tools :: 
clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-char.cpp
6.42s: Clang Tools :: clang-tidy/infrastructure/check_clang_tidy.cpp
6.32s: Clang Tools :: clang-tidy/checkers/modernize/loop-convert-reverse.cpp
6.01s: Clang Tools :: clang-tidy/checkers/readability/redundant-casting.cpp
5.62s: Clang Tools :: 
clang-tidy/checkers/modernize/use-auto-min-type-name-length.cpp
5.58s: Clang Tools :: 
clang-tidy/checkers/modernize/replace-disallow-copy-and-assign-macro.cpp
5.46s: Clang Tools :: 
clang-tidy/checkers/readability/function-cognitive-complexity-flags.cpp
5.08s: Clang Tools :: 
clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
5.07s: Clang Tools :: clang-tidy/checkers/readability/redundant-declaration.cpp
4.99s: Clang Tools :: 
clang-tidy/checkers/readability/identifier-naming-hungarian-notation-lower-case-prefix.cpp
4.91s: Clang Tools :: 
clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-pointer-offset.cpp
4.87s: Clang Tools :: 
clang-tidy/checkers/readability/identifier-naming-hungarian-notation-cfgfile.cpp
4.79s: Clang Tools :: clang-tidy/checkers/google/upgrade-googletest-case.cpp
4.78s: Clang Tools :: clang-tidy/infrastructure/clean-up-code.cpp
4.76s: Clang Tools :: 
clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-int.cpp
```

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


1 Files Affected:

- (modified) clang-tools-extra/clangd/test/infinite-instantiation.test (+3-2) 


``diff
diff --git a/clang-tools-extra/clangd/test/infinite-instantiation.test 
b/clang-tools-extra/clangd/test/infinite-instantiation.test
index 85a1b656f4908..98260c075d240 100644
--- a/clang-tools-extra/clangd/test/infinite-instantiation.test
+++ b/clang-tools-extra/clangd/test/infinite-instantiation.test
@@ -1,5 +1,6 @@
-// RUN: cp %s %t.cpp
-// RUN: not clangd -check=%t.cpp 2>&1 | FileCheck -strict-whitespace %s
+// RUN: rm -rf %t.dir && mkdir -p %t.dir
+// RUN: echo '[{"directory": "%/t.dir", "command": "clang -ftemplate-depth=100 
-x c++ %s", "file": "%s"}]' > %t.dir/compile_commands.json
+// RUN: not clangd --compile-commands-dir=%t.dir -check=%s 2>&1 | FileCheck 
-strict-whitespace %s
 
 // CHECK: [template_recursion_depth_exceeded]
 

``




https://github.com/llvm/llvm-project/pull/92888
___

[clang] [clang-tools-extra] [libcxx] Reland "[clang] Enable sized deallocation by default in C++14 onwards" (PR #90373)

2024-05-21 Thread Pengcheng Wang via cfe-commits

https://github.com/wangpc-pp updated 
https://github.com/llvm/llvm-project/pull/90373

>From fd015302585fc8149811868636cb0da5c422cf7a Mon Sep 17 00:00:00 2001
From: Pengcheng Wang 
Date: Fri, 26 Apr 2024 16:59:12 +0800
Subject: [PATCH] [clang] Enable sized deallocation by default in C++14 onwards

Since C++14 has been released for about nine years and most standard
libraries have implemented sized deallocation functions, it's time to
make this feature default again.

This is another try of https://reviews.llvm.org/D112921.

The original commit cf5a8b4 was reverted by 2e5035a due to some
failures (see #83774).

Fixes #60061
---
 .../clangd/unittests/FindTargetTests.cpp  |   4 +-
 .../checkers/misc/new-delete-overloads.cpp|  10 -
 clang/docs/ReleaseNotes.rst   |   5 +
 clang/include/clang/Driver/Options.td |   8 +-
 clang/lib/Driver/ToolChains/Clang.cpp |  13 +-
 clang/lib/Driver/ToolChains/Darwin.cpp|  58 -
 clang/lib/Driver/ToolChains/Darwin.h  |   4 +
 clang/lib/Driver/ToolChains/ZOS.cpp   |   6 +
 clang/test/AST/ast-dump-expr-json.cpp |   2 +-
 clang/test/AST/ast-dump-expr.cpp  |   2 +-
 clang/test/AST/ast-dump-stmt-json.cpp | 244 +-
 clang/test/Analysis/cxxnewexpr-callback.cpp   |   4 +-
 .../basic.stc.dynamic.deallocation/p2.cpp |   2 +-
 clang/test/CXX/drs/cwg292.cpp |  17 +-
 .../test/CXX/expr/expr.unary/expr.new/p14.cpp |   2 +-
 .../CodeGenCXX/cxx1y-sized-deallocation.cpp   |  10 +-
 .../CodeGenCXX/cxx1z-aligned-allocation.cpp   |   6 +-
 .../CodeGenCXX/cxx2a-destroying-delete.cpp|   4 +-
 clang/test/CodeGenCXX/delete-two-arg.cpp  |   4 +-
 clang/test/CodeGenCXX/delete.cpp  |  12 +-
 clang/test/CodeGenCXX/dllimport.cpp   |   4 +-
 clang/test/CodeGenCXX/new.cpp |   6 +-
 .../coro-aligned-alloc-2.cpp  |   2 -
 .../CodeGenCoroutines/coro-aligned-alloc.cpp  |   6 +-
 clang/test/CodeGenCoroutines/coro-alloc.cpp   |   6 +-
 clang/test/CodeGenCoroutines/coro-cleanup.cpp |   6 +-
 clang/test/CodeGenCoroutines/coro-dealloc.cpp |   2 -
 clang/test/CodeGenCoroutines/coro-gro.cpp |   3 +-
 clang/test/CodeGenCoroutines/pr56919.cpp  |   9 +-
 clang/test/Lexer/cxx-features.cpp |  20 +-
 clang/test/PCH/cxx1z-aligned-alloc.cpp|  10 +-
 clang/test/SemaCXX/MicrosoftExtensions.cpp|   8 +-
 .../SemaCXX/builtin-operator-new-delete.cpp   |   2 +-
 .../test/SemaCXX/cxx1y-sized-deallocation.cpp |   2 +-
 .../unavailable_aligned_allocation.cpp|  15 +-
 clang/tools/clang-repl/CMakeLists.txt |  43 +++
 clang/unittests/Interpreter/CMakeLists.txt|  43 +++
 .../StaticAnalyzer/CallEventTest.cpp  |   2 +-
 clang/www/cxx_status.html |  11 +-
 .../support.dynamic/libcpp_deallocate.sh.cpp  |   3 +
 .../sized_delete_array14.pass.cpp |   8 +-
 .../new.delete.single/sized_delete14.pass.cpp |   8 +-
 42 files changed, 523 insertions(+), 113 deletions(-)

diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp 
b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index 0b2273f0a9a6e..3220a5a6a9825 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -836,7 +836,9 @@ TEST_F(TargetDeclTest, OverloadExpr) {
   [[delete]] x;
 }
   )cpp";
-  EXPECT_DECLS("CXXDeleteExpr", "void operator delete(void *) noexcept");
+  // Sized deallocation is enabled by default in C++14 onwards.
+  EXPECT_DECLS("CXXDeleteExpr",
+   "void operator delete(void *, unsigned long) noexcept");
 }
 
 TEST_F(TargetDeclTest, DependentExprs) {
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp
index 78f021144b2e1..f86fe8a4c5b14 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp
@@ -12,16 +12,6 @@ struct S {
 // CHECK-MESSAGES: :[[@LINE+1]]:7: warning: declaration of 'operator new' has 
no matching declaration of 'operator delete' at the same scope
 void *operator new(size_t size) noexcept(false);
 
-struct T {
-  // Sized deallocations are not enabled by default, and so this new/delete 
pair
-  // does not match. However, we expect only one warning, for the new, because
-  // the operator delete is a placement delete and we do not warn on 
mismatching
-  // placement operations.
-  // CHECK-MESSAGES: :[[@LINE+1]]:9: warning: declaration of 'operator new' 
has no matching declaration of 'operator delete' at the same scope
-  void *operator new(size_t size) noexcept;
-  void operator delete(void *ptr, size_t) noexcept; // ok only if sized 
deallocation is enabled
-};
-
 struct U {
   void *operator new(size_t size) noexcept;
   void operator delete(void *ptr) n

[clang] [clang-tools-extra] [libcxx] Reland "[clang] Enable sized deallocation by default in C++14 onwards" (PR #90373)

2024-05-21 Thread Pengcheng Wang via cfe-commits

wangpc-pp wrote:

Please review this PR as all noticable issues have been fixed I think.

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


[clang] 808fc84 - [clang][Interp] Fix dummy DeclRefExprs for function pointers

2024-05-21 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-05-21T12:02:19+02:00
New Revision: 808fc8406973f958fa76acba2d7648d215d9681b

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

LOG: [clang][Interp] Fix dummy DeclRefExprs for function pointers

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/functions.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index ee83947196c6e..640311e1444bf 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -3722,8 +3722,16 @@ bool ByteCodeExprGen::VisitDeclRefExpr(const 
DeclRefExpr *E) {
 }
   }
 
-  if (std::optional I = P.getOrCreateDummy(D))
-return this->emitGetPtrGlobal(*I, E);
+  if (std::optional I = P.getOrCreateDummy(D)) {
+if (!this->emitGetPtrGlobal(*I, E))
+  return false;
+// Convert the dummy pointer to another pointer type if we have to.
+if (PrimType PT = classifyPrim(E); PT != PT_Ptr) {
+  if (!this->emitDecayPtr(PT_Ptr, PT, E))
+return false;
+}
+return true;
+  }
 
   return this->emitInvalidDeclRef(E, E);
 }

diff  --git a/clang/test/AST/Interp/functions.cpp 
b/clang/test/AST/Interp/functions.cpp
index a5bb9f1a19aaa..e95ade8ef51b7 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -617,3 +617,9 @@ namespace {
   void bir [[clang::annotate("B", {1, 2, 3, 4})]] (); // both-error 
{{'annotate' attribute requires parameter 1 to be a constant expression}} \
   // both-note 
{{subexpression not valid in a constant expression}}
 }
+
+namespace FuncPtrParam {
+  void foo(int(&a)()) {
+*a; // both-warning {{expression result unused}}
+  }
+}



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


[clang-tools-extra] [clangd] Reduce instantiation depth in `infinite-instantiations.test` (PR #92888)

2024-05-21 Thread Younan Zhang via cfe-commits

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

Thanks! I added that test to check if the instantiation stack guard takes 
effect in clangd. And the change makes sense to me.

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


[clang] 375761b - [Clang] Emit lifetime markers for non-aggregate temporary allocas (#90849)

2024-05-21 Thread via cfe-commits

Author: Lukacma
Date: 2024-05-21T11:07:29+01:00
New Revision: 375761bcaba9ba5694890ece6eed5db286fc4fd1

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

LOG: [Clang] Emit lifetime markers for non-aggregate temporary allocas (#90849)

This patch extends https://reviews.llvm.org/D68611 and emits lifetime
markers for temporary allocas of non-aggregate types as well.

Added: 


Modified: 
clang/lib/CodeGen/CGCall.cpp
clang/test/CodeGen/aarch64-byval-temp.c
clang/test/CodeGen/aarch64-sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c
clang/test/CodeGen/aarch64-sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.cpp
clang/test/CodeGen/nofpclass.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index cc626844f424d..97449a5e51e73 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -5192,18 +5192,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
 case ABIArgInfo::Indirect:
 case ABIArgInfo::IndirectAliased: {
   assert(NumIRArgs == 1);
-  if (!I->isAggregate()) {
-// Make a temporary alloca to pass the argument.
-RawAddress Addr = CreateMemTempWithoutCast(
-I->Ty, ArgInfo.getIndirectAlign(), "indirect-arg-temp");
-
-llvm::Value *Val = getAsNaturalPointerTo(Addr, I->Ty);
-if (ArgHasMaybeUndefAttr)
-  Val = Builder.CreateFreeze(Val);
-IRCallArgs[FirstIRArg] = Val;
-
-I->copyInto(*this, Addr);
-  } else {
+  if (I->isAggregate()) {
 // We want to avoid creating an unnecessary temporary+copy here;
 // however, we need one in three cases:
 // 1. If the argument is not byval, and we are required to copy the
@@ -5256,28 +5245,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   }
 }
 
-if (NeedCopy) {
-  // Create an aligned temporary, and copy to it.
-  RawAddress AI = CreateMemTempWithoutCast(
-  I->Ty, ArgInfo.getIndirectAlign(), "byval-temp");
-  llvm::Value *Val = getAsNaturalPointerTo(AI, I->Ty);
-  if (ArgHasMaybeUndefAttr)
-Val = Builder.CreateFreeze(Val);
-  IRCallArgs[FirstIRArg] = Val;
-
-  // Emit lifetime markers for the temporary alloca.
-  llvm::TypeSize ByvalTempElementSize =
-  CGM.getDataLayout().getTypeAllocSize(AI.getElementType());
-  llvm::Value *LifetimeSize =
-  EmitLifetimeStart(ByvalTempElementSize, AI.getPointer());
-
-  // Add cleanup code to emit the end lifetime marker after the call.
-  if (LifetimeSize) // In case we disabled lifetime markers.
-CallLifetimeEndAfterCall.emplace_back(AI, LifetimeSize);
-
-  // Generate the copy.
-  I->copyInto(*this, AI);
-} else {
+if (!NeedCopy) {
   // Skip the extra memcpy call.
   llvm::Value *V = getAsNaturalPointerTo(Addr, I->Ty);
   auto *T = llvm::PointerType::get(
@@ -5289,8 +5257,31 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   if (ArgHasMaybeUndefAttr)
 Val = Builder.CreateFreeze(Val);
   IRCallArgs[FirstIRArg] = Val;
+  break;
 }
   }
+
+  // For non-aggregate args and aggregate args meeting conditions above
+  // we need to create an aligned temporary, and copy to it.
+  RawAddress AI = CreateMemTempWithoutCast(
+  I->Ty, ArgInfo.getIndirectAlign(), "byval-temp");
+  llvm::Value *Val = getAsNaturalPointerTo(AI, I->Ty);
+  if (ArgHasMaybeUndefAttr)
+Val = Builder.CreateFreeze(Val);
+  IRCallArgs[FirstIRArg] = Val;
+
+  // Emit lifetime markers for the temporary alloca.
+  llvm::TypeSize ByvalTempElementSize =
+  CGM.getDataLayout().getTypeAllocSize(AI.getElementType());
+  llvm::Value *LifetimeSize =
+  EmitLifetimeStart(ByvalTempElementSize, AI.getPointer());
+
+  // Add cleanup code to emit the end lifetime marker after the call.
+  if (LifetimeSize) // In case we disabled lifetime markers.
+CallLifetimeEndAfterCall.emplace_back(AI, LifetimeSize);
+
+  // Generate the copy.
+  I->copyInto(*this, AI);
   break;
 }
 

diff  --git a/clang/test/CodeGen/aarch64-byval-temp.c 
b/clang/test/CodeGen/aarch64-byval-temp.c
index e9e2586406e5c..0384830c69a41 100644
--- a/clang/test/CodeGen/aarch64-byval-temp.c
+++ b/clang/test/CodeGen/aarch64-byval-temp.c
@@ -1,13 +1,14 @@
-// RUN: %clang_cc1 -emit-llvm -triple arm64-- -o - %s -O0 | FileCheck %s 
--check-prefix=CHECK-O0
-// RUN: %clang_cc1 -emit-llvm -disable-llvm-optzns -triple arm64-- -o - %s -O3 
| FileCheck %s --check-prefix=CHECK-O3
+// RUN: %clang_cc1 -emit-llv

[clang] [Clang] Emit lifetime markers for non-aggregate temporary allocas (PR #90849)

2024-05-21 Thread via cfe-commits

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


[clang] bb3d261 - [clang][Interp] Protect GetPtrField ops from unknown size arrays

2024-05-21 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-05-21T12:32:59+02:00
New Revision: bb3d261f55e72e313fd8ddfefac3b47cfca2f656

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

LOG: [clang][Interp] Protect GetPtrField ops from unknown size arrays

Added: 


Modified: 
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/arrays.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index d9f23a4b8c965..bc2ca126ce364 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1245,6 +1245,8 @@ inline bool GetPtrField(InterpState &S, CodePtr OpPC, 
uint32_t Off) {
 return false;
   if (!CheckRange(S, OpPC, Ptr, CSK_Field))
 return false;
+  if (!CheckArray(S, OpPC, Ptr))
+return false;
   if (!CheckSubobject(S, OpPC, Ptr, CSK_Field))
 return false;
 

diff  --git a/clang/test/AST/Interp/arrays.cpp 
b/clang/test/AST/Interp/arrays.cpp
index 929f25b95fa1f..71b6dabf39e45 100644
--- a/clang/test/AST/Interp/arrays.cpp
+++ b/clang/test/AST/Interp/arrays.cpp
@@ -595,3 +595,12 @@ int test_multiarray22() {
 }
 
 #endif
+
+namespace ArrayMemberAccess {
+  struct A {
+int x;
+  };
+  void f(const A (&a)[]) {
+bool cond = a->x;
+  }
+}



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


[clang] [Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer (PR #87933)

2024-05-21 Thread via cfe-commits

yronglin wrote:

> > @erichkeane Can you please take a look?
> 
> Looking now, I was out on Friday due to illness.

I'm sorry to hear that. Sending all my best and wishing you a rapid comeback.

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


[clang] [Clang] Add support for [[msvc::noinline]] attribute. (PR #91720)

2024-05-21 Thread Xu Zhang via cfe-commits

https://github.com/simonzgx updated 
https://github.com/llvm/llvm-project/pull/91720

>From 54b69712d2ffc3536d41d56194e67da802b92049 Mon Sep 17 00:00:00 2001
From: Xu Zhang 
Date: Fri, 10 May 2024 01:24:24 +0800
Subject: [PATCH 1/5] [Clang] Add support for [[msvc::noinline]] attribute.
 (#90941)

---
 clang/include/clang/Basic/Attr.td   | 5 -
 clang/include/clang/Basic/AttrDocs.td   | 2 ++
 clang/test/CodeGen/attr-ms-noinline.cpp | 0
 clang/test/Sema/attr-ms-noinline.cpp| 0
 4 files changed, 6 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/attr-ms-noinline.cpp
 create mode 100644 clang/test/Sema/attr-ms-noinline.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 7a7721239a28f..8532e5c47fe47 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1997,9 +1997,12 @@ def Convergent : InheritableAttr {
 def NoInline : DeclOrStmtAttr {
   let Spellings = [CustomKeyword<"__noinline__">, GCC<"noinline">,
CXX11<"clang", "noinline">, C23<"clang", "noinline">,
+   CXX11<"msvc", "noinline">, C23<"msvc", "noinline">,
Declspec<"noinline">];
   let Accessors = [Accessor<"isClangNoInline", [CXX11<"clang", "noinline">,
-C23<"clang", "noinline">]>];
+C23<"clang", "noinline">,
+CXX11<"msvc", "noinline">,
+C23<"msvc", "noinline">]>];
   let Documentation = [NoInlineDocs];
   let Subjects = SubjectList<[Function, Stmt], WarnDiag,
  "functions and statements">;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index b48aaf65558ac..7442f7e828462 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -597,6 +597,8 @@ spellings of the attribute are not supported on statements. 
If a statement is
 marked ``[[clang::noinline]]`` and contains calls, those calls inside the
 statement will not be inlined by the compiler.
 
+``[[msvc::noinline]]`` 
+
 ``__noinline__`` can be used as a keyword in CUDA/HIP languages. This is to
 avoid diagnostics due to usage of ``__attribute__((__noinline__))``
 with ``__noinline__`` defined as a macro as ``__attribute__((noinline))``.
diff --git a/clang/test/CodeGen/attr-ms-noinline.cpp 
b/clang/test/CodeGen/attr-ms-noinline.cpp
new file mode 100644
index 0..e69de29bb2d1d
diff --git a/clang/test/Sema/attr-ms-noinline.cpp 
b/clang/test/Sema/attr-ms-noinline.cpp
new file mode 100644
index 0..e69de29bb2d1d

>From bbc27cb48f616a98d4d379b8ac72e0c408c8ca64 Mon Sep 17 00:00:00 2001
From: Xu Zhang 
Date: Fri, 10 May 2024 17:46:40 +0800
Subject: [PATCH 2/5] add unit test

---
 clang/include/clang/Basic/AttrDocs.td   |  2 -
 clang/test/CodeGen/attr-ms-noinline.cpp | 53 
 clang/test/Sema/attr-ms-noinline.cpp| 66 +
 3 files changed, 119 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 7442f7e828462..b48aaf65558ac 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -597,8 +597,6 @@ spellings of the attribute are not supported on statements. 
If a statement is
 marked ``[[clang::noinline]]`` and contains calls, those calls inside the
 statement will not be inlined by the compiler.
 
-``[[msvc::noinline]]`` 
-
 ``__noinline__`` can be used as a keyword in CUDA/HIP languages. This is to
 avoid diagnostics due to usage of ``__attribute__((__noinline__))``
 with ``__noinline__`` defined as a macro as ``__attribute__((noinline))``.
diff --git a/clang/test/CodeGen/attr-ms-noinline.cpp 
b/clang/test/CodeGen/attr-ms-noinline.cpp
index e69de29bb2d1d..99b0a05af715d 100644
--- a/clang/test/CodeGen/attr-ms-noinline.cpp
+++ b/clang/test/CodeGen/attr-ms-noinline.cpp
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -emit-llvm %s -triple x86_64-unknown-linux-gnu -o - | 
FileCheck %s
+
+bool bar();
+void f(bool, bool);
+void g(bool);
+
+static int baz(int x) {
+return x * 10;
+}
+
+[[msvc::noinline]] bool noi() { }
+
+void foo(int i) {
+  [[msvc::noinline]] bar();
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR:[0-9]+]]
+  [[msvc::noinline]] i = baz(i);
+// CHECK: call noundef i32 @_ZL3bazi({{.*}}) #[[NOINLINEATTR]]
+  [[msvc::noinline]] (i = 4, bar());
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]]
+  [[msvc::noinline]] (void)(bar());
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]]
+  [[msvc::noinline]] f(bar(), bar());
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]]
+// CHECK: call noundef zeroext i1 @_Z3barv() #[[NOINLINEATTR]]
+// CHECK: call void @_Z1fbb({{.*}}) #[[NOINLINEATTR]]
+  [[msvc::noinline]] [] { bar(); b

[clang] [Clang] Add support for [[msvc::noinline]] attribute. (PR #91720)

2024-05-21 Thread Xu Zhang via cfe-commits

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


[clang] d9c27ca - [clang][Interp] Fix discarding construct exprs with zero initializers

2024-05-21 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-05-21T12:51:30+02:00
New Revision: d9c27cafdb1c16fff837a3eb0ec0fb2ad912bc50

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

LOG: [clang][Interp] Fix discarding construct exprs with zero initializers

We need to create the temporary earlier so the
visitZeroRecordInitializer() call has access to it.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 640311e1444bf..a61270c77ea8f 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2088,6 +2088,21 @@ bool ByteCodeExprGen::VisitCXXConstructExpr(
   if (T->isRecordType()) {
 const CXXConstructorDecl *Ctor = E->getConstructor();
 
+// If we're discarding a construct expression, we still need
+// to allocate a variable and call the constructor and destructor.
+if (DiscardResult) {
+  if (Ctor->isTrivial())
+return true;
+  assert(!Initializing);
+  std::optional LocalIndex = allocateLocal(E);
+
+  if (!LocalIndex)
+return false;
+
+  if (!this->emitGetPtrLocal(*LocalIndex, E))
+return false;
+}
+
 // Zero initialization.
 if (E->requiresZeroInitialization()) {
   const Record *R = getRecord(E->getType());
@@ -2108,19 +2123,6 @@ bool ByteCodeExprGen::VisitCXXConstructExpr(
 assert(Func->hasThisPointer());
 assert(!Func->hasRVO());
 
-// If we're discarding a construct expression, we still need
-// to allocate a variable and call the constructor and destructor.
-if (DiscardResult) {
-  assert(!Initializing);
-  std::optional LocalIndex = allocateLocal(E);
-
-  if (!LocalIndex)
-return false;
-
-  if (!this->emitGetPtrLocal(*LocalIndex, E))
-return false;
-}
-
 //  The This pointer is already on the stack because this is an 
initializer,
 //  but we need to dup() so the call() below has its own copy.
 if (!this->emitDupPtr(E))

diff  --git a/clang/test/AST/Interp/records.cpp 
b/clang/test/AST/Interp/records.cpp
index 41be9b71a27f9..3a5ecd291a568 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -1459,3 +1459,13 @@ namespace TemporaryWithInvalidDestructor {
 // both-note {{in call to}}
 #endif
 }
+
+namespace IgnoredCtorWithZeroInit {
+  struct S {
+int a;
+  };
+
+  bool get_status() {
+return (S(), true);
+  }
+}



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


[clang-tools-extra] [clangd] Reduce instantiation depth in `infinite-instantiations.test` (PR #92888)

2024-05-21 Thread Vlad Serebrennikov via cfe-commits

Endilll wrote:

Linux CI passed, so I'm merging this.

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


[clang-tools-extra] b7d911b - [clangd] Reduce instantiation depth in `infinite-instantiations.test` (#92888)

2024-05-21 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-05-21T14:56:25+04:00
New Revision: b7d911b76a6c44a3fcec56dd7e5fde9fbe63f4fe

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

LOG: [clangd] Reduce instantiation depth in `infinite-instantiations.test` 
(#92888)

This patch reduces template instantiation depth in
`infinite-instantiations.test`, because it doesn't seem to be concerned
with the default instantiation depth in particular, but has a very
material impact on testing times of clangd. Which subsequently affects
CI run times for all Clang changes.

The following numbers are taken from
https://buildkite.com/llvm-project/github-pull-requests/builds/65299,
but they are the same for any CI run with clangd:
Linux:
```
Slowest Tests:
--
35.19s: Clangd :: infinite-instantiation.test
5.53s: Clangd :: protocol.test
1.48s: Clang Tools :: clang-tidy/checkers/modernize/use-emplace.cpp
1.40s: Clang Tools :: 
clang-tidy/checkers/misc/non-private-member-variables-in-classes.cpp
1.17s: Clang Tools :: clang-tidy/checkers/google/upgrade-googletest-case.cpp
1.15s: Clang Tools :: clang-tidy/checkers/bugprone/unsafe-functions.c
1.10s: Clang Tools :: clang-tidy/infrastructure/check_clang_tidy.cpp
1.07s: Clang Tools :: clang-tidy/checkers/readability/redundant-casting.cpp
1.06s: Clang Tools :: clang-tidy/checkers/misc/const-correctness-values.cpp
1.02s: Clang Tools :: 
clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-char.cpp
1.00s: Clang Tools :: clang-tidy/checkers/modernize/loop-convert-reverse.cpp
0.97s: Clang Tools :: clang-tidy/checkers/modernize/loop-convert-basic.cpp
0.95s: Clang Tools :: clang-tidy/checkers/modernize/use-std-print.cpp
0.93s: Clang Tools :: clang-tidy/checkers/modernize/loop-convert-extra.cpp
0.92s: Clang Tools :: clang-tidy/checkers/altera/single-work-item-barrier.cpp
0.90s: Clang Tools :: 
clang-tidy/checkers/readability/identifier-naming-hungarian-notation-lower-case-prefix.cpp
0.90s: Clang Tools :: 
clang-tidy/checkers/modernize/use-auto-min-type-name-length.cpp
0.89s: Clang Tools :: 
clang-tidy/checkers/readability/identifier-naming-hungarian-notation-cfgfile.cpp
0.88s: Clang Tools :: 
clang-tidy/checkers/readability/identifier-naming-hungarian-notation.cpp
0.85s: Clangd Unit Tests :: ./ClangdTests/Hover/All
```
Windows:
```
Slowest Tests:
--
244.74s: Clangd :: infinite-instantiation.test
11.42s: Clangd :: protocol.test
8.97s: Clang Tools :: 
clang-tidy/checkers/misc/non-private-member-variables-in-classes.cpp
7.44s: Clang Tools :: clang-tidy/checkers/altera/single-work-item-barrier.cpp
6.71s: Clang Tools :: clang-tidy/checkers/bugprone/unsafe-functions.c
6.61s: Clang Tools :: 
clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-char.cpp
6.42s: Clang Tools :: clang-tidy/infrastructure/check_clang_tidy.cpp
6.32s: Clang Tools :: clang-tidy/checkers/modernize/loop-convert-reverse.cpp
6.01s: Clang Tools :: clang-tidy/checkers/readability/redundant-casting.cpp
5.62s: Clang Tools :: 
clang-tidy/checkers/modernize/use-auto-min-type-name-length.cpp
5.58s: Clang Tools :: 
clang-tidy/checkers/modernize/replace-disallow-copy-and-assign-macro.cpp
5.46s: Clang Tools :: 
clang-tidy/checkers/readability/function-cognitive-complexity-flags.cpp
5.08s: Clang Tools :: 
clang-tidy/checkers/readability/avoid-return-with-void-value.cpp
5.07s: Clang Tools :: clang-tidy/checkers/readability/redundant-declaration.cpp
4.99s: Clang Tools :: 
clang-tidy/checkers/readability/identifier-naming-hungarian-notation-lower-case-prefix.cpp
4.91s: Clang Tools :: 
clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-pointer-offset.cpp
4.87s: Clang Tools :: 
clang-tidy/checkers/readability/identifier-naming-hungarian-notation-cfgfile.cpp
4.79s: Clang Tools :: clang-tidy/checkers/google/upgrade-googletest-case.cpp
4.78s: Clang Tools :: clang-tidy/infrastructure/clean-up-code.cpp
4.76s: Clang Tools :: 
clang-tidy/checkers/bugprone/implicit-widening-of-multiplication-result-int.cpp
```

Added: 


Modified: 
clang-tools-extra/clangd/test/infinite-instantiation.test

Removed: 




diff  --git a/clang-tools-extra/clangd/test/infinite-instantiation.test 
b/clang-tools-extra/clangd/test/infinite-instantiation.test
index 85a1b656f4908..98260c075d240 100644
--- a/clang-tools-extra/clangd/test/infinite-instantiation.test
+++ b/clang-tools-extra/clangd/test/infinite-instantiation.test
@@ -1,5 +1,6 @@
-// RUN: cp %s %t.cpp
-// RUN: not clangd -check=%t.cpp 2>&1 | FileCheck -strict-whitespace %s
+// RUN: rm -rf %t.dir && mkdir -p %t.dir
+// RUN: echo '[{"directory": "%/t.dir", "command": "clang -ftemplate-depth=100 
-x c++ %s",

[clang-tools-extra] [clangd] Reduce instantiation depth in `infinite-instantiations.test` (PR #92888)

2024-05-21 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll closed 
https://github.com/llvm/llvm-project/pull/92888
___
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 modernize-use-std-format check (PR #90397)

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

kadircet wrote:

hi! this seems to be crashing for certain code patterns, 
https://github.com/llvm/llvm-project/issues/92896 has a minimal reproducer

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


[clang] a7521fd - [clang][Interp] Implement __builtin_sycl_unique_stable_name

2024-05-21 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-05-21T13:20:42+02:00
New Revision: a7521fd162cac93da37df9151d233692fd61998f

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

LOG: [clang][Interp] Implement __builtin_sycl_unique_stable_name

Added: 
clang/test/AST/Interp/sycl.cpp

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

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index a61270c77ea8f..33d69d04487de 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1594,6 +1594,30 @@ bool ByteCodeExprGen::VisitStringLiteral(const 
StringLiteral *E) {
   return true;
 }
 
+template 
+bool ByteCodeExprGen::VisitSYCLUniqueStableNameExpr(
+const SYCLUniqueStableNameExpr *E) {
+  if (DiscardResult)
+return true;
+
+  assert(!Initializing);
+
+  auto &A = Ctx.getASTContext();
+  std::string ResultStr = E->ComputeName(A);
+
+  QualType CharTy = A.CharTy.withConst();
+  APInt Size(A.getTypeSize(A.getSizeType()), ResultStr.size() + 1);
+  QualType ArrayTy = A.getConstantArrayType(CharTy, Size, nullptr,
+ArraySizeModifier::Normal, 0);
+
+  StringLiteral *SL =
+  StringLiteral::Create(A, ResultStr, StringLiteralKind::Ordinary,
+/*Pascal=*/false, ArrayTy, E->getLocation());
+
+  unsigned StringIndex = P.createGlobalString(SL);
+  return this->emitGetPtrGlobal(StringIndex, E);
+}
+
 template 
 bool ByteCodeExprGen::VisitCharacterLiteral(
 const CharacterLiteral *E) {

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index e73a2f0334cf6..a2e283c866332 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -90,6 +90,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitOpaqueValueExpr(const OpaqueValueExpr *E);
   bool VisitAbstractConditionalOperator(const AbstractConditionalOperator *E);
   bool VisitStringLiteral(const StringLiteral *E);
+  bool VisitSYCLUniqueStableNameExpr(const SYCLUniqueStableNameExpr *E);
   bool VisitCharacterLiteral(const CharacterLiteral *E);
   bool VisitCompoundAssignOperator(const CompoundAssignOperator *E);
   bool VisitFloatCompoundAssignOperator(const CompoundAssignOperator *E);

diff  --git a/clang/test/AST/Interp/sycl.cpp b/clang/test/AST/Interp/sycl.cpp
new file mode 100644
index 0..5c922eca58091
--- /dev/null
+++ b/clang/test/AST/Interp/sycl.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -std=c++17 -triple x86_64-linux-gnu -fsycl-is-device 
-verify=both,ref -fsyntax-only -Wno-unused
+// RUN: %clang_cc1 %s -std=c++17 -triple x86_64-linux-gnu -fsycl-is-device 
-verify=both,expected -fsyntax-only -Wno-unused 
-fexperimental-new-constant-interpreter
+
+// both-no-diagnostics
+
+constexpr int a = 0;
+constexpr const char *a_name = __builtin_sycl_unique_stable_name(decltype(a));
+static_assert(__builtin_strcmp(a_name, "_ZTSKi") == 0);
+



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


[clang] [llvm] [AArch64] Fix feature flags dependecies (PR #90612)

2024-05-21 Thread via cfe-commits

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

>From a68d74949438f486f8443c1a4cb5727d769dde31 Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Fri, 26 Apr 2024 09:58:44 +
Subject: [PATCH 1/4] [AArch64] Fix feature flags dependecies

---
 clang/test/Driver/aarch64-v95a.c  |   8 +
 .../llvm/TargetParser/AArch64TargetParser.h   |  32 ++--
 llvm/lib/Target/AArch64/AArch64Features.td|  40 +++--
 llvm/lib/Target/AArch64/AArch64InstrInfo.td   |   2 -
 .../Target/AArch64/AArch64SystemOperands.td   |   4 +-
 .../AArch64/AsmParser/AArch64AsmParser.cpp|   3 +-
 llvm/test/MC/AArch64/FP8/system-regs.s|  21 +--
 .../TargetParser/TargetParserTest.cpp | 155 +++---
 8 files changed, 152 insertions(+), 113 deletions(-)

diff --git a/clang/test/Driver/aarch64-v95a.c b/clang/test/Driver/aarch64-v95a.c
index 1037da65c8cb5..538ff0876090b 100644
--- a/clang/test/Driver/aarch64-v95a.c
+++ b/clang/test/Driver/aarch64-v95a.c
@@ -22,6 +22,14 @@
 // RUN: %clang -target aarch64 -march=armv9.5-a+cpa -### -c %s 2>&1 | 
FileCheck -check-prefix=V95A-CPA %s
 // V95A-CPA: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" 
"-target-feature" "+v9.5a"{{.*}} "-target-feature" "+cpa"
 
+// RUN: %clang -target aarch64 -march=armv9.5a+cpa -### -c %s 2>&1 | FileCheck 
-check-prefix=V95A-LUT %s
+// RUN: %clang -target aarch64 -march=armv9.5-a+cpa -### -c %s 2>&1 | 
FileCheck -check-prefix=V95A-LUT %s
+// V95A-LUT: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" 
"-target-feature" "+v9.5a"{{.*}} "-target-feature" "+lut"
+
+// RUN: %clang -target aarch64 -march=armv9.5a+cpa -### -c %s 2>&1 | FileCheck 
-check-prefix=V95A-FAMINMAX %s
+// RUN: %clang -target aarch64 -march=armv9.5-a+cpa -### -c %s 2>&1 | 
FileCheck -check-prefix=V95A-FAMINMAX %s
+// V95A-FAMINMAX: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"generic" "-target-feature" "+v9.5a"{{.*}} "-target-feature" "+faminmax"
+
 // RUN: %clang -target aarch64 -march=armv9.5a+pauth-lr -### -c %s 2>&1 | 
FileCheck -check-prefix=V95A-PAUTHLR %s
 // RUN: %clang -target aarch64 -march=armv9.5-a+pauth-lr -### -c %s 2>&1 | 
FileCheck -check-prefix=V95A-PAUTHLR %s
 // V95A-PAUTHLR: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"generic" "-target-feature" "+v9.5a"{{.*}} "-target-feature" "+pauth-lr"
diff --git a/llvm/include/llvm/TargetParser/AArch64TargetParser.h 
b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
index 805b963a7a13c..b0df70f5343a5 100644
--- a/llvm/include/llvm/TargetParser/AArch64TargetParser.h
+++ b/llvm/include/llvm/TargetParser/AArch64TargetParser.h
@@ -164,7 +164,6 @@ enum ArchExtKind : unsigned {
   AEK_RASv2 = 55, // FEAT_RASv2
   AEK_ITE =   56, // FEAT_ITE
   AEK_GCS =   57, // FEAT_GCS
-  AEK_FPMR =  58, // FEAT_FPMR
   AEK_FP8 =   59, // FEAT_FP8
   AEK_FAMINMAX =  60, // FEAT_FAMINMAX
   AEK_FP8FMA =61, // FEAT_FP8FMA
@@ -291,18 +290,17 @@ inline constexpr ExtensionInfo Extensions[] = {
 {"tme", AArch64::AEK_TME, "+tme", "-tme", FEAT_INIT, "", 0},
 {"wfxt", AArch64::AEK_NONE, {}, {}, FEAT_WFXT, "+wfxt", 550},
 {"gcs", AArch64::AEK_GCS, "+gcs", "-gcs", FEAT_INIT, "", 0},
-{"fpmr", AArch64::AEK_FPMR, "+fpmr", "-fpmr", FEAT_INIT, "", 0},
-{"fp8", AArch64::AEK_FP8, "+fp8", "-fp8", FEAT_INIT, "+fpmr", 0},
+{"fp8", AArch64::AEK_FP8, "+fp8", "-fp8", FEAT_INIT, "+faminmax, +lut, 
+bf16", 0},
 {"faminmax", AArch64::AEK_FAMINMAX, "+faminmax", "-faminmax", FEAT_INIT, 
"", 0},
-{"fp8fma", AArch64::AEK_FP8FMA, "+fp8fma", "-fp8fma", FEAT_INIT, "+fpmr", 
0},
-{"ssve-fp8fma", AArch64::AEK_SSVE_FP8FMA, "+ssve-fp8fma", "-ssve-fp8fma", 
FEAT_INIT, "+sme2", 0},
-{"fp8dot2", AArch64::AEK_FP8DOT2, "+fp8dot2", "-fp8dot2", FEAT_INIT, "", 
0},
-{"ssve-fp8dot2", AArch64::AEK_SSVE_FP8DOT2, "+ssve-fp8dot2", 
"-ssve-fp8dot2", FEAT_INIT, "+sme2", 0},
-{"fp8dot4", AArch64::AEK_FP8DOT4, "+fp8dot4", "-fp8dot4", FEAT_INIT, "", 
0},
-{"ssve-fp8dot4", AArch64::AEK_SSVE_FP8DOT4, "+ssve-fp8dot4", 
"-ssve-fp8dot4", FEAT_INIT, "+sme2", 0},
+{"fp8fma", AArch64::AEK_FP8FMA, "+fp8fma", "-fp8fma", FEAT_INIT, "+fp8", 
0},
+{"ssve-fp8fma", AArch64::AEK_SSVE_FP8FMA, "+ssve-fp8fma", "-ssve-fp8fma", 
FEAT_INIT, "+sme2,+fp8", 0},
+{"fp8dot2", AArch64::AEK_FP8DOT2, "+fp8dot2", "-fp8dot2", FEAT_INIT, 
"+fp8dot4", 0},
+{"ssve-fp8dot2", AArch64::AEK_SSVE_FP8DOT2, "+ssve-fp8dot2", 
"-ssve-fp8dot2", FEAT_INIT, "+ssve-fp8dot4", 0},
+{"fp8dot4", AArch64::AEK_FP8DOT4, "+fp8dot4", "-fp8dot4", FEAT_INIT, 
"+fp8fma", 0},
+{"ssve-fp8dot4", AArch64::AEK_SSVE_FP8DOT4, "+ssve-fp8dot4", 
"-ssve-fp8dot4", FEAT_INIT, "+ssve-fp8fma", 0},
 {"lut", AArch64::AEK_LUT, "+lut", "-lut", FEAT_INIT, "", 0},
 {"sme-lutv2", AArch64::AEK_SME_LUTv2, "+sme-lutv2", "-sme-lutv2", 
FEAT_INIT, "", 0},
-{"sme-f8f16", AArch64::AEK_SMEF8F16, "+sme-f8f16", "-sme-f8f16", 
FEAT_INIT, "+sme2,+f

[clang] 18e7bcb - [clang][Interp] Reject inc/dec ops before C++ 14

2024-05-21 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-05-21T13:20:42+02:00
New Revision: 18e7bcbae12bc2e2cf944a0b3f12075f508c

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

LOG: [clang][Interp] Reject inc/dec ops before C++ 14

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/cxx11.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 33d69d04487de..859a3fabea32b 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -3395,6 +3395,9 @@ bool ByteCodeExprGen::VisitUnaryOperator(const 
UnaryOperator *E) {
 
   switch (E->getOpcode()) {
   case UO_PostInc: { // x++
+if (!Ctx.getLangOpts().CPlusPlus14)
+  return this->emitInvalid(E);
+
 if (!this->visit(SubExpr))
   return false;
 
@@ -3413,6 +3416,9 @@ bool ByteCodeExprGen::VisitUnaryOperator(const 
UnaryOperator *E) {
 return DiscardResult ? this->emitIncPop(*T, E) : this->emitInc(*T, E);
   }
   case UO_PostDec: { // x--
+if (!Ctx.getLangOpts().CPlusPlus14)
+  return this->emitInvalid(E);
+
 if (!this->visit(SubExpr))
   return false;
 
@@ -3431,6 +3437,9 @@ bool ByteCodeExprGen::VisitUnaryOperator(const 
UnaryOperator *E) {
 return DiscardResult ? this->emitDecPop(*T, E) : this->emitDec(*T, E);
   }
   case UO_PreInc: { // ++x
+if (!Ctx.getLangOpts().CPlusPlus14)
+  return this->emitInvalid(E);
+
 if (!this->visit(SubExpr))
   return false;
 
@@ -3475,6 +3484,9 @@ bool ByteCodeExprGen::VisitUnaryOperator(const 
UnaryOperator *E) {
 return E->isGLValue() || this->emitLoadPop(*T, E);
   }
   case UO_PreDec: { // --x
+if (!Ctx.getLangOpts().CPlusPlus14)
+  return this->emitInvalid(E);
+
 if (!this->visit(SubExpr))
   return false;
 

diff  --git a/clang/test/AST/Interp/cxx11.cpp b/clang/test/AST/Interp/cxx11.cpp
index 993e3618a3784..f06a5dd173cba 100644
--- a/clang/test/AST/Interp/cxx11.cpp
+++ b/clang/test/AST/Interp/cxx11.cpp
@@ -30,3 +30,19 @@ constexpr S s = { 5 };
 constexpr const int *p = &s.m + 1;
 
 constexpr const int *np2 = &(*(int(*)[4])nullptr)[0]; // ok
+
+constexpr int preDec(int x) { // both-error {{never produces a constant 
expression}}
+  return --x; // both-note {{subexpression}}
+}
+
+constexpr int postDec(int x) { // both-error {{never produces a constant 
expression}}
+  return x--;  // both-note {{subexpression}}
+}
+
+constexpr int preInc(int x) { // both-error {{never produces a constant 
expression}}
+  return ++x;  // both-note {{subexpression}}
+}
+
+constexpr int postInc(int x) { // both-error {{never produces a constant 
expression}}
+  return x++;  // both-note {{subexpression}}
+}



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


[clang] [llvm] [AArch64] Fix feature flags dependecies (PR #90612)

2024-05-21 Thread via cfe-commits

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

>From 2f8d7a5898697529d07bef72181510af105327e9 Mon Sep 17 00:00:00 2001
From: Marian Lukac 
Date: Tue, 21 May 2024 11:21:18 +
Subject: [PATCH] [AArch64] Fix feature flags dependecies

---
 clang/test/Driver/aarch64-v95a.c  |  8 +---
 llvm/lib/Target/AArch64/AArch64Features.td| 46 +--
 llvm/lib/Target/AArch64/AArch64InstrInfo.td   |  2 -
 .../Target/AArch64/AArch64SystemOperands.td   |  2 -
 .../AArch64/AsmParser/AArch64AsmParser.cpp|  3 +-
 llvm/test/MC/AArch64/FP8/system-regs.s| 22 -
 .../TargetParser/TargetParserTest.cpp |  6 +--
 7 files changed, 35 insertions(+), 54 deletions(-)

diff --git a/clang/test/Driver/aarch64-v95a.c b/clang/test/Driver/aarch64-v95a.c
index 1037da65c8cb5..62878f2127626 100644
--- a/clang/test/Driver/aarch64-v95a.c
+++ b/clang/test/Driver/aarch64-v95a.c
@@ -6,7 +6,7 @@
 // RUN: %clang -target aarch64 -mlittle-endian -march=armv9.5-a -### -c %s 
2>&1 | FileCheck -check-prefix=GENERICV95A %s
 // RUN: %clang -target aarch64_be -mlittle-endian -march=armv9.5a -### -c %s 
2>&1 | FileCheck -check-prefix=GENERICV95A %s
 // RUN: %clang -target aarch64_be -mlittle-endian -march=armv9.5-a -### -c %s 
2>&1 | FileCheck -check-prefix=GENERICV95A %s
-// GENERICV95A: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" 
"-target-feature" "+v9.5a"
+// GENERICV95A: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" 
"-target-feature" "+v9.5a"{{.*}}  "-target-feature" "+cpa"{{.*}} 
"-target-feature" "+faminmax"{{.*}}  "-target-feature" "+lut"
 
 // RUN: %clang -target aarch64_be -march=armv9.5a -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERICV95A-BE %s
 // RUN: %clang -target aarch64_be -march=armv9.5-a -### -c %s 2>&1 | FileCheck 
-check-prefix=GENERICV95A-BE %s
@@ -14,14 +14,10 @@
 // RUN: %clang -target aarch64 -mbig-endian -march=armv9.5-a -### -c %s 2>&1 | 
FileCheck -check-prefix=GENERICV95A-BE %s
 // RUN: %clang -target aarch64_be -mbig-endian -march=armv9.5a -### -c %s 2>&1 
| FileCheck -check-prefix=GENERICV95A-BE %s
 // RUN: %clang -target aarch64_be -mbig-endian -march=armv9.5-a -### -c %s 
2>&1 | FileCheck -check-prefix=GENERICV95A-BE %s
-// GENERICV95A-BE: "-cc1"{{.*}} "-triple" "aarch64_be{{.*}}" "-target-cpu" 
"generic" "-target-feature" "+v9.5a"
+// GENERICV95A-BE: "-cc1"{{.*}} "-triple" "aarch64_be{{.*}}" "-target-cpu" 
"generic" "-target-feature" "+v9.5a"{{.*}}  "-target-feature" "+cpa"{{.*}} 
"-target-feature" "+faminmax"{{.*}}  "-target-feature" "+lut"
 
 // = Features supported on aarch64 =
 
-// RUN: %clang -target aarch64 -march=armv9.5a+cpa -### -c %s 2>&1 | FileCheck 
-check-prefix=V95A-CPA %s
-// RUN: %clang -target aarch64 -march=armv9.5-a+cpa -### -c %s 2>&1 | 
FileCheck -check-prefix=V95A-CPA %s
-// V95A-CPA: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" "generic" 
"-target-feature" "+v9.5a"{{.*}} "-target-feature" "+cpa"
-
 // RUN: %clang -target aarch64 -march=armv9.5a+pauth-lr -### -c %s 2>&1 | 
FileCheck -check-prefix=V95A-PAUTHLR %s
 // RUN: %clang -target aarch64 -march=armv9.5-a+pauth-lr -### -c %s 2>&1 | 
FileCheck -check-prefix=V95A-PAUTHLR %s
 // V95A-PAUTHLR: "-cc1"{{.*}} "-triple" "aarch64{{.*}}" "-target-cpu" 
"generic" "-target-feature" "+v9.5a"{{.*}} "-target-feature" "+pauth-lr"
diff --git a/llvm/lib/Target/AArch64/AArch64Features.td 
b/llvm/lib/Target/AArch64/AArch64Features.td
index ba0b760ce3d73..ffb899a301459 100644
--- a/llvm/lib/Target/AArch64/AArch64Features.td
+++ b/llvm/lib/Target/AArch64/AArch64Features.td
@@ -223,13 +223,6 @@ def FeatureSVE : Extension<"sve", "SVE",
   "Enable Scalable Vector Extension (SVE) instructions (FEAT_SVE)", 
[FeatureFullFP16],
   "FEAT_SVE", "+sve,+fullfp16,+fp-armv8,+neon", 310>;
 
-def FeatureFPMR : Extension<"fpmr", "FPMR",
-  "Enable FPMR Register (FEAT_FPMR)">;
-
-let FMVDependencies = "+fpmr" in
-def FeatureFP8 : Extension<"fp8", "FP8",
-  "Enable FP8 instructions (FEAT_FP8)">;
-
 // This flag is currently still labeled as Experimental, but when fully
 // implemented this should tell the compiler to use the zeroing pseudos to
 // benefit from the reverse instructions (e.g. SUB vs SUBR) if the inactive
@@ -667,41 +660,44 @@ def FeatureSME2p1 : Extension<"sme2p1", "SME2p1",
 def FeatureFAMINMAX: Extension<"faminmax", "FAMINMAX",
"Enable FAMIN and FAMAX instructions (FEAT_FAMINMAX)">;
 
-let FMVDependencies = "+fpmr" in
+def FeatureLUT: Extension<"lut", "LUT",
+   "Enable Lookup Table instructions (FEAT_LUT)">;
+   
+def FeatureFP8 : Extension<"fp8", "FP8",
+  "Enable FP8 instructions (FEAT_FP8)", [FeatureFAMINMAX, FeatureLUT, 
FeatureBF16]>;
+  
 def FeatureFP8FMA : Extension<"fp8fma", "FP8FMA",
-  "Enable fp8 multiply-add instructions (FEAT_FP8FMA)">;
+  "Enable fp8 multiply-add instructions (FEAT_FP8FMA)", [FeatureFP8]>;
 
 let FMVDependencies = "+sme2" in
 def FeatureSSVE_FP8FMA : Extension<"ssve-fp8fma", "SSVE_FP8FMA"

[clang] [llvm] [AArch64] Fix feature flags dependecies (PR #90612)

2024-05-21 Thread via cfe-commits


@@ -1942,12 +1942,10 @@ def : RWSysReg<"PM",0b11, 0b000, 
0b0100, 0b0011, 0b001>;
 
 // 2023 ISA Extension
 // AArch64 Floating-point Mode Register controls behaviors of the FP8
-// instructions (FEAT_FPMR)

Lukacma wrote:

Done

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


[clang] [llvm] [AArch64] Fix feature flags dependecies (PR #90612)

2024-05-21 Thread via cfe-commits


@@ -1996,7 +1996,6 @@ TEST(TargetParserTest, AArch64ExtensionFeatures) {
   AArch64::AEK_D128, AArch64::AEK_LSE128,
   AArch64::AEK_SPECRES2, AArch64::AEK_RASv2,
   AArch64::AEK_ITE,  AArch64::AEK_GCS,
-  AArch64::AEK_FPMR, AArch64::AEK_FP8,

Lukacma wrote:

Fixed

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


[clang] [clang-tools-extra] [llvm] [polly] [test]: fix filecheck annotation typos (PR #91854)

2024-05-21 Thread via cfe-commits

klensy wrote:

Moved mlir fixes to https://github.com/llvm/llvm-project/pull/92897

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


[clang] [Clang] Add support for [[msvc::noinline]] attribute. (PR #91720)

2024-05-21 Thread Xu Zhang via cfe-commits

simonzgx wrote:

> You seem to have lost the tests in the latest version of this commit.

Have already added.

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


[clang] 46d8bb0 - [clang][Interp] Fix initializing zero-size arrays

2024-05-21 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-05-21T13:46:36+02:00
New Revision: 46d8bb08cfd3798977b4e22881514dc9d77425c2

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

LOG: [clang][Interp] Fix initializing zero-size arrays

Added: 


Modified: 
clang/lib/AST/Interp/Pointer.h
clang/test/AST/Interp/arrays.cpp
clang/unittests/AST/Interp/Descriptor.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Pointer.h b/clang/lib/AST/Interp/Pointer.h
index 9900f37e60d4e..3ade5756e580e 100644
--- a/clang/lib/AST/Interp/Pointer.h
+++ b/clang/lib/AST/Interp/Pointer.h
@@ -556,12 +556,16 @@ class Pointer {
 if (!asBlockPointer().Pointee)
   return false;
 
-return isElementPastEnd() || getSize() == getOffset();
+return isElementPastEnd() ||
+   (getSize() == getOffset() && !isZeroSizeArray());
   }
 
   /// Checks if the pointer is an out-of-bounds element pointer.
   bool isElementPastEnd() const { return Offset == PastEndMark; }
 
+  /// Checks if the pointer is pointing to a zero-size array.
+  bool isZeroSizeArray() const { return getFieldDesc()->isZeroSizeArray(); }
+
   /// Dereferences the pointer, if it's live.
   template  T &deref() const {
 assert(isLive() && "Invalid pointer");

diff  --git a/clang/test/AST/Interp/arrays.cpp 
b/clang/test/AST/Interp/arrays.cpp
index 71b6dabf39e45..e936ec6dc894b 100644
--- a/clang/test/AST/Interp/arrays.cpp
+++ b/clang/test/AST/Interp/arrays.cpp
@@ -26,6 +26,7 @@ static_assert(foo[2][2] == nullptr, "");
 static_assert(foo[2][3] == &m, "");
 static_assert(foo[2][4] == nullptr, "");
 
+constexpr int ZeroSizeArray[] = {};
 
 constexpr int SomeInt[] = {1};
 constexpr int getSomeInt() { return *SomeInt; }

diff  --git a/clang/unittests/AST/Interp/Descriptor.cpp 
b/clang/unittests/AST/Interp/Descriptor.cpp
index 053d579ea3919..3157b4d401f98 100644
--- a/clang/unittests/AST/Interp/Descriptor.cpp
+++ b/clang/unittests/AST/Interp/Descriptor.cpp
@@ -22,9 +22,10 @@ TEST(Descriptor, Primitives) {
   "  char s[4];\n"
   "  A a[3];\n"
   "  short l[3][3];\n"
+  "  int EmptyA[0];\n"
   "};\n"
   "constexpr S d = {0.0, \"foo\", {{true, false}, {false, true}, {false, 
false}},\n"
-  "  {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}};\n";
+  "  {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, {}};\n";
 
   auto AST = tooling::buildASTFromCodeWithArgs(
   Code, {"-fexperimental-new-constant-interpreter"});
@@ -64,7 +65,7 @@ TEST(Descriptor, Primitives) {
   // Test the Record for the struct S.
   const Record *SRecord = GlobalDesc->ElemRecord;
   ASSERT_TRUE(SRecord);
-  ASSERT_TRUE(SRecord->getNumFields() == 4);
+  ASSERT_TRUE(SRecord->getNumFields() == 5);
   ASSERT_TRUE(SRecord->getNumBases() == 0);
   ASSERT_FALSE(SRecord->getDestructor());
 
@@ -113,6 +114,16 @@ TEST(Descriptor, Primitives) {
   ASSERT_TRUE(F4->Desc->getElemSize() > 0);
   ASSERT_TRUE(F4->Desc->ElemDesc->isPrimitiveArray());
 
+  // Fifth field. Zero-size array.
+  const Record::Field *F5 = SRecord->getField(4u);
+  ASSERT_TRUE(F5);
+  ASSERT_FALSE(F5->isBitField());
+  ASSERT_TRUE(F5->Desc->isArray());
+  ASSERT_FALSE(F5->Desc->isCompositeArray());
+  ASSERT_TRUE(F5->Desc->isPrimitiveArray());
+  ASSERT_FALSE(F5->Desc->isPrimitive());
+  ASSERT_EQ(F5->Desc->getNumElems(), 0u);
+
   // Check pointer stuff.
   // Global variables have an inline descriptor.
   ASSERT_TRUE(GlobalPtr.isRoot());
@@ -382,4 +393,13 @@ TEST(Descriptor, Primitives) {
 ASSERT_EQ(PE3.getArray(), NE3);
 ASSERT_EQ(PE3.getIndex(), 2u);
   }
+
+  // Zero-size array.
+  {
+const Pointer &PF5 = GlobalPtr.atField(F5->Offset);
+
+ASSERT_TRUE(PF5.isZeroSizeArray());
+ASSERT_FALSE(PF5.isOnePastEnd());
+ASSERT_FALSE(PF5.isElementPastEnd());
+  }
 }



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


[clang] [DebugInfo] Add flag to only emit referenced member functions (PR #87018)

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


@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -debug-info-kind=limited -gomit-unreferenced-members %s 
-emit-llvm -o - | FileCheck %s

SLTozer wrote:

Test needs renaming for the different flag name?

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


[clang] [DebugInfo] Add flag to only emit referenced member functions (PR #87018)

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

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


[clang] [DebugInfo] Add flag to only emit referenced member functions (PR #87018)

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


@@ -2755,7 +2755,7 @@ CGDebugInfo::CreateTypeDefinition(const RecordType *Ty) {
 
   // Collect data fields (including static variables and any initializers).
   CollectRecordFields(RD, DefUnit, EltTys, FwdDecl);
-  if (CXXDecl)
+  if (CXXDecl && !CGM.getCodeGenOpts().DebugOmitUnreferencedMembers)

SLTozer wrote:

>From the old review, there was a question about whether this should be 
>disabled by `-fstandalone-debug` - it seemed like there was a reasonable case 
>for (being able to call member functions from a different TU without debug 
>info), and a reasonable case against (inconsistency with non-member 
>functions), and it's not totally clear whether that was resolved.

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


[clang] [DebugInfo] Add flag to only emit referenced member functions (PR #87018)

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

https://github.com/SLTozer commented:

I think the comment about `s/members/methods/` is still outstanding - I agree 
that methods is more descriptive than members.

I'm +1 on having this be non-default; adding it to SCE tuning is also not 
necessary (or desired) for now, because this is more aggressive than our 
private option (we keep entries for member functions that are called), and 
we're still working out whether we can/should adopt this instead. 

Otherwise, existing comments aside, this looks good: the size reduction is 
considerable, and likely becoming necessary for some.

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


[clang] [DebugInfo] Add flag to only emit referenced member functions (PR #87018)

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


@@ -4260,6 +4260,13 @@ defm strict_dwarf : BoolOption<"g", "strict-dwarf",
   "the specified version, avoiding features from later versions.">,
   NegFlag, BothFlags<[], [ClangOption, CLOption, DXCOption]>>,
   Group;
+defm omit_unreferenced_members : BoolOption<"g", "omit-unreferenced-members",
+  CodeGenOpts<"DebugOmitUnreferencedMembers">, DefaultFalse,
+  PosFlag,
+  NegFlag, BothFlags<[], [ClangOption, CLOption, DXCOption]>>,
+  Group;

SLTozer wrote:

As a small matter of convenience, since this is just being passed straight 
through the driver I think this could be a marshalling flag, which iirc would 
allow us to omit the `renderDebugOptions` code?
```suggestion
defm omit_unreferenced_members : Flag<["-"], "gomit-unreferenced-members">,
  Group, Visibility<[ClangOption, CC1Option]>,
  HelpText<"Omit member function declarations from type descriptions if the "
"member is unreferenced.">,
  MarshallingInfoFlag>;
```

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


[clang] [llvm] [Clang] Fix definition of layout-compatible to ignore empty classes (PR #92103)

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

MitalAshok wrote:

@dwblaikie This patch will bring Clang in line with GCC and MSVC: 
https://godbolt.org/z/nj715zbsW

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


[clang] [llvm] [Clang] Fix definition of layout-compatible to ignore empty classes (PR #92103)

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


@@ -561,6 +561,42 @@ void CXXRecordDecl::addedClassSubobject(CXXRecordDecl 
*Subobj) {
 data().StructuralIfLiteral = false;
 }
 
+const CXXRecordDecl *CXXRecordDecl::getStandardLayoutBaseWithFields() const {
+#ifndef NDEBUG
+  {
+assert(
+isStandardLayout() &&
+"getStandardLayoutBaseWithFields called on a non-standard-layout 
type");
+unsigned NumberOfBasesWithFields = 0;
+if (!field_empty())
+  ++NumberOfBasesWithFields;
+std::set UniqueBases;

MitalAshok wrote:

@Endilll `llvm::SmallPtrSet` seemed more appropriate here

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


[clang] [llvm] [Clang] Fix definition of layout-compatible to ignore empty classes (PR #92103)

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

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

>From 5908130604728b9aa9b70eeb2523d368df08e68d Mon Sep 17 00:00:00 2001
From: Mital Ashok 
Date: Tue, 14 May 2024 08:28:19 +0100
Subject: [PATCH 1/3] [Clang] Fix definition of layout-compatible to ignore
 empty classes

Also changes the behaviour of __builtin_is_layout_compatible

None of the historic nor the current definition of layout-compatible classes 
mention anything about base classes (other than implicitly through being 
standard-layout) and are defined in terms of members, not direct members.
---
 clang/include/clang/AST/DeclCXX.h  |  7 
 clang/lib/AST/DeclCXX.cpp  | 36 +
 clang/lib/Sema/SemaChecking.cpp| 63 +-
 clang/test/SemaCXX/type-traits.cpp | 11 ++
 llvm/include/llvm/ADT/STLExtras.h  |  6 +++
 5 files changed, 79 insertions(+), 44 deletions(-)

diff --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index fb52ac804849d..60a5005c51a5e 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1229,6 +1229,13 @@ class CXXRecordDecl : public RecordDecl {
   /// C++11 [class]p7, specifically using the C++11 rules without any DRs.
   bool isCXX11StandardLayout() const { return data().IsCXX11StandardLayout; }
 
+  /// If this is a standard-layout class or union, any and all data members 
will
+  /// be declared in the same type.
+  ///
+  /// This retrieves the type if this class has any data members,
+  /// or the current class if there is no class with fields.
+  const CXXRecordDecl *getStandardLayoutBaseWithFields() const;
+
   /// Determine whether this class, or any of its class subobjects,
   /// contains a mutable field.
   bool hasMutableFields() const { return data().HasMutableFields; }
diff --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 75c441293d62e..ab032a4595d46 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -561,6 +561,42 @@ void CXXRecordDecl::addedClassSubobject(CXXRecordDecl 
*Subobj) {
 data().StructuralIfLiteral = false;
 }
 
+const CXXRecordDecl *CXXRecordDecl::getStandardLayoutBaseWithFields() const {
+#ifndef NDEBUG
+  {
+assert(
+isStandardLayout() &&
+"getStandardLayoutBaseWithFields called on a non-standard-layout 
type");
+unsigned NumberOfBasesWithFields = 0;
+if (!field_empty())
+  ++NumberOfBasesWithFields;
+std::set UniqueBases;
+forallBases([&](const CXXRecordDecl *Base) -> bool {
+  if (!Base->field_empty())
+++NumberOfBasesWithFields;
+  assert(
+  UniqueBases.insert(Base->getCanonicalDecl()).second &&
+  "Standard layout struct has multiple base classes of the same type");
+  return true;
+});
+assert(NumberOfBasesWithFields <= 1 &&
+   "Standard layout struct has fields declared in more than one 
class");
+  }
+#endif
+  if (!field_empty())
+return this;
+  const CXXRecordDecl *Result = this;
+  forallBases([&](const CXXRecordDecl *Base) -> bool {
+if (!Base->field_empty()) {
+  // This is the base where the fields are declared; return early
+  Result = Base;
+  return false;
+}
+return true;
+  });
+  return Result;
+}
+
 bool CXXRecordDecl::hasConstexprDestructor() const {
   auto *Dtor = getDestructor();
   return Dtor ? Dtor->isConstexpr() : defaultedDestructorIsConstexpr();
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index ecd1821651140..acd142c1932ad 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -19084,7 +19084,8 @@ void Sema::DiagnoseSelfMove(const Expr *LHSExpr, const 
Expr *RHSExpr,
 static bool isLayoutCompatible(ASTContext &C, QualType T1, QualType T2);
 
 /// Check if two enumeration types are layout-compatible.
-static bool isLayoutCompatible(ASTContext &C, EnumDecl *ED1, EnumDecl *ED2) {
+static bool isLayoutCompatible(ASTContext &C, const EnumDecl *ED1,
+   const EnumDecl *ED2) {
   // C++11 [dcl.enum] p8:
   // Two enumeration types are layout-compatible if they have the same
   // underlying type.
@@ -19095,8 +19096,8 @@ static bool isLayoutCompatible(ASTContext &C, EnumDecl 
*ED1, EnumDecl *ED2) {
 /// Check if two fields are layout-compatible.
 /// Can be used on union members, which are exempt from alignment requirement
 /// of common initial sequence.
-static bool isLayoutCompatible(ASTContext &C, FieldDecl *Field1,
-   FieldDecl *Field2,
+static bool isLayoutCompatible(ASTContext &C, const FieldDecl *Field1,
+   const FieldDecl *Field2,
bool AreUnionMembers = false) {
   [[maybe_unused]] const Type *Field1Parent =
   Field1->getParent()->getTypeForDecl();
@@ -19139,52 +19140,26 @@ static bool isLayoutCompatible(ASTContext &C, 
FieldDecl *Field1,
 
 /// Check if two standa

[clang] [clang] Introduce `SemaPseudoObject` (PR #92646)

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

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


[clang] [clang] Introduce `SemaPseudoObject` (PR #92646)

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

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

LGTM!

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


[clang] 1664610 - [clang] Introduce `SemaPseudoObject` (#92646)

2024-05-21 Thread via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-05-21T16:03:56+04:00
New Revision: 1664610130b88ef168e33eddfe973a3f11bd4261

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

LOG: [clang] Introduce `SemaPseudoObject` (#92646)

This patch moves `Sema` functions that handle pseudo-objects into the
new `SemaPseudoObject` class. This continues previous efforts to split
`Sema` up. Additional context can be found in #84184.
As usual, in order to help reviewing this, formatting changes are split
into a separate commit.

Added: 
clang/include/clang/Sema/SemaPseudoObject.h

Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaPseudoObject.cpp
clang/lib/Sema/TreeTransform.h

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 5894239664c15..01ddba5eaf01d 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -174,6 +174,7 @@ class SemaHLSL;
 class SemaObjC;
 class SemaOpenACC;
 class SemaOpenMP;
+class SemaPseudoObject;
 class SemaSYCL;
 class StandardConversionSequence;
 class Stmt;
@@ -471,20 +472,19 @@ class Sema final : public SemaBase {
   // 18. Name Lookup (SemaLookup.cpp)
   // 19. Modules (SemaModule.cpp)
   // 20. C++ Overloading (SemaOverload.cpp)
-  // 21. Pseudo-Object (SemaPseudoObject.cpp)
-  // 22. Statements (SemaStmt.cpp)
-  // 23. `inline asm` Statement (SemaStmtAsm.cpp)
-  // 24. Statement Attribute Handling (SemaStmtAttr.cpp)
-  // 25. C++ Templates (SemaTemplate.cpp)
-  // 26. C++ Template Argument Deduction (SemaTemplateDeduction.cpp)
-  // 27. C++ Template Instantiation (SemaTemplateInstantiate.cpp)
-  // 28. C++ Template Declaration Instantiation
+  // 21. Statements (SemaStmt.cpp)
+  // 22. `inline asm` Statement (SemaStmtAsm.cpp)
+  // 23. Statement Attribute Handling (SemaStmtAttr.cpp)
+  // 24. C++ Templates (SemaTemplate.cpp)
+  // 25. C++ Template Argument Deduction (SemaTemplateDeduction.cpp)
+  // 26. C++ Template Instantiation (SemaTemplateInstantiate.cpp)
+  // 27. C++ Template Declaration Instantiation
   // (SemaTemplateInstantiateDecl.cpp)
-  // 29. C++ Variadic Templates (SemaTemplateVariadic.cpp)
-  // 30. Constraints and Concepts (SemaConcept.cpp)
-  // 31. Types (SemaType.cpp)
-  // 32. FixIt Helpers (SemaFixItUtils.cpp)
-  // 33. Name Lookup for RISC-V Vector Intrinsic (SemaRISCVVectorLookup.cpp)
+  // 28. C++ Variadic Templates (SemaTemplateVariadic.cpp)
+  // 29. Constraints and Concepts (SemaConcept.cpp)
+  // 30. Types (SemaType.cpp)
+  // 31. FixIt Helpers (SemaFixItUtils.cpp)
+  // 32. Name Lookup for RISC-V Vector Intrinsic (SemaRISCVVectorLookup.cpp)
 
   /// \name Semantic Analysis
   /// Implementations are in Sema.cpp
@@ -1015,6 +1015,11 @@ class Sema final : public SemaBase {
 return *OpenMPPtr;
   }
 
+  SemaPseudoObject &PseudoObject() {
+assert(PseudoObjectPtr);
+return *PseudoObjectPtr;
+  }
+
   SemaSYCL &SYCL() {
 assert(SYCLPtr);
 return *SYCLPtr;
@@ -1056,6 +1061,7 @@ class Sema final : public SemaBase {
   std::unique_ptr ObjCPtr;
   std::unique_ptr OpenACCPtr;
   std::unique_ptr OpenMPPtr;
+  std::unique_ptr PseudoObjectPtr;
   std::unique_ptr SYCLPtr;
 
   ///@}
@@ -6369,6 +6375,8 @@ class Sema final : public SemaBase {
   llvm::SmallVector, 1>
   ImplicitlyRetainedSelfLocs;
 
+  void maybeExtendBlockObject(ExprResult &E);
+
 private:
   static BinaryOperatorKind ConvertTokenKindToBinaryOpcode(tok::TokenKind 
Kind);
 
@@ -8367,29 +8375,6 @@ class Sema final : public SemaBase {
   //
   //
 
-  /// \name Pseudo-Object
-  /// Implementations are in SemaPseudoObject.cpp
-  ///@{
-
-public:
-  void maybeExtendBlockObject(ExprResult &E);
-
-  ExprResult checkPseudoObjectIncDec(Scope *S, SourceLocation OpLoc,
- UnaryOperatorKind Opcode, Expr *Op);
-  ExprResult checkPseudoObjectAssignment(Scope *S, SourceLocation OpLoc,
- BinaryOperatorKind Opcode, Expr *LHS,
- Expr *RHS);
-  ExprResult checkPseudoObjectRValue(Expr *E);
-  Expr *recreateSyntacticForm(PseudoObjectExpr *E);
-
-  ///@}
-
-  //
-  //
-  // -
-  //
-  //
-
   /// \name Statements
   /// Implementations are in SemaStmt.cpp
   ///@{

diff  --git a/clang/include/clang/Sema/SemaPseudoObject.h 
b/clang/include/clang/Sema/SemaPseudoObject.h
new file mode 100644
index 0..22d8be2b3726e
--- /dev/null
+++ b/clang/include/clang/Sema/SemaPseudoObject.h
@@ -0,0 +1,40 @@
+//===- SemaPseudoObject.h --- Semantic Analysis for Pseudo-Objects 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0

[clang] [clang] Introduce `SemaPseudoObject` (PR #92646)

2024-05-21 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [ExtractAPI,test] fix filecheck annotation (PR #92231)

2024-05-21 Thread via cfe-commits

https://github.com/klensy updated 
https://github.com/llvm/llvm-project/pull/92231

>From 9ecc2005888c8ebdf24c7bca163d8c1de6be68b0 Mon Sep 17 00:00:00 2001
From: klensy 
Date: Wed, 15 May 2024 12:14:56 +0300
Subject: [PATCH] [ExtractAPI,test] fix filecheck annotation

---
 clang/test/ExtractAPI/availability.c  | 2 +-
 clang/test/ExtractAPI/objc_property.m | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/test/ExtractAPI/availability.c 
b/clang/test/ExtractAPI/availability.c
index 237b2ffa55d7d..ca6007e12e255 100644
--- a/clang/test/ExtractAPI/availability.c
+++ b/clang/test/ExtractAPI/availability.c
@@ -40,7 +40,7 @@ void b(void) __attribute__((availability(macos, 
introduced=11.0, deprecated=12.0
 // B-NEXT:   }
 // B-NEXT: ]
 
-// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix E
+// RUN: FileCheck %s --input-file %t/output.symbols.json --check-prefix C
 void c(void) __attribute__((availability(macos, introduced=11.0, 
deprecated=12.0, obsoleted=20.0))) __attribute__((availability(ios, 
introduced=13.0)));
 // C-LABEL: "!testLabel": "c:@F@c"
 // C:   "availability": [
diff --git a/clang/test/ExtractAPI/objc_property.m 
b/clang/test/ExtractAPI/objc_property.m
index f05584c885d91..0c0b17c9c000f 100644
--- a/clang/test/ExtractAPI/objc_property.m
+++ b/clang/test/ExtractAPI/objc_property.m
@@ -11,7 +11,7 @@ @protocol Protocol
 
 @interface Interface
 @property(class) int myInterfaceTypeProp;
-// CHECk-DAG: "!testRelLabel": "memberOf $ 
c:objc(cs)Interface(cpy)myInterfaceTypeProp $ c:objc(cs)Interface"
+// CHECK-DAG: "!testRelLabel": "memberOf $ 
c:objc(cs)Interface(cpy)myInterfaceTypeProp $ c:objc(cs)Interface"
 @property int myInterfaceInstanceProp;
 // CHECK-DAG: "!testRelLabel": "memberOf $ 
c:objc(cs)Interface(py)myInterfaceInstanceProp $ c:objc(cs)Interface"
 @end
@@ -20,7 +20,7 @@ @interface Interface (Category) 
 @property(class) int myCategoryTypeProp;
 // CHECK-DAG: "!testRelLabel": "memberOf $ 
c:objc(cs)Interface(cpy)myCategoryTypeProp $ c:objc(cs)Interface"
 @property int myCategoryInstanceProp;
-// CHECK-DAG "!testRelLabel": "memberOf $ 
c:objc(cs)Interface(py)myCategoryInstanceProp $ c:objc(cs)Interface"
+// CHECK-DAG: "!testRelLabel": "memberOf $ 
c:objc(cs)Interface(py)myCategoryInstanceProp $ c:objc(cs)Interface"
 @end
 
 // expected-no-diagnostics

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


[clang] [ExtractAPI,test] fix filecheck annotation (PR #92231)

2024-05-21 Thread via cfe-commits

klensy wrote:

Fixed email.

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


[clang] 45293b5 - MIPS/Clang: handleTargetFeatures, add +fp64 if +msa and no other +-fp (#92728)

2024-05-21 Thread via cfe-commits

Author: YunQiang Su
Date: 2024-05-21T20:14:46+08:00
New Revision: 45293b5edb7f320bc1b14b6ce8ac90ed111baa53

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

LOG: MIPS/Clang: handleTargetFeatures, add +fp64 if +msa and no other +-fp 
(#92728)

Commit: d59bc6b5c75384aa0b1e78cc85e17e8acaccebaf
Clang/MIPS: Add +fp64 if MSA and no explicit -mfp option (#91949)
added +fp64 for `clang`, while not for `clang -cc1`. So

   clang -cc1 -triple=mips -target-feature +msa -S

will emit an asm source file without ".module fp=64".

Added: 


Modified: 
clang/lib/Basic/Targets/Mips.h

Removed: 




diff  --git a/clang/lib/Basic/Targets/Mips.h b/clang/lib/Basic/Targets/Mips.h
index f76c6ece8bf48..b6f110249fa78 100644
--- a/clang/lib/Basic/Targets/Mips.h
+++ b/clang/lib/Basic/Targets/Mips.h
@@ -324,6 +324,7 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 FPMode = getDefaultFPMode();
 bool OddSpregGiven = false;
 bool StrictAlign = false;
+bool FpGiven = false;
 
 for (const auto &Feature : Features) {
   if (Feature == "+single-float")
@@ -348,13 +349,16 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 HasMSA = true;
   else if (Feature == "+nomadd4")
 DisableMadd4 = true;
-  else if (Feature == "+fp64")
+  else if (Feature == "+fp64") {
 FPMode = FP64;
-  else if (Feature == "-fp64")
+FpGiven = true;
+  } else if (Feature == "-fp64") {
 FPMode = FP32;
-  else if (Feature == "+fpxx")
+FpGiven = true;
+  } else if (Feature == "+fpxx") {
 FPMode = FPXX;
-  else if (Feature == "+nan2008")
+FpGiven = true;
+  } else if (Feature == "+nan2008")
 IsNan2008 = true;
   else if (Feature == "-nan2008")
 IsNan2008 = false;
@@ -381,6 +385,11 @@ class LLVM_LIBRARY_VISIBILITY MipsTargetInfo : public 
TargetInfo {
 if (StrictAlign)
   HasUnalignedAccess = false;
 
+if (HasMSA && !FpGiven) {
+  FPMode = FP64;
+  Features.push_back("+fp64");
+}
+
 setDataLayout();
 
 return true;



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


[clang] MIPS/Clang: handleTargetFeatures, add +fp64 if +msa and no other +-fp (PR #92728)

2024-05-21 Thread YunQiang Su via cfe-commits

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


[clang] MIPS/Clang: Add more false option pairs into validateTarget (PR #91968)

2024-05-21 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa updated 
https://github.com/llvm/llvm-project/pull/91968

>From cccd9606fd574726c2cde2e473d1e05a62147caf Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Mon, 13 May 2024 21:46:40 +0800
Subject: [PATCH] MIPS/Clang: Add more false option pairs into validateTarget

The option pairs include:
-mfpxx -mips1
-msoft-float -mmsa
-mmsa -mabi=32 with 32bit pre-R2 CPUs
-mfpxx -mmsa
-mfp32 -mmsa
---
 clang/lib/Basic/Targets/Mips.cpp | 28 
 1 file changed, 28 insertions(+)

diff --git a/clang/lib/Basic/Targets/Mips.cpp b/clang/lib/Basic/Targets/Mips.cpp
index 3a65f53c52485..174bc9d2ab996 100644
--- a/clang/lib/Basic/Targets/Mips.cpp
+++ b/clang/lib/Basic/Targets/Mips.cpp
@@ -273,6 +273,34 @@ bool MipsTargetInfo::validateTarget(DiagnosticsEngine 
&Diags) const {
 Diags.Report(diag::err_mips_fp64_req) << "-mfp64";
 return false;
   }
+  // FPXX requires mips2+
+  if (FPMode == FPXX && CPU == "mips1") {
+Diags.Report(diag::err_opt_not_valid_with_opt) << "-mfpxx" << CPU;
+return false;
+  }
+  // -mmsa with -msoft-float makes nonsense
+  if (FloatABI == SoftFloat && HasMSA) {
+Diags.Report(diag::err_opt_not_valid_with_opt) << "-msoft-float"
+   << "-mmsa";
+return false;
+  }
+  // Option -mmsa permitted on Mips32 iff revision 2 or higher is present
+  if (HasMSA && (CPU == "mips1" || CPU == "mips2" || getISARev() < 2) &&
+  ABI == "o32") {
+Diags.Report(diag::err_mips_fp64_req) << "-mmsa";
+return false;
+  }
+  // MSA requires FP64
+  if (FPMode == FPXX && HasMSA) {
+Diags.Report(diag::err_opt_not_valid_with_opt) << "-mfpxx"
+   << "-mmsa";
+return false;
+  }
+  if (FPMode == FP32 && HasMSA) {
+Diags.Report(diag::err_opt_not_valid_with_opt) << "-mfp32"
+   << "-mmsa";
+return false;
+  }
 
   return true;
 }

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


[clang] [llvm] [IR] Avoid creating icmp/fcmp constant expressions (PR #92885)

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


@@ -1422,7 +1417,7 @@ define i1 @user_of_not_called() {
 ; CHECK-LABEL: define {{[^@]+}}@user_of_not_called() {
 ; CHECK-NEXT:call void @useFnDecl(ptr addrspace(42) noundef nonnull 
addrspacecast (ptr @not_called1 to ptr addrspace(42)))
 ; CHECK-NEXT:call void @useFnDef(ptr addrspace(42) noundef nonnull 
addrspacecast (ptr @not_called2 to ptr addrspace(42)))
-; CHECK-NEXT:ret i1 icmp eq (ptr addrspace(42) addrspacecast (ptr 
@not_called3 to ptr addrspace(42)), ptr addrspace(42) null)
+; CHECK-NEXT:ret i1 false

nikic wrote:

This change looked suspicious to me -- I was afraid that we started to simplify 
a null comparison through an addrspace cast, which wouldn't generally be valid. 
But this doesn't seem to be the case as far as ConstantFolding/InstSimplify are 
concerned. This is some Attributor-specific behavior and it has been flipping 
back and forth in this test in multiple previous changes. Maybe @jdoerfert 
knows what is happening here.

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


[clang] [flang] [flang][driver] Accept -fallow-argument-mismatch with a warning instead of rejecting it (PR #91611)

2024-05-21 Thread Paul Osmialowski via cfe-commits

pawosm-arm wrote:

> 
> It sounds like an issue with the `mpich` build script rather than LLVM Flang. 
> Why would `mpich` and other projects use this flag to begin with? Do other 
> Fortran compilers support it?
>

I don't know why they do that, I suppose they think they know better. I don't 
suspect they are aware of the pain they brought to the users (of various 
Fortran compilers).
 
> From GFrotran docs 
> (https://gcc.gnu.org/onlinedocs/gfortran/Fortran-Dialect-Options.html):
> 
> > Using this option is strongly discouraged.
> 

As I said, I suppose they think they know better.

> In general, I'm hesitant to allow such dummy flags that:
> 
> * do nothing,
> * are there merely to prevent issues in build scripts.
> 
> Are there no other ways around it? We obviously should make it possible for 
> LLVM Flang to build all projects, but I really want to avoid Flang containing 
> multiple dummy flags only to work around build scripts that assume a 
> particular compiler is used.
> 

The alternative is to instruct the users how to patch the `configure` scripts. 
There is always a trade-off between disgust (caused by introduction of ugly 
flags) and battered user experience (caused by the compiler rejecting a flag 
that someone in some widely used project insisted that should be accepted). We 
could document the problem and describe how to work around it, however we must 
carefully consider the maintenance cost of this extra bit of documentation.

> We might be missing some "gfortran compatibility mode" in Flang (on top of 
> `FlangMode`). Such mode could allow unsupported GFortran flags and warn 
> whenever those are used. `flang-new` would still "default" to `FlangMode` and 
> just generate an error.
> 

Yes, we agreed long time ago that gfortran isn't the gold standard of how the 
Fortran compiler should behave. But the reality always knows it better. And 
things like mpich or netcdf are widely used in the exact environment we want to 
target with our compiler.



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


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

2024-05-21 Thread Alexandros Lamprineas via cfe-commits


@@ -0,0 +1,84 @@
+// Function MultiVersioning (FMV) properties
+
+// Something you can add to target_version or target_clones
+class FMVExtension {
+// Name, as spelled in target_version or target_clones. e.g. "memtag"
+string Name = n;
+
+// A C++ expression giving the number of the bit in the FMV ABI.
+// Currently this is given as a value from the enum "CPUFeatures".
+// If this is not set, it indicates that this is not an FMV extension.
+string Bit = b;
+
+// SubtargetFeatures to enable for code functions with this FMV feature.
+// TODO list BackendFeatures = f;
+string BackendFeatures = f;
+
+// The FMV priority.
+int Priority = p;

labrinea wrote:

unsigned?

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


[clang] [clang][analyzer] Move checker alpha.security.cert.pos.34c into security.PutenvWithAuto (PR #92424)

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

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

LGTM, feel free to merge this. As @steakhal said, ensure that the PR 
title/description and the commit message all reflect the actual changes that 
you're commiting.

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


[clang] [llvm] [polly] [X86] Remove knl/knm specific ISAs supports (PR #92883)

2024-05-21 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

Please note it in release notes.

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


[clang] [llvm] [polly] [X86] Remove knl/knm specific ISAs supports (PR #92883)

2024-05-21 Thread Phoebe Wang via cfe-commits


@@ -9265,6 +9265,33 @@ multiclass avx512_fp28_s opc, string 
OpcodeStr,X86VectorVTInfo _,
   }
 }
 
+multiclass avx512_fp28_s_ass opc, string OpcodeStr, X86VectorVTInfo _> 
{
+  let ExeDomain = _.ExeDomain, hasNoSchedulingInfo = 1 in {
+  defm r : AVX512_maskable_scalar, Sched<[WriteMove]>;
+  defm rb : AVX512_maskable_scalar, Sched<[WriteMove]>, EVEX_B;
+  defm m : AVX512_maskable_scalar, Sched<[WriteMove]>;
+  }
+}
+
+multiclass avx512_eri_s_ass opc, string OpcodeStr> {
+  defm SSZ : avx512_fp28_s_ass,
+ EVEX_CD8<32, CD8VT1>, VEX_LIG, T8, PD, EVEX, ;
+  defm SDZ : avx512_fp28_s_ass,
+ EVEX_CD8<64, CD8VT1>, VEX_LIG, REX_W, T8, PD, EVEX, ;
+}
+
+defm VRCP28   : avx512_eri_s_ass<0xCB, "vrcp28">;

phoebewang wrote:

Why still keep these instructions?

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


[clang-tools-extra] 2117136 - [clangd] Fix bad directory path in `infinite-instantiations.test`

2024-05-21 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2024-05-21T15:42:31+03:00
New Revision: 2117136b2b78ef3b83202909ffaf351598da8bd5

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

LOG: [clangd] Fix bad directory path in `infinite-instantiations.test`

Addresses buildbot failure 
https://lab.llvm.org/buildbot/#/builders/123/builds/26913 caused by #92888

Added: 


Modified: 
clang-tools-extra/clangd/test/infinite-instantiation.test

Removed: 




diff  --git a/clang-tools-extra/clangd/test/infinite-instantiation.test 
b/clang-tools-extra/clangd/test/infinite-instantiation.test
index 98260c075d240..da1a294142429 100644
--- a/clang-tools-extra/clangd/test/infinite-instantiation.test
+++ b/clang-tools-extra/clangd/test/infinite-instantiation.test
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t.dir && mkdir -p %t.dir
-// RUN: echo '[{"directory": "%/t.dir", "command": "clang -ftemplate-depth=100 
-x c++ %s", "file": "%s"}]' > %t.dir/compile_commands.json
+// RUN: echo '[{"directory": "%t.dir", "command": "clang -ftemplate-depth=100 
-x c++ %s", "file": "%s"}]' > %t.dir/compile_commands.json
 // RUN: not clangd --compile-commands-dir=%t.dir -check=%s 2>&1 | FileCheck 
-strict-whitespace %s
 
 // CHECK: [template_recursion_depth_exceeded]



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


[clang] [llvm] [polly] [X86] Remove knl/knm specific ISAs supports (PR #92883)

2024-05-21 Thread Phoebe Wang via cfe-commits


@@ -9325,6 +9345,43 @@ multiclass avx512_fp28_p_sae opc, string 
OpcodeStr, X86VectorVTInfo _,
 EVEX_B, Sched<[sched]>;
 }
 
+multiclass avx512_fp28_p_ass opc, string OpcodeStr, X86VectorVTInfo _> 
{
+  let ExeDomain = _.ExeDomain, hasNoSchedulingInfo = 1 in {
+  defm r : AVX512_maskable, Sched<[WriteMove]>;
+
+  defm m : AVX512_maskable, Sched<[WriteMove]>;
+
+  defm mb : AVX512_maskable, Sched<[WriteMove]>, EVEX_B;
+  }
+}
+multiclass avx512_fp28_p_sae_ass opc, string OpcodeStr, 
X86VectorVTInfo _> {
+  let ExeDomain = _.ExeDomain, Uses = [MXCSR] in
+  defm rb : AVX512_maskable, Sched<[WriteMove]>, EVEX_B;
+}
+
+multiclass  avx512_eri_ass opc, string OpcodeStr> {
+   defm PSZ : avx512_fp28_p_ass,
+  avx512_fp28_p_sae_ass,
+  T8, PD, EVEX_V512, EVEX_CD8<32, CD8VF>;
+   defm PDZ : avx512_fp28_p_ass,
+  avx512_fp28_p_sae_ass,
+  T8, PD, EVEX_V512, REX_W, EVEX_CD8<64, CD8VF>;
+}
+
+defm VRSQRT28 : avx512_eri_ass<0xCC, "vrsqrt28">, EVEX;

phoebewang wrote:

ditto.

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


[clang] [C] Disallow declarations where a statement is required (PR #92908)

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

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

This fixes a regression introduced in 8bd06d5b65845e5e01dd899a2deb773580460b89 
where Clang began to accept a declaration where a statement is required. e.g.,
```
if (1)
  int x; // Previously accepted, now properly rejected
```

Fixes #92775

>From 219dae02c3235c17bc4568496a7df9763d798e2a Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Mon, 20 May 2024 13:40:28 -0400
Subject: [PATCH 1/4] [C] Fix declaration parsing

8bd06d5b65845e5e01dd899a2deb773580460b89 removed the notion of parsed
statement contexts that track whether a declaration is valid for C or
not. This resurrects the concept, because C still does not allow a
declaration as a substatement.
---
 clang/include/clang/Parse/Parser.h | 9 ++---
 clang/lib/Parse/ParseStmt.cpp  | 5 -
 clang/test/C/C99/block-scopes.c| 3 ++-
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 5f04664141d29..5e455b16fb8c0 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -467,15 +467,18 @@ class Parser : public CodeCompletionHandler {
 
   /// Flags describing a context in which we're parsing a statement.
   enum class ParsedStmtContext {
+/// This context permits declarations in language modes where declarations
+/// are not statements.
+AllowDeclarationsInC = 0x1,
 /// This context permits standalone OpenMP directives.
-AllowStandaloneOpenMPDirectives = 0x1,
+AllowStandaloneOpenMPDirectives = 0x2,
 /// This context is at the top level of a GNU statement expression.
-InStmtExpr = 0x2,
+InStmtExpr = 0x4,
 
 /// The context of a regular substatement.
 SubStmt = 0,
 /// The context of a compound-statement.
-Compound = AllowStandaloneOpenMPDirectives,
+Compound = AllowDeclarationsInC | AllowStandaloneOpenMPDirectives,
 
 LLVM_MARK_AS_BITMASK_ENUM(InStmtExpr)
   };
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index b0af04451166c..57b9fb10a1e08 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -239,7 +239,10 @@ StmtResult 
Parser::ParseStatementOrDeclarationAfterAttributes(
 auto IsStmtAttr = [](ParsedAttr &Attr) { return Attr.isStmtAttr(); };
 bool AllAttrsAreStmtAttrs = llvm::all_of(CXX11Attrs, IsStmtAttr) &&
 llvm::all_of(GNUAttrs, IsStmtAttr);
-if (((GNUAttributeLoc.isValid() && !(HaveAttrs && AllAttrsAreStmtAttrs)) ||
+if ((getLangOpts().CPlusPlus || getLangOpts().MicrosoftExt ||
+ (StmtCtx & ParsedStmtContext::AllowDeclarationsInC) !=
+ ParsedStmtContext()) &&
+((GNUAttributeLoc.isValid() && !(HaveAttrs && AllAttrsAreStmtAttrs)) ||
  isDeclarationStatement())) {
   SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
   DeclGroupPtrTy Decl;
diff --git a/clang/test/C/C99/block-scopes.c b/clang/test/C/C99/block-scopes.c
index 589047df3e52b..116e5d922593e 100644
--- a/clang/test/C/C99/block-scopes.c
+++ b/clang/test/C/C99/block-scopes.c
@@ -18,8 +18,9 @@
 
 enum {a, b};
 void different(void) {
-  if (sizeof(enum {b, a}) != sizeof(int))
+  if (sizeof(enum {b, a}) != sizeof(int)) {
 _Static_assert(a == 1, "");
+  }
   /* In C89, the 'b' found here would have been from the enum declaration in
* the controlling expression of the selection statement, not from the global
* declaration. In C99 and later, that enumeration is scoped to the 'if'

>From c67502ddeb0c1db5c71fe1eb115250bd238c0d9d Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Tue, 21 May 2024 08:34:01 -0400
Subject: [PATCH 2/4] Update OpenACC test for slight behavioral change

---
 clang/test/SemaOpenACC/parallel-loc-and-stmt.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/test/SemaOpenACC/parallel-loc-and-stmt.c 
b/clang/test/SemaOpenACC/parallel-loc-and-stmt.c
index ba29f6da8ba25..bbcdd823483a5 100644
--- a/clang/test/SemaOpenACC/parallel-loc-and-stmt.c
+++ b/clang/test/SemaOpenACC/parallel-loc-and-stmt.c
@@ -33,9 +33,11 @@ int foo3;
 
 void func() {
   // FIXME: Should we disallow this on declarations, or consider this to be on
-  // the initialization?
+  // the initialization? This is currently rejected in C because
+  // Parser::ParseOpenACCDirectiveStmt() calls ParseStatement() and passes the
+  // statement context as "SubStmt" which does not allow for a declaration in 
C.
 #pragma acc parallel
-  int foo;
+  int foo; // expected-error {{expected expression}}
 
 #pragma acc parallel
   {

>From 6e2e9c015ba5c60204f3ef71ebd63db8d986835a Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Tue, 21 May 2024 08:40:46 -0400
Subject: [PATCH 3/4] Add test coverage for changes

---
 clang/test/Parser/decls.c | 39 +++
 1 file changed, 39 insertions(+)
 create mode 100644 clang/test/Parse

[clang] [C] Disallow declarations where a statement is required (PR #92908)

2024-05-21 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Aaron Ballman (AaronBallman)


Changes

This fixes a regression introduced in 8bd06d5b65845e5e01dd899a2deb773580460b89 
where Clang began to accept a declaration where a statement is required. e.g.,
```
if (1)
  int x; // Previously accepted, now properly rejected
```

Fixes #92775

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


6 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/include/clang/Parse/Parser.h (+6-3) 
- (modified) clang/lib/Parse/ParseStmt.cpp (+4-1) 
- (modified) clang/test/C/C99/block-scopes.c (+2-1) 
- (added) clang/test/Parser/decls.c (+39) 
- (modified) clang/test/SemaOpenACC/parallel-loc-and-stmt.c (+4-2) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 81e9d0423f96a..a47252c536c0f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -589,6 +589,9 @@ Bug Fixes in This Version
 - ``__is_array`` and ``__is_bounded_array`` no longer return ``true`` for
   zero-sized arrays. Fixes (#GH54705).
 
+- Correctly reject declarations where a statement is required in C.
+  Fixes #GH92775
+
 Bug Fixes to Compiler Builtins
 ^^
 
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 5f04664141d29..5e455b16fb8c0 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -467,15 +467,18 @@ class Parser : public CodeCompletionHandler {
 
   /// Flags describing a context in which we're parsing a statement.
   enum class ParsedStmtContext {
+/// This context permits declarations in language modes where declarations
+/// are not statements.
+AllowDeclarationsInC = 0x1,
 /// This context permits standalone OpenMP directives.
-AllowStandaloneOpenMPDirectives = 0x1,
+AllowStandaloneOpenMPDirectives = 0x2,
 /// This context is at the top level of a GNU statement expression.
-InStmtExpr = 0x2,
+InStmtExpr = 0x4,
 
 /// The context of a regular substatement.
 SubStmt = 0,
 /// The context of a compound-statement.
-Compound = AllowStandaloneOpenMPDirectives,
+Compound = AllowDeclarationsInC | AllowStandaloneOpenMPDirectives,
 
 LLVM_MARK_AS_BITMASK_ENUM(InStmtExpr)
   };
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index b0af04451166c..57b9fb10a1e08 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -239,7 +239,10 @@ StmtResult 
Parser::ParseStatementOrDeclarationAfterAttributes(
 auto IsStmtAttr = [](ParsedAttr &Attr) { return Attr.isStmtAttr(); };
 bool AllAttrsAreStmtAttrs = llvm::all_of(CXX11Attrs, IsStmtAttr) &&
 llvm::all_of(GNUAttrs, IsStmtAttr);
-if (((GNUAttributeLoc.isValid() && !(HaveAttrs && AllAttrsAreStmtAttrs)) ||
+if ((getLangOpts().CPlusPlus || getLangOpts().MicrosoftExt ||
+ (StmtCtx & ParsedStmtContext::AllowDeclarationsInC) !=
+ ParsedStmtContext()) &&
+((GNUAttributeLoc.isValid() && !(HaveAttrs && AllAttrsAreStmtAttrs)) ||
  isDeclarationStatement())) {
   SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
   DeclGroupPtrTy Decl;
diff --git a/clang/test/C/C99/block-scopes.c b/clang/test/C/C99/block-scopes.c
index 589047df3e52b..116e5d922593e 100644
--- a/clang/test/C/C99/block-scopes.c
+++ b/clang/test/C/C99/block-scopes.c
@@ -18,8 +18,9 @@
 
 enum {a, b};
 void different(void) {
-  if (sizeof(enum {b, a}) != sizeof(int))
+  if (sizeof(enum {b, a}) != sizeof(int)) {
 _Static_assert(a == 1, "");
+  }
   /* In C89, the 'b' found here would have been from the enum declaration in
* the controlling expression of the selection statement, not from the global
* declaration. In C99 and later, that enumeration is scoped to the 'if'
diff --git a/clang/test/Parser/decls.c b/clang/test/Parser/decls.c
new file mode 100644
index 0..39ef05bf4bd99
--- /dev/null
+++ b/clang/test/Parser/decls.c
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -pedantic
+
+// Test that we can parse declarations at global scope.
+int v;
+
+void func(void) {
+  // Test that we can parse declarations within a compound statement.
+  int a;
+  {
+int b;
+  }
+
+  int z = ({ // expected-warning {{use of GNU statement expression extension}}
+   // Test that we can parse declarations within a GNU statement 
expression.
+   int w = 12;
+   w;
+  });
+
+  // Test that we diagnose declarations where a statement is required.
+  // See GH92775.
+  if (1)
+int x; // expected-error {{expected expression}}
+  for (;;)
+int c; // expected-error {{expected expression}}
+
+  label:
+int y; // expected-warning {{label followed by a declaration is a C23 
extension}}
+
+  // Test that lookup works as expected.
+  (void)a;
+  (void)v;
+  (void)z;
+  (void)b; // expected-error {{use of undeclared i

[clang] [llvm] [polly] [X86] Remove knl/knm specific ISAs supports (PR #92883)

2024-05-21 Thread Phoebe Wang via cfe-commits


@@ -9265,6 +9265,33 @@ multiclass avx512_fp28_s opc, string 
OpcodeStr,X86VectorVTInfo _,
   }
 }
 
+multiclass avx512_fp28_s_ass opc, string OpcodeStr, X86VectorVTInfo _> 
{
+  let ExeDomain = _.ExeDomain, hasNoSchedulingInfo = 1 in {
+  defm r : AVX512_maskable_scalar, Sched<[WriteMove]>;
+  defm rb : AVX512_maskable_scalar, Sched<[WriteMove]>, EVEX_B;
+  defm m : AVX512_maskable_scalar, Sched<[WriteMove]>;
+  }
+}
+
+multiclass avx512_eri_s_ass opc, string OpcodeStr> {
+  defm SSZ : avx512_fp28_s_ass,
+ EVEX_CD8<32, CD8VT1>, VEX_LIG, T8, PD, EVEX, ;
+  defm SDZ : avx512_fp28_s_ass,
+ EVEX_CD8<64, CD8VT1>, VEX_LIG, REX_W, T8, PD, EVEX, ;
+}
+
+defm VRCP28   : avx512_eri_s_ass<0xCB, "vrcp28">;

phoebewang wrote:

Ok, I recalled we still want the enc/dec support.

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


[clang] [llvm] [polly] [X86] Remove knl/knm specific ISAs supports (PR #92883)

2024-05-21 Thread Phoebe Wang via cfe-commits


@@ -1,373 +0,0 @@
-# NOTE: Assertions have been autogenerated by utils/update_mca_test_checks.py

phoebewang wrote:

Why removing this?

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


[clang] [llvm] [polly] [X86] Remove knl/knm specific ISAs supports (PR #92883)

2024-05-21 Thread Phoebe Wang via cfe-commits


@@ -23,7 +23,7 @@
 br i1 %6, label %4, label %5, !llvm.loop !9
   }
 
-  attributes #0 = { nofree norecurse nosync nounwind uwtable writeonly 
mustprogress "frame-pointer"="none" "min-legal-vector-width"="0" 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-cpu"="x86-64" 
"target-features"="+cx8,+fxsr,+mmx,+x87,-aes,-avx,-avx2,-avx512bf16,-avx512bitalg,-avx512bw,-avx512cd,-avx512dq,-avx512er,-avx512f,-avx512ifma,-avx512pf,-avx512vbmi,-avx512vbmi2,-avx512vl,-avx512vnni,-avx512vp2intersect,-avx512vpopcntdq,-avxvnni,-f16c,-fma,-fma4,-gfni,-kl,-pclmul,-sha,-sse,-sse2,-sse3,-sse4.1,-sse4.2,-sse4a,-ssse3,-vaes,-vpclmulqdq,-widekl,-xop"
 "tune-cpu"="generic" }
+  attributes #0 = { nofree norecurse nosync nounwind uwtable writeonly 
mustprogress "frame-pointer"="none" "min-legal-vector-width"="0" 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-cpu"="x86-64" 
"target-features"="+cx8,+fxsr,+mmx,+x87,-aes,-avx,-avx2,-avx512bf16,-avx512bitalg,-avx512bw,-avx512cd,-avx512dq,-avx512f,-avx512ifma,-avx512pf,-avx512vbmi,-avx512vbmi2,-avx512vl,-avx512vnni,-avx512vp2intersect,-avx512vpopcntdq,-avxvnni,-f16c,-fma,-fma4,-gfni,-kl,-pclmul,-sha,-sse,-sse2,-sse3,-sse4.1,-sse4.2,-sse4a,-ssse3,-vaes,-vpclmulqdq,-widekl,-xop"
 "tune-cpu"="generic" }

phoebewang wrote:

I think maybe we can do an NFC patch to remove these "target-features"="..." 
given we have already had "target-cpu"="xxx".

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


  1   2   3   4   5   >