[clang] [RISCV] Change required features for Zvfhmin intrinsics from ZvfhminOrZvfh to Zvfhmin (PR #77866)

2024-01-12 Thread Craig Topper via cfe-commits

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

LGTM

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


[clang-tools-extra] f489fb3 - [clangd] Fix sysroot flag handling in CommandMangler to prevent duplicates (#75694)

2024-01-12 Thread via cfe-commits

Author: Kon
Date: 2024-01-12T03:11:38-05:00
New Revision: f489fb3d75aaedf6f056113370a8b3b8659b9f17

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

LOG: [clangd] Fix sysroot flag handling in CommandMangler to prevent duplicates 
(#75694)

CommandMangler should guess the sysroot path of the host system and add
that through `-isysroot` flag only when there is no `--sysroot` or
`-isysroot` flag in the original compile command to avoid duplicate
sysroot.

Previously, CommandMangler appropriately avoided adding a guessed
sysroot flag if the original command had an argument in the form of
`--sysroot=`, `--sysroot `, or `-isysroot `.
However, when presented as `-isysroot` (without spaces after
`-isysroot`), CommandMangler mistakenly appended the guessed sysroot
flag, resulting in duplicated sysroot in the final command.

This commit fixes it, ensuring the final command has no duplicate
sysroot flags. Also adds unit tests for this fix.

Added: 


Modified: 
clang-tools-extra/clangd/CompileCommands.cpp
clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index f4e8e7e74a3bee..1b4b24d59cb83a 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -313,13 +313,15 @@ void CommandMangler::operator()(tooling::CompileCommand 
&Command,
 
   tooling::addTargetAndModeForProgramName(Cmd, Cmd.front());
 
-  // Check whether the flag exists, either as -flag or -flag=*
-  auto Has = [&](llvm::StringRef Flag) {
-for (llvm::StringRef Arg : Cmd) {
-  if (Arg.consume_front(Flag) && (Arg.empty() || Arg[0] == '='))
-return true;
-}
-return false;
+  // Check whether the flag exists in the command.
+  auto HasExact = [&](llvm::StringRef Flag) {
+return llvm::any_of(Cmd, [&](llvm::StringRef Arg) { return Arg == Flag; });
+  };
+
+  // Check whether the flag appears in the command as a prefix.
+  auto HasPrefix = [&](llvm::StringRef Flag) {
+return llvm::any_of(
+Cmd, [&](llvm::StringRef Arg) { return Arg.startswith(Flag); });
   };
 
   llvm::erase_if(Cmd, [](llvm::StringRef Elem) {
@@ -327,12 +329,13 @@ void CommandMangler::operator()(tooling::CompileCommand 
&Command,
   });
 
   std::vector ToAppend;
-  if (ResourceDir && !Has("-resource-dir"))
+  if (ResourceDir && !HasExact("-resource-dir") && 
!HasPrefix("-resource-dir="))
 ToAppend.push_back(("-resource-dir=" + *ResourceDir));
 
   // Don't set `-isysroot` if it is already set or if `--sysroot` is set.
   // `--sysroot` is a superset of the `-isysroot` argument.
-  if (Sysroot && !Has("-isysroot") && !Has("--sysroot")) {
+  if (Sysroot && !HasPrefix("-isysroot") && !HasExact("--sysroot") &&
+  !HasPrefix("--sysroot=")) {
 ToAppend.push_back("-isysroot");
 ToAppend.push_back(*Sysroot);
   }
@@ -343,7 +346,7 @@ void CommandMangler::operator()(tooling::CompileCommand 
&Command,
   }
 
   if (!Cmd.empty()) {
-bool FollowSymlink = !Has("-no-canonical-prefixes");
+bool FollowSymlink = !HasExact("-no-canonical-prefixes");
 Cmd.front() =
 (FollowSymlink ? ResolvedDrivers : ResolvedDriversNoFollow)
 .get(Cmd.front(), [&, this] {

diff  --git a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp 
b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
index 772177b60b5eed..b64dd4acad4c22 100644
--- a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -370,9 +370,8 @@ TEST(ArgStripperTest, OrderDependent) {
 }
 
 TEST(PrintArgvTest, All) {
-  std::vector Args = {
-  "one", "two", "thr ee", "f\"o\"ur", "fi\\ve", "$"
-  };
+  std::vector Args = {"one",  "two","thr ee",
+   "f\"o\"ur", "fi\\ve", "$"};
   const char *Expected = R"(one two "thr ee" "f\"o\"ur" "fi\\ve" $)";
   EXPECT_EQ(Expected, printArgv(Args));
 }
@@ -450,6 +449,82 @@ TEST(CommandMangler, PathsAsPositional) {
   Mangler(Cmd, "a.cc");
   EXPECT_THAT(Cmd.CommandLine, Contains("foo"));
 }
+
+TEST(CommandMangler, RespectsOriginalResourceDir) {
+  auto Mangler = CommandMangler::forTests();
+  Mangler.ResourceDir = testPath("fake/resources");
+
+  {
+tooling::CompileCommand Cmd;
+Cmd.CommandLine = {"clang++", "-resource-dir", testPath("true/resources"),
+   "foo.cc"};
+Mangler(Cmd, "foo.cc");
+EXPECT_THAT(llvm::join(Cmd.CommandLine, " "),
+HasSubstr("-resource-dir " + testPath("true/resources")));
+EXPECT_THAT(llvm::join(Cmd.CommandLine, " "),
+Not(HasSubstr(testPath("fake/resources";
+  }
+
+  {
+tooling::Compile

[clang-tools-extra] [clangd] Fix sysroot flag handling in CommandMangler to prevent duplicates (PR #75694)

2024-01-12 Thread Nathan Ridge via cfe-commits

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


[clang-tools-extra] [clangd] Fix sysroot flag handling in CommandMangler to prevent duplicates (PR #75694)

2024-01-12 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

> Thank you for the review. Since I don't have permission to commit the change, 
> could you merge this on my behalf?

Sure, done.

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


[clang] [Clang][RISCV][RVV Intrinsic] Fix codegen redundant intrinsic names (PR #77889)

2024-01-12 Thread via cfe-commits

https://github.com/circYuan created 
https://github.com/llvm/llvm-project/pull/77889

This patch avoids adding redundant vcreate_v intrinsics to the RISCV 
IntrinsicList.
Since vcreate_v uses LFixedLog2LMUL, I believe we can simply set Log2LMUL to 
the smallest value (-3) to prevent the creation of redundant vcreate_v 
instances with the same intrinsic name and prototype in the IntrinsicList when 
clang creates it.

From 8562ac9ab907c3b99b3890792c0f288c0e61588d Mon Sep 17 00:00:00 2001
From: Tony Chuan-Yue Yuan 
Date: Fri, 12 Jan 2024 15:31:45 +0800
Subject: [PATCH] [Clang][RISCV][RVV Intrinsic] Fix codegen redundant intrinsic
 names

Since vcreate_v uses the FixLog2LMUL, we can simply set the Log2LMUL to
the smallest one to avoid creating redundant vcreate_v which contains
the same intrinsic name and the same prototype.
---
 clang/include/clang/Basic/riscv_vector.td | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index e7d78b03511fe9..1411d5375bdadd 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -2479,9 +2479,11 @@ let HasMasked = false, HasVL = false, IRName = "" in {
   }
   }] in {
 
-defm : RVVNonTupleVCreateBuiltin<1, [0]>;
-defm : RVVNonTupleVCreateBuiltin<2, [0, 1]>;
-defm : RVVNonTupleVCreateBuiltin<3, [0, 1, 2]>;
+let Log2LMUL = [-3] in {
+  defm : RVVNonTupleVCreateBuiltin<1, [0]>;
+  defm : RVVNonTupleVCreateBuiltin<2, [0, 1]>;
+  defm : RVVNonTupleVCreateBuiltin<3, [0, 1, 2]>;
+}
 
 foreach nf = NFList in {
   let NF = nf in {

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


[clang] [clang][dataflow] Make cap on block visits configurable by caller. (PR #77481)

2024-01-12 Thread via cfe-commits

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

Approved with comments

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


[clang] [clang][dataflow] Make cap on block visits configurable by caller. (PR #77481)

2024-01-12 Thread via cfe-commits

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


[clang] [clang][dataflow] Make cap on block visits configurable by caller. (PR #77481)

2024-01-12 Thread via cfe-commits


@@ -138,13 +138,20 @@ struct TypeErasedDataflowAnalysisState {
 /// dataflow analysis cannot be performed successfully. Otherwise, calls
 /// `PostVisitCFG` on each CFG element with the final analysis results at that
 /// program point.
+///
+/// `MaxBlockVisits` caps the number of block visits during analysis. It 
doesn't
+/// distinguish between repeat visits to the same block and visits to distinct
+/// blocks. This parameter is a backstop to prevent infintite loops, in the 
case
+/// of bugs in the lattice and/or transfer functions that prevent the analysis
+/// from converging.

martinboehme wrote:

It looks as if `MaxBlockVisits` is further capped within the function, but the 
documentation doesn't talk about this.

Change either the implementation or the documentation to make them match?

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


[clang] [clang][dataflow] Make cap on block visits configurable by caller. (PR #77481)

2024-01-12 Thread via cfe-commits


@@ -186,6 +186,14 @@ template  struct DataflowAnalysisState {
 /// the dataflow analysis cannot be performed successfully. Otherwise, calls
 /// `PostVisitCFG` on each CFG element with the final analysis results at that
 /// program point.
+///
+/// `MaxBlockVisits` caps the number of block visits during analysis. It 
doesn't
+/// distinguish between repeat visits to the same block and visits to distinct
+/// blocks. This parameter is a backstop to prevent infintite loops, in the 
case
+/// of bugs in the lattice and/or transfer functions that prevent the analysis
+/// from converging. The default value is essentially arbitrary -- large enough
+/// to accomodate what seems like any reasonable CFG, but still small enough to
+/// limit the cost of hitting the limit.

martinboehme wrote:

```suggestion
/// `MaxBlockVisits` caps the number of block visits during analysis. It doesn't
/// distinguish between repeat visits to the same block and visits to distinct
/// blocks. This parameter is a backstop to prevent infinite loops, in the case
/// of bugs in the lattice and/or transfer functions that prevent the analysis
/// from converging. The default value is essentially arbitrary -- large enough
/// to accommodate what seems like any reasonable CFG, but still small enough to
/// limit the cost of hitting the limit.
```

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


[clang] [clang][dataflow] Make cap on block visits configurable by caller. (PR #77481)

2024-01-12 Thread via cfe-commits


@@ -186,6 +186,14 @@ template  struct DataflowAnalysisState {
 /// the dataflow analysis cannot be performed successfully. Otherwise, calls
 /// `PostVisitCFG` on each CFG element with the final analysis results at that
 /// program point.
+///
+/// `MaxBlockVisits` caps the number of block visits during analysis. It 
doesn't
+/// distinguish between repeat visits to the same block and visits to distinct
+/// blocks. This parameter is a backstop to prevent infintite loops, in the 
case
+/// of bugs in the lattice and/or transfer functions that prevent the analysis
+/// from converging. The default value is essentially arbitrary -- large enough
+/// to accomodate what seems like any reasonable CFG, but still small enough to
+/// limit the cost of hitting the limit.

martinboehme wrote:

This comment is duplicated several times below. This feels a bit boilerplate-y, 
and the copies are likely to go out of sync over time. Maybe keep the full 
comment in only one central location, and in the other locations put just a 
short description that references the central comment?

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


[clang] [clang][dataflow] Make cap on block visits configurable by caller. (PR #77481)

2024-01-12 Thread via cfe-commits


@@ -261,14 +270,23 @@ auto createAnalysis(ASTContext &ASTCtx, Environment &Env)
 ///   iterations.
 /// - This limit is still low enough to keep runtimes acceptable (on typical
 ///   machines) in cases where we hit the limit.
+///
+/// `MaxBlockVisits` caps the number of block visits during analysis. It 
doesn't
+/// distinguish between repeat visits to the same block and visits to distinct
+/// blocks. This parameter is a backstop to prevent infintite loops, in the 
case
+/// of bugs in the lattice and/or transfer functions that prevent the analysis
+/// from converging. The default value is essentially arbitrary -- large enough
+/// to accomodate what seems like any reasonable CFG, but still small enough to
+/// limit the cost of hitting the limit.

martinboehme wrote:

```suggestion
/// `MaxBlockVisits` caps the number of block visits during analysis. It doesn't
/// distinguish between repeat visits to the same block and visits to distinct
/// blocks. This parameter is a backstop to prevent infinite loops, in the case
/// of bugs in the lattice and/or transfer functions that prevent the analysis
/// from converging. The default value is essentially arbitrary -- large enough
/// to accommodate what seems like any reasonable CFG, but still small enough to
/// limit the cost of hitting the limit.
```

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


[clang] [clang][dataflow] Make cap on block visits configurable by caller. (PR #77481)

2024-01-12 Thread via cfe-commits


@@ -138,13 +138,20 @@ struct TypeErasedDataflowAnalysisState {
 /// dataflow analysis cannot be performed successfully. Otherwise, calls
 /// `PostVisitCFG` on each CFG element with the final analysis results at that
 /// program point.
+///
+/// `MaxBlockVisits` caps the number of block visits during analysis. It 
doesn't
+/// distinguish between repeat visits to the same block and visits to distinct
+/// blocks. This parameter is a backstop to prevent infintite loops, in the 
case
+/// of bugs in the lattice and/or transfer functions that prevent the analysis
+/// from converging.

martinboehme wrote:

```suggestion
/// `MaxBlockVisits` caps the number of block visits during analysis. It doesn't
/// distinguish between repeat visits to the same block and visits to distinct
/// blocks. This parameter is a backstop to prevent infinite loops, in the case
/// of bugs in the lattice and/or transfer functions that prevent the analysis
/// from converging.
```

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


[clang] [Clang][RISCV][RVV Intrinsic] Fix codegen redundant intrinsic names (PR #77889)

2024-01-12 Thread via cfe-commits

github-actions[bot] wrote:

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [Clang][RISCV][RVV Intrinsic] Fix codegen redundant intrinsic names (PR #77889)

2024-01-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: 袁銓嶽 (circYuan)


Changes

This patch avoids adding redundant vcreate_v intrinsics to the RISCV 
IntrinsicList.
Since vcreate_v uses LFixedLog2LMUL, I believe we can simply set Log2LMUL to 
the smallest value (-3) to prevent the creation of redundant vcreate_v 
instances with the same intrinsic name and prototype in the IntrinsicList when 
clang creates it.

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


1 Files Affected:

- (modified) clang/include/clang/Basic/riscv_vector.td (+5-3) 


``diff
diff --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index e7d78b03511fe9..1411d5375bdadd 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -2479,9 +2479,11 @@ let HasMasked = false, HasVL = false, IRName = "" in {
   }
   }] in {
 
-defm : RVVNonTupleVCreateBuiltin<1, [0]>;
-defm : RVVNonTupleVCreateBuiltin<2, [0, 1]>;
-defm : RVVNonTupleVCreateBuiltin<3, [0, 1, 2]>;
+let Log2LMUL = [-3] in {
+  defm : RVVNonTupleVCreateBuiltin<1, [0]>;
+  defm : RVVNonTupleVCreateBuiltin<2, [0, 1]>;
+  defm : RVVNonTupleVCreateBuiltin<3, [0, 1, 2]>;
+}
 
 foreach nf = NFList in {
   let NF = nf in {

``




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


[clang] [Clang][RISCV][RVV Intrinsic] Fix codegen redundant intrinsic names (PR #77889)

2024-01-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-risc-v

Author: 袁銓嶽 (circYuan)


Changes

This patch avoids adding redundant vcreate_v intrinsics to the RISCV 
IntrinsicList.
Since vcreate_v uses LFixedLog2LMUL, I believe we can simply set Log2LMUL to 
the smallest value (-3) to prevent the creation of redundant vcreate_v 
instances with the same intrinsic name and prototype in the IntrinsicList when 
clang creates it.

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


1 Files Affected:

- (modified) clang/include/clang/Basic/riscv_vector.td (+5-3) 


``diff
diff --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index e7d78b03511fe9..1411d5375bdadd 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -2479,9 +2479,11 @@ let HasMasked = false, HasVL = false, IRName = "" in {
   }
   }] in {
 
-defm : RVVNonTupleVCreateBuiltin<1, [0]>;
-defm : RVVNonTupleVCreateBuiltin<2, [0, 1]>;
-defm : RVVNonTupleVCreateBuiltin<3, [0, 1, 2]>;
+let Log2LMUL = [-3] in {
+  defm : RVVNonTupleVCreateBuiltin<1, [0]>;
+  defm : RVVNonTupleVCreateBuiltin<2, [0, 1]>;
+  defm : RVVNonTupleVCreateBuiltin<3, [0, 1, 2]>;
+}
 
 foreach nf = NFList in {
   let NF = nf in {

``




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


[clang] [clang] WIP: Implement CTAD for type alias template. (PR #77890)

2024-01-12 Thread Haojian Wu via cfe-commits

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

Fixes #54051

This is a preliminary,  WIP and messy implementation. While it is still missing 
many pieces (see FIXMEs), it works for simple cases.

CC @ilya-biryukov, @sam-mccall , @usx95 

>From ccf08bb5e209c98bddcb39b28256cd85cecd93cd Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Wed, 26 Jul 2023 09:40:12 +0200
Subject: [PATCH] [clang] WIP: Implement CTAD for type alias template.

This is a preliminary,  WIP and messy implementation.

While it is still missing many pieces (see FIXMEs), it works for happy
cases.
---
 clang/include/clang/Sema/Sema.h   |  16 +-
 clang/lib/Sema/SemaInit.cpp   | 513 +-
 clang/lib/Sema/SemaTemplateDeduction.cpp  |   9 +
 clang/lib/Sema/SemaTemplateInstantiate.cpp|  26 +-
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  17 +-
 ...xx1z-class-template-argument-deduction.cpp |   6 +-
 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp  |  32 ++
 7 files changed, 604 insertions(+), 15 deletions(-)
 create mode 100644 clang/test/SemaCXX/cxx20-ctad-type-alias.cpp

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 4c464a1ae4c67f..6a6a30fc52c782 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9251,6 +9251,14 @@ class Sema final {
   const TemplateArgumentList &TemplateArgs,
   sema::TemplateDeductionInfo &Info);
 
+  TemplateDeductionResult
+  DeduceTemplateArguments(TemplateParameterList *TemplateParams,
+  ArrayRef Ps,
+  ArrayRef As,
+  sema::TemplateDeductionInfo &Info,
+  SmallVectorImpl &Deduced,
+  bool NumberOfArgumentsMustMatch);
+
   TemplateDeductionResult SubstituteExplicitTemplateArguments(
   FunctionTemplateDecl *FunctionTemplate,
   TemplateArgumentListInfo &ExplicitTemplateArgs,
@@ -10403,9 +10411,11 @@ class Sema final {
   SourceLocation PointOfInstantiation, FunctionDecl *Decl,
   ArrayRef TemplateArgs,
   ConstraintSatisfaction &Satisfaction);
-  FunctionDecl *InstantiateFunctionDeclaration(FunctionTemplateDecl *FTD,
-   const TemplateArgumentList 
*Args,
-   SourceLocation Loc);
+  FunctionDecl *InstantiateFunctionDeclaration(
+  FunctionTemplateDecl *FTD, const TemplateArgumentList *Args,
+  SourceLocation Loc,
+  CodeSynthesisContext::SynthesisKind CSC =
+  CodeSynthesisContext::ExplicitTemplateArgumentSubstitution);
   void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
  FunctionDecl *Function,
  bool Recursive = false,
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 408ee5f775804b..d247fa74d553e1 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -10,12 +10,18 @@
 //
 
//===--===//
 
+#include "TreeTransform.h"
+#include "TypeLocBuilder.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclAccessPair.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
+#include "clang/AST/DeclTemplate.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/ExprOpenMP.h"
 #include "clang/AST/IgnoreExpr.h"
+#include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/SourceManager.h"
@@ -27,6 +33,7 @@
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Ownership.h"
 #include "clang/Sema/SemaInternal.h"
+#include "clang/Sema/Template.h"
 #include "llvm/ADT/APInt.h"
 #include "llvm/ADT/FoldingSet.h"
 #include "llvm/ADT/PointerIntPair.h"
@@ -10570,6 +10577,381 @@ static bool 
isOrIsDerivedFromSpecializationOf(CXXRecordDecl *RD,
   return !(NotSpecialization(RD) && RD->forallBases(NotSpecialization));
 }
 
+
+/// FIXME: this is a copy-paste from SemaTemplate.cpp
+/// Tree transform to "extract" a transformed type from a class template's
+/// constructor to a deduction guide.
+class ExtractTypeForDeductionGuide
+  : public TreeTransform {
+  llvm::SmallVectorImpl &MaterializedTypedefs;
+
+public:
+  typedef TreeTransform Base;
+  ExtractTypeForDeductionGuide(
+  Sema &SemaRef,
+  llvm::SmallVectorImpl &MaterializedTypedefs)
+  : Base(SemaRef), MaterializedTypedefs(MaterializedTypedefs) {}
+
+  TypeSourceInfo *transform(TypeSourceInfo *TSI) { return TransformType(TSI); }
+
+  QualType TransformTypedefType(TypeLocBuilder &TLB, TypedefTypeLoc TL) {
+ASTContext &Context = SemaRef.getASTContext();
+TypedefNameDecl *OrigDecl = TL.getTypedefNameDecl();
+TypedefNameDecl *Decl = OrigDecl;
+// Transform the underlying type of the typedef and 

[clang-tools-extra] dabc901 - [clangd] Use starts_with instead of startswith in CompileCommands.cpp (NFC)

2024-01-12 Thread Jie Fu via cfe-commits

Author: Jie Fu
Date: 2024-01-12T16:18:14+08:00
New Revision: dabc9018ee856dee672fb1035fd3eb1bb39bd7a6

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

LOG: [clangd] Use starts_with instead of startswith in CompileCommands.cpp (NFC)

llvm-project/clang-tools-extra/clangd/CompileCommands.cpp:324:52:
 error: 'startswith' is deprecated: Use starts_with instead 
[-Werror,-Wdeprecated-declarations]
  324 | Cmd, [&](llvm::StringRef Arg) { return Arg.startswith(Flag); });
  |^~
  |starts_with

Added: 


Modified: 
clang-tools-extra/clangd/CompileCommands.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index 1b4b24d59cb83a..166f17e9b3f712 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -321,7 +321,7 @@ void CommandMangler::operator()(tooling::CompileCommand 
&Command,
   // Check whether the flag appears in the command as a prefix.
   auto HasPrefix = [&](llvm::StringRef Flag) {
 return llvm::any_of(
-Cmd, [&](llvm::StringRef Arg) { return Arg.startswith(Flag); });
+Cmd, [&](llvm::StringRef Arg) { return Arg.starts_with(Flag); });
   };
 
   llvm::erase_if(Cmd, [](llvm::StringRef Elem) {



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


[clang] [clang][dataflow] Process terminator condition within `transferCFGBlock()`. (PR #77750)

2024-01-12 Thread via cfe-commits


@@ -489,6 +482,31 @@ transferCFGBlock(const CFGBlock &Block, AnalysisContext 
&AC,
 }
 AC.Log.recordState(State);
   }
+
+  // If we have a terminator, evaluate its condition.
+  // This `Expr` may not appear as a `CFGElement` anywhere else, and it's
+  // important that we evaluate it here (rather than while processing the
+  // terminator) so that we put the corresponding value in the right
+  // environment.
+  if (const Expr *TerminatorCond =
+  dyn_cast_or_null(Block.getTerminatorCondition())) {
+if (State.Env.getValue(*TerminatorCond) == nullptr)
+  // FIXME: This only runs the builtin transfer, not the analysis-specific
+  // transfer. Fixing this isn't trivial, as the analysis-specific transfer
+  // takes a `CFGElement` as input, but some expressions only show up as a
+  // terminator condition, but not as a `CFGElement`. The condition of an 
if

martinboehme wrote:

Hm, that's an idea!

I'd still like to leave this to a future patch, as it's a further change in 
behavior. Note that the code we had so far also only ran the builtin transfer; 
this FIXME just documents this previously undocumented deficiency, so we're not 
regressing in any way.

I'd like to make this change separately so that we can separate out any 
unwanted side-effects of the two changes.

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


[clang] [clang] WIP: Implement CTAD for type alias template. (PR #77890)

2024-01-12 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 98c6aa72299caeff6b188e1ff2fc1b39c5b893b6 
ccf08bb5e209c98bddcb39b28256cd85cecd93cd -- 
clang/test/SemaCXX/cxx20-ctad-type-alias.cpp clang/include/clang/Sema/Sema.h 
clang/lib/Sema/SemaInit.cpp clang/lib/Sema/SemaTemplateDeduction.cpp 
clang/lib/Sema/SemaTemplateInstantiate.cpp 
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6a6a30fc52..2bfc387175 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9251,13 +9251,11 @@ public:
   const TemplateArgumentList &TemplateArgs,
   sema::TemplateDeductionInfo &Info);
 
-  TemplateDeductionResult
-  DeduceTemplateArguments(TemplateParameterList *TemplateParams,
-  ArrayRef Ps,
-  ArrayRef As,
-  sema::TemplateDeductionInfo &Info,
-  SmallVectorImpl &Deduced,
-  bool NumberOfArgumentsMustMatch);
+  TemplateDeductionResult DeduceTemplateArguments(
+  TemplateParameterList *TemplateParams, ArrayRef Ps,
+  ArrayRef As, sema::TemplateDeductionInfo &Info,
+  SmallVectorImpl &Deduced,
+  bool NumberOfArgumentsMustMatch);
 
   TemplateDeductionResult SubstituteExplicitTemplateArguments(
   FunctionTemplateDecl *FunctionTemplate,
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index d247fa74d5..28d103b8d8 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -10577,12 +10577,11 @@ static bool 
isOrIsDerivedFromSpecializationOf(CXXRecordDecl *RD,
   return !(NotSpecialization(RD) && RD->forallBases(NotSpecialization));
 }
 
-
 /// FIXME: this is a copy-paste from SemaTemplate.cpp
 /// Tree transform to "extract" a transformed type from a class template's
 /// constructor to a deduction guide.
 class ExtractTypeForDeductionGuide
-  : public TreeTransform {
+: public TreeTransform {
   llvm::SmallVectorImpl &MaterializedTypedefs;
 
 public:
@@ -10626,7 +10625,8 @@ public:
   }
 };
 
-// Transform to form a corresponding deduction guide for type alias template 
decl.
+// Transform to form a corresponding deduction guide for type alias template
+// decl.
 //
 // This class implements the C++ [over.match.class.deduct]p3:
 //   ... Let g denote the result of substituting these deductions into f. If
@@ -10684,7 +10684,7 @@ struct AliasTemplateDeductionGuideTransform {
 int Index = 0;
 TemplateParameterList *TemplateParams = nullptr;
 
-for (TemplateTypeParmDecl* Param : DeducedTemplateTypeParDecls) {
+for (TemplateTypeParmDecl *Param : DeducedTemplateTypeParDecls) {
   MultiLevelTemplateArgumentList Args;
 
   Args.setKind(TemplateSubstitutionKind::Rewrite);
@@ -10706,7 +10706,7 @@ struct AliasTemplateDeductionGuideTransform {
 
 TemplateParams = TemplateParameterList::Create(
 SemaRef.Context, SourceLocation(), SourceLocation(), AllParams,
-SourceLocation(), /*requiresClause */nullptr);
+SourceLocation(), /*requiresClause */ nullptr);
 
 MultiLevelTemplateArgumentList Args;
 Args.setKind(TemplateSubstitutionKind::Rewrite);
@@ -10722,7 +10722,7 @@ struct AliasTemplateDeductionGuideTransform {
 // replacing references to the old parameters with references to the
 // new ones.
 TypeLocBuilder TLB;
-SmallVector Params;
+SmallVector Params;
 SmallVector MaterializedTypedefs;
 QualType NewType = transformFunctionProtoType(
 TLB, FPTL, Params, Args, UnderlyingCDGD->getReturnType(),
@@ -10745,16 +10745,16 @@ private:
   /// to earlier parameters and renumbering as we go.
   NamedDecl *transformTemplateParameter(NamedDecl *TemplateParam,
 MultiLevelTemplateArgumentList &Args,
-int Index ) {
+int Index) {
 if (auto *TTP = dyn_cast(TemplateParam)) {
   // TemplateTypeParmDecl's index cannot be changed after creation, so
   // substitute it directly.
   auto *NewTTP = TemplateTypeParmDecl::Create(
   SemaRef.Context, DC, TTP->getBeginLoc(), TTP->getLocation(),
   // FIXME: is the depth/index right?
-  TTP->getDepth(),  Index,
-  TTP->getIdentifier(), TTP->wasDeclaredWithTypename(),
-  TTP->isParameterPack(), TTP->hasTypeConstraint(),
+  TTP->getDepth(), Index, TTP->getIdentifier(),
+  TTP->wasDeclaredWithTypename(), TTP->isParameterPack(),
+  TTP->hasTypeConstraint(),
   TTP->isExpandedParameterPack()
 

[clang] 537bbb4 - [clang][dataflow] Process terminator condition within `transferCFGBlock()`. (#77750)

2024-01-12 Thread via cfe-commits

Author: martinboehme
Date: 2024-01-12T09:20:58+01:00
New Revision: 537bbb4688b021c7eb7045ffd0d5f63087af83c3

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

LOG: [clang][dataflow] Process terminator condition within 
`transferCFGBlock()`. (#77750)

In particular, it's important that we create the "fallback" atomic at
this point
(which we produce if the transfer function didn't produce a value for
the
expression) so that it is placed in the correct environment.

Previously, we processed the terminator condition in the
`TerminatorVisitor`,
which put the fallback atomic in a copy of the environment that is
produced as
input for the _successor_ block, rather than the environment for the
block
containing the expression for which we produce the fallback atomic.

As a result, we produce different fallback atomics every time we process
the
successor block, and hence we don't have a consistent representation of
the
terminator condition in the flow condition.

This patch includes a test (authored by ymand@) that fails without the
fix.

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index faf83a8920d4ea..fdb2aeacf063ab 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -126,19 +126,12 @@ class TerminatorVisitor
 
 private:
   TerminatorVisitorRetTy extendFlowCondition(const Expr &Cond) {
-// The terminator sub-expression might not be evaluated.
-if (Env.getValue(Cond) == nullptr)
-  transfer(StmtToEnv, Cond, Env);
-
 auto *Val = Env.get(Cond);
-// Value merging depends on flow conditions from 
diff erent environments
-// being mutually exclusive -- that is, they cannot both be true in their
-// entirety (even if they may share some clauses). So, we need *some* value
-// for the condition expression, even if just an atom.
-if (Val == nullptr) {
-  Val = &Env.makeAtomicBoolValue();
-  Env.setValue(Cond, *Val);
-}
+// In transferCFGBlock(), we ensure that we always have a `Value` for the
+// terminator condition, so assert this.
+// We consciously assert ourselves instead of asserting via `cast()` so
+// that we get a more meaningful line number if the assertion fails.
+assert(Val != nullptr);
 
 bool ConditionValue = true;
 // The condition must be inverted for the successor that encompasses the
@@ -489,6 +482,31 @@ transferCFGBlock(const CFGBlock &Block, AnalysisContext 
&AC,
 }
 AC.Log.recordState(State);
   }
+
+  // If we have a terminator, evaluate its condition.
+  // This `Expr` may not appear as a `CFGElement` anywhere else, and it's
+  // important that we evaluate it here (rather than while processing the
+  // terminator) so that we put the corresponding value in the right
+  // environment.
+  if (const Expr *TerminatorCond =
+  dyn_cast_or_null(Block.getTerminatorCondition())) {
+if (State.Env.getValue(*TerminatorCond) == nullptr)
+  // FIXME: This only runs the builtin transfer, not the analysis-specific
+  // transfer. Fixing this isn't trivial, as the analysis-specific transfer
+  // takes a `CFGElement` as input, but some expressions only show up as a
+  // terminator condition, but not as a `CFGElement`. The condition of an 
if
+  // statement is one such example.
+  transfer(StmtToEnvMap(AC.CFCtx, AC.BlockStates), *TerminatorCond,
+   State.Env);
+
+// If the transfer function didn't produce a value, create an atom so that
+// we have *some* value for the condition expression. This ensures that
+// when we extend the flow condition, it actually changes.
+if (State.Env.getValue(*TerminatorCond) == nullptr)
+  State.Env.setValue(*TerminatorCond, State.Env.makeAtomicBoolValue());
+AC.Log.recordState(State);
+  }
+
   return State;
 }
 

diff  --git a/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
index a60dbe1f61f6d6..c5594aa3fe9d1f 100644
--- a/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
@@ -123,6 +123,7 @@ recordState(Elements=1, Branches=0, Joins=0)
 enterElement(b (ImplicitCastExpr, LValueToRValue, _Bool))
 transfer()
 recordState(Elements=2, Branches=0, Joins=0)
+recordState(Elements=2, Branches=0, Joins=0)
 
 enterBlock(3, false)
 transferBranch(0)

diff  --git a/clang/unittes

[clang] [clang][dataflow] Process terminator condition within `transferCFGBlock()`. (PR #77750)

2024-01-12 Thread via cfe-commits

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


[clang] [clang][analyzer] Add function 'fprintf' to StreamChecker. (PR #77613)

2024-01-12 Thread Balázs Kéri via cfe-commits

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

From 96a786f07ca5fb84b372e0b7c60f371bf4cdfd7c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Wed, 10 Jan 2024 10:55:27 +0100
Subject: [PATCH] [clang][analyzer] Add function 'fprintf' to StreamChecker.

---
 .../StaticAnalyzer/Checkers/StreamChecker.cpp | 49 +++
 clang/test/Analysis/stream-error.c| 17 +++
 clang/test/Analysis/stream.c  | 11 +++--
 3 files changed, 74 insertions(+), 3 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
index 742426a628e065..95c7503e49e0d3 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -263,6 +263,9 @@ class StreamChecker : public Checker(Call.getOriginExpr());
+  if (!CE)
+return;
+
+  const StreamState *OldSS = State->get(StreamSym);
+  if (!OldSS)
+return;
+
+  assertStreamStateOpened(OldSS);
+
+  NonLoc RetVal = makeRetVal(C, CE).castAs();
+  State = State->BindExpr(CE, C.getLocationContext(), RetVal);
+  SValBuilder &SVB = C.getSValBuilder();
+  auto &ACtx = C.getASTContext();
+  auto Cond = SVB.evalBinOp(State, BO_GE, RetVal, SVB.makeZeroVal(ACtx.IntTy),
+SVB.getConditionType())
+  .getAs();
+  if (!Cond)
+return;
+  ProgramStateRef StateNotFailed, StateFailed;
+  std::tie(StateNotFailed, StateFailed) = State->assume(*Cond);
+
+  StateNotFailed =
+  StateNotFailed->set(StreamSym, StreamState::getOpened(Desc));
+  C.addTransition(StateNotFailed);
+
+  // Add transition for the failed state. The resulting value of the file
+  // position indicator for the stream is indeterminate.
+  StateFailed = StateFailed->set(
+  StreamSym, StreamState::getOpened(Desc, ErrorFError, true));
+  C.addTransition(StateFailed);
+}
+
 void StreamChecker::evalUngetc(const FnDescription *Desc, const CallEvent 
&Call,
CheckerContext &C) const {
   ProgramStateRef State = C.getState();
diff --git a/clang/test/Analysis/stream-error.c 
b/clang/test/Analysis/stream-error.c
index 2d03c0bbe7c474..0f7fdddc0dd4cd 100644
--- a/clang/test/Analysis/stream-error.c
+++ b/clang/test/Analysis/stream-error.c
@@ -191,6 +191,23 @@ void error_fputs(void) {
   fputs("ABC", F); // expected-warning {{Stream might be already closed}}
 }
 
+void error_fprintf(void) {
+  FILE *F = tmpfile();
+  if (!F)
+return;
+  int Ret = fprintf(F, "aaa");
+  if (Ret >= 0) {
+clang_analyzer_eval(feof(F) || ferror(F)); // expected-warning {{FALSE}}
+fprintf(F, "bbb"); // no-warning
+  } else {
+clang_analyzer_eval(ferror(F)); // expected-warning {{TRUE}}
+clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
+fprintf(F, "bbb");  // expected-warning {{might be 
'indeterminate'}}
+  }
+  fclose(F);
+  fprintf(F, "ccc"); // expected-warning {{Stream might be already closed}}
+}
+
 void error_ungetc() {
   FILE *F = tmpfile();
   if (!F)
diff --git a/clang/test/Analysis/stream.c b/clang/test/Analysis/stream.c
index d8026247697a50..e8f06922bdb2f3 100644
--- a/clang/test/Analysis/stream.c
+++ b/clang/test/Analysis/stream.c
@@ -39,6 +39,12 @@ void check_fputs(void) {
   fclose(fp);
 }
 
+void check_fprintf(void) {
+  FILE *fp = tmpfile();
+  fprintf(fp, "ABC"); // expected-warning {{Stream pointer might be NULL}}
+  fclose(fp);
+}
+
 void check_ungetc(void) {
   FILE *fp = tmpfile();
   ungetc('A', fp); // expected-warning {{Stream pointer might be NULL}}
@@ -271,9 +277,8 @@ void check_escape4(void) {
 return;
   fwrite("1", 1, 1, F); // may fail
 
-  // no escape at (non-StreamChecker-handled) system call
-  // FIXME: all such calls should be handled by the checker
-  fprintf(F, "0");
+  // no escape at a non-StreamChecker-handled system call
+  setbuf(F, "0");
 
   fwrite("1", 1, 1, F); // expected-warning {{might be 'indeterminate'}}
   fclose(F);

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


[clang] ef156f9 - [clang][dataflow] Remove unused private field 'StmtToEnv' (NFC)

2024-01-12 Thread Jie Fu via cfe-commits

Author: Jie Fu
Date: 2024-01-12T16:26:00+08:00
New Revision: ef156f91262e960eea5ca93f95dd6111cfa3c5cc

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

LOG: [clang][dataflow] Remove unused private field 'StmtToEnv' (NFC)

llvm-project/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp:148:23:
 error: private field 'StmtToEnv' is not used [-Werror,-Wunused-private-field]
  148 |   const StmtToEnvMap &StmtToEnv;
  |   ^
1 error generated.

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index fdb2aeacf063ab..24d1447f09794a 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -77,7 +77,7 @@ class TerminatorVisitor
 public:
   TerminatorVisitor(const StmtToEnvMap &StmtToEnv, Environment &Env,
 int BlockSuccIdx)
-  : StmtToEnv(StmtToEnv), Env(Env), BlockSuccIdx(BlockSuccIdx) {}
+  : Env(Env), BlockSuccIdx(BlockSuccIdx) {}
 
   TerminatorVisitorRetTy VisitIfStmt(const IfStmt *S) {
 auto *Cond = S->getCond();
@@ -145,7 +145,6 @@ class TerminatorVisitor
 return {&Cond, ConditionValue};
   }
 
-  const StmtToEnvMap &StmtToEnv;
   Environment &Env;
   int BlockSuccIdx;
 };



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


[clang] [clang][Interp] Implement IntegralAP::{div, rem} (PR #72614)

2024-01-12 Thread Timm Baeder via cfe-commits

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

>From 8b657f24c900d9e123a74c76eb3c12c1d34f1a93 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Thu, 16 Nov 2023 18:05:17 +0100
Subject: [PATCH] [clang][Interp] Implement IntegralAP::{div, rem}

---
 clang/lib/AST/Interp/IntegralAP.h | 12 
 clang/test/AST/Interp/intap.cpp   | 30 ++
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index d5f46409d231d48..55e29caa1cd7471 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -204,14 +204,18 @@ template  class IntegralAP final {
   }
 
   static bool rem(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
-// FIXME: Implement.
-assert(false);
+if constexpr (Signed)
+  *R = IntegralAP(A.V.srem(B.V));
+else
+  *R = IntegralAP(A.V.urem(B.V));
 return false;
   }
 
   static bool div(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
-// FIXME: Implement.
-assert(false);
+if constexpr (Signed)
+  *R = IntegralAP(A.V.sdiv(B.V));
+else
+  *R = IntegralAP(A.V.udiv(B.V));
 return false;
   }
 
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index b99422dc8f93125..118dc21b67e875f 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -5,6 +5,7 @@
 
 
 using MaxBitInt = _BitInt(128);
+#define INT_MIN (~__INT_MAX__)
 
 constexpr _BitInt(2) A = 0;
 constexpr _BitInt(2) B = A + 1;
@@ -44,6 +45,35 @@ static_assert(MulA * MulB == 50, ""); // ref-error {{not an 
integral constant ex
 static_assert(MulA * 5 == 25, "");
 static_assert(-1 * MulB == -7, "");
 
+
+constexpr _BitInt(4) DivA = 2;
+constexpr _BitInt(2) DivB = 1;
+static_assert(DivA / DivB == 2, "");
+
+constexpr _BitInt(4) DivC = DivA / 0; // ref-error {{must be initialized by a 
constant expression}} \
+  // ref-note {{division by zero}} \
+  // expected-error {{must be initialized 
by a constant expression}} \
+  // expected-note {{division by zero}}
+
+constexpr _BitInt(7) RemA = 47;
+constexpr _BitInt(6) RemB = 9;
+static_assert(RemA % RemB == 2, "");
+static_assert(RemA % 0 == 1, ""); // ref-error {{not an integral constant 
expression}} \
+  // ref-note {{division by zero}} \
+  // expected-error {{not an integral constant 
expression}} \
+  // expected-note {{division by zero}}
+
+constexpr _BitInt(32) bottom = -1;
+constexpr _BitInt(32) top = INT_MIN;
+constexpr _BitInt(32) nope = top / bottom;  // ref-error {{must be initialized 
by a constant expression}} \
+// ref-note {{value 2147483648 is 
outside the range}} \
+// expected-error {{must be 
initialized by a constant expression}} \
+// expected-note {{value 
2147483648 is outside the range}}
+constexpr _BitInt(32) n = top % bottom; // ref-error {{must be initialized 
by a constant expression}} \
+// ref-note {{value 2147483648 is 
outside the range}} \
+// expected-error {{must be 
initialized by a constant expression}} \
+// expected-note {{value 
2147483648 is outside the range}}
+
 namespace APCast {
   constexpr _BitInt(10) A = 1;
   constexpr _BitInt(11) B = A;

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


[clang] [clang][Interp] Implement IntegralAP::{div, rem} (PR #72614)

2024-01-12 Thread Timm Baeder via cfe-commits


@@ -44,6 +44,24 @@ static_assert(MulA * MulB == 50, ""); // ref-error {{not an 
integral constant ex
 static_assert(MulA * 5 == 25, "");
 static_assert(-1 * MulB == -7, "");
 
+
+constexpr _BitInt(4) DivA = 2;
+constexpr _BitInt(2) DivB = 1;
+static_assert(DivA / DivB == 2, "");
+
+constexpr _BitInt(4) DivC = DivA / 0; // ref-error {{must be initialized by a 
constant expression}} \

tbaederr wrote:

Using `int` means it won't use `IntegralAP` at all though. I've added those 
tests with `_BitInt(32)`.

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


[clang] [llvm] AMDGPU/GFX12: Add new dot4 fp8/bf8 instructions (PR #77892)

2024-01-12 Thread Mariusz Sikora via cfe-commits

https://github.com/mariusz-sikora-at-amd created 
https://github.com/llvm/llvm-project/pull/77892

Endoding is VOP3P. Tagged as deep/machine learning instructions. i32 type 
(v4fp8 or v4bf8 packed in i32) is used for src0 and src1. src0 and src1 have no 
src_modifiers. src2 is f32 and has src_modifiers: f32 fneg(neg_lo[2]) and f32 
fabs(neg_hi[2]).

>From 628a3d2b42cdcbd903e0830ab7d631ea7dc422b9 Mon Sep 17 00:00:00 2001
From: Petar Avramovic 
Date: Wed, 10 Jan 2024 12:17:58 +0100
Subject: [PATCH] AMDGPU/GFX12: Add new dot4 fp8/bf8 instructions

Endoding is VOP3P. Tagged as deep/machine learning instructions.
i32 type (v4fp8 or v4bf8 packed in i32) is used for src0 and src1.
src0 and src1 have no src_modifiers. src2 is f32 and has src_modifiers:
f32 fneg(neg_lo[2]) and f32 fabs(neg_hi[2]).
---
 clang/include/clang/Basic/BuiltinsAMDGPU.def  |   4 +
 .../builtins-amdgcn-dl-insts-err.cl   |   5 +
 .../builtins-amdgcn-dl-insts-gfx12.cl |  20 ++
 llvm/include/llvm/IR/IntrinsicsAMDGPU.td  |  19 ++
 .../Target/AMDGPU/AMDGPURegisterBankInfo.cpp  |   4 +
 .../AMDGPU/AsmParser/AMDGPUAsmParser.cpp  |  46 
 .../AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp |  17 +-
 llvm/lib/Target/AMDGPU/VOP3PInstructions.td   |  47 
 llvm/lib/Target/AMDGPU/VOPInstructions.td |  13 +-
 .../CodeGen/AMDGPU/llvm.amdgcn.fdot4.f32.ll   | 255 ++
 llvm/test/MC/AMDGPU/gfx12_asm_vop3p.s | 120 +
 llvm/test/MC/AMDGPU/gfx12_asm_vop3p_dpp16.s   |  24 ++
 .../MC/AMDGPU/gfx12_asm_vop3p_dpp16_err.s |  24 ++
 llvm/test/MC/AMDGPU/gfx12_asm_vop3p_dpp8.s|  24 ++
 .../test/MC/AMDGPU/gfx12_asm_vop3p_dpp8_err.s |  27 ++
 llvm/test/MC/AMDGPU/gfx12_asm_vop3p_err.s | 133 +
 .../Disassembler/AMDGPU/gfx12_dasm_vop3p.txt  | 120 +
 .../AMDGPU/gfx12_dasm_vop3p_dpp16.txt |  24 ++
 .../AMDGPU/gfx12_dasm_vop3p_dpp8.txt  |  24 ++
 19 files changed, 938 insertions(+), 12 deletions(-)
 create mode 100644 clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-gfx12.cl
 create mode 100644 llvm/test/CodeGen/AMDGPU/llvm.amdgcn.fdot4.f32.ll
 create mode 100644 llvm/test/MC/AMDGPU/gfx12_asm_vop3p_dpp16_err.s
 create mode 100644 llvm/test/MC/AMDGPU/gfx12_asm_vop3p_dpp8_err.s
 create mode 100644 llvm/test/MC/AMDGPU/gfx12_asm_vop3p_err.s

diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index e562ef04a30194..1c1b9b2c9e9e8c 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -255,6 +255,10 @@ TARGET_BUILTIN(__builtin_amdgcn_sudot4, "iIbiIbiiIb", 
"nc", "dot8-insts")
 TARGET_BUILTIN(__builtin_amdgcn_sdot8, "SiSiSiSiIb", "nc", "dot1-insts")
 TARGET_BUILTIN(__builtin_amdgcn_udot8, "UiUiUiUiIb", "nc", "dot7-insts")
 TARGET_BUILTIN(__builtin_amdgcn_sudot8, "iIbiIbiiIb", "nc", "dot8-insts")
+TARGET_BUILTIN(__builtin_amdgcn_fdot4_f32_fp8_bf8, "fUiUif", "nc", 
"gfx12-insts")
+TARGET_BUILTIN(__builtin_amdgcn_fdot4_f32_bf8_fp8, "fUiUif", "nc", 
"gfx12-insts")
+TARGET_BUILTIN(__builtin_amdgcn_fdot4_f32_fp8_fp8, "fUiUif", "nc", 
"gfx12-insts")
+TARGET_BUILTIN(__builtin_amdgcn_fdot4_f32_bf8_bf8, "fUiUif", "nc", 
"gfx12-insts")
 
 
//===--===//
 // GFX10+ only builtins.
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-err.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-err.cl
index 6573325150d958..1be47f71276208 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-err.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-err.cl
@@ -49,4 +49,9 @@ kernel void builtins_amdgcn_dl_insts_err(
 
   iOut[3] = __builtin_amdgcn_sudot8(false, A, true, B, C, false);// 
expected-error {{'__builtin_amdgcn_sudot8' needs target feature dot8-insts}}
   iOut[4] = __builtin_amdgcn_sudot8(true, A, false, B, C, true); // 
expected-error {{'__builtin_amdgcn_sudot8' needs target feature dot8-insts}}
+
+  fOut[5] = __builtin_amdgcn_fdot4_f32_fp8_bf8(uiA, uiB, fC);// 
expected-error {{'__builtin_amdgcn_fdot4_f32_fp8_bf8' needs target feature 
gfx12-insts}}
+  fOut[6] = __builtin_amdgcn_fdot4_f32_bf8_fp8(uiA, uiB, fC);// 
expected-error {{'__builtin_amdgcn_fdot4_f32_bf8_fp8' needs target feature 
gfx12-insts}}
+  fOut[7] = __builtin_amdgcn_fdot4_f32_fp8_fp8(uiA, uiB, fC);// 
expected-error {{'__builtin_amdgcn_fdot4_f32_fp8_fp8' needs target feature 
gfx12-insts}}
+  fOut[8] = __builtin_amdgcn_fdot4_f32_bf8_bf8(uiA, uiB, fC);// 
expected-error {{'__builtin_amdgcn_fdot4_f32_bf8_bf8' needs target feature 
gfx12-insts}}
 }
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-gfx12.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-gfx12.cl
new file mode 100644
index 00..31e10c0a5dc18c
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-gfx12.cl
@@ -0,0 +1,20 @@
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1

[clang] [llvm] AMDGPU/GFX12: Add new dot4 fp8/bf8 instructions (PR #77892)

2024-01-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-amdgpu

Author: Mariusz Sikora (mariusz-sikora-at-amd)


Changes

Endoding is VOP3P. Tagged as deep/machine learning instructions. i32 type 
(v4fp8 or v4bf8 packed in i32) is used for src0 and src1. src0 and src1 have no 
src_modifiers. src2 is f32 and has src_modifiers: f32 fneg(neg_lo[2]) and f32 
fabs(neg_hi[2]).

---

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


19 Files Affected:

- (modified) clang/include/clang/Basic/BuiltinsAMDGPU.def (+4) 
- (modified) clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-err.cl (+5) 
- (added) clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-gfx12.cl (+20) 
- (modified) llvm/include/llvm/IR/IntrinsicsAMDGPU.td (+19) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp (+4) 
- (modified) llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp (+46) 
- (modified) llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUInstPrinter.cpp (+11-6) 
- (modified) llvm/lib/Target/AMDGPU/VOP3PInstructions.td (+47) 
- (modified) llvm/lib/Target/AMDGPU/VOPInstructions.td (+7-6) 
- (added) llvm/test/CodeGen/AMDGPU/llvm.amdgcn.fdot4.f32.ll (+255) 
- (modified) llvm/test/MC/AMDGPU/gfx12_asm_vop3p.s (+120) 
- (modified) llvm/test/MC/AMDGPU/gfx12_asm_vop3p_dpp16.s (+24) 
- (added) llvm/test/MC/AMDGPU/gfx12_asm_vop3p_dpp16_err.s (+24) 
- (modified) llvm/test/MC/AMDGPU/gfx12_asm_vop3p_dpp8.s (+24) 
- (added) llvm/test/MC/AMDGPU/gfx12_asm_vop3p_dpp8_err.s (+27) 
- (added) llvm/test/MC/AMDGPU/gfx12_asm_vop3p_err.s (+133) 
- (modified) llvm/test/MC/Disassembler/AMDGPU/gfx12_dasm_vop3p.txt (+120) 
- (modified) llvm/test/MC/Disassembler/AMDGPU/gfx12_dasm_vop3p_dpp16.txt (+24) 
- (modified) llvm/test/MC/Disassembler/AMDGPU/gfx12_dasm_vop3p_dpp8.txt (+24) 


``diff
diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index e562ef04a30194..1c1b9b2c9e9e8c 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -255,6 +255,10 @@ TARGET_BUILTIN(__builtin_amdgcn_sudot4, "iIbiIbiiIb", 
"nc", "dot8-insts")
 TARGET_BUILTIN(__builtin_amdgcn_sdot8, "SiSiSiSiIb", "nc", "dot1-insts")
 TARGET_BUILTIN(__builtin_amdgcn_udot8, "UiUiUiUiIb", "nc", "dot7-insts")
 TARGET_BUILTIN(__builtin_amdgcn_sudot8, "iIbiIbiiIb", "nc", "dot8-insts")
+TARGET_BUILTIN(__builtin_amdgcn_fdot4_f32_fp8_bf8, "fUiUif", "nc", 
"gfx12-insts")
+TARGET_BUILTIN(__builtin_amdgcn_fdot4_f32_bf8_fp8, "fUiUif", "nc", 
"gfx12-insts")
+TARGET_BUILTIN(__builtin_amdgcn_fdot4_f32_fp8_fp8, "fUiUif", "nc", 
"gfx12-insts")
+TARGET_BUILTIN(__builtin_amdgcn_fdot4_f32_bf8_bf8, "fUiUif", "nc", 
"gfx12-insts")
 
 
//===--===//
 // GFX10+ only builtins.
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-err.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-err.cl
index 6573325150d958..1be47f71276208 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-err.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-err.cl
@@ -49,4 +49,9 @@ kernel void builtins_amdgcn_dl_insts_err(
 
   iOut[3] = __builtin_amdgcn_sudot8(false, A, true, B, C, false);// 
expected-error {{'__builtin_amdgcn_sudot8' needs target feature dot8-insts}}
   iOut[4] = __builtin_amdgcn_sudot8(true, A, false, B, C, true); // 
expected-error {{'__builtin_amdgcn_sudot8' needs target feature dot8-insts}}
+
+  fOut[5] = __builtin_amdgcn_fdot4_f32_fp8_bf8(uiA, uiB, fC);// 
expected-error {{'__builtin_amdgcn_fdot4_f32_fp8_bf8' needs target feature 
gfx12-insts}}
+  fOut[6] = __builtin_amdgcn_fdot4_f32_bf8_fp8(uiA, uiB, fC);// 
expected-error {{'__builtin_amdgcn_fdot4_f32_bf8_fp8' needs target feature 
gfx12-insts}}
+  fOut[7] = __builtin_amdgcn_fdot4_f32_fp8_fp8(uiA, uiB, fC);// 
expected-error {{'__builtin_amdgcn_fdot4_f32_fp8_fp8' needs target feature 
gfx12-insts}}
+  fOut[8] = __builtin_amdgcn_fdot4_f32_bf8_bf8(uiA, uiB, fC);// 
expected-error {{'__builtin_amdgcn_fdot4_f32_bf8_bf8' needs target feature 
gfx12-insts}}
 }
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-gfx12.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-gfx12.cl
new file mode 100644
index 00..31e10c0a5dc18c
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-dl-insts-gfx12.cl
@@ -0,0 +1,20 @@
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx1200 -S 
-emit-llvm -o - %s | FileCheck %s
+
+typedef unsigned int uint;
+
+// CHECK-LABEL: @builtins_amdgcn_dl_insts
+// CHECK: call float @llvm.amdgcn.fdot4.f32.fp8.bf8(i32 %uiA, i32 %uiB, float 
%fC)
+// CHECK: call float @llvm.amdgcn.fdot4.f32.bf8.fp8(i32 %uiA, i32 %uiB, float 
%fC)
+// CHECK: call float @llvm.amdgcn.fdot4.f32.fp8.fp8(i32 %uiA, i32 %uiB, float 
%fC)
+// CHECK: call float @llvm.amdgcn.fdot4.f32.bf8.bf8(i3

[clang] c65b939 - [clang-format] SpacesInSquareBrackets not working for Java (#77833)

2024-01-12 Thread via cfe-commits

Author: MyDeveloperDay
Date: 2024-01-12T08:30:53Z
New Revision: c65b939fb795ce4688d33531341d460a47d16664

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

LOG: [clang-format] SpacesInSquareBrackets not working for Java (#77833)

spaces in [] needs to be handled the same in Java the same as C#.

Co-authored-by: paul_hoad 

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestJava.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index d2f6932880df53..24ce18a64348c1 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4674,6 +4674,10 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine &Line,
   } else if (Style.Language == FormatStyle::LK_Java) {
 if (Left.is(tok::r_square) && Right.is(tok::l_brace))
   return true;
+// spaces inside square brackets.
+if (Left.is(tok::l_square) || Right.is(tok::r_square))
+  return Style.SpacesInSquareBrackets;
+
 if (Left.is(Keywords.kw_synchronized) && Right.is(tok::l_paren)) {
   return Style.SpaceBeforeParensOptions.AfterControlStatements ||
  spaceRequiredBeforeParens(Right);

diff  --git a/clang/unittests/Format/FormatTestJava.cpp 
b/clang/unittests/Format/FormatTestJava.cpp
index 202d603d057790..6da5f4fa254331 100644
--- a/clang/unittests/Format/FormatTestJava.cpp
+++ b/clang/unittests/Format/FormatTestJava.cpp
@@ -603,6 +603,21 @@ TEST_F(FormatTestJava, ShortFunctions) {
Style);
 }
 
+TEST_F(FormatTestJava, ConfigurableSpacesInSquareBrackets) {
+  FormatStyle Spaces = getLLVMStyle(FormatStyle::LK_Java);
+
+  verifyFormat("Object[] arguments", Spaces);
+  verifyFormat("final Class[] types = new Class[numElements];", Spaces);
+  verifyFormat("types[i] = arguments[i].getClass();", Spaces);
+
+  Spaces.SpacesInSquareBrackets = true;
+
+  verifyFormat("Object[ ] arguments", Spaces);
+  verifyFormat("final Class[ ] types = new Class[ numElements ];",
+   Spaces);
+  verifyFormat("types[ i ] = arguments[ i ].getClass();", Spaces);
+}
+
 } // namespace
 } // namespace test
 } // namespace format



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


[lldb] [lld] [openmp] [libcxx] [mlir] [clang] [compiler-rt] [flang] [llvm] [clang-format] SpacesInSquareBrackets not working for Java (PR #77833)

2024-01-12 Thread via cfe-commits

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


[compiler-rt] [lldb] [libc] [lld] [flang] [clang-tools-extra] [libcxx] [clang] [llvm] [AMDGPU] Use alias info to relax waitcounts for LDS DMA (PR #74537)

2024-01-12 Thread Matt Arsenault via cfe-commits


@@ -1183,9 +1228,21 @@ bool 
SIInsertWaitcnts::generateWaitcntInstBefore(MachineInstr &MI,
 // No need to wait before load from VMEM to LDS.
 if (TII->mayWriteLDSThroughDMA(MI))
   continue;
-unsigned RegNo = SQ_MAX_PGM_VGPRS + EXTRA_VGPR_LDS;
+
 // VM_CNT is only relevant to vgpr or LDS.
-ScoreBrackets.determineWait(VM_CNT, RegNo, Wait);
+unsigned RegNo = SQ_MAX_PGM_VGPRS + EXTRA_VGPR_LDS;
+bool FoundAliasingStore = false;
+if (Ptr && Memop->getAAInfo() && Memop->getAAInfo().Scope) {

arsenm wrote:

I still don't understand the usage of scope; scope isn't special, isn't common 
and I do at all like specially treating it. I think you should just let the AA 
query figure out what to do with it 

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


[lldb] [libc] [lld] [libcxx] [clang] [compiler-rt] [flang] [clang-tools-extra] [llvm] [AMDGPU] Use alias info to relax waitcounts for LDS DMA (PR #74537)

2024-01-12 Thread Matt Arsenault via cfe-commits


@@ -130,6 +130,8 @@
 ; GCN-O0-NEXT:MachineDominator Tree Construction
 ; GCN-O0-NEXT:Machine Natural Loop Construction
 ; GCN-O0-NEXT:MachinePostDominator Tree Construction
+; GCN-O0-NEXT:Basic Alias Analysis (stateless AA impl)
+; GCN-O0-NEXT:Function Alias Analysis Results

arsenm wrote:

Can you skip querying for AA at -O0?

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


[libc] [clang] [libcxx] [llvm] [clang-tools-extra] [flang] [compiler-rt] [lldb] [lld] [AMDGPU] Use alias info to relax waitcounts for LDS DMA (PR #74537)

2024-01-12 Thread Matt Arsenault via cfe-commits


@@ -703,8 +713,37 @@ void WaitcntBrackets::updateByEvent(const SIInstrInfo *TII,
 setRegScore(RegNo, T, CurrScore);
   }
 }
-if (Inst.mayStore() && (TII->isDS(Inst) || mayWriteLDSThroughDMA(Inst))) {
-  setRegScore(SQ_MAX_PGM_VGPRS + EXTRA_VGPR_LDS, T, CurrScore);
+if (Inst.mayStore() &&
+(TII->isDS(Inst) || TII->mayWriteLDSThroughDMA(Inst))) {
+  // MUBUF and FLAT LDS DMA operations need a wait on vmcnt before LDS
+  // written can be accessed. A load from LDS to VMEM does not need a wait.
+  unsigned Slot = 0;
+  for (const auto *MemOp : Inst.memoperands()) {
+if (!MemOp->isStore() ||
+MemOp->getAddrSpace() != AMDGPUAS::LOCAL_ADDRESS)
+  continue;
+// Comparing just AA info does not guarantee memoperands are equal

arsenm wrote:

But there's no PseudoSourceValue in this example, it should be a 
straightforward Value-to-Value comparison 

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


[llvm] [clang] [X86] Add "Ws" constraint and "p" modifier for symbolic address/label reference (PR #77886)

2024-01-12 Thread Phoebe Wang via cfe-commits


@@ -0,0 +1,34 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=i686 < %s | FileCheck %s
+; RUN: llc -mtriple=x86_64 < %s | FileCheck %s
+
+@var = external dso_local global i32, align 4
+
+define dso_local void @test() {
+; CHECK-LABEL: test:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:#APP
+; CHECK-NEXT:# var test
+; CHECK-NEXT:#NO_APP
+; CHECK-NEXT:ret{{[l|q]}}
+entry:
+  call void asm sideeffect "// ${0:p} ${1:p}", 
"^Ws,^Ws,~{dirflag},~{fpsr},~{flags}"(ptr @var, ptr @test)
+  ret void
+}
+
+define dso_local void @test_label() {
+; CHECK-LABEL: test_label:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:  .Ltmp0: # Block address taken
+; CHECK-NEXT:  # %bb.1: # %label
+; CHECK-NEXT:#APP
+; CHECK-NEXT:# .Ltmp0
+; CHECK-NEXT:#NO_APP
+; CHECK-NEXT:ret{{[l|q]}}
+entry:
+  br label %label
+
+label:
+  tail call void asm sideeffect "// ${0:p}", 
"Ws,~{dirflag},~{fpsr},~{flags}"(ptr blockaddress(@test_label, %label))

phoebewang wrote:

Missing a `^` before `Ws`?

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


[llvm] [clang] [X86] Add "Ws" constraint and "p" modifier for symbolic address/label reference (PR #77886)

2024-01-12 Thread Phoebe Wang via cfe-commits


@@ -56966,6 +56965,17 @@ void 
X86TargetLowering::LowerAsmOperandForConstraint(SDValue Op,
 }
 return;
   }
+  case 'W': {
+assert(Constraint[1] == 's');
+if (const auto *GA = dyn_cast(Op)) {
+  Ops.push_back(DAG.getTargetGlobalAddress(GA->getGlobal(), SDLoc(Op),
+   GA->getValueType(0)));
+} else if (const auto *BA = dyn_cast(Op)) {
+  Ops.push_back(DAG.getTargetBlockAddress(BA->getBlockAddress(),
+  BA->getValueType(0)));
+}

phoebewang wrote:

Don't need parentheses here.

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


[llvm] [clang] [X86] Add "Ws" constraint and "p" modifier for symbolic address/label reference (PR #77886)

2024-01-12 Thread Phoebe Wang via cfe-commits


@@ -5336,6 +5336,7 @@ X86:
   operand in a SSE register. If AVX is also enabled, can also be a 256-bit
   vector operand in an AVX register. If AVX-512 is also enabled, can also be a
   512-bit vector operand in an AVX512 register. Otherwise, an error.
+- ``Ws``: A symbolic reference or label reference.

phoebewang wrote:

What's the reason to choose `Ws`?

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


[clang] [clang] Fix crash when compiling error with invalid decl (PR #77893)

2024-01-12 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky created 
https://github.com/llvm/llvm-project/pull/77893

`APValue::LValueBase::LValueBase` constructs `ValueDecl` with its 
canonicalDecl, even though it's invalid. And when obtain its type, it also 
check all redecls and ignore checking if it's valid. This will cause crash in 
invalid code. This patch fixes this issue by checking its validation and skip 
invalid decls.
Fix [issue](https://github.com/llvm/llvm-project/issues/69468)

>From 15c32039dfa8613a9ac992166dcb924cdd09ffa8 Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Thu, 11 Jan 2024 13:02:21 +0800
Subject: [PATCH 1/2] [Clang][SemaCXX] improve sema check of clang::musttail
 attribute

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++
 clang/lib/Sema/SemaStmt.cpp  | 6 ++
 clang/test/SemaCXX/PR76631.cpp   | 7 +++
 3 files changed, 15 insertions(+)
 create mode 100644 clang/test/SemaCXX/PR76631.cpp

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1a79892e40030ae..1006e7d65dd868c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3113,6 +3113,8 @@ def err_musttail_scope : Error<
   "cannot perform a tail call from this return statement">;
 def err_musttail_no_variadic : Error<
   "%0 attribute may not be used with variadic functions">;
+def err_musttail_no_return : Error<
+  "%0 attribute may not be used with no-return-attribute functions">;
 
 def err_nsobject_attribute : Error<
   "'NSObject' attribute is for pointer types only">;
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 21efe25ed84a3d2..9e7c8c7e4e8c12c 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -786,6 +786,12 @@ bool Sema::checkMustTailAttr(const Stmt *St, const Attr 
&MTA) {
 return false;
   }
 
+  const auto *CalleeDecl = CE->getCalleeDecl();
+  if (CalleeDecl && CalleeDecl->hasAttr()) {
+Diag(St->getBeginLoc(), diag::err_musttail_no_return) << &MTA;
+return false;
+  }
+
   // Caller and callee must match in whether they have a "this" parameter.
   if (CallerType.This.isNull() != CalleeType.This.isNull()) {
 if (const auto *ND = dyn_cast_or_null(CE->getCalleeDecl())) {
diff --git a/clang/test/SemaCXX/PR76631.cpp b/clang/test/SemaCXX/PR76631.cpp
new file mode 100644
index 000..df89753bd125804
--- /dev/null
+++ b/clang/test/SemaCXX/PR76631.cpp
@@ -0,0 +1,7 @@
+[[noreturn]] void throw_int() {
+  throw int();
+}
+
+void throw_int_wrapper() {
+  [[clang::musttail]] return throw_int(); // expected-error {{'musttail' 
attribute may not be used with no-return-attribute functions}}
+}

>From 0b3eac94c1eb584f97bbf657960f302db0dabebf Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Fri, 12 Jan 2024 15:15:37 +0800
Subject: [PATCH 2/2] [clang] Fix crash when compiling error with invalid decl

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  2 --
 clang/lib/AST/APValue.cpp|  8 ++--
 clang/lib/Sema/SemaStmt.cpp  |  6 --
 clang/test/AST/invalid-decl-no-crash.cpp | 12 
 clang/test/SemaCXX/PR76631.cpp   |  7 ---
 5 files changed, 18 insertions(+), 17 deletions(-)
 create mode 100644 clang/test/AST/invalid-decl-no-crash.cpp
 delete mode 100644 clang/test/SemaCXX/PR76631.cpp

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1006e7d65dd868c..1a79892e40030ae 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3113,8 +3113,6 @@ def err_musttail_scope : Error<
   "cannot perform a tail call from this return statement">;
 def err_musttail_no_variadic : Error<
   "%0 attribute may not be used with variadic functions">;
-def err_musttail_no_return : Error<
-  "%0 attribute may not be used with no-return-attribute functions">;
 
 def err_nsobject_attribute : Error<
   "'NSObject' attribute is for pointer types only">;
diff --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
index 4eae308ef5b34c6..b1fd93b23f38cc6 100644
--- a/clang/lib/AST/APValue.cpp
+++ b/clang/lib/AST/APValue.cpp
@@ -40,7 +40,11 @@ static_assert(
 "Type is insufficiently aligned");
 
 APValue::LValueBase::LValueBase(const ValueDecl *P, unsigned I, unsigned V)
-: Ptr(P ? cast(P->getCanonicalDecl()) : nullptr), Local{I, V} {}
+: Ptr(P ? cast(P->getCanonicalDecl()->isInvalidDecl()
+  ? P
+  : P->getCanonicalDecl())
+: nullptr),
+  Local{I, V} {}
 APValue::LValueBase::LValueBase(const Expr *P, unsigned I, unsigned V)
 : Ptr(P), Local{I, V} {}
 
@@ -73,7 +77,7 @@ QualType APValue::LValueBase::getType() const {
 for (auto *Redecl = cast(D->getMostRecentDecl()); Redecl;
  Redecl = cast_or_null(Re

[clang] [clang] Fix crash when compiling error with invalid decl (PR #77893)

2024-01-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Qizhi Hu (jcsxky)


Changes

`APValue::LValueBase::LValueBase` constructs `ValueDecl` with its 
canonicalDecl, even though it's invalid. And when obtain its type, it also 
check all redecls and ignore checking if it's valid. This will cause crash in 
invalid code. This patch fixes this issue by checking its validation and skip 
invalid decls.
Fix [issue](https://github.com/llvm/llvm-project/issues/69468)

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


2 Files Affected:

- (modified) clang/lib/AST/APValue.cpp (+6-2) 
- (added) clang/test/AST/invalid-decl-no-crash.cpp (+12) 


``diff
diff --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
index 4eae308ef5b34c..b1fd93b23f38cc 100644
--- a/clang/lib/AST/APValue.cpp
+++ b/clang/lib/AST/APValue.cpp
@@ -40,7 +40,11 @@ static_assert(
 "Type is insufficiently aligned");
 
 APValue::LValueBase::LValueBase(const ValueDecl *P, unsigned I, unsigned V)
-: Ptr(P ? cast(P->getCanonicalDecl()) : nullptr), Local{I, V} {}
+: Ptr(P ? cast(P->getCanonicalDecl()->isInvalidDecl()
+  ? P
+  : P->getCanonicalDecl())
+: nullptr),
+  Local{I, V} {}
 APValue::LValueBase::LValueBase(const Expr *P, unsigned I, unsigned V)
 : Ptr(P), Local{I, V} {}
 
@@ -73,7 +77,7 @@ QualType APValue::LValueBase::getType() const {
 for (auto *Redecl = cast(D->getMostRecentDecl()); Redecl;
  Redecl = cast_or_null(Redecl->getPreviousDecl())) {
   QualType T = Redecl->getType();
-  if (!T->isIncompleteArrayType())
+  if (!T->isIncompleteArrayType() && !Redecl->isInvalidDecl())
 return T;
 }
 return D->getType();
diff --git a/clang/test/AST/invalid-decl-no-crash.cpp 
b/clang/test/AST/invalid-decl-no-crash.cpp
new file mode 100644
index 00..2b35ef702ae553
--- /dev/null
+++ b/clang/test/AST/invalid-decl-no-crash.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+
+a[i] = b[i]; // expected-error {{use of undeclared identifier 'i'}} \
+expected-error {{a type specifier is required for all 
declarations}} \
+expected-error {{use of undeclared identifier 'b'}} \
+expected-error {{use of undeclared identifier 'i'}}
+extern char b[];
+extern char a[];
+
+void foo(int j) {
+  a[j] = b[j];
+}

``




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


[clang] [clang][dataflow] Process terminator condition within `transferCFGBlock()`. (PR #77750)

2024-01-12 Thread via cfe-commits

martinboehme wrote:

Reverting: Causes build bots to fail because `TerminatorVisitor::StmtToEnv` is 
now unused.

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


[clang] Revert "[clang][dataflow] Process terminator condition within `transferCFGBlock()`." (PR #77895)

2024-01-12 Thread via cfe-commits

https://github.com/martinboehme created 
https://github.com/llvm/llvm-project/pull/77895

Reverts llvm/llvm-project#77750

>From 44fbb43480c8779e8164a21dacb4d524d69b0e07 Mon Sep 17 00:00:00 2001
From: martinboehme 
Date: Fri, 12 Jan 2024 09:53:53 +0100
Subject: [PATCH] Revert "[clang][dataflow] Process terminator condition within
 `transferCFGBlock()`."

---
 .../TypeErasedDataflowAnalysis.cpp| 42 ++-
 .../Analysis/FlowSensitive/LoggerTest.cpp |  1 -
 .../Analysis/FlowSensitive/TransferTest.cpp   | 31 --
 3 files changed, 12 insertions(+), 62 deletions(-)

diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index 24d1447f09794a..e0a3552a9cde17 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -126,12 +126,19 @@ class TerminatorVisitor
 
 private:
   TerminatorVisitorRetTy extendFlowCondition(const Expr &Cond) {
+// The terminator sub-expression might not be evaluated.
+if (Env.getValue(Cond) == nullptr)
+  transfer(StmtToEnv, Cond, Env);
+
 auto *Val = Env.get(Cond);
-// In transferCFGBlock(), we ensure that we always have a `Value` for the
-// terminator condition, so assert this.
-// We consciously assert ourselves instead of asserting via `cast()` so
-// that we get a more meaningful line number if the assertion fails.
-assert(Val != nullptr);
+// Value merging depends on flow conditions from different environments
+// being mutually exclusive -- that is, they cannot both be true in their
+// entirety (even if they may share some clauses). So, we need *some* value
+// for the condition expression, even if just an atom.
+if (Val == nullptr) {
+  Val = &Env.makeAtomicBoolValue();
+  Env.setValue(Cond, *Val);
+}
 
 bool ConditionValue = true;
 // The condition must be inverted for the successor that encompasses the
@@ -481,31 +488,6 @@ transferCFGBlock(const CFGBlock &Block, AnalysisContext 
&AC,
 }
 AC.Log.recordState(State);
   }
-
-  // If we have a terminator, evaluate its condition.
-  // This `Expr` may not appear as a `CFGElement` anywhere else, and it's
-  // important that we evaluate it here (rather than while processing the
-  // terminator) so that we put the corresponding value in the right
-  // environment.
-  if (const Expr *TerminatorCond =
-  dyn_cast_or_null(Block.getTerminatorCondition())) {
-if (State.Env.getValue(*TerminatorCond) == nullptr)
-  // FIXME: This only runs the builtin transfer, not the analysis-specific
-  // transfer. Fixing this isn't trivial, as the analysis-specific transfer
-  // takes a `CFGElement` as input, but some expressions only show up as a
-  // terminator condition, but not as a `CFGElement`. The condition of an 
if
-  // statement is one such example.
-  transfer(StmtToEnvMap(AC.CFCtx, AC.BlockStates), *TerminatorCond,
-   State.Env);
-
-// If the transfer function didn't produce a value, create an atom so that
-// we have *some* value for the condition expression. This ensures that
-// when we extend the flow condition, it actually changes.
-if (State.Env.getValue(*TerminatorCond) == nullptr)
-  State.Env.setValue(*TerminatorCond, State.Env.makeAtomicBoolValue());
-AC.Log.recordState(State);
-  }
-
   return State;
 }
 
diff --git a/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
index c5594aa3fe9d1f..a60dbe1f61f6d6 100644
--- a/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
@@ -123,7 +123,6 @@ recordState(Elements=1, Branches=0, Joins=0)
 enterElement(b (ImplicitCastExpr, LValueToRValue, _Bool))
 transfer()
 recordState(Elements=2, Branches=0, Joins=0)
-recordState(Elements=2, Branches=0, Joins=0)
 
 enterBlock(3, false)
 transferBranch(0)
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 6d88e25f77c807..056c4f3383d832 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -6408,35 +6408,4 @@ TEST(TransferTest, DifferentReferenceLocInJoin) {
   });
 }
 
-// This test verifies correct modeling of a relational dependency that goes
-// through unmodeled functions (the simple `cond()` in this case).
-TEST(TransferTest, ConditionalRelation) {
-  std::string Code = R"(
-bool cond();
-void target() {
-   bool a = true;
-   bool b = true;
-   if (cond()) {
- a = false;
- if (cond()) {
-   b = false;
- }
-   }
-   (void)0;
-   // [[p]]
-}
- )";
-  runDataflow(
-  Code,
-  [](const llvm::StringMap> &Results,
-   

[clang] 1aacdfe - Revert "[clang][dataflow] Process terminator condition within `transferCFGBlock()`." (#77895)

2024-01-12 Thread via cfe-commits

Author: martinboehme
Date: 2024-01-12T09:54:50+01:00
New Revision: 1aacdfe473276ad631db773310fe167ec93fb764

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

LOG: Revert "[clang][dataflow] Process terminator condition within 
`transferCFGBlock()`." (#77895)

Reverts llvm/llvm-project#77750

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index 24d1447f09794a..e0a3552a9cde17 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -126,12 +126,19 @@ class TerminatorVisitor
 
 private:
   TerminatorVisitorRetTy extendFlowCondition(const Expr &Cond) {
+// The terminator sub-expression might not be evaluated.
+if (Env.getValue(Cond) == nullptr)
+  transfer(StmtToEnv, Cond, Env);
+
 auto *Val = Env.get(Cond);
-// In transferCFGBlock(), we ensure that we always have a `Value` for the
-// terminator condition, so assert this.
-// We consciously assert ourselves instead of asserting via `cast()` so
-// that we get a more meaningful line number if the assertion fails.
-assert(Val != nullptr);
+// Value merging depends on flow conditions from 
diff erent environments
+// being mutually exclusive -- that is, they cannot both be true in their
+// entirety (even if they may share some clauses). So, we need *some* value
+// for the condition expression, even if just an atom.
+if (Val == nullptr) {
+  Val = &Env.makeAtomicBoolValue();
+  Env.setValue(Cond, *Val);
+}
 
 bool ConditionValue = true;
 // The condition must be inverted for the successor that encompasses the
@@ -481,31 +488,6 @@ transferCFGBlock(const CFGBlock &Block, AnalysisContext 
&AC,
 }
 AC.Log.recordState(State);
   }
-
-  // If we have a terminator, evaluate its condition.
-  // This `Expr` may not appear as a `CFGElement` anywhere else, and it's
-  // important that we evaluate it here (rather than while processing the
-  // terminator) so that we put the corresponding value in the right
-  // environment.
-  if (const Expr *TerminatorCond =
-  dyn_cast_or_null(Block.getTerminatorCondition())) {
-if (State.Env.getValue(*TerminatorCond) == nullptr)
-  // FIXME: This only runs the builtin transfer, not the analysis-specific
-  // transfer. Fixing this isn't trivial, as the analysis-specific transfer
-  // takes a `CFGElement` as input, but some expressions only show up as a
-  // terminator condition, but not as a `CFGElement`. The condition of an 
if
-  // statement is one such example.
-  transfer(StmtToEnvMap(AC.CFCtx, AC.BlockStates), *TerminatorCond,
-   State.Env);
-
-// If the transfer function didn't produce a value, create an atom so that
-// we have *some* value for the condition expression. This ensures that
-// when we extend the flow condition, it actually changes.
-if (State.Env.getValue(*TerminatorCond) == nullptr)
-  State.Env.setValue(*TerminatorCond, State.Env.makeAtomicBoolValue());
-AC.Log.recordState(State);
-  }
-
   return State;
 }
 

diff  --git a/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
index c5594aa3fe9d1f..a60dbe1f61f6d6 100644
--- a/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
@@ -123,7 +123,6 @@ recordState(Elements=1, Branches=0, Joins=0)
 enterElement(b (ImplicitCastExpr, LValueToRValue, _Bool))
 transfer()
 recordState(Elements=2, Branches=0, Joins=0)
-recordState(Elements=2, Branches=0, Joins=0)
 
 enterBlock(3, false)
 transferBranch(0)

diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 6d88e25f77c807..056c4f3383d832 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -6408,35 +6408,4 @@ TEST(TransferTest, DifferentReferenceLocInJoin) {
   });
 }
 
-// This test verifies correct modeling of a relational dependency that goes
-// through unmodeled functions (the simple `cond()` in this case).
-TEST(TransferTest, ConditionalRelation) {
-  std::string Code = R"(
-bool cond();
-void target() {
-   bool a = true;
-   bool b = true;
-   if (cond()) {
- a = false;
- if (cond()) {
-   b = false;
-  

[clang] Revert "[clang][dataflow] Process terminator condition within `transferCFGBlock()`." (PR #77895)

2024-01-12 Thread via cfe-commits

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


[clang] Revert "[clang][dataflow] Process terminator condition within `transferCFGBlock()`." (PR #77895)

2024-01-12 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-analysis

Author: None (martinboehme)


Changes

Reverts llvm/llvm-project#77750

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


3 Files Affected:

- (modified) clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
(+12-30) 
- (modified) clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp (-1) 
- (modified) clang/unittests/Analysis/FlowSensitive/TransferTest.cpp (-31) 


``diff
diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index 24d1447f09794a..e0a3552a9cde17 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -126,12 +126,19 @@ class TerminatorVisitor
 
 private:
   TerminatorVisitorRetTy extendFlowCondition(const Expr &Cond) {
+// The terminator sub-expression might not be evaluated.
+if (Env.getValue(Cond) == nullptr)
+  transfer(StmtToEnv, Cond, Env);
+
 auto *Val = Env.get(Cond);
-// In transferCFGBlock(), we ensure that we always have a `Value` for the
-// terminator condition, so assert this.
-// We consciously assert ourselves instead of asserting via `cast()` so
-// that we get a more meaningful line number if the assertion fails.
-assert(Val != nullptr);
+// Value merging depends on flow conditions from different environments
+// being mutually exclusive -- that is, they cannot both be true in their
+// entirety (even if they may share some clauses). So, we need *some* value
+// for the condition expression, even if just an atom.
+if (Val == nullptr) {
+  Val = &Env.makeAtomicBoolValue();
+  Env.setValue(Cond, *Val);
+}
 
 bool ConditionValue = true;
 // The condition must be inverted for the successor that encompasses the
@@ -481,31 +488,6 @@ transferCFGBlock(const CFGBlock &Block, AnalysisContext 
&AC,
 }
 AC.Log.recordState(State);
   }
-
-  // If we have a terminator, evaluate its condition.
-  // This `Expr` may not appear as a `CFGElement` anywhere else, and it's
-  // important that we evaluate it here (rather than while processing the
-  // terminator) so that we put the corresponding value in the right
-  // environment.
-  if (const Expr *TerminatorCond =
-  dyn_cast_or_null(Block.getTerminatorCondition())) {
-if (State.Env.getValue(*TerminatorCond) == nullptr)
-  // FIXME: This only runs the builtin transfer, not the analysis-specific
-  // transfer. Fixing this isn't trivial, as the analysis-specific transfer
-  // takes a `CFGElement` as input, but some expressions only show up as a
-  // terminator condition, but not as a `CFGElement`. The condition of an 
if
-  // statement is one such example.
-  transfer(StmtToEnvMap(AC.CFCtx, AC.BlockStates), *TerminatorCond,
-   State.Env);
-
-// If the transfer function didn't produce a value, create an atom so that
-// we have *some* value for the condition expression. This ensures that
-// when we extend the flow condition, it actually changes.
-if (State.Env.getValue(*TerminatorCond) == nullptr)
-  State.Env.setValue(*TerminatorCond, State.Env.makeAtomicBoolValue());
-AC.Log.recordState(State);
-  }
-
   return State;
 }
 
diff --git a/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
index c5594aa3fe9d1f..a60dbe1f61f6d6 100644
--- a/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/LoggerTest.cpp
@@ -123,7 +123,6 @@ recordState(Elements=1, Branches=0, Joins=0)
 enterElement(b (ImplicitCastExpr, LValueToRValue, _Bool))
 transfer()
 recordState(Elements=2, Branches=0, Joins=0)
-recordState(Elements=2, Branches=0, Joins=0)
 
 enterBlock(3, false)
 transferBranch(0)
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 6d88e25f77c807..056c4f3383d832 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -6408,35 +6408,4 @@ TEST(TransferTest, DifferentReferenceLocInJoin) {
   });
 }
 
-// This test verifies correct modeling of a relational dependency that goes
-// through unmodeled functions (the simple `cond()` in this case).
-TEST(TransferTest, ConditionalRelation) {
-  std::string Code = R"(
-bool cond();
-void target() {
-   bool a = true;
-   bool b = true;
-   if (cond()) {
- a = false;
- if (cond()) {
-   b = false;
- }
-   }
-   (void)0;
-   // [[p]]
-}
- )";
-  runDataflow(
-  Code,
-  [](const llvm::StringMap> &Results,
- ASTContext &ASTCtx) {
-const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
-

[clang] [ObjC]: Make type encoding safe in symbol names (PR #77797)

2024-01-12 Thread David Chisnall via cfe-commits

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


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


[clang] 3168192 - [ObjC]: Make type encoding safe in symbol names (#77797)

2024-01-12 Thread via cfe-commits

Author: Frederik Carlier
Date: 2024-01-12T09:03:37Z
New Revision: 3168192de567815c511e384707a3a5063b81189b

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

LOG: [ObjC]: Make type encoding safe in symbol names (#77797)

Type encodings are part of symbol names in the Objective C ABI. Replace
characters which are reseved in symbol names:

- ELF: avoid including '@' characters in type encodings
- Windows: avoid including '=' characters in type encodings

Added: 


Modified: 
clang/lib/CodeGen/CGObjCGNU.cpp
clang/test/CodeGenObjC/dllstorage.m
clang/test/CodeGenObjC/encode-test-6.m

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index cd1a0b6a130ff0..9cc7f32815f7e9 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -1431,12 +1431,24 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 const std::string &TypeEncoding) override {
 return GetConstantSelector(Sel, TypeEncoding);
   }
+  std::string GetSymbolNameForTypeEncoding(const std::string &TypeEncoding) {
+std::string MangledTypes = std::string(TypeEncoding);
+// @ is used as a special character in ELF symbol names (used for symbol
+// versioning), so mangle the name to not include it.  Replace it with a
+// character that is not a valid type encoding character (and, being
+// non-printable, never will be!)
+if (CGM.getTriple().isOSBinFormatELF())
+  std::replace(MangledTypes.begin(), MangledTypes.end(), '@', '\1');
+// = in dll exported names causes lld to fail when linking on Windows.
+if (CGM.getTriple().isOSWindows())
+  std::replace(MangledTypes.begin(), MangledTypes.end(), '=', '\2');
+return MangledTypes;
+  }
   llvm::Constant  *GetTypeString(llvm::StringRef TypeEncoding) {
 if (TypeEncoding.empty())
   return NULLPtr;
-std::string MangledTypes = std::string(TypeEncoding);
-std::replace(MangledTypes.begin(), MangledTypes.end(),
-  '@', '\1');
+std::string MangledTypes =
+GetSymbolNameForTypeEncoding(std::string(TypeEncoding));
 std::string TypesVarName = ".objc_sel_types_" + MangledTypes;
 auto *TypesGlobal = TheModule.getGlobalVariable(TypesVarName);
 if (!TypesGlobal) {
@@ -1453,13 +1465,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
   }
   llvm::Constant *GetConstantSelector(Selector Sel,
   const std::string &TypeEncoding) 
override {
-// @ is used as a special character in symbol names (used for symbol
-// versioning), so mangle the name to not include it.  Replace it with a
-// character that is not a valid type encoding character (and, being
-// non-printable, never will be!)
-std::string MangledTypes = TypeEncoding;
-std::replace(MangledTypes.begin(), MangledTypes.end(),
-  '@', '\1');
+std::string MangledTypes = GetSymbolNameForTypeEncoding(TypeEncoding);
 auto SelVarName = (StringRef(".objc_selector_") + Sel.getAsString() + "_" +
   MangledTypes).str();
 if (auto *GV = TheModule.getNamedGlobal(SelVarName))
@@ -1671,9 +1677,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 const ObjCIvarDecl *Ivar) override {
 std::string TypeEncoding;
 CGM.getContext().getObjCEncodingForType(Ivar->getType(), TypeEncoding);
-// Prevent the @ from being interpreted as a symbol version.
-std::replace(TypeEncoding.begin(), TypeEncoding.end(),
-  '@', '\1');
+TypeEncoding = GetSymbolNameForTypeEncoding(TypeEncoding);
 const std::string Name = "__objc_ivar_offset_" + ID->getNameAsString()
   + '.' + Ivar->getNameAsString() + '.' + TypeEncoding;
 return Name;

diff  --git a/clang/test/CodeGenObjC/dllstorage.m 
b/clang/test/CodeGenObjC/dllstorage.m
index 0dbf1881caa9c0..f45eb7bb6aee78 100644
--- a/clang/test/CodeGenObjC/dllstorage.m
+++ b/clang/test/CodeGenObjC/dllstorage.m
@@ -35,7 +35,7 @@ @implementation J {
 
 // CHECK-IR-DAG: @"OBJC_IVAR_$_J._ivar" = global i32
 
-// CHECK-NF-DAG: @"__objc_ivar_offset_J._ivar.\01" = hidden global i32
+// CHECK-NF-DAG: @"__objc_ivar_offset_J._ivar.@" = hidden global i32
 
 @interface K : J
 @end
@@ -56,7 +56,7 @@ @implementation K {
 
 // CHECK-IR-DAG: @"OBJC_IVAR_$_K._ivar" = global i32
 
-// CHECK-NF-DAG: @"__objc_ivar_offset_K._ivar.\01" = hidden global i32
+// CHECK-NF-DAG: @"__objc_ivar_offset_K._ivar.@" = hidden global i32
 
 __declspec(dllexport)
 @interface L : K
@@ -94,11 +94,11 @@ @implementation L {
 // CHECK-IR-DAG: @"OBJC_IVAR_$_L._package" = global i32
 // CHECK-IR-DAG: @"OBJC_IVAR_$_L._private" = global i32
 
-// CHECK-NF-DAG: @"__objc_ivar_offset_L._none.\01" = hidden global i32
-// CHECK-NF-DAG: @"__objc_ivar_offset_

[clang] [ObjC]: Make type encoding safe in symbol names (PR #77797)

2024-01-12 Thread David Chisnall via cfe-commits

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


[clang] [clang][dataflow] Fix bug in `Value` comparison. (PR #76746)

2024-01-12 Thread via cfe-commits

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

Sorry for the delay!

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


[clang] [SPIR-V] Prefer llvm-spirv- tool (PR #77897)

2024-01-12 Thread Henry Linjamäki via cfe-commits

https://github.com/linehill created 
https://github.com/llvm/llvm-project/pull/77897

Prefer using `llvm-spirv-` tool (i.e. `llvm-spirv-18`) over 
plain `llvm-spirv`. If the versioned tool is not found in PATH, fall back to 
use the plain `llvm-spirv`.

An issue with the using `llvm-spirv` is that the one found in PATH might be 
compiled against older LLVM version which could lead to crashes or obscure 
bugs. For example, `llvm-spirv` distributed by Ubuntu links against different 
LLVM version depending on the Ubuntu release (LLVM-10 in 20.04LTS, LLVM-13 in 
22.04LTS).

From 6165987ab890156a503d7afa38ad5c88510368b0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Henry=20Linjam=C3=A4ki?= 
Date: Thu, 21 Dec 2023 08:43:16 +0200
Subject: [PATCH] [SPIR-V] Prefer llvm-spirv- tool

Prefer using `llvm-spirv-` tool
(i.e. `llvm-spirv-18`) over plain `llvm-spirv`. If the versioned tool
is not found in PATH, fall back to use the plain `llvm-spirv`.

An issue with the using `llvm-spirv` is that the one found in PATH
might be compiled against older LLVM version which could lead to
crashes or obscure bugs. For example, `llvm-spirv` distributed by
Ubuntu links against different LLVM version depending on the Ubuntu
release (LLVM-10 in 20.04LTS, LLVM-13 in 22.04LTS).
---
 clang/lib/Driver/ToolChains/SPIRV.cpp  | 12 ++--
 clang/test/Driver/hipspv-toolchain.hip | 13 +
 clang/test/Driver/spirv-toolchain.cl   | 10 ++
 clang/test/lit.site.cfg.py.in  |  1 +
 4 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/SPIRV.cpp 
b/clang/lib/Driver/ToolChains/SPIRV.cpp
index 27de69550853cf..ce900600cbee51 100644
--- a/clang/lib/Driver/ToolChains/SPIRV.cpp
+++ b/clang/lib/Driver/ToolChains/SPIRV.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 #include "SPIRV.h"
 #include "CommonArgs.h"
+#include "clang/Basic/Version.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/InputInfo.h"
@@ -32,8 +33,15 @@ void SPIRV::constructTranslateCommand(Compilation &C, const 
Tool &T,
 
   CmdArgs.append({"-o", Output.getFilename()});
 
-  const char *Exec =
-  C.getArgs().MakeArgString(T.getToolChain().GetProgramPath("llvm-spirv"));
+  // Try to find "llvm-spirv-". Otherwise, fall back to
+  // plain "llvm-spirv".
+  using namespace std::string_literals;
+  auto VersionedTool = "llvm-spirv-"s + std::to_string(LLVM_VERSION_MAJOR);
+  std::string ExeCand = T.getToolChain().GetProgramPath(VersionedTool.c_str());
+  if (!llvm::sys::fs::can_execute(ExeCand))
+ExeCand = T.getToolChain().GetProgramPath("llvm-spirv");
+
+  const char *Exec = C.getArgs().MakeArgString(ExeCand);
   C.addCommand(std::make_unique(JA, T, ResponseFileSupport::None(),
  Exec, CmdArgs, Input, Output));
 }
diff --git a/clang/test/Driver/hipspv-toolchain.hip 
b/clang/test/Driver/hipspv-toolchain.hip
index bfae41049ba4dd..5f6dcc069afe8b 100644
--- a/clang/test/Driver/hipspv-toolchain.hip
+++ b/clang/test/Driver/hipspv-toolchain.hip
@@ -34,3 +34,16 @@
 // CHECK-SAME: "-o" [[OBJ_HOST:".*o"]] "-x" "hip"
 
 // CHECK: {{".*ld.*"}} {{.*}}[[OBJ_HOST]]
+
+//-
+// Check llvm-spirv- is used if it is found in PATH.
+// RUN: mkdir -p %t/versioned
+// RUN: touch %t/versioned/llvm-spirv-%llvm-version-major \
+// RUN:   && chmod +x %t/versioned/llvm-spirv-%llvm-version-major
+// RUN: env "PATH=%t/versioned" %clang -### -target x86_64-linux-gnu \
+// RUN:   --offload=spirv64 --hip-path=%S/Inputs/hipspv -nohipwrapperinc \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -DVERSION=%llvm-version-major \
+// RUN:   --check-prefix=VERSIONED %s
+
+// VERSIONED: {{.*}}llvm-spirv-[[VERSION]]
diff --git a/clang/test/Driver/spirv-toolchain.cl 
b/clang/test/Driver/spirv-toolchain.cl
index db3ee4d3fe02f8..de818177cb19f1 100644
--- a/clang/test/Driver/spirv-toolchain.cl
+++ b/clang/test/Driver/spirv-toolchain.cl
@@ -77,3 +77,13 @@
 
 // XTOR: {{llvm-spirv.*"}}
 // BACKEND-NOT: {{llvm-spirv.*"}}
+
+//-
+// Check llvm-spirv- is used if it is found in PATH.
+// RUN: mkdir -p %t/versioned
+// RUN: touch %t/versioned/llvm-spirv-%llvm-version-major \
+// RUN:   && chmod +x %t/versioned/llvm-spirv-%llvm-version-major
+// RUN: env "PATH=%t/versioned" %clang -### --target=spirv64 -x cl -c %s 2>&1 \
+// RUN:   | FileCheck -DVERSION=%llvm-version-major --check-prefix=VERSIONED %s
+
+// VERSIONED: {{.*}}llvm-spirv-[[VERSION]]
diff --git a/clang/test/lit.site.cfg.py.in b/clang/test/lit.site.cfg.py.in
index ef75770a2c3c9a..b4e88096aaa0f3 100644
--- a/clang/test/lit.site.cfg.py.in
+++ b/clang/test/lit.site.cfg.py.in
@@ -41,6 +41,7 @@ config.llvm_external_lit = path(r"@LLVM_EXTERNAL_LIT@")
 config.standalone_build = @CLANG_BUILT_STANDALONE@
 config.ppc_linux_default_ieeelong

[clang] [SPIR-V] Prefer llvm-spirv- tool (PR #77897)

2024-01-12 Thread via cfe-commits

github-actions[bot] wrote:

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [SPIR-V] Prefer llvm-spirv- tool (PR #77897)

2024-01-12 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-spir-v

Author: Henry Linjamäki (linehill)


Changes

Prefer using `llvm-spirv-` tool (i.e. 
`llvm-spirv-18`) over plain `llvm-spirv`. If the versioned tool is not found in 
PATH, fall back to use the plain `llvm-spirv`.

An issue with the using `llvm-spirv` is that the one found in PATH might be 
compiled against older LLVM version which could lead to crashes or obscure 
bugs. For example, `llvm-spirv` distributed by Ubuntu links against different 
LLVM version depending on the Ubuntu release (LLVM-10 in 20.04LTS, LLVM-13 in 
22.04LTS).

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


4 Files Affected:

- (modified) clang/lib/Driver/ToolChains/SPIRV.cpp (+10-2) 
- (modified) clang/test/Driver/hipspv-toolchain.hip (+13) 
- (modified) clang/test/Driver/spirv-toolchain.cl (+10) 
- (modified) clang/test/lit.site.cfg.py.in (+1) 


``diff
diff --git a/clang/lib/Driver/ToolChains/SPIRV.cpp 
b/clang/lib/Driver/ToolChains/SPIRV.cpp
index 27de69550853cf..ce900600cbee51 100644
--- a/clang/lib/Driver/ToolChains/SPIRV.cpp
+++ b/clang/lib/Driver/ToolChains/SPIRV.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 #include "SPIRV.h"
 #include "CommonArgs.h"
+#include "clang/Basic/Version.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/InputInfo.h"
@@ -32,8 +33,15 @@ void SPIRV::constructTranslateCommand(Compilation &C, const 
Tool &T,
 
   CmdArgs.append({"-o", Output.getFilename()});
 
-  const char *Exec =
-  C.getArgs().MakeArgString(T.getToolChain().GetProgramPath("llvm-spirv"));
+  // Try to find "llvm-spirv-". Otherwise, fall back to
+  // plain "llvm-spirv".
+  using namespace std::string_literals;
+  auto VersionedTool = "llvm-spirv-"s + std::to_string(LLVM_VERSION_MAJOR);
+  std::string ExeCand = T.getToolChain().GetProgramPath(VersionedTool.c_str());
+  if (!llvm::sys::fs::can_execute(ExeCand))
+ExeCand = T.getToolChain().GetProgramPath("llvm-spirv");
+
+  const char *Exec = C.getArgs().MakeArgString(ExeCand);
   C.addCommand(std::make_unique(JA, T, ResponseFileSupport::None(),
  Exec, CmdArgs, Input, Output));
 }
diff --git a/clang/test/Driver/hipspv-toolchain.hip 
b/clang/test/Driver/hipspv-toolchain.hip
index bfae41049ba4dd..5f6dcc069afe8b 100644
--- a/clang/test/Driver/hipspv-toolchain.hip
+++ b/clang/test/Driver/hipspv-toolchain.hip
@@ -34,3 +34,16 @@
 // CHECK-SAME: "-o" [[OBJ_HOST:".*o"]] "-x" "hip"
 
 // CHECK: {{".*ld.*"}} {{.*}}[[OBJ_HOST]]
+
+//-
+// Check llvm-spirv- is used if it is found in PATH.
+// RUN: mkdir -p %t/versioned
+// RUN: touch %t/versioned/llvm-spirv-%llvm-version-major \
+// RUN:   && chmod +x %t/versioned/llvm-spirv-%llvm-version-major
+// RUN: env "PATH=%t/versioned" %clang -### -target x86_64-linux-gnu \
+// RUN:   --offload=spirv64 --hip-path=%S/Inputs/hipspv -nohipwrapperinc \
+// RUN:   %s 2>&1 \
+// RUN:   | FileCheck -DVERSION=%llvm-version-major \
+// RUN:   --check-prefix=VERSIONED %s
+
+// VERSIONED: {{.*}}llvm-spirv-[[VERSION]]
diff --git a/clang/test/Driver/spirv-toolchain.cl 
b/clang/test/Driver/spirv-toolchain.cl
index db3ee4d3fe02f8..de818177cb19f1 100644
--- a/clang/test/Driver/spirv-toolchain.cl
+++ b/clang/test/Driver/spirv-toolchain.cl
@@ -77,3 +77,13 @@
 
 // XTOR: {{llvm-spirv.*"}}
 // BACKEND-NOT: {{llvm-spirv.*"}}
+
+//-
+// Check llvm-spirv- is used if it is found in PATH.
+// RUN: mkdir -p %t/versioned
+// RUN: touch %t/versioned/llvm-spirv-%llvm-version-major \
+// RUN:   && chmod +x %t/versioned/llvm-spirv-%llvm-version-major
+// RUN: env "PATH=%t/versioned" %clang -### --target=spirv64 -x cl -c %s 2>&1 \
+// RUN:   | FileCheck -DVERSION=%llvm-version-major --check-prefix=VERSIONED %s
+
+// VERSIONED: {{.*}}llvm-spirv-[[VERSION]]
diff --git a/clang/test/lit.site.cfg.py.in b/clang/test/lit.site.cfg.py.in
index ef75770a2c3c9a..b4e88096aaa0f3 100644
--- a/clang/test/lit.site.cfg.py.in
+++ b/clang/test/lit.site.cfg.py.in
@@ -41,6 +41,7 @@ config.llvm_external_lit = path(r"@LLVM_EXTERNAL_LIT@")
 config.standalone_build = @CLANG_BUILT_STANDALONE@
 config.ppc_linux_default_ieeelongdouble = @PPC_LINUX_DEFAULT_IEEELONGDOUBLE@
 config.have_llvm_driver = @LLVM_TOOL_LLVM_DRIVER_BUILD@
+config.substitutions.append(("%llvm-version-major", "@LLVM_VERSION_MAJOR@"))
 
 import lit.llvm
 lit.llvm.initialize(lit_config, config)

``




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


[llvm] [clang-tools-extra] LLVM is not needed for chapter two. (PR #69823)

2024-01-12 Thread via cfe-commits

gonsolo wrote:

Adding commiters to doc/tutorial since LLVM 17 to get this merged:
@Logikable @aemerson @aeubanks @MaskRay @youkaichao @hanickadot 

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


[clang] fbac3b0 - Revert "[clang][dataflow] Remove unused private field 'StmtToEnv' (NFC)"

2024-01-12 Thread Jie Fu via cfe-commits

Author: Jie Fu
Date: 2024-01-12T17:17:39+08:00
New Revision: fbac3b0db5ff1d409f90219aeb6460ec5d14f19a

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

LOG: Revert "[clang][dataflow] Remove unused private field 'StmtToEnv' (NFC)"

Revert it after 1aacdfe473276ad631db773310fe167ec93fb764

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index e0a3552a9cde17..faf83a8920d4ea 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -77,7 +77,7 @@ class TerminatorVisitor
 public:
   TerminatorVisitor(const StmtToEnvMap &StmtToEnv, Environment &Env,
 int BlockSuccIdx)
-  : Env(Env), BlockSuccIdx(BlockSuccIdx) {}
+  : StmtToEnv(StmtToEnv), Env(Env), BlockSuccIdx(BlockSuccIdx) {}
 
   TerminatorVisitorRetTy VisitIfStmt(const IfStmt *S) {
 auto *Cond = S->getCond();
@@ -152,6 +152,7 @@ class TerminatorVisitor
 return {&Cond, ConditionValue};
   }
 
+  const StmtToEnvMap &StmtToEnv;
   Environment &Env;
   int BlockSuccIdx;
 };



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


[llvm] [clang-tools-extra] LLVM is not needed for chapter two. (PR #69823)

2024-01-12 Thread via cfe-commits

youkaichao wrote:

Hey, anything required from my side?

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


[clang] [clang] WIP: Implement CTAD for type alias template. (PR #77890)

2024-01-12 Thread via cfe-commits

cor3ntin wrote:

I'm thrilled to see work in this area. Thanks!

Note that Clang 18 is going to branch soon, so this PR is going to target Clang 
19.
However, because it took a while to stabilize other CTAD related works, i think 
it might be worth it to try to complete that work early in the Clang 19 cycle, 
so that we have a few months to weed out the bugs.

I do believe this is the last unimplemented features for our C++20 support 
(outside of bugs and modules)

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


[llvm] [clang] [clang][Driver] Don't ignore -gmodules .gch files (PR #77711)

2024-01-12 Thread via cfe-commits

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

lgtm

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


[flang] [clang] [clang-tools-extra] [compiler-rt] [llvm] [AArch64][SME] Fix multi vector cvt builtins (PR #77656)

2024-01-12 Thread Matthew Devereau via cfe-commits

https://github.com/MDevereau updated 
https://github.com/llvm/llvm-project/pull/77656

>From 67be98b05d771dabe11af54b69532641fa548fb1 Mon Sep 17 00:00:00 2001
From: Matt Devereau 
Date: Wed, 10 Jan 2024 17:58:30 +
Subject: [PATCH 1/3] [AArch64][SME] Fix multi vector cvt builtins

This fixes cvt multi vector builtins that erroneously had inverted
return vectors and vector parameters. This caused the incorrect
instructions to be emitted.
---
 clang/include/clang/Basic/arm_sve.td  | 18 ++---
 .../aarch64-sme2-intrinsics/acle_sme2_cvt.c   | 32 
 llvm/include/llvm/IR/IntrinsicsAArch64.td |  8 +-
 .../CodeGen/AArch64/sme2-intrinsics-cvt.ll| 80 +--
 4 files changed, 69 insertions(+), 69 deletions(-)

diff --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 7f80fb0386cc77..301ef67b3d40bc 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2238,15 +2238,15 @@ let TargetGuard = "sme2" in {
   def SVCVT_F16_X2  : SInst<"svcvt_f16[_f32_x2]", "e2", "f", MergeNone, 
"aarch64_sve_fcvt_x2", [IsStreaming],[]>;
   def SVCVT_BF16_X2 : SInst<"svcvt_bf16[_f32_x2]", "$2", "f", MergeNone, 
"aarch64_sve_bfcvt_x2", [IsOverloadNone, IsStreaming],[]>;
 
-  def SVCVT_F32_U32_X2 : SInst<"svcvt_{d}[_u32_x2]", "2.d2.u", "f", MergeNone, 
"aarch64_sve_fcvtu_x2", [IsStreaming], []>;
-  def SVCVT_U32_F32_X2 : SInst<"svcvt_u32[_{d}_x2]", "2.u2.d", "f", MergeNone, 
"aarch64_sve_ucvtf_x2", [IsStreaming], []>;
-  def SVCVT_F32_S32_X2 : SInst<"svcvt_{d}[_s32_x2]", "2.d2.x", "f", MergeNone, 
"aarch64_sve_fcvts_x2", [IsStreaming], []>;
-  def SVCVT_S32_F32_X2 : SInst<"svcvt_s32[_{d}_x2]", "2.x2.d", "f", MergeNone, 
"aarch64_sve_scvtf_x2", [IsStreaming], []>;
-
-  def SVCVT_F32_U32_X4 : SInst<"svcvt_{d}[_u32_x4]", "4.d4.u", "f", MergeNone, 
"aarch64_sve_fcvtu_x4", [IsStreaming], []>;
-  def SVCVT_U32_F32_X4 : SInst<"svcvt_u32[_{d}_x4]", "4.u4.d", "f", MergeNone, 
"aarch64_sve_ucvtf_x4", [IsStreaming], []>;
-  def SVCVT_F32_S32_X4 : SInst<"svcvt_{d}[_s32_x4]", "4.d4.x", "f", MergeNone, 
"aarch64_sve_fcvts_x4", [IsStreaming], []>;
-  def SVCVT_S32_F32_X4 : SInst<"svcvt_s32[_{d}_x4]", "4.x4.d", "f", MergeNone, 
"aarch64_sve_scvtf_x4", [IsStreaming], []>;
+  def SVCVT_F32_U32_X2 : SInst<"svcvt_{d}[_u32_x2]", "2.d2.u", "f", MergeNone, 
"aarch64_sve_ucvtf_x2", [IsStreaming], []>;
+  def SVCVT_U32_F32_X2 : SInst<"svcvt_u32[_{d}_x2]", "2.u2.d", "f", MergeNone, 
"aarch64_sve_fcvtu_x2", [IsStreaming], []>;
+  def SVCVT_F32_S32_X2 : SInst<"svcvt_{d}[_s32_x2]", "2.d2.x", "f", MergeNone, 
"aarch64_sve_scvtf_x2", [IsStreaming], []>;
+  def SVCVT_S32_F32_X2 : SInst<"svcvt_s32[_{d}_x2]", "2.x2.d", "f", MergeNone, 
"aarch64_sve_fcvts_x2", [IsStreaming], []>;
+
+  def SVCVT_F32_U32_X4 : SInst<"svcvt_{d}[_u32_x4]", "4.d4.u", "f", MergeNone, 
"aarch64_sve_ucvtf_x4", [IsStreaming], []>;
+  def SVCVT_U32_F32_X4 : SInst<"svcvt_u32[_{d}_x4]", "4.u4.d", "f", MergeNone, 
"aarch64_sve_fcvtu_x4", [IsStreaming], []>;
+  def SVCVT_F32_S32_X4 : SInst<"svcvt_{d}[_s32_x4]", "4.d4.x", "f", MergeNone, 
"aarch64_sve_scvtf_x4", [IsStreaming], []>;
+  def SVCVT_S32_F32_X4 : SInst<"svcvt_s32[_{d}_x4]", "4.x4.d", "f", MergeNone, 
"aarch64_sve_fcvts_x4", [IsStreaming], []>;
 }
 
 //
diff --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_cvt.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_cvt.c
index a3ee7d2092f79f..f596b3167f2b82 100644
--- a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_cvt.c
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_cvt.c
@@ -59,7 +59,7 @@ svbfloat16_t test_cvt_bf16_x2(svfloat32x2_t zn)  
__arm_streaming {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv4i32.nxv8i32( [[ZN:%.*]], i64 0)
 // CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv4i32.nxv8i32( [[ZN]], i64 4)
-// CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.fcvtu.x2.nxv4f32( [[TMP0]], 
 [[TMP1]])
+// CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.ucvtf.x2.nxv4f32( [[TMP0]], 
 [[TMP1]])
 // CHECK-NEXT:[[TMP3:%.*]] = extractvalue { ,  } [[TMP2]], 0
 // CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv8f32.nxv4f32( poison,  [[TMP3]], i64 0)
 // CHECK-NEXT:[[TMP5:%.*]] = extractvalue { ,  } [[TMP2]], 1
@@ -70,7 +70,7 @@ svbfloat16_t test_cvt_bf16_x2(svfloat32x2_t zn)  
__arm_streaming {
 // CPP-CHECK-NEXT:  entry:
 // CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv4i32.nxv8i32( [[ZN:%.*]], i64 0)
 // CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv4i32.nxv8i32( [[ZN]], i64 4)
-// CPP-CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.fcvtu.x2.nxv4f32( [[TMP0]], 
 [[TMP1]])
+// CPP-CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.ucvtf.x2.nxv4f32( [[TMP0]], 
 [[TMP1]])
 // CPP-CHECK-NEXT:[[TMP3:%.*]] = extractvalue { , 
 } [[TMP2]], 0
 // CPP-CHEC

[clang] a8f83cc - [AArch64][SME] Fix multi vector cvt builtins (#77656)

2024-01-12 Thread via cfe-commits

Author: Matthew Devereau
Date: 2024-01-12T09:55:52Z
New Revision: a8f83cc1597216821b41c69dcfc8251f73b08848

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

LOG: [AArch64][SME] Fix multi vector cvt builtins (#77656)

This fixes cvt multi vector builtins that erroneously had inverted
return vectors and vector parameters. This caused the incorrect
instructions to be emitted.

Added: 


Modified: 
clang/include/clang/Basic/arm_sve.td
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_cvt.c
llvm/include/llvm/IR/IntrinsicsAArch64.td
llvm/test/CodeGen/AArch64/sme2-intrinsics-cvt.ll

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sve.td 
b/clang/include/clang/Basic/arm_sve.td
index 6f35e25617adea..6de940b4da6033 100644
--- a/clang/include/clang/Basic/arm_sve.td
+++ b/clang/include/clang/Basic/arm_sve.td
@@ -2238,15 +2238,15 @@ let TargetGuard = "sme2" in {
   def SVCVT_F16_X2  : SInst<"svcvt_f16[_f32_x2]", "e2", "f", MergeNone, 
"aarch64_sve_fcvt_x2", [IsStreaming],[]>;
   def SVCVT_BF16_X2 : SInst<"svcvt_bf16[_f32_x2]", "$2", "f", MergeNone, 
"aarch64_sve_bfcvt_x2", [IsOverloadNone, IsStreaming],[]>;
 
-  def SVCVT_F32_U32_X2 : SInst<"svcvt_{d}[_u32_x2]", "2.d2.u", "f", MergeNone, 
"aarch64_sve_fcvtu_x2", [IsStreaming], []>;
-  def SVCVT_U32_F32_X2 : SInst<"svcvt_u32[_{d}_x2]", "2.u2.d", "f", MergeNone, 
"aarch64_sve_ucvtf_x2", [IsStreaming], []>;
-  def SVCVT_F32_S32_X2 : SInst<"svcvt_{d}[_s32_x2]", "2.d2.x", "f", MergeNone, 
"aarch64_sve_fcvts_x2", [IsStreaming], []>;
-  def SVCVT_S32_F32_X2 : SInst<"svcvt_s32[_{d}_x2]", "2.x2.d", "f", MergeNone, 
"aarch64_sve_scvtf_x2", [IsStreaming], []>;
-
-  def SVCVT_F32_U32_X4 : SInst<"svcvt_{d}[_u32_x4]", "4.d4.u", "f", MergeNone, 
"aarch64_sve_fcvtu_x4", [IsStreaming], []>;
-  def SVCVT_U32_F32_X4 : SInst<"svcvt_u32[_{d}_x4]", "4.u4.d", "f", MergeNone, 
"aarch64_sve_ucvtf_x4", [IsStreaming], []>;
-  def SVCVT_F32_S32_X4 : SInst<"svcvt_{d}[_s32_x4]", "4.d4.x", "f", MergeNone, 
"aarch64_sve_fcvts_x4", [IsStreaming], []>;
-  def SVCVT_S32_F32_X4 : SInst<"svcvt_s32[_{d}_x4]", "4.x4.d", "f", MergeNone, 
"aarch64_sve_scvtf_x4", [IsStreaming], []>;
+  def SVCVT_F32_U32_X2 : SInst<"svcvt_{d}[_u32_x2]", "2.d2.u", "f", MergeNone, 
"aarch64_sve_ucvtf_x2", [IsStreaming], []>;
+  def SVCVT_U32_F32_X2 : SInst<"svcvt_u32[_{d}_x2]", "2.u2.d", "f", MergeNone, 
"aarch64_sve_fcvtu_x2", [IsStreaming], []>;
+  def SVCVT_F32_S32_X2 : SInst<"svcvt_{d}[_s32_x2]", "2.d2.x", "f", MergeNone, 
"aarch64_sve_scvtf_x2", [IsStreaming], []>;
+  def SVCVT_S32_F32_X2 : SInst<"svcvt_s32[_{d}_x2]", "2.x2.d", "f", MergeNone, 
"aarch64_sve_fcvts_x2", [IsStreaming], []>;
+
+  def SVCVT_F32_U32_X4 : SInst<"svcvt_{d}[_u32_x4]", "4.d4.u", "f", MergeNone, 
"aarch64_sve_ucvtf_x4", [IsStreaming], []>;
+  def SVCVT_U32_F32_X4 : SInst<"svcvt_u32[_{d}_x4]", "4.u4.d", "f", MergeNone, 
"aarch64_sve_fcvtu_x4", [IsStreaming], []>;
+  def SVCVT_F32_S32_X4 : SInst<"svcvt_{d}[_s32_x4]", "4.d4.x", "f", MergeNone, 
"aarch64_sve_scvtf_x4", [IsStreaming], []>;
+  def SVCVT_S32_F32_X4 : SInst<"svcvt_s32[_{d}_x4]", "4.x4.d", "f", MergeNone, 
"aarch64_sve_fcvts_x4", [IsStreaming], []>;
 }
 
 //

diff  --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_cvt.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_cvt.c
index a3ee7d2092f79f..f596b3167f2b82 100644
--- a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_cvt.c
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_cvt.c
@@ -59,7 +59,7 @@ svbfloat16_t test_cvt_bf16_x2(svfloat32x2_t zn)  
__arm_streaming {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv4i32.nxv8i32( [[ZN:%.*]], i64 0)
 // CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv4i32.nxv8i32( [[ZN]], i64 4)
-// CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.fcvtu.x2.nxv4f32( [[TMP0]], 
 [[TMP1]])
+// CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.ucvtf.x2.nxv4f32( [[TMP0]], 
 [[TMP1]])
 // CHECK-NEXT:[[TMP3:%.*]] = extractvalue { ,  } [[TMP2]], 0
 // CHECK-NEXT:[[TMP4:%.*]] = tail call  
@llvm.vector.insert.nxv8f32.nxv4f32( poison,  [[TMP3]], i64 0)
 // CHECK-NEXT:[[TMP5:%.*]] = extractvalue { ,  } [[TMP2]], 1
@@ -70,7 +70,7 @@ svbfloat16_t test_cvt_bf16_x2(svfloat32x2_t zn)  
__arm_streaming {
 // CPP-CHECK-NEXT:  entry:
 // CPP-CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.vector.extract.nxv4i32.nxv8i32( [[ZN:%.*]], i64 0)
 // CPP-CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.vector.extract.nxv4i32.nxv8i32( [[ZN]], i64 4)
-// CPP-CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.fcvtu.x2.nxv4f32( [[TMP0]], 
 [[TMP1]])
+// CPP-CHECK-NEXT:[[TMP2:%.*]] = tail call { ,  } @llvm.aarch64.sve.ucvtf.x2.nxv4f32( [[TMP

[flang] [clang] [clang-tools-extra] [compiler-rt] [llvm] [AArch64][SME] Fix multi vector cvt builtins (PR #77656)

2024-01-12 Thread Matthew Devereau via cfe-commits

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


[clang] [AArch64][SME2] Fix SME2 mla/mls tests (PR #76711)

2024-01-12 Thread Matthew Devereau via cfe-commits

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


[clang] 42fe3bc - [AArch64][SME2] Fix SME2 mla/mls tests (#76711)

2024-01-12 Thread via cfe-commits

Author: Matthew Devereau
Date: 2024-01-12T09:56:50Z
New Revision: 42fe3bc186b938197b3dfe3bd0445674c33fc5eb

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

LOG: [AArch64][SME2] Fix SME2 mla/mls tests (#76711)

The ACLE defines these builtins as svmla[_single]_za32[_f32]_vg1x2,
which means the SVE_ACLE_FUNC macro should test the overloaded forms as

SVE_ACLE_FUNC(svmla,_single,_za32,_f32,_vg1x2)


https://github.com/ARM-software/acle/blob/b88cbf7e9c104100bb5016c848763171494dee44/main/acle.md?plain=1#L10170-L10205

Added: 


Modified: 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mla.c
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mlal.c
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mlall.c
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mls.c
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mlsl.c

Removed: 




diff  --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mla.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mla.c
index f52edd9888daa9..2679f9cc8dfd0c 100644
--- a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mla.c
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mla.c
@@ -86,7 +86,7 @@ void test_svmla4_f32(uint32_t slice_base, svfloat32x4_t zn, 
svfloat32x4_t zm) __
 // CPP-CHECK-NEXT:ret void
 //
 void test_svmla_single2_f32(uint32_t slice_base, svfloat32x2_t zn, svfloat32_t 
zm) __arm_streaming __arm_shared_za {
-  SVE_ACLE_FUNC(svmla_single_za32,,_f32,,_vg1x2)(slice_base, zn, zm);
+  SVE_ACLE_FUNC(svmla,_single,_za32,_f32,_vg1x2)(slice_base, zn, zm);
 }
 
 // CHECK-LABEL: @test_svmla_single4_f32(
@@ -108,7 +108,7 @@ void test_svmla_single2_f32(uint32_t slice_base, 
svfloat32x2_t zn, svfloat32_t z
 // CPP-CHECK-NEXT:ret void
 //
 void test_svmla_single4_f32(uint32_t slice_base, svfloat32x4_t zn, svfloat32_t 
zm) __arm_streaming __arm_shared_za {
-  SVE_ACLE_FUNC(svmla_single_za32,,_f32,,_vg1x4)(slice_base, zn, zm);
+  SVE_ACLE_FUNC(svmla,_single,_za32,_f32,_vg1x4)(slice_base, zn, zm);
 }
 
 //
@@ -224,7 +224,7 @@ void test_svmla4_f64(uint32_t slice_base, svfloat64x4_t zn, 
svfloat64x4_t zm) __
 // CPP-CHECK-NEXT:ret void
 //
 void test_svmla_single2_f64(uint32_t slice_base, svfloat64x2_t zn, svfloat64_t 
zm) __arm_streaming __arm_shared_za {
-  SVE_ACLE_FUNC(svmla_single_za64,,_f64,,_vg1x2)(slice_base, zn, zm);
+  SVE_ACLE_FUNC(svmla,_single,_za64,_f64,_vg1x2)(slice_base, zn, zm);
 }
 
 // CHECK-LABEL: @test_svmla_single4_f64(
@@ -246,7 +246,7 @@ void test_svmla_single2_f64(uint32_t slice_base, 
svfloat64x2_t zn, svfloat64_t z
 // CPP-CHECK-NEXT:ret void
 //
 void test_svmla_single4_f64(uint32_t slice_base, svfloat64x4_t zn, svfloat64_t 
zm) __arm_streaming __arm_shared_za {
-  SVE_ACLE_FUNC(svmla_single_za64,,_f64,,_vg1x4)(slice_base, zn, zm);
+  SVE_ACLE_FUNC(svmla,_single,_za64,_f64,_vg1x4)(slice_base, zn, zm);
 }
 
 //

diff  --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mlal.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mlal.c
index 834ade75350767..032830512987af 100644
--- a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mlal.c
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_mlal.c
@@ -311,7 +311,7 @@ void test_svmla_single1_s16(uint32_t slice_base, svint16_t 
zn, svint16_t zm) __a
 //
 void test_svmla_single2_f16(uint32_t slice_base, svfloat16x2_t zn, svfloat16_t 
zm) __arm_streaming __arm_shared_za
 {
-   SVE_ACLE_FUNC(svmla_single_za32,,_f16,,_vg2x2)(slice_base, zn, zm);
+   SVE_ACLE_FUNC(svmla,_single,_za32,_f16,_vg2x2)(slice_base, zn, zm);
 }
 
 // CHECK-LABEL: @test_svmla_single2_bf16(
@@ -330,7 +330,7 @@ void test_svmla_single2_f16(uint32_t slice_base, 
svfloat16x2_t zn, svfloat16_t z
 //
 void test_svmla_single2_bf16(uint32_t slice_base, svbfloat16x2_t zn, 
svbfloat16_t zm) __arm_streaming __arm_shared_za
 {
-   SVE_ACLE_FUNC(svmla_single_za32,,_bf16,,_vg2x2)(slice_base, zn, zm);
+   SVE_ACLE_FUNC(svmla,_single,_za32,_bf16,_vg2x2)(slice_base, zn, zm);
 }
 
 // CHECK-LABEL: @test_svmla_single2_u16(
@@ -349,7 +349,7 @@ void test_svmla_single2_bf16(uint32_t slice_base, 
svbfloat16x2_t zn, svbfloat16_
 //
 void test_svmla_single2_u16(uint32_t slice_base, svuint16x2_t zn, svuint16_t 
zm) __arm_streaming __arm_shared_za
 {
-   SVE_ACLE_FUNC(svmla_single_za32,,_u16,,_vg2x2)(slice_base, zn, zm);
+   SVE_ACLE_FUNC(svmla,_single,_za32,_u16,_vg2x2)(slice_base, zn, zm);
 }
 
 // CHECK-LABEL: @test_svmla_single2_s16(
@@ -368,7 +368,7 @@ void test_svmla_single2_u16(uint32_t slice_base, 
svuint16x2_t zn, svuint16_t zm)
 //
 void test_svmla_single2_s16(uint32_t slice_base, svint16x2_t zn, svint16_t zm) 
__arm_streaming __arm_shared_za
 {
-   SVE_ACLE_FUNC(svmla_single_za32,,_s16,,_vg2x2)(slice_base, zn, zm);
+   SVE_ACLE_FUNC

[llvm] [clang] [AMDGPU] Add GFX12 WMMA and SWMMAC instructions (PR #77795)

2024-01-12 Thread Piotr Sobczak via cfe-commits


@@ -18240,65 +18240,211 @@ Value 
*CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
   case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w32:
   case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w64:
   case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w32:
-  case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w64: {
+  case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w64:
+  case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w32_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w64_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w32_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w64_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w32_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w64_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w32_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w64_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w32_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w64_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w32_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w64_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_fp8_w32_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_fp8_w64_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_bf8_w32_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_bf8_w64_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_fp8_w32_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_fp8_w64_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_bf8_w32_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_bf8_w64_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x32_iu4_w32_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x32_iu4_w64_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_f16_w32:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_f16_w64:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf16_w32:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf16_w64:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x32_f16_w32:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x32_f16_w64:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_bf16_16x16x32_bf16_w32:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_bf16_16x16x32_bf16_w64:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu8_w32:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu8_w64:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu4_w32:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu4_w64:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x64_iu4_w32:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x64_iu4_w64:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_fp8_w32:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_fp8_w64:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_bf8_w32:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_bf8_w64:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_fp8_w32:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_fp8_w64:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_bf8_w32:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_bf8_w64: {
 
 // These operations perform a matrix multiplication and accumulation of
 // the form:
 // D = A * B + C
-// The return type always matches the type of matrix C.
-unsigned ArgForMatchingRetType;
+// We need to specify one type for matrices AB and one for matrices CD.
+SmallVector ArgsForMatchingMatrixTypes;
+// Some intrinsics expect "false" as an extra bool argument.

piotrAMD wrote:

```suggestion
// On GFX12, the intrinsics with 16-bit accumulator use a packed layout. 
There is no need for the variable opsel argument, so always set it to "false".
```

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


[clang] 4d46721 - [Clang] Revert inintentional changes to cmake committed in 33e5db6e0

2024-01-12 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2024-01-12T10:59:46+01:00
New Revision: 4d467215f162b487381e17b8cb59283af75ca50e

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

LOG: [Clang] Revert inintentional changes to cmake committed in 33e5db6e0

Added: 


Modified: 
clang/.clang-tidy
llvm/cmake/modules/HandleLLVMOptions.cmake

Removed: 




diff  --git a/clang/.clang-tidy b/clang/.clang-tidy
index 7eef110c3cf7e2..ba55beb095f54f 100644
--- a/clang/.clang-tidy
+++ b/clang/.clang-tidy
@@ -1,5 +1,5 @@
 # Note that the readability-identifier-naming check is disabled, there are too
 # many violations in the codebase and they create too much noise in clang-tidy
 # results.
-Checks: '-readability-identifier-naming, -misc-include*'
+Checks: '-readability-identifier-naming'
 InheritParentConfig: true

diff  --git a/llvm/cmake/modules/HandleLLVMOptions.cmake 
b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 52babeda1fef03..0699a8586fcc7e 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -647,7 +647,7 @@ if ( LLVM_COMPILER_IS_GCC_COMPATIBLE )
   # crash if LLVM is built with GCC and LTO enabled (#57740).  Until
   # these bugs are fixed, we need to disable dead store eliminations
   # based on object lifetime.
-  # add_flag_if_supported("-fno-lifetime-dse" CMAKE_CXX_FLAGS)
+  add_flag_if_supported("-fno-lifetime-dse" CMAKE_CXX_FLAGS)
 endif ( LLVM_COMPILER_IS_GCC_COMPATIBLE )
 
 # Modules enablement for GCC-compatible compilers:



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


[clang-tools-extra] [llvm] [Matrix] Convert column-vector ops feeding dot product to row-vectors. (PR #72647)

2024-01-12 Thread Florian Hahn via cfe-commits

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

>From 3dfe86782806f048b130d46afa6293712919f672 Mon Sep 17 00:00:00 2001
From: Florian Hahn 
Date: Fri, 14 Apr 2023 14:33:57 +0100
Subject: [PATCH 1/2] [Matrix] Convert column-vector ops feeding dot product to
 row-vectors.

Generalize the logic used to convert column-vector ops to row-vectors to
support converting chains of operations.

A potential next step is to further generalize this to convert
column-vector ops to row-vector ops in general, not just for operands of
dot products. Dot-product handling would then be driven by the general
conversion, rather than the other way around.
---
 .../Scalar/LowerMatrixIntrinsics.cpp  | 51 ++-
 .../LowerMatrixIntrinsics/dot-product-int.ll  | 47 -
 2 files changed, 47 insertions(+), 51 deletions(-)

diff --git a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp 
b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
index 72b9db1e73d73d..c6bb43d3a78cf3 100644
--- a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
+++ b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
@@ -1332,8 +1332,8 @@ class LowerMatrixIntrinsics {
 if (!IsIntVec && !FMF.allowReassoc())
   return;
 
-auto CanBeFlattened = [this](Value *Op) {
-  if (match(Op, m_BinOp()) && ShapeMap.find(Op) != ShapeMap.end())
+auto CanBeFlattened = [](Value *Op) {
+  if (match(Op, m_BinOp()))
 return true;
   return match(
   Op, m_OneUse(m_CombineOr(
@@ -1346,6 +1346,9 @@ class LowerMatrixIntrinsics {
 // the returned cost is < 0, the argument is cheaper to use in the
 // dot-product lowering.
 auto GetCostForArg = [this, &CanBeFlattened](Value *Op, unsigned N) {
+  if (ShapeMap.find(Op) == ShapeMap.end())
+return InstructionCost::getInvalid();
+
   if (!isa(Op))
 return InstructionCost(0);
 
@@ -1356,7 +1359,7 @@ class LowerMatrixIntrinsics {
 InstructionCost EmbedCost(0);
 // Roughly estimate the cost for embedding the columns into a vector.
 for (unsigned I = 1; I < N; ++I)
-  EmbedCost -=
+  EmbedCost +=
   TTI.getShuffleCost(TTI::SK_Splice, FixedVectorType::get(EltTy, 
1),
  std::nullopt, TTI::TCK_RecipThroughput);
 return EmbedCost;
@@ -1378,7 +1381,7 @@ class LowerMatrixIntrinsics {
 // vector.
 InstructionCost EmbedCost(0);
 for (unsigned I = 1; I < N; ++I)
-  EmbedCost +=
+  EmbedCost -=
   TTI.getShuffleCost(TTI::SK_Splice, FixedVectorType::get(EltTy, 
1),
  std::nullopt, TTI::TCK_RecipThroughput);
 return EmbedCost;
@@ -1391,7 +1394,26 @@ class LowerMatrixIntrinsics {
   return TTI.getMemoryOpCost(Instruction::Load, VecTy, Align(1), 0) -
  N * TTI.getMemoryOpCost(Instruction::Load, EltTy, Align(1), 0);
 };
-auto LHSCost = GetCostForArg(LHS, LShape.NumColumns);
+
+SmallPtrSet Seen;
+SmallVector WorkList;
+SmallVector ToFlatten;
+WorkList.push_back(LHS);
+InstructionCost LHSCost(0);
+while (!WorkList.empty()) {
+  Value *Op = WorkList.pop_back_val();
+  if (!Seen.insert(Op).second)
+continue;
+
+  InstructionCost OpCost = GetCostForArg(Op, LShape.NumColumns);
+  if (OpCost + LHSCost >= LHSCost)
+continue;
+
+  LHSCost += OpCost;
+  ToFlatten.push_back(Op);
+  if (auto *I = dyn_cast(Op))
+WorkList.append(I->op_begin(), I->op_end());
+}
 
 // We compare the costs of a vector.reduce.add to sequential add.
 int AddOpCode = IsIntVec ? Instruction::Add : Instruction::FAdd;
@@ -1412,16 +1434,16 @@ class LowerMatrixIntrinsics {
 FusedInsts.insert(MatMul);
 IRBuilder<> Builder(MatMul);
 auto FlattenArg = [&Builder, &FusedInsts, &CanBeFlattened,
-   this](Value *Op) -> Value * {
+   this](Value *Op) {
   // Matmul must be the only user of loads because we don't use LowerLoad
   // for row vectors (LowerLoad results in scalar loads and shufflevectors
   // instead of single vector load).
   if (!CanBeFlattened(Op))
-return Op;
+return;
 
   if (match(Op, m_BinOp()) && ShapeMap.find(Op) != ShapeMap.end()) {
 ShapeMap[Op] = ShapeMap[Op].t();
-return Op;
+return;
   }
 
   FusedInsts.insert(cast(Op));
@@ -1432,16 +1454,19 @@ class LowerMatrixIntrinsics {
 auto *NewLoad = Builder.CreateLoad(Op->getType(), Arg);
 Op->replaceAllUsesWith(NewLoad);
 cast(Op)->eraseFromParent();
-return NewLoad;
+return;
   } else if (match(Op, m_Intrinsic(
m_Value(Arg {
 ToRemove.push_back(cast(Op));
-return Arg;
+Op->replaceAllUsesWith(Arg);
+return;
   }
-
-  return Op;
 };
-LHS = FlattenArg(L

[llvm] [clang] [AMDGPU] Add GFX12 WMMA and SWMMAC instructions (PR #77795)

2024-01-12 Thread Piotr Sobczak via cfe-commits


@@ -18240,65 +18240,211 @@ Value 
*CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
   case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w32:
   case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w64:
   case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w32:
-  case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w64: {
+  case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w64:
+  case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w32_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w64_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w32_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w64_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w32_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w64_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w32_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w64_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w32_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w64_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w32_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w64_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_fp8_w32_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_fp8_w64_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_bf8_w32_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_bf8_w64_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_fp8_w32_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_fp8_w64_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_bf8_w32_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_bf8_w64_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x32_iu4_w32_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x32_iu4_w64_gfx12:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_f16_w32:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_f16_w64:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf16_w32:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf16_w64:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x32_f16_w32:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x32_f16_w64:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_bf16_16x16x32_bf16_w32:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_bf16_16x16x32_bf16_w64:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu8_w32:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu8_w64:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu4_w32:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu4_w64:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x64_iu4_w32:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x64_iu4_w64:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_fp8_w32:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_fp8_w64:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_bf8_w32:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_bf8_w64:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_fp8_w32:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_fp8_w64:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_bf8_w32:
+  case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_bf8_w64: {
 
 // These operations perform a matrix multiplication and accumulation of
 // the form:
 // D = A * B + C
-// The return type always matches the type of matrix C.
-unsigned ArgForMatchingRetType;
+// We need to specify one type for matrices AB and one for matrices CD.
+SmallVector ArgsForMatchingMatrixTypes;
+// Some intrinsics expect "false" as an extra bool argument.
+bool AppendExtraBoolArg = false;

piotrAMD wrote:

```suggestion
bool AppendFalseForOpselArg = false;
```

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


[clang] [clang] Reapply Handle templated operators with reversed arguments (PR #72213)

2024-01-12 Thread Ilya Biryukov via cfe-commits


@@ -324,6 +324,113 @@ bool x = X() == X(); // expected-warning {{ambiguous}}
 }
 } // namespace P2468R2
 
+namespace GH53954{
+namespace friend_template_1 {
+struct P {
+  template 
+  friend bool operator==(const P&, const T&) { return true; } // expected-note 
{{candidate}} \
+  // expected-note {{ambiguous candidate function 
with reversed arguments}}
+};
+struct A : public P {};
+struct B : public P {};
+bool check(A a, B b) { return a == b; } // expected-warning {{use of 
overloaded operator '==' (with operand types 'A' and 'B') to be ambiguous}}
+}
+
+namespace friend_template_2 {
+struct P {
+  template 
+  friend bool operator==(const T&, const P&) { return true; } // expected-note 
{{candidate}} \
+  // expected-note {{ambiguous 
candidate function with reversed arguments}}
+};
+struct A : public P {};
+struct B : public P {};
+bool check(A a, B b) { return a == b; } // expected-warning {{use of 
overloaded operator '==' (with operand types 'A' and 'B') to be ambiguous}}
+}
+
+namespace friend_template_class_template {
+template
+struct P {
+  template 
+  friend bool operator==(const T&, const P&) { // expected-note 2 {{candidate}}
+return true;
+  }
+};
+struct A : public P {};
+struct B : public P {};
+bool check(A a, B b) { return a == b; } // expected-warning {{ambiguous}}
+}
+
+namespace friend_template_fixme {
+// FIXME(GH70210): This should not rewrite operator== and definitely not a 
hard error.

ilya-biryukov wrote:

I just wanted to point out that this bug is worrying as it might break some 
code that's not easy to rewrite.
We worked around the problem in LLVM with 
77f2ccbaac5e05e14827247ea8f6cc0f9d214390, but you could already see how the 
rewrite is complicated.

I don't think we should block on that, especially given that the issue you 
mention requires further progress from EWG and CWG. But I would keep a close 
eye for people complaining about this change.

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


[clang] [clang] Reapply Handle templated operators with reversed arguments (PR #72213)

2024-01-12 Thread Ilya Biryukov via cfe-commits

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


[clang] [clang] Reapply Handle templated operators with reversed arguments (PR #72213)

2024-01-12 Thread Ilya Biryukov via cfe-commits

https://github.com/ilya-biryukov approved this pull request.

I only have minor requests to add a new test and update the release note a bit.
Otherwise LGMT

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


[clang] [clang] Reapply Handle templated operators with reversed arguments (PR #72213)

2024-01-12 Thread Ilya Biryukov via cfe-commits


@@ -37,6 +37,27 @@ These changes are ones which we think may surprise users 
when upgrading to
 Clang |release| because of the opportunity they pose for disruption to existing
 code bases.
 
+- Fix a bug in reversed argument for templated operators.
+  This breaks code in C++20 which was previously accepted in C++17. Eg:

ilya-biryukov wrote:

Could you also clarify add a sentence clarifying that Clang did not properly 
diagnose this case in C++20 mode before this change?

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


[clang] [clang] Reapply Handle templated operators with reversed arguments (PR #72213)

2024-01-12 Thread Ilya Biryukov via cfe-commits


@@ -10088,9 +10088,13 @@ static bool allowAmbiguity(ASTContext &Context, const 
FunctionDecl *F1,
const FunctionDecl *F2) {
   if (declaresSameEntity(F1, F2))
 return true;
-  if (F1->isTemplateInstantiation() && F2->isTemplateInstantiation() &&
-  declaresSameEntity(F1->getPrimaryTemplate(), F2->getPrimaryTemplate())) {
-return true;
+  if (F1->isTemplateInstantiation() && F2->isTemplateInstantiation()) {
+auto PT1 = F1->getPrimaryTemplate();
+auto PT2 = F2->getPrimaryTemplate();
+if (declaresSameEntity(PT1, PT2) ||

ilya-biryukov wrote:

I believe your godbolt invocation is incomplete, it misses the actual 
comparisons. My example also needs an update to actually get some 
reasonably-looking code, see https://godbolt.org/z/G4914bf3z:

```cpp
template 
struct Foo {};
template  bool operator==(Foo, Foo);
template  bool operator==(Foo, Foo);

void test() {
Foo() == Foo();
}
```

I think that's supposed to excercise the code path I was referring to. Could we 
add this test case?

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


[clang-tools-extra] [llvm] [Matrix] Convert column-vector ops feeding dot product to row-vectors. (PR #72647)

2024-01-12 Thread Florian Hahn via cfe-commits


@@ -1391,7 +1394,26 @@ class LowerMatrixIntrinsics {
   return TTI.getMemoryOpCost(Instruction::Load, VecTy, Align(1), 0) -
  N * TTI.getMemoryOpCost(Instruction::Load, EltTy, Align(1), 0);
 };
-auto LHSCost = GetCostForArg(LHS, LShape.NumColumns);
+

fhahn wrote:

Thanks, added a comment for what the loop does, does hat make sense?

https://github.com/llvm/llvm-project/pull/72647
___
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 readability-redundant-casting check (PR #70595)

2024-01-12 Thread Congcong Cai via cfe-commits


@@ -0,0 +1,242 @@
+//===--- RedundantCastingCheck.cpp - clang-tidy 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "RedundantCastingCheck.h"
+#include "../utils/FixItHintUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+static bool areTypesEquals(QualType S, QualType D) {
+  if (S == D)
+return true;
+
+  const auto *TS = S->getAs();
+  const auto *TD = D->getAs();
+  if (TS != TD)
+return false;
+
+  QualType PtrS = S->getPointeeType();
+  QualType PtrD = D->getPointeeType();
+
+  if (!PtrS.isNull() && !PtrD.isNull())
+return areTypesEquals(PtrS, PtrD);
+
+  const DeducedType *DT = S->getContainedDeducedType();
+  if (DT && DT->isDeduced())
+return D == DT->getDeducedType();
+
+  return false;
+}
+
+static bool areTypesEquals(QualType TypeS, QualType TypeD,
+   bool IgnoreTypeAliases) {
+  const QualType CTypeS = TypeS.getCanonicalType();
+  const QualType CTypeD = TypeD.getCanonicalType();
+  if (CTypeS != CTypeD)
+return false;
+
+  return IgnoreTypeAliases || areTypesEquals(TypeS.getLocalUnqualifiedType(),
+ TypeD.getLocalUnqualifiedType());
+}
+
+static bool areBinaryOperatorOperandsTypesEqual(const Expr *E,
+bool IgnoreTypeAliases) {
+  if (!E)
+return false;
+  const Expr *WithoutImplicitAndParen = E->IgnoreParenImpCasts();
+  if (!WithoutImplicitAndParen)
+return false;
+  if (const auto *B = dyn_cast(WithoutImplicitAndParen)) {
+const QualType NonReferenceType =
+WithoutImplicitAndParen->getType().getNonReferenceType();
+if (!areTypesEquals(
+B->getLHS()->IgnoreImplicit()->getType().getNonReferenceType(),
+NonReferenceType, IgnoreTypeAliases))
+  return true;
+if (!areTypesEquals(
+B->getRHS()->IgnoreImplicit()->getType().getNonReferenceType(),
+NonReferenceType, IgnoreTypeAliases))
+  return true;
+  }
+  return false;
+}
+
+static const Decl *getSourceExprDecl(const Expr *SourceExpr) {
+  const Expr *CleanSourceExpr = SourceExpr->IgnoreParenImpCasts();
+  if (const auto *E = dyn_cast(CleanSourceExpr)) {
+return E->getDecl();
+  }
+
+  if (const auto *E = dyn_cast(CleanSourceExpr)) {
+return E->getCalleeDecl();
+  }
+
+  if (const auto *E = dyn_cast(CleanSourceExpr)) {
+return E->getMemberDecl();
+  }
+  return nullptr;
+}
+
+RedundantCastingCheck::RedundantCastingCheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)),
+  IgnoreTypeAliases(Options.getLocalOrGlobal("IgnoreTypeAliases", false)) 
{}
+
+void RedundantCastingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IgnoreMacros", IgnoreMacros);
+  Options.store(Opts, "IgnoreTypeAliases", IgnoreTypeAliases);
+}
+
+void RedundantCastingCheck::registerMatchers(MatchFinder *Finder) {
+
+  auto SimpleType = qualType(hasCanonicalType(
+  qualType(anyOf(builtinType(), references(builtinType()),
+ references(pointsTo(qualType())), 
pointsTo(qualType());
+
+  auto BitfieldMemberExpr = memberExpr(member(fieldDecl(isBitField(;
+
+  Finder->addMatcher(
+  explicitCastExpr(
+  unless(hasCastKind(CK_ConstructorConversion)),
+  unless(hasCastKind(CK_UserDefinedConversion)),
+  
unless(cxxFunctionalCastExpr(hasDestinationType(unless(SimpleType,
+
+  hasDestinationType(qualType().bind("type2")),
+  hasSourceExpression(anyOf(
+  expr(unless(initListExpr()), unless(BitfieldMemberExpr),
+   hasType(qualType().bind("type1")))

HerrCai0907 wrote:

`type1` and `type2` are not a good idea. Do you mean `dstType` and `srcType`

https://github.com/llvm/llvm-project/pull/70595
___
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 readability-redundant-casting check (PR #70595)

2024-01-12 Thread Congcong Cai via cfe-commits


@@ -0,0 +1,200 @@
+// RUN: %check_clang_tidy -std=c++11-or-later %s readability-redundant-casting 
%t
+// RUN: %check_clang_tidy -std=c++11-or-later -check-suffix=,MACROS %s 
readability-redundant-casting %t -- \
+// RUN:   -config='{CheckOptions: { 
readability-redundant-casting.IgnoreMacros: false }}'
+// RUN: %check_clang_tidy -std=c++11-or-later -check-suffix=,ALIASES %s 
readability-redundant-casting %t -- \
+// RUN:   -config='{CheckOptions: { 
readability-redundant-casting.IgnoreTypeAliases: true }}'
+
+struct A {};
+struct B : A {};
+A getA();
+
+void testRedundantStaticCasting(A& value) {
+  A& a1 = static_cast(value);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: redundant explicit casting to 
the same type 'A' as the sub-expression, remove this casting 
[readability-redundant-casting]
+  // CHECK-MESSAGES: :[[@LINE-3]]:36: note: source type originates from 
referencing this parameter
+  // CHECK-FIXES: {{^}}  A& a1 = value;
+}
+
+void testRedundantConstCasting1(A& value) {
+  A& a2 = const_cast(value);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: redundant explicit casting to 
the same type 'A' as the sub-expression, remove this casting 
[readability-redundant-casting]
+  // CHECK-MESSAGES: :[[@LINE-3]]:36: note: source type originates from 
referencing this parameter
+  // CHECK-FIXES: {{^}}  A& a2 = value;
+}
+
+void testRedundantConstCasting2(const A& value) {
+  const A& a3 = const_cast(value);
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: redundant explicit casting to 
the same type 'const A' as the sub-expression, remove this casting 
[readability-redundant-casting]
+  // CHECK-MESSAGES: :[[@LINE-3]]:42: note: source type originates from 
referencing this parameter
+  // CHECK-FIXES: {{^}}  const A& a3 = value;
+}
+
+void testRedundantReinterpretCasting(A& value) {
+  A& a4 = reinterpret_cast(value);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: redundant explicit casting to 
the same type 'A' as the sub-expression, remove this casting 
[readability-redundant-casting]
+  // CHECK-MESSAGES: :[[@LINE-3]]:41: note: source type originates from 
referencing this parameter
+  // CHECK-FIXES: {{^}}  A& a4 = value;
+}
+
+void testRedundantCCasting(A& value) {
+  A& a5 = (A&)(value);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: redundant explicit casting to 
the same type 'A' as the sub-expression, remove this casting 
[readability-redundant-casting]
+  // CHECK-MESSAGES: :[[@LINE-3]]:31: note: source type originates from 
referencing this parameter
+  // CHECK-FIXES: {{^}}  A& a5 = value;
+}
+
+void testDoubleCasting(A& value) {
+  A& a6 = static_cast(reinterpret_cast(value));
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: redundant explicit casting to 
the same type 'A' as the sub-expression, remove this casting 
[readability-redundant-casting]
+  // CHECK-MESSAGES: :[[@LINE-2]]:27: warning: redundant explicit casting to 
the same type 'A' as the sub-expression, remove this casting 
[readability-redundant-casting]
+  // CHECK-MESSAGES: :[[@LINE-4]]:27: note: source type originates from 
referencing this parameter
+  // CHECK-FIXES: {{^}}  A& a6 = value;
+}
+
+void testDiffrentTypesCast(B& value) {
+  A& a7 = static_cast(value);
+}
+
+void testCastingWithAuto() {
+  auto a = getA();
+  A& a8 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: redundant explicit casting to 
the same type 'A' as the sub-expression, remove this casting 
[readability-redundant-casting]
+  // CHECK-MESSAGES: :[[@LINE-3]]:8: note: source type originates from 
referencing this variable
+  // CHECK-FIXES: {{^}}  A& a8 = a;
+}
+
+void testCastingWithConstAuto() {
+  const auto a = getA();
+  const A& a9 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:17: warning: redundant explicit casting to 
the same type 'const A' as the sub-expression, remove this casting 
[readability-redundant-casting]
+  // CHECK-MESSAGES: :[[@LINE-3]]:14: note: source type originates from 
referencing this variable
+  // CHECK-FIXES: {{^}}  const A& a9 = a;
+}
+
+void testCastingWithAutoPtr(A& ptr) {
+  auto* a = &ptr;
+  A* a10 = static_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: redundant explicit casting to 
the same type 'A *' as the sub-expression, remove this casting 
[readability-redundant-casting]
+  // CHECK-MESSAGES: :[[@LINE-3]]:9: note: source type originates from 
referencing this variable
+  // CHECK-FIXES: {{^}}  A* a10 = a;
+}
+
+template
+void testRedundantTemplateCasting(T& value) {
+  A& a = static_cast(value);
+  T& t = static_cast(value);

HerrCai0907 wrote:

I don't think redundant casting should be diagnosed for template parameters.
It may break existing code when template function supports different type input 
and need to cast them to the same type.

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

[clang] [clang][analyzer] Improve modeling of 'fseeko' and 'ftello' in StdLibraryFunctionsChecker (PR #77902)

2024-01-12 Thread Ben Shi via cfe-commits

https://github.com/benshi001 created 
https://github.com/llvm/llvm-project/pull/77902

None

>From 97d753446ffc8eb9c701effb52dd671afc73e1dd Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Fri, 12 Jan 2024 18:17:39 +0800
Subject: [PATCH] [clang][analyzer] Improve modeling of 'fseeko' and 'ftello'
 in StdLibraryFunctionsChecker

---
 .../Checkers/StdLibraryFunctionsChecker.cpp   | 12 +--
 clang/test/Analysis/stream-errno.c| 32 +++
 2 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 3b36565681a7f3..f93eb4bf48 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2859,13 +2859,19 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 "fseeko",
 Signature(ArgTypes{FilePtrTy, Off_tTy, IntTy}, RetType{IntTy}),
 Summary(NoEvalCall)
-.Case(ReturnsZeroOrMinusOne, ErrnoIrrelevant)
-.ArgConstraint(NotNull(ArgNo(0;
+.Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0)))
+.ArgConstraint(ArgumentCondition(2, WithinRange, {{0, 2}})));
 
 // off_t ftello(FILE *stream);
 addToFunctionSummaryMap(
 "ftello", Signature(ArgTypes{FilePtrTy}, RetType{Off_tTy}),
-Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0;
+Summary(NoEvalCall)
+.Case({ReturnValueCondition(WithinRange, Range(0, LongMax))},
+  ErrnoUnchanged, GenericSuccessMsg)
+.Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0;
 
 // void *mmap(void *addr, size_t length, int prot, int flags, int fd,
 // off_t offset);
diff --git a/clang/test/Analysis/stream-errno.c 
b/clang/test/Analysis/stream-errno.c
index f44ee6070708b2..bc184d5ce018d3 100644
--- a/clang/test/Analysis/stream-errno.c
+++ b/clang/test/Analysis/stream-errno.c
@@ -129,6 +129,7 @@ void check_fseek(void) {
   int S = fseek(F, 11, SEEK_SET);
   if (S != 0) {
 clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+clang_analyzer_eval(S == -1);// expected-warning{{TRUE}}
 if (errno) {} // no-warning
 fclose(F);
 return;
@@ -136,6 +137,21 @@ void check_fseek(void) {
   if (errno) {} // expected-warning{{An undefined value may be read from 
'errno'}}
 }
 
+void check_fseeko(void) {
+  FILE *F = tmpfile();
+  if (!F)
+return;
+  int S = fseeko(F, 11, SEEK_SET);
+  if (S == -1) {
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+if (errno) {}// no-warning
+  } else {
+clang_analyzer_eval(S == 0); // expected-warning{{TRUE}}
+if (errno) {}// expected-warning{{An undefined value 
may be read from 'errno'}}
+  }
+  fclose(F);
+}
+
 void check_no_errno_change(void) {
   FILE *F = tmpfile();
   if (!F)
@@ -197,6 +213,22 @@ void check_ftell(void) {
   fclose(F);
 }
 
+void check_ftello(void) {
+  FILE *F = tmpfile();
+  if (!F)
+return;
+  errno = 0;
+  off_t Ret = ftello(F);
+  if (Ret >= 0) {
+clang_analyzer_eval(errno == 0); // expected-warning{{TRUE}}
+  } else {
+clang_analyzer_eval(Ret == -1);  // expected-warning{{TRUE}}
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+  }
+  if (errno) {}  // no-warning
+  fclose(F);
+}
+
 void check_rewind(void) {
   FILE *F = tmpfile();
   if (!F)

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


[clang] [clang][analyzer] Improve modeling of 'fseeko' and 'ftello' in StdLibraryFunctionsChecker (PR #77902)

2024-01-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ben Shi (benshi001)


Changes



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


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
(+9-3) 
- (modified) clang/test/Analysis/stream-errno.c (+32) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 3b36565681a7f3..f93eb4bf48 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2859,13 +2859,19 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 "fseeko",
 Signature(ArgTypes{FilePtrTy, Off_tTy, IntTy}, RetType{IntTy}),
 Summary(NoEvalCall)
-.Case(ReturnsZeroOrMinusOne, ErrnoIrrelevant)
-.ArgConstraint(NotNull(ArgNo(0;
+.Case(ReturnsZero, ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0)))
+.ArgConstraint(ArgumentCondition(2, WithinRange, {{0, 2}})));
 
 // off_t ftello(FILE *stream);
 addToFunctionSummaryMap(
 "ftello", Signature(ArgTypes{FilePtrTy}, RetType{Off_tTy}),
-Summary(NoEvalCall).ArgConstraint(NotNull(ArgNo(0;
+Summary(NoEvalCall)
+.Case({ReturnValueCondition(WithinRange, Range(0, LongMax))},
+  ErrnoUnchanged, GenericSuccessMsg)
+.Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
+.ArgConstraint(NotNull(ArgNo(0;
 
 // void *mmap(void *addr, size_t length, int prot, int flags, int fd,
 // off_t offset);
diff --git a/clang/test/Analysis/stream-errno.c 
b/clang/test/Analysis/stream-errno.c
index f44ee6070708b2..bc184d5ce018d3 100644
--- a/clang/test/Analysis/stream-errno.c
+++ b/clang/test/Analysis/stream-errno.c
@@ -129,6 +129,7 @@ void check_fseek(void) {
   int S = fseek(F, 11, SEEK_SET);
   if (S != 0) {
 clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+clang_analyzer_eval(S == -1);// expected-warning{{TRUE}}
 if (errno) {} // no-warning
 fclose(F);
 return;
@@ -136,6 +137,21 @@ void check_fseek(void) {
   if (errno) {} // expected-warning{{An undefined value may be read from 
'errno'}}
 }
 
+void check_fseeko(void) {
+  FILE *F = tmpfile();
+  if (!F)
+return;
+  int S = fseeko(F, 11, SEEK_SET);
+  if (S == -1) {
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+if (errno) {}// no-warning
+  } else {
+clang_analyzer_eval(S == 0); // expected-warning{{TRUE}}
+if (errno) {}// expected-warning{{An undefined value 
may be read from 'errno'}}
+  }
+  fclose(F);
+}
+
 void check_no_errno_change(void) {
   FILE *F = tmpfile();
   if (!F)
@@ -197,6 +213,22 @@ void check_ftell(void) {
   fclose(F);
 }
 
+void check_ftello(void) {
+  FILE *F = tmpfile();
+  if (!F)
+return;
+  errno = 0;
+  off_t Ret = ftello(F);
+  if (Ret >= 0) {
+clang_analyzer_eval(errno == 0); // expected-warning{{TRUE}}
+  } else {
+clang_analyzer_eval(Ret == -1);  // expected-warning{{TRUE}}
+clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+  }
+  if (errno) {}  // no-warning
+  fclose(F);
+}
+
 void check_rewind(void) {
   FILE *F = tmpfile();
   if (!F)

``




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


[clang] [X86_64] fix empty structure vaarg in c++ (PR #77903)

2024-01-12 Thread via cfe-commits

https://github.com/hstk30-hw created 
https://github.com/llvm/llvm-project/pull/77903

SizeInBytes of empty structure is 0 in C, while 1 in C++. And empty structure 
argument of the function is ignored in X86_64 backend.As a result, the value of 
variable arguments in C++ is incorrect. #77036 

>From ebb2cdbea5e2c29b52f3bd46d31af105cf395e6d Mon Sep 17 00:00:00 2001
From: Longsheng Mou 
Date: Fri, 12 Jan 2024 18:24:08 +0800
Subject: [PATCH] [X86_64] fix empty structure vaarg in c++

SizeInBytes of empty structure is 0 in C, while 1 in C++.
And empty structure argument of the function is ignored
in X86_64 backend.As a result, the value of variable
arguments in C++ is incorrect.
---
 clang/lib/CodeGen/Targets/X86.cpp |  5 +
 clang/test/CodeGen/X86/x86_64-vaarg.c | 15 +++
 2 files changed, 20 insertions(+)
 create mode 100644 clang/test/CodeGen/X86/x86_64-vaarg.c

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index d053f41ab168f5..fde76ed6709cef 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -2989,6 +2989,11 @@ static Address EmitX86_64VAArgFromMemory(CodeGenFunction 
&CGF,
   // an 8 byte boundary.
 
   uint64_t SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8;
+  
+  if (isEmptyRecord(CGF.getContext(), Ty, true)) {
+SizeInBytes = 0;  
+  }
+  
   llvm::Value *Offset =
   llvm::ConstantInt::get(CGF.Int32Ty, (SizeInBytes + 7)  & ~7);
   overflow_arg_area = CGF.Builder.CreateGEP(CGF.Int8Ty, overflow_arg_area,
diff --git a/clang/test/CodeGen/X86/x86_64-vaarg.c 
b/clang/test/CodeGen/X86/x86_64-vaarg.c
new file mode 100644
index 00..ae201a2d3f3017
--- /dev/null
+++ b/clang/test/CodeGen/X86/x86_64-vaarg.c
@@ -0,0 +1,15 @@
+// RUN: %clang -xc++ -target x86_64-linux-gnu -emit-llvm -S -o - %s | 
FileCheck %s
+
+struct Empty {};
+
+struct Empty emptyvar;
+
+void take_args(int a, ...) {
+// CHECK:  %overflow_arg_area = load ptr, ptr %overflow_arg_area_p, 
align 8
+// CHECK-NEXT: %overflow_arg_area.next = getelementptr i8, ptr 
%overflow_arg_area, i32 0
+// CHECK-NEXT: store ptr %overflow_arg_area.next, ptr 
%overflow_arg_area_p, align 8
+__builtin_va_list l;
+__builtin_va_start(l, a);
+emptyvar = __builtin_va_arg(l, struct Empty);
+__builtin_va_end(l);
+}

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


[clang] [X86_64] fix empty structure vaarg in c++ (PR #77903)

2024-01-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: None (hstk30-hw)


Changes

SizeInBytes of empty structure is 0 in C, while 1 in C++. And empty structure 
argument of the function is ignored in X86_64 backend.As a result, the value of 
variable arguments in C++ is incorrect. #77036 

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


2 Files Affected:

- (modified) clang/lib/CodeGen/Targets/X86.cpp (+5) 
- (added) clang/test/CodeGen/X86/x86_64-vaarg.c (+15) 


``diff
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index d053f41ab168f5..fde76ed6709cef 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -2989,6 +2989,11 @@ static Address EmitX86_64VAArgFromMemory(CodeGenFunction 
&CGF,
   // an 8 byte boundary.
 
   uint64_t SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8;
+  
+  if (isEmptyRecord(CGF.getContext(), Ty, true)) {
+SizeInBytes = 0;  
+  }
+  
   llvm::Value *Offset =
   llvm::ConstantInt::get(CGF.Int32Ty, (SizeInBytes + 7)  & ~7);
   overflow_arg_area = CGF.Builder.CreateGEP(CGF.Int8Ty, overflow_arg_area,
diff --git a/clang/test/CodeGen/X86/x86_64-vaarg.c 
b/clang/test/CodeGen/X86/x86_64-vaarg.c
new file mode 100644
index 00..ae201a2d3f3017
--- /dev/null
+++ b/clang/test/CodeGen/X86/x86_64-vaarg.c
@@ -0,0 +1,15 @@
+// RUN: %clang -xc++ -target x86_64-linux-gnu -emit-llvm -S -o - %s | 
FileCheck %s
+
+struct Empty {};
+
+struct Empty emptyvar;
+
+void take_args(int a, ...) {
+// CHECK:  %overflow_arg_area = load ptr, ptr %overflow_arg_area_p, 
align 8
+// CHECK-NEXT: %overflow_arg_area.next = getelementptr i8, ptr 
%overflow_arg_area, i32 0
+// CHECK-NEXT: store ptr %overflow_arg_area.next, ptr 
%overflow_arg_area_p, align 8
+__builtin_va_list l;
+__builtin_va_start(l, a);
+emptyvar = __builtin_va_arg(l, struct Empty);
+__builtin_va_end(l);
+}

``




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


[clang] [X86_64] fix empty structure vaarg in c++ (PR #77903)

2024-01-12 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 4d467215f162b487381e17b8cb59283af75ca50e 
ebb2cdbea5e2c29b52f3bd46d31af105cf395e6d -- 
clang/test/CodeGen/X86/x86_64-vaarg.c clang/lib/CodeGen/Targets/X86.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index fde76ed670..4f9e903b8f 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -2989,11 +2989,11 @@ static Address 
EmitX86_64VAArgFromMemory(CodeGenFunction &CGF,
   // an 8 byte boundary.
 
   uint64_t SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8;
-  
+
   if (isEmptyRecord(CGF.getContext(), Ty, true)) {
-SizeInBytes = 0;  
+SizeInBytes = 0;
   }
-  
+
   llvm::Value *Offset =
   llvm::ConstantInt::get(CGF.Int32Ty, (SizeInBytes + 7)  & ~7);
   overflow_arg_area = CGF.Builder.CreateGEP(CGF.Int8Ty, overflow_arg_area,

``




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


[clang] [X86_64] fix empty structure vaarg in c++ (PR #77903)

2024-01-12 Thread via cfe-commits

https://github.com/hstk30-hw updated 
https://github.com/llvm/llvm-project/pull/77903

>From a9e8e956870668f32f7394c949f7c47cf2018dd1 Mon Sep 17 00:00:00 2001
From: Longsheng Mou 
Date: Fri, 12 Jan 2024 18:24:08 +0800
Subject: [PATCH] [X86_64] fix empty structure vaarg in c++

SizeInBytes of empty structure is 0 in C, while 1 in C++.
And empty structure argument of the function is ignored
in X86_64 backend.As a result, the value of variable
arguments in C++ is incorrect.
---
 clang/lib/CodeGen/Targets/X86.cpp |  5 +
 clang/test/CodeGen/X86/x86_64-vaarg.c | 15 +++
 2 files changed, 20 insertions(+)
 create mode 100644 clang/test/CodeGen/X86/x86_64-vaarg.c

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index d053f41ab168f5..c2c11280838b12 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -2989,6 +2989,11 @@ static Address EmitX86_64VAArgFromMemory(CodeGenFunction 
&CGF,
   // an 8 byte boundary.
 
   uint64_t SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8;
+
+  if (isEmptyRecord(CGF.getContext(), Ty, true)) {
+SizeInBytes = 0;  
+  }
+
   llvm::Value *Offset =
   llvm::ConstantInt::get(CGF.Int32Ty, (SizeInBytes + 7)  & ~7);
   overflow_arg_area = CGF.Builder.CreateGEP(CGF.Int8Ty, overflow_arg_area,
diff --git a/clang/test/CodeGen/X86/x86_64-vaarg.c 
b/clang/test/CodeGen/X86/x86_64-vaarg.c
new file mode 100644
index 00..ae201a2d3f3017
--- /dev/null
+++ b/clang/test/CodeGen/X86/x86_64-vaarg.c
@@ -0,0 +1,15 @@
+// RUN: %clang -xc++ -target x86_64-linux-gnu -emit-llvm -S -o - %s | 
FileCheck %s
+
+struct Empty {};
+
+struct Empty emptyvar;
+
+void take_args(int a, ...) {
+// CHECK:  %overflow_arg_area = load ptr, ptr %overflow_arg_area_p, 
align 8
+// CHECK-NEXT: %overflow_arg_area.next = getelementptr i8, ptr 
%overflow_arg_area, i32 0
+// CHECK-NEXT: store ptr %overflow_arg_area.next, ptr 
%overflow_arg_area_p, align 8
+__builtin_va_list l;
+__builtin_va_start(l, a);
+emptyvar = __builtin_va_arg(l, struct Empty);
+__builtin_va_end(l);
+}

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


[clang] [X86_64] fix empty structure vaarg in c++ (PR #77903)

2024-01-12 Thread via cfe-commits

https://github.com/hstk30-hw updated 
https://github.com/llvm/llvm-project/pull/77903

>From a9e8e956870668f32f7394c949f7c47cf2018dd1 Mon Sep 17 00:00:00 2001
From: Longsheng Mou 
Date: Fri, 12 Jan 2024 18:24:08 +0800
Subject: [PATCH 1/2] [X86_64] fix empty structure vaarg in c++

SizeInBytes of empty structure is 0 in C, while 1 in C++.
And empty structure argument of the function is ignored
in X86_64 backend.As a result, the value of variable
arguments in C++ is incorrect.
---
 clang/lib/CodeGen/Targets/X86.cpp |  5 +
 clang/test/CodeGen/X86/x86_64-vaarg.c | 15 +++
 2 files changed, 20 insertions(+)
 create mode 100644 clang/test/CodeGen/X86/x86_64-vaarg.c

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index d053f41ab168f5..c2c11280838b12 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -2989,6 +2989,11 @@ static Address EmitX86_64VAArgFromMemory(CodeGenFunction 
&CGF,
   // an 8 byte boundary.
 
   uint64_t SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8;
+
+  if (isEmptyRecord(CGF.getContext(), Ty, true)) {
+SizeInBytes = 0;  
+  }
+
   llvm::Value *Offset =
   llvm::ConstantInt::get(CGF.Int32Ty, (SizeInBytes + 7)  & ~7);
   overflow_arg_area = CGF.Builder.CreateGEP(CGF.Int8Ty, overflow_arg_area,
diff --git a/clang/test/CodeGen/X86/x86_64-vaarg.c 
b/clang/test/CodeGen/X86/x86_64-vaarg.c
new file mode 100644
index 00..ae201a2d3f3017
--- /dev/null
+++ b/clang/test/CodeGen/X86/x86_64-vaarg.c
@@ -0,0 +1,15 @@
+// RUN: %clang -xc++ -target x86_64-linux-gnu -emit-llvm -S -o - %s | 
FileCheck %s
+
+struct Empty {};
+
+struct Empty emptyvar;
+
+void take_args(int a, ...) {
+// CHECK:  %overflow_arg_area = load ptr, ptr %overflow_arg_area_p, 
align 8
+// CHECK-NEXT: %overflow_arg_area.next = getelementptr i8, ptr 
%overflow_arg_area, i32 0
+// CHECK-NEXT: store ptr %overflow_arg_area.next, ptr 
%overflow_arg_area_p, align 8
+__builtin_va_list l;
+__builtin_va_start(l, a);
+emptyvar = __builtin_va_arg(l, struct Empty);
+__builtin_va_end(l);
+}

>From dd0bbc3c30dc37fe75e2b58dfd7714af116926a8 Mon Sep 17 00:00:00 2001
From: Longsheng Mou 
Date: Fri, 12 Jan 2024 18:24:08 +0800
Subject: [PATCH 2/2] [X86_64] fix empty structure vaarg in c++

SizeInBytes of empty structure is 0 in C, while 1 in C++.
And empty structure argument of the function is ignored
in X86_64 backend.As a result, the value of variable
arguments in C++ is incorrect.
---
 clang/lib/CodeGen/Targets/X86.cpp |  5 +
 clang/test/CodeGen/X86/x86_64-vaarg.c | 15 +++
 2 files changed, 20 insertions(+)
 create mode 100644 clang/test/CodeGen/X86/x86_64-vaarg.c

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index d053f41ab168f5..c2c11280838b12 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -2989,6 +2989,11 @@ static Address EmitX86_64VAArgFromMemory(CodeGenFunction 
&CGF,
   // an 8 byte boundary.
 
   uint64_t SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8;
+
+  if (isEmptyRecord(CGF.getContext(), Ty, true)) {
+SizeInBytes = 0;  
+  }
+
   llvm::Value *Offset =
   llvm::ConstantInt::get(CGF.Int32Ty, (SizeInBytes + 7)  & ~7);
   overflow_arg_area = CGF.Builder.CreateGEP(CGF.Int8Ty, overflow_arg_area,
diff --git a/clang/test/CodeGen/X86/x86_64-vaarg.c 
b/clang/test/CodeGen/X86/x86_64-vaarg.c
new file mode 100644
index 00..ae201a2d3f3017
--- /dev/null
+++ b/clang/test/CodeGen/X86/x86_64-vaarg.c
@@ -0,0 +1,15 @@
+// RUN: %clang -xc++ -target x86_64-linux-gnu -emit-llvm -S -o - %s | 
FileCheck %s
+
+struct Empty {};
+
+struct Empty emptyvar;
+
+void take_args(int a, ...) {
+// CHECK:  %overflow_arg_area = load ptr, ptr %overflow_arg_area_p, 
align 8
+// CHECK-NEXT: %overflow_arg_area.next = getelementptr i8, ptr 
%overflow_arg_area, i32 0
+// CHECK-NEXT: store ptr %overflow_arg_area.next, ptr 
%overflow_arg_area_p, align 8
+__builtin_va_list l;
+__builtin_va_start(l, a);
+emptyvar = __builtin_va_arg(l, struct Empty);
+__builtin_va_end(l);
+}

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


[clang] [X86_64] fix empty structure vaarg in c++ (PR #77903)

2024-01-12 Thread via cfe-commits

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


[clang] [clang] Add test for CWG1807 (PR #77637)

2024-01-12 Thread Vlad Serebrennikov via cfe-commits

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

>From 545ee4900e48b186e1c9fff93dc62a459ee19754 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Wed, 10 Jan 2024 20:27:53 +0300
Subject: [PATCH 1/5] [clang] Add test for CWG1807

The test checks that objects in arrays are destructed in reverse order during 
stack unwinding.
---
 clang/test/CXX/drs/dr1807.cpp | 31 +++
 clang/www/cxx_dr_status.html  |  2 +-
 2 files changed, 32 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CXX/drs/dr1807.cpp

diff --git a/clang/test/CXX/drs/dr1807.cpp b/clang/test/CXX/drs/dr1807.cpp
new file mode 100644
index 00..f599a36c8b2cbd
--- /dev/null
+++ b/clang/test/CXX/drs/dr1807.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -std=c++98 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK,CXX98
+// RUN: %clang_cc1 -std=c++11 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK,SINCE-CXX11
+// RUN: %clang_cc1 -std=c++14 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK,SINCE-CXX11
+// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK,SINCE-CXX11
+// RUN: %clang_cc1 -std=c++20 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK,SINCE-CXX11
+// RUN: %clang_cc1 -std=c++23 %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK,SINCE-CXX11
+// RUN: %clang_cc1 -std=c++2c %s -triple x86_64-linux-gnu -emit-llvm -o - 
-fexceptions -fcxx-exceptions -pedantic-errors | llvm-cxxfilt -n | FileCheck %s 
--check-prefixes CHECK,SINCE-CXX11
+
+namespace dr1807 { // dr1807: 3.0
+struct S {
+  S() {}
+  ~S() {}
+};
+
+void f() {
+  try {
+S s[3];
+  } catch (...) {}
+}
+}
+
+// CHECK:  invoke void @dr1807::S::S(){{.+}}
+// CHECK-NEXT: {{.+}} unwind label %lpad
+
+// CHECK-LABEL:  lpad:
+// CHECK:  br {{.+}}, label {{.+}}, label %arraydestroy.body
+
+// CHECK-LABEL:  arraydestroy.body:
+// CHECK:  %arraydestroy.element = getelementptr {{.+}}, i64 -1
+// CXX98-NEXT: invoke void @dr1807::S::~S(){{.*}}%arraydestroy.element
+// SINCE-CXX11-NEXT:   call void @dr1807::S::~S(){{.*}}%arraydestroy.element
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index 2bded63d5cd41c..bea9d0f54c471e 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -10649,7 +10649,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/1807.html";>1807
 CD4
 Order of destruction of array elements after an exception
-Unknown
+Clang 3.0
   
   
 https://cplusplus.github.io/CWG/issues/1808.html";>1808

>From 81b5f521c4e8e77f39ef1b01612a7866c6de8440 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Wed, 10 Jan 2024 21:57:30 +0300
Subject: [PATCH 2/5] Leave a comment in dr18xx.cpp

---
 clang/test/CXX/drs/dr18xx.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/test/CXX/drs/dr18xx.cpp b/clang/test/CXX/drs/dr18xx.cpp
index 1d76804907a5c1..e092c83ab4ce42 100644
--- a/clang/test/CXX/drs/dr18xx.cpp
+++ b/clang/test/CXX/drs/dr18xx.cpp
@@ -164,6 +164,8 @@ void A::C::f4() {
 }
 } // namespace dr1804
 
+// dr1807 is in separate file
+
 namespace dr1812 { // dr1812: no
// NB: dup 1710
 #if __cplusplus >= 201103L

>From 59ec23c9cdd4d4557c0b471331683d577add31d6 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Wed, 10 Jan 2024 22:06:01 +0300
Subject: [PATCH 3/5] Eliminate the need for readers to guess how the file is
 named

---
 clang/test/CXX/drs/dr18xx.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CXX/drs/dr18xx.cpp b/clang/test/CXX/drs/dr18xx.cpp
index e092c83ab4ce42..530122ccd1aab1 100644
--- a/clang/test/CXX/drs/dr18xx.cpp
+++ b/clang/test/CXX/drs/dr18xx.cpp
@@ -164,7 +164,7 @@ void A::C::f4() {
 }
 } // namespace dr1804
 
-// dr1807 is in separate file
+// dr1807 is in dr1807.cpp
 
 namespace dr1812 { // dr1812: no
// NB: dup 1710

>From 62f1fa6bb3c691dde2e903711634857de486e71e Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Wed, 10 Jan 2024 23:33:41 +0300
Subject: [PATCH 4/5] Simplify C++ part of the test

---
 clang/test/CXX/drs/dr1807.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/clang/test/CXX/drs/dr1807.cpp b/clang/test/CXX/drs/dr1807.cpp
index f599a36c8b2cbd..e654987b485c76 100644
--- a/clang/test

[clang] [X86_64] fix empty structure vaarg in c++ (PR #77907)

2024-01-12 Thread via cfe-commits

https://github.com/hstk30-hw created 
https://github.com/llvm/llvm-project/pull/77907

SizeInBytes of empty structure is 0 in C, while 1 in C++. And empty structure 
argument of the function is ignored in X86_64 backend.As a result, the value of 
variable arguments in C++ is incorrect. fix #77036

>From 8e4aa168b2e7b2aa71be7f1c88f940ef141fb77c Mon Sep 17 00:00:00 2001
From: Longsheng Mou 
Date: Fri, 12 Jan 2024 18:24:08 +0800
Subject: [PATCH] [X86_64] fix empty structure vaarg in c++

SizeInBytes of empty structure is 0 in C, while 1 in C++.
And empty structure argument of the function is ignored
in X86_64 backend.As a result, the value of variable
arguments in C++ is incorrect.
---
 clang/lib/CodeGen/Targets/X86.cpp |  5 +
 clang/test/CodeGen/X86/x86_64-vaarg.c | 15 +++
 2 files changed, 20 insertions(+)
 create mode 100644 clang/test/CodeGen/X86/x86_64-vaarg.c

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index d053f41ab168f5..c2c11280838b12 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -2989,6 +2989,11 @@ static Address EmitX86_64VAArgFromMemory(CodeGenFunction 
&CGF,
   // an 8 byte boundary.
 
   uint64_t SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8;
+
+  if (isEmptyRecord(CGF.getContext(), Ty, true)) {
+SizeInBytes = 0;  
+  }
+
   llvm::Value *Offset =
   llvm::ConstantInt::get(CGF.Int32Ty, (SizeInBytes + 7)  & ~7);
   overflow_arg_area = CGF.Builder.CreateGEP(CGF.Int8Ty, overflow_arg_area,
diff --git a/clang/test/CodeGen/X86/x86_64-vaarg.c 
b/clang/test/CodeGen/X86/x86_64-vaarg.c
new file mode 100644
index 00..ae201a2d3f3017
--- /dev/null
+++ b/clang/test/CodeGen/X86/x86_64-vaarg.c
@@ -0,0 +1,15 @@
+// RUN: %clang -xc++ -target x86_64-linux-gnu -emit-llvm -S -o - %s | 
FileCheck %s
+
+struct Empty {};
+
+struct Empty emptyvar;
+
+void take_args(int a, ...) {
+// CHECK:  %overflow_arg_area = load ptr, ptr %overflow_arg_area_p, 
align 8
+// CHECK-NEXT: %overflow_arg_area.next = getelementptr i8, ptr 
%overflow_arg_area, i32 0
+// CHECK-NEXT: store ptr %overflow_arg_area.next, ptr 
%overflow_arg_area_p, align 8
+__builtin_va_list l;
+__builtin_va_start(l, a);
+emptyvar = __builtin_va_arg(l, struct Empty);
+__builtin_va_end(l);
+}

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


[clang] [X86_64] fix empty structure vaarg in c++ (PR #77907)

2024-01-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (hstk30-hw)


Changes

SizeInBytes of empty structure is 0 in C, while 1 in C++. And empty structure 
argument of the function is ignored in X86_64 backend.As a result, the value of 
variable arguments in C++ is incorrect. fix #77036

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


2 Files Affected:

- (modified) clang/lib/CodeGen/Targets/X86.cpp (+5) 
- (added) clang/test/CodeGen/X86/x86_64-vaarg.c (+15) 


``diff
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index d053f41ab168f5..c2c11280838b12 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -2989,6 +2989,11 @@ static Address EmitX86_64VAArgFromMemory(CodeGenFunction 
&CGF,
   // an 8 byte boundary.
 
   uint64_t SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8;
+
+  if (isEmptyRecord(CGF.getContext(), Ty, true)) {
+SizeInBytes = 0;  
+  }
+
   llvm::Value *Offset =
   llvm::ConstantInt::get(CGF.Int32Ty, (SizeInBytes + 7)  & ~7);
   overflow_arg_area = CGF.Builder.CreateGEP(CGF.Int8Ty, overflow_arg_area,
diff --git a/clang/test/CodeGen/X86/x86_64-vaarg.c 
b/clang/test/CodeGen/X86/x86_64-vaarg.c
new file mode 100644
index 00..ae201a2d3f3017
--- /dev/null
+++ b/clang/test/CodeGen/X86/x86_64-vaarg.c
@@ -0,0 +1,15 @@
+// RUN: %clang -xc++ -target x86_64-linux-gnu -emit-llvm -S -o - %s | 
FileCheck %s
+
+struct Empty {};
+
+struct Empty emptyvar;
+
+void take_args(int a, ...) {
+// CHECK:  %overflow_arg_area = load ptr, ptr %overflow_arg_area_p, 
align 8
+// CHECK-NEXT: %overflow_arg_area.next = getelementptr i8, ptr 
%overflow_arg_area, i32 0
+// CHECK-NEXT: store ptr %overflow_arg_area.next, ptr 
%overflow_arg_area_p, align 8
+__builtin_va_list l;
+__builtin_va_start(l, a);
+emptyvar = __builtin_va_arg(l, struct Empty);
+__builtin_va_end(l);
+}

``




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


[clang] [X86_64] fix empty structure vaarg in c++ (PR #77907)

2024-01-12 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: None (hstk30-hw)


Changes

SizeInBytes of empty structure is 0 in C, while 1 in C++. And empty structure 
argument of the function is ignored in X86_64 backend.As a result, the value of 
variable arguments in C++ is incorrect. fix #77036

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


2 Files Affected:

- (modified) clang/lib/CodeGen/Targets/X86.cpp (+5) 
- (added) clang/test/CodeGen/X86/x86_64-vaarg.c (+15) 


``diff
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index d053f41ab168f5..c2c11280838b12 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -2989,6 +2989,11 @@ static Address EmitX86_64VAArgFromMemory(CodeGenFunction 
&CGF,
   // an 8 byte boundary.
 
   uint64_t SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8;
+
+  if (isEmptyRecord(CGF.getContext(), Ty, true)) {
+SizeInBytes = 0;  
+  }
+
   llvm::Value *Offset =
   llvm::ConstantInt::get(CGF.Int32Ty, (SizeInBytes + 7)  & ~7);
   overflow_arg_area = CGF.Builder.CreateGEP(CGF.Int8Ty, overflow_arg_area,
diff --git a/clang/test/CodeGen/X86/x86_64-vaarg.c 
b/clang/test/CodeGen/X86/x86_64-vaarg.c
new file mode 100644
index 00..ae201a2d3f3017
--- /dev/null
+++ b/clang/test/CodeGen/X86/x86_64-vaarg.c
@@ -0,0 +1,15 @@
+// RUN: %clang -xc++ -target x86_64-linux-gnu -emit-llvm -S -o - %s | 
FileCheck %s
+
+struct Empty {};
+
+struct Empty emptyvar;
+
+void take_args(int a, ...) {
+// CHECK:  %overflow_arg_area = load ptr, ptr %overflow_arg_area_p, 
align 8
+// CHECK-NEXT: %overflow_arg_area.next = getelementptr i8, ptr 
%overflow_arg_area, i32 0
+// CHECK-NEXT: store ptr %overflow_arg_area.next, ptr 
%overflow_arg_area_p, align 8
+__builtin_va_list l;
+__builtin_va_start(l, a);
+emptyvar = __builtin_va_arg(l, struct Empty);
+__builtin_va_end(l);
+}

``




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


[clang] [X86_64] fix empty structure vaarg in c++ (PR #77907)

2024-01-12 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 4d467215f162b487381e17b8cb59283af75ca50e 
8e4aa168b2e7b2aa71be7f1c88f940ef141fb77c -- 
clang/test/CodeGen/X86/x86_64-vaarg.c clang/lib/CodeGen/Targets/X86.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index c2c1128083..4f9e903b8f 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -2991,7 +2991,7 @@ static Address EmitX86_64VAArgFromMemory(CodeGenFunction 
&CGF,
   uint64_t SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8;
 
   if (isEmptyRecord(CGF.getContext(), Ty, true)) {
-SizeInBytes = 0;  
+SizeInBytes = 0;
   }
 
   llvm::Value *Offset =

``




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


[llvm] [clang] [Clang][IR] add TBAA metadata on pointer, union and array types. (PR #75177)

2024-01-12 Thread Sam James via cfe-commits

thesamesam wrote:

> I put union TBAA under the option that is disabled by default. I am also 
> considering to put pointer TBAA under option too, if it raises enough 
> concerns too.

Let's please file a bug once this is merged so we remember to come back to that.

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


[clang] [X86_64] fix empty structure vaarg in c++ (PR #77907)

2024-01-12 Thread via cfe-commits

https://github.com/hstk30-hw updated 
https://github.com/llvm/llvm-project/pull/77907

>From fa84978a2e7d787ff6681e1e239347d0c80f2458 Mon Sep 17 00:00:00 2001
From: Longsheng Mou 
Date: Fri, 12 Jan 2024 18:24:08 +0800
Subject: [PATCH] [X86_64] fix empty structure vaarg in c++

SizeInBytes of empty structure is 0 in C, while 1 in C++.
And empty structure argument of the function is ignored
in X86_64 backend.As a result, the value of variable
arguments in C++ is incorrect.
---
 clang/lib/CodeGen/Targets/X86.cpp |  5 +
 clang/test/CodeGen/X86/x86_64-vaarg.c | 15 +++
 2 files changed, 20 insertions(+)
 create mode 100644 clang/test/CodeGen/X86/x86_64-vaarg.c

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index d053f41ab168f5..c2c11280838b12 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -2989,6 +2989,11 @@ static Address EmitX86_64VAArgFromMemory(CodeGenFunction 
&CGF,
   // an 8 byte boundary.
 
   uint64_t SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8;
+
+  if (isEmptyRecord(CGF.getContext(), Ty, true)) {
+SizeInBytes = 0;  
+  }
+
   llvm::Value *Offset =
   llvm::ConstantInt::get(CGF.Int32Ty, (SizeInBytes + 7)  & ~7);
   overflow_arg_area = CGF.Builder.CreateGEP(CGF.Int8Ty, overflow_arg_area,
diff --git a/clang/test/CodeGen/X86/x86_64-vaarg.c 
b/clang/test/CodeGen/X86/x86_64-vaarg.c
new file mode 100644
index 00..ae201a2d3f3017
--- /dev/null
+++ b/clang/test/CodeGen/X86/x86_64-vaarg.c
@@ -0,0 +1,15 @@
+// RUN: %clang -xc++ -target x86_64-linux-gnu -emit-llvm -S -o - %s | 
FileCheck %s
+
+struct Empty {};
+
+struct Empty emptyvar;
+
+void take_args(int a, ...) {
+// CHECK:  %overflow_arg_area = load ptr, ptr %overflow_arg_area_p, 
align 8
+// CHECK-NEXT: %overflow_arg_area.next = getelementptr i8, ptr 
%overflow_arg_area, i32 0
+// CHECK-NEXT: store ptr %overflow_arg_area.next, ptr 
%overflow_arg_area_p, align 8
+__builtin_va_list l;
+__builtin_va_start(l, a);
+emptyvar = __builtin_va_arg(l, struct Empty);
+__builtin_va_end(l);
+}

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


[clang] [Clang][AArch64] Change SME attributes for shared/new/preserved state. (PR #76971)

2024-01-12 Thread Sander de Smalen via cfe-commits


@@ -255,6 +255,22 @@ class AttributeCommonInfo {
 return SpellingIndex != SpellingNotCalculated;
   }
 };
+
+enum class KeywordAttributeParseArgumentsKind { None, Optional, Required };

sdesmalen-arm wrote:

Done.

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


[clang] [Clang][AArch64] Change SME attributes for shared/new/preserved state. (PR #76971)

2024-01-12 Thread Sander de Smalen via cfe-commits


@@ -8806,26 +8806,90 @@ static bool MustDelayAttributeArguments(const 
ParsedAttr &AL) {
   return false;
 }
 
+static bool checkArmNewAttrMutualExclusion(Sema &S, const ParsedAttr &AL,
+   const FunctionProtoType *FPT,
+   FunctionType::ArmStateValue State,
+   StringRef StateName) {
+  std::string ArmNewStr =

sdesmalen-arm wrote:

Done.

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


[clang] [Clang][AArch64] Change SME attributes for shared/new/preserved state. (PR #76971)

2024-01-12 Thread Sander de Smalen via cfe-commits


@@ -6898,13 +6941,18 @@ at the end of the function.
   }];
 }
 
-def ArmSmeNewZADocs : Documentation {
+def ArmNewDocs : Documentation {
   let Category = DocCatArmSmeAttributes;
   let Content = [{
-The ``__arm_new_za`` keyword applies to function declarations and specifies
-that the function will be set up with a fresh ZA context.
+The ``__arm_new`` keyword applies to function declarations and specifies
+that the function will create a new scope for state S.
+
+The attribute takes string arguments to instruct the compiler which state
+is shared.  The supported states for S are:

sdesmalen-arm wrote:

Done.

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


[clang] [Clang][AArch64] Change SME attributes for shared/new/preserved state. (PR #76971)

2024-01-12 Thread Sander de Smalen via cfe-commits


@@ -1,60 +1,60 @@
 // RUN: %clang_cc1 -fsyntax-only -triple aarch64-none-linux-gnu 
-target-feature +sme -verify=expected,notc2x -Wno-strict-prototypes %s
 // RUN: %clang_cc1 -fsyntax-only -triple aarch64-none-linux-gnu 
-target-feature +sme -verify=expected,c2x %s
 
-enum __arm_streaming E { // expected-error {{'__arm_streaming' only applies to 
non-K&R-style functions}}
-  One __arm_streaming, // expected-error {{'__arm_streaming' only applies to 
non-K&R-style functions}}
+enum __arm_inout("za") E { // expected-error {{'__arm_inout' only applies to 
non-K&R-style functions}}

sdesmalen-arm wrote:

I've added explicit tests for unbalanced parentheses, but also changed this 
test to test both attributes (with and without arguments), using a macro that 
is sed-replaced with a RUN line.

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


[clang] [Clang][AArch64] Change SME attributes for shared/new/preserved state. (PR #76971)

2024-01-12 Thread Sander de Smalen via cfe-commits


@@ -66,7 +66,7 @@ void test_svzero_mask_za_2(void) __arm_shared_za {
 // CHECK-CXX-NEXT:tail call void @llvm.aarch64.sme.zero(i32 255)
 // CHECK-CXX-NEXT:ret void
 //
-void test_svzero_za(void) __arm_shared_za {
+void test_svzero_za(void) __arm_inout("za") {

sdesmalen-arm wrote:

Done.

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


[clang] [Clang][AArch64] Change SME attributes for shared/new/preserved state. (PR #76971)

2024-01-12 Thread Sander de Smalen via cfe-commits


@@ -30,7 +30,7 @@
 // CPP-CHECK-NEXT:tail call void 
@llvm.aarch64.sme.write.ver.vg2.nxv16i8(i32 0, i32 [[BASE:%.*]],  [[TMP0]],  [[TMP1]])
 // CPP-CHECK-NEXT:ret void
 //
-void test_svwrite_ver_za8_u8_vg2(uint32_t base, svuint8x2_t val) 
__arm_streaming __arm_shared_za {
+void test_svwrite_ver_za8_u8_vg2(uint32_t base, svuint8x2_t val) 
__arm_streaming __arm_out("za") {

sdesmalen-arm wrote:

Done.

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


[clang] [X86_64] fix empty structure vaarg in c++ (PR #77907)

2024-01-12 Thread via cfe-commits

https://github.com/hstk30-hw updated 
https://github.com/llvm/llvm-project/pull/77907

>From 63ed15b49cfb87b85c858fe826c6a401a1f052eb Mon Sep 17 00:00:00 2001
From: Longsheng Mou 
Date: Fri, 12 Jan 2024 18:24:08 +0800
Subject: [PATCH] [X86_64] fix empty structure vaarg in c++

SizeInBytes of empty structure is 0 in C, while 1 in C++.
And empty structure argument of the function is ignored
in X86_64 backend.As a result, the value of variable
arguments in C++ is incorrect.
---
 clang/lib/CodeGen/Targets/X86.cpp |  5 +
 clang/test/CodeGen/X86/x86_64-vaarg.c | 15 +++
 2 files changed, 20 insertions(+)
 create mode 100644 clang/test/CodeGen/X86/x86_64-vaarg.c

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index d053f41ab168f5..4f9e903b8f0e98 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -2989,6 +2989,11 @@ static Address EmitX86_64VAArgFromMemory(CodeGenFunction 
&CGF,
   // an 8 byte boundary.
 
   uint64_t SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8;
+
+  if (isEmptyRecord(CGF.getContext(), Ty, true)) {
+SizeInBytes = 0;
+  }
+
   llvm::Value *Offset =
   llvm::ConstantInt::get(CGF.Int32Ty, (SizeInBytes + 7)  & ~7);
   overflow_arg_area = CGF.Builder.CreateGEP(CGF.Int8Ty, overflow_arg_area,
diff --git a/clang/test/CodeGen/X86/x86_64-vaarg.c 
b/clang/test/CodeGen/X86/x86_64-vaarg.c
new file mode 100644
index 00..ae201a2d3f3017
--- /dev/null
+++ b/clang/test/CodeGen/X86/x86_64-vaarg.c
@@ -0,0 +1,15 @@
+// RUN: %clang -xc++ -target x86_64-linux-gnu -emit-llvm -S -o - %s | 
FileCheck %s
+
+struct Empty {};
+
+struct Empty emptyvar;
+
+void take_args(int a, ...) {
+// CHECK:  %overflow_arg_area = load ptr, ptr %overflow_arg_area_p, 
align 8
+// CHECK-NEXT: %overflow_arg_area.next = getelementptr i8, ptr 
%overflow_arg_area, i32 0
+// CHECK-NEXT: store ptr %overflow_arg_area.next, ptr 
%overflow_arg_area_p, align 8
+__builtin_va_list l;
+__builtin_va_start(l, a);
+emptyvar = __builtin_va_arg(l, struct Empty);
+__builtin_va_end(l);
+}

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


[clang-tools-extra] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)

2024-01-12 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/77816

>From 1883d987b2f83adaef05fdb47ae25c7b06582a64 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Fri, 12 Jan 2024 00:02:46 +0530
Subject: [PATCH 1/9] Add readability check to suggest replacement of
 conditional statement with std::min/std::max

Signed-off-by: 11happy 
---
 .../clang-tidy/readability/CMakeLists.txt |  1 +
 .../ConditionaltostdminmaxCheck.cpp   | 86 +++
 .../readability/ConditionaltostdminmaxCheck.h | 30 +++
 .../readability/ReadabilityTidyModule.cpp |  3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../readability/ConditionalToStdMinMax.rst| 29 +++
 .../readability/ConditionalToStdMinMax.cpp| 27 ++
 8 files changed, 183 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/ConditionaltostdminmaxCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/ConditionaltostdminmaxCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/ConditionalToStdMinMax.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/ConditionalToStdMinMax.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 408c822b861c5f..4bc373bb69bb84 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -8,6 +8,7 @@ add_clang_library(clangTidyReadabilityModule
   AvoidReturnWithVoidValueCheck.cpp
   AvoidUnconditionalPreprocessorIfCheck.cpp
   BracesAroundStatementsCheck.cpp
+  ConditionaltostdminmaxCheck.cpp
   ConstReturnTypeCheck.cpp
   ContainerContainsCheck.cpp
   ContainerDataPointerCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/readability/ConditionaltostdminmaxCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ConditionaltostdminmaxCheck.cpp
new file mode 100644
index 00..fba8c68f737450
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/ConditionaltostdminmaxCheck.cpp
@@ -0,0 +1,86 @@
+//===--- ConditionaltostdminmaxCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ConditionaltostdminmaxCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void ConditionaltostdminmaxCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+ifStmt(
+  has(
+binaryOperator(
+  anyOf(hasOperatorName("<"),hasOperatorName(">")),
+  hasLHS(ignoringImpCasts(declRefExpr().bind("lhsVar1"))),
+  hasRHS(ignoringImpCasts(declRefExpr().bind("rhsVar1")))
+  )
+  )
+,
+hasThen(
+  stmt(
+binaryOperator(
+  hasOperatorName("="),
+  hasLHS(ignoringImpCasts(declRefExpr().bind("lhsVar2"))),
+  hasRHS(ignoringImpCasts(declRefExpr().bind("rhsVar2")))
+  )
+)
+  ) 
+).bind("ifStmt"),this);
+
+
+
+}
+
+void ConditionaltostdminmaxCheck::check(const MatchFinder::MatchResult 
&Result) {
+  const DeclRefExpr *lhsVar1 = Result.Nodes.getNodeAs("lhsVar1");
+  const DeclRefExpr *rhsVar1 = Result.Nodes.getNodeAs("rhsVar1");
+  const DeclRefExpr *lhsVar2 = Result.Nodes.getNodeAs("lhsVar2");
+  const DeclRefExpr *rhsVar2 = Result.Nodes.getNodeAs("rhsVar2"); 
 
+  const IfStmt *ifStmt = Result.Nodes.getNodeAs("ifStmt");
+
+  if (!lhsVar1 || !rhsVar1 || !lhsVar2 || !rhsVar2 || !ifStmt)
+return;
+
+  const BinaryOperator *binaryOp = dyn_cast(ifStmt->getCond());
+  if (!binaryOp)
+  return;
+
+  SourceLocation ifLocation = ifStmt->getIfLoc();
+  SourceLocation thenLocation = ifStmt->getEndLoc();
+
+  if(binaryOp->getOpcode() == BO_LT){
+if(lhsVar1->getDecl() == lhsVar2->getDecl() && rhsVar1->getDecl() == 
rhsVar2->getDecl()){
+  diag(ifStmt->getIfLoc(), "use std::max instead of 
<")getNameInfo().getAsString() + ", " +
+  rhsVar1->getNameInfo().getAsString() + 
")");
+}
+else if(lhsVar1->getDecl() == rhsVar2->getDecl() && rhsVar1->getDecl() == 
lhsVar2->getDecl()){
+  diag(ifStmt->getIfLoc(), "use std::min instead of 
<")getNameInfo().getAsString() + ", " +
+  rhsVar1->getNameInfo().getAsString() + 
")");
+}
+  }
+  else if(binaryOp->getOpcode() == BO_GT){
+if(lhsVar1->getDecl() == lhs

[clang-tools-extra] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)

2024-01-12 Thread Bhuminjay Soni via cfe-commits

11happy wrote:

Thank you for all the suggestions , I think I have tried to incorporate all of 
them .

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


[clang-tools-extra] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)

2024-01-12 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/77816

>From 1883d987b2f83adaef05fdb47ae25c7b06582a64 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Fri, 12 Jan 2024 00:02:46 +0530
Subject: [PATCH 01/10] Add readability check to suggest replacement of
 conditional statement with std::min/std::max

Signed-off-by: 11happy 
---
 .../clang-tidy/readability/CMakeLists.txt |  1 +
 .../ConditionaltostdminmaxCheck.cpp   | 86 +++
 .../readability/ConditionaltostdminmaxCheck.h | 30 +++
 .../readability/ReadabilityTidyModule.cpp |  3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../readability/ConditionalToStdMinMax.rst| 29 +++
 .../readability/ConditionalToStdMinMax.cpp| 27 ++
 8 files changed, 183 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/ConditionaltostdminmaxCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/ConditionaltostdminmaxCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/ConditionalToStdMinMax.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/ConditionalToStdMinMax.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 408c822b861c5f..4bc373bb69bb84 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -8,6 +8,7 @@ add_clang_library(clangTidyReadabilityModule
   AvoidReturnWithVoidValueCheck.cpp
   AvoidUnconditionalPreprocessorIfCheck.cpp
   BracesAroundStatementsCheck.cpp
+  ConditionaltostdminmaxCheck.cpp
   ConstReturnTypeCheck.cpp
   ContainerContainsCheck.cpp
   ContainerDataPointerCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/readability/ConditionaltostdminmaxCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ConditionaltostdminmaxCheck.cpp
new file mode 100644
index 00..fba8c68f737450
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/ConditionaltostdminmaxCheck.cpp
@@ -0,0 +1,86 @@
+//===--- ConditionaltostdminmaxCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ConditionaltostdminmaxCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void ConditionaltostdminmaxCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+ifStmt(
+  has(
+binaryOperator(
+  anyOf(hasOperatorName("<"),hasOperatorName(">")),
+  hasLHS(ignoringImpCasts(declRefExpr().bind("lhsVar1"))),
+  hasRHS(ignoringImpCasts(declRefExpr().bind("rhsVar1")))
+  )
+  )
+,
+hasThen(
+  stmt(
+binaryOperator(
+  hasOperatorName("="),
+  hasLHS(ignoringImpCasts(declRefExpr().bind("lhsVar2"))),
+  hasRHS(ignoringImpCasts(declRefExpr().bind("rhsVar2")))
+  )
+)
+  ) 
+).bind("ifStmt"),this);
+
+
+
+}
+
+void ConditionaltostdminmaxCheck::check(const MatchFinder::MatchResult 
&Result) {
+  const DeclRefExpr *lhsVar1 = Result.Nodes.getNodeAs("lhsVar1");
+  const DeclRefExpr *rhsVar1 = Result.Nodes.getNodeAs("rhsVar1");
+  const DeclRefExpr *lhsVar2 = Result.Nodes.getNodeAs("lhsVar2");
+  const DeclRefExpr *rhsVar2 = Result.Nodes.getNodeAs("rhsVar2"); 
 
+  const IfStmt *ifStmt = Result.Nodes.getNodeAs("ifStmt");
+
+  if (!lhsVar1 || !rhsVar1 || !lhsVar2 || !rhsVar2 || !ifStmt)
+return;
+
+  const BinaryOperator *binaryOp = dyn_cast(ifStmt->getCond());
+  if (!binaryOp)
+  return;
+
+  SourceLocation ifLocation = ifStmt->getIfLoc();
+  SourceLocation thenLocation = ifStmt->getEndLoc();
+
+  if(binaryOp->getOpcode() == BO_LT){
+if(lhsVar1->getDecl() == lhsVar2->getDecl() && rhsVar1->getDecl() == 
rhsVar2->getDecl()){
+  diag(ifStmt->getIfLoc(), "use std::max instead of 
<")getNameInfo().getAsString() + ", " +
+  rhsVar1->getNameInfo().getAsString() + 
")");
+}
+else if(lhsVar1->getDecl() == rhsVar2->getDecl() && rhsVar1->getDecl() == 
lhsVar2->getDecl()){
+  diag(ifStmt->getIfLoc(), "use std::min instead of 
<")getNameInfo().getAsString() + ", " +
+  rhsVar1->getNameInfo().getAsString() + 
")");
+}
+  }
+  else if(binaryOp->getOpcode() == BO_GT){
+if(lhsVar1->getDecl() == l

[clang-tools-extra] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)

2024-01-12 Thread Bhuminjay Soni via cfe-commits

https://github.com/11happy updated 
https://github.com/llvm/llvm-project/pull/77816

>From 1883d987b2f83adaef05fdb47ae25c7b06582a64 Mon Sep 17 00:00:00 2001
From: 11happy 
Date: Fri, 12 Jan 2024 00:02:46 +0530
Subject: [PATCH 01/11] Add readability check to suggest replacement of
 conditional statement with std::min/std::max

Signed-off-by: 11happy 
---
 .../clang-tidy/readability/CMakeLists.txt |  1 +
 .../ConditionaltostdminmaxCheck.cpp   | 86 +++
 .../readability/ConditionaltostdminmaxCheck.h | 30 +++
 .../readability/ReadabilityTidyModule.cpp |  3 +
 clang-tools-extra/docs/ReleaseNotes.rst   |  6 ++
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../readability/ConditionalToStdMinMax.rst| 29 +++
 .../readability/ConditionalToStdMinMax.cpp| 27 ++
 8 files changed, 183 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/ConditionaltostdminmaxCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/ConditionaltostdminmaxCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/ConditionalToStdMinMax.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/ConditionalToStdMinMax.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 408c822b861c5f..4bc373bb69bb84 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -8,6 +8,7 @@ add_clang_library(clangTidyReadabilityModule
   AvoidReturnWithVoidValueCheck.cpp
   AvoidUnconditionalPreprocessorIfCheck.cpp
   BracesAroundStatementsCheck.cpp
+  ConditionaltostdminmaxCheck.cpp
   ConstReturnTypeCheck.cpp
   ContainerContainsCheck.cpp
   ContainerDataPointerCheck.cpp
diff --git 
a/clang-tools-extra/clang-tidy/readability/ConditionaltostdminmaxCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ConditionaltostdminmaxCheck.cpp
new file mode 100644
index 00..fba8c68f737450
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/readability/ConditionaltostdminmaxCheck.cpp
@@ -0,0 +1,86 @@
+//===--- ConditionaltostdminmaxCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ConditionaltostdminmaxCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void ConditionaltostdminmaxCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+ifStmt(
+  has(
+binaryOperator(
+  anyOf(hasOperatorName("<"),hasOperatorName(">")),
+  hasLHS(ignoringImpCasts(declRefExpr().bind("lhsVar1"))),
+  hasRHS(ignoringImpCasts(declRefExpr().bind("rhsVar1")))
+  )
+  )
+,
+hasThen(
+  stmt(
+binaryOperator(
+  hasOperatorName("="),
+  hasLHS(ignoringImpCasts(declRefExpr().bind("lhsVar2"))),
+  hasRHS(ignoringImpCasts(declRefExpr().bind("rhsVar2")))
+  )
+)
+  ) 
+).bind("ifStmt"),this);
+
+
+
+}
+
+void ConditionaltostdminmaxCheck::check(const MatchFinder::MatchResult 
&Result) {
+  const DeclRefExpr *lhsVar1 = Result.Nodes.getNodeAs("lhsVar1");
+  const DeclRefExpr *rhsVar1 = Result.Nodes.getNodeAs("rhsVar1");
+  const DeclRefExpr *lhsVar2 = Result.Nodes.getNodeAs("lhsVar2");
+  const DeclRefExpr *rhsVar2 = Result.Nodes.getNodeAs("rhsVar2"); 
 
+  const IfStmt *ifStmt = Result.Nodes.getNodeAs("ifStmt");
+
+  if (!lhsVar1 || !rhsVar1 || !lhsVar2 || !rhsVar2 || !ifStmt)
+return;
+
+  const BinaryOperator *binaryOp = dyn_cast(ifStmt->getCond());
+  if (!binaryOp)
+  return;
+
+  SourceLocation ifLocation = ifStmt->getIfLoc();
+  SourceLocation thenLocation = ifStmt->getEndLoc();
+
+  if(binaryOp->getOpcode() == BO_LT){
+if(lhsVar1->getDecl() == lhsVar2->getDecl() && rhsVar1->getDecl() == 
rhsVar2->getDecl()){
+  diag(ifStmt->getIfLoc(), "use std::max instead of 
<")getNameInfo().getAsString() + ", " +
+  rhsVar1->getNameInfo().getAsString() + 
")");
+}
+else if(lhsVar1->getDecl() == rhsVar2->getDecl() && rhsVar1->getDecl() == 
lhsVar2->getDecl()){
+  diag(ifStmt->getIfLoc(), "use std::min instead of 
<")getNameInfo().getAsString() + ", " +
+  rhsVar1->getNameInfo().getAsString() + 
")");
+}
+  }
+  else if(binaryOp->getOpcode() == BO_GT){
+if(lhsVar1->getDecl() == l

[clang-tools-extra] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)

2024-01-12 Thread Bhuminjay Soni via cfe-commits


@@ -0,0 +1,27 @@
+// RUN: %check_clang_tidy %s readability-ConditionalToStdMinMax %t
+
+void foo() {
+  int value1,value2;
+
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: warning: use std::max instead of < 
[readability-ConditionalToStdMinMax]
+  if (value1 < value2)
+value1 = value2; // CHECK-FIXES: value1 = std::max(value1, value2);

11happy wrote:

How do I put the CHECK_FIXES above as it checks in that line?

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


[clang-tools-extra] [clang] [llvm] [flang] [Flang][OpenMP] Avoid default none errors for seq loop indices in par… (PR #76258)

2024-01-12 Thread Kiran Chandramohan via cfe-commits

https://github.com/kiranchandramohan updated 
https://github.com/llvm/llvm-project/pull/76258

>From 03e611d413cffa6ff7432a8a88db5d6901449f3c Mon Sep 17 00:00:00 2001
From: Kiran Chandramohan 
Date: Fri, 22 Dec 2023 18:35:00 +
Subject: [PATCH] [Flang][OpenMP] Avoid default none errors for seq loop
 indices in parallel

---
 flang/lib/Semantics/resolve-directives.cpp |  6 +-
 flang/test/Semantics/OpenMP/resolve05.f90  | 13 +
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/flang/lib/Semantics/resolve-directives.cpp 
b/flang/lib/Semantics/resolve-directives.cpp
index da6c865ad56a3b..6e782204e6368c 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1910,7 +1910,11 @@ void OmpAttributeVisitor::Post(const parser::Name &name) 
{
   if (Symbol * found{currScope().FindSymbol(name.source)}) {
 if (symbol != found) {
   name.symbol = found; // adjust the symbol within region
-} else if (GetContext().defaultDSA == Symbol::Flag::OmpNone) {
+} else if (GetContext().defaultDSA == Symbol::Flag::OmpNone &&
+// Exclude indices of sequential loops that are privatised in
+// the scope of the parallel region, and not in this scope.
+// TODO: check whether this should be caught in IsObjectWithDSA
+!symbol->test(Symbol::Flag::OmpPrivate)) {
   context_.Say(name.source,
   "The DEFAULT(NONE) clause requires that '%s' must be listed in "
   "a data-sharing attribute clause"_err_en_US,
diff --git a/flang/test/Semantics/OpenMP/resolve05.f90 
b/flang/test/Semantics/OpenMP/resolve05.f90
index 00f4860302183d..c4cebb48ac5c2b 100644
--- a/flang/test/Semantics/OpenMP/resolve05.f90
+++ b/flang/test/Semantics/OpenMP/resolve05.f90
@@ -17,7 +17,20 @@ subroutine default_none()
   !$omp end parallel
 end subroutine default_none
 
+! Test that indices of sequential loops are privatised and hence do not error
+! for DEFAULT(NONE)
+subroutine default_none_seq_loop
+  integer :: i
+
+  !$omp parallel do default(none)
+  do i = 1, 10
+ do j = 1, 20
+enddo
+  enddo
+end subroutine
+
 program mm
   call default_none()
+  call default_none_seq_loop()
   !TODO: private, firstprivate, shared
 end

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


[clang-tools-extra] [clang] [llvm] [flang] [Flang][OpenMP] Avoid default none errors for seq loop indices in par… (PR #76258)

2024-01-12 Thread Kiran Chandramohan via cfe-commits

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


  1   2   3   4   5   >